@ultimat3/cli 31.20.0 → 31.22.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.
Files changed (39) hide show
  1. package/CLAUDE.md +1 -1
  2. package/README.md +11 -6
  3. package/package.json +29 -29
  4. package/src/cmd-db.ts +5 -18
  5. package/src/cmd-doctor.ts +8 -3
  6. package/src/cmd-mcp.ts +6 -1
  7. package/src/cmd-verify.ts +19 -15
  8. package/src/db-schema-dump.ts +20 -0
  9. package/src/dev-lock.ts +26 -5
  10. package/src/doctor-guards.ts +27 -12
  11. package/src/drift-store.ts +28 -2
  12. package/src/error-codes-doctor.ts +9 -5
  13. package/src/guards.ts +66 -28
  14. package/src/lint-findings.ts +34 -10
  15. package/src/mcp-agent-host.ts +107 -0
  16. package/src/mcp-errors.ts +4 -0
  17. package/src/mcp-host.ts +23 -1
  18. package/src/mcp-request-statements.ts +129 -0
  19. package/src/mcp-ui.ts +1 -2
  20. package/src/messages.ts +0 -2
  21. package/src/runtime-cache.ts +12 -3
  22. package/src/schema-dump-drift.ts +78 -4
  23. package/src/templates/guard-repo-await-in-loop-test.ts +89 -0
  24. package/src/templates/guard-repo-await-in-loop.ts +214 -0
  25. package/src/templates/guard-repo-unbounded-test.ts +56 -0
  26. package/src/templates/guard-repo-unbounded.ts +197 -0
  27. package/src/templates/scaffold-claude-agents.ts +4 -4
  28. package/src/templates/scaffold-claude-hook.ts +40 -0
  29. package/src/templates/scaffold-claude.ts +22 -6
  30. package/src/templates/scaffold-docs.ts +2 -7
  31. package/src/templates/scaffold-guards.ts +6 -0
  32. package/src/verify-changed.ts +32 -5
  33. package/src/verify-checks.ts +26 -7
  34. package/src/verify-progress.ts +32 -1
  35. package/wiki/CLI-Reference.md +19 -8
  36. package/wiki/MCP-And-AI.md +7 -3
  37. package/wiki/Tutorial-02-First-Feature.md +1 -1
  38. package/wiki/Upgrading.md +7 -0
  39. package/src/retry-memo.ts +0 -37
package/CLAUDE.md CHANGED
@@ -174,7 +174,7 @@ Commands: `bun test ./packages/cli/` (repo root: the preload),
174
174
  |---|---|
175
175
  | `cmd-registries.ts` / `cmd-jobs.ts` / `cmd-tasks.ts` / `cmd-policy.ts` / `cmd-i18n.ts` | project a framework registry; each pairs CLI wiring with a facts module |
176
176
  | `cmd-auth.ts` / `cmd-auth-spec.ts` / `doctor-auth.ts` | `x auth seal-mfa`: seals plaintext `x_users.mfa_secret` through auth's `sealMfaSecrets` |
177
- | `cmd-mcp.ts` / `mcp-host.ts` / `mcp-errors.ts` / `mcp-db-target.ts` / `mcp-host-shell.ts` / `mcp-test-{output,run}.ts` | `x mcp serve`: 19 tools, two transports; `tests.run`/`verify.run` ARE `x test`/`x verify`, `ULTIMATE_ENV` unset in children (`mcp-host.parity.test.ts`) † |
177
+ | `cmd-mcp.ts` / `mcp-host.ts` / `mcp-errors.ts` / `mcp-db-target.ts` / `mcp-host-shell.ts` / `mcp-test-{output,run}.ts` | `x mcp serve`: 23 tools, two transports, stdout only JSON-RPC under stdio (`cmd-mcp-stdio.test.ts`); `tests.run`/`verify.run` ARE `x test`/`x verify`, `ULTIMATE_ENV` unset in children (`mcp-host.parity.test.ts`) † |
178
178
  | `cmd-shot*.ts` / `cdp-shot-*.ts` / `browser-launcher*.ts` / `island-*` | `x shot` over raw CDP; `verdict.json` names its own blind spots. Not a gate step |
179
179
  | `shot-route.ts` / `shot-run.ts` / `shot-gpu.ts` | `x shot`'s route argument (`readRoute`, `shotSlug`); one capture (`runShot`); the page's `navigator.gpu` adapter (`verdict.gpu`, never gating). `cmd-shot.ts` re-exports the first two |
