@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
@@ -2,8 +2,10 @@ import { readFileSync } from 'node:fs';
2
2
  import { copyFile, readdir, readFile } from 'node:fs/promises';
3
3
  import { basename, join } from 'node:path';
4
4
  import { t } from './messages.js';
5
+ import { SnapshotCheckoutChanged } from './snapshot-checkout.js';
5
6
  import { SnapshotRefused } from './snapshot-env.js';
6
7
  import { sha256 } from './snapshot-hashes.js';
8
+ import { requireReusedScenes } from './snapshot-reuse.js';
7
9
  import { boundShots, hashShots } from './snapshot-shots.js';
8
10
  import { lookKey, photographed } from './snapshot-themes.js';
9
11
  export async function previousSnapshot(folder) {
@@ -30,7 +32,21 @@ export async function previousSnapshot(folder) {
30
32
  export function inputsFingerprint(inputs, scenes, api, data) {
31
33
  if (!scenes.length || !inputs || scenes.some((scene) => !inputs.fingerprints.has(scene.key)))
32
34
  return;
33
- return sha256(JSON.stringify([api, data, [...inputs.fingerprints]]));
35
+ const runtime = inputs.runtime();
36
+ return sha256(JSON.stringify([api, data, [...inputs.fingerprints], ...(runtime ? [runtime] : [])]));
37
+ }
38
+ export function runtimeHash(inputs, run) {
39
+ try {
40
+ return inputs?.runtime(true);
41
+ }
42
+ catch {
43
+ throw new SnapshotCheckoutChanged(run.commit, run.commit);
44
+ }
45
+ }
46
+ export function reuseFingerprint(inputs, { key, surface }) {
47
+ const hash = inputs?.reuse.get(key);
48
+ const runtime = inputs?.runtime(false, surface);
49
+ return hash && runtime ? sha256(JSON.stringify([hash, runtime])) : hash;
34
50
  }
35
51
  export function keptScenes(report, selected) {
36
52
  if (!report)
@@ -82,6 +98,16 @@ export async function partialReason(old, run, picked, all, report, inputs) {
82
98
  const looks = run.looks.flatMap((theme) => Object.keys(theme.color)
83
99
  .filter((mode) => photographed(theme.key, mode, run.product))
84
100
  .map((mode) => lookKey(theme.key, mode)));
101
+ if (old.reuseReport !== undefined || old.scenes.some((scene) => scene.reusedFrom)) {
102
+ try {
103
+ if (!run.root)
104
+ return 'prototype.partialEvidence';
105
+ requireReusedScenes(run.root, old, false);
106
+ }
107
+ catch {
108
+ return 'prototype.partialEvidence';
109
+ }
110
+ }
85
111
  for (const scene of old.scenes) {
86
112
  if (picked.has(scene.key))
87
113
  continue;
@@ -89,7 +115,9 @@ export async function partialReason(old, run, picked, all, report, inputs) {
89
115
  if (!shots ||
90
116
  shots.length !== looks.length ||
91
117
  scene.apiCalls !== false ||
92
- scene.fingerprint !== inputs?.fingerprints.get(scene.key))
118
+ !scene.fingerprint ||
119
+ (scene.fingerprint !== inputs?.fingerprints.get(scene.key) &&
120
+ scene.fingerprint !== reuseFingerprint(inputs, scene)))
93
121
  return 'prototype.partialEvidence';
94
122
  const hashes = await hashShots(run.out, run.commit, scene);
95
123
  if (!hashes ||
@@ -1,9 +1,30 @@
1
+ import { type Metafile } from 'esbuild';
1
2
  import { type SurfaceEntry } from './snapshot-bundle.ts';
2
3
  export declare const dependencyVersion: string;
3
- /** Hash the same bytes esbuild reads, sharing file reads across surfaces. */
4
+ export declare const slash: (path: string) => string;
5
+ export declare function pathIn(root: string, file: string): boolean;
6
+ declare function cachedFiles(): {
7
+ read: (file: string) => Promise<Buffer<ArrayBufferLike>>;
8
+ digest: (file: string) => Promise<string>;
9
+ same: () => Promise<boolean>;
10
+ has: (file: string) => boolean;
11
+ };
12
+ /** The resolver reads manifests and config even though they need not be bundle inputs. */
13
+ export declare function resolutionSettings(root: string, files: readonly string[], deps: ReturnType<typeof snapshotDependencies>): Promise<string[][]>;
14
+ /** Include competing paths if the stock bundlers may prioritize them differently. */
15
+ export declare function resolutionAlternatives(importer: string, spec: string | undefined, target: string): string[];
16
+ /** esbuild's input graph can list external TS type imports even though no JS loads them. */
17
+ export declare function runtimeExternal(path: string, specifiers: readonly string[], read: ReturnType<typeof cachedFiles>['read']): Promise<boolean>;
4
18
  export declare function snapshotDependencies(root: string, catalog: string): {
5
19
  read: (file: string) => Promise<Buffer<ArrayBufferLike>>;
6
20
  digest: (file: string) => Promise<string>;
7
21
  same: () => Promise<boolean>;
8
- walk: (entry: SurfaceEntry) => Promise<(readonly [string, string])[] | undefined>;
22
+ walk: (entry: SurfaceEntry) => Promise<{
23
+ files: (readonly [string, string])[];
24
+ meta: Metafile;
25
+ selected: Set<string>;
26
+ unproven: Set<string>;
27
+ } | undefined>;
28
+ assets: (path: string) => never[] | Promise<string[] | undefined>;
9
29
  };
30
+ export {};
@@ -1,13 +1,19 @@
1
- import { readFile } from 'node:fs/promises';
1
+ import { existsSync, statSync } from 'node:fs';
2
+ import { lstat, readFile } from 'node:fs/promises';
2
3
  import { createRequire } from 'node:module';
3
- import { dirname, extname, join, relative, resolve } from 'node:path';
4
- import { version } from 'esbuild';
4
+ import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
5
+ import { transform, version } from 'esbuild';
6
+ import { withoutComments } from './milestone-manifests.js';
5
7
  import { codeReferences } from './milestone-references.js';
6
8
  import { bundleSurface, catalogInput, loaders, virtualInput, } from './snapshot-bundle.js';
7
9
  import { sha256 } from './snapshot-hashes.js';
8
10
  export const dependencyVersion = version;
9
11
  const CODE_LOADERS = new Set(['ts', 'tsx', 'js', 'jsx']);
10
- const slash = (path) => path.replaceAll('\\', '/');
12
+ export const slash = (path) => path.replaceAll('\\', '/');
13
+ export function pathIn(root, file) {
14
+ const name = relative(root, file);
15
+ return !isAbsolute(name) && name !== '..' && !name.startsWith(`..${sep}`);
16
+ }
11
17
  const assetLiteral = (url) => url.startsWith('data:') || url.startsWith('#');
12
18
  // This loader mounts host-supplied Studio parts outside the scene. The module still contributes
13
19
  // its bytes and ordinary imports. All other unresolved warnings fail the walk.
@@ -24,7 +30,6 @@ function hostPartLoader(dir) {
24
30
  }
25
31
  function selectedInputs(meta) {
26
32
  const outputs = Object.entries(meta.outputs);
27
- // The output imports omit external edges that were only used as TS types.
28
33
  if (outputs.some(([, output]) => output.imports.some(({ path, external, kind }) => external && !(kind === 'url-token' && assetLiteral(path)))))
29
34
  return;
30
35
  const selected = new Set(outputs
@@ -32,7 +37,6 @@ function selectedInputs(meta) {
32
37
  .flatMap(([, output]) => Object.entries(output.inputs)
33
38
  .filter(([, input]) => input.bytesInOutput > 0)
34
39
  .map(([file]) => file)));
35
- // An unused JS import can emit an asset, while a used stylesheet can have a zero-byte URL edge.
36
40
  for (const file of selected)
37
41
  for (const edge of meta.inputs[file]?.imports ?? [])
38
42
  if (edge.kind === 'url-token' && !edge.external)
@@ -47,17 +51,35 @@ function unresolved(root, warning, selected, ignored) {
47
51
  return false;
48
52
  return warning.id !== 'unsupported-dynamic-import' || resolve(root, file) !== ignored;
49
53
  }
54
+ async function fileState(path) {
55
+ try {
56
+ return { bytes: await readFile(path) };
57
+ }
58
+ catch (error) {
59
+ const code = error.code;
60
+ if (!code || !['EBUSY', 'EPERM', 'EACCES'].includes(code))
61
+ throw error;
62
+ const file = await lstat(path);
63
+ if (!file.isFile())
64
+ throw error;
65
+ const lock = JSON.stringify([code, file.ino, file.size, file.mtimeMs, file.ctimeMs]);
66
+ return { error, lock };
67
+ }
68
+ }
50
69
  function cachedFiles() {
51
70
  const files = new Map();
52
71
  const digests = new Map();
53
- function read(file) {
72
+ async function read(file) {
54
73
  const key = resolve(file);
55
74
  let contents = files.get(key);
56
75
  if (!contents) {
57
- contents = readFile(key);
76
+ contents = fileState(key);
58
77
  files.set(key, contents);
59
78
  }
60
- return contents;
79
+ const state = await contents;
80
+ if ('bytes' in state)
81
+ return state.bytes;
82
+ throw state.error;
61
83
  }
62
84
  async function digest(file) {
63
85
  const key = resolve(file);
@@ -66,10 +88,86 @@ function cachedFiles() {
66
88
  return hash;
67
89
  }
68
90
  async function same() {
69
- return (await Promise.all([...digests].map(async ([file, hash]) => readFile(file).then((bytes) => sha256(bytes) === hash, () => false)))).every(Boolean);
91
+ const matches = await Promise.all([...files].map(async ([file, original]) => {
92
+ try {
93
+ const start = await original;
94
+ const end = await fileState(file);
95
+ if ('bytes' in start && 'bytes' in end)
96
+ return start.bytes.equals(end.bytes);
97
+ return 'lock' in start && 'lock' in end && start.lock === end.lock;
98
+ }
99
+ catch {
100
+ return false;
101
+ }
102
+ }));
103
+ return matches.every(Boolean);
70
104
  }
71
105
  return { read, digest, same, has: (file) => files.has(file) };
72
106
  }
107
+ /** The resolver reads manifests and config even though they need not be bundle inputs. */
108
+ export async function resolutionSettings(root, files, deps) {
109
+ const checked = new Set();
110
+ const manifests = new Set();
111
+ for (const file of files) {
112
+ for (let dir = dirname(file); pathIn(root, dir) && !checked.has(dir); dir = dirname(dir)) {
113
+ checked.add(dir);
114
+ for (const name of ['package.json', 'tsconfig.json', 'jsconfig.json']) {
115
+ const path = join(dir, name);
116
+ if (existsSync(path))
117
+ manifests.add(path);
118
+ }
119
+ if (dir === root)
120
+ break;
121
+ }
122
+ }
123
+ const resolveConfig = createRequire(join(root, 'package.json'));
124
+ for (const file of manifests) {
125
+ if (file.endsWith('package.json'))
126
+ continue;
127
+ const config = JSON.parse(withoutComments((await deps.read(file)).toString('utf8')));
128
+ const extendsList = [config.extends ?? []].flat();
129
+ for (const name of extendsList) {
130
+ if (typeof name !== 'string')
131
+ throw new Error();
132
+ const extension = name.startsWith('.')
133
+ ? [resolve(dirname(file), name), resolve(dirname(file), `${name}.json`)].find((path) => statSync(path, { throwIfNoEntry: false })?.isFile())
134
+ : resolveConfig.resolve(name, { paths: [dirname(file)] });
135
+ if (!extension)
136
+ throw new Error();
137
+ if (manifests.size >= 2000)
138
+ throw new Error();
139
+ manifests.add(extension);
140
+ }
141
+ }
142
+ return Promise.all([...manifests]
143
+ .sort()
144
+ .map(async (file) => [slash(relative(root, file)), await deps.digest(file)]));
145
+ }
146
+ const EXTENSIONS = ['mjs', 'js', 'mts', 'ts', 'jsx', 'tsx', 'cjs', 'cts', 'json', 'css'];
147
+ /** Include competing paths if the stock bundlers may prioritize them differently. */
148
+ export function resolutionAlternatives(importer, spec, target) {
149
+ const ext = extname(target).slice(1);
150
+ if (!EXTENSIONS.includes(ext))
151
+ return [];
152
+ const address = spec?.startsWith('.') ? resolve(dirname(importer), spec) : undefined;
153
+ if (address === target)
154
+ return [];
155
+ const base = address ?? target.slice(0, -ext.length - 1);
156
+ const stem = base.replace(/\.(?:web|native)$/, '');
157
+ return [stem, join(stem, 'index')]
158
+ .flatMap((path) => EXTENSIONS.flatMap((extension) => ['', '.web', '.native'].map((platform) => `${path + platform}.${extension}`)))
159
+ .concat(join(stem, 'package.json'))
160
+ .filter((path) => path !== target && statSync(path, { throwIfNoEntry: false })?.isFile());
161
+ }
162
+ /** esbuild's input graph can list external TS type imports even though no JS loads them. */
163
+ export async function runtimeExternal(path, specifiers, read) {
164
+ const loader = loaders[extname(path).toLowerCase()];
165
+ if (loader !== 'ts' && loader !== 'tsx')
166
+ return true;
167
+ const source = (await read(path)).toString('utf8');
168
+ const { code } = await transform(source, { loader, jsx: 'automatic' });
169
+ return specifiers.some((name) => !/^[\w@/.\-:#]+$/.test(name) || code.includes(JSON.stringify(name)));
170
+ }
73
171
  function collectDependencies(root, catalog, files) {
74
172
  const assets = new Map();
75
173
  function assetPaths(path) {
@@ -85,7 +183,7 @@ function collectDependencies(root, catalog, files) {
85
183
  }
86
184
  return cached;
87
185
  }
88
- return async (entry, selected, unproven) => {
186
+ const broad = async (entry, selected, unproven) => {
89
187
  // The registry and roots count even when their output has zero bytes.
90
188
  const dependencies = new Set([entry.registry, ...entry.roots]);
91
189
  if (files.has(catalog))
@@ -107,8 +205,8 @@ function collectDependencies(root, catalog, files) {
107
205
  .sort()
108
206
  .map(async (file) => [slash(relative(root, file)), await files.digest(file)]));
109
207
  };
208
+ return { broad, assetPaths };
110
209
  }
111
- /** Hash the same bytes esbuild reads, sharing file reads across surfaces. */
112
210
  export function snapshotDependencies(root, catalog) {
113
211
  const files = cachedFiles();
114
212
  const collect = collectDependencies(root, catalog, files);
@@ -121,14 +219,22 @@ export function snapshotDependencies(root, catalog) {
121
219
  if (!selected ||
122
220
  result.warnings.some((warning) => unresolved(root, warning, selected, ignored)))
123
221
  return;
124
- return await collect(entry, selected, unproven);
222
+ const hashes = await collect.broad(entry, selected, unproven);
223
+ if (hashes && result.metafile)
224
+ return { files: hashes, meta: result.metafile, selected, unproven };
125
225
  }
126
226
  catch {
127
227
  // esbuild could not establish this surface's inputs. Draw its scenes.
128
228
  return;
129
229
  }
130
230
  }
131
- return { read: files.read, digest: files.digest, same: files.same, walk };
231
+ return {
232
+ read: files.read,
233
+ digest: files.digest,
234
+ same: files.same,
235
+ walk,
236
+ assets: collect.assetPaths,
237
+ };
132
238
  }
133
239
  /** esbuild does not expand bundler-specific loaders or read files named by new URL(). */
134
240
  function runtimeAssets(source, loader) {
@@ -2,3 +2,10 @@ export declare const sha256: (value: string | Buffer) => string;
2
2
  export declare const sha256Pattern: RegExp;
3
3
  /** Only values that survive a JSON round trip can identify results from an earlier run. */
4
4
  export declare function plainData(value: unknown, ancestors?: Set<object>): boolean;
5
+ /**
6
+ * A scene as data for the progress journal: each function in it stands for its source text, which
7
+ * the journal's pinned source tree already holds (a handler such as `onPress` is never called while
8
+ * a picture is drawn). Anything else that is not plain (a class instance, an accessor, a cycle) is
9
+ * left as it is, so `plainData` still refuses it; so is a bound or built-in function.
10
+ */
11
+ export declare function sceneData(value: unknown, ancestors?: Set<object>): unknown;
@@ -25,3 +25,31 @@ export function plainData(value, ancestors = new Set()) {
25
25
  ancestors.delete(value);
26
26
  return plain;
27
27
  }
28
+ /**
29
+ * A scene as data for the progress journal: each function in it stands for its source text, which
30
+ * the journal's pinned source tree already holds (a handler such as `onPress` is never called while
31
+ * a picture is drawn). Anything else that is not plain (a class instance, an accessor, a cycle) is
32
+ * left as it is, so `plainData` still refuses it; so is a bound or built-in function.
33
+ */
34
+ export function sceneData(value, ancestors = new Set()) {
35
+ if (typeof value === 'function') {
36
+ const source = String(value);
37
+ // A bound or built-in function has no source to tell two apart.
38
+ return source.includes('[native code]') ? value : { function: source };
39
+ }
40
+ if (typeof value !== 'object' || value === null || ancestors.has(value))
41
+ return value;
42
+ const array = Array.isArray(value);
43
+ if (Object.getPrototypeOf(value) !== (array ? Array.prototype : Object.prototype))
44
+ return value;
45
+ const fields = Object.getOwnPropertyDescriptors(value);
46
+ const keys = Reflect.ownKeys(fields).filter((key) => !array || key !== 'length');
47
+ if (keys.some((key) => typeof key !== 'string' || !fields[key]?.enumerable || !('value' in fields[key])))
48
+ return value;
49
+ ancestors.add(value);
50
+ const copy = array
51
+ ? value.map((item) => sceneData(item, ancestors))
52
+ : Object.fromEntries(keys.map((key) => [key, sceneData(fields[key]?.value, ancestors)]));
53
+ ancestors.delete(value);
54
+ return copy;
55
+ }
@@ -1,11 +1,20 @@
1
- import type { Scene } from '@buffcore/config';
1
+ import type { Scene, Surface } from '@buffcore/config';
2
2
  import type { Run } from './scene.ts';
3
+ import type { RequestCoverage } from './snapshot-requests.ts';
3
4
  export interface SnapshotInputs {
5
+ /** Broad binding for completing or resuming the same run. */
4
6
  fingerprints: ReadonlyMap<string, string>;
7
+ /** Each scene's own fingerprint: the files its view imports and the shared parts (F113d). */
8
+ reuse: ReadonlyMap<string, string>;
9
+ /** What every scene's picture depends on beyond its own surface (public values, settings, tools). */
10
+ shared?: string;
11
+ /** The inputs every scene shares (F113c), once compared: a change draws the full matrix. */
12
+ parts?(): string | undefined;
13
+ /** Each readable surface's own inputs: its settings and the files its views load. */
14
+ surfaces?: ReadonlyMap<Surface, string>;
5
15
  same(): Promise<boolean>;
6
- hasAsset(scene: Scene, url: URL): boolean;
16
+ coversRequest: RequestCoverage;
17
+ prepare: (launch?: (scenes: readonly Scene[]) => Promise<void>) => Promise<void>;
18
+ runtime(force?: boolean, surface?: Surface): string | undefined;
7
19
  }
8
- /** The surface loads its whole view registry. Scene definitions still identify individual scenes. */
9
- export declare function snapshotInputs(root: string, scenes: readonly Scene[], run: Run, browser: () => Promise<string>, design?: string,
10
- /** What the fingerprint reads public values from: the process's, or a linked run's own. */
11
- environment?: Record<string, string | undefined>): Promise<SnapshotInputs>;
20
+ export declare function snapshotInputs(root: string, scenes: readonly Scene[], run: Run, browser: () => Promise<string>, design?: string, environment?: Record<string, string | undefined>): Promise<SnapshotInputs>;