@henols/c64-re-tools 2.2.0-rc.7 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henols/c64-re-tools",
3
- "version": "2.2.0-rc.7",
3
+ "version": "2.2.1",
4
4
  "description": "Agent-friendly Commodore 64 engineering toolkit for reverse engineering, debugging, development and testing.",
5
5
  "license": "MIT",
6
6
  "author": "Henrik Olsson",
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: c64-docs
3
- description: Use this skill to write the documentation of a C64 program. The documentation puts first the development of the program and its copy protection, and explains them in depth. It tells the findings and what each one means in practice. It explains how the program works, with links to the main parts of the source, and tells the releases and cracks for preservation. The script generates the reference pages from the knowledge and the source. You write the other pages by the method of this skill. A second command of the script makes the links and checks every link. Use it after the source is identical, or to keep the documentation correct after a change to the knowledge.
3
+ description: Use this skill to write the documentation of a C64 program. The documentation puts first the development of the program and its copy protection, and explains them in depth. It tells the findings and what each one means in practice. It explains how the program works, with links to the main parts of the source, and lists the releases in short. The script generates the reference pages from the knowledge and the source. You write the other pages by the method of this skill. A second command of the script makes the links and checks every link. Use it after the source is identical, or to keep the documentation correct after a change to the knowledge.
4
4
  ---
5
5
 
6
6
  # c64-docs
@@ -9,7 +9,7 @@ description: Use this skill to write the documentation of a C64 program. The doc
9
9
 
10
10
  Write documentation that explains how a program works, and that points to the main parts of the code. The documentation is Markdown in the project. The entry page is `README.md` in the project folder. The other pages and the reference are in `docs/`. The documentation has two parts:
11
11
 
12
- - **The pages that you write.** They explain how the program works. They give the flows, the state machines, the data formats and the task of each part. They tell the development of the program and its copy protection first, in depth. They tell the findings and what each one means in practice, and the releases and cracks. They link only the main parts of the code. Use the page types in `references/page-types.md` and the rules in `references/style.md`.
12
+ - **The pages that you write.** They explain how the program works. They give the flows, the state machines, the data formats and the task of each part. They tell the development of the program and its copy protection first, in depth. They tell the findings and what each one means in practice. They list the releases in short. They link only the main parts of the code. Use the page types in `references/page-types.md` and the rules in `references/style.md`.
13
13
  - **The reference.** `docs.ts generate` generates it from the knowledge, the source map of c64-source and the image. It is the lookup for each routine, table and variable. It has a page for each module, with the routines, their callers and callees, the data and a call graph. It also has pages for the tables, the memory map with the variables, and the graphics. Do not edit these pages. The next run writes over them.
14
14
 
15
15
  `docs.ts link` makes the links of the pages that you write. A name and its address in backticks become one link to the line of the name in the source. When the source changes, `docs.ts link` moves the links to the new lines.
@@ -70,7 +70,7 @@ node <skill>/scripts/docs.ts link README.md docs --source src --check
70
70
  2. Generate the source with c64-source. Make sure that `check.identical` is `true`. The script also writes `source-map.json`.
71
71
  3. Run `docs.ts generate`. Read `index.md` of the reference. A module with no routines, or a routine with no comment, shows what the knowledge does not have yet.
72
72
  4. Make the plan of the pages. Start from the modules and the call graphs. Find the main loop, the interrupt chain, the dispatch tables, the state machines and the data formats. Each subsystem gets one page in `docs/`. The entry page `README.md` in the project folder lists the pages. Use the page types in `references/page-types.md`.
73
- 5. Collect the facts about the development, the copy protection and the releases. These facts are the most interesting parts for a reader, so look for them carefully. Read the leftover spaces and their comments in the knowledge. If the knowledge has none, run `provenance.ts leftovers` of c64-provenance. For two or more releases, run `provenance.ts compare` of c64-provenance. Get the crack stages from c64-unpacker. Find each check of the copy protection in the code, and the effect of a failed check. These facts go into the development section, the copy protection section, the releases section and their pages.
73
+ 5. Collect the facts about the development and the copy protection. These facts are the most interesting parts for a reader, so look for them carefully. Read the leftover spaces and their comments in the knowledge. If the knowledge has none, run `provenance.ts leftovers` of c64-provenance. For two or more releases, run `provenance.ts compare` of c64-provenance to separate the program from the changes of each release. Find each check of the copy protection in the code, and the effect of a failed check. These facts go into the development section, the copy protection section and their pages. Do not examine the cracks in detail. They are not part of the program.
74
74
  6. Write each page. Read the code and the knowledge for each fact. Run the program with c64-testing or c64-emulator when a fact needs a run. Explain each part before you name the code. Link only the main parts: write `` `draw_room` `$09BC` `` for a link, and `` `draw_room` `` for each other mention. Mark each fact with its evidence. Several subagents can write the pages at the same time, one page each. Give each subagent `references/page-types.md` and `references/style.md`.
