clearotron 0.5.1-beta.0 → 0.5.1-beta.2

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.
@@ -0,0 +1,103 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright 2026 Cordillera Sàrl. Additional terms under section 7 of the AGPL-3.0 apply — see ADDITIONAL-TERMS.md
3
+ // how-it-runs.mjs — how the process refusing an order runs, as the remedy it names needs it.
4
+ //
5
+ // An install that cannot search refuses an order, and three places tell the person who runs it what to do: the
6
+ // portal, the run's refusal in the operator's log, and `clearotron start`. What to do depends on the
7
+ // configuration the refusing process actually uses and on how it is reloaded (the owner's words, composed in
8
+ // driver/run-requirements.mjs, `remedyFor`). This reads that, once, for the portal and the runner alike:
9
+ //
10
+ // launcher a user unit among the product's units, which are byte for byte what `clearotron start
11
+ // --background` writes, with no server unit it does not manage beside them. They read
12
+ // `unitEnvPath()`, and that command adds a line the file lacks and never replaces one.
13
+ // units a user unit among the product's units, otherwise. Their `EnvironmentFile=` lines name one file.
14
+ // service run by systemd, and not one of the above: a system unit, another unit, or units that name no one
15
+ // file. Nothing here can name its configuration or its restart.
16
+ // start a child of a foreground `clearotron start`, which hands it the file it read as a flag.
17
+ // hand started some other way: it reads its own settings file, or none.
18
+ //
19
+ // READS ONLY: files, the process's own cgroup and its own environment. No `systemctl`, no process. Every input is
20
+ // a parameter, so a test drives each state over a machine of its own and never this machine's units.
21
+ import { existsSync, readFileSync } from "node:fs";
22
+ import { join, dirname } from "node:path";
23
+ import { homedir } from "node:os";
24
+ import { fileURLToPath } from "node:url";
25
+ import { SERVER_INSTALL_SET, SERVER_UNITS, aBackgroundStartRefreshes } from "../shared/server-units.mjs";
26
+ import { mergeEnvFile } from "../shared/env-file-merge.mjs";
27
+ import { unitEnvPath, activeEnvPath, envFileRead } from "../shared/env-local.mjs";
28
+ import { environmentFilesOf } from "./unit-environment.mjs";
29
+ import { startEnvFileOf } from "./run-requirements.mjs";
30
+
31
+ const INSTALL_ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
32
+ const readText = (path) => readFileSync(path, "utf8");
33
+ const readOrNull = (read, path) => { try { return read(path); } catch { return null; } };
34
+ const readCgroup = () => readOrNull(readText, "/proc/self/cgroup");
35
+
36
+ /**
37
+ * This process's own systemd unit and the manager that runs it, from the text of `/proc/self/cgroup`, or null.
38
+ * cgroup v2 writes one line, `0::<path>`; v1 writes one per controller, and systemd's is `N:name=systemd:<path>`.
39
+ * A path through `user@<uid>.service` is the user's manager, and one under `/system.slice/` is the system's.
40
+ * Null when no line names a service unit under either. PURE.
41
+ */
42
+ export function ownUnit(cgroupText) {
43
+ for (const line of String(cgroupText ?? "").split("\n")) {
44
+ const m = /^\d+:(?:name=systemd)?:(\/\S*)$/.exec(line.trim());
45
+ if (!m) continue;
46
+ const unit = /\/([^/]+\.service)$/.exec(m[1])?.[1];
47
+ if (!unit) continue;
48
+ if (/\/user@\d+\.service\//.test(m[1])) return { manager: "user", unit };
49
+ if (m[1].startsWith("/system.slice/")) return { manager: "system", unit };
50
+ }
51
+ return null;
52
+ }
53
+
54
+ /** A unit's declared systemd Type, lowercased; `simple` when the text says none. */
55
+ const unitType = (text) => (String(text ?? "").match(/^Type=(\w+)/m)?.[1] ?? "simple").toLowerCase();
56
+
57
+ /**
58
+ * How this process runs. `missing` is the order-time rows the install lacks (run-requirements.mjs). Returns one
59
+ * of the states in this file's header:
60
+ * { kind: "launcher", file, units, noLineYet, launcherFile } `noLineYet`: no missing setting has a line in
61
+ * `file`, by the merge's own rule, under which a `NAME=` line counts as present even when empty.
62
+ * `launcherFile` is the install's settings file a background start adds from, or null when there is none
63
+ * separate from `file`: then that start adds from the environment it runs in.
64
+ * { kind: "units", file, units }
65
+ * { kind: "service" }
66
+ * { kind: "start" }
67
+ * { kind: "hand", file } `file` is the settings file this process reads, or null when it reads none.
68
+ * `units` is the installed product units that run continuously, the ones to restart.
69
+ */
70
+ export function howItRuns({ missing = [], env = process.env, argv = process.argv, home = homedir(), repoRoot = INSTALL_ROOT,
71
+ cgroup = readCgroup, readFile = envFileRead, exists = existsSync, read = readText,
72
+ template = (u) => readOrNull(readText, join(repoRoot, "driver", "systemd", u)) } = {}) {
73
+ if (String(env?.INVOCATION_ID ?? "").trim()) {
74
+ const own = ownUnit(cgroup());
75
+ const unitDir = join(home, ".config", "systemd", "user");
76
+ const installed = [...new Set([...SERVER_INSTALL_SET, ...SERVER_UNITS])].filter((u) => exists(join(unitDir, u)));
77
+ if (own?.manager !== "user" || !installed.includes(own.unit)) return { kind: "service" };
78
+ const texts = Object.fromEntries(installed.map((u) => [u, readOrNull(read, join(unitDir, u))]));
79
+ const units = installed.filter((u) => unitType(texts[u]) !== "oneshot");
80
+ const launcher = aBackgroundStartRefreshes(SERVER_UNITS.filter((u) => installed.includes(u)))
81
+ && installed.filter((u) => SERVER_INSTALL_SET.includes(u))
82
+ .every((u) => texts[u] !== null && texts[u] === template(u));
83
+ if (launcher) {
84
+ const file = unitEnvPath({ home });
85
+ let text = "";
86
+ let known = true;
87
+ try { text = read(file); } catch (e) { if (e?.code !== "ENOENT") known = false; }
88
+ const names = missing.flatMap((r) => r.anyOf ?? [r.name]);
89
+ const noLineYet = known && names.every((n) => mergeEnvFile(text, { [n]: "x" }).added.includes(n));
90
+ const settings = activeEnvPath({ repoRoot, home });
91
+ return { kind: "launcher", file, units, noLineYet, launcherFile: settings !== file && exists(settings) ? settings : null };
92
+ }
93
+ const files = new Set();
94
+ for (const u of installed) {
95
+ const named = texts[u] === null ? null : environmentFilesOf(texts[u], home);
96
+ if (!named || named.length !== 1) return { kind: "service" };
97
+ files.add(named[0]);
98
+ }
99
+ return files.size === 1 ? { kind: "units", file: [...files][0], units } : { kind: "service" };
100
+ }
101
+ if (startEnvFileOf(argv)) return { kind: "start" };
102
+ return { kind: "hand", file: readFile() ?? null };
103
+ }
@@ -84,7 +84,8 @@ export function ownersOwedACheck(recordsDoc, { cap = OWNER_CHECK_CAP } = {}) {
84
84
  // classes it actually searched. Passing the entry's own classes as the mark's keeps the predicate
85
85
  // reading the same scope it reads at publish time instead of silently widening to every record.
86
86
  // THE READING STEP NAMES THE FILINGS WHOSE OWNER MERITS A SEARCH, where it finished: judgment, not the first few owners
87
- // of what would be promoted. A run whose step did not finish keeps the bounded rule below.
87
+ // of what would be promoted. A run whose step did not finish keeps the bounded rule below. Either way at most
88
+ // `cap` owners per name are searched (owner's ruling, 2026-11-08), in the register's record order.
88
89
  const named = Array.isArray(entry?.reading?.ownerChecks) ? new Set(entry.reading.ownerChecks.map(String)) : null;
89
90
  const promoted = named ? (entry?.records ?? []).filter((r) => named.has(String(r?.recordId ?? ""))) : promotableRecords(entry, { classesSearched: entry?.classes ?? [] });
90
91
  const byOwner = new Map();
@@ -100,7 +101,7 @@ export function ownersOwedACheck(recordsDoc, { cap = OWNER_CHECK_CAP } = {}) {
100
101
  for (const c of (Array.isArray(r.classes) ? r.classes : [])) if (Number.isFinite(Number(c))) g.classes.add(Number(c));
101
102
  byOwner.set(key, g);
102
103
  }
103
- for (const g of named ? [...byOwner.values()] : [...byOwner.values()].slice(0, cap)) {
104
+ for (const g of [...byOwner.values()].slice(0, cap)) {
104
105
  out.push({ mark: g.mark, owner: g.owner, recordIds: g.recordIds.filter(Boolean), classes: [...g.classes].sort((a, b) => a - b) });
105
106
  }
106
107
  }
@@ -2,7 +2,7 @@
2
2
  "name": "clearotron-driver",
3
3
  "private": true,
4
4
  "type": "module",
5
- "version": "0.5.1-beta.0",
5
+ "version": "0.5.1-beta.2",
6
6
  "license": "AGPL-3.0-only",
7
7
  "description": "Deterministic driver for the trademark clearance workflow: orchestration in code (fan-out, fan-in barrier, gating, retries); the model does judgment leaves only, through a reasoning CLI spawned per stage.",
8
8
  "engines": {
@@ -35,7 +35,7 @@
35
35
  import "../shared/env-local.mjs"; // — FIRST: applies the CLEAROTRON_* translation before any module-top
36
36
  // capture evaluates. Reads no `.env` here — that load is gated on isCliEntry(argv[1]).
37
37
  import { readFileSync, existsSync, readdirSync, statSync } from "node:fs";
38
- import { hostname as osHostname } from "node:os"; // — the address a refusal page names when nothing else identifies this instance
38
+ import { hostname as osHostname, homedir } from "node:os"; // — the address a refusal page names when nothing else identifies this instance
39
39
 
40
40
  // The port this service listens on when nobody says otherwise. Declared here rather than at the
41
41
  // listener, because the refusal page names the address too and it is composed on IMPORT-side code: the
@@ -46,6 +46,7 @@ import { storeInRepo, storeOutsideRepoMessage, makeCommittableAudit, resolveStor
46
46
  import { customerStoreDir, customerStoreLine } from "../shared/customer-store.mjs"; // — one store for the surface and the runs
47
47
  import { clientFailureNote } from "../shared/client-failure-note.mjs"; // — one sentence, three surfaces
48
48
  import { bareInvocation, browserCommand, invocationPrefix, installRoute, npxVersionOf } from "../shared/invocation.mjs"; // — and why this one surface is by NAME
49
+ import { channelOf, channelPackage, ownVersion } from "../shared/permanent-install.mjs"; // — which release channel this install came from
49
50
  import { stdioConnectOffer, stdioConnectFor, STDIO_SHAPES } from "../shared/stdio-connect.mjs"; // — ONE author for the connect route
50
51
  import { isWsl, wslTarget } from "../shared/wsl.mjs"; // — on WSL, the connect lines say where they run and cross the boundary themselves
51
52
  import { doorKind } from "../shared/mcp-challenge.mjs"; // — one reading of what a connector asks for, shared with doctor
@@ -153,6 +154,7 @@ import { readFlagSnapshot, builtFor, registerCanCountFor, registerTerritoriesFor
153
154
  import { isDemo, demoPostureLine } from "./demo-posture.mjs";
154
155
  import { orderTimeRefusal } from "./run-requirements.mjs"; // the runner's own test for "can this install run a search"
155
156
  import { runTables } from "./order-tables.mjs"; // …asked of the runner's own tables, so the two cannot disagree
157
+ import { howItRuns } from "./how-it-runs.mjs"; // …and the remedy, for how this portal runs
156
158
  import { triggerCapGap, triggerCapWarning } from "./trigger-cap.mjs"; // F51 — one answer, three surfaces
157
159
  import { makeUpstream } from "./portal-upstream.mjs";
158
160
  import { flagView, accessView, observedView, authView } from "./portal-config-view.mjs";
@@ -187,6 +189,16 @@ import { deploymentBox } from "../shared/deployment-box.mjs"; // — the box n
187
189
  import { stageNow } from "./progress.mjs"; // the stage a live run is in now, for the card and the row
188
190
  // A run in one of these has finished; its step is the one its terminal write set, not the stage it last entered.
189
191
  const TERMINAL_STATES = new Set(["delivered", "failed", "cancelled"]);
192
+ // This install's release channel, `beta` or `latest`, read once off its own version. /me carries it.
193
+ const INSTALL_CHANNEL = channelOf(ownVersion());
194
+
195
+ /**
196
+ * The operator's line when the brief reader cannot be built: why, and the check to run, ON THIS CHANNEL.
197
+ * `npx clearotron doctor` fetches the stable, which on a beta reads the beta's install with the other code.
198
+ */
199
+ export function briefReadingOffLine(reason, pkg = channelPackage()) {
200
+ return `brief reading OFF — ${reason}. Describe-it stays disabled; \`npx ${pkg} doctor\` reports the engine's auth state.`;
201
+ }
190
202
 
191
203
  // The offering the portal menus build from — product-rows.mjs's row, unchanged.
192
204
  //
@@ -1188,6 +1200,17 @@ export function makeConnectorKeyRevoker({ env = process.env, home = null } = {})
1188
1200
  // that sets it; everyone else is shown the client sentence, which names neither.
1189
1201
  const refusalFor = (principal, refusal) => (seesEverything(principal) && refusal.installer) || refusal.client;
1190
1202
 
1203
+ /**
1204
+ * The portal's own question about an order: the runner's (`orderTimeRefusal`), with the remedy the person who runs
1205
+ * the install is shown read from how THIS portal runs (driver/how-it-runs.mjs): the configuration it actually uses,
1206
+ * and how it is reloaded. Every input is a parameter, so a test plants a machine, an environment, a command line
1207
+ * and a cgroup of its own; each one left out is this process's own.
1208
+ */
1209
+ export function portalOrderRefusal({ env = process.env, tables = {}, argv, home = homedir(), repoRoot = INSTALL_ROOT, cgroup, readFile, exists, read, template } = {}) {
1210
+ return orderTimeRefusal(env, tables, {
1211
+ howFor: (missing) => howItRuns({ missing, env, argv, home, repoRoot, cgroup, readFile, exists, read, template }) });
1212
+ }
1213
+
1191
1214
  export function makePortalService({
1192
1215
  poolRoot, workspaceRoot, recipesDir = undefined, secret,
1193
1216
  grants = null,
@@ -1676,7 +1699,14 @@ export function makePortalService({
1676
1699
  // must leave the button alone rather than infer demo from an absent file.
1677
1700
  // READ ONCE. The payload names it and the program reading below is gated on it; two calls to
1678
1701
  // `flagView` here would be two reads of the same file that could disagree with each other.
1679
- const meEngineMode = flagView(poolRoot).engineMode;
1702
+ //
1703
+ // A DEMO ANSWERS NULL. No order in a demo reaches an engine: the run route below resolves each one
1704
+ // to the finished example for the search picked (`if (demo)`), which is what the demo's banner
1705
+ // promises. The demo's snapshot still describes the machine, so on a machine with no engine program
1706
+ // this read "demo", and New clearance drew the no-engine notice where Review search belongs: the
1707
+ // one flow the demo exists to show could not be started. Null leaves the button alone, as it does
1708
+ // on a fresh install, and the configuration page still reads the snapshot for itself.
1709
+ const meEngineMode = demo ? null : flagView(poolRoot).engineMode;
1680
1710
  const searchRefusal = demo ? null : await orderRefusal();
1681
1711
  // THE HOUSE MARKETPLACES, offered as suggestions wherever a company's marketplaces are edited. A new
1682
1712
  // company starts with none (the owner's ruling of 2026-09-23) and somebody picks; these are the
@@ -1712,6 +1742,10 @@ export function makePortalService({
1712
1742
  // half its readers. A WORD, never a command line and never a prefix: `invocationForm` can
1713
1743
  // answer with this machine's absolute path, and this value is rendered in a browser.
1714
1744
  setupRoute: installRoute(),
1745
+ // WHICH RELEASE CHANNEL THIS INSTALL CAME FROM, read off its own version as `update` reads it, so the
1746
+ // setup command a screen names fetches this channel. `npx clearotron install` fetches the stable, and
1747
+ // the stable's setup then moves itself into ~/.local over a beta. A WORD, like the route above.
1748
+ channel: INSTALL_CHANNEL,
1715
1749
  // THE COMMAND THAT FILES AN ORGANISATION, for the screen that cannot create a company without one.
1716
1750
  // `browserCommand`'s rule: no path on this machine, and from npx's cache the published version
1717
1751
  // rather than a bare name that reader does not have.
@@ -5303,7 +5337,7 @@ const PORT = PORT_CHOICE.port;
5303
5337
  if (runner?.error) {
5304
5338
  // NAMES THE CONDITION, on the operator's surface. The client-facing note stays client-facing;
5305
5339
  // this is the line whose absence made a billing posture look like a forgotten switch.
5306
- log(`brief reading OFF — ${runner.error}. Describe-it stays disabled; \`npx clearotron doctor\` reports the engine's auth state.`);
5340
+ log(briefReadingOffLine(runner.error));
5307
5341
  return null;
5308
5342
  }
5309
5343
  log(`brief reading ON — engine=${runner.engine} billing=${runner.authMode} model=${model}`);
@@ -5335,7 +5369,7 @@ const PORT = PORT_CHOICE.port;
5335
5369
  // demo out of one. Anything but the literal "1" is not a demo.
5336
5370
  demo: isDemo(process.env), // — one name, shared with the MCP door
5337
5371
  // The runner's own order-time test, asked of the runner's own tables: the portal refuses what the runner would.
5338
- orderRefusal: async () => orderTimeRefusal(process.env, await runTables()) });
5372
+ orderRefusal: async () => portalOrderRefusal({ tables: await runTables() }) });
5339
5373
  const { RateLimiter } = await import("../mcp-server/lib/ratelimit.mjs");
5340
5374
  const limiter = new RateLimiter({ perMinute: Number(process.env.PORTAL_RATE_PER_MIN || 120) });
5341
5375
  const { createServer } = await import("node:http");
@@ -369,14 +369,50 @@ export function whatIsMissing(rows = []) {
369
369
  }
370
370
 
371
371
  /**
372
- * The first two sentences of the refusal the person who runs the install is shown, in the owner's words
373
- * (2026-11-06): what the install lacks for a search (`missing`, as whatIsMissing words it) and the command
374
- * that sets it up. `install` is that command as the reader types it: the portal names `clearotron install`,
375
- * and `doctor` names it as it runs from where doctor ran. One composer, so the portal's sentence and
376
- * doctor's opening cannot drift apart. PURE.
372
+ * What the person who runs the install is told to do, for how the refusing process runs (the owner's words,
373
+ * 2026-11-07). `how` is driver/how-it-runs.mjs's answer. The portal and the run's refusal say the same remedy;
374
+ * `it` names the refusing process where the remedy speaks of it ("the portal", "this runner"), and `install` is
375
+ * the setup command as the reader types it. Null when `how` names no state. PURE.
376
+ *
377
+ * LAUNCHER UNITS, NO LINE YET: setup writes the install's settings and `clearotron start --background` adds what
378
+ * the services' file lacks, then restarts them. Anywhere else that route is not the whole remedy. A background
379
+ * start keeps a line already in the file, an empty one included, and it does not manage units it did not write.
380
+ * There the reader sets each setting where the process reads it and restarts it, by the restart this machine
381
+ * has: `systemctl --user` for the product's own user units, nothing named for a service this cannot see.
382
+ */
383
+ export function remedyFor(how, { it = "the portal", install = "clearotron install" } = {}) {
384
+ switch (how?.kind) {
385
+ case "launcher":
386
+ return how.noLineYet
387
+ ? `Its background services read their settings from ${how.file}. Run \`${install}\` in a terminal to set it up, then \`clearotron start --background\`: it adds the missing lines to that file and restarts the services.`
388
+ : `Its background services read their settings from ${how.file}. \`clearotron start --background\` only adds a setting that file has no line for; it never replaces one. Set each missing setting in that file and in ${how.launcherFile ?? "the environment you run `clearotron start --background` in"}, then restart the services: \`systemctl --user restart ${how.units.join(" ")}\`.`;
389
+ case "units":
390
+ return `Its background services read their settings from ${how.file}. Set each missing setting in that file, then restart the services: \`systemctl --user restart ${how.units.join(" ")}\`.`;
391
+ case "service":
392
+ return "Its services take their settings from the service manager that runs them. Set each missing setting there, then restart the services.";
393
+ case "start":
394
+ return `Run \`${install}\` in a terminal to set it up, then stop \`clearotron start\` with Ctrl-C and run it again: it reads the settings setup writes when it starts.`;
395
+ case "hand":
396
+ return `Set each missing setting in ${how.file ? `${how.file}, which ${it} reads when it starts` : `the environment ${it} runs in`}, then start ${it} again.`;
397
+ default:
398
+ return null;
399
+ }
400
+ }
401
+
402
+ /** Whether the remedy has the reader set settings by hand: then the portal, which never names one, points at doctor. */
403
+ const setsByHand = (how) => Boolean(how?.kind) && !(how.kind === "start" || (how.kind === "launcher" && how.noLineYet));
404
+
405
+ /**
406
+ * The refusal the person who runs the install is shown, up to its closing sentence: what the install lacks for a
407
+ * search (`missing`, as whatIsMissing words it), and the remedy for how the refusing process runs (`how`, see
408
+ * remedyFor). With no `how`, the words for a machine nothing is known about: run setup. `install` is the setup
409
+ * command as the reader types it: the portal names `clearotron install`, and `doctor` names it as it runs from
410
+ * where doctor ran. One composer, so the portal's sentence and doctor's opening cannot drift apart. PURE.
377
411
  */
378
- export function cannotSearchYet(missing, install = "clearotron install") {
379
- return `This install cannot run a search yet: ${missing}. Run \`${install}\` in a terminal to set it up.`;
412
+ export function cannotSearchYet(missing, install = "clearotron install", how = null) {
413
+ const head = `This install cannot run a search yet: ${missing}.`;
414
+ const remedy = remedyFor(how, { install });
415
+ return remedy ? `${head} ${remedy}` : `${head} Run \`${install}\` in a terminal to set it up.`;
380
416
  }
381
417
 
382
418
  /**
@@ -391,62 +427,50 @@ export function cannotSearchYet(missing, install = "clearotron install") {
391
427
  * says anybody has been notified — which is the sentence F41 delivered while nobody had been.
392
428
  *
393
429
  * Returns null when nothing blocks, so a caller cannot mistake "configured" for "could not look".
430
+ *
431
+ * `howFor` is how the caller runs: given the missing rows, it answers driver/how-it-runs.mjs's `howItRuns`. The
432
+ * portal passes one (portalOrderRefusal) and so does the runner (runner.mjs), each for its own process, so the
433
+ * remedy names the configuration that process actually uses and how to reload it. Without one, the operator is
434
+ * pointed at setup and the units' file, and the person who runs the install at setup: the words for a process
435
+ * nothing is known about.
394
436
  */
395
- export function orderTimeRefusal(env = {}, tables = {}, { envFile = null, readFile = null, startFile = null } = {}) {
437
+ export function orderTimeRefusal(env = {}, tables = {}, { howFor = null } = {}) {
396
438
  const missing = missingRequirements(env, tables).atOrder;
397
439
  if (!missing.length) return null;
398
440
  const names = missing.map((r) => r.name);
399
441
  const gap = whatIsMissing(missing);
400
- // EVERY FILE THAT REACHES THIS RUN, EACH NAMED BY WHAT READS IT — the rule `bin/start.mjs` already
401
- // follows, for the reason it gives: two copies of this sentence is how one of them comes to name a file
402
- // the reader cannot use. This copy named only `envFile`, the file background units read. A runner
403
- // started from a terminal on a box with no units reads the install's own file instead, so its operator
404
- // was told to create a file nothing on that box reads — and the one actually read went unnamed.
405
- // `readFile` is the file THIS process loaded at start; it is null under a unit, where the unit's own
406
- // EnvironmentFile is the only configuration and `envFile` alone is the true answer.
407
- //
408
- // AND A RUNNER THAT `clearotron start` STARTED READ NO FILE EITHER. The supervisor read the install's own
409
- // file and handed its values down with CLEAROTRON_NO_ENV_FILE=1, so `readFile` is null there exactly as
410
- // it is under a unit, and this sentence named the units' file: on a box with no units, a file that does
411
- // not exist, while the file the values came from went unnamed. Measured on a fresh install, 2026-09-10.
412
- // `startFile` is the file that supervisor read. It reaches the runner as a command-line flag that a unit's
413
- // fixed ExecStart never carries, so it is set exactly when `clearotron start` is the parent.
414
- const cmd = "`clearotron install` in a terminal, which writes them for you";
415
- const both = readFile && envFile && readFile !== envFile;
416
- const one = readFile || envFile;
417
- const where = both
418
- ? ` Set them in either of these — both reach a run:\n ${readFile} — the file this runner read when it started\n`
419
- + ` ${envFile} — the file background units read\n then restart, or run ${cmd}.`
420
- : !readFile && startFile
421
- ? ` Set them in ${startFile} — the file \`clearotron start\` read when it started this runner — then restart it, or run ${cmd}.`
422
- : one
423
- ? ` Set them in ${one} and restart, or run ${cmd}.`
424
- : " Run `clearotron install` in a terminal to configure them, or set them in the file this install's units read.";
442
+ const how = howFor ? howFor(missing) : null;
443
+ const forOperator = remedyFor(how, { it: "this runner" })
444
+ ?? "Run `clearotron install` in a terminal to configure them, or set them in the file this install's units read.";
425
445
  return {
426
446
  names,
427
447
  missing: gap,
428
448
  operator: `this installation cannot run a search yet — it is installed but not configured:\n`
429
449
  + missing.map((r) => ` ${r.name} — ${r.why}`).join("\n")
430
- + `\n\n Nothing has been searched and nothing has been spent.${where}`,
450
+ + `\n\n Nothing has been searched and nothing has been spent. ${forOperator}`,
431
451
  // ONE SENTENCE, NO NAMES, AND NO PROMISE. "Contact" rather than "we have been notified": this
432
452
  // product has no outbox on a box in this state, so a notice would be the F41 lie one level up.
433
453
  client: CLIENT_REFUSAL,
434
- // THE PERSON WHO RUNS THE INSTALL is shown what is missing and the command that sets it, in the owner's words
435
- // (2026-11-06). The portal shows this to a person who sees everything, the one its Installation settings
436
- // page is for, and the client sentence to everyone else. A gap with no phrase keeps the client sentence.
437
- installer: gap ? `${cannotSearchYet(gap)} Nothing has been searched and nothing has been charged.` : CLIENT_REFUSAL,
454
+ // THE PERSON WHO RUNS THE INSTALL is shown what is missing and what to do, in the owner's words. The portal shows
455
+ // this to a person who sees everything, the one its Installation settings page is for, and the client sentence
456
+ // to everyone else. A gap with no phrase keeps the client sentence. The browser is never shown a setting's
457
+ // name, so where the remedy has the reader set settings by hand, it points at doctor, which names them.
458
+ installer: gap
459
+ ? `${cannotSearchYet(gap, "clearotron install", how)}${setsByHand(how) ? " `clearotron doctor` names each setting." : ""} `
460
+ + "Nothing has been searched and nothing has been charged."
461
+ : CLIENT_REFUSAL,
438
462
  };
439
463
  }
440
464
 
441
465
  const CLIENT_REFUSAL = "This installation is not configured to run searches yet. Nothing has been searched and "
442
466
  + "nothing has been charged. Please contact whoever administers it.";
443
467
 
444
- // THE ENV FILE `clearotron start` READ, when it started this runner: the one file a refusal can honestly
445
- // name for a runner that read none itself (`startFile` above). A command-line flag rather than a variable,
446
- // for two reasons. A unit's ExecStart is fixed at `--watch` and never carries it, so a runner holding it
447
- // was started by that command. And a variable read by product code belongs in the environment catalogue,
448
- // which describes settings an operator makes, and this is not one. `bin/start.mjs` puts it on the
449
- // worker's command line, and `driver/runner.mjs` reads it off its own.
468
+ // THE ENV FILE `clearotron start` READ, when it started this process: the file the settings of a process that
469
+ // read none itself came from, and the sign that a foreground start is what must be run again to reload them
470
+ // (driver/how-it-runs.mjs, the `start` state). A command-line flag rather than a variable, for two reasons. A
471
+ // unit's ExecStart is fixed and never carries it, so a process holding it was started by that command. And a
472
+ // variable read by product code belongs in the environment catalogue, which describes settings an operator
473
+ // makes, and this is not one. `bin/start.mjs` puts it on the worker's and the portal's command lines.
450
474
  export const START_ENV_FILE_FLAG = "--start-env-file=";
451
475
 
452
476
  /** The path `argv` carries in `--start-env-file=<path>`, or null when it carries none or an empty one. PURE. */
package/driver/runner.mjs CHANGED
@@ -28,9 +28,9 @@ import { driverDir, ensureDriverDir } from "../shared/driver-dir.mjs"; // —
28
28
  // other nine. Behaviour here is unchanged: the same object and the same three suffixes, sourced.
29
29
  import { isLiveQueueMarker, PROSE_PARTS, CLAIM_SIDECAR_SUFFIXES, TERMINAL_QUEUE_SUFFIXES, withFoldedGoods } from "./queue-markers.mjs";
30
30
  import { matterLedgerPath, DEFAULT_CLIENT_DAILY_RUNS } from "./usage-ledger.mjs"; // ONE ledger-path calculation, shared with the portal pre-check
31
- import { orderTimeRefusal, START_ENV_FILE_FLAG, startEnvFileOf } from "./run-requirements.mjs"; // one authority for what a run needs, and when it is asked for
31
+ import { orderTimeRefusal, START_ENV_FILE_FLAG } from "./run-requirements.mjs"; // one authority for what a run needs, and when it is asked for
32
32
  import { runTables } from "./order-tables.mjs"; // the tables the portal's order door reads too, so the two cannot disagree
33
- import { unitEnvPath, envFileRead } from "../shared/env-local.mjs"; // the file the units read, named by its one author
33
+ import { howItRuns } from "./how-it-runs.mjs"; // how this runner runs, for the remedy its refusal names
34
34
  import { fileURLToPath } from "node:url";
35
35
  import { config, preflightDeploymentUrls } from "./driver.config.mjs";
36
36
  import { deriveSlug, todayISO, mintFreshCodename } from "./phase0.mjs";
@@ -869,7 +869,9 @@ async function claimAndPrep(jsonFile, qdir, agentId) {
869
869
  }
870
870
  // ── IS THIS BOX CONFIGURED TO SEARCH AT ALL? See the header above claimAndPrep.
871
871
  {
872
- const refusal = orderTimeRefusal(process.env, await runTables(), { envFile: unitEnvPath(), readFile: envFileRead(), startFile: startEnvFileOf(process.argv) });
872
+ // The remedy names the configuration THIS runner uses and how it is reloaded: its unit's, the file the
873
+ // foreground start that launched it read, or its own (driver/how-it-runs.mjs).
874
+ const refusal = orderTimeRefusal(process.env, await runTables(), { howFor: (missing) => howItRuns({ missing }) });
873
875
  if (refusal) {
874
876
  note(`[runner] ${base} REFUSED at order time — this install is not configured to run a search: ${refusal.names.join(", ")}`);
875
877
  await failAtIntake(procPath, qdir, base, agentId, job,
@@ -99,6 +99,12 @@
99
99
  "skips": 0,
100
100
  "todos": 0
101
101
  },
102
+ "a-brief-is-read-only-by-an-ai-that-is-chosen.test.mjs": {
103
+ "tests": 3,
104
+ "asserts": 17,
105
+ "skips": 3,
106
+ "todos": 0
107
+ },
102
108
  "a-browser-run-gets-its-own-temp-root.test.mjs": {
103
109
  "tests": 13,
104
110
  "asserts": 32,
@@ -123,6 +129,12 @@
123
129
  "skips": 0,
124
130
  "todos": 0
125
131
  },
132
+ "a-cancelled-setup-names-what-stays.test.mjs": {
133
+ "tests": 6,
134
+ "asserts": 14,
135
+ "skips": 5,
136
+ "todos": 0
137
+ },
126
138
  "a-cap-of-zero-is-not-a-register-outcome.test.mjs": {
127
139
  "tests": 3,
128
140
  "asserts": 6,
@@ -315,6 +327,12 @@
315
327
  "skips": 1,
316
328
  "todos": 0
317
329
  },
330
+ "a-command-printed-on-a-beta-fetches-the-beta.test.mjs": {
331
+ "tests": 2,
332
+ "asserts": 9,
333
+ "skips": 0,
334
+ "todos": 0
335
+ },
318
336
  "a-common-law-coverage-status-is-read-as-data.test.mjs": {
319
337
  "tests": 14,
320
338
  "asserts": 50,
@@ -1139,7 +1157,7 @@
1139
1157
  },
1140
1158
  "a-knockout-reads-the-register-by-judgment.test.mjs": {
1141
1159
  "tests": 45,
1142
- "asserts": 209,
1160
+ "asserts": 211,
1143
1161
  "skips": 0,
1144
1162
  "todos": 0
1145
1163
  },
@@ -2837,7 +2855,7 @@
2837
2855
  },
2838
2856
  "an-install-that-cannot-search-refuses-the-order-at-review.test.mjs": {
2839
2857
  "tests": 9,
2840
- "asserts": 39,
2858
+ "asserts": 40,
2841
2859
  "skips": 0,
2842
2860
  "todos": 0
2843
2861
  },
@@ -3814,8 +3832,8 @@
3814
3832
  "todos": 0
3815
3833
  },
3816
3834
  "doctor-does-not-tick-a-billing-mode-it-cannot-see.test.mjs": {
3817
- "tests": 5,
3818
- "asserts": 8,
3835
+ "tests": 6,
3836
+ "asserts": 12,
3819
3837
  "skips": 0,
3820
3838
  "todos": 0
3821
3839
  },
@@ -3831,6 +3849,12 @@
3831
3849
  "skips": 0,
3832
3850
  "todos": 0
3833
3851
  },
3852
+ "doctor-reads-only-the-ai-that-is-chosen.test.mjs": {
3853
+ "tests": 2,
3854
+ "asserts": 23,
3855
+ "skips": 2,
3856
+ "todos": 0
3857
+ },
3834
3858
  "doctor-reads-the-units-not-the-shell.test.mjs": {
3835
3859
  "tests": 45,
3836
3860
  "asserts": 128,
@@ -4937,7 +4961,7 @@
4937
4961
  },
4938
4962
  "onboard-wizard.test.mjs": {
4939
4963
  "tests": 78,
4940
- "asserts": 302,
4964
+ "asserts": 303,
4941
4965
  "skips": 4,
4942
4966
  "todos": 0
4943
4967
  },
@@ -5272,8 +5296,8 @@
5272
5296
  "todos": 0
5273
5297
  },
5274
5298
  "portal-service.test.mjs": {
5275
- "tests": 133,
5276
- "asserts": 718,
5299
+ "tests": 136,
5300
+ "asserts": 732,
5277
5301
  "skips": 1,
5278
5302
  "todos": 0
5279
5303
  },
@@ -6881,7 +6905,7 @@
6881
6905
  },
6882
6906
  "the-demo-reads-no-brief-and-drains-no-queue.test.mjs": {
6883
6907
  "tests": 1,
6884
- "asserts": 13,
6908
+ "asserts": 14,
6885
6909
  "skips": 0,
6886
6910
  "todos": 0
6887
6911
  },
@@ -6958,8 +6982,8 @@
6958
6982
  "todos": 0
6959
6983
  },
6960
6984
  "the-end-of-setup-agrees-with-what-it-left-unset.test.mjs": {
6961
- "tests": 7,
6962
- "asserts": 18,
6985
+ "tests": 8,
6986
+ "asserts": 21,
6963
6987
  "skips": 0,
6964
6988
  "todos": 0
6965
6989
  },
@@ -7366,8 +7390,8 @@
7366
7390
  "todos": 0
7367
7391
  },
7368
7392
  "the-owner-of-a-promoted-filing-is-searched.test.mjs": {
7369
- "tests": 16,
7370
- "asserts": 49,
7393
+ "tests": 17,
7394
+ "asserts": 54,
7371
7395
  "skips": 0,
7372
7396
  "todos": 0
7373
7397
  },
@@ -7623,6 +7647,12 @@
7623
7647
  "skips": 4,
7624
7648
  "todos": 0
7625
7649
  },
7650
+ "the-refusal-names-the-whole-remedy.test.mjs": {
7651
+ "tests": 12,
7652
+ "asserts": 41,
7653
+ "skips": 0,
7654
+ "todos": 0
7655
+ },
7626
7656
  "the-register-claims-check-reads-the-records-the-run-holds.test.mjs": {
7627
7657
  "tests": 10,
7628
7658
  "asserts": 20,
@@ -8715,8 +8745,8 @@
8715
8745
  "todos": 0
8716
8746
  },
8717
8747
  "list-runs-says-when-nothing-is-configured.test.mjs": {
8718
- "tests": 2,
8719
- "asserts": 6,
8748
+ "tests": 3,
8749
+ "asserts": 8,
8720
8750
  "skips": 0,
8721
8751
  "todos": 0
8722
8752
  },
@@ -8893,6 +8923,12 @@
8893
8923
  "portal-ui": {
8894
8924
  "ext": "ts",
8895
8925
  "perFile": {
8926
+ "aScreenAwaitingACompanyAsksNothing.test.ts": {
8927
+ "tests": 2,
8928
+ "asserts": 7,
8929
+ "skips": 0,
8930
+ "todos": 0
8931
+ },
8896
8932
  "about.test.ts": {
8897
8933
  "tests": 3,
8898
8934
  "asserts": 13,
@@ -8906,8 +8942,8 @@
8906
8942
  "todos": 0
8907
8943
  },
8908
8944
  "api.test.ts": {
8909
- "tests": 48,
8910
- "asserts": 195,
8945
+ "tests": 49,
8946
+ "asserts": 199,
8911
8947
  "skips": 0,
8912
8948
  "todos": 0
8913
8949
  },
@@ -9002,8 +9038,8 @@
9002
9038
  "todos": 0
9003
9039
  },
9004
9040
  "engineState.test.ts": {
9005
- "tests": 13,
9006
- "asserts": 59,
9041
+ "tests": 15,
9042
+ "asserts": 68,
9007
9043
  "skips": 0,
9008
9044
  "todos": 0
9009
9045
  },
@@ -9116,8 +9152,8 @@
9116
9152
  "todos": 0
9117
9153
  },
9118
9154
  "newClearanceStructure.test.ts": {
9119
- "tests": 9,
9120
- "asserts": 69,
9155
+ "tests": 10,
9156
+ "asserts": 75,
9121
9157
  "skips": 0,
9122
9158
  "todos": 0
9123
9159
  },
@@ -9182,8 +9218,8 @@
9182
9218
  "todos": 0
9183
9219
  },
9184
9220
  "profileFields.test.ts": {
9185
- "tests": 55,
9186
- "asserts": 178,
9221
+ "tests": 57,
9222
+ "asserts": 190,
9187
9223
  "skips": 0,
9188
9224
  "todos": 0
9189
9225
  },
@@ -9206,8 +9242,8 @@
9206
9242
  "todos": 0
9207
9243
  },
9208
9244
  "recommendSearch.test.ts": {
9209
- "tests": 6,
9210
- "asserts": 14,
9245
+ "tests": 7,
9246
+ "asserts": 20,
9211
9247
  "skips": 0,
9212
9248
  "todos": 0
9213
9249
  },