@nice-code/commander 0.103.0 → 0.105.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 +6 -0
- package/build/cli.cjs +118 -13
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +118 -14
- package/build/cli.mjs.map +1 -1
- package/build/client/assets/index-DLZZdohI.css +1 -0
- package/build/client/assets/index-DnkcXn4a.js +23 -0
- package/build/client/assets/index-DnkcXn4a.js.map +1 -0
- package/build/client/index.html +2 -2
- package/build/{main-KhpDJbPT.mjs → main-C5HqmZgp.mjs} +44 -4
- package/build/main-C5HqmZgp.mjs.map +1 -0
- package/build/{main-DkrkRGT6.cjs → main-vXl0q1X7.cjs} +42 -2
- package/build/main-vXl0q1X7.cjs.map +1 -0
- package/package.json +6 -6
- package/build/client/assets/index-BEawHnvQ.css +0 -1
- package/build/client/assets/index-CP-c9YFT.js +0 -23
- package/build/client/assets/index-CP-c9YFT.js.map +0 -1
- package/build/main-DkrkRGT6.cjs.map +0 -1
- package/build/main-KhpDJbPT.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -57,6 +57,12 @@ The GUI’s **shutdown daemon** button stops every task and service managed by t
|
|
|
57
57
|
including processes hidden by filters or suites, then exits the daemon. Confirm the dialog to
|
|
58
58
|
proceed. Run `nice-commander ui` to start it again.
|
|
59
59
|
|
|
60
|
+
`nice-commander ui` attaches to the daemon already running for the project, even one started by
|
|
61
|
+
an older build: each daemon serves the web UI it was built with, so upgrading the package never
|
|
62
|
+
breaks the open dashboard. `nice-commander ui --fresh` stops that daemon (and everything it runs)
|
|
63
|
+
and starts one on the installed build. If a page ever can't connect, it offers **reload** and
|
|
64
|
+
**shut down daemon** instead of a dead end.
|
|
65
|
+
|
|
60
66
|
## What it does that a script does not
|
|
61
67
|
|
|
62
68
|
- **`dependsOn` waits for *ready*, not for *spawned*** — a real readiness contract (port, HTTP,
|
package/build/cli.cjs
CHANGED
|
@@ -151,7 +151,7 @@ function validStartStamp(value) {
|
|
|
151
151
|
function isInstanceRecord(value) {
|
|
152
152
|
if (value == null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
153
153
|
const record = value;
|
|
154
|
-
return record.service === "nice-commander" && boundedString(record.instanceId) && boundedInt(record.generation, 0, Number.MAX_SAFE_INTEGER) && boundedInt(record.pid, 1, Number.MAX_SAFE_INTEGER) && boundedInt(record.port, 1, 65535) && boundedString(record.token) && boundedString(record.configKey) && boundedString(record.configRevisionHash) && boundedString(record.configPath) && boundedString(record.packageVersion) && boundedString(record.realmSchemaHash) && validStartStamp(record.startStamp) && record.protocolVersion === 7;
|
|
154
|
+
return record.service === "nice-commander" && boundedString(record.instanceId) && boundedInt(record.generation, 0, Number.MAX_SAFE_INTEGER) && boundedInt(record.pid, 1, Number.MAX_SAFE_INTEGER) && boundedInt(record.port, 1, 65535) && boundedString(record.token) && boundedString(record.configKey) && boundedString(record.configRevisionHash) && boundedString(record.configPath) && boundedString(record.packageVersion) && boundedString(record.realmSchemaHash) && validStartStamp(record.startStamp) && (record.servesOwnClient == null || typeof record.servesOwnClient === "boolean") && record.protocolVersion === 7;
|
|
155
155
|
}
|
|
156
156
|
async function writeInstanceRecord(path, record) {
|
|
157
157
|
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), {
|
|
@@ -210,7 +210,8 @@ async function readSkewedInstanceRecord(path, expectedRealmSchemaHash) {
|
|
|
210
210
|
protocolVersion: record["protocolVersion"],
|
|
211
211
|
packageVersion: boundedString(record["packageVersion"]) ? record["packageVersion"] : "unknown",
|
|
212
212
|
startStamp: validStartStamp(record["startStamp"]) ? record["startStamp"] ?? null : null,
|
|
213
|
-
skew: sameProtocol ? "realm-schema" : "protocol"
|
|
213
|
+
skew: sameProtocol ? "realm-schema" : "protocol",
|
|
214
|
+
servesOwnClient: record["servesOwnClient"] === true
|
|
214
215
|
};
|
|
215
216
|
}
|
|
216
217
|
/** Liveness only — enough to say "something is there", never enough to authorize a kill (C1). */
|
|
@@ -22166,6 +22167,20 @@ var RealmRuleTrie = class {
|
|
|
22166
22167
|
params
|
|
22167
22168
|
};
|
|
22168
22169
|
}
|
|
22170
|
+
/**
|
|
22171
|
+
* Whether some rule's pattern can match a path strictly BENEATH `path` (a `**` at or above it
|
|
22172
|
+
* counts). Ignores `view` conditions — the answer is about schema reachability, not access.
|
|
22173
|
+
*/
|
|
22174
|
+
reachesBeneath(path) {
|
|
22175
|
+
return this._reachesBeneath(this._root, path, 0);
|
|
22176
|
+
}
|
|
22177
|
+
_reachesBeneath(node, path, depth) {
|
|
22178
|
+
if (node.deep != null) return true;
|
|
22179
|
+
if (depth === path.length) return (node.lit?.size ?? 0) > 0 || node.var != null || node.star != null;
|
|
22180
|
+
const litChild = node.lit?.get(path[depth]);
|
|
22181
|
+
if (litChild != null && this._reachesBeneath(litChild, path, depth + 1)) return true;
|
|
22182
|
+
return node.var != null && this._reachesBeneath(node.var.node, path, depth + 1);
|
|
22183
|
+
}
|
|
22169
22184
|
_match(node, path, depth) {
|
|
22170
22185
|
if (depth === path.length) return node.exact;
|
|
22171
22186
|
const seg = path[depth];
|
|
@@ -22725,14 +22740,22 @@ const OMIT = {
|
|
|
22725
22740
|
value: void 0,
|
|
22726
22741
|
anyVisible: false
|
|
22727
22742
|
};
|
|
22728
|
-
|
|
22743
|
+
/** Does `path` pass through a record entry? Its containers are then data, not structure. */
|
|
22744
|
+
function underRecordEntry(schemaRoot, path) {
|
|
22745
|
+
for (let depth = 1; depth < path.length; depth++) {
|
|
22746
|
+
const parent = schemaNodeAtPath(schemaRoot, path.slice(0, depth));
|
|
22747
|
+
if (parent != null && unwrapOptional(parent).kind === "record") return true;
|
|
22748
|
+
}
|
|
22749
|
+
return false;
|
|
22750
|
+
}
|
|
22751
|
+
function pruneNode(ctx, node, value, path, inEntry = underRecordEntry(ctx.schemaRoot, path)) {
|
|
22729
22752
|
if (value === void 0) return OMIT;
|
|
22730
22753
|
const inner = unwrapOptional(node);
|
|
22731
22754
|
if (inner.kind === "object") {
|
|
22732
22755
|
const out = {};
|
|
22733
22756
|
let anyVisible = false;
|
|
22734
22757
|
for (const [key, child] of Object.entries(inner.entries)) {
|
|
22735
|
-
const pruned = pruneNode(ctx, child, value[key], [...path, key]);
|
|
22758
|
+
const pruned = pruneNode(ctx, child, value[key], [...path, key], inEntry);
|
|
22736
22759
|
if (pruned.anyVisible) {
|
|
22737
22760
|
out[key] = pruned.value;
|
|
22738
22761
|
anyVisible = true;
|
|
@@ -22747,15 +22770,16 @@ function pruneNode(ctx, node, value, path) {
|
|
|
22747
22770
|
const out = {};
|
|
22748
22771
|
let anyVisible = false;
|
|
22749
22772
|
if (value != null && typeof value === "object") for (const [key, entry] of Object.entries(value)) {
|
|
22750
|
-
const pruned = pruneNode(ctx, inner.value, entry, [...path, key]);
|
|
22773
|
+
const pruned = pruneNode(ctx, inner.value, entry, [...path, key], true);
|
|
22751
22774
|
if (pruned.anyVisible) {
|
|
22752
22775
|
out[key] = pruned.value;
|
|
22753
22776
|
anyVisible = true;
|
|
22754
22777
|
}
|
|
22755
22778
|
}
|
|
22779
|
+
const structural = !inEntry && ctx.trie.reachesBeneath(path);
|
|
22756
22780
|
return {
|
|
22757
22781
|
value: out,
|
|
22758
|
-
anyVisible: anyVisible || leafVisible(ctx, path)
|
|
22782
|
+
anyVisible: anyVisible || structural || leafVisible(ctx, path)
|
|
22759
22783
|
};
|
|
22760
22784
|
}
|
|
22761
22785
|
return leafVisible(ctx, path) ? {
|
|
@@ -24470,6 +24494,11 @@ const COMMANDER_TICKET_PATH = "/ticket";
|
|
|
24470
24494
|
/** CLI liveness/discovery probe (instance-record root token only). */
|
|
24471
24495
|
const COMMANDER_HEALTH_PATH = "/health";
|
|
24472
24496
|
/**
|
|
24497
|
+
* Plain-HTTP shutdown, capability-gated. It needs no realm, so a page from another build — one
|
|
24498
|
+
* that can never attach the status realm — can still stop the daemon it is stuck on.
|
|
24499
|
+
*/
|
|
24500
|
+
const COMMANDER_SHUTDOWN_PATH = "/shutdown";
|
|
24501
|
+
/**
|
|
24473
24502
|
* ws tickets ride the subprotocol negotiation (browsers cannot set arbitrary ws headers):
|
|
24474
24503
|
* the client offers `commander-auth.<ticket>`, the daemon selects it to complete the upgrade.
|
|
24475
24504
|
*/
|
|
@@ -24814,7 +24843,10 @@ async function findSkewedDaemon(config) {
|
|
|
24814
24843
|
return {
|
|
24815
24844
|
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.`,
|
|
24816
24845
|
pid: skewed.pid,
|
|
24817
|
-
|
|
24846
|
+
port: skewed.port,
|
|
24847
|
+
packageVersion: skewed.packageVersion,
|
|
24848
|
+
startStamp: skewed.startStamp,
|
|
24849
|
+
servesOwnClient: skewed.servesOwnClient
|
|
24818
24850
|
};
|
|
24819
24851
|
}
|
|
24820
24852
|
/** Read-only commands' daemon-or-report: never starts anything, exit 3 when not running. */
|
|
@@ -27039,6 +27071,7 @@ async function candidates() {
|
|
|
27039
27071
|
}
|
|
27040
27072
|
/** Try each opener in turn; resolves true when one spawns without an immediate failure. */
|
|
27041
27073
|
async function openBrowser(url) {
|
|
27074
|
+
if (process.env["NICE_COMMANDER_NO_BROWSER"] === "1") return false;
|
|
27042
27075
|
for (const candidate of await candidates()) if (await new Promise((resolve) => {
|
|
27043
27076
|
try {
|
|
27044
27077
|
const child = (0, node_child_process.spawn)(candidate.command, candidate.args(url), {
|
|
@@ -27057,20 +27090,88 @@ async function openBrowser(url) {
|
|
|
27057
27090
|
}
|
|
27058
27091
|
//#endregion
|
|
27059
27092
|
//#region src/cli/commands/ui.ts
|
|
27093
|
+
/** How long a wire-requested shutdown gets to finish its ladder before a signal follows it. */
|
|
27094
|
+
const FRESH_EXIT_WAIT_MS = 3e4;
|
|
27060
27095
|
async function cmdUi(ctx) {
|
|
27061
|
-
const bad = unknownFlags(ctx.args.flags, []);
|
|
27096
|
+
const bad = unknownFlags(ctx.args.flags, ["--fresh"]);
|
|
27062
27097
|
if (bad != null) throw new CliExit(EXIT.usage, bad);
|
|
27098
|
+
const { out } = ctx;
|
|
27099
|
+
if (ctx.args.flags.get("--fresh") === true) await stopExistingDaemon(ctx);
|
|
27100
|
+
else {
|
|
27101
|
+
const skewed = await findSkewedDaemon(ctx.config);
|
|
27102
|
+
if (skewed?.servesOwnClient === true) {
|
|
27103
|
+
const url = `http://127.0.0.1:${skewed.port}`;
|
|
27104
|
+
const opened = await openBrowser(url);
|
|
27105
|
+
if (out.json) out.printJson({
|
|
27106
|
+
url,
|
|
27107
|
+
opened,
|
|
27108
|
+
attached: true,
|
|
27109
|
+
daemonBuild: skewed.packageVersion
|
|
27110
|
+
});
|
|
27111
|
+
else {
|
|
27112
|
+
out.print(opened ? `opened ${url}` : `could not open a browser — visit ${url}`);
|
|
27113
|
+
out.print(out.paint("gray", `attached to the running daemon (build ${skewed.packageVersion}; this CLI is ${await commanderPackageVersion()}). \`nice-commander ui --fresh\` restarts it on this build — that stops everything it runs.`));
|
|
27114
|
+
}
|
|
27115
|
+
return EXIT.ok;
|
|
27116
|
+
}
|
|
27117
|
+
}
|
|
27063
27118
|
const handle = await ensureDaemonRunning(ctx.config);
|
|
27064
27119
|
ctx.spawnedDaemon = handle.spawned;
|
|
27065
27120
|
const url = `http://127.0.0.1:${handle.record.port}`;
|
|
27066
27121
|
const opened = await openBrowser(url);
|
|
27067
|
-
if (
|
|
27122
|
+
if (out.json) out.printJson({
|
|
27068
27123
|
url,
|
|
27069
|
-
opened
|
|
27124
|
+
opened,
|
|
27125
|
+
attached: !handle.spawned
|
|
27070
27126
|
});
|
|
27071
|
-
else
|
|
27127
|
+
else {
|
|
27128
|
+
if (handle.replaced != null) out.print(out.paint("gray", `replaced an idle daemon from build ${handle.replaced.packageVersion} (pid ${handle.replaced.pid})`));
|
|
27129
|
+
out.print(opened ? `opened ${url}` : `could not open a browser — visit ${url}`);
|
|
27130
|
+
}
|
|
27072
27131
|
return EXIT.ok;
|
|
27073
27132
|
}
|
|
27133
|
+
/**
|
|
27134
|
+
* `--fresh`: stop this config's daemon, whatever build it is, and wait until it has exited — the
|
|
27135
|
+
* boot that follows must not find (and reuse) a daemon that is still walking its ladder.
|
|
27136
|
+
* The wire goes first when it speaks our build: a signal is the fallback, because on Windows it
|
|
27137
|
+
* is a hard kill that skips the ladder.
|
|
27138
|
+
*/
|
|
27139
|
+
async function stopExistingDaemon(ctx) {
|
|
27140
|
+
const { config, out } = ctx;
|
|
27141
|
+
const live = await findDaemon(config);
|
|
27142
|
+
const skewed = live == null ? await findSkewedDaemon(config) : null;
|
|
27143
|
+
const target = live != null ? {
|
|
27144
|
+
pid: live.record.pid,
|
|
27145
|
+
startStamp: live.record.startStamp
|
|
27146
|
+
} : skewed != null ? {
|
|
27147
|
+
pid: skewed.pid,
|
|
27148
|
+
startStamp: skewed.startStamp
|
|
27149
|
+
} : null;
|
|
27150
|
+
if (target == null) return;
|
|
27151
|
+
if (!out.json) out.print(out.paint("gray", `--fresh: stopping the daemon (pid ${target.pid})…`));
|
|
27152
|
+
if (live != null) try {
|
|
27153
|
+
const client = await connectDaemon(live);
|
|
27154
|
+
try {
|
|
27155
|
+
await client.shutdown();
|
|
27156
|
+
} finally {
|
|
27157
|
+
client.dispose();
|
|
27158
|
+
}
|
|
27159
|
+
if (await waitForExit(target.pid, FRESH_EXIT_WAIT_MS)) return;
|
|
27160
|
+
} catch (error) {
|
|
27161
|
+
if (!(error instanceof CliExit)) throw error;
|
|
27162
|
+
}
|
|
27163
|
+
const result = await signalDaemonShutdown(target);
|
|
27164
|
+
if (result.outcome === "exited" || result.outcome === "not-running") return;
|
|
27165
|
+
throw new CliExit(EXIT.failure, result.outcome === "still-stopping" ? `--fresh: the daemon (pid ${target.pid}) is still stopping — retry in a moment` : `--fresh: pid ${target.pid} could not be verified as this config's daemon (possibly pid reuse), so nothing was stopped — verify it yourself, then retry`);
|
|
27166
|
+
}
|
|
27167
|
+
async function waitForExit(pid, timeoutMs) {
|
|
27168
|
+
const deadline = Date.now() + timeoutMs;
|
|
27169
|
+
while (Date.now() < deadline) {
|
|
27170
|
+
if (!pidAlive$1(pid)) return true;
|
|
27171
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
27172
|
+
}
|
|
27173
|
+
return !pidAlive$1(pid);
|
|
27174
|
+
}
|
|
27074
27175
|
//#endregion
|
|
27075
27176
|
//#region src/daemon/savedFilters.ts
|
|
27076
27177
|
const STORE_VERSION = 1;
|
|
@@ -27193,7 +27294,10 @@ const COMMAND_HELP = [
|
|
|
27193
27294
|
non-zero. Children inherit THIS shell's environment;
|
|
27194
27295
|
daemon-owned processes (up) inherit the daemon's
|
|
27195
27296
|
boot-time snapshot instead — see doctor.`],
|
|
27196
|
-
["ui",
|
|
27297
|
+
["ui", ` ui [--fresh] open the browser at this config's daemon (prints URL),
|
|
27298
|
+
starting one if none runs. A running daemon is attached
|
|
27299
|
+
to, even from an older build. --fresh stops it (and
|
|
27300
|
+
everything it runs) and starts one on this build.`],
|
|
27197
27301
|
["doctor", ` doctor [--reap] [--reap-strays [--yes] [--force]]
|
|
27198
27302
|
diagnostics: ledger, capability, endpoints (each port
|
|
27199
27303
|
owner marked STRAY or not), env.
|
|
@@ -27273,7 +27377,7 @@ async function withTimeout(ctx, run) {
|
|
|
27273
27377
|
async function main() {
|
|
27274
27378
|
const argv = process.argv.slice(2);
|
|
27275
27379
|
if (argv[0] === "daemon") {
|
|
27276
|
-
const { runCommanderDaemon } = await Promise.resolve().then(() => require("./main-
|
|
27380
|
+
const { runCommanderDaemon } = await Promise.resolve().then(() => require("./main-vXl0q1X7.cjs"));
|
|
27277
27381
|
return runCommanderDaemon(argv.slice(1));
|
|
27278
27382
|
}
|
|
27279
27383
|
const parsed = parseCliArgs(argv);
|
|
@@ -27321,6 +27425,7 @@ main().then((code) => {
|
|
|
27321
27425
|
exports.COMMANDER_BOOTSTRAP_PATH = COMMANDER_BOOTSTRAP_PATH;
|
|
27322
27426
|
exports.COMMANDER_HEALTH_PATH = COMMANDER_HEALTH_PATH;
|
|
27323
27427
|
exports.COMMANDER_LOGS_PATH = COMMANDER_LOGS_PATH;
|
|
27428
|
+
exports.COMMANDER_SHUTDOWN_PATH = COMMANDER_SHUTDOWN_PATH;
|
|
27324
27429
|
exports.COMMANDER_TICKET_PATH = COMMANDER_TICKET_PATH;
|
|
27325
27430
|
exports.COMMANDER_TICKET_PROTOCOL_PREFIX = COMMANDER_TICKET_PROTOCOL_PREFIX;
|
|
27326
27431
|
exports.COMMANDER_WS_PATH = COMMANDER_WS_PATH;
|