@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
|
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ContextHarness = exports.HarnessKernel = void 0;
|
|
4
4
|
exports.createHarnessKernel = createHarnessKernel;
|
|
5
5
|
exports.createContextHarness = createContextHarness;
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const redaction_1 = require("../services/redaction");
|
|
9
|
+
const tool_serializer_1 = require("../framework/tool-serializer");
|
|
10
|
+
const verification_command_1 = require("../framework/verification-command");
|
|
6
11
|
const assembler_1 = require("./assembler");
|
|
7
12
|
const capability_profile_1 = require("./capability-profile");
|
|
8
13
|
const capsule_1 = require("./capsule");
|
|
@@ -14,6 +19,7 @@ const ledger_1 = require("./ledger");
|
|
|
14
19
|
const progress_controller_1 = require("./progress-controller");
|
|
15
20
|
const state_1 = require("./state");
|
|
16
21
|
const stop_controller_1 = require("./stop-controller");
|
|
22
|
+
const task_checklist_1 = require("./task-checklist");
|
|
17
23
|
const turn_summary_1 = require("./turn-summary");
|
|
18
24
|
const verification_1 = require("./verification");
|
|
19
25
|
const DEFAULT_CONFIG = {
|
|
@@ -31,12 +37,30 @@ class HarnessKernel {
|
|
|
31
37
|
this.cwd = options.cwd;
|
|
32
38
|
this.modelId = options.modelId;
|
|
33
39
|
this.config = { ...DEFAULT_CONFIG, ...options.config };
|
|
40
|
+
this.requireLocalVerificationReceipt = options.requireLocalVerificationReceipt === true;
|
|
34
41
|
const state = (0, state_1.upgradeHarnessState)(options.state, { cwd: options.cwd });
|
|
35
42
|
this.contract = state.contract;
|
|
36
|
-
this.ledger = new ledger_1.ContextLedger(state.ledger);
|
|
43
|
+
this.ledger = new ledger_1.ContextLedger(state.ledger, state.workspaceRevision);
|
|
44
|
+
this.verificationWorkspace = state.verificationWorkspace;
|
|
37
45
|
this.capsule = state.capsule;
|
|
38
46
|
this.completionBlockCount = state.completionBlockCount ?? 0;
|
|
39
47
|
this.taskEpoch = state.taskEpoch ?? 1;
|
|
48
|
+
this.goalTaskId = state.goalTaskId;
|
|
49
|
+
const restoredChanges = (0, task_checklist_1.requestedWorkspaceChanges)(state.activeInstruction ?? this.contract?.userIntent ?? '');
|
|
50
|
+
this.taskChecklistRequired = state.taskChecklistRequired ?? restoredChanges.checklistRequired;
|
|
51
|
+
this.taskChecklistTargets =
|
|
52
|
+
state.taskChecklistTargets ?? (0, task_checklist_1.workspaceChangeTargets)(this.cwd, restoredChanges.paths);
|
|
53
|
+
const todos = (state.taskTodos ?? []).map(saved => withTodoVerification(saved, saved.id ?? this.taskTodoId(saved.content), saved));
|
|
54
|
+
const byDescription = new Map(todos.map(todo => [todo.content, todo.id]));
|
|
55
|
+
this.taskTodoReceipts = (state.taskTodoReceipts ?? []).map(([savedId, ...receipt]) => [
|
|
56
|
+
byDescription.get(savedId) ?? savedId,
|
|
57
|
+
...receipt,
|
|
58
|
+
]);
|
|
59
|
+
this.taskTodos = todos.map(todo => {
|
|
60
|
+
return todo.status === 'completed' && this.missingTodoEvidence(todo)
|
|
61
|
+
? { ...todo, status: 'pending' }
|
|
62
|
+
: todo;
|
|
63
|
+
});
|
|
40
64
|
this.rootObjective = state.rootObjective;
|
|
41
65
|
this.activeInstruction = state.activeInstruction;
|
|
42
66
|
this.intentHistory = state.intentHistory ?? [];
|
|
@@ -56,14 +80,62 @@ class HarnessKernel {
|
|
|
56
80
|
this.reconciledAt = state.reconciledAt;
|
|
57
81
|
this.updatedAt = state.updatedAt;
|
|
58
82
|
}
|
|
59
|
-
updateContractFromUserInput(input) {
|
|
83
|
+
updateContractFromUserInput(input, goalTaskId) {
|
|
84
|
+
this.reportedTaskBlocker = undefined;
|
|
60
85
|
if (this.config.enabled === false)
|
|
61
86
|
return;
|
|
62
|
-
|
|
87
|
+
if (goalTaskId && this.goalTaskId === goalTaskId && this.contract)
|
|
88
|
+
return;
|
|
89
|
+
const deferral = (0, task_checklist_1.requestedTaskDeferral)(input);
|
|
90
|
+
if (deferral &&
|
|
91
|
+
this.goalTaskId === goalTaskId &&
|
|
92
|
+
this.taskTodos.some(todo => todo.status !== 'completed')) {
|
|
93
|
+
this.deferTaskTodos(deferral);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const classified = (0, intent_1.classifyIntent)(input, this.toJSON());
|
|
97
|
+
const ownerChanged = this.goalTaskId !== goalTaskId;
|
|
98
|
+
const intent = ownerChanged
|
|
99
|
+
? {
|
|
100
|
+
...classified,
|
|
101
|
+
kind: 'new_task',
|
|
102
|
+
rootObjectiveChanged: true,
|
|
103
|
+
reason: 'explicit Goal task boundary',
|
|
104
|
+
confidence: 1,
|
|
105
|
+
taskEpoch: this.contract ? this.taskEpoch + 1 : classified.taskEpoch,
|
|
106
|
+
}
|
|
107
|
+
: classified;
|
|
63
108
|
this.contract = this.contract
|
|
64
109
|
? (0, contract_1.updateTaskContract)(this.contract, input, this.cwd, intent)
|
|
65
110
|
: (0, contract_1.createTaskContract)(input, this.cwd);
|
|
111
|
+
this.goalTaskId = goalTaskId;
|
|
112
|
+
if (intent.taskEpoch !== this.taskEpoch) {
|
|
113
|
+
this.taskChecklistRequired = false;
|
|
114
|
+
this.taskChecklistTargets = [];
|
|
115
|
+
this.taskTodos = [];
|
|
116
|
+
this.taskTodoReceipts.length = 0;
|
|
117
|
+
this.completionBlockCount = 0;
|
|
118
|
+
this.activeConstraints = [];
|
|
119
|
+
this.nonGoals = [];
|
|
120
|
+
this.openQuestions = [];
|
|
121
|
+
}
|
|
122
|
+
else if (intent.kind === 'continue_current_task' &&
|
|
123
|
+
this.taskTodos.some(todo => todo.deferredReason)) {
|
|
124
|
+
this.taskTodos = this.taskTodos.map(todo => ({ ...todo, deferredReason: undefined }));
|
|
125
|
+
}
|
|
66
126
|
this.taskEpoch = intent.taskEpoch;
|
|
127
|
+
const changes = (0, task_checklist_1.requestedWorkspaceChanges)(input);
|
|
128
|
+
this.taskChecklistRequired || (this.taskChecklistRequired = changes.checklistRequired);
|
|
129
|
+
const previousTargets = this.taskChecklistTargets;
|
|
130
|
+
this.taskChecklistTargets = (0, task_checklist_1.workspaceChangeTargets)(this.cwd, [
|
|
131
|
+
...previousTargets,
|
|
132
|
+
...changes.paths,
|
|
133
|
+
]);
|
|
134
|
+
if (intent.kind !== 'new_task' &&
|
|
135
|
+
this.taskChecklistTargets.some(target => !previousTargets.includes(target)) &&
|
|
136
|
+
this.hasCurrentWorkspaceVerification(true)) {
|
|
137
|
+
this.invalidateUnboundVerification();
|
|
138
|
+
}
|
|
67
139
|
if (intent.rootObjectiveChanged || !this.rootObjective) {
|
|
68
140
|
this.rootObjective = this.contract.objective;
|
|
69
141
|
}
|
|
@@ -82,6 +154,219 @@ class HarnessKernel {
|
|
|
82
154
|
classifyIntent(input) {
|
|
83
155
|
return (0, intent_1.classifyIntent)(input, this.toJSON());
|
|
84
156
|
}
|
|
157
|
+
activeTaskTodo() {
|
|
158
|
+
return this.taskTodos.find(todo => todo.status === 'in_progress' && !todo.deferredReason)?.id;
|
|
159
|
+
}
|
|
160
|
+
hasTaskTodos() {
|
|
161
|
+
return this.taskTodos.length > 0;
|
|
162
|
+
}
|
|
163
|
+
missingExecutionChecklist(action) {
|
|
164
|
+
if (this.hasOnlyDeferredWork()) {
|
|
165
|
+
return 'The user deferred the remaining steps. Wait for explicit continuation.';
|
|
166
|
+
}
|
|
167
|
+
if (action && this.taskTodos.some(todo => todo.deferredReason)) {
|
|
168
|
+
const scoped = this.checkDeferredWorkspaceAction(action);
|
|
169
|
+
if (scoped)
|
|
170
|
+
return scoped;
|
|
171
|
+
}
|
|
172
|
+
if (!this.taskChecklistRequired)
|
|
173
|
+
return undefined;
|
|
174
|
+
return (0, task_checklist_1.executionChecklistIssue)(this.taskTodos, this.taskChecklistTargets, this.cwd);
|
|
175
|
+
}
|
|
176
|
+
checkDeferredWorkspaceAction(action) {
|
|
177
|
+
const target = action.path ? (0, verification_1.workspaceArtifactPath)(this.cwd, action.path) : undefined;
|
|
178
|
+
if (target) {
|
|
179
|
+
const covering = this.taskTodos.filter(todo => (0, task_checklist_1.workspaceChangeTargets)(this.cwd, (0, task_checklist_1.requestedWorkspaceChanges)(todo.content).paths).includes(target));
|
|
180
|
+
return covering.length > 0 && covering.every(todo => todo.deferredReason)
|
|
181
|
+
? `The user deferred the checklist step that changes ${target}.`
|
|
182
|
+
: undefined;
|
|
183
|
+
}
|
|
184
|
+
const active = this.taskTodos.find(todo => todo.status === 'in_progress');
|
|
185
|
+
const kind = action.command ? (0, verification_command_1.classifyDirectVerificationCommand)(action.command) : undefined;
|
|
186
|
+
if (active && (0, verification_command_1.isLocalVerificationKind)(kind) && active.verification?.includes(kind)) {
|
|
187
|
+
const expected = todoChecks(active.content).filter(check => check.kind === kind);
|
|
188
|
+
if (!expected.length ||
|
|
189
|
+
expected.some(check => matchesTodoCheck({ ...action, kind }, check, this.cwd)))
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
return 'The user deferred part of the checklist. Use a file tool for the active step or run its required check before making other workspace changes.';
|
|
193
|
+
}
|
|
194
|
+
prepareTaskPlanStopCheck() {
|
|
195
|
+
return () => {
|
|
196
|
+
if (this.hasOnlyDeferredWork()) {
|
|
197
|
+
return {
|
|
198
|
+
code: 'task_deferred',
|
|
199
|
+
message: 'The remaining checklist steps are deferred at your request. Say “continue” to resume them.',
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
const blocker = this.reportedTaskBlocker;
|
|
203
|
+
this.reportedTaskBlocker = undefined;
|
|
204
|
+
return blocker;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
hasOnlyDeferredWork() {
|
|
208
|
+
return (this.taskTodos.some(todo => todo.deferredReason) &&
|
|
209
|
+
this.taskTodos.every(todo => todo.deferredReason || todo.status === 'completed'));
|
|
210
|
+
}
|
|
211
|
+
deferTaskTodos(scope) {
|
|
212
|
+
const selected = scope === 'first'
|
|
213
|
+
? this.taskTodos[0]
|
|
214
|
+
: scope === 'current'
|
|
215
|
+
? (this.taskTodos.find(todo => todo.status === 'in_progress') ??
|
|
216
|
+
this.taskTodos.find(todo => todo.status !== 'completed'))
|
|
217
|
+
: undefined;
|
|
218
|
+
this.taskTodos = this.taskTodos.map(todo => {
|
|
219
|
+
if (todo.status === 'completed')
|
|
220
|
+
return todo;
|
|
221
|
+
return todo === selected
|
|
222
|
+
? { ...todo, status: 'in_progress', deferredReason: undefined }
|
|
223
|
+
: { ...todo, status: 'pending', deferredReason: 'Deferred by user request' };
|
|
224
|
+
});
|
|
225
|
+
this.refreshCapsule();
|
|
226
|
+
this.touch();
|
|
227
|
+
}
|
|
228
|
+
requiresVerification() {
|
|
229
|
+
if (this.config.enabled === false ||
|
|
230
|
+
(this.config.completionGate !== 'block' && this.config.completionGate !== true))
|
|
231
|
+
return false;
|
|
232
|
+
return (this.contract?.criteria?.some(item => (0, verification_1.requiredVerificationKinds)(item.statement).length > 0) ||
|
|
233
|
+
(0, drift_guard_1.hasExplicitVerificationNeed)(this.contract));
|
|
234
|
+
}
|
|
235
|
+
recordTaskTodoReceipt(step, observation) {
|
|
236
|
+
const todo = this.taskTodos.find(item => item.status === 'in_progress');
|
|
237
|
+
if (todo?.id !== step)
|
|
238
|
+
return;
|
|
239
|
+
const { digest, kind, passed, changedFile, command, cwd } = observation;
|
|
240
|
+
if (this.taskTodoReceipts.some(([, recordedDigest]) => recordedDigest === digest))
|
|
241
|
+
return;
|
|
242
|
+
const required = todo.verification ?? [];
|
|
243
|
+
let evidence;
|
|
244
|
+
if (required.length) {
|
|
245
|
+
if (!kind || !required.includes(kind))
|
|
246
|
+
return;
|
|
247
|
+
const requested = todoChecks(todo.content).filter(check => check.kind === kind);
|
|
248
|
+
if (requested.length &&
|
|
249
|
+
!requested.some(check => matchesTodoCheck(observation, check, this.cwd)))
|
|
250
|
+
return;
|
|
251
|
+
evidence = {
|
|
252
|
+
kind,
|
|
253
|
+
passed,
|
|
254
|
+
workspaceRevision: this.ledger.workspaceRevision,
|
|
255
|
+
...(requested.length ? { command, cwd: (0, path_1.resolve)(this.cwd, cwd ?? '.') } : {}),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
else if ((0, task_checklist_1.isImplementationTodo)(todo)) {
|
|
259
|
+
if (!passed || !changedFile)
|
|
260
|
+
return;
|
|
261
|
+
const path = (0, verification_1.workspaceArtifactPath)(this.cwd, changedFile);
|
|
262
|
+
const targets = (0, task_checklist_1.workspaceChangeTargets)(this.cwd, (0, task_checklist_1.requestedWorkspaceChanges)(todo.content).paths);
|
|
263
|
+
if (!path || (targets.length && !targets.includes(path)))
|
|
264
|
+
return;
|
|
265
|
+
evidence = { changedFile: path };
|
|
266
|
+
}
|
|
267
|
+
else if (!passed) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const index = this.taskTodoReceipts.findIndex(([name, , previous]) => name === step && sameTodoEvidenceTarget(previous, evidence));
|
|
271
|
+
if (index < 0) {
|
|
272
|
+
this.taskTodoReceipts.push(evidence ? [step, digest, evidence] : [step, digest]);
|
|
273
|
+
}
|
|
274
|
+
else if (evidence && 'kind' in evidence) {
|
|
275
|
+
this.taskTodoReceipts[index] = [step, digest, evidence];
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
this.touch();
|
|
281
|
+
}
|
|
282
|
+
updateTaskTodos(todos, blockedReason) {
|
|
283
|
+
const previousTodos = new Map(this.taskTodos.map(todo => [todo.content, todo]));
|
|
284
|
+
const next = new Map(todos.map(todo => {
|
|
285
|
+
const previous = previousTodos.get(todo.content);
|
|
286
|
+
return [
|
|
287
|
+
todo.content,
|
|
288
|
+
withTodoVerification(todo, previous?.id ?? this.taskTodoId(todo.content), previous),
|
|
289
|
+
];
|
|
290
|
+
}));
|
|
291
|
+
if (next.size !== todos.length)
|
|
292
|
+
return 'Todo descriptions must be unique.';
|
|
293
|
+
if (this.taskTodos.some(todo => todo.deferredReason) && next.size > previousTodos.size) {
|
|
294
|
+
return 'The user deferred part of the checklist. Wait for their continuation before adding steps.';
|
|
295
|
+
}
|
|
296
|
+
for (const previous of this.taskTodos) {
|
|
297
|
+
const replacement = next.get(previous.content);
|
|
298
|
+
if (!replacement)
|
|
299
|
+
return `Keep the existing todo "${previous.content}" in the checklist.`;
|
|
300
|
+
if (previous.deferredReason && replacement.status !== 'pending') {
|
|
301
|
+
return `The user deferred "${previous.content}". Keep it pending until they explicitly continue.`;
|
|
302
|
+
}
|
|
303
|
+
if (previous.status === 'completed' && replacement.status !== 'completed') {
|
|
304
|
+
return `Add a new todo for further work on "${previous.content}".`;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
for (const todo of next.values()) {
|
|
308
|
+
if (todo.status !== 'completed')
|
|
309
|
+
continue;
|
|
310
|
+
const missing = this.missingTodoEvidence(todo);
|
|
311
|
+
if (missing)
|
|
312
|
+
return missing;
|
|
313
|
+
}
|
|
314
|
+
if (blockedReason !== undefined) {
|
|
315
|
+
const active = [...next.values()].find(todo => todo.status === 'in_progress');
|
|
316
|
+
if (!active || !blockedReason.trim())
|
|
317
|
+
return 'Report the blocker on an active todo.';
|
|
318
|
+
this.reportedTaskBlocker = {
|
|
319
|
+
code: 'task_step_blocked',
|
|
320
|
+
message: `Blocked at “${active.content}”. ${(0, redaction_1.redactTraceText)(blockedReason.trim())}`,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
this.taskTodos = [...next.values()];
|
|
324
|
+
this.touch();
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
327
|
+
taskTodoId(content) {
|
|
328
|
+
return (0, crypto_1.createHash)('sha256')
|
|
329
|
+
.update(JSON.stringify([this.contract?.id, this.taskEpoch, content]))
|
|
330
|
+
.digest('hex')
|
|
331
|
+
.slice(0, 24);
|
|
332
|
+
}
|
|
333
|
+
missingTodoEvidence(todo) {
|
|
334
|
+
const receipts = this.taskTodoReceipts.filter(([step]) => step === todo.id);
|
|
335
|
+
if (todo.verification?.length) {
|
|
336
|
+
const expected = todoChecks(todo.content);
|
|
337
|
+
const verified = receipts.flatMap(([, , result]) => result &&
|
|
338
|
+
'kind' in result &&
|
|
339
|
+
result.passed &&
|
|
340
|
+
result.workspaceRevision === this.ledger.workspaceRevision
|
|
341
|
+
? [result]
|
|
342
|
+
: []);
|
|
343
|
+
const missing = todo.verification.flatMap(kind => {
|
|
344
|
+
const selectors = expected.filter(check => check.kind === kind);
|
|
345
|
+
if (selectors.length) {
|
|
346
|
+
return selectors
|
|
347
|
+
.filter(check => !verified.some(result => matchesTodoCheck(result, check, this.cwd)))
|
|
348
|
+
.map(check => check.command);
|
|
349
|
+
}
|
|
350
|
+
return verified.some(result => result.kind === kind) ? [] : [kind];
|
|
351
|
+
});
|
|
352
|
+
if (missing.length === 0)
|
|
353
|
+
return undefined;
|
|
354
|
+
return `Keep "${todo.content}" open until its required checks pass: ${missing.join(', ')}. Run each check directly with exec_command while this todo is in progress.`;
|
|
355
|
+
}
|
|
356
|
+
if ((0, task_checklist_1.isImplementationTodo)(todo)) {
|
|
357
|
+
const changedFiles = new Set(receipts.flatMap(([, , result]) => result && 'changedFile' in result ? [result.changedFile] : []));
|
|
358
|
+
const targets = (0, task_checklist_1.workspaceChangeTargets)(this.cwd, (0, task_checklist_1.requestedWorkspaceChanges)(todo.content).paths);
|
|
359
|
+
const remaining = targets.filter(target => !changedFiles.has(target));
|
|
360
|
+
if (remaining.length)
|
|
361
|
+
return `Keep "${todo.content}" open until there are verified file changes for: ${remaining.join(', ')}.`;
|
|
362
|
+
if (changedFiles.size)
|
|
363
|
+
return undefined;
|
|
364
|
+
return `Keep "${todo.content}" open until a successful workspace change is recorded for that step.`;
|
|
365
|
+
}
|
|
366
|
+
if (receipts.some(([, , result]) => !result))
|
|
367
|
+
return undefined;
|
|
368
|
+
return `Keep "${todo.content}" open until a successful tool receipt is recorded for that step.`;
|
|
369
|
+
}
|
|
85
370
|
updateCapabilityProfile(input) {
|
|
86
371
|
if (this.config.enabled === false)
|
|
87
372
|
return this.capabilityProfile;
|
|
@@ -173,11 +458,92 @@ class HarnessKernel {
|
|
|
173
458
|
recordToolResult(params) {
|
|
174
459
|
if (this.config.enabled === false)
|
|
175
460
|
return;
|
|
176
|
-
const entry = this.ledger.recordToolResult(params);
|
|
461
|
+
const entry = this.ledger.recordToolResult(params, this.requireLocalVerificationReceipt, this.contract?.id);
|
|
462
|
+
if (entry.metadata?.changedFile)
|
|
463
|
+
this.invalidateVerificationAfterWrite();
|
|
464
|
+
this.recordTaskStepAttempt(params);
|
|
177
465
|
this.autoLinkVerificationEvidence(entry);
|
|
466
|
+
this.autoLinkArtifactReadback(entry, params);
|
|
178
467
|
this.refreshCapsule();
|
|
179
468
|
this.touch();
|
|
180
469
|
}
|
|
470
|
+
recordTaskStepAttempt(params) {
|
|
471
|
+
if (!params.toolReceiptDigest)
|
|
472
|
+
return;
|
|
473
|
+
const index = this.taskTodos.findIndex(todo => todo.status === 'in_progress' && !todo.deferredReason);
|
|
474
|
+
if (index < 0)
|
|
475
|
+
return;
|
|
476
|
+
const step = this.taskTodos[index];
|
|
477
|
+
const previous = step.recovery;
|
|
478
|
+
if (params.success) {
|
|
479
|
+
if (previous?.consecutiveFailures &&
|
|
480
|
+
this.taskTodoReceipts.some(([id, receipt]) => id === step.id && receipt === params.toolReceiptDigest)) {
|
|
481
|
+
this.taskTodos[index] = {
|
|
482
|
+
...step,
|
|
483
|
+
recovery: { ...previous, consecutiveFailures: 0, strategies: [] },
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
// Track actual attempted work. Read-only probes have their own loop progress policy.
|
|
489
|
+
if (!params.verification &&
|
|
490
|
+
params.name !== 'edit_file' &&
|
|
491
|
+
params.name !== 'write_file' &&
|
|
492
|
+
(params.name !== 'exec_command' || params.readOnly !== false))
|
|
493
|
+
return;
|
|
494
|
+
const args = Object.entries(params.args).sort(([left], [right]) => left.localeCompare(right));
|
|
495
|
+
const strategy = (0, crypto_1.createHash)('sha256')
|
|
496
|
+
.update(JSON.stringify([params.name, args]))
|
|
497
|
+
.digest('hex')
|
|
498
|
+
.slice(0, 16);
|
|
499
|
+
this.taskTodos[index] = {
|
|
500
|
+
...step,
|
|
501
|
+
recovery: {
|
|
502
|
+
failures: (previous?.failures ?? 0) + 1,
|
|
503
|
+
consecutiveFailures: (previous?.consecutiveFailures ?? 0) + 1,
|
|
504
|
+
strategies: [...new Set([...(previous?.strategies ?? []), strategy])].slice(-task_checklist_1.TASK_RECOVERY_STRATEGY_HISTORY_LIMIT),
|
|
505
|
+
lastFailure: params.verification
|
|
506
|
+
? `${params.verification.kind} verification failed`
|
|
507
|
+
: `${params.name} failed`,
|
|
508
|
+
},
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
/** A crash left a write intent without enough evidence to prove its effect. */
|
|
512
|
+
noteIndeterminateWorkspaceChange() {
|
|
513
|
+
if (this.config.enabled === false)
|
|
514
|
+
return;
|
|
515
|
+
this.ledger.advanceWorkspaceRevision();
|
|
516
|
+
this.invalidateVerificationAfterWrite();
|
|
517
|
+
this.refreshCapsule();
|
|
518
|
+
this.touch();
|
|
519
|
+
}
|
|
520
|
+
hasCurrentWorkspaceVerification(activeTaskOnly = false) {
|
|
521
|
+
const revision = this.ledger.workspaceRevision;
|
|
522
|
+
return (this.ledger
|
|
523
|
+
.getEntries()
|
|
524
|
+
.some(entry => entry.type === 'verification' &&
|
|
525
|
+
typeof entry.metadata?.toolReceiptDigest === 'string' &&
|
|
526
|
+
entry.metadata.workspaceRevision === revision &&
|
|
527
|
+
(!activeTaskOnly || entry.metadata.taskContractId === this.contract?.id)) ||
|
|
528
|
+
this.taskTodoReceipts.some(([, , evidence]) => evidence && 'kind' in evidence ? evidence.workspaceRevision === revision : false));
|
|
529
|
+
}
|
|
530
|
+
observeVerificationWorkspace(fingerprint) {
|
|
531
|
+
if (this.config.enabled === false || fingerprint === this.verificationWorkspace)
|
|
532
|
+
return;
|
|
533
|
+
const previous = this.verificationWorkspace;
|
|
534
|
+
this.verificationWorkspace = fingerprint ?? undefined;
|
|
535
|
+
if (this.hasCurrentWorkspaceVerification()) {
|
|
536
|
+
if (previous && fingerprint) {
|
|
537
|
+
this.ledger.advanceWorkspaceRevision();
|
|
538
|
+
this.invalidateVerificationAfterWrite();
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
this.invalidateUnboundVerification();
|
|
542
|
+
}
|
|
543
|
+
this.refreshCapsule();
|
|
544
|
+
}
|
|
545
|
+
this.touch();
|
|
546
|
+
}
|
|
181
547
|
ingestTurn(params) {
|
|
182
548
|
if (this.config.enabled === false)
|
|
183
549
|
return undefined;
|
|
@@ -199,19 +565,53 @@ class HarnessKernel {
|
|
|
199
565
|
this.touch();
|
|
200
566
|
return summary;
|
|
201
567
|
}
|
|
202
|
-
|
|
203
|
-
|
|
568
|
+
progressState() {
|
|
569
|
+
return this.progressController.toJSON();
|
|
570
|
+
}
|
|
571
|
+
recordProgress(baseline, unconfirmedWorkspaceRevisions = 0) {
|
|
572
|
+
const delta = this.progressController.observe({
|
|
204
573
|
contract: this.contract,
|
|
205
574
|
ledger: this.ledger.getEntries(),
|
|
206
|
-
|
|
207
|
-
|
|
575
|
+
diagnostics: this.diagnostics,
|
|
576
|
+
workspaceRevision: this.ledger.workspaceRevision,
|
|
577
|
+
unconfirmedWorkspaceRevisions,
|
|
578
|
+
taskTodos: this.taskTodos,
|
|
579
|
+
}, baseline);
|
|
580
|
+
this.touch();
|
|
581
|
+
return delta;
|
|
582
|
+
}
|
|
583
|
+
beforeComplete(enforceTaskTodos = false, requireEveryCriterion = false) {
|
|
584
|
+
const result = (0, drift_guard_1.evaluateCompletionGate)({
|
|
208
585
|
contract: this.contract,
|
|
209
586
|
ledger: this.ledger.getEntries(),
|
|
210
|
-
|
|
587
|
+
workspaceRevision: this.ledger.workspaceRevision,
|
|
588
|
+
requireLocalReceipt: this.requireLocalVerificationReceipt,
|
|
589
|
+
requireEveryCriterion,
|
|
211
590
|
});
|
|
591
|
+
if (requireEveryCriterion && this.contract?.criteria) {
|
|
592
|
+
const statuses = new Map(result.criterionResults?.map(criterion => [criterion.criterionId, criterion.status]));
|
|
593
|
+
this.contract = {
|
|
594
|
+
...this.contract,
|
|
595
|
+
criteria: this.contract.criteria.map(criterion => ({
|
|
596
|
+
...criterion,
|
|
597
|
+
status: statuses.get(criterion.id) ?? criterion.status,
|
|
598
|
+
})),
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
if (enforceTaskTodos) {
|
|
602
|
+
const checklist = this.missingExecutionChecklist();
|
|
603
|
+
if (checklist)
|
|
604
|
+
result.missing.push(checklist);
|
|
605
|
+
for (const todo of this.taskTodos) {
|
|
606
|
+
if (todo.status !== 'completed')
|
|
607
|
+
result.missing.push(`Unfinished todo: ${todo.content}`);
|
|
608
|
+
}
|
|
609
|
+
if (result.missing.length > 0)
|
|
610
|
+
result.canComplete = false;
|
|
611
|
+
}
|
|
612
|
+
const progressDelta = this.recordProgress();
|
|
212
613
|
result.progressDelta = progressDelta;
|
|
213
614
|
result.stopDecision = this.stopController.decideCompletion(result, progressDelta);
|
|
214
|
-
this.touch();
|
|
215
615
|
const mode = this.config.completionGate === true
|
|
216
616
|
? 'block'
|
|
217
617
|
: this.config.completionGate === false
|
|
@@ -232,7 +632,7 @@ class HarnessKernel {
|
|
|
232
632
|
// Block completion until evidence is provided. Track consecutive blocks
|
|
233
633
|
// so callers can detect a stalled loop, but never silently pass the gate
|
|
234
634
|
// without evidence.
|
|
235
|
-
if (!result.canComplete && mode === 'block') {
|
|
635
|
+
if (!result.canComplete && (mode === 'block' || requireEveryCriterion)) {
|
|
236
636
|
this.completionBlockCount++;
|
|
237
637
|
this.touch();
|
|
238
638
|
return result;
|
|
@@ -336,9 +736,18 @@ class HarnessKernel {
|
|
|
336
736
|
version: 2,
|
|
337
737
|
contract: this.contract,
|
|
338
738
|
ledger: this.ledger.toJSON(),
|
|
739
|
+
workspaceRevision: this.ledger.workspaceRevision,
|
|
740
|
+
...(this.verificationWorkspace ? { verificationWorkspace: this.verificationWorkspace } : {}),
|
|
339
741
|
capsule: this.capsule,
|
|
340
742
|
completionBlockCount: this.completionBlockCount,
|
|
341
743
|
taskEpoch: this.taskEpoch,
|
|
744
|
+
...(this.taskChecklistRequired ? { taskChecklistRequired: true } : {}),
|
|
745
|
+
...(this.taskChecklistTargets.length
|
|
746
|
+
? { taskChecklistTargets: this.taskChecklistTargets }
|
|
747
|
+
: {}),
|
|
748
|
+
...(this.goalTaskId ? { goalTaskId: this.goalTaskId } : {}),
|
|
749
|
+
...(this.taskTodos.length ? { taskTodos: this.taskTodos } : {}),
|
|
750
|
+
...(this.taskTodoReceipts.length ? { taskTodoReceipts: [...this.taskTodoReceipts] } : {}),
|
|
342
751
|
rootObjective: this.rootObjective,
|
|
343
752
|
activeInstruction: this.activeInstruction,
|
|
344
753
|
intentHistory: this.intentHistory,
|
|
@@ -359,7 +768,7 @@ class HarnessKernel {
|
|
|
359
768
|
refreshCapsule() {
|
|
360
769
|
if (!this.contract && this.ledger.getEntries().length === 0)
|
|
361
770
|
return;
|
|
362
|
-
this.capsule = (0, capsule_1.createContextCapsule)(this.contract, this.ledger.getEntries());
|
|
771
|
+
this.capsule = (0, capsule_1.createContextCapsule)(this.contract, this.ledger.getEntries(), this.ledger.workspaceRevision);
|
|
363
772
|
this.refreshEvidenceIndex();
|
|
364
773
|
}
|
|
365
774
|
refreshEvidenceIndex() {
|
|
@@ -378,34 +787,81 @@ class HarnessKernel {
|
|
|
378
787
|
return DEFAULT_CONFIG.maxRecentTurns;
|
|
379
788
|
return Math.max(0, Math.min(80, Math.floor(configured)));
|
|
380
789
|
}
|
|
790
|
+
/** An unbound result must be rerun without recording a filesystem mutation. */
|
|
791
|
+
invalidateUnboundVerification() {
|
|
792
|
+
this.ledger.forgetVerificationBindings();
|
|
793
|
+
for (const [index, [step, receipt, evidence]] of this.taskTodoReceipts.entries()) {
|
|
794
|
+
if (evidence &&
|
|
795
|
+
'kind' in evidence &&
|
|
796
|
+
evidence.workspaceRevision === this.ledger.workspaceRevision) {
|
|
797
|
+
this.taskTodoReceipts[index] = [
|
|
798
|
+
step,
|
|
799
|
+
receipt,
|
|
800
|
+
{ ...evidence, workspaceRevision: undefined },
|
|
801
|
+
];
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
this.invalidateVerificationAfterWrite();
|
|
805
|
+
}
|
|
806
|
+
invalidateVerificationAfterWrite() {
|
|
807
|
+
if (this.contract?.criteria) {
|
|
808
|
+
this.contract = {
|
|
809
|
+
...this.contract,
|
|
810
|
+
criteria: this.contract.criteria.map(criterion => (criterion.status === 'passed' || criterion.status === 'failed') &&
|
|
811
|
+
(0, verification_1.requiredVerificationKinds)(criterion.statement).length > 0
|
|
812
|
+
? { ...criterion, status: 'pending' }
|
|
813
|
+
: criterion),
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
this.taskTodos = this.taskTodos.map(todo => todo.status === 'completed' && todo.verification?.length && this.missingTodoEvidence(todo)
|
|
817
|
+
? { ...todo, status: 'pending' }
|
|
818
|
+
: todo);
|
|
819
|
+
}
|
|
381
820
|
autoLinkVerificationEvidence(entry) {
|
|
382
821
|
if (!this.contract?.criteria || !(0, verification_1.isTrustedEvidence)(entry))
|
|
383
822
|
return;
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
823
|
+
const kind = (0, verification_1.verificationKindForEntry)(entry, this.requireLocalVerificationReceipt);
|
|
824
|
+
if (kind === 'generic' && entry.type !== 'verification')
|
|
825
|
+
return;
|
|
826
|
+
const workspace = this.contract.allowedScope.cwd;
|
|
827
|
+
for (const criterion of this.contract.criteria) {
|
|
828
|
+
if (!(0, verification_1.requiredVerificationKinds)(criterion.statement).includes(kind))
|
|
829
|
+
continue;
|
|
830
|
+
const checks = (0, verification_1.requestedLocalChecks)(criterion.statement).filter(check => check.kind === kind);
|
|
831
|
+
if (checks.length && !checks.some(check => (0, verification_1.matchesRequestedCheck)(entry, check, workspace)))
|
|
832
|
+
continue;
|
|
833
|
+
this.updateCriterionEvidence(criterion.id, entry.id);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
autoLinkArtifactReadback(entry, input) {
|
|
837
|
+
const contract = this.contract;
|
|
838
|
+
const metadata = entry.metadata;
|
|
839
|
+
if (!contract?.criteria ||
|
|
840
|
+
!metadata ||
|
|
841
|
+
input.name !== 'read_file' ||
|
|
842
|
+
!input.toolReceiptDigest ||
|
|
843
|
+
!(0, verification_1.isTrustedEvidence)(entry) ||
|
|
844
|
+
typeof metadata.path !== 'string')
|
|
387
845
|
return;
|
|
388
|
-
const
|
|
389
|
-
|
|
846
|
+
const cwd = contract.allowedScope.cwd;
|
|
847
|
+
const path = (0, verification_1.workspaceArtifactPath)(cwd, metadata.path);
|
|
848
|
+
if (!path)
|
|
390
849
|
return;
|
|
391
|
-
const
|
|
392
|
-
const
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
}) ??
|
|
407
|
-
candidates[0];
|
|
408
|
-
this.updateCriterionEvidence(selected.id, entry.id);
|
|
850
|
+
const output = (0, tool_serializer_1.parseToolResultEnvelope)(input.result).output;
|
|
851
|
+
for (const criterion of contract.criteria) {
|
|
852
|
+
const artifact = (0, verification_1.requestedFileArtifact)(criterion.statement);
|
|
853
|
+
if (!artifact || (0, verification_1.workspaceArtifactPath)(cwd, artifact.path) !== path)
|
|
854
|
+
continue;
|
|
855
|
+
const write = (0, verification_1.latestArtifactWrite)(this.ledger.getEntries(), contract.id, cwd, artifact.path);
|
|
856
|
+
if (!write)
|
|
857
|
+
continue;
|
|
858
|
+
metadata.artifactMatches = {
|
|
859
|
+
...metadata.artifactMatches,
|
|
860
|
+
[criterion.id]: metadata.success === true && (!artifact.contains || output.includes(artifact.contains)),
|
|
861
|
+
};
|
|
862
|
+
this.updateCriterionEvidence(criterion.id, write.id);
|
|
863
|
+
this.updateCriterionEvidence(criterion.id, entry.id);
|
|
864
|
+
}
|
|
409
865
|
}
|
|
410
866
|
updateCriterionEvidence(criterionId, evidenceRef) {
|
|
411
867
|
if (!this.contract?.criteria)
|
|
@@ -423,6 +879,9 @@ class HarnessKernel {
|
|
|
423
879
|
criteria: [{ ...item, evidenceRefs }],
|
|
424
880
|
},
|
|
425
881
|
ledger: this.ledger.getEntries(),
|
|
882
|
+
workspaceRevision: this.ledger.workspaceRevision,
|
|
883
|
+
requireLocalReceipt: this.requireLocalVerificationReceipt,
|
|
884
|
+
requireEveryCriterion: !!(0, verification_1.requestedFileArtifact)(item.statement),
|
|
426
885
|
}).criterionResults?.[0];
|
|
427
886
|
return {
|
|
428
887
|
...item,
|
|
@@ -442,6 +901,57 @@ class HarnessKernel {
|
|
|
442
901
|
}
|
|
443
902
|
exports.HarnessKernel = HarnessKernel;
|
|
444
903
|
exports.ContextHarness = HarnessKernel;
|
|
904
|
+
function withTodoVerification(todo, id, previous) {
|
|
905
|
+
const required = new Set([...(previous?.verification ?? []), ...(todo.verification ?? [])]);
|
|
906
|
+
for (const check of todoChecks(todo.content)) {
|
|
907
|
+
if ((0, verification_command_1.isLocalVerificationKind)(check.kind))
|
|
908
|
+
required.add(check.kind);
|
|
909
|
+
}
|
|
910
|
+
const command = (0, verification_command_1.classifyDirectVerificationCommand)(todo.content);
|
|
911
|
+
if ((0, verification_command_1.isLocalVerificationKind)(command))
|
|
912
|
+
required.add(command);
|
|
913
|
+
if (/^(?:(?:run|execute)\b|运行|执行)/iu.test(todo.content)) {
|
|
914
|
+
const inferred = (0, verification_1.requiredVerificationKinds)(todo.content);
|
|
915
|
+
for (const kind of verification_command_1.LOCAL_VERIFICATION_KINDS) {
|
|
916
|
+
if (inferred.includes(kind))
|
|
917
|
+
required.add(kind);
|
|
918
|
+
}
|
|
919
|
+
if (/^(?:(?:run|execute)\s+(?:the\s+)?build\b|(?:运行|执行)(?:项目)?(?:构建|编译))/iu.test(todo.content)) {
|
|
920
|
+
required.add('build');
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
const verification = verification_command_1.LOCAL_VERIFICATION_KINDS.filter(kind => required.has(kind));
|
|
924
|
+
return {
|
|
925
|
+
content: todo.content,
|
|
926
|
+
activeForm: todo.activeForm,
|
|
927
|
+
status: todo.status,
|
|
928
|
+
id,
|
|
929
|
+
...(verification.length ? { verification } : {}),
|
|
930
|
+
...(previous?.deferredReason ? { deferredReason: previous.deferredReason } : {}),
|
|
931
|
+
...(previous?.recovery ? { recovery: previous.recovery } : {}),
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
function todoChecks(content) {
|
|
935
|
+
const requested = (0, verification_1.requestedLocalChecks)(content);
|
|
936
|
+
const command = content.trim();
|
|
937
|
+
const direct = (0, verification_command_1.classifyDirectVerificationCommand)(command);
|
|
938
|
+
if ((0, verification_command_1.isLocalVerificationKind)(direct))
|
|
939
|
+
requested.push({ kind: direct, command });
|
|
940
|
+
return requested;
|
|
941
|
+
}
|
|
942
|
+
function matchesTodoCheck(observed, check, workspace) {
|
|
943
|
+
return (observed.kind === check.kind &&
|
|
944
|
+
observed.command === check.command &&
|
|
945
|
+
(!check.cwd || (0, path_1.resolve)(workspace, observed.cwd ?? '.') === (0, path_1.resolve)(workspace, check.cwd)));
|
|
946
|
+
}
|
|
947
|
+
function sameTodoEvidenceTarget(previous, next) {
|
|
948
|
+
if (!previous || !next)
|
|
949
|
+
return !previous && !next;
|
|
950
|
+
if ('kind' in previous && 'kind' in next) {
|
|
951
|
+
return (previous.kind === next.kind && previous.command === next.command && previous.cwd === next.cwd);
|
|
952
|
+
}
|
|
953
|
+
return ('changedFile' in previous && 'changedFile' in next && previous.changedFile === next.changedFile);
|
|
954
|
+
}
|
|
445
955
|
function createHarnessKernel(options) {
|
|
446
956
|
return new HarnessKernel(options);
|
|
447
957
|
}
|