import type { SubAgentToolCall } from './sub-agent-dispatcher.js'; /** G6.3 Heartbeat entry — single update written by a running sub-agent. */ export interface Heartbeat { readonly at: string; readonly status: HeartbeatStatus; readonly progress: number; readonly note: string | null; } export type HeartbeatStatus = 'queued' | 'running' | 'finalizing' | 'done' | 'failed' | 'stale'; export type DispatchRecordStatus = 'queued' | 'running' | 'finalizing' | 'done' | 'failed' | 'cancelled' | 'no-execution' | 'stale'; export type DispatchOutcome = 'success' | 'failed' | 'timeout' | 'cancelled' | 'no-execution'; /** G2+G5+G6 dispatch record schema (AC-26 + AC-34). */ export interface DispatchRecord { readonly version: 2; readonly createdAt: string; readonly completedAt: string | null; readonly outcome: DispatchOutcome; readonly artifactPaths: readonly string[]; readonly disposed: boolean; readonly disposedAt: string | null; readonly role: string; readonly requestId: string; readonly sessionId: string; readonly prompt: string; readonly toolCall: SubAgentToolCall; /** G5 batch id (AC-27) — uuid-like opaque token grouping one batch. */ readonly batchId: string; /** G6 fields (AC-34) — backward compat: defaults on read. */ readonly heartbeats: readonly Heartbeat[]; readonly lastBeatAt: string | null; readonly status: DispatchRecordStatus; } /** Input for the initial write. */ export type WriteInitialDispatchInput = { projectRoot: string; sessionId: string; requestId: string; role: string; prompt: string; toolCall: SubAgentToolCall; batchId: string; /** Override the timestamp (testing). */ now?: () => Date; }; /** Heartbeat write input. */ export type AppendHeartbeatInput = { recordPath: string; status: HeartbeatStatus; progress: number; note?: string; now?: () => Date; }; /** Lifecycle transition input. */ export type LifecycleInput = { recordPath: string; outcome: DispatchOutcome; status: DispatchRecordStatus; artifactPaths?: readonly string[]; now?: () => Date; /** * Slice 2026-06-23-audit-4th #A4: trusted project root. Required * so the active-dispatches index can be updated without deriving * the root from the recordPath (the same anti-pattern that * audit-3rd #1 fixed for heartbeat). The CLI / LLM-side runner * passes this from `--project` or `process.cwd()`. */ projectRoot?: string; }; /** Write a new dispatch record (G2 + G5 + G6). Returns the absolute path. */ export declare function writeInitialDispatchRecord(input: WriteInitialDispatchInput): { path: string; record: DispatchRecord; }; /** * Active-dispatches index. Per-session JSON file at * `.peaks/_sub_agents//active-dispatches.json`. Map. Updated on dispatch + completion. */ export interface ActiveDispatchEntry { readonly recordPath: string; readonly requestId: string; readonly role: string; readonly batchId: string; readonly createdAt: string; readonly status: 'queued' | 'running' | 'finalizing' | 'done' | 'failed' | 'cancelled' | 'stale' | 'no-execution'; } /** * Slice 2026-06-23-audit-4th #A4: read the active-dispatches index * for a session. Returns the current map. Used * by the LLM-side runner to discover in-flight records on restart. * Returns an empty map when the index file is missing or corrupt * (the on-disk records directory is the next fallback). */ export declare function readActiveDispatchIndex(projectRoot: string, sessionId: string): Record; /** Slice 2026-06-23-audit-4th #A3: default TTL for dispatch records. */ export declare const DISPATCH_RECORD_TTL_DAYS = 30; /** * Slice 2026-06-23-audit-4th #A3: is this dispatch record an orphan * (older than DISPATCH_RECORD_TTL_DAYS or already GC'd)? Mirrors * `isOrphanChannel` in shared-channel.ts so a future * `peaks sub-agent cleanup` umbrella can run all three sweeps * (shared channel + dispatch record + contract) in one pass. */ export declare function isOrphanDispatchRecord(opts: { projectRoot: string; sid: string; rid: string; recordPath: string; now?: Date; }): boolean; /** Append a heartbeat (G6). Idempotent on (at, status) — append-only. */ export declare function appendHeartbeat(input: AppendHeartbeatInput): { record: DispatchRecord; truncated: boolean; }; /** Apply truncation: keep most recent 100, mark truncated flag. */ export declare function applyTruncation(entries: readonly Heartbeat[]): { heartbeats: Heartbeat[]; truncated: boolean; }; /** Mark a record as completed (success / failed / cancelled / no-execution). */ export declare function markCompleted(input: LifecycleInput): { record: DispatchRecord; }; /** Mark a record as disposed (reducer ran). */ export declare function markDisposed(recordPath: string, now?: () => Date): { record: DispatchRecord; }; /** * Read a dispatch record with backward-compat defaults. Old records * missing G5 / G6 fields are upgraded on read (no error, no overwrite). */ export declare function readRecord(recordPath: string): DispatchRecord; /** Read multiple records from a list of paths. Tolerates missing files. */ export declare function readRecords(paths: readonly string[]): DispatchRecord[]; declare function isDispatchStatus(v: unknown): v is DispatchRecordStatus; declare function isOutcome(v: unknown): v is DispatchOutcome; export { isDispatchStatus, isOutcome };