feat(session-manager): add project path filtering for session listing

- Add SESSION_STORAGE constant for session metadata directory
- Add getMainSessions() function to retrieve main sessions with filtering:
  - Sorts sessions by updated time (newest first)
  - Filters out child sessions (with parentID)
  - Filters sessions by directory path
- Update session_list tool to use new getMainSessions():
  - Add project_path parameter (default: current working directory)
  - Maintains existing date range filtering and limit behavior

🤖 Generated with assistance of OhMyOpenCode
This commit is contained in:
YeonGyu-Kim
2025-12-31 12:42:22 +09:00
parent a60546711a
commit 96db5bef67
3 changed files with 52 additions and 7 deletions
+43 -2
View File
@@ -1,8 +1,49 @@
import { existsSync, readdirSync } from "node:fs"
import { readdir, readFile } from "node:fs/promises"
import { join } from "node:path"
import { MESSAGE_STORAGE, PART_STORAGE, TODO_DIR, TRANSCRIPT_DIR } from "./constants"
import type { SessionMessage, SessionInfo, TodoItem } from "./types"
import { MESSAGE_STORAGE, PART_STORAGE, SESSION_STORAGE, TODO_DIR, TRANSCRIPT_DIR } from "./constants"
import type { SessionMessage, SessionInfo, TodoItem, SessionMetadata } from "./types"
export interface GetMainSessionsOptions {
directory?: string
}
export async function getMainSessions(options: GetMainSessionsOptions): Promise<SessionMetadata[]> {
if (!existsSync(SESSION_STORAGE)) return []
const sessions: SessionMetadata[] = []
try {
const projectDirs = await readdir(SESSION_STORAGE, { withFileTypes: true })
for (const projectDir of projectDirs) {
if (!projectDir.isDirectory()) continue
const projectPath = join(SESSION_STORAGE, projectDir.name)
const sessionFiles = await readdir(projectPath)
for (const file of sessionFiles) {
if (!file.endsWith(".json")) continue
try {
const content = await readFile(join(projectPath, file), "utf-8")
const meta = JSON.parse(content) as SessionMetadata
if (meta.parentID) continue
if (options.directory && meta.directory !== options.directory) continue
sessions.push(meta)
} catch {
continue
}
}
}
} catch {
return []
}
return sessions.sort((a, b) => b.time.updated - a.time.updated)
}
export async function getAllSessions(): Promise<string[]> {
if (!existsSync(MESSAGE_STORAGE)) return []