@buffcore/cli 0.8.42 → 0.8.44

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 (119) hide show
  1. package/CHANGELOG.md +26 -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/approval-folders.d.ts +20 -0
  22. package/dist/commands/ui/chat/approval-folders.js +134 -0
  23. package/dist/commands/ui/chat/approval-text.d.ts +11 -0
  24. package/dist/commands/ui/chat/approval-text.js +69 -0
  25. package/dist/commands/ui/chat/approval-writes.d.ts +32 -0
  26. package/dist/commands/ui/chat/approval-writes.js +179 -0
  27. package/dist/commands/ui/chat/claude-permissions.d.ts +4 -4
  28. package/dist/commands/ui/chat/claude-permissions.js +32 -4
  29. package/dist/commands/ui/chat/codex-idle.d.ts +1 -0
  30. package/dist/commands/ui/chat/commit-limits.d.ts +36 -0
  31. package/dist/commands/ui/chat/commit-limits.js +164 -0
  32. package/dist/commands/ui/chat/fresh-critique.d.ts +28 -0
  33. package/dist/commands/ui/chat/fresh-critique.js +123 -0
  34. package/dist/commands/ui/chat/fresh-launch.d.ts +36 -0
  35. package/dist/commands/ui/chat/fresh-launch.js +125 -0
  36. package/dist/commands/ui/chat/fresh-prompts.d.ts +17 -0
  37. package/dist/commands/ui/chat/fresh-prompts.js +76 -0
  38. package/dist/commands/ui/chat/fresh-report.d.ts +8 -0
  39. package/dist/commands/ui/chat/fresh-report.js +36 -0
  40. package/dist/commands/ui/chat/fresh-routes.d.ts +3 -0
  41. package/dist/commands/ui/chat/fresh-routes.js +64 -0
  42. package/dist/commands/ui/chat/fresh-settings.d.ts +12 -0
  43. package/dist/commands/ui/chat/fresh-settings.js +66 -0
  44. package/dist/commands/ui/chat/fresh-store.d.ts +17 -0
  45. package/dist/commands/ui/chat/fresh-store.js +67 -0
  46. package/dist/commands/ui/chat/fresh.d.ts +31 -0
  47. package/dist/commands/ui/chat/fresh.en.d.ts +7 -0
  48. package/dist/commands/ui/chat/fresh.en.js +7 -0
  49. package/dist/commands/ui/chat/fresh.es.d.ts +7 -0
  50. package/dist/commands/ui/chat/fresh.es.js +7 -0
  51. package/dist/commands/ui/chat/fresh.js +118 -0
  52. package/dist/commands/ui/chat/gh-api-limits.d.ts +14 -0
  53. package/dist/commands/ui/chat/gh-api-limits.js +74 -0
  54. package/dist/commands/ui/chat/git-words.d.ts +10 -0
  55. package/dist/commands/ui/chat/git-words.js +26 -0
  56. package/dist/commands/ui/chat/host-launched.d.ts +11 -0
  57. package/dist/commands/ui/chat/host-launched.js +35 -0
  58. package/dist/commands/ui/chat/limit-mentions.d.ts +2 -2
  59. package/dist/commands/ui/chat/limit-mentions.js +36 -2
  60. package/dist/commands/ui/chat/limit-text.d.ts +15 -0
  61. package/dist/commands/ui/chat/limit-text.js +36 -0
  62. package/dist/commands/ui/chat/limits-hook.js +2 -2
  63. package/dist/commands/ui/chat/limits.d.ts +11 -9
  64. package/dist/commands/ui/chat/limits.en.d.ts +4 -0
  65. package/dist/commands/ui/chat/limits.en.js +4 -0
  66. package/dist/commands/ui/chat/limits.es.js +4 -0
  67. package/dist/commands/ui/chat/limits.js +67 -51
  68. package/dist/commands/ui/chat/parse-claude.js +7 -3
  69. package/dist/commands/ui/chat/permission-ask.js +3 -0
  70. package/dist/commands/ui/chat/planning-limits.js +26 -0
  71. package/dist/commands/ui/chat/publish-limits.d.ts +4 -0
  72. package/dist/commands/ui/chat/publish-limits.js +113 -0
  73. package/dist/commands/ui/chat/recorded-turn.js +3 -0
  74. package/dist/commands/ui/chat/stream.js +4 -1
  75. package/dist/commands/ui/chat/turn-guard.d.ts +10 -2
  76. package/dist/commands/ui/chat/turn-guard.js +20 -3
  77. package/dist/commands/ui/chat/turn-state.d.ts +5 -0
  78. package/dist/commands/ui/chat/turn.js +1 -0
  79. package/dist/commands/ui/comp-approval.d.ts +6 -0
  80. package/dist/commands/ui/comp-approval.js +42 -0
  81. package/dist/commands/ui/host.js +3 -0
  82. package/dist/commands/ui/index.d.ts +42 -0
  83. package/dist/commands/ui/index.js +32 -8
  84. package/dist/commands/ui/loop-approve.d.ts +4 -4
  85. package/dist/commands/ui/places-change.d.ts +1 -1
  86. package/dist/commands/ui/plan-structure.d.ts +3 -0
  87. package/dist/commands/ui/plan-structure.en.d.ts +3 -0
  88. package/dist/commands/ui/plan-structure.en.js +3 -0
  89. package/dist/commands/ui/plan-structure.es.d.ts +3 -0
  90. package/dist/commands/ui/plan-structure.es.js +3 -0
  91. package/dist/commands/ui/plan-structure.js +12 -4
  92. package/dist/commands/ui/prototype-comp-route.d.ts +7 -0
  93. package/dist/commands/ui/prototype-comp-route.js +109 -0
  94. package/dist/commands/ui/prototype-main.d.ts +2 -1
  95. package/dist/commands/ui/prototype-scenes-child.js +4 -1
  96. package/dist/commands/ui/prototype-snapshot-session.d.ts +1 -1
  97. package/dist/commands/ui/prototype-snapshot-session.js +3 -0
  98. package/dist/commands/ui/prototype-snapshot.d.ts +1 -1
  99. package/dist/commands/ui/routes.d.ts +8 -3
  100. package/dist/commands/ui/routes.js +3 -3
  101. package/dist/commands/ui/save-publish.js +3 -0
  102. package/dist/commands/ui/server-options.js +1 -0
  103. package/dist/commands/ui/server-request.js +5 -0
  104. package/dist/commands/ui/server.d.ts +14 -0
  105. package/dist/commands/ui/server.js +10 -3
  106. package/dist/commands/ui/structure-surface.d.ts +6 -0
  107. package/dist/commands/ui/structure-surface.js +94 -0
  108. package/dist/commands/ui/studio-routes.d.ts +1 -0
  109. package/dist/commands/ui/studio-routes.js +7 -1
  110. package/dist/commands/ui/studio-state.d.ts +7 -4
  111. package/dist/commands/ui/studio-versions.d.ts +3 -3
  112. package/dist/ui/page.js +98 -89
  113. package/docs/PROCESS.md +5 -0
  114. package/docs/PROTOTYPE.md +31 -0
  115. package/docs/WORKBENCH.md +11 -2
  116. package/package.json +11 -11
  117. package/skills/ape-critique/SKILL.md +9 -3
  118. package/skills/ape-design-system/SKILL.md +2 -1
  119. package/skills/ape-prototype/SKILL.md +5 -1
