@ultimat3/cli 31.0.0 → 31.1.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 +5 -0
- package/package.json +29 -29
- package/src/affected-base.ts +51 -0
- package/src/affected.ts +29 -10
- 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-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-verify-spec.ts +2 -2
- package/src/error-codes-package.ts +38 -0
- package/src/error-codes.ts +5 -21
- package/src/mcp-errors.ts +2 -0
- package/src/messages-gate.ts +6 -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/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/tsconfig-aliases.ts +85 -0
- 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 +7 -1
package/CLAUDE.md
CHANGED
|
@@ -60,6 +60,7 @@ Commands: `bun test ./packages/cli/` (repo root: the preload),
|
|
|
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.1.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.1.0",
|
|
57
|
+
"@ultimat3/admin": "31.1.0",
|
|
58
|
+
"@ultimat3/ai": "31.1.0",
|
|
59
|
+
"@ultimat3/auth": "31.1.0",
|
|
60
|
+
"@ultimat3/cache": "31.1.0",
|
|
61
|
+
"@ultimat3/core": "31.1.0",
|
|
62
|
+
"@ultimat3/db": "31.1.0",
|
|
63
|
+
"@ultimat3/entity": "31.1.0",
|
|
64
|
+
"@ultimat3/flags": "31.1.0",
|
|
65
|
+
"@ultimat3/http": "31.1.0",
|
|
66
|
+
"@ultimat3/i18n": "31.1.0",
|
|
67
|
+
"@ultimat3/jobs": "31.1.0",
|
|
68
|
+
"@ultimat3/mail": "31.1.0",
|
|
69
|
+
"@ultimat3/manifest": "31.1.0",
|
|
70
|
+
"@ultimat3/mcp": "31.1.0",
|
|
71
|
+
"@ultimat3/money": "31.1.0",
|
|
72
|
+
"@ultimat3/notify": "31.1.0",
|
|
73
|
+
"@ultimat3/policy": "31.1.0",
|
|
74
|
+
"@ultimat3/pwa": "31.1.0",
|
|
75
|
+
"@ultimat3/query": "31.1.0",
|
|
76
|
+
"@ultimat3/realtime": "31.1.0",
|
|
77
|
+
"@ultimat3/render": "31.1.0",
|
|
78
|
+
"@ultimat3/schema": "31.1.0",
|
|
79
|
+
"@ultimat3/scraping": "31.1.0",
|
|
80
|
+
"@ultimat3/seo": "31.1.0",
|
|
81
|
+
"@ultimat3/storage": "31.1.0",
|
|
82
|
+
"@ultimat3/testing": "31.1.0",
|
|
83
|
+
"@ultimat3/time": "31.1.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,
|
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
|
};
|
package/src/cmd-affected.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { msg } from './messages';
|
|
|
14
14
|
import type { CommandResult, JsonValue } from './output';
|
|
15
15
|
import { flagBool } from './parse';
|
|
16
16
|
import { renderTable } from './table';
|
|
17
|
+
import { writeLine } from './write-line';
|
|
17
18
|
|
|
18
19
|
const HEADER = ['workspace', 'dir'] as const;
|
|
19
20
|
|
|
@@ -36,81 +37,94 @@ export const AFFECTED_MESSAGE_KEYS = [
|
|
|
36
37
|
'cli.affected.testsAll',
|
|
37
38
|
] as const;
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
40
|
+
/**
|
|
41
|
+
* `--paths` is for `bun test $(x affected --paths)`, so its stdout is the directories and nothing
|
|
42
|
+
* else: each one written here, on fd 1, and the rest of the render — the notes and the `✓` summary,
|
|
43
|
+
* which a shell would split into bogus arguments — sent to fd 2 by `stream: 'stderr'`. The one
|
|
44
|
+
* write a command makes itself: `CommandResult` has no "bare stdout" channel, and the one sink
|
|
45
|
+
* `dispatch` picks per result cannot split a result across both fds. `writeOut` is injectable so a
|
|
46
|
+
* test reads fd 1 exactly as a shell would.
|
|
47
|
+
*/
|
|
48
|
+
export function createAffectedCommand(writeOut: (line: string) => void = writeLine): CliCommand {
|
|
49
|
+
return { spec: affectedSpec, run: (ctx) => runAffected(ctx, writeOut) };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function runAffected(
|
|
53
|
+
ctx: CommandContext,
|
|
54
|
+
writeOut: (line: string) => void,
|
|
55
|
+
): Promise<CommandResult> {
|
|
56
|
+
// The one resolver `x test --affected` narrows with, so this command reports exactly what that
|
|
57
|
+
// one runs. It reads `--base` before git is spawned (a malformed ref must not cost a
|
|
58
|
+
// subprocess) and takes the diff at the CHECKOUT root, which is what git prints paths against.
|
|
59
|
+
const { selection, root, plan } = await affectedScope({
|
|
60
|
+
runner: ctx.runner,
|
|
61
|
+
cwd: ctx.cwd,
|
|
62
|
+
args: ctx.args,
|
|
63
|
+
command: 'affected',
|
|
64
|
+
});
|
|
65
|
+
const params = { base: selection.base, changed: plan.changed.length };
|
|
66
|
+
const tests = await appTestScope(ctx.cwd, root, plan.changed);
|
|
67
|
+
const table = renderTable(
|
|
68
|
+
HEADER,
|
|
69
|
+
plan.workspaces.map((workspace) => [workspace.name, workspace.dir]),
|
|
70
|
+
).map((line) => ` ${line}`);
|
|
71
|
+
const data: JsonValue = {
|
|
72
|
+
base: selection.base,
|
|
73
|
+
dirty: selection.dirty,
|
|
74
|
+
root,
|
|
75
|
+
changed: [...plan.changed],
|
|
76
|
+
ignored: [...plan.ignored],
|
|
77
|
+
rootWide: [...plan.rootWide],
|
|
78
|
+
workspaces: plan.workspaces.map((workspace) => ({
|
|
79
|
+
name: workspace.name,
|
|
80
|
+
dir: workspace.dir,
|
|
81
|
+
})),
|
|
82
|
+
paths: plan.workspaces.map((workspace) => workspace.dir),
|
|
83
|
+
...(tests === undefined
|
|
84
|
+
? {}
|
|
85
|
+
: {
|
|
86
|
+
tests: {
|
|
87
|
+
app: tests.app,
|
|
88
|
+
all: tests.all,
|
|
89
|
+
forcing: [...tests.forcing],
|
|
90
|
+
files: [...tests.tests],
|
|
91
|
+
},
|
|
92
|
+
}),
|
|
93
|
+
};
|
|
94
|
+
const bare = flagBool(ctx.args, 'paths') && !ctx.args.json;
|
|
95
|
+
if (bare) for (const workspace of plan.workspaces) writeOut(workspace.dir);
|
|
96
|
+
return {
|
|
97
|
+
...(bare ? { stream: 'stderr' as const } : {}),
|
|
98
|
+
// An empty answer is a fact, not a failure: a `.md`-only diff genuinely re-checks nothing,
|
|
99
|
+
// and reporting it red would fail a build for editing a doc. The count is in the summary and
|
|
100
|
+
// `data.changed`/`data.ignored` say what was looked at, so "green because nothing is
|
|
101
|
+
// affected" is never mistaken for "green because everything passed".
|
|
102
|
+
ok: true,
|
|
103
|
+
command: 'affected',
|
|
104
|
+
summary:
|
|
105
|
+
plan.workspaces.length === 0
|
|
106
|
+
? msg('cli.affected.none', params)
|
|
107
|
+
: msg('cli.affected.count', { ...params, count: plan.workspaces.length }),
|
|
108
|
+
lines: [
|
|
109
|
+
...(selection.dirty ? [msg('cli.affected.dirty')] : []),
|
|
69
110
|
...(tests === undefined
|
|
70
|
-
?
|
|
71
|
-
:
|
|
72
|
-
tests
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
//
|
|
82
|
-
//
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
: msg('cli.affected.count', { ...params, count: plan.workspaces.length }),
|
|
91
|
-
lines: [
|
|
92
|
-
...(selection.dirty ? [msg('cli.affected.dirty')] : []),
|
|
93
|
-
...(tests === undefined
|
|
94
|
-
? []
|
|
95
|
-
: [
|
|
96
|
-
tests.all
|
|
97
|
-
? msg('cli.affected.testsAll', {
|
|
98
|
-
files: `${tests.forcing.slice(0, 3).join(', ')}${tests.forcing.length > 3 ? ` (+${tests.forcing.length - 3})` : ''}`,
|
|
99
|
-
})
|
|
100
|
-
: msg('cli.affected.tests', { count: tests.tests.length }),
|
|
101
|
-
]),
|
|
102
|
-
...(plan.rootWide.length === 0
|
|
103
|
-
? []
|
|
104
|
-
: [msg('cli.affected.rootWide', { files: plan.rootWide.join(', ') })]),
|
|
105
|
-
...(plan.workspaces.length === 0
|
|
106
|
-
? []
|
|
107
|
-
: // `--paths` changes only what the human sees; `--json` carries both projections on
|
|
108
|
-
// every run, so the two renderers can never state different sets.
|
|
109
|
-
flagBool(ctx.args, 'paths')
|
|
110
|
-
? plan.workspaces.map((workspace) => workspace.dir)
|
|
111
|
-
: table),
|
|
112
|
-
],
|
|
113
|
-
data,
|
|
114
|
-
};
|
|
115
|
-
},
|
|
116
|
-
};
|
|
111
|
+
? []
|
|
112
|
+
: [
|
|
113
|
+
tests.all
|
|
114
|
+
? msg('cli.affected.testsAll', {
|
|
115
|
+
files: `${tests.forcing.slice(0, 3).join(', ')}${tests.forcing.length > 3 ? ` (+${tests.forcing.length - 3})` : ''}`,
|
|
116
|
+
})
|
|
117
|
+
: msg('cli.affected.tests', { count: tests.tests.length }),
|
|
118
|
+
]),
|
|
119
|
+
...(plan.rootWide.length === 0
|
|
120
|
+
? []
|
|
121
|
+
: [msg('cli.affected.rootWide', { files: plan.rootWide.join(', ') })]),
|
|
122
|
+
// `--paths` changes only what the human sees; `--json` carries both projections on every
|
|
123
|
+
// run, so the two renderers can never state different sets.
|
|
124
|
+
...(plan.workspaces.length === 0 || bare ? [] : table),
|
|
125
|
+
],
|
|
126
|
+
data,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export const affectedCommand: CliCommand = createAffectedCommand();
|
package/src/cmd-ci.ts
CHANGED
|
@@ -275,9 +275,12 @@ async function inspect(
|
|
|
275
275
|
// this repair closes — so when the log had nothing, the finding reads nothing.
|
|
276
276
|
findings.push({
|
|
277
277
|
...finding,
|
|
278
|
-
//
|
|
279
|
-
// log author's instruction, not this CLI's
|
|
280
|
-
|
|
278
|
+
// Tagged, never fenced inside the value: the log is foreign text, and a `fix:` read from it
|
|
279
|
+
// is the log author's instruction, not this CLI's — `source` says so to a machine, and
|
|
280
|
+
// `output-findings.ts` never rewrites it into a runnable `bunx x`. A `<comment>` fence
|
|
281
|
+
// INSIDE `fix` reached the human render as one line of markup and literal `\n` (31.0
|
|
282
|
+
// field report), so the value stays the clean text and the job rides on `meta.job`.
|
|
283
|
+
meta: { ...finding.meta, job: name },
|
|
281
284
|
source: 'ci-log',
|
|
282
285
|
});
|
|
283
286
|
}
|
package/src/cmd-pr-spec.ts
CHANGED
|
@@ -7,7 +7,7 @@ export const PR_SUBCOMMANDS = ['review', 'resolve', 'reply'] as const;
|
|
|
7
7
|
|
|
8
8
|
export const prSpec: CommandSpec = {
|
|
9
9
|
name: 'pr',
|
|
10
|
-
summary: '
|
|
10
|
+
summary: 'reviews, comments, bots that did not review, and inline threads; resolve or reply',
|
|
11
11
|
usage:
|
|
12
12
|
'x pr review [--pr <n>] [--repo owner/name] [--all] [--full] | x pr resolve <thread-id> | x pr reply <thread-id> --body "…"',
|
|
13
13
|
subcommands: PR_SUBCOMMANDS,
|