@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,133 @@
1
+ // `x i18n split [<locale>]`: every flat catalog, or the one named, moved into a directory of
2
+ // namespace files — `catalogs/<locale>/<namespace>.json` — with the barrel that joins them, the
3
+ // app's index importing it and `.gitattributes` merging it. Lossless: the files join back to the
4
+ // exact catalog that was split. Idempotent: a split locale is re-derived in place, nothing moves.
5
+
6
+ // why: Bun has no path API, so `join` builds the absolute path `Bun.file` reads and deletes.
7
+ import { join } from 'node:path';
8
+ import type { Catalog } from '@ultimat3/i18n';
9
+ import { catalogKeyDuplicate } from '@ultimat3/i18n';
10
+ import type { CatalogLayout, LocaleLayout } from './catalog-layout';
11
+ import {
12
+ catalogFileOf,
13
+ loadFlatCatalog,
14
+ loadSplitCatalog,
15
+ readCatalogLayout,
16
+ writeLocaleCatalog,
17
+ } from './catalog-layout';
18
+ import { BadFlagError } from './errors';
19
+ import { syncI18nIndex } from './i18n-index';
20
+ import { msg } from './messages';
21
+ import type { CommandResult } from './output';
22
+ import { quoteArg } from './shell-quote';
23
+ import { catalogPath } from './templates/locales';
24
+ import {
25
+ FLAT_CATALOG_ATTRIBUTE,
26
+ MERGE_ATTRIBUTES,
27
+ ROOT_GITATTRIBUTES_PATH,
28
+ } from './templates/scaffold-gitattributes';
29
+
30
+ /** What one locale's split did. */
31
+ interface LocaleSplit {
32
+ readonly locale: string;
33
+ /** The form it was in before this run. */
34
+ readonly from: LocaleLayout['form'];
35
+ readonly keys: number;
36
+ readonly files: number;
37
+ }
38
+
39
+ /**
40
+ * A mixed locale's two halves as one catalog. A key both define is refused naming the flat file
41
+ * and the namespace file — never resolved by picking one: which wording ships is a decision.
42
+ */
43
+ async function mixedCatalog(root: string, locale: string, layout: CatalogLayout): Promise<Catalog> {
44
+ const flat = await loadFlatCatalog(root, locale);
45
+ const split = await loadSplitCatalog(root, locale, layout[locale]?.files ?? []);
46
+ for (const key of Object.keys(flat)) {
47
+ if (Object.hasOwn(split, key)) {
48
+ throw catalogKeyDuplicate(key, [catalogPath(locale), catalogFileOf(layout, locale, key)]);
49
+ }
50
+ }
51
+ return { ...split, ...flat };
52
+ }
53
+
54
+ async function splitLocale(
55
+ root: string,
56
+ locale: string,
57
+ layout: CatalogLayout,
58
+ ): Promise<{
59
+ readonly result: LocaleSplit;
60
+ readonly written: readonly string[];
61
+ readonly removed?: string;
62
+ }> {
63
+ const entry = layout[locale];
64
+ if (entry === undefined) {
65
+ throw new BadFlagError({
66
+ flag: 'locale',
67
+ command: 'i18n',
68
+ reason: `no catalog for "${locale}" at ${catalogPath(locale)}`,
69
+ fix: `x i18n add ${quoteArg(locale)}`,
70
+ });
71
+ }
72
+ let catalog: Catalog;
73
+ if (entry.form === 'flat') catalog = await loadFlatCatalog(root, locale);
74
+ else if (entry.form === 'mixed') catalog = await mixedCatalog(root, locale, layout);
75
+ else catalog = await loadSplitCatalog(root, locale, entry.files);
76
+ // Every namespace file first, the flat file deleted only after: a run that dies half-way leaves
77
+ // a mixed locale, which every read refuses and this command repairs — never a lost key.
78
+ const target = { form: 'split' as const, files: entry.files };
79
+ const written = await writeLocaleCatalog(root, locale, catalog, target);
80
+ if (entry.form !== 'split') await Bun.file(join(root, catalogPath(locale))).delete();
81
+ const files = (await readCatalogLayout(root))[locale]?.files.length ?? 0;
82
+ const result = { locale, from: entry.form, keys: Object.keys(catalog).length, files };
83
+ return entry.form === 'split'
84
+ ? { result, written }
85
+ : { result, written, removed: catalogPath(locale) };
86
+ }
87
+
88
+ /**
89
+ * `.gitattributes`' flat-only catalog rule, widened to the split layout — the line `x new` wrote
90
+ * before split catalogs existed. A file without that line (no merge rules, or rules written by
91
+ * hand) is left alone: `bunx x upgrade`'s `merge-drivers` codemod is what writes them.
92
+ */
93
+ async function widenAttributes(root: string): Promise<readonly string[]> {
94
+ const file = Bun.file(join(root, ROOT_GITATTRIBUTES_PATH));
95
+ if (!(await file.exists())) return [];
96
+ const held = await file.text();
97
+ if (!held.split('\n').includes(FLAT_CATALOG_ATTRIBUTE)) return [];
98
+ const rules = MERGE_ATTRIBUTES.split('\n').filter((line) => line.startsWith('packages/i18n/'));
99
+ await Bun.write(file, held.replace(FLAT_CATALOG_ATTRIBUTE, rules.join('\n')));
100
+ return [ROOT_GITATTRIBUTES_PATH];
101
+ }
102
+
103
+ /** `locale` is the positional, already validated by the caller; absent means every locale. */
104
+ export async function runSplit(root: string, locale: string | undefined): Promise<CommandResult> {
105
+ const layout = await readCatalogLayout(root);
106
+ const locales = locale === undefined ? Object.keys(layout) : [locale];
107
+ const results: LocaleSplit[] = [];
108
+ const written: string[] = [];
109
+ const removed: string[] = [];
110
+ for (const one of locales) {
111
+ const split = await splitLocale(root, one, layout);
112
+ results.push(split.result);
113
+ written.push(...split.written);
114
+ if (split.removed !== undefined) removed.push(split.removed);
115
+ }
116
+ // The index imports each locale in the form it is now in, and each barrel is current.
117
+ const index = await syncI18nIndex(root);
118
+ written.push(...(index.edited ?? []), ...(await widenAttributes(root)));
119
+ const touched = [...new Set(written)].sort();
120
+ const moved = results.filter((one) => one.from !== 'split').length;
121
+ return {
122
+ ok: index.findings.length === 0,
123
+ command: 'i18n',
124
+ summary: msg('cli.i18n.split', {
125
+ locales: results.length,
126
+ files: results.reduce((sum, one) => sum + one.files, 0),
127
+ moved,
128
+ }),
129
+ lines: [...touched.map((path) => ` ${path}`), ...removed.map((path) => ` ${path} (removed)`)],
130
+ findings: index.findings,
131
+ data: { locales: results.map((one) => ({ ...one })), written: touched, removed },
132
+ };
133
+ }
package/src/cmd-i18n.ts CHANGED
@@ -1,34 +1,28 @@
1
- // `x i18n check|add <locale>|sync <locale>` — the command every X_LOCALE_UNSUPPORTED,
1
+ // `x i18n check|add <locale>|sync <locale>|split [<locale>]` — the command every X_LOCALE_UNSUPPORTED,
2
2
  // X_CATALOG_MISSING_KEYS and X_CATALOG_INVALID fix line already names. CLI wiring only: the
