/** * Director state checkpoint — written incrementally throughout a fleet * run so a crashed director can be inspected (and eventually resumed) * instead of leaving only a final `fleet.json` manifest after `shutdown()`. * * Schema is JSON-friendly and deliberately denormalized. Each mutation * triggers an atomic-write of the whole file — small payloads (typically * < 10 KB even with dozens of subagents) make this cheap. */ export interface DirectorSubagentState { id: string; name?: string | undefined; role?: string | undefined; provider?: string | undefined; model?: string | undefined; spawnedAt: string; } export interface DirectorTaskState { taskId: string; subagentId?: string | undefined; description?: string | undefined; status: 'pending' | 'running' | 'completed' | 'failed' | 'stopped' | 'timeout'; assignedAt?: string | undefined; completedAt?: string | undefined; iterations?: number | undefined; toolCalls?: number | undefined; durationMs?: number | undefined; error?: string | undefined; worktree?: DirectorTaskWorktreeState | undefined; } export interface DirectorTaskWorktreeState { taskId: string; subagentId: string; handleId: string; dir: string; branch: string; baseBranch: string; status: 'allocated' | 'fallback' | 'committed' | 'merged' | 'kept' | 'released' | 'conflict' | 'failed'; commitSha?: string | undefined; conflictFiles?: string[] | undefined; error?: string | undefined; } export interface DirectorStateSnapshot { version: 1; directorRunId: string; updatedAt: string; spawnCount: number; maxSpawns?: number | undefined; spawnDepth: number; maxSpawnDepth: number; directorBudget?: { maxCostUsd?: number | undefined; maxTokens?: number | undefined; } | undefined; subagents: DirectorSubagentState[]; tasks: DirectorTaskState[]; /** Aggregated usage snapshot. Optional — populated by the Director on save when available. */ usage?: unknown | undefined; } export declare function loadDirectorState(filePath: string): Promise; /** * Lock file entry written when a director starts. Prevents two directors * from resuming the same run — the second one sees the lock and refuses * rather than corrupting the checkpoint by writing concurrently. */ export interface DirectorStateLock { pid: number; hostname: string; startedAt: string; } /** * Write a lock file to claim this checkpoint. Returns false if the lock * is already held by a live process; returns true if the lock was acquired * (either the file didn't exist, or the previous holder is dead). */ export declare function acquireDirectorStateLock(lockPath: string, processId?: number): Promise; /** * Remove the lock file. Call this on graceful Director.shutdown() so the * next director run can claim the checkpoint without stale-lock checks. */ export declare function releaseDirectorStateLock(lockPath: string): Promise; /** * In-memory accumulator with atomic-write checkpoint. The Director keeps * an instance, mutates it on every spawn/assign/complete/fail event, and * the instance debounces writes so a burst of activity collapses into a * single disk hit. * * Supports crash recovery: use `loadDirectorState()` to read an existing * checkpoint, then call `DirectorStateCheckpoint.resume(snapshot)` to * re-attach to a fleet mid-flight. The lock mechanism ensures no two * directors can claim the same checkpoint. */ export declare class DirectorStateCheckpoint { private snapshot; private readonly filePath; private readonly lockPath; private timer; private readonly debounceMs; private writing; private rewriteRequested; constructor(filePath: string, init: { directorRunId: string; maxSpawns?: number | undefined; spawnDepth: number; maxSpawnDepth: number; directorBudget?: { maxCostUsd?: number | undefined; maxTokens?: number | undefined; } | undefined; }, debounceMs?: number); /** * Attempt to acquire the lock for this checkpoint. Call this before * resuming a crashed director run. If it returns false, another * director process is still running this fleet — do not resume. */ acquireLock(): Promise; /** * Release the lock on graceful shutdown. Call `flush()` first to ensure * the final checkpoint state is on disk before removing the lock. * Without this, the next resume will see a stale-lock and refuse. */ releaseLock(): Promise; /** * Resume from a snapshot previously loaded via `loadDirectorState()`. * Use this when `--resume ` is triggered — the snapshot has * the full fleet state (subagents, tasks) from before the crash; the * checkpoint continues from there. */ resume(snapshot: DirectorStateSnapshot): void; current(): DirectorStateSnapshot; recordSpawn(sub: DirectorSubagentState, spawnCount: number): void; recordTaskAssigned(task: DirectorTaskState): void; recordTaskStatus(taskId: string, patch: Partial & { status: DirectorTaskState['status']; }): void; recordTaskWorktree(taskId: string, worktree: DirectorTaskWorktreeState): void; setUsage(usage: unknown): void; /** Force a synchronous flush — used by Director.shutdown(). */ flush(): Promise; private bumpUpdatedAt; private schedule; private persist; } //# sourceMappingURL=director-state.d.ts.map