@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.
Files changed (169) hide show
  1. package/CLAUDE.md +1 -1
  2. package/README.md +9 -9
  3. package/package.json +29 -29
  4. package/src/app-kit-disk.ts +39 -0
  5. package/src/app-kit-forms.ts +27 -0
  6. package/src/app-kit.ts +146 -0
  7. package/src/budgets.ts +3 -1
  8. package/src/catalog-layout.ts +194 -0
  9. package/src/cdp-shot-driver-screen.ts +72 -0
  10. package/src/cdp-shot-driver.ts +17 -1
  11. package/src/cmd-design-capture.ts +210 -0
  12. package/src/cmd-design-errors.ts +50 -0
  13. package/src/cmd-design-paths.ts +47 -0
  14. package/src/cmd-design-publish.ts +64 -0
  15. package/src/cmd-design-run.ts +229 -0
  16. package/src/cmd-design-spec.ts +47 -0
  17. package/src/cmd-design-theme.ts +107 -0
  18. package/src/cmd-design-url.ts +201 -0
  19. package/src/cmd-design.ts +188 -0
  20. package/src/cmd-doctor.ts +3 -0
  21. package/src/cmd-generate-spec.ts +5 -0
  22. package/src/cmd-generate.ts +3 -1
  23. package/src/cmd-i18n-spec.ts +4 -4
  24. package/src/cmd-i18n-split.ts +133 -0
  25. package/src/cmd-i18n.ts +46 -66
  26. package/src/cmd-kit-spec.ts +13 -0
  27. package/src/cmd-kit.ts +133 -0
  28. package/src/cmd-shot-against.ts +275 -0
  29. package/src/cmd-shot-spec.ts +9 -1
  30. package/src/cmd-shot.ts +19 -0
  31. package/src/cmd-upgrade.ts +11 -0
  32. package/src/codemods/agent-kit.ts +130 -0
  33. package/src/codemods/agents-md-budget.ts +47 -0
  34. package/src/codemods/docs-visual-quality.ts +198 -0
  35. package/src/codemods/index.ts +8 -0
  36. package/src/codemods/settings-kit-allow.ts +49 -0
  37. package/src/config-redact.ts +20 -4
  38. package/src/db-rollback-pass.ts +4 -1
  39. package/src/design-extract-script.ts +187 -0
  40. package/src/design-extract.ts +311 -0
  41. package/src/design-map-colors.ts +180 -0
  42. package/src/design-map.ts +288 -0
  43. package/src/dev-child-watch.ts +16 -0
  44. package/src/dev-db-migrate.ts +27 -46
  45. package/src/dev-db-migrator-hold.ts +131 -0
  46. package/src/dev-db-rollback.ts +11 -2
  47. package/src/dev-rebuild-schema.ts +7 -24
  48. package/src/doctor-kit.ts +25 -0
  49. package/src/error-catalog.ts +4 -2
  50. package/src/error-codes-kit.ts +24 -0
  51. package/src/error-codes.ts +12 -10
  52. package/src/generate-catalog-locales.ts +25 -2
  53. package/src/generate-files.ts +31 -1
  54. package/src/generate-follow-ups.ts +8 -3
  55. package/src/guards-shipped-names.ts +5 -0
  56. package/src/i18n-audit.ts +17 -33
  57. package/src/i18n-index.ts +108 -31
  58. package/src/i18n-locale-parity.ts +14 -6
  59. package/src/i18n-new-locale.ts +75 -0
  60. package/src/i18n-registration.ts +52 -27
  61. package/src/island-capture.ts +36 -7
  62. package/src/kit/agent-audit.ts +49 -0
  63. package/src/kit/agent-data.ts +32 -0
  64. package/src/kit/agent-server.ts +34 -0
  65. package/src/kit/agent-shape.ts +61 -0
  66. package/src/kit/agent-web.ts +49 -0
  67. package/src/kit/design-map.ts +106 -0
  68. package/src/kit/managed.ts +12 -0
  69. package/src/kit/registry.ts +89 -0
  70. package/src/kit/skill-design-research.ts +119 -0
  71. package/src/kit/skill-feature.ts +159 -0
  72. package/src/kit/skill-planx.ts +139 -0
  73. package/src/kit/skill-upgrade.ts +94 -0
  74. package/src/kit/skill-verify.ts +80 -0
  75. package/src/mcp-errors.ts +5 -0
  76. package/src/mcp-ui-diff.ts +13 -38
  77. package/src/mcp-ui.ts +30 -1
  78. package/src/merge-state.ts +3 -2
  79. package/src/messages-design.ts +104 -0
  80. package/src/messages-floor.ts +2 -0
  81. package/src/messages-upgrade.ts +9 -0
  82. package/src/messages.ts +4 -0
  83. package/src/registry.ts +4 -0
  84. package/src/serve-boot-telemetry.ts +106 -0
  85. package/src/serve-boot.ts +23 -4
  86. package/src/shot-blank.ts +70 -0
  87. package/src/shot-diff.ts +96 -0
  88. package/src/shot-gpu.ts +17 -5
  89. package/src/templates/catalog-barrel.ts +84 -0
  90. package/src/templates/guard-animated-layout-script.ts +173 -0
  91. package/src/templates/guard-effect-without-fallback.ts +117 -0
  92. package/src/templates/guard-motion-adapter.ts +161 -0
  93. package/src/templates/guard-raw-frame-loop.ts +134 -0
  94. package/src/templates/guard-raw-motion-script.ts +132 -0
  95. package/src/templates/guard-raw-motion-ts-scan.ts +95 -0
  96. package/src/templates/guard-released-forms.ts +12 -1
  97. package/src/templates/guard-untranslated-string.ts +27 -6
  98. package/src/templates/index.ts +1 -2
  99. package/src/templates/island.ts +55 -8
  100. package/src/templates/kit-released-forms.ts +63 -0
  101. package/src/templates/locales.ts +6 -0
  102. package/src/templates/motion-scale.ts +115 -0
  103. package/src/templates/scaffold-claude.ts +39 -26
  104. package/src/templates/scaffold-design.ts +41 -0
  105. package/src/templates/scaffold-docs.ts +31 -7
  106. package/src/templates/scaffold-gitattributes.ts +9 -2
  107. package/src/templates/scaffold-guards.ts +31 -2
  108. package/src/templates/scaffold-i18n.ts +10 -6
  109. package/src/templates/scaffold-verify-floor.ts +3 -0
  110. package/src/templates/shapes/blog-site.ts +15 -0
  111. package/src/templates/shapes/blog.ts +2 -0
  112. package/src/templates/shapes/content-site.ts +13 -0
  113. package/src/templates/shapes/content.ts +2 -0
  114. package/src/templates/shapes/dashboard-detail.ts +2 -0
  115. package/src/templates/shapes/dashboard-motion.ts +284 -0
  116. package/src/templates/shapes/dashboard.ts +19 -1
  117. package/src/templates/shapes/landing-motion.ts +67 -0
  118. package/src/templates/shapes/offline.ts +5 -2
  119. package/src/templates/shapes/saas.ts +4 -0
  120. package/src/test-ignores.ts +3 -2
  121. package/src/upgrade-gate.ts +14 -2
  122. package/src/upgrade-kit.ts +65 -0
  123. package/src/upgrade-report-kit.ts +28 -0
  124. package/src/upgrade-report.ts +3 -0
  125. package/src/verify-checks.ts +9 -1
  126. package/src/verify-floor.ts +9 -1
  127. package/src/verify-local-only.ts +66 -0
  128. package/src/verify-run.ts +17 -2
  129. package/src/workspace-checks.ts +3 -3
  130. package/wiki/Actions.md +1 -1
  131. package/wiki/Agents.md +33 -1
  132. package/wiki/Auth.md +3 -3
  133. package/wiki/Batching-And-Preloading.md +1 -0
  134. package/wiki/CLI-Reference-Data.md +241 -0
  135. package/wiki/CLI-Reference-Gate.md +572 -0
  136. package/wiki/CLI-Reference-Project.md +414 -0
  137. package/wiki/CLI-Reference-Ship.md +348 -0
  138. package/wiki/CLI-Reference-Tools.md +687 -0
  139. package/wiki/CLI-Reference.md +18 -2227
  140. package/wiki/Compared.md +8 -8
  141. package/wiki/Configuration.md +26 -2
  142. package/wiki/Deployment.md +1 -1
  143. package/wiki/Design-Research.md +96 -0
  144. package/wiki/Effects.md +83 -0
  145. package/wiki/Entities-And-Migrations.md +3 -2
  146. package/wiki/FAQ.md +1 -1
  147. package/wiki/Getting-Started.md +1 -1
  148. package/wiki/Home.md +2 -2
  149. package/wiki/I18n.md +39 -5
  150. package/wiki/Installation.md +1 -1
  151. package/wiki/Jobs-And-Workflows.md +29 -1
  152. package/wiki/Known-Gaps.md +6 -2
  153. package/wiki/MCP-And-AI.md +4 -0
  154. package/wiki/Motion.md +85 -0
  155. package/wiki/Observability.md +15 -1
  156. package/wiki/Outbound-HTTP.md +62 -2
  157. package/wiki/PWA-And-Offline.md +1 -1
  158. package/wiki/Policies-And-Authz.md +10 -0
  159. package/wiki/Project-Layout.md +1 -1
  160. package/wiki/Realtime.md +29 -2
  161. package/wiki/Static-Assets.md +1 -1
  162. package/wiki/Testing.md +33 -0
  163. package/wiki/Theming.md +31 -8
  164. package/wiki/Troubleshooting.md +1 -1
  165. package/wiki/Tutorial-02-First-Feature.md +1 -1
  166. package/wiki/UI-Components.md +2 -0
  167. package/wiki/Upgrading.md +9 -3
  168. package/src/templates/scaffold-claude-agents.ts +0 -161
  169. package/src/templates/scaffold-claude-commands.ts +0 -239
