@ultimat3/cli 31.0.0 → 31.2.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 +6 -1
- package/package.json +29 -29
- package/src/affected-base.ts +51 -0
- package/src/affected.ts +29 -10
- package/src/binding-names.ts +124 -0
- package/src/browser-transport.ts +28 -0
- package/src/ci-log.ts +76 -13
- package/src/cmd-affected-spec.ts +7 -3
- package/src/cmd-affected.ts +91 -77
- package/src/cmd-ci.ts +6 -3
- package/src/cmd-doctor.ts +8 -0
- package/src/cmd-exercise.ts +13 -1
- package/src/cmd-pr-spec.ts +1 -1
- package/src/cmd-pr.ts +72 -1
- package/src/cmd-shot.ts +13 -271
- package/src/cmd-test-spec.ts +2 -2
- package/src/cmd-upgrade.ts +28 -4
- package/src/cmd-verify-spec.ts +2 -2
- package/src/doctor-typescript.ts +31 -0
- package/src/error-codes-package.ts +38 -0
- package/src/error-codes.ts +7 -21
- package/src/mcp-errors-shot.ts +49 -0
- package/src/mcp-errors.ts +7 -41
- package/src/measure-scope.ts +17 -4
- package/src/messages-gate.ts +6 -0
- package/src/messages-upgrade.ts +2 -0
- package/src/offline-ports.ts +106 -0
- package/src/output.ts +21 -3
- package/src/pr-activity.ts +150 -0
- package/src/pr-bots.ts +109 -0
- package/src/pr-threads.ts +7 -2
- package/src/prerender.ts +2 -2
- package/src/runtime-storage-boot.ts +41 -7
- package/src/shot-gpu.ts +61 -0
- package/src/shot-route.ts +95 -0
- package/src/shot-run.ts +189 -0
- package/src/shot-verdict.ts +5 -0
- package/src/templates/scaffold-repo.ts +2 -1
- package/src/templates/sign-in-oidc.ts +24 -9
- package/src/transport-calls.ts +7 -3
- package/src/transport-values.ts +59 -0
- package/src/tsconfig-aliases.ts +85 -0
- package/src/typescript-floor.ts +83 -0
- package/src/upgrade-report.ts +8 -1
- package/src/verify-changed-scope.ts +3 -2
- package/src/verify-checks.ts +2 -0
- package/src/workspace-external-deps.ts +164 -0
- package/wiki/CLI-Reference.md +12 -8
- package/wiki/Upgrading.md +24 -5
package/CLAUDE.md
CHANGED
|
@@ -55,11 +55,12 @@ Commands: `bun test ./packages/cli/` (repo root: the preload),
|
|
|
55
55
|
| `verify-factories.ts` | `unit` lints `<app>/packages/db/factories.ts` (`X_TEST_FACTORY_INVALID`) |
|
|
56
56
|
| `boundary-findings.ts` / `app-boundaries.ts` / `boundary-cuts.ts` / `package-boundaries.ts` | surface + layer rules, `X_BOUNDARY_PACKAGE_TO_APP`; a `fix:` is the concrete cut † |
|
|
57
57
|
| `app-boundaries.ts` (workspaces) | `@<scope>/<app>/<rest>` resolves onto `apps/<app>/<rest>` when that is an app source, so the surface rules hold across app workspaces |
|
|
58
|
-
| `app-transport.ts` / `browser-transport.ts` / `transport-calls.ts` / `import-closure.ts` / `server-barrels.ts` | `boundaries`, built in: one browser transport; never a `guards/` file † |
|
|
58
|
+
| `app-transport.ts` / `browser-transport.ts` / `transport-calls.ts` / `transport-values.ts` / `binding-names.ts` / `import-closure.ts` / `server-barrels.ts` | `boundaries`, built in: one browser transport; never a `guards/` file † |
|
|
59
59
|
| `guards.ts` / `guard-sources.ts` | an app's `guards/*.ts`, run on `boundaries`; ONE shared walk (`GuardSources`) † |
|
|
60
60
|
| `templates/scaffold-guards.ts` | `SHIPPED`, the one list of shipped guards (`x new`, `x g guard`, `doctor-guards.ts`) † |
|
|
61
61
|
| `error-contract.ts` / `ts-scan.ts` / `fix-scan.ts` / `fix-imports.ts` / `fix-command.ts` / `fix-path.ts` | the `errors` step: every `fix:` names a runnable command, call or existing file |
|
|
62
62
|
| `workspace-checks.ts` / `test-only-shipped.ts` / `workspace-graph.ts` / `tsconfig-references.ts` / `publish-closure.ts` | `package-shape`, `filesize` ‡ |
|
|
63
|
+
| `workspace-external-deps.ts` · `tsconfig-aliases.ts` · `error-codes-package.ts` | `package-shape`: a registry import neither the workspace nor the root declares (`X_WORKSPACE_EXTERNAL_DEP_UNDECLARED`); fix `bun add <pkg> --cwd <workspace>`. The step family's codes and titles, split out of `error-codes.ts` |
|
|
63
64
|
| `app-permissions*.ts` / `permission-grants.ts` | `policy`: `X_PERMISSION_UNGRANTED`, `X_PERMISSION_BORROWED` † |
|
|
64
65
|
| `job-registration.ts` | `manifest`: no job or task under a positional `anonymous-*` name (`X_JOB_UNREGISTERED`) |
|
|
65
66
|
| `unscanned-admin.ts` | `manifest`: a `defineAdmin()` outside the app scan (`apps/*/src/`) is `X_ADMIN_UNSCANNED` |
|
|
@@ -167,7 +168,11 @@ Commands: `bun test ./packages/cli/` (repo root: the preload),
|
|
|
167
168
|
| `cmd-auth.ts` / `cmd-auth-spec.ts` / `doctor-auth.ts` | `x auth seal-mfa`: seals plaintext `x_users.mfa_secret` through auth's `sealMfaSecrets` |
|
|
168
169
|
| `cmd-mcp.ts` / `mcp-host.ts` / `mcp-errors.ts` / `mcp-db-target.ts` | `x mcp serve`: 19 tools, two transports † |
|
|
169
170
|
| `cmd-shot*.ts` / `cdp-shot-*.ts` / `browser-launcher*.ts` / `island-*` | `x shot` over raw CDP; `verdict.json` names its own blind spots. Not a gate step |
|
|
171
|
+
| `shot-route.ts` / `shot-run.ts` / `shot-gpu.ts` | `x shot`'s route argument (`readRoute`, `shotSlug`); one capture (`runShot`); the page's `navigator.gpu` adapter (`verdict.gpu`, never gating). `cmd-shot.ts` re-exports the first two |
|
|
170
172
|
| `cmd-pr.ts` / `cmd-ci.ts` / `ci-runs.ts` / `ci-tested.ts` | GitHub through `gh`, schema-parsed; not gate steps † |
|
|
173
|
+
| `pr-threads.ts` / `pr-activity.ts` | `x pr review`'s ONE GraphQL document: threads, plus every review (verdict, body) and issue comment |
|
|
174
|
+
| `pr-bots.ts` | which review bots posted a "did not review" notice (rate/review limit, skipped); `blocked` = no review of theirs after it |
|
|
175
|
+
| `ci-log.ts` | `x ci`'s log reader: undoes `##[…]` markers, `::error` annotations and `<comment>` fences; `fix` stays clean, provenance is `source: 'ci-log'` + `meta.job` + `output.ts`'s `[from=ci-log …]` head marker |
|
|
171
176
|
| `error-catalog.ts` | imports every `@ultimat3/*` package so `x errors` answers for any code |
|
|
172
177
|
| `cmd-docs.ts` / `docs-sources.ts` / `docs-section.ts` | `x docs`: the app's and the CLI's `@ultimat3` docs; `Page#anchor` prints a section † |
|
|
173
178
|
| `cmd-env-init.ts` / `env-production.ts` / `cmd-deploy-preflight.ts` | the one writer of `.env.production`; compose pre-flight (`X_DEPLOY_ENV_MISSING`) † |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/cli",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.2.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.
|
|
57
|
-
"@ultimat3/admin": "31.
|
|
58
|
-
"@ultimat3/ai": "31.
|
|
59
|
-
"@ultimat3/auth": "31.
|
|
60
|
-
"@ultimat3/cache": "31.
|
|
61
|
-
"@ultimat3/core": "31.
|
|
62
|
-
"@ultimat3/db": "31.
|
|
63
|
-
"@ultimat3/entity": "31.
|
|
64
|
-
"@ultimat3/flags": "31.
|
|
65
|
-
"@ultimat3/http": "31.
|
|
66
|
-
"@ultimat3/i18n": "31.
|
|
67
|
-
"@ultimat3/jobs": "31.
|
|
68
|
-
"@ultimat3/mail": "31.
|
|
69
|
-
"@ultimat3/manifest": "31.
|
|
70
|
-
"@ultimat3/mcp": "31.
|
|
71
|
-
"@ultimat3/money": "31.
|
|
72
|
-
"@ultimat3/notify": "31.
|
|
73
|
-
"@ultimat3/policy": "31.
|
|
74
|
-
"@ultimat3/pwa": "31.
|
|
75
|
-
"@ultimat3/query": "31.
|
|
76
|
-
"@ultimat3/realtime": "31.
|
|
77
|
-
"@ultimat3/render": "31.
|
|
78
|
-
"@ultimat3/schema": "31.
|
|
79
|
-
"@ultimat3/scraping": "31.
|
|
80
|
-
"@ultimat3/seo": "31.
|
|
81
|
-
"@ultimat3/storage": "31.
|
|
82
|
-
"@ultimat3/testing": "31.
|
|
83
|
-
"@ultimat3/time": "31.
|
|
56
|
+
"@ultimat3/action": "31.2.0",
|
|
57
|
+
"@ultimat3/admin": "31.2.0",
|
|
58
|
+
"@ultimat3/ai": "31.2.0",
|
|
59
|
+
"@ultimat3/auth": "31.2.0",
|
|
60
|
+
"@ultimat3/cache": "31.2.0",
|
|
61
|
+
"@ultimat3/core": "31.2.0",
|
|
62
|
+
"@ultimat3/db": "31.2.0",
|
|
63
|
+
"@ultimat3/entity": "31.2.0",
|
|
64
|
+
"@ultimat3/flags": "31.2.0",
|
|
65
|
+
"@ultimat3/http": "31.2.0",
|
|
66
|
+
"@ultimat3/i18n": "31.2.0",
|
|
67
|
+
"@ultimat3/jobs": "31.2.0",
|
|
68
|
+
"@ultimat3/mail": "31.2.0",
|
|
69
|
+
"@ultimat3/manifest": "31.2.0",
|
|
70
|
+
"@ultimat3/mcp": "31.2.0",
|
|
71
|
+
"@ultimat3/money": "31.2.0",
|
|
72
|
+
"@ultimat3/notify": "31.2.0",
|
|
73
|
+
"@ultimat3/policy": "31.2.0",
|
|
74
|
+
"@ultimat3/pwa": "31.2.0",
|
|
75
|
+
"@ultimat3/query": "31.2.0",
|
|
76
|
+
"@ultimat3/realtime": "31.2.0",
|
|
77
|
+
"@ultimat3/render": "31.2.0",
|
|
78
|
+
"@ultimat3/schema": "31.2.0",
|
|
79
|
+
"@ultimat3/scraping": "31.2.0",
|
|
80
|
+
"@ultimat3/seo": "31.2.0",
|
|
81
|
+
"@ultimat3/storage": "31.2.0",
|
|
82
|
+
"@ultimat3/testing": "31.2.0",
|
|
83
|
+
"@ultimat3/time": "31.2.0",
|
|
84
84
|
"babel-preset-solid": "^1.9.16"
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// The ref a diff is measured against when `--base` says nothing: the REMOTE-TRACKING default branch
|
|
2
|
+
// (`origin/HEAD` → `origin/main`), never local `main` while a remote-tracking ref exists. Local `main` is
|
|
3
|
+
// whatever was last pulled, and in a checkout nobody pulls (or a worktree) it lags origin: the diff
|
|
4
|
+
// then counts files already merged upstream as this branch's work, and the "affected" set widens.
|
|
5
|
+
|
|
6
|
+
import type { Runner } from './exec';
|
|
7
|
+
|
|
8
|
+
/** The branch a change is measured against when no remote-tracking ref names one. */
|
|
9
|
+
export const DEFAULT_BASE = 'main';
|
|
10
|
+
|
|
11
|
+
/** The remote whose default branch is the base. One name: a second guess is a second answer. */
|
|
12
|
+
export const DEFAULT_REMOTE = 'origin';
|
|
13
|
+
|
|
14
|
+
/** What `--help` says the default is, for every command that reads `--base`. */
|
|
15
|
+
export const DEFAULT_BASE_HELP = `${DEFAULT_REMOTE}/HEAD's branch (e.g. ${DEFAULT_REMOTE}/${DEFAULT_BASE}), else local ${DEFAULT_BASE} when there is no remote-tracking ref (${DEFAULT_REMOTE}/HEAD or ${DEFAULT_REMOTE}/${DEFAULT_BASE})`;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The default base, read from what the checkout already has — never fetched: a command that
|
|
19
|
+
* scopes a test run must not reach the network, and a stale `origin/main` is still nearer the truth
|
|
20
|
+
* than a stale local `main` (`git fetch` moves the first; only a pull moves the second).
|
|
21
|
+
*
|
|
22
|
+
* In order: `origin/HEAD`'s target (a clone sets it), then `origin/main` (a remote added by hand
|
|
23
|
+
* leaves `origin/HEAD` unset), then local `main` — when there is no remote-tracking ref (`origin/HEAD`
|
|
24
|
+
* or `origin/main`): no remote at all, an `origin` never fetched, or one whose branch is not `main`.
|
|
25
|
+
*/
|
|
26
|
+
export async function defaultBase(runner: Runner, cwd: string): Promise<string> {
|
|
27
|
+
const head = await runner(
|
|
28
|
+
['git', 'symbolic-ref', '--quiet', '--short', `refs/remotes/${DEFAULT_REMOTE}/HEAD`],
|
|
29
|
+
{ cwd },
|
|
30
|
+
);
|
|
31
|
+
const target = head.ok ? head.stdout.trim() : '';
|
|
32
|
+
if (target.length > 0) return target;
|
|
33
|
+
const tracking = `${DEFAULT_REMOTE}/${DEFAULT_BASE}`;
|
|
34
|
+
const main = await runner(
|
|
35
|
+
['git', 'rev-parse', '--verify', '--quiet', `refs/remotes/${tracking}^{commit}`],
|
|
36
|
+
{ cwd },
|
|
37
|
+
);
|
|
38
|
+
return main.ok ? tracking : DEFAULT_BASE;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The `git fetch` that makes `base` resolvable: a remote-tracking ref is refreshed by fetching its
|
|
43
|
+
* branch, a local one by fetching into it. `origin/main:origin/main` would create a local branch
|
|
44
|
+
* literally named `origin/main`, which is how the old one-size fix line broke on its own default.
|
|
45
|
+
*/
|
|
46
|
+
export const fetchFixFor = (base: string): string => {
|
|
47
|
+
const prefix = `${DEFAULT_REMOTE}/`;
|
|
48
|
+
return base.startsWith(prefix)
|
|
49
|
+
? `git fetch --no-tags ${DEFAULT_REMOTE} ${base.slice(prefix.length)}`
|
|
50
|
+
: `git fetch --no-tags ${DEFAULT_REMOTE} ${base}:${base}`;
|
|
51
|
+
};
|
package/src/affected.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
// directory is checkout-relative while a caller's scan yields paths relative to its own root.
|
|
14
14
|
import { join, relative } from 'node:path';
|
|
15
15
|
import { singleLine, UltimateError } from '@ultimat3/core';
|
|
16
|
+
import { DEFAULT_BASE, defaultBase, fetchFixFor } from './affected-base';
|
|
16
17
|
import { readUnownedDirs } from './affected-unowned';
|
|
17
18
|
import { BadFlagError } from './errors';
|
|
18
19
|
import type { ExecResult, Runner } from './exec';
|
|
@@ -23,8 +24,7 @@ import { flagBool, flagString } from './parse';
|
|
|
23
24
|
import type { WorkspaceNode } from './workspace-graph';
|
|
24
25
|
import { readWorkspaceGraph } from './workspace-graph';
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
export const DEFAULT_BASE = 'main';
|
|
27
|
+
export { DEFAULT_BASE } from './affected-base';
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* A file with no compilation unit behind it. A doc or a plan re-checks nothing, so it maps to no
|
|
@@ -162,18 +162,26 @@ const invocationOf = (command: string): string =>
|
|
|
162
162
|
: `x ${command} --affected`;
|
|
163
163
|
|
|
164
164
|
export interface AffectedSelection {
|
|
165
|
+
/** The ref the diff was measured against — `--base`, or the default it resolved to. */
|
|
165
166
|
readonly base: string;
|
|
166
167
|
readonly dirty: boolean;
|
|
167
168
|
}
|
|
168
169
|
|
|
170
|
+
/** What argv asked for: `base` is absent when `--base` was not given. */
|
|
171
|
+
export interface AffectedRequest {
|
|
172
|
+
readonly base: string | undefined;
|
|
173
|
+
readonly dirty: boolean;
|
|
174
|
+
}
|
|
175
|
+
|
|
169
176
|
/**
|
|
170
|
-
* One reader for `--base` and `--dirty`, shared by `x affected
|
|
171
|
-
* readers would be two answers to "what is this diff measured against", and the
|
|
172
|
-
* scoping is only trustworthy if it is the first command's.
|
|
177
|
+
* One reader for `--base` and `--dirty`, shared by `x affected`, `x test --affected` and `x verify
|
|
178
|
+
* --changed`: two readers would be two answers to "what is this diff measured against", and the
|
|
179
|
+
* second command's scoping is only trustworthy if it is the first command's. Pure — a malformed
|
|
180
|
+
* `--base` is refused before git is spawned; `resolveSelection` fills the default in.
|
|
173
181
|
*/
|
|
174
|
-
export function readAffectedSelection(args: ParsedArgs, command: string):
|
|
175
|
-
const base = flagString(args, 'base')
|
|
176
|
-
if (base.trim().length === 0) {
|
|
182
|
+
export function readAffectedSelection(args: ParsedArgs, command: string): AffectedRequest {
|
|
183
|
+
const base = flagString(args, 'base');
|
|
184
|
+
if (base !== undefined && base.trim().length === 0) {
|
|
177
185
|
throw new BadFlagError({
|
|
178
186
|
flag: 'base',
|
|
179
187
|
command,
|
|
@@ -184,6 +192,16 @@ export function readAffectedSelection(args: ParsedArgs, command: string): Affect
|
|
|
184
192
|
return { base, dirty: flagBool(args, 'dirty') };
|
|
185
193
|
}
|
|
186
194
|
|
|
195
|
+
/** `--base` verbatim when given, else the remote-tracking default branch (`affected-base.ts`). */
|
|
196
|
+
export const resolveSelection = async (
|
|
197
|
+
runner: Runner,
|
|
198
|
+
cwd: string,
|
|
199
|
+
request: AffectedRequest,
|
|
200
|
+
): Promise<AffectedSelection> => ({
|
|
201
|
+
base: request.base ?? (await defaultBase(runner, cwd)),
|
|
202
|
+
dirty: request.dirty,
|
|
203
|
+
});
|
|
204
|
+
|
|
187
205
|
const git = (runner: Runner, cwd: string, args: readonly string[]): Promise<ExecResult> =>
|
|
188
206
|
runner(['git', ...args], { cwd });
|
|
189
207
|
|
|
@@ -238,7 +256,7 @@ export async function changedFiles(
|
|
|
238
256
|
flag: 'base',
|
|
239
257
|
command: options.command,
|
|
240
258
|
reason: `git resolves no commit named "${base}" in this checkout`,
|
|
241
|
-
fix:
|
|
259
|
+
fix: `${fetchFixFor(base)}, then re-run: ${invocationOf(options.command)} --base ${base} --json`,
|
|
242
260
|
});
|
|
243
261
|
}
|
|
244
262
|
const runs = [
|
|
@@ -309,8 +327,9 @@ export interface AffectedScopeOptions {
|
|
|
309
327
|
* checkmark on a broken repo, and two implementations is how one of them gets it wrong.
|
|
310
328
|
*/
|
|
311
329
|
export async function affectedScope(options: AffectedScopeOptions): Promise<AffectedScope> {
|
|
312
|
-
const
|
|
330
|
+
const request = readAffectedSelection(options.args, options.command);
|
|
313
331
|
const root = await gitRoot(options.runner, options.cwd, options.command);
|
|
332
|
+
const selection = await resolveSelection(options.runner, root, request);
|
|
314
333
|
const graph = await readWorkspaceGraph(root);
|
|
315
334
|
const plan = planAffected(
|
|
316
335
|
graph,
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// The names an object destructuring BINDS, read off masked source: `{ fetch: f }` binds `f`, never
|
|
2
|
+
// `fetch`; `{ fetch }`, `{ fetch = d }`, `{ a: { fetch } }` and `{ ...fetch }` bind `fetch`. Only a
|
|
3
|
+
// pattern in a binding position counts — a `const`/`let`/`var` declaration or a parameter list —
|
|
4
|
+
// so `make({ fetch })`, the very hand-off the transport rule reports, binds nothing.
|
|
5
|
+
|
|
6
|
+
/** Opening bracket → its closer. A `Map`: a char read off source never reaches a prototype. */
|
|
7
|
+
const PAIRS: ReadonlyMap<string, string> = new Map([
|
|
8
|
+
['(', ')'],
|
|
9
|
+
['[', ']'],
|
|
10
|
+
['{', '}'],
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
/** The index of the bracket closing the one at `open`, or `-1`. Exact on masked text only. */
|
|
14
|
+
function closing(masked: string, open: number): number {
|
|
15
|
+
const stack: string[] = [];
|
|
16
|
+
for (let at = open; at < masked.length; at += 1) {
|
|
17
|
+
const char = masked[at] ?? '';
|
|
18
|
+
const close = PAIRS.get(char);
|
|
19
|
+
if (close !== undefined) stack.push(close);
|
|
20
|
+
else if (char === stack[stack.length - 1]) {
|
|
21
|
+
stack.pop();
|
|
22
|
+
if (stack.length === 0) return at;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return -1;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The index of the unmatched `(` enclosing `index`, or `-1`. */
|
|
29
|
+
function enclosingParen(masked: string, index: number): number {
|
|
30
|
+
let depth = 0;
|
|
31
|
+
for (let at = index - 1; at >= 0; at -= 1) {
|
|
32
|
+
const char = masked[at] ?? '';
|
|
33
|
+
if (char === ')' || char === ']' || char === '}') depth += 1;
|
|
34
|
+
else if (char === '(' || char === '[' || char === '{') {
|
|
35
|
+
if (depth === 0) return char === '(' ? at : -1;
|
|
36
|
+
depth -= 1;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return -1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** `text` split on commas at depth zero — a pattern's entries. */
|
|
43
|
+
function topLevel(text: string, separator: string): readonly string[] {
|
|
44
|
+
const parts: string[] = [];
|
|
45
|
+
let depth = 0;
|
|
46
|
+
let from = 0;
|
|
47
|
+
for (let at = 0; at < text.length; at += 1) {
|
|
48
|
+
const char = text[at] ?? '';
|
|
49
|
+
if ('([{'.includes(char)) depth += 1;
|
|
50
|
+
else if (')]}'.includes(char)) depth -= 1;
|
|
51
|
+
else if (char === separator && depth === 0) {
|
|
52
|
+
parts.push(text.slice(from, at));
|
|
53
|
+
from = at + 1;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
parts.push(text.slice(from));
|
|
57
|
+
return parts;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The first `=` at depth zero that is no `==`/`=>`, or `-1`: where a default starts. */
|
|
61
|
+
function defaultAt(text: string): number {
|
|
62
|
+
let depth = 0;
|
|
63
|
+
for (let at = 0; at < text.length; at += 1) {
|
|
64
|
+
const char = text[at] ?? '';
|
|
65
|
+
if ('([{'.includes(char)) depth += 1;
|
|
66
|
+
else if (')]}'.includes(char)) depth -= 1;
|
|
67
|
+
else if (char === '=' && depth === 0 && !/[=>]/.test(text[at + 1] ?? '')) {
|
|
68
|
+
return /[=!<>]/.test(text[at - 1] ?? '') ? -1 : at;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return -1;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The names one binding target binds: an identifier, or a nested object or array pattern. */
|
|
75
|
+
function targetNames(raw: string): readonly string[] {
|
|
76
|
+
const cut = defaultAt(raw);
|
|
77
|
+
const target = (cut < 0 ? raw : raw.slice(0, cut))
|
|
78
|
+
.trim()
|
|
79
|
+
.replace(/^\.\.\./, '')
|
|
80
|
+
.trim();
|
|
81
|
+
if (target.startsWith('{')) return patternNames(target.slice(1, -1), 'object');
|
|
82
|
+
if (target.startsWith('[')) return patternNames(target.slice(1, -1), 'array');
|
|
83
|
+
const name = /^[\w$]+/.exec(target)?.[0];
|
|
84
|
+
return name === undefined ? [] : [name];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function patternNames(body: string, kind: 'object' | 'array'): readonly string[] {
|
|
88
|
+
return topLevel(body, ',').flatMap((entry) => {
|
|
89
|
+
if (kind === 'array') return targetNames(entry);
|
|
90
|
+
const [key, ...rest] = topLevel(entry, ':');
|
|
91
|
+
// `key: target` binds the target; a shorthand `name` or `name = d` binds the name.
|
|
92
|
+
return rest.length === 0 ? targetNames(key ?? '') : targetNames(rest.join(':'));
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Cheap, before any bracket is matched: a declaration keyword, or a `(`/`,` a parameter follows. */
|
|
97
|
+
function mayBind(masked: string, open: number): 'declared' | 'parameter' | undefined {
|
|
98
|
+
const head = masked.slice(Math.max(0, open - 8), open);
|
|
99
|
+
if (/\b(?:const|let|var)\s*$/.test(head)) return 'declared';
|
|
100
|
+
return /[(,]\s*$/.test(masked.slice(Math.max(0, open - 64), open)) ? 'parameter' : undefined;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** A `{` after `(`/`,` is a parameter when its list is followed by a body, an arrow or a type. */
|
|
104
|
+
function isParameter(masked: string, open: number, close: number): boolean {
|
|
105
|
+
const paren = enclosingParen(masked, open);
|
|
106
|
+
if (paren < 0) return false;
|
|
107
|
+
const end = closing(masked, paren);
|
|
108
|
+
if (end < close) return false;
|
|
109
|
+
// A call's arguments are followed by neither: `make({ fetch }).then(go)`, `make({ fetch });`.
|
|
110
|
+
return /^\s*(?:=>|\{|:(?!:))/.test(masked.slice(end + 1, end + 64));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Every name the object patterns in binding positions of `masked` bind. */
|
|
114
|
+
export function destructuredNames(masked: string): ReadonlySet<string> {
|
|
115
|
+
const names = new Set<string>();
|
|
116
|
+
for (let open = masked.indexOf('{'); open >= 0; open = masked.indexOf('{', open + 1)) {
|
|
117
|
+
const position = mayBind(masked, open);
|
|
118
|
+
if (position === undefined) continue;
|
|
119
|
+
const close = closing(masked, open);
|
|
120
|
+
if (close < 0 || (position === 'parameter' && !isParameter(masked, open, close))) continue;
|
|
121
|
+
for (const name of patternNames(masked.slice(open + 1, close), 'object')) names.add(name);
|
|
122
|
+
}
|
|
123
|
+
return names;
|
|
124
|
+
}
|
package/src/browser-transport.ts
CHANGED
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
// imported by either; a request made inside an installed package (the walk ends at the package
|
|
14
14
|
// boundary); a fetch reached through a computed member (`globalThis['fetch']`); and a bare
|
|
15
15
|
// `fetch(` in a file that also binds a local `fetch` (`bindsFetch`). A floor, not a proof.
|
|
16
|
+
//
|
|
17
|
+
// The global `fetch` PASSED ON — `rpc({ fetch })`, `const f = window.fetch` — is the same bypass
|
|
18
|
+
// one module later (`transport-values.ts`), reported with a fix that removes the hand-off.
|
|
16
19
|
|
|
17
20
|
import { ERROR_DOCS_URL, maskLiterals } from '@ultimat3/core';
|
|
18
21
|
import { commentSafe } from './comment-safe';
|
|
@@ -24,9 +27,12 @@ import { barrelImports } from './server-barrels';
|
|
|
24
27
|
import { isTest } from './source-files';
|
|
25
28
|
import type { TransportCall, TransportShape } from './transport-calls';
|
|
26
29
|
import { transportCalls } from './transport-calls';
|
|
30
|
+
import { fetchValues } from './transport-values';
|
|
27
31
|
|
|
28
32
|
export interface Bypass extends TransportCall {
|
|
29
33
|
readonly file: string;
|
|
34
|
+
/** The global handed on as a value rather than called here (`transport-values.ts`). */
|
|
35
|
+
readonly passed?: boolean;
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
export interface ServerBarrel extends BarrelImport {
|
|
@@ -90,6 +96,10 @@ export function checkBrowserTransport(input: TransportInput): {
|
|
|
90
96
|
if (input.seams.get(call.shape) === file) continue;
|
|
91
97
|
bypasses.push({ ...call, file });
|
|
92
98
|
}
|
|
99
|
+
for (const value of fetchValues(source)) {
|
|
100
|
+
if (input.seams.get(value.shape) === file) continue;
|
|
101
|
+
bypasses.push({ ...value, file, passed: true });
|
|
102
|
+
}
|
|
93
103
|
for (const found of barrelImports(source, input.barrels)) {
|
|
94
104
|
if (input.ownsBarrel?.(file, found.barrel) === true) continue;
|
|
95
105
|
barrels.push({ ...found, file });
|
|
@@ -137,6 +147,7 @@ const siteOf = (site: { readonly file: string; readonly line: number }): string
|
|
|
137
147
|
* command re-reads the tree; the comment is the edit, because only the finding knows the line.
|
|
138
148
|
*/
|
|
139
149
|
export function bypassFinding(bypass: Bypass, context: FindingContext): Finding {
|
|
150
|
+
if (bypass.passed === true) return passedFinding(bypass, context);
|
|
140
151
|
const holder = context.holder(bypass.shape);
|
|
141
152
|
const site = siteOf(bypass);
|
|
142
153
|
return {
|
|
@@ -148,6 +159,23 @@ export function bypassFinding(bypass: Bypass, context: FindingContext): Finding
|
|
|
148
159
|
};
|
|
149
160
|
}
|
|
150
161
|
|
|
162
|
+
/**
|
|
163
|
+
* The global handed to another module: the request happens THERE, through a property no rule reads,
|
|
164
|
+
* so the edit is here — stop handing it on (a typed client already sends through the seam) — and
|
|
165
|
+
* the module that took it is the one to move onto the replacement.
|
|
166
|
+
*/
|
|
167
|
+
function passedFinding(bypass: Bypass, context: FindingContext): Finding {
|
|
168
|
+
const holder = context.holder(bypass.shape);
|
|
169
|
+
const site = siteOf(bypass);
|
|
170
|
+
return {
|
|
171
|
+
code: 'X_BROWSER_TRANSPORT_BYPASS',
|
|
172
|
+
at: `${bypass.file}:${bypass.line}`,
|
|
173
|
+
cause: `${site} passes the global ${bypass.spelled} as a value in browser-reachable code; whatever receives it calls it directly, and ${holder === undefined ? 'no module may' : `only ${holder} may`}, so those requests skip the page's record store, idempotency header and principal fence`,
|
|
174
|
+
fix: `${context.rerun} # after deleting ${bypass.spelled} at ${site} (rpc() and queryClient() send through clientTransport when given none) and making the module that took it use ${REPLACEMENT.get(bypass.shape) ?? ''}`,
|
|
175
|
+
docs: ERROR_DOCS_URL,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
151
179
|
export function barrelFinding(site: ServerBarrel, context: FindingContext): Finding {
|
|
152
180
|
const at = siteOf(site);
|
|
153
181
|
return {
|
package/src/ci-log.ts
CHANGED
|
@@ -46,17 +46,40 @@ export function parseLogLines(log: string): readonly CiLogLine[] {
|
|
|
46
46
|
const columns = line.split('\t');
|
|
47
47
|
const tabbed = columns.length >= 3;
|
|
48
48
|
const rest = tabbed ? columns.slice(2).join('\t') : line;
|
|
49
|
-
const text = rest.replace(STAMP, '').replace(
|
|
49
|
+
const text = rest.replace(STAMP, '').replace(MARKER, '');
|
|
50
50
|
if (text.startsWith('##[endgroup]')) continue;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
text,
|
|
55
|
-
});
|
|
51
|
+
const job = tabbed ? (columns[0] ?? '') : '';
|
|
52
|
+
const step = tabbed ? (columns[1] ?? '') : '';
|
|
53
|
+
for (const part of unannotated(text)) out.push({ job, step, text: part });
|
|
56
54
|
}
|
|
57
55
|
return out;
|
|
58
56
|
}
|
|
59
57
|
|
|
58
|
+
/**
|
|
59
|
+
* The runner's own line markers: `##[group]` opens a fold, and an annotation is printed with its
|
|
60
|
+
* level as a prefix (`##[error]X_LINT_FAILED`). Neither is the text the step wrote.
|
|
61
|
+
*/
|
|
62
|
+
const MARKER = /^##\[(?:group|error|warning|notice|debug)\]/;
|
|
63
|
+
/** A workflow command a step echoed whole: `::error file=a.ts,title=t::message`. */
|
|
64
|
+
const ANNOTATION = /^::(?:error|warning|notice|debug)(?:\s[^:]*)?::(.*)$/;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* An annotation's message, decoded: GitHub's encoding writes a newline as `%0A` (and `%` as
|
|
68
|
+
* `%25`), so a three-line finding inside one `::error` is one line of the log until this splits it
|
|
69
|
+
* back into the lines `renderFinding` wrote. MESSAGE data escapes only `%`, CR and LF — `%3A` and
|
|
70
|
+
* `%2C` are property escapes, and decoding them here would corrupt a URL in a fix. `%25` goes
|
|
71
|
+
* last, so an escaped `%250A` comes back as the text `%0A` rather than a line break.
|
|
72
|
+
*/
|
|
73
|
+
function unannotated(text: string): readonly string[] {
|
|
74
|
+
const message = ANNOTATION.exec(text)?.[1];
|
|
75
|
+
if (message === undefined) return [text];
|
|
76
|
+
return message
|
|
77
|
+
.replaceAll('%0D', '')
|
|
78
|
+
.split('%0A')
|
|
79
|
+
.map((part) => part.replaceAll('%25', '%'))
|
|
80
|
+
.filter((part) => part.trim() !== '');
|
|
81
|
+
}
|
|
82
|
+
|
|
60
83
|
/** Every job the log carries a line for, in the order they first appear. */
|
|
61
84
|
export function jobsInLog(lines: readonly CiLogLine[]): readonly string[] {
|
|
62
85
|
const seen: string[] = [];
|
|
@@ -75,16 +98,54 @@ const CODE = /^(X_[A-Z][A-Z0-9_]*)/;
|
|
|
75
98
|
// `CODE (path) [step=unit]` — an end-anchor matches only what follows the brackets, the match
|
|
76
99
|
// fails, and the path is dropped. With no step the optional group is absent and the
|
|
77
100
|
// parenthesised group is still the last thing on the line.
|
|
78
|
-
|
|
101
|
+
// A `[from=ci-log …]` marker (`output.ts`'s `fromLabel`) may close the head after both: an `x ci`
|
|
102
|
+
// render read back by another `x ci` must still yield its locators.
|
|
103
|
+
const LOCATOR = /\(([^()]+)\)(?=\s*(?:\[step=[^[\]]+\]\s*)?(?:\[from=[^[\]]*\]\s*)?$)/;
|
|
79
104
|
// The second, non-path locator the renderer prints on the head — `meta.step` in the same
|
|
80
105
|
// brackets-keyed form (`[step=lint]`) `renderFinding` writes — so a merge gap's gate step name
|
|
81
106
|
// or any future non-path identifier survives the round-trip too. Its own brackets are what
|
|
82
107
|
// `LOCATOR`'s lookahead stands aside for, so the two cannot collide in one head.
|
|
83
|
-
const STEP_LOCATOR = /\[step=([^[\]]+)\]\s
|
|
108
|
+
const STEP_LOCATOR = /\[step=([^[\]]+)\]\s*(?:\[from=[^[\]]*\]\s*)?$/;
|
|
84
109
|
|
|
85
110
|
const after = (text: string, label: string): string | undefined =>
|
|
86
111
|
text.trim().startsWith(label) ? text.trim().slice(label.length).trim() : undefined;
|
|
87
112
|
|
|
113
|
+
// `commentBlock`'s fence (`foreign-text.ts`), as it reaches a log: `x ci` run INSIDE a job prints a
|
|
114
|
+
// fenced value through `singleLine`, so its newlines arrive as the two characters `\n`. The
|
|
115
|
+
// fence is transport around the value, never the value — the reader is owed the command.
|
|
116
|
+
const FENCE_OPEN = /^<comment id="[^"]*">$/;
|
|
117
|
+
const FENCE_ONE_LINE = /^<comment id="[^"]*">(?:\\n)?([\s\S]*?)(?:\\n)?<\/comment>$/;
|
|
118
|
+
const FENCE_CLOSE = '</comment>';
|
|
119
|
+
|
|
120
|
+
/** One labelled field of a finding block, and the index of the line after it. */
|
|
121
|
+
interface Field {
|
|
122
|
+
readonly value: string;
|
|
123
|
+
readonly next: number;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The value of `label:` on line `index`, with a fence around it taken off — whether the fence was
|
|
128
|
+
* flattened onto one line or spread over the lines that follow until `</comment>`.
|
|
129
|
+
*/
|
|
130
|
+
function fieldAt(texts: readonly string[], index: number, label: string): Field | undefined {
|
|
131
|
+
const value = after(texts[index] ?? '', label);
|
|
132
|
+
if (value === undefined) return undefined;
|
|
133
|
+
const flat = FENCE_ONE_LINE.exec(value);
|
|
134
|
+
if (flat !== null) {
|
|
135
|
+
return { value: (flat[1] ?? '').split(String.raw`\n`).join(' ').trim(), next: index + 1 };
|
|
136
|
+
}
|
|
137
|
+
if (!FENCE_OPEN.test(value)) return { value, next: index + 1 };
|
|
138
|
+
const close = texts.indexOf(FENCE_CLOSE, index + 1);
|
|
139
|
+
if (close === -1) return { value, next: index + 1 };
|
|
140
|
+
return {
|
|
141
|
+
value: texts
|
|
142
|
+
.slice(index + 1, close)
|
|
143
|
+
.join(' ')
|
|
144
|
+
.trim(),
|
|
145
|
+
next: close + 1,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
88
149
|
// The `meta.step` locator the renderer prints in the head (`output.ts:185-189`): a gate step name
|
|
89
150
|
// the finding carries on `meta`, never on `at`. Total on every shape `Finding.meta` may take —
|
|
90
151
|
// the field is optional, and a malformed `meta` (a non-object value, an array) is read as "no
|
|
@@ -129,13 +190,15 @@ export function findingsFrom(lines: readonly CiLogLine[]): readonly Finding[] {
|
|
|
129
190
|
for (let index = 0; index < texts.length; index += 1) {
|
|
130
191
|
const head = CODE.exec(texts[index] ?? '');
|
|
131
192
|
if (head === null) continue;
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
if (
|
|
193
|
+
const causeField = fieldAt(texts, index + 1, 'cause:');
|
|
194
|
+
const fixField = causeField === undefined ? undefined : fieldAt(texts, causeField.next, 'fix:');
|
|
195
|
+
if (causeField === undefined || fixField === undefined) continue;
|
|
196
|
+
const cause = causeField.value;
|
|
197
|
+
const fix = fixField.value;
|
|
135
198
|
const code = head[1] ?? '';
|
|
136
199
|
const at = LOCATOR.exec(texts[index] ?? '')?.[1];
|
|
137
200
|
const step = STEP_LOCATOR.exec(texts[index] ?? '')?.[1];
|
|
138
|
-
const docs = after(texts[
|
|
201
|
+
const docs = after(texts[fixField.next] ?? '', 'docs:');
|
|
139
202
|
// Step name and any other reconstructed structured fact ride on `meta`, so the
|
|
140
203
|
// reconstructed finding has a place to put a non-path locator `at` cannot carry.
|
|
141
204
|
const meta = step === undefined ? undefined : { step };
|
|
@@ -155,7 +218,7 @@ export function findingsFrom(lines: readonly CiLogLine[]): readonly Finding[] {
|
|
|
155
218
|
seen.add(findingKey(finding));
|
|
156
219
|
out.push(finding);
|
|
157
220
|
}
|
|
158
|
-
index
|
|
221
|
+
index = fixField.next - 1;
|
|
159
222
|
}
|
|
160
223
|
return out;
|
|
161
224
|
}
|
package/src/cmd-affected-spec.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// `x affected`'s declaration, apart from its body: the parser, `x help` and the `errors` step
|
|
2
2
|
// read it without loading `cmd-affected.ts`, which `registry.ts` imports only when the command runs.
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { DEFAULT_BASE_HELP } from './affected-base';
|
|
5
5
|
import type { CommandSpec } from './parse';
|
|
6
6
|
|
|
7
7
|
export const affectedSpec: CommandSpec = {
|
|
@@ -12,13 +12,17 @@ export const affectedSpec: CommandSpec = {
|
|
|
12
12
|
{
|
|
13
13
|
name: 'base',
|
|
14
14
|
type: 'string',
|
|
15
|
-
summary: `git ref to diff against, merge-base style (default: ${
|
|
15
|
+
summary: `git ref to diff against, merge-base style (default: ${DEFAULT_BASE_HELP})`,
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
18
|
name: 'dirty',
|
|
19
19
|
type: 'boolean',
|
|
20
20
|
summary: 'also count uncommitted work — every agent sharing this checkout, not only yours',
|
|
21
21
|
},
|
|
22
|
-
{
|
|
22
|
+
{
|
|
23
|
+
name: 'paths',
|
|
24
|
+
type: 'boolean',
|
|
25
|
+
summary: 'stdout is the directories alone, one per line; notes and the summary go to stderr',
|
|
26
|
+
},
|
|
23
27
|
],
|
|
24
28
|
};
|