MCPcopy
hub / github.com/garrytan/gstack / readAgentRecord

Function readAgentRecord

browse/src/terminal-agent-control.ts:98–109  ·  view source on GitHub ↗
(stateDir: string)

Source from the content-addressed store, hash-verified

96
97/** Read the current record. Returns null on missing/malformed file. */
98export 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. */
112export function writeAgentRecord(stateDir: string, record: AgentRecord): void {

Callers 4

buildFetchHandlerFunction · 0.90
shutdownFunction · 0.90
spawnTerminalAgentFunction · 0.85

Calls 1

agentRecordPathFunction · 0.85

Tested by

no test coverage detected