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
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { access } from 'node:fs/promises';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { defaultPrivateKeyPath, defaultPublicKeyPath } from './trust.mjs';
|
|
6
|
+
import { createCodingRuntime, loadCodingPolicy } from './coding-plane.mjs';
|
|
7
|
+
import { loadAutonomousPolicy } from './autonomous-policy.mjs';
|
|
8
|
+
import { createNativeDiffRuntime } from './native-diff.mjs';
|
|
9
|
+
import { createAutonomousRuntime } from './autonomous-runtime.mjs';
|
|
10
|
+
import { startLocalSupervisorHost } from './autonomous-local-supervisor.mjs';
|
|
11
|
+
|
|
12
|
+
const packageRoot=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
|
13
|
+
const stateRoot=path.resolve(process.env.DEADBYTE_STATE_ROOT||path.join(os.homedir(),'.deadbyte-mcp'));
|
|
14
|
+
const signingKeyPath=process.env.DEADBYTE_SIGNING_KEY||defaultPrivateKeyPath();
|
|
15
|
+
const verifyKeyPath=process.env.DEADBYTE_VERIFY_KEY||defaultPublicKeyPath();
|
|
16
|
+
|
|
17
|
+
async function policyPath(envName,localName){
|
|
18
|
+
const explicit=process.env[envName];
|
|
19
|
+
const candidate=explicit?path.resolve(explicit):path.join(packageRoot,'controller',localName);
|
|
20
|
+
try { await access(candidate); }
|
|
21
|
+
catch { throw new Error(`${envName} policy unavailable: ${candidate}`); }
|
|
22
|
+
return candidate;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const onceMode=process.env.DEADBYTE_SUPERVISOR_ONCE??'0';
|
|
26
|
+
if(!['0','1'].includes(onceMode)) throw new Error('DEADBYTE_SUPERVISOR_ONCE must be 0 or 1');
|
|
27
|
+
const codingPolicyPath=await policyPath('DEADBYTE_CODING_POLICY','deadbyte-coding-policy.json');
|
|
28
|
+
const autonomousPolicyPath=await policyPath('DEADBYTE_AUTONOMOUS_POLICY','deadbyte-autonomous-policy.json');
|
|
29
|
+
const codingPolicy=await loadCodingPolicy(codingPolicyPath);
|
|
30
|
+
const codingRuntime=createCodingRuntime({policy:codingPolicy,signingKeyPath,verifyKeyPath});
|
|
31
|
+
const autonomousPolicy=await loadAutonomousPolicy(autonomousPolicyPath,codingPolicy);
|
|
32
|
+
const nativeDiffRuntime=createNativeDiffRuntime({policy:autonomousPolicy,codingRuntime,signingKeyPath,verifyKeyPath});
|
|
33
|
+
const autonomousRuntime=createAutonomousRuntime({policy:autonomousPolicy,codingRuntime,nativeDiffRuntime,signingKeyPath,verifyKeyPath});
|
|
34
|
+
const markerPath=path.resolve(process.env.DEADBYTE_SUPERVISOR_MARKER||path.join(autonomousPolicy.evidence_dir,'supervisor-owner.json'));
|
|
35
|
+
const host=await startLocalSupervisorHost({runtime:autonomousRuntime,policy:autonomousPolicy,markerPath,
|
|
36
|
+
idleDelayMs:750,maxCycles:32,continuous:onceMode!=='1'});
|
|
37
|
+
|
|
38
|
+
const ready={schema:'deadbyte.autonomous-supervisor-host.v1',status:'ready',pid:process.pid,
|
|
39
|
+
marker_path:markerPath,policy_sha256:autonomousPolicy.policy_sha256,state_root:stateRoot};
|
|
40
|
+
process.stdout.write(`${JSON.stringify(ready)}\n`);
|
|
41
|
+
|
|
42
|
+
let stopping=false;
|
|
43
|
+
async function stopAndExit(code=0){
|
|
44
|
+
if(stopping) return;
|
|
45
|
+
stopping=true;
|
|
46
|
+
try { await host.stop(); }
|
|
47
|
+
catch(error){ process.stderr.write(`DEADBYTE supervisor host stop failed: ${String(error)}\n`); code=1; }
|
|
48
|
+
process.exitCode=code;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if(onceMode==='1') {
|
|
52
|
+
try { await host.scanNow(); await stopAndExit(0); }
|
|
53
|
+
catch(error){ process.stderr.write(`DEADBYTE supervisor host one-pass failed: ${String(error)}\n`); await stopAndExit(1); }
|
|
54
|
+
} else {
|
|
55
|
+
await new Promise(resolve=>{
|
|
56
|
+
const keepAlive=setInterval(()=>{},60_000);
|
|
57
|
+
let finishing=false;
|
|
58
|
+
const finish=(code,error=null)=>{
|
|
59
|
+
if(finishing) return;
|
|
60
|
+
finishing=true;
|
|
61
|
+
clearInterval(keepAlive);
|
|
62
|
+
if(error) process.stderr.write(`${error?.stack??String(error)}\n`);
|
|
63
|
+
void stopAndExit(code).finally(resolve);
|
|
64
|
+
};
|
|
65
|
+
process.once('SIGINT',()=>finish(0));
|
|
66
|
+
process.once('SIGTERM',()=>finish(0));
|
|
67
|
+
process.once('uncaughtException',error=>finish(1,error));
|
|
68
|
+
process.once('unhandledRejection',error=>finish(1,error));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -2,7 +2,7 @@ import { readdir } from 'node:fs/promises';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
4
|
const GOAL_ID_RE = /^[0-9a-f]{64}$/;
|
|
5
|
-
const TERMINAL = new Set(['succeeded', 'cancelled'
|
|
5
|
+
const TERMINAL = new Set(['succeeded', 'cancelled']);
|
|
6
6
|
|
|
7
7
|
function delay(ms, signal) {
|
|
8
8
|
if (signal?.aborted) return Promise.resolve();
|
|
@@ -22,22 +22,22 @@ async function listGoalIds(policy) {
|
|
|
22
22
|
.map(item => item.name).sort();
|
|
23
23
|
}
|
|
24
24
|
export function startAutonomousSupervisor({ runtime, policy = runtime?.policy,
|
|
25
|
-
idleDelayMs = 750, maxCycles = 32, logger = console } = {}) {
|
|
25
|
+
idleDelayMs = 750, maxCycles = 32, logger = console, continuous = true } = {}) {
|
|
26
26
|
if (!runtime || !policy) throw new Error('autonomous supervisor requires runtime + policy');
|
|
27
|
-
|
|
28
|
-
throw new Error('autonomous supervisor requires openai_compatible planner backend');
|
|
29
|
-
}
|
|
27
|
+
const providerBacked = policy.planner.backend === 'openai_compatible';
|
|
30
28
|
if (!Number.isInteger(idleDelayMs) || idleDelayMs < 25 || idleDelayMs > 60_000) {
|
|
31
29
|
throw new Error('autonomous supervisor idleDelayMs out of range');
|
|
32
30
|
}
|
|
33
31
|
if (!Number.isInteger(maxCycles) || maxCycles < 1 || maxCycles > 32) {
|
|
34
32
|
throw new Error('autonomous supervisor maxCycles out of range');
|
|
35
33
|
}
|
|
34
|
+
if (typeof continuous !== 'boolean') throw new Error('autonomous supervisor continuous must be boolean');
|
|
36
35
|
const abort = new AbortController();
|
|
37
36
|
const failures = new Map();
|
|
38
37
|
let passes = 0;
|
|
39
38
|
|
|
40
39
|
async function pass() {
|
|
40
|
+
if (!providerBacked) { passes += 1; return 0; }
|
|
41
41
|
let runnable = 0;
|
|
42
42
|
for (const goalId of await listGoalIds(policy)) {
|
|
43
43
|
if (abort.signal.aborted) break;
|
|
@@ -45,12 +45,35 @@ export function startAutonomousSupervisor({ runtime, policy = runtime?.policy,
|
|
|
45
45
|
try { status = await runtime.status({ goalId }); }
|
|
46
46
|
catch (error) { logger.warn?.(`DEADBYTE supervisor status ${goalId}: ${String(error)}`); continue; }
|
|
47
47
|
if (TERMINAL.has(status.state)) { failures.delete(goalId); continue; }
|
|
48
|
+
if (status.state === 'paused' && status.reason !== 'provider_circuit_open') {
|
|
49
|
+
failures.delete(goalId); continue;
|
|
50
|
+
}
|
|
51
|
+
if (status.state === 'paused' && status.reason === 'provider_circuit_open') {
|
|
52
|
+
let circuit;
|
|
53
|
+
try { circuit=await runtime.providerCircuitStatus({goalId}); }
|
|
54
|
+
catch (error) { logger.warn?.(`DEADBYTE supervisor circuit ${goalId}: ${String(error)}`); continue; }
|
|
55
|
+
const probeAt=Date.parse(circuit?.next_probe_at_utc ?? '');
|
|
56
|
+
if (circuit?.state === 'OPEN' && Number.isFinite(probeAt) && Date.now() < probeAt) {
|
|
57
|
+
failures.set(goalId,{count:0,retry_at:probeAt,error:'provider_circuit_open'});
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (!['HALF_OPEN','CLOSED'].includes(circuit?.state)) {
|
|
61
|
+
failures.delete(goalId); continue;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
48
64
|
runnable += 1;
|
|
49
65
|
const failure = failures.get(goalId);
|
|
50
66
|
if (failure && Date.now() < failure.retry_at) continue;
|
|
51
67
|
try {
|
|
52
68
|
const result = await runtime.run({ goalId, maxCycles });
|
|
53
|
-
|
|
69
|
+
if (result.status === 'paused' && result.reason === 'provider_circuit_open') {
|
|
70
|
+
const circuit=await runtime.providerCircuitStatus({goalId});
|
|
71
|
+
const probeAt=Date.parse(circuit?.next_probe_at_utc ?? '');
|
|
72
|
+
failures.set(goalId,{count:0,retry_at:Number.isFinite(probeAt)?probeAt:Date.now()+idleDelayMs,
|
|
73
|
+
error:'provider_circuit_open'});
|
|
74
|
+
} else {
|
|
75
|
+
failures.delete(goalId);
|
|
76
|
+
}
|
|
54
77
|
if (result.status === 'input_required') {
|
|
55
78
|
throw new Error('provider-backed supervisor unexpectedly requested client sampling');
|
|
56
79
|
}
|
|
@@ -66,7 +89,7 @@ export function startAutonomousSupervisor({ runtime, policy = runtime?.policy,
|
|
|
66
89
|
return runnable;
|
|
67
90
|
}
|
|
68
91
|
|
|
69
|
-
const done = (async () => {
|
|
92
|
+
const done = continuous ? (async () => {
|
|
70
93
|
while (!abort.signal.aborted) {
|
|
71
94
|
let runnable = 0;
|
|
72
95
|
try { runnable = await pass(); }
|
|
@@ -74,7 +97,7 @@ export function startAutonomousSupervisor({ runtime, policy = runtime?.policy,
|
|
|
74
97
|
if (abort.signal.aborted) break;
|
|
75
98
|
await delay(runnable > 0 ? 25 : idleDelayMs, abort.signal);
|
|
76
99
|
}
|
|
77
|
-
})();
|
|
100
|
+
})() : Promise.resolve();
|
|
78
101
|
|
|
79
102
|
return Object.freeze({
|
|
80
103
|
get running() { return !abort.signal.aborted; },
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { readdir, readFile, stat } from 'node:fs/promises';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { canonicalJson } from './canonical-json.mjs';
|
|
7
|
+
import { buildCapabilityBenchmark } from './capability-benchmark.mjs';
|
|
8
|
+
|
|
9
|
+
const sha256=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
10
|
+
const TEST_TIMEOUT_MS=180_000;
|
|
11
|
+
|
|
12
|
+
export const R35_BENCHMARK_CASE_IDS=Object.freeze([
|
|
13
|
+
'filesystem_bounded_read','exact_edit_stale_reject','paged_search','process_owned_lifecycle',
|
|
14
|
+
'semantic_typescript','semantic_python','semantic_rust','semantic_cpp','context_provenance',
|
|
15
|
+
'autonomous_fail_repair','remote_replay_dedupe'
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
const DEFINITIONS=Object.freeze([
|
|
19
|
+
{case_id:'filesystem_bounded_read',test_files:['test/multi-file-read.test.mjs'],fixture_files:['test/multi-file-read.test.mjs'],round_trips:2,stale_rejected:false,recovery_success:true},
|
|
20
|
+
{case_id:'exact_edit_stale_reject',test_files:['test/coding-plane.test.mjs','test/native-diff.test.mjs'],fixture_files:['test/coding-plane.test.mjs','test/native-diff.test.mjs'],round_trips:4,stale_rejected:true,recovery_success:true},
|
|
21
|
+
{case_id:'paged_search',test_files:['test/observation-runtime.test.mjs'],fixture_files:['test/observation-runtime.test.mjs'],round_trips:4,stale_rejected:false,recovery_success:true},
|
|
22
|
+
{case_id:'process_owned_lifecycle',test_files:['test/process-runtime.test.mjs'],fixture_files:['test/process-runtime.test.mjs'],round_trips:6,stale_rejected:true,recovery_success:true},
|
|
23
|
+
{case_id:'semantic_typescript',test_files:['test/semantic-code.test.mjs'],fixture_files:['test/semantic-code.test.mjs','test/fixtures/semantic/typescript'],round_trips:5,stale_rejected:true,recovery_success:true},
|
|
24
|
+
{case_id:'semantic_python',test_files:['test/semantic-multilang.test.mjs'],fixture_files:['test/semantic-multilang.test.mjs','test/fixtures/semantic/python'],test_name_pattern:'R35 python semantic tracer',requires_semantic_config:true,round_trips:5,stale_rejected:true,recovery_success:true},
|
|
25
|
+
{case_id:'semantic_rust',test_files:['test/semantic-multilang.test.mjs'],fixture_files:['test/semantic-multilang.test.mjs','test/fixtures/semantic/rust'],test_name_pattern:'R35 rust semantic tracer',requires_semantic_config:true,round_trips:5,stale_rejected:true,recovery_success:true},
|
|
26
|
+
{case_id:'semantic_cpp',test_files:['test/semantic-multilang.test.mjs'],fixture_files:['test/semantic-multilang.test.mjs','test/fixtures/semantic/cpp'],test_name_pattern:'R35 cpp semantic tracer',requires_semantic_config:true,round_trips:5,stale_rejected:true,recovery_success:true},
|
|
27
|
+
{case_id:'context_provenance',test_files:['test/context-provenance.test.mjs','test/autonomous-context-engine.test.mjs'],fixture_files:['test/context-provenance.test.mjs','test/autonomous-context-engine.test.mjs'],round_trips:2,stale_rejected:false,recovery_success:true},
|
|
28
|
+
{case_id:'autonomous_fail_repair',test_files:['test/autonomous-r34-e2e.test.mjs','test/autonomous-loop-v2.test.mjs'],fixture_files:['test/autonomous-r34-e2e.test.mjs','test/autonomous-loop-v2.test.mjs','test/helpers/autonomous-r34-fixture.mjs'],test_name_pattern:'(?:multi-step fail replan repair finish|failed VERIFY enters CRITIC|REPAIR must change)',round_trips:8,stale_rejected:true,recovery_success:true},
|
|
29
|
+
{case_id:'remote_replay_dedupe',test_files:['test/remote-result-journal.test.mjs','test/remote-session-cli.test.mjs'],fixture_files:['test/remote-result-journal.test.mjs','test/remote-session-cli.test.mjs'],test_name_pattern:'(?:duplicate terminal results|remote --resume replays)',round_trips:4,stale_rejected:false,recovery_success:true}
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
export function benchmarkCaseDefinitions(){
|
|
33
|
+
return DEFINITIONS.map(item=>({
|
|
34
|
+
...structuredClone(item),
|
|
35
|
+
fixture_files:['bench/fixtures/corpus.json',...item.fixture_files]
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function collectFiles(root,relative){
|
|
40
|
+
const absolute=path.resolve(root,relative);
|
|
41
|
+
const info=await stat(absolute);
|
|
42
|
+
if(info.isFile()) return [{relative:relative.replaceAll('\\','/'),absolute}];
|
|
43
|
+
if(!info.isDirectory()) throw new Error(`benchmark fixture '${relative}' is not file/directory`);
|
|
44
|
+
const out=[];
|
|
45
|
+
async function walk(dir,rel){
|
|
46
|
+
const names=(await readdir(dir,{withFileTypes:true})).sort((a,b)=>a.name.localeCompare(b.name));
|
|
47
|
+
for(const entry of names){
|
|
48
|
+
const child=path.join(dir,entry.name);const childRel=path.join(rel,entry.name);
|
|
49
|
+
if(entry.isSymbolicLink()) throw new Error(`benchmark fixture symlink rejected: ${childRel}`);
|
|
50
|
+
if(entry.isDirectory()) await walk(child,childRel);
|
|
51
|
+
else if(entry.isFile()) out.push({relative:childRel.replaceAll('\\','/'),absolute:child});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
await walk(absolute,relative);
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function fixtureIdentityForCase({rootUrl,definition}){
|
|
59
|
+
if(!definition||typeof definition!=='object'||!Array.isArray(definition.fixture_files)||definition.fixture_files.length<1) throw new Error('benchmark fixture definition invalid');
|
|
60
|
+
const root=typeof rootUrl==='string'?path.resolve(rootUrl):fileURLToPath(rootUrl);
|
|
61
|
+
const files=[];
|
|
62
|
+
for(const relative of definition.fixture_files) files.push(...await collectFiles(root,relative));
|
|
63
|
+
files.sort((a,b)=>a.relative.localeCompare(b.relative));
|
|
64
|
+
const records=[];
|
|
65
|
+
for(const item of files) records.push({path:item.relative,sha256:sha256(await readFile(item.absolute))});
|
|
66
|
+
return sha256(Buffer.from(canonicalJson({schema:'deadbyte.r35-benchmark-fixture.v1',case_id:definition.case_id,files:records}),'utf8'));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function runNodeTest({root,definition,env,timeoutMs}){
|
|
70
|
+
return new Promise(resolve=>{
|
|
71
|
+
const args=['--test'];
|
|
72
|
+
if(definition.test_name_pattern) args.push(`--test-name-pattern=${definition.test_name_pattern}`);
|
|
73
|
+
args.push(...definition.test_files);
|
|
74
|
+
const started=process.hrtime.bigint();
|
|
75
|
+
const child=spawn(process.execPath,args,{cwd:root,env:{...process.env,...env},shell:false,windowsHide:true,stdio:['ignore','pipe','pipe']});
|
|
76
|
+
const stdout=[];const stderr=[];let bytes=0;let killed=false;
|
|
77
|
+
const timer=setTimeout(()=>{killed=true;child.kill('SIGKILL');},timeoutMs);
|
|
78
|
+
child.stdout.on('data',chunk=>{stdout.push(chunk);bytes+=chunk.length;});
|
|
79
|
+
child.stderr.on('data',chunk=>{stderr.push(chunk);bytes+=chunk.length;});
|
|
80
|
+
child.once('error',error=>{clearTimeout(timer);resolve({exit_code:null,timed_out:false,error:String(error),stdout:Buffer.concat(stdout),stderr:Buffer.concat(stderr),bytes,elapsed_ms:Number(process.hrtime.bigint()-started)/1e6});});
|
|
81
|
+
child.once('exit',(code,signal)=>{clearTimeout(timer);resolve({exit_code:code,timed_out:killed,signal,stdout:Buffer.concat(stdout),stderr:Buffer.concat(stderr),bytes,elapsed_ms:Number(process.hrtime.bigint()-started)/1e6});});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function runCapabilityBenchmark({rootUrl,definitions=benchmarkCaseDefinitions(),env={},timeoutMs=TEST_TIMEOUT_MS}={}){
|
|
86
|
+
const root=typeof rootUrl==='string'?path.resolve(rootUrl):fileURLToPath(rootUrl??new URL('../',import.meta.url));
|
|
87
|
+
if(!Array.isArray(definitions)||definitions.length<1) throw new Error('benchmark definitions invalid');
|
|
88
|
+
if(!Number.isInteger(timeoutMs)||timeoutMs<1000||timeoutMs>600000) throw new Error('benchmark timeout invalid');
|
|
89
|
+
const cases=[];
|
|
90
|
+
for(const definition of definitions){
|
|
91
|
+
if(definition.requires_semantic_config&&(!env.DEADBYTE_R35_SEMANTIC_CONFIG||!env.DEADBYTE_R35_SEMANTIC_CONFIG_SHA256)){
|
|
92
|
+
throw new Error(`benchmark case '${definition.case_id}' requires pinned semantic config env`);
|
|
93
|
+
}
|
|
94
|
+
const fixture_sha256=await fixtureIdentityForCase({rootUrl:root,definition});
|
|
95
|
+
let result;
|
|
96
|
+
try{result=await runNodeTest({root,definition,env,timeoutMs});}
|
|
97
|
+
catch(error){result={exit_code:null,timed_out:false,error:String(error),stdout:Buffer.alloc(0),stderr:Buffer.alloc(0),bytes:0,elapsed_ms:0};}
|
|
98
|
+
const evidence={schema:'deadbyte.r35-benchmark-case-evidence.v1',case_id:definition.case_id,exit_code:result.exit_code,
|
|
99
|
+
timed_out:result.timed_out===true,signal:result.signal??null,error:result.error??null,
|
|
100
|
+
stdout_sha256:sha256(result.stdout??Buffer.alloc(0)),stderr_sha256:sha256(result.stderr??Buffer.alloc(0))};
|
|
101
|
+
const correct=result.exit_code===0&&!result.timed_out&&!result.error;
|
|
102
|
+
cases.push({case_id:definition.case_id,fixture_sha256,correct,round_trips:definition.round_trips,
|
|
103
|
+
bytes_returned:result.bytes??0,elapsed_ms:result.elapsed_ms??0,
|
|
104
|
+
stale_rejected:correct&&definition.stale_rejected===true,recovery_success:correct&&definition.recovery_success===true,
|
|
105
|
+
duplicate_side_effects:correct?0:1,evidence_sha256:sha256(Buffer.from(canonicalJson(evidence),'utf8'))});
|
|
106
|
+
}
|
|
107
|
+
return buildCapabilityBenchmark({suite_id:'r35-offline-v1',cases});
|
|
108
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { canonicalJson } from './canonical-json.mjs';
|
|
3
|
+
|
|
4
|
+
export const CAPABILITY_BENCHMARK_SCHEMA='deadbyte.r35-capability-benchmark.v1';
|
|
5
|
+
const HEX64=/^[0-9a-f]{64}$/;
|
|
6
|
+
const CASE_ID=/^[A-Za-z0-9._-]{1,96}$/;
|
|
7
|
+
const SUITE_ID=/^[A-Za-z0-9._-]{1,96}$/;
|
|
8
|
+
|
|
9
|
+
function sha256(value){return createHash('sha256').update(Buffer.from(canonicalJson(value),'utf8')).digest('hex');}
|
|
10
|
+
function bool(value,label){if(typeof value!=='boolean') throw new Error(`${label} invalid`);return value;}
|
|
11
|
+
function uint(value,label,{min=0,max=Number.MAX_SAFE_INTEGER}={}){
|
|
12
|
+
if(!Number.isSafeInteger(value)||value<min||value>max) throw new Error(`${label} invalid`);return value;
|
|
13
|
+
}
|
|
14
|
+
function finite(value,label){if(typeof value!=='number'||!Number.isFinite(value)||value<0) throw new Error(`${label} invalid`);return value;}
|
|
15
|
+
function hash(value,label){if(typeof value!=='string'||!HEX64.test(value)) throw new Error(`${label} evidence hash invalid`);return value;}
|
|
16
|
+
|
|
17
|
+
export function normalizeBenchmarkCase(raw){
|
|
18
|
+
if(!raw||typeof raw!=='object'||Array.isArray(raw)) throw new Error('benchmark case invalid');
|
|
19
|
+
const id=raw.case_id;
|
|
20
|
+
if(typeof id!=='string'||!CASE_ID.test(id)) throw new Error('benchmark case_id invalid');
|
|
21
|
+
return Object.freeze({
|
|
22
|
+
case_id:id,
|
|
23
|
+
fixture_sha256:hash(raw.fixture_sha256,'benchmark fixture'),
|
|
24
|
+
correct:bool(raw.correct,'benchmark correct'),
|
|
25
|
+
round_trips:uint(raw.round_trips,'benchmark round-trips',{min:1,max:100000}),
|
|
26
|
+
bytes_returned:uint(raw.bytes_returned,'benchmark bytes_returned',{max:1024*1024*1024}),
|
|
27
|
+
elapsed_ms:finite(raw.elapsed_ms,'benchmark elapsed_ms'),
|
|
28
|
+
stale_rejected:bool(raw.stale_rejected,'benchmark stale_rejected'),
|
|
29
|
+
recovery_success:bool(raw.recovery_success,'benchmark recovery_success'),
|
|
30
|
+
duplicate_side_effects:uint(raw.duplicate_side_effects,'benchmark duplicate_side_effects',{max:100000}),
|
|
31
|
+
evidence_sha256:hash(raw.evidence_sha256,'benchmark evidence')
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function buildCapabilityBenchmark({suite_id:rawSuiteId,cases:rawCases}={}){
|
|
36
|
+
if(typeof rawSuiteId!=='string'||!SUITE_ID.test(rawSuiteId)) throw new Error('benchmark suite_id invalid');
|
|
37
|
+
if(!Array.isArray(rawCases)||rawCases.length<1||rawCases.length>128) throw new Error('benchmark cases invalid');
|
|
38
|
+
const cases=rawCases.map(normalizeBenchmarkCase).sort((a,b)=>a.case_id.localeCompare(b.case_id));
|
|
39
|
+
const seen=new Set();
|
|
40
|
+
for(const item of cases){if(seen.has(item.case_id)) throw new Error(`duplicate case '${item.case_id}'`);seen.add(item.case_id);}
|
|
41
|
+
const fixtureIdentity={schema:'deadbyte.r35-capability-fixtures.v1',suite_id:rawSuiteId,
|
|
42
|
+
fixtures:cases.map(item=>({case_id:item.case_id,fixture_sha256:item.fixture_sha256}))};
|
|
43
|
+
const fixture_identity_sha256=sha256(fixtureIdentity);
|
|
44
|
+
const observation={schema:CAPABILITY_BENCHMARK_SCHEMA,suite_id:rawSuiteId,fixture_identity_sha256,cases};
|
|
45
|
+
return Object.freeze({
|
|
46
|
+
...observation,
|
|
47
|
+
overall_correct:cases.every(item=>item.correct),
|
|
48
|
+
observation_sha256:sha256(observation)
|
|
49
|
+
});
|
|
50
|
+
}
|
package/src/coding-mcp-tools.mjs
CHANGED
|
@@ -2,8 +2,9 @@ import * as z from 'zod/v4';
|
|
|
2
2
|
import { CODING_TASK_ID_RE, CODING_STEP_ID_RE } from './coding-task-runtime.mjs';
|
|
3
3
|
import {
|
|
4
4
|
codingBenchmarkRunOutputSchema, codingCommandRunOutputSchema,
|
|
5
|
-
codingFileReadOutputSchema, codingFileWriteOutputSchema,
|
|
5
|
+
codingFileReadOutputSchema, codingFilesReadOutputSchema, codingFileWriteOutputSchema,
|
|
6
6
|
codingReceiptVerifyOutputSchema, codingSearchOutputSchema, codingSessionStatusOutputSchema, codingStatOutputSchema,
|
|
7
|
+
codingSymbolOutlineOutputSchema, codingSymbolDefinitionOutputSchema, codingSymbolReferencesOutputSchema, codingSymbolReplaceOutputSchema,
|
|
7
8
|
codingTaskApproveOutputSchema, codingTaskCancelOutputSchema,
|
|
8
9
|
codingTaskEventsOutputSchema, codingTaskRunOutputSchema,
|
|
9
10
|
codingTaskStatusOutputSchema, codingTaskSubmitOutputSchema,
|
|
@@ -45,8 +46,8 @@ const taskStep = z.union([
|
|
|
45
46
|
|
|
46
47
|
function result(schema, value, isError = false) { return codingStructuredResult(schema, value, isError); }
|
|
47
48
|
function fail(schema, error) { return result(schema, { status: 'failed', error: String(error) }, true); }
|
|
48
|
-
export function registerCodingTools(server, { codingRuntime, taskRuntime }) {
|
|
49
|
-
if (!codingRuntime || !taskRuntime) throw new Error('coding tool registration requires runtimes');
|
|
49
|
+
export function registerCodingTools(server, { codingRuntime, taskRuntime, semanticRuntime }) {
|
|
50
|
+
if (!codingRuntime || !taskRuntime || !semanticRuntime) throw new Error('coding tool registration requires runtimes');
|
|
50
51
|
|
|
51
52
|
server.registerTool('coding_session_status', {
|
|
52
53
|
description: 'Read coding-plane policy/lease status. This never arms or renews authority.',
|
|
@@ -76,6 +77,48 @@ export function registerCodingTools(server, { codingRuntime, taskRuntime }) {
|
|
|
76
77
|
catch (error) { return fail(codingSearchOutputSchema, error); }
|
|
77
78
|
});
|
|
78
79
|
|
|
80
|
+
server.registerTool('coding_symbol_outline', {
|
|
81
|
+
description: 'Return a bounded JS/TS symbol outline using the bundled TypeScript language service. Results are rooted in the active coding-policy source tree.',
|
|
82
|
+
inputSchema: z.strictObject({ root_id: rootId, path: relPath, max_symbols: z.number().int().min(1).max(500).default(200) }),
|
|
83
|
+
outputSchema: codingSymbolOutlineOutputSchema
|
|
84
|
+
}, async ({ root_id, path, max_symbols }) => { try { return result(codingSymbolOutlineOutputSchema, await semanticRuntime.outline({ rootId: root_id, relativePath: path, maxSymbols: max_symbols })); } catch (error) { return fail(codingSymbolOutlineOutputSchema, error); } });
|
|
85
|
+
|
|
86
|
+
server.registerTool('coding_symbol_definition', {
|
|
87
|
+
description: 'Resolve JS/TS definitions at a zero-based line/column using the bundled TypeScript language service.',
|
|
88
|
+
inputSchema: z.strictObject({ root_id: rootId, path: relPath, line: z.number().int().min(0), column: z.number().int().min(0), max_results: z.number().int().min(1).max(200).default(50) }),
|
|
89
|
+
outputSchema: codingSymbolDefinitionOutputSchema
|
|
90
|
+
}, async ({ root_id, path, line, column, max_results }) => { try { return result(codingSymbolDefinitionOutputSchema, await semanticRuntime.definition({ rootId: root_id, relativePath: path, line, column, maxResults: max_results })); } catch (error) { return fail(codingSymbolDefinitionOutputSchema, error); } });
|
|
91
|
+
|
|
92
|
+
server.registerTool('coding_symbol_references', {
|
|
93
|
+
description: 'Find bounded JS/TS references at a zero-based line/column using the bundled TypeScript language service.',
|
|
94
|
+
inputSchema: z.strictObject({ root_id: rootId, path: relPath, line: z.number().int().min(0), column: z.number().int().min(0), max_results: z.number().int().min(1).max(500).default(200) }),
|
|
95
|
+
outputSchema: codingSymbolReferencesOutputSchema
|
|
96
|
+
}, async ({ root_id, path, line, column, max_results }) => { try { return result(codingSymbolReferencesOutputSchema, await semanticRuntime.references({ rootId: root_id, relativePath: path, line, column, maxResults: max_results })); } catch (error) { return fail(codingSymbolReferencesOutputSchema, error); } });
|
|
97
|
+
|
|
98
|
+
server.registerTool('coding_symbol_replace', {
|
|
99
|
+
description: 'Replace one current JS/TS symbol body by symbol_id under exact file SHA-256 precondition. The commit reuses the coding plane signed surgical-edit receipt path.',
|
|
100
|
+
inputSchema: z.strictObject({ root_id: rootId, path: relPath, symbol_id: hex64, new_body: z.string().max(524288), expected_sha256: hex64 }),
|
|
101
|
+
outputSchema: codingSymbolReplaceOutputSchema
|
|
102
|
+
}, async ({ root_id, path, symbol_id, new_body, expected_sha256 }) => { try { return result(codingSymbolReplaceOutputSchema, await semanticRuntime.replaceSymbol({ rootId: root_id, relativePath: path, symbolId: symbol_id, newBody: new_body, expectedSha256: expected_sha256 })); } catch (error) { return fail(codingSymbolReplaceOutputSchema, error); } });
|
|
103
|
+
|
|
104
|
+
server.registerTool('coding_files_read', {
|
|
105
|
+
description: 'Read up to 32 bounded files in one request using the same coding-policy lease and deny-path checks as coding_file_read.',
|
|
106
|
+
inputSchema: z.strictObject({ root_id: rootId, files: z.array(z.strictObject({ path: relPath, encoding: z.enum(['utf8','base64']).default('utf8') })).min(1).max(32),
|
|
107
|
+
max_total_bytes: z.number().int().min(1).max(2097152).default(1048576) }),
|
|
108
|
+
outputSchema: codingFilesReadOutputSchema
|
|
109
|
+
}, async ({ root_id, files, max_total_bytes }) => {
|
|
110
|
+
try {
|
|
111
|
+
const values=[]; let total=0;
|
|
112
|
+
for(const item of files){
|
|
113
|
+
const read=await codingRuntime.fileRead({rootId:root_id,relativePath:item.path,encoding:item.encoding});
|
|
114
|
+
total+=read.bytes;
|
|
115
|
+
if(total>max_total_bytes) throw new Error(`coding multi-read exceeds ${max_total_bytes} byte total limit`);
|
|
116
|
+
values.push({path:item.path,encoding:item.encoding,bytes:read.bytes,sha256:read.sha256,content:read.content});
|
|
117
|
+
}
|
|
118
|
+
return result(codingFilesReadOutputSchema,{status:'ok',root_id,total_bytes:total,files:values});
|
|
119
|
+
} catch(error){ return fail(codingFilesReadOutputSchema,error); }
|
|
120
|
+
});
|
|
121
|
+
|
|
79
122
|
server.registerTool('coding_file_read', {
|
|
80
123
|
description: 'Read one bounded file inside an active coding lease.',
|
|
81
124
|
inputSchema: z.strictObject({ root_id: rootId, path: relPath, encoding: z.enum(['utf8','base64']).default('utf8') }), outputSchema: codingFileReadOutputSchema
|
|
@@ -83,6 +83,51 @@ export const codingSearchOutputSchema = statusContract({
|
|
|
83
83
|
files_scanned: z.number().int().min(0).optional(), bytes_scanned: z.number().int().min(0).optional(), truncated: z.boolean().optional() },
|
|
84
84
|
successStatuses: ['ok'], successRequired: ['root_id','path','pattern','mode','case_sensitive','matches','files_scanned','bytes_scanned','truncated']
|
|
85
85
|
});
|
|
86
|
+
const semanticLocationSchema = z.strictObject({
|
|
87
|
+
path: z.string().min(1).max(512), name: z.string().max(256), kind: z.string().min(1).max(64),
|
|
88
|
+
start_line: z.number().int().min(0), start_column: z.number().int().min(0),
|
|
89
|
+
end_line: z.number().int().min(0), end_column: z.number().int().min(0)
|
|
90
|
+
});
|
|
91
|
+
const semanticSymbolSchema = semanticLocationSchema.extend({
|
|
92
|
+
symbol_id: hex64, container_name: z.string().max(256),
|
|
93
|
+
name_start_line: z.number().int().min(0), name_start_column: z.number().int().min(0)
|
|
94
|
+
});
|
|
95
|
+
export const codingSymbolOutlineOutputSchema = statusContract({
|
|
96
|
+
statuses: ['ok','failed'],
|
|
97
|
+
shape: { root_id: z.string().min(1).max(64).optional(), path: z.string().min(1).max(512).optional(),
|
|
98
|
+
file_sha256: hex64.optional(), engine: z.string().min(1).max(64).optional(),
|
|
99
|
+
symbols: z.array(semanticSymbolSchema).max(500).optional(), truncated: z.boolean().optional() },
|
|
100
|
+
successStatuses: ['ok'], successRequired: ['root_id','path','file_sha256','engine','symbols','truncated']
|
|
101
|
+
});
|
|
102
|
+
export const codingSymbolDefinitionOutputSchema = statusContract({
|
|
103
|
+
statuses: ['ok','failed'],
|
|
104
|
+
shape: { root_id: z.string().min(1).max(64).optional(), path: z.string().min(1).max(512).optional(),
|
|
105
|
+
line: z.number().int().min(0).optional(), column: z.number().int().min(0).optional(), engine: z.string().min(1).max(64).optional(),
|
|
106
|
+
locations: z.array(semanticLocationSchema).max(200).optional(), truncated: z.boolean().optional() },
|
|
107
|
+
successStatuses: ['ok'], successRequired: ['root_id','path','line','column','engine','locations','truncated']
|
|
108
|
+
});
|
|
109
|
+
export const codingSymbolReferencesOutputSchema = statusContract({
|
|
110
|
+
statuses: ['ok','failed'],
|
|
111
|
+
shape: { root_id: z.string().min(1).max(64).optional(), path: z.string().min(1).max(512).optional(),
|
|
112
|
+
line: z.number().int().min(0).optional(), column: z.number().int().min(0).optional(), engine: z.string().min(1).max(64).optional(),
|
|
113
|
+
locations: z.array(semanticLocationSchema).max(500).optional(), truncated: z.boolean().optional() },
|
|
114
|
+
successStatuses: ['ok'], successRequired: ['root_id','path','line','column','engine','locations','truncated']
|
|
115
|
+
});
|
|
116
|
+
export const codingSymbolReplaceOutputSchema = statusContract({
|
|
117
|
+
statuses: ['committed','failed'],
|
|
118
|
+
shape: { root_id: z.string().min(1).max(64).optional(), path: z.string().min(1).max(512).optional(), previous_sha256: hex64.optional(),
|
|
119
|
+
sha256: hex64.optional(), bytes: z.number().int().min(0).optional(), replacements: z.literal(1).optional(),
|
|
120
|
+
receipt_id: receiptId.optional(), receipt_sha256: hex64.optional(), request_sha256: hex64.optional(),
|
|
121
|
+
symbol_id: hex64.optional(), symbol_name: z.string().min(1).max(256).optional(), engine: z.string().min(1).max(64).optional() },
|
|
122
|
+
successStatuses: ['committed'], successRequired: ['root_id','path','previous_sha256','sha256','bytes','replacements','receipt_id','receipt_sha256','request_sha256','symbol_id','symbol_name','engine']
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
export const codingFilesReadOutputSchema = statusContract({
|
|
126
|
+
statuses: ['ok','failed'],
|
|
127
|
+
shape: { root_id: z.string().min(1).max(64).optional(), total_bytes: z.number().int().min(0).optional(),
|
|
128
|
+
files: z.array(z.strictObject({ path: z.string().min(1).max(512), encoding: z.enum(['utf8','base64']), bytes: z.number().int().min(0), sha256: hex64, content: z.string() })).max(32).optional() },
|
|
129
|
+
successStatuses: ['ok'], successRequired: ['root_id','total_bytes','files']
|
|
130
|
+
});
|
|
86
131
|
export const codingFileReadOutputSchema = statusContract({
|
|
87
132
|
statuses: ['ok', 'failed'],
|
|
88
133
|
shape: { root_id: z.string().min(1).max(64).optional(), path: z.string().min(1).max(512).optional(), encoding: z.enum(['utf8', 'base64']).optional(),
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { canonicalJson } from './canonical-json.mjs';
|
|
3
|
+
|
|
4
|
+
const SCHEMA='deadbyte.context-provenance.v1';
|
|
5
|
+
const HEX64=/^[0-9a-f]{64}$/;
|
|
6
|
+
const SECRET_KEY=/(?:^|[_-])(token|password|secret|authorization|cookie|credential|credentials|api[_-]?key|private[_-]?key|recovery)(?:$|[_-])/i;
|
|
7
|
+
|
|
8
|
+
const sha256=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
9
|
+
|
|
10
|
+
function boundedText(value,label,max=512){
|
|
11
|
+
if(typeof value!=='string'||value.length<1||value.length>max||/[\r\n\0]/.test(value)) throw new Error(`provenance ${label} invalid`);
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function observedUtc(value){
|
|
16
|
+
if(typeof value!=='string'||value.length<20||value.length>64) throw new Error('provenance observedAtUtc invalid');
|
|
17
|
+
const time=Date.parse(value);
|
|
18
|
+
if(!Number.isFinite(time)) throw new Error('provenance observedAtUtc invalid');
|
|
19
|
+
return new Date(time).toISOString();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function structuredSecretShape(value,key=''){
|
|
23
|
+
if(key&&SECRET_KEY.test(key)) return {value:'[REDACTED]',secret:true};
|
|
24
|
+
if(Array.isArray(value)){
|
|
25
|
+
let secret=false;
|
|
26
|
+
const out=value.map(item=>{const next=structuredSecretShape(item,'');secret=secret||next.secret;return next.value;});
|
|
27
|
+
return {value:out,secret};
|
|
28
|
+
}
|
|
29
|
+
if(value&&typeof value==='object'&&!Buffer.isBuffer(value)&&!(value instanceof Uint8Array)){
|
|
30
|
+
let secret=false;const out={};
|
|
31
|
+
for(const name of Object.keys(value).sort()){
|
|
32
|
+
const next=structuredSecretShape(value[name],name);secret=secret||next.secret;out[name]=next.value;
|
|
33
|
+
}
|
|
34
|
+
return {value:out,secret};
|
|
35
|
+
}
|
|
36
|
+
return {value,secret:false};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function bytesIdentity(bytes){
|
|
40
|
+
if(Buffer.isBuffer(bytes)) return {raw:bytes,safe:bytes,secret:false};
|
|
41
|
+
if(bytes instanceof Uint8Array) { const raw=Buffer.from(bytes); return {raw,safe:raw,secret:false}; }
|
|
42
|
+
if(typeof bytes==='string'){const raw=Buffer.from(bytes,'utf8');return {raw,safe:raw,secret:false};}
|
|
43
|
+
if(bytes===null||typeof bytes!=='object') throw new Error('provenance bytes invalid');
|
|
44
|
+
const raw=Buffer.from(canonicalJson(bytes),'utf8');
|
|
45
|
+
const shaped=structuredSecretShape(bytes);
|
|
46
|
+
return {raw,safe:Buffer.from(canonicalJson(shaped.value),'utf8'),secret:shaped.secret};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function provenanceFor({sourceKind,sourceId,bytes,observedAtUtc,trustClass,relevanceEpoch}){
|
|
50
|
+
const source_kind=boundedText(sourceKind,'sourceKind',96);
|
|
51
|
+
const source_id=boundedText(sourceId,'sourceId',1024);
|
|
52
|
+
const trust_class=boundedText(trustClass,'trustClass',96);
|
|
53
|
+
if(!Number.isInteger(relevanceEpoch)||relevanceEpoch<0||relevanceEpoch>Number.MAX_SAFE_INTEGER) throw new Error('provenance relevanceEpoch invalid');
|
|
54
|
+
const observed_at_utc=observedUtc(observedAtUtc);
|
|
55
|
+
const identity=bytesIdentity(bytes);
|
|
56
|
+
const source_sha256=identity.secret?null:sha256(identity.raw);
|
|
57
|
+
const safePayloadSha256=sha256(identity.safe);
|
|
58
|
+
const provenance_id=sha256(Buffer.from(canonicalJson({schema:SCHEMA,source_kind,source_id,source_sha256,safe_payload_sha256:safePayloadSha256,trust_class,relevance_epoch:relevanceEpoch}),'utf8'));
|
|
59
|
+
const out={schema:SCHEMA,source_kind,source_id,observed_at_utc,byte_count:identity.raw.length,trust_class,relevance_epoch:relevanceEpoch,provenance_id};
|
|
60
|
+
if(source_sha256!==null) out.source_sha256=source_sha256;
|
|
61
|
+
else out.digest_withheld='secret';
|
|
62
|
+
return Object.freeze(out);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function provenanceOf(item,index){
|
|
66
|
+
if(!item||typeof item!=='object'||Array.isArray(item)) throw new Error(`evidence item ${index+1} invalid`);
|
|
67
|
+
const provenance=item.provenance;
|
|
68
|
+
if(!provenance||typeof provenance!=='object'||provenance.schema!==SCHEMA||!HEX64.test(provenance.provenance_id??'')) throw new Error(`evidence provenance ${index+1} invalid`);
|
|
69
|
+
const time=Date.parse(provenance.observed_at_utc);
|
|
70
|
+
if(!Number.isFinite(time)) throw new Error(`evidence provenance ${index+1} observed_at_utc invalid`);
|
|
71
|
+
return {provenance,time};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function dedupeEvidence(items){
|
|
75
|
+
if(!Array.isArray(items)) throw new Error('evidence items must be an array');
|
|
76
|
+
const order=[];const selected=new Map();
|
|
77
|
+
for(let index=0;index<items.length;index+=1){
|
|
78
|
+
const item=items[index];const {provenance,time}=provenanceOf(item,index);const id=provenance.provenance_id;
|
|
79
|
+
if(!selected.has(id)){order.push(id);selected.set(id,{item,time,index});continue;}
|
|
80
|
+
const previous=selected.get(id);
|
|
81
|
+
if(time>previous.time||(time===previous.time&&index>previous.index)) selected.set(id,{item,time,index});
|
|
82
|
+
}
|
|
83
|
+
return order.map(id=>structuredClone(selected.get(id).item));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const CONTEXT_PROVENANCE_SCHEMA=SCHEMA;
|