agent-dag 1.33.52 → 1.33.53

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/bin/agent-dag.js CHANGED
@@ -28,11 +28,8 @@ import { dirname, join } from "node:path";
28
28
  import { fileURLToPath } from "node:url";
29
29
  import { spawnSpec } from "../src/server/exec.mjs";
30
30
  import { installedVersion, npxRestartSpec } from "../src/server/self-update.mjs";
31
+ import { workerExitAction } from "../src/server/supervisor.mjs";
31
32
 
32
- // Chosen because they mean nothing else here: the worker exits 0 normally and
33
- // non-zero on failure, both of which must pass straight through.
34
- const RESTART_CODE = 75; // come back running the files on disk
35
- const UPGRADE_CODE = 76; // come back through npx, which fetches newer files
36
33
  const BIN_DIR = dirname(fileURLToPath(import.meta.url));
37
34
  const WORKER = join(BIN_DIR, "deck.js");
38
35
  const PKG_ROOT = dirname(BIN_DIR);
@@ -49,9 +46,10 @@ const VERSION = installedVersion(PKG_ROOT) ?? "?";
49
46
  let boundPort = null;
50
47
  let restarts = 0;
51
48
  let child = null;
52
- // Set by the signal handlers. Without it, Ctrl+C during an npx fetch looks
53
- // exactly like a failed fetch, and the fallback below would resurrect the deck
54
- // the user just stopped.
49
+ // Set by the signal handlers, and the first thing every exit path asks. Without
50
+ // it, Ctrl+C during an npx fetch looks exactly like a failed fetch, and a
51
+ // worker that was already exiting 75 or 76 when the signal landed reads as a
52
+ // restart request — both resurrect the deck the user just stopped.
55
53
  let stopping = false;
56
54
 
57
55
  function launch(respawn) {
@@ -81,12 +79,16 @@ function launch(respawn) {
81
79
 
82
80
  child.on("exit", (code, signal) => {
83
81
  child = null;
84
- if (code === RESTART_CODE) {
82
+ // `stopping` outranks the exit code see supervisor.mjs. A restart and a
83
+ // Ctrl+C can land together, and honouring the code first is how the deck
84
+ // came back to life after the user stopped it.
85
+ const next = workerExitAction(code, stopping);
86
+ if (next.relaunch === "disk") {
85
87
  restarts++;
86
88
  launch(true);
87
89
  return;
88
90
  }
89
- if (code === UPGRADE_CODE) {
91
+ if (next.relaunch === "npx") {
90
92
  restarts++;
91
93
  launchNpx();
92
94
  return;
@@ -94,7 +96,7 @@ function launch(respawn) {
94
96
  // Anything else is the worker's own verdict and belongs to whoever started
95
97
  // us — including the ccdeck wrapper, which exits with our code in turn.
96
98
  if (signal) process.kill(process.pid, signal);
97
- else process.exit(code ?? 0);
99
+ else process.exit(next.code);
98
100
  });
99
101
 
100
102
  child.on("error", (err) => {