@nice-code/commander 0.104.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 +91 -9
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +91 -10
- 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-BB6yHp_S.js +0 -23
- package/build/client/assets/index-BB6yHp_S.js.map +0 -1
- package/build/client/assets/index-BEawHnvQ.css +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). */
|
|
@@ -24493,6 +24494,11 @@ const COMMANDER_TICKET_PATH = "/ticket";
|
|
|
24493
24494
|
/** CLI liveness/discovery probe (instance-record root token only). */
|
|
24494
24495
|
const COMMANDER_HEALTH_PATH = "/health";
|
|
24495
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
|
+
/**
|
|
24496
24502
|
* ws tickets ride the subprotocol negotiation (browsers cannot set arbitrary ws headers):
|
|
24497
24503
|
* the client offers `commander-auth.<ticket>`, the daemon selects it to complete the upgrade.
|
|
24498
24504
|
*/
|
|
@@ -24837,7 +24843,10 @@ async function findSkewedDaemon(config) {
|
|
|
24837
24843
|
return {
|
|
24838
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.`,
|
|
24839
24845
|
pid: skewed.pid,
|
|
24840
|
-
|
|
24846
|
+
port: skewed.port,
|
|
24847
|
+
packageVersion: skewed.packageVersion,
|
|
24848
|
+
startStamp: skewed.startStamp,
|
|
24849
|
+
servesOwnClient: skewed.servesOwnClient
|
|
24841
24850
|
};
|
|
24842
24851
|
}
|
|
24843
24852
|
/** Read-only commands' daemon-or-report: never starts anything, exit 3 when not running. */
|
|
@@ -27062,6 +27071,7 @@ async function candidates() {
|
|
|
27062
27071
|
}
|
|
27063
27072
|
/** Try each opener in turn; resolves true when one spawns without an immediate failure. */
|
|
27064
27073
|
async function openBrowser(url) {
|
|
27074
|
+
if (process.env["NICE_COMMANDER_NO_BROWSER"] === "1") return false;
|
|
27065
27075
|
for (const candidate of await candidates()) if (await new Promise((resolve) => {
|
|
27066
27076
|
try {
|
|
27067
27077
|
const child = (0, node_child_process.spawn)(candidate.command, candidate.args(url), {
|
|
@@ -27080,20 +27090,88 @@ async function openBrowser(url) {
|
|
|
27080
27090
|
}
|
|
27081
27091
|
//#endregion
|
|
27082
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;
|
|
27083
27095
|
async function cmdUi(ctx) {
|
|
27084
|
-
const bad = unknownFlags(ctx.args.flags, []);
|
|
27096
|
+
const bad = unknownFlags(ctx.args.flags, ["--fresh"]);
|
|
27085
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
|
+
}
|
|
27086
27118
|
const handle = await ensureDaemonRunning(ctx.config);
|
|
27087
27119
|
ctx.spawnedDaemon = handle.spawned;
|
|
27088
27120
|
const url = `http://127.0.0.1:${handle.record.port}`;
|
|
27089
27121
|
const opened = await openBrowser(url);
|
|
27090
|
-
if (
|
|
27122
|
+
if (out.json) out.printJson({
|
|
27091
27123
|
url,
|
|
27092
|
-
opened
|
|
27124
|
+
opened,
|
|
27125
|
+
attached: !handle.spawned
|
|
27093
27126
|
});
|
|
27094
|
-
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
|
+
}
|
|
27095
27131
|
return EXIT.ok;
|
|
27096
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
|
+
}
|
|
27097
27175
|
//#endregion
|
|
27098
27176
|
//#region src/daemon/savedFilters.ts
|
|
27099
27177
|
const STORE_VERSION = 1;
|
|
@@ -27216,7 +27294,10 @@ const COMMAND_HELP = [
|
|
|
27216
27294
|
non-zero. Children inherit THIS shell's environment;
|
|
27217
27295
|
daemon-owned processes (up) inherit the daemon's
|
|
27218
27296
|
boot-time snapshot instead — see doctor.`],
|
|
27219
|
-
["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.`],
|
|
27220
27301
|
["doctor", ` doctor [--reap] [--reap-strays [--yes] [--force]]
|
|
27221
27302
|
diagnostics: ledger, capability, endpoints (each port
|
|
27222
27303
|
owner marked STRAY or not), env.
|
|
@@ -27296,7 +27377,7 @@ async function withTimeout(ctx, run) {
|
|
|
27296
27377
|
async function main() {
|
|
27297
27378
|
const argv = process.argv.slice(2);
|
|
27298
27379
|
if (argv[0] === "daemon") {
|
|
27299
|
-
const { runCommanderDaemon } = await Promise.resolve().then(() => require("./main-
|
|
27380
|
+
const { runCommanderDaemon } = await Promise.resolve().then(() => require("./main-vXl0q1X7.cjs"));
|
|
27300
27381
|
return runCommanderDaemon(argv.slice(1));
|
|
27301
27382
|
}
|
|
27302
27383
|
const parsed = parseCliArgs(argv);
|
|
@@ -27344,6 +27425,7 @@ main().then((code) => {
|
|
|
27344
27425
|
exports.COMMANDER_BOOTSTRAP_PATH = COMMANDER_BOOTSTRAP_PATH;
|
|
27345
27426
|
exports.COMMANDER_HEALTH_PATH = COMMANDER_HEALTH_PATH;
|
|
27346
27427
|
exports.COMMANDER_LOGS_PATH = COMMANDER_LOGS_PATH;
|
|
27428
|
+
exports.COMMANDER_SHUTDOWN_PATH = COMMANDER_SHUTDOWN_PATH;
|
|
27347
27429
|
exports.COMMANDER_TICKET_PATH = COMMANDER_TICKET_PATH;
|
|
27348
27430
|
exports.COMMANDER_TICKET_PROTOCOL_PREFIX = COMMANDER_TICKET_PROTOCOL_PREFIX;
|
|
27349
27431
|
exports.COMMANDER_WS_PATH = COMMANDER_WS_PATH;
|