import { RemediationPlan, RemediationItemState, ClarificationRequest, ClosingPlan, CoverageLedger, RemediationHostHandoffRecord } from "./types.js"; export interface RemediationState { status: "pending" | "planning" | "waiting_for_clarification" | "implementing" | "triage" | "waiting_for_triage" | "closing" | "complete"; plan?: RemediationPlan; items?: Record; clarifications?: ClarificationRequest[]; closing_plan?: ClosingPlan; started_at?: string; step_count?: number; plan_coverage?: CoverageLedger; /** * Reason the run was routed to close without all items reaching a terminal * status. Set by the triage phase on `halt` so the close phase can stamp * a `user_halted` marker in the partial report. */ closing_context?: "user_halted"; /** * Union of repo-relative paths every ACCEPTED node has actually cherry-picked * into the main tree this run (ground truth, path-sorted, de-duplicated). * Populated from accepted host results. Each entry is validated against the * prompt-bound write scope before it can advance item state. * * This is the close phase's staging manifest (`collectStagingFiles` in * `src/remediate/phases/close.ts`): the invariant "remediation close must * never commit files the run didn't touch" is enforced by staging exactly * `applied_edit_surface ∩ currently-dirty`, never a repo-wide sweep. * * The close phase additionally unions in each resolved item's declared * `item_spec.touched_files` / finding `affected_files` as a conservative * fallback for current states created before host-result ingestion recorded * this surface. */ applied_edit_surface?: string[]; /** * Repo-relative paths that were ALREADY dirty (changed vs HEAD, or untracked) * when this run's plan was created — captured once via `stagedAndUntracked` * at the extracted-plan join site (src/remediate/steps/nextStep.ts), path-sorted, * and never re-captured on a replan (re-capturing after edits landed would * wrongly classify the run's own hand-applied work as pre-existing dirt). * * Consumed by the close phase's `resolveEditSurfaceManifest`: a file that was * dirty BEFORE the run started cannot be one of the run's edits, so it is * excluded from the DECLARED (fallback) manifest sources * (`item_spec.touched_files` / finding `affected_files` — plan-time * declarations/write-grants, not verified diffs). Ground-truth entries * (`applied_edit_surface`) are also excluded from closing-stage staging: a * landed commit proves attribution of the commit, not ownership of any * still-dirty pre-run content at that path. * * Absent on states created before this field existed: treated as empty — no * exclusions, preserving prior behavior for in-flight runs. */ run_start_dirty?: string[]; /** * Independent digest binding for the currently emitted host workload. * Cleared once that workload has no pending items. Production result * ingestion requires this record before it trusts any host-written file. */ host_handoff?: RemediationHostHandoffRecord; } export declare const LOCK_TIMEOUT_MS: number; export declare class StateStore { private artifactsDir; private readonly _correlationId?; /** * Thin adapter over the shared locked JSON store: `state.json` guarded by a * sibling `state.lock`. The lock-timeout derivation and the read-under-lock → * atomic-write cycle (shared `writeJsonFile`: temp + atomic rename, * INV-remediate-state-04) are single-sourced there; only the * RemediationState schema validation lives here. */ private readonly store; constructor(artifactsDir: string, _correlationId?: string | undefined); init(): Promise; /** * Read state.json and schema-validate it. Returns null when the file is * absent. Throws when the file is present but fails schema validation * (corrupt or version-drifted — callers must not silently swallow such a * state and hand it to the state machine). INV-remediate-state-01. * * Does NOT hold the lock — use `mutate` for any read-modify-write transition * that requires TOCTOU safety (INV-remediate-state-02). */ loadState(): Promise; /** * TOCTOU-safe read-modify-write: acquires the file lock ONCE, loads the * current state (or null), passes it to `fn`, and writes the returned state * before releasing the lock. No other holder can interleave between the load * and the save. INV-remediate-state-02 + INV-remediate-state-03. */ mutate(fn: (current: RemediationState | null) => Promise): Promise; /** * Save state.json unconditionally (no TOCTOU protection, no read — so a * corrupt on-disk state never blocks recovery). Prefer `mutate` for * transitions; use this only when the caller holds an external guarantee * that no concurrent writer exists (e.g. single-agent close phase). */ saveState(state: RemediationState): Promise; } //# sourceMappingURL=store.d.ts.map