@nice-code/commander 0.72.0 → 0.73.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/build/cli.cjs CHANGED
@@ -1103,6 +1103,45 @@ function getNiceErrorLogger() {
1103
1103
  return activeLogger;
1104
1104
  }
1105
1105
  //#endregion
1106
+ //#region ../nice-error/src/NiceError/nice_error.static.ts
1107
+ const DUR_OBJ_PACK_PREFIX = "NE_DUROBJ[[";
1108
+ const DUR_OBJ_PACK_SUFFIX = "]]NE_DUROBJ";
1109
+ /**
1110
+ * The domain of the generic wrapper `castNiceError` produces for anything that
1111
+ * wasn't already a `NiceError` (native throws, error-like objects, nullish,
1112
+ * primitives). `NiceError.isUnhandled` is defined as "belongs to this domain" —
1113
+ * i.e. an error we never accounted for and had to wrap. Kept here (not imported
1114
+ * from `nice_core_errors`) so `NiceError` can reference it without an import cycle.
1115
+ */
1116
+ const ERR_CAST_NOT_NICE_DOMAIN = "err_cast_not_nice";
1117
+ //#endregion
1118
+ //#region ../nice-error/src/utils/packError/causePack.ts
1119
+ const causePack = (error) => {
1120
+ error._packedState = {
1121
+ cause: error.cause,
1122
+ packedAs: "cause_pack"
1123
+ };
1124
+ error.cause = `${DUR_OBJ_PACK_PREFIX}${JSON.stringify(error.toJsonObject())}${DUR_OBJ_PACK_SUFFIX}`;
1125
+ return error;
1126
+ };
1127
+ //#endregion
1128
+ //#region ../nice-error/src/utils/packError/msgPack.ts
1129
+ const msgPack = (error) => {
1130
+ error._packedState = {
1131
+ message: error.cleanMessage,
1132
+ packedAs: "msg_pack"
1133
+ };
1134
+ error.message = `${DUR_OBJ_PACK_PREFIX}${JSON.stringify(error.toJsonObject())}${DUR_OBJ_PACK_SUFFIX}`;
1135
+ return error;
1136
+ };
1137
+ //#endregion
1138
+ //#region ../nice-error/src/utils/packError/packError.ts
1139
+ const packError = (error, packType = "msg_pack") => {
1140
+ if (packType === "no_pack") return error;
1141
+ if (packType === "msg_pack") return msgPack(error);
1142
+ return causePack(error);
1143
+ };
1144
+ //#endregion
1106
1145
  //#region ../nice-error/src/utils/serializeErrorCause.ts
1107
1146
  /**
1108
1147
  * JSON-safe serialization of an error `cause` (and `AggregateError.errors`),
@@ -1143,45 +1182,6 @@ function serializeErrorCause(value, depth = DEFAULT_CAUSE_DEPTH) {
1143
1182
  }
1144
1183
  }
1145
1184
  //#endregion
1146
- //#region ../nice-error/src/NiceError/nice_error.static.ts
1147
- const DUR_OBJ_PACK_PREFIX = "NE_DUROBJ[[";
1148
- const DUR_OBJ_PACK_SUFFIX = "]]NE_DUROBJ";
1149
- /**
1150
- * The domain of the generic wrapper `castNiceError` produces for anything that
1151
- * wasn't already a `NiceError` (native throws, error-like objects, nullish,
1152
- * primitives). `NiceError.isUnhandled` is defined as "belongs to this domain" —
1153
- * i.e. an error we never accounted for and had to wrap. Kept here (not imported
1154
- * from `nice_core_errors`) so `NiceError` can reference it without an import cycle.
1155
- */
1156
- const ERR_CAST_NOT_NICE_DOMAIN = "err_cast_not_nice";
1157
- //#endregion
1158
- //#region ../nice-error/src/utils/packError/causePack.ts
1159
- const causePack = (error) => {
1160
- error._packedState = {
1161
- cause: error.cause,
1162
- packedAs: "cause_pack"
1163
- };
1164
- error.cause = `${DUR_OBJ_PACK_PREFIX}${JSON.stringify(error.toJsonObject())}${DUR_OBJ_PACK_SUFFIX}`;
1165
- return error;
1166
- };
1167
- //#endregion
1168
- //#region ../nice-error/src/utils/packError/msgPack.ts
1169
- const msgPack = (error) => {
1170
- error._packedState = {
1171
- message: error.cleanMessage,
1172
- packedAs: "msg_pack"
1173
- };
1174
- error.message = `${DUR_OBJ_PACK_PREFIX}${JSON.stringify(error.toJsonObject())}${DUR_OBJ_PACK_SUFFIX}`;
1175
- return error;
1176
- };
1177
- //#endregion
1178
- //#region ../nice-error/src/utils/packError/packError.ts
1179
- const packError = (error, packType = "msg_pack") => {
1180
- if (packType === "no_pack") return error;
1181
- if (packType === "msg_pack") return msgPack(error);
1182
- return causePack(error);
1183
- };
1184
- //#endregion
1185
1185
  //#region ../nice-error/src/NiceError/NiceError.ts
1186
1186
  var NiceError = class extends Error {
1187
1187
  name = "NiceError";
@@ -5168,256 +5168,6 @@ dropLink: async (opts) => {
5168
5168
  }
5169
5169
  };
5170
5170
  //#endregion
