breakpoint-mcp 1.21.1 → 1.23.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/README.md +1 -1
- package/dist/annotations.js +225 -0
- package/dist/capabilities.js +5 -1
- package/dist/cli/doctor.js +1 -1
- package/dist/cli/init.js +1 -1
- package/dist/cli/tools.js +193 -0
- package/dist/index.js +26 -4
- package/dist/peers.js +238 -0
- package/dist/recipes.js +33 -1
- package/dist/schemas.js +17 -0
- package/dist/secret.js +49 -0
- package/dist/tools/processes.js +25 -1
- package/dist/tools/runtime.js +292 -67
- package/dist/toolsets.js +7 -1
- package/package.json +1 -1
package/dist/peers.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import net from "node:net";
|
|
2
|
+
import { BridgeClient, BridgeError } from "./bridge.js";
|
|
3
|
+
import { ProcessRegistry } from "./tools/processes.js";
|
|
4
|
+
import { ensureProjectSecret, readProjectSecret } from "./secret.js";
|
|
5
|
+
import { log } from "./logger.js";
|
|
6
|
+
/**
|
|
7
|
+
* Hard ceiling on simultaneously live peers.
|
|
8
|
+
*
|
|
9
|
+
* Four, not the eight a rival offers. Four headless Godot instances is already a
|
|
10
|
+
* heavy CI runner, the convergence cases that matter are covered at four, and
|
|
11
|
+
* every extra instance multiplies the flake surface of the one feature whose
|
|
12
|
+
* entire selling point is that it does NOT flake. Raise it on evidence, never
|
|
13
|
+
* speculatively.
|
|
14
|
+
*/
|
|
15
|
+
export const MAX_PEERS = 4;
|
|
16
|
+
/** How far above the default runtime port the allocator will scan. */
|
|
17
|
+
const PORT_SCAN_SPAN = 200;
|
|
18
|
+
/** Is `port` bindable on `host` right now? */
|
|
19
|
+
function portFree(host, port) {
|
|
20
|
+
return new Promise((resolve) => {
|
|
21
|
+
const srv = net.createServer();
|
|
22
|
+
srv.once("error", () => resolve(false));
|
|
23
|
+
srv.once("listening", () => srv.close(() => resolve(true)));
|
|
24
|
+
try {
|
|
25
|
+
srv.listen(port, host);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
resolve(false);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
33
|
+
export class PeerRegistry {
|
|
34
|
+
cfg;
|
|
35
|
+
/** Peers get their OWN process registry, so peer ids and `godot_run_managed`
|
|
36
|
+
* ids never share a namespace and the `runtime` toolset does not depend on
|
|
37
|
+
* whether the `processes` toolset is enabled. */
|
|
38
|
+
procs = new ProcessRegistry();
|
|
39
|
+
peers = new Map();
|
|
40
|
+
counter = 0;
|
|
41
|
+
constructor(cfg) {
|
|
42
|
+
this.cfg = cfg;
|
|
43
|
+
}
|
|
44
|
+
/** Peers that have not been stopped and whose child is still running. */
|
|
45
|
+
live() {
|
|
46
|
+
const out = [];
|
|
47
|
+
for (const e of this.peers.values()) {
|
|
48
|
+
if (e.stopped)
|
|
49
|
+
continue;
|
|
50
|
+
if (this.procs.get(e.managedId)?.exited)
|
|
51
|
+
continue;
|
|
52
|
+
out.push(e.info);
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
/** Every peer this registry has spawned, live or not. */
|
|
57
|
+
all() {
|
|
58
|
+
return [...this.peers.values()].map((e) => e.info);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The bridge client addressing one peer. Throws a BridgeError the runtime
|
|
62
|
+
* tools' `fail()` renders — an unknown or dead peer must read as a clear
|
|
63
|
+
* message naming the live ids, never as a generic "cannot reach the bridge".
|
|
64
|
+
*/
|
|
65
|
+
clientFor(id) {
|
|
66
|
+
const e = this.peers.get(id);
|
|
67
|
+
if (!e) {
|
|
68
|
+
const ids = this.live().map((p) => p.id);
|
|
69
|
+
throw new BridgeError("unknown_peer", `No peer with id "${id}". Live peers: ${ids.length ? ids.join(", ") : "(none)"}. ` +
|
|
70
|
+
`Spawn peers with runtime_spawn_peers, or omit \`peer\` to address the default running game.`);
|
|
71
|
+
}
|
|
72
|
+
if (e.stopped)
|
|
73
|
+
throw new BridgeError("peer_stopped", `Peer "${id}" was stopped by runtime_peer_stop.`);
|
|
74
|
+
const m = this.procs.get(e.managedId);
|
|
75
|
+
if (m?.exited) {
|
|
76
|
+
const tail = this.procs.tail(e.managedId, 6).join(" | ");
|
|
77
|
+
throw new BridgeError("peer_exited", `Peer "${id}" exited (code ${m.exitCode})${tail ? `; last output: ${tail}` : ""}.`);
|
|
78
|
+
}
|
|
79
|
+
return e.client;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Allocate `count` free loopback ports, starting just above the default
|
|
83
|
+
* runtime port so a peer never collides with a developer's already-running
|
|
84
|
+
* game. Ports held by live peers are skipped even if the probe would pass.
|
|
85
|
+
*
|
|
86
|
+
* Probe-then-release is a TOCTOU window by construction: another process could
|
|
87
|
+
* take the port between the probe and the child's bind. Allocation is
|
|
88
|
+
* sequential and the window is sub-millisecond, and the failure mode is
|
|
89
|
+
* benign — the child logs "could not listen" and the readiness wait below
|
|
90
|
+
* reports it with that line attached, rather than the peer silently
|
|
91
|
+
* half-existing.
|
|
92
|
+
*/
|
|
93
|
+
async allocatePorts(count) {
|
|
94
|
+
const taken = new Set([this.cfg.runtimePort, ...this.live().map((p) => p.port)]);
|
|
95
|
+
const ports = [];
|
|
96
|
+
const base = this.cfg.runtimePort + 1;
|
|
97
|
+
for (let port = base; port < base + PORT_SCAN_SPAN && ports.length < count; port++) {
|
|
98
|
+
if (taken.has(port))
|
|
99
|
+
continue;
|
|
100
|
+
if (!(await portFree(this.cfg.runtimeHost, port)))
|
|
101
|
+
continue;
|
|
102
|
+
taken.add(port);
|
|
103
|
+
ports.push(port);
|
|
104
|
+
}
|
|
105
|
+
if (ports.length < count) {
|
|
106
|
+
throw new BridgeError("no_free_port", `Could not find ${count} free loopback port(s) in ${base}–${base + PORT_SCAN_SPAN - 1}. ` +
|
|
107
|
+
`Stop stale peers with runtime_peer_stop{all:true}, or set BREAKPOINT_RUNTIME_PORT to a quieter range.`);
|
|
108
|
+
}
|
|
109
|
+
return ports;
|
|
110
|
+
}
|
|
111
|
+
/** Poll a peer's bridge until it answers `ping`, or the deadline passes. */
|
|
112
|
+
async waitReady(client, deadline) {
|
|
113
|
+
for (;;) {
|
|
114
|
+
const remaining = deadline - Date.now();
|
|
115
|
+
if (remaining <= 0)
|
|
116
|
+
return false;
|
|
117
|
+
try {
|
|
118
|
+
await client.request("ping", {}, Math.min(1000, remaining));
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
if (Date.now() >= deadline)
|
|
123
|
+
return false;
|
|
124
|
+
await sleep(100);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Spawn `count` headless peers and wait until each answers `ping`.
|
|
130
|
+
*
|
|
131
|
+
* Waiting is part of the contract on purpose. Godot needs ~200 ms to bind, so
|
|
132
|
+
* a tool that returned immediately would hand the caller peers its very next
|
|
133
|
+
* call cannot reach — a flake in the one feature that exists to remove flakes.
|
|
134
|
+
*/
|
|
135
|
+
async spawn(opts) {
|
|
136
|
+
const liveCount = this.live().length;
|
|
137
|
+
if (liveCount + opts.count > MAX_PEERS) {
|
|
138
|
+
throw new BridgeError("peer_limit", `${liveCount} peer(s) already live; spawning ${opts.count} more would exceed the ceiling of ${MAX_PEERS}. ` +
|
|
139
|
+
`Stop some with runtime_peer_stop{all:true} first.`);
|
|
140
|
+
}
|
|
141
|
+
// Constraint 2 — mint BEFORE the first spawn so no child reaches the addon's
|
|
142
|
+
// unlocked mint branch. Never overwrites an existing secret.
|
|
143
|
+
const secret = ensureProjectSecret(this.cfg.projectPath);
|
|
144
|
+
if (!secret) {
|
|
145
|
+
log("[peers] could not read or mint the project secret; peers will mint their own (see peers.ts)");
|
|
146
|
+
}
|
|
147
|
+
const ports = await this.allocatePorts(opts.count);
|
|
148
|
+
const deadline = Date.now() + (opts.timeoutMs ?? 15000);
|
|
149
|
+
const spawned = [];
|
|
150
|
+
for (let i = 0; i < ports.length; i++) {
|
|
151
|
+
const port = ports[i];
|
|
152
|
+
const id = `peer-${++this.counter}`;
|
|
153
|
+
const extraArgs = ["--headless", ...(opts.args ?? []), ...(opts.scene ? [opts.scene] : [])];
|
|
154
|
+
const env = {
|
|
155
|
+
BREAKPOINT_RUNTIME_PORT: String(port),
|
|
156
|
+
BREAKPOINT_PEER_ID: id,
|
|
157
|
+
BREAKPOINT_PEER_INDEX: String(i),
|
|
158
|
+
};
|
|
159
|
+
if (opts.role)
|
|
160
|
+
env.BREAKPOINT_PEER_ROLE = opts.role;
|
|
161
|
+
const managed = this.procs.run(this.cfg, extraArgs, env);
|
|
162
|
+
const client = new BridgeClient(this.cfg.runtimeHost, port, this.cfg.runtimeTimeoutMs, `runtime peer ${id}`, "Is the peer still running? Peers are headless children of this server; a project that fails to load exits immediately.",
|
|
163
|
+
// The FILE, not resolveBridgeSecret: the addon's _setup_auth() does not
|
|
164
|
+
// read BREAKPOINT_*_SECRET, so a host-launched child authenticates with
|
|
165
|
+
// whatever is on disk regardless of the host's env overrides.
|
|
166
|
+
() => readProjectSecret(this.cfg.projectPath));
|
|
167
|
+
const entry = {
|
|
168
|
+
info: { id, port, pid: managed.child.pid ?? null, role: opts.role ?? null, ready: false },
|
|
169
|
+
client,
|
|
170
|
+
managedId: managed.id,
|
|
171
|
+
stopped: false,
|
|
172
|
+
};
|
|
173
|
+
this.peers.set(id, entry);
|
|
174
|
+
spawned.push(entry);
|
|
175
|
+
}
|
|
176
|
+
await Promise.all(spawned.map(async (e) => {
|
|
177
|
+
e.info.ready = await this.waitReady(e.client, deadline);
|
|
178
|
+
}));
|
|
179
|
+
const notReady = spawned.filter((e) => !e.info.ready);
|
|
180
|
+
if (notReady.length) {
|
|
181
|
+
const detail = notReady
|
|
182
|
+
.map((e) => {
|
|
183
|
+
const m = this.procs.get(e.managedId);
|
|
184
|
+
const why = m?.exited ? `exited (code ${m.exitCode})` : "never answered ping";
|
|
185
|
+
const tail = this.procs.tail(e.managedId, 6).join(" | ");
|
|
186
|
+
return `${e.info.id} on ${e.info.port}: ${why}${tail ? ` — ${tail}` : ""}`;
|
|
187
|
+
})
|
|
188
|
+
.join("; ");
|
|
189
|
+
// Leave the failed peers registered rather than reaping them: the caller
|
|
190
|
+
// can still runtime_peer_stop{all:true}, and a half-started peer that
|
|
191
|
+
// vanished from the registry is harder to reason about than one that
|
|
192
|
+
// reports why it is not ready.
|
|
193
|
+
throw new BridgeError("peer_not_ready", `${notReady.length} of ${spawned.length} peer(s) did not become ready. ${detail}. ` +
|
|
194
|
+
`Is the Breakpoint MCP addon enabled in this project (it registers the runtime autoload)?`);
|
|
195
|
+
}
|
|
196
|
+
return spawned.map((e) => e.info);
|
|
197
|
+
}
|
|
198
|
+
/** Stop one peer (or all). Repeating is a no-op, so the tool is idempotent. */
|
|
199
|
+
stop(id, all = false) {
|
|
200
|
+
const targets = all ? [...this.peers.keys()] : id ? [id] : [];
|
|
201
|
+
if (!all && id && !this.peers.has(id)) {
|
|
202
|
+
const ids = this.live().map((p) => p.id);
|
|
203
|
+
throw new BridgeError("unknown_peer", `No peer with id "${id}". Live peers: ${ids.length ? ids.join(", ") : "(none)"}.`);
|
|
204
|
+
}
|
|
205
|
+
const stopped = [];
|
|
206
|
+
for (const t of targets) {
|
|
207
|
+
const e = this.peers.get(t);
|
|
208
|
+
if (!e)
|
|
209
|
+
continue;
|
|
210
|
+
try {
|
|
211
|
+
e.client.close();
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
/* ignore */
|
|
215
|
+
}
|
|
216
|
+
try {
|
|
217
|
+
this.procs.get(e.managedId)?.child.kill();
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
/* ignore */
|
|
221
|
+
}
|
|
222
|
+
e.stopped = true;
|
|
223
|
+
stopped.push(t);
|
|
224
|
+
}
|
|
225
|
+
return stopped;
|
|
226
|
+
}
|
|
227
|
+
/** Shutdown hook — kill every peer child and close every peer socket. */
|
|
228
|
+
stopAll() {
|
|
229
|
+
try {
|
|
230
|
+
this.stop(undefined, true);
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
/* ignore */
|
|
234
|
+
}
|
|
235
|
+
this.procs.killAll();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=peers.js.map
|
package/dist/recipes.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* it's **free** (MIT, shipped in the server), and it sits **over typed,
|
|
8
8
|
* schema-validated, undoable tools** — so the contract is executed by the
|
|
9
9
|
* server, not merely described in prose the model might misapply. Recipes are
|
|
10
|
-
* discoverable via MCP `prompts/list`; they add **no tools** (the
|
|
10
|
+
* discoverable via MCP `prompts/list`; they add **no tools** (the 289-tool
|
|
11
11
|
* count is unchanged) and cost nothing until a client pulls one.
|
|
12
12
|
*/
|
|
13
13
|
import { z } from "zod";
|
|
@@ -28,6 +28,7 @@ export const RECIPE_NAMES = [
|
|
|
28
28
|
"recipe_type_safe_edit",
|
|
29
29
|
"recipe_csharp_fix_and_debug",
|
|
30
30
|
"recipe_deterministic_playtest",
|
|
31
|
+
"recipe_multiplayer_scaffold_and_converge",
|
|
31
32
|
];
|
|
32
33
|
export function registerRecipes(server) {
|
|
33
34
|
// 1 — 2D player controller, then verify it moves.
|
|
@@ -196,5 +197,36 @@ export function registerRecipes(server) {
|
|
|
196
197
|
SAFETY,
|
|
197
198
|
].join("\n"));
|
|
198
199
|
});
|
|
200
|
+
// 8 — Multiplayer: scaffold it with mp_*, then prove independent peers converge.
|
|
201
|
+
server.registerPrompt("recipe_multiplayer_scaffold_and_converge", {
|
|
202
|
+
title: "Scaffold multiplayer with mp_*, then prove independent peers converge",
|
|
203
|
+
description: "Scaffold ENet + spawner / synchronizer / RPC netcode, then spawn real headless peers and assert they reach a byte-equal state — the scaffold verified rather than assumed.",
|
|
204
|
+
argsSchema: {
|
|
205
|
+
scene_path: z.string().optional().describe("Scene to scaffold and play-test (default res://main.tscn)"),
|
|
206
|
+
peer_count: z.string().optional().describe("Headless peers to spawn (1-4; default 3)"),
|
|
207
|
+
seed: z.string().optional().describe("RNG seed given to every peer (default 12345)"),
|
|
208
|
+
frames: z.string().optional().describe("Physics frames to step on each peer (default 30)"),
|
|
209
|
+
root_path: z.string().optional().describe("Node subtree to compare across peers (default '.', the running scene root)"),
|
|
210
|
+
},
|
|
211
|
+
}, (a) => {
|
|
212
|
+
const scene = str(a, "scene_path", "res://main.tscn");
|
|
213
|
+
const count = str(a, "peer_count", "3");
|
|
214
|
+
const seed = str(a, "seed", "12345");
|
|
215
|
+
const frames = str(a, "frames", "30");
|
|
216
|
+
const root = str(a, "root_path", ".");
|
|
217
|
+
return recipe("Multiplayer scaffolding with a multi-peer convergence check.", [
|
|
218
|
+
`Goal: scaffold multiplayer in ${scene} with the mp_* family, then prove ${count} independently-driven peers reach the SAME state.`,
|
|
219
|
+
"",
|
|
220
|
+
`1. Scaffold: scene_open ${scene}. mp_setup_enet_peer for the host/join script (mp_setup_webrtc_peer if you need WebRTC); mp_scaffold_lobby for a lobby; mp_add_spawner for nodes created at runtime and mp_add_synchronizer for replicated properties; mp_set_authority on the nodes each peer owns; mp_wire_rpc for the calls that cross the wire. Run gd_diagnostics until clean BEFORE running anything.`,
|
|
221
|
+
"2. Make it testable, or step 4 will diverge and be right to: keep replicated state on _physics_process (the FIXED timestep), guard every global randf() on `delta > 0`, and give idle-frame code its OWN RandomNumberGenerator. runtime_seed_rng seeds ONE stream for the whole project, and freezing does not stop callbacks firing — an unguarded draw burns that stream at wall-clock rate and desynchronises peers that are otherwise identical.",
|
|
222
|
+
`3. Spawn: runtime_spawn_peers{count:${count}} — real headless children of this project, each on its own loopback port (ceiling 4). Pass role:"server" to label one and branch on OS.get_environment("BREAKPOINT_PEER_ROLE"). It is code-execution-privileged, so it is absent from the default surface unless you enabled that capability group.`,
|
|
223
|
+
`4. Converge, IN THIS ORDER: runtime_time_scale{scale:0, peer} to FREEZE every peer first (they free-ran for different durations since spawn, so their state already differs); runtime_set_property{peer} to equalise the starting state; runtime_seed_rng{seed:${seed}, peer} with the SAME seed on each; runtime_step_frames{frames:${frames}, kind:"physics", peer} on each; then runtime_peers_digest{root:"${root}"}.`,
|
|
224
|
+
`5. Assert, then diagnose: converged:true is the green result. On false, diverged_at names the exact node paths that disagree — start there with runtime_get_property{peer} and runtime_get_log{peer} on the two peers that differ, runtime_assert_node_state for the value you expected, and dbg_set_breakpoints + dbg_launch when you need the frame it went wrong on. Finish with runtime_peer_stop{all:true}.`,
|
|
225
|
+
"",
|
|
226
|
+
"Scope, so a green result means what you think it does: peers are local headless children on loopback — this is testing, not hosting, and Breakpoint runs no relay, lobby or signalling server. Convergence is a same-machine claim (one OS, one engine build); it says nothing about two players on two machines.",
|
|
227
|
+
"",
|
|
228
|
+
SAFETY,
|
|
229
|
+
].join("\n"));
|
|
230
|
+
});
|
|
199
231
|
}
|
|
200
232
|
//# sourceMappingURL=recipes.js.map
|
package/dist/schemas.js
CHANGED
|
@@ -513,6 +513,23 @@ export const outputSchemas = {
|
|
|
513
513
|
runtime_step_frames: { frames_advanced: z.number(), frame_index: z.number() },
|
|
514
514
|
runtime_state_digest: { digest: z.record(z.record(encodedValue)), node_count: z.number() },
|
|
515
515
|
runtime_seed_rng: { seed: z.number() },
|
|
516
|
+
// F6 additions: multi-peer deterministic playtesting (spawn / stop / converge).
|
|
517
|
+
runtime_spawn_peers: {
|
|
518
|
+
peers: z.array(z.object({
|
|
519
|
+
id: z.string(),
|
|
520
|
+
port: z.number(),
|
|
521
|
+
pid: z.number().nullable(),
|
|
522
|
+
role: z.string().nullable(),
|
|
523
|
+
ready: z.boolean(),
|
|
524
|
+
})),
|
|
525
|
+
count: z.number(),
|
|
526
|
+
},
|
|
527
|
+
runtime_peer_stop: { stopped: z.array(z.string()) },
|
|
528
|
+
runtime_peers_digest: {
|
|
529
|
+
digests: z.array(z.object({ id: z.string(), digest: z.record(z.record(encodedValue)), node_count: z.number() })),
|
|
530
|
+
converged: z.boolean(),
|
|
531
|
+
diverged_at: z.array(z.string()).nullable(),
|
|
532
|
+
},
|
|
516
533
|
// ---- Group K: knowledge & search ----
|
|
517
534
|
// Host-side project index (tools/knowledge.ts) — no bridge/LSP; read the project files directly.
|
|
518
535
|
project_search: {
|
package/dist/secret.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { randomBytes } from "node:crypto";
|
|
3
4
|
/**
|
|
4
5
|
* Loopback-bridge shared secret (host side).
|
|
5
6
|
*
|
|
@@ -35,4 +36,52 @@ export function resolveBridgeSecret(projectPath, envNames) {
|
|
|
35
36
|
}
|
|
36
37
|
return readProjectSecret(projectPath);
|
|
37
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Mint the per-project secret if it does not exist yet, and return it (or the
|
|
41
|
+
* existing one). Returns null if the file can neither be read nor written — the
|
|
42
|
+
* caller then proceeds exactly as before, with the child minting its own.
|
|
43
|
+
*
|
|
44
|
+
* Why the HOST mints it, ahead of spawning peers (F6 spike, constraint 2):
|
|
45
|
+
* `BridgeSecret.load_or_mint()` in the addon is a check-then-write with no lock
|
|
46
|
+
* — `file_exists → read` ELSE `mint → write`. F6 spawns N children through one
|
|
47
|
+
* funnel, so on a COLD project every child can reach the mint branch before any
|
|
48
|
+
* of them has written. Two peers minting different secrets, each holding its own
|
|
49
|
+
* in memory while the last writer wins on disk, is a peer the host can never
|
|
50
|
+
* authenticate against — and it presents as a flaky spawn, not a clear error.
|
|
51
|
+
* Measured 6/6 clean at 3 simultaneous peers, but that is Godot's ~200 ms init
|
|
52
|
+
* versus a sub-millisecond mint, i.e. timing, not a guarantee; the window is
|
|
53
|
+
* structurally open and would surface on someone else's slower machine.
|
|
54
|
+
*
|
|
55
|
+
* Writing the file first closes it by construction: every child then takes the
|
|
56
|
+
* `file_exists` path (verified 4/4 in the spike, with the file untouched after).
|
|
57
|
+
* An EXISTING secret is never overwritten — the editor may have minted it, and
|
|
58
|
+
* all three parties must agree on one value.
|
|
59
|
+
*
|
|
60
|
+
* Format matches `addons/breakpoint_mcp/bridge_secret.gd` exactly: 32 random
|
|
61
|
+
* bytes, hex-encoded to 64 characters, at `<projectPath>/.godot/breakpoint_mcp.secret`.
|
|
62
|
+
* Note the addon's `_setup_auth()` does NOT read the env overrides — they are
|
|
63
|
+
* host-side only — so the FILE is the mechanism for a host-launched child.
|
|
64
|
+
*/
|
|
65
|
+
export function ensureProjectSecret(projectPath) {
|
|
66
|
+
const existing = readProjectSecret(projectPath);
|
|
67
|
+
if (existing)
|
|
68
|
+
return existing;
|
|
69
|
+
try {
|
|
70
|
+
const dir = path.join(projectPath, ".godot");
|
|
71
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
72
|
+
const secret = randomBytes(32).toString("hex");
|
|
73
|
+
// wx: never clobber a secret another process minted between the read above
|
|
74
|
+
// and this write — losing that race must be a no-op, not an overwrite.
|
|
75
|
+
try {
|
|
76
|
+
fs.writeFileSync(path.join(dir, "breakpoint_mcp.secret"), secret, { encoding: "utf8", flag: "wx", mode: 0o600 });
|
|
77
|
+
return secret;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return readProjectSecret(projectPath);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
38
87
|
//# sourceMappingURL=secret.js.map
|
package/dist/tools/processes.js
CHANGED
|
@@ -12,11 +12,23 @@ const LINE_CAP = 5000;
|
|
|
12
12
|
export class ProcessRegistry {
|
|
13
13
|
procs = new Map();
|
|
14
14
|
counter = 0;
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Spawn a managed Godot child. `env` is an OVERLAY on the inherited
|
|
17
|
+
* environment, not a replacement: omitted (the `godot_run_managed` path) the
|
|
18
|
+
* child inherits exactly as before, byte-identical to pre-F6 behaviour.
|
|
19
|
+
*
|
|
20
|
+
* The overlay is what makes multi-peer work at all — the runtime autoload
|
|
21
|
+
* reads `BREAKPOINT_RUNTIME_PORT` from its environment
|
|
22
|
+
* (`runtime_bridge.gd:74`), so N addressable peers is a per-child env
|
|
23
|
+
* passthrough plus a port allocator, with no protocol, transport or handshake
|
|
24
|
+
* change. See `peers.ts`.
|
|
25
|
+
*/
|
|
26
|
+
run(cfg, extraArgs, env) {
|
|
16
27
|
const id = `godot-${++this.counter}`;
|
|
17
28
|
const child = spawn(cfg.godotBin, ["--path", cfg.projectPath, ...extraArgs], {
|
|
18
29
|
cwd: cfg.projectPath,
|
|
19
30
|
stdio: ["ignore", "pipe", "pipe"],
|
|
31
|
+
...(env ? { env: { ...process.env, ...env } } : {}),
|
|
20
32
|
});
|
|
21
33
|
const m = { id, child, lines: [], seq: 0, exited: false, exitCode: null };
|
|
22
34
|
const ingest = (stream) => (buf) => {
|
|
@@ -43,6 +55,18 @@ export class ProcessRegistry {
|
|
|
43
55
|
get(id) {
|
|
44
56
|
return this.procs.get(id);
|
|
45
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* The last `n` captured lines for a managed child, newest last. Used to
|
|
60
|
+
* explain a peer that never bound its port — a project that fails to load
|
|
61
|
+
* dies with the reason on stderr, and without this the caller only ever sees
|
|
62
|
+
* "cannot reach the runtime bridge".
|
|
63
|
+
*/
|
|
64
|
+
tail(id, n = 12) {
|
|
65
|
+
const m = this.procs.get(id);
|
|
66
|
+
if (!m)
|
|
67
|
+
return [];
|
|
68
|
+
return m.lines.slice(-n).map((l) => l.text);
|
|
69
|
+
}
|
|
46
70
|
killAll() {
|
|
47
71
|
for (const m of this.procs.values()) {
|
|
48
72
|
try {
|