@nice-code/commander 0.70.1 → 0.71.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 +527 -28
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +522 -29
- package/build/cli.mjs.map +1 -1
- package/build/client/assets/index-CQFZypxP.js +13 -0
- package/build/client/assets/{index-CGcBzzm0.js.map → index-CQFZypxP.js.map} +1 -1
- package/build/client/index.html +1 -1
- package/build/config.cjs.map +1 -1
- package/build/config.d.cts +30 -2
- package/build/config.d.mts +30 -2
- package/build/config.mjs.map +1 -1
- package/build/{main-r_PeNn4s.mjs → main-BUB2LNcg.mjs} +62 -10
- package/build/main-BUB2LNcg.mjs.map +1 -0
- package/build/{main-Cq4RCzSk.cjs → main-Cqij6RwE.cjs} +61 -9
- package/build/main-Cqij6RwE.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-CGcBzzm0.js +0 -12
- package/build/main-Cq4RCzSk.cjs.map +0 -1
- package/build/main-r_PeNn4s.mjs.map +0 -1
package/build/cli.cjs
CHANGED
|
@@ -19,6 +19,12 @@ let node_net = require("node:net");
|
|
|
19
19
|
//#region src/cli/args.ts
|
|
20
20
|
const GLOBAL_VALUE_FLAGS = new Set(["--config", "--timeout"]);
|
|
21
21
|
/**
|
|
22
|
+
* Flags that ACCUMULATE instead of overwriting. `env --set A=1 --set B=2` has to mean both, and a
|
|
23
|
+
* plain Map keeps only the last. The name still lands in `flags` so `unknownFlags` keeps rejecting
|
|
24
|
+
* it on every command that does not accept it.
|
|
25
|
+
*/
|
|
26
|
+
const REPEATABLE_VALUE_FLAGS = new Set(["--set", "--unset"]);
|
|
27
|
+
/**
|
|
22
28
|
* Per-command flags that take a VALUE. Everything else is boolean — and that distinction is
|
|
23
29
|
* load-bearing: a greedy "consume the next token" parse turned `up --no-wait demo` into
|
|
24
30
|
* `--no-wait="demo"` with NO positionals, which fell through to `defaultSelection` and started
|
|
@@ -27,6 +33,7 @@ const GLOBAL_VALUE_FLAGS = new Set(["--config", "--timeout"]);
|
|
|
27
33
|
const COMMAND_VALUE_FLAGS = new Set(["--parallel"]);
|
|
28
34
|
function parseCliArgs(argv) {
|
|
29
35
|
const flags = /* @__PURE__ */ new Map();
|
|
36
|
+
const repeated = /* @__PURE__ */ new Map();
|
|
30
37
|
const positionals = [];
|
|
31
38
|
let command = null;
|
|
32
39
|
let json = false;
|
|
@@ -58,6 +65,16 @@ function parseCliArgs(argv) {
|
|
|
58
65
|
else help = true;
|
|
59
66
|
continue;
|
|
60
67
|
}
|
|
68
|
+
if (REPEATABLE_VALUE_FLAGS.has(arg)) {
|
|
69
|
+
const value = inlineValue ?? argv[i + 1];
|
|
70
|
+
if (value == null || value.startsWith("--")) return { error: `flag ${arg} needs a value` };
|
|
71
|
+
const values = repeated.get(arg) ?? [];
|
|
72
|
+
values.push(value);
|
|
73
|
+
repeated.set(arg, values);
|
|
74
|
+
flags.set(arg, value);
|
|
75
|
+
if (inlineValue == null) i += 1;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
61
78
|
if (arg.startsWith("--")) {
|
|
62
79
|
if (inlineValue != null) {
|
|
63
80
|
flags.set(arg, inlineValue);
|
|
@@ -87,7 +104,8 @@ function parseCliArgs(argv) {
|
|
|
87
104
|
json,
|
|
88
105
|
noColor,
|
|
89
106
|
help,
|
|
90
|
-
flags
|
|
107
|
+
flags,
|
|
108
|
+
repeated
|
|
91
109
|
};
|
|
92
110
|
if (configPath != null) args.configPath = configPath;
|
|
93
111
|
if (timeoutMs != null) args.timeoutMs = timeoutMs;
|
|
@@ -318,6 +336,148 @@ function hashCanonical(value, length = 16) {
|
|
|
318
336
|
function configKeyFor(name, configRealpath) {
|
|
319
337
|
return `${name}-${hashCanonical(configRealpath, 8)}`;
|
|
320
338
|
}
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region src/config/envVars.ts
|
|
341
|
+
/**
|
|
342
|
+
* Names that hold credentials often enough that publishing one by accident is the bigger risk.
|
|
343
|
+
* Matched case-insensitively; `secret: false` is the explicit opt-out.
|
|
344
|
+
*/
|
|
345
|
+
const SECRET_NAME = /(^|_)(SECRETS?|TOKENS?|PASSWORD|PASSWD|CREDENTIALS?|APIKEY)|_KEY$/i;
|
|
346
|
+
function looksSecret(name) {
|
|
347
|
+
return SECRET_NAME.test(name);
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* The overrides that would actually apply to this process. Only DECLARED names survive: an entry
|
|
351
|
+
* for a variable the config no longer declares is inert and never reaches a child. That filter is
|
|
352
|
+
* the safety property behind letting the UI write here at all.
|
|
353
|
+
*/
|
|
354
|
+
function appliedOverrides(definition, overrides) {
|
|
355
|
+
const stored = overrides[definition.id];
|
|
356
|
+
const applied = {};
|
|
357
|
+
if (stored == null) return applied;
|
|
358
|
+
for (const declared of definition.envVars) {
|
|
359
|
+
const value = stored[declared.name];
|
|
360
|
+
if (value != null) applied[declared.name] = value;
|
|
361
|
+
}
|
|
362
|
+
return applied;
|
|
363
|
+
}
|
|
364
|
+
/** The env a spawn would use right now: the config's resolved `env` with overrides layered on. */
|
|
365
|
+
function effectiveEnv(definition, overrides) {
|
|
366
|
+
const applied = appliedOverrides(definition, overrides);
|
|
367
|
+
return Object.keys(applied).length === 0 ? definition.env : {
|
|
368
|
+
...definition.env,
|
|
369
|
+
...applied
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
/** Drift key: two starts share it exactly when they would spawn with the same overrides. */
|
|
373
|
+
function overrideFingerprint(definition, overrides) {
|
|
374
|
+
return hashCanonical(appliedOverrides(definition, overrides), 12);
|
|
375
|
+
}
|
|
376
|
+
function envVarViews(definition, overrides, baseEnv) {
|
|
377
|
+
const applied = appliedOverrides(definition, overrides);
|
|
378
|
+
return definition.envVars.map((declared) => {
|
|
379
|
+
const override = applied[declared.name];
|
|
380
|
+
const source = override != null ? "override" : declared.default != null ? "default" : baseEnv[declared.name] != null ? "inherited" : "unset";
|
|
381
|
+
const value = source === "override" ? override : source === "default" ? declared.default : null;
|
|
382
|
+
const view = {
|
|
383
|
+
name: declared.name,
|
|
384
|
+
secret: declared.secret,
|
|
385
|
+
required: declared.required,
|
|
386
|
+
source
|
|
387
|
+
};
|
|
388
|
+
if (declared.description != null) view.description = declared.description;
|
|
389
|
+
if (declared.values != null) view.values = [...declared.values];
|
|
390
|
+
if (value != null && !declared.secret) view.value = value;
|
|
391
|
+
return view;
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
/** A `required` variable with nothing to fill it — a start would run without something it needs. */
|
|
395
|
+
function missingRequired(definition, overrides, baseEnv) {
|
|
396
|
+
return envVarViews(definition, overrides, baseEnv).filter((view) => view.required && view.source === "unset").map((view) => view.name);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Keep only what the config can justify. Setting a value requires a DECLARED variable on a known
|
|
400
|
+
* process — that filter is what makes the UI's write path safe. Removing is always allowed, even
|
|
401
|
+
* for a name or id the config no longer knows: otherwise a stale entry could never be cleared.
|
|
402
|
+
*/
|
|
403
|
+
function checkEnvMutations(config, input) {
|
|
404
|
+
const byId = new Map(config.processes.map((proc) => [proc.id, proc]));
|
|
405
|
+
const mutations = {};
|
|
406
|
+
const warnings = [];
|
|
407
|
+
for (const [id, values] of Object.entries(input.processes)) {
|
|
408
|
+
const definition = byId.get(id);
|
|
409
|
+
const accepted = {};
|
|
410
|
+
for (const [name, value] of Object.entries(values)) {
|
|
411
|
+
if (value == null) {
|
|
412
|
+
accepted[name] = null;
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
if (definition == null) {
|
|
416
|
+
warnings.push(`"${id}": no such process`);
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
const declared = definition.envVars.find((candidate) => candidate.name === name);
|
|
420
|
+
if (declared == null) {
|
|
421
|
+
warnings.push(`"${id}" does not declare ${name} — add it to \`envVars\` in the config`);
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
if (declared.values != null && !declared.values.includes(value)) {
|
|
425
|
+
warnings.push(`"${id}" ${name}: expected one of ${declared.values.join(", ")}`);
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
accepted[name] = value;
|
|
429
|
+
}
|
|
430
|
+
if (Object.keys(accepted).length > 0) mutations[id] = accepted;
|
|
431
|
+
}
|
|
432
|
+
return {
|
|
433
|
+
mutations,
|
|
434
|
+
clear: [...input.clear ?? []],
|
|
435
|
+
warnings
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Overrides that moved a value the config also spent on an endpoint. Declaring `PORT` with a
|
|
440
|
+
* default of 3000 and then overriding it to 3005 leaves the endpoint, the readiness probe and
|
|
441
|
+
* every link still on 3000 — the process binds happily and everything pointing at it is wrong.
|
|
442
|
+
* Detected by coincidence of value rather than by the name, so it needs no special case for PORT.
|
|
443
|
+
*/
|
|
444
|
+
function overridesOffEndpoint(definition, overrides) {
|
|
445
|
+
const ports = new Set(definition.endpoints.map((endpoint) => endpoint.port));
|
|
446
|
+
const off = [];
|
|
447
|
+
for (const [name, value] of Object.entries(appliedOverrides(definition, overrides))) {
|
|
448
|
+
const declared = definition.envVars.find((candidate) => candidate.name === name)?.default;
|
|
449
|
+
if (declared == null || value === declared || !ports.has(Number(declared))) continue;
|
|
450
|
+
off.push({
|
|
451
|
+
name,
|
|
452
|
+
value,
|
|
453
|
+
port: Number(declared)
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
return off;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Stored overrides the config can no longer explain. Deliberately kept rather than pruned — a
|
|
460
|
+
* process renamed mid-edit should not silently eat the value you set — so they are reported by
|
|
461
|
+
* `env` and `doctor` instead, and `--clear` is what removes them.
|
|
462
|
+
*/
|
|
463
|
+
function staleOverrides(config, overrides) {
|
|
464
|
+
const byId = new Map(config.processes.map((proc) => [proc.id, proc]));
|
|
465
|
+
const stale = [];
|
|
466
|
+
for (const [id, values] of Object.entries(overrides)) {
|
|
467
|
+
const definition = byId.get(id);
|
|
468
|
+
for (const name of Object.keys(values)) if (definition == null) stale.push({
|
|
469
|
+
id,
|
|
470
|
+
name,
|
|
471
|
+
reason: "unknown process"
|
|
472
|
+
});
|
|
473
|
+
else if (!definition.envVars.some((declared) => declared.name === name)) stale.push({
|
|
474
|
+
id,
|
|
475
|
+
name,
|
|
476
|
+
reason: "not declared"
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
return stale;
|
|
480
|
+
}
|
|
321
481
|
/** C0/DEL/C1 control characters have no business in tag keys/values or env keys. */
|
|
322
482
|
function hasControlChars(value) {
|
|
323
483
|
for (let i = 0; i < value.length; i += 1) {
|
|
@@ -330,6 +490,39 @@ const MAX_TAGS = 32;
|
|
|
330
490
|
function isRecord(value) {
|
|
331
491
|
return typeof value === "object" && value != null && !Array.isArray(value);
|
|
332
492
|
}
|
|
493
|
+
/** `=` would split the child's environment block; control chars have no business in a key. */
|
|
494
|
+
function isEnvName(value) {
|
|
495
|
+
return value !== "" && !value.includes("=") && !hasControlChars(value);
|
|
496
|
+
}
|
|
497
|
+
/** The optional half of a declaration, or null when one of its fields was malformed. */
|
|
498
|
+
function readEnvVarFields(declared, name, at, errors) {
|
|
499
|
+
const before = errors.length;
|
|
500
|
+
const description = declared["description"];
|
|
501
|
+
if (description != null && typeof description !== "string") errors.push(`${at}.description: expected a string`);
|
|
502
|
+
const fallback = declared["default"];
|
|
503
|
+
if (fallback != null && typeof fallback !== "string") errors.push(`${at}.default: expected a string (an environment value is always text)`);
|
|
504
|
+
const rawValues = declared["values"];
|
|
505
|
+
let values;
|
|
506
|
+
if (rawValues != null) if (!Array.isArray(rawValues) || rawValues.some((entry) => typeof entry !== "string")) errors.push(`${at}.values: expected an array of strings`);
|
|
507
|
+
else if (rawValues.length === 0) errors.push(`${at}.values: an empty set can never be satisfied`);
|
|
508
|
+
else {
|
|
509
|
+
values = [...rawValues];
|
|
510
|
+
if (typeof fallback === "string" && !values.includes(fallback)) errors.push(`${at}.default: ${JSON.stringify(fallback)} is not one of ${values.join(", ")}`);
|
|
511
|
+
}
|
|
512
|
+
const secret = declared["secret"];
|
|
513
|
+
if (secret != null && typeof secret !== "boolean") errors.push(`${at}.secret: expected a boolean`);
|
|
514
|
+
const required = declared["required"];
|
|
515
|
+
if (required != null && typeof required !== "boolean") errors.push(`${at}.required: expected a boolean`);
|
|
516
|
+
if (errors.length !== before) return null;
|
|
517
|
+
return {
|
|
518
|
+
name,
|
|
519
|
+
...typeof description === "string" ? { description } : {},
|
|
520
|
+
...typeof fallback === "string" ? { default: fallback } : {},
|
|
521
|
+
...values != null ? { values } : {},
|
|
522
|
+
secret: typeof secret === "boolean" ? secret : looksSecret(name),
|
|
523
|
+
required: required === true
|
|
524
|
+
};
|
|
525
|
+
}
|
|
333
526
|
function isUrlCleanHttp(url) {
|
|
334
527
|
try {
|
|
335
528
|
const parsed = new URL(url);
|
|
@@ -437,9 +630,34 @@ function validateCommanderConfig(raw, anchor) {
|
|
|
437
630
|
if (!(0, node_fs.existsSync)(cwd) || !(0, node_fs.statSync)(cwd).isDirectory()) errors.push(`${at}.cwd: "${proc.cwd}" does not exist or is not a directory`);
|
|
438
631
|
const env = {};
|
|
439
632
|
if (proc.env != null) if (!isRecord(proc.env)) errors.push(`${at}.env: expected a record of string | null`);
|
|
440
|
-
else for (const [key, value] of Object.entries(proc.env)) if (
|
|
633
|
+
else for (const [key, value] of Object.entries(proc.env)) if (!isEnvName(key)) errors.push(`${at}.env: invalid key ${JSON.stringify(key)}`);
|
|
441
634
|
else if (typeof value !== "string" && value !== null) errors.push(`${at}.env[${JSON.stringify(key)}]: expected string | null`);
|
|
442
635
|
else env[key] = value;
|
|
636
|
+
const envVars = [];
|
|
637
|
+
if (proc.envVars != null) if (!Array.isArray(proc.envVars)) errors.push(`${at}.envVars: expected an array of declarations (a fixed map goes in \`env\`)`);
|
|
638
|
+
else for (const [varIndex, declared] of proc.envVars.entries()) {
|
|
639
|
+
const atV = `${at}.envVars[${varIndex}]`;
|
|
640
|
+
if (!isRecord(declared)) {
|
|
641
|
+
errors.push(`${atV}: expected an object`);
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
644
|
+
const name = declared["name"];
|
|
645
|
+
if (typeof name !== "string" || !isEnvName(name)) {
|
|
646
|
+
errors.push(`${atV}.name: expected an environment variable name`);
|
|
647
|
+
continue;
|
|
648
|
+
}
|
|
649
|
+
if (envVars.some((existing) => existing.name === name)) {
|
|
650
|
+
errors.push(`${atV}.name: duplicate declaration of "${name}"`);
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
if (name in env) {
|
|
654
|
+
errors.push(`${atV}.name: "${name}" is also in \`env\` — declare it in one place`);
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
657
|
+
const resolved = readEnvVarFields(declared, name, atV, errors);
|
|
658
|
+
if (resolved != null) envVars.push(resolved);
|
|
659
|
+
}
|
|
660
|
+
for (const declared of envVars) if (declared.default != null) env[declared.name] = declared.default;
|
|
443
661
|
const tags = {
|
|
444
662
|
...config.defaults?.tags,
|
|
445
663
|
...proc.tags
|
|
@@ -531,6 +749,7 @@ function validateCommanderConfig(raw, anchor) {
|
|
|
531
749
|
run: proc.run,
|
|
532
750
|
...proc.shell != null ? { shell: proc.shell } : {},
|
|
533
751
|
env,
|
|
752
|
+
envVars,
|
|
534
753
|
stdin,
|
|
535
754
|
tags,
|
|
536
755
|
dependsOn,
|
|
@@ -21920,7 +22139,8 @@ function commanderStatePaths(dataDir, configKey) {
|
|
|
21920
22139
|
logsDir: (0, node_path.join)(stateDir, "logs"),
|
|
21921
22140
|
upLockPath: (0, node_path.join)(stateDir, "up.lock"),
|
|
21922
22141
|
bootLogPath: (0, node_path.join)(stateDir, "daemon-boot.log"),
|
|
21923
|
-
ingestSeqPath: (0, node_path.join)(stateDir, "ingest-seq")
|
|
22142
|
+
ingestSeqPath: (0, node_path.join)(stateDir, "ingest-seq"),
|
|
22143
|
+
envOverridesPath: (0, node_path.join)(stateDir, "env-overrides.json")
|
|
21924
22144
|
};
|
|
21925
22145
|
}
|
|
21926
22146
|
async function ensureStateDir(paths) {
|
|
@@ -21957,7 +22177,7 @@ function validStartStamp(value) {
|
|
|
21957
22177
|
function isInstanceRecord(value) {
|
|
21958
22178
|
if (value == null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
21959
22179
|
const record = value;
|
|
21960
|
-
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) && validStartStamp(record.startStamp) && record.protocolVersion ===
|
|
22180
|
+
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) && validStartStamp(record.startStamp) && record.protocolVersion === 2;
|
|
21961
22181
|
}
|
|
21962
22182
|
async function writeInstanceRecord(path, record) {
|
|
21963
22183
|
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), {
|
|
@@ -22002,7 +22222,7 @@ async function readForeignInstanceRecord(path) {
|
|
|
22002
22222
|
const record = parsed;
|
|
22003
22223
|
if (record["service"] !== "nice-commander") return null;
|
|
22004
22224
|
if (!boundedInt(record["protocolVersion"], 0, Number.MAX_SAFE_INTEGER)) return null;
|
|
22005
|
-
if (record["protocolVersion"] ===
|
|
22225
|
+
if (record["protocolVersion"] === 2) return null;
|
|
22006
22226
|
if (!boundedInt(record["pid"], 1, Number.MAX_SAFE_INTEGER)) return null;
|
|
22007
22227
|
if (!boundedInt(record["port"], 1, 65535)) return null;
|
|
22008
22228
|
return {
|
|
@@ -22012,6 +22232,15 @@ async function readForeignInstanceRecord(path) {
|
|
|
22012
22232
|
packageVersion: boundedString(record["packageVersion"]) ? record["packageVersion"] : "unknown"
|
|
22013
22233
|
};
|
|
22014
22234
|
}
|
|
22235
|
+
/** Liveness only — enough to say "something is there", never enough to authorize a kill (C1). */
|
|
22236
|
+
function pidAlive$1(pid) {
|
|
22237
|
+
try {
|
|
22238
|
+
process.kill(pid, 0);
|
|
22239
|
+
return true;
|
|
22240
|
+
} catch (error) {
|
|
22241
|
+
return error.code === "EPERM";
|
|
22242
|
+
}
|
|
22243
|
+
}
|
|
22015
22244
|
/**
|
|
22016
22245
|
* Is this record's daemon still the process it claims to be? pid alive AND startStamp equal —
|
|
22017
22246
|
* an unreadable stamp answers false (a reused pid must never be trusted).
|
|
@@ -22044,7 +22273,7 @@ async function pingDaemon(record, timeoutMs = 2e3) {
|
|
|
22044
22273
|
//#region src/daemon/lockfile.ts
|
|
22045
22274
|
const LOCK_RETRY_LIMIT = 250;
|
|
22046
22275
|
const LOCK_RETRY_MS = 40;
|
|
22047
|
-
function pidAlive
|
|
22276
|
+
function pidAlive(pid) {
|
|
22048
22277
|
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
22049
22278
|
try {
|
|
22050
22279
|
process.kill(pid, 0);
|
|
@@ -22107,7 +22336,7 @@ async function withCommanderLock(path, action) {
|
|
|
22107
22336
|
try {
|
|
22108
22337
|
current = JSON.parse(await (0, node_fs_promises.readFile)(path, "utf8"));
|
|
22109
22338
|
} catch {}
|
|
22110
|
-
if (current?.pid != null && current.id != null && !pidAlive
|
|
22339
|
+
if (current?.pid != null && current.id != null && !pidAlive(current.pid)) {
|
|
22111
22340
|
await stealStaleLock(path, current.id);
|
|
22112
22341
|
continue;
|
|
22113
22342
|
}
|
|
@@ -22162,15 +22391,6 @@ var CommanderDaemonBootError = class extends Error {
|
|
|
22162
22391
|
this.name = "CommanderDaemonBootError";
|
|
22163
22392
|
}
|
|
22164
22393
|
};
|
|
22165
|
-
/** Liveness only — enough to say "something is there", never enough to authorize a kill (C1). */
|
|
22166
|
-
function pidAlive(pid) {
|
|
22167
|
-
try {
|
|
22168
|
-
process.kill(pid, 0);
|
|
22169
|
-
return true;
|
|
22170
|
-
} catch (error) {
|
|
22171
|
-
return error.code === "EPERM";
|
|
22172
|
-
}
|
|
22173
|
-
}
|
|
22174
22394
|
async function ensureDaemon(options) {
|
|
22175
22395
|
const dataDir = options.dataDir != null ? (0, node_path.resolve)(options.dataDir) : resolveCommanderDataDir();
|
|
22176
22396
|
const paths = commanderStatePaths(dataDir, options.config.configKey);
|
|
@@ -22186,7 +22406,7 @@ async function ensureDaemon(options) {
|
|
|
22186
22406
|
}
|
|
22187
22407
|
if (existing == null) {
|
|
22188
22408
|
const foreign = await readForeignInstanceRecord(paths.instanceRecordPath);
|
|
22189
|
-
if (foreign != null && pidAlive(foreign.pid)) throw new Error(`a nice-commander daemon speaking protocol v${foreign.protocolVersion} (package ${foreign.packageVersion}) is already running for this config — pid ${foreign.pid}, port ${foreign.port}. This build speaks
|
|
22409
|
+
if (foreign != null && pidAlive$1(foreign.pid)) throw new Error(`a nice-commander daemon speaking protocol v${foreign.protocolVersion} (package ${foreign.packageVersion}) is already running for this config — pid ${foreign.pid}, port ${foreign.port}. This build speaks v2 and cannot talk to it. Stop it with that version's \`nice-commander shutdown\`, or end pid ${foreign.pid} yourself; if it is already gone, remove ${paths.instanceRecordPath}.`);
|
|
22190
22410
|
}
|
|
22191
22411
|
await ensureStateDir(paths);
|
|
22192
22412
|
const bootFd = (0, node_fs.openSync)(paths.bootLogPath, "w", 384);
|
|
@@ -22300,6 +22520,40 @@ function checkStart(value) {
|
|
|
22300
22520
|
if (staggerMs != null) input.staggerMs = staggerMs;
|
|
22301
22521
|
return input;
|
|
22302
22522
|
}
|
|
22523
|
+
function checkSetEnv(value) {
|
|
22524
|
+
const record = asRecord(value);
|
|
22525
|
+
if (record == null) return "expected an object";
|
|
22526
|
+
const processes = asRecord(record["processes"]);
|
|
22527
|
+
if (processes == null) return "processes: expected an object keyed by process id";
|
|
22528
|
+
const checked = {};
|
|
22529
|
+
for (const [id, values] of Object.entries(processes)) {
|
|
22530
|
+
const entries = asRecord(values);
|
|
22531
|
+
if (entries == null) return `processes[${JSON.stringify(id)}]: expected an object`;
|
|
22532
|
+
const mutations = {};
|
|
22533
|
+
for (const [name, entry] of Object.entries(entries)) {
|
|
22534
|
+
if (entry !== null && typeof entry !== "string") return `processes[${JSON.stringify(id)}][${JSON.stringify(name)}]: expected string | null`;
|
|
22535
|
+
mutations[name] = entry;
|
|
22536
|
+
}
|
|
22537
|
+
checked[id] = mutations;
|
|
22538
|
+
}
|
|
22539
|
+
const clear = record["clear"];
|
|
22540
|
+
if (clear == null) return { processes: checked };
|
|
22541
|
+
const ids = asIdList(clear);
|
|
22542
|
+
return ids == null ? "clear: expected an array of process ids" : {
|
|
22543
|
+
processes: checked,
|
|
22544
|
+
clear: ids
|
|
22545
|
+
};
|
|
22546
|
+
}
|
|
22547
|
+
function checkEnvReport(value) {
|
|
22548
|
+
const record = asRecord(value);
|
|
22549
|
+
if (record == null || record["ok"] !== true) return "expected { ok: true }";
|
|
22550
|
+
const warnings = record["warnings"];
|
|
22551
|
+
if (!Array.isArray(warnings) || !warnings.every((entry) => typeof entry === "string")) return "warnings: expected an array of strings";
|
|
22552
|
+
return {
|
|
22553
|
+
ok: true,
|
|
22554
|
+
warnings
|
|
22555
|
+
};
|
|
22556
|
+
}
|
|
22303
22557
|
function checkIds(value) {
|
|
22304
22558
|
const record = asRecord(value);
|
|
22305
22559
|
if (record == null) return "expected an object";
|
|
@@ -22385,6 +22639,7 @@ const commanderControlDomain = createActionRootDomain({ domain: "commander" }).c
|
|
|
22385
22639
|
start: actionSchema().input({ schema: handSchema(checkStart) }).output({ schema: handSchema(checkReport) }),
|
|
22386
22640
|
stop: actionSchema().input({ schema: handSchema(checkIds) }).output({ schema: handSchema(checkReport) }),
|
|
22387
22641
|
restart: actionSchema().input({ schema: handSchema(checkStart) }).output({ schema: handSchema(checkReport) }),
|
|
22642
|
+
setEnv: actionSchema().input({ schema: handSchema(checkSetEnv) }).output({ schema: handSchema(checkEnvReport) }),
|
|
22388
22643
|
reloadConfig: actionSchema().input({ schema: handSchema(checkEmpty) }).output({ schema: handSchema(checkReloadResult) }),
|
|
22389
22644
|
shutdown: actionSchema().input({ schema: handSchema(checkEmpty) }).output({ schema: handSchema((value) => value != null && value.ok === true ? { ok: true } : "expected { ok: true }") })
|
|
22390
22645
|
}
|
|
@@ -22421,6 +22676,7 @@ const commanderStatusRealm = defineRealm({
|
|
|
22421
22676
|
})),
|
|
22422
22677
|
stale: t.boolean(),
|
|
22423
22678
|
removed: t.boolean(),
|
|
22679
|
+
envDrift: t.boolean(),
|
|
22424
22680
|
blockedBy: t.optional(t.string()),
|
|
22425
22681
|
degradedBy: t.array(t.string()),
|
|
22426
22682
|
unreadyReason: t.optional(t.string()),
|
|
@@ -22442,6 +22698,15 @@ const commanderStatusRealm = defineRealm({
|
|
|
22442
22698
|
port: t.number(),
|
|
22443
22699
|
ownership: t.string(),
|
|
22444
22700
|
url: t.optional(t.string())
|
|
22701
|
+
})),
|
|
22702
|
+
envVars: t.array(t.object({
|
|
22703
|
+
name: t.string(),
|
|
22704
|
+
description: t.optional(t.string()),
|
|
22705
|
+
secret: t.boolean(),
|
|
22706
|
+
required: t.boolean(),
|
|
22707
|
+
values: t.optional(t.array(t.string())),
|
|
22708
|
+
source: t.string(),
|
|
22709
|
+
value: t.optional(t.string())
|
|
22445
22710
|
}))
|
|
22446
22711
|
})
|
|
22447
22712
|
})),
|
|
@@ -22465,8 +22730,10 @@ async function findDaemon(config) {
|
|
|
22465
22730
|
/** Read-only commands' daemon-or-report: never starts anything, exit 3 when not running. */
|
|
22466
22731
|
async function requireDaemon(config) {
|
|
22467
22732
|
const handle = await findDaemon(config);
|
|
22468
|
-
if (handle
|
|
22469
|
-
|
|
22733
|
+
if (handle != null) return handle;
|
|
22734
|
+
const foreign = await readForeignInstanceRecord(commanderStatePaths(resolveCommanderDataDir(), config.configKey).instanceRecordPath);
|
|
22735
|
+
if (foreign != null && pidAlive$1(foreign.pid)) throw new CliExit(EXIT.notRunning, `a nice-commander daemon speaking protocol v${foreign.protocolVersion} (package ${foreign.packageVersion}) is running for this config — pid ${foreign.pid}, port ${foreign.port}. This build speaks v2 and cannot read its state. Stop it with that version's \`nice-commander shutdown\`, then \`up\` again.`);
|
|
22736
|
+
throw new CliExit(EXIT.notRunning, `daemon not running for "${config.name}" (start one with \`up\`)`);
|
|
22470
22737
|
}
|
|
22471
22738
|
/** `up`/`ui`'s spawn-or-reuse; the daemon child reruns THIS bin (`daemon` subcommand). */
|
|
22472
22739
|
async function ensureDaemonRunning(config) {
|
|
@@ -22545,9 +22812,16 @@ async function connectDaemon(handle) {
|
|
|
22545
22812
|
const payload = await (await runtime.handleActionPayload(request)).waitForResultPayload();
|
|
22546
22813
|
if (!payload.result.ok) throw new CliExit(EXIT.failure, `action "${action}" rejected by the daemon`);
|
|
22547
22814
|
const report = parseActionReport(payload.result.output);
|
|
22548
|
-
if (report == null) throw new CliExit(EXIT.failure, `the daemon answered "${action}" with something this CLI does not recognise — protocol ${record.protocolVersion} vs
|
|
22815
|
+
if (report == null) throw new CliExit(EXIT.failure, `the daemon answered "${action}" with something this CLI does not recognise — protocol ${record.protocolVersion} vs 2`);
|
|
22549
22816
|
return report;
|
|
22550
22817
|
},
|
|
22818
|
+
setEnv: async (input) => {
|
|
22819
|
+
const request = commanderControlDomain.actionForId("setEnv").request(input);
|
|
22820
|
+
const payload = await (await runtime.handleActionPayload(request)).waitForResultPayload();
|
|
22821
|
+
if (!payload.result.ok) throw new CliExit(EXIT.failure, `action "setEnv" rejected by the daemon`);
|
|
22822
|
+
const warnings = payload.result.output.warnings;
|
|
22823
|
+
return Array.isArray(warnings) ? warnings.filter((entry) => typeof entry === "string") : [];
|
|
22824
|
+
},
|
|
22551
22825
|
shutdown: async () => {
|
|
22552
22826
|
const request = commanderControlDomain.actionForId("shutdown").request({});
|
|
22553
22827
|
if (!(await (await runtime.handleActionPayload(request)).waitForResultPayload()).result.ok) throw new CliExit(EXIT.failure, `action "shutdown" rejected by the daemon`);
|
|
@@ -22699,6 +22973,85 @@ async function cmdShutdown(ctx) {
|
|
|
22699
22973
|
}
|
|
22700
22974
|
}
|
|
22701
22975
|
//#endregion
|
|
22976
|
+
//#region src/daemon/envOverrides.ts
|
|
22977
|
+
const STORE_VERSION = 1;
|
|
22978
|
+
/** A knob is a port or a log level, not a payload. Bounds keep a mistake from becoming a file. */
|
|
22979
|
+
const MAX_VALUE_LENGTH = 4096;
|
|
22980
|
+
const EMPTY_ENV_OVERRIDES = Object.freeze({});
|
|
22981
|
+
function readable(value) {
|
|
22982
|
+
if (value == null || typeof value !== "object") return null;
|
|
22983
|
+
const processes = value.processes;
|
|
22984
|
+
if (processes == null || typeof processes !== "object" || Array.isArray(processes)) return null;
|
|
22985
|
+
const clean = {};
|
|
22986
|
+
for (const [id, values] of Object.entries(processes)) {
|
|
22987
|
+
if (values == null || typeof values !== "object" || Array.isArray(values)) continue;
|
|
22988
|
+
const entries = {};
|
|
22989
|
+
for (const [name, entry] of Object.entries(values)) if (typeof entry === "string" && entry.length <= MAX_VALUE_LENGTH) entries[name] = entry;
|
|
22990
|
+
if (Object.keys(entries).length > 0) clean[id] = entries;
|
|
22991
|
+
}
|
|
22992
|
+
return clean;
|
|
22993
|
+
}
|
|
22994
|
+
/**
|
|
22995
|
+
* Missing, unreadable or corrupt all read as "no overrides". A bad file must never block a start:
|
|
22996
|
+
* the config alone is always enough to run, and the surfaces that report overrides say when the
|
|
22997
|
+
* store could not be read.
|
|
22998
|
+
*/
|
|
22999
|
+
async function readEnvOverrides(path) {
|
|
23000
|
+
try {
|
|
23001
|
+
return readable(JSON.parse(await (0, node_fs_promises.readFile)(path, "utf8"))) ?? EMPTY_ENV_OVERRIDES;
|
|
23002
|
+
} catch {
|
|
23003
|
+
return EMPTY_ENV_OVERRIDES;
|
|
23004
|
+
}
|
|
23005
|
+
}
|
|
23006
|
+
/** 0600 and atomic — it can hold a token, and a half-written file must never be read as empty. */
|
|
23007
|
+
async function writeEnvOverrides(path, overrides) {
|
|
23008
|
+
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), {
|
|
23009
|
+
recursive: true,
|
|
23010
|
+
mode: 448
|
|
23011
|
+
});
|
|
23012
|
+
const store = {
|
|
23013
|
+
version: STORE_VERSION,
|
|
23014
|
+
processes: Object.fromEntries(Object.entries(overrides).filter(([, values]) => Object.keys(values).length > 0).map(([id, values]) => [id, { ...values }]))
|
|
23015
|
+
};
|
|
23016
|
+
const temp = `${path}.${process.pid}.tmp`;
|
|
23017
|
+
await (0, node_fs_promises.writeFile)(temp, `${JSON.stringify(store, null, 2)}\n`, {
|
|
23018
|
+
encoding: "utf8",
|
|
23019
|
+
mode: 384
|
|
23020
|
+
});
|
|
23021
|
+
await (0, node_fs_promises.rename)(temp, path);
|
|
23022
|
+
}
|
|
23023
|
+
/** Pure: the store that results from applying `change`. Empty processes are pruned. */
|
|
23024
|
+
function mutateEnvOverrides(current, change) {
|
|
23025
|
+
const next = {};
|
|
23026
|
+
for (const [id, values] of Object.entries(current)) next[id] = { ...values };
|
|
23027
|
+
for (const id of change.clear ?? []) delete next[id];
|
|
23028
|
+
for (const [id, values] of Object.entries(change.mutations ?? {})) {
|
|
23029
|
+
const entries = next[id] ?? {};
|
|
23030
|
+
for (const [name, value] of Object.entries(values)) if (value == null) delete entries[name];
|
|
23031
|
+
else entries[name] = value;
|
|
23032
|
+
if (Object.keys(entries).length > 0) next[id] = entries;
|
|
23033
|
+
else delete next[id];
|
|
23034
|
+
}
|
|
23035
|
+
return next;
|
|
23036
|
+
}
|
|
23037
|
+
/**
|
|
23038
|
+
* Read → check against the config → mutate → write, atomically enough for a file two surfaces
|
|
23039
|
+
* touch. The one implementation behind both writers, so the daemon's `setEnv` and the CLI's
|
|
23040
|
+
* no-daemon path can never diverge on what they accept.
|
|
23041
|
+
*/
|
|
23042
|
+
async function applyEnvMutation(path, config, input) {
|
|
23043
|
+
const checked = checkEnvMutations(config, input);
|
|
23044
|
+
const next = mutateEnvOverrides(await readEnvOverrides(path), checked);
|
|
23045
|
+
await writeEnvOverrides(path, next);
|
|
23046
|
+
return {
|
|
23047
|
+
overrides: next,
|
|
23048
|
+
warnings: checked.warnings
|
|
23049
|
+
};
|
|
23050
|
+
}
|
|
23051
|
+
function countOverrides(overrides) {
|
|
23052
|
+
return Object.values(overrides).reduce((total, values) => total + Object.keys(values).length, 0);
|
|
23053
|
+
}
|
|
23054
|
+
//#endregion
|
|
22702
23055
|
//#region src/cli/commands/doctor.ts
|
|
22703
23056
|
function formatAge(ms) {
|
|
22704
23057
|
if (ms < 6e4) return `${Math.round(ms / 1e3)}s`;
|
|
@@ -22797,6 +23150,14 @@ async function diagnose(ctx, handle) {
|
|
|
22797
23150
|
report.info.push(`ledger quarantine: ${quarantined.length} record(s) a reap refused to kill` + (quarantined.length > recent.length ? ` (newest ${recent.length} shown)` : ""));
|
|
22798
23151
|
for (const entry of recent) report.warnings.push(`quarantined "${entry.record.id}" (pid ${entry.record.pid}): ${entry.reason} — never killed on an ambiguous identity; verify it yourself before ending it`);
|
|
22799
23152
|
}
|
|
23153
|
+
const overrides = await readEnvOverrides(paths.envOverridesPath);
|
|
23154
|
+
const overrideCount = countOverrides(overrides);
|
|
23155
|
+
if (overrideCount > 0) report.info.push(`env overrides: ${overrideCount} set in ${paths.envOverridesPath} — they apply to every start (\`nice-commander env\` lists them, \`--clear\` drops them)`);
|
|
23156
|
+
for (const entry of staleOverrides(config, overrides)) report.warnings.push(`env override ${entry.id}.${entry.name} is stored but inert (${entry.reason}) — clear it with \`env ${entry.id} --clear\``);
|
|
23157
|
+
for (const proc of config.processes) {
|
|
23158
|
+
for (const name of missingRequired(proc, overrides, process.env)) report.warnings.push(`"${proc.id}" requires ${name} and nothing supplies it — set it with \`env ${proc.id} --set ${name}=…\``);
|
|
23159
|
+
for (const off of overridesOffEndpoint(proc, overrides)) report.warnings.push(`"${proc.id}" ${off.name}=${off.value} but its endpoint and readiness are still on ${off.port} — it will bind somewhere nothing points at`);
|
|
23160
|
+
}
|
|
22800
23161
|
const capability = (0, _nice_code_process.detectCapability)();
|
|
22801
23162
|
report.info.push(`tree ownership: ${capability.treeMechanism}`);
|
|
22802
23163
|
for (const note of capability.notes) report.warnings.push(note);
|
|
@@ -22847,6 +23208,128 @@ async function cmdDoctor(ctx) {
|
|
|
22847
23208
|
return EXIT.ok;
|
|
22848
23209
|
}
|
|
22849
23210
|
//#endregion
|
|
23211
|
+
//#region src/cli/commands/env.ts
|
|
23212
|
+
/** `NAME=VALUE` for `--set`. */
|
|
23213
|
+
function parseAssignments(values) {
|
|
23214
|
+
const parsed = {};
|
|
23215
|
+
for (const entry of values) {
|
|
23216
|
+
const eq = entry.indexOf("=");
|
|
23217
|
+
if (eq <= 0) return { error: `--set expects NAME=VALUE, got ${JSON.stringify(entry)}` };
|
|
23218
|
+
parsed[entry.slice(0, eq)] = entry.slice(eq + 1);
|
|
23219
|
+
}
|
|
23220
|
+
return parsed;
|
|
23221
|
+
}
|
|
23222
|
+
function parseNames(values) {
|
|
23223
|
+
for (const entry of values) if (entry.includes("=")) return { error: `--unset expects a NAME, got ${JSON.stringify(entry)}` };
|
|
23224
|
+
return [...values];
|
|
23225
|
+
}
|
|
23226
|
+
function describeValue(view) {
|
|
23227
|
+
if (view.secret) return view.source === "unset" ? "-" : "••••••";
|
|
23228
|
+
return view.value ?? (view.source === "inherited" ? "(the daemon's env)" : "-");
|
|
23229
|
+
}
|
|
23230
|
+
function renderProcess(out, definition, views) {
|
|
23231
|
+
out.print(out.paint("bold", definition.id));
|
|
23232
|
+
if (views.length === 0) {
|
|
23233
|
+
out.print(out.paint("gray", " declares no env vars — add `envVars` to the config to tune it"));
|
|
23234
|
+
return;
|
|
23235
|
+
}
|
|
23236
|
+
out.print(out.table([
|
|
23237
|
+
" NAME",
|
|
23238
|
+
"VALUE",
|
|
23239
|
+
"SOURCE",
|
|
23240
|
+
"NOTES"
|
|
23241
|
+
], views.map((view) => [
|
|
23242
|
+
` ${view.name}`,
|
|
23243
|
+
describeValue(view),
|
|
23244
|
+
view.source,
|
|
23245
|
+
[
|
|
23246
|
+
view.description,
|
|
23247
|
+
view.required && view.source === "unset" ? out.paint("red", "required, unset") : null,
|
|
23248
|
+
view.values != null ? `one of: ${view.values.join(", ")}` : null
|
|
23249
|
+
].filter((note) => note != null).join(" · ")
|
|
23250
|
+
])));
|
|
23251
|
+
}
|
|
23252
|
+
async function cmdEnv(ctx) {
|
|
23253
|
+
const bad = unknownFlags(ctx.args.flags, [
|
|
23254
|
+
"--set",
|
|
23255
|
+
"--unset",
|
|
23256
|
+
"--clear",
|
|
23257
|
+
"--all"
|
|
23258
|
+
]);
|
|
23259
|
+
if (bad != null) throw new CliExit(EXIT.usage, bad);
|
|
23260
|
+
const sets = parseAssignments(ctx.args.repeated.get("--set") ?? []);
|
|
23261
|
+
if ("error" in sets) throw new CliExit(EXIT.usage, sets.error);
|
|
23262
|
+
const unsets = parseNames(ctx.args.repeated.get("--unset") ?? []);
|
|
23263
|
+
if ("error" in unsets) throw new CliExit(EXIT.usage, unsets.error);
|
|
23264
|
+
const clearing = ctx.args.flags.get("--clear") === true;
|
|
23265
|
+
const mutating = Object.keys(sets).length > 0 || unsets.length > 0 || clearing;
|
|
23266
|
+
const { out, config } = ctx;
|
|
23267
|
+
const paths = commanderStatePaths(resolveCommanderDataDir(), config.configKey);
|
|
23268
|
+
const definitions = mutating || ctx.args.positionals.length > 0 || ctx.args.flags.has("--all") ? idsToDefinitions(ctx, selectOrExit(ctx, { bare: "required" }).direct) : config.processes.filter((proc) => proc.envVars.length > 0);
|
|
23269
|
+
const handle = mutating ? await findDaemon(config) : null;
|
|
23270
|
+
const client = handle == null ? null : await connectDaemon(handle);
|
|
23271
|
+
try {
|
|
23272
|
+
const result = mutating ? await mutate(ctx, paths.envOverridesPath, client, {
|
|
23273
|
+
processes: Object.fromEntries(definitions.map((definition) => [definition.id, {
|
|
23274
|
+
...sets,
|
|
23275
|
+
...Object.fromEntries(unsets.map((name) => [name, null]))
|
|
23276
|
+
}])),
|
|
23277
|
+
...clearing ? { clear: definitions.map((definition) => definition.id) } : {}
|
|
23278
|
+
}) : {
|
|
23279
|
+
overrides: await readEnvOverrides(paths.envOverridesPath),
|
|
23280
|
+
warnings: []
|
|
23281
|
+
};
|
|
23282
|
+
const views = new Map(definitions.map((definition) => [definition.id, envVarViews(definition, result.overrides, process.env)]));
|
|
23283
|
+
const stale = staleOverrides(config, result.overrides);
|
|
23284
|
+
if (out.json) {
|
|
23285
|
+
out.printJson({
|
|
23286
|
+
overridesPath: paths.envOverridesPath,
|
|
23287
|
+
processes: definitions.map((definition) => ({
|
|
23288
|
+
id: definition.id,
|
|
23289
|
+
envVars: views.get(definition.id) ?? []
|
|
23290
|
+
})),
|
|
23291
|
+
stale,
|
|
23292
|
+
warnings: result.warnings
|
|
23293
|
+
});
|
|
23294
|
+
return result.warnings.length > 0 ? EXIT.failure : EXIT.ok;
|
|
23295
|
+
}
|
|
23296
|
+
for (const definition of definitions) {
|
|
23297
|
+
renderProcess(out, definition, views.get(definition.id) ?? []);
|
|
23298
|
+
out.print();
|
|
23299
|
+
}
|
|
23300
|
+
const total = countOverrides(result.overrides);
|
|
23301
|
+
if (total > 0) out.print(out.paint("gray", `${total} sticky override(s) — they apply to every start until \`nice-commander env <sel> --clear\`.`));
|
|
23302
|
+
if (client != null) {
|
|
23303
|
+
const processes = client.state().processes;
|
|
23304
|
+
for (const definition of definitions) {
|
|
23305
|
+
if (processes[definition.id]?.envDrift !== true) continue;
|
|
23306
|
+
out.print(out.paint("yellow", `${definition.id} is running with the previous values — restart it`));
|
|
23307
|
+
}
|
|
23308
|
+
}
|
|
23309
|
+
for (const definition of definitions) for (const off of overridesOffEndpoint(definition, result.overrides)) out.warn(out.paint("yellow", `⚠ ${definition.id} ${off.name}=${off.value} but its endpoint and readiness are still on ${off.port} — it will bind somewhere nothing points at`));
|
|
23310
|
+
for (const entry of stale) out.warn(out.paint("yellow", `⚠ stored override ${entry.id}.${entry.name} is inert (${entry.reason}) — \`env ${entry.id} --clear\` removes it`));
|
|
23311
|
+
for (const warning of result.warnings) out.warn(out.paint("yellow", `⚠ ${warning}`));
|
|
23312
|
+
return result.warnings.length > 0 ? EXIT.failure : EXIT.ok;
|
|
23313
|
+
} finally {
|
|
23314
|
+
client?.dispose();
|
|
23315
|
+
}
|
|
23316
|
+
}
|
|
23317
|
+
function idsToDefinitions(ctx, ids) {
|
|
23318
|
+
return ctx.config.processes.filter((proc) => ids.includes(proc.id));
|
|
23319
|
+
}
|
|
23320
|
+
/**
|
|
23321
|
+
* The daemon owns the store while it is alive, so a live one does the write — two writers would
|
|
23322
|
+
* race, and its in-memory view would go stale the instant we wrote behind its back.
|
|
23323
|
+
*/
|
|
23324
|
+
async function mutate(ctx, path, client, input) {
|
|
23325
|
+
if (client == null) return applyEnvMutation(path, ctx.config, input);
|
|
23326
|
+
const warnings = await client.setEnv(input);
|
|
23327
|
+
return {
|
|
23328
|
+
overrides: await readEnvOverrides(path),
|
|
23329
|
+
warnings
|
|
23330
|
+
};
|
|
23331
|
+
}
|
|
23332
|
+
//#endregion
|
|
22850
23333
|
//#region src/cli/commands/inspect.ts
|
|
22851
23334
|
async function cmdList(ctx) {
|
|
22852
23335
|
const bad = unknownFlags(ctx.args.flags, []);
|
|
@@ -22864,7 +23347,8 @@ async function cmdList(ctx) {
|
|
|
22864
23347
|
tags: proc.tags,
|
|
22865
23348
|
dependsOn: proc.dependsOn,
|
|
22866
23349
|
endpoints: proc.endpoints,
|
|
22867
|
-
url: proc.url ?? null
|
|
23350
|
+
url: proc.url ?? null,
|
|
23351
|
+
envVars: proc.envVars
|
|
22868
23352
|
})),
|
|
22869
23353
|
groups: Object.fromEntries(Object.entries(config.groups).map(([name, group]) => [name, {
|
|
22870
23354
|
ids: group.ids,
|
|
@@ -23232,6 +23716,7 @@ async function cmdRun(ctx) {
|
|
|
23232
23716
|
});
|
|
23233
23717
|
if (parallel != null && !defs.some((def) => def.kind === "task")) out.warn(out.paint("yellow", "note: --parallel applies to tasks; this selection has none — ignored."));
|
|
23234
23718
|
const paths = commanderStatePaths(resolveCommanderDataDir(), config.configKey);
|
|
23719
|
+
const overrides = await readEnvOverrides(paths.envOverridesPath);
|
|
23235
23720
|
const ledger = (0, _nice_code_process.openProcessLedger)({
|
|
23236
23721
|
dir: paths.stateDir,
|
|
23237
23722
|
namespace: paths.ledgerNamespace,
|
|
@@ -23268,7 +23753,7 @@ async function cmdRun(ctx) {
|
|
|
23268
23753
|
run: def.run,
|
|
23269
23754
|
...def.shell != null ? { shell: def.shell } : {},
|
|
23270
23755
|
cwd: def.cwd,
|
|
23271
|
-
env: def
|
|
23756
|
+
env: effectiveEnv(def, overrides),
|
|
23272
23757
|
kind: def.kind,
|
|
23273
23758
|
...ready != null ? { ready } : {},
|
|
23274
23759
|
stop: def.stop,
|
|
@@ -23478,6 +23963,7 @@ function notesFor(proc) {
|
|
|
23478
23963
|
if (proc.degradedBy.length > 0) notes.push(`degraded by ${proc.degradedBy.join(", ")}`);
|
|
23479
23964
|
if (proc.unreadyReason != null) notes.push(`unready: ${proc.unreadyReason}`);
|
|
23480
23965
|
if (proc.stale) notes.push("stale (config changed — restart to apply)");
|
|
23966
|
+
if (proc.envDrift) notes.push("env override changed — restart to apply");
|
|
23481
23967
|
if (proc.removed) notes.push("removed from config");
|
|
23482
23968
|
if (proc.capability?.degraded === true) notes.push(proc.capability.treeMechanism);
|
|
23483
23969
|
return notes.join("; ");
|
|
@@ -23611,14 +24097,16 @@ async function cmdUi(ctx) {
|
|
|
23611
24097
|
url,
|
|
23612
24098
|
opened
|
|
23613
24099
|
});
|
|
23614
|
-
else ctx.out.print(opened ? `opened ${url}
|
|
24100
|
+
else ctx.out.print(opened ? `opened ${url}` : `could not open a browser — visit ${url}`);
|
|
23615
24101
|
return EXIT.ok;
|
|
23616
24102
|
}
|
|
23617
24103
|
//#endregion
|
|
23618
24104
|
//#region src/cli.ts
|
|
23619
24105
|
const HELP = `nice-commander — one typed config, one control surface, for dev environments.
|
|
23620
24106
|
|
|
23621
|
-
usage: nice-commander [--config <path>] [--json] [--no-color] [--timeout <ms>]
|
|
24107
|
+
usage: nice-commander [--config <path>] [--json] [--no-color] [--timeout <ms>] [command] [selection] [flags]
|
|
24108
|
+
|
|
24109
|
+
With NO command, "ui" runs: the daemon is ensured and the browser opened. --help prints this text.
|
|
23622
24110
|
|
|
23623
24111
|
selection: process ids, group names, tag=val (AND across terms), or --all.
|
|
23624
24112
|
Bare up/explain use the config's defaultSelection (or print the groups and exit);
|
|
@@ -23632,6 +24120,9 @@ commands:
|
|
|
23632
24120
|
logs <sel> [-f] merged interleaved tail with colored id prefixes
|
|
23633
24121
|
list config introspection (processes, groups, warnings)
|
|
23634
24122
|
explain [sel] expanded ids, auto-included deps, DAG order
|
|
24123
|
+
env [sel] [--set N=V] [--unset N] declared env vars and their values; --clear drops
|
|
24124
|
+
overrides. A set value is STICKY: it applies to every
|
|
24125
|
+
later start until cleared, and never restarts anything.
|
|
23635
24126
|
run <sel> [--parallel N] [--fail-fast] foreground, no daemon; tasks = local CI shape,
|
|
23636
24127
|
a single id gets raw inherited stdio (interactive)
|
|
23637
24128
|
ui ensure the daemon and open the browser (prints URL)
|
|
@@ -23649,6 +24140,7 @@ const COMMANDS = {
|
|
|
23649
24140
|
logs: cmdLogs,
|
|
23650
24141
|
list: cmdList,
|
|
23651
24142
|
explain: cmdExplain,
|
|
24143
|
+
env: cmdEnv,
|
|
23652
24144
|
run: cmdRun,
|
|
23653
24145
|
ui: cmdUi,
|
|
23654
24146
|
doctor: cmdDoctor,
|
|
@@ -23686,7 +24178,7 @@ async function withTimeout(ctx, run) {
|
|
|
23686
24178
|
async function main() {
|
|
23687
24179
|
const argv = process.argv.slice(2);
|
|
23688
24180
|
if (argv[0] === "daemon") {
|
|
23689
|
-
const { runCommanderDaemon } = await Promise.resolve().then(() => require("./main-
|
|
24181
|
+
const { runCommanderDaemon } = await Promise.resolve().then(() => require("./main-Cqij6RwE.cjs"));
|
|
23690
24182
|
return runCommanderDaemon(argv.slice(1));
|
|
23691
24183
|
}
|
|
23692
24184
|
const parsed = parseCliArgs(argv);
|
|
@@ -23694,13 +24186,14 @@ async function main() {
|
|
|
23694
24186
|
process.stderr.write(`nice-commander: ${parsed.error}\n`);
|
|
23695
24187
|
return EXIT.usage;
|
|
23696
24188
|
}
|
|
23697
|
-
if (parsed.help || parsed.command
|
|
24189
|
+
if (parsed.help || parsed.command === "help") {
|
|
23698
24190
|
process.stdout.write(HELP);
|
|
23699
24191
|
return EXIT.ok;
|
|
23700
24192
|
}
|
|
23701
|
-
const
|
|
24193
|
+
const requested = parsed.command ?? "ui";
|
|
24194
|
+
const command = COMMANDS[requested];
|
|
23702
24195
|
if (command == null) {
|
|
23703
|
-
process.stderr.write(`nice-commander: unknown command "${
|
|
24196
|
+
process.stderr.write(`nice-commander: unknown command "${requested}" (--help lists them)\n`);
|
|
23704
24197
|
return EXIT.usage;
|
|
23705
24198
|
}
|
|
23706
24199
|
try {
|
|
@@ -23737,19 +24230,25 @@ exports.COMMANDER_TICKET_PATH = COMMANDER_TICKET_PATH;
|
|
|
23737
24230
|
exports.COMMANDER_TICKET_PROTOCOL_PREFIX = COMMANDER_TICKET_PROTOCOL_PREFIX;
|
|
23738
24231
|
exports.COMMANDER_WS_PATH = COMMANDER_WS_PATH;
|
|
23739
24232
|
exports.RuntimeCoordinate = RuntimeCoordinate;
|
|
24233
|
+
exports.applyEnvMutation = applyEnvMutation;
|
|
23740
24234
|
exports.commanderChannel = commanderChannel;
|
|
23741
24235
|
exports.commanderControlDomain = commanderControlDomain;
|
|
23742
24236
|
exports.commanderStatePaths = commanderStatePaths;
|
|
23743
24237
|
exports.commanderStatusRealm = commanderStatusRealm;
|
|
24238
|
+
exports.countOverrides = countOverrides;
|
|
23744
24239
|
exports.createDefaultServeLogger = createDefaultServeLogger;
|
|
23745
24240
|
exports.createMemoryStorageAdapter_json = createMemoryStorageAdapter_json;
|
|
23746
24241
|
exports.createRealmAcceptor = createRealmAcceptor;
|
|
23747
24242
|
exports.createRealmServerEngine = createRealmServerEngine;
|
|
24243
|
+
exports.effectiveEnv = effectiveEnv;
|
|
23748
24244
|
exports.ensureStateDir = ensureStateDir;
|
|
24245
|
+
exports.envVarViews = envVarViews;
|
|
23749
24246
|
exports.httpAcceptorCarrier = httpAcceptorCarrier;
|
|
23750
24247
|
exports.loadCommanderConfigFile = loadCommanderConfigFile;
|
|
23751
24248
|
exports.orderByDependency = orderByDependency;
|
|
24249
|
+
exports.overrideFingerprint = overrideFingerprint;
|
|
23752
24250
|
exports.parseLogsClientMessage = parseLogsClientMessage;
|
|
24251
|
+
exports.readEnvOverrides = readEnvOverrides;
|
|
23753
24252
|
exports.readInstanceRecord = readInstanceRecord;
|
|
23754
24253
|
exports.recordDaemonAlive = recordDaemonAlive;
|
|
23755
24254
|
exports.removeInstanceRecord = removeInstanceRecord;
|