@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,279 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readRsiLifecycle = readRsiLifecycle;
4
+ exports.summarizeRsiObservations = summarizeRsiObservations;
5
+ exports.advanceRsi = advanceRsi;
6
+ const fs_1 = require("fs");
7
+ const path_1 = require("path");
8
+ const atomic_write_1 = require("../../services/atomic-write");
9
+ const file_lock_1 = require("../../services/file-lock");
10
+ const global_config_1 = require("../../services/global-config");
11
+ const evaluation_1 = require("./evaluation");
12
+ const proposal_1 = require("./proposal");
13
+ const receipt_1 = require("./receipt");
14
+ const skill_state_1 = require("./skill-state");
15
+ const trajectory_1 = require("./trajectory");
16
+ function readRsiLifecycle(output, proposalDigest, comparisonDigest) {
17
+ const state = (0, receipt_1.readRsiState)((0, path_1.join)(output, 'lifecycle.json'));
18
+ if (state &&
19
+ (state.proposalDigest !== proposalDigest || state.comparisonDigest !== comparisonDigest)) {
20
+ throw new Error('RSI lifecycle does not match the proposal and comparison receipts.');
21
+ }
22
+ return state;
23
+ }
24
+ function summarizeRsiObservations(state, category) {
25
+ const turns = state.observations
26
+ .flatMap(item => item.turns)
27
+ .filter(turn => turn.category === category);
28
+ if (turns.length === 0)
29
+ return undefined;
30
+ return {
31
+ turns: turns.length,
32
+ recurrences: turns.filter(turn => turn.result !== 'accepted').length,
33
+ toolCalls: turns.reduce((sum, turn) => sum + turn.toolReceipts.length, 0),
34
+ elapsedMs: turns.reduce((sum, turn) => sum + (turn.skillProof?.elapsedMs ?? 0), 0),
35
+ };
36
+ }
37
+ function commonGitDir(cwd) {
38
+ return (0, fs_1.realpathSync)((0, proposal_1.rsiGit)(cwd, ['rev-parse', '--path-format=absolute', '--git-common-dir']).trim());
39
+ }
40
+ function reviewGitDir(repository, worktree, baseCommit) {
41
+ (0, proposal_1.resolveRsiBase)({ repository: worktree, baseCommit });
42
+ const common = commonGitDir(worktree);
43
+ const gitDir = (0, fs_1.realpathSync)((0, proposal_1.rsiGit)(worktree, ['rev-parse', '--absolute-git-dir']).trim());
44
+ if (worktree === repository || common !== commonGitDir(repository) || gitDir === common) {
45
+ throw new Error('RSI apply needs a separate linked Git worktree of the selected repository.');
46
+ }
47
+ return gitDir;
48
+ }
49
+ function head(cwd) {
50
+ return (0, proposal_1.rsiGit)(cwd, ['rev-parse', 'HEAD']).trim();
51
+ }
52
+ function assertDescends(cwd, ancestor, commit) {
53
+ try {
54
+ (0, proposal_1.rsiGit)(cwd, ['merge-base', '--is-ancestor', ancestor, commit]);
55
+ }
56
+ catch {
57
+ throw new Error('The review worktree HEAD does not descend from the accepted RSI commit.');
58
+ }
59
+ }
60
+ function assertTargetUnstaged(cwd, candidate) {
61
+ if ((0, proposal_1.rsiGit)(cwd, ['diff', '--cached', '--name-only', '-z', '--', candidate.path])) {
62
+ throw new Error('Unstage the target Skill before running RSI.');
63
+ }
64
+ }
65
+ function otherSkillPath(candidate) {
66
+ const root = candidate.path.startsWith('.agents/') ? '.orion-code/skills' : '.agents/skills';
67
+ return `${root}/${candidate.skill}/SKILL.md`;
68
+ }
69
+ function replaceSkill(worktree, candidate, before, after) {
70
+ const current = (0, skill_state_1.readWorktreeSkill)(worktree, candidate.path);
71
+ if ((0, skill_state_1.readWorktreeSkill)(worktree, otherSkillPath(candidate)) !== undefined ||
72
+ (current !== before && current !== after))
73
+ throw new Error('The target Skill changed or has a conflicting project copy.');
74
+ if (current === after)
75
+ return;
76
+ const path = (0, path_1.join)(worktree, candidate.path);
77
+ if (after === undefined) {
78
+ (0, fs_1.unlinkSync)(path);
79
+ }
80
+ else {
81
+ (0, fs_1.mkdirSync)((0, path_1.dirname)(path), { recursive: true, mode: 0o755 });
82
+ const mode = current === undefined ? 0o644 : (0, fs_1.lstatSync)(path).mode & 0o777;
83
+ (0, atomic_write_1.atomicWriteFileSync)(path, after, { mode, fsync: true });
84
+ }
85
+ if ((0, skill_state_1.readWorktreeSkill)(worktree, candidate.path) !== after)
86
+ throw new Error('RSI Skill readback differs after writing.');
87
+ }
88
+ function verifyReviewCommit(worktree, commit, parent, candidate, expected) {
89
+ (0, proposal_1.resolveRsiBase)({ repository: worktree, baseCommit: commit });
90
+ const [actualParent, ...otherParents] = (0, proposal_1.rsiGit)(worktree, ['show', '-s', '--format=%P', commit])
91
+ .trim()
92
+ .split(' ');
93
+ const changed = (0, proposal_1.rsiGit)(worktree, [
94
+ 'diff-tree',
95
+ '--no-commit-id',
96
+ '--name-only',
97
+ '-r',
98
+ '-z',
99
+ parent,
100
+ commit,
101
+ '--',
102
+ ]);
103
+ const mode = (ref) => (0, proposal_1.rsiGit)(worktree, ['ls-tree', '-z', ref, '--', candidate.path]).split(' ')[0];
104
+ if (head(worktree) !== commit ||
105
+ actualParent !== parent ||
106
+ otherParents.length !== 0 ||
107
+ changed !== `${candidate.path}\0` ||
108
+ (expected !== undefined && mode(commit) !== (mode(parent) || '100644')) ||
109
+ (0, proposal_1.readRsiGitFile)(worktree, commit, candidate.path) !== expected ||
110
+ (0, skill_state_1.readWorktreeSkill)(worktree, candidate.path) !== expected ||
111
+ (0, skill_state_1.readWorktreeSkill)(worktree, otherSkillPath(candidate)) !== undefined)
112
+ throw new Error('The review commit must be at HEAD, descend directly from the recorded parent, and change only the exact RSI Skill.');
113
+ assertTargetUnstaged(worktree, candidate);
114
+ }
115
+ async function advanceRsi(output, request) {
116
+ const directory = (0, fs_1.realpathSync)((0, path_1.resolve)(output));
117
+ const proposal = (0, receipt_1.readRsiReceipt)(directory);
118
+ const comparison = (0, evaluation_1.readRsiComparison)(directory, proposal.digest);
119
+ const candidate = proposal.proposal;
120
+ if (!('patch' in candidate) ||
121
+ comparison?.phase !== 'awaiting_review' ||
122
+ comparison.verdict !== 'improved' ||
123
+ comparison.candidateDigest !== candidate.candidateContentDigest)
124
+ throw new Error('RSI apply requires a paired evaluation that reached awaiting_review.');
125
+ const { before, after } = await (0, proposal_1.resolveRsiCandidate)(proposal.repository, candidate);
126
+ const path = (0, path_1.join)(directory, 'lifecycle.json');
127
+ const read = () => readRsiLifecycle(directory, proposal.digest, comparison.digest);
128
+ const initial = read();
129
+ const worktree = 'worktree' in request ? (0, fs_1.realpathSync)((0, path_1.resolve)(request.worktree)) : initial?.worktree;
130
+ if (!worktree)
131
+ throw new Error('Apply the candidate to a review worktree first.');
132
+ const gitDir = reviewGitDir(proposal.repository, worktree, candidate.baseCommit);
133
+ const save = (state, update) => {
134
+ const { version, proposalDigest, comparisonDigest, candidateDigest, worktree, phase, accepted, rollback, observations, rollbackObservation, } = { ...state, ...update };
135
+ return (0, receipt_1.writeRsiState)(path, {
136
+ version,
137
+ proposalDigest,
138
+ comparisonDigest,
139
+ candidateDigest,
140
+ worktree,
141
+ phase,
142
+ observations,
143
+ ...(accepted ? { accepted } : {}),
144
+ ...(rollback ? { rollback } : {}),
145
+ ...(rollbackObservation ? { rollbackObservation } : {}),
146
+ });
147
+ };
148
+ const lock = (fn) => (0, file_lock_1.withFileLockSync)(path, () => (0, file_lock_1.withFileLockSync)((0, path_1.join)(gitDir, 'orion-rsi'), fn));
149
+ if (request.action === 'observe') {
150
+ if (!initial?.accepted ||
151
+ (initial.phase !== 'accepted' &&
152
+ initial.phase !== 'observed' &&
153
+ initial.phase !== 'rolled_back' &&
154
+ initial.phase !== 'rollback_verified'))
155
+ throw new Error('Record the verified adoption or rollback commit before observing its effect.');
156
+ const isRollback = initial.phase === 'rolled_back' || initial.phase === 'rollback_verified';
157
+ const requiredCommit = isRollback ? initial.rollback.commit : initial.accepted.commit;
158
+ const since = isRollback ? initial.rollback.at : initial.accepted.at;
159
+ const expected = isRollback ? before : after;
160
+ const input = (0, trajectory_1.parseRsiSelection)((0, receipt_1.readRsiJson)(request.input));
161
+ const workspace = (0, proposal_1.resolveRsiBase)(input);
162
+ const selection = { ...input, repository: workspace };
163
+ if (commonGitDir(workspace) !== commonGitDir(worktree) ||
164
+ selection.baseCommit !== head(workspace)) {
165
+ throw new Error('Observation must name a checkout of the same repository and its current HEAD.');
166
+ }
167
+ assertDescends(workspace, requiredCommit, selection.baseCommit);
168
+ if ((0, proposal_1.readRsiGitFile)(workspace, selection.baseCommit, candidate.path) !== expected) {
169
+ throw new Error('The observed commit does not contain the expected Skill revision.');
170
+ }
171
+ const skill = await (0, skill_state_1.inspectRsiSkill)(workspace, candidate, expected, (0, global_config_1.loadGlobalConfig)().skills?.paths);
172
+ const evidence = (0, trajectory_1.collectRsiEvidence)(selection, skill);
173
+ if (evidence.some(turn => !turn.skillProof?.verified || turn.skillProof.startedAt < since)) {
174
+ throw new Error('Each follow-up must be a new durable turn with verified use of the expected Skill revision.');
175
+ }
176
+ return lock(() => {
177
+ if (read()?.digest !== initial.digest ||
178
+ head(workspace) !== selection.baseCommit ||
179
+ (0, skill_state_1.readWorktreeSkill)(workspace, candidate.path) !== expected ||
180
+ (0, skill_state_1.readWorktreeSkill)(workspace, otherSkillPath(candidate)) !== undefined)
181
+ throw new Error('The observed workspace or RSI state has changed. Retry the observation.');
182
+ const observation = { workspace, commit: selection.baseCommit, turns: evidence };
183
+ if (initial.phase === 'rollback_verified') {
184
+ const saved = initial.rollbackObservation;
185
+ if (saved.workspace !== workspace ||
186
+ saved.commit !== observation.commit ||
187
+ JSON.stringify(saved.turns.map(turn => turn.turnCommitDigest)) !==
188
+ JSON.stringify(evidence.map(turn => turn.turnCommitDigest)))
189
+ throw new Error('The rollback already has a different verified observation.');
190
+ return initial;
191
+ }
192
+ if (isRollback)
193
+ return save(initial, { phase: 'rollback_verified', rollbackObservation: observation });
194
+ const seen = new Set(initial.observations.flatMap(item => item.turns.map(turn => turn.turnCommitDigest)));
195
+ const fresh = evidence.filter(turn => !seen.has(turn.turnCommitDigest));
196
+ if (fresh.length === 0)
197
+ return initial;
198
+ if (seen.size + fresh.length > 64)
199
+ throw new Error('This RSI run already has its maximum 64 observations.');
200
+ return save(initial, {
201
+ phase: 'observed',
202
+ observations: [...initial.observations, { ...observation, turns: fresh }],
203
+ });
204
+ });
205
+ }
206
+ return lock(() => {
207
+ let state = read();
208
+ if (state && state.worktree !== worktree)
209
+ throw new Error('The run is bound to a different review worktree.');
210
+ if (request.action === 'apply') {
211
+ if (request.candidate !== candidate.candidateContentDigest)
212
+ throw new Error('Explicit candidate digest approval is required.');
213
+ if (state && state.phase !== 'applying')
214
+ return state;
215
+ if (head(worktree) !== candidate.baseCommit)
216
+ throw new Error('The review worktree HEAD must match the proposal base.');
217
+ assertTargetUnstaged(worktree, candidate);
218
+ if (!state) {
219
+ if ((0, skill_state_1.readWorktreeSkill)(worktree, candidate.path) !== before ||
220
+ (0, skill_state_1.readWorktreeSkill)(worktree, otherSkillPath(candidate)) !== undefined)
221
+ throw new Error('The target Skill has local changes or another project copy.');
222
+ state = (0, receipt_1.writeRsiState)(path, {
223
+ version: 1,
224
+ proposalDigest: proposal.digest,
225
+ comparisonDigest: comparison.digest,
226
+ candidateDigest: candidate.candidateContentDigest,
227
+ worktree,
228
+ phase: 'applying',
229
+ observations: [],
230
+ });
231
+ }
232
+ replaceSkill(worktree, candidate, before, after);
233
+ return save(state, { phase: 'applied_to_review' });
234
+ }
235
+ if (request.action === 'accept') {
236
+ if (state?.accepted?.commit === request.commit)
237
+ return state;
238
+ if (!state || state.phase !== 'applied_to_review')
239
+ throw new Error('Apply the candidate before recording its review commit.');
240
+ verifyReviewCommit(worktree, request.commit, candidate.baseCommit, candidate, after);
241
+ return save(state, {
242
+ phase: 'accepted',
243
+ accepted: { commit: request.commit, at: Date.now() },
244
+ });
245
+ }
246
+ if (!state?.accepted)
247
+ throw new Error('Accept the candidate before rolling it back.');
248
+ if (request.commit !== undefined) {
249
+ if (state.rollback?.commit === request.commit)
250
+ return state;
251
+ if (state.phase !== 'rollback_pending_commit' || !state.rollback) {
252
+ throw new Error('Prepare the rollback before recording its separate commit.');
253
+ }
254
+ verifyReviewCommit(worktree, request.commit, state.rollback.parent, candidate, before);
255
+ return save(state, {
256
+ phase: 'rolled_back',
257
+ rollback: { ...state.rollback, commit: request.commit, at: Date.now() },
258
+ });
259
+ }
260
+ if (state.phase === 'rollback_pending_commit' ||
261
+ state.phase === 'rolled_back' ||
262
+ state.phase === 'rollback_verified')
263
+ return state;
264
+ const parent = state.rollback?.parent ?? head(worktree);
265
+ if (head(worktree) !== parent || (0, proposal_1.readRsiGitFile)(worktree, parent, candidate.path) !== after)
266
+ throw new Error('The current HEAD no longer has the accepted RSI Skill.');
267
+ assertDescends(worktree, state.accepted.commit, parent);
268
+ assertTargetUnstaged(worktree, candidate);
269
+ if (state.phase !== 'rolling_back') {
270
+ if ((0, skill_state_1.readWorktreeSkill)(worktree, candidate.path) !== after ||
271
+ (0, skill_state_1.readWorktreeSkill)(worktree, otherSkillPath(candidate)) !== undefined)
272
+ throw new Error('The accepted Skill has local changes or another project copy.');
273
+ state = save(state, { phase: 'rolling_back', rollback: { parent } });
274
+ }
275
+ replaceSkill(worktree, candidate, after, before);
276
+ return save(state, { phase: 'rollback_pending_commit' });
277
+ });
278
+ }
279
+ //# sourceMappingURL=lifecycle.js.map
@@ -0,0 +1,39 @@
1
+ import { type RsiCategory, type RsiDiagnosticCode, type RsiSelectionV1, type RsiTurnEvidenceV1 } from './contracts';
2
+ export type RsiProposalV1 = {
3
+ readonly version: 1;
4
+ readonly baseCommit: string;
5
+ readonly policyDigest: string;
6
+ readonly evidenceDigests: readonly string[];
7
+ } & ({
8
+ readonly decision: 'skip';
9
+ readonly reason: 'no_corrections' | 'unrepeated_problem' | 'rule_already_present' | 'runtime_review_required';
10
+ } | {
11
+ readonly decision: 'harness_proposal';
12
+ readonly diagnosis: RsiDiagnosticCode;
13
+ readonly verification: string;
14
+ } | {
15
+ readonly decision: 'tool_proposal';
16
+ readonly category: 'missing_tool';
17
+ readonly verification: string;
18
+ } | {
19
+ readonly decision: 'edit_skill' | 'new_project_skill';
20
+ readonly category: Exclude<RsiCategory, 'missing_tool'>;
21
+ readonly skill: string;
22
+ readonly path: string;
23
+ readonly baseContentDigest: string | null;
24
+ readonly candidateContentDigest: string;
25
+ readonly patch: string;
26
+ });
27
+ export declare function rsiGit(cwd: string, args: readonly string[]): string;
28
+ export declare function resolveRsiBase(selection: Pick<RsiSelectionV1, 'repository' | 'baseCommit'>): string;
29
+ export declare function readRsiGitFile(repository: string, base: string, path: string): string | undefined;
30
+ export type RsiSkillCandidate = Extract<RsiProposalV1, {
31
+ path: string;
32
+ }>;
33
+ /** Resolve the approved bytes from the original Git base and fixed generator. */
34
+ export declare function resolveRsiCandidate(repository: string, candidate: RsiSkillCandidate): Promise<{
35
+ before: string | undefined;
36
+ after: string;
37
+ }>;
38
+ export declare function proposeRsiSkill(repository: string, baseCommit: string, evidence: readonly RsiTurnEvidenceV1[]): Promise<RsiProposalV1>;
39
+ //# sourceMappingURL=proposal.d.ts.map
@@ -0,0 +1,312 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rsiGit = rsiGit;
4
+ exports.resolveRsiBase = resolveRsiBase;
5
+ exports.readRsiGitFile = readRsiGitFile;
6
+ exports.resolveRsiCandidate = resolveRsiCandidate;
7
+ exports.proposeRsiSkill = proposeRsiSkill;
8
+ const child_process_1 = require("child_process");
9
+ const fs_1 = require("fs");
10
+ const os_1 = require("os");
11
+ const path_1 = require("path");
12
+ const canonical_1 = require("../protocol/canonical");
13
+ const filesystem_skill_provider_1 = require("../skills/filesystem-skill-provider");
14
+ const contracts_1 = require("./contracts");
15
+ const diagnosis_1 = require("./diagnosis");
16
+ const SKILL_ROOTS = ['.agents/skills', '.orion-code/skills'];
17
+ const MAX_BLOB_BYTES = 64 * 1024;
18
+ const SKILL_NAME = /^[a-z0-9][a-z0-9-]{0,63}$/u;
19
+ const CATEGORY_RULES = {
20
+ cross_module_callers: 'When a public interface changes, find its direct callers and relevant tests. Update the affected call sites and verify the shared contract.',
21
+ local_edit_cost: 'For a private implementation change, inspect the edited module and its local tests. Widen the search only when a public interface or cross-module dependency changes.',
22
+ missing_verification: 'Before reporting completion, run the narrowest project check that verifies the changed behavior. Report the check result and any verification still pending.',
23
+ };
24
+ function gitEnvironment() {
25
+ return {
26
+ ...Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith('GIT_'))),
27
+ GIT_CONFIG_NOSYSTEM: '1',
28
+ GIT_CONFIG_GLOBAL: os_1.devNull,
29
+ GIT_OPTIONAL_LOCKS: '0',
30
+ };
31
+ }
32
+ function rsiGit(cwd, args) {
33
+ return (0, child_process_1.execFileSync)('git', ['--no-replace-objects', ...args], {
34
+ cwd,
35
+ encoding: 'utf8',
36
+ maxBuffer: 512 * 1024,
37
+ timeout: 5000,
38
+ env: gitEnvironment(),
39
+ stdio: ['ignore', 'pipe', 'pipe'],
40
+ });
41
+ }
42
+ function resolveRsiBase(selection) {
43
+ const repository = (0, fs_1.realpathSync)(selection.repository);
44
+ const root = (0, fs_1.realpathSync)(rsiGit(repository, ['rev-parse', '--show-toplevel']).trim());
45
+ if (root !== repository)
46
+ throw new Error('Selection repository must be the Git workspace root.');
47
+ if (!/^[a-f0-9]{40}(?:[a-f0-9]{24})?$/u.test(selection.baseCommit)) {
48
+ throw new Error('Selection baseCommit must be a full Git commit ID.');
49
+ }
50
+ const base = rsiGit(root, ['rev-parse', '--verify', `${selection.baseCommit}^{commit}`]).trim();
51
+ if (base !== selection.baseCommit)
52
+ throw new Error('Selection baseCommit must name a commit.');
53
+ return root;
54
+ }
55
+ function assertBaseDirectories(repository, base, path) {
56
+ const directories = path.split('/').slice(0, -1);
57
+ for (let depth = 1; depth <= directories.length; depth++) {
58
+ const parent = directories.slice(0, depth).join('/');
59
+ const entry = rsiGit(repository, ['ls-tree', '-z', base, '--', parent]);
60
+ if (!entry)
61
+ return;
62
+ if (!entry.startsWith('040000 tree '))
63
+ throw new Error(`Expected a Git directory at ${parent}.`);
64
+ }
65
+ }
66
+ function readRsiGitFile(repository, base, path) {
67
+ assertBaseDirectories(repository, base, path);
68
+ const entry = rsiGit(repository, ['ls-tree', '-z', base, '--', path]);
69
+ if (!entry)
70
+ return undefined;
71
+ const match = /^100(?:644|755) blob ([a-f0-9]{40,64})\t([^\0]+)\0$/u.exec(entry);
72
+ if (!match || match[2] !== path)
73
+ throw new Error(`Expected a regular Git blob at ${path}.`);
74
+ const blob = match[1];
75
+ if (Number(rsiGit(repository, ['cat-file', '-s', blob])) > MAX_BLOB_BYTES) {
76
+ throw new Error(`The Git blob at ${path} exceeds the RSI size limit.`);
77
+ }
78
+ return rsiGit(repository, ['cat-file', 'blob', blob]);
79
+ }
80
+ function readPolicy(repository, base) {
81
+ const contents = readRsiGitFile(repository, base, contracts_1.RSI_POLICY_PATH);
82
+ if (contents === undefined)
83
+ return contracts_1.DEFAULT_RSI_POLICY;
84
+ const policy = JSON.parse(contents);
85
+ if (!policy ||
86
+ Object.keys(policy).some(key => !['version', 'callerScope', 'priority', 'minimumRepeat'].includes(key)) ||
87
+ policy.version !== 1 ||
88
+ (policy.callerScope !== 'public-interface' && policy.callerScope !== 'all-edits') ||
89
+ !Number.isSafeInteger(policy.minimumRepeat) ||
90
+ policy.minimumRepeat < 2 ||
91
+ policy.minimumRepeat > 5 ||
92
+ !Array.isArray(policy.priority) ||
93
+ policy.priority.length !== contracts_1.RSI_CATEGORIES.length ||
94
+ !contracts_1.RSI_CATEGORIES.every(category => policy.priority.includes(category))) {
95
+ throw new Error('Invalid versioned RSI policy.');
96
+ }
97
+ return policy;
98
+ }
99
+ async function validateSkill(root, name) {
100
+ const provider = (0, filesystem_skill_provider_1.createFilesystemSkillProviderV1)({
101
+ roots: [{ path: root, sourceScope: 'project' }],
102
+ watch: false,
103
+ maxDefinitionBytes: MAX_BLOB_BYTES,
104
+ });
105
+ const signal = new AbortController().signal;
106
+ const observation = await provider.list({ id: 'rsi-fixture', sourceScopeOrder: ['project'] }, signal);
107
+ const selected = observation.descriptors.find(descriptor => descriptor.name === name);
108
+ if (!observation.complete ||
109
+ observation.descriptors.length !== 1 ||
110
+ !selected ||
111
+ !selected.modelInvocable) {
112
+ throw new Error(`Production Skill provider could not select ${name}.`);
113
+ }
114
+ const definition = await provider.get(selected.id, signal);
115
+ if (!definition)
116
+ throw new Error(`Production Skill provider could not load ${name}.`);
117
+ return {
118
+ name: selected.name,
119
+ capabilities: selected.requestedCapabilities,
120
+ userInvocable: selected.userInvocable,
121
+ modelInvocable: selected.modelInvocable,
122
+ };
123
+ }
124
+ function newSkill(name, rule) {
125
+ return [
126
+ '---',
127
+ `name: ${name}`,
128
+ 'description: Apply a verified project coding check when its trigger is present.',
129
+ 'capabilities: []',
130
+ 'model-invocable: true',
131
+ 'user-invocable: true',
132
+ '---',
133
+ '',
134
+ '## Project verification rule',
135
+ '',
136
+ rule,
137
+ '',
138
+ ].join('\n');
139
+ }
140
+ async function validateAndDiff(path, name, before, after) {
141
+ const work = (0, fs_1.mkdtempSync)((0, path_1.join)((0, os_1.tmpdir)(), 'orion-rsi-skill-'));
142
+ const write = (arm, content) => {
143
+ const file = (0, path_1.join)(work, arm, path);
144
+ (0, fs_1.mkdirSync)((0, path_1.join)(file, '..'), { recursive: true, mode: 0o700 });
145
+ (0, fs_1.writeFileSync)(file, content, { mode: 0o600 });
146
+ return (0, path_1.join)(work, arm, path.split('/').slice(0, -2).join('/'));
147
+ };
148
+ try {
149
+ const candidate = await validateSkill(write('candidate', after), name);
150
+ if (before !== undefined) {
151
+ const baseline = await validateSkill(write('base', before), name);
152
+ if ((0, canonical_1.digestRuntimeValue)(baseline) !== (0, canonical_1.digestRuntimeValue)(candidate)) {
153
+ throw new Error('The candidate changes the Skill invocation or capabilities.');
154
+ }
155
+ }
156
+ try {
157
+ return rsiGit(work, [
158
+ '--no-pager',
159
+ 'diff',
160
+ '--no-index',
161
+ '--no-textconv',
162
+ '--no-ext-diff',
163
+ '--',
164
+ before === undefined ? os_1.devNull : `base/${path}`,
165
+ `candidate/${path}`,
166
+ ]);
167
+ }
168
+ catch (error) {
169
+ const diff = error;
170
+ if (diff.status !== 1 || !diff.stdout?.startsWith('diff --git '))
171
+ throw error;
172
+ return diff.stdout
173
+ .split('\n')
174
+ .map(line => /^(diff --git |--- |\+\+\+ )/u.test(line)
175
+ ? line.replace(/([ab]\/)(?:base|candidate)\//gu, '$1')
176
+ : line)
177
+ .join('\n');
178
+ }
179
+ }
180
+ finally {
181
+ (0, fs_1.rmSync)(work, { recursive: true, force: true });
182
+ }
183
+ }
184
+ function addRule(name, rule, before) {
185
+ return before === undefined
186
+ ? newSkill(name, rule)
187
+ : `${before}${before.endsWith('\n') ? '\n' : '\n\n'}## Project verification rule\n\n${rule}\n`;
188
+ }
189
+ function getRule(category, policy) {
190
+ return category === 'cross_module_callers' && policy.callerScope === 'all-edits'
191
+ ? 'For each edit, find its callers and relevant tests before making the change. Verify every affected contract.'
192
+ : CATEGORY_RULES[category];
193
+ }
194
+ /** Resolve the approved bytes from the original Git base and fixed generator. */
195
+ async function resolveRsiCandidate(repository, candidate) {
196
+ const root = resolveRsiBase({ repository, baseCommit: candidate.baseCommit });
197
+ if (!SKILL_NAME.test(candidate.skill) ||
198
+ !SKILL_ROOTS.some(path => candidate.path === `${path}/${candidate.skill}/SKILL.md`) ||
199
+ !Object.prototype.hasOwnProperty.call(CATEGORY_RULES, candidate.category)) {
200
+ throw new Error('Invalid RSI Skill candidate path or category.');
201
+ }
202
+ const policy = readPolicy(root, candidate.baseCommit);
203
+ const before = readRsiGitFile(root, candidate.baseCommit, candidate.path);
204
+ const after = addRule(candidate.skill, getRule(candidate.category, policy), before);
205
+ if ((0, canonical_1.digestRuntimeValue)(policy) !== candidate.policyDigest ||
206
+ (before === undefined ? null : (0, canonical_1.digestRuntimeValue)(before)) !== candidate.baseContentDigest ||
207
+ (0, canonical_1.digestRuntimeValue)(after) !== candidate.candidateContentDigest ||
208
+ (before === undefined ? 'new_project_skill' : 'edit_skill') !== candidate.decision ||
209
+ (await validateAndDiff(candidate.path, candidate.skill, before, after)) !== candidate.patch) {
210
+ throw new Error('RSI Skill candidate differs from the verified base and generator.');
211
+ }
212
+ return { before, after };
213
+ }
214
+ async function proposeRsiSkill(repository, baseCommit, evidence) {
215
+ const policy = readPolicy(repository, baseCommit);
216
+ const policyDigest = (0, canonical_1.digestRuntimeValue)(policy);
217
+ const corrections = evidence.filter(turn => turn.result !== 'accepted');
218
+ const common = {
219
+ version: 1,
220
+ baseCommit,
221
+ policyDigest,
222
+ evidenceDigests: evidence.map(turn => turn.turnCommitDigest),
223
+ };
224
+ if (corrections.length === 0)
225
+ return { ...common, decision: 'skip', reason: 'no_corrections' };
226
+ const runtimeGroups = new Map();
227
+ const groups = new Map();
228
+ for (const turn of corrections) {
229
+ if (turn.diagnosis) {
230
+ const { code } = turn.diagnosis;
231
+ const { route } = diagnosis_1.RSI_DIAGNOSES[code];
232
+ if (route === 'harness') {
233
+ const observed = runtimeGroups.get(code) ?? [];
234
+ runtimeGroups.set(code, [...observed, turn]);
235
+ }
236
+ if (route !== 'needs_feedback')
237
+ continue;
238
+ }
239
+ const key = `${turn.category}:${turn.skill ?? ''}`;
240
+ const group = groups.get(key) ?? [];
241
+ group.push(turn);
242
+ groups.set(key, group);
243
+ }
244
+ const harness = [...runtimeGroups].sort(([left, a], [right, b]) => b.length - a.length || left.localeCompare(right))[0];
245
+ if (harness && (groups.size === 0 || harness[1].length >= policy.minimumRepeat)) {
246
+ const [diagnosis, observed] = harness;
247
+ return {
248
+ ...common,
249
+ decision: 'harness_proposal',
250
+ diagnosis,
251
+ evidenceDigests: observed.map(turn => turn.turnCommitDigest),
252
+ verification: diagnosis_1.RSI_DIAGNOSES[diagnosis].verify,
253
+ };
254
+ }
255
+ if (groups.size === 0)
256
+ return { ...common, decision: 'skip', reason: 'runtime_review_required' };
257
+ const ranked = [...groups.values()].sort((left, right) => right.length - left.length ||
258
+ policy.priority.indexOf(left[0].category) - policy.priority.indexOf(right[0].category) ||
259
+ (left[0].skill ?? '').localeCompare(right[0].skill ?? ''));
260
+ let ruleAlreadyPresent = false;
261
+ for (const group of ranked) {
262
+ const { category, skill } = group[0];
263
+ const selected = { ...common, evidenceDigests: group.map(turn => turn.turnCommitDigest) };
264
+ if (category === 'missing_tool') {
265
+ return {
266
+ ...selected,
267
+ decision: 'tool_proposal',
268
+ category,
269
+ verification: 'Reproduce the missing operation on a minimal fixture and define the result and workspace scope before implementation.',
270
+ };
271
+ }
272
+ const name = skill ?? `orion-rsi-${category.replace(/_/gu, '-')}`;
273
+ if (!SKILL_NAME.test(name))
274
+ throw new Error('Selection contains an invalid Skill name.');
275
+ const paths = SKILL_ROOTS.map(root => `${root}/${name}/SKILL.md`);
276
+ const present = paths.flatMap(path => {
277
+ const before = readRsiGitFile(repository, baseCommit, path);
278
+ return before === undefined ? [] : [{ path, before }];
279
+ });
280
+ if (present.length > 1)
281
+ throw new Error(`Project Skill ${name} is ambiguous at the comparison base.`);
282
+ if (skill && present.length === 0)
283
+ throw new Error(`Project Skill ${name} was not found at the comparison base.`);
284
+ if (present.length === 0 && group.length < policy.minimumRepeat)
285
+ continue;
286
+ const path = present[0]?.path ?? paths[0];
287
+ const before = present[0]?.before;
288
+ const rule = getRule(category, policy);
289
+ if (before?.includes(rule)) {
290
+ ruleAlreadyPresent = true;
291
+ continue;
292
+ }
293
+ const after = addRule(name, rule, before);
294
+ const patch = await validateAndDiff(path, name, before, after);
295
+ return {
296
+ ...selected,
297
+ decision: before === undefined ? 'new_project_skill' : 'edit_skill',
298
+ category,
299
+ path,
300
+ skill: name,
301
+ baseContentDigest: before === undefined ? null : (0, canonical_1.digestRuntimeValue)(before),
302
+ candidateContentDigest: (0, canonical_1.digestRuntimeValue)(after),
303
+ patch,
304
+ };
305
+ }
306
+ return {
307
+ ...common,
308
+ decision: 'skip',
309
+ reason: ruleAlreadyPresent ? 'rule_already_present' : 'unrepeated_problem',
310
+ };
311
+ }
312
+ //# sourceMappingURL=proposal.js.map
@@ -0,0 +1,28 @@
1
+ import type { RsiTurnEvidenceV1 } from './contracts';
2
+ import type { RsiProposalV1 } from './proposal';
3
+ export interface RsiProposalReceiptV1 {
4
+ readonly version: 1;
5
+ readonly repository: string;
6
+ readonly inputDigest: string;
7
+ readonly phase: 'awaiting_evaluation' | 'skipped' | 'tool_proposal' | 'harness_proposal';
8
+ readonly evaluation: 'not_run';
9
+ readonly evidence: readonly RsiTurnEvidenceV1[];
10
+ readonly proposal: RsiProposalV1;
11
+ readonly digest: string;
12
+ }
13
+ export declare function readRsiFile(path: string): string;
14
+ export declare function readRsiJson(path: string): unknown;
15
+ export declare function buildRsiReceipt(repository: string, inputDigest: string, evidence: readonly RsiTurnEvidenceV1[], proposal: RsiProposalV1): RsiProposalReceiptV1;
16
+ export declare function readRsiReceipt(output: string): RsiProposalReceiptV1;
17
+ export declare function readIfPresent(path: string): string | undefined;
18
+ export declare function readRsiState<T extends {
19
+ version: 1;
20
+ digest: string;
21
+ }>(path: string): T | undefined;
22
+ export declare function writeRsiState<T extends {
23
+ version: 1;
24
+ }>(path: string, body: T): T & {
25
+ digest: string;
26
+ };
27
+ export declare function writeRsiReceipt(output: string, receipt: RsiProposalReceiptV1): void;
28
+ //# sourceMappingURL=receipt.d.ts.map