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