@orion-agents/orion-code 0.3.66 → 0.4.4

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 (384) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +78 -361
  3. package/README.zh-CN.md +71 -262
  4. package/bin/orion +4 -1
  5. package/dist/acp/session-updates.d.ts +35 -0
  6. package/dist/acp/session-updates.js +183 -0
  7. package/dist/acp/sessions.d.ts +32 -0
  8. package/dist/acp/sessions.js +328 -0
  9. package/dist/acp/stdio.d.ts +3 -0
  10. package/dist/acp/stdio.js +59 -0
  11. package/dist/cli.js +136 -185
  12. package/dist/commands/context-tool-command-handlers.d.ts +1 -1
  13. package/dist/commands/context-tool-command-handlers.js +24 -3
  14. package/dist/commands/core-command-handlers.js +10 -18
  15. package/dist/commands/diagnostic-command-handlers.js +58 -48
  16. package/dist/commands/diagnostic-commands.js +0 -12
  17. package/dist/commands/init-command.d.ts +3 -0
  18. package/dist/commands/init-command.js +131 -0
  19. package/dist/commands/model-command-handlers.d.ts +1 -2
  20. package/dist/commands/model-command-handlers.js +15 -100
  21. package/dist/commands/model-commands.js +0 -11
  22. package/dist/commands/registry.js +1 -19
  23. package/dist/commands/rsi-command.d.ts +2 -0
  24. package/dist/commands/rsi-command.js +180 -0
  25. package/dist/commands/session-command-handlers.js +28 -19
  26. package/dist/commands/system-commands.js +0 -1
  27. package/dist/commands/target-command.js +49 -6
  28. package/dist/commands/tool-commands.js +1 -1
  29. package/dist/commands/types.d.ts +4 -10
  30. package/dist/commands/types.js +1 -21
  31. package/dist/commands/workflow-command-handlers.js +13 -4
  32. package/dist/commands/workflow-commands.js +2 -2
  33. package/dist/framework/loop-budget-contract.d.ts +2 -8
  34. package/dist/framework/loop-budget-contract.js +0 -3
  35. package/dist/framework/loop-progress.d.ts +18 -0
  36. package/dist/framework/loop-progress.js +63 -0
  37. package/dist/framework/prompt.d.ts +0 -2
  38. package/dist/framework/prompt.js +9 -27
  39. package/dist/framework/query.d.ts +26 -31
  40. package/dist/framework/query.js +451 -292
  41. package/dist/framework/store.d.ts +6 -10
  42. package/dist/framework/store.js +2 -21
  43. package/dist/framework/tool-call-orchestrator.d.ts +7 -0
  44. package/dist/framework/tool-call-orchestrator.js +8 -3
  45. package/dist/framework/tool-state.d.ts +2 -0
  46. package/dist/framework/tool.d.ts +0 -23
  47. package/dist/framework/verification-command.d.ts +15 -0
  48. package/dist/framework/verification-command.js +32 -0
  49. package/dist/harness/assembler.d.ts +1 -0
  50. package/dist/harness/assembler.js +24 -0
  51. package/dist/harness/capsule.d.ts +1 -1
  52. package/dist/harness/capsule.js +33 -14
  53. package/dist/harness/context-harness.d.ts +37 -12
  54. package/dist/harness/context-harness.js +545 -35
  55. package/dist/harness/contract.js +1 -1
  56. package/dist/harness/drift-guard.d.ts +4 -0
  57. package/dist/harness/drift-guard.js +68 -16
  58. package/dist/harness/index.d.ts +1 -1
  59. package/dist/harness/intent.js +21 -0
  60. package/dist/harness/ledger.d.ts +7 -11
  61. package/dist/harness/ledger.js +50 -9
  62. package/dist/harness/progress-controller.d.ts +12 -7
  63. package/dist/harness/progress-controller.js +96 -29
  64. package/dist/harness/state.js +10 -1
  65. package/dist/harness/stop-controller.d.ts +0 -5
  66. package/dist/harness/stop-controller.js +11 -31
  67. package/dist/harness/task-checklist.d.ts +16 -0
  68. package/dist/harness/task-checklist.js +92 -0
  69. package/dist/harness/types.d.ts +78 -1
  70. package/dist/harness/verification.d.ts +19 -1
  71. package/dist/harness/verification.js +116 -29
  72. package/dist/index.d.ts +1 -1
  73. package/dist/index.js +1 -3
  74. package/dist/print-ui/event-stream.d.ts +43 -0
  75. package/dist/print-ui/event-stream.js +204 -0
  76. package/dist/print-ui/launch.d.ts +12 -1
  77. package/dist/print-ui/launch.js +173 -11
  78. package/dist/product/environment.d.ts +1 -1
  79. package/dist/product/environment.js +1 -1
  80. package/dist/product/identity.d.ts +1 -1
  81. package/dist/product/identity.js +1 -1
  82. package/dist/product/paths.d.ts +3 -2
  83. package/dist/product/paths.js +6 -2
  84. package/dist/runtime/agent-loop.d.ts +12 -2
  85. package/dist/runtime/agent-loop.js +172 -29
  86. package/dist/runtime/agent-runtime-controller.d.ts +14 -4
  87. package/dist/runtime/agent-runtime-controller.js +366 -192
  88. package/dist/runtime/agent-runtime-protocol.d.ts +10 -18
  89. package/dist/runtime/agent-runtime-runner.d.ts +10 -0
  90. package/dist/runtime/builtin-tool-provider.js +5 -1
  91. package/dist/runtime/capability-receipt-journal.js +1 -0
  92. package/dist/runtime/durable-tool-receipt-reader.js +2 -1
  93. package/dist/runtime/first-party-tool-services.d.ts +1 -0
  94. package/dist/runtime/first-party-tool-services.js +2 -12
  95. package/dist/runtime/first-party-tool-universe.d.ts +1 -0
  96. package/dist/runtime/first-party-tool-universe.js +1 -1
  97. package/dist/runtime/followup-queue-store.d.ts +16 -0
  98. package/dist/runtime/followup-queue-store.js +75 -0
  99. package/dist/runtime/goal-lifecycle-v2.d.ts +16 -4
  100. package/dist/runtime/goal-lifecycle-v2.js +217 -39
  101. package/dist/runtime/goal-runtime-coordinator.d.ts +14 -2
  102. package/dist/runtime/goal-runtime-coordinator.js +147 -36
  103. package/dist/runtime/goals/presentation.js +3 -1
  104. package/dist/runtime/goals/types.d.ts +1 -3
  105. package/dist/runtime/goals/types.js +0 -3
  106. package/dist/runtime/loop-budget.d.ts +0 -7
  107. package/dist/runtime/loop-budget.js +8 -52
  108. package/dist/runtime/mcp/first-party-mcp-adapter.d.ts +2 -0
  109. package/dist/runtime/mcp/first-party-mcp-adapter.js +23 -19
  110. package/dist/runtime/model-coordinator.js +2 -5
  111. package/dist/runtime/orion-runtime-v1.d.ts +18 -2
  112. package/dist/runtime/orion-runtime-v1.js +183 -46
  113. package/dist/runtime/orion-session-runner.d.ts +7 -0
  114. package/dist/runtime/orion-session-runner.js +82 -0
  115. package/dist/runtime/plan-review.d.ts +1 -0
  116. package/dist/runtime/plan-review.js +8 -4
  117. package/dist/runtime/product-bootstrap.d.ts +6 -0
  118. package/dist/runtime/product-bootstrap.js +41 -51
  119. package/dist/runtime/product-orion-runtime.js +129 -58
  120. package/dist/runtime/release-receipts.d.ts +24 -133
  121. package/dist/runtime/release-receipts.js +129 -693
  122. package/dist/runtime/rich-text/layout.js +108 -65
  123. package/dist/runtime/rsi/contracts.d.ts +50 -0
  124. package/dist/runtime/rsi/contracts.js +17 -0
  125. package/dist/runtime/rsi/diagnosis.d.ts +46 -0
  126. package/dist/runtime/rsi/diagnosis.js +98 -0
  127. package/dist/runtime/rsi/evaluation-suite.d.ts +25 -0
  128. package/dist/runtime/rsi/evaluation-suite.js +141 -0
  129. package/dist/runtime/rsi/evaluation-worker.d.ts +19 -0
  130. package/dist/runtime/rsi/evaluation-worker.js +64 -0
  131. package/dist/runtime/rsi/evaluation.d.ts +49 -0
  132. package/dist/runtime/rsi/evaluation.js +345 -0
  133. package/dist/runtime/rsi/lifecycle.d.ts +54 -0
  134. package/dist/runtime/rsi/lifecycle.js +279 -0
  135. package/dist/runtime/rsi/proposal.d.ts +39 -0
  136. package/dist/runtime/rsi/proposal.js +312 -0
  137. package/dist/runtime/rsi/receipt.d.ts +28 -0
  138. package/dist/runtime/rsi/receipt.js +138 -0
  139. package/dist/runtime/rsi/skill-state.d.ts +7 -0
  140. package/dist/runtime/rsi/skill-state.js +50 -0
  141. package/dist/runtime/rsi/trajectory.d.ts +19 -0
  142. package/dist/runtime/rsi/trajectory.js +314 -0
  143. package/dist/runtime/rsi/triage.d.ts +274 -0
  144. package/dist/runtime/rsi/triage.js +58 -0
  145. package/dist/runtime/session-composer-control.d.ts +5 -24
  146. package/dist/runtime/session-composer-control.js +27 -189
  147. package/dist/runtime/step-snapshot.d.ts +4 -1
  148. package/dist/runtime/step-snapshot.js +11 -1
  149. package/dist/runtime/subagent-thread-runtime.js +27 -5
  150. package/dist/runtime/subagents/policy.js +0 -1
  151. package/dist/runtime/subagents/production.js +1 -5
  152. package/dist/runtime/subagents/runtime-integration.js +2 -4
  153. package/dist/runtime/subagents/types.d.ts +0 -5
  154. package/dist/runtime/subagents/types.js +0 -2
  155. package/dist/runtime/task-context-recovery.d.ts +55 -0
  156. package/dist/runtime/task-context-recovery.js +349 -0
  157. package/dist/runtime/task-context-service.d.ts +20 -10
  158. package/dist/runtime/task-context-service.js +69 -9
  159. package/dist/runtime/thread-admission.d.ts +3 -1
  160. package/dist/runtime/thread-admission.js +21 -7
  161. package/dist/runtime/thread-event-store.d.ts +2 -2
  162. package/dist/runtime/thread-event-store.js +7 -2
  163. package/dist/runtime/thread-projection.js +4 -2
  164. package/dist/runtime/thread-runtime.d.ts +10 -0
  165. package/dist/runtime/thread-runtime.js +85 -3
  166. package/dist/runtime/thread-session-index.d.ts +8 -0
  167. package/dist/runtime/thread-session-index.js +50 -1
  168. package/dist/runtime/thread-session-view.d.ts +2 -1
  169. package/dist/runtime/thread-session-view.js +4 -0
  170. package/dist/runtime/thread-tool-journal.d.ts +1 -0
  171. package/dist/runtime/thread-tool-journal.js +6 -2
  172. package/dist/runtime/thread-ui-adapter.d.ts +1 -0
  173. package/dist/runtime/thread-ui-adapter.js +89 -22
  174. package/dist/runtime/tool-gateway.d.ts +9 -0
  175. package/dist/runtime/tool-gateway.js +24 -0
  176. package/dist/runtime/tool-receipt-validator.js +4 -0
  177. package/dist/runtime/tool-transcript-entry.d.ts +16 -0
  178. package/dist/runtime/tool-transcript-entry.js +73 -0
  179. package/dist/runtime/turn-commit.d.ts +4 -1
  180. package/dist/runtime/turn-commit.js +19 -15
  181. package/dist/runtime/ui-events.d.ts +15 -1
  182. package/dist/runtime/ui-view-model.d.ts +6 -5
  183. package/dist/runtime/ui-view-model.js +78 -61
  184. package/dist/runtime/workspace-runtime-kernel.js +0 -1
  185. package/dist/runtime/workspace-verification.d.ts +7 -0
  186. package/dist/runtime/workspace-verification.js +83 -0
  187. package/dist/services/atomic-write.d.ts +2 -0
  188. package/dist/services/atomic-write.js +12 -1
  189. package/dist/services/code-review/format.d.ts +4 -1
  190. package/dist/services/code-review/format.js +5 -1
  191. package/dist/services/code-review/runner.d.ts +2 -2
  192. package/dist/services/code-review/runner.js +86 -64
  193. package/dist/services/code-review/snapshot.d.ts +9 -9
  194. package/dist/services/code-review/snapshot.js +182 -166
  195. package/dist/services/compact/auto-compact.d.ts +21 -6
  196. package/dist/services/compact/auto-compact.js +148 -22
  197. package/dist/services/compact/background-candidate.d.ts +33 -0
  198. package/dist/services/compact/background-candidate.js +184 -0
  199. package/dist/services/compact/compact.d.ts +4 -1
  200. package/dist/services/compact/compact.js +30 -3
  201. package/dist/services/compact/coordinator.d.ts +10 -4
  202. package/dist/services/compact/coordinator.js +17 -7
  203. package/dist/services/compact/summary-generator.d.ts +4 -2
  204. package/dist/services/compact/summary-generator.js +17 -3
  205. package/dist/services/config.d.ts +5 -5
  206. package/dist/services/config.js +29 -48
  207. package/dist/services/doctor.js +85 -13
  208. package/dist/services/effort.d.ts +5 -5
  209. package/dist/services/effort.js +5 -11
  210. package/dist/services/file-lock.d.ts +9 -3
  211. package/dist/services/file-lock.js +92 -26
  212. package/dist/services/global-config.d.ts +26 -64
  213. package/dist/services/global-config.js +233 -193
  214. package/dist/services/llm.d.ts +42 -4
  215. package/dist/services/llm.js +177 -45
  216. package/dist/services/model-client-pool.d.ts +15 -9
  217. package/dist/services/model-client-pool.js +62 -33
  218. package/dist/services/model-context.d.ts +2 -1
  219. package/dist/services/model-context.js +15 -9
  220. package/dist/services/model-registry.d.ts +4 -15
  221. package/dist/services/model-registry.js +32 -101
  222. package/dist/services/provider-diagnostics.d.ts +8 -0
  223. package/dist/services/provider-diagnostics.js +17 -12
  224. package/dist/services/provider-resilience/coordinator.d.ts +1 -1
  225. package/dist/services/provider-resilience/coordinator.js +10 -6
  226. package/dist/services/provider-resilience/request-gate.d.ts +3 -0
  227. package/dist/services/provider-resilience/request-gate.js +29 -18
  228. package/dist/services/provider-resilience/types.d.ts +2 -0
  229. package/dist/services/session-storage.d.ts +7 -10
  230. package/dist/services/session-storage.js +57 -30
  231. package/dist/services/settings-coordinator.d.ts +0 -6
  232. package/dist/services/settings-coordinator.js +19 -56
  233. package/dist/services/settings-document-repository.d.ts +3 -10
  234. package/dist/services/settings-document-repository.js +7 -85
  235. package/dist/services/usage-state.d.ts +3 -3
  236. package/dist/services/usage-state.js +11 -42
  237. package/dist/terminal-ui/answer-format.d.ts +14 -0
  238. package/dist/terminal-ui/answer-format.js +119 -0
  239. package/dist/terminal-ui/launch.d.ts +7 -6
  240. package/dist/terminal-ui/launch.js +160 -70
  241. package/dist/terminal-ui/output-queue.d.ts +2 -1
  242. package/dist/terminal-ui/output-queue.js +1 -1
  243. package/dist/terminal-ui/raw-editor.d.ts +2 -1
  244. package/dist/terminal-ui/raw-editor.js +56 -15
  245. package/dist/tools/core/edit-file.js +6 -2
  246. package/dist/tools/core/write-file.js +9 -2
  247. package/dist/tools/lsp.d.ts +16 -1
  248. package/dist/tools/lsp.js +60 -19
  249. package/dist/tools/sandbox.d.ts +1 -1
  250. package/dist/tools/sandbox.js +3 -16
  251. package/dist/tools/todo.d.ts +4 -2
  252. package/dist/tools/todo.js +91 -30
  253. package/dist/tui-core/input-parser.d.ts +1 -0
  254. package/dist/tui-core/input-parser.js +6 -0
  255. package/dist/tui-core/style.d.ts +1 -8
  256. package/dist/tui-core/style.js +3 -110
  257. package/dist/tui-ui/chrome-view-model.d.ts +1 -1
  258. package/dist/tui-ui/chrome-view-model.js +36 -32
  259. package/dist/tui-ui/launch.js +14 -14
  260. package/dist/tui-ui/layout.d.ts +5 -7
  261. package/dist/tui-ui/layout.js +129 -124
  262. package/dist/tui-ui/runner.d.ts +11 -12
  263. package/dist/tui-ui/runner.js +88 -67
  264. package/dist/tui-ui/state.d.ts +0 -11
  265. package/dist/tui-ui/state.js +22 -33
  266. package/dist/tui-ui/terminal-image.js +22 -4
  267. package/dist/tui-ui/transcript-inspector-layout.js +6 -3
  268. package/dist/tui-ui/transcript-inspector.d.ts +1 -0
  269. package/dist/tui-ui/transcript-inspector.js +7 -1
  270. package/dist/tui-ui/transcript-layout.js +42 -6
  271. package/dist/utils/terminal-text.d.ts +11 -0
  272. package/dist/utils/terminal-text.js +114 -0
  273. package/docs/cli-guide.md +575 -0
  274. package/docs/orion.example.yaml +43 -0
  275. package/docs/readme.md +12 -57
  276. package/npm-shrinkwrap.json +484 -1855
  277. package/package.json +13 -63
  278. package/dist/migration/command.d.ts +0 -9
  279. package/dist/migration/command.js +0 -100
  280. package/dist/migration/index.d.ts +0 -7
  281. package/dist/migration/index.js +0 -14
  282. package/dist/migration/migrate.d.ts +0 -19
  283. package/dist/migration/migrate.js +0 -406
  284. package/dist/migration/types.d.ts +0 -55
  285. package/dist/migration/types.js +0 -6
  286. package/dist/services/tool-allowlist.d.ts +0 -110
  287. package/dist/services/tool-allowlist.js +0 -299
  288. package/dist/services/yaml-config.d.ts +0 -57
  289. package/dist/services/yaml-config.js +0 -178
  290. package/dist/web/cli-options.d.ts +0 -17
  291. package/dist/web/cli-options.js +0 -51
  292. package/dist/web/code-review-run-service.d.ts +0 -68
  293. package/dist/web/code-review-run-service.js +0 -228
  294. package/dist/web/context-text.d.ts +0 -17
  295. package/dist/web/context-text.js +0 -40
  296. package/dist/web/errors.d.ts +0 -6
  297. package/dist/web/errors.js +0 -13
  298. package/dist/web/event-hub.d.ts +0 -45
  299. package/dist/web/event-hub.js +0 -370
  300. package/dist/web/file-read-service.d.ts +0 -101
  301. package/dist/web/file-read-service.js +0 -593
  302. package/dist/web/file-write-service.d.ts +0 -16
  303. package/dist/web/file-write-service.js +0 -103
  304. package/dist/web/git-compare-service.d.ts +0 -45
  305. package/dist/web/git-compare-service.js +0 -160
  306. package/dist/web/git-diff-document.d.ts +0 -102
  307. package/dist/web/git-diff-document.js +0 -258
  308. package/dist/web/git-file-source.d.ts +0 -25
  309. package/dist/web/git-file-source.js +0 -21
  310. package/dist/web/git-history-service.d.ts +0 -151
  311. package/dist/web/git-history-service.js +0 -619
  312. package/dist/web/git-index-transaction.d.ts +0 -45
  313. package/dist/web/git-index-transaction.js +0 -174
  314. package/dist/web/git-patch-builder.d.ts +0 -30
  315. package/dist/web/git-patch-builder.js +0 -138
  316. package/dist/web/git-read-model-service.d.ts +0 -452
  317. package/dist/web/git-read-model-service.js +0 -1833
  318. package/dist/web/git-version-service.d.ts +0 -79
  319. package/dist/web/git-version-service.js +0 -279
  320. package/dist/web/host-daemon.d.ts +0 -70
  321. package/dist/web/host-daemon.js +0 -237
  322. package/dist/web/index.d.ts +0 -6
  323. package/dist/web/index.js +0 -28
  324. package/dist/web/launch.d.ts +0 -12
  325. package/dist/web/launch.js +0 -89
  326. package/dist/web/native-directory-picker.d.ts +0 -63
  327. package/dist/web/native-directory-picker.js +0 -169
  328. package/dist/web/protocol.d.ts +0 -705
  329. package/dist/web/protocol.js +0 -639
  330. package/dist/web/review-service.d.ts +0 -22
  331. package/dist/web/review-service.js +0 -68
  332. package/dist/web/server.d.ts +0 -20
  333. package/dist/web/server.js +0 -1453
  334. package/dist/web/session-runtime-registry.d.ts +0 -138
  335. package/dist/web/session-runtime-registry.js +0 -471
  336. package/dist/web/terminal-manager.d.ts +0 -156
  337. package/dist/web/terminal-manager.js +0 -779
  338. package/dist/web/terminal-server.d.ts +0 -8
  339. package/dist/web/terminal-server.js +0 -304
  340. package/dist/web/workbench-controller.d.ts +0 -395
  341. package/dist/web/workbench-controller.js +0 -3077
  342. package/dist/web/workspace-discovery.d.ts +0 -92
  343. package/dist/web/workspace-discovery.js +0 -324
  344. package/dist/web/workspace-mutation-arbiter.d.ts +0 -54
  345. package/dist/web/workspace-mutation-arbiter.js +0 -267
  346. package/dist/web/workspace-open-telemetry.d.ts +0 -55
  347. package/dist/web/workspace-open-telemetry.js +0 -73
  348. package/dist/web-client/assets/FilesPanel-CPDovK_K.js +0 -1
  349. package/dist/web-client/assets/GitPanel-DtU_TD61.js +0 -4
  350. package/dist/web-client/assets/ReviewPanel-vMO7BEA3.js +0 -6
  351. package/dist/web-client/assets/TerminalPanel-C9vDTAlS.js +0 -23
  352. package/dist/web-client/assets/TerminalPanel-DLuoa74B.css +0 -1
  353. package/dist/web-client/assets/index-CABdwh4l.css +0 -1
  354. package/dist/web-client/assets/index-KvshfEbl.js +0 -20
  355. package/dist/web-client/assets/useAutoNotice-IE1g2wcb.js +0 -1
  356. package/dist/web-client/favicon.svg +0 -9
  357. package/dist/web-client/index.html +0 -17
  358. package/docs/architecture/agent-mode-permission-contract.md +0 -87
  359. package/docs/architecture/v0.3.0-web-api.yaml +0 -1340
  360. package/docs/architecture/v0.3.1-web-api.yaml +0 -2338
  361. package/docs/architecture/v0.3.2-web-api.yaml +0 -3029
  362. package/docs/architecture/v0.3.3-web-api.yaml +0 -3205
  363. package/docs/architecture/v0.3.4-stabilization-contract.md +0 -32
  364. package/docs/migration/v0.1.9-to-v0.2.0.md +0 -98
  365. package/docs/migration/v0.2.2-to-v0.3.0-settings.md +0 -114
  366. package/docs/migration/v0.2.2-to-v0.3.0.md +0 -55
  367. package/docs/migration/v0.3.0-to-v0.3.1.md +0 -88
  368. package/docs/migration/v0.3.1-to-v0.3.2.md +0 -94
  369. package/docs/migration/v0.3.2-to-v0.3.3.md +0 -62
  370. package/docs/migration/v0.3.3-to-v0.3.4.md +0 -36
  371. package/docs/orion.example.json +0 -86
  372. package/docs/plan/v0.2.0-dsh-harness-redesign-plan.md +0 -1234
  373. package/docs/plan/v0.2.0-release-checklist.md +0 -91
  374. package/docs/plan/v0.3.0-node-runtime-compatibility-plan.md +0 -57
  375. package/docs/plan/v0.3.0-settings-integration-plan.md +0 -740
  376. package/docs/plan/v0.3.0-web-workbench-plan.md +0 -376
  377. package/docs/plan/v0.3.1-web-workbench-professional-shell-plan.md +0 -848
  378. package/docs/plan/v0.3.2-web-workbench-layout-and-composer-plan.md +0 -869
  379. package/docs/plan/v0.3.3-plan.md +0 -1113
  380. package/docs/plan/v0.3.4-stabilization-plan.md +0 -89
  381. package/docs/test/v0.3.1-web-workbench-e2e-plan.md +0 -140
  382. package/docs/test/v0.3.2-web-workbench-e2e-plan.md +0 -100
  383. package/docs/test/v0.3.3-web-workbench-e2e-plan.md +0 -79
  384. package/docs/test/v0.3.4-stabilization-e2e-plan.md +0 -54
