@nice-code/commander 0.94.0 → 0.96.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -9
- package/build/cli.cjs +843 -371
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +838 -372
- package/build/cli.mjs.map +1 -1
- package/build/client/assets/index-B71o2DG0.js +23 -0
- package/build/client/assets/index-B71o2DG0.js.map +1 -0
- package/build/client/assets/index-p81Nnav2.css +1 -0
- package/build/client/index.html +2 -2
- package/build/config.cjs.map +1 -1
- package/build/config.d.cts +30 -12
- package/build/config.d.mts +30 -12
- package/build/config.mjs.map +1 -1
- package/build/{main-B7EwREFQ.cjs → main-BBRM0ZOp.cjs} +200 -8
- package/build/main-BBRM0ZOp.cjs.map +1 -0
- package/build/{main-BlAdEbVt.mjs → main-DrNJc_xN.mjs} +201 -9
- package/build/main-DrNJc_xN.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-7N0rwKz3.css +0 -1
- package/build/client/assets/index-RJ2tYN8w.js +0 -23
- package/build/client/assets/index-RJ2tYN8w.js.map +0 -1
- package/build/main-B7EwREFQ.cjs.map +0 -1
- package/build/main-BlAdEbVt.mjs.map +0 -1
package/build/cli.cjs
CHANGED
|
@@ -15,10 +15,10 @@ let module$1 = require("module");
|
|
|
15
15
|
let ws = require("ws");
|
|
16
16
|
let node_os = require("node:os");
|
|
17
17
|
let node_child_process = require("node:child_process");
|
|
18
|
-
let
|
|
18
|
+
let node_net = require("node:net");
|
|
19
19
|
let node_dns_promises = require("node:dns/promises");
|
|
20
20
|
let node_util = require("node:util");
|
|
21
|
-
let
|
|
21
|
+
let node_readline_promises = require("node:readline/promises");
|
|
22
22
|
//#region src/cli/args.ts
|
|
23
23
|
const GLOBAL_VALUE_FLAGS = new Set(["--config", "--timeout"]);
|
|
24
24
|
/**
|
|
@@ -151,7 +151,7 @@ function validStartStamp(value) {
|
|
|
151
151
|
function isInstanceRecord(value) {
|
|
152
152
|
if (value == null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
153
153
|
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.protocolVersion ===
|
|
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.protocolVersion === 6;
|
|
155
155
|
}
|
|
156
156
|
async function writeInstanceRecord(path, record) {
|
|
157
157
|
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), {
|
|
@@ -201,7 +201,7 @@ async function readSkewedInstanceRecord(path, expectedRealmSchemaHash) {
|
|
|
201
201
|
if (!boundedInt(record["protocolVersion"], 0, Number.MAX_SAFE_INTEGER)) return null;
|
|
202
202
|
if (!boundedInt(record["pid"], 1, Number.MAX_SAFE_INTEGER)) return null;
|
|
203
203
|
if (!boundedInt(record["port"], 1, 65535)) return null;
|
|
204
|
-
const sameProtocol = record["protocolVersion"] ===
|
|
204
|
+
const sameProtocol = record["protocolVersion"] === 6;
|
|
205
205
|
const sameRealm = boundedString(record["realmSchemaHash"]) && record["realmSchemaHash"] === expectedRealmSchemaHash;
|
|
206
206
|
if (sameProtocol && sameRealm) return null;
|
|
207
207
|
return {
|
|
@@ -298,6 +298,102 @@ async function pingDaemon(record, timeoutMs = 2e3) {
|
|
|
298
298
|
}
|
|
299
299
|
}
|
|
300
300
|
//#endregion
|
|
301
|
+
//#region src/config/tags.ts
|
|
302
|
+
/** `key=value` → `[key, value]`, or null when the term is not tag-shaped. */
|
|
303
|
+
function parseTagTerm(term) {
|
|
304
|
+
const eq = term.indexOf("=");
|
|
305
|
+
return eq > 0 ? [term.slice(0, eq), term.slice(eq + 1)] : null;
|
|
306
|
+
}
|
|
307
|
+
function hasTag(tags, key, value) {
|
|
308
|
+
return tags[key]?.includes(value) === true;
|
|
309
|
+
}
|
|
310
|
+
/** Every entry must match (AND). */
|
|
311
|
+
function matchesTagQuery(tags, query) {
|
|
312
|
+
return Object.entries(query).every(([key, value]) => hasTag(tags, key, value));
|
|
313
|
+
}
|
|
314
|
+
/** Every `key=value` a process carries, in key order. */
|
|
315
|
+
function tagTermsOf(tags) {
|
|
316
|
+
return Object.entries(tags).flatMap(([key, values]) => values.map((value) => `${key}=${value}`));
|
|
317
|
+
}
|
|
318
|
+
//#endregion
|
|
319
|
+
//#region src/config/tagGroups.ts
|
|
320
|
+
/** Which of `terms` these tags carry, in `terms` order. */
|
|
321
|
+
function tagSignature(tags, terms) {
|
|
322
|
+
return terms.filter((term) => {
|
|
323
|
+
const parsed = parseTagTerm(term);
|
|
324
|
+
return parsed != null && tags[parsed[0]]?.includes(parsed[1]) === true;
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Bucket by signature: most matched terms first, then by where the signature's terms sit in the
|
|
329
|
+
* filter — never by anything live, so buckets hold still while processes change state. In `any`
|
|
330
|
+
* mode the first bucket is the `all` result whenever anything matches every term.
|
|
331
|
+
*/
|
|
332
|
+
function tagGroupsFor(items, terms, mode) {
|
|
333
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
334
|
+
for (const item of items) {
|
|
335
|
+
const signature = tagSignature(item.tags, terms);
|
|
336
|
+
if (signature.length === 0 || mode === "all" && signature.length < terms.length) continue;
|
|
337
|
+
const key = signature.join(",");
|
|
338
|
+
const bucket = buckets.get(key) ?? {
|
|
339
|
+
signature,
|
|
340
|
+
members: []
|
|
341
|
+
};
|
|
342
|
+
bucket.members.push(item);
|
|
343
|
+
buckets.set(key, bucket);
|
|
344
|
+
}
|
|
345
|
+
const rank = (group) => group.signature.map((term) => terms.indexOf(term));
|
|
346
|
+
return [...buckets.values()].sort((a, b) => {
|
|
347
|
+
if (a.signature.length !== b.signature.length) return b.signature.length - a.signature.length;
|
|
348
|
+
const [ra, rb] = [rank(a), rank(b)];
|
|
349
|
+
for (let i = 0; i < ra.length; i += 1) if (ra[i] !== rb[i]) return (ra[i] ?? 0) - (rb[i] ?? 0);
|
|
350
|
+
return 0;
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
function sameSignature(a, b) {
|
|
354
|
+
return a.length === b.length && a.every((term) => b.includes(term));
|
|
355
|
+
}
|
|
356
|
+
function savedFilterId(query) {
|
|
357
|
+
const terms = [...query.terms].sort();
|
|
358
|
+
const bucket = query.bucket == null ? "" : `|${[...query.bucket].sort().join(",")}`;
|
|
359
|
+
return `${query.mode}:${terms.join(",")}${bucket}`;
|
|
360
|
+
}
|
|
361
|
+
/** The members a saved filter selects right now. `optIn` processes are never bulk members. */
|
|
362
|
+
function savedFilterMembers(query, items) {
|
|
363
|
+
const groups = tagGroupsFor(items.filter((item) => !item.optIn), [...query.terms].sort(), query.mode);
|
|
364
|
+
const bucket = query.bucket;
|
|
365
|
+
return (bucket == null ? groups : groups.filter((group) => sameSignature(group.signature, bucket))).flatMap((group) => group.members);
|
|
366
|
+
}
|
|
367
|
+
function asTerms(value) {
|
|
368
|
+
if (!Array.isArray(value) || value.length === 0 || value.length > 16) return null;
|
|
369
|
+
const terms = [];
|
|
370
|
+
for (const entry of value) {
|
|
371
|
+
if (typeof entry !== "string" || entry.length > 512 || parseTagTerm(entry) == null) return null;
|
|
372
|
+
if (!terms.includes(entry)) terms.push(entry);
|
|
373
|
+
}
|
|
374
|
+
return terms.sort();
|
|
375
|
+
}
|
|
376
|
+
/** The one place an untrusted value (the wire, or the file) becomes a query. */
|
|
377
|
+
function checkSavedFilterQuery(value) {
|
|
378
|
+
if (value == null || typeof value !== "object" || Array.isArray(value)) return "expected an object";
|
|
379
|
+
const record = { ...value };
|
|
380
|
+
const mode = record["mode"];
|
|
381
|
+
if (mode !== "all" && mode !== "any") return "mode: expected \"all\" | \"any\"";
|
|
382
|
+
const terms = asTerms(record["terms"]);
|
|
383
|
+
if (terms == null) return `terms: expected 1–16 tag=value strings`;
|
|
384
|
+
if (record["bucket"] == null) return {
|
|
385
|
+
mode,
|
|
386
|
+
terms
|
|
387
|
+
};
|
|
388
|
+
const bucket = asTerms(record["bucket"]);
|
|
389
|
+
if (bucket == null || !bucket.every((term) => terms.includes(term))) return "bucket: expected a subset of terms";
|
|
390
|
+
return {
|
|
391
|
+
mode,
|
|
392
|
+
terms,
|
|
393
|
+
bucket
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
//#endregion
|
|
301
397
|
//#region src/config/resolve.ts
|
|
302
398
|
/** Topological order of the given id set over the dependsOn graph; config order breaks ties. */
|
|
303
399
|
function orderByDependency(processes, ids) {
|
|
@@ -351,40 +447,53 @@ function withDependencies(processes, ids) {
|
|
|
351
447
|
* Resolve CLI/UI selection terms against the model. An empty `terms` is the caller's problem
|
|
352
448
|
* (bare `up` consults `defaultSelection` before ever reaching here).
|
|
353
449
|
*/
|
|
354
|
-
function resolveSelection(config, terms,
|
|
450
|
+
function resolveSelection(config, terms, options = {}) {
|
|
451
|
+
const extraIds = options.extraIds ?? [];
|
|
452
|
+
const bulk = (id) => options.purpose === "address" || config.processes.find((proc) => proc.id === id)?.optIn !== true;
|
|
355
453
|
const errors = [];
|
|
356
454
|
const selectors = /* @__PURE__ */ new Set();
|
|
357
455
|
const tagTerms = [];
|
|
358
456
|
for (const term of terms) {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
457
|
+
if (term.startsWith("@")) {
|
|
458
|
+
const pin = options.pins?.find((candidate) => candidate.name === term.slice(1));
|
|
459
|
+
if (pin == null) {
|
|
460
|
+
errors.push(`unknown pin "${term}" (pins are saved from the web UI)`);
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
for (const proc of savedFilterMembers(pin, config.processes)) selectors.add(proc.id);
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
const tagTerm = parseTagTerm(term);
|
|
467
|
+
if (tagTerm != null) {
|
|
468
|
+
tagTerms.push(tagTerm);
|
|
362
469
|
continue;
|
|
363
470
|
}
|
|
364
471
|
if (term === "all") {
|
|
365
|
-
for (const proc of config.processes) selectors.add(proc.id);
|
|
472
|
+
for (const proc of config.processes) if (bulk(proc.id)) selectors.add(proc.id);
|
|
366
473
|
for (const id of extraIds) selectors.add(id);
|
|
367
474
|
continue;
|
|
368
475
|
}
|
|
369
|
-
if (config.
|
|
370
|
-
for (const id of config.
|
|
476
|
+
if (config.suites[term] != null) {
|
|
477
|
+
for (const id of config.suites[term].ids) selectors.add(id);
|
|
371
478
|
continue;
|
|
372
479
|
}
|
|
373
480
|
if (config.processes.some((proc) => proc.id === term) || extraIds.includes(term)) {
|
|
374
481
|
selectors.add(term);
|
|
375
482
|
continue;
|
|
376
483
|
}
|
|
377
|
-
errors.push(`unknown selection "${term}" (not a process id,
|
|
484
|
+
errors.push(`unknown selection "${term}" (not a process id, suite, @pin, tag=value, or "all")`);
|
|
378
485
|
}
|
|
379
486
|
if (errors.length > 0) return {
|
|
380
487
|
ok: false,
|
|
381
488
|
errors
|
|
382
489
|
};
|
|
383
490
|
let direct = [...selectors];
|
|
384
|
-
if (selectors.size === 0 && tagTerms.length > 0) direct = config.processes.map((proc) => proc.id);
|
|
491
|
+
if (selectors.size === 0 && tagTerms.length > 0) direct = config.processes.filter((proc) => bulk(proc.id)).map((proc) => proc.id);
|
|
385
492
|
if (tagTerms.length > 0) direct = direct.filter((id) => {
|
|
386
493
|
const proc = config.processes.find((candidate) => candidate.id === id);
|
|
387
|
-
|
|
494
|
+
if (proc == null) return false;
|
|
495
|
+
const matches = ([key, value]) => hasTag(proc.tags, key, value);
|
|
496
|
+
return options.any === true ? tagTerms.some(matches) : tagTerms.every(matches);
|
|
388
497
|
});
|
|
389
498
|
const closed = withDependencies(config.processes, direct);
|
|
390
499
|
const ordered = orderByDependency(config.processes, closed);
|
|
@@ -651,6 +760,8 @@ function staleOverrides(config, overrides) {
|
|
|
651
760
|
}
|
|
652
761
|
return stale;
|
|
653
762
|
}
|
|
763
|
+
const SUITE_PARALLEL_DEFAULT = 4;
|
|
764
|
+
const SUITE_STAGGER_DEFAULT_MS = 100;
|
|
654
765
|
/** C0/DEL/C1 control characters have no business in tag keys/values or env keys. */
|
|
655
766
|
function hasControlChars(value) {
|
|
656
767
|
for (let i = 0; i < value.length; i += 1) {
|
|
@@ -660,6 +771,7 @@ function hasControlChars(value) {
|
|
|
660
771
|
return false;
|
|
661
772
|
}
|
|
662
773
|
const MAX_TAGS = 32;
|
|
774
|
+
const MAX_TAG_VALUES = 16;
|
|
663
775
|
function isRecord(value) {
|
|
664
776
|
return typeof value === "object" && value != null && !Array.isArray(value);
|
|
665
777
|
}
|
|
@@ -748,8 +860,52 @@ function findCycle(graph) {
|
|
|
748
860
|
}
|
|
749
861
|
return null;
|
|
750
862
|
}
|
|
751
|
-
|
|
752
|
-
|
|
863
|
+
/**
|
|
864
|
+
* Expand `include`/`where`/`exclude` over a set of sibling definitions. A `where` never picks up
|
|
865
|
+
* an `optIn` process; an explicit `include` does. Callers guarantee the reference graph is
|
|
866
|
+
* acyclic; `seen` only keeps a malformed one from recursing forever.
|
|
867
|
+
*/
|
|
868
|
+
function expandSelection(name, inputs, byId, seen = /* @__PURE__ */ new Set()) {
|
|
869
|
+
const out = /* @__PURE__ */ new Set();
|
|
870
|
+
const input = inputs[name];
|
|
871
|
+
if (seen.has(name) || !isRecord(input)) return out;
|
|
872
|
+
seen.add(name);
|
|
873
|
+
const selection = input;
|
|
874
|
+
for (const entry of selection.include ?? []) if (byId.has(entry)) out.add(entry);
|
|
875
|
+
else if (typeof entry === "string" && entry in inputs) for (const id of expandSelection(entry, inputs, byId, seen)) out.add(id);
|
|
876
|
+
for (const query of normalizeTagQueryOr(selection.where) ?? []) for (const proc of byId.values()) if (!proc.optIn && matchesTagQuery(proc.tags, query)) out.add(proc.id);
|
|
877
|
+
const { ids: excludedIds, queries } = normalizeExcludes(selection.exclude);
|
|
878
|
+
for (const id of excludedIds) out.delete(id);
|
|
879
|
+
for (const id of [...out]) {
|
|
880
|
+
const proc = byId.get(id);
|
|
881
|
+
if (proc != null && queries.some((query) => matchesTagQuery(proc.tags, query))) out.delete(id);
|
|
882
|
+
}
|
|
883
|
+
seen.delete(name);
|
|
884
|
+
return out;
|
|
885
|
+
}
|
|
886
|
+
/** The tag selection that picks out exactly `ids`, if one exists — smallest first. */
|
|
887
|
+
function equivalentTagSelection(ids, byId) {
|
|
888
|
+
const [first, ...rest] = [...ids].flatMap((id) => byId.get(id) ?? []);
|
|
889
|
+
if (first == null) return null;
|
|
890
|
+
const common = tagTermsOf(first.tags).filter((term) => rest.every((proc) => tagTermsOf(proc.tags).includes(term)));
|
|
891
|
+
const selects = (terms) => {
|
|
892
|
+
const matched = [...byId.values()].filter((proc) => !proc.optIn && terms.every((term) => tagTermsOf(proc.tags).includes(term)));
|
|
893
|
+
return matched.length === ids.size && matched.every((proc) => ids.has(proc.id));
|
|
894
|
+
};
|
|
895
|
+
for (const term of common) if (selects([term])) return [term];
|
|
896
|
+
return common.length > 1 && selects(common) ? common : null;
|
|
897
|
+
}
|
|
898
|
+
/** `groups` was removed — say what each one becomes instead of just refusing the key. */
|
|
899
|
+
function groupMigrationErrors(groupsInput, byId) {
|
|
900
|
+
const errors = ["groups: removed — processes are organised by tags, and a run-unit is a `suite`. Per group:"];
|
|
901
|
+
for (const name of Object.keys(groupsInput)) {
|
|
902
|
+
const ids = expandSelection(name, groupsInput, byId);
|
|
903
|
+
const tagSelection = equivalentTagSelection(ids, byId);
|
|
904
|
+
if (ids.size < 2) errors.push(`groups.${name}: one member — delete it and use the id "${[...ids][0] ?? "?"}" directly`);
|
|
905
|
+
else if (tagSelection != null) errors.push(`groups.${name}: this is the tag selection \`${tagSelection.join(" ")}\` — delete it and select by tag (pin it in the UI), or move it under \`suites\` if it is a real run-unit`);
|
|
906
|
+
else errors.push(`groups.${name}: move it under \`suites\` unchanged`);
|
|
907
|
+
}
|
|
908
|
+
return errors;
|
|
753
909
|
}
|
|
754
910
|
/**
|
|
755
911
|
* Validate a raw loaded config and build the resolved model. `configDir`/`configPath` are the
|
|
@@ -831,16 +987,25 @@ function validateCommanderConfig(raw, anchor) {
|
|
|
831
987
|
if (resolved != null) envVars.push(resolved);
|
|
832
988
|
}
|
|
833
989
|
for (const declared of envVars) if (declared.default != null) env[declared.name] = declared.default;
|
|
834
|
-
const
|
|
990
|
+
const tagEntries = Object.entries({
|
|
835
991
|
...config.defaults?.tags,
|
|
836
992
|
...proc.tags
|
|
837
|
-
};
|
|
838
|
-
const tagEntries = Object.entries(tags);
|
|
993
|
+
});
|
|
839
994
|
if (tagEntries.length > MAX_TAGS) errors.push(`${at}.tags: ${tagEntries.length} entries exceeds the ${MAX_TAGS} bound`);
|
|
995
|
+
const tags = {};
|
|
840
996
|
for (const [key, value] of tagEntries) {
|
|
841
|
-
if (key === "" || key.length > 64 || hasControlChars(key)) errors.push(`${at}.tags: invalid key ${JSON.stringify(key)}`);
|
|
842
|
-
|
|
997
|
+
if (key === "" || key.length > 64 || key.includes("=") || hasControlChars(key)) errors.push(`${at}.tags: invalid key ${JSON.stringify(key)}`);
|
|
998
|
+
const values = typeof value === "string" ? [value] : value;
|
|
999
|
+
if (!Array.isArray(values) || values.length === 0 || values.length > MAX_TAG_VALUES) {
|
|
1000
|
+
errors.push(`${at}.tags[${JSON.stringify(key)}]: expected a string or 1–${MAX_TAG_VALUES} strings`);
|
|
1001
|
+
continue;
|
|
1002
|
+
}
|
|
1003
|
+
const clean = [];
|
|
1004
|
+
for (const entry of values) if (typeof entry !== "string" || entry.length > 256 || entry.includes(",") || hasControlChars(entry)) errors.push(`${at}.tags[${JSON.stringify(key)}]: invalid value`);
|
|
1005
|
+
else if (!clean.includes(entry)) clean.push(entry);
|
|
1006
|
+
tags[key] = clean;
|
|
843
1007
|
}
|
|
1008
|
+
if (proc.optIn != null && typeof proc.optIn !== "boolean") errors.push(`${at}.optIn: expected a boolean`);
|
|
844
1009
|
const endpoints = [];
|
|
845
1010
|
const endpointNames = /* @__PURE__ */ new Set();
|
|
846
1011
|
for (const [endpointIndex, endpoint] of (proc.endpoints ?? []).entries()) {
|
|
@@ -925,6 +1090,7 @@ function validateCommanderConfig(raw, anchor) {
|
|
|
925
1090
|
envVars,
|
|
926
1091
|
stdin,
|
|
927
1092
|
tags,
|
|
1093
|
+
optIn: proc.optIn === true,
|
|
928
1094
|
dependsOn,
|
|
929
1095
|
endpoints,
|
|
930
1096
|
...proc.url != null ? { url: proc.url } : {},
|
|
@@ -942,60 +1108,57 @@ function validateCommanderConfig(raw, anchor) {
|
|
|
942
1108
|
for (const [id, deps] of dependsGraph) for (const dep of deps) if (!byId.has(dep)) errors.push(`process "${id}" dependsOn: unknown id "${dep}"`);
|
|
943
1109
|
const processCycle = findCycle(dependsGraph);
|
|
944
1110
|
if (processCycle != null) errors.push(`dependsOn cycle: ${processCycle.join(" → ")}`);
|
|
945
|
-
const
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
1111
|
+
const removedGroups = raw.groups;
|
|
1112
|
+
if (removedGroups != null) errors.push(...groupMigrationErrors(isRecord(removedGroups) ? removedGroups : {}, byId));
|
|
1113
|
+
const suitesInput = isRecord(config.suites) ? config.suites : {};
|
|
1114
|
+
if (config.suites != null && !isRecord(config.suites)) errors.push("suites: expected an object keyed by suite name");
|
|
1115
|
+
const suiteRefs = /* @__PURE__ */ new Map();
|
|
1116
|
+
for (const [name, suite] of Object.entries(suitesInput)) {
|
|
1117
|
+
const at = `suites.${name}`;
|
|
1118
|
+
if (!require_types.COMMANDER_ID_PATTERN.test(name)) errors.push(`suites.${JSON.stringify(name)}: must match ${require_types.COMMANDER_ID_PATTERN}`);
|
|
1119
|
+
if (name === "all") errors.push(`${at}: "all" is the built-in selector`);
|
|
1120
|
+
if (byId.has(name)) errors.push(`${at}: collides with a process id`);
|
|
1121
|
+
if (!isRecord(suite)) {
|
|
1122
|
+
errors.push(`${at}: expected an object`);
|
|
953
1123
|
continue;
|
|
954
1124
|
}
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
const proc = byId.get(id);
|
|
982
|
-
if (proc != null && queries.some((query) => matchesTags(proc.tags, query))) out.delete(id);
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
seen.delete(name);
|
|
986
|
-
return out;
|
|
987
|
-
};
|
|
988
|
-
for (const name of Object.keys(groupsInput)) {
|
|
989
|
-
const expanded = expand(name, /* @__PURE__ */ new Set());
|
|
990
|
-
const ordered = [...byId.keys()].filter((id) => expanded.has(id));
|
|
991
|
-
if (ordered.length === 0) warnings.push(`groups.${name}: expands to zero processes`);
|
|
992
|
-
const staggerMs = groupsInput[name]?.staggerMs;
|
|
993
|
-
groups[name] = {
|
|
994
|
-
name,
|
|
995
|
-
ids: ordered,
|
|
996
|
-
staggerMs: typeof staggerMs === "number" ? staggerMs : 100
|
|
997
|
-
};
|
|
1125
|
+
const definition = suite;
|
|
1126
|
+
if (definition.description != null && typeof definition.description !== "string") errors.push(`${at}.description: expected a string`);
|
|
1127
|
+
if (definition.parallel != null && (!Number.isInteger(definition.parallel) || definition.parallel < 1)) errors.push(`${at}.parallel: expected an integer ≥ 1`);
|
|
1128
|
+
if (definition.failFast != null && typeof definition.failFast !== "boolean") errors.push(`${at}.failFast: expected a boolean`);
|
|
1129
|
+
if (definition.staggerMs != null && (typeof definition.staggerMs !== "number" || definition.staggerMs < 0)) errors.push(`${at}.staggerMs: expected a non-negative number`);
|
|
1130
|
+
for (const entry of definition.include ?? []) if (typeof entry !== "string") errors.push(`${at}.include: expected id/suite strings`);
|
|
1131
|
+
else if (!byId.has(entry) && !(entry in suitesInput)) errors.push(`${at}.include: unknown id or suite "${entry}"`);
|
|
1132
|
+
const { ids: excludedIds, queries: excludeQueries } = normalizeExcludes(definition.exclude);
|
|
1133
|
+
for (const id of excludedIds) if (!byId.has(id)) errors.push(`${at}.exclude: unknown id "${id}"`);
|
|
1134
|
+
for (const query of [...normalizeTagQueryOr(definition.where) ?? [], ...excludeQueries]) {
|
|
1135
|
+
if (Object.keys(query).length === 0) warnings.push(`${at}: an empty tag query matches everything`);
|
|
1136
|
+
for (const [key, value] of Object.entries(query)) if (typeof value !== "string") errors.push(`${at}: tag query ${JSON.stringify(key)} must map to a string`);
|
|
1137
|
+
}
|
|
1138
|
+
suiteRefs.set(name, (definition.include ?? []).filter((entry) => typeof entry === "string" && entry in suitesInput));
|
|
1139
|
+
}
|
|
1140
|
+
const suiteCycle = findCycle(suiteRefs);
|
|
1141
|
+
if (suiteCycle != null) errors.push(`suite include cycle: ${suiteCycle.join(" → ")}`);
|
|
1142
|
+
const suites = {};
|
|
1143
|
+
if (suiteCycle == null) for (const [name, suite] of Object.entries(suitesInput)) {
|
|
1144
|
+
if (!isRecord(suite)) continue;
|
|
1145
|
+
const definition = suite;
|
|
1146
|
+
const expanded = expandSelection(name, suitesInput, byId);
|
|
1147
|
+
const ordered = [...byId.keys()].filter((id) => expanded.has(id));
|
|
1148
|
+
if (ordered.length < 2) {
|
|
1149
|
+
errors.push(ordered.length === 0 ? `suites.${name}: expands to zero processes` : `suites.${name}: one member — run "${ordered[0]}" directly; use a tag if you wanted a label`);
|
|
1150
|
+
continue;
|
|
998
1151
|
}
|
|
1152
|
+
const tagSelection = Object.keys(definition).every((key) => key === "where") ? equivalentTagSelection(expanded, byId) : null;
|
|
1153
|
+
if (tagSelection != null && tagSelection.length === 1) warnings.push(`suites.${name}: this is exactly the tag selection \`${tagSelection[0]}\` — a pinned tag group may be all you need`);
|
|
1154
|
+
suites[name] = {
|
|
1155
|
+
name,
|
|
1156
|
+
...typeof definition.description === "string" ? { description: definition.description } : {},
|
|
1157
|
+
ids: ordered,
|
|
1158
|
+
parallel: definition.parallel ?? SUITE_PARALLEL_DEFAULT,
|
|
1159
|
+
failFast: definition.failFast === true,
|
|
1160
|
+
staggerMs: definition.staggerMs ?? SUITE_STAGGER_DEFAULT_MS
|
|
1161
|
+
};
|
|
999
1162
|
}
|
|
1000
1163
|
const portClaims = /* @__PURE__ */ new Map();
|
|
1001
1164
|
for (const proc of byId.values()) for (const ep of proc.endpoints) {
|
|
@@ -1016,7 +1179,7 @@ function validateCommanderConfig(raw, anchor) {
|
|
|
1016
1179
|
}
|
|
1017
1180
|
if (config.defaultSelection != null) {
|
|
1018
1181
|
const selection = config.defaultSelection;
|
|
1019
|
-
if (!byId.has(selection) && !(selection in
|
|
1182
|
+
if (typeof selection !== "string" || !byId.has(selection) && !(selection in suitesInput) && parseTagTerm(selection) == null) errors.push(`defaultSelection: expected a process id, a suite, or one tag=value term`);
|
|
1020
1183
|
}
|
|
1021
1184
|
const watchFiles = [anchor.configPath];
|
|
1022
1185
|
for (const file of config.watchFiles ?? []) {
|
|
@@ -1036,7 +1199,7 @@ function validateCommanderConfig(raw, anchor) {
|
|
|
1036
1199
|
const resolvedBase = {
|
|
1037
1200
|
name,
|
|
1038
1201
|
processes,
|
|
1039
|
-
|
|
1202
|
+
suites,
|
|
1040
1203
|
defaultSelection: config.defaultSelection,
|
|
1041
1204
|
daemon: { port: typeof config.daemon?.port === "number" ? config.daemon.port : 4900 }
|
|
1042
1205
|
};
|
|
@@ -1096,7 +1259,7 @@ async function loadConfigOrExit(configPath) {
|
|
|
1096
1259
|
*/
|
|
1097
1260
|
function requireSelectionTerms(ctx) {
|
|
1098
1261
|
if (ctx.args.positionals.length > 0 || ctx.args.flags.get("--all") === true) return;
|
|
1099
|
-
throw new CliExit(EXIT.usage, `${ctx.args.command} requires a selection (ids,
|
|
1262
|
+
throw new CliExit(EXIT.usage, `${ctx.args.command} requires a selection (ids, suite, @pin, tag=val) or --all`);
|
|
1100
1263
|
}
|
|
1101
1264
|
function selectOrExit(ctx, options) {
|
|
1102
1265
|
const { args, config } = ctx;
|
|
@@ -1104,19 +1267,24 @@ function selectOrExit(ctx, options) {
|
|
|
1104
1267
|
if (args.flags.get("--all") === true) terms = [...terms, "all"];
|
|
1105
1268
|
if (terms.length === 0) if (options.bare === "default" && config.defaultSelection != null) terms = [config.defaultSelection];
|
|
1106
1269
|
else if (options.bare === "default") {
|
|
1107
|
-
const
|
|
1108
|
-
throw new CliExit(EXIT.usage, `bare ${args.command}: the config has no defaultSelection.
|
|
1270
|
+
const suites = Object.keys(config.suites);
|
|
1271
|
+
throw new CliExit(EXIT.usage, `bare ${args.command}: the config has no defaultSelection. Suites: ${suites.length > 0 ? suites.join(", ") : "(none)"} — or name ids, tag=val, --all`);
|
|
1109
1272
|
} else requireSelectionTerms(ctx);
|
|
1110
|
-
const result = resolveSelection(config, terms,
|
|
1273
|
+
const result = resolveSelection(config, terms, {
|
|
1274
|
+
extraIds: options.extraIds ?? [],
|
|
1275
|
+
any: args.flags.get("--any") === true,
|
|
1276
|
+
purpose: args.command === "down" || args.command === "logs" ? "address" : "start",
|
|
1277
|
+
pins: ctx.pins ?? []
|
|
1278
|
+
});
|
|
1111
1279
|
if (!result.ok) throw new CliExit(EXIT.usage, result.errors.join("\n"));
|
|
1112
1280
|
return result.selection;
|
|
1113
1281
|
}
|
|
1114
|
-
/**
|
|
1282
|
+
/** Suite stagger for a start: the widest stagger among the suites named in the terms. */
|
|
1115
1283
|
function staggerFor(config, terms) {
|
|
1116
1284
|
let stagger = 0;
|
|
1117
1285
|
for (const term of terms) {
|
|
1118
|
-
const
|
|
1119
|
-
if (
|
|
1286
|
+
const suite = config.suites[term];
|
|
1287
|
+
if (suite != null) stagger = Math.max(stagger, suite.staggerMs);
|
|
1120
1288
|
}
|
|
1121
1289
|
return stagger;
|
|
1122
1290
|
}
|
|
@@ -5162,7 +5330,7 @@ function reject(reason, id) {
|
|
|
5162
5330
|
/**
|
|
5163
5331
|
* The machine-readable reject id an untrusted verify key produces: the presented key differs from
|
|
5164
5332
|
* the one pinned for this client identity (trust-on-first-use). Carried on the reject frame's `id`
|
|
5165
|
-
* and surfaced to the dialing side as `
|
|
5333
|
+
* and surfaced to the dialing side as `err_wire_connect` id `identity_pin_mismatch`, so an app can
|
|
5166
5334
|
* branch on it (`err.hasId("identity_pin_mismatch")`) — the obvious recovery being "this identity
|
|
5167
5335
|
* is unusable with this key: clear the client's identity storage / mint a new persistent id".
|
|
5168
5336
|
*/
|
|
@@ -5832,6 +6000,9 @@ dropLink: async (opts) => {
|
|
|
5832
6000
|
* Close any live long-lived connection (e.g. a WebSocket) before dropping it, so a teardown
|
|
5833
6001
|
* actually releases the socket instead of leaving it open until GC. HTTP/stateless transports
|
|
5834
6002
|
* don't implement `disconnect`, so they're simply forgotten.
|
|
6003
|
+
*
|
|
6004
|
+
* @internal Bare cache drop with no redial suppression. Apps call {@link clearTransportCache} or
|
|
6005
|
+
* {@link releaseLink} instead.
|
|
5835
6006
|
*/
|
|
5836
6007
|
clearCache() {
|
|
5837
6008
|
for (const entry of this._cache.values()) if (entry instanceof Promise) entry.then((ready) => ready.methods.disconnect?.()).catch(() => {});
|
|
@@ -10201,6 +10372,34 @@ var ReliableLog = class {
|
|
|
10201
10372
|
}
|
|
10202
10373
|
return prefix;
|
|
10203
10374
|
}
|
|
10375
|
+
/**
|
|
10376
|
+
* {@link contiguousPrefix} with each payload's `seq` attached, optionally only the entries after
|
|
10377
|
+
* `afterSeq`. Pruned or compacted seqs are absent, so the first entry's `seq` says where the stored
|
|
10378
|
+
* history now starts.
|
|
10379
|
+
*/
|
|
10380
|
+
contiguousEntries(streamId, afterSeq = -1) {
|
|
10381
|
+
const highWater = this._store.getHighWater(streamId);
|
|
10382
|
+
const entries = [];
|
|
10383
|
+
for (let seq = Math.max(afterSeq + 1, 0); seq <= highWater; seq++) {
|
|
10384
|
+
const raw = this._store.getPayload(streamId, seq);
|
|
10385
|
+
if (raw != null) entries.push({
|
|
10386
|
+
seq,
|
|
10387
|
+
payload: this._deserialize(raw)
|
|
10388
|
+
});
|
|
10389
|
+
}
|
|
10390
|
+
return entries;
|
|
10391
|
+
}
|
|
10392
|
+
/**
|
|
10393
|
+
* Delete a stream's stored frames with `seq <= through` (the replay recipe's prune, once the consumer
|
|
10394
|
+
* confirmed them). Clamped to the high-water, so a too-large `through` never touches undelivered frames.
|
|
10395
|
+
* Returns `false` when the store has no `deleteThrough` and nothing was pruned.
|
|
10396
|
+
*/
|
|
10397
|
+
pruneThrough(streamId, through) {
|
|
10398
|
+
if (this._store.deleteThrough == null) return false;
|
|
10399
|
+
const clamped = Math.min(through, this._store.getHighWater(streamId));
|
|
10400
|
+
if (clamped >= 0) this._store.deleteThrough(streamId, clamped);
|
|
10401
|
+
return true;
|
|
10402
|
+
}
|
|
10204
10403
|
};
|
|
10205
10404
|
/**
|
|
10206
10405
|
* An in-memory {@link IReliableLogStore} — used by tests to stand in for a Durable Object's SQL storage. It
|
|
@@ -10211,7 +10410,7 @@ var ReliableLog = class {
|
|
|
10211
10410
|
function createMemoryReliableLogStore() {
|
|
10212
10411
|
const frames = /* @__PURE__ */ new Map();
|
|
10213
10412
|
const highWater = /* @__PURE__ */ new Map();
|
|
10214
|
-
const key = (streamId, seq) => `${streamId}
|
|
10413
|
+
const key = (streamId, seq) => `${streamId}\u0000${seq}`;
|
|
10215
10414
|
return {
|
|
10216
10415
|
insertIgnore: (streamId, seq, payload) => {
|
|
10217
10416
|
const k = key(streamId, seq);
|
|
@@ -10225,7 +10424,7 @@ function createMemoryReliableLogStore() {
|
|
|
10225
10424
|
for (let seq = 0; seq <= through; seq++) frames.delete(key(streamId, seq));
|
|
10226
10425
|
},
|
|
10227
10426
|
deleteStream: (streamId) => {
|
|
10228
|
-
const prefix = `${streamId}
|
|
10427
|
+
const prefix = `${streamId}\u0000`;
|
|
10229
10428
|
for (const k of frames.keys()) if (k.startsWith(prefix)) frames.delete(k);
|
|
10230
10429
|
highWater.delete(streamId);
|
|
10231
10430
|
}
|
|
@@ -15112,7 +15311,7 @@ var ChannelAcceptor = class ChannelAcceptor extends PeerLink {
|
|
|
15112
15311
|
this._sendPayload(connection, action, runtime.coordinate);
|
|
15113
15312
|
runningAction._completeWithResult(action.successResult(void 0));
|
|
15114
15313
|
} catch (err) {
|
|
15115
|
-
runningAction._abort(err);
|
|
15314
|
+
runningAction._abort(this._pushSendError(action.id, err));
|
|
15116
15315
|
}
|
|
15117
15316
|
return runningAction;
|
|
15118
15317
|
}
|
|
@@ -15125,10 +15324,19 @@ var ChannelAcceptor = class ChannelAcceptor extends PeerLink {
|
|
|
15125
15324
|
try {
|
|
15126
15325
|
this._sendPayload(connection, action, runtime.coordinate);
|
|
15127
15326
|
} catch (err) {
|
|
15128
|
-
runningAction._abort(err);
|
|
15327
|
+
runningAction._abort(this._pushSendError(action.id, err));
|
|
15129
15328
|
}
|
|
15130
15329
|
return runningAction;
|
|
15131
15330
|
}
|
|
15331
|
+
/** A failed push send as a typed `send_failed`, keeping the carrier's error as the origin. */
|
|
15332
|
+
_pushSendError(actionId, cause) {
|
|
15333
|
+
if (err_nice_transport.isExact(cause)) return cause;
|
|
15334
|
+
return err_nice_transport.fromId("send_failed", {
|
|
15335
|
+
actionId,
|
|
15336
|
+
actionState: "request",
|
|
15337
|
+
message: cause instanceof Error ? cause.message : String(cause)
|
|
15338
|
+
}).withOriginError(cause);
|
|
15339
|
+
}
|
|
15132
15340
|
/** Encode + send one payload; returns the encoded frame's size so a logger can report it. */
|
|
15133
15341
|
_sendPayload(connection, payload, localClient, reliability) {
|
|
15134
15342
|
const encoding = this._connEncoding.get(connection) ?? "binary";
|
|
@@ -16005,8 +16213,10 @@ function deriveDictionaryVersion(domains) {
|
|
|
16005
16213
|
* Declare a transport-agnostic channel by role — the single source of truth both peers share. Each end
|
|
16006
16214
|
* MUST call this with the same domains in the same order (the binary wire dictionary is positional); the
|
|
16007
16215
|
* `dictionaryVersion` is derived from those domains unless you pin an explicit one. The wire dictionary
|
|
16008
|
-
* spans `[...toAcceptor, ...toConnector]` in that order
|
|
16009
|
-
*
|
|
16216
|
+
* spans `[...toAcceptor, ...toConnector]` in that order. Any change to the domains or their actions moves
|
|
16217
|
+
* the derived version, and the handshake rejects a peer whose version differs, so deploy both ends
|
|
16218
|
+
* together. Appending stays compatible with older peers only under a hand-pinned `dictionaryVersion`
|
|
16219
|
+
* you leave unchanged, and only when the additions come last in the whole dictionary.
|
|
16010
16220
|
*
|
|
16011
16221
|
* Declare the domains *by role* — `toAcceptor` (connector→acceptor requests) and `toConnector`
|
|
16012
16222
|
* (acceptor→connector pushes) — so the routing for both ends is derived from the channel (see
|
|
@@ -16709,7 +16919,7 @@ function serveChannel(runtime, channel, options) {
|
|
|
16709
16919
|
const pushToClient = (target, request, pushOptions) => {
|
|
16710
16920
|
if (disposed) throw new Error("serveChannel: server disposed");
|
|
16711
16921
|
const owner = target instanceof RuntimeCoordinate ? acceptors.find((acceptor) => acceptor.ownsLiveConnectionFor(target)) : acceptors.find((acceptor) => acceptor.hasConnection(target));
|
|
16712
|
-
if (owner == null) throw
|
|
16922
|
+
if (owner == null) throw err_nice_transport.fromId("not_found", { actionId: target instanceof RuntimeCoordinate ? target.stringId : "push-target-connection" });
|
|
16713
16923
|
return owner.pushToClient(runtime, target, request, pushOptions);
|
|
16714
16924
|
};
|
|
16715
16925
|
const broadcast = (makeRequest, broadcastOptions) => {
|
|
@@ -18671,11 +18881,11 @@ const err_realm = err_nice.createChildDomain({
|
|
|
18671
18881
|
message: ({ lastKnownVersion, oldestReplayable }) => `Version ${lastKnownVersion} is behind the replayable window (oldest ${oldestReplayable}) — full rehydration required.`,
|
|
18672
18882
|
context: { required: true }
|
|
18673
18883
|
}),
|
|
18674
|
-
/** A
|
|
18675
|
-
*
|
|
18676
|
-
*
|
|
18884
|
+
/** A write or intent made before the first hydrate is queued for it; this is the queued
|
|
18885
|
+
* handle's rejection when that hydrate never came (the realm detached, or `pendingExpiryMs`
|
|
18886
|
+
* passed first). Definite: nothing was sent. A refused attach rejects with the attach error. */
|
|
18677
18887
|
write_before_hydrate: err({
|
|
18678
|
-
message: ({ realmId }) => `
|
|
18888
|
+
message: ({ realmId }) => `A write on "${realmId}" was queued for the first hydrate, which never arrived (the realm detached, or the pending expiry passed first) — nothing was sent.`,
|
|
18679
18889
|
context: { required: true }
|
|
18680
18890
|
}),
|
|
18681
18891
|
/**
|
|
@@ -19836,7 +20046,7 @@ const DEFAULT_PROBE_REPLY_TIMEOUT_MS = 1e4;
|
|
|
19836
20046
|
function connectRealm(realm, options) {
|
|
19837
20047
|
const coordinate = options.connection.coordinate;
|
|
19838
20048
|
const persistentId = options.avatar.persistentId ?? coordinate?.perId;
|
|
19839
|
-
if (persistentId == null) throw new Error("connectRealm: no avatar identity —
|
|
20049
|
+
if (persistentId == null) throw new Error("connectRealm: no avatar identity — the connection carries no persistent id. Give it one where you open the connection (identity: coord.specify({ perId })), or pass avatar.persistentId explicitly.");
|
|
19840
20050
|
const avatar = {
|
|
19841
20051
|
type: options.avatar.type,
|
|
19842
20052
|
persistentId,
|
|
@@ -19877,8 +20087,10 @@ function connectRealm(realm, options) {
|
|
|
19877
20087
|
if (next === "live") hasBeenLive = true;
|
|
19878
20088
|
for (const listener of [...statusListeners]) listener(next, { hasBeenLive });
|
|
19879
20089
|
devtools?.onStatus?.(next, { hasBeenLive });
|
|
20090
|
+
if (next === "detached") rejectHydrateQueue();
|
|
19880
20091
|
};
|
|
19881
20092
|
let pending = [];
|
|
20093
|
+
const hydrateQueue = [];
|
|
19882
20094
|
let nextSeq = 0;
|
|
19883
20095
|
let flushScheduled = false;
|
|
19884
20096
|
let projecting = false;
|
|
@@ -20340,8 +20552,7 @@ function connectRealm(realm, options) {
|
|
|
20340
20552
|
if (coalesceWindowMs > 0) unrefTimer(setTimeout(flushOutbox, coalesceWindowMs));
|
|
20341
20553
|
else queueMicrotask(flushOutbox);
|
|
20342
20554
|
};
|
|
20343
|
-
const
|
|
20344
|
-
const controller = createWriteHandle();
|
|
20555
|
+
const rejectUnsent = (controller, kind, error, intentName) => {
|
|
20345
20556
|
controller.reject(error);
|
|
20346
20557
|
emitRejection({
|
|
20347
20558
|
error,
|
|
@@ -20359,6 +20570,56 @@ function connectRealm(realm, options) {
|
|
|
20359
20570
|
});
|
|
20360
20571
|
return controller.handle;
|
|
20361
20572
|
};
|
|
20573
|
+
const rejectImmediately = (kind, error, intentName) => rejectUnsent(createWriteHandle(), kind, error, intentName);
|
|
20574
|
+
const neverHydratedError = () => attachError ?? err_realm.fromId("write_before_hydrate", { realmId: realm.id });
|
|
20575
|
+
const rejectQueued = (queued, error) => {
|
|
20576
|
+
if (queued.expiryTimer != null) clearTimeout(queued.expiryTimer);
|
|
20577
|
+
rejectUnsent(queued.controller, queued.kind, error, queued.intentName);
|
|
20578
|
+
};
|
|
20579
|
+
const mustQueueUntilHydrate = () => confirmedVersion === -1 || hydrateQueue.length > 0;
|
|
20580
|
+
const queueUntilHydrate = (queuedWrite, durability) => {
|
|
20581
|
+
const controller = createWriteHandle();
|
|
20582
|
+
if (status === "detached") return rejectUnsent(controller, queuedWrite.kind, neverHydratedError(), queuedWrite.intentName);
|
|
20583
|
+
const queued = {
|
|
20584
|
+
...queuedWrite,
|
|
20585
|
+
controller,
|
|
20586
|
+
expiryTimer: void 0
|
|
20587
|
+
};
|
|
20588
|
+
if (durability !== "reassert") {
|
|
20589
|
+
queued.expiryTimer = setTimeout(() => {
|
|
20590
|
+
const index = hydrateQueue.indexOf(queued);
|
|
20591
|
+
if (index < 0) return;
|
|
20592
|
+
hydrateQueue.splice(index, 1);
|
|
20593
|
+
rejectQueued(queued, neverHydratedError());
|
|
20594
|
+
notifyPending();
|
|
20595
|
+
}, expiryMs);
|
|
20596
|
+
unrefTimer(queued.expiryTimer);
|
|
20597
|
+
}
|
|
20598
|
+
hydrateQueue.push(queued);
|
|
20599
|
+
notifyPending();
|
|
20600
|
+
return controller.handle;
|
|
20601
|
+
};
|
|
20602
|
+
const drainHydrateQueue = () => {
|
|
20603
|
+
for (let queued = hydrateQueue.shift(); queued != null; queued = hydrateQueue.shift()) {
|
|
20604
|
+
if (queued.expiryTimer != null) clearTimeout(queued.expiryTimer);
|
|
20605
|
+
const { controller } = queued;
|
|
20606
|
+
let sent;
|
|
20607
|
+
try {
|
|
20608
|
+
sent = queued.run();
|
|
20609
|
+
} catch (cause) {
|
|
20610
|
+
console.error(`${warnTag()} a write queued before the first hydrate threw`, cause);
|
|
20611
|
+
rejectQueued(queued, castNiceError(cause));
|
|
20612
|
+
continue;
|
|
20613
|
+
}
|
|
20614
|
+
const settled = sent;
|
|
20615
|
+
settled.then(controller.confirm, () => {
|
|
20616
|
+
if (settled.error != null) controller.reject(settled.error);
|
|
20617
|
+
});
|
|
20618
|
+
}
|
|
20619
|
+
};
|
|
20620
|
+
const rejectHydrateQueue = () => {
|
|
20621
|
+
for (const queued of hydrateQueue.splice(0)) rejectQueued(queued, neverHydratedError());
|
|
20622
|
+
};
|
|
20362
20623
|
const enqueueWrite = (patches, writeOptions) => {
|
|
20363
20624
|
const durability = writeOptions?.durability;
|
|
20364
20625
|
const immediate = writeOptions?.flush === "immediate";
|
|
@@ -20411,19 +20672,8 @@ function connectRealm(realm, options) {
|
|
|
20411
20672
|
} else scheduleFlush();
|
|
20412
20673
|
return controller.handle;
|
|
20413
20674
|
};
|
|
20414
|
-
const
|
|
20675
|
+
const applyUpdate = (fn, updateOptions) => {
|
|
20415
20676
|
const projected = store.state;
|
|
20416
|
-
if (confirmedVersion === -1) {
|
|
20417
|
-
const error = err_realm.fromId("write_before_hydrate", { realmId: realm.id });
|
|
20418
|
-
try {
|
|
20419
|
-
produceWithPatches(projected, (draft) => {
|
|
20420
|
-
fn(draft);
|
|
20421
|
-
});
|
|
20422
|
-
} catch (cause) {
|
|
20423
|
-
throw new Error(error.message, { cause });
|
|
20424
|
-
}
|
|
20425
|
-
return rejectImmediately("write", error);
|
|
20426
|
-
}
|
|
20427
20677
|
let returned;
|
|
20428
20678
|
const [next, patches] = produceWithPatches(projected, (draft) => {
|
|
20429
20679
|
returned = fn(draft);
|
|
@@ -20445,7 +20695,16 @@ function connectRealm(realm, options) {
|
|
|
20445
20695
|
if (verdict !== true) return rejectImmediately("write", verdict);
|
|
20446
20696
|
return enqueueWrite(canonical, updateOptions);
|
|
20447
20697
|
};
|
|
20448
|
-
const
|
|
20698
|
+
const update = (fn, updateOptions) => mustQueueUntilHydrate() ? queueUntilHydrate({
|
|
20699
|
+
kind: "write",
|
|
20700
|
+
run: () => applyUpdate(fn, updateOptions)
|
|
20701
|
+
}, updateOptions?.durability) : applyUpdate(fn, updateOptions);
|
|
20702
|
+
const runIntent = (name, input) => mustQueueUntilHydrate() ? queueUntilHydrate({
|
|
20703
|
+
kind: "intent",
|
|
20704
|
+
intentName: name,
|
|
20705
|
+
run: () => sendIntent(name, input)
|
|
20706
|
+
}) : sendIntent(name, input);
|
|
20707
|
+
const sendIntent = (name, input) => {
|
|
20449
20708
|
const def = realm.intents[name];
|
|
20450
20709
|
if (def == null) return rejectImmediately("intent", err_realm.fromId("intent_unknown", { intent: name }), name);
|
|
20451
20710
|
const invalid = validateValue(def.input, input);
|
|
@@ -20626,7 +20885,8 @@ function connectRealm(realm, options) {
|
|
|
20626
20885
|
if (!isFirstHydrate && realm.transient.length > 0 && options.assertOnAttach != null && !hasPendingSystemAssert()) enqueueSystemAssert(confirmed);
|
|
20627
20886
|
revalidateAndResendPending();
|
|
20628
20887
|
project({ fullReplace: true });
|
|
20629
|
-
if (options.assertOnAttach != null && !hasPendingSystemAssert())
|
|
20888
|
+
if (options.assertOnAttach != null && !hasPendingSystemAssert()) applyUpdate(options.assertOnAttach);
|
|
20889
|
+
drainHydrateQueue();
|
|
20630
20890
|
checkReownWatch();
|
|
20631
20891
|
return;
|
|
20632
20892
|
}
|
|
@@ -20933,11 +21193,12 @@ function connectRealm(realm, options) {
|
|
|
20933
21193
|
}
|
|
20934
21194
|
const handle = {
|
|
20935
21195
|
store,
|
|
21196
|
+
avatar,
|
|
20936
21197
|
update,
|
|
20937
21198
|
intents: Object.fromEntries(realm.intentNames.map((name) => [name, (input) => runIntent(name, input)])),
|
|
20938
21199
|
pending: {
|
|
20939
21200
|
get count() {
|
|
20940
|
-
return pending.reduce((n, frame) => frame.isSystemAssert ? n : n + 1, 0);
|
|
21201
|
+
return pending.reduce((n, frame) => frame.isSystemAssert ? n : n + 1, 0) + hydrateQueue.length;
|
|
20941
21202
|
},
|
|
20942
21203
|
has(pathPrefix) {
|
|
20943
21204
|
return pending.some((frame) => !frame.isSystemAssert && frame.patches.some((patch) => patch.path.join(".").startsWith(pathPrefix)));
|
|
@@ -23313,7 +23574,8 @@ function commanderStatePaths(dataDir, configKey) {
|
|
|
23313
23574
|
upLockPath: (0, node_path.join)(stateDir, "up.lock"),
|
|
23314
23575
|
bootLogPath: (0, node_path.join)(stateDir, "daemon-boot.log"),
|
|
23315
23576
|
ingestSeqPath: (0, node_path.join)(stateDir, "ingest-seq"),
|
|
23316
|
-
envOverridesPath: (0, node_path.join)(stateDir, "env-overrides.json")
|
|
23577
|
+
envOverridesPath: (0, node_path.join)(stateDir, "env-overrides.json"),
|
|
23578
|
+
savedFiltersPath: (0, node_path.join)(stateDir, "saved-filters.json")
|
|
23317
23579
|
};
|
|
23318
23580
|
}
|
|
23319
23581
|
async function ensureStateDir(paths) {
|
|
@@ -23407,7 +23669,8 @@ const commanderStatusRealm = defineRealm({
|
|
|
23407
23669
|
degraded: t.boolean(),
|
|
23408
23670
|
notes: t.array(t.string())
|
|
23409
23671
|
})),
|
|
23410
|
-
tags: t.record(t.id("tag"), t.string()),
|
|
23672
|
+
tags: t.record(t.id("tag"), t.array(t.string())),
|
|
23673
|
+
optIn: t.boolean(),
|
|
23411
23674
|
detail: t.object({
|
|
23412
23675
|
command: t.string(),
|
|
23413
23676
|
cwd: t.string(),
|
|
@@ -23433,7 +23696,30 @@ const commanderStatusRealm = defineRealm({
|
|
|
23433
23696
|
}))
|
|
23434
23697
|
})
|
|
23435
23698
|
})),
|
|
23436
|
-
|
|
23699
|
+
suites: t.record(t.id("suiteName"), t.object({
|
|
23700
|
+
description: t.optional(t.string()),
|
|
23701
|
+
members: t.array(t.string()),
|
|
23702
|
+
parallel: t.number(),
|
|
23703
|
+
failFast: t.boolean()
|
|
23704
|
+
})),
|
|
23705
|
+
runs: t.record(t.id("runKey"), t.object({
|
|
23706
|
+
suite: t.optional(t.string()),
|
|
23707
|
+
filterId: t.optional(t.string()),
|
|
23708
|
+
startedAt: t.number(),
|
|
23709
|
+
endedAt: t.optional(t.number()),
|
|
23710
|
+
outcome: t.optional(t.union(t.literal("passed"), t.literal("failed"))),
|
|
23711
|
+
previousDurationMs: t.optional(t.number()),
|
|
23712
|
+
members: t.record(t.id("processId"), t.union(t.literal("pending"), t.literal("running"), t.literal("pass"), t.literal("fail"), t.literal("blocked"), t.literal("skipped")))
|
|
23713
|
+
})),
|
|
23714
|
+
savedFilters: t.array(t.object({
|
|
23715
|
+
id: t.string(),
|
|
23716
|
+
name: t.optional(t.string()),
|
|
23717
|
+
mode: t.union(t.literal("all"), t.literal("any")),
|
|
23718
|
+
terms: t.array(t.string()),
|
|
23719
|
+
bucket: t.optional(t.array(t.string())),
|
|
23720
|
+
pinned: t.boolean(),
|
|
23721
|
+
lastRunAt: t.optional(t.number())
|
|
23722
|
+
}))
|
|
23437
23723
|
},
|
|
23438
23724
|
rules: (r) => [r.path("**").view(r.everyone).alter(r.serverOnly)]
|
|
23439
23725
|
});
|
|
@@ -23566,7 +23852,7 @@ var CommanderDaemonBootError = class extends Error {
|
|
|
23566
23852
|
* a live dev environment, and an upgrade must never be the thing that kills one.
|
|
23567
23853
|
*/
|
|
23568
23854
|
async function replaceSkewedDaemon(paths, skewed) {
|
|
23569
|
-
const daemonLabel = `the daemon for this config (pid ${skewed.pid}, build ${skewed.packageVersion}, protocol v${skewed.protocolVersion}) predates this CLI (protocol
|
|
23855
|
+
const daemonLabel = `the daemon for this config (pid ${skewed.pid}, build ${skewed.packageVersion}, protocol v${skewed.protocolVersion}) predates this CLI (protocol v6${skewed.skew === "realm-schema" ? ", different status schema" : ""})`;
|
|
23570
23856
|
let liveIds = [];
|
|
23571
23857
|
try {
|
|
23572
23858
|
liveIds = (await (0, _nice_code_process.openProcessLedger)({
|
|
@@ -23817,6 +24103,67 @@ function checkIds(value) {
|
|
|
23817
24103
|
const ids = asIdList(record["ids"]);
|
|
23818
24104
|
return ids == null ? "ids: expected an array of process ids" : { ids };
|
|
23819
24105
|
}
|
|
24106
|
+
function checkRunSuite(value) {
|
|
24107
|
+
const record = asRecord(value);
|
|
24108
|
+
if (record == null) return "expected an object";
|
|
24109
|
+
const input = {};
|
|
24110
|
+
const suite = record["suite"];
|
|
24111
|
+
if (suite != null) {
|
|
24112
|
+
if (typeof suite !== "string" || suite === "") return "suite: expected a suite name";
|
|
24113
|
+
input.suite = suite;
|
|
24114
|
+
}
|
|
24115
|
+
if (record["ids"] != null) {
|
|
24116
|
+
const ids = asIdList(record["ids"]);
|
|
24117
|
+
if (ids == null) return "ids: expected an array of process ids";
|
|
24118
|
+
input.ids = ids;
|
|
24119
|
+
}
|
|
24120
|
+
if (input.suite == null === (input.ids == null)) return "expected exactly one of suite | ids";
|
|
24121
|
+
const parallel = record["parallel"];
|
|
24122
|
+
if (parallel != null) {
|
|
24123
|
+
if (typeof parallel !== "number" || !Number.isInteger(parallel) || parallel < 1) return "parallel: expected an integer ≥ 1";
|
|
24124
|
+
input.parallel = parallel;
|
|
24125
|
+
}
|
|
24126
|
+
const failFast = record["failFast"];
|
|
24127
|
+
if (failFast != null) {
|
|
24128
|
+
if (typeof failFast !== "boolean") return "failFast: expected a boolean";
|
|
24129
|
+
input.failFast = failFast;
|
|
24130
|
+
}
|
|
24131
|
+
if (record["filter"] != null) {
|
|
24132
|
+
const filter = checkSavedFilterQuery(record["filter"]);
|
|
24133
|
+
if (typeof filter === "string") return `filter.${filter}`;
|
|
24134
|
+
input.filter = filter;
|
|
24135
|
+
}
|
|
24136
|
+
return input;
|
|
24137
|
+
}
|
|
24138
|
+
function checkRunSuiteReport(value) {
|
|
24139
|
+
const record = asRecord(value);
|
|
24140
|
+
if (record == null || typeof record["accepted"] !== "boolean") return "expected { accepted }";
|
|
24141
|
+
const { runKey, reason } = record;
|
|
24142
|
+
return {
|
|
24143
|
+
accepted: record["accepted"],
|
|
24144
|
+
...typeof runKey === "string" ? { runKey } : {},
|
|
24145
|
+
...typeof reason === "string" ? { reason } : {}
|
|
24146
|
+
};
|
|
24147
|
+
}
|
|
24148
|
+
function checkSaveFilter(value) {
|
|
24149
|
+
const record = asRecord(value);
|
|
24150
|
+
if (record == null) return "expected an object";
|
|
24151
|
+
const filter = checkSavedFilterQuery(record["filter"]);
|
|
24152
|
+
if (typeof filter === "string") return `filter.${filter}`;
|
|
24153
|
+
const name = record["name"];
|
|
24154
|
+
if (typeof name !== "string") return "name: expected a string";
|
|
24155
|
+
return {
|
|
24156
|
+
filter,
|
|
24157
|
+
name
|
|
24158
|
+
};
|
|
24159
|
+
}
|
|
24160
|
+
function checkRemoveFilter(value) {
|
|
24161
|
+
const id = asRecord(value)?.["id"];
|
|
24162
|
+
return typeof id === "string" && id !== "" ? { id } : "id: expected a saved filter id";
|
|
24163
|
+
}
|
|
24164
|
+
function checkOk(value) {
|
|
24165
|
+
return asRecord(value)?.["ok"] === true ? { ok: true } : "expected { ok: true }";
|
|
24166
|
+
}
|
|
23820
24167
|
function checkEmpty(value) {
|
|
23821
24168
|
return asRecord(value) == null ? "expected an object" : {};
|
|
23822
24169
|
}
|
|
@@ -23897,9 +24244,12 @@ const commanderControlDomain = createActionRootDomain({ domain: "commander" }).c
|
|
|
23897
24244
|
start: actionSchema().input({ schema: handSchema(checkStart) }).output({ schema: handSchema(checkReport) }),
|
|
23898
24245
|
stop: actionSchema().input({ schema: handSchema(checkIds) }).output({ schema: handSchema(checkReport) }),
|
|
23899
24246
|
restart: actionSchema().input({ schema: handSchema(checkStart) }).output({ schema: handSchema(checkReport) }),
|
|
24247
|
+
runSuite: actionSchema().input({ schema: handSchema(checkRunSuite) }).output({ schema: handSchema(checkRunSuiteReport) }),
|
|
24248
|
+
saveFilter: actionSchema().input({ schema: handSchema(checkSaveFilter) }).output({ schema: handSchema(checkOk) }),
|
|
24249
|
+
removeFilter: actionSchema().input({ schema: handSchema(checkRemoveFilter) }).output({ schema: handSchema(checkOk) }),
|
|
23900
24250
|
setEnv: actionSchema().input({ schema: handSchema(checkSetEnv) }).output({ schema: handSchema(checkEnvReport) }),
|
|
23901
24251
|
reloadConfig: actionSchema().input({ schema: handSchema(checkEmpty) }).output({ schema: handSchema(checkReloadResult) }),
|
|
23902
|
-
shutdown: actionSchema().input({ schema: handSchema(checkEmpty) }).output({ schema: handSchema(
|
|
24252
|
+
shutdown: actionSchema().input({ schema: handSchema(checkEmpty) }).output({ schema: handSchema(checkOk) })
|
|
23903
24253
|
}
|
|
23904
24254
|
});
|
|
23905
24255
|
/** One socket carries control actions (toAcceptor) + the status realm (a mux protocol, D1). */
|
|
@@ -23943,7 +24293,7 @@ async function findDaemon(config) {
|
|
|
23943
24293
|
async function findSkewedDaemon(config) {
|
|
23944
24294
|
const skewed = await readSkewedInstanceRecord(commanderStatePaths(resolveCommanderDataDir(), config.configKey).instanceRecordPath, commanderStatusRealm.schemaHash);
|
|
23945
24295
|
if (skewed == null || !pidAlive$1(skewed.pid)) return null;
|
|
23946
|
-
const difference = skewed.skew === "protocol" ? `speaks protocol v${skewed.protocolVersion}; this build speaks
|
|
24296
|
+
const difference = skewed.skew === "protocol" ? `speaks protocol v${skewed.protocolVersion}; this build speaks v6` : "was started before an upgrade changed the status schema";
|
|
23947
24297
|
return {
|
|
23948
24298
|
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.`,
|
|
23949
24299
|
pid: skewed.pid,
|
|
@@ -24041,7 +24391,7 @@ async function connectDaemon(handle) {
|
|
|
24041
24391
|
const payload = await (await runtime.handleActionPayload(request)).waitForResultPayload();
|
|
24042
24392
|
if (!payload.result.ok) throw new CliExit(EXIT.failure, `action "${action}" rejected by the daemon`);
|
|
24043
24393
|
const report = parseActionReport(payload.result.output);
|
|
24044
|
-
if (report == null) throw new CliExit(EXIT.failure, `the daemon answered "${action}" with something this CLI does not recognise — protocol ${record.protocolVersion} vs
|
|
24394
|
+
if (report == null) throw new CliExit(EXIT.failure, `the daemon answered "${action}" with something this CLI does not recognise — protocol ${record.protocolVersion} vs 6`);
|
|
24045
24395
|
return report;
|
|
24046
24396
|
},
|
|
24047
24397
|
setEnv: async (input) => {
|
|
@@ -24128,7 +24478,8 @@ async function cmdUp(ctx) {
|
|
|
24128
24478
|
const bad = unknownFlags(ctx.args.flags, [
|
|
24129
24479
|
"--no-wait",
|
|
24130
24480
|
"--dry-run",
|
|
24131
|
-
"--all"
|
|
24481
|
+
"--all",
|
|
24482
|
+
"--any"
|
|
24132
24483
|
]);
|
|
24133
24484
|
if (bad != null) throw new CliExit(EXIT.usage, bad);
|
|
24134
24485
|
const selection = selectOrExit(ctx, { bare: "default" });
|
|
@@ -24162,7 +24513,11 @@ async function cmdUp(ctx) {
|
|
|
24162
24513
|
}
|
|
24163
24514
|
}
|
|
24164
24515
|
async function controlVerb(ctx, verb) {
|
|
24165
|
-
const known = verb === "restart" ? [
|
|
24516
|
+
const known = verb === "restart" ? [
|
|
24517
|
+
"--no-wait",
|
|
24518
|
+
"--all",
|
|
24519
|
+
"--any"
|
|
24520
|
+
] : ["--all", "--any"];
|
|
24166
24521
|
const bad = unknownFlags(ctx.args.flags, known);
|
|
24167
24522
|
if (bad != null) throw new CliExit(EXIT.usage, bad);
|
|
24168
24523
|
requireSelectionTerms(ctx);
|
|
@@ -24257,6 +24612,85 @@ function reportSignalShutdown(ctx, result) {
|
|
|
24257
24612
|
}
|
|
24258
24613
|
}
|
|
24259
24614
|
//#endregion
|
|
24615
|
+
//#region src/daemon/envOverrides.ts
|
|
24616
|
+
const STORE_VERSION$1 = 1;
|
|
24617
|
+
/** A knob is a port or a log level, not a payload. Bounds keep a mistake from becoming a file. */
|
|
24618
|
+
const MAX_VALUE_LENGTH = 4096;
|
|
24619
|
+
const EMPTY_ENV_OVERRIDES = Object.freeze({});
|
|
24620
|
+
function readable$1(value) {
|
|
24621
|
+
if (value == null || typeof value !== "object") return null;
|
|
24622
|
+
const processes = value.processes;
|
|
24623
|
+
if (processes == null || typeof processes !== "object" || Array.isArray(processes)) return null;
|
|
24624
|
+
const clean = {};
|
|
24625
|
+
for (const [id, values] of Object.entries(processes)) {
|
|
24626
|
+
if (values == null || typeof values !== "object" || Array.isArray(values)) continue;
|
|
24627
|
+
const entries = {};
|
|
24628
|
+
for (const [name, entry] of Object.entries(values)) if (typeof entry === "string" && entry.length <= MAX_VALUE_LENGTH) entries[name] = entry;
|
|
24629
|
+
if (Object.keys(entries).length > 0) clean[id] = entries;
|
|
24630
|
+
}
|
|
24631
|
+
return clean;
|
|
24632
|
+
}
|
|
24633
|
+
/**
|
|
24634
|
+
* Missing, unreadable or corrupt all read as "no overrides". A bad file must never block a start:
|
|
24635
|
+
* the config alone is always enough to run, and the surfaces that report overrides say when the
|
|
24636
|
+
* store could not be read.
|
|
24637
|
+
*/
|
|
24638
|
+
async function readEnvOverrides(path) {
|
|
24639
|
+
try {
|
|
24640
|
+
return readable$1(JSON.parse(await (0, node_fs_promises.readFile)(path, "utf8"))) ?? EMPTY_ENV_OVERRIDES;
|
|
24641
|
+
} catch {
|
|
24642
|
+
return EMPTY_ENV_OVERRIDES;
|
|
24643
|
+
}
|
|
24644
|
+
}
|
|
24645
|
+
/** 0600 and atomic — it can hold a token, and a half-written file must never be read as empty. */
|
|
24646
|
+
async function writeEnvOverrides(path, overrides) {
|
|
24647
|
+
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), {
|
|
24648
|
+
recursive: true,
|
|
24649
|
+
mode: 448
|
|
24650
|
+
});
|
|
24651
|
+
const store = {
|
|
24652
|
+
version: STORE_VERSION$1,
|
|
24653
|
+
processes: Object.fromEntries(Object.entries(overrides).filter(([, values]) => Object.keys(values).length > 0).map(([id, values]) => [id, { ...values }]))
|
|
24654
|
+
};
|
|
24655
|
+
const temp = `${path}.${process.pid}.tmp`;
|
|
24656
|
+
await (0, node_fs_promises.writeFile)(temp, `${JSON.stringify(store, null, 2)}\n`, {
|
|
24657
|
+
encoding: "utf8",
|
|
24658
|
+
mode: 384
|
|
24659
|
+
});
|
|
24660
|
+
await (0, node_fs_promises.rename)(temp, path);
|
|
24661
|
+
}
|
|
24662
|
+
/** Pure: the store that results from applying `change`. Empty processes are pruned. */
|
|
24663
|
+
function mutateEnvOverrides(current, change) {
|
|
24664
|
+
const next = {};
|
|
24665
|
+
for (const [id, values] of Object.entries(current)) next[id] = { ...values };
|
|
24666
|
+
for (const id of change.clear ?? []) delete next[id];
|
|
24667
|
+
for (const [id, values] of Object.entries(change.mutations ?? {})) {
|
|
24668
|
+
const entries = next[id] ?? {};
|
|
24669
|
+
for (const [name, value] of Object.entries(values)) if (value == null) delete entries[name];
|
|
24670
|
+
else entries[name] = value;
|
|
24671
|
+
if (Object.keys(entries).length > 0) next[id] = entries;
|
|
24672
|
+
else delete next[id];
|
|
24673
|
+
}
|
|
24674
|
+
return next;
|
|
24675
|
+
}
|
|
24676
|
+
/**
|
|
24677
|
+
* Read → check against the config → mutate → write, atomically enough for a file two surfaces
|
|
24678
|
+
* touch. The one implementation behind both writers, so the daemon's `setEnv` and the CLI's
|
|
24679
|
+
* no-daemon path can never diverge on what they accept.
|
|
24680
|
+
*/
|
|
24681
|
+
async function applyEnvMutation(path, config, input) {
|
|
24682
|
+
const checked = checkEnvMutations(config, input);
|
|
24683
|
+
const next = mutateEnvOverrides(await readEnvOverrides(path), checked);
|
|
24684
|
+
await writeEnvOverrides(path, next);
|
|
24685
|
+
return {
|
|
24686
|
+
overrides: next,
|
|
24687
|
+
warnings: checked.warnings
|
|
24688
|
+
};
|
|
24689
|
+
}
|
|
24690
|
+
function countOverrides(overrides) {
|
|
24691
|
+
return Object.values(overrides).reduce((total, values) => total + Object.keys(values).length, 0);
|
|
24692
|
+
}
|
|
24693
|
+
//#endregion
|
|
24260
24694
|
//#region src/ports/listeners.ts
|
|
24261
24695
|
const exec = (0, node_util.promisify)(node_child_process.execFile);
|
|
24262
24696
|
const ACTIVE = new Set([
|
|
@@ -24490,181 +24924,6 @@ function createPortInspector(options) {
|
|
|
24490
24924
|
return { run };
|
|
24491
24925
|
}
|
|
24492
24926
|
//#endregion
|
|
24493
|
-
//#region src/cli/commands/ports.ts
|
|
24494
|
-
async function portProcessStates(ctx) {
|
|
24495
|
-
const handle = await findDaemon(ctx.config);
|
|
24496
|
-
if (!handle) return /* @__PURE__ */ new Map();
|
|
24497
|
-
const client = await connectDaemon(handle);
|
|
24498
|
-
try {
|
|
24499
|
-
return new Map(Object.entries(client.state().processes).map(([id, p]) => [id, p.state]));
|
|
24500
|
-
} finally {
|
|
24501
|
-
client.dispose();
|
|
24502
|
-
}
|
|
24503
|
-
}
|
|
24504
|
-
async function cmdPorts(ctx) {
|
|
24505
|
-
const bad = unknownFlags(ctx.args.flags, [
|
|
24506
|
-
"--all",
|
|
24507
|
-
"--kill",
|
|
24508
|
-
"--yes",
|
|
24509
|
-
"--force"
|
|
24510
|
-
]);
|
|
24511
|
-
if (bad) throw new CliExit(EXIT.usage, bad);
|
|
24512
|
-
const pid = numericFlag(ctx.args.flags, "--kill");
|
|
24513
|
-
if (pid != null && typeof pid !== "number") throw new CliExit(EXIT.usage, pid.error);
|
|
24514
|
-
for (const flag of [
|
|
24515
|
-
"--yes",
|
|
24516
|
-
"--force",
|
|
24517
|
-
"--all"
|
|
24518
|
-
]) if (ctx.args.flags.has(flag) && ctx.args.flags.get(flag) !== true) throw new CliExit(EXIT.usage, `${flag} takes no value`);
|
|
24519
|
-
if (!pid && (ctx.args.flags.has("--force") || ctx.args.flags.has("--yes"))) throw new CliExit(EXIT.usage, "--force/--yes require --kill PID");
|
|
24520
|
-
const ids = ctx.args.positionals.length || ctx.args.flags.has("--all") ? selectOrExit(ctx, { bare: "required" }).direct : ctx.config.processes.map((p) => p.id);
|
|
24521
|
-
const inspector = createPortInspector({
|
|
24522
|
-
config: () => ctx.config,
|
|
24523
|
-
states: () => portProcessStates(ctx),
|
|
24524
|
-
protectedPids: async () => {
|
|
24525
|
-
const daemon = await findDaemon(ctx.config);
|
|
24526
|
-
return daemon ? [daemon.record.pid] : [];
|
|
24527
|
-
}
|
|
24528
|
-
});
|
|
24529
|
-
const report = await inspector.run({ ids });
|
|
24530
|
-
const print = (result) => {
|
|
24531
|
-
if (ctx.out.json) {
|
|
24532
|
-
ctx.out.printJson(result);
|
|
24533
|
-
return;
|
|
24534
|
-
}
|
|
24535
|
-
ctx.out.print(ctx.out.table([
|
|
24536
|
-
"PROCESS",
|
|
24537
|
-
"ENDPOINT",
|
|
24538
|
-
"PID",
|
|
24539
|
-
"PARENT",
|
|
24540
|
-
"COMMAND",
|
|
24541
|
-
"CWD",
|
|
24542
|
-
"IDENTITY",
|
|
24543
|
-
"STOP"
|
|
24544
|
-
], result.listeners.map((l) => [
|
|
24545
|
-
l.id,
|
|
24546
|
-
`${l.host}:${l.port}`,
|
|
24547
|
-
String(l.pid),
|
|
24548
|
-
String(l.ppid ?? "unknown"),
|
|
24549
|
-
l.command,
|
|
24550
|
-
l.cwd ?? "unavailable",
|
|
24551
|
-
l.startStamp ?? "unknown",
|
|
24552
|
-
l.refusal ?? "available"
|
|
24553
|
-
])));
|
|
24554
|
-
if (!result.listeners.length) ctx.out.print("No visible listeners on the selected exclusive TCP endpoints.");
|
|
24555
|
-
for (const warning of result.warnings) ctx.out.warn(warning);
|
|
24556
|
-
};
|
|
24557
|
-
if (!pid) {
|
|
24558
|
-
print(report);
|
|
24559
|
-
return report.warnings.length ? EXIT.failure : EXIT.ok;
|
|
24560
|
-
}
|
|
24561
|
-
const target = report.listeners.find((l) => l.pid === pid);
|
|
24562
|
-
if (!target?.token) {
|
|
24563
|
-
print(report);
|
|
24564
|
-
throw new CliExit(EXIT.failure, target?.refusal ?? `PID ${pid} is not a verified listener on the selected endpoints`);
|
|
24565
|
-
}
|
|
24566
|
-
if (!ctx.args.flags.has("--yes")) {
|
|
24567
|
-
print(report);
|
|
24568
|
-
if (!process.stdin.isTTY || ctx.out.json) throw new CliExit(EXIT.usage, "Stopping requires interactive confirmation, or --yes with --kill PID");
|
|
24569
|
-
const rl = (0, node_readline_promises.createInterface)({
|
|
24570
|
-
input: process.stdin,
|
|
24571
|
-
output: process.stdout
|
|
24572
|
-
});
|
|
24573
|
-
try {
|
|
24574
|
-
const answer = await rl.question(`${ctx.args.flags.has("--force") ? "Force kill" : "Stop"} PID ${pid} (${target.command}) on ${target.host}:${target.port}? [y/N] `);
|
|
24575
|
-
if (!/^y(es)?$/i.test(answer.trim())) return EXIT.ok;
|
|
24576
|
-
} finally {
|
|
24577
|
-
rl.close();
|
|
24578
|
-
}
|
|
24579
|
-
}
|
|
24580
|
-
const result = await inspector.run({
|
|
24581
|
-
ids,
|
|
24582
|
-
token: target.token,
|
|
24583
|
-
force: ctx.args.flags.has("--force")
|
|
24584
|
-
});
|
|
24585
|
-
print(result);
|
|
24586
|
-
return result.warnings.length ? EXIT.failure : EXIT.ok;
|
|
24587
|
-
}
|
|
24588
|
-
//#endregion
|
|
24589
|
-
//#region src/daemon/envOverrides.ts
|
|
24590
|
-
const STORE_VERSION = 1;
|
|
24591
|
-
/** A knob is a port or a log level, not a payload. Bounds keep a mistake from becoming a file. */
|
|
24592
|
-
const MAX_VALUE_LENGTH = 4096;
|
|
24593
|
-
const EMPTY_ENV_OVERRIDES = Object.freeze({});
|
|
24594
|
-
function readable(value) {
|
|
24595
|
-
if (value == null || typeof value !== "object") return null;
|
|
24596
|
-
const processes = value.processes;
|
|
24597
|
-
if (processes == null || typeof processes !== "object" || Array.isArray(processes)) return null;
|
|
24598
|
-
const clean = {};
|
|
24599
|
-
for (const [id, values] of Object.entries(processes)) {
|
|
24600
|
-
if (values == null || typeof values !== "object" || Array.isArray(values)) continue;
|
|
24601
|
-
const entries = {};
|
|
24602
|
-
for (const [name, entry] of Object.entries(values)) if (typeof entry === "string" && entry.length <= MAX_VALUE_LENGTH) entries[name] = entry;
|
|
24603
|
-
if (Object.keys(entries).length > 0) clean[id] = entries;
|
|
24604
|
-
}
|
|
24605
|
-
return clean;
|
|
24606
|
-
}
|
|
24607
|
-
/**
|
|
24608
|
-
* Missing, unreadable or corrupt all read as "no overrides". A bad file must never block a start:
|
|
24609
|
-
* the config alone is always enough to run, and the surfaces that report overrides say when the
|
|
24610
|
-
* store could not be read.
|
|
24611
|
-
*/
|
|
24612
|
-
async function readEnvOverrides(path) {
|
|
24613
|
-
try {
|
|
24614
|
-
return readable(JSON.parse(await (0, node_fs_promises.readFile)(path, "utf8"))) ?? EMPTY_ENV_OVERRIDES;
|
|
24615
|
-
} catch {
|
|
24616
|
-
return EMPTY_ENV_OVERRIDES;
|
|
24617
|
-
}
|
|
24618
|
-
}
|
|
24619
|
-
/** 0600 and atomic — it can hold a token, and a half-written file must never be read as empty. */
|
|
24620
|
-
async function writeEnvOverrides(path, overrides) {
|
|
24621
|
-
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), {
|
|
24622
|
-
recursive: true,
|
|
24623
|
-
mode: 448
|
|
24624
|
-
});
|
|
24625
|
-
const store = {
|
|
24626
|
-
version: STORE_VERSION,
|
|
24627
|
-
processes: Object.fromEntries(Object.entries(overrides).filter(([, values]) => Object.keys(values).length > 0).map(([id, values]) => [id, { ...values }]))
|
|
24628
|
-
};
|
|
24629
|
-
const temp = `${path}.${process.pid}.tmp`;
|
|
24630
|
-
await (0, node_fs_promises.writeFile)(temp, `${JSON.stringify(store, null, 2)}\n`, {
|
|
24631
|
-
encoding: "utf8",
|
|
24632
|
-
mode: 384
|
|
24633
|
-
});
|
|
24634
|
-
await (0, node_fs_promises.rename)(temp, path);
|
|
24635
|
-
}
|
|
24636
|
-
/** Pure: the store that results from applying `change`. Empty processes are pruned. */
|
|
24637
|
-
function mutateEnvOverrides(current, change) {
|
|
24638
|
-
const next = {};
|
|
24639
|
-
for (const [id, values] of Object.entries(current)) next[id] = { ...values };
|
|
24640
|
-
for (const id of change.clear ?? []) delete next[id];
|
|
24641
|
-
for (const [id, values] of Object.entries(change.mutations ?? {})) {
|
|
24642
|
-
const entries = next[id] ?? {};
|
|
24643
|
-
for (const [name, value] of Object.entries(values)) if (value == null) delete entries[name];
|
|
24644
|
-
else entries[name] = value;
|
|
24645
|
-
if (Object.keys(entries).length > 0) next[id] = entries;
|
|
24646
|
-
else delete next[id];
|
|
24647
|
-
}
|
|
24648
|
-
return next;
|
|
24649
|
-
}
|
|
24650
|
-
/**
|
|
24651
|
-
* Read → check against the config → mutate → write, atomically enough for a file two surfaces
|
|
24652
|
-
* touch. The one implementation behind both writers, so the daemon's `setEnv` and the CLI's
|
|
24653
|
-
* no-daemon path can never diverge on what they accept.
|
|
24654
|
-
*/
|
|
24655
|
-
async function applyEnvMutation(path, config, input) {
|
|
24656
|
-
const checked = checkEnvMutations(config, input);
|
|
24657
|
-
const next = mutateEnvOverrides(await readEnvOverrides(path), checked);
|
|
24658
|
-
await writeEnvOverrides(path, next);
|
|
24659
|
-
return {
|
|
24660
|
-
overrides: next,
|
|
24661
|
-
warnings: checked.warnings
|
|
24662
|
-
};
|
|
24663
|
-
}
|
|
24664
|
-
function countOverrides(overrides) {
|
|
24665
|
-
return Object.values(overrides).reduce((total, values) => total + Object.keys(values).length, 0);
|
|
24666
|
-
}
|
|
24667
|
-
//#endregion
|
|
24668
24927
|
//#region src/cli/commands/doctor.ts
|
|
24669
24928
|
function formatAge(ms) {
|
|
24670
24929
|
if (ms < 6e4) return `${Math.round(ms / 1e3)}s`;
|
|
@@ -24998,12 +25257,10 @@ async function cmdList(ctx) {
|
|
|
24998
25257
|
dependsOn: proc.dependsOn,
|
|
24999
25258
|
endpoints: proc.endpoints,
|
|
25000
25259
|
url: proc.url ?? null,
|
|
25001
|
-
envVars: proc.envVars
|
|
25260
|
+
envVars: proc.envVars,
|
|
25261
|
+
optIn: proc.optIn
|
|
25002
25262
|
})),
|
|
25003
|
-
|
|
25004
|
-
ids: group.ids,
|
|
25005
|
-
staggerMs: group.staggerMs
|
|
25006
|
-
}])),
|
|
25263
|
+
suites: Object.fromEntries(Object.entries(config.suites).map(([name, { name: _name, ...suite }]) => [name, suite])),
|
|
25007
25264
|
warnings: config.warnings
|
|
25008
25265
|
});
|
|
25009
25266
|
return EXIT.ok;
|
|
@@ -25017,31 +25274,31 @@ async function cmdList(ctx) {
|
|
|
25017
25274
|
], config.processes.map((proc) => [
|
|
25018
25275
|
proc.id,
|
|
25019
25276
|
proc.kind,
|
|
25020
|
-
|
|
25277
|
+
[...tagTermsOf(proc.tags), ...proc.optIn ? ["(opt-in)"] : []].join(" "),
|
|
25021
25278
|
proc.dependsOn.join(" "),
|
|
25022
25279
|
proc.endpoints.map((endpoint) => `${endpoint.name}:${endpoint.port}`).join(" ")
|
|
25023
25280
|
])));
|
|
25024
|
-
const
|
|
25025
|
-
name,
|
|
25026
|
-
String(
|
|
25027
|
-
|
|
25028
|
-
|
|
25281
|
+
const suiteRows = Object.values(config.suites).map((suite) => [
|
|
25282
|
+
suite.name,
|
|
25283
|
+
String(suite.ids.length),
|
|
25284
|
+
`parallel ${suite.parallel}${suite.failFast ? " · fail-fast" : ""}`,
|
|
25285
|
+
suite.ids.join(" ")
|
|
25029
25286
|
]);
|
|
25030
|
-
if (
|
|
25287
|
+
if (suiteRows.length > 0) {
|
|
25031
25288
|
out.print("");
|
|
25032
25289
|
out.print(out.table([
|
|
25033
|
-
"
|
|
25290
|
+
"SUITE",
|
|
25034
25291
|
"N",
|
|
25035
|
-
"
|
|
25036
|
-
"
|
|
25037
|
-
],
|
|
25292
|
+
"POLICY",
|
|
25293
|
+
"IDS"
|
|
25294
|
+
], suiteRows));
|
|
25038
25295
|
}
|
|
25039
25296
|
if (config.defaultSelection != null) out.print(out.paint("gray", `\ndefaultSelection: ${config.defaultSelection}`));
|
|
25040
25297
|
for (const warning of config.warnings) out.warn(`${out.paint("yellow", "⚠")} ${warning}`);
|
|
25041
25298
|
return EXIT.ok;
|
|
25042
25299
|
}
|
|
25043
25300
|
async function cmdExplain(ctx) {
|
|
25044
|
-
const bad = unknownFlags(ctx.args.flags, ["--all"]);
|
|
25301
|
+
const bad = unknownFlags(ctx.args.flags, ["--all", "--any"]);
|
|
25045
25302
|
if (bad != null) throw new CliExit(EXIT.usage, bad);
|
|
25046
25303
|
const selection = selectOrExit(ctx, { bare: "default" });
|
|
25047
25304
|
const { out } = ctx;
|
|
@@ -25051,6 +25308,9 @@ async function cmdExplain(ctx) {
|
|
|
25051
25308
|
}
|
|
25052
25309
|
out.print(`direct: ${selection.direct.join(", ") || "(none)"}`);
|
|
25053
25310
|
out.print(`auto-included: ${selection.autoIncluded.length > 0 ? selection.autoIncluded.join(", ") : "(none)"}`);
|
|
25311
|
+
const [onlyTerm] = ctx.args.positionals.length === 1 ? ctx.args.positionals : [];
|
|
25312
|
+
const suite = onlyTerm == null ? void 0 : ctx.config.suites[onlyTerm];
|
|
25313
|
+
if (suite != null) out.print(`suite policy: parallel ${suite.parallel}, fail-fast ${suite.failFast ? "on" : "off"}, stagger ${suite.staggerMs}ms`);
|
|
25054
25314
|
out.print(`DAG order:`);
|
|
25055
25315
|
selection.ordered.forEach((id, index) => {
|
|
25056
25316
|
out.print(` ${index + 1}. ${id}`);
|
|
@@ -25238,6 +25498,7 @@ function printLine(out, entry) {
|
|
|
25238
25498
|
}
|
|
25239
25499
|
async function cmdLogs(ctx) {
|
|
25240
25500
|
const bad = unknownFlags(ctx.args.flags, [
|
|
25501
|
+
"--any",
|
|
25241
25502
|
"-f",
|
|
25242
25503
|
"--follow",
|
|
25243
25504
|
"--all"
|
|
@@ -25302,6 +25563,159 @@ async function cmdLogs(ctx) {
|
|
|
25302
25563
|
}
|
|
25303
25564
|
}
|
|
25304
25565
|
//#endregion
|
|
25566
|
+
//#region src/cli/commands/ports.ts
|
|
25567
|
+
async function portProcessStates(ctx) {
|
|
25568
|
+
const handle = await findDaemon(ctx.config);
|
|
25569
|
+
if (!handle) return /* @__PURE__ */ new Map();
|
|
25570
|
+
const client = await connectDaemon(handle);
|
|
25571
|
+
try {
|
|
25572
|
+
return new Map(Object.entries(client.state().processes).map(([id, p]) => [id, p.state]));
|
|
25573
|
+
} finally {
|
|
25574
|
+
client.dispose();
|
|
25575
|
+
}
|
|
25576
|
+
}
|
|
25577
|
+
async function cmdPorts(ctx) {
|
|
25578
|
+
const bad = unknownFlags(ctx.args.flags, [
|
|
25579
|
+
"--all",
|
|
25580
|
+
"--kill",
|
|
25581
|
+
"--yes",
|
|
25582
|
+
"--force"
|
|
25583
|
+
]);
|
|
25584
|
+
if (bad) throw new CliExit(EXIT.usage, bad);
|
|
25585
|
+
const pid = numericFlag(ctx.args.flags, "--kill");
|
|
25586
|
+
if (pid != null && typeof pid !== "number") throw new CliExit(EXIT.usage, pid.error);
|
|
25587
|
+
for (const flag of [
|
|
25588
|
+
"--yes",
|
|
25589
|
+
"--force",
|
|
25590
|
+
"--all"
|
|
25591
|
+
]) if (ctx.args.flags.has(flag) && ctx.args.flags.get(flag) !== true) throw new CliExit(EXIT.usage, `${flag} takes no value`);
|
|
25592
|
+
if (!pid && (ctx.args.flags.has("--force") || ctx.args.flags.has("--yes"))) throw new CliExit(EXIT.usage, "--force/--yes require --kill PID");
|
|
25593
|
+
const ids = ctx.args.positionals.length || ctx.args.flags.has("--all") ? selectOrExit(ctx, { bare: "required" }).direct : ctx.config.processes.map((p) => p.id);
|
|
25594
|
+
const inspector = createPortInspector({
|
|
25595
|
+
config: () => ctx.config,
|
|
25596
|
+
states: () => portProcessStates(ctx),
|
|
25597
|
+
protectedPids: async () => {
|
|
25598
|
+
const daemon = await findDaemon(ctx.config);
|
|
25599
|
+
return daemon ? [daemon.record.pid] : [];
|
|
25600
|
+
}
|
|
25601
|
+
});
|
|
25602
|
+
const report = await inspector.run({ ids });
|
|
25603
|
+
const print = (result) => {
|
|
25604
|
+
if (ctx.out.json) {
|
|
25605
|
+
ctx.out.printJson(result);
|
|
25606
|
+
return;
|
|
25607
|
+
}
|
|
25608
|
+
ctx.out.print(ctx.out.table([
|
|
25609
|
+
"PROCESS",
|
|
25610
|
+
"ENDPOINT",
|
|
25611
|
+
"PID",
|
|
25612
|
+
"PARENT",
|
|
25613
|
+
"COMMAND",
|
|
25614
|
+
"CWD",
|
|
25615
|
+
"IDENTITY",
|
|
25616
|
+
"STOP"
|
|
25617
|
+
], result.listeners.map((l) => [
|
|
25618
|
+
l.id,
|
|
25619
|
+
`${l.host}:${l.port}`,
|
|
25620
|
+
String(l.pid),
|
|
25621
|
+
String(l.ppid ?? "unknown"),
|
|
25622
|
+
l.command,
|
|
25623
|
+
l.cwd ?? "unavailable",
|
|
25624
|
+
l.startStamp ?? "unknown",
|
|
25625
|
+
l.refusal ?? "available"
|
|
25626
|
+
])));
|
|
25627
|
+
if (!result.listeners.length) ctx.out.print("No visible listeners on the selected exclusive TCP endpoints.");
|
|
25628
|
+
for (const warning of result.warnings) ctx.out.warn(warning);
|
|
25629
|
+
};
|
|
25630
|
+
if (!pid) {
|
|
25631
|
+
print(report);
|
|
25632
|
+
return report.warnings.length ? EXIT.failure : EXIT.ok;
|
|
25633
|
+
}
|
|
25634
|
+
const target = report.listeners.find((l) => l.pid === pid);
|
|
25635
|
+
if (!target?.token) {
|
|
25636
|
+
print(report);
|
|
25637
|
+
throw new CliExit(EXIT.failure, target?.refusal ?? `PID ${pid} is not a verified listener on the selected endpoints`);
|
|
25638
|
+
}
|
|
25639
|
+
if (!ctx.args.flags.has("--yes")) {
|
|
25640
|
+
print(report);
|
|
25641
|
+
if (!process.stdin.isTTY || ctx.out.json) throw new CliExit(EXIT.usage, "Stopping requires interactive confirmation, or --yes with --kill PID");
|
|
25642
|
+
const rl = (0, node_readline_promises.createInterface)({
|
|
25643
|
+
input: process.stdin,
|
|
25644
|
+
output: process.stdout
|
|
25645
|
+
});
|
|
25646
|
+
try {
|
|
25647
|
+
const answer = await rl.question(`${ctx.args.flags.has("--force") ? "Force kill" : "Stop"} PID ${pid} (${target.command}) on ${target.host}:${target.port}? [y/N] `);
|
|
25648
|
+
if (!/^y(es)?$/i.test(answer.trim())) return EXIT.ok;
|
|
25649
|
+
} finally {
|
|
25650
|
+
rl.close();
|
|
25651
|
+
}
|
|
25652
|
+
}
|
|
25653
|
+
const result = await inspector.run({
|
|
25654
|
+
ids,
|
|
25655
|
+
token: target.token,
|
|
25656
|
+
force: ctx.args.flags.has("--force")
|
|
25657
|
+
});
|
|
25658
|
+
print(result);
|
|
25659
|
+
return result.warnings.length ? EXIT.failure : EXIT.ok;
|
|
25660
|
+
}
|
|
25661
|
+
//#endregion
|
|
25662
|
+
//#region src/run/scheduler.ts
|
|
25663
|
+
async function runTaskPool(options) {
|
|
25664
|
+
const { failFast } = options;
|
|
25665
|
+
const pending = [...options.tasks];
|
|
25666
|
+
const succeeded = /* @__PURE__ */ new Set();
|
|
25667
|
+
const failed = /* @__PURE__ */ new Set();
|
|
25668
|
+
const running = /* @__PURE__ */ new Set();
|
|
25669
|
+
const selected = new Set(options.tasks.map((task) => task.id));
|
|
25670
|
+
const depsOf = (task) => task.dependsOn.filter((id) => selected.has(id));
|
|
25671
|
+
let cut = false;
|
|
25672
|
+
let waiters = [];
|
|
25673
|
+
const settled = () => new Promise((resolve) => {
|
|
25674
|
+
waiters.push(resolve);
|
|
25675
|
+
});
|
|
25676
|
+
const wake = () => {
|
|
25677
|
+
const current = waiters;
|
|
25678
|
+
waiters = [];
|
|
25679
|
+
for (const resolve of current) resolve();
|
|
25680
|
+
};
|
|
25681
|
+
const workers = Array.from({ length: Math.min(Math.max(1, options.parallel), pending.length) }, async () => {
|
|
25682
|
+
for (;;) {
|
|
25683
|
+
if (cut) return;
|
|
25684
|
+
const index = pending.findIndex((task) => depsOf(task).every((id) => succeeded.has(id) || failed.has(id)));
|
|
25685
|
+
if (index < 0) {
|
|
25686
|
+
if (running.size === 0) return;
|
|
25687
|
+
await settled();
|
|
25688
|
+
continue;
|
|
25689
|
+
}
|
|
25690
|
+
const [task] = pending.splice(index, 1);
|
|
25691
|
+
if (task == null) return;
|
|
25692
|
+
const blockedBy = depsOf(task).find((id) => failed.has(id));
|
|
25693
|
+
if (blockedBy != null) {
|
|
25694
|
+
failed.add(task.id);
|
|
25695
|
+
options.onBlocked(task, blockedBy);
|
|
25696
|
+
wake();
|
|
25697
|
+
continue;
|
|
25698
|
+
}
|
|
25699
|
+
running.add(task.id);
|
|
25700
|
+
const ok = await options.run(task);
|
|
25701
|
+
running.delete(task.id);
|
|
25702
|
+
(ok ? succeeded : failed).add(task.id);
|
|
25703
|
+
if (!ok && failFast && !cut) {
|
|
25704
|
+
cut = true;
|
|
25705
|
+
options.onFailFast?.();
|
|
25706
|
+
}
|
|
25707
|
+
wake();
|
|
25708
|
+
if (cut) return;
|
|
25709
|
+
}
|
|
25710
|
+
});
|
|
25711
|
+
await Promise.all(workers);
|
|
25712
|
+
return {
|
|
25713
|
+
succeeded,
|
|
25714
|
+
failed,
|
|
25715
|
+
leftover: pending
|
|
25716
|
+
};
|
|
25717
|
+
}
|
|
25718
|
+
//#endregion
|
|
25305
25719
|
//#region src/cli/commands/run.ts
|
|
25306
25720
|
const ACTIVE_STATES$1 = new Set([
|
|
25307
25721
|
"starting",
|
|
@@ -25366,14 +25780,17 @@ async function cmdRun(ctx) {
|
|
|
25366
25780
|
const bad = unknownFlags(ctx.args.flags, [
|
|
25367
25781
|
"--parallel",
|
|
25368
25782
|
"--fail-fast",
|
|
25369
|
-
"--all"
|
|
25783
|
+
"--all",
|
|
25784
|
+
"--any"
|
|
25370
25785
|
]);
|
|
25371
25786
|
if (bad != null) throw new CliExit(EXIT.usage, bad);
|
|
25372
25787
|
const parallel = numericFlag(ctx.args.flags, "--parallel");
|
|
25373
25788
|
if (parallel != null && typeof parallel === "object") throw new CliExit(EXIT.usage, parallel.error);
|
|
25374
|
-
const failFast = ctx.args.flags.has("--fail-fast");
|
|
25375
25789
|
const selection = selectOrExit(ctx, { bare: "required" });
|
|
25376
25790
|
const { out, config } = ctx;
|
|
25791
|
+
const [onlyTerm] = ctx.args.positionals.length === 1 ? ctx.args.positionals : [];
|
|
25792
|
+
const suitePolicy = onlyTerm == null ? void 0 : config.suites[onlyTerm];
|
|
25793
|
+
const failFast = ctx.args.flags.has("--fail-fast") || suitePolicy?.failFast === true;
|
|
25377
25794
|
const byId = new Map(config.processes.map((proc) => [proc.id, proc]));
|
|
25378
25795
|
const defs = selection.ordered.flatMap((id) => {
|
|
25379
25796
|
const def = byId.get(id);
|
|
@@ -25534,60 +25951,30 @@ async function cmdRun(ctx) {
|
|
|
25534
25951
|
try {
|
|
25535
25952
|
const pumps = single ? [] : procs.map((proc) => startPump(out, proc));
|
|
25536
25953
|
if (tasks.length > 0 && services.length === 0) {
|
|
25537
|
-
const
|
|
25538
|
-
|
|
25539
|
-
|
|
25540
|
-
|
|
25541
|
-
|
|
25542
|
-
const depsOf = (def) => def.dependsOn.filter((id) => selected.has(id));
|
|
25543
|
-
let waiters = [];
|
|
25544
|
-
const settled = () => new Promise((resolve) => {
|
|
25545
|
-
waiters.push(resolve);
|
|
25546
|
-
});
|
|
25547
|
-
const wake = () => {
|
|
25548
|
-
const current = waiters;
|
|
25549
|
-
waiters = [];
|
|
25550
|
-
for (const resolve of current) resolve();
|
|
25551
|
-
};
|
|
25552
|
-
const workers = Array.from({ length: Math.min(parallel ?? 1, pending.length) }, async () => {
|
|
25553
|
-
for (;;) {
|
|
25554
|
-
if (failFast && failures.length > 0) return;
|
|
25555
|
-
const index = pending.findIndex((def) => depsOf(def).every((id) => succeeded.has(id) || failed.has(id)));
|
|
25556
|
-
if (index < 0) {
|
|
25557
|
-
if (running.size === 0) return;
|
|
25558
|
-
await settled();
|
|
25559
|
-
continue;
|
|
25560
|
-
}
|
|
25561
|
-
const [def] = pending.splice(index, 1);
|
|
25562
|
-
const blockedBy = depsOf(def).find((id) => failed.has(id));
|
|
25563
|
-
if (blockedBy != null) {
|
|
25564
|
-
out.print(`${out.paint("yellow", "⊘")} ${out.accent(def.id, def.id)} blocked: "${blockedBy}" failed`);
|
|
25565
|
-
failed.add(def.id);
|
|
25566
|
-
recordFailure({
|
|
25567
|
-
id: def.id,
|
|
25568
|
-
code: 1,
|
|
25569
|
-
failed: true
|
|
25570
|
-
});
|
|
25571
|
-
wake();
|
|
25572
|
-
continue;
|
|
25573
|
-
}
|
|
25574
|
-
running.add(def.id);
|
|
25954
|
+
const pool = await runTaskPool({
|
|
25955
|
+
tasks,
|
|
25956
|
+
parallel: parallel ?? suitePolicy?.parallel ?? 1,
|
|
25957
|
+
failFast,
|
|
25958
|
+
run: async (def) => {
|
|
25575
25959
|
const result = await runTask(def);
|
|
25576
|
-
|
|
25577
|
-
|
|
25578
|
-
|
|
25579
|
-
|
|
25580
|
-
|
|
25581
|
-
|
|
25582
|
-
|
|
25583
|
-
|
|
25584
|
-
|
|
25585
|
-
}
|
|
25960
|
+
if (result.failed) recordFailure(result);
|
|
25961
|
+
return !result.failed;
|
|
25962
|
+
},
|
|
25963
|
+
onBlocked: (def, blockedBy) => {
|
|
25964
|
+
out.print(`${out.paint("yellow", "⊘")} ${out.accent(def.id, def.id)} blocked: "${blockedBy}" failed`);
|
|
25965
|
+
recordFailure({
|
|
25966
|
+
id: def.id,
|
|
25967
|
+
code: 1,
|
|
25968
|
+
failed: true
|
|
25969
|
+
});
|
|
25970
|
+
},
|
|
25971
|
+
onFailFast: () => {
|
|
25972
|
+
for (const proc of procs) if (!TERMINAL_STATES.has(proc.state)) proc.stop();
|
|
25586
25973
|
}
|
|
25587
25974
|
});
|
|
25588
|
-
|
|
25589
|
-
for (const def of
|
|
25590
|
-
const blockedBy =
|
|
25975
|
+
const { succeeded } = pool;
|
|
25976
|
+
for (const def of pool.leftover) {
|
|
25977
|
+
const blockedBy = def.dependsOn.find((id) => tasks.some((t) => t.id === id) && !succeeded.has(id)) ?? "a dependency";
|
|
25591
25978
|
out.print(`${out.paint("yellow", "⊘")} ${out.accent(def.id, def.id)} blocked: "${blockedBy}" did not succeed`);
|
|
25592
25979
|
recordFailure({
|
|
25593
25980
|
id: def.id,
|
|
@@ -25865,6 +26252,82 @@ async function cmdUi(ctx) {
|
|
|
25865
26252
|
return EXIT.ok;
|
|
25866
26253
|
}
|
|
25867
26254
|
//#endregion
|
|
26255
|
+
//#region src/daemon/savedFilters.ts
|
|
26256
|
+
const STORE_VERSION = 1;
|
|
26257
|
+
function readable(value) {
|
|
26258
|
+
const filters = value?.filters;
|
|
26259
|
+
if (!Array.isArray(filters)) return [];
|
|
26260
|
+
const clean = [];
|
|
26261
|
+
for (const entry of filters) {
|
|
26262
|
+
const query = checkSavedFilterQuery(entry);
|
|
26263
|
+
if (typeof query === "string") continue;
|
|
26264
|
+
const record = { ...entry };
|
|
26265
|
+
const name = record["name"];
|
|
26266
|
+
const lastRunAt = record["lastRunAt"];
|
|
26267
|
+
clean.push({
|
|
26268
|
+
id: savedFilterId(query),
|
|
26269
|
+
...query,
|
|
26270
|
+
pinned: record["pinned"] === true,
|
|
26271
|
+
...typeof name === "string" && name !== "" ? { name: name.slice(0, 48) } : {},
|
|
26272
|
+
...typeof lastRunAt === "number" ? { lastRunAt } : {}
|
|
26273
|
+
});
|
|
26274
|
+
}
|
|
26275
|
+
return bounded(clean);
|
|
26276
|
+
}
|
|
26277
|
+
/** Pins are kept (newest-first cap); recents are a small ring, most recently run first. */
|
|
26278
|
+
function bounded(filters) {
|
|
26279
|
+
const pins = filters.filter((filter) => filter.pinned).slice(0, 24);
|
|
26280
|
+
const recents = filters.filter((filter) => !filter.pinned).sort((a, b) => (b.lastRunAt ?? 0) - (a.lastRunAt ?? 0)).slice(0, 8);
|
|
26281
|
+
return [...pins, ...recents];
|
|
26282
|
+
}
|
|
26283
|
+
/** Missing, unreadable or corrupt all read as "nothing saved" — never a reason to fail a boot. */
|
|
26284
|
+
async function readSavedFilters(path) {
|
|
26285
|
+
try {
|
|
26286
|
+
return readable(JSON.parse(await (0, node_fs_promises.readFile)(path, "utf8")));
|
|
26287
|
+
} catch {
|
|
26288
|
+
return [];
|
|
26289
|
+
}
|
|
26290
|
+
}
|
|
26291
|
+
async function writeSavedFilters(path, filters) {
|
|
26292
|
+
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), {
|
|
26293
|
+
recursive: true,
|
|
26294
|
+
mode: 448
|
|
26295
|
+
});
|
|
26296
|
+
const temp = `${path}.${process.pid}.tmp`;
|
|
26297
|
+
await (0, node_fs_promises.writeFile)(temp, `${JSON.stringify({
|
|
26298
|
+
version: STORE_VERSION,
|
|
26299
|
+
filters
|
|
26300
|
+
}, null, 2)}\n`, {
|
|
26301
|
+
encoding: "utf8",
|
|
26302
|
+
mode: 384
|
|
26303
|
+
});
|
|
26304
|
+
await (0, node_fs_promises.rename)(temp, path);
|
|
26305
|
+
}
|
|
26306
|
+
/** Pure: the list that results from `change`. */
|
|
26307
|
+
function mutateSavedFilters(current, change) {
|
|
26308
|
+
if (change.kind === "remove") return current.filter((filter) => filter.id !== change.id);
|
|
26309
|
+
const id = savedFilterId(change.query);
|
|
26310
|
+
const existing = current.find((filter) => filter.id === id);
|
|
26311
|
+
const rest = current.filter((filter) => filter.id !== id);
|
|
26312
|
+
if (change.kind === "pin") {
|
|
26313
|
+
const name = change.name.trim().slice(0, 48);
|
|
26314
|
+
return bounded([{
|
|
26315
|
+
...existing,
|
|
26316
|
+
id,
|
|
26317
|
+
...change.query,
|
|
26318
|
+
pinned: true,
|
|
26319
|
+
...name !== "" ? { name } : {}
|
|
26320
|
+
}, ...rest]);
|
|
26321
|
+
}
|
|
26322
|
+
return bounded([{
|
|
26323
|
+
...existing,
|
|
26324
|
+
id,
|
|
26325
|
+
...change.query,
|
|
26326
|
+
pinned: existing?.pinned === true,
|
|
26327
|
+
lastRunAt: change.at
|
|
26328
|
+
}, ...rest]);
|
|
26329
|
+
}
|
|
26330
|
+
//#endregion
|
|
25868
26331
|
//#region src/cli.ts
|
|
25869
26332
|
const HELP = `nice-commander — one typed config, one control surface, for dev environments.
|
|
25870
26333
|
|
|
@@ -25872,8 +26335,9 @@ usage: nice-commander [--config <path>] [--json] [--no-color] [--timeout <ms>] [
|
|
|
25872
26335
|
|
|
25873
26336
|
With NO command, "ui" runs: the daemon is ensured and the browser opened. --help prints this text.
|
|
25874
26337
|
|
|
25875
|
-
selection: process ids,
|
|
25876
|
-
|
|
26338
|
+
selection: process ids, suite names, @pin names, tag=val, or --all. Several tag=val terms AND
|
|
26339
|
+
together; --any ORs them instead. A tag selection and --all never start an optIn process.
|
|
26340
|
+
Bare up/explain use the config's defaultSelection (or print the suites and exit);
|
|
25877
26341
|
bare down/restart/logs/run always require a selection — omission never means --all.
|
|
25878
26342
|
|
|
25879
26343
|
commands:
|
|
@@ -25882,12 +26346,13 @@ commands:
|
|
|
25882
26346
|
restart <sel> [--no-wait] stop + start
|
|
25883
26347
|
status [--watch] table from the live status realm
|
|
25884
26348
|
logs <sel> [-f] merged interleaved tail with colored id prefixes
|
|
25885
|
-
list config introspection (processes,
|
|
25886
|
-
explain [sel] expanded ids, auto-included deps, DAG order
|
|
26349
|
+
list config introspection (processes, suites, warnings)
|
|
26350
|
+
explain [sel] expanded ids, auto-included deps, DAG order, suite policy
|
|
25887
26351
|
env [sel] [--set N=V] [--unset N] declared env vars and their values; --clear drops
|
|
25888
26352
|
overrides. A set value is STICKY: it applies to every
|
|
25889
26353
|
later start until cleared, and never restarts anything.
|
|
25890
|
-
run <sel> [--parallel N] [--fail-fast] foreground, no daemon; tasks = local CI shape
|
|
26354
|
+
run <sel> [--parallel N] [--fail-fast] foreground, no daemon; tasks = local CI shape
|
|
26355
|
+
(a suite supplies its own parallel/fail-fast),
|
|
25891
26356
|
a single id gets raw inherited stdio (interactive).
|
|
25892
26357
|
--fail-fast = stop at the FIRST failure and stop the
|
|
25893
26358
|
survivors; without it every task still runs, every
|
|
@@ -25955,7 +26420,7 @@ async function withTimeout(ctx, run) {
|
|
|
25955
26420
|
async function main() {
|
|
25956
26421
|
const argv = process.argv.slice(2);
|
|
25957
26422
|
if (argv[0] === "daemon") {
|
|
25958
|
-
const { runCommanderDaemon } = await Promise.resolve().then(() => require("./main-
|
|
26423
|
+
const { runCommanderDaemon } = await Promise.resolve().then(() => require("./main-BBRM0ZOp.cjs"));
|
|
25959
26424
|
return runCommanderDaemon(argv.slice(1));
|
|
25960
26425
|
}
|
|
25961
26426
|
const parsed = parseCliArgs(argv);
|
|
@@ -25980,6 +26445,7 @@ async function main() {
|
|
|
25980
26445
|
out: createOut(parsed),
|
|
25981
26446
|
config
|
|
25982
26447
|
};
|
|
26448
|
+
if (parsed.positionals.some((term) => term.startsWith("@"))) ctx.pins = await readSavedFilters(commanderStatePaths(resolveCommanderDataDir(), config.configKey).savedFiltersPath);
|
|
25983
26449
|
const code = await withTimeout(ctx, command(ctx));
|
|
25984
26450
|
if (ctx.spawnedDaemon === true) process.exit(code);
|
|
25985
26451
|
return code;
|
|
@@ -26023,20 +26489,26 @@ exports.createRealmServerEngine = createRealmServerEngine;
|
|
|
26023
26489
|
exports.effectiveEnv = effectiveEnv;
|
|
26024
26490
|
exports.ensureStateDir = ensureStateDir;
|
|
26025
26491
|
exports.envVarViews = envVarViews;
|
|
26492
|
+
exports.hashCanonical = hashCanonical;
|
|
26026
26493
|
exports.httpAcceptorCarrier = httpAcceptorCarrier;
|
|
26027
26494
|
exports.loadCommanderConfigFile = loadCommanderConfigFile;
|
|
26495
|
+
exports.mutateSavedFilters = mutateSavedFilters;
|
|
26028
26496
|
exports.orderByDependency = orderByDependency;
|
|
26029
26497
|
exports.overrideFingerprint = overrideFingerprint;
|
|
26030
26498
|
exports.parseLogsClientMessage = parseLogsClientMessage;
|
|
26031
26499
|
exports.readEnvOverrides = readEnvOverrides;
|
|
26032
26500
|
exports.readInstanceRecord = readInstanceRecord;
|
|
26501
|
+
exports.readSavedFilters = readSavedFilters;
|
|
26033
26502
|
exports.recordDaemonAlive = recordDaemonAlive;
|
|
26034
26503
|
exports.removeInstanceRecord = removeInstanceRecord;
|
|
26035
26504
|
exports.resolveCommanderDataDir = resolveCommanderDataDir;
|
|
26505
|
+
exports.runTaskPool = runTaskPool;
|
|
26506
|
+
exports.savedFilterId = savedFilterId;
|
|
26036
26507
|
exports.serveChannel = serveChannel;
|
|
26037
26508
|
exports.validateCommanderConfig = validateCommanderConfig;
|
|
26038
26509
|
exports.withDependencies = withDependencies;
|
|
26039
26510
|
exports.writeInstanceRecord = writeInstanceRecord;
|
|
26511
|
+
exports.writeSavedFilters = writeSavedFilters;
|
|
26040
26512
|
exports.wsAcceptorCarrier = wsAcceptorCarrier;
|
|
26041
26513
|
|
|
26042
26514
|
//# sourceMappingURL=cli.cjs.map
|