deadbyte-mcp 0.14.0 → 0.15.1

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.
Files changed (157) hide show
  1. package/AGENTS.md +11 -18
  2. package/CONTEXT.md +3 -3
  3. package/MANIFEST.SHA256 +156 -70
  4. package/PROVENANCE.json +10 -0
  5. package/R43-PARENT.json +20 -0
  6. package/R44-DONORS.json +99 -0
  7. package/R44-PARENT.json +18 -0
  8. package/R45-PARENT.json +18 -0
  9. package/README.txt +19 -14
  10. package/RELEASE.json +37 -0
  11. package/SBOM.cdx.json +46 -0
  12. package/TEST-MATRIX.json +31 -0
  13. package/bin/deadbyte-hardware-observer-r45.exe +0 -0
  14. package/bin/deadbyte-hardware-observer-r45.obj +0 -0
  15. package/controller/README.TXT +5 -6
  16. package/controller/deadbyte-controller.ps1 +2 -2
  17. package/docs/ARCHITECTURE.md +8 -1
  18. package/docs/R44-ARCHITECTURE.md +37 -0
  19. package/native/deadbyte-hardware-observer.cpp +308 -0
  20. package/package.json +18 -8
  21. package/scripts/autonomous-tests.ps1 +2 -2
  22. package/scripts/build-hardware-r45.ps1 +71 -0
  23. package/scripts/deferred-slot-operation-r43.mjs +126 -0
  24. package/scripts/deferred-slot-operation-r44.mjs +126 -0
  25. package/scripts/deferred-slot-operation-r45.mjs +126 -0
  26. package/scripts/derive-r45-parent.mjs +24 -0
  27. package/scripts/derive-r45-release.mjs +72 -0
  28. package/scripts/derive-r45-tests.mjs +20 -0
  29. package/scripts/final-closure-r43.mjs +115 -0
  30. package/scripts/final-closure-r44.mjs +121 -0
  31. package/scripts/final-closure-r45.mjs +121 -0
  32. package/scripts/final-closure-verify-r43.mjs +213 -0
  33. package/scripts/final-closure-verify-r44.mjs +220 -0
  34. package/scripts/final-closure-verify-r45.mjs +220 -0
  35. package/scripts/finalize-r43.mjs +217 -0
  36. package/scripts/finalize-r44.mjs +217 -0
  37. package/scripts/finalize-r45.mjs +219 -0
  38. package/scripts/full-regression-r43.mjs +20 -0
  39. package/scripts/full-regression-r44.mjs +20 -0
  40. package/scripts/full-regression-r45.mjs +20 -0
  41. package/scripts/full-regression-summary-r45.mjs +14 -0
  42. package/scripts/gate-windows-r43.ps1 +36 -0
  43. package/scripts/gate-windows-r44.ps1 +36 -0
  44. package/scripts/gate-windows-r45.ps1 +44 -0
  45. package/scripts/init-host-policy.ps1 +39 -1
  46. package/scripts/inspect-active-release-r45.mjs +20 -0
  47. package/scripts/release-manifest.mjs +3 -1
  48. package/scripts/release-parity-r43.mjs +218 -0
  49. package/scripts/release-parity-r44.mjs +242 -0
  50. package/scripts/release-parity-r45.mjs +253 -0
  51. package/scripts/release-parity-tests-r43.ps1 +8 -0
  52. package/scripts/release-parity-tests-r44.ps1 +8 -0
  53. package/scripts/release-parity-tests-r45.ps1 +8 -0
  54. package/scripts/verify-r43-parent.mjs +126 -0
  55. package/scripts/verify-r44-parent.mjs +142 -0
  56. package/scripts/verify-r45-parent.mjs +142 -0
  57. package/scripts/windows-gate-evidence-r43.mjs +55 -0
  58. package/scripts/windows-gate-evidence-r44.mjs +55 -0
  59. package/scripts/windows-gate-evidence-r45.mjs +60 -0
  60. package/src/agent-backend-r44.mjs +254 -0
  61. package/src/autonomous-output-contracts.mjs +1 -1
  62. package/src/autonomous-policy.mjs +41 -4
  63. package/src/autonomous-runtime.mjs +37 -19
  64. package/src/autonomous-supervisor-host.mjs +12 -2
  65. package/src/capability-ledger.mjs +3 -1
  66. package/src/codex-app-server-r44.mjs +154 -0
  67. package/src/coding-plane.mjs +66 -19
  68. package/src/compact-gateway-mcp-tools.mjs +4 -2
  69. package/src/deadbyte-cli.mjs +17 -9
  70. package/src/doctor-r45.mjs +65 -0
  71. package/src/durable-job-r44.mjs +145 -0
  72. package/src/external-job-provider-r44.mjs +126 -0
  73. package/src/host-plane.mjs +156 -87
  74. package/src/job-supervisor-host-r44.mjs +112 -0
  75. package/src/machine-fs-smoke-client.mjs +1 -1
  76. package/src/machine-fs.mjs +21 -10
  77. package/src/mcp-host-smoke-client.mjs +1 -1
  78. package/src/mcp-server.mjs +84 -26
  79. package/src/mcp-smoke-client.mjs +1 -1
  80. package/src/native-diff-v2.mjs +12 -7
  81. package/src/native-diff.mjs +32 -9
  82. package/src/observation-mcp-tools.mjs +5 -1
  83. package/src/observation-output-contracts.mjs +8 -0
  84. package/src/observation-runtime.mjs +33 -2
  85. package/src/observation-smoke-client.mjs +7 -3
  86. package/src/operator-surface.mjs +2 -2
  87. package/src/output-contracts.mjs +27 -11
  88. package/src/process-policy.mjs +19 -0
  89. package/src/process-runtime.mjs +5 -2
  90. package/src/process-smoke-client.mjs +2 -2
  91. package/src/provider-circuit.mjs +8 -2
  92. package/src/r44-compact-disarmed-probe.mjs +74 -0
  93. package/src/r44-full-surface-probe.mjs +34 -0
  94. package/src/r45-compact-disarmed-probe.mjs +74 -0
  95. package/src/r45-full-surface-probe.mjs +34 -0
  96. package/src/release-generation.mjs +1 -0
  97. package/src/remote-device-r44.mjs +205 -0
  98. package/src/remote-mcp-autonomous-smoke-client.mjs +4 -4
  99. package/src/remote-mcp-r44-parity-client.mjs +203 -0
  100. package/src/remote-mcp-r45-parity-client.mjs +206 -0
  101. package/src/remote-mcp-smoke-client.mjs +7 -4
  102. package/src/runtime-update.mjs +100 -39
  103. package/src/skill-mcp-tools-r44.mjs +37 -0
  104. package/src/skill-plane-r44.mjs +203 -0
  105. package/src/tunnel-stdio-compat-smoke.mjs +1 -1
  106. package/src/version.mjs +1 -1
  107. package/test/agent-backend-r44.test.mjs +115 -0
  108. package/test/agent-runtime.test.mjs +4 -3
  109. package/test/autonomous-loop.test.mjs +121 -11
  110. package/test/autonomous-runtime.test.mjs +3 -2
  111. package/test/capability-ledger-r36.test.mjs +3 -3
  112. package/test/cli-entrypoint.test.mjs +4 -4
  113. package/test/codex-app-server-r44.test.mjs +115 -0
  114. package/test/codex-autonomous-r44.test.mjs +87 -0
  115. package/test/coding-plane.test.mjs +3 -2
  116. package/test/coding-runtime.test.mjs +36 -1
  117. package/test/compact-catalog-r36.test.mjs +3 -3
  118. package/test/compact-max-catalog-r40.test.mjs +4 -2
  119. package/test/compact-max-catalog-r44.test.mjs +97 -0
  120. package/test/compact-max-catalog-r45.test.mjs +99 -0
  121. package/test/contained.test.mjs +23 -11
  122. package/test/controller.test.mjs +5 -1
  123. package/test/core.test.mjs +1 -1
  124. package/test/durable-job-r44.test.mjs +75 -0
  125. package/test/external-job-provider-r44.test.mjs +46 -0
  126. package/test/full-max-catalog-r40.test.mjs +5 -3
  127. package/test/full-max-catalog-r44.test.mjs +91 -0
  128. package/test/full-max-catalog-r45.test.mjs +91 -0
  129. package/test/hardware-observation-r45.test.mjs +44 -0
  130. package/test/host-inline-r45.test.mjs +67 -0
  131. package/test/host-plane.test.mjs +15 -1
  132. package/test/machine-mcp-integration.test.mjs +1 -0
  133. package/test/native-diff.test.mjs +28 -0
  134. package/test/observation-mcp-tools.test.mjs +4 -3
  135. package/test/output-schema.test.mjs +3 -2
  136. package/test/package-boundary.test.mjs +1 -1
  137. package/test/process-policy.test.mjs +22 -1
  138. package/test/production-docs.test.mjs +3 -3
  139. package/test/prompts-resources.test.mjs +1 -1
  140. package/test/r33-closeout-regression.test.mjs +20 -36
  141. package/test/r33-finalization.test.mjs +7 -7
  142. package/test/r43-finalization.test.mjs +31 -0
  143. package/test/r43-finalizer.test.mjs +34 -0
  144. package/test/r43-parent.test.mjs +29 -0
  145. package/test/r44-finalization.test.mjs +58 -0
  146. package/test/r44-finalizer.test.mjs +48 -0
  147. package/test/r44-parent.test.mjs +25 -0
  148. package/test/r45-autonomous-quick-test.test.mjs +10 -0
  149. package/test/r45-finalization.test.mjs +84 -0
  150. package/test/release-generation.test.mjs +1 -0
  151. package/test/release-version.test.mjs +65 -20
  152. package/test/remote-device-r44.test.mjs +104 -0
  153. package/test/runtime-host-bootstrap-r45.test.mjs +46 -0
  154. package/test/runtime-self-update.test.mjs +42 -0
  155. package/test/skill-mcp-r44.test.mjs +38 -0
  156. package/test/skill-plane-r44.test.mjs +93 -0
  157. package/test/standing-grants.test.mjs +5 -1
