MCPcopy Create free account
hub / github.com/MatterAIOrg/OrbCode / listSessions

Function listSessions

src/core/sessions.ts:52–72  ·  view source on GitHub ↗
(cwd: string)

Source from the content-addressed store, hash-verified

50
51/** Sessions for a workspace, most recently updated first. */
52export function listSessions(cwd: string): SessionData[] {
53 let files: string[]
54 try {
55 files = fs.readdirSync(getSessionsDir()).filter((f) => f.endsWith(".json"))
56 } catch {
57 return []
58 }
59 const sessions: SessionData[] = []
60 for (const file of files) {
61 try {
62 const data = JSON.parse(fs.readFileSync(path.join(getSessionsDir(), file), "utf8")) as SessionData
63 if (data.cwd === cwd && Array.isArray(data.messages) && data.messages.length > 0) {
64 sessions.push(data)
65 }
66 } catch {
67 // skip unreadable session files
68 }
69 }
70 sessions.sort((a, b) => (a.updatedAt < b.updatedAt ? 1 : -1))
71 return sessions.slice(0, MAX_SESSIONS_LISTED)
72}

Callers 1

AppFunction · 0.85

Calls 1

getSessionsDirFunction · 0.85

Tested by

no test coverage detected