(stateDir: string)
| 96 | |
| 97 | /** Read the current record. Returns null on missing/malformed file. */ |
| 98 | export function readAgentRecord(stateDir: string): AgentRecord | null { |
| 99 | try { |
| 100 | const raw = fs.readFileSync(agentRecordPath(stateDir), 'utf-8'); |
| 101 | const j = JSON.parse(raw); |
| 102 | if (typeof j?.pid === 'number' && typeof j?.gen === 'string' && typeof j?.startedAt === 'number') { |
| 103 | return j as AgentRecord; |
| 104 | } |
| 105 | return null; |
| 106 | } catch { |
| 107 | return null; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /** Atomic write. Caller must ensure stateDir exists; agent does this at boot. */ |
| 112 | export function writeAgentRecord(stateDir: string, record: AgentRecord): void { |
no test coverage detected