@buffcore/cli 0.8.46 → 0.8.48
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.
- package/CHANGELOG.md +74 -0
- package/dist/commands/build/server-text.en.d.ts +5 -0
- package/dist/commands/build/server-text.en.js +5 -0
- package/dist/commands/build/server-text.js +5 -0
- package/dist/commands/build/server.d.ts +4 -0
- package/dist/commands/build/server.js +10 -1
- package/dist/commands/change-merge-remove.d.ts +9 -2
- package/dist/commands/change-merge-remove.js +27 -15
- package/dist/commands/change-merge.d.ts +2 -2
- package/dist/commands/design/check.d.ts +1 -1
- package/dist/commands/design/check.js +2 -1
- package/dist/commands/design/contract-size.d.ts +7 -0
- package/dist/commands/design/contract-size.js +47 -0
- package/dist/commands/design/tells.en.d.ts +2 -0
- package/dist/commands/design/tells.en.js +2 -0
- package/dist/commands/design/tells.es.js +2 -0
- package/dist/commands/dev.d.ts +9 -2
- package/dist/commands/dev.js +24 -5
- package/dist/commands/extension/places-approval.d.ts +4 -0
- package/dist/commands/hardening.d.ts +3 -0
- package/dist/commands/hardening.en.d.ts +3 -0
- package/dist/commands/hardening.en.js +3 -0
- package/dist/commands/hardening.es.d.ts +2 -0
- package/dist/commands/hardening.es.js +3 -0
- package/dist/commands/hardening.js +19 -0
- package/dist/commands/process-paths.d.ts +14 -0
- package/dist/commands/process-paths.js +90 -0
- package/dist/commands/prototype/ai-approval.d.ts +27 -0
- package/dist/commands/prototype/ai-approval.js +60 -0
- package/dist/commands/prototype/approver.d.ts +71 -0
- package/dist/commands/prototype/approver.js +168 -0
- package/dist/commands/prototype/comp-record.d.ts +5 -0
- package/dist/commands/prototype/comp-record.js +22 -0
- package/dist/commands/prototype/critique-gate.d.ts +14 -0
- package/dist/commands/prototype/critique-gate.js +48 -0
- package/dist/commands/prototype/fence.d.ts +1 -0
- package/dist/commands/prototype/fence.js +12 -0
- package/dist/commands/prototype/final-approval-grant.js +18 -0
- package/dist/commands/prototype/final-approval.js +4 -1
- package/dist/commands/prototype/index.js +3 -0
- package/dist/commands/prototype/layout-hints.d.ts +34 -0
- package/dist/commands/prototype/layout-hints.js +194 -0
- package/dist/commands/prototype/layout-measure.d.ts +39 -0
- package/dist/commands/prototype/layout-measure.js +97 -0
- package/dist/commands/prototype/layout-words.d.ts +2 -0
- package/dist/commands/prototype/layout-words.js +11 -0
- package/dist/commands/prototype/layout.en.d.ts +6 -0
- package/dist/commands/prototype/layout.en.js +7 -0
- package/dist/commands/prototype/load-location.js +2 -3
- package/dist/commands/prototype/messages.en.d.ts +14 -0
- package/dist/commands/prototype/messages.en.js +15 -1
- package/dist/commands/prototype/messages.js +15 -1
- package/dist/commands/prototype/milestone-versions.d.ts +4 -0
- package/dist/commands/prototype/prune-command.d.ts +5 -0
- package/dist/commands/prototype/prune-command.js +25 -0
- package/dist/commands/prototype/prune-words.d.ts +1 -0
- package/dist/commands/prototype/prune-words.js +7 -0
- package/dist/commands/prototype/prune.d.ts +16 -0
- package/dist/commands/prototype/prune.en.d.ts +9 -0
- package/dist/commands/prototype/prune.en.js +9 -0
- package/dist/commands/prototype/prune.es.d.ts +2 -0
- package/dist/commands/prototype/prune.es.js +9 -0
- package/dist/commands/prototype/prune.js +140 -0
- package/dist/commands/prototype/reopen-messages.d.ts +9 -0
- package/dist/commands/prototype/reopen-messages.js +19 -0
- package/dist/commands/prototype/report.d.ts +14 -0
- package/dist/commands/prototype/report.js +5 -1
- package/dist/commands/prototype/scene-layout.d.ts +17 -0
- package/dist/commands/prototype/scene-layout.js +57 -0
- package/dist/commands/prototype/scene-ready.js +8 -2
- package/dist/commands/prototype/scene.d.ts +15 -2
- package/dist/commands/prototype/scene.js +54 -42
- package/dist/commands/prototype/selector-answer.d.ts +43 -0
- package/dist/commands/prototype/selector-answer.js +73 -0
- package/dist/commands/prototype/selector-misses.d.ts +19 -0
- package/dist/commands/prototype/selector-misses.js +78 -0
- package/dist/commands/prototype/selector-prompt.d.ts +23 -0
- package/dist/commands/prototype/selector-prompt.js +32 -0
- package/dist/commands/prototype/selector-run.d.ts +13 -0
- package/dist/commands/prototype/selector-run.js +113 -0
- package/dist/commands/prototype/selector.d.ts +54 -0
- package/dist/commands/prototype/selector.js +96 -0
- package/dist/commands/prototype/snapshot-ancestor.js +2 -0
- package/dist/commands/prototype/snapshot-bundle.d.ts +17 -3
- package/dist/commands/prototype/snapshot-bundle.js +69 -7
- package/dist/commands/prototype/snapshot-check-files.d.ts +2 -0
- package/dist/commands/prototype/snapshot-check-files.js +41 -0
- package/dist/commands/prototype/snapshot-command.d.ts +2 -0
- package/dist/commands/prototype/snapshot-command.js +3 -0
- package/dist/commands/prototype/snapshot-completion.d.ts +4 -0
- package/dist/commands/prototype/snapshot-completion.js +30 -2
- package/dist/commands/prototype/snapshot-dependencies.d.ts +23 -2
- package/dist/commands/prototype/snapshot-dependencies.js +120 -14
- package/dist/commands/prototype/snapshot-hashes.d.ts +7 -0
- package/dist/commands/prototype/snapshot-hashes.js +28 -0
- package/dist/commands/prototype/snapshot-inputs.d.ts +15 -6
- package/dist/commands/prototype/snapshot-inputs.js +140 -197
- package/dist/commands/prototype/snapshot-matrix.d.ts +58 -0
- package/dist/commands/prototype/snapshot-matrix.js +95 -0
- package/dist/commands/prototype/snapshot-metro-inputs.d.ts +8 -0
- package/dist/commands/prototype/snapshot-metro-inputs.js +81 -0
- package/dist/commands/prototype/snapshot-owners.d.ts +6 -2
- package/dist/commands/prototype/snapshot-owners.js +12 -3
- package/dist/commands/prototype/snapshot-progress-entry.d.ts +14 -0
- package/dist/commands/prototype/snapshot-progress-entry.js +85 -0
- package/dist/commands/prototype/snapshot-progress.d.ts +19 -2
- package/dist/commands/prototype/snapshot-progress.js +54 -102
- package/dist/commands/prototype/snapshot-registry.d.ts +14 -0
- package/dist/commands/prototype/snapshot-registry.js +121 -0
- package/dist/commands/prototype/snapshot-report.d.ts +4 -0
- package/dist/commands/prototype/snapshot-report.js +77 -12
- package/dist/commands/prototype/snapshot-requests.d.ts +13 -3
- package/dist/commands/prototype/snapshot-requests.js +68 -30
- package/dist/commands/prototype/snapshot-reuse.d.ts +6 -1
- package/dist/commands/prototype/snapshot-reuse.js +17 -7
- package/dist/commands/prototype/snapshot-scene-inputs.d.ts +30 -0
- package/dist/commands/prototype/snapshot-scene-inputs.js +210 -0
- package/dist/commands/prototype/snapshot-served-inputs.d.ts +3 -0
- package/dist/commands/prototype/snapshot-served-inputs.js +12 -0
- package/dist/commands/prototype/snapshot-server-record.d.ts +26 -0
- package/dist/commands/prototype/snapshot-server-record.js +135 -0
- package/dist/commands/prototype/snapshot-servers.d.ts +3 -1
- package/dist/commands/prototype/snapshot-servers.js +50 -2
- package/dist/commands/prototype/snapshot-setup.d.ts +3 -1
- package/dist/commands/prototype/snapshot-setup.js +2 -1
- package/dist/commands/prototype/snapshot-surface-inputs.d.ts +23 -0
- package/dist/commands/prototype/snapshot-surface-inputs.js +161 -0
- package/dist/commands/prototype/snapshot-vite-inputs.d.ts +22 -0
- package/dist/commands/prototype/snapshot-vite-inputs.js +209 -0
- package/dist/commands/prototype/snapshot.d.ts +5 -0
- package/dist/commands/prototype/snapshot.js +72 -10
- package/dist/commands/prototype/version-commands.d.ts +4 -0
- package/dist/commands/prototype/version-commands.js +36 -8
- package/dist/commands/prototype/versions.d.ts +28 -2
- package/dist/commands/prototype/versions.js +25 -1
- package/dist/commands/prototype/vite-fs-path.d.ts +4 -0
- package/dist/commands/prototype/vite-fs-path.js +15 -0
- package/dist/commands/remove-links.d.ts +6 -0
- package/dist/commands/remove-links.js +17 -0
- package/dist/commands/server/build.d.ts +2 -1
- package/dist/commands/server/build.js +10 -2
- package/dist/commands/server/deploy-local.d.ts +3 -0
- package/dist/commands/server/deploy-local.js +9 -0
- package/dist/commands/server/deploy-plan.d.ts +5 -0
- package/dist/commands/server/deploy-plan.js +56 -0
- package/dist/commands/server/deploy-result.d.ts +7 -0
- package/dist/commands/server/deploy-result.js +1 -0
- package/dist/commands/server/deploy-script.d.ts +2 -0
- package/dist/commands/server/deploy-script.js +3 -2
- package/dist/commands/server/deploy.d.ts +9 -6
- package/dist/commands/server/deploy.js +39 -61
- package/dist/commands/server/files.d.ts +9 -1
- package/dist/commands/server/files.js +25 -5
- package/dist/commands/server/image.d.ts +4 -2
- package/dist/commands/server/image.js +6 -5
- package/dist/commands/server/setup.js +4 -0
- package/dist/commands/server/system-packages.d.ts +29 -0
- package/dist/commands/server/system-packages.js +103 -0
- package/dist/commands/services/compose.d.ts +1 -1
- package/dist/commands/services/compose.js +5 -3
- package/dist/commands/size-docs.d.ts +9 -0
- package/dist/commands/size-docs.en.d.ts +6 -0
- package/dist/commands/size-docs.en.js +6 -0
- package/dist/commands/size-docs.es.d.ts +2 -0
- package/dist/commands/size-docs.es.js +6 -0
- package/dist/commands/size-docs.js +28 -0
- package/dist/commands/size.d.ts +5 -2
- package/dist/commands/size.js +27 -9
- package/dist/commands/ui/agents-route.js +2 -0
- package/dist/commands/ui/approval-authority.d.ts +10 -2
- package/dist/commands/ui/approval-authority.en.d.ts +1 -0
- package/dist/commands/ui/approval-authority.en.js +1 -0
- package/dist/commands/ui/approval-authority.es.d.ts +1 -0
- package/dist/commands/ui/approval-authority.es.js +1 -0
- package/dist/commands/ui/approval-authority.js +8 -2
- package/dist/commands/ui/approve.js +2 -4
- package/dist/commands/ui/autopilot-ai-approve.d.ts +18 -0
- package/dist/commands/ui/autopilot-ai-approve.js +68 -0
- package/dist/commands/ui/autopilot-loop.js +5 -6
- package/dist/commands/ui/autopilot-merge.js +3 -0
- package/dist/commands/ui/autopilot-records.d.ts +2 -0
- package/dist/commands/ui/autopilot-records.js +5 -0
- package/dist/commands/ui/autopilot.en.d.ts +23 -0
- package/dist/commands/ui/autopilot.en.js +23 -0
- package/dist/commands/ui/autopilot.es.d.ts +23 -0
- package/dist/commands/ui/autopilot.es.js +23 -0
- package/dist/commands/ui/brand-approval.js +5 -1
- package/dist/commands/ui/chat/find.d.ts +2 -0
- package/dist/commands/ui/chat/find.js +13 -0
- package/dist/commands/ui/chat/fresh-codex.d.ts +39 -0
- package/dist/commands/ui/chat/fresh-codex.js +175 -0
- package/dist/commands/ui/chat/fresh-critique.js +13 -5
- package/dist/commands/ui/chat/fresh-launch.d.ts +19 -0
- package/dist/commands/ui/chat/fresh-launch.js +67 -11
- package/dist/commands/ui/chat/fresh-prompts.d.ts +2 -0
- package/dist/commands/ui/chat/fresh-prompts.js +2 -0
- package/dist/commands/ui/chat/fresh-secrets.d.ts +6 -0
- package/dist/commands/ui/chat/fresh-secrets.js +172 -0
- package/dist/commands/ui/chat/fresh.en.d.ts +1 -0
- package/dist/commands/ui/chat/fresh.en.js +2 -1
- package/dist/commands/ui/chat/fresh.es.d.ts +1 -0
- package/dist/commands/ui/chat/fresh.es.js +2 -1
- package/dist/commands/ui/chat/permissions.js +1 -1
- package/dist/commands/ui/chat/routes.js +4 -0
- package/dist/commands/ui/chat/worktree.js +25 -5
- package/dist/commands/ui/comp-approval.d.ts +14 -2
- package/dist/commands/ui/comp-approval.js +45 -8
- package/dist/commands/ui/index.js +3 -0
- package/dist/commands/ui/level-route.js +3 -0
- package/dist/commands/ui/loop-approve.d.ts +30 -1
- package/dist/commands/ui/loop-approve.js +2 -2
- package/dist/commands/ui/merge-authority.d.ts +4 -1
- package/dist/commands/ui/merge-authority.en.d.ts +4 -0
- package/dist/commands/ui/merge-authority.en.js +5 -1
- package/dist/commands/ui/merge-authority.es.d.ts +4 -0
- package/dist/commands/ui/merge-authority.es.js +5 -1
- package/dist/commands/ui/merge-authority.js +6 -3
- package/dist/commands/ui/merge-claims.d.ts +7 -0
- package/dist/commands/ui/merge-claims.js +21 -0
- package/dist/commands/ui/merge-delegation.js +8 -3
- package/dist/commands/ui/merge-hold-name.d.ts +5 -0
- package/dist/commands/ui/merge-hold-name.js +5 -0
- package/dist/commands/ui/merge-hold.d.ts +6 -1
- package/dist/commands/ui/merge-hold.js +23 -5
- package/dist/commands/ui/merge-publish-host.d.ts +1 -0
- package/dist/commands/ui/merge-publish-host.js +2 -2
- package/dist/commands/ui/merge-record.d.ts +2 -0
- package/dist/commands/ui/merge-record.js +1 -1
- package/dist/commands/ui/merge-route.js +20 -1
- package/dist/commands/ui/merge-settle.d.ts +32 -0
- package/dist/commands/ui/merge-settle.js +133 -0
- package/dist/commands/ui/merge-state.d.ts +5 -0
- package/dist/commands/ui/merge-state.js +7 -1
- package/dist/commands/ui/merge-withdraw.d.ts +9 -0
- package/dist/commands/ui/merge-withdraw.js +29 -0
- package/dist/commands/ui/places-change.d.ts +4 -0
- package/dist/commands/ui/plan-files.js +5 -2
- package/dist/commands/ui/plan-structure.js +5 -7
- package/dist/commands/ui/prototype-comp-route.d.ts +12 -3
- package/dist/commands/ui/prototype-comp-route.js +35 -17
- package/dist/commands/ui/prototype-main.d.ts +4 -0
- package/dist/commands/ui/real-file.d.ts +11 -0
- package/dist/commands/ui/real-file.js +84 -0
- package/dist/commands/ui/reopen-route.d.ts +117 -0
- package/dist/commands/ui/reopen-route.js +97 -0
- package/dist/commands/ui/save-route.d.ts +2 -0
- package/dist/commands/ui/save-route.js +8 -1
- package/dist/commands/ui/server.d.ts +1 -0
- package/dist/commands/ui/server.js +1 -0
- package/dist/commands/ui/studio-routes.js +2 -0
- package/dist/commands/ui/studio-state.d.ts +34 -0
- package/dist/commands/ui/studio-versions.d.ts +24 -0
- package/dist/commands/ui/studio-versions.js +19 -3
- package/dist/commands/ui/worktrees.d.ts +1 -1
- package/dist/commands/ui/worktrees.js +19 -3
- package/dist/commands/worktree-sweep.d.ts +45 -0
- package/dist/commands/worktree-sweep.js +188 -0
- package/dist/commands/worktrees-command.d.ts +32 -0
- package/dist/commands/worktrees-command.en.d.ts +25 -0
- package/dist/commands/worktrees-command.en.js +55 -0
- package/dist/commands/worktrees-command.js +96 -0
- package/dist/main.js +2 -0
- package/dist/ui/page.js +89 -89
- package/docs/PROTOTYPE.md +19 -3
- package/docs/WORKBENCH.md +41 -6
- package/package.json +11 -11
- package/skills/ape-critique/SKILL.md +41 -6
- package/skills/ape-deploy/SKILL.md +4 -2
- package/skills/ape-design-system/SKILL.md +3 -0
- package/skills/ape-plan-change/SKILL.md +6 -0
- package/skills/ape-prototype/SKILL.md +8 -4
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Learning without a person (S3c): a full run that finds a problem in a look the last selector run
|
|
2
|
+
// didn't draw for that scene records the miss in `prototype/snapshots/selector-misses.json`
|
|
3
|
+
// (committed with the report), and later selector turns get the latest misses as examples.
|
|
4
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
export const MISSES_FILE = 'selector-misses.json';
|
|
7
|
+
/** The misses kept, newest last. */
|
|
8
|
+
export const MAX_MISSES = 20;
|
|
9
|
+
const isMiss = (value) => {
|
|
10
|
+
const miss = value;
|
|
11
|
+
return (!!miss &&
|
|
12
|
+
typeof miss.report === 'string' &&
|
|
13
|
+
typeof miss.scene === 'string' &&
|
|
14
|
+
typeof miss.check === 'string' &&
|
|
15
|
+
typeof miss.theme === 'string');
|
|
16
|
+
};
|
|
17
|
+
/** The latest misses in the snapshots folder; none when the file is missing or unreadable. */
|
|
18
|
+
export function readMisses(dir) {
|
|
19
|
+
try {
|
|
20
|
+
const value = JSON.parse(readFileSync(join(dir, MISSES_FILE), 'utf8'));
|
|
21
|
+
const misses = value?.misses;
|
|
22
|
+
return Array.isArray(misses) ? misses.filter(isMiss).slice(-MAX_MISSES) : [];
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Whether the selector run drew this problem's look for its scene: a floor look or a pick. */
|
|
29
|
+
function drawn(selector, problem) {
|
|
30
|
+
const looks = [
|
|
31
|
+
...selector.floor,
|
|
32
|
+
...selector.picks.flatMap((pick) => pick.scene === problem.scene && pick.look ? [pick.look] : []),
|
|
33
|
+
];
|
|
34
|
+
return looks.some((look) => {
|
|
35
|
+
const [theme, mode, locale] = look.split('.');
|
|
36
|
+
return (theme === problem.theme &&
|
|
37
|
+
(problem.mode === undefined || mode === problem.mode) &&
|
|
38
|
+
(problem.locale === undefined || locale === problem.locale));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** The problems of a full report that the last selector run (`last`) did not draw. */
|
|
42
|
+
export function findMisses(full, last) {
|
|
43
|
+
const selector = last?.selector;
|
|
44
|
+
if (full.matrix !== 'full' || full.scene !== undefined || !selector)
|
|
45
|
+
return [];
|
|
46
|
+
return full.problems.flatMap((problem) => {
|
|
47
|
+
if (!problem.scene)
|
|
48
|
+
return [];
|
|
49
|
+
const miss = {
|
|
50
|
+
report: full.commit,
|
|
51
|
+
scene: problem.scene,
|
|
52
|
+
check: problem.check,
|
|
53
|
+
theme: problem.theme,
|
|
54
|
+
...(problem.mode ? { mode: problem.mode } : {}),
|
|
55
|
+
...(problem.locale ? { locale: problem.locale } : {}),
|
|
56
|
+
};
|
|
57
|
+
return drawn(selector, miss) ? [] : [miss];
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/** Add the new misses, once each, and keep the latest; true when the file changed. */
|
|
61
|
+
export function recordMisses(dir, found) {
|
|
62
|
+
if (!found.length)
|
|
63
|
+
return false;
|
|
64
|
+
const known = readMisses(dir);
|
|
65
|
+
const keys = new Set(known.map((miss) => JSON.stringify({ ...miss, report: '' })));
|
|
66
|
+
const added = found.filter((miss) => {
|
|
67
|
+
const key = JSON.stringify({ ...miss, report: '' });
|
|
68
|
+
if (keys.has(key))
|
|
69
|
+
return false;
|
|
70
|
+
keys.add(key);
|
|
71
|
+
return true;
|
|
72
|
+
});
|
|
73
|
+
if (!added.length)
|
|
74
|
+
return false;
|
|
75
|
+
const misses = [...known, ...added].slice(-MAX_MISSES);
|
|
76
|
+
writeFileSync(join(dir, MISSES_FILE), `${JSON.stringify({ misses }, null, 2)}\n`);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SelectorMiss } from './selector-misses.ts';
|
|
2
|
+
export interface SelectorInput {
|
|
3
|
+
/** The commit of the report the floor compared with; absent when there is none. */
|
|
4
|
+
base?: string;
|
|
5
|
+
/** `git diff` since that commit (stat and patch, bounded). */
|
|
6
|
+
diff: string;
|
|
7
|
+
scenes: readonly {
|
|
8
|
+
key: string;
|
|
9
|
+
surface: string;
|
|
10
|
+
view: string;
|
|
11
|
+
}[];
|
|
12
|
+
/** The looks every scene is drawn in, `<theme>.<mode>.<locale>`. */
|
|
13
|
+
floor: readonly string[];
|
|
14
|
+
/** Every look a pick may name. */
|
|
15
|
+
looks: readonly string[];
|
|
16
|
+
/** Recent looks a full run found a problem in that the selector had not drawn. */
|
|
17
|
+
misses: readonly SelectorMiss[];
|
|
18
|
+
}
|
|
19
|
+
/** The prompt of one selector turn; `first` holds the first turn's picks (the second turn only). */
|
|
20
|
+
export declare function selectorPrompt(input: SelectorInput, first?: readonly {
|
|
21
|
+
scene: string;
|
|
22
|
+
look?: string;
|
|
23
|
+
}[]): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// What the selector's turns are asked (S3c). Both turns get the same input; the second also gets the
|
|
2
|
+
// first answer's picks without their reasons, and may only add. The agent reads; it writes nothing.
|
|
3
|
+
import { fenceData } from './fence.js';
|
|
4
|
+
const SHAPE = '{"picks":[{"scene":"<scene key>","look":"<theme>.<mode>.<locale>","reason":"<one line>"}]}';
|
|
5
|
+
/** The prompt of one selector turn; `first` holds the first turn's picks (the second turn only). */
|
|
6
|
+
export function selectorPrompt(input, first) {
|
|
7
|
+
return [
|
|
8
|
+
'You choose extra screenshots for a prototype snapshot. Read the repository as you need; change nothing.',
|
|
9
|
+
'Every scene that changed is drawn in the floor looks below. Name the scenes and looks the change could',
|
|
10
|
+
'break that the floor does not draw: a scene to draw again in the floor (omit "look"), or one look from the',
|
|
11
|
+
'list of possible looks for a scene. You can only add; the floor always stays. Name nothing you cannot',
|
|
12
|
+
'justify in one line. An empty list is a good answer when the floor is enough.',
|
|
13
|
+
`Answer with JSON only, exactly this shape, at most 40 picks: ${SHAPE}`,
|
|
14
|
+
...(first
|
|
15
|
+
? [
|
|
16
|
+
'Another reviewer already picked the following; it stays. Add only what it missed, or answer {"picks":[]}.',
|
|
17
|
+
JSON.stringify(first),
|
|
18
|
+
]
|
|
19
|
+
: []),
|
|
20
|
+
`Floor looks: ${JSON.stringify(input.floor)}`,
|
|
21
|
+
`Possible looks: ${JSON.stringify(input.looks)}`,
|
|
22
|
+
`Scenes (key, surface, view it imports): ${JSON.stringify(input.scenes.map((s) => [s.key, s.surface, s.view]))}`,
|
|
23
|
+
...(input.misses.length
|
|
24
|
+
? [
|
|
25
|
+
'Earlier misses (a full run found a problem in a look the selector had not drawn):',
|
|
26
|
+
JSON.stringify(input.misses),
|
|
27
|
+
]
|
|
28
|
+
: []),
|
|
29
|
+
input.base ? `Changes since ${input.base}:` : 'No earlier report: the changes are unknown.',
|
|
30
|
+
fenceData('diff', input.diff),
|
|
31
|
+
].join('\n');
|
|
32
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SnapshotReport } from './report.ts';
|
|
2
|
+
import type { Run } from './scene.ts';
|
|
3
|
+
import { type SelectorRecord } from './selector.ts';
|
|
4
|
+
import type { SelectorInput } from './selector-prompt.ts';
|
|
5
|
+
import type { SnapshotOptions } from './snapshot.ts';
|
|
6
|
+
/** How a snapshot run asks the selector: the CLI's real turns, or a test's fake. */
|
|
7
|
+
export type Selector = (folder: string, input: SelectorInput) => Promise<SelectorRecord>;
|
|
8
|
+
/** The CLI's selector: plan/agents.md's validation agent and model, through the studio's launch. */
|
|
9
|
+
export declare function cliSelector(root: string, env?: NodeJS.ProcessEnv): Selector;
|
|
10
|
+
/** Ask the selector (whole floor runs only) and add its picks to the run; never throws. */
|
|
11
|
+
export declare function selectForRun(options: SnapshotOptions, run: Run): Promise<void>;
|
|
12
|
+
/** After a whole full run: note the problems in looks the last selector run didn't draw. */
|
|
13
|
+
export declare function afterFullRun(options: SnapshotOptions, report: SnapshotReport): void;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// The selector in a snapshot run (S3c): after the floor is known and before drawing, the selector's
|
|
2
|
+
// picks are added to the run (scenes drawn again, looks beyond the floor); the report keeps them. A
|
|
3
|
+
// full run (`--full` or a shared change) skips it, and records the selector's misses for later turns.
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { parseAgentsFile } from '../agents-file.js';
|
|
7
|
+
import { hostGitBytes } from '../safe-git.js';
|
|
8
|
+
import { freshEnvironment } from '../ui/chat/fresh-codex.js';
|
|
9
|
+
import { agentStart } from '../ui/chat/process.js';
|
|
10
|
+
import { t } from './messages.js';
|
|
11
|
+
import { runSelector, SELECTOR_SECONDS, skippedRun } from './selector.js';
|
|
12
|
+
import { extrasOf } from './selector-answer.js';
|
|
13
|
+
import { findMisses, readMisses, recordMisses } from './selector-misses.js';
|
|
14
|
+
import { findAncestor } from './snapshot-ancestor.js';
|
|
15
|
+
import { drawnLooks, lookName } from './snapshot-matrix.js';
|
|
16
|
+
/** The diff a turn reads at most, in characters. */
|
|
17
|
+
const DIFF_CHARS = 40_000;
|
|
18
|
+
/** The CLI's selector: plan/agents.md's validation agent and model, through the studio's launch. */
|
|
19
|
+
export function cliSelector(root, env = process.env) {
|
|
20
|
+
return async (folder, input) => {
|
|
21
|
+
let settings;
|
|
22
|
+
try {
|
|
23
|
+
settings = parseAgentsFile(readFileSync(join(root, 'plan', 'agents.md'), 'utf8'));
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
settings = undefined;
|
|
27
|
+
}
|
|
28
|
+
// The environment of the agent turn that runs this snapshot never reaches the selector's.
|
|
29
|
+
const source = freshEnvironment(env);
|
|
30
|
+
let start;
|
|
31
|
+
try {
|
|
32
|
+
start = agentStart(root, source);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return skippedRun('launch', input.floor);
|
|
36
|
+
}
|
|
37
|
+
const home = process.platform === 'win32' ? env.USERPROFILE : env.HOME;
|
|
38
|
+
return runSelector(folder, input, { start, settings, env, ...(home ? { home } : {}) });
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function diffSince(root, base) {
|
|
42
|
+
if (!base)
|
|
43
|
+
return '';
|
|
44
|
+
const read = (args) => {
|
|
45
|
+
try {
|
|
46
|
+
return hostGitBytes(root, [
|
|
47
|
+
'diff',
|
|
48
|
+
'--no-color',
|
|
49
|
+
'--no-ext-diff',
|
|
50
|
+
'--no-textconv',
|
|
51
|
+
...args,
|
|
52
|
+
base,
|
|
53
|
+
]).toString();
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return '';
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const stat = read(['--stat']);
|
|
60
|
+
const patch = stat.length < DIFF_CHARS ? read([]) : '';
|
|
61
|
+
const text = `${stat}\n${patch}`;
|
|
62
|
+
return text.length > DIFF_CHARS ? `${text.slice(0, DIFF_CHARS)}\n[diff cut]` : text;
|
|
63
|
+
}
|
|
64
|
+
/** Ask the selector (whole floor runs only) and add its picks to the run; never throws. */
|
|
65
|
+
export async function selectForRun(options, run) {
|
|
66
|
+
if (!options.selector)
|
|
67
|
+
return;
|
|
68
|
+
const floor = drawnLooks({ ...run, matrix: 'floor' }).map(lookName);
|
|
69
|
+
const why = run.matrix !== 'floor' ? 'full' : options.scene !== undefined ? 'scene' : undefined;
|
|
70
|
+
let record;
|
|
71
|
+
if (why)
|
|
72
|
+
record = skippedRun(why, floor);
|
|
73
|
+
else {
|
|
74
|
+
const base = options.root ? findAncestor(options.root, run.commit)?.report.commit : undefined;
|
|
75
|
+
const input = {
|
|
76
|
+
...(base ? { base } : {}),
|
|
77
|
+
diff: options.root ? diffSince(options.root, base) : '',
|
|
78
|
+
scenes: options.scenes.scenes.map(({ key, surface, view }) => ({ key, surface, view })),
|
|
79
|
+
floor,
|
|
80
|
+
looks: drawnLooks({ ...run, matrix: 'full' }).map(lookName),
|
|
81
|
+
misses: readMisses(options.dir),
|
|
82
|
+
};
|
|
83
|
+
record = await options
|
|
84
|
+
.selector(options.root ?? process.cwd(), input)
|
|
85
|
+
.catch(() => skippedRun('failed', floor));
|
|
86
|
+
}
|
|
87
|
+
run.selector = record;
|
|
88
|
+
const extras = extrasOf(record.picks);
|
|
89
|
+
run.redraw = extras.scenes;
|
|
90
|
+
run.extraLooks = extras.looks;
|
|
91
|
+
if (record.skipped && record.skipped !== 'full' && record.skipped !== 'scene')
|
|
92
|
+
console.log(t('prototype.selectorSkipped', {
|
|
93
|
+
why: t(`prototype.selector.${record.skipped}`, {
|
|
94
|
+
seconds: SELECTOR_SECONDS,
|
|
95
|
+
agent: record.agent,
|
|
96
|
+
file: record.file,
|
|
97
|
+
}),
|
|
98
|
+
}));
|
|
99
|
+
else if (record.picks.length)
|
|
100
|
+
console.log(t('prototype.selectorAdded', { count: record.picks.length }));
|
|
101
|
+
}
|
|
102
|
+
/** After a whole full run: note the problems in looks the last selector run didn't draw. */
|
|
103
|
+
export function afterFullRun(options, report) {
|
|
104
|
+
if (!options.selector || !options.root || report.matrix !== 'full')
|
|
105
|
+
return;
|
|
106
|
+
try {
|
|
107
|
+
const last = findAncestor(options.root, report.commit)?.report;
|
|
108
|
+
recordMisses(options.dir, findMisses(report, last));
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
/* Learning never fails a run. */
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { AgentsFile } from '@buffcore/contracts/workbench';
|
|
2
|
+
import { type FreshAgent } from '../ui/chat/fresh-codex.ts';
|
|
3
|
+
import { type Start, stopTree } from '../ui/runner.ts';
|
|
4
|
+
import { type SelectorDrop, type SelectorPick } from './selector-answer.ts';
|
|
5
|
+
import { type SelectorInput } from './selector-prompt.ts';
|
|
6
|
+
/** How long one selector turn may take. */
|
|
7
|
+
export declare const SELECTOR_SECONDS = 120;
|
|
8
|
+
/** Why the floor was drawn alone, or why a turn gave nothing. */
|
|
9
|
+
export type SelectorWhy = 'full' | 'scene' | 'agent-unsupported' | 'codex-sandbox' | 'ci' | 'host' | 'launch' | 'failed' | 'timeout' | 'shape' | 'secret';
|
|
10
|
+
export interface SelectorTurn {
|
|
11
|
+
agent: FreshAgent;
|
|
12
|
+
model?: string;
|
|
13
|
+
effort?: string;
|
|
14
|
+
/** `done`, or why the turn gave nothing. */
|
|
15
|
+
state: 'done' | Extract<SelectorWhy, 'launch' | 'failed' | 'timeout' | 'shape' | 'secret'>;
|
|
16
|
+
seconds: number;
|
|
17
|
+
/** With 'secret': the secret file whose value the answer quoted (never the value). */
|
|
18
|
+
file?: string;
|
|
19
|
+
}
|
|
20
|
+
/** What `report.json` keeps of the run's selector, in `selector`. */
|
|
21
|
+
export interface SelectorRecord {
|
|
22
|
+
/** Absent when at least one turn answered; else why the floor was drawn alone. */
|
|
23
|
+
skipped?: SelectorWhy;
|
|
24
|
+
/** With 'agent-unsupported': the agent plan/agents.md sets, which has no fresh read-only turn. */
|
|
25
|
+
agent?: string;
|
|
26
|
+
/** With 'secret': the secret file whose value a turn's answer quoted (never the value). */
|
|
27
|
+
file?: string;
|
|
28
|
+
turns: SelectorTurn[];
|
|
29
|
+
picks: SelectorPick[];
|
|
30
|
+
dropped: SelectorDrop[];
|
|
31
|
+
/** The floor's looks, to tell a later full run which looks this run drew. */
|
|
32
|
+
floor: string[];
|
|
33
|
+
}
|
|
34
|
+
export interface SelectorDeps {
|
|
35
|
+
start: Start;
|
|
36
|
+
settings: AgentsFile | undefined;
|
|
37
|
+
env: NodeJS.ProcessEnv;
|
|
38
|
+
stop?: typeof stopTree;
|
|
39
|
+
seconds?: number;
|
|
40
|
+
/** The bounded wait after a timeout (tests shorten it). */
|
|
41
|
+
stopWaitMs?: number;
|
|
42
|
+
/** The person's home, whose Claude settings give the turn their denies and sign-in. */
|
|
43
|
+
home?: string;
|
|
44
|
+
}
|
|
45
|
+
/** The floor alone, and why. */
|
|
46
|
+
export declare const skippedRun: (why: SelectorWhy, floor: readonly string[], turns?: SelectorTurn[]) => {
|
|
47
|
+
skipped: SelectorWhy;
|
|
48
|
+
turns: SelectorTurn[];
|
|
49
|
+
picks: never[];
|
|
50
|
+
dropped: never[];
|
|
51
|
+
floor: string[];
|
|
52
|
+
};
|
|
53
|
+
/** Run both turns and keep their union; never throws. */
|
|
54
|
+
export declare function runSelector(folder: string, input: SelectorInput, deps: SelectorDeps): Promise<SelectorRecord>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { freshAgent, freshUnready } from '../ui/chat/fresh-codex.js';
|
|
2
|
+
import { runFresh, stopFresh } from '../ui/chat/fresh-launch.js';
|
|
3
|
+
import { hostLaunchedEnv } from '../ui/chat/host-launched.js';
|
|
4
|
+
import { stopTree } from '../ui/runner.js';
|
|
5
|
+
import { parseAnswer, unionPicks, } from './selector-answer.js';
|
|
6
|
+
import { selectorPrompt } from './selector-prompt.js';
|
|
7
|
+
/** How long one selector turn may take. */
|
|
8
|
+
export const SELECTOR_SECONDS = 120;
|
|
9
|
+
/** How long a stopped turn may take to close before its settings file is removed anyway. */
|
|
10
|
+
const STOP_WAIT_MS = 5000;
|
|
11
|
+
const wait = (ms) => new Promise((done) => setTimeout(done, ms).unref?.());
|
|
12
|
+
/** The floor alone, and why. */
|
|
13
|
+
export const skippedRun = (why, floor, turns = []) => ({
|
|
14
|
+
skipped: why,
|
|
15
|
+
turns,
|
|
16
|
+
picks: [],
|
|
17
|
+
dropped: [],
|
|
18
|
+
floor: [...floor],
|
|
19
|
+
});
|
|
20
|
+
/** Run both turns and keep their union; never throws. */
|
|
21
|
+
export async function runSelector(folder, input, deps) {
|
|
22
|
+
const { settings, env } = deps;
|
|
23
|
+
// As the critique: without plan/agents.md, Claude Code.
|
|
24
|
+
const agent = settings?.work.validation ?? settings?.default ?? 'claude';
|
|
25
|
+
// Only an agent with a fresh read-only turn (fresh-launch.ts) takes it, as for the critique.
|
|
26
|
+
const unready = freshUnready(agent, folder);
|
|
27
|
+
if (unready || !freshAgent(agent)) {
|
|
28
|
+
const why = unready !== 'codex-sandbox' ? 'agent-unsupported' : unready;
|
|
29
|
+
return { ...skippedRun(why, input.floor), agent };
|
|
30
|
+
}
|
|
31
|
+
// A test run counts as CI: a child the tests start must never reach a live agent.
|
|
32
|
+
if (env.CI || env.VITEST)
|
|
33
|
+
return skippedRun('ci', input.floor);
|
|
34
|
+
// The host's own launcher starts every turn; a terminal run can't.
|
|
35
|
+
if (hostLaunchedEnv(env))
|
|
36
|
+
return skippedRun('host', input.floor);
|
|
37
|
+
const choice = {
|
|
38
|
+
...(settings?.model?.validation ? { model: settings.model.validation } : {}),
|
|
39
|
+
...(settings?.effort?.validation ? { effort: settings.effort.validation } : {}),
|
|
40
|
+
};
|
|
41
|
+
const bounds = {
|
|
42
|
+
scenes: new Set(input.scenes.map((scene) => scene.key)),
|
|
43
|
+
looks: new Set(input.looks),
|
|
44
|
+
floor: new Set(input.floor),
|
|
45
|
+
};
|
|
46
|
+
const launch = { agent, folder, ...choice, ...(deps.home ? { home: deps.home } : {}) };
|
|
47
|
+
const one = await selectorTurn(deps, { ...launch, prompt: selectorPrompt(input) });
|
|
48
|
+
if (!one.answer) {
|
|
49
|
+
const skipped = skippedRun(one.turn.state, input.floor, [one.turn]);
|
|
50
|
+
return one.turn.file ? { ...skipped, file: one.turn.file } : skipped;
|
|
51
|
+
}
|
|
52
|
+
const first = unionPicks([one.answer], bounds).picks.map(({ scene, look }) => ({
|
|
53
|
+
scene,
|
|
54
|
+
...(look ? { look } : {}),
|
|
55
|
+
}));
|
|
56
|
+
const two = await selectorTurn(deps, { ...launch, prompt: selectorPrompt(input, first) });
|
|
57
|
+
return {
|
|
58
|
+
turns: [one.turn, two.turn],
|
|
59
|
+
...unionPicks([one.answer, two.answer], bounds),
|
|
60
|
+
floor: [...input.floor],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
async function selectorTurn(deps, launch) {
|
|
64
|
+
const started = Date.now();
|
|
65
|
+
const record = (state) => ({
|
|
66
|
+
agent: launch.agent ?? 'claude',
|
|
67
|
+
...(launch.model ? { model: launch.model } : {}),
|
|
68
|
+
...(launch.effort ? { effort: launch.effort } : {}),
|
|
69
|
+
state,
|
|
70
|
+
seconds: Math.max(0, Math.floor((Date.now() - started) / 1000)),
|
|
71
|
+
});
|
|
72
|
+
const run = runFresh(deps.start, launch);
|
|
73
|
+
if (!run.child)
|
|
74
|
+
return { turn: record('launch') };
|
|
75
|
+
let timer;
|
|
76
|
+
const late = new Promise((done) => {
|
|
77
|
+
timer = setTimeout(() => done('timeout'), (deps.seconds ?? SELECTOR_SECONDS) * 1000);
|
|
78
|
+
timer.unref?.();
|
|
79
|
+
});
|
|
80
|
+
const result = await Promise.race([run.result, late]);
|
|
81
|
+
clearTimeout(timer);
|
|
82
|
+
if (result === 'timeout') {
|
|
83
|
+
stopFresh(run, deps.stop ?? stopTree);
|
|
84
|
+
// The stopped tree closes the child, which removes the turn's settings file; if it never does,
|
|
85
|
+
// the file goes after a bounded wait.
|
|
86
|
+
await Promise.race([run.result, wait(deps.stopWaitMs ?? STOP_WAIT_MS)]);
|
|
87
|
+
run.release?.();
|
|
88
|
+
return { turn: record('timeout') };
|
|
89
|
+
}
|
|
90
|
+
if (result.secret)
|
|
91
|
+
return { turn: { ...record('secret'), file: result.secret } };
|
|
92
|
+
if (result.text === undefined)
|
|
93
|
+
return { turn: record('failed') };
|
|
94
|
+
const answer = parseAnswer(result.text);
|
|
95
|
+
return answer ? { turn: record('done'), answer } : { turn: record('shape') };
|
|
96
|
+
}
|
|
@@ -57,6 +57,8 @@ export function findAncestor(root, current, reader = bounded) {
|
|
|
57
57
|
'--format=%H',
|
|
58
58
|
'--name-only',
|
|
59
59
|
'--no-renames',
|
|
60
|
+
// A commit that only removes old reports (`ape prototype prune`) holds no report to reuse.
|
|
61
|
+
'--diff-filter=d',
|
|
60
62
|
'--diff-merges=first-parent',
|
|
61
63
|
'--relative',
|
|
62
64
|
'--no-notes',
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { Surface } from '@buffcore/config';
|
|
2
|
-
import { type Loader, type PluginBuild } from 'esbuild';
|
|
2
|
+
import { type Loader, type Metafile, type PluginBuild } from 'esbuild';
|
|
3
3
|
export declare const loaders: Record<string, Loader>;
|
|
4
4
|
export interface SurfaceEntry {
|
|
5
5
|
surface: Surface;
|
|
6
6
|
dir: string;
|
|
7
7
|
registry: string;
|
|
8
8
|
roots: string[];
|
|
9
|
+
routes: string[];
|
|
9
10
|
}
|
|
10
11
|
export declare const catalogInput = "snapshot-inputs:snapshot-catalog-effects";
|
|
11
12
|
export declare const virtualInput: (name: string) => boolean;
|
|
@@ -19,12 +20,13 @@ export declare function bundleSurface(root: string, catalog: string, entry: Surf
|
|
|
19
20
|
format: "esm";
|
|
20
21
|
platform: "browser";
|
|
21
22
|
conditions: string[];
|
|
22
|
-
mainFields: string[]
|
|
23
|
+
mainFields: string[];
|
|
23
24
|
define: {
|
|
24
25
|
'import.meta.env.DEV': string;
|
|
25
26
|
__DEV__: string;
|
|
26
27
|
};
|
|
27
28
|
jsx: "automatic";
|
|
29
|
+
jsxDev: boolean;
|
|
28
30
|
ignoreAnnotations: true;
|
|
29
31
|
loader: Record<string, Loader>;
|
|
30
32
|
logLevel: "silent";
|
|
@@ -39,6 +41,18 @@ export declare function bundleSurface(root: string, catalog: string, entry: Surf
|
|
|
39
41
|
name: string;
|
|
40
42
|
setup(builder: PluginBuild): void;
|
|
41
43
|
}[];
|
|
42
|
-
resolveExtensions: string[]
|
|
44
|
+
resolveExtensions: string[];
|
|
43
45
|
write: false;
|
|
44
46
|
}>>;
|
|
47
|
+
export type Imports = Metafile['inputs'][string]['imports'];
|
|
48
|
+
export type SourceFiles = {
|
|
49
|
+
read(file: string): Promise<Buffer>;
|
|
50
|
+
};
|
|
51
|
+
export declare function code(file: string, deps: SourceFiles, format?: 'esm'): Promise<string>;
|
|
52
|
+
export declare function reexports(source: string): RegExpExecArray[] | undefined;
|
|
53
|
+
/** Isolate initialization and re-export wiring without running the module. */
|
|
54
|
+
export declare function moduleEffects(file: string, deps: SourceFiles): Promise<{
|
|
55
|
+
initializes: boolean;
|
|
56
|
+
exports: string[];
|
|
57
|
+
defaultOnly: boolean;
|
|
58
|
+
} | undefined>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isBuiltin } from 'node:module';
|
|
2
2
|
import { dirname, extname, join } from 'node:path';
|
|
3
|
-
import { build } from 'esbuild';
|
|
3
|
+
import { build, transform } from 'esbuild';
|
|
4
|
+
import { inProse, tokenize } from './milestone-tokens.js';
|
|
4
5
|
import { catalogForWalk } from './snapshot-catalog.js';
|
|
5
6
|
export const loaders = {
|
|
6
7
|
'.ts': 'ts',
|
|
@@ -47,7 +48,18 @@ function projectCatalog(builder, route, catalog, project) {
|
|
|
47
48
|
});
|
|
48
49
|
}
|
|
49
50
|
function metroWeb(builder, dir) {
|
|
50
|
-
|
|
51
|
+
// The stock Metro resolver gives the app one copy of each of its React singletons.
|
|
52
|
+
builder.onResolve({
|
|
53
|
+
filter: /^(?:react|react-dom|react-native|react-native-web|react-native-unistyles|react-native-svg)(?:\/|$)/,
|
|
54
|
+
}, ({ path, kind, pluginData }) => {
|
|
55
|
+
if (pluginData === metroEmpty)
|
|
56
|
+
return;
|
|
57
|
+
return builder.resolve(path === 'react-native' ? 'react-native-web' : path, {
|
|
58
|
+
kind,
|
|
59
|
+
resolveDir: dir,
|
|
60
|
+
pluginData: metroEmpty,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
51
63
|
// Stock Metro stubs Node builtins on the web when there is no browser implementation.
|
|
52
64
|
builder.onResolve({ filter: /^node:/ }, ({ path }) => {
|
|
53
65
|
if (isBuiltin(path))
|
|
@@ -76,12 +88,12 @@ function surfacePlugin(catalog, entry, read, unproven) {
|
|
|
76
88
|
};
|
|
77
89
|
}
|
|
78
90
|
export function bundleSurface(root, catalog, entry, read, unproven) {
|
|
79
|
-
const { surface, registry, roots } = entry;
|
|
91
|
+
const { surface, registry, roots, routes } = entry;
|
|
80
92
|
const app = surface === 'app';
|
|
81
93
|
return build({
|
|
82
94
|
absWorkingDir: root,
|
|
83
95
|
stdin: {
|
|
84
|
-
contents: [registry, ...roots]
|
|
96
|
+
contents: [...new Set([registry, ...roots, ...routes])]
|
|
85
97
|
.map((file, index) => `export * as __snapshotRoot${index} from ${JSON.stringify(file)};`)
|
|
86
98
|
.join('\n'),
|
|
87
99
|
resolveDir: root,
|
|
@@ -89,10 +101,13 @@ export function bundleSurface(root, catalog, entry, read, unproven) {
|
|
|
89
101
|
bundle: true,
|
|
90
102
|
format: 'esm',
|
|
91
103
|
platform: 'browser',
|
|
92
|
-
conditions: app ? [
|
|
93
|
-
mainFields: app
|
|
104
|
+
conditions: app ? [] : ['development', 'module'],
|
|
105
|
+
mainFields: app
|
|
106
|
+
? ['browser', 'module', 'main']
|
|
107
|
+
: ['browser', 'module', 'jsnext:main', 'jsnext', 'main'],
|
|
94
108
|
define: { 'import.meta.env.DEV': 'true', __DEV__: 'true' },
|
|
95
109
|
jsx: 'automatic',
|
|
110
|
+
jsxDev: !app,
|
|
96
111
|
ignoreAnnotations: true,
|
|
97
112
|
loader: loaders,
|
|
98
113
|
logLevel: 'silent',
|
|
@@ -106,7 +121,54 @@ export function bundleSurface(root, catalog, entry, read, unproven) {
|
|
|
106
121
|
plugins: [surfacePlugin(catalog, entry, read, unproven)],
|
|
107
122
|
resolveExtensions: app
|
|
108
123
|
? ['.web.tsx', '.web.ts', '.web.jsx', '.web.js', '.tsx', '.ts', '.jsx', '.js', '.json']
|
|
109
|
-
:
|
|
124
|
+
: ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json'],
|
|
110
125
|
write: false,
|
|
111
126
|
});
|
|
112
127
|
}
|
|
128
|
+
export async function code(file, deps, format) {
|
|
129
|
+
return (await transform((await deps.read(file)).toString('utf8'), {
|
|
130
|
+
loader: loaders[extname(file).toLowerCase()],
|
|
131
|
+
jsx: 'preserve',
|
|
132
|
+
...(format ? { format } : {}),
|
|
133
|
+
})).code;
|
|
134
|
+
}
|
|
135
|
+
// esbuild prints top-level import and export declarations at column zero. Check token ranges
|
|
136
|
+
// too: identical lines inside a template literal are not declarations.
|
|
137
|
+
export function reexports(source) {
|
|
138
|
+
const tokens = tokenize(source, true);
|
|
139
|
+
if (!tokens)
|
|
140
|
+
return;
|
|
141
|
+
const pattern = /^export (\*|\{[\w$\s,]+}) from ("[^"\\\n]+");$/gm;
|
|
142
|
+
return [...source.matchAll(pattern)].filter(({ index }) => !inProse(tokens.prose, index));
|
|
143
|
+
}
|
|
144
|
+
/** Isolate initialization and re-export wiring without running the module. */
|
|
145
|
+
export async function moduleEffects(file, deps) {
|
|
146
|
+
const source = await code(file, deps, 'esm');
|
|
147
|
+
const original = (await deps.read(file)).toString('utf8');
|
|
148
|
+
const named = /\bexport\s*[{*]/.test(original) ? reexports(await code(file, deps)) : [];
|
|
149
|
+
const stars = reexports(source);
|
|
150
|
+
if (!named || !stars)
|
|
151
|
+
return;
|
|
152
|
+
const tokens = tokenize(source, true);
|
|
153
|
+
if (!tokens)
|
|
154
|
+
return;
|
|
155
|
+
const list = [...source.matchAll(/^export \{[\w$\s,]+};$/gm)].filter(({ index }) => !inProse(tokens.prose, index));
|
|
156
|
+
const body = source.split('');
|
|
157
|
+
for (const { index, 0: statement } of [...stars, ...list])
|
|
158
|
+
body.fill(' ', index, index + statement.length);
|
|
159
|
+
const { code: effects } = await transform(body.join(''), {
|
|
160
|
+
loader: 'jsx',
|
|
161
|
+
jsx: 'transform',
|
|
162
|
+
treeShaking: true,
|
|
163
|
+
ignoreAnnotations: true,
|
|
164
|
+
minifySyntax: true,
|
|
165
|
+
});
|
|
166
|
+
// A retained directive, declaration, or instruction is a shared effect.
|
|
167
|
+
return {
|
|
168
|
+
initializes: effects.split('\n').some((line) => !!line && !line.startsWith('import ')),
|
|
169
|
+
exports: [...named, ...list].map(([statement]) => statement),
|
|
170
|
+
defaultOnly: !named.length &&
|
|
171
|
+
list.length === 1 &&
|
|
172
|
+
/^export \{\s+[\w$]+ as default\s+};$/.test(list[0]?.[0] ?? ''),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* The code that draws and checks a scene, that proves its requests and decides its file set, and
|
|
4
|
+
* the words its findings use: in every fingerprint, so a change to any of them redraws every scene.
|
|
5
|
+
*/
|
|
6
|
+
const checks = [
|
|
7
|
+
'browser',
|
|
8
|
+
'checks',
|
|
9
|
+
'fonts',
|
|
10
|
+
'font-samples',
|
|
11
|
+
'full-shot',
|
|
12
|
+
'measure',
|
|
13
|
+
'media-ready',
|
|
14
|
+
'messages',
|
|
15
|
+
'messages.en',
|
|
16
|
+
'module-errors',
|
|
17
|
+
'readable',
|
|
18
|
+
'scene',
|
|
19
|
+
'scene-check',
|
|
20
|
+
'scene-load',
|
|
21
|
+
'scene-look',
|
|
22
|
+
'scene-ready',
|
|
23
|
+
'scene-render',
|
|
24
|
+
'snapshot-bundle',
|
|
25
|
+
'snapshot-dependencies',
|
|
26
|
+
'snapshot-inputs',
|
|
27
|
+
'snapshot-metro-inputs',
|
|
28
|
+
'snapshot-recovery',
|
|
29
|
+
'snapshot-registry',
|
|
30
|
+
'snapshot-requests',
|
|
31
|
+
'snapshot-scene-inputs',
|
|
32
|
+
'snapshot-served-inputs',
|
|
33
|
+
'snapshot-surface-inputs',
|
|
34
|
+
'snapshot-themes',
|
|
35
|
+
'snapshot-vite-inputs',
|
|
36
|
+
];
|
|
37
|
+
/** The files of `checks`, beside this one. */
|
|
38
|
+
export function sceneCheckFiles() {
|
|
39
|
+
const extension = import.meta.url.endsWith('.ts') ? '.ts' : '.js';
|
|
40
|
+
return [...checks.map((name) => name + extension), 'drawn-text.js'].map((file) => join(import.meta.dirname, file));
|
|
41
|
+
}
|
|
@@ -11,6 +11,8 @@ export interface SnapshotFlags extends Pick<SetupFlags, 'ownFirst'> {
|
|
|
11
11
|
remake?: boolean;
|
|
12
12
|
/** Scene pages open at once, 1 to 4 (`--pages`); unset, the cores and the free memory say. */
|
|
13
13
|
pages?: number;
|
|
14
|
+
/** `--full`: every theme, mode and pseudo-locale, not only the floor (S3b). */
|
|
15
|
+
full?: boolean;
|
|
14
16
|
json?: boolean;
|
|
15
17
|
}
|
|
16
18
|
/** `ape prototype snapshot`: needs `ape dev` running. Fails (exit 1) when a check fails. */
|
|
@@ -10,6 +10,7 @@ import { readModel } from './data.js';
|
|
|
10
10
|
import { MAX_SHOT_HEIGHT } from './full-shot.js';
|
|
11
11
|
import { number, t } from './messages.js';
|
|
12
12
|
import { newestReport, renderRetries, requireCommitted, shortCommit, unsavedWork, } from './report.js';
|
|
13
|
+
import { cliSelector } from './selector-run.js';
|
|
13
14
|
import { remakeScreenshots, takeSnapshot } from './snapshot.js';
|
|
14
15
|
import { SnapshotAccessRefused } from './snapshot-refused.js';
|
|
15
16
|
import { requireServers, setup, } from './snapshot-setup.js';
|
|
@@ -91,6 +92,8 @@ async function taken(run, commit, onFallback) {
|
|
|
91
92
|
// Asked again after the scenes are drawn: an edit made while they were drawn counts too.
|
|
92
93
|
dirty: () => unsaved || unsavedWork(root),
|
|
93
94
|
runId: runId && /^[a-f0-9-]{36}$/.test(runId) ? runId : undefined,
|
|
95
|
+
// Fresh, read-only agent turns pick looks beyond the floor (S3c); never the turn running this.
|
|
96
|
+
selector: cliSelector(root),
|
|
94
97
|
artifacts: { 'data.json': model, ...(design ? { 'design.json': design } : {}) },
|
|
95
98
|
});
|
|
96
99
|
}
|