75
75
  7. Record each new fact in the knowledge first: a name, a comment, a region or a module. Then the source and the reference show it too. A fact only in a page is lost at the next change of the knowledge.
76
76
  8. Run `docs.ts link`. Read `problems` and correct each one. Then run `docs.ts link --check`. Make sure that `result` is `PASS`.
@@ -158,5 +158,4 @@ Do not store:
158
158
  - The source and its source map → c64-source
159
159
  - A fact that needs a run → c64-testing or c64-emulator
160
160
  - Leftovers, traces of the development and the differences of releases → c64-provenance
161
- - The stages of a crack or a packer → c64-unpacker
162
161
  - What an address of the C64 is → c64-memory-map
@@ -10,11 +10,11 @@ The most interesting parts for a reader are the development of the program and i
10
10
 
11
11
  1. **One paragraph.** What the program is, who made it and when, and which release the documentation is for. Under it, one line defines the evidence marks: **Observed**, **Code** and **Conclusion**.
12
12
  2. **The development.** How the authors made the program, as the code and the leftovers tell it. Explain each trace in depth: what the bytes are, how you identified them, and what they tell about the work of the authors. Use as many paragraphs as the traces need. Link the development page (section 6) for the full details.
13
- 3. **The copy protection.** How the original protection works, in depth. Tell what the loader left in memory, and explain each check and where the program hides it. Tell what happens when a check fails. Tell which parts of it each release still has, and how the rebuild turns it off. Link the copy protection page (section 7) for the full details.
13
+ 3. **The copy protection.** How the original protection works, in depth. Tell what the loader left in memory, and explain each check and where the program hides it. Tell what happens when a check fails, and how the rebuild turns it off. Link the copy protection page (section 7) for the full details.
14
14
  4. **Findings.** The bugs and the facts that a reader does not expect. Write a bulleted list, not a table. Each item has a title in bold, the facts and the evidence. It also has a link to the page with the details. Then tell what the finding means in practice. Examples are what a player sees, what a test or a fix can use, and what a preservation project must know. Mark an idea that no run showed as **Conclusion**.
15
15
  5. **How the program works.** A short walk through the program, from the start to the main loop. Tell what the program does at each stage and why. Use one mermaid diagram of the layers and one of the flow of the player. Under the diagrams, a numbered list tells how the layers work together. Link only the entry of each layer, for example the cold start, the main loop and the interrupt. Use about 5 to 8 links in the full section.
16
16
  6. **The pages.** A table with one row for each page: the link and one sentence about its content. The sentences have no links to the code.
17
- 7. **Releases and cracks.** The known releases, what each crack changed, and what a preservation project must know. Give a summary here. When the facts fill more than a screen, put them on a releases page (section 8) and link it.
17
+ 7. **The releases.** A short section. A small table gives each known release: the label, the file and the SHA-256 of the file. Then one line for each crack tells what it adds around the program, and the bytes of the program that it changed. Do not describe the intro, the mover or the relocator of a crack in detail. They are not part of the program.
18
18
  8. **The rebuild.** Which release is the base release, the program of the knowledge. Which changes of the release to the machine state stay, and how the loader sets them. A table of the switches from `knowledge.ts switches`: the name, the kind, the default and the releases that have the switch on. How to build the default program and each release. Which scenarios compare the original with the rebuild.
19
19
  9. **Still open.** What is not known yet, and which run can find it.
20
20
  10. **The reference.** One line with a link to `docs/reference/index.md`.
@@ -40,7 +40,7 @@ Look for findings of these kinds. They are often the most useful to a reader:
40
40
 
41
41
  ## The copy protection
42
42
 
