Fallback inventory used when `state.json` is unreadable: walk * ` /agents/*` directly and synthesize minimal AgentInfo * records for the directories that contain a `wire.jsonl`. Parent * links and `type` are unknown without state, so we mark every agent * as `independent` with a n
(sessionDir: string)
| 117 | * as `independent` with a null parent — the routes only need |
| 118 | * `agentId` + `wireExists` to serve wire/context. */ |
| 119 | async function discoverAgentsFromDisk(sessionDir: string): Promise<AgentInfo[]> { |
| 120 | const agentsDir = join(sessionDir, 'agents'); |
| 121 | let entries: import('node:fs').Dirent[]; |
| 122 | try { |
| 123 | entries = await readdir(agentsDir, { withFileTypes: true }); |
| 124 | } catch { |
| 125 | return []; |
| 126 | } |
| 127 | const out: AgentInfo[] = []; |
| 128 | for (const entry of entries) { |
| 129 | if (!entry.isDirectory()) continue; |
| 130 | const id = entry.name; |
| 131 | if (!isSafeAgentId(id)) continue; |
| 132 | const wirePath = join(agentsDir, id, 'wire.jsonl'); |
| 133 | const exists = await pathExists(wirePath); |
| 134 | let readable = exists; |
| 135 | let info: { count: number; protocolVersion: string | null } = { count: 0, protocolVersion: null }; |
| 136 | if (exists) { |
| 137 | try { |
| 138 | info = await scanWire(wirePath); |
| 139 | } catch { |
| 140 | readable = false; |
| 141 | } |
| 142 | } |
| 143 | out.push({ |
| 144 | agentId: id, |
| 145 | type: id === 'main' ? 'main' : 'independent', |
| 146 | parentAgentId: null, |
| 147 | homedir: join(agentsDir, id), |
| 148 | wireExists: readable, |
| 149 | wireRecordCount: info.count, |
| 150 | wireProtocolVersion: info.protocolVersion, |
| 151 | // swarmItem is persisted in state.json, which is unavailable on this |
| 152 | // disk-only fallback path, so it cannot be recovered here. |
| 153 | swarmItem: null, |
| 154 | }); |
| 155 | } |
| 156 | return out.sort((a, b) => compareAgentIds(a.agentId, b.agentId)); |
| 157 | } |
| 158 | |
| 159 | async function tryReadSummary( |
| 160 | sessionDir: string, |
no test coverage detected