@nice-code/commander 0.95.0 → 0.97.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 +900 -398
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +894 -399
- package/build/cli.mjs.map +1 -1
- package/build/client/assets/index-BEawHnvQ.css +1 -0
- package/build/client/assets/index-eogxmN5c.js +23 -0
- package/build/client/assets/index-eogxmN5c.js.map +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-BlAdEbVt.mjs → main-BBH2T2OI.mjs} +219 -10
- package/build/main-BBH2T2OI.mjs.map +1 -0
- package/build/{main-B7EwREFQ.cjs → main-Xo-6rWk6.cjs} +218 -9
- package/build/main-Xo-6rWk6.cjs.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-0MrLSa7o.css +0 -1
- package/build/client/assets/index-DvDRKmj5.js +0 -23
- package/build/client/assets/index-DvDRKmj5.js.map +0 -1
- package/build/main-B7EwREFQ.cjs.map +0 -1
- package/build/main-BlAdEbVt.mjs.map +0 -1
package/build/cli.mjs
CHANGED
|
@@ -12,10 +12,10 @@ import { createRequire as createRequire$1 } from "module";
|
|
|
12
12
|
import { WebSocket as WebSocket$1 } from "ws";
|
|
13
13
|
import { homedir, networkInterfaces } from "node:os";
|
|
14
14
|
import { execFile, spawn } from "node:child_process";
|
|
15
|
-
import {
|
|
15
|
+
import { connect } from "node:net";
|
|
16
16
|
import { lookup } from "node:dns/promises";
|
|
17
17
|
import { promisify } from "node:util";
|
|
18
|
-
import {
|
|
18
|
+
import { createInterface } from "node:readline/promises";
|
|
19
19
|
//#region \0rolldown/runtime.js
|
|
20
20
|
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
21
21
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
@@ -152,7 +152,7 @@ function validStartStamp(value) {
|
|
|
152
152
|
function isInstanceRecord(value) {
|
|
153
153
|
if (value == null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
154
154
|
const record = value;
|
|
155
|
-
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 ===
|
|
155
|
+
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;
|
|
156
156
|
}
|
|
157
157
|
async function writeInstanceRecord(path, record) {
|
|
158
158
|
await mkdir(dirname(path), {
|
|
@@ -202,7 +202,7 @@ async function readSkewedInstanceRecord(path, expectedRealmSchemaHash) {
|
|
|
202
202
|
if (!boundedInt(record["protocolVersion"], 0, Number.MAX_SAFE_INTEGER)) return null;
|
|
203
203
|
if (!boundedInt(record["pid"], 1, Number.MAX_SAFE_INTEGER)) return null;
|
|
204
204
|
if (!boundedInt(record["port"], 1, 65535)) return null;
|
|
205
|
-
const sameProtocol = record["protocolVersion"] ===
|
|
205
|
+
const sameProtocol = record["protocolVersion"] === 6;
|
|
206
206
|
const sameRealm = boundedString(record["realmSchemaHash"]) && record["realmSchemaHash"] === expectedRealmSchemaHash;
|
|
207
207
|
if (sameProtocol && sameRealm) return null;
|
|
208
208
|
return {
|
|
@@ -299,6 +299,102 @@ async function pingDaemon(record, timeoutMs = 2e3) {
|
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
301
|
//#endregion
|
|
302
|
+
//#region src/config/tags.ts
|
|
303
|
+
/** `key=value` → `[key, value]`, or null when the term is not tag-shaped. */
|
|
304
|
+
function parseTagTerm(term) {
|
|
305
|
+
const eq = term.indexOf("=");
|
|
306
|
+
return eq > 0 ? [term.slice(0, eq), term.slice(eq + 1)] : null;
|
|
307
|
+
}
|
|
308
|
+
function hasTag(tags, key, value) {
|
|
309
|
+
return tags[key]?.includes(value) === true;
|
|
310
|
+
}
|
|
311
|
+
/** Every entry must match (AND). */
|
|
312
|
+
function matchesTagQuery(tags, query) {
|
|
313
|
+
return Object.entries(query).every(([key, value]) => hasTag(tags, key, value));
|
|
314
|
+
}
|
|
315
|
+
/** Every `key=value` a process carries, in key order. */
|
|
316
|
+
function tagTermsOf(tags) {
|
|
317
|
+
return Object.entries(tags).flatMap(([key, values]) => values.map((value) => `${key}=${value}`));
|
|
318
|
+
}
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region src/config/tagGroups.ts
|
|
321
|
+
/** Which of `terms` these tags carry, in `terms` order. */
|
|
322
|
+
function tagSignature(tags, terms) {
|
|
323
|
+
return terms.filter((term) => {
|
|
324
|
+
const parsed = parseTagTerm(term);
|
|
325
|
+
return parsed != null && tags[parsed[0]]?.includes(parsed[1]) === true;
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Bucket by signature: most matched terms first, then by where the signature's terms sit in the
|
|
330
|
+
* filter — never by anything live, so buckets hold still while processes change state. In `any`
|
|
331
|
+
* mode the first bucket is the `all` result whenever anything matches every term.
|
|
332
|
+
*/
|
|
333
|
+
function tagGroupsFor(items, terms, mode) {
|
|
334
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
335
|
+
for (const item of items) {
|
|
336
|
+
const signature = tagSignature(item.tags, terms);
|
|
337
|
+
if (signature.length === 0 || mode === "all" && signature.length < terms.length) continue;
|
|
338
|
+
const key = signature.join(",");
|
|
339
|
+
const bucket = buckets.get(key) ?? {
|
|
340
|
+
signature,
|
|
341
|
+
members: []
|
|
342
|
+
};
|
|
343
|
+
bucket.members.push(item);
|
|
344
|
+
buckets.set(key, bucket);
|
|
345
|
+
}
|
|
346
|
+
const rank = (group) => group.signature.map((term) => terms.indexOf(term));
|
|
347
|
+
return [...buckets.values()].sort((a, b) => {
|
|
348
|
+
if (a.signature.length !== b.signature.length) return b.signature.length - a.signature.length;
|
|
349
|
+
const [ra, rb] = [rank(a), rank(b)];
|
|
350
|
+
for (let i = 0; i < ra.length; i += 1) if (ra[i] !== rb[i]) return (ra[i] ?? 0) - (rb[i] ?? 0);
|
|
351
|
+
return 0;
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
function sameSignature(a, b) {
|
|
355
|
+
return a.length === b.length && a.every((term) => b.includes(term));
|
|
356
|
+
}
|
|
357
|
+
function savedFilterId(query) {
|
|
358
|
+
const terms = [...query.terms].sort();
|
|
359
|
+
const bucket = query.bucket == null ? "" : `|${[...query.bucket].sort().join(",")}`;
|
|
360
|
+
return `${query.mode}:${terms.join(",")}${bucket}`;
|
|
361
|
+
}
|
|
362
|
+
/** The members a saved filter selects right now. `optIn` processes are never bulk members. */
|
|
363
|
+
function savedFilterMembers(query, items) {
|
|
364
|
+
const groups = tagGroupsFor(items.filter((item) => !item.optIn), [...query.terms].sort(), query.mode);
|
|
365
|
+
const bucket = query.bucket;
|
|
366
|
+
return (bucket == null ? groups : groups.filter((group) => sameSignature(group.signature, bucket))).flatMap((group) => group.members);
|
|
367
|
+
}
|
|
368
|
+
function asTerms(value) {
|
|
369
|
+
if (!Array.isArray(value) || value.length === 0 || value.length > 16) return null;
|
|
370
|
+
const terms = [];
|
|
371
|
+
for (const entry of value) {
|
|
372
|
+
if (typeof entry !== "string" || entry.length > 512 || parseTagTerm(entry) == null) return null;
|
|
373
|
+
if (!terms.includes(entry)) terms.push(entry);
|
|
374
|
+
}
|
|
375
|
+
return terms.sort();
|
|
376
|
+
}
|
|
377
|
+
/** The one place an untrusted value (the wire, or the file) becomes a query. */
|
|
378
|
+
function checkSavedFilterQuery(value) {
|
|
379
|
+
if (value == null || typeof value !== "object" || Array.isArray(value)) return "expected an object";
|
|
380
|
+
const record = { ...value };
|
|
381
|
+
const mode = record["mode"];
|
|
382
|
+
if (mode !== "all" && mode !== "any") return "mode: expected \"all\" | \"any\"";
|
|
383
|
+
const terms = asTerms(record["terms"]);
|
|
384
|
+
if (terms == null) return `terms: expected 1–16 tag=value strings`;
|
|
385
|
+
if (record["bucket"] == null) return {
|
|
386
|
+
mode,
|
|
387
|
+
terms
|
|
388
|
+
};
|
|
389
|
+
const bucket = asTerms(record["bucket"]);
|
|
390
|
+
if (bucket == null || !bucket.every((term) => terms.includes(term))) return "bucket: expected a subset of terms";
|
|
391
|
+
return {
|
|
392
|
+
mode,
|
|
393
|
+
terms,
|
|
394
|
+
bucket
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
//#endregion
|
|
302
398
|
//#region src/config/resolve.ts
|
|
303
399
|
/** Topological order of the given id set over the dependsOn graph; config order breaks ties. */
|
|
304
400
|
function orderByDependency(processes, ids) {
|
|
@@ -349,43 +445,79 @@ function withDependencies(processes, ids) {
|
|
|
349
445
|
return closed;
|
|
350
446
|
}
|
|
351
447
|
/**
|
|
448
|
+
* What stopping `direct` AND its dependencies may take down. A dependency is kept when a live
|
|
449
|
+
* process outside the stop set still needs it — and keeping one keeps what IT needs, hence the
|
|
450
|
+
* loop. Dependencies that simply are not running are not reported either way.
|
|
451
|
+
*/
|
|
452
|
+
function stopSetWithDependencies(processes, direct, isLive) {
|
|
453
|
+
const stop = withDependencies(processes, direct);
|
|
454
|
+
const kept = [];
|
|
455
|
+
for (let changed = true; changed;) {
|
|
456
|
+
changed = false;
|
|
457
|
+
const needed = withDependencies(processes, processes.filter((proc) => !stop.has(proc.id) && isLive(proc.id)).map((proc) => proc.id));
|
|
458
|
+
for (const id of [...stop]) {
|
|
459
|
+
if (direct.includes(id) || !needed.has(id)) continue;
|
|
460
|
+
stop.delete(id);
|
|
461
|
+
if (isLive(id)) kept.push(id);
|
|
462
|
+
changed = true;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return {
|
|
466
|
+
stop: orderByDependency(processes, stop),
|
|
467
|
+
kept
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
352
471
|
* Resolve CLI/UI selection terms against the model. An empty `terms` is the caller's problem
|
|
353
472
|
* (bare `up` consults `defaultSelection` before ever reaching here).
|
|
354
473
|
*/
|
|
355
|
-
function resolveSelection(config, terms,
|
|
474
|
+
function resolveSelection(config, terms, options = {}) {
|
|
475
|
+
const extraIds = options.extraIds ?? [];
|
|
476
|
+
const bulk = (id) => options.purpose === "address" || config.processes.find((proc) => proc.id === id)?.optIn !== true;
|
|
356
477
|
const errors = [];
|
|
357
478
|
const selectors = /* @__PURE__ */ new Set();
|
|
358
479
|
const tagTerms = [];
|
|
359
480
|
for (const term of terms) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
481
|
+
if (term.startsWith("@")) {
|
|
482
|
+
const pin = options.pins?.find((candidate) => candidate.name === term.slice(1));
|
|
483
|
+
if (pin == null) {
|
|
484
|
+
errors.push(`unknown pin "${term}" (pins are saved from the web UI)`);
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
for (const proc of savedFilterMembers(pin, config.processes)) selectors.add(proc.id);
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
const tagTerm = parseTagTerm(term);
|
|
491
|
+
if (tagTerm != null) {
|
|
492
|
+
tagTerms.push(tagTerm);
|
|
363
493
|
continue;
|
|
364
494
|
}
|
|
365
495
|
if (term === "all") {
|
|
366
|
-
for (const proc of config.processes) selectors.add(proc.id);
|
|
496
|
+
for (const proc of config.processes) if (bulk(proc.id)) selectors.add(proc.id);
|
|
367
497
|
for (const id of extraIds) selectors.add(id);
|
|
368
498
|
continue;
|
|
369
499
|
}
|
|
370
|
-
if (config.
|
|
371
|
-
for (const id of config.
|
|
500
|
+
if (config.suites[term] != null) {
|
|
501
|
+
for (const id of config.suites[term].ids) selectors.add(id);
|
|
372
502
|
continue;
|
|
373
503
|
}
|
|
374
504
|
if (config.processes.some((proc) => proc.id === term) || extraIds.includes(term)) {
|
|
375
505
|
selectors.add(term);
|
|
376
506
|
continue;
|
|
377
507
|
}
|
|
378
|
-
errors.push(`unknown selection "${term}" (not a process id,
|
|
508
|
+
errors.push(`unknown selection "${term}" (not a process id, suite, @pin, tag=value, or "all")`);
|
|
379
509
|
}
|
|
380
510
|
if (errors.length > 0) return {
|
|
381
511
|
ok: false,
|
|
382
512
|
errors
|
|
383
513
|
};
|
|
384
514
|
let direct = [...selectors];
|
|
385
|
-
if (selectors.size === 0 && tagTerms.length > 0) direct = config.processes.map((proc) => proc.id);
|
|
515
|
+
if (selectors.size === 0 && tagTerms.length > 0) direct = config.processes.filter((proc) => bulk(proc.id)).map((proc) => proc.id);
|
|
386
516
|
if (tagTerms.length > 0) direct = direct.filter((id) => {
|
|
387
517
|
const proc = config.processes.find((candidate) => candidate.id === id);
|
|
388
|
-
|
|
518
|
+
if (proc == null) return false;
|
|
519
|
+
const matches = ([key, value]) => hasTag(proc.tags, key, value);
|
|
520
|
+
return options.any === true ? tagTerms.some(matches) : tagTerms.every(matches);
|
|
389
521
|
});
|
|
390
522
|
const closed = withDependencies(config.processes, direct);
|
|
391
523
|
const ordered = orderByDependency(config.processes, closed);
|
|
@@ -652,6 +784,8 @@ function staleOverrides(config, overrides) {
|
|
|
652
784
|
}
|
|
653
785
|
return stale;
|
|
654
786
|
}
|
|
787
|
+
const SUITE_PARALLEL_DEFAULT = 4;
|
|
788
|
+
const SUITE_STAGGER_DEFAULT_MS = 100;
|
|
655
789
|
/** C0/DEL/C1 control characters have no business in tag keys/values or env keys. */
|
|
656
790
|
function hasControlChars(value) {
|
|
657
791
|
for (let i = 0; i < value.length; i += 1) {
|
|
@@ -661,6 +795,7 @@ function hasControlChars(value) {
|
|
|
661
795
|
return false;
|
|
662
796
|
}
|
|
663
797
|
const MAX_TAGS = 32;
|
|
798
|
+
const MAX_TAG_VALUES = 16;
|
|
664
799
|
function isRecord(value) {
|
|
665
800
|
return typeof value === "object" && value != null && !Array.isArray(value);
|
|
666
801
|
}
|
|
@@ -749,8 +884,52 @@ function findCycle(graph) {
|
|
|
749
884
|
}
|
|
750
885
|
return null;
|
|
751
886
|
}
|
|
752
|
-
|
|
753
|
-
|
|
887
|
+
/**
|
|
888
|
+
* Expand `include`/`where`/`exclude` over a set of sibling definitions. A `where` never picks up
|
|
889
|
+
* an `optIn` process; an explicit `include` does. Callers guarantee the reference graph is
|
|
890
|
+
* acyclic; `seen` only keeps a malformed one from recursing forever.
|
|
891
|
+
*/
|
|
892
|
+
function expandSelection(name, inputs, byId, seen = /* @__PURE__ */ new Set()) {
|
|
893
|
+
const out = /* @__PURE__ */ new Set();
|
|
894
|
+
const input = inputs[name];
|
|
895
|
+
if (seen.has(name) || !isRecord(input)) return out;
|
|
896
|
+
seen.add(name);
|
|
897
|
+
const selection = input;
|
|
898
|
+
for (const entry of selection.include ?? []) if (byId.has(entry)) out.add(entry);
|
|
899
|
+
else if (typeof entry === "string" && entry in inputs) for (const id of expandSelection(entry, inputs, byId, seen)) out.add(id);
|
|
900
|
+
for (const query of normalizeTagQueryOr(selection.where) ?? []) for (const proc of byId.values()) if (!proc.optIn && matchesTagQuery(proc.tags, query)) out.add(proc.id);
|
|
901
|
+
const { ids: excludedIds, queries } = normalizeExcludes(selection.exclude);
|
|
902
|
+
for (const id of excludedIds) out.delete(id);
|
|
903
|
+
for (const id of [...out]) {
|
|
904
|
+
const proc = byId.get(id);
|
|
905
|
+
if (proc != null && queries.some((query) => matchesTagQuery(proc.tags, query))) out.delete(id);
|
|
906
|
+
}
|
|
907
|
+
seen.delete(name);
|
|
908
|
+
return out;
|
|
909
|
+
}
|
|
910
|
+
/** The tag selection that picks out exactly `ids`, if one exists — smallest first. */
|
|
911
|
+
function equivalentTagSelection(ids, byId) {
|
|
912
|
+
const [first, ...rest] = [...ids].flatMap((id) => byId.get(id) ?? []);
|
|
913
|
+
if (first == null) return null;
|
|
914
|
+
const common = tagTermsOf(first.tags).filter((term) => rest.every((proc) => tagTermsOf(proc.tags).includes(term)));
|
|
915
|
+
const selects = (terms) => {
|
|
916
|
+
const matched = [...byId.values()].filter((proc) => !proc.optIn && terms.every((term) => tagTermsOf(proc.tags).includes(term)));
|
|
917
|
+
return matched.length === ids.size && matched.every((proc) => ids.has(proc.id));
|
|
918
|
+
};
|
|
919
|
+
for (const term of common) if (selects([term])) return [term];
|
|
920
|
+
return common.length > 1 && selects(common) ? common : null;
|
|
921
|
+
}
|
|
922
|
+
/** `groups` was removed — say what each one becomes instead of just refusing the key. */
|
|
923
|
+
function groupMigrationErrors(groupsInput, byId) {
|
|
924
|
+
const errors = ["groups: removed — processes are organised by tags, and a run-unit is a `suite`. Per group:"];
|
|
925
|
+
for (const name of Object.keys(groupsInput)) {
|
|
926
|
+
const ids = expandSelection(name, groupsInput, byId);
|
|
927
|
+
const tagSelection = equivalentTagSelection(ids, byId);
|
|
928
|
+
if (ids.size < 2) errors.push(`groups.${name}: one member — delete it and use the id "${[...ids][0] ?? "?"}" directly`);
|
|
929
|
+
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`);
|
|
930
|
+
else errors.push(`groups.${name}: move it under \`suites\` unchanged`);
|
|
931
|
+
}
|
|
932
|
+
return errors;
|
|
754
933
|
}
|
|
755
934
|
/**
|
|
756
935
|
* Validate a raw loaded config and build the resolved model. `configDir`/`configPath` are the
|
|
@@ -832,16 +1011,25 @@ function validateCommanderConfig(raw, anchor) {
|
|
|
832
1011
|
if (resolved != null) envVars.push(resolved);
|
|
833
1012
|
}
|
|
834
1013
|
for (const declared of envVars) if (declared.default != null) env[declared.name] = declared.default;
|
|
835
|
-
const
|
|
1014
|
+
const tagEntries = Object.entries({
|
|
836
1015
|
...config.defaults?.tags,
|
|
837
1016
|
...proc.tags
|
|
838
|
-
};
|
|
839
|
-
const tagEntries = Object.entries(tags);
|
|
1017
|
+
});
|
|
840
1018
|
if (tagEntries.length > MAX_TAGS) errors.push(`${at}.tags: ${tagEntries.length} entries exceeds the ${MAX_TAGS} bound`);
|
|
1019
|
+
const tags = {};
|
|
841
1020
|
for (const [key, value] of tagEntries) {
|
|
842
|
-
if (key === "" || key.length > 64 || hasControlChars(key)) errors.push(`${at}.tags: invalid key ${JSON.stringify(key)}`);
|
|
843
|
-
|
|
1021
|
+
if (key === "" || key.length > 64 || key.includes("=") || hasControlChars(key)) errors.push(`${at}.tags: invalid key ${JSON.stringify(key)}`);
|
|
1022
|
+
const values = typeof value === "string" ? [value] : value;
|
|
1023
|
+
if (!Array.isArray(values) || values.length === 0 || values.length > MAX_TAG_VALUES) {
|
|
1024
|
+
errors.push(`${at}.tags[${JSON.stringify(key)}]: expected a string or 1–${MAX_TAG_VALUES} strings`);
|
|
1025
|
+
continue;
|
|
1026
|
+
}
|
|
1027
|
+
const clean = [];
|
|
1028
|
+
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`);
|
|
1029
|
+
else if (!clean.includes(entry)) clean.push(entry);
|
|
1030
|
+
tags[key] = clean;
|
|
844
1031
|
}
|
|
1032
|
+
if (proc.optIn != null && typeof proc.optIn !== "boolean") errors.push(`${at}.optIn: expected a boolean`);
|
|
845
1033
|
const endpoints = [];
|
|
846
1034
|
const endpointNames = /* @__PURE__ */ new Set();
|
|
847
1035
|
for (const [endpointIndex, endpoint] of (proc.endpoints ?? []).entries()) {
|
|
@@ -926,6 +1114,7 @@ function validateCommanderConfig(raw, anchor) {
|
|
|
926
1114
|
envVars,
|
|
927
1115
|
stdin,
|
|
928
1116
|
tags,
|
|
1117
|
+
optIn: proc.optIn === true,
|
|
929
1118
|
dependsOn,
|
|
930
1119
|
endpoints,
|
|
931
1120
|
...proc.url != null ? { url: proc.url } : {},
|
|
@@ -943,60 +1132,57 @@ function validateCommanderConfig(raw, anchor) {
|
|
|
943
1132
|
for (const [id, deps] of dependsGraph) for (const dep of deps) if (!byId.has(dep)) errors.push(`process "${id}" dependsOn: unknown id "${dep}"`);
|
|
944
1133
|
const processCycle = findCycle(dependsGraph);
|
|
945
1134
|
if (processCycle != null) errors.push(`dependsOn cycle: ${processCycle.join(" → ")}`);
|
|
946
|
-
const
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
1135
|
+
const removedGroups = raw.groups;
|
|
1136
|
+
if (removedGroups != null) errors.push(...groupMigrationErrors(isRecord(removedGroups) ? removedGroups : {}, byId));
|
|
1137
|
+
const suitesInput = isRecord(config.suites) ? config.suites : {};
|
|
1138
|
+
if (config.suites != null && !isRecord(config.suites)) errors.push("suites: expected an object keyed by suite name");
|
|
1139
|
+
const suiteRefs = /* @__PURE__ */ new Map();
|
|
1140
|
+
for (const [name, suite] of Object.entries(suitesInput)) {
|
|
1141
|
+
const at = `suites.${name}`;
|
|
1142
|
+
if (!COMMANDER_ID_PATTERN.test(name)) errors.push(`suites.${JSON.stringify(name)}: must match ${COMMANDER_ID_PATTERN}`);
|
|
1143
|
+
if (name === "all") errors.push(`${at}: "all" is the built-in selector`);
|
|
1144
|
+
if (byId.has(name)) errors.push(`${at}: collides with a process id`);
|
|
1145
|
+
if (!isRecord(suite)) {
|
|
1146
|
+
errors.push(`${at}: expected an object`);
|
|
954
1147
|
continue;
|
|
955
1148
|
}
|
|
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
|
-
|
|
982
|
-
const proc = byId.get(id);
|
|
983
|
-
if (proc != null && queries.some((query) => matchesTags(proc.tags, query))) out.delete(id);
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
seen.delete(name);
|
|
987
|
-
return out;
|
|
988
|
-
};
|
|
989
|
-
for (const name of Object.keys(groupsInput)) {
|
|
990
|
-
const expanded = expand(name, /* @__PURE__ */ new Set());
|
|
991
|
-
const ordered = [...byId.keys()].filter((id) => expanded.has(id));
|
|
992
|
-
if (ordered.length === 0) warnings.push(`groups.${name}: expands to zero processes`);
|
|
993
|
-
const staggerMs = groupsInput[name]?.staggerMs;
|
|
994
|
-
groups[name] = {
|
|
995
|
-
name,
|
|
996
|
-
ids: ordered,
|
|
997
|
-
staggerMs: typeof staggerMs === "number" ? staggerMs : 100
|
|
998
|
-
};
|
|
1149
|
+
const definition = suite;
|
|
1150
|
+
if (definition.description != null && typeof definition.description !== "string") errors.push(`${at}.description: expected a string`);
|
|
1151
|
+
if (definition.parallel != null && (!Number.isInteger(definition.parallel) || definition.parallel < 1)) errors.push(`${at}.parallel: expected an integer ≥ 1`);
|
|
1152
|
+
if (definition.failFast != null && typeof definition.failFast !== "boolean") errors.push(`${at}.failFast: expected a boolean`);
|
|
1153
|
+
if (definition.staggerMs != null && (typeof definition.staggerMs !== "number" || definition.staggerMs < 0)) errors.push(`${at}.staggerMs: expected a non-negative number`);
|
|
1154
|
+
for (const entry of definition.include ?? []) if (typeof entry !== "string") errors.push(`${at}.include: expected id/suite strings`);
|
|
1155
|
+
else if (!byId.has(entry) && !(entry in suitesInput)) errors.push(`${at}.include: unknown id or suite "${entry}"`);
|
|
1156
|
+
const { ids: excludedIds, queries: excludeQueries } = normalizeExcludes(definition.exclude);
|
|
1157
|
+
for (const id of excludedIds) if (!byId.has(id)) errors.push(`${at}.exclude: unknown id "${id}"`);
|
|
1158
|
+
for (const query of [...normalizeTagQueryOr(definition.where) ?? [], ...excludeQueries]) {
|
|
1159
|
+
if (Object.keys(query).length === 0) warnings.push(`${at}: an empty tag query matches everything`);
|
|
1160
|
+
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`);
|
|
1161
|
+
}
|
|
1162
|
+
suiteRefs.set(name, (definition.include ?? []).filter((entry) => typeof entry === "string" && entry in suitesInput));
|
|
1163
|
+
}
|
|
1164
|
+
const suiteCycle = findCycle(suiteRefs);
|
|
1165
|
+
if (suiteCycle != null) errors.push(`suite include cycle: ${suiteCycle.join(" → ")}`);
|
|
1166
|
+
const suites = {};
|
|
1167
|
+
if (suiteCycle == null) for (const [name, suite] of Object.entries(suitesInput)) {
|
|
1168
|
+
if (!isRecord(suite)) continue;
|
|
1169
|
+
const definition = suite;
|
|
1170
|
+
const expanded = expandSelection(name, suitesInput, byId);
|
|
1171
|
+
const ordered = [...byId.keys()].filter((id) => expanded.has(id));
|
|
1172
|
+
if (ordered.length < 2) {
|
|
1173
|
+
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`);
|
|
1174
|
+
continue;
|
|
999
1175
|
}
|
|
1176
|
+
const tagSelection = Object.keys(definition).every((key) => key === "where") ? equivalentTagSelection(expanded, byId) : null;
|
|
1177
|
+
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`);
|
|
1178
|
+
suites[name] = {
|
|
1179
|
+
name,
|
|
1180
|
+
...typeof definition.description === "string" ? { description: definition.description } : {},
|
|
1181
|
+
ids: ordered,
|
|
1182
|
+
parallel: definition.parallel ?? SUITE_PARALLEL_DEFAULT,
|
|
1183
|
+
failFast: definition.failFast === true,
|
|
1184
|
+
staggerMs: definition.staggerMs ?? SUITE_STAGGER_DEFAULT_MS
|
|
1185
|
+
};
|
|
1000
1186
|
}
|
|
1001
1187
|
const portClaims = /* @__PURE__ */ new Map();
|
|
1002
1188
|
for (const proc of byId.values()) for (const ep of proc.endpoints) {
|
|
@@ -1017,7 +1203,7 @@ function validateCommanderConfig(raw, anchor) {
|
|
|
1017
1203
|
}
|
|
1018
1204
|
if (config.defaultSelection != null) {
|
|
1019
1205
|
const selection = config.defaultSelection;
|
|
1020
|
-
if (!byId.has(selection) && !(selection in
|
|
1206
|
+
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`);
|
|
1021
1207
|
}
|
|
1022
1208
|
const watchFiles = [anchor.configPath];
|
|
1023
1209
|
for (const file of config.watchFiles ?? []) {
|
|
@@ -1037,7 +1223,7 @@ function validateCommanderConfig(raw, anchor) {
|
|
|
1037
1223
|
const resolvedBase = {
|
|
1038
1224
|
name,
|
|
1039
1225
|
processes,
|
|
1040
|
-
|
|
1226
|
+
suites,
|
|
1041
1227
|
defaultSelection: config.defaultSelection,
|
|
1042
1228
|
daemon: { port: typeof config.daemon?.port === "number" ? config.daemon.port : 4900 }
|
|
1043
1229
|
};
|
|
@@ -1097,7 +1283,7 @@ async function loadConfigOrExit(configPath) {
|
|
|
1097
1283
|
*/
|
|
1098
1284
|
function requireSelectionTerms(ctx) {
|
|
1099
1285
|
if (ctx.args.positionals.length > 0 || ctx.args.flags.get("--all") === true) return;
|
|
1100
|
-
throw new CliExit(EXIT.usage, `${ctx.args.command} requires a selection (ids,
|
|
1286
|
+
throw new CliExit(EXIT.usage, `${ctx.args.command} requires a selection (ids, suite, @pin, tag=val) or --all`);
|
|
1101
1287
|
}
|
|
1102
1288
|
function selectOrExit(ctx, options) {
|
|
1103
1289
|
const { args, config } = ctx;
|
|
@@ -1105,19 +1291,24 @@ function selectOrExit(ctx, options) {
|
|
|
1105
1291
|
if (args.flags.get("--all") === true) terms = [...terms, "all"];
|
|
1106
1292
|
if (terms.length === 0) if (options.bare === "default" && config.defaultSelection != null) terms = [config.defaultSelection];
|
|
1107
1293
|
else if (options.bare === "default") {
|
|
1108
|
-
const
|
|
1109
|
-
throw new CliExit(EXIT.usage, `bare ${args.command}: the config has no defaultSelection.
|
|
1294
|
+
const suites = Object.keys(config.suites);
|
|
1295
|
+
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`);
|
|
1110
1296
|
} else requireSelectionTerms(ctx);
|
|
1111
|
-
const result = resolveSelection(config, terms,
|
|
1297
|
+
const result = resolveSelection(config, terms, {
|
|
1298
|
+
extraIds: options.extraIds ?? [],
|
|
1299
|
+
any: args.flags.get("--any") === true,
|
|
1300
|
+
purpose: args.command === "down" || args.command === "logs" ? "address" : "start",
|
|
1301
|
+
pins: ctx.pins ?? []
|
|
1302
|
+
});
|
|
1112
1303
|
if (!result.ok) throw new CliExit(EXIT.usage, result.errors.join("\n"));
|
|
1113
1304
|
return result.selection;
|
|
1114
1305
|
}
|
|
1115
|
-
/**
|
|
1306
|
+
/** Suite stagger for a start: the widest stagger among the suites named in the terms. */
|
|
1116
1307
|
function staggerFor(config, terms) {
|
|
1117
1308
|
let stagger = 0;
|
|
1118
1309
|
for (const term of terms) {
|
|
1119
|
-
const
|
|
1120
|
-
if (
|
|
1310
|
+
const suite = config.suites[term];
|
|
1311
|
+
if (suite != null) stagger = Math.max(stagger, suite.staggerMs);
|
|
1121
1312
|
}
|
|
1122
1313
|
return stagger;
|
|
1123
1314
|
}
|
|
@@ -5163,7 +5354,7 @@ function reject(reason, id) {
|
|
|
5163
5354
|
/**
|
|
5164
5355
|
* The machine-readable reject id an untrusted verify key produces: the presented key differs from
|
|
5165
5356
|
* the one pinned for this client identity (trust-on-first-use). Carried on the reject frame's `id`
|
|
5166
|
-
* and surfaced to the dialing side as `
|
|
5357
|
+
* and surfaced to the dialing side as `err_wire_connect` id `identity_pin_mismatch`, so an app can
|
|
5167
5358
|
* branch on it (`err.hasId("identity_pin_mismatch")`) — the obvious recovery being "this identity
|
|
5168
5359
|
* is unusable with this key: clear the client's identity storage / mint a new persistent id".
|
|
5169
5360
|
*/
|
|
@@ -5833,6 +6024,9 @@ dropLink: async (opts) => {
|
|
|
5833
6024
|
* Close any live long-lived connection (e.g. a WebSocket) before dropping it, so a teardown
|
|
5834
6025
|
* actually releases the socket instead of leaving it open until GC. HTTP/stateless transports
|
|
5835
6026
|
* don't implement `disconnect`, so they're simply forgotten.
|
|
6027
|
+
*
|
|
6028
|
+
* @internal Bare cache drop with no redial suppression. Apps call {@link clearTransportCache} or
|
|
6029
|
+
* {@link releaseLink} instead.
|
|
5836
6030
|
*/
|
|
5837
6031
|
clearCache() {
|
|
5838
6032
|
for (const entry of this._cache.values()) if (entry instanceof Promise) entry.then((ready) => ready.methods.disconnect?.()).catch(() => {});
|
|
@@ -10202,6 +10396,34 @@ var ReliableLog = class {
|
|
|
10202
10396
|
}
|
|
10203
10397
|
return prefix;
|
|
10204
10398
|
}
|
|
10399
|
+
/**
|
|
10400
|
+
* {@link contiguousPrefix} with each payload's `seq` attached, optionally only the entries after
|
|
10401
|
+
* `afterSeq`. Pruned or compacted seqs are absent, so the first entry's `seq` says where the stored
|
|
10402
|
+
* history now starts.
|
|
10403
|
+
*/
|
|
10404
|
+
contiguousEntries(streamId, afterSeq = -1) {
|
|
10405
|
+
const highWater = this._store.getHighWater(streamId);
|
|
10406
|
+
const entries = [];
|
|
10407
|
+
for (let seq = Math.max(afterSeq + 1, 0); seq <= highWater; seq++) {
|
|
10408
|
+
const raw = this._store.getPayload(streamId, seq);
|
|
10409
|
+
if (raw != null) entries.push({
|
|
10410
|
+
seq,
|
|
10411
|
+
payload: this._deserialize(raw)
|
|
10412
|
+
});
|
|
10413
|
+
}
|
|
10414
|
+
return entries;
|
|
10415
|
+
}
|
|
10416
|
+
/**
|
|
10417
|
+
* Delete a stream's stored frames with `seq <= through` (the replay recipe's prune, once the consumer
|
|
10418
|
+
* confirmed them). Clamped to the high-water, so a too-large `through` never touches undelivered frames.
|
|
10419
|
+
* Returns `false` when the store has no `deleteThrough` and nothing was pruned.
|
|
10420
|
+
*/
|
|
10421
|
+
pruneThrough(streamId, through) {
|
|
10422
|
+
if (this._store.deleteThrough == null) return false;
|
|
10423
|
+
const clamped = Math.min(through, this._store.getHighWater(streamId));
|
|
10424
|
+
if (clamped >= 0) this._store.deleteThrough(streamId, clamped);
|
|
10425
|
+
return true;
|
|
10426
|
+
}
|
|
10205
10427
|
};
|
|
10206
10428
|
/**
|
|
10207
10429
|
* An in-memory {@link IReliableLogStore} — used by tests to stand in for a Durable Object's SQL storage. It
|
|
@@ -10212,7 +10434,7 @@ var ReliableLog = class {
|
|
|
10212
10434
|
function createMemoryReliableLogStore() {
|
|
10213
10435
|
const frames = /* @__PURE__ */ new Map();
|
|
10214
10436
|
const highWater = /* @__PURE__ */ new Map();
|
|
10215
|
-
const key = (streamId, seq) => `${streamId}
|
|
10437
|
+
const key = (streamId, seq) => `${streamId}\u0000${seq}`;
|
|
10216
10438
|
return {
|
|
10217
10439
|
insertIgnore: (streamId, seq, payload) => {
|
|
10218
10440
|
const k = key(streamId, seq);
|
|
@@ -10226,7 +10448,7 @@ function createMemoryReliableLogStore() {
|
|
|
10226
10448
|
for (let seq = 0; seq <= through; seq++) frames.delete(key(streamId, seq));
|
|
10227
10449
|
},
|
|
10228
10450
|
deleteStream: (streamId) => {
|
|
10229
|
-
const prefix = `${streamId}
|
|
10451
|
+
const prefix = `${streamId}\u0000`;
|
|
10230
10452
|
for (const k of frames.keys()) if (k.startsWith(prefix)) frames.delete(k);
|
|
10231
10453
|
highWater.delete(streamId);
|
|
10232
10454
|
}
|
|
@@ -15113,7 +15335,7 @@ var ChannelAcceptor = class ChannelAcceptor extends PeerLink {
|
|
|
15113
15335
|
this._sendPayload(connection, action, runtime.coordinate);
|
|
15114
15336
|
runningAction._completeWithResult(action.successResult(void 0));
|
|
15115
15337
|
} catch (err) {
|
|
15116
|
-
runningAction._abort(err);
|
|
15338
|
+
runningAction._abort(this._pushSendError(action.id, err));
|
|
15117
15339
|
}
|
|
15118
15340
|
return runningAction;
|
|
15119
15341
|
}
|
|
@@ -15126,10 +15348,19 @@ var ChannelAcceptor = class ChannelAcceptor extends PeerLink {
|
|
|
15126
15348
|
try {
|
|
15127
15349
|
this._sendPayload(connection, action, runtime.coordinate);
|
|
15128
15350
|
} catch (err) {
|
|
15129
|
-
runningAction._abort(err);
|
|
15351
|
+
runningAction._abort(this._pushSendError(action.id, err));
|
|
15130
15352
|
}
|
|
15131
15353
|
return runningAction;
|
|
15132
15354
|
}
|
|
15355
|
+
/** A failed push send as a typed `send_failed`, keeping the carrier's error as the origin. */
|
|
15356
|
+
_pushSendError(actionId, cause) {
|
|
15357
|
+
if (err_nice_transport.isExact(cause)) return cause;
|
|
15358
|
+
return err_nice_transport.fromId("send_failed", {
|
|
15359
|
+
actionId,
|
|
15360
|
+
actionState: "request",
|
|
15361
|
+
message: cause instanceof Error ? cause.message : String(cause)
|
|
15362
|
+
}).withOriginError(cause);
|
|
15363
|
+
}
|
|
15133
15364
|
/** Encode + send one payload; returns the encoded frame's size so a logger can report it. */
|
|
15134
15365
|
_sendPayload(connection, payload, localClient, reliability) {
|
|
15135
15366
|
const encoding = this._connEncoding.get(connection) ?? "binary";
|
|
@@ -16006,8 +16237,10 @@ function deriveDictionaryVersion(domains) {
|
|
|
16006
16237
|
* Declare a transport-agnostic channel by role — the single source of truth both peers share. Each end
|
|
16007
16238
|
* MUST call this with the same domains in the same order (the binary wire dictionary is positional); the
|
|
16008
16239
|
* `dictionaryVersion` is derived from those domains unless you pin an explicit one. The wire dictionary
|
|
16009
|
-
* spans `[...toAcceptor, ...toConnector]` in that order
|
|
16010
|
-
*
|
|
16240
|
+
* spans `[...toAcceptor, ...toConnector]` in that order. Any change to the domains or their actions moves
|
|
16241
|
+
* the derived version, and the handshake rejects a peer whose version differs, so deploy both ends
|
|
16242
|
+
* together. Appending stays compatible with older peers only under a hand-pinned `dictionaryVersion`
|
|
16243
|
+
* you leave unchanged, and only when the additions come last in the whole dictionary.
|
|
16011
16244
|
*
|
|
16012
16245
|
* Declare the domains *by role* — `toAcceptor` (connector→acceptor requests) and `toConnector`
|
|
16013
16246
|
* (acceptor→connector pushes) — so the routing for both ends is derived from the channel (see
|
|
@@ -16710,7 +16943,7 @@ function serveChannel(runtime, channel, options) {
|
|
|
16710
16943
|
const pushToClient = (target, request, pushOptions) => {
|
|
16711
16944
|
if (disposed) throw new Error("serveChannel: server disposed");
|
|
16712
16945
|
const owner = target instanceof RuntimeCoordinate ? acceptors.find((acceptor) => acceptor.ownsLiveConnectionFor(target)) : acceptors.find((acceptor) => acceptor.hasConnection(target));
|
|
16713
|
-
if (owner == null) throw
|
|
16946
|
+
if (owner == null) throw err_nice_transport.fromId("not_found", { actionId: target instanceof RuntimeCoordinate ? target.stringId : "push-target-connection" });
|
|
16714
16947
|
return owner.pushToClient(runtime, target, request, pushOptions);
|
|
16715
16948
|
};
|
|
16716
16949
|
const broadcast = (makeRequest, broadcastOptions) => {
|
|
@@ -18672,11 +18905,11 @@ const err_realm = err_nice.createChildDomain({
|
|
|
18672
18905
|
message: ({ lastKnownVersion, oldestReplayable }) => `Version ${lastKnownVersion} is behind the replayable window (oldest ${oldestReplayable}) — full rehydration required.`,
|
|
18673
18906
|
context: { required: true }
|
|
18674
18907
|
}),
|
|
18675
|
-
/** A
|
|
18676
|
-
*
|
|
18677
|
-
*
|
|
18908
|
+
/** A write or intent made before the first hydrate is queued for it; this is the queued
|
|
18909
|
+
* handle's rejection when that hydrate never came (the realm detached, or `pendingExpiryMs`
|
|
18910
|
+
* passed first). Definite: nothing was sent. A refused attach rejects with the attach error. */
|
|
18678
18911
|
write_before_hydrate: err({
|
|
18679
|
-
message: ({ realmId }) => `
|
|
18912
|
+
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.`,
|
|
18680
18913
|
context: { required: true }
|
|
18681
18914
|
}),
|
|
18682
18915
|
/**
|
|
@@ -19837,7 +20070,7 @@ const DEFAULT_PROBE_REPLY_TIMEOUT_MS = 1e4;
|
|
|
19837
20070
|
function connectRealm(realm, options) {
|
|
19838
20071
|
const coordinate = options.connection.coordinate;
|
|
19839
20072
|
const persistentId = options.avatar.persistentId ?? coordinate?.perId;
|
|
19840
|
-
if (persistentId == null) throw new Error("connectRealm: no avatar identity —
|
|
20073
|
+
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.");
|
|
19841
20074
|
const avatar = {
|
|
19842
20075
|
type: options.avatar.type,
|
|
19843
20076
|
persistentId,
|
|
@@ -19878,8 +20111,10 @@ function connectRealm(realm, options) {
|
|
|
19878
20111
|
if (next === "live") hasBeenLive = true;
|
|
19879
20112
|
for (const listener of [...statusListeners]) listener(next, { hasBeenLive });
|
|
19880
20113
|
devtools?.onStatus?.(next, { hasBeenLive });
|
|
20114
|
+
if (next === "detached") rejectHydrateQueue();
|
|
19881
20115
|
};
|
|
19882
20116
|
let pending = [];
|
|
20117
|
+
const hydrateQueue = [];
|
|
19883
20118
|
let nextSeq = 0;
|
|
19884
20119
|
let flushScheduled = false;
|
|
19885
20120
|
let projecting = false;
|
|
@@ -20341,8 +20576,7 @@ function connectRealm(realm, options) {
|
|
|
20341
20576
|
if (coalesceWindowMs > 0) unrefTimer(setTimeout(flushOutbox, coalesceWindowMs));
|
|
20342
20577
|
else queueMicrotask(flushOutbox);
|
|
20343
20578
|
};
|
|
20344
|
-
const
|
|
20345
|
-
const controller = createWriteHandle();
|
|
20579
|
+
const rejectUnsent = (controller, kind, error, intentName) => {
|
|
20346
20580
|
controller.reject(error);
|
|
20347
20581
|
emitRejection({
|
|
20348
20582
|
error,
|
|
@@ -20360,6 +20594,56 @@ function connectRealm(realm, options) {
|
|
|
20360
20594
|
});
|
|
20361
20595
|
return controller.handle;
|
|
20362
20596
|
};
|
|
20597
|
+
const rejectImmediately = (kind, error, intentName) => rejectUnsent(createWriteHandle(), kind, error, intentName);
|
|
20598
|
+
const neverHydratedError = () => attachError ?? err_realm.fromId("write_before_hydrate", { realmId: realm.id });
|
|
20599
|
+
const rejectQueued = (queued, error) => {
|
|
20600
|
+
if (queued.expiryTimer != null) clearTimeout(queued.expiryTimer);
|
|
20601
|
+
rejectUnsent(queued.controller, queued.kind, error, queued.intentName);
|
|
20602
|
+
};
|
|
20603
|
+
const mustQueueUntilHydrate = () => confirmedVersion === -1 || hydrateQueue.length > 0;
|
|
20604
|
+
const queueUntilHydrate = (queuedWrite, durability) => {
|
|
20605
|
+
const controller = createWriteHandle();
|
|
20606
|
+
if (status === "detached") return rejectUnsent(controller, queuedWrite.kind, neverHydratedError(), queuedWrite.intentName);
|
|
20607
|
+
const queued = {
|
|
20608
|
+
...queuedWrite,
|
|
20609
|
+
controller,
|
|
20610
|
+
expiryTimer: void 0
|
|
20611
|
+
};
|
|
20612
|
+
if (durability !== "reassert") {
|
|
20613
|
+
queued.expiryTimer = setTimeout(() => {
|
|
20614
|
+
const index = hydrateQueue.indexOf(queued);
|
|
20615
|
+
if (index < 0) return;
|
|
20616
|
+
hydrateQueue.splice(index, 1);
|
|
20617
|
+
rejectQueued(queued, neverHydratedError());
|
|
20618
|
+
notifyPending();
|
|
20619
|
+
}, expiryMs);
|
|
20620
|
+
unrefTimer(queued.expiryTimer);
|
|
20621
|
+
}
|
|
20622
|
+
hydrateQueue.push(queued);
|
|
20623
|
+
notifyPending();
|
|
20624
|
+
return controller.handle;
|
|
20625
|
+
};
|
|
20626
|
+
const drainHydrateQueue = () => {
|
|
20627
|
+
for (let queued = hydrateQueue.shift(); queued != null; queued = hydrateQueue.shift()) {
|
|
20628
|
+
if (queued.expiryTimer != null) clearTimeout(queued.expiryTimer);
|
|
20629
|
+
const { controller } = queued;
|
|
20630
|
+
let sent;
|
|
20631
|
+
try {
|
|
20632
|
+
sent = queued.run();
|
|
20633
|
+
} catch (cause) {
|
|
20634
|
+
console.error(`${warnTag()} a write queued before the first hydrate threw`, cause);
|
|
20635
|
+
rejectQueued(queued, castNiceError(cause));
|
|
20636
|
+
continue;
|
|
20637
|
+
}
|
|
20638
|
+
const settled = sent;
|
|
20639
|
+
settled.then(controller.confirm, () => {
|
|
20640
|
+
if (settled.error != null) controller.reject(settled.error);
|
|
20641
|
+
});
|
|
20642
|
+
}
|
|
20643
|
+
};
|
|
20644
|
+
const rejectHydrateQueue = () => {
|
|
20645
|
+
for (const queued of hydrateQueue.splice(0)) rejectQueued(queued, neverHydratedError());
|
|
20646
|
+
};
|
|
20363
20647
|
const enqueueWrite = (patches, writeOptions) => {
|
|
20364
20648
|
const durability = writeOptions?.durability;
|
|
20365
20649
|
const immediate = writeOptions?.flush === "immediate";
|
|
@@ -20412,19 +20696,8 @@ function connectRealm(realm, options) {
|
|
|
20412
20696
|
} else scheduleFlush();
|
|
20413
20697
|
return controller.handle;
|
|
20414
20698
|
};
|
|
20415
|
-
const
|
|
20699
|
+
const applyUpdate = (fn, updateOptions) => {
|
|
20416
20700
|
const projected = store.state;
|
|
20417
|
-
if (confirmedVersion === -1) {
|
|
20418
|
-
const error = err_realm.fromId("write_before_hydrate", { realmId: realm.id });
|
|
20419
|
-
try {
|
|
20420
|
-
produceWithPatches(projected, (draft) => {
|
|
20421
|
-
fn(draft);
|
|
20422
|
-
});
|
|
20423
|
-
} catch (cause) {
|
|
20424
|
-
throw new Error(error.message, { cause });
|
|
20425
|
-
}
|
|
20426
|
-
return rejectImmediately("write", error);
|
|
20427
|
-
}
|
|
20428
20701
|
let returned;
|
|
20429
20702
|
const [next, patches] = produceWithPatches(projected, (draft) => {
|
|
20430
20703
|
returned = fn(draft);
|
|
@@ -20446,7 +20719,16 @@ function connectRealm(realm, options) {
|
|
|
20446
20719
|
if (verdict !== true) return rejectImmediately("write", verdict);
|
|
20447
20720
|
return enqueueWrite(canonical, updateOptions);
|
|
20448
20721
|
};
|
|
20449
|
-
const
|
|
20722
|
+
const update = (fn, updateOptions) => mustQueueUntilHydrate() ? queueUntilHydrate({
|
|
20723
|
+
kind: "write",
|
|
20724
|
+
run: () => applyUpdate(fn, updateOptions)
|
|
20725
|
+
}, updateOptions?.durability) : applyUpdate(fn, updateOptions);
|
|
20726
|
+
const runIntent = (name, input) => mustQueueUntilHydrate() ? queueUntilHydrate({
|
|
20727
|
+
kind: "intent",
|
|
20728
|
+
intentName: name,
|
|
20729
|
+
run: () => sendIntent(name, input)
|
|
20730
|
+
}) : sendIntent(name, input);
|
|
20731
|
+
const sendIntent = (name, input) => {
|
|
20450
20732
|
const def = realm.intents[name];
|
|
20451
20733
|
if (def == null) return rejectImmediately("intent", err_realm.fromId("intent_unknown", { intent: name }), name);
|
|
20452
20734
|
const invalid = validateValue(def.input, input);
|
|
@@ -20627,7 +20909,8 @@ function connectRealm(realm, options) {
|
|
|
20627
20909
|
if (!isFirstHydrate && realm.transient.length > 0 && options.assertOnAttach != null && !hasPendingSystemAssert()) enqueueSystemAssert(confirmed);
|
|
20628
20910
|
revalidateAndResendPending();
|
|
20629
20911
|
project({ fullReplace: true });
|
|
20630
|
-
if (options.assertOnAttach != null && !hasPendingSystemAssert())
|
|
20912
|
+
if (options.assertOnAttach != null && !hasPendingSystemAssert()) applyUpdate(options.assertOnAttach);
|
|
20913
|
+
drainHydrateQueue();
|
|
20631
20914
|
checkReownWatch();
|
|
20632
20915
|
return;
|
|
20633
20916
|
}
|
|
@@ -20934,11 +21217,12 @@ function connectRealm(realm, options) {
|
|
|
20934
21217
|
}
|
|
20935
21218
|
const handle = {
|
|
20936
21219
|
store,
|
|
21220
|
+
avatar,
|
|
20937
21221
|
update,
|
|
20938
21222
|
intents: Object.fromEntries(realm.intentNames.map((name) => [name, (input) => runIntent(name, input)])),
|
|
20939
21223
|
pending: {
|
|
20940
21224
|
get count() {
|
|
20941
|
-
return pending.reduce((n, frame) => frame.isSystemAssert ? n : n + 1, 0);
|
|
21225
|
+
return pending.reduce((n, frame) => frame.isSystemAssert ? n : n + 1, 0) + hydrateQueue.length;
|
|
20942
21226
|
},
|
|
20943
21227
|
has(pathPrefix) {
|
|
20944
21228
|
return pending.some((frame) => !frame.isSystemAssert && frame.patches.some((patch) => patch.path.join(".").startsWith(pathPrefix)));
|
|
@@ -23314,7 +23598,8 @@ function commanderStatePaths(dataDir, configKey) {
|
|
|
23314
23598
|
upLockPath: join(stateDir, "up.lock"),
|
|
23315
23599
|
bootLogPath: join(stateDir, "daemon-boot.log"),
|
|
23316
23600
|
ingestSeqPath: join(stateDir, "ingest-seq"),
|
|
23317
|
-
envOverridesPath: join(stateDir, "env-overrides.json")
|
|
23601
|
+
envOverridesPath: join(stateDir, "env-overrides.json"),
|
|
23602
|
+
savedFiltersPath: join(stateDir, "saved-filters.json")
|
|
23318
23603
|
};
|
|
23319
23604
|
}
|
|
23320
23605
|
async function ensureStateDir(paths) {
|
|
@@ -23408,7 +23693,8 @@ const commanderStatusRealm = defineRealm({
|
|
|
23408
23693
|
degraded: t.boolean(),
|
|
23409
23694
|
notes: t.array(t.string())
|
|
23410
23695
|
})),
|
|
23411
|
-
tags: t.record(t.id("tag"), t.string()),
|
|
23696
|
+
tags: t.record(t.id("tag"), t.array(t.string())),
|
|
23697
|
+
optIn: t.boolean(),
|
|
23412
23698
|
detail: t.object({
|
|
23413
23699
|
command: t.string(),
|
|
23414
23700
|
cwd: t.string(),
|
|
@@ -23434,7 +23720,30 @@ const commanderStatusRealm = defineRealm({
|
|
|
23434
23720
|
}))
|
|
23435
23721
|
})
|
|
23436
23722
|
})),
|
|
23437
|
-
|
|
23723
|
+
suites: t.record(t.id("suiteName"), t.object({
|
|
23724
|
+
description: t.optional(t.string()),
|
|
23725
|
+
members: t.array(t.string()),
|
|
23726
|
+
parallel: t.number(),
|
|
23727
|
+
failFast: t.boolean()
|
|
23728
|
+
})),
|
|
23729
|
+
runs: t.record(t.id("runKey"), t.object({
|
|
23730
|
+
suite: t.optional(t.string()),
|
|
23731
|
+
filterId: t.optional(t.string()),
|
|
23732
|
+
startedAt: t.number(),
|
|
23733
|
+
endedAt: t.optional(t.number()),
|
|
23734
|
+
outcome: t.optional(t.union(t.literal("passed"), t.literal("failed"))),
|
|
23735
|
+
previousDurationMs: t.optional(t.number()),
|
|
23736
|
+
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")))
|
|
23737
|
+
})),
|
|
23738
|
+
savedFilters: t.array(t.object({
|
|
23739
|
+
id: t.string(),
|
|
23740
|
+
name: t.optional(t.string()),
|
|
23741
|
+
mode: t.union(t.literal("all"), t.literal("any")),
|
|
23742
|
+
terms: t.array(t.string()),
|
|
23743
|
+
bucket: t.optional(t.array(t.string())),
|
|
23744
|
+
pinned: t.boolean(),
|
|
23745
|
+
lastRunAt: t.optional(t.number())
|
|
23746
|
+
}))
|
|
23438
23747
|
},
|
|
23439
23748
|
rules: (r) => [r.path("**").view(r.everyone).alter(r.serverOnly)]
|
|
23440
23749
|
});
|
|
@@ -23567,7 +23876,7 @@ var CommanderDaemonBootError = class extends Error {
|
|
|
23567
23876
|
* a live dev environment, and an upgrade must never be the thing that kills one.
|
|
23568
23877
|
*/
|
|
23569
23878
|
async function replaceSkewedDaemon(paths, skewed) {
|
|
23570
|
-
const daemonLabel = `the daemon for this config (pid ${skewed.pid}, build ${skewed.packageVersion}, protocol v${skewed.protocolVersion}) predates this CLI (protocol
|
|
23879
|
+
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" : ""})`;
|
|
23571
23880
|
let liveIds = [];
|
|
23572
23881
|
try {
|
|
23573
23882
|
liveIds = (await openProcessLedger({
|
|
@@ -23812,11 +24121,78 @@ function checkEnvReport(value) {
|
|
|
23812
24121
|
warnings
|
|
23813
24122
|
};
|
|
23814
24123
|
}
|
|
23815
|
-
function
|
|
24124
|
+
function checkStop(value) {
|
|
23816
24125
|
const record = asRecord(value);
|
|
23817
24126
|
if (record == null) return "expected an object";
|
|
23818
24127
|
const ids = asIdList(record["ids"]);
|
|
23819
|
-
|
|
24128
|
+
if (ids == null) return "ids: expected an array of process ids";
|
|
24129
|
+
const withDependencies = record["withDependencies"];
|
|
24130
|
+
if (withDependencies != null && typeof withDependencies !== "boolean") return "withDependencies: expected a boolean";
|
|
24131
|
+
return withDependencies === true ? {
|
|
24132
|
+
ids,
|
|
24133
|
+
withDependencies
|
|
24134
|
+
} : { ids };
|
|
24135
|
+
}
|
|
24136
|
+
function checkRunSuite(value) {
|
|
24137
|
+
const record = asRecord(value);
|
|
24138
|
+
if (record == null) return "expected an object";
|
|
24139
|
+
const input = {};
|
|
24140
|
+
const suite = record["suite"];
|
|
24141
|
+
if (suite != null) {
|
|
24142
|
+
if (typeof suite !== "string" || suite === "") return "suite: expected a suite name";
|
|
24143
|
+
input.suite = suite;
|
|
24144
|
+
}
|
|
24145
|
+
if (record["ids"] != null) {
|
|
24146
|
+
const ids = asIdList(record["ids"]);
|
|
24147
|
+
if (ids == null) return "ids: expected an array of process ids";
|
|
24148
|
+
input.ids = ids;
|
|
24149
|
+
}
|
|
24150
|
+
if (input.suite == null === (input.ids == null)) return "expected exactly one of suite | ids";
|
|
24151
|
+
const parallel = record["parallel"];
|
|
24152
|
+
if (parallel != null) {
|
|
24153
|
+
if (typeof parallel !== "number" || !Number.isInteger(parallel) || parallel < 1) return "parallel: expected an integer ≥ 1";
|
|
24154
|
+
input.parallel = parallel;
|
|
24155
|
+
}
|
|
24156
|
+
const failFast = record["failFast"];
|
|
24157
|
+
if (failFast != null) {
|
|
24158
|
+
if (typeof failFast !== "boolean") return "failFast: expected a boolean";
|
|
24159
|
+
input.failFast = failFast;
|
|
24160
|
+
}
|
|
24161
|
+
if (record["filter"] != null) {
|
|
24162
|
+
const filter = checkSavedFilterQuery(record["filter"]);
|
|
24163
|
+
if (typeof filter === "string") return `filter.${filter}`;
|
|
24164
|
+
input.filter = filter;
|
|
24165
|
+
}
|
|
24166
|
+
return input;
|
|
24167
|
+
}
|
|
24168
|
+
function checkRunSuiteReport(value) {
|
|
24169
|
+
const record = asRecord(value);
|
|
24170
|
+
if (record == null || typeof record["accepted"] !== "boolean") return "expected { accepted }";
|
|
24171
|
+
const { runKey, reason } = record;
|
|
24172
|
+
return {
|
|
24173
|
+
accepted: record["accepted"],
|
|
24174
|
+
...typeof runKey === "string" ? { runKey } : {},
|
|
24175
|
+
...typeof reason === "string" ? { reason } : {}
|
|
24176
|
+
};
|
|
24177
|
+
}
|
|
24178
|
+
function checkSaveFilter(value) {
|
|
24179
|
+
const record = asRecord(value);
|
|
24180
|
+
if (record == null) return "expected an object";
|
|
24181
|
+
const filter = checkSavedFilterQuery(record["filter"]);
|
|
24182
|
+
if (typeof filter === "string") return `filter.${filter}`;
|
|
24183
|
+
const name = record["name"];
|
|
24184
|
+
if (typeof name !== "string") return "name: expected a string";
|
|
24185
|
+
return {
|
|
24186
|
+
filter,
|
|
24187
|
+
name
|
|
24188
|
+
};
|
|
24189
|
+
}
|
|
24190
|
+
function checkRemoveFilter(value) {
|
|
24191
|
+
const id = asRecord(value)?.["id"];
|
|
24192
|
+
return typeof id === "string" && id !== "" ? { id } : "id: expected a saved filter id";
|
|
24193
|
+
}
|
|
24194
|
+
function checkOk(value) {
|
|
24195
|
+
return asRecord(value)?.["ok"] === true ? { ok: true } : "expected { ok: true }";
|
|
23820
24196
|
}
|
|
23821
24197
|
function checkEmpty(value) {
|
|
23822
24198
|
return asRecord(value) == null ? "expected an object" : {};
|
|
@@ -23896,11 +24272,14 @@ const commanderControlDomain = createActionRootDomain({ domain: "commander" }).c
|
|
|
23896
24272
|
actions: {
|
|
23897
24273
|
ports: actionSchema().input({ schema: handSchema(checkPortsInput) }).output({ schema: handSchema(checkPortsReport) }),
|
|
23898
24274
|
start: actionSchema().input({ schema: handSchema(checkStart) }).output({ schema: handSchema(checkReport) }),
|
|
23899
|
-
stop: actionSchema().input({ schema: handSchema(
|
|
24275
|
+
stop: actionSchema().input({ schema: handSchema(checkStop) }).output({ schema: handSchema(checkReport) }),
|
|
23900
24276
|
restart: actionSchema().input({ schema: handSchema(checkStart) }).output({ schema: handSchema(checkReport) }),
|
|
24277
|
+
runSuite: actionSchema().input({ schema: handSchema(checkRunSuite) }).output({ schema: handSchema(checkRunSuiteReport) }),
|
|
24278
|
+
saveFilter: actionSchema().input({ schema: handSchema(checkSaveFilter) }).output({ schema: handSchema(checkOk) }),
|
|
24279
|
+
removeFilter: actionSchema().input({ schema: handSchema(checkRemoveFilter) }).output({ schema: handSchema(checkOk) }),
|
|
23901
24280
|
setEnv: actionSchema().input({ schema: handSchema(checkSetEnv) }).output({ schema: handSchema(checkEnvReport) }),
|
|
23902
24281
|
reloadConfig: actionSchema().input({ schema: handSchema(checkEmpty) }).output({ schema: handSchema(checkReloadResult) }),
|
|
23903
|
-
shutdown: actionSchema().input({ schema: handSchema(checkEmpty) }).output({ schema: handSchema(
|
|
24282
|
+
shutdown: actionSchema().input({ schema: handSchema(checkEmpty) }).output({ schema: handSchema(checkOk) })
|
|
23904
24283
|
}
|
|
23905
24284
|
});
|
|
23906
24285
|
/** One socket carries control actions (toAcceptor) + the status realm (a mux protocol, D1). */
|
|
@@ -23944,7 +24323,7 @@ async function findDaemon(config) {
|
|
|
23944
24323
|
async function findSkewedDaemon(config) {
|
|
23945
24324
|
const skewed = await readSkewedInstanceRecord(commanderStatePaths(resolveCommanderDataDir(), config.configKey).instanceRecordPath, commanderStatusRealm.schemaHash);
|
|
23946
24325
|
if (skewed == null || !pidAlive$1(skewed.pid)) return null;
|
|
23947
|
-
const difference = skewed.skew === "protocol" ? `speaks protocol v${skewed.protocolVersion}; this build speaks
|
|
24326
|
+
const difference = skewed.skew === "protocol" ? `speaks protocol v${skewed.protocolVersion}; this build speaks v6` : "was started before an upgrade changed the status schema";
|
|
23948
24327
|
return {
|
|
23949
24328
|
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.`,
|
|
23950
24329
|
pid: skewed.pid,
|
|
@@ -24042,7 +24421,7 @@ async function connectDaemon(handle) {
|
|
|
24042
24421
|
const payload = await (await runtime.handleActionPayload(request)).waitForResultPayload();
|
|
24043
24422
|
if (!payload.result.ok) throw new CliExit(EXIT.failure, `action "${action}" rejected by the daemon`);
|
|
24044
24423
|
const report = parseActionReport(payload.result.output);
|
|
24045
|
-
if (report == null) throw new CliExit(EXIT.failure, `the daemon answered "${action}" with something this CLI does not recognise — protocol ${record.protocolVersion} vs
|
|
24424
|
+
if (report == null) throw new CliExit(EXIT.failure, `the daemon answered "${action}" with something this CLI does not recognise — protocol ${record.protocolVersion} vs 6`);
|
|
24046
24425
|
return report;
|
|
24047
24426
|
},
|
|
24048
24427
|
setEnv: async (input) => {
|
|
@@ -24129,7 +24508,8 @@ async function cmdUp(ctx) {
|
|
|
24129
24508
|
const bad = unknownFlags(ctx.args.flags, [
|
|
24130
24509
|
"--no-wait",
|
|
24131
24510
|
"--dry-run",
|
|
24132
|
-
"--all"
|
|
24511
|
+
"--all",
|
|
24512
|
+
"--any"
|
|
24133
24513
|
]);
|
|
24134
24514
|
if (bad != null) throw new CliExit(EXIT.usage, bad);
|
|
24135
24515
|
const selection = selectOrExit(ctx, { bare: "default" });
|
|
@@ -24163,7 +24543,11 @@ async function cmdUp(ctx) {
|
|
|
24163
24543
|
}
|
|
24164
24544
|
}
|
|
24165
24545
|
async function controlVerb(ctx, verb) {
|
|
24166
|
-
const known = verb === "restart" ? [
|
|
24546
|
+
const known = verb === "restart" ? [
|
|
24547
|
+
"--no-wait",
|
|
24548
|
+
"--all",
|
|
24549
|
+
"--any"
|
|
24550
|
+
] : ["--all", "--any"];
|
|
24167
24551
|
const bad = unknownFlags(ctx.args.flags, known);
|
|
24168
24552
|
if (bad != null) throw new CliExit(EXIT.usage, bad);
|
|
24169
24553
|
requireSelectionTerms(ctx);
|
|
@@ -24258,6 +24642,85 @@ function reportSignalShutdown(ctx, result) {
|
|
|
24258
24642
|
}
|
|
24259
24643
|
}
|
|
24260
24644
|
//#endregion
|
|
24645
|
+
//#region src/daemon/envOverrides.ts
|
|
24646
|
+
const STORE_VERSION$1 = 1;
|
|
24647
|
+
/** A knob is a port or a log level, not a payload. Bounds keep a mistake from becoming a file. */
|
|
24648
|
+
const MAX_VALUE_LENGTH = 4096;
|
|
24649
|
+
const EMPTY_ENV_OVERRIDES = Object.freeze({});
|
|
24650
|
+
function readable$1(value) {
|
|
24651
|
+
if (value == null || typeof value !== "object") return null;
|
|
24652
|
+
const processes = value.processes;
|
|
24653
|
+
if (processes == null || typeof processes !== "object" || Array.isArray(processes)) return null;
|
|
24654
|
+
const clean = {};
|
|
24655
|
+
for (const [id, values] of Object.entries(processes)) {
|
|
24656
|
+
if (values == null || typeof values !== "object" || Array.isArray(values)) continue;
|
|
24657
|
+
const entries = {};
|
|
24658
|
+
for (const [name, entry] of Object.entries(values)) if (typeof entry === "string" && entry.length <= MAX_VALUE_LENGTH) entries[name] = entry;
|
|
24659
|
+
if (Object.keys(entries).length > 0) clean[id] = entries;
|
|
24660
|
+
}
|
|
24661
|
+
return clean;
|
|
24662
|
+
}
|
|
24663
|
+
/**
|
|
24664
|
+
* Missing, unreadable or corrupt all read as "no overrides". A bad file must never block a start:
|
|
24665
|
+
* the config alone is always enough to run, and the surfaces that report overrides say when the
|
|
24666
|
+
* store could not be read.
|
|
24667
|
+
*/
|
|
24668
|
+
async function readEnvOverrides(path) {
|
|
24669
|
+
try {
|
|
24670
|
+
return readable$1(JSON.parse(await readFile(path, "utf8"))) ?? EMPTY_ENV_OVERRIDES;
|
|
24671
|
+
} catch {
|
|
24672
|
+
return EMPTY_ENV_OVERRIDES;
|
|
24673
|
+
}
|
|
24674
|
+
}
|
|
24675
|
+
/** 0600 and atomic — it can hold a token, and a half-written file must never be read as empty. */
|
|
24676
|
+
async function writeEnvOverrides(path, overrides) {
|
|
24677
|
+
await mkdir(dirname(path), {
|
|
24678
|
+
recursive: true,
|
|
24679
|
+
mode: 448
|
|
24680
|
+
});
|
|
24681
|
+
const store = {
|
|
24682
|
+
version: STORE_VERSION$1,
|
|
24683
|
+
processes: Object.fromEntries(Object.entries(overrides).filter(([, values]) => Object.keys(values).length > 0).map(([id, values]) => [id, { ...values }]))
|
|
24684
|
+
};
|
|
24685
|
+
const temp = `${path}.${process.pid}.tmp`;
|
|
24686
|
+
await writeFile(temp, `${JSON.stringify(store, null, 2)}\n`, {
|
|
24687
|
+
encoding: "utf8",
|
|
24688
|
+
mode: 384
|
|
24689
|
+
});
|
|
24690
|
+
await rename(temp, path);
|
|
24691
|
+
}
|
|
24692
|
+
/** Pure: the store that results from applying `change`. Empty processes are pruned. */
|
|
24693
|
+
function mutateEnvOverrides(current, change) {
|
|
24694
|
+
const next = {};
|
|
24695
|
+
for (const [id, values] of Object.entries(current)) next[id] = { ...values };
|
|
24696
|
+
for (const id of change.clear ?? []) delete next[id];
|
|
24697
|
+
for (const [id, values] of Object.entries(change.mutations ?? {})) {
|
|
24698
|
+
const entries = next[id] ?? {};
|
|
24699
|
+
for (const [name, value] of Object.entries(values)) if (value == null) delete entries[name];
|
|
24700
|
+
else entries[name] = value;
|
|
24701
|
+
if (Object.keys(entries).length > 0) next[id] = entries;
|
|
24702
|
+
else delete next[id];
|
|
24703
|
+
}
|
|
24704
|
+
return next;
|
|
24705
|
+
}
|
|
24706
|
+
/**
|
|
24707
|
+
* Read → check against the config → mutate → write, atomically enough for a file two surfaces
|
|
24708
|
+
* touch. The one implementation behind both writers, so the daemon's `setEnv` and the CLI's
|
|
24709
|
+
* no-daemon path can never diverge on what they accept.
|
|
24710
|
+
*/
|
|
24711
|
+
async function applyEnvMutation(path, config, input) {
|
|
24712
|
+
const checked = checkEnvMutations(config, input);
|
|
24713
|
+
const next = mutateEnvOverrides(await readEnvOverrides(path), checked);
|
|
24714
|
+
await writeEnvOverrides(path, next);
|
|
24715
|
+
return {
|
|
24716
|
+
overrides: next,
|
|
24717
|
+
warnings: checked.warnings
|
|
24718
|
+
};
|
|
24719
|
+
}
|
|
24720
|
+
function countOverrides(overrides) {
|
|
24721
|
+
return Object.values(overrides).reduce((total, values) => total + Object.keys(values).length, 0);
|
|
24722
|
+
}
|
|
24723
|
+
//#endregion
|
|
24261
24724
|
//#region src/ports/listeners.ts
|
|
24262
24725
|
const exec = promisify(execFile);
|
|
24263
24726
|
const ACTIVE = new Set([
|
|
@@ -24491,206 +24954,31 @@ function createPortInspector(options) {
|
|
|
24491
24954
|
return { run };
|
|
24492
24955
|
}
|
|
24493
24956
|
//#endregion
|
|
24494
|
-
//#region src/cli/commands/
|
|
24495
|
-
|
|
24496
|
-
|
|
24497
|
-
if (
|
|
24498
|
-
|
|
24957
|
+
//#region src/cli/commands/doctor.ts
|
|
24958
|
+
function formatAge(ms) {
|
|
24959
|
+
if (ms < 6e4) return `${Math.round(ms / 1e3)}s`;
|
|
24960
|
+
if (ms < 36e5) return `${Math.round(ms / 6e4)}m`;
|
|
24961
|
+
return `${(ms / 36e5).toFixed(1)}h`;
|
|
24962
|
+
}
|
|
24963
|
+
let cachedWsl = null;
|
|
24964
|
+
/** WSL detection (fs.watch is flaky on /mnt/c; also drives the browser ladder). */
|
|
24965
|
+
async function isWsl() {
|
|
24966
|
+
if (cachedWsl != null) return cachedWsl;
|
|
24967
|
+
if (process.platform !== "linux") {
|
|
24968
|
+
cachedWsl = false;
|
|
24969
|
+
return false;
|
|
24970
|
+
}
|
|
24971
|
+
if (process.env["WSL_DISTRO_NAME"] != null) {
|
|
24972
|
+
cachedWsl = true;
|
|
24973
|
+
return true;
|
|
24974
|
+
}
|
|
24499
24975
|
try {
|
|
24500
|
-
|
|
24501
|
-
|
|
24502
|
-
|
|
24503
|
-
}
|
|
24504
|
-
|
|
24505
|
-
|
|
24506
|
-
const bad = unknownFlags(ctx.args.flags, [
|
|
24507
|
-
"--all",
|
|
24508
|
-
"--kill",
|
|
24509
|
-
"--yes",
|
|
24510
|
-
"--force"
|
|
24511
|
-
]);
|
|
24512
|
-
if (bad) throw new CliExit(EXIT.usage, bad);
|
|
24513
|
-
const pid = numericFlag(ctx.args.flags, "--kill");
|
|
24514
|
-
if (pid != null && typeof pid !== "number") throw new CliExit(EXIT.usage, pid.error);
|
|
24515
|
-
for (const flag of [
|
|
24516
|
-
"--yes",
|
|
24517
|
-
"--force",
|
|
24518
|
-
"--all"
|
|
24519
|
-
]) if (ctx.args.flags.has(flag) && ctx.args.flags.get(flag) !== true) throw new CliExit(EXIT.usage, `${flag} takes no value`);
|
|
24520
|
-
if (!pid && (ctx.args.flags.has("--force") || ctx.args.flags.has("--yes"))) throw new CliExit(EXIT.usage, "--force/--yes require --kill PID");
|
|
24521
|
-
const ids = ctx.args.positionals.length || ctx.args.flags.has("--all") ? selectOrExit(ctx, { bare: "required" }).direct : ctx.config.processes.map((p) => p.id);
|
|
24522
|
-
const inspector = createPortInspector({
|
|
24523
|
-
config: () => ctx.config,
|
|
24524
|
-
states: () => portProcessStates(ctx),
|
|
24525
|
-
protectedPids: async () => {
|
|
24526
|
-
const daemon = await findDaemon(ctx.config);
|
|
24527
|
-
return daemon ? [daemon.record.pid] : [];
|
|
24528
|
-
}
|
|
24529
|
-
});
|
|
24530
|
-
const report = await inspector.run({ ids });
|
|
24531
|
-
const print = (result) => {
|
|
24532
|
-
if (ctx.out.json) {
|
|
24533
|
-
ctx.out.printJson(result);
|
|
24534
|
-
return;
|
|
24535
|
-
}
|
|
24536
|
-
ctx.out.print(ctx.out.table([
|
|
24537
|
-
"PROCESS",
|
|
24538
|
-
"ENDPOINT",
|
|
24539
|
-
"PID",
|
|
24540
|
-
"PARENT",
|
|
24541
|
-
"COMMAND",
|
|
24542
|
-
"CWD",
|
|
24543
|
-
"IDENTITY",
|
|
24544
|
-
"STOP"
|
|
24545
|
-
], result.listeners.map((l) => [
|
|
24546
|
-
l.id,
|
|
24547
|
-
`${l.host}:${l.port}`,
|
|
24548
|
-
String(l.pid),
|
|
24549
|
-
String(l.ppid ?? "unknown"),
|
|
24550
|
-
l.command,
|
|
24551
|
-
l.cwd ?? "unavailable",
|
|
24552
|
-
l.startStamp ?? "unknown",
|
|
24553
|
-
l.refusal ?? "available"
|
|
24554
|
-
])));
|
|
24555
|
-
if (!result.listeners.length) ctx.out.print("No visible listeners on the selected exclusive TCP endpoints.");
|
|
24556
|
-
for (const warning of result.warnings) ctx.out.warn(warning);
|
|
24557
|
-
};
|
|
24558
|
-
if (!pid) {
|
|
24559
|
-
print(report);
|
|
24560
|
-
return report.warnings.length ? EXIT.failure : EXIT.ok;
|
|
24561
|
-
}
|
|
24562
|
-
const target = report.listeners.find((l) => l.pid === pid);
|
|
24563
|
-
if (!target?.token) {
|
|
24564
|
-
print(report);
|
|
24565
|
-
throw new CliExit(EXIT.failure, target?.refusal ?? `PID ${pid} is not a verified listener on the selected endpoints`);
|
|
24566
|
-
}
|
|
24567
|
-
if (!ctx.args.flags.has("--yes")) {
|
|
24568
|
-
print(report);
|
|
24569
|
-
if (!process.stdin.isTTY || ctx.out.json) throw new CliExit(EXIT.usage, "Stopping requires interactive confirmation, or --yes with --kill PID");
|
|
24570
|
-
const rl = createInterface({
|
|
24571
|
-
input: process.stdin,
|
|
24572
|
-
output: process.stdout
|
|
24573
|
-
});
|
|
24574
|
-
try {
|
|
24575
|
-
const answer = await rl.question(`${ctx.args.flags.has("--force") ? "Force kill" : "Stop"} PID ${pid} (${target.command}) on ${target.host}:${target.port}? [y/N] `);
|
|
24576
|
-
if (!/^y(es)?$/i.test(answer.trim())) return EXIT.ok;
|
|
24577
|
-
} finally {
|
|
24578
|
-
rl.close();
|
|
24579
|
-
}
|
|
24580
|
-
}
|
|
24581
|
-
const result = await inspector.run({
|
|
24582
|
-
ids,
|
|
24583
|
-
token: target.token,
|
|
24584
|
-
force: ctx.args.flags.has("--force")
|
|
24585
|
-
});
|
|
24586
|
-
print(result);
|
|
24587
|
-
return result.warnings.length ? EXIT.failure : EXIT.ok;
|
|
24588
|
-
}
|
|
24589
|
-
//#endregion
|
|
24590
|
-
//#region src/daemon/envOverrides.ts
|
|
24591
|
-
const STORE_VERSION = 1;
|
|
24592
|
-
/** A knob is a port or a log level, not a payload. Bounds keep a mistake from becoming a file. */
|
|
24593
|
-
const MAX_VALUE_LENGTH = 4096;
|
|
24594
|
-
const EMPTY_ENV_OVERRIDES = Object.freeze({});
|
|
24595
|
-
function readable(value) {
|
|
24596
|
-
if (value == null || typeof value !== "object") return null;
|
|
24597
|
-
const processes = value.processes;
|
|
24598
|
-
if (processes == null || typeof processes !== "object" || Array.isArray(processes)) return null;
|
|
24599
|
-
const clean = {};
|
|
24600
|
-
for (const [id, values] of Object.entries(processes)) {
|
|
24601
|
-
if (values == null || typeof values !== "object" || Array.isArray(values)) continue;
|
|
24602
|
-
const entries = {};
|
|
24603
|
-
for (const [name, entry] of Object.entries(values)) if (typeof entry === "string" && entry.length <= MAX_VALUE_LENGTH) entries[name] = entry;
|
|
24604
|
-
if (Object.keys(entries).length > 0) clean[id] = entries;
|
|
24605
|
-
}
|
|
24606
|
-
return clean;
|
|
24607
|
-
}
|
|
24608
|
-
/**
|
|
24609
|
-
* Missing, unreadable or corrupt all read as "no overrides". A bad file must never block a start:
|
|
24610
|
-
* the config alone is always enough to run, and the surfaces that report overrides say when the
|
|
24611
|
-
* store could not be read.
|
|
24612
|
-
*/
|
|
24613
|
-
async function readEnvOverrides(path) {
|
|
24614
|
-
try {
|
|
24615
|
-
return readable(JSON.parse(await readFile(path, "utf8"))) ?? EMPTY_ENV_OVERRIDES;
|
|
24616
|
-
} catch {
|
|
24617
|
-
return EMPTY_ENV_OVERRIDES;
|
|
24618
|
-
}
|
|
24619
|
-
}
|
|
24620
|
-
/** 0600 and atomic — it can hold a token, and a half-written file must never be read as empty. */
|
|
24621
|
-
async function writeEnvOverrides(path, overrides) {
|
|
24622
|
-
await mkdir(dirname(path), {
|
|
24623
|
-
recursive: true,
|
|
24624
|
-
mode: 448
|
|
24625
|
-
});
|
|
24626
|
-
const store = {
|
|
24627
|
-
version: STORE_VERSION,
|
|
24628
|
-
processes: Object.fromEntries(Object.entries(overrides).filter(([, values]) => Object.keys(values).length > 0).map(([id, values]) => [id, { ...values }]))
|
|
24629
|
-
};
|
|
24630
|
-
const temp = `${path}.${process.pid}.tmp`;
|
|
24631
|
-
await writeFile(temp, `${JSON.stringify(store, null, 2)}\n`, {
|
|
24632
|
-
encoding: "utf8",
|
|
24633
|
-
mode: 384
|
|
24634
|
-
});
|
|
24635
|
-
await rename(temp, path);
|
|
24636
|
-
}
|
|
24637
|
-
/** Pure: the store that results from applying `change`. Empty processes are pruned. */
|
|
24638
|
-
function mutateEnvOverrides(current, change) {
|
|
24639
|
-
const next = {};
|
|
24640
|
-
for (const [id, values] of Object.entries(current)) next[id] = { ...values };
|
|
24641
|
-
for (const id of change.clear ?? []) delete next[id];
|
|
24642
|
-
for (const [id, values] of Object.entries(change.mutations ?? {})) {
|
|
24643
|
-
const entries = next[id] ?? {};
|
|
24644
|
-
for (const [name, value] of Object.entries(values)) if (value == null) delete entries[name];
|
|
24645
|
-
else entries[name] = value;
|
|
24646
|
-
if (Object.keys(entries).length > 0) next[id] = entries;
|
|
24647
|
-
else delete next[id];
|
|
24648
|
-
}
|
|
24649
|
-
return next;
|
|
24650
|
-
}
|
|
24651
|
-
/**
|
|
24652
|
-
* Read → check against the config → mutate → write, atomically enough for a file two surfaces
|
|
24653
|
-
* touch. The one implementation behind both writers, so the daemon's `setEnv` and the CLI's
|
|
24654
|
-
* no-daemon path can never diverge on what they accept.
|
|
24655
|
-
*/
|
|
24656
|
-
async function applyEnvMutation(path, config, input) {
|
|
24657
|
-
const checked = checkEnvMutations(config, input);
|
|
24658
|
-
const next = mutateEnvOverrides(await readEnvOverrides(path), checked);
|
|
24659
|
-
await writeEnvOverrides(path, next);
|
|
24660
|
-
return {
|
|
24661
|
-
overrides: next,
|
|
24662
|
-
warnings: checked.warnings
|
|
24663
|
-
};
|
|
24664
|
-
}
|
|
24665
|
-
function countOverrides(overrides) {
|
|
24666
|
-
return Object.values(overrides).reduce((total, values) => total + Object.keys(values).length, 0);
|
|
24667
|
-
}
|
|
24668
|
-
//#endregion
|
|
24669
|
-
//#region src/cli/commands/doctor.ts
|
|
24670
|
-
function formatAge(ms) {
|
|
24671
|
-
if (ms < 6e4) return `${Math.round(ms / 1e3)}s`;
|
|
24672
|
-
if (ms < 36e5) return `${Math.round(ms / 6e4)}m`;
|
|
24673
|
-
return `${(ms / 36e5).toFixed(1)}h`;
|
|
24674
|
-
}
|
|
24675
|
-
let cachedWsl = null;
|
|
24676
|
-
/** WSL detection (fs.watch is flaky on /mnt/c; also drives the browser ladder). */
|
|
24677
|
-
async function isWsl() {
|
|
24678
|
-
if (cachedWsl != null) return cachedWsl;
|
|
24679
|
-
if (process.platform !== "linux") {
|
|
24680
|
-
cachedWsl = false;
|
|
24681
|
-
return false;
|
|
24682
|
-
}
|
|
24683
|
-
if (process.env["WSL_DISTRO_NAME"] != null) {
|
|
24684
|
-
cachedWsl = true;
|
|
24685
|
-
return true;
|
|
24686
|
-
}
|
|
24687
|
-
try {
|
|
24688
|
-
const release = await readFile("/proc/sys/kernel/osrelease", "utf8");
|
|
24689
|
-
cachedWsl = /microsoft/i.test(release);
|
|
24690
|
-
return cachedWsl;
|
|
24691
|
-
} catch {
|
|
24692
|
-
cachedWsl = false;
|
|
24693
|
-
return false;
|
|
24976
|
+
const release = await readFile("/proc/sys/kernel/osrelease", "utf8");
|
|
24977
|
+
cachedWsl = /microsoft/i.test(release);
|
|
24978
|
+
return cachedWsl;
|
|
24979
|
+
} catch {
|
|
24980
|
+
cachedWsl = false;
|
|
24981
|
+
return false;
|
|
24694
24982
|
}
|
|
24695
24983
|
}
|
|
24696
24984
|
function tryConnectTcp(host, port, timeoutMs = 600) {
|
|
@@ -24999,12 +25287,10 @@ async function cmdList(ctx) {
|
|
|
24999
25287
|
dependsOn: proc.dependsOn,
|
|
25000
25288
|
endpoints: proc.endpoints,
|
|
25001
25289
|
url: proc.url ?? null,
|
|
25002
|
-
envVars: proc.envVars
|
|
25290
|
+
envVars: proc.envVars,
|
|
25291
|
+
optIn: proc.optIn
|
|
25003
25292
|
})),
|
|
25004
|
-
|
|
25005
|
-
ids: group.ids,
|
|
25006
|
-
staggerMs: group.staggerMs
|
|
25007
|
-
}])),
|
|
25293
|
+
suites: Object.fromEntries(Object.entries(config.suites).map(([name, { name: _name, ...suite }]) => [name, suite])),
|
|
25008
25294
|
warnings: config.warnings
|
|
25009
25295
|
});
|
|
25010
25296
|
return EXIT.ok;
|
|
@@ -25018,31 +25304,31 @@ async function cmdList(ctx) {
|
|
|
25018
25304
|
], config.processes.map((proc) => [
|
|
25019
25305
|
proc.id,
|
|
25020
25306
|
proc.kind,
|
|
25021
|
-
|
|
25307
|
+
[...tagTermsOf(proc.tags), ...proc.optIn ? ["(opt-in)"] : []].join(" "),
|
|
25022
25308
|
proc.dependsOn.join(" "),
|
|
25023
25309
|
proc.endpoints.map((endpoint) => `${endpoint.name}:${endpoint.port}`).join(" ")
|
|
25024
25310
|
])));
|
|
25025
|
-
const
|
|
25026
|
-
name,
|
|
25027
|
-
String(
|
|
25028
|
-
|
|
25029
|
-
|
|
25311
|
+
const suiteRows = Object.values(config.suites).map((suite) => [
|
|
25312
|
+
suite.name,
|
|
25313
|
+
String(suite.ids.length),
|
|
25314
|
+
`parallel ${suite.parallel}${suite.failFast ? " · fail-fast" : ""}`,
|
|
25315
|
+
suite.ids.join(" ")
|
|
25030
25316
|
]);
|
|
25031
|
-
if (
|
|
25317
|
+
if (suiteRows.length > 0) {
|
|
25032
25318
|
out.print("");
|
|
25033
25319
|
out.print(out.table([
|
|
25034
|
-
"
|
|
25320
|
+
"SUITE",
|
|
25035
25321
|
"N",
|
|
25036
|
-
"
|
|
25037
|
-
"
|
|
25038
|
-
],
|
|
25322
|
+
"POLICY",
|
|
25323
|
+
"IDS"
|
|
25324
|
+
], suiteRows));
|
|
25039
25325
|
}
|
|
25040
25326
|
if (config.defaultSelection != null) out.print(out.paint("gray", `\ndefaultSelection: ${config.defaultSelection}`));
|
|
25041
25327
|
for (const warning of config.warnings) out.warn(`${out.paint("yellow", "⚠")} ${warning}`);
|
|
25042
25328
|
return EXIT.ok;
|
|
25043
25329
|
}
|
|
25044
25330
|
async function cmdExplain(ctx) {
|
|
25045
|
-
const bad = unknownFlags(ctx.args.flags, ["--all"]);
|
|
25331
|
+
const bad = unknownFlags(ctx.args.flags, ["--all", "--any"]);
|
|
25046
25332
|
if (bad != null) throw new CliExit(EXIT.usage, bad);
|
|
25047
25333
|
const selection = selectOrExit(ctx, { bare: "default" });
|
|
25048
25334
|
const { out } = ctx;
|
|
@@ -25052,6 +25338,9 @@ async function cmdExplain(ctx) {
|
|
|
25052
25338
|
}
|
|
25053
25339
|
out.print(`direct: ${selection.direct.join(", ") || "(none)"}`);
|
|
25054
25340
|
out.print(`auto-included: ${selection.autoIncluded.length > 0 ? selection.autoIncluded.join(", ") : "(none)"}`);
|
|
25341
|
+
const [onlyTerm] = ctx.args.positionals.length === 1 ? ctx.args.positionals : [];
|
|
25342
|
+
const suite = onlyTerm == null ? void 0 : ctx.config.suites[onlyTerm];
|
|
25343
|
+
if (suite != null) out.print(`suite policy: parallel ${suite.parallel}, fail-fast ${suite.failFast ? "on" : "off"}, stagger ${suite.staggerMs}ms`);
|
|
25055
25344
|
out.print(`DAG order:`);
|
|
25056
25345
|
selection.ordered.forEach((id, index) => {
|
|
25057
25346
|
out.print(` ${index + 1}. ${id}`);
|
|
@@ -25239,6 +25528,7 @@ function printLine(out, entry) {
|
|
|
25239
25528
|
}
|
|
25240
25529
|
async function cmdLogs(ctx) {
|
|
25241
25530
|
const bad = unknownFlags(ctx.args.flags, [
|
|
25531
|
+
"--any",
|
|
25242
25532
|
"-f",
|
|
25243
25533
|
"--follow",
|
|
25244
25534
|
"--all"
|
|
@@ -25303,6 +25593,159 @@ async function cmdLogs(ctx) {
|
|
|
25303
25593
|
}
|
|
25304
25594
|
}
|
|
25305
25595
|
//#endregion
|
|
25596
|
+
//#region src/cli/commands/ports.ts
|
|
25597
|
+
async function portProcessStates(ctx) {
|
|
25598
|
+
const handle = await findDaemon(ctx.config);
|
|
25599
|
+
if (!handle) return /* @__PURE__ */ new Map();
|
|
25600
|
+
const client = await connectDaemon(handle);
|
|
25601
|
+
try {
|
|
25602
|
+
return new Map(Object.entries(client.state().processes).map(([id, p]) => [id, p.state]));
|
|
25603
|
+
} finally {
|
|
25604
|
+
client.dispose();
|
|
25605
|
+
}
|
|
25606
|
+
}
|
|
25607
|
+
async function cmdPorts(ctx) {
|
|
25608
|
+
const bad = unknownFlags(ctx.args.flags, [
|
|
25609
|
+
"--all",
|
|
25610
|
+
"--kill",
|
|
25611
|
+
"--yes",
|
|
25612
|
+
"--force"
|
|
25613
|
+
]);
|
|
25614
|
+
if (bad) throw new CliExit(EXIT.usage, bad);
|
|
25615
|
+
const pid = numericFlag(ctx.args.flags, "--kill");
|
|
25616
|
+
if (pid != null && typeof pid !== "number") throw new CliExit(EXIT.usage, pid.error);
|
|
25617
|
+
for (const flag of [
|
|
25618
|
+
"--yes",
|
|
25619
|
+
"--force",
|
|
25620
|
+
"--all"
|
|
25621
|
+
]) if (ctx.args.flags.has(flag) && ctx.args.flags.get(flag) !== true) throw new CliExit(EXIT.usage, `${flag} takes no value`);
|
|
25622
|
+
if (!pid && (ctx.args.flags.has("--force") || ctx.args.flags.has("--yes"))) throw new CliExit(EXIT.usage, "--force/--yes require --kill PID");
|
|
25623
|
+
const ids = ctx.args.positionals.length || ctx.args.flags.has("--all") ? selectOrExit(ctx, { bare: "required" }).direct : ctx.config.processes.map((p) => p.id);
|
|
25624
|
+
const inspector = createPortInspector({
|
|
25625
|
+
config: () => ctx.config,
|
|
25626
|
+
states: () => portProcessStates(ctx),
|
|
25627
|
+
protectedPids: async () => {
|
|
25628
|
+
const daemon = await findDaemon(ctx.config);
|
|
25629
|
+
return daemon ? [daemon.record.pid] : [];
|
|
25630
|
+
}
|
|
25631
|
+
});
|
|
25632
|
+
const report = await inspector.run({ ids });
|
|
25633
|
+
const print = (result) => {
|
|
25634
|
+
if (ctx.out.json) {
|
|
25635
|
+
ctx.out.printJson(result);
|
|
25636
|
+
return;
|
|
25637
|
+
}
|
|
25638
|
+
ctx.out.print(ctx.out.table([
|
|
25639
|
+
"PROCESS",
|
|
25640
|
+
"ENDPOINT",
|
|
25641
|
+
"PID",
|
|
25642
|
+
"PARENT",
|
|
25643
|
+
"COMMAND",
|
|
25644
|
+
"CWD",
|
|
25645
|
+
"IDENTITY",
|
|
25646
|
+
"STOP"
|
|
25647
|
+
], result.listeners.map((l) => [
|
|
25648
|
+
l.id,
|
|
25649
|
+
`${l.host}:${l.port}`,
|
|
25650
|
+
String(l.pid),
|
|
25651
|
+
String(l.ppid ?? "unknown"),
|
|
25652
|
+
l.command,
|
|
25653
|
+
l.cwd ?? "unavailable",
|
|
25654
|
+
l.startStamp ?? "unknown",
|
|
25655
|
+
l.refusal ?? "available"
|
|
25656
|
+
])));
|
|
25657
|
+
if (!result.listeners.length) ctx.out.print("No visible listeners on the selected exclusive TCP endpoints.");
|
|
25658
|
+
for (const warning of result.warnings) ctx.out.warn(warning);
|
|
25659
|
+
};
|
|
25660
|
+
if (!pid) {
|
|
25661
|
+
print(report);
|
|
25662
|
+
return report.warnings.length ? EXIT.failure : EXIT.ok;
|
|
25663
|
+
}
|
|
25664
|
+
const target = report.listeners.find((l) => l.pid === pid);
|
|
25665
|
+
if (!target?.token) {
|
|
25666
|
+
print(report);
|
|
25667
|
+
throw new CliExit(EXIT.failure, target?.refusal ?? `PID ${pid} is not a verified listener on the selected endpoints`);
|
|
25668
|
+
}
|
|
25669
|
+
if (!ctx.args.flags.has("--yes")) {
|
|
25670
|
+
print(report);
|
|
25671
|
+
if (!process.stdin.isTTY || ctx.out.json) throw new CliExit(EXIT.usage, "Stopping requires interactive confirmation, or --yes with --kill PID");
|
|
25672
|
+
const rl = createInterface({
|
|
25673
|
+
input: process.stdin,
|
|
25674
|
+
output: process.stdout
|
|
25675
|
+
});
|
|
25676
|
+
try {
|
|
25677
|
+
const answer = await rl.question(`${ctx.args.flags.has("--force") ? "Force kill" : "Stop"} PID ${pid} (${target.command}) on ${target.host}:${target.port}? [y/N] `);
|
|
25678
|
+
if (!/^y(es)?$/i.test(answer.trim())) return EXIT.ok;
|
|
25679
|
+
} finally {
|
|
25680
|
+
rl.close();
|
|
25681
|
+
}
|
|
25682
|
+
}
|
|
25683
|
+
const result = await inspector.run({
|
|
25684
|
+
ids,
|
|
25685
|
+
token: target.token,
|
|
25686
|
+
force: ctx.args.flags.has("--force")
|
|
25687
|
+
});
|
|
25688
|
+
print(result);
|
|
25689
|
+
return result.warnings.length ? EXIT.failure : EXIT.ok;
|
|
25690
|
+
}
|
|
25691
|
+
//#endregion
|
|
25692
|
+
//#region src/run/scheduler.ts
|
|
25693
|
+
async function runTaskPool(options) {
|
|
25694
|
+
const { failFast } = options;
|
|
25695
|
+
const pending = [...options.tasks];
|
|
25696
|
+
const succeeded = /* @__PURE__ */ new Set();
|
|
25697
|
+
const failed = /* @__PURE__ */ new Set();
|
|
25698
|
+
const running = /* @__PURE__ */ new Set();
|
|
25699
|
+
const selected = new Set(options.tasks.map((task) => task.id));
|
|
25700
|
+
const depsOf = (task) => task.dependsOn.filter((id) => selected.has(id));
|
|
25701
|
+
let cut = false;
|
|
25702
|
+
let waiters = [];
|
|
25703
|
+
const settled = () => new Promise((resolve) => {
|
|
25704
|
+
waiters.push(resolve);
|
|
25705
|
+
});
|
|
25706
|
+
const wake = () => {
|
|
25707
|
+
const current = waiters;
|
|
25708
|
+
waiters = [];
|
|
25709
|
+
for (const resolve of current) resolve();
|
|
25710
|
+
};
|
|
25711
|
+
const workers = Array.from({ length: Math.min(Math.max(1, options.parallel), pending.length) }, async () => {
|
|
25712
|
+
for (;;) {
|
|
25713
|
+
if (cut) return;
|
|
25714
|
+
const index = pending.findIndex((task) => depsOf(task).every((id) => succeeded.has(id) || failed.has(id)));
|
|
25715
|
+
if (index < 0) {
|
|
25716
|
+
if (running.size === 0) return;
|
|
25717
|
+
await settled();
|
|
25718
|
+
continue;
|
|
25719
|
+
}
|
|
25720
|
+
const [task] = pending.splice(index, 1);
|
|
25721
|
+
if (task == null) return;
|
|
25722
|
+
const blockedBy = depsOf(task).find((id) => failed.has(id));
|
|
25723
|
+
if (blockedBy != null) {
|
|
25724
|
+
failed.add(task.id);
|
|
25725
|
+
options.onBlocked(task, blockedBy);
|
|
25726
|
+
wake();
|
|
25727
|
+
continue;
|
|
25728
|
+
}
|
|
25729
|
+
running.add(task.id);
|
|
25730
|
+
const ok = await options.run(task);
|
|
25731
|
+
running.delete(task.id);
|
|
25732
|
+
(ok ? succeeded : failed).add(task.id);
|
|
25733
|
+
if (!ok && failFast && !cut) {
|
|
25734
|
+
cut = true;
|
|
25735
|
+
options.onFailFast?.();
|
|
25736
|
+
}
|
|
25737
|
+
wake();
|
|
25738
|
+
if (cut) return;
|
|
25739
|
+
}
|
|
25740
|
+
});
|
|
25741
|
+
await Promise.all(workers);
|
|
25742
|
+
return {
|
|
25743
|
+
succeeded,
|
|
25744
|
+
failed,
|
|
25745
|
+
leftover: pending
|
|
25746
|
+
};
|
|
25747
|
+
}
|
|
25748
|
+
//#endregion
|
|
25306
25749
|
//#region src/cli/commands/run.ts
|
|
25307
25750
|
const ACTIVE_STATES$1 = new Set([
|
|
25308
25751
|
"starting",
|
|
@@ -25367,14 +25810,17 @@ async function cmdRun(ctx) {
|
|
|
25367
25810
|
const bad = unknownFlags(ctx.args.flags, [
|
|
25368
25811
|
"--parallel",
|
|
25369
25812
|
"--fail-fast",
|
|
25370
|
-
"--all"
|
|
25813
|
+
"--all",
|
|
25814
|
+
"--any"
|
|
25371
25815
|
]);
|
|
25372
25816
|
if (bad != null) throw new CliExit(EXIT.usage, bad);
|
|
25373
25817
|
const parallel = numericFlag(ctx.args.flags, "--parallel");
|
|
25374
25818
|
if (parallel != null && typeof parallel === "object") throw new CliExit(EXIT.usage, parallel.error);
|
|
25375
|
-
const failFast = ctx.args.flags.has("--fail-fast");
|
|
25376
25819
|
const selection = selectOrExit(ctx, { bare: "required" });
|
|
25377
25820
|
const { out, config } = ctx;
|
|
25821
|
+
const [onlyTerm] = ctx.args.positionals.length === 1 ? ctx.args.positionals : [];
|
|
25822
|
+
const suitePolicy = onlyTerm == null ? void 0 : config.suites[onlyTerm];
|
|
25823
|
+
const failFast = ctx.args.flags.has("--fail-fast") || suitePolicy?.failFast === true;
|
|
25378
25824
|
const byId = new Map(config.processes.map((proc) => [proc.id, proc]));
|
|
25379
25825
|
const defs = selection.ordered.flatMap((id) => {
|
|
25380
25826
|
const def = byId.get(id);
|
|
@@ -25535,60 +25981,30 @@ async function cmdRun(ctx) {
|
|
|
25535
25981
|
try {
|
|
25536
25982
|
const pumps = single ? [] : procs.map((proc) => startPump(out, proc));
|
|
25537
25983
|
if (tasks.length > 0 && services.length === 0) {
|
|
25538
|
-
const
|
|
25539
|
-
|
|
25540
|
-
|
|
25541
|
-
|
|
25542
|
-
|
|
25543
|
-
const depsOf = (def) => def.dependsOn.filter((id) => selected.has(id));
|
|
25544
|
-
let waiters = [];
|
|
25545
|
-
const settled = () => new Promise((resolve) => {
|
|
25546
|
-
waiters.push(resolve);
|
|
25547
|
-
});
|
|
25548
|
-
const wake = () => {
|
|
25549
|
-
const current = waiters;
|
|
25550
|
-
waiters = [];
|
|
25551
|
-
for (const resolve of current) resolve();
|
|
25552
|
-
};
|
|
25553
|
-
const workers = Array.from({ length: Math.min(parallel ?? 1, pending.length) }, async () => {
|
|
25554
|
-
for (;;) {
|
|
25555
|
-
if (failFast && failures.length > 0) return;
|
|
25556
|
-
const index = pending.findIndex((def) => depsOf(def).every((id) => succeeded.has(id) || failed.has(id)));
|
|
25557
|
-
if (index < 0) {
|
|
25558
|
-
if (running.size === 0) return;
|
|
25559
|
-
await settled();
|
|
25560
|
-
continue;
|
|
25561
|
-
}
|
|
25562
|
-
const [def] = pending.splice(index, 1);
|
|
25563
|
-
const blockedBy = depsOf(def).find((id) => failed.has(id));
|
|
25564
|
-
if (blockedBy != null) {
|
|
25565
|
-
out.print(`${out.paint("yellow", "⊘")} ${out.accent(def.id, def.id)} blocked: "${blockedBy}" failed`);
|
|
25566
|
-
failed.add(def.id);
|
|
25567
|
-
recordFailure({
|
|
25568
|
-
id: def.id,
|
|
25569
|
-
code: 1,
|
|
25570
|
-
failed: true
|
|
25571
|
-
});
|
|
25572
|
-
wake();
|
|
25573
|
-
continue;
|
|
25574
|
-
}
|
|
25575
|
-
running.add(def.id);
|
|
25984
|
+
const pool = await runTaskPool({
|
|
25985
|
+
tasks,
|
|
25986
|
+
parallel: parallel ?? suitePolicy?.parallel ?? 1,
|
|
25987
|
+
failFast,
|
|
25988
|
+
run: async (def) => {
|
|
25576
25989
|
const result = await runTask(def);
|
|
25577
|
-
|
|
25578
|
-
|
|
25579
|
-
|
|
25580
|
-
|
|
25581
|
-
|
|
25582
|
-
|
|
25583
|
-
|
|
25584
|
-
|
|
25585
|
-
|
|
25586
|
-
}
|
|
25990
|
+
if (result.failed) recordFailure(result);
|
|
25991
|
+
return !result.failed;
|
|
25992
|
+
},
|
|
25993
|
+
onBlocked: (def, blockedBy) => {
|
|
25994
|
+
out.print(`${out.paint("yellow", "⊘")} ${out.accent(def.id, def.id)} blocked: "${blockedBy}" failed`);
|
|
25995
|
+
recordFailure({
|
|
25996
|
+
id: def.id,
|
|
25997
|
+
code: 1,
|
|
25998
|
+
failed: true
|
|
25999
|
+
});
|
|
26000
|
+
},
|
|
26001
|
+
onFailFast: () => {
|
|
26002
|
+
for (const proc of procs) if (!TERMINAL_STATES.has(proc.state)) proc.stop();
|
|
25587
26003
|
}
|
|
25588
26004
|
});
|
|
25589
|
-
|
|
25590
|
-
for (const def of
|
|
25591
|
-
const blockedBy =
|
|
26005
|
+
const { succeeded } = pool;
|
|
26006
|
+
for (const def of pool.leftover) {
|
|
26007
|
+
const blockedBy = def.dependsOn.find((id) => tasks.some((t) => t.id === id) && !succeeded.has(id)) ?? "a dependency";
|
|
25592
26008
|
out.print(`${out.paint("yellow", "⊘")} ${out.accent(def.id, def.id)} blocked: "${blockedBy}" did not succeed`);
|
|
25593
26009
|
recordFailure({
|
|
25594
26010
|
id: def.id,
|
|
@@ -25866,6 +26282,82 @@ async function cmdUi(ctx) {
|
|
|
25866
26282
|
return EXIT.ok;
|
|
25867
26283
|
}
|
|
25868
26284
|
//#endregion
|
|
26285
|
+
//#region src/daemon/savedFilters.ts
|
|
26286
|
+
const STORE_VERSION = 1;
|
|
26287
|
+
function readable(value) {
|
|
26288
|
+
const filters = value?.filters;
|
|
26289
|
+
if (!Array.isArray(filters)) return [];
|
|
26290
|
+
const clean = [];
|
|
26291
|
+
for (const entry of filters) {
|
|
26292
|
+
const query = checkSavedFilterQuery(entry);
|
|
26293
|
+
if (typeof query === "string") continue;
|
|
26294
|
+
const record = { ...entry };
|
|
26295
|
+
const name = record["name"];
|
|
26296
|
+
const lastRunAt = record["lastRunAt"];
|
|
26297
|
+
clean.push({
|
|
26298
|
+
id: savedFilterId(query),
|
|
26299
|
+
...query,
|
|
26300
|
+
pinned: record["pinned"] === true,
|
|
26301
|
+
...typeof name === "string" && name !== "" ? { name: name.slice(0, 48) } : {},
|
|
26302
|
+
...typeof lastRunAt === "number" ? { lastRunAt } : {}
|
|
26303
|
+
});
|
|
26304
|
+
}
|
|
26305
|
+
return bounded(clean);
|
|
26306
|
+
}
|
|
26307
|
+
/** Pins are kept (newest-first cap); recents are a small ring, most recently run first. */
|
|
26308
|
+
function bounded(filters) {
|
|
26309
|
+
const pins = filters.filter((filter) => filter.pinned).slice(0, 24);
|
|
26310
|
+
const recents = filters.filter((filter) => !filter.pinned).sort((a, b) => (b.lastRunAt ?? 0) - (a.lastRunAt ?? 0)).slice(0, 8);
|
|
26311
|
+
return [...pins, ...recents];
|
|
26312
|
+
}
|
|
26313
|
+
/** Missing, unreadable or corrupt all read as "nothing saved" — never a reason to fail a boot. */
|
|
26314
|
+
async function readSavedFilters(path) {
|
|
26315
|
+
try {
|
|
26316
|
+
return readable(JSON.parse(await readFile(path, "utf8")));
|
|
26317
|
+
} catch {
|
|
26318
|
+
return [];
|
|
26319
|
+
}
|
|
26320
|
+
}
|
|
26321
|
+
async function writeSavedFilters(path, filters) {
|
|
26322
|
+
await mkdir(dirname(path), {
|
|
26323
|
+
recursive: true,
|
|
26324
|
+
mode: 448
|
|
26325
|
+
});
|
|
26326
|
+
const temp = `${path}.${process.pid}.tmp`;
|
|
26327
|
+
await writeFile(temp, `${JSON.stringify({
|
|
26328
|
+
version: STORE_VERSION,
|
|
26329
|
+
filters
|
|
26330
|
+
}, null, 2)}\n`, {
|
|
26331
|
+
encoding: "utf8",
|
|
26332
|
+
mode: 384
|
|
26333
|
+
});
|
|
26334
|
+
await rename(temp, path);
|
|
26335
|
+
}
|
|
26336
|
+
/** Pure: the list that results from `change`. */
|
|
26337
|
+
function mutateSavedFilters(current, change) {
|
|
26338
|
+
if (change.kind === "remove") return current.filter((filter) => filter.id !== change.id);
|
|
26339
|
+
const id = savedFilterId(change.query);
|
|
26340
|
+
const existing = current.find((filter) => filter.id === id);
|
|
26341
|
+
const rest = current.filter((filter) => filter.id !== id);
|
|
26342
|
+
if (change.kind === "pin") {
|
|
26343
|
+
const name = change.name.trim().slice(0, 48);
|
|
26344
|
+
return bounded([{
|
|
26345
|
+
...existing,
|
|
26346
|
+
id,
|
|
26347
|
+
...change.query,
|
|
26348
|
+
pinned: true,
|
|
26349
|
+
...name !== "" ? { name } : {}
|
|
26350
|
+
}, ...rest]);
|
|
26351
|
+
}
|
|
26352
|
+
return bounded([{
|
|
26353
|
+
...existing,
|
|
26354
|
+
id,
|
|
26355
|
+
...change.query,
|
|
26356
|
+
pinned: existing?.pinned === true,
|
|
26357
|
+
lastRunAt: change.at
|
|
26358
|
+
}, ...rest]);
|
|
26359
|
+
}
|
|
26360
|
+
//#endregion
|
|
25869
26361
|
//#region src/cli.ts
|
|
25870
26362
|
const HELP = `nice-commander — one typed config, one control surface, for dev environments.
|
|
25871
26363
|
|
|
@@ -25873,8 +26365,9 @@ usage: nice-commander [--config <path>] [--json] [--no-color] [--timeout <ms>] [
|
|
|
25873
26365
|
|
|
25874
26366
|
With NO command, "ui" runs: the daemon is ensured and the browser opened. --help prints this text.
|
|
25875
26367
|
|
|
25876
|
-
selection: process ids,
|
|
25877
|
-
|
|
26368
|
+
selection: process ids, suite names, @pin names, tag=val, or --all. Several tag=val terms AND
|
|
26369
|
+
together; --any ORs them instead. A tag selection and --all never start an optIn process.
|
|
26370
|
+
Bare up/explain use the config's defaultSelection (or print the suites and exit);
|
|
25878
26371
|
bare down/restart/logs/run always require a selection — omission never means --all.
|
|
25879
26372
|
|
|
25880
26373
|
commands:
|
|
@@ -25883,12 +26376,13 @@ commands:
|
|
|
25883
26376
|
restart <sel> [--no-wait] stop + start
|
|
25884
26377
|
status [--watch] table from the live status realm
|
|
25885
26378
|
logs <sel> [-f] merged interleaved tail with colored id prefixes
|
|
25886
|
-
list config introspection (processes,
|
|
25887
|
-
explain [sel] expanded ids, auto-included deps, DAG order
|
|
26379
|
+
list config introspection (processes, suites, warnings)
|
|
26380
|
+
explain [sel] expanded ids, auto-included deps, DAG order, suite policy
|
|
25888
26381
|
env [sel] [--set N=V] [--unset N] declared env vars and their values; --clear drops
|
|
25889
26382
|
overrides. A set value is STICKY: it applies to every
|
|
25890
26383
|
later start until cleared, and never restarts anything.
|
|
25891
|
-
run <sel> [--parallel N] [--fail-fast] foreground, no daemon; tasks = local CI shape
|
|
26384
|
+
run <sel> [--parallel N] [--fail-fast] foreground, no daemon; tasks = local CI shape
|
|
26385
|
+
(a suite supplies its own parallel/fail-fast),
|
|
25892
26386
|
a single id gets raw inherited stdio (interactive).
|
|
25893
26387
|
--fail-fast = stop at the FIRST failure and stop the
|
|
25894
26388
|
survivors; without it every task still runs, every
|
|
@@ -25956,7 +26450,7 @@ async function withTimeout(ctx, run) {
|
|
|
25956
26450
|
async function main() {
|
|
25957
26451
|
const argv = process.argv.slice(2);
|
|
25958
26452
|
if (argv[0] === "daemon") {
|
|
25959
|
-
const { runCommanderDaemon } = await import("./main-
|
|
26453
|
+
const { runCommanderDaemon } = await import("./main-BBH2T2OI.mjs");
|
|
25960
26454
|
return runCommanderDaemon(argv.slice(1));
|
|
25961
26455
|
}
|
|
25962
26456
|
const parsed = parseCliArgs(argv);
|
|
@@ -25981,6 +26475,7 @@ async function main() {
|
|
|
25981
26475
|
out: createOut(parsed),
|
|
25982
26476
|
config
|
|
25983
26477
|
};
|
|
26478
|
+
if (parsed.positionals.some((term) => term.startsWith("@"))) ctx.pins = await readSavedFilters(commanderStatePaths(resolveCommanderDataDir(), config.configKey).savedFiltersPath);
|
|
25984
26479
|
const code = await withTimeout(ctx, command(ctx));
|
|
25985
26480
|
if (ctx.spawnedDaemon === true) process.exit(code);
|
|
25986
26481
|
return code;
|
|
@@ -26000,6 +26495,6 @@ main().then((code) => {
|
|
|
26000
26495
|
process.exitCode = EXIT.failure;
|
|
26001
26496
|
});
|
|
26002
26497
|
//#endregion
|
|
26003
|
-
export {
|
|
26498
|
+
export { ActionRuntime as A, stopSetWithDependencies as B, resolveCommanderDataDir as C, wsAcceptorCarrier as D, httpAcceptorCarrier as E, envVarViews as F, removeInstanceRecord as G, savedFilterId as H, overrideFingerprint as I, writeInstanceRecord as K, hashCanonical as L, createMemoryStorageAdapter_json as M, validateCommanderConfig as N, serveChannel as O, effectiveEnv as P, loadCommanderConfigFile as R, ensureStateDir as S, createRealmServerEngine as T, readInstanceRecord as U, withDependencies as V, recordDaemonAlive as W, COMMANDER_WS_PATH as _, parseLogsClientMessage as a, commanderPackageVersion as b, countOverrides as c, commanderControlDomain as d, COMMANDER_BOOTSTRAP_PATH as f, COMMANDER_TICKET_PROTOCOL_PREFIX as g, COMMANDER_TICKET_PATH as h, runTaskPool as i, RuntimeCoordinate as j, createDefaultServeLogger as k, readEnvOverrides as l, COMMANDER_LOGS_PATH as m, readSavedFilters as n, createPortInspector as o, COMMANDER_HEALTH_PATH as p, writeSavedFilters as r, applyEnvMutation as s, mutateSavedFilters as t, commanderChannel as u, commanderStatusRealm as v, createRealmAcceptor as w, commanderStatePaths as x, commanderRuntimeError as y, orderByDependency as z };
|
|
26004
26499
|
|
|
26005
26500
|
//# sourceMappingURL=cli.mjs.map
|