@ultimat3/cli 31.15.0 → 31.17.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 (86) hide show
  1. package/README.md +7 -1
  2. package/package.json +29 -29
  3. package/src/cache-graph.ts +67 -0
  4. package/src/cmd-cache-spec.ts +25 -0
  5. package/src/cmd-cache.ts +187 -0
  6. package/src/cmd-config-spec.ts +23 -0
  7. package/src/cmd-config.ts +61 -0
  8. package/src/cmd-doctor.ts +47 -37
  9. package/src/cmd-exercise.ts +42 -5
  10. package/src/cmd-explain-spec.ts +24 -0
  11. package/src/cmd-explain.ts +201 -0
  12. package/src/cmd-logs-spec.ts +34 -0
  13. package/src/cmd-logs.ts +80 -0
  14. package/src/cmd-planned.ts +15 -29
  15. package/src/cmd-token-spec.ts +54 -0
  16. package/src/cmd-token.ts +173 -0
  17. package/src/cmd-upgrade.ts +19 -2
  18. package/src/cmd-verify-spec.ts +13 -3
  19. package/src/cmd-verify.ts +2 -0
  20. package/src/config-redact.ts +39 -0
  21. package/src/coverage-floor.ts +2 -2
  22. package/src/dev-boot-data-dir.ts +69 -0
  23. package/src/dev-boot.ts +26 -13
  24. package/src/doctor-env-reserved.ts +111 -0
  25. package/src/doctor-floor.ts +62 -0
  26. package/src/doctor-pins.ts +101 -0
  27. package/src/doctor-probe.ts +21 -1
  28. package/src/doctor-row-security.ts +119 -4
  29. package/src/doctor-warnings.ts +55 -0
  30. package/src/error-codes-doctor.ts +24 -0
  31. package/src/error-codes-tooling.ts +6 -4
  32. package/src/error-codes.ts +7 -0
  33. package/src/errors.ts +8 -2
  34. package/src/exercise-entry-edit.ts +5 -1
  35. package/src/exercise-floor-report.ts +138 -0
  36. package/src/exercise-floor-verdict.ts +98 -0
  37. package/src/exercise-floor.ts +158 -0
  38. package/src/exercise-routes.ts +59 -0
  39. package/src/explain-capture.ts +38 -0
  40. package/src/generate-exercise.ts +2 -2
  41. package/src/generate-factories.ts +133 -0
  42. package/src/generate-files.ts +11 -0
  43. package/src/generate-kinds.ts +13 -0
  44. package/src/mcp-db-target.ts +4 -3
  45. package/src/mcp-errors.ts +14 -0
  46. package/src/messages-gate.ts +2 -0
  47. package/src/messages-ops.ts +32 -0
  48. package/src/messages-upgrade.ts +14 -0
  49. package/src/messages.ts +5 -0
  50. package/src/otlp-export.ts +16 -2
  51. package/src/registry.ts +10 -0
  52. package/src/role-start.ts +11 -5
  53. package/src/runtime-services.ts +35 -19
  54. package/src/serve-boot-phases.ts +30 -0
  55. package/src/serve-boot-warnings.ts +62 -0
  56. package/src/serve-boot.ts +30 -11
  57. package/src/templates/generate-cron-job.ts +90 -0
  58. package/src/templates/generate-purge.ts +93 -0
  59. package/src/templates/generate-webhook-receiver.ts +274 -0
  60. package/src/templates/github/ci.yml.ts +101 -36
  61. package/src/templates/guard-repo-raw-sql-test.ts +174 -0
  62. package/src/templates/guard-repo-raw-sql.ts +115 -145
  63. package/src/templates/guard-unbounded-fanout.ts +170 -0
  64. package/src/templates/scaffold-claude-commands.ts +3 -2
  65. package/src/templates/scaffold-docs.ts +3 -2
  66. package/src/templates/scaffold-guards.ts +3 -0
  67. package/src/templates/scaffold-verify-floor.ts +4 -0
  68. package/src/test-dotenv.ts +15 -2
  69. package/src/upgrade-coverage.ts +109 -0
  70. package/src/upgrade-document.ts +18 -0
  71. package/src/upgrade-exercise-floor.ts +53 -0
  72. package/src/upgrade-gate.ts +84 -29
  73. package/src/upgrade-guards.ts +159 -0
  74. package/src/upgrade-report.ts +33 -1
  75. package/src/verify-checks.ts +3 -1
  76. package/src/verify-floor.ts +13 -0
  77. package/src/verify-plan.ts +127 -0
  78. package/wiki/CI-Parallel-Gate.md +38 -1
  79. package/wiki/CLI-Reference.md +115 -14
  80. package/wiki/Caching-And-Invalidation.md +10 -10
  81. package/wiki/Configuration.md +20 -2
  82. package/wiki/Known-Gaps.md +1 -1
  83. package/wiki/MCP-And-AI.md +1 -1
  84. package/wiki/Testing.md +96 -2
  85. package/wiki/Troubleshooting.md +3 -2
  86. package/wiki/Upgrading.md +9 -0
