/** * state/persistence — durable file-based state for swarm and team runs. * * Every run has a manifest file, a task state file, and an append-only * event log. This module provides atomic reads and writes so crash * recovery can rebuild correct state. * * Directory layout: * .pi/swarm/state/runs/{runId}/ * manifest.json -- run metadata, status, agent IDs * tasks.json -- task graph & per-task status * events.jsonl -- append-only event log * agents/{agentId}/ * status.json -- per-agent status * output.log -- agent stdout capture */ export declare function validateId(id: string, kind: string): void; /** * Resolve the crew root directory. * * Always uses `.pi/swarm/` under the project root. Creates `.pi/` * if it does not already exist. */ export declare function resolveSwarmRoot(cwd: string): string; /** Resolve the state directory for a specific run. */ export declare function resolveRunStateDir(swarmRoot: string, runId: string): string; /** Resolve per-agent state directory. */ export declare function resolveAgentStateDir(swarmRoot: string, runId: string, agentId: string): string; export interface RunManifest { readonly runId: string; readonly type: "swarm" | "team" | "coordinator"; status: "running" | "completed" | "failed" | "abandoned"; goal?: string; startedAt: number; completedAt?: number; lastHeartbeatAt?: number; agentIds: string[]; error?: string; } /** * Create a new run manifest and write it to disk. */ export declare function createManifest(swarmRoot: string, manifest: RunManifest): void; /** * Read a run manifest from disk. * Returns null if the manifest does not exist or is corrupted (#126). * * ENOENT is treated as "absent" and returns null silently. JSON parse * errors and other I/O failures are logged via console.error so operators * know a manifest is corrupted, but the null contract is preserved. */ export declare function readManifest(swarmRoot: string, runId: string): RunManifest | null; /** * Update a run manifest (overwrites the file atomically). */ export declare function updateManifest(swarmRoot: string, manifest: RunManifest): void; /** * Update the heartbeat timestamp for a running manifest. */ export declare function updateHeartbeat(swarmRoot: string, runId: string): void; /** * Register an agent ID in the run manifest. * Called when a new agent spawns so the manifest tracks all agents in the run. */ export declare function registerAgentInManifest(swarmRoot: string, runId: string, agentId: string): void; /** * Append an event to the run's event log. * * #106p + #134: O_APPEND + fsync via `appendLine` replaces the previous * read-modify-write path. Each line is durable on disk before the call * returns, and a SIGKILL mid-call cannot leave a torn line (the OS * guarantees O_APPEND is atomic for writes that fit in a single record). * For a long-running run (1000+ events), the previous path read and * rewrote the entire log on every append — this version is O(1). */ export declare function appendEvent(swarmRoot: string, runId: string, event: Record): void; /** * Read all events from the run's event log. */ export declare function readEvents(swarmRoot: string, runId: string): Record[]; /** * Load per-agent status. */ export declare function loadAgentStatus(swarmRoot: string, runId: string, agentId: string): Record | null; /** * List all active run IDs in the state directory. * Only returns IDs that match the safe ID pattern. */ export declare function listActiveRuns(swarmRoot: string): string[]; /** * Delete the entire run state directory. */ export declare function deleteRunState(swarmRoot: string, runId: string): void; /** * Write a file atomically using a temp file + rename. * On POSIX rename is atomic; on Windows it replaces the target. */ export declare function writeAtomic(filePath: string, content: string): void; //# sourceMappingURL=persistence.d.ts.map