import { type ClaudeProcessFactory } from "../bot/claude-process.js"; import { SessionStore } from "../bot/session-store.js"; import type { GoalSpec } from "./goal-parser.js"; import { type MetricMeasurer } from "./evaluator.js"; import { type GoalRunSummary } from "./tracker.js"; /** * v0.4 — goal-runner. * * Per docs/plan/v0.4-autonomous-engine.md §3 + §8. * * Drives one autonomous goal run end-to-end: * 1. Load goal.md + AGENTS.md, resolve paths, preflight Input guard * 2. Open a dedicated background PM session (bg--) * 3. Cycle loop: * a) pre-cycle git-snapshot commit * b) PM executes the pipeline via Task tool (each stage = one Task call) * c) evaluator measures + keep/discard * d) tracker appends results.tsv + _best.json * e) Runtime guard checks budget/discard streak → continue or stop * f) CONFIRMING state machine (2 consecutive keeps → CONVERGED → ship) * 4. Final summary written to /_last-run.md (morning-brief reads) * * The runner does NOT post to the messenger directly (Output guard). Results * surface via morning-brief cron on the next 08:00 brief. */ export type GoalRunState = "RUNNING" | "CONFIRMING1" | "CONFIRMING2" | "CONVERGED" | "STOPPED"; export interface GoalRunnerDeps { workspace: string; claude: ClaudeProcessFactory; sessions: SessionStore; measurer: MetricMeasurer; /** Hard timeout per Claude invocation in ms. Falls back to AGENTS.md value × 1000. */ invokeTimeoutMs?: number; } export interface GoalRunOptions { goal: GoalSpec; /** Optional explicit run-id; default = ISO of start time. */ runId?: string; /** Override AGENTS.md path resolution (rarely used; tests). */ agentsMdWorkspace?: string; } export interface GoalRunReport { goalId: string; runId: string; startedAt: string; endedAt: string; state: GoalRunState; cyclesAttempted: number; cyclesKept: number; cyclesDiscarded: number; totalCostUsd: number; bestCommit?: string; shipCandidateCommit?: string; terminationReason: string; oscillationWarning: boolean; summary: GoalRunSummary; } export declare class GoalRunner { private readonly deps; constructor(deps: GoalRunnerDeps); run(opts: GoalRunOptions): Promise; private failFast; private processStreamLine; } /** Generate a session-id slug for the background PM session. Caller can also * derive their own; this is a convenience for CLI display. */ export declare function backgroundSessionId(goalId: string): string;