@@ -0,0 +1,349 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTaskRecoveryBinder = createTaskRecoveryBinder;
4
+ exports.projectTaskToolEvidence = projectTaskToolEvidence;
5
+ exports.recordTaskTodoToolReceipt = recordTaskTodoToolReceipt;
6
+ exports.recoverInterruptedTaskContext = recoverInterruptedTaskContext;
7
+ const crypto_1 = require("crypto");
8
+ const path_1 = require("path");
9
+ const tool_serializer_1 = require("../framework/tool-serializer");
10
+ const verification_command_1 = require("../framework/verification-command");
11
+ const verification_1 = require("../harness/verification");
12
+ const redaction_1 = require("../services/redaction");
13
+ const common_1 = require("../tools/core/common");
14
+ const canonical_1 = require("./protocol/canonical");
15
+ const task_context_service_1 = require("./task-context-service");
16
+ const thread_tool_journal_1 = require("./thread-tool-journal");
17
+ const tool_receipt_validator_1 = require("./tool-receipt-validator");
18
+ const turn_commit_1 = require("./turn-commit");
19
+ const interrupted = 'runtime_restarted_before_terminal_commit';
20
+ function createTaskRecoveryBinder(taskContext, previousCommitDigest, progressAtAdmission) {
21
+ let checkpoint;
22
+ return (input) => {
23
+ const { descriptor, name, args, cwd, activeTodoId } = input;
24
+ if (descriptor?.executorId !== `builtin:${name}:v1`)
25
+ return undefined;
26
+ if (!activeTodoId &&
27
+ !['write_file', 'edit_file', 'read_file', 'todo_write', 'exec_command'].includes(name)) {
28
+ return undefined;
29
+ }
30
+ let seed;
31
+ if (!checkpoint) {
32
+ const state = taskContext.exportState();
33
+ seed = {
34
+ priorCommitDigest: previousCommitDigest() ?? null,
35
+ cwd: (0, path_1.resolve)(cwd),
36
+ revision: taskContext.revision,
37
+ state,
38
+ progressAtAdmission,
39
+ };
40
+ checkpoint = { digest: (0, canonical_1.digestRuntimeValue)(seed), epoch: state.taskEpoch ?? 1 };
41
+ }
42
+ const command = name === 'exec_command' &&
43
+ typeof args.command === 'string' &&
44
+ (0, verification_command_1.classifyDirectVerificationCommand)(args.command) &&
45
+ (0, redaction_1.redactTraceText)(args.command) === args.command
46
+ ? args.command
47
+ : undefined;
48
+ const path = typeof args.path === 'string'
49
+ ? (0, verification_1.workspaceArtifactPath)(cwd, (0, common_1.normalizeToolPath)(args.path))
50
+ : undefined;
51
+ return {
52
+ version: 1,
53
+ seedDigest: checkpoint.digest,
54
+ ...(seed ? { seed } : {}),
55
+ taskContractId: taskContext.getContract()?.id ?? null,
56
+ taskEpoch: checkpoint.epoch,
57
+ activeTodoId,
58
+ readOnly: descriptor.risk.readOnly,
59
+ ...((name === 'write_file' || name === 'edit_file') && path && args.preview !== true
60
+ ? { workspaceWrite: true }
61
+ : {}),
62
+ args: {
63
+ path,
64
+ command,
65
+ cwd: command && typeof args.cwd === 'string' ? (0, common_1.normalizeToolPath)(args.cwd) : undefined,
66
+ },
67
+ };
68
+ };
69
+ }
70
+ /** Derive evidence from the executor's committed outcome, not its display text. */
71
+ function projectTaskToolEvidence(receipt, args, cwd) {
72
+ if (receipt.terminalPhase !== 'execute')
73
+ return {};
74
+ const reportedWritePath = receipt.result.metadata?.workspaceWritePath;
75
+ const changedFile = receipt.success &&
76
+ (receipt.toolName === 'write_file' || receipt.toolName === 'edit_file') &&
77
+ typeof reportedWritePath === 'string'
78
+ ? (0, verification_1.workspaceArtifactPath)(cwd, reportedWritePath)
79
+ : undefined;
80
+ const command = receipt.toolName === 'exec_command' && typeof args.command === 'string'
81
+ ? args.command
82
+ : undefined;
83
+ const kind = command && (0, verification_command_1.classifyDirectVerificationCommand)(command);
84
+ const verification = command && kind
85
+ ? {
86
+ kind,
87
+ toolReceiptDigest: receipt.digest,
88
+ command,
89
+ cwd: (0, path_1.resolve)(cwd, typeof args.cwd === 'string' ? (0, common_1.normalizeToolPath)(args.cwd) : '.'),
90
+ passed: receipt.success && receipt.verificationWorkspace !== null,
91
+ }
92
+ : undefined;
93
+ return { changedFile, verification };
94
+ }
95
+ function recordTaskTodoToolReceipt(taskContext, todo, receipt, { changedFile, verification }) {
96
+ if (verification && receipt.verificationWorkspace !== undefined) {
97
+ taskContext.observeVerificationWorkspace(receipt.verificationWorkspace);
98
+ }
99
+ if (!todo || receipt.terminalPhase !== 'execute' || (!receipt.success && !verification))
100
+ return;
101
+ taskContext.recordTaskTodoReceipt(todo, {
102
+ digest: receipt.digest,
103
+ passed: verification?.passed ?? receipt.success,
104
+ kind: (0, verification_command_1.isLocalVerificationKind)(verification?.kind) ? verification.kind : undefined,
105
+ changedFile,
106
+ command: verification?.command,
107
+ cwd: verification?.cwd,
108
+ });
109
+ }
110
+ /** Restore already-made effects. This never dispatches a model request or reexecutes a tool. */
111
+ function recoverInterruptedTaskContext(input) {
112
+ const { store, previousCommit, taskOptions, restoreGoalState } = input;
113
+ const projection = store.loadProjection();
114
+ const turnId = projection.activeTurnId;
115
+ if (!turnId)
116
+ return;
117
+ const turn = projection.turns[turnId];
118
+ if (turn.commit || turn.mode === 'maintenance')
119
+ return;
120
+ const events = [];
121
+ let cursor = turn.startedSeq;
122
+ while (cursor < projection.cursor) {
123
+ const page = store.replay(cursor, undefined, 'task_context_recovery');
124
+ events.push(...page.events.filter(event => event.turnId === turnId && event.seq <= projection.cursor));
125
+ cursor = page.nextCursor;
126
+ }
127
+ const steps = new Map();
128
+ const intents = new Map();
129
+ let checkpoint;
130
+ for (const event of events) {
131
+ if (event.payload.type === 'step.snapshot' && event.stepId) {
132
+ steps.set(event.stepId, event);
133
+ }
134
+ const entry = readBoundIntent(event, steps);
135
+ if (!entry)
136
+ continue;
137
+ intents.set(entry.intent.invocationId, entry);
138
+ if (!checkpoint &&
139
+ entry.binding.seed &&
140
+ validSeed(entry.binding, previousCommit, taskOptions.cwd)) {
141
+ checkpoint = entry;
142
+ }
143
+ }
144
+ const goalState = restoreGoalState();
145
+ const goalInterruptedBeforeTools = turn.mode === 'goal' &&
146
+ goalState &&
147
+ 'status' in goalState &&
148
+ goalState.status === 'paused' &&
149
+ turn.itemIds.every(itemId => projection.items[itemId].kind !== 'command');
150
+ // A Goal can crash on its first provider request, before a task seed is
151
+ // bound to any tool. Persist its pause or a later reopen will see only the
152
+ // older active Goal state and start another request.
153
+ if (!checkpoint?.binding.seed && !goalInterruptedBeforeTools)
154
+ return;
155
+ const receipts = new Map();
156
+ for (const [index, fact] of events.entries()) {
157
+ if (fact.payload.type !== 'tool.receipt' || !fact.itemId)
158
+ continue;
159
+ const item = projection.items[fact.itemId];
160
+ const terminal = events[index + 1];
161
+ if (!item?.name || !item.intent || !terminal || receipts.has(item.itemId))
162
+ continue;
163
+ const receipt = linkedReceipt(fact, terminal, item.itemId, item.name, item.intent);
164
+ if (!receipt)
165
+ continue;
166
+ receipts.set(item.itemId, { seq: fact.seq, value: receipt });
167
+ }
168
+ let taskContextState = taskOptions.state;
169
+ let taskContextRevision = taskOptions.revision;
170
+ if (checkpoint?.binding.seed) {
171
+ const { seed, seedDigest, taskContractId, taskEpoch } = checkpoint.binding;
172
+ const taskContext = (0, task_context_service_1.createTaskContextService)({
173
+ ...taskOptions,
174
+ state: seed.state,
175
+ revision: seed.revision,
176
+ requireLocalVerificationReceipt: true,
177
+ captureVerificationWorkspace: undefined,
178
+ });
179
+ let unconfirmedWorkspaceRevisions = 0;
180
+ for (const event of events) {
181
+ if (!event.itemId || event.seq < checkpoint.event.seq)
182
+ continue;
183
+ const bound = intents.get(event.itemId);
184
+ if (!bound ||
185
+ bound.binding.seedDigest !== seedDigest ||
186
+ bound.binding.taskContractId !== taskContractId ||
187
+ bound.binding.taskEpoch !== taskEpoch) {
188
+ continue;
189
+ }
190
+ const receipt = receipts.get(event.itemId);
191
+ if (receipt?.seq === event.seq && receipt.value.terminalPhase === 'execute') {
192
+ restoreToolObservation(taskContext, receipt.value, bound.binding, seed.cwd);
193
+ }
194
+ else if (event.payload.type === 'item.started' &&
195
+ !receipt &&
196
+ bound.binding.workspaceWrite) {
197
+ // The filesystem effect is unknown. Invalidate earlier test results
198
+ // without adding file-change evidence for this invocation.
199
+ taskContext.noteIndeterminateWorkspaceChange();
200
+ unconfirmedWorkspaceRevisions++;
201
+ }
202
+ }
203
+ if (taskOptions.captureVerificationWorkspace) {
204
+ taskContext.refreshVerificationWorkspace(taskOptions.captureVerificationWorkspace);
205
+ }
206
+ taskContext.recordProgress(seed.progressAtAdmission, unconfirmedWorkspaceRevisions);
207
+ taskContextState = taskContext.exportState();
208
+ taskContextRevision = taskContext.revision;
209
+ }
210
+ if (!taskContextState || taskContextRevision === undefined)
211
+ return;
212
+ const openItems = turn.itemIds
213
+ .map(itemId => projection.items[itemId])
214
+ .filter(item => item.status === 'started')
215
+ .map(item => ({
216
+ turnId,
217
+ itemId: item.itemId,
218
+ stepId: item.stepId,
219
+ payload: { type: 'item.indeterminate', data: { reason: interrupted } },
220
+ }));
221
+ // On a newly cut-over Session the provider still uses its imported transcript
222
+ // until the first TurnCommit. Preserve that same base on recovery.
223
+ const history = (store.loadAuthoritativeModelHistory() ??
224
+ input.loadImportedHistory?.() ??
225
+ []);
226
+ const commit = (0, turn_commit_1.createTurnCommitV1)({
227
+ commitId: (0, crypto_1.randomUUID)(),
228
+ threadId: store.threadId,
229
+ turnId,
230
+ sourceCursor: projection.cursor + openItems.length,
231
+ createdAt: Date.now(),
232
+ history,
233
+ taskContextState,
234
+ taskContextRevision,
235
+ terminal: { status: 'interrupted', reason: interrupted },
236
+ goalState,
237
+ stepSnapshotDigests: events.flatMap(event => event.payload.type === 'step.snapshot' ? [event.payload.data.digest] : []),
238
+ capabilityReceiptDigests: events.flatMap(event => event.payload.type === 'capability.receipt' ? [event.payload.data.digest] : []),
239
+ toolReceiptDigests: [...receipts.values()].map(receipt => receipt.value.digest),
240
+ });
241
+ store.appendDurableBatch([
242
+ ...openItems,
243
+ (0, turn_commit_1.turnCommitEventV1)(commit),
244
+ { turnId, payload: { type: 'turn.interrupted', data: { reason: interrupted } } },
245
+ ], projection.cursor);
246
+ return commit;
247
+ }
248
+ function readBoundIntent(event, steps) {
249
+ if (event.payload.type !== 'item.started' ||
250
+ event.payload.data.kind !== 'command' ||
251
+ !event.payload.data.intent ||
252
+ !event.stepId)
253
+ return;
254
+ const step = steps.get(event.stepId);
255
+ if (step?.payload.type !== 'step.snapshot')
256
+ return;
257
+ const intent = tryParseIntent(event.payload.data.intent);
258
+ const binding = intent?.taskRecovery;
259
+ if (!intent ||
260
+ !binding ||
261
+ binding.version !== 1 ||
262
+ !binding.args ||
263
+ intent.parentInvocationId ||
264
+ intent.invocationId !== event.itemId ||
265
+ intent.threadId !== event.threadId ||
266
+ intent.turnId !== event.turnId ||
267
+ intent.stepId !== event.stepId ||
268
+ intent.toolName !== event.payload.data.name ||
269
+ intent.requestDigest !== event.payload.data.inputDigest ||
270
+ intent.snapshotDigest !== step.payload.data.digest)
271
+ return;
272
+ return { event, intent, binding };
273
+ }
274
+ function validSeed(binding, previousCommit, workspace) {
275
+ const seed = binding.seed;
276
+ return Boolean(seed &&
277
+ seed.cwd === (0, path_1.resolve)(workspace) &&
278
+ Array.isArray(seed.state?.ledger) &&
279
+ seed.progressAtAdmission &&
280
+ Number.isSafeInteger(seed.revision) &&
281
+ seed.revision >= (previousCommit?.taskContextRevision ?? 0) &&
282
+ seed.priorCommitDigest === (previousCommit?.digest ?? null) &&
283
+ (seed.state.contract?.id ?? null) === binding.taskContractId &&
284
+ (seed.state.taskEpoch ?? 1) === binding.taskEpoch &&
285
+ (0, canonical_1.digestRuntimeValue)(seed) === binding.seedDigest);
286
+ }
287
+ function linkedReceipt(factEvent, terminalEvent, itemId, toolName, storedIntent) {
288
+ const intent = tryParseIntent(storedIntent);
289
+ if (!intent)
290
+ return;
291
+ try {
292
+ const receipt = (0, tool_receipt_validator_1.validateDurableToolInvocationReceiptV1)({
293
+ factEvent,
294
+ terminalEvent,
295
+ item: { itemId, toolName },
296
+ });
297
+ return receipt.intentDigest === intent.digest &&
298
+ receipt.invocationId === intent.invocationId &&
299
+ receipt.threadId === intent.threadId &&
300
+ receipt.turnId === intent.turnId &&
301
+ receipt.stepId === intent.stepId &&
302
+ receipt.parentInvocationId === intent.parentInvocationId &&
303
+ receipt.snapshotDigest === intent.snapshotDigest &&
304
+ receipt.toolName === intent.toolName
305
+ ? receipt
306
+ : undefined;
307
+ }
308
+ catch (error) {
309
+ if (!(error instanceof tool_receipt_validator_1.DurableToolReceiptValidationError))
310
+ throw error;
311
+ return undefined;
312
+ }
313
+ }
314
+ function tryParseIntent(value) {
315
+ try {
316
+ return (0, thread_tool_journal_1.parseToolInvocationIntentV1)(value);
317
+ }
318
+ catch {
319
+ return undefined;
320
+ }
321
+ }
322
+ function restoreToolObservation(taskContext, receipt, binding, cwd) {
323
+ if (receipt.toolName === 'todo_write') {
324
+ const todos = receipt.result.metadata?.taskTodos;
325
+ if (receipt.success &&
326
+ Array.isArray(todos) &&
327
+ todos.length > 0 &&
328
+ todos.every(todo => typeof todo?.content === 'string' &&
329
+ typeof todo.activeForm === 'string' &&
330
+ ['pending', 'in_progress', 'completed'].includes(todo.status)))
331
+ taskContext.updateTaskTodos(todos);
332
+ return;
333
+ }
334
+ const evidence = projectTaskToolEvidence(receipt, binding.args, cwd);
335
+ recordTaskTodoToolReceipt(taskContext, binding.activeTodoId, receipt, evidence);
336
+ taskContext.observeToolResult({
337
+ name: receipt.toolName,
338
+ args: { ...binding.args },
339
+ result: (0, tool_serializer_1.serializeToolResult)(receipt.result),
340
+ duration: receipt.durationMs,
341
+ success: receipt.success,
342
+ error: receipt.result.error,
343
+ summary: receipt.result.summary,
344
+ toolReceiptDigest: receipt.digest,
345
+ readOnly: binding.readOnly,
346
+ ...evidence,
347
+ });
348
+ }
349
+ //# sourceMappingURL=task-context-recovery.js.map
@@ -1,6 +1,7 @@
1
+ import { HarnessKernel } from '../harness/context-harness';
1
2
  import type { PromptAssemblyOptions } from '../harness/assembler';
