import type { CorrectionPayload, Result, WorkflowError, WorkflowGateMode, WorkflowPhase, WorkflowPhaseRecord, WorkflowPhaseStatus, WorkflowRunRecord } from '../types/index.js'; export type WorkflowRunOptions = { storyId: string; gates: WorkflowGateMode; maxIterations: number; profiles?: string[]; deliveryMode?: WorkflowRunRecord['deliveryMode']; baseline?: WorkflowRunRecord['baseline']; }; export type PhaseOutcome = { kind: 'done'; notes: string; } | { kind: 'qa-fail'; notes: string; correction?: CorrectionPayload; } | { kind: 'reject'; targetPhase: WorkflowPhase; findings: string; correction?: CorrectionPayload; } | { kind: 'gate-pause'; reviewId: string; } | { kind: 'decompose'; voter: 'ba' | 'ta'; reason: string; suggestedSplits: string[]; }; export type PendingDelegatedPhaseDecision = { kind: 'ready'; } | { kind: 'failed'; status: 'failed' | 'timeout' | 'rejected'; } | { kind: 'still-running'; }; /** * GH-748: pure decision logic for `workflow run --autonomous`'s background- * dispatch resume check — separated from the I/O (reading spawn-sessions.jsonl, * persisting the run) so it's unit-testable without spinning up a real bridge. * `still-running` also covers "not found yet" (the bridge may not have * persisted the session this instant) — never treated as failed. */ export declare function decidePendingDelegatedPhase(spawnSessionId: string, spawnSessions: Array<{ id: string; status: string; }>): PendingDelegatedPhaseDecision; export declare function workflowRunPath(cwd: string): string; export declare function createWorkflowRun(cwd: string, opts: WorkflowRunOptions): WorkflowRunRecord; export declare function readWorkflowRun(cwd: string, id: string): WorkflowRunRecord | undefined; export declare function advanceWorkflow(cwd: string, run: WorkflowRunRecord, phase: WorkflowPhase, outcome: PhaseOutcome): Result; export declare function initPhase(cwd: string, run: WorkflowRunRecord, phase: WorkflowPhase, rejectionContext?: string): WorkflowPhaseRecord; export declare function listWorkflowRuns(cwd: string): WorkflowRunRecord[]; export declare function persistWorkflowRun(cwd: string, run: WorkflowRunRecord): WorkflowRunRecord; export type GateResumeDecision = { approved: true; } | { approved: false; reason: string; }; /** The latest review for a mandatory gate is authoritative; older approvals cannot mask later rejection. */ export declare function validateGateResume(cwd: string, run: WorkflowRunRecord): GateResumeDecision; export declare function toAutonomousRunView(run: WorkflowRunRecord): import('../types/index.js').AutonomousRunView | null; export declare function pausedPhaseAndNext(run: WorkflowRunRecord, cwd?: string): { pausedPhase: WorkflowPhase; nextPhase: WorkflowPhase; reviewId: string; } | undefined; export type CorrectionReturn = { reviewId: string; returnTarget: WorkflowPhase; findings?: string; correctionIteration: number; }; export declare function detectCorrectionReturn(cwd: string, run: WorkflowRunRecord): CorrectionReturn | undefined; /** * Settle a run whose phases have all been executed: clear gates approved since the * last write and promote the run to `done`. Used by `workflow run --resume` when * there is no phase left to run, so resuming a finished run converges instead of * re-executing its last phase (GH-641). */ export declare function settleCompletedRun(cwd: string, run: WorkflowRunRecord): WorkflowRunRecord; export declare function midPhaseGates(run: WorkflowRunRecord): Array<{ phase: WorkflowPhase; reviewId: string; }>; export declare function updatePhaseStatus(cwd: string, run: WorkflowRunRecord, phase: WorkflowPhase, status: WorkflowPhaseStatus, extra?: { clarificationIds?: string[]; }): WorkflowRunRecord; export declare function addMidPhaseGate(cwd: string, run: WorkflowRunRecord, phase: WorkflowPhase, reviewId: string): WorkflowRunRecord; /** * Roll back a run to `targetPhase` (inclusive). * * All phase records from `targetPhase` onward are removed so the run can * be re-executed from that phase via `workflow run --resume`. The run * status is reset to `running` and the rollback reason is recorded. */ export declare function rollbackWorkflowRun(cwd: string, run: WorkflowRunRecord, targetPhase: WorkflowPhase, reason: string): Result;