@ultimat3/cli 3.0.0 → 4.0.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 +69 -10
- package/package.json +24 -24
- package/src/budgets.ts +8 -5
- package/src/cmd-deploy.ts +42 -14
- package/src/cmd-docs.ts +7 -3
- package/src/cmd-fix.ts +15 -3
- package/src/cmd-generate.ts +29 -4
- package/src/cmd-help.ts +25 -4
- package/src/cmd-i18n.ts +8 -5
- package/src/cmd-jobs.ts +6 -5
- package/src/cmd-mcp.ts +16 -12
- package/src/cmd-new.ts +9 -13
- package/src/cmd-planned.ts +13 -0
- package/src/cmd-policy.ts +8 -6
- package/src/cmd-registries.ts +7 -6
- package/src/cmd-routes.ts +27 -4
- package/src/cmd-secrets.ts +6 -6
- package/src/cmd-verify.ts +55 -3
- package/src/command.ts +10 -2
- package/src/dev-cache.ts +9 -9
- package/src/dev-render.ts +6 -1
- package/src/dev-runtime.ts +2 -2
- package/src/dispatch.ts +33 -4
- package/src/error-codes.ts +5 -0
- package/src/error-contract.ts +31 -4
- package/src/fix-command.ts +9 -2
- package/src/fix-imports.ts +118 -0
- package/src/fix-scan.ts +251 -0
- package/src/flag-reads.ts +114 -0
- package/src/i18n-audit.ts +2 -1
- package/src/index.ts +8 -1
- package/src/jobs-drain.ts +6 -1
- package/src/mcp-errors.ts +5 -0
- package/src/mcp-host.ts +4 -2
- package/src/messages.ts +3 -0
- package/src/otlp-export.ts +14 -0
- package/src/parse.ts +6 -1
- package/src/seo-meta.ts +105 -0
- package/src/templates/action.ts +39 -7
- package/src/templates/backfill.ts +3 -1
- package/src/templates/index.ts +10 -1
- package/src/templates/job.ts +6 -2
- package/src/templates/query.ts +6 -1
- package/src/templates/route.ts +18 -9
- package/src/templates/scaffold-api.ts +100 -0
- package/src/templates/scaffold-app.ts +8 -48
- package/src/templates/scaffold-container.ts +44 -9
- package/src/templates/scaffold-helm-templates.ts +327 -0
- package/src/templates/scaffold-helm.ts +144 -0
- package/src/templates/scaffold-repo.ts +25 -8
- package/src/ts-scan.ts +12 -174
- package/src/verify-step.ts +5 -0
package/src/ts-scan.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
// Reading
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// Reading TypeScript source without a parser: the masking every scan here shares, and the `X_*`
|
|
2
|
+
// codes a package declares. Deliberately not `tsc` — a regex over a masked file is the whole job.
|
|
3
|
+
// Masking is the load-bearing part: the contract's own 3-line rendering appears verbatim in doc
|
|
4
|
+
// blocks and template literals, and a scanner that reads it as code invents work. What a `fix:`
|
|
5
|
+
// can evaluate to is `fix-scan.ts`, which reads these primitives and is the only file that grew.
|
|
5
6
|
|
|
6
7
|
export interface SourceSite {
|
|
7
8
|
/** Repo-relative file the site was read from. */
|
|
@@ -18,9 +19,10 @@ export interface CodeSite extends SourceSite {
|
|
|
18
19
|
readonly code: string;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
22
|
+
// `ReadonlySet`, so a consumer cannot mutate what every scan in this package reads.
|
|
23
|
+
export const QUOTES: ReadonlySet<string> = new Set(["'", '"', '`']);
|
|
24
|
+
export const OPENERS: ReadonlySet<string> = new Set(['(', '[', '{']);
|
|
25
|
+
export const CLOSERS: ReadonlySet<string> = new Set([')', ']', '}']);
|
|
24
26
|
const WORD = /[\w$]/;
|
|
25
27
|
|
|
26
28
|
/** After one of these words a `/` opens a regex; after any other identifier it divides. */
|
|
@@ -36,7 +38,7 @@ const REGEX_AFTER_WORDS = new Set(
|
|
|
36
38
|
* silently emptying the `errors` gate for the whole file. Same rule `endOfRegex` applies to a `/`.
|
|
37
39
|
* An escaped newline is still a continuation: the escape is consumed before the line test.
|
|
38
40
|
*/
|
|
39
|
-
function endOfLiteral(text: string, from: number): number {
|
|
41
|
+
export function endOfLiteral(text: string, from: number): number {
|
|
40
42
|
const quote = text[from] as string;
|
|
41
43
|
const spansLines = quote === '`';
|
|
42
44
|
for (let i = from + 1; i < text.length; i += 1) {
|
|
@@ -132,7 +134,7 @@ export const maskLiterals = (text: string): string => blankRegions(text, true);
|
|
|
132
134
|
* asking for a line per literal pays once per literal — measured at ~15s over the framework's own
|
|
133
135
|
* package tree, against ~1s for the same walk with this. One offset table, then a binary search.
|
|
134
136
|
*/
|
|
135
|
-
function lineIndex(text: string): (index: number) => number {
|
|
137
|
+
export function lineIndex(text: string): (index: number) => number {
|
|
136
138
|
const newlines: number[] = [];
|
|
137
139
|
for (let i = 0; i < text.length; i += 1) if (text[i] === '\n') newlines.push(i);
|
|
138
140
|
return (index) => {
|
|
@@ -153,7 +155,7 @@ function lineIndex(text: string): (index: number) => number {
|
|
|
153
155
|
* instead of silently skipped; the depth rule is what keeps `command.join(' ')`'s separator and
|
|
154
156
|
* `table['key']`'s key out — an argument is not a fix.
|
|
155
157
|
*/
|
|
156
|
-
function valueLiterals(
|
|
158
|
+
export function valueLiterals(
|
|
157
159
|
masked: string,
|
|
158
160
|
source: string,
|
|
159
161
|
from: number,
|
|
@@ -182,170 +184,6 @@ function valueLiterals(
|
|
|
182
184
|
}));
|
|
183
185
|
}
|
|
184
186
|
|
|
185
|
-
/** The lookbehind rejects member access: `cond ? e.fix : ''` is a ternary, not a declaration. */
|
|
186
|
-
const FIX_KEY = /(?<![.\w$])fix\s*:\s*/g;
|
|
187
|
-
|
|
188
|
-
/** Text between the bracket at `open` and its match, or `undefined` when it never closes. */
|
|
189
|
-
function bracketSpan(masked: string, open: number): string | undefined {
|
|
190
|
-
let depth = 0;
|
|
191
|
-
for (let i = open; i < masked.length; i += 1) {
|
|
192
|
-
const ch = masked[i] as string;
|
|
193
|
-
// Only `()[]{}`. An angle bracket is a generic in a parameter list and the tail of `=>` in the
|
|
194
|
-
// very same list, so counting it makes `(fn: () => void)` end the span in the wrong place.
|
|
195
|
-
if (OPENERS.has(ch)) depth += 1;
|
|
196
|
-
else if (CLOSERS.has(ch)) {
|
|
197
|
-
depth -= 1;
|
|
198
|
-
if (depth === 0) return masked.slice(open + 1, i);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return undefined;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/** Split at depth-0 commas. Safe on masked text, where a comma inside a literal is already gone. */
|
|
205
|
-
function topLevelParts(text: string): readonly string[] {
|
|
206
|
-
const parts: string[] = [];
|
|
207
|
-
let depth = 0;
|
|
208
|
-
let start = 0;
|
|
209
|
-
for (let i = 0; i < text.length; i += 1) {
|
|
210
|
-
const ch = text[i] as string;
|
|
211
|
-
if (OPENERS.has(ch)) depth += 1;
|
|
212
|
-
else if (CLOSERS.has(ch)) depth -= 1;
|
|
213
|
-
else if (ch === ',' && depth === 0) {
|
|
214
|
-
parts.push(text.slice(start, i));
|
|
215
|
-
start = i + 1;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
parts.push(text.slice(start));
|
|
219
|
-
return parts;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/** A local function that builds an error and takes its fix positionally, and where in its list. */
|
|
223
|
-
interface FixHelper {
|
|
224
|
-
readonly name: string;
|
|
225
|
-
readonly index: number;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const HELPER_DECL =
|
|
229
|
-
/(?<![.\w$])(?:function\s+([A-Za-z_$][\w$]*)\s*\(|(?:const|let)\s+([A-Za-z_$][\w$]*)\s*(?::[^=;]*)?=\s*(?:async\s+)?\()/g;
|
|
230
|
-
|
|
231
|
-
const FIX_PARAM = /^\s*fix\s*:\s*string\s*$/;
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* What separates a helper that BUILDS a fix from one that CONSUMES one. `citedCommandProblem(fix:
|
|
235
|
-
* string, …)` in `fix-command.ts` takes a fix in order to judge it, and reading its call sites as
|
|
236
|
-
* declarations would report findings about strings that are already findings. A builder names a
|
|
237
|
-
* `code` or constructs an `…Error`; a consumer does neither.
|
|
238
|
-
*/
|
|
239
|
-
const BUILDS_ERROR = /(?<![.\w$])code\s*[:=]|new\s+[A-Za-z_$][\w$]*Error\s*\(/;
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* The body of the declaration whose parameter list ends at `after`, and never a `{` belonging to
|
|
243
|
-
* something below it. An unbounded `indexOf('{')` reads the next object literal in the FILE when
|
|
244
|
-
* the body is a concise expression, so `const label = (fix: string) => fix.trim();` followed
|
|
245
|
-
* anywhere by a `{ code: … }` was read as an error builder and every `label(…)` call handed the
|
|
246
|
-
* gate a string to judge as a fix — a false gate failure over innocent source.
|
|
247
|
-
*
|
|
248
|
-
* The scan therefore ends at the `;` that ends the declaration, or at a bracket closing a scope
|
|
249
|
-
* this declaration is inside. Both directions of that bound answer `''`, which classifies the
|
|
250
|
-
* helper as a non-builder: a missed fix line costs one unchecked citation, a wrongly claimed one
|
|
251
|
-
* costs a build. A `{` inside a return-type annotation (`(): { ok: boolean } => …`) is read as the
|
|
252
|
-
* body and answers `''` for the same reason.
|
|
253
|
-
*/
|
|
254
|
-
function bodyOf(masked: string, after: number): string {
|
|
255
|
-
for (let i = after; i < masked.length; i += 1) {
|
|
256
|
-
const ch = masked[i] as string;
|
|
257
|
-
if (ch === '{') return bracketSpan(masked, i) ?? '';
|
|
258
|
-
if (ch === ';' || CLOSERS.has(ch)) break;
|
|
259
|
-
}
|
|
260
|
-
return '';
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
function fixHelpers(masked: string): readonly FixHelper[] {
|
|
264
|
-
const helpers: FixHelper[] = [];
|
|
265
|
-
for (const declaration of masked.matchAll(HELPER_DECL)) {
|
|
266
|
-
const name = declaration[1] ?? declaration[2];
|
|
267
|
-
const open = declaration.index + declaration[0].length - 1;
|
|
268
|
-
if (name === undefined || masked[open] !== '(') continue;
|
|
269
|
-
const params = bracketSpan(masked, open);
|
|
270
|
-
// A rest parameter makes the position of everything after it unknowable, and a destructured
|
|
271
|
-
// one has no position at all — its `fix:` key at the CALL site is already read by `FIX_KEY`.
|
|
272
|
-
if (params === undefined || params.includes('...')) continue;
|
|
273
|
-
const parts = topLevelParts(params);
|
|
274
|
-
if (parts.some((part) => /^\s*[[{]/.test(part))) continue;
|
|
275
|
-
const index = parts.findIndex((part) => FIX_PARAM.test(part));
|
|
276
|
-
if (index === -1) continue;
|
|
277
|
-
if (!BUILDS_ERROR.test(bodyOf(masked, open + params.length + 2))) continue;
|
|
278
|
-
helpers.push({ name, index });
|
|
279
|
-
}
|
|
280
|
-
return helpers;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* The argument in that position at every call to that helper IN THIS FILE.
|
|
285
|
-
*
|
|
286
|
-
* Same file, deliberately: resolving `dbNotImplemented` imported from `@ultimat3/db` would mean a
|
|
287
|
-
* cross-file symbol table, and a scanner that guessed at which import a name came from would read
|
|
288
|
-
* an unrelated function's argument as a fix. The gap that leaves is named in `CLAUDE.md`.
|
|
289
|
-
*/
|
|
290
|
-
function helperFixSites(
|
|
291
|
-
masked: string,
|
|
292
|
-
source: string,
|
|
293
|
-
at: string,
|
|
294
|
-
helper: FixHelper,
|
|
295
|
-
lineAt: (index: number) => number,
|
|
296
|
-
): readonly FixSite[] {
|
|
297
|
-
const sites: FixSite[] = [];
|
|
298
|
-
// The lookbehind is `FIX_KEY`'s: `reporter.rejected(…)` is some other object's method.
|
|
299
|
-
const call = new RegExp(`(?<![.\\w$])${helper.name}\\s*\\(`, 'g');
|
|
300
|
-
for (const match of masked.matchAll(call)) {
|
|
301
|
-
const open = match.index + match[0].length - 1;
|
|
302
|
-
const args = bracketSpan(masked, open);
|
|
303
|
-
if (args === undefined) continue;
|
|
304
|
-
const parts = topLevelParts(args);
|
|
305
|
-
const argument = parts[helper.index];
|
|
306
|
-
if (argument === undefined) continue;
|
|
307
|
-
// Stricter than the `fix:` path, and deliberately: the whole argument must BE one literal.
|
|
308
|
-
// `valueLiterals` alone reads `prefix + 'x doctor'` as one literal, because the identifier
|
|
309
|
-
// half contributes none — and publishing half a fix as the whole one is the failure
|
|
310
|
-
// `soleLiteral` already names. A key at least declares that what follows is the value.
|
|
311
|
-
const quote = argument.trim()[0];
|
|
312
|
-
if (quote === undefined || !QUOTES.has(quote)) continue;
|
|
313
|
-
const literal = argument.indexOf(quote);
|
|
314
|
-
if (argument.slice(endOfLiteral(argument, literal)).trim() !== '') continue;
|
|
315
|
-
const from = parts.slice(0, helper.index).reduce((n, part) => n + part.length + 1, open + 1);
|
|
316
|
-
const literals = valueLiterals(masked, source, from, lineAt);
|
|
317
|
-
if (literals.length === 1) sites.push({ ...(literals[0] as FixSite), at });
|
|
318
|
-
}
|
|
319
|
-
return sites;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Every string a `fix:` can evaluate to. Searched over the masked source, so a `fix:` written
|
|
324
|
-
* inside a doc comment or interpolated into a message is not mistaken for a declaration. A `fix`
|
|
325
|
-
* computed at runtime — a bare identifier, a parameter, a table lookup with no literal fallback —
|
|
326
|
-
* has nothing to read and is beyond a static scan; the gate says so rather than guessing.
|
|
327
|
-
*
|
|
328
|
-
* Two shapes, because a fix does not always arrive under a key. `@ultimat3/mcp`'s `readonly-sql.ts`
|
|
329
|
-
* hands every one of its fixes positionally to a local `rejected(cause, fix)` helper, so the key
|
|
330
|
-
* rule alone returned `[]` for the whole file — 20 non-test files in that package and the scanner
|
|
331
|
-
* saw fixes in three — and two stale `x db branch <name>` lines shipped through the hole.
|
|
332
|
-
*/
|
|
333
|
-
export function scanFixes(source: string, at: string): readonly FixSite[] {
|
|
334
|
-
const masked = maskLiterals(source);
|
|
335
|
-
const lineAt = lineIndex(masked);
|
|
336
|
-
const sites: FixSite[] = [];
|
|
337
|
-
for (const key of masked.matchAll(FIX_KEY)) {
|
|
338
|
-
const start = key.index + key[0].length;
|
|
339
|
-
for (const literal of valueLiterals(masked, source, start, lineAt)) {
|
|
340
|
-
sites.push({ ...literal, at });
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
for (const helper of fixHelpers(masked)) {
|
|
344
|
-
sites.push(...helperFixSites(masked, source, at, helper, lineAt));
|
|
345
|
-
}
|
|
346
|
-
return sites;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
187
|
const CODE_TABLE = /\bexport const [A-Z][A-Z0-9_]*_ERROR_(?:CODES|TITLES)\b/;
|
|
350
188
|
|
|
351
189
|
/**
|
package/src/verify-step.ts
CHANGED
|
@@ -28,6 +28,11 @@ export const VERIFY_STEP_NAMES = [
|
|
|
28
28
|
'drift',
|
|
29
29
|
'contract-diff',
|
|
30
30
|
'budgets',
|
|
31
|
+
// Eighteenth, and a deliberate widening of a closed list rather than a `HostCheck`: an SEO gate
|
|
32
|
+
// is a MECHANISM every app with a `site/` surface wants (axiom 8), not a rule one host repo
|
|
33
|
+
// enforces — and `verifyCommand.run` passes no host checks at all, so the app path could not
|
|
34
|
+
// have carried it. It runs beside `budgets` because both read the app the same load produced.
|
|
35
|
+
'seo',
|
|
31
36
|
'manifest',
|
|
32
37
|
'roadmap',
|
|
33
38
|
] as const;
|