@gajae-code/coding-agent 0.2.5 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/types/async/job-manager.d.ts +91 -2
  3. package/dist/types/cli/args.d.ts +1 -1
  4. package/dist/types/commands/deep-interview.d.ts +3 -0
  5. package/dist/types/commands/harness.d.ts +37 -0
  6. package/dist/types/config/keybindings.d.ts +5 -0
  7. package/dist/types/config/settings-schema.d.ts +10 -4
  8. package/dist/types/config/settings.d.ts +2 -0
  9. package/dist/types/debug/crash-diagnostics.d.ts +45 -0
  10. package/dist/types/debug/runtime-gauges.d.ts +6 -0
  11. package/dist/types/deep-interview/render-middleware.d.ts +6 -0
  12. package/dist/types/eval/py/executor.d.ts +2 -0
  13. package/dist/types/eval/py/kernel.d.ts +2 -0
  14. package/dist/types/exec/bash-executor.d.ts +10 -0
  15. package/dist/types/extensibility/custom-tools/types.d.ts +1 -0
  16. package/dist/types/extensibility/extensions/types.d.ts +6 -0
  17. package/dist/types/extensibility/shared-events.d.ts +1 -0
  18. package/dist/types/gjc-runtime/cli-write-receipt.d.ts +24 -0
  19. package/dist/types/gjc-runtime/deep-interview-runtime.d.ts +1 -0
  20. package/dist/types/gjc-runtime/state-graph.d.ts +4 -0
  21. package/dist/types/gjc-runtime/state-migrations.d.ts +33 -0
  22. package/dist/types/gjc-runtime/state-renderer.d.ts +65 -0
  23. package/dist/types/gjc-runtime/state-runtime.d.ts +2 -0
  24. package/dist/types/gjc-runtime/state-schema.d.ts +317 -0
  25. package/dist/types/gjc-runtime/state-validation.d.ts +6 -0
  26. package/dist/types/gjc-runtime/state-writer.d.ts +147 -0
  27. package/dist/types/gjc-runtime/team-runtime.d.ts +81 -7
  28. package/dist/types/gjc-runtime/workflow-command-ref.d.ts +43 -0
  29. package/dist/types/gjc-runtime/workflow-manifest.d.ts +54 -0
  30. package/dist/types/harness-control-plane/classifier.d.ts +13 -0
  31. package/dist/types/harness-control-plane/control-endpoint.d.ts +31 -0
  32. package/dist/types/harness-control-plane/finalize.d.ts +47 -0
  33. package/dist/types/harness-control-plane/frame-mapper.d.ts +29 -0
  34. package/dist/types/harness-control-plane/operate.d.ts +35 -0
  35. package/dist/types/harness-control-plane/owner.d.ts +46 -0
  36. package/dist/types/harness-control-plane/preserve.d.ts +19 -0
  37. package/dist/types/harness-control-plane/receipts.d.ts +88 -0
  38. package/dist/types/harness-control-plane/rpc-adapter.d.ts +66 -0
  39. package/dist/types/harness-control-plane/seams.d.ts +21 -0
  40. package/dist/types/harness-control-plane/session-lease.d.ts +65 -0
  41. package/dist/types/harness-control-plane/state-machine.d.ts +19 -0
  42. package/dist/types/harness-control-plane/storage.d.ts +53 -0
  43. package/dist/types/harness-control-plane/types.d.ts +162 -0
  44. package/dist/types/hooks/skill-keywords.d.ts +2 -1
  45. package/dist/types/hooks/skill-state.d.ts +23 -29
  46. package/dist/types/internal-urls/agent-protocol.d.ts +2 -2
  47. package/dist/types/internal-urls/artifact-protocol.d.ts +2 -2
  48. package/dist/types/internal-urls/registry-helpers.d.ts +8 -7
  49. package/dist/types/internal-urls/types.d.ts +4 -0
  50. package/dist/types/lsp/index.d.ts +10 -10
  51. package/dist/types/modes/bridge/auth.d.ts +12 -0
  52. package/dist/types/modes/bridge/bridge-client-bridge.d.ts +9 -0
  53. package/dist/types/modes/bridge/bridge-mode.d.ts +44 -0
  54. package/dist/types/modes/bridge/bridge-ui-context.d.ts +88 -0
  55. package/dist/types/modes/bridge/event-stream.d.ts +8 -0
  56. package/dist/types/modes/components/custom-editor.d.ts +6 -0
  57. package/dist/types/modes/components/hook-selector.d.ts +1 -0
  58. package/dist/types/modes/components/jobs-overlay-model.d.ts +31 -0
  59. package/dist/types/modes/components/jobs-overlay.d.ts +30 -0
  60. package/dist/types/modes/components/status-line/types.d.ts +2 -0
  61. package/dist/types/modes/components/status-line.d.ts +2 -0
  62. package/dist/types/modes/controllers/input-controller.d.ts +1 -0
  63. package/dist/types/modes/controllers/selector-controller.d.ts +8 -0
  64. package/dist/types/modes/index.d.ts +1 -0
  65. package/dist/types/modes/interactive-mode.d.ts +2 -0
  66. package/dist/types/modes/jobs-observer.d.ts +57 -0
  67. package/dist/types/modes/rpc/host-tools.d.ts +1 -16
  68. package/dist/types/modes/rpc/host-uris.d.ts +1 -38
  69. package/dist/types/modes/shared/agent-wire/command-dispatch.d.ts +20 -0
  70. package/dist/types/modes/shared/agent-wire/command-validation.d.ts +2 -0
  71. package/dist/types/modes/shared/agent-wire/event-envelope.d.ts +24 -0
  72. package/dist/types/modes/shared/agent-wire/handshake.d.ts +46 -0
  73. package/dist/types/modes/shared/agent-wire/host-tool-bridge.d.ts +16 -0
  74. package/dist/types/modes/shared/agent-wire/host-uri-bridge.d.ts +17 -0
  75. package/dist/types/modes/shared/agent-wire/protocol.d.ts +44 -0
  76. package/dist/types/modes/shared/agent-wire/responses.d.ts +4 -0
  77. package/dist/types/modes/shared/agent-wire/scopes.d.ts +18 -0
  78. package/dist/types/modes/shared/agent-wire/ui-request-broker.d.ts +42 -0
  79. package/dist/types/modes/shared/agent-wire/ui-result.d.ts +27 -0
  80. package/dist/types/modes/types.d.ts +2 -0
  81. package/dist/types/sdk.d.ts +4 -0
  82. package/dist/types/session/agent-session.d.ts +19 -1
  83. package/dist/types/skill-state/active-state.d.ts +2 -0
  84. package/dist/types/skill-state/deep-interview-mutation-guard.d.ts +1 -1
  85. package/dist/types/skill-state/workflow-state-contract.d.ts +25 -2
  86. package/dist/types/skill-state/workflow-state-version.d.ts +3 -0
  87. package/dist/types/task/executor.d.ts +3 -0
  88. package/dist/types/task/id.d.ts +7 -0
  89. package/dist/types/task/index.d.ts +5 -0
  90. package/dist/types/task/receipt.d.ts +85 -0
  91. package/dist/types/task/spawn-gate.d.ts +38 -0
  92. package/dist/types/task/types.d.ts +198 -14
  93. package/dist/types/tools/cron.d.ts +6 -0
  94. package/dist/types/tools/index.d.ts +2 -0
  95. package/dist/types/tools/path-utils.d.ts +1 -0
  96. package/dist/types/tools/subagent.d.ts +26 -1
  97. package/package.json +7 -7
  98. package/scripts/build-binary.ts +7 -0
  99. package/src/async/job-manager.ts +334 -6
  100. package/src/cli/args.ts +9 -2
  101. package/src/cli/auth-broker-cli.ts +1 -0
  102. package/src/cli/config-cli.ts +10 -2
  103. package/src/cli.ts +2 -0
  104. package/src/commands/deep-interview.ts +1 -0
  105. package/src/commands/harness.ts +862 -0
  106. package/src/commands/launch.ts +2 -2
  107. package/src/commands/state.ts +2 -1
  108. package/src/commands/team.ts +54 -39
  109. package/src/config/keybindings.ts +6 -0
  110. package/src/config/settings-schema.ts +13 -3
  111. package/src/config/settings.ts +5 -0
  112. package/src/dap/client.ts +17 -3
  113. package/src/debug/crash-diagnostics.ts +223 -0
  114. package/src/debug/runtime-gauges.ts +20 -0
  115. package/src/deep-interview/render-middleware.ts +372 -0
  116. package/src/defaults/gjc/skills/deep-interview/SKILL.md +1 -1
  117. package/src/defaults/gjc/skills/ralplan/SKILL.md +31 -2
  118. package/src/defaults/gjc/skills/team/SKILL.md +47 -21
  119. package/src/defaults/gjc/skills/ultragoal/SKILL.md +106 -13
  120. package/src/eval/py/executor.ts +21 -1
  121. package/src/eval/py/kernel.ts +15 -0
  122. package/src/exec/bash-executor.ts +41 -0
  123. package/src/extensibility/custom-tools/types.ts +1 -0
  124. package/src/extensibility/extensions/types.ts +6 -0
  125. package/src/extensibility/shared-events.ts +1 -0
  126. package/src/gjc-runtime/cli-write-receipt.ts +31 -0
  127. package/src/gjc-runtime/deep-interview-runtime.ts +98 -42
  128. package/src/gjc-runtime/goal-mode-request.ts +11 -3
  129. package/src/gjc-runtime/ralplan-runtime.ts +235 -43
  130. package/src/gjc-runtime/state-graph.ts +86 -0
  131. package/src/gjc-runtime/state-migrations.ts +179 -0
  132. package/src/gjc-runtime/state-renderer.ts +345 -0
  133. package/src/gjc-runtime/state-runtime.ts +1155 -46
  134. package/src/gjc-runtime/state-schema.ts +192 -0
  135. package/src/gjc-runtime/state-validation.ts +49 -0
  136. package/src/gjc-runtime/state-writer.ts +749 -0
  137. package/src/gjc-runtime/team-runtime.ts +1255 -189
  138. package/src/gjc-runtime/ultragoal-runtime.ts +460 -43
  139. package/src/gjc-runtime/workflow-command-ref.ts +239 -0
  140. package/src/gjc-runtime/workflow-manifest.generated.json +1601 -0
  141. package/src/gjc-runtime/workflow-manifest.ts +427 -0
  142. package/src/harness-control-plane/classifier.ts +128 -0
  143. package/src/harness-control-plane/control-endpoint.ts +148 -0
  144. package/src/harness-control-plane/finalize.ts +222 -0
  145. package/src/harness-control-plane/frame-mapper.ts +286 -0
  146. package/src/harness-control-plane/operate.ts +225 -0
  147. package/src/harness-control-plane/owner.ts +600 -0
  148. package/src/harness-control-plane/preserve.ts +102 -0
  149. package/src/harness-control-plane/receipts.ts +216 -0
  150. package/src/harness-control-plane/rpc-adapter.ts +276 -0
  151. package/src/harness-control-plane/seams.ts +39 -0
  152. package/src/harness-control-plane/session-lease.ts +388 -0
  153. package/src/harness-control-plane/state-machine.ts +98 -0
  154. package/src/harness-control-plane/storage.ts +257 -0
  155. package/src/harness-control-plane/types.ts +214 -0
  156. package/src/hooks/skill-keywords.ts +4 -2
  157. package/src/hooks/skill-state.ts +197 -64
  158. package/src/internal-urls/agent-protocol.ts +68 -21
  159. package/src/internal-urls/artifact-protocol.ts +12 -17
  160. package/src/internal-urls/docs-index.generated.ts +3 -2
  161. package/src/internal-urls/registry-helpers.ts +19 -16
  162. package/src/internal-urls/types.ts +4 -0
  163. package/src/lsp/client.ts +18 -2
  164. package/src/main.ts +21 -5
  165. package/src/modes/bridge/auth.ts +41 -0
  166. package/src/modes/bridge/bridge-client-bridge.ts +47 -0
  167. package/src/modes/bridge/bridge-mode.ts +520 -0
  168. package/src/modes/bridge/bridge-ui-context.ts +200 -0
  169. package/src/modes/bridge/event-stream.ts +70 -0
  170. package/src/modes/components/assistant-message.ts +5 -1
  171. package/src/modes/components/custom-editor.ts +101 -0
  172. package/src/modes/components/hook-selector.ts +133 -20
  173. package/src/modes/components/jobs-overlay-model.ts +109 -0
  174. package/src/modes/components/jobs-overlay.ts +172 -0
  175. package/src/modes/components/status-line/presets.ts +7 -5
  176. package/src/modes/components/status-line/segments.ts +25 -0
  177. package/src/modes/components/status-line/types.ts +2 -0
  178. package/src/modes/components/status-line.ts +9 -1
  179. package/src/modes/controllers/event-controller.ts +71 -6
  180. package/src/modes/controllers/extension-ui-controller.ts +43 -1
  181. package/src/modes/controllers/input-controller.ts +105 -9
  182. package/src/modes/controllers/selector-controller.ts +31 -1
  183. package/src/modes/index.ts +1 -0
  184. package/src/modes/interactive-mode.ts +28 -0
  185. package/src/modes/jobs-observer.ts +204 -0
  186. package/src/modes/rpc/host-tools.ts +1 -186
  187. package/src/modes/rpc/host-uris.ts +1 -235
  188. package/src/modes/rpc/rpc-client.ts +25 -10
  189. package/src/modes/rpc/rpc-mode.ts +12 -381
  190. package/src/modes/shared/agent-wire/command-dispatch.ts +341 -0
  191. package/src/modes/shared/agent-wire/command-validation.ts +131 -0
  192. package/src/modes/shared/agent-wire/event-envelope.ts +108 -0
  193. package/src/modes/shared/agent-wire/handshake.ts +117 -0
  194. package/src/modes/shared/agent-wire/host-tool-bridge.ts +194 -0
  195. package/src/modes/shared/agent-wire/host-uri-bridge.ts +236 -0
  196. package/src/modes/shared/agent-wire/protocol.ts +96 -0
  197. package/src/modes/shared/agent-wire/responses.ts +17 -0
  198. package/src/modes/shared/agent-wire/scopes.ts +89 -0
  199. package/src/modes/shared/agent-wire/ui-request-broker.ts +150 -0
  200. package/src/modes/shared/agent-wire/ui-result.ts +48 -0
  201. package/src/modes/types.ts +2 -0
  202. package/src/prompts/agents/executor.md +13 -0
  203. package/src/prompts/tools/subagent.md +39 -4
  204. package/src/prompts/tools/task-summary.md +3 -9
  205. package/src/prompts/tools/task.md +5 -1
  206. package/src/sdk.ts +8 -0
  207. package/src/session/agent-session.ts +445 -71
  208. package/src/session/session-manager.ts +13 -1
  209. package/src/skill-state/active-state.ts +58 -65
  210. package/src/skill-state/deep-interview-mutation-guard.ts +114 -17
  211. package/src/skill-state/initial-phase.ts +2 -0
  212. package/src/skill-state/workflow-state-contract.ts +33 -4
  213. package/src/skill-state/workflow-state-version.ts +3 -0
  214. package/src/slash-commands/builtin-registry.ts +8 -0
  215. package/src/task/executor.ts +79 -13
  216. package/src/task/id.ts +33 -0
  217. package/src/task/index.ts +376 -74
  218. package/src/task/output-manager.ts +5 -4
  219. package/src/task/receipt.ts +297 -0
  220. package/src/task/render.ts +54 -134
  221. package/src/task/spawn-gate.ts +132 -0
  222. package/src/task/types.ts +104 -10
  223. package/src/tools/ask.ts +88 -27
  224. package/src/tools/ast-edit.ts +1 -0
  225. package/src/tools/ast-grep.ts +1 -0
  226. package/src/tools/bash.ts +1 -1
  227. package/src/tools/cron.ts +48 -0
  228. package/src/tools/find.ts +4 -1
  229. package/src/tools/index.ts +2 -0
  230. package/src/tools/path-utils.ts +3 -2
  231. package/src/tools/read.ts +1 -0
  232. package/src/tools/search.ts +1 -0
  233. package/src/tools/skill.ts +6 -1
  234. package/src/tools/subagent.ts +423 -79