2
3
  import type { CreateTurnSummaryInput } from '../harness/turn-summary';
3
- import type { CapabilityProfileInput, CompletionGateResult, ContextCapsule, DriftCheckResult, HarnessConfig, HarnessState, IntentUpdate, TaskContract, TurnSummary } from '../harness/types';
4
+ import type { CapabilityProfileInput, CompletionGateResult, ContextCapsule, DriftCheckResult, HarnessConfig, HarnessProgressState, HarnessState, IntentUpdate, TaskContract, TaskTodoObservation, TaskWorkspaceAction, ToolResultObservation, TurnSummary } from '../harness/types';
4
5
  import type { LLMResponse, Message } from '../services/llm';
5
6
  export type DeepReadonly<T> = T extends (...args: never[]) => unknown ? T : T extends readonly (infer U)[] ? readonly DeepReadonly<U>[] : T extends object ? {
6
7
  readonly [K in keyof T]: DeepReadonly<T[K]>;
@@ -11,18 +12,14 @@ export interface TaskContextServiceOptions {
11
12
  readonly state?: HarnessState;
12
13
  readonly config?: HarnessConfig;
13
14
  readonly revision?: number;
15
+ readonly requireLocalVerificationReceipt?: boolean;
16
+ readonly captureVerificationWorkspace?: () => string | null;
14
17
  }
15
18
  export interface TaskContextToolInput {
16
19
  readonly name: string;
17
20
  readonly args: Record<string, unknown>;
18
21
  }
19
- export interface TaskContextToolResultInput extends TaskContextToolInput {
20
- readonly result: string;
21
- readonly duration: number;
22
- readonly success: boolean;
23
- readonly error?: string;
24
- readonly summary?: string;
25
- }
22
+ export type TaskContextToolResultInput = ToolResultObservation;
26
23
  export interface TaskContextAppliedSkill {
27
24
  readonly name: string;
28
25
  readonly source?: string;
@@ -65,7 +62,7 @@ export interface TaskContextExplanation {
65
62
  export interface TaskContextService {
66
63
  readonly serviceId: 'task-context';
67
64
  readonly revision: number;
68
- observeUserInput(input: string): DeepReadonly<IntentUpdate> | undefined;
65
+ observeUserInput(input: string, goalTaskId?: string): DeepReadonly<IntentUpdate> | undefined;
69
66
  classifyIntent(input: string): DeepReadonly<IntentUpdate>;
70
67
  observeCapability(input: CapabilityProfileInput): DeepReadonly<HarnessState['capabilityProfile']>;
71
68
  assembleMessages(messages: Message[], options?: PromptAssemblyOptions): Message[];
@@ -73,8 +70,20 @@ export interface TaskContextService {
73
70
  observeAppliedSkills(skills: TaskContextAppliedSkill[]): void;
74
71
  checkToolUse(input: TaskContextToolInput): DeepReadonly<DriftCheckResult>;
75
72
  observeToolResult(input: TaskContextToolResultInput): void;
73
+ observeVerificationWorkspace(fingerprint: string | null): void;
74
+ refreshVerificationWorkspace(capture?: () => string | null): void;
75
+ noteIndeterminateWorkspaceChange(): void;
76
76
  observeTurn(input: TaskContextTurnInput): DeepReadonly<TurnSummary> | undefined;
77
- auditCompletion(): TaskContextCompletionDecisionV1;
77
+ activeTaskTodo(): string | undefined;
78
+ hasTaskTodos(): boolean;
79
+ missingExecutionChecklist(action?: TaskWorkspaceAction): string | undefined;
80
+ prepareTaskPlanStopCheck(): ReturnType<HarnessKernel['prepareTaskPlanStopCheck']>;
81
+ requiresVerification(): boolean;
82
+ recordTaskTodoReceipt(step: string, observation: TaskTodoObservation): void;
83
+ updateTaskTodos(todos: NonNullable<HarnessState['taskTodos']>, blockedReason?: string): string | undefined;
84
+ progressState(): HarnessProgressState;
85
+ recordProgress(baseline: HarnessProgressState, unconfirmedWorkspaceRevisions?: number): void;
86
+ auditCompletion(enforceTaskTodos?: boolean, requireEveryCriterion?: boolean): TaskContextCompletionDecisionV1;
78
87
  completionBlockedMessage(result: CompletionGateResult): Message;
79
88
  toolBlockedResult(result: DriftCheckResult): string;
80
89
  linkEvidence(criterionId: string, evidenceRef: string): boolean;
@@ -84,6 +93,7 @@ export interface TaskContextService {
84
93
  getCapsule(): DeepReadonly<ContextCapsule> | undefined;
85
94
  explain(): TaskContextExplanation;
86
95
  snapshot(): DeepReadonly<TaskContextSnapshotV1>;
96
+ restoreGoalCheckpoint(state: HarnessState, revision: number): void;
87
97
  /** Mutable clone intended for the future atomic TurnCommit owner. */
88
98
  exportState(): HarnessState;
89
99
  }
@@ -16,23 +16,30 @@ function immutableClone(value) {
16
16
  }
17
17
  class HarnessKernelTaskContextService {
18
18
  constructor(options) {
19
+ this.options = options;
19
20
  this.serviceId = 'task-context';
20
21
  if (!Number.isSafeInteger(options.revision ?? 0) || (options.revision ?? 0) < 0) {
21
22
  throw new RangeError('TaskContext revision must be a non-negative safe integer.');
22
23
  }
23
24
  this.revisionValue = options.revision ?? 0;
24
- this.kernel = new context_harness_1.HarnessKernel({
25
- cwd: options.cwd,
26
- modelId: options.modelId,
27
- state: options.state ? structuredClone(options.state) : undefined,
28
- config: { completionGate: 'block', ...options.config },
25
+ this.captureVerificationWorkspace = options.captureVerificationWorkspace;
26
+ this.kernel = this.createKernel(options.state);
27
+ }
28
+ createKernel(state) {
29
+ return new context_harness_1.HarnessKernel({
30
+ cwd: this.options.cwd,
31
+ modelId: this.options.modelId,
32
+ state: state ? structuredClone(state) : undefined,
33
+ config: { completionGate: 'block', ...this.options.config },
34
+ requireLocalVerificationReceipt: this.options.requireLocalVerificationReceipt,
29
35
  });
30
36
  }
31
37
  get revision() {
32
38
  return this.revisionValue;
33
39
  }
34
- observeUserInput(input) {
35
- const result = this.mutate(() => this.kernel.updateContractFromUserInput(input));
40
+ observeUserInput(input, goalTaskId) {
41
+ const result = this.mutate(() => this.kernel.updateContractFromUserInput(input, goalTaskId));
42
+ this.refreshVerificationWorkspace();
36
43
  return result ? immutableClone(result) : undefined;
37
44
  }
38
45
  classifyIntent(input) {
@@ -56,12 +63,53 @@ class HarnessKernelTaskContextService {
56
63
  observeToolResult(input) {
57
64
  this.mutate(() => this.kernel.recordToolResult(input));
58
65
  }
66
+ observeVerificationWorkspace(fingerprint) {
67
+ this.mutate(() => this.kernel.observeVerificationWorkspace(fingerprint));
68
+ }
69
+ refreshVerificationWorkspace(capture = this.captureVerificationWorkspace) {
70
+ if (capture && this.kernel.hasCurrentWorkspaceVerification(true)) {
71
+ this.observeVerificationWorkspace(capture());
72
+ }
73
+ }
74
+ noteIndeterminateWorkspaceChange() {
75
+ this.mutate(() => this.kernel.noteIndeterminateWorkspaceChange());
76
+ }
59
77
  observeTurn(input) {
60
78
  const result = this.mutate(() => this.kernel.ingestTurn(input));
61
79
  return result ? immutableClone(result) : undefined;
62
80
  }
63
- auditCompletion() {
64
- const result = this.mutate(() => this.kernel.beforeComplete());
81
+ activeTaskTodo() {
82
+ return this.kernel.activeTaskTodo();
83
+ }
84
+ hasTaskTodos() {
85
+ return this.kernel.hasTaskTodos();
86
+ }
87
+ missingExecutionChecklist(action) {
88
+ return this.kernel.missingExecutionChecklist(action);
89
+ }
90
+ prepareTaskPlanStopCheck() {
91
+ return this.kernel.prepareTaskPlanStopCheck();
92
+ }
93
+ requiresVerification() {
94
+ return this.kernel.requiresVerification();
95
+ }
96
+ recordTaskTodoReceipt(step, observation) {
97
+ this.mutate(() => this.kernel.recordTaskTodoReceipt(step, observation));
98
+ }
99
+ updateTaskTodos(todos, blockedReason) {
100
+ if (todos.some(todo => todo.status === 'completed'))
101
+ this.refreshVerificationWorkspace();
102
+ return this.mutate(() => this.kernel.updateTaskTodos(todos, blockedReason));
103
+ }
104
+ progressState() {
105
+ return this.kernel.progressState();
106
+ }
107
+ recordProgress(baseline, unconfirmedWorkspaceRevisions) {
108
+ this.mutate(() => this.kernel.recordProgress(baseline, unconfirmedWorkspaceRevisions));
109
+ }
110
+ auditCompletion(enforceTaskTodos = false, requireEveryCriterion = false) {
111
+ this.refreshVerificationWorkspace();
112
+ const result = this.mutate(() => this.kernel.beforeComplete(enforceTaskTodos, requireEveryCriterion));
65
113
  return immutableClone({
66
114
  ...result,
67
115
  version: 1,
@@ -108,6 +156,18 @@ class HarnessKernelTaskContextService {
108
156
  exportState() {
109
157
  return structuredClone(this.kernel.toJSON());
110
158
  }
159
+ restoreGoalCheckpoint(state, revision) {
160
+ const counts = this.kernel.progressState().progressCountedByReason;
161
+ this.kernel = this.createKernel({
162
+ ...state,
163
+ progressState: {
164
+ schemaVersion: 1,
165
+ ...state.progressState,
166
+ ...(counts ? { progressCountedByReason: counts } : {}),
167
+ },
168
+ });
169
+ this.revisionValue = Math.max(this.revisionValue, revision) + 1;
170
+ }
111
171
  mutate(operation) {
112
172
  const before = this.kernel.toJSON().updatedAt;
113
173
  const result = operation();
@@ -14,6 +14,7 @@ export interface ActiveThreadTurnV1 {
14
14
  readonly kind: ThreadTurnKindV1;
15
15
  readonly startedAt: number;
16
16
  readonly interruptIntentId?: string;
17
+ readonly steeringClosed?: true;
17
18
  }
18
19
  export interface QueuedThreadTurnV1 {
19
20
  readonly queueId: string;
@@ -104,9 +105,10 @@ export declare class ThreadAdmissionControllerV1 {
104
105
  admit(command: Extract<AgentRuntimeCommandV1, {
105
106
  type: 'turn.start' | 'turn.steer' | 'turn.follow_up' | 'turn.interrupt';
106
107
  }>): ThreadCommandAdmissionV1;
107
- start(request: ThreadTurnRequestV1): TurnAdmissionV1;
108
+ start(request: ThreadTurnRequestV1, pendingFollowupId?: string): TurnAdmissionV1;
108
109
  followUp(request: ThreadTurnRequestV1): TurnAdmissionV1;
109
110
  steer(input: string): TurnAdmissionV1;
111
+ closeSteering(turnId: string): void;
110
112
  interrupt(): InterruptAdmissionV1;
111
113
  finish(turnId: string): ThreadTurnFinishV1;
112
114
  /**
@@ -46,8 +46,8 @@ class ThreadAdmissionControllerV1 {
46
46
  return this.interrupt();
47
47
  }
48
48
  }
49
- start(request) {
50
- return this.admitTurn(request, 'start');
49
+ start(request, pendingFollowupId) {
50
+ return this.admitTurn(request, 'start', pendingFollowupId);
51
51
  }
52
52
  followUp(request) {
53
53
  return this.admitTurn(request, 'follow_up');
@@ -57,8 +57,11 @@ class ThreadAdmissionControllerV1 {
57
57
  return rejected('shutdown');
58
58
  if (!this.activeTurn)
59
59
  return rejected('no_active_turn');
60
- if (this.activeTurn.kind === 'maintenance')
60
+ if (this.activeTurn.kind === 'maintenance' ||
61
+ this.activeTurn.steeringClosed ||
62
+ this.activeTurn.interruptIntentId) {
61
63
  return rejected('non_steerable');
64
+ }
62
65
  if (!validInput(input, this.maxInputBytes))
63
66
  return rejected('invalid_input');
64
67
  return {
@@ -67,6 +70,11 @@ class ThreadAdmissionControllerV1 {
67
70
  itemId: this.nextId('steer item'),
68
71
  };
69
72
  }
73
+ closeSteering(turnId) {
74
+ if (this.activeTurn?.turnId === turnId && !this.activeTurn.steeringClosed) {
75
+ this.activeTurn = { ...this.activeTurn, steeringClosed: true };
76
+ }
77
+ }
70
78
  interrupt() {
71
79
  if (this.shutdown)
72
80
  return { status: 'rejected', reason: 'shutdown' };
@@ -175,9 +183,15 @@ class ThreadAdmissionControllerV1 {
175
183
  this.continuationMode = snapshot.continuationMode;
176
184
  this.shutdown = snapshot.shutdown;
177
185
  }
178
- admitTurn(request, source) {
186
+ admitTurn(request, source, pendingFollowupId) {
179
187
  if (this.shutdown)
180
188
  return rejected('shutdown');
189
+ if (pendingFollowupId !== undefined) {
190
+ if (!(0, runtime_protocol_v1_1.isRuntimeId)(pendingFollowupId))
191
+ return rejected('invalid_input');
192
+ if (this.activeTurn || this.queue.length > 0)
193
+ return rejected('overloaded');
194
+ }
181
195
  const now = this.clock();
182
196
  this.dropExpired(now);
183
197
  const inputBytes = Buffer.byteLength(request.input, 'utf8');
@@ -188,7 +202,7 @@ class ThreadAdmissionControllerV1 {
188
202
  }
189
203
  const kind = request.kind ?? (request.mode === 'maintenance' ? 'maintenance' : 'regular');
190
204
  if (!this.activeTurn) {
191
- const active = this.begin({ ...request, kind }, now);
205
+ const active = this.begin({ ...request, kind }, now, pendingFollowupId);
192
206
  return { status: 'started', turnId: active.turnId };
193
207
  }
194
208
  if (this.queue.length >= this.maxQueuedItems ||
@@ -212,9 +226,9 @@ class ThreadAdmissionControllerV1 {
212
226
  this.queuedBytes += inputBytes;
213
227
  return { status: 'queued', queueId, position: this.queue.length, deadline };
214
228
  }
215
- begin(request, now) {
229
+ begin(request, now, pendingFollowupId) {
216
230
  const active = {
217
- turnId: this.nextId('turn'),
231
+ turnId: pendingFollowupId ?? this.nextId('turn'),
218
232
  input: request.input,
219
233
  mode: request.mode,
220
234
  kind: request.kind,
@@ -14,7 +14,7 @@ export interface ThreadEventReplayV1 {
14
14
  readonly nextCursor: number;
15
15
  readonly hasMore: boolean;
16
16
  }
17
- export type ThreadEventReplayReasonV1 = 'direct' | 'capability_receipt_journal' | 'durable_tool_receipt' | 'legacy_materializer' | 'projection_schema_upgrade' | 'runtime_diagnostics_legacy' | 'subagent_receipt_journal' | 'thread_session_view' | 'turn_commit_journal' | 'ui_gap_recovery' | 'ui_initial_history';
17
+ export type ThreadEventReplayReasonV1 = 'direct' | 'capability_receipt_journal' | 'durable_tool_receipt' | 'legacy_materializer' | 'projection_schema_upgrade' | 'runtime_diagnostics_legacy' | 'subagent_receipt_journal' | 'task_context_recovery' | 'thread_session_view' | 'turn_commit_journal' | 'ui_gap_recovery' | 'ui_initial_history';
18
18
  export interface ThreadEventCommitV1 {
19
19
  readonly events: readonly RuntimeEventEnvelopeV1[];
20
20
  readonly projection: ThreadProjectionV1;
@@ -125,7 +125,7 @@ export declare class ThreadEventStore {
125
125
  private cachedHead?;
126
126
  constructor(rootDir: string, threadId: string, options?: ThreadEventStoreOptionsV1);
127
127
  appendDurable<T extends RuntimeEventV1>(input: AppendRuntimeEventV1<T>): RuntimeEventEnvelopeV1<T>;
128
- appendDurableBatch(inputs: readonly AppendRuntimeEventV1[]): ThreadEventCommitV1;
128
+ appendDurableBatch(inputs: readonly AppendRuntimeEventV1[], expectedCursor?: number): ThreadEventCommitV1;
129
129
  /** Observe locally committed durable facts after log and projection fsync. */
130
130
  subscribeCommitted(listener: (events: readonly RuntimeEventEnvelopeV1[]) => void): () => void;
131
131
  createEphemeral<T extends Extract<RuntimeEventV1, {
@@ -65,13 +65,16 @@ class ThreadEventStore {
65
65
  appendDurable(input) {
66
66
  return this.appendDurableBatch([input]).events[0];
67
67
  }
68
- appendDurableBatch(inputs) {
68
+ appendDurableBatch(inputs, expectedCursor) {
69
69
  if (inputs.length === 0) {
70
70
  return { events: [], projection: this.loadProjection() };
71
71
  }
72
72
  const commit = this.withLogLock(() => {
73
73
  ensurePrivateDirectory(this.rootDir);
74
74
  let head = this.loadVerifiedHead();
75
+ if (expectedCursor !== undefined && head.projection.cursor !== expectedCursor) {
76
+ throw new ThreadEventStoreError('ORION_THREAD_EVENT_CURSOR', `Thread changed before append (expected cursor ${expectedCursor}, found ${head.projection.cursor})`);
77
+ }
75
78
  if (!(0, thread_projection_1.hasCurrentThreadProjectionShapeV1)(head.projection)) {
76
79
  // An older projection cannot be incrementally advanced because it did
77
80
  // not retain all diagnostic/compact history. Rebuild from facts once.
@@ -535,7 +538,9 @@ class ThreadEventStore {
535
538
  });
536
539
  }
537
540
  }
538
- return inputs.length > 0 ? this.appendDurableBatch(inputs).projection : projection;
541
+ return inputs.length > 0
542
+ ? this.appendDurableBatch(inputs, projection.cursor).projection
543
+ : projection;
539
544
  }
540
545
  /**
541
546
  * Return the last verified log head. A fresh process may adopt the persisted