export const COORDINATOR_SCHEMA_VERSION = 1 as const; export const DEFAULT_IDLE_TTL_MS = 420_000; export type AgentState = "queued" | "running" | "idle" | "parked" | "aborted"; export type JobState = "queued" | "running" | "completed" | "failed" | "aborted" | "unexecuted"; export type TurnState = "queued" | "running" | "completed" | "failed" | "aborted" | "interrupted"; export type FormalResultEvidenceStatus = "completed" | "partial" | "blocked" | "unverified" | "malformed"; export interface FormalResultEvidenceRecord { version: 1; eventId: string; eventSequence: number; agentId: string; jobId: string; turnId: string; changeId: string; packageId: string; roleId: string; canonicalStatus: FormalResultEvidenceStatus; outputPath: string; outputSha256: string; outputBytes: number; historyPath: string; historyPrefixSha256: string; historyPrefixBytes: number; } /** * Structured model identity shared by durable Agent, turn, job, delivery, and * display projections. All fields are optional so legacy Journal records can * still be replayed without inventing identity that was never recorded. */ export interface ModelIdentityProjection { requestedModel?: string; /** Compatibility alias used by task result model objects. */ requested?: string; requestedThinking?: string; effectiveModel?: string; /** Compatibility aliases used by live/result consumers. */ effective?: string; canonical?: string; provider?: string; model?: string; modelLayer?: string; layer?: string; thinking?: string; modelSource?: string; thinkingSource?: string; /** Legacy model-selection source alias retained for consumers in the wild. */ source?: string; speedTier?: string; service?: string; effectiveMode?: string; effectiveModeReason?: string; parentModel?: string; parentThinking?: string; parentSpeedTier?: string; parentSource?: string; effectiveProvenance?: string; } export interface AgentRecord extends ModelIdentityProjection { id: string; name: string; selector: string; state: AgentState; parentAgentId?: string; sessionPath?: string; currentTurnId?: string; currentJobId?: string; createdAt: string; updatedAt: string; metadata?: Record; } export interface JobRecord extends ModelIdentityProjection { id: string; agentId: string; state: JobState; createdAt: string; updatedAt: string; error?: string; metadata?: Record; } export interface TurnRecord extends ModelIdentityProjection { id: string; agentId: string; jobId?: string; state: TurnState; createdAt: string; updatedAt: string; outcome?: string; metadata?: Record; } export interface MailboxRecord { agentId: string; messages: Array>; } export interface CoordinatorState { schemaVersion: typeof COORDINATOR_SCHEMA_VERSION; parentId: string; lastSequence: number; appliedEventIds: string[]; agents: Record; releasedAgents: Record; jobs: Record; turns: Record; mailboxes: Record; deliveries: Record>; models: Record>; workspaces: Record>; workspaceLeases: Record>; messages: Record>; formalResultEvidence: Record; } export type CoordinatorEventKind = | "agent.created" | "agent.state" | "agent.session" | "agent.released" | "job.created" | "job.state" | "turn.created" | "turn.state" | "turn.audit" | "formal.result.evidence" | "formal.message.prepared" | "mailbox.put" | "message.put" | "delivery.put" | "model.put" | "model.clear" | "workspace.lease" | "workspace.put"; export interface CoordinatorEvent { schemaVersion: typeof COORDINATOR_SCHEMA_VERSION; eventId: string; sequence: number; timestamp: string; parentId: string; kind: CoordinatorEventKind; agentId?: string; jobId?: string; turnId?: string; deliveryId?: string; messageId?: string; payload: Record; } export interface CoordinatorEventInput { kind: CoordinatorEventKind; agentId?: string; jobId?: string; turnId?: string; deliveryId?: string; messageId?: string; payload: Record; } export interface CoordinatorSnapshot { schemaVersion: typeof COORDINATOR_SCHEMA_VERSION; parentId: string; checkpointSequence: number; createdAt: string; state: CoordinatorState; } export interface ReplayDiagnostics { toleratedFinalPartialLine: boolean; ignoredBytes: number; snapshotLoaded: boolean; } export interface ReplayResult { state: CoordinatorState; events: CoordinatorEvent[]; diagnostics: ReplayDiagnostics; } export interface SidecarLayout { parentSessionPath: string; root: string; coordinatorPath: string; snapshotPath: string; agentsDir: string; patchesDir: string; resultsDir: string; workspacesPath: string; }