@buffcore/cli 0.8.42 → 0.8.43

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.
Files changed (96) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/commands/design/references.d.ts +9 -0
  3. package/dist/commands/design/references.js +20 -1
  4. package/dist/commands/extension/places-approval.d.ts +1 -1
  5. package/dist/commands/prototype/comp-record.d.ts +27 -0
  6. package/dist/commands/prototype/comp-record.js +85 -0
  7. package/dist/commands/prototype/comp-words.d.ts +12 -0
  8. package/dist/commands/prototype/comp-words.js +24 -0
  9. package/dist/commands/prototype/comp.d.ts +26 -0
  10. package/dist/commands/prototype/comp.js +71 -0
  11. package/dist/commands/prototype/milestone-versions.d.ts +1 -1
  12. package/dist/commands/prototype/record-look-child.js +4 -1
  13. package/dist/commands/prototype/snapshot-command.js +1 -1
  14. package/dist/commands/prototype/snapshot-setup.d.ts +11 -0
  15. package/dist/commands/prototype/snapshot-setup.js +29 -5
  16. package/dist/commands/prototype/versions.d.ts +3 -3
  17. package/dist/commands/ui/agents-route.d.ts +2 -0
  18. package/dist/commands/ui/agents-route.js +8 -5
  19. package/dist/commands/ui/approval-authority.d.ts +1 -1
  20. package/dist/commands/ui/approve.js +7 -1
  21. package/dist/commands/ui/chat/codex-idle.d.ts +1 -0
  22. package/dist/commands/ui/chat/fresh-critique.d.ts +28 -0
  23. package/dist/commands/ui/chat/fresh-critique.js +121 -0
  24. package/dist/commands/ui/chat/fresh-launch.d.ts +31 -0
  25. package/dist/commands/ui/chat/fresh-launch.js +122 -0
  26. package/dist/commands/ui/chat/fresh-prompts.d.ts +17 -0
  27. package/dist/commands/ui/chat/fresh-prompts.js +76 -0
  28. package/dist/commands/ui/chat/fresh-report.d.ts +8 -0
  29. package/dist/commands/ui/chat/fresh-report.js +36 -0
  30. package/dist/commands/ui/chat/fresh-routes.d.ts +3 -0
  31. package/dist/commands/ui/chat/fresh-routes.js +64 -0
  32. package/dist/commands/ui/chat/fresh-settings.d.ts +12 -0
  33. package/dist/commands/ui/chat/fresh-settings.js +66 -0
  34. package/dist/commands/ui/chat/fresh-store.d.ts +17 -0
  35. package/dist/commands/ui/chat/fresh-store.js +67 -0
  36. package/dist/commands/ui/chat/fresh.d.ts +31 -0
  37. package/dist/commands/ui/chat/fresh.en.d.ts +7 -0
  38. package/dist/commands/ui/chat/fresh.en.js +7 -0
  39. package/dist/commands/ui/chat/fresh.es.d.ts +7 -0
  40. package/dist/commands/ui/chat/fresh.es.js +7 -0
  41. package/dist/commands/ui/chat/fresh.js +112 -0
  42. package/dist/commands/ui/chat/limit-mentions.d.ts +2 -2
  43. package/dist/commands/ui/chat/limit-mentions.js +22 -2
  44. package/dist/commands/ui/chat/limits.d.ts +8 -1
  45. package/dist/commands/ui/chat/limits.en.d.ts +2 -0
  46. package/dist/commands/ui/chat/limits.en.js +2 -0
  47. package/dist/commands/ui/chat/limits.es.js +2 -0
  48. package/dist/commands/ui/chat/limits.js +13 -1
  49. package/dist/commands/ui/chat/parse-claude.js +7 -3
  50. package/dist/commands/ui/chat/permission-ask.js +3 -0
  51. package/dist/commands/ui/chat/planning-limits.js +15 -0
  52. package/dist/commands/ui/chat/publish-limits.d.ts +4 -0
  53. package/dist/commands/ui/chat/publish-limits.js +97 -0
  54. package/dist/commands/ui/chat/recorded-turn.js +3 -0
  55. package/dist/commands/ui/chat/stream.js +4 -1
  56. package/dist/commands/ui/chat/turn-guard.d.ts +2 -0
  57. package/dist/commands/ui/chat/turn-guard.js +12 -0
  58. package/dist/commands/ui/chat/turn-state.d.ts +5 -0
  59. package/dist/commands/ui/chat/turn.js +1 -0
  60. package/dist/commands/ui/comp-approval.d.ts +6 -0
  61. package/dist/commands/ui/comp-approval.js +42 -0
  62. package/dist/commands/ui/host.js +3 -0
  63. package/dist/commands/ui/index.js +18 -6
  64. package/dist/commands/ui/loop-approve.d.ts +4 -4
  65. package/dist/commands/ui/places-change.d.ts +1 -1
  66. package/dist/commands/ui/plan-structure.d.ts +3 -0
  67. package/dist/commands/ui/plan-structure.en.d.ts +3 -0
  68. package/dist/commands/ui/plan-structure.en.js +3 -0
  69. package/dist/commands/ui/plan-structure.es.d.ts +3 -0
  70. package/dist/commands/ui/plan-structure.es.js +3 -0
  71. package/dist/commands/ui/plan-structure.js +12 -4
  72. package/dist/commands/ui/prototype-comp-route.d.ts +7 -0
  73. package/dist/commands/ui/prototype-comp-route.js +109 -0
  74. package/dist/commands/ui/prototype-main.d.ts +2 -1
  75. package/dist/commands/ui/prototype-scenes-child.js +4 -1
  76. package/dist/commands/ui/prototype-snapshot-session.d.ts +1 -1
  77. package/dist/commands/ui/prototype-snapshot-session.js +3 -0
  78. package/dist/commands/ui/prototype-snapshot.d.ts +1 -1
  79. package/dist/commands/ui/routes.d.ts +6 -3
  80. package/dist/commands/ui/routes.js +3 -3
  81. package/dist/commands/ui/save-publish.js +3 -0
  82. package/dist/commands/ui/server.d.ts +7 -0
  83. package/dist/commands/ui/server.js +7 -3
  84. package/dist/commands/ui/structure-surface.d.ts +6 -0
  85. package/dist/commands/ui/structure-surface.js +94 -0
  86. package/dist/commands/ui/studio-routes.js +4 -0
  87. package/dist/commands/ui/studio-state.d.ts +6 -4
  88. package/dist/commands/ui/studio-versions.d.ts +3 -3
  89. package/dist/ui/page.js +81 -81
  90. package/docs/PROCESS.md +5 -0
  91. package/docs/PROTOTYPE.md +20 -0
  92. package/docs/WORKBENCH.md +2 -2
  93. package/package.json +11 -11
  94. package/skills/ape-critique/SKILL.md +9 -3
  95. package/skills/ape-design-system/SKILL.md +2 -1
  96. package/skills/ape-prototype/SKILL.md +5 -1
