@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,8 +2,13 @@
|
|
|
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 task_checklist_1 = require("../harness/task-checklist");
|
|
8
|
+
const file_lock_1 = require("../services/file-lock");
|
|
6
9
|
const agent_loop_1 = require("./agent-loop");
|
|
10
|
+
const builtin_tool_provider_1 = require("./builtin-tool-provider");
|
|
11
|
+
const todo_1 = require("../tools/todo");
|
|
7
12
|
const batch_read_service_1 = require("./batch-read-service");
|
|
8
13
|
const capability_receipt_journal_1 = require("./capability-receipt-journal");
|
|
9
14
|
const capability_step_factory_1 = require("./capability-step-factory");
|
|
@@ -12,6 +17,7 @@ const goal_runtime_coordinator_1 = require("./goal-runtime-coordinator");
|
|
|
12
17
|
const mcp_1 = require("./mcp");
|
|
13
18
|
const prompts_1 = require("./prompts");
|
|
14
19
|
const canonical_1 = require("./protocol/canonical");
|
|
20
|
+
const task_context_recovery_1 = require("./task-context-recovery");
|
|
15
21
|
const harness_metrics_1 = require("./harness-metrics");
|
|
16
22
|
const resource_scope_1 = require("./resource-scope");
|
|
17
23
|
const runtime_services_1 = require("./runtime-services");
|
|
@@ -48,7 +54,6 @@ const SERVICE_IDS = Object.freeze({
|
|
|
48
54
|
compaction: 'compact-transaction-v1',
|
|
49
55
|
});
|
|
50
56
|
/** Process-local guard; it is an ownership check, never a service lookup path. */
|
|
51
|
-
const ACTIVE_RUNTIME_OWNERS = new Map();
|
|
52
57
|
/**
|
|
53
58
|
* Explicit first-party production composition root for exactly one ThreadRuntime.
|
|
54
59
|
* Construction is side-effect free; start() owns resources and close() releases them.
|
|
@@ -58,7 +63,6 @@ class OrionRuntimeV1 {
|
|
|
58
63
|
this.stateValue = 'created';
|
|
59
64
|
this.closeRequested = false;
|
|
60
65
|
this.options = validateOptions(options);
|
|
61
|
-
this.ownerKey = ownerKey(this.options.eventStore);
|
|
62
66
|
this.scope = new resource_scope_1.ResourceScope({ deadlineMs: options.closeDeadlineMs });
|
|
63
67
|
}
|
|
64
68
|
get state() {
|
|
@@ -240,14 +244,26 @@ class OrionRuntimeV1 {
|
|
|
240
244
|
if (!Number.isSafeInteger(maxMessages) || maxMessages <= 0) {
|
|
241
245
|
throw new OrionRuntimeV1Error('ORION_RUNTIME_INVALID_CONFIGURATION', 'Explicit compact maxMessages must be a positive integer.');
|
|
242
246
|
}
|
|
247
|
+
const budget = input.modelSwitchBudget;
|
|
248
|
+
if (budget &&
|
|
249
|
+
(!Number.isSafeInteger(budget.safeInputBudget) ||
|
|
250
|
+
budget.safeInputBudget <= 0 ||
|
|
251
|
+
!Number.isSafeInteger(budget.targetTokens) ||
|
|
252
|
+
budget.targetTokens <= 0 ||
|
|
253
|
+
budget.targetTokens > budget.safeInputBudget)) {
|
|
254
|
+
throw new OrionRuntimeV1Error('ORION_RUNTIME_INVALID_CONFIGURATION', 'Model-switch compact requires a positive target within its safe input budget.');
|
|
255
|
+
}
|
|
243
256
|
const request = Object.freeze({
|
|
244
257
|
type: 'compact',
|
|
245
258
|
source: 'explicit',
|
|
246
259
|
prepare: async ({ source, history, }, signal) => {
|
|
247
260
|
throwIfAborted(signal);
|
|
248
261
|
const messages = parseModelVisibleHistory(history);
|
|
249
|
-
const result = await coordinator.compactManual(messages, maxMessages, input.focus);
|
|
262
|
+
const result = await coordinator.compactManual(messages, maxMessages, input.focus, budget, signal);
|
|
250
263
|
throwIfAborted(signal);
|
|
264
|
+
if (budget && result.afterTokens > budget.targetTokens) {
|
|
265
|
+
throw new Error(`Compact candidate uses ${result.afterTokens} tokens; target is ${budget.targetTokens}.`);
|
|
266
|
+
}
|
|
251
267
|
return (0, thread_compact_persistence_1.createThreadCompactCandidateDraftV1)({
|
|
252
268
|
source: 'explicit',
|
|
253
269
|
sourceHistoryDigest: source.historyDigest,
|
|
@@ -292,15 +308,38 @@ class OrionRuntimeV1 {
|
|
|
292
308
|
}
|
|
293
309
|
async performStart() {
|
|
294
310
|
try {
|
|
295
|
-
this.acquireOwnership();
|
|
296
311
|
const eventStore = this.options.eventStore.store ??
|
|
297
312
|
new thread_event_store_1.ThreadEventStore(this.options.eventStore.rootDir, this.options.eventStore.threadId, this.options.eventStore.options);
|
|
313
|
+
this.acquireOwnership(eventStore);
|
|
298
314
|
const compactPersistence = new thread_compact_persistence_1.ThreadCompactTransactionPersistenceV1(eventStore);
|
|
299
315
|
const compactRunner = new thread_compact_persistence_1.ThreadCompactMaintenanceRunnerV1(eventStore, this.options.compact);
|
|
300
316
|
const compactRecovery = await compactRunner.recoverOrphans();
|
|
301
|
-
const
|
|
302
|
-
const
|
|
317
|
+
const startupProjection = eventStore.loadProjection();
|
|
318
|
+
const orphan = startupProjection.activeTurnId
|
|
319
|
+
? startupProjection.turns[startupProjection.activeTurnId]
|
|
320
|
+
: undefined;
|
|
321
|
+
const previousCommit = restoreLatestTurnCommit(eventStore);
|
|
322
|
+
const taskOptions = mergeTaskContextOptions(this.options.taskContext, previousCommit);
|
|
323
|
+
const recovered = (0, task_context_recovery_1.recoverInterruptedTaskContext)({
|
|
324
|
+
store: eventStore,
|
|
325
|
+
previousCommit,
|
|
326
|
+
taskOptions,
|
|
327
|
+
loadImportedHistory: this.options.loadImportedHistory,
|
|
328
|
+
restoreGoalState: () => (0, goal_runtime_coordinator_1.recoverInterruptedGoalState)(previousCommit),
|
|
329
|
+
});
|
|
330
|
+
const restored = recovered ?? previousCommit;
|
|
331
|
+
const taskContext = (0, task_context_service_1.createTaskContextService)({
|
|
332
|
+
...taskOptions,
|
|
333
|
+
...(recovered
|
|
334
|
+
? {
|
|
335
|
+
state: parseTaskContextState(recovered),
|
|
336
|
+
revision: recovered.taskContextRevision,
|
|
337
|
+
}
|
|
338
|
+
: {}),
|
|
339
|
+
requireLocalVerificationReceipt: true,
|
|
340
|
+
});
|
|
303
341
|
const goal = new goal_runtime_coordinator_1.GoalRuntimeCoordinatorV2({
|
|
342
|
+
...this.options.goalPolicy,
|
|
304
343
|
...(this.options.goal ? { definition: this.options.goal } : {}),
|
|
305
344
|
...(restored ? { restoredCommit: restored } : {}),
|
|
306
345
|
});
|
|
@@ -326,7 +365,13 @@ class OrionRuntimeV1 {
|
|
|
326
365
|
};
|
|
327
366
|
},
|
|
328
367
|
});
|
|
368
|
+
const todoCatalog = this.options.enableTaskTodos
|
|
369
|
+
? (0, builtin_tool_provider_1.createBuiltinToolCatalogV1)([(0, todo_1.createTodoWriteTool)(todos => taskContext.updateTaskTodos(todos))], { context: this.options.toolContext })
|
|
370
|
+
: undefined;
|
|
329
371
|
const basePolicy = new first_party_tool_services_1.FirstPartyToolPolicyServiceV1(this.options.toolCatalog, this.options.toolContext);
|
|
372
|
+
const todoPolicy = todoCatalog
|
|
373
|
+
? new first_party_tool_services_1.FirstPartyToolPolicyServiceV1(todoCatalog, this.options.toolContext)
|
|
374
|
+
: undefined;
|
|
330
375
|
const subagentTurns = new Map();
|
|
331
376
|
const subagentTurnFlights = new Map();
|
|
332
377
|
const subagentUnavailableTurns = new Set();
|
|
@@ -335,6 +380,8 @@ class OrionRuntimeV1 {
|
|
|
335
380
|
const policy = Object.freeze({
|
|
336
381
|
serviceId: 'turn-routed-first-party-tool-policy-v1',
|
|
337
382
|
decide: (input) => {
|
|
383
|
+
if (todoPolicy && input.descriptor.name === 'todo_write')
|
|
384
|
+
return todoPolicy.decide(input);
|
|
338
385
|
if (input.descriptor.name === 'subtask') {
|
|
339
386
|
const turnPolicy = subagentPolicies.get(input.snapshot.turnId);
|
|
340
387
|
if (!turnPolicy) {
|
|
@@ -433,7 +480,7 @@ class OrionRuntimeV1 {
|
|
|
433
480
|
prompts,
|
|
434
481
|
}));
|
|
435
482
|
const subagentTurn = await resolveSubagentTurn(input, configured.compiler.authority);
|
|
436
|
-
const dynamic = mergeDynamicTools(configured.dynamicTools, subagentTurn?.catalog);
|
|
483
|
+
const dynamic = mergeDynamicTools(mergeDynamicTools(configured.dynamicTools, subagentTurn?.catalog), (0, task_checklist_1.supportsExecutionChecklist)(input.mode) ? todoCatalog : undefined);
|
|
437
484
|
const registry = new Map(this.options.toolCatalog.bindings);
|
|
438
485
|
for (const [bindingId, binding] of dynamic?.bindings ?? []) {
|
|
439
486
|
if (registry.has(bindingId)) {
|
|
@@ -468,11 +515,16 @@ class OrionRuntimeV1 {
|
|
|
468
515
|
},
|
|
469
516
|
});
|
|
470
517
|
const turnCommits = new turn_commit_1.ThreadTurnCommitJournalV1(eventStore);
|
|
518
|
+
let activeTurnContext;
|
|
519
|
+
const loopOptions = this.options.loop;
|
|
471
520
|
const agentLoop = new agent_loop_1.AgentLoopV1({
|
|
472
521
|
llm: this.options.modelExecutor,
|
|
473
522
|
taskContext,
|
|
474
523
|
steps: stepFactory,
|
|
475
524
|
gateway,
|
|
525
|
+
previousCommitDigest: () => latestTurnCommitProjection(eventStore)?.digest,
|
|
526
|
+
enableTaskTodos: this.options.enableTaskTodos,
|
|
527
|
+
resolveGoalTask: () => goal.state,
|
|
476
528
|
loadBaseMessages: context => loadRuntimeBaseMessages(compactPersistence, this.options.loadBaseMessages?.(eventStore, context, prompts, {
|
|
477
529
|
taskContext,
|
|
478
530
|
goal,
|
|
@@ -481,7 +533,18 @@ class OrionRuntimeV1 {
|
|
|
481
533
|
})),
|
|
482
534
|
toolContext: () => this.options.toolContext,
|
|
483
535
|
streamCallbacks: this.options.loop?.streamCallbacks,
|
|
484
|
-
loopBudget
|
|
536
|
+
get loopBudget() {
|
|
537
|
+
return activeTurnContext && loopOptions?.resolveLoopBudget
|
|
538
|
+
? loopOptions.resolveLoopBudget(activeTurnContext, goal)
|
|
539
|
+
: loopOptions?.loopBudget;
|
|
540
|
+
},
|
|
541
|
+
get remainingGoalTokens() {
|
|
542
|
+
const state = goal.state;
|
|
543
|
+
return state?.status === 'active'
|
|
544
|
+
? Math.max(0, state.budget.maxTokens - state.tokensUsed)
|
|
545
|
+
: undefined;
|
|
546
|
+
},
|
|
547
|
+
allowBudgetRecovery: true,
|
|
485
548
|
onContextUsage: this.options.loop?.onContextUsage,
|
|
486
549
|
compactCoordinator: this.options.loop?.compactCoordinator,
|
|
487
550
|
commitTurn: commit => {
|
|
@@ -491,12 +554,21 @@ class OrionRuntimeV1 {
|
|
|
491
554
|
: commit;
|
|
492
555
|
let durableCommit;
|
|
493
556
|
goal.commitTurn(committed, fields => {
|
|
557
|
+
if (activeTurnContext &&
|
|
558
|
+
fields.stopDecision &&
|
|
559
|
+
/^(goal_checkpoint|goal_manual_continuation)/u.test(fields.stopDecision.reason.code)) {
|
|
560
|
+
const checkpoint = activeTurnContext.startItem({ kind: 'reasoning' });
|
|
561
|
+
activeTurnContext.completeItem(checkpoint, {
|
|
562
|
+
content: fields.stopDecision.reason.message,
|
|
563
|
+
summary: fields.stopDecision.reason.message,
|
|
564
|
+
});
|
|
565
|
+
}
|
|
494
566
|
durableCommit = turnCommits.commit({
|
|
495
567
|
turnId: committed.turnId,
|
|
496
568
|
history: committed.history,
|
|
497
569
|
taskContextState: committed.taskContextState,
|
|
498
570
|
taskContextRevision: committed.taskContextRevision,
|
|
499
|
-
terminal: terminalFromAgentCommit(committed.queryComplete),
|
|
571
|
+
terminal: terminalFromAgentCommit(committed.queryComplete, activeTurnContext?.mode !== 'goal'),
|
|
500
572
|
...(fields.goalState ? { goalState: fields.goalState } : {}),
|
|
501
573
|
...(fields.stopDecision ? { stopDecision: fields.stopDecision } : {}),
|
|
502
574
|
...(prepared?.plan ? { plan: prepared.plan } : {}),
|
|
@@ -524,12 +596,22 @@ class OrionRuntimeV1 {
|
|
|
524
596
|
const runtime = new thread_runtime_1.ThreadRuntimeV1({
|
|
525
597
|
...this.options.thread,
|
|
526
598
|
store: eventStore,
|
|
527
|
-
runner:
|
|
599
|
+
runner: {
|
|
600
|
+
run: async (context) => {
|
|
601
|
+
activeTurnContext = context;
|
|
602
|
+
try {
|
|
603
|
+
return await agentLoop.run(context);
|
|
604
|
+
}
|
|
605
|
+
finally {
|
|
606
|
+
activeTurnContext = undefined;
|
|
607
|
+
}
|
|
608
|
+
},
|
|
609
|
+
},
|
|
528
610
|
maintenanceRunner: compactRunner,
|
|
529
611
|
projectPath: this.options.projectPath,
|
|
530
612
|
requireTurnCommit: true,
|
|
531
613
|
onTurnStarted: turn => {
|
|
532
|
-
goal.markTurnStarted(turn.turnId, turn.startedAt);
|
|
614
|
+
goal.markTurnStarted(turn.turnId, turn.startedAt, taskContext.exportState().ledger.map(entry => entry.id));
|
|
533
615
|
this.options.thread?.onTurnStarted?.(turn);
|
|
534
616
|
},
|
|
535
617
|
onTurnDurablyTerminal: terminal => goal.afterDurableTerminal(terminal.turnId, terminal.terminal) ??
|
|
@@ -554,6 +636,7 @@ class OrionRuntimeV1 {
|
|
|
554
636
|
}
|
|
555
637
|
},
|
|
556
638
|
});
|
|
639
|
+
this.writerThread = runtime;
|
|
557
640
|
return {
|
|
558
641
|
value: runtime,
|
|
559
642
|
dispose: async (context) => {
|
|
@@ -617,6 +700,7 @@ class OrionRuntimeV1 {
|
|
|
617
700
|
? eventStore.loadProjection().turns[restored.turnId]
|
|
618
701
|
: undefined;
|
|
619
702
|
if (!this.closeRequested &&
|
|
703
|
+
!(orphan && orphan.mode !== 'maintenance' && !orphan.commit) &&
|
|
620
704
|
restoredTurn?.status === 'completed' &&
|
|
621
705
|
eventStore.loadProjection().queue.length === 0) {
|
|
622
706
|
const continuation = goal.takeRestoredContinuation();
|
|
@@ -650,22 +734,35 @@ class OrionRuntimeV1 {
|
|
|
650
734
|
// Failed start already rolled back the same ResourceScope.
|
|
651
735
|
}
|
|
652
736
|
}
|
|
737
|
+
this.options.loop?.compactCoordinator?.cancelBackground('runtime_closed');
|
|
653
738
|
const report = await this.scope.close({ reason });
|
|
654
739
|
this.releaseOwnership();
|
|
655
740
|
this.stateValue = 'closed';
|
|
656
741
|
return report;
|
|
657
742
|
}
|
|
658
|
-
acquireOwnership() {
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
743
|
+
acquireOwnership(store) {
|
|
744
|
+
(0, fs_1.mkdirSync)(store.rootDir, { recursive: true, mode: 0o700 });
|
|
745
|
+
try {
|
|
746
|
+
this.releaseWriter = (0, file_lock_1.acquireFileLockSync)(`${store.logPath}.runtime-owner`, { waitMs: 0 });
|
|
747
|
+
}
|
|
748
|
+
catch (error) {
|
|
749
|
+
if (!(error instanceof file_lock_1.FileLockBusyError))
|
|
750
|
+
throw error;
|
|
751
|
+
throw new OrionRuntimeV1Error('ORION_RUNTIME_OWNER_CONFLICT', `Thread ${store.threadId} already has an active OrionRuntime owner.`);
|
|
662
752
|
}
|
|
663
|
-
ACTIVE_RUNTIME_OWNERS.set(this.ownerKey, this);
|
|
664
753
|
}
|
|
665
754
|
releaseOwnership() {
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
755
|
+
const release = this.releaseWriter;
|
|
756
|
+
if (!release)
|
|
757
|
+
return;
|
|
758
|
+
this.releaseWriter = undefined;
|
|
759
|
+
// The scope's teardown deadline may expire before an aborted tool drains.
|
|
760
|
+
// Keep its write lease until there is no active turn left to publish.
|
|
761
|
+
if (this.writerThread)
|
|
762
|
+
void this.writerThread.waitForIdle().then(release);
|
|
763
|
+
else
|
|
764
|
+
release();
|
|
765
|
+
this.writerThread = undefined;
|
|
669
766
|
}
|
|
670
767
|
requireGraph() {
|
|
671
768
|
if (!this.graphValue || this.stateValue !== 'started') {
|
|
@@ -678,25 +775,25 @@ exports.OrionRuntimeV1 = OrionRuntimeV1;
|
|
|
678
775
|
function createOrionRuntimeV1(options) {
|
|
679
776
|
return new OrionRuntimeV1(options);
|
|
680
777
|
}
|
|
681
|
-
function mergeDynamicTools(configured,
|
|
682
|
-
if (!
|
|
778
|
+
function mergeDynamicTools(configured, additionalCatalog) {
|
|
779
|
+
if (!additionalCatalog)
|
|
683
780
|
return configured;
|
|
684
781
|
const candidates = [...(configured?.candidates ?? [])];
|
|
685
782
|
const bindings = new Map(configured?.bindings ?? []);
|
|
686
783
|
const candidateNames = new Set(candidates.map(candidate => candidate.descriptor.name));
|
|
687
784
|
const candidateBindingIds = new Set(candidates.map(candidate => candidate.bindingId));
|
|
688
|
-
for (const candidate of
|
|
785
|
+
for (const candidate of additionalCatalog.candidates) {
|
|
689
786
|
if (candidateNames.has(candidate.descriptor.name)) {
|
|
690
|
-
invalidConfiguration(`
|
|
787
|
+
invalidConfiguration(`Duplicate dynamic tool ${candidate.descriptor.name}.`);
|
|
691
788
|
}
|
|
692
789
|
if (candidateBindingIds.has(candidate.bindingId) || bindings.has(candidate.bindingId)) {
|
|
693
|
-
invalidConfiguration(`
|
|
790
|
+
invalidConfiguration(`Duplicate dynamic binding ${candidate.bindingId}.`);
|
|
694
791
|
}
|
|
695
792
|
candidates.push(candidate);
|
|
696
793
|
candidateNames.add(candidate.descriptor.name);
|
|
697
794
|
candidateBindingIds.add(candidate.bindingId);
|
|
698
795
|
}
|
|
699
|
-
for (const [bindingId, binding] of
|
|
796
|
+
for (const [bindingId, binding] of additionalCatalog.bindings) {
|
|
700
797
|
if (bindings.has(bindingId)) {
|
|
701
798
|
invalidConfiguration(`Turn subagent binding collides with dynamic binding ${bindingId}.`);
|
|
702
799
|
}
|
|
@@ -836,9 +933,6 @@ function validateOptions(options) {
|
|
|
836
933
|
projectPath: (0, path_1.resolve)(options.projectPath),
|
|
837
934
|
});
|
|
838
935
|
}
|
|
839
|
-
function ownerKey(roots) {
|
|
840
|
-
return `${(0, path_1.resolve)(roots.rootDir)}\u0000${roots.threadId}`;
|
|
841
|
-
}
|
|
842
936
|
function goalControlInput(control) {
|
|
843
937
|
return `goal-control:${control.action}:${(0, canonical_1.digestRuntimeValue)(control)}`;
|
|
844
938
|
}
|
|
@@ -873,11 +967,16 @@ function mergeTaskContextOptions(configured, restored) {
|
|
|
873
967
|
};
|
|
874
968
|
}
|
|
875
969
|
function restoreLatestTurnCommit(store) {
|
|
876
|
-
const
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
970
|
+
const commit = latestTurnCommitProjection(store);
|
|
971
|
+
return commit ? (0, turn_commit_1.parseTurnCommitV1)(commit.receipt) : undefined;
|
|
972
|
+
}
|
|
973
|
+
function latestTurnCommitProjection(store) {
|
|
974
|
+
let latest;
|
|
975
|
+
for (const { commit } of Object.values(store.loadProjection().turns)) {
|
|
976
|
+
if (commit && (!latest || commit.seq > latest.seq))
|
|
977
|
+
latest = commit;
|
|
978
|
+
}
|
|
979
|
+
return latest;
|
|
881
980
|
}
|
|
882
981
|
function parseTaskContextState(commit) {
|
|
883
982
|
try {
|
|
@@ -943,19 +1042,16 @@ function withStopDecision(commit, stopDecision) {
|
|
|
943
1042
|
};
|
|
944
1043
|
return Object.freeze({ ...content, digest: (0, canonical_1.digestRuntimeValue)(content) });
|
|
945
1044
|
}
|
|
946
|
-
function terminalFromAgentCommit(complete) {
|
|
1045
|
+
function terminalFromAgentCommit(complete, showBudgetStop) {
|
|
947
1046
|
if (complete.stats?.finishReason === 'cancelled') {
|
|
948
1047
|
return { status: 'interrupted', reason: complete.content || 'AgentLoop interrupted' };
|
|
949
1048
|
}
|
|
950
|
-
if (complete.stats
|
|
1049
|
+
if ((0, agent_loop_1.isFailedLoopStats)(complete.stats)) {
|
|
951
1050
|
return { status: 'failed', error: complete.content || 'AgentLoop failed' };
|
|
952
1051
|
}
|
|
953
1052
|
return {
|
|
954
1053
|
status: 'completed',
|
|
955
|
-
outcome: (0,
|
|
956
|
-
finishReason: complete.stats?.finishReason ?? 'completed',
|
|
957
|
-
stopDecision: complete.stats?.stopDecision,
|
|
958
|
-
}),
|
|
1054
|
+
outcome: (0, agent_loop_1.serializeAgentLoopOutcome)(complete.stats, showBudgetStop),
|
|
959
1055
|
};
|
|
960
1056
|
}
|
|
961
1057
|
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);
|