@ultimat3/cli 31.51.0 → 31.53.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 +1 -1
- package/README.md +9 -9
- package/package.json +29 -29
- package/src/app-kit-disk.ts +39 -0
- package/src/app-kit-forms.ts +27 -0
- package/src/app-kit.ts +146 -0
- package/src/budgets.ts +3 -1
- package/src/catalog-layout.ts +194 -0
- package/src/cdp-shot-driver-screen.ts +72 -0
- package/src/cdp-shot-driver.ts +17 -1
- package/src/cmd-design-capture.ts +210 -0
- package/src/cmd-design-errors.ts +50 -0
- package/src/cmd-design-paths.ts +47 -0
- package/src/cmd-design-publish.ts +64 -0
- package/src/cmd-design-run.ts +229 -0
- package/src/cmd-design-spec.ts +47 -0
- package/src/cmd-design-theme.ts +107 -0
- package/src/cmd-design-url.ts +201 -0
- package/src/cmd-design.ts +188 -0
- package/src/cmd-doctor.ts +3 -0
- package/src/cmd-generate-spec.ts +5 -0
- package/src/cmd-generate.ts +3 -1
- package/src/cmd-i18n-spec.ts +4 -4
- package/src/cmd-i18n-split.ts +133 -0
- package/src/cmd-i18n.ts +46 -66
- package/src/cmd-kit-spec.ts +13 -0
- package/src/cmd-kit.ts +133 -0
- package/src/cmd-shot-against.ts +275 -0
- package/src/cmd-shot-spec.ts +9 -1
- package/src/cmd-shot.ts +19 -0
- package/src/cmd-upgrade.ts +11 -0
- package/src/codemods/agent-kit.ts +130 -0
- package/src/codemods/agents-md-budget.ts +47 -0
- package/src/codemods/docs-visual-quality.ts +198 -0
- package/src/codemods/index.ts +8 -0
- package/src/codemods/settings-kit-allow.ts +49 -0
- package/src/config-redact.ts +20 -4
- package/src/db-rollback-pass.ts +4 -1
- package/src/design-extract-script.ts +187 -0
- package/src/design-extract.ts +311 -0
- package/src/design-map-colors.ts +180 -0
- package/src/design-map.ts +288 -0
- package/src/dev-child-watch.ts +16 -0
- package/src/dev-db-migrate.ts +27 -46
- package/src/dev-db-migrator-hold.ts +131 -0
- package/src/dev-db-rollback.ts +11 -2
- package/src/dev-rebuild-schema.ts +7 -24
- package/src/doctor-kit.ts +25 -0
- package/src/error-catalog.ts +4 -2
- package/src/error-codes-kit.ts +24 -0
- package/src/error-codes.ts +12 -10
- package/src/generate-catalog-locales.ts +25 -2
- package/src/generate-files.ts +31 -1
- package/src/generate-follow-ups.ts +8 -3
- package/src/guards-shipped-names.ts +5 -0
- package/src/i18n-audit.ts +17 -33
- package/src/i18n-index.ts +108 -31
- package/src/i18n-locale-parity.ts +14 -6
- package/src/i18n-new-locale.ts +75 -0
- package/src/i18n-registration.ts +52 -27
- package/src/island-capture.ts +36 -7
- package/src/kit/agent-audit.ts +49 -0
- package/src/kit/agent-data.ts +32 -0
- package/src/kit/agent-server.ts +34 -0
- package/src/kit/agent-shape.ts +61 -0
- package/src/kit/agent-web.ts +49 -0
- package/src/kit/design-map.ts +106 -0
- package/src/kit/managed.ts +12 -0
- package/src/kit/registry.ts +89 -0
- package/src/kit/skill-design-research.ts +119 -0
- package/src/kit/skill-feature.ts +159 -0
- package/src/kit/skill-planx.ts +139 -0
- package/src/kit/skill-upgrade.ts +94 -0
- package/src/kit/skill-verify.ts +80 -0
- package/src/mcp-errors.ts +5 -0
- package/src/mcp-ui-diff.ts +13 -38
- package/src/mcp-ui.ts +30 -1
- package/src/merge-state.ts +3 -2
- package/src/messages-design.ts +104 -0
- package/src/messages-floor.ts +2 -0
- package/src/messages-upgrade.ts +9 -0
- package/src/messages.ts +4 -0
- package/src/registry.ts +4 -0
- package/src/serve-boot-telemetry.ts +106 -0
- package/src/serve-boot.ts +23 -4
- package/src/shot-blank.ts +70 -0
- package/src/shot-diff.ts +96 -0
- package/src/shot-gpu.ts +17 -5
- package/src/templates/catalog-barrel.ts +84 -0
- package/src/templates/guard-animated-layout-script.ts +173 -0
- package/src/templates/guard-effect-without-fallback.ts +117 -0
- package/src/templates/guard-motion-adapter.ts +161 -0
- package/src/templates/guard-raw-frame-loop.ts +134 -0
- package/src/templates/guard-raw-motion-script.ts +132 -0
- package/src/templates/guard-raw-motion-ts-scan.ts +95 -0
- package/src/templates/guard-released-forms.ts +12 -1
- package/src/templates/guard-untranslated-string.ts +27 -6
- package/src/templates/index.ts +1 -2
- package/src/templates/island.ts +55 -8
- package/src/templates/kit-released-forms.ts +63 -0
- package/src/templates/locales.ts +6 -0
- package/src/templates/motion-scale.ts +115 -0
- package/src/templates/scaffold-claude.ts +39 -26
- package/src/templates/scaffold-design.ts +41 -0
- package/src/templates/scaffold-docs.ts +31 -7
- package/src/templates/scaffold-gitattributes.ts +9 -2
- package/src/templates/scaffold-guards.ts +31 -2
- package/src/templates/scaffold-i18n.ts +10 -6
- package/src/templates/scaffold-verify-floor.ts +3 -0
- package/src/templates/shapes/blog-site.ts +15 -0
- package/src/templates/shapes/blog.ts +2 -0
- package/src/templates/shapes/content-site.ts +13 -0
- package/src/templates/shapes/content.ts +2 -0
- package/src/templates/shapes/dashboard-detail.ts +2 -0
- package/src/templates/shapes/dashboard-motion.ts +284 -0
- package/src/templates/shapes/dashboard.ts +19 -1
- package/src/templates/shapes/landing-motion.ts +67 -0
- package/src/templates/shapes/offline.ts +5 -2
- package/src/templates/shapes/saas.ts +4 -0
- package/src/test-ignores.ts +3 -2
- package/src/upgrade-gate.ts +14 -2
- package/src/upgrade-kit.ts +65 -0
- package/src/upgrade-report-kit.ts +28 -0
- package/src/upgrade-report.ts +3 -0
- package/src/verify-checks.ts +9 -1
- package/src/verify-floor.ts +9 -1
- package/src/verify-local-only.ts +66 -0
- package/src/verify-run.ts +17 -2
- package/src/workspace-checks.ts +3 -3
- package/wiki/Actions.md +1 -1
- package/wiki/Agents.md +33 -1
- package/wiki/Auth.md +3 -3
- package/wiki/Batching-And-Preloading.md +1 -0
- package/wiki/CLI-Reference-Data.md +241 -0
- package/wiki/CLI-Reference-Gate.md +572 -0
- package/wiki/CLI-Reference-Project.md +414 -0
- package/wiki/CLI-Reference-Ship.md +348 -0
- package/wiki/CLI-Reference-Tools.md +687 -0
- package/wiki/CLI-Reference.md +18 -2227
- package/wiki/Compared.md +8 -8
- package/wiki/Configuration.md +26 -2
- package/wiki/Deployment.md +1 -1
- package/wiki/Design-Research.md +96 -0
- package/wiki/Effects.md +83 -0
- package/wiki/Entities-And-Migrations.md +3 -2
- package/wiki/FAQ.md +1 -1
- package/wiki/Getting-Started.md +1 -1
- package/wiki/Home.md +2 -2
- package/wiki/I18n.md +39 -5
- package/wiki/Installation.md +1 -1
- package/wiki/Jobs-And-Workflows.md +29 -1
- package/wiki/Known-Gaps.md +6 -2
- package/wiki/MCP-And-AI.md +4 -0
- package/wiki/Motion.md +85 -0
- package/wiki/Observability.md +15 -1
- package/wiki/Outbound-HTTP.md +62 -2
- package/wiki/PWA-And-Offline.md +1 -1
- package/wiki/Policies-And-Authz.md +10 -0
- package/wiki/Project-Layout.md +1 -1
- package/wiki/Realtime.md +29 -2
- package/wiki/Static-Assets.md +1 -1
- package/wiki/Testing.md +33 -0
- package/wiki/Theming.md +31 -8
- package/wiki/Troubleshooting.md +1 -1
- package/wiki/Tutorial-02-First-Feature.md +1 -1
- package/wiki/UI-Components.md +2 -0
- package/wiki/Upgrading.md +9 -3
- package/src/templates/scaffold-claude-agents.ts +0 -161
- package/src/templates/scaffold-claude-commands.ts +0 -239
package/CLAUDE.md
CHANGED
|
@@ -191,7 +191,7 @@ Commands: `bun test ./packages/cli/` (repo root: the preload),
|
|
|
191
191
|
| `cmd-tasks-run.ts` | `x tasks run`: `TaskHandle.enqueue()`; production needs `--production` or `ULTIMATE_TASK_RUN=<name>` (`X_TASK_RUN_PRODUCTION`) |
|
|
192
192
|
| `doctor-api-listing.ts` | `x doctor` warns: action/query off a `defineApi()` listing others |
|
|
193
193
|
| `cmd-auth.ts` / `cmd-auth-spec.ts` / `doctor-auth.ts` | `x auth seal-mfa`: seals plaintext `x_users.mfa_secret` through auth's `sealMfaSecrets` |
|
|
194
|
-
| `cmd-mcp.ts` / `mcp-host*.ts` / `mcp-errors.ts` / `mcp-db-target.ts` / `mcp-test-{output,run}.ts` | `x mcp serve`:
|
|
194
|
+
| `cmd-mcp.ts` / `mcp-host*.ts` / `mcp-errors.ts` / `mcp-db-target.ts` / `mcp-test-{output,run}.ts` | `x mcp serve`: 24 tools, two transports; `tests.run`/`verify.run` ARE `x test`/`x verify` † |
|
|
195
195
|
| `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 |
|
|
196
196
|
| `cmd-profile*.ts` | `x profile <route>`: in-process JSC sampling profile of a route, hottest functions |
|
|
197
197
|
| `mcp-host-logs.ts` | `logs.tail` and `x logs tail`'s reader: path rule, end-first bounded read, per-role tail |
|
package/README.md
CHANGED
|
@@ -27,8 +27,8 @@ Commands and the `x verify` step count, `As of 2026-08`:
|
|
|
27
27
|
| `x g <primitive> <name>` | scaffolds a primitive **with a passing test** | never a TODO stub |
|
|
28
28
|
| `x db gen\|migrate\|rollback\|reset\|branch\|backfill` | everything DB | `rollback [--steps n]` (default 1) runs the `-- down` half of the most recently applied migration(s) and leaves the files on disk; `gen` refuses an applied migration edited since (`X_MIGRATION_CONFLICT`) before it writes — checked against the embedded ledger only (asked of a live `x dev` when one holds it): an external `DATABASE_URL` is never dialled, so there `x db migrate`'s own audit is the refusal, and an embedded ledger it cannot read is a warning line naming why, never a refusal; `branch` = copy-on-write clone + preview URL; `backfill` dry-runs unless `--write`. The schema browser is `/_x`'s db panel (`x dev`); `studio` left the registry ([Known gaps](../../wiki/Known-Gaps.md#open-by-decision)) |
|
|
29
29
|
| `x mcp serve` | `@ultimat3/mcp`'s 19 dev tools, over stdio or HTTP | one catalog, one scope set, both transports |
|
|
30
|
-
| `x upgrade` | one major per run: exact pins, the Bun floor, `bun install`, the gate; an `AGENTS.md` byte-identical to `CLAUDE.md` becomes a symlink to it, a different one is reported in `data.agentsMd` and left | the `--json` report names the wiki section, the guards that differ and what the gate still says ([fields](../../wiki/CLI-Reference.md#x-upgrade)); `bunx @ultimat3/cli@latest upgrade` in an app that predates it; pins with no `app.config.ts` still hop, and `data.proof` says what checked them |
|
|
31
|
-
| `x doctor` | environment, ports, drift, PWA prerequisites, `APP_URL` | every finding carries a fix command; probes the port `x dev` binds ([which one](../../wiki/CLI-Reference.md#x-doctor)); the framework's deploy secrets only where the machine names `staging`/`production` |
|
|
30
|
+
| `x upgrade` | one major per run: exact pins, the Bun floor, `bun install`, the gate; an `AGENTS.md` byte-identical to `CLAUDE.md` becomes a symlink to it, a different one is reported in `data.agentsMd` and left | the `--json` report names the wiki section, the guards that differ and what the gate still says ([fields](../../wiki/CLI-Reference-Tools.md#x-upgrade)); `bunx @ultimat3/cli@latest upgrade` in an app that predates it; pins with no `app.config.ts` still hop, and `data.proof` says what checked them |
|
|
31
|
+
| `x doctor` | environment, ports, drift, PWA prerequisites, `APP_URL` | every finding carries a fix command; probes the port `x dev` binds ([which one](../../wiki/CLI-Reference-Tools.md#x-doctor)); the framework's deploy secrets only where the machine names `staging`/`production` |
|
|
32
32
|
| `x deploy` | container deploy plan | compose or helm; zero platform primitives. Compose reads `.env.production` first (`X_DEPLOY_ENV_MISSING`). Helm carries `drain.*`, `drain.workerRetireMs` as `roles.worker.retireSeconds`, and `jobs.maxInFlight` as the worker's `targetAverageValue` |
|
|
33
33
|
| `x deploy verify` | production serves this build, holds it, and a worker of it claims every queue | samples `/readyz` through the load balancer, grades `x_job_workers` when `DATABASE_URL` is set; no platform API |
|
|
34
34
|
| `x manifest` / `x routes` | generated facts | `x.manifest.json`, `openapi.json`, route table |
|
|
@@ -46,16 +46,16 @@ Commands and the `x verify` step count, `As of 2026-08`:
|
|
|
46
46
|
| `x repro <id> [--write] [--verify]` / `--list` / `--from` | a dead job or a captured 5xx as a red test in `repro/` | `--verify` answers `{ reproduced, code, fingerprint }`; a mismatch is `X_REPRO_NOT_REPRODUCED`, never a crash |
|
|
47
47
|
| `x repro <id> --bundle` | the failure as one redacted `repro/bundle-<id>.json` for an issue | secrets masked, env values / hostnames / paths replaced; `bunx create-ultimate repro <file>` opens it |
|
|
48
48
|
| `x docs "<question>"` | the framework docs and the wiki, offline | answered from the installed packages and the `wiki/` this tarball ships (`prepack`: `scripts/pack-cli-wiki.ts`), never the network; `x docs Upgrading#<anchor>` prints one whole section |
|
|
49
|
-
| `x graph [--from a --to b]` / `x impact <file\|primitive\|entity>` | the app as one typed graph (`@ultimat3/manifest`'s `buildGraph` over the loaded app, its module graph and `.x/exercise.json`) · what an edit reaches | every edge `declared`, `import` or `observed`; a miss is `X_GRAPH_NODE_UNKNOWN` with the nearest three; `x affected` in an app root adds `data.tests` by import closure ([details](../../wiki/CLI-Reference.md#x-graph--x-impact)) |
|
|
50
|
-
| `x client vendor <name>` / `x client customer --out <dir>` | one OpenAPI compiler (`openapi-compile.ts`), two emitters: a vendor's document into `apps/web/clients/<name>/` (`outbound()` + `t`), or the app's published document into a client with no framework import | every generated file is stamped with its source and body hash; `drift` raises `X_CLIENT_STALE` / `X_CLIENT_EDITED` ([flags](../../wiki/CLI-Reference.md#x-client)) |
|
|
49
|
+
| `x graph [--from a --to b]` / `x impact <file\|primitive\|entity>` | the app as one typed graph (`@ultimat3/manifest`'s `buildGraph` over the loaded app, its module graph and `.x/exercise.json`) · what an edit reaches | every edge `declared`, `import` or `observed`; a miss is `X_GRAPH_NODE_UNKNOWN` with the nearest three; `x affected` in an app root adds `data.tests` by import closure ([details](../../wiki/CLI-Reference-Tools.md#x-graph--x-impact)) |
|
|
50
|
+
| `x client vendor <name>` / `x client customer --out <dir>` | one OpenAPI compiler (`openapi-compile.ts`), two emitters: a vendor's document into `apps/web/clients/<name>/` (`outbound()` + `t`), or the app's published document into a client with no framework import | every generated file is stamped with its source and body hash; `drift` raises `X_CLIENT_STALE` / `X_CLIENT_EDITED` ([flags](../../wiki/CLI-Reference-Tools.md#x-client)) |
|
|
51
51
|
| `x fix boundary <file>` | the minimal cut for a crossed surface boundary | prints the plan and the `git mv`; never rewrites a file |
|
|
52
|
-
| `x ci [runs]` / `x ci tested` | CI triage through `gh`; `tested`: may this push reuse a green PR run of the same tree | `tested` exits 0 on every answer, `data.tested`; any doubt is `false`, a full run ([conditions](../../wiki/CLI-Reference.md#x-pr--x-ci)) |
|
|
53
|
-
| `x token create\|list\|revoke` | MCP / API tokens in `x_api_keys` | `create --scopes a,b` prints the plaintext once and stores its hash; `list --owner <id>` carries no secret; no `grant`: a wider set is a new key ([details](../../wiki/CLI-Reference.md#x-token)) |
|
|
52
|
+
| `x ci [runs]` / `x ci tested` | CI triage through `gh`; `tested`: may this push reuse a green PR run of the same tree | `tested` exits 0 on every answer, `data.tested`; any doubt is `false`, a full run ([conditions](../../wiki/CLI-Reference-Tools.md#x-pr--x-ci)) |
|
|
53
|
+
| `x token create\|list\|revoke` | MCP / API tokens in `x_api_keys` | `create --scopes a,b` prints the plaintext once and stores its hash; `list --owner <id>` carries no secret; no `grant`: a wider set is a new key ([details](../../wiki/CLI-Reference-Tools.md#x-token)) |
|
|
54
54
|
| `x config show [--section <key>]` | the resolved `app.config.ts` | defaults merged by `defineConfig`; credential keys, `secret()` values and URL passwords redacted |
|
|
55
55
|
| `x logs tail [--lines n] [--role <role>]` | the end of `.x/dev.log` or a role log | the `logs.tail` MCP tool's file and reader |
|
|
56
56
|
| `x cache graph\|bust <tag>\|clear` | the tag graph off the manifest; a bust through the app's own tiers and bus | an in-process bus is said in the summary; a failed tier is `X_CACHE_DRIVER_UNAVAILABLE` |
|
|
57
57
|
| `x explain <query> [--input <json>] [--org <id>]` | one query's statements, planned on the dev database | the `exercise` step's oracle (`sweepPlans`): an unindexed read is `X_QUERY_UNINDEXED` with the `indexes:` entry as its fix |
|
|
58
|
-
| `x status [--url <origin>] [--samples n]` | the build each live worker runs, and what each origin's `/readyz` answers | a read, exit 0; `data.unrecorded` names the roles no fleet-wide record covers ([details](../../wiki/CLI-Reference.md#x-status)) |
|
|
58
|
+
| `x status [--url <origin>] [--samples n]` | the build each live worker runs, and what each origin's `/readyz` answers | a read, exit 0; `data.unrecorded` names the roles no fleet-wide record covers ([details](../../wiki/CLI-Reference-Ship.md#x-status)) |
|
|
59
59
|
|
|
60
60
|
Everything in [CLI reference](../../wiki/CLI-Reference.md)'s planned table is also in the registry
|
|
61
61
|
and exits `X_NOT_IMPLEMENTED` with a `fix:` naming the closest shipped command — "not built yet"
|
|
@@ -349,8 +349,8 @@ one, silently. `As of 2026-11`:
|
|
|
349
349
|
| Command | Beside a live `x dev` holding `.x/pgdata` |
|
|
350
350
|
|---|---|
|
|
351
351
|
| `x db migrate` | applied BY the dev server (`POST /_x/db/migrate`: loopback Host and peer, same-origin — the command sends `Sec-Fetch-Site: same-origin`, so an app's CSRF check lets it through); the report, drift and schema dump are the same. `x dev`'s own `x db gen "…" && x db migrate` fix works as printed. A holder that is still booting (its lock claimed inside the last 120 s, or a new child) is waited for, up to 120 s, on a refused connection only |
|
|
352
|
-
| `x db migrate`, app with `database.rowSecurity` |
|
|
353
|
-
| `x db rollback [--steps n]` | run BY the dev server (`POST /_x/db/rollback`, the same doors); with `database.rowSecurity`
|
|
352
|
+
| `x db migrate`, app with `database.rowSecurity` | applied by the dev server too: it holds its one session exclusively, runs the pass as `x_migrator`, and serves as `x_app` again before any other statement runs (`dev-db-migrator-hold.ts`). A session that cannot become `x_app` again stops serving: `X_DB_ROW_SECURITY_BYPASSED`, fix `x stop --json && x dev` |
|
|
353
|
+
| `x db rollback [--steps n]` | run BY the dev server (`POST /_x/db/rollback`, the same doors); with `database.rowSecurity` under the same hold as `x_migrator` |
|
|
354
354
|
| `x db gen` | reads the ledger's checksums from the dev server (`POST /_x/db/ledger`) for its edited-migration check; one that does not answer is a printed line, never a refusal |
|
|
355
355
|
| `x db seed`, `x db backfill --write`, `x jobs retry\|cancel\|delete\|promote\|resolve-step\|pause\|resume`, `x auth seal-mfa` | `X_DEV_ALREADY_RUNNING`; the fix stops the holder, runs the command and starts `x dev` again |
|
|
356
356
|
| `x db reset\|status\|diagnostics\|recount` | `X_DEV_ALREADY_RUNNING`, as before |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/cli",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.53.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.1.0",
|
|
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.53.0",
|
|
57
|
+
"@ultimat3/admin": "31.53.0",
|
|
58
|
+
"@ultimat3/ai": "31.53.0",
|
|
59
|
+
"@ultimat3/auth": "31.53.0",
|
|
60
|
+
"@ultimat3/cache": "31.53.0",
|
|
61
|
+
"@ultimat3/core": "31.53.0",
|
|
62
|
+
"@ultimat3/db": "31.53.0",
|
|
63
|
+
"@ultimat3/entity": "31.53.0",
|
|
64
|
+
"@ultimat3/flags": "31.53.0",
|
|
65
|
+
"@ultimat3/http": "31.53.0",
|
|
66
|
+
"@ultimat3/i18n": "31.53.0",
|
|
67
|
+
"@ultimat3/jobs": "31.53.0",
|
|
68
|
+
"@ultimat3/mail": "31.53.0",
|
|
69
|
+
"@ultimat3/manifest": "31.53.0",
|
|
70
|
+
"@ultimat3/mcp": "31.53.0",
|
|
71
|
+
"@ultimat3/money": "31.53.0",
|
|
72
|
+
"@ultimat3/notify": "31.53.0",
|
|
73
|
+
"@ultimat3/policy": "31.53.0",
|
|
74
|
+
"@ultimat3/pwa": "31.53.0",
|
|
75
|
+
"@ultimat3/query": "31.53.0",
|
|
76
|
+
"@ultimat3/realtime": "31.53.0",
|
|
77
|
+
"@ultimat3/render": "31.53.0",
|
|
78
|
+
"@ultimat3/schema": "31.53.0",
|
|
79
|
+
"@ultimat3/scraping": "31.53.0",
|
|
80
|
+
"@ultimat3/seo": "31.53.0",
|
|
81
|
+
"@ultimat3/storage": "31.53.0",
|
|
82
|
+
"@ultimat3/testing": "31.53.0",
|
|
83
|
+
"@ultimat3/time": "31.53.0",
|
|
84
84
|
"babel-preset-solid": "^1.9.16"
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// The agent kit as an app root holds it: the disk behind `judgeKit`, and the managed files rendered
|
|
2
|
+
// for the app's own name. One seam, so the gate, `x kit`, `x doctor` and `x upgrade` read the same.
|
|
3
|
+
|
|
4
|
+
// why: Bun exposes no path-join or basename primitive.
|
|
5
|
+
import { basename, join } from 'node:path';
|
|
6
|
+
import type { KitDisk, KitVerdict } from './app-kit';
|
|
7
|
+
import { judgeKit } from './app-kit';
|
|
8
|
+
import { appName } from './codemods/agents-dev-mcp';
|
|
9
|
+
import type { KitFile } from './kit/registry';
|
|
10
|
+
import { kitFiles } from './kit/registry';
|
|
11
|
+
import { names } from './templates/naming';
|
|
12
|
+
|
|
13
|
+
export const diskAt = (root: string): KitDisk => ({
|
|
14
|
+
async read(path) {
|
|
15
|
+
const file = Bun.file(join(root, path));
|
|
16
|
+
return (await file.exists()) ? file.text() : undefined;
|
|
17
|
+
},
|
|
18
|
+
async glob(pattern) {
|
|
19
|
+
const found: string[] = [];
|
|
20
|
+
for await (const path of new Bun.Glob(pattern).scan({ cwd: root })) found.push(path);
|
|
21
|
+
return found.sort();
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/** The name the scaffold spelled into the kit: the root `package.json`'s, else the directory's. */
|
|
26
|
+
export async function kitAppName(root: string): Promise<string> {
|
|
27
|
+
const manifest = await diskAt(root).read('package.json');
|
|
28
|
+
return (manifest === undefined ? undefined : appName(manifest)) ?? basename(root);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Every managed file rendered for the app at `root`. */
|
|
32
|
+
export async function managedKit(root: string): Promise<readonly KitFile[]> {
|
|
33
|
+
return kitFiles(names(await kitAppName(root)));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The gate's, `x doctor`'s and `x upgrade`'s one question about an app. */
|
|
37
|
+
export async function kitVerdict(root: string): Promise<KitVerdict> {
|
|
38
|
+
return judgeKit(diskAt(root), await managedKit(root));
|
|
39
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// The identity of a command or agent file an earlier release wrote: hashed with the app's name
|
|
2
|
+
// swapped for a fixed one, because the templates spell `mcp__<app>__*` into the text. The refresh
|
|
3
|
+
// script and the `agent-kit` codemod share this one function, so a form hashed there matches here.
|
|
4
|
+
|
|
5
|
+
import { guardFormHash } from './guards-vendored';
|
|
6
|
+
|
|
7
|
+
/** A valid kebab name no app picks: the template is rendered with it, and an app's text maps to it. */
|
|
8
|
+
export const KIT_FORM_NAME = 'zz-kit-form-zz';
|
|
9
|
+
|
|
10
|
+
/** `file`'s hash with the app's `kebab` read as `KIT_FORM_NAME`. */
|
|
11
|
+
export const kitFormHash = (text: string, kebab: string): string =>
|
|
12
|
+
guardFormHash(kebab === '' ? text : text.replaceAll(kebab, KIT_FORM_NAME));
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* True when `text` is one of `known` for some name the app could have been scaffolded under. These
|
|
16
|
+
* are identities of public template text, never a secret, so a set lookup is the right comparison —
|
|
17
|
+
* `timingSafeEqual` would guard a value nobody is trying to learn byte by byte.
|
|
18
|
+
*/
|
|
19
|
+
export const isReleasedKitForm = (
|
|
20
|
+
text: string,
|
|
21
|
+
names: readonly string[],
|
|
22
|
+
known: readonly string[] | undefined,
|
|
23
|
+
): boolean => {
|
|
24
|
+
if (known === undefined) return false;
|
|
25
|
+
const released = new Set(known);
|
|
26
|
+
return names.some((name) => released.has(kitFormHash(text, name)));
|
|
27
|
+
};
|
package/src/app-kit.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// The agent kit against the app's disk: a managed file missing or edited is X_KIT_DRIFT, a command
|
|
2
|
+
// that a same-named skill silently shadows is X_KIT_SHADOWED. Pure over an injected reader, so the
|
|
3
|
+
// gate, `x kit`, `x doctor` and `x upgrade` all ask one function. `.claude/kit.json` is the opt-in:
|
|
4
|
+
// present, the findings are errors; absent, one warning — `main` never reddens on a new rule.
|
|
5
|
+
|
|
6
|
+
import { ERROR_DOCS_URL, isJsonObject, renderFixShellArg } from '@ultimat3/core';
|
|
7
|
+
import type { KitFile } from './kit/registry';
|
|
8
|
+
import { KIT_MARKER } from './kit/registry';
|
|
9
|
+
import type { Finding } from './output';
|
|
10
|
+
|
|
11
|
+
export const KIT_DRIFT = 'X_KIT_DRIFT';
|
|
12
|
+
export const KIT_SHADOWED = 'X_KIT_SHADOWED';
|
|
13
|
+
export const KIT_FIX = 'bunx x kit';
|
|
14
|
+
const COMMANDS_DIR = '.claude/commands';
|
|
15
|
+
|
|
16
|
+
/** What the app's disk answers: the text at a path, and the paths a glob names. */
|
|
17
|
+
export interface KitDisk {
|
|
18
|
+
read(path: string): Promise<string | undefined>;
|
|
19
|
+
glob(pattern: string): Promise<readonly string[]>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type KitMarker =
|
|
23
|
+
| { readonly state: 'absent' }
|
|
24
|
+
| { readonly state: 'invalid'; readonly why: string }
|
|
25
|
+
| { readonly state: 'present'; readonly off: readonly string[] };
|
|
26
|
+
|
|
27
|
+
/** `kit.json` parsed: `{ "off": ["<entry name>", …] }`, the only key. */
|
|
28
|
+
export function parseKitMarker(text: string | undefined): KitMarker {
|
|
29
|
+
if (text === undefined) return { state: 'absent' };
|
|
30
|
+
let parsed: unknown;
|
|
31
|
+
try {
|
|
32
|
+
parsed = JSON.parse(text);
|
|
33
|
+
} catch {
|
|
34
|
+
return { state: 'invalid', why: 'it is not JSON' };
|
|
35
|
+
}
|
|
36
|
+
if (!isJsonObject(parsed)) return { state: 'invalid', why: 'it is not an object' };
|
|
37
|
+
const off = parsed['off'];
|
|
38
|
+
if (off === undefined) return { state: 'present', off: [] };
|
|
39
|
+
if (!Array.isArray(off) || off.some((entry) => typeof entry !== 'string')) {
|
|
40
|
+
return { state: 'invalid', why: '"off" is not a list of entry names' };
|
|
41
|
+
}
|
|
42
|
+
return { state: 'present', off: off as string[] };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const finding = (code: string, cause: string, fix: string, at: string): Finding => ({
|
|
46
|
+
code,
|
|
47
|
+
cause,
|
|
48
|
+
fix,
|
|
49
|
+
docs: ERROR_DOCS_URL,
|
|
50
|
+
at,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
/** The managed files `x kit` writes: every entry the app has not switched off. */
|
|
54
|
+
export const activeKit = (
|
|
55
|
+
managed: readonly KitFile[],
|
|
56
|
+
off: readonly string[],
|
|
57
|
+
): readonly KitFile[] => managed.filter((file) => !off.includes(file.name));
|
|
58
|
+
|
|
59
|
+
const same = (a: string, b: string): boolean =>
|
|
60
|
+
a.replaceAll('\r\n', '\n') === b.replaceAll('\r\n', '\n');
|
|
61
|
+
|
|
62
|
+
/** One finding per managed file the disk lacks or holds edited. */
|
|
63
|
+
async function driftFindings(disk: KitDisk, files: readonly KitFile[]): Promise<Finding[]> {
|
|
64
|
+
const found: Finding[] = [];
|
|
65
|
+
for (const file of files) {
|
|
66
|
+
const held = await disk.read(file.path);
|
|
67
|
+
if (held !== undefined && same(held, file.contents)) continue;
|
|
68
|
+
const variant =
|
|
69
|
+
file.kind === 'skill'
|
|
70
|
+
? `.claude/skills/app-${file.name}/SKILL.md`
|
|
71
|
+
: `.claude/agents/app-${file.name}.md`;
|
|
72
|
+
found.push(
|
|
73
|
+
finding(
|
|
74
|
+
KIT_DRIFT,
|
|
75
|
+
held === undefined
|
|
76
|
+
? `${file.path} is a managed kit file and is missing`
|
|
77
|
+
: `${file.path} is a managed kit file and was edited by hand; \`x kit\` rewrites it`,
|
|
78
|
+
held === undefined
|
|
79
|
+
? KIT_FIX
|
|
80
|
+
: `${KIT_FIX} # to keep your change, copy the file to ${variant} and add "${file.name}" to "off" in ${KIT_MARKER} first`,
|
|
81
|
+
file.path,
|
|
82
|
+
),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return found;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** A `.claude/commands/<skill>.md` an ACTIVE skill of the same name silently shadows: not an "off" one. */
|
|
89
|
+
async function shadowFindings(disk: KitDisk, files: readonly KitFile[]): Promise<Finding[]> {
|
|
90
|
+
const found: Finding[] = [];
|
|
91
|
+
for (const file of files.filter((entry) => entry.kind === 'skill')) {
|
|
92
|
+
const path = `${COMMANDS_DIR}/${file.name}.md`;
|
|
93
|
+
if ((await disk.read(path)) === undefined) continue;
|
|
94
|
+
found.push(
|
|
95
|
+
finding(
|
|
96
|
+
KIT_SHADOWED,
|
|
97
|
+
`${path} is shadowed by the managed skill ${file.name}: the skill runs, the command never does`,
|
|
98
|
+
`git -C .claude/commands mv ${renderFixShellArg(`${file.name}.md`, '<command>.md')} ${renderFixShellArg(`app-${file.name}.md`, 'app-<command>.md')}`,
|
|
99
|
+
path,
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
return found;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface KitVerdict {
|
|
107
|
+
readonly marker: KitMarker;
|
|
108
|
+
readonly findings: readonly Finding[];
|
|
109
|
+
/** Advice that fails nothing: the marker absent, or one the gate cannot read. */
|
|
110
|
+
readonly warnings: readonly string[];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The kit against the disk. A marker that reads as a list of names to leave off is honoured; one
|
|
115
|
+
* that does not parse is a finding of its own, and nothing else is judged against a guess.
|
|
116
|
+
*/
|
|
117
|
+
export async function judgeKit(disk: KitDisk, managed: readonly KitFile[]): Promise<KitVerdict> {
|
|
118
|
+
const marker = parseKitMarker(await disk.read(KIT_MARKER));
|
|
119
|
+
if (marker.state === 'absent') {
|
|
120
|
+
return {
|
|
121
|
+
marker,
|
|
122
|
+
findings: [],
|
|
123
|
+
warnings: [`${KIT_MARKER} is absent: this app has no managed agent kit — fix: ${KIT_FIX}`],
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (marker.state === 'invalid') {
|
|
127
|
+
return {
|
|
128
|
+
marker,
|
|
129
|
+
findings: [
|
|
130
|
+
finding(
|
|
131
|
+
KIT_DRIFT,
|
|
132
|
+
`${KIT_MARKER} is unreadable: ${marker.why}`,
|
|
133
|
+
`printf '{\\n "off": []\\n}\\n' > ${KIT_MARKER}`,
|
|
134
|
+
KIT_MARKER,
|
|
135
|
+
),
|
|
136
|
+
],
|
|
137
|
+
warnings: [],
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const files = activeKit(managed, marker.off);
|
|
141
|
+
return {
|
|
142
|
+
marker,
|
|
143
|
+
findings: [...(await driftFindings(disk, files)), ...(await shadowFindings(disk, files))],
|
|
144
|
+
warnings: [],
|
|
145
|
+
};
|
|
146
|
+
}
|
package/src/budgets.ts
CHANGED
|
@@ -90,8 +90,10 @@ export interface BuildStats {
|
|
|
90
90
|
* origin), so two spellings of one fetch are charged once; and an app/ page is weighed as SERVED
|
|
91
91
|
* — its page boot charged, the runtime chunk that boot makes unfetched not (plan 101 sweep 9).
|
|
92
92
|
* `6`: a `<link rel="modulepreload">` is a fetch and is charged, deduped with every other (B4).
|
|
93
|
+
* `7`: the exempt theme script's bytes moved again — it also stamps `html[data-motion="paused"]`
|
|
94
|
+
* from the reader's stored motion pause before first paint (plan 101, 06 motion).
|
|
93
95
|
*/
|
|
94
|
-
export const BUILD_STATS_RULES =
|
|
96
|
+
export const BUILD_STATS_RULES = 7;
|
|
95
97
|
|
|
96
98
|
const chainOf = (stats: RouteStats): string =>
|
|
97
99
|
stats.heaviestChain === undefined ? 'unknown import chain' : stats.heaviestChain.join(' -> ');
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// Where an app's catalogs live, per locale: one flat `catalogs/<locale>.json`, or a directory
|
|
2
|
+
// `catalogs/<locale>/` of namespace files (`billing.json`, `site/home.json`) joined by a generated
|
|
3
|
+
// `index.ts`. Every CLI reader and writer of an app's catalogs asks this module, so the two forms
|
|
4
|
+
// are one answer: read, loaded, named in a finding, and written back in the form they came in.
|
|
5
|
+
|
|
6
|
+
// why: `node:` and not Bun: `Bun.file().exists()` answers false for a directory and Bun has no
|
|
7
|
+
// directory listing, and both are how a split locale is told from a flat one; Bun has no path API
|
|
8
|
+
// at all, so `join` builds what `Bun.file` reads.
|
|
9
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { renderThrowable } from '@ultimat3/core';
|
|
12
|
+
import type { Catalog, Locale } from '@ultimat3/i18n';
|
|
13
|
+
import {
|
|
14
|
+
catalogFilePrefix,
|
|
15
|
+
catalogInvalid,
|
|
16
|
+
catalogLayoutMixed,
|
|
17
|
+
joinCatalogFiles,
|
|
18
|
+
loadCatalog,
|
|
19
|
+
partitionCatalog,
|
|
20
|
+
} from '@ultimat3/i18n';
|
|
21
|
+
import { catalogBarrel } from './templates/catalog-barrel';
|
|
22
|
+
import { catalogJson } from './templates/catalog-json';
|
|
23
|
+
import { CATALOG_BARREL, CATALOG_ROOT, catalogDir, catalogPath } from './templates/locales';
|
|
24
|
+
|
|
25
|
+
/** `mixed` is a locale with both — refused on every read, repaired by `x i18n split`. */
|
|
26
|
+
export type CatalogForm = 'flat' | 'split' | 'mixed';
|
|
27
|
+
|
|
28
|
+
export interface LocaleLayout {
|
|
29
|
+
readonly form: CatalogForm;
|
|
30
|
+
/** Split and mixed: every namespace file, relative to the directory, sorted. Flat: none. */
|
|
31
|
+
readonly files: readonly string[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Locale → its layout, for every locale with a catalog on disk. */
|
|
35
|
+
export type CatalogLayout = Readonly<Record<Locale, LocaleLayout>>;
|
|
36
|
+
|
|
37
|
+
/** The namespace files of a locale directory, `/`-separated whatever the host's separator. */
|
|
38
|
+
async function namespaceFiles(root: string, locale: string): Promise<readonly string[]> {
|
|
39
|
+
const files: string[] = [];
|
|
40
|
+
const cwd = join(root, catalogDir(locale));
|
|
41
|
+
for await (const entry of new Bun.Glob('**/*.json').scan({ cwd, absolute: false })) {
|
|
42
|
+
files.push(entry.replaceAll('\\', '/'));
|
|
43
|
+
}
|
|
44
|
+
return files.sort();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Every locale on disk and its form. No `catalogs/` directory yet is no locale at all. */
|
|
48
|
+
export async function readCatalogLayout(root: string): Promise<CatalogLayout> {
|
|
49
|
+
const dir = join(root, CATALOG_ROOT);
|
|
50
|
+
if (!existsSync(dir)) return {};
|
|
51
|
+
const layout: Record<string, LocaleLayout> = {};
|
|
52
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
53
|
+
const flat = new Set(
|
|
54
|
+
entries
|
|
55
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith('.json'))
|
|
56
|
+
.map((entry) => entry.name.slice(0, -'.json'.length)),
|
|
57
|
+
);
|
|
58
|
+
for (const locale of flat) layout[locale] = { form: 'flat', files: [] };
|
|
59
|
+
for (const entry of entries.filter((one) => one.isDirectory())) {
|
|
60
|
+
const files = await namespaceFiles(root, entry.name);
|
|
61
|
+
layout[entry.name] = { form: flat.has(entry.name) ? 'mixed' : 'split', files };
|
|
62
|
+
}
|
|
63
|
+
return Object.fromEntries(Object.entries(layout).sort(([a], [b]) => (a < b ? -1 : 1)));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Where a finding points for `locale`: the flat file, or the directory a split locale is. */
|
|
67
|
+
export const catalogLocation = (layout: CatalogLayout | undefined, locale: Locale): string =>
|
|
68
|
+
layout !== undefined && Object.hasOwn(layout, locale) && layout[locale]?.form === 'split'
|
|
69
|
+
? `${catalogDir(locale)}/`
|
|
70
|
+
: catalogPath(locale);
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The one file that holds `key` in `locale`: a split locale's namespace file of the key's longest
|
|
74
|
+
* prefix, so a finding about `billing.plans.pro` sends its reader to `en/billing.json` rather than
|
|
75
|
+
* to a directory of forty files. A flat locale, or a key no file prefixes, is `catalogLocation`.
|
|
76
|
+
*/
|
|
77
|
+
export function catalogFileOf(
|
|
78
|
+
layout: CatalogLayout | undefined,
|
|
79
|
+
locale: Locale,
|
|
80
|
+
key: string,
|
|
81
|
+
): string {
|
|
82
|
+
const entry = layout !== undefined && Object.hasOwn(layout, locale) ? layout[locale] : undefined;
|
|
83
|
+
if (entry?.form !== 'split') return catalogLocation(layout, locale);
|
|
84
|
+
const owner = entry.files
|
|
85
|
+
.filter((name) => key.startsWith(`${catalogFilePrefix(name)}.`))
|
|
86
|
+
.sort((a, b) => b.length - a.length)[0];
|
|
87
|
+
return owner === undefined ? `${catalogDir(locale)}/` : `${catalogDir(locale)}/${owner}`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* A `JSON.parse` failure is still a catalog problem, not a bare-Error crash through the command —
|
|
92
|
+
* reported through the same factory a structural violation uses.
|
|
93
|
+
*/
|
|
94
|
+
function parseCatalogJson(path: string, raw: string): unknown {
|
|
95
|
+
try {
|
|
96
|
+
return JSON.parse(raw);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
throw catalogInvalid(path, renderThrowable(error));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const readJson = async (root: string, path: string): Promise<unknown> =>
|
|
103
|
+
parseCatalogJson(path, await Bun.file(join(root, path)).text());
|
|
104
|
+
|
|
105
|
+
/** The flat file's catalog: the one `x i18n split` folds into a directory. */
|
|
106
|
+
export async function loadFlatCatalog(root: string, locale: Locale): Promise<Catalog> {
|
|
107
|
+
return loadCatalog(await readJson(root, catalogPath(locale)));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** A split locale's directory as one catalog — `X_CATALOG_KEY_DUPLICATE` for a key two files hold. */
|
|
111
|
+
export async function loadSplitCatalog(
|
|
112
|
+
root: string,
|
|
113
|
+
locale: Locale,
|
|
114
|
+
files: readonly string[],
|
|
115
|
+
): Promise<Catalog> {
|
|
116
|
+
const parts = [];
|
|
117
|
+
for (const name of files) {
|
|
118
|
+
const path = `${catalogDir(locale)}/${name}`;
|
|
119
|
+
parts.push({ path, name, value: await readJson(root, path) });
|
|
120
|
+
}
|
|
121
|
+
return joinCatalogFiles(parts);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Every locale's catalog, parsed and flattened — never a bare `JSON.parse`: `loadCatalog` is the
|
|
126
|
+
* seam that fails a malformed entry loud (`X_CATALOG_INVALID`) instead of auditing it as empty.
|
|
127
|
+
* A mixed locale is `X_CATALOG_LAYOUT_MIXED`: which half ships is the question it cannot answer.
|
|
128
|
+
*/
|
|
129
|
+
export async function loadLayoutCatalogs(
|
|
130
|
+
root: string,
|
|
131
|
+
layout: CatalogLayout,
|
|
132
|
+
): Promise<Readonly<Record<Locale, Catalog>>> {
|
|
133
|
+
const catalogs: Record<string, Catalog> = {};
|
|
134
|
+
for (const [locale, { form, files }] of Object.entries(layout)) {
|
|
135
|
+
if (form === 'mixed') throw catalogLayoutMixed(locale);
|
|
136
|
+
catalogs[locale] =
|
|
137
|
+
form === 'flat'
|
|
138
|
+
? await loadFlatCatalog(root, locale)
|
|
139
|
+
: await loadSplitCatalog(root, locale, files);
|
|
140
|
+
}
|
|
141
|
+
return catalogs;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** One file a catalog write lands, root-relative. */
|
|
145
|
+
export interface CatalogWrite {
|
|
146
|
+
readonly path: string;
|
|
147
|
+
readonly contents: string;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* The files `catalog` is written as for `locale`, in `form` — each nested and sorted, the bytes
|
|
152
|
+
* `serializeCatalog` writes (`nestCatalog` walks the keys sorted): the one flat file, or one file per
|
|
153
|
+
* namespace — a key going to the existing file of its longest prefix (`files`), else to its
|
|
154
|
+
* namespace's own, created — plus the barrel over every file the directory then holds.
|
|
155
|
+
*/
|
|
156
|
+
export function catalogWrites(
|
|
157
|
+
locale: Locale,
|
|
158
|
+
catalog: Catalog,
|
|
159
|
+
form: CatalogForm,
|
|
160
|
+
files: readonly string[] = [],
|
|
161
|
+
): readonly CatalogWrite[] {
|
|
162
|
+
if (form === 'flat') return [{ path: catalogPath(locale), contents: catalogJson(catalog) }];
|
|
163
|
+
const parts = partitionCatalog(catalog, files);
|
|
164
|
+
const dir = catalogDir(locale);
|
|
165
|
+
// A file `catalog` leaves no key in is written empty, never left behind: the barrel imports it.
|
|
166
|
+
const names = [...new Set([...files, ...parts.keys()])].sort();
|
|
167
|
+
const writes = names.map((name) => ({
|
|
168
|
+
path: `${dir}/${name}`,
|
|
169
|
+
contents: catalogJson(parts.get(name) ?? {}),
|
|
170
|
+
}));
|
|
171
|
+
const barrel = catalogBarrel(names);
|
|
172
|
+
return [...writes, { path: `${dir}/${CATALOG_BARREL}`, contents: barrel }];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* `catalogWrites`, landed: only the files whose bytes change, so a sync that adds one key to
|
|
177
|
+
* `billing` leaves every other namespace file untouched. Answers the paths it wrote.
|
|
178
|
+
*/
|
|
179
|
+
export async function writeLocaleCatalog(
|
|
180
|
+
root: string,
|
|
181
|
+
locale: Locale,
|
|
182
|
+
catalog: Catalog,
|
|
183
|
+
layout: LocaleLayout | undefined,
|
|
184
|
+
): Promise<readonly string[]> {
|
|
185
|
+
const form = layout?.form === 'split' ? 'split' : 'flat';
|
|
186
|
+
const written: string[] = [];
|
|
187
|
+
for (const write of catalogWrites(locale, catalog, form, layout?.files)) {
|
|
188
|
+
const file = Bun.file(join(root, write.path));
|
|
189
|
+
if ((await file.exists()) && (await file.text()) === write.contents) continue;
|
|
190
|
+
await Bun.write(file, write.contents);
|
|
191
|
+
written.push(write.path);
|
|
192
|
+
}
|
|
193
|
+
return written;
|
|
194
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// The DNS half of a shot session's request interception: `Fetch.requestPaused` events are screened
|
|
2
|
+
// by an async resolver before `cdp-shot-watch.ts` sees them — refused ones failed here, the rest
|
|
3
|
+
// handed on unchanged.
|
|
4
|
+
//
|
|
5
|
+
// The watch decides by NAME (core's `hostDecision`, whose floor already refuses a private literal and
|
|
6
|
+
// `localhost`); a name that RESOLVES inward needs a resolver. Chrome re-resolves the name itself
|
|
7
|
+
// (rebinding stays open, as `@ultimat3/scraping`'s browser leg documents): this closes the static
|
|
8
|
+
// case, not the race. A WebSocket handshake is never paused by `Fetch` at all — whoever screens a
|
|
9
|
+
// session refuses sockets in the page (`DESIGN_PREPARE`).
|
|
10
|
+
|
|
11
|
+
import type { CdpConnection, CdpEventListener } from '@ultimat3/scraping/cdp';
|
|
12
|
+
|
|
13
|
+
/** Why a request was refused: it resolves inward, or it could not be resolved at all. */
|
|
14
|
+
export type DialRefusal = 'private' | 'unresolved';
|
|
15
|
+
|
|
16
|
+
export interface DialScreen {
|
|
17
|
+
/** The sessions whose pauses are this session's to decide; another's pass through untouched. */
|
|
18
|
+
readonly owns: (sessionId: string | undefined) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* `undefined` when there is nothing to resolve (the watch decides alone), else a promise of the
|
|
21
|
+
* refusal — `undefined` when the request may go. A rejection refuses as `unresolved`: an
|
|
22
|
+
* unscreened request is never released, and a resolver that failed proved nothing private.
|
|
23
|
+
*/
|
|
24
|
+
readonly screen: (url: string) => Promise<DialRefusal | undefined> | undefined;
|
|
25
|
+
/** Told of each refusal and why, so the caller can report what the page tried to reach. */
|
|
26
|
+
readonly refused: (url: string, reason: DialRefusal) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const urlOf = (params: Record<string, unknown>): string => {
|
|
30
|
+
const request = params['request'];
|
|
31
|
+
if (typeof request !== 'object' || request === null) return '';
|
|
32
|
+
const url = (request as Record<string, unknown>)['url'];
|
|
33
|
+
return typeof url === 'string' ? url : '';
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function screenedConnection(connection: CdpConnection, dial: DialScreen): CdpConnection {
|
|
37
|
+
const screenedListener =
|
|
38
|
+
(listener: CdpEventListener): CdpEventListener =>
|
|
39
|
+
(params, on) => {
|
|
40
|
+
if (!dial.owns(on)) return listener(params, on);
|
|
41
|
+
const url = urlOf(params);
|
|
42
|
+
const pending = dial.screen(url);
|
|
43
|
+
if (pending === undefined) return listener(params, on);
|
|
44
|
+
void pending
|
|
45
|
+
.catch((): DialRefusal => 'unresolved')
|
|
46
|
+
.then((refusal) => {
|
|
47
|
+
if (refusal === undefined) return listener(params, on);
|
|
48
|
+
dial.refused(url, refusal);
|
|
49
|
+
return connection
|
|
50
|
+
.send(
|
|
51
|
+
'Fetch.failRequest',
|
|
52
|
+
{ requestId: params['requestId'], errorReason: 'BlockedByClient' },
|
|
53
|
+
on,
|
|
54
|
+
)
|
|
55
|
+
.then(
|
|
56
|
+
() => undefined,
|
|
57
|
+
() => undefined,
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
send: (method, params, sessionId, deadlineMs) =>
|
|
63
|
+
connection.send(method, params, sessionId, deadlineMs),
|
|
64
|
+
once: (method, sessionId, timeoutMs) => connection.once(method, sessionId, timeoutMs),
|
|
65
|
+
on: (method, listener) =>
|
|
66
|
+
connection.on(
|
|
67
|
+
method,
|
|
68
|
+
method === 'Fetch.requestPaused' ? screenedListener(listener) : listener,
|
|
69
|
+
),
|
|
70
|
+
close: () => connection.close(),
|
|
71
|
+
};
|
|
72
|
+
}
|