@buffcore/cli 0.8.45 → 0.8.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +63 -0
- package/dist/commands/change-merge-remove.d.ts +9 -2
- package/dist/commands/change-merge-remove.js +27 -15
- 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/extension/places-approval.d.ts +4 -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/browser.d.ts +4 -24
- package/dist/commands/prototype/browser.js +13 -76
- 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/loaded-garbage.d.ts +10 -0
- package/dist/commands/prototype/loaded-garbage.js +20 -0
- package/dist/commands/prototype/media-ready.d.ts +9 -3
- package/dist/commands/prototype/media-ready.js +9 -4
- package/dist/commands/prototype/messages.en.d.ts +15 -0
- package/dist/commands/prototype/messages.en.js +15 -0
- package/dist/commands/prototype/messages.js +15 -0
- 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-check.d.ts +37 -0
- package/dist/commands/prototype/scene-check.js +68 -0
- package/dist/commands/prototype/scene-layout.d.ts +17 -0
- package/dist/commands/prototype/scene-layout.js +57 -0
- package/dist/commands/prototype/scene-look.d.ts +14 -0
- package/dist/commands/prototype/scene-look.js +89 -0
- package/dist/commands/prototype/scene-ready.d.ts +46 -0
- package/dist/commands/prototype/scene-ready.js +122 -0
- package/dist/commands/prototype/scene.d.ts +37 -3
- package/dist/commands/prototype/scene.js +103 -36
- 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 +23 -10
- 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 -190
- 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 +54 -4
- 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 +6 -0
- package/dist/commands/prototype/snapshot.js +73 -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/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/approval-authority.d.ts +10 -2
- package/dist/commands/ui/approval-authority.js +1 -0
- 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.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/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/worktree.js +25 -5
- package/dist/commands/ui/index.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-route.js +3 -0
- package/dist/commands/ui/places-change.d.ts +4 -0
- package/dist/commands/ui/prototype-main.d.ts +4 -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 +4 -0
- package/dist/commands/ui/studio-routes.js +2 -0
- package/dist/commands/ui/studio-state.d.ts +33 -0
- package/dist/commands/ui/studio-versions.d.ts +24 -0
- 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 +82 -82
- package/docs/PROTOTYPE.md +6 -3
- package/docs/WORKBENCH.md +11 -6
- package/package.json +11 -11
- package/skills/ape-critique/SKILL.md +41 -6
- 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
- package/templates/product/apps/app/app.json +3 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { existsSync, lstatSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { basename, dirname, extname, join, relative, resolve } from 'node:path';
|
|
4
|
+
import { references } from './milestone-references.js';
|
|
5
|
+
import { loaders } from './snapshot-bundle.js';
|
|
6
|
+
import { pathIn } from './snapshot-dependencies.js';
|
|
7
|
+
import { sha256 } from './snapshot-hashes.js';
|
|
8
|
+
import { matchesBytes, servedBytes } from './snapshot-served-inputs.js';
|
|
9
|
+
import { viteFsFile, viteFsPath } from './vite-fs-path.js';
|
|
10
|
+
export async function pageInputs(dir, read) {
|
|
11
|
+
const page = join(dir, 'index.html');
|
|
12
|
+
const assets = [];
|
|
13
|
+
const roots = [];
|
|
14
|
+
if (!existsSync(page))
|
|
15
|
+
return { assets, roots };
|
|
16
|
+
const links = references('page', (await read(page)).toString('utf8'), page);
|
|
17
|
+
if (typeof links === 'string')
|
|
18
|
+
throw new Error();
|
|
19
|
+
for (const [kind, url] of links) {
|
|
20
|
+
if (/^(?:[\w+.-]+:|\/\/|#)/.test(url))
|
|
21
|
+
continue;
|
|
22
|
+
const name = decodeURIComponent(url.split(/[?#]/, 1)[0] ?? '').replace(/^\//, '');
|
|
23
|
+
const file = resolve(dir, name);
|
|
24
|
+
if (!pathIn(dir, file))
|
|
25
|
+
throw new Error();
|
|
26
|
+
const loader = loaders[extname(file).toLowerCase()];
|
|
27
|
+
const found = [file, join(dir, 'public', name)].filter(existsSync);
|
|
28
|
+
if (kind === 'page' && loader === 'file')
|
|
29
|
+
assets.push(...found);
|
|
30
|
+
else if (loader || kind === 'module') {
|
|
31
|
+
const [root] = found;
|
|
32
|
+
if (!root || found.length !== 1 || !loader)
|
|
33
|
+
throw new Error();
|
|
34
|
+
roots.push(root);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { assets, roots };
|
|
38
|
+
}
|
|
39
|
+
export function surfaceFile(dir, url, assets) {
|
|
40
|
+
const path = decodeURIComponent(url.pathname);
|
|
41
|
+
// Vite marks JS asset imports and gives refreshed URLs a numeric cache stamp.
|
|
42
|
+
if (url.search && !/^\?(?:import(?:&t=\d+)?|t=\d+)$/.test(url.search))
|
|
43
|
+
return;
|
|
44
|
+
const outside = viteFsFile(path);
|
|
45
|
+
const files = outside
|
|
46
|
+
? [outside]
|
|
47
|
+
: [resolve(dir, `.${path}`), resolve(dir, 'public', `.${path}`)];
|
|
48
|
+
const found = files.filter((file) => assets.has(file));
|
|
49
|
+
return found.length === 1 ? found[0] : undefined;
|
|
50
|
+
}
|
|
51
|
+
export async function viteFiles(dir, deps) {
|
|
52
|
+
const require = createRequire(join(dir, 'package.json'));
|
|
53
|
+
const client = join(dirname(require.resolve('vite/package.json')), 'dist/client');
|
|
54
|
+
const react = require.resolve('@vitejs/plugin-react');
|
|
55
|
+
const runtime = {
|
|
56
|
+
'/@vite/client': join(client, 'client.mjs'),
|
|
57
|
+
'/@vite/env': join(client, 'env.mjs'),
|
|
58
|
+
'/@react-refresh': join(dirname(react), 'refresh-runtime.js'),
|
|
59
|
+
};
|
|
60
|
+
const settings = await Promise.all([...Object.values(runtime), require.resolve('vite'), react].map(async (file) => [
|
|
61
|
+
relative(dir, file),
|
|
62
|
+
await deps.digest(file),
|
|
63
|
+
]));
|
|
64
|
+
return {
|
|
65
|
+
runtime: new Set(Object.keys(runtime)),
|
|
66
|
+
settings,
|
|
67
|
+
files: [runtime['/@vite/env']],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const OPTIMIZED = '/node_modules/.vite/deps/';
|
|
71
|
+
const outputName = /^[a-zA-Z0-9_@.-]+\.js$/;
|
|
72
|
+
function readCache(folder, files) {
|
|
73
|
+
const metadata = readFileSync(join(folder, '_metadata.json'));
|
|
74
|
+
const data = JSON.parse(metadata.toString('utf8'));
|
|
75
|
+
if (!data.optimized || !data.chunks)
|
|
76
|
+
throw new Error();
|
|
77
|
+
const outputs = new Map();
|
|
78
|
+
const verified = new Set();
|
|
79
|
+
function add(entry) {
|
|
80
|
+
const name = entry.file;
|
|
81
|
+
if (typeof name !== 'string' || !outputName.test(name) || basename(name) !== name)
|
|
82
|
+
throw new Error();
|
|
83
|
+
const file = join(folder, name);
|
|
84
|
+
if (!lstatSync(file).isFile())
|
|
85
|
+
throw new Error();
|
|
86
|
+
outputs.set(name, sha256(readFileSync(file)));
|
|
87
|
+
return name;
|
|
88
|
+
}
|
|
89
|
+
for (const entry of Object.values(data.optimized)) {
|
|
90
|
+
const name = add(entry);
|
|
91
|
+
if (typeof entry.src === 'string' && files.has(resolve(folder, entry.src)))
|
|
92
|
+
verified.add(name);
|
|
93
|
+
}
|
|
94
|
+
for (const entry of Object.values(data.chunks))
|
|
95
|
+
verified.add(add(entry));
|
|
96
|
+
return {
|
|
97
|
+
outputs,
|
|
98
|
+
verified,
|
|
99
|
+
hash: sha256(JSON.stringify([sha256(metadata), [...outputs].sort()])),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** Bind the scripts that Vite actually serves, including the bytes of its generated output. */
|
|
103
|
+
export function viteRequests(dir, runtime, modules, assets, runtimeFiles = [], page) {
|
|
104
|
+
const folder = join(dir, OPTIMIZED);
|
|
105
|
+
const paths = [...runtime, ...runtimeFiles.map(viteFsPath)];
|
|
106
|
+
async function readRuntime() {
|
|
107
|
+
if (!page)
|
|
108
|
+
return;
|
|
109
|
+
const html = await servedBytes(page, 'html', 15_000);
|
|
110
|
+
if (!html)
|
|
111
|
+
return;
|
|
112
|
+
const helpers = new Map();
|
|
113
|
+
let client;
|
|
114
|
+
let token;
|
|
115
|
+
await Promise.all(paths.map(async (path) => {
|
|
116
|
+
const script = await servedBytes(new URL(path, page), 'javascript', 15_000).catch(() => undefined);
|
|
117
|
+
if (!script)
|
|
118
|
+
return;
|
|
119
|
+
helpers.set(path, sha256(script));
|
|
120
|
+
if (path === '/@vite/client') {
|
|
121
|
+
client = script.toString('utf8');
|
|
122
|
+
token = /^const wsToken = "([\w-]+)";$/m.exec(client)?.[1];
|
|
123
|
+
}
|
|
124
|
+
}));
|
|
125
|
+
if (!token || !client || !helpers.has('/@react-refresh'))
|
|
126
|
+
return;
|
|
127
|
+
// Keep byte equality within a capture. Across runs, Vite's stamped entry and HMR
|
|
128
|
+
// connection values still name the same verified files and transport.
|
|
129
|
+
const stablePage = html
|
|
130
|
+
.toString('utf8')
|
|
131
|
+
.replace(/(<script type="module" src=")(\/[^"?]+)\?t=\d+("\s*><\/script>)/g, (tag, before, path, after) => surfaceFile(dir, new URL(path, page), modules) ? `${before}${path}${after}` : tag);
|
|
132
|
+
const stableClient = sha256(client
|
|
133
|
+
.replace(/^const wsToken = "[\w-]+";$/m, 'const wsToken = "";')
|
|
134
|
+
.replace(/^(const (?:serverHost|directSocketHost) = )"(?:localhost|127\.0\.0\.1|\[::1\]):\d+\/";$/gm, '$1"";')
|
|
135
|
+
.replace(/\n\/\/# sourceMappingURL=data:application\/json;base64,[\w+/=]+\s*$/, ''));
|
|
136
|
+
const stableHelpers = [...helpers].map(([path, digest]) => [
|
|
137
|
+
path,
|
|
138
|
+
path === '/@vite/client' ? stableClient : digest,
|
|
139
|
+
]);
|
|
140
|
+
return {
|
|
141
|
+
html: sha256(html),
|
|
142
|
+
helpers,
|
|
143
|
+
token,
|
|
144
|
+
actual: sha256(JSON.stringify([sha256(html), [...helpers].sort()])),
|
|
145
|
+
key: sha256(JSON.stringify([sha256(stablePage), stableHelpers.sort()])),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const safeRuntime = () => readRuntime().catch(() => undefined);
|
|
149
|
+
let reference;
|
|
150
|
+
const observed = new Map();
|
|
151
|
+
let stamp;
|
|
152
|
+
let cache;
|
|
153
|
+
function load(force = false) {
|
|
154
|
+
try {
|
|
155
|
+
const time = statSync(join(folder, '_metadata.json')).mtimeMs;
|
|
156
|
+
if (force || time !== stamp)
|
|
157
|
+
cache = readCache(folder, modules);
|
|
158
|
+
stamp = time;
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
stamp = undefined;
|
|
162
|
+
cache = undefined;
|
|
163
|
+
}
|
|
164
|
+
return cache;
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
async prepare() {
|
|
168
|
+
reference = await safeRuntime();
|
|
169
|
+
},
|
|
170
|
+
proof: () => reference?.key,
|
|
171
|
+
async same() {
|
|
172
|
+
return !reference || reference.actual === (await safeRuntime())?.actual;
|
|
173
|
+
},
|
|
174
|
+
hash(force = false) {
|
|
175
|
+
const result = load(force);
|
|
176
|
+
if ([...observed].some(([name, hash]) => result?.outputs.get(name) !== hash))
|
|
177
|
+
throw new Error();
|
|
178
|
+
return reference ? sha256(JSON.stringify([reference.key, result?.hash])) : result?.hash;
|
|
179
|
+
},
|
|
180
|
+
tracks(url, kind, response) {
|
|
181
|
+
const path = decodeURIComponent(url.pathname);
|
|
182
|
+
if (assets.has(resolve(dir, 'public', `.${path}`)))
|
|
183
|
+
return false;
|
|
184
|
+
if (kind === 'document')
|
|
185
|
+
return path === '/_scene' && matchesBytes(reference?.html, response);
|
|
186
|
+
if (kind === 'websocket')
|
|
187
|
+
return path === '/' && !!reference?.token && url.search === `?token=${reference.token}`;
|
|
188
|
+
if (kind === 'fetch' && path === '/console.json' && !url.search)
|
|
189
|
+
return matchesBytes(reference?.html, response);
|
|
190
|
+
if (kind !== 'script')
|
|
191
|
+
return false;
|
|
192
|
+
if (paths.includes(path))
|
|
193
|
+
return !url.search && matchesBytes(reference?.helpers.get(path), response);
|
|
194
|
+
if (!path.startsWith(OPTIMIZED) || !/^\?v=[a-f0-9]+$/.test(url.search))
|
|
195
|
+
return false;
|
|
196
|
+
const name = path.slice(OPTIMIZED.length);
|
|
197
|
+
const result = load();
|
|
198
|
+
const hash = result?.outputs.get(name);
|
|
199
|
+
if (!hash || !result?.verified.has(name))
|
|
200
|
+
return false;
|
|
201
|
+
if (!observed.has(name)) {
|
|
202
|
+
if (sha256(readFileSync(join(folder, name))) !== hash)
|
|
203
|
+
return false;
|
|
204
|
+
observed.set(name, hash);
|
|
205
|
+
}
|
|
206
|
+
return observed.get(name) === hash;
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
@@ -2,6 +2,7 @@ import { type Scene, type Scenes } from '@buffcore/config';
|
|
|
2
2
|
import { type SnapshotReport } from './report.ts';
|
|
3
3
|
import type { Run } from './scene.ts';
|
|
4
4
|
import { type SceneSelection } from './scene-selection.ts';
|
|
5
|
+
import { type Selector } from './selector-run.ts';
|
|
5
6
|
import { type SnapshotProgressSource } from './snapshot-progress.ts';
|
|
6
7
|
export { pickScenes } from './scene-selection.ts';
|
|
7
8
|
export { snapAll } from './snapshot-runner.ts';
|
|
@@ -16,6 +17,10 @@ export interface SnapshotOptions {
|
|
|
16
17
|
commit: string;
|
|
17
18
|
/** `prototype/snapshots/`: the screenshots go in `<commit>/` there. */
|
|
18
19
|
dir: string;
|
|
20
|
+
/** `--full`: every theme, mode and pseudo-locale; else the floor unless a shared input changed. */
|
|
21
|
+
full?: boolean | undefined;
|
|
22
|
+
/** The selector (S3c): the CLI passes its real turns, a test a fake; unset, none is asked. */
|
|
23
|
+
selector?: Selector | undefined;
|
|
19
24
|
/** Scene keys or prefix patterns to snapshot; undefined selects every scene. */
|
|
20
25
|
scene?: SceneSelection | undefined;
|
|
21
26
|
sceneTimeout?: number | undefined;
|
|
@@ -40,6 +45,7 @@ export interface SnapshotOptions {
|
|
|
40
45
|
/** A linked worktree's run draws against a stand-in API: the report says so. */
|
|
41
46
|
api?: 'stand-in' | undefined;
|
|
42
47
|
serverExit?: Run['serverExit'];
|
|
48
|
+
onFallback?: Run['onFallback'];
|
|
43
49
|
/** Scene pages open at once (`--pages`); undefined is `pagesFor` the cores and the free memory. */
|
|
44
50
|
pages?: number | undefined;
|
|
45
51
|
/** Keys of the scenes drawn before the others (the change's own); the report keeps its order. */
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
// The snapshot: every scene (or one) in every theme, mode and language, checked and screenshotted,
|
|
2
2
|
// from the development servers that are running; or a committed report's screenshots made again.
|
|
3
|
-
import { mkdir } from 'node:fs/promises';
|
|
3
|
+
import { mkdir, readFile } from 'node:fs/promises';
|
|
4
4
|
import { join, resolve } from 'node:path';
|
|
5
5
|
import { FRAME_SIZES, SURFACES } from '@buffcore/config';
|
|
6
6
|
import { PSEUDO_LOCALES } from '@buffcore/i18n';
|
|
7
|
+
import { checkTheme } from '@buffcore/tokens';
|
|
7
8
|
import { browserSession } from './browser.js';
|
|
8
9
|
import { intlWords } from './checks.js';
|
|
9
10
|
import { locale } from './messages.js';
|
|
10
11
|
import { renderRetries } from './report.js';
|
|
11
12
|
import { pickScenes } from './scene-selection.js';
|
|
13
|
+
import { afterFullRun, selectForRun } from './selector-run.js';
|
|
14
|
+
import { sceneCheckFiles } from './snapshot-check-files.js';
|
|
12
15
|
import { previousSnapshot } from './snapshot-completion.js';
|
|
16
|
+
import { sceneData, sha256 } from './snapshot-hashes.js';
|
|
13
17
|
import { snapshotInputs } from './snapshot-inputs.js';
|
|
18
|
+
import { runMatrix } from './snapshot-matrix.js';
|
|
14
19
|
import { withSnapshotProgress, } from './snapshot-progress.js';
|
|
15
20
|
import { writeSnapshot } from './snapshot-report.js';
|
|
16
21
|
import { snapAll } from './snapshot-runner.js';
|
|
@@ -39,6 +44,7 @@ function runOf(options) {
|
|
|
39
44
|
commit,
|
|
40
45
|
out: join(options.dir, commit),
|
|
41
46
|
serverExit: options.serverExit,
|
|
47
|
+
onFallback: options.onFallback,
|
|
42
48
|
};
|
|
43
49
|
}
|
|
44
50
|
/**
|
|
@@ -53,7 +59,15 @@ export async function takeSnapshot(options) {
|
|
|
53
59
|
recoverForRun(options.dir);
|
|
54
60
|
const picked = pickScenes(options.scenes, options.scene);
|
|
55
61
|
const run = runOf(options);
|
|
56
|
-
|
|
62
|
+
const report = await writeRun(options, run, picked);
|
|
63
|
+
if (options.scene === undefined)
|
|
64
|
+
afterFullRun(options, report);
|
|
65
|
+
return report;
|
|
66
|
+
}
|
|
67
|
+
/** The code that draws and checks a scene (S1's in-place looks included), even for a scene with no fingerprint. */
|
|
68
|
+
async function drawingCode() {
|
|
69
|
+
const bytes = await Promise.all(sceneCheckFiles().map((file) => readFile(file)));
|
|
70
|
+
return sha256(JSON.stringify(bytes.map((data) => sha256(data))));
|
|
57
71
|
}
|
|
58
72
|
async function writeRun(options, run, picked) {
|
|
59
73
|
const previous = options.scene === undefined ? undefined : await previousSnapshot(run.out);
|
|
@@ -69,19 +83,42 @@ async function writeRun(options, run, picked) {
|
|
|
69
83
|
const inputs = options.root
|
|
70
84
|
? await snapshotInputs(options.root, canComplete ? options.scenes.scenes : picked, run, browserVersion, options.design, options.environment)
|
|
71
85
|
: undefined;
|
|
72
|
-
|
|
86
|
+
// The floor, or the full matrix (S3b); the inputs above don't depend on which.
|
|
87
|
+
Object.assign(run, runMatrix(options.full, inputs?.parts?.(), options.root, run.commit));
|
|
88
|
+
// Before drawing: the selector's picks join the floor (S3c).
|
|
89
|
+
await selectForRun(options, run);
|
|
90
|
+
if (options.scene !== undefined || !run.looks.some((theme) => checkTheme(theme).length))
|
|
91
|
+
await inputs?.prepare(options.prepare);
|
|
92
|
+
const write = (remaining, progress) => inSnapshotFolder(options.dir, options.commit, options.runId, (out) => writeSnapshot(options, {
|
|
93
|
+
...run,
|
|
94
|
+
out,
|
|
95
|
+
saveScene: progress?.draw,
|
|
96
|
+
session,
|
|
97
|
+
coversRequest: inputs?.coversRequest,
|
|
98
|
+
}, picked, remaining, progress, inputs, previous), () => {
|
|
73
99
|
progress?.check();
|
|
74
100
|
run.checkCheckout?.();
|
|
75
101
|
previous?.check();
|
|
76
102
|
});
|
|
77
|
-
|
|
103
|
+
// Without the inputs every picture shares (public values, settings, tools), nothing is kept.
|
|
104
|
+
// The studio can issue review proof: its pictures come from this run or a committed ancestor.
|
|
105
|
+
if (!options.progress || !inputs?.shared || options.runId)
|
|
78
106
|
return await write(picked);
|
|
107
|
+
// `--scene` keeps a journal too: a scene's entry serves any run of the same source that draws it.
|
|
108
|
+
const all = options.scenes.scenes;
|
|
79
109
|
return await withSnapshotProgress(options.progress, async () => {
|
|
80
110
|
return [
|
|
81
|
-
picked
|
|
82
|
-
|
|
111
|
+
// Each picked scene's own definition is bound to its entry; other scenes only by name.
|
|
112
|
+
all.map(({ key, surface, frame }) => [key, surface, run.frames[frame]]),
|
|
83
113
|
picked.length ? await browserVersion() : null,
|
|
84
114
|
run.looks,
|
|
115
|
+
run.redraw?.size || run.extraLooks?.size
|
|
116
|
+
? [
|
|
117
|
+
run.matrix,
|
|
118
|
+
[...(run.redraw ?? [])],
|
|
119
|
+
[...(run.extraLooks ?? [])].map(([k, v]) => [k, [...v]]),
|
|
120
|
+
]
|
|
121
|
+
: run.matrix,
|
|
85
122
|
run.fontTheme,
|
|
86
123
|
options.locales,
|
|
87
124
|
SURFACES,
|
|
@@ -89,9 +126,22 @@ async function writeRun(options, run, picked) {
|
|
|
89
126
|
options.artifacts?.['data.json'],
|
|
90
127
|
options.sceneTimeout,
|
|
91
128
|
locale(),
|
|
92
|
-
|
|
129
|
+
await drawingCode(),
|
|
130
|
+
inputs?.shared ?? null,
|
|
93
131
|
];
|
|
94
|
-
},
|
|
132
|
+
}, {
|
|
133
|
+
all,
|
|
134
|
+
picked,
|
|
135
|
+
inputs: new Map(picked.map((scene) => [
|
|
136
|
+
scene.key,
|
|
137
|
+
[
|
|
138
|
+
sceneData(scene),
|
|
139
|
+
inputs?.surfaces?.get(scene.surface) ?? null,
|
|
140
|
+
inputs?.fingerprints.get(scene.key) ?? null,
|
|
141
|
+
inputs?.reuse.get(scene.key) ?? null,
|
|
142
|
+
],
|
|
143
|
+
])),
|
|
144
|
+
}, run.commit, write, () => inputs?.runtime());
|
|
95
145
|
}
|
|
96
146
|
finally {
|
|
97
147
|
await session?.close();
|
|
@@ -106,10 +156,23 @@ export async function remakeScreenshots(options) {
|
|
|
106
156
|
recoverSnapshots(options.dir);
|
|
107
157
|
const { report } = options;
|
|
108
158
|
const keys = new Set(report.scenes.map((s) => s.key));
|
|
109
|
-
|
|
159
|
+
// Each scene's own looks: a floor scene's, or a full one's (reused, or from an older report).
|
|
160
|
+
const matrixOf = new Map(report.scenes.map((s) => [s.key, s.matrix ?? 'full']));
|
|
161
|
+
const extraLooks = new Map(report.scenes.map((s) => [s.key, new Set(s.extraLooks ?? [])]));
|
|
162
|
+
const scenes = pickScenes(options.scenes, options.scene).filter((s) => keys.has(s.key));
|
|
110
163
|
const run = { ...runOf({ ...options, commit: report.commit }), photosOnly: true };
|
|
111
164
|
await mkdir(run.out, { recursive: true });
|
|
112
|
-
const
|
|
165
|
+
const picked = [];
|
|
166
|
+
const snapped = [];
|
|
167
|
+
for (const matrix of ['floor', 'full']) {
|
|
168
|
+
const group = scenes.filter((scene) => matrixOf.get(scene.key) === matrix);
|
|
169
|
+
if (!group.length)
|
|
170
|
+
continue;
|
|
171
|
+
picked.push(...group);
|
|
172
|
+
snapped.push(...(await snapAll(group, { ...run, matrix, extraLooks }, undefined, {
|
|
173
|
+
pages: options.pages,
|
|
174
|
+
})));
|
|
175
|
+
}
|
|
113
176
|
return {
|
|
114
177
|
screenshots: snapped.flatMap((s) => Object.values(s.screenshots)),
|
|
115
178
|
retried: picked.filter((_, i) => snapped[i]?.retried).map((scene) => scene.key),
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { Command } from 'commander';
|
|
2
|
+
import { type VersionRow } from './versions.ts';
|
|
2
3
|
interface Flags {
|
|
3
4
|
json?: boolean;
|
|
4
5
|
version?: string;
|
|
5
6
|
why?: string;
|
|
6
7
|
}
|
|
8
|
+
export declare function printVersions(records: VersionRow[]): void;
|
|
9
|
+
/** A person reopens an AI approval (S4): the version waits for a person's approval again. */
|
|
10
|
+
export declare function reopen(change: string): Promise<void>;
|
|
7
11
|
/** Presence is checked at the terminal door; the shared write has no terminal dependency. */
|
|
8
12
|
export declare function approve(change: string, flags?: Flags): Promise<void>;
|
|
9
13
|
/** Register the repository's version doors. There is deliberately no MCP approval door. */
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { createInterface } from 'node:readline/promises';
|
|
2
|
-
import { approvalHolds } from '@buffcore/contracts/approvals';
|
|
2
|
+
import { approvalHolds, isAiSignature, } from '@buffcore/contracts/approvals';
|
|
3
3
|
import { findRoot } from '../../project.js';
|
|
4
4
|
import { ruleT } from '../approval-rules.js';
|
|
5
5
|
import { printJson } from '../json.js';
|
|
6
|
+
import { reopenAndSave } from '../ui/reopen-route.js';
|
|
6
7
|
import { captureCompareCommand, printCommandFailure } from '../ui/snapshot-diagnostics-command.js';
|
|
7
8
|
import { compareVersions, sameWords } from './compare.js';
|
|
8
9
|
import { parseVersion } from './compare-failure.js';
|
|
10
|
+
import { noCritique } from './critique-gate.js';
|
|
9
11
|
import { number, t } from './messages.js';
|
|
12
|
+
import { reopenT } from './reopen-messages.js';
|
|
10
13
|
import { git } from './report.js';
|
|
11
14
|
import { refuseOlder } from './supersede.js';
|
|
12
15
|
import { approveVersion, heldOnly, listVersions, pickVersion, readVersions, recordFromCommand, VersionRefusal, } from './versions.js';
|
|
@@ -37,7 +40,7 @@ async function run(flags, work, print) {
|
|
|
37
40
|
process.exitCode = 2;
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
|
-
function printVersions(records) {
|
|
43
|
+
export function printVersions(records) {
|
|
41
44
|
for (const record of records)
|
|
42
45
|
for (const version of record.versions) {
|
|
43
46
|
console.log(t('prototype.row', {
|
|
@@ -45,7 +48,9 @@ function printVersions(records) {
|
|
|
45
48
|
version: number(version.version),
|
|
46
49
|
approved: version.version === record.approved?.version &&
|
|
47
50
|
approvalHolds(record.approved.approval, new Date())
|
|
48
|
-
?
|
|
51
|
+
? record.approved.approval.signatures.some(isAiSignature)
|
|
52
|
+
? reopenT('reopen.aiMark')
|
|
53
|
+
: t('prototype.mark')
|
|
49
54
|
: '',
|
|
50
55
|
commit: version.commit,
|
|
51
56
|
why: version.why,
|
|
@@ -55,6 +60,23 @@ function printVersions(records) {
|
|
|
55
60
|
if (refusal)
|
|
56
61
|
console.log(refusal);
|
|
57
62
|
}
|
|
63
|
+
/** A person reopens an AI approval (S4): the version waits for a person's approval again. */
|
|
64
|
+
export async function reopen(change) {
|
|
65
|
+
return run({}, async () => {
|
|
66
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
67
|
+
throw new Error(t('prototype.person'));
|
|
68
|
+
const root = findRoot();
|
|
69
|
+
let by = '';
|
|
70
|
+
try {
|
|
71
|
+
by = git(root, ['config', 'user.email']);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// No identity: the shared write refuses with its own sentence.
|
|
75
|
+
}
|
|
76
|
+
// The same isolated commit as the studio's Reopen, saying who and when.
|
|
77
|
+
return { ok: true, record: await reopenAndSave(root, change, by) };
|
|
78
|
+
}, () => console.log(reopenT('reopen.done', { change })));
|
|
79
|
+
}
|
|
58
80
|
/** Presence is checked at the terminal door; the shared write has no terminal dependency. */
|
|
59
81
|
export async function approve(change, flags = {}) {
|
|
60
82
|
return run(flags, async () => {
|
|
@@ -120,6 +142,7 @@ export function addVersionCommands(prototype) {
|
|
|
120
142
|
.option('--version <n>', t('prototype.numberHelp'))
|
|
121
143
|
.option('--json', t('prototype.jsonHelp'))
|
|
122
144
|
.action(approve);
|
|
145
|
+
prototype.command('reopen <change>').description(reopenT('reopen.help')).action(reopen);
|
|
123
146
|
prototype
|
|
124
147
|
.command('versions [change]')
|
|
125
148
|
.description(t('prototype.versionsHelp'))
|
|
@@ -137,14 +160,19 @@ export function addVersionCommands(prototype) {
|
|
|
137
160
|
/** One change answers `record`, as before; several answer `records`, in the order named. */
|
|
138
161
|
function makeVersion(changes, flags) {
|
|
139
162
|
return run(flags, async () => {
|
|
140
|
-
const
|
|
163
|
+
const root = findRoot();
|
|
164
|
+
const records = await recordFromCommand(root, changes, flags.why ?? '');
|
|
141
165
|
const [record] = records;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
166
|
+
const answer = changes.length === 1 && record ? { ok: true, record } : { ok: true, records };
|
|
167
|
+
const note = noCritique(root);
|
|
168
|
+
if (note)
|
|
169
|
+
answer.note = note;
|
|
170
|
+
return answer;
|
|
171
|
+
}, ({ record, records = record ? [record] : [], note }) => {
|
|
146
172
|
for (const { change, versions } of records)
|
|
147
173
|
console.log(t('prototype.recorded', { change, version: number(versions.at(-1)?.version ?? 0) }));
|
|
174
|
+
if (note)
|
|
175
|
+
console.log(note);
|
|
148
176
|
});
|
|
149
177
|
}
|
|
150
178
|
async function compareCommand(change, a, b, flags) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type PrototypeVersions } from '@buffcore/contracts/approvals';
|
|
1
|
+
import { type PrototypeVersions, type Signature } from '@buffcore/contracts/approvals';
|
|
2
2
|
import { ApprovalRefusal as VersionRefusal } from '../approval-rules.ts';
|
|
3
3
|
import { approvedIn, pickVersion } from './pick-version.ts';
|
|
4
4
|
import { versionSnapshot } from './version-snapshot.ts';
|
|
@@ -45,6 +45,10 @@ export declare const recordFromCommand: (root: string, changes: readonly string[
|
|
|
45
45
|
fingerprint: string;
|
|
46
46
|
role?: string | undefined;
|
|
47
47
|
agent?: string | undefined;
|
|
48
|
+
ai?: {
|
|
49
|
+
model?: string | undefined;
|
|
50
|
+
reason: string;
|
|
51
|
+
} | undefined;
|
|
48
52
|
}[];
|
|
49
53
|
rule?: {
|
|
50
54
|
kind: "one";
|
|
@@ -58,6 +62,10 @@ export declare const recordFromCommand: (root: string, changes: readonly string[
|
|
|
58
62
|
by: string;
|
|
59
63
|
} | undefined;
|
|
60
64
|
};
|
|
65
|
+
reopened?: {
|
|
66
|
+
by: string;
|
|
67
|
+
at: string;
|
|
68
|
+
} | undefined;
|
|
61
69
|
} | undefined;
|
|
62
70
|
pending?: {
|
|
63
71
|
version: number;
|
|
@@ -70,6 +78,10 @@ export declare const recordFromCommand: (root: string, changes: readonly string[
|
|
|
70
78
|
fingerprint: string;
|
|
71
79
|
role?: string | undefined;
|
|
72
80
|
agent?: string | undefined;
|
|
81
|
+
ai?: {
|
|
82
|
+
model?: string | undefined;
|
|
83
|
+
reason: string;
|
|
84
|
+
} | undefined;
|
|
73
85
|
}[];
|
|
74
86
|
rule?: {
|
|
75
87
|
kind: "one";
|
|
@@ -83,6 +95,10 @@ export declare const recordFromCommand: (root: string, changes: readonly string[
|
|
|
83
95
|
by: string;
|
|
84
96
|
} | undefined;
|
|
85
97
|
};
|
|
98
|
+
reopened?: {
|
|
99
|
+
by: string;
|
|
100
|
+
at: string;
|
|
101
|
+
} | undefined;
|
|
86
102
|
} | undefined;
|
|
87
103
|
superseded?: {
|
|
88
104
|
version: number;
|
|
@@ -95,6 +111,10 @@ export declare const recordFromCommand: (root: string, changes: readonly string[
|
|
|
95
111
|
fingerprint: string;
|
|
96
112
|
role?: string | undefined;
|
|
97
113
|
agent?: string | undefined;
|
|
114
|
+
ai?: {
|
|
115
|
+
model?: string | undefined;
|
|
116
|
+
reason: string;
|
|
117
|
+
} | undefined;
|
|
98
118
|
}[];
|
|
99
119
|
rule?: {
|
|
100
120
|
kind: "one";
|
|
@@ -108,12 +128,16 @@ export declare const recordFromCommand: (root: string, changes: readonly string[
|
|
|
108
128
|
by: string;
|
|
109
129
|
} | undefined;
|
|
110
130
|
};
|
|
131
|
+
reopened?: {
|
|
132
|
+
by: string;
|
|
133
|
+
at: string;
|
|
134
|
+
} | undefined;
|
|
111
135
|
}[] | undefined;
|
|
112
136
|
}[]>;
|
|
113
137
|
/** The studio's doors record one change, over a checkout with nothing waiting. */
|
|
114
138
|
export declare function recordVersion(root: string, change: string, why: string, now?: Date, write?: boolean): Promise<PrototypeVersions>;
|
|
115
139
|
/** One shared write for the person's terminal and the workbench's approval button. */
|
|
116
|
-
export declare function approveVersion(root: string, change: string, version: number | undefined, by: string, now: Date, role?: string, agent?: string, write?: boolean): PrototypeVersions;
|
|
140
|
+
export declare function approveVersion(root: string, change: string, version: number | undefined, by: string, now: Date, role?: string, agent?: string, write?: boolean, ai?: Signature['ai']): PrototypeVersions;
|
|
117
141
|
export declare const approvedVersion: (root: string, change: string, now?: Date) => {
|
|
118
142
|
version: number;
|
|
119
143
|
commit: string;
|
|
@@ -123,3 +147,5 @@ export declare const approvedVersion: (root: string, change: string, now?: Date)
|
|
|
123
147
|
why: string;
|
|
124
148
|
at: string;
|
|
125
149
|
};
|
|
150
|
+
/** A person reopens an AI approval (S4), at any level: it moves to `superseded`; the version waits. */
|
|
151
|
+
export declare function reopenVersion(root: string, change: string, by: string, now: Date, write?: boolean): PrototypeVersions;
|
|
@@ -4,13 +4,16 @@ import { join } from 'node:path';
|
|
|
4
4
|
import { approvalHolds, prototypeVersionsSchema, } from '@buffcore/contracts/approvals';
|
|
5
5
|
import { approvalRule, ruleT, signApproval, ApprovalRefusal as VersionRefusal, } from '../approval-rules.js';
|
|
6
6
|
import { readChanges } from '../change-file.js';
|
|
7
|
+
import { openP0Refusal } from './critique-gate.js';
|
|
7
8
|
import { t } from './messages.js';
|
|
8
9
|
import { MilestoneVersionsPending, requireLegacyChange } from './milestone-key.js';
|
|
9
10
|
import { approvedIn, pickVersion } from './pick-version.js';
|
|
10
11
|
import { appendVersion, isWhy, recordText, requireCleanCheckout } from './record-checkout.js';
|
|
11
12
|
import { refuseUnsavedVersion, requireSavedLook, requireSavedSnapshot } from './record-look.js';
|
|
13
|
+
import { reopenT } from './reopen-messages.js';
|
|
12
14
|
import { git } from './report.js';
|
|
13
15
|
import { requireReviewProof, snapshotSource } from './review-snapshot.js';
|
|
16
|
+
import { meetsFloor } from './snapshot-matrix.js';
|
|
14
17
|
import { requireReusedScenes } from './snapshot-reuse.js';
|
|
15
18
|
import { requireFinishedReport } from './snapshot-trust.js';
|
|
16
19
|
import { personHeld, signNewest } from './supersede.js';
|
|
@@ -135,6 +138,8 @@ async function provenSnapshot(root) {
|
|
|
135
138
|
}
|
|
136
139
|
const commit = snapshotSource(root, saved.report);
|
|
137
140
|
requireFinishedReport(saved.report, saved.snapshot);
|
|
141
|
+
if (!meetsFloor(saved.report))
|
|
142
|
+
throw new VersionRefusal(t('prototype.belowFloor'));
|
|
138
143
|
requireSavedSnapshot(saved.report);
|
|
139
144
|
requireReusedScenes(root, saved.report, true);
|
|
140
145
|
await requireSavedLook(root, commit, saved.report, saved.model);
|
|
@@ -149,6 +154,10 @@ export async function recordVersions(root, changes, why, { now = new Date(), wri
|
|
|
149
154
|
if (!isWhy(why))
|
|
150
155
|
throw new VersionRefusal(t('prototype.why'));
|
|
151
156
|
requireCleanCheckout(root, standing ? { recording: changes, known } : undefined);
|
|
157
|
+
// The critique on file, in the clean checkout: an open P0 holds every change back.
|
|
158
|
+
const p0 = openP0Refusal(root);
|
|
159
|
+
if (p0)
|
|
160
|
+
throw new VersionRefusal(p0);
|
|
152
161
|
const { commit, fingerprints } = await provenSnapshot(root);
|
|
153
162
|
for (const change of changes)
|
|
154
163
|
namedRefusal(changes, change, () => requireReviewProof(root, change, commit, fingerprints));
|
|
@@ -168,7 +177,7 @@ export async function recordVersion(root, change, why, now = new Date(), write =
|
|
|
168
177
|
return record;
|
|
169
178
|
}
|
|
170
179
|
/** One shared write for the person's terminal and the workbench's approval button. */
|
|
171
|
-
export function approveVersion(root, change, version, by, now, role, agent, write = true) {
|
|
180
|
+
export function approveVersion(root, change, version, by, now, role, agent, write = true, ai) {
|
|
172
181
|
return update(root, change, (record) => {
|
|
173
182
|
if (record.approved && !personHeld(record.approved.approval))
|
|
174
183
|
delete record.approved;
|
|
@@ -186,6 +195,8 @@ export function approveVersion(root, change, version, by, now, role, agent, writ
|
|
|
186
195
|
fingerprint,
|
|
187
196
|
...(role ? { role } : {}),
|
|
188
197
|
...(agent === undefined ? {} : { agent }),
|
|
198
|
+
// An AI approval (S4) always names its agent; a person's never carries `ai`.
|
|
199
|
+
...(ai && agent !== undefined ? { ai } : {}),
|
|
189
200
|
}, approvalRule(root, 'prototype'));
|
|
190
201
|
};
|
|
191
202
|
// A held approval stays in force while the newest version gathers its own signatures.
|
|
@@ -201,3 +212,16 @@ export function approveVersion(root, change, version, by, now, role, agent, writ
|
|
|
201
212
|
}, write);
|
|
202
213
|
}
|
|
203
214
|
export const approvedVersion = (root, change, now = new Date()) => approvedIn(readVersions(root, change), change, now);
|
|
215
|
+
/** A person reopens an AI approval (S4), at any level: it moves to `superseded`; the version waits. */
|
|
216
|
+
export function reopenVersion(root, change, by, now, write = true) {
|
|
217
|
+
return update(root, change, (record) => {
|
|
218
|
+
const held = record.approved;
|
|
219
|
+
if (!held?.approval.signatures.some((s) => s.ai))
|
|
220
|
+
throw new VersionRefusal(reopenT('reopen.none', { change }));
|
|
221
|
+
if (!by.trim())
|
|
222
|
+
throw new VersionRefusal(t('prototype.identity'));
|
|
223
|
+
const reopened = { by: by.trim(), at: now.toISOString() };
|
|
224
|
+
record.superseded = [...(record.superseded ?? []), { ...held, reopened }];
|
|
225
|
+
delete record.approved;
|
|
226
|
+
}, write);
|
|
227
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Vite serves a file outside its root at `/@fs/` and the file's own path: `/@fs/home/me/x.ts` on
|
|
2
|
+
// Linux and macOS, `/@fs/C:/me/x.ts` on Windows. Both directions, as Vite itself reads them.
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
const PREFIX = '/@fs/';
|
|
5
|
+
/** The path Vite serves `file` at. */
|
|
6
|
+
export function viteFsPath(file) {
|
|
7
|
+
return PREFIX + file.replaceAll('\\', '/').replace(/^\/+/, '');
|
|
8
|
+
}
|
|
9
|
+
/** The file a `/@fs/` path names, or undefined for any other path. */
|
|
10
|
+
export function viteFsFile(path) {
|
|
11
|
+
if (!path.startsWith(PREFIX))
|
|
12
|
+
return undefined;
|
|
13
|
+
const rest = path.slice(PREFIX.length).replace(/^\/+/, '');
|
|
14
|
+
return resolve(/^[a-z]:\//i.test(rest) ? rest : `/${rest}`);
|
|
15
|
+
}
|