deadbyte-mcp 0.15.33 → 0.15.35

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 (72) hide show
  1. package/MANIFEST.SHA256 +71 -22
  2. package/PROVENANCE.json +57 -28
  3. package/README.txt +22 -14
  4. package/RELEASE.json +41 -29
  5. package/SBOM.cdx.json +25 -3
  6. package/TEST-MATRIX.json +135 -43
  7. package/bridge/package.json +11 -0
  8. package/bridge/src/bridge.mjs +412 -0
  9. package/bridge/src/node-http-adapter.mjs +56 -0
  10. package/bridge/src/public-tool-definitions.mjs +14 -0
  11. package/bridge/src/r40-governor.mjs +160 -0
  12. package/controller/deadbyte-controller.ps1 +84 -8
  13. package/controller/deadbyte-process-policy.json +4 -4
  14. package/package.json +6 -3
  15. package/scripts/bridge-benchmark-r58.mjs +67 -0
  16. package/scripts/deploy-r48.mjs +2 -3
  17. package/scripts/gate-windows-r57.ps1 +27 -0
  18. package/scripts/gate-windows-r58.ps1 +33 -0
  19. package/scripts/owner-probe-r58.mjs +31 -0
  20. package/scripts/performance-r58.mjs +57 -0
  21. package/scripts/public-baseline-r58.mjs +72 -0
  22. package/scripts/public-surface-r58.mjs +84 -0
  23. package/scripts/r58-cross-plane.ps1 +6 -0
  24. package/scripts/r58-focused.ps1 +6 -0
  25. package/scripts/windows-gate-evidence-r57.mjs +81 -0
  26. package/scripts/windows-gate-evidence-r58.mjs +93 -0
  27. package/src/deadbyte-cli.mjs +40 -12
  28. package/src/doctor-foreground-r58.mjs +44 -0
  29. package/src/doctor-installation-r58.mjs +63 -0
  30. package/src/doctor-r45.mjs +21 -4
  31. package/src/doctor-runtime-r58.mjs +82 -0
  32. package/src/doctor-transactions-r58.mjs +40 -0
  33. package/src/foreground-process-identity.mjs +27 -0
  34. package/src/foreground-session-lock.mjs +20 -0
  35. package/src/foreground-session-lock.ps1 +15 -0
  36. package/src/release-generation.mjs +1 -0
  37. package/src/release-slot.mjs +2 -1
  38. package/src/remote-session-guardian.mjs +8 -1
  39. package/src/runtime-update.mjs +117 -3
  40. package/src/version.mjs +1 -1
  41. package/test/controller-r211.test.mjs +4 -1
  42. package/test/controller.test.mjs +2 -1
  43. package/test/helpers/r58-doctor-fixture.mjs +26 -0
  44. package/test/r49-windows-gate.test.mjs +14 -10
  45. package/test/r56-release-contract.test.mjs +5 -3
  46. package/test/r57-core-startup-race.test.mjs +85 -0
  47. package/test/r57-release-contract.test.mjs +67 -0
  48. package/test/r58-bridge-dependency-binding.test.mjs +62 -0
  49. package/test/r58-bundled-bridge.test.mjs +22 -0
  50. package/test/r58-cleanup-retention.test.mjs +45 -0
  51. package/test/r58-completed-update-receipt.test.mjs +76 -0
  52. package/test/r58-concurrent-recovery.test.mjs +54 -0
  53. package/test/r58-controller-core-observation.test.mjs +36 -0
  54. package/test/r58-controller-json.test.mjs +48 -0
  55. package/test/r58-controller-live-local.test.mjs +85 -0
  56. package/test/r58-controller-readonly.test.mjs +23 -0
  57. package/test/r58-controller-state-coherence.test.mjs +45 -0
  58. package/test/r58-doctor-cli.test.mjs +20 -0
  59. package/test/r58-doctor-foreground.test.mjs +50 -0
  60. package/test/r58-doctor-installation.test.mjs +55 -0
  61. package/test/r58-doctor-pointer.test.mjs +41 -0
  62. package/test/r58-doctor-runtime.test.mjs +45 -0
  63. package/test/r58-doctor-transactions.test.mjs +21 -0
  64. package/test/r58-guardian-channel.test.mjs +26 -0
  65. package/test/r58-launcher-shell.test.mjs +28 -0
  66. package/test/r58-owner-identity.test.mjs +20 -0
  67. package/test/r58-release-contract.test.mjs +49 -0
  68. package/test/r58-session-lock.test.mjs +26 -0
  69. package/test/r58-stale-owner.test.mjs +71 -0
  70. package/test/r58-windows-gate.test.mjs +31 -0
  71. package/test/release-generation.test.mjs +4 -1
  72. package/test/remote-session-cli.test.mjs +55 -2
package/TEST-MATRIX.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema": "deadbyte.test-matrix.v1",
3
- "version": "0.15.33",
4
- "train": "R56",
3
+ "version": "0.15.35",
4
+ "train": "R58",
5
5
  "primary_platform": "win32-x64",
6
6
  "reference": {
7
7
  "package": "@wonderwhy-er/desktop-commander",
@@ -11,93 +11,170 @@
11
11
  },