5171
- //#region ../nice-wire/src/Mux/protocolFrame.ts
5172
- /**
5173
- * Frame-protocol prefix bytes (realm plan §3.1). A registered protocol frame is
5174
- * `[prefixByte, ...payload]` with the prefix drawn from the reserved range `0x00`–`0x0F` —
5175
- * bytes no legacy frame can start with: binary action envelopes are msgpack fixarrays
5176
- * (`0x96`–`0x98`), control frames are msgpack maps (`0x80`–`0x8f`, `0xde`, `0xdf`), and
5177
- * handshake frames are text JSON (`{` = `0x7b`). Frames without a reserved prefix fall through
5178
- * to the legacy sniffing untouched, so old peers stay byte-identical (pinned by the
5179
- * byte-compat goldens).
5180
- *
5181
- * The registry is **closed** — same philosophy as the control-message registry: protocols are
5182
- * library-level concerns assigned here, never user-claimable ad hoc.
5183
- */
5184
- const WIRE_PROTOCOL_PREFIX = {
5185
- /** `0x00` is reserved/invalid — a zero prefix is treated as a decode error, never dispatched. */
5186
- invalid: 0,
5187
- /** `@nice-code/realm` state-sync frames. */
5188
- realm: 1,
5189
- /**
5190
- * `@nice-code/devtools` observation frames. Assigned here so the prefix space has one
5191
- * authoritative catalogue; `@nice-code/devtools-core` (a zero-runtime-dependency package that
5192
- * cannot import wire) mirrors it structurally as its own `DEVTOOLS_WIRE_PREFIX = 0x02`.
5193
- */
5194
- devtools: 2
5195
- };
5196
- /**
5197
- * Peek a frame's protocol prefix: the byte when it is a binary frame starting in the reserved
5198
- * range, else `undefined` (a legacy frame — handshake/control/action — or a text frame).
5199
- */
5200
- function peekProtocolPrefix(frame) {
5201
- let first;
5202
- if (frame instanceof Uint8Array) first = frame.length > 0 ? frame[0] : void 0;
5203
- else if (frame instanceof ArrayBuffer) first = frame.byteLength > 0 ? new Uint8Array(frame, 0, 1)[0] : void 0;
5204
- else return void 0;
5205
- if (first == null || first > 15) return void 0;
5206
- return first;
5207
- }
5208
- /** Wrap a protocol payload with its prefix byte. */
5209
- function encodeProtocolFrame(prefixByte, payload) {
5210
- if (prefixByte <= 0 || prefixByte > 15) throw new Error(`encodeProtocolFrame: prefix 0x${prefixByte.toString(16)} outside reserved range`);
5211
- const framed = new Uint8Array(payload.length + 1);
5212
- framed[0] = prefixByte;
5213
- framed.set(payload, 1);
5214
- return framed;
5215
- }
5216
- /** The handshake capability tag advertising a frame protocol (`hello.caps` / `welcome.caps`). */
5217
- function protocolCap(protocolId) {
5218
- return `proto:${protocolId}`;
5219
- }
5220
- /** Extract the advertised protocol ids from a peer's handshake caps. */
5221
- function protocolsFromCaps(caps) {
5222
- const ids = /* @__PURE__ */ new Set();
5223
- for (const cap of caps ?? []) if (cap.startsWith("proto:")) ids.add(cap.slice(6));
5224
- return ids;
5225
- }
5226
- //#endregion
5227
- //#region ../nice-wire/src/Mux/WireProtocolMux.ts
5228
- var WireProtocolMux = class {
5229
- _byPrefix = /* @__PURE__ */ new Map();
5230
- _send;
5231
- _remoteProtocolIds = /* @__PURE__ */ new Set();
5232
- _attached = false;
5233
- /** Register a protocol (before or after attach; late registrants get an immediate attach). */
5234
- registerProtocol(protocol) {
5235
- if (this._attached) console.warn(`[wire] registerProtocol("${protocol.id}"): the connection is already attached — this protocol missed the handshake's caps advertisement and will not be resumed after a host wake. Register it before connecting.`);
5236
- if (protocol.prefixByte <= WIRE_PROTOCOL_PREFIX.invalid || protocol.prefixByte > 15) throw new Error(`registerProtocol("${protocol.id}"): prefix 0x${protocol.prefixByte.toString(16)} outside the reserved range`);
5237
- if (this._byPrefix.has(protocol.prefixByte)) throw new Error(`registerProtocol("${protocol.id}"): prefix 0x${protocol.prefixByte.toString(16)} already registered`);
5238
- const port = {
5239
- send: (payload) => {
5240
- if (!this._canSpeak(protocol)) throw new Error(`protocol "${protocol.id}": connection not attached or peer did not advertise "${protocolCap(protocol.id)}"`);
5241
- this._send?.(encodeProtocolFrame(protocol.prefixByte, payload));
5242
- },
5243
- isOpen: () => this._canSpeak(protocol)
5244
- };
5245
- this._byPrefix.set(protocol.prefixByte, {
5246
- protocol,
5247
- port
5248
- });
5249
- if (this._attached && this._canSpeak(protocol)) protocol.onAttach?.(port);
5250
- return port;
5251
- }
5252
- /** The `proto:<id>` caps to advertise in this side's handshake. */
5253
- localCaps() {
5254
- return [...this._byPrefix.values()].map(({ protocol }) => protocolCap(protocol.id));
5255
- }
5256
- /** Record the peer's advertised protocol ids (from its handshake caps). */
5257
- setRemoteProtocolIds(ids) {
5258
- this._remoteProtocolIds = ids;
5259
- }
5260
- /** Connection ready: give protocols their send path and fire attach for negotiated ones. */
5261
- attach(send) {
5262
- this._send = send;
5263
- this._attached = true;
5264
- for (const { protocol, port } of this._byPrefix.values()) if (this._canSpeak(protocol)) protocol.onAttach?.(port);
5265
- }
5266
- /** Connection lost: notify protocols; sends now throw until the next attach. */
5267
- detach() {
5268
- if (!this._attached) return;
5269
- this._attached = false;
5270
- this._send = void 0;
5271
- for (const { protocol } of this._byPrefix.values()) protocol.onDetach?.();
5272
- }
5273
- /**
5274
- * The registered protocol id a frame belongs to, by its prefix byte — `undefined` for a legacy
5275
- * (unprefixed) frame or an unregistered prefix. Attribution only (the wire-tap lane label);
5276
- * dispatch stays with {@link dispatchIncoming}.
5277
- */
5278
- protocolIdFor(frame) {
5279
- const prefix = peekProtocolPrefix(frame);
5280
- if (prefix == null) return void 0;
5281
- return this._byPrefix.get(prefix)?.protocol.id;
5282
- }
5283
- /**
5284
- * Offer one inbound (already-decrypted) frame. Returns `true` when consumed as a protocol
5285
- * frame — including an unknown/unregistered prefix, which is dropped (a prefixed frame is
5286
- * *never* a legacy frame, so falling through would mis-decode it).
5287
- */
5288
- dispatchIncoming(frame) {
5289
- const prefix = peekProtocolPrefix(frame);
5290
- if (prefix == null) return false;
5291
- const registered = this._byPrefix.get(prefix);
5292
- if (prefix === WIRE_PROTOCOL_PREFIX.invalid || registered == null) return true;
5293
- const bytes = frame instanceof Uint8Array ? frame : new Uint8Array(frame);
5294
- registered.protocol.onFrame(bytes.subarray(1), registered.port);
5295
- return true;
5296
- }
5297
- _canSpeak(protocol) {
5298
- return this._attached && this._remoteProtocolIds.has(protocol.id);
5299
- }
5300
- };
5301
- //#endregion
5302
- //#region ../nice-wire/src/tap/wireTap.ts
5303
- /**
5304
- * Wrap a tap so every event it receives is attributed to `linkId` unless the emitter already named
5305
- * one. This is how the **connector** side gets per-link attribution: an acceptor knows many peers
5306
- * and tags each frame with the bound client as it emits, whereas a connector has exactly one peer
5307
- * for the whole connection — so stamping once at the seam beats threading an id through the pipe,
5308
- * the session, the keepalive and the exchange carrier.
5309
- *
5310
- * Both ends therefore answer the same question with `linkId`: *who is on the other end of this
5311
- * frame*. A client's core can then split its traffic per backend it dials, exactly as a server's
5312
- * splits per client it serves.
5313
- */
5314
- function withLinkIdTap(tap, linkId) {
5315
- return (event) => {
5316
- tap(event.linkId != null ? event : {
5317
- ...event,
5318
- linkId
5319
- });
5320
- };
5321
- }
5322
- /**
5323
- * Wrap an exchange (HTTP) carrier so every request/reply pair is reported to the
5324
- * tap under the `"http"` lane — the exchange path's equivalent of the duplex
5325
- * session's pipe/dispatch taps. Envelope bytes as handed to the carrier (the
5326
- * HTTP layer's own headers are outside the library's sight and not counted).
5327
- */
5328
- function withExchangeTap(carrier, tap, linkId) {
5329
- return {
5330
- exchange: async (frame, opts) => {
5331
- tap({
5332
- dir: "out",
5333
- bytes: wireFrameByteSize(frame),
5334
- lane: "http",
5335
- linkId
5336
- });
5337
- const reply = await carrier.exchange(frame, opts);
5338
- tap({
5339
- dir: "in",
5340
- bytes: wireFrameByteSize(reply),
5341
- lane: "http",
5342
- linkId
5343
- });
5344
- return reply;
5345
- },
5346
- get label() {
5347
- return carrier.label;
5348
- }
5349
- };
5350
- }
5351
- let encoder;
5352
- /** The transmitted size of one frame: `byteLength` for binary, UTF-8 length for strings. */
5353
- function wireFrameByteSize(frame) {
5354
- if (typeof frame === "string") {
5355
- if (encoder == null) encoder = new TextEncoder();
5356
- return encoder.encode(frame).byteLength;
5357
- }
5358
- if (frame instanceof Uint8Array) return frame.byteLength;
5359
- if (frame instanceof ArrayBuffer) return frame.byteLength;
5360
- if (typeof SharedArrayBuffer !== "undefined" && frame instanceof SharedArrayBuffer) return frame.byteLength;
5361
- if (ArrayBuffer.isView(frame)) return frame.byteLength;
5362
- return 0;
5363
- }
5364
- //#endregion
5365
- //#region ../nice-wire/src/Connect/wireConnectionParts.ts
5366
- /** 8b.3 defaults: ≈20 s worst-case half-open detection, quiet enough for a healthy idle tab. */
5367
- const DEFAULT_LINK_KEEPALIVE_IDLE_MS = 15e3;
5368
- const DEFAULT_LINK_KEEPALIVE_PONG_TIMEOUT_MS = 5e3;
5369
- const ephemeralIdentityWarned = /* @__PURE__ */ new Set();
5370
- /**
5371
- * The ephemeral-identity trap (Inteleport feedback §1): a coordinate with a persistent id whose
5372
- * crypto identity lives in non-durable storage keys the peer's trust-on-first-use verify-key pin but
5373
- * regenerates a new key on every reload — so every reload after the first is rejected
5374
- * `identity_pin_mismatch`, forever. It type-checks and the first load works, so nothing else surfaces
5375
- * it. Warn once per pinned identity (module-global dedupe — one warning per identity per process, not
5376
- * per connection). `durable === undefined` (a custom adapter) stays silent; a deliberately
5377
- * per-session id opts out with `ephemeralIdentity: true`. Shared by every dial-out entry point
5378
- * (`createWireClient`, `connectChannel`), so the check lives once.
5379
- */
5380
- function warnOnEphemeralPinnedIdentity(callerName, coordinate, storage) {
5381
- if (storage.durable !== false || coordinate.perId == null) return;
5382
- const pinKey = `${coordinate.envId}::${coordinate.perId}`;
5383
- if (ephemeralIdentityWarned.has(pinKey)) return;
5384
- ephemeralIdentityWarned.add(pinKey);
5385
- console.warn(`${callerName}: the runtime coordinate [${pinKey}] carries a persistent id, which keys the peer's trust-on-first-use verify-key pin — but the \`storage\` passed here is not durable (memory/session-backed), so this client's crypto identity regenerates on every reload. The peer will pin the first key it sees and reject every reconnect after the first reload (identity_pin_mismatch). Back the connection with a durable adapter (e.g. createWebLocalStorageAdapter) that persists at least as long as the persistent id, or set \`ephemeralIdentity: true\` if the id is minted fresh per session. Memory adapters are for tests.`);
5386
- }
5387
- /**
5388
- * Assemble the connection facts a dial-out entry point shares — the one implementation of "how a
5389
- * wire connection's mux, crypto identity, keepalive, and traffic tap are set up" (first-production
5390
- * plan Phase 1.6). `createWireClient` and `connectChannel` both call this; each then builds its own
5391
- * transports (mux-only `WireLinkConnection`s vs action `Transport`s with the codec lane) around the
5392
- * shared result, so a fix to any of these lands once.
5393
- */
5394
- function assembleWireConnectionParts(options) {
5395
- const mux = options.mux ?? new WireProtocolMux();
5396
- for (const protocol of options.protocols ?? []) mux.registerProtocol(protocol);
5397
- let link = options.link;
5398
- if (options.anySecure && link == null) {
5399
- if (options.storage == null) throw new Error(`${options.callerName}: a secure transport requires \`storage\` (or \`link\`) for the crypto identity. Pass it, or set \`secure: false\` on the transport for a plain connection.`);
5400
- if (options.ephemeralIdentity !== true) warnOnEphemeralPinnedIdentity(options.callerName, options.identity, options.storage);
5401
- link = new ClientCryptoKeyLink({ storageAdapter: options.storage });
5402
- }
5403
- const resolveLinkKeepalive = () => {
5404
- if (options.linkKeepalive === false) return void 0;
5405
- const explicit = options.linkKeepalive;
5406
- if (!(explicit != null || options.keepLinkAlive === true || options.keepLinkAlive !== false && mux.localCaps().length > 0)) return void 0;
5407
- return {
5408
- idleMs: explicit?.idleMs ?? DEFAULT_LINK_KEEPALIVE_IDLE_MS,
5409
- pongTimeoutMs: explicit?.pongTimeoutMs ?? DEFAULT_LINK_KEEPALIVE_PONG_TIMEOUT_MS
5410
- };
5411
- };
5412
- const wireTap = options.wireTap != null ? withLinkIdTap(options.wireTap, options.peer.stringId) : void 0;
5413
- return {
5414
- mux,
5415
- link,
5416
- resolveLinkKeepalive,
5417
- wireTap
5418
- };
5419
- }
5420
- //#endregion
5421
5171
  //#region ../../node_modules/msgpackr/unpack.js