180
180
  | `cmd-pr.ts` / `cmd-ci.ts` / `ci-runs.ts` / `ci-tested.ts` | GitHub through `gh`, schema-parsed; not gate steps † |
package/README.md CHANGED
@@ -165,9 +165,10 @@ execute and carries its `why`; `x doctor` prints them. A `--shard` slice hands i
165
165
 
166
166
  A step has a **deadline** — 8 minutes for the six suites, 5 for every other step,
167
167
  `"stepTimeoutMs": { "<step>": ms }` in `x.verify.json` to change one. Past it the step fails by
168
- name with `X_VERIFY_STEP_TIMEOUT` and every process it started is killed. Under `--json` each
169
- finished step is one line on stderr (`{"step":"lint","ok":true,"ms":21987}`); stdout stays the
170
- single document.
168
+ name with `X_VERIFY_STEP_TIMEOUT` and every process it started is killed. Each finished step is
169
+ one line on stderr — under `--json` a JSON one (`{"step":"lint","ok":true,"ms":21987}`), otherwise
170
+ `✓ lint 22.0s`, and a red step names its narrowest re-run (`✗ unit 3.1s → x test unit --filter …
171
+ --json`, `As of 31.22`); stdout stays the single document.
171
172
 
172
173
  An app extends the gate with its own conventions, never with its own step: a file in `guards/`
173
174
  exports a `guard` whose `check(root, sources)` returns `Finding[]`, and the `boundaries` step runs
@@ -175,9 +176,13 @@ every one of them. `sources` is the run's ONE read of the app (`GuardSources`):
175
176
  walked and read once however many guards ask, and `compiled(path)` is a stylesheet as the build
176
177
  compiles it. Nothing registers a guard — the directory is the registration — and what a guard returns
177
178
  is held to the same error contract shipped source is (`X_GUARD_INVALID`, `X_GUARD_FAILED`,
178
- `X_GUARD_FINDING_INVALID`). `x g guard <name>` scaffolds one with its test — the shipped guard of
179
- that name where there is one (`x new` writes all twenty), the blank template otherwise — and
180
- `x doctor` lists the shipped ones an app does not hold.
179
+ `X_GUARD_FINDING_INVALID`). A guard that exports `severity: 'warning'` is **report-only** (`As of
180
+ 31.22`): its findings ride the step as `warnings` — in `--json` and on the step line, never a
181
+ failure — so a rule ships to every app before the apps are clean of it; a finding that breaks the
182
+ contract fails either way. `repo-await-in-loop` and `repo-unbounded` ship that way. `x g guard
183
+ <name>` scaffolds one with its test — the shipped guard of that name where there is one (`x new`
184
+ writes all twenty-five), the blank template otherwise — and `x doctor` warns of each shipped one an
185
+ app does not hold (`X_SHIPPED_GUARD_MISSING`, beside the verdict, never in it).
181
186
 
182
187
  ## Layout
183
188
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/cli",
3
- "version": "31.20.0",
3
+ "version": "31.22.0",
4
4
  "description": "The `x` binary: new, dev, build, verify, generate, db, mcp, doctor, deploy",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -53,34 +53,34 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@babel/core": "^8.0.9",