3
3
  // facts come from `i18n-audit.ts`, the audit itself from `@ultimat3/i18n`'s own `auditCatalogs`.
4
4
 
5
- // why: `node:` and not Bun: Bun has no exclusive-create write, and `open(path, 'wx')` is the only
6
- // one there is — `Bun.write` overwrites, so an existence check before it is a race a second
7
- // `x i18n add` wins. `mkdir` comes with it because `open` does not create the parent directory
8
- // `Bun.write` would, and `node:path` because Bun exposes no path API to build what either of them
9
- // takes.
10
- import { type FileHandle, mkdir, open } from 'node:fs/promises';
11
- import { dirname, join } from 'node:path';
12
- import { DEFAULT_LOCALE, stringField } from '@ultimat3/core';
5
+ import { DEFAULT_LOCALE } from '@ultimat3/core';
13
6
  import type { Catalog } from '@ultimat3/i18n';
14
7
  import { auditCatalogs, catalogFor, catalogKeys } from '@ultimat3/i18n';
15
8
  import { adminKeyLabel, mountedAdminKeys } from './admin-catalog-keys';
16
9
  import { loadApp } from './app-load';
17
10
  import { requireAppRoot } from './app-root';
11
+ import type { CatalogLayout } from './catalog-layout';
12
+ import {
13
+ catalogLocation,
14
+ loadLayoutCatalogs,
15
+ readCatalogLayout,
16
+ writeLocaleCatalog,
17
+ } from './catalog-layout';
18
18
  import { i18nSpec } from './cmd-i18n-spec';
