@nice-code/commander 0.104.0 → 0.106.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 +253 -41
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +252 -42
- package/build/cli.mjs.map +1 -1
- package/build/client/assets/index-DLZZdohI.css +1 -0
- package/build/client/assets/index-RGFhhnpd.js +23 -0
- package/build/client/assets/index-RGFhhnpd.js.map +1 -0
- package/build/client/index.html +2 -2
- package/build/{main-KhpDJbPT.mjs → main-1B7viLr8.mjs} +51 -6
- package/build/main-1B7viLr8.mjs.map +1 -0
- package/build/{main-DkrkRGT6.cjs → main-BHPsC_5Q.cjs} +49 -4
- package/build/main-BHPsC_5Q.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/build/cli.mjs
CHANGED
|
@@ -10,11 +10,11 @@ import { createJiti } from "jiti";
|
|
|
10
10
|
import { createHash, randomUUID, webcrypto } from "node:crypto";
|
|
11
11
|
import { createRequire as createRequire$1 } from "module";
|
|
12
12
|
import { WebSocket as WebSocket$1 } from "ws";
|
|
13
|
-
import { homedir, networkInterfaces } from "node:os";
|
|
14
13
|
import { execFile, spawn } from "node:child_process";
|
|
14
|
+
import { promisify } from "node:util";
|
|
15
|
+
import { homedir, networkInterfaces } from "node:os";
|
|
15
16
|
import { connect } from "node:net";
|
|
16
17
|
import { lookup } from "node:dns/promises";
|
|
17
|
-
import { promisify } from "node:util";
|
|
18
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);
|
|
@@ -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 === 7;
|
|
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.servesOwnClient == null || typeof record.servesOwnClient === "boolean") && record.protocolVersion === 7;
|
|
156
156
|
}
|
|
157
157
|
async function writeInstanceRecord(path, record) {
|
|
158
158
|
await mkdir(dirname(path), {
|
|
@@ -211,7 +211,8 @@ async function readSkewedInstanceRecord(path, expectedRealmSchemaHash) {
|
|
|
211
211
|
protocolVersion: record["protocolVersion"],
|
|
212
212
|
packageVersion: boundedString(record["packageVersion"]) ? record["packageVersion"] : "unknown",
|
|
213
213
|
startStamp: validStartStamp(record["startStamp"]) ? record["startStamp"] ?? null : null,
|
|
214
|
-
skew: sameProtocol ? "realm-schema" : "protocol"
|
|
214
|
+
skew: sameProtocol ? "realm-schema" : "protocol",
|
|
215
|
+
servesOwnClient: record["servesOwnClient"] === true
|
|
215
216
|
};
|
|
216
217
|
}
|
|
217
218
|
/** Liveness only — enough to say "something is there", never enough to authorize a kill (C1). */
|
|
@@ -24084,6 +24085,85 @@ function createRealmAcceptor(options) {
|
|
|
24084
24085
|
};
|
|
24085
24086
|
}
|
|
24086
24087
|
//#endregion
|
|
24088
|
+
//#region src/daemon/daemonProcesses.ts
|
|
24089
|
+
const exec$2 = promisify(execFile);
|
|
24090
|
+
/** `pid<space>command line` for every process this user can see. */
|
|
24091
|
+
async function processTable() {
|
|
24092
|
+
if (process.platform === "win32") {
|
|
24093
|
+
const { stdout } = await exec$2("powershell.exe", [
|
|
24094
|
+
"-NoProfile",
|
|
24095
|
+
"-NonInteractive",
|
|
24096
|
+
"-Command",
|
|
24097
|
+
"Get-CimInstance Win32_Process | ForEach-Object { \"$($_.ProcessId) $($_.CommandLine)\" }"
|
|
24098
|
+
], {
|
|
24099
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
24100
|
+
timeout: 15e3,
|
|
24101
|
+
windowsHide: true
|
|
24102
|
+
});
|
|
24103
|
+
return parseTable(stdout);
|
|
24104
|
+
}
|
|
24105
|
+
const { stdout } = await exec$2("ps", [
|
|
24106
|
+
"-axww",
|
|
24107
|
+
"-o",
|
|
24108
|
+
"pid=",
|
|
24109
|
+
"-o",
|
|
24110
|
+
"args="
|
|
24111
|
+
], {
|
|
24112
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
24113
|
+
timeout: 1e4
|
|
24114
|
+
});
|
|
24115
|
+
return parseTable(stdout);
|
|
24116
|
+
}
|
|
24117
|
+
function parseTable(text) {
|
|
24118
|
+
const rows = [];
|
|
24119
|
+
for (const line of text.split(/\r?\n/)) {
|
|
24120
|
+
const match = /^\s*(\d+)\s+(.*)$/.exec(line);
|
|
24121
|
+
if (match != null) rows.push({
|
|
24122
|
+
pid: Number(match[1]),
|
|
24123
|
+
commandLine: match[2] ?? ""
|
|
24124
|
+
});
|
|
24125
|
+
}
|
|
24126
|
+
return rows;
|
|
24127
|
+
}
|
|
24128
|
+
/**
|
|
24129
|
+
* Is this command line the daemon for `configPath` under `dataDir`? Quotes are dropped first:
|
|
24130
|
+
* Windows quotes an argument holding a space (`--data-dir "C:\…\App Data"`), `ps` does not.
|
|
24131
|
+
*/
|
|
24132
|
+
function isDaemonCommandLine(commandLine, configPath, dataDir) {
|
|
24133
|
+
const line = ` ${commandLine.replaceAll("\"", "")} `;
|
|
24134
|
+
return line.includes(` daemon --config ${configPath} `) && line.includes(` --data-dir ${dataDir} `);
|
|
24135
|
+
}
|
|
24136
|
+
/** One sentence naming record-less daemons and the one command that clears them. */
|
|
24137
|
+
function orphanMessage(orphans) {
|
|
24138
|
+
const one = orphans.length === 1;
|
|
24139
|
+
const pids = orphans.map((orphan) => orphan.pid).join(", ");
|
|
24140
|
+
const them = one ? "it" : "them";
|
|
24141
|
+
return `${one ? "a daemon" : `${orphans.length} daemons`} for this config ${one ? "is" : "are"} running without an instance record (pid ${pids}), so this CLI cannot talk to ${them}. Run \`nice-commander shutdown\` (it stops ${them} and everything ${one ? "it runs" : "they run"}), then retry.`;
|
|
24142
|
+
}
|
|
24143
|
+
/**
|
|
24144
|
+
* Every live daemon process for this config and data dir, except `excludePid` (a daemon asking
|
|
24145
|
+
* about its peers, or a caller that already holds the recorded one). Best effort: a process
|
|
24146
|
+
* table that cannot be read answers "none", never an error — this is a fallback, not the path.
|
|
24147
|
+
*/
|
|
24148
|
+
async function findDaemonProcesses(configPath, dataDir, excludePid) {
|
|
24149
|
+
let table;
|
|
24150
|
+
try {
|
|
24151
|
+
table = await processTable();
|
|
24152
|
+
} catch {
|
|
24153
|
+
return [];
|
|
24154
|
+
}
|
|
24155
|
+
const found = [];
|
|
24156
|
+
for (const row of table) {
|
|
24157
|
+
if (row.pid === process.pid || row.pid === excludePid) continue;
|
|
24158
|
+
if (!isDaemonCommandLine(row.commandLine, configPath, dataDir)) continue;
|
|
24159
|
+
found.push({
|
|
24160
|
+
pid: row.pid,
|
|
24161
|
+
startStamp: await readProcessStartStamp(row.pid)
|
|
24162
|
+
});
|
|
24163
|
+
}
|
|
24164
|
+
return found;
|
|
24165
|
+
}
|
|
24166
|
+
//#endregion
|
|
24087
24167
|
//#region src/daemon/dataDir.ts
|
|
24088
24168
|
function resolveCommanderDataDir(environment = process.env, platform = process.platform) {
|
|
24089
24169
|
const override = environment["NICE_COMMANDER_DATA_DIR"];
|
|
@@ -24408,6 +24488,16 @@ async function replaceSkewedDaemon(paths, skewed) {
|
|
|
24408
24488
|
case "identity-unverified": throw new Error(`${daemonLabel}, but pid ${skewed.pid} could not be verified as that daemon (start stamp missing or changed — possibly pid reuse). Nothing was killed. Verify the pid yourself, and if the daemon is really gone remove ${paths.instanceRecordPath}.`);
|
|
24409
24489
|
}
|
|
24410
24490
|
}
|
|
24491
|
+
/** How long `ensureDaemon` lets a record-less daemon finish exiting before calling it an orphan. */
|
|
24492
|
+
const ORPHAN_GRACE_MS = 5e3;
|
|
24493
|
+
async function waitForOrphansToExit(configPath, dataDir, recordedPid) {
|
|
24494
|
+
const deadline = Date.now() + ORPHAN_GRACE_MS;
|
|
24495
|
+
for (;;) {
|
|
24496
|
+
const orphans = await findDaemonProcesses(configPath, dataDir, recordedPid);
|
|
24497
|
+
if (orphans.length === 0 || Date.now() > deadline) return orphans;
|
|
24498
|
+
await new Promise((resolveWait) => setTimeout(resolveWait, 250));
|
|
24499
|
+
}
|
|
24500
|
+
}
|
|
24411
24501
|
async function ensureDaemon(options) {
|
|
24412
24502
|
const runtimeError = commanderRuntimeError();
|
|
24413
24503
|
if (runtimeError != null) throw new Error(runtimeError);
|
|
@@ -24429,6 +24519,9 @@ async function ensureDaemon(options) {
|
|
|
24429
24519
|
const skewed = await readSkewedInstanceRecord(paths.instanceRecordPath, commanderStatusRealm.schemaHash);
|
|
24430
24520
|
if (skewed != null && pidAlive$1(skewed.pid)) replaced = await replaceSkewedDaemon(paths, skewed);
|
|
24431
24521
|
}
|
|
24522
|
+
const recordedPid = existing != null ? existing.pid : void 0;
|
|
24523
|
+
const orphans = await waitForOrphansToExit(options.config.configPath, dataDir, recordedPid);
|
|
24524
|
+
if (orphans.length > 0) throw new Error(orphanMessage(orphans));
|
|
24432
24525
|
await ensureStateDir(paths);
|
|
24433
24526
|
const bootFd = openSync(paths.bootLogPath, "w", 384);
|
|
24434
24527
|
const child = spawn(process.execPath, [
|
|
@@ -24494,6 +24587,11 @@ const COMMANDER_TICKET_PATH = "/ticket";
|
|
|
24494
24587
|
/** CLI liveness/discovery probe (instance-record root token only). */
|
|
24495
24588
|
const COMMANDER_HEALTH_PATH = "/health";
|
|
24496
24589
|
/**
|
|
24590
|
+
* Plain-HTTP shutdown, capability-gated. It needs no realm, so a page from another build — one
|
|
24591
|
+
* that can never attach the status realm — can still stop the daemon it is stuck on.
|
|
24592
|
+
*/
|
|
24593
|
+
const COMMANDER_SHUTDOWN_PATH = "/shutdown";
|
|
24594
|
+
/**
|
|
24497
24595
|
* ws tickets ride the subprotocol negotiation (browsers cannot set arbitrary ws headers):
|
|
24498
24596
|
* the client offers `commander-auth.<ticket>`, the daemon selects it to complete the upgrade.
|
|
24499
24597
|
*/
|
|
@@ -24838,15 +24936,27 @@ async function findSkewedDaemon(config) {
|
|
|
24838
24936
|
return {
|
|
24839
24937
|
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.`,
|
|
24840
24938
|
pid: skewed.pid,
|
|
24841
|
-
|
|
24939
|
+
port: skewed.port,
|
|
24940
|
+
packageVersion: skewed.packageVersion,
|
|
24941
|
+
startStamp: skewed.startStamp,
|
|
24942
|
+
servesOwnClient: skewed.servesOwnClient
|
|
24842
24943
|
};
|
|
24843
24944
|
}
|
|
24945
|
+
/**
|
|
24946
|
+
* This config's daemons that no instance record points at (see `daemonProcesses.ts`). The CLI
|
|
24947
|
+
* cannot talk to them — no token — but it can name them, and `shutdown` can stop them.
|
|
24948
|
+
*/
|
|
24949
|
+
async function findOrphanDaemons(config, recordedPid) {
|
|
24950
|
+
return findDaemonProcesses(config.configPath, resolveCommanderDataDir(), recordedPid);
|
|
24951
|
+
}
|
|
24844
24952
|
/** Read-only commands' daemon-or-report: never starts anything, exit 3 when not running. */
|
|
24845
24953
|
async function requireDaemon(config) {
|
|
24846
24954
|
const handle = await findDaemon(config);
|
|
24847
24955
|
if (handle != null) return handle;
|
|
24848
24956
|
const skewed = await findSkewedDaemon(config);
|
|
24849
24957
|
if (skewed != null) throw new CliExit(EXIT.notRunning, skewed.message);
|
|
24958
|
+
const orphans = await findOrphanDaemons(config);
|
|
24959
|
+
if (orphans.length > 0) throw new CliExit(EXIT.notRunning, orphanMessage(orphans));
|
|
24850
24960
|
throw new CliExit(EXIT.notRunning, `daemon not running for "${config.name}" (start one with \`up\`)`);
|
|
24851
24961
|
}
|
|
24852
24962
|
/** `up`/`ui`'s spawn-or-reuse; the daemon child reruns THIS bin (`daemon` subcommand). */
|
|
@@ -25137,17 +25247,47 @@ async function cmdRestart(ctx) {
|
|
|
25137
25247
|
async function cmdShutdown(ctx) {
|
|
25138
25248
|
const bad = unknownFlags(ctx.args.flags, []);
|
|
25139
25249
|
if (bad != null) throw new CliExit(EXIT.usage, bad);
|
|
25140
|
-
const { out } = ctx;
|
|
25141
|
-
const
|
|
25142
|
-
|
|
25250
|
+
const { out, config } = ctx;
|
|
25251
|
+
const reports = [];
|
|
25252
|
+
let code = null;
|
|
25253
|
+
let recordedPid;
|
|
25254
|
+
const handle = await findDaemon(config);
|
|
25255
|
+
if (handle != null) {
|
|
25256
|
+
recordedPid = handle.record.pid;
|
|
25257
|
+
code = await shutdownRecorded(ctx, handle, reports);
|
|
25258
|
+
} else {
|
|
25259
|
+
const skewed = await findSkewedDaemon(config);
|
|
25260
|
+
if (skewed != null) {
|
|
25261
|
+
recordedPid = skewed.pid;
|
|
25262
|
+
if (!out.json) out.print(out.paint("gray", skewed.message));
|
|
25263
|
+
code = reportSignalShutdown(ctx, await signalDaemonShutdown({
|
|
25264
|
+
pid: skewed.pid,
|
|
25265
|
+
startStamp: skewed.startStamp
|
|
25266
|
+
}), "could not be reached over the wire", reports);
|
|
25267
|
+
}
|
|
25268
|
+
}
|
|
25269
|
+
for (const orphan of await findOrphanDaemons(config, recordedPid)) {
|
|
25270
|
+
const next = reportSignalShutdown(ctx, await signalDaemonShutdown(orphan), "was running without an instance record (the CLI had lost track of it)", reports);
|
|
25271
|
+
code = code == null ? next : Math.max(code, next);
|
|
25272
|
+
}
|
|
25273
|
+
if (code == null) throw new CliExit(EXIT.notRunning, `daemon not running for "${config.name}"`);
|
|
25274
|
+
if (out.json) out.printJson(reports.length === 1 ? reports[0] : {
|
|
25275
|
+
ok: reports.every((report) => report["ok"] === true),
|
|
25276
|
+
daemons: reports
|
|
25277
|
+
});
|
|
25278
|
+
return code;
|
|
25279
|
+
}
|
|
25280
|
+
/** The recorded daemon: the wire first (the graceful ask), a verified signal when it refuses. */
|
|
25281
|
+
async function shutdownRecorded(ctx, handle, reports) {
|
|
25282
|
+
try {
|
|
25143
25283
|
const client = await connectDaemon(handle);
|
|
25144
25284
|
try {
|
|
25145
25285
|
await client.shutdown();
|
|
25146
|
-
|
|
25286
|
+
reports.push({
|
|
25147
25287
|
ok: true,
|
|
25148
25288
|
via: "wire"
|
|
25149
25289
|
});
|
|
25150
|
-
|
|
25290
|
+
if (!ctx.out.json) ctx.out.print(`daemon for "${ctx.config.name}" is shutting down`);
|
|
25151
25291
|
return EXIT.ok;
|
|
25152
25292
|
} finally {
|
|
25153
25293
|
client.dispose();
|
|
@@ -25157,42 +25297,33 @@ async function cmdShutdown(ctx) {
|
|
|
25157
25297
|
return reportSignalShutdown(ctx, await signalDaemonShutdown({
|
|
25158
25298
|
pid: handle.record.pid,
|
|
25159
25299
|
startStamp: handle.record.startStamp
|
|
25160
|
-
}));
|
|
25300
|
+
}), "could not be reached over the wire", reports);
|
|
25161
25301
|
}
|
|
25162
|
-
const skewed = await findSkewedDaemon(ctx.config);
|
|
25163
|
-
if (skewed != null) {
|
|
25164
|
-
if (!out.json) out.print(out.paint("gray", skewed.message));
|
|
25165
|
-
return reportSignalShutdown(ctx, await signalDaemonShutdown({
|
|
25166
|
-
pid: skewed.pid,
|
|
25167
|
-
startStamp: skewed.startStamp
|
|
25168
|
-
}));
|
|
25169
|
-
}
|
|
25170
|
-
throw new CliExit(EXIT.notRunning, `daemon not running for "${ctx.config.name}"`);
|
|
25171
25302
|
}
|
|
25172
|
-
function reportSignalShutdown(ctx, result) {
|
|
25303
|
+
function reportSignalShutdown(ctx, result, why, reports) {
|
|
25173
25304
|
const { out } = ctx;
|
|
25174
|
-
|
|
25175
|
-
|
|
25176
|
-
|
|
25177
|
-
|
|
25178
|
-
|
|
25179
|
-
|
|
25180
|
-
|
|
25181
|
-
}
|
|
25305
|
+
const code = result.outcome === "exited" || result.outcome === "not-running" ? EXIT.ok : EXIT.failure;
|
|
25306
|
+
reports.push({
|
|
25307
|
+
ok: result.outcome === "exited",
|
|
25308
|
+
via: "signal",
|
|
25309
|
+
...result
|
|
25310
|
+
});
|
|
25311
|
+
if (out.json) return code;
|
|
25182
25312
|
switch (result.outcome) {
|
|
25183
25313
|
case "exited":
|
|
25184
|
-
out.print(`daemon for "${ctx.config.name}" (pid ${result.pid})
|
|
25185
|
-
|
|
25314
|
+
out.print(`daemon for "${ctx.config.name}" (pid ${result.pid}) ${why} — stopped via signal (its own shutdown ladder ran)`);
|
|
25315
|
+
break;
|
|
25186
25316
|
case "still-stopping":
|
|
25187
25317
|
out.print(out.paint("yellow", `⚠ daemon (pid ${result.pid}) was signalled and is still stopping — run \`shutdown\` again to escalate if it stays stuck`));
|
|
25188
|
-
|
|
25318
|
+
break;
|
|
25189
25319
|
case "identity-unverified":
|
|
25190
|
-
out.print(out.paint("yellow", `⚠ pid ${result.pid} could not be verified as
|
|
25191
|
-
|
|
25320
|
+
out.print(out.paint("yellow", `⚠ pid ${result.pid} could not be verified as this config's daemon (start stamp missing or changed — possibly pid reuse). Nothing was killed; verify the pid yourself, and remove the instance record if the daemon is really gone.`));
|
|
25321
|
+
break;
|
|
25192
25322
|
case "not-running":
|
|
25193
25323
|
out.print(`daemon not running for "${ctx.config.name}" (stale record)`);
|
|
25194
|
-
|
|
25324
|
+
break;
|
|
25195
25325
|
}
|
|
25326
|
+
return code;
|
|
25196
25327
|
}
|
|
25197
25328
|
//#endregion
|
|
25198
25329
|
//#region src/daemon/envOverrides.ts
|
|
@@ -27063,6 +27194,7 @@ async function candidates() {
|
|
|
27063
27194
|
}
|
|
27064
27195
|
/** Try each opener in turn; resolves true when one spawns without an immediate failure. */
|
|
27065
27196
|
async function openBrowser(url) {
|
|
27197
|
+
if (process.env["NICE_COMMANDER_NO_BROWSER"] === "1") return false;
|
|
27066
27198
|
for (const candidate of await candidates()) if (await new Promise((resolve) => {
|
|
27067
27199
|
try {
|
|
27068
27200
|
const child = spawn(candidate.command, candidate.args(url), {
|
|
@@ -27081,20 +27213,95 @@ async function openBrowser(url) {
|
|
|
27081
27213
|
}
|
|
27082
27214
|
//#endregion
|
|
27083
27215
|
//#region src/cli/commands/ui.ts
|
|
27216
|
+
/** How long a wire-requested shutdown gets to finish its ladder before a signal follows it. */
|
|
27217
|
+
const FRESH_EXIT_WAIT_MS = 3e4;
|
|
27084
27218
|
async function cmdUi(ctx) {
|
|
27085
|
-
const bad = unknownFlags(ctx.args.flags, []);
|
|
27219
|
+
const bad = unknownFlags(ctx.args.flags, ["--fresh"]);
|
|
27086
27220
|
if (bad != null) throw new CliExit(EXIT.usage, bad);
|
|
27221
|
+
const { out } = ctx;
|
|
27222
|
+
if (ctx.args.flags.get("--fresh") === true) await stopExistingDaemon(ctx);
|
|
27223
|
+
else {
|
|
27224
|
+
const skewed = await findSkewedDaemon(ctx.config);
|
|
27225
|
+
if (skewed?.servesOwnClient === true) {
|
|
27226
|
+
const url = `http://127.0.0.1:${skewed.port}`;
|
|
27227
|
+
const opened = await openBrowser(url);
|
|
27228
|
+
if (out.json) out.printJson({
|
|
27229
|
+
url,
|
|
27230
|
+
opened,
|
|
27231
|
+
attached: true,
|
|
27232
|
+
daemonBuild: skewed.packageVersion
|
|
27233
|
+
});
|
|
27234
|
+
else {
|
|
27235
|
+
out.print(opened ? `opened ${url}` : `could not open a browser — visit ${url}`);
|
|
27236
|
+
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.`));
|
|
27237
|
+
}
|
|
27238
|
+
return EXIT.ok;
|
|
27239
|
+
}
|
|
27240
|
+
}
|
|
27087
27241
|
const handle = await ensureDaemonRunning(ctx.config);
|
|
27088
27242
|
ctx.spawnedDaemon = handle.spawned;
|
|
27089
27243
|
const url = `http://127.0.0.1:${handle.record.port}`;
|
|
27090
27244
|
const opened = await openBrowser(url);
|
|
27091
|
-
if (
|
|
27245
|
+
if (out.json) out.printJson({
|
|
27092
27246
|
url,
|
|
27093
|
-
opened
|
|
27247
|
+
opened,
|
|
27248
|
+
attached: !handle.spawned
|
|
27094
27249
|
});
|
|
27095
|
-
else
|
|
27250
|
+
else {
|
|
27251
|
+
if (handle.replaced != null) out.print(out.paint("gray", `replaced an idle daemon from build ${handle.replaced.packageVersion} (pid ${handle.replaced.pid})`));
|
|
27252
|
+
out.print(opened ? `opened ${url}` : `could not open a browser — visit ${url}`);
|
|
27253
|
+
}
|
|
27096
27254
|
return EXIT.ok;
|
|
27097
27255
|
}
|
|
27256
|
+
/**
|
|
27257
|
+
* `--fresh`: stop this config's daemon, whatever build it is, and wait until it has exited — the
|
|
27258
|
+
* boot that follows must not find (and reuse) a daemon that is still walking its ladder.
|
|
27259
|
+
* The wire goes first when it speaks our build: a signal is the fallback, because on Windows it
|
|
27260
|
+
* is a hard kill that skips the ladder.
|
|
27261
|
+
*/
|
|
27262
|
+
async function stopExistingDaemon(ctx) {
|
|
27263
|
+
const { config, out } = ctx;
|
|
27264
|
+
const live = await findDaemon(config);
|
|
27265
|
+
const skewed = live == null ? await findSkewedDaemon(config) : null;
|
|
27266
|
+
const recorded = live != null ? {
|
|
27267
|
+
pid: live.record.pid,
|
|
27268
|
+
startStamp: live.record.startStamp
|
|
27269
|
+
} : skewed != null ? {
|
|
27270
|
+
pid: skewed.pid,
|
|
27271
|
+
startStamp: skewed.startStamp
|
|
27272
|
+
} : null;
|
|
27273
|
+
const targets = [...recorded != null ? [recorded] : [], ...await findOrphanDaemons(config, recorded?.pid)];
|
|
27274
|
+
for (const target of targets) {
|
|
27275
|
+
if (!out.json) out.print(out.paint("gray", `--fresh: stopping the daemon (pid ${target.pid})…`));
|
|
27276
|
+
if (target === recorded && live != null && await stopOverWire(live)) continue;
|
|
27277
|
+
const result = await signalDaemonShutdown(target);
|
|
27278
|
+
if (result.outcome === "exited" || result.outcome === "not-running") continue;
|
|
27279
|
+
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`);
|
|
27280
|
+
}
|
|
27281
|
+
}
|
|
27282
|
+
/** The graceful ask; false when the wire refuses us or the ladder outlasts the wait. */
|
|
27283
|
+
async function stopOverWire(live) {
|
|
27284
|
+
try {
|
|
27285
|
+
const client = await connectDaemon(live);
|
|
27286
|
+
try {
|
|
27287
|
+
await client.shutdown();
|
|
27288
|
+
} finally {
|
|
27289
|
+
client.dispose();
|
|
27290
|
+
}
|
|
27291
|
+
} catch (error) {
|
|
27292
|
+
if (!(error instanceof CliExit)) throw error;
|
|
27293
|
+
return false;
|
|
27294
|
+
}
|
|
27295
|
+
return waitForExit(live.record.pid, FRESH_EXIT_WAIT_MS);
|
|
27296
|
+
}
|
|
27297
|
+
async function waitForExit(pid, timeoutMs) {
|
|
27298
|
+
const deadline = Date.now() + timeoutMs;
|
|
27299
|
+
while (Date.now() < deadline) {
|
|
27300
|
+
if (!pidAlive$1(pid)) return true;
|
|
27301
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
27302
|
+
}
|
|
27303
|
+
return !pidAlive$1(pid);
|
|
27304
|
+
}
|
|
27098
27305
|
//#endregion
|
|
27099
27306
|
//#region src/daemon/savedFilters.ts
|
|
27100
27307
|
const STORE_VERSION = 1;
|
|
@@ -27217,7 +27424,10 @@ const COMMAND_HELP = [
|
|
|
27217
27424
|
non-zero. Children inherit THIS shell's environment;
|
|
27218
27425
|
daemon-owned processes (up) inherit the daemon's
|
|
27219
27426
|
boot-time snapshot instead — see doctor.`],
|
|
27220
|
-
["ui",
|
|
27427
|
+
["ui", ` ui [--fresh] open the browser at this config's daemon (prints URL),
|
|
27428
|
+
starting one if none runs. A running daemon is attached
|
|
27429
|
+
to, even from an older build. --fresh stops it (and
|
|
27430
|
+
everything it runs) and starts one on this build.`],
|
|
27221
27431
|
["doctor", ` doctor [--reap] [--reap-strays [--yes] [--force]]
|
|
27222
27432
|
diagnostics: ledger, capability, endpoints (each port
|
|
27223
27433
|
owner marked STRAY or not), env.
|
|
@@ -27297,7 +27507,7 @@ async function withTimeout(ctx, run) {
|
|
|
27297
27507
|
async function main() {
|
|
27298
27508
|
const argv = process.argv.slice(2);
|
|
27299
27509
|
if (argv[0] === "daemon") {
|
|
27300
|
-
const { runCommanderDaemon } = await import("./main-
|
|
27510
|
+
const { runCommanderDaemon } = await import("./main-1B7viLr8.mjs");
|
|
27301
27511
|
return runCommanderDaemon(argv.slice(1));
|
|
27302
27512
|
}
|
|
27303
27513
|
const parsed = parseCliArgs(argv);
|
|
@@ -27342,6 +27552,6 @@ main().then((code) => {
|
|
|
27342
27552
|
process.exitCode = EXIT.failure;
|
|
27343
27553
|
});
|
|
27344
27554
|
//#endregion
|
|
27345
|
-
export {
|
|
27555
|
+
export { createRealmServerEngine as A, overrideFingerprint as B, commanderRuntimeError as C, resolveCommanderDataDir as D, ensureStateDir as E, createMemoryStorageAdapter_json as F, withDependencies as G, loadCommanderConfigFile as H, wsAcceptorCarrier as I, recordDaemonAlive as J, savedFilterId as K, validateCommanderConfig as L, serveChannel as M, createDefaultServeLogger as N, findDaemonProcesses as O, RuntimeCoordinate as P, effectiveEnv as R, commanderStatusRealm as S, commanderStatePaths as T, orderByDependency as U, hashCanonical as V, stopSetWithDependencies as W, writeInstanceRecord as X, removeInstanceRecord as Y, COMMANDER_LOGS_PATH as _, parseLogsClientMessage as a, COMMANDER_TICKET_PROTOCOL_PREFIX as b, identifyEndpointOwner as c, countOverrides as d, readEnvOverrides as f, COMMANDER_HEALTH_PATH as g, COMMANDER_BOOTSTRAP_PATH as h, runTaskPool as i, httpAcceptorCarrier as j, createRealmAcceptor as k, signalStray as l, commanderControlDomain as m, readSavedFilters as n, ancestors as o, commanderChannel as p, readInstanceRecord as q, writeSavedFilters as r, createPortInspector as s, mutateSavedFilters as t, applyEnvMutation as u, COMMANDER_SHUTDOWN_PATH as v, commanderPackageVersion as w, COMMANDER_WS_PATH as x, COMMANDER_TICKET_PATH as y, envVarViews as z };
|
|
27346
27556
|
|
|
27347
27557
|
//# sourceMappingURL=cli.mjs.map
|