12
12
  "required": [
13
13
  {
14
- "id": "r56-focused",
15
- "command": "npm run r56:focused:test",
16
- "expected": "PASS signed rollback handoff launcher restore, ordering, activation recovery regressions, runtime update/slot contracts"
14
+ "id": "r58-focused",
15
+ "command": "npm run r58:focused:test",
16
+ "expected": "PASS frontend/backend/bridge consolidation and inherited update/rollback contracts"
17
+ },
18
+ {
19
+ "id": "performance",
20
+ "command": "R58 performance benchmark suite",
21
+ "expected": "No material common-path regression and >=20% aggregate warm p95 improvement where DEADBYTE-owned latency dominates, or evidence-backed external-latency limitation"
22
+ },
23
+ {
24
+ "id": "cross-plane",
25
+ "command": "R58 cross-plane acceptance",
26
+ "expected": "PASS isolated frontend/controller/bridge/core lifecycle, stale-session, durable-job, interruption and recovery cases"
17
27
  },
18
28
  {
19
29
  "id": "full-regression",
20
30
  "command": "npm run r48:full:test",
21
- "expected": "PASS current R56 successor"
31
+ "expected": "PASS current R58 candidate after final relevant source mutation"
22
32
  },
23
33
  {
24
34
  "id": "package-boundary",
25
35
  "command": "node --test test/package-boundary.test.mjs",
26
- "expected": "PASS"
36
+ "expected": "PASS bundled Bridge and canonical launchers/package surface"
27
37
  },
28
38
  {
29
39
  "id": "windows-gate",
30
40
  "command": "npm run gate:windows",
31
- "expected": "PASS R56 focused + recorded full regression + manifest/doctor evidence"
41
+ "expected": "PASS R58 focused/performance/cross-plane/full/package/manifest/doctor evidence"
32
42
  },
33
43
  {
34
44
  "id": "package-verify",
35
45
  "command": "node scripts/npm-release-r48.mjs --verify-only",
36
- "expected": "PASS exact packaged surface and isolated doctor"
46
+ "expected": "PASS isolated exact packaged surface and doctor"
37
47
  },
38
48
  {
39
49
  "id": "activation",
40
- "command": "npx --yes deadbyte-mcp@0.15.33 remote",
41
- "expected": "activate exact R56 from exact active 0.15.32"
50
+ "command": "npx --yes deadbyte-mcp@0.15.35 remote",
51
+ "expected": "activate exact R58 from exact active 0.15.34"
42
52
  },
43
53
  {
44
54
  "id": "rollback",
45
- "command": "runtime-update --rollback-receipt <signed R56 activation receipt>",
46
- "expected": "restore exact signed 0.15.32 pointer, signed predecessor launcher snapshot, ONLINE runtime, all authority DISARMED"
55
+ "command": "runtime-update --rollback-receipt <signed R58 activation receipt>",
56
+ "expected": "restore exact signed 0.15.34 pointer/runtime, ONLINE, all authority DISARMED"
47
57
  },
48
58
  {
49
59
  "id": "restore",
50
- "command": "npx --yes deadbyte-mcp@0.15.33 remote",
51
- "expected": "restore same exact R56 release/generation and foreground authority contract"
60
+ "command": "npx --yes deadbyte-mcp@0.15.35 remote",
61
+ "expected": "restore exact same immutable R58 release/generation and foreground authority contract"
52
62
  }
53
63
  ],
