ai-devkit
ai-devkit copied to clipboard
fix(agent-manager): Gemini sessions written as session-*.jsonl (Gemini CLI 0.46+) are never detected
Problem
Current Gemini CLI versions (observed with 0.46) write chat sessions as session-<timestamp>-<id>.jsonl. GeminiSessionLocator.isSessionFile (packages/agent-manager/src/providers/gemini/GeminiSessionLocator.ts) only accepts files ending in .json:
return fileName.startsWith(SESSION_FILE_PREFIX) && fileName.endsWith(".json");
So sessions from current Gemini versions are never discovered. Live Gemini agents show up with no session, summary or preview, and agent sessions doesn't list them.
The format is also different. It isn't one JSON document; it's a log:
- line 1 is a metadata record (
sessionId,projectHash,startTime,lastUpdated,kind); - later lines are update records such as
{"$set": {"messages": [...]}}.
GeminiSessionParser only understands the single-document .json format.
Found while working on #263.
Proposed approach
- Accept both
session-*.json(legacy) andsession-*.jsonlin discovery and history listing. - Read
sessionIdandprojectHashfor.jsonlfrom line 1, using the bounded head read introduced in #263. - Parse the
.jsonllog by applying the update records in order (at least$set; check which other operators Gemini emits) to rebuild the session. That feedsparseSession/getConversationand the summary. - Where it fits, reuse the incremental utility (#256) and the tail reader (#260) for the
.jsonlformat.
Acceptance criteria
- [ ] Live discovery and
listSessions/findSessionsByIdfindsession-*.jsonlfiles. - [ ] Session metadata for
.jsonlcomes from line 1 with a bounded read (≤ 64 KiB). - [ ] Parsing a
.jsonllog (metadata plus$setupdates) gives the same session, messages and summary as the equivalent.jsondocument (fixture test with both formats). - [ ] Unknown update operators are ignored without crashing, and a test covers that.
- [ ] Legacy
.jsonsessions still work (existing tests pass). - [ ] Fixtures are synthetic, modelled on the real record shapes, with no real session content.