@buffcore/cli 0.8.43 → 0.8.45
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 +28 -0
- package/dist/commands/prototype/mark-shot.d.ts +31 -0
- package/dist/commands/prototype/mark-shot.js +149 -0
- package/dist/commands/ui/chat/approval-folders.d.ts +20 -0
- package/dist/commands/ui/chat/approval-folders.js +134 -0
- package/dist/commands/ui/chat/approval-text.d.ts +11 -0
- package/dist/commands/ui/chat/approval-text.js +69 -0
- package/dist/commands/ui/chat/approval-writes.d.ts +32 -0
- package/dist/commands/ui/chat/approval-writes.js +179 -0
- package/dist/commands/ui/chat/claude-permissions.d.ts +4 -4
- package/dist/commands/ui/chat/claude-permissions.js +32 -4
- package/dist/commands/ui/chat/codex-idle.d.ts +1 -1
- package/dist/commands/ui/chat/commit-limits.d.ts +36 -0
- package/dist/commands/ui/chat/commit-limits.js +164 -0
- package/dist/commands/ui/chat/fresh-critique.js +3 -1
- package/dist/commands/ui/chat/fresh-launch.d.ts +5 -0
- package/dist/commands/ui/chat/fresh-launch.js +7 -4
- package/dist/commands/ui/chat/fresh.js +7 -1
- package/dist/commands/ui/chat/gh-api-limits.d.ts +14 -0
- package/dist/commands/ui/chat/gh-api-limits.js +74 -0
- package/dist/commands/ui/chat/git-words.d.ts +10 -0
- package/dist/commands/ui/chat/git-words.js +26 -0
- package/dist/commands/ui/chat/host-launched.d.ts +11 -0
- package/dist/commands/ui/chat/host-launched.js +35 -0
- package/dist/commands/ui/chat/limit-mentions.js +16 -2
- package/dist/commands/ui/chat/limit-text.d.ts +15 -0
- package/dist/commands/ui/chat/limit-text.js +36 -0
- package/dist/commands/ui/chat/limits-hook.js +2 -2
- package/dist/commands/ui/chat/limits.d.ts +7 -12
- package/dist/commands/ui/chat/limits.en.d.ts +2 -0
- package/dist/commands/ui/chat/limits.en.js +2 -0
- package/dist/commands/ui/chat/limits.es.js +2 -0
- package/dist/commands/ui/chat/limits.js +63 -59
- package/dist/commands/ui/chat/planning-limits.js +11 -0
- package/dist/commands/ui/chat/publish-limits.js +23 -7
- package/dist/commands/ui/chat/turn-guard.d.ts +8 -2
- package/dist/commands/ui/chat/turn-guard.js +8 -3
- package/dist/commands/ui/commands.en.d.ts +3 -0
- package/dist/commands/ui/commands.en.js +3 -0
- package/dist/commands/ui/commands.es.d.ts +3 -0
- package/dist/commands/ui/commands.es.js +3 -0
- package/dist/commands/ui/index.d.ts +42 -0
- package/dist/commands/ui/index.js +14 -2
- package/dist/commands/ui/plan-brief.d.ts +13 -0
- package/dist/commands/ui/plan-brief.js +91 -0
- package/dist/commands/ui/plan-files.d.ts +1 -11
- package/dist/commands/ui/plan-files.js +2 -48
- package/dist/commands/ui/prototype-main.d.ts +5 -0
- package/dist/commands/ui/prototype-shot-route.d.ts +16 -0
- package/dist/commands/ui/prototype-shot-route.js +98 -0
- package/dist/commands/ui/routes.d.ts +2 -0
- package/dist/commands/ui/server-core.js +2 -0
- package/dist/commands/ui/server-options.js +1 -0
- package/dist/commands/ui/server-request.js +5 -0
- package/dist/commands/ui/server.d.ts +7 -0
- package/dist/commands/ui/server.js +16 -1
- package/dist/commands/ui/studio-routes.d.ts +1 -0
- package/dist/commands/ui/studio-routes.js +3 -1
- package/dist/commands/ui/studio-state.d.ts +6 -0
- package/dist/ui/page.js +114 -95
- package/docs/PROTOTYPE.md +14 -2
- package/docs/WORKBENCH.md +12 -3
- package/package.json +11 -11
- package/skills/ape-plan-change/SKILL.md +8 -0
- package/templates/product/plan/brief.md +29 -0
|
@@ -25,6 +25,9 @@ export declare const en: {
|
|
|
25
25
|
'ui.compare.noGit': string;
|
|
26
26
|
'ui.compare.unexpected': string;
|
|
27
27
|
'ui.snapshot.noChange': string;
|
|
28
|
+
'ui.shot.invalid': string;
|
|
29
|
+
'ui.shot.notRunning': string;
|
|
30
|
+
'ui.shot.failed': string;
|
|
28
31
|
'ui.snapshot.readFailed': string;
|
|
29
32
|
'ui.snapshot.proof': string;
|
|
30
33
|
'ui.snapshot.linked': string;
|
|
@@ -25,6 +25,9 @@ export const en = {
|
|
|
25
25
|
'ui.compare.noGit': 'Git could not read the repository history. Check the checkout and make sure the commits for the comparison are available.',
|
|
26
26
|
'ui.compare.unexpected': 'The comparison failed unexpectedly. Run pnpm ape prototype versions --json. If that fails, check the change’s file in prototype/versions/. If the versions look right, report the comparison failure.',
|
|
27
27
|
'ui.snapshot.noChange': 'There is no change selected for a snapshot.',
|
|
28
|
+
'ui.shot.invalid': 'The studio asked for a picture it cannot take.',
|
|
29
|
+
'ui.shot.notRunning': 'The app is not running, so its marked screen cannot be shot.',
|
|
30
|
+
'ui.shot.failed': 'The marked screen could not be shot: {reason}',
|
|
28
31
|
'ui.snapshot.readFailed': 'Git could not read the saved source.',
|
|
29
32
|
'ui.snapshot.proof': 'Record version needs unchanged passing snapshot proof for this change, saved source and checkout. Save the review files and take a new snapshot if needed.',
|
|
30
33
|
'ui.snapshot.linked': '{coding, select, yes {{here, select, yes {This studio is open in the checkout where {change} is being built} other {{change} is being built in its own checkout}}. Its approved prototype is on main, so there is nothing to record from that checkout. Take snapshot draws it there with its own servers, and Save keeps its snapshot files on the change’s branch.} other {{here, select, yes {This studio is open in {change}’s own checkout} other {{change} is checked out in {path}}}. Take snapshot draws it there with its own servers, and Save keeps its snapshot files on the change’s branch. The studio records only on main, so in a terminal in {here, select, yes {this folder} other {that folder}}: commit all its changes and the new prototype/snapshots folder, then run pnpm ape prototype version {change} --why "what changed".}}',
|
|
@@ -25,6 +25,9 @@ export declare const es: {
|
|
|
25
25
|
'ui.compare.noGit': string;
|
|
26
26
|
'ui.compare.unexpected': string;
|
|
27
27
|
'ui.snapshot.noChange': string;
|
|
28
|
+
'ui.shot.invalid': string;
|
|
29
|
+
'ui.shot.notRunning': string;
|
|
30
|
+
'ui.shot.failed': string;
|
|
28
31
|
'ui.snapshot.readFailed': string;
|
|
29
32
|
'ui.snapshot.proof': string;
|
|
30
33
|
'ui.snapshot.linked': string;
|
|
@@ -25,6 +25,9 @@ export const es = {
|
|
|
25
25
|
'ui.compare.noGit': 'Git no pudo leer el historial del repositorio. Revisa la copia de trabajo y comprueba que los commits de la comparación estén disponibles.',
|
|
26
26
|
'ui.compare.unexpected': 'La comparación falló de forma inesperada. Ejecuta pnpm ape prototype versions --json. Si ese comando falla, revisa el archivo del cambio en prototype/versions/. Si las versiones son correctas, informa del fallo de la comparación.',
|
|
27
27
|
'ui.snapshot.noChange': 'No hay ningún cambio seleccionado para una instantánea.',
|
|
28
|
+
'ui.shot.invalid': 'El estudio pidió una imagen que no se puede tomar.',
|
|
29
|
+
'ui.shot.notRunning': 'La app no está en marcha, así que no se puede capturar la pantalla marcada.',
|
|
30
|
+
'ui.shot.failed': 'No se pudo capturar la pantalla marcada: {reason}',
|
|
28
31
|
'ui.snapshot.readFailed': 'Git no pudo leer el código guardado.',
|
|
29
32
|
'ui.snapshot.proof': 'Registrar versión necesita una prueba de captura válida y sin cambios para este cambio, código guardado y copia de trabajo. Guarda los archivos de revisión y toma una nueva captura si es necesario.',
|
|
30
33
|
'ui.snapshot.linked': '{coding, select, yes {{here, select, yes {Este estudio está abierto en la copia de trabajo donde se está construyendo {change}} other {{change} se está construyendo en su propia copia de trabajo}}. Su prototipo aprobado está en main, así que no hay nada que registrar desde esa copia de trabajo. Tomar instantánea la dibuja allí con sus propios servidores, y Guardar conserva los archivos de su instantánea en la rama del cambio.} other {{here, select, yes {Este estudio está abierto en la copia de trabajo propia de {change}} other {{change} está en la copia de trabajo {path}}}. Tomar instantánea la dibuja allí con sus propios servidores, y Guardar conserva los archivos de su instantánea en la rama del cambio. El estudio registra solo en main, así que en una terminal en {here, select, yes {esta carpeta} other {esa carpeta}}: haz commit de todos sus cambios y de la nueva carpeta prototype/snapshots, y luego ejecuta pnpm ape prototype version {change} --why "qué cambió".}}',
|
|
@@ -5,6 +5,48 @@ export interface UiOptions {
|
|
|
5
5
|
studio?: boolean;
|
|
6
6
|
lang?: string;
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* The environment `ape ui` was started with, copied before the product's `.env` is loaded (it is
|
|
10
|
+
* what agent turns get), then the product's settings. Only that copy can turn on the host-launched
|
|
11
|
+
* mode: a value an agent writes into the product's `.env` never counts.
|
|
12
|
+
*/
|
|
13
|
+
export declare function uiEnvironment(root: string): {
|
|
14
|
+
agentEnvironment: {
|
|
15
|
+
[key: string]: string | undefined;
|
|
16
|
+
};
|
|
17
|
+
env: {
|
|
18
|
+
APE_ENV: "development" | "production" | "staging" | "test";
|
|
19
|
+
APE_RELEASE: string;
|
|
20
|
+
APE_LOG_LEVEL: "debug" | "error" | "fatal" | "info" | "trace" | "warn";
|
|
21
|
+
DATABASE_URL: string;
|
|
22
|
+
REDIS_URL: string;
|
|
23
|
+
APE_REDIS_PREFIX?: string | undefined;
|
|
24
|
+
APE_API_PORT: number;
|
|
25
|
+
APE_API_URL: string;
|
|
26
|
+
APE_WORKER_CONCURRENCY: number;
|
|
27
|
+
APE_ADMIN_URL: string;
|
|
28
|
+
APE_APP_URL: string;
|
|
29
|
+
APE_HOST: string;
|
|
30
|
+
APE_AUTH_SECRET: string;
|
|
31
|
+
APE_ENCRYPTION_KEY: string;
|
|
32
|
+
APE_S3_ENDPOINT?: string | undefined;
|
|
33
|
+
APE_S3_REGION: string;
|
|
34
|
+
APE_S3_BUCKET: string;
|
|
35
|
+
APE_S3_ACCESS_KEY?: string | undefined;
|
|
36
|
+
APE_S3_SECRET_KEY?: string | undefined;
|
|
37
|
+
APE_AI_MODE: "fixture" | "live" | "record";
|
|
38
|
+
APE_ALLOW_LIVE_AI: boolean;
|
|
39
|
+
ANTHROPIC_API_KEY?: string | undefined;
|
|
40
|
+
OPENAI_API_KEY?: string | undefined;
|
|
41
|
+
GOOGLE_VERTEX_API_KEY?: string | undefined;
|
|
42
|
+
GOOGLE_VERTEX_PROJECT?: string | undefined;
|
|
43
|
+
GOOGLE_VERTEX_LOCATION: string;
|
|
44
|
+
APE_BACKUP_KEY?: string | undefined;
|
|
45
|
+
TURNSTILE_SITE_KEY?: string | undefined;
|
|
46
|
+
TURNSTILE_SECRET_KEY?: string | undefined;
|
|
47
|
+
};
|
|
48
|
+
hostLaunched: boolean;
|
|
49
|
+
};
|
|
8
50
|
export declare function ui(options: UiOptions): Promise<void>;
|
|
9
51
|
/** `ape ui [--port <n>] [--no-open] [--lang <en|es>]` on the CLI's program. */
|
|
10
52
|
export declare function addUiCommand(program: Command): void;
|
|
@@ -7,6 +7,7 @@ import { InvalidArgumentError } from 'commander';
|
|
|
7
7
|
import { findRoot, loadEnv, loadProduct } from '../../project.js';
|
|
8
8
|
import { FreshLooks } from './chat/fresh.js';
|
|
9
9
|
import { freshRoutes } from './chat/fresh-routes.js';
|
|
10
|
+
import { hostLaunchedEnv } from './chat/host-launched.js';
|
|
10
11
|
import { TurnMigrations } from './chat/migration-turn.js';
|
|
11
12
|
import { agentStart } from './chat/process.js';
|
|
12
13
|
import { chatRoutes } from './chat/routes.js';
|
|
@@ -43,13 +44,22 @@ function openBrowser(url) {
|
|
|
43
44
|
.on('error', () => { })
|
|
44
45
|
.unref();
|
|
45
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* The environment `ape ui` was started with, copied before the product's `.env` is loaded (it is
|
|
49
|
+
* what agent turns get), then the product's settings. Only that copy can turn on the host-launched
|
|
50
|
+
* mode: a value an agent writes into the product's `.env` never counts.
|
|
51
|
+
*/
|
|
52
|
+
export function uiEnvironment(root) {
|
|
53
|
+
const agentEnvironment = { ...process.env };
|
|
54
|
+
const env = loadEnv(root);
|
|
55
|
+
return { agentEnvironment, env, hostLaunched: hostLaunchedEnv(agentEnvironment) };
|
|
56
|
+
}
|
|
46
57
|
export async function ui(options) {
|
|
47
58
|
const locale = options.lang === undefined ? undefined : uiLocale(options.lang);
|
|
48
59
|
if (options.studio)
|
|
49
60
|
console.log(t('ui.studio.noop', undefined, locale));
|
|
50
61
|
const root = findRoot();
|
|
51
|
-
const agentEnvironment
|
|
52
|
-
const env = loadEnv(root);
|
|
62
|
+
const { agentEnvironment, env, hostLaunched } = uiEnvironment(root);
|
|
53
63
|
const { name } = await loadProduct(root);
|
|
54
64
|
const port = options.port ? Number(options.port) : defaultStudioPort(env.APE_API_PORT);
|
|
55
65
|
const token = newToken();
|
|
@@ -72,6 +82,8 @@ export async function ui(options) {
|
|
|
72
82
|
const server = createUiServer({
|
|
73
83
|
turnMigrations: migrations,
|
|
74
84
|
contained: false,
|
|
85
|
+
// A host that starts `ape ui` under its own trusted launcher sets APE_HOST_LAUNCHED=1.
|
|
86
|
+
hostLaunched,
|
|
75
87
|
token,
|
|
76
88
|
code,
|
|
77
89
|
product: name,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PlanFacts } from '@buffcore/contracts/workbench';
|
|
2
|
+
export declare const withoutComments: (text: string) => string;
|
|
3
|
+
export declare const answer: (text: string) => string;
|
|
4
|
+
export declare const plain: (text: string) => string;
|
|
5
|
+
/** A newline wraps a paragraph or list item; only a new marker starts another item. */
|
|
6
|
+
export declare function briefSection(text: string, words?: (text: string) => string): string;
|
|
7
|
+
/** Section spelling, fences and closing hashes follow the original Brief reader. */
|
|
8
|
+
export declare function planSections(text: string): {
|
|
9
|
+
heading: string;
|
|
10
|
+
body: string;
|
|
11
|
+
}[];
|
|
12
|
+
/** Section headings stay as written; the template's prompts are not answers. */
|
|
13
|
+
export declare function parseBrief(text: string | null): PlanFacts['brief'];
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export const withoutComments = (text) => text.replace(/<!--[\s\S]*?(?:-->|$)/g, '');
|
|
2
|
+
// The base readers' grammar, shared by bounded plan previews as well as Brief and Roadmap.
|
|
3
|
+
export const answer = (text) => text
|
|
4
|
+
// Without a closing > the tag alternative cannot match. Keep the original code grammar.
|
|
5
|
+
.replace(text.includes('>') ? /`+([^`]*)`+|<[^>]*>/g : /`+([^`]*)`+/g, (_match, code) => code ?? '')
|
|
6
|
+
.replace(/^\s*(?:[-*+]|\d+[.)])\s*$/gm, '')
|
|
7
|
+
.trim();
|
|
8
|
+
export const plain = (text) => {
|
|
9
|
+
const words = answer(text);
|
|
10
|
+
// The original link expression cannot match without ](. This guard changes no output.
|
|
11
|
+
return (words.includes('](') ? words.replace(/!?\[([^\]]*)\]\((?:[^()]|\([^()]*\))*\)/g, '$1') : words).replace(/\*\*|__|`/g, '');
|
|
12
|
+
};
|
|
13
|
+
/** A newline wraps a paragraph or list item; only a new marker starts another item. */
|
|
14
|
+
export function briefSection(text, words = plain) {
|
|
15
|
+
const lines = [];
|
|
16
|
+
for (const raw of words(text).split(/\r?\n/)) {
|
|
17
|
+
const line = raw.trim();
|
|
18
|
+
const marker = /^(?:[-*+]|\d+[.)])\s+/;
|
|
19
|
+
if (marker.test(line))
|
|
20
|
+
lines.push(line.replace(marker, '- '));
|
|
21
|
+
else if (line && lines.at(-1))
|
|
22
|
+
lines[lines.length - 1] += ` ${line}`;
|
|
23
|
+
else
|
|
24
|
+
lines.push(line);
|
|
25
|
+
}
|
|
26
|
+
return lines.join('\n').trim();
|
|
27
|
+
}
|
|
28
|
+
/** Section spelling, fences and closing hashes follow the original Brief reader. */
|
|
29
|
+
export function planSections(text) {
|
|
30
|
+
return text
|
|
31
|
+
.split(/^##\s+/m)
|
|
32
|
+
.slice(1)
|
|
33
|
+
.map((part) => {
|
|
34
|
+
const [heading = '', ...body] = part.split(/\r?\n/);
|
|
35
|
+
return { heading: heading.trim(), body: body.join('\n') };
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A section's short form: `> Summary: one line`, as many as the section needs (one per role). Also
|
|
40
|
+
* `> Resumen:`, and the word in bold.
|
|
41
|
+
*/
|
|
42
|
+
const SUMMARY = /^\s*>\s*(?:\*\*|__)?(?:summary|resumen)(?:\*\*|__)?\s*:\s*(?:\*\*|__)?\s*(.*)$/i;
|
|
43
|
+
/**
|
|
44
|
+
* The template's prompts, in their own form: a line (or a list item) that is all `<Words...>`, the
|
|
45
|
+
* first a capital, wrapping onto the next lines with no blank line between, and never holding an
|
|
46
|
+
* address (`://`, `@`) or another `<` or `>`. Nothing else is taken for a tag: `age < 18`,
|
|
47
|
+
* `<https://...>` and `<help@...>` are the person's words, and the studio shows them as text.
|
|
48
|
+
*/
|
|
49
|
+
const PROMPT = /^[ \t]*(?:(?:[-*+]|\d+[.)])[ \t]+)?<(?=[A-Z])(?![^>]*:\/\/)[^<>@\n]*(?:\n[ \t]*[^<>@\s][^<>@\n]*)*>[ \t]*$/gm;
|
|
50
|
+
/** The brief's words: the base grammar, without reading `<` and `>` as tags. */
|
|
51
|
+
const briefWords = (text) => text
|
|
52
|
+
.replace(/`+([^`]*)`+/g, '$1')
|
|
53
|
+
.replace(/!?\[([^\]]*)\]\((?:[^()]|\([^()]*\))*\)/g, '$1')
|
|
54
|
+
.replace(/\*\*|__/g, '')
|
|
55
|
+
.replace(/^\s*(?:[-*+]|\d+[.)])\s*$/gm, '')
|
|
56
|
+
.trim();
|
|
57
|
+
/**
|
|
58
|
+
* One section: its summary lines (template prompts and Markdown removed), and the rest as written,
|
|
59
|
+
* without the template's `<prompts>`, for reading.
|
|
60
|
+
*/
|
|
61
|
+
function briefPart(heading, body) {
|
|
62
|
+
const lines = body.split(/\r?\n/);
|
|
63
|
+
const summary = lines.flatMap((line) => {
|
|
64
|
+
const words = plain(SUMMARY.exec(line)?.[1] ?? '');
|
|
65
|
+
return words ? [words] : [];
|
|
66
|
+
});
|
|
67
|
+
const rest = lines
|
|
68
|
+
.filter((line) => !SUMMARY.test(line))
|
|
69
|
+
.join('\n')
|
|
70
|
+
.replace(PROMPT, '');
|
|
71
|
+
const text = rest.replace(/\n{3,}/g, '\n\n').trim();
|
|
72
|
+
return { part: { heading, summary, text }, rest };
|
|
73
|
+
}
|
|
74
|
+
/** Section headings stay as written; the template's prompts are not answers. */
|
|
75
|
+
export function parseBrief(text) {
|
|
76
|
+
if (text === null)
|
|
77
|
+
return null;
|
|
78
|
+
const sections = {};
|
|
79
|
+
const parts = [];
|
|
80
|
+
for (const { heading, body } of planSections(withoutComments(text))) {
|
|
81
|
+
const { part, rest } = briefPart(heading, body);
|
|
82
|
+
// A section with only its summary is answered: the summary is its words.
|
|
83
|
+
sections[heading] = briefSection(rest, briefWords) || part.summary.join('\n');
|
|
84
|
+
if (part.text || part.summary.length)
|
|
85
|
+
parts.push(part);
|
|
86
|
+
}
|
|
87
|
+
const kindPart = parts.find((part) => /b2b|b2c|kind/i.test(part.heading));
|
|
88
|
+
const kindWords = kindPart ? `${kindPart.summary.join('\n')}\n${kindPart.text}` : '';
|
|
89
|
+
const kind = /\bb2([bc])\b/i.exec(kindWords)?.[1]?.toLowerCase();
|
|
90
|
+
return { sections, parts, ...(kind ? { kind: kind === 'b' ? 'b2b' : 'b2c' } : {}) };
|
|
91
|
+
}
|
|
@@ -1,23 +1,13 @@
|
|
|
1
1
|
import type { PlanFacts } from '@buffcore/contracts/workbench';
|
|
2
2
|
import { type Change } from '../change-file.ts';
|
|
3
|
+
export { answer, briefSection, parseBrief, plain, planSections, withoutComments, } from './plan-brief.ts';
|
|
3
4
|
export { parseJourneys } from './plan-journeys.ts';
|
|
4
|
-
export declare const withoutComments: (text: string) => string;
|
|
5
5
|
export declare function textAt(root: string, file: string): Promise<string | null>;
|
|
6
|
-
export declare const answer: (text: string) => string;
|
|
7
|
-
export declare const plain: (text: string) => string;
|
|
8
|
-
/** A newline wraps a paragraph or list item; only a new marker starts another item. */
|
|
9
|
-
export declare function briefSection(text: string): string;
|
|
10
|
-
/** Section spelling, fences and closing hashes follow the original Brief reader. */
|
|
11
|
-
export declare function planSections(text: string): {
|
|
12
|
-
heading: string;
|
|
13
|
-
body: string;
|
|
14
|
-
}[];
|
|
15
6
|
/** The base change reader's list grammar; prose never becomes an inferred step. */
|
|
16
7
|
export declare function stepItems(text: string, read?: (text: string, index: number) => string): string[];
|
|
17
8
|
export declare const journeyStepItems: (text: string) => string[];
|
|
18
9
|
/** Section headings stay as written; the template's prompts are not answers. */
|
|
19
10
|
export declare function readBrief(root: string): Promise<PlanFacts['brief']>;
|
|
20
|
-
export declare function parseBrief(text: string | null): PlanFacts['brief'];
|
|
21
11
|
/** Only actual milestone headings and their change ids; commented examples stay unanswered. */
|
|
22
12
|
export declare function readRoadmap(root: string): Promise<PlanFacts['milestones']>;
|
|
23
13
|
export declare function parseRoadmap(text: string): PlanFacts['milestones'];
|
|
@@ -5,14 +5,15 @@ import { readChange } from '../change-file.js';
|
|
|
5
5
|
import { fourAtATime, needsPrototype, readTree } from '../change-screens.js';
|
|
6
6
|
import { resolveMode } from '../design/state.js';
|
|
7
7
|
import { brandMatches, brandPreview } from './brand-approval.js';
|
|
8
|
+
import { answer, parseBrief, plain, withoutComments } from './plan-brief.js';
|
|
8
9
|
import { changeDetail } from './plan-details.js';
|
|
9
10
|
import { planHistory } from './plan-history.js';
|
|
10
11
|
import { parseJourneys } from './plan-journeys.js';
|
|
11
12
|
import { readNotThis } from './plan-not.js';
|
|
12
13
|
import { structureFacts } from './plan-structure.js';
|
|
13
14
|
import { stepFiles } from './save-ownership.js';
|
|
15
|
+
export { answer, briefSection, parseBrief, plain, planSections, withoutComments, } from './plan-brief.js';
|
|
14
16
|
export { parseJourneys } from './plan-journeys.js';
|
|
15
|
-
export const withoutComments = (text) => text.replace(/<!--[\s\S]*?(?:-->|$)/g, '');
|
|
16
17
|
async function rawTextAt(root, file) {
|
|
17
18
|
try {
|
|
18
19
|
return await readFile(join(root, file), 'utf8');
|
|
@@ -25,42 +26,6 @@ export async function textAt(root, file) {
|
|
|
25
26
|
const text = await rawTextAt(root, file);
|
|
26
27
|
return text === null ? null : withoutComments(text);
|
|
27
28
|
}
|
|
28
|
-
// The base readers' grammar, shared by bounded plan previews as well as Brief and Roadmap.
|
|
29
|
-
export const answer = (text) => text
|
|
30
|
-
// Without a closing > the tag alternative cannot match. Keep the original code grammar.
|
|
31
|
-
.replace(text.includes('>') ? /`+([^`]*)`+|<[^>]*>/g : /`+([^`]*)`+/g, (_match, code) => code ?? '')
|
|
32
|
-
.replace(/^\s*(?:[-*+]|\d+[.)])\s*$/gm, '')
|
|
33
|
-
.trim();
|
|
34
|
-
export const plain = (text) => {
|
|
35
|
-
const words = answer(text);
|
|
36
|
-
// The original link expression cannot match without ](. This guard changes no output.
|
|
37
|
-
return (words.includes('](') ? words.replace(/!?\[([^\]]*)\]\((?:[^()]|\([^()]*\))*\)/g, '$1') : words).replace(/\*\*|__|`/g, '');
|
|
38
|
-
};
|
|
39
|
-
/** A newline wraps a paragraph or list item; only a new marker starts another item. */
|
|
40
|
-
export function briefSection(text) {
|
|
41
|
-
const lines = [];
|
|
42
|
-
for (const raw of plain(text).split(/\r?\n/)) {
|
|
43
|
-
const line = raw.trim();
|
|
44
|
-
const marker = /^(?:[-*+]|\d+[.)])\s+/;
|
|
45
|
-
if (marker.test(line))
|
|
46
|
-
lines.push(line.replace(marker, '- '));
|
|
47
|
-
else if (line && lines.at(-1))
|
|
48
|
-
lines[lines.length - 1] += ` ${line}`;
|
|
49
|
-
else
|
|
50
|
-
lines.push(line);
|
|
51
|
-
}
|
|
52
|
-
return lines.join('\n').trim();
|
|
53
|
-
}
|
|
54
|
-
/** Section spelling, fences and closing hashes follow the original Brief reader. */
|
|
55
|
-
export function planSections(text) {
|
|
56
|
-
return text
|
|
57
|
-
.split(/^##\s+/m)
|
|
58
|
-
.slice(1)
|
|
59
|
-
.map((part) => {
|
|
60
|
-
const [heading = '', ...body] = part.split(/\r?\n/);
|
|
61
|
-
return { heading: heading.trim(), body: body.join('\n') };
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
29
|
/** The base change reader's list grammar; prose never becomes an inferred step. */
|
|
65
30
|
export function stepItems(text, read = plain) {
|
|
66
31
|
const items = [];
|
|
@@ -80,17 +45,6 @@ export const journeyStepItems = (text) => plain(text)
|
|
|
80
45
|
export async function readBrief(root) {
|
|
81
46
|
return parseBrief(await rawTextAt(root, stepFiles.brief[0]));
|
|
82
47
|
}
|
|
83
|
-
export function parseBrief(text) {
|
|
84
|
-
if (text === null)
|
|
85
|
-
return null;
|
|
86
|
-
const sections = {};
|
|
87
|
-
for (const { heading, body } of planSections(withoutComments(text))) {
|
|
88
|
-
sections[heading] = briefSection(body);
|
|
89
|
-
}
|
|
90
|
-
const kindSection = Object.entries(sections).find(([heading]) => /b2b|b2c|kind/i.test(heading));
|
|
91
|
-
const kind = /\bb2([bc])\b/i.exec(kindSection?.[1] ?? '')?.[1]?.toLowerCase();
|
|
92
|
-
return { sections, ...(kind ? { kind: kind === 'b' ? 'b2b' : 'b2c' } : {}) };
|
|
93
|
-
}
|
|
94
48
|
/** Only actual milestone headings and their change ids; commented examples stay unanswered. */
|
|
95
49
|
export async function readRoadmap(root) {
|
|
96
50
|
return parseRoadmap((await rawTextAt(root, stepFiles.plan[0])) ?? '');
|
|
@@ -6,6 +6,11 @@ export declare function planPrototypeOnMain(root: string, plan: PlanFacts | unde
|
|
|
6
6
|
brief: {
|
|
7
7
|
sections: Record<string, string>;
|
|
8
8
|
kind?: "b2b" | "b2c" | undefined;
|
|
9
|
+
parts?: {
|
|
10
|
+
heading: string;
|
|
11
|
+
summary: string[];
|
|
12
|
+
text: string;
|
|
13
|
+
}[] | undefined;
|
|
9
14
|
} | null;
|
|
10
15
|
milestones: {
|
|
11
16
|
name: string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type MarkShotBody } from '@buffcore/contracts/workbench';
|
|
2
|
+
import { launchBrowser } from '../prototype/browser.ts';
|
|
3
|
+
import { shootMarks } from '../prototype/mark-shot.ts';
|
|
4
|
+
import type { UiRoute } from './routes.ts';
|
|
5
|
+
import type { UiServerOptions } from './server.ts';
|
|
6
|
+
export type Shooter = (url: URL, body: MarkShotBody) => Promise<Buffer>;
|
|
7
|
+
/** At most this many pictures are taken at once; the others wait their turn. */
|
|
8
|
+
export declare const SHOTS_AT_ONCE = 2;
|
|
9
|
+
/**
|
|
10
|
+
* One browser for the studio's pictures, launched once however many ask at the same moment, with
|
|
11
|
+
* at most SHOTS_AT_ONCE pictures taken at a time, and closed when no picture was asked for a while.
|
|
12
|
+
*/
|
|
13
|
+
export declare function browserShooter(launch?: typeof launchBrowser, shot?: typeof shootMarks): Shooter & {
|
|
14
|
+
close: () => Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
export declare function prototypeShotRoute(options: Pick<UiServerOptions, 'stack'>, shutdown?: AbortSignal, shoot?: Shooter): UiRoute;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// `POST /api/prototype/shot`: a picture of the running app at one marked screen and device, with the
|
|
2
|
+
// marks drawn, for the one message that sends them. The snapshot's own browser (Playwright's
|
|
3
|
+
// headless Chromium) opens only this studio's app address; nothing from the request names a host.
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { markShotBody, workbenchApi } from '@buffcore/contracts/workbench';
|
|
6
|
+
import { launchBrowser } from '../prototype/browser.js';
|
|
7
|
+
import { shootMarks, shotAddress } from '../prototype/mark-shot.js';
|
|
8
|
+
import { commandT as t } from './commands.js';
|
|
9
|
+
/** The body: a few marks of numbers; a drawing's points are the largest part. */
|
|
10
|
+
const BODY_LIMIT = 200_000;
|
|
11
|
+
/** A picture past this is not sent (a chat image's limit, in base64 characters). */
|
|
12
|
+
const PICTURE_LIMIT = 5 * 1024 * 1024;
|
|
13
|
+
/** The browser closes when no picture was asked for this long (ms). */
|
|
14
|
+
const IDLE = 60_000;
|
|
15
|
+
/** At most this many pictures are taken at once; the others wait their turn. */
|
|
16
|
+
export const SHOTS_AT_ONCE = 2;
|
|
17
|
+
/**
|
|
18
|
+
* One browser for the studio's pictures, launched once however many ask at the same moment, with
|
|
19
|
+
* at most SHOTS_AT_ONCE pictures taken at a time, and closed when no picture was asked for a while.
|
|
20
|
+
*/
|
|
21
|
+
export function browserShooter(launch = launchBrowser, shot = shootMarks) {
|
|
22
|
+
let browser;
|
|
23
|
+
let timer;
|
|
24
|
+
let running = 0;
|
|
25
|
+
const waiting = [];
|
|
26
|
+
const close = async () => {
|
|
27
|
+
const open = browser;
|
|
28
|
+
browser = undefined;
|
|
29
|
+
await (await open?.catch(() => undefined))?.close();
|
|
30
|
+
};
|
|
31
|
+
const opened = async () => {
|
|
32
|
+
const current = browser ?? launch();
|
|
33
|
+
browser = current;
|
|
34
|
+
const ready = await current.catch((error) => {
|
|
35
|
+
if (browser === current)
|
|
36
|
+
browser = undefined;
|
|
37
|
+
throw error;
|
|
38
|
+
});
|
|
39
|
+
if (ready.isConnected())
|
|
40
|
+
return ready;
|
|
41
|
+
// Gone (a crash): the first to see it launches again, the others share that launch.
|
|
42
|
+
if (browser === current)
|
|
43
|
+
browser = launch();
|
|
44
|
+
return opened();
|
|
45
|
+
};
|
|
46
|
+
const shoot = async (url, body) => {
|
|
47
|
+
clearTimeout(timer);
|
|
48
|
+
// A finished shot hands its place straight to the next in line.
|
|
49
|
+
if (running < SHOTS_AT_ONCE)
|
|
50
|
+
running += 1;
|
|
51
|
+
else
|
|
52
|
+
await new Promise((turn) => waiting.push(turn));
|
|
53
|
+
try {
|
|
54
|
+
return await shot(await opened(), url, body);
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
const next = waiting.shift();
|
|
58
|
+
if (next)
|
|
59
|
+
next();
|
|
60
|
+
else
|
|
61
|
+
running -= 1;
|
|
62
|
+
if (!running) {
|
|
63
|
+
timer = setTimeout(() => void close(), IDLE);
|
|
64
|
+
timer.unref?.();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
return Object.assign(shoot, { close });
|
|
69
|
+
}
|
|
70
|
+
export function prototypeShotRoute(options, shutdown, shoot = browserShooter()) {
|
|
71
|
+
const closable = shoot;
|
|
72
|
+
shutdown?.addEventListener('abort', () => void closable.close?.(), { once: true });
|
|
73
|
+
return {
|
|
74
|
+
method: 'POST',
|
|
75
|
+
path: workbenchApi.prototypeShot,
|
|
76
|
+
right: 'build',
|
|
77
|
+
origin: true,
|
|
78
|
+
handle: async ({ body }) => {
|
|
79
|
+
const request = markShotBody.safeParse(await body(BODY_LIMIT).catch(() => undefined));
|
|
80
|
+
if (!request.success)
|
|
81
|
+
return { status: 400, body: { error: t('ui.shot.invalid') } };
|
|
82
|
+
const stack = options.stack.info();
|
|
83
|
+
if (!stack.answers?.app)
|
|
84
|
+
return { status: 409, body: { error: t('ui.shot.notRunning') } };
|
|
85
|
+
try {
|
|
86
|
+
const png = await shoot(shotAddress(stack.app, request.data, randomUUID()), request.data);
|
|
87
|
+
const data = png.toString('base64');
|
|
88
|
+
if (data.length > PICTURE_LIMIT)
|
|
89
|
+
throw new Error('too large');
|
|
90
|
+
return { status: 200, body: { type: 'image/png', data } };
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
const reason = (error instanceof Error ? error.message : String(error)).split('\n')[0];
|
|
94
|
+
return { status: 503, body: { error: t('ui.shot.failed', { reason }) } };
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -18,6 +18,8 @@ export interface UiRequest extends MergeConfiguration, SaveConfiguration, Outsid
|
|
|
18
18
|
readonly stop?: AbortSignal;
|
|
19
19
|
/** Supplied only by createUiServer, never by the request body or product. */
|
|
20
20
|
readonly contained?: boolean;
|
|
21
|
+
/** The host's launcher starts the turns; supplied only by createUiServer. */
|
|
22
|
+
readonly hostLaunched?: boolean;
|
|
21
23
|
req: IncomingMessage;
|
|
22
24
|
/**
|
|
23
25
|
* The path's `:name` segments, decoded: one may hold a `/` (from `%2F`), so a handler checks it
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { workbenchApi } from '@buffcore/contracts/workbench';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { readableFields } from './access.js';
|
|
4
|
+
import { prototypeShotRoute } from './prototype-shot-route.js';
|
|
4
5
|
import { prototypeSnapshotRoute } from './prototype-snapshot.js';
|
|
5
6
|
import { runRoute } from './run-route.js';
|
|
6
7
|
import { visibleRuns } from './snapshot-view.js';
|
|
@@ -45,6 +46,7 @@ export function coreRoutes(options, shutdown) {
|
|
|
45
46
|
},
|
|
46
47
|
runRoute(options, snapshot.record),
|
|
47
48
|
snapshot,
|
|
49
|
+
prototypeShotRoute(options, shutdown),
|
|
48
50
|
{
|
|
49
51
|
method: 'POST',
|
|
50
52
|
path: workbenchApi.stack,
|
|
@@ -20,6 +20,7 @@ export function checkedUiOptions(input) {
|
|
|
20
20
|
return {
|
|
21
21
|
...input,
|
|
22
22
|
contained: input.contained === true,
|
|
23
|
+
hostLaunched: input.hostLaunched === true,
|
|
23
24
|
hostParts: checkedHostParts(input.hostParts, signedIn),
|
|
24
25
|
outside: checkedOutside(input.outside, signedIn),
|
|
25
26
|
theme: checkedTheme(input.theme),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { hostLaunched as isHostLaunched } from './chat/host-launched.js';
|
|
1
2
|
import { localStudioOrigin } from './prototype-origin.js';
|
|
2
3
|
import { bodyOf } from './routes.js';
|
|
3
4
|
/** Local pages and coding turns use the bound address, including when port 0 was requested. */
|
|
@@ -16,11 +17,15 @@ export function requestContext(options, req, params, identity, shutdown) {
|
|
|
16
17
|
let body;
|
|
17
18
|
const disconnected = new AbortController();
|
|
18
19
|
req.once('aborted', () => disconnected.abort());
|
|
20
|
+
// A host may pass a runner without a folder (or none): no folder is in the mode then.
|
|
21
|
+
const folder = options.runner?.cwd;
|
|
19
22
|
return {
|
|
20
23
|
req,
|
|
21
24
|
identity,
|
|
22
25
|
hosted: Boolean(options.signIn),
|
|
23
26
|
contained: options.contained === true,
|
|
27
|
+
// On only while this server's product folder is in the mode (an empty runner folder never is).
|
|
28
|
+
hostLaunched: folder ? isHostLaunched(folder) : false,
|
|
24
29
|
...(options.approval ? { approval: options.approval } : {}),
|
|
25
30
|
...(options.level?.where.trim() ? { level: options.level } : {}),
|
|
26
31
|
save: options.save,
|
|
@@ -60,6 +60,13 @@ export interface UiServerOptions extends SaveConfiguration, OutsideConfiguration
|
|
|
60
60
|
mergeTimeoutMs?: number;
|
|
61
61
|
/** Host-owned isolation boundary; never inferred from product inputs. */
|
|
62
62
|
contained?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* The host's own trusted launcher starts the agent's turns: they launch as in 0.8.41, with no
|
|
65
|
+
* per-turn settings, MCP config, permission prompt tool or socket, and the host applies the
|
|
66
|
+
* limits (chat/host-launched.ts). For the product folder of `runner.cwd`, which it needs; one
|
|
67
|
+
* mode per folder, so the last server created for a folder decides it. Off by default.
|
|
68
|
+
*/
|
|
69
|
+
hostLaunched?: boolean;
|
|
63
70
|
product: string;
|
|
64
71
|
script: () => Promise<string>;
|
|
65
72
|
stack: Stack;
|
|
@@ -3,6 +3,7 @@ import { createServer } from 'node:http';
|
|
|
3
3
|
import { workbenchApi } from '@buffcore/contracts/workbench';
|
|
4
4
|
import { migrationRoute } from '../migrate-create-protocol.js';
|
|
5
5
|
import { MilestoneVersionsPending } from '../prototype/milestone-key.js';
|
|
6
|
+
import { registerHostLaunched } from './chat/host-launched.js';
|
|
6
7
|
import { scrubLaunchIds } from './chat/launch-ids.js';
|
|
7
8
|
import { exchangeCode } from './code.js';
|
|
8
9
|
import { studioFont } from './fonts.js';
|
|
@@ -65,15 +66,29 @@ export function createUiServer(input) {
|
|
|
65
66
|
});
|
|
66
67
|
const key = options.runner.cwd ? runnerKey(options.runner.cwd) : undefined;
|
|
67
68
|
server.on('listening', () => localListener(options, server.address().port));
|
|
69
|
+
// A browser opens spare connections it may never send a request on. close() ends those at once
|
|
70
|
+
// (Node ends only the idle ones), so it never waits on them, and a server started again on the
|
|
71
|
+
// same port answers the tab's next load.
|
|
72
|
+
const unused = new Set();
|
|
73
|
+
server.on('connection', (socket) => {
|
|
74
|
+
unused.add(socket);
|
|
75
|
+
socket.once('close', () => unused.delete(socket));
|
|
76
|
+
});
|
|
77
|
+
server.on('request', (req) => unused.delete(req.socket));
|
|
68
78
|
const close = server.close;
|
|
69
79
|
server.close = function (callback) {
|
|
70
80
|
shutdown.abort();
|
|
71
|
-
|
|
81
|
+
const closing = close.call(this, callback);
|
|
82
|
+
for (const socket of unused)
|
|
83
|
+
socket.destroy();
|
|
84
|
+
return closing;
|
|
72
85
|
};
|
|
73
86
|
if (key)
|
|
74
87
|
snapshotRunners.set(key, options.runner);
|
|
88
|
+
const launcher = key ? registerHostLaunched(key, options.hostLaunched === true) : () => { };
|
|
75
89
|
server.once('close', () => {
|
|
76
90
|
shutdown.abort();
|
|
91
|
+
launcher();
|
|
77
92
|
if (key && snapshotRunners.get(key) === options.runner)
|
|
78
93
|
snapshotRunners.delete(key);
|
|
79
94
|
});
|
|
@@ -22,6 +22,7 @@ export const studioAccess = {
|
|
|
22
22
|
viewer: true,
|
|
23
23
|
machine: true,
|
|
24
24
|
contained: true,
|
|
25
|
+
hostLaunched: true,
|
|
25
26
|
product: true,
|
|
26
27
|
appUrl: true,
|
|
27
28
|
plan: true,
|
|
@@ -93,7 +94,7 @@ cached = false) {
|
|
|
93
94
|
path: '/api/studio',
|
|
94
95
|
readable: true,
|
|
95
96
|
handle: async (request) => {
|
|
96
|
-
const { identity, hosted, approval, level, contained = false } = request;
|
|
97
|
+
const { identity, hosted, approval, level, contained = false, hostLaunched } = request;
|
|
97
98
|
const current = await merged(await state({ identity, hosted, approval, level }), request);
|
|
98
99
|
const context = authorityFor({ identity, approval });
|
|
99
100
|
const checked = context
|
|
@@ -107,6 +108,7 @@ cached = false) {
|
|
|
107
108
|
viewer: identity?.viewer,
|
|
108
109
|
machine: identity?.machine,
|
|
109
110
|
contained,
|
|
111
|
+
hostLaunched: hostLaunched === true,
|
|
110
112
|
level,
|
|
111
113
|
outside: outsideState(request.outside),
|
|
112
114
|
}, identity?.viewer, studioAccess),
|
|
@@ -11,6 +11,7 @@ export declare function prototypeChange(root: string, context?: ApprovalContext)
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function studioState(root: string, options: Pick<UiServerOptions, 'product' | 'stack' | 'runner' | 'plan'>, detect?: () => Promise<FoundAgent[]>, held?: (id: string) => boolean, cached?: boolean): (request?: Request) => Promise<{
|
|
13
13
|
contained?: boolean | undefined;
|
|
14
|
+
hostLaunched?: boolean | undefined;
|
|
14
15
|
viewer?: {
|
|
15
16
|
name: string;
|
|
16
17
|
email?: string | undefined;
|
|
@@ -170,6 +171,11 @@ export declare function studioState(root: string, options: Pick<UiServerOptions,
|
|
|
170
171
|
brief: {
|
|
171
172
|
sections: Record<string, string>;
|
|
172
173
|
kind?: "b2b" | "b2c" | undefined;
|
|
174
|
+
parts?: {
|
|
175
|
+
heading: string;
|
|
176
|
+
summary: string[];
|
|
177
|
+
text: string;
|
|
178
|
+
}[] | undefined;
|
|
173
179
|
} | null;
|
|
174
180
|
milestones: {
|
|
175
181
|
name: string;
|