import { type RuntimeProfile } from "./runtime-profile.js"; import type { GoalEvidence, GoalTerminalReceipt } from "./goal-bound.js"; import type { SerialDispatchSettlement } from "../plugin/runtime-bridge.js"; import { type OperatorContractRepairFileIdentity } from "./operator-contract-repair.js"; export declare const OPERATOR_LIMITS: Readonly<{ units: 32; planBytes: number; packetBytes: number; remediationReserve: 32; }>; export interface OperatorContractDiagnostic { readonly document: "approval" | "proposal" | "plan" | "handoff" | "manifest" | "controls"; readonly pointer: string; readonly code: string; readonly rule: string; readonly repair_kind: "repair-field" | "repair-proof-mapping" | "retry-storage-after-cleanup"; readonly length?: number; readonly limit?: number; readonly unit_index?: number; readonly repair_paths?: readonly string[]; readonly expected?: string; readonly actual_type?: "array" | "boolean" | "integer" | "null" | "number" | "object" | "string" | "undefined"; } export declare class OperatorContractError extends Error { readonly diagnostics: readonly OperatorContractDiagnostic[]; readonly diagnostics_truncated: boolean; constructor(diagnostics: readonly OperatorContractDiagnostic[]); } export interface OperatorUnit { readonly id: string; readonly title: string; readonly objective: string; readonly read: readonly string[]; readonly write: readonly string[]; readonly validation: readonly string[]; readonly acceptance_indices: readonly number[]; } export interface OperatorGitLifecycle { readonly branch_create: { readonly branch: string; readonly start_ref: string; }; readonly commit: { readonly message: string; }; readonly post_commit_validation: readonly string[]; /** * Paths no unit may write during implementation, pre-approved for remediation only. A write union * has to be authored before any implementation or review exists, so a review finding whose fix sits * one file outside it otherwise strands a complete candidate on a user decision. The reserve makes * that margin explicit at approval time instead of leaving it to be predicted exactly. */ readonly remediation_reserve?: readonly string[]; /** * Exactly the paths the host itself named in a prior remediation write-scope rejection. It is not a * free-form expansion: the host rejects any entry it did not record, so the root can only consent to * the host's own list after returning the blocked decision to the user. */ readonly remediation_scope_expansion?: readonly string[]; } export interface OperatorPlan { readonly schema_version: "0.1"; readonly acceptance: readonly string[]; readonly acceptance_proof: readonly (readonly string[])[]; readonly source_refs: readonly string[]; readonly goal_declaration: Record; readonly units: readonly OperatorUnit[]; readonly git_lifecycle?: OperatorGitLifecycle; } export interface OperatorTask { readonly description: string; readonly subagent_type: string; readonly prompt: string; readonly task_id?: string; } export interface OperatorRepairValidationRetryBinding { readonly authority: "operator-repair-validation-retry"; readonly operator_run_id: string; readonly unit_id: string; readonly operator_generation: number; readonly plan_hash: string; readonly control_hash: string; readonly operator_acceptance_fingerprint: string; readonly validation_commands: readonly string[]; readonly repair_fingerprint: string; } export interface OperatorRepairValidationRetrySource { readonly taskID: string; readonly operatorRunID: string; readonly operatorUnitID: string; readonly childSessionID: string; readonly operatorAcceptanceFingerprint: string; readonly validationCommands: readonly string[]; readonly repairFingerprint: string; readonly binding: OperatorRepairValidationRetryBinding; } export type OperatorProposal = { status: "prepared"; state: OperatorState; } | { status: "invalid-plan"; draft_id: string; diagnostics: readonly OperatorContractDiagnostic[]; diagnostics_truncated: boolean; }; type OperatorPhase = "prepared" | "running" | "awaiting-decision" | "awaiting-acceptance" | "completed" | "cancelled"; interface UnitState { readonly unit: OperatorUnit; readonly task: OperatorTask; readonly handoffPath: string; readonly manifestPath: string; readonly hashes: readonly string[]; status: "pending" | "running" | "succeeded" | "failed" | "cancelled"; callID: string | null; childSessionID: string | null; evidence: readonly GoalEvidence[]; resultClass: string | null; repairValidationAttempts: number; repairValidation: { readonly repair_fingerprint: string; readonly child_session_id: string; readonly commands: readonly string[]; readonly removed_paths: readonly string[]; candidate_fingerprint: string | null; next_index: number; } | null; } interface OperatorGitLifecycleState { readonly branch: string; readonly startRef: string; readonly startOID: string; readonly originalHead: string; readonly originalRef: string | null; readonly commitMessage: string; readonly writeUnion: readonly string[]; /** * Approved for remediation replacements only. Never widens this run's own unit write enforcement. * Optional because states persisted before the reserve existed load without it. */ readonly remediationReserve?: readonly string[]; readonly postCommitValidation: readonly string[]; committedHead: string | null; commitProvenance?: "host-created" | "existing-history" | "inherited-parent" | "uncommitted-baseline" | null; /** Uncommitted paths a prior unit left at this lifecycle's baseline, carried forward inside the declared write scope. */ carriedPaths?: readonly string[]; } interface OperatorContractRepairState { readonly code: "operator-git-change-outside-write-union"; readonly unit_id: string; readonly diagnostics: readonly OperatorContractDiagnostic[]; readonly diagnostics_truncated: boolean; readonly repair_generation: 0; readonly mode: "discard-transient" | "unavailable"; readonly repair_fingerprint: string | null; readonly files: readonly OperatorContractRepairFileIdentity[]; readonly remaining_validation: readonly string[]; } export interface OperatorAcceptanceAnchor { readonly taskID: string; readonly handoffPath: string; readonly handoffHash: string; } export interface OperatorState { readonly schema_version: "0.1"; readonly profile: string; readonly rootSessionID: string; readonly runID: string; readonly planHash: string; readonly acceptance: readonly string[]; readonly acceptanceProof: readonly (readonly string[])[]; readonly acceptanceFingerprint: string; readonly sourceRefs: readonly string[]; readonly createdAt: string; readonly parentRunID: string | null; readonly priorAcceptedUnits: readonly OperatorAcceptanceAnchor[]; readonly remediationParent: { readonly taskID: string; readonly committedHead: string; readonly runID?: string; readonly acceptanceFingerprint?: string; readonly approvedWriteUnion?: readonly string[]; readonly approvedRemediationReserve?: readonly string[]; readonly commitMessage?: string; readonly commitProvenance?: "host-created" | "existing-history" | "inherited-parent" | "uncommitted-baseline"; } | null; readonly gitLifecycle: OperatorGitLifecycleState | null; contractRepair: OperatorContractRepairState | null; /** Transient paths a cancelled active repair left behind; clearing them reopens replacement. */ repairResidualPaths: readonly string[]; /** * Paths this host refused on the most recent remediation write-scope rejection. It is the only list * a later remediation_scope_expansion may name, so consent cannot widen beyond what was reported. */ pendingScopeExpansion: readonly string[]; /** Real user turn carrying host approval when pendingScopeExpansion was recorded. */ pendingScopeExpansionApprovalTurnID?: string | null; repairGeneration: number; generation: number; sequence: number; phase: OperatorPhase; operatorCallID: string | null; operatorSessionID: string | null; dispatched: number; units: UnitState[]; decision: string | null; receipt: GoalTerminalReceipt | null; } export declare function operatorGitPathAuthorized(path: string, scopes: readonly string[], platform?: NodeJS.Platform): boolean; export declare function parseOperatorPlan(value: unknown): OperatorPlan; /** Root-owned durable queue. It never executes code, changes acceptance, or accepts a candidate. */ export declare class OperatorRuntime { readonly profile: RuntimeProfile; private readonly gitPath; private readonly states; private readonly writes; private readonly transactions; readonly projectRoot: string; constructor(projectRoot: string, profile: RuntimeProfile, gitPath?: string); private file; read(root: string): Promise; private save; private serial; private validGitLifecycleState; private validContractRepairState; private validRepairFileIdentity; private validRepairValidationState; private git; /** Transients an abandoned repair left behind that still exist on disk. */ private remainingResidualRepairPaths; private cleanStatus; /** Staged, unstaged, and untracked paths of the current worktree. */ private uncommittedPaths; private createGitLifecycle; private cleanupCreatedBranch; prepare(root: string, raw: unknown, scopeApprovalTurnID?: string): Promise; private draftFile; propose(root: string, raw: unknown, scopeApprovalTurnID?: string): Promise; private proposeOnce; repair(root: string, draftID: string, patches: unknown): Promise; private prepareOnce; operatorTask(state: OperatorState): OperatorTask; /** Root-visible handle for the bounded operations delegate; its contract stays host-internal. */ dispatchTask(state: OperatorState): OperatorTask; private resolveOperatorTask; /** A bounded handle to the immutable task retained in durable operator state. */ private workerTask; private repairWorkerTask; nextWorkerTask(state: OperatorState): OperatorTask; /** Atomically claim and resolve one exact admitted prompt for its native child. */ claimAdmittedWorkerPrompt(root: string, parent: string, child: string, prompt: string): Promise<{ callID: string; prompt: string; repairValidationRetry?: { taskID: string; repairFingerprint: string; binding: OperatorRepairValidationRetryBinding; }; }>; private matchesWorkerTask; matchesRecordedWorkerTask(state: OperatorState, unitID: string, args: unknown): boolean; admitOperator(root: string, callID: string, args: unknown): Promise; private admitOperatorOnce; bindOperator(root: string, sessionID: string, prompt: string): Promise; private bindOperatorOnce; /** Atomically bind one native delegate child and reveal its admitted canonical contract only there. */ claimAdmittedOperatorPrompt(root: string, parent: string, child: string, prompt: string): Promise; next(root: string, actor: string): Promise; private nextOnce; admitWorker(root: string, actor: string, callID: string, args: unknown): Promise; private admitWorkerOnce; rejectedAdmission(root: string, callID: string): Promise; rejectDispatch(root: string, callID: string, decision?: string): Promise; private rejectDispatchOnce; private repairPathProtected; private captureRepairFile; private captureContractRepair; recordContractRepair(root: string, actor: string, error: OperatorContractError, command: string): Promise; applyContractRepair(root: string, input: { run_id: string; unit_id: string; repair_fingerprint: string; decision: string; paths: readonly string[]; }, assertValidationBudget: () => Promise): Promise; repairValidationAccess(root: string, actor: string): Promise<{ unit_id: string; task_id: string; handoff_path: string; manifest_path: string; manifest_hash: string; repair_fingerprint: string; expected_command: string | null; complete: boolean; } | null>; recordRepairValidationResult(root: string, actor: string, command: string, exit: number): Promise; completeRepairValidation(root: string, callID: string, evidence: readonly GoalEvidence[]): Promise; failRepairValidation(root: string, callID: string, decision: string): Promise; abortAppliedContractRepair(root: string, decision: string): Promise; operatorRejected(root: string): Promise; private operatorRejectedOnce; settled(result: SerialDispatchSettlement): Promise; private settledOnce; observeChild(root: string, callID: string, childID: string): Promise; private observeChildOnce; operatorReturned(root: string): Promise; private operatorReturnedOnce; interrupted(root: string, reason: string): Promise; private interruptedOnce; terminal(root: string, receipt: GoalTerminalReceipt): Promise; private terminalOnce; required(root: string): Promise; private repairValidationRetryFingerprint; private repairValidationRetryBinding; canRetryRepairValidation(state: OperatorState): boolean; resumeRepairValidation(root: string, runID: string, authorize: (source: OperatorRepairValidationRetrySource) => Promise): Promise; resume(root: string, runID: string, recovered: ReadonlyMap, unstarted?: ReadonlySet): Promise; requireAcceptanceRemediation(root: string, runID: string): Promise; draftStatus(root: string): Promise; completionGoalFingerprint(state: OperatorState): Promise; verifyContinuityControls(state: OperatorState): Promise; packet(state: OperatorState): unknown; continuationCheckpoint(root: string): Promise; private verifyControls; private gitPaths; private pathAuthorized; /** * Persist the exact paths a remediation write-scope rejection refused. The root reports them to the * user; only these may later reappear as remediation_scope_expansion. */ private recordPendingScopeExpansion; /** * Accept a declared expansion only when the parent durably recorded every path as refused. An * undeclared or invented entry is a contract error, not a silently narrowed grant. */ private authorizedScopeExpansion; private gitAcceptanceReadiness; beforePostCommitValidation(root: string, actor: string, command: string): Promise; preflightPostCommitValidation(root: string, actor: string, command: string): Promise; postCommitLocked(root: string): Promise; private currentAuthorizedGitChanges; private assertRemovedRepairPathsAbsent; private repairValidationCandidateFingerprint; private finalizeGitLifecycle; /** Whether every commit between the lifecycle start and head touches only authorized paths. */ private authorizedHistory; private assertCommitPathsAuthorized; private inheritParentCommit; } export {};