@nice-code/commander 0.110.0 → 0.111.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cli.cjs +351 -19
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +343 -20
- package/build/cli.mjs.map +1 -1
- package/build/client/assets/{index-DLZZdohI.css → index-B5u-kfUT.css} +1 -1
- package/build/client/assets/{index-dItAKcyH.js → index-ChNWrJqv.js} +5 -5
- package/build/client/assets/{index-dItAKcyH.js.map → index-ChNWrJqv.js.map} +1 -1
- package/build/client/index.html +2 -2
- package/build/config.cjs.map +1 -1
- package/build/config.d.cts +19 -1
- package/build/config.d.mts +19 -1
- package/build/config.mjs.map +1 -1
- package/build/{main-CVu9gjbx.cjs → main-C3BG9bju.cjs} +157 -75
- package/build/main-C3BG9bju.cjs.map +1 -0
- package/build/{main-CWWlV2U5.mjs → main-DSPhWTfM.mjs} +159 -77
- package/build/main-DSPhWTfM.mjs.map +1 -0
- package/build/types-B3WIUo4S.mjs.map +1 -1
- package/build/types-CIdWQGjF.cjs.map +1 -1
- package/package.json +6 -6
- package/build/main-CVu9gjbx.cjs.map +0 -1
- package/build/main-CWWlV2U5.mjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { cp,
|
|
3
|
-
import {
|
|
1
|
+
import { $ as savedFilterId, A as commanderRuntimeError, B as createDefaultServeLogger, D as COMMANDER_TICKET_PROTOCOL_PREFIX, F as findDaemonProcesses, G as effectiveEnv, H as createMemoryStorageAdapter_json, I as createRealmAcceptor, J as hashCanonical, K as envVarViews, L as createRealmServerEngine, M as commanderStatePaths, N as ensureStateDir, P as resolveCommanderDataDir, Q as withDependencies, R as httpAcceptorCarrier, U as wsAcceptorCarrier, V as RuntimeCoordinate, W as validateCommanderConfig, X as orderByDependency, Y as loadCommanderConfigFile, Z as stopSetWithDependencies, _ as applyEnvMutation, a as durationKey, at as writeInstanceRecord, b as commanderChannel, c as withDuration, d as writeLastStarts, et as resolveFlags, f as parseLogsClientMessage, g as signalStray, h as identifyEndpointOwner, i as runTaskPool, it as removeInstanceRecord, j as commanderPackageVersion, k as commanderStatusRealm, l as writeTaskDurations, m as createPortInspector, n as readSavedFilters, nt as readInstanceRecord, o as estimateMs, p as ancestors, q as overrideFingerprint, r as writeSavedFilters, rt as recordDaemonAlive, s as readTaskDurations, t as mutateSavedFilters, tt as runWithArgs, u as readLastStarts, v as countOverrides, x as commanderControlDomain, y as readEnvOverrides, z as serveChannel } from "./cli.mjs";
|
|
2
|
+
import { cp, readFile, realpath, rm, stat } from "node:fs/promises";
|
|
3
|
+
import { extname, isAbsolute, join, normalize, relative, resolve, sep } from "node:path";
|
|
4
4
|
import { createNiceProcess, openProcessLedger, readProcessStartStamp, signalProcessGroup, taskkillTree } from "@nice-code/process";
|
|
5
5
|
import { closeSync, createReadStream, existsSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, statSync, watch, writeFileSync, writeSync } from "node:fs";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
@@ -512,6 +512,8 @@ function projectProcess(status) {
|
|
|
512
512
|
...status.pid != null ? { pid: status.pid } : {},
|
|
513
513
|
...status.startedAt != null ? { startedAt: status.startedAt } : {},
|
|
514
514
|
...status.lastStartedAt != null ? { lastStartedAt: status.lastStartedAt } : {},
|
|
515
|
+
flags: status.flags,
|
|
516
|
+
...status.estimatedMs != null ? { estimatedMs: status.estimatedMs } : {},
|
|
515
517
|
...status.sawOutputAt != null ? { sawOutputAt: status.sawOutputAt } : {},
|
|
516
518
|
...status.lastTask != null ? { lastTask: {
|
|
517
519
|
outcome: status.lastTask.outcome,
|
|
@@ -564,6 +566,11 @@ function projectProcess(status) {
|
|
|
564
566
|
...declared.values != null ? { values: declared.values } : {},
|
|
565
567
|
source: declared.source,
|
|
566
568
|
...declared.value != null ? { value: declared.value } : {}
|
|
569
|
+
})),
|
|
570
|
+
flags: status.detail.flags.map((flag) => ({
|
|
571
|
+
name: flag.name,
|
|
572
|
+
args: flag.args,
|
|
573
|
+
...flag.description != null ? { description: flag.description } : {}
|
|
567
574
|
}))
|
|
568
575
|
}
|
|
569
576
|
};
|
|
@@ -643,13 +650,14 @@ function createControlPlane(options) {
|
|
|
643
650
|
} }), httpAcceptorCarrier()],
|
|
644
651
|
handlers: [commanderControlDomain.wrapAsLocalHandler({
|
|
645
652
|
ports: (input) => ports.run(input),
|
|
646
|
-
start: async ({ ids, wait, staggerMs, replaceSame }) => {
|
|
653
|
+
start: async ({ ids, wait, staggerMs, replaceSame, flags }) => {
|
|
647
654
|
const config = supervisor.config;
|
|
648
655
|
const ordered = orderByDependency(config.processes, withDependencies(config.processes, ids));
|
|
649
656
|
return supervisor.start(ordered, {
|
|
650
657
|
wait: wait ?? true,
|
|
651
658
|
staggerMs: staggerMs ?? 0,
|
|
652
|
-
replaceSame: replaceSame === true
|
|
659
|
+
replaceSame: replaceSame === true,
|
|
660
|
+
...flags != null ? { flags } : {}
|
|
653
661
|
});
|
|
654
662
|
},
|
|
655
663
|
stop: async ({ ids, withDependencies: alsoDependencies }) => {
|
|
@@ -662,14 +670,15 @@ function createControlPlane(options) {
|
|
|
662
670
|
warnings: [...report.warnings, `left running — still needed by other live processes: ${kept.join(", ")}`]
|
|
663
671
|
};
|
|
664
672
|
},
|
|
665
|
-
restart: async ({ ids, wait, staggerMs, replaceSame }) => {
|
|
673
|
+
restart: async ({ ids, wait, staggerMs, replaceSame, flags }) => {
|
|
666
674
|
const config = supervisor.config;
|
|
667
675
|
const ordered = orderByDependency(config.processes, withDependencies(config.processes, ids));
|
|
668
676
|
return supervisor.restart(ordered, {
|
|
669
677
|
wait: wait ?? true,
|
|
670
678
|
staggerMs: staggerMs ?? 0,
|
|
671
679
|
stopIds: ids,
|
|
672
|
-
replaceSame: replaceSame === true
|
|
680
|
+
replaceSame: replaceSame === true,
|
|
681
|
+
...flags != null ? { flags } : {}
|
|
673
682
|
});
|
|
674
683
|
},
|
|
675
684
|
runSuite: async (input) => {
|
|
@@ -700,6 +709,10 @@ function createControlPlane(options) {
|
|
|
700
709
|
ok: true,
|
|
701
710
|
warnings: await options.setEnvOverrides(input)
|
|
702
711
|
}),
|
|
712
|
+
noteRuns: async ({ runs }) => {
|
|
713
|
+
for (const run of runs) supervisor.noteForegroundRun(run);
|
|
714
|
+
return { ok: true };
|
|
715
|
+
},
|
|
703
716
|
reloadConfig: async () => {
|
|
704
717
|
await options.reloadConfig();
|
|
705
718
|
return {
|
|
@@ -766,41 +779,6 @@ function createControlPlane(options) {
|
|
|
766
779
|
};
|
|
767
780
|
}
|
|
768
781
|
//#endregion
|
|
769
|
-
//#region src/daemon/lastStarts.ts
|
|
770
|
-
const STORE_VERSION = 1;
|
|
771
|
-
/** Newest first, capped at `MAX_LAST_STARTS`. */
|
|
772
|
-
function bounded(entries) {
|
|
773
|
-
return Object.fromEntries([...entries].sort(([, a], [, b]) => b - a).slice(0, 256));
|
|
774
|
-
}
|
|
775
|
-
/** Missing, unreadable or corrupt all read as "nothing started yet" — never a reason to fail a boot. */
|
|
776
|
-
async function readLastStarts(path) {
|
|
777
|
-
try {
|
|
778
|
-
const parsed = JSON.parse(await readFile(path, "utf8"));
|
|
779
|
-
if (parsed == null || typeof parsed !== "object" || !("processes" in parsed)) return {};
|
|
780
|
-
const processes = parsed.processes;
|
|
781
|
-
if (processes == null || typeof processes !== "object" || Array.isArray(processes)) return {};
|
|
782
|
-
return bounded(Object.entries(processes).filter((entry) => typeof entry[1] === "number" && Number.isFinite(entry[1])));
|
|
783
|
-
} catch {
|
|
784
|
-
return {};
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
async function writeLastStarts(path, lastStarts) {
|
|
788
|
-
await mkdir(dirname(path), {
|
|
789
|
-
recursive: true,
|
|
790
|
-
mode: 448
|
|
791
|
-
});
|
|
792
|
-
const temp = `${path}.${process.pid}.tmp`;
|
|
793
|
-
const store = {
|
|
794
|
-
version: STORE_VERSION,
|
|
795
|
-
processes: bounded(Object.entries(lastStarts))
|
|
796
|
-
};
|
|
797
|
-
await writeFile(temp, `${JSON.stringify(store, null, 2)}\n`, {
|
|
798
|
-
encoding: "utf8",
|
|
799
|
-
mode: 384
|
|
800
|
-
});
|
|
801
|
-
await rename(temp, path);
|
|
802
|
-
}
|
|
803
|
-
//#endregion
|
|
804
782
|
//#region src/daemon/history.ts
|
|
805
783
|
/** Entries one read may return. A viewer renders a screenful; this is already generous. */
|
|
806
784
|
const MAX_HISTORY_ENTRIES = 2e3;
|
|
@@ -1332,6 +1310,12 @@ const ACTIVE_STATES = new Set([
|
|
|
1332
1310
|
]);
|
|
1333
1311
|
/** Per-process run ring bound — enough to fill the UI's 30-minute window, never a log. */
|
|
1334
1312
|
const RECENT_RUNS_CAP = 12;
|
|
1313
|
+
const NO_FLAGS = {
|
|
1314
|
+
flags: [],
|
|
1315
|
+
args: []
|
|
1316
|
+
};
|
|
1317
|
+
const sameFlags = (a, b) => a.length === b.length && a.every((flag, index) => flag === b[index]);
|
|
1318
|
+
const flagsLabel = (flags) => flags.length === 0 ? "no flags" : `flags ${flags.join(", ")}`;
|
|
1335
1319
|
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
1336
1320
|
const ENDPOINT_PROBE_MS = 250;
|
|
1337
1321
|
/** A just-stopped listener can linger for an instant; a restart must not trip over its own port. */
|
|
@@ -1365,6 +1349,8 @@ var CommanderSupervisor = class {
|
|
|
1365
1349
|
_envOverrides;
|
|
1366
1350
|
_lastStarts;
|
|
1367
1351
|
_onStart;
|
|
1352
|
+
_taskDurations;
|
|
1353
|
+
_onTaskDurations;
|
|
1368
1354
|
_stopping = false;
|
|
1369
1355
|
/** The daemon and its ancestors — never a stray, never signalled. Read once. */
|
|
1370
1356
|
_protectedPids = null;
|
|
@@ -1377,6 +1363,8 @@ var CommanderSupervisor = class {
|
|
|
1377
1363
|
this._envOverrides = options.envOverrides ?? {};
|
|
1378
1364
|
this._lastStarts = options.lastStarts ?? {};
|
|
1379
1365
|
this._onStart = options.onStart;
|
|
1366
|
+
this._taskDurations = options.taskDurations ?? {};
|
|
1367
|
+
this._onTaskDurations = options.onTaskDurations;
|
|
1380
1368
|
for (const definition of options.config.processes) this._holders.set(definition.id, this._newHolder(definition));
|
|
1381
1369
|
}
|
|
1382
1370
|
get config() {
|
|
@@ -1430,8 +1418,19 @@ var CommanderSupervisor = class {
|
|
|
1430
1418
|
_markStarted(holder) {
|
|
1431
1419
|
const at = Date.now();
|
|
1432
1420
|
holder.startedAt = at;
|
|
1421
|
+
holder.lastStartedAt = at;
|
|
1422
|
+
holder.flags = holder.procFlags ?? [];
|
|
1433
1423
|
this._onStart?.(holder.definition.id, at);
|
|
1434
1424
|
}
|
|
1425
|
+
_recordDuration(key, ms) {
|
|
1426
|
+
this._taskDurations = withDuration(this._taskDurations, key, ms);
|
|
1427
|
+
this._onTaskDurations?.(this._taskDurations);
|
|
1428
|
+
}
|
|
1429
|
+
/** Why a start that named flags did not get them: the process already runs another set. */
|
|
1430
|
+
_flagConflict(running, request) {
|
|
1431
|
+
if (request == null || sameFlags(request.flags, running)) return null;
|
|
1432
|
+
return `already running with ${flagsLabel(running)} — restart it to run with ` + flagsLabel(request.flags);
|
|
1433
|
+
}
|
|
1435
1434
|
/** Close the live tail record — idempotent; the first close wins. */
|
|
1436
1435
|
_runEnded(holder, outcome) {
|
|
1437
1436
|
const tail = holder.recentRuns[holder.recentRuns.length - 1];
|
|
@@ -1444,7 +1443,10 @@ var CommanderSupervisor = class {
|
|
|
1444
1443
|
definition,
|
|
1445
1444
|
proc: null,
|
|
1446
1445
|
envFingerprint: null,
|
|
1446
|
+
procFlags: null,
|
|
1447
1447
|
startedAt: null,
|
|
1448
|
+
lastStartedAt: this._lastStarts[definition.id] ?? null,
|
|
1449
|
+
flags: [],
|
|
1448
1450
|
stale: false,
|
|
1449
1451
|
removed: false,
|
|
1450
1452
|
blockedBy: null,
|
|
@@ -1453,6 +1455,7 @@ var CommanderSupervisor = class {
|
|
|
1453
1455
|
degradedBy: /* @__PURE__ */ new Set(),
|
|
1454
1456
|
taskTimer: null,
|
|
1455
1457
|
taskRun: null,
|
|
1458
|
+
taskRunFlags: [],
|
|
1456
1459
|
chain: Promise.resolve(),
|
|
1457
1460
|
sawOutputAt: null,
|
|
1458
1461
|
lastTask: null,
|
|
@@ -1465,15 +1468,16 @@ var CommanderSupervisor = class {
|
|
|
1465
1468
|
holder.chain = run.catch(() => {});
|
|
1466
1469
|
return run;
|
|
1467
1470
|
}
|
|
1468
|
-
_ensureProc(holder) {
|
|
1471
|
+
_ensureProc(holder, flags = NO_FLAGS) {
|
|
1469
1472
|
const definition = holder.definition;
|
|
1470
1473
|
const fingerprint = overrideFingerprint(definition, this._envOverrides);
|
|
1471
|
-
if (holder.proc != null && holder.envFingerprint !== fingerprint && !ACTIVE_STATES.has(holder.proc.state)) holder.proc = null;
|
|
1474
|
+
if (holder.proc != null && (holder.envFingerprint !== fingerprint || !sameFlags(holder.procFlags ?? [], flags.flags)) && !ACTIVE_STATES.has(holder.proc.state)) holder.proc = null;
|
|
1472
1475
|
if (holder.proc != null) return holder.proc;
|
|
1473
1476
|
holder.envFingerprint = fingerprint;
|
|
1477
|
+
holder.procFlags = flags.flags;
|
|
1474
1478
|
const proc = createNiceProcess({
|
|
1475
1479
|
id: definition.id,
|
|
1476
|
-
run: definition.run,
|
|
1480
|
+
run: runWithArgs(definition.run, flags.args),
|
|
1477
1481
|
...definition.shell != null ? { shell: definition.shell } : {},
|
|
1478
1482
|
cwd: definition.cwd,
|
|
1479
1483
|
env: effectiveEnv(definition, this._envOverrides),
|
|
@@ -1668,6 +1672,16 @@ var CommanderSupervisor = class {
|
|
|
1668
1672
|
});
|
|
1669
1673
|
continue;
|
|
1670
1674
|
}
|
|
1675
|
+
const requested = options.flags?.[id];
|
|
1676
|
+
const flags = requested == null ? null : resolveFlags(holder.definition, requested);
|
|
1677
|
+
if (flags != null && "error" in flags) {
|
|
1678
|
+
results.push({
|
|
1679
|
+
id,
|
|
1680
|
+
outcome: "failed",
|
|
1681
|
+
reason: flags.error
|
|
1682
|
+
});
|
|
1683
|
+
continue;
|
|
1684
|
+
}
|
|
1671
1685
|
let blocked = null;
|
|
1672
1686
|
let blockedOn = null;
|
|
1673
1687
|
for (const depId of holder.definition.dependsOn) {
|
|
@@ -1713,7 +1727,7 @@ var CommanderSupervisor = class {
|
|
|
1713
1727
|
holder.blockedOn = null;
|
|
1714
1728
|
let result;
|
|
1715
1729
|
if (holder.definition.kind === "task") {
|
|
1716
|
-
const run = this._runTaskOnce(holder, taskRuns, replaceSame);
|
|
1730
|
+
const run = this._runTaskOnce(holder, taskRuns, replaceSame, flags);
|
|
1717
1731
|
if (waitForReady) result = await run;
|
|
1718
1732
|
else {
|
|
1719
1733
|
run.catch(() => {});
|
|
@@ -1723,11 +1737,18 @@ var CommanderSupervisor = class {
|
|
|
1723
1737
|
};
|
|
1724
1738
|
}
|
|
1725
1739
|
} else result = await this._enqueue(holder, async () => {
|
|
1726
|
-
const proc = this._ensureProc(holder);
|
|
1727
|
-
if (ACTIVE_STATES.has(proc.state))
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1740
|
+
const proc = this._ensureProc(holder, flags ?? NO_FLAGS);
|
|
1741
|
+
if (ACTIVE_STATES.has(proc.state)) {
|
|
1742
|
+
const conflict = this._flagConflict(holder.flags, flags);
|
|
1743
|
+
return conflict == null ? {
|
|
1744
|
+
id,
|
|
1745
|
+
outcome: "already-running"
|
|
1746
|
+
} : {
|
|
1747
|
+
id,
|
|
1748
|
+
outcome: "already-running",
|
|
1749
|
+
reason: conflict
|
|
1750
|
+
};
|
|
1751
|
+
}
|
|
1731
1752
|
if (this._stopping) return {
|
|
1732
1753
|
id,
|
|
1733
1754
|
outcome: "failed",
|
|
@@ -1787,10 +1808,10 @@ var CommanderSupervisor = class {
|
|
|
1787
1808
|
* A task within ONE start transaction: task dependencies run once per transaction, so a
|
|
1788
1809
|
* repeat request inside the same action joins that run rather than starting a second one.
|
|
1789
1810
|
*/
|
|
1790
|
-
_runTaskOnce(holder, taskRuns, replaceSame = false) {
|
|
1811
|
+
_runTaskOnce(holder, taskRuns, replaceSame = false, flags = null) {
|
|
1791
1812
|
const existing = taskRuns.get(holder.definition.id);
|
|
1792
1813
|
if (existing != null) return existing;
|
|
1793
|
-
const run = this._taskRun(holder, replaceSame);
|
|
1814
|
+
const run = this._taskRun(holder, replaceSame, flags);
|
|
1794
1815
|
taskRuns.set(holder.definition.id, run);
|
|
1795
1816
|
return run;
|
|
1796
1817
|
}
|
|
@@ -1803,12 +1824,19 @@ var CommanderSupervisor = class {
|
|
|
1803
1824
|
* the task's own exit — an unbounded deadlock for a task with no `timeoutMs`, and the reason a
|
|
1804
1825
|
* wedged check could hang daemon shutdown forever (C3, edges 14/36/39).
|
|
1805
1826
|
*/
|
|
1806
|
-
_taskRun(holder, replaceSame = false) {
|
|
1807
|
-
if (holder.taskRun != null) return holder.taskRun;
|
|
1827
|
+
_taskRun(holder, replaceSame = false, flags = null) {
|
|
1808
1828
|
const id = holder.definition.id;
|
|
1829
|
+
if (holder.taskRun != null) {
|
|
1830
|
+
const conflict = this._flagConflict(holder.taskRunFlags, flags);
|
|
1831
|
+
return conflict == null ? holder.taskRun : Promise.resolve({
|
|
1832
|
+
id,
|
|
1833
|
+
outcome: "already-running",
|
|
1834
|
+
reason: conflict
|
|
1835
|
+
});
|
|
1836
|
+
}
|
|
1809
1837
|
const run = (async () => {
|
|
1810
1838
|
const failure = await this._enqueue(holder, async () => {
|
|
1811
|
-
const proc = this._ensureProc(holder);
|
|
1839
|
+
const proc = this._ensureProc(holder, flags ?? NO_FLAGS);
|
|
1812
1840
|
if (ACTIVE_STATES.has(proc.state)) return null;
|
|
1813
1841
|
if (this._stopping) return {
|
|
1814
1842
|
id,
|
|
@@ -1849,6 +1877,7 @@ var CommanderSupervisor = class {
|
|
|
1849
1877
|
if (holder.taskRun === run) holder.taskRun = null;
|
|
1850
1878
|
});
|
|
1851
1879
|
holder.taskRun = run;
|
|
1880
|
+
holder.taskRunFlags = flags?.flags ?? [];
|
|
1852
1881
|
return run;
|
|
1853
1882
|
}
|
|
1854
1883
|
/** Await a started task's exit (outside the chain, so a stop can always get through). */
|
|
@@ -1897,14 +1926,16 @@ var CommanderSupervisor = class {
|
|
|
1897
1926
|
reason = `exit ${exit.code ?? exit.signal ?? "unknown"}`;
|
|
1898
1927
|
}
|
|
1899
1928
|
const endedAt = Date.now();
|
|
1929
|
+
const durationMs = holder.startedAt != null ? endedAt - holder.startedAt : null;
|
|
1900
1930
|
holder.lastTask = {
|
|
1901
1931
|
outcome,
|
|
1902
1932
|
reason,
|
|
1903
1933
|
timedOut,
|
|
1904
1934
|
endedAt,
|
|
1905
|
-
durationMs
|
|
1935
|
+
durationMs,
|
|
1906
1936
|
definitionHash: holder.definition.definitionHash
|
|
1907
1937
|
};
|
|
1938
|
+
if (outcome === "succeeded" && durationMs != null) this._recordDuration(durationKey(id, holder.flags), durationMs);
|
|
1908
1939
|
const tail = holder.recentRuns[holder.recentRuns.length - 1];
|
|
1909
1940
|
if (tail != null) {
|
|
1910
1941
|
tail.endedAt = endedAt;
|
|
@@ -1989,8 +2020,22 @@ var CommanderSupervisor = class {
|
|
|
1989
2020
|
* restart of three frontends took the backend down with it.
|
|
1990
2021
|
*/
|
|
1991
2022
|
async restart(orderedIds, options = {}) {
|
|
1992
|
-
const
|
|
1993
|
-
const
|
|
2023
|
+
const stopIds = options.stopIds ?? orderedIds;
|
|
2024
|
+
const flags = {};
|
|
2025
|
+
for (const id of stopIds) {
|
|
2026
|
+
const holder = this._holders.get(id);
|
|
2027
|
+
if (holder == null) continue;
|
|
2028
|
+
const declared = new Set(holder.definition.flags.map((flag) => flag.name));
|
|
2029
|
+
flags[id] = options.flags?.[id] ?? holder.flags.filter((flag) => declared.has(flag));
|
|
2030
|
+
}
|
|
2031
|
+
const stopped = await this.stop(stopIds);
|
|
2032
|
+
const started = await this.start(orderedIds, {
|
|
2033
|
+
...options,
|
|
2034
|
+
flags: {
|
|
2035
|
+
...options.flags,
|
|
2036
|
+
...flags
|
|
2037
|
+
}
|
|
2038
|
+
});
|
|
1994
2039
|
return {
|
|
1995
2040
|
results: started.results.map((result) => {
|
|
1996
2041
|
const stopResult = stopped.results.find((candidate) => candidate.id === result.id);
|
|
@@ -2027,6 +2072,7 @@ var CommanderSupervisor = class {
|
|
|
2027
2072
|
if (!active) {
|
|
2028
2073
|
holder.proc = null;
|
|
2029
2074
|
holder.envFingerprint = null;
|
|
2075
|
+
holder.procFlags = null;
|
|
2030
2076
|
holder.stale = false;
|
|
2031
2077
|
}
|
|
2032
2078
|
holder.definition = definition;
|
|
@@ -2050,6 +2096,20 @@ var CommanderSupervisor = class {
|
|
|
2050
2096
|
this._envOverrides = next;
|
|
2051
2097
|
for (const holder of this._holders.values()) this._notify(holder.definition.id);
|
|
2052
2098
|
}
|
|
2099
|
+
/**
|
|
2100
|
+
* A foreground `run` of `id`: outside this daemon, so never in its status — but still "recently
|
|
2101
|
+
* started", and a success is still a sample for the estimate.
|
|
2102
|
+
*/
|
|
2103
|
+
noteForegroundRun(run) {
|
|
2104
|
+
const holder = this._holders.get(run.id);
|
|
2105
|
+
if (holder == null) return;
|
|
2106
|
+
if ((holder.lastStartedAt ?? 0) < run.startedAt) {
|
|
2107
|
+
holder.lastStartedAt = run.startedAt;
|
|
2108
|
+
this._onStart?.(run.id, run.startedAt);
|
|
2109
|
+
}
|
|
2110
|
+
if (run.durationMs != null && holder.definition.kind === "task") this._recordDuration(durationKey(run.id, run.flags), run.durationMs);
|
|
2111
|
+
this._notify(run.id);
|
|
2112
|
+
}
|
|
2053
2113
|
status() {
|
|
2054
2114
|
return [...this._holders.values()].map((holder) => {
|
|
2055
2115
|
const proc = holder.proc;
|
|
@@ -2063,7 +2123,9 @@ var CommanderSupervisor = class {
|
|
|
2063
2123
|
state,
|
|
2064
2124
|
pid: proc?.pid ?? null,
|
|
2065
2125
|
startedAt: holder.startedAt,
|
|
2066
|
-
lastStartedAt: holder.
|
|
2126
|
+
lastStartedAt: holder.lastStartedAt,
|
|
2127
|
+
flags: [...holder.flags],
|
|
2128
|
+
estimatedMs: holder.definition.kind === "task" ? estimateMs(this._taskDurations[durationKey(holder.definition.id, holder.flags)]) : null,
|
|
2067
2129
|
sawOutputAt: holder.sawOutputAt,
|
|
2068
2130
|
lastTask: holder.lastTask,
|
|
2069
2131
|
recentRuns: holder.recentRuns.map((run) => ({ ...run })),
|
|
@@ -2137,6 +2199,11 @@ function describe(definition, envVars) {
|
|
|
2137
2199
|
dependsOn: [...definition.dependsOn],
|
|
2138
2200
|
...definition.url == null ? {} : { url: definition.url },
|
|
2139
2201
|
envVars,
|
|
2202
|
+
flags: definition.flags.map((flag) => ({
|
|
2203
|
+
name: flag.name,
|
|
2204
|
+
args: flag.args.join(" "),
|
|
2205
|
+
...flag.description == null ? {} : { description: flag.description }
|
|
2206
|
+
})),
|
|
2140
2207
|
...definition.timeoutMs == null ? {} : { timeoutMs: definition.timeoutMs },
|
|
2141
2208
|
...definition.ready == null ? {} : { ready: describeReady(definition.ready) },
|
|
2142
2209
|
endpoints: definition.endpoints.map((endpoint) => ({
|
|
@@ -2188,6 +2255,24 @@ function argValue(argv, flag) {
|
|
|
2188
2255
|
const at = argv.indexOf(flag);
|
|
2189
2256
|
return at >= 0 && at + 1 < argv.length ? argv[at + 1] : null;
|
|
2190
2257
|
}
|
|
2258
|
+
/**
|
|
2259
|
+
* A store save that coalesces: a suite run starts many processes in one burst, and only the newest
|
|
2260
|
+
* value needs to land — a save queued behind a write in flight takes whatever is newest by then.
|
|
2261
|
+
*/
|
|
2262
|
+
function latestWins(write) {
|
|
2263
|
+
let latest;
|
|
2264
|
+
let queued = false;
|
|
2265
|
+
let writes = Promise.resolve();
|
|
2266
|
+
return (value) => {
|
|
2267
|
+
latest = value;
|
|
2268
|
+
if (queued) return;
|
|
2269
|
+
queued = true;
|
|
2270
|
+
writes = writes.then(() => {
|
|
2271
|
+
queued = false;
|
|
2272
|
+
return write(latest);
|
|
2273
|
+
});
|
|
2274
|
+
};
|
|
2275
|
+
}
|
|
2191
2276
|
/** Bounded global scavenger: dead-daemon ledgers in ANY config subdir get their orphans reaped. */
|
|
2192
2277
|
async function scavengeDeadDaemons(dataDir, ownConfigKey, log) {
|
|
2193
2278
|
let subdirs;
|
|
@@ -2243,20 +2328,9 @@ async function startCommanderDaemon(argv) {
|
|
|
2243
2328
|
const sink = new AggregateSink(paths.logsDir, paths.ingestSeqPath, generation);
|
|
2244
2329
|
const envOverrides = await readEnvOverrides(paths.envOverridesPath);
|
|
2245
2330
|
let lastStarts = await readLastStarts(paths.lastStartsPath);
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
const
|
|
2249
|
-
lastStarts = {
|
|
2250
|
-
...lastStarts,
|
|
2251
|
-
[id]: at
|
|
2252
|
-
};
|
|
2253
|
-
if (lastStartsQueued) return;
|
|
2254
|
-
lastStartsQueued = true;
|
|
2255
|
-
lastStartsWrites = lastStartsWrites.then(async () => {
|
|
2256
|
-
lastStartsQueued = false;
|
|
2257
|
-
await writeLastStarts(paths.lastStartsPath, lastStarts).catch((error) => log(`last starts not saved: ${error.message}`));
|
|
2258
|
-
});
|
|
2259
|
-
};
|
|
2331
|
+
const saveLastStarts = latestWins((value) => writeLastStarts(paths.lastStartsPath, value).catch((error) => log(`last starts not saved: ${error.message}`)));
|
|
2332
|
+
const taskDurations = await readTaskDurations(paths.taskDurationsPath);
|
|
2333
|
+
const saveTaskDurations = latestWins((value) => writeTaskDurations(paths.taskDurationsPath, value).catch((error) => log(`task durations not saved: ${error.message}`)));
|
|
2260
2334
|
const supervisor = new CommanderSupervisor({
|
|
2261
2335
|
config: resolved,
|
|
2262
2336
|
ledger,
|
|
@@ -2264,7 +2338,15 @@ async function startCommanderDaemon(argv) {
|
|
|
2264
2338
|
logsDir: paths.logsDir,
|
|
2265
2339
|
envOverrides,
|
|
2266
2340
|
lastStarts,
|
|
2267
|
-
onStart:
|
|
2341
|
+
onStart: (id, at) => {
|
|
2342
|
+
lastStarts = {
|
|
2343
|
+
...lastStarts,
|
|
2344
|
+
[id]: at
|
|
2345
|
+
};
|
|
2346
|
+
saveLastStarts(lastStarts);
|
|
2347
|
+
},
|
|
2348
|
+
taskDurations,
|
|
2349
|
+
onTaskDurations: saveTaskDurations
|
|
2268
2350
|
});
|
|
2269
2351
|
const token = randomUUID();
|
|
2270
2352
|
const auth = new CommanderAuth(token);
|
|
@@ -2460,7 +2542,7 @@ async function startCommanderDaemon(argv) {
|
|
|
2460
2542
|
configKey: resolved.configKey,
|
|
2461
2543
|
configRevisionHash: resolved.configRevisionHash,
|
|
2462
2544
|
configPath: resolved.configPath,
|
|
2463
|
-
protocolVersion:
|
|
2545
|
+
protocolVersion: 8,
|
|
2464
2546
|
packageVersion: await commanderPackageVersion(),
|
|
2465
2547
|
realmSchemaHash: commanderStatusRealm.schemaHash,
|
|
2466
2548
|
servesOwnClient
|
|
@@ -2549,4 +2631,4 @@ async function runCommanderDaemon(argv) {
|
|
|
2549
2631
|
//#endregion
|
|
2550
2632
|
export { runCommanderDaemon };
|
|
2551
2633
|
|
|
2552
|
-
//# sourceMappingURL=main-
|
|
2634
|
+
//# sourceMappingURL=main-DSPhWTfM.mjs.map
|