(
sessionDir: string,
sessionId: string,
workDir: string,
opts: { imported?: boolean; importMeta?: ImportInfo | null } = {},
)
| 157 | } |
| 158 | |
| 159 | async function tryReadSummary( |
| 160 | sessionDir: string, |
| 161 | sessionId: string, |
| 162 | workDir: string, |
| 163 | opts: { imported?: boolean; importMeta?: ImportInfo | null } = {}, |
| 164 | ): Promise<SessionSummary | null> { |
| 165 | const imported = opts.imported ?? false; |
| 166 | const importMeta = opts.importMeta ?? null; |
| 167 | const state = await readState(sessionDir); |
| 168 | if (state === null) { |
| 169 | return brokenStateSummary(sessionDir, sessionId, workDir, imported, importMeta); |
| 170 | } |
| 171 | // Local migrated-CLI sessions are hidden; an imported bundle is shown |
| 172 | // regardless because the user chose to import it. |
| 173 | if (!imported && state.custom?.['imported_from_kimi_cli'] === true) return null; |
| 174 | |
| 175 | const mainWirePath = join(sessionDir, 'agents', 'main', 'wire.jsonl'); |
| 176 | const mainExists = await pathExists(mainWirePath); |
| 177 | let mainCount = 0; |
| 178 | let protocolVersion: string | null = null; |
| 179 | let health: SessionHealth = 'ok'; |
| 180 | if (!mainExists) { |
| 181 | health = 'missing_main_wire'; |
| 182 | } else { |
| 183 | try { |
| 184 | const info = await scanWire(mainWirePath); |
| 185 | mainCount = info.count; |
| 186 | protocolVersion = info.protocolVersion; |
| 187 | // Note: the protocol version is not used to gate health any more — |
| 188 | // the wire-reader best-efforts unknown versions with a warning. |
| 189 | } catch { |
| 190 | // A single unreadable wire file must not fail the whole list. |
| 191 | health = 'broken_main_wire'; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | return { |
| 196 | sessionId, |
| 197 | sessionDir, |
| 198 | workDir, |
| 199 | title: state.title ?? null, |
| 200 | lastPrompt: state.lastPrompt ?? null, |
| 201 | isCustomTitle: state.isCustomTitle ?? false, |
| 202 | createdAt: parseTs(state.createdAt), |
| 203 | updatedAt: parseTs(state.updatedAt), |
| 204 | agentCount: Object.keys(state.agents ?? {}).length, |
| 205 | mainAgentExists: mainExists, |
| 206 | mainWireRecordCount: mainCount, |
| 207 | wireProtocolVersion: protocolVersion, |
| 208 | health, |
| 209 | imported, |
| 210 | importMeta, |
| 211 | }; |
| 212 | } |
| 213 | |
| 214 | function brokenStateSummary( |
| 215 | sessionDir: string, |
no test coverage detected