19
+ import { runSplit } from './cmd-i18n-split';
19
20
  import type { CliCommand, CommandContext } from './command';
20
- import { BadFlagError, CatalogExistsError, MissingPositionalError } from './errors';
21
- import {
22
- auditApp,
23
- loadCatalogs,
24
- resolveDefaultLocale,
25
- scanSource,
26
- seedCatalog,
27
- serializeCatalog,
28
- syncCatalog,
29
- } from './i18n-audit';
21
+ import { BadFlagError, MissingPositionalError } from './errors';
22
+ import { auditApp, resolveDefaultLocale, scanSource, seedCatalog, syncCatalog } from './i18n-audit';
30
23
  import { syncI18nIndex } from './i18n-index';
31
24
  import { localeParityFindings } from './i18n-locale-parity';
25
+ import { writeNewLocale } from './i18n-new-locale';
32
26
  import {
33
27
  checkRegistration,
34
28
  isLoudMiss,
@@ -48,41 +42,6 @@ export { I18N_SUBCOMMANDS } from './cmd-i18n-spec';
48
42
  /** `ExtractReport` is plain JSON by construction — same idiom as `cmd-registries.ts`'s `asJson`. */
49
43
  const asJson = (value: object): Record<string, JsonValue> => value as Record<string, JsonValue>;
50
44
 
51
- /**
52
- * `open`'s failure when the file is already there — the one errno this command translates.
53
- *
54
- * `stringField`, never `'code' in error && error.code`: `in` narrows for the COMPILER and promises
55
- * the runtime nothing, so the read still happens on a value this process did not build and a
56
- * throwing getter takes the command down one line after the guard written to make it safe. The
57
- * same repair `dev-lock.ts` took for the cast spelling of the identical read.
58
- */
59
- const isAlreadyExists = (error: unknown): boolean => stringField(error, 'code') === 'EEXIST';
60
-
61
- /**
62
- * The exclusive half of the create: `wx` fails rather than truncates, so an existing catalog is
63
- * refused by the write itself. An `existsSync` before a `Bun.write` is the same answer with a
64
- * window in it, and what falls through that window is a translator's work.
65
- */
66
- async function openExclusive(absolute: string, locale: string): Promise<FileHandle> {
67
- try {
68
- return await open(absolute, 'wx');
69
- } catch (error) {
70
- if (isAlreadyExists(error)) throw new CatalogExistsError({ locale, path: catalogPath(locale) });
71
- throw error;
72
- }
73
- }
74
-
75
- /** `x i18n add`'s only write. `catalogs/` may not exist yet, and `open` never creates it. */
76
- async function writeNewCatalog(absolute: string, locale: string, contents: string): Promise<void> {
77
- await mkdir(dirname(absolute), { recursive: true });
78
- const handle = await openExclusive(absolute, locale);
79
- try {
80
- await handle.writeFile(contents);
81
- } finally {
82
- await handle.close();
83
- }
84
- }
85
-
86
45
  function requireLocalePositional(ctx: CommandContext, sub: string): string {
87
46
  const raw = ctx.args.positionals[0];
88
47
  if (raw === undefined) {
@@ -132,21 +91,31 @@ const unansweredAdminKeys = (locale: string, keys: readonly string[]): readonly
132
91
  unanswered(catalogFor(locale), keys);
133
92
 
134
93
  async function runCheck(root: string): Promise<CommandResult> {
135
- const { report: audited, catalogs, extraction, ignoreUnused } = await auditApp(root);
94
+ const { report: audited, catalogs, extraction, ignoreUnused, layout } = await auditApp(root);
136
95
  // Corrected once, before anything reads it: the table's `missing` column, the summary count, the
137
96
  // findings and `--json`'s `data` are four projections of one report, and a placeholder counted in
138
97
  // only some of them is the command disagreeing with itself about the same app.
139
98
  const report = withPlaceholdersMissing(audited, catalogs);
140
99
  // The runtime question, asked after the file question and never instead of it: a catalog can be
141
100
  // complete on disk, used everywhere in source, and reach no registry at all (issue #249).
142
- const registration = await checkRegistration({ root, catalogs, extraction, ignoreUnused });
101
+ const registration = await checkRegistration({
102
+ root,
103
+ catalogs,
104
+ extraction,
105
+ ignoreUnused,
106
+ layout,
107
+ });
143
108
  // The two rules only a comparison with the reference locale can see: a slot one side does not
144
109
  // have, and a string nobody translated. The same call `x verify`'s `i18n` step makes, so the
145
110
  // command and the gate answer about an app with one voice.
146
- const parity = localeParityFindings(catalogs);
111
+ const parity = localeParityFindings(catalogs, layout);
147
112
  const parityLocales = new Set(parity.map((finding) => finding.meta?.['locale'])).size;
148
113
 
149
- const findings: Finding[] = [...missingKeyFindings(report), ...registration.findings, ...parity];
114
+ const findings: Finding[] = [
115
+ ...missingKeyFindings(report, layout),
116
+ ...registration.findings,
117
+ ...parity,
118
+ ];
150
119
 
151
120
  // Whether the LOCALE has a catalog is the wrong question — the framework's own `en` is always
152
121
  // registered, so a locale-presence column reads `yes` for an app whose every key is a loud miss.
@@ -228,12 +197,14 @@ async function runCheck(root: string): Promise<CommandResult> {
228
197
 
229
198
  async function runAdd(root: string, ctx: CommandContext): Promise<CommandResult> {
230
199
  const locale = resolveOneLocale(ctx, 'add');
231
- const path = catalogPath(locale);
232
200
  const app = await loadApp(root);
233
- const catalogs = await loadCatalogs(root);
201
+ const layout = await readCatalogLayout(root);
202
+ const catalogs = await loadLayoutCatalogs(root, layout);
234
203
  const from = resolveDefaultLocale(app.locales.defaultLocale, catalogs);
235
204
  const seeded = seedCatalog(from === undefined ? {} : (catalogs[from] ?? {}));
236
- await writeNewCatalog(join(root, path), locale, serializeCatalog(seeded));
205
+ // In the default locale's form: a split app's new locale is a directory of the same files.
206
+ const source = from === undefined ? undefined : layout[from];
207
+ const path = await writeNewLocale(root, locale, seeded, source);
237
208
  // The second half of adding a locale, and without it this command SHIPPED A RED GATE: the file
238
209
  // landed, `packages/i18n/src/index.ts` still said `locales: { en }`, and `x verify --only i18n`
239
210
  // answered `X_CATALOG_UNREGISTERED` with a fix naming an edit that had already been made. Same
@@ -319,6 +290,7 @@ async function adminCatalog(locale: string, seeded: boolean): Promise<Catalog> {
319
290
  async function backfillDefault(
320
291
  root: string,
321
292
  catalogs: Readonly<Record<string, Catalog>>,
293
+ layout: CatalogLayout,
322
294
  from: string,
323
295
  adminKeys: readonly string[],
324
296
  ): Promise<readonly string[]> {
@@ -330,13 +302,14 @@ async function backfillDefault(
330
302
  };
331
303
  const source = Object.fromEntries(adminKeys.map((key) => [key, real(key)]));
332
304
  const { merged, added } = syncCatalog(target, source);
333
- if (added.length > 0) await Bun.write(join(root, catalogPath(from)), serializeCatalog(merged));
305
+ if (added.length > 0) await writeLocaleCatalog(root, from, merged, layout[from]);
334
306
  return added;
335
307
  }
336
308
 
337
309
  async function runSync(root: string, ctx: CommandContext): Promise<CommandResult> {
338
310
  const locale = resolveOneLocale(ctx, 'sync');
339
- const catalogs = await loadCatalogs(root);
311
+ const layout = await readCatalogLayout(root);
312
+ const catalogs = await loadLayoutCatalogs(root, layout);
340
313
  const target = catalogs[locale];
341
314
  if (target === undefined) {
342
315
  throw new BadFlagError({
@@ -364,9 +337,12 @@ async function runSync(root: string, ctx: CommandContext): Promise<CommandResult
364
337
  : seedCatalog(catalogs[from] ?? {})),
365
338
  };
366
339
  const { merged, added } = syncCatalog(target, source);
367
- if (added.length > 0) await Bun.write(join(root, catalogPath(locale)), serializeCatalog(merged));
340
+ // Into the locale's own form: a split locale's key lands in its namespace file, created if new.
341
+ if (added.length > 0) await writeLocaleCatalog(root, locale, merged, layout[locale]);
368
342
  const adminAdded = added.filter((key) => Object.hasOwn(admin, key));
369
- const defaultAdded = seeded ? [] : await backfillDefault(root, catalogs, from, adminAdded);
343
+ const defaultAdded = seeded
344
+ ? []
345
+ : await backfillDefault(root, catalogs, layout, from, adminAdded);
370
346
  // Unconditional, and not only when keys moved: a catalog that reached disk some other way — a
371
347
  // hand-created file, a `git merge` — is exactly the unregistered locale the gate refuses, and
372
348
  // this is the command its `fix:` names. Re-deriving an index that is already correct writes the
@@ -389,7 +365,7 @@ async function runSync(root: string, ctx: CommandContext): Promise<CommandResult
389
365
  from: from ?? locale,
390
366
  added,
391
367
  total,
392
- path: catalogPath(locale),
368
+ path: catalogLocation(layout, locale),
393
369
  registered,
394
370
  // Which of `added` still need a human: every one but an admin label in the default locale.
395
371
  // `⟦key⟧` where there was no catalog to copy from, `⟦<default string>⟧` on a real merge —
@@ -410,6 +386,10 @@ export const i18nCommand: CliCommand = {
410
386
  const sub = ctx.args.subcommand ?? 'check';
411
387
  if (sub === 'add') return runAdd(root, ctx);
412
388
  if (sub === 'sync') return runSync(root, ctx);
389
+ if (sub === 'split') {
390
+ const named = ctx.args.positionals[0] === undefined ? undefined : resolveOneLocale(ctx, sub);
391
+ return runSplit(root, named);
392
+ }
413
393
  return runCheck(root);
414
394
  },
415
395
  };
@@ -0,0 +1,13 @@
1
+ // `x kit`'s declaration, apart from its body: the parser, `x help` and the `errors` step read it
2
+ // without loading `cmd-kit.ts`, which `registry.ts` imports only when the command runs.
3
+
4
+ import type { CommandSpec } from './parse';
5
+
6
+ export const kitSpec: CommandSpec = {
7
+ name: 'kit',
8
+ summary:
9
+ 'write the managed agent kit (.claude/skills, .claude/agents) from the installed framework; app-* files and "off" entries are never touched',
10
+ usage: 'x kit [--json]',
11
+ requiresApp: true,
12
+ flags: [],
13
+ };
package/src/cmd-kit.ts ADDED
@@ -0,0 +1,133 @@
1
+ // `x kit` — writes the managed agent kit into the app and refreshes it after an upgrade. A file is
2
+ // rewritten only when it differs; `app-*` files, `apps/web/DESIGN.md` and any entry `.claude/kit.json`
3
+ // lists under "off" are never touched, and `.claude/kit.json` is written once, when it is absent.
4
+
5
+ import { ERROR_DOCS_URL } from '@ultimat3/core';
6
+ import { activeKit, judgeKit, parseKitMarker } from './app-kit';
7
+ import { diskAt, managedKit } from './app-kit-disk';
8
+ import { requireAppRoot } from './app-root';
9
+ import { kitSpec } from './cmd-kit-spec';
10
+ import { agentKitCodemod } from './codemods/agent-kit';
11
+ import { fsCodemodApp } from './codemods/engine-fs';
12
+ import type { CliCommand, CommandContext } from './command';
13
+ import { ScaffoldPathEscapeError } from './errors';
14
+ import { KIT_MARKER, kitMarkerFile } from './kit/registry';
15
+ import { msg } from './messages';
16
+ import type { CommandResult, Finding } from './output';
17
+
18
+ export interface KitWrite {
19
+ readonly path: string;
20
+ readonly action: 'created' | 'updated';
21
+ }
22
+
23
+ /** What a refresh wrote. `findings` is what it could not decide for the author. */
24
+ export interface KitRefresh {
25
+ readonly written: readonly KitWrite[];
26
+ readonly unchanged: number;
27
+ readonly off: readonly string[];
28
+ readonly findings: readonly Finding[];
29
+ /** Old files kept as `app-<name>.md` before the managed ones landed: the edits nothing may lose. */
30
+ readonly renamed: readonly { readonly path: string; readonly reason: string }[];
31
+ }
32
+
33
+ /** A path the guard refused: named, with how to find the link that leaves the app. */
34
+ const escapeFinding = (path: string): Finding => ({
35
+ code: 'X_SCAFFOLD_PATH_ESCAPE',
36
+ cause: `${path} resolves outside the app (a symlink on the way leaves it), so x kit did not write it`,
37
+ fix: 'find .claude -type l -ls # each link that leaves the app: rm it, make the path a real file or directory, then: bunx x kit',
38
+ docs: ERROR_DOCS_URL,
39
+ at: path,
40
+ });
41
+
42
+ /** Writes every managed file that is missing or differs; the marker when absent. Never deletes. */
43
+ export async function refreshKit(root: string): Promise<KitRefresh> {
44
+ const disk = diskAt(root);
45
+ const managed = await managedKit(root);
46
+ const markerText = await disk.read(KIT_MARKER);
47
+ const marker = parseKitMarker(markerText);
48
+ // An unreadable marker is the author's: guessing its "off" list could overwrite a file it kept.
49
+ if (marker.state === 'invalid') {
50
+ const verdict = await judgeKit(disk, managed);
51
+ return { written: [], unchanged: 0, off: [], findings: verdict.findings, renamed: [] };
52
+ }
53
+ const off = marker.state === 'present' ? marker.off : [];
54
+ // No marker yet: a legacy `.claude/agents/<n>.md` an author edited sits on a managed path, and the
55
+ // write below would replace it. The codemod's own step keeps it as `app-<n>.md` first (and drops an
56
+ // unedited released one); with a marker it does nothing, and the gate judges an edit instead.
57
+ // Every write goes through the engine's guard (`codemods/engine-fs.ts`): a path that resolves
58
+ // outside the app, through a symlink or not, is refused and said so, never followed.
59
+ const app = fsCodemodApp(root);
60
+ const refusals: Finding[] = [];
61
+ const guarded = async <T>(path: string, work: () => Promise<T>): Promise<T | undefined> => {
62
+ try {
63
+ return await work();
64
+ } catch (error) {
65
+ if (!(error instanceof ScaffoldPathEscapeError)) throw error;
66
+ refusals.push(escapeFinding(path));
67
+ return undefined;
68
+ }
69
+ };
70
+ const carried =
71
+ marker.state === 'absent'
72
+ ? await guarded('.claude', () => agentKitCodemod().run(app))
73
+ : undefined;
74
+ const renamed = (carried?.skipped ?? []).map((skip) => ({
75
+ path: skip.path,
76
+ reason: skip.reason,
77
+ }));
78
+ const written: KitWrite[] = [];
79
+ let unchanged = 0;
80
+ for (const file of activeKit(managed, off)) {
81
+ const held = await guarded(file.path, () => app.read(file.path));
82
+ if (held === undefined && refusals.some((found) => found.at === file.path)) continue;
83
+ if (held === file.contents) {
84
+ unchanged += 1;
85
+ continue;
86
+ }
87
+ const landed = await guarded(file.path, async () => {
88
+ await app.write(file.path, file.contents);
89
+ return true;
90
+ });
91
+ if (landed === true) {
92
+ written.push({ path: file.path, action: held === undefined ? 'created' : 'updated' });
93
+ }
94
+ }
95
+ if (marker.state === 'absent') {
96
+ const file = kitMarkerFile();
97
+ const landed = await guarded(file.path, async () => {
98
+ await app.write(file.path, String(file.contents));
99
+ return true;
100
+ });
101
+ if (landed === true) written.push({ path: file.path, action: 'created' });
102
+ }
103
+ // Left for the author: a command a skill shadows is renamed with `git mv`, never by this command.
104
+ const after = await judgeKit(disk, managed);
105
+ return { written, unchanged, off, findings: [...refusals, ...after.findings], renamed };
106
+ }
107
+
108
+ export const kitCommand: CliCommand = {
109
+ spec: kitSpec,
110
+ async run(ctx: CommandContext): Promise<CommandResult> {
111
+ const root = requireAppRoot('kit', ctx.cwd).dir;
112
+ const done = await refreshKit(root);
113
+ return {
114
+ ok: done.findings.length === 0,
115
+ command: 'kit',
116
+ summary:
117
+ done.written.length === 0
118
+ ? msg('cli.kit.current', { count: done.unchanged })
119
+ : msg('cli.kit.wrote', { count: done.written.length }),
120
+ findings: done.findings,
121
+ data: {
122
+ written: done.written.map((w) => ({ ...w })),
123
+ unchanged: done.unchanged,
124
+ off: [...done.off],
125
+ renamed: done.renamed.map((r) => ({ ...r })),
126
+ },
127
+ lines: [
128
+ ...done.written.map((w) => `${w.action} ${w.path}`),
129
+ ...done.renamed.map((r) => `kept ${r.path}: ${r.reason}`),
130
+ ],
131
+ };
132
+ },
133
+ };