@@ -0,0 +1,25 @@
1
+ // `x doctor`'s agent-kit fact: the managed skills and agents against the disk (`app-kit.ts`), as
2
+ // warnings with the fix. Never the verdict — `x verify` is where the kit is an error, and only once
3
+ // `.claude/kit.json` has opted the app in (`X_BREAKING_ON_MAIN`).
4
+
5
+ import { ERROR_DOCS_URL } from '@ultimat3/core';
6
+ import { KIT_FIX } from './app-kit';
7
+ import { kitVerdict } from './app-kit-disk';
8
+ import { KIT_MARKER } from './kit/registry';
9
+ import type { Finding } from './output';
10
+
11
+ export async function kitWarnings(root: string): Promise<readonly Finding[]> {
12
+ const verdict = await kitVerdict(root);
13
+ return [
14
+ ...verdict.findings,
15
+ ...verdict.warnings.map(
16
+ (cause): Finding => ({
17
+ code: 'X_KIT_DRIFT',
18
+ cause,
19
+ fix: KIT_FIX,
20
+ docs: ERROR_DOCS_URL,
21
+ at: KIT_MARKER,
22
+ }),
23
+ ),
24
+ ];
25
+ }
@@ -21,6 +21,7 @@ export const CATALOG_PACKAGES = [
21
21
  '@ultimat3/cache',
22
22
  '@ultimat3/core',
23
23
  '@ultimat3/db',
24
+ '@ultimat3/effects',
24
25
  '@ultimat3/entity',
25
26
  '@ultimat3/flags',
26
27
  '@ultimat3/http',
@@ -50,14 +51,15 @@ export const CATALOG_PACKAGES = [
50
51
  * declare (`error-catalog.test.ts`), which is why `admin` is not here: `x dev` imports it and
51
52
  * `package.json` depends on it. `ui` reaches the CLI only as `admin`'s own dependency, so an
52
53
  * installer that keeps transitive packages private reports its codes `unavailable` rather than
53
- * the CLI declaring a package no command imports. `scraping` left this list in 31.0.0: the boot
54
+ * the CLI declaring a package no command imports. `effects` is an app's optional package that no
55
+ * command imports, for the same reason. `scraping` left this list in 31.0.0: the boot
54
56
  * imports its `./adapter` when `runtime.ts` supplies a `scrapeDriver`, so it is declared. Every other
55
57
  * entry above is a real runtime import and must be a declared dependency — `error-catalog.test.ts`
56
58
  * holds the list to exactly that, because an undeclared one resolves through workspace symlinks
57
59
  * here and through nothing in an installed app, where `x errors explain X_FLAG_EXPIRED` then
58
60
  * refuses a code the wiki promises.
59
61
  */
60
- export const CATALOG_OPTIONAL_HOSTS: readonly string[] = ['@ultimat3/ui'];
62
+ export const CATALOG_OPTIONAL_HOSTS: readonly string[] = ['@ultimat3/effects', '@ultimat3/ui'];
61
63
 
62
64
  export interface ErrorCatalog {
63
65
  /** Packages whose codes are now registered. */
@@ -0,0 +1,24 @@
1
+ // The X_* codes of the design-research surface (`x design research`, `x shot --against`) and the
2
+ // managed agent kit (`x kit`, the gate's kit check) — split out of `error-codes.ts` at its 500-line
3
+ // ceiling, as `error-codes-shot.ts` was. `error-codes.ts` folds these into the CLI's one owned union
4
+ // and registers them in its one call; nothing else imports this file.
5
+
6
+ /** Codes the design-research commands and the agent kit declare and own. */
7
+ export const CLI_KIT_ERROR_CODES = [
8
+ 'X_DESIGN_URL_REFUSED',
9
+ 'X_DESIGN_REFERENCE_UNREACHABLE',
10
+ 'X_SHOT_AGAINST_MISSING',
11
+ 'X_KIT_DRIFT',
12
+ 'X_KIT_SHADOWED',
13
+ ] as const;
14
+
15
+ export type CliKitErrorCode = (typeof CLI_KIT_ERROR_CODES)[number];
16
+
17
+ /** Their titles, typed over the list above so a code without one is a build error. */
18
+ export const CLI_KIT_ERROR_TITLES: Readonly<Record<CliKitErrorCode, string>> = {
19
+ X_DESIGN_URL_REFUSED: 'design reference URL refused',
20
+ X_DESIGN_REFERENCE_UNREACHABLE: 'design reference unreachable',
21
+ X_SHOT_AGAINST_MISSING: 'no reference shot to compare against',
22
+ X_KIT_DRIFT: 'agent kit file drifted',
23
+ X_KIT_SHADOWED: 'agent kit name shadowed',
24
+ };
@@ -9,6 +9,8 @@ import type { CliBoundaryErrorCode } from './error-codes-boundary';
9
9
  import { CLI_BOUNDARY_ERROR_CODES, CLI_BOUNDARY_ERROR_TITLES } from './error-codes-boundary';
10
10
  import type { CliDoctorErrorCode } from './error-codes-doctor';
11
11
  import { CLI_DOCTOR_ERROR_CODES, CLI_DOCTOR_ERROR_TITLES } from './error-codes-doctor';
12
+ import type { CliKitErrorCode } from './error-codes-kit';
13
+ import { CLI_KIT_ERROR_CODES, CLI_KIT_ERROR_TITLES } from './error-codes-kit';
12
14
  import type { CliPackageErrorCode } from './error-codes-package';
13
15
  import { CLI_PACKAGE_ERROR_CODES, CLI_PACKAGE_ERROR_TITLES } from './error-codes-package';
14
16
  import type { CliProcessesErrorCode } from './error-codes-processes';
@@ -241,10 +243,9 @@ export const CLI_OWNED_ERROR_CODES = [
241
243
  ] as const;
242
244
 
243
245
  /**
244
- * `X_NOT_IMPLEMENTED` is `@ultimat3/core`'s — every planned command throws it through core's
245
- * own `NotImplementedError`, and none of them may declare a title for it. The CLI is the process that imports every
246
- * package (`error-catalog.ts`), so a title declared twice here is the one that would win by load
247
- * order rather than by ownership.
246
+ * `X_NOT_IMPLEMENTED` is `@ultimat3/core`'s — every planned command throws it through core's own
247
+ * `NotImplementedError`, and none may declare a title for it. The CLI imports every package
248
+ * (`error-catalog.ts`), so a title declared twice here would win by load order, not ownership.
248
249
  *
249
250
  * The three env codes are core's for the same reason: `defineEnv`, `checkEnv` and the
250
251
  * `.env.example` projection all live in `@ultimat3/core`, and `x env` is the surface that reports
@@ -276,6 +277,7 @@ export const CLI_ERROR_CODES = [
276
277
  ...CLI_AGENTS_ERROR_CODES,
277
278
  ...CLI_BOUNDARY_ERROR_CODES,
278
279
  ...CLI_DOCTOR_ERROR_CODES,
280
+ ...CLI_KIT_ERROR_CODES,
279
281
  ...CLI_PACKAGE_ERROR_CODES,
280
282
  ...CLI_PROCESSES_ERROR_CODES,
281
283
  ...CLI_SHOT_ERROR_CODES,
@@ -291,6 +293,7 @@ export type CliOwnedErrorCode =
291
293
  | CliAgentsErrorCode
292
294
  | CliBoundaryErrorCode
293
295
  | CliDoctorErrorCode
296
+ | CliKitErrorCode
294
297
  | CliPackageErrorCode
295
298
  | CliProcessesErrorCode
296
299
  | CliShotErrorCode
@@ -482,6 +485,7 @@ registerErrorCodes(
482
485
  ...CLI_PACKAGE_ERROR_TITLES,
483
486
  ...CLI_PROCESSES_ERROR_TITLES,
484
487
  ...CLI_SHOT_ERROR_TITLES,
488
+ ...CLI_KIT_ERROR_TITLES,
485
489
  ...CLI_TOOLING_ERROR_TITLES,
486
490
  ...CLI_VERIFY_ERROR_TITLES,
487
491
  }).map(([code, title]) => [code, { title }]),
@@ -490,9 +494,7 @@ registerErrorCodes(
490
494
 
491
495
  // This file exports NO `docsFor(code)`, and adding one back is the defect. A CLI error passes no
492
496
  // `docs:` at all — `UltimateError` fills it from `describeErrorCode(code).docs`, which is
493
- // `@ultimat3/core`'s `ERROR_DOCS_URL`: one page for every code, never one per code, because `wiki/`
494
- // is the framework's only public documentation surface and a code lives there in a TABLE ROW, which
495
- // has no anchor. A `Finding` is a plain object with no constructor to fill it, so it carries
496
- // `ERROR_DOCS_URL` imported from core — the same constant, not a second copy of it. The
497
- // `https://ultimate.dev/errors/<code>` links `docsFor` built until 9.x answered 404, host included,
498
- // on every error the CLI has ever thrown.
497
+ // `@ultimat3/core`'s `ERROR_DOCS_URL`: one page for every code, because `wiki/` is the only public
498
+ // documentation surface and a code lives there in a TABLE ROW, which has no anchor. A `Finding` has
499
+ // no constructor to fill it, so it carries `ERROR_DOCS_URL` imported from core — the same constant.
500
+ // The `https://ultimate.dev/errors/<code>` links `docsFor` built until 9.x answered 404 on every error.
@@ -4,13 +4,16 @@
4
4
  // with `x i18n add <locale>`, the one command that starts a catalog holding every existing key.
5
5
 
6
6
  import { renderFixShellArg } from '@ultimat3/core';
7
- import { type Catalog, loadCatalog } from '@ultimat3/i18n';
7
+ import { type Catalog, loadCatalog, partitionCatalog } from '@ultimat3/i18n';
8
8
  import { loadAppCatalogs } from '@ultimat3/i18n/app-catalogs';
9
+ import type { CatalogLayout } from './catalog-layout';
10
+ import { readCatalogLayout } from './catalog-layout';
9
11
  import { BadFlagError } from './errors';
10
12
  import { resolveDefaultLocale, seedCatalog, serializeCatalog } from './i18n-audit';
11
13
  import { catalogLocales } from './i18n-index';
12
14
  import type { GeneratedFile } from './templates';
13
15
  import { CATALOG_ROOT, catalogPath } from './templates';
16
+ import { catalogDir } from './templates/locales';
14
17
 
15
18
  /** The locale a `merge: 'json'` file is the catalog of, or `undefined` for any other file. */
16
19
  const localeOf = (file: GeneratedFile): string | undefined => {
@@ -69,13 +72,33 @@ export async function localiseCatalogs(
69
72
  });
70
73
  }
71
74
  }
72
- return files.map((file) => {
75
+ const localised = files.map((file) => {
73
76
  const locale = localeOf(file);
74
77
  if (file.merge !== 'json' || locale === undefined || locale === fallback) return file;
75
78
  if (fallback === undefined) return file;
76
79
  const generated: unknown = JSON.parse(file.contents);
77
80
  return { ...file, contents: serializeCatalog(seedCatalog(loadCatalog(generated))) };
78
81
  });
82
+ const layout = await readCatalogLayout(root);
83
+ return localised.flatMap((file) => intoLayout(file, layout));
84
+ }
85
+
86
+ /**
87
+ * A template's `catalogs/<locale>.json` landed where the app keeps that locale: as is for a flat
88
+ * one, and for a split one as one `merge: 'json'` file per namespace — each key in the existing
89
+ * file of its longest prefix, else in its namespace's own, created. Written as `<locale>.json`
90
+ * beside the directory, it would be `X_CATALOG_LAYOUT_MIXED` on the next read.
91
+ */
92
+ function intoLayout(file: GeneratedFile, layout: CatalogLayout): readonly GeneratedFile[] {
93
+ const locale = localeOf(file);
94
+ const entry = locale === undefined ? undefined : layout[locale];
95
+ if (file.merge !== 'json' || locale === undefined || entry?.form !== 'split') return [file];
96
+ const parts = partitionCatalog(loadCatalog(JSON.parse(file.contents)), entry.files);
97
+ return [...parts].map(([name, part]) => ({
98
+ ...file,
99
+ path: `${catalogDir(locale)}/${name}`,
100
+ contents: serializeCatalog(part),
101
+ }));
79
102
  }
80
103
 
81
104
  /**
@@ -34,6 +34,8 @@ import { importRowsFiles } from './templates/generate-import-rows';
34
34
  import { purgeFiles } from './templates/generate-purge';
35
35
  import { webhookReceiverFiles } from './templates/generate-webhook-receiver';
36
36
  import { inviteFiles } from './templates/invite';
37
+ import type { EffectEntry } from './templates/island';
38
+ import { EFFECT_ENTRIES } from './templates/island';
37
39
  import { helmMonitoringFiles } from './templates/scaffold-helm-alerts';
38
40
  import { oidcSignInFiles } from './templates/sign-in-oidc';
39
41
  import { passwordSignInFiles } from './templates/sign-in-password';
@@ -55,6 +57,8 @@ export interface GenerateOptions {
55
57
  * the path a page's `src` resolved to, and an app's admin is wherever its `defineAdmin` is.
56
58
  */
57
59
  readonly at?: string;
60
+ /** `island` only: wrap the panel in this `@ultimat3/effects` entry (`readEffect` has checked it). */
61
+ readonly effect?: EffectEntry;
58
62
  /** `admin:page` only: the permission the page's own work needs, on top of `admin:read`. */
59
63
  readonly permission?: string;
60
64
  /**
@@ -262,7 +266,12 @@ export function generate(options: GenerateOptions): readonly GeneratedFile[] {
262
266
  }),
263
267
  );
264
268
  case 'island':
265
- return dedupe(islandFiles(options.name, { dir: options.at ?? `${surfaceDir}/${feature}` }));
269
+ return dedupe(
270
+ islandFiles(options.name, {
271
+ dir: options.at ?? `${surfaceDir}/${feature}`,
272
+ effect: options.effect,
273
+ }),
274
+ );
266
275
  // No `--at`, no surface, no feature: `guards/` is the one directory the gate discovers, and a
267
276
  // guard that lived anywhere else would need an app-side registration to be found.
268
277
  // A name the framework ships a guard under is refused: that guard already runs, built in, and
@@ -344,3 +353,24 @@ export function generate(options: GenerateOptions): readonly GeneratedFile[] {
344
353
  }
345
354
  }
346
355
  }
356
+
357
+ const isEffectEntry = (value: string): value is EffectEntry => Object.hasOwn(EFFECT_ENTRIES, value);
358
+
359
+ /**
360
+ * `--effect`, against the closed set of entries that can wrap a panel: any other value, and the flag
361
+ * on a kind that has no panel, is refused before a file is planned (`X_CLI_BAD_FLAG`).
362
+ */
363
+ export function readEffect(raw: string | undefined, kind: Generator): EffectEntry | undefined {
364
+ if (raw === undefined) return undefined;
365
+ const entries = Object.keys(EFFECT_ENTRIES);
366
+ if (kind === 'island' && isEffectEntry(raw)) return raw;
367
+ throw new BadFlagError({
368
+ flag: 'effect',
369
+ command: 'g',
370
+ reason:
371
+ kind === 'island'
372
+ ? `"${raw}" is no entry that wraps a panel — one of: ${entries.join(', ')}`
373
+ : `only an island has a panel to wrap, and this is a ${kind}`,
374
+ fix: 'x g island <name> --effect aurora',
375
+ });
376
+ }
@@ -26,11 +26,16 @@ export interface FollowUps {
26
26
  readonly findings: readonly Finding[];
27
27
  }
28
28
 
29
- /** The locale each written catalog file is for: a dry run's catalogs are not on the disk yet. */
29
+ /**
30
+ * The locale each written catalog file is for: a dry run's catalogs are not on the disk yet. A
31
+ * flat `<locale>.json`, or any namespace file under a split locale's `<locale>/`.
32
+ */
30
33
  const writtenLocales = (written: readonly string[]): readonly string[] =>
31
34
  written.flatMap((path) => {
32
35
  const stem = path.startsWith(`${CATALOG_ROOT}/`) ? path.slice(CATALOG_ROOT.length + 1) : '';
33
- return stem.endsWith('.json') && !stem.includes('/') ? [stem.slice(0, -'.json'.length)] : [];
36
+ if (!stem.endsWith('.json')) return [];
37
+ const slash = stem.indexOf('/');
38
+ return [slash === -1 ? stem.slice(0, -'.json'.length) : stem.slice(0, slash)];
34
39
  });
35
40
 
36
41
  export async function followUpEdits(
@@ -55,7 +60,7 @@ export async function followUpEdits(
55
60
  // A catalog on disk and a locale the app can select are two facts — see `syncI18nIndex`.
56
61
  const indexSync =
57
62
  written.length > 0
58
- ? await syncI18nIndex(root, disk, writtenLocales(written))
63
+ ? await syncI18nIndex(root, disk, [...new Set(writtenLocales(written))], written)
59
64
  : { registered: true, findings: [] };
60
65
  return {
61
66
  edited: [
@@ -4,19 +4,24 @@
4
4
 
5
5
  export const SHIPPED_GUARD_NAMES = [
6
6
  'animated-layout-property',
7
+ 'animated-layout-script',
7
8
  'bare-error',
9
+ 'effect-without-fallback',
8
10
  'error-declared',
9
11
  'focus-visible',
10
12
  'image-dimensions',
11
13
  'island-mount-clears',
12
14
  'island-without-states',
15
+ 'motion-adapter',
13
16
  'native-confirm',
14
17
  'raw-breakpoint',
15
18
  'raw-colour',
16
19
  'raw-fetch',
20
+ 'raw-frame-loop',
17
21
  'raw-interval',
18
22
  'raw-length',
19
23
  'raw-motion',
24
+ 'raw-motion-script',
20
25
  'raw-shadow',
21
26
  'raw-z-index',
22
27
  'repo-await-in-loop',
package/src/i18n-audit.ts CHANGED
@@ -3,27 +3,26 @@
3
3
  // testable without a ParsedArgs or a rendered message.
4
4
 
5
5
  // why: `node:` and not Bun: `Bun.file().exists()` answers false for a directory, and `existsSync`
6
- // is how a missing `catalogs/` directory reads as "nothing shipped" instead of a throw; Bun has no
6
+ // is how a missing `packages/i18n` reads as "no catalog module" instead of a throw; Bun has no
7
7
  // path API at all — `join` builds the absolute path `Bun.file` reads; `posixRelative` turns it
8
8
  // back into the root-relative POSIX shape every CLI-reported path is keyed by.
9
9
  import { existsSync } from 'node:fs';
10
10
  import { join } from 'node:path';
11
- import { DEFAULT_LOCALE, renderThrowable } from '@ultimat3/core';
11
+ import { DEFAULT_LOCALE } from '@ultimat3/core';
12
12
  import type { Catalog, Extraction, ExtractReport, Locale } from '@ultimat3/i18n';
13
13
  import {
14
14
  auditCatalogs,
15
- catalogInvalid,
16
15
  catalogKeys,
17
16
  extractFromFiles,
18
- loadCatalog,
19
17
  missingFrom,
20
18
  nestCatalog,
21
19
  } from '@ultimat3/i18n';
20
+ import type { CatalogLayout } from './catalog-layout';
21
+ import { loadLayoutCatalogs, readCatalogLayout } from './catalog-layout';
22
22
  import { APP_KEY_SHAPES } from './i18n-app-key-shapes';
23
23
  import { isLoudMiss, loudMiss } from './i18n-registration';
24
24
  import { posixRelative } from './posix-path';
25
25
  import { eachSourceFile, isTest } from './source-files';
26
- import { CATALOG_ROOT, catalogPath } from './templates/locales';
27
26
 
28
27
  /**
29
28
  * Every key the app's own source names: a `t()` call, a mail block or subject, a push payload
@@ -54,35 +53,13 @@ export async function scanSource(root: string): Promise<Extraction> {
54
53
  }
55
54
 
56
55
  /**
57
- * A `JSON.parse` failure is still a catalog problem, not a bare-Error crash through this command —
58
- * reported through the same factory a structural violation (`loadCatalog` below) uses.
59
- */
60
- function parseCatalogJson(path: string, raw: string): unknown {
61
- try {
62
- return JSON.parse(raw);
63
- } catch (error) {
64
- throw catalogInvalid(path, renderThrowable(error));
65
- }
66
- }
67
-
68
- /**
69
- * Every `packages/i18n/catalogs/*.json` on disk, parsed and flattened through `loadCatalog` —
70
- * never a bare `JSON.parse`: a nested `{ one, other }` plural authored by hand is a known past
71
- * bug, and `loadCatalog` is the seam that fails it loud (`X_CATALOG_INVALID`) instead of auditing
72
- * it as an empty catalog. No `catalogs/` directory yet (a fresh app, or `packages/i18n` never
73
- * scaffolded) yields `{}` — every caller here treats that as "nothing shipped", not an error.
56
+ * Every catalog on disk, parsed and flattened, flat `catalogs/<locale>.json` and split
57
+ * `catalogs/<locale>/` alike (`catalog-layout.ts`). No `catalogs/` directory yet (a fresh app, or
58
+ * `packages/i18n` never scaffolded) yields `{}` — every caller here treats that as "nothing
59
+ * shipped", not an error.
74
60
  */
75
61
  export async function loadCatalogs(root: string): Promise<Readonly<Record<Locale, Catalog>>> {
76
- const dir = join(root, CATALOG_ROOT);
77
- if (!existsSync(dir)) return {};
78
- const catalogs: Record<string, Catalog> = {};
79
- for await (const entry of new Bun.Glob('*.json').scan({ cwd: dir, absolute: false })) {
80
- const locale = entry.replace(/\.json$/, '');
81
- const path = catalogPath(locale);
82
- const raw = await Bun.file(join(root, path)).text();
83
- catalogs[locale] = loadCatalog(parseCatalogJson(path, raw));
84
- }
85
- return catalogs;
62
+ return loadLayoutCatalogs(root, await readCatalogLayout(root));
86
63
  }
87
64
 
88
65
  export interface AuditFacts {
@@ -93,6 +70,8 @@ export interface AuditFacts {
93
70
  readonly extraction: Extraction;
94
71
  /** The `prefix*` patterns derived from dynamic calls, carried for the same reason. */
95
72
  readonly ignoreUnused: readonly string[];
73
+ /** Each locale's form on disk, so a finding names the file or directory the keys live in. */
74
+ readonly layout: CatalogLayout;
96
75
  }
97
76
 
98
77
  /** The static head of a template literal, up to its first interpolation. */
@@ -117,7 +96,11 @@ export function runtimeKeyPatterns(extraction: Extraction): readonly string[] {
117
96
 
118
97
  /** The source scan and the catalogs on disk, audited together — the one fact `x i18n check` reports. */
119
98
  export async function auditApp(root: string): Promise<AuditFacts> {
120
- const [extraction, catalogs] = await Promise.all([scanSource(root), loadCatalogs(root)]);
99
+ const layout = await readCatalogLayout(root);
100
+ const [extraction, catalogs] = await Promise.all([
101
+ scanSource(root),
102
+ loadLayoutCatalogs(root, layout),
103
+ ]);
121
104
  const ignoreUnused = runtimeKeyPatterns(extraction);
122
105
  return {
123
106
  // `reference` is what sees a key no static shape names: `t(\`plans.\${x}\`)` reads the same
@@ -126,6 +109,7 @@ export async function auditApp(root: string): Promise<AuditFacts> {
126
109
  catalogs,
127
110
  extraction,
128
111
  ignoreUnused,
112
+ layout,
129
113
  };
130
114
  }
131
115
 
package/src/i18n-index.ts CHANGED
@@ -1,4 +1,5 @@
1
- // The one writer of `packages/i18n/src/index.ts`, shared by `x g` and `x i18n add|sync`.
1
+ // The one writer of `packages/i18n/src/index.ts` and of each split locale's barrel
2
+ // (`catalogs/<locale>/index.ts`), shared by `x g` and `x i18n add|sync|split`.
2
3
  //
3
4
  // A catalog file existing on disk and the app being able to SELECT that locale are two different
4
5
  // facts, and only this closes the gap: the index hardcodes `locales: { en }`, so a locale whose
@@ -6,26 +7,20 @@
6
7
  // (`X_CATALOG_UNREGISTERED`). `x i18n add fr` wrote the file, touched nothing else, and left
7
8
  // `x verify` red with a fix line that named an edit nobody could perform (#F4).
8
9
 
9
- // why: Bun has no synchronous existence check — `Bun.file(p).exists()` is async, and this decides
10
- // whether to write at all, before any await the caller could interleave with.
11
- import { existsSync } from 'node:fs';
12
10
  import { stripComments } from '@ultimat3/core';
13
11
  import { APP_CATALOGS_PATH } from '@ultimat3/i18n/app-catalogs';
12
+ import type { CatalogLayout, LocaleLayout } from './catalog-layout';
13
+ import { readCatalogLayout } from './catalog-layout';
14
14
  import type { GenerateDisk } from './generate-disk';
15
15
  import { appDisk } from './generate-disk';
16
- import { containedPath } from './generate-write';
17
16
  import type { Finding } from './output';
18
17
  import { CATALOG_ROOT, i18nIndex, localeEntry, localeImport } from './templates';
18
+ import { catalogBarrel } from './templates/catalog-barrel';
19
+ import { CATALOG_BARREL, catalogDir } from './templates/locales';
19
20
 
20
- /** Every locale with a catalog on disk, sorted — the file names are the tags. */
21
+ /** Every locale with a catalog on disk, sorted — flat file stems and split directories alike. */
21
22
  export async function catalogLocales(root: string): Promise<readonly string[]> {
22
- const catalogDir = containedPath(root, CATALOG_ROOT);
23
- if (!existsSync(catalogDir)) return [];
24
- const locales: string[] = [];
25
- for await (const entry of new Bun.Glob('*.json').scan({ cwd: catalogDir, absolute: false })) {
26
- locales.push(entry.replace(/\.json$/, ''));
27
- }
28
- return locales.sort();
23
+ return Object.keys(await readCatalogLayout(root));
29
24
  }
30
25
 
31
26
  /** What a sync did: whether every catalog on disk is now selectable, and why not when it is not. */
@@ -37,12 +32,79 @@ export interface IndexSync {
37
32
  readonly edited?: readonly string[];
38
33
  }
39
34
 
40
- const CATALOG_IMPORT = /^import (\w+) from '\.\.\/catalogs\/([^']+)\.json';$/gm;
35
+ /** Both spellings `localeImport` writes: `import en from '../catalogs/en.json'` (flat) and
36
+ * `import { catalog as en } from '../catalogs/en'` (a split locale's barrel). */
37
+ const CATALOG_IMPORT =
38
+ /^import (?:(\w+)|\{ catalog as (\w+) \}) from '\.\.\/catalogs\/([^'/]+?)(\.json)?';$/gm;
41
39
  const LOCALES_OBJECT = /(locales:\s*\{)([^{}]*)(\})/;
42
40
 
43
- /** The tags the index imports a catalog for, in file order. */
44
- const importedLocales = (source: string): readonly string[] =>
45
- [...source.matchAll(CATALOG_IMPORT)].map((match) => match[2] ?? '');
41
+ interface ImportedLocale {
42
+ readonly locale: string;
43
+ readonly split: boolean;
44
+ readonly line: string;
45
+ readonly binding: string;
46
+ }
47
+
48
+ /** The tags the index imports a catalog for, in file order, each with the form it imports. */
49
+ const importedLocales = (source: string): readonly ImportedLocale[] =>
50
+ [...source.matchAll(CATALOG_IMPORT)].map((match) => ({
51
+ locale: match[3] ?? '',
52
+ split: match[4] === undefined,
53
+ line: match[0],
54
+ binding: match[1] ?? match[2] ?? '',
55
+ }));
56
+
57
+ /**
58
+ * Every import whose form no longer matches the disk, rewritten in place under its own binding —
59
+ * `x i18n split` turned `en.json` into `en/`, and nothing else in the index has to move.
60
+ */
61
+ function withForms(source: string, split: readonly string[]): string {
62
+ let next = source;
63
+ for (const imported of importedLocales(source)) {
64
+ const wanted = split.includes(imported.locale);
65
+ if (wanted === imported.split) continue;
66
+ const line = wanted
67
+ ? `import { catalog as ${imported.binding} } from '../catalogs/${imported.locale}';`
68
+ : `import ${imported.binding} from '../catalogs/${imported.locale}.json';`;
69
+ next = next.replace(imported.line, line);
70
+ }
71
+ return next;
72
+ }
73
+
74
+ /** Each split locale's barrel, re-derived from its files (and the ones a dry run plans). */
75
+ async function syncBarrels(
76
+ layout: CatalogLayout,
77
+ disk: GenerateDisk,
78
+ plannedFiles: readonly string[],
79
+ ): Promise<readonly string[]> {
80
+ const edited: string[] = [];
81
+ for (const [locale, { form, files }] of Object.entries(layout)) {
82
+ if (form !== 'split') continue;
83
+ const prefix = `${catalogDir(locale)}/`;
84
+ const planned = plannedFiles
85
+ .filter((path) => path.startsWith(prefix) && path.endsWith('.json'))
86
+ .map((path) => path.slice(prefix.length));
87
+ const barrel = catalogBarrel([...files, ...planned]);
88
+ const path = `${prefix}${CATALOG_BARREL}`;
89
+ if ((await disk.read(path)) === barrel) continue;
90
+ await disk.write(path, barrel);
91
+ edited.push(path);
92
+ }
93
+ return edited;
94
+ }
95
+
96
+ /** The layout on disk, with the split locales a dry run's planned files would create. */
97
+ function plannedLayout(layout: CatalogLayout, plannedFiles: readonly string[]): CatalogLayout {
98
+ const next: Record<string, LocaleLayout> = { ...layout };
99
+ for (const path of plannedFiles) {
100
+ const stem = path.startsWith(`${CATALOG_ROOT}/`) ? path.slice(CATALOG_ROOT.length + 1) : '';
101
+ const slash = stem.indexOf('/');
102
+ if (slash <= 0 || !stem.endsWith('.json')) continue;
103
+ const locale = stem.slice(0, slash);
104
+ next[locale] ??= { form: 'split', files: [] };
105
+ }
106
+ return next;
107
+ }
46
108
 
47
109
  /**
48
110
  * Makes every catalog on disk selectable, and touches the index no more than that takes.
@@ -58,26 +120,41 @@ export async function syncI18nIndex(
58
120
  disk: GenerateDisk = appDisk(root),
59
121
  /** Locales whose catalog a dry run PLANS: on the real disk only once the run has written. */
60
122
  planned: readonly string[] = [],
123
+ /** Catalog files a dry run plans, so a split locale's barrel names a namespace not yet written. */
124
+ plannedFiles: readonly string[] = [],
61
125
  ): Promise<IndexSync> {
126
+ const layout = plannedLayout(await readCatalogLayout(root), plannedFiles);
127
+ const barrels = await syncBarrels(layout, disk, plannedFiles);
128
+ const touching = (paths: readonly string[]) => (paths.length > 0 ? { edited: paths } : {});
62
129
  const current = await disk.read(APP_CATALOGS_PATH);
63
- if (current === undefined) return { registered: false, findings: [] };
64
- const onDisk = [...new Set([...(await catalogLocales(root)), ...planned])].sort();
130
+ if (current === undefined) return { registered: false, findings: [], ...touching(barrels) };
131
+ const onDisk = [...new Set([...Object.keys(layout), ...planned])].sort();
132
+ const split = onDisk.filter((locale) => layout[locale]?.form === 'split');
65
133
  const imported = importedLocales(current);
66
134
  const write = async (next: string): Promise<IndexSync> => {
67
- if (next === current) return { registered: true, findings: [] };
68
- await disk.write(APP_CATALOGS_PATH, next);
69
- return { registered: true, findings: [], edited: [APP_CATALOGS_PATH] };
135
+ const touched = next === current ? barrels : [...barrels, APP_CATALOGS_PATH];
136
+ if (next !== current) await disk.write(APP_CATALOGS_PATH, next);
137
+ return { registered: true, findings: [], ...touching(touched) };
70
138
  };
71
- if (current === i18nIndex(imported)) return write(i18nIndex(onDisk));
72
- const missing = onDisk.filter((locale) => !imported.includes(locale));
73
- if (missing.length === 0) return { registered: true, findings: [] };
74
- const edited = withLocales(current, missing);
75
- if (edited === undefined) return { registered: false, findings: [refusal(missing)] };
139
+ const importedTags = imported.map((entry) => entry.locale);
140
+ const importedSplit = imported.filter((entry) => entry.split).map((entry) => entry.locale);
141
+ if (current === i18nIndex(importedTags, importedSplit)) return write(i18nIndex(onDisk, split));
142
+ const reformed = withForms(current, split);
143
+ const missing = onDisk.filter((locale) => !importedTags.includes(locale));
144
+ if (missing.length === 0) return write(reformed);
145
+ const edited = withLocales(reformed, missing, split);
146
+ if (edited === undefined) {
147
+ return { registered: false, findings: [refusal(missing, split)], ...touching(barrels) };
148
+ }
76
149
  return write(edited);
77
150
  }
78
151
 
79
152
  /** Each import after the last catalog import (or at the top), each entry at the object's end. */
80
- function withLocales(source: string, locales: readonly string[]): string | undefined {
153
+ function withLocales(
154
+ source: string,
155
+ locales: readonly string[],
156
+ split: readonly string[],
157
+ ): string | undefined {
81
158
  // Found on the comment-stripped text (same offsets): a `locales: { … }` in a comment above the
82
159
  // call is prose, and it was the one this edited.
83
160
  const object = LOCALES_OBJECT.exec(stripComments(source));
@@ -89,16 +166,16 @@ function withLocales(source: string, locales: readonly string[]): string | undef
89
166
  const body = inner.trim().replace(/,$/, '');
90
167
  const entries = [body, ...locales.map(localeEntry)].filter((part) => part !== '').join(', ');
91
168
  const withEntries = `${source.slice(0, object.index)}${head} ${entries} }${source.slice(object.index + whole.length)}`;
92
- const imports = locales.map(localeImport).join('\n');
169
+ const imports = locales.map((locale) => localeImport(locale, split.includes(locale))).join('\n');
93
170
  const lastImport = [...withEntries.matchAll(CATALOG_IMPORT)].at(-1);
94
171
  if (lastImport === undefined) return `${imports}\n${withEntries}`;
95
172
  const at = lastImport.index + lastImport[0].length;
96
173
  return `${withEntries.slice(0, at)}\n${imports}${withEntries.slice(at)}`;
97
174
  }
98
175
 
99
- const refusal = (locales: readonly string[]): Finding => ({
176
+ const refusal = (locales: readonly string[], split: readonly string[]): Finding => ({
100
177
  code: 'X_CATALOG_UNREGISTERED',
101
178
  cause: `${APP_CATALOGS_PATH} is hand-written in a shape this writer cannot add ${locales.join(', ')} to, so those catalogs are on disk and not selectable`,
102
- fix: `defineCatalogs({ default, locales: { …, ${locales.map(localeEntry).join(', ')} } }) // in ${APP_CATALOGS_PATH}, below ${locales.map(localeImport).join(' ')}`,
179
+ fix: `defineCatalogs({ default, locales: { …, ${locales.map(localeEntry).join(', ')} } }) // in ${APP_CATALOGS_PATH}, below ${locales.map((locale) => localeImport(locale, split.includes(locale))).join(' ')}`,
103
180
  at: APP_CATALOGS_PATH,
104
181
  });