@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,140 @@
|
|
|
1
|
+
// `ape prototype prune`: committed snapshot folders under `prototype/snapshots/` that no version
|
|
2
|
+
// names are dead weight (about 2 MB of data each), and git keeps them in history. Prune removes
|
|
3
|
+
// them from the working tree; the person commits the deletion. It keeps every folder a record in
|
|
4
|
+
// `prototype/versions/` (or `design/approval.json`) names by its source commit or its report's
|
|
5
|
+
// fingerprint, the newest committed snapshot, HEAD's, any folder with unsaved changes, and `comp/`.
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { existsSync, readdirSync, readFileSync, rmSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import { pruneText } from './prune-words.js';
|
|
10
|
+
import { git, gitBytes, snapshotsDir } from './report.js';
|
|
11
|
+
const SNAPSHOTS = 'prototype/snapshots/';
|
|
12
|
+
const HASH = /^[0-9a-f]{7,40}$/;
|
|
13
|
+
/** The commit-named folders git tracks under `prototype/snapshots/` (never `comp/`). */
|
|
14
|
+
function committedFolders(root) {
|
|
15
|
+
const listed = gitBytes(root, ['ls-files', '-z', '--', SNAPSHOTS]).toString('utf8');
|
|
16
|
+
const folders = new Set();
|
|
17
|
+
for (const path of listed.split('\0')) {
|
|
18
|
+
const [folder, file] = path.slice(SNAPSHOTS.length).split('/');
|
|
19
|
+
if (path.startsWith(SNAPSHOTS) && folder && file && HASH.test(folder))
|
|
20
|
+
folders.add(folder);
|
|
21
|
+
}
|
|
22
|
+
return [...folders].sort();
|
|
23
|
+
}
|
|
24
|
+
/** Every `commit` and `report` string anywhere in a record. */
|
|
25
|
+
function collect(value, into) {
|
|
26
|
+
if (Array.isArray(value))
|
|
27
|
+
for (const item of value)
|
|
28
|
+
collect(item, into);
|
|
29
|
+
else if (value && typeof value === 'object')
|
|
30
|
+
for (const [key, item] of Object.entries(value)) {
|
|
31
|
+
if (key === 'commit' && typeof item === 'string')
|
|
32
|
+
into.commits.add(item.toLowerCase());
|
|
33
|
+
else if (key === 'report' && typeof item === 'string')
|
|
34
|
+
into.reports.add(item);
|
|
35
|
+
else
|
|
36
|
+
collect(item, into);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** The JSON files under a folder, at any depth. */
|
|
40
|
+
function jsonFiles(dir) {
|
|
41
|
+
if (!existsSync(dir))
|
|
42
|
+
return [];
|
|
43
|
+
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
44
|
+
const path = join(dir, entry.name);
|
|
45
|
+
if (entry.isDirectory())
|
|
46
|
+
return jsonFiles(path);
|
|
47
|
+
return entry.name.endsWith('.json') ? [path] : [];
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/** What the records name: source commits and report fingerprints. A record that won't parse refuses. */
|
|
51
|
+
function references(root) {
|
|
52
|
+
const into = { commits: new Set(), reports: new Set() };
|
|
53
|
+
const files = jsonFiles(join(root, 'prototype', 'versions'));
|
|
54
|
+
const approval = join(root, 'design', 'approval.json');
|
|
55
|
+
if (existsSync(approval))
|
|
56
|
+
files.push(approval);
|
|
57
|
+
for (const file of files) {
|
|
58
|
+
try {
|
|
59
|
+
collect(JSON.parse(readFileSync(file, 'utf8')), into);
|
|
60
|
+
}
|
|
61
|
+
catch (cause) {
|
|
62
|
+
throw new Error(pruneText('prune.unreadable', { file }), { cause });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return into;
|
|
66
|
+
}
|
|
67
|
+
const readReport = (root, folder) => {
|
|
68
|
+
try {
|
|
69
|
+
return readFileSync(join(snapshotsDir(root), folder, 'report.json'));
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const createdAt = (bytes) => {
|
|
76
|
+
try {
|
|
77
|
+
const at = JSON.parse(bytes?.toString('utf8') ?? '').createdAt;
|
|
78
|
+
return typeof at === 'string' ? at : '';
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return '';
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
/** The folders under `prototype/snapshots/` with unsaved changes, as `git status` lists them. */
|
|
85
|
+
function unsavedFolders(root) {
|
|
86
|
+
const status = gitBytes(root, [
|
|
87
|
+
'status',
|
|
88
|
+
'--porcelain=v1',
|
|
89
|
+
'-z',
|
|
90
|
+
'--no-renames',
|
|
91
|
+
'--',
|
|
92
|
+
SNAPSHOTS,
|
|
93
|
+
]);
|
|
94
|
+
const prefix = `${git(root, ['rev-parse', '--show-prefix'])}${SNAPSHOTS}`;
|
|
95
|
+
const folders = new Set();
|
|
96
|
+
for (const entry of status.toString('utf8').split('\0')) {
|
|
97
|
+
const path = entry.slice(3);
|
|
98
|
+
if (path.startsWith(prefix))
|
|
99
|
+
folders.add(path.slice(prefix.length).split('/')[0] ?? '');
|
|
100
|
+
}
|
|
101
|
+
return folders;
|
|
102
|
+
}
|
|
103
|
+
/** Remove (or, with `dryRun`, list) the committed snapshot folders nothing needs. */
|
|
104
|
+
export function pruneSnapshots(root, { dryRun = false } = {}) {
|
|
105
|
+
const folders = committedFolders(root);
|
|
106
|
+
const { commits, reports } = references(root);
|
|
107
|
+
const head = git(root, ['rev-parse', 'HEAD']).toLowerCase();
|
|
108
|
+
const unsaved = unsavedFolders(root);
|
|
109
|
+
const bytes = new Map(folders.map((folder) => [folder, readReport(root, folder)]));
|
|
110
|
+
const newest = [...folders].sort((a, b) => createdAt(bytes.get(b)).localeCompare(createdAt(bytes.get(a))))[0];
|
|
111
|
+
const named = (folder) => {
|
|
112
|
+
const report = bytes.get(folder);
|
|
113
|
+
const digest = report && createHash('sha256').update(report).digest('hex');
|
|
114
|
+
return ((digest !== undefined && reports.has(digest)) ||
|
|
115
|
+
[...commits].some((commit) => commit.startsWith(folder) || folder.startsWith(commit)));
|
|
116
|
+
};
|
|
117
|
+
const because = (folder) => {
|
|
118
|
+
if (named(folder))
|
|
119
|
+
return 'version';
|
|
120
|
+
if (head.startsWith(folder))
|
|
121
|
+
return 'head';
|
|
122
|
+
if (unsaved.has(folder))
|
|
123
|
+
return 'unsaved';
|
|
124
|
+
if (folder === newest)
|
|
125
|
+
return 'newest';
|
|
126
|
+
return undefined;
|
|
127
|
+
};
|
|
128
|
+
const result = { ok: true, dryRun, removed: [], kept: [] };
|
|
129
|
+
for (const folder of folders) {
|
|
130
|
+
const kept = because(folder);
|
|
131
|
+
if (kept)
|
|
132
|
+
result.kept.push({ folder, because: kept });
|
|
133
|
+
else
|
|
134
|
+
result.removed.push(folder);
|
|
135
|
+
}
|
|
136
|
+
if (!dryRun)
|
|
137
|
+
for (const folder of result.removed)
|
|
138
|
+
rmSync(join(snapshotsDir(root), folder), { recursive: true, force: true });
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const en: {
|
|
2
|
+
'reopen.none': string;
|
|
3
|
+
'reopen.help': string;
|
|
4
|
+
'reopen.done': string;
|
|
5
|
+
'reopen.aiMark': string;
|
|
6
|
+
'reopen.host': string;
|
|
7
|
+
};
|
|
8
|
+
export declare const reopenT: (key: keyof typeof en, values?: Record<string, unknown>) => string;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Words for reopening an AI approval (S4), in English and Spanish.
|
|
2
|
+
import { createI18n } from '@buffcore/i18n';
|
|
3
|
+
import { locale } from './messages.js';
|
|
4
|
+
const en = {
|
|
5
|
+
'reopen.none': '{change} has no AI approval to reopen.',
|
|
6
|
+
'reopen.help': 'Reopen an AI approval so the version waits for a person (a person only)',
|
|
7
|
+
'reopen.done': '{change}: the AI approval is reopened; the version waits for a person.',
|
|
8
|
+
'reopen.aiMark': ' (approved by AI, a person may reopen it)',
|
|
9
|
+
'reopen.host': 'This host cannot reopen an AI approval from the studio. Ask whoever runs it.',
|
|
10
|
+
};
|
|
11
|
+
const es = {
|
|
12
|
+
'reopen.none': '{change} no tiene una aprobación de IA que reabrir.',
|
|
13
|
+
'reopen.help': 'Reabre una aprobación de IA para que la versión espere a una persona (solo una persona)',
|
|
14
|
+
'reopen.done': '{change}: la aprobación de IA está reabierta; la versión espera a una persona.',
|
|
15
|
+
'reopen.aiMark': ' (aprobada por IA, una persona puede reabrirla)',
|
|
16
|
+
'reopen.host': 'Este servidor no puede reabrir una aprobación de IA desde el estudio. Pregunta a quien lo gestiona.',
|
|
17
|
+
};
|
|
18
|
+
const translator = createI18n({ catalogs: [{ en, es }] });
|
|
19
|
+
export const reopenT = (key, values) => translator.t(locale(), key, values);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Frame, Surface } from '@buffcore/config';
|
|
2
2
|
import type { PrototypeProblem } from '@buffcore/contracts/prototype';
|
|
3
3
|
import type { LoadFailure } from './scene-errors.ts';
|
|
4
|
+
import type { SelectorRecord } from './selector.ts';
|
|
5
|
+
import type { Matrix, MatrixReason } from './snapshot-matrix.ts';
|
|
4
6
|
export interface SnapshotHint {
|
|
5
7
|
scene: string;
|
|
6
8
|
theme: string;
|
|
@@ -32,6 +34,14 @@ export interface SnapshotReport {
|
|
|
32
34
|
api?: 'stand-in';
|
|
33
35
|
themes: string[];
|
|
34
36
|
locales: string[];
|
|
37
|
+
/** The looks the run drew (S3b): absent in an older report, which drew the full matrix. */
|
|
38
|
+
matrix?: Matrix;
|
|
39
|
+
/** Why it drew them: the default, `--full`, or a shared input changed since the last full report. */
|
|
40
|
+
matrixReason?: MatrixReason;
|
|
41
|
+
/** The shared inputs (F113c) of the last full report: this one's own when it is full. */
|
|
42
|
+
fullInputs?: string;
|
|
43
|
+
/** The selector's turns, picks with reasons, drops, or why it didn't run (S3c); absent: not asked. */
|
|
44
|
+
selector?: SelectorRecord;
|
|
35
45
|
scenes: {
|
|
36
46
|
key: string;
|
|
37
47
|
title: string;
|
|
@@ -56,6 +66,10 @@ export interface SnapshotReport {
|
|
|
56
66
|
scriptError?: LoadFailure;
|
|
57
67
|
/** The ancestor snapshot's folder (its source commit). */
|
|
58
68
|
reusedFrom?: string;
|
|
69
|
+
/** The looks this scene was drawn in (a reused scene keeps its own); absent: full. */
|
|
70
|
+
matrix?: Matrix;
|
|
71
|
+
/** The looks the selector added beyond the floor for this scene (S3c), `<theme>.<mode>.<locale>`. */
|
|
72
|
+
extraLooks?: string[];
|
|
59
73
|
}[];
|
|
60
74
|
/** The ancestor commit that holds the exact report used for every reused scene. */
|
|
61
75
|
reuseReport?: string;
|
|
@@ -5,6 +5,7 @@ import { existsSync } from 'node:fs';
|
|
|
5
5
|
import { readdir, readFile } from 'node:fs/promises';
|
|
6
6
|
import { join } from 'node:path';
|
|
7
7
|
import { hostGitBytes } from '../safe-git.js';
|
|
8
|
+
import { MISSES_FILE } from './selector-misses.js';
|
|
8
9
|
import { recoverSnapshots } from './snapshot-storage.js';
|
|
9
10
|
/** The scenes drawn again after a render error (a timeout leaves no line). */
|
|
10
11
|
export const renderRetries = (scenes) => scenes.flatMap(({ key, retryError }) => (retryError ? [{ scene: key, error: retryError }] : []));
|
|
@@ -58,7 +59,10 @@ export function unsavedEntries(dir, output) {
|
|
|
58
59
|
return gitBytes(dir, ['status', '--porcelain=v1', '-z', '--untracked-files=all', '--no-renames'])
|
|
59
60
|
.toString('utf8')
|
|
60
61
|
.split('\0')
|
|
61
|
-
.filter((entry) => entry !== '' &&
|
|
62
|
+
.filter((entry) => entry !== '' &&
|
|
63
|
+
!(entry.startsWith('?? ') && entry.slice(3).startsWith(output)) &&
|
|
64
|
+
// The selector's misses (S3c) are learning, not work: committed or not, never unsaved.
|
|
65
|
+
entry.slice(3) !== `${output}${MISSES_FILE}`);
|
|
62
66
|
}
|
|
63
67
|
/** Refuse uncommitted changes: what follows must match the commit checked out. */
|
|
64
68
|
export function requireCommitted(dir, why) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { LayoutException, Scene } from '@buffcore/config';
|
|
2
|
+
import type { Theme } from '@buffcore/tokens';
|
|
3
|
+
import type { Page } from 'playwright-core';
|
|
4
|
+
import { type LayoutFinding } from './layout-hints.ts';
|
|
5
|
+
import type { SnapshotHint } from './report.ts';
|
|
6
|
+
/** A scene's layout hints in the report, at most: past this, its layout wants a look as a whole. */
|
|
7
|
+
export declare const MAX_LAYOUT_HINTS = 20;
|
|
8
|
+
/** True when the scene marks this finding as meant. */
|
|
9
|
+
export declare function setAside(finding: LayoutFinding, exceptions?: readonly LayoutException[]): boolean;
|
|
10
|
+
/** The finding in the reader's words. */
|
|
11
|
+
export declare function layoutDetail(scene: string, finding: LayoutFinding): string;
|
|
12
|
+
/** Measure the page as it shows `look` and add its new layout hints to the scene's `hints`. */
|
|
13
|
+
export declare function addLayoutHints(page: Page, scene: Scene, theme: Theme | undefined, look: {
|
|
14
|
+
theme: string;
|
|
15
|
+
mode: string;
|
|
16
|
+
locale: string;
|
|
17
|
+
}, hints: SnapshotHint[]): Promise<void>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { layoutFindings, spacingSteps } from './layout-hints.js';
|
|
2
|
+
import { measureLayout } from './layout-measure.js';
|
|
3
|
+
import { layoutText } from './layout-words.js';
|
|
4
|
+
import { number } from './messages.js';
|
|
5
|
+
/** A scene's layout hints in the report, at most: past this, its layout wants a look as a whole. */
|
|
6
|
+
export const MAX_LAYOUT_HINTS = 20;
|
|
7
|
+
/** True when the scene marks this finding as meant. */
|
|
8
|
+
export function setAside(finding, exceptions = []) {
|
|
9
|
+
const names = [finding.element, 'other' in finding ? finding.other : ''];
|
|
10
|
+
return exceptions.some((one) => one.kind === finding.kind &&
|
|
11
|
+
(!one.element || names.some((n) => n.includes(one.element ?? ''))));
|
|
12
|
+
}
|
|
13
|
+
/** The finding in the reader's words. */
|
|
14
|
+
export function layoutDetail(scene, finding) {
|
|
15
|
+
switch (finding.kind) {
|
|
16
|
+
case 'overlap':
|
|
17
|
+
return layoutText('layout.overlap', {
|
|
18
|
+
scene,
|
|
19
|
+
element: finding.element,
|
|
20
|
+
other: finding.other,
|
|
21
|
+
width: number(finding.width),
|
|
22
|
+
height: number(finding.height),
|
|
23
|
+
});
|
|
24
|
+
case 'edge':
|
|
25
|
+
return layoutText('layout.edge', {
|
|
26
|
+
scene,
|
|
27
|
+
element: finding.element,
|
|
28
|
+
offset: number(finding.offset),
|
|
29
|
+
count: number(finding.count),
|
|
30
|
+
});
|
|
31
|
+
case 'padding':
|
|
32
|
+
return layoutText('layout.padding', { scene, ...finding, count: number(finding.count) });
|
|
33
|
+
case 'gap':
|
|
34
|
+
return layoutText('layout.gap', {
|
|
35
|
+
scene,
|
|
36
|
+
...finding,
|
|
37
|
+
gap: number(finding.gap),
|
|
38
|
+
value: number(finding.value),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Measure the page as it shows `look` and add its new layout hints to the scene's `hints`. */
|
|
43
|
+
export async function addLayoutHints(page, scene, theme, look, hints) {
|
|
44
|
+
if (!theme)
|
|
45
|
+
return;
|
|
46
|
+
const boxes = JSON.parse(await page.evaluate(measureLayout));
|
|
47
|
+
const scale = scene.surface === 'app' ? (scene.scale ?? 1) : 1;
|
|
48
|
+
for (const finding of layoutFindings(boxes, spacingSteps(theme.space, scale))) {
|
|
49
|
+
if (hints.length >= MAX_LAYOUT_HINTS)
|
|
50
|
+
return;
|
|
51
|
+
if (setAside(finding, scene.layoutExceptions))
|
|
52
|
+
continue;
|
|
53
|
+
const detail = layoutDetail(scene.key, finding);
|
|
54
|
+
if (!hints.some((hint) => hint.detail === detail))
|
|
55
|
+
hints.push({ scene: scene.key, ...look, detail });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -75,8 +75,14 @@ const ANIMATION_WAIT = 2_000;
|
|
|
75
75
|
* focus ring. True when fonts or pictures were still loading as their allowance ran out.
|
|
76
76
|
*/
|
|
77
77
|
async function drawn(frame, locale, live, { animationWait, mediaWait, readyWait, onMedia }) {
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
// A lazy view still loading (`data-prototype-pending`) has not drawn yet.
|
|
79
|
+
await frame.waitForFunction((lang) => {
|
|
80
|
+
const root = document.getElementById('root');
|
|
81
|
+
return (document.documentElement.lang === lang &&
|
|
82
|
+
!!root &&
|
|
83
|
+
root.childElementCount > 0 &&
|
|
84
|
+
!root.querySelector('[data-prototype-pending]'));
|
|
85
|
+
}, locale, readyWait === undefined ? undefined : { timeout: readyWait });
|
|
80
86
|
// An attempt that lost its page (a module failed, the page loaded again) does nothing more.
|
|
81
87
|
if (!live())
|
|
82
88
|
return false;
|
|
@@ -6,8 +6,10 @@ import { type browserSession } from './browser.ts';
|
|
|
6
6
|
import type { SnapshotHint } from './report.ts';
|
|
7
7
|
import type { LoadFailure } from './scene-errors.ts';
|
|
8
8
|
import { type FallbackCounter } from './scene-look.ts';
|
|
9
|
+
import type { SelectorRecord } from './selector.ts';
|
|
10
|
+
import { type Matrix, type MatrixReason } from './snapshot-matrix.ts';
|
|
9
11
|
import type { SnapshotProgress } from './snapshot-progress.ts';
|
|
10
|
-
import { type SceneRequestFacts } from './snapshot-requests.ts';
|
|
12
|
+
import { type RequestCoverage, type SceneRequestFacts } from './snapshot-requests.ts';
|
|
11
13
|
import { lookKey, photographed } from './snapshot-themes.ts';
|
|
12
14
|
export { lookKey, photographed };
|
|
13
15
|
/** What every scene of one snapshot shares. */
|
|
@@ -33,10 +35,19 @@ export interface Run {
|
|
|
33
35
|
session?: ReturnType<typeof browserSession> | undefined;
|
|
34
36
|
requests?: SceneRequestFacts;
|
|
35
37
|
onFallback?: FallbackCounter | undefined;
|
|
36
|
-
|
|
38
|
+
coversRequest?: RequestCoverage | undefined;
|
|
37
39
|
saveScene?: SnapshotProgress['draw'] | undefined;
|
|
38
40
|
/** The first full-run scene on each surface, even when that scene has already finished. */
|
|
39
41
|
warmScenes?: ReadonlySet<string> | undefined;
|
|
42
|
+
/** The looks drawn (`snapshot-matrix.ts`); unset, the full matrix. */
|
|
43
|
+
matrix?: Matrix | undefined;
|
|
44
|
+
/** Why, and the shared inputs of the last full report, for `report.json`. */
|
|
45
|
+
matrixReason?: MatrixReason | undefined;
|
|
46
|
+
fullInputs?: string | undefined;
|
|
47
|
+
/** The selector (S3c): its record, the scenes it drew again and the looks it added, by scene. */
|
|
48
|
+
selector?: SelectorRecord | undefined;
|
|
49
|
+
redraw?: ReadonlySet<string> | undefined;
|
|
50
|
+
extraLooks?: ReadonlyMap<string, ReadonlySet<string>> | undefined;
|
|
40
51
|
/** Only the screenshots, no checks: `--remake` making a committed report's screenshots again. */
|
|
41
52
|
photosOnly?: boolean;
|
|
42
53
|
/** How a server the run started itself ended, if it has: read before `.ape/dev.json`. */
|
|
@@ -63,6 +74,8 @@ interface Found {
|
|
|
63
74
|
cut: string[];
|
|
64
75
|
problems: PrototypeProblem[];
|
|
65
76
|
hints: SnapshotHint[];
|
|
77
|
+
/** Layout hints (`scene-layout.ts`), apart from the font advice a late scene drops. */
|
|
78
|
+
layout?: SnapshotHint[];
|
|
66
79
|
/** The color pairs already reported, by theme and mode. */
|
|
67
80
|
pairs: Set<string>;
|
|
68
81
|
}
|
|
@@ -12,9 +12,11 @@ import { MEDIA_WAIT } from './media-ready.js';
|
|
|
12
12
|
import { t } from './messages.js';
|
|
13
13
|
import { describe, readText } from './readable.js';
|
|
14
14
|
import { freshLoadsAgree, lookEvidence } from './scene-check.js';
|
|
15
|
+
import { addLayoutHints } from './scene-layout.js';
|
|
15
16
|
import { LookMoveFailed, sceneLookLoader } from './scene-look.js';
|
|
16
17
|
import { renderScene, requireNoErrorOverlay, SceneTimeoutError } from './scene-render.js';
|
|
17
|
-
import {
|
|
18
|
+
import { drawnLooks } from './snapshot-matrix.js';
|
|
19
|
+
import { sceneRequests, settleRequests, } from './snapshot-requests.js';
|
|
18
20
|
import { shotName } from './snapshot-shots.js';
|
|
19
21
|
import { lookKey, photographed } from './snapshot-themes.js';
|
|
20
22
|
export { lookKey, photographed };
|
|
@@ -23,15 +25,20 @@ const LATE_WAIT = 1_000;
|
|
|
23
25
|
/** Open the first look so the surface can finish its cold build. */
|
|
24
26
|
export async function warmSurface(browser, scene, run, signal) {
|
|
25
27
|
await renderScene(browser, run.frames[scene.frame], scene.key, run.sceneTimeout, async (page) => {
|
|
26
|
-
|
|
27
|
-
sceneRequests(page, run, scene);
|
|
28
|
+
const requests = run.requests && sceneRequests(page, run, scene);
|
|
28
29
|
const look = { theme: run.product, mode: 'light', locale: run.first };
|
|
29
30
|
await openScene(page, sceneUrl(run.urls[scene.surface], scene.key, look), run.first);
|
|
31
|
+
await requests?.finish();
|
|
30
32
|
}, signal, run);
|
|
31
33
|
}
|
|
34
|
+
/** The facts a scene attempt has drawn with: a second attempt (a retry) is not tracked. */
|
|
35
|
+
const attempts = new WeakSet();
|
|
32
36
|
/** One scene in every theme, mode and language: its screenshots and its problems. */
|
|
33
37
|
export async function snapScene(browser, scene, run, signal) {
|
|
34
38
|
const requests = run.requests ?? { apiCalls: false, untrackedRequests: false };
|
|
39
|
+
if (attempts.has(requests))
|
|
40
|
+
requests.untrackedRequests = true;
|
|
41
|
+
attempts.add(requests);
|
|
35
42
|
const attempt = { ...run, requests };
|
|
36
43
|
let moved = false;
|
|
37
44
|
let started = performance.now();
|
|
@@ -56,13 +63,16 @@ export async function snapScene(browser, scene, run, signal) {
|
|
|
56
63
|
// Something an earlier look left behind changed a checked one: draw every look fresh.
|
|
57
64
|
run.onFallback?.('scene');
|
|
58
65
|
const { checks: _, ...fresh } = await drawScene(browser, scene, attempt, signal);
|
|
66
|
+
await settleRequests(requests);
|
|
59
67
|
return { ...fresh, ...requests };
|
|
60
68
|
}
|
|
69
|
+
// Every load's requests, check loads included, are checked against the scene's fingerprint.
|
|
70
|
+
await settleRequests(requests);
|
|
61
71
|
return { ...drawn, ...requests };
|
|
62
72
|
}
|
|
63
73
|
function drawScene(browser, scene, run, signal, onMove) {
|
|
64
74
|
return renderScene(browser, run.frames[scene.frame], scene.key, run.sceneTimeout, async (page, advise) => {
|
|
65
|
-
sceneRequests(page, run, scene);
|
|
75
|
+
const requests = sceneRequests(page, run, scene);
|
|
66
76
|
let moves = 0;
|
|
67
77
|
const show = sceneLookLoader(page, onMove && run.onFallback, Boolean(onMove), () => {
|
|
68
78
|
moves++;
|
|
@@ -85,45 +95,41 @@ function drawScene(browser, scene, run, signal, onMove) {
|
|
|
85
95
|
const declared = run.photosOnly
|
|
86
96
|
? undefined
|
|
87
97
|
: run.looks.find((theme) => theme.key === run.fontTheme);
|
|
88
|
-
for (const theme of run.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
seconds: MEDIA_WAIT / 1000,
|
|
109
|
-
}),
|
|
110
|
-
});
|
|
111
|
-
await checkLook(page, look, run, found).catch((error) => {
|
|
112
|
-
throw pageGone(error) ? new PageLoadError(String(error), { cause: error }) : error;
|
|
98
|
+
for (const { theme, mode, locale } of drawnLooks(run, scene.key)) {
|
|
99
|
+
const look = { theme: theme.key, mode, locale };
|
|
100
|
+
if (run.photosOnly && !(locale === run.first && photographed(theme.key, mode, run.product)))
|
|
101
|
+
continue;
|
|
102
|
+
const url = sceneUrl(run.urls[scene.surface], scene.key, look);
|
|
103
|
+
const mediaWait = late.length ? LATE_WAIT : undefined;
|
|
104
|
+
const before = moves;
|
|
105
|
+
requests.look();
|
|
106
|
+
const lateNow = await show(url, locale, mediaWait);
|
|
107
|
+
last = { look, url, mediaWait, late: lateNow };
|
|
108
|
+
const photoMoved = moves > before && locale === run.first && photographed(theme.key, mode, run.product);
|
|
109
|
+
if (lateNow)
|
|
110
|
+
if (!late.length)
|
|
111
|
+
late.push({
|
|
112
|
+
scene: scene.key,
|
|
113
|
+
...look,
|
|
114
|
+
detail: t('prototype.mediaLate', {
|
|
115
|
+
scene: scene.key,
|
|
116
|
+
seconds: MEDIA_WAIT / 1000,
|
|
117
|
+
}),
|
|
113
118
|
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
await checkLook(page, look, run, found).catch((error) => {
|
|
120
|
+
throw pageGone(error) ? new PageLoadError(String(error), { cause: error }) : error;
|
|
121
|
+
});
|
|
122
|
+
if (photoMoved)
|
|
123
|
+
photo = { last, evidence: await lookEvidence(page, last, run, scene, checkLook) };
|
|
124
|
+
if (theme === declared) {
|
|
125
|
+
const details = await advise(async (timeLeft) => (await watchFonts(page, scene.key, theme)?.(timeLeft)) ?? []);
|
|
126
|
+
if (!details)
|
|
127
|
+
found.hints.length = 0;
|
|
128
|
+
else
|
|
129
|
+
for (const detail of details)
|
|
130
|
+
found.hints.push({ scene: scene.key, ...look, detail });
|
|
126
131
|
}
|
|
132
|
+
await requireNoErrorOverlay(page);
|
|
127
133
|
}
|
|
128
134
|
const { screenshots, cut, problems } = found;
|
|
129
135
|
// A scene with a look moved in place proves its last look against a fresh load, and its
|
|
@@ -134,7 +140,8 @@ function drawScene(browser, scene, run, signal, onMove) {
|
|
|
134
140
|
if (photo && photo.last !== last)
|
|
135
141
|
checks.push(photo);
|
|
136
142
|
}
|
|
137
|
-
|
|
143
|
+
const hints = [...found.hints, ...(found.layout ?? []), ...late];
|
|
144
|
+
return { screenshots, cut, problems, hints, checks };
|
|
138
145
|
}, signal, run);
|
|
139
146
|
}
|
|
140
147
|
/** The scene page as it shows one look: photographed when it is reviewed, and checked. */
|
|
@@ -159,6 +166,11 @@ export async function checkLook(page, look, run, found) {
|
|
|
159
166
|
const where = { surface, locale, first: run.first, data: found.data, intl: run.intl };
|
|
160
167
|
for (const [check, detail] of pageProblems(measured, where))
|
|
161
168
|
found.problems.push({ check, scene, theme, locale, detail });
|
|
169
|
+
// Layout doesn't change with the mode either; measured in the first language.
|
|
170
|
+
found.layout ??= [];
|
|
171
|
+
const shown = run.looks.find((t) => t.key === theme);
|
|
172
|
+
if (locale === run.first)
|
|
173
|
+
await addLayoutHints(page, found.scene, shown, look, found.layout);
|
|
162
174
|
}
|
|
163
175
|
// A theme can change a box's size, so what sticks out is looked for in every mode.
|
|
164
176
|
for (const detail of clippedEdges(measured.edges))
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** One turn's answer: at most 40 picks, each with a one-line reason. */
|
|
3
|
+
export declare const SelectorAnswer: z.ZodObject<{
|
|
4
|
+
picks: z.ZodArray<z.ZodObject<{
|
|
5
|
+
scene: z.ZodString;
|
|
6
|
+
look: z.ZodOptional<z.ZodString>;
|
|
7
|
+
reason: z.ZodString;
|
|
8
|
+
}, z.core.$strict>>;
|
|
9
|
+
}, z.core.$strict>;
|
|
10
|
+
export type SelectorAnswer = z.infer<typeof SelectorAnswer>;
|
|
11
|
+
export type SelectorTurnNumber = 1 | 2;
|
|
12
|
+
export interface SelectorPick {
|
|
13
|
+
scene: string;
|
|
14
|
+
look?: string;
|
|
15
|
+
reason: string;
|
|
16
|
+
turn: SelectorTurnNumber;
|
|
17
|
+
}
|
|
18
|
+
/** Why a pick was dropped: an unknown scene or look, a look the floor draws already, a repeat. */
|
|
19
|
+
export type DropReason = 'scene' | 'look' | 'floor' | 'repeat';
|
|
20
|
+
export interface SelectorDrop {
|
|
21
|
+
scene: string;
|
|
22
|
+
look?: string;
|
|
23
|
+
turn: SelectorTurnNumber;
|
|
24
|
+
why: DropReason;
|
|
25
|
+
}
|
|
26
|
+
/** The answer in a turn's final text (bare, or in a fenced block), or undefined when out of shape. */
|
|
27
|
+
export declare function parseAnswer(text: string | undefined): SelectorAnswer | undefined;
|
|
28
|
+
/** The scenes and looks a run may add: every scene's key, the matrix's looks and the floor's. */
|
|
29
|
+
export interface SelectorBounds {
|
|
30
|
+
scenes: ReadonlySet<string>;
|
|
31
|
+
looks: ReadonlySet<string>;
|
|
32
|
+
floor: ReadonlySet<string>;
|
|
33
|
+
}
|
|
34
|
+
/** Both turns' picks, kept in order; the second turn's repeats of the first are dropped. */
|
|
35
|
+
export declare function unionPicks(answers: readonly (SelectorAnswer | undefined)[], bounds: SelectorBounds): {
|
|
36
|
+
picks: SelectorPick[];
|
|
37
|
+
dropped: SelectorDrop[];
|
|
38
|
+
};
|
|
39
|
+
/** What the run draws beyond the floor: scenes drawn again, and each scene's added looks. */
|
|
40
|
+
export declare function extrasOf(picks: readonly SelectorPick[]): {
|
|
41
|
+
scenes: Set<string>;
|
|
42
|
+
looks: Map<string, Set<string>>;
|
|
43
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// The selector's answer (S3c): a fixed JSON shape, read at this edge with Zod, and the union of
|
|
2
|
+
// both turns' picks with the floor. A pick only adds: a scene to draw again in the floor, or a look
|
|
3
|
+
// beyond the floor for one scene. Anything outside the scene list or the matrix is dropped and noted.
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
/** One turn's answer: at most 40 picks, each with a one-line reason. */
|
|
6
|
+
export const SelectorAnswer = z
|
|
7
|
+
.object({
|
|
8
|
+
picks: z
|
|
9
|
+
.array(z
|
|
10
|
+
.object({
|
|
11
|
+
scene: z.string().min(1).max(100),
|
|
12
|
+
/** `<theme>.<mode>.<locale>`, one of the matrix's looks; absent: the scene in the floor. */
|
|
13
|
+
look: z.string().min(1).max(140).optional(),
|
|
14
|
+
reason: z.string().trim().min(1).max(200),
|
|
15
|
+
})
|
|
16
|
+
.strict())
|
|
17
|
+
.max(40),
|
|
18
|
+
})
|
|
19
|
+
.strict();
|
|
20
|
+
/** The answer in a turn's final text (bare, or in a fenced block), or undefined when out of shape. */
|
|
21
|
+
export function parseAnswer(text) {
|
|
22
|
+
if (!text)
|
|
23
|
+
return;
|
|
24
|
+
const start = text.indexOf('{');
|
|
25
|
+
const end = text.lastIndexOf('}');
|
|
26
|
+
if (start < 0 || end <= start)
|
|
27
|
+
return;
|
|
28
|
+
try {
|
|
29
|
+
const parsed = SelectorAnswer.safeParse(JSON.parse(text.slice(start, end + 1)));
|
|
30
|
+
return parsed.success ? parsed.data : undefined;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Both turns' picks, kept in order; the second turn's repeats of the first are dropped. */
|
|
37
|
+
export function unionPicks(answers, bounds) {
|
|
38
|
+
const picks = [];
|
|
39
|
+
const dropped = [];
|
|
40
|
+
const seen = new Set();
|
|
41
|
+
answers.forEach((answer, index) => {
|
|
42
|
+
const turn = (index + 1);
|
|
43
|
+
for (const { scene, look, reason } of answer?.picks ?? []) {
|
|
44
|
+
const where = { scene, ...(look ? { look } : {}), turn };
|
|
45
|
+
const key = JSON.stringify([scene, look ?? null]);
|
|
46
|
+
const why = !bounds.scenes.has(scene)
|
|
47
|
+
? 'scene'
|
|
48
|
+
: look !== undefined && !bounds.looks.has(look)
|
|
49
|
+
? 'look'
|
|
50
|
+
: look !== undefined && bounds.floor.has(look)
|
|
51
|
+
? 'floor'
|
|
52
|
+
: seen.has(key)
|
|
53
|
+
? 'repeat'
|
|
54
|
+
: undefined;
|
|
55
|
+
if (why)
|
|
56
|
+
dropped.push({ ...where, why });
|
|
57
|
+
else {
|
|
58
|
+
seen.add(key);
|
|
59
|
+
picks.push({ ...where, reason });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return { picks, dropped };
|
|
64
|
+
}
|
|
65
|
+
/** What the run draws beyond the floor: scenes drawn again, and each scene's added looks. */
|
|
66
|
+
export function extrasOf(picks) {
|
|
67
|
+
const scenes = new Set(picks.map((pick) => pick.scene));
|
|
68
|
+
const looks = new Map();
|
|
69
|
+
for (const { scene, look } of picks)
|
|
70
|
+
if (look)
|
|
71
|
+
looks.set(scene, (looks.get(scene) ?? new Set()).add(look));
|
|
72
|
+
return { scenes, looks };
|
|
73
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SnapshotReport } from './report.ts';
|
|
2
|
+
export declare const MISSES_FILE = "selector-misses.json";
|
|
3
|
+
/** The misses kept, newest last. */
|
|
4
|
+
export declare const MAX_MISSES = 20;
|
|
5
|
+
export interface SelectorMiss {
|
|
6
|
+
/** The full report that found it. */
|
|
7
|
+
report: string;
|
|
8
|
+
scene: string;
|
|
9
|
+
check: string;
|
|
10
|
+
theme: string;
|
|
11
|
+
mode?: string;
|
|
12
|
+
locale?: string;
|
|
13
|
+
}
|
|
14
|
+
/** The latest misses in the snapshots folder; none when the file is missing or unreadable. */
|
|
15
|
+
export declare function readMisses(dir: string): SelectorMiss[];
|
|
16
|
+
/** The problems of a full report that the last selector run (`last`) did not draw. */
|
|
17
|
+
export declare function findMisses(full: SnapshotReport, last: SnapshotReport | undefined): SelectorMiss[];
|
|
18
|
+
/** Add the new misses, once each, and keep the latest; true when the file changed. */
|
|
19
|
+
export declare function recordMisses(dir: string, found: readonly SelectorMiss[]): boolean;
|