@ultimat3/cli 31.5.0 → 31.6.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/CLAUDE.md +14 -7
- package/package.json +29 -29
- package/src/admin-catalog-keys.ts +17 -1
- package/src/app-transport.ts +7 -3
- package/src/browser-barrel-cut.ts +109 -0
- package/src/browser-import-chain.ts +119 -0
- package/src/browser-transport.ts +85 -13
- package/src/cmd-dev.ts +15 -2
- package/src/cmd-fix.ts +14 -4
- package/src/cmd-i18n.ts +52 -10
- package/src/dev-boot.ts +6 -4
- package/src/dev-log.ts +95 -0
- package/src/dev-rebuild-remount.ts +152 -0
- package/src/dev-rebuild-schema.ts +30 -0
- package/src/dev-rebuild.ts +51 -14
- package/src/dev-supervisor.ts +5 -4
- package/src/error-codes.ts +2 -0
- package/src/error-contract.ts +29 -2
- package/src/fix-sequence.ts +97 -0
- package/src/generate-grant-findings.ts +2 -2
- package/src/generate-grants.ts +50 -1
- package/src/generate-write.ts +16 -0
- package/src/i18n-registration.ts +8 -5
- package/src/load-findings.ts +29 -22
- package/src/mcp-errors.ts +11 -3
- package/src/mcp-host-shell.ts +128 -0
- package/src/mcp-host.ts +19 -54
- package/src/mcp-test-output.ts +5 -2
- package/src/messages-gate.ts +12 -0
- package/src/messages.ts +16 -0
- package/src/policy-append.ts +88 -0
- package/src/templates/entity.ts +18 -3
- package/src/templates/policy.ts +5 -1
- package/src/templates/query.ts +4 -2
- package/src/templates/resource-service.ts +5 -2
- package/src/templates/scaffold-repo.ts +8 -2
- package/src/ts-scan.ts +86 -1
- package/src/verify-checks.ts +23 -51
- package/src/verify-contract-diff.ts +143 -0
- package/src/verify-seeds.ts +132 -0
- package/src/verify-tests.ts +12 -6
- package/wiki/CLI-Reference.md +2 -2
- package/wiki/Upgrading.md +3 -0
package/src/error-contract.ts
CHANGED
|
@@ -112,25 +112,52 @@ export interface ErrorFixReport {
|
|
|
112
112
|
* relative specifiers only, and that gap is 3 call sites across this repo, measured 2026-08.
|
|
113
113
|
*/
|
|
114
114
|
readonly unreadable: number;
|
|
115
|
+
/** File → fix lines `fix-sequence.ts` refused there, allowed or not: what the baseline must equal. */
|
|
116
|
+
readonly sequenceRefused: ReadonlyMap<string, number>;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* `fix-sequence.ts`'s rule, ratcheted per file: a file at or under its recorded count passes, and
|
|
121
|
+
* past it every refused line is reported — a text scan cannot tell which of them is the new one.
|
|
122
|
+
*/
|
|
123
|
+
function sequenceRefusals(
|
|
124
|
+
sites: readonly FixSite[],
|
|
125
|
+
fixSequenceProblem: (fix: string) => string | undefined,
|
|
126
|
+
): readonly Finding[] {
|
|
127
|
+
return sites.flatMap((site) => {
|
|
128
|
+
const problem = fixSequenceProblem(staticFix(site.fix));
|
|
129
|
+
return problem === undefined ? [] : [fixFinding(site, problem)];
|
|
130
|
+
});
|
|
115
131
|
}
|
|
116
132
|
|
|
117
133
|
export async function checkErrorFixReport(root: string): Promise<ErrorFixReport> {
|
|
118
134
|
const findings: Finding[] = [];
|
|
119
135
|
const catalog = await loadCommandCatalog();
|
|
136
|
+
// At its point of use, like the catalog: `app-load.ts` imports this module for
|
|
137
|
+
// `collectDeclaredCodes`, and a gate-only rule must not ride into every serving role's graph
|
|
138
|
+
// (`serve-graph.test.ts`'s `SERVING_ROLE_CEILING`).
|
|
139
|
+
const { FIX_SEQUENCE_BASELINE, fixSequenceProblem, generatorForceProblem } = await import(
|
|
140
|
+
'./fix-sequence'
|
|
141
|
+
);
|
|
120
142
|
const imports = createHelperResolver(root);
|
|
121
143
|
let checked = 0;
|
|
122
144
|
let unreadable = 0;
|
|
145
|
+
const sequenceRefused = new Map<string, number>();
|
|
123
146
|
for await (const path of eachSourceFile(root)) {
|
|
124
147
|
if (isTest(path) || isGenerated(path)) continue;
|
|
125
148
|
const source = await Bun.file(join(root, path)).text();
|
|
126
149
|
const scan = scanFixSites(source, path, await imports(path, source));
|
|
127
150
|
checked += scan.sites.length;
|
|
128
151
|
unreadable += scan.unreadable;
|
|
152
|
+
const refused = sequenceRefusals(scan.sites, fixSequenceProblem);
|
|
153
|
+
if (refused.length > 0) sequenceRefused.set(path, refused.length);
|
|
154
|
+
if (refused.length > (FIX_SEQUENCE_BASELINE.get(path) ?? 0)) findings.push(...refused);
|
|
129
155
|
for (const site of scan.sites) {
|
|
130
156
|
// The interpolation-blanked form for both rules: `x ${name}` names no command this can
|
|
131
157
|
// resolve, and reading `<value>` as one would be a finding nobody can act on.
|
|
132
158
|
const fix = staticFix(site.fix);
|
|
133
|
-
const problem =
|
|
159
|
+
const problem =
|
|
160
|
+
fixProblem(site.fix) ?? generatorForceProblem(fix) ?? citedCommandProblem(fix, catalog);
|
|
134
161
|
if (problem !== undefined) {
|
|
135
162
|
findings.push(fixFinding(site, problem));
|
|
136
163
|
continue;
|
|
@@ -141,7 +168,7 @@ export async function checkErrorFixReport(root: string): Promise<ErrorFixReport>
|
|
|
141
168
|
if (missing !== undefined) findings.push(pathFinding(site, missing));
|
|
142
169
|
}
|
|
143
170
|
}
|
|
144
|
-
return { findings, checked, unreadable };
|
|
171
|
+
return { findings, checked, unreadable, sequenceRefused };
|
|
145
172
|
}
|
|
146
173
|
|
|
147
174
|
/** The findings alone, for every caller that reports no coverage line. */
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// The order rule on a `fix:` line, for the `errors` step: the edit leads, the re-run follows —
|
|
2
|
+
// `x verify # after deleting .sensitive()` is pasted before it is read, and re-runs unchanged.
|
|
3
|
+
// Shipped lines are ratcheted per file in `FIX_SEQUENCE_BASELINE`; a new one is
|
|
4
|
+
// `X_ERROR_FIX_INVALID`. A generator offered with `--force` is never a fix (none shipped 2026-11).
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A comment opening with the precondition, in its deferred-edit form only: `<command> # after
|
|
8
|
+
* editing …` (a gerund, a call, or an interpolated edit) or `# once … is repaired` (a past
|
|
9
|
+
* participle). A `#` glued to a word is a URL fragment (`…/Upgrading#after-31`), and `# once per
|
|
10
|
+
* environment` / `# once, at boot` is a frequency — neither is refused.
|
|
11
|
+
*/
|
|
12
|
+
const DEFERRED_EDIT =
|
|
13
|
+
/(?:^|\s)#\s+(?:(after)\s+(?:\w+ing\b|[\w.$]+\(|<value>)|(once)\s+(?!(?:per|only|a|an|each|every|more)\b)[^#,]*?\b\w+ed\b)/i;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A line whose whole instruction is to run the failing command again: an optional "fix the
|
|
17
|
+
* failure / cause / error, then", the re-run, and nothing it names to change.
|
|
18
|
+
*/
|
|
19
|
+
const RERUN_ONLY =
|
|
20
|
+
/^\s*(?:(?:fix|resolve|address|correct|repair)\b[^,.;#]*\b(?:cause|failure|error|problem)\b[^,.;#]*[,;]?\s*(?:then|and)\s+)?(?:re-?run|retry|run (?:it |this )?again)(?:\s+(?:it|this|the command|this command))?\s*\.?\s*$/i;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The rule, on one fix line — already `staticFix`ed by the caller, as every rule of the step reads
|
|
24
|
+
* it. `undefined` means the line leads with what to change.
|
|
25
|
+
*/
|
|
26
|
+
export function fixSequenceProblem(fix: string): string | undefined {
|
|
27
|
+
const deferred = DEFERRED_EDIT.exec(fix);
|
|
28
|
+
if (deferred !== null) {
|
|
29
|
+
return `fix "${fix}" opens with the command and defers the edit to "# ${deferred[1] ?? deferred[2]} …", so the line pasted first re-runs the failure unchanged — lead with the edit, then the command`;
|
|
30
|
+
}
|
|
31
|
+
if (RERUN_ONLY.test(fix)) {
|
|
32
|
+
return `fix "${fix}" only says to re-run, and names no edit, call or file that would make the re-run pass`;
|
|
33
|
+
}
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** `x g …` / `x generate …` carrying `--force`, before any `#` comment: the part that is pasted. */
|
|
38
|
+
const FORCED_GENERATOR = /(?:^|[\s;|&(])x\s+(?:g|generate)\b[^#]*?\s--force(?![\w-])/;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A printed fix is pasted with no diff in front of it, and a generator's file can be shared — a
|
|
42
|
+
* slice's `policy.ts` holds every permission its generators wrote, and `x g policy … --force`
|
|
43
|
+
* replaced the first with the second (FX2). Prose behind the `#` is not pasted, so it is not read.
|
|
44
|
+
*/
|
|
45
|
+
export function generatorForceProblem(fix: string): string | undefined {
|
|
46
|
+
const runnable = fix.split(/\s#\s/)[0] ?? '';
|
|
47
|
+
if (!FORCED_GENERATOR.test(runnable)) return undefined;
|
|
48
|
+
return `fix "${fix}" runs a generator with --force, which overwrites a file other slices or generators may share, and a pasted fix shows no diff first — name the edit to the existing file instead`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Root-relative file → how many fix lines in it the rule above refuses: 53 lines in 38 files across
|
|
53
|
+
* this repo and its three tracked apps, measured 2026-11-11 (the docs site's
|
|
54
|
+
* `packages/docs-source/src/errors.ts` is the one app entry). A file at or under its count passes;
|
|
55
|
+
* one past it, or any file not listed — every app's — is a finding at each of its refused lines.
|
|
56
|
+
* Held EQUAL to the step's counts by `fix-sequence.test.ts`: rewrite a line, lower its entry.
|
|
57
|
+
*/
|
|
58
|
+
export const FIX_SEQUENCE_BASELINE: ReadonlyMap<string, number> = new Map([
|
|
59
|
+
['packages/cli/src/cmd-client-customer.ts', 1],
|
|
60
|
+
['packages/cli/src/cmd-deploy-preflight.ts', 1],
|
|
61
|
+
['packages/cli/src/cmd-env-init.ts', 1],
|
|
62
|
+
['packages/cli/src/handle-registration.ts', 1],
|
|
63
|
+
['packages/cli/src/job-registration.ts', 1],
|
|
64
|
+
['packages/cli/src/package-boundaries.ts', 1],
|
|
65
|
+
['packages/cli/src/upgrade-plan.ts', 1],
|
|
66
|
+
['packages/cli/src/verify-drift-owner.ts', 1],
|
|
67
|
+
['packages/core/src/define-error.ts', 1],
|
|
68
|
+
['packages/core/src/errors.ts', 1],
|
|
69
|
+
['packages/db/src/drift-triggers.ts', 1],
|
|
70
|
+
['packages/db/src/generate-partition.ts', 2],
|
|
71
|
+
['packages/db/src/lifecycle-errors.ts', 1],
|
|
72
|
+
['packages/db/src/primary-key.ts', 1],
|
|
73
|
+
['packages/docs-source/src/errors.ts', 4],
|
|
74
|
+
['packages/entity/src/counter.ts', 1],
|
|
75
|
+
['packages/entity/src/partition.ts', 1],
|
|
76
|
+
['packages/entity/src/retain.ts', 1],
|
|
77
|
+
['packages/jobs/src/subject-errors.ts', 1],
|
|
78
|
+
['packages/mail/src/preview-check.ts', 1],
|
|
79
|
+
['packages/mcp/src/meta-errors.ts', 1],
|
|
80
|
+
['packages/mcp/src/remote-errors.ts', 1],
|
|
81
|
+
['packages/schema/src/sensitive.ts', 1],
|
|
82
|
+
['packages/seo/src/errors.ts', 1],
|
|
83
|
+
['packages/testing/src/exercise-override-input.ts', 1],
|
|
84
|
+
['packages/testing/src/plan-sweep-report.ts', 4],
|
|
85
|
+
['scripts/adapter-ports.ts', 4],
|
|
86
|
+
['scripts/bench-claims.ts', 1],
|
|
87
|
+
['scripts/budget-raises.ts', 1],
|
|
88
|
+
['scripts/declaration-readers-callers.ts', 2],
|
|
89
|
+
['scripts/factory-names.ts', 2],
|
|
90
|
+
['scripts/instrument-slots.ts', 1],
|
|
91
|
+
['scripts/lib/export-all.ts', 1],
|
|
92
|
+
['scripts/new-error-code.ts', 1],
|
|
93
|
+
['scripts/plan-status.ts', 3],
|
|
94
|
+
['scripts/posix-relative.ts', 1],
|
|
95
|
+
['scripts/set-cookie-literals.ts', 2],
|
|
96
|
+
['scripts/sql-export-readers.ts', 1],
|
|
97
|
+
]);
|
|
@@ -8,9 +8,9 @@ import { appDisk } from './generate-disk';
|
|
|
8
8
|
import type { RoleGrant } from './generate-grants';
|
|
9
9
|
import {
|
|
10
10
|
adminGrantsFor,
|
|
11
|
-
grantsForWritten,
|
|
12
11
|
insertGrants,
|
|
13
12
|
insertPermissions,
|
|
13
|
+
policyGrantsFor,
|
|
14
14
|
writtenTables,
|
|
15
15
|
} from './generate-grants';
|
|
16
16
|
import type { Finding } from './output';
|
|
@@ -49,7 +49,7 @@ export async function ungrantedByGenerator(
|
|
|
49
49
|
disk: GenerateDisk = appDisk(root),
|
|
50
50
|
): Promise<readonly Finding[]> {
|
|
51
51
|
const admin = (await writtenTables(root, written, disk)).flatMap(adminGrantsFor);
|
|
52
|
-
const grants = [...
|
|
52
|
+
const grants = [...(await policyGrantsFor(root, written, disk)), ...admin];
|
|
53
53
|
if (grants.length === 0) return [];
|
|
54
54
|
const source = await disk.read(ROLES_FILE);
|
|
55
55
|
// The file whose declarations nobody granted: where a reader starts when the map is not ours.
|
package/src/generate-grants.ts
CHANGED
|
@@ -39,6 +39,55 @@ export function grantsForWritten(written: readonly string[]): readonly RoleGrant
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/** `member` reads, `admin` does everything else — `grantsForWritten`'s rule, per permission. */
|
|
43
|
+
const grantFor = (permission: string): RoleGrant => ({
|
|
44
|
+
role: permission.endsWith(':read') ? 'member' : 'admin',
|
|
45
|
+
permission,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/** The string literals of the `definePermissions([...])` list opening at `open`. */
|
|
49
|
+
const literalsAt = (source: string, masked: string, open: number): readonly string[] =>
|
|
50
|
+
(readList(source, masked, open)?.entries ?? []).flatMap((entry) => {
|
|
51
|
+
const literal = /^'([^']+)'$/.exec(entry.text.trim())?.[1];
|
|
52
|
+
return literal === undefined ? [] : [literal];
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/** Every permission a policy's `definePermissions([...])` calls declare, comments masked. */
|
|
56
|
+
export function declaredPermissions(source: string): readonly string[] {
|
|
57
|
+
const masked = maskOf(source);
|
|
58
|
+
return declarationLists(masked).flatMap((open) => literalsAt(source, masked, open));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The set a generator run WROTE into a policy: its LAST `definePermissions([...])` call. A fresh
|
|
63
|
+
* file holds one call, the template's; an append (`policy-append.ts`) puts its set after
|
|
64
|
+
* everything the author had. Never every declared permission: a hand-placed admin-only
|
|
65
|
+
* `payroll:read` earlier in the file would be granted to `member` by the next `x g policy`.
|
|
66
|
+
*/
|
|
67
|
+
export function introducedPermissions(source: string): readonly string[] {
|
|
68
|
+
const masked = maskOf(source);
|
|
69
|
+
const last = declarationLists(masked).at(-1);
|
|
70
|
+
return last === undefined ? [] : literalsAt(source, masked, last);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The grants the written policies imply: the set each run introduced, read off the file as it now
|
|
75
|
+
* stands — or, a file this cannot read a declaration from, the slice-path rule of
|
|
76
|
+
* `grantsForWritten`.
|
|
77
|
+
*/
|
|
78
|
+
export async function policyGrantsFor(
|
|
79
|
+
root: string,
|
|
80
|
+
written: readonly string[],
|
|
81
|
+
disk: GenerateDisk = appDisk(root),
|
|
82
|
+
): Promise<readonly RoleGrant[]> {
|
|
83
|
+
const grants: RoleGrant[] = [];
|
|
84
|
+
for (const path of written.filter((each) => POLICY_PATH.test(each))) {
|
|
85
|
+
const introduced = introducedPermissions((await disk.read(path)) ?? '');
|
|
86
|
+
grants.push(...(introduced.length > 0 ? introduced.map(grantFor) : grantsForWritten([path])));
|
|
87
|
+
}
|
|
88
|
+
return grants;
|
|
89
|
+
}
|
|
90
|
+
|
|
42
91
|
/** `entity('widgets', {` — the name the admin's permissions are spelled with. */
|
|
43
92
|
const ENTITY_NAME = /\bentity\(\s*'([^']+)'/;
|
|
44
93
|
|
|
@@ -166,7 +215,7 @@ export async function grantGeneratedPermissions(
|
|
|
166
215
|
disk: GenerateDisk = appDisk(root),
|
|
167
216
|
): Promise<readonly string[]> {
|
|
168
217
|
const admin = (await writtenTables(root, written, disk)).flatMap(adminGrantsFor);
|
|
169
|
-
const grants = [...
|
|
218
|
+
const grants = [...(await policyGrantsFor(root, written, disk)), ...admin];
|
|
170
219
|
const before = grants.length === 0 ? undefined : await disk.read(ROLES_FILE);
|
|
171
220
|
if (before === undefined) return [];
|
|
172
221
|
const unplaced = insertGrants(before, grants).skipped;
|
package/src/generate-write.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { commentSafe } from './comment-safe';
|
|
|
13
13
|
import { GenerateJsonInvalidError, ScaffoldPathEscapeError } from './errors';
|
|
14
14
|
import { mergeJsonDeep, mergeJsonInPlace, sortJsonDeep } from './json-merge';
|
|
15
15
|
import type { Finding } from './output';
|
|
16
|
+
import { appendPolicy } from './policy-append';
|
|
16
17
|
import { quoteArg } from './shell-quote';
|
|
17
18
|
import type { GeneratedFile } from './templates';
|
|
18
19
|
|
|
@@ -188,6 +189,12 @@ const conflictFix = (
|
|
|
188
189
|
return `${invocation} --force # overwrites ${path}, or pass a different name`;
|
|
189
190
|
const into = `--feature ${quoteArg(slice)}`;
|
|
190
191
|
const named = quoteArg(name);
|
|
192
|
+
// `x g policy` on a slice that already declares this very set: an action is the wrong kind and
|
|
193
|
+
// `--force` deletes every other rule in the file. A second set under its own name APPENDS.
|
|
194
|
+
const head = /^(?<head>.*? g) policy /.exec(invocation)?.groups?.['head'];
|
|
195
|
+
if (module === 'policy.ts' && head !== undefined) {
|
|
196
|
+
return `${head} policy ${quoteArg(`${name}-admin`)} ${into} # appends a second permission set: ${commentSafe(path)} already exports ${commentSafe(name)}'s`;
|
|
197
|
+
}
|
|
191
198
|
// A read needs the slice's table (X_FEATURE_REQUIRED), so it is offered only beside one.
|
|
192
199
|
const read = existsSync(join(dirname(absolute), 'entity.ts'))
|
|
193
200
|
? `or x g query ${named} ${into}`
|
|
@@ -212,6 +219,15 @@ function planFile(
|
|
|
212
219
|
? { kind: 'skip' }
|
|
213
220
|
: { kind: 'write', file, absolute, contents: file.contents };
|
|
214
221
|
}
|
|
222
|
+
// A slice's `policy.ts` holds every primitive's rules: a second permission set is appended to it,
|
|
223
|
+
// `--force` included — overwriting it would delete the rules already there. The same set again
|
|
224
|
+
// does not merge (`appendPolicy` answers undefined) and is the conflict below.
|
|
225
|
+
if (file.merge === undefined && typeof file.contents === 'string' && existsSync(absolute)) {
|
|
226
|
+
const merged = file.path.endsWith('/policy.ts')
|
|
227
|
+
? appendPolicy(readFileSync(absolute, 'utf8'), file.contents)
|
|
228
|
+
: undefined;
|
|
229
|
+
if (merged !== undefined) return { kind: 'write', file, absolute, contents: merged };
|
|
230
|
+
}
|
|
215
231
|
// The scaffold's own copy, untouched, is replaced without asking; an edited one is the author's.
|
|
216
232
|
if (file.merge === 'replaces-pristine' && existsSync(absolute)) {
|
|
217
233
|
if (readFileSync(absolute, 'utf8') === file.pristine) {
|
package/src/i18n-registration.ts
CHANGED
|
@@ -156,14 +156,18 @@ export async function checkRegistration(input: RegistrationInput): Promise<Regis
|
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
/**
|
|
160
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Keys the catalog does not define, or defines with a placeholder. Labels are never plurals.
|
|
161
|
+
* Exported because `x i18n sync` writes exactly this set and `x i18n check` counts it: one rule.
|
|
162
|
+
*/
|
|
163
|
+
export const unanswered = (catalog: Catalog, keys: readonly string[]): readonly string[] =>
|
|
161
164
|
keys.filter((key) => !Object.hasOwn(catalog, key) || isLoudMiss(catalog[key]));
|
|
162
165
|
|
|
163
166
|
/**
|
|
164
167
|
* `X_CATALOG_MISSING_KEYS` — the same fact, a catalog without keys it is asked for — with the
|
|
165
|
-
* cause naming who asks
|
|
166
|
-
*
|
|
168
|
+
* cause naming who asks. The fix stays the code's own, `x i18n sync <locale>`: it writes these keys
|
|
169
|
+
* too (`cmd-i18n.ts`), nested. The hand edit this used to name was a dotted key, which
|
|
170
|
+
* `loadCatalog` refuses as `X_CATALOG_INVALID`.
|
|
167
171
|
*/
|
|
168
172
|
function adminKeysFinding(locale: Locale, missing: readonly string[]): Finding {
|
|
169
173
|
const path = catalogPath(locale);
|
|
@@ -172,7 +176,6 @@ function adminKeysFinding(locale: Locale, missing: readonly string[]): Finding {
|
|
|
172
176
|
return {
|
|
173
177
|
...findingFrom(catalogMissingKeys(locale, missing)),
|
|
174
178
|
cause: `${path} is missing ${missing.length} key(s) the mounted admin renders (defineAdmin derives them, so no source file names one): ${shown.join(', ')}${more}`,
|
|
175
|
-
fix: `add to ${path}, each with its real label: ${shown.join(', ')}${more} — then x i18n check --json`,
|
|
176
179
|
at: path,
|
|
177
180
|
};
|
|
178
181
|
}
|
package/src/load-findings.ts
CHANGED
|
@@ -1,41 +1,48 @@
|
|
|
1
|
-
// One cause, one
|
|
2
|
-
//
|
|
3
|
-
// findings
|
|
4
|
-
//
|
|
5
|
-
//
|
|
1
|
+
// One cause, one finding. A module that will not import leaves every registry half-filled, and each
|
|
2
|
+
// step that loaded the app reported what half a registry looks like — a permission typo read as 9
|
|
3
|
+
// findings across 7 steps (plan 101 19a FX8). The `manifest` step owns the load's findings: it runs
|
|
4
|
+
// in every repo, and "does the projection describe the code?" is the question a broken module
|
|
5
|
+
// answers first. Every other step that loads the app stands down while the load is red.
|
|
6
6
|
|
|
7
7
|
import { loadApp } from './app-load';
|
|
8
|
+
import { msg } from './messages';
|
|
8
9
|
import type { Finding } from './output';
|
|
9
|
-
import type {
|
|
10
|
+
import type { VerifyContext, VerifyStep, VerifyStepName } from './verify-step';
|
|
10
11
|
|
|
11
12
|
/** The step that reports the app's load failures. Every other step points at it. */
|
|
12
13
|
export const LOAD_OWNER: VerifyStepName = 'manifest';
|
|
13
14
|
|
|
15
|
+
/** What a dependent step says instead of running over a half-loaded registry. */
|
|
16
|
+
export const LOAD_BLOCKED = msg('cli.verify.loadBlocked', { owner: LOAD_OWNER });
|
|
17
|
+
|
|
14
18
|
/** What the app load reports, as the step sees it. */
|
|
15
19
|
export type LoadProbe = (root: string) => Promise<{ readonly findings: readonly Finding[] }>;
|
|
16
20
|
|
|
17
21
|
const keyOf = (finding: Finding): string =>
|
|
18
22
|
[finding.code, finding.at ?? '', finding.cause].join('\u0000');
|
|
19
23
|
|
|
24
|
+
/** Whether this run reports the owner step: the gate always does, `--only` when it names it. */
|
|
25
|
+
function ownerRuns(ctx: VerifyContext): boolean {
|
|
26
|
+
if (ctx.only === undefined) return true;
|
|
27
|
+
return typeof ctx.only === 'string' ? ctx.only === LOAD_OWNER : ctx.only.includes(LOAD_OWNER);
|
|
28
|
+
}
|
|
29
|
+
|
|
20
30
|
/**
|
|
21
|
-
* `
|
|
22
|
-
*
|
|
23
|
-
*
|
|
31
|
+
* `step`, standing down while the app's load has findings. A run that includes the owner gets one
|
|
32
|
+
* line saying where the cause went and no findings — the gate is red on `manifest` already. A
|
|
33
|
+
* narrowed run without the owner (`x verify --only budgets`) carries the load's findings itself:
|
|
34
|
+
* skipping there would be a green over an app that does not load.
|
|
24
35
|
*/
|
|
25
|
-
export
|
|
26
|
-
root: string,
|
|
27
|
-
findings: readonly Finding[],
|
|
28
|
-
load: LoadProbe = loadApp,
|
|
29
|
-
): Promise<StepOutcome> {
|
|
30
|
-
const loaded = new Set((await load(root)).findings.map(keyOf));
|
|
31
|
-
const kept = findings.filter((finding) => !loaded.has(keyOf(finding)));
|
|
32
|
-
const moved = findings.length - kept.length;
|
|
36
|
+
export function blockedByLoad(step: VerifyStep, load: LoadProbe = loadApp): VerifyStep {
|
|
33
37
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
...step,
|
|
39
|
+
async run(ctx) {
|
|
40
|
+
const { findings } = await load(ctx.root);
|
|
41
|
+
if (findings.length === 0) return step.run(ctx);
|
|
42
|
+
return ownerRuns(ctx)
|
|
43
|
+
? { ok: true, findings: [], output: LOAD_BLOCKED }
|
|
44
|
+
: { ok: false, findings, output: LOAD_BLOCKED };
|
|
45
|
+
},
|
|
39
46
|
};
|
|
40
47
|
}
|
|
41
48
|
|
package/src/mcp-errors.ts
CHANGED
|
@@ -143,7 +143,10 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
143
143
|
X_PORT_INVALID: 'docker run -e PORT=3000 my-app:latest',
|
|
144
144
|
X_RUNTIME_DRIVER_SPLIT:
|
|
145
145
|
'x dev --json # the boot names the driver; move it to `export const runtime = { jobs }` in apps/web/runtime.ts',
|
|
146
|
-
|
|
146
|
+
// `generate-write.ts`'s `conflictFix` shape, without the run's own name: list what the run would
|
|
147
|
+
// write, then a free name or the slice to add into — never `--force` over a file a slice shares.
|
|
148
|
+
X_GENERATE_CONFLICT:
|
|
149
|
+
'x g route posts --dry-run --json # lists each file the run would write; then the same command under a name no file holds, or x g query posts --feature posts to add into that slice',
|
|
147
150
|
X_APP_NAME_EMPTY:
|
|
148
151
|
'x new my-app --json # a name with letters or digits; it becomes the directory',
|
|
149
152
|
X_APP_EMPTY:
|
|
@@ -210,8 +213,10 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
210
213
|
// The finding's own `fix:` is this command plus the edit — the line, and what replaces the call.
|
|
211
214
|
X_BROWSER_TRANSPORT_BYPASS:
|
|
212
215
|
'x verify --only boundaries --json # each finding names the line and the transport to use instead',
|
|
216
|
+
// `x errors explain` holds no finding, so the runnable half is the step that prints one; that
|
|
217
|
+
// finding's own fix IS the edit, edit first (`fix-sequence.ts`): a swap, or a cut.
|
|
213
218
|
X_BROWSER_SERVER_BARREL:
|
|
214
|
-
'x verify --only boundaries --json # each finding
|
|
219
|
+
'x verify --only boundaries --json # each finding opens with its edit: the import swapped to the browser entry it names (@ultimat3/query/client for @ultimat3/query), or the cut where the island first reaches the barrel',
|
|
215
220
|
// `EDITOR=` inline rather than `export`: the variable is only needed for the one invocation, and
|
|
216
221
|
// an agent copying this line gets a working command instead of a shell it has to keep.
|
|
217
222
|
X_SECRETS_EDITOR_MISSING: 'EDITOR=nano x secrets edit',
|
|
@@ -374,6 +379,7 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
374
379
|
'x verify --only package-shape --json # each finding carries its own `bun add <package> --cwd <workspace>` line',
|
|
375
380
|
X_TYPESCRIPT_VERSION:
|
|
376
381
|
'x doctor --json # each X_TYPESCRIPT_VERSION finding names its manifest and the bun add that moves it',
|
|
382
|
+
X_SEED_FAILED: 'bun --eval \'await (await import("./packages/db/seeds/dev.ts")).dev.run()\'',
|
|
377
383
|
};
|
|
378
384
|
|
|
379
385
|
const isCliCode = (code: string): code is CliErrorCode =>
|
|
@@ -413,7 +419,9 @@ function projectedFix(code: string): string {
|
|
|
413
419
|
// with the same line, because it is the same condition seen from a second command.
|
|
414
420
|
return `bun install && x doctor --json # the installed @ultimat3 packages could not be read, so no throw site could be quoted for ${code}`;
|
|
415
421
|
}
|
|
416
|
-
|
|
422
|
+
// Not "nothing raises it": the scan reads literals and `*FIXES` table keys, and a code raised
|
|
423
|
+
// from a computed value is neither — that claim told the reader of a live error it was dead.
|
|
424
|
+
return `x errors list --json # no throw site in the installed framework spells ${code} as a literal or a *FIXES table key: it is raised from a computed value, and the raised error carries its own fix line`;
|
|
417
425
|
}
|
|
418
426
|
// Both notes name a thing this answer does NOT know, because an answer that hides either is one
|
|
419
427
|
// an agent acts on without noticing: which of several throw sites it is quoting, and which words
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// `tests.run` and `verify.run` as the shell runs them: `x test` and `x verify` themselves, through
|
|
2
|
+
// their own commands, with the environment the shell would have handed them. A second test path in
|
|
3
|
+
// the dev MCP server (a bare `bun test <filter>`) answered red for files `x test` ran green.
|
|
4
|
+
|
|
5
|
+
import { ENVIRONMENT_KEY } from '@ultimat3/core';
|
|
6
|
+
import type { TestRun, VerifyResult, VerifyStep } from '@ultimat3/mcp';
|
|
7
|
+
import { testCommand } from './cmd-test';
|
|
8
|
+
import { testSpec } from './cmd-test-spec';
|
|
9
|
+
import { verifyCommand } from './cmd-verify';
|
|
10
|
+
import { verifySpec } from './cmd-verify-spec';
|
|
11
|
+
import { BadFlagError } from './errors';
|
|
12
|
+
import type { ExecResult, Runner } from './exec';
|
|
13
|
+
import { testRunOf } from './mcp-test-run';
|
|
14
|
+
import { parseArgs } from './parse';
|
|
15
|
+
|
|
16
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
17
|
+
|
|
18
|
+
export interface ShellRunInput {
|
|
19
|
+
readonly root: string;
|
|
20
|
+
/** The host's environment — after `declareDevEnvironment` may have written to it. */
|
|
21
|
+
readonly env: Env;
|
|
22
|
+
readonly runner: Runner;
|
|
23
|
+
/**
|
|
24
|
+
* Whether THIS process declared `ULTIMATE_ENV=development` (`declareDevEnvironment`). A shell
|
|
25
|
+
* never has it, so neither may a child: inherited, it overrode the `NODE_ENV=test` every
|
|
26
|
+
* `bun test` sets, and the app's tests seeded and connected as development.
|
|
27
|
+
*/
|
|
28
|
+
readonly declared: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The env a shell would hand `x test`/`x verify`: the host's, less what the host declared. */
|
|
32
|
+
export const shellEnv = (input: ShellRunInput): Env =>
|
|
33
|
+
input.declared ? { ...input.env, [ENVIRONMENT_KEY]: undefined } : input.env;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Every child spawned with the declared key unset, unless the caller sets it itself. `exec.ts`
|
|
37
|
+
* overlays `options.env` onto `Bun.env`, the very object `declareDevEnvironment` wrote to, so
|
|
38
|
+
* handing the commands `shellEnv` alone would not reach their children.
|
|
39
|
+
*/
|
|
40
|
+
export function shellRunner(input: ShellRunInput): Runner {
|
|
41
|
+
if (!input.declared) return input.runner;
|
|
42
|
+
return (command, options) =>
|
|
43
|
+
input.runner(command, { ...options, env: { [ENVIRONMENT_KEY]: undefined, ...options.env } });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* `x test`'s argv for a `tests.run` filter. A filter is a path substring; one starting with `-`
|
|
48
|
+
* would be read as a flag of `x test`, so it is refused rather than forwarded.
|
|
49
|
+
*/
|
|
50
|
+
export function testRunArgs(filter: string | undefined): readonly string[] {
|
|
51
|
+
if (filter === undefined) return ['test'];
|
|
52
|
+
if (filter.trimStart().startsWith('-')) {
|
|
53
|
+
throw new BadFlagError({
|
|
54
|
+
flag: 'filter',
|
|
55
|
+
command: 'mcp serve',
|
|
56
|
+
reason: `test.run's filter "${filter}" starts with "-", which x test would read as its own flag`,
|
|
57
|
+
fix: 'call test.run with a path filter such as packages/cli/src, or with no filter',
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return ['test', '--filter', filter];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const isBunTest = (result: ExecResult): boolean =>
|
|
64
|
+
result.command[0] === 'bun' && result.command[1] === 'test';
|
|
65
|
+
|
|
66
|
+
/** Every `bun test` batch `x test` spawned, summed into the one answer the tool returns. */
|
|
67
|
+
export function sumRuns(results: readonly ExecResult[], durationMs: number): TestRun {
|
|
68
|
+
const runs = results.filter(isBunTest).map(testRunOf);
|
|
69
|
+
return {
|
|
70
|
+
passed: runs.reduce((sum, run) => sum + run.passed, 0),
|
|
71
|
+
failed: runs.reduce((sum, run) => sum + run.failed, 0),
|
|
72
|
+
skipped: runs.reduce((sum, run) => sum + run.skipped, 0),
|
|
73
|
+
durationMs,
|
|
74
|
+
failures: runs.flatMap((run) => run.failures),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** `tests.run`: `x test --filter <filter>`, with each batch's output read back into counts. */
|
|
79
|
+
export async function shellTests(
|
|
80
|
+
input: ShellRunInput,
|
|
81
|
+
filter: string | undefined,
|
|
82
|
+
): Promise<TestRun> {
|
|
83
|
+
const results: ExecResult[] = [];
|
|
84
|
+
const runner = shellRunner(input);
|
|
85
|
+
const started = performance.now();
|
|
86
|
+
const outcome = await testCommand.run({
|
|
87
|
+
args: parseArgs(testRunArgs(filter), [testSpec]),
|
|
88
|
+
cwd: input.root,
|
|
89
|
+
env: shellEnv(input),
|
|
90
|
+
bunVersion: Bun.version,
|
|
91
|
+
runner: async (command, options) => {
|
|
92
|
+
const result = await runner(command, options);
|
|
93
|
+
results.push(result);
|
|
94
|
+
return result;
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
const run = sumRuns(results, Math.round(performance.now() - started));
|
|
98
|
+
// A red command with no red batch read (a batch the parser could not see) is still red.
|
|
99
|
+
if (outcome.ok || run.failed > 0) return run;
|
|
100
|
+
const failure = { test: 'x test', message: outcome.summary };
|
|
101
|
+
return { ...run, failed: 1, failures: [failure] };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** `verify.run`: `x verify [--only a,b]`, its steps projected onto the tool's shape. */
|
|
105
|
+
export async function shellVerify(
|
|
106
|
+
input: ShellRunInput,
|
|
107
|
+
only: readonly string[] | undefined,
|
|
108
|
+
): Promise<VerifyResult> {
|
|
109
|
+
const argv = only === undefined ? ['verify'] : ['verify', '--only', only.join(',')];
|
|
110
|
+
// A refused `--only` throws the command's own coded error, which the tool renders as one.
|
|
111
|
+
const result = await verifyCommand.run({
|
|
112
|
+
args: parseArgs(argv, [verifySpec]),
|
|
113
|
+
cwd: input.root,
|
|
114
|
+
env: shellEnv(input),
|
|
115
|
+
bunVersion: Bun.version,
|
|
116
|
+
runner: shellRunner(input),
|
|
117
|
+
});
|
|
118
|
+
return {
|
|
119
|
+
ok: result.ok,
|
|
120
|
+
steps: (result.steps ?? []).map((step): VerifyStep => {
|
|
121
|
+
const detail = step.findings[0]?.cause;
|
|
122
|
+
// exactOptionalPropertyTypes: omit `detail`, never hand over an explicit undefined.
|
|
123
|
+
return detail === undefined
|
|
124
|
+
? { name: step.name, ok: step.ok }
|
|
125
|
+
: { name: step.name, ok: step.ok, detail };
|
|
126
|
+
}),
|
|
127
|
+
};
|
|
128
|
+
}
|