@buffcore/cli 0.8.45 → 0.8.47

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 (199) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/dist/commands/change-merge-remove.d.ts +9 -2
  3. package/dist/commands/change-merge-remove.js +27 -15
  4. package/dist/commands/design/check.d.ts +1 -1
  5. package/dist/commands/design/check.js +2 -1
  6. package/dist/commands/design/contract-size.d.ts +7 -0
  7. package/dist/commands/design/contract-size.js +47 -0
  8. package/dist/commands/design/tells.en.d.ts +2 -0
  9. package/dist/commands/design/tells.en.js +2 -0
  10. package/dist/commands/design/tells.es.js +2 -0
  11. package/dist/commands/extension/places-approval.d.ts +4 -0
  12. package/dist/commands/process-paths.d.ts +14 -0
  13. package/dist/commands/process-paths.js +90 -0
  14. package/dist/commands/prototype/ai-approval.d.ts +27 -0
  15. package/dist/commands/prototype/ai-approval.js +60 -0
  16. package/dist/commands/prototype/approver.d.ts +71 -0
  17. package/dist/commands/prototype/approver.js +168 -0
  18. package/dist/commands/prototype/browser.d.ts +4 -24
  19. package/dist/commands/prototype/browser.js +13 -76
  20. package/dist/commands/prototype/critique-gate.d.ts +14 -0
  21. package/dist/commands/prototype/critique-gate.js +48 -0
  22. package/dist/commands/prototype/fence.d.ts +1 -0
  23. package/dist/commands/prototype/fence.js +12 -0
  24. package/dist/commands/prototype/final-approval-grant.js +18 -0
  25. package/dist/commands/prototype/final-approval.js +4 -1
  26. package/dist/commands/prototype/index.js +3 -0
  27. package/dist/commands/prototype/layout-hints.d.ts +34 -0
  28. package/dist/commands/prototype/layout-hints.js +194 -0
  29. package/dist/commands/prototype/layout-measure.d.ts +39 -0
  30. package/dist/commands/prototype/layout-measure.js +97 -0
  31. package/dist/commands/prototype/layout-words.d.ts +2 -0
  32. package/dist/commands/prototype/layout-words.js +11 -0
  33. package/dist/commands/prototype/layout.en.d.ts +6 -0
  34. package/dist/commands/prototype/layout.en.js +7 -0
  35. package/dist/commands/prototype/load-location.js +2 -3
  36. package/dist/commands/prototype/loaded-garbage.d.ts +10 -0
  37. package/dist/commands/prototype/loaded-garbage.js +20 -0
  38. package/dist/commands/prototype/media-ready.d.ts +9 -3
  39. package/dist/commands/prototype/media-ready.js +9 -4
  40. package/dist/commands/prototype/messages.en.d.ts +15 -0
  41. package/dist/commands/prototype/messages.en.js +15 -0
  42. package/dist/commands/prototype/messages.js +15 -0
  43. package/dist/commands/prototype/milestone-versions.d.ts +4 -0
  44. package/dist/commands/prototype/prune-command.d.ts +5 -0
  45. package/dist/commands/prototype/prune-command.js +25 -0
  46. package/dist/commands/prototype/prune-words.d.ts +1 -0
  47. package/dist/commands/prototype/prune-words.js +7 -0
  48. package/dist/commands/prototype/prune.d.ts +16 -0
  49. package/dist/commands/prototype/prune.en.d.ts +9 -0
  50. package/dist/commands/prototype/prune.en.js +9 -0
  51. package/dist/commands/prototype/prune.es.d.ts +2 -0
  52. package/dist/commands/prototype/prune.es.js +9 -0
  53. package/dist/commands/prototype/prune.js +140 -0
  54. package/dist/commands/prototype/reopen-messages.d.ts +9 -0
  55. package/dist/commands/prototype/reopen-messages.js +19 -0
  56. package/dist/commands/prototype/report.d.ts +14 -0
  57. package/dist/commands/prototype/report.js +5 -1
  58. package/dist/commands/prototype/scene-check.d.ts +37 -0
  59. package/dist/commands/prototype/scene-check.js +68 -0
  60. package/dist/commands/prototype/scene-layout.d.ts +17 -0
  61. package/dist/commands/prototype/scene-layout.js +57 -0
  62. package/dist/commands/prototype/scene-look.d.ts +14 -0
  63. package/dist/commands/prototype/scene-look.js +89 -0
  64. package/dist/commands/prototype/scene-ready.d.ts +46 -0
  65. package/dist/commands/prototype/scene-ready.js +122 -0
  66. package/dist/commands/prototype/scene.d.ts +37 -3
  67. package/dist/commands/prototype/scene.js +103 -36
  68. package/dist/commands/prototype/selector-answer.d.ts +43 -0
  69. package/dist/commands/prototype/selector-answer.js +73 -0
  70. package/dist/commands/prototype/selector-misses.d.ts +19 -0
  71. package/dist/commands/prototype/selector-misses.js +78 -0
  72. package/dist/commands/prototype/selector-prompt.d.ts +23 -0
  73. package/dist/commands/prototype/selector-prompt.js +32 -0
  74. package/dist/commands/prototype/selector-run.d.ts +13 -0
  75. package/dist/commands/prototype/selector-run.js +113 -0
  76. package/dist/commands/prototype/selector.d.ts +54 -0
  77. package/dist/commands/prototype/selector.js +96 -0
  78. package/dist/commands/prototype/snapshot-ancestor.js +2 -0
  79. package/dist/commands/prototype/snapshot-bundle.d.ts +17 -3
  80. package/dist/commands/prototype/snapshot-bundle.js +69 -7
  81. package/dist/commands/prototype/snapshot-check-files.d.ts +2 -0
  82. package/dist/commands/prototype/snapshot-check-files.js +41 -0
  83. package/dist/commands/prototype/snapshot-command.d.ts +2 -0
  84. package/dist/commands/prototype/snapshot-command.js +23 -10
  85. package/dist/commands/prototype/snapshot-completion.d.ts +4 -0
  86. package/dist/commands/prototype/snapshot-completion.js +30 -2
  87. package/dist/commands/prototype/snapshot-dependencies.d.ts +23 -2
  88. package/dist/commands/prototype/snapshot-dependencies.js +120 -14
  89. package/dist/commands/prototype/snapshot-hashes.d.ts +7 -0
  90. package/dist/commands/prototype/snapshot-hashes.js +28 -0
  91. package/dist/commands/prototype/snapshot-inputs.d.ts +15 -6
  92. package/dist/commands/prototype/snapshot-inputs.js +140 -190
  93. package/dist/commands/prototype/snapshot-matrix.d.ts +58 -0
  94. package/dist/commands/prototype/snapshot-matrix.js +95 -0
  95. package/dist/commands/prototype/snapshot-metro-inputs.d.ts +8 -0
  96. package/dist/commands/prototype/snapshot-metro-inputs.js +81 -0
  97. package/dist/commands/prototype/snapshot-owners.d.ts +6 -2
  98. package/dist/commands/prototype/snapshot-owners.js +12 -3
  99. package/dist/commands/prototype/snapshot-progress-entry.d.ts +14 -0
  100. package/dist/commands/prototype/snapshot-progress-entry.js +85 -0
  101. package/dist/commands/prototype/snapshot-progress.d.ts +19 -2
  102. package/dist/commands/prototype/snapshot-progress.js +54 -102
  103. package/dist/commands/prototype/snapshot-registry.d.ts +14 -0
  104. package/dist/commands/prototype/snapshot-registry.js +121 -0
  105. package/dist/commands/prototype/snapshot-report.d.ts +4 -0
  106. package/dist/commands/prototype/snapshot-report.js +77 -12
  107. package/dist/commands/prototype/snapshot-requests.d.ts +13 -3
  108. package/dist/commands/prototype/snapshot-requests.js +68 -30
  109. package/dist/commands/prototype/snapshot-reuse.d.ts +6 -1
  110. package/dist/commands/prototype/snapshot-reuse.js +17 -7
  111. package/dist/commands/prototype/snapshot-scene-inputs.d.ts +30 -0
  112. package/dist/commands/prototype/snapshot-scene-inputs.js +210 -0
  113. package/dist/commands/prototype/snapshot-served-inputs.d.ts +3 -0
  114. package/dist/commands/prototype/snapshot-served-inputs.js +12 -0
  115. package/dist/commands/prototype/snapshot-server-record.d.ts +26 -0
  116. package/dist/commands/prototype/snapshot-server-record.js +135 -0
  117. package/dist/commands/prototype/snapshot-servers.d.ts +3 -1
  118. package/dist/commands/prototype/snapshot-servers.js +54 -4
  119. package/dist/commands/prototype/snapshot-setup.d.ts +3 -1
  120. package/dist/commands/prototype/snapshot-setup.js +2 -1
  121. package/dist/commands/prototype/snapshot-surface-inputs.d.ts +23 -0
  122. package/dist/commands/prototype/snapshot-surface-inputs.js +161 -0
  123. package/dist/commands/prototype/snapshot-vite-inputs.d.ts +22 -0
  124. package/dist/commands/prototype/snapshot-vite-inputs.js +209 -0
  125. package/dist/commands/prototype/snapshot.d.ts +6 -0
  126. package/dist/commands/prototype/snapshot.js +73 -10
  127. package/dist/commands/prototype/version-commands.d.ts +4 -0
  128. package/dist/commands/prototype/version-commands.js +36 -8
  129. package/dist/commands/prototype/versions.d.ts +28 -2
  130. package/dist/commands/prototype/versions.js +25 -1
  131. package/dist/commands/prototype/vite-fs-path.d.ts +4 -0
  132. package/dist/commands/prototype/vite-fs-path.js +15 -0
  133. package/dist/commands/remove-links.d.ts +6 -0
  134. package/dist/commands/remove-links.js +17 -0
  135. package/dist/commands/size-docs.d.ts +9 -0
  136. package/dist/commands/size-docs.en.d.ts +6 -0
  137. package/dist/commands/size-docs.en.js +6 -0
  138. package/dist/commands/size-docs.es.d.ts +2 -0
  139. package/dist/commands/size-docs.es.js +6 -0
  140. package/dist/commands/size-docs.js +28 -0
  141. package/dist/commands/size.d.ts +5 -2
  142. package/dist/commands/size.js +27 -9
  143. package/dist/commands/ui/approval-authority.d.ts +10 -2
  144. package/dist/commands/ui/approval-authority.js +1 -0
  145. package/dist/commands/ui/autopilot-ai-approve.d.ts +18 -0
  146. package/dist/commands/ui/autopilot-ai-approve.js +68 -0
  147. package/dist/commands/ui/autopilot-loop.js +5 -6
  148. package/dist/commands/ui/autopilot-merge.js +3 -0
  149. package/dist/commands/ui/autopilot.en.d.ts +23 -0
  150. package/dist/commands/ui/autopilot.en.js +23 -0
  151. package/dist/commands/ui/autopilot.es.d.ts +23 -0
  152. package/dist/commands/ui/autopilot.es.js +23 -0
  153. package/dist/commands/ui/chat/find.d.ts +2 -0
  154. package/dist/commands/ui/chat/find.js +13 -0
  155. package/dist/commands/ui/chat/fresh-codex.d.ts +39 -0
  156. package/dist/commands/ui/chat/fresh-codex.js +175 -0
  157. package/dist/commands/ui/chat/fresh-critique.js +13 -5
  158. package/dist/commands/ui/chat/fresh-launch.d.ts +19 -0
  159. package/dist/commands/ui/chat/fresh-launch.js +67 -11
  160. package/dist/commands/ui/chat/fresh-prompts.d.ts +2 -0
  161. package/dist/commands/ui/chat/fresh-prompts.js +2 -0
  162. package/dist/commands/ui/chat/fresh-secrets.d.ts +6 -0
  163. package/dist/commands/ui/chat/fresh-secrets.js +172 -0
  164. package/dist/commands/ui/chat/fresh.en.d.ts +1 -0
  165. package/dist/commands/ui/chat/fresh.en.js +2 -1
  166. package/dist/commands/ui/chat/fresh.es.d.ts +1 -0
  167. package/dist/commands/ui/chat/fresh.es.js +2 -1
  168. package/dist/commands/ui/chat/worktree.js +25 -5
  169. package/dist/commands/ui/index.js +3 -0
  170. package/dist/commands/ui/loop-approve.d.ts +30 -1
  171. package/dist/commands/ui/loop-approve.js +2 -2
  172. package/dist/commands/ui/merge-route.js +3 -0
  173. package/dist/commands/ui/places-change.d.ts +4 -0
  174. package/dist/commands/ui/prototype-main.d.ts +4 -0
  175. package/dist/commands/ui/reopen-route.d.ts +117 -0
  176. package/dist/commands/ui/reopen-route.js +97 -0
  177. package/dist/commands/ui/save-route.d.ts +2 -0
  178. package/dist/commands/ui/save-route.js +4 -0
  179. package/dist/commands/ui/studio-routes.js +2 -0
  180. package/dist/commands/ui/studio-state.d.ts +33 -0
  181. package/dist/commands/ui/studio-versions.d.ts +24 -0
  182. package/dist/commands/ui/worktrees.d.ts +1 -1
  183. package/dist/commands/ui/worktrees.js +19 -3
  184. package/dist/commands/worktree-sweep.d.ts +45 -0
  185. package/dist/commands/worktree-sweep.js +188 -0
  186. package/dist/commands/worktrees-command.d.ts +32 -0
  187. package/dist/commands/worktrees-command.en.d.ts +25 -0
  188. package/dist/commands/worktrees-command.en.js +55 -0
  189. package/dist/commands/worktrees-command.js +96 -0
  190. package/dist/main.js +2 -0
  191. package/dist/ui/page.js +82 -82
  192. package/docs/PROTOTYPE.md +6 -3
  193. package/docs/WORKBENCH.md +11 -6
  194. package/package.json +11 -11
  195. package/skills/ape-critique/SKILL.md +41 -6
  196. package/skills/ape-design-system/SKILL.md +3 -0
  197. package/skills/ape-plan-change/SKILL.md +6 -0
  198. package/skills/ape-prototype/SKILL.md +8 -4
  199. package/templates/product/apps/app/app.json +3 -0
