@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
|
@@ -425,8 +425,10 @@ function resolvePlanReview(state, event) {
|
|
|
425
425
|
}
|
|
426
426
|
const current = state.planReview;
|
|
427
427
|
const data = event.payload.data;
|
|
428
|
-
if (!current ||
|
|
429
|
-
|
|
428
|
+
if (!current ||
|
|
429
|
+
current.status === 'cancelled' ||
|
|
430
|
+
(data.action !== 'cancel' && current.status !== 'awaiting_review')) {
|
|
431
|
+
throw invariant('no plan accepts this review action', event);
|
|
430
432
|
}
|
|
431
433
|
if (current.reviewId !== data.reviewId ||
|
|
432
434
|
current.revision !== data.previousRevision ||
|
|
@@ -65,6 +65,8 @@ export interface ThreadTurnExecutionContextV1 {
|
|
|
65
65
|
readonly outputDigest?: string;
|
|
66
66
|
}): void;
|
|
67
67
|
failItem(handle: ThreadItemHandleV1, error: string): void;
|
|
68
|
+
/** Drain committed input in order. A closing drain seals the turn only when empty. */
|
|
69
|
+
takePendingSteering?(closeIfEmpty?: boolean): string[];
|
|
68
70
|
onSteer(handler: (input: string, itemId: string) => void | Promise<void>): void;
|
|
69
71
|
}
|
|
70
72
|
export interface ThreadTurnRunnerV1 {
|
|
@@ -115,9 +117,11 @@ export declare class ThreadRuntimeV1 {
|
|
|
115
117
|
private readonly onTurnDurablyTerminal?;
|
|
116
118
|
private readonly onTurnSettled?;
|
|
117
119
|
private readonly consumers;
|
|
120
|
+
private readonly liveObservers;
|
|
118
121
|
private readonly compactMaintenance;
|
|
119
122
|
private readonly goalControlTurns;
|
|
120
123
|
private readonly queuedGoalControls;
|
|
124
|
+
private readonly pendingSteering;
|
|
121
125
|
private activeAbort;
|
|
122
126
|
private activeTurnId;
|
|
123
127
|
private activeRun;
|
|
@@ -130,6 +134,10 @@ export declare class ThreadRuntimeV1 {
|
|
|
130
134
|
dispatch(command: Extract<AgentRuntimeCommandV1, {
|
|
131
135
|
type: 'turn.start' | 'turn.steer' | 'turn.follow_up' | 'turn.interrupt';
|
|
132
136
|
}>): ThreadCommandAdmissionV1;
|
|
137
|
+
/** A pending user input and its admitted turn share one identity across crashes. */
|
|
138
|
+
startPendingFollowup(turnId: string, input: string, mode: Exclude<ThreadTurnRequestV1['mode'], 'goal' | 'maintenance'>): ThreadCommandAdmissionV1 | {
|
|
139
|
+
status: 'already_admitted';
|
|
140
|
+
};
|
|
133
141
|
startMaintenance(input: string): ThreadCommandAdmissionV1;
|
|
134
142
|
/**
|
|
135
143
|
* Serialize a Goal control mutation through the same bounded admission and
|
|
@@ -143,6 +151,8 @@ export declare class ThreadRuntimeV1 {
|
|
|
143
151
|
unsubscribe(consumerId: string): void;
|
|
144
152
|
/** Observe committed durable facts without acquiring ownership of the Thread lifecycle. */
|
|
145
153
|
observeCommittedEvents(listener: (events: readonly RuntimeEventEnvelopeV1[]) => void): () => void;
|
|
154
|
+
/** Observe newly published durable events and ephemeral deltas, without replay. */
|
|
155
|
+
observeLiveEvents(listener: (events: readonly RuntimeEventEnvelopeV1[]) => void): () => void;
|
|
146
156
|
replay(cursor?: number, limit?: number, reason?: ThreadEventReplayReasonV1): import("./thread-event-store").ThreadEventReplayV1;
|
|
147
157
|
getProjection(): import("./thread-projection").ThreadProjectionV1;
|
|
148
158
|
getAdmissionSnapshot(): import("./thread-admission").ThreadAdmissionSnapshotV1;
|
|
@@ -7,9 +7,11 @@ const runtime_protocol_v1_1 = require("./protocol/runtime-protocol-v1");
|
|
|
7
7
|
class ThreadRuntimeV1 {
|
|
8
8
|
constructor(options) {
|
|
9
9
|
this.consumers = new Map();
|
|
10
|
+
this.liveObservers = new Set();
|
|
10
11
|
this.compactMaintenance = new Map();
|
|
11
12
|
this.goalControlTurns = new Map();
|
|
12
13
|
this.queuedGoalControls = new Map();
|
|
14
|
+
this.pendingSteering = new Map();
|
|
13
15
|
this.idleWaiters = new Set();
|
|
14
16
|
this.closed = false;
|
|
15
17
|
this.store = options.store;
|
|
@@ -125,7 +127,14 @@ class ThreadRuntimeV1 {
|
|
|
125
127
|
payload: { type: 'item.completed', data: { content: steerInput } },
|
|
126
128
|
},
|
|
127
129
|
]);
|
|
128
|
-
|
|
130
|
+
if (this.activeTurnId === result.activeTurnId) {
|
|
131
|
+
try {
|
|
132
|
+
void Promise.resolve(this.steerHandler?.(steerInput, result.itemId)).catch(() => undefined);
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// A callback cannot veto already committed input.
|
|
136
|
+
}
|
|
137
|
+
}
|
|
129
138
|
break;
|
|
130
139
|
}
|
|
131
140
|
case 'interrupt_requested':
|
|
@@ -152,6 +161,32 @@ class ThreadRuntimeV1 {
|
|
|
152
161
|
throw error;
|
|
153
162
|
}
|
|
154
163
|
}
|
|
164
|
+
/** A pending user input and its admitted turn share one identity across crashes. */
|
|
165
|
+
startPendingFollowup(turnId, input, mode) {
|
|
166
|
+
if (this.closed)
|
|
167
|
+
return { status: 'rejected', reason: 'shutdown' };
|
|
168
|
+
if (!(0, runtime_protocol_v1_1.isRuntimeId)(turnId))
|
|
169
|
+
return { status: 'rejected', reason: 'invalid_input' };
|
|
170
|
+
if (Object.prototype.hasOwnProperty.call(this.getProjection().turns, turnId)) {
|
|
171
|
+
return { status: 'already_admitted' };
|
|
172
|
+
}
|
|
173
|
+
if (this.activeRun)
|
|
174
|
+
return { status: 'rejected', reason: 'overloaded' };
|
|
175
|
+
const before = this.admission.getSnapshot();
|
|
176
|
+
const result = this.admission.start({ input, mode, kind: 'regular' }, turnId);
|
|
177
|
+
if (result.status !== 'started')
|
|
178
|
+
return result;
|
|
179
|
+
try {
|
|
180
|
+
const active = this.requiredActiveTurn(result.turnId);
|
|
181
|
+
this.persistTurnStart(active);
|
|
182
|
+
this.scheduleTurn(active);
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
this.admission.restore(before);
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
155
190
|
startMaintenance(input) {
|
|
156
191
|
if (this.closed)
|
|
157
192
|
return { status: 'rejected', reason: 'shutdown' };
|
|
@@ -252,6 +287,13 @@ class ThreadRuntimeV1 {
|
|
|
252
287
|
throw new Error('Closed Thread runtime cannot be observed');
|
|
253
288
|
return this.store.subscribeCommitted(listener);
|
|
254
289
|
}
|
|
290
|
+
/** Observe newly published durable events and ephemeral deltas, without replay. */
|
|
291
|
+
observeLiveEvents(listener) {
|
|
292
|
+
if (this.closed)
|
|
293
|
+
throw new Error('Closed Thread runtime cannot be observed');
|
|
294
|
+
this.liveObservers.add(listener);
|
|
295
|
+
return () => this.liveObservers.delete(listener);
|
|
296
|
+
}
|
|
255
297
|
replay(cursor = 0, limit, reason) {
|
|
256
298
|
return this.store.replay(cursor, limit, reason);
|
|
257
299
|
}
|
|
@@ -302,9 +344,11 @@ class ThreadRuntimeV1 {
|
|
|
302
344
|
request.onRejected?.('shutdown');
|
|
303
345
|
this.goalControlTurns.clear();
|
|
304
346
|
this.queuedGoalControls.clear();
|
|
347
|
+
this.pendingSteering.clear();
|
|
305
348
|
this.admission.close();
|
|
306
349
|
this.activeAbort?.abort(reason);
|
|
307
350
|
this.consumers.clear();
|
|
351
|
+
this.liveObservers.clear();
|
|
308
352
|
this.unsubscribeStore();
|
|
309
353
|
}
|
|
310
354
|
/** Runtime-owned entry for a recovered Goal; public input still uses dispatch(). */
|
|
@@ -377,8 +421,10 @@ class ThreadRuntimeV1 {
|
|
|
377
421
|
}
|
|
378
422
|
}
|
|
379
423
|
scheduleTurn(active) {
|
|
424
|
+
// Admission can open a turn after the preceding terminal is durable but
|
|
425
|
+
// before its resources settle. That run's finally block starts the new turn.
|
|
380
426
|
if (this.activeRun)
|
|
381
|
-
|
|
427
|
+
return;
|
|
382
428
|
const abortController = new AbortController();
|
|
383
429
|
this.activeAbort = abortController;
|
|
384
430
|
this.activeTurnId = active.turnId;
|
|
@@ -480,13 +526,28 @@ class ThreadRuntimeV1 {
|
|
|
480
526
|
failItem: (handle, error) => {
|
|
481
527
|
this.commitAndPublish([{ ...handle, payload: { type: 'item.failed', data: { error } } }]);
|
|
482
528
|
},
|
|
529
|
+
takePendingSteering: closeIfEmpty => {
|
|
530
|
+
if (this.closed || this.activeTurnId !== active.turnId || abortSignal.aborted)
|
|
531
|
+
return [];
|
|
532
|
+
const pending = this.pendingSteering.get(active.turnId);
|
|
533
|
+
if (pending) {
|
|
534
|
+
this.pendingSteering.delete(active.turnId);
|
|
535
|
+
return pending;
|
|
536
|
+
}
|
|
537
|
+
if (closeIfEmpty)
|
|
538
|
+
this.admission.closeSteering(active.turnId);
|
|
539
|
+
return [];
|
|
540
|
+
},
|
|
483
541
|
onSteer: handler => {
|
|
484
|
-
this.
|
|
542
|
+
if (this.activeTurnId === active.turnId)
|
|
543
|
+
this.steerHandler = handler;
|
|
485
544
|
},
|
|
486
545
|
};
|
|
487
546
|
}
|
|
488
547
|
finalizeTurn(active, outcome) {
|
|
489
548
|
const turnId = active.turnId;
|
|
549
|
+
this.admission.closeSteering(turnId);
|
|
550
|
+
this.pendingSteering.delete(turnId);
|
|
490
551
|
const goalControl = this.goalControlTurns.has(turnId);
|
|
491
552
|
let terminalPublished = false;
|
|
492
553
|
try {
|
|
@@ -659,9 +720,30 @@ class ThreadRuntimeV1 {
|
|
|
659
720
|
}
|
|
660
721
|
publish(events) {
|
|
661
722
|
for (const event of events) {
|
|
723
|
+
// Project committed steering before a live observer can drain it or submit more input.
|
|
724
|
+
if (event.turnId && event.durability === 'durable') {
|
|
725
|
+
if (event.payload.type === 'turn.steered') {
|
|
726
|
+
const pending = this.pendingSteering.get(event.turnId);
|
|
727
|
+
if (pending)
|
|
728
|
+
pending.push(event.payload.data.input);
|
|
729
|
+
else
|
|
730
|
+
this.pendingSteering.set(event.turnId, [event.payload.data.input]);
|
|
731
|
+
}
|
|
732
|
+
else if (event.payload.type === 'turn.interrupt_requested') {
|
|
733
|
+
this.pendingSteering.delete(event.turnId);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
662
736
|
for (const buffer of this.consumers.values())
|
|
663
737
|
buffer.offer(event);
|
|
664
738
|
}
|
|
739
|
+
for (const observer of this.liveObservers) {
|
|
740
|
+
try {
|
|
741
|
+
observer(events);
|
|
742
|
+
}
|
|
743
|
+
catch {
|
|
744
|
+
// Observers cannot interrupt Thread execution or change committed facts.
|
|
745
|
+
}
|
|
746
|
+
}
|
|
665
747
|
}
|
|
666
748
|
resolveIdleIfNeeded() {
|
|
667
749
|
if (this.activeRun || this.admission.getSnapshot().activeTurn)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Message } from '../services/llm';
|
|
2
2
|
import type { RuntimeEventEnvelopeV1 } from './protocol/runtime-protocol-v1';
|
|
3
3
|
import type { ThreadLogIdentityV1 } from './thread-event-store';
|
|
4
|
+
import type { TranscriptEntry } from './ui-events';
|
|
4
5
|
import type { ItemProjectionV1, PlanReviewProjectionV1, ThreadProjectionV1, TurnProjectionStatusV1 } from './thread-projection';
|
|
5
6
|
export interface ThreadSessionIndexPerformanceCountersV1 {
|
|
6
7
|
readonly indexBuilds: number;
|
|
@@ -19,6 +20,13 @@ export interface ThreadSessionTranscriptMessageV1 {
|
|
|
19
20
|
readonly tool_calls?: NonNullable<Message['tool_calls']>;
|
|
20
21
|
readonly appliedSkills?: readonly string[];
|
|
21
22
|
}
|
|
23
|
+
export declare const RESUME_TRANSCRIPT_WINDOW_MESSAGES = 50;
|
|
24
|
+
export interface ThreadResumeDisplayV1 {
|
|
25
|
+
readonly entries: readonly TranscriptEntry[];
|
|
26
|
+
readonly totalEntries: number;
|
|
27
|
+
}
|
|
28
|
+
/** UI-only window. These entries must never be used for model history recovery. */
|
|
29
|
+
export declare function projectThreadResumeDisplay(items: Readonly<Record<string, ItemProjectionV1>>): ThreadResumeDisplayV1;
|
|
22
30
|
export interface ThreadSessionTurnCommitV1 {
|
|
23
31
|
readonly seq: number;
|
|
24
32
|
readonly receipt: string;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ThreadSessionIndexError = void 0;
|
|
3
|
+
exports.ThreadSessionIndexError = exports.RESUME_TRANSCRIPT_WINDOW_MESSAGES = void 0;
|
|
4
4
|
exports.threadSessionIndexPerformanceCountersV1 = threadSessionIndexPerformanceCountersV1;
|
|
5
|
+
exports.projectThreadResumeDisplay = projectThreadResumeDisplay;
|
|
5
6
|
exports.buildThreadSessionIndexV1 = buildThreadSessionIndexV1;
|
|
6
7
|
exports.advanceThreadSessionIndexV1 = advanceThreadSessionIndexV1;
|
|
7
8
|
exports.loadThreadSessionIndexManifestV1 = loadThreadSessionIndexManifestV1;
|
|
@@ -11,6 +12,7 @@ const fs_1 = require("fs");
|
|
|
11
12
|
const path_1 = require("path");
|
|
12
13
|
const atomic_write_1 = require("../services/atomic-write");
|
|
13
14
|
const canonical_1 = require("./protocol/canonical");
|
|
15
|
+
const tool_transcript_entry_1 = require("./tool-transcript-entry");
|
|
14
16
|
const TRANSCRIPT_PAGE_ITEMS = 100;
|
|
15
17
|
const MAX_MANIFEST_PAGES = 100000;
|
|
16
18
|
const threadSessionIndexPerformance = {
|
|
@@ -23,6 +25,53 @@ const threadSessionIndexPerformance = {
|
|
|
23
25
|
function threadSessionIndexPerformanceCountersV1() {
|
|
24
26
|
return Object.freeze({ ...threadSessionIndexPerformance });
|
|
25
27
|
}
|
|
28
|
+
exports.RESUME_TRANSCRIPT_WINDOW_MESSAGES = 50;
|
|
29
|
+
/** UI-only window. These entries must never be used for model history recovery. */
|
|
30
|
+
function projectThreadResumeDisplay(items) {
|
|
31
|
+
const ordered = Object.values(items)
|
|
32
|
+
.filter(item => {
|
|
33
|
+
if (item.status === 'started')
|
|
34
|
+
return false;
|
|
35
|
+
return ((item.kind === 'message' && isMessageRole(item.role)) ||
|
|
36
|
+
item.kind === 'reasoning' ||
|
|
37
|
+
(0, tool_transcript_entry_1.isToolTranscriptItem)(item.kind));
|
|
38
|
+
})
|
|
39
|
+
.sort((left, right) => left.startedSeq - right.startedSeq);
|
|
40
|
+
return {
|
|
41
|
+
totalEntries: ordered.length,
|
|
42
|
+
entries: ordered.slice(-exports.RESUME_TRANSCRIPT_WINDOW_MESSAGES).map(item => {
|
|
43
|
+
if (item.kind === 'message') {
|
|
44
|
+
const legacy = parseLegacyTranscriptReceipt(item.receipt);
|
|
45
|
+
const role = legacy?.role ?? item.role;
|
|
46
|
+
return {
|
|
47
|
+
id: item.itemId,
|
|
48
|
+
role,
|
|
49
|
+
content: legacy?.content ?? item.content ?? item.summary ?? item.error ?? '',
|
|
50
|
+
...(role === 'user' ? { title: 'you' } : {}),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (item.kind === 'reasoning') {
|
|
54
|
+
return {
|
|
55
|
+
id: item.itemId,
|
|
56
|
+
role: 'assistant',
|
|
57
|
+
title: 'reasoning',
|
|
58
|
+
content: item.content ?? item.summary ?? '',
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
id: item.itemId,
|
|
63
|
+
...(0, tool_transcript_entry_1.toolTranscriptEntry)({
|
|
64
|
+
name: item.name ?? item.kind,
|
|
65
|
+
callId: item.itemId,
|
|
66
|
+
sequence: item.startedSeq,
|
|
67
|
+
success: item.status === 'completed',
|
|
68
|
+
command: (0, tool_transcript_entry_1.toolCommandFromIntent)(item.intent),
|
|
69
|
+
output: item.summary ?? item.error,
|
|
70
|
+
}),
|
|
71
|
+
};
|
|
72
|
+
}),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
26
75
|
class ThreadSessionIndexError extends Error {
|
|
27
76
|
constructor(code, message) {
|
|
28
77
|
super(message);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Message } from '../services/llm';
|
|
2
2
|
import { type SessionHistoryRecoveryDiagnosticV1, type SessionHistoryResolvedSourceV1 } from './session-history-recovery';
|
|
3
3
|
import { ThreadEventStore, type ThreadReadModelHeadV1 } from './thread-event-store';
|
|
4
|
-
import { type ThreadSessionLatestTurnV1, type ThreadSessionTranscriptMessageV1, type ThreadSessionTurnCommitV1 } from './thread-session-index';
|
|
4
|
+
import { type ThreadSessionLatestTurnV1, type ThreadSessionTranscriptMessageV1, type ThreadSessionTurnCommitV1, type ThreadResumeDisplayV1 } from './thread-session-index';
|
|
5
5
|
import type { PlanReviewProjectionV1 } from './thread-projection';
|
|
6
6
|
export type { ThreadSessionTranscriptMessageV1, ThreadSessionTurnCommitV1, } from './thread-session-index';
|
|
7
7
|
/** Metadata/transcript projection that never needs to decode model history. */
|
|
@@ -29,6 +29,7 @@ export interface ThreadSessionViewV1 extends ThreadSessionSummaryV1 {
|
|
|
29
29
|
readonly diagnostics: readonly SessionHistoryRecoveryDiagnosticV1[];
|
|
30
30
|
readonly latestTurnCommit?: ThreadSessionTurnCommitV1;
|
|
31
31
|
readonly latestPlanTurnCommit?: ThreadSessionTurnCommitV1;
|
|
32
|
+
readonly resumeDisplay?: ThreadResumeDisplayV1;
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
35
|
* A verified, process-local hand-off from Session restore into the sole
|
|
@@ -62,6 +62,7 @@ function openThreadSessionViewV1(projectPath, sessionId) {
|
|
|
62
62
|
modelHistory: recovery.messages,
|
|
63
63
|
modelHistorySource: recovery.source,
|
|
64
64
|
diagnostics: recovery.diagnostics,
|
|
65
|
+
...(captured.resumeDisplay ? { resumeDisplay: captured.resumeDisplay } : {}),
|
|
65
66
|
...(captured.latestTurnCommit ? { latestTurnCommit: captured.latestTurnCommit } : {}),
|
|
66
67
|
...(captured.latestPlanTurnCommit
|
|
67
68
|
? { latestPlanTurnCommit: captured.latestPlanTurnCommit }
|
|
@@ -201,6 +202,9 @@ function captureThreadSessionV1(projectPath, sessionId, includeDurableHistory) {
|
|
|
201
202
|
},
|
|
202
203
|
}),
|
|
203
204
|
durableHistory,
|
|
205
|
+
...(includeDurableHistory
|
|
206
|
+
? { resumeDisplay: (0, thread_session_index_1.projectThreadResumeDisplay)(projection.items) }
|
|
207
|
+
: {}),
|
|
204
208
|
store,
|
|
205
209
|
cutoverGeneration: resolution.generation,
|
|
206
210
|
...(latestTurnCommit ? { latestTurnCommit: Object.freeze(latestTurnCommit) } : {}),
|
|
@@ -8,4 +8,5 @@ export declare class ThreadToolInvocationJournalV1 implements ToolInvocationJour
|
|
|
8
8
|
begin(intent: ToolInvocationIntentV1): Promise<void>;
|
|
9
9
|
complete(receipt: ToolInvocationReceiptV1): Promise<void>;
|
|
10
10
|
}
|
|
11
|
+
export declare function parseToolInvocationIntentV1(value: string): ToolInvocationIntentV1;
|
|
11
12
|
//# sourceMappingURL=thread-tool-journal.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ThreadToolInvocationJournalV1 = void 0;
|
|
4
|
+
exports.parseToolInvocationIntentV1 = parseToolInvocationIntentV1;
|
|
4
5
|
const canonical_1 = require("./protocol/canonical");
|
|
5
6
|
/** Durable ToolGateway journal backed by the canonical Thread event log. */
|
|
6
7
|
class ThreadToolInvocationJournalV1 {
|
|
@@ -14,7 +15,7 @@ class ThreadToolInvocationJournalV1 {
|
|
|
14
15
|
if (item.kind !== 'command' || !item.intent) {
|
|
15
16
|
throw new Error(`Thread item ${invocationId} is not a durable tool invocation intent`);
|
|
16
17
|
}
|
|
17
|
-
const intent =
|
|
18
|
+
const intent = parseToolInvocationIntentV1(item.intent);
|
|
18
19
|
const receipt = item.receipt ? parseReceipt(item.receipt) : undefined;
|
|
19
20
|
if (receipt && receipt.intentDigest !== intent.digest) {
|
|
20
21
|
throw new Error(`Tool receipt ${invocationId} does not match its durable intent`);
|
|
@@ -108,8 +109,11 @@ function toTerminalPayload(receipt, receiptJson) {
|
|
|
108
109
|
};
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
|
-
function
|
|
112
|
+
function parseToolInvocationIntentV1(value) {
|
|
112
113
|
const parsed = JSON.parse(value);
|
|
114
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
115
|
+
throw new Error('Durable tool invocation intent must be an object');
|
|
116
|
+
}
|
|
113
117
|
const { digest, ...content } = parsed;
|
|
114
118
|
if (parsed?.version !== 1 ||
|
|
115
119
|
typeof digest !== 'string' ||
|
|
@@ -61,6 +61,7 @@ export declare class ThreadUiAdapterV1 implements AgentRuntimeRunnerV1 {
|
|
|
61
61
|
close(reason?: string): void;
|
|
62
62
|
snapshot(): ThreadUiAdapterSnapshotV1;
|
|
63
63
|
private runTurn;
|
|
64
|
+
private admitPendingFollowup;
|
|
64
65
|
private waitForIdleAndFlush;
|
|
65
66
|
private replayInitialHistory;
|
|
66
67
|
private replayRequired;
|
|
@@ -4,9 +4,29 @@ exports.ThreadUiAdmissionError = exports.ThreadUiAdapterError = exports.ThreadUi
|
|
|
4
4
|
const agent_runtime_protocol_1 = require("./agent-runtime-protocol");
|
|
5
5
|
const goal_runtime_coordinator_1 = require("./goal-runtime-coordinator");
|
|
6
6
|
const runtime_protocol_v1_1 = require("./protocol/runtime-protocol-v1");
|
|
7
|
+
const tool_transcript_entry_1 = require("./tool-transcript-entry");
|
|
7
8
|
const tool_receipt_validator_1 = require("./tool-receipt-validator");
|
|
8
9
|
const turn_commit_1 = require("./turn-commit");
|
|
10
|
+
const ui_view_model_1 = require("./ui-view-model");
|
|
9
11
|
exports.THREAD_UI_ADAPTER_VERSION = 1;
|
|
12
|
+
function budgetStopFromOutcome(outcome) {
|
|
13
|
+
if (!outcome?.startsWith('{'))
|
|
14
|
+
return undefined;
|
|
15
|
+
try {
|
|
16
|
+
const parsed = JSON.parse(outcome);
|
|
17
|
+
const stop = parsed.budgetStop;
|
|
18
|
+
if (stop?.schemaVersion === 1 &&
|
|
19
|
+
typeof stop.reason === 'string' &&
|
|
20
|
+
Number.isSafeInteger(stop.llmRequests?.current) &&
|
|
21
|
+
Number.isSafeInteger(stop.toolCalls?.current)) {
|
|
22
|
+
return stop;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// Outcomes from other Thread runners need not use the agent-loop format.
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
10
30
|
/**
|
|
11
31
|
* Transitional projection from the durable Thread runtime to existing UI
|
|
12
32
|
* contracts. ThreadRuntime remains the sole owner of turn/item state; this
|
|
@@ -110,7 +130,16 @@ class ThreadUiAdapterV1 {
|
|
|
110
130
|
async runTurn(input, mode, options) {
|
|
111
131
|
this.assertOpen();
|
|
112
132
|
throwIfAborted(options.abortSignal);
|
|
113
|
-
const
|
|
133
|
+
const pending = options.followup;
|
|
134
|
+
// Maintenance reports a terminal fact before releasing the execution
|
|
135
|
+
// lease. The pending input must wait for that release before handoff.
|
|
136
|
+
const admission = pending
|
|
137
|
+
? await this.admitPendingFollowup(pending, input, mode, options.abortSignal)
|
|
138
|
+
: this.runtime.dispatch({ type: 'turn.start', data: { input, mode } });
|
|
139
|
+
if (admission.status === 'already_admitted') {
|
|
140
|
+
pending?.onAdmitted();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
114
143
|
if (admission.status === 'rejected') {
|
|
115
144
|
throw new ThreadUiAdmissionError(admission.reason);
|
|
116
145
|
}
|
|
@@ -119,12 +148,23 @@ class ThreadUiAdapterV1 {
|
|
|
119
148
|
}
|
|
120
149
|
const detachAbort = forwardAbort(options.abortSignal, reason => this.interrupt(reason));
|
|
121
150
|
try {
|
|
151
|
+
pending?.onAdmitted();
|
|
122
152
|
await this.waitForIdleAndFlush();
|
|
123
153
|
}
|
|
124
154
|
finally {
|
|
125
155
|
detachAbort();
|
|
126
156
|
}
|
|
127
157
|
}
|
|
158
|
+
async admitPendingFollowup(pending, input, mode, signal) {
|
|
159
|
+
if (mode === 'goal')
|
|
160
|
+
throw new ThreadUiAdapterError('A pending follow-up must be user input.');
|
|
161
|
+
await this.runtime.waitForIdle();
|
|
162
|
+
this.assertOpen();
|
|
163
|
+
throwIfAborted(signal);
|
|
164
|
+
if (!pending.isPending())
|
|
165
|
+
throw new ThreadUiAdmissionError('pending follow-up changed');
|
|
166
|
+
return this.runtime.startPendingFollowup(pending.id, input, mode);
|
|
167
|
+
}
|
|
128
168
|
async waitForIdleAndFlush() {
|
|
129
169
|
let idle = false;
|
|
130
170
|
const idlePromise = this.runtime.waitForIdle().finally(() => {
|
|
@@ -199,14 +239,27 @@ class ThreadUiAdapterV1 {
|
|
|
199
239
|
case 'turn.interrupt_requested':
|
|
200
240
|
this.emit({ type: 'status_changed', message: 'Interrupt requested…' });
|
|
201
241
|
return;
|
|
202
|
-
case 'turn.completed':
|
|
242
|
+
case 'turn.completed': {
|
|
203
243
|
this.emit({ type: 'processing_changed', processing: false });
|
|
244
|
+
const budgetStop = budgetStopFromOutcome(event.payload.data.outcome);
|
|
245
|
+
if (budgetStop) {
|
|
246
|
+
this.emit({
|
|
247
|
+
type: 'transcript_append',
|
|
248
|
+
entry: {
|
|
249
|
+
role: 'status',
|
|
250
|
+
title: 'execution budget',
|
|
251
|
+
content: (0, ui_view_model_1.formatLoopBudgetStopView)(budgetStop),
|
|
252
|
+
budgetStop,
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
}
|
|
204
256
|
this.emit({
|
|
205
257
|
type: 'status_changed',
|
|
206
|
-
message: event.payload.data.outcome?.trim() || 'Ready',
|
|
258
|
+
message: budgetStop?.reason ?? (event.payload.data.outcome?.trim() || 'Ready'),
|
|
207
259
|
});
|
|
208
260
|
this.projectCompletedPlanMode(event);
|
|
209
261
|
return;
|
|
262
|
+
}
|
|
210
263
|
case 'turn.failed':
|
|
211
264
|
this.emit({
|
|
212
265
|
type: 'transcript_append',
|
|
@@ -285,17 +338,6 @@ class ThreadUiAdapterV1 {
|
|
|
285
338
|
}
|
|
286
339
|
projectGoalCommit(receipt) {
|
|
287
340
|
const persistence = (0, goal_runtime_coordinator_1.readGoalRuntimePersistenceV2)((0, turn_commit_1.parseTurnCommitV1)(receipt));
|
|
288
|
-
if (persistence.state?.status === 'completed') {
|
|
289
|
-
this.emit({
|
|
290
|
-
type: 'goal_event',
|
|
291
|
-
event: {
|
|
292
|
-
type: 'goal_cleared',
|
|
293
|
-
goalId: persistence.state.goalId,
|
|
294
|
-
reason: 'completion_auto_exit',
|
|
295
|
-
},
|
|
296
|
-
});
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
341
|
if (persistence.state) {
|
|
300
342
|
this.emit({
|
|
301
343
|
type: 'goal_event',
|
|
@@ -332,17 +374,19 @@ class ThreadUiAdapterV1 {
|
|
|
332
374
|
role: data.role,
|
|
333
375
|
name: data.name?.trim() || defaultItemName(data.kind),
|
|
334
376
|
args: data.inputDigest ? { inputDigest: data.inputDigest } : {},
|
|
377
|
+
command: (0, tool_transcript_entry_1.toolCommandFromIntent)(data.intent),
|
|
335
378
|
sequence: event.seq,
|
|
336
379
|
startedAt: event.timestamp,
|
|
337
380
|
content: '',
|
|
338
381
|
};
|
|
339
|
-
if (
|
|
382
|
+
if ((0, tool_transcript_entry_1.isToolTranscriptItem)(presentation.kind)) {
|
|
340
383
|
this.emit({
|
|
341
384
|
type: 'tool_started',
|
|
342
385
|
event: {
|
|
343
386
|
callId: presentation.itemId,
|
|
344
387
|
name: presentation.name,
|
|
345
388
|
args: presentation.args,
|
|
389
|
+
...(presentation.command ? { command: presentation.command } : {}),
|
|
346
390
|
sequence: presentation.sequence,
|
|
347
391
|
},
|
|
348
392
|
});
|
|
@@ -362,7 +406,7 @@ class ThreadUiAdapterV1 {
|
|
|
362
406
|
return;
|
|
363
407
|
const presentation = this.ensurePresentation(event);
|
|
364
408
|
presentation.content += event.payload.data.delta;
|
|
365
|
-
if (!
|
|
409
|
+
if (!(0, tool_transcript_entry_1.isToolTranscriptItem)(presentation.kind) && presentation.transcriptId) {
|
|
366
410
|
this.emit({
|
|
367
411
|
type: 'transcript_update',
|
|
368
412
|
id: presentation.transcriptId,
|
|
@@ -373,16 +417,25 @@ class ThreadUiAdapterV1 {
|
|
|
373
417
|
finishItem(event) {
|
|
374
418
|
const presentation = this.ensurePresentation(event);
|
|
375
419
|
const terminal = terminalItemData(event);
|
|
376
|
-
|
|
420
|
+
// The compact item owns a durable receipt. Its short summary keeps the
|
|
421
|
+
// preceding result or budget pause visible in an interactive transcript.
|
|
422
|
+
if (presentation.kind === 'compact' && terminal.summary) {
|
|
423
|
+
presentation.content = terminal.summary;
|
|
424
|
+
}
|
|
425
|
+
else if (terminal.content !== undefined) {
|
|
377
426
|
presentation.content = terminal.content;
|
|
427
|
+
}
|
|
378
428
|
if (!presentation.content && terminal.summary)
|
|
379
429
|
presentation.content = terminal.summary;
|
|
380
|
-
if (
|
|
430
|
+
if ((0, tool_transcript_entry_1.isToolTranscriptItem)(presentation.kind)) {
|
|
381
431
|
const durableReceiptFact = this.toolReceiptFacts.get(presentation.itemId);
|
|
382
432
|
let receipt;
|
|
383
433
|
const hasTerminalReceipt = terminal.receipt !== undefined;
|
|
384
434
|
const hasDurableReceiptFact = durableReceiptFact !== undefined;
|
|
385
|
-
|
|
435
|
+
// A torn journal batch can leave a receipt fact without its terminal
|
|
436
|
+
// pair. Recovery publishes an indeterminate Item, never a receipt.
|
|
437
|
+
const abandonedReceipt = event.payload.type === 'item.indeterminate' && !hasTerminalReceipt;
|
|
438
|
+
if (!abandonedReceipt && hasTerminalReceipt !== hasDurableReceiptFact) {
|
|
386
439
|
throw new ThreadUiAdapterError(hasTerminalReceipt
|
|
387
440
|
? `Tool item ${presentation.itemId} has a canonical receipt without its durable receipt fact.`
|
|
388
441
|
: `Tool item ${presentation.itemId} has a durable receipt fact without its canonical terminal receipt.`);
|
|
@@ -410,6 +463,7 @@ class ThreadUiAdapterV1 {
|
|
|
410
463
|
callId: presentation.itemId,
|
|
411
464
|
name: presentation.name,
|
|
412
465
|
args: presentation.args,
|
|
466
|
+
...(presentation.command ? { command: presentation.command } : {}),
|
|
413
467
|
success,
|
|
414
468
|
duration: Math.max(0, event.timestamp - presentation.startedAt),
|
|
415
469
|
sequence: presentation.sequence,
|
|
@@ -427,6 +481,20 @@ class ThreadUiAdapterV1 {
|
|
|
427
481
|
: {}),
|
|
428
482
|
},
|
|
429
483
|
});
|
|
484
|
+
this.emit({
|
|
485
|
+
type: 'transcript_append',
|
|
486
|
+
entry: {
|
|
487
|
+
...(0, tool_transcript_entry_1.toolTranscriptEntry)({
|
|
488
|
+
callId: presentation.itemId,
|
|
489
|
+
sequence: presentation.sequence,
|
|
490
|
+
name: presentation.name,
|
|
491
|
+
success,
|
|
492
|
+
command: presentation.command,
|
|
493
|
+
output: presentation.content || terminal.error,
|
|
494
|
+
}),
|
|
495
|
+
live: false,
|
|
496
|
+
},
|
|
497
|
+
});
|
|
430
498
|
}
|
|
431
499
|
else if (presentation.transcriptId) {
|
|
432
500
|
const success = event.payload.type === 'item.completed';
|
|
@@ -472,6 +540,7 @@ class ThreadUiAdapterV1 {
|
|
|
472
540
|
...(isItemRole(projected.role) ? { role: projected.role } : {}),
|
|
473
541
|
...(projected.name ? { name: projected.name } : {}),
|
|
474
542
|
...(projected.inputDigest ? { inputDigest: projected.inputDigest } : {}),
|
|
543
|
+
...(projected.intent ? { intent: projected.intent } : {}),
|
|
475
544
|
},
|
|
476
545
|
},
|
|
477
546
|
});
|
|
@@ -518,6 +587,7 @@ function goalUiSnapshot(state) {
|
|
|
518
587
|
? 'blocked'
|
|
519
588
|
: state.status,
|
|
520
589
|
tokenBudget: state.budget.maxTokens,
|
|
590
|
+
timeBudgetMs: state.budget.maxElapsedMs,
|
|
521
591
|
tokensUsed: state.tokensUsed,
|
|
522
592
|
timeUsedMs: state.elapsedMs,
|
|
523
593
|
continuationCount: state.continuationCount,
|
|
@@ -570,9 +640,6 @@ function transcriptTitle(presentation) {
|
|
|
570
640
|
return presentation.name;
|
|
571
641
|
}
|
|
572
642
|
}
|
|
573
|
-
function isToolItem(kind) {
|
|
574
|
-
return kind === 'command' || kind === 'file_change' || kind === 'mcp';
|
|
575
|
-
}
|
|
576
643
|
function defaultItemName(kind) {
|
|
577
644
|
switch (kind) {
|
|
578
645
|
case 'file_change':
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ToolContext, ToolResult } from '../framework/tool';
|
|
2
|
+
import type { TaskToolRecoveryBindingV1 } from './task-context-recovery';
|
|
2
3
|
import { ExecutionService, type BoundToolExecutionResultV1, type StepSnapshotV1, type ToolBindingDescriptorV1 } from './step-snapshot';
|
|
3
4
|
export type ToolPolicyBehaviorV1 = 'allow' | 'ask' | 'deny';
|
|
4
5
|
export type ToolTerminalV1 = 'completed' | 'failed' | 'interrupted' | 'indeterminate';
|
|
@@ -10,6 +11,9 @@ export interface ToolInvocationV1 {
|
|
|
10
11
|
readonly args: Readonly<Record<string, unknown>>;
|
|
11
12
|
readonly context: ToolContext;
|
|
12
13
|
readonly abortSignal?: AbortSignal;
|
|
14
|
+
/** Workflow prerequisites are recoverable tool failures, independent of approval. */
|
|
15
|
+
readonly prerequisiteFailure?: string;
|
|
16
|
+
readonly taskRecovery?: TaskToolRecoveryBindingV1;
|
|
13
17
|
}
|
|
14
18
|
export interface ToolPolicyDecisionV1 {
|
|
15
19
|
readonly behavior: ToolPolicyBehaviorV1;
|
|
@@ -38,6 +42,7 @@ export interface ToolPolicyServiceV1 {
|
|
|
38
42
|
}
|
|
39
43
|
export interface ToolApprovalServiceV1 {
|
|
40
44
|
decide(input: {
|
|
45
|
+
readonly invocationId?: string;
|
|
41
46
|
readonly snapshot: StepSnapshotV1;
|
|
42
47
|
readonly descriptor: ToolBindingDescriptorV1;
|
|
43
48
|
readonly args: Readonly<Record<string, unknown>>;
|
|
@@ -64,6 +69,8 @@ export interface ToolInvocationIntentV1 {
|
|
|
64
69
|
readonly snapshotDigest: string;
|
|
65
70
|
readonly argsDigest: string;
|
|
66
71
|
readonly requestDigest: string;
|
|
72
|
+
readonly displayCommand?: string;
|
|
73
|
+
readonly taskRecovery?: TaskToolRecoveryBindingV1;
|
|
67
74
|
readonly startedAt: number;
|
|
68
75
|
readonly digest: string;
|
|
69
76
|
}
|
|
@@ -88,6 +95,8 @@ export interface ToolInvocationReceiptV1 {
|
|
|
88
95
|
readonly success: boolean;
|
|
89
96
|
readonly result: ToolResult;
|
|
90
97
|
readonly outputDigest: string;
|
|
98
|
+
/** Runtime-captured workspace identity for this local verification result. */
|
|
99
|
+
readonly verificationWorkspace?: string | null;
|
|
91
100
|
readonly startedAt: number;
|
|
92
101
|
readonly finishedAt: number;
|
|
93
102
|
readonly durationMs: number;
|