56
- "@ultimat3/action": "31.20.0",
57
- "@ultimat3/admin": "31.20.0",
58
- "@ultimat3/ai": "31.20.0",
59
- "@ultimat3/auth": "31.20.0",
60
- "@ultimat3/cache": "31.20.0",
61
- "@ultimat3/core": "31.20.0",
62
- "@ultimat3/db": "31.20.0",
63
- "@ultimat3/entity": "31.20.0",
64
- "@ultimat3/flags": "31.20.0",
65
- "@ultimat3/http": "31.20.0",
66
- "@ultimat3/i18n": "31.20.0",
67
- "@ultimat3/jobs": "31.20.0",
68
- "@ultimat3/mail": "31.20.0",
69
- "@ultimat3/manifest": "31.20.0",
70
- "@ultimat3/mcp": "31.20.0",
71
- "@ultimat3/money": "31.20.0",
72
- "@ultimat3/notify": "31.20.0",
73
- "@ultimat3/policy": "31.20.0",
74
- "@ultimat3/pwa": "31.20.0",
75
- "@ultimat3/query": "31.20.0",
76
- "@ultimat3/realtime": "31.20.0",
77
- "@ultimat3/render": "31.20.0",
78
- "@ultimat3/schema": "31.20.0",
79
- "@ultimat3/scraping": "31.20.0",
80
- "@ultimat3/seo": "31.20.0",
81
- "@ultimat3/storage": "31.20.0",
82
- "@ultimat3/testing": "31.20.0",
83
- "@ultimat3/time": "31.20.0",
56
+ "@ultimat3/action": "31.22.0",
57
+ "@ultimat3/admin": "31.22.0",
58
+ "@ultimat3/ai": "31.22.0",
59
+ "@ultimat3/auth": "31.22.0",
60
+ "@ultimat3/cache": "31.22.0",
61
+ "@ultimat3/core": "31.22.0",
62
+ "@ultimat3/db": "31.22.0",
63
+ "@ultimat3/entity": "31.22.0",
64
+ "@ultimat3/flags": "31.22.0",
65
+ "@ultimat3/http": "31.22.0",
66
+ "@ultimat3/i18n": "31.22.0",
67
+ "@ultimat3/jobs": "31.22.0",
68
+ "@ultimat3/mail": "31.22.0",
69
+ "@ultimat3/manifest": "31.22.0",
70
+ "@ultimat3/mcp": "31.22.0",
71
+ "@ultimat3/money": "31.22.0",
72
+ "@ultimat3/notify": "31.22.0",
73
+ "@ultimat3/policy": "31.22.0",
74
+ "@ultimat3/pwa": "31.22.0",
75
+ "@ultimat3/query": "31.22.0",
76
+ "@ultimat3/realtime": "31.22.0",
77
+ "@ultimat3/render": "31.22.0",
78
+ "@ultimat3/schema": "31.22.0",
79
+ "@ultimat3/scraping": "31.22.0",
80
+ "@ultimat3/seo": "31.22.0",
81
+ "@ultimat3/storage": "31.22.0",
82
+ "@ultimat3/testing": "31.22.0",
83
+ "@ultimat3/time": "31.22.0",
84
84
  "babel-preset-solid": "^1.9.16"
85
85
  }
86
86
  }
package/src/cmd-db.ts CHANGED
@@ -27,12 +27,8 @@ import { stepFinding } from './db-finding';
27
27
  import { generateAppMigration, unrenderedJson, unrenderedLines } from './db-generate';
28
28
  import { liveObjectDrift } from './db-object-drift';
29
29
  import { layTemplate } from './db-reset-template';
30
- import {
31
- afterWrittenMigration,
32
- refreshSchemaDump,
33
- type SchemaDumpRefresh,
34
- schemaDumpJson,
35
- } from './db-schema-refresh';
30
+ import { schemaDumpLines } from './db-schema-dump';
31
+ import { afterWrittenMigration, refreshSchemaDump, schemaDumpJson } from './db-schema-refresh';
36
32
  import type { SeedPassRow } from './db-seed';
