import type { SessionManager } from "@caupulican/pi-agent-core/node"; import type { EvidenceBundle, LearningDecision, WorkerClaim } from "../autonomy/contracts.ts"; import type { LaneRecord } from "../autonomy/lane-tracker.ts"; import type { BackgroundToolTaskRef } from "../background-tool-task-controller.ts"; import type { TaskRuntimeProjection } from "../orchestration/task-runtime.ts"; import { type SessionWorkStateProjection } from "../orchestration/work-state-projection.ts"; import type { OpenTaskStepProjection } from "../tasks/task-projection.ts"; import { type GoalContinuationDecision } from "./goal-continuation-controller.ts"; import type { GoalState } from "./goal-state.ts"; export interface GoalRuntimeSnapshotSettings { maxStallTurns: number; } /** * A read-only projection of one OPEN (non-terminal) task_steps step, included in the goal * runtime snapshot purely for cross-visibility. This is NOT a shared state machine: the goal * loop never writes back to task state through this snapshot, and the task store stays the * single source of truth for its own steps. */ export type GoalRuntimeOpenTaskStep = OpenTaskStepProjection; /** * Live, per-worktree-sync-lane status for one lane bound to a dispatched worker, as the caller * (runtime-builder / whatever host process has live git-engine access) derives it. `boundLaneId` is * the host `LaneRecord.laneId` the lane's registration was correlated to * (`LaneRegistration.boundLaneId`, same id-space as `Requirement.boundLaneId`) -- `undefined` for a * lane never bound to a dispatch. `fresh`/`stale` mirror `LaneFacts`; `syncRequired` is the * staleness-propagation verdict (`WorktreeSyncPolicy`-derived); `rebaseInProgress` marks a sync that * stopped on conflicts (a rebase left in progress) -- see `core/worktree-sync/git-engine.ts`. */ export interface GoalRuntimeWorktreeLaneStatus { laneKey: string; boundLaneId?: string; fresh: boolean; stale: boolean; syncRequired: boolean; rebaseInProgress: boolean; } /** * Per-requirement projection of {@link GoalRuntimeWorktreeLaneStatus}, joined via * `requirement.boundLaneId === status.boundLaneId` -- read-only cross-visibility for snapshot * consumers (e.g. a future continuation-prompt render), mirroring `openTaskSteps`'s role. This is * NOT what feeds `evaluateGoalContinuation` (that reads the raw `boundLaneId`-keyed sets directly); * it exists purely so a requirement's worktree state is visible without re-deriving the join. */ export interface GoalRuntimeRequirementWorktreeState { requirementId: string; laneKey: string; fresh: boolean; stale: boolean; syncRequired: boolean; rebaseInProgress: boolean; } export interface GoalRuntimeSnapshot { goalState?: GoalState; latestEvidenceBundle?: EvidenceBundle; workerClaims: readonly WorkerClaim[]; learningDecisions: readonly LearningDecision[]; continuation: GoalContinuationDecision; /** * Open (non-terminal) task_steps steps on the active branch, latest-wins. Read-only. * Optional (like `goalState`/`latestEvidenceBundle`) so hand-built snapshots in existing * tests/call sites that predate this field keep compiling unchanged; `buildGoalRuntimeSnapshot` * itself always populates a concrete array (possibly empty). */ openTaskSteps?: readonly GoalRuntimeOpenTaskStep[]; /** Canonical read model joining requirements, foreground steps, and delegated DAG tasks. */ workState?: SessionWorkStateProjection; /** * Per-requirement worktree-sync state, present only for requirements whose `boundLaneId` matches * a `worktreeLaneStatus` entry supplied to the builder. Optional (like `openTaskSteps`) so every * pre-existing caller/test keeps compiling unchanged; omitted entirely (not an empty array) when * the builder was never given `worktreeLaneStatus`, since "no data supplied" and "data supplied, * nothing bound" are genuinely different states worth distinguishing. */ requirementWorktreeStates?: readonly GoalRuntimeRequirementWorktreeState[]; } /** * Branch-scoped: every resolver here reads from ONE source (the active branch), so the goal * state, evidence bundle, worker claims, learning decisions, and open task steps in the * returned snapshot are never a mix of the current branch and a sibling branch's history. */ export declare function buildGoalRuntimeSnapshot(args: { sessionManager: Pick; settings: GoalRuntimeSnapshotSettings; /** * Live lane records (queued/running/terminal), independent of branch scoping. Used ONLY to (a) * detect a worker in flight against the active goal's open requirement ("waiting" — see * `evaluateGoalContinuation`'s `inFlightGoalLaneIds`), and (b) surface this goal's cumulative * worker/subagent spend (advisory — see `GoalState.continuationWorkerSpendUsd`). Optional so * every pre-existing caller (hand-built snapshots, tests) that predates lane-awareness keeps * compiling and behaving byte-identically: omitting it disables both the "waiting" branch and the * worker-spend overlay, and never changes any OTHER continuation outcome. */ laneRecords?: readonly LaneRecord[]; /** * Current time as an ISO-string factory, threaded into `evaluateGoalContinuation`'s never-hang * wait-timeout check (`now`/`maxWorkerWaitMs` — see there) alongside `maxWorkerWaitMs` below. * Defaults to the real wall clock. A factory (not a plain string) so a caller/test can inject a * fixed clock without freezing global `Date`. */ now?: () => string; /** * Maximum milliseconds a bound in-flight requirement may wait before the continuation escalates * to `worker_wait_timeout` instead of `"waiting"` forever (see `evaluateGoalContinuation`). * Defaults to `DEFAULT_GOAL_WORKER_WAIT_MS`. */ maxWorkerWaitMs?: number; /** * Live per-lane worktree-sync status, independent of branch scoping -- exactly like `laneRecords`, * this builder performs NO I/O of its own; the caller derives this array (e.g. from * `core/worktree-sync/git-engine.ts`'s live status) and supplies it ready-made. Used to (a) build * `requirementWorktreeStates` (per-requirement projection, matched via `boundLaneId`) and (b) * derive the `laneSyncConflictLaneKeys`/`syncRequiredLaneKeys` sets threaded into * `evaluateGoalContinuation`. Optional so every pre-existing caller (predating worktree-sync * awareness) keeps compiling and behaving byte-identically: omitting it disables both, and never * changes any OTHER continuation outcome. */ worktreeLaneStatus?: readonly GoalRuntimeWorktreeLaneStatus[]; /** Durable worker DAG projection, supplied only when the delegate capability has been loaded. */ taskRuntime?: TaskRuntimeProjection; /** Live background tool_task records for this session. */ backgroundToolTasks?: readonly BackgroundToolTaskRef[]; }): GoalRuntimeSnapshot; //# sourceMappingURL=goal-runtime-snapshot.d.ts.map