@nice-code/commander 0.91.0 → 0.92.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -47,6 +47,10 @@ bunx nice-commander down dev
47
47
  Every acting command takes the same selector — ids, group names, or `tag=value` terms (AND across
48
48
  terms). `up --dry-run` and `explain` show exactly what would be touched, without touching it.
49
49
 
50
+ The GUI’s **shutdown daemon** button stops every task and service managed by that daemon,
51
+ including processes hidden by filters or groups, then exits the daemon. Confirm the dialog to
52
+ proceed. Run `nice-commander ui` to start it again.
53
+
50
54
  ## What it does that a script does not
51
55
 
52
56
  - **`dependsOn` waits for *ready*, not for *spawned*** — a real readiness contract (port, HTTP,
@@ -64,6 +68,13 @@ terms). `up --dry-run` and `explain` show exactly what would be touched, without
64
68
  Node ≥ 22 or Bun. The web UI is pre-built into the package; Vite and React are not installed on
65
69
  your machine. Built on [`@nice-code/process`](https://www.npmjs.com/package/@nice-code/process).
66
70
 
71
+ `bunx nice-commander` follows the executable's Node shebang, so it still needs Node ≥ 22.
72
+ Use `bunx --bun nice-commander` to explicitly run with Bun. An older Node can serve the UI
73
+ but fail its authenticated WebSocket handshake, leaving the CLI and browser waiting for the
74
+ status realm. After upgrading your runtime, run `nice-commander shutdown` (this stops managed
75
+ processes), then retry, so an existing daemon is replaced too. No extra environment variables
76
+ are needed.
77
+
67
78
  ## Developing the web UI (`bun run dev`)
68
79
 
69
80
  Editing the UI needs a fast loop, so the package ships a dev harness: `bun run dev` (from
package/build/cli.cjs CHANGED
@@ -9217,6 +9217,8 @@ var AcceptorSecureSession = class {
9217
9217
  _pipe;
9218
9218
  _authed = false;
9219
9219
  _plain = false;
9220
+ _handshakeStarted = false;
9221
+ _handshakeFailed = false;
9220
9222
  /** The channel tags the client advertised in its `hello`, captured for the handler's codec selection. */
9221
9223
  _helloChannels;
9222
9224
  /** Serializes inbound processing (handshake + decryption are async). */
@@ -9230,7 +9232,19 @@ var AcceptorSecureSession = class {
9230
9232
  * acceptor and carried through here because only the decrypted frame reveals its lane.
9231
9233
  */
9232
9234
  receive(frame, wireBytes) {
9233
- this._inboundChain = this._inboundChain.then(() => this._receive(frame, wireBytes)).catch((err) => console.error("[ws-server] failed to process inbound frame", err));
9235
+ this._inboundChain = this._inboundChain.then(() => {
9236
+ if (!this._handshakeFailed) return this._receive(frame, wireBytes);
9237
+ }).catch((err) => {
9238
+ console.error("[ws-server] failed to process inbound frame", err);
9239
+ if (!this._handshakeStarted || this._authed || this._handshakeFailed) return;
9240
+ this._handshakeFailed = true;
9241
+ try {
9242
+ this.config.send(encodeHandshakeMessage({
9243
+ t: "reject",
9244
+ reason: "server handshake failed; check server logs"
9245
+ }));
9246
+ } catch {}
9247
+ });
9234
9248
  }
9235
9249
  async _receive(frame, wireBytes) {
9236
9250
  if (this._plain) {
@@ -9251,6 +9265,7 @@ var AcceptorSecureSession = class {
9251
9265
  bytes: wireBytes ?? 0,
9252
9266
  lane: "handshake"
9253
9267
  });
9268
+ this._handshakeStarted = true;
9254
9269
  await this.config.link.initialize();
9255
9270
  if (this._handshake == null) this._handshake = createServerHandshake({
9256
9271
  link: this.config.link,
@@ -23333,6 +23348,13 @@ async function commanderPackageVersion() {
23333
23348
  return cached;
23334
23349
  }
23335
23350
  //#endregion
23351
+ //#region src/daemon/runtime.ts
23352
+ /** Check before advertising a daemon whose HTTP works but whose wire handshake cannot run. */
23353
+ function commanderRuntimeError() {
23354
+ const runtime = process.versions.bun == null ? `Node ${process.version}` : `Bun ${process.versions.bun}`;
23355
+ if (process.versions.bun == null && Number(process.versions.node.split(".")[0]) < 22 || globalThis.crypto?.subtle == null || typeof globalThis.WebSocket !== "function") return `nice-commander requires Node >=22 or a current Bun with Web Crypto and WebSocket support; running ${runtime} (${process.execPath}). Upgrade Node, or run \`bunx --bun nice-commander\`. Plain \`bunx\` follows the binary's node shebang. If a daemon is already running, run \`nice-commander shutdown\` before retrying; shutdown stops its managed processes.`;
23356
+ }
23357
+ //#endregion
23336
23358
  //#region src/protocol/statusRealm.ts
23337
23359
  /**
23338
23360
  * Read-only viewer for every authenticated identity — control authority lives in the ticket
@@ -23566,6 +23588,8 @@ async function replaceSkewedDaemon(paths, skewed) {
23566
23588
  }
23567
23589
  }
23568
23590
  async function ensureDaemon(options) {
23591
+ const runtimeError = commanderRuntimeError();
23592
+ if (runtimeError != null) throw new Error(runtimeError);
23569
23593
  const dataDir = options.dataDir != null ? (0, node_path.resolve)(options.dataDir) : resolveCommanderDataDir();
23570
23594
  const paths = commanderStatePaths(dataDir, options.config.configKey);
23571
23595
  const timeoutMs = options.handshakeTimeoutMs ?? HANDSHAKE_TIMEOUT_MS;
@@ -23840,6 +23864,20 @@ const commanderChannel = defineChannel({
23840
23864
  toConnector: []
23841
23865
  });
23842
23866
  //#endregion
23867
+ //#region src/protocol/waitForStatusRealm.ts
23868
+ /** Retain cold-start retries, but report a failed dial instead of hiding it behind hydration. */
23869
+ async function waitForStatusRealm(connector, realm, timeoutMs) {
23870
+ let connectionError;
23871
+ connector.connect().catch((error) => {
23872
+ connectionError = error;
23873
+ });
23874
+ try {
23875
+ await realm.whenLive({ timeoutMs });
23876
+ } catch (error) {
23877
+ throw realm.attachError ?? connectionError ?? error;
23878
+ }
23879
+ }
23880
+ //#endregion
23843
23881
  //#region src/cli/daemonClient.ts
23844
23882
  /** The running daemon for this config, or null (dead record, failed ping, nothing on disk). */
23845
23883
  async function findDaemon(config) {
@@ -23906,6 +23944,8 @@ async function mintTicket(record) {
23906
23944
  return body.ticket;
23907
23945
  }
23908
23946
  async function connectDaemon(handle) {
23947
+ const runtimeError = commanderRuntimeError();
23948
+ if (runtimeError != null) throw new CliExit(EXIT.failure, runtimeError);
23909
23949
  const { record } = handle;
23910
23950
  if (record.realmSchemaHash !== commanderStatusRealm.schemaHash) throw new CliExit(EXIT.failure, `the daemon for this config (pid ${record.pid}, build ${record.packageVersion}) was started before an upgrade changed the status schema — this CLI (build ${await commanderPackageVersion()}) cannot read its state. Run \`nice-commander shutdown\` (it stops a daemon from any build), then retry.`);
23911
23951
  const ticket = await mintTicket(record);
@@ -23939,12 +23979,12 @@ async function connectDaemon(handle) {
23939
23979
  connection: realmConnection(connector),
23940
23980
  assertOnAttach: () => {}
23941
23981
  });
23942
- connector.connect().catch(() => {});
23943
23982
  try {
23944
- await realm.whenLive({ timeoutMs: 1e4 });
23945
- } catch {
23983
+ await waitForStatusRealm(connector, realm, 1e4);
23984
+ } catch (error) {
23985
+ realm.detach();
23946
23986
  connector.dispose();
23947
- const reason = realm.attachError != null ? String(realm.attachError) : "timeout";
23987
+ const reason = String(error);
23948
23988
  const hint = reason.includes("schema_mismatch") ? ` The daemon (pid ${record.pid}, build ${record.packageVersion}) and this CLI were built from different realm definitions — run \`nice-commander shutdown\` (it stops a daemon from any build), then retry.` : "";
23949
23989
  throw new CliExit(EXIT.failure, `could not attach the status realm (${reason}).${hint}`);
23950
23990
  }
@@ -25526,7 +25566,7 @@ async function withTimeout(ctx, run) {
25526
25566
  async function main() {
25527
25567
  const argv = process.argv.slice(2);
25528
25568
  if (argv[0] === "daemon") {
25529
- const { runCommanderDaemon } = await Promise.resolve().then(() => require("./main-Cf9OmhIY.cjs"));
25569
+ const { runCommanderDaemon } = await Promise.resolve().then(() => require("./main-B_0GjEIc.cjs"));
25530
25570
  return runCommanderDaemon(argv.slice(1));
25531
25571
  }
25532
25572
  const parsed = parseCliArgs(argv);
@@ -25582,6 +25622,7 @@ exports.applyEnvMutation = applyEnvMutation;
25582
25622
  exports.commanderChannel = commanderChannel;
25583
25623
  exports.commanderControlDomain = commanderControlDomain;
25584
25624
  exports.commanderPackageVersion = commanderPackageVersion;
25625
+ exports.commanderRuntimeError = commanderRuntimeError;
25585
25626
  exports.commanderStatePaths = commanderStatePaths;
25586
25627
  exports.commanderStatusRealm = commanderStatusRealm;
25587
25628
  exports.countOverrides = countOverrides;