@@ -0,0 +1,220 @@
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-R45-FINAL-CLOSURE-V1\0','utf8');
10
+ const PING_DOMAIN=Buffer.from('DEADBYTE-MACHINE-PING-V1\0','utf8');
11
+ const R45_PREDECESSOR_RELEASE_ID='v0.15.0-c15fa41719be61b3';
12
+ const R45_PREDECESSOR_MANIFEST='c15fa41719be61b3186e49b2367a5f4c057365cfb465102dbefb7d7355f45483';
13
+ const R45_FULL_TOOL_COUNT=82;
14
+ const R45_COMPACT_TOOL_COUNT=43;
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','skill_integrity','agent_backend_persistence','codex_protocol_contract','remote_device_identity','durable_job_supervisor','real_external_supervisor_smoke'];
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.15.1'&&value?.manifest_sha256===manifest&&value?.release_id===`v0.15.1-${manifest.slice(0,16)}`;
25
+ }
26
+ function isR44PredecessorIdentity(value){
27
+ return value?.version==='0.15.0'&&value?.manifest_sha256===R45_PREDECESSOR_MANIFEST&&value?.release_id===R45_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.r45-final-closure.v1','closure schema mismatch');
96
+ insist(envelope.body.version==='0.15.1','closure version mismatch');
97
+ insist(envelope.body.release_label==='R45 MACHINE FREEDOM FINAL 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-R45-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.15.1','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(isR44PredecessorIdentity(predecessor),'closure predecessor is not exact sealed R44 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===R45_FULL_TOOL_COUNT&&surfaces.local_full.strict_output_schemas===true,'closure local full 82-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===R45_COMPACT_TOOL_COUNT&&surfaces.public_compact.capability_closure===true&&surfaces.public_compact.skill_catalog_verified===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.r45-parity.v1'&&parity.status==='passed','R45 parity evidence invalid');
139
+ insist(parity.rdc_operation_count===0&&parity.execution_provider==='deadbyte_mcp','R45 parity execution provider mismatch');
140
+ insist(isCandidateIdentity(parity.candidate,pointer.manifest_sha256),'R45 parity candidate binding mismatch');
141
+ insist(isCandidateIdentity(parity.successor,pointer.manifest_sha256),'R45 parity successor binding mismatch');
142
+ insist(isR44PredecessorIdentity(parity.predecessor),'R45 parity predecessor binding mismatch');
143
+ insist(parity.local_full?.status==='passed'&&parity.local_full.tool_count===R45_FULL_TOOL_COUNT&&parity.local_full.strict_output_schemas===true,'R45 parity local full proof invalid');
144
+ insist(parity.local_full.catalog_sha256===surfaces.local_full.catalog_sha256,'R45 local full catalog drift between parity and closure');
145
+ insist(parity.public_compact?.status==='passed'&&parity.public_compact.tool_count===R45_COMPACT_TOOL_COUNT&&parity.public_compact.capability_closure===true&&parity.public_compact.skill_catalog_verified===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,'R45 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,'R45 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===R45_COMPACT_TOOL_COUNT&&parity.successor_disarmed.capability_closure===true&&parity.successor_disarmed.skill_catalog_verified===true&&parity.successor_disarmed.coding_armed===false&&parity.successor_disarmed.autonomous_armed===false&&parity.successor_disarmed.desktop_armed===false,'R45 parity successor disarmed proof invalid');
150
+ insist(parity.successor_disarmed.catalog_sha256===surfaces.public_compact.catalog_sha256,'R45 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,'R45 parity immutable-slot proof missing');
153
+ insist(samePath(parity.immutable_slot.release_root,pointer.release_root),'R45 parity immutable release_root mismatch');
154
+ insist(samePath(parity.immutable_slot.development_root,immutable.development_root),'R45 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,`R45 parity requirement missing ${key}`);
157
+ const activation=JSON.parse(await readFile(evidence.activation.path,'utf8'));
158
+ const rollback=JSON.parse(await readFile(evidence.rollback.path,'utf8'));
159
+ const restore=JSON.parse(await readFile(evidence.restore.path,'utf8'));
160
+ verifyUpdateEnvelope(activation,keyInfo);verifyUpdateEnvelope(rollback,keyInfo);verifyUpdateEnvelope(restore,keyInfo);
161
+ insist(activation.body.schema==='deadbyte.r27-slot-update-receipt.v1'&&activation.body.rollback_performed===false,'R45 activation receipt invalid');
162
+ insist(activation.body.release_version==='0.15.1'&&activation.body.candidate_manifest_sha256===pointer.manifest_sha256,'R45 activation candidate identity invalid');
163
+ insist(isCandidateIdentity(activation.body.active_pointer,pointer.manifest_sha256),'R45 activation active pointer invalid');
164
+ insist(isR44PredecessorIdentity(activation.body.prior_pointer),'R45 activation predecessor is not exact R44 predecessor');
165
+ insist(samePath(activation.body.development_root,immutable.development_root),'R45 activation development_root mismatch');
166
+ insist(!samePath(activation.body.development_root,activation.body.active_pointer.release_root),'R45 activation development_root aliases release slot');
167
+ insist(activation.body.authority?.final?.desktop_armed===false,'R45 activation restored Desktop authority unexpectedly');
168
+
169
+ insist(rollback.body.schema==='deadbyte.r31-slot-rollback-receipt.v1'&&rollback.body.rollback_performed===true,'R45 rollback receipt invalid');
170
+ insist(isCandidateIdentity(rollback.body.from_pointer,pointer.manifest_sha256),'R45 rollback source is not exact candidate');
171
+ insist(isR44PredecessorIdentity(rollback.body.active_pointer),'R45 rollback target is not exact R44 predecessor');
172
+ insist(rollback.body.activation_receipt_sha256===activation.receipt_sha256,'R45 rollback not bound to activation receipt');
173
+
174
+ insist(restore.body.schema==='deadbyte.r27-slot-update-receipt.v1'&&restore.body.rollback_performed===false,'R45 restore receipt invalid');
175
+ insist(restore.body.release_version==='0.15.1'&&restore.body.candidate_manifest_sha256===pointer.manifest_sha256,'R45 restore candidate identity invalid');
176
+ insist(isR44PredecessorIdentity(restore.body.prior_pointer),'R45 restore predecessor is not exact R44 predecessor');
177
+ insist(isCandidateIdentity(restore.body.active_pointer,pointer.manifest_sha256)&&same(restore.body.active_pointer,pointer),'R45 restore/current pointer mismatch');
178
+ insist(samePath(restore.body.development_root,immutable.development_root),'R45 restore development_root mismatch');
179
+ insist(!samePath(restore.body.development_root,restore.body.active_pointer.release_root),'R45 restore development_root aliases release slot');
180
+ insist(restore.body.authority?.final?.desktop_armed===false,'R45 restore restored Desktop authority unexpectedly');
181
+
182
+ const windowsGate=JSON.parse(await readFile(evidence.windows_gate.path,'utf8'));
183
+ insist(windowsGate.schema==='deadbyte.r45-windows-gate.v1'&&windowsGate.status==='passed'&&windowsGate.exit_code===0,'R45 Windows gate evidence invalid');
184
+ insist(windowsGate.version==='0.15.1'&&windowsGate.manifest_sha256===pointer.manifest_sha256,'R45 Windows gate manifest/version binding mismatch');
185
+ insist(windowsGate.marker==='DEADBYTE V0.15.1 / R45 MACHINE FREEDOM WINDOWS BATCH GATE: PASS','R45 Windows gate PASS marker mismatch');
186
+
187
+ const featureContract=surfaces.feature_contract;
188
+ insist(featureContract?.schema==='deadbyte.r45-windows-gate.v1'&&featureContract.manifest_sha256===pointer.manifest_sha256,'closure feature contract invalid');
189
+ insist(parity.feature_gate_sha256===evidence.windows_gate.sha256,'parity feature gate hash mismatch');
190
+ for(const key of ['skill_integrity','agent_backend_persistence','codex_protocol_contract','remote_device_identity','durable_job_supervisor','real_external_supervisor_smoke','full_regression_required','host_inline_native','native_hardware_observation','doctor_release_truth']) {
191
+ insist(windowsGate.features?.[key]===true&&featureContract.features?.[key]===true,`R45 feature proof missing ${key}`);
192
+ }
193
+
194
+ const machine=envelope.body.machine;
195
+ 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');
196
+ verifyPing(machine.ping,machine.status,pointer);
197
+ insist(machine.ping.nonce===machine.nonce,'machine ping nonce binding mismatch');
198
+
199
+ const grantNames=['process-grant.json','coding-grant.json','autonomous-grant.json','desktop-grant.json','host-grant.json'];
200
+ insist(envelope.body.authority?.all_disarmed===true,'closure authority not disarmed');
201
+ for(const name of grantNames){
202
+ let exists=true;try{await lstat(path.join(stateRoot,'runtime',name));}catch(error){if(error?.code==='ENOENT') exists=false;else throw error;}
203
+ insist(!exists,`authority grant still present: ${name}`);
204
+ insist(envelope.body.authority.grants_absent?.[name]===true,`closure grant absence not recorded: ${name}`);
205
+ }
206
+ return {ok:true,status:'passed',release_id:pointer.release_id,manifest_sha256:pointer.manifest_sha256,
207
+ generation_manifest_sha256:pointer.generation_manifest_sha256,release_files:releaseFiles,generation_files:generationFiles,
208
+ machine_id:machine.status.machine_id,parity_sha256:evidence.parity.sha256,closure_sha256:envelope.closure_sha256,
209
+ full_tool_count:R45_FULL_TOOL_COUNT,compact_tool_count:surfaces.public_compact.tool_count};
210
+ }
211
+
212
+ const invoked=process.argv[1]&&path.resolve(process.argv[1])===fileURLToPath(import.meta.url);
213
+ if(invoked){
214
+ const file=process.argv[2];
215
+ if(!file) throw new Error('usage: node scripts/final-closure-verify-r45.mjs <closure.json>');
216
+ try{
217
+ const envelope=JSON.parse(await readFile(path.resolve(file),'utf8'));
218
+ console.log(JSON.stringify(await verifyFinalClosureObject(envelope),null,2));
219
+ }catch(error){console.error(error instanceof Error?error.stack:String(error));process.exitCode=1;}
220
+ }
@@ -0,0 +1,217 @@
1
+ import { createHash, randomBytes } from 'node:crypto';
2
+ import { spawn, spawnSync } from 'node:child_process';
3
+ import { lstat, mkdir, readFile, realpath, rename, 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, parseControllerStatus, runSlotUpdateCli } from '../src/runtime-update.mjs';
9
+ import { verifyR43Parent } from './verify-r43-parent.mjs';
10
+ import { runReleaseParity } from './release-parity-r43.mjs';
11
+ import { writeFinalClosure } from './final-closure-r43.mjs';
12
+ import { verifyFinalClosureObject } from './final-closure-verify-r43.mjs';
13
+
14
+ const HEX64=/^[0-9a-f]{64}$/;
15
+ const EXPECTED_VERSION='0.14.1';
16
+ const PARENT_RELEASE_ID='v0.14.0-08cd8f3b98c90e0e';
17
+ const PARENT_MANIFEST='08cd8f3b98c90e0e250cf506ff396515065ff5457909f850b75b0b6e8ecc2dd1';
18
+ const PARENT_ACTIVATION_RECEIPT='074140ad8b94501e0a095a7fa132dc5d6e2c57102c9eeaaa2ac9e4ea93b9b187';
19
+ const here=path.dirname(fileURLToPath(import.meta.url));
20
+ const packageRoot=path.resolve(here,'..');
21
+ const stateRoot=path.resolve(process.env.DEADBYTE_STATE_ROOT||path.join(os.homedir(),'.deadbyte-mcp'));
22
+ const evidenceRoot=path.join(stateRoot,'evidence','release','r43-finalization');
23
+ const launcher=path.join(stateRoot,'bin','DEADBYTE-MCP.ps1');
24
+ const ps=path.join(process.env.SystemRoot||'C:\\Windows','System32','WindowsPowerShell','v1.0','powershell.exe');
25
+ const sha256=bytes=>createHash('sha256').update(bytes).digest('hex');
26
+ const sleep=ms=>new Promise(resolve=>setTimeout(resolve,ms));
27
+ const insist=(ok,message)=>{if(!ok)throw new Error(message);};
28
+
29
+ async function atomicJson(file,value){
30
+ await mkdir(path.dirname(file),{recursive:true});
31
+ const bytes=Buffer.from(`${JSON.stringify(value,null,2)}\n`,'utf8');
32
+ const temp=`${file}.${process.pid}.${randomBytes(4).toString('hex')}.tmp`;
33
+ await writeFile(temp,bytes,{flag:'wx'});
34
+ await rename(temp,file);
35
+ return {path:file,sha256:sha256(bytes)};
36
+ }
37
+ async function activePointer(){
38
+ return parseActivePointer(await readFile(path.join(stateRoot,'active-release.json'),'utf8'));
39
+ }
40
+ async function bridgeArgs(){
41
+ const pointer=await activePointer();
42
+ const config=await loadPowerShellDataFile(pointer.config_path);
43
+ const raw=config?.Bridge?.WorkingDirectory;
44
+ insist(typeof raw==='string'&&path.isAbsolute(raw),'active Bridge.WorkingDirectory must be absolute');
45
+ const root=await realpath(path.resolve(raw));
46
+ const pkg=JSON.parse(await readFile(path.join(root,'package.json'),'utf8'));
47
+ insist(pkg?.name==='deadbyte-chatgpt-bridge','active Bridge package identity mismatch');
48
+ const script=path.join(root,'src','bridge.mjs');
49
+ return ['--bridge-root',root,'--bridge-script-sha256',sha256(await readFile(script))];
50
+ }
51
+ async function activationArgs(manifestSha256){
52
+ insist(HEX64.test(manifestSha256??''),'R43 finalizer manifest must be lowercase SHA-256');
53
+ const processPolicy=path.join(packageRoot,'controller','deadbyte-process-policy.json');
54
+ const desktopPolicy=path.join(packageRoot,'controller','deadbyte-desktop-policy.json');
55
+ const semantic=path.join(packageRoot,'controller','deadbyte-semantic-lsp-config.json');
56
+ return [
57
+ '--stage',packageRoot,'--development-root',packageRoot,'--expected-version',EXPECTED_VERSION,
58
+ '--expected-manifest',manifestSha256,
59
+ '--process-policy',processPolicy,'--process-policy-sha256',sha256(await readFile(processPolicy)),
60
+ '--desktop-policy',desktopPolicy,'--desktop-policy-sha256',sha256(await readFile(desktopPolicy)),
61
+ '--semantic-lsp-config',semantic,'--semantic-lsp-config-sha256',sha256(await readFile(semantic)),
62
+ '--enable-machine-fs','--enable-observation','--enable-desktop','--enable-autonomous-supervisor',
63
+ '--restore-standing-grants',
64
+ ...await bridgeArgs()
65
+ ];
66
+ }
67
+ export function validateFinalizerAuthorityStatus(status){
68
+ insist(status?.process_armed===true,'R43 finalizer requires Process standing grant');
69
+ insist(status?.coding_armed===true,'R43 finalizer requires Coding standing grant');
70
+ insist(status?.autonomous_armed===true,'R43 finalizer requires Autonomous standing grant');
71
+ insist(status?.desktop_armed===false,'R43 finalizer requires Desktop DISARMED');
72
+ insist(status?.host_armed===false,'R43 finalizer requires Host DISARMED');
73
+ return true;
74
+ }
75
+ function currentAuthorityStatus(){
76
+ const result=spawnSync(ps,['-NoLogo','-NoProfile','-ExecutionPolicy','Bypass','-File',launcher,'status'],
77
+ {encoding:'utf8',windowsHide:true,timeout:20000});
78
+ if(result.error) throw result.error;
79
+ if(result.status!==0) throw new Error(`R43 finalizer controller status failed: ${result.stderr||result.stdout}`);
80
+ return parseControllerStatus(result.stdout??'');
81
+ }
82
+ export function validateWindowsGateEvidence(value,manifestSha256,parent){
83
+ insist(value?.schema==='deadbyte.r43-windows-gate.v1'&&value.status==='passed'&&value.exit_code===0,'R43 Windows gate evidence invalid');
84
+ insist(value.version===EXPECTED_VERSION&&value.manifest_sha256===manifestSha256,'R43 Windows gate candidate mismatch');
85
+ insist(value.marker==='DEADBYTE V0.14.1 / R43 AUTHORITY HARDENING WINDOWS BATCH GATE: PASS','R43 Windows gate marker mismatch');
86
+ insist(value.parent?.release_id===parent.parent_release_id&&value.parent?.manifest_sha256===parent.parent_manifest_sha256,'R43 Windows gate parent mismatch');
87
+ insist(value.parent?.generation_manifest_sha256===parent.parent_generation_manifest_sha256,'R43 Windows gate parent generation mismatch');
88
+ insist(value.parent?.activation_receipt_sha256===PARENT_ACTIVATION_RECEIPT,'R43 Windows gate parent activation mismatch');
89
+ insist(value.hardening?.authority_toctou===true&&value.hardening?.absolute_execution_deadline===true&&
90
+ value.hardening?.pre_spawn_authority_recheck===true&&value.hardening?.full_regression_required===true&&
91
+ value.hardening?.model_path_changed===false,'R43 Windows gate hardening contract mismatch');
92
+ return true;
93
+ }
94
+ function disarmFailClosed(){
95
+ const results=[];
96
+ for(const command of ['disarmdesktop','disarmautonomous','disarmcoding','disarmprocess','disarmhost']){
97
+ const result=spawnSync(ps,['-NoLogo','-NoProfile','-ExecutionPolicy','Bypass','-File',launcher,command],
98
+ {encoding:'utf8',windowsHide:true,timeout:20000});
99
+ results.push({command,status:result.status,signal:result.signal??null});
100
+ }
101
+ return results;
102
+ }
103
+ async function mirrorRoot(){
104
+ const pointer=await activePointer();
105
+ const policy=JSON.parse(await readFile(path.join(pointer.generation_root,'coding-policy.json'),'utf8'));
106
+ const raw=policy?.roots?.parity_scratch?.path??policy?.roots?.parity_scratch?.real_path;
107
+ if(typeof raw!=='string'||!path.isAbsolute(raw)) throw new Error('active generation parity_scratch root unavailable');
108
+ const stat=await lstat(raw);
109
+ if(!stat.isDirectory()||stat.isSymbolicLink()) throw new Error('parity_scratch root must be a real directory');
110
+ return raw;
111
+ }
112
+ async function writeMirror(manifestSha256,value){
113
+ const root=await mirrorRoot();
114
+ const file=path.join(root,`r43-final-${manifestSha256.slice(0,16)}.json`);
115
+ return atomicJson(file,value);
116
+ }
117
+ async function verifyInputs(manifestSha256){
118
+ insist(HEX64.test(manifestSha256??''),'R43 finalizer manifest invalid');
119
+ const manifestBytes=await readFile(path.join(packageRoot,'MANIFEST.SHA256'));
120
+ insist(sha256(manifestBytes)===manifestSha256,'R43 finalizer manifest drift');
121
+ const pkg=JSON.parse(await readFile(path.join(packageRoot,'package.json'),'utf8'));
122
+ insist(pkg?.name==='deadbyte-mcp'&&pkg?.version===EXPECTED_VERSION,'R43 finalizer package identity mismatch');
123
+ const parent=await verifyR43Parent(path.join(packageRoot,'R43-PARENT.json'));
124
+ const authorityStatus=currentAuthorityStatus();
125
+ validateFinalizerAuthorityStatus(authorityStatus);
126
+ const before=await activePointer();
127
+ insist(before.release_id===PARENT_RELEASE_ID&&before.manifest_sha256===PARENT_MANIFEST,'R43 finalizer must start from exact sealed R42 parent');
128
+ const windowsGatePath=path.join(stateRoot,'evidence','release',`r43-windows-gate-${manifestSha256.slice(0,16)}.json`);
129
+ const windowsGateBytes=await readFile(windowsGatePath);
130
+ const windowsGate=JSON.parse(windowsGateBytes.toString('utf8').replace(/^\uFEFF/,''));
131
+ validateWindowsGateEvidence(windowsGate,manifestSha256,parent);
132
+ return {parent,before,authorityStatus,windowsGatePath,windowsGateFileSha256:sha256(windowsGateBytes)};
133
+ }
134
+ async function runWorker(manifestSha256,operationId){
135
+ const statePath=path.join(evidenceRoot,`${operationId}.json`);
136
+ let activation=null;
137
+ let parity=null;
138
+ try{
139
+ await atomicJson(statePath,{schema:'deadbyte.r43-finalization-state.v1',operation_id:operationId,status:'running',
140
+ manifest_sha256:manifestSha256,started_at_utc:new Date().toISOString()});
141
+ const inputs=await verifyInputs(manifestSha256);
142
+ activation=await runSlotUpdateCli(await activationArgs(manifestSha256),{stateRoot});
143
+ insist(activation?.pointer?.version===EXPECTED_VERSION&&activation.pointer.manifest_sha256===manifestSha256,'R43 activation result mismatch');
144
+ insist(activation?.final_authority?.process_armed===true&&activation?.final_authority?.coding_armed===true&&activation?.final_authority?.autonomous_armed===true,
145
+ 'R43 activation must restore prior Process+Coding+Autonomous standing grants for detached parity');
146
+ insist(activation?.final_authority?.desktop_armed===false&&activation?.final_authority?.host_armed===false,
147
+ 'R43 activation must keep Desktop+Host disarmed');
148
+
149
+ parity=await runReleaseParity(activation.receipt_path);
150
+ insist(parity?.evidence?.status==='passed'&&parity.evidence?.candidate?.manifest_sha256===manifestSha256,'R43 parity result mismatch');
151
+
152
+ const closure=await writeFinalClosure({parityPath:parity.evidence_path,activationPath:activation.receipt_path,
153
+ windowsGatePath:inputs.windowsGatePath});
154
+ const envelope=JSON.parse(await readFile(closure.path,'utf8'));
155
+ const verified=await verifyFinalClosureObject(envelope,{stateRoot});
156
+ insist(verified?.ok===true&&verified.status==='passed'&&verified.manifest_sha256===manifestSha256,'R43 independent final closure verification failed');
157
+
158
+ const pointer=await activePointer();
159
+ const result={schema:'deadbyte.r43-finalization-result.v1',status:'passed',verified:true,
160
+ completed_at_utc:new Date().toISOString(),release_id:pointer.release_id,version:pointer.version,
161
+ manifest_sha256:pointer.manifest_sha256,generation_manifest_sha256:pointer.generation_manifest_sha256,
162
+ activation_receipt_sha256:activation.receipt_sha256,
163
+ parity_sha256:parity.evidence_sha256,windows_gate_sha256:inputs.windowsGateFileSha256,
164
+ closure_file_sha256:closure.sha256,closure_sha256:closure.closure_sha256,
165
+ full_tool_count:verified.full_tool_count,compact_tool_count:verified.compact_tool_count,
166
+ parent_release_id:inputs.parent.parent_release_id,parent_manifest_sha256:inputs.parent.parent_manifest_sha256};
167
+ const mirror=await writeMirror(manifestSha256,result);
168
+ await atomicJson(statePath,{...result,operation_id:operationId,mirror_path:mirror.path,mirror_sha256:mirror.sha256,
169
+ activation_receipt_path:activation.receipt_path,parity_path:parity.evidence_path,closure_path:closure.path});
170
+ return result;
171
+ }catch(error){
172
+ let rollback=null;
173
+ try{
174
+ if(activation?.receipt_path){
175
+ const pointer=await activePointer().catch(()=>null);
176
+ if(pointer?.version===EXPECTED_VERSION&&pointer?.manifest_sha256===manifestSha256){
177
+ rollback=await runSlotUpdateCli(['--rollback-receipt',activation.receipt_path],{stateRoot});
178
+ }
179
+ }
180
+ }catch(rollbackError){rollback={error:String(rollbackError?.message??rollbackError)};}
181
+ const disarm=disarmFailClosed();
182
+ const failed={schema:'deadbyte.r43-finalization-result.v1',status:'failed',verified:false,
183
+ completed_at_utc:new Date().toISOString(),manifest_sha256:manifestSha256,
184
+ error:String(error?.message??error),rollback:rollback?{ok:rollback?.ok===true,error:rollback?.error??null}:null,disarm};
185
+ await atomicJson(statePath,{...failed,operation_id:operationId}).catch(()=>{});
186
+ await writeMirror(manifestSha256,failed).catch(()=>{});
187
+ throw error;
188
+ }
189
+ }
190
+ export async function scheduleFinalization(manifestSha256){
191
+ insist(HEX64.test(manifestSha256??''),'R43 finalizer manifest invalid');
192
+ const operationId=`r43-${manifestSha256.slice(0,16)}-${randomBytes(8).toString('hex')}`;
193
+ const statePath=path.join(evidenceRoot,`${operationId}.json`);
194
+ await atomicJson(statePath,{schema:'deadbyte.r43-finalization-state.v1',operation_id:operationId,status:'scheduled',
195
+ manifest_sha256:manifestSha256,scheduled_at_utc:new Date().toISOString()});
196
+ const child=spawn(process.execPath,[fileURLToPath(import.meta.url),manifestSha256,'--worker',operationId],{
197
+ cwd:packageRoot,detached:true,stdio:'ignore',windowsHide:true,env:{...process.env,DEADBYTE_STATE_ROOT:stateRoot}
198
+ });
199
+ child.unref();
200
+ return {status:'scheduled',operation_id:operationId,state_path:statePath,manifest_sha256:manifestSha256,
201
+ execution_provider:'deadbyte_mcp',rdc_operation_count:0};
202
+ }
203
+
204
+ const invoked=process.argv[1]&&path.resolve(process.argv[1])===fileURLToPath(import.meta.url);
205
+ if(invoked){
206
+ const [manifestSha256,flag,operationId]=process.argv.slice(2);
207
+ try{
208
+ if(flag==='--worker'){
209
+ insist(/^r43-[0-9a-f]{16}-[0-9a-f]{16}$/.test(operationId??''),'R43 finalizer worker operation id invalid');
210
+ await sleep(4000);
211
+ await runWorker(manifestSha256,operationId);
212
+ }else{
213
+ insist(flag===undefined&&operationId===undefined,'usage: node scripts/finalize-r43.mjs <manifest_sha256>');
214
+ console.log(JSON.stringify(await scheduleFinalization(manifestSha256)));
215
+ }
216
+ }catch(error){console.error(error instanceof Error?error.stack:String(error));process.exitCode=1;}
217
+ }