5422
5172
  var decoder;
5423
5173
  try {
@@ -7784,39 +7534,95 @@ if (!(process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED !== void 0 && process.en
7784
7534
  if (extractor) setExtractor(extractor.extractStrings);
7785
7535
  } catch (error) {}
7786
7536
  }
7787
- //#endregion
7788
- //#region ../nice-wire/src/crypto/actionFrameCrypto.ts
7789
- const ENCRYPTED_ENVELOPE_LENGTH = 2;
7790
- /**
7791
- * Build the encrypt/decrypt transform for a connection whose handshake settled on the `encrypted`
7792
- * level. The shared key is derived once from {@link IActionFrameCryptoConfig.keyMaterial} and captured
7793
- * for this connection alone, decoupling it from the link's shared key cache.
7794
- */
7795
- function createActionFrameCrypto({ link, keyMaterial }) {
7796
- const keyPromise = link.deriveSharedAesGcmKey(keyMaterial);
7797
- return {
7798
- async encryptFrame(frame) {
7799
- const { nonce, ciphertext } = await encryptBytesWithAesGcmKey({
7800
- dataToEncrypt: frame,
7801
- aesGcmKey: await keyPromise
7802
- });
7803
- return pack([nonce, ciphertext]);
7804
- },
7805
- async decryptFrame(frame) {
7806
- if (typeof frame === "string") throw new Error("[ws-crypto] expected an encrypted binary frame, received text");
7807
- const envelope = unpack(frame instanceof ArrayBuffer ? new Uint8Array(frame) : frame);
7808
- if (!Array.isArray(envelope) || envelope.length !== ENCRYPTED_ENVELOPE_LENGTH) throw new Error("[ws-crypto] malformed encrypted frame envelope");
7809
- const [nonce, ciphertext] = envelope;
7810
- if (!(nonce instanceof Uint8Array) || !(ciphertext instanceof Uint8Array)) throw new Error("[ws-crypto] malformed encrypted frame fields");
7811
- return await decryptBytesWithAesGcmKey({
7812
- dataToDecrypt: {
7813
- nonce,
7814
- ciphertext
7815
- },
7816
- aesGcmKey: await keyPromise
7817
- });
7818
- }
7819
- };
7537
+ //#endregion
7538
+ //#region ../nice-wire/src/crypto/actionFrameCrypto.ts
7539
+ const ENCRYPTED_ENVELOPE_LENGTH = 2;
7540
+ /**
7541
+ * Build the encrypt/decrypt transform for a connection whose handshake settled on the `encrypted`
7542
+ * level. The shared key is derived once from {@link IActionFrameCryptoConfig.keyMaterial} and captured
7543
+ * for this connection alone, decoupling it from the link's shared key cache.
7544
+ */
7545
+ function createActionFrameCrypto({ link, keyMaterial }) {
7546
+ const keyPromise = link.deriveSharedAesGcmKey(keyMaterial);
7547
+ return {
7548
+ async encryptFrame(frame) {
7549
+ const { nonce, ciphertext } = await encryptBytesWithAesGcmKey({
7550
+ dataToEncrypt: frame,
7551
+ aesGcmKey: await keyPromise
7552
+ });
7553
+ return pack([nonce, ciphertext]);
7554
+ },
7555
+ async decryptFrame(frame) {
7556
+ if (typeof frame === "string") throw new Error("[ws-crypto] expected an encrypted binary frame, received text");
7557
+ const envelope = unpack(frame instanceof ArrayBuffer ? new Uint8Array(frame) : frame);
7558
+ if (!Array.isArray(envelope) || envelope.length !== ENCRYPTED_ENVELOPE_LENGTH) throw new Error("[ws-crypto] malformed encrypted frame envelope");
7559
+ const [nonce, ciphertext] = envelope;
7560
+ if (!(nonce instanceof Uint8Array) || !(ciphertext instanceof Uint8Array)) throw new Error("[ws-crypto] malformed encrypted frame fields");
7561
+ return await decryptBytesWithAesGcmKey({
7562
+ dataToDecrypt: {
7563
+ nonce,
7564
+ ciphertext
7565
+ },
7566
+ aesGcmKey: await keyPromise
7567
+ });
7568
+ }
7569
+ };
7570
+ }
7571
+ //#endregion
7572
+ //#region ../nice-wire/src/Mux/protocolFrame.ts
7573
+ /**
7574
+ * Frame-protocol prefix bytes (realm plan §3.1). A registered protocol frame is
7575
+ * `[prefixByte, ...payload]` with the prefix drawn from the reserved range `0x00`–`0x0F` —
7576
+ * bytes no legacy frame can start with: binary action envelopes are msgpack fixarrays
7577
+ * (`0x96`–`0x98`), control frames are msgpack maps (`0x80`–`0x8f`, `0xde`, `0xdf`), and
7578
+ * handshake frames are text JSON (`{` = `0x7b`). Frames without a reserved prefix fall through
7579
+ * to the legacy sniffing untouched, so old peers stay byte-identical (pinned by the
7580
+ * byte-compat goldens).
7581
+ *
7582
+ * The registry is **closed** — same philosophy as the control-message registry: protocols are
7583
+ * library-level concerns assigned here, never user-claimable ad hoc.
7584
+ */
7585
+ const WIRE_PROTOCOL_PREFIX = {
7586
+ /** `0x00` is reserved/invalid — a zero prefix is treated as a decode error, never dispatched. */
7587
+ invalid: 0,
7588
+ /** `@nice-code/realm` state-sync frames. */
7589
+ realm: 1,
7590
+ /**
7591
+ * `@nice-code/devtools` observation frames. Assigned here so the prefix space has one
7592
+ * authoritative catalogue; `@nice-code/devtools-core` (a zero-runtime-dependency package that
7593
+ * cannot import wire) mirrors it structurally as its own `DEVTOOLS_WIRE_PREFIX = 0x02`.
7594
+ */
7595
+ devtools: 2
7596
+ };
7597
+ /**
7598
+ * Peek a frame's protocol prefix: the byte when it is a binary frame starting in the reserved
7599
+ * range, else `undefined` (a legacy frame — handshake/control/action — or a text frame).
7600
+ */
7601
+ function peekProtocolPrefix(frame) {
7602
+ let first;
7603
+ if (frame instanceof Uint8Array) first = frame.length > 0 ? frame[0] : void 0;
7604
+ else if (frame instanceof ArrayBuffer) first = frame.byteLength > 0 ? new Uint8Array(frame, 0, 1)[0] : void 0;
7605
+ else return void 0;
7606
+ if (first == null || first > 15) return void 0;
7607
+ return first;
7608
+ }
7609
+ /** Wrap a protocol payload with its prefix byte. */
7610
+ function encodeProtocolFrame(prefixByte, payload) {
7611
+ if (prefixByte <= 0 || prefixByte > 15) throw new Error(`encodeProtocolFrame: prefix 0x${prefixByte.toString(16)} outside reserved range`);
7612
+ const framed = new Uint8Array(payload.length + 1);
7613
+ framed[0] = prefixByte;
7614
+ framed.set(payload, 1);
7615
+ return framed;
7616
+ }
7617
+ /** The handshake capability tag advertising a frame protocol (`hello.caps` / `welcome.caps`). */
7618
+ function protocolCap(protocolId) {
7619
+ return `proto:${protocolId}`;
7620
+ }
7621
+ /** Extract the advertised protocol ids from a peer's handshake caps. */
7622
+ function protocolsFromCaps(caps) {
7623
+ const ids = /* @__PURE__ */ new Set();
7624
+ for (const cap of caps ?? []) if (cap.startsWith("proto:")) ids.add(cap.slice(6));
7625
+ return ids;
7820
7626
  }
7821
7627
  //#endregion
7822
7628
  //#region ../nice-wire/src/crypto/frameBytes.ts
@@ -7857,6 +7663,69 @@ function createFrameCryptoPipe(config) {
7857
7663
  };
7858
7664
  }
7859
7665
  //#endregion
7666
+ //#region ../nice-wire/src/tap/wireTap.ts
7667
+ /**
7668
+ * Wrap a tap so every event it receives is attributed to `linkId` unless the emitter already named
7669
+ * one. This is how the **connector** side gets per-link attribution: an acceptor knows many peers
7670
+ * and tags each frame with the bound client as it emits, whereas a connector has exactly one peer
7671
+ * for the whole connection — so stamping once at the seam beats threading an id through the pipe,
7672
+ * the session, the keepalive and the exchange carrier.
7673
+ *
7674
+ * Both ends therefore answer the same question with `linkId`: *who is on the other end of this
7675
+ * frame*. A client's core can then split its traffic per backend it dials, exactly as a server's
7676
+ * splits per client it serves.
7677
+ */
7678
+ function withLinkIdTap(tap, linkId) {
7679
+ return (event) => {
7680
+ tap(event.linkId != null ? event : {
7681
+ ...event,
7682
+ linkId
7683
+ });
7684
+ };
7685
+ }
7686
+ /**
7687
+ * Wrap an exchange (HTTP) carrier so every request/reply pair is reported to the
7688
+ * tap under the `"http"` lane — the exchange path's equivalent of the duplex
7689
+ * session's pipe/dispatch taps. Envelope bytes as handed to the carrier (the
7690
+ * HTTP layer's own headers are outside the library's sight and not counted).
7691
+ */
7692
+ function withExchangeTap(carrier, tap, linkId) {
7693
+ return {
7694
+ exchange: async (frame, opts) => {
7695
+ tap({
7696
+ dir: "out",
7697
+ bytes: wireFrameByteSize(frame),
7698
+ lane: "http",
7699
+ linkId
7700
+ });
7701
+ const reply = await carrier.exchange(frame, opts);
7702
+ tap({
7703
+ dir: "in",
7704
+ bytes: wireFrameByteSize(reply),
7705
+ lane: "http",
7706
+ linkId
7707
+ });
7708
+ return reply;
7709
+ },
7710
+ get label() {
7711
+ return carrier.label;
7712
+ }
7713
+ };
7714
+ }
7715
+ let encoder;
7716
+ /** The transmitted size of one frame: `byteLength` for binary, UTF-8 length for strings. */
7717
+ function wireFrameByteSize(frame) {
7718
+ if (typeof frame === "string") {
7719
+ if (encoder == null) encoder = new TextEncoder();
7720
+ return encoder.encode(frame).byteLength;
7721
+ }
7722
+ if (frame instanceof Uint8Array) return frame.byteLength;
7723
+ if (frame instanceof ArrayBuffer) return frame.byteLength;
7724
+ if (typeof SharedArrayBuffer !== "undefined" && frame instanceof SharedArrayBuffer) return frame.byteLength;
7725
+ if (ArrayBuffer.isView(frame)) return frame.byteLength;
7726
+ return 0;
7727
+ }
7728
+ //#endregion
7860
7729
  //#region ../nice-wire/src/Connect/handshakeRejectError.ts
7861
7730
  /**
7862
7731
  * Map a peer's handshake reject frame to the error the dialing side throws (Inteleport feedback
@@ -8307,6 +8176,137 @@ function addTransportStatusMetadata(transportStatus) {
8307
8176
  return { status: "uninitialized" };
8308
8177
  }
8309
8178
  //#endregion
8179
+ //#region ../nice-wire/src/Mux/WireProtocolMux.ts
8180
+ var WireProtocolMux = class {
8181
+ _byPrefix = /* @__PURE__ */ new Map();
8182
+ _send;
8183
+ _remoteProtocolIds = /* @__PURE__ */ new Set();
8184
+ _attached = false;
8185
+ /** Register a protocol (before or after attach; late registrants get an immediate attach). */
8186
+ registerProtocol(protocol) {
8187
+ if (this._attached) console.warn(`[wire] registerProtocol("${protocol.id}"): the connection is already attached — this protocol missed the handshake's caps advertisement and will not be resumed after a host wake. Register it before connecting.`);
8188
+ if (protocol.prefixByte <= WIRE_PROTOCOL_PREFIX.invalid || protocol.prefixByte > 15) throw new Error(`registerProtocol("${protocol.id}"): prefix 0x${protocol.prefixByte.toString(16)} outside the reserved range`);
8189
+ if (this._byPrefix.has(protocol.prefixByte)) throw new Error(`registerProtocol("${protocol.id}"): prefix 0x${protocol.prefixByte.toString(16)} already registered`);
8190
+ const port = {
8191
+ send: (payload) => {
8192
+ if (!this._canSpeak(protocol)) throw new Error(`protocol "${protocol.id}": connection not attached or peer did not advertise "${protocolCap(protocol.id)}"`);
8193
+ this._send?.(encodeProtocolFrame(protocol.prefixByte, payload));
8194
+ },
8195
+ isOpen: () => this._canSpeak(protocol)
8196
+ };
8197
+ this._byPrefix.set(protocol.prefixByte, {
8198
+ protocol,
8199
+ port
8200
+ });
8201
+ if (this._attached && this._canSpeak(protocol)) protocol.onAttach?.(port);
8202
+ return port;
8203
+ }
8204
+ /** The `proto:<id>` caps to advertise in this side's handshake. */
8205
+ localCaps() {
8206
+ return [...this._byPrefix.values()].map(({ protocol }) => protocolCap(protocol.id));
8207
+ }
8208
+ /** Record the peer's advertised protocol ids (from its handshake caps). */
8209
+ setRemoteProtocolIds(ids) {
8210
+ this._remoteProtocolIds = ids;
8211
+ }
8212
+ /** Connection ready: give protocols their send path and fire attach for negotiated ones. */
8213
+ attach(send) {
8214
+ this._send = send;
8215
+ this._attached = true;
8216
+ for (const { protocol, port } of this._byPrefix.values()) if (this._canSpeak(protocol)) protocol.onAttach?.(port);
8217
+ }
8218
+ /** Connection lost: notify protocols; sends now throw until the next attach. */
8219
+ detach() {
8220
+ if (!this._attached) return;
8221
+ this._attached = false;
8222
+ this._send = void 0;
8223
+ for (const { protocol } of this._byPrefix.values()) protocol.onDetach?.();
8224
+ }
8225
+ /**
8226
+ * The registered protocol id a frame belongs to, by its prefix byte — `undefined` for a legacy
8227
+ * (unprefixed) frame or an unregistered prefix. Attribution only (the wire-tap lane label);
8228
+ * dispatch stays with {@link dispatchIncoming}.
8229
+ */
8230
+ protocolIdFor(frame) {
8231
+ const prefix = peekProtocolPrefix(frame);
8232
+ if (prefix == null) return void 0;
8233
+ return this._byPrefix.get(prefix)?.protocol.id;
8234
+ }
8235
+ /**
8236
+ * Offer one inbound (already-decrypted) frame. Returns `true` when consumed as a protocol
8237
+ * frame — including an unknown/unregistered prefix, which is dropped (a prefixed frame is
8238
+ * *never* a legacy frame, so falling through would mis-decode it).
8239
+ */
8240
+ dispatchIncoming(frame) {
8241
+ const prefix = peekProtocolPrefix(frame);
8242
+ if (prefix == null) return false;
8243
+ const registered = this._byPrefix.get(prefix);
8244
+ if (prefix === WIRE_PROTOCOL_PREFIX.invalid || registered == null) return true;
8245
+ const bytes = frame instanceof Uint8Array ? frame : new Uint8Array(frame);
8246
+ registered.protocol.onFrame(bytes.subarray(1), registered.port);
8247
+ return true;
8248
+ }
8249
+ _canSpeak(protocol) {
8250
+ return this._attached && this._remoteProtocolIds.has(protocol.id);
8251
+ }
8252
+ };
8253
+ //#endregion
8254
+ //#region ../nice-wire/src/Connect/wireConnectionParts.ts
8255
+ /** 8b.3 defaults: ≈20 s worst-case half-open detection, quiet enough for a healthy idle tab. */
8256
+ const DEFAULT_LINK_KEEPALIVE_IDLE_MS = 15e3;
8257
+ const DEFAULT_LINK_KEEPALIVE_PONG_TIMEOUT_MS = 5e3;
8258
+ const ephemeralIdentityWarned = /* @__PURE__ */ new Set();
8259
+ /**
8260
+ * The ephemeral-identity trap (Inteleport feedback §1): a coordinate with a persistent id whose
8261
+ * crypto identity lives in non-durable storage keys the peer's trust-on-first-use verify-key pin but
8262
+ * regenerates a new key on every reload — so every reload after the first is rejected
8263
+ * `identity_pin_mismatch`, forever. It type-checks and the first load works, so nothing else surfaces
8264
+ * it. Warn once per pinned identity (module-global dedupe — one warning per identity per process, not
8265
+ * per connection). `durable === undefined` (a custom adapter) stays silent; a deliberately
8266
+ * per-session id opts out with `ephemeralIdentity: true`. Shared by every dial-out entry point
8267
+ * (`createWireClient`, `connectChannel`), so the check lives once.
8268
+ */
8269
+ function warnOnEphemeralPinnedIdentity(callerName, coordinate, storage) {
8270
+ if (storage.durable !== false || coordinate.perId == null) return;
8271
+ const pinKey = `${coordinate.envId}::${coordinate.perId}`;
8272
+ if (ephemeralIdentityWarned.has(pinKey)) return;
8273
+ ephemeralIdentityWarned.add(pinKey);
8274
+ console.warn(`${callerName}: the runtime coordinate [${pinKey}] carries a persistent id, which keys the peer's trust-on-first-use verify-key pin — but the \`storage\` passed here is not durable (memory/session-backed), so this client's crypto identity regenerates on every reload. The peer will pin the first key it sees and reject every reconnect after the first reload (identity_pin_mismatch). Back the connection with a durable adapter (e.g. createWebLocalStorageAdapter) that persists at least as long as the persistent id, or set \`ephemeralIdentity: true\` if the id is minted fresh per session. Memory adapters are for tests.`);
8275
+ }
8276
+ /**
8277
+ * Assemble the connection facts a dial-out entry point shares — the one implementation of "how a
8278
+ * wire connection's mux, crypto identity, keepalive, and traffic tap are set up" (first-production
8279
+ * plan Phase 1.6). `createWireClient` and `connectChannel` both call this; each then builds its own
8280
+ * transports (mux-only `WireLinkConnection`s vs action `Transport`s with the codec lane) around the
8281
+ * shared result, so a fix to any of these lands once.
8282
+ */
8283
+ function assembleWireConnectionParts(options) {
8284
+ const mux = options.mux ?? new WireProtocolMux();
8285
+ for (const protocol of options.protocols ?? []) mux.registerProtocol(protocol);
8286
+ let link = options.link;
8287
+ if (options.anySecure && link == null) {
8288
+ if (options.storage == null) throw new Error(`${options.callerName}: a secure transport requires \`storage\` (or \`link\`) for the crypto identity. Pass it, or set \`secure: false\` on the transport for a plain connection.`);
8289
+ if (options.ephemeralIdentity !== true) warnOnEphemeralPinnedIdentity(options.callerName, options.identity, options.storage);
8290
+ link = new ClientCryptoKeyLink({ storageAdapter: options.storage });
8291
+ }
8292
+ const resolveLinkKeepalive = () => {
8293
+ if (options.linkKeepalive === false) return void 0;
8294
+ const explicit = options.linkKeepalive;
8295
+ if (!(explicit != null || options.keepLinkAlive === true || options.keepLinkAlive !== false && mux.localCaps().length > 0)) return void 0;
8296
+ return {
8297
+ idleMs: explicit?.idleMs ?? DEFAULT_LINK_KEEPALIVE_IDLE_MS,
8298
+ pongTimeoutMs: explicit?.pongTimeoutMs ?? DEFAULT_LINK_KEEPALIVE_PONG_TIMEOUT_MS
8299
+ };
8300
+ };
8301
+ const wireTap = options.wireTap != null ? withLinkIdTap(options.wireTap, options.peer.stringId) : void 0;
8302
+ return {
8303
+ mux,
8304
+ link,
8305
+ resolveLinkKeepalive,
8306
+ wireTap
8307
+ };
8308
+ }
8309
+ //#endregion
8310
8310
  //#region ../nice-wire/src/Connect/exchangeEnvelope.ts
