deadbyte-mcp 0.8.9 → 0.9.0
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/CONTEXT.md +41 -0
- package/MANIFEST.SHA256 +348 -83
- package/R34-BASELINE.json +9 -0
- package/README.txt +135 -9
- package/bench/fixtures/corpus.json +17 -0
- package/bin/WORKER-REGISTRY.txt +3 -3
- package/bin/appcontainer-stage.exe +0 -0
- package/bin/appcontainer-stage.obj +0 -0
- package/bin/bootstrap-advapi32.exe +0 -0
- package/bin/bootstrap-advapi32.obj +0 -0
- package/bin/bootstrap-exitcode.exe +0 -0
- package/bin/bootstrap-exitcode.obj +0 -0
- package/bin/bootstrap-kernel32.exe +0 -0
- package/bin/bootstrap-kernel32.obj +0 -0
- package/bin/child-control-probe.exe +0 -0
- package/bin/child-control-probe.obj +0 -0
- package/bin/child-control-stage.exe +0 -0
- package/bin/child-control-stage.obj +0 -0
- package/bin/contained-reverse-worker.exe +0 -0
- package/bin/contained-reverse-worker.obj +0 -0
- package/bin/contained-transform-worker.exe +0 -0
- package/bin/contained-transform-worker.obj +0 -0
- package/bin/containment-probe.exe +0 -0
- package/bin/containment-probe.obj +0 -0
- package/bin/deadbyte-contain.exe +0 -0
- package/bin/deadbyte-contain.obj +0 -0
- package/bin/deadbyte-exec.exe +0 -0
- package/bin/deadbyte-exec.obj +0 -0
- package/bin/deadbyte-process-host.exe +0 -0
- package/bin/deadbyte-process-host.obj +0 -0
- package/bin/deadbyte-tunnel-host.exe +0 -0
- package/bin/deadbyte-tunnel-host.obj +0 -0
- package/controller/README.TXT +10 -4
- package/controller/deadbyte-controller.config.psd1.example +14 -0
- package/controller/deadbyte-controller.ps1 +144 -19
- package/controller/deadbyte-process-policy.json +5 -5
- package/controller/deadbyte-semantic-lsp-config.json +95 -0
- package/deadbyte-mcp-0.8.9.tgz +0 -0
- package/docs/ADR-0001-PRODUCTION-BASELINE-SEAMS.md +29 -0
- package/docs/ARCHITECTURE.md +6 -5
- package/docs/superpowers/plans/2026-09-16-deadbyte-loop-engine.md +846 -0
- package/docs/superpowers/plans/2026-09-17-r35-production-successor.md +408 -0
- package/docs/superpowers/specs/2026-09-16-deadbyte-loop-engine-design.md +435 -0
- package/docs/superpowers/specs/2026-09-17-r35-production-successor-design.md +220 -0
- package/node_modules/typescript/LICENSE.txt +55 -0
- package/node_modules/typescript/README.md +50 -0
- package/node_modules/typescript/SECURITY.md +41 -0
- package/node_modules/typescript/ThirdPartyNoticeText.txt +193 -0
- package/node_modules/typescript/bin/tsc +2 -0
- package/node_modules/typescript/bin/tsserver +2 -0
- package/node_modules/typescript/lib/_tsc.js +133818 -0
- package/node_modules/typescript/lib/_tsserver.js +659 -0
- package/node_modules/typescript/lib/_typingsInstaller.js +222 -0
- package/node_modules/typescript/lib/cs/diagnosticMessages.generated.json +2122 -0
- package/node_modules/typescript/lib/de/diagnosticMessages.generated.json +2122 -0
- package/node_modules/typescript/lib/es/diagnosticMessages.generated.json +2122 -0
- package/node_modules/typescript/lib/fr/diagnosticMessages.generated.json +2122 -0
- package/node_modules/typescript/lib/it/diagnosticMessages.generated.json +2122 -0
- package/node_modules/typescript/lib/ja/diagnosticMessages.generated.json +2122 -0
- package/node_modules/typescript/lib/ko/diagnosticMessages.generated.json +2122 -0
- package/node_modules/typescript/lib/lib.d.ts +22 -0
- package/node_modules/typescript/lib/lib.decorators.d.ts +384 -0
- package/node_modules/typescript/lib/lib.decorators.legacy.d.ts +22 -0
- package/node_modules/typescript/lib/lib.dom.asynciterable.d.ts +41 -0
- package/node_modules/typescript/lib/lib.dom.d.ts +39429 -0
- package/node_modules/typescript/lib/lib.dom.iterable.d.ts +571 -0
- package/node_modules/typescript/lib/lib.es2015.collection.d.ts +147 -0
- package/node_modules/typescript/lib/lib.es2015.core.d.ts +597 -0
- package/node_modules/typescript/lib/lib.es2015.d.ts +28 -0
- package/node_modules/typescript/lib/lib.es2015.generator.d.ts +77 -0
- package/node_modules/typescript/lib/lib.es2015.iterable.d.ts +605 -0
- package/node_modules/typescript/lib/lib.es2015.promise.d.ts +81 -0
- package/node_modules/typescript/lib/lib.es2015.proxy.d.ts +128 -0
- package/node_modules/typescript/lib/lib.es2015.reflect.d.ts +144 -0
- package/node_modules/typescript/lib/lib.es2015.symbol.d.ts +46 -0
- package/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts +326 -0
- package/node_modules/typescript/lib/lib.es2016.array.include.d.ts +116 -0
- package/node_modules/typescript/lib/lib.es2016.d.ts +21 -0
- package/node_modules/typescript/lib/lib.es2016.full.d.ts +23 -0
- package/node_modules/typescript/lib/lib.es2016.intl.d.ts +31 -0
- package/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts +21 -0
- package/node_modules/typescript/lib/lib.es2017.d.ts +26 -0
- package/node_modules/typescript/lib/lib.es2017.date.d.ts +31 -0
- package/node_modules/typescript/lib/lib.es2017.full.d.ts +23 -0
- package/node_modules/typescript/lib/lib.es2017.intl.d.ts +44 -0
- package/node_modules/typescript/lib/lib.es2017.object.d.ts +49 -0
- package/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts +135 -0
- package/node_modules/typescript/lib/lib.es2017.string.d.ts +45 -0
- package/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts +53 -0
- package/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts +77 -0
- package/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts +53 -0
- package/node_modules/typescript/lib/lib.es2018.d.ts +24 -0
- package/node_modules/typescript/lib/lib.es2018.full.d.ts +24 -0
- package/node_modules/typescript/lib/lib.es2018.intl.d.ts +83 -0
- package/node_modules/typescript/lib/lib.es2018.promise.d.ts +30 -0
- package/node_modules/typescript/lib/lib.es2018.regexp.d.ts +37 -0
- package/node_modules/typescript/lib/lib.es2019.array.d.ts +79 -0
- package/node_modules/typescript/lib/lib.es2019.d.ts +24 -0
- package/node_modules/typescript/lib/lib.es2019.full.d.ts +24 -0
- package/node_modules/typescript/lib/lib.es2019.intl.d.ts +23 -0
- package/node_modules/typescript/lib/lib.es2019.object.d.ts +33 -0
- package/node_modules/typescript/lib/lib.es2019.string.d.ts +37 -0
- package/node_modules/typescript/lib/lib.es2019.symbol.d.ts +24 -0
- package/node_modules/typescript/lib/lib.es2020.bigint.d.ts +765 -0
- package/node_modules/typescript/lib/lib.es2020.d.ts +27 -0
- package/node_modules/typescript/lib/lib.es2020.date.d.ts +42 -0
- package/node_modules/typescript/lib/lib.es2020.full.d.ts +24 -0
- package/node_modules/typescript/lib/lib.es2020.intl.d.ts +474 -0
- package/node_modules/typescript/lib/lib.es2020.number.d.ts +28 -0
- package/node_modules/typescript/lib/lib.es2020.promise.d.ts +47 -0
- package/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts +99 -0
- package/node_modules/typescript/lib/lib.es2020.string.d.ts +44 -0
- package/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts +41 -0
- package/node_modules/typescript/lib/lib.es2021.d.ts +23 -0
- package/node_modules/typescript/lib/lib.es2021.full.d.ts +24 -0
- package/node_modules/typescript/lib/lib.es2021.intl.d.ts +166 -0
- package/node_modules/typescript/lib/lib.es2021.promise.d.ts +48 -0
- package/node_modules/typescript/lib/lib.es2021.string.d.ts +33 -0
- package/node_modules/typescript/lib/lib.es2021.weakref.d.ts +78 -0
- package/node_modules/typescript/lib/lib.es2022.array.d.ts +121 -0
- package/node_modules/typescript/lib/lib.es2022.d.ts +25 -0
- package/node_modules/typescript/lib/lib.es2022.error.d.ts +75 -0
- package/node_modules/typescript/lib/lib.es2022.full.d.ts +24 -0
- package/node_modules/typescript/lib/lib.es2022.intl.d.ts +145 -0
- package/node_modules/typescript/lib/lib.es2022.object.d.ts +26 -0
- package/node_modules/typescript/lib/lib.es2022.regexp.d.ts +39 -0
- package/node_modules/typescript/lib/lib.es2022.string.d.ts +25 -0
- package/node_modules/typescript/lib/lib.es2023.array.d.ts +924 -0
- package/node_modules/typescript/lib/lib.es2023.collection.d.ts +21 -0
- package/node_modules/typescript/lib/lib.es2023.d.ts +22 -0
- package/node_modules/typescript/lib/lib.es2023.full.d.ts +24 -0
- package/node_modules/typescript/lib/lib.es2023.intl.d.ts +56 -0
- package/node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts +65 -0
- package/node_modules/typescript/lib/lib.es2024.collection.d.ts +29 -0
- package/node_modules/typescript/lib/lib.es2024.d.ts +26 -0
- package/node_modules/typescript/lib/lib.es2024.full.d.ts +24 -0
- package/node_modules/typescript/lib/lib.es2024.object.d.ts +29 -0
- package/node_modules/typescript/lib/lib.es2024.promise.d.ts +35 -0
- package/node_modules/typescript/lib/lib.es2024.regexp.d.ts +25 -0
- package/node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts +68 -0
- package/node_modules/typescript/lib/lib.es2024.string.d.ts +29 -0
- package/node_modules/typescript/lib/lib.es5.d.ts +4601 -0
- package/node_modules/typescript/lib/lib.es6.d.ts +23 -0
- package/node_modules/typescript/lib/lib.esnext.array.d.ts +35 -0
- package/node_modules/typescript/lib/lib.esnext.collection.d.ts +96 -0
- package/node_modules/typescript/lib/lib.esnext.d.ts +29 -0
- package/node_modules/typescript/lib/lib.esnext.decorators.d.ts +28 -0
- package/node_modules/typescript/lib/lib.esnext.disposable.d.ts +193 -0
- package/node_modules/typescript/lib/lib.esnext.error.d.ts +24 -0
- package/node_modules/typescript/lib/lib.esnext.float16.d.ts +445 -0
- package/node_modules/typescript/lib/lib.esnext.full.d.ts +24 -0
- package/node_modules/typescript/lib/lib.esnext.intl.d.ts +21 -0
- package/node_modules/typescript/lib/lib.esnext.iterator.d.ts +148 -0
- package/node_modules/typescript/lib/lib.esnext.promise.d.ts +34 -0
- package/node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts +25 -0
- package/node_modules/typescript/lib/lib.scripthost.d.ts +322 -0
- package/node_modules/typescript/lib/lib.webworker.asynciterable.d.ts +41 -0
- package/node_modules/typescript/lib/lib.webworker.d.ts +13150 -0
- package/node_modules/typescript/lib/lib.webworker.importscripts.d.ts +23 -0
- package/node_modules/typescript/lib/lib.webworker.iterable.d.ts +340 -0
- package/node_modules/typescript/lib/pl/diagnosticMessages.generated.json +2122 -0
- package/node_modules/typescript/lib/pt-br/diagnosticMessages.generated.json +2122 -0
- package/node_modules/typescript/lib/ru/diagnosticMessages.generated.json +2122 -0
- package/node_modules/typescript/lib/tr/diagnosticMessages.generated.json +2122 -0
- package/node_modules/typescript/lib/tsc.js +8 -0
- package/node_modules/typescript/lib/tsserver.js +8 -0
- package/node_modules/typescript/lib/tsserverlibrary.d.ts +17 -0
- package/node_modules/typescript/lib/tsserverlibrary.js +21 -0
- package/node_modules/typescript/lib/typesMap.json +497 -0
- package/node_modules/typescript/lib/typescript.d.ts +11437 -0
- package/node_modules/typescript/lib/typescript.js +200276 -0
- package/node_modules/typescript/lib/typingsInstaller.js +8 -0
- package/node_modules/typescript/lib/watchGuard.js +53 -0
- package/node_modules/typescript/lib/zh-cn/diagnosticMessages.generated.json +2122 -0
- package/node_modules/typescript/lib/zh-tw/diagnosticMessages.generated.json +2122 -0
- package/node_modules/typescript/package.json +120 -0
- package/package.json +5 -3
- package/proof/CONTAINMENT-BUILD.txt +6 -6
- package/proof/R34-TASK8-SUPERVISOR-CHECKPOINT.json +29 -0
- package/proof/R34-TASK9-MCP-SURFACE-CHECKPOINT.json +28 -0
- package/scripts/capability-benchmark.mjs +27 -0
- package/scripts/deferred-slot-operation.mjs +4 -2
- package/scripts/final-closure-verify.mjs +10 -10
- package/scripts/final-closure.mjs +11 -11
- package/scripts/gate-windows.ps1 +3 -3
- package/scripts/release-parity.mjs +14 -14
- package/scripts/semantic-preflight.ps1 +73 -0
- package/scripts/tool-surface-snapshot.mjs +73 -0
- package/scripts/windows-gate-evidence.mjs +5 -5
- package/src/audit-verify.mjs +6 -2
- package/src/autonomous-action-reconcile.mjs +142 -0
- package/src/autonomous-context-engine.mjs +255 -0
- package/src/autonomous-live-state.mjs +17 -0
- package/src/autonomous-local-supervisor.mjs +249 -0
- package/src/autonomous-loop-state.mjs +304 -0
- package/src/autonomous-output-contracts.mjs +22 -3
- package/src/autonomous-plan.mjs +181 -0
- package/src/autonomous-planner-contracts.mjs +44 -0
- package/src/autonomous-planner.mjs +91 -6
- package/src/autonomous-policy.mjs +15 -2
- package/src/autonomous-progress.mjs +127 -0
- package/src/autonomous-runtime.mjs +601 -48
- package/src/autonomous-supervisor-host.mjs +70 -0
- package/src/autonomous-supervisor.mjs +31 -8
- package/src/capability-benchmark-runner.mjs +108 -0
- package/src/capability-benchmark.mjs +50 -0
- package/src/coding-mcp-tools.mjs +46 -3
- package/src/coding-output-contracts.mjs +45 -0
- package/src/context-provenance.mjs +86 -0
- package/src/deadbyte-cli.mjs +136 -30
- package/src/document-adapter.mjs +43 -0
- package/src/lsp-stdio-client.mjs +112 -0
- package/src/machine-fs-smoke-client.mjs +2 -1
- package/src/mcp-server.mjs +17 -3
- package/src/observation-smoke-client.mjs +3 -2
- package/src/operator-surface.mjs +37 -0
- package/src/provider-circuit.mjs +125 -0
- package/src/release-generation.mjs +44 -5
- package/src/remote-mcp-autonomous-smoke-client.mjs +53 -14
- package/src/remote-mcp-coding-smoke-client.mjs +5 -4
- package/src/remote-mcp-r24-disarmed-smoke-client.mjs +4 -2
- package/src/remote-mcp-r33-parity-client.mjs +1 -1
- package/src/remote-mcp-r34-parity-client.mjs +177 -0
- package/src/remote-mcp-smoke-client.mjs +2 -1
- package/src/remote-result-journal.mjs +114 -0
- package/src/runtime-update.mjs +58 -8
- package/src/semantic-backend-registry.mjs +39 -0
- package/src/semantic-code.mjs +179 -0
- package/src/semantic-lsp-backend.mjs +183 -0
- package/src/semantic-lsp-config.mjs +112 -0
- package/src/tool-surface-ledger.mjs +92 -0
- package/src/version.mjs +1 -1
- package/test/audit-verify.test.mjs +1 -1
- package/test/autonomous-action-reconcile.test.mjs +106 -0
- package/test/autonomous-adversarial.test.mjs +149 -6
- package/test/autonomous-context-engine.test.mjs +181 -0
- package/test/autonomous-live-state.test.mjs +27 -0
- package/test/autonomous-local-supervisor.test.mjs +403 -0
- package/test/autonomous-loop-state.test.mjs +126 -0
- package/test/autonomous-loop-v2.test.mjs +105 -0
- package/test/autonomous-loop.test.mjs +79 -1
- package/test/autonomous-output-contract.test.mjs +54 -0
- package/test/autonomous-plan.test.mjs +101 -0
- package/test/autonomous-progress.test.mjs +106 -0
- package/test/autonomous-r34-e2e.test.mjs +338 -0
- package/test/autonomous-runtime.test.mjs +3 -3
- package/test/autonomous-supervisor-integration.test.mjs +48 -3
- package/test/capability-benchmark-runner.test.mjs +49 -0
- package/test/capability-benchmark.test.mjs +47 -0
- package/test/cli-entrypoint.test.mjs +12 -0
- package/test/coding-catalog-consistency.test.mjs +24 -0
- package/test/coding-plane.test.mjs +3 -3
- package/test/context-provenance.test.mjs +61 -0
- package/test/controller-r27.test.mjs +4 -3
- package/test/controller.test.mjs +52 -0
- package/test/core.test.mjs +1 -1
- package/test/deferred-slot-operation-behavior.test.mjs +5 -1
- package/test/deferred-slot-operation.test.mjs +2 -1
- package/test/document-adapter.test.mjs +23 -0
- package/test/fixtures/lsp-framed-server.mjs +33 -0
- package/test/fixtures/semantic/cpp/compile_commands.json +4 -0
- package/test/fixtures/semantic/cpp/lib.cpp +2 -0
- package/test/fixtures/semantic/cpp/lib.hpp +2 -0
- package/test/fixtures/semantic/cpp/main.cpp +2 -0
- package/test/fixtures/semantic/python/lib.py +2 -0
- package/test/fixtures/semantic/python/main.py +2 -0
- package/test/fixtures/semantic/rust/Cargo.lock +7 -0
- package/test/fixtures/semantic/rust/Cargo.toml +8 -0
- package/test/fixtures/semantic/rust/src/lib.rs +3 -0
- package/test/fixtures/semantic/rust/src/main.rs +5 -0
- package/test/fixtures/semantic/rust/src/math.rs +3 -0
- package/test/fixtures/semantic/rust/target/.rustc_info.json +1 -0
- package/test/fixtures/semantic/rust/target/CACHEDIR.TAG +3 -0
- package/test/fixtures/semantic/rust/target/debug/.cargo-lock +0 -0
- package/test/fixtures/semantic/rust/target/debug/.fingerprint/semantic_rust-4c168fa33c79d09c/dep-test-lib-semantic_rust +0 -0
- package/test/fixtures/semantic/rust/target/debug/.fingerprint/semantic_rust-4c168fa33c79d09c/invoked.timestamp +1 -0
- package/test/fixtures/semantic/rust/target/debug/.fingerprint/semantic_rust-4c168fa33c79d09c/test-lib-semantic_rust +1 -0
- package/test/fixtures/semantic/rust/target/debug/.fingerprint/semantic_rust-4c168fa33c79d09c/test-lib-semantic_rust.json +1 -0
- package/test/fixtures/semantic/rust/target/debug/.fingerprint/semantic_rust-5dcd474439c54a26/dep-test-bin-semantic_rust_bin +0 -0
- package/test/fixtures/semantic/rust/target/debug/.fingerprint/semantic_rust-5dcd474439c54a26/invoked.timestamp +1 -0
- package/test/fixtures/semantic/rust/target/debug/.fingerprint/semantic_rust-5dcd474439c54a26/test-bin-semantic_rust_bin +1 -0
- package/test/fixtures/semantic/rust/target/debug/.fingerprint/semantic_rust-5dcd474439c54a26/test-bin-semantic_rust_bin.json +1 -0
- package/test/fixtures/semantic/rust/target/debug/.fingerprint/semantic_rust-6212ccd976aa3808/dep-lib-semantic_rust +0 -0
- package/test/fixtures/semantic/rust/target/debug/.fingerprint/semantic_rust-6212ccd976aa3808/invoked.timestamp +1 -0
- package/test/fixtures/semantic/rust/target/debug/.fingerprint/semantic_rust-6212ccd976aa3808/lib-semantic_rust +1 -0
- package/test/fixtures/semantic/rust/target/debug/.fingerprint/semantic_rust-6212ccd976aa3808/lib-semantic_rust.json +1 -0
- package/test/fixtures/semantic/rust/target/debug/.fingerprint/semantic_rust-d741378dccdef61c/bin-semantic_rust_bin +1 -0
- package/test/fixtures/semantic/rust/target/debug/.fingerprint/semantic_rust-d741378dccdef61c/bin-semantic_rust_bin.json +1 -0
- package/test/fixtures/semantic/rust/target/debug/.fingerprint/semantic_rust-d741378dccdef61c/dep-bin-semantic_rust_bin +0 -0
- package/test/fixtures/semantic/rust/target/debug/.fingerprint/semantic_rust-d741378dccdef61c/invoked.timestamp +1 -0
- package/test/fixtures/semantic/rust/target/debug/deps/libsemantic_rust-4c168fa33c79d09c.rmeta +0 -0
- package/test/fixtures/semantic/rust/target/debug/deps/libsemantic_rust-6212ccd976aa3808.rmeta +0 -0
- package/test/fixtures/semantic/rust/target/debug/deps/libsemantic_rust_bin-5dcd474439c54a26.rmeta +0 -0
- package/test/fixtures/semantic/rust/target/debug/deps/libsemantic_rust_bin-d741378dccdef61c.rmeta +0 -0
- package/test/fixtures/semantic/rust/target/debug/deps/semantic_rust-4c168fa33c79d09c.d +5 -0
- package/test/fixtures/semantic/rust/target/debug/deps/semantic_rust-6212ccd976aa3808.d +5 -0
- package/test/fixtures/semantic/rust/target/debug/deps/semantic_rust_bin-5dcd474439c54a26.d +6 -0
- package/test/fixtures/semantic/rust/target/debug/deps/semantic_rust_bin-d741378dccdef61c.d +6 -0
- package/test/fixtures/semantic/rust/target/debug/incremental/semantic_rust-1nzlugxi6lq16/s-hmdgo8b6hg-1n6glhc-1qb77z00k06rqw4jdkj92spax/dep-graph.bin +0 -0
- package/test/fixtures/semantic/rust/target/debug/incremental/semantic_rust-1nzlugxi6lq16/s-hmdgo8b6hg-1n6glhc-1qb77z00k06rqw4jdkj92spax/query-cache.bin +0 -0
- package/test/fixtures/semantic/rust/target/debug/incremental/semantic_rust-1nzlugxi6lq16/s-hmdgo8b6hg-1n6glhc-1qb77z00k06rqw4jdkj92spax/work-products.bin +0 -0
- package/test/fixtures/semantic/rust/target/debug/incremental/semantic_rust-1nzlugxi6lq16/s-hmdgo8b6hg-1n6glhc.lock +0 -0
- package/test/fixtures/semantic/rust/target/debug/incremental/semantic_rust-3s436v7g6f5xm/s-hmdgo8b58k-1ekj4lq-9twkpivsqnjon278x20bddozq/dep-graph.bin +0 -0
- package/test/fixtures/semantic/rust/target/debug/incremental/semantic_rust-3s436v7g6f5xm/s-hmdgo8b58k-1ekj4lq-9twkpivsqnjon278x20bddozq/metadata.rmeta +0 -0
- package/test/fixtures/semantic/rust/target/debug/incremental/semantic_rust-3s436v7g6f5xm/s-hmdgo8b58k-1ekj4lq-9twkpivsqnjon278x20bddozq/query-cache.bin +0 -0
- package/test/fixtures/semantic/rust/target/debug/incremental/semantic_rust-3s436v7g6f5xm/s-hmdgo8b58k-1ekj4lq-9twkpivsqnjon278x20bddozq/work-products.bin +0 -0
- package/test/fixtures/semantic/rust/target/debug/incremental/semantic_rust-3s436v7g6f5xm/s-hmdgo8b58k-1ekj4lq.lock +0 -0
- package/test/fixtures/semantic/rust/target/debug/incremental/semantic_rust_bin-1jxcbdeehal7q/s-hmdgo8bxlf-1qr24o3-cmu3jai030no72y8u9eurrnjj/dep-graph.bin +0 -0
- package/test/fixtures/semantic/rust/target/debug/incremental/semantic_rust_bin-1jxcbdeehal7q/s-hmdgo8bxlf-1qr24o3-cmu3jai030no72y8u9eurrnjj/query-cache.bin +0 -0
- package/test/fixtures/semantic/rust/target/debug/incremental/semantic_rust_bin-1jxcbdeehal7q/s-hmdgo8bxlf-1qr24o3-cmu3jai030no72y8u9eurrnjj/work-products.bin +0 -0
- package/test/fixtures/semantic/rust/target/debug/incremental/semantic_rust_bin-1jxcbdeehal7q/s-hmdgo8bxlf-1qr24o3.lock +0 -0
- package/test/fixtures/semantic/rust/target/debug/incremental/semantic_rust_bin-2ocx55p60ni6b/s-hmdgo8bxj8-0ir41qt-diy9mqvc2eoiblmhjs3stcgi3/dep-graph.bin +0 -0
- package/test/fixtures/semantic/rust/target/debug/incremental/semantic_rust_bin-2ocx55p60ni6b/s-hmdgo8bxj8-0ir41qt-diy9mqvc2eoiblmhjs3stcgi3/query-cache.bin +0 -0
- package/test/fixtures/semantic/rust/target/debug/incremental/semantic_rust_bin-2ocx55p60ni6b/s-hmdgo8bxj8-0ir41qt-diy9mqvc2eoiblmhjs3stcgi3/work-products.bin +0 -0
- package/test/fixtures/semantic/rust/target/debug/incremental/semantic_rust_bin-2ocx55p60ni6b/s-hmdgo8bxj8-0ir41qt.lock +0 -0
- package/test/fixtures/semantic/rust/target/flycheck0/stderr +1 -0
- package/test/fixtures/semantic/rust/target/flycheck0/stdout +5 -0
- package/test/fixtures/semantic/typescript/lib.ts +3 -0
- package/test/fixtures/semantic/typescript/main.ts +2 -0
- package/test/fixtures/tool-surface-stdio-server.mjs +14 -0
- package/test/helpers/autonomous-r34-fixture.mjs +120 -0
- package/test/lsp-stdio-client.test.mjs +72 -0
- package/test/multi-file-read.test.mjs +41 -0
- package/test/observation-integration.test.mjs +3 -3
- package/test/production-docs.test.mjs +48 -0
- package/test/prompts-resources.test.mjs +35 -0
- package/test/provider-circuit.test.mjs +93 -0
- package/test/public-autonomous-ingress-budget.test.mjs +28 -0
- package/test/r33-closeout-regression.test.mjs +3 -3
- package/test/r33-finalization.test.mjs +19 -16
- package/test/release-generation.test.mjs +23 -2
- package/test/release-version.test.mjs +24 -17
- package/test/remote-r24-catalog.test.mjs +5 -4
- package/test/remote-result-journal.test.mjs +58 -0
- package/test/remote-session-cli.test.mjs +150 -15
- package/test/runtime-self-update.test.mjs +63 -0
- package/test/semantic-backend-registry.test.mjs +29 -0
- package/test/semantic-code.test.mjs +66 -0
- package/test/semantic-lsp-backend.test.mjs +99 -0
- package/test/semantic-lsp-config.test.mjs +81 -0
- package/test/semantic-lsp-readiness.test.mjs +34 -0
- package/test/semantic-lsp-transient-empty.test.mjs +32 -0
- package/test/semantic-lsp-transient-null.test.mjs +31 -0
- package/test/semantic-multilang.test.mjs +72 -0
- package/test/semantic-runtime-routing.test.mjs +32 -0
- package/test/semantic-server-config-integration.test.mjs +66 -0
- package/test/tool-surface-ledger.test.mjs +59 -0
- package/test/tool-surface-snapshot.test.mjs +17 -0
- package/test/tracer-bullet.test.mjs +77 -0
|
@@ -4,7 +4,12 @@ import path from 'node:path';
|
|
|
4
4
|
import { canonicalJson } from './canonical-json.mjs';
|
|
5
5
|
import { loadPrivateSigningKey, loadPublicVerifyKey } from './trust.mjs';
|
|
6
6
|
import { assertAutonomousArmed, autonomousSessionStatus } from './autonomous-policy.mjs';
|
|
7
|
-
import { buildPlannerPrompt, parsePlannerDecision, requestProviderDecision } from './autonomous-planner.mjs';
|
|
7
|
+
import { buildPlannerPrompt, parsePlannerDecision, parseR34PlannerDecision, requestProviderDecision } from './autonomous-planner.mjs';
|
|
8
|
+
import { actionIdentity, reconcileStartedAction } from './autonomous-action-reconcile.mjs';
|
|
9
|
+
import { createPlan, replanPlan, completePlanStep, planIsComplete as r34PlanIsComplete } from './autonomous-plan.mjs';
|
|
10
|
+
import { deriveLoopState, repairFingerprint } from './autonomous-loop-state.mjs';
|
|
11
|
+
import { judgeProgress, stallDisposition } from './autonomous-progress.mjs';
|
|
12
|
+
import { classifyProviderFailure, deriveCircuit, providerCallDisposition, providerCircuitId } from './provider-circuit.mjs';
|
|
8
13
|
import { verifyObservationReceiptFile } from './observation-runtime.mjs';
|
|
9
14
|
|
|
10
15
|
export const AUTONOMOUS_GOAL_SCHEMA = 'deadbyte.autonomous-goal.v1';
|
|
@@ -196,7 +201,8 @@ function profileOutcome(profile, checked) {
|
|
|
196
201
|
...(profile.kind === 'command' ? { exit_code:receipt.exit_code, timed_out:receipt.timed_out, elapsed_ms:receipt.elapsed_ms } :
|
|
197
202
|
{ median_ms:receipt.median_ms, p95_ms:receipt.p95_ms, regression_pct:receipt.regression_pct, verdict:receipt.verdict }) } };
|
|
198
203
|
}
|
|
199
|
-
async function executeProfile({ ctx, events, goalId, actionKey, profileId, epoch, policy, codingRuntime, signingKeyPath
|
|
204
|
+
async function executeProfile({ ctx, events, goalId, actionKey, profileId, epoch, policy, codingRuntime, signingKeyPath,
|
|
205
|
+
r34ResumePhase = null }) {
|
|
200
206
|
const profile = policy.profiles[profileId];
|
|
201
207
|
if (!profile) throw new Error(`autonomous profile '${profileId}' not found`);
|
|
202
208
|
const prior = [...events].reverse().find(event => event.type === 'profile_completed' && event.payload?.action_key === actionKey && event.payload?.profile_id === profileId);
|
|
@@ -204,14 +210,38 @@ async function executeProfile({ ctx, events, goalId, actionKey, profileId, epoch
|
|
|
204
210
|
const receiptId = profileReceiptId(goalId, actionKey, profileId);
|
|
205
211
|
const requestSha256 = profileRequestSha(codingRuntime, profile);
|
|
206
212
|
const started = [...events].reverse().find(event => event.type === 'profile_started' && event.payload?.action_key === actionKey && event.payload?.profile_id === profileId);
|
|
213
|
+
async function pauseR34Ambiguous(detail) {
|
|
214
|
+
if (!r34ResumePhase) return null;
|
|
215
|
+
if (!events.some(event => event.type === 'waiting_entered' && event.payload?.action_key === actionKey)) {
|
|
216
|
+
await appendEvent(ctx,events,signingKeyPath,'waiting_entered',{
|
|
217
|
+
reason:'ambiguous_interrupted_action',requires_approval:true,resume_phase:r34ResumePhase,
|
|
218
|
+
action_key:actionKey,profile_id:profileId,detail:truncated(detail,512)
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
await appendEvent(ctx,events,signingKeyPath,'goal_paused',{
|
|
222
|
+
reason:'ambiguous_interrupted_action',action_key:actionKey,profile_id:profileId
|
|
223
|
+
});
|
|
224
|
+
return {status:'paused',reason:'ambiguous_interrupted_action',observation:null,existing:false};
|
|
225
|
+
}
|
|
207
226
|
if (started) {
|
|
208
227
|
const checked = await codingRuntime.verifyReceiptDetailed(receiptId);
|
|
209
228
|
if (!checked.ok) {
|
|
229
|
+
const r34Paused=await pauseR34Ambiguous(checked.reason ?? 'profile receipt verification failed');
|
|
230
|
+
if (r34Paused) return r34Paused;
|
|
210
231
|
await appendEvent(ctx,events,signingKeyPath,'goal_paused',{ reason:'interrupted_profile_without_receipt', profile_id:profileId, action_key:actionKey });
|
|
211
232
|
return { status:'paused', observation:null, existing:false };
|
|
212
233
|
}
|
|
213
|
-
if (checked.request_sha256 !== requestSha256)
|
|
214
|
-
|
|
234
|
+
if (checked.request_sha256 !== requestSha256) {
|
|
235
|
+
const r34Paused=await pauseR34Ambiguous(`profile '${profileId}' recovered receipt request mismatch`);
|
|
236
|
+
if (r34Paused) return r34Paused;
|
|
237
|
+
throw new Error(`profile '${profileId}' recovered receipt request mismatch`);
|
|
238
|
+
}
|
|
239
|
+
const outcome = profileOutcome(profile,checked);
|
|
240
|
+
if (!outcome.valid) {
|
|
241
|
+
const r34Paused=await pauseR34Ambiguous(outcome.reason);
|
|
242
|
+
if (r34Paused) return r34Paused;
|
|
243
|
+
throw new Error(outcome.reason);
|
|
244
|
+
}
|
|
215
245
|
const payload = { action_key:actionKey, profile_id:profileId, mutation_epoch:epoch, passed:outcome.passed,
|
|
216
246
|
recovered:true, required_for_release:profile.required_for_release, run_after_mutation:profile.run_after_mutation, ...outcome.payload };
|
|
217
247
|
await appendEvent(ctx,events,signingKeyPath,'profile_completed',payload);
|
|
@@ -232,6 +262,8 @@ async function executeProfile({ ctx, events, goalId, actionKey, profileId, epoch
|
|
|
232
262
|
} catch (error) {
|
|
233
263
|
const checked = await codingRuntime.verifyReceiptDetailed(receiptId);
|
|
234
264
|
if (!checked.ok) {
|
|
265
|
+
const r34Paused=await pauseR34Ambiguous(checked.reason ?? error);
|
|
266
|
+
if (r34Paused) return r34Paused;
|
|
235
267
|
await appendEvent(ctx,events,signingKeyPath,'goal_paused',{ reason:'profile_execution_without_receipt', profile_id:profileId,
|
|
236
268
|
action_key:actionKey, detail:truncated(error) });
|
|
237
269
|
return { status:'paused', observation:null, existing:false };
|
|
@@ -240,9 +272,16 @@ async function executeProfile({ ctx, events, goalId, actionKey, profileId, epoch
|
|
|
240
272
|
}
|
|
241
273
|
const checked = await codingRuntime.verifyReceiptDetailed(receiptId);
|
|
242
274
|
if (!checked.ok || checked.request_sha256 !== requestSha256 || (result && result.receipt_sha256 !== checked.receipt_sha256)) {
|
|
275
|
+
const r34Paused=await pauseR34Ambiguous(`profile '${profileId}' post-execution receipt verification failed`);
|
|
276
|
+
if (r34Paused) return r34Paused;
|
|
243
277
|
throw new Error(`profile '${profileId}' post-execution receipt verification failed`);
|
|
244
278
|
}
|
|
245
|
-
const outcome = profileOutcome(profile,checked);
|
|
279
|
+
const outcome = profileOutcome(profile,checked);
|
|
280
|
+
if (!outcome.valid) {
|
|
281
|
+
const r34Paused=await pauseR34Ambiguous(outcome.reason);
|
|
282
|
+
if (r34Paused) return r34Paused;
|
|
283
|
+
throw new Error(outcome.reason);
|
|
284
|
+
}
|
|
246
285
|
const payload = { action_key:actionKey, profile_id:profileId, mutation_epoch:epoch, passed:outcome.passed,
|
|
247
286
|
recovered:result === null, required_for_release:profile.required_for_release,
|
|
248
287
|
run_after_mutation:profile.run_after_mutation,
|
|
@@ -337,6 +376,106 @@ function validatePlanTransition(previous, next) {
|
|
|
337
376
|
function planIsComplete(plan) {
|
|
338
377
|
return Boolean(plan?.steps?.length) && plan.steps.every(step => step.status === 'completed');
|
|
339
378
|
}
|
|
379
|
+
function parseRuntimePlannerDecision(rawText,policy) {
|
|
380
|
+
let candidate;
|
|
381
|
+
try { candidate = JSON.parse(rawText); }
|
|
382
|
+
catch { return parsePlannerDecision(rawText,policy); }
|
|
383
|
+
return candidate?.schema === 'deadbyte.autonomous-decision.v2'
|
|
384
|
+
? parseR34PlannerDecision(rawText,policy)
|
|
385
|
+
: parsePlannerDecision(rawText,policy);
|
|
386
|
+
}
|
|
387
|
+
function hasR34Loop(events) {
|
|
388
|
+
return events.some(event => event.type === 'plan_created' || event.type === 'plan_replanned' ||
|
|
389
|
+
event.type === 'waiting_entered' || event.payload?.decision?.schema === 'deadbyte.autonomous-decision.v2');
|
|
390
|
+
}
|
|
391
|
+
function loopStateOrNull(goal,events) {
|
|
392
|
+
return hasR34Loop(events) ? deriveLoopState(goal,events) : null;
|
|
393
|
+
}
|
|
394
|
+
function legacyPublicLoopPhase(phase) {
|
|
395
|
+
return ({PLAN:'PLANNING',INSPECT:'INSPECTING',ACT:'ACTING',VERIFY:'VERIFYING',CRITIC:'REPLANNING',
|
|
396
|
+
REPAIR:'REPLANNING',RELEASE:'VERIFYING',WAITING:'WAITING',SUCCEEDED:'COMPLETE',FAILED:'WAITING'})[phase] ?? 'WAITING';
|
|
397
|
+
}
|
|
398
|
+
function publicLoopState(loop) {
|
|
399
|
+
if (!loop) return null;
|
|
400
|
+
const currentStep=loop.current_step ? {
|
|
401
|
+
step_id:loop.current_step.step_id,intent:loop.current_step.intent,status:loop.current_step.status
|
|
402
|
+
} : null;
|
|
403
|
+
const progress=loop.progress ? {
|
|
404
|
+
verdict:loop.progress.verdict,score:loop.progress.score,
|
|
405
|
+
reason_codes:[...(loop.progress.reason_codes ?? [])],fingerprint:loop.progress.fingerprint
|
|
406
|
+
} : null;
|
|
407
|
+
const actionKind=loop.pending_action?.action?.kind ?? loop.pending_action?.kind ?? null;
|
|
408
|
+
const pendingAction=loop.pending_action && actionKind ? {
|
|
409
|
+
action_id:loop.pending_action.action_id,request_sha256:loop.pending_action.request_sha256,kind:actionKind
|
|
410
|
+
} : null;
|
|
411
|
+
return {
|
|
412
|
+
schema:'deadbyte.autonomous-loop-state.v1',phase:legacyPublicLoopPhase(loop.phase),plan_id:loop.plan_id,plan_version:loop.plan_version,
|
|
413
|
+
current_step:currentStep,replan_count:loop.replan_count,progress,
|
|
414
|
+
pending_action:pendingAction,pending_approval:loop.pending_approval,wait_reason:loop.wait_reason
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
function withLoopResult(goal,events,result) {
|
|
418
|
+
const loop=publicLoopState(loopStateOrNull(goal,events));
|
|
419
|
+
return loop ? {...result,loop} : result;
|
|
420
|
+
}
|
|
421
|
+
function providerCircuitSnapshot(policy,events,observedAtUtc=new Date().toISOString()) {
|
|
422
|
+
if (policy.planner.backend !== 'openai_compatible') return null;
|
|
423
|
+
return deriveCircuit(events,providerCircuitId(policy.planner),policy.planner.circuit,observedAtUtc);
|
|
424
|
+
}
|
|
425
|
+
async function enterProviderCircuitWait({ctx,events,goal,policy,signingKeyPath,reason,circuit}) {
|
|
426
|
+
const loop=deriveLoopState(goal,events);
|
|
427
|
+
if (loop.phase !== 'WAITING') {
|
|
428
|
+
await appendEvent(ctx,events,signingKeyPath,'waiting_entered',{
|
|
429
|
+
reason,requires_approval:false,resume_phase:loop.phase,
|
|
430
|
+
provider_id:providerCircuitId(policy.planner),circuit_state:circuit.state,
|
|
431
|
+
next_probe_at_utc:circuit.next_probe_at_utc
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
await appendEvent(ctx,events,signingKeyPath,'goal_paused',{
|
|
435
|
+
reason,provider_id:providerCircuitId(policy.planner),circuit_state:circuit.state,
|
|
436
|
+
next_probe_at_utc:circuit.next_probe_at_utc
|
|
437
|
+
});
|
|
438
|
+
return {status:'paused',reason,circuit};
|
|
439
|
+
}
|
|
440
|
+
async function requestProviderWithCircuit({ctx,events,goal,policy,pending,signingKeyPath}) {
|
|
441
|
+
const providerId=providerCircuitId(policy.planner);
|
|
442
|
+
let circuit=providerCircuitSnapshot(policy,events);
|
|
443
|
+
let disposition=providerCallDisposition(circuit);
|
|
444
|
+
if (!disposition.allowed && disposition.reason==='half_open_probe_limit') {
|
|
445
|
+
await appendEvent(ctx,events,signingKeyPath,'provider_call_failed',{
|
|
446
|
+
provider_id:providerId,request_id:pending.request_id,failure_class:'transport',interrupted_probe:true
|
|
447
|
+
});
|
|
448
|
+
circuit=providerCircuitSnapshot(policy,events);
|
|
449
|
+
disposition=providerCallDisposition(circuit);
|
|
450
|
+
}
|
|
451
|
+
if (!disposition.allowed) {
|
|
452
|
+
const reason=disposition.reason==='circuit_unavailable'?'provider_circuit_unavailable':'provider_circuit_open';
|
|
453
|
+
return {waiting:await enterProviderCircuitWait({ctx,events,goal,policy,signingKeyPath,reason,circuit})};
|
|
454
|
+
}
|
|
455
|
+
if (disposition.probe) {
|
|
456
|
+
await appendEvent(ctx,events,signingKeyPath,'provider_probe_started',{
|
|
457
|
+
provider_id:providerId,request_id:pending.request_id
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
try {
|
|
461
|
+
const response=await requestProviderDecision(policy,pending.prompt);
|
|
462
|
+
await appendEvent(ctx,events,signingKeyPath,'provider_call_succeeded',{
|
|
463
|
+
provider_id:providerId,request_id:pending.request_id,probe:disposition.probe===true
|
|
464
|
+
});
|
|
465
|
+
return {response};
|
|
466
|
+
} catch (error) {
|
|
467
|
+
await appendEvent(ctx,events,signingKeyPath,'provider_call_failed',{
|
|
468
|
+
provider_id:providerId,request_id:pending.request_id,failure_class:classifyProviderFailure(error),
|
|
469
|
+
probe:disposition.probe===true
|
|
470
|
+
});
|
|
471
|
+
circuit=providerCircuitSnapshot(policy,events);
|
|
472
|
+
if (circuit.state==='OPEN'||circuit.state==='UNAVAILABLE') {
|
|
473
|
+
const reason=circuit.state==='UNAVAILABLE'?'provider_circuit_unavailable':'provider_circuit_open';
|
|
474
|
+
return {waiting:await enterProviderCircuitWait({ctx,events,goal,policy,signingKeyPath,reason,circuit})};
|
|
475
|
+
}
|
|
476
|
+
throw error;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
340
479
|
async function acceptPlannerDecision({ ctx, events, goal, state, policy, codingRuntime, signingKeyPath, plannerResponse }) {
|
|
341
480
|
let currentState = state;
|
|
342
481
|
let pending = currentState.pending_request ?? await requestPlanner(ctx,goal,events,currentState,policy,codingRuntime,signingKeyPath);
|
|
@@ -345,7 +484,9 @@ async function acceptPlannerDecision({ ctx, events, goal, state, policy, codingR
|
|
|
345
484
|
while (pending) {
|
|
346
485
|
let response;
|
|
347
486
|
if (policy.planner.backend === 'openai_compatible') {
|
|
348
|
-
|
|
487
|
+
const provider=await requestProviderWithCircuit({ctx,events,goal,policy,pending,signingKeyPath});
|
|
488
|
+
if (provider.waiting) return {needs_planner:false,rejected:false,paused:true,provider_waiting:true};
|
|
489
|
+
response=provider.response;
|
|
349
490
|
} else {
|
|
350
491
|
if (!suppliedResponse) return { needs_planner:true, request:pending };
|
|
351
492
|
if (suppliedResponse.request_id !== pending.request_id) throw new Error('planner response request_id mismatch');
|
|
@@ -357,8 +498,8 @@ async function acceptPlannerDecision({ ctx, events, goal, state, policy, codingR
|
|
|
357
498
|
}
|
|
358
499
|
let decision;
|
|
359
500
|
try {
|
|
360
|
-
decision =
|
|
361
|
-
validatePlanTransition(currentState.active_plan,decision.plan);
|
|
501
|
+
decision = parseRuntimePlannerDecision(response.raw_text,policy);
|
|
502
|
+
if (decision.schema !== 'deadbyte.autonomous-decision.v2') validatePlanTransition(currentState.active_plan,decision.plan);
|
|
362
503
|
} catch (error) {
|
|
363
504
|
const reason = truncated(error,512);
|
|
364
505
|
const attempt = 1 + events.filter(event => event.type === 'planner_rejected' &&
|
|
@@ -405,7 +546,9 @@ async function executeInspect({ ctx, events, goal, decisionEvent, decision, codi
|
|
|
405
546
|
const read = await codingRuntime.fileRead({ rootId:goal.root_id, relativePath:item.path, encoding:'utf8' });
|
|
406
547
|
const bytes = Buffer.byteLength(read.content,'utf8');
|
|
407
548
|
if (bytes > item.max_bytes) throw new Error(`planner inspect '${item.path}' exceeds requested max_bytes`);
|
|
408
|
-
contexts.push({ path:item.path, sha256:read.sha256, bytes:read.bytes, content:read.content
|
|
549
|
+
contexts.push({ path:item.path, sha256:read.sha256, bytes:read.bytes, content:read.content,
|
|
550
|
+
observed_at_utc:new Date().toISOString(), trust_class:'workspace_read',
|
|
551
|
+
relevance_epoch:Number.isInteger(decisionEvent.mutation_epoch) ? decisionEvent.mutation_epoch : 0 });
|
|
409
552
|
}
|
|
410
553
|
await appendEvent(ctx,events,signingKeyPath,'inspect_completed',{
|
|
411
554
|
decision_event_sha256:decisionEvent.event_sha256, contexts
|
|
@@ -546,34 +689,142 @@ async function runMutationProfiles({ ctx, events, goal, epoch, actionKey, policy
|
|
|
546
689
|
}
|
|
547
690
|
return results;
|
|
548
691
|
}
|
|
692
|
+
function patchActionCoordinates(state) {
|
|
693
|
+
const plan = state.active_plan ?? null;
|
|
694
|
+
const planId = SHA256_RE.test(plan?.plan_id ?? '')
|
|
695
|
+
? plan.plan_id
|
|
696
|
+
: sha256Object({ schema:'deadbyte.autonomous-plan-coordinate.v1', plan });
|
|
697
|
+
const planVersion = Number.isInteger(plan?.plan_version) && plan.plan_version >= 1
|
|
698
|
+
? plan.plan_version
|
|
699
|
+
: Math.max(1,Number(state.planner_round) || 1);
|
|
700
|
+
const activeStep = plan?.steps?.find(step => ['active','running','failed'].includes(step.status))
|
|
701
|
+
?? plan?.steps?.find(step => step.status === 'pending')
|
|
702
|
+
?? null;
|
|
703
|
+
const stepId = ID_RE.test(activeStep?.step_id ?? '')
|
|
704
|
+
? activeStep.step_id
|
|
705
|
+
: `decision-${Math.max(1,Number(state.planner_round) || 1)}`;
|
|
706
|
+
return { planId,planVersion,stepId };
|
|
707
|
+
}
|
|
708
|
+
function patchStartedForDecision(events, decisionEventSha) {
|
|
709
|
+
return [...events].reverse().find(event => event.type === 'action_started' &&
|
|
710
|
+
event.payload?.decision_event_sha256 === decisionEventSha && event.payload?.action?.kind === 'patch') ?? null;
|
|
711
|
+
}
|
|
712
|
+
function patchCommitForAction(events, actionId) {
|
|
713
|
+
return [...events].reverse().find(event => event.type === 'native_diff_committed' &&
|
|
714
|
+
event.payload?.action_id === actionId) ?? null;
|
|
715
|
+
}
|
|
716
|
+
function patchCompletionForAction(events, actionId) {
|
|
717
|
+
return [...events].reverse().find(event => event.type === 'action_completed' &&
|
|
718
|
+
event.payload?.action_id === actionId) ?? null;
|
|
719
|
+
}
|
|
720
|
+
async function verifyPatchDiff(nativeDiffRuntime,diffId) {
|
|
721
|
+
const verified = await nativeDiffRuntime.verify({ diffId });
|
|
722
|
+
if (!verified.ok || verified.current_state_matches !== true) {
|
|
723
|
+
throw new Error(`autonomous native diff verification failed: ${verified.reason ?? 'state mismatch'}`);
|
|
724
|
+
}
|
|
725
|
+
return verified;
|
|
726
|
+
}
|
|
727
|
+
async function appendPatchCommit({ctx,events,signingKeyPath,started,decisionEvent,verified,recovered=false}) {
|
|
728
|
+
const actionId = started.payload.action_id;
|
|
729
|
+
const prior = patchCommitForAction(events,actionId);
|
|
730
|
+
if (prior) return prior;
|
|
731
|
+
const action = started.payload.action;
|
|
732
|
+
return appendEvent(ctx,events,signingKeyPath,'native_diff_committed',{
|
|
733
|
+
action_id:actionId, decision_event_sha256:decisionEvent.event_sha256, diff_id:action.diff_id,
|
|
734
|
+
diff_receipt_sha256:verified.receipt_sha256, mutation_epoch:started.payload.target_mutation_epoch,
|
|
735
|
+
mutation_count:started.payload.mutation_count, operation_count:action.operation_count,
|
|
736
|
+
paths:action.paths, coding_receipts_verified:verified.coding_receipts_verified,
|
|
737
|
+
...(recovered ? { recovered:true } : {})
|
|
738
|
+
});
|
|
739
|
+
}
|
|
549
740
|
async function executePatch({ ctx, events, goal, state, decisionEvent, decision, nativeDiffRuntime,
|
|
550
|
-
policy, codingRuntime, signingKeyPath }) {
|
|
551
|
-
|
|
741
|
+
policy, codingRuntime, signingKeyPath, actionCoordinatesOverride = null }) {
|
|
742
|
+
let started = patchStartedForDecision(events,decisionEvent.event_sha256);
|
|
743
|
+
if (!started && state.mutation_count + decision.operations.length > policy.limits.max_mutations) {
|
|
552
744
|
await appendEvent(ctx,events,signingKeyPath,'goal_paused',{
|
|
553
745
|
reason:'mutation_limit', max_mutations:policy.limits.max_mutations
|
|
554
746
|
});
|
|
555
747
|
return { status:'paused' };
|
|
556
748
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
749
|
+
|
|
750
|
+
if (!started) {
|
|
751
|
+
const applicationScope = sha256Object({ schema:'deadbyte.autonomous-native-diff-scope.v1',
|
|
752
|
+
goal_id:goal.goal_id, decision_event_sha256:decisionEvent.event_sha256 });
|
|
753
|
+
const preview = await nativeDiffRuntime.preview({ rootId:goal.root_id,
|
|
754
|
+
operations:decision.operations, title:decision.summary, applicationScope });
|
|
755
|
+
const coordinates = actionCoordinatesOverride ?? patchActionCoordinates(state);
|
|
756
|
+
const action = { kind:'patch', diff_id:preview.diff_id,
|
|
757
|
+
operation_count:preview.operation_count, paths:preview.paths };
|
|
758
|
+
const identity = actionIdentity({ goalId:goal.goal_id, planId:coordinates.planId,
|
|
759
|
+
planVersion:coordinates.planVersion, stepId:coordinates.stepId, mutationEpoch:state.mutation_epoch,
|
|
760
|
+
decisionEventSha:decisionEvent.event_sha256, action });
|
|
761
|
+
started = await appendEvent(ctx,events,signingKeyPath,'action_started',{
|
|
762
|
+
...identity, decision_event_sha256:decisionEvent.event_sha256,
|
|
763
|
+
plan_id:coordinates.planId, plan_version:coordinates.planVersion, step_id:coordinates.stepId,
|
|
764
|
+
mutation_epoch:state.mutation_epoch, target_mutation_epoch:state.mutation_epoch + 1,
|
|
765
|
+
mutation_count:decision.operations.length, action
|
|
766
|
+
});
|
|
565
767
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
768
|
+
|
|
769
|
+
const actionId = started.payload.action_id;
|
|
770
|
+
const diffId = started.payload.action.diff_id;
|
|
771
|
+
const existingCompletion = patchCompletionForAction(events,actionId);
|
|
772
|
+
if (existingCompletion) {
|
|
773
|
+
const committed = patchCommitForAction(events,actionId);
|
|
774
|
+
if (!committed) throw new Error('completed patch action missing native diff commit');
|
|
775
|
+
const epoch = committed.payload.mutation_epoch;
|
|
776
|
+
const profiles = await runMutationProfiles({ ctx,events,goal,epoch,
|
|
777
|
+
actionKey:`mutation-${epoch}`,policy,codingRuntime,signingKeyPath });
|
|
778
|
+
return { status:profiles.some(item => item.status === 'paused') ? 'paused' : 'completed',
|
|
779
|
+
diff_id:diffId, mutation_epoch:epoch, profiles, recovered:true };
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
const reconciliation = await reconcileStartedAction({ startedEvent:started, journal:events,
|
|
783
|
+
runtimes:{ nativeDiffRuntime,codingRuntime } });
|
|
784
|
+
if (reconciliation.classification === 'ambiguous') {
|
|
785
|
+
if (!events.some(event => event.type === 'waiting_entered' && event.payload?.action_id === actionId)) {
|
|
786
|
+
await appendEvent(ctx,events,signingKeyPath,'waiting_entered',{
|
|
787
|
+
reason:'ambiguous_interrupted_action', action_id:actionId,
|
|
788
|
+
decision_event_sha256:decisionEvent.event_sha256, detail:truncated(reconciliation.reason,512)
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
await appendEvent(ctx,events,signingKeyPath,'goal_paused',{
|
|
792
|
+
reason:'ambiguous_interrupted_action', action_id:actionId,
|
|
793
|
+
decision_event_sha256:decisionEvent.event_sha256
|
|
794
|
+
});
|
|
795
|
+
return { status:'paused', reason:'ambiguous_interrupted_action' };
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
let verified;
|
|
799
|
+
let recovered = false;
|
|
800
|
+
if (reconciliation.classification === 'executed_verified') {
|
|
801
|
+
recovered = true;
|
|
802
|
+
verified = await verifyPatchDiff(nativeDiffRuntime,diffId);
|
|
803
|
+
if (!events.some(event => event.type === 'action_reconciled' && event.payload?.action_id === actionId)) {
|
|
804
|
+
await appendEvent(ctx,events,signingKeyPath,'action_reconciled',{
|
|
805
|
+
action_id:actionId, request_sha256:started.payload.request_sha256,
|
|
806
|
+
decision_event_sha256:decisionEvent.event_sha256,
|
|
807
|
+
classification:reconciliation.classification, evidence:reconciliation.evidence
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
} else {
|
|
811
|
+
await nativeDiffRuntime.apply({ diffId });
|
|
812
|
+
verified = await verifyPatchDiff(nativeDiffRuntime,diffId);
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
const committed = await appendPatchCommit({ctx,events,signingKeyPath,started,decisionEvent,verified,recovered});
|
|
816
|
+
if (!patchCompletionForAction(events,actionId)) {
|
|
817
|
+
await appendEvent(ctx,events,signingKeyPath,'action_completed',{
|
|
818
|
+
action_id:actionId, request_sha256:started.payload.request_sha256,
|
|
819
|
+
decision_event_sha256:decisionEvent.event_sha256, classification:'executed_verified',
|
|
820
|
+
diff_id:diffId, receipt_sha256:verified.receipt_sha256, recovered
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
const epoch = committed.payload.mutation_epoch;
|
|
573
824
|
const profiles = await runMutationProfiles({ ctx,events,goal,epoch,
|
|
574
825
|
actionKey:`mutation-${epoch}`,policy,codingRuntime,signingKeyPath });
|
|
575
826
|
return { status:profiles.some(item => item.status === 'paused') ? 'paused' : 'completed',
|
|
576
|
-
diff_id:
|
|
827
|
+
diff_id:diffId, mutation_epoch:epoch, profiles, recovered };
|
|
577
828
|
}
|
|
578
829
|
async function runRequiredReleaseProfiles({ ctx, events, goal, state, policy, codingRuntime, signingKeyPath }) {
|
|
579
830
|
const requiredIds = Object.entries(policy.profiles)
|
|
@@ -696,10 +947,251 @@ async function verifyReleaseReceipt({ ctx, goal, events, policy, verifyKeyPath,
|
|
|
696
947
|
journal_head_sha256:completion.event_sha256 };
|
|
697
948
|
}
|
|
698
949
|
|
|
950
|
+
function r34CompletedSteps(plan) {
|
|
951
|
+
return Array.isArray(plan?.steps) ? plan.steps.filter(step => step.status === 'completed').length : 0;
|
|
952
|
+
}
|
|
953
|
+
function r34ProgressHistory(events) {
|
|
954
|
+
const history=[];
|
|
955
|
+
for (const event of events) {
|
|
956
|
+
if (event.type === 'plan_replanned') history.push('replan');
|
|
957
|
+
if (event.type === 'progress_judged' && ['progress','stalled','regressed'].includes(event.payload?.verdict)) {
|
|
958
|
+
history.push(event.payload.verdict);
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
return history;
|
|
962
|
+
}
|
|
963
|
+
async function r34PhaseChange({ctx,events,goal,signingKeyPath,to,reason}) {
|
|
964
|
+
const loop=deriveLoopState(goal,events);
|
|
965
|
+
if (loop.phase === to) return loop;
|
|
966
|
+
await appendEvent(ctx,events,signingKeyPath,'phase_changed',{from:loop.phase,to,reason});
|
|
967
|
+
return deriveLoopState(goal,events);
|
|
968
|
+
}
|
|
969
|
+
async function r35EnterCritic({ctx,events,goal,signingKeyPath,failureClass,evidenceFingerprint,detail}) {
|
|
970
|
+
let loop=deriveLoopState(goal,events);
|
|
971
|
+
const fingerprint=SHA256_RE.test(evidenceFingerprint ?? '') ? evidenceFingerprint : sha256Object({
|
|
972
|
+
schema:'deadbyte.autonomous-critic-evidence.v1',failure_class:failureClass,detail:String(detail ?? '')
|
|
973
|
+
});
|
|
974
|
+
await appendEvent(ctx,events,signingKeyPath,'critic_classified',{
|
|
975
|
+
failure_class:failureClass,evidence_fingerprint:fingerprint,detail:truncated(detail ?? failureClass,1024)
|
|
976
|
+
});
|
|
977
|
+
loop=deriveLoopState(goal,events);
|
|
978
|
+
if (loop.phase !== 'CRITIC') loop=await r34PhaseChange({ctx,events,goal,signingKeyPath,to:'CRITIC',reason:failureClass});
|
|
979
|
+
return loop;
|
|
980
|
+
}
|
|
981
|
+
async function r35BeginRepair({ctx,events,goal,signingKeyPath,hypothesis}) {
|
|
982
|
+
let loop=deriveLoopState(goal,events);
|
|
983
|
+
if (loop.phase !== 'CRITIC' && loop.phase !== 'REPAIR') throw new Error(`R35 repair requires CRITIC/REPAIR phase, got ${loop.phase}`);
|
|
984
|
+
if (loop.phase === 'CRITIC') loop=await r34PhaseChange({ctx,events,goal,signingKeyPath,to:'REPAIR',reason:'critic_ready'});
|
|
985
|
+
const priorHypothesis=loop.critic?.detail ?? hypothesis;
|
|
986
|
+
const previousFingerprint=repairFingerprint({plan:loop.plan,hypothesis:priorHypothesis});
|
|
987
|
+
await appendEvent(ctx,events,signingKeyPath,'repair_started',{
|
|
988
|
+
previous_fingerprint:previousFingerprint,hypothesis:priorHypothesis
|
|
989
|
+
});
|
|
990
|
+
return {loop:deriveLoopState(goal,events),previousFingerprint};
|
|
991
|
+
}
|
|
992
|
+
async function r35CompleteRepair({ctx,events,goal,signingKeyPath,previousFingerprint,hypothesis}) {
|
|
993
|
+
const loop=deriveLoopState(goal,events);
|
|
994
|
+
const nextFingerprint=repairFingerprint({plan:loop.plan,hypothesis});
|
|
995
|
+
await appendEvent(ctx,events,signingKeyPath,'repair_completed',{
|
|
996
|
+
previous_fingerprint:previousFingerprint,repair_fingerprint:nextFingerprint,hypothesis
|
|
997
|
+
});
|
|
998
|
+
return deriveLoopState(goal,events);
|
|
999
|
+
}
|
|
1000
|
+
async function r34EnterWaiting({ctx,events,goal,signingKeyPath,reason,resumePhase}) {
|
|
1001
|
+
const loop=deriveLoopState(goal,events);
|
|
1002
|
+
if (loop.phase !== 'WAITING') {
|
|
1003
|
+
await appendEvent(ctx,events,signingKeyPath,'waiting_entered',{
|
|
1004
|
+
reason,requires_approval:true,resume_phase:resumePhase ?? loop.phase
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
await appendEvent(ctx,events,signingKeyPath,'goal_paused',{reason});
|
|
1008
|
+
return {status:'paused',reason};
|
|
1009
|
+
}
|
|
1010
|
+
function r34ReasonHash(goal,decisionEvent,reason) {
|
|
1011
|
+
return sha256Object({schema:'deadbyte.autonomous-plan-reason.v1',goal_id:goal.goal_id,
|
|
1012
|
+
decision_event_sha256:decisionEvent.event_sha256,reason:String(reason ?? '')});
|
|
1013
|
+
}
|
|
1014
|
+
async function executeR34Decision({ctx,events,goal,state,decisionEvent,decision,policy,codingRuntime,
|
|
1015
|
+
nativeDiffRuntime,machineFsRuntime,observationRuntime,processRuntime,assertRunAuthority,
|
|
1016
|
+
signingKeyPath,verifyKeyPath}) {
|
|
1017
|
+
let loop=deriveLoopState(goal,events);
|
|
1018
|
+
if (decision.kind === 'plan_create') {
|
|
1019
|
+
if (loop.phase !== 'PLAN' || loop.plan) throw new Error('R34 plan_create requires empty PLANNING state');
|
|
1020
|
+
const plan=createPlan({goalId:goal.goal_id,title:decision.title,steps:decision.steps,
|
|
1021
|
+
reasonHash:r34ReasonHash(goal,decisionEvent,decision.reason ?? 'initial_plan')});
|
|
1022
|
+
await appendEvent(ctx,events,signingKeyPath,'plan_created',{decision_event_sha256:decisionEvent.event_sha256,plan});
|
|
1023
|
+
await r34PhaseChange({ctx,events,goal,signingKeyPath,to:'INSPECT',reason:'plan_ready'});
|
|
1024
|
+
return {status:'completed',plan};
|
|
1025
|
+
}
|
|
1026
|
+
if (!loop.plan) throw new Error(`R34 ${decision.kind} requires a durable plan`);
|
|
1027
|
+
|
|
1028
|
+
if (decision.kind === 'inspect') {
|
|
1029
|
+
if (loop.phase !== 'INSPECT') throw new Error(`R34 inspect requires INSPECTING phase, got ${loop.phase}`);
|
|
1030
|
+
const contexts=[];
|
|
1031
|
+
for (const item of decision.reads) {
|
|
1032
|
+
const read=await codingRuntime.fileRead({rootId:goal.root_id,relativePath:item.path,encoding:'utf8'});
|
|
1033
|
+
const bytes=Buffer.byteLength(read.content,'utf8');
|
|
1034
|
+
if (bytes > item.max_bytes) throw new Error(`R34 inspect '${item.path}' exceeds requested max_bytes`);
|
|
1035
|
+
contexts.push({path:item.path,sha256:read.sha256,bytes:read.bytes,content:read.content,
|
|
1036
|
+
observed_at_utc:new Date().toISOString(),trust_class:'workspace_read',relevance_epoch:state.mutation_epoch});
|
|
1037
|
+
}
|
|
1038
|
+
const evidenceHead=sha256Object({schema:'deadbyte.autonomous-inspection-evidence.v1',contexts});
|
|
1039
|
+
await appendEvent(ctx,events,signingKeyPath,'inspection_completed',{
|
|
1040
|
+
decision_event_sha256:decisionEvent.event_sha256,evidence_head_sha256:evidenceHead,contexts
|
|
1041
|
+
});
|
|
1042
|
+
await r34PhaseChange({ctx,events,goal,signingKeyPath,to:'ACT',reason:'inspection_complete'});
|
|
1043
|
+
return {status:'completed',contexts,evidence_head_sha256:evidenceHead};
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
if (decision.kind === 'act') {
|
|
1047
|
+
if (loop.phase !== 'ACT') throw new Error(`R34 act requires ACTING phase, got ${loop.phase}`);
|
|
1048
|
+
const before={mutation_epoch:state.mutation_epoch,completed_steps:r34CompletedSteps(loop.plan),
|
|
1049
|
+
evidence_head:loop.evidence_head_sha256,release_ready:false,
|
|
1050
|
+
acceptance_failures:state.observations.filter(item=>item?.passed===false).length};
|
|
1051
|
+
let outcome;
|
|
1052
|
+
if (decision.action.kind === 'patch') {
|
|
1053
|
+
await assertRunAuthority(goal.root_id);
|
|
1054
|
+
const currentStep=loop.current_step;
|
|
1055
|
+
if (!currentStep) throw new Error('R34 patch requires active plan step');
|
|
1056
|
+
try {
|
|
1057
|
+
outcome=await executePatch({ctx,events,goal,state,decisionEvent,
|
|
1058
|
+
decision:{operations:decision.action.operations,summary:`R34 ${currentStep.step_id}`},nativeDiffRuntime,
|
|
1059
|
+
policy,codingRuntime,signingKeyPath,actionCoordinatesOverride:{planId:loop.plan_id,
|
|
1060
|
+
planVersion:loop.plan_version,stepId:currentStep.step_id}});
|
|
1061
|
+
} catch (error) {
|
|
1062
|
+
const detail=truncated(error,512);
|
|
1063
|
+
if (!/^native diff precondition '.+' (?:mismatch|expected absent, found [0-9a-f]{64})$/i.test(detail)) throw error;
|
|
1064
|
+
await appendEvent(ctx,events,signingKeyPath,'action_precondition_failed',{
|
|
1065
|
+
decision_event_sha256:decisionEvent.event_sha256,reason:'stale_sha',detail
|
|
1066
|
+
});
|
|
1067
|
+
await r35EnterCritic({ctx,events,goal,signingKeyPath,failureClass:'stale_precondition',detail});
|
|
1068
|
+
return {status:'blocked',reason:'stale_sha'};
|
|
1069
|
+
}
|
|
1070
|
+
} else if (decision.action.kind === 'run_profile') {
|
|
1071
|
+
await assertRunAuthority(goal.root_id);
|
|
1072
|
+
outcome=await executeProfile({ctx,events,goalId:goal.goal_id,
|
|
1073
|
+
actionKey:`r34-${decisionEvent.event_sha256}`,profileId:decision.action.profile_id,
|
|
1074
|
+
epoch:state.mutation_epoch,policy,codingRuntime,signingKeyPath,r34ResumePhase:loop.phase});
|
|
1075
|
+
} else if (decision.action.kind === 'delegate') {
|
|
1076
|
+
outcome=await executeDelegate({ctx,events,goal,decisionEvent,
|
|
1077
|
+
decision:{operation:decision.action.operation},policy,
|
|
1078
|
+
runtimes:{machineFsRuntime,observationRuntime,processRuntime},assertRunAuthority,signingKeyPath,verifyKeyPath});
|
|
1079
|
+
} else {
|
|
1080
|
+
throw new Error(`unsupported R34 action '${String(decision.action.kind)}'`);
|
|
1081
|
+
}
|
|
1082
|
+
if (outcome.status === 'paused') return outcome;
|
|
1083
|
+
await r34PhaseChange({ctx,events,goal,signingKeyPath,to:'VERIFY',reason:'action_observed'});
|
|
1084
|
+
const afterState=deriveState(goal,events);
|
|
1085
|
+
loop=deriveLoopState(goal,events);
|
|
1086
|
+
const after={mutation_epoch:afterState.mutation_epoch,completed_steps:r34CompletedSteps(loop.plan),
|
|
1087
|
+
evidence_head:loop.evidence_head_sha256,release_ready:false,
|
|
1088
|
+
acceptance_failures:afterState.observations.filter(item=>item?.passed===false).length};
|
|
1089
|
+
const evidence={
|
|
1090
|
+
native_diff_verified:decision.action.kind === 'patch' && afterState.mutation_epoch > state.mutation_epoch,
|
|
1091
|
+
new_profile_evidence:decision.action.kind === 'run_profile' && outcome.status === 'passed' &&
|
|
1092
|
+
afterState.observations.length > state.observations.length,
|
|
1093
|
+
diagnostic_narrowed:decision.action.kind === 'delegate' && afterState.observations.length > state.observations.length,
|
|
1094
|
+
interrupted_action_recovered:outcome.recovered === true
|
|
1095
|
+
};
|
|
1096
|
+
const progress=judgeProgress({before,after,decision,evidence});
|
|
1097
|
+
await appendEvent(ctx,events,signingKeyPath,'progress_judged',{
|
|
1098
|
+
decision_event_sha256:decisionEvent.event_sha256,...progress
|
|
1099
|
+
});
|
|
1100
|
+
if (progress.verdict === 'regressed') {
|
|
1101
|
+
await r35EnterCritic({ctx,events,goal,signingKeyPath,failureClass:'verification_failure',
|
|
1102
|
+
evidenceFingerprint:progress.fingerprint,detail:'verification regressed against observed acceptance evidence'});
|
|
1103
|
+
} else if (progress.verdict === 'stalled') {
|
|
1104
|
+
const disposition=stallDisposition({history:r34ProgressHistory(events),limits:policy.limits});
|
|
1105
|
+
if (disposition.action === 'replan') {
|
|
1106
|
+
await r35EnterCritic({ctx,events,goal,signingKeyPath,failureClass:'no_progress',
|
|
1107
|
+
evidenceFingerprint:progress.fingerprint,detail:disposition.reason});
|
|
1108
|
+
} else if (disposition.action === 'wait') {
|
|
1109
|
+
await r35EnterCritic({ctx,events,goal,signingKeyPath,failureClass:'no_progress',
|
|
1110
|
+
evidenceFingerprint:progress.fingerprint,detail:disposition.reason});
|
|
1111
|
+
return r34EnterWaiting({ctx,events,goal,signingKeyPath,reason:'no_progress_after_replan',resumePhase:'CRITIC'});
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
return outcome;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
if (decision.kind === 'step_complete') {
|
|
1118
|
+
if (loop.phase !== 'VERIFY') throw new Error(`R34 step_complete requires VERIFYING phase, got ${loop.phase}`);
|
|
1119
|
+
const beforeCount=r34CompletedSteps(loop.plan);
|
|
1120
|
+
const plan=completePlanStep(loop.plan,{stepId:decision.step_id,evidence:decision.evidence});
|
|
1121
|
+
await appendEvent(ctx,events,signingKeyPath,'step_completed',{
|
|
1122
|
+
decision_event_sha256:decisionEvent.event_sha256,step_id:decision.step_id,evidence:decision.evidence,plan
|
|
1123
|
+
});
|
|
1124
|
+
const progress=judgeProgress({
|
|
1125
|
+
before:{mutation_epoch:state.mutation_epoch,completed_steps:beforeCount},
|
|
1126
|
+
after:{mutation_epoch:state.mutation_epoch,completed_steps:r34CompletedSteps(plan)},
|
|
1127
|
+
decision,evidence:{step_evidence_verified:true}
|
|
1128
|
+
});
|
|
1129
|
+
await appendEvent(ctx,events,signingKeyPath,'progress_judged',{
|
|
1130
|
+
decision_event_sha256:decisionEvent.event_sha256,...progress
|
|
1131
|
+
});
|
|
1132
|
+
const target=r34PlanIsComplete(plan)?'PLAN':'INSPECT';
|
|
1133
|
+
await r34PhaseChange({ctx,events,goal,signingKeyPath,to:target,reason:r34PlanIsComplete(plan)?'plan_complete':'next_plan_step'});
|
|
1134
|
+
return {status:'completed',plan};
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
if (decision.kind === 'replan') {
|
|
1138
|
+
if (!['CRITIC','REPAIR'].includes(loop.phase)) {
|
|
1139
|
+
if (!['VERIFY','PLAN'].includes(loop.phase)) throw new Error(`R35 replan invalid from ${loop.phase}`);
|
|
1140
|
+
loop=await r35EnterCritic({ctx,events,goal,signingKeyPath,failureClass:'insufficient_proof',
|
|
1141
|
+
evidenceFingerprint:loop.progress?.fingerprint,detail:decision.reason});
|
|
1142
|
+
}
|
|
1143
|
+
const repair=await r35BeginRepair({ctx,events,goal,signingKeyPath,hypothesis:decision.reason});
|
|
1144
|
+
loop=repair.loop;
|
|
1145
|
+
const completed=loop.plan.steps.filter(step=>step.status==='completed').map(step=>structuredClone(step));
|
|
1146
|
+
const plan=replanPlan(loop.plan,{steps:[...completed,...decision.steps],
|
|
1147
|
+
reasonHash:r34ReasonHash(goal,decisionEvent,decision.reason)});
|
|
1148
|
+
await appendEvent(ctx,events,signingKeyPath,'plan_replanned',{
|
|
1149
|
+
decision_event_sha256:decisionEvent.event_sha256,reason:decision.reason,plan
|
|
1150
|
+
});
|
|
1151
|
+
await r35CompleteRepair({ctx,events,goal,signingKeyPath,previousFingerprint:repair.previousFingerprint,
|
|
1152
|
+
hypothesis:decision.reason});
|
|
1153
|
+
await r34PhaseChange({ctx,events,goal,signingKeyPath,to:'INSPECT',reason:'repair_ready'});
|
|
1154
|
+
return {status:'completed',plan};
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
if (decision.kind === 'pause') {
|
|
1158
|
+
return r34EnterWaiting({ctx,events,goal,signingKeyPath,reason:decision.reason,resumePhase:loop.phase});
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
if (decision.kind === 'finish') {
|
|
1162
|
+
if (!r34PlanIsComplete(loop.plan)) {
|
|
1163
|
+
await appendEvent(ctx,events,signingKeyPath,'plan_guard_blocked',{
|
|
1164
|
+
decision_event_sha256:decisionEvent.event_sha256,action:'finish',
|
|
1165
|
+
reason:'plan_incomplete_blocks_finish',plan_id:loop.plan_id,plan_version:loop.plan_version
|
|
1166
|
+
});
|
|
1167
|
+
return {status:'blocked',reason:'plan_incomplete_blocks_finish'};
|
|
1168
|
+
}
|
|
1169
|
+
if (loop.phase !== 'PLAN') throw new Error(`R34 finish requires PLANNING phase, got ${loop.phase}`);
|
|
1170
|
+
await appendEvent(ctx,events,signingKeyPath,'finish_requested',{
|
|
1171
|
+
decision_event_sha256:decisionEvent.event_sha256,mutation_epoch:state.mutation_epoch,
|
|
1172
|
+
planner_summary:decision.summary ?? 'R34 finish'
|
|
1173
|
+
});
|
|
1174
|
+
await r34PhaseChange({ctx,events,goal,signingKeyPath,to:'RELEASE',reason:'finish_requested'});
|
|
1175
|
+
return {status:'finish_requested'};
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
throw new Error(`unsupported R34 decision '${String(decision.kind)}'`);
|
|
1179
|
+
}
|
|
1180
|
+
|
|
699
1181
|
async function executeDecision({ ctx, events, goal, state, decisionEvent, policy, codingRuntime,
|
|
700
1182
|
nativeDiffRuntime, machineFsRuntime, observationRuntime, processRuntime, assertRunAuthority,
|
|
701
1183
|
signingKeyPath, verifyKeyPath }) {
|
|
702
1184
|
const decision = decisionEvent.decision;
|
|
1185
|
+
if (decision?.schema === 'deadbyte.autonomous-decision.v2') {
|
|
1186
|
+
const outcome=await executeR34Decision({ctx,events,goal,state,decisionEvent,decision,policy,codingRuntime,
|
|
1187
|
+
nativeDiffRuntime,machineFsRuntime,observationRuntime,processRuntime,assertRunAuthority,
|
|
1188
|
+
signingKeyPath,verifyKeyPath});
|
|
1189
|
+
await appendEvent(ctx,events,signingKeyPath,'decision_completed',{
|
|
1190
|
+
decision_event_sha256:decisionEvent.event_sha256,action:decision.kind,
|
|
1191
|
+
outcome_status:outcome.status ?? 'completed'
|
|
1192
|
+
});
|
|
1193
|
+
return outcome;
|
|
1194
|
+
}
|
|
703
1195
|
if (repeatedDecisionCount(state,decision) >= 3) {
|
|
704
1196
|
await appendEvent(ctx,events,signingKeyPath,'goal_paused',{ reason:'no_progress_repeated_decision' });
|
|
705
1197
|
return { status:'paused' };
|
|
@@ -757,6 +1249,24 @@ function terminalState(state) {
|
|
|
757
1249
|
return ['succeeded','cancelled'].includes(state.state);
|
|
758
1250
|
}
|
|
759
1251
|
function pauseState(state) { return state.state === 'paused'; }
|
|
1252
|
+
async function resumeProviderWaitIfReady({ctx,journal,goal,state,policy,signingKeyPath}) {
|
|
1253
|
+
if (state.state!=='paused'||state.reason!=='provider_circuit_open'||policy.planner.backend!=='openai_compatible') return state;
|
|
1254
|
+
const circuit=providerCircuitSnapshot(policy,journal);
|
|
1255
|
+
const disposition=providerCallDisposition(circuit);
|
|
1256
|
+
if (!disposition.allowed||circuit.state!=='HALF_OPEN') return state;
|
|
1257
|
+
const waiting=[...journal].reverse().find(event=>event.type==='waiting_entered'&&event.payload?.reason==='provider_circuit_open')??null;
|
|
1258
|
+
const resumePhase=typeof waiting?.payload?.resume_phase==='string'?waiting.payload.resume_phase:'PLAN';
|
|
1259
|
+
await appendEvent(ctx,journal,signingKeyPath,'waiting_resumed',{
|
|
1260
|
+
to:resumePhase,reason:'provider_circuit_half_open',approved_at_utc:new Date().toISOString()
|
|
1261
|
+
});
|
|
1262
|
+
await appendEvent(ctx,journal,signingKeyPath,'goal_resumed',{
|
|
1263
|
+
previous_reason:'provider_circuit_open',approved_at_utc:new Date().toISOString()
|
|
1264
|
+
});
|
|
1265
|
+
return deriveState(goal,journal);
|
|
1266
|
+
}
|
|
1267
|
+
function isAuthorityUnavailable(error) {
|
|
1268
|
+
return /(?:disarmed|lease|outside active lease|authority unavailable)/i.test(String(error?.message ?? error));
|
|
1269
|
+
}
|
|
760
1270
|
|
|
761
1271
|
export function createAutonomousRuntime({ policy, codingRuntime, nativeDiffRuntime, machineFsRuntime = null,
|
|
762
1272
|
observationRuntime = null, processRuntime = null, signingKeyPath, verifyKeyPath }) {
|
|
@@ -773,6 +1283,13 @@ export function createAutonomousRuntime({ policy, codingRuntime, nativeDiffRunti
|
|
|
773
1283
|
profile_ids:Object.keys(policy.profiles), policy_sha256:policy.policy_sha256,
|
|
774
1284
|
coding_policy_sha256:policy.coding_policy_sha256 };
|
|
775
1285
|
}
|
|
1286
|
+
async function providerCircuitStatus({goalId}) {
|
|
1287
|
+
if (policy.planner.backend!=='openai_compatible') return null;
|
|
1288
|
+
const ctx=goalContext(policy,goalId);
|
|
1289
|
+
await loadGoal(ctx,policy,verifyKeyPath);
|
|
1290
|
+
const journal=await readEvents(ctx,verifyKeyPath);
|
|
1291
|
+
return providerCircuitSnapshot(policy,journal);
|
|
1292
|
+
}
|
|
776
1293
|
|
|
777
1294
|
async function assertRunAuthority(rootId) {
|
|
778
1295
|
const autonomous = await assertAutonomousArmed(policy,rootId);
|
|
@@ -812,8 +1329,10 @@ export function createAutonomousRuntime({ policy, codingRuntime, nativeDiffRunti
|
|
|
812
1329
|
const goal = await loadGoal(ctx,policy,verifyKeyPath);
|
|
813
1330
|
const journal = await readEvents(ctx,verifyKeyPath);
|
|
814
1331
|
const derived = deriveState(goal,journal);
|
|
1332
|
+
const loop = publicLoopState(loopStateOrNull(goal,journal));
|
|
815
1333
|
return { status:'ok', goal_id:goalId, goal_sha256:goal.goal_sha256,
|
|
816
|
-
title:goal.title, root_id:goal.root_id, journal_verified:true, ...derived
|
|
1334
|
+
title:goal.title, root_id:goal.root_id, journal_verified:true, ...derived,
|
|
1335
|
+
...(loop ? {loop} : {}) };
|
|
817
1336
|
}
|
|
818
1337
|
|
|
819
1338
|
async function events({ goalId, fromSeq = 1, limit = 100 }) {
|
|
@@ -851,16 +1370,25 @@ export function createAutonomousRuntime({ policy, codingRuntime, nativeDiffRunti
|
|
|
851
1370
|
const goal = await loadGoal(ctx,policy,verifyKeyPath);
|
|
852
1371
|
const journal = await readEvents(ctx,verifyKeyPath);
|
|
853
1372
|
const current = deriveState(goal,journal);
|
|
854
|
-
if (terminalState(current)) return { status:'terminal', goal_id:goalId, state:current.state };
|
|
1373
|
+
if (terminalState(current)) return withLoopResult(goal,journal,{ status:'terminal', goal_id:goalId, state:current.state });
|
|
855
1374
|
if (!pauseState(current)) throw new Error('autonomous goal is not paused');
|
|
856
1375
|
if (decision === 'reject') {
|
|
857
1376
|
await appendEvent(ctx,journal,signingKeyPath,'goal_cancelled',{ reason:'resume_rejected' });
|
|
858
|
-
return { status:'rejected', goal_id:goalId, state:'cancelled' };
|
|
1377
|
+
return withLoopResult(goal,journal,{ status:'rejected', goal_id:goalId, state:'cancelled' });
|
|
1378
|
+
}
|
|
1379
|
+
if (hasR34Loop(journal)) {
|
|
1380
|
+
await assertRunAuthority(goal.root_id);
|
|
1381
|
+
const waiting=[...journal].reverse().find(event=>event.type==='waiting_entered') ?? null;
|
|
1382
|
+
const resumePhase=typeof waiting?.payload?.resume_phase === 'string' ? waiting.payload.resume_phase : 'PLAN';
|
|
1383
|
+
await appendEvent(ctx,journal,signingKeyPath,'waiting_resumed',{
|
|
1384
|
+
to:resumePhase,reason:waiting?.payload?.reason ?? current.reason ?? 'operator_approved',
|
|
1385
|
+
approved_at_utc:new Date().toISOString()
|
|
1386
|
+
});
|
|
859
1387
|
}
|
|
860
1388
|
await appendEvent(ctx,journal,signingKeyPath,'goal_resumed',{
|
|
861
1389
|
previous_reason:current.reason, approved_at_utc:new Date().toISOString()
|
|
862
1390
|
});
|
|
863
|
-
return { status:'approved', goal_id:goalId, state:'running' };
|
|
1391
|
+
return withLoopResult(goal,journal,{ status:'approved', goal_id:goalId, state:'running' });
|
|
864
1392
|
} finally {
|
|
865
1393
|
await releaseLock(ctx);
|
|
866
1394
|
}
|
|
@@ -927,35 +1455,60 @@ export function createAutonomousRuntime({ policy, codingRuntime, nativeDiffRunti
|
|
|
927
1455
|
if (!Number.isInteger(maxCycles) || maxCycles < 1 || maxCycles > 32) throw new Error('autonomous max_cycles must be in [1,32]');
|
|
928
1456
|
const ctx = goalContext(policy,goalId);
|
|
929
1457
|
const goal = await loadGoal(ctx,policy,verifyKeyPath);
|
|
930
|
-
await assertRunAuthority(goal.root_id);
|
|
931
1458
|
await acquireLock(ctx);
|
|
932
1459
|
try {
|
|
933
1460
|
const journal = await readEvents(ctx,verifyKeyPath);
|
|
934
1461
|
let state = deriveState(goal,journal);
|
|
935
|
-
if (terminalState(state)) return { status:'terminal', goal_id:goalId, ...state };
|
|
936
|
-
|
|
1462
|
+
if (terminalState(state)) return withLoopResult(goal,journal,{ status:'terminal', goal_id:goalId, ...state });
|
|
1463
|
+
state=await resumeProviderWaitIfReady({ctx,journal,goal,state,policy,signingKeyPath});
|
|
1464
|
+
if (pauseState(state)) return withLoopResult(goal,journal,{ status:'paused', goal_id:goalId, ...state });
|
|
1465
|
+
const loopBeforeAuthority = loopStateOrNull(goal,journal);
|
|
1466
|
+
try {
|
|
1467
|
+
await assertRunAuthority(goal.root_id);
|
|
1468
|
+
} catch (error) {
|
|
1469
|
+
if (!loopBeforeAuthority || !isAuthorityUnavailable(error)) throw error;
|
|
1470
|
+
const waiting=await r34EnterWaiting({ctx,events:journal,goal,signingKeyPath,
|
|
1471
|
+
reason:'authority_unavailable',resumePhase:loopBeforeAuthority.phase});
|
|
1472
|
+
state=deriveState(goal,journal);
|
|
1473
|
+
return withLoopResult(goal,journal,{...waiting,goal_id:goalId,...state});
|
|
1474
|
+
}
|
|
937
1475
|
if (await consumeCancel(ctx,journal,signingKeyPath,verifyKeyPath)) {
|
|
938
|
-
state = deriveState(goal,journal); return { status:'cancelled', goal_id:goalId, ...state };
|
|
1476
|
+
state = deriveState(goal,journal); return withLoopResult(goal,journal,{ status:'cancelled', goal_id:goalId, ...state });
|
|
939
1477
|
}
|
|
940
1478
|
await appendEvent(ctx,journal,signingKeyPath,'goal_run_started',{ max_cycles:maxCycles });
|
|
941
1479
|
let cycles = 0; let suppliedResponse = plannerResponse;
|
|
942
1480
|
while (cycles < maxCycles) {
|
|
943
1481
|
state = deriveState(goal,journal);
|
|
944
|
-
if (terminalState(state) || pauseState(state)) return { status:state.state, goal_id:goalId, ...state };
|
|
1482
|
+
if (terminalState(state) || pauseState(state)) return withLoopResult(goal,journal,{ status:state.state, goal_id:goalId, ...state });
|
|
945
1483
|
if (await consumeCancel(ctx,journal,signingKeyPath,verifyKeyPath)) {
|
|
946
|
-
state = deriveState(goal,journal); return { status:'cancelled', goal_id:goalId, ...state };
|
|
1484
|
+
state = deriveState(goal,journal); return withLoopResult(goal,journal,{ status:'cancelled', goal_id:goalId, ...state });
|
|
947
1485
|
}
|
|
948
1486
|
if (state.pending_decision) {
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
1487
|
+
let outcome;
|
|
1488
|
+
try {
|
|
1489
|
+
outcome = await executeDecision({ ctx,events:journal,goal,state,
|
|
1490
|
+
decisionEvent:state.pending_decision,policy,codingRuntime,nativeDiffRuntime,machineFsRuntime,
|
|
1491
|
+
observationRuntime,processRuntime,assertRunAuthority,signingKeyPath,verifyKeyPath });
|
|
1492
|
+
} catch (error) {
|
|
1493
|
+
const loop=loopStateOrNull(goal,journal);
|
|
1494
|
+
if (!loop || loop.pending_action || !isAuthorityUnavailable(error)) throw error;
|
|
1495
|
+
outcome=await r34EnterWaiting({ctx,events:journal,goal,signingKeyPath,
|
|
1496
|
+
reason:'authority_unavailable',resumePhase:loop.phase});
|
|
1497
|
+
}
|
|
952
1498
|
cycles += 1; state = deriveState(goal,journal);
|
|
953
|
-
if (outcome.status === 'paused' || pauseState(state)) return { status:'paused', goal_id:goalId, ...state };
|
|
1499
|
+
if (outcome.status === 'paused' || pauseState(state)) return withLoopResult(goal,journal,{ status:'paused', goal_id:goalId, ...state });
|
|
954
1500
|
if (outcome.status === 'finish_requested') {
|
|
955
1501
|
const gate = await releaseGateLocked(ctx,goal,journal);
|
|
956
1502
|
state = deriveState(goal,journal);
|
|
957
|
-
if (gate.status === 'passed') return { status:'completed', goal_id:goalId, release:gate, ...state };
|
|
958
|
-
if (gate.status === 'paused') return { status:'paused', goal_id:goalId, release:gate, ...state };
|
|
1503
|
+
if (gate.status === 'passed') return withLoopResult(goal,journal,{ status:'completed', goal_id:goalId, release:gate, ...state });
|
|
1504
|
+
if (gate.status === 'paused') return withLoopResult(goal,journal,{ status:'paused', goal_id:goalId, release:gate, ...state });
|
|
1505
|
+
const releaseLoop=loopStateOrNull(goal,journal);
|
|
1506
|
+
if (releaseLoop?.phase === 'RELEASE') {
|
|
1507
|
+
await r35EnterCritic({ctx,events:journal,goal,signingKeyPath,failureClass:'verification_failure',
|
|
1508
|
+
evidenceFingerprint:sha256Object({schema:'deadbyte.autonomous-release-failure.v1',gate}),
|
|
1509
|
+
detail:`release gate ${gate.status}: ${gate.reason ?? 'required profile failure'}`});
|
|
1510
|
+
state=deriveState(goal,journal);
|
|
1511
|
+
}
|
|
959
1512
|
}
|
|
960
1513
|
continue;
|
|
961
1514
|
}
|
|
@@ -964,18 +1517,18 @@ export function createAutonomousRuntime({ policy, codingRuntime, nativeDiffRunti
|
|
|
964
1517
|
suppliedResponse = null;
|
|
965
1518
|
if (accepted?.needs_planner) {
|
|
966
1519
|
state = deriveState(goal,journal);
|
|
967
|
-
return { status:'input_required', goal_id:goalId,
|
|
1520
|
+
return withLoopResult(goal,journal,{ status:'input_required', goal_id:goalId,
|
|
968
1521
|
planner_request:{ request_id:accepted.request.request_id,
|
|
969
1522
|
planner_round:accepted.request.planner_round,
|
|
970
1523
|
mutation_epoch:accepted.request.mutation_epoch,
|
|
971
1524
|
prompt:accepted.request.prompt,
|
|
972
|
-
prompt_sha256:accepted.request.prompt_sha256 }, ...state };
|
|
1525
|
+
prompt_sha256:accepted.request.prompt_sha256 }, ...state });
|
|
973
1526
|
}
|
|
974
1527
|
state = deriveState(goal,journal);
|
|
975
|
-
if (pauseState(state)) return { status:'paused', goal_id:goalId, ...state };
|
|
1528
|
+
if (pauseState(state)) return withLoopResult(goal,journal,{ status:'paused', goal_id:goalId, ...state });
|
|
976
1529
|
}
|
|
977
1530
|
state = deriveState(goal,journal);
|
|
978
|
-
return { status:'yielded', goal_id:goalId, cycles, ...state };
|
|
1531
|
+
return withLoopResult(goal,journal,{ status:'yielded', goal_id:goalId, cycles, ...state });
|
|
979
1532
|
} finally { await releaseLock(ctx); }
|
|
980
1533
|
}
|
|
981
1534
|
|
|
@@ -988,6 +1541,6 @@ export function createAutonomousRuntime({ policy, codingRuntime, nativeDiffRunti
|
|
|
988
1541
|
return verifyReleaseReceipt({ ctx,goal,events:journal,policy,verifyKeyPath,nativeDiffRuntime,codingRuntime });
|
|
989
1542
|
}
|
|
990
1543
|
|
|
991
|
-
return Object.freeze({ policy, sessionStatus, submit, run, status, events, cancel, approve,
|
|
1544
|
+
return Object.freeze({ policy, sessionStatus, providerCircuitStatus, submit, run, status, events, cancel, approve,
|
|
992
1545
|
releaseGate, verify });
|
|
993
1546
|
}
|