deadbyte-mcp 0.12.0 → 0.14.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/.gitattributes +7 -0
- package/AGENTS.md +25 -0
- package/CONTEXT.md +3 -3
- package/MANIFEST.SHA256 +89 -45
- package/R41-PARENT.json +15 -0
- package/R42-PARENT.json +19 -0
- package/README.txt +2 -2
- package/bin/appcontainer-stage.obj +0 -0
- package/bin/bootstrap-advapi32.obj +0 -0
- package/bin/bootstrap-exitcode.obj +0 -0
- package/bin/bootstrap-kernel32.obj +0 -0
- package/bin/child-control-probe.obj +0 -0
- package/bin/child-control-stage.obj +0 -0
- package/bin/contained-reverse-worker.obj +0 -0
- package/bin/contained-transform-worker.obj +0 -0
- package/bin/containment-probe.obj +0 -0
- package/bin/deadbyte-contain.obj +0 -0
- package/bin/deadbyte-exec.obj +0 -0
- package/bin/deadbyte-process-host.obj +0 -0
- package/bin/deadbyte-tunnel-host.obj +0 -0
- package/controller/README.TXT +1 -1
- package/controller/deadbyte-controller.ps1 +1 -1
- package/controller/deadbyte-desktop-policy.json +5 -5
- package/controller/deadbyte-process-policy.json +4 -4
- package/docs/ARCHITECTURE.md +1 -1
- package/docs/superpowers/specs/2026-09-20-r41-deterministic-memory-design.md +132 -0
- package/harness/r42-agent-evals.json +48 -0
- package/harness/task-contract.schema.json +33 -0
- package/package.json +11 -7
- package/proof/CONTAINMENT-BUILD.txt +6 -6
- package/scripts/agent-eval-r42.mjs +46 -0
- package/scripts/build-containment.ps1 +24 -14
- package/scripts/build-desktop-r40.ps1 +15 -9
- package/scripts/deferred-slot-operation-r41.mjs +127 -0
- package/scripts/deferred-slot-operation-r42.mjs +126 -0
- package/scripts/final-closure-r41.mjs +116 -0
- package/scripts/final-closure-r42.mjs +116 -0
- package/scripts/final-closure-verify-r41.mjs +215 -0
- package/scripts/final-closure-verify-r42.mjs +223 -0
- package/scripts/gate-windows-r41.ps1 +48 -0
- package/scripts/gate-windows-r42.ps1 +54 -0
- package/scripts/init-desktop-policy-r40.ps1 +10 -4
- package/scripts/release-parity-r41.mjs +221 -0
- package/scripts/release-parity-r42.mjs +235 -0
- package/scripts/release-parity-tests-r41.ps1 +9 -0
- package/scripts/release-parity-tests-r42.ps1 +6 -0
- package/scripts/verify-memory-r41.mjs +88 -0
- package/scripts/verify-r41-parent.mjs +61 -0
- package/scripts/verify-r42-parent.mjs +101 -0
- package/scripts/windows-gate-evidence-r41.mjs +53 -0
- package/scripts/windows-gate-evidence-r42.mjs +64 -0
- package/src/agent-eval-r42.mjs +73 -0
- package/src/agent-eval-runner-r42.mjs +138 -0
- package/src/agent-governance-r42.mjs +142 -0
- package/src/autonomous-context-engine.mjs +4 -1
- package/src/autonomous-loop-state.mjs +10 -0
- package/src/autonomous-mcp-tools.mjs +21 -6
- package/src/autonomous-output-contracts.mjs +18 -2
- package/src/autonomous-planner-contracts.mjs +3 -0
- package/src/autonomous-planner.mjs +48 -6
- package/src/autonomous-policy.mjs +10 -2
- package/src/autonomous-runtime.mjs +144 -25
- package/src/autonomous-supervisor.mjs +1 -1
- package/src/evidence-publisher-r42.mjs +76 -0
- package/src/mcp-server.mjs +15 -2
- package/src/memory-r41.mjs +692 -0
- package/src/provider-circuit.mjs +4 -4
- package/src/version.mjs +1 -1
- package/test/agent-eval-r42.test.mjs +39 -0
- package/test/agent-eval-runner-r42.test.mjs +61 -0
- package/test/agent-governance-r42.test.mjs +77 -0
- package/test/autonomous-r34-e2e.test.mjs +2 -1
- package/test/cli-entrypoint.test.mjs +1 -1
- package/test/controller-desktop-r40.test.mjs +2 -1
- package/test/core.test.mjs +1 -1
- package/test/evidence-publisher-r42.test.mjs +53 -0
- package/test/helpers/autonomous-r34-fixture.mjs +3 -3
- package/test/human-clarification-r42.test.mjs +53 -0
- package/test/memory-autonomous-integration-r41.test.mjs +31 -0
- package/test/memory-history-r41.test.mjs +126 -0
- package/test/memory-projections-r41.test.mjs +92 -0
- package/test/memory-retrieval-r41.test.mjs +124 -0
- package/test/memory-snapshot-r41.test.mjs +106 -0
- package/test/provider-responses-r42.test.mjs +90 -0
- package/test/r33-closeout-regression.test.mjs +27 -12
- package/test/r33-finalization.test.mjs +4 -4
- package/test/r41-finalization.test.mjs +38 -0
- package/test/r42-finalization.test.mjs +38 -0
- package/test/release-version.test.mjs +14 -13
- package/test/task-contract-r42.test.mjs +41 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { createHash, createPublicKey, randomBytes } from 'node:crypto';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { mkdir, readFile, realpath, writeFile } from 'node:fs/promises';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { parseActivePointer } from '../src/release-slot.mjs';
|
|
8
|
+
import { loadPowerShellDataFile, runSlotUpdateCli, verifySlotUpdateEnvelope } from '../src/runtime-update.mjs';
|
|
9
|
+
|
|
10
|
+
const HEX64=/^[0-9a-f]{64}$/;
|
|
11
|
+
const RECEIPT_ID=/^r27-[A-Za-z0-9-]+$/;
|
|
12
|
+
const here=path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const packageRoot=path.resolve(here,'..');
|
|
14
|
+
const stateRoot=path.resolve(process.env.DEADBYTE_STATE_ROOT||path.join(os.homedir(),'.deadbyte-mcp'));
|
|
15
|
+
const evidenceRoot=path.join(stateRoot,'evidence','deferred-slot-operations');
|
|
16
|
+
const sha256=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
17
|
+
const atomicJson=async(file,value)=>{
|
|
18
|
+
await mkdir(path.dirname(file),{recursive:true});
|
|
19
|
+
const temp=`${file}.${process.pid}.${randomBytes(4).toString('hex')}.tmp`;
|
|
20
|
+
await writeFile(temp,`${JSON.stringify(value,null,2)}\n`,{flag:'wx'});
|
|
21
|
+
await import('node:fs/promises').then(fs=>fs.rename(temp,file));
|
|
22
|
+
};
|
|
23
|
+
function activationArgs(manifestSha){
|
|
24
|
+
if(!HEX64.test(manifestSha??'')) throw new Error('activate requires one lowercase manifest SHA-256');
|
|
25
|
+
return ['--stage',packageRoot,'--development-root',packageRoot,'--expected-version','0.14.0',
|
|
26
|
+
'--expected-manifest',manifestSha,'--process-policy',path.join(packageRoot,'controller','deadbyte-process-policy.json'),
|
|
27
|
+
'--process-policy-sha256',null,'--desktop-policy',path.join(packageRoot,'controller','deadbyte-desktop-policy.json'),
|
|
28
|
+
'--desktop-policy-sha256',null,'--semantic-lsp-config',path.join(packageRoot,'controller','deadbyte-semantic-lsp-config.json'),
|
|
29
|
+
'--semantic-lsp-config-sha256',null,'--enable-machine-fs','--enable-observation','--enable-desktop','--enable-autonomous-supervisor'];
|
|
30
|
+
}
|
|
31
|
+
async function bridgeBootstrapArgs(explicitBridgeRoot=null,explicitBridgeSha256=null){
|
|
32
|
+
const hasRoot=typeof explicitBridgeRoot==='string'&&explicitBridgeRoot.length>0;
|
|
33
|
+
const hasSha=typeof explicitBridgeSha256==='string'&&explicitBridgeSha256.length>0;
|
|
34
|
+
if(hasRoot!==hasSha) throw new Error('bridge override requires exact root + SHA pair');
|
|
35
|
+
let bridgeRootRaw,expectedSha256=null;
|
|
36
|
+
if(hasRoot){
|
|
37
|
+
if(!path.isAbsolute(explicitBridgeRoot)||!HEX64.test(explicitBridgeSha256)) throw new Error('bridge override requires exact root + SHA pair');
|
|
38
|
+
bridgeRootRaw=explicitBridgeRoot;expectedSha256=explicitBridgeSha256;
|
|
39
|
+
}else{
|
|
40
|
+
const pointer=parseActivePointer(await readFile(path.join(stateRoot,'active-release.json'),'utf8'));
|
|
41
|
+
const config=await loadPowerShellDataFile(pointer.config_path);
|
|
42
|
+
bridgeRootRaw=config?.Bridge?.WorkingDirectory;
|
|
43
|
+
if(typeof bridgeRootRaw!=='string'||!path.isAbsolute(bridgeRootRaw)) throw new Error('active controller Bridge.WorkingDirectory must be absolute');
|
|
44
|
+
}
|
|
45
|
+
const bridgeRoot=await realpath(path.resolve(bridgeRootRaw));
|
|
46
|
+
const packageFile=path.join(bridgeRoot,'package.json');
|
|
47
|
+
const bridgeScript=path.join(bridgeRoot,'src','bridge.mjs');
|
|
48
|
+
const pkg=JSON.parse(await readFile(packageFile,'utf8'));
|
|
49
|
+
if(pkg?.name!=='deadbyte-chatgpt-bridge') throw new Error('active Bridge package identity mismatch');
|
|
50
|
+
const scriptSha256=sha256(await readFile(bridgeScript));
|
|
51
|
+
if(expectedSha256&&scriptSha256!==expectedSha256) throw new Error('bridge override SHA-256 mismatch');
|
|
52
|
+
return ['--bridge-root',bridgeRoot,'--bridge-script-sha256',scriptSha256];
|
|
53
|
+
}
|
|
54
|
+
async function rollbackArgs(receiptPath){
|
|
55
|
+
const resolved=await realpath(path.resolve(receiptPath));
|
|
56
|
+
const allowed=path.join(stateRoot,'evidence','updates')+path.sep;
|
|
57
|
+
if(!resolved.startsWith(allowed)||path.basename(resolved).toLowerCase()!=='receipt.json'||!RECEIPT_ID.test(path.basename(path.dirname(resolved)))) {
|
|
58
|
+
throw new Error('rollback receipt must be one signed activation receipt under the update evidence store');
|
|
59
|
+
}
|
|
60
|
+
const envelope=JSON.parse(await readFile(resolved,'utf8'));
|
|
61
|
+
const publicKey=createPublicKey(await readFile(path.join(stateRoot,'trust','ed25519-public.pem')));
|
|
62
|
+
if(!verifySlotUpdateEnvelope(envelope,publicKey)||envelope.body?.rollback_performed!==false) throw new Error('rollback activation receipt verification failed');
|
|
63
|
+
const pointer=parseActivePointer(await readFile(path.join(stateRoot,'active-release.json'),'utf8'));
|
|
64
|
+
if(pointer.release_id!==envelope.body?.active_pointer?.release_id||pointer.generation_root!==envelope.body?.active_pointer?.generation_root) {
|
|
65
|
+
throw new Error('rollback receipt does not identify the active release generation');
|
|
66
|
+
}
|
|
67
|
+
return ['--rollback-receipt',resolved];
|
|
68
|
+
}
|
|
69
|
+
async function normalizedArgs(mode,value,{explicitBridgeRoot=null,explicitBridgeSha256=null}={}){
|
|
70
|
+
if(mode==='activate'){
|
|
71
|
+
const args=activationArgs(value);
|
|
72
|
+
args[args.indexOf('--process-policy-sha256')+1]=sha256(await readFile(path.join(packageRoot,'controller','deadbyte-process-policy.json')));
|
|
73
|
+
args[args.indexOf('--desktop-policy-sha256')+1]=sha256(await readFile(path.join(packageRoot,'controller','deadbyte-desktop-policy.json')));
|
|
74
|
+
args[args.indexOf('--semantic-lsp-config-sha256')+1]=sha256(await readFile(path.join(packageRoot,'controller','deadbyte-semantic-lsp-config.json')));
|
|
75
|
+
args.push(...await bridgeBootstrapArgs(explicitBridgeRoot,explicitBridgeSha256));
|
|
76
|
+
return args;
|
|
77
|
+
}
|
|
78
|
+
if(mode==='rollback'){
|
|
79
|
+
if(explicitBridgeRoot||explicitBridgeSha256) throw new Error('rollback does not accept bridge override');
|
|
80
|
+
return rollbackArgs(value);
|
|
81
|
+
}
|
|
82
|
+
throw new Error("operation must be exactly 'activate' or 'rollback'");
|
|
83
|
+
}
|
|
84
|
+
const rawArgs=process.argv.slice(2);
|
|
85
|
+
const mode=rawArgs[0],value=rawArgs[1];
|
|
86
|
+
if(!value||!['activate','rollback'].includes(mode)) throw new Error('usage: deferred-slot-operation-r42.mjs <activate manifest_sha256|rollback activation_receipt> [--bridge-root ABS --bridge-script-sha256 HEX64]');
|
|
87
|
+
let cursor=2,explicitBridgeRoot=null,explicitBridgeSha256=null;
|
|
88
|
+
if(rawArgs[cursor]==='--bridge-root'){
|
|
89
|
+
explicitBridgeRoot=rawArgs[cursor+1]??null;
|
|
90
|
+
if(rawArgs[cursor+2]!=='--bridge-script-sha256') throw new Error('bridge override requires exact root + SHA pair');
|
|
91
|
+
explicitBridgeSha256=rawArgs[cursor+3]??null;cursor+=4;
|
|
92
|
+
}
|
|
93
|
+
let workerFlag=null,operationIdArg=null;
|
|
94
|
+
if(rawArgs[cursor]==='--worker'){workerFlag='--worker';operationIdArg=rawArgs[cursor+1]??null;cursor+=2;}
|
|
95
|
+
if(cursor!==rawArgs.length) throw new Error('deferred slot operation arguments invalid');
|
|
96
|
+
if((explicitBridgeRoot===null)!==(explicitBridgeSha256===null)) throw new Error('bridge override requires exact root + SHA pair');
|
|
97
|
+
if(mode==='rollback'&&(explicitBridgeRoot||explicitBridgeSha256)) throw new Error('rollback does not accept bridge override');
|
|
98
|
+
if(workerFlag==='--worker'){
|
|
99
|
+
if(!/^[0-9a-f]{32}$/.test(operationIdArg??'')) throw new Error('deferred worker operation id invalid');
|
|
100
|
+
const statePath=path.join(evidenceRoot,`${operationIdArg}.json`);
|
|
101
|
+
await new Promise(resolve=>setTimeout(resolve,4000));
|
|
102
|
+
await atomicJson(statePath,{schema:'deadbyte.deferred-slot-operation.v1',operation_id:operationIdArg,mode,state:'running',started_at_utc:new Date().toISOString(),bridge_root:explicitBridgeRoot,bridge_script_sha256:explicitBridgeSha256});
|
|
103
|
+
try{
|
|
104
|
+
const args=await normalizedArgs(mode,value,{explicitBridgeRoot,explicitBridgeSha256});
|
|
105
|
+
const result=await runSlotUpdateCli(args,{stateRoot});
|
|
106
|
+
await atomicJson(statePath,{schema:'deadbyte.deferred-slot-operation.v1',operation_id:operationIdArg,mode,state:'completed',
|
|
107
|
+
completed_at_utc:new Date().toISOString(),receipt_path:result.receipt_path,receipt_sha256:result.receipt_sha256,
|
|
108
|
+
active_release:result.pointer.release_id,generation_root:result.pointer.generation_root,bridge_root:explicitBridgeRoot,bridge_script_sha256:explicitBridgeSha256});
|
|
109
|
+
}catch(error){
|
|
110
|
+
await atomicJson(statePath,{schema:'deadbyte.deferred-slot-operation.v1',operation_id:operationIdArg,mode,state:'failed',
|
|
111
|
+
completed_at_utc:new Date().toISOString(),error:String(error?.message??error),bridge_root:explicitBridgeRoot,bridge_script_sha256:explicitBridgeSha256});
|
|
112
|
+
process.exitCode=1;
|
|
113
|
+
}
|
|
114
|
+
}else{
|
|
115
|
+
const operationId=randomBytes(16).toString('hex');
|
|
116
|
+
const statePath=path.join(evidenceRoot,`${operationId}.json`);
|
|
117
|
+
await atomicJson(statePath,{schema:'deadbyte.deferred-slot-operation.v1',operation_id:operationId,mode,state:'scheduled',scheduled_at_utc:new Date().toISOString(),bridge_root:explicitBridgeRoot,bridge_script_sha256:explicitBridgeSha256});
|
|
118
|
+
const workerArgs=[fileURLToPath(import.meta.url),mode,value];
|
|
119
|
+
if(explicitBridgeRoot) workerArgs.push('--bridge-root',explicitBridgeRoot,'--bridge-script-sha256',explicitBridgeSha256);
|
|
120
|
+
workerArgs.push('--worker',operationId);
|
|
121
|
+
const child=spawn(process.execPath,workerArgs,{
|
|
122
|
+
cwd:packageRoot,detached:true,stdio:'ignore',windowsHide:true,env:{...process.env,DEADBYTE_STATE_ROOT:stateRoot}
|
|
123
|
+
});
|
|
124
|
+
child.unref();
|
|
125
|
+
console.log(JSON.stringify({status:'scheduled',operation_id:operationId,mode,state_path:statePath,execution_provider:'deadbyte_mcp',rdc_operation_count:0,bridge_root:explicitBridgeRoot,bridge_script_sha256:explicitBridgeSha256}));
|
|
126
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createHash, createPrivateKey, createPublicKey, sign as cryptoSign } from 'node:crypto';
|
|
2
|
+
import { lstat, mkdir, open, readFile, rename, rm } from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { probeR40FullSurface } from '../src/r40-full-surface-probe.mjs';
|
|
7
|
+
import { probeR40CompactDisarmed } from '../src/r40-compact-disarmed-probe.mjs';
|
|
8
|
+
import {
|
|
9
|
+
validateParityEvidence,
|
|
10
|
+
R41_PREDECESSOR_RELEASE_ID,
|
|
11
|
+
R41_PREDECESSOR_MANIFEST
|
|
12
|
+
} from './release-parity-r41.mjs';
|
|
13
|
+
|
|
14
|
+
const DOMAIN=Buffer.from('DEADBYTE-R41-FINAL-CLOSURE-V1\0','utf8');
|
|
15
|
+
const stateRoot=path.resolve(process.env.DEADBYTE_STATE_ROOT||path.join(os.homedir(),'.deadbyte-mcp'));
|
|
16
|
+
const sha256=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
17
|
+
const canonical=value=>Array.isArray(value)?value.map(canonical):value&&typeof value==='object'
|
|
18
|
+
?Object.fromEntries(Object.keys(value).sort().map(key=>[key,canonical(value[key])])):value;
|
|
19
|
+
const canonicalJson=value=>JSON.stringify(canonical(value));
|
|
20
|
+
function insist(ok,msg){if(!ok) throw new Error(msg);}
|
|
21
|
+
function samePath(a,b){return path.resolve(String(a)).toLowerCase()===path.resolve(String(b)).toLowerCase();}
|
|
22
|
+
async function fileEvidence(file){const abs=path.resolve(file),bytes=await readFile(abs);return {path:abs,sha256:sha256(bytes)};}
|
|
23
|
+
async function publicUrl(){
|
|
24
|
+
const value=(await readFile(path.join(stateRoot,'bridge','mcp-url.txt'),'utf8')).trim();
|
|
25
|
+
const url=new URL(value);insist(url.protocol==='https:','final closure requires HTTPS public endpoint');return value;
|
|
26
|
+
}
|
|
27
|
+
async function grantAbsence(){
|
|
28
|
+
const out={};
|
|
29
|
+
for(const name of ['process-grant.json','coding-grant.json','autonomous-grant.json','desktop-grant.json','host-grant.json']){
|
|
30
|
+
let absent=false;try{await lstat(path.join(stateRoot,'runtime',name));}catch(error){if(error?.code==='ENOENT') absent=true;else throw error;}
|
|
31
|
+
insist(absent,`authority grant still present: ${name}`);out[name]=true;
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
async function atomicCreate(file,bytes){
|
|
36
|
+
await mkdir(path.dirname(file),{recursive:true});
|
|
37
|
+
const temp=`${file}.tmp-${process.pid}-${Math.random().toString(16).slice(2)}`;
|
|
38
|
+
const handle=await open(temp,'wx');
|
|
39
|
+
try{await handle.writeFile(bytes);await handle.sync();}finally{await handle.close();}
|
|
40
|
+
try{await rename(temp,file);}catch(error){await rm(temp,{force:true}).catch(()=>{});throw error;}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function writeFinalClosure({parityPath,activationPath,windowsGatePath}){
|
|
44
|
+
const pointer=JSON.parse(await readFile(path.join(stateRoot,'active-release.json'),'utf8'));
|
|
45
|
+
insist(pointer.version==='0.13.0','final closure requires V0.13.0 active release');
|
|
46
|
+
insist(pointer.release_id===`v${pointer.version}-${pointer.manifest_sha256.slice(0,16)}`,'final closure release id/content address mismatch');
|
|
47
|
+
|
|
48
|
+
const parity=JSON.parse(await readFile(path.resolve(parityPath),'utf8'));
|
|
49
|
+
insist(parity.schema==='deadbyte.r41-parity.v1','R40 parity schema mismatch at final closure');
|
|
50
|
+
validateParityEvidence(parity);
|
|
51
|
+
insist(parity.candidate?.release_id===pointer.release_id&&parity.candidate?.manifest_sha256===pointer.manifest_sha256,'parity candidate/current release mismatch');
|
|
52
|
+
insist(parity.successor?.release_id===pointer.release_id&&parity.successor?.manifest_sha256===pointer.manifest_sha256,'parity successor/current release mismatch');
|
|
53
|
+
insist(parity.predecessor?.release_id===R41_PREDECESSOR_RELEASE_ID&&parity.predecessor?.manifest_sha256===R41_PREDECESSOR_MANIFEST,'parity predecessor identity mismatch');
|
|
54
|
+
insist(parity.rollback?.receipt_path&&parity.restore?.receipt_path,'parity rollback/restore receipt paths missing');
|
|
55
|
+
insist(parity.immutable_slot?.protected===true,'parity immutable-slot proof missing');
|
|
56
|
+
insist(samePath(parity.immutable_slot.release_root,pointer.release_root),'parity immutable release root mismatch');
|
|
57
|
+
insist(!samePath(parity.immutable_slot.development_root,pointer.release_root),'development_root must differ from immutable release_root');
|
|
58
|
+
|
|
59
|
+
const windowsGate=JSON.parse(await readFile(path.resolve(windowsGatePath),'utf8'));
|
|
60
|
+
insist(windowsGate.schema==='deadbyte.r41-windows-gate.v1'&&windowsGate.status==='passed'&&windowsGate.exit_code===0,'R40 Windows gate evidence invalid');
|
|
61
|
+
insist(windowsGate.version==='0.13.0'&&windowsGate.manifest_sha256===pointer.manifest_sha256,'R40 Windows gate/current release mismatch');
|
|
62
|
+
insist(windowsGate.marker==='DEADBYTE V0.13.0 / R41 WINDOWS BATCH GATE: PASS','R40 Windows gate marker mismatch');
|
|
63
|
+
|
|
64
|
+
const localFull=await probeR40FullSurface({packageRoot:pointer.release_root,generationRoot:pointer.generation_root,stateRoot});
|
|
65
|
+
insist(localFull.status==='passed'&&localFull.tool_count===80&&localFull.strict_output_schemas===true,'final local full 80-tool proof failed');
|
|
66
|
+
const compact=await probeR40CompactDisarmed(await publicUrl());
|
|
67
|
+
insist(compact.status==='passed'&&compact.tool_count===42&&compact.capability_closure===true,'final public compact capability closure failed');
|
|
68
|
+
insist(compact.coding_armed===false&&compact.autonomous_armed===false&&compact.desktop_armed===false,'final public compact authority is not DISARMED');
|
|
69
|
+
insist(compact.desktop_observation_receipt_verified===true&&compact.desktop_grounding_receipt_verified===true,'final public Desktop read-only proof missing');
|
|
70
|
+
insist(compact.release_id===pointer.release_id&&compact.release_manifest_sha256===pointer.manifest_sha256,'final public compact release binding mismatch');
|
|
71
|
+
insist(compact.machine_status?.release_id===pointer.release_id&&compact.machine_status?.release_manifest_sha256===pointer.manifest_sha256,'final machine status/current release mismatch');
|
|
72
|
+
insist(compact.machine_ping?.nonce===compact.nonce,'final machine ping nonce mismatch');
|
|
73
|
+
|
|
74
|
+
const evidence={
|
|
75
|
+
parity:await fileEvidence(parityPath),activation:await fileEvidence(activationPath),
|
|
76
|
+
rollback:await fileEvidence(parity.rollback.receipt_path),restore:await fileEvidence(parity.restore.receipt_path),
|
|
77
|
+
windows_gate:await fileEvidence(windowsGatePath)
|
|
78
|
+
};
|
|
79
|
+
const body={
|
|
80
|
+
schema:'deadbyte.r41-final-closure.v1',version:'0.13.0',release_label:'R41 DETERMINISTIC MEMORY BASELINE',
|
|
81
|
+
completed_at_utc:new Date().toISOString(),active_pointer:pointer,
|
|
82
|
+
predecessor:{release_id:R41_PREDECESSOR_RELEASE_ID,version:'0.12.0',manifest_sha256:R41_PREDECESSOR_MANIFEST},
|
|
83
|
+
immutable_slot:{protected:true,release_root:path.resolve(pointer.release_root),development_root:path.resolve(parity.immutable_slot.development_root)},
|
|
84
|
+
surfaces:{
|
|
85
|
+
local_full:{status:localFull.status,profile:localFull.profile,tool_count:localFull.tool_count,catalog_sha256:localFull.catalog_sha256,strict_output_schemas:localFull.strict_output_schemas,protocol_revision:localFull.protocol_revision},
|
|
86
|
+
public_compact:{status:compact.status,profile:compact.profile,tool_count:compact.tool_count,catalog_sha256:compact.catalog_sha256,strict_output_schemas:compact.strict_output_schemas,ledger_sha256:compact.ledger_sha256,capability_count:compact.capability_count,production_non_host_capabilities:compact.production_non_host_capabilities,capability_closure:compact.capability_closure,coding_armed:compact.coding_armed,autonomous_armed:compact.autonomous_armed,desktop_armed:compact.desktop_armed,desktop_observation_receipt_verified:compact.desktop_observation_receipt_verified,desktop_grounding_receipt_verified:compact.desktop_grounding_receipt_verified,protocol_revision:compact.protocol_revision},
|
|
87
|
+
deterministic_memory:parity.deterministic_memory
|
|
88
|
+
},
|
|
89
|
+
evidence,
|
|
90
|
+
machine:{status:compact.machine_status,ping:compact.machine_ping,nonce:compact.nonce},
|
|
91
|
+
authority:{all_disarmed:true,grants_absent:await grantAbsence()}
|
|
92
|
+
};
|
|
93
|
+
const privateKey=createPrivateKey(await readFile(path.join(stateRoot,'trust','ed25519-private.pem')));
|
|
94
|
+
const publicKey=createPublicKey(privateKey);
|
|
95
|
+
insist(privateKey.asymmetricKeyType==='ed25519'&&publicKey.asymmetricKeyType==='ed25519','closure signing key must be Ed25519');
|
|
96
|
+
const keyId=sha256(Buffer.from(publicKey.export({type:'spki',format:'der'})));
|
|
97
|
+
const bodyBytes=Buffer.from(canonicalJson(body),'utf8');
|
|
98
|
+
const signature=cryptoSign(null,Buffer.concat([DOMAIN,bodyBytes]),privateKey);
|
|
99
|
+
const envelope={body,body_sha256:sha256(bodyBytes),attestation:{algorithm:'ed25519',domain:'DEADBYTE-R41-FINAL-CLOSURE-V1',key_id:keyId,signature_base64:signature.toString('base64')}};
|
|
100
|
+
envelope.closure_sha256=sha256(Buffer.from(canonicalJson(envelope),'utf8'));
|
|
101
|
+
const dir=path.join(stateRoot,'evidence','release');
|
|
102
|
+
const file=path.join(dir,`r41-final-${pointer.manifest_sha256.slice(0,16)}.json`);
|
|
103
|
+
const bytes=Buffer.from(`${JSON.stringify(envelope,null,2)}\n`,'utf8');
|
|
104
|
+
await atomicCreate(file,bytes);
|
|
105
|
+
return {status:'written',path:file,sha256:sha256(bytes),closure_sha256:envelope.closure_sha256,release_id:pointer.release_id};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const invoked=process.argv[1]&&path.resolve(process.argv[1])===fileURLToPath(import.meta.url);
|
|
109
|
+
if(invoked){
|
|
110
|
+
const [parityPath,activationPath,windowsGatePath]=process.argv.slice(2);
|
|
111
|
+
if(!parityPath||!activationPath||!windowsGatePath) throw new Error('usage: node scripts/final-closure-r41.mjs <parity.json> <activation-receipt.json> <windows-gate.json>');
|
|
112
|
+
writeFinalClosure({parityPath,activationPath,windowsGatePath})
|
|
113
|
+
.then(result=>console.log(JSON.stringify(result,null,2)))
|
|
114
|
+
.catch(error=>{console.error(error instanceof Error?error.stack:String(error));process.exitCode=1;});
|
|
115
|
+
}
|
|
116
|
+
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createHash, createPrivateKey, createPublicKey, sign as cryptoSign } from 'node:crypto';
|
|
2
|
+
import { lstat, mkdir, open, readFile, rename, rm } from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { probeR40FullSurface } from '../src/r40-full-surface-probe.mjs';
|
|
7
|
+
import { probeR40CompactDisarmed } from '../src/r40-compact-disarmed-probe.mjs';
|
|
8
|
+
import {
|
|
9
|
+
validateParityEvidence,
|
|
10
|
+
R42_PREDECESSOR_RELEASE_ID,
|
|
11
|
+
R42_PREDECESSOR_MANIFEST
|
|
12
|
+
} from './release-parity-r42.mjs';
|
|
13
|
+
|
|
14
|
+
const DOMAIN=Buffer.from('DEADBYTE-R42-FINAL-CLOSURE-V1\0','utf8');
|
|
15
|
+
const stateRoot=path.resolve(process.env.DEADBYTE_STATE_ROOT||path.join(os.homedir(),'.deadbyte-mcp'));
|
|
16
|
+
const sha256=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
17
|
+
const canonical=value=>Array.isArray(value)?value.map(canonical):value&&typeof value==='object'
|
|
18
|
+
?Object.fromEntries(Object.keys(value).sort().map(key=>[key,canonical(value[key])])):value;
|
|
19
|
+
const canonicalJson=value=>JSON.stringify(canonical(value));
|
|
20
|
+
function insist(ok,msg){if(!ok) throw new Error(msg);}
|
|
21
|
+
function samePath(a,b){return path.resolve(String(a)).toLowerCase()===path.resolve(String(b)).toLowerCase();}
|
|
22
|
+
async function fileEvidence(file){const abs=path.resolve(file),bytes=await readFile(abs);return {path:abs,sha256:sha256(bytes)};}
|
|
23
|
+
async function publicUrl(){
|
|
24
|
+
const value=(await readFile(path.join(stateRoot,'bridge','mcp-url.txt'),'utf8')).trim();
|
|
25
|
+
const url=new URL(value);insist(url.protocol==='https:','final closure requires HTTPS public endpoint');return value;
|
|
26
|
+
}
|
|
27
|
+
async function grantAbsence(){
|
|
28
|
+
const out={};
|
|
29
|
+
for(const name of ['process-grant.json','coding-grant.json','autonomous-grant.json','desktop-grant.json','host-grant.json']){
|
|
30
|
+
let absent=false;try{await lstat(path.join(stateRoot,'runtime',name));}catch(error){if(error?.code==='ENOENT') absent=true;else throw error;}
|
|
31
|
+
insist(absent,`authority grant still present: ${name}`);out[name]=true;
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
async function atomicCreate(file,bytes){
|
|
36
|
+
await mkdir(path.dirname(file),{recursive:true});
|
|
37
|
+
const temp=`${file}.tmp-${process.pid}-${Math.random().toString(16).slice(2)}`;
|
|
38
|
+
const handle=await open(temp,'wx');
|
|
39
|
+
try{await handle.writeFile(bytes);await handle.sync();}finally{await handle.close();}
|
|
40
|
+
try{await rename(temp,file);}catch(error){await rm(temp,{force:true}).catch(()=>{});throw error;}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function writeFinalClosure({parityPath,activationPath,windowsGatePath}){
|
|
44
|
+
const pointer=JSON.parse(await readFile(path.join(stateRoot,'active-release.json'),'utf8'));
|
|
45
|
+
insist(pointer.version==='0.14.0','final closure requires V0.14.0 active release');
|
|
46
|
+
insist(pointer.release_id===`v${pointer.version}-${pointer.manifest_sha256.slice(0,16)}`,'final closure release id/content address mismatch');
|
|
47
|
+
|
|
48
|
+
const parity=JSON.parse(await readFile(path.resolve(parityPath),'utf8'));
|
|
49
|
+
insist(parity.schema==='deadbyte.r42-parity.v1','R40 parity schema mismatch at final closure');
|
|
50
|
+
validateParityEvidence(parity);
|
|
51
|
+
insist(parity.candidate?.release_id===pointer.release_id&&parity.candidate?.manifest_sha256===pointer.manifest_sha256,'parity candidate/current release mismatch');
|
|
52
|
+
insist(parity.successor?.release_id===pointer.release_id&&parity.successor?.manifest_sha256===pointer.manifest_sha256,'parity successor/current release mismatch');
|
|
53
|
+
insist(parity.predecessor?.release_id===R42_PREDECESSOR_RELEASE_ID&&parity.predecessor?.manifest_sha256===R42_PREDECESSOR_MANIFEST,'parity predecessor identity mismatch');
|
|
54
|
+
insist(parity.rollback?.receipt_path&&parity.restore?.receipt_path,'parity rollback/restore receipt paths missing');
|
|
55
|
+
insist(parity.immutable_slot?.protected===true,'parity immutable-slot proof missing');
|
|
56
|
+
insist(samePath(parity.immutable_slot.release_root,pointer.release_root),'parity immutable release root mismatch');
|
|
57
|
+
insist(!samePath(parity.immutable_slot.development_root,pointer.release_root),'development_root must differ from immutable release_root');
|
|
58
|
+
|
|
59
|
+
const windowsGate=JSON.parse(await readFile(path.resolve(windowsGatePath),'utf8'));
|
|
60
|
+
insist(windowsGate.schema==='deadbyte.r42-windows-gate.v1'&&windowsGate.status==='passed'&&windowsGate.exit_code===0,'R40 Windows gate evidence invalid');
|
|
61
|
+
insist(windowsGate.version==='0.14.0'&&windowsGate.manifest_sha256===pointer.manifest_sha256,'R40 Windows gate/current release mismatch');
|
|
62
|
+
insist(windowsGate.marker==='DEADBYTE V0.14.0 / R42 WINDOWS BATCH GATE: PASS','R40 Windows gate marker mismatch');
|
|
63
|
+
|
|
64
|
+
const localFull=await probeR40FullSurface({packageRoot:pointer.release_root,generationRoot:pointer.generation_root,stateRoot});
|
|
65
|
+
insist(localFull.status==='passed'&&localFull.tool_count===80&&localFull.strict_output_schemas===true,'final local full 80-tool proof failed');
|
|
66
|
+
const compact=await probeR40CompactDisarmed(await publicUrl());
|
|
67
|
+
insist(compact.status==='passed'&&compact.tool_count===42&&compact.capability_closure===true,'final public compact capability closure failed');
|
|
68
|
+
insist(compact.coding_armed===false&&compact.autonomous_armed===false&&compact.desktop_armed===false,'final public compact authority is not DISARMED');
|
|
69
|
+
insist(compact.desktop_observation_receipt_verified===true&&compact.desktop_grounding_receipt_verified===true,'final public Desktop read-only proof missing');
|
|
70
|
+
insist(compact.release_id===pointer.release_id&&compact.release_manifest_sha256===pointer.manifest_sha256,'final public compact release binding mismatch');
|
|
71
|
+
insist(compact.machine_status?.release_id===pointer.release_id&&compact.machine_status?.release_manifest_sha256===pointer.manifest_sha256,'final machine status/current release mismatch');
|
|
72
|
+
insist(compact.machine_ping?.nonce===compact.nonce,'final machine ping nonce mismatch');
|
|
73
|
+
|
|
74
|
+
const evidence={
|
|
75
|
+
parity:await fileEvidence(parityPath),activation:await fileEvidence(activationPath),
|
|
76
|
+
rollback:await fileEvidence(parity.rollback.receipt_path),restore:await fileEvidence(parity.restore.receipt_path),
|
|
77
|
+
windows_gate:await fileEvidence(windowsGatePath),model_eval:await fileEvidence(parity.model_eval.path)
|
|
78
|
+
};
|
|
79
|
+
const body={
|
|
80
|
+
schema:'deadbyte.r42-final-closure.v1',version:'0.14.0',release_label:'R42 AGENTIC GOVERNANCE BASELINE',
|
|
81
|
+
completed_at_utc:new Date().toISOString(),active_pointer:pointer,
|
|
82
|
+
predecessor:{release_id:R42_PREDECESSOR_RELEASE_ID,version:'0.13.0',manifest_sha256:R42_PREDECESSOR_MANIFEST},
|
|
83
|
+
immutable_slot:{protected:true,release_root:path.resolve(pointer.release_root),development_root:path.resolve(parity.immutable_slot.development_root)},
|
|
84
|
+
surfaces:{
|
|
85
|
+
local_full:{status:localFull.status,profile:localFull.profile,tool_count:localFull.tool_count,catalog_sha256:localFull.catalog_sha256,strict_output_schemas:localFull.strict_output_schemas,protocol_revision:localFull.protocol_revision},
|
|
86
|
+
public_compact:{status:compact.status,profile:compact.profile,tool_count:compact.tool_count,catalog_sha256:compact.catalog_sha256,strict_output_schemas:compact.strict_output_schemas,ledger_sha256:compact.ledger_sha256,capability_count:compact.capability_count,production_non_host_capabilities:compact.production_non_host_capabilities,capability_closure:compact.capability_closure,coding_armed:compact.coding_armed,autonomous_armed:compact.autonomous_armed,desktop_armed:compact.desktop_armed,desktop_observation_receipt_verified:compact.desktop_observation_receipt_verified,desktop_grounding_receipt_verified:compact.desktop_grounding_receipt_verified,protocol_revision:compact.protocol_revision},
|
|
87
|
+
deterministic_memory:parity.deterministic_memory,
|
|
88
|
+
model_eval:parity.model_eval
|
|
89
|
+
},
|
|
90
|
+
evidence,
|
|
91
|
+
machine:{status:compact.machine_status,ping:compact.machine_ping,nonce:compact.nonce},
|
|
92
|
+
authority:{all_disarmed:true,grants_absent:await grantAbsence()}
|
|
93
|
+
};
|
|
94
|
+
const privateKey=createPrivateKey(await readFile(path.join(stateRoot,'trust','ed25519-private.pem')));
|
|
95
|
+
const publicKey=createPublicKey(privateKey);
|
|
96
|
+
insist(privateKey.asymmetricKeyType==='ed25519'&&publicKey.asymmetricKeyType==='ed25519','closure signing key must be Ed25519');
|
|
97
|
+
const keyId=sha256(Buffer.from(publicKey.export({type:'spki',format:'der'})));
|
|
98
|
+
const bodyBytes=Buffer.from(canonicalJson(body),'utf8');
|
|
99
|
+
const signature=cryptoSign(null,Buffer.concat([DOMAIN,bodyBytes]),privateKey);
|
|
100
|
+
const envelope={body,body_sha256:sha256(bodyBytes),attestation:{algorithm:'ed25519',domain:'DEADBYTE-R42-FINAL-CLOSURE-V1',key_id:keyId,signature_base64:signature.toString('base64')}};
|
|
101
|
+
envelope.closure_sha256=sha256(Buffer.from(canonicalJson(envelope),'utf8'));
|
|
102
|
+
const dir=path.join(stateRoot,'evidence','release');
|
|
103
|
+
const file=path.join(dir,`r42-final-${pointer.manifest_sha256.slice(0,16)}.json`);
|
|
104
|
+
const bytes=Buffer.from(`${JSON.stringify(envelope,null,2)}\n`,'utf8');
|
|
105
|
+
await atomicCreate(file,bytes);
|
|
106
|
+
return {status:'written',path:file,sha256:sha256(bytes),closure_sha256:envelope.closure_sha256,release_id:pointer.release_id};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const invoked=process.argv[1]&&path.resolve(process.argv[1])===fileURLToPath(import.meta.url);
|
|
110
|
+
if(invoked){
|
|
111
|
+
const [parityPath,activationPath,windowsGatePath]=process.argv.slice(2);
|
|
112
|
+
if(!parityPath||!activationPath||!windowsGatePath) throw new Error('usage: node scripts/final-closure-r42.mjs <parity.json> <activation-receipt.json> <windows-gate.json>');
|
|
113
|
+
writeFinalClosure({parityPath,activationPath,windowsGatePath})
|
|
114
|
+
.then(result=>console.log(JSON.stringify(result,null,2)))
|
|
115
|
+
.catch(error=>{console.error(error instanceof Error?error.stack:String(error));process.exitCode=1;});
|
|
116
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { createHash, createPublicKey, verify as cryptoVerify } from 'node:crypto';
|
|
2
|
+
import { lstat, readFile, readdir } from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const HEX64=/^[0-9a-f]{64}$/;
|
|
8
|
+
const UPDATE_DOMAIN=Buffer.from('DEADBYTE-R27-SLOT-UPDATE-V1\0','utf8');
|
|
9
|
+
const CLOSURE_DOMAIN=Buffer.from('DEADBYTE-R41-FINAL-CLOSURE-V1\0','utf8');
|
|
10
|
+
const PING_DOMAIN=Buffer.from('DEADBYTE-MACHINE-PING-V1\0','utf8');
|
|
11
|
+
const R41_PREDECESSOR_RELEASE_ID='v0.12.0-70906ae0a7e4f062';
|
|
12
|
+
const R41_PREDECESSOR_MANIFEST='70906ae0a7e4f0627efbb5087b40b85677c81ed6d64ed89c0ba2af846e390f39';
|
|
13
|
+
const R40_FULL_TOOL_COUNT=80;
|
|
14
|
+
const R40_COMPACT_TOOL_COUNT=42;
|
|
15
|
+
const REQUIRED_PARITY_KEYS=['tree_read','precondition_mutation','search','owned_process','observation','coding_loop','autonomy','interrupted_recovery','evidence_verification','compact_closure','full_surface','desktop_readonly','desktop_guarded_input','deterministic_memory'];
|
|
16
|
+
const sha256=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
17
|
+
const canonical=value=>Array.isArray(value)?value.map(canonical):value&&typeof value==='object'
|
|
18
|
+
?Object.fromEntries(Object.keys(value).sort().map(key=>[key,canonical(value[key])])):value;
|
|
19
|
+
const canonicalJson=value=>JSON.stringify(canonical(value));
|
|
20
|
+
const same=(a,b)=>canonicalJson(a)===canonicalJson(b);
|
|
21
|
+
function insist(ok,msg){if(!ok) throw new Error(msg);}
|
|
22
|
+
function samePath(a,b){return path.resolve(String(a)).toLowerCase()===path.resolve(String(b)).toLowerCase();}
|
|
23
|
+
function isCandidateIdentity(value,manifest){
|
|
24
|
+
return value?.version==='0.13.0'&&value?.manifest_sha256===manifest&&value?.release_id===`v0.13.0-${manifest.slice(0,16)}`;
|
|
25
|
+
}
|
|
26
|
+
function isR40PredecessorIdentity(value){
|
|
27
|
+
return value?.version==='0.12.0'&&value?.manifest_sha256===R41_PREDECESSOR_MANIFEST&&value?.release_id===R41_PREDECESSOR_RELEASE_ID;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function parseManifest(text){
|
|
31
|
+
const out=new Map();
|
|
32
|
+
for(const [i,line] of text.split(/\r?\n/).entries()){
|
|
33
|
+
if(!line) continue;
|
|
34
|
+
const m=/^([0-9a-f]{64}) ([^\0]+)$/.exec(line);insist(m,`manifest line ${i+1} malformed`);
|
|
35
|
+
insist(!path.posix.isAbsolute(m[2])&&!m[2].split('/').includes('..')&&!out.has(m[2]),`unsafe/duplicate manifest path ${m[2]}`);
|
|
36
|
+
out.set(m[2],m[1]);
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
async function walk(root,rel=''){
|
|
41
|
+
const dir=path.join(root,...(rel?rel.split('/'):[]));
|
|
42
|
+
const names=(await readdir(dir)).sort((a,b)=>a.localeCompare(b,'en'));
|
|
43
|
+
const files=[];
|
|
44
|
+
for(const name of names){
|
|
45
|
+
const childRel=rel?`${rel}/${name}`:name;
|
|
46
|
+
const full=path.join(root,...childRel.split('/'));
|
|
47
|
+
const st=await lstat(full);insist(!st.isSymbolicLink(),`symlink forbidden: ${childRel}`);
|
|
48
|
+
if(st.isDirectory()) files.push(...await walk(root,childRel));
|
|
49
|
+
else{insist(st.isFile(),`non-file forbidden: ${childRel}`);files.push(childRel);}
|
|
50
|
+
}
|
|
51
|
+
return files;
|
|
52
|
+
}
|
|
53
|
+
async function verifyTree(root,manifestName,expectedDigest){
|
|
54
|
+
const manifestBytes=await readFile(path.join(root,manifestName));
|
|
55
|
+
insist(sha256(manifestBytes)===expectedDigest,`${manifestName} digest mismatch`);
|
|
56
|
+
const entries=parseManifest(manifestBytes.toString('utf8'));
|
|
57
|
+
const actual=(await walk(root)).filter(rel=>rel!==manifestName).sort((a,b)=>a.localeCompare(b,'en'));
|
|
58
|
+
const expected=[...entries.keys()].sort((a,b)=>a.localeCompare(b,'en'));
|
|
59
|
+
insist(same(actual,expected),`${manifestName} exact tree mismatch`);
|
|
60
|
+
for(const [rel,digest] of entries) insist(sha256(await readFile(path.join(root,...rel.split('/'))))===digest,`${manifestName} file hash mismatch: ${rel}`);
|
|
61
|
+
return entries.size;
|
|
62
|
+
}
|
|
63
|
+
function publicKeyInfo(publicPem){
|
|
64
|
+
const key=createPublicKey(publicPem);insist(key.asymmetricKeyType==='ed25519','public key must be Ed25519');
|
|
65
|
+
const der=Buffer.from(key.export({type:'spki',format:'der'}));
|
|
66
|
+
return {key,key_id:sha256(der),spki_base64:der.toString('base64')};
|
|
67
|
+
}
|
|
68
|
+
function verifyUpdateEnvelope(env,keyInfo){
|
|
69
|
+
insist(env?.body&&env?.attestation,'update envelope malformed');
|
|
70
|
+
const bodyBytes=Buffer.from(canonicalJson(env.body),'utf8');
|
|
71
|
+
insist(sha256(bodyBytes)===env.body_sha256,'update body hash mismatch');
|
|
72
|
+
const {receipt_sha256,...unsigned}=env;
|
|
73
|
+
insist(sha256(Buffer.from(canonicalJson(unsigned),'utf8'))===receipt_sha256,'update receipt hash mismatch');
|
|
74
|
+
insist(env.attestation.algorithm==='ed25519'&&env.attestation.domain==='DEADBYTE-R27-SLOT-UPDATE-V1','update attestation contract mismatch');
|
|
75
|
+
insist(env.attestation.key_id===keyInfo.key_id,'update signer mismatch');
|
|
76
|
+
insist(cryptoVerify(null,Buffer.concat([UPDATE_DOMAIN,bodyBytes]),keyInfo.key,Buffer.from(env.attestation.signature_base64,'base64')),'update signature invalid');
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
function verifyPing(ping,status,pointer){
|
|
80
|
+
insist(ping?.status==='ok'&&ping.schema==='deadbyte.machine-ping.v1','machine ping malformed');
|
|
81
|
+
insist(status?.status==='ok'&&typeof status.public_key_spki_base64==='string','machine status malformed');
|
|
82
|
+
const der=Buffer.from(status.public_key_spki_base64,'base64');
|
|
83
|
+
insist(der.toString('base64')===status.public_key_spki_base64,'machine SPKI base64 non-canonical');
|
|
84
|
+
const machineKey=createPublicKey({key:der,format:'der',type:'spki'});insist(machineKey.asymmetricKeyType==='ed25519','machine key must be Ed25519');
|
|
85
|
+
const machineId=sha256(der);
|
|
86
|
+
insist(status.machine_id===machineId&&ping.machine_id===machineId&&ping.attestation?.key_id===machineId,'machine id/key mismatch');
|
|
87
|
+
insist(ping.release_id===pointer.release_id&&ping.release_manifest_sha256===pointer.manifest_sha256,'machine ping release binding mismatch');
|
|
88
|
+
insist(ping.generation_manifest_sha256===pointer.generation_manifest_sha256,'machine ping generation binding mismatch');
|
|
89
|
+
const {status:_s,attestation:_a,...body}=ping;
|
|
90
|
+
const bytes=Buffer.from(canonicalJson(body),'utf8');
|
|
91
|
+
insist(cryptoVerify(null,Buffer.concat([PING_DOMAIN,bytes]),machineKey,Buffer.from(ping.attestation.signature_base64,'base64')),'machine ping signature invalid');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function verifyFinalClosureObject(envelope,{stateRoot=path.join(os.homedir(),'.deadbyte-mcp')}={}){
|
|
95
|
+
insist(envelope?.body?.schema==='deadbyte.r41-final-closure.v1','closure schema mismatch');
|
|
96
|
+
insist(envelope.body.version==='0.13.0','closure version mismatch');
|
|
97
|
+
insist(envelope.body.release_label==='R41 DETERMINISTIC MEMORY BASELINE','closure release label mismatch');
|
|
98
|
+
const keyInfo=publicKeyInfo(await readFile(path.join(stateRoot,'trust','ed25519-public.pem')));
|
|
99
|
+
const bodyBytes=Buffer.from(canonicalJson(envelope.body),'utf8');
|
|
100
|
+
insist(sha256(bodyBytes)===envelope.body_sha256,'closure body hash mismatch');
|
|
101
|
+
const {closure_sha256,...unsigned}=envelope;
|
|
102
|
+
insist(sha256(Buffer.from(canonicalJson(unsigned),'utf8'))===closure_sha256,'closure envelope hash mismatch');
|
|
103
|
+
insist(envelope.attestation?.algorithm==='ed25519'&&envelope.attestation?.domain==='DEADBYTE-R41-FINAL-CLOSURE-V1','closure attestation contract mismatch');
|
|
104
|
+
insist(envelope.attestation.key_id===keyInfo.key_id,'closure signer mismatch');
|
|
105
|
+
insist(cryptoVerify(null,Buffer.concat([CLOSURE_DOMAIN,bodyBytes]),keyInfo.key,Buffer.from(envelope.attestation.signature_base64,'base64')),'closure signature invalid');
|
|
106
|
+
|
|
107
|
+
const pointer=JSON.parse(await readFile(path.join(stateRoot,'active-release.json'),'utf8'));
|
|
108
|
+
insist(same(pointer,envelope.body.active_pointer),'active pointer drift');
|
|
109
|
+
insist(pointer.version==='0.13.0','active pointer version mismatch');
|
|
110
|
+
insist(isCandidateIdentity(pointer,pointer.manifest_sha256),'release id/content address mismatch');
|
|
111
|
+
const releaseFiles=await verifyTree(pointer.release_root,'MANIFEST.SHA256',pointer.manifest_sha256);
|
|
112
|
+
const generationFiles=await verifyTree(pointer.generation_root,'GENERATION.SHA256',pointer.generation_manifest_sha256);
|
|
113
|
+
insist(sha256(await readFile(path.join(stateRoot,'bin','DEADBYTE-MCP.ps1')))===pointer.launcher_sha256,'launcher hash mismatch');
|
|
114
|
+
|
|
115
|
+
const predecessor=envelope.body.predecessor;
|
|
116
|
+
insist(isR40PredecessorIdentity(predecessor),'closure predecessor is not exact sealed R40 predecessor');
|
|
117
|
+
const immutable=envelope.body.immutable_slot;
|
|
118
|
+
insist(immutable?.protected===true,'closure immutable-slot protection missing');
|
|
119
|
+
insist(samePath(immutable.release_root,pointer.release_root),'closure immutable release_root mismatch');
|
|
120
|
+
insist(!samePath(immutable.development_root,immutable.release_root),'closure development_root aliases immutable release_root');
|
|
121
|
+
|
|
122
|
+
const surfaces=envelope.body.surfaces;
|
|
123
|
+
insist(surfaces?.local_full?.status==='passed'&&surfaces.local_full.tool_count===R40_FULL_TOOL_COUNT&&surfaces.local_full.strict_output_schemas===true,'closure local full 80-tool proof invalid');
|
|
124
|
+
insist(HEX64.test(surfaces.local_full.catalog_sha256??''),'closure local full catalog hash missing');
|
|
125
|
+
insist(surfaces?.public_compact?.status==='passed'&&surfaces.public_compact.tool_count===R40_COMPACT_TOOL_COUNT&&surfaces.public_compact.capability_closure===true,'closure public compact capability proof invalid');
|
|
126
|
+
insist(surfaces.public_compact.coding_armed===false&&surfaces.public_compact.autonomous_armed===false&&surfaces.public_compact.desktop_armed===false,'closure compact authority is not DISARMED');
|
|
127
|
+
insist(surfaces.public_compact.desktop_observation_receipt_verified===true&&surfaces.public_compact.desktop_grounding_receipt_verified===true,'closure Desktop read-only proof invalid');
|
|
128
|
+
insist(HEX64.test(surfaces.public_compact.catalog_sha256??'')&&HEX64.test(surfaces.public_compact.ledger_sha256??''),'closure compact catalog/ledger hash missing');
|
|
129
|
+
|
|
130
|
+
const evidence=envelope.body.evidence;
|
|
131
|
+
insist(evidence&&evidence.parity&&evidence.activation&&evidence.rollback&&evidence.restore&&evidence.windows_gate,'closure evidence set incomplete');
|
|
132
|
+
for(const [name,item] of Object.entries(evidence)){
|
|
133
|
+
insist(item?.path&&HEX64.test(item.sha256??''),`${name} evidence identity malformed`);
|
|
134
|
+
insist(sha256(await readFile(item.path))===item.sha256,`${name} evidence hash mismatch`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const parity=JSON.parse(await readFile(evidence.parity.path,'utf8'));
|
|
138
|
+
insist(parity.schema==='deadbyte.r41-parity.v1'&&parity.status==='passed','R40 parity evidence invalid');
|
|
139
|
+
insist(parity.rdc_operation_count===0&&parity.execution_provider==='deadbyte_mcp','R40 parity execution provider mismatch');
|
|
140
|
+
insist(isCandidateIdentity(parity.candidate,pointer.manifest_sha256),'R40 parity candidate binding mismatch');
|
|
141
|
+
insist(isCandidateIdentity(parity.successor,pointer.manifest_sha256),'R40 parity successor binding mismatch');
|
|
142
|
+
insist(isR40PredecessorIdentity(parity.predecessor),'R40 parity predecessor binding mismatch');
|
|
143
|
+
insist(parity.local_full?.status==='passed'&&parity.local_full.tool_count===R40_FULL_TOOL_COUNT&&parity.local_full.strict_output_schemas===true,'R40 parity local full proof invalid');
|
|
144
|
+
insist(parity.local_full.catalog_sha256===surfaces.local_full.catalog_sha256,'R36 local full catalog drift between parity and closure');
|
|
145
|
+
insist(parity.public_compact?.status==='passed'&&parity.public_compact.tool_count===R40_COMPACT_TOOL_COUNT&&parity.public_compact.capability_closure===true&&parity.public_compact.gateway_count===6&&parity.public_compact.desktop_armed===false&&parity.public_compact.desktop_observation_receipt_verified===true&&parity.public_compact.desktop_grounding_receipt_verified===true,'R40 parity public compact/Desktop proof invalid');
|
|
146
|
+
insist(parity.desktop_guarded?.status==='passed'&&parity.desktop_guarded.native_injected===true&&parity.desktop_guarded.replay_performed===false&&parity.desktop_guarded.action_receipts_verified===3,'R40 parity guarded Desktop proof invalid');
|
|
147
|
+
insist(parity.deterministic_memory?.status==='passed'&&parity.deterministic_memory.goal_count>=1&&parity.deterministic_memory.snapshot_count>=1&&parity.deterministic_memory.index_count>=1,'R41 deterministic memory proof invalid');
|
|
148
|
+
insist(same(surfaces.deterministic_memory,parity.deterministic_memory),'R41 closure deterministic memory binding mismatch');
|
|
149
|
+
insist(parity.successor_disarmed?.status==='passed'&&parity.successor_disarmed.tool_count===R40_COMPACT_TOOL_COUNT&&parity.successor_disarmed.capability_closure===true&&parity.successor_disarmed.coding_armed===false&&parity.successor_disarmed.autonomous_armed===false&&parity.successor_disarmed.desktop_armed===false,'R40 parity successor disarmed proof invalid');
|
|
150
|
+
insist(parity.successor_disarmed.catalog_sha256===surfaces.public_compact.catalog_sha256,'R36 compact catalog drift between restore and closure');
|
|
151
|
+
insist(parity.successor_disarmed.ledger_sha256===surfaces.public_compact.ledger_sha256,'R36 capability ledger drift between restore and closure');
|
|
152
|
+
insist(parity.immutable_slot?.protected===true,'R40 parity immutable-slot proof missing');
|
|
153
|
+
insist(samePath(parity.immutable_slot.release_root,pointer.release_root),'R40 parity immutable release_root mismatch');
|
|
154
|
+
insist(samePath(parity.immutable_slot.development_root,immutable.development_root),'R40 parity/closure development_root mismatch');
|
|
155
|
+
insist(!samePath(parity.immutable_slot.development_root,pointer.release_root),'R36 mutable development_root aliases immutable release slot');
|
|
156
|
+
for(const key of REQUIRED_PARITY_KEYS) insist(parity.requirements?.[key]===true,`R40 parity requirement missing ${key}`);
|
|
157
|
+
|
|
158
|
+
const activation=JSON.parse(await readFile(evidence.activation.path,'utf8'));
|
|
159
|
+
const rollback=JSON.parse(await readFile(evidence.rollback.path,'utf8'));
|
|
160
|
+
const restore=JSON.parse(await readFile(evidence.restore.path,'utf8'));
|
|
161
|
+
verifyUpdateEnvelope(activation,keyInfo);verifyUpdateEnvelope(rollback,keyInfo);verifyUpdateEnvelope(restore,keyInfo);
|
|
162
|
+
insist(activation.body.schema==='deadbyte.r27-slot-update-receipt.v1'&&activation.body.rollback_performed===false,'R40 activation receipt invalid');
|
|
163
|
+
insist(activation.body.release_version==='0.13.0'&&activation.body.candidate_manifest_sha256===pointer.manifest_sha256,'R40 activation candidate identity invalid');
|
|
164
|
+
insist(isCandidateIdentity(activation.body.active_pointer,pointer.manifest_sha256),'R40 activation active pointer invalid');
|
|
165
|
+
insist(isR40PredecessorIdentity(activation.body.prior_pointer),'R41 activation predecessor is not exact R40 predecessor');
|
|
166
|
+
insist(samePath(activation.body.development_root,immutable.development_root),'R40 activation development_root mismatch');
|
|
167
|
+
insist(!samePath(activation.body.development_root,activation.body.active_pointer.release_root),'R40 activation development_root aliases release slot');
|
|
168
|
+
insist(activation.body.authority?.final?.desktop_armed===false,'R40 activation restored Desktop authority unexpectedly');
|
|
169
|
+
|
|
170
|
+
insist(rollback.body.schema==='deadbyte.r31-slot-rollback-receipt.v1'&&rollback.body.rollback_performed===true,'R40 rollback receipt invalid');
|
|
171
|
+
insist(isCandidateIdentity(rollback.body.from_pointer,pointer.manifest_sha256),'R40 rollback source is not exact candidate');
|
|
172
|
+
insist(isR40PredecessorIdentity(rollback.body.active_pointer),'R41 rollback target is not exact R40 predecessor');
|
|
173
|
+
insist(rollback.body.activation_receipt_sha256===activation.receipt_sha256,'R40 rollback not bound to activation receipt');
|
|
174
|
+
|
|
175
|
+
insist(restore.body.schema==='deadbyte.r27-slot-update-receipt.v1'&&restore.body.rollback_performed===false,'R40 restore receipt invalid');
|
|
176
|
+
insist(restore.body.release_version==='0.13.0'&&restore.body.candidate_manifest_sha256===pointer.manifest_sha256,'R40 restore candidate identity invalid');
|
|
177
|
+
insist(isR40PredecessorIdentity(restore.body.prior_pointer),'R41 restore predecessor is not exact R40 predecessor');
|
|
178
|
+
insist(isCandidateIdentity(restore.body.active_pointer,pointer.manifest_sha256)&&same(restore.body.active_pointer,pointer),'R40 restore/current pointer mismatch');
|
|
179
|
+
insist(samePath(restore.body.development_root,immutable.development_root),'R40 restore development_root mismatch');
|
|
180
|
+
insist(!samePath(restore.body.development_root,restore.body.active_pointer.release_root),'R40 restore development_root aliases release slot');
|
|
181
|
+
insist(restore.body.authority?.final?.desktop_armed===false,'R40 restore restored Desktop authority unexpectedly');
|
|
182
|
+
|
|
183
|
+
const windowsGate=JSON.parse(await readFile(evidence.windows_gate.path,'utf8'));
|
|
184
|
+
insist(windowsGate.schema==='deadbyte.r41-windows-gate.v1'&&windowsGate.status==='passed'&&windowsGate.exit_code===0,'R40 Windows gate evidence invalid');
|
|
185
|
+
insist(windowsGate.version==='0.13.0'&&windowsGate.manifest_sha256===pointer.manifest_sha256,'R40 Windows gate manifest/version binding mismatch');
|
|
186
|
+
insist(windowsGate.marker==='DEADBYTE V0.13.0 / R41 WINDOWS BATCH GATE: PASS','R40 Windows gate PASS marker mismatch');
|
|
187
|
+
|
|
188
|
+
const machine=envelope.body.machine;
|
|
189
|
+
insist(machine?.status?.release_id===pointer.release_id&&machine.status.release_manifest_sha256===pointer.manifest_sha256&&machine.status.generation_manifest_sha256===pointer.generation_manifest_sha256,'machine status binding mismatch');
|
|
190
|
+
verifyPing(machine.ping,machine.status,pointer);
|
|
191
|
+
insist(machine.ping.nonce===machine.nonce,'machine ping nonce binding mismatch');
|
|
192
|
+
|
|
193
|
+
const grantNames=['process-grant.json','coding-grant.json','autonomous-grant.json','desktop-grant.json','host-grant.json'];
|
|
194
|
+
insist(envelope.body.authority?.all_disarmed===true,'closure authority not disarmed');
|
|
195
|
+
for(const name of grantNames){
|
|
196
|
+
let exists=true;try{await lstat(path.join(stateRoot,'runtime',name));}catch(error){if(error?.code==='ENOENT') exists=false;else throw error;}
|
|
197
|
+
insist(!exists,`authority grant still present: ${name}`);
|
|
198
|
+
insist(envelope.body.authority.grants_absent?.[name]===true,`closure grant absence not recorded: ${name}`);
|
|
199
|
+
}
|
|
200
|
+
return {ok:true,status:'passed',release_id:pointer.release_id,manifest_sha256:pointer.manifest_sha256,
|
|
201
|
+
generation_manifest_sha256:pointer.generation_manifest_sha256,release_files:releaseFiles,generation_files:generationFiles,
|
|
202
|
+
machine_id:machine.status.machine_id,parity_sha256:evidence.parity.sha256,closure_sha256:envelope.closure_sha256,
|
|
203
|
+
full_tool_count:R40_FULL_TOOL_COUNT,compact_tool_count:surfaces.public_compact.tool_count};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const invoked=process.argv[1]&&path.resolve(process.argv[1])===fileURLToPath(import.meta.url);
|
|
207
|
+
if(invoked){
|
|
208
|
+
const file=process.argv[2];
|
|
209
|
+
if(!file) throw new Error('usage: node scripts/final-closure-verify-r41.mjs <closure.json>');
|
|
210
|
+
try{
|
|
211
|
+
const envelope=JSON.parse(await readFile(path.resolve(file),'utf8'));
|
|
212
|
+
console.log(JSON.stringify(await verifyFinalClosureObject(envelope),null,2));
|
|
213
|
+
}catch(error){console.error(error instanceof Error?error.stack:String(error));process.exitCode=1;}
|
|
214
|
+
}
|
|
215
|
+
|