@@ -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
  };
@@ -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
@@ -27,13 +29,16 @@ export interface UiRequest extends MergeConfiguration, SaveConfiguration, Outsid
27
29
  /** The JSON body, at most `limit` characters (10,000 by default); `{}` when empty. */
28
30
  body: (limit?: number) => Promise<unknown>;
29
31
  }
32
+ /** The image types an answer's bytes may be sent as. */
33
+ export type ImageType = 'image/png' | 'image/jpeg' | 'image/webp' | 'image/gif' | 'image/avif';
30
34
  export interface UiAnswer {
31
35
  status: number;
32
- /** JSON; a Buffer is sent as a PNG image. */
36
+ /** JSON; a Buffer is sent as an image, PNG unless `type` names another. */
33
37
  body: unknown;
38
+ type?: ImageType;
34
39
  }
35
- /** A PNG answer: never cached or sniffed. */
36
- export declare function sendPng(res: ServerResponse, status: number, png: Buffer): void;
40
+ /** An image answer (PNG by default): never cached or sniffed. */
41
+ export declare function sendPng(res: ServerResponse, status: number, png: Buffer, type?: ImageType): void;
37
42
  export interface UiRoute {
38
43
  method: 'GET' | 'POST';
39
44
  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 {
@@ -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,
@@ -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. */
@@ -53,6 +60,13 @@ export interface UiServerOptions extends SaveConfiguration, OutsideConfiguration
53
60
  mergeTimeoutMs?: number;
54
61
  /** Host-owned isolation boundary; never inferred from product inputs. */
55
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;
56
70
  product: string;
57
71
  script: () => Promise<string>;
58
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';
@@ -16,6 +17,8 @@ import { checkedUiOptions } from './server-options.js';
16
17
  import { localListener, migrationSignal, requestContext } from './server-request.js';
17
18
  import { runnerKey, snapshotRunners } from './snapshot-runners.js';
18
19
  import { studioT } from './studio-messages.js';
20
+ export { FreshLooks } from './chat/fresh.js';
21
+ export { freshRoutes } from './chat/fresh-routes.js';
19
22
  export { chatRoutes } from './chat/routes.js';
20
23
  export { ChatEngine } from './chat/turn.js';
21
24
  export { pageScript } from './page.js';
@@ -42,7 +45,9 @@ function send(res, status, body, type = 'application/json', extra = {}) {
42
45
  });
43
46
  res.end(scrubLaunchIds(body));
44
47
  }
