import type { FeatureMapSnapshot, FixAllState } from "@kenkaiiii/gg-protocol"; import { type CheckResult, type FixCheck } from "./fix-all-checks.js"; import { type Preflight, type RollbackRequest } from "./fix-all-git.js"; import { type FixAllJournal, type LoadedJournal } from "./fix-all-journal.js"; /** Group failures in a row before the run pauses (a broken provider or toolchain). */ export declare const FAIL_STREAK_PAUSE = 3; export interface FixAllPromptResult { /** The agent's last reply. */ readonly reply: string; /** The run failed (a provider error), in plain words. */ readonly error: string | null; /** The agent submitted a plan instead of fixing (the plan is already cleared). */ readonly planSubmitted: boolean; } /** A run's folder and branch, and the commit it started at: what an ended run with no fixes leaves. */ export interface FixAllRunFolder { readonly root: string; readonly branch: string; readonly head: string; } /** What the daemon does to run a run in its own folder: a background session there takes it. */ export type FixAllLaunchRequest = { readonly kind: "start"; /** The checkout Start was pressed in: the branch starts from its HEAD. */ readonly from: string; readonly key: string; readonly startCount: number; } | { readonly kind: "resume"; /** The run's folder. */ readonly root: string; readonly key: string; readonly confirmRestructure?: boolean; }; export interface FixAllRunnerDeps { readonly cwd: string; /** `~/.gg/feature-maps`. */ readonly stateDir: string; readonly map: { snapshot(): Promise; refresh(): Promise; act(featureId: string, actionId: string): Promise; }; readonly session: { /** A fresh session with the step's header row. */ begin(header: string): Promise; prompt(text: string, label: string): Promise; /** Stop the agent's run and its background agents (not called on the global Stop). */ abort(): void; /** * Wait for background agents the fix started; `onWait` hears how many still work. False when * they were still working at the deadline (they're interrupted then). */ settle(signal: AbortSignal, onWait: (working: number) => void): Promise; }; /** This session's current conversation file: the one to open to watch the run. */ readonly sessionPath?: () => string | null; readonly git: { /** The checkout root, or null outside Git. */ root(dir: string): Promise; /** The repository's main folder, the same from every worktree: what a run is keyed by. */ repoKey(dir: string): Promise; preflight(dir: string, opts?: { branch?: string; }): Promise; proposeBranch(dir: string, now: Date): Promise; currentBranch(dir: string): Promise; head(dir: string): Promise; isAncestor(dir: string, commit: string): Promise; changedPaths(dir: string): Promise; filesToDiscard(dir: string, checkpoint: string): Promise; commit(dir: string, branch: string, message: string): Promise; rollback(req: RollbackRequest): Promise; }; readonly checks: { resolve(root: string): Promise; /** What a fresh folder runs before its first checks (installs), each like a check. */ setup(root: string, checks: readonly FixCheck[]): Promise; /** A folder's build (its `build` script), for checks that need its output; null without one. */ build(root: string, dir?: string): FixCheck | null; /** The checks for one fix, given the files it changed (the full set when it can't narrow). */ scope(root: string, commands: readonly FixCheck[], changed: readonly string[]): FixCheck[]; run(root: string, commands: readonly FixCheck[], signal: AbortSignal, onCommand?: (index: number, command: FixCheck) => void): Promise; }; /** Why the window can't start a run now (agent running, task sweep, autopilot, Goal), or null. */ readonly busyReason: () => string | null; /** Other sessions on this checkout, and whether any is working (only that clashes with a run). */ readonly othersOnCheckout: (root: string) => Promise<{ count: number; busy: boolean; }>; /** Hold the window's run claim for the whole run; false when something else holds it. */ readonly claim: () => boolean; readonly release: () => void; /** To every session of the repository (`key`), or this one's while it has none. */ readonly broadcast: (state: FixAllState, key: string | null) => void; /** This runner took the repository's run (true), or let it go once it ended (false). */ readonly onLive?: (key: string, live: boolean) => void; /** The run ended (stopped, dismissed or never started) without committing a fix: remove its folder. */ readonly discardFolder?: (run: FixAllRunFolder) => void; /** Run it in its own folder: a background session there takes it; resolves to its runner. */ readonly launch: (request: FixAllLaunchRequest) => Promise; readonly journal: { load(file: string): Promise; save(file: string, journal: FixAllJournal): Promise; remove(file: string): Promise; }; readonly log: (level: "INFO" | "WARN", message: string, data?: Record) => void; readonly now?: () => Date; } export interface FixAllRunner { state(): Promise; /** Fast guards, then launches the run in a folder of its own. Throws FixAllGuardError. */ start(): Promise; /** In the run's new folder, on its branch: set up, baseline checks, then the loop. */ beginInWorktree(opts: { branch: string; startCount: number; }): Promise; pause(): Promise; resume(opts: { confirmRestructure?: boolean; }): Promise; /** `fromCancel`: the global Stop, which already aborted the agent. On a finished run: dismiss. */ stop(fromCancel?: boolean): Promise; /** A run is working (not paused or waiting): questions get the unattended deadline. */ active(): boolean; /** Its loop is running: typed messages in sessions on its folder are held. */ working(): boolean; /** This runner owns the repository's run until it ends or is dismissed (keeps its session). */ owns(): boolean; /** The run's folder while this runner owns it. */ folder(): string | null; /** The repository key, once known. */ key(): string | null; /** Resolves once the background loop settles (tests). */ settled(): Promise; } /** The reason while a pause takes effect; the app keys its "Pausing…" off it. */ export declare const PAUSING = "Pausing\u2026"; /** How long a fix's background agents may keep working before its checks run without them. */ export declare const FIX_ALL_SETTLE_MS: number; /** A typed prompt or `!` command while a run works the checkout: it would land in the fixes. */ export declare const FIX_ALL_HOLDS_CHAT = "Fix all is working in this folder, so a message or command now would get mixed into its fixes. Pause it first."; /** The Fix all run of each repository, shared by every session of it on any checkout (daemon-wide). */ export interface FixAllCheckout { /** The runner that owns the repository's run (keyed by its main folder), or null. */ live(key: string): FixAllRunner | null; setLive(key: string, runner: FixAllRunner, live: boolean): void; /** A folder's checkout root (cached). */ rootOf(dir: string): Promise; /** A folder's repository key: its main folder (cached). */ keyOf(dir: string): Promise; /** To every session of the repository `key`, in order. */ broadcast(key: string, type: string, data: unknown): void; } /** * Why a typed message or `!` command in a session on `dir` is held, or null: only while the * repository's run is working, and only on the run's own folder (the project's folder and other * worktrees stay free). */ export declare function fixAllHoldsAt(checkout: FixAllCheckout, dir: string): Promise; /** Fixes are checked scoped to what they touched; the full checks run after this many. */ export declare const FULL_CHECKS_EVERY = 10; export declare function createFixAllRunner(deps: FixAllRunnerDeps): FixAllRunner;