@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,117 @@
1
+ // The `effect-without-fallback` guard: a GPU or canvas effect is `EffectCanvas` from
2
+ // `@ultimat3/effects`, whose `fallback` is required by type. A raw `<canvas`, a WebGL context or
3
+ // `navigator.gpu` in a page is an effect with no static frame: blank under reduced motion, no
4
+ // WebGL, a lost context, and in every screenshot and server-rendered byte. REPORT ONLY in an app
5
+ //
6
+ // that predates it (`severity: 'warning'`); `x new` writes the `"error"` row.
7
+
8
+ import { guardCode } from './guard';
9
+ import { TS_BLANK_SOURCE } from './guard-raw-motion-ts-scan';
10
+ import type { GeneratedFile } from './naming';
11
+
12
+ /** Derived from the guard's name, never a literal: an `X_*` literal here is a FRAMEWORK code. */
13
+ const NAME = 'effect-without-fallback';
14
+ const CODE = guardCode(NAME);
15
+
16
+ const source =
17
+ (): string => `// effect-without-fallback: a canvas or GPU effect is EffectCanvas, whose fallback is required.
18
+ // \`x verify\` discovers every file in \`guards/\` and runs its \`guard\` inside the \`boundaries\`
19
+ // step — nothing registers this file, so nothing can forget to. Delete it to drop the rule.
20
+ //
21
+ // Read: \`<canvas\`, \`getContext('webgl…')\` and \`navigator.gpu\` in a \`.tsx\` outside tests. A canvas
22
+ // the app draws is
23
+ // \`<EffectCanvas draw={…} fallback={…} />\`. REPORT ONLY (\`severity: 'warning'\`) until clean.
24
+
25
+ import type { Finding, Guard } from '@ultimat3/cli';
26
+
27
+ /** The app owns the codes its own conventions raise — this one is named for the guard. */
28
+ const CODE = '${CODE}';
29
+
30
+ export interface SourceFile {
31
+ /** App-root-relative POSIX path, so the finding names the file an author opens. */
32
+ readonly path: string;
33
+ readonly source: string;
34
+ }
35
+
36
+ const SIGNATURES: readonly (readonly [RegExp, string])[] = [
37
+ [/<canvas\\b/g, 'a <canvas>'],
38
+ [/getContext\\s*\\(\\s*(['"\`])webgl/g, 'a WebGL context'],
39
+ [/(?<![\\w$])navigator\\s*\\.\\s*gpu\\b/g, 'navigator.gpu'],
40
+ ];
41
+
42
+ ${TS_BLANK_SOURCE}
43
+ /** Pure — the caller does the I/O — so the rule is testable without a filesystem. */
44
+ export function effectsWithoutFallback(files: readonly SourceFile[]): readonly Finding[] {
45
+ const findings: Finding[] = [];
46
+ for (const file of files) {
47
+ const text = blankScript(file.source);
48
+ for (const [pattern, name] of SIGNATURES) {
49
+ for (const match of text.matchAll(pattern)) {
50
+ const at = \`\${file.path}:\${text.slice(0, match.index).split('\\n').length}\`;
51
+ findings.push({
52
+ code: CODE,
53
+ cause: \`\${at} draws with \${name} outside EffectCanvas — no static frame stands in when motion is reduced, WebGL is missing or the context is lost\`,
54
+ fix: \`render <EffectCanvas draw={…} fallback={…} /> — import { EffectCanvas } from '@ultimat3/effects' — at \${at} (a ready-made effect such as ShaderBackground needs no canvas of yours), then: x verify --only boundaries\`,
55
+ at,
56
+ });
57
+ }
58
+ }
59
+ }
60
+ return findings.sort((a, b) => (a.at ?? '').localeCompare(b.at ?? '', 'en', { numeric: true }));
61
+ }
62
+
63
+ export const guard: Guard = {
64
+ summary: 'a canvas or GPU effect is EffectCanvas, whose fallback is required, never a raw canvas',
65
+ severity: 'warning',
66
+ async check(_root, sources) {
67
+ const code = await sources.files('{apps,packages}/**/*.tsx');
68
+ return effectsWithoutFallback(
69
+ code
70
+ .filter((file) => !/\\.(?:test|spec)\\.tsx$/.test(file.path))
71
+ .map((file) => ({ path: file.path, source: file.text })),
72
+ );
73
+ },
74
+ };
75
+ `;
76
+
77
+ const test =
78
+ (): string => `// The rule, driven directly. Failure case first: a guard whose rule silently stopped matching is
79
+ // a green gate over the convention it was written to enforce.
80
+
81
+ import { expect, unitTest } from '@ultimat3/testing';
82
+ import { effectsWithoutFallback } from './effect-without-fallback';
83
+
84
+ const file = (source: string, path = 'apps/web/app/feed/orb.island.tsx') => [{ path, source }];
85
+
86
+ unitTest('a raw canvas is refused at its line, and the fix names EffectCanvas', () => {
87
+ const findings = effectsWithoutFallback(file('const a = 1;\\nexport const V = () => <canvas />;'));
88
+ expect(findings).toHaveLength(1);
89
+ expect(findings[0]?.code).toBe('${CODE}');
90
+ expect(findings[0]?.at).toBe('apps/web/app/feed/orb.island.tsx:2');
91
+ expect(findings[0]?.fix).toContain('EffectCanvas');
92
+ });
93
+
94
+ unitTest('a WebGL context and navigator.gpu are the same rule', () => {
95
+ expect(effectsWithoutFallback(file("const gl = el.getContext('webgl2');"))).toHaveLength(1);
96
+ expect(effectsWithoutFallback(file('const gl = el.getContext("webgl");'))).toHaveLength(1);
97
+ expect(effectsWithoutFallback(file('const gpu = navigator.gpu;'))).toHaveLength(1);
98
+ });
99
+
100
+ unitTest('a comment-like string hides nothing: the canvas after it is still refused', () => {
101
+ expect(effectsWithoutFallback(file("const u = '//cdn'; const v = <canvas />;"))).toHaveLength(1);
102
+ });
103
+
104
+ unitTest('EffectCanvas, a 2d context, a comment and a string are silent', () => {
105
+ expect(effectsWithoutFallback(file('<EffectCanvas draw={d} fallback={<img />} />'))).toEqual([]);
106
+ expect(effectsWithoutFallback(file("const c = el.getContext('2d');"))).toEqual([]);
107
+ expect(effectsWithoutFallback(file('// <canvas /> navigator.gpu'))).toEqual([]);
108
+ const hidden = file("const s = '/* x */'; const t = <canvas />;");
109
+ expect(effectsWithoutFallback(hidden)).toHaveLength(1);
110
+ });
111
+ `;
112
+
113
+ /** `guards/effect-without-fallback.ts` and its test. The directory registers it. */
114
+ export const effectWithoutFallbackGuardFiles = (): readonly GeneratedFile[] => [
115
+ { path: `guards/${NAME}.ts`, contents: source() },
116
+ { path: `guards/${NAME}.test.ts`, contents: test() },
117
+ ];
@@ -0,0 +1,161 @@
1
+ // The `motion-adapter` guard: motion and GPU effects go through `@ultimat3/ui/motion` and
2
+ // `@ultimat3/effects`, never a second engine imported into app code. Every engine here is the
3
+ // framework's own (WAAPI for motion, a WebGL2 mount for shaders); a second one is a second tempo,
4
+ // a second reduced-motion story and a second bundle graph nobody budgeted. REPORT ONLY in an app
5
+ //
6
+ // that predates it (`severity: 'warning'`); `x new` writes the `"error"` row.
7
+
8
+ import { guardCode } from './guard';
9
+ import { TS_BLANK_SOURCE } from './guard-raw-motion-ts-scan';
10
+ import type { GeneratedFile } from './naming';
11
+
12
+ /** Derived from the guard's name, never a literal: an `X_*` literal here is a FRAMEWORK code. */
13
+ const NAME = 'motion-adapter';
14
+ const CODE = guardCode(NAME);
15
+
16
+ const source =
17
+ (): string => `// motion-adapter: motion and GPU effects come from the framework's adapter, never a direct engine.
18
+ // \`x verify\` discovers every file in \`guards/\` and runs its \`guard\` inside the \`boundaries\`
19
+ // step — nothing registers this file, so nothing can forget to. Delete it to drop the rule.
20
+ //
21
+ // Read: an import, re-export, \`import()\` or \`require()\` of an engine's package or one of its
22
+ // subpaths, in a script outside tests. REPORT ONLY (\`severity: 'warning'\`): listed, never red,
23
+ // until an app is clean of it; \`"error"\` in \`guards/shipped.json\` makes it gate.
24
+
25
+ import type { Finding, Guard } from '@ultimat3/cli';
26
+
27
+ /** The app owns the codes its own conventions raise — this one is named for the guard. */
28
+ const CODE = '${CODE}';
29
+
30
+ const MOTION_FIX =
31
+ "animate, stagger, inView, scrollLinked, layout, Presence from '@ultimat3/ui/motion'";
32
+ const GPU_FIX =
33
+ "ShaderBackground, EffectCanvas or another effect from '@ultimat3/effects' (its static frame is the fallback)";
34
+
35
+ /** Package → the framework surface that does its job. */
36
+ const ENGINES: Readonly<Record<string, string>> = {
37
+ motion: MOTION_FIX,
38
+ 'motion-dom': MOTION_FIX,
39
+ 'framer-motion': MOTION_FIX,
40
+ gsap: MOTION_FIX,
41
+ animejs: MOTION_FIX,
42
+ 'solid-motionone': MOTION_FIX,
43
+ 'solid-transition-group': "Presence, PresenceList from '@ultimat3/ui/motion'",
44
+ '@paper-design/shaders': GPU_FIX,
45
+ shaders: GPU_FIX,
46
+ ogl: GPU_FIX,
47
+ three: GPU_FIX,
48
+ };
49
+
50
+ export interface ScriptFile {
51
+ /** App-root-relative POSIX path, so the finding names the file an author opens. */
52
+ readonly path: string;
53
+ readonly source: string;
54
+ }
55
+
56
+ const SPECIFIER = /(?:\\bfrom\\s*|\\bimport\\s*\\(?\\s*|\\brequire\\s*\\(\\s*)(['"])([^'"\\n]+)\\1/g;
57
+
58
+ /** \`three/examples/jsm/x\` → \`three\`; \`@paper-design/shaders/react\` → \`@paper-design/shaders\`. */
59
+ const packageOf = (specifier: string): string =>
60
+ specifier
61
+ .split('/')
62
+ .slice(0, specifier.startsWith('@') ? 2 : 1)
63
+ .join('/');
64
+
65
+ ${TS_BLANK_SOURCE}
66
+ /** Pure — the caller does the I/O — so the rule is testable without a filesystem. */
67
+ export function motionAdapter(files: readonly ScriptFile[]): readonly Finding[] {
68
+ const findings: Finding[] = [];
69
+ for (const file of files) {
70
+ const text = blankScript(file.source);
71
+ for (const match of text.matchAll(SPECIFIER)) {
72
+ const engine = packageOf(match[2] ?? '');
73
+ if (!Object.hasOwn(ENGINES, engine)) continue;
74
+ const at = \`\${file.path}:\${text.slice(0, match.index).split('\\n').length}\`;
75
+ findings.push({
76
+ code: CODE,
77
+ cause: \`\${at} imports \${engine}, a second animation or effect engine — the app moves at one tempo, under one reduced-motion rule, through the framework's own\`,
78
+ fix: \`import \${ENGINES[engine]} at \${at}, then remove \${engine} from package.json and run: x verify --only boundaries\`,
79
+ at,
80
+ });
81
+ }
82
+ }
83
+ return findings;
84
+ }
85
+
86
+ export const guard: Guard = {
87
+ summary:
88
+ 'motion and effects come from @ultimat3/ui/motion and @ultimat3/effects, never a direct engine',
89
+ severity: 'warning',
90
+ async check(_root, sources) {
91
+ const code = await sources.files('{apps,packages}/**/*.{ts,tsx}');
92
+ return motionAdapter(
93
+ code
94
+ .filter((file) => !/\\.(?:test|spec|d)\\.tsx?$/.test(file.path))
95
+ .map((file) => ({ path: file.path, source: file.text })),
96
+ );
97
+ },
98
+ };
99
+ `;
100
+
101
+ const test =
102
+ (): string => `// The rule, driven directly. Failure case first: a guard whose rule silently stopped matching is
103
+ // a green gate over the convention it was written to enforce.
104
+
105
+ import { expect, unitTest } from '@ultimat3/testing';
106
+ import { motionAdapter } from './motion-adapter';
107
+
108
+ const file = (source: string) => [{ path: 'apps/web/app/feed/card.island.tsx', source }];
109
+
110
+ unitTest('a direct engine import is refused, at its line, with the adapter to use', () => {
111
+ const findings = motionAdapter(file("import { a } from './a';\\nimport b from 'motion';"));
112
+ expect(findings).toHaveLength(1);
113
+ expect(findings[0]?.code).toBe('${CODE}');
114
+ expect(findings[0]?.at).toBe('apps/web/app/feed/card.island.tsx:2');
115
+ expect(findings[0]?.fix).toContain('@ultimat3/ui/motion');
116
+ });
117
+
118
+ unitTest('every engine, its subpaths, import(), require() and re-exports are the same rule', () => {
119
+ const engines = [
120
+ "import 'gsap';",
121
+ "import { motion } from 'framer-motion';",
122
+ "import { animate } from 'motion/react';",
123
+ "import { x } from 'motion-dom';",
124
+ "import a from 'animejs';",
125
+ "import { Motion } from 'solid-motionone';",
126
+ "import { TransitionGroup } from 'solid-transition-group';",
127
+ "import { Mesh } from '@paper-design/shaders/react';",
128
+ "import { Shader } from 'shaders';",
129
+ "import { Renderer } from 'ogl';",
130
+ "import { Scene } from 'three/examples/jsm/Addons.js';",
131
+ "const m = await import('gsap');",
132
+ "const t = require('three');",
133
+ "export { animate } from 'motion';",
134
+ ];
135
+ for (const line of engines) expect(motionAdapter(file(line))).toHaveLength(1);
136
+ });
137
+
138
+ unitTest('a comment-like string hides nothing: the import after it is still refused', () => {
139
+ expect(motionAdapter(file("const g = 'dist/*'; import('gsap'); /** d */"))).toHaveLength(1);
140
+ expect(motionAdapter(file("const u = '//cdn'; const t = require('three');"))).toHaveLength(1);
141
+ });
142
+
143
+ unitTest('the adapter, a lookalike package, a comment and a string are silent', () => {
144
+ const silent = [
145
+ "import { animate } from '@ultimat3/ui/motion';",
146
+ "import { Aurora } from '@ultimat3/effects';",
147
+ "import { x } from 'motionless';",
148
+ "import { x } from 'threes';",
149
+ "import { x } from './motion';",
150
+ "// import { animate } from 'motion';",
151
+ "const s = 'gsap';",
152
+ ];
153
+ for (const line of silent) expect(motionAdapter(file(line))).toEqual([]);
154
+ });
155
+ `;
156
+
157
+ /** `guards/motion-adapter.ts` and its test. No index, no registry — the directory registers it. */
158
+ export const motionAdapterGuardFiles = (): readonly GeneratedFile[] => [
159
+ { path: `guards/${NAME}.ts`, contents: source() },
160
+ { path: `guards/${NAME}.test.ts`, contents: test() },
161
+ ];
@@ -0,0 +1,134 @@
1
+ // The `raw-frame-loop` guard: a per-frame loop is `frameLoop()` from `@ultimat3/ui/motion`, never a
2
+ // bare `requestAnimationFrame(`. A raw loop keeps painting in a hidden tab, offscreen and under
3
+ // reduced motion; `frameLoop` stops for each of those and for a user's pause (WCAG 2.2.2). A
4
+ // `// why:` on the call's line, or the line above it, admits a one-shot that is not a loop —
5
+ //
6
+ // as `raw-interval` admits a tick. REPORT ONLY in an app that predates it.
7
+
8
+ import { guardCode } from './guard';
9
+ import { LOCAL_BINDING_SOURCE } from './guard-local-binding';
10
+ import { TS_BLANK_SOURCE } from './guard-raw-motion-ts-scan';
11
+ import type { GeneratedFile } from './naming';
12
+
13
+ /** Derived from the guard's name, never a literal: an `X_*` literal here is a FRAMEWORK code. */
14
+ const NAME = 'raw-frame-loop';
15
+ const CODE = guardCode(NAME);
16
+
17
+ const source =
18
+ (): string => `// raw-frame-loop: a per-frame loop is frameLoop(), never a bare requestAnimationFrame(.
19
+ // \`x verify\` discovers every file in \`guards/\` and runs its \`guard\` inside the \`boundaries\`
20
+ // step — nothing registers this file, so nothing can forget to. Delete it to drop the rule.
21
+ //
22
+ // Why: a raw loop paints on in a hidden tab, offscreen and under reduced motion, and no user can
23
+ // pause it. \`frameLoop(tick, { el })\` from \`@ultimat3/ui/motion\` stops for each of those. Read: a
24
+ // bare, \`window.\`, \`self.\` or \`globalThis.\` \`requestAnimationFrame(\` in a script outside tests.
25
+ // Admitted: a \`// why:\` on the call's line or the line above it. Not read: a file that binds its
26
+ // own \`requestAnimationFrame\`. REPORT ONLY (\`severity: 'warning'\`) until an app is clean of it.
27
+
28
+ import type { Finding, Guard } from '@ultimat3/cli';
29
+
30
+ /** The app owns the codes its own conventions raise — this one is named for the guard. */
31
+ const CODE = '${CODE}';
32
+
33
+ export interface SourceFile {
34
+ /** App-root-relative POSIX path, so the finding names the file an author opens. */
35
+ readonly path: string;
36
+ readonly source: string;
37
+ }
38
+
39
+ const CALL = /(?<![\\w$.])(?:(?:globalThis|window|self)\\s*\\.\\s*)?requestAnimationFrame\\s*\\(/g;
40
+ const WHY = /\\/\\/\\s*why:/;
41
+
42
+ ${LOCAL_BINDING_SOURCE}
43
+
44
+ ${TS_BLANK_SOURCE}
45
+ /** Pure — the caller does the I/O — so the rule is testable without a filesystem. */
46
+ export function rawFrameLoops(files: readonly SourceFile[]): readonly Finding[] {
47
+ const findings: Finding[] = [];
48
+ for (const file of files) {
49
+ const lines = file.source.split('\\n');
50
+ const text = blankScript(file.source, true);
51
+ const local = bindsLocally(text, 'requestAnimationFrame');
52
+ for (const match of text.matchAll(CALL)) {
53
+ // A bare call to the file's own \`requestAnimationFrame\` is not the browser's; \`window.\` is.
54
+ if (local && match[0].startsWith('requestAnimationFrame')) continue;
55
+ const line = text.slice(0, match.index).split('\\n').length;
56
+ if (WHY.test(lines[line - 1] ?? '') || WHY.test(lines[line - 2] ?? '')) continue;
57
+ const at = \`\${file.path}:\${line}\`;
58
+ findings.push({
59
+ code: CODE,
60
+ cause: \`\${at} runs a frame loop with requestAnimationFrame, which keeps painting in a hidden tab, offscreen and under reduced motion, and which no user can pause\`,
61
+ fix: \`import { frameLoop } from '@ultimat3/ui/motion' and call frameLoop(tick, { el }) at \${at}, disposing it on cleanup — or add a // why: comment on that line naming why this call is not a loop — then: x verify --only boundaries\`,
62
+ at,
63
+ });
64
+ }
65
+ }
66
+ return findings;
67
+ }
68
+
69
+ export const guard: Guard = {
70
+ summary: 'a per-frame loop is frameLoop(), never a bare requestAnimationFrame',
71
+ severity: 'warning',
72
+ async check(_root, sources) {
73
+ const code = await sources.files('{apps,packages}/**/*.{ts,tsx}');
74
+ return rawFrameLoops(
75
+ code
76
+ .filter((file) => !/\\.(?:test|spec|d)\\.tsx?$/.test(file.path))
77
+ .map((file) => ({ path: file.path, source: file.text })),
78
+ );
79
+ },
80
+ };
81
+ `;
82
+
83
+ const test =
84
+ (): string => `// The rule, driven directly. Failure case first: a guard whose rule silently stopped matching is
85
+ // a green gate over the convention it was written to enforce.
86
+
87
+ import { expect, unitTest } from '@ultimat3/testing';
88
+ import { rawFrameLoops } from './raw-frame-loop';
89
+
90
+ const file = (source: string) => [{ path: 'apps/web/app/feed/orb.island.tsx', source }];
91
+
92
+ unitTest('a bare requestAnimationFrame is refused, and the finding names the line', () => {
93
+ const findings = rawFrameLoops(file('const a = 1;\\nrequestAnimationFrame(tick);'));
94
+ expect(findings).toHaveLength(1);
95
+ expect(findings[0]?.code).toBe('${CODE}');
96
+ expect(findings[0]?.at).toBe('apps/web/app/feed/orb.island.tsx:2');
97
+ expect(findings[0]?.fix).toContain('frameLoop');
98
+ });
99
+
100
+ unitTest('window., self. and globalThis. are the same rule', () => {
101
+ expect(rawFrameLoops(file('window.requestAnimationFrame(tick);'))).toHaveLength(1);
102
+ expect(rawFrameLoops(file('self.requestAnimationFrame(tick);'))).toHaveLength(1);
103
+ expect(rawFrameLoops(file('globalThis.requestAnimationFrame(tick);'))).toHaveLength(1);
104
+ });
105
+
106
+ unitTest('a why: on the line or the line above admits it', () => {
107
+ const same = file('requestAnimationFrame(focus); // why: one frame');
108
+ expect(rawFrameLoops(same)).toEqual([]);
109
+ const above = file('// why: one frame\\nrequestAnimationFrame(focus);');
110
+ expect(rawFrameLoops(above)).toEqual([]);
111
+ });
112
+
113
+ unitTest('a comment-like string hides nothing: the call after it is still refused', () => {
114
+ expect(rawFrameLoops(file("const u = '//cdn'; requestAnimationFrame(tick);"))).toHaveLength(1);
115
+ const doc = file("const g = 'dist/*'; requestAnimationFrame(t); /** d */");
116
+ expect(rawFrameLoops(doc)).toHaveLength(1);
117
+ });
118
+
119
+ unitTest('frameLoop, another object, a comment, a string and a local binding are not calls', () => {
120
+ expect(rawFrameLoops(file('frameLoop(tick, { el });'))).toEqual([]);
121
+ expect(rawFrameLoops(file('clock.requestAnimationFrame(tick);'))).toEqual([]);
122
+ expect(rawFrameLoops(file('// requestAnimationFrame(tick);'))).toEqual([]);
123
+ expect(rawFrameLoops(file("const s = 'requestAnimationFrame(tick)';"))).toEqual([]);
124
+ expect(
125
+ rawFrameLoops(file('const requestAnimationFrame = fake;\\nrequestAnimationFrame(tick);')),
126
+ ).toEqual([]);
127
+ });
128
+ `;
129
+
130
+ /** `guards/raw-frame-loop.ts` and its test. No index, no registry — the directory registers it. */
131
+ export const rawFrameLoopGuardFiles = (): readonly GeneratedFile[] => [
132
+ { path: `guards/${NAME}.ts`, contents: source() },
133
+ { path: `guards/${NAME}.test.ts`, contents: test() },
134
+ ];
@@ -0,0 +1,132 @@
1
+ // The `raw-motion-script` guard: `raw-motion`'s rule for TypeScript. A duration or delay handed to
2
+ // `.animate(` and a `cubic-bezier(` string come off the motion scale (`motionTiming()` from
3
+ // `@ultimat3/ui/motion`), so a script moves at the tempo the stylesheets do. A guard of its own,
4
+ // REPORT ONLY (`severity: 'warning'`), because `raw-motion` gates and a stricter rule on `main`
5
+ //
6
+ // is a break; `x new` writes the `"error"` row.
7
+
8
+ import { guardCode } from './guard';
9
+ import { TS_ANIMATE_SCAN_SOURCE } from './guard-raw-motion-ts-scan';
10
+ import { MOTION_SCALE_SOURCE } from './motion-scale';
11
+ import type { GeneratedFile } from './naming';
12
+
13
+ /** Derived from the guard's name, never a literal: an `X_*` literal here is a FRAMEWORK code. */
14
+ const NAME = 'raw-motion-script';
15
+ const CODE = guardCode(NAME);
16
+
17
+ const source =
18
+ (): string => `// raw-motion-script: a script's durations and curves come off the motion scale, never a literal.
19
+ // \`x verify\` discovers every file in \`guards/\` and runs its \`guard\` inside the \`boundaries\`
20
+ // step — nothing registers this file, so nothing can forget to. Delete it to drop the rule.
21
+ //
22
+ // Read: a nonzero number written as \`duration\`, \`delay\` or \`endDelay\` inside a \`.animate(\` call,
23
+ // and any \`cubic-bezier(\` string, in a script outside tests. REPORT ONLY (\`severity: 'warning'\`).
24
+
25
+ import type { Finding, Guard } from '@ultimat3/cli';
26
+
27
+ /** The app owns the codes its own conventions raise — this one is named for the guard. */
28
+ const CODE = '${CODE}';
29
+
30
+ ${MOTION_SCALE_SOURCE}
31
+ ${TS_ANIMATE_SCAN_SOURCE}
32
+ const NUMBER_OPTION = /(?<![\\w$.])(duration|delay|endDelay)\\s*:\\s*(\\d*\\.?\\d+)(?![\\w.])/g;
33
+
34
+ /** Pure — the caller does the I/O — so the rule is testable without a filesystem. */
35
+ export function rawMotionScripts(files: readonly ScriptFile[]): readonly Finding[] {
36
+ const findings: Finding[] = [];
37
+ for (const file of files) {
38
+ if (!isAppScript(file.path)) continue;
39
+ const text = blankScriptComments(file.source);
40
+ for (const call of animateCalls(text)) {
41
+ for (const match of call.body.matchAll(NUMBER_OPTION)) {
42
+ const ms = Number(match[2]);
43
+ if (ms === 0) continue;
44
+ const at = \`\${file.path}:\${scriptLineOf(text, call.start + match.index)}\`;
45
+ findings.push({
46
+ code: CODE,
47
+ cause: \`\${at} animates with \\\`\${match[1]}: \${match[2]}\\\` — a time of this call's own, off the motion scale\`,
48
+ fix: \`\${match[1]}: motionTiming('\${durationFor(ms)}').duration — import { motionTiming } from '@ultimat3/ui/motion' at \${at} (durations: \${DURATIONS.map(([name]) => name).join(' ')}), then: x verify --only boundaries\`,
49
+ at,
50
+ });
51
+ }
52
+ }
53
+ for (const match of text.matchAll(/cubic-bezier\\(([^)]*)\\)/g)) {
54
+ const at = \`\${file.path}:\${scriptLineOf(text, match.index)}\`;
55
+ findings.push({
56
+ code: CODE,
57
+ cause: \`\${at} writes \\\`\${match[0]}\\\` — an easing curve of this file's own, off the motion scale\`,
58
+ fix: \`easing: motionTiming('base', '\${easingFor(match[1] ?? '')}').easing — import { motionTiming } from '@ultimat3/ui/motion' at \${at} (easings: \${Object.values(EASINGS).join(' ')}), then: x verify --only boundaries\`,
59
+ at,
60
+ });
61
+ }
62
+ }
63
+ return findings;
64
+ }
65
+
66
+ export const guard: Guard = {
67
+ summary: 'script durations and easing curves come off the motion scale, never a literal',
68
+ severity: 'warning',
69
+ async check(_root, sources) {
70
+ const scripts = await sources.files('{apps,packages}/**/*.{ts,tsx}');
71
+ return rawMotionScripts(scripts.map((file) => ({ path: file.path, source: file.text })));
72
+ },
73
+ };
74
+ `;
75
+
76
+ const test =
77
+ (): string => `// The rule, driven directly. Failure case first: a guard whose rule silently stopped matching is
78
+ // a green gate over the convention it was written to enforce.
79
+
80
+ import { expect, unitTest } from '@ultimat3/testing';
81
+ import { rawMotionScripts } from './raw-motion-script';
82
+
83
+ const script = (source: string) => [{ path: 'apps/web/app/feed/card.island.tsx', source }];
84
+
85
+ unitTest('a number as duration or delay in .animate( is refused, with the token', () => {
86
+ const findings = rawMotionScripts(
87
+ script('el.animate({ opacity: [0, 1] }, { duration: 300, easing: "ease" });'),
88
+ );
89
+ expect(findings).toHaveLength(1);
90
+ expect(findings[0]?.code).toBe('${CODE}');
91
+ expect(findings[0]?.fix).toStartWith("duration: motionTiming('base').duration — ");
92
+ expect(rawMotionScripts(script('\\nel.animate(k, {\\n delay: 130,\\n});'))[0]?.at).toBe(
93
+ 'apps/web/app/feed/card.island.tsx:3',
94
+ );
95
+ });
96
+
97
+ unitTest('a cubic-bezier string in a script is refused, and the nearest token named', () => {
98
+ const findings = rawMotionScripts(script("const e = 'cubic-bezier(0.2, 0.9, 0.3, 1)';"));
99
+ expect(findings).toHaveLength(1);
100
+ expect(findings[0]?.fix).toStartWith("easing: motionTiming('base', 'out').easing — ");
101
+ });
102
+
103
+ unitTest('a comment-like string hides nothing: the call after it is still read', () => {
104
+ const source = "const g = 'dist/*'; el.animate(k, { duration: 300 }); /** doc */";
105
+ expect(rawMotionScripts(script(source))).toHaveLength(1);
106
+ const cdn = script("const u = '//cdn'; el.animate(k, { delay: 90 });");
107
+ expect(rawMotionScripts(cdn)).toHaveLength(1);
108
+ });
109
+
110
+ unitTest('a token read, a zero, another call, a comment and a test are silent', () => {
111
+ const silent = [
112
+ 'el.animate(k, { duration: timing.duration, delay: 0 });',
113
+ 'el.animate(k, { duration: motionTiming("fast").duration });',
114
+ 'setTimeout(run, { duration: 300 });',
115
+ 'run({ duration: 300 });',
116
+ '// el.animate(k, { duration: 300 });',
117
+ "el.animate({ transform: 'translate(0)' }, { duration: t }); run({ duration: 300 });",
118
+ ];
119
+ for (const source of silent) expect(rawMotionScripts(script(source))).toEqual([]);
120
+ expect(
121
+ rawMotionScripts([
122
+ { path: 'apps/web/app/card.test.ts', source: 'el.animate(k, { duration: 300 });' },
123
+ ]),
124
+ ).toEqual([]);
125
+ });
126
+ `;
127
+
128
+ /** `guards/raw-motion-script.ts` and its test. The directory registers it. */
129
+ export const rawMotionScriptGuardFiles = (): readonly GeneratedFile[] => [
130
+ { path: `guards/${NAME}.ts`, contents: source() },
131
+ { path: `guards/${NAME}.test.ts`, contents: test() },
132
+ ];
@@ -0,0 +1,95 @@
1
+ // The TypeScript scanning helpers of the script motion guards, as source text a guard file carries
2
+ // (a guard imports nothing but types, so a helper is embedded, as `LOCAL_BINDING_SOURCE` is).
3
+ // `TS_BLANK_SOURCE` is the string-aware comment blanker every script guard embeds;
4
+ // `TS_ANIMATE_SCAN_SOURCE` adds the `.animate(` call reader `raw-motion-script` and
5
+ //
6
+ // `animated-layout-script` share.
7
+
8
+ /**
9
+ * Comments blanked IN PLACE (a reported line number still points at the source) by a scan that
10
+ * knows where a string is: `'dist/*'` opens no comment and `'//cdn'` is no line comment.
11
+ * `strings` blanks the string bodies too. A regex literal holding a quote is the one thing it
12
+ * misreads; a quote ends at its line, so the misreading never outlives it.
13
+ */
14
+ export const TS_BLANK_SOURCE = `/** Comments blanked in place; string bodies too when \`strings\` — a string is never a comment. */
15
+ export const blankScript = (text: string, strings = false): string => {
16
+ const pad = (chunk: string): string => chunk.replaceAll(/[^\\n]/g, ' ');
17
+ const parts: string[] = [];
18
+ let kept = 0;
19
+ let i = 0;
20
+ /** Everything since the last cut is code and is copied as one run, never per character. */
21
+ const cut = (from: number, to: number, replacement: string): void => {
22
+ parts.push(text.slice(kept, from), replacement);
23
+ kept = to;
24
+ i = to;
25
+ };
26
+ while (i < text.length) {
27
+ const ch = text[i] ?? '';
28
+ const next = text[i + 1];
29
+ if (ch === '/' && (next === '/' || next === '*')) {
30
+ const close = next === '/' ? text.indexOf('\\n', i) : text.indexOf('*/', i + 2);
31
+ const end = close === -1 ? text.length : next === '/' ? close : close + 2;
32
+ cut(i, end, pad(text.slice(i, end)));
33
+ } else if (ch === "'" || ch === '"' || ch === '\`') {
34
+ let j = i + 1;
35
+ while (j < text.length && text[j] !== ch) {
36
+ if (text[j] === '\\\\') j += 1;
37
+ else if (ch !== '\`' && text[j] === '\\n') break;
38
+ j += 1;
39
+ }
40
+ const end = Math.min(j + 1, text.length);
41
+ if (strings) cut(i, end, pad(text.slice(i, end)));
42
+ else i = end;
43
+ } else i += 1;
44
+ }
45
+ parts.push(text.slice(kept));
46
+ return parts.join('');
47
+ };
48
+ `;
49
+
50
+ export const TS_ANIMATE_SCAN_SOURCE = `${TS_BLANK_SOURCE}
51
+ export interface ScriptFile {
52
+ /** App-root-relative POSIX path, so the finding names the file an author opens. */
53
+ readonly path: string;
54
+ readonly source: string;
55
+ }
56
+
57
+ /** A script an author did not write for the app: a test, a story, a declaration. */
58
+ export const isAppScript = (path: string): boolean =>
59
+ /\\.(?:ts|tsx)$/.test(path) && !/\\.(?:test|spec|d)\\.tsx?$/.test(path);
60
+
61
+ /** Comments blanked, strings kept: a curve is written in one. */
62
+ export const blankScriptComments = (text: string): string => blankScript(text);
63
+
64
+ export const scriptLineOf = (text: string, index: number): number =>
65
+ text.slice(0, index).split('\\n').length;
66
+
67
+ export interface AnimateCall {
68
+ /** Offset of the first argument character in the file. */
69
+ readonly start: number;
70
+ /** The argument text, up to the call's own closing paren; a paren in a string never counts. */
71
+ readonly body: string;
72
+ }
73
+
74
+ /** Every \`.animate(\` call, balanced to its closing paren. */
75
+ export function animateCalls(text: string): readonly AnimateCall[] {
76
+ const calls: AnimateCall[] = [];
77
+ for (const match of text.matchAll(/\\.animate\\s*\\(/g)) {
78
+ const start = match.index + match[0].length;
79
+ let depth = 1;
80
+ let quote = '';
81
+ let i = start;
82
+ for (; i < text.length && depth > 0; i += 1) {
83
+ const ch = text[i] ?? '';
84
+ if (quote !== '') {
85
+ if (ch === '\\\\') i += 1;
86
+ else if (ch === quote) quote = '';
87
+ } else if (ch === "'" || ch === '"' || ch === '\`') quote = ch;
88
+ else if (ch === '(') depth += 1;
89
+ else if (ch === ')') depth -= 1;
90
+ }
91
+ calls.push({ start, body: text.slice(start, i - 1) });
92
+ }
93
+ return calls;
94
+ }
95
+ `;