@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.
- package/CHANGELOG.md +87 -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 +35 -0
- package/dist/acp/session-updates.js +183 -0
- package/dist/acp/sessions.d.ts +32 -0
- package/dist/acp/sessions.js +328 -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 +10 -18
- package/dist/commands/diagnostic-command-handlers.js +58 -48
- 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 +1 -19
- 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/target-command.js +49 -6
- 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/commands/workflow-commands.js +2 -2
- package/dist/framework/loop-budget-contract.d.ts +2 -8
- package/dist/framework/loop-budget-contract.js +0 -3
- package/dist/framework/loop-progress.d.ts +18 -0
- package/dist/framework/loop-progress.js +63 -0
- package/dist/framework/prompt.d.ts +0 -2
- package/dist/framework/prompt.js +9 -27
- package/dist/framework/query.d.ts +26 -31
- package/dist/framework/query.js +451 -292
- 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 +37 -12
- package/dist/harness/context-harness.js +545 -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/index.d.ts +1 -1
- package/dist/harness/intent.js +21 -0
- package/dist/harness/ledger.d.ts +7 -11
- package/dist/harness/ledger.js +50 -9
- package/dist/harness/progress-controller.d.ts +12 -7
- package/dist/harness/progress-controller.js +96 -29
- package/dist/harness/state.js +10 -1
- package/dist/harness/stop-controller.d.ts +0 -5
- package/dist/harness/stop-controller.js +11 -31
- package/dist/harness/task-checklist.d.ts +16 -0
- package/dist/harness/task-checklist.js +92 -0
- package/dist/harness/types.d.ts +78 -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 +43 -0
- package/dist/print-ui/event-stream.js +204 -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 +12 -2
- package/dist/runtime/agent-loop.js +172 -29
- package/dist/runtime/agent-runtime-controller.d.ts +14 -4
- package/dist/runtime/agent-runtime-controller.js +366 -192
- 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 +16 -4
- package/dist/runtime/goal-lifecycle-v2.js +217 -39
- package/dist/runtime/goal-runtime-coordinator.d.ts +14 -2
- package/dist/runtime/goal-runtime-coordinator.js +147 -36
- package/dist/runtime/goals/presentation.js +3 -1
- package/dist/runtime/goals/types.d.ts +1 -3
- package/dist/runtime/goals/types.js +0 -3
- package/dist/runtime/loop-budget.d.ts +0 -7
- package/dist/runtime/loop-budget.js +8 -52
- 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 +183 -46
- 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 +129 -58
- 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 +345 -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 +4 -1
- package/dist/runtime/step-snapshot.js +11 -1
- package/dist/runtime/subagent-thread-runtime.js +27 -5
- package/dist/runtime/subagents/policy.js +0 -1
- package/dist/runtime/subagents/production.js +1 -5
- 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 +349 -0
- package/dist/runtime/task-context-service.d.ts +20 -10
- package/dist/runtime/task-context-service.js +69 -9
- package/dist/runtime/thread-admission.d.ts +3 -1
- package/dist/runtime/thread-admission.js +21 -7
- 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 +10 -0
- package/dist/runtime/thread-runtime.js +85 -3
- 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 +89 -22
- package/dist/runtime/tool-gateway.d.ts +9 -0
- package/dist/runtime/tool-gateway.js +24 -0
- package/dist/runtime/tool-receipt-validator.js +4 -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 +15 -1
- package/dist/runtime/ui-view-model.d.ts +6 -5
- package/dist/runtime/ui-view-model.js +78 -61
- package/dist/runtime/workspace-runtime-kernel.js +0 -1
- package/dist/runtime/workspace-verification.d.ts +7 -0
- package/dist/runtime/workspace-verification.js +83 -0
- 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 +29 -48
- 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 -64
- package/dist/services/global-config.js +233 -193
- package/dist/services/llm.d.ts +42 -4
- package/dist/services/llm.js +177 -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 +8 -0
- package/dist/services/provider-diagnostics.js +17 -12
- 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 +6 -2
- package/dist/tools/core/write-file.js +9 -2
- 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 +91 -30
- 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 +36 -32
- 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 +575 -0
- package/docs/orion.example.yaml +43 -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,8 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OrionRuntimeV1 = exports.OrionRuntimeV1Error = void 0;
|
|
4
4
|
exports.createOrionRuntimeV1 = createOrionRuntimeV1;
|
|
5
|
+
const fs_1 = require("fs");
|
|
5
6
|
const path_1 = require("path");
|
|
7
|
+
const paths_1 = require("../product/paths");
|
|
8
|
+
const task_checklist_1 = require("../harness/task-checklist");
|
|
9
|
+
const file_lock_1 = require("../services/file-lock");
|
|
6
10
|
const agent_loop_1 = require("./agent-loop");
|
|
11
|
+
const builtin_tool_provider_1 = require("./builtin-tool-provider");
|
|
12
|
+
const todo_1 = require("../tools/todo");
|
|
7
13
|
const batch_read_service_1 = require("./batch-read-service");
|
|
8
14
|
const capability_receipt_journal_1 = require("./capability-receipt-journal");
|
|
9
15
|
const capability_step_factory_1 = require("./capability-step-factory");
|
|
@@ -12,6 +18,7 @@ const goal_runtime_coordinator_1 = require("./goal-runtime-coordinator");
|
|
|
12
18
|
const mcp_1 = require("./mcp");
|
|
13
19
|
const prompts_1 = require("./prompts");
|
|
14
20
|
const canonical_1 = require("./protocol/canonical");
|
|
21
|
+
const task_context_recovery_1 = require("./task-context-recovery");
|
|
15
22
|
const harness_metrics_1 = require("./harness-metrics");
|
|
16
23
|
const resource_scope_1 = require("./resource-scope");
|
|
17
24
|
const runtime_services_1 = require("./runtime-services");
|
|
@@ -22,6 +29,7 @@ const task_context_service_1 = require("./task-context-service");
|
|
|
22
29
|
const thread_event_store_1 = require("./thread-event-store");
|
|
23
30
|
const thread_runtime_1 = require("./thread-runtime");
|
|
24
31
|
const thread_tool_journal_1 = require("./thread-tool-journal");
|
|
32
|
+
const workspace_verification_1 = require("./workspace-verification");
|
|
25
33
|
const tool_gateway_1 = require("./tool-gateway");
|
|
26
34
|
const turn_commit_1 = require("./turn-commit");
|
|
27
35
|
class OrionRuntimeV1Error extends Error {
|
|
@@ -48,7 +56,6 @@ const SERVICE_IDS = Object.freeze({
|
|
|
48
56
|
compaction: 'compact-transaction-v1',
|
|
49
57
|
});
|
|
50
58
|
/** Process-local guard; it is an ownership check, never a service lookup path. */
|
|
51
|
-
const ACTIVE_RUNTIME_OWNERS = new Map();
|
|
52
59
|
/**
|
|
53
60
|
* Explicit first-party production composition root for exactly one ThreadRuntime.
|
|
54
61
|
* Construction is side-effect free; start() owns resources and close() releases them.
|
|
@@ -58,7 +65,6 @@ class OrionRuntimeV1 {
|
|
|
58
65
|
this.stateValue = 'created';
|
|
59
66
|
this.closeRequested = false;
|
|
60
67
|
this.options = validateOptions(options);
|
|
61
|
-
this.ownerKey = ownerKey(this.options.eventStore);
|
|
62
68
|
this.scope = new resource_scope_1.ResourceScope({ deadlineMs: options.closeDeadlineMs });
|
|
63
69
|
}
|
|
64
70
|
get state() {
|
|
@@ -240,14 +246,26 @@ class OrionRuntimeV1 {
|
|
|
240
246
|
if (!Number.isSafeInteger(maxMessages) || maxMessages <= 0) {
|
|
241
247
|
throw new OrionRuntimeV1Error('ORION_RUNTIME_INVALID_CONFIGURATION', 'Explicit compact maxMessages must be a positive integer.');
|
|
242
248
|
}
|
|
249
|
+
const budget = input.modelSwitchBudget;
|
|
250
|
+
if (budget &&
|
|
251
|
+
(!Number.isSafeInteger(budget.safeInputBudget) ||
|
|
252
|
+
budget.safeInputBudget <= 0 ||
|
|
253
|
+
!Number.isSafeInteger(budget.targetTokens) ||
|
|
254
|
+
budget.targetTokens <= 0 ||
|
|
255
|
+
budget.targetTokens > budget.safeInputBudget)) {
|
|
256
|
+
throw new OrionRuntimeV1Error('ORION_RUNTIME_INVALID_CONFIGURATION', 'Model-switch compact requires a positive target within its safe input budget.');
|
|
257
|
+
}
|
|
243
258
|
const request = Object.freeze({
|
|
244
259
|
type: 'compact',
|
|
245
260
|
source: 'explicit',
|
|
246
261
|
prepare: async ({ source, history, }, signal) => {
|
|
247
262
|
throwIfAborted(signal);
|
|
248
263
|
const messages = parseModelVisibleHistory(history);
|
|
249
|
-
const result = await coordinator.compactManual(messages, maxMessages, input.focus);
|
|
264
|
+
const result = await coordinator.compactManual(messages, maxMessages, input.focus, budget, signal);
|
|
250
265
|
throwIfAborted(signal);
|
|
266
|
+
if (budget && result.afterTokens > budget.targetTokens) {
|
|
267
|
+
throw new Error(`Compact candidate uses ${result.afterTokens} tokens; target is ${budget.targetTokens}.`);
|
|
268
|
+
}
|
|
251
269
|
return (0, thread_compact_persistence_1.createThreadCompactCandidateDraftV1)({
|
|
252
270
|
source: 'explicit',
|
|
253
271
|
sourceHistoryDigest: source.historyDigest,
|
|
@@ -292,15 +310,50 @@ class OrionRuntimeV1 {
|
|
|
292
310
|
}
|
|
293
311
|
async performStart() {
|
|
294
312
|
try {
|
|
295
|
-
this.acquireOwnership();
|
|
296
313
|
const eventStore = this.options.eventStore.store ??
|
|
297
314
|
new thread_event_store_1.ThreadEventStore(this.options.eventStore.rootDir, this.options.eventStore.threadId, this.options.eventStore.options);
|
|
315
|
+
this.acquireOwnership(eventStore);
|
|
298
316
|
const compactPersistence = new thread_compact_persistence_1.ThreadCompactTransactionPersistenceV1(eventStore);
|
|
299
317
|
const compactRunner = new thread_compact_persistence_1.ThreadCompactMaintenanceRunnerV1(eventStore, this.options.compact);
|
|
300
318
|
const compactRecovery = await compactRunner.recoverOrphans();
|
|
301
|
-
const
|
|
302
|
-
const
|
|
319
|
+
const startupProjection = eventStore.loadProjection();
|
|
320
|
+
const orphan = startupProjection.activeTurnId
|
|
321
|
+
? startupProjection.turns[startupProjection.activeTurnId]
|
|
322
|
+
: undefined;
|
|
323
|
+
const previousCommit = restoreLatestTurnCommit(eventStore);
|
|
324
|
+
const captureWorkspace = () => (0, workspace_verification_1.captureVerificationWorkspace)(this.options.taskContext.cwd, [
|
|
325
|
+
(0, paths_1.getConfigDir)(),
|
|
326
|
+
this.options.eventStore.rootDir,
|
|
327
|
+
]);
|
|
328
|
+
const taskOptions = {
|
|
329
|
+
...mergeTaskContextOptions(this.options.taskContext, previousCommit),
|
|
330
|
+
captureVerificationWorkspace: captureWorkspace,
|
|
331
|
+
};
|
|
332
|
+
const recovered = (0, task_context_recovery_1.recoverInterruptedTaskContext)({
|
|
333
|
+
store: eventStore,
|
|
334
|
+
previousCommit,
|
|
335
|
+
taskOptions,
|
|
336
|
+
loadImportedHistory: this.options.loadImportedHistory,
|
|
337
|
+
restoreGoalState: () => {
|
|
338
|
+
if (orphan?.mode === 'goal')
|
|
339
|
+
return (0, goal_runtime_coordinator_1.recoverInterruptedGoalState)(previousCommit);
|
|
340
|
+
const saved = (0, goal_runtime_coordinator_1.readGoalRuntimePersistenceV2)(previousCommit);
|
|
341
|
+
return saved.state ?? saved.tombstone;
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
const restored = recovered ?? previousCommit;
|
|
345
|
+
const taskContext = (0, task_context_service_1.createTaskContextService)({
|
|
346
|
+
...taskOptions,
|
|
347
|
+
...(recovered
|
|
348
|
+
? {
|
|
349
|
+
state: parseTaskContextState(recovered),
|
|
350
|
+
revision: recovered.taskContextRevision,
|
|
351
|
+
}
|
|
352
|
+
: {}),
|
|
353
|
+
requireLocalVerificationReceipt: true,
|
|
354
|
+
});
|
|
303
355
|
const goal = new goal_runtime_coordinator_1.GoalRuntimeCoordinatorV2({
|
|
356
|
+
...this.options.goalPolicy,
|
|
304
357
|
...(this.options.goal ? { definition: this.options.goal } : {}),
|
|
305
358
|
...(restored ? { restoredCommit: restored } : {}),
|
|
306
359
|
});
|
|
@@ -326,7 +379,15 @@ class OrionRuntimeV1 {
|
|
|
326
379
|
};
|
|
327
380
|
},
|
|
328
381
|
});
|
|
382
|
+
const todoCatalog = this.options.enableTaskTodos
|
|
383
|
+
? (0, builtin_tool_provider_1.createBuiltinToolCatalogV1)([
|
|
384
|
+
(0, todo_1.createTodoWriteTool)((todos, blockedReason) => taskContext.updateTaskTodos(todos, blockedReason)),
|
|
385
|
+
], { context: this.options.toolContext })
|
|
386
|
+
: undefined;
|
|
329
387
|
const basePolicy = new first_party_tool_services_1.FirstPartyToolPolicyServiceV1(this.options.toolCatalog, this.options.toolContext);
|
|
388
|
+
const todoPolicy = todoCatalog
|
|
389
|
+
? new first_party_tool_services_1.FirstPartyToolPolicyServiceV1(todoCatalog, this.options.toolContext)
|
|
390
|
+
: undefined;
|
|
330
391
|
const subagentTurns = new Map();
|
|
331
392
|
const subagentTurnFlights = new Map();
|
|
332
393
|
const subagentUnavailableTurns = new Set();
|
|
@@ -335,6 +396,8 @@ class OrionRuntimeV1 {
|
|
|
335
396
|
const policy = Object.freeze({
|
|
336
397
|
serviceId: 'turn-routed-first-party-tool-policy-v1',
|
|
337
398
|
decide: (input) => {
|
|
399
|
+
if (todoPolicy && input.descriptor.name === 'todo_write')
|
|
400
|
+
return todoPolicy.decide(input);
|
|
338
401
|
if (input.descriptor.name === 'subtask') {
|
|
339
402
|
const turnPolicy = subagentPolicies.get(input.snapshot.turnId);
|
|
340
403
|
if (!turnPolicy) {
|
|
@@ -356,7 +419,7 @@ class OrionRuntimeV1 {
|
|
|
356
419
|
});
|
|
357
420
|
const approval = new first_party_tool_services_1.FirstPartyToolApprovalServiceV1(this.options.approvalHandler);
|
|
358
421
|
const sandbox = new first_party_tool_services_1.FirstPartySandboxServiceV1();
|
|
359
|
-
const execution = new step_snapshot_1.ExecutionService(this.options.workspaceMutationCoordinator);
|
|
422
|
+
const execution = new step_snapshot_1.ExecutionService(this.options.workspaceMutationCoordinator, captureWorkspace);
|
|
360
423
|
const toolJournal = new thread_tool_journal_1.ThreadToolInvocationJournalV1(eventStore);
|
|
361
424
|
const gateway = new tool_gateway_1.ToolGateway({
|
|
362
425
|
policy,
|
|
@@ -433,7 +496,7 @@ class OrionRuntimeV1 {
|
|
|
433
496
|
prompts,
|
|
434
497
|
}));
|
|
435
498
|
const subagentTurn = await resolveSubagentTurn(input, configured.compiler.authority);
|
|
436
|
-
const dynamic = mergeDynamicTools(configured.dynamicTools, subagentTurn?.catalog);
|
|
499
|
+
const dynamic = mergeDynamicTools(mergeDynamicTools(configured.dynamicTools, subagentTurn?.catalog), (0, task_checklist_1.supportsExecutionChecklist)(input.mode) ? todoCatalog : undefined);
|
|
437
500
|
const registry = new Map(this.options.toolCatalog.bindings);
|
|
438
501
|
for (const [bindingId, binding] of dynamic?.bindings ?? []) {
|
|
439
502
|
if (registry.has(bindingId)) {
|
|
@@ -468,11 +531,16 @@ class OrionRuntimeV1 {
|
|
|
468
531
|
},
|
|
469
532
|
});
|
|
470
533
|
const turnCommits = new turn_commit_1.ThreadTurnCommitJournalV1(eventStore);
|
|
534
|
+
let activeTurnContext;
|
|
535
|
+
const loopOptions = this.options.loop;
|
|
471
536
|
const agentLoop = new agent_loop_1.AgentLoopV1({
|
|
472
537
|
llm: this.options.modelExecutor,
|
|
473
538
|
taskContext,
|
|
474
539
|
steps: stepFactory,
|
|
475
540
|
gateway,
|
|
541
|
+
previousCommitDigest: () => latestTurnCommitProjection(eventStore)?.digest,
|
|
542
|
+
enableTaskTodos: this.options.enableTaskTodos,
|
|
543
|
+
resolveGoalTask: () => goal.state,
|
|
476
544
|
loadBaseMessages: context => loadRuntimeBaseMessages(compactPersistence, this.options.loadBaseMessages?.(eventStore, context, prompts, {
|
|
477
545
|
taskContext,
|
|
478
546
|
goal,
|
|
@@ -481,7 +549,25 @@ class OrionRuntimeV1 {
|
|
|
481
549
|
})),
|
|
482
550
|
toolContext: () => this.options.toolContext,
|
|
483
551
|
streamCallbacks: this.options.loop?.streamCallbacks,
|
|
484
|
-
loopBudget
|
|
552
|
+
get loopBudget() {
|
|
553
|
+
return activeTurnContext && loopOptions?.resolveLoopBudget
|
|
554
|
+
? loopOptions.resolveLoopBudget(activeTurnContext, goal)
|
|
555
|
+
: loopOptions?.loopBudget;
|
|
556
|
+
},
|
|
557
|
+
get remainingGoalTokens() {
|
|
558
|
+
const state = goal.state;
|
|
559
|
+
return activeTurnContext?.mode === 'goal' &&
|
|
560
|
+
state?.status === 'active' &&
|
|
561
|
+
state.budget.maxTokens !== undefined
|
|
562
|
+
? Math.max(0, state.budget.maxTokens - state.tokensUsed)
|
|
563
|
+
: undefined;
|
|
564
|
+
},
|
|
565
|
+
get goalDeadlineAt() {
|
|
566
|
+
return activeTurnContext?.mode === 'goal'
|
|
567
|
+
? goal.deadlineAt(activeTurnContext.turnId)
|
|
568
|
+
: undefined;
|
|
569
|
+
},
|
|
570
|
+
allowToolPressureCompaction: true,
|
|
485
571
|
onContextUsage: this.options.loop?.onContextUsage,
|
|
486
572
|
compactCoordinator: this.options.loop?.compactCoordinator,
|
|
487
573
|
commitTurn: commit => {
|
|
@@ -491,18 +577,27 @@ class OrionRuntimeV1 {
|
|
|
491
577
|
: commit;
|
|
492
578
|
let durableCommit;
|
|
493
579
|
goal.commitTurn(committed, fields => {
|
|
580
|
+
if (activeTurnContext &&
|
|
581
|
+
fields.stopDecision &&
|
|
582
|
+
/^(goal_checkpoint|goal_manual_continuation)/u.test(fields.stopDecision.reason.code)) {
|
|
583
|
+
const checkpoint = activeTurnContext.startItem({ kind: 'reasoning' });
|
|
584
|
+
activeTurnContext.completeItem(checkpoint, {
|
|
585
|
+
content: fields.stopDecision.reason.message,
|
|
586
|
+
summary: fields.stopDecision.reason.message,
|
|
587
|
+
});
|
|
588
|
+
}
|
|
494
589
|
durableCommit = turnCommits.commit({
|
|
495
590
|
turnId: committed.turnId,
|
|
496
591
|
history: committed.history,
|
|
497
592
|
taskContextState: committed.taskContextState,
|
|
498
593
|
taskContextRevision: committed.taskContextRevision,
|
|
499
|
-
terminal: terminalFromAgentCommit(committed.queryComplete),
|
|
594
|
+
terminal: terminalFromAgentCommit(committed.queryComplete, activeTurnContext?.mode !== 'goal'),
|
|
500
595
|
...(fields.goalState ? { goalState: fields.goalState } : {}),
|
|
501
596
|
...(fields.stopDecision ? { stopDecision: fields.stopDecision } : {}),
|
|
502
597
|
...(prepared?.plan ? { plan: prepared.plan } : {}),
|
|
503
598
|
});
|
|
504
599
|
return durableCommit;
|
|
505
|
-
});
|
|
600
|
+
}, activeTurnContext?.mode === 'goal');
|
|
506
601
|
if (!durableCommit) {
|
|
507
602
|
throw new OrionRuntimeV1Error('ORION_RUNTIME_INVALID_CONFIGURATION', `Turn ${commit.turnId} completed without an authoritative TurnCommit.`);
|
|
508
603
|
}
|
|
@@ -524,14 +619,25 @@ class OrionRuntimeV1 {
|
|
|
524
619
|
const runtime = new thread_runtime_1.ThreadRuntimeV1({
|
|
525
620
|
...this.options.thread,
|
|
526
621
|
store: eventStore,
|
|
527
|
-
runner:
|
|
622
|
+
runner: {
|
|
623
|
+
run: async (context) => {
|
|
624
|
+
activeTurnContext = context;
|
|
625
|
+
try {
|
|
626
|
+
const goalId = context.mode === 'goal' ? goal.state?.goalId : undefined;
|
|
627
|
+
if (goalId) {
|
|
628
|
+
restoreGoalTaskCheckpoint(eventStore, taskContext, goalId);
|
|
629
|
+
goal.markTurnStarted(context.turnId, undefined, taskContext.exportState().ledger.map(entry => entry.id));
|
|
630
|
+
}
|
|
631
|
+
return await agentLoop.run(context);
|
|
632
|
+
}
|
|
633
|
+
finally {
|
|
634
|
+
activeTurnContext = undefined;
|
|
635
|
+
}
|
|
636
|
+
},
|
|
637
|
+
},
|
|
528
638
|
maintenanceRunner: compactRunner,
|
|
529
639
|
projectPath: this.options.projectPath,
|
|
530
640
|
requireTurnCommit: true,
|
|
531
|
-
onTurnStarted: turn => {
|
|
532
|
-
goal.markTurnStarted(turn.turnId, turn.startedAt);
|
|
533
|
-
this.options.thread?.onTurnStarted?.(turn);
|
|
534
|
-
},
|
|
535
641
|
onTurnDurablyTerminal: terminal => goal.afterDurableTerminal(terminal.turnId, terminal.terminal) ??
|
|
536
642
|
this.options.thread?.onTurnDurablyTerminal?.(terminal),
|
|
537
643
|
onTurnSettled: async (turnId) => {
|
|
@@ -554,6 +660,7 @@ class OrionRuntimeV1 {
|
|
|
554
660
|
}
|
|
555
661
|
},
|
|
556
662
|
});
|
|
663
|
+
this.writerThread = runtime;
|
|
557
664
|
return {
|
|
558
665
|
value: runtime,
|
|
559
666
|
dispose: async (context) => {
|
|
@@ -617,8 +724,11 @@ class OrionRuntimeV1 {
|
|
|
617
724
|
? eventStore.loadProjection().turns[restored.turnId]
|
|
618
725
|
: undefined;
|
|
619
726
|
if (!this.closeRequested &&
|
|
620
|
-
|
|
621
|
-
|
|
727
|
+
!(orphan?.mode === 'goal' && !orphan.commit) &&
|
|
728
|
+
restoredTurn?.status === restored?.terminal &&
|
|
729
|
+
restoredTurn !== undefined &&
|
|
730
|
+
!thread.getAdmissionSnapshot().activeTurn &&
|
|
731
|
+
thread.getAdmissionSnapshot().queue.length === 0) {
|
|
622
732
|
const continuation = goal.takeRestoredContinuation();
|
|
623
733
|
if (continuation)
|
|
624
734
|
thread.startGoalContinuation(continuation);
|
|
@@ -650,22 +760,35 @@ class OrionRuntimeV1 {
|
|
|
650
760
|
// Failed start already rolled back the same ResourceScope.
|
|
651
761
|
}
|
|
652
762
|
}
|
|
763
|
+
this.options.loop?.compactCoordinator?.cancelBackground('runtime_closed');
|
|
653
764
|
const report = await this.scope.close({ reason });
|
|
654
765
|
this.releaseOwnership();
|
|
655
766
|
this.stateValue = 'closed';
|
|
656
767
|
return report;
|
|
657
768
|
}
|
|
658
|
-
acquireOwnership() {
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
769
|
+
acquireOwnership(store) {
|
|
770
|
+
(0, fs_1.mkdirSync)(store.rootDir, { recursive: true, mode: 0o700 });
|
|
771
|
+
try {
|
|
772
|
+
this.releaseWriter = (0, file_lock_1.acquireFileLockSync)(`${store.logPath}.runtime-owner`, { waitMs: 0 });
|
|
773
|
+
}
|
|
774
|
+
catch (error) {
|
|
775
|
+
if (!(error instanceof file_lock_1.FileLockBusyError))
|
|
776
|
+
throw error;
|
|
777
|
+
throw new OrionRuntimeV1Error('ORION_RUNTIME_OWNER_CONFLICT', `Thread ${store.threadId} already has an active OrionRuntime owner.`);
|
|
662
778
|
}
|
|
663
|
-
ACTIVE_RUNTIME_OWNERS.set(this.ownerKey, this);
|
|
664
779
|
}
|
|
665
780
|
releaseOwnership() {
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
781
|
+
const release = this.releaseWriter;
|
|
782
|
+
if (!release)
|
|
783
|
+
return;
|
|
784
|
+
this.releaseWriter = undefined;
|
|
785
|
+
// The scope's teardown deadline may expire before an aborted tool drains.
|
|
786
|
+
// Keep its write lease until there is no active turn left to publish.
|
|
787
|
+
if (this.writerThread)
|
|
788
|
+
void this.writerThread.waitForIdle().then(release);
|
|
789
|
+
else
|
|
790
|
+
release();
|
|
791
|
+
this.writerThread = undefined;
|
|
669
792
|
}
|
|
670
793
|
requireGraph() {
|
|
671
794
|
if (!this.graphValue || this.stateValue !== 'started') {
|
|
@@ -678,25 +801,25 @@ exports.OrionRuntimeV1 = OrionRuntimeV1;
|
|
|
678
801
|
function createOrionRuntimeV1(options) {
|
|
679
802
|
return new OrionRuntimeV1(options);
|
|
680
803
|
}
|
|
681
|
-
function mergeDynamicTools(configured,
|
|
682
|
-
if (!
|
|
804
|
+
function mergeDynamicTools(configured, additionalCatalog) {
|
|
805
|
+
if (!additionalCatalog)
|
|
683
806
|
return configured;
|
|
684
807
|
const candidates = [...(configured?.candidates ?? [])];
|
|
685
808
|
const bindings = new Map(configured?.bindings ?? []);
|
|
686
809
|
const candidateNames = new Set(candidates.map(candidate => candidate.descriptor.name));
|
|
687
810
|
const candidateBindingIds = new Set(candidates.map(candidate => candidate.bindingId));
|
|
688
|
-
for (const candidate of
|
|
811
|
+
for (const candidate of additionalCatalog.candidates) {
|
|
689
812
|
if (candidateNames.has(candidate.descriptor.name)) {
|
|
690
|
-
invalidConfiguration(`
|
|
813
|
+
invalidConfiguration(`Duplicate dynamic tool ${candidate.descriptor.name}.`);
|
|
691
814
|
}
|
|
692
815
|
if (candidateBindingIds.has(candidate.bindingId) || bindings.has(candidate.bindingId)) {
|
|
693
|
-
invalidConfiguration(`
|
|
816
|
+
invalidConfiguration(`Duplicate dynamic binding ${candidate.bindingId}.`);
|
|
694
817
|
}
|
|
695
818
|
candidates.push(candidate);
|
|
696
819
|
candidateNames.add(candidate.descriptor.name);
|
|
697
820
|
candidateBindingIds.add(candidate.bindingId);
|
|
698
821
|
}
|
|
699
|
-
for (const [bindingId, binding] of
|
|
822
|
+
for (const [bindingId, binding] of additionalCatalog.bindings) {
|
|
700
823
|
if (bindings.has(bindingId)) {
|
|
701
824
|
invalidConfiguration(`Turn subagent binding collides with dynamic binding ${bindingId}.`);
|
|
702
825
|
}
|
|
@@ -836,9 +959,6 @@ function validateOptions(options) {
|
|
|
836
959
|
projectPath: (0, path_1.resolve)(options.projectPath),
|
|
837
960
|
});
|
|
838
961
|
}
|
|
839
|
-
function ownerKey(roots) {
|
|
840
|
-
return `${(0, path_1.resolve)(roots.rootDir)}\u0000${roots.threadId}`;
|
|
841
|
-
}
|
|
842
962
|
function goalControlInput(control) {
|
|
843
963
|
return `goal-control:${control.action}:${(0, canonical_1.digestRuntimeValue)(control)}`;
|
|
844
964
|
}
|
|
@@ -873,11 +993,16 @@ function mergeTaskContextOptions(configured, restored) {
|
|
|
873
993
|
};
|
|
874
994
|
}
|
|
875
995
|
function restoreLatestTurnCommit(store) {
|
|
876
|
-
const
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
996
|
+
const commit = latestTurnCommitProjection(store);
|
|
997
|
+
return commit ? (0, turn_commit_1.parseTurnCommitV1)(commit.receipt) : undefined;
|
|
998
|
+
}
|
|
999
|
+
function latestTurnCommitProjection(store) {
|
|
1000
|
+
let latest;
|
|
1001
|
+
for (const { commit } of Object.values(store.loadProjection().turns)) {
|
|
1002
|
+
if (commit && (!latest || commit.seq > latest.seq))
|
|
1003
|
+
latest = commit;
|
|
1004
|
+
}
|
|
1005
|
+
return latest;
|
|
881
1006
|
}
|
|
882
1007
|
function parseTaskContextState(commit) {
|
|
883
1008
|
try {
|
|
@@ -887,6 +1012,21 @@ function parseTaskContextState(commit) {
|
|
|
887
1012
|
invalidConfiguration('Durable TurnCommit TaskContext is not valid JSON.');
|
|
888
1013
|
}
|
|
889
1014
|
}
|
|
1015
|
+
function restoreGoalTaskCheckpoint(store, taskContext, goalId) {
|
|
1016
|
+
if (taskContext.exportState().goalTaskId === goalId)
|
|
1017
|
+
return;
|
|
1018
|
+
const goalCommits = Object.values(store.loadProjection().turns)
|
|
1019
|
+
.flatMap(turn => (turn.mode === 'goal' && turn.commit ? [turn.commit] : []))
|
|
1020
|
+
.sort((left, right) => right.seq - left.seq);
|
|
1021
|
+
for (const saved of goalCommits) {
|
|
1022
|
+
const commit = (0, turn_commit_1.parseTurnCommitV1)(saved.receipt);
|
|
1023
|
+
const state = parseTaskContextState(commit);
|
|
1024
|
+
if (state.goalTaskId !== goalId)
|
|
1025
|
+
continue;
|
|
1026
|
+
taskContext.restoreGoalCheckpoint(state, commit.taskContextRevision);
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
890
1030
|
async function loadRuntimeBaseMessages(compact, configured) {
|
|
891
1031
|
const authoritative = compact.loadModelVisibleHistory();
|
|
892
1032
|
const configuredMessages = configured ? await configured : undefined;
|
|
@@ -943,19 +1083,16 @@ function withStopDecision(commit, stopDecision) {
|
|
|
943
1083
|
};
|
|
944
1084
|
return Object.freeze({ ...content, digest: (0, canonical_1.digestRuntimeValue)(content) });
|
|
945
1085
|
}
|
|
946
|
-
function terminalFromAgentCommit(complete) {
|
|
1086
|
+
function terminalFromAgentCommit(complete, showBudgetStop) {
|
|
947
1087
|
if (complete.stats?.finishReason === 'cancelled') {
|
|
948
1088
|
return { status: 'interrupted', reason: complete.content || 'AgentLoop interrupted' };
|
|
949
1089
|
}
|
|
950
|
-
if (complete.stats
|
|
1090
|
+
if ((0, agent_loop_1.isFailedLoopStats)(complete.stats)) {
|
|
951
1091
|
return { status: 'failed', error: complete.content || 'AgentLoop failed' };
|
|
952
1092
|
}
|
|
953
1093
|
return {
|
|
954
1094
|
status: 'completed',
|
|
955
|
-
outcome: (0,
|
|
956
|
-
finishReason: complete.stats?.finishReason ?? 'completed',
|
|
957
|
-
stopDecision: complete.stats?.stopDecision,
|
|
958
|
-
}),
|
|
1095
|
+
outcome: (0, agent_loop_1.serializeAgentLoopOutcome)(complete.stats, showBudgetStop),
|
|
959
1096
|
};
|
|
960
1097
|
}
|
|
961
1098
|
function servicePort(serviceId, value) {
|
|
@@ -7,6 +7,7 @@ import type { UiEventSink } from './ui-events';
|
|
|
7
7
|
import type { ThreadSessionRuntimeActivationV1 } from './thread-session-view';
|
|
8
8
|
import { resolvePlanReviewV1 } from './plan-review';
|
|
9
9
|
import type { PlanReviewProjectionV1 } from './thread-projection';
|
|
10
|
+
import type { ModelSwitchCompactPreflightRequest, ModelSwitchCompactPreflightReceipt } from './model-coordinator';
|
|
10
11
|
export interface OrionSessionRunnerOptionsV1 {
|
|
11
12
|
readonly eventSink: UiEventSink;
|
|
12
13
|
readonly getSessionId: () => string;
|
|
@@ -31,9 +32,15 @@ export declare class OrionSessionRunnerV1 implements AgentRuntimeRunnerV1 {
|
|
|
31
32
|
constructor(options: OrionSessionRunnerOptionsV1);
|
|
32
33
|
runInput(input: string, options?: AgentRuntimeRunInputOptionsV1): Promise<void>;
|
|
33
34
|
runRequest(request: AgentTurnRequest, options?: AgentRuntimeRunInputOptionsV1): Promise<void>;
|
|
35
|
+
admittedFollowups(sessionId: string, ids: readonly string[]): ReadonlySet<string>;
|
|
36
|
+
conversationTurnCount(sessionId: string): number | undefined;
|
|
37
|
+
compactRecoveryWarning(sessionId: string): string | undefined;
|
|
38
|
+
private assertFollowupSession;
|
|
34
39
|
restoreSession(activation?: ThreadSessionRuntimeActivationV1): Promise<void>;
|
|
35
40
|
controlGoal(control: GoalRuntimeControlV2): Promise<GoalRuntimeControlResultV2>;
|
|
36
41
|
compact(input?: AgentRuntimeCompactInputV1): Promise<AgentRuntimeCompactResultV1>;
|
|
42
|
+
/** A committed model-switch receipt always identifies the durable Thread history. */
|
|
43
|
+
compactForModelSwitch(request: ModelSwitchCompactPreflightRequest): Promise<ModelSwitchCompactPreflightReceipt>;
|
|
37
44
|
diagnostics(): Promise<OrionRuntimeDiagnosticsV1>;
|
|
38
45
|
planReviewState(): Promise<PlanReviewProjectionV1 | undefined>;
|
|
39
46
|
reviewPlan(input: Parameters<typeof resolvePlanReviewV1>[1]): Promise<ReturnType<typeof resolvePlanReviewV1>>;
|
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.OrionSessionRunnerV1 = void 0;
|
|
4
4
|
const thread_ui_adapter_1 = require("./thread-ui-adapter");
|
|
5
5
|
const plan_review_1 = require("./plan-review");
|
|
6
|
+
const token_estimate_1 = require("../utils/token-estimate");
|
|
7
|
+
const canonical_1 = require("./protocol/canonical");
|
|
8
|
+
const session_storage_1 = require("../services/session-storage");
|
|
6
9
|
/**
|
|
7
10
|
* Session-aware product runner. A session switch drains and closes the old
|
|
8
11
|
* OrionRuntime before constructing the next sole Thread owner.
|
|
@@ -15,12 +18,43 @@ class OrionSessionRunnerV1 {
|
|
|
15
18
|
}
|
|
16
19
|
async runInput(input, options) {
|
|
17
20
|
const active = await this.ensureActive();
|
|
21
|
+
this.assertFollowupSession(active, options);
|
|
18
22
|
return active.adapter.runInput(input, options);
|
|
19
23
|
}
|
|
20
24
|
async runRequest(request, options) {
|
|
21
25
|
const active = await this.ensureActive();
|
|
26
|
+
this.assertFollowupSession(active, options);
|
|
22
27
|
return active.adapter.runRequest(request, options);
|
|
23
28
|
}
|
|
29
|
+
admittedFollowups(sessionId, ids) {
|
|
30
|
+
if (this.active?.sessionId !== sessionId || ids.length === 0)
|
|
31
|
+
return new Set();
|
|
32
|
+
const turns = this.active.runtime.thread.getProjection().turns;
|
|
33
|
+
return new Set(ids.filter(id => Object.prototype.hasOwnProperty.call(turns, id)));
|
|
34
|
+
}
|
|
35
|
+
conversationTurnCount(sessionId) {
|
|
36
|
+
if (this.active?.sessionId !== sessionId)
|
|
37
|
+
return undefined;
|
|
38
|
+
const turns = this.active.runtime.thread.getProjection().turns;
|
|
39
|
+
return Object.values(turns).filter(turn => turn.mode !== 'maintenance').length;
|
|
40
|
+
}
|
|
41
|
+
compactRecoveryWarning(sessionId) {
|
|
42
|
+
if (this.active?.sessionId !== sessionId)
|
|
43
|
+
return;
|
|
44
|
+
const events = this.active.runtime.thread.getProjection().compactEvents;
|
|
45
|
+
const latest = events?.[events.length - 1]?.payload;
|
|
46
|
+
if (latest?.type === 'compact.failed' &&
|
|
47
|
+
latest.data.failureCode === 'orphaned_before_checkpoint_commit') {
|
|
48
|
+
return 'Previous compaction was interrupted before its checkpoint committed. Using the last committed context.';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
assertFollowupSession(active, options) {
|
|
52
|
+
if (options?.followup &&
|
|
53
|
+
(active.sessionId !== options.followup.sessionId ||
|
|
54
|
+
active.sessionId !== this.options.getSessionId())) {
|
|
55
|
+
throw new Error('Queued follow-up belongs to another session.');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
24
58
|
async restoreSession(activation) {
|
|
25
59
|
if (this.closed)
|
|
26
60
|
throw new Error('Orion session runner is closed.');
|
|
@@ -78,6 +112,54 @@ class OrionSessionRunnerV1 {
|
|
|
78
112
|
active.adapter.flush();
|
|
79
113
|
return { status, turnId: admission.turnId };
|
|
80
114
|
}
|
|
115
|
+
/** A committed model-switch receipt always identifies the durable Thread history. */
|
|
116
|
+
async compactForModelSwitch(request) {
|
|
117
|
+
const active = await this.ensureActive();
|
|
118
|
+
const snapshot = active.runtime.thread.getAdmissionSnapshot();
|
|
119
|
+
if (snapshot.activeTurn || snapshot.queue.length > 0) {
|
|
120
|
+
return { status: 'rejected', error: 'Model-switch compact requires an idle runtime.' };
|
|
121
|
+
}
|
|
122
|
+
const history = active.runtime.graph.compactPersistence.loadModelVisibleHistory();
|
|
123
|
+
const currentTokens = (0, token_estimate_1.estimateMessagesTokens)(history ?? []);
|
|
124
|
+
if (currentTokens <= request.safeInputBudget)
|
|
125
|
+
return { status: 'not_needed', currentTokens };
|
|
126
|
+
const admission = active.runtime.compact({
|
|
127
|
+
modelSwitchBudget: {
|
|
128
|
+
safeInputBudget: request.safeInputBudget,
|
|
129
|
+
targetTokens: request.targetTokens,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
if (admission.status !== 'started') {
|
|
133
|
+
return {
|
|
134
|
+
status: 'rejected',
|
|
135
|
+
error: `Model-switch compact was not admitted: ${admission.status}.`,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
this.startBackgroundDrain(active);
|
|
139
|
+
const status = await active.runtime.thread.waitForTurnTerminal(admission.turnId);
|
|
140
|
+
if (this.active === active)
|
|
141
|
+
active.adapter.flush();
|
|
142
|
+
if (status !== 'completed') {
|
|
143
|
+
return { status: 'rejected', error: `Model-switch compact ended as ${status}.` };
|
|
144
|
+
}
|
|
145
|
+
const durable = active.runtime.graph.compactPersistence.loadModelVisibleHistory();
|
|
146
|
+
const candidateFingerprint = (0, canonical_1.digestRuntimeValue)(durable);
|
|
147
|
+
const completed = active.runtime.graph.compactPersistence
|
|
148
|
+
.listCompactEvents()
|
|
149
|
+
.find(event => event.turnId === admission.turnId && event.payload.type === 'compact.completed');
|
|
150
|
+
if (completed?.payload.type !== 'compact.completed' ||
|
|
151
|
+
completed.payload.data.nextModelVisibleHistoryDigest !== candidateFingerprint) {
|
|
152
|
+
return { status: 'rejected', error: 'Model-switch compact history could not be read back.' };
|
|
153
|
+
}
|
|
154
|
+
// Session restore normalizes transport fields (for example timestamps).
|
|
155
|
+
// Return the exact provider-visible projection consumed by that path.
|
|
156
|
+
const restored = [...(0, session_storage_1.loadSessionRestoreBundle)(active.sessionId).history.messages];
|
|
157
|
+
return {
|
|
158
|
+
status: 'committed',
|
|
159
|
+
afterTokens: (0, token_estimate_1.estimateMessagesTokens)(restored),
|
|
160
|
+
candidateFingerprint: (0, canonical_1.digestRuntimeValue)(restored),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
81
163
|
async diagnostics() {
|
|
82
164
|
const active = await this.ensureActive();
|
|
83
165
|
return active.runtime.diagnostics();
|
|
@@ -35,4 +35,5 @@ export declare function resolvePlanReviewV1(runtime: OrionRuntimeV1, input: {
|
|
|
35
35
|
/** Recover the crash gap between a durable resolution and its turn admission. */
|
|
36
36
|
export declare function recoverResolvedPlanReviewV1(runtime: OrionRuntimeV1): PlanReviewResolutionReceiptV1['admission'];
|
|
37
37
|
export declare function findPlanReceiptForReviewV1(projection: ThreadProjectionV1, review: PlanReviewProjectionV1): PlanReceiptV1;
|
|
38
|
+
export declare function planReviewTurnInput(review: PlanReviewProjectionV1): string;
|
|
38
39
|
//# sourceMappingURL=plan-review.d.ts.map
|
|
@@ -5,6 +5,7 @@ exports.ensurePlanReviewRequestedV1 = ensurePlanReviewRequestedV1;
|
|
|
5
5
|
exports.resolvePlanReviewV1 = resolvePlanReviewV1;
|
|
6
6
|
exports.recoverResolvedPlanReviewV1 = recoverResolvedPlanReviewV1;
|
|
7
7
|
exports.findPlanReceiptForReviewV1 = findPlanReceiptForReviewV1;
|
|
8
|
+
exports.planReviewTurnInput = planReviewTurnInput;
|
|
8
9
|
const crypto_1 = require("crypto");
|
|
9
10
|
const canonical_1 = require("./protocol/canonical");
|
|
10
11
|
const turn_commit_1 = require("./turn-commit");
|
|
@@ -56,8 +57,11 @@ function resolvePlanReviewV1(runtime, input) {
|
|
|
56
57
|
throw new PlanReviewControlError('runtime_busy', 'The active logical request must finish before reviewing its plan.');
|
|
57
58
|
}
|
|
58
59
|
const current = projection.planReview;
|
|
59
|
-
if (!current ||
|
|
60
|
-
|
|
60
|
+
if (!current ||
|
|
61
|
+
current.planDigest !== input.planDigest ||
|
|
62
|
+
current.status === 'cancelled' ||
|
|
63
|
+
(input.action !== 'cancel' && current.status !== 'awaiting_review')) {
|
|
64
|
+
throw new PlanReviewControlError('plan_review_stale', 'The plan review no longer matches a plan that accepts this action.');
|
|
61
65
|
}
|
|
62
66
|
const feedback = input.feedback?.trim();
|
|
63
67
|
if (input.action === 'continue' && !feedback) {
|
|
@@ -155,8 +159,8 @@ function planReviewTurnInput(review) {
|
|
|
155
159
|
].join('\n');
|
|
156
160
|
}
|
|
157
161
|
function requireBoundPlanReceipt(projection, review) {
|
|
158
|
-
for (const turn of Object.values(projection.turns)) {
|
|
159
|
-
if (!turn.commit)
|
|
162
|
+
for (const turn of Object.values(projection.turns).reverse()) {
|
|
163
|
+
if (!turn.commit || turn.commit.seq >= review.requestedSeq)
|
|
160
164
|
continue;
|
|
161
165
|
const commit = (0, turn_commit_1.parseTurnCommitV1)(turn.commit.receipt);
|
|
162
166
|
if (!commit.planReceipt)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type UIRenderer } from '../services/config';
|
|
2
2
|
import { type SettingsInvalidationV1 } from '../services/settings-coordinator';
|
|
3
|
+
import { type SessionMeta } from '../services/session-storage';
|
|
4
|
+
import { type FirstPartyMcpServerConfigV1 } from './mcp';
|
|
3
5
|
import type { OrionRuntimeV1 } from './orion-runtime-v1';
|
|
4
6
|
import type { ThreadSessionRuntimeActivationV1 } from './thread-session-view';
|
|
5
7
|
import type { OrionCodeUiRuntime } from './ui-events';
|
|
@@ -7,7 +9,9 @@ import type { WorkspaceMutationCoordinatorV1 } from './step-snapshot';
|
|
|
7
9
|
import { WorkspaceRuntimeKernelV1 } from './workspace-runtime-kernel';
|
|
8
10
|
export interface CreateWorkspaceRuntimeKernelOptionsV1 {
|
|
9
11
|
readonly cwd: string;
|
|
12
|
+
readonly toolNames?: readonly string[];
|
|
10
13
|
readonly uiRenderer?: UIRenderer;
|
|
14
|
+
readonly sessionMcpServers?: Readonly<Record<string, FirstPartyMcpServerConfigV1>>;
|
|
11
15
|
readonly onSettingsInvalidated?: (event: SettingsInvalidationV1) => void;
|
|
12
16
|
}
|
|
13
17
|
/**
|
|
@@ -20,6 +24,8 @@ export declare function createWorkspaceRuntimeKernelV1(options: CreateWorkspaceR
|
|
|
20
24
|
export interface ProductUiRuntimeBootstrapOptions {
|
|
21
25
|
readonly cwd: string;
|
|
22
26
|
readonly uiRenderer?: UIRenderer;
|
|
27
|
+
readonly sessionSource?: SessionMeta['source'];
|
|
28
|
+
readonly sessionMcpServers?: Readonly<Record<string, FirstPartyMcpServerConfigV1>>;
|
|
23
29
|
/** Renderer-specific shutdown label used in durable diagnostics. */
|
|
24
30
|
readonly shutdownReason?: string;
|
|
25
31
|
readonly onActiveSessionRuntime?: (runtime: OrionRuntimeV1, sessionId: string, activation?: ThreadSessionRuntimeActivationV1) => void | (() => void);
|