MCPcopy
hub / github.com/RedPlanetHQ/core / scanSessions

Method scanSessions

packages/cli/src/utils/coding-agents/codex.ts:312–356  ·  view source on GitHub ↗
(options: ScanOptions = {})

Source from the content-addressed store, hash-verified

310 }
311
312 async scanSessions(options: ScanOptions = {}): Promise<ScannedSession[]> {
313 const results: ScannedSession[] = [];
314
315 for (const {filePath, sessionId} of walkCodexSessions(options.since)) {
316 let stats;
317 try {
318 stats = statSync(filePath);
319 } catch {
320 continue;
321 }
322
323 if (options.since && stats.mtimeMs < options.since) continue;
324
325 results.push({
326 sessionId,
327 agent: this.agentName,
328 dir: '', // populated below from session_meta
329 title: null,
330 filePath,
331 fileSizeBytes: stats.size,
332 createdAt: stats.birthtimeMs || stats.mtimeMs,
333 updatedAt: stats.mtimeMs,
334 turnCount: 0,
335 });
336 }
337
338 results.sort((a, b) => b.updatedAt - a.updatedAt);
339
340 // Populate title + dir from session_meta (first line) in parallel
341 await Promise.all(results.map(async (s) => {
342 const first = await readFirstLine(s.filePath);
343 if (first?.type === 'session_meta') {
344 const payload = first.payload as any;
345 s.dir = payload?.cwd ?? '';
346 }
347 s.title = await this.extractTitle(s.filePath);
348 }));
349
350 // Apply dir filter after reading cwd from session_meta
351 if (options.dir) {
352 return results.filter((s) => s.dir === options.dir);
353 }
354
355 return results;
356 }
357}
358
359export const codexReader = new CodexReader();

Callers 1

scanAllSessionsFunction · 0.45

Calls 6

extractTitleMethod · 0.95
walkCodexSessionsFunction · 0.85
readFirstLineFunction · 0.85
pushMethod · 0.80
allMethod · 0.80
filterMethod · 0.80

Tested by

no test coverage detected