@orion-agents/orion-code 0.3.66 → 0.4.3
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.
- package/CHANGELOG.md +81 -0
- package/README.md +78 -361
- package/README.zh-CN.md +71 -262
- package/bin/orion +4 -1
- package/dist/acp/session-updates.d.ts +34 -0
- package/dist/acp/session-updates.js +162 -0
- package/dist/acp/sessions.d.ts +32 -0
- package/dist/acp/sessions.js +315 -0
- package/dist/acp/stdio.d.ts +3 -0
- package/dist/acp/stdio.js +59 -0
- package/dist/cli.js +136 -185
- package/dist/commands/context-tool-command-handlers.d.ts +1 -1
- package/dist/commands/context-tool-command-handlers.js +24 -3
- package/dist/commands/core-command-handlers.js +5 -1
- package/dist/commands/diagnostic-command-handlers.js +20 -6
- package/dist/commands/diagnostic-commands.js +0 -12
- package/dist/commands/init-command.d.ts +3 -0
- package/dist/commands/init-command.js +131 -0
- package/dist/commands/model-command-handlers.d.ts +1 -2
- package/dist/commands/model-command-handlers.js +15 -100
- package/dist/commands/model-commands.js +0 -11
- package/dist/commands/registry.js +0 -18
- package/dist/commands/rsi-command.d.ts +2 -0
- package/dist/commands/rsi-command.js +180 -0
- package/dist/commands/session-command-handlers.js +28 -19
- package/dist/commands/system-commands.js +0 -1
- package/dist/commands/tool-commands.js +1 -1
- package/dist/commands/types.d.ts +4 -10
- package/dist/commands/types.js +1 -21
- package/dist/commands/workflow-command-handlers.js +13 -4
- package/dist/framework/loop-budget-contract.d.ts +7 -2
- package/dist/framework/loop-budget-contract.js +4 -1
- package/dist/framework/loop-progress.d.ts +22 -0
- package/dist/framework/loop-progress.js +79 -0
- package/dist/framework/prompt.d.ts +0 -2
- package/dist/framework/prompt.js +9 -27
- package/dist/framework/query.d.ts +27 -20
- package/dist/framework/query.js +453 -153
- package/dist/framework/store.d.ts +6 -10
- package/dist/framework/store.js +2 -21
- package/dist/framework/tool-call-orchestrator.d.ts +7 -0
- package/dist/framework/tool-call-orchestrator.js +8 -3
- package/dist/framework/tool-state.d.ts +2 -0
- package/dist/framework/tool.d.ts +0 -23
- package/dist/framework/verification-command.d.ts +15 -0
- package/dist/framework/verification-command.js +32 -0
- package/dist/harness/assembler.d.ts +1 -0
- package/dist/harness/assembler.js +24 -0
- package/dist/harness/capsule.d.ts +1 -1
- package/dist/harness/capsule.js +33 -14
- package/dist/harness/context-harness.d.ts +31 -12
- package/dist/harness/context-harness.js +491 -35
- package/dist/harness/contract.js +1 -1
- package/dist/harness/drift-guard.d.ts +4 -0
- package/dist/harness/drift-guard.js +68 -16
- package/dist/harness/intent.js +21 -0
- package/dist/harness/ledger.d.ts +6 -11
- package/dist/harness/ledger.js +39 -9
- package/dist/harness/progress-controller.d.ts +12 -7
- package/dist/harness/progress-controller.js +66 -21
- package/dist/harness/state.js +9 -1
- package/dist/harness/task-checklist.d.ts +16 -0
- package/dist/harness/task-checklist.js +95 -0
- package/dist/harness/types.d.ts +73 -1
- package/dist/harness/verification.d.ts +19 -1
- package/dist/harness/verification.js +116 -29
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -3
- package/dist/print-ui/event-stream.d.ts +38 -0
- package/dist/print-ui/event-stream.js +187 -0
- package/dist/print-ui/launch.d.ts +12 -1
- package/dist/print-ui/launch.js +173 -11
- package/dist/product/environment.d.ts +1 -1
- package/dist/product/environment.js +1 -1
- package/dist/product/identity.d.ts +1 -1
- package/dist/product/identity.js +1 -1
- package/dist/product/paths.d.ts +3 -2
- package/dist/product/paths.js +6 -2
- package/dist/runtime/agent-loop.d.ts +11 -2
- package/dist/runtime/agent-loop.js +165 -25
- package/dist/runtime/agent-runtime-controller.d.ts +13 -3
- package/dist/runtime/agent-runtime-controller.js +347 -183
- package/dist/runtime/agent-runtime-protocol.d.ts +10 -18
- package/dist/runtime/agent-runtime-runner.d.ts +10 -0
- package/dist/runtime/builtin-tool-provider.js +5 -1
- package/dist/runtime/capability-receipt-journal.js +1 -0
- package/dist/runtime/durable-tool-receipt-reader.js +2 -1
- package/dist/runtime/first-party-tool-services.d.ts +1 -0
- package/dist/runtime/first-party-tool-services.js +2 -12
- package/dist/runtime/first-party-tool-universe.d.ts +1 -0
- package/dist/runtime/first-party-tool-universe.js +1 -1
- package/dist/runtime/followup-queue-store.d.ts +16 -0
- package/dist/runtime/followup-queue-store.js +75 -0
- package/dist/runtime/goal-lifecycle-v2.d.ts +11 -1
- package/dist/runtime/goal-lifecycle-v2.js +85 -15
- package/dist/runtime/goal-runtime-coordinator.d.ts +10 -1
- package/dist/runtime/goal-runtime-coordinator.js +81 -24
- package/dist/runtime/loop-budget.js +7 -5
- package/dist/runtime/mcp/first-party-mcp-adapter.d.ts +2 -0
- package/dist/runtime/mcp/first-party-mcp-adapter.js +23 -19
- package/dist/runtime/model-coordinator.js +2 -5
- package/dist/runtime/orion-runtime-v1.d.ts +18 -2
- package/dist/runtime/orion-runtime-v1.js +135 -39
- package/dist/runtime/orion-session-runner.d.ts +7 -0
- package/dist/runtime/orion-session-runner.js +82 -0
- package/dist/runtime/plan-review.d.ts +1 -0
- package/dist/runtime/plan-review.js +8 -4
- package/dist/runtime/product-bootstrap.d.ts +6 -0
- package/dist/runtime/product-bootstrap.js +41 -51
- package/dist/runtime/product-orion-runtime.js +128 -52
- package/dist/runtime/release-receipts.d.ts +24 -133
- package/dist/runtime/release-receipts.js +129 -693
- package/dist/runtime/rich-text/layout.js +108 -65
- package/dist/runtime/rsi/contracts.d.ts +50 -0
- package/dist/runtime/rsi/contracts.js +17 -0
- package/dist/runtime/rsi/diagnosis.d.ts +46 -0
- package/dist/runtime/rsi/diagnosis.js +98 -0
- package/dist/runtime/rsi/evaluation-suite.d.ts +25 -0
- package/dist/runtime/rsi/evaluation-suite.js +141 -0
- package/dist/runtime/rsi/evaluation-worker.d.ts +19 -0
- package/dist/runtime/rsi/evaluation-worker.js +64 -0
- package/dist/runtime/rsi/evaluation.d.ts +49 -0
- package/dist/runtime/rsi/evaluation.js +351 -0
- package/dist/runtime/rsi/lifecycle.d.ts +54 -0
- package/dist/runtime/rsi/lifecycle.js +279 -0
- package/dist/runtime/rsi/proposal.d.ts +39 -0
- package/dist/runtime/rsi/proposal.js +312 -0
- package/dist/runtime/rsi/receipt.d.ts +28 -0
- package/dist/runtime/rsi/receipt.js +138 -0
- package/dist/runtime/rsi/skill-state.d.ts +7 -0
- package/dist/runtime/rsi/skill-state.js +50 -0
- package/dist/runtime/rsi/trajectory.d.ts +19 -0
- package/dist/runtime/rsi/trajectory.js +314 -0
- package/dist/runtime/rsi/triage.d.ts +274 -0
- package/dist/runtime/rsi/triage.js +58 -0
- package/dist/runtime/session-composer-control.d.ts +5 -24
- package/dist/runtime/session-composer-control.js +27 -189
- package/dist/runtime/step-snapshot.d.ts +1 -0
- package/dist/runtime/subagents/policy.js +0 -1
- package/dist/runtime/subagents/production.js +1 -1
- package/dist/runtime/subagents/runtime-integration.js +2 -4
- package/dist/runtime/subagents/types.d.ts +0 -5
- package/dist/runtime/subagents/types.js +0 -2
- package/dist/runtime/task-context-recovery.d.ts +55 -0
- package/dist/runtime/task-context-recovery.js +342 -0
- package/dist/runtime/task-context-service.d.ts +16 -10
- package/dist/runtime/task-context-service.js +35 -4
- package/dist/runtime/thread-admission.d.ts +1 -1
- package/dist/runtime/thread-admission.js +12 -6
- package/dist/runtime/thread-event-store.d.ts +2 -2
- package/dist/runtime/thread-event-store.js +7 -2
- package/dist/runtime/thread-projection.js +4 -2
- package/dist/runtime/thread-runtime.d.ts +7 -0
- package/dist/runtime/thread-runtime.js +43 -0
- package/dist/runtime/thread-session-index.d.ts +8 -0
- package/dist/runtime/thread-session-index.js +50 -1
- package/dist/runtime/thread-session-view.d.ts +2 -1
- package/dist/runtime/thread-session-view.js +4 -0
- package/dist/runtime/thread-tool-journal.d.ts +1 -0
- package/dist/runtime/thread-tool-journal.js +6 -2
- package/dist/runtime/thread-ui-adapter.d.ts +1 -0
- package/dist/runtime/thread-ui-adapter.js +88 -11
- package/dist/runtime/tool-gateway.d.ts +7 -0
- package/dist/runtime/tool-gateway.js +20 -0
- package/dist/runtime/tool-transcript-entry.d.ts +16 -0
- package/dist/runtime/tool-transcript-entry.js +73 -0
- package/dist/runtime/turn-commit.d.ts +4 -1
- package/dist/runtime/turn-commit.js +19 -15
- package/dist/runtime/ui-events.d.ts +12 -0
- package/dist/runtime/ui-view-model.d.ts +6 -5
- package/dist/runtime/ui-view-model.js +33 -19
- package/dist/runtime/workspace-runtime-kernel.js +0 -1
- package/dist/services/atomic-write.d.ts +2 -0
- package/dist/services/atomic-write.js +12 -1
- package/dist/services/code-review/format.d.ts +4 -1
- package/dist/services/code-review/format.js +5 -1
- package/dist/services/code-review/runner.d.ts +2 -2
- package/dist/services/code-review/runner.js +86 -64
- package/dist/services/code-review/snapshot.d.ts +9 -9
- package/dist/services/code-review/snapshot.js +182 -166
- package/dist/services/compact/auto-compact.d.ts +21 -6
- package/dist/services/compact/auto-compact.js +148 -22
- package/dist/services/compact/background-candidate.d.ts +33 -0
- package/dist/services/compact/background-candidate.js +184 -0
- package/dist/services/compact/compact.d.ts +4 -1
- package/dist/services/compact/compact.js +30 -3
- package/dist/services/compact/coordinator.d.ts +10 -4
- package/dist/services/compact/coordinator.js +17 -7
- package/dist/services/compact/summary-generator.d.ts +4 -2
- package/dist/services/compact/summary-generator.js +17 -3
- package/dist/services/config.d.ts +5 -5
- package/dist/services/config.js +30 -45
- package/dist/services/doctor.js +85 -13
- package/dist/services/effort.d.ts +5 -5
- package/dist/services/effort.js +5 -11
- package/dist/services/file-lock.d.ts +9 -3
- package/dist/services/file-lock.js +92 -26
- package/dist/services/global-config.d.ts +26 -56
- package/dist/services/global-config.js +213 -183
- package/dist/services/llm.d.ts +40 -4
- package/dist/services/llm.js +164 -45
- package/dist/services/model-client-pool.d.ts +15 -9
- package/dist/services/model-client-pool.js +62 -33
- package/dist/services/model-context.d.ts +2 -1
- package/dist/services/model-context.js +15 -9
- package/dist/services/model-registry.d.ts +4 -15
- package/dist/services/model-registry.js +32 -101
- package/dist/services/provider-diagnostics.d.ts +7 -0
- package/dist/services/provider-diagnostics.js +9 -10
- package/dist/services/provider-resilience/coordinator.d.ts +1 -1
- package/dist/services/provider-resilience/coordinator.js +10 -6
- package/dist/services/provider-resilience/request-gate.d.ts +3 -0
- package/dist/services/provider-resilience/request-gate.js +29 -18
- package/dist/services/provider-resilience/types.d.ts +2 -0
- package/dist/services/session-storage.d.ts +7 -10
- package/dist/services/session-storage.js +57 -30
- package/dist/services/settings-coordinator.d.ts +0 -6
- package/dist/services/settings-coordinator.js +19 -56
- package/dist/services/settings-document-repository.d.ts +3 -10
- package/dist/services/settings-document-repository.js +7 -85
- package/dist/services/usage-state.d.ts +3 -3
- package/dist/services/usage-state.js +11 -42
- package/dist/terminal-ui/answer-format.d.ts +14 -0
- package/dist/terminal-ui/answer-format.js +119 -0
- package/dist/terminal-ui/launch.d.ts +7 -6
- package/dist/terminal-ui/launch.js +160 -70
- package/dist/terminal-ui/output-queue.d.ts +2 -1
- package/dist/terminal-ui/output-queue.js +1 -1
- package/dist/terminal-ui/raw-editor.d.ts +2 -1
- package/dist/terminal-ui/raw-editor.js +56 -15
- package/dist/tools/core/edit-file.js +2 -0
- package/dist/tools/core/write-file.js +5 -0
- package/dist/tools/lsp.d.ts +16 -1
- package/dist/tools/lsp.js +60 -19
- package/dist/tools/sandbox.d.ts +1 -1
- package/dist/tools/sandbox.js +3 -16
- package/dist/tools/todo.d.ts +4 -2
- package/dist/tools/todo.js +76 -31
- package/dist/tui-core/input-parser.d.ts +1 -0
- package/dist/tui-core/input-parser.js +6 -0
- package/dist/tui-core/style.d.ts +1 -8
- package/dist/tui-core/style.js +3 -110
- package/dist/tui-ui/chrome-view-model.d.ts +1 -1
- package/dist/tui-ui/chrome-view-model.js +22 -27
- package/dist/tui-ui/launch.js +14 -14
- package/dist/tui-ui/layout.d.ts +5 -7
- package/dist/tui-ui/layout.js +129 -124
- package/dist/tui-ui/runner.d.ts +11 -12
- package/dist/tui-ui/runner.js +88 -67
- package/dist/tui-ui/state.d.ts +0 -11
- package/dist/tui-ui/state.js +22 -33
- package/dist/tui-ui/terminal-image.js +22 -4
- package/dist/tui-ui/transcript-inspector-layout.js +6 -3
- package/dist/tui-ui/transcript-inspector.d.ts +1 -0
- package/dist/tui-ui/transcript-inspector.js +7 -1
- package/dist/tui-ui/transcript-layout.js +42 -6
- package/dist/utils/terminal-text.d.ts +11 -0
- package/dist/utils/terminal-text.js +114 -0
- package/docs/cli-guide.md +562 -0
- package/docs/orion.example.yaml +42 -0
- package/docs/readme.md +12 -57
- package/npm-shrinkwrap.json +484 -1855
- package/package.json +13 -63
- package/dist/migration/command.d.ts +0 -9
- package/dist/migration/command.js +0 -100
- package/dist/migration/index.d.ts +0 -7
- package/dist/migration/index.js +0 -14
- package/dist/migration/migrate.d.ts +0 -19
- package/dist/migration/migrate.js +0 -406
- package/dist/migration/types.d.ts +0 -55
- package/dist/migration/types.js +0 -6
- package/dist/services/tool-allowlist.d.ts +0 -110
- package/dist/services/tool-allowlist.js +0 -299
- package/dist/services/yaml-config.d.ts +0 -57
- package/dist/services/yaml-config.js +0 -178
- package/dist/web/cli-options.d.ts +0 -17
- package/dist/web/cli-options.js +0 -51
- package/dist/web/code-review-run-service.d.ts +0 -68
- package/dist/web/code-review-run-service.js +0 -228
- package/dist/web/context-text.d.ts +0 -17
- package/dist/web/context-text.js +0 -40
- package/dist/web/errors.d.ts +0 -6
- package/dist/web/errors.js +0 -13
- package/dist/web/event-hub.d.ts +0 -45
- package/dist/web/event-hub.js +0 -370
- package/dist/web/file-read-service.d.ts +0 -101
- package/dist/web/file-read-service.js +0 -593
- package/dist/web/file-write-service.d.ts +0 -16
- package/dist/web/file-write-service.js +0 -103
- package/dist/web/git-compare-service.d.ts +0 -45
- package/dist/web/git-compare-service.js +0 -160
- package/dist/web/git-diff-document.d.ts +0 -102
- package/dist/web/git-diff-document.js +0 -258
- package/dist/web/git-file-source.d.ts +0 -25
- package/dist/web/git-file-source.js +0 -21
- package/dist/web/git-history-service.d.ts +0 -151
- package/dist/web/git-history-service.js +0 -619
- package/dist/web/git-index-transaction.d.ts +0 -45
- package/dist/web/git-index-transaction.js +0 -174
- package/dist/web/git-patch-builder.d.ts +0 -30
- package/dist/web/git-patch-builder.js +0 -138
- package/dist/web/git-read-model-service.d.ts +0 -452
- package/dist/web/git-read-model-service.js +0 -1833
- package/dist/web/git-version-service.d.ts +0 -79
- package/dist/web/git-version-service.js +0 -279
- package/dist/web/host-daemon.d.ts +0 -70
- package/dist/web/host-daemon.js +0 -237
- package/dist/web/index.d.ts +0 -6
- package/dist/web/index.js +0 -28
- package/dist/web/launch.d.ts +0 -12
- package/dist/web/launch.js +0 -89
- package/dist/web/native-directory-picker.d.ts +0 -63
- package/dist/web/native-directory-picker.js +0 -169
- package/dist/web/protocol.d.ts +0 -705
- package/dist/web/protocol.js +0 -639
- package/dist/web/review-service.d.ts +0 -22
- package/dist/web/review-service.js +0 -68
- package/dist/web/server.d.ts +0 -20
- package/dist/web/server.js +0 -1453
- package/dist/web/session-runtime-registry.d.ts +0 -138
- package/dist/web/session-runtime-registry.js +0 -471
- package/dist/web/terminal-manager.d.ts +0 -156
- package/dist/web/terminal-manager.js +0 -779
- package/dist/web/terminal-server.d.ts +0 -8
- package/dist/web/terminal-server.js +0 -304
- package/dist/web/workbench-controller.d.ts +0 -395
- package/dist/web/workbench-controller.js +0 -3077
- package/dist/web/workspace-discovery.d.ts +0 -92
- package/dist/web/workspace-discovery.js +0 -324
- package/dist/web/workspace-mutation-arbiter.d.ts +0 -54
- package/dist/web/workspace-mutation-arbiter.js +0 -267
- package/dist/web/workspace-open-telemetry.d.ts +0 -55
- package/dist/web/workspace-open-telemetry.js +0 -73
- package/dist/web-client/assets/FilesPanel-CPDovK_K.js +0 -1
- package/dist/web-client/assets/GitPanel-DtU_TD61.js +0 -4
- package/dist/web-client/assets/ReviewPanel-vMO7BEA3.js +0 -6
- package/dist/web-client/assets/TerminalPanel-C9vDTAlS.js +0 -23
- package/dist/web-client/assets/TerminalPanel-DLuoa74B.css +0 -1
- package/dist/web-client/assets/index-CABdwh4l.css +0 -1
- package/dist/web-client/assets/index-KvshfEbl.js +0 -20
- package/dist/web-client/assets/useAutoNotice-IE1g2wcb.js +0 -1
- package/dist/web-client/favicon.svg +0 -9
- package/dist/web-client/index.html +0 -17
- package/docs/architecture/agent-mode-permission-contract.md +0 -87
- package/docs/architecture/v0.3.0-web-api.yaml +0 -1340
- package/docs/architecture/v0.3.1-web-api.yaml +0 -2338
- package/docs/architecture/v0.3.2-web-api.yaml +0 -3029
- package/docs/architecture/v0.3.3-web-api.yaml +0 -3205
- package/docs/architecture/v0.3.4-stabilization-contract.md +0 -32
- package/docs/migration/v0.1.9-to-v0.2.0.md +0 -98
- package/docs/migration/v0.2.2-to-v0.3.0-settings.md +0 -114
- package/docs/migration/v0.2.2-to-v0.3.0.md +0 -55
- package/docs/migration/v0.3.0-to-v0.3.1.md +0 -88
- package/docs/migration/v0.3.1-to-v0.3.2.md +0 -94
- package/docs/migration/v0.3.2-to-v0.3.3.md +0 -62
- package/docs/migration/v0.3.3-to-v0.3.4.md +0 -36
- package/docs/orion.example.json +0 -86
- package/docs/plan/v0.2.0-dsh-harness-redesign-plan.md +0 -1234
- package/docs/plan/v0.2.0-release-checklist.md +0 -91
- package/docs/plan/v0.3.0-node-runtime-compatibility-plan.md +0 -57
- package/docs/plan/v0.3.0-settings-integration-plan.md +0 -740
- package/docs/plan/v0.3.0-web-workbench-plan.md +0 -376
- package/docs/plan/v0.3.1-web-workbench-professional-shell-plan.md +0 -848
- package/docs/plan/v0.3.2-web-workbench-layout-and-composer-plan.md +0 -869
- package/docs/plan/v0.3.3-plan.md +0 -1113
- package/docs/plan/v0.3.4-stabilization-plan.md +0 -89
- package/docs/test/v0.3.1-web-workbench-e2e-plan.md +0 -140
- package/docs/test/v0.3.2-web-workbench-e2e-plan.md +0 -100
- package/docs/test/v0.3.3-web-workbench-e2e-plan.md +0 -79
- 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.
|
|
6
|
-
*
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
184
|
-
|
|
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 (
|
|
201
|
-
|
|
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,14 +266,43 @@ 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, ['budgetPolicy', 'budget', 'continuation', 'goalBudget'], 'agentLoop');
|
|
276
|
+
if (value.agentLoop.budgetPolicy !== undefined &&
|
|
277
|
+
value.agentLoop.budgetPolicy !== 'adaptive' &&
|
|
278
|
+
value.agentLoop.budgetPolicy !== 'fixed') {
|
|
279
|
+
invalidField('agentLoop.budgetPolicy');
|
|
280
|
+
}
|
|
281
|
+
if (value.agentLoop.continuation !== undefined &&
|
|
282
|
+
value.agentLoop.continuation !== 'agent' &&
|
|
283
|
+
value.agentLoop.continuation !== 'manual') {
|
|
284
|
+
invalidField('agentLoop.continuation');
|
|
285
|
+
}
|
|
286
|
+
if (value.agentLoop.goalBudget !== undefined) {
|
|
287
|
+
if (!isRecord(value.agentLoop.goalBudget))
|
|
288
|
+
invalidField('agentLoop.goalBudget');
|
|
289
|
+
validateKnownKeys(value.agentLoop.goalBudget, ['maxTokens', 'maxElapsedMs'], 'agentLoop.goalBudget');
|
|
290
|
+
for (const key of ['maxTokens', 'maxElapsedMs']) {
|
|
291
|
+
validateOptionalPositiveInteger(value.agentLoop.goalBudget, key, `agentLoop.goalBudget.${key}`);
|
|
292
|
+
if (value.agentLoop.goalBudget[key] !== undefined &&
|
|
293
|
+
!Number.isSafeInteger(value.agentLoop.goalBudget[key]))
|
|
294
|
+
invalidField(`agentLoop.goalBudget.${key}`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
236
297
|
if (value.agentLoop.budget !== undefined) {
|
|
237
298
|
if (!isRecord(value.agentLoop.budget))
|
|
238
299
|
invalidField('agentLoop.budget');
|
|
300
|
+
validateKnownKeys(value.agentLoop.budget, [
|
|
301
|
+
'maxLlmRequestsPerUserTurn',
|
|
302
|
+
'maxToolCallsPerUserTurn',
|
|
303
|
+
'maxReadOnlyFragmentation',
|
|
304
|
+
'maxModelVisibleToolBytes',
|
|
305
|
+
], 'agentLoop.budget');
|
|
239
306
|
for (const key of [
|
|
240
307
|
'maxLlmRequestsPerUserTurn',
|
|
241
308
|
'maxToolCallsPerUserTurn',
|
|
@@ -249,6 +316,16 @@ function validateGlobalConfigDocumentStrict(value) {
|
|
|
249
316
|
if (value.subagents !== undefined) {
|
|
250
317
|
if (!isRecord(value.subagents))
|
|
251
318
|
invalidField('subagents');
|
|
319
|
+
validateKnownKeys(value.subagents, [
|
|
320
|
+
'mode',
|
|
321
|
+
'maxParallel',
|
|
322
|
+
'maxTasksPerTurn',
|
|
323
|
+
'maxModelRequestsPerTask',
|
|
324
|
+
'maxModelRequestsPerTurn',
|
|
325
|
+
'maxToolCallsPerTask',
|
|
326
|
+
'timeoutMs',
|
|
327
|
+
'roles',
|
|
328
|
+
], 'subagents');
|
|
252
329
|
if (value.subagents.mode !== undefined &&
|
|
253
330
|
value.subagents.mode !== 'off' &&
|
|
254
331
|
value.subagents.mode !== 'explicit' &&
|
|
@@ -258,7 +335,6 @@ function validateGlobalConfigDocumentStrict(value) {
|
|
|
258
335
|
for (const key of [
|
|
259
336
|
'maxParallel',
|
|
260
337
|
'maxTasksPerTurn',
|
|
261
|
-
'maxTurnsPerTask',
|
|
262
338
|
'maxModelRequestsPerTask',
|
|
263
339
|
'maxModelRequestsPerTurn',
|
|
264
340
|
'maxToolCallsPerTask',
|
|
@@ -276,6 +352,7 @@ function validateGlobalConfigDocumentStrict(value) {
|
|
|
276
352
|
if (value.cost !== undefined) {
|
|
277
353
|
if (!isRecord(value.cost))
|
|
278
354
|
invalidField('cost');
|
|
355
|
+
validateKnownKeys(value.cost, ['modelPricing', 'defaultPricing'], 'cost');
|
|
279
356
|
if (value.cost.defaultPricing !== undefined) {
|
|
280
357
|
validatePricing(value.cost.defaultPricing, 'cost.defaultPricing');
|
|
281
358
|
}
|
|
@@ -296,6 +373,7 @@ function validateGlobalConfigDocumentStrict(value) {
|
|
|
296
373
|
if (!Array.isArray(value.models) || !value.models.every(isRecord))
|
|
297
374
|
invalidField('models');
|
|
298
375
|
for (const provider of value.providers) {
|
|
376
|
+
validateKnownKeys(provider, ['id', 'baseUrl', 'apiKey', 'protocol', 'displayName'], 'providers.*');
|
|
299
377
|
validateOptionalString(provider, 'id', 'providers.*.id', false);
|
|
300
378
|
validateOptionalString(provider, 'baseUrl', 'providers.*.baseUrl', false);
|
|
301
379
|
validateOptionalString(provider, 'apiKey', 'providers.*.apiKey', false);
|
|
@@ -305,12 +383,27 @@ function validateGlobalConfigDocumentStrict(value) {
|
|
|
305
383
|
typeof provider.apiKey !== 'string') {
|
|
306
384
|
invalidField('providers');
|
|
307
385
|
}
|
|
308
|
-
if (provider.protocol !== 'openai-completions'
|
|
309
|
-
provider.protocol !== 'anthropic-messages') {
|
|
386
|
+
if (provider.protocol !== 'openai-completions') {
|
|
310
387
|
invalidField('providers.*.protocol');
|
|
311
388
|
}
|
|
312
389
|
}
|
|
313
390
|
for (const model of value.models) {
|
|
391
|
+
validateKnownKeys(model, [
|
|
392
|
+
'id',
|
|
393
|
+
'displayName',
|
|
394
|
+
'provider',
|
|
395
|
+
'model',
|
|
396
|
+
'contextWindow',
|
|
397
|
+
'maxOutputTokens',
|
|
398
|
+
'aliases',
|
|
399
|
+
'enabled',
|
|
400
|
+
'reasoningEffort',
|
|
401
|
+
], 'models.*');
|
|
402
|
+
if (model.reasoningEffort !== undefined) {
|
|
403
|
+
if (!isRecord(model.reasoningEffort))
|
|
404
|
+
invalidField('models.*.reasoningEffort');
|
|
405
|
+
validateKnownKeys(model.reasoningEffort, ['supportedLevels', 'defaultLevel'], 'models.*.reasoningEffort');
|
|
406
|
+
}
|
|
314
407
|
validateOptionalString(model, 'id', 'models.*.id', false);
|
|
315
408
|
validateOptionalString(model, 'displayName', 'models.*.displayName');
|
|
316
409
|
validateOptionalString(model, 'provider', 'models.*.provider', false);
|
|
@@ -324,14 +417,6 @@ function validateGlobalConfigDocumentStrict(value) {
|
|
|
324
417
|
validateOptionalPositiveInteger(model, 'maxOutputTokens', 'models.*.maxOutputTokens');
|
|
325
418
|
validateOptionalStringArray(model, 'aliases', 'models.*.aliases');
|
|
326
419
|
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
420
|
}
|
|
336
421
|
let validation;
|
|
337
422
|
try {
|
|
@@ -346,16 +431,51 @@ function validateGlobalConfigDocumentStrict(value) {
|
|
|
346
431
|
}
|
|
347
432
|
/** Parse exact file bytes through the strict Settings validator. */
|
|
348
433
|
function parseGlobalConfigDocumentStrict(content) {
|
|
434
|
+
const text = typeof content === 'string' ? content : content.toString('utf8');
|
|
349
435
|
let parsed;
|
|
350
436
|
try {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
437
|
+
// CORE_SCHEMA keeps dates as strings and refuses executable/custom tags.
|
|
438
|
+
// The default duplicate-key rejection applies at every mapping depth.
|
|
439
|
+
parsed = (0, js_yaml_1.load)(text, { schema: js_yaml_1.CORE_SCHEMA });
|
|
440
|
+
}
|
|
441
|
+
catch (error) {
|
|
442
|
+
if (!(error instanceof js_yaml_1.YAMLException))
|
|
443
|
+
invalidField('$yaml');
|
|
444
|
+
// Some parser reasons interpolate raw tags or values. Expose only fixed diagnostics.
|
|
445
|
+
const safeReasons = new Set([
|
|
446
|
+
'bad indentation of a mapping entry',
|
|
447
|
+
'bad indentation of a sequence entry',
|
|
448
|
+
'duplicated mapping key',
|
|
449
|
+
'end of the stream or a document separator is expected',
|
|
450
|
+
'missed comma between flow collection entries',
|
|
451
|
+
'unexpected end of the stream within a flow collection',
|
|
452
|
+
'unexpected end of the stream within a quoted scalar',
|
|
453
|
+
]);
|
|
454
|
+
const reason = safeReasons.has(error.reason) ? error.reason : 'invalid YAML syntax';
|
|
455
|
+
throw new GlobalConfigDocumentValidationError(`yaml:${(error.mark?.line ?? 0) + 1}:${(error.mark?.column ?? 0) + 1}`, undefined, reason);
|
|
456
|
+
}
|
|
457
|
+
// A retired YAML pointer cannot select a session. Strip it before exposing
|
|
458
|
+
// the document to configuration editors, including their next save.
|
|
459
|
+
if (isRecord(parsed) && isRecord(parsed.projects)) {
|
|
460
|
+
parsed = {
|
|
461
|
+
...parsed,
|
|
462
|
+
projects: Object.fromEntries(Object.entries(parsed.projects).map(([path, project]) => {
|
|
463
|
+
if (!isRecord(project))
|
|
464
|
+
return [path, project];
|
|
465
|
+
const settings = { ...project };
|
|
466
|
+
delete settings.lastSessionId;
|
|
467
|
+
return [path, settings];
|
|
468
|
+
})),
|
|
469
|
+
};
|
|
355
470
|
}
|
|
356
471
|
validateGlobalConfigDocumentStrict(parsed);
|
|
357
472
|
return parsed;
|
|
358
473
|
}
|
|
474
|
+
/** Canonical YAML write path. Comments are not retained after a settings mutation. */
|
|
475
|
+
function serializeGlobalConfigDocumentStrict(document) {
|
|
476
|
+
validateGlobalConfigDocumentStrict(document);
|
|
477
|
+
return (0, js_yaml_1.dump)(document, { noRefs: true, lineWidth: -1, sortKeys: false });
|
|
478
|
+
}
|
|
359
479
|
const TUI_THEME_PREFERENCES = new Set([
|
|
360
480
|
'orion-pixel',
|
|
361
481
|
'classic',
|
|
@@ -369,7 +489,6 @@ const TUI_STATUS_ITEMS = new Set([
|
|
|
369
489
|
'model',
|
|
370
490
|
'effort',
|
|
371
491
|
'context',
|
|
372
|
-
'permission',
|
|
373
492
|
'queue',
|
|
374
493
|
'activity',
|
|
375
494
|
]);
|
|
@@ -399,9 +518,6 @@ function sanitizeUiConfig(value) {
|
|
|
399
518
|
return undefined;
|
|
400
519
|
const raw = value;
|
|
401
520
|
const ui = {};
|
|
402
|
-
if (raw.confirmations === 'config' || raw.confirmations === 'interactive') {
|
|
403
|
-
ui.confirmations = raw.confirmations;
|
|
404
|
-
}
|
|
405
521
|
if (typeof raw.theme === 'string' && TUI_THEME_PREFERENCES.has(raw.theme)) {
|
|
406
522
|
ui.theme = raw.theme;
|
|
407
523
|
}
|
|
@@ -437,35 +553,6 @@ function sanitizeUiConfig(value) {
|
|
|
437
553
|
}
|
|
438
554
|
return Object.keys(ui).length > 0 ? ui : undefined;
|
|
439
555
|
}
|
|
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
556
|
function sanitizeSandboxConfig(value) {
|
|
470
557
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
471
558
|
return undefined;
|
|
@@ -495,9 +582,6 @@ function sanitizeProjectConfig(value) {
|
|
|
495
582
|
return {};
|
|
496
583
|
const raw = value;
|
|
497
584
|
const sanitized = {};
|
|
498
|
-
if (Array.isArray(raw.allowedTools) && raw.allowedTools.every(item => typeof item === 'string')) {
|
|
499
|
-
sanitized.allowedTools = [...raw.allowedTools];
|
|
500
|
-
}
|
|
501
585
|
if (typeof raw.compactInstructions === 'string') {
|
|
502
586
|
const compactInstructions = raw.compactInstructions
|
|
503
587
|
.replace(/\r\n?/gu, '\n')
|
|
@@ -509,30 +593,13 @@ function sanitizeProjectConfig(value) {
|
|
|
509
593
|
const sandbox = sanitizeSandboxConfig(raw.sandbox);
|
|
510
594
|
if (sandbox)
|
|
511
595
|
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
596
|
if ((0, effort_1.isEffortPreference)(raw.defaultEffort))
|
|
520
597
|
sanitized.defaultEffort = raw.defaultEffort;
|
|
521
598
|
return sanitized;
|
|
522
599
|
}
|
|
523
600
|
function sanitizeGlobalConfig(config) {
|
|
524
|
-
const { ui,
|
|
525
|
-
void _totalSessions;
|
|
526
|
-
void _totalTokens;
|
|
527
|
-
void _totalCost;
|
|
601
|
+
const { ui, ...rest } = config;
|
|
528
602
|
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
603
|
if (!(0, effort_1.isEffortPreference)(rest.defaultEffort))
|
|
537
604
|
delete sanitized.defaultEffort;
|
|
538
605
|
const sandbox = sanitizeSandboxConfig(rest.sandbox);
|
|
@@ -550,9 +617,6 @@ function sanitizeGlobalConfig(config) {
|
|
|
550
617
|
const persistedUi = sanitizeUiConfig(ui);
|
|
551
618
|
if (persistedUi)
|
|
552
619
|
sanitized.ui = persistedUi;
|
|
553
|
-
const persistedWeb = sanitizeWebConfig(web);
|
|
554
|
-
if (persistedWeb)
|
|
555
|
-
sanitized.web = persistedWeb;
|
|
556
620
|
return sanitized;
|
|
557
621
|
}
|
|
558
622
|
// ============================================================================
|
|
@@ -570,11 +634,21 @@ function loadGlobalConfig() {
|
|
|
570
634
|
}
|
|
571
635
|
try {
|
|
572
636
|
const content = (0, fs_1.readFileSync)(path, 'utf-8');
|
|
573
|
-
const parsed =
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
return sanitizeGlobalConfig({
|
|
637
|
+
const parsed = parseGlobalConfigDocumentStrict(content);
|
|
638
|
+
const defaultModel = parsed.defaultModel === undefined && Array.isArray(parsed.models)
|
|
639
|
+
? (0, model_registry_1.buildRegistry)(parsed).registry?.defaultProfile?.id
|
|
640
|
+
: undefined;
|
|
641
|
+
return sanitizeGlobalConfig({
|
|
642
|
+
...DEFAULT_CONFIG,
|
|
643
|
+
...(defaultModel ? { defaultModel } : {}),
|
|
644
|
+
...parsed,
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
catch (error) {
|
|
648
|
+
if (error instanceof GlobalConfigDocumentValidationError) {
|
|
649
|
+
throw new GlobalConfigDocumentValidationError(error.field, path, error.yamlReason);
|
|
650
|
+
}
|
|
651
|
+
throw new GlobalConfigDocumentValidationError('$read', path);
|
|
578
652
|
}
|
|
579
653
|
}
|
|
580
654
|
/**
|
|
@@ -583,15 +657,15 @@ function loadGlobalConfig() {
|
|
|
583
657
|
function saveGlobalConfig(config) {
|
|
584
658
|
(0, config_dir_1.ensureConfigDir)();
|
|
585
659
|
const path = (0, config_dir_1.getGlobalConfigPath)();
|
|
586
|
-
(0, file_lock_1.withFileLockSync)(path, () =>
|
|
660
|
+
(0, file_lock_1.withFileLockSync)(path, () => {
|
|
661
|
+
if ((0, fs_1.existsSync)(path))
|
|
662
|
+
parseGlobalConfigDocumentStrict((0, fs_1.readFileSync)(path));
|
|
663
|
+
saveGlobalConfigUnlocked(path, config);
|
|
664
|
+
}, { waitMs: 10000 });
|
|
587
665
|
}
|
|
588
666
|
function saveGlobalConfigUnlocked(path, config) {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
(0, atomic_write_1.atomicWriteFileSync)(path, JSON.stringify(sanitizeGlobalConfig(config), null, 2), {
|
|
592
|
-
mode: 0o600,
|
|
593
|
-
fsync: true,
|
|
594
|
-
});
|
|
667
|
+
validateGlobalConfigDocumentStrict(config);
|
|
668
|
+
(0, atomic_write_1.atomicWriteFileSync)(path, serializeGlobalConfigDocumentStrict(sanitizeGlobalConfig(config)), { mode: 0o600, fsync: true });
|
|
595
669
|
}
|
|
596
670
|
/**
|
|
597
671
|
* 更新全局配置(部分更新)
|
|
@@ -625,50 +699,6 @@ function saveProjectConfig(projectPath, projectConfig) {
|
|
|
625
699
|
saveGlobalConfigUnlocked(path, config);
|
|
626
700
|
}, { waitMs: 10000 });
|
|
627
701
|
}
|
|
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
702
|
var usage_state_1 = require("./usage-state");
|
|
673
703
|
Object.defineProperty(exports, "incrementSessionCount", { enumerable: true, get: function () { return usage_state_1.incrementSessionCount; } });
|
|
674
704
|
Object.defineProperty(exports, "updateTokenStats", { enumerable: true, get: function () { return usage_state_1.updateTokenStats; } });
|