@ultimat3/cli 31.16.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.
- package/README.md +7 -1
- package/package.json +29 -29
- package/src/cache-graph.ts +67 -0
- package/src/cmd-cache-spec.ts +25 -0
- package/src/cmd-cache.ts +187 -0
- package/src/cmd-config-spec.ts +23 -0
- package/src/cmd-config.ts +61 -0
- package/src/cmd-exercise.ts +34 -10
- package/src/cmd-explain-spec.ts +24 -0
- package/src/cmd-explain.ts +201 -0
- package/src/cmd-logs-spec.ts +34 -0
- package/src/cmd-logs.ts +80 -0
- package/src/cmd-planned.ts +15 -29
- package/src/cmd-token-spec.ts +54 -0
- package/src/cmd-token.ts +173 -0
- package/src/cmd-verify-spec.ts +13 -3
- package/src/cmd-verify.ts +2 -0
- package/src/config-redact.ts +39 -0
- package/src/dev-boot-data-dir.ts +69 -0
- package/src/dev-boot.ts +26 -13
- package/src/error-codes-tooling.ts +6 -4
- package/src/error-codes.ts +2 -0
- package/src/errors.ts +8 -2
- package/src/exercise-entry-edit.ts +5 -1
- package/src/exercise-routes.ts +59 -0
- package/src/explain-capture.ts +38 -0
- package/src/generate-exercise.ts +2 -2
- package/src/generate-factories.ts +133 -0
- package/src/generate-files.ts +11 -0
- package/src/generate-kinds.ts +13 -0
- package/src/mcp-db-target.ts +4 -3
- package/src/mcp-errors.ts +4 -0
- package/src/messages-gate.ts +2 -0
- package/src/messages-ops.ts +32 -0
- package/src/messages-upgrade.ts +1 -0
- package/src/messages.ts +2 -0
- package/src/otlp-export.ts +16 -2
- package/src/registry.ts +10 -0
- package/src/role-start.ts +11 -5
- package/src/runtime-services.ts +35 -19
- package/src/serve-boot-phases.ts +30 -0
- package/src/serve-boot-warnings.ts +62 -0
- package/src/serve-boot.ts +30 -11
- package/src/templates/generate-cron-job.ts +90 -0
- package/src/templates/generate-purge.ts +93 -0
- package/src/templates/generate-webhook-receiver.ts +274 -0
- package/src/templates/github/ci.yml.ts +101 -36
- package/src/templates/guard-repo-raw-sql-test.ts +174 -0
- package/src/templates/guard-repo-raw-sql.ts +115 -145
- package/src/templates/guard-unbounded-fanout.ts +170 -0
- package/src/templates/scaffold-claude-commands.ts +3 -2
- package/src/templates/scaffold-docs.ts +3 -2
- package/src/templates/scaffold-guards.ts +3 -0
- package/src/upgrade-gate.ts +18 -6
- package/src/upgrade-report.ts +4 -0
- package/src/verify-plan.ts +127 -0
- package/wiki/CI-Parallel-Gate.md +38 -1
- package/wiki/CLI-Reference.md +90 -12
- package/wiki/Caching-And-Invalidation.md +10 -10
- package/wiki/Configuration.md +4 -2
- package/wiki/Known-Gaps.md +1 -1
- package/wiki/MCP-And-AI.md +1 -1
- package/wiki/Testing.md +32 -0
- package/wiki/Troubleshooting.md +3 -2
- package/wiki/Upgrading.md +6 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// The resolved `AppConfig` as JSON an operator may paste into an issue: every credential-named key
|
|
2
|
+
// and every `secret()` value replaced, a URL's password cut out of its userinfo. The key rule is
|
|
3
|
+
// core's `isRedactedKey` — the logger's — so a field the log line hides is hidden here too.
|
|
4
|
+
|
|
5
|
+
import { isRedactedKey, isSecret, REDACTED } from '@ultimat3/core';
|
|
6
|
+
import type { JsonValue } from './output';
|
|
7
|
+
|
|
8
|
+
/** `scheme://user:password@host` → `scheme://user:[redacted]@host`. The user stays: it is no secret. */
|
|
9
|
+
const USERINFO_PASSWORD = /^([a-z][a-z0-9+.-]*:\/\/[^:/@\s]*):[^@/\s]*@/i;
|
|
10
|
+
|
|
11
|
+
/** Past this depth a config is not data an operator wrote; the walk stops rather than recurse. */
|
|
12
|
+
const MAX_DEPTH = 16;
|
|
13
|
+
|
|
14
|
+
export function redactConfigValue(value: unknown, depth = 0): JsonValue {
|
|
15
|
+
if (isSecret(value)) return REDACTED;
|
|
16
|
+
if (value === null || value === undefined) return null;
|
|
17
|
+
if (typeof value === 'string') return value.replace(USERINFO_PASSWORD, `$1:${REDACTED}@`);
|
|
18
|
+
if (typeof value === 'number') return Number.isFinite(value) ? value : String(value);
|
|
19
|
+
if (typeof value === 'boolean') return value;
|
|
20
|
+
// A config may carry a callback (a `health` probe, a `resolve` hook): named, never its source.
|
|
21
|
+
if (typeof value === 'function') return '[function]';
|
|
22
|
+
if (typeof value === 'bigint' || typeof value === 'symbol') return String(value);
|
|
23
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value.toISOString();
|
|
24
|
+
if (value instanceof RegExp) return String(value);
|
|
25
|
+
if (depth >= MAX_DEPTH) return '[nested too deep]';
|
|
26
|
+
if (Array.isArray(value)) return value.map((item: unknown) => redactConfigValue(item, depth + 1));
|
|
27
|
+
const out: Record<string, JsonValue> = {};
|
|
28
|
+
for (const [key, item] of Object.entries(value as Record<string, unknown>)) {
|
|
29
|
+
// `defineProperty`, never `out[key] =`: a config key is the app's string, and `__proto__`
|
|
30
|
+
// assigned would re-prototype the record instead of adding a field.
|
|
31
|
+
Object.defineProperty(out, key, {
|
|
32
|
+
value: isRedactedKey(key) ? REDACTED : redactConfigValue(item, depth + 1),
|
|
33
|
+
enumerable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// `x dev`'s answer to an embedded data directory that will not open: set it aside under a dated
|
|
2
|
+
// suffix, boot a fresh one, and say so (`X_DEV_DATA_UNOPENABLE`, a notice, never a refusal). The
|
|
3
|
+
// boot used to fail with `X_DB_UNAVAILABLE`, whose fix was to run the command that had just failed.
|
|
4
|
+
|
|
5
|
+
// why: Bun ships no rename or exists API for a directory.
|
|
6
|
+
import { existsSync, renameSync } from 'node:fs';
|
|
7
|
+
import { renderThrowable } from '@ultimat3/core';
|
|
8
|
+
import { pgliteClient, pgliteDataDir, sql } from '@ultimat3/db';
|
|
9
|
+
import type { Finding } from './output';
|
|
10
|
+
import type { ServiceBinding } from './runtime-bindings';
|
|
11
|
+
|
|
12
|
+
/** `<dir>.unopenable-<UTC instant>`: sorts by date, and no two boots a second apart collide. */
|
|
13
|
+
export const asideName = (dataDir: string, now: Date): string =>
|
|
14
|
+
`${dataDir}.unopenable-${now
|
|
15
|
+
.toISOString()
|
|
16
|
+
.replace(/[-:]/g, '')
|
|
17
|
+
.replace(/\.\d+Z$/, 'Z')}`;
|
|
18
|
+
|
|
19
|
+
/** Whether PGlite opens `dataDir` and answers one statement. Costs a PGlite boot. */
|
|
20
|
+
export async function pgliteOpens(
|
|
21
|
+
dataDir: string,
|
|
22
|
+
extensions: () => Promise<readonly string[]>,
|
|
23
|
+
): Promise<boolean> {
|
|
24
|
+
const client = pgliteClient({ dataDir, extensions });
|
|
25
|
+
try {
|
|
26
|
+
await client.query(sql`select 1`);
|
|
27
|
+
return true;
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
} finally {
|
|
31
|
+
await client.close().catch(() => undefined);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface StartOverOptions<T> {
|
|
36
|
+
/** The boot: `startServices`, run a second time over the fresh directory. */
|
|
37
|
+
readonly start: () => Promise<T>;
|
|
38
|
+
/** Asked only after `start` failed: does the directory open on its own? */
|
|
39
|
+
readonly opens: (dataDir: string) => Promise<boolean>;
|
|
40
|
+
readonly now: () => Date;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* `start()`, and when it fails over an embedded directory that exists and does not open by itself,
|
|
45
|
+
* that directory renamed aside and `start()` once more. Every other failure — an external database,
|
|
46
|
+
* a first boot with nothing on disk, a directory that opens — is rethrown untouched: moving a
|
|
47
|
+
* developer's data is only ever the answer to that data being unreadable. Renamed, never deleted.
|
|
48
|
+
*/
|
|
49
|
+
export async function startOverUnopenable<T>(
|
|
50
|
+
binding: ServiceBinding,
|
|
51
|
+
options: StartOverOptions<T>,
|
|
52
|
+
): Promise<{ readonly value: T; readonly notice?: Finding }> {
|
|
53
|
+
try {
|
|
54
|
+
return { value: await options.start() };
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (binding.mode !== 'embedded') throw error;
|
|
57
|
+
const dataDir = pgliteDataDir(binding.url);
|
|
58
|
+
if (!existsSync(dataDir) || (await options.opens(dataDir))) throw error;
|
|
59
|
+
const aside = asideName(dataDir, options.now());
|
|
60
|
+
renameSync(dataDir, aside);
|
|
61
|
+
const notice: Finding = {
|
|
62
|
+
code: 'X_DEV_DATA_UNOPENABLE',
|
|
63
|
+
cause: `the embedded database at ${dataDir} would not open (${renderThrowable(error)}), so it was moved to ${aside} and this boot started an empty one — the app's tables and rows are in the moved directory, not in this database`,
|
|
64
|
+
fix: 'x db migrate',
|
|
65
|
+
meta: { dataDir, aside },
|
|
66
|
+
};
|
|
67
|
+
return { value: await options.start(), notice };
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/dev-boot.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { devShellStyle } from '@ultimat3/admin/dev';
|
|
7
7
|
import type { Role } from '@ultimat3/core';
|
|
8
|
-
import { subscribe, subscribeSemconvMetrics } from '@ultimat3/core';
|
|
8
|
+
import { subscribe, subscribeSemconvMetrics, systemClock } from '@ultimat3/core';
|
|
9
9
|
import type { OverlayNotice, RequestContext } from '@ultimat3/http';
|
|
10
10
|
import { asCtx, subscribeRequestTimings } from '@ultimat3/http';
|
|
11
11
|
import { loadSignInPath } from './app-auth';
|
|
@@ -13,6 +13,7 @@ import { loadAppConfig } from './app-config-load';
|
|
|
13
13
|
import type { StalePin } from './app-reload-graph';
|
|
14
14
|
import { enableReloadTracking } from './app-reload-graph';
|
|
15
15
|
import { loadAppRuntime } from './app-runtime';
|
|
16
|
+
import { pgliteOpens, startOverUnopenable } from './dev-boot-data-dir';
|
|
16
17
|
import type { DevDashboardInput, DevStatus } from './dev-dashboard';
|
|
17
18
|
import { devPanels } from './dev-dashboard';
|
|
18
19
|
import { createInvalidationLog } from './dev-dashboard-invalidations';
|
|
@@ -25,6 +26,7 @@ import { createTraceRecorder } from './dev-traces';
|
|
|
25
26
|
import { watchTree } from './dev-watch-tree';
|
|
26
27
|
import { armFailureCapture } from './failure-capture-boot';
|
|
27
28
|
import { FRAME_STYLE } from './island-harness';
|
|
29
|
+
import { appExtensions } from './migration-extensions';
|
|
28
30
|
import type { Finding } from './output';
|
|
29
31
|
import { plainRoutes } from './plain-routes';
|
|
30
32
|
import type { RunningRoles } from './role-start';
|
|
@@ -118,22 +120,31 @@ export async function startDev(options: StartDevOptions): Promise<DevServer> {
|
|
|
118
120
|
// actions wrote to two different places in `x dev` and to one in production.
|
|
119
121
|
const appRuntime = await loadAppRuntime(options.root);
|
|
120
122
|
// The roles decide whether this boot waits for the bus, exactly as a container's one role does.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
123
|
+
// An embedded data directory that will not open is set aside and the boot runs again over an
|
|
124
|
+
// empty one — the developer is told where it went (`dev-boot-data-dir.ts`).
|
|
125
|
+
const started = await startOverUnopenable(resolved.db, {
|
|
126
|
+
start: () =>
|
|
127
|
+
startServices(
|
|
128
|
+
resolved,
|
|
129
|
+
env,
|
|
130
|
+
appRuntime,
|
|
131
|
+
'apply',
|
|
132
|
+
options.roles ?? DEV_ROLES,
|
|
133
|
+
// Every role in one process: a bus that is away must not take the pages down with it.
|
|
134
|
+
true,
|
|
135
|
+
),
|
|
136
|
+
opens: (dataDir) => pgliteOpens(dataDir, () => appExtensions(options.root)),
|
|
137
|
+
now: () => (appRuntime?.clock ?? systemClock).now(),
|
|
138
|
+
});
|
|
139
|
+
const runtime: RunningServices = started.value;
|
|
140
|
+
const notices = started.notice === undefined ? [] : [started.notice];
|
|
130
141
|
// The events binding the boot line reports is the bus the runtime chose, read off it.
|
|
131
142
|
const services = withRealtimeEvents(resolved, env, appRuntime?.transport !== undefined);
|
|
132
143
|
// `serve.ts`'s `releaseBoot` shape: everything acquired from here on is released, newest first,
|
|
133
144
|
// if the boot throws — a failed `x dev` left PGlite holding `.x/pgdata` for the retry to meet.
|
|
134
145
|
const acquired: (() => void | Promise<void>)[] = [() => runtime.stop()];
|
|
135
146
|
try {
|
|
136
|
-
return await bootDev(options, services, runtime, acquired, appRuntime);
|
|
147
|
+
return await bootDev(options, services, runtime, acquired, appRuntime, notices);
|
|
137
148
|
} catch (error) {
|
|
138
149
|
await releaseBoot(acquired);
|
|
139
150
|
throw error;
|
|
@@ -146,6 +157,8 @@ async function bootDev(
|
|
|
146
157
|
runtime: RunningServices,
|
|
147
158
|
acquired: (() => void | Promise<void>)[],
|
|
148
159
|
appRuntime: RuntimeOverrides | undefined,
|
|
160
|
+
/** What the boot did on the developer's behalf and must say: a set-aside data directory. */
|
|
161
|
+
notices: readonly Finding[],
|
|
149
162
|
): Promise<DevServer> {
|
|
150
163
|
// Installed before the app loads, so a span opened during registration is already recorded.
|
|
151
164
|
// Tracing is always on in the framework and free until something subscribes to `span.end`;
|
|
@@ -321,8 +334,8 @@ async function bootDev(
|
|
|
321
334
|
get findings(): readonly Finding[] {
|
|
322
335
|
const loops = statements.repeats().map(loopFacts).map(loopFinding);
|
|
323
336
|
return state.reloadFinding === undefined
|
|
324
|
-
? [...state.appFindings, ...loops]
|
|
325
|
-
: [...state.appFindings, state.reloadFinding, ...loops];
|
|
337
|
+
? [...notices, ...state.appFindings, ...loops]
|
|
338
|
+
: [...notices, ...state.appFindings, state.reloadFinding, ...loops];
|
|
326
339
|
},
|
|
327
340
|
running,
|
|
328
341
|
runtime,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// The X_* codes of the app tooling commands — `x client`, `x graph` / `x impact
|
|
2
|
-
// split out of `error-codes.ts` at its 500-line ceiling, as `error-codes-shot.ts`
|
|
3
|
-
// folds these into the CLI's one owned union and registers them in its one call.
|
|
1
|
+
// The X_* codes of the app tooling commands — `x client`, `x graph` / `x impact`, `x repro` and
|
|
2
|
+
// `x explain` — split out of `error-codes.ts` at its 500-line ceiling, as `error-codes-shot.ts`
|
|
3
|
+
// was. That file folds these into the CLI's one owned union and registers them in its one call.
|
|
4
4
|
|
|
5
|
-
/** Codes `x client`, `x graph`, `x impact` and `x
|
|
5
|
+
/** Codes `x client`, `x graph`, `x impact`, `x repro` and `x explain` declare and own. */
|
|
6
6
|
export const CLI_TOOLING_ERROR_CODES = [
|
|
7
7
|
'X_CLIENT_SPEC_UNSUPPORTED',
|
|
8
8
|
'X_CLIENT_STALE',
|
|
@@ -12,6 +12,7 @@ export const CLI_TOOLING_ERROR_CODES = [
|
|
|
12
12
|
'X_REPRO_UNKNOWN',
|
|
13
13
|
'X_REPRO_NOT_REPRODUCED',
|
|
14
14
|
'X_REPRO_CAPTURE_OFF',
|
|
15
|
+
'X_EXPLAIN_PRODUCTION_DATABASE',
|
|
15
16
|
] as const;
|
|
16
17
|
|
|
17
18
|
export type CliToolingErrorCode = (typeof CLI_TOOLING_ERROR_CODES)[number];
|
|
@@ -26,4 +27,5 @@ export const CLI_TOOLING_ERROR_TITLES: Readonly<Record<CliToolingErrorCode, stri
|
|
|
26
27
|
X_REPRO_UNKNOWN: 'x repro was given an id nothing holds',
|
|
27
28
|
X_REPRO_NOT_REPRODUCED: 'a written repro test did not fail the way the original did',
|
|
28
29
|
X_REPRO_CAPTURE_OFF: 'x repro was given a request id while failure capture is off',
|
|
30
|
+
X_EXPLAIN_PRODUCTION_DATABASE: 'x explain refused to run on a production database',
|
|
29
31
|
};
|
package/src/error-codes.ts
CHANGED
|
@@ -242,6 +242,7 @@ export const CLI_OWNED_ERROR_CODES = [
|
|
|
242
242
|
'X_SEED_FAILED',
|
|
243
243
|
'X_NATIVE_FORM_UNANSWERED',
|
|
244
244
|
'X_ASSET_RETAIN_UNDECLARED',
|
|
245
|
+
'X_DEV_DATA_UNOPENABLE',
|
|
245
246
|
] as const;
|
|
246
247
|
|
|
247
248
|
/**
|
|
@@ -470,6 +471,7 @@ export const CLI_ERROR_TITLES: Readonly<Record<CliListedErrorCode, string>> = {
|
|
|
470
471
|
X_SEED_FAILED: 'a seed threw an uncoded error',
|
|
471
472
|
X_NATIVE_FORM_UNANSWERED: 'a page form posts to an action that declares no native answer',
|
|
472
473
|
X_ASSET_RETAIN_UNDECLARED: "A served build keeps no earlier build's assets",
|
|
474
|
+
X_DEV_DATA_UNOPENABLE: 'x dev set aside an embedded data directory that would not open',
|
|
473
475
|
};
|
|
474
476
|
|
|
475
477
|
// One unconditional call, so a second package claiming one of the CLI's codes throws
|
package/src/errors.ts
CHANGED
|
@@ -7,10 +7,16 @@ import { quoteArg } from './shell-quote';
|
|
|
7
7
|
|
|
8
8
|
/** An unknown command or subcommand. Carries a suggestion so the retry is one keystroke away. */
|
|
9
9
|
export class UnknownCommandError extends UltimateError {
|
|
10
|
-
|
|
10
|
+
/** `why`: the decision behind a name that is deliberately not a command, said after the list. */
|
|
11
|
+
constructor(input: {
|
|
12
|
+
path: string;
|
|
13
|
+
known: readonly string[];
|
|
14
|
+
suggestion?: string;
|
|
15
|
+
why?: string;
|
|
16
|
+
}) {
|
|
11
17
|
super({
|
|
12
18
|
code: 'X_CLI_UNKNOWN_COMMAND',
|
|
13
|
-
cause: `"x ${input.path}" is not a command (known: ${input.known.join(', ')})`,
|
|
19
|
+
cause: `"x ${input.path}" is not a command (known: ${input.known.join(', ')})${input.why === undefined ? '' : ` — ${input.why}`}`,
|
|
14
20
|
fix: input.suggestion === undefined ? 'x help' : `x ${input.suggestion}`,
|
|
15
21
|
});
|
|
16
22
|
}
|
|
@@ -34,6 +34,10 @@ const KEY = /^(?:([A-Za-z_$][\w$]*)|'([^']*)'|"([^"]*)")\s*(?::|$)/;
|
|
|
34
34
|
|
|
35
35
|
const refused = (reason: string): ExerciseEdit => ({ kind: 'refused', reason });
|
|
36
36
|
|
|
37
|
+
/** As an object key: bare where it is an identifier, quoted where it is not (`'billing-events'`). */
|
|
38
|
+
export const entryKey = (name: string): string =>
|
|
39
|
+
/^[A-Za-z_$][\w$]*$/.test(name) ? name : `'${name}'`;
|
|
40
|
+
|
|
37
41
|
/** `source` (or `x new`'s file when there is none) with every entry it does not name yet. */
|
|
38
42
|
export function editExerciseFile(
|
|
39
43
|
source: string | undefined,
|
|
@@ -83,7 +87,7 @@ const lineIndent = (source: string, at: number): string => {
|
|
|
83
87
|
|
|
84
88
|
/** ` name: value,` with every line of the value under `indent`. */
|
|
85
89
|
const row = (indent: string, entry: ExerciseEntry): string =>
|
|
86
|
-
`${indent}${entry.name}: ${entry.value.split('\n').join(`\n${indent}`)},`;
|
|
90
|
+
`${indent}${entryKey(entry.name)}: ${entry.value.split('\n').join(`\n${indent}`)},`;
|
|
87
91
|
|
|
88
92
|
function insertRows(
|
|
89
93
|
source: string,
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// What `x exercise` says about the route `load`s the pass ran (`@ultimat3/testing`'s
|
|
2
|
+
// `exercise-route-loads.ts`), and about a primitive reached with nothing to prove: WARNING lines,
|
|
3
|
+
// each naming the route file or the primitive. Warnings on `main` — a page read was never judged
|
|
4
|
+
// before, and an app that has not opted in stays green (X_BREAKING_ON_MAIN); red needs a floor key.
|
|
5
|
+
|
|
6
|
+
import type { ExerciseRecord, RouteLoadRecord } from '@ultimat3/testing';
|
|
7
|
+
|
|
8
|
+
const where = (record: RouteLoadRecord): string => `route ${record.name} (${record.file})`;
|
|
9
|
+
|
|
10
|
+
/** Each route's load as warning lines: a loop, a call over the ceiling, a seq scan, or unrun. */
|
|
11
|
+
export function routeLoadWarnings(records: readonly RouteLoadRecord[]): readonly string[] {
|
|
12
|
+
return records.flatMap((record): readonly string[] => {
|
|
13
|
+
if (record.outcome !== 'reached') {
|
|
14
|
+
return [`${where(record)} · load not exercised: ${record.reason ?? record.outcome}`];
|
|
15
|
+
}
|
|
16
|
+
const lines: string[] = [];
|
|
17
|
+
if (record.scale?.verdict === 'grows') {
|
|
18
|
+
for (const shape of record.scale.shapes) {
|
|
19
|
+
lines.push(
|
|
20
|
+
`${where(record)} · X_QUERY_SCALES_WITH_ROWS ${shape.fingerprint} ${String(shape.small)}→${String(shape.large)} at 2→8 rows a table: its load reads once per row — fold it into one read, or wrap it in expectedQueryLoop('<why>', fn)`,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const ceiling = record.statementCeiling;
|
|
25
|
+
if (ceiling?.verdict === 'over') {
|
|
26
|
+
const top = ceiling.top.map((shape) => `${shape.fingerprint} ×${String(shape.count)}`);
|
|
27
|
+
lines.push(
|
|
28
|
+
`${where(record)} · X_STATEMENTS_OVER_BUDGET ${String(ceiling.statements)} statements in one load, max ${String(ceiling.max)}: ${top.join(', ')}`,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
for (const finding of record.plans?.findings ?? []) {
|
|
32
|
+
lines.push(`${where(record)} · ${finding.code} ${finding.table}`);
|
|
33
|
+
}
|
|
34
|
+
return lines;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** How many names an empty-reach line lists before it says how many more. */
|
|
39
|
+
const NAMED = 5;
|
|
40
|
+
|
|
41
|
+
/** The line's code (`@ultimat3/testing` registers it): a warning on `main`, never a finding. */
|
|
42
|
+
const EMPTY_REACH = 'X_EXERCISE_EMPTY_REACH';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Reached with no statement and no effect: every proof on it is vacuous — a scale sweep of nothing
|
|
46
|
+
* is "flat", a tenant proof over nothing is "proven". Said once, with the first few named.
|
|
47
|
+
*/
|
|
48
|
+
export function emptyReachWarnings(records: readonly ExerciseRecord[]): readonly string[] {
|
|
49
|
+
const empty = records.filter(
|
|
50
|
+
(record) =>
|
|
51
|
+
record.outcome === 'reached' && record.statements === 0 && record.effects.length === 0,
|
|
52
|
+
);
|
|
53
|
+
if (empty.length === 0) return [];
|
|
54
|
+
const named = empty.slice(0, NAMED).map((record) => `${record.kind} ${record.name}`);
|
|
55
|
+
const more = empty.length > NAMED ? `, and ${String(empty.length - NAMED)} more` : '';
|
|
56
|
+
return [
|
|
57
|
+
`${EMPTY_REACH} ${String(empty.length)} reached primitive(s) sent no statement and had no effect, so their proofs prove nothing: ${named.join(', ')}${more} — fix: edit exercise.ts: give each an input that reaches its work, or { off: '<why>' }`,
|
|
58
|
+
];
|
|
59
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// The statements ONE call sends, as `x explain` plans them: every `db.statement` event the call
|
|
2
|
+
// made under a marker of its own (never by time — the bus is process-wide), its text whitespace
|
|
3
|
+
// collapsed and its `expectedSeqScan` reason kept, exactly as the exercise room records them.
|
|
4
|
+
|
|
5
|
+
import { asyncContext, subscribe } from '@ultimat3/core';
|
|
6
|
+
import { expectedSeqScanReason } from '@ultimat3/db';
|
|
7
|
+
import type { SentStatement } from '@ultimat3/testing';
|
|
8
|
+
|
|
9
|
+
const scope = asyncContext<object>('x explain');
|
|
10
|
+
|
|
11
|
+
export interface Captured<T> {
|
|
12
|
+
readonly value: T;
|
|
13
|
+
/** Statement text → who sent it and why it may scan, in the shape `sweepPlans` reads. */
|
|
14
|
+
readonly sent: ReadonlyMap<string, SentStatement>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function captureStatements<T>(
|
|
18
|
+
subject: string,
|
|
19
|
+
fn: () => Promise<T>,
|
|
20
|
+
): Promise<Captured<T>> {
|
|
21
|
+
const marker = {};
|
|
22
|
+
const sent = new Map<string, { primitives: Set<string>; scan?: string }>();
|
|
23
|
+
// The bus delivers synchronously in the sender's context, so the marker read is the sender's.
|
|
24
|
+
const off = subscribe('db.statement', (event) => {
|
|
25
|
+
if (scope.get() !== marker) return;
|
|
26
|
+
const text = event.payload.text.replace(/\s+/g, ' ').trim();
|
|
27
|
+
const one = sent.get(text) ?? { primitives: new Set([subject]) };
|
|
28
|
+
const scan = expectedSeqScanReason();
|
|
29
|
+
if (scan !== undefined) one.scan = scan;
|
|
30
|
+
sent.set(text, one);
|
|
31
|
+
});
|
|
32
|
+
try {
|
|
33
|
+
const value = await scope.run(marker, fn);
|
|
34
|
+
return { value, sent };
|
|
35
|
+
} finally {
|
|
36
|
+
off();
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/generate-exercise.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { UltimateError } from '@ultimat3/core';
|
|
6
6
|
import type { ExerciseEntry } from './exercise-entry-edit';
|
|
7
|
-
import { editExerciseFile } from './exercise-entry-edit';
|
|
7
|
+
import { editExerciseFile, entryKey } from './exercise-entry-edit';
|
|
8
8
|
import { EXERCISE_FILE } from './exercise-registration';
|
|
9
9
|
import type { GenerateDisk } from './generate-disk';
|
|
10
10
|
import type { Finding } from './output';
|
|
@@ -23,7 +23,7 @@ export const writtenExercises = (
|
|
|
23
23
|
|
|
24
24
|
/** One line of an entry: what the fix asks to paste, whitespace folded. */
|
|
25
25
|
const oneLine = (entry: ExerciseEntry): string =>
|
|
26
|
-
`${entry.name}: ${entry.value.replace(/\s*\n\s*/g, ' ').replace(/, }/g, ' }')}`;
|
|
26
|
+
`${entryKey(entry.name)}: ${entry.value.replace(/\s*\n\s*/g, ' ').replace(/, }/g, ' }')}`;
|
|
27
27
|
|
|
28
28
|
/** Inserts `entries` into the app's exercise file; answers the path when it changed, or a refusal. */
|
|
29
29
|
export async function declareGeneratedExercises(
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Which `x g` generator scaffolds each primitive factory, or why none does. One row per
|
|
2
|
+
// `PRIMITIVE_FACTORIES` entry, held to it by `generate-factories.test.ts`: a factory that ships
|
|
3
|
+
// with neither a generator nor a reason is refused there, never noticed later.
|
|
4
|
+
|
|
5
|
+
import type { Generator } from './generate-kinds';
|
|
6
|
+
|
|
7
|
+
/** A factory `x g <generator>` scaffolds: the one call, its tests, in the feature's slice. */
|
|
8
|
+
interface Generated {
|
|
9
|
+
readonly factory: string;
|
|
10
|
+
readonly generator: Generator;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** A factory no generator writes, and the sentence that says why — the decision, on the record. */
|
|
14
|
+
interface NotGenerated {
|
|
15
|
+
readonly factory: string;
|
|
16
|
+
readonly none: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type FactoryGenerator = Generated | NotGenerated;
|
|
20
|
+
|
|
21
|
+
/** The model rule three AI factories share: the app registers every model, the framework none. */
|
|
22
|
+
const MODEL =
|
|
23
|
+
'calls a model the app registers itself (registerModel, @ultimat3/ai) — the framework registers none, so a generated declaration would name an id that is X_AI_MODEL_UNKNOWN at its first call';
|
|
24
|
+
|
|
25
|
+
/** Sorted by factory name, as `PRIMITIVE_FACTORIES` is by package then name. */
|
|
26
|
+
export const FACTORY_GENERATORS: readonly FactoryGenerator[] = [
|
|
27
|
+
{ factory: 'agent', none: MODEL },
|
|
28
|
+
{
|
|
29
|
+
factory: 'agentJob',
|
|
30
|
+
none: 'wraps an action the app already declares, and which one is a choice x g cannot read off the disk; deferred (plan 101 U6) until x g takes the action to wrap',
|
|
31
|
+
},
|
|
32
|
+
{ factory: 'backfill', generator: 'backfill' },
|
|
33
|
+
{
|
|
34
|
+
factory: 'consumer',
|
|
35
|
+
none: 'subscribes to an event topic the app publishes — the topic and its payload are the app’s own vocabulary, and a generated consumer would subscribe to nothing',
|
|
36
|
+
},
|
|
37
|
+
{ factory: 'cronJob', generator: 'cron-job' },
|
|
38
|
+
{
|
|
39
|
+
factory: 'deviceSocket',
|
|
40
|
+
none: 'a websocket mount speaking the app’s own device protocol; the protocol is the whole of the declaration, and only the app knows it',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
factory: 'exportRows',
|
|
44
|
+
none: 'reads one table through the app’s typed handle into a storage disk; deferred (plan 101 U6) until x g can refuse a slice whose table is not the scaffolded one under its own code',
|
|
45
|
+
},
|
|
46
|
+
{ factory: 'hive', none: MODEL },
|
|
47
|
+
{
|
|
48
|
+
factory: 'importRows',
|
|
49
|
+
none: 'writes an uploaded file into one table through the app’s typed handle; deferred (plan 101 U6) on the same refusal exportRows waits for',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
factory: 'ledger',
|
|
53
|
+
none: 'the attempt table a webhook() delivery writes, declared once beside that webhook — it has no meaning without one, so it ships with it',
|
|
54
|
+
},
|
|
55
|
+
{ factory: 'llm', none: MODEL },
|
|
56
|
+
{
|
|
57
|
+
factory: 'mcpConfirmations',
|
|
58
|
+
none: 'the MCP server’s own confirmation actions: an app lists the value @ultimat3/mcp returns in defineApi, and has no body of its own to write',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
factory: 'notifier',
|
|
62
|
+
none: 'fans a notification out over the channels the app configures — mail, push, in-app — and which channels exist is the app’s configuration, not a template',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
factory: 'partitions',
|
|
66
|
+
none: 'keeps a partitioned table’s partitions ahead of time, and only a table the schema declares partitioned has any; x db gen writes that declaration',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
factory: 'pdf',
|
|
70
|
+
none: 'renders a page the app serves into a document; the page and its route are the declaration, and x g route writes the route',
|
|
71
|
+
},
|
|
72
|
+
{ factory: 'purge', generator: 'purge' },
|
|
73
|
+
{
|
|
74
|
+
factory: 'pushRegister',
|
|
75
|
+
none: 'a framework action over the device registrations @ultimat3/notify stores; an app lists it in defineApi and writes no body',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
factory: 'pushSubscribe',
|
|
79
|
+
none: 'a framework action over the Web Push subscriptions @ultimat3/pwa stores; an app lists it in defineApi and writes no body',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
factory: 'pushUnregister',
|
|
83
|
+
none: 'the other half of pushRegister: a framework action an app lists in defineApi, with no body of its own',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
factory: 'pushUnsubscribe',
|
|
87
|
+
none: 'the other half of pushSubscribe: a framework action an app lists in defineApi, with no body of its own',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
factory: 'refreshView',
|
|
91
|
+
none: 'refreshes a materialized view the schema declares; with no view there is nothing to refresh, and the view is a migration, not a template',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
factory: 'reindex',
|
|
95
|
+
none: 'rebuilds an index the schema declares, concurrently; which index bloats is a measurement on a live database, never a scaffold',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
factory: 'rollup',
|
|
99
|
+
none: 'counts a source table into a destination entity by bucket; deferred (plan 101 U6) until x g plants the destination entity and its migration beside it',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
factory: 'scrape',
|
|
103
|
+
none: 'fetches pages the app names and extracts what the app wants from them; the target and the extraction are the whole declaration',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
factory: 'subjectErase',
|
|
107
|
+
none: 'erases one data subject across every table that holds one, which the app declares per entity — the coverage x verify holds is that declaration',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
factory: 'subjectExport',
|
|
111
|
+
none: 'exports one data subject across the same declared tables subjectErase reads; one declaration per app, written beside the entities',
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
factory: 'transition',
|
|
115
|
+
none: 'declares the edges of an entity’s own status column — which states exist is the app’s business convention; x g mutator writes the mutator shape it returns',
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
factory: 'uploadFlow',
|
|
119
|
+
none: 'a request and a confirm action over the app’s storage bucket and the row an upload attaches to — both the app’s, and neither on the disk x g reads',
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
factory: 'webhook',
|
|
123
|
+
none: 'one signed delivery to an endpoint the app stores, with its ledger; deferred (plan 101 U6) until x g plants the endpoint table and the ledger it needs',
|
|
124
|
+
},
|
|
125
|
+
{ factory: 'webhookReceiver', generator: 'webhook-receiver' },
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
/** `x g llm` or `x g agent-job`: the factory a word names, when it is one no generator writes. */
|
|
129
|
+
export function factoryWithoutGenerator(raw: string): NotGenerated | undefined {
|
|
130
|
+
const camel = raw.replaceAll(/-([a-z])/g, (_match, letter: string) => letter.toUpperCase());
|
|
131
|
+
const row = FACTORY_GENERATORS.find((entry) => entry.factory === camel);
|
|
132
|
+
return row !== undefined && 'none' in row ? row : undefined;
|
|
133
|
+
}
|
package/src/generate-files.ts
CHANGED
|
@@ -28,6 +28,9 @@ import {
|
|
|
28
28
|
taskFiles,
|
|
29
29
|
} from './templates';
|
|
30
30
|
import { adminCatalogFiles } from './templates/admin-catalog';
|
|
31
|
+
import { cronJobFiles } from './templates/generate-cron-job';
|
|
32
|
+
import { purgeFiles } from './templates/generate-purge';
|
|
33
|
+
import { webhookReceiverFiles } from './templates/generate-webhook-receiver';
|
|
31
34
|
import { helmMonitoringFiles } from './templates/scaffold-helm-alerts';
|
|
32
35
|
import { oidcSignInFiles } from './templates/sign-in-oidc';
|
|
33
36
|
import { passwordSignInFiles } from './templates/sign-in-password';
|
|
@@ -195,6 +198,14 @@ export function generate(options: GenerateOptions): readonly GeneratedFile[] {
|
|
|
195
198
|
...(options.sliceRepo === undefined ? {} : { sliceRepo: options.sliceRepo }),
|
|
196
199
|
}),
|
|
197
200
|
);
|
|
201
|
+
// A primitive factory's one call, in the feature's slice. None reads the slice: each declares
|
|
202
|
+
// no table of its own, so it compiles in a feature that has no entity yet.
|
|
203
|
+
case 'cron-job':
|
|
204
|
+
return dedupe(cronJobFiles(options.name, target));
|
|
205
|
+
case 'purge':
|
|
206
|
+
return dedupe(purgeFiles(options.name, target));
|
|
207
|
+
case 'webhook-receiver':
|
|
208
|
+
return dedupe(webhookReceiverFiles(options.name, target));
|
|
198
209
|
case 'entity':
|
|
199
210
|
// With the labels the admin reads for it: the entity is an admin screen once it is in the
|
|
200
211
|
// handle, whether or not a resource was generated around it.
|
package/src/generate-kinds.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
MissingSubcommandError,
|
|
10
10
|
UnknownCommandError,
|
|
11
11
|
} from './errors';
|
|
12
|
+
import { factoryWithoutGenerator } from './generate-factories';
|
|
12
13
|
import { quoteArg } from './shell-quote';
|
|
13
14
|
import type { Surface } from './templates';
|
|
14
15
|
import { camel, kebab } from './templates/naming';
|
|
@@ -18,6 +19,11 @@ export const GENERATORS = [
|
|
|
18
19
|
'action',
|
|
19
20
|
'mutator',
|
|
20
21
|
'backfill',
|
|
22
|
+
// Three primitive factories, each its one call in the feature's `jobs/`. Which factories have a
|
|
23
|
+
// generator, and why the rest have none, is `FACTORY_GENERATORS` (`generate-factories.ts`).
|
|
24
|
+
'cron-job',
|
|
25
|
+
'purge',
|
|
26
|
+
'webhook-receiver',
|
|
21
27
|
'job',
|
|
22
28
|
'route',
|
|
23
29
|
'policy',
|
|
@@ -102,12 +108,16 @@ export function readKind(raw: string | undefined): Generator {
|
|
|
102
108
|
// deliberately never asked about an absent word, since the empty string is within `job`'s
|
|
103
109
|
// cutoff and would "suggest" a generator nobody typed.
|
|
104
110
|
if (raw === undefined) throw new MissingSubcommandError({ command: 'g', known: GENERATORS });
|
|
111
|
+
const decided = factoryWithoutGenerator(raw);
|
|
105
112
|
const near = nearestName(raw, kinds);
|
|
106
113
|
const suggestion = GENERATORS.find((kind) => kind === near);
|
|
107
114
|
throw new UnknownCommandError({
|
|
108
115
|
path: `g ${raw}`.trim(),
|
|
109
116
|
known: GENERATORS,
|
|
110
117
|
suggestion: suggestion === undefined ? 'help g' : `g ${suggestion} ${EXAMPLE_NAME[suggestion]}`,
|
|
118
|
+
...(decided === undefined
|
|
119
|
+
? {}
|
|
120
|
+
: { why: `${decided.factory}() has no generator: ${decided.none}` }),
|
|
111
121
|
});
|
|
112
122
|
}
|
|
113
123
|
|
|
@@ -275,6 +285,9 @@ const EXAMPLE_NAME: Readonly<Record<Generator, string>> = {
|
|
|
275
285
|
action: 'publish-post',
|
|
276
286
|
mutator: 'rename-post',
|
|
277
287
|
backfill: 'backfill-slugs',
|
|
288
|
+
'cron-job': 'nightly-report',
|
|
289
|
+
purge: 'purge-retained',
|
|
290
|
+
'webhook-receiver': 'billing-events',
|
|
278
291
|
job: 'send-digest',
|
|
279
292
|
route: 'posts',
|
|
280
293
|
policy: 'post',
|
package/src/mcp-db-target.ts
CHANGED
|
@@ -27,7 +27,7 @@ import { safeUrlLabel } from './safe-url-label';
|
|
|
27
27
|
*/
|
|
28
28
|
export function databaseTarget(services: DevServices, env: Env): DatabaseTarget {
|
|
29
29
|
const url = services.db.url;
|
|
30
|
-
const production =
|
|
30
|
+
const production = readsAsProduction(env);
|
|
31
31
|
return services.db.mode === 'embedded'
|
|
32
32
|
? { label: url, branch: pgliteBranch(url, services.stateDir), production }
|
|
33
33
|
: {
|
|
@@ -46,9 +46,10 @@ export function databaseTarget(services: DevServices, env: Env): DatabaseTarget
|
|
|
46
46
|
* `undefined` is answered **true**, and that is the whole point of using it here. It means exactly
|
|
47
47
|
* one thing: `ULTIMATE_ENV` is set to something that is not an environment. Reading a typo as "not
|
|
48
48
|
* production" would let the single misconfiguration this guard exists to survive defeat it — so an
|
|
49
|
-
* environment that cannot be read is treated as the most dangerous one it could be.
|
|
49
|
+
* environment that cannot be read is treated as the most dangerous one it could be. `x explain` and
|
|
50
|
+
* `x token` ask the same question through this one reader (`cmd-explain.ts`, `cmd-token.ts`).
|
|
50
51
|
*/
|
|
51
|
-
const
|
|
52
|
+
export const readsAsProduction = (env: Env): boolean => {
|
|
52
53
|
const environment = tryResolveEnvironment({ env });
|
|
53
54
|
return environment === undefined || environment === 'production';
|
|
54
55
|
};
|
package/src/mcp-errors.ts
CHANGED
|
@@ -394,6 +394,10 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
394
394
|
'x doctor --json # its X_VERIFY_STEP_UNFLOORED fix names the steps: run that x verify --only, then add each step that passed, not skipped, to "steps" in x.verify.json',
|
|
395
395
|
X_DB_ROW_SECURITY_OFF:
|
|
396
396
|
'database: { rowSecurity: true } # in defineConfig, app.config.ts; then: x db gen "row security" --json && x db migrate --json && x doctor --json',
|
|
397
|
+
X_DEV_DATA_UNOPENABLE:
|
|
398
|
+
'x db migrate --json # the fresh database has no tables yet; then x db seed --json if the app declares a seed. The moved directory (meta.aside) is kept: delete it once its rows are not needed',
|
|
399
|
+
X_EXPLAIN_PRODUCTION_DATABASE:
|
|
400
|
+
'env -u DATABASE_URL x queries list --json # then the same prefix on x explain <query> --json: it plans on the embedded dev database; for a copy of production data, point DATABASE_URL at a staging restore with ULTIMATE_ENV=staging',
|
|
397
401
|
};
|
|
398
402
|
|
|
399
403
|
const isCliCode = (code: string): code is CliErrorCode =>
|
package/src/messages-gate.ts
CHANGED
|
@@ -73,6 +73,8 @@ export const GATE_MESSAGES = {
|
|
|
73
73
|
'cli.verify.notAGateRun': 'NOT A GATE RUN — {summary}',
|
|
74
74
|
'cli.verify.pass': 'all {count} steps passed in {ms}ms',
|
|
75
75
|
'cli.verify.fail': '{failed} of {count} steps failed',
|
|
76
|
+
'cli.verify.plan':
|
|
77
|
+
'the gate in {parts} part(s) over {steps} steps — the CI matrix is data.matrix',
|
|
76
78
|
// The budgets step built before it weighed (`verify-budgets-build.ts`): which stats state made it.
|
|
77
79
|
'cli.verify.budgets.built':
|
|
78
80
|
'built first: build stats were {state} — x build --target static --out {out} ({ms}ms)',
|