@@ -0,0 +1,225 @@
1
+ /**
2
+ * operate(goal) — autonomous owner-driven lifecycle (M9) integrating the recovery loop (M6).
3
+ *
4
+ * start -> submit(single-flight) -> [observe -> classify -> recover]* -> finalize(evidence-gated).
5
+ * Destructive recovery (restart-clean/preserve-delta/fallback) writes a valid `vanish` receipt
6
+ * BEFORE acting; dirty/unknown deltas are preserved, never clean-restarted. The loop is bounded
7
+ * by `maxIterations` and the per-classification retry budgets.
8
+ *
9
+ * External effects (RPC, observation, validation/git/gh) are injected so the whole lifecycle is
10
+ * unit/e2e-testable with a fake harness.
11
+ */
12
+ import { randomBytes } from "node:crypto";
13
+ import { type FinalizeChecks, type FinalizeResult, runFinalize, type ValidationCommandSpec } from "./finalize";
14
+ import { type PreserveResult, preserveDirtyWorktree } from "./preserve";
15
+ import {
16
+ buildReceipt,
17
+ type ReceiptSubject,
18
+ requiresVanishBeforeAction,
19
+ type VanishEvidence,
20
+ validateReceipt,
21
+ } from "./receipts";
22
+ import { type HarnessRpc, singleFlightAccept } from "./rpc-adapter";
23
+ import { writeReceiptImmutable } from "./storage";
24
+ import {
25
+ DEFAULT_RETRY_BUDGET,
26
+ type HarnessLifecycle,
27
+ type Observation,
28
+ type RecoveryClassification,
29
+ type RetryBudget,
30
+ type Severity,
31
+ } from "./types";
32
+
33
+ export interface OperateOptions {
34
+ root: string;
35
+ sessionId: string;
36
+ workspace: string;
37
+ branch: string;
38
+ rpc: HarnessRpc;
39
+ /** Factory used to (re)create the RPC subprocess on restart recovery. Defaults to reusing `rpc`. */
40
+ rpcFactory?: () => HarnessRpc;
41
+ /** Bounded observation provider (scripted in tests; real = git + rpc state). */
42
+ observe: () => Promise<Observation>;
43
+ /** Real dirty-worktree preservation; injectable for tests. Defaults to git stash/diff capture. */
44
+ preserve?: (workspace: string) => PreserveResult;
45
+ finalizeChecks: FinalizeChecks;
46
+ validationCommands?: ValidationCommandSpec[];
47
+ retryBudget?: Partial<RetryBudget>;
48
+ acceptanceTimeoutMs?: number;
49
+ maxIterations?: number;
50
+ /** Injected event emitter. Production owner calls must pass the lease-guarded single-writer #emit. */
51
+ emit: (severity: Severity, kind: string, evidence: Record<string, unknown>) => Promise<void>;
52
+ clock?: () => number;
53
+ }
54
+
55
+ export interface OperateResult {
56
+ completed: boolean;
57
+ lifecycle: HarnessLifecycle;
58
+ iterations: number;
59
+ classifications: RecoveryClassification[];
60
+ vanishReceiptIds: string[];
61
+ finalize?: FinalizeResult;
62
+ blockers: string[];
63
+ }
64
+
65
+ export async function operate(goal: string, opts: OperateOptions): Promise<OperateResult> {
66
+ const budget: RetryBudget = { ...DEFAULT_RETRY_BUDGET, ...opts.retryBudget };
67
+ const acceptanceTimeoutMs = opts.acceptanceTimeoutMs ?? 30_000;
68
+ const maxIterations = opts.maxIterations ?? 10;
69
+ const subject: ReceiptSubject = { workspace: opts.workspace, branch: opts.branch, head: null, commit: null };
70
+ const classifications: RecoveryClassification[] = [];
71
+ const vanishReceiptIds: string[] = [];
72
+ const blockers: string[] = [];
73
+
74
+ let rpc = opts.rpc;
75
+
76
+ const now = (): string => new Date(opts.clock ? opts.clock() : Date.now()).toISOString();
77
+ let lifecycle: HarnessLifecycle = "started";
78
+ const emit = opts.emit;
79
+
80
+ const writeVanish = async (obs: Observation, classification: RecoveryClassification): Promise<boolean> => {
81
+ const dirty = obs.gitDelta === "dirty" || obs.gitDelta === "unknown";
82
+ let untrackedManifest: VanishEvidence["untrackedManifest"] = [];
83
+ let stashRef: string | null = null;
84
+ let snapshotComplete = true;
85
+ let gitStatusPorcelain = obs.observedSignals.join(",");
86
+ if (dirty) {
87
+ const preserve = opts.preserve ?? preserveDirtyWorktree;
88
+ const p = preserve(opts.workspace);
89
+ untrackedManifest = p.untrackedManifest;
90
+ stashRef = p.stashRef;
91
+ snapshotComplete = p.snapshotComplete;
92
+ gitStatusPorcelain = `tracked-diff-sha:${p.trackedDiffSha256};untracked:${p.untrackedManifest.length};stash:${p.stashRef ?? "none"}`;
93
+ }
94
+ const evidence: VanishEvidence = {
95
+ classification,
96
+ gitDelta: obs.gitDelta,
97
+ gitStatusPorcelain,
98
+ untrackedManifest,
99
+ preservation: dirty && stashRef ? "stash" : "snapshot",
100
+ stashRef,
101
+ snapshotComplete,
102
+ forbiddenActions: dirty ? ["restart-clean", "delete", "reset"] : [],
103
+ };
104
+ const receipt = buildReceipt<VanishEvidence>({
105
+ receiptId: `vanish-${Date.now()}-${randomBytes(4).toString("hex")}`,
106
+ sessionId: opts.sessionId,
107
+ family: "vanish",
108
+ source: "operate",
109
+ subject,
110
+ evidence,
111
+ createdAt: now(),
112
+ });
113
+ const outcome = validateReceipt(receipt);
114
+ await writeReceiptImmutable(opts.root, opts.sessionId, "vanish", receipt.receiptId, receipt);
115
+ vanishReceiptIds.push(receipt.receiptId);
116
+ await emit(outcome.valid ? "critical" : "warn", "vanish_receipt", { classification, valid: outcome.valid });
117
+ return outcome.valid;
118
+ };
119
+
120
+ const submit = async (): Promise<boolean> => {
121
+ const acc = await singleFlightAccept(rpc, goal, acceptanceTimeoutMs);
122
+ await emit(acc.accepted ? "info" : "warn", acc.accepted ? "prompt_accepted" : "prompt_not_accepted", {
123
+ reason: acc.reason,
124
+ });
125
+ return acc.accepted;
126
+ };
127
+
128
+ await emit("info", "operate_started", { goal });
129
+ let accepted = await submit();
130
+ lifecycle = accepted ? "observing" : "submitted";
131
+ let iterations = 0;
132
+
133
+ while (iterations < maxIterations) {
134
+ iterations++;
135
+ const obs = await opts.observe();
136
+ const decision = classifyRecoveryLocal(obs, budget, accepted);
137
+ classifications.push(decision.classification);
138
+ await emit(decision.severity, `classified:${decision.classification}`, { reason: decision.reason });
139
+
140
+ if (decision.classification === "continue") {
141
+ if (obs.observedSignals.includes("completed") || obs.lifecycle === "finalizing") {
142
+ lifecycle = "finalizing";
143
+ break;
144
+ }
145
+ continue;
146
+ }
147
+
148
+ // Destructive/recovery actions require a valid vanish receipt first.
149
+ if (requiresVanishBeforeAction(decision.classification)) {
150
+ const safe = await writeVanish(obs, decision.classification);
151
+ if (!safe) {
152
+ lifecycle = "blocked";
153
+ blockers.push("invalid-vanish-receipt");
154
+ break;
155
+ }
156
+ }
157
+
158
+ if (decision.classification === "reinject-prompt") {
159
+ budget.reinjectPrompt = Math.max(0, budget.reinjectPrompt - 1);
160
+ accepted = await submit();
161
+ } else if (decision.classification === "restart-clean") {
162
+ budget.zeroDeltaVanish = Math.max(0, budget.zeroDeltaVanish - 1);
163
+ rpc = opts.rpcFactory ? opts.rpcFactory() : rpc;
164
+ accepted = await submit();
165
+ } else if (decision.classification === "restart-preserve-delta") {
166
+ budget.dirtyVanishPreserve = Math.max(0, budget.dirtyVanishPreserve - 1);
167
+ rpc = opts.rpcFactory ? opts.rpcFactory() : rpc;
168
+ accepted = await submit();
169
+ } else if (decision.classification === "fallback-codex-exec") {
170
+ lifecycle = "blocked";
171
+ blockers.push("fallback-codex-exec-requested");
172
+ break;
173
+ } else if (decision.classification === "human-check") {
174
+ lifecycle = "blocked";
175
+ blockers.push("human-check-required");
176
+ break;
177
+ }
178
+ }
179
+
180
+ if (lifecycle === "blocked") {
181
+ await emit("critical", "operate_blocked", { blockers });
182
+ return { completed: false, lifecycle, iterations, classifications, vanishReceiptIds, blockers };
183
+ }
184
+
185
+ // B3: never finalize on loop-exhaustion — require an explicit observed completion.
186
+ if (lifecycle !== "finalizing") {
187
+ blockers.push("no-observed-completion");
188
+ await emit("critical", "operate_blocked", { blockers });
189
+ return { completed: false, lifecycle: "blocked", iterations, classifications, vanishReceiptIds, blockers };
190
+ }
191
+
192
+ const finalize = await runFinalize({
193
+ root: opts.root,
194
+ sessionId: opts.sessionId,
195
+ workspace: opts.workspace,
196
+ branch: opts.branch,
197
+ requireTests: true,
198
+ requireCommit: true,
199
+ requirePr: true,
200
+ validationCommands: opts.validationCommands,
201
+ checks: opts.finalizeChecks,
202
+ clock: opts.clock,
203
+ });
204
+ await emit(finalize.completed ? "info" : "critical", "operate_finalized", {
205
+ completed: finalize.completed,
206
+ blockers: finalize.blockers,
207
+ });
208
+ return {
209
+ completed: finalize.completed,
210
+ lifecycle: finalize.completed ? "completed" : "blocked",
211
+ iterations,
212
+ classifications,
213
+ vanishReceiptIds,
214
+ finalize,
215
+ blockers: finalize.blockers,
216
+ };
217
+ }
218
+
219
+ // Local import indirection keeps the classifier dependency explicit at the call site.
220
+ import { classifyRecovery } from "./classifier";
221
+ import type { RecoveryDecision } from "./types";
222
+
223
+ function classifyRecoveryLocal(obs: Observation, budget: RetryBudget, acceptedPromptActive: boolean): RecoveryDecision {
224
+ return classifyRecovery({ observation: obs, retryBudget: budget, acceptedPromptActive });
225
+ }