@nice-code/commander 0.110.0 → 0.112.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 +672 -109
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +664 -110
- package/build/cli.mjs.map +1 -1
- package/build/client/assets/{index-DLZZdohI.css → index-B5u-kfUT.css} +1 -1
- package/build/client/assets/index-BK6klick.js +23 -0
- package/build/client/assets/index-BK6klick.js.map +1 -0
- package/build/client/index.html +2 -2
- package/build/config.cjs.map +1 -1
- package/build/config.d.cts +19 -1
- package/build/config.d.mts +19 -1
- package/build/config.mjs.map +1 -1
- package/build/{main-CVu9gjbx.cjs → main-C3BG9bju.cjs} +157 -75
- package/build/main-C3BG9bju.cjs.map +1 -0
- package/build/{main-CWWlV2U5.mjs → main-DSPhWTfM.mjs} +159 -77
- package/build/main-DSPhWTfM.mjs.map +1 -0
- package/build/types-B3WIUo4S.mjs.map +1 -1
- package/build/types-CIdWQGjF.cjs.map +1 -1
- package/package.json +6 -6
- package/build/client/assets/index-dItAKcyH.js +0 -23
- package/build/client/assets/index-dItAKcyH.js.map +0 -1
- package/build/main-CVu9gjbx.cjs.map +0 -1
- package/build/main-CWWlV2U5.mjs.map +0 -1
package/build/cli.cjs
CHANGED
|
@@ -26,7 +26,11 @@ const GLOBAL_VALUE_FLAGS = new Set(["--config", "--timeout"]);
|
|
|
26
26
|
* plain Map keeps only the last. The name still lands in `flags` so `unknownFlags` keeps rejecting
|
|
27
27
|
* it on every command that does not accept it.
|
|
28
28
|
*/
|
|
29
|
-
const REPEATABLE_VALUE_FLAGS = new Set([
|
|
29
|
+
const REPEATABLE_VALUE_FLAGS = new Set([
|
|
30
|
+
"--set",
|
|
31
|
+
"--unset",
|
|
32
|
+
"--with"
|
|
33
|
+
]);
|
|
30
34
|
/**
|
|
31
35
|
* Per-command flags that take a VALUE. Everything else is boolean — and that distinction is
|
|
32
36
|
* load-bearing: a greedy "consume the next token" parse turned `up --no-wait demo` into
|
|
@@ -38,6 +42,7 @@ function parseCliArgs(argv) {
|
|
|
38
42
|
const flags = /* @__PURE__ */ new Map();
|
|
39
43
|
const repeated = /* @__PURE__ */ new Map();
|
|
40
44
|
const positionals = [];
|
|
45
|
+
const passthrough = [];
|
|
41
46
|
let command = null;
|
|
42
47
|
let json = false;
|
|
43
48
|
let noColor = false;
|
|
@@ -46,6 +51,10 @@ function parseCliArgs(argv) {
|
|
|
46
51
|
let timeoutMs;
|
|
47
52
|
for (let i = 0; i < argv.length; i += 1) {
|
|
48
53
|
const token = argv[i];
|
|
54
|
+
if (token === "--") {
|
|
55
|
+
passthrough.push(...argv.slice(i + 1));
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
49
58
|
const eq = token.startsWith("--") ? token.indexOf("=") : -1;
|
|
50
59
|
const arg = eq > 2 ? token.slice(0, eq) : token;
|
|
51
60
|
const inlineValue = eq > 2 ? token.slice(eq + 1) : null;
|
|
@@ -108,7 +117,8 @@ function parseCliArgs(argv) {
|
|
|
108
117
|
noColor,
|
|
109
118
|
help,
|
|
110
119
|
flags,
|
|
111
|
-
repeated
|
|
120
|
+
repeated,
|
|
121
|
+
passthrough
|
|
112
122
|
};
|
|
113
123
|
if (configPath != null) args.configPath = configPath;
|
|
114
124
|
if (timeoutMs != null) args.timeoutMs = timeoutMs;
|
|
@@ -151,7 +161,7 @@ function validStartStamp(value) {
|
|
|
151
161
|
function isInstanceRecord(value) {
|
|
152
162
|
if (value == null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
153
163
|
const record = value;
|
|
154
|
-
return record.service === "nice-commander" && boundedString(record.instanceId) && boundedInt(record.generation, 0, Number.MAX_SAFE_INTEGER) && boundedInt(record.pid, 1, Number.MAX_SAFE_INTEGER) && boundedInt(record.port, 1, 65535) && boundedString(record.token) && boundedString(record.configKey) && boundedString(record.configRevisionHash) && boundedString(record.configPath) && boundedString(record.packageVersion) && boundedString(record.realmSchemaHash) && validStartStamp(record.startStamp) && (record.servesOwnClient == null || typeof record.servesOwnClient === "boolean") && record.protocolVersion ===
|
|
164
|
+
return record.service === "nice-commander" && boundedString(record.instanceId) && boundedInt(record.generation, 0, Number.MAX_SAFE_INTEGER) && boundedInt(record.pid, 1, Number.MAX_SAFE_INTEGER) && boundedInt(record.port, 1, 65535) && boundedString(record.token) && boundedString(record.configKey) && boundedString(record.configRevisionHash) && boundedString(record.configPath) && boundedString(record.packageVersion) && boundedString(record.realmSchemaHash) && validStartStamp(record.startStamp) && (record.servesOwnClient == null || typeof record.servesOwnClient === "boolean") && record.protocolVersion === 8;
|
|
155
165
|
}
|
|
156
166
|
async function writeInstanceRecord(path, record) {
|
|
157
167
|
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), {
|
|
@@ -201,7 +211,7 @@ async function readSkewedInstanceRecord(path, expectedRealmSchemaHash) {
|
|
|
201
211
|
if (!boundedInt(record["protocolVersion"], 0, Number.MAX_SAFE_INTEGER)) return null;
|
|
202
212
|
if (!boundedInt(record["pid"], 1, Number.MAX_SAFE_INTEGER)) return null;
|
|
203
213
|
if (!boundedInt(record["port"], 1, 65535)) return null;
|
|
204
|
-
const sameProtocol = record["protocolVersion"] ===
|
|
214
|
+
const sameProtocol = record["protocolVersion"] === 8;
|
|
205
215
|
const sameRealm = boundedString(record["realmSchemaHash"]) && record["realmSchemaHash"] === expectedRealmSchemaHash;
|
|
206
216
|
if (sameProtocol && sameRealm) return null;
|
|
207
217
|
return {
|
|
@@ -297,6 +307,31 @@ async function pingDaemon(record, timeoutMs = 2e3) {
|
|
|
297
307
|
}
|
|
298
308
|
}
|
|
299
309
|
//#endregion
|
|
310
|
+
//#region src/config/flags.ts
|
|
311
|
+
/**
|
|
312
|
+
* An argument a shell-string `run` can take appended unquoted in sh, cmd and PowerShell alike.
|
|
313
|
+
* Anything else (spaces, quotes, `$`, `%`, `,`, `;`…) would need per-shell quoting.
|
|
314
|
+
*/
|
|
315
|
+
const SHELL_PLAIN_ARG = /^[A-Za-z0-9_+=:./-]+$/;
|
|
316
|
+
/** `run` with `args` appended — after the argv, or after the shell string. */
|
|
317
|
+
function runWithArgs(run, args) {
|
|
318
|
+
if (args.length === 0) return run;
|
|
319
|
+
return typeof run === "string" ? `${run} ${args.join(" ")}` : [...run, ...args];
|
|
320
|
+
}
|
|
321
|
+
/** Requested names against a definition's declared flags; an undeclared name is an error. */
|
|
322
|
+
function resolveFlags(definition, names) {
|
|
323
|
+
const unknown = names.filter((name) => !definition.flags.some((flag) => flag.name === name));
|
|
324
|
+
if (unknown.length > 0) {
|
|
325
|
+
const declared = definition.flags.map((flag) => flag.name);
|
|
326
|
+
return { error: `"${definition.id}" declares no flag ${unknown.map((name) => `"${name}"`).join(", ")} — ` + (declared.length > 0 ? `its flags: ${declared.join(", ")}` : "it declares none") };
|
|
327
|
+
}
|
|
328
|
+
const on = definition.flags.filter((flag) => names.includes(flag.name));
|
|
329
|
+
return {
|
|
330
|
+
flags: on.map((flag) => flag.name),
|
|
331
|
+
args: on.flatMap((flag) => flag.args)
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
//#endregion
|
|
300
335
|
//#region src/config/tags.ts
|
|
301
336
|
/** `key=value` → `[key, value]`, or null when the term is not tag-shaped. */
|
|
302
337
|
function parseTagTerm(term) {
|
|
@@ -832,6 +867,54 @@ function readEnvVarFields(declared, name, at, errors) {
|
|
|
832
867
|
required: required === true
|
|
833
868
|
};
|
|
834
869
|
}
|
|
870
|
+
const MAX_FLAGS = 32;
|
|
871
|
+
function readFlags(raw, shellString, at, errors) {
|
|
872
|
+
if (raw == null) return [];
|
|
873
|
+
if (!Array.isArray(raw)) {
|
|
874
|
+
errors.push(`${at}.flags: expected an array of flag declarations`);
|
|
875
|
+
return [];
|
|
876
|
+
}
|
|
877
|
+
if (raw.length > MAX_FLAGS) errors.push(`${at}.flags: ${raw.length} entries exceeds the ${MAX_FLAGS} bound`);
|
|
878
|
+
const flags = [];
|
|
879
|
+
for (const [index, declared] of raw.entries()) {
|
|
880
|
+
const atF = `${at}.flags[${index}]`;
|
|
881
|
+
if (!isRecord(declared)) {
|
|
882
|
+
errors.push(`${atF}: expected an object`);
|
|
883
|
+
continue;
|
|
884
|
+
}
|
|
885
|
+
const name = declared["name"];
|
|
886
|
+
if (typeof name !== "string" || !require_types.COMMANDER_ID_PATTERN.test(name)) {
|
|
887
|
+
errors.push(`${atF}.name: must match ${require_types.COMMANDER_ID_PATTERN}`);
|
|
888
|
+
continue;
|
|
889
|
+
}
|
|
890
|
+
if (flags.some((existing) => existing.name === name)) {
|
|
891
|
+
errors.push(`${atF}.name: duplicate flag "${name}"`);
|
|
892
|
+
continue;
|
|
893
|
+
}
|
|
894
|
+
const description = declared["description"];
|
|
895
|
+
if (description != null && typeof description !== "string") {
|
|
896
|
+
errors.push(`${atF}.description: expected a string`);
|
|
897
|
+
continue;
|
|
898
|
+
}
|
|
899
|
+
const rawArgs = declared["args"] ?? [`--${name}`];
|
|
900
|
+
if (!Array.isArray(rawArgs) || rawArgs.length === 0 || rawArgs.some((arg) => typeof arg !== "string" || arg === "" || hasControlChars(arg))) {
|
|
901
|
+
errors.push(`${atF}.args: expected a non-empty array of non-empty strings`);
|
|
902
|
+
continue;
|
|
903
|
+
}
|
|
904
|
+
const args = rawArgs.filter((arg) => typeof arg === "string");
|
|
905
|
+
const unquotable = shellString ? args.find((arg) => !SHELL_PLAIN_ARG.test(arg)) : void 0;
|
|
906
|
+
if (unquotable != null) {
|
|
907
|
+
errors.push(`${atF}.args: ${JSON.stringify(unquotable)} would need shell quoting, and a shell-string \`run\` takes its flags unquoted — use the argv form of \`run\`, or a plain argument`);
|
|
908
|
+
continue;
|
|
909
|
+
}
|
|
910
|
+
flags.push({
|
|
911
|
+
name,
|
|
912
|
+
args,
|
|
913
|
+
...typeof description === "string" ? { description } : {}
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
return flags;
|
|
917
|
+
}
|
|
835
918
|
function isUrlCleanHttp(url) {
|
|
836
919
|
try {
|
|
837
920
|
const parsed = new URL(url);
|
|
@@ -1011,6 +1094,7 @@ function validateCommanderConfig(raw, anchor) {
|
|
|
1011
1094
|
if (resolved != null) envVars.push(resolved);
|
|
1012
1095
|
}
|
|
1013
1096
|
for (const declared of envVars) if (declared.default != null) env[declared.name] = declared.default;
|
|
1097
|
+
const flags = readFlags(proc.flags, typeof proc.run === "string", at, errors);
|
|
1014
1098
|
const tagEntries = Object.entries({
|
|
1015
1099
|
...config.defaults?.tags,
|
|
1016
1100
|
...proc.tags
|
|
@@ -1114,6 +1198,7 @@ function validateCommanderConfig(raw, anchor) {
|
|
|
1114
1198
|
...proc.shell != null ? { shell: proc.shell } : {},
|
|
1115
1199
|
env,
|
|
1116
1200
|
envVars,
|
|
1201
|
+
flags,
|
|
1117
1202
|
stdin,
|
|
1118
1203
|
tags,
|
|
1119
1204
|
optIn: proc.optIn === true,
|
|
@@ -1306,6 +1391,28 @@ function selectOrExit(ctx, options) {
|
|
|
1306
1391
|
if (!result.ok) throw new CliExit(EXIT.usage, result.errors.join("\n"));
|
|
1307
1392
|
return result.selection;
|
|
1308
1393
|
}
|
|
1394
|
+
/**
|
|
1395
|
+
* The one process a per-process option (`--with`, `-- args`) applies to: the selection must be
|
|
1396
|
+
* exactly its id — a flag set means nothing to a suite or a tag.
|
|
1397
|
+
*/
|
|
1398
|
+
function singleProcessOrExit(ctx, option) {
|
|
1399
|
+
const [term, ...rest] = ctx.args.positionals;
|
|
1400
|
+
const definition = ctx.config.processes.find((proc) => proc.id === term);
|
|
1401
|
+
if (definition == null || rest.length > 0 || ctx.args.flags.has("--all")) throw new CliExit(EXIT.usage, `${option} applies to one process — select it by its id alone (\`${ctx.args.command} <id> ${option} …\`)`);
|
|
1402
|
+
return definition;
|
|
1403
|
+
}
|
|
1404
|
+
/** `--with a --with b` / `--with a,b`, resolved against the selected process's declared flags. */
|
|
1405
|
+
function flagsOrExit(ctx) {
|
|
1406
|
+
const raw = ctx.args.repeated.get("--with") ?? [];
|
|
1407
|
+
if (raw.length === 0) return null;
|
|
1408
|
+
const definition = singleProcessOrExit(ctx, "--with");
|
|
1409
|
+
const resolved = resolveFlags(definition, raw.flatMap((value) => value.split(",")).filter((name) => name !== ""));
|
|
1410
|
+
if ("error" in resolved) throw new CliExit(EXIT.usage, resolved.error);
|
|
1411
|
+
return {
|
|
1412
|
+
id: definition.id,
|
|
1413
|
+
...resolved
|
|
1414
|
+
};
|
|
1415
|
+
}
|
|
1309
1416
|
/** Suite stagger for a start: the widest stagger among the suites named in the terms. */
|
|
1310
1417
|
function staggerFor(config, terms) {
|
|
1311
1418
|
let stagger = 0;
|
|
@@ -4615,6 +4722,7 @@ var ClientCryptoKeyLink = class {
|
|
|
4615
4722
|
localVerifyKeyPair;
|
|
4616
4723
|
linkedClientKeys = /* @__PURE__ */ new Map();
|
|
4617
4724
|
storage;
|
|
4725
|
+
storageAdapter;
|
|
4618
4726
|
identityMode;
|
|
4619
4727
|
initialized = false;
|
|
4620
4728
|
initializePromise;
|
|
@@ -4622,9 +4730,18 @@ var ClientCryptoKeyLink = class {
|
|
|
4622
4730
|
localVerifyKeyPairPromise;
|
|
4623
4731
|
constructor({ storageAdapter, identityMode } = {}) {
|
|
4624
4732
|
if (storageAdapter != null) this.storage = createTypedStorage({ storageAdapter });
|
|
4733
|
+
this.storageAdapter = storageAdapter;
|
|
4625
4734
|
this.identityMode = identityMode ?? "lazy";
|
|
4626
4735
|
}
|
|
4627
4736
|
/**
|
|
4737
|
+
* A namespace of this identity's own store (same backing storage, `prefix` appended), for state
|
|
4738
|
+
* that belongs to this identity and must go wherever its keys go — e.g. a connector's established
|
|
4739
|
+
* sessions. `undefined` when the link has no storage.
|
|
4740
|
+
*/
|
|
4741
|
+
scopedStorage(prefix) {
|
|
4742
|
+
return this.storageAdapter?.withKeyPrefix(prefix);
|
|
4743
|
+
}
|
|
4744
|
+
/**
|
|
4628
4745
|
* Loads the local key pairs and any linked client public keys from storage (when a storage
|
|
4629
4746
|
* adapter was provided), generating and persisting fresh local key pairs if none exist yet.
|
|
4630
4747
|
*
|
|
@@ -9538,6 +9655,12 @@ function assembleWireConnectionParts(options) {
|
|
|
9538
9655
|
}
|
|
9539
9656
|
//#endregion
|
|
9540
9657
|
//#region ../nice-wire/src/Connect/exchangeEnvelope.ts
|
|
9658
|
+
/**
|
|
9659
|
+
* The `err` id an acceptor sends when it refused the session itself (expired, tampered or
|
|
9660
|
+
* wrong-key ticket, or an act at the wrong level) — before any lane ran, so the connector may
|
|
9661
|
+
* drop the session, handshake again and resend the same act.
|
|
9662
|
+
*/
|
|
9663
|
+
const WIRE_EXCHANGE_SESSION_REFUSED = "session_refused";
|
|
9541
9664
|
function encodeExchange(envelope) {
|
|
9542
9665
|
return JSON.stringify(envelope);
|
|
9543
9666
|
}
|
|
@@ -9566,33 +9689,261 @@ function hasEnvelopeKind(value) {
|
|
|
9566
9689
|
return typeof value === "object" && value != null && "k" in value;
|
|
9567
9690
|
}
|
|
9568
9691
|
//#endregion
|
|
9692
|
+
//#region ../nice-wire/src/SecureSession/exchangeTicketSeal.ts
|
|
9693
|
+
const SEALED_ENVELOPE_LENGTH = 2;
|
|
9694
|
+
function createExchangeTicketSealer(link, options = {}) {
|
|
9695
|
+
let keyPromise;
|
|
9696
|
+
const getKey = () => {
|
|
9697
|
+
if (keyPromise == null) keyPromise = link.deriveLocalSealKey({ version: options.version }).catch((err) => {
|
|
9698
|
+
keyPromise = void 0;
|
|
9699
|
+
throw err;
|
|
9700
|
+
});
|
|
9701
|
+
return keyPromise;
|
|
9702
|
+
};
|
|
9703
|
+
return {
|
|
9704
|
+
async seal(value, ttlMs) {
|
|
9705
|
+
const { nonce, ciphertext } = await encryptBytesWithAesGcmKey({
|
|
9706
|
+
dataToEncrypt: pack({
|
|
9707
|
+
v: value,
|
|
9708
|
+
exp: Date.now() + ttlMs
|
|
9709
|
+
}),
|
|
9710
|
+
aesGcmKey: await getKey()
|
|
9711
|
+
});
|
|
9712
|
+
return bytesToBase64(pack([nonce, ciphertext]));
|
|
9713
|
+
},
|
|
9714
|
+
async open(blob) {
|
|
9715
|
+
try {
|
|
9716
|
+
const envelope = unpack(base64ToBytes(blob));
|
|
9717
|
+
if (!Array.isArray(envelope) || envelope.length !== SEALED_ENVELOPE_LENGTH) return void 0;
|
|
9718
|
+
const [nonce, ciphertext] = envelope;
|
|
9719
|
+
if (!(nonce instanceof Uint8Array) || !(ciphertext instanceof Uint8Array)) return void 0;
|
|
9720
|
+
const payload = unpack(await decryptBytesWithAesGcmKey({
|
|
9721
|
+
dataToDecrypt: {
|
|
9722
|
+
nonce,
|
|
9723
|
+
ciphertext
|
|
9724
|
+
},
|
|
9725
|
+
aesGcmKey: await getKey()
|
|
9726
|
+
}));
|
|
9727
|
+
if (payload == null || typeof payload.exp !== "number" || payload.exp < Date.now()) return;
|
|
9728
|
+
return payload.v;
|
|
9729
|
+
} catch {
|
|
9730
|
+
return;
|
|
9731
|
+
}
|
|
9732
|
+
}
|
|
9733
|
+
};
|
|
9734
|
+
}
|
|
9735
|
+
//#endregion
|
|
9736
|
+
//#region ../nice-wire/src/Connect/exchangeSessionShelf.ts
|
|
9737
|
+
/** Lapse a little before the acceptor would, so a request is never sent on its last second. */
|
|
9738
|
+
function expiryFor(receivedAt, ttlMs) {
|
|
9739
|
+
if (ttlMs == null || !(ttlMs > 0)) return void 0;
|
|
9740
|
+
return receivedAt + ttlMs - Math.min(6e4, ttlMs / 10);
|
|
9741
|
+
}
|
|
9742
|
+
function stateFromRecord(link, record) {
|
|
9743
|
+
const crypto = record.km != null ? createActionFrameCrypto({
|
|
9744
|
+
link,
|
|
9745
|
+
keyMaterial: record.km
|
|
9746
|
+
}) : void 0;
|
|
9747
|
+
return {
|
|
9748
|
+
token: record.t,
|
|
9749
|
+
crypto,
|
|
9750
|
+
expiresAt: record.exp,
|
|
9751
|
+
record
|
|
9752
|
+
};
|
|
9753
|
+
}
|
|
9754
|
+
function isLapsed(state) {
|
|
9755
|
+
return state.expiresAt != null && Date.now() >= state.expiresAt;
|
|
9756
|
+
}
|
|
9757
|
+
/**
|
|
9758
|
+
* One session's lifecycle: at most one handshake in flight, shared by every caller; a refused or
|
|
9759
|
+
* lapsed session is replaced once, however many requests noticed it.
|
|
9760
|
+
*/
|
|
9761
|
+
var ExchangeSessionSlot = class {
|
|
9762
|
+
_entry;
|
|
9763
|
+
current(initial, replacement) {
|
|
9764
|
+
const entry = this._entry;
|
|
9765
|
+
if (entry == null) return this._start(initial);
|
|
9766
|
+
if (entry.state != null && isLapsed(entry.state)) return this.renew(entry.state, replacement);
|
|
9767
|
+
return entry.promise;
|
|
9768
|
+
}
|
|
9769
|
+
renew(stale, replacement) {
|
|
9770
|
+
const entry = this._entry;
|
|
9771
|
+
if (entry != null && entry.state !== stale) return entry.promise;
|
|
9772
|
+
return this._start(replacement);
|
|
9773
|
+
}
|
|
9774
|
+
_start(establish) {
|
|
9775
|
+
const entry = { promise: establish() };
|
|
9776
|
+
this._entry = entry;
|
|
9777
|
+
entry.promise.then((state) => {
|
|
9778
|
+
entry.state = state;
|
|
9779
|
+
}, () => {
|
|
9780
|
+
if (this._entry === entry) this._entry = void 0;
|
|
9781
|
+
});
|
|
9782
|
+
return entry.promise;
|
|
9783
|
+
}
|
|
9784
|
+
};
|
|
9785
|
+
/** A session source for one transport alone — today's behaviour, plus renewal on refusal. */
|
|
9786
|
+
function privateSessionSource(handshake) {
|
|
9787
|
+
const slot = new ExchangeSessionSlot();
|
|
9788
|
+
return {
|
|
9789
|
+
current: () => slot.current(handshake, handshake),
|
|
9790
|
+
renew: (stale) => slot.renew(stale, handshake)
|
|
9791
|
+
};
|
|
9792
|
+
}
|
|
9793
|
+
const STORE_KEY = "sessions";
|
|
9794
|
+
const SEAL_VERSION = "connector-exchange-session/v1";
|
|
9795
|
+
/**
|
|
9796
|
+
* Every session one crypto identity holds with its peers, keyed by peer identity: shared in memory
|
|
9797
|
+
* by all of the link's transports, and kept in the link's own storage so a reload restores it.
|
|
9798
|
+
* Stored copies are sealed with a key derived from the link's private key — useless to another
|
|
9799
|
+
* device, and unopenable once the identity is reset.
|
|
9800
|
+
*/
|
|
9801
|
+
var ExchangeSessionShelf = class {
|
|
9802
|
+
_link;
|
|
9803
|
+
_slots = /* @__PURE__ */ new Map();
|
|
9804
|
+
_storage;
|
|
9805
|
+
_sealer;
|
|
9806
|
+
constructor(_link) {
|
|
9807
|
+
this._link = _link;
|
|
9808
|
+
this._storage = _link.scopedStorage("wire-exchange/");
|
|
9809
|
+
this._sealer = createExchangeTicketSealer(_link, { version: SEAL_VERSION });
|
|
9810
|
+
}
|
|
9811
|
+
source(key, handshake) {
|
|
9812
|
+
let slot = this._slots.get(key);
|
|
9813
|
+
if (slot == null) {
|
|
9814
|
+
slot = new ExchangeSessionSlot();
|
|
9815
|
+
this._slots.set(key, slot);
|
|
9816
|
+
}
|
|
9817
|
+
const held = slot;
|
|
9818
|
+
const handshakeAndKeep = async () => {
|
|
9819
|
+
const state = await handshake();
|
|
9820
|
+
await this._keep(key, state).catch(() => void 0);
|
|
9821
|
+
return state;
|
|
9822
|
+
};
|
|
9823
|
+
const restoreOrHandshake = async () => {
|
|
9824
|
+
return await this._restore(key).catch(() => void 0) ?? await handshakeAndKeep();
|
|
9825
|
+
};
|
|
9826
|
+
const replace = async () => {
|
|
9827
|
+
await this._forget(key).catch(() => void 0);
|
|
9828
|
+
return await handshakeAndKeep();
|
|
9829
|
+
};
|
|
9830
|
+
return {
|
|
9831
|
+
current: () => held.current(restoreOrHandshake, replace),
|
|
9832
|
+
renew: (stale) => held.renew(stale, replace)
|
|
9833
|
+
};
|
|
9834
|
+
}
|
|
9835
|
+
async _restore(key) {
|
|
9836
|
+
const storage = this._storage;
|
|
9837
|
+
if (storage == null) return void 0;
|
|
9838
|
+
const stored = (await storage.getJson(STORE_KEY))?.[key];
|
|
9839
|
+
if (stored == null || stored.exp <= Date.now()) return void 0;
|
|
9840
|
+
await this._link.initialize();
|
|
9841
|
+
const record = await this._sealer.open(stored.sealed);
|
|
9842
|
+
if (record == null || typeof record.t !== "string") return void 0;
|
|
9843
|
+
return stateFromRecord(this._link, record);
|
|
9844
|
+
}
|
|
9845
|
+
async _keep(key, state) {
|
|
9846
|
+
const storage = this._storage;
|
|
9847
|
+
const record = state.record;
|
|
9848
|
+
if (storage == null || record?.exp == null) return;
|
|
9849
|
+
const ttl = record.exp - Date.now();
|
|
9850
|
+
if (ttl <= 0) return;
|
|
9851
|
+
const sealed = await this._sealer.seal(record, ttl);
|
|
9852
|
+
await this._update(storage, (sessions) => ({
|
|
9853
|
+
...sessions,
|
|
9854
|
+
[key]: {
|
|
9855
|
+
exp: record.exp ?? 0,
|
|
9856
|
+
sealed
|
|
9857
|
+
}
|
|
9858
|
+
}));
|
|
9859
|
+
}
|
|
9860
|
+
async _forget(key) {
|
|
9861
|
+
const storage = this._storage;
|
|
9862
|
+
if (storage == null) return;
|
|
9863
|
+
await this._update(storage, (sessions) => {
|
|
9864
|
+
const { [key]: _dropped, ...rest } = sessions;
|
|
9865
|
+
return rest;
|
|
9866
|
+
});
|
|
9867
|
+
}
|
|
9868
|
+
async _update(storage, change) {
|
|
9869
|
+
await storage.updateJsonOrDef(STORE_KEY, {}, (current) => {
|
|
9870
|
+
const now = Date.now();
|
|
9871
|
+
const live = {};
|
|
9872
|
+
for (const [key, entry] of Object.entries(change(current))) if (entry.exp > now) live[key] = entry;
|
|
9873
|
+
return live;
|
|
9874
|
+
});
|
|
9875
|
+
}
|
|
9876
|
+
};
|
|
9877
|
+
const shelves = /* @__PURE__ */ new WeakMap();
|
|
9878
|
+
/**
|
|
9879
|
+
* The source a secure exchange draws its session from: shared by peer identity when the config asks
|
|
9880
|
+
* for reuse and names the peer, private to this transport otherwise.
|
|
9881
|
+
*/
|
|
9882
|
+
function exchangeSessionSource(secure, lane, handshake) {
|
|
9883
|
+
const peer = secure.expectedPeer;
|
|
9884
|
+
if (secure.reuseExchangeSessions !== true || peer == null) return privateSessionSource(handshake);
|
|
9885
|
+
let shelf = shelves.get(secure.link);
|
|
9886
|
+
if (shelf == null) {
|
|
9887
|
+
shelf = new ExchangeSessionShelf(secure.link);
|
|
9888
|
+
shelves.set(secure.link, shelf);
|
|
9889
|
+
}
|
|
9890
|
+
const key = JSON.stringify([
|
|
9891
|
+
secure.localCoordinate.envId,
|
|
9892
|
+
secure.localCoordinate.perId ?? null,
|
|
9893
|
+
peer.envId,
|
|
9894
|
+
peer.perId ?? null,
|
|
9895
|
+
secure.securityLevel,
|
|
9896
|
+
lane.dictionaryVersion,
|
|
9897
|
+
[...lane.channels ?? []].sort()
|
|
9898
|
+
]);
|
|
9899
|
+
return shelf.source(key, handshake);
|
|
9900
|
+
}
|
|
9901
|
+
//#endregion
|
|
9569
9902
|
//#region ../nice-wire/src/Connect/exchangeSession.ts
|
|
9570
9903
|
const textEncoder$1 = new TextEncoder();
|
|
9571
9904
|
const textDecoder$1 = new TextDecoder();
|
|
9905
|
+
const PLAIN_STATE = {};
|
|
9572
9906
|
/** Plain path (no handshake/token): every wire rides a bare `act` envelope, plaintext both ways. */
|
|
9573
9907
|
function establishPlainExchangeSession(carrier) {
|
|
9574
|
-
return makeSession(carrier, {
|
|
9908
|
+
return makeSession(carrier, {
|
|
9909
|
+
current: async () => PLAIN_STATE,
|
|
9910
|
+
renew: async () => PLAIN_STATE
|
|
9911
|
+
});
|
|
9575
9912
|
}
|
|
9576
9913
|
/**
|
|
9577
|
-
* Secure path: run the handshake (two exchanges)
|
|
9578
|
-
* The lane supplies the handshake payload (`dictionaryVersion`/`channels`,
|
|
9579
|
-
* byte-frozen wire names; the version is signed into the challenge).
|
|
9914
|
+
* Secure path: run the handshake (two exchanges) at bring-up — or restore a kept session — then
|
|
9915
|
+
* reuse the token + crypto. The lane supplies the handshake payload (`dictionaryVersion`/`channels`,
|
|
9916
|
+
* E5 — emitted under the byte-frozen wire names; the version is signed into the challenge).
|
|
9580
9917
|
*/
|
|
9581
9918
|
async function establishSecureExchangeSession(ctx) {
|
|
9582
|
-
const
|
|
9583
|
-
|
|
9584
|
-
|
|
9585
|
-
|
|
9586
|
-
|
|
9587
|
-
|
|
9588
|
-
|
|
9919
|
+
const source = exchangeSessionSource(ctx.secure, ctx.lane, () => runConnectorExchangeHandshake(ctx.carrier, ctx.secure, ctx.lane));
|
|
9920
|
+
await source.current();
|
|
9921
|
+
return makeSession(ctx.carrier, source, ctx.secure.localCoordinate.insId);
|
|
9922
|
+
}
|
|
9923
|
+
function makeSession(carrier, source, insId) {
|
|
9924
|
+
const post = async (state, wire, signal) => {
|
|
9925
|
+
const request = await buildRequestEnvelope(state, wire, insId);
|
|
9926
|
+
return decodeExchangeReply(asString(await carrier.exchange(encodeExchange(request), { signal })));
|
|
9927
|
+
};
|
|
9928
|
+
const roundTrip = async (wire, signal) => {
|
|
9929
|
+
const state = await source.current();
|
|
9930
|
+
const reply = await post(state, wire, signal);
|
|
9931
|
+
if (reply?.k !== "err" || reply.id !== "session_refused" || state.token == null) return {
|
|
9932
|
+
state,
|
|
9933
|
+
reply
|
|
9934
|
+
};
|
|
9935
|
+
const renewed = await source.renew(state);
|
|
9936
|
+
return {
|
|
9937
|
+
state: renewed,
|
|
9938
|
+
reply: await post(renewed, wire, signal)
|
|
9939
|
+
};
|
|
9589
9940
|
};
|
|
9590
9941
|
return {
|
|
9591
9942
|
send: async (wire, opts) => {
|
|
9592
|
-
await
|
|
9943
|
+
await roundTrip(wire, opts?.signal);
|
|
9593
9944
|
},
|
|
9594
9945
|
exchange: async (wire, opts) => {
|
|
9595
|
-
const reply =
|
|
9946
|
+
const { state, reply } = await roundTrip(wire, opts?.signal);
|
|
9596
9947
|
if (reply == null) return {
|
|
9597
9948
|
ok: false,
|
|
9598
9949
|
reason: "malformed_reply"
|
|
@@ -9614,18 +9965,21 @@ function makeSession(carrier, state) {
|
|
|
9614
9965
|
}
|
|
9615
9966
|
};
|
|
9616
9967
|
}
|
|
9617
|
-
async function buildRequestEnvelope(state, wire) {
|
|
9968
|
+
async function buildRequestEnvelope(state, wire, insId) {
|
|
9969
|
+
const i = state.token != null ? insId : void 0;
|
|
9618
9970
|
if (state.crypto != null) {
|
|
9619
9971
|
const ciphertext = await state.crypto.encryptFrame(textEncoder$1.encode(JSON.stringify(wire)));
|
|
9620
9972
|
return {
|
|
9621
9973
|
k: "act",
|
|
9622
9974
|
t: state.token,
|
|
9975
|
+
i,
|
|
9623
9976
|
c: bytesToBase64(ciphertext)
|
|
9624
9977
|
};
|
|
9625
9978
|
}
|
|
9626
9979
|
return {
|
|
9627
9980
|
k: "act",
|
|
9628
9981
|
t: state.token,
|
|
9982
|
+
i,
|
|
9629
9983
|
w: wire
|
|
9630
9984
|
};
|
|
9631
9985
|
}
|
|
@@ -9668,14 +10022,13 @@ async function runConnectorExchangeHandshake(carrier, secure, lane) {
|
|
|
9668
10022
|
if (accept.t !== "accept") throw nonProtocolReply(carrier, "an accept frame", `hs/${accept.t}`);
|
|
9669
10023
|
if (acceptReply.t == null) throw new Error(`[${HANDSHAKE_STAGE}] accept missing session token${at(carrier)}`);
|
|
9670
10024
|
const result = await handshake.onAccept(accept);
|
|
9671
|
-
const
|
|
9672
|
-
|
|
9673
|
-
|
|
9674
|
-
|
|
9675
|
-
|
|
9676
|
-
|
|
9677
|
-
|
|
9678
|
-
};
|
|
10025
|
+
const keyMaterial = result.securityLevel === "encrypted" ? result.encryptionKeyMaterial : void 0;
|
|
10026
|
+
return stateFromRecord(secure.link, {
|
|
10027
|
+
t: acceptReply.t,
|
|
10028
|
+
level: result.securityLevel,
|
|
10029
|
+
km: keyMaterial,
|
|
10030
|
+
exp: expiryFor(Date.now(), acceptReply.ttl)
|
|
10031
|
+
});
|
|
9679
10032
|
}
|
|
9680
10033
|
const HANDSHAKE_STAGE = "exchange-handshake";
|
|
9681
10034
|
/**
|
|
@@ -10261,50 +10614,6 @@ var WireAcceptor = class {
|
|
|
10261
10614
|
}
|
|
10262
10615
|
};
|
|
10263
10616
|
//#endregion
|
|
10264
|
-
//#region ../nice-wire/src/SecureSession/exchangeTicketSeal.ts
|
|
10265
|
-
const SEALED_ENVELOPE_LENGTH = 2;
|
|
10266
|
-
function createExchangeTicketSealer(link, options = {}) {
|
|
10267
|
-
let keyPromise;
|
|
10268
|
-
const getKey = () => {
|
|
10269
|
-
if (keyPromise == null) keyPromise = link.deriveLocalSealKey({ version: options.version }).catch((err) => {
|
|
10270
|
-
keyPromise = void 0;
|
|
10271
|
-
throw err;
|
|
10272
|
-
});
|
|
10273
|
-
return keyPromise;
|
|
10274
|
-
};
|
|
10275
|
-
return {
|
|
10276
|
-
async seal(value, ttlMs) {
|
|
10277
|
-
const { nonce, ciphertext } = await encryptBytesWithAesGcmKey({
|
|
10278
|
-
dataToEncrypt: pack({
|
|
10279
|
-
v: value,
|
|
10280
|
-
exp: Date.now() + ttlMs
|
|
10281
|
-
}),
|
|
10282
|
-
aesGcmKey: await getKey()
|
|
10283
|
-
});
|
|
10284
|
-
return bytesToBase64(pack([nonce, ciphertext]));
|
|
10285
|
-
},
|
|
10286
|
-
async open(blob) {
|
|
10287
|
-
try {
|
|
10288
|
-
const envelope = unpack(base64ToBytes(blob));
|
|
10289
|
-
if (!Array.isArray(envelope) || envelope.length !== SEALED_ENVELOPE_LENGTH) return void 0;
|
|
10290
|
-
const [nonce, ciphertext] = envelope;
|
|
10291
|
-
if (!(nonce instanceof Uint8Array) || !(ciphertext instanceof Uint8Array)) return void 0;
|
|
10292
|
-
const payload = unpack(await decryptBytesWithAesGcmKey({
|
|
10293
|
-
dataToDecrypt: {
|
|
10294
|
-
nonce,
|
|
10295
|
-
ciphertext
|
|
10296
|
-
},
|
|
10297
|
-
aesGcmKey: await getKey()
|
|
10298
|
-
}));
|
|
10299
|
-
if (payload == null || typeof payload.exp !== "number" || payload.exp < Date.now()) return;
|
|
10300
|
-
return payload.v;
|
|
10301
|
-
} catch {
|
|
10302
|
-
return;
|
|
10303
|
-
}
|
|
10304
|
-
}
|
|
10305
|
-
};
|
|
10306
|
-
}
|
|
10307
|
-
//#endregion
|
|
10308
10617
|
//#region ../nice-wire/src/Connect/WireExchangeAcceptor.ts
|
|
10309
10618
|
/** The default session-ticket lifetime — see {@link IWireExchangeAcceptorOptions.sessionTtlMs}. */
|
|
10310
10619
|
const DEFAULT_SESSION_TTL_MS = 720 * 60 * 1e3;
|
|
@@ -10374,11 +10683,17 @@ var WireExchangeAcceptor = class {
|
|
|
10374
10683
|
m: encodeHandshakeMessage(reply)
|
|
10375
10684
|
};
|
|
10376
10685
|
const pending = handshake.exportPending();
|
|
10377
|
-
|
|
10686
|
+
const dv = this._dictionaryVersion(message.channels);
|
|
10687
|
+
if (pending == null || dv == null) return {
|
|
10378
10688
|
k: "err",
|
|
10379
10689
|
message: "handshake produced no continuation state"
|
|
10380
10690
|
};
|
|
10381
|
-
const
|
|
10691
|
+
const continuation = {
|
|
10692
|
+
...pending,
|
|
10693
|
+
dv,
|
|
10694
|
+
ch: message.channels
|
|
10695
|
+
};
|
|
10696
|
+
const hsc = await this._sealer.seal(continuation, HANDSHAKE_CONTINUATION_TTL_MS);
|
|
10382
10697
|
return {
|
|
10383
10698
|
k: "hs",
|
|
10384
10699
|
m: encodeHandshakeMessage(reply),
|
|
@@ -10390,11 +10705,12 @@ var WireExchangeAcceptor = class {
|
|
|
10390
10705
|
k: "err",
|
|
10391
10706
|
message: "prove missing continuation token"
|
|
10392
10707
|
};
|
|
10393
|
-
const
|
|
10394
|
-
if (
|
|
10708
|
+
const continuation = await this._sealer.open(request.hsc);
|
|
10709
|
+
if (continuation == null) return {
|
|
10395
10710
|
k: "err",
|
|
10396
10711
|
message: "invalid or expired continuation token"
|
|
10397
10712
|
};
|
|
10713
|
+
const { dv, ch, ...pending } = continuation;
|
|
10398
10714
|
const handshake = this._makeHandshake();
|
|
10399
10715
|
await handshake.restorePending(pending);
|
|
10400
10716
|
const reply = await handshake.onProve(message);
|
|
@@ -10403,13 +10719,16 @@ var WireExchangeAcceptor = class {
|
|
|
10403
10719
|
const ticket = {
|
|
10404
10720
|
client: result.remote,
|
|
10405
10721
|
securityLevel: result.securityLevel,
|
|
10406
|
-
keyMaterial: result.encryptionKeyMaterial
|
|
10722
|
+
keyMaterial: result.encryptionKeyMaterial,
|
|
10723
|
+
dv,
|
|
10724
|
+
ch
|
|
10407
10725
|
};
|
|
10408
10726
|
const t = await this._sealer.seal(ticket, this._sessionTtlMs);
|
|
10409
10727
|
return {
|
|
10410
10728
|
k: "hs",
|
|
10411
10729
|
m: encodeHandshakeMessage(reply),
|
|
10412
|
-
t
|
|
10730
|
+
t,
|
|
10731
|
+
ttl: this._sessionTtlMs
|
|
10413
10732
|
};
|
|
10414
10733
|
}
|
|
10415
10734
|
return {
|
|
@@ -10422,6 +10741,10 @@ var WireExchangeAcceptor = class {
|
|
|
10422
10741
|
message: `unexpected handshake message ${message.t}`
|
|
10423
10742
|
};
|
|
10424
10743
|
}
|
|
10744
|
+
_dictionaryVersion(channels) {
|
|
10745
|
+
const version = this._lane.dictionaryVersion;
|
|
10746
|
+
return typeof version === "function" ? version({ channels: channels == null ? void 0 : [...channels] }) : version;
|
|
10747
|
+
}
|
|
10425
10748
|
async _handleAction(request) {
|
|
10426
10749
|
let client;
|
|
10427
10750
|
let crypto;
|
|
@@ -10429,24 +10752,30 @@ var WireExchangeAcceptor = class {
|
|
|
10429
10752
|
let securityLevel = "none";
|
|
10430
10753
|
if (request.t != null) {
|
|
10431
10754
|
const ticket = await this._sealer.open(request.t);
|
|
10432
|
-
if (ticket == null) return
|
|
10433
|
-
|
|
10434
|
-
|
|
10435
|
-
|
|
10436
|
-
|
|
10755
|
+
if (ticket == null) return refused("unknown or expired session token");
|
|
10756
|
+
if (ticket.dv != null && ticket.dv !== this._dictionaryVersion(ticket.ch)) return refused("session was agreed under another dictionary version");
|
|
10757
|
+
client = new RuntimeCoordinate(typeof request.i === "string" ? {
|
|
10758
|
+
...ticket.client,
|
|
10759
|
+
insId: request.i
|
|
10760
|
+
} : ticket.client);
|
|
10437
10761
|
securityLevel = ticket.securityLevel;
|
|
10438
|
-
|
|
10439
|
-
|
|
10440
|
-
|
|
10441
|
-
|
|
10442
|
-
|
|
10443
|
-
|
|
10444
|
-
|
|
10445
|
-
|
|
10446
|
-
|
|
10447
|
-
|
|
10448
|
-
|
|
10449
|
-
|
|
10762
|
+
if (ticket.securityLevel === "encrypted") {
|
|
10763
|
+
if (!("c" in request)) return refused("encrypted session refuses a plaintext act");
|
|
10764
|
+
if (ticket.keyMaterial == null) return refused("encrypted session has no key material");
|
|
10765
|
+
crypto = createActionFrameCrypto({
|
|
10766
|
+
link: this._security.link,
|
|
10767
|
+
keyMaterial: ticket.keyMaterial
|
|
10768
|
+
});
|
|
10769
|
+
try {
|
|
10770
|
+
const plain = await crypto.decryptFrame(base64ToBytes(request.c));
|
|
10771
|
+
wire = JSON.parse(textDecoder.decode(plain));
|
|
10772
|
+
} catch {
|
|
10773
|
+
return refused("undecryptable act");
|
|
10774
|
+
}
|
|
10775
|
+
} else {
|
|
10776
|
+
if ("c" in request) return refused("session is not encrypted");
|
|
10777
|
+
wire = request.w;
|
|
10778
|
+
}
|
|
10450
10779
|
} else {
|
|
10451
10780
|
if (!this._noneAllowed || "c" in request) return {
|
|
10452
10781
|
k: "err",
|
|
@@ -10464,7 +10793,7 @@ var WireExchangeAcceptor = class {
|
|
|
10464
10793
|
k: "err",
|
|
10465
10794
|
message: laneReply.message
|
|
10466
10795
|
};
|
|
10467
|
-
if (crypto != null
|
|
10796
|
+
if (crypto != null) return {
|
|
10468
10797
|
k: "act",
|
|
10469
10798
|
c: bytesToBase64(await crypto.encryptFrame(textEncoder.encode(JSON.stringify(laneReply.wire))))
|
|
10470
10799
|
};
|
|
@@ -10480,6 +10809,13 @@ var WireExchangeAcceptor = class {
|
|
|
10480
10809
|
});
|
|
10481
10810
|
}
|
|
10482
10811
|
};
|
|
10812
|
+
function refused(message) {
|
|
10813
|
+
return {
|
|
10814
|
+
k: "err",
|
|
10815
|
+
message,
|
|
10816
|
+
id: WIRE_EXCHANGE_SESSION_REFUSED
|
|
10817
|
+
};
|
|
10818
|
+
}
|
|
10483
10819
|
//#endregion
|
|
10484
10820
|
//#region ../nice-wire/src/codec/controlFrame.ts
|
|
10485
10821
|
/** msgpack map (object) first-byte prefixes — fixmap `0x80–0x8f`, map16 `0xde`, map32 `0xdf`. */
|
|
@@ -16873,6 +17209,7 @@ function transport(options) {
|
|
|
16873
17209
|
link,
|
|
16874
17210
|
localCoordinate: (options.identity ?? options.runtime.coordinate).toJsonObject(),
|
|
16875
17211
|
expectedPeer: options.expectedPeer?.toJsonObject(),
|
|
17212
|
+
reuseExchangeSessions: options.reuseExchangeSessions,
|
|
16876
17213
|
dictionaryVersion: channel.dictionaryVersion,
|
|
16877
17214
|
channelTags: channel.tags,
|
|
16878
17215
|
mux: options.mux
|
|
@@ -17040,6 +17377,7 @@ function connectChannel(runtime, channel, options) {
|
|
|
17040
17377
|
secure: descriptor.secure ?? true,
|
|
17041
17378
|
link,
|
|
17042
17379
|
securityLevel: descriptor.securityLevel ?? securityLevel,
|
|
17380
|
+
reuseExchangeSessions: options.reuseExchangeSessions,
|
|
17043
17381
|
available: descriptor.available,
|
|
17044
17382
|
label: descriptor.label,
|
|
17045
17383
|
mux: wireMux,
|
|
@@ -24429,7 +24767,8 @@ function commanderStatePaths(dataDir, configKey) {
|
|
|
24429
24767
|
ingestSeqPath: (0, node_path.join)(stateDir, "ingest-seq"),
|
|
24430
24768
|
envOverridesPath: (0, node_path.join)(stateDir, "env-overrides.json"),
|
|
24431
24769
|
savedFiltersPath: (0, node_path.join)(stateDir, "saved-filters.json"),
|
|
24432
|
-
lastStartsPath: (0, node_path.join)(stateDir, "last-starts.json")
|
|
24770
|
+
lastStartsPath: (0, node_path.join)(stateDir, "last-starts.json"),
|
|
24771
|
+
taskDurationsPath: (0, node_path.join)(stateDir, "task-durations.json")
|
|
24433
24772
|
};
|
|
24434
24773
|
}
|
|
24435
24774
|
async function ensureStateDir(paths) {
|
|
@@ -24494,6 +24833,8 @@ const commanderStatusRealm = defineRealm({
|
|
|
24494
24833
|
pid: t.optional(t.number()),
|
|
24495
24834
|
startedAt: t.optional(t.number()),
|
|
24496
24835
|
lastStartedAt: t.optional(t.number()),
|
|
24836
|
+
flags: t.array(t.string()),
|
|
24837
|
+
estimatedMs: t.optional(t.number()),
|
|
24497
24838
|
sawOutputAt: t.optional(t.number()),
|
|
24498
24839
|
lastTask: t.optional(t.object({
|
|
24499
24840
|
outcome: t.string(),
|
|
@@ -24550,6 +24891,11 @@ const commanderStatusRealm = defineRealm({
|
|
|
24550
24891
|
values: t.optional(t.array(t.string())),
|
|
24551
24892
|
source: t.string(),
|
|
24552
24893
|
value: t.optional(t.string())
|
|
24894
|
+
})),
|
|
24895
|
+
flags: t.array(t.object({
|
|
24896
|
+
name: t.string(),
|
|
24897
|
+
args: t.string(),
|
|
24898
|
+
description: t.optional(t.string())
|
|
24553
24899
|
}))
|
|
24554
24900
|
})
|
|
24555
24901
|
})),
|
|
@@ -24709,7 +25055,7 @@ var CommanderDaemonBootError = class extends Error {
|
|
|
24709
25055
|
* a live dev environment, and an upgrade must never be the thing that kills one.
|
|
24710
25056
|
*/
|
|
24711
25057
|
async function replaceSkewedDaemon(paths, skewed) {
|
|
24712
|
-
const daemonLabel = `the daemon for this config (pid ${skewed.pid}, build ${skewed.packageVersion}, protocol v${skewed.protocolVersion}) predates this CLI (protocol
|
|
25058
|
+
const daemonLabel = `the daemon for this config (pid ${skewed.pid}, build ${skewed.packageVersion}, protocol v${skewed.protocolVersion}) predates this CLI (protocol v8${skewed.skew === "realm-schema" ? ", different status schema" : ""})`;
|
|
24713
25059
|
let liveIds;
|
|
24714
25060
|
try {
|
|
24715
25061
|
liveIds = (await (0, _nice_code_process.openProcessLedger)({
|
|
@@ -24939,8 +25285,50 @@ function checkStart(value) {
|
|
|
24939
25285
|
if (wait != null) input.wait = wait;
|
|
24940
25286
|
if (staggerMs != null) input.staggerMs = staggerMs;
|
|
24941
25287
|
if (replaceSame != null) input.replaceSame = replaceSame;
|
|
25288
|
+
if (record["flags"] != null) {
|
|
25289
|
+
const flags = checkFlagsById(record["flags"]);
|
|
25290
|
+
if (typeof flags === "string") return `flags${flags}`;
|
|
25291
|
+
input.flags = flags;
|
|
25292
|
+
}
|
|
24942
25293
|
return input;
|
|
24943
25294
|
}
|
|
25295
|
+
function checkFlagsById(value) {
|
|
25296
|
+
const record = asRecord(value);
|
|
25297
|
+
if (record == null) return ": expected an object keyed by process id";
|
|
25298
|
+
const checked = {};
|
|
25299
|
+
for (const [id, names] of Object.entries(record)) {
|
|
25300
|
+
const list = asIdList(names);
|
|
25301
|
+
if (list == null) return `[${JSON.stringify(id)}]: expected an array of flag names`;
|
|
25302
|
+
checked[id] = list;
|
|
25303
|
+
}
|
|
25304
|
+
return checked;
|
|
25305
|
+
}
|
|
25306
|
+
function checkNoteRuns(value) {
|
|
25307
|
+
const runs = asRecord(value)?.["runs"];
|
|
25308
|
+
if (!Array.isArray(runs)) return "runs: expected an array";
|
|
25309
|
+
const checked = [];
|
|
25310
|
+
for (const entry of runs) {
|
|
25311
|
+
const run = asRecord(entry);
|
|
25312
|
+
if (run == null) return "runs: expected objects";
|
|
25313
|
+
const { id, startedAt, durationMs } = run;
|
|
25314
|
+
const flags = asIdList(run["flags"]);
|
|
25315
|
+
if (typeof id !== "string" || id === "") return "runs: id expected a process id";
|
|
25316
|
+
if (typeof startedAt !== "number" || !Number.isFinite(startedAt)) return "runs: startedAt expected epoch ms";
|
|
25317
|
+
if (flags == null) return "runs: flags expected an array of flag names";
|
|
25318
|
+
if (durationMs != null && (typeof durationMs !== "number" || !(durationMs >= 0))) return "runs: durationMs expected a non-negative number";
|
|
25319
|
+
checked.push(typeof durationMs === "number" ? {
|
|
25320
|
+
id,
|
|
25321
|
+
startedAt,
|
|
25322
|
+
flags,
|
|
25323
|
+
durationMs
|
|
25324
|
+
} : {
|
|
25325
|
+
id,
|
|
25326
|
+
startedAt,
|
|
25327
|
+
flags
|
|
25328
|
+
});
|
|
25329
|
+
}
|
|
25330
|
+
return { runs: checked };
|
|
25331
|
+
}
|
|
24944
25332
|
function checkSetEnv(value) {
|
|
24945
25333
|
const record = asRecord(value);
|
|
24946
25334
|
if (record == null) return "expected an object";
|
|
@@ -25132,6 +25520,7 @@ const commanderControlDomain = createActionRootDomain({ domain: "commander" }).c
|
|
|
25132
25520
|
saveFilter: actionSchema().input({ schema: handSchema(checkSaveFilter) }).output({ schema: handSchema(checkOk) }),
|
|
25133
25521
|
removeFilter: actionSchema().input({ schema: handSchema(checkRemoveFilter) }).output({ schema: handSchema(checkOk) }),
|
|
25134
25522
|
setEnv: actionSchema().input({ schema: handSchema(checkSetEnv) }).output({ schema: handSchema(checkEnvReport) }),
|
|
25523
|
+
noteRuns: actionSchema().input({ schema: handSchema(checkNoteRuns) }).output({ schema: handSchema(checkOk) }),
|
|
25135
25524
|
reloadConfig: actionSchema().input({ schema: handSchema(checkEmpty) }).output({ schema: handSchema(checkReloadResult) }),
|
|
25136
25525
|
shutdown: actionSchema().input({ schema: handSchema(checkEmpty) }).output({ schema: handSchema(checkOk) })
|
|
25137
25526
|
}
|
|
@@ -25177,7 +25566,7 @@ async function findDaemon(config) {
|
|
|
25177
25566
|
async function findSkewedDaemon(config) {
|
|
25178
25567
|
const skewed = await readSkewedInstanceRecord(commanderStatePaths(resolveCommanderDataDir(), config.configKey).instanceRecordPath, commanderStatusRealm.schemaHash);
|
|
25179
25568
|
if (skewed == null || !pidAlive$1(skewed.pid)) return null;
|
|
25180
|
-
const difference = skewed.skew === "protocol" ? `speaks protocol v${skewed.protocolVersion}; this build speaks
|
|
25569
|
+
const difference = skewed.skew === "protocol" ? `speaks protocol v${skewed.protocolVersion}; this build speaks v8` : "was started before an upgrade changed the status schema";
|
|
25181
25570
|
return {
|
|
25182
25571
|
message: `the daemon for this config (pid ${skewed.pid}, port ${skewed.port}, build ${skewed.packageVersion}) ${difference} — this CLI (build ${await commanderPackageVersion()}) cannot talk to it. Run \`nice-commander shutdown\` (it stops a daemon from any build), then retry.`,
|
|
25183
25572
|
pid: skewed.pid,
|
|
@@ -25287,7 +25676,7 @@ async function connectDaemon(handle) {
|
|
|
25287
25676
|
const payload = await (await runtime.handleActionPayload(request)).waitForResultPayload();
|
|
25288
25677
|
if (!payload.result.ok) throw new CliExit(EXIT.failure, `action "${action}" rejected by the daemon`);
|
|
25289
25678
|
const report = parseActionReport(payload.result.output);
|
|
25290
|
-
if (report == null) throw new CliExit(EXIT.failure, `the daemon answered "${action}" with something this CLI does not recognise — protocol ${record.protocolVersion} vs
|
|
25679
|
+
if (report == null) throw new CliExit(EXIT.failure, `the daemon answered "${action}" with something this CLI does not recognise — protocol ${record.protocolVersion} vs 8`);
|
|
25291
25680
|
return report;
|
|
25292
25681
|
},
|
|
25293
25682
|
setEnv: async (input) => {
|
|
@@ -25297,6 +25686,10 @@ async function connectDaemon(handle) {
|
|
|
25297
25686
|
const warnings = payload.result.output.warnings;
|
|
25298
25687
|
return Array.isArray(warnings) ? warnings.filter((entry) => typeof entry === "string") : [];
|
|
25299
25688
|
},
|
|
25689
|
+
noteRuns: async (input) => {
|
|
25690
|
+
const request = commanderControlDomain.actionForId("noteRuns").request(input);
|
|
25691
|
+
if (!(await (await runtime.handleActionPayload(request)).waitForResultPayload()).result.ok) throw new CliExit(EXIT.failure, `action "noteRuns" rejected by the daemon`);
|
|
25692
|
+
},
|
|
25300
25693
|
shutdown: async () => {
|
|
25301
25694
|
const request = commanderControlDomain.actionForId("shutdown").request({});
|
|
25302
25695
|
if (!(await (await runtime.handleActionPayload(request)).waitForResultPayload()).result.ok) throw new CliExit(EXIT.failure, `action "shutdown" rejected by the daemon`);
|
|
@@ -25411,11 +25804,13 @@ async function cmdUp(ctx) {
|
|
|
25411
25804
|
"--no-wait",
|
|
25412
25805
|
"--dry-run",
|
|
25413
25806
|
"--replace-same",
|
|
25807
|
+
"--with",
|
|
25414
25808
|
"--all",
|
|
25415
25809
|
"--any"
|
|
25416
25810
|
]);
|
|
25417
25811
|
if (bad != null) throw new CliExit(EXIT.usage, bad);
|
|
25418
25812
|
const selection = selectOrExit(ctx, { bare: "default" });
|
|
25813
|
+
const flags = flagsOrExit(ctx);
|
|
25419
25814
|
if (ctx.args.flags.has("--dry-run")) {
|
|
25420
25815
|
const { out } = ctx;
|
|
25421
25816
|
if (out.json) out.printJson(selection);
|
|
@@ -25440,7 +25835,8 @@ async function cmdUp(ctx) {
|
|
|
25440
25835
|
ids: selection.ordered,
|
|
25441
25836
|
wait,
|
|
25442
25837
|
...staggerMs > 0 ? { staggerMs } : {},
|
|
25443
|
-
...replaceSame ? { replaceSame } : {}
|
|
25838
|
+
...replaceSame ? { replaceSame } : {},
|
|
25839
|
+
...flags != null ? { flags: { [flags.id]: flags.flags } } : {}
|
|
25444
25840
|
}));
|
|
25445
25841
|
return printReport(ctx.out, report, client.state());
|
|
25446
25842
|
} finally {
|
|
@@ -25451,6 +25847,7 @@ async function controlVerb(ctx, verb) {
|
|
|
25451
25847
|
const known = verb === "restart" ? [
|
|
25452
25848
|
"--no-wait",
|
|
25453
25849
|
"--replace-same",
|
|
25850
|
+
"--with",
|
|
25454
25851
|
"--all",
|
|
25455
25852
|
"--any"
|
|
25456
25853
|
] : ["--all", "--any"];
|
|
@@ -25465,11 +25862,13 @@ async function controlVerb(ctx, verb) {
|
|
|
25465
25862
|
extraIds: Object.keys(client.state().processes ?? {}).filter((id) => !declared.has(id))
|
|
25466
25863
|
});
|
|
25467
25864
|
const replaceSame = ctx.args.flags.has("--replace-same");
|
|
25865
|
+
const flags = verb === "restart" ? flagsOrExit(ctx) : null;
|
|
25468
25866
|
const report = await withProgress(client, ctx.out, new Set(selection.ordered), () => verb === "stop" ? client.control("stop", { ids: selection.ordered }) : client.control("restart", {
|
|
25469
25867
|
ids: selection.ordered,
|
|
25470
25868
|
wait: !ctx.args.flags.has("--no-wait"),
|
|
25471
25869
|
staggerMs: staggerFor(ctx.config, ctx.args.positionals),
|
|
25472
|
-
...replaceSame ? { replaceSame } : {}
|
|
25870
|
+
...replaceSame ? { replaceSame } : {},
|
|
25871
|
+
...flags != null ? { flags: { [flags.id]: flags.flags } } : {}
|
|
25473
25872
|
}));
|
|
25474
25873
|
return printReport(ctx.out, report, client.state());
|
|
25475
25874
|
} finally {
|
|
@@ -25572,7 +25971,7 @@ function reportSignalShutdown(ctx, result, why, reports) {
|
|
|
25572
25971
|
}
|
|
25573
25972
|
//#endregion
|
|
25574
25973
|
//#region src/daemon/envOverrides.ts
|
|
25575
|
-
const STORE_VERSION$
|
|
25974
|
+
const STORE_VERSION$3 = 1;
|
|
25576
25975
|
/** A knob is a port or a log level, not a payload. Bounds keep a mistake from becoming a file. */
|
|
25577
25976
|
const MAX_VALUE_LENGTH = 4096;
|
|
25578
25977
|
const EMPTY_ENV_OVERRIDES = Object.freeze({});
|
|
@@ -25608,7 +26007,7 @@ async function writeEnvOverrides(path, overrides) {
|
|
|
25608
26007
|
mode: 448
|
|
25609
26008
|
});
|
|
25610
26009
|
const store = {
|
|
25611
|
-
version: STORE_VERSION$
|
|
26010
|
+
version: STORE_VERSION$3,
|
|
25612
26011
|
processes: Object.fromEntries(Object.entries(overrides).filter(([, values]) => Object.keys(values).length > 0).map(([id, values]) => [id, { ...values }]))
|
|
25613
26012
|
};
|
|
25614
26013
|
const temp = `${path}.${process.pid}.tmp`;
|
|
@@ -26564,6 +26963,7 @@ async function cmdList(ctx) {
|
|
|
26564
26963
|
endpoints: proc.endpoints,
|
|
26565
26964
|
url: proc.url ?? null,
|
|
26566
26965
|
envVars: proc.envVars,
|
|
26966
|
+
flags: proc.flags,
|
|
26567
26967
|
optIn: proc.optIn
|
|
26568
26968
|
})),
|
|
26569
26969
|
suites: Object.fromEntries(Object.entries(config.suites).map(([name, { name: _name, ...suite }]) => [name, suite])),
|
|
@@ -26625,6 +27025,12 @@ async function cmdExplain(ctx) {
|
|
|
26625
27025
|
selection.ordered.forEach((id, index) => {
|
|
26626
27026
|
out.print(` ${index + 1}. ${id}`);
|
|
26627
27027
|
});
|
|
27028
|
+
const flagged = ctx.config.processes.filter((proc) => selection.direct.includes(proc.id) && proc.flags.length > 0);
|
|
27029
|
+
if (flagged.length > 0) out.print("flags:");
|
|
27030
|
+
for (const proc of flagged) for (const flag of proc.flags) {
|
|
27031
|
+
const about = flag.description != null ? ` — ${flag.description}` : "";
|
|
27032
|
+
out.print(` ${proc.id} --with ${flag.name} appends ${flag.args.join(" ")}${about}`);
|
|
27033
|
+
}
|
|
26628
27034
|
if (!ctx.args.flags.has("--env")) {
|
|
26629
27035
|
out.print(out.paint("gray", "env: `explain <sel> --env` shows each id's spawn environment"));
|
|
26630
27036
|
return EXIT.ok;
|
|
@@ -26877,6 +27283,91 @@ async function cmdLogs(ctx) {
|
|
|
26877
27283
|
}
|
|
26878
27284
|
}
|
|
26879
27285
|
//#endregion
|
|
27286
|
+
//#region src/daemon/lastStarts.ts
|
|
27287
|
+
const STORE_VERSION$2 = 1;
|
|
27288
|
+
/** Newest first, capped at `MAX_LAST_STARTS`. */
|
|
27289
|
+
function bounded$1(entries) {
|
|
27290
|
+
return Object.fromEntries([...entries].sort(([, a], [, b]) => b - a).slice(0, 256));
|
|
27291
|
+
}
|
|
27292
|
+
/** Missing, unreadable or corrupt all read as "nothing started yet" — never a reason to fail a boot. */
|
|
27293
|
+
async function readLastStarts(path) {
|
|
27294
|
+
try {
|
|
27295
|
+
const parsed = JSON.parse(await (0, node_fs_promises.readFile)(path, "utf8"));
|
|
27296
|
+
if (parsed == null || typeof parsed !== "object" || !("processes" in parsed)) return {};
|
|
27297
|
+
const processes = parsed.processes;
|
|
27298
|
+
if (processes == null || typeof processes !== "object" || Array.isArray(processes)) return {};
|
|
27299
|
+
return bounded$1(Object.entries(processes).filter((entry) => typeof entry[1] === "number" && Number.isFinite(entry[1])));
|
|
27300
|
+
} catch {
|
|
27301
|
+
return {};
|
|
27302
|
+
}
|
|
27303
|
+
}
|
|
27304
|
+
async function writeLastStarts(path, lastStarts) {
|
|
27305
|
+
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), {
|
|
27306
|
+
recursive: true,
|
|
27307
|
+
mode: 448
|
|
27308
|
+
});
|
|
27309
|
+
const temp = `${path}.${process.pid}.tmp`;
|
|
27310
|
+
const store = {
|
|
27311
|
+
version: STORE_VERSION$2,
|
|
27312
|
+
processes: bounded$1(Object.entries(lastStarts))
|
|
27313
|
+
};
|
|
27314
|
+
await (0, node_fs_promises.writeFile)(temp, `${JSON.stringify(store, null, 2)}\n`, {
|
|
27315
|
+
encoding: "utf8",
|
|
27316
|
+
mode: 384
|
|
27317
|
+
});
|
|
27318
|
+
await (0, node_fs_promises.rename)(temp, path);
|
|
27319
|
+
}
|
|
27320
|
+
//#endregion
|
|
27321
|
+
//#region src/daemon/taskDurations.ts
|
|
27322
|
+
const STORE_VERSION$1 = 1;
|
|
27323
|
+
/** Each flag set keeps its own samples — `dev-reset+hosted` runs as long as it runs, not as `dev-reset`. */
|
|
27324
|
+
function durationKey(id, flags) {
|
|
27325
|
+
return [id, ...flags].join("+");
|
|
27326
|
+
}
|
|
27327
|
+
/** `durations` with one more sample under `key`, which moves to the newest end of the bound. */
|
|
27328
|
+
function withDuration(durations, key, ms) {
|
|
27329
|
+
const samples = [...durations[key] ?? [], ms].slice(-3);
|
|
27330
|
+
const rest = Object.entries(durations).filter(([existing]) => existing !== key);
|
|
27331
|
+
return Object.fromEntries([...rest, [key, samples]].slice(-256));
|
|
27332
|
+
}
|
|
27333
|
+
/** The mean of the samples, or null with nothing to go on. */
|
|
27334
|
+
function estimateMs(samples) {
|
|
27335
|
+
if (samples == null || samples.length === 0) return null;
|
|
27336
|
+
return Math.round(samples.reduce((total, ms) => total + ms, 0) / samples.length);
|
|
27337
|
+
}
|
|
27338
|
+
/** Missing, unreadable or corrupt all read as "no history yet" — never a reason to fail a boot. */
|
|
27339
|
+
async function readTaskDurations(path) {
|
|
27340
|
+
try {
|
|
27341
|
+
const parsed = JSON.parse(await (0, node_fs_promises.readFile)(path, "utf8"));
|
|
27342
|
+
if (parsed == null || typeof parsed !== "object" || !("tasks" in parsed)) return {};
|
|
27343
|
+
const tasks = parsed.tasks;
|
|
27344
|
+
if (tasks == null || typeof tasks !== "object" || Array.isArray(tasks)) return {};
|
|
27345
|
+
const entries = Object.entries(tasks).flatMap(([key, samples]) => {
|
|
27346
|
+
if (!Array.isArray(samples)) return [];
|
|
27347
|
+
const valid = samples.filter((ms) => typeof ms === "number" && Number.isFinite(ms) && ms >= 0);
|
|
27348
|
+
return valid.length > 0 ? [[key, valid.slice(-3)]] : [];
|
|
27349
|
+
});
|
|
27350
|
+
return Object.fromEntries(entries.slice(-256));
|
|
27351
|
+
} catch {
|
|
27352
|
+
return {};
|
|
27353
|
+
}
|
|
27354
|
+
}
|
|
27355
|
+
async function writeTaskDurations(path, durations) {
|
|
27356
|
+
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), {
|
|
27357
|
+
recursive: true,
|
|
27358
|
+
mode: 448
|
|
27359
|
+
});
|
|
27360
|
+
const temp = `${path}.${process.pid}.tmp`;
|
|
27361
|
+
await (0, node_fs_promises.writeFile)(temp, `${JSON.stringify({
|
|
27362
|
+
version: STORE_VERSION$1,
|
|
27363
|
+
tasks: durations
|
|
27364
|
+
}, null, 2)}\n`, {
|
|
27365
|
+
encoding: "utf8",
|
|
27366
|
+
mode: 384
|
|
27367
|
+
});
|
|
27368
|
+
await (0, node_fs_promises.rename)(temp, path);
|
|
27369
|
+
}
|
|
27370
|
+
//#endregion
|
|
26880
27371
|
//#region src/run/scheduler.ts
|
|
26881
27372
|
async function runTaskPool(options) {
|
|
26882
27373
|
const { failFast } = options;
|
|
@@ -26987,6 +27478,36 @@ function startPump(out, proc) {
|
|
|
26987
27478
|
}
|
|
26988
27479
|
};
|
|
26989
27480
|
}
|
|
27481
|
+
/**
|
|
27482
|
+
* What this run ran reaches the "recently started" order and the task estimates — through the
|
|
27483
|
+
* daemon when one is up (it owns those stores while it runs), else straight into the stores.
|
|
27484
|
+
*/
|
|
27485
|
+
async function noteForegroundRuns(config, paths, runs) {
|
|
27486
|
+
if (runs.length === 0) return;
|
|
27487
|
+
try {
|
|
27488
|
+
const handle = await findDaemon(config);
|
|
27489
|
+
if (handle != null) {
|
|
27490
|
+
const client = await connectDaemon(handle);
|
|
27491
|
+
try {
|
|
27492
|
+
await client.noteRuns({ runs: [...runs] });
|
|
27493
|
+
} finally {
|
|
27494
|
+
client.dispose();
|
|
27495
|
+
}
|
|
27496
|
+
return;
|
|
27497
|
+
}
|
|
27498
|
+
let lastStarts = await readLastStarts(paths.lastStartsPath);
|
|
27499
|
+
let durations = await readTaskDurations(paths.taskDurationsPath);
|
|
27500
|
+
for (const run of runs) {
|
|
27501
|
+
if ((lastStarts[run.id] ?? 0) < run.startedAt) lastStarts = {
|
|
27502
|
+
...lastStarts,
|
|
27503
|
+
[run.id]: run.startedAt
|
|
27504
|
+
};
|
|
27505
|
+
if (run.durationMs != null) durations = withDuration(durations, durationKey(run.id, run.flags), run.durationMs);
|
|
27506
|
+
}
|
|
27507
|
+
await writeLastStarts(paths.lastStartsPath, lastStarts);
|
|
27508
|
+
await writeTaskDurations(paths.taskDurationsPath, durations);
|
|
27509
|
+
} catch {}
|
|
27510
|
+
}
|
|
26990
27511
|
/** Let the last lines flush, then close every pump — the only way each one is guaranteed to end. */
|
|
26991
27512
|
async function drainPumps(pumps, graceMs = 250) {
|
|
26992
27513
|
if (pumps.length === 0) return;
|
|
@@ -26998,10 +27519,18 @@ async function cmdRun(ctx) {
|
|
|
26998
27519
|
const bad = unknownFlags(ctx.args.flags, [
|
|
26999
27520
|
"--parallel",
|
|
27000
27521
|
"--fail-fast",
|
|
27522
|
+
"--with",
|
|
27001
27523
|
"--all",
|
|
27002
27524
|
"--any"
|
|
27003
27525
|
]);
|
|
27004
27526
|
if (bad != null) throw new CliExit(EXIT.usage, bad);
|
|
27527
|
+
const flags = flagsOrExit(ctx);
|
|
27528
|
+
const passthrough = ctx.args.passthrough;
|
|
27529
|
+
const target = passthrough.length > 0 ? singleProcessOrExit(ctx, "--") : null;
|
|
27530
|
+
const unquotable = typeof target?.run === "string" ? passthrough.find((arg) => !SHELL_PLAIN_ARG.test(arg)) : void 0;
|
|
27531
|
+
if (target != null && unquotable != null) throw new CliExit(EXIT.usage, `"${target.id}" runs through a shell, where ${JSON.stringify(unquotable)} would need quoting — pass plain arguments, or declare a flag for it`);
|
|
27532
|
+
/** The one id `--with` / `--` select gets its flags' arguments, then the raw ones. */
|
|
27533
|
+
const extraArgs = (id) => [...flags?.id === id ? flags.args : [], ...target?.id === id ? passthrough : []];
|
|
27005
27534
|
const parallel = numericFlag(ctx.args.flags, "--parallel");
|
|
27006
27535
|
if (parallel != null && typeof parallel === "object") throw new CliExit(EXIT.usage, parallel.error);
|
|
27007
27536
|
const selection = selectOrExit(ctx, { bare: "required" });
|
|
@@ -27050,7 +27579,7 @@ async function cmdRun(ctx) {
|
|
|
27050
27579
|
}
|
|
27051
27580
|
return (0, _nice_code_process.createNiceProcess)({
|
|
27052
27581
|
id: def.id,
|
|
27053
|
-
run: def.run,
|
|
27582
|
+
run: runWithArgs(def.run, extraArgs(def.id)),
|
|
27054
27583
|
...def.shell != null ? { shell: def.shell } : {},
|
|
27055
27584
|
cwd: def.cwd,
|
|
27056
27585
|
env: effectiveEnv(def, overrides),
|
|
@@ -27092,6 +27621,16 @@ async function cmdRun(ctx) {
|
|
|
27092
27621
|
if (await Promise.race([graceful.then(() => true), new Promise((settle) => setTimeout(() => settle(false), TIMEOUT_STOP_GRACE_MS))])) return;
|
|
27093
27622
|
for (const proc of procs) if (proc.pid != null) forceKillTree(proc.pid);
|
|
27094
27623
|
};
|
|
27624
|
+
const ran = [];
|
|
27625
|
+
const noteStart = (def) => {
|
|
27626
|
+
const run = {
|
|
27627
|
+
id: def.id,
|
|
27628
|
+
startedAt: Date.now(),
|
|
27629
|
+
flags: flags?.id === def.id ? flags.flags : []
|
|
27630
|
+
};
|
|
27631
|
+
ran.push(run);
|
|
27632
|
+
return run;
|
|
27633
|
+
};
|
|
27095
27634
|
const runTask = async (def) => {
|
|
27096
27635
|
const proc = procFor(def.id);
|
|
27097
27636
|
if (!single) out.print(`${out.paint("cyan", "▸")} ${out.accent(def.id, def.id)} running…`);
|
|
@@ -27103,8 +27642,10 @@ async function cmdRun(ctx) {
|
|
|
27103
27642
|
});
|
|
27104
27643
|
let timer = null;
|
|
27105
27644
|
let timedOut = false;
|
|
27645
|
+
let run = null;
|
|
27106
27646
|
try {
|
|
27107
27647
|
await proc.start();
|
|
27648
|
+
run = noteStart(def);
|
|
27108
27649
|
if (def.timeoutMs != null) {
|
|
27109
27650
|
timer = setTimeout(() => {
|
|
27110
27651
|
timedOut = true;
|
|
@@ -27133,6 +27674,7 @@ async function cmdRun(ctx) {
|
|
|
27133
27674
|
}
|
|
27134
27675
|
const code = proc.lastExit?.code ?? (proc.state === "succeeded" ? 0 : 1);
|
|
27135
27676
|
const failed = code !== 0;
|
|
27677
|
+
if (!failed && run != null && passthrough.length === 0) run.durationMs = Date.now() - run.startedAt;
|
|
27136
27678
|
out.print(failed ? `${out.paint("red", "✗")} ${out.accent(def.id, def.id)} exit ${code}` : `${out.paint("green", "✓")} ${out.accent(def.id, def.id)} ok`);
|
|
27137
27679
|
return {
|
|
27138
27680
|
id: def.id,
|
|
@@ -27221,6 +27763,7 @@ async function cmdRun(ctx) {
|
|
|
27221
27763
|
}
|
|
27222
27764
|
const proc = procFor(def.id);
|
|
27223
27765
|
await proc.start();
|
|
27766
|
+
noteStart(def);
|
|
27224
27767
|
if (!single) out.print(`${out.paint("cyan", "▸")} ${out.accent(def.id, def.id)} started (pid ${proc.pid ?? "?"})`);
|
|
27225
27768
|
}
|
|
27226
27769
|
if (services.length > 0 && !(failFast && failures.length > 0)) {
|
|
@@ -27243,6 +27786,7 @@ async function cmdRun(ctx) {
|
|
|
27243
27786
|
} finally {
|
|
27244
27787
|
process.removeListener("SIGINT", onSigint);
|
|
27245
27788
|
await Promise.allSettled(procs.filter((proc) => !TERMINAL_STATES.has(proc.state)).map((proc) => proc.stop()));
|
|
27789
|
+
await noteForegroundRuns(config, paths, ran);
|
|
27246
27790
|
}
|
|
27247
27791
|
}
|
|
27248
27792
|
//#endregion
|
|
@@ -27641,16 +28185,19 @@ bare down/restart/logs/run always require a selection — omission never means -
|
|
|
27641
28185
|
* block followed by every entry, in this order.
|
|
27642
28186
|
*/
|
|
27643
28187
|
const COMMAND_HELP = [
|
|
27644
|
-
["up", ` up [sel] [--no-wait] [--dry-run] [--replace-same]
|
|
28188
|
+
["up", ` up [sel] [--no-wait] [--dry-run] [--replace-same] [--with <flag>]
|
|
27645
28189
|
start: deps auto-included, DAG order, live progress;
|
|
27646
|
-
a ready service prints its URL. --
|
|
28190
|
+
a ready service prints its URL. --with turns on a
|
|
28191
|
+
flag the selected process declares (repeat it, or
|
|
28192
|
+
a,b) — one id only. --replace-same lets a
|
|
27647
28193
|
start take an exclusive port from a STRAY — this same
|
|
27648
28194
|
command in the same cwd, started outside the daemon
|
|
27649
28195
|
(a stranger on the port still refuses). --json reports
|
|
27650
28196
|
every id's outcome, state, pid and endpoints as data.`],
|
|
27651
28197
|
["down", " down <sel> stop (reverse-DAG order)"],
|
|
27652
|
-
["restart", ` restart <sel> [--no-wait] [--replace-same]
|
|
27653
|
-
stop + start
|
|
28198
|
+
["restart", ` restart <sel> [--no-wait] [--replace-same] [--with <flag>]
|
|
28199
|
+
stop + start, with the flags of the run it replaces
|
|
28200
|
+
unless --with names others`],
|
|
27654
28201
|
["status", " status [--watch] table from the live status realm"],
|
|
27655
28202
|
["logs", " logs <sel> [-f] merged interleaved tail with colored id prefixes"],
|
|
27656
28203
|
["list", " list config introspection (processes, suites, warnings)"],
|
|
@@ -27659,9 +28206,12 @@ const COMMAND_HELP = [
|
|
|
27659
28206
|
["env", ` env [sel] [--set N=V] [--unset N] declared env vars and their values; --clear drops
|
|
27660
28207
|
overrides. A set value is STICKY: it applies to every
|
|
27661
28208
|
later start until cleared, and never restarts anything.`],
|
|
27662
|
-
["run", ` run <sel> [--parallel N] [--fail-fast]
|
|
28209
|
+
["run", ` run <sel> [--parallel N] [--fail-fast] [--with <flag>] [-- <args>]
|
|
28210
|
+
foreground, no daemon; tasks = local CI shape
|
|
27663
28211
|
(a suite supplies its own parallel/fail-fast),
|
|
27664
28212
|
a single id gets raw inherited stdio (interactive).
|
|
28213
|
+
--with turns on declared flags; anything after --
|
|
28214
|
+
is appended to that one id's command as-is.
|
|
27665
28215
|
--fail-fast = stop at the FIRST failure and stop the
|
|
27666
28216
|
survivors; without it every task still runs, every
|
|
27667
28217
|
failure is reported, and the exit code is still
|
|
@@ -27751,7 +28301,7 @@ async function withTimeout(ctx, run) {
|
|
|
27751
28301
|
async function main() {
|
|
27752
28302
|
const argv = process.argv.slice(2);
|
|
27753
28303
|
if (argv[0] === "daemon") {
|
|
27754
|
-
const { runCommanderDaemon } = await Promise.resolve().then(() => require("./main-
|
|
28304
|
+
const { runCommanderDaemon } = await Promise.resolve().then(() => require("./main-C3BG9bju.cjs"));
|
|
27755
28305
|
return runCommanderDaemon(argv.slice(1));
|
|
27756
28306
|
}
|
|
27757
28307
|
const parsed = parseCliArgs(argv);
|
|
@@ -27759,6 +28309,10 @@ async function main() {
|
|
|
27759
28309
|
process.stderr.write(`nice-commander: ${parsed.error}\n`);
|
|
27760
28310
|
return EXIT.usage;
|
|
27761
28311
|
}
|
|
28312
|
+
if (parsed.passthrough.length > 0 && parsed.command !== "run") {
|
|
28313
|
+
process.stderr.write("nice-commander: arguments after `--` go to a foreground `run` only — a daemon start appends only the flags a process declares (`--with <flag>`)\n");
|
|
28314
|
+
return EXIT.usage;
|
|
28315
|
+
}
|
|
27762
28316
|
if (parsed.help || parsed.command === "help") {
|
|
27763
28317
|
process.stdout.write(helpFor(parsed.command === "help" ? null : parsed.command));
|
|
27764
28318
|
return EXIT.ok;
|
|
@@ -27818,9 +28372,11 @@ exports.createMemoryStorageAdapter_json = createMemoryStorageAdapter_json;
|
|
|
27818
28372
|
exports.createPortInspector = createPortInspector;
|
|
27819
28373
|
exports.createRealmAcceptor = createRealmAcceptor;
|
|
27820
28374
|
exports.createRealmServerEngine = createRealmServerEngine;
|
|
28375
|
+
exports.durationKey = durationKey;
|
|
27821
28376
|
exports.effectiveEnv = effectiveEnv;
|
|
27822
28377
|
exports.ensureStateDir = ensureStateDir;
|
|
27823
28378
|
exports.envVarViews = envVarViews;
|
|
28379
|
+
exports.estimateMs = estimateMs;
|
|
27824
28380
|
exports.findDaemonProcesses = findDaemonProcesses;
|
|
27825
28381
|
exports.hashCanonical = hashCanonical;
|
|
27826
28382
|
exports.httpAcceptorCarrier = httpAcceptorCarrier;
|
|
@@ -27832,19 +28388,26 @@ exports.overrideFingerprint = overrideFingerprint;
|
|
|
27832
28388
|
exports.parseLogsClientMessage = parseLogsClientMessage;
|
|
27833
28389
|
exports.readEnvOverrides = readEnvOverrides;
|
|
27834
28390
|
exports.readInstanceRecord = readInstanceRecord;
|
|
28391
|
+
exports.readLastStarts = readLastStarts;
|
|
27835
28392
|
exports.readSavedFilters = readSavedFilters;
|
|
28393
|
+
exports.readTaskDurations = readTaskDurations;
|
|
27836
28394
|
exports.recordDaemonAlive = recordDaemonAlive;
|
|
27837
28395
|
exports.removeInstanceRecord = removeInstanceRecord;
|
|
27838
28396
|
exports.resolveCommanderDataDir = resolveCommanderDataDir;
|
|
28397
|
+
exports.resolveFlags = resolveFlags;
|
|
27839
28398
|
exports.runTaskPool = runTaskPool;
|
|
28399
|
+
exports.runWithArgs = runWithArgs;
|
|
27840
28400
|
exports.savedFilterId = savedFilterId;
|
|
27841
28401
|
exports.serveChannel = serveChannel;
|
|
27842
28402
|
exports.signalStray = signalStray;
|
|
27843
28403
|
exports.stopSetWithDependencies = stopSetWithDependencies;
|
|
27844
28404
|
exports.validateCommanderConfig = validateCommanderConfig;
|
|
27845
28405
|
exports.withDependencies = withDependencies;
|
|
28406
|
+
exports.withDuration = withDuration;
|
|
27846
28407
|
exports.writeInstanceRecord = writeInstanceRecord;
|
|
28408
|
+
exports.writeLastStarts = writeLastStarts;
|
|
27847
28409
|
exports.writeSavedFilters = writeSavedFilters;
|
|
28410
|
+
exports.writeTaskDurations = writeTaskDurations;
|
|
27848
28411
|
exports.wsAcceptorCarrier = wsAcceptorCarrier;
|
|
27849
28412
|
|
|
27850
28413
|
//# sourceMappingURL=cli.cjs.map
|