8311
8311
  function encodeExchange(envelope) {
8312
8312
  return JSON.stringify(envelope);
@@ -21292,7 +21292,7 @@ var RealmServerEngine = class {
21292
21292
  deferredMs
21293
21293
  }));
21294
21294
  }
21295
- if (fired) this._detachScheduleChanged();
21295
+ if (fired || this._pendingDetaches.size > 0) this._detachScheduleChanged();
21296
21296
  }
21297
21297
  /**
21298
21298
  * The scheduling seam: hand the change to the host when it owns scheduling
@@ -22478,6 +22478,19 @@ const COMMANDER_HEALTH_PATH = "/health";
22478
22478
  const COMMANDER_TICKET_PROTOCOL_PREFIX = "commander-auth.";
22479
22479
  //#endregion
22480
22480
  //#region src/protocol/control.ts
22481
+ /**
22482
+ * Per-request timeout for control actions, passed as the channel's `defaultTimeout` by BOTH
22483
+ * clients (the CLI's daemonClient and the web session).
22484
+ *
22485
+ * ⚠ Without this, every control request inherited the wire stack's 10 s
22486
+ * `DEFAULT_TRANSPORT_TIMEOUT` — and `start`/`up` of a real group legitimately runs for minutes,
22487
+ * so the client aborted with "transport timed out" while the daemon carried on and the status
22488
+ * realm streamed live progress into the same UI (REVIEW-AND-FIX F2). A verdict-bearing RPC gets a
22489
+ * deadline sized for the work it names, not for a ping. Fifteen minutes matches the largest
22490
+ * `timeoutMs` any row in a config is likely to carry; a daemon that is actually gone still fails
22491
+ * fast through the link layer, not through this.
22492
+ */
22493
+ const COMMANDER_CONTROL_TIMEOUT_MS = 9e5;
22481
22494
  function handSchema(check) {
22482
22495
  return { "~standard": {
22483
22496
  version: 1,
@@ -22772,6 +22785,7 @@ async function connectDaemon(handle) {
22772
22785
  storage: new StorageAdapter({ methods: createMemoryStorageMethods_json(/* @__PURE__ */ new Map()) }),
22773
22786
  ephemeralIdentity: true,
22774
22787
  securityLevel: "authenticated",
22788
+ defaultTimeout: COMMANDER_CONTROL_TIMEOUT_MS,
22775
22789
  keepLinkAlive: false,
22776
22790
  onLinkEvent: (event) => {
22777
22791
  if (process.env["NICE_COMMANDER_DEBUG"] != null) process.stderr.write(`[link] ${JSON.stringify(event)}\n`);
@@ -23194,9 +23208,30 @@ async function fetchProcessStates(handle) {
23194
23208
  }
23195
23209
  }
23196
23210
  async function cmdDoctor(ctx) {
23197
- const bad = unknownFlags(ctx.args.flags, []);
23211
+ const bad = unknownFlags(ctx.args.flags, ["--reap"]);
23198
23212
  if (bad != null) throw new CliExit(EXIT.usage, bad);
23199
- const report = await diagnose(ctx, await findDaemon(ctx.config));
23213
+ const handle = await findDaemon(ctx.config);
23214
+ if (ctx.args.flags.has("--reap")) {
23215
+ const { out } = ctx;
23216
+ if (handle != null) {
23217
+ out.warn(out.paint("yellow", "⚠ --reap refused: a live daemon owns this config's ledger — its children are not orphans. Stop it first (`nice-commander shutdown`) if you really mean this."));
23218
+ return EXIT.failure;
23219
+ }
23220
+ const paths = commanderStatePaths(resolveCommanderDataDir(), ctx.config.configKey);
23221
+ const result = await (0, _nice_code_process.openProcessLedger)({
23222
+ dir: paths.stateDir,
23223
+ namespace: paths.ledgerNamespace
23224
+ }).reapOrphans();
23225
+ if (result.schemaUnknown) {
23226
+ out.warn(out.paint("yellow", "⚠ ledger schema is newer than this build understands — nothing touched"));
23227
+ return EXIT.failure;
23228
+ }
23229
+ out.print(`reap: ${result.reaped.length} orphan record(s) reaped, ${result.quarantined.length} quarantined`);
23230
+ for (const entry of result.reaped) out.print(` ${out.paint("green", "✓")} reaped "${entry.record.id}" (pid ${entry.record.pid}, ${entry.how})`);
23231
+ for (const entry of result.quarantined) out.print(` ${out.paint("yellow", "⚠")} quarantined "${entry.record.id}" (pid ${entry.record.pid}): ${entry.reason} — ambiguous identity, never killed blind`);
23232
+ return EXIT.ok;
23233
+ }
23234
+ const report = await diagnose(ctx, handle);
23200
23235
  const { out } = ctx;
23201
23236
  if (out.json) {
23202
23237
  out.printJson(report);
@@ -23405,6 +23440,21 @@ async function cmdExplain(ctx) {
23405
23440
  selection.ordered.forEach((id, index) => {
23406
23441
  out.print(` ${index + 1}. ${id}`);
23407
23442
  });
23443
+ const overrides = await readEnvOverrides(commanderStatePaths(resolveCommanderDataDir(), ctx.config.configKey).envOverridesPath);
23444
+ out.print("env:");
23445
+ out.print(" note: `run` children inherit THIS shell's environment; daemon-owned starts (`up`) inherit");
23446
+ out.print(" the daemon's boot-time snapshot — `doctor` shows that snapshot's age.");
23447
+ for (const id of selection.ordered) {
23448
+ const def = ctx.config.processes.find((proc) => proc.id === id);
23449
+ if (def == null) continue;
23450
+ const parts = [];
23451
+ for (const [key, value] of Object.entries(def.env)) parts.push(value == null ? `${key}=(unset)` : `${key}=${value} (config)`);
23452
+ for (const view of envVarViews(def, overrides, process.env)) {
23453
+ const shown = view.secret ? "•••" : view.value ?? (view.source === "inherited" ? "(from shell)" : "(unset)");
23454
+ parts.push(`${view.name}=${shown} (${view.source}${view.source === "override" ? ", sticky" : ""})`);
23455
+ }
23456
+ if (parts.length > 0) out.print(` ${id}: ${parts.join(" ")}`);
23457
+ }
23408
23458
  return EXIT.ok;
23409
23459
  }
23410
23460
  //#endregion
@@ -23843,6 +23893,29 @@ async function cmdRun(ctx) {
23843
23893
  const tasks = defs.filter((def) => def.kind === "task");
23844
23894
  const services = defs.filter((def) => def.kind === "service");
23845
23895
  const failures = [];
23896
+ /**
23897
+ * Record a failure AND set `process.exitCode` eagerly — belt-and-braces for the drain class.
23898
+ *
23899
+ * This command has twice reached "a FAILING RUN REPORTED SUCCESS" via the same shape: something
23900
+ * left the run's promise suspended, the event loop drained, and Node exited with the default 0
23901
+ * (see the startPump warning above, and the lost-wakeup pool defect this file carried until
23902
+ * 2026-07). The proper exit code is still returned at the end and overwrites this; the eager
23903
+ * assignment just guarantees that NO future scheduling hang can ever turn a printed ✗ into a
23904
+ * green exit again.
23905
+ */
23906
+ const recordFailure = (result) => {
23907
+ failures.push(result);
23908
+ process.exitCode = result.code === 0 ? EXIT.failure : result.code;
23909
+ };
23910
+ /** `run: N ok, M failed (ids…)` — the human-readable verdict beside the exit code. */
23911
+ const printSummary = (ok, skipped) => {
23912
+ if (tasks.length === 0) return;
23913
+ const parts = [`${ok} ok`];
23914
+ if (failures.length > 0) parts.push(`${failures.length} failed (${failures.map((entry) => entry.id).join(", ")})`);
23915
+ if (skipped > 0) parts.push(`${skipped} not run`);
23916
+ const line = `run: ${parts.join(", ")}`;
23917
+ out.print(failures.length > 0 ? out.paint("red", line) : out.paint("green", line));
23918
+ };
23846
23919
  try {
23847
23920
  const pumps = single ? [] : procs.map((proc) => startPump(out, proc));
23848
23921
  if (tasks.length > 0 && services.length === 0) {
@@ -23852,10 +23925,15 @@ async function cmdRun(ctx) {
23852
23925
  const running = /* @__PURE__ */ new Set();
23853
23926
  const selected = new Set(tasks.map((def) => def.id));
23854
23927
  const depsOf = (def) => def.dependsOn.filter((id) => selected.has(id));
23855
- let wake = () => {};
23928
+ let waiters = [];
23856
23929
  const settled = () => new Promise((resolve) => {
23857
- wake = resolve;
23930
+ waiters.push(resolve);
23858
23931
  });
23932
+ const wake = () => {
23933
+ const current = waiters;
23934
+ waiters = [];
23935
+ for (const resolve of current) resolve();
23936
+ };
23859
23937
  const workers = Array.from({ length: Math.min(parallel ?? 1, pending.length) }, async () => {
23860
23938
  for (;;) {
23861
23939
  if (failFast && failures.length > 0) return;
@@ -23870,7 +23948,7 @@ async function cmdRun(ctx) {
23870
23948
  if (blockedBy != null) {
23871
23949
  out.print(`${out.paint("yellow", "⊘")} ${out.accent(def.id, def.id)} blocked: "${blockedBy}" failed`);
23872
23950
  failed.add(def.id);
23873
- failures.push({
23951
+ recordFailure({
23874
23952
  id: def.id,
23875
23953
  code: 1,
23876
23954
  failed: true
@@ -23884,7 +23962,7 @@ async function cmdRun(ctx) {
23884
23962
  (result.failed ? failed : succeeded).add(def.id);
23885
23963
  wake();
23886
23964
  if (result.failed) {
23887
- failures.push(result);
23965
+ recordFailure(result);
23888
23966
  if (failFast) {
23889
23967
  for (const proc of procs) if (!TERMINAL_STATES.has(proc.state)) proc.stop();
23890
23968
  return;
@@ -23896,20 +23974,23 @@ async function cmdRun(ctx) {
23896
23974
  for (const def of pending) {
23897
23975
  const blockedBy = depsOf(def).find((id) => !succeeded.has(id)) ?? "a dependency";
23898
23976
  out.print(`${out.paint("yellow", "⊘")} ${out.accent(def.id, def.id)} blocked: "${blockedBy}" did not succeed`);
23899
- failures.push({
23977
+ recordFailure({
23900
23978
  id: def.id,
23901
23979
  code: 1,
23902
23980
  failed: true
23903
23981
  });
23904
23982
  }
23905
23983
  await drainPumps(pumps);
23984
+ printSummary(succeeded.size, tasks.length - succeeded.size - failures.length);
23906
23985
  return failures.length > 0 ? failures[0]?.code ?? 1 : EXIT.ok;
23907
23986
  }
23987
+ let mixedOk = 0;
23908
23988
  for (const def of defs) {
23909
23989
  if (failFast && failures.length > 0) break;
23910
23990
  if (def.kind === "task") {
23911
23991
  const result = await runTask(def);
23912
- if (result.failed) failures.push(result);
23992
+ if (result.failed) recordFailure(result);
23993
+ else mixedOk += 1;
23913
23994
  continue;
23914
23995
  }
23915
23996
  for (const depId of def.dependsOn) {
@@ -23937,6 +24018,7 @@ async function cmdRun(ctx) {
23937
24018
  await stopping;
23938
24019
  }
23939
24020
  await drainPumps(pumps);
24021
+ printSummary(mixedOk, tasks.length - mixedOk - failures.length);
23940
24022
  return failures.length > 0 ? failures[0]?.code ?? 1 : EXIT.ok;
23941
24023
  } finally {
23942
24024
  process.removeListener("SIGINT", onSigint);
@@ -24163,9 +24245,18 @@ commands:
24163
24245
  overrides. A set value is STICKY: it applies to every
24164
24246
  later start until cleared, and never restarts anything.
24165
24247
  run <sel> [--parallel N] [--fail-fast] foreground, no daemon; tasks = local CI shape,
24166
- a single id gets raw inherited stdio (interactive)
24248
+ a single id gets raw inherited stdio (interactive).
24249
+ --fail-fast = stop at the FIRST failure and stop the
24250
+ survivors; without it every task still runs, every
24251
+ failure is reported, and the exit code is still
24252
+ non-zero. Children inherit THIS shell's environment;
24253
+ daemon-owned processes (up) inherit the daemon's
24254
+ boot-time snapshot instead — see doctor.
24167
24255
  ui ensure the daemon and open the browser (prints URL)
24168
- doctor diagnostics: ledger, capability, endpoints, env
24256
+ doctor [--reap] diagnostics: ledger, capability, endpoints, env.
24257
+ --reap collects a crashed daemon's orphans NOW
24258
+ (same reap the next boot runs; refused while a
24259
+ daemon is live)
24169
24260
  shutdown stop the daemon (graceful ladder)
24170
24261
 
24171
24262
  status/down/logs/doctor/shutdown never start a missing daemon — they report "not running".
@@ -24217,7 +24308,7 @@ async function withTimeout(ctx, run) {
24217
24308
  async function main() {
24218
24309
  const argv = process.argv.slice(2);
24219
24310
  if (argv[0] === "daemon") {
24220
- const { runCommanderDaemon } = await Promise.resolve().then(() => require("./main-Cqij6RwE.cjs"));
24311
+ const { runCommanderDaemon } = await Promise.resolve().then(() => require("./main-CLqn8JGt.cjs"));
24221
24312
  return runCommanderDaemon(argv.slice(1));
24222
24313
  }
24223
24314
  const parsed = parseCliArgs(argv);