@buffcore/cli 0.8.40 → 0.8.42
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 +36 -0
- package/dist/commands/agents-file.d.ts +5 -0
- package/dist/commands/agents-file.js +30 -7
- package/dist/commands/change.d.ts +4 -0
- package/dist/commands/change.js +12 -5
- package/dist/commands/create-block.d.ts +2 -1
- package/dist/commands/create-block.js +7 -5
- package/dist/commands/create-steps.en.js +1 -1
- package/dist/commands/create-steps.js +1 -1
- package/dist/commands/create.d.ts +3 -2
- package/dist/commands/create.en.js +1 -1
- package/dist/commands/create.es.js +1 -1
- package/dist/commands/create.js +8 -6
- package/dist/commands/design/check.d.ts +2 -0
- package/dist/commands/design/check.js +6 -0
- package/dist/commands/design/journey-roles.d.ts +6 -0
- package/dist/commands/design/journey-roles.js +60 -0
- package/dist/commands/design/references.d.ts +3 -0
- package/dist/commands/design/references.js +25 -0
- package/dist/commands/design/tells-text.js +2 -2
- package/dist/commands/design/tells.d.ts +3 -1
- 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/design/tells.js +10 -7
- package/dist/commands/dev.js +3 -0
- package/dist/commands/port-claims.d.ts +23 -0
- package/dist/commands/port-claims.js +95 -0
- package/dist/commands/prototype/browser.d.ts +9 -4
- package/dist/commands/prototype/browser.js +26 -18
- package/dist/commands/prototype/export-base.d.ts +27 -0
- package/dist/commands/prototype/export-base.js +80 -0
- package/dist/commands/prototype/export.d.ts +3 -2
- package/dist/commands/prototype/export.js +13 -6
- package/dist/commands/prototype/index.js +1 -0
- package/dist/commands/prototype/media-ready.d.ts +8 -0
- package/dist/commands/prototype/media-ready.js +36 -0
- package/dist/commands/prototype/messages.en.d.ts +6 -0
- package/dist/commands/prototype/messages.en.js +6 -0
- package/dist/commands/prototype/messages.js +6 -0
- package/dist/commands/prototype/scene.d.ts +3 -1
- package/dist/commands/prototype/scene.js +22 -6
- package/dist/commands/prototype/snapshot-inputs.js +35 -7
- package/dist/commands/prototype/snapshot-setup.d.ts +1 -1
- package/dist/commands/prototype/snapshot-setup.js +2 -1
- package/dist/commands/prototype/snapshot-themes.js +3 -1
- package/dist/commands/prototype/snapshot.d.ts +2 -0
- package/dist/commands/prototype/snapshot.js +2 -1
- package/dist/commands/ui/autopilot-records.d.ts +3 -0
- package/dist/commands/ui/chat/allow-folder-route.d.ts +9 -0
- package/dist/commands/ui/chat/allow-folder-route.js +56 -0
- package/dist/commands/ui/chat/allow-folder.d.ts +18 -0
- package/dist/commands/ui/chat/allow-folder.js +76 -0
- package/dist/commands/ui/chat/ask-person.d.ts +17 -0
- package/dist/commands/ui/chat/ask-person.en.d.ts +4 -0
- package/dist/commands/ui/chat/ask-person.en.js +4 -0
- package/dist/commands/ui/chat/ask-person.es.d.ts +4 -0
- package/dist/commands/ui/chat/ask-person.es.js +4 -0
- package/dist/commands/ui/chat/ask-person.js +60 -0
- package/dist/commands/ui/chat/claude-permissions.d.ts +21 -0
- package/dist/commands/ui/chat/claude-permissions.js +69 -0
- package/dist/commands/ui/chat/codex-idle.d.ts +1 -0
- package/dist/commands/ui/chat/codex-overrides.js +2 -1
- package/dist/commands/ui/chat/codex-permissions.d.ts +12 -0
- package/dist/commands/ui/chat/codex-permissions.js +97 -0
- package/dist/commands/ui/chat/command-parts.d.ts +33 -0
- package/dist/commands/ui/chat/command-parts.js +219 -0
- package/dist/commands/ui/chat/command-wrappers.d.ts +21 -0
- package/dist/commands/ui/chat/command-wrappers.js +100 -0
- package/dist/commands/ui/chat/design-deletes.d.ts +1 -0
- package/dist/commands/ui/chat/design-deletes.js +39 -0
- package/dist/commands/ui/chat/launch-input.d.ts +4 -2
- package/dist/commands/ui/chat/launch-input.js +16 -3
- package/dist/commands/ui/chat/limit-mentions.d.ts +5 -0
- package/dist/commands/ui/chat/limit-mentions.js +74 -0
- package/dist/commands/ui/chat/limit-patterns.d.ts +15 -0
- package/dist/commands/ui/chat/limit-patterns.js +182 -0
- package/dist/commands/ui/chat/limits-hook.d.ts +1 -0
- package/dist/commands/ui/chat/limits-hook.js +30 -0
- package/dist/commands/ui/chat/limits.d.ts +37 -0
- package/dist/commands/ui/chat/limits.en.d.ts +18 -0
- package/dist/commands/ui/chat/limits.en.js +18 -0
- package/dist/commands/ui/chat/limits.es.d.ts +2 -0
- package/dist/commands/ui/chat/limits.es.js +17 -0
- package/dist/commands/ui/chat/limits.js +224 -0
- package/dist/commands/ui/chat/local-settings.d.ts +17 -0
- package/dist/commands/ui/chat/local-settings.js +73 -0
- package/dist/commands/ui/chat/opencode-config.d.ts +22 -0
- package/dist/commands/ui/chat/opencode-config.js +83 -0
- package/dist/commands/ui/chat/parse-claude.js +18 -2
- package/dist/commands/ui/chat/permission-ask.d.ts +44 -0
- package/dist/commands/ui/chat/permission-ask.js +142 -0
- package/dist/commands/ui/chat/permission-channel.d.ts +18 -0
- package/dist/commands/ui/chat/permission-channel.js +67 -0
- package/dist/commands/ui/chat/permission-route.d.ts +10 -0
- package/dist/commands/ui/chat/permission-route.js +47 -0
- package/dist/commands/ui/chat/permission-tool.d.ts +1 -0
- package/dist/commands/ui/chat/permission-tool.js +86 -0
- package/dist/commands/ui/chat/permissions.d.ts +11 -12
- package/dist/commands/ui/chat/permissions.js +20 -102
- package/dist/commands/ui/chat/planning-limits.d.ts +12 -0
- package/dist/commands/ui/chat/planning-limits.js +31 -0
- package/dist/commands/ui/chat/process.js +4 -1
- package/dist/commands/ui/chat/prompt.d.ts +8 -1
- package/dist/commands/ui/chat/prompt.en.d.ts +4 -0
- package/dist/commands/ui/chat/prompt.en.js +4 -0
- package/dist/commands/ui/chat/prompt.es.d.ts +4 -0
- package/dist/commands/ui/chat/prompt.es.js +4 -0
- package/dist/commands/ui/chat/prompt.js +18 -50
- package/dist/commands/ui/chat/recorded-turn.js +5 -0
- package/dist/commands/ui/chat/routes.js +4 -0
- package/dist/commands/ui/chat/secret-folders.d.ts +16 -0
- package/dist/commands/ui/chat/secret-folders.js +35 -0
- package/dist/commands/ui/chat/stdin-shells.d.ts +8 -0
- package/dist/commands/ui/chat/stdin-shells.js +102 -0
- package/dist/commands/ui/chat/step-rules.d.ts +13 -0
- package/dist/commands/ui/chat/step-rules.js +47 -0
- package/dist/commands/ui/chat/store.d.ts +2 -0
- package/dist/commands/ui/chat/store.js +25 -3
- package/dist/commands/ui/chat/stream.en.d.ts +17 -0
- package/dist/commands/ui/chat/stream.en.js +18 -1
- package/dist/commands/ui/chat/stream.es.d.ts +17 -0
- package/dist/commands/ui/chat/stream.es.js +18 -1
- package/dist/commands/ui/chat/stream.js +4 -1
- package/dist/commands/ui/chat/turn-guard.d.ts +25 -0
- package/dist/commands/ui/chat/turn-guard.js +74 -0
- package/dist/commands/ui/chat/turn-input.d.ts +3 -2
- package/dist/commands/ui/chat/turn-input.js +3 -1
- package/dist/commands/ui/chat/turn-reserve.js +2 -0
- package/dist/commands/ui/chat/turn-scenes.d.ts +19 -0
- package/dist/commands/ui/chat/turn-scenes.js +44 -0
- package/dist/commands/ui/chat/turn-selection.d.ts +3 -0
- package/dist/commands/ui/chat/turn-selection.js +9 -3
- package/dist/commands/ui/chat/turn-state.d.ts +6 -0
- package/dist/commands/ui/chat/turn.js +8 -3
- package/dist/commands/ui/level-route.js +8 -3
- package/dist/commands/ui/page.d.ts +19 -1
- package/dist/commands/ui/page.js +9 -6
- package/dist/commands/ui/plan-structure.d.ts +9 -2
- package/dist/commands/ui/plan-structure.en.d.ts +1 -0
- package/dist/commands/ui/plan-structure.en.js +1 -0
- package/dist/commands/ui/plan-structure.es.d.ts +1 -0
- package/dist/commands/ui/plan-structure.es.js +1 -0
- package/dist/commands/ui/plan-structure.js +36 -10
- package/dist/commands/ui/prototype-main.d.ts +1 -0
- package/dist/commands/ui/prototype-scenes-child.js +3 -1
- package/dist/commands/ui/prototype-scenes-read.d.ts +1 -0
- package/dist/commands/ui/prototype-scenes-route.js +7 -1
- package/dist/commands/ui/save-commit.js +6 -2
- package/dist/commands/ui/server-options.js +2 -0
- package/dist/commands/ui/server.d.ts +5 -22
- package/dist/commands/ui/server.js +3 -45
- package/dist/commands/ui/snapshot-runners.d.ts +22 -0
- package/dist/commands/ui/snapshot-runners.js +45 -0
- package/dist/commands/ui/studio-routes.d.ts +1 -0
- package/dist/commands/ui/studio-routes.js +1 -0
- package/dist/commands/ui/studio-state.d.ts +4 -1
- package/dist/commands/ui/studio-state.js +1 -0
- package/dist/commands/ui/studio.en.d.ts +13 -0
- package/dist/commands/ui/studio.en.js +13 -0
- package/dist/commands/ui/studio.es.d.ts +13 -0
- package/dist/commands/ui/studio.es.js +13 -0
- package/dist/commands/ui/theme-option.d.ts +8 -0
- package/dist/commands/ui/theme-option.js +40 -0
- package/dist/commands/ui/theme-values.d.ts +5 -0
- package/dist/commands/ui/theme-values.js +113 -0
- package/dist/ui/page.js +86 -86
- package/docs/PROTOTYPE.md +4 -1
- package/docs/WORKBENCH.md +90 -26
- package/package.json +11 -11
- package/skills/ape-critique/SKILL.md +8 -4
- package/skills/ape-design-system/SKILL.md +14 -3
- package/skills/ape-plan-change/SKILL.md +9 -5
- package/skills/ape-prototype/SKILL.md +8 -1
- package/templates/example/apps/app/src/i18n/en.ts +2 -0
- package/templates/example/apps/app/src/i18n/es.json +2 -0
- package/templates/product/README.md +1 -1
- package/templates/product/apps/admin/src/fonts.ts +2 -1
- package/templates/product/apps/app/src/fonts.ts +5 -1
- package/templates/product/apps/app/src/i18n/en.ts +2 -0
- package/templates/product/apps/app/src/i18n/es.json +2 -0
- package/templates/product/prototype/journeys.ts +3 -0
|
@@ -5,11 +5,11 @@ import { stopTree } from '../runner.js';
|
|
|
5
5
|
import { finishChild, stopChild } from './agent-process.js';
|
|
6
6
|
import { withTranscripts } from './attachments.js';
|
|
7
7
|
import { finishChangeSave, readUnsavedTurn } from './change-save-turn.js';
|
|
8
|
+
import { withLinkedPermissions } from './codex-permissions.js';
|
|
8
9
|
import { CodingApprovalRefusal, requireCodingApproval } from './coding-approval.js';
|
|
9
10
|
import { HeldMerges } from './held-merges.js';
|
|
10
11
|
import { launchInput, startCodingTurn } from './launch-input.js';
|
|
11
12
|
import * as orphans from './orphans.js';
|
|
12
|
-
import { withLinkedPermissions } from './permissions.js';
|
|
13
13
|
import { turnOptions, turnPerson } from './person.js';
|
|
14
14
|
import { agentStart } from './process.js';
|
|
15
15
|
import { chatError, chatErrorMessage, t } from './prompt.js';
|
|
@@ -21,6 +21,7 @@ import { ChatStore, message } from './store.js';
|
|
|
21
21
|
import { StudioSession } from './studio-session.js';
|
|
22
22
|
import { selectTakeover, selectTurnAgent, turnChoices } from './turn-input.js';
|
|
23
23
|
import { reserveTurn } from './turn-reserve.js';
|
|
24
|
+
import { mayChangeScenes, turnScenes } from './turn-scenes.js';
|
|
24
25
|
import { startSelection } from './turn-selection.js';
|
|
25
26
|
import { LOST_TURN } from './turn-state.js';
|
|
26
27
|
import { noteFailure } from './unsent.js';
|
|
@@ -139,8 +140,9 @@ export class ChatEngine {
|
|
|
139
140
|
if (run.stopped || this.closing)
|
|
140
141
|
return this.finish(run, false);
|
|
141
142
|
this.store.saveRetry(run.chat);
|
|
142
|
-
const
|
|
143
|
-
const
|
|
143
|
+
const save = () => this.store.checkpoint(run.chat);
|
|
144
|
+
const { adapter, input, spec, examples, guard } = launchInput(run, this.root, context, save);
|
|
145
|
+
const child = startCodingTurn(this.start, spec, run, this.options.migrations, examples, guard);
|
|
144
146
|
run.child = child;
|
|
145
147
|
run.launched = true;
|
|
146
148
|
const reported = startSelection(run);
|
|
@@ -179,6 +181,9 @@ export class ChatEngine {
|
|
|
179
181
|
if (result.signedOut && (await this.takeover(run)))
|
|
180
182
|
return;
|
|
181
183
|
}
|
|
184
|
+
const first = run.firstMessage ?? 0;
|
|
185
|
+
if (!failed && !run.stopped && mayChangeScenes(run.chat, first))
|
|
186
|
+
run.scenes = await turnScenes(run.tree, run.chat, first);
|
|
182
187
|
const saved = writesInChange(run.chat)
|
|
183
188
|
? await finishChangeSave(this.root, run, failed, this.attemptedTips.get(run.tree))
|
|
184
189
|
: undefined;
|
|
@@ -15,7 +15,7 @@ export function levelRoute(root) {
|
|
|
15
15
|
const { body, identity, hosted, level: control } = request;
|
|
16
16
|
if (control)
|
|
17
17
|
return { status: 409, body: levelElsewhere(control) };
|
|
18
|
-
const { level } = levelBody.parse(await body());
|
|
18
|
+
const { level, neverAsk } = levelBody.parse(await body());
|
|
19
19
|
const person = personForTurn({ identity, hosted });
|
|
20
20
|
if (!person)
|
|
21
21
|
return { status: 403, body: { error: hostT('ui.host.private') } };
|
|
@@ -25,9 +25,14 @@ export function levelRoute(root) {
|
|
|
25
25
|
work: {},
|
|
26
26
|
level: 'guide',
|
|
27
27
|
};
|
|
28
|
-
|
|
28
|
+
// Never ask lives only with Autopilot: another level clears it, so coming back starts off.
|
|
29
|
+
const { neverAsk: saved, ...rest } = file;
|
|
30
|
+
const next = level === 'auto' && (neverAsk ?? saved)
|
|
31
|
+
? { ...rest, level, neverAsk: true }
|
|
32
|
+
: { ...rest, level };
|
|
33
|
+
const content = await agentsFileText(target, next);
|
|
29
34
|
if (!request.save) {
|
|
30
|
-
await writeAgentsFile(target,
|
|
35
|
+
await writeAgentsFile(target, next);
|
|
31
36
|
factsChanged('levels', 'unsaved');
|
|
32
37
|
if (level !== 'auto')
|
|
33
38
|
mergeEvent('level', target);
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { type HostPartSources } from '@buffcore/contracts/workbench';
|
|
2
|
+
import type { Theme } from '@buffcore/tokens';
|
|
3
|
+
/** What a host adds to the studio's page: its modules and its theme, both checked at start. */
|
|
4
|
+
export interface HostPageOptions {
|
|
5
|
+
/** Trusted modules served by the host, at the places `HostPartSources` names. Requires signIn. */
|
|
6
|
+
hostParts?: HostPartSources;
|
|
7
|
+
/** A host's theme, the same `Theme` as `studioTheme`; refused at start with every problem listed. */
|
|
8
|
+
theme?: Theme;
|
|
9
|
+
}
|
|
2
10
|
/** The page's script, bundled from the admin shell's source (esbuild, a build-time tool). */
|
|
3
11
|
export declare function bundlePage(cli?: string): Promise<string>;
|
|
4
12
|
/** Where a built CLI keeps the page's script. */
|
|
@@ -6,7 +14,7 @@ export declare const builtPage: (cli: string) => string;
|
|
|
6
14
|
/** The page's script: bundled now from source in a checkout, else the one the build made. */
|
|
7
15
|
export declare function pageScript(cli?: string, locale?: 'en' | 'es'): Promise<string>;
|
|
8
16
|
/** The page itself; mounting localizes the title to the studio's chosen language. */
|
|
9
|
-
export declare const pageHtml: (product: string, hostParts?: HostPartSources, local?: boolean) => string;
|
|
17
|
+
export declare const pageHtml: (product: string, hostParts?: HostPartSources, local?: boolean, theme?: Theme) => string;
|
|
10
18
|
/** Programmatic host setup only; reject unsafe maps before creating the server. */
|
|
11
19
|
export declare function checkedHostParts(sources: HostPartSources | undefined, signedIn: boolean): {
|
|
12
20
|
'top.end'?: string | undefined;
|
|
@@ -14,4 +22,14 @@ export declare function checkedHostParts(sources: HostPartSources | undefined, s
|
|
|
14
22
|
'top.below'?: string | undefined;
|
|
15
23
|
'setup.end'?: string | undefined;
|
|
16
24
|
'issues.top'?: string | undefined;
|
|
25
|
+
'side:prototype'?: string | undefined;
|
|
26
|
+
'approve:release'?: string | undefined;
|
|
27
|
+
'card:server'?: string | undefined;
|
|
28
|
+
rail?: {
|
|
29
|
+
id: string;
|
|
30
|
+
label: string;
|
|
31
|
+
source: string;
|
|
32
|
+
icon?: string | undefined;
|
|
33
|
+
}[] | undefined;
|
|
34
|
+
label?: string | undefined;
|
|
17
35
|
} | undefined;
|
package/dist/commands/ui/page.js
CHANGED
|
@@ -18,7 +18,9 @@ const token = root.hasAttribute('data-local-studio')
|
|
|
18
18
|
: new URLSearchParams(location.search).get('token') ?? '';
|
|
19
19
|
const data = document.getElementById('studio-host-parts');
|
|
20
20
|
const hostParts = data ? JSON.parse(data.textContent) : undefined;
|
|
21
|
-
|
|
21
|
+
const look = document.getElementById('studio-theme');
|
|
22
|
+
const theme = look ? JSON.parse(look.textContent) : undefined;
|
|
23
|
+
mountStudio(root, { token, hostParts, theme, locale: document.documentElement.lang || undefined });
|
|
22
24
|
`;
|
|
23
25
|
/** The page's script, bundled from the admin shell's source (esbuild, a build-time tool). */
|
|
24
26
|
export async function bundlePage(cli = runningCli()) {
|
|
@@ -47,14 +49,15 @@ export async function pageScript(cli = runningCli(), locale) {
|
|
|
47
49
|
}
|
|
48
50
|
const escapeHtml = (s) => s.replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c] ?? c);
|
|
49
51
|
/** The page itself; mounting localizes the title to the studio's chosen language. */
|
|
50
|
-
export const pageHtml = (product, hostParts, local = false) => `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escapeHtml(studioT('ui.title', { name: product }))}</title><link rel="stylesheet" href="${FONT_SHEET}" referrerpolicy="no-referrer"></head><body><div id="root"${local ? ' data-local-studio' : ''}></div>${hostPartsData(hostParts)}<script type="module" src="/page.js"></script></body></html>`;
|
|
52
|
+
export const pageHtml = (product, hostParts, local = false, theme) => `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escapeHtml(studioT('ui.title', { name: product }))}</title><link rel="stylesheet" href="${FONT_SHEET}" referrerpolicy="no-referrer"></head><body><div id="root"${local ? ' data-local-studio' : ''}></div>${hostPartsData(hostParts)}${jsonData('studio-theme', theme)}<script type="module" src="/page.js"></script></body></html>`;
|
|
51
53
|
/** JSON data only; HTML delimiters cannot close this element or become executable markup. */
|
|
52
|
-
function
|
|
53
|
-
if (
|
|
54
|
+
function jsonData(id, value) {
|
|
55
|
+
if (value === undefined)
|
|
54
56
|
return '';
|
|
55
|
-
const data = JSON.stringify(
|
|
56
|
-
return `<script id="
|
|
57
|
+
const data = JSON.stringify(value).replace(/[<>&\u2028\u2029]/g, (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`);
|
|
58
|
+
return `<script id="${id}" type="application/json">${data}</script>`;
|
|
57
59
|
}
|
|
60
|
+
const hostPartsData = (sources) => sources ? jsonData('studio-host-parts', hostPartSourcesSchema.parse(sources)) : '';
|
|
58
61
|
/** Programmatic host setup only; reject unsafe maps before creating the server. */
|
|
59
62
|
export function checkedHostParts(sources, signedIn) {
|
|
60
63
|
if (sources === undefined)
|
|
@@ -4,9 +4,16 @@ export interface StructureRow {
|
|
|
4
4
|
who: string;
|
|
5
5
|
place: string;
|
|
6
6
|
main: boolean;
|
|
7
|
+
/** The change that adds this first screen, while its route does not exist yet. */
|
|
8
|
+
planned?: string;
|
|
7
9
|
}
|
|
8
|
-
/**
|
|
9
|
-
export
|
|
10
|
+
/** The screens each change file lists under `touches.screens`, by change id. */
|
|
11
|
+
export type ChangeScreens = ReadonlyMap<string, readonly string[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Planning/build time only. Screen keys are inventory routes or console screen names, or a
|
|
14
|
+
* planned one (`/billing (planned, C-020)`) that the named change lists under its screens.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseStructure(text: string, screens?: readonly string[], changes?: ChangeScreens): {
|
|
10
17
|
rows: StructureRow[];
|
|
11
18
|
notes: string[];
|
|
12
19
|
};
|
|
@@ -13,6 +13,7 @@ export const en = {
|
|
|
13
13
|
'structure.first': '{row} needs a first screen. Choose where this section opens.',
|
|
14
14
|
'structure.key': '{row}: {screen} is not a screen key. Use its route or console screen name.',
|
|
15
15
|
'structure.unknown': '{row}: the first screen {screen} was not found in the product’s screens.',
|
|
16
|
+
'structure.planned': '{row}: {screen} is planned in {change}, but that change does not list it under its screens. Add it there, or name an existing screen.',
|
|
16
17
|
'structure.repeated': '{row}: another section has this name in the same place for the same people.',
|
|
17
18
|
'structure.main': '{row}: Main must be yes or no. File order ranks the main sections.',
|
|
18
19
|
'structure.empty': 'Name at least one section and its first screen.',
|
|
@@ -13,6 +13,7 @@ export const es = {
|
|
|
13
13
|
'structure.first': '{row} necesita una primera pantalla. Elige dónde se abre esta sección.',
|
|
14
14
|
'structure.key': '{row}: {screen} no es una clave de pantalla. Usa su ruta o nombre de pantalla de consola.',
|
|
15
15
|
'structure.unknown': '{row}: no se encontró la primera pantalla {screen} en las pantallas del producto.',
|
|
16
|
+
'structure.planned': '{row}: {screen} está planificada en {change}, pero ese cambio no la incluye en sus pantallas. Añádela allí o usa una pantalla que ya exista.',
|
|
16
17
|
'structure.repeated': '{row}: otra sección tiene este nombre en el mismo lugar para las mismas personas.',
|
|
17
18
|
'structure.main': '{row}: Main debe ser yes o no. El orden del archivo ordena las secciones principales.',
|
|
18
19
|
'structure.empty': 'Nombra al menos una sección y su primera pantalla.',
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { createI18n } from '@buffcore/i18n';
|
|
4
|
+
import { readChanges } from '../change-file.js';
|
|
4
5
|
import { adminScreens, appScreens } from '../inventory-screens.js';
|
|
5
6
|
import { en } from './plan-structure.en.js';
|
|
6
7
|
import { es } from './plan-structure.es.js';
|
|
8
|
+
/** `/billing (planned, C-020)`: a first screen a change adds, before its route exists. */
|
|
9
|
+
const PLANNED = /^(.*\S) \(planned, (C-\d{3,})\)$/u;
|
|
7
10
|
const messages = createI18n({ catalogs: [{ en, es }] });
|
|
8
11
|
const columns = ['Section', 'First screen', 'Who', 'Place', 'Main'];
|
|
9
12
|
function excerpt(value, limit = 60) {
|
|
@@ -83,16 +86,19 @@ function checkColumns(table, t, numbers) {
|
|
|
83
86
|
}));
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
|
-
function structureRows(table, t, screens) {
|
|
89
|
+
function structureRows(table, t, screens, changes) {
|
|
87
90
|
const rows = [];
|
|
88
91
|
const seen = new Set();
|
|
89
92
|
for (const line of table.slice(2)) {
|
|
90
93
|
// Escapes are text only in DATA cells, never in header/separator comparisons.
|
|
91
94
|
const values = cells(line.text).map((cell) => cell.replace(/\\\|/g, '|'));
|
|
92
|
-
const [section = '',
|
|
95
|
+
const [section = '', cell = '', who = '', place = '', main = ''] = values;
|
|
96
|
+
const plan = PLANNED.exec(cell);
|
|
97
|
+
const screen = plan?.[1] ?? cell;
|
|
98
|
+
const change = plan?.[2] ?? '';
|
|
93
99
|
const row = `${sourceName(line, t)}${section ? `: ${excerpt(section)}` : ''}`;
|
|
94
100
|
const fail = (key) => {
|
|
95
|
-
throw new Error(t(key, { row, screen: excerpt(screen) }));
|
|
101
|
+
throw new Error(t(key, { row, screen: excerpt(screen), change }));
|
|
96
102
|
};
|
|
97
103
|
if (values.length !== 5 || !section || !who || !place)
|
|
98
104
|
fail('structure.fields');
|
|
@@ -101,7 +107,12 @@ function structureRows(table, t, screens) {
|
|
|
101
107
|
if (!/^(?:\/|\/?[\p{L}\p{N}_[\]().-]+(?:\/[\p{L}\p{N}_[\]().-]+)*)$/u.test(screen) ||
|
|
102
108
|
screen.split('/').some((part) => part === '.' || part === '..'))
|
|
103
109
|
fail('structure.key');
|
|
104
|
-
|
|
110
|
+
// A planned row turns ordinary once its route exists; until then its change must list it.
|
|
111
|
+
const exists = !!screens?.length && screens.includes(screen);
|
|
112
|
+
const planned = plan && !exists ? change : undefined;
|
|
113
|
+
if (planned && changes && !changes.get(planned)?.includes(screen))
|
|
114
|
+
fail('structure.planned');
|
|
115
|
+
if (!planned && screens?.length && !exists)
|
|
105
116
|
fail('structure.unknown');
|
|
106
117
|
const identity = JSON.stringify([
|
|
107
118
|
section.toLowerCase(),
|
|
@@ -113,20 +124,30 @@ function structureRows(table, t, screens) {
|
|
|
113
124
|
if (!/^(yes|no)$/.test(main))
|
|
114
125
|
fail('structure.main');
|
|
115
126
|
seen.add(identity);
|
|
116
|
-
rows.push({
|
|
127
|
+
rows.push({
|
|
128
|
+
section,
|
|
129
|
+
screen,
|
|
130
|
+
who,
|
|
131
|
+
place,
|
|
132
|
+
main: main === 'yes',
|
|
133
|
+
...(planned ? { planned } : {}),
|
|
134
|
+
});
|
|
117
135
|
}
|
|
118
136
|
if (!rows.length)
|
|
119
137
|
throw new Error(t('structure.empty'));
|
|
120
138
|
return rows;
|
|
121
139
|
}
|
|
122
|
-
/**
|
|
123
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Planning/build time only. Screen keys are inventory routes or console screen names, or a
|
|
142
|
+
* planned one (`/billing (planned, C-020)`) that the named change lists under its screens.
|
|
143
|
+
*/
|
|
144
|
+
export function parseStructure(text, screens, changes) {
|
|
124
145
|
const locale = /^es(?:[-_.]|$)/i.test(process.env.LC_ALL || process.env.LANG || '') ? 'es' : 'en';
|
|
125
146
|
const t = (key, values) => messages.t(locale, key, values);
|
|
126
147
|
const numbers = new Intl.NumberFormat(locale);
|
|
127
148
|
const { table, notes } = structureLines(text, t, numbers);
|
|
128
149
|
checkColumns(table, t, numbers);
|
|
129
|
-
const rows = structureRows(table, t, screens);
|
|
150
|
+
const rows = structureRows(table, t, screens, changes);
|
|
130
151
|
if (!notes.length)
|
|
131
152
|
throw new Error(t('structure.notes'));
|
|
132
153
|
return { rows, notes };
|
|
@@ -140,12 +161,17 @@ export async function readStructure(root) {
|
|
|
140
161
|
});
|
|
141
162
|
if (text === null)
|
|
142
163
|
return null;
|
|
143
|
-
const [app, admin] = await Promise.all([
|
|
164
|
+
const [app, admin, planned] = await Promise.all([
|
|
165
|
+
appScreens(root, root),
|
|
166
|
+
adminScreens(root, root),
|
|
167
|
+
readChanges(root),
|
|
168
|
+
]);
|
|
144
169
|
const screens = [
|
|
145
170
|
...app.map((item) => item.route),
|
|
146
171
|
...admin.flatMap((item) => [item.path, item.screen]),
|
|
147
172
|
];
|
|
148
|
-
|
|
173
|
+
const changes = new Map(planned.changes.map((c) => [c.id, c.touches.screens]));
|
|
174
|
+
return parseStructure(text, screens, changes);
|
|
149
175
|
}
|
|
150
176
|
/** A malformed structure must not hide the rest of an older product's plan. */
|
|
151
177
|
export async function structureFacts(root) {
|
|
@@ -11,10 +11,12 @@ import { writeSync } from 'node:fs';
|
|
|
11
11
|
import { pathToFileURL } from 'node:url';
|
|
12
12
|
try {
|
|
13
13
|
const prototype = (await import(__rewriteRelativeImportExtension(pathToFileURL(process.argv[2] ?? '').href))).default;
|
|
14
|
-
const scenes = prototype.scenes.map(({ key, title, surface }) => ({
|
|
14
|
+
const scenes = prototype.scenes.map(({ key, title, surface, view }) => ({
|
|
15
15
|
key,
|
|
16
16
|
title,
|
|
17
17
|
surface,
|
|
18
|
+
// A named view only; a component has no name the studio can follow to its files.
|
|
19
|
+
...(typeof view === 'string' ? { view } : {}),
|
|
18
20
|
}));
|
|
19
21
|
writeSync(3, JSON.stringify({ ok: true, scenes }));
|
|
20
22
|
process.exit(0);
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { workbenchApi } from '@buffcore/contracts/workbench';
|
|
2
2
|
import { prototypeSceneReader } from './prototype-scenes-read.js';
|
|
3
|
+
/** The route answers scene identities only: a scene's view name stays inside the studio. */
|
|
4
|
+
function identities(reply) {
|
|
5
|
+
return reply.ok
|
|
6
|
+
? { ok: true, scenes: reply.scenes.map(({ key, title, surface }) => ({ key, title, surface })) }
|
|
7
|
+
: reply;
|
|
8
|
+
}
|
|
3
9
|
/** Loading project code needs snapshot authority before the reader can run. */
|
|
4
10
|
export function prototypeScenesRoute(root) {
|
|
5
11
|
const read = prototypeSceneReader(root);
|
|
@@ -9,6 +15,6 @@ export function prototypeScenesRoute(root) {
|
|
|
9
15
|
readable: true,
|
|
10
16
|
right: 'build',
|
|
11
17
|
origin: true,
|
|
12
|
-
handle: async () => ({ status: 200, body: await read() }),
|
|
18
|
+
handle: async () => ({ status: 200, body: identities(await read()) }),
|
|
13
19
|
};
|
|
14
20
|
}
|
|
@@ -30,10 +30,14 @@ async function workingChanged(git, index, files) {
|
|
|
30
30
|
const changed = new Set(diff.split('\0'));
|
|
31
31
|
return files.some((file) => changed.has(file));
|
|
32
32
|
}
|
|
33
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Read the exact saved tree, never a working file that can change after the snapshot. Never ask
|
|
35
|
+
* counts as part of the level: a generic save may change neither.
|
|
36
|
+
*/
|
|
34
37
|
async function levelAt(git, ref, path) {
|
|
35
38
|
try {
|
|
36
|
-
|
|
39
|
+
const file = parseCommittedAgents(await git(['show', `${ref}:./${path}`]));
|
|
40
|
+
return file.neverAsk ? `${file.level}+neverAsk` : file.level;
|
|
37
41
|
}
|
|
38
42
|
catch (error) {
|
|
39
43
|
if (error.code === 'ETIMEDOUT')
|
|
@@ -3,6 +3,7 @@ import { saveHostT, saveTimeout } from './host-save.js';
|
|
|
3
3
|
import { mergeT, mergeTimeout } from './merge-authority.js';
|
|
4
4
|
import { checkedOutside } from './outside.js';
|
|
5
5
|
import { checkedHostParts } from './page.js';
|
|
6
|
+
import { checkedTheme } from './theme-option.js';
|
|
6
7
|
/** Validate host-owned registration before the server starts listening. */
|
|
7
8
|
export function checkedUiOptions(input) {
|
|
8
9
|
if (input.approval && !input.signIn)
|
|
@@ -21,5 +22,6 @@ export function checkedUiOptions(input) {
|
|
|
21
22
|
contained: input.contained === true,
|
|
22
23
|
hostParts: checkedHostParts(input.hostParts, signedIn),
|
|
23
24
|
outside: checkedOutside(input.outside, signedIn),
|
|
25
|
+
theme: checkedTheme(input.theme),
|
|
24
26
|
};
|
|
25
27
|
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { type Server } from 'node:http';
|
|
2
|
-
import type {
|
|
3
|
-
import { type HostPartSources } from '@buffcore/contracts/workbench';
|
|
2
|
+
import type { PlannedChange } from '@buffcore/admin-shell/workbench';
|
|
4
3
|
import type { HostApproval } from './approval-authority.ts';
|
|
5
4
|
import type { TurnMigrations } from './chat/migration-turn.ts';
|
|
6
5
|
import { type LocalCode } from './code.ts';
|
|
7
|
-
import {
|
|
6
|
+
import type { CommandSpec } from './commands.ts';
|
|
8
7
|
import { type HostLevel, type SignIn } from './host.ts';
|
|
9
8
|
import type { SaveConfiguration } from './host-save.ts';
|
|
10
9
|
import type { HostMerge } from './merge-authority.ts';
|
|
11
10
|
import type { OutsideConfiguration } from './outside.ts';
|
|
11
|
+
import { type HostPageOptions } from './page.ts';
|
|
12
12
|
import { type UiRoute } from './routes.ts';
|
|
13
13
|
import type { Runner } from './runner.ts';
|
|
14
|
-
import { type DiagnosticRun } from './snapshot-diagnostics.ts';
|
|
15
14
|
import type { Stack } from './stack.ts';
|
|
16
15
|
export type { Machine, Right, Viewer } from '@buffcore/contracts/workbench';
|
|
17
16
|
export type { ApprovalArtifact, HostApproval, HostApprovalAnswer } from './approval-authority.ts';
|
|
@@ -28,6 +27,7 @@ export { type AgentTurn, Runner, type Start } from './runner.ts';
|
|
|
28
27
|
export { coreRoutes, stateAccess } from './server-core.ts';
|
|
29
28
|
export { listenLocal } from './server-request.ts';
|
|
30
29
|
export type { DiagnosticRun, StoredRuns } from './snapshot-diagnostics.ts';
|
|
30
|
+
export { recordPrototypeRun, runPrototypeSnapshot } from './snapshot-runners.ts';
|
|
31
31
|
export { diagnosticsView, runView, visibleRuns } from './snapshot-view.ts';
|
|
32
32
|
export { Stack } from './stack.ts';
|
|
33
33
|
export { studioRoutes } from './studio-routes.ts';
|
|
@@ -39,7 +39,7 @@ export interface Plan {
|
|
|
39
39
|
/** The product has `prototype/home.tsx`. */
|
|
40
40
|
prototypeHome: boolean;
|
|
41
41
|
}
|
|
42
|
-
export interface UiServerOptions extends SaveConfiguration, OutsideConfiguration {
|
|
42
|
+
export interface UiServerOptions extends SaveConfiguration, OutsideConfiguration, HostPageOptions {
|
|
43
43
|
turnMigrations?: TurnMigrations;
|
|
44
44
|
snapshotLimits?: CommandSpec['limits'];
|
|
45
45
|
/** Required for local use; ignored when the host supplies signIn. */
|
|
@@ -51,8 +51,6 @@ export interface UiServerOptions extends SaveConfiguration, OutsideConfiguration
|
|
|
51
51
|
approval?: HostApproval;
|
|
52
52
|
merge?: HostMerge;
|
|
53
53
|
mergeTimeoutMs?: number;
|
|
54
|
-
/** Trusted modules served by the host, at five existing places. Requires signIn. */
|
|
55
|
-
hostParts?: HostPartSources;
|
|
56
54
|
/** Host-owned isolation boundary; never inferred from product inputs. */
|
|
57
55
|
contained?: boolean;
|
|
58
56
|
product: string;
|
|
@@ -65,20 +63,5 @@ export interface UiServerOptions extends SaveConfiguration, OutsideConfiguration
|
|
|
65
63
|
/** More of the API: each part of the workbench adds its routes (routes.ts). */
|
|
66
64
|
routes?: readonly UiRoute[];
|
|
67
65
|
}
|
|
68
|
-
type DiagnosticId = 'snapshot' | 'post-merge' | `snapshot:${string}` | `post-merge:${string}` | `snapshot-check:${string}` | `compare:${string}`;
|
|
69
|
-
export declare function recordPrototypeRun<T extends string>(root: string, id: T, run?: T extends DiagnosticId ? DiagnosticRun : CommandRun | DiagnosticRun): void;
|
|
70
|
-
/** Autopilot starts its own fresh run on the same runner as the person's Snapshot command. */
|
|
71
|
-
export declare function runPrototypeSnapshot(root: string, signal?: AbortSignal, id?: string, options?: {
|
|
72
|
-
cwd: string;
|
|
73
|
-
scenes?: readonly string[];
|
|
74
|
-
commit?: string;
|
|
75
|
-
command?: string;
|
|
76
|
-
json?: boolean;
|
|
77
|
-
limits?: CommandSpec['limits'];
|
|
78
|
-
snapshotRunId?: string;
|
|
79
|
-
/** Keep only the problems the result lists, not the progress lines the tool printed. */
|
|
80
|
-
listedOnly?: boolean;
|
|
81
|
-
onSnapshotProgress?: CommandSpec['onSnapshotProgress'];
|
|
82
|
-
}): Promise<DiagnosticRun | undefined>;
|
|
83
66
|
/** The server, not yet listening. Local callers use listenLocal; a host owns its listener. */
|
|
84
67
|
export declare function createUiServer(input: UiServerOptions): Server;
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
// The workbench's page and JSON API: local Host/token guards, or the host's sign-in per request.
|
|
2
|
-
import { existsSync, realpathSync } from 'node:fs';
|
|
3
2
|
import { createServer } from 'node:http';
|
|
4
|
-
import { resolve } from 'node:path';
|
|
5
3
|
import { workbenchApi } from '@buffcore/contracts/workbench';
|
|
6
4
|
import { migrationRoute } from '../migrate-create-protocol.js';
|
|
7
5
|
import { MilestoneVersionsPending } from '../prototype/milestone-key.js';
|
|
8
|
-
import { snapshotsDir } from '../prototype/report.js';
|
|
9
|
-
import { cleanSnapshotChild } from '../prototype/snapshot-storage.js';
|
|
10
6
|
import { scrubLaunchIds } from './chat/launch-ids.js';
|
|
11
7
|
import { exchangeCode } from './code.js';
|
|
12
|
-
import { commandFor } from './commands.js';
|
|
13
8
|
import { studioFont } from './fonts.js';
|
|
14
9
|
import { allowedHost, allowedToken } from './guard.js';
|
|
15
10
|
import { denied, hostT, localIdentity, requestRefusal, routeRight, signedIn, } from './host.js';
|
|
@@ -19,7 +14,7 @@ import { matchRoute, sendPng } from './routes.js';
|
|
|
19
14
|
import { coreRoutes } from './server-core.js';
|
|
20
15
|
import { checkedUiOptions } from './server-options.js';
|
|
21
16
|
import { localListener, migrationSignal, requestContext } from './server-request.js';
|
|
22
|
-
import {
|
|
17
|
+
import { runnerKey, snapshotRunners } from './snapshot-runners.js';
|
|
23
18
|
import { studioT } from './studio-messages.js';
|
|
24
19
|
export { chatRoutes } from './chat/routes.js';
|
|
25
20
|
export { ChatEngine } from './chat/turn.js';
|
|
@@ -28,6 +23,7 @@ export { readProductPlan } from './product-plan.js';
|
|
|
28
23
|
export { Runner } from './runner.js';
|
|
29
24
|
export { coreRoutes, stateAccess } from './server-core.js';
|
|
30
25
|
export { listenLocal } from './server-request.js';
|
|
26
|
+
export { recordPrototypeRun, runPrototypeSnapshot } from './snapshot-runners.js';
|
|
31
27
|
export { diagnosticsView, runView, visibleRuns } from './snapshot-view.js';
|
|
32
28
|
export { Stack } from './stack.js';
|
|
33
29
|
export { studioRoutes } from './studio-routes.js';
|
|
@@ -37,44 +33,6 @@ const LOCAL_PAGE_HEADERS = {
|
|
|
37
33
|
'x-frame-options': 'DENY',
|
|
38
34
|
'referrer-policy': 'no-referrer',
|
|
39
35
|
};
|
|
40
|
-
const snapshotRunners = new Map();
|
|
41
|
-
const runnerKey = (root) => (existsSync(root) ? realpathSync.native(root) : resolve(root));
|
|
42
|
-
export function recordPrototypeRun(root, id, run) {
|
|
43
|
-
snapshotRunners.get(runnerKey(root))?.record(id, run);
|
|
44
|
-
}
|
|
45
|
-
/** Autopilot starts its own fresh run on the same runner as the person's Snapshot command. */
|
|
46
|
-
export function runPrototypeSnapshot(root, signal, id = 'snapshot', options) {
|
|
47
|
-
const runner = snapshotRunners.get(runnerKey(root));
|
|
48
|
-
const spec = options?.command
|
|
49
|
-
? { program: 'shell', args: [options.command], json: options.json ?? false }
|
|
50
|
-
: commandFor('snapshot', { seeds: [], changes: [], scenes: options?.scenes });
|
|
51
|
-
if (!runner || !spec)
|
|
52
|
-
return Promise.resolve(undefined);
|
|
53
|
-
const child = options
|
|
54
|
-
? {
|
|
55
|
-
...spec,
|
|
56
|
-
cwd: options.cwd,
|
|
57
|
-
validationCommit: options.commit,
|
|
58
|
-
limits: options.limits,
|
|
59
|
-
onSnapshotProgress: options.onSnapshotProgress,
|
|
60
|
-
...(options.snapshotRunId ? { snapshotRunId: options.snapshotRunId } : {}),
|
|
61
|
-
}
|
|
62
|
-
: spec;
|
|
63
|
-
return new Promise((resolve) => {
|
|
64
|
-
const finish = async () => {
|
|
65
|
-
const run = runner.all()[id];
|
|
66
|
-
if (options?.snapshotRunId) {
|
|
67
|
-
// Leftover folders are tidied here, not judged: a child that published its whole snapshot
|
|
68
|
-
// passed, and a folder that cannot be removed now is removed by the next recovery.
|
|
69
|
-
await cleanSnapshotChild(snapshotsDir(options.cwd), options.snapshotRunId).catch(() => { });
|
|
70
|
-
}
|
|
71
|
-
resolve(run ? captureRecordedRun(options?.cwd ?? root, run) : undefined);
|
|
72
|
-
};
|
|
73
|
-
const started = runner.run(id, child, finish, signal);
|
|
74
|
-
if (!started)
|
|
75
|
-
resolve(undefined);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
36
|
function send(res, status, body, type = 'application/json', extra = {}) {
|
|
79
37
|
res.writeHead(status, {
|
|
80
38
|
'content-type': `${type}; charset=utf-8`,
|
|
@@ -136,7 +94,7 @@ async function handleRequest(options, routes, req, res, port, script, shutdown)
|
|
|
136
94
|
...headers,
|
|
137
95
|
location: `${localStudioOrigin(port)}/${search}`,
|
|
138
96
|
});
|
|
139
|
-
return send(res, 200, pageHtml(options.product, options.hostParts, !options.signIn), 'text/html', headers);
|
|
97
|
+
return send(res, 200, pageHtml(options.product, options.hostParts, !options.signIn, options.theme), 'text/html', headers);
|
|
140
98
|
}
|
|
141
99
|
if (req.method === 'GET' && path === '/page.js')
|
|
142
100
|
return send(res, 200, await script(), 'text/javascript');
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CommandRun } from '@buffcore/admin-shell/workbench';
|
|
2
|
+
import { type CommandSpec } from './commands.ts';
|
|
3
|
+
import type { Runner } from './runner.ts';
|
|
4
|
+
import { type DiagnosticRun } from './snapshot-diagnostics.ts';
|
|
5
|
+
export declare const snapshotRunners: Map<string, Runner>;
|
|
6
|
+
export declare const runnerKey: (root: string) => string;
|
|
7
|
+
type DiagnosticId = 'snapshot' | 'post-merge' | `snapshot:${string}` | `post-merge:${string}` | `snapshot-check:${string}` | `compare:${string}`;
|
|
8
|
+
export declare function recordPrototypeRun<T extends string>(root: string, id: T, run?: T extends DiagnosticId ? DiagnosticRun : CommandRun | DiagnosticRun): void;
|
|
9
|
+
/** Autopilot starts its own fresh run on the same runner as the person's Snapshot command. */
|
|
10
|
+
export declare function runPrototypeSnapshot(root: string, signal?: AbortSignal, id?: string, options?: {
|
|
11
|
+
cwd: string;
|
|
12
|
+
scenes?: readonly string[];
|
|
13
|
+
commit?: string;
|
|
14
|
+
command?: string;
|
|
15
|
+
json?: boolean;
|
|
16
|
+
limits?: CommandSpec['limits'];
|
|
17
|
+
snapshotRunId?: string;
|
|
18
|
+
/** Keep only the problems the result lists, not the progress lines the tool printed. */
|
|
19
|
+
listedOnly?: boolean;
|
|
20
|
+
onSnapshotProgress?: CommandSpec['onSnapshotProgress'];
|
|
21
|
+
}): Promise<DiagnosticRun | undefined>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// The prototype snapshot runners the studio's servers register, one per product folder.
|
|
2
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { snapshotsDir } from '../prototype/report.js';
|
|
5
|
+
import { cleanSnapshotChild } from '../prototype/snapshot-storage.js';
|
|
6
|
+
import { commandFor } from './commands.js';
|
|
7
|
+
import { captureRecordedRun } from './snapshot-diagnostics.js';
|
|
8
|
+
export const snapshotRunners = new Map();
|
|
9
|
+
export const runnerKey = (root) => existsSync(root) ? realpathSync.native(root) : resolve(root);
|
|
10
|
+
export function recordPrototypeRun(root, id, run) {
|
|
11
|
+
snapshotRunners.get(runnerKey(root))?.record(id, run);
|
|
12
|
+
}
|
|
13
|
+
/** Autopilot starts its own fresh run on the same runner as the person's Snapshot command. */
|
|
14
|
+
export function runPrototypeSnapshot(root, signal, id = 'snapshot', options) {
|
|
15
|
+
const runner = snapshotRunners.get(runnerKey(root));
|
|
16
|
+
const spec = options?.command
|
|
17
|
+
? { program: 'shell', args: [options.command], json: options.json ?? false }
|
|
18
|
+
: commandFor('snapshot', { seeds: [], changes: [], scenes: options?.scenes });
|
|
19
|
+
if (!runner || !spec)
|
|
20
|
+
return Promise.resolve(undefined);
|
|
21
|
+
const child = options
|
|
22
|
+
? {
|
|
23
|
+
...spec,
|
|
24
|
+
cwd: options.cwd,
|
|
25
|
+
validationCommit: options.commit,
|
|
26
|
+
limits: options.limits,
|
|
27
|
+
onSnapshotProgress: options.onSnapshotProgress,
|
|
28
|
+
...(options.snapshotRunId ? { snapshotRunId: options.snapshotRunId } : {}),
|
|
29
|
+
}
|
|
30
|
+
: spec;
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
const finish = async () => {
|
|
33
|
+
const run = runner.all()[id];
|
|
34
|
+
if (options?.snapshotRunId) {
|
|
35
|
+
// Leftover folders are tidied here, not judged: a child that published its whole snapshot
|
|
36
|
+
// passed, and a folder that cannot be removed now is removed by the next recovery.
|
|
37
|
+
await cleanSnapshotChild(snapshotsDir(options.cwd), options.snapshotRunId).catch(() => { });
|
|
38
|
+
}
|
|
39
|
+
resolve(run ? captureRecordedRun(options?.cwd ?? root, run) : undefined);
|
|
40
|
+
};
|
|
41
|
+
const started = runner.run(id, child, finish, signal);
|
|
42
|
+
if (!started)
|
|
43
|
+
resolve(undefined);
|
|
44
|
+
});
|
|
45
|
+
}
|