package/README.md CHANGED
@@ -21,7 +21,8 @@ Commands and the `x verify` step count, `As of 2026-08`:
21
21
  | `x build --target docker\|binary\|static` | one artifact | `ROLE` selects behaviour at start |
22
22
  | `x build --target prebuilt` | the store a container boots from: island chunks, compiled stylesheets | a `RUN` line in the image build, never run by hand |
23
23
  | `x verify` | **the gate** | 21 named steps, each with pass/fail + duration; `budgets` runs `x build --target static` first when its stats are missing or older than the source |
24
- | `x exercise [<name>] [--seed n]` | every action, query and job run once on generated rows, no test written | a scratch database; `.x/exercise.json`; an `unreached` primitive is `X_CONTRACT_EXERCISE_UNREACHED` with the override to paste into `apps/web/exercise.ts` — the gate's `exercise` step |
24
+ | `x verify plan [--parts n]` | the gate as CI parts | `data.matrix` is a GitHub `strategy.matrix` of `x verify --only … [--shard i/n]` parts; `x new`'s workflow reads it with `fromJSON`, and `x verify merge` folds the parts back |
25
+ | `x exercise [<name>] [--seed n]` | every action, query, job and route `load` run once on generated rows, no test written | a scratch database; `.x/exercise.json`; an `unreached` primitive is `X_CONTRACT_EXERCISE_UNREACHED` with the override to paste into `apps/web/exercise.ts` — the gate's `exercise` step. `x.verify.json` `exercise: { unprovenMax, statementsMax }` turns unproven proofs and over-ceiling calls red; absent, warning lines. Route loads land in `routes` beside `records`, their loops and seq scans as warning lines |
25
26
  | `x drill [<name>] [--list] [--budget-ms n]` | the app's roles as real processes on real services, each fault played through a proxy or a signal, judged on framework contracts only | a scratch database per drill; load = anonymous site pages plus every action an anonymous POST reaches (`data.skippedWrites` names the rest and why); `X_DRILL_FAILED` per property that did not hold, `X_DRILL_SERVICE_MISSING` before anything starts. Not a gate step — CI's `fault-drills` job runs three on `examples/dummy` |
26
27
  | `x g <primitive> <name>` | scaffolds a primitive **with a passing test** | never a TODO stub |
27
28
  | `x db gen\|migrate\|reset\|branch\|backfill` | everything DB | `branch` = copy-on-write clone + preview URL; `backfill` dry-runs unless `--write`. `x db studio` is **planned** — it parses, and exits `X_NOT_IMPLEMENTED` naming `/_x`'s db panel |