37
33
  import {
38
34
  discoverSeeds,
@@ -149,7 +145,7 @@ async function runGen(ctx: CommandContext, root: string, name: string): Promise<
149
145
  : msg('cli.db.gen.unchanged'),
150
146
  findings: [...generated.findings, ...dumpFindings],
151
147
  // `files` is what this command WROTE, so the empty array here was a false claim.
152
- lines: [...generated.files.map((file) => ` ${file}`), ...dumpLines(dump), ...lost],
148
+ lines: [...generated.files.map((file) => ` ${file}`), ...schemaDumpLines(dump), ...lost],
153
149
  data: {
154
150
  outcome: generated.outcome,
155
151
  migration: null,
@@ -169,7 +165,7 @@ async function runGen(ctx: CommandContext, root: string, name: string): Promise<
169
165
  : msg('cli.db.gen.writtenDumpFailed', { id: migration.id }),
170
166
  // Exit 1 with a migration on disk: the finding has to say so, or the next move is a duplicate.
171
167
  findings: dumpFindings.map((finding) => afterWrittenMigration(finding, migration.id)),
172
- lines: [...generated.files.map((file) => ` ${file}`), ...dumpLines(dump), ...lost],
168
+ lines: [...generated.files.map((file) => ` ${file}`), ...schemaDumpLines(dump), ...lost],
173
169
  data: {
174
170
  outcome: generated.outcome,
175
171
  migration: migration.id,
@@ -184,15 +180,6 @@ async function runGen(ctx: CommandContext, root: string, name: string): Promise<
184
180
  };
185
181
  }
186
182
 
187
- /**
188
- * What the dump refresh did, one path per line — the same list `data.schemaDump` carries, so the
189
- * human render and `--json` report one fact. A refresh that changed nothing prints nothing.
190
- */
191
- const dumpLines = (dump: SchemaDumpRefresh): readonly string[] => [
192
- ...dump.written.map((file) => ` ${file}`),
193
- ...dump.removed.map((file) => ` - ${file}`),
194
- ];
195
-
196
183
  /**
197
184
  * The post-migrate report, rendered. Through `driftError` rather than a second literal: the
198
185
  * three-line `X_DB_DRIFT` output is pinned by the framework contract, and this command must not be
@@ -237,7 +224,7 @@ async function runMigrate(
237
224
  command: 'db',
238
225
  summary,
239
226
  findings,
240
- lines: dumpLines(dump),
227
+ lines: schemaDumpLines(dump),
241
228
  data: {
242
229
  applied: report.applied.map((entry) => entry.id),
243
230
  skipped: report.skipped.length,
package/src/cmd-doctor.ts CHANGED
@@ -11,7 +11,7 @@ import { authStorageFindings } from './doctor-auth';
11
11
  import { chartAlertsProbe, NOTHING_MISSING, withChartAlertsListing } from './doctor-chart-alerts';
12
12
  import { coverageExcludesProbe, withCoverageExcludes } from './doctor-coverage';
13
13
  import { embeddedDatabaseFinding } from './doctor-database';
14
- import { shippedGuardsProbe, withGuardListing } from './doctor-guards';
14
+ import { missingGuardWarnings, shippedGuardsProbe, withGuardListing } from './doctor-guards';
15
15
  import { offlineFallbackFinding } from './doctor-offline';
16
16
  import { NO_POOLER_FACT, poolerFindings, withPoolerReport } from './doctor-pooler';
17
17
  import { doctorPort, portFindings } from './doctor-port';
@@ -143,6 +143,7 @@ export async function reportDoctor(probe: DoctorProbe): Promise<CommandResult> {
143
143
  // Asked once: `runDoctor` reads the verdict and the report beside it reads the numbers.
144
144
  const pooler = probe.root === undefined ? NO_POOLER_FACT : await probe.pooler();
145
145
  const findings = await runDoctor({ ...probe, pooler: async () => pooler });
146
+ const guardEntries = probe.root === undefined ? [] : await shippedGuardsProbe(probe.root);
146
147
  const listed = withGuardListing(
147
148
  {
148
149
  ok: findings.length === 0,
@@ -155,7 +156,7 @@ export async function reportDoctor(probe: DoctorProbe): Promise<CommandResult> {
155
156
  data: { count: findings.length, codes: findings.map((entry) => entry.code) },
156
157
  },
157
158
  // A listing beside the verdict, never part of it (`doctor-guards.ts` says why).
158
- probe.root === undefined ? [] : await shippedGuardsProbe(probe.root),
159
+ guardEntries,
159
160
  );
160
161
  // The second listing: what the coverage floor does not see (`doctor-coverage.ts`).
161
162
  const covered = withCoverageExcludes(
@@ -176,7 +177,11 @@ export async function reportDoctor(probe: DoctorProbe): Promise<CommandResult> {
176
177
  pooler,
177
178
  );
178
179
  // Last, and beside the verdict on `main`: the 31.16.0 checks (`doctor-warnings.ts`).
179
- return withDoctorWarnings(reminded, await doctorWarnings(probe));
180
+ // A missing shipped guard among them (`X_SHIPPED_GUARD_MISSING`): a warning, so exit stays.
181
+ return withDoctorWarnings(reminded, [
182
+ ...(await doctorWarnings(probe)),
183
+ ...missingGuardWarnings(guardEntries),
184
+ ]);
180
185
  }
181
186
 
182
187
  export const doctorCommand: CliCommand = {
package/src/cmd-mcp.ts CHANGED
@@ -1,4 +1,4 @@
1
- // `x mcp serve` — the framework's dev MCP server over stdio or HTTP. The 18 tools, the JSON-RPC
1
+ // `x mcp serve` — the framework's dev MCP server over stdio or HTTP. The tools, the JSON-RPC
2
2
  // dispatch, both transports and the structural SQL refusals all come from `@ultimat3/mcp`; the CLI
3
3
  // supplies only the app, the caller and the socket. A tool answered here would be a second answer
4
4
  // to a question the framework already answers.
@@ -7,6 +7,7 @@ import {
7
7
  markListening,
8
8
  nanoid,
9
9
  renderFixShellArg,
10
+ setLogStream,
10
11
  timingSafeEqual,
11
12
  UltimateError,
12
13
  } from '@ultimat3/core';
@@ -236,6 +237,10 @@ export const mcpCommand: CliCommand = {
236
237
  });
237
238
  }
238
239
  const port = readPort(ctx);
240
+ // BEFORE the host imports an app module: under stdio fd 1 is the wire, and a module that logs
241
+ // as it loads (the reference app's demo-viewer warning) wrote its line ahead of `initialize`'s
242
+ // reply. `dispatch` sends logs to stderr for `--json` only; a session is the other case.
243
+ if (transport === 'stdio' && ctx.args.subcommand !== 'tools') setLogStream('stderr');
239
244
  const host = await createDevMcpServer({ root, env: ctx.env, runner: ctx.runner });
240
245
  if (ctx.args.subcommand === 'tools') return catalog(host);
241
246
  if (transport !== 'http') return serveOverStdio(host);
package/src/cmd-verify.ts CHANGED
@@ -64,21 +64,25 @@ export const verifyCommand: CliCommand = {
64
64
  // Either render prints its verdict only when the run ends; the progress on stderr — a line per
65
65
  // finished step, a heartbeat while one runs — is what a cancelled job's log ends on (#589) and
66
66
  // what keeps a silence-killing harness from killing a healthy gate. stdout stays the document.
67
- const result = await withVerifyProgress(writeErrorLine, (progress) =>
68
- runVerify(VERIFY_STEPS, {
69
- root,
70
- runner: ctx.runner,
71
- env: ctx.env,
72
- pace: measurePace(),
73
- ...(workers === undefined ? {} : { workers }),
74
- ...(only === undefined ? {} : { only }),
75
- ...(shard === undefined ? {} : { shard }),
76
- ...(isolate === undefined ? {} : { isolate }),
77
- ...(changed?.tests === undefined
78
- ? {}
79
- : { tests: { scope: changed.tests.scope, whole: changed.tests.whole } }),
80
- ...progress,
81
- }),
67
+ const result = await withVerifyProgress(
68
+ writeErrorLine,
69
+ (progress) =>
70
+ runVerify(VERIFY_STEPS, {
71
+ root,
72
+ runner: ctx.runner,
73
+ env: ctx.env,
74
+ pace: measurePace(),
75
+ ...(workers === undefined ? {} : { workers }),
76
+ ...(only === undefined ? {} : { only }),
77
+ ...(shard === undefined ? {} : { shard }),
78
+ ...(isolate === undefined ? {} : { isolate }),
79
+ ...(changed?.tests === undefined
80
+ ? {}
81
+ : { tests: { scope: changed.tests.scope, whole: changed.tests.whole } }),
82
+ ...progress,
83
+ }),
84
+ // A line per step a person reads, JSON only for the `--json` reader that parses stderr.
85
+ { render: ctx.args.json ? 'json' : 'human' },
82
86
  );
83
87
  const sharded = shard === undefined ? result : withShardData(result, shard);
84
88
  return changed === undefined ? sharded : withChangedData(sharded, changed);
@@ -148,3 +148,23 @@ export async function writeSchemaDump(
148
148
  }
149
149
  return { written, removed, total: files.length };
150
150
  }
151
+
152
+ /** How many changed files a person's report names one per line before it says a count instead. */
153
+ const DUMP_LINES_SHOWN = 5;
154
+
155
+ /**
156
+ * What a refresh did, for a person: each file when there are a few, `packages/db/schema/ +75` when
157
+ * a whole dump was written — the first `bun run setup` listed 75 paths mid-report. `--json`
158
+ * (`data.schemaDump`) carries every path either way, so the count hides nothing from a reader.
159
+ */
160
+ export function schemaDumpLines(
161
+ write: Pick<SchemaDumpWrite, 'written' | 'removed'>,
162
+ ): readonly string[] {
163
+ const { written, removed } = write;
164
+ if (written.length + removed.length <= DUMP_LINES_SHOWN) {
165
+ return [...written.map((file) => ` ${file}`), ...removed.map((file) => ` - ${file}`)];
166
+ }
167
+ return [
168
+ ` ${SCHEMA_DUMP_DIR}/ +${written.length}${removed.length > 0 ? ` -${removed.length}` : ''}`,
169
+ ];
170
+ }
package/src/dev-lock.ts CHANGED
@@ -233,6 +233,20 @@ const stagingPath = (path: string): string =>
233
233
 
234
234
  const lockText = (lock: DevLock): string => `${JSON.stringify(lock, null, 2)}\n`;
235
235
 
236
+ /**
237
+ * The claim's two filesystem writes. A seam, so a test can see what a rival would read between
238
+ * them without replacing `node:fs` for every module in its process (`mock.module` never undoes).
239
+ */
240
+ export interface ClaimFiles {
241
+ readonly write: (path: string, text: string) => void;
242
+ readonly link: (existing: string, path: string) => void;
243
+ }
244
+
245
+ const NODE_CLAIM_FILES: ClaimFiles = {
246
+ write: (path, text) => writeFileSync(path, text),
247
+ link: (existing, path) => linkSync(existing, path),
248
+ };
249
+
236
250
  /**
237
251
  * Take the lock, or answer `false` because someone else holds it.
238
252
  *
@@ -246,15 +260,20 @@ const lockText = (lock: DevLock): string => `${JSON.stringify(lock, null, 2)}\n`
246
260
  * `.x/` this user may not write, a filesystem without hard links — is `X_DEV_STATE_UNWRITABLE`
247
261
  * naming the directory and the errno, the original kept as its `sourceError`.
248
262
  */
249
- function claimExclusive(stateDir: string, path: string, lock: DevLock): boolean {
263
+ function claimExclusive(
264
+ stateDir: string,
265
+ path: string,
266
+ lock: DevLock,
267
+ files: ClaimFiles = NODE_CLAIM_FILES,
268
+ ): boolean {
250
269
  const staged = stagingPath(path);
251
270
  try {
252
- writeFileSync(staged, lockText(lock));
271
+ files.write(staged, lockText(lock));
253
272
  } catch (error) {
254
273
  throw new DevStateUnwritableError({ stateDir, error });
255
274
  }
256
275
  try {
257
- linkSync(staged, path);
276
+ files.link(staged, path);
258
277
  return true;
259
278
  } catch (error) {
260
279
  // Same rule as `isProcessAlive` above: read the field, never cast and dereference.
@@ -299,6 +318,8 @@ export interface PreflightInput {
299
318
  readonly portBound?: (port: number, hostname: string) => boolean;
300
319
  readonly alive?: (pid: number) => boolean;
301
320
  readonly holder?: (port: number) => Promise<PortHolder>;
321
+ /** Injected by the test; `node:fs` in production. */
322
+ readonly files?: ClaimFiles;
302
323
  }
303
324
 
304
325
  export interface PreflightResult {
@@ -331,7 +352,7 @@ async function claimOrClearStale(
331
352
  let clearedStale = false;
332
353
  let held: DevLock | null = null;
333
354
  for (let round = 0; round < CLAIM_ROUNDS; round += 1) {
334
- if (claimExclusive(input.stateDir, path, mine)) return clearedStale;
355
+ if (claimExclusive(input.stateDir, path, mine, input.files)) return clearedStale;
335
356
  const raw = await readRaw(path);
336
357
  const now = raw === null ? null : parseLock(raw);
337
358
  // `held` keeps the last identity read: a half-written file parses as `null` for microseconds.
@@ -350,7 +371,7 @@ async function claimOrClearStale(
350
371
  const outcome = stealStale({
351
372
  path,
352
373
  judged: raw,
353
- claim: (guard) => claimExclusive(input.stateDir, guard, mine),
374
+ claim: (guard) => claimExclusive(input.stateDir, guard, mine, input.files),
354
375
  alive: isProcessAlive,
355
376
  });
356
377
  if (outcome === 'busy') await Bun.sleep(STEAL_BUSY_MS);
@@ -1,13 +1,14 @@
1
1
  // `x doctor`'s guard listing: the shipped guards this app's `guards/` does not hold, and the ones
2
- // it holds in a form that is not the current template — each with the command that writes it. A
3
- // LISTING, never a finding: every shipped guard is the app's copy ("delete this file to drop the
4
- // rule"), so a missing or edited one may be a decision the framework must not overrule.
2
+ // it holds in a form that is not the current template — each with the command that writes it.
3
+ // Never in the VERDICT: every shipped guard is the app's copy ("delete this file to drop the
4
+ // rule"), so a missing one is a warning beside it (`data.warnings`) and an edited one a listing.
5
5
 
6
6
  // why: Bun exposes no path-join primitive; Bun.file takes one already joined.
7
7
  import { join } from 'node:path';
8
+ import { ERROR_DOCS_URL } from '@ultimat3/core';
8
9
  import { GUARD_DIR, guardPaths } from './guards';
9
10
  import { msg } from './messages';
10
- import type { CommandResult, JsonValue } from './output';
11
+ import type { CommandResult, Finding, JsonValue } from './output';
11
12
  import { SHIPPED_GUARD_NAMES, shippedGuardSource } from './templates/scaffold-guards';
12
13
 
13
14
  export interface MissingGuard {
@@ -25,6 +26,25 @@ export function missingShippedGuards(present: readonly string[]): readonly Missi
25
26
  }));
26
27
  }
27
28
 
29
+ export const MISSING_GUARD = 'X_SHIPPED_GUARD_MISSING';
30
+
31
+ /**
32
+ * A missing shipped guard as a WARNING, one per guard: the gate does not hold this app to that
33
+ * rule, and "no findings — environment is shippable" alone said nothing of it. A warning and not a
34
+ * finding, so on `main` an adopter's doctor keeps its exit status (`doctor-warnings.ts`).
35
+ */
36
+ export function missingGuardWarnings(entries: readonly GuardListingEntry[]): readonly Finding[] {
37
+ return entries
38
+ .filter((entry): entry is MissingGuard => 'add' in entry)
39
+ .map(({ name, add }) => ({
40
+ code: MISSING_GUARD,
41
+ cause: `${GUARD_DIR}/${name}.ts is not in this app, so x verify does not hold it to the shipped ${name} rule`,
42
+ fix: `${add} && x verify --only boundaries --json`,
43
+ docs: ERROR_DOCS_URL,
44
+ at: `${GUARD_DIR}/${name}.ts`,
45
+ }));
46
+ }
47
+
28
48
  export interface DifferingGuard {
29
49
  readonly name: string;
30
50
  /** Rewrites the guard and its test from the current template. Review the diff, then keep it. */
@@ -73,8 +93,9 @@ export async function shippedGuardsProbe(root: string): Promise<readonly GuardLi
73
93
  }
74
94
 
75
95
  /**
76
- * The listing, on a result `x doctor` already decided: `data.guards.missing` for a machine, one
77
- * line per command for a person. `ok`, the summary and the findings are returned as they came.
96
+ * The listing, on a result `x doctor` already decided: `data.guards` for a machine; for a person,
97
+ * a line per differing guard — a missing one's command is its warning's line, never printed twice.
98
+ * `ok`, the summary and the findings are returned as they came.
78
99
  */
79
100
  export function withGuardListing(
80
101
  result: CommandResult,
@@ -84,12 +105,6 @@ export function withGuardListing(
84
105
  const missing = entries.filter((entry): entry is MissingGuard => 'add' in entry);
85
106
  const differs = entries.filter((entry): entry is DifferingGuard => 'refresh' in entry);
86
107
  const lines = [
87
- ...(missing.length === 0
88
- ? []
89
- : [
90
- msg('cli.doctor.guards', { count: missing.length }),
91
- ...missing.map(({ add }) => ` ${add}`),
92
- ]),
93
108
  ...(differs.length === 0
94
109
  ? []
95
110
  : [
@@ -1,6 +1,7 @@
1
1
  // Single responsibility: whether the `drift` step has a SQL schema to judge. Migrations, drift and
2
2
  // `x db` describe Postgres only; an app whose rows live in a `defineDriver` store owns its schema,
3
- // and the step skips it with the reason printed rather than demanding `x db gen "initial"`.
3
+ // and the step skips it with the reason printed rather than demanding `x db gen "initial"`. Also
4
+ // where the step's advice turns into a verdict: warnings on `main`, findings on `next`.
4
5
 
5
6
  import type { DriverStoreKind } from '@ultimat3/entity/adapter';
6
7
  import { driverStores } from '@ultimat3/entity/adapter';
@@ -33,11 +34,28 @@ export const nonSqlDriftSkip = (
33
34
  return msg('cli.verify.driftNonSql', { stores: custom.join(', ') });
34
35
  };
35
36
 
37
+ /**
38
+ * The `next` switch. `false` on `main`: an index nothing declares (`X_DB_INDEX_UNDECLARED`) rides
39
+ * in `warnings`, since refusing it reddens an app that passed yesterday (X_BREAKING_ON_MAIN).
40
+ * `next` sets it `true`, and the same facts are the step's findings.
41
+ */
42
+ export const REFUSE_UNDECLARED_INDEX = false;
43
+
44
+ /** One fact, in both shapes: the findings `next` refuses on, the lines `main` prints. */
45
+ export interface DriftAdvice {
46
+ readonly findings: () => Promise<readonly Finding[]>;
47
+ readonly warnings: () => Promise<readonly string[]>;
48
+ }
49
+
36
50
  export interface DriftRails {
37
51
  /** The migration and schema rails — the ones a store owning its own schema has nothing for. */
38
52
  readonly schema: () => Promise<readonly Finding[]>;
39
53
  /** The generated client against its stamp: a fact about the app's API, whatever stores rows. */
40
54
  readonly client: () => Promise<readonly Finding[]>;
55
+ /** A schema rail's advice: skipped with the schema rails, a verdict only under `refuseAdvice`. */
56
+ readonly advice?: DriftAdvice;
57
+ /** Defaults to `REFUSE_UNDECLARED_INDEX`; a test states the other branch. */
58
+ readonly refuseAdvice?: boolean;
41
59
  readonly stores?: Stores;
42
60
  }
43
61
 
@@ -47,9 +65,17 @@ export interface DriftRails {
47
65
  */
48
66
  export const driftOutcome = async (root: string, rails: DriftRails): Promise<StepOutcome> => {
49
67
  const skipped = nonSqlDriftSkip(root, rails.stores);
68
+ const advice = skipped === undefined ? rails.advice : undefined;
69
+ const refuse = rails.refuseAdvice ?? REFUSE_UNDECLARED_INDEX;
50
70
  const findings = [
51
71
  ...(skipped === undefined ? await rails.schema() : []),
72
+ ...(advice !== undefined && refuse ? await advice.findings() : []),
52
73
  ...(await rails.client()),
53
74
  ];
54
- return { ...fromFindings(findings), ...(skipped === undefined ? {} : { output: skipped }) };
75
+ const warnings = advice !== undefined && !refuse ? await advice.warnings() : [];
76
+ return {
77
+ ...fromFindings(findings),
78
+ ...(skipped === undefined ? {} : { output: skipped }),
79
+ ...(warnings.length === 0 ? {} : { warnings }),
80
+ };
55
81
  };
@@ -1,15 +1,17 @@
1
- // The X_* codes of how an app is HELD — `x doctor`'s floor, pin, env-name and row-security checks
2
- // and the `exercise` floor in `x.verify.json` — split out of `error-codes.ts` at its 500-line
3
- // ceiling, as `error-codes-shot.ts` was. `error-codes.ts` folds these into the CLI's one owned union
4
- // and registers them in its one call; nothing else imports this file.
1
+ // The X_* codes of how an app is HELD — `x doctor`'s floor, pin, env-name, row-security and
2
+ // shipped-guard checks, the `exercise` floor and the `drift` step's undeclared index — split out of
3
+ // `error-codes.ts` at its 500-line ceiling. `error-codes.ts` folds these into the CLI's one owned
4
+ // union and registers them in its one call; nothing else imports this file.
5
5
 
6
- /** Codes `x doctor` and the `exercise` floor declare and own. */
6
+ /** Codes `x doctor`, the `exercise` floor and the `drift` step's index advice declare and own. */
7
7
  export const CLI_DOCTOR_ERROR_CODES = [
8
8
  'X_EXERCISE_UNPROVEN_ABOVE_FLOOR',
9
9
  'X_ENV_NAME_RESERVED',
10
10
  'X_FRAMEWORK_PIN_RANGE',
11
11
  'X_VERIFY_STEP_UNFLOORED',
12
12
  'X_DB_ROW_SECURITY_OFF',
13
+ 'X_DB_INDEX_UNDECLARED',
14
+ 'X_SHIPPED_GUARD_MISSING',
13
15
  ] as const;
14
16
 
15
17
  export type CliDoctorErrorCode = (typeof CLI_DOCTOR_ERROR_CODES)[number];
@@ -21,4 +23,6 @@ export const CLI_DOCTOR_ERROR_TITLES: Readonly<Record<CliDoctorErrorCode, string
21
23
  X_FRAMEWORK_PIN_RANGE: 'An @ultimat3/* dependency is pinned as a range',
22
24
  X_VERIFY_STEP_UNFLOORED: 'A gate step applies to this app but x.verify.json does not floor it',
23
25
  X_DB_ROW_SECURITY_OFF: 'Raw sql reaches tenant tables while database.rowSecurity is off',
26
+ X_DB_INDEX_UNDECLARED: 'Schema dump holds an index nothing declares',
27
+ X_SHIPPED_GUARD_MISSING: "A guard x new ships is not in this app's guards/",
24
28
  };