54
64
  "observed_pre_release_evidence": {
55
- "red_parent_0_15_32": {
65
+ "bridge_dependency_first_red": {
66
+ "status": "FAIL_EXPECTED",
67
+ "tests": 3,
68
+ "failed": 3,
69
+ "receipt_id": "9ccae28950a898ed6303953f",
70
+ "receipt_sha256": "81c77105679581b927bd874d74456c057901c05578c8baeb055311bdde668339"
71
+ },
72
+ "bridge_dependency_green": {
73
+ "status": "PASS",
74
+ "tests": 3,
75
+ "failed": 0,
76
+ "receipt_id": "58e4aefc717b305ea95bb719",
77
+ "receipt_sha256": "46f66b52eb9a761ef1260c15bee618ecda3944a3df3767057aabf0541da3fd9b"
78
+ },
79
+ "bundled_bridge_first_red": {
56
80
  "status": "FAIL_EXPECTED",
57
- "tests": 5,
58
- "failed": 5,
59
- "receipt_id": "483a2b5bbda756dc85954752",
60
- "receipt_sha256": "f3b446306691d61e97896ab4d237abaa20d1243237299812e790233c46451dba"
81
+ "tests": 2,
82
+ "failed": 2,
83
+ "receipt_id": "184fba94cec5527ca276dfb6",
84
+ "receipt_sha256": "f261242a1d007ee54a233dcb755c7b80db00b0bb1dc7825aed2c6ee3a6fe6d52"
61
85
  },
62
- "green_r56_candidate": {
86
+ "bundled_bridge_green": {
63
87
  "status": "PASS",
64
- "tests": 5,
88
+ "tests": 2,
65
89
  "failed": 0,
66
- "receipt_id": "7bf8f8dd93f175f5d7de118a",
67
- "receipt_sha256": "4198930f38a3fc4b7978cfc94ca4509127561c170b05f7566bdf79513e449a8b"
90
+ "receipt_id": "fe63b8ef6299469b4d722e23",
91
+ "receipt_sha256": "32c8b4b5c4569928b90945d069dbc9fd46008d11114ab421d5ba72c5a117d197"
68
92
  },
69
- "parent_activation": {
93
+ "isolated_live_lifecycle": {
70
94
  "status": "PASS",
71
- "release_id": "v0.15.32-e7223f467777f5df",
72
- "manifest_sha256": "e7223f467777f5dfeb20fd2cc7a6eca22619a44ed95e5bc0b32d9c7aabba361b",
73
- "generation_manifest_sha256": "740443fd207c5e6ffd5952079214bf6e81e9281a6ec880de9bbe3b8ce1deb00e",
74
- "activation_receipt_sha256": "6518a04154f485cfae42e582269634d69a8b05a0183149d5e10006fbdd9d933c"
95
+ "tests": 1,
96
+ "failed": 0,
97
+ "receipt_id": "891a8004a121eba1feb374e1",
98
+ "receipt_sha256": "1c8454baee9c36ebefc49318a4d31d14cd91644bd91f92ef77ffa4d857788555"
75
99
  },
76
- "parent_rollback": {
77
- "status": "FAIL_EXPECTED",
78
- "error": "active pointer launcher digest mismatch",
79
- "command_receipt_sha256": "00cbd497e4902c67ab39313a378e2fcf32159113b46339ad1d54b5e5a7714205"
100
+ "focused_current": {
101
+ "status": "PASS",
102
+ "tests": 98,
103
+ "failed": 0,
104
+ "receipt_id": "f7571557a3faeafea4af755a",
105
+ "receipt_sha256": "2225e2506b3a714359194fcb2657d22911eaef34904ab0a031c1e35419f293e7",
106
+ "request_sha256": "4bd1ac94df92661a950ad7c6b52b062b2c873581ea72868ce411a770b7ab3e67"
107
+ },
108
+ "performance": {
109
+ "status": "PASS_BOUNDED_PREPUBLISH",
110
+ "summary_sha256": "4586d8462ce1ae643d255315d4b4febfdd3f731dd8728e4b37b5636b622b756c",
111
+ "stdio_parent_p95_ms": 1.0380999999997584,
112
+ "stdio_candidate_p95_ms": 1.0587000000000444,
113
+ "stdio_p95_delta_pct": 1.984392678457768,
114
+ "bridge_candidate_first_reduction_pct": 63.632445348471286,
115
+ "bridge_baseline_first_reduction_pct": 43.06594367803213,
116
+ "receipts": [
117
+ "63d921dc746b3070ce359a5307d0117bbb2327fa6317bb71ab1906a925b3aa97",
118
+ "4d3aac8c4bad143dd82a1d2f8b3904fd01862708e24cb11a01285b74548cebe6",
119
+ "cf8450e1cecbdfb41cf546b8818181c4f5c141e6b050d694af87920c7f7612de",
120
+ "eff9d7e55cec4d6a778afdda3bb3b8e2e24f7a4addd9bb6ace6eaa2839f2372d"
121
+ ]
122
+ },
123
+ "cross_plane": {
124
+ "status": "PASS",
125
+ "tests": 126,
126
+ "failures": 0,
127
+ "receipts": [
128
+ "b57c8c1051655f36116a5bea4d2c6818001daede3e6cc5689049f44495f11153",
129
+ "e9aef5b21f8bfd4b4737964aa275045383540fc0569bffb57f0b7a1974dda967",
130
+ "ea1df2285e27758517259195de743ea186817888809c91f7998772acb2ad58c7",
131
+ "d6d80921d04ccbc7e1ede7ebc63a50157ee33e3f7529f2e75c8120285cbcfd52",
132
+ "27385e3e27cf7952b89bca8660369f09559f028606cd9e53c5275a178ad5057b"
133
+ ]
80
134
  },
81
135
  "full_regression": {
82
136
  "status": "PASS",
83
- "files": 233,
137
+ "files": 258,
84
138
  "batches": 8,
85
- "elapsed_ms": 245761.429,
86
- "receipt_id": "3dce7b1649f489fc02b8f055",
87
- "receipt_sha256": "35da0a6a0a7d98c08f32f24b5f06df434d353018089acfaf51b9dd51693b7083",
88
- "request_sha256": "af035b60299d84e743aa2babaa2321e89555bea4bbb2cd95036f6dc9fe086010"
139
+ "elapsed_ms": 336694.69,
140
+ "receipt_id": "bb121ac3ce6b6806f7f46fff",
141
+ "receipt_sha256": "2d38483435dfc05a30682cd28df80d479f8e2590c636dde5ff3e278372d7463e",
142
+ "request_sha256": "130a418b22b2aef396a1aa0021bdfa0ba9a57d09af9497dcd2522adbca47aecd"
143
+ },
144
+ "package": {
145
+ "status": "PENDING"
146
+ },
147
+ "public_surface": {
148
+ "status": "PASS",
149
+ "production_tool_count": 43,
150
+ "candidate_tool_count": 43,
151
+ "drift": [],
152
+ "baseline_catalog_sha256": "ceabd441cc774d03322041155052a28c8fb1c63ae9847199e0278d05c4bd1b28",
153
+ "names_sha256": "dde7d10e85c52beb285e3adf41b69dece11162ab0bc8233f056e471f653776d6",
154
+ "schema_sha256": "8efb5cbcd24f1a46ef4588c92d913fa1fd72d7c71a9ad243b151f2b483a7f5cb",
155
+ "receipt_sha256": "58eefdebe2c456b171eaebf585687bf111ee81f84c92ae968091f4eb056d4c91"
156
+ },
157
+ "pre_full_package_process": {
158
+ "status": "PASS",
159
+ "tests": 17,
160
+ "failed": 0,
161
+ "receipt_id": "f1aa5d06775113d734b94149",
162
+ "receipt_sha256": "d0dce46d897422f0db690b0cd523e5ab740ffd967e4dc8e265d436d888ccff9f"
89
163
  }
90
164
  },
91
165
  "inherited_parent_evidence": {
92
- "version": "0.15.32",
93
- "parent_full_regression": "PASS",
94
- "parent_manifest_sha256": "e7223f467777f5dfeb20fd2cc7a6eca22619a44ed95e5bc0b32d9c7aabba361b",
95
- "parent_tarball_sha256": "c9e1f5875dd2177cee0089305b40321c128c54ce7f5522e34e507d4ecfb22638",
166
+ "version": "0.15.34",
167
+ "parent_manifest_sha256": "2199bb59f0e0fc205d470d11f990d3ce3df444be5eba2a7d8dbc60d5f5b790bb",
168
+ "parent_generation_manifest_sha256": "1a20a62aaeb324a9b5c03d158952f35092d58fedf2ac7725820ba2b094a4a88f",
169
+ "parent_tarball_sha256": "a6f7b21faf34793ca17dfb6d0e9ec03320f1468d011e75d8349098df82fc2639",
96
170
  "parent_registry_identity": "PASS",
97
- "four_hour_soak": "NOT_COMPLETED_OPERATOR_BYPASS"
171
+ "parent_activation_rollback_restore": "PASS",
172
+ "parent_rollback_receipt_sha256": "2f8aa5784fe6629c25af776b247b22b8e84d1a51c3420339ddd7a7445cf6ff9b",
173
+ "four_hour_soak": "NOT_COMPLETED"
98
174
  },
99
175
  "operator_override": {
100
176
  "four_hour_soak": "NOT_COMPLETED",
177
+ "clean_machine": "NOT_COMPLETED",
101
178
  "stable_final_claim": false
102
179
  },
103
180
  "performance": {
@@ -131,6 +208,21 @@
131
208
  "signed_handoff_launcher_snapshot_required": true,
132
209
  "predecessor_launcher_restored_before_pointer_commit": true,
133
210
  "successor_launcher_restored_before_recovery_pointer": true
211
+ },
212
+ "r57": {
213
+ "core_startup_wait_timeout_ms": 10000,
214
+ "core_startup_poll_ms": 100,
215
+ "retry_only_zero_child": true,
216
+ "ambiguous_topology_fail_closed": true
217
+ },
218
+ "r58": {
219
+ "baseline_version": "0.15.34",
220
+ "candidate_version": "0.15.35",
221
+ "aggregate_warm_p95_target_reduction_pct": 20,
222
+ "status": "PASS_BOUNDED_PREPUBLISH",
223
+ "bridge_baseline_first_p95_reduction_pct": 43.06594367803213,
224
+ "bridge_candidate_first_p95_reduction_pct": 63.632445348471286,
225
+ "stdio_p95_delta_pct": 1.984392678457768
134
226
  }
135
227
  },
136
228
  "non_win32": {
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "deadbyte-chatgpt-bridge",
3
+ "version": "0.15.35",
4
+ "private": true,
5
+ "type": "module",
6
+ "engines": { "node": ">=22" },
7
+ "dependencies": {
8
+ "@modelcontextprotocol/client": "2.1.0",
9
+ "@modelcontextprotocol/server": "2.1.0"
10
+ }
11
+ }
@@ -0,0 +1,412 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { createServer } from 'node:http';
3
+ import { readFileSync } from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { Client } from '@modelcontextprotocol/client';
7
+ import { StdioClientTransport, getDefaultEnvironment } from '@modelcontextprotocol/client/stdio';
8
+ import { McpServer, createMcpHandler, createRequestStateCodec, inputRequired, inputResponse } from '@modelcontextprotocol/server';
9
+ import {preparePublicToolDefinitions} from './public-tool-definitions.mjs';
10
+ import {createDeadbyteNodeHandler} from './node-http-adapter.mjs';
11
+ import { bridgeCatalogSha256, bridgeDeadlineForTool, createBridgeGovernor, enforceDesktopBridgeResult, verifyCompactCatalogAttestation } from './r40-governor.mjs';
12
+
13
+ const coreRoot = path.resolve(process.env.DEADBYTE_CORE_ROOT ?? 'C:/Users/DEADBYTE/Downloads/deadbyte-mcp-v0.6.0');
14
+ const coreServer = path.join(coreRoot, 'src', 'mcp-server.mjs');
15
+ const workspaceRoot = path.resolve(process.env.DEADBYTE_WORKSPACE_ROOT ?? path.join(coreRoot, 'workspaces'));
16
+ const port = Number(process.env.DEADBYTE_BRIDGE_PORT ?? '8787');
17
+ const baseTools = ['contained_transform', 'evidence_verify', 'file_read', 'proof_execute', 'workspace_open'];
18
+ const privilegedTools = ['host_exec', 'host_file_read', 'host_file_write'];
19
+ const agentTools = [
20
+ 'agent_task_approve', 'agent_task_cancel', 'agent_task_events', 'agent_task_run',
21
+ 'agent_task_status', 'agent_task_submit', 'agent_task_verify'
22
+ ];
23
+ const codingTools = [
24
+ 'coding_benchmark_run', 'coding_command_run', 'coding_file_read', 'coding_file_write',
25
+ 'coding_receipt_verify', 'coding_session_status', 'coding_task_approve', 'coding_task_cancel',
26
+ 'coding_task_events', 'coding_task_run', 'coding_task_status', 'coding_task_submit',
27
+ 'coding_task_verify', 'coding_text_replace', 'coding_tree'
28
+ ];
29
+ const autonomousTools = [
30
+ 'autonomous_goal_approve', 'autonomous_goal_cancel', 'autonomous_goal_events',
31
+ 'autonomous_goal_run', 'autonomous_goal_status', 'autonomous_goal_submit',
32
+ 'autonomous_goal_verify', 'autonomous_release_gate', 'autonomous_session_status',
33
+ 'native_diff_apply', 'native_diff_preview', 'native_diff_verify'
34
+ ];
35
+ const r35FullTools = [
36
+ 'agent_task_approve','agent_task_cancel','agent_task_events','agent_task_run','agent_task_status','agent_task_submit','agent_task_verify',
37
+ 'autonomous_goal_approve','autonomous_goal_cancel','autonomous_goal_events','autonomous_goal_run','autonomous_goal_status','autonomous_goal_submit','autonomous_goal_verify','autonomous_release_gate','autonomous_session_status',
38
+ 'coding_benchmark_run','coding_command_run','coding_file_read','coding_file_write','coding_files_read','coding_receipt_verify','coding_search','coding_session_status','coding_stat',
39
+ 'coding_symbol_definition','coding_symbol_outline','coding_symbol_references','coding_symbol_replace',
40
+ 'coding_task_approve','coding_task_cancel','coding_task_events','coding_task_run','coding_task_status','coding_task_submit','coding_task_verify','coding_text_replace','coding_tree',
41
+ 'contained_transform','evidence_verify','file_read',
42
+ 'host_exec','host_file_read','host_file_write',
43
+ 'machine_fs_delete','machine_fs_edit_exact','machine_fs_list','machine_fs_mkdir','machine_fs_move','machine_fs_read','machine_fs_stat','machine_fs_write',
44
+ 'machine_list','machine_ping','machine_process_list','machine_revoke','machine_search_cancel','machine_search_page','machine_search_start','machine_search_status','machine_status','machine_system_status',
45
+ 'native_diff_apply','native_diff_preview','native_diff_verify',
46
+ 'process_session_action','process_session_list','process_session_read','process_session_start','process_session_status','process_session_terminate',
47
+ 'proof_execute','workspace_open'
48
+ ].sort();
49
+ const r36CompactTools = [
50
+ 'autonomous_goal_approve','autonomous_goal_cancel','autonomous_goal_events','autonomous_goal_run','autonomous_goal_status','autonomous_goal_submit','autonomous_goal_verify','autonomous_release_gate','autonomous_session_status',
51
+ 'capability_manifest',
52
+ 'coding_benchmark_run','coding_command_run','coding_file_read','coding_file_write','coding_inspect','coding_receipt_verify','coding_session_status','coding_symbol_replace',
53
+ 'coding_task_approve','coding_task_cancel','coding_task_events','coding_task_run','coding_task_status','coding_task_submit','coding_task_verify','coding_text_replace','coding_tree',
54
+ 'evidence_verify',
55
+ 'host_exec','host_file_read','host_file_write',
56
+ 'machine_fs','machine_list','machine_observe','machine_ping','machine_revoke','machine_status',
57
+ 'native_diff_apply','native_diff_preview','native_diff_verify',
58
+ 'process_session'
59
+ ].sort();
60
+ if (r35FullTools.length !== 73) throw new Error(`R35 production catalog constant drift: ${r35FullTools.length}`);
61
+ if (r36CompactTools.length !== 41) throw new Error(`R36 compact catalog constant drift: ${r36CompactTools.length}`);
62
+ const AUTONOMOUS_DOWNSTREAM_TIMEOUT_MS = 900000;
63
+ const AUTONOMOUS_DOWNSTREAM_TOTAL_MS = 1200000;
64
+ const AUDIT_MAX_STRING_BYTES = 512;
65
+ const AUDIT_MAX_ARRAY_ITEMS = 24;
66
+ const AUDIT_MAX_OBJECT_KEYS = 48;
67
+ const SENSITIVE_AUDIT_KEY = /(token|secret|password|authorization|cookie|recovery|private[_-]?key)/i;
68
+ const PAYLOAD_AUDIT_KEY = /^(content|raw_text|text)$/i;
69
+ let auditSequence = 0;
70
+ const bridgeGovernor = createBridgeGovernor();
71
+
72
+ function auditDigest(text) {
73
+ return createHash('sha256').update(text, 'utf8').digest('hex');
74
+ }
75
+
76
+ function auditString(value, key = '') {
77
+ const bytes = Buffer.byteLength(value, 'utf8');
78
+ if (SENSITIVE_AUDIT_KEY.test(key)) return `<redacted bytes=${bytes} sha256=${auditDigest(value)}>`;
79
+ if (PAYLOAD_AUDIT_KEY.test(key)) return `<payload bytes=${bytes} sha256=${auditDigest(value)}>`;
80
+ if (/^(?:Bearer\s+|Basic\s+|sk-[A-Za-z0-9_-]{12,}|gh[pousr]_[A-Za-z0-9_]{12,})/i.test(value)) {
81
+ return `<redacted bytes=${bytes} sha256=${auditDigest(value)}>`;
82
+ }
83
+ if (bytes <= AUDIT_MAX_STRING_BYTES) return value;
84
+ const prefix = value.slice(0, 256);
85
+ return `${prefix}<truncated bytes=${bytes} sha256=${auditDigest(value)}>`;
86
+ }
87
+
88
+ function auditSanitize(value, key = '', depth = 0) {
89
+ if (value === null || value === undefined) return value ?? null;
90
+ if (depth > 6) return '<depth-limit>';
91
+ if (typeof value === 'string') return auditString(value, key);
92
+ if (typeof value === 'number' || typeof value === 'boolean') return value;
93
+ if (typeof value === 'bigint') return value.toString();
94
+ if (Array.isArray(value)) {
95
+ const out = value.slice(0, AUDIT_MAX_ARRAY_ITEMS).map(item => auditSanitize(item, key, depth + 1));
96
+ if (value.length > AUDIT_MAX_ARRAY_ITEMS) out.push(`<${value.length - AUDIT_MAX_ARRAY_ITEMS} more items>`);
97
+ return out;
98
+ }
99
+ if (typeof value === 'object') {
100
+ const entries = Object.entries(value).slice(0, AUDIT_MAX_OBJECT_KEYS);
101
+ const out = {};
102
+ for (const [childKey, childValue] of entries) out[childKey] = auditSanitize(childValue, childKey, depth + 1);
103
+ if (Object.keys(value).length > AUDIT_MAX_OBJECT_KEYS) out._truncated_keys = Object.keys(value).length - AUDIT_MAX_OBJECT_KEYS;
104
+ return out;
105
+ }
106
+ return String(value);
107
+ }
108
+
109
+ const BRIDGE_LOG_LEVEL = process.env.DEADBYTE_BRIDGE_LOG_LEVEL === 'debug' ? 'debug' : 'human';
110
+
111
+ function auditWrite(kind, call, payload) {
112
+ const stamp = new Date().toISOString();
113
+ const id = String(call.id).padStart(6, '0');
114
+ console.log(`[TOOL ${kind}] ${stamp} #${id} ${call.name} ${JSON.stringify(auditSanitize(payload))}`);
115
+ }
116
+
117
+ function compactDuration(ms) {
118
+ if (!Number.isFinite(ms) || ms < 0) return '0ms';
119
+ if (ms < 10) return `${ms.toFixed(1)}ms`;
120
+ if (ms < 1000) return `${Math.round(ms)}ms`;
121
+ return `${(ms / 1000).toFixed(ms < 10000 ? 2 : 1)}s`;
122
+ }
123
+
124
+ function auditShortReason(result, error = null) {
125
+ const structured = result?.structuredContent;
126
+ const candidates = error
127
+ ? [error?.message ?? String(error)]
128
+ : [
129
+ structured?.error, structured?.message, structured?.reason,
130
+ structured?.result?.error, structured?.result?.message,
131
+ ...(Array.isArray(result?.content) ? result.content.filter(item => item?.type === 'text').map(item => item.text) : [])
132
+ ];
133
+ for (const candidate of candidates) {
134
+ if (typeof candidate !== 'string' || !candidate) continue;
135
+ const sanitized = auditString(candidate);
136
+ const text = String(sanitized).replace(/[\r\n\t]+/g, ' ').replace(/\s{2,}/g, ' ').trim();
137
+ if (text) return text.length <= 180 ? text : `${text.slice(0, 179)}…`;
138
+ }
139
+ return '';
140
+ }
141
+
142
+ function auditCompactResult(call, { result = null, error = null } = {}) {
143
+ const elapsedMs = Number(process.hrtime.bigint() - call.started) / 1e6;
144
+ const failed = error !== null || result?.isError === true;
145
+ const reason = failed ? auditShortReason(result, error) : '';
146
+ const stamp = new Date().toISOString();
147
+ const id = String(call.id).padStart(6, '0');
148
+ console.log(`[TOOL] ${stamp} #${id} ${failed ? '✗' : '✓'} ${call.name} ${compactDuration(elapsedMs)}${reason ? ` — ${reason}` : ''}`);
149
+ return elapsedMs;
150
+ }
151
+
152
+ function auditToolStart(name, args) {
153
+ const call = { id: ++auditSequence, name, started: process.hrtime.bigint() };
154
+ if (BRIDGE_LOG_LEVEL === 'debug') auditWrite('IN ', call, args);
155
+ return call;
156
+ }
157
+
158
+ function auditToolFinish(call, result) {
159
+ const elapsedMs = auditCompactResult(call, { result });
160
+ if (BRIDGE_LOG_LEVEL === 'debug') {
161
+ auditWrite('OUT', call, {
162
+ elapsed_ms: Number(elapsedMs.toFixed(3)),
163
+ is_error: result?.isError === true,
164
+ structured: result?.structuredContent ?? null,
165
+ content: result?.content ?? null
166
+ });
167
+ }
168
+ }
169
+
170
+ function auditToolFail(call, error) {
171
+ const elapsedMs = auditCompactResult(call, { error });
172
+ if (BRIDGE_LOG_LEVEL === 'debug') {
173
+ auditWrite('ERR', call, {
174
+ elapsed_ms: Number(elapsedMs.toFixed(3)),
175
+ name: error?.name ?? 'Error',
176
+ message: error?.message ?? String(error)
177
+ });
178
+ }
179
+ }
180
+
181
+ const allowedCatalogs = [];
182
+ for (const host of [false, true]) {
183
+ for (const agent of [false, true]) {
184
+ for (const coding of [false, true]) {
185
+ for (const autonomous of [false, true]) {
186
+ if (autonomous && !coding) continue;
187
+ const items = [...baseTools];
188
+ if (host) items.push(...privilegedTools);
189
+ if (agent) items.push(...agentTools);
190
+ if (coding) items.push(...codingTools);
191
+ if (autonomous) items.push(...autonomousTools);
192
+ allowedCatalogs.push(items.sort());
193
+ }
194
+ }
195
+ }
196
+ }
197
+
198
+ function loadToken() {
199
+ const fromEnv = process.env.DEADBYTE_BRIDGE_PATH_TOKEN ?? '';
200
+ if (/^[a-f0-9]{64}$/.test(fromEnv)) return fromEnv;
201
+ const tokenFile = process.env.DEADBYTE_BRIDGE_TOKEN_FILE ?? path.join(os.homedir(), '.deadbyte-mcp', 'bridge', 'path-token.txt');
202
+ const value = readFileSync(tokenFile, 'utf8').trim();
203
+ if (!/^[a-f0-9]{64}$/.test(value)) throw new Error(`invalid bridge path token file: ${tokenFile}`);
204
+ return value;
205
+ }
206
+
207
+ const token = loadToken();
208
+ const requestStateKey = createHash('sha256')
209
+ .update('DEADBYTE-R24-MRTR-V1\0', 'utf8')
210
+ .update(token, 'utf8')
211
+ .digest();
212
+ const requestStateCodec = createRequestStateCodec({ key: requestStateKey, ttlSeconds: 600 });
213
+ if (!Number.isInteger(port) || port < 1024 || port > 65535) throw new Error('invalid DEADBYTE_BRIDGE_PORT');
214
+ const endpointPath = `/mcp/${token}`;
215
+
216
+ process.on('uncaughtExceptionMonitor', error => {
217
+ console.error(`[bridge-fatal-monitor] ${error?.stack ?? String(error)}`);
218
+ });
219
+ process.on('exit', code => {
220
+ console.error(`[bridge-exit] code=${code}`);
221
+ });
222
+
223
+ const downstream = new Client(
224
+ { name: 'deadbyte-chatgpt-bridge', version: '0.2.0' },
225
+ { versionNegotiation: { mode: { pin: '2026-07-28' } } }
226
+ );
227
+ const downstreamTransport = new StdioClientTransport({
228
+ command: process.execPath,
229
+ args: [coreServer],
230
+ cwd: coreRoot,
231
+ env: {
232
+ ...getDefaultEnvironment(),
233
+ ...process.env,
234
+ DEADBYTE_WORKSPACE_ROOT: workspaceRoot
235
+ },
236
+ stderr: 'pipe'
237
+ });
238
+
239
+ downstreamTransport.stderr?.on('data', chunk => process.stderr.write(`[deadbyte-core] ${chunk}`));
240
+ await downstream.connect(downstreamTransport);
241
+ if (downstream.getProtocolEra() !== 'modern') throw new Error('DEADBYTE downstream is not modern MCP');
242
+
243
+ const listed = await downstream.listTools();
244
+ const actualNames = listed.tools.map(tool => tool.name).sort();
245
+ const exactR36Compact = JSON.stringify(actualNames) === JSON.stringify(r36CompactTools);
246
+ let compactCatalogAttestation = null;
247
+ let compactCatalogLegacy = false;
248
+ if (actualNames.includes('capability_manifest')) {
249
+ const manifestResult = await downstream.callTool(
250
+ { name:'capability_manifest', arguments:{} },
251
+ bridgeDeadlineForTool('capability_manifest')
252
+ );
253
+ const manifestSchema = manifestResult?.structuredContent?.result?.schema ?? null;
254
+ if (manifestSchema === 'deadbyte.capability-manifest.v2' || manifestSchema === 'deadbyte.capability-manifest.v3') {
255
+ compactCatalogAttestation = verifyCompactCatalogAttestation(actualNames, manifestResult);
256
+ } else if (manifestSchema === 'deadbyte.capability-manifest.v1' && exactR36Compact) {
257
+ compactCatalogLegacy = true;
258
+ } else {
259
+ throw new Error(`DEADBYTE compact catalog attestation unavailable or invalid schema: ${String(manifestSchema)}`);
260
+ }
261
+ }
262
+ const catalogOk = compactCatalogAttestation?.ok === true || compactCatalogLegacy ||
263
+ allowedCatalogs.some(expected => JSON.stringify(actualNames) === JSON.stringify(expected)) ||
264
+ JSON.stringify(actualNames) === JSON.stringify(r35FullTools);
265
+ if (!catalogOk) throw new Error(`DEADBYTE tool catalog mismatch: ${JSON.stringify(actualNames)}`);
266
+ const hostConfigured = privilegedTools.every(name => actualNames.includes(name));
267
+ const agentConfigured = agentTools.every(name => actualNames.includes(name));
268
+ const codingConfigured = codingTools.every(name => actualNames.includes(name));
269
+ const autonomousConfigured = autonomousTools.every(name => actualNames.includes(name));
270
+ const bridgeCatalogDigest = bridgeCatalogSha256(actualNames);
271
+
272
+ function plannerTextFromInput(ctx) {
273
+ const response = inputResponse(ctx.mcpReq.inputResponses, 'planner');
274
+ if (!response || response.kind !== 'sampling') throw new Error('planner sampling response missing');
275
+ const content = response.result?.content;
276
+ const block = Array.isArray(content) ? content.find(item => item?.type === 'text') : content;
277
+ if (!block || block.type !== 'text' || typeof block.text !== 'string') throw new Error('planner sampling response missing text');
278
+ return { raw_text: block.text, model: typeof response.result?.model === 'string' ? response.result.model.slice(0, 128) : 'client-model' };
279
+ }
280
+
281
+ const publicToolDefinitions=preparePublicToolDefinitions(listed.tools);
282
+
283
+ function buildFrontServer() {
284
+ const front = new McpServer(
285
+ { name: 'deadbyte-chatgpt-bridge', version: '0.2.0' },
286
+ { requestState: { verify: requestStateCodec.verify } }
287
+ );
288
+ for (const tool of publicToolDefinitions) {
289
+ const {inputSchema,outputSchema}=tool;
290
+ front.registerTool(tool.name, {
291
+ title: tool.title,
292
+ description: tool.description,
293
+ inputSchema,
294
+ outputSchema,
295
+ annotations: tool.annotations
296
+ }, async (args, ctx) => {
297
+ if (tool.name !== 'autonomous_goal_run') {
298
+ const audit = auditToolStart(tool.name, args);
299
+ const ticket = await bridgeGovernor.acquire(tool.name);
300
+ try {
301
+ const budget = bridgeDeadlineForTool(tool.name);
302
+ const result = await downstream.callTool({ name: tool.name, arguments: args }, budget);
303
+ enforceDesktopBridgeResult(tool.name, result);
304
+ auditToolFinish(audit, result);
305
+ return result;
306
+ } catch (error) {
307
+ auditToolFail(audit, error);
308
+ throw error;
309
+ } finally {
310
+ ticket.release();
311
+ }
312
+ }
313
+ const state = ctx.mcpReq.requestState();
314
+ const callArgs = { ...args };
315
+ if (state) {
316
+ if (state.goal_id !== args.goal_id || typeof state.request_id !== 'string') throw new Error('autonomous planner requestState binding mismatch');
317
+ const planner = plannerTextFromInput(ctx);
318
+ callArgs.planner_response = { request_id: state.request_id, raw_text: planner.raw_text, model: planner.model };
319
+ }
320
+ const audit = auditToolStart(tool.name, callArgs);
321
+ const ticket = await bridgeGovernor.acquire(tool.name);
322
+ let result;
323
+ try {
324
+ const budget = bridgeDeadlineForTool(tool.name);
325
+ result = await downstream.callTool({ name: tool.name, arguments: callArgs }, budget);
326
+ auditToolFinish(audit, result);
327
+ } catch (error) {
328
+ auditToolFail(audit, error);
329
+ throw error;
330
+ } finally {
331
+ ticket.release();
332
+ }
333
+ const plannerRequest = result?.structuredContent?.status === 'input_required' ? result.structuredContent.planner_request : null;
334
+ if (!plannerRequest) return result;
335
+ if (plannerRequest.request_id === undefined || typeof plannerRequest.prompt !== 'string') throw new Error('autonomous planner request malformed');
336
+ return inputRequired({
337
+ inputRequests: {
338
+ planner: inputRequired.createMessage({
339
+ messages: [{ role: 'user', content: { type: 'text', text: plannerRequest.prompt } }],
340
+ maxTokens: 4096,
341
+ temperature: 0,
342
+ includeContext: 'none'
343
+ })
344
+ },
345
+ requestState: await requestStateCodec.mint({ goal_id: args.goal_id, request_id: plannerRequest.request_id })
346
+ });
347
+ });
348
+ }
349
+ return front;
350
+ }
351
+
352
+ const mcpHandler = createMcpHandler(() => buildFrontServer(), {
353
+ legacy: 'reject',
354
+ responseMode: 'json',
355
+ onerror: error => console.error(`[mcp-http] ${error.stack ?? String(error)}`)
356
+ });
357
+ const nodeMcpHandler = createDeadbyteNodeHandler(mcpHandler);
358
+ const httpServer = createServer(async (req, res) => {
359
+ try {
360
+ const pathname = new URL(req.url ?? '/', 'http://127.0.0.1').pathname;
361
+ if (pathname === '/healthz') {
362
+ res.writeHead(200, { 'content-type': 'text/plain; charset=utf-8' });
363
+ return res.end('ok');
364
+ }
365
+ if (pathname === '/healthz/r40') {
366
+ res.writeHead(200, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' });
367
+ return res.end(JSON.stringify({
368
+ status:'ok',catalog_sha256:bridgeCatalogDigest,
369
+ catalog_attestation:compactCatalogAttestation?.ok===true?'verified':compactCatalogLegacy?'legacy-r39':'not-applicable',
370
+ ledger_sha256:compactCatalogAttestation?.ledger_sha256??null,
371
+ governor:bridgeGovernor.snapshot()
372
+ }));
373
+ }
374
+ if (pathname !== endpointPath) {
375
+ res.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' });
376
+ return res.end('not found');
377
+ }
378
+ const contentLength = Number(req.headers['content-length'] ?? '0');
379
+ if (Number.isFinite(contentLength) && contentLength > 1024 * 1024) {
380
+ res.writeHead(413, { 'content-type': 'text/plain; charset=utf-8' });
381
+ return res.end('request too large');
382
+ }
383
+ await nodeMcpHandler(req, res);
384
+ } catch (error) {
385
+ if (!res.headersSent) res.writeHead(500, { 'content-type': 'text/plain; charset=utf-8' });
386
+ if (!res.writableEnded) res.end('bridge error');
387
+ console.error(error instanceof Error ? error.stack : String(error));
388
+ }
389
+ });
390
+
391
+ await new Promise((resolve, reject) => {
392
+ httpServer.once('error', reject);
393
+ httpServer.listen(port, '127.0.0.1', resolve);
394
+ });
395
+ console.log(`BRIDGE_READY http://127.0.0.1:${port}${endpointPath}`);
396
+ console.log(`BRIDGE_TOOLS ${actualNames.join(',')}`);
397
+ console.log(`BRIDGE_CATALOG_SHA256 ${bridgeCatalogDigest}`);
398
+ console.log(`BRIDGE_CATALOG_ATTESTATION ${compactCatalogAttestation?.ok===true?'VERIFIED':compactCatalogLegacy?'LEGACY_R39':'NOT_APPLICABLE'}`);
399
+ console.log(`BRIDGE_HOST_PLANE ${hostConfigured ? 'CONFIGURED_DISARMED_OR_ARMED_BY_LOCAL_LEASE' : 'UNCONFIGURED'}`);
400
+ console.log(`BRIDGE_AGENT_RUNTIME ${agentConfigured ? 'ENABLED' : 'DISABLED'}`);
401
+ console.log(`BRIDGE_CODING_RUNTIME ${codingConfigured ? 'ENABLED' : 'DISABLED'}`);
402
+ console.log(`BRIDGE_AUTONOMOUS_RUNTIME ${autonomousConfigured ? 'ENABLED' : 'DISABLED'}`);
403
+
404
+ async function shutdown() {
405
+ httpServer.close();
406
+ await mcpHandler.close().catch(() => {});
407
+ await downstream.close().catch(() => {});
408
+ process.exit(0);
409
+ }
410
+ process.once('SIGINT', shutdown);
411
+ process.once('SIGTERM', shutdown);
412
+