import type { FSWatcher } from "node:fs"; import type { ExtensionContext } from "@earendil-works/pi-coding-agent"; import type { AsyncJobState, ReadonlyAsyncJobState } from "./async.ts"; import type { HistoryIndexHandle } from "./history.ts"; import type { ForegroundResumeRun, OwnedRun, ReadonlyForegroundResumeRun, TrackedOwnedRun, } from "./owned-runs.ts"; /** Session lifecycle owner. Only owner boundaries may update maps, timers, handles and projections. */ export interface SubagentState { baseCwd: string; currentSessionId: string | null; asyncJobs: Map; waitingRuns?: Map; isRunResultConsumed?: (runId: string) => boolean; foregroundRuns?: Map; ownedRuns?: Map; historyIndex?: HistoryIndexHandle; historyReady?: Promise; historyClosing?: Promise; persistOwnedRun?: (run: OwnedRun) => void; onRunsChanged?: () => void; cleanupTimers: Map>; lastUiContext: ExtensionContext | null; poller: NodeJS.Timeout | null; completionSeen: Map; watcher: FSWatcher | null; watcherRestartTimer: ReturnType | null; resultFileCoalescer: { readonly schedule: (file: string, delayMs?: number) => boolean; readonly clear: () => void; }; } /** Read-only application state around genuine native handles, which retain their SDK contracts. */ export type ReadonlySubagentState = Readonly< Omit< SubagentState, | "asyncJobs" | "waitingRuns" | "foregroundRuns" | "ownedRuns" | "cleanupTimers" | "completionSeen" > > & { readonly asyncJobs: Readonly>; readonly waitingRuns?: Readonly>; readonly foregroundRuns?: Readonly>; readonly ownedRuns?: Readonly>; readonly cleanupTimers: Readonly>>; readonly completionSeen: Readonly>; };