@ultimat3/cli 31.21.0 → 31.22.1
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 +1 -1
- package/README.md +11 -6
- package/package.json +29 -29
- package/src/cmd-db.ts +5 -18
- package/src/cmd-doctor.ts +8 -3
- package/src/cmd-mcp.ts +6 -1
- package/src/cmd-verify.ts +19 -15
- package/src/db-schema-dump.ts +20 -0
- package/src/dev-lock.ts +26 -5
- package/src/doctor-guards.ts +27 -12
- package/src/error-codes-doctor.ts +6 -4
- package/src/guards.ts +66 -28
- package/src/lint-findings.ts +34 -10
- package/src/mcp-agent-host.ts +107 -0
- package/src/mcp-errors.ts +2 -0
- package/src/mcp-host.ts +22 -0
- package/src/mcp-request-statements.ts +129 -0
- package/src/messages.ts +0 -2
- package/src/runtime-cache.ts +12 -3
- package/src/templates/guard-repo-await-in-loop-test.ts +89 -0
- package/src/templates/guard-repo-await-in-loop.ts +214 -0
- package/src/templates/guard-repo-unbounded-test.ts +56 -0
- package/src/templates/guard-repo-unbounded.ts +197 -0
- package/src/templates/scaffold-claude-agents.ts +4 -4
- package/src/templates/scaffold-claude-hook.ts +40 -0
- package/src/templates/scaffold-claude.ts +22 -6
- package/src/templates/scaffold-docs.ts +2 -7
- package/src/templates/scaffold-guards.ts +6 -0
- package/src/verify-changed.ts +32 -5
- package/src/verify-checks.ts +14 -6
- package/src/verify-progress.ts +32 -1
- package/wiki/CLI-Reference.md +19 -8
- package/wiki/MCP-And-AI.md +7 -3
- package/wiki/Tutorial-02-First-Feature.md +1 -1
- package/wiki/Upgrading.md +6 -0
package/CLAUDE.md
CHANGED
|
@@ -174,7 +174,7 @@ Commands: `bun test ./packages/cli/` (repo root: the preload),
|
|
|
174
174
|
|---|---|
|
|
175
175
|
| `cmd-registries.ts` / `cmd-jobs.ts` / `cmd-tasks.ts` / `cmd-policy.ts` / `cmd-i18n.ts` | project a framework registry; each pairs CLI wiring with a facts module |
|
|
176
176
|
| `cmd-auth.ts` / `cmd-auth-spec.ts` / `doctor-auth.ts` | `x auth seal-mfa`: seals plaintext `x_users.mfa_secret` through auth's `sealMfaSecrets` |
|
|
177
|
-
| `cmd-mcp.ts` / `mcp-host.ts` / `mcp-errors.ts` / `mcp-db-target.ts` / `mcp-host-shell.ts` / `mcp-test-{output,run}.ts` | `x mcp serve`:
|
|
177
|
+
| `cmd-mcp.ts` / `mcp-host.ts` / `mcp-errors.ts` / `mcp-db-target.ts` / `mcp-host-shell.ts` / `mcp-test-{output,run}.ts` | `x mcp serve`: 23 tools, two transports, stdout only JSON-RPC under stdio (`cmd-mcp-stdio.test.ts`); `tests.run`/`verify.run` ARE `x test`/`x verify`, `ULTIMATE_ENV` unset in children (`mcp-host.parity.test.ts`) † |
|
|
178
178
|
| `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 |
|
|
179
179
|
| `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 |
|
|
180
180
|
| `cmd-pr.ts` / `cmd-ci.ts` / `ci-runs.ts` / `ci-tested.ts` | GitHub through `gh`, schema-parsed; not gate steps † |
|
package/README.md
CHANGED
|
@@ -165,9 +165,10 @@ execute and carries its `why`; `x doctor` prints them. A `--shard` slice hands i
|
|
|
165
165
|
|
|
166
166
|
A step has a **deadline** — 8 minutes for the six suites, 5 for every other step,
|
|
167
167
|
`"stepTimeoutMs": { "<step>": ms }` in `x.verify.json` to change one. Past it the step fails by
|
|
168
|
-
name with `X_VERIFY_STEP_TIMEOUT` and every process it started is killed.
|
|
169
|
-
|
|
170
|
-
|
|
168
|
+
name with `X_VERIFY_STEP_TIMEOUT` and every process it started is killed. Each finished step is
|
|
169
|
+
one line on stderr — under `--json` a JSON one (`{"step":"lint","ok":true,"ms":21987}`), otherwise
|
|
170
|
+
`✓ lint 22.0s`, and a red step names its narrowest re-run (`✗ unit 3.1s → x test unit --filter …
|
|
171
|
+
--json`, `As of 31.22`); stdout stays the single document.
|
|
171
172
|
|
|
172
173
|
An app extends the gate with its own conventions, never with its own step: a file in `guards/`
|
|
173
174
|
exports a `guard` whose `check(root, sources)` returns `Finding[]`, and the `boundaries` step runs
|
|
@@ -175,9 +176,13 @@ every one of them. `sources` is the run's ONE read of the app (`GuardSources`):
|
|
|
175
176
|
walked and read once however many guards ask, and `compiled(path)` is a stylesheet as the build
|
|
176
177
|
compiles it. Nothing registers a guard — the directory is the registration — and what a guard returns
|
|
177
178
|
is held to the same error contract shipped source is (`X_GUARD_INVALID`, `X_GUARD_FAILED`,
|
|
178
|
-
`X_GUARD_FINDING_INVALID`).
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
`X_GUARD_FINDING_INVALID`). A guard that exports `severity: 'warning'` is **report-only** (`As of
|
|
180
|
+
31.22`): its findings ride the step as `warnings` — in `--json` and on the step line, never a
|
|
181
|
+
failure — so a rule ships to every app before the apps are clean of it; a finding that breaks the
|
|
182
|
+
contract fails either way. `repo-await-in-loop` and `repo-unbounded` ship that way. `x g guard
|
|
183
|
+
<name>` scaffolds one with its test — the shipped guard of that name where there is one (`x new`
|
|
184
|
+
writes all twenty-five), the blank template otherwise — and `x doctor` warns of each shipped one an
|
|
185
|
+
app does not hold (`X_SHIPPED_GUARD_MISSING`, beside the verdict, never in it).
|
|
181
186
|
|
|
182
187
|
## Layout
|
|
183
188
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/cli",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.22.1",
|
|
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.22.1",
|
|
57
|
+
"@ultimat3/admin": "31.22.1",
|
|
58
|
+
"@ultimat3/ai": "31.22.1",
|
|
59
|
+
"@ultimat3/auth": "31.22.1",
|
|
60
|
+
"@ultimat3/cache": "31.22.1",
|
|
61
|
+
"@ultimat3/core": "31.22.1",
|
|
62
|
+
"@ultimat3/db": "31.22.1",
|
|
63
|
+
"@ultimat3/entity": "31.22.1",
|
|
64
|
+
"@ultimat3/flags": "31.22.1",
|
|
65
|
+
"@ultimat3/http": "31.22.1",
|
|
66
|
+
"@ultimat3/i18n": "31.22.1",
|
|
67
|
+
"@ultimat3/jobs": "31.22.1",
|
|
68
|
+
"@ultimat3/mail": "31.22.1",
|
|
69
|
+
"@ultimat3/manifest": "31.22.1",
|
|
70
|
+
"@ultimat3/mcp": "31.22.1",
|
|
71
|
+
"@ultimat3/money": "31.22.1",
|
|
72
|
+
"@ultimat3/notify": "31.22.1",
|
|
73
|
+
"@ultimat3/policy": "31.22.1",
|
|
74
|
+
"@ultimat3/pwa": "31.22.1",
|
|
75
|
+
"@ultimat3/query": "31.22.1",
|
|
76
|
+
"@ultimat3/realtime": "31.22.1",
|
|
77
|
+
"@ultimat3/render": "31.22.1",
|
|
78
|
+
"@ultimat3/schema": "31.22.1",
|
|
79
|
+
"@ultimat3/scraping": "31.22.1",
|
|
80
|
+
"@ultimat3/seo": "31.22.1",
|
|
81
|
+
"@ultimat3/storage": "31.22.1",
|
|
82
|
+
"@ultimat3/testing": "31.22.1",
|
|
83
|
+
"@ultimat3/time": "31.22.1",
|
|
84
84
|
"babel-preset-solid": "^1.9.16"
|
|
85
85
|
}
|
|
86
86
|
}
|
package/src/cmd-db.ts
CHANGED
|
@@ -27,12 +27,8 @@ import { stepFinding } from './db-finding';
|
|
|
27
27
|
import { generateAppMigration, unrenderedJson, unrenderedLines } from './db-generate';
|
|
28
28
|
import { liveObjectDrift } from './db-object-drift';
|
|
29
29
|
import { layTemplate } from './db-reset-template';
|
|
30
|
-
import {
|
|
31
|
-
|
|
32
|
-
refreshSchemaDump,
|
|
33
|
-
type SchemaDumpRefresh,
|
|
34
|
-
schemaDumpJson,
|
|
35
|
-
} from './db-schema-refresh';
|
|
30
|
+
import { schemaDumpLines } from './db-schema-dump';
|
|
31
|
+
import { afterWrittenMigration, refreshSchemaDump, schemaDumpJson } from './db-schema-refresh';
|
|
36
32
|
import type { SeedPassRow } from './db-seed';
|
|
37
33
|
import {
|
|
38
34
|
discoverSeeds,
|
|
@@ -149,7 +145,7 @@ async function runGen(ctx: CommandContext, root: string, name: string): Promise<
|
|
|
149
145
|
: msg('cli.db.gen.unchanged'),
|
|
150
146
|
findings: [...generated.findings, ...dumpFindings],
|
|
151
147
|
// `files` is what this command WROTE, so the empty array here was a false claim.
|
|
152
|
-
lines: [...generated.files.map((file) => ` ${file}`), ...
|
|
148
|
+
lines: [...generated.files.map((file) => ` ${file}`), ...schemaDumpLines(dump), ...lost],
|
|
153
149
|
data: {
|
|
154
150
|
outcome: generated.outcome,
|
|
155
151
|
migration: null,
|
|
@@ -169,7 +165,7 @@ async function runGen(ctx: CommandContext, root: string, name: string): Promise<
|
|
|
169
165
|
: msg('cli.db.gen.writtenDumpFailed', { id: migration.id }),
|
|
170
166
|
// Exit 1 with a migration on disk: the finding has to say so, or the next move is a duplicate.
|
|
171
167
|
findings: dumpFindings.map((finding) => afterWrittenMigration(finding, migration.id)),
|
|
172
|
-
lines: [...generated.files.map((file) => ` ${file}`), ...
|
|
168
|
+
lines: [...generated.files.map((file) => ` ${file}`), ...schemaDumpLines(dump), ...lost],
|
|
173
169
|
data: {
|
|
174
170
|
outcome: generated.outcome,
|
|
175
171
|
migration: migration.id,
|
|
@@ -184,15 +180,6 @@ async function runGen(ctx: CommandContext, root: string, name: string): Promise<
|
|
|
184
180
|
};
|
|
185
181
|
}
|
|
186
182
|
|
|
187
|
-
/**
|
|
188
|
-
* What the dump refresh did, one path per line — the same list `data.schemaDump` carries, so the
|
|
189
|
-
* human render and `--json` report one fact. A refresh that changed nothing prints nothing.
|
|
190
|
-
*/
|
|
191
|
-
const dumpLines = (dump: SchemaDumpRefresh): readonly string[] => [
|
|
192
|
-
...dump.written.map((file) => ` ${file}`),
|
|
193
|
-
...dump.removed.map((file) => ` - ${file}`),
|
|
194
|
-
];
|
|
195
|
-
|
|
196
183
|
/**
|
|
197
184
|
* The post-migrate report, rendered. Through `driftError` rather than a second literal: the
|
|
198
185
|
* three-line `X_DB_DRIFT` output is pinned by the framework contract, and this command must not be
|
|
@@ -237,7 +224,7 @@ async function runMigrate(
|
|
|
237
224
|
command: 'db',
|
|
238
225
|
summary,
|
|
239
226
|
findings,
|
|
240
|
-
lines:
|
|
227
|
+
lines: schemaDumpLines(dump),
|
|
241
228
|
data: {
|
|
242
229
|
applied: report.applied.map((entry) => entry.id),
|
|
243
230
|
skipped: report.skipped.length,
|
package/src/cmd-doctor.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { authStorageFindings } from './doctor-auth';
|
|
|
11
11
|
import { chartAlertsProbe, NOTHING_MISSING, withChartAlertsListing } from './doctor-chart-alerts';
|
|
12
12
|
import { coverageExcludesProbe, withCoverageExcludes } from './doctor-coverage';
|
|
13
13
|
import { embeddedDatabaseFinding } from './doctor-database';
|
|
14
|
-
import { shippedGuardsProbe, withGuardListing } from './doctor-guards';
|
|
14
|
+
import { missingGuardWarnings, shippedGuardsProbe, withGuardListing } from './doctor-guards';
|
|
15
15
|
import { offlineFallbackFinding } from './doctor-offline';
|
|
16
16
|
import { NO_POOLER_FACT, poolerFindings, withPoolerReport } from './doctor-pooler';
|
|
17
17
|
import { doctorPort, portFindings } from './doctor-port';
|
|
@@ -143,6 +143,7 @@ export async function reportDoctor(probe: DoctorProbe): Promise<CommandResult> {
|
|
|
143
143
|
// Asked once: `runDoctor` reads the verdict and the report beside it reads the numbers.
|
|
144
144
|
const pooler = probe.root === undefined ? NO_POOLER_FACT : await probe.pooler();
|
|
145
145
|
const findings = await runDoctor({ ...probe, pooler: async () => pooler });
|
|
146
|
+
const guardEntries = probe.root === undefined ? [] : await shippedGuardsProbe(probe.root);
|
|
146
147
|
const listed = withGuardListing(
|
|
147
148
|
{
|
|
148
149
|
ok: findings.length === 0,
|
|
@@ -155,7 +156,7 @@ export async function reportDoctor(probe: DoctorProbe): Promise<CommandResult> {
|
|
|
155
156
|
data: { count: findings.length, codes: findings.map((entry) => entry.code) },
|
|
156
157
|
},
|
|
157
158
|
// A listing beside the verdict, never part of it (`doctor-guards.ts` says why).
|
|
158
|
-
|
|
159
|
+
guardEntries,
|
|
159
160
|
);
|
|
160
161
|
// The second listing: what the coverage floor does not see (`doctor-coverage.ts`).
|
|
161
162
|
const covered = withCoverageExcludes(
|
|
@@ -176,7 +177,11 @@ export async function reportDoctor(probe: DoctorProbe): Promise<CommandResult> {
|
|
|
176
177
|
pooler,
|
|
177
178
|
);
|
|
178
179
|
// Last, and beside the verdict on `main`: the 31.16.0 checks (`doctor-warnings.ts`).
|
|
179
|
-
|
|
180
|
+
// A missing shipped guard among them (`X_SHIPPED_GUARD_MISSING`): a warning, so exit stays.
|
|
181
|
+
return withDoctorWarnings(reminded, [
|
|
182
|
+
...(await doctorWarnings(probe)),
|
|
183
|
+
...missingGuardWarnings(guardEntries),
|
|
184
|
+
]);
|
|
180
185
|
}
|
|
181
186
|
|
|
182
187
|
export const doctorCommand: CliCommand = {
|
package/src/cmd-mcp.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// `x mcp serve` — the framework's dev MCP server over stdio or HTTP. The
|
|
1
|
+
// `x mcp serve` — the framework's dev MCP server over stdio or HTTP. The tools, the JSON-RPC
|
|
2
2
|
// dispatch, both transports and the structural SQL refusals all come from `@ultimat3/mcp`; the CLI
|
|
3
3
|
// supplies only the app, the caller and the socket. A tool answered here would be a second answer
|
|
4
4
|
// to a question the framework already answers.
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
markListening,
|
|
8
8
|
nanoid,
|
|
9
9
|
renderFixShellArg,
|
|
10
|
+
setLogStream,
|
|
10
11
|
timingSafeEqual,
|
|
11
12
|
UltimateError,
|
|
12
13
|
} from '@ultimat3/core';
|
|
@@ -236,6 +237,10 @@ export const mcpCommand: CliCommand = {
|
|
|
236
237
|
});
|
|
237
238
|
}
|
|
238
239
|
const port = readPort(ctx);
|
|
240
|
+
// BEFORE the host imports an app module: under stdio fd 1 is the wire, and a module that logs
|
|
241
|
+
// as it loads (the reference app's demo-viewer warning) wrote its line ahead of `initialize`'s
|
|
242
|
+
// reply. `dispatch` sends logs to stderr for `--json` only; a session is the other case.
|
|
243
|
+
if (transport === 'stdio' && ctx.args.subcommand !== 'tools') setLogStream('stderr');
|
|
239
244
|
const host = await createDevMcpServer({ root, env: ctx.env, runner: ctx.runner });
|
|
240
245
|
if (ctx.args.subcommand === 'tools') return catalog(host);
|
|
241
246
|
if (transport !== 'http') return serveOverStdio(host);
|
package/src/cmd-verify.ts
CHANGED
|
@@ -64,21 +64,25 @@ export const verifyCommand: CliCommand = {
|
|
|
64
64
|
// Either render prints its verdict only when the run ends; the progress on stderr — a line per
|
|
65
65
|
// finished step, a heartbeat while one runs — is what a cancelled job's log ends on (#589) and
|
|
66
66
|
// what keeps a silence-killing harness from killing a healthy gate. stdout stays the document.
|
|
67
|
-
const result = await withVerifyProgress(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
? {}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
67
|
+
const result = await withVerifyProgress(
|
|
68
|
+
writeErrorLine,
|
|
69
|
+
(progress) =>
|
|
70
|
+
runVerify(VERIFY_STEPS, {
|
|
71
|
+
root,
|
|
72
|
+
runner: ctx.runner,
|
|
73
|
+
env: ctx.env,
|
|
74
|
+
pace: measurePace(),
|
|
75
|
+
...(workers === undefined ? {} : { workers }),
|
|
76
|
+
...(only === undefined ? {} : { only }),
|
|
77
|
+
...(shard === undefined ? {} : { shard }),
|
|
78
|
+
...(isolate === undefined ? {} : { isolate }),
|
|
79
|
+
...(changed?.tests === undefined
|
|
80
|
+
? {}
|
|
81
|
+
: { tests: { scope: changed.tests.scope, whole: changed.tests.whole } }),
|
|
82
|
+
...progress,
|
|
83
|
+
}),
|
|
84
|
+
// A line per step a person reads, JSON only for the `--json` reader that parses stderr.
|
|
85
|
+
{ render: ctx.args.json ? 'json' : 'human' },
|
|
82
86
|
);
|
|
83
87
|
const sharded = shard === undefined ? result : withShardData(result, shard);
|
|
84
88
|
return changed === undefined ? sharded : withChangedData(sharded, changed);
|
package/src/db-schema-dump.ts
CHANGED
|
@@ -148,3 +148,23 @@ export async function writeSchemaDump(
|
|
|
148
148
|
}
|
|
149
149
|
return { written, removed, total: files.length };
|
|
150
150
|
}
|
|
151
|
+
|
|
152
|
+
/** How many changed files a person's report names one per line before it says a count instead. */
|
|
153
|
+
const DUMP_LINES_SHOWN = 5;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* What a refresh did, for a person: each file when there are a few, `packages/db/schema/ +75` when
|
|
157
|
+
* a whole dump was written — the first `bun run setup` listed 75 paths mid-report. `--json`
|
|
158
|
+
* (`data.schemaDump`) carries every path either way, so the count hides nothing from a reader.
|
|
159
|
+
*/
|
|
160
|
+
export function schemaDumpLines(
|
|
161
|
+
write: Pick<SchemaDumpWrite, 'written' | 'removed'>,
|
|
162
|
+
): readonly string[] {
|
|
163
|
+
const { written, removed } = write;
|
|
164
|
+
if (written.length + removed.length <= DUMP_LINES_SHOWN) {
|
|
165
|
+
return [...written.map((file) => ` ${file}`), ...removed.map((file) => ` - ${file}`)];
|
|
166
|
+
}
|
|
167
|
+
return [
|
|
168
|
+
` ${SCHEMA_DUMP_DIR}/ +${written.length}${removed.length > 0 ? ` -${removed.length}` : ''}`,
|
|
169
|
+
];
|
|
170
|
+
}
|
package/src/dev-lock.ts
CHANGED
|
@@ -233,6 +233,20 @@ const stagingPath = (path: string): string =>
|
|
|
233
233
|
|
|
234
234
|
const lockText = (lock: DevLock): string => `${JSON.stringify(lock, null, 2)}\n`;
|
|
235
235
|
|
|
236
|
+
/**
|
|
237
|
+
* The claim's two filesystem writes. A seam, so a test can see what a rival would read between
|
|
238
|
+
* them without replacing `node:fs` for every module in its process (`mock.module` never undoes).
|
|
239
|
+
*/
|
|
240
|
+
export interface ClaimFiles {
|
|
241
|
+
readonly write: (path: string, text: string) => void;
|
|
242
|
+
readonly link: (existing: string, path: string) => void;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const NODE_CLAIM_FILES: ClaimFiles = {
|
|
246
|
+
write: (path, text) => writeFileSync(path, text),
|
|
247
|
+
link: (existing, path) => linkSync(existing, path),
|
|
248
|
+
};
|
|
249
|
+
|
|
236
250
|
/**
|
|
237
251
|
* Take the lock, or answer `false` because someone else holds it.
|
|
238
252
|
*
|
|
@@ -246,15 +260,20 @@ const lockText = (lock: DevLock): string => `${JSON.stringify(lock, null, 2)}\n`
|
|
|
246
260
|
* `.x/` this user may not write, a filesystem without hard links — is `X_DEV_STATE_UNWRITABLE`
|
|
247
261
|
* naming the directory and the errno, the original kept as its `sourceError`.
|
|
248
262
|
*/
|
|
249
|
-
function claimExclusive(
|
|
263
|
+
function claimExclusive(
|
|
264
|
+
stateDir: string,
|
|
265
|
+
path: string,
|
|
266
|
+
lock: DevLock,
|
|
267
|
+
files: ClaimFiles = NODE_CLAIM_FILES,
|
|
268
|
+
): boolean {
|
|
250
269
|
const staged = stagingPath(path);
|
|
251
270
|
try {
|
|
252
|
-
|
|
271
|
+
files.write(staged, lockText(lock));
|
|
253
272
|
} catch (error) {
|
|
254
273
|
throw new DevStateUnwritableError({ stateDir, error });
|
|
255
274
|
}
|
|
256
275
|
try {
|
|
257
|
-
|
|
276
|
+
files.link(staged, path);
|
|
258
277
|
return true;
|
|
259
278
|
} catch (error) {
|
|
260
279
|
// Same rule as `isProcessAlive` above: read the field, never cast and dereference.
|
|
@@ -299,6 +318,8 @@ export interface PreflightInput {
|
|
|
299
318
|
readonly portBound?: (port: number, hostname: string) => boolean;
|
|
300
319
|
readonly alive?: (pid: number) => boolean;
|
|
301
320
|
readonly holder?: (port: number) => Promise<PortHolder>;
|
|
321
|
+
/** Injected by the test; `node:fs` in production. */
|
|
322
|
+
readonly files?: ClaimFiles;
|
|
302
323
|
}
|
|
303
324
|
|
|
304
325
|
export interface PreflightResult {
|
|
@@ -331,7 +352,7 @@ async function claimOrClearStale(
|
|
|
331
352
|
let clearedStale = false;
|
|
332
353
|
let held: DevLock | null = null;
|
|
333
354
|
for (let round = 0; round < CLAIM_ROUNDS; round += 1) {
|
|
334
|
-
if (claimExclusive(input.stateDir, path, mine)) return clearedStale;
|
|
355
|
+
if (claimExclusive(input.stateDir, path, mine, input.files)) return clearedStale;
|
|
335
356
|
const raw = await readRaw(path);
|
|
336
357
|
const now = raw === null ? null : parseLock(raw);
|
|
337
358
|
// `held` keeps the last identity read: a half-written file parses as `null` for microseconds.
|
|
@@ -350,7 +371,7 @@ async function claimOrClearStale(
|
|
|
350
371
|
const outcome = stealStale({
|
|
351
372
|
path,
|
|
352
373
|
judged: raw,
|
|
353
|
-
claim: (guard) => claimExclusive(input.stateDir, guard, mine),
|
|
374
|
+
claim: (guard) => claimExclusive(input.stateDir, guard, mine, input.files),
|
|
354
375
|
alive: isProcessAlive,
|
|
355
376
|
});
|
|
356
377
|
if (outcome === 'busy') await Bun.sleep(STEAL_BUSY_MS);
|
package/src/doctor-guards.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// `x doctor`'s guard listing: the shipped guards this app's `guards/` does not hold, and the ones
|
|
2
|
-
// it holds in a form that is not the current template — each with the command that writes it.
|
|
3
|
-
//
|
|
4
|
-
// rule"), so a missing
|
|
2
|
+
// it holds in a form that is not the current template — each with the command that writes it.
|
|
3
|
+
// Never in the VERDICT: every shipped guard is the app's copy ("delete this file to drop the
|
|
4
|
+
// rule"), so a missing one is a warning beside it (`data.warnings`) and an edited one a listing.
|
|
5
5
|
|
|
6
6
|
// why: Bun exposes no path-join primitive; Bun.file takes one already joined.
|
|
7
7
|
import { join } from 'node:path';
|
|
8
|
+
import { ERROR_DOCS_URL } from '@ultimat3/core';
|
|
8
9
|
import { GUARD_DIR, guardPaths } from './guards';
|
|
9
10
|
import { msg } from './messages';
|
|
10
|
-
import type { CommandResult, JsonValue } from './output';
|
|
11
|
+
import type { CommandResult, Finding, JsonValue } from './output';
|
|
11
12
|
import { SHIPPED_GUARD_NAMES, shippedGuardSource } from './templates/scaffold-guards';
|
|
12
13
|
|
|
13
14
|
export interface MissingGuard {
|
|
@@ -25,6 +26,25 @@ export function missingShippedGuards(present: readonly string[]): readonly Missi
|
|
|
25
26
|
}));
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
export const MISSING_GUARD = 'X_SHIPPED_GUARD_MISSING';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A missing shipped guard as a WARNING, one per guard: the gate does not hold this app to that
|
|
33
|
+
* rule, and "no findings — environment is shippable" alone said nothing of it. A warning and not a
|
|
34
|
+
* finding, so on `main` an adopter's doctor keeps its exit status (`doctor-warnings.ts`).
|
|
35
|
+
*/
|
|
36
|
+
export function missingGuardWarnings(entries: readonly GuardListingEntry[]): readonly Finding[] {
|
|
37
|
+
return entries
|
|
38
|
+
.filter((entry): entry is MissingGuard => 'add' in entry)
|
|
39
|
+
.map(({ name, add }) => ({
|
|
40
|
+
code: MISSING_GUARD,
|
|
41
|
+
cause: `${GUARD_DIR}/${name}.ts is not in this app, so x verify does not hold it to the shipped ${name} rule`,
|
|
42
|
+
fix: `${add} && x verify --only boundaries --json`,
|
|
43
|
+
docs: ERROR_DOCS_URL,
|
|
44
|
+
at: `${GUARD_DIR}/${name}.ts`,
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
|
|
28
48
|
export interface DifferingGuard {
|
|
29
49
|
readonly name: string;
|
|
30
50
|
/** Rewrites the guard and its test from the current template. Review the diff, then keep it. */
|
|
@@ -73,8 +93,9 @@ export async function shippedGuardsProbe(root: string): Promise<readonly GuardLi
|
|
|
73
93
|
}
|
|
74
94
|
|
|
75
95
|
/**
|
|
76
|
-
* The listing, on a result `x doctor` already decided: `data.guards
|
|
77
|
-
* line per
|
|
96
|
+
* The listing, on a result `x doctor` already decided: `data.guards` for a machine; for a person,
|
|
97
|
+
* a line per differing guard — a missing one's command is its warning's line, never printed twice.
|
|
98
|
+
* `ok`, the summary and the findings are returned as they came.
|
|
78
99
|
*/
|
|
79
100
|
export function withGuardListing(
|
|
80
101
|
result: CommandResult,
|
|
@@ -84,12 +105,6 @@ export function withGuardListing(
|
|
|
84
105
|
const missing = entries.filter((entry): entry is MissingGuard => 'add' in entry);
|
|
85
106
|
const differs = entries.filter((entry): entry is DifferingGuard => 'refresh' in entry);
|
|
86
107
|
const lines = [
|
|
87
|
-
...(missing.length === 0
|
|
88
|
-
? []
|
|
89
|
-
: [
|
|
90
|
-
msg('cli.doctor.guards', { count: missing.length }),
|
|
91
|
-
...missing.map(({ add }) => ` ${add}`),
|
|
92
|
-
]),
|
|
93
108
|
...(differs.length === 0
|
|
94
109
|
? []
|
|
95
110
|
: [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// The X_* codes of how an app is HELD — `x doctor`'s floor, pin, env-name
|
|
2
|
-
// the `exercise` floor
|
|
3
|
-
//
|
|
4
|
-
// and registers them in its one call; nothing else imports this file.
|
|
1
|
+
// The X_* codes of how an app is HELD — `x doctor`'s floor, pin, env-name, row-security and
|
|
2
|
+
// shipped-guard checks, the `exercise` floor and the `drift` step's undeclared index — split out of
|
|
3
|
+
// `error-codes.ts` at its 500-line ceiling. `error-codes.ts` folds these into the CLI's one owned
|
|
4
|
+
// union and registers them in its one call; nothing else imports this file.
|
|
5
5
|
|
|
6
6
|
/** Codes `x doctor`, the `exercise` floor and the `drift` step's index advice declare and own. */
|
|
7
7
|
export const CLI_DOCTOR_ERROR_CODES = [
|
|
@@ -11,6 +11,7 @@ export const CLI_DOCTOR_ERROR_CODES = [
|
|
|
11
11
|
'X_VERIFY_STEP_UNFLOORED',
|
|
12
12
|
'X_DB_ROW_SECURITY_OFF',
|
|
13
13
|
'X_DB_INDEX_UNDECLARED',
|
|
14
|
+
'X_SHIPPED_GUARD_MISSING',
|
|
14
15
|
] as const;
|
|
15
16
|
|
|
16
17
|
export type CliDoctorErrorCode = (typeof CLI_DOCTOR_ERROR_CODES)[number];
|
|
@@ -23,4 +24,5 @@ export const CLI_DOCTOR_ERROR_TITLES: Readonly<Record<CliDoctorErrorCode, string
|
|
|
23
24
|
X_VERIFY_STEP_UNFLOORED: 'A gate step applies to this app but x.verify.json does not floor it',
|
|
24
25
|
X_DB_ROW_SECURITY_OFF: 'Raw sql reaches tenant tables while database.rowSecurity is off',
|
|
25
26
|
X_DB_INDEX_UNDECLARED: 'Schema dump holds an index nothing declares',
|
|
27
|
+
X_SHIPPED_GUARD_MISSING: "A guard x new ships is not in this app's guards/",
|
|
26
28
|
};
|
package/src/guards.ts
CHANGED
|
@@ -31,6 +31,13 @@ export interface Guard {
|
|
|
31
31
|
* may, from `root`.
|
|
32
32
|
*/
|
|
33
33
|
check(root: string, sources: GuardSources): Promise<readonly Finding[]> | readonly Finding[];
|
|
34
|
+
/**
|
|
35
|
+
* `'warning'`: REPORT ONLY. The findings it returns ride the step as warnings — listed in
|
|
36
|
+
* `--json` and on the step line, never a failure — so a rule can ship to every app before the
|
|
37
|
+
* apps are clean of it. Absent: every finding fails the gate. A finding that breaks the contract
|
|
38
|
+
* is a failure either way, because a guard that fails open is the defect this seam refuses.
|
|
39
|
+
*/
|
|
40
|
+
readonly severity?: 'warning';
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
@@ -40,7 +47,8 @@ const isGuard = (value: unknown): value is Guard =>
|
|
|
40
47
|
isRecord(value) &&
|
|
41
48
|
typeof value['summary'] === 'string' &&
|
|
42
49
|
value['summary'].trim() !== '' &&
|
|
43
|
-
typeof value['check'] === 'function'
|
|
50
|
+
typeof value['check'] === 'function' &&
|
|
51
|
+
(value['severity'] === undefined || value['severity'] === 'warning');
|
|
44
52
|
|
|
45
53
|
const CODE = /^X_[A-Z0-9_]+$/;
|
|
46
54
|
|
|
@@ -122,6 +130,22 @@ const invalid = (path: string, cause: string): Finding => ({
|
|
|
122
130
|
at: path,
|
|
123
131
|
});
|
|
124
132
|
|
|
133
|
+
const notAGuard = (path: string, exported: unknown): Finding => {
|
|
134
|
+
if (exported === undefined) {
|
|
135
|
+
return invalid(
|
|
136
|
+
path,
|
|
137
|
+
`${path} exports no \`guard\`, so a file in ${GUARD_DIR}/ enforces nothing`,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
const severity = isRecord(exported) ? exported['severity'] : undefined;
|
|
141
|
+
return invalid(
|
|
142
|
+
path,
|
|
143
|
+
severity !== undefined && severity !== 'warning'
|
|
144
|
+
? `${path} exports a \`guard\` whose severity is ${shown(severity)} — 'warning' (report only) is the one, or none to fail the gate`
|
|
145
|
+
: `${path} exports a \`guard\` with no summary and no check()`,
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
|
|
125
149
|
const findingInvalid = (path: string, cause: string): Finding => ({
|
|
126
150
|
code: 'X_GUARD_FINDING_INVALID',
|
|
127
151
|
cause: `${path} returned a finding that is not one: ${cause}`,
|
|
@@ -133,52 +157,53 @@ const findingInvalid = (path: string, cause: string): Finding => ({
|
|
|
133
157
|
/** Same reason as `shown`: an app's guard may throw a value that fights every way of reading it. */
|
|
134
158
|
const messageOf = (error: unknown): string => renderThrowable(error);
|
|
135
159
|
|
|
160
|
+
/** What the gate does with a guard's findings: fail on `findings`, list `warnings`. */
|
|
161
|
+
export interface GuardReport {
|
|
162
|
+
readonly findings: readonly Finding[];
|
|
163
|
+
/** A report-only guard's findings, each held to the same contract. Never a failure. */
|
|
164
|
+
readonly warnings: readonly Finding[];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const refused = (finding: Finding): GuardReport => ({ findings: [finding], warnings: [] });
|
|
168
|
+
|
|
136
169
|
/** One guard: import it, run it, and hold what it returns to the contract. Never throws. */
|
|
137
|
-
async function runGuard(
|
|
138
|
-
root: string,
|
|
139
|
-
path: string,
|
|
140
|
-
sources: GuardSources,
|
|
141
|
-
): Promise<readonly Finding[]> {
|
|
170
|
+
async function runGuard(root: string, path: string, sources: GuardSources): Promise<GuardReport> {
|
|
142
171
|
let loaded: unknown;
|
|
143
172
|
try {
|
|
144
173
|
loaded = await import(pathToFileURL(join(root, path)).href);
|
|
145
174
|
} catch (error) {
|
|
146
|
-
return
|
|
175
|
+
return refused(failed(path, `${path} could not be imported: ${messageOf(error)}`));
|
|
147
176
|
}
|
|
148
177
|
const exported = isRecord(loaded) ? loaded['guard'] : undefined;
|
|
149
|
-
if (!isGuard(exported))
|
|
150
|
-
return [
|
|
151
|
-
invalid(
|
|
152
|
-
path,
|
|
153
|
-
exported === undefined
|
|
154
|
-
? `${path} exports no \`guard\`, so a file in ${GUARD_DIR}/ enforces nothing`
|
|
155
|
-
: `${path} exports a \`guard\` with no summary and no check()`,
|
|
156
|
-
),
|
|
157
|
-
];
|
|
158
|
-
}
|
|
178
|
+
if (!isGuard(exported)) return refused(notAGuard(path, exported));
|
|
159
179
|
let returned: unknown;
|
|
160
180
|
try {
|
|
161
181
|
returned = await exported.check(root, sources);
|
|
162
182
|
} catch (error) {
|
|
163
|
-
return
|
|
183
|
+
return refused(failed(path, `${path} ("${exported.summary}") threw: ${messageOf(error)}`));
|
|
164
184
|
}
|
|
165
185
|
if (!Array.isArray(returned)) {
|
|
166
|
-
return
|
|
186
|
+
return refused(
|
|
187
|
+
findingInvalid(path, `check() answered ${typeof returned}, not a list of findings`),
|
|
188
|
+
);
|
|
167
189
|
}
|
|
168
|
-
const
|
|
190
|
+
const broken: Finding[] = [];
|
|
191
|
+
const held: Finding[] = [];
|
|
169
192
|
for (const candidate of returned as readonly unknown[]) {
|
|
170
193
|
// Reading a candidate can throw on its own — a getter that raises, a proxy that refuses — and
|
|
171
194
|
// `findingProblem` is total only for values it can read. Per candidate, so one unreadable
|
|
172
195
|
// entry costs its own line and not the readable findings beside it.
|
|
173
196
|
try {
|
|
174
197
|
const problem = findingProblem(candidate);
|
|
175
|
-
if (problem !== undefined)
|
|
176
|
-
else
|
|
198
|
+
if (problem !== undefined) broken.push(findingInvalid(path, problem));
|
|
199
|
+
else held.push(findingOf(candidate as Record<string, unknown>, path));
|
|
177
200
|
} catch (error) {
|
|
178
|
-
|
|
201
|
+
broken.push(findingInvalid(path, `it could not be read: ${messageOf(error)}`));
|
|
179
202
|
}
|
|
180
203
|
}
|
|
181
|
-
return
|
|
204
|
+
return exported.severity === 'warning'
|
|
205
|
+
? { findings: broken, warnings: held }
|
|
206
|
+
: { findings: [...broken, ...held], warnings: [] };
|
|
182
207
|
}
|
|
183
208
|
|
|
184
209
|
/**
|
|
@@ -188,15 +213,28 @@ async function runGuard(
|
|
|
188
213
|
* step, which is what keeps "green" meaning one thing (axiom 5) while the app still gets to make
|
|
189
214
|
* its own convention a build error.
|
|
190
215
|
*/
|
|
191
|
-
export const
|
|
216
|
+
export const guardReport = async (
|
|
192
217
|
root: string,
|
|
193
218
|
/** Files the step already read (`guardSources`' seed), so no guard reads one a second time. */
|
|
194
219
|
seed: readonly { readonly path: string; readonly source: string }[] = [],
|
|
195
|
-
): Promise<
|
|
220
|
+
): Promise<GuardReport> => {
|
|
196
221
|
const findings: Finding[] = [];
|
|
222
|
+
const warnings: Finding[] = [];
|
|
197
223
|
const sources = guardSources(root, seed);
|
|
198
224
|
for (const path of await guardPaths(root)) {
|
|
199
|
-
|
|
225
|
+
const report = await runGuard(root, path, sources);
|
|
226
|
+
findings.push(...report.findings);
|
|
227
|
+
warnings.push(...report.warnings);
|
|
200
228
|
}
|
|
201
|
-
return findings;
|
|
229
|
+
return { findings, warnings };
|
|
202
230
|
};
|
|
231
|
+
|
|
232
|
+
/** The findings that fail the gate; a report-only guard's are `guardReport`'s `warnings`. */
|
|
233
|
+
export const guardFindings = async (
|
|
234
|
+
root: string,
|
|
235
|
+
seed: readonly { readonly path: string; readonly source: string }[] = [],
|
|
236
|
+
): Promise<readonly Finding[]> => (await guardReport(root, seed)).findings;
|
|
237
|
+
|
|
238
|
+
/** A report-only finding as the one line the step lists it on. */
|
|
239
|
+
export const guardWarningLine = (finding: Finding): string =>
|
|
240
|
+
`${finding.at === undefined ? '' : `${finding.at}: `}${finding.code} ${finding.cause} — fix: ${finding.fix}`;
|