MCPcopy Create free account
hub / github.com/arctic-cli/interface / loadRecentSessions

Function loadRecentSessions

packages/arctic/src/cli/recent-sessions.ts:30–61  ·  view source on GitHub ↗
(limit = 5, cwd: string = process.cwd())

Source from the content-addressed store, hash-verified

28}
29
30export function loadRecentSessions(limit = 5, cwd: string = process.cwd()): RecentSessionSummary[] {
31 const projects = resolveProjectIDsForCwd(cwd)
32 const targetProjects = projects.length > 0 ? projects : listAllProjectIDs()
33 if (targetProjects.length === 0) return []
34
35 const sessions: RecentSessionSummary[] = []
36 for (const projectID of targetProjects) {
37 const sessionDir = path.join(SESSION_ROOT, projectID)
38 let files: string[]
39 try {
40 files = fs.readdirSync(sessionDir)
41 } catch {
42 continue
43 }
44
45 for (const file of files) {
46 if (!file.endsWith(".json")) continue
47 const record = readJson<StoredSessionRecord>(path.join(sessionDir, file))
48 if (!record || record.parentID) continue
49 const updated = record.time?.updated
50 if (typeof updated !== "number") continue
51 sessions.push({
52 id: record.id ?? file.replace(/\.json$/, ""),
53 title: record.title,
54 updated,
55 })
56 }
57 }
58
59 sessions.sort((a, b) => (b.updated ?? 0) - (a.updated ?? 0))
60 return sessions.slice(0, limit)
61}
62
63function resolveProjectIDsForCwd(cwd: string): string[] {
64 const normalizedCwd = path.resolve(cwd)

Callers 2

buildLinesFunction · 0.90
LogoFunction · 0.90

Calls 5

resolveProjectIDsForCwdFunction · 0.85
listAllProjectIDsFunction · 0.85
readJsonFunction · 0.85
pushMethod · 0.80
cwdMethod · 0.65

Tested by

no test coverage detected