@@ -1,209 +1,171 @@
1
- import { existsSync, readdirSync } from 'node:fs';
2
- import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
3
- import { parseEnv } from 'node:util';
4
- import { SURFACES } from '@buffcore/config';
5
- import { pageOptions } from './browser.js';
6
- import { surfaceDir } from './export.js';
1
+ import { existsSync } from 'node:fs';
2
+ import { dirname, join, resolve } from 'node:path';
3
+ import { SURFACES, sceneUrl } from '@buffcore/config';
7
4
  import { locale } from './messages.js';
8
- import { references } from './milestone-references.js';
9
- import { isStock } from './milestone-stock.js';
10
- import { loaders } from './snapshot-bundle.js';
11
- import { dependencyVersion, snapshotDependencies } from './snapshot-dependencies.js';
5
+ import { dependencyVersion, pathIn, snapshotDependencies } from './snapshot-dependencies.js';
12
6
  import { plainData, sha256 } from './snapshot-hashes.js';
13
- const CHECKS = [
14
- 'browser',
15
- 'checks',
16
- 'fonts',
17
- 'font-samples',
18
- 'full-shot',
19
- 'measure',
20
- 'readable',
21
- 'scene',
22
- 'scene-render',
23
- 'snapshot-requests',
24
- 'snapshot-themes',
25
- ];
26
- const SURFACE_ROOTS = {
27
- admin: ['src/main.tsx', 'src/prototype/index.tsx'],
28
- app: ['src/app/_scene.tsx', 'src/app/_layout.tsx', 'src/prototype/scene.tsx', 'src/fonts.ts'],
29
- };
30
- const SETTINGS = [
31
- 'package.json',
32
- 'tsconfig.json',
33
- 'jsconfig.json',
34
- 'app.json',
35
- 'index.html',
36
- 'public/console.json',
37
- '.env',
38
- '.env.local',
39
- '.env.development',
40
- '.env.development.local',
41
- ];
42
- const existing = (dir, paths) => paths.map((path) => join(dir, path)).filter(existsSync);
43
- const TOOLCHAINS = ['vite.config', 'metro.config', 'babel.config', 'postcss.config', 'app.config']
44
- .flatMap((name) => ['ts', 'js', 'mts', 'mjs', 'cts', 'cjs'].map((ext) => `${name}.${ext}`))
45
- .concat(['.babelrc', '.babelrc.json', '.postcssrc', '.postcssrc.json']);
46
- // The in-repository dev configs use the same resolvers as the product templates.
47
- const BUNDLED_TOOLCHAINS = {
48
- 'apps/admin/vite.config.ts': '0fe0ec6d310d92e37ab052f230ecb6b9ff7a19241061300eebf85920018a6638',
49
- 'apps/app/metro.config.js': 'd2261b4852313fdf42fa63d97d162c691cc89757df4de8ecdff1d8bac939b117',
50
- 'apps/app/babel.config.js': '51ba161016afa8ae07b41bb4305f1c6e71ff30d007e58fbebe0cf383bbce67c0',
51
- };
52
- /** esbuild can model the shipped surface configuration. A product loader may resolve differently. */
53
- async function toolchains(dir, surface, read) {
54
- try {
55
- const files = existing(dir, TOOLCHAINS);
56
- for (const file of files) {
57
- const name = `apps/${surface}/${relative(dir, file)}`;
58
- const text = (await read(file)).toString('utf8').replaceAll('\r\n', '\n');
59
- if (!isStock(name, text) && BUNDLED_TOOLCHAINS[name] !== sha256(text))
60
- return;
61
- }
62
- return files;
63
- }
64
- catch {
65
- return;
66
- }
67
- }
68
- /** A product inside a workspace uses the enclosing lockfile when it has none of its own. */
69
- function lockfile(root) {
70
- for (let dir = root;; dir = dirname(dir)) {
71
- const files = existing(dir, ['pnpm-lock.yaml', 'package-lock.json', 'yarn.lock']);
72
- if (files.length || dirname(dir) === dir)
73
- return files;
74
- }
75
- }
76
- const publicEnvironment = (env) => Object.entries(env)
77
- .filter(([key]) => /^(VITE_|EXPO_PUBLIC_)/.test(key))
78
- .sort();
79
- async function settingHashes(root, files, dependencies) {
80
- return Promise.all(files.map(async (file) => {
81
- const name = relative(root, file);
82
- if (!/^\.env(?:\.|$)/.test(basename(file)))
83
- return [name, await dependencies.digest(file)];
84
- await dependencies.digest(file);
85
- const environment = publicEnvironment(parseEnv((await dependencies.read(file)).toString('utf8')));
86
- if (environment.some(([, value]) => value?.includes('$')))
87
- throw new Error();
88
- return [name, sha256(JSON.stringify(environment))];
89
- }));
90
- }
91
- /** The design system's font files the console serves under `_fonts/`, as its Vite plugin lists them. */
92
- function designFonts(root) {
93
- const dir = join(root, 'design', 'fonts');
94
- try {
95
- return readdirSync(dir, { withFileTypes: true })
96
- .filter((entry) => entry.isFile() && /\.(?:woff2?|ttf|otf)$/i.test(entry.name))
97
- .map((entry) => join(dir, entry.name))
98
- .sort();
99
- }
100
- catch {
101
- return [];
102
- }
103
- }
104
- /** The HTML can load public fonts or images without a JavaScript import. */
105
- async function pageAssets(dir, read) {
106
- const page = join(dir, 'index.html');
107
- if (!existsSync(page))
108
- return [];
109
- const links = references('page', (await read(page)).toString('utf8'), page);
110
- if (typeof links === 'string')
111
- throw new Error();
112
- const publicDir = join(dir, 'public');
113
- return links.flatMap(([kind, url]) => {
114
- if (kind !== 'page' || /^(?:[\w+.-]+:|\/\/|#)/.test(url))
115
- return [];
116
- const file = resolve(publicDir, decodeURIComponent(url.split(/[?#]/, 1)[0] ?? '').replace(/^\//, ''));
117
- const path = relative(publicDir, file);
118
- if (isAbsolute(path) || path === '..' || path.startsWith(`..${sep}`))
119
- return [];
120
- return loaders[extname(file).toLowerCase()] === 'file' && existsSync(file) ? [file] : [];
121
- });
122
- }
123
- async function surfaceEntry(root, surface, dependencies) {
124
- const dir = surfaceDir(root, surface);
125
- const registry = dir && join(dir, 'src', 'prototype', 'views.ts');
126
- if (!dir || !registry || !existsSync(registry))
127
- return;
128
- const configuration = await toolchains(dir, surface, dependencies.read);
129
- if (!configuration)
130
- return;
131
- const page = await pageAssets(dir, dependencies.read).catch(() => undefined);
132
- if (!page)
133
- return;
134
- const assets = [...page, ...(surface === 'admin' ? designFonts(root) : [])];
135
- const entry = {
136
- surface,
137
- dir,
138
- registry,
139
- roots: [...existing(dir, SURFACE_ROOTS[surface]), ...existing(root, ['design/theme.ts'])],
140
- };
141
- const settings = await settingHashes(root, [...existing(dir, SETTINGS), ...configuration, ...assets], dependencies).catch(() => undefined);
142
- if (settings)
143
- return { entry, settings, assets };
144
- }
145
- function hasSurfaceAsset(surface, url) {
146
- if (!surface)
147
- return false;
148
- const path = decodeURIComponent(url.pathname);
149
- const { fonts } = surface;
150
- if (fonts && path.startsWith(fonts.path))
151
- return surface.assets.has(join(fonts.dir, path.slice(fonts.path.length)));
152
- if (path.startsWith('/@fs/'))
153
- return surface.assets.has(resolve(path.slice(5)));
154
- const metroAsset = url.searchParams.get('unstable_path');
155
- if (path === '/assets/' && metroAsset)
156
- return surface.assets.has(resolve(surface.dir, metroAsset));
157
- return (surface.assets.has(resolve(surface.dir, `.${path}`)) ||
158
- surface.assets.has(resolve(surface.dir, 'public', `.${path}`)));
159
- }
7
+ import { metroInputs } from './snapshot-metro-inputs.js';
8
+ import { sceneCandidates, sceneGraph, scenePage } from './snapshot-scene-inputs.js';
9
+ import { matchesBytes } from './snapshot-served-inputs.js';
10
+ import { designFont, lockfile, publicEnvironment, sharedSettings, surfaceEntry, } from './snapshot-surface-inputs.js';
11
+ import { surfaceFile, viteRequests } from './snapshot-vite-inputs.js';
160
12
  /** The console's `_fonts/` under the base its address names (`/`, or `/s/abc/`). */
161
13
  function fontPath(address) {
162
14
  const base = decodeURIComponent(URL.parse(address)?.pathname ?? '/');
163
15
  return `${base.endsWith('/') ? base : `${base}/`}_fonts/`;
164
16
  }
165
- /** The surface loads its whole view registry. Scene definitions still identify individual scenes. */
166
- export async function snapshotInputs(root, scenes, run, browser, design,
167
- /** What the fingerprint reads public values from: the process's, or a linked run's own. */
168
- environment = process.env) {
169
- const dependencies = snapshotDependencies(root, join(root, 'prototype', 'scenes.ts'));
17
+ export async function snapshotInputs(root, scenes, run, browser, design, environment = process.env) {
18
+ let version;
19
+ const browserVersion = async () => (version ??= await browser());
20
+ const read = () => readInputs(root, scenes, run, browserVersion, design, environment);
21
+ const start = await read();
22
+ return {
23
+ ...start,
24
+ async same() {
25
+ // A fresh walk sees added resolution candidates and settings that were absent at the start.
26
+ return (await start.same()) && start.signature() === (await read()).signature();
27
+ },
28
+ };
29
+ }
30
+ async function readInputs(root, scenes, run, browser, design, environment) {
31
+ const catalog = join(root, 'prototype', 'scenes.ts');
32
+ const dependencies = snapshotDependencies(root, catalog);
33
+ const catalogBytes = existsSync(catalog) && (await dependencies.digest(catalog));
170
34
  const inputs = new Map();
171
35
  const fingerprints = new Map();
36
+ const surfaces = new Map();
37
+ const candidates = sceneCandidates(root, scenes, run, dependencies);
38
+ let metro;
39
+ const probes = [];
172
40
  const result = {
173
41
  fingerprints,
174
- same: dependencies.same,
175
- hasAsset: (scene, url) => hasSurfaceAsset(inputs.get(scene.surface), url),
42
+ surfaces,
43
+ reuse: candidates.reuse,
44
+ parts: () => candidates.parts,
45
+ signature: () => JSON.stringify([[...fingerprints], candidates.signature, catalogBytes]),
46
+ same: async () => (await dependencies.same()) &&
47
+ (await metro?.same()) !== false &&
48
+ (await inputs.get('admin')?.vite?.same()) !== false,
49
+ runtime: (force, surface) => {
50
+ const app = metro?.hash();
51
+ if (surface === 'app')
52
+ return app;
53
+ const vite = inputs.get('admin')?.vite?.hash(force);
54
+ if (surface === 'admin')
55
+ return vite;
56
+ return app ? sha256(JSON.stringify([vite, app])) : vite;
57
+ },
58
+ coversRequest: (async (scene, url, kind, response) => {
59
+ const surface = inputs.get(scene.surface);
60
+ const assets = candidates.assets.get(scene.key);
61
+ if (!surface || !assets)
62
+ return false;
63
+ if (scene.surface === 'app' && metro && ['document', 'websocket'].includes(kind))
64
+ return metro.covers(url, kind, response);
65
+ if (kind === 'document') {
66
+ if (url.pathname !== '/_scene')
67
+ return false;
68
+ return (surface.vite?.tracks(url, kind, response) ?? matchesBytes(surface.document, response));
69
+ }
70
+ if (metro && scene.surface === 'app' && url.pathname === '/assets/') {
71
+ const path = url.searchParams.get('unstable_path');
72
+ const file = path && resolve(surface.dir, path);
73
+ if (!file || url.searchParams.size !== 1 || !assets.has(file))
74
+ return false;
75
+ return matchesBytes(await dependencies.digest(file), response);
76
+ }
77
+ const font = surface.fonts && designFont(root, surface.fonts, url, assets);
78
+ if (font)
79
+ return matchesBytes(await dependencies.digest(font), response);
80
+ const file = kind !== 'websocket' && surfaceFile(surface.dir, url, assets);
81
+ if (file) {
82
+ if (surface.vite &&
83
+ ['script', 'stylesheet'].includes(kind) &&
84
+ !pathIn(join(surface.dir, 'public'), file))
85
+ return !!response?.ok();
86
+ return matchesBytes(await dependencies.digest(file), response);
87
+ }
88
+ if (scene.surface === 'app')
89
+ return metro?.covers(url, kind, response) ?? false;
90
+ if (kind === 'script' && !response?.ok())
91
+ return false;
92
+ return surface.vite?.tracks(url, kind, response) ?? false;
93
+ }),
94
+ async prepare(launch) {
95
+ if (!probes.length)
96
+ return;
97
+ await launch?.(probes.map(({ scene }) => scene));
98
+ await Promise.all(probes.map(async ({ scene, read, hash }) => {
99
+ await read();
100
+ if (!hash())
101
+ for (const candidate of scenes)
102
+ if (candidate.surface === scene.surface)
103
+ candidates.reuse.delete(candidate.key);
104
+ }));
105
+ },
176
106
  };
177
107
  for (const surface of new Set(scenes.map((scene) => scene.surface))) {
108
+ if (surface === 'app' && environment.EXPO_METRO_NO_MAIN_FIELD_OVERRIDE)
109
+ continue;
178
110
  const setup = await surfaceEntry(root, surface, dependencies);
179
111
  if (!setup)
180
112
  continue;
181
- const files = await dependencies.walk(setup.entry);
182
- if (files)
113
+ const walked = await dependencies.walk(setup.entry);
114
+ if (walked) {
115
+ const graph = await sceneGraph(root, catalog, setup.entry, walked, dependencies, run.locales, !!setup.vite);
116
+ const first = scenes.find((scene) => scene.surface === surface);
117
+ // An owned server fills its address during launch, after the graph is resolved.
118
+ const page = new URL('http://127.0.0.1');
119
+ const readAfterLaunch = (read) => async () => {
120
+ if (!first)
121
+ return;
122
+ page.href = sceneUrl(run.urls[surface], first.key, {
123
+ theme: run.product,
124
+ mode: 'light',
125
+ locale: run.first,
126
+ });
127
+ return read();
128
+ };
129
+ const vite = setup.vite &&
130
+ graph &&
131
+ viteRequests(setup.entry.dir, setup.vite.runtime, new Set(graph.setup.map(([file]) => resolve(root, file))), new Set(setup.assets), setup.vite.files, page);
183
132
  inputs.set(surface, {
184
133
  dir: setup.entry.dir,
185
- hash: sha256(JSON.stringify([setup.settings, files])),
186
- assets: new Set([...setup.assets, ...files.map(([file]) => resolve(root, file))]),
187
- ...(surface === 'admin' && {
188
- fonts: { path: fontPath(run.urls.admin), dir: join(root, 'design', 'fonts') },
189
- }),
134
+ hash: sha256(JSON.stringify([setup.settings, walked.files])),
135
+ graph,
136
+ vite,
137
+ whole: setup.metro,
138
+ document: setup.document,
139
+ settings: setup.settings,
140
+ pageAssets: setup.assets,
141
+ ...(surface === 'admin' && { fonts: fontPath(run.urls.admin) }),
190
142
  });
143
+ if (first && vite)
144
+ probes.push({ scene: first, read: readAfterLaunch(vite.prepare), hash: vite.proof });
145
+ if (setup.metro && graph && first) {
146
+ metro = metroInputs(setup.entry.dir, dirname(lockfile(root)[0] ?? join(root, 'package.json')), page);
147
+ probes.push({ scene: first, read: readAfterLaunch(metro.prepare), hash: metro.hash });
148
+ }
149
+ }
191
150
  }
192
- if (!inputs.size)
151
+ for (const [surface, { hash }] of inputs)
152
+ surfaces.set(surface, hash);
153
+ if (!scenes.length)
193
154
  return result;
194
155
  const common = await sharedSettings(root, dependencies).catch(() => undefined);
195
156
  if (!common)
196
157
  return result;
197
158
  const shared = sharedFingerprint(run, await browser(), common, design, environment);
159
+ result.shared = shared;
160
+ if (!inputs.size)
161
+ return result;
162
+ await candidates.compare(inputs, shared);
198
163
  for (const scene of scenes) {
199
164
  const surface = inputs.get(scene.surface);
200
165
  if (!surface || typeof scene.view !== 'string' || !plainData(scene))
201
166
  continue;
202
- // Each scene holds its own frame's size, in one key order: a new desktop frame re-shoots
203
- // only the scenes shown in it.
204
- const { width, height } = run.frames[scene.frame];
205
- const page = pageOptions({ width, height });
206
- fingerprints.set(scene.key, sha256(JSON.stringify([shared, surface.hash, scene, page])));
167
+ // Each scene holds its own frame's size: a new desktop frame re-shoots only its scenes.
168
+ fingerprints.set(scene.key, sha256(JSON.stringify([shared, surface.hash, scene, scenePage(run, scene)])));
207
169
  }
208
170
  return result;
209
171
  }
@@ -213,7 +175,7 @@ environment = process.env) {
213
175
  */
214
176
  function sharedFingerprint(run, browser, common, design, environment) {
215
177
  return sha256(JSON.stringify([
216
- 'snapshot-inputs-v4',
178
+ 'snapshot-inputs-v5',
217
179
  dependencyVersion,
218
180
  browser,
219
181
  run.looks,
@@ -229,15 +191,3 @@ function sharedFingerprint(run, browser, common, design, environment) {
229
191
  common,
230
192
  ]));
231
193
  }
232
- async function sharedSettings(root, dependencies) {
233
- const ext = import.meta.url.endsWith('.ts') ? '.ts' : '.js';
234
- const checks = [...CHECKS.map((name) => name + ext), 'drawn-text.js'];
235
- // The root `.env` is not a file input: `loadEnv` puts its values into the environment the
236
- // fingerprint reads, so main (which has one) and a worktree (which has none) agree.
237
- const settings = SETTINGS.filter((name) => !name.startsWith('.env'));
238
- const files = [...existing(root, [...settings, 'buffcore.config.ts']), ...lockfile(root)];
239
- return Promise.all([
240
- Promise.all(checks.map((file) => dependencies.digest(resolve(import.meta.dirname, file)))),
241
- settingHashes(root, files, dependencies),
242
- ]);
243
- }
@@ -0,0 +1,58 @@
1
+ import type { Theme } from '@buffcore/tokens';
2
+ import type { SnapshotReport } from './report.ts';
3
+ /**
4
+ * `floor`: the product's theme (the first starter when it names none), light and dark, its languages
5
+ * and `en-XA` (`ar-XB` too with a right-to-left language). `full`: every theme, mode and pseudo-locale.
6
+ */
7
+ export type Matrix = 'floor' | 'full';
8
+ /** Why: the default, the `--full` switch, or a shared input changed since the last full report. */
9
+ export type MatrixReason = 'floor' | 'switch' | 'shared';
10
+ export interface MatrixRun {
11
+ looks: readonly Theme[];
12
+ product: string;
13
+ locales: readonly string[];
14
+ /** Unset: the full matrix (a caller that names none keeps what every run drew before). */
15
+ matrix?: Matrix | undefined;
16
+ /** The selector's added looks (S3c), by scene: drawn on top of the floor, never in its place. */
17
+ extraLooks?: ReadonlyMap<string, ReadonlySet<string>> | undefined;
18
+ }
19
+ /** The product's languages and `en-XA`, and `ar-XB` when one of them is written right to left. */
20
+ export declare function floorLocales(locales: readonly string[]): string[];
21
+ type Look = {
22
+ theme: Theme;
23
+ mode: string;
24
+ locale: string;
25
+ };
26
+ /** A look's name, `<theme>.<mode>.<locale>`, as the selector and the report name it. */
27
+ export declare const lookName: ({ theme, mode, locale }: Look) => string;
28
+ /**
29
+ * The looks a scene is drawn and checked in, in order: theme, then mode, then language. In the
30
+ * floor, a scene the selector added looks for draws those too, in the full matrix's order.
31
+ */
32
+ export declare function drawnLooks(run: MatrixRun, scene?: string): Look[];
33
+ /** Whether a scene drawn in `had` covers a run that draws `wants` (an older report's scene: full). */
34
+ export declare const covers: (had: Matrix | undefined, wants: Matrix | undefined) => boolean;
35
+ /**
36
+ * The matrix a run draws: full with the switch; full when the shared inputs differ from those of the
37
+ * last full report (the nearest ancestor's `fullInputs`), or are unknown; else the floor.
38
+ */
39
+ export declare function chooseMatrix(full: boolean | undefined, current: string | undefined, ancestor: Pick<SnapshotReport, 'fullInputs'> | undefined): {
40
+ matrix: Matrix;
41
+ reason: MatrixReason;
42
+ };
43
+ /** The run's matrix and what its report records, from the switch and the nearest ancestor report. */
44
+ export declare function runMatrix(full: boolean | undefined, parts: string | undefined, root?: string, commit?: string): {
45
+ matrix: Matrix;
46
+ matrixReason: MatrixReason;
47
+ fullInputs: string | undefined;
48
+ };
49
+ /**
50
+ * What `ape prototype version` accepts, judged scene by scene on what was drawn: each scene's matrix
51
+ * is the floor or the full one, covers the report's (`covers`, as reuse: a full report holds no floor
52
+ * scene, reused or not), and its pictures are exactly that matrix's: the product's theme light and
53
+ * dark (the floor), or every theme light and the product's dark (full). The report's languages hold
54
+ * the floor's (`en-XA`, and `ar-XB` with a right-to-left language). A report written before S3b names
55
+ * no matrix and holds no floor scene: it is judged as before.
56
+ */
57
+ export declare function meetsFloor(report: Pick<SnapshotReport, 'matrix' | 'scenes' | 'themes' | 'locales'>): boolean;
58
+ export {};
@@ -0,0 +1,95 @@
1
+ // Which looks a snapshot draws (F113b, F113c): the floor by default, the full matrix with `--full`
2
+ // or when an input every scene shares changed since the last full report.
3
+ import { isRtl, PSEUDO_LOCALES } from '@buffcore/i18n';
4
+ import { findAncestor } from './snapshot-ancestor.js';
5
+ import { lookKey, photographed } from './snapshot-themes.js';
6
+ const FLOOR_MODES = ['light', 'dark'];
7
+ /** The product's languages and `en-XA`, and `ar-XB` when one of them is written right to left. */
8
+ export function floorLocales(locales) {
9
+ const own = locales.filter((locale) => !PSEUDO_LOCALES.some((pseudo) => pseudo === locale));
10
+ return [...own, 'en-XA', ...(own.some(isRtl) ? ['ar-XB'] : [])];
11
+ }
12
+ /** A look's name, `<theme>.<mode>.<locale>`, as the selector and the report name it. */
13
+ export const lookName = ({ theme, mode, locale }) => `${theme.key}.${mode}.${locale}`;
14
+ /**
15
+ * The looks a scene is drawn and checked in, in order: theme, then mode, then language. In the
16
+ * floor, a scene the selector added looks for draws those too, in the full matrix's order.
17
+ */
18
+ export function drawnLooks(run, scene) {
19
+ const extra = scene === undefined ? undefined : run.extraLooks?.get(scene);
20
+ if (run.matrix === 'floor' && extra?.size) {
21
+ const floor = new Set(drawnLooks({ ...run, extraLooks: undefined }).map(lookName));
22
+ return drawnLooks({ ...run, matrix: 'full' }).filter((look) => floor.has(lookName(look)) || extra.has(lookName(look)));
23
+ }
24
+ const floor = run.matrix === 'floor';
25
+ const own = run.looks.find((theme) => theme.key === run.product) ?? run.looks[0];
26
+ const themes = floor ? (own ? [own] : []) : run.looks;
27
+ const locales = floor ? floorLocales(run.locales) : run.locales;
28
+ return themes.flatMap((theme) => Object.keys(theme.color)
29
+ .filter((mode) => !floor || FLOOR_MODES.includes(mode))
30
+ .flatMap((mode) => locales.map((locale) => ({ theme, mode, locale }))));
31
+ }
32
+ /** Whether a scene drawn in `had` covers a run that draws `wants` (an older report's scene: full). */
33
+ export const covers = (had, wants) => (had ?? 'full') === 'full' || wants === 'floor';
34
+ /**
35
+ * The matrix a run draws: full with the switch; full when the shared inputs differ from those of the
36
+ * last full report (the nearest ancestor's `fullInputs`), or are unknown; else the floor.
37
+ */
38
+ export function chooseMatrix(full, current, ancestor) {
39
+ if (full)
40
+ return { matrix: 'full', reason: 'switch' };
41
+ if (current === undefined || ancestor?.fullInputs !== current)
42
+ return { matrix: 'full', reason: 'shared' };
43
+ return { matrix: 'floor', reason: 'floor' };
44
+ }
45
+ /** The run's matrix and what its report records, from the switch and the nearest ancestor report. */
46
+ export function runMatrix(full, parts, root, commit) {
47
+ const ancestor = full || !root || !commit ? undefined : findAncestor(root, commit)?.report;
48
+ const { matrix, reason } = chooseMatrix(full, parts, ancestor);
49
+ return {
50
+ matrix,
51
+ matrixReason: reason,
52
+ fullInputs: matrix === 'full' ? parts : ancestor?.fullInputs,
53
+ };
54
+ }
55
+ const MATRICES = [undefined, 'floor', 'full'];
56
+ /**
57
+ * What `ape prototype version` accepts, judged scene by scene on what was drawn: each scene's matrix
58
+ * is the floor or the full one, covers the report's (`covers`, as reuse: a full report holds no floor
59
+ * scene, reused or not), and its pictures are exactly that matrix's: the product's theme light and
60
+ * dark (the floor), or every theme light and the product's dark (full). The report's languages hold
61
+ * the floor's (`en-XA`, and `ar-XB` with a right-to-left language). A report written before S3b names
62
+ * no matrix and holds no floor scene: it is judged as before.
63
+ */
64
+ export function meetsFloor(report) {
65
+ if (!MATRICES.includes(report.matrix))
66
+ return false;
67
+ // An older ape's report names no matrix: it drew every scene in the full one, as it always did.
68
+ if (report.matrix === undefined)
69
+ return report.scenes.every((scene) => scene.matrix === undefined);
70
+ const locales = report.locales ?? [];
71
+ if (!floorLocales(locales).every((locale) => locales.includes(locale)))
72
+ return false;
73
+ const darks = report.scenes.flatMap((scene) => Object.keys(scene.screenshots).filter((look) => look.endsWith('.dark')));
74
+ const dark = darks[0];
75
+ const product = dark?.slice(0, -'.dark'.length);
76
+ if (!dark || !product || !report.themes?.includes(product))
77
+ return false;
78
+ return report.scenes.every((scene) => {
79
+ if (!MATRICES.includes(scene.matrix) || !covers(scene.matrix, report.matrix))
80
+ return false;
81
+ const want = [...(scene.matrix === 'floor' ? [product] : report.themes), dark].sort();
82
+ // A floor scene's selector picks (S3c) may add their own photos: the picked looks' keys, no other.
83
+ const extra = new Set(scene.matrix === 'floor'
84
+ ? (scene.extraLooks ?? []).flatMap((look) => {
85
+ const [theme = '', mode = ''] = look.split('.');
86
+ return report.themes?.includes(theme) && photographed(theme, mode, product)
87
+ ? [lookKey(theme, mode)]
88
+ : [];
89
+ })
90
+ : []);
91
+ const drawn = Object.keys(scene.screenshots).sort();
92
+ const own = drawn.filter((key) => !(extra.has(key) && !want.includes(key)));
93
+ return JSON.stringify(own) === JSON.stringify(want);
94
+ });
95
+ }
@@ -0,0 +1,8 @@
1
+ import type { Response } from 'playwright-core';
2
+ /** An Expo bundle contains all its views. Bind the actual entry and document bytes as app inputs. */
3
+ export declare function metroInputs(dir: string, workspace: string, page: URL): {
4
+ prepare(): Promise<void>;
5
+ hash: () => string | undefined;
6
+ same(): Promise<boolean>;
7
+ covers(url: URL, kind: string, response?: Response): Promise<boolean>;
8
+ };
@@ -0,0 +1,81 @@
1
+ import { resolve } from 'node:path';
2
+ import { sha256 } from './snapshot-hashes.js';
3
+ import { matchesBytes, servedBytes } from './snapshot-served-inputs.js';
4
+ const webQuery = new URLSearchParams({
5
+ platform: 'web',
6
+ dev: 'true',
7
+ hot: 'false',
8
+ lazy: 'true',
9
+ 'transform.engine': 'hermes',
10
+ 'transform.routerRoot': 'src/app',
11
+ unstable_transformProfile: 'hermes-stable',
12
+ });
13
+ function bundleUrl(html, page, dir, workspace) {
14
+ const scripts = [...html.matchAll(/<script\b([^>]*)>/gi)];
15
+ const [script] = scripts;
16
+ if (scripts.length !== 1 || !script)
17
+ return;
18
+ const path = /^ src="(\/[^"\s]+)" defer$/.exec(script[1] ?? '')?.[1];
19
+ if (!path)
20
+ return;
21
+ const bundle = new URL(path, page);
22
+ if (bundle.origin !== page.origin || bundle.hash || !bundle.pathname.endsWith('.bundle'))
23
+ return;
24
+ const entry = decodeURIComponent(bundle.pathname.slice(0, -'.bundle'.length));
25
+ if (![dir, workspace].some((root) => resolve(root, `.${entry}`) === resolve(dir, 'index.ts')))
26
+ return;
27
+ if (bundle.searchParams.size !== webQuery.size)
28
+ return;
29
+ if ([...webQuery].some(([key, value]) => bundle.searchParams.get(key) !== value))
30
+ return;
31
+ return bundle;
32
+ }
33
+ /**
34
+ * The served text with every loopback address's port taken out: a run's ports are its own (a
35
+ * worktree's are new every time), and Metro writes them into the bundle (its links, and public
36
+ * values such as the API's address).
37
+ */
38
+ const portless = (bytes) => bytes.toString('utf8').replace(/(127\.0\.0\.1|localhost|\[::1\]):\d+/g, '$1:port');
39
+ /** An Expo bundle contains all its views. Bind the actual entry and document bytes as app inputs. */
40
+ export function metroInputs(dir, workspace, page) {
41
+ async function read() {
42
+ const html = await servedBytes(page, 'html');
43
+ if (!html)
44
+ return;
45
+ const bundle = bundleUrl(html.toString('utf8'), page, dir, workspace);
46
+ if (!bundle)
47
+ return;
48
+ const js = await servedBytes(bundle, 'javascript');
49
+ if (!js)
50
+ return;
51
+ return {
52
+ path: bundle.pathname + bundle.search,
53
+ html: sha256(html),
54
+ js: sha256(js),
55
+ code: sha256(JSON.stringify([portless(html), portless(js)])),
56
+ };
57
+ }
58
+ let prepared;
59
+ const safeRead = () => read().catch(() => undefined);
60
+ return {
61
+ async prepare() {
62
+ prepared = await safeRead();
63
+ },
64
+ hash: () => prepared && sha256(JSON.stringify([prepared.path, prepared.code])),
65
+ async same() {
66
+ return !prepared || JSON.stringify(prepared) === JSON.stringify(await safeRead());
67
+ },
68
+ async covers(url, kind, response) {
69
+ if (!prepared)
70
+ return false;
71
+ if (kind === 'websocket')
72
+ return !url.search && ['/hot', '/message'].includes(url.pathname);
73
+ const hash = kind === 'document' && url.pathname === '/_scene'
74
+ ? prepared.html
75
+ : kind === 'script' && url.pathname + url.search === prepared.path
76
+ ? prepared.js
77
+ : undefined;
78
+ return matchesBytes(hash, response);
79
+ },
80
+ };
81
+ }
@@ -13,8 +13,12 @@ export interface Owners {
13
13
  export declare function parseNetstat(text: string, port: number): number[];
14
14
  /** `lsof -Fp` lines: `p4242`. */
15
15
  export declare function parseLsof(text: string): number[];
16
- /** `pid ppid` pairs, one per line, from either platform's process table. */
17
- export declare function descendants(table: string, root: number): Set<number>;
16
+ /**
17
+ * `pid ppid` pairs, one per line, from either platform's process table. With `starts` (each
18
+ * process's start, in milliseconds), a child counts only when it started at or after its parent:
19
+ * Windows keeps a dead parent's id on its children, and that id can be given to a later process.
20
+ */
21
+ export declare function descendants(table: string, root: number, starts?: ReadonlyMap<number, number>): Set<number>;
18
22
  export declare const systemOwners: Owners;
19
23
  /** Who has the port: `ours`, `foreign` (a listener outside the tree, or none), or `failed` (no answer). */
20
24
  export declare function portOwner(port: number, pid: number, owners?: Owners): Promise<'ours' | 'foreign' | 'failed'>;