@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
@@ -2,25 +2,24 @@
2
2
  /**
3
3
  * Orion Code - global configuration management.
4
4
  *
5
- * Config stored in ~/.orion-code/orion.json
6
- * Environment variable overrides use ORION_CODE_ prefix.
5
+ * Config stored in ~/.orion-code/orion.yaml
6
+ * ORION_CODE_CONFIG_DIR selects an isolated configuration root.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.updateTokenStats = exports.incrementSessionCount = exports.GlobalConfigDocumentValidationError = void 0;
10
10
  exports.validateGlobalConfigDocumentStrict = validateGlobalConfigDocumentStrict;
11
11
  exports.parseGlobalConfigDocumentStrict = parseGlobalConfigDocumentStrict;
12
+ exports.serializeGlobalConfigDocumentStrict = serializeGlobalConfigDocumentStrict;
12
13
  exports.loadGlobalConfig = loadGlobalConfig;
13
14
  exports.saveGlobalConfig = saveGlobalConfig;
14
15
  exports.updateGlobalConfig = updateGlobalConfig;
15
16
  exports.getProjectConfig = getProjectConfig;
16
17
  exports.saveProjectConfig = saveProjectConfig;
17
- exports.getOrCreateUserId = getOrCreateUserId;
18
- exports.recordFirstStartTime = recordFirstStartTime;
19
18
  exports.getInputHistory = getInputHistory;
20
19
  exports.addToInputHistory = addToInputHistory;
21
20
  exports.searchInputHistory = searchInputHistory;
22
21
  const fs_1 = require("fs");
23
- const crypto_1 = require("crypto");
22
+ const js_yaml_1 = require("js-yaml");
24
23
  const path_1 = require("path");
25
24
  const config_dir_1 = require("./config-dir");
26
25
  const atomic_write_1 = require("./atomic-write");
@@ -33,14 +32,15 @@ const model_registry_1 = require("./model-registry");
33
32
  const DEFAULT_CONFIG = {
34
33
  schemaVersion: 1,
35
34
  defaultModel: 'gpt-4o',
36
- toolConfirmation: 'allow',
37
35
  };
38
36
  const CONFIG_SCHEMA_VERSION = 1;
39
- /** Raised only by the strict Settings path; the legacy startup loader remains tolerant. */
37
+ /** Safe field/position diagnostics, never YAML source lines or configuration values. */
40
38
  class GlobalConfigDocumentValidationError extends Error {
41
- constructor(field) {
42
- super(`Invalid Orion configuration field: ${field}`);
39
+ constructor(field, configPath, yamlReason) {
40
+ super(`Invalid Orion configuration field: ${field}${configPath ? ` in ${configPath}` : ''}${yamlReason ? ` (${yamlReason})` : ''}`);
43
41
  this.field = field;
42
+ this.configPath = configPath;
43
+ this.yamlReason = yamlReason;
44
44
  this.name = 'GlobalConfigDocumentValidationError';
45
45
  }
46
46
  }
@@ -51,6 +51,36 @@ function isRecord(value) {
51
51
  function invalidField(field) {
52
52
  throw new GlobalConfigDocumentValidationError(field);
53
53
  }
54
+ function validateKnownKeys(record, keys, field = '') {
55
+ for (const key of Object.keys(record)) {
56
+ if (!keys.includes(key)) {
57
+ // Unknown keys can themselves contain secrets. Only display identifier-like names.
58
+ const safeKey = /^[A-Za-z_][A-Za-z0-9_-]{0,63}$/u.test(key) ? key : '$unknown';
59
+ invalidField(field ? `${field}.${safeKey}` : safeKey);
60
+ }
61
+ }
62
+ }
63
+ function validateDocumentTree(value, ancestors = new Set(), depth = 0, budget = { remaining: 20000 }) {
64
+ if (--budget.remaining < 0)
65
+ invalidField('$size');
66
+ if (depth > 100)
67
+ invalidField('$depth');
68
+ if (typeof value === 'number' && !Number.isFinite(value))
69
+ invalidField('$number');
70
+ if (value === null || typeof value !== 'object')
71
+ return;
72
+ if (ancestors.has(value))
73
+ invalidField('$cycle');
74
+ if (!Array.isArray(value) &&
75
+ Object.getPrototypeOf(value) !== Object.prototype &&
76
+ Object.getPrototypeOf(value) !== null) {
77
+ invalidField('$type');
78
+ }
79
+ ancestors.add(value);
80
+ for (const child of Object.values(value))
81
+ validateDocumentTree(child, ancestors, depth + 1, budget);
82
+ ancestors.delete(value);
83
+ }
54
84
  function validateOptionalString(record, key, field, allowEmpty = true) {
55
85
  const value = record[key];
56
86
  if (value === undefined)
@@ -81,6 +111,7 @@ function validateSandboxDocument(value, field) {
81
111
  return;
82
112
  if (!isRecord(value))
83
113
  invalidField(field);
114
+ validateKnownKeys(value, ['profile', 'backend', 'allowNetwork', 'writableRoots', 'image'], field);
84
115
  if (value.profile !== undefined &&
85
116
  value.profile !== 'none' &&
86
117
  value.profile !== 'read-only' &&
@@ -101,12 +132,9 @@ function validateSandboxDocument(value, field) {
101
132
  function validateProjectDocument(value) {
102
133
  if (!isRecord(value))
103
134
  invalidField('projects.*');
104
- validateOptionalStringArray(value, 'allowedTools', 'projects.*.allowedTools');
135
+ validateKnownKeys(value, ['compactInstructions', 'sandbox', 'defaultEffort'], 'projects.*');
105
136
  validateOptionalString(value, 'compactInstructions', 'projects.*.compactInstructions');
106
137
  validateSandboxDocument(value.sandbox, 'projects.*.sandbox');
107
- validateOptionalString(value, 'lastSessionId', 'projects.*.lastSessionId');
108
- validateOptionalString(value, 'lastModel', 'projects.*.lastModel');
109
- validateOptionalBoolean(value, 'hasTrustDialogAccepted', 'projects.*.hasTrustDialogAccepted');
110
138
  if (value.defaultEffort !== undefined && !(0, effort_1.isEffortPreference)(value.defaultEffort)) {
111
139
  invalidField('projects.*.defaultEffort');
112
140
  }
@@ -114,6 +142,7 @@ function validateProjectDocument(value) {
114
142
  function validatePricing(value, field) {
115
143
  if (!isRecord(value))
116
144
  invalidField(field);
145
+ validateKnownKeys(value, ['input', 'output', 'cachedInput'], field);
117
146
  for (const key of ['input', 'output']) {
118
147
  if (typeof value[key] !== 'number' || !Number.isFinite(value[key]) || value[key] < 0) {
119
148
  invalidField(`${field}.${key}`);
@@ -127,28 +156,33 @@ function validatePricing(value, field) {
127
156
  }
128
157
  }
129
158
  /**
130
- * Validate the complete known schema without normalizing or dropping unknown
131
- * fields. Settings mutations must call this before writing their raw clone.
159
+ * Validate the v0.4 schema without silently normalizing misspelled or retired fields.
132
160
  */
133
161
  function validateGlobalConfigDocumentStrict(value) {
134
162
  if (!isRecord(value))
135
163
  invalidField('$');
164
+ validateDocumentTree(value);
165
+ validateKnownKeys(value, [
166
+ 'schemaVersion',
167
+ 'providers',
168
+ 'models',
169
+ 'defaultModel',
170
+ 'fallbackModel',
171
+ 'defaultEffort',
172
+ 'webSearch',
173
+ 'ui',
174
+ 'skills',
175
+ 'agentLoop',
176
+ 'subagents',
177
+ 'cost',
178
+ 'sandbox',
179
+ 'projects',
180
+ ]);
136
181
  if (value.schemaVersion !== undefined && value.schemaVersion !== CONFIG_SCHEMA_VERSION) {
137
182
  invalidField('schemaVersion');
138
183
  }
139
- validateOptionalString(value, 'apiKey', 'apiKey');
140
- validateOptionalString(value, 'apiBaseUrl', 'apiBaseUrl');
141
184
  validateOptionalString(value, 'defaultModel', 'defaultModel', false);
142
185
  validateOptionalString(value, 'fallbackModel', 'fallbackModel', false);
143
- validateOptionalString(value, 'userId', 'userId', false);
144
- validateOptionalString(value, 'firstStartTime', 'firstStartTime', false);
145
- validateOptionalStringArray(value, 'allowedTools', 'allowedTools');
146
- if (value.toolConfirmation !== undefined &&
147
- value.toolConfirmation !== 'ask' &&
148
- value.toolConfirmation !== 'allow' &&
149
- value.toolConfirmation !== 'deny') {
150
- invalidField('toolConfirmation');
151
- }
152
186
  if (value.defaultEffort !== undefined && !(0, effort_1.isEffortPreference)(value.defaultEffort)) {
153
187
  invalidField('defaultEffort');
154
188
  }
@@ -159,36 +193,11 @@ function validateGlobalConfigDocumentStrict(value) {
159
193
  for (const project of Object.values(value.projects))
160
194
  validateProjectDocument(project);
161
195
  }
162
- if (value.web !== undefined) {
163
- if (!isRecord(value.web))
164
- invalidField('web');
165
- if (value.web.appearance !== undefined) {
166
- if (!isRecord(value.web.appearance))
167
- invalidField('web.appearance');
168
- const { style, theme, motion } = value.web.appearance;
169
- if (style !== undefined && style !== 'classic' && style !== 'orion-blocksmith') {
170
- invalidField('web.appearance.style');
171
- }
172
- if (theme !== undefined && theme !== 'system' && theme !== 'light' && theme !== 'dark') {
173
- invalidField('web.appearance.theme');
174
- }
175
- if (motion !== undefined && motion !== 'system' && motion !== 'reduced') {
176
- invalidField('web.appearance.motion');
177
- }
178
- }
179
- }
180
196
  if (value.ui !== undefined) {
181
197
  if (!isRecord(value.ui))
182
198
  invalidField('ui');
183
- const { renderer, confirmations, theme, motion } = value.ui;
184
- if (renderer !== undefined && renderer !== 'terminal' && renderer !== 'tui') {
185
- invalidField('ui.renderer');
186
- }
187
- if (confirmations !== undefined &&
188
- confirmations !== 'config' &&
189
- confirmations !== 'interactive') {
190
- invalidField('ui.confirmations');
191
- }
199
+ validateKnownKeys(value.ui, ['theme', 'motion', 'mascot', 'statusLine', 'keymap'], 'ui');
200
+ const { theme, motion } = value.ui;
192
201
  if (theme !== undefined && !TUI_THEME_PREFERENCES.has(theme)) {
193
202
  invalidField('ui.theme');
194
203
  }
@@ -197,12 +206,41 @@ function validateGlobalConfigDocumentStrict(value) {
197
206
  }
198
207
  validateOptionalBoolean(value.ui, 'mascot', 'ui.mascot');
199
208
  validateOptionalStringArray(value.ui, 'statusLine', 'ui.statusLine');
200
- if (value.ui.keymap !== undefined && !isRecord(value.ui.keymap))
201
- invalidField('ui.keymap');
209
+ if (Array.isArray(value.ui.statusLine) &&
210
+ !value.ui.statusLine.every(item => TUI_STATUS_ITEMS.has(item)))
211
+ invalidField('ui.statusLine');
212
+ if (value.ui.keymap !== undefined) {
213
+ if (!isRecord(value.ui.keymap))
214
+ invalidField('ui.keymap');
215
+ validateKnownKeys(value.ui.keymap, [...TUI_KEYMAP_ACTIONS], 'ui.keymap');
216
+ const claimedBindings = new Set();
217
+ for (const [action, bindings] of Object.entries(value.ui.keymap)) {
218
+ if (!Array.isArray(bindings) ||
219
+ !bindings.every(binding => typeof binding === 'string' && TUI_KEY_BINDINGS.has(binding.trim().toLowerCase())))
220
+ invalidField(`ui.keymap.${action}`);
221
+ for (const binding of bindings) {
222
+ const normalized = binding.trim().toLowerCase();
223
+ if (claimedBindings.has(normalized))
224
+ invalidField(`ui.keymap.${action}`);
225
+ claimedBindings.add(normalized);
226
+ }
227
+ }
228
+ }
202
229
  }
203
230
  if (value.webSearch !== undefined) {
204
231
  if (!isRecord(value.webSearch))
205
232
  invalidField('webSearch');
233
+ validateKnownKeys(value.webSearch, [
234
+ 'provider',
235
+ 'endpoint',
236
+ 'apiKey',
237
+ 'toolName',
238
+ 'timeoutMs',
239
+ 'authType',
240
+ 'apiKeyHeader',
241
+ 'apiKeyQueryParam',
242
+ 'headers',
243
+ ], 'webSearch');
206
244
  for (const key of [
207
245
  'provider',
208
246
  'endpoint',
@@ -228,27 +266,49 @@ function validateGlobalConfigDocumentStrict(value) {
228
266
  if (value.skills !== undefined) {
229
267
  if (!isRecord(value.skills))
230
268
  invalidField('skills');
269
+ validateKnownKeys(value.skills, ['paths'], 'skills');
231
270
  validateOptionalStringArray(value.skills, 'paths', 'skills.paths');
232
271
  }
233
272
  if (value.agentLoop !== undefined) {
234
273
  if (!isRecord(value.agentLoop))
235
274
  invalidField('agentLoop');
275
+ validateKnownKeys(value.agentLoop, ['budget', 'continuation', 'goalBudget'], 'agentLoop');
276
+ if (value.agentLoop.continuation !== undefined &&
277
+ value.agentLoop.continuation !== 'agent' &&
278
+ value.agentLoop.continuation !== 'manual') {
279
+ invalidField('agentLoop.continuation');
280
+ }
281
+ if (value.agentLoop.goalBudget !== undefined) {
282
+ if (!isRecord(value.agentLoop.goalBudget))
283
+ invalidField('agentLoop.goalBudget');
284
+ validateKnownKeys(value.agentLoop.goalBudget, ['maxTokens', 'maxElapsedMs'], 'agentLoop.goalBudget');
285
+ for (const key of ['maxTokens', 'maxElapsedMs']) {
286
+ validateOptionalPositiveInteger(value.agentLoop.goalBudget, key, `agentLoop.goalBudget.${key}`);
287
+ if (value.agentLoop.goalBudget[key] !== undefined &&
288
+ !Number.isSafeInteger(value.agentLoop.goalBudget[key]))
289
+ invalidField(`agentLoop.goalBudget.${key}`);
290
+ }
291
+ }
236
292
  if (value.agentLoop.budget !== undefined) {
237
293
  if (!isRecord(value.agentLoop.budget))
238
294
  invalidField('agentLoop.budget');
239
- for (const key of [
240
- 'maxLlmRequestsPerUserTurn',
241
- 'maxToolCallsPerUserTurn',
242
- 'maxReadOnlyFragmentation',
243
- 'maxModelVisibleToolBytes',
244
- ]) {
245
- validateOptionalPositiveInteger(value.agentLoop.budget, key, `agentLoop.budget.${key}`);
246
- }
295
+ validateKnownKeys(value.agentLoop.budget, ['maxModelVisibleToolBytes'], 'agentLoop.budget');
296
+ validateOptionalPositiveInteger(value.agentLoop.budget, 'maxModelVisibleToolBytes', 'agentLoop.budget.maxModelVisibleToolBytes');
247
297
  }
248
298
  }
249
299
  if (value.subagents !== undefined) {
250
300
  if (!isRecord(value.subagents))
251
301
  invalidField('subagents');
302
+ validateKnownKeys(value.subagents, [
303
+ 'mode',
304
+ 'maxParallel',
305
+ 'maxTasksPerTurn',
306
+ 'maxModelRequestsPerTask',
307
+ 'maxModelRequestsPerTurn',
308
+ 'maxToolCallsPerTask',
309
+ 'timeoutMs',
310
+ 'roles',
311
+ ], 'subagents');
252
312
  if (value.subagents.mode !== undefined &&
253
313
  value.subagents.mode !== 'off' &&
254
314
  value.subagents.mode !== 'explicit' &&
@@ -258,7 +318,6 @@ function validateGlobalConfigDocumentStrict(value) {
258
318
  for (const key of [
259
319
  'maxParallel',
260
320
  'maxTasksPerTurn',
261
- 'maxTurnsPerTask',
262
321
  'maxModelRequestsPerTask',
263
322
  'maxModelRequestsPerTurn',
264
323
  'maxToolCallsPerTask',
@@ -276,6 +335,7 @@ function validateGlobalConfigDocumentStrict(value) {
276
335
  if (value.cost !== undefined) {
277
336
  if (!isRecord(value.cost))
278
337
  invalidField('cost');
338
+ validateKnownKeys(value.cost, ['modelPricing', 'defaultPricing'], 'cost');
279
339
  if (value.cost.defaultPricing !== undefined) {
280
340
  validatePricing(value.cost.defaultPricing, 'cost.defaultPricing');
281
341
  }
@@ -296,6 +356,7 @@ function validateGlobalConfigDocumentStrict(value) {
296
356
  if (!Array.isArray(value.models) || !value.models.every(isRecord))
297
357
  invalidField('models');
298
358
  for (const provider of value.providers) {
359
+ validateKnownKeys(provider, ['id', 'baseUrl', 'apiKey', 'protocol', 'displayName'], 'providers.*');
299
360
  validateOptionalString(provider, 'id', 'providers.*.id', false);
300
361
  validateOptionalString(provider, 'baseUrl', 'providers.*.baseUrl', false);
301
362
  validateOptionalString(provider, 'apiKey', 'providers.*.apiKey', false);
@@ -305,12 +366,27 @@ function validateGlobalConfigDocumentStrict(value) {
305
366
  typeof provider.apiKey !== 'string') {
306
367
  invalidField('providers');
307
368
  }
308
- if (provider.protocol !== 'openai-completions' &&
309
- provider.protocol !== 'anthropic-messages') {
369
+ if (provider.protocol !== 'openai-completions') {
310
370
  invalidField('providers.*.protocol');
311
371
  }
312
372
  }
313
373
  for (const model of value.models) {
374
+ validateKnownKeys(model, [
375
+ 'id',
376
+ 'displayName',
377
+ 'provider',
378
+ 'model',
379
+ 'contextWindow',
380
+ 'maxOutputTokens',
381
+ 'aliases',
382
+ 'enabled',
383
+ 'reasoningEffort',
384
+ ], 'models.*');
385
+ if (model.reasoningEffort !== undefined) {
386
+ if (!isRecord(model.reasoningEffort))
387
+ invalidField('models.*.reasoningEffort');
388
+ validateKnownKeys(model.reasoningEffort, ['supportedLevels', 'defaultLevel'], 'models.*.reasoningEffort');
389
+ }
314
390
  validateOptionalString(model, 'id', 'models.*.id', false);
315
391
  validateOptionalString(model, 'displayName', 'models.*.displayName');
316
392
  validateOptionalString(model, 'provider', 'models.*.provider', false);
@@ -324,14 +400,6 @@ function validateGlobalConfigDocumentStrict(value) {
324
400
  validateOptionalPositiveInteger(model, 'maxOutputTokens', 'models.*.maxOutputTokens');
325
401
  validateOptionalStringArray(model, 'aliases', 'models.*.aliases');
326
402
  validateOptionalBoolean(model, 'enabled', 'models.*.enabled');
327
- validateOptionalBoolean(model, 'reasoning', 'models.*.reasoning');
328
- if (model.temperatureMode !== undefined &&
329
- model.temperatureMode !== 'supported' &&
330
- model.temperatureMode !== 'unsupported') {
331
- invalidField('models.*.temperatureMode');
332
- }
333
- if (model.cost !== undefined)
334
- validatePricing(model.cost, 'models.*.cost');
335
403
  }
336
404
  let validation;
337
405
  try {
@@ -344,17 +412,78 @@ function validateGlobalConfigDocumentStrict(value) {
344
412
  invalidField('providers/models');
345
413
  }
346
414
  }
415
+ /** Make retired turn counters inert while retaining supported settings and strict tree checks. */
416
+ function withoutRetiredAgentLoopSettings(document) {
417
+ if (!isRecord(document) || !isRecord(document.agentLoop))
418
+ return document;
419
+ validateDocumentTree(document);
420
+ const agentLoop = { ...document.agentLoop };
421
+ delete agentLoop.budgetPolicy;
422
+ if (isRecord(agentLoop.budget)) {
423
+ const budget = { ...agentLoop.budget };
424
+ delete budget.maxLlmRequestsPerUserTurn;
425
+ delete budget.maxToolCallsPerUserTurn;
426
+ delete budget.maxReadOnlyFragmentation;
427
+ if (Object.keys(budget).length > 0)
428
+ agentLoop.budget = budget;
429
+ else
430
+ delete agentLoop.budget;
431
+ }
432
+ const normalized = { ...document };
433
+ if (Object.keys(agentLoop).length > 0)
434
+ normalized.agentLoop = agentLoop;
435
+ else
436
+ delete normalized.agentLoop;
437
+ return normalized;
438
+ }
347
439
  /** Parse exact file bytes through the strict Settings validator. */
348
440
  function parseGlobalConfigDocumentStrict(content) {
441
+ const text = typeof content === 'string' ? content : content.toString('utf8');
349
442
  let parsed;
350
443
  try {
351
- parsed = JSON.parse(typeof content === 'string' ? content : content.toString('utf8'));
352
- }
353
- catch {
354
- invalidField('$json');
444
+ // CORE_SCHEMA keeps dates as strings and refuses executable/custom tags.
445
+ // The default duplicate-key rejection applies at every mapping depth.
446
+ parsed = (0, js_yaml_1.load)(text, { schema: js_yaml_1.CORE_SCHEMA });
447
+ }
448
+ catch (error) {
449
+ if (!(error instanceof js_yaml_1.YAMLException))
450
+ invalidField('$yaml');
451
+ // Some parser reasons interpolate raw tags or values. Expose only fixed diagnostics.
452
+ const safeReasons = new Set([
453
+ 'bad indentation of a mapping entry',
454
+ 'bad indentation of a sequence entry',
455
+ 'duplicated mapping key',
456
+ 'end of the stream or a document separator is expected',
457
+ 'missed comma between flow collection entries',
458
+ 'unexpected end of the stream within a flow collection',
459
+ 'unexpected end of the stream within a quoted scalar',
460
+ ]);
461
+ const reason = safeReasons.has(error.reason) ? error.reason : 'invalid YAML syntax';
462
+ throw new GlobalConfigDocumentValidationError(`yaml:${(error.mark?.line ?? 0) + 1}:${(error.mark?.column ?? 0) + 1}`, undefined, reason);
463
+ }
464
+ // A retired YAML pointer cannot select a session. Strip it before exposing
465
+ // the document to configuration editors, including their next save.
466
+ if (isRecord(parsed) && isRecord(parsed.projects)) {
467
+ parsed = {
468
+ ...parsed,
469
+ projects: Object.fromEntries(Object.entries(parsed.projects).map(([path, project]) => {
470
+ if (!isRecord(project))
471
+ return [path, project];
472
+ const settings = { ...project };
473
+ delete settings.lastSessionId;
474
+ return [path, settings];
475
+ })),
476
+ };
355
477
  }
356
- validateGlobalConfigDocumentStrict(parsed);
357
- return parsed;
478
+ const document = withoutRetiredAgentLoopSettings(parsed);
479
+ validateGlobalConfigDocumentStrict(document);
480
+ return document;
481
+ }
482
+ /** Canonical YAML write path. Comments are not retained after a settings mutation. */
483
+ function serializeGlobalConfigDocumentStrict(document) {
484
+ const normalized = withoutRetiredAgentLoopSettings(document);
485
+ validateGlobalConfigDocumentStrict(normalized);
486
+ return (0, js_yaml_1.dump)(normalized, { noRefs: true, lineWidth: -1, sortKeys: false });
358
487
  }
359
488
  const TUI_THEME_PREFERENCES = new Set([
360
489
  'orion-pixel',
@@ -369,7 +498,6 @@ const TUI_STATUS_ITEMS = new Set([
369
498
  'model',
370
499
  'effort',
371
500
  'context',
372
- 'permission',
373
501
  'queue',
374
502
  'activity',
375
503
  ]);
@@ -399,9 +527,6 @@ function sanitizeUiConfig(value) {
399
527
  return undefined;
400
528
  const raw = value;
401
529
  const ui = {};
402
- if (raw.confirmations === 'config' || raw.confirmations === 'interactive') {
403
- ui.confirmations = raw.confirmations;
404
- }
405
530
  if (typeof raw.theme === 'string' && TUI_THEME_PREFERENCES.has(raw.theme)) {
406
531
  ui.theme = raw.theme;
407
532
  }
@@ -437,35 +562,6 @@ function sanitizeUiConfig(value) {
437
562
  }
438
563
  return Object.keys(ui).length > 0 ? ui : undefined;
439
564
  }
440
- function sanitizeWebConfig(value) {
441
- if (!value || typeof value !== 'object' || Array.isArray(value))
442
- return undefined;
443
- const raw = value;
444
- // Preserve forward-compatible Web fields while sanitizing the owned subtree.
445
- const sanitized = { ...raw };
446
- if (raw.appearance && typeof raw.appearance === 'object' && !Array.isArray(raw.appearance)) {
447
- const appearance = { ...raw.appearance };
448
- if (appearance.style !== 'classic' && appearance.style !== 'orion-blocksmith') {
449
- delete appearance.style;
450
- }
451
- if (appearance.theme !== 'system' &&
452
- appearance.theme !== 'light' &&
453
- appearance.theme !== 'dark') {
454
- delete appearance.theme;
455
- }
456
- if (appearance.motion !== 'system' && appearance.motion !== 'reduced') {
457
- delete appearance.motion;
458
- }
459
- if (Object.keys(appearance).length > 0)
460
- sanitized.appearance = appearance;
461
- else
462
- delete sanitized.appearance;
463
- }
464
- else {
465
- delete sanitized.appearance;
466
- }
467
- return sanitized;
468
- }
469
565
  function sanitizeSandboxConfig(value) {
470
566
  if (!value || typeof value !== 'object' || Array.isArray(value))
471
567
  return undefined;
@@ -495,9 +591,6 @@ function sanitizeProjectConfig(value) {
495
591
  return {};
496
592
  const raw = value;
497
593
  const sanitized = {};
498
- if (Array.isArray(raw.allowedTools) && raw.allowedTools.every(item => typeof item === 'string')) {
499
- sanitized.allowedTools = [...raw.allowedTools];
500
- }
501
594
  if (typeof raw.compactInstructions === 'string') {
502
595
  const compactInstructions = raw.compactInstructions
503
596
  .replace(/\r\n?/gu, '\n')
@@ -509,30 +602,13 @@ function sanitizeProjectConfig(value) {
509
602
  const sandbox = sanitizeSandboxConfig(raw.sandbox);
510
603
  if (sandbox)
511
604
  sanitized.sandbox = sandbox;
512
- if (typeof raw.lastSessionId === 'string')
513
- sanitized.lastSessionId = raw.lastSessionId;
514
- if (typeof raw.lastModel === 'string')
515
- sanitized.lastModel = raw.lastModel;
516
- if (typeof raw.hasTrustDialogAccepted === 'boolean') {
517
- sanitized.hasTrustDialogAccepted = raw.hasTrustDialogAccepted;
518
- }
519
605
  if ((0, effort_1.isEffortPreference)(raw.defaultEffort))
520
606
  sanitized.defaultEffort = raw.defaultEffort;
521
607
  return sanitized;
522
608
  }
523
609
  function sanitizeGlobalConfig(config) {
524
- const { ui, web, totalSessions: _totalSessions, totalTokens: _totalTokens, totalCost: _totalCost, ...rest } = config;
525
- void _totalSessions;
526
- void _totalTokens;
527
- void _totalCost;
610
+ const { ui, ...rest } = config;
528
611
  const sanitized = { ...rest, schemaVersion: CONFIG_SCHEMA_VERSION };
529
- if (Array.isArray(rest.allowedTools) &&
530
- rest.allowedTools.every(item => typeof item === 'string')) {
531
- sanitized.allowedTools = [...new Set(rest.allowedTools)];
532
- }
533
- else {
534
- delete sanitized.allowedTools;
535
- }
536
612
  if (!(0, effort_1.isEffortPreference)(rest.defaultEffort))
537
613
  delete sanitized.defaultEffort;
538
614
  const sandbox = sanitizeSandboxConfig(rest.sandbox);
@@ -550,9 +626,6 @@ function sanitizeGlobalConfig(config) {
550
626
  const persistedUi = sanitizeUiConfig(ui);
551
627
  if (persistedUi)
552
628
  sanitized.ui = persistedUi;
553
- const persistedWeb = sanitizeWebConfig(web);
554
- if (persistedWeb)
555
- sanitized.web = persistedWeb;
556
629
  return sanitized;
557
630
  }
558
631
  // ============================================================================
@@ -570,11 +643,21 @@ function loadGlobalConfig() {
570
643
  }
571
644
  try {
572
645
  const content = (0, fs_1.readFileSync)(path, 'utf-8');
573
- const parsed = JSON.parse(content);
574
- return sanitizeGlobalConfig({ ...DEFAULT_CONFIG, ...parsed });
575
- }
576
- catch {
577
- return sanitizeGlobalConfig({ ...DEFAULT_CONFIG });
646
+ const parsed = parseGlobalConfigDocumentStrict(content);
647
+ const defaultModel = parsed.defaultModel === undefined && Array.isArray(parsed.models)
648
+ ? (0, model_registry_1.buildRegistry)(parsed).registry?.defaultProfile?.id
649
+ : undefined;
650
+ return sanitizeGlobalConfig({
651
+ ...DEFAULT_CONFIG,
652
+ ...(defaultModel ? { defaultModel } : {}),
653
+ ...parsed,
654
+ });
655
+ }
656
+ catch (error) {
657
+ if (error instanceof GlobalConfigDocumentValidationError) {
658
+ throw new GlobalConfigDocumentValidationError(error.field, path, error.yamlReason);
659
+ }
660
+ throw new GlobalConfigDocumentValidationError('$read', path);
578
661
  }
579
662
  }
580
663
  /**
@@ -583,15 +666,16 @@ function loadGlobalConfig() {
583
666
  function saveGlobalConfig(config) {
584
667
  (0, config_dir_1.ensureConfigDir)();
585
668
  const path = (0, config_dir_1.getGlobalConfigPath)();
586
- (0, file_lock_1.withFileLockSync)(path, () => saveGlobalConfigUnlocked(path, config), { waitMs: 10000 });
669
+ (0, file_lock_1.withFileLockSync)(path, () => {
670
+ if ((0, fs_1.existsSync)(path))
671
+ parseGlobalConfigDocumentStrict((0, fs_1.readFileSync)(path));
672
+ saveGlobalConfigUnlocked(path, config);
673
+ }, { waitMs: 10000 });
587
674
  }
588
675
  function saveGlobalConfigUnlocked(path, config) {
589
- // orion.json holds provider credentials; an interrupted in-place write makes
590
- // it unparseable and the loader falls back to defaults, wiping the config.
591
- (0, atomic_write_1.atomicWriteFileSync)(path, JSON.stringify(sanitizeGlobalConfig(config), null, 2), {
592
- mode: 0o600,
593
- fsync: true,
594
- });
676
+ const document = withoutRetiredAgentLoopSettings(config);
677
+ validateGlobalConfigDocumentStrict(document);
678
+ (0, atomic_write_1.atomicWriteFileSync)(path, serializeGlobalConfigDocumentStrict(sanitizeGlobalConfig(document)), { mode: 0o600, fsync: true });
595
679
  }
596
680
  /**
597
681
  * 更新全局配置(部分更新)
@@ -625,50 +709,6 @@ function saveProjectConfig(projectPath, projectConfig) {
625
709
  saveGlobalConfigUnlocked(path, config);
626
710
  }, { waitMs: 10000 });
627
711
  }
628
- // ============================================================================
629
- // 用户 ID
630
- // ============================================================================
631
- function getOrCreateUserId() {
632
- (0, config_dir_1.ensureConfigDir)();
633
- const path = (0, config_dir_1.getGlobalConfigPath)();
634
- return (0, file_lock_1.withFileLockSync)(path, () => {
635
- const config = loadGlobalConfig();
636
- if (config.userId)
637
- return config.userId;
638
- const userId = (0, crypto_1.randomBytes)(16).toString('hex');
639
- saveGlobalConfigUnlocked(path, { ...config, userId });
640
- return userId;
641
- }, { waitMs: 10000 });
642
- }
643
- function recordFirstStartTime() {
644
- (0, config_dir_1.ensureConfigDir)();
645
- const path = (0, config_dir_1.getGlobalConfigPath)();
646
- (0, file_lock_1.withFileLockSync)(path, () => {
647
- let document;
648
- if ((0, fs_1.existsSync)(path)) {
649
- try {
650
- document = parseGlobalConfigDocumentStrict((0, fs_1.readFileSync)(path));
651
- }
652
- catch {
653
- // Startup metadata is optional. Never let the tolerant compatibility
654
- // loader turn an invalid user document into defaults and overwrite it.
655
- return;
656
- }
657
- }
658
- else {
659
- document = { schemaVersion: CONFIG_SCHEMA_VERSION };
660
- }
661
- if (typeof document.firstStartTime === 'string' && document.firstStartTime.trim())
662
- return;
663
- const candidate = {
664
- ...document,
665
- schemaVersion: document.schemaVersion ?? CONFIG_SCHEMA_VERSION,
666
- firstStartTime: new Date().toISOString(),
667
- };
668
- validateGlobalConfigDocumentStrict(candidate);
669
- (0, atomic_write_1.atomicWriteFileSync)(path, JSON.stringify(candidate, null, 2), { mode: 0o600, fsync: true });
670
- }, { waitMs: 10000 });
671
- }
672
712
  var usage_state_1 = require("./usage-state");
673
713
  Object.defineProperty(exports, "incrementSessionCount", { enumerable: true, get: function () { return usage_state_1.incrementSessionCount; } });
674
714
  Object.defineProperty(exports, "updateTokenStats", { enumerable: true, get: function () { return usage_state_1.updateTokenStats; } });