import type { LoopBudget, LoopRecord, LoopTask, MachineState } from "../../contracts/index.js"; import { type LedgerEvent } from "./ledger.js"; export interface RunContract { runId: string; workspaceId: string; projectId: string; task: LoopTask; budget: LoopBudget; createdAt: string; metadata?: Record; } export interface AttemptArtifacts { /** Compiled PromptPacket written as compiled-context.json */ compiledContext: unknown; /** Structured verification evidence captured from the authoritative MartinLoop verifier (optional) */ verification?: unknown; /** Unified diff string from the patch (optional) */ diff?: string; /** Raw verifier command output (optional) */ verifierOutput?: string; /** Grounding scan result (optional) */ groundingScan?: unknown; /** Safety leash artifact captured for a blocked or escalated attempt (optional) */ leash?: unknown; /** Patch score artifact captured for Phase 10 patch-truth decisions (optional) */ patchScore?: unknown; /** Patch keep/discard/escalate decision artifact (optional) */ patchDecision?: unknown; /** Rollback boundary captured before an attempt mutates the repo (optional) */ rollbackBoundary?: unknown; /** Rollback restore outcome captured after discard/escalation/failure (optional) */ rollbackOutcome?: unknown; } /** * RunStore isolates all filesystem persistence from orchestration logic. * runMartin accepts an optional store; when provided, every lifecycle event * is durably written before the run proceeds to the next step. */ export interface RunStore { /** * Optional runs root hint for filesystem-backed stores. * Orchestration should prefer this over recomputing the default home store. */ runsRoot?: string; /** * Write contract.json for a new run. Called once at run start. * The contract is immutable after this point. */ initRun(contract: RunContract): Promise; /** * Overwrite state.json with the current MachineState. * Called on every phase transition. */ updateState(runId: string, state: MachineState): Promise; /** * Append one event line to ledger.jsonl. Append-only — never rewrites. */ appendLedger(runId: string, event: LedgerEvent): Promise; /** * Write artifacts for a completed attempt to artifacts/attempt-/. */ writeAttemptArtifacts(runId: string, attemptIndex: number, artifacts: AttemptArtifacts): Promise; /** * Persist the latest canonical loop record snapshot when the caller has one. * Optional to avoid breaking custom RunStore implementations. */ writeLoopRecord?(runId: string, loop: LoopRecord): Promise; } export declare function resolveRunsRoot(env?: NodeJS.ProcessEnv): string; export declare function runDir(runsRoot: string, runId: string): string; export declare function artifactDir(runsRoot: string, runId: string, attemptIndex: number): string; /** * Filesystem-backed RunStore. Writes to: * //contract.json * //state.json * //ledger.jsonl * //artifacts/attempt-/compiled-context.json * //artifacts/attempt-/diff.patch (if diff provided) * //artifacts/attempt-/verifier-output.txt (if provided) * //artifacts/attempt-/grounding-scan.json (if provided) * //artifacts/attempt-/leash.json (if leash provided) * //artifacts/attempt-/patch-score.json (if patchScore provided) * //artifacts/attempt-/patch-decision.json (if patchDecision provided) * //artifacts/attempt-/rollback-boundary.json (if rollbackBoundary provided) * //artifacts/attempt-/rollback-outcome.json (if rollbackOutcome provided) */ export declare function createFileRunStore(options?: { runsRoot?: string; }): RunStore;