43
- <Several paragraphs: the marks of the loader, each check, what a failed check does, and the state in each release.> The details are on [docs/protection.md](docs/protection.md).
43
+ <Several paragraphs: the marks of the loader, each check, and what a failed check does.> The details are on [docs/protection.md](docs/protection.md).
44
44
 
45
45
  ## Findings
46
46
 
@@ -66,9 +66,9 @@ flowchart TB
66
66
  |---|---|
67
67
  | [docs/main_loop.md](docs/main_loop.md) | **The main loop.** <one sentence> |
68
68
 
69
- ## Releases and cracks
69
+ ## The releases
70
70
 
71
- <Summary, or a link to docs/releases.md.>
71
+ <A small table of the releases, and one line for each crack.>
72
72
 
73
73
  ## The rebuild
74
74
 
@@ -102,7 +102,7 @@ Reverse-engineered C64 games. Each game has its own folder with the original dis
102
102
  One page for each subsystem, for example the main loop, the interrupt chain, the room generation or the sound player. It has these parts:
103
103
 
104
104
  1. **What it does.** One paragraph in the words of the program. Tell what the subsystem does for the player and why the program needs it. Do not list the routines.
105
- 2. **The conventions.** The terms of the page, for example "a pass is one run of the main loop". Use the conventions block of section 9.
105
+ 2. **The conventions.** The terms of the page, for example "a pass is one run of the main loop". Use the conventions block of section 8.
106
106
  3. **How it works.** A small mermaid flowchart, then the explanation in prose. Put a fact that a reader does not expect into the text where it belongs. The findings of the entry page link to it. Link the entry routine of the subsystem one time. For the main routine, give a numbered list of what it does and why, in the order of the code. Name a helper routine only when the reader needs it. Add pseudo-code when a loop or a condition is not clear from the list.
107
107
  4. **The data.** Only the data that a reader needs to understand the subsystem. For each structure, give the layout: the bytes, the entries and the meaning of each byte. The reference lists every variable, so do not make a table of each variable.
108
108
  5. **The state machine.** For code that changes from one state to another: a mermaid `stateDiagram-v2` and a transition table. The transition table has the state, the condition, the next state and the name of the code that makes the change, without a link.
@@ -178,21 +178,11 @@ One page, `docs/protection.md`, that explains the copy protection of the program
178
178
  1. **The scheme.** How the original protection works as a whole. Tell about the disk or the loader, and the marks that the loader leaves in memory. Tell which keys the program compares.
179
179
  2. **Each check.** For each check, tell where it is and when it runs. Tell what it compares, and how the program hides it. Link the code of the check one time. Use a table for a summary of the checks, without links.
180
180
  3. **The effect of a failed check.** What the program does when a check fails. Examples are a crash at once, a slow change of code, damaged data and a wipe of memory. Tell how long the effect takes to show.
181
- 4. **The releases.** What each crack did to the protection: removed it, set the marks again, or left it as it is. Tell which checks still run in each release.
181
+ 4. **The releases.** In one or two sentences: which checks still run in each release.
182
182
  5. **The rebuild.** The switch that turns the protection off, the bytes that it changes, and the scenarios that show that the program runs without it.
183
183
  6. **Still open.** The checks that no run reached, and the run that can reach them.
184
184
 
185
- ## 8. The releases page
186
-
187
- One page, `docs/releases.md`, for the releases of the program and the facts that a preservation project needs. Get the differences from `provenance.ts compare` of c64-provenance, and the crack stages from c64-unpacker. It has these parts:
188
-
189
- 1. **The known releases.** A table with one row for each release. A row gives the label, the disk image, the file, the group, the date and the SHA-256 of the file. The file is the file of the release, for example the PRG on the disk. Write "unknown" for a value that no source gives.
190
- 2. **The original.** Which release is nearest to the original program, and the evidence. Tell what is missing, for example the original loader or a release without a crack.
191
- 3. **The cracks.** For each crack: the intro, the mover, the relocator, the packer, a trainer and the texts that it changed. Tell what the crack did to the copy protection, and link the copy protection page.
192
- 4. **Traces of other people.** A release made from another crack, a memory dump of a program that ran, or tools on the disk.
193
- 5. **The differences.** A table of the bytes where the releases differ, what each difference does, and the switch that gives it in the rebuild.
194
-
195
- ## 9. The conventions block
185
+ ## 8. The conventions block
196
186
 
197
187
  Put this block near the top of each subsystem page. Change the terms for the program.
198
188
 
