(home: string, sessionId: string)
| 63 | } |
| 64 | |
| 65 | export async function readSessionDetail(home: string, sessionId: string): Promise<SessionDetail | null> { |
| 66 | if (isImportId(sessionId)) return readImportedDetail(home, sessionId); |
| 67 | const sessionDir = await findSessionDir(home, sessionId); |
| 68 | if (sessionDir === null) return null; |
| 69 | const index = await readSessionIndex(home); |
| 70 | const workDir = index.get(sessionId)?.workDir ?? ''; |
| 71 | const state = await readState(sessionDir); |
| 72 | // When state.json is unreadable we still return a SessionDetail so the |
| 73 | // UI can render the broken-state diagnostic. Agent inventory cannot be |
| 74 | // derived from state, but the on-disk `agents/<id>/wire.jsonl` files |
| 75 | // are independent of state — probe for them directly so users can |
| 76 | // still inspect the wire/context of a session whose state is corrupt. |
| 77 | if (state === null) { |
| 78 | const agents = await discoverAgentsFromDisk(sessionDir); |
| 79 | return { sessionId, sessionDir, workDir, state: null, agents, imported: false, importMeta: null }; |
| 80 | } |
| 81 | if (state.custom?.['imported_from_kimi_cli'] === true) return null; |
| 82 | const agents = await inventoryAgents(sessionDir, state); |
| 83 | return { sessionId, sessionDir, workDir, state, agents, imported: false, importMeta: null }; |
| 84 | } |
| 85 | |
| 86 | /** Detail for an imported bundle. Same readers as a local session, but the |
| 87 | * directory is `imported/<id>/`, the workDir comes from the manifest, and |
no test coverage detected