@@ -0,0 +1,42 @@
1
+ // Approve the look: the guarded approval route's door for the comp. A person's only, at every level;
2
+ // there is no agent, MCP or Autopilot door, and `approveComp` refuses an agent's name. The record is
3
+ // saved as its own isolated commit, as a version approval is (`saveApprovalRecord`).
4
+ import { ApprovalRefusal } from '../approval-rules.js';
5
+ import { newestComp } from '../prototype/comp.js';
6
+ import { approveComp, COMP_FILE } from '../prototype/comp-record.js';
7
+ import { compT } from '../prototype/comp-words.js';
8
+ import { VersionRefusal } from '../prototype/versions.js';
9
+ import { hostGit } from '../safe-git.js';
10
+ import { HostSaveRefusal } from './host-save.js';
11
+ import { saveApprovalRecord } from './save-route.js';
12
+ const git = async (root, args) => (await hostGit(root, args)).trim();
13
+ export async function compApproval(root, fingerprint, signer, role, agent, source) {
14
+ if (agent !== undefined)
15
+ return { status: 409, body: { error: compT('comp.person') } };
16
+ const by = signer ?? (await git(root, ['config', 'user.email']).catch(() => ''));
17
+ if (!by)
18
+ return { status: 400, body: { error: compT('comp.identity') } };
19
+ const commit = await git(root, ['rev-parse', '--verify', 'HEAD']).catch(() => null);
20
+ if (!commit)
21
+ return { status: 409, body: { error: compT('comp.commitFirst') } };
22
+ try {
23
+ const record = await saveApprovalRecord(root, COMP_FILE, (write = true) => approveComp(root, { by, commit, fingerprint, role }, write), by, undefined, source);
24
+ return { status: 201, body: record.approval };
25
+ }
26
+ catch (error) {
27
+ if (error instanceof HostSaveRefusal)
28
+ return { status: 409, body: error.result() };
29
+ if (error instanceof ApprovalRefusal || error instanceof VersionRefusal)
30
+ return { status: 409, body: { error: error.message } };
31
+ throw error;
32
+ }
33
+ }
34
+ /** What a host's authority judges: the comp the page showed, at the commit checked out. */
35
+ export async function compResolver(root, fingerprint) {
36
+ const commit = await git(root, ['rev-parse', '--verify', 'HEAD']);
37
+ return () => {
38
+ if (newestComp(root)?.fingerprint !== fingerprint)
39
+ throw new Error();
40
+ return { kind: 'comp', version: null, commit, fingerprint };
41
+ };
42
+ }
@@ -54,6 +54,9 @@ export async function routeRight(route, request) {
54
54
  return route.right;
55
55
  if (route.path === '/api/approve') {
56
56
  const { kind } = approvalKind.parse(await request.body());
57
+ // The comp is the prototype's look: whoever approves prototypes approves it.
58
+ if (kind === 'comp')
59
+ return 'approve:prototype';
57
60
  return kind === 'places' ? 'approve:data' : `approve:${kind}`;
58
61
  }
59
62
  if (route.path === '/api/run') {
@@ -5,7 +5,10 @@ import { spawn } from 'node:child_process';
5
5
  import { createI18n } from '@buffcore/i18n';
6
6
  import { InvalidArgumentError } from 'commander';
7
7
  import { findRoot, loadEnv, loadProduct } from '../../project.js';
8
+ import { FreshLooks } from './chat/fresh.js';
9
+ import { freshRoutes } from './chat/fresh-routes.js';
8
10
  import { TurnMigrations } from './chat/migration-turn.js';
11
+ import { agentStart } from './chat/process.js';
9
12
  import { chatRoutes } from './chat/routes.js';
10
13
  import { installShutdown } from './chat/shutdown.js';
11
14
  import { ChatEngine } from './chat/turn.js';
@@ -52,7 +55,8 @@ export async function ui(options) {
52
55
  const token = newToken();
53
56
  const code = localCode((event) => console.log(t(`ui.code.${event}`, undefined, locale)));
54
57
  const migrations = new TurnMigrations(root, env, locale);
55
- const chats = new ChatEngine(root, { environment: agentEnvironment, migrations });
58
+ const fresh = new FreshLooks(root, agentStart(root, agentEnvironment));
59
+ const chats = new ChatEngine(root, { environment: agentEnvironment, migrations, fresh });
56
60
  await chats.ready;
57
61
  const stack = new Stack(root, {
58
62
  app: env.APE_APP_URL,
@@ -76,13 +80,17 @@ export async function ui(options) {
76
80
  runner,
77
81
  plan: () => plan,
78
82
  refreshPlan,
79
- routes: [...routes, ...chatRoutes(chats)],
83
+ routes: [...routes, ...chatRoutes(chats), ...freshRoutes(fresh, root)],
84
+ onFullSnapshot: (source, report) => void fresh.afterSnapshot(source, report),
80
85
  });
81
86
  await openStudio(server, port, token, code, options, locale);
82
- keepStudio(server, stack, chats, migrations);
87
+ keepStudio(server, stack, chats, migrations, fresh);
83
88
  }
84
- function keepStudio(server, stack, chats, migrations) {
85
- server.once('close', () => chats.stopAll());
89
+ function keepStudio(server, stack, chats, migrations, fresh) {
90
+ server.once('close', () => {
91
+ fresh.close();
92
+ void chats.stopAll();
93
+ });
86
94
  void stack.check();
87
95
  setInterval(() => void stack.check(), 2000).unref();
88
96
  installShutdown({
@@ -91,9 +99,13 @@ function keepStudio(server, stack, chats, migrations) {
91
99
  },
92
100
  release: () => stack.release(),
93
101
  stop: async () => {
102
+ fresh.close();
94
103
  await Promise.all([chats.shutdown(), migrations.idle()]);
95
104
  },
96
- force: () => chats.stopAll(true),
105
+ force: () => {
106
+ fresh.close();
107
+ return chats.stopAll(true);
108
+ },
97
109
  });
98
110
  }
99
111
  async function openStudio(server, port, token, code, options, locale) {
@@ -9,7 +9,7 @@ export declare function brandApproval(root: string, direction: keyof typeof them
9
9
  } | {
10
10
  status: number;
11
11
  body: {
12
- kind: "brand" | "money" | "places" | "plan" | "prototype" | "release";
12
+ kind: "brand" | "comp" | "money" | "places" | "plan" | "prototype" | "release";
13
13
  signatures: {
14
14
  by: string;
15
15
  at: string;
@@ -75,7 +75,7 @@ export declare function prototypeApproval(root: string, request: {
75
75
  approved?: {
76
76
  version: number;
77
77
  approval: {
78
- kind: "brand" | "money" | "places" | "plan" | "prototype" | "release";
78
+ kind: "brand" | "comp" | "money" | "places" | "plan" | "prototype" | "release";
79
79
  signatures: {
80
80
  by: string;
81
81
  at: string;
@@ -100,7 +100,7 @@ export declare function prototypeApproval(root: string, request: {
100
100
  pending?: {
101
101
  version: number;
102
102
  approval: {
103
- kind: "brand" | "money" | "places" | "plan" | "prototype" | "release";
103
+ kind: "brand" | "comp" | "money" | "places" | "plan" | "prototype" | "release";
104
104
  signatures: {
105
105
  by: string;
106
106
  at: string;
@@ -125,7 +125,7 @@ export declare function prototypeApproval(root: string, request: {
125
125
  superseded?: {
126
126
  version: number;
127
127
  approval: {
128
- kind: "brand" | "money" | "places" | "plan" | "prototype" | "release";
128
+ kind: "brand" | "comp" | "money" | "places" | "plan" | "prototype" | "release";
129
129
  signatures: {
130
130
  by: string;
131
131
  at: string;
@@ -42,7 +42,7 @@ export declare function plannedPlaceApproval(root: string, change: string): Prom
42
42
  revision: string;
43
43
  record: {
44
44
  approvals: {
45
- kind: "brand" | "money" | "places" | "plan" | "prototype" | "release";
45
+ kind: "brand" | "comp" | "money" | "places" | "plan" | "prototype" | "release";
46
46
  signatures: {
47
47
  by: string;
48
48
  at: string;
@@ -16,16 +16,19 @@ export type ChangeScreens = ReadonlyMap<string, readonly string[]>;
16
16
  export declare function parseStructure(text: string, screens?: readonly string[], changes?: ChangeScreens): {
17
17
  rows: StructureRow[];
18
18
  notes: string[];
19
+ surface: "desktop" | "phone";
19
20
  };
20
21
  /** Reuse the inventory's discovery; no product code is loaded and no navigation is inferred. */
21
22
  export declare function readStructure(root: string): Promise<{
22
23
  rows: StructureRow[];
23
24
  notes: string[];
25
+ surface: "desktop" | "phone";
24
26
  } | null>;
25
27
  /** A malformed structure must not hide the rest of an older product's plan. */
26
28
  export declare function structureFacts(root: string): Promise<{
27
29
  rows: StructureRow[];
28
30
  notes: string[];
31
+ surface: "desktop" | "phone";
29
32
  } | {
30
33
  rows: never[];
31
34
  notes: never[];
@@ -18,4 +18,7 @@ export declare const en: {
18
18
  'structure.main': string;
19
19
  'structure.empty': string;
20
20
  'structure.notes': string;
21
+ 'structure.surfaceMissing': string;
22
+ 'structure.surfaceFailed': string;
23
+ 'structure.surface': string;
21
24
  };
@@ -18,4 +18,7 @@ export const en = {
18
18
  'structure.main': '{row}: Main must be yes or no. File order ranks the main sections.',
19
19
  'structure.empty': 'Name at least one section and its first screen.',
20
20
  'structure.notes': 'Add short notes for nested screens and their return targets, phone and wide screens.',
21
+ 'structure.surfaceMissing': 'Draft the structure first; then choose which surface comes first.',
22
+ 'structure.surfaceFailed': 'The surface could not be written. Try again.',
23
+ 'structure.surface': '{row}: write the Surface line once, before the table, as Surface: desktop or Surface: phone.',
21
24
  };
@@ -18,4 +18,7 @@ export declare const es: {
18
18
  'structure.main': string;
19
19
  'structure.empty': string;
20
20
  'structure.notes': string;
21
+ 'structure.surfaceMissing': string;
22
+ 'structure.surfaceFailed': string;
23
+ 'structure.surface': string;
21
24
  };
@@ -18,4 +18,7 @@ export const es = {
18
18
  'structure.main': '{row}: Main debe ser yes o no. El orden del archivo ordena las secciones principales.',
19
19
  'structure.empty': 'Nombra al menos una sección y su primera pantalla.',
20
20
  'structure.notes': 'Añade notas breves para las pantallas anidadas y su regreso, teléfonos y pantallas anchas.',
21
+ 'structure.surfaceMissing': 'Primero haz el borrador de la estructura; luego elige qué superficie va primero.',
22
+ 'structure.surfaceFailed': 'No se pudo escribir la superficie. Inténtalo de nuevo.',
23
+ 'structure.surface': '{row}: escribe la línea Surface una vez, antes de la tabla, como Surface: desktop o Surface: phone.',
21
24
  };
@@ -3,6 +3,7 @@ import { join } from 'node:path';
3
3
  import { createI18n } from '@buffcore/i18n';
4
4
  import { readChanges } from '../change-file.js';
5
5
  import { adminScreens, appScreens } from '../inventory-screens.js';
6
+ import { SURFACE_FIELD, SURFACE_LINE } from '../prototype/comp.js';
6
7
  import { en } from './plan-structure.en.js';
7
8
  import { es } from './plan-structure.es.js';
8
9
  /** `/billing (planned, C-020)`: a first screen a change adds, before its route exists. */
@@ -28,6 +29,7 @@ function sourceName(line, t) {
28
29
  function structureLines(text, t, numbers) {
29
30
  const table = [];
30
31
  const notes = [];
32
+ let surface;
31
33
  let state = 'before';
32
34
  for (const [index, line] of text
33
35
  .replace(/^\uFEFF/, '')
@@ -42,7 +44,13 @@ function structureLines(text, t, numbers) {
42
44
  state = 'after';
43
45
  }
44
46
  else if (state === 'before' && /^# [\p{L}\p{N}][^<>|]*$/u.test(line)) {
45
- // Only titles and empty lines may precede the table.
47
+ // Only titles, the surface and empty lines may precede the table.
48
+ }
49
+ else if (state === 'before' && SURFACE_FIELD.test(line)) {
50
+ const found = SURFACE_LINE.exec(line);
51
+ if (surface || !found)
52
+ throw new Error(t('structure.surface', { row }));
53
+ surface = found[1]?.toLowerCase();
46
54
  }
47
55
  else if (/^\|.*(?<!\\)\|$/.test(line)) {
48
56
  if (state === 'after')
@@ -58,7 +66,7 @@ function structureLines(text, t, numbers) {
58
66
  throw new Error(t(state === 'before' ? 'structure.before' : 'structure.noteShape', { row }));
59
67
  }
60
68
  }
61
- return { table, notes };
69
+ return { table, notes, surface: surface ?? 'desktop' };
62
70
  }
63
71
  const cells = (line) => line
64
72
  .split(/(?<!\\)\|/)
@@ -145,12 +153,12 @@ export function parseStructure(text, screens, changes) {
145
153
  const locale = /^es(?:[-_.]|$)/i.test(process.env.LC_ALL || process.env.LANG || '') ? 'es' : 'en';
146
154
  const t = (key, values) => messages.t(locale, key, values);
147
155
  const numbers = new Intl.NumberFormat(locale);
148
- const { table, notes } = structureLines(text, t, numbers);
156
+ const { table, notes, surface } = structureLines(text, t, numbers);
149
157
  checkColumns(table, t, numbers);
150
158
  const rows = structureRows(table, t, screens, changes);
151
159
  if (!notes.length)
152
160
  throw new Error(t('structure.notes'));
153
- return { rows, notes };
161
+ return { rows, notes, surface };
154
162
  }
155
163
  /** Reuse the inventory's discovery; no product code is loaded and no navigation is inferred. */
156
164
  export async function readStructure(root) {
@@ -0,0 +1,7 @@
1
+ import { type PrototypeCompReply } from '@buffcore/contracts/workbench';
2
+ import type { ImageType, UiRoute } from './routes.ts';
3
+ export declare const pictureType: (file: string) => ImageType | undefined;
4
+ export declare function compReply(root: string, hosted?: boolean): Promise<PrototypeCompReply>;
5
+ /** The file a picture name stands for, or undefined: only the comp's own shots and the references. */
6
+ export declare function compPicture(root: string, name: string, hosted?: boolean): Promise<string | undefined>;
7
+ export declare function prototypeCompRoutes(root: string): UiRoute[];
@@ -0,0 +1,109 @@
1
+ // The comp page's reads: the newest comp snapshot's screens, the references beside them and the
2
+ // approval; and each picture by its name (never by a path from the request).
3
+ import { readFile } from 'node:fs/promises';
4
+ import { extname, join } from 'node:path';
5
+ import { frameSizes } from '@buffcore/config';
6
+ import { workbenchApi } from '@buffcore/contracts/workbench';
7
+ import { loadProduct } from '../../project.js';
8
+ import { referencePictures } from '../design/references.js';
9
+ import { compDir, firstSurface, newestComp } from '../prototype/comp.js';
10
+ import { compApproved, readCompApproval } from '../prototype/comp-record.js';
11
+ import { snapshotsDir } from '../prototype/report.js';
12
+ const MAX = 12;
13
+ /** The picture types the page shows, by extension; any other file is never served. */
14
+ const TYPES = {
15
+ '.png': 'image/png',
16
+ '.jpg': 'image/jpeg',
17
+ '.jpeg': 'image/jpeg',
18
+ '.webp': 'image/webp',
19
+ '.gif': 'image/gif',
20
+ '.avif': 'image/avif',
21
+ };
22
+ export const pictureType = (file) => TYPES[extname(file).toLowerCase()];
23
+ const SHOT = /^[0-9a-f]{7,64}\/[^/\\]+\.png$/;
24
+ /** A comp screen's light and dark pictures: the product's theme, as the snapshot shot them. */
25
+ function screenShots(scene) {
26
+ const looks = Object.keys(scene.screenshots ?? {});
27
+ const dark = looks.find((look) => look.endsWith('.dark'));
28
+ const light = dark && looks.includes(dark.slice(0, -5)) ? dark.slice(0, -5) : looks[0];
29
+ return { light, dark };
30
+ }
31
+ async function desktopWidth(root) {
32
+ try {
33
+ return frameSizes(await loadProduct(root)).desktop.width;
34
+ }
35
+ catch {
36
+ return frameSizes().desktop.width;
37
+ }
38
+ }
39
+ /**
40
+ * The reference files the page may show, in their places: on the person's own computer (the local
41
+ * studio) any listed picture; under a host only those inside the product's folder.
42
+ */
43
+ async function shownReferences(root, hosted) {
44
+ return (await referencePictures(root))
45
+ .slice(0, MAX)
46
+ .map(({ file, inside }) => file && (inside || !hosted) && pictureType(file) ? file : undefined);
47
+ }
48
+ export async function compReply(root, hosted = false) {
49
+ const surface = firstSurface(root);
50
+ const comp = newestComp(root);
51
+ const record = readCompApproval(root);
52
+ const references = await shownReferences(root, hosted);
53
+ const screens = (comp?.report.scenes ?? []).slice(0, MAX).map((scene, index) => {
54
+ const { light, dark } = screenShots(scene);
55
+ return {
56
+ key: scene.key.slice(0, 100),
57
+ title: String(scene.title ?? scene.key).slice(0, 200),
58
+ ...(light ? { light: `screen-${index}-light` } : {}),
59
+ ...(dark ? { dark: `screen-${index}-dark` } : {}),
60
+ };
61
+ });
62
+ return {
63
+ surface,
64
+ width: surface === 'phone' ? frameSizes().phone.width : await desktopWidth(root),
65
+ screens,
66
+ references: references.map((file, index) => (file ? `reference-${index}` : null)),
67
+ ...(comp ? { fingerprint: comp.fingerprint } : {}),
68
+ approved: compApproved(record, comp),
69
+ approval: record?.approval ?? null,
70
+ };
71
+ }
72
+ /** The file a picture name stands for, or undefined: only the comp's own shots and the references. */
73
+ export async function compPicture(root, name, hosted = false) {
74
+ const screen = /^screen-(\d{1,2})-(light|dark)$/.exec(name);
75
+ if (screen) {
76
+ const scene = newestComp(root)?.report.scenes[Number(screen[1])];
77
+ if (!scene)
78
+ return;
79
+ const look = screenShots(scene)[screen[2]];
80
+ const path = look ? scene.screenshots[look] : undefined;
81
+ return path && SHOT.test(path) ? join(compDir(snapshotsDir(root)), path) : undefined;
82
+ }
83
+ const reference = /^reference-(\d{1,2})$/.exec(name);
84
+ if (reference)
85
+ return (await shownReferences(root, hosted))[Number(reference[1])];
86
+ }
87
+ export function prototypeCompRoutes(root) {
88
+ return [
89
+ {
90
+ method: 'GET',
91
+ path: workbenchApi.prototypeComp,
92
+ right: 'read:runs',
93
+ handle: async ({ hosted }) => ({ status: 200, body: await compReply(root, !!hosted) }),
94
+ },
95
+ {
96
+ method: 'GET',
97
+ path: `${workbenchApi.prototypeComp}/picture/:name`,
98
+ right: 'read:runs',
99
+ handle: async ({ params, hosted }) => {
100
+ const file = await compPicture(root, params.name ?? '', !!hosted);
101
+ const type = file ? pictureType(file) : undefined;
102
+ const bytes = file && type ? await readFile(file).catch(() => undefined) : undefined;
103
+ return bytes && type
104
+ ? { status: 200, body: bytes, type }
105
+ : { status: 404, body: { error: 'missing' } };
106
+ },
107
+ },
108
+ ];
109
+ }
@@ -72,12 +72,13 @@ export declare function planPrototypeOnMain(root: string, plan: PlanFacts | unde
72
72
  planned?: string | undefined;
73
73
  }[];
74
74
  notes: string[];
75
+ surface?: "desktop" | "phone" | undefined;
75
76
  problem?: string | undefined;
76
77
  } | null | undefined;
77
78
  themeDirection?: string | undefined;
78
79
  themeVoice?: string | undefined;
79
80
  brand: {
80
- kind: "brand" | "money" | "places" | "plan" | "prototype" | "release";
81
+ kind: "brand" | "comp" | "money" | "places" | "plan" | "prototype" | "release";
81
82
  signatures: {
82
83
  by: string;
83
84
  at: string;
@@ -11,7 +11,10 @@ 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, view }) => ({
14
+ // The comp's scenes (`comp/`) are snapshotted apart and never listed among the scenes.
15
+ const scenes = prototype.scenes
16
+ .filter(({ key }) => !(typeof key === 'string' && key.startsWith('comp/')))
17
+ .map(({ key, title, surface, view }) => ({
15
18
  key,
16
19
  title,
17
20
  surface,
@@ -8,7 +8,7 @@ import type { SnapshotProgress } from './snapshot-progress.ts';
8
8
  export { SNAPSHOT_TIMEOUT_MS };
9
9
  export declare const SNAPSHOT_OUTPUT_BYTES: number;
10
10
  type Status = 'idle' | 'serversNeeded' | 'running' | 'stopped' | 'failed' | 'passed';
11
- type Options = Pick<UiServerOptions, 'runner' | 'stack' | 'snapshotLimits'>;
11
+ type Options = Pick<UiServerOptions, 'runner' | 'stack' | 'snapshotLimits' | 'onFullSnapshot'>;
12
12
  /** Main keeps the runner id `snapshot`; a change in its own checkout runs on `snapshot:<change>`. */
13
13
  export declare const runnerId: (change: string, linked: boolean) => "snapshot" | `snapshot:${string}`;
14
14
  export declare const sameSource: (a: Pick<PrototypeSource, 'change' | 'checkout' | 'commit'> | undefined, b: PrototypeSource) => boolean;
@@ -163,6 +163,9 @@ export class SnapshotSessions {
163
163
  ...(proof ? { proof } : {}),
164
164
  result,
165
165
  });
166
+ // Only a full run that passed starts the critique, as a fresh turn of its own.
167
+ if (proof)
168
+ this.options.onFullSnapshot?.(source, run.files?.[0]);
166
169
  }
167
170
  start(source, linked, scenes) {
168
171
  const controller = new AbortController();
@@ -3,6 +3,6 @@ import type { UiRoute } from './routes.ts';
3
3
  import type { UiServerOptions } from './server.ts';
4
4
  export { SNAPSHOT_OUTPUT_BYTES, SNAPSHOT_TIMEOUT_MS } from './prototype-snapshot-session.ts';
5
5
  /** A person-operated snapshot route; execution belongs to the captured session. */
6
- export declare function prototypeSnapshotRoute(options: Pick<UiServerOptions, 'runner' | 'stack' | 'snapshotLimits'>, shutdown?: AbortSignal): UiRoute & {
6
+ export declare function prototypeSnapshotRoute(options: Pick<UiServerOptions, 'runner' | 'stack' | 'snapshotLimits' | 'onFullSnapshot'>, shutdown?: AbortSignal): UiRoute & {
7
7
  record: (change: string) => ReviewProof;
8
8
  };
@@ -27,13 +27,16 @@ export interface UiRequest extends MergeConfiguration, SaveConfiguration, Outsid
27
27
  /** The JSON body, at most `limit` characters (10,000 by default); `{}` when empty. */
28
28
  body: (limit?: number) => Promise<unknown>;
29
29
  }
30
+ /** The image types an answer's bytes may be sent as. */
31
+ export type ImageType = 'image/png' | 'image/jpeg' | 'image/webp' | 'image/gif' | 'image/avif';
30
32
  export interface UiAnswer {
31
33
  status: number;
32
- /** JSON; a Buffer is sent as a PNG image. */
34
+ /** JSON; a Buffer is sent as an image, PNG unless `type` names another. */
33
35
  body: unknown;
36
+ type?: ImageType;
34
37
  }
35
- /** A PNG answer: never cached or sniffed. */
36
- export declare function sendPng(res: ServerResponse, status: number, png: Buffer): void;
38
+ /** An image answer (PNG by default): never cached or sniffed. */
39
+ export declare function sendPng(res: ServerResponse, status: number, png: Buffer, type?: ImageType): void;
37
40
  export interface UiRoute {
38
41
  method: 'GET' | 'POST';
39
42
  path: `/api/${string}`;
@@ -1,7 +1,7 @@
1
- /** A PNG answer: never cached or sniffed. */
2
- export function sendPng(res, status, png) {
1
+ /** An image answer (PNG by default): never cached or sniffed. */
2
+ export function sendPng(res, status, png, type = 'image/png') {
3
3
  res.writeHead(status, {
4
- 'content-type': 'image/png',
4
+ 'content-type': type,
5
5
  'content-length': png.length,
6
6
  'cache-control': 'no-store',
7
7
  'x-content-type-options': 'nosniff',
@@ -1,6 +1,7 @@
1
1
  import { readFile, writeFile } from 'node:fs/promises';
2
2
  import { dirname, join } from 'node:path';
3
3
  import { MAIN_REF } from '../main-ref.js';
4
+ import { COMP_FILE, COMP_SUBJECT } from '../prototype/comp-record.js';
4
5
  import { changedByChecks, held, onHead, refFailure, unknown } from './save-failure.js';
5
6
  import { editedHooks } from './save-hooks.js';
6
7
  import { t } from './save-messages.js';
@@ -17,6 +18,8 @@ const stepNames = {
17
18
  export function stepMessage(step, count, approval) {
18
19
  if (step === 'places-approval')
19
20
  return 'plan: approve the places';
21
+ if (step === 'prototype-approval' && approval?.file === COMP_FILE)
22
+ return COMP_SUBJECT;
20
23
  if (step === 'prototype-approval' && approval) {
21
24
  const change = /^prototype\/versions\/(C-\d{3,})\.json$/.exec(approval.file)?.[1];
22
25
  try {
@@ -14,6 +14,8 @@ import type { Runner } from './runner.ts';
14
14
  import type { Stack } from './stack.ts';
15
15
  export type { Machine, Right, Viewer } from '@buffcore/contracts/workbench';
16
16
  export type { ApprovalArtifact, HostApproval, HostApprovalAnswer } from './approval-authority.ts';
17
+ export { FreshLooks } from './chat/fresh.ts';
18
+ export { freshRoutes } from './chat/fresh-routes.ts';
17
19
  export { chatRoutes } from './chat/routes.ts';
18
20
  export { ChatEngine, type ChatEngineOptions } from './chat/turn.ts';
19
21
  export type { HostLevel, SignIn, UiIdentity } from './host.ts';
@@ -42,6 +44,11 @@ export interface Plan {
42
44
  export interface UiServerOptions extends SaveConfiguration, OutsideConfiguration, HostPageOptions {
43
45
  turnMigrations?: TurnMigrations;
44
46
  snapshotLimits?: CommandSpec['limits'];
47
+ /** A full studio snapshot passed: the studio starts the critique as a fresh turn. */
48
+ onFullSnapshot?: (source: {
49
+ change: string;
50
+ checkout: string;
51
+ }, report?: string) => void;
45
52
  /** Required for local use; ignored when the host supplies signIn. */
46
53
  token?: string;
47
54
  /** Local recovery only; ignored completely in hosted mode. */
@@ -16,6 +16,8 @@ import { checkedUiOptions } from './server-options.js';
16
16
  import { localListener, migrationSignal, requestContext } from './server-request.js';
17
17
  import { runnerKey, snapshotRunners } from './snapshot-runners.js';
18
18
  import { studioT } from './studio-messages.js';
19
+ export { FreshLooks } from './chat/fresh.js';
20
+ export { freshRoutes } from './chat/fresh-routes.js';
19
21
  export { chatRoutes } from './chat/routes.js';
20
22
  export { ChatEngine } from './chat/turn.js';
21
23
  export { pageScript } from './page.js';
@@ -42,7 +44,9 @@ function send(res, status, body, type = 'application/json', extra = {}) {
42
44
  });
43
45
  res.end(scrubLaunchIds(body));
44
46
  }
45
- const json = (res, status, body) => Buffer.isBuffer(body) ? sendPng(res, status, body) : send(res, status, JSON.stringify(body));
47
+ const json = (res, status, body, type) => Buffer.isBuffer(body)
48
+ ? sendPng(res, status, body, type)
49
+ : send(res, status, JSON.stringify(body));
46
50
  /** The server, not yet listening. Local callers use listenLocal; a host owns its listener. */
47
51
  export function createUiServer(input) {
48
52
  const options = checkedUiOptions(input);
@@ -85,7 +89,7 @@ async function handleRequest(options, routes, req, res, port, script, shutdown)
85
89
  const { pathname: path, search } = new URL(req.url ?? '/', 'http://workbench');
86
90
  if (!options.signIn && path === migrationRoute && options.turnMigrations) {
87
91
  const answer = await options.turnMigrations.request(req, migrationSignal(res, shutdown));
88
- return json(res, answer.status, answer.body);
92
+ return json(res, answer.status, answer.body, answer.type);
89
93
  }
90
94
  if (req.method === 'GET' && path === '/') {
91
95
  const headers = options.signIn ? {} : LOCAL_PAGE_HEADERS;
@@ -127,5 +131,5 @@ async function handleApi(options, routes, req, res, path, shutdown) {
127
131
  const refusal = requestRefusal(found.route, request) ??
128
132
  denied(identity.viewer, await routeRight(found.route, request));
129
133
  const answer = refusal ?? (await found.route.handle(request));
130
- return json(res, answer.status, answer.body);
134
+ return json(res, answer.status, answer.body, answer.type);
131
135
  }
@@ -0,0 +1,6 @@
1
+ import { type FirstSurface } from '@buffcore/contracts/workbench';
2
+ import type { UiRoute } from './routes.ts';
3
+ /** The structure's text with its surface line set: replaced where it is, else after the title. */
4
+ export declare function withSurface(source: string, surface: FirstSurface): string;
5
+ /** A person with the build right answers; Structure's Save commits the file as it does the rest. */
6
+ export declare function structureSurfaceRoute(root: string): UiRoute;