package/src/host/main.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env tsx
2
2
 
3
+ import { constants } from "node:os";
3
4
  import { parseArgs } from "node:util";
4
5
 
5
6
  import { DEFAULT_HOST_PORT } from "../protocol/messages.ts";
@@ -138,7 +139,8 @@ async function main(): Promise<number> {
138
139
  process.stdout.write(`c64-re-tools-host listening on ${address}\n`);
139
140
  trace().event("host.listening", { addresses: [address] });
140
141
 
141
- trace().event("host.stop", { signal: await stopSignal(log) });
142
+ // A second signal exits at once: the exit guard SIGKILLs every group that is still running.
143
+ trace().event("host.stop", { signal: await stopSignal(log, (signal) => process.exit(128 + constants.signals[signal])) });
142
144
  await server.close();
143
145
  await supervisor.stopAll();
144
146
  return 0;
@@ -308,24 +308,24 @@ export function parsePort(text: string): number | undefined {
308
308
  }
309
309
 
310
310
  /**
311
- * Resolves with the first SIGINT or SIGTERM. The handlers stay: a later
312
- * signal is logged and ignored, so a second Ctrl+C cannot cut the shutdown
313
- * short before every emulator and tool is stopped.
311
+ * Resolves with the first SIGINT, SIGTERM or SIGHUP. The handlers stay: a
312
+ * later signal is logged and calls again, which stops the host at once
313
+ * instead of waiting for the graceful stop of each emulator and tool.
314
314
  */
315
- export function stopSignal(log: (line: string) => void): Promise<NodeJS.Signals> {
315
+ export function stopSignal(log: (line: string) => void, again: (signal: NodeJS.Signals) => void): Promise<NodeJS.Signals> {
316
316
  return new Promise((resolve) => {
317
317
  let stopping = false;
318
318
  const stop = (signal: NodeJS.Signals) => {
319
319
  if (stopping) {
320
- log(`received ${signal} again; the host is already stopping`);
320
+ log(`received ${signal} again; stopping at once`);
321
+ again(signal);
321
322
  return;
322
323
  }
323
324
  stopping = true;
324
325
  log(`received ${signal}, stopping`);
325
326
  resolve(signal);
326
327
  };
327
- process.on("SIGINT", stop);
328
- process.on("SIGTERM", stop);
328
+ for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"] as const) process.on(signal, stop);
329
329
  });
330
330
  }
331
331
 
@@ -288,7 +288,9 @@ export class ViceSession implements ViceSessionHandle {
288
288
  /**
289
289
  * A VICE ended or dropped its monitor without the session asking. A window
290
290
  * VICE goes back headless from the state of when the window opened;
291
- * any other loss is final.
291
+ * any other loss is final, and the lost VICE is stopped at once: a VICE
292
+ * that hangs without its monitor ends, and its group and scratch directory
293
+ * do not wait for the session to close.
292
294
  */
293
295
  #ended(vice: ViceProcess, why: string): void {
294
296
  if (this.#closed || this.#vice !== vice || this.#lost || this.#windowClosing) return;
@@ -302,6 +304,7 @@ export class ViceSession implements ViceSessionHandle {
302
304
  return;
303
305
  }
304
306
  this.#lost = true;
307
+ void vice.stop().catch((error: unknown) => this.#log(`stopping the lost VICE failed: ${error instanceof Error ? error.message : String(error)}`));
305
308
  }
306
309
 
307
310
  /** Restarts headless from the handover saved when the window opened. */
package/src/mcp/main.ts CHANGED
@@ -123,10 +123,10 @@ async function main(): Promise<void> {
123
123
  process.exit(0);
124
124
  };
125
125
  // The harness ends the server by closing stdin or by a signal; both end the session and its emulator.
126
+ // Only the client holds the writing end of stdin: its end, close or error means that the client is gone.
126
127
  server.onclose = () => void stop();
127
- process.stdin.once("end", () => void stop());
128
- process.once("SIGINT", () => void stop());
129
- process.once("SIGTERM", () => void stop());
128
+ for (const event of ["end", "close", "error"] as const) process.stdin.once(event, () => void stop());
129
+ for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"] as const) process.once(signal, () => void stop());
130
130
 
131
131
  await server.connect(new StdioServerTransport());
132
132
  }
@@ -18,6 +18,21 @@ export const C64RUN_PROTOCOL = 2;
18
18
  export const PAL_FRAME_CYCLES = 19_656;
19
19
 
20
20
  const STOP_MS = 5_000;
21
+ /** How long c64run may take to answer a command, beyond the run up to a target tick. */
22
+ const COMMAND_MS = 30_000;
23
+ /** The slowest run that a command limit allows for: c64run runs about 6 million cycles per second. */
24
+ const SLOWEST_CYCLES_PER_SECOND = 1_000_000;
25
+
26
+ /**
27
+ * The time limit of a command, so that a core that hangs cannot keep the
28
+ * script running. run, run-pc and run-reads end with the absolute tick that
29
+ * they run to at most; the others answer at once.
30
+ */
31
+ export function commandLimitMs(text: string): number {
32
+ const [name, ...rest] = text.split(" ");
33
+ const target = name === "run" || name === "run-pc" || name === "run-reads" ? Number(rest.at(-1)) : 0;
34
+ return COMMAND_MS + (Number.isFinite(target) ? (target * 1000) / SLOWEST_CYCLES_PER_SECOND : 0);
35
+ }
21
36
 
22
37
  /** The machine state that most commands answer with. */
23
38
  export interface CoreStatus {
@@ -82,7 +97,8 @@ export class C64RunSession {
82
97
  createInterface({ input: child.stdout! }).on("line", (line) => this.#waiting.shift()?.resolve(line));
83
98
  void process.exited.then((status) => {
84
99
  const how = status.spawnError !== undefined ? `did not start (${status.spawnError})` : `ended (exit ${status.code ?? status.signal})`;
85
- this.#ended = new WireFailure(status.spawnError !== undefined ? "installation-incomplete" : "operation-failed", `c64run ${how}.${this.#stderr === "" ? "" : ` ${this.#stderr.trim()}`}`);
100
+ // A core stopped because it did not answer keeps that reason.
101
+ this.#ended ??= new WireFailure(status.spawnError !== undefined ? "installation-incomplete" : "operation-failed", `c64run ${how}.${this.#stderr === "" ? "" : ` ${this.#stderr.trim()}`}`);
86
102
  for (const waiting of this.#waiting.splice(0)) waiting.reject(this.#ended);
87
103
  });
88
104
  }
@@ -103,10 +119,24 @@ export class C64RunSession {
103
119
  return session;
104
120
  }
105
121
 
106
- /** Sends one command and gives its "ok ..." answer. An "err ..." answer throws operation-failed. */
107
- command(text: string): Promise<string> {
122
+ /**
123
+ * Sends one command and gives its "ok ..." answer. An "err ..." answer throws operation-failed.
124
+ * A core that does not answer within the limit is stopped: every command then fails.
125
+ */
126
+ command(text: string, limitMs = commandLimitMs(text)): Promise<string> {
108
127
  if (this.#ended !== undefined) return Promise.reject(this.#ended);
109
- const answer = new Promise<string>((resolve, reject) => this.#waiting.push({ resolve, reject }));
128
+ const answer = new Promise<string>((resolve, reject) => {
129
+ const timer = setTimeout(() => {
130
+ this.#ended = new WireFailure("operation-failed", `c64run ${text.split(" ")[0]} did not answer in ${Math.ceil(limitMs / 1000)} s; the core is stopped.`);
131
+ for (const waiting of this.#waiting.splice(0)) waiting.reject(this.#ended);
132
+ void this.#process.stop().catch(() => {});
133
+ }, limitMs);
134
+ const done = () => clearTimeout(timer);
135
+ this.#waiting.push({
136
+ resolve: (line) => (done(), resolve(line)),
137
+ reject: (error) => (done(), reject(error)),
138
+ });
139
+ });
110
140
  this.#process.child.stdin!.write(`${text}\n`);
111
141
  return answer.then((line) => {
112
142
  if (line.startsWith("ok")) return line;
@@ -1,6 +1,6 @@
1
1
  // The context for running native tools inside a skill script or the CLI:
2
2
  // one supervisor whose exit guard stops every tool process group when
3
- // the script ends, also on Ctrl+C or SIGTERM, and whose watchdog does the same
3
+ // the script ends, also on Ctrl+C, SIGTERM or SIGHUP, and whose watchdog does the same
4
4
  // when the script dies without its exit guard, for example by SIGKILL.
5
5
  // A line that a tool adapter logs goes to the trace of the script.
6
6
 
@@ -23,7 +23,7 @@ export function localToolContext(): LocalToolContext {
23
23
  supervisor.startWatchdog("skill-script");
24
24
  const controller = new AbortController();
25
25
  // A signal ends the script through process.exit, so the exit guard runs.
26
- for (const [signal, code] of [["SIGINT", 130], ["SIGTERM", 143]] as const) {
26
+ for (const [signal, code] of [["SIGINT", 130], ["SIGTERM", 143], ["SIGHUP", 129]] as const) {
27
27
  process.once(signal, () => {
28
28
  controller.abort();
29
29
  process.exit(code);
@@ -1,6 +1,6 @@
1
1
  import { spawn, spawnSync, type ChildProcess, type StdioOptions } from "node:child_process";
2
2
  import type { Writable } from "node:stream";
3
- import { mkdtempSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
3
+ import { existsSync, mkdtempSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
4
4
  import { tmpdir } from "node:os";
5
5
  import { join } from "node:path";
6
6
  import { setTimeout as sleep } from "node:timers/promises";
@@ -14,6 +14,8 @@ export const STOP_GRACE_MS = 5_000;
14
14
  /** How long to wait for the group to vanish after SIGKILL before giving up. */
15
15
  const KILL_WAIT_MS = 2_000;
16
16
  const POLL_MS = 25;
17
+ /** How many times a killed watchdog is replaced. A watchdog that cannot run at all must not start new ones forever. */
18
+ const WATCHDOG_RESPAWNS = 5;
17
19
 
18
20
  export interface SpawnOptions {
19
21
  cwd?: string;
@@ -170,6 +172,7 @@ export class ProcessSupervisor {
170
172
  /** The registry file that the watchdog reads, once a watchdog runs. */
171
173
  #registry: string | undefined;
172
174
  #watchdogPid: number | undefined;
175
+ #watchdogRespawns = 0;
173
176
  /** The writing end of the watchdog's pipe. Kept open until this process ends: its end tells the watchdog that this process is gone. */
174
177
  #watchdogPipe: Writable | undefined;
175
178
 
@@ -270,10 +273,20 @@ export class ProcessSupervisor {
270
273
  const directory = mkdtempSync(join(tmpdir(), `c64-re-tools-${owner}-watchdog-`));
271
274
  this.#registry = join(directory, "registry.json");
272
275
  this.#writeRegistry();
276
+ this.#spawnWatchdog(this.#registry);
277
+ this.installExitGuard();
278
+ }
279
+
280
+ /**
281
+ * A watchdog that ends while its registry is still there did not end by
282
+ * itself (it removes the registry when it cleans up, as the exit guard does):
283
+ * something killed it. A new one takes over the same registry, a few times at most.
284
+ */
285
+ #spawnWatchdog(registry: string): void {
273
286
  // The watchdog runs in the temporary directory, never in the caller's directory: Windows refuses
274
287
  // to remove a directory that a running process uses. Its standard input is a pipe from this
275
288
  // process, which the system closes when this process ends.
276
- const watchdog = spawn(process.execPath, [...process.execArgv, WATCHDOG, String(process.pid), this.#registry], { cwd: tmpdir(), detached: true, stdio: ["pipe", "ignore", "ignore"], windowsHide: true });
289
+ const watchdog = spawn(process.execPath, [...process.execArgv, WATCHDOG, String(process.pid), registry], { cwd: tmpdir(), detached: true, stdio: ["pipe", "ignore", "ignore"], windowsHide: true });
277
290
  watchdog.unref();
278
291
  // The pipe does not keep this process running, and an error on it does not end this process.
279
292
  const pipe = watchdog.stdin as (Writable & { unref?: () => void }) | null;
@@ -281,7 +294,11 @@ export class ProcessSupervisor {
281
294
  pipe?.unref?.();
282
295
  this.#watchdogPipe = pipe ?? undefined;
283
296
  this.#watchdogPid = watchdog.pid;
284
- this.installExitGuard();
297
+ watchdog.once("exit", () => {
298
+ if (!existsSync(registry) || this.#watchdogRespawns >= WATCHDOG_RESPAWNS) return;
299
+ this.#watchdogRespawns++;
300
+ this.#spawnWatchdog(registry);
301
+ });
285
302
  }
286
303
 
287
304
  #writeRegistry(): void {