45
- const json = (res, status, body) => Buffer.isBuffer(body) ? sendPng(res, status, body) : send(res, status, JSON.stringify(body));
48
+ const json = (res, status, body, type) => Buffer.isBuffer(body)
49
+ ? sendPng(res, status, body, type)
50
+ : send(res, status, JSON.stringify(body));
46
51
  /** The server, not yet listening. Local callers use listenLocal; a host owns its listener. */
47
52
  export function createUiServer(input) {
48
53
  const options = checkedUiOptions(input);
@@ -68,8 +73,10 @@ export function createUiServer(input) {
68
73
  };
69
74
  if (key)
70
75
  snapshotRunners.set(key, options.runner);
76
+ const launcher = key ? registerHostLaunched(key, options.hostLaunched === true) : () => { };
71
77
  server.once('close', () => {
72
78
  shutdown.abort();
79
+ launcher();
73
80
  if (key && snapshotRunners.get(key) === options.runner)
74
81
  snapshotRunners.delete(key);
75
82
  });
@@ -85,7 +92,7 @@ async function handleRequest(options, routes, req, res, port, script, shutdown)
85
92
  const { pathname: path, search } = new URL(req.url ?? '/', 'http://workbench');
86
93
  if (!options.signIn && path === migrationRoute && options.turnMigrations) {
87
94
  const answer = await options.turnMigrations.request(req, migrationSignal(res, shutdown));
88
- return json(res, answer.status, answer.body);
95
+ return json(res, answer.status, answer.body, answer.type);
89
96
  }
90
97
  if (req.method === 'GET' && path === '/') {
91
98
  const headers = options.signIn ? {} : LOCAL_PAGE_HEADERS;
@@ -127,5 +134,5 @@ async function handleApi(options, routes, req, res, path, shutdown) {
127
134
  const refusal = requestRefusal(found.route, request) ??
128
135
  denied(identity.viewer, await routeRight(found.route, request));
129
136
  const answer = refusal ?? (await found.route.handle(request));
130
- return json(res, answer.status, answer.body);
137
+ return json(res, answer.status, answer.body, answer.type);
131
138
  }
@@ -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;
@@ -0,0 +1,94 @@
1
+ // "Which surface comes first?": the person's answer, kept in `plan/structure.md`'s header line
2
+ // (`Surface: desktop` or `Surface: phone`), written to the working copy; Structure's Save commits it.
3
+ import { randomUUID } from 'node:crypto';
4
+ import { existsSync } from 'node:fs';
5
+ import { readFile, rename, rm, writeFile } from 'node:fs/promises';
6
+ import { join } from 'node:path';
7
+ import { structureSurfaceBodySchema, workbenchApi, } from '@buffcore/contracts/workbench';
8
+ import { createI18n } from '@buffcore/i18n';
9
+ import { SURFACE_FIELD } from '../prototype/comp.js';
10
+ import { VersionRefusal } from '../prototype/versions.js';
11
+ import { personForTurn } from './chat/person.js';
12
+ import { hostT } from './host.js';
13
+ import { en } from './plan-structure.en.js';
14
+ import { es } from './plan-structure.es.js';
15
+ import { parseStructure } from './plan-structure.js';
16
+ import { savePathReason } from './save-paths.js';
17
+ import { withStudioSave } from './save-route.js';
18
+ const FILE = 'plan/structure.md';
19
+ const messages = createI18n({ catalogs: [{ en, es }] });
20
+ const surfaceT = (key) => messages.t(/^es(?:[-_.]|$)/i.test(process.env.LC_ALL || process.env.LANG || '') ? 'es' : 'en', key);
21
+ /** The structure's text with its surface line set: replaced where it is, else after the title. */
22
+ export function withSurface(source, surface) {
23
+ // A byte-order mark stays the file's first character.
24
+ const bom = source.startsWith('') ? '' : '';
25
+ const text = source.slice(bom.length);
26
+ const eol = text.includes('\r\n') ? '\r\n' : '\n';
27
+ const lines = text.split(/\r\n|\n/);
28
+ const line = `Surface: ${surface}`;
29
+ const table = lines.findIndex((entry) => entry.startsWith('|'));
30
+ const head = lines.slice(0, table === -1 ? lines.length : table);
31
+ const at = head.findIndex((entry) => SURFACE_FIELD.test(entry));
32
+ if (at !== -1)
33
+ lines[at] = line;
34
+ else {
35
+ const title = head.findIndex((entry) => entry.startsWith('# '));
36
+ if (title === -1)
37
+ lines.splice(0, 0, line, '');
38
+ else
39
+ lines.splice(title + 1, 0, '', line);
40
+ }
41
+ return bom + lines.join(eol);
42
+ }
43
+ async function writeSurface(root, surface) {
44
+ const file = join(root, FILE);
45
+ if (!existsSync(file))
46
+ return surfaceT('structure.surfaceMissing');
47
+ const reason = savePathReason(root, [FILE]);
48
+ if (reason)
49
+ return reason;
50
+ const next = withSurface(await readFile(file, 'utf8'), surface);
51
+ try {
52
+ parseStructure(next);
53
+ }
54
+ catch (error) {
55
+ return error instanceof Error ? error.message : surfaceT('structure.surfaceFailed');
56
+ }
57
+ const temp = `${file}.${randomUUID()}.tmp`;
58
+ try {
59
+ await writeFile(temp, next, { flag: 'wx' });
60
+ await rename(temp, file);
61
+ }
62
+ catch {
63
+ await rm(temp, { force: true });
64
+ return surfaceT('structure.surfaceFailed');
65
+ }
66
+ }
67
+ /** A person with the build right answers; Structure's Save commits the file as it does the rest. */
68
+ export function structureSurfaceRoute(root) {
69
+ return {
70
+ method: 'POST',
71
+ path: workbenchApi.structureSurface,
72
+ right: 'build',
73
+ handle: async (request) => {
74
+ if (!personForTurn(request))
75
+ return { status: 403, body: { error: hostT('ui.host.private') } };
76
+ const body = structureSurfaceBodySchema.safeParse(await request.body());
77
+ if (!body.success)
78
+ return { status: 400, body: { error: surfaceT('structure.surfaceFailed') } };
79
+ try {
80
+ const answer = await withStudioSave(root, () => writeSurface(root, body.data.surface));
81
+ if (typeof answer === 'object')
82
+ return { status: 409, body: { error: answer.detail } };
83
+ if (answer)
84
+ return { status: 409, body: { error: answer } };
85
+ }
86
+ catch (error) {
87
+ if (error instanceof VersionRefusal)
88
+ return { status: 409, body: { error: error.message } };
89
+ return { status: 500, body: { error: surfaceT('structure.surfaceFailed') } };
90
+ }
91
+ return { status: 202, body: { surface: body.data.surface } };
92
+ },
93
+ };
94
+ }
@@ -4,6 +4,7 @@ export declare const studioAccess: {
4
4
  viewer: true;
5
5
  machine: true;
6
6
  contained: true;
7
+ hostLaunched: true;
7
8
  product: true;
8
9
  appUrl: true;
9
10
  plan: true;
@@ -12,14 +12,17 @@ import { mergeRoutes } from './merge-route.js';
12
12
  import { mergeStudio } from './merge-state.js';
13
13
  import { outsideState } from './outside.js';
14
14
  import { outsideRoute } from './outside-route.js';
15
+ import { prototypeCompRoutes } from './prototype-comp-route.js';
15
16
  import { planPrototypeOnMain } from './prototype-main.js';
16
17
  import { prototypeScenesRoute } from './prototype-scenes-route.js';
17
18
  import { saveRoute } from './save-route.js';
19
+ import { structureSurfaceRoute } from './structure-surface.js';
18
20
  import { Latest } from './studio-facts.js';
19
21
  export const studioAccess = {
20
22
  viewer: true,
21
23
  machine: true,
22
24
  contained: true,
25
+ hostLaunched: true,
23
26
  product: true,
24
27
  appUrl: true,
25
28
  plan: true,
@@ -83,13 +86,15 @@ cached = false) {
83
86
  agentsRoute(root),
84
87
  agentCheckRoute(root),
85
88
  prototypeScenesRoute(root),
89
+ ...prototypeCompRoutes(root),
90
+ structureSurfaceRoute(root),
86
91
  outsideRoute,
87
92
  {
88
93
  method: 'GET',
89
94
  path: '/api/studio',
90
95
  readable: true,
91
96
  handle: async (request) => {
92
- const { identity, hosted, approval, level, contained = false } = request;
97
+ const { identity, hosted, approval, level, contained = false, hostLaunched } = request;
93
98
  const current = await merged(await state({ identity, hosted, approval, level }), request);
94
99
  const context = authorityFor({ identity, approval });
95
100
  const checked = context
@@ -103,6 +108,7 @@ cached = false) {
103
108
  viewer: identity?.viewer,
104
109
  machine: identity?.machine,
105
110
  contained,
111
+ hostLaunched: hostLaunched === true,
106
112
  level,
107
113
  outside: outsideState(request.outside),
108
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;
@@ -35,6 +36,7 @@ export declare function studioState(root: string, options: Pick<UiServerOptions,
35
36
  effort?: Partial<Record<"coding" | "design" | "fixes" | "planning" | "tests" | "validation", "auto" | "high" | "low" | "max" | "medium" | "xhigh">> | undefined;
36
37
  level: "auto" | "guide" | "lead" | "review";
37
38
  neverAsk?: boolean | undefined;
39
+ review?: boolean | undefined;
38
40
  } | null;
39
41
  found: {
40
42
  id: "antigravity" | "claude" | "codex" | "cursor" | "grok" | "muse" | "opencode";
@@ -89,7 +91,7 @@ export declare function studioState(root: string, options: Pick<UiServerOptions,
89
91
  approved?: {
90
92
  version: number;
91
93
  approval: {
92
- kind: "brand" | "money" | "places" | "plan" | "prototype" | "release";
94
+ kind: "brand" | "comp" | "money" | "places" | "plan" | "prototype" | "release";
93
95
  signatures: {
94
96
  by: string;
95
97
  at: string;
@@ -114,7 +116,7 @@ export declare function studioState(root: string, options: Pick<UiServerOptions,
114
116
  pending?: {
115
117
  version: number;
116
118
  approval: {
117
- kind: "brand" | "money" | "places" | "plan" | "prototype" | "release";
119
+ kind: "brand" | "comp" | "money" | "places" | "plan" | "prototype" | "release";
118
120
  signatures: {
119
121
  by: string;
120
122
  at: string;
@@ -139,7 +141,7 @@ export declare function studioState(root: string, options: Pick<UiServerOptions,
139
141
  superseded?: {
140
142
  version: number;
141
143
  approval: {
142
- kind: "brand" | "money" | "places" | "plan" | "prototype" | "release";
144
+ kind: "brand" | "comp" | "money" | "places" | "plan" | "prototype" | "release";
143
145
  signatures: {
144
146
  by: string;
145
147
  at: string;
@@ -235,12 +237,13 @@ export declare function studioState(root: string, options: Pick<UiServerOptions,
235
237
  planned?: string | undefined;
236
238
  }[];
237
239
  notes: string[];
240
+ surface?: "desktop" | "phone" | undefined;
238
241
  problem?: string | undefined;
239
242
  } | null | undefined;
240
243
  themeDirection?: string | undefined;
241
244
  themeVoice?: string | undefined;
242
245
  brand: {
243
- kind: "brand" | "money" | "places" | "plan" | "prototype" | "release";
246
+ kind: "brand" | "comp" | "money" | "places" | "plan" | "prototype" | "release";
244
247
  signatures: {
245
248
  by: string;
246
249
  at: string;
@@ -14,7 +14,7 @@ export declare function authorityVersion(root: string, change: string): {
14
14
  approved?: {
15
15
  version: number;
16
16
  approval: {
17
- kind: "brand" | "money" | "places" | "plan" | "prototype" | "release";
17
+ kind: "brand" | "comp" | "money" | "places" | "plan" | "prototype" | "release";
18
18
  signatures: {
19
19
  by: string;
20
20
  at: string;
@@ -39,7 +39,7 @@ export declare function authorityVersion(root: string, change: string): {
39
39
  pending?: {
40
40
  version: number;
41
41
  approval: {
42
- kind: "brand" | "money" | "places" | "plan" | "prototype" | "release";
42
+ kind: "brand" | "comp" | "money" | "places" | "plan" | "prototype" | "release";
43
43
  signatures: {
44
44
  by: string;
45
45
  at: string;
@@ -64,7 +64,7 @@ export declare function authorityVersion(root: string, change: string): {
64
64
  superseded?: {
65
65
  version: number;
66
66
  approval: {
67
- kind: "brand" | "money" | "places" | "plan" | "prototype" | "release";
67
+ kind: "brand" | "comp" | "money" | "places" | "plan" | "prototype" | "release";
68
68
  signatures: {
69
69
  by: string;
70
70
  at: string;