gdharness 1.1.22 → 1.1.23

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/build/index.js CHANGED
@@ -10058,23 +10058,24 @@ function sameCodeNote(addonVersion, serverVersion, addonDigest, shippedDigest) {
10058
10058
  }
10059
10059
  return `The editor loaded the ${addonVersion} addons, which are the same code this ${serverVersion} server ships, so nothing needs restarting; addonVersion changes at the next editor start.`;
10060
10060
  }
10061
- function addonMismatch(addonVersion, serverVersion, addonDigest, shippedDigest) {
10061
+ function addonMismatch(addonVersion, serverVersion, addonDigest, shippedDigest, onDisk) {
10062
10062
  if (!editorIsStale(addonVersion, serverVersion, addonDigest, shippedDigest)) {
10063
10063
  return;
10064
10064
  }
10065
10065
  const reported = addonVersion ?? "";
10066
+ const restart = onDisk !== undefined && onDisk !== shippedDigest ? `The project's own addons are not this server's either, so a restart would load the same code again: gdharness upgrade in the project installs the ${serverVersion} addons, and editor_launch restart then picks them up.` : "Restart it with editor_launch restart to pick this one up.";
10066
10067
  if (reported === serverVersion) {
10067
- return `The editor is running a different build of the ${reported} addon from the one this server ships. Restart it with editor_launch restart to pick this one up.`;
10068
+ return `The editor is running a different build of the ${reported} addon from the one this server ships. ${restart}`;
10068
10069
  }
10069
10070
  const editor = reported === "" ? UNVERSIONED : `the ${reported} addon`;
10070
10071
  const both = `The editor is running ${editor} while this server ships ${serverVersion}.`;
10071
10072
  if (reported !== "" && isNewer(reported, serverVersion)) {
10072
10073
  return `${both} This server is the older half: reconnect it in your harness so it spawns ${reported}.`;
10073
10074
  }
10074
- return `${both} Restart it with editor_launch restart to pick the new one up.`;
10075
+ return `${both} ${restart}`;
10075
10076
  }
10076
- function markIfStale(answer, addonVersion, serverVersion, addonDigest, shippedDigest) {
10077
- const staleNote = addonMismatch(addonVersion, serverVersion, addonDigest, shippedDigest);
10077
+ function markIfStale(answer, addonVersion, serverVersion, addonDigest, shippedDigest, onDisk) {
10078
+ const staleNote = addonMismatch(addonVersion, serverVersion, addonDigest, shippedDigest, onDisk);
10078
10079
  if (staleNote === undefined || typeof answer !== "object" || answer === null || Array.isArray(answer)) {
10079
10080
  return answer;
10080
10081
  }
@@ -24863,6 +24864,7 @@ function editorArguments(projectPath, ports, logFile, hidden) {
24863
24864
  ];
24864
24865
  }
24865
24866
  var OPENED_BY_A_SERVER = "GDHARNESS_OPENED_BY_A_SERVER";
24867
+ var EDITOR_PID_VARIABLE = "GDHARNESS_EDITOR_PID";
24866
24868
  function userDataIn(home, variables = process.env) {
24867
24869
  const moved = ["APPDATA", "XDG_DATA_HOME"];
24868
24870
  const carried = {};
@@ -25463,6 +25465,12 @@ function parseAnnouncement(file, pid) {
25463
25465
  }
25464
25466
  };
25465
25467
  }
25468
+ function dialAddress(address) {
25469
+ if (address === "*" || address === "0.0.0.0") {
25470
+ return "127.0.0.1";
25471
+ }
25472
+ return address === "::" ? "::1" : address;
25473
+ }
25466
25474
  function runtimesAnnounced(directories = runtimeDirectories()) {
25467
25475
  const running = new Map;
25468
25476
  const unspoken = new Map;
@@ -25767,7 +25775,7 @@ function runtimeRequest(endpoint, command, params, timeoutMs, keepListening = fa
25767
25775
  let late = false;
25768
25776
  let buffered = "";
25769
25777
  let welcomed = false;
25770
- const socket = createConnection({ port: endpoint.port, host: endpoint.address });
25778
+ const socket = createConnection({ port: endpoint.port, host: dialAddress(endpoint.address) });
25771
25779
  let lateTimer = null;
25772
25780
  const finish = (reply) => {
25773
25781
  if (late) {
@@ -27642,7 +27650,10 @@ function mayYetConnect(listeningSince, now = Date.now()) {
27642
27650
  return listeningSince === undefined || now - listeningSince.getTime() < CONNECT_WINDOW_MS;
27643
27651
  }
27644
27652
  function theEditorHasComeBack(status, startedAt) {
27645
- return status.connected && (status.connectedAt?.getTime() ?? 0) > startedAt && status.addonVersion !== undefined;
27653
+ return hasSaidWhoItIs(status) && (status.connectedAt?.getTime() ?? 0) > startedAt;
27654
+ }
27655
+ function hasSaidWhoItIs(status) {
27656
+ return status.connected && status.addonVersion !== undefined;
27646
27657
  }
27647
27658
  function anEditorIsStillComing(listeningSince, launchedEditorIsAlive, now = Date.now()) {
27648
27659
  return mayYetConnect(listeningSince, now) || launchedEditorIsAlive;
@@ -27792,6 +27803,7 @@ class GodotBridge extends EventEmitter {
27792
27803
  dapPort: this.connectionInfo?.dapPort,
27793
27804
  debugPort: this.connectionInfo?.debugPort,
27794
27805
  openedByAServer: this.connectionInfo?.openedByAServer,
27806
+ startedByAnEditor: this.connectionInfo?.startedByAnEditor,
27795
27807
  syncsBreakpoints: this.connectionInfo?.syncsBreakpoints,
27796
27808
  pendingRequests: this.pendingRequests.size,
27797
27809
  queuedResources: this.resourceQueues.size,
@@ -27937,6 +27949,7 @@ class GodotBridge extends EventEmitter {
27937
27949
  this.connectionInfo.dapPort = servedPort(message.dap_port);
27938
27950
  this.connectionInfo.debugPort = servedPort(message.debug_port);
27939
27951
  this.connectionInfo.openedByAServer = message.opened_by_a_server === true;
27952
+ this.connectionInfo.startedByAnEditor = typeof message.started_by_an_editor === "boolean" ? message.started_by_an_editor : undefined;
27940
27953
  this.connectionInfo.syncsBreakpoints = typeof message.syncs_breakpoints === "boolean" ? message.syncs_breakpoints : undefined;
27941
27954
  this.log("info", `Godot ready: ${message.project_path}`);
27942
27955
  this.emitBridgeEvent("godot_connected", { projectPath: message.project_path });
@@ -28794,6 +28807,7 @@ function parseJUnit(xml) {
28794
28807
  const cases = suite.children.filter((child) => child.name === "testcase").map((element) => caseOf(suite, element));
28795
28808
  const failures = cases.filter((entry) => entry.status === "failed").length;
28796
28809
  const errors = cases.filter((entry) => entry.status === "error").length;
28810
+ const written = (kind) => suite.children.filter((child) => child.name === "testcase").reduce((sum, element) => sum + element.children.filter((child) => child.name === kind).length, 0);
28797
28811
  return {
28798
28812
  name: suite.attributes["name"] ?? "",
28799
28813
  path: pathOf(suite),
@@ -28801,8 +28815,8 @@ function parseJUnit(xml) {
28801
28815
  discovered: count(suite.attributes, "tests"),
28802
28816
  failures,
28803
28817
  errors,
28804
- hookFailures: Math.max(0, count(suite.attributes, "failures") - failures),
28805
- hookErrors: Math.max(0, count(suite.attributes, "errors") - errors),
28818
+ hookFailures: Math.max(0, count(suite.attributes, "failures") - written("failure")),
28819
+ hookErrors: Math.max(0, count(suite.attributes, "errors") - written("error")),
28806
28820
  skipped: cases.filter((entry) => entry.status === "skipped").length,
28807
28821
  time: count(suite.attributes, "time"),
28808
28822
  cases
@@ -29687,7 +29701,37 @@ function skipped(name) {
29687
29701
  function steppedOver(directory) {
29688
29702
  return existsSync12(join15(directory, ".gdignore"));
29689
29703
  }
29690
- var ASSET_EXTENSIONS = new Set(["png", "jpg", "jpeg", "webp", "svg", "ttf", "otf", "wav", "mp3", "ogg"]);
29704
+ var SCENE_EXTENSIONS = new Set(["tscn", "scn"]);
29705
+ var ASSET_EXTENSIONS = new Set([
29706
+ "png",
29707
+ "jpg",
29708
+ "jpeg",
29709
+ "webp",
29710
+ "svg",
29711
+ "bmp",
29712
+ "tga",
29713
+ "exr",
29714
+ "hdr",
29715
+ "ktx",
29716
+ "dds",
29717
+ "ttf",
29718
+ "otf",
29719
+ "woff",
29720
+ "woff2",
29721
+ "fnt",
29722
+ "wav",
29723
+ "mp3",
29724
+ "ogg",
29725
+ "glb",
29726
+ "gltf",
29727
+ "obj",
29728
+ "fbx",
29729
+ "blend",
29730
+ "dae",
29731
+ "ogv",
29732
+ "gdshader",
29733
+ "shader"
29734
+ ]);
29691
29735
  function projectStructure(projectPath) {
29692
29736
  const structure = { scenes: 0, scripts: 0, assets: 0, other: 0 };
29693
29737
  const visit = (directory) => {
@@ -29702,7 +29746,7 @@ function projectStructure(projectPath) {
29702
29746
  visit(join15(directory, entry.name));
29703
29747
  } else if (entry.isFile()) {
29704
29748
  const extension = entry.name.split(".").pop()?.toLowerCase() ?? "";
29705
- if (extension === "tscn") {
29749
+ if (SCENE_EXTENSIONS.has(extension)) {
29706
29750
  structure.scenes += 1;
29707
29751
  } else if (extension === "gd" || extension === "cs") {
29708
29752
  structure.scripts += 1;
@@ -29745,8 +29789,11 @@ function scriptsWithoutUid(projectPath) {
29745
29789
  visit(projectPath, "");
29746
29790
  return found.sort();
29747
29791
  }
29792
+ function isBinary(bytes) {
29793
+ return bytes.subarray(0, 8000).includes(0);
29794
+ }
29748
29795
  function searchProject(projectPath, options) {
29749
- const extensions = new Set(options.fileTypes.map((ext) => ext.replace(/^\./, "").toLowerCase()).filter(Boolean));
29796
+ const extensions = options.fileTypes === undefined ? null : new Set(options.fileTypes.map((ext) => ext.replace(/^\./, "").toLowerCase()).filter(Boolean));
29750
29797
  const result = {
29751
29798
  query: options.query,
29752
29799
  results: [],
@@ -29754,13 +29801,7 @@ function searchProject(projectPath, options) {
29754
29801
  };
29755
29802
  const regex = options.regex ? new RegExp(options.query, options.caseSensitive ? "" : "i") : null;
29756
29803
  const needle = options.caseSensitive ? options.query : options.query.toLowerCase();
29757
- const full = () => {
29758
- if (result.summary.total_matches >= options.maxResults) {
29759
- result.summary.truncated = true;
29760
- return true;
29761
- }
29762
- return false;
29763
- };
29804
+ const full = () => result.summary.truncated;
29764
29805
  const visit = (directory) => {
29765
29806
  if (steppedOver(directory)) {
29766
29807
  return;
@@ -29778,21 +29819,26 @@ function searchProject(projectPath, options) {
29778
29819
  continue;
29779
29820
  }
29780
29821
  const extension = entry.name.includes(".") ? entry.name.split(".").pop()?.toLowerCase() ?? "" : "";
29781
- if (!entry.isFile() || !extensions.has(extension)) {
29822
+ if (!entry.isFile() || extensions !== null && !extensions.has(extension)) {
29823
+ continue;
29824
+ }
29825
+ const bytes = readFileSync13(entryPath);
29826
+ if (extensions === null && isBinary(bytes)) {
29782
29827
  continue;
29783
29828
  }
29784
29829
  result.summary.files_searched += 1;
29785
29830
  const matches = [];
29786
- for (const [index, line] of readFileSync13(entryPath, "utf8").split(`
29787
- `).entries()) {
29788
- if (full()) {
29789
- break;
29831
+ for (const [index, line] of bytes.toString("utf8").split(/\r?\n/).entries()) {
29832
+ const found = regex ? regex.exec(line) : (options.caseSensitive ? line : line.toLowerCase()).includes(needle) ? [options.query] : null;
29833
+ if (found === null) {
29834
+ continue;
29790
29835
  }
29791
- const match = regex ? regex.exec(line)?.[0] : (options.caseSensitive ? line : line.toLowerCase()).includes(needle) ? options.query : "";
29792
- if (match) {
29793
- matches.push({ line: index + 1, content: line.trim(), match });
29794
- result.summary.total_matches += 1;
29836
+ if (result.summary.total_matches >= options.maxResults) {
29837
+ result.summary.truncated = true;
29838
+ break;
29795
29839
  }
29840
+ matches.push({ line: index + 1, content: line.trim(), match: found[0] ?? "" });
29841
+ result.summary.total_matches += 1;
29796
29842
  }
29797
29843
  if (matches.length > 0) {
29798
29844
  const relativePath = entryPath.slice(projectPath.length + 1).replace(/\\/g, "/");
@@ -29806,7 +29852,7 @@ function searchProject(projectPath, options) {
29806
29852
  }
29807
29853
 
29808
29854
  // src/resources.ts
29809
- import { readFileSync as readFileSync14 } from "node:fs";
29855
+ import { readFileSync as readFileSync14, realpathSync as realpathSync4 } from "node:fs";
29810
29856
  import { extname, resolve as resolve4 } from "node:path";
29811
29857
  var STATIC_RESOURCES = [
29812
29858
  {
@@ -29840,7 +29886,7 @@ var RESOURCE_COUNT = STATIC_RESOURCES.length + RESOURCE_TEMPLATES.length;
29840
29886
  function ensureProjectPath(getProjectPath) {
29841
29887
  const projectPath = getProjectPath();
29842
29888
  if (!projectPath) {
29843
- throw new Refusal("Project path is not set. Set a Godot project path first.");
29889
+ throw new Refusal("This server knows no project to read from: start it with GDHARNESS_PROJECT, connect an editor, or make any tool call naming a projectPath that holds project.godot.");
29844
29890
  }
29845
29891
  return resolve4(projectPath);
29846
29892
  }
@@ -29856,7 +29902,22 @@ function resolveProjectFile(projectPath, resourcePath) {
29856
29902
  if (!contained.ok) {
29857
29903
  throw new Refusal(contained.reason);
29858
29904
  }
29859
- return contained.absolutePath;
29905
+ let root;
29906
+ try {
29907
+ root = realpathSync4.native(projectPath);
29908
+ } catch {
29909
+ throw new Refusal(`The project directory ${projectPath} is not there.`);
29910
+ }
29911
+ let real;
29912
+ try {
29913
+ real = realpathSync4.native(contained.absolutePath);
29914
+ } catch {
29915
+ throw new Refusal(`No file at ${resourcePath} in the project.`);
29916
+ }
29917
+ if (!isWithinRoot(root, real)) {
29918
+ throw new Refusal(`${resourcePath} leads outside the project through a link, so it is not read.`);
29919
+ }
29920
+ return real;
29860
29921
  }
29861
29922
  function parseGodotUri(uri) {
29862
29923
  if (uri === "godot://project/info") {
@@ -30093,7 +30154,7 @@ import {
30093
30154
  openSync as openSync2,
30094
30155
  readdirSync as readdirSync6,
30095
30156
  readFileSync as readFileSync16,
30096
- realpathSync as realpathSync4,
30157
+ realpathSync as realpathSync5,
30097
30158
  rmSync as rmSync7,
30098
30159
  statSync as statSync6,
30099
30160
  writeFileSync as writeFileSync10
@@ -30109,7 +30170,7 @@ function realAsFarAsItExists(path) {
30109
30170
  let at = path;
30110
30171
  for (;; ) {
30111
30172
  try {
30112
- return join17(realpathSync4.native(at), ...missing);
30173
+ return join17(realpathSync5.native(at), ...missing);
30113
30174
  } catch {
30114
30175
  const parent = dirname10(at);
30115
30176
  if (parent === at) {
@@ -30229,7 +30290,9 @@ function recordAt(path) {
30229
30290
  pid,
30230
30291
  transcript,
30231
30292
  startedAt,
30293
+ ...typeof fields["startedBy"] === "number" ? { startedBy: fields["startedBy"] } : {},
30232
30294
  projectPath: typeof fields["projectPath"] === "string" ? fields["projectPath"] : "",
30295
+ ...typeof fields["servedBy"] === "string" && fields["servedBy"] !== "" ? { servedBy: fields["servedBy"] } : {},
30233
30296
  arguments: Array.isArray(args) ? args.filter((value) => typeof value === "string") : [],
30234
30297
  ...typeof fields["command"] === "string" ? { command: fields["command"] } : {},
30235
30298
  ...typeof fields["exitCode"] === "number" ? { exitCode: fields["exitCode"] } : {},
@@ -30238,7 +30301,8 @@ function recordAt(path) {
30238
30301
  }
30239
30302
  async function runningAs(pid) {
30240
30303
  if (process.platform === "win32") {
30241
- const answer = await windowsCommandLine(pid);
30304
+ const read = await readWindowsCommandLine(pid);
30305
+ const answer = "answer" in read ? read.answer : null;
30242
30306
  if (answer !== null) {
30243
30307
  const [, ...rest] = answer.split(`
30244
30308
  `);
@@ -30250,7 +30314,11 @@ async function runningAs(pid) {
30250
30314
  }
30251
30315
  }
30252
30316
  const image = await windowsImage(pid);
30253
- return image === null ? null : { kind: "image", text: image };
30317
+ return image === null ? null : {
30318
+ kind: "image",
30319
+ text: image,
30320
+ unread: "unread" in read ? read.unread : "Windows gave an empty command line"
30321
+ };
30254
30322
  }
30255
30323
  try {
30256
30324
  const began = await startedAt(pid, null);
@@ -30301,13 +30369,18 @@ function listeningPidInNetstat(printed, port) {
30301
30369
  }
30302
30370
  return null;
30303
30371
  }
30304
- async function windowsCommandLine(pid) {
30305
- try {
30306
- const answer = (await askWindows(`$p = Get-CimInstance Win32_Process -Filter "ProcessId=${pid}"; if ($p) { $p.CreationDate.ToUniversalTime().ToString("o"); $p.CommandLine }`, 15000)).trim();
30307
- return answer === "" ? null : answer;
30308
- } catch {
30309
- return null;
30372
+ async function readWindowsCommandLine(pid, ask = askWindows) {
30373
+ const query = `$p = Get-CimInstance Win32_Process -Filter "ProcessId=${pid}"; if ($p) { $p.CreationDate.ToUniversalTime().ToString("o"); $p.CommandLine }`;
30374
+ let unread = "";
30375
+ for (const withinMs of [15000, 45000]) {
30376
+ try {
30377
+ const answer = (await ask(query, withinMs)).trim();
30378
+ return answer === "" ? { unread: "Windows gave no command line for it" } : { answer };
30379
+ } catch (error) {
30380
+ unread = errorMessage(error);
30381
+ }
30310
30382
  }
30383
+ return { unread };
30311
30384
  }
30312
30385
  async function startedAt(pid, windowsAnswer) {
30313
30386
  if (process.platform === "win32") {
@@ -30335,37 +30408,44 @@ async function windowsImage(pid) {
30335
30408
  return null;
30336
30409
  }
30337
30410
  }
30338
- async function stillTheRecordedRun(record) {
30339
- return judgeRun(record, await runningAs(record.pid), "confirmed");
30411
+ async function whyNotStillTheRecordedRun(record) {
30412
+ return whyNotTheRun(record, await runningAs(record.pid), "confirmed");
30340
30413
  }
30341
30414
  async function couldStillBeTheRecordedRun(record) {
30342
30415
  return judgeRun(record, await runningAs(record.pid), "possible");
30343
30416
  }
30344
30417
  var SAME_RUN_WINDOW_MS = 1e4;
30345
30418
  function judgeRun(record, running, needed) {
30419
+ return whyNotTheRun(record, running, needed) === null;
30420
+ }
30421
+ function whyNotTheRun(record, running, needed) {
30346
30422
  if (running === null) {
30347
- return false;
30423
+ return "the operating system would not describe that process";
30348
30424
  }
30349
- if (running.startedAt !== undefined && running.startedAt - record.startedAt > SAME_RUN_WINDOW_MS) {
30350
- return false;
30425
+ const after = running.startedAt === undefined ? 0 : running.startedAt - (record.startedBy ?? record.startedAt);
30426
+ if (after > SAME_RUN_WINDOW_MS) {
30427
+ return `that process started ${Math.round(after / 1000)} seconds after the run had`;
30351
30428
  }
30352
30429
  const engine = record.command === undefined ? null : basename3(record.command);
30353
30430
  const said = process.platform === "win32" ? running.text.toLowerCase() : running.text;
30354
30431
  const wanted = engine === null || process.platform !== "win32" ? engine : engine.toLowerCase();
30355
30432
  if (wanted !== null && !said.includes(wanted)) {
30356
- return false;
30433
+ return `that process is not ${engine ?? "the engine"}, which the run was started with`;
30357
30434
  }
30358
30435
  if (running.kind === "commandLine" && readCommandLine(running.text).editor) {
30359
- return false;
30436
+ return "that process is an editor";
30360
30437
  }
30361
30438
  if (record.projectPath === "") {
30362
- return wanted !== null;
30439
+ return wanted !== null ? null : "the record names neither the project nor the engine";
30363
30440
  }
30364
30441
  if (running.kind === "image") {
30365
- return needed === "possible" && wanted !== null;
30442
+ if (wanted === null) {
30443
+ return "the operating system named only its executable, and the record names no engine";
30444
+ }
30445
+ return needed === "possible" ? null : `the operating system named only its executable and not its command line (${running.unread ?? "no reason given"}), which is not enough to signal it on`;
30366
30446
  }
30367
30447
  const project = process.platform === "win32" ? record.projectPath.toLowerCase() : record.projectPath;
30368
- return said.includes(project);
30448
+ return said.includes(project) ? null : `that process's command line does not name ${record.projectPath}`;
30369
30449
  }
30370
30450
  async function stillTheAnnouncedGame(pid, projectPath, announcedAt) {
30371
30451
  return judgeAnnouncedGame(await runningAs(pid), projectPath, announcedAt);
@@ -30426,6 +30506,7 @@ function sweepTranscripts(keepMs = 24 * 60 * 60 * 1000, now = Date.now()) {
30426
30506
  }
30427
30507
 
30428
30508
  // src/setup.ts
30509
+ import { spawnSync } from "node:child_process";
30429
30510
  import { createHash as createHash4 } from "node:crypto";
30430
30511
  import {
30431
30512
  cpSync,
@@ -30484,6 +30565,14 @@ function shippedEditorDigest() {
30484
30565
  }
30485
30566
  return shippedDigest ?? undefined;
30486
30567
  }
30568
+ function installedEditorDigest(projectPath) {
30569
+ const marker = join18(projectPath, "addons", ADDONS[0], DIGEST_MARKER);
30570
+ if (!existsSync13(marker)) {
30571
+ return null;
30572
+ }
30573
+ const said = readFileSync17(marker, "utf8").trim();
30574
+ return said === "" ? null : said;
30575
+ }
30487
30576
  function shippedAddonsDirectory() {
30488
30577
  return join18(dirname11(fileURLToPath3(import.meta.url)), "godot", "addons");
30489
30578
  }
@@ -30495,6 +30584,113 @@ function installedAddonVersion(projectPath) {
30495
30584
  const said = readFileSync17(marker, "utf8").trim();
30496
30585
  return said === "" ? null : said;
30497
30586
  }
30587
+ function loaderAmong(projectPath, named) {
30588
+ let byName = null;
30589
+ for (const [entry, path] of named) {
30590
+ if (entry === RUNTIME_AUTOLOAD.name || path === RUNTIME_AUTOLOAD.path) {
30591
+ continue;
30592
+ }
30593
+ let source = null;
30594
+ try {
30595
+ source = readFileSync17(join18(projectPath, path), "utf8");
30596
+ } catch {}
30597
+ if (source?.includes(RUNTIME_AUTOLOAD.path)) {
30598
+ return { name: entry, path, exists: true };
30599
+ }
30600
+ byName ??= path.toLowerCase().includes("gdharness") ? { name: entry, path, exists: source !== null } : null;
30601
+ }
30602
+ return byName;
30603
+ }
30604
+ function autoloadPaths(settings) {
30605
+ const named = new Map;
30606
+ for (const [name, value] of Object.entries(settings["autoload"] ?? {})) {
30607
+ const said = typeof value === "string" ? value.replace(/^\*/, "") : "";
30608
+ if (said.startsWith("res://")) {
30609
+ named.set(name, said.slice("res://".length));
30610
+ }
30611
+ }
30612
+ return named;
30613
+ }
30614
+ function trackedByGit(projectPath, wanted) {
30615
+ if (wanted.length === 0) {
30616
+ return new Set;
30617
+ }
30618
+ const asked = spawnSync("git", ["ls-files", "-z", "--", ...wanted], {
30619
+ cwd: projectPath,
30620
+ encoding: "utf8"
30621
+ });
30622
+ if (asked.status !== 0) {
30623
+ return null;
30624
+ }
30625
+ return new Set(asked.stdout.split("\x00").filter(Boolean));
30626
+ }
30627
+ function enabledPlugins(settings) {
30628
+ const raw = settings["editor_plugins"]?.["enabled"];
30629
+ if (typeof raw !== "string") {
30630
+ return [];
30631
+ }
30632
+ return [...raw.matchAll(/res:\/\/addons\/([^/"]+)\/plugin\.cfg/g)].map((match) => match[1] ?? "").filter(Boolean);
30633
+ }
30634
+ function inspectProject(projectPath) {
30635
+ const problems = [];
30636
+ const addons = ADDONS.map((name) => {
30637
+ const directory = join18(projectPath, "addons", name);
30638
+ const marker = join18(directory, VERSION_MARKER);
30639
+ const installed = existsSync13(directory);
30640
+ const version = existsSync13(marker) ? readFileSync17(marker, "utf8").trim() : null;
30641
+ const current = version === SERVER_VERSION;
30642
+ if (!installed) {
30643
+ problems.push(`addons/${name} is not installed; run gdharness setup`);
30644
+ } else if (!current) {
30645
+ problems.push(`addons/${name} is ${version ?? "of an unknown version"}, this gdharness is ${SERVER_VERSION}; run gdharness setup`);
30646
+ }
30647
+ return { name, installed, version, current };
30648
+ });
30649
+ const settings = parseProjectGodot(readFileSync17(join18(projectPath, "project.godot"), "utf8"));
30650
+ const pluginsEnabled = enabledPlugins(settings);
30651
+ for (const name of EDITOR_PLUGINS) {
30652
+ if (!pluginsEnabled.includes(name)) {
30653
+ problems.push(`the ${name} plugin is not enabled in project.godot; run gdharness setup`);
30654
+ }
30655
+ }
30656
+ const autoload = settings["autoload"];
30657
+ const registered = autoload === undefined ? undefined : readString(autoload, RUNTIME_AUTOLOAD.name);
30658
+ const runtimeAutoloadPath = typeof registered === "string" ? registered.replace(/^\*/, "") : null;
30659
+ const named = autoloadPaths(settings);
30660
+ const runtimeLoaderAutoload = loaderAmong(projectPath, named);
30661
+ const runtimeAutoload = runtimeAutoloadPath !== null || runtimeLoaderAutoload !== null;
30662
+ const tracked = trackedByGit(projectPath, [...named.values()]);
30663
+ const addonMissing = (path) => addons.some((addon) => !addon.installed && path.startsWith(`addons/${addon.name}/`));
30664
+ for (const [name, path] of named) {
30665
+ if (!existsSync13(join18(projectPath, path))) {
30666
+ if (!addonMissing(path)) {
30667
+ problems.push(`the ${name} autoload names res://${path}, which is not in this project, so it boots with a missing script; restore that file, or point the autoload at one that is here`);
30668
+ }
30669
+ continue;
30670
+ }
30671
+ if (tracked !== null && !tracked.has(path)) {
30672
+ problems.push(`the ${name} autoload names res://${path}, which git does not carry, so a clone boots with a missing script; commit that file, or point the autoload at one the project tracks`);
30673
+ }
30674
+ }
30675
+ const cached = cachedClasses(projectPath);
30676
+ const staleClasses = cached === null ? [] : staleAgainst(cached, projectPath);
30677
+ if (cached === null) {
30678
+ problems.push("no .godot/global_script_class_cache.cfg: the engine knows no class_name; run project_import refresh_classes or open the editor");
30679
+ } else if (staleClasses.length > 0) {
30680
+ problems.push(`the class cache does not list ${staleClasses.join(", ")}; run project_import refresh_classes or gdharness classes`);
30681
+ }
30682
+ return {
30683
+ projectPath,
30684
+ addons,
30685
+ pluginsEnabled,
30686
+ runtimeAutoload,
30687
+ runtimeAutoloadPath,
30688
+ runtimeLoaderAutoload,
30689
+ staleClasses,
30690
+ classCacheExists: cached !== null,
30691
+ problems
30692
+ };
30693
+ }
30498
30694
 
30499
30695
  // src/tool-definitions.ts
30500
30696
  var PROJECT_INFO_SECTIONS = [
@@ -31153,13 +31349,13 @@ var TOOL_SPECS = [
31153
31349
  },
31154
31350
  {
31155
31351
  name: "editor_launch",
31156
- description: "Opens the Godot editor on a project, or restarts the one already connected. The editor is an ordinary visible one on the desktop in use, and on Windows it is shown without being activated, so opening or reopening it does not take the keyboard from whatever the user is typing in. hidden: true opens it headless instead and, on Windows, on a desktop of its own, where the games it plays go too; a hidden editor serves the bridge, the language server and the debug adapter as a visible one does. A game a visible editor plays opens as a window on the desktop in use. An editor goes on serving the addon it read at startup, so restart is what puts a gdharness upgrade into effect, and nothing else here restarts one; it saves open scenes on the way out and answers with the version that came back. An editor a server opened is started again by the server, visible unless hidden: true is passed again. One opened by hand restarts itself, which only one with a window can do, because the engine hands back none of the arguments it was started with. editor_status says which editor is connected and whether it is holding an old addon. Opening a project is a save and so is closing one, which is the part that is not obvious from outside: the editor imports the project on open and writes project.godot back, and Godot writes only what differs from its own defaults, so a key named deliberately at its default value is dropped either way. A restart says which under settingsDropped in its own answer because it waits for the editor to return. An open cannot, since it answers as soon as the process exists and the save happens during the import minutes later, so editor_status carries that reading once the editor has connected. Nothing else will say a key went until something depends on one. A restart of an editor this server opened is a quit and then a launch, and this server can be ended between them, usually by the reconnect the restart was being taken for: the editor is gone and nothing replaces it. That is written down before the quit, so the next server says so under restartInterrupted in editor_status rather than waiting for an editor that is not coming, and open finishes it, saying so under finishesRestart.",
31352
+ description: "Opens the Godot editor on a project, or restarts the one already connected. The editor is an ordinary visible one on the desktop in use, and on Windows it is shown without being activated, so opening or reopening it does not take the keyboard from whatever the user is typing in. hidden: true opens it headless instead and, on Windows, on a desktop of its own, where the games it plays go too; a hidden editor serves the bridge, the language server and the debug adapter as a visible one does. A game a visible editor plays opens as a window on the desktop in use. An editor goes on serving the addon it read at startup, so restart is what puts a gdharness upgrade into effect, and nothing else here restarts one; it saves open scenes on the way out and answers with the version that came back. An editor a server opened is started again by the server, visible unless hidden: true is passed again, once the old one has gone: it waits 90 seconds for that, or GDHARNESS_EDITOR_RESTART_TIMEOUT_MS, and an old editor still running after it is not replaced, since the new one would find its ports held. One opened by hand restarts itself, which only one with a window can do, because the engine hands back none of the arguments it was started with. editor_status says which editor is connected and whether it is holding an old addon. Opening a project is a save and so is closing one, which is the part that is not obvious from outside: the editor imports the project on open and writes project.godot back, and Godot writes only what differs from its own defaults, so a key named deliberately at its default value is dropped either way. A restart says which under settingsDropped in its own answer because it waits for the editor to return. An open cannot, since it answers as soon as the process exists and the save happens during the import minutes later, so editor_status carries that reading once the editor has connected. Nothing else will say a key went until something depends on one. A restart of an editor this server opened is a quit and then a launch, and this server can be ended between them, usually by the reconnect the restart was being taken for: the editor is gone and nothing replaces it. That is written down before the quit, so the next server says so under restartInterrupted in editor_status rather than waiting for an editor that is not coming, and open finishes it, saying so under finishesRestart. An open is refused when the editor it would start could never reach this server: a project other than the one this server serves, whose editor dials that project's own server; a project without the gdharness editor addon installed and enabled; and a project whose editor a restart is already bringing back.",
31157
31353
  parameters: {
31158
31354
  projectPath: { ...PROJECT_PATH, ops: ["open"] },
31159
31355
  hidden: {
31160
31356
  type: "boolean",
31161
31357
  ops: ["open", "restart"],
31162
- description: "Open the editor headless and, on Windows, on a desktop of its own, so no window of it or of the games it plays appears. Default false: one visible editor, shown without taking the focus."
31358
+ description: "Open the editor headless and, on Windows, on a desktop of its own, so no window of it or of the games it plays appears. Default false: one visible editor, shown without taking the focus. On restart only for an editor a server opened; one opened by hand comes back as it was, so hidden is refused there."
31163
31359
  }
31164
31360
  },
31165
31361
  requires: [],
@@ -31247,7 +31443,7 @@ var TOOL_SPECS = [
31247
31443
  requires: ["projectPath"]
31248
31444
  },
31249
31445
  stop: {
31250
- summary: "end the run and answer with what it printed last, naming the process ended under endedPid: for a run the editor plays, the number its game announced under, read at the stop rather than remembered, and the operating system hands a freed number to the next process, so it can equal the game before it. A game that started processes of its own keeps them unless andChildren says to end those too. stopped is false, with the number under notSignalled, when that number no longer answers as the process the run was started as and nothing was signalled",
31446
+ summary: "end the run and answer with what it printed last, naming the process ended under endedPid: for a run the editor plays, the number its game announced under, read at the stop rather than remembered, and the operating system hands a freed number to the next process, so it can equal the game before it. A game that started processes of its own keeps them unless andChildren says to end those too. stopped is false, with the number under notSignalled, when that number no longer answers as the process the run was started as and nothing was signalled, and false with the number under stillGoing when what was told to end was still running ten seconds later",
31251
31447
  requires: []
31252
31448
  },
31253
31449
  check: {
@@ -31308,7 +31504,7 @@ var TOOL_SPECS = [
31308
31504
  },
31309
31505
  {
31310
31506
  name: "editor_status",
31311
- description: "Whether the editor addon is connected, which Godot answers, whether the editor is playing something, and whether a game with the runtime addon is reachable: runtimeConnected counts the games of the project this server serves, and runtimes lists every game on the machine with ofThisProject saying which is which, since a game of another project is reached only by naming its projectPath. playingInEditor is null when the editor was not asked or did not answer, which is not the same as a no: with no editor connected there is nobody to ask, and an editor that does not serve the question is given a moment and then left. A game can be playing while this is null, so read it as unanswered rather than as nothing playing, and use processActive and runtimes, which come from elsewhere and do not depend on the editor answering. editor.scan says whether the editor is scanning or importing and how many milliseconds ago its last scan finished (finishedMsAgo), or is null when it did not answer: the editor rewrites the class cache just after a scan, and editor_run waits that out before starting a game, saying so under waitedForEditorScanMs. Each game under runtimes is pinged with a short wait, so one held at a breakpoint is listed as unreachable rather than making this call wait out the runtime timeout; for the run this server is reporting on, heldAt says whether that is what it is, with the same three answers editor_output gives. A game the editor played announces the editor under editorPid, and so does whatever that game started for itself; a game some other server started announces none, which is how the two are told apart when both are running from one project. When connected is false, mayYetConnect says whether that is final: the editor dials this server rather than the other way round and backs off between tries, so for the first half-minute after a server starts, false means \"not reached yet\" as often as it means \"no editor\". True is worth waiting out; false is an editor that is not there. False beside restartInterrupted is one that an editor_launch restart on a previous server asked to quit, where the launch half never ran because that server was ended in between, usually by the reconnect the restart was taken for; editor_launch open finishes it. listeningSince is when this server took the bridge port, which is what that window is measured from and what a caller wanting its own window should read. An editor this server opened counts for as long as its process lives, however far past that window the import runs, and awaitingLaunchedEditor names its pid so the two reasons for true are told apart. settingsDropped appears here once when the editor this server opened saved project.godot on its way in, which is the same reading editor_launch restart makes in its own answer. A game that has announced itself in a protocol this server does not speak is listed under unreadable rather than left out, with the protocol it speaks and whether the server or the addon is the older half. This happens during an upgrade that moves the runtime protocol, which most do not: installing replaces the addon on disk as soon as the pin moves, while a server that is already running stays on the version it started with, so the two speak different protocols until the server is reconnected. Those games are real and running, but no tool here can reach them until the halves match, so runtimes stays empty and runtimeConnected stays false. An upgrade that leaves the protocol alone opens no such window and this list stays empty through it. addonIsStale is decided by the code of the editor addons rather than their version, so an editor started before an upgrade that left that code alone reports the older addonVersion, is not stale, and addonNote says so: it needs no restart. port is the one the editor bridge is on; when that is not the one this server was configured with, portWanted names the configured one and portNote says why it moved and, when it was the server this one replaced, which pid kept it. A server replacing another of its project that holds the configured port waits for it to stand down and takes the port over, which takes a few seconds; bridgeHandover says so while it waits, and it moves only if that server has not let go within the wait.",
31507
+ description: "Whether the editor addon is connected, which Godot answers, whether the editor is playing something, and whether a game with the runtime addon is reachable: runtimeConnected counts the games of the project this server serves, and runtimes lists every game on the machine with ofThisProject saying which is which, since a game of another project is reached only by naming its projectPath. playingInEditor is null when the editor was not asked or did not answer, which is not the same as a no: with no editor connected there is nobody to ask, and an editor that does not serve the question is given a moment and then left. A game can be playing while this is null, so read it as unanswered rather than as nothing playing, and use processActive and runtimes, which come from elsewhere and do not depend on the editor answering. editor.scan says whether the editor is scanning or importing and how many milliseconds ago its last scan finished (finishedMsAgo), or is null when it did not answer: the editor rewrites the class cache just after a scan, and editor_run waits that out before starting a game, saying so under waitedForEditorScanMs. Each game under runtimes is pinged with a short wait, so one held at a breakpoint is listed as unreachable rather than making this call wait out the runtime timeout; for the run this server is reporting on, heldAt says whether that is what it is, with the same three answers editor_output gives. A game the editor played announces the editor under editorPid, and so does whatever that game started for itself; a game some other server started announces none, which is how the two are told apart when both are running from one project. When connected is false, mayYetConnect says whether that is final: the editor dials this server rather than the other way round and backs off between tries, so for the first half-minute after a server starts, false means \"not reached yet\" as often as it means \"no editor\". True is worth waiting out; false is an editor that is not there. False beside restartInterrupted is one that an editor_launch restart on a previous server asked to quit, where the launch half never ran because that server was ended in between, usually by the reconnect the restart was taken for; editor_launch open finishes it. True beside restartUnderway is a restart still in progress, its server alive and within the wait for the old editor to go: the editor is coming, and opening another would put two on one project. listeningSince is when this server took the bridge port, which is what that window is measured from and what a caller wanting its own window should read. An editor this server opened counts for as long as its process lives, however far past that window the import runs, and awaitingLaunchedEditor names its pid so the two reasons for true are told apart. settingsDropped appears here once when the editor this server opened saved project.godot on its way in, which is the same reading editor_launch restart makes in its own answer. A game that has announced itself in a protocol this server does not speak is listed under unreadable rather than left out, with the protocol it speaks and whether the server or the addon is the older half. This happens during an upgrade that moves the runtime protocol, which most do not: installing replaces the addon on disk as soon as the pin moves, while a server that is already running stays on the version it started with, so the two speak different protocols until the server is reconnected. Those games are real and running, but no tool here can reach them until the halves match, so runtimes stays empty and runtimeConnected stays false. An upgrade that leaves the protocol alone opens no such window and this list stays empty through it. addonIsStale is decided by the code of the editor addons rather than their version, so an editor started before an upgrade that left that code alone reports the older addonVersion, is not stale, and addonNote says so: it needs no restart. port is the one the editor bridge is on; when that is not the one this server was configured with, portWanted names the configured one and portNote says why it moved and, when it was the server this one replaced, which pid kept it. A server replacing another of its project that holds the configured port waits for it to stand down and takes the port over, which takes a few seconds; bridgeHandover says so while it waits, and it moves only if that server has not let go within the wait. An editor that has connected and not yet greeted, which lasts a frame and longer while it imports, reports nothing about itself: greeting says so, addonIsStale is absent rather than guessed, and a restart asked then waits for the greeting to learn who opened it. startedByAnEditor is an editor another editor started, by Godot's own restart or the project manager, which has none of the arguments a server gave the one before it; startedByAnEditorNote says what that costs.",
31312
31508
  parameters: {},
31313
31509
  requires: []
31314
31510
  },
@@ -31347,6 +31543,7 @@ var TOOL_SPECS = [
31347
31543
  "physics2d",
31348
31544
  "physics3d",
31349
31545
  "audio",
31546
+ "visual",
31350
31547
  "animation",
31351
31548
  "ui"
31352
31549
  ],
@@ -31386,7 +31583,7 @@ var TOOL_SPECS = [
31386
31583
  property: {
31387
31584
  type: "string",
31388
31585
  ops: ["property", "find"],
31389
- description: 'property: which one to read. find: read this one off every node matched, so a panel of labels is one call rather than one per label. Colons read through what a node holds, "_game:clock:speed", which is where a game keeps what is worth asking about. A number or a key steps into a list or a map, "_game:run:roster:0:traits", which is how the lists a game keeps its state in are walked: a roster, a board, an in-tray. A packed list, such as a PackedStringArray, steps the same way. A negative number counts from the end. A step written as a call, "get_viewport():gui_get_focus_owner()", calls a method that takes no arguments and walks into what it returned, which is how a question only a method answers is read in one call: which control holds the focus in the viewport this one is in. A list or a map answers the calls that read it and take no arguments, "_game:run:board:size()" or "_game:inbox:keys()", and not those that change it, such as clear() or sort(). A step that is not there is named, and says what was there instead.'
31586
+ description: 'property: which one to read. find: read this one off every node matched, so a panel of labels is one call rather than one per label. Colons read through what a node holds, "_game:clock:speed", which is where a game keeps what is worth asking about. A number or a key steps into a list or a map, "_game:run:roster:0:traits", which is how the lists a game keeps its state in are walked: a roster, a board, an in-tray. A packed list, such as a PackedStringArray, steps the same way. A negative number counts from the end. A step written as a call, "get_viewport():gui_get_focus_owner()", calls a method that takes no arguments and only reads (an engine method the engine marks as reading, or a game method not declared -> void, so queue_free() is refused) and walks into what it returned, which is how a question only a method answers is read in one call: which control holds the focus in the viewport this one is in. A list or a map answers the calls that read it and take no arguments, "_game:run:board:size()" or "_game:inbox:keys()", and not those that change it, such as clear() or sort(). A step that is not there is named, and says what was there instead.'
31390
31587
  },
31391
31588
  depth: {
31392
31589
  type: "integer",
@@ -31425,13 +31622,14 @@ var TOOL_SPECS = [
31425
31622
  limit: {
31426
31623
  type: "integer",
31427
31624
  minimum: 1,
31625
+ maximum: 5000,
31428
31626
  ops: ["find", "text"],
31429
- description: "find: the most nodes to answer with, default 100. text: the most lines, default 500, with omitted saying how many lines that left behind. A screen whose dialog sits under a long list is a screen read with omitted greater than zero, so raise this or point root at the dialog rather than reading the answer as what is on screen."
31627
+ description: "find: the most nodes to answer with, default 100. text: the most lines, default 500, with omitted saying how many lines that left behind. At most 5000 for either. A screen whose dialog sits under a long list is a screen read with omitted greater than zero, so raise this or point root at the dialog rather than reading the answer as what is on screen."
31430
31628
  },
31431
31629
  includeHidden: {
31432
31630
  type: "boolean",
31433
31631
  ops: ["text", "find"],
31434
- description: "text: read hidden nodes as well, for checking that something is not showing. Default false. find: default true, since a find means the node whether or not it is drawn; false answers with what the player can actually see, which is how a panel that keeps a label for every line and hides the ones that do not is read. A node counts as hidden when anything above it is, and how many matches were left out comes back under hidden."
31632
+ description: "text: read hidden nodes as well, for checking that something is not showing. Default false. find: default true, since a find means the node whether or not it is drawn; false answers with what the player can actually see, which is how a panel that keeps a label for every line and hides the ones that do not is read. A node counts as hidden when the engine would not draw it: a hidden Control, Node2D or Node3D above it hides it, a plain Node in between breaks that chain as it does for the engine, and a hidden canvas layer or window hides everything in it. How many matches were left out comes back under hidden."
31435
31633
  },
31436
31634
  metrics: {
31437
31635
  type: "array",
@@ -31530,7 +31728,7 @@ var TOOL_SPECS = [
31530
31728
  },
31531
31729
  {
31532
31730
  name: "runtime_capture",
31533
- description: "A picture of the running game: the whole screen or one viewport, as an image. Needs the game running with a window. A capture asked for before the game's first frame is drawn waits for that frame, since the game announces itself before it and the viewport holds nothing it drew until then.",
31731
+ description: "A picture of the running game: the whole screen or one viewport, as an image. The whole screen includes the game's own dialogs and popups where they sit, also when a project opens them as windows of their own (subwindows not embedded). Needs the game running with a window. A capture asked for before the game's first frame is drawn waits for that frame, since the game announces itself before it and the viewport holds nothing it drew until then.",
31534
31732
  parameters: {
31535
31733
  projectPath: RUNNING_PROJECT_PATH,
31536
31734
  pid: RUNNING_PID,
@@ -31704,7 +31902,7 @@ var TOOL_SPECS = [
31704
31902
  },
31705
31903
  value: {
31706
31904
  ops: ["until"],
31707
- description: "until: the value to wait for, fitted to the property's type. On a property holding an object, whether declared to or untyped and holding one or null, the text null means null. One declared to hold an object refuses any value other than null, since it can never hold it."
31905
+ description: "until: the value to wait for, fitted to the property's type and compared at the precision the property keeps, so -1.1 meets a 32-bit float holding -1.10000002. A value the property would have to cut is refused: a fraction on a whole number, a number other than 0 or 1 on a bool. On a property holding an object, whether declared to or untyped and holding one or null, the text null means null. One declared to hold an object refuses any value other than null, since it can never hold it."
31708
31906
  },
31709
31907
  says: {
31710
31908
  type: "string",
@@ -31832,7 +32030,14 @@ var UPDATE_NOTICE_EVERY = 500;
31832
32030
  var FEEDBACK_NOTICE_EVERY = 250;
31833
32031
  var run4 = promisify5(execFile5);
31834
32032
  var __dirname2 = dirname12(fileURLToPath4(import.meta.url));
31835
- var EDITOR_RESTART_TIMEOUT_MS = 90000;
32033
+ function editorRestartTimeoutMs() {
32034
+ const override = Number.parseInt(envValue("GDHARNESS_EDITOR_RESTART_TIMEOUT_MS") ?? "", 10);
32035
+ return Number.isInteger(override) && override > 0 ? override : 90000;
32036
+ }
32037
+ var GREETING_WAIT_MS = 1e4;
32038
+ function restartUnderway(note, now = Date.now()) {
32039
+ return alive(note.byPid) && now - Date.parse(note.quitAt) < editorRestartTimeoutMs() + 30000;
32040
+ }
31836
32041
  var HOLD_PING_MS = 2000;
31837
32042
  var SLOWEST_FRAME_RATE = 20;
31838
32043
  function captureDestinationRefusal(outputPath, projects) {
@@ -31988,22 +32193,31 @@ function stopVerdict(stop) {
31988
32193
  withChildren: false
31989
32194
  };
31990
32195
  }
32196
+ if (stop.ending === "lingering") {
32197
+ const told = stop.throughEditor ? stop.endedPid === null ? "The editor was asked to stop the scene it is playing and was still playing it" : `The editor was asked to stop the scene it is playing, and its game, pid ${stop.endedPid}, was still running` : `pid ${stop.endedPid ?? "unknown"} was told to end and was still running`;
32198
+ return {
32199
+ stopped: false,
32200
+ stillGoing: stop.endedPid,
32201
+ note: `${told} ${STOP_WAIT_MS / 1000} seconds later, so it has not stopped. editor_status says when it has gone, and editor_run stop asks again.`,
32202
+ withChildren: true
32203
+ };
32204
+ }
31991
32205
  return {
31992
32206
  stopped: true,
31993
32207
  endedPid: stop.endedPid,
31994
32208
  clean: stop.clean,
31995
- note: `${stop.throughEditor ? stop.endedPid === null ? "The editor was asked to stop the scene it is playing. Its game had not announced a runtime, so no process was named under endedPid, and its exit code stays with the editor." : "The editor was asked to stop the scene it is playing." : "The process named under endedPid was ended."}${stop.exitSignal === null ? "" : ` It was ended by ${stop.exitSignal} and so has no exit code.`}${stop.ending === "gone" ? "" : ` It had not exited ${STOP_WAIT_MS / 1000} seconds after being told to, so it may still be going: editor_status says whether it is.`}`,
32209
+ note: `${stop.throughEditor ? stop.endedPid === null ? "The editor was asked to stop the scene it is playing. Its game had not announced a runtime, so no process was named under endedPid, and its exit code stays with the editor." : "The editor was asked to stop the scene it is playing." : "The process named under endedPid was ended."}${stop.exitSignal === null ? "" : ` It was ended by ${stop.exitSignal} and so has no exit code.`}`,
31996
32210
  withChildren: true
31997
32211
  };
31998
32212
  }
31999
32213
  function endedPreviousRun(ended) {
32000
- if (ended === null || ended.ending === "refused" || ended.ending === "unreached") {
32214
+ if (ended?.ending !== "gone") {
32001
32215
  return;
32002
32216
  }
32003
32217
  return ended.pid ?? true;
32004
32218
  }
32005
32219
  function previousRunLeft(ended) {
32006
- return ended?.ending === "refused" && ended.pid !== null ? ended.pid : undefined;
32220
+ return (ended?.ending === "refused" || ended?.ending === "lingering") && ended.pid !== null ? ended.pid : undefined;
32007
32221
  }
32008
32222
  var CONSOLE_WRAPPER = /_console(\.exe)?$/i;
32009
32223
  function engineNamesOf(executable) {
@@ -32083,8 +32297,10 @@ function endedToStartThis(ended) {
32083
32297
  if (ended.ending === "unreached") {
32084
32298
  return ` ${which} was not ended here: the editor could not be asked to stop it. The editor stops a play before starting the next, so it is not running beside this one if this start reached the editor.`;
32085
32299
  }
32086
- const after = ended.ending === "lingering" ? ` It had not exited ${STOP_WAIT_MS / 1000} seconds after being told to, so it may still be running beside this one: editor_status says whether it is.` : "";
32087
- return ` ${which} was ended to start this one; its output is no longer what editor_output answers about.${after}`;
32300
+ if (ended.ending === "lingering") {
32301
+ return ` ${which} was told to end to start this one and was still running ${STOP_WAIT_MS / 1000} seconds later, so it is running beside this one: editor_status says when it has gone.`;
32302
+ }
32303
+ return ` ${which} was ended to start this one; its output is no longer what editor_output answers about.`;
32088
32304
  }
32089
32305
  var LONGEST_BOOT_NOTED_MS = 5 * 60000;
32090
32306
  var MOST_GROUPS = 20;
@@ -32473,6 +32689,7 @@ class GodotServer {
32473
32689
  shutdownInitiated = false;
32474
32690
  launchedEditor = null;
32475
32691
  launchedFrom = null;
32692
+ launchedDropped = null;
32476
32693
  ownProject;
32477
32694
  announcedAt = null;
32478
32695
  handingOverFrom = null;
@@ -32480,9 +32697,12 @@ class GodotServer {
32480
32697
  constructor() {
32481
32698
  this.ownProject = envValue("GDHARNESS_PROJECT") ?? null;
32482
32699
  this.godotBridge = getDefaultBridge(this.ownProject);
32700
+ this.godotBridge.on("godot_connected", () => {
32701
+ this.settleTheLaunchReading();
32702
+ });
32483
32703
  this.mcp = new McpServer({ name: "gdharness", version: SERVER_VERSION }, { capabilities: { tools: {}, resources: {} } });
32484
32704
  this.setupToolHandlers();
32485
- setupResourceHandlers(this.mcp, () => this.lastProjectPath);
32705
+ setupResourceHandlers(this.mcp, () => this.ourProject() ?? this.lastProjectPath);
32486
32706
  this.mcp.server.onerror = (error) => {
32487
32707
  console.error("[MCP Error]", error);
32488
32708
  };
@@ -32748,8 +32968,9 @@ class GodotServer {
32748
32968
  if (!checked.ok) {
32749
32969
  return checked.response;
32750
32970
  }
32751
- if (typeof args["projectPath"] === "string") {
32752
- this.lastProjectPath = args["projectPath"];
32971
+ const named = args["projectPath"];
32972
+ if (typeof named === "string" && existsSync14(join19(named, "project.godot"))) {
32973
+ this.lastProjectPath = named;
32753
32974
  }
32754
32975
  this.updates.refresh();
32755
32976
  const answer = await withCallSignal(extra.signal, () => this.answered(spec.name, checked.op ?? "", args));
@@ -32789,6 +33010,17 @@ class GodotServer {
32789
33010
  return answer;
32790
33011
  }
32791
33012
  const moved = this.projectHasMovedOn();
33013
+ if (moved !== null && !isNewer(moved, SERVER_VERSION)) {
33014
+ this.noticedUpdate = true;
33015
+ this.callsSinceNotice = 0;
33016
+ return this.saying(answer, {
33017
+ project_addons_behind_this_server: {
33018
+ server_is: SERVER_VERSION,
33019
+ project_is: moved,
33020
+ what_to_do: `The project's gdharness addons are ${moved}, older than this ${SERVER_VERSION} server, so an ` + "editor restart loads the old code and reconnecting spawns this same server again. Tell the " + "user, and offer to run gdharness upgrade in the project, which replaces the addons with " + "this server's; ask first, since it changes files in their project. editor_launch restart " + "then loads them."
33021
+ }
33022
+ });
33023
+ }
32792
33024
  if (moved !== null) {
32793
33025
  this.noticedUpdate = true;
32794
33026
  this.callsSinceNotice = 0;
@@ -32821,7 +33053,7 @@ class GodotServer {
32821
33053
  return this.saying(answer, {
32822
33054
  update_available: {
32823
33055
  ...notice,
32824
- what_to_do: "Tell the user a newer gdharness is out, with what changed, and offer to take it. " + "Only run the upgrade command if they say yes: it restarts their editor and the " + "MCP server has to be reconnected afterwards."
33056
+ what_to_do: "Tell the user a newer gdharness is out, with what changed, and offer to take it. " + "Only run the upgrade command if they say yes: it replaces the addons in their project, " + "and afterwards the MCP server has to be reconnected and the editor restarted with " + "editor_launch restart."
32825
33057
  }
32826
33058
  });
32827
33059
  }
@@ -32838,6 +33070,11 @@ class GodotServer {
32838
33070
  const installed = installedAddonVersion(this.ownProject);
32839
33071
  return installed === null || installed === SERVER_VERSION ? null : installed;
32840
33072
  }
33073
+ editorCodeOnDisk() {
33074
+ const status = this.godotBridge.getStatus();
33075
+ const project = (status.connected ? status.projectPath : undefined) ?? this.ownProject;
33076
+ return project === null || project === "" ? undefined : installedEditorDigest(project);
33077
+ }
32841
33078
  configDisagreement() {
32842
33079
  return this.ownProject === null ? null : configDisagrees(this.ownProject, SERVER_VERSION);
32843
33080
  }
@@ -33789,6 +34026,10 @@ class GodotServer {
33789
34026
  }
33790
34027
  return this.jsonTextResponse(info);
33791
34028
  }
34029
+ fileTypes(args) {
34030
+ const named = readStringArray(args, "fileTypes");
34031
+ return named === undefined ? {} : { fileTypes: named };
34032
+ }
33792
34033
  handleSearchProject(args) {
33793
34034
  const project = this.project(args);
33794
34035
  if (!project.ok) {
@@ -33797,16 +34038,7 @@ class GodotServer {
33797
34038
  try {
33798
34039
  return this.jsonTextResponse(searchProject(project.value.path, {
33799
34040
  query: readString(args, "query") ?? "",
33800
- fileTypes: readStringArray(args, "fileTypes") ?? [
33801
- "gd",
33802
- "tscn",
33803
- "tres",
33804
- "gdshader",
33805
- "cfg",
33806
- "md",
33807
- "txt",
33808
- "json"
33809
- ],
34041
+ ...this.fileTypes(args),
33810
34042
  regex: readBoolean(args, "regex") ?? false,
33811
34043
  caseSensitive: readBoolean(args, "caseSensitive") ?? false,
33812
34044
  maxResults: readPositiveNumber(args, "maxResults") ?? 100
@@ -34117,7 +34349,7 @@ class GodotServer {
34117
34349
  warnings: diagnostics.length - errors,
34118
34350
  diagnostics,
34119
34351
  ...disagrees
34120
- }, this.godotBridge.getStatus().addonVersion, SERVER_VERSION, this.godotBridge.getStatus().addonDigest, shippedEditorDigest()));
34352
+ }, this.godotBridge.getStatus().addonVersion, SERVER_VERSION, this.godotBridge.getStatus().addonDigest, shippedEditorDigest(), this.editorCodeOnDisk()));
34121
34353
  }
34122
34354
  whereTheFileDisagrees(diagnostics, args) {
34123
34355
  const messages = diagnostics.map((entry) => asParams(entry)["message"]).filter((message) => typeof message === "string");
@@ -34268,7 +34500,7 @@ class GodotServer {
34268
34500
  }
34269
34501
  breakpointsAtRisk() {
34270
34502
  const status = this.godotBridge.getStatus();
34271
- if (!status.connected || status.syncsBreakpoints === true) {
34503
+ if (!hasSaidWhoItIs(status) || status.syncsBreakpoints === true) {
34272
34504
  return {};
34273
34505
  }
34274
34506
  return {
@@ -34323,26 +34555,34 @@ class GodotServer {
34323
34555
  restartSettled(this.ownProject);
34324
34556
  return null;
34325
34557
  }
34326
- return owed;
34558
+ return { note: owed, underway: restartUnderway(owed) };
34327
34559
  }
34328
34560
  async getEditorStatusPayload() {
34329
34561
  const status = this.godotBridge.getStatus();
34330
34562
  const launchedIsUp = !status.connected && await this.launchedEditorIsUp();
34331
34563
  const isPortConflict = this.bridgeStartupError?.includes("EADDRINUSE") ?? false;
34332
- const stale = status.connected && editorIsStale(status.addonVersion, SERVER_VERSION, status.addonDigest, shippedEditorDigest());
34564
+ const greeted = hasSaidWhoItIs(status);
34565
+ const stale = greeted && editorIsStale(status.addonVersion, SERVER_VERSION, status.addonDigest, shippedEditorDigest());
34333
34566
  const unfinished = this.restartLeftUnfinished(status.connected);
34334
34567
  return {
34335
34568
  ...status,
34336
34569
  serverVersion: SERVER_VERSION,
34337
- addonIsStale: status.connected ? stale : undefined,
34570
+ addonIsStale: greeted ? stale : undefined,
34571
+ greeting: status.connected && !greeted ? "The editor has connected and has not yet said who it is: its project, pid, addon version and ports arrive with its greeting a moment after the socket opens, later while it imports. Ask again for them." : undefined,
34338
34572
  bridgeAvailable: this.bridgeStartupError === null,
34339
- mayYetConnect: status.connected ? undefined : unfinished !== null ? false : anEditorIsStillComing(status.listeningSince, launchedIsUp),
34340
- restartInterrupted: unfinished === null ? undefined : {
34341
- quitEditorPid: unfinished.editorPid,
34342
- quitAt: unfinished.quitAt,
34343
- byServerPid: unfinished.byPid,
34573
+ mayYetConnect: status.connected ? undefined : unfinished !== null ? unfinished.underway : anEditorIsStillComing(status.listeningSince, launchedIsUp),
34574
+ restartInterrupted: unfinished === null || unfinished.underway ? undefined : {
34575
+ quitEditorPid: unfinished.note.editorPid,
34576
+ quitAt: unfinished.note.quitAt,
34577
+ byServerPid: unfinished.note.byPid,
34344
34578
  note: "A restart begun by a previous gdharness server asked this project's editor to quit, and that server was ended before it could start the editor again, so nothing is coming. editor_launch open starts one, and clears this."
34345
34579
  },
34580
+ restartUnderway: unfinished === null || !unfinished.underway ? undefined : {
34581
+ quitEditorPid: unfinished.note.editorPid,
34582
+ quitAt: unfinished.note.quitAt,
34583
+ byServerPid: unfinished.note.byPid,
34584
+ note: `A restart of this project's editor is under way: gdharness server pid ${unfinished.note.byPid} asked it to quit at ${unfinished.note.quitAt} and is starting it again. Wait for it rather than opening another.`
34585
+ },
34346
34586
  awaitingLaunchedEditor: status.connected || !launchedIsUp ? undefined : this.launchedEditor?.pid ?? undefined,
34347
34587
  ...status.connected ? this.whatTheLaunchedEditorDropped() : {},
34348
34588
  startupError: this.bridgeStartupError,
@@ -34352,8 +34592,9 @@ class GodotServer {
34352
34592
  port: this.godotBridge.configuredPort,
34353
34593
  note: `The gdharness server this one replaced, pid ${this.handingOverFrom}, still holds port ${this.godotBridge.configuredPort} and is standing down; this server takes the port when it lets go, and takes another after ${HANDOVER_MS / 1000} seconds if it does not.`
34354
34594
  },
34355
- staleNote: stale ? addonMismatch(status.addonVersion, SERVER_VERSION, status.addonDigest, shippedEditorDigest()) : undefined,
34356
- addonNote: status.connected ? sameCodeNote(status.addonVersion, SERVER_VERSION, status.addonDigest, shippedEditorDigest()) : undefined,
34595
+ staleNote: stale ? addonMismatch(status.addonVersion, SERVER_VERSION, status.addonDigest, shippedEditorDigest(), this.editorCodeOnDisk()) : undefined,
34596
+ addonNote: greeted ? sameCodeNote(status.addonVersion, SERVER_VERSION, status.addonDigest, shippedEditorDigest()) : undefined,
34597
+ startedByAnEditorNote: status.startedByAnEditor === true ? "Another editor started this one: Godot's own restart, or the project manager opening a project. None of the arguments a server gave the editor before it reached this one, so it serves the ports its editor settings name (and none at all while another editor holds those, when the script and debug tools reach that editor instead), its console is not captured, and it restarts itself. Close it and use editor_launch open to have an editor this server started." : undefined,
34357
34598
  ...this.breakpointsAtRisk(),
34358
34599
  retryingBridge: this.bridgeRetry === null ? undefined : true,
34359
34600
  announcedAt: this.announcedAt ?? undefined,
@@ -34492,17 +34733,33 @@ class GodotServer {
34492
34733
  "editor_status says whether the bridge is up and what has reached it"
34493
34734
  ]);
34494
34735
  }
34495
- const settingsBefore = this.settingKeysOf(before.projectPath);
34736
+ if (!hasSaidWhoItIs(before)) {
34737
+ const settled = await this.waitForBridge(() => hasSaidWhoItIs(this.godotBridge.getStatus()) || !this.godotBridge.isConnected(), Date.now() + GREETING_WAIT_MS);
34738
+ if (!settled) {
34739
+ return this.createErrorResponse(`The editor has connected and has not said who it is within ${GREETING_WAIT_MS / 1000}s, so whether this server or the editor itself restarts it cannot be told.`, [
34740
+ "editor_status says when it has, under greeting while it has not",
34741
+ "Then ask for the restart again"
34742
+ ]);
34743
+ }
34744
+ return this.handleRestartEditor(args);
34745
+ }
34496
34746
  const mine = before.openedByAServer === true && before.projectPath !== undefined;
34747
+ if (!mine && args["hidden"] === true) {
34748
+ return this.createErrorResponse("This editor was opened by hand, and restarts itself as it was, so it cannot come back hidden.", [
34749
+ "Close it, then editor_launch open with hidden: true starts a hidden one this server can restart",
34750
+ "editor_launch restart without hidden restarts it as it is"
34751
+ ]);
34752
+ }
34753
+ const settingsBefore = this.settingKeysOf(before.projectPath);
34497
34754
  const asked = mine ? await this.startItAgain(before.projectPath ?? "", before.editorPid, args["hidden"] === true) : await this.handleViaBridge("restart_editor", {});
34498
34755
  if (asked.isError === true) {
34499
34756
  return asked;
34500
34757
  }
34501
34758
  const startedAt = before.connectedAt?.getTime() ?? 0;
34502
34759
  const began = Date.now();
34503
- const back = await this.waitForBridge(() => theEditorHasComeBack(this.godotBridge.getStatus(), startedAt), began + EDITOR_RESTART_TIMEOUT_MS);
34760
+ const back = await this.waitForBridge(() => theEditorHasComeBack(this.godotBridge.getStatus(), startedAt), began + editorRestartTimeoutMs());
34504
34761
  if (!back) {
34505
- return this.createErrorResponse(`The editor was asked to restart and has not come back within ${EDITOR_RESTART_TIMEOUT_MS / 1000}s.`, [
34762
+ return this.createErrorResponse(`The editor was asked to restart and has not come back within ${editorRestartTimeoutMs() / 1000}s.`, [
34506
34763
  "It may be asking what to do about an unsaved scene: look at the editor window",
34507
34764
  "An addon that no longer parses stops the editor reaching this server",
34508
34765
  "editor_status says whether anything has reached the bridge since"
@@ -34516,18 +34773,27 @@ class GodotServer {
34516
34773
  addonVersion: now.addonVersion,
34517
34774
  serverVersion: SERVER_VERSION,
34518
34775
  addonIsStale: editorIsStale(now.addonVersion, SERVER_VERSION, now.addonDigest, shippedEditorDigest()),
34519
- staleNote: addonMismatch(now.addonVersion, SERVER_VERSION, now.addonDigest, shippedEditorDigest()),
34776
+ staleNote: addonMismatch(now.addonVersion, SERVER_VERSION, now.addonDigest, shippedEditorDigest(), this.editorCodeOnDisk()),
34520
34777
  ...this.whatTheEditorDropped(settingsBefore, after),
34521
34778
  tookMs: Date.now() - began
34522
34779
  });
34523
34780
  }
34524
- whatTheLaunchedEditorDropped() {
34781
+ settleTheLaunchReading() {
34525
34782
  const watched = this.launchedFrom;
34526
- if (watched === null) {
34527
- return {};
34783
+ const status = this.godotBridge.getStatus();
34784
+ if (watched === null || !hasSaidWhoItIs(status)) {
34785
+ return;
34528
34786
  }
34529
34787
  this.launchedFrom = null;
34530
- return this.whatTheEditorDropped(watched.before, this.settingKeysOf(watched.projectPath));
34788
+ if (status.editorPid === undefined || status.editorPid !== this.launchedEditor?.pid) {
34789
+ return;
34790
+ }
34791
+ this.launchedDropped = this.whatTheEditorDropped(watched.before, this.settingKeysOf(watched.projectPath));
34792
+ }
34793
+ whatTheLaunchedEditorDropped() {
34794
+ const dropped = this.launchedDropped ?? {};
34795
+ this.launchedDropped = null;
34796
+ return dropped;
34531
34797
  }
34532
34798
  whatTheEditorDropped(before, after) {
34533
34799
  return settingsDroppedReport(before, after);
@@ -34553,7 +34819,14 @@ class GodotServer {
34553
34819
  restartSettled(projectPath);
34554
34820
  return asked;
34555
34821
  }
34556
- await this.waitForBridge(() => !alive(editorPid), Date.now() + EDITOR_RESTART_TIMEOUT_MS);
34822
+ const gone = await this.waitForBridge(() => !alive(editorPid), Date.now() + editorRestartTimeoutMs());
34823
+ if (!gone) {
34824
+ restartSettled(projectPath);
34825
+ return this.createErrorResponse(`The editor was asked to go and pid ${editorPid ?? "unknown"} is still running after ${editorRestartTimeoutMs() / 1000}s, so no replacement was started: it would find the language server and debug adapter ports still held.`, [
34826
+ "It may be asking what to do about unsaved changes, or a script may be holding up its exit",
34827
+ `editor_launch open starts one on ${projectPath} once it has gone`
34828
+ ]);
34829
+ }
34557
34830
  const opened = await this.openAnEditor(engine.value, projectPath, ports, hidden);
34558
34831
  restartSettled(projectPath);
34559
34832
  if (opened.error !== null) {
@@ -34584,6 +34857,10 @@ class GodotServer {
34584
34857
  "Another project wants its own gdharness server, which is its own harness session"
34585
34858
  ]);
34586
34859
  }
34860
+ const refused = this.anEditorThatCannotConnect(project.value.path);
34861
+ if (refused !== null) {
34862
+ return refused;
34863
+ }
34587
34864
  const engine = await this.engine();
34588
34865
  if (!engine.ok) {
34589
34866
  return engine.response;
@@ -34608,6 +34885,27 @@ class GodotServer {
34608
34885
  settingsNote: before === null ? "project.godot could not be read before this editor was opened, so nothing here will be able to say what the import saved away. Opening a project rewrites the file and drops any key sitting at its own default." : before.size === 0 ? undefined : "Opening a project imports it and saves project.godot, and Godot drops any key sitting at its own default. editor_status names anything lost under settingsDropped once this editor has connected."
34609
34886
  });
34610
34887
  }
34888
+ anEditorThatCannotConnect(projectPath) {
34889
+ if (this.ownProject !== null && !isSameDirectory(this.ownProject, projectPath)) {
34890
+ return this.createErrorResponse(`This server serves ${this.ownProject}, and an editor of ${projectPath} would dial that project's own server rather than this one.`, [
34891
+ "Open it from that project's own gdharness session",
34892
+ `editor_launch with projectPath ${this.ownProject} opens the editor this server serves`
34893
+ ]);
34894
+ }
34895
+ const report = inspectProject(projectPath);
34896
+ const installed = report.addons.some((addon) => addon.name === "gdharness_editor" && addon.installed);
34897
+ if (!installed || !report.pluginsEnabled.includes("gdharness_editor")) {
34898
+ return this.createErrorResponse(`The gdharness editor addon is not ${installed ? "enabled" : "installed"} in ${projectPath}, so an editor opened on it would never reach this server.`, installed ? [
34899
+ "gdharness setup in the project enables it",
34900
+ "Or enable it under Project Settings, Plugins, in an editor opened by hand"
34901
+ ] : ["gdharness setup in the project installs and enables it"]);
34902
+ }
34903
+ const owed = restartOwed(projectPath);
34904
+ if (owed !== null && restartUnderway(owed)) {
34905
+ return this.createErrorResponse(`A restart of this project's editor is under way: gdharness server pid ${owed.byPid} asked it to quit at ${owed.quitAt} and is starting it again, so opening another would put two editors on one project.`, ["editor_status says when it has connected"]);
34906
+ }
34907
+ return null;
34908
+ }
34611
34909
  async openAnEditor(engine, projectPath, ports, hidden) {
34612
34910
  clearEditorLog(projectPath);
34613
34911
  const launched = await launchOutsideTheTree({
@@ -35055,23 +35353,30 @@ class GodotServer {
35055
35353
  pid: running.pid,
35056
35354
  transcript: running.transcript ?? "",
35057
35355
  startedAt: running.startedAt,
35356
+ ...running.startedBy === undefined ? {} : { startedBy: running.startedBy },
35058
35357
  projectPath: running.projectPath ?? "",
35059
35358
  arguments: [],
35060
35359
  ...running.command === undefined ? {} : { command: running.command }
35061
35360
  };
35062
- if (!await stillTheRecordedRun(startedAs)) {
35361
+ const why = await whyNotStillTheRecordedRun(startedAs);
35362
+ if (why !== null) {
35063
35363
  clearTheRecord();
35064
35364
  running.endedHere = null;
35065
- running.log.record("warning", `This run was not ended here: pid ${running.pid} no longer answers as the process the run was started as, so nothing was signalled. If that process is still the game, end it yourself; if it is not, it belongs to something else.`);
35365
+ running.log.record("warning", `This run was not ended here: pid ${running.pid} no longer answers as the process the run was started as (${why}), so nothing was signalled. If that process is still the game, end it yourself; if it is not, it belongs to something else.`);
35066
35366
  return "refused";
35067
35367
  }
35068
35368
  const signalled = await runningAs(running.pid);
35069
35369
  const described = signalled === null ? "nothing it would name" : `${signalled.kind}: ${signalled.text}`;
35070
35370
  let landed = true;
35371
+ let declined = null;
35071
35372
  try {
35072
35373
  process.kill(running.pid);
35073
- } catch {
35374
+ } catch (error) {
35074
35375
  landed = false;
35376
+ const code = error.code;
35377
+ if (code !== "ESRCH") {
35378
+ declined = code ?? errorMessage(error);
35379
+ }
35075
35380
  }
35076
35381
  const gone = await untilGone([running.pid]);
35077
35382
  if (gone) {
@@ -35082,7 +35387,7 @@ class GodotServer {
35082
35387
  running.exitSignal = "SIGTERM";
35083
35388
  }
35084
35389
  clearTheRecord();
35085
- running.log.record("info", landed ? `gdharness ended pid ${running.pid}, which the operating system described as ${described}.` : `gdharness signalled pid ${running.pid} and it was already gone; the operating system had described it as ${described}.`);
35390
+ running.log.record(gone ? "info" : "warning", declined !== null ? `gdharness could not signal pid ${running.pid}: the operating system refused it (${declined}). It had described that process as ${described}.` : !gone ? `gdharness signalled pid ${running.pid}, which the operating system described as ${described}, and it was still running ${STOP_WAIT_MS / 1000} seconds later.` : landed ? `gdharness ended pid ${running.pid}, which the operating system described as ${described}.` : `gdharness signalled pid ${running.pid} and it was already gone; the operating system had described it as ${described}.`);
35086
35391
  return gone ? "gone" : "lingering";
35087
35392
  }
35088
35393
  spawnGame(godotPath, cmdArgs, env) {
@@ -35166,12 +35471,13 @@ class GodotServer {
35166
35471
  command: godotPath,
35167
35472
  args: cmdArgs,
35168
35473
  ...env === undefined ? {} : { env },
35169
- run: { transcript: transcript.path, startedAt, projectPath },
35474
+ run: { transcript: transcript.path, startedAt, projectPath, ...this.servedBy() },
35170
35475
  ...desktop === undefined ? {} : { desktop }
35171
35476
  });
35172
35477
  if ("error" in launched) {
35173
35478
  return launched;
35174
35479
  }
35480
+ const startedBy = Date.now();
35175
35481
  sweepTranscripts();
35176
35482
  return {
35177
35483
  pid: launched.pid,
@@ -35180,6 +35486,7 @@ class GodotServer {
35180
35486
  readOffset: 0,
35181
35487
  projectPath,
35182
35488
  startedAt,
35489
+ startedBy,
35183
35490
  command: godotPath,
35184
35491
  exitCode: null,
35185
35492
  exitSignal: null,
@@ -35399,8 +35706,9 @@ class GodotServer {
35399
35706
  }
35400
35707
  async adoptRecordedRun() {
35401
35708
  const project = this.ourProject();
35402
- const record = project === null ? null : readRunRecord(project);
35403
- if (record === null || !this.couldBeOurs(record.projectPath)) {
35709
+ const found = project === null ? [] : [readRunRecord(project), this.startedForUs(project)];
35710
+ const record = found.reduce((newest, one) => one !== null && (newest === null || one.startedAt > newest.startedAt) ? one : newest, null);
35711
+ if (record === null || !(this.couldBeOurs(record.projectPath) || this.couldBeOurs(record.servedBy ?? ""))) {
35404
35712
  return null;
35405
35713
  }
35406
35714
  const adopted = {
@@ -35410,6 +35718,7 @@ class GodotServer {
35410
35718
  readOffset: 0,
35411
35719
  projectPath: record.projectPath === "" ? null : record.projectPath,
35412
35720
  startedAt: record.startedAt,
35721
+ ...record.startedBy === undefined ? {} : { startedBy: record.startedBy },
35413
35722
  ...record.command === undefined ? {} : { command: record.command },
35414
35723
  exitCode: null,
35415
35724
  exitSignal: null,
@@ -35430,6 +35739,13 @@ class GodotServer {
35430
35739
  this.activeProcess = adopted;
35431
35740
  return adopted;
35432
35741
  }
35742
+ servedBy() {
35743
+ const mine = this.ourProject();
35744
+ return mine === null ? {} : { servedBy: mine };
35745
+ }
35746
+ startedForUs(project) {
35747
+ return everyRunRecord().find((one) => one.servedBy !== undefined && isSameDirectory(one.servedBy, project) && !(one.projectPath !== "" && isSameDirectory(one.projectPath, project))) ?? null;
35748
+ }
35433
35749
  nothingOfOursIsRunning() {
35434
35750
  const status = this.godotBridge.getStatus();
35435
35751
  const noEditor = !status.connected ? " No editor is connected, so a game the editor is playing cannot be seen from here at all:" + " editor_status says whether one is on its way, and a run of yours that is still up is" + " reachable again once it is." : "";
@@ -35596,22 +35912,20 @@ class GodotServer {
35596
35912
  }
35597
35913
  async handleEditorConsole(args) {
35598
35914
  const status = this.godotBridge.getStatus();
35599
- const projectPath = status.projectPath ?? this.ownProject ?? undefined;
35600
- if (projectPath === undefined) {
35601
- return this.createErrorResponse("No editor is connected, so there is no console to read.", [
35602
- "editor_status says whether one is connected and whether it may yet be",
35603
- "editor_launch opens one, and an editor opened here has its console captured"
35604
- ]);
35915
+ const greeted = hasSaidWhoItIs(status);
35916
+ const launched = greeted ? null : this.launchedEditor?.pid ?? null;
35917
+ if (!greeted && launched === null && status.connected) {
35918
+ return this.createErrorResponse("The editor has connected and has not yet said who it is, so whose console to read cannot be told yet.", ["Ask again in a moment; editor_status shows greeting until it has"]);
35605
35919
  }
35606
- const launched = status.connected ? null : this.launchedEditor?.pid ?? null;
35607
- if (!status.connected && launched === null) {
35920
+ const projectPath = status.projectPath ?? this.ownProject ?? undefined;
35921
+ if (projectPath === undefined || !greeted && launched === null) {
35608
35922
  return this.createErrorResponse("No editor is connected, so there is no console to read.", [
35609
35923
  "editor_status says whether one is connected and whether it may yet be",
35610
35924
  "editor_launch opens one, and an editor opened here has its console captured"
35611
35925
  ]);
35612
35926
  }
35613
- const editorPid = status.connected ? status.editorPid ?? null : launched;
35614
- const console2 = editorConsole(projectPath, editorPid, status.connected ? status.openedByAServer === true : true);
35927
+ const editorPid = greeted ? status.editorPid ?? null : launched;
35928
+ const console2 = editorConsole(projectPath, editorPid, greeted ? status.openedByAServer === true : true);
35615
35929
  if ("kind" in console2) {
35616
35930
  return this.createErrorResponse(theConsoleWasNotCaptured(console2, projectPath), [
35617
35931
  "editor_launch restart replaces this editor with one whose console is captured",
@@ -35793,6 +36107,7 @@ class GodotServer {
35793
36107
  through: stopped.throughEditor ? "editor" : "gdharness",
35794
36108
  endedPid: verdict.endedPid,
35795
36109
  notSignalled: verdict.notSignalled,
36110
+ stillGoing: verdict.stillGoing,
35796
36111
  ...childrenFields(ended),
35797
36112
  exitedBeforeStop: !wasRunning,
35798
36113
  exitCode: stopped.exitCode,
@@ -35850,12 +36165,13 @@ class GodotServer {
35850
36165
  await announcementEnded(pid);
35851
36166
  }
35852
36167
  return this.jsonTextResponse({
35853
- stopped: true,
36168
+ stopped: gone,
35854
36169
  through: "gdharness",
35855
- endedPid: pid,
36170
+ endedPid: gone ? pid : undefined,
36171
+ stillGoing: gone ? undefined : pid,
35856
36172
  ...childrenFields(ended),
35857
36173
  exitedBeforeStop: !landed,
35858
- note: `${landed ? `pid ${pid} was ended: a game of this project that no server here was holding,` : `pid ${pid} had already gone when it was signalled: a game of this project that no server here was holding,`} identified by its announcement and by its command line, ${read.executable} run with --path ${read.projectPath ?? ""}. Nothing here read what it printed or holds its exit code, so neither is in this answer.${gone ? "" : ` It had not exited ${STOP_WAIT_MS / 1000} seconds after being told to, so it may still be going: editor_status says whether it is.`} ${aboutTheChildren(ended, false)}`
36174
+ note: `${!gone ? `pid ${pid} was told to end and was still running ${STOP_WAIT_MS / 1000} seconds later, so it has not stopped: a game of this project that no server here was holding,` : landed ? `pid ${pid} was ended: a game of this project that no server here was holding,` : `pid ${pid} had already gone when it was signalled: a game of this project that no server here was holding,`} identified by its announcement and by its command line, ${read.executable} run with --path ${read.projectPath ?? ""}. Nothing here read what it printed or holds its exit code, so neither is in this answer.${gone ? "" : " editor_status says when it has gone."} ${aboutTheChildren(ended, false)}`
35859
36175
  });
35860
36176
  }
35861
36177
  async whatTheRunStarted(run) {
@@ -36002,7 +36318,8 @@ class GodotServer {
36002
36318
  }
36003
36319
  }
36004
36320
  const after = projectPath === "" || busy ? null : cachedClasses(projectPath);
36005
- const lost = before === null || after === null ? [] : [...before.keys()].filter((name) => !after.has(name));
36321
+ const declaredNow = before === null || after === null ? null : declaredClasses(projectPath);
36322
+ const lost = before === null || after === null || declaredNow === null ? [] : [...before.keys()].filter((name) => !after.has(name) && declaredNow.has(name));
36006
36323
  if (lost.length > 0) {
36007
36324
  this.noteAShortListEditor(projectPath);
36008
36325
  }
@@ -36063,7 +36380,7 @@ class GodotServer {
36063
36380
  }
36064
36381
  const checked = busy ? { unseen: [] } : await this.classesTheEditorCannotSee(args);
36065
36382
  const unseen = checked.unseen;
36066
- const broughtIn = blind.unseen.map((one) => one.className).filter((name) => !unseen.some((still) => still.className === name));
36383
+ const broughtIn = busy ? [] : blind.unseen.map((one) => one.className).filter((name) => !unseen.some((still) => still.className === name));
36067
36384
  const dependents = busy || projectPath === "" || broughtIn.length === 0 ? null : await this.reloadDependents(projectPath, broughtIn);
36068
36385
  const stillGone = lost.filter((name) => !restored.includes(name));
36069
36386
  const notes = [];
@@ -36304,7 +36621,7 @@ class GodotServer {
36304
36621
  ]);
36305
36622
  }
36306
36623
  try {
36307
- return this.jsonTextResponse(markIfStale(await this.godotBridge.invokeTool(toolName, args), this.godotBridge.getStatus().addonVersion, SERVER_VERSION, this.godotBridge.getStatus().addonDigest, shippedEditorDigest()));
36624
+ return this.jsonTextResponse(markIfStale(await this.godotBridge.invokeTool(toolName, args), this.godotBridge.getStatus().addonVersion, SERVER_VERSION, this.godotBridge.getStatus().addonDigest, shippedEditorDigest(), this.editorCodeOnDisk()));
36308
36625
  } catch (error) {
36309
36626
  return this.createErrorResponse(`The editor answered ${toolName} with an error: ${errorMessage(error)}`);
36310
36627
  }
@@ -36582,6 +36899,7 @@ class GodotServer {
36582
36899
  }
36583
36900
  }
36584
36901
  async function runGodotServer() {
36902
+ delete process.env[EDITOR_PID_VARIABLE];
36585
36903
  const server = new GodotServer;
36586
36904
  await server.run();
36587
36905
  }