@@ -47,6 +48,11 @@ Commands and the `x verify` step count, `As of 2026-08`:
47
48
  | `x client vendor <name>` / `x client customer --out <dir>` | one OpenAPI compiler (`openapi-compile.ts`), two emitters: a vendor's document into `apps/web/clients/<name>/` (`outbound()` + `t`), or the app's published document into a client with no framework import | every generated file is stamped with its source and body hash; `drift` raises `X_CLIENT_STALE` / `X_CLIENT_EDITED` ([flags](../../wiki/CLI-Reference.md#x-client)) |
48
49
  | `x fix boundary <file>` | the minimal cut for a crossed surface boundary | prints the plan and the `git mv`; never rewrites a file |
49
50
  | `x ci [runs]` / `x ci tested` | CI triage through `gh`; `tested`: may this push reuse a green PR run of the same tree | `tested` exits 0 on every answer, `data.tested`; any doubt is `false`, a full run ([conditions](../../wiki/CLI-Reference.md#x-pr--x-ci)) |
51
+ | `x token create\|list\|revoke` | MCP / API tokens in `x_api_keys` | `create --scopes a,b` prints the plaintext once and stores its hash; `list --owner <id>` carries no secret; `grant` is planned ([details](../../wiki/CLI-Reference.md#x-token)) |
52
+ | `x config show [--section <key>]` | the resolved `app.config.ts` | defaults merged by `defineConfig`; credential keys, `secret()` values and URL passwords redacted |
53
+ | `x logs tail [--lines n] [--role <role>]` | the end of `.x/dev.log` or a role log | the `logs.tail` MCP tool's file and reader |
54
+ | `x cache graph\|bust <tag>\|clear` | the tag graph off the manifest; a bust through the app's own tiers and bus | an in-process bus is said in the summary; a failed tier is `X_CACHE_DRIVER_UNAVAILABLE`; `stats` is planned |
55
+ | `x explain <query> [--input <json>] [--org <id>]` | one query's statements, planned on the dev database | the `exercise` step's oracle (`sweepPlans`): an unindexed read is `X_QUERY_UNINDEXED` with the `indexes:` entry as its fix |
50
56
 
51
57
  Everything in [CLI reference](../../wiki/CLI-Reference.md)'s planned table is also in the registry
52
58
  and exits `X_NOT_IMPLEMENTED` with a `fix:` naming the closest shipped command — "not built yet"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/cli",
3
- "version": "31.15.0",
3
+ "version": "31.17.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.15.0",
57
- "@ultimat3/admin": "31.15.0",
58
- "@ultimat3/ai": "31.15.0",
59
- "@ultimat3/auth": "31.15.0",
60
- "@ultimat3/cache": "31.15.0",
61
- "@ultimat3/core": "31.15.0",
62
- "@ultimat3/db": "31.15.0",
63
- "@ultimat3/entity": "31.15.0",
64
- "@ultimat3/flags": "31.15.0",
65
- "@ultimat3/http": "31.15.0",
66
- "@ultimat3/i18n": "31.15.0",
67
- "@ultimat3/jobs": "31.15.0",
68
- "@ultimat3/mail": "31.15.0",
69
- "@ultimat3/manifest": "31.15.0",
70
- "@ultimat3/mcp": "31.15.0",
71
- "@ultimat3/money": "31.15.0",
72
- "@ultimat3/notify": "31.15.0",
73
- "@ultimat3/policy": "31.15.0",
74
- "@ultimat3/pwa": "31.15.0",
75
- "@ultimat3/query": "31.15.0",
76
- "@ultimat3/realtime": "31.15.0",
77
- "@ultimat3/render": "31.15.0",
78
- "@ultimat3/schema": "31.15.0",
79
- "@ultimat3/scraping": "31.15.0",
80
- "@ultimat3/seo": "31.15.0",
81
- "@ultimat3/storage": "31.15.0",
82
- "@ultimat3/testing": "31.15.0",
83
- "@ultimat3/time": "31.15.0",
56
+ "@ultimat3/action": "31.17.0",
57
+ "@ultimat3/admin": "31.17.0",
58
+ "@ultimat3/ai": "31.17.0",
59
+ "@ultimat3/auth": "31.17.0",
60
+ "@ultimat3/cache": "31.17.0",
61
+ "@ultimat3/core": "31.17.0",
62
+ "@ultimat3/db": "31.17.0",
63
+ "@ultimat3/entity": "31.17.0",
64
+ "@ultimat3/flags": "31.17.0",
65
+ "@ultimat3/http": "31.17.0",
66
+ "@ultimat3/i18n": "31.17.0",
67
+ "@ultimat3/jobs": "31.17.0",
68
+ "@ultimat3/mail": "31.17.0",
69
+ "@ultimat3/manifest": "31.17.0",
70
+ "@ultimat3/mcp": "31.17.0",
71
+ "@ultimat3/money": "31.17.0",
72
+ "@ultimat3/notify": "31.17.0",
73
+ "@ultimat3/policy": "31.17.0",
74
+ "@ultimat3/pwa": "31.17.0",
75
+ "@ultimat3/query": "31.17.0",
76
+ "@ultimat3/realtime": "31.17.0",
77
+ "@ultimat3/render": "31.17.0",
78
+ "@ultimat3/schema": "31.17.0",
79
+ "@ultimat3/scraping": "31.17.0",
80
+ "@ultimat3/seo": "31.17.0",
81
+ "@ultimat3/storage": "31.17.0",
82
+ "@ultimat3/testing": "31.17.0",
83
+ "@ultimat3/time": "31.17.0",
84
84
  "babel-preset-solid": "^1.9.16"
85
85
  }
86
86
  }
@@ -0,0 +1,67 @@
1
+ // The static tag graph `x cache graph` prints: per declared tag, the actions whose `invalidates`
2
+ // name it, the queries cached under it and the ISR routes revalidated by it — read off the app's
3
+ // manifest, the one description of what each primitive declared. Pure: manifest in, rows out.
4
+
5
+ import { parseTag } from '@ultimat3/cache';
6
+
7
+ /** What the graph reads of a `Manifest` — the whole manifest satisfies it, so does a fixture. */
8
+ export interface CacheGraphSource {
9
+ readonly actions: readonly {
10
+ readonly name: string;
11
+ readonly cacheInvalidates: readonly string[];
12
+ }[];
13
+ readonly queries: readonly { readonly name: string; readonly cacheTags: readonly string[] }[];
14
+ readonly routes: readonly { readonly url: string; readonly revalidateTags?: readonly string[] }[];
15
+ }
16
+
17
+ export interface CacheGraphRow {
18
+ /** The entity half of the tag: `post` for both `post` and `post:42`. */
19
+ readonly tag: string;
20
+ /** Actions whose `invalidates` names it — the writes that evict. */
21
+ readonly writers: readonly string[];
22
+ /** Queries cached under it — the reads that are evicted. */
23
+ readonly readers: readonly string[];
24
+ /** Routes whose `revalidate: { tags }` names it. */
25
+ readonly routes: readonly string[];
26
+ }
27
+
28
+ /** A tag read and never written: its entries are fresh only until their TTL. */
29
+ export const neverEvicted = (row: CacheGraphRow): boolean =>
30
+ row.writers.length === 0 && (row.readers.length > 0 || row.routes.length > 0);
31
+
32
+ interface Builder {
33
+ readonly writers: Set<string>;
34
+ readonly readers: Set<string>;
35
+ readonly routes: Set<string>;
36
+ }
37
+
38
+ export function cacheGraph(manifest: CacheGraphSource): readonly CacheGraphRow[] {
39
+ // A `Map`, never a record keyed by tag: a tag is the app's string, and `__proto__` is one.
40
+ const rows = new Map<string, Builder>();
41
+ const row = (wire: string): Builder => {
42
+ const tag = parseTag(wire).entity;
43
+ const found = rows.get(tag);
44
+ if (found !== undefined) return found;
45
+ const fresh: Builder = { writers: new Set(), readers: new Set(), routes: new Set() };
46
+ rows.set(tag, fresh);
47
+ return fresh;
48
+ };
49
+ for (const action of manifest.actions) {
50
+ for (const wire of action.cacheInvalidates) row(wire).writers.add(action.name);
51
+ }
52
+ for (const query of manifest.queries) {
53
+ for (const wire of query.cacheTags) row(wire).readers.add(query.name);
54
+ }
55
+ for (const route of manifest.routes) {
56
+ for (const wire of route.revalidateTags ?? []) row(wire).routes.add(route.url);
57
+ }
58
+ const sorted = (set: ReadonlySet<string>): readonly string[] => [...set].sort();
59
+ return [...rows.entries()]
60
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
61
+ .map(([tag, built]) => ({
62
+ tag,
63
+ writers: sorted(built.writers),
64
+ readers: sorted(built.readers),
65
+ routes: sorted(built.routes),
66
+ }));
67
+ }
@@ -0,0 +1,25 @@
1
+ // `x cache`'s declaration, apart from its body: the parser, `x help` and the `errors` step
2
+ // read it without loading `cmd-cache.ts`, which `registry.ts` imports only when the command runs.
3
+
4
+ import type { CommandSpec } from './parse';
5
+
6
+ /** `stats` stays listed and answers X_NOT_IMPLEMENTED (`PLANNED_SUBCOMMANDS`): hits live in a server. */
7
+ export const CACHE_SUBCOMMANDS = ['graph', 'bust', 'clear', 'stats'] as const;
8
+
9
+ export const cacheSpec: CommandSpec = {
10
+ name: 'cache',
11
+ summary: 'the tag graph (what each write evicts), and a bust of one tag or of every tag',
12
+ usage: 'x cache graph [--tag <tag>] · x cache bust <tag> · x cache clear [--json]',
13
+ requiresApp: true,
14
+ subcommands: [...CACHE_SUBCOMMANDS],
15
+ // Read-only, so the bare form may mean it; `bust` and `clear` are typed or not run.
16
+ defaultSubcommand: 'graph',
17
+ flags: [
18
+ {
19
+ name: 'tag',
20
+ type: 'string',
21
+ summary: 'graph: one tag only — the blast radius of a write that names it',
22
+ subcommands: ['graph'],
23
+ },
24
+ ],
25
+ };
@@ -0,0 +1,187 @@
1
+ // `x cache graph|bust <tag>|clear` — the tag graph off the manifest (`cache-graph.ts`), and a bust
2
+ // run the way an action's `invalidates` runs one: the app's own tiers registered by the same boot a
3
+ // role makes (`startServices`), then `invalidateTags`, which drops the shared tiers, purges the
4
+ // edge and publishes on the bus every replica listens to. No second eviction path.
5
+
6
+ import type { InvalidationReport } from '@ultimat3/cache';
7
+ import {
8
+ assertKnownTags,
9
+ CacheDriverUnavailableError,
10
+ invalidateTags,
11
+ knownTags,
12
+ parseTag,
13
+ } from '@ultimat3/cache';
14
+ import { renderFixShellArg } from '@ultimat3/core';
15
+ import { redisUrlSource } from '@ultimat3/core/redis';
16
+ import { InProcessTransport } from '@ultimat3/realtime/server';
17
+ import { loadApp } from './app-load';
18
+ import { appManifest } from './app-manifest';
19
+ import { requireAppRoot } from './app-root';
20
+ import { loadAppRuntime } from './app-runtime';
21
+ import { cacheGraph, neverEvicted } from './cache-graph';
22
+ import { cacheSpec } from './cmd-cache-spec';
23
+ import { plannedSubcommand } from './cmd-planned';
24
+ import type { CliCommand, CommandContext } from './command';
25
+ import { MissingPositionalError } from './errors';
26
+ import { msg } from './messages';
27
+ import type { CommandResult, Finding, JsonValue } from './output';
28
+ import { findingFrom } from './output';
29
+ import { flagString } from './parse';
30
+ import { resolveServices } from './runtime-bindings';
31
+ import { startServices } from './runtime-services';
32
+
33
+ /** The app's tiers and bus, booted for one bust. */
34
+ export interface CacheHandle {
35
+ invalidate(tags: readonly string[]): Promise<InvalidationReport>;
36
+ /** False when the bus is in-process: no other process hears this one. */
37
+ readonly reachesPeers: boolean;
38
+ /** The bus as the boot line names it — never a URL. */
39
+ readonly bus: string;
40
+ close(): Promise<void>;
41
+ }
42
+
43
+ export type OpenCache = (root: string, ctx: CommandContext) => Promise<CacheHandle>;
44
+
45
+ /**
46
+ * A role's boot with no role started: the tiers `cache.tiers` declares and the broadcast. `'ensure'`,
47
+ * as every CLI command but the migrate step: a bust run against production takes no migration
48
+ * lock, runs no framework DDL and stamps no build (`runtime-queue.ts`'s `SchemaMode`).
49
+ */
50
+ export const openAppCacheWith =
51
+ (start: typeof startServices): OpenCache =>
52
+ async (root, ctx) => {
53
+ const running = await start(
54
+ resolveServices(root, ctx.env),
55
+ ctx.env,
56
+ await loadAppRuntime(root),
57
+ 'ensure',
58
+ [],
59
+ );
60
+ return {
61
+ invalidate: (tags) => invalidateTags(tags.map(parseTag)),
62
+ reachesPeers: !(
63
+ running.transport instanceof InProcessTransport && redisUrlSource(ctx.env) === undefined
64
+ ),
65
+ bus: running.transport.name,
66
+ close: () => running.stop(),
67
+ };
68
+ };
69
+
70
+ async function graph(root: string, only: string | undefined): Promise<CommandResult> {
71
+ const { manifest, findings } = await appManifest(root);
72
+ const tag = only === undefined ? undefined : parseTag(only);
73
+ // After the app loaded, so the declared set is the app's: an undeclared tag is X_CACHE_TAG_UNKNOWN
74
+ // naming the declared ones, never an empty graph that reads as "nothing depends on it".
75
+ if (tag !== undefined) assertKnownTags([tag]);
76
+ const rows = cacheGraph(manifest).filter((row) => tag === undefined || row.tag === tag.entity);
77
+ const stale = rows.filter(neverEvicted).map((row) => row.tag);
78
+ return {
79
+ ok: findings.length === 0,
80
+ command: 'cache',
81
+ summary: msg('cli.cache.graph', { tags: rows.length, stale: stale.length }),
82
+ findings,
83
+ lines: rows.map((row) =>
84
+ msg('cli.cache.graphRow', {
85
+ tag: row.tag,
86
+ writers: row.writers.join(', ') || '—',
87
+ readers: [...row.readers, ...row.routes].join(', ') || '—',
88
+ }),
89
+ ),
90
+ data: {
91
+ tags: rows.map((row) => ({
92
+ tag: row.tag,
93
+ writers: [...row.writers],
94
+ readers: [...row.readers],
95
+ routes: [...row.routes],
96
+ })),
97
+ neverEvicted: stale,
98
+ },
99
+ };
100
+ }
101
+
102
+ /** A tier that failed the bust, as the finding an operator acts on. */
103
+ const tierFinding = (error: { tier: string; message: string }, retry: string): Finding =>
104
+ findingFrom(
105
+ new CacheDriverUnavailableError({
106
+ driver: error.tier,
107
+ cause: error.message,
108
+ fix: `${retry} # again once it answers; x doctor --json names the tier's binding`,
109
+ }),
110
+ );
111
+
112
+ async function bust(
113
+ ctx: CommandContext,
114
+ open: OpenCache,
115
+ root: string,
116
+ /** Read AFTER the app loads: `clear`'s tags are the ones its modules declare. */
117
+ tagsOf: () => readonly string[],
118
+ retry: string,
119
+ ): Promise<CommandResult> {
120
+ // Loaded first: the declared tags are registered by the app's modules, and an undeclared one is
121
+ // refused by `invalidateTags` itself (X_CACHE_TAG_UNKNOWN) rather than busting nothing.
122
+ const { findings } = await loadApp(root);
123
+ const tags = tagsOf();
124
+ const handle = await open(root, ctx);
125
+ const report = await handle.invalidate(tags).finally(() => handle.close());
126
+ const failures = report.errors.map((error) => tierFinding(error, retry));
127
+ const data: JsonValue = {
128
+ tags: [...report.tags],
129
+ tiers: report.tiers.map((tier) => ({
130
+ tier: tier.tier,
131
+ keys: tier.keys.length,
132
+ ...(tier.skipped === undefined ? {} : { skipped: tier.skipped }),
133
+ })),
134
+ isr: [...report.isr],
135
+ cdn: [...report.cdn],
136
+ bus: handle.bus,
137
+ reachesPeers: handle.reachesPeers,
138
+ durationMs: report.durationMs,
139
+ };
140
+ return {
141
+ ok: findings.length === 0 && failures.length === 0,
142
+ command: 'cache',
143
+ summary: handle.reachesPeers
144
+ ? msg('cli.cache.busted', { tags: report.tags.length, bus: handle.bus })
145
+ : msg('cli.cache.bustedLocal', { tags: report.tags.length }),
146
+ findings: [...findings, ...failures],
147
+ lines: report.tiers.map((tier) =>
148
+ msg('cli.cache.tierRow', { tier: tier.tier, keys: tier.keys.length }),
149
+ ),
150
+ data,
151
+ };
152
+ }
153
+
154
+ /** `open` is the seam a test hands tiers through; the shipped command boots the app's own. */
155
+ export const cacheCommandOver = (open: OpenCache): CliCommand => ({
156
+ spec: cacheSpec,
157
+ async run(ctx: CommandContext): Promise<CommandResult> {
158
+ const root = requireAppRoot('cache', ctx.cwd).dir;
159
+ const sub = ctx.args.subcommand ?? 'graph';
160
+ if (sub === 'graph') return graph(root, flagString(ctx.args, 'tag'));
161
+ if (sub === 'bust') {
162
+ const tag = ctx.args.positionals[0];
163
+ if (tag === undefined) {
164
+ throw new MissingPositionalError({
165
+ command: 'cache bust',
166
+ positional: 'tag',
167
+ example: 'x cache graph --json # the declared tags; then x cache bust <tag>',
168
+ });
169
+ }
170
+ return bust(
171
+ ctx,
172
+ open,
173
+ root,
174
+ () => [tag],
175
+ `x cache bust ${renderFixShellArg(tag, '<tag>')} --json`,
176
+ );
177
+ }
178
+ if (sub === 'clear') {
179
+ // Every declared tag through the same bust, so each peer drops what each one covers. An
180
+ // entry cached under no tag is not reached: it waits for its TTL, as it would for any write.
181
+ return bust(ctx, open, root, knownTags, 'x cache clear --json');
182
+ }
183
+ throw plannedSubcommand('cache', sub);
184
+ },
185
+ });
186
+
187
+ export const cacheCommand: CliCommand = cacheCommandOver(openAppCacheWith(startServices));
@@ -0,0 +1,23 @@
1
+ // `x config`'s declaration, apart from its body: the parser, `x help` and the `errors` step
2
+ // read it without loading `cmd-config.ts`, which `registry.ts` imports only when the command runs.
3
+
4
+ import type { CommandSpec } from './parse';
5
+
6
+ export const CONFIG_SUBCOMMANDS = ['show'] as const;
7
+
8
+ export const configSpec: CommandSpec = {
9
+ name: 'config',
10
+ summary: 'the resolved app.config.ts, defaults included, credentials redacted',
11
+ usage: 'x config show [--section <key>] [--json]',
12
+ requiresApp: true,
13
+ subcommands: [...CONFIG_SUBCOMMANDS],
14
+ // Read-only, so the bare form may mean it.
15
+ defaultSubcommand: 'show',
16
+ flags: [
17
+ {
18
+ name: 'section',
19
+ type: 'string',
20
+ summary: 'one top-level key of the resolved config (cache, database, auth, …)',
21
+ },
22
+ ],
23
+ };
@@ -0,0 +1,61 @@
1
+ // `x config show [--section <key>]` — the app's `AppConfig` as the boot reads it: `app.config.ts`
2
+ // through `loadAppConfig` (core's `defineConfig`, defaults merged), credentials redacted by
3
+ // `config-redact.ts`. The answer to "what is this app actually configured to do", without a boot.
4
+
5
+ import { ConfigInvalidError } from '@ultimat3/core';
6
+ import { loadAppConfig } from './app-config-load';
7
+ import { requireAppRoot } from './app-root';
8
+ import { configSpec } from './cmd-config-spec';
9
+ import type { CliCommand, CommandContext } from './command';
10
+ import { ok } from './command';
11
+ import { redactConfigValue } from './config-redact';
12
+ import { BadFlagError } from './errors';
13
+ import { msg } from './messages';
14
+ import type { CommandResult, JsonValue } from './output';
15
+ import { flagString } from './parse';
16
+
17
+ /** The record's own keys, sorted — the closed set `--section` is held to. */
18
+ const sectionsOf = (config: object): readonly string[] => Object.keys(config).sort();
19
+
20
+ export const configCommand: CliCommand = {
21
+ spec: configSpec,
22
+ async run(ctx: CommandContext): Promise<CommandResult> {
23
+ const root = requireAppRoot('config', ctx.cwd);
24
+ const config = await loadAppConfig(root.dir);
25
+ // `requireAppRoot` found the file, so only a race with a delete lands here.
26
+ if (config === undefined) {
27
+ throw new ConfigInvalidError({
28
+ cause: `${root.configPath} vanished between finding the app and reading it`,
29
+ fix: "export const config = defineConfig({ name: 'my-app' });",
30
+ });
31
+ }
32
+ const sections = sectionsOf(config);
33
+ const section = flagString(ctx.args, 'section');
34
+ // `Object.hasOwn`, never `config[section]` first: `--section constructor` would answer the
35
+ // record's prototype method as if the app had declared it.
36
+ if (section !== undefined && !Object.hasOwn(config, section)) {
37
+ throw new BadFlagError({
38
+ flag: 'section',
39
+ command: 'config show',
40
+ reason: `"${section}" is not a key of the resolved config (known: ${sections.join(', ')})`,
41
+ fix: 'x config show --section cache --json',
42
+ });
43
+ }
44
+ const whole = redactConfigValue(config) as { readonly [key: string]: JsonValue };
45
+ const shown: JsonValue = section === undefined ? whole : (whole[section] ?? null);
46
+ return ok(
47
+ 'config',
48
+ section === undefined
49
+ ? msg('cli.config.show', {
50
+ name: config.name,
51
+ count: sections.length,
52
+ path: root.configPath,
53
+ })
54
+ : msg('cli.config.section', { section, path: root.configPath }),
55
+ {
56
+ lines: JSON.stringify(shown, null, 2).split('\n'),
57
+ data: { path: root.configPath, section: section ?? null, config: shown },
58
+ },
59
+ );
60
+ },
61
+ };
package/src/cmd-doctor.ts CHANGED
@@ -20,6 +20,7 @@ import { probeFor } from './doctor-probe';
20
20
  import { rollingSinceProbe, withRollingReminder } from './doctor-rolling';
21
21
  import { sealedKeyFindings } from './doctor-sealed';
22
22
  import { typescriptFindings } from './doctor-typescript';
23
+ import { doctorWarnings, withDoctorWarnings } from './doctor-warnings';
23
24
  import { ICON_SOURCE } from './icon-assets';
24
25
  import { msg } from './messages';
25
26
  import type { CommandResult, Finding } from './output';
@@ -131,48 +132,57 @@ export async function runDoctor(probe: DoctorProbe): Promise<readonly Finding[]>
131
132
  // Sealed columns against the key ring: no key at all, or a rotation whose re-seal is pending.
132
133
  findings.push(...sealedKeyFindings(await probe.sealedKeys()));
133
134
  findings.push(...authStorageFindings(await probe.authStorage()));
135
+ // `X_FRAMEWORK_PIN_RANGE`, `X_ENV_NAME_RESERVED`, `X_DB_ROW_SECURITY_OFF` and
136
+ // `X_VERIFY_STEP_UNFLOORED` are not here: on `main` they warn beside the verdict
137
+ // (`doctor-warnings.ts`), so an upgrade with no change keeps this green.
134
138
  return findings;
135
139
  }
136
140
 
141
+ /** The whole report over one probe: the verdict, then the listings and warnings beside it. */
142
+ export async function reportDoctor(probe: DoctorProbe): Promise<CommandResult> {
143
+ // Asked once: `runDoctor` reads the verdict and the report beside it reads the numbers.
144
+ const pooler = probe.root === undefined ? NO_POOLER_FACT : await probe.pooler();
145
+ const findings = await runDoctor({ ...probe, pooler: async () => pooler });
146
+ const listed = withGuardListing(
147
+ {
148
+ ok: findings.length === 0,
149
+ command: 'doctor',
150
+ summary:
151
+ findings.length === 0
152
+ ? msg('cli.doctor.clean')
153
+ : msg('cli.doctor.findings', { count: findings.length }),
154
+ findings,
155
+ data: { count: findings.length, codes: findings.map((entry) => entry.code) },
156
+ },
157
+ // A listing beside the verdict, never part of it (`doctor-guards.ts` says why).
158
+ probe.root === undefined ? [] : await shippedGuardsProbe(probe.root),
159
+ );
160
+ // The second listing: what the coverage floor does not see (`doctor-coverage.ts`).
161
+ const covered = withCoverageExcludes(
162
+ listed,
163
+ probe.root === undefined ? [] : await coverageExcludesProbe(probe.root),
164
+ );
165
+ // The third: the monitoring templates the app's chart predates (`doctor-chart-alerts.ts`).
166
+ const charted = withChartAlertsListing(
167
+ covered,
168
+ probe.root === undefined ? [] : chartAlertsProbe(probe.root),
169
+ );
170
+ // A reminder, not a finding: the rolling rail is off until this is set (`doctor-rolling.ts`).
171
+ const reminded = withPoolerReport(
172
+ withRollingReminder(
173
+ charted,
174
+ probe.root === undefined ? undefined : await rollingSinceProbe(probe.root),
175
+ ),
176
+ pooler,
177
+ );
178
+ // Last, and beside the verdict on `main`: the 31.16.0 checks (`doctor-warnings.ts`).
179
+ return withDoctorWarnings(reminded, await doctorWarnings(probe));
180
+ }
181
+
137
182
  export const doctorCommand: CliCommand = {
138
183
  spec: doctorSpec,
139
- async run(ctx: CommandContext): Promise<CommandResult> {
184
+ run(ctx: CommandContext): Promise<CommandResult> {
140
185
  const port = doctorPort(ctx.args, ctx.env);
141
- const probe = probeFor(ctx.cwd, ctx.bunVersion, port, ctx.env);
142
- // Asked once: `runDoctor` reads the verdict and the report beside it reads the numbers.
143
- const pooler = probe.root === undefined ? NO_POOLER_FACT : await probe.pooler();
144
- const findings = await runDoctor({ ...probe, pooler: async () => pooler });
145
- const listed = withGuardListing(
146
- {
147
- ok: findings.length === 0,
148
- command: 'doctor',
149
- summary:
150
- findings.length === 0
151
- ? msg('cli.doctor.clean')
152
- : msg('cli.doctor.findings', { count: findings.length }),
153
- findings,
154
- data: { count: findings.length, codes: findings.map((entry) => entry.code) },
155
- },
156
- // A listing beside the verdict, never part of it (`doctor-guards.ts` says why).
157
- probe.root === undefined ? [] : await shippedGuardsProbe(probe.root),
158
- );
159
- // The second listing: what the coverage floor does not see (`doctor-coverage.ts`).
160
- const covered = withCoverageExcludes(
161
- listed,
162
- probe.root === undefined ? [] : await coverageExcludesProbe(probe.root),
163
- );
164
- // The third: the monitoring templates the app's chart predates (`doctor-chart-alerts.ts`).
165
- const charted = withChartAlertsListing(
166
- covered,
167
- probe.root === undefined ? [] : chartAlertsProbe(probe.root),
168
- );
169
- // A reminder, not a finding: the rolling rail is off until this is set (`doctor-rolling.ts`).
170
- return withPoolerReport(
171
- withRollingReminder(
172
- charted,
173
- probe.root === undefined ? undefined : await rollingSinceProbe(probe.root),
174
- ),
175
- pooler,
176
- );
186
+ return reportDoctor(probeFor(ctx.cwd, ctx.bunVersion, port, ctx.env));
177
187
  },
178
188
  };