@buffcore/cli 0.8.40 → 0.8.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/commands/agents-file.d.ts +5 -0
  3. package/dist/commands/agents-file.js +30 -7
  4. package/dist/commands/change.d.ts +4 -0
  5. package/dist/commands/change.js +12 -5
  6. package/dist/commands/create-block.d.ts +2 -1
  7. package/dist/commands/create-block.js +7 -5
  8. package/dist/commands/create-steps.en.js +1 -1
  9. package/dist/commands/create-steps.js +1 -1
  10. package/dist/commands/create.d.ts +3 -2
  11. package/dist/commands/create.en.js +1 -1
  12. package/dist/commands/create.es.js +1 -1
  13. package/dist/commands/create.js +8 -6
  14. package/dist/commands/design/check.d.ts +2 -0
  15. package/dist/commands/design/check.js +6 -0
  16. package/dist/commands/design/journey-roles.d.ts +6 -0
  17. package/dist/commands/design/journey-roles.js +60 -0
  18. package/dist/commands/design/references.d.ts +3 -0
  19. package/dist/commands/design/references.js +25 -0
  20. package/dist/commands/design/tells-text.js +2 -2
  21. package/dist/commands/design/tells.d.ts +3 -1
  22. package/dist/commands/design/tells.en.d.ts +2 -0
  23. package/dist/commands/design/tells.en.js +2 -0
  24. package/dist/commands/design/tells.es.js +2 -0
  25. package/dist/commands/design/tells.js +10 -7
  26. package/dist/commands/dev.js +3 -0
  27. package/dist/commands/port-claims.d.ts +23 -0
  28. package/dist/commands/port-claims.js +95 -0
  29. package/dist/commands/prototype/browser.d.ts +9 -4
  30. package/dist/commands/prototype/browser.js +26 -18
  31. package/dist/commands/prototype/export-base.d.ts +27 -0
  32. package/dist/commands/prototype/export-base.js +80 -0
  33. package/dist/commands/prototype/export.d.ts +3 -2
  34. package/dist/commands/prototype/export.js +13 -6
  35. package/dist/commands/prototype/index.js +1 -0
  36. package/dist/commands/prototype/media-ready.d.ts +8 -0
  37. package/dist/commands/prototype/media-ready.js +36 -0
  38. package/dist/commands/prototype/messages.en.d.ts +6 -0
  39. package/dist/commands/prototype/messages.en.js +6 -0
  40. package/dist/commands/prototype/messages.js +6 -0
  41. package/dist/commands/prototype/scene.d.ts +3 -1
  42. package/dist/commands/prototype/scene.js +22 -6
  43. package/dist/commands/prototype/snapshot-inputs.js +35 -7
  44. package/dist/commands/prototype/snapshot-setup.d.ts +1 -1
  45. package/dist/commands/prototype/snapshot-setup.js +2 -1
  46. package/dist/commands/prototype/snapshot-themes.js +3 -1
  47. package/dist/commands/prototype/snapshot.d.ts +2 -0
  48. package/dist/commands/prototype/snapshot.js +2 -1
  49. package/dist/commands/ui/autopilot-records.d.ts +3 -0
  50. package/dist/commands/ui/chat/allow-folder-route.d.ts +9 -0
  51. package/dist/commands/ui/chat/allow-folder-route.js +56 -0
  52. package/dist/commands/ui/chat/allow-folder.d.ts +18 -0
  53. package/dist/commands/ui/chat/allow-folder.js +76 -0
  54. package/dist/commands/ui/chat/ask-person.d.ts +17 -0
  55. package/dist/commands/ui/chat/ask-person.en.d.ts +4 -0
  56. package/dist/commands/ui/chat/ask-person.en.js +4 -0
  57. package/dist/commands/ui/chat/ask-person.es.d.ts +4 -0
  58. package/dist/commands/ui/chat/ask-person.es.js +4 -0
  59. package/dist/commands/ui/chat/ask-person.js +60 -0
  60. package/dist/commands/ui/chat/claude-permissions.d.ts +21 -0
  61. package/dist/commands/ui/chat/claude-permissions.js +69 -0
  62. package/dist/commands/ui/chat/codex-idle.d.ts +1 -0
  63. package/dist/commands/ui/chat/codex-overrides.js +2 -1
  64. package/dist/commands/ui/chat/codex-permissions.d.ts +12 -0
  65. package/dist/commands/ui/chat/codex-permissions.js +97 -0
  66. package/dist/commands/ui/chat/command-parts.d.ts +33 -0
  67. package/dist/commands/ui/chat/command-parts.js +219 -0
  68. package/dist/commands/ui/chat/command-wrappers.d.ts +21 -0
  69. package/dist/commands/ui/chat/command-wrappers.js +100 -0
  70. package/dist/commands/ui/chat/design-deletes.d.ts +1 -0
  71. package/dist/commands/ui/chat/design-deletes.js +39 -0
  72. package/dist/commands/ui/chat/launch-input.d.ts +4 -2
  73. package/dist/commands/ui/chat/launch-input.js +16 -3
  74. package/dist/commands/ui/chat/limit-mentions.d.ts +5 -0
  75. package/dist/commands/ui/chat/limit-mentions.js +74 -0
  76. package/dist/commands/ui/chat/limit-patterns.d.ts +15 -0
  77. package/dist/commands/ui/chat/limit-patterns.js +182 -0
  78. package/dist/commands/ui/chat/limits-hook.d.ts +1 -0
  79. package/dist/commands/ui/chat/limits-hook.js +30 -0
  80. package/dist/commands/ui/chat/limits.d.ts +37 -0
  81. package/dist/commands/ui/chat/limits.en.d.ts +18 -0
  82. package/dist/commands/ui/chat/limits.en.js +18 -0
  83. package/dist/commands/ui/chat/limits.es.d.ts +2 -0
  84. package/dist/commands/ui/chat/limits.es.js +17 -0
  85. package/dist/commands/ui/chat/limits.js +224 -0
  86. package/dist/commands/ui/chat/local-settings.d.ts +17 -0
  87. package/dist/commands/ui/chat/local-settings.js +73 -0
  88. package/dist/commands/ui/chat/opencode-config.d.ts +22 -0
  89. package/dist/commands/ui/chat/opencode-config.js +83 -0
  90. package/dist/commands/ui/chat/parse-claude.js +18 -2
  91. package/dist/commands/ui/chat/permission-ask.d.ts +44 -0
  92. package/dist/commands/ui/chat/permission-ask.js +142 -0
  93. package/dist/commands/ui/chat/permission-channel.d.ts +18 -0
  94. package/dist/commands/ui/chat/permission-channel.js +67 -0
  95. package/dist/commands/ui/chat/permission-route.d.ts +10 -0
  96. package/dist/commands/ui/chat/permission-route.js +47 -0
  97. package/dist/commands/ui/chat/permission-tool.d.ts +1 -0
  98. package/dist/commands/ui/chat/permission-tool.js +86 -0
  99. package/dist/commands/ui/chat/permissions.d.ts +11 -12
  100. package/dist/commands/ui/chat/permissions.js +20 -102
  101. package/dist/commands/ui/chat/planning-limits.d.ts +12 -0
  102. package/dist/commands/ui/chat/planning-limits.js +31 -0
  103. package/dist/commands/ui/chat/process.js +4 -1
  104. package/dist/commands/ui/chat/prompt.d.ts +8 -1
  105. package/dist/commands/ui/chat/prompt.en.d.ts +4 -0
  106. package/dist/commands/ui/chat/prompt.en.js +4 -0
  107. package/dist/commands/ui/chat/prompt.es.d.ts +4 -0
  108. package/dist/commands/ui/chat/prompt.es.js +4 -0
  109. package/dist/commands/ui/chat/prompt.js +18 -50
  110. package/dist/commands/ui/chat/recorded-turn.js +5 -0
  111. package/dist/commands/ui/chat/routes.js +4 -0
  112. package/dist/commands/ui/chat/secret-folders.d.ts +16 -0
  113. package/dist/commands/ui/chat/secret-folders.js +35 -0
  114. package/dist/commands/ui/chat/stdin-shells.d.ts +8 -0
  115. package/dist/commands/ui/chat/stdin-shells.js +102 -0
  116. package/dist/commands/ui/chat/step-rules.d.ts +13 -0
  117. package/dist/commands/ui/chat/step-rules.js +47 -0
  118. package/dist/commands/ui/chat/store.d.ts +2 -0
  119. package/dist/commands/ui/chat/store.js +25 -3
  120. package/dist/commands/ui/chat/stream.en.d.ts +17 -0
  121. package/dist/commands/ui/chat/stream.en.js +18 -1
  122. package/dist/commands/ui/chat/stream.es.d.ts +17 -0
  123. package/dist/commands/ui/chat/stream.es.js +18 -1
  124. package/dist/commands/ui/chat/stream.js +4 -1
  125. package/dist/commands/ui/chat/turn-guard.d.ts +25 -0
  126. package/dist/commands/ui/chat/turn-guard.js +74 -0
  127. package/dist/commands/ui/chat/turn-input.d.ts +3 -2
  128. package/dist/commands/ui/chat/turn-input.js +3 -1
  129. package/dist/commands/ui/chat/turn-reserve.js +2 -0
  130. package/dist/commands/ui/chat/turn-scenes.d.ts +19 -0
  131. package/dist/commands/ui/chat/turn-scenes.js +44 -0
  132. package/dist/commands/ui/chat/turn-selection.d.ts +3 -0
  133. package/dist/commands/ui/chat/turn-selection.js +9 -3
  134. package/dist/commands/ui/chat/turn-state.d.ts +6 -0
  135. package/dist/commands/ui/chat/turn.js +8 -3
  136. package/dist/commands/ui/level-route.js +8 -3
  137. package/dist/commands/ui/page.d.ts +19 -1
  138. package/dist/commands/ui/page.js +9 -6
  139. package/dist/commands/ui/plan-structure.d.ts +9 -2
  140. package/dist/commands/ui/plan-structure.en.d.ts +1 -0
  141. package/dist/commands/ui/plan-structure.en.js +1 -0
  142. package/dist/commands/ui/plan-structure.es.d.ts +1 -0
  143. package/dist/commands/ui/plan-structure.es.js +1 -0
  144. package/dist/commands/ui/plan-structure.js +36 -10
  145. package/dist/commands/ui/prototype-main.d.ts +1 -0
  146. package/dist/commands/ui/prototype-scenes-child.js +3 -1
  147. package/dist/commands/ui/prototype-scenes-read.d.ts +1 -0
  148. package/dist/commands/ui/prototype-scenes-route.js +7 -1
  149. package/dist/commands/ui/save-commit.js +6 -2
  150. package/dist/commands/ui/server-options.js +2 -0
  151. package/dist/commands/ui/server.d.ts +5 -22
  152. package/dist/commands/ui/server.js +3 -45
  153. package/dist/commands/ui/snapshot-runners.d.ts +22 -0
  154. package/dist/commands/ui/snapshot-runners.js +45 -0
  155. package/dist/commands/ui/studio-routes.d.ts +1 -0
  156. package/dist/commands/ui/studio-routes.js +1 -0
  157. package/dist/commands/ui/studio-state.d.ts +4 -1
  158. package/dist/commands/ui/studio-state.js +1 -0
  159. package/dist/commands/ui/studio.en.d.ts +13 -0
  160. package/dist/commands/ui/studio.en.js +13 -0
  161. package/dist/commands/ui/studio.es.d.ts +13 -0
  162. package/dist/commands/ui/studio.es.js +13 -0
  163. package/dist/commands/ui/theme-option.d.ts +8 -0
  164. package/dist/commands/ui/theme-option.js +40 -0
  165. package/dist/commands/ui/theme-values.d.ts +5 -0
  166. package/dist/commands/ui/theme-values.js +113 -0
  167. package/dist/ui/page.js +86 -86
  168. package/docs/PROTOTYPE.md +4 -1
  169. package/docs/WORKBENCH.md +90 -26
  170. package/package.json +11 -11
  171. package/skills/ape-critique/SKILL.md +8 -4
  172. package/skills/ape-design-system/SKILL.md +14 -3
  173. package/skills/ape-plan-change/SKILL.md +9 -5
  174. package/skills/ape-prototype/SKILL.md +8 -1
  175. package/templates/example/apps/app/src/i18n/en.ts +2 -0
  176. package/templates/example/apps/app/src/i18n/es.json +2 -0
  177. package/templates/product/README.md +1 -1
  178. package/templates/product/apps/admin/src/fonts.ts +2 -1
  179. package/templates/product/apps/app/src/fonts.ts +5 -1
  180. package/templates/product/apps/app/src/i18n/en.ts +2 -0
  181. package/templates/product/apps/app/src/i18n/es.json +2 -0
  182. package/templates/product/prototype/journeys.ts +3 -0
@@ -1,7 +1,7 @@
1
- import { existsSync } from 'node:fs';
1
+ import { existsSync, readdirSync } from 'node:fs';
2
2
  import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
3
3
  import { parseEnv } from 'node:util';
4
- import { FRAME_SIZES, SURFACES } from '@buffcore/config';
4
+ import { SURFACES } from '@buffcore/config';
5
5
  import { pageOptions } from './browser.js';
6
6
  import { surfaceDir } from './export.js';
7
7
  import { locale } from './messages.js';
@@ -88,6 +88,19 @@ async function settingHashes(root, files, dependencies) {
88
88
  return [name, sha256(JSON.stringify(environment))];
89
89
  }));
90
90
  }
91
+ /** The design system's font files the console serves under `_fonts/`, as its Vite plugin lists them. */
92
+ function designFonts(root) {
93
+ const dir = join(root, 'design', 'fonts');
94
+ try {
95
+ return readdirSync(dir, { withFileTypes: true })
96
+ .filter((entry) => entry.isFile() && /\.(?:woff2?|ttf|otf)$/i.test(entry.name))
97
+ .map((entry) => join(dir, entry.name))
98
+ .sort();
99
+ }
100
+ catch {
101
+ return [];
102
+ }
103
+ }
91
104
  /** The HTML can load public fonts or images without a JavaScript import. */
92
105
  async function pageAssets(dir, read) {
93
106
  const page = join(dir, 'index.html');
@@ -115,9 +128,10 @@ async function surfaceEntry(root, surface, dependencies) {
115
128
  const configuration = await toolchains(dir, surface, dependencies.read);
116
129
  if (!configuration)
117
130
  return;
118
- const assets = await pageAssets(dir, dependencies.read).catch(() => undefined);
119
- if (!assets)
131
+ const page = await pageAssets(dir, dependencies.read).catch(() => undefined);
132
+ if (!page)
120
133
  return;
134
+ const assets = [...page, ...(surface === 'admin' ? designFonts(root) : [])];
121
135
  const entry = {
122
136
  surface,
123
137
  dir,
@@ -132,6 +146,9 @@ function hasSurfaceAsset(surface, url) {
132
146
  if (!surface)
133
147
  return false;
134
148
  const path = decodeURIComponent(url.pathname);
149
+ const { fonts } = surface;
150
+ if (fonts && path.startsWith(fonts.path))
151
+ return surface.assets.has(join(fonts.dir, path.slice(fonts.path.length)));
135
152
  if (path.startsWith('/@fs/'))
136
153
  return surface.assets.has(resolve(path.slice(5)));
137
154
  const metroAsset = url.searchParams.get('unstable_path');
@@ -140,6 +157,11 @@ function hasSurfaceAsset(surface, url) {
140
157
  return (surface.assets.has(resolve(surface.dir, `.${path}`)) ||
141
158
  surface.assets.has(resolve(surface.dir, 'public', `.${path}`)));
142
159
  }
160
+ /** The console's `_fonts/` under the base its address names (`/`, or `/s/abc/`). */
161
+ function fontPath(address) {
162
+ const base = decodeURIComponent(URL.parse(address)?.pathname ?? '/');
163
+ return `${base.endsWith('/') ? base : `${base}/`}_fonts/`;
164
+ }
143
165
  /** The surface loads its whole view registry. Scene definitions still identify individual scenes. */
144
166
  export async function snapshotInputs(root, scenes, run, browser, design,
145
167
  /** What the fingerprint reads public values from: the process's, or a linked run's own. */
@@ -162,6 +184,9 @@ environment = process.env) {
162
184
  dir: setup.entry.dir,
163
185
  hash: sha256(JSON.stringify([setup.settings, files])),
164
186
  assets: new Set([...setup.assets, ...files.map(([file]) => resolve(root, file))]),
187
+ ...(surface === 'admin' && {
188
+ fonts: { path: fontPath(run.urls.admin), dir: join(root, 'design', 'fonts') },
189
+ }),
165
190
  });
166
191
  }
167
192
  if (!inputs.size)
@@ -174,7 +199,11 @@ environment = process.env) {
174
199
  const surface = inputs.get(scene.surface);
175
200
  if (!surface || typeof scene.view !== 'string' || !plainData(scene))
176
201
  continue;
177
- fingerprints.set(scene.key, sha256(JSON.stringify([shared, surface.hash, scene, pageOptions(FRAME_SIZES[scene.frame])])));
202
+ // Each scene holds its own frame's size, in one key order: a new desktop frame re-shoots
203
+ // only the scenes shown in it.
204
+ const { width, height } = run.frames[scene.frame];
205
+ const page = pageOptions({ width, height });
206
+ fingerprints.set(scene.key, sha256(JSON.stringify([shared, surface.hash, scene, page])));
178
207
  }
179
208
  return result;
180
209
  }
@@ -184,10 +213,9 @@ environment = process.env) {
184
213
  */
185
214
  function sharedFingerprint(run, browser, common, design, environment) {
186
215
  return sha256(JSON.stringify([
187
- 'snapshot-inputs-v3',
216
+ 'snapshot-inputs-v4',
188
217
  dependencyVersion,
189
218
  browser,
190
- FRAME_SIZES,
191
219
  run.looks,
192
220
  run.fontTheme,
193
221
  run.first,
@@ -28,7 +28,7 @@ export interface Setup {
28
28
  progress: SnapshotProgressSource | undefined;
29
29
  urls: SnapshotOptions['urls'];
30
30
  dir: string;
31
- options: Pick<SnapshotOptions, 'scenes' | 'locales' | 'urls' | 'dir' | 'scene' | 'sceneTimeout' | 'root' | 'pages' | 'ownScenes'>;
31
+ options: Pick<SnapshotOptions, 'scenes' | 'locales' | 'frames' | 'urls' | 'dir' | 'scene' | 'sceneTimeout' | 'root' | 'pages' | 'ownScenes'>;
32
32
  seconds(): number;
33
33
  }
34
34
  export type Servers = {
@@ -10,7 +10,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
10
10
  import { existsSync } from 'node:fs';
11
11
  import { join } from 'node:path';
12
12
  import { pathToFileURL } from 'node:url';
13
- import { coreEnvSchema, defineEnv, isContainer, } from '@buffcore/config';
13
+ import { coreEnvSchema, defineEnv, frameSizes, isContainer, } from '@buffcore/config';
14
14
  import { developmentOnly, findRoot, loadEnv, loadProduct } from '../../project.js';
15
15
  import { loadTheme } from '../design/sources.js';
16
16
  import { ownSceneKeys } from './own-scenes.js';
@@ -108,6 +108,7 @@ export async function setup(flags, servers) {
108
108
  options: {
109
109
  scenes,
110
110
  locales: product.locales,
111
+ frames: frameSizes(product),
111
112
  urls,
112
113
  dir,
113
114
  scene,
@@ -5,7 +5,9 @@ import { themes } from '@buffcore/tokens';
5
5
  * must work in each).
6
6
  */
7
7
  export function themesOf(product) {
8
- const starters = Object.values(themes);
8
+ // Neutral and Soft hold BuffCore's components to every check; Clear, Warm and Bold pass the same
9
+ // token checks in their own tests. Five looks per scene would not fit one scene's time budget.
10
+ const starters = [themes.neutral, themes.soft];
9
11
  const starter = starters.find((theme) => theme.key === product?.key);
10
12
  return product && JSON.stringify(product) !== JSON.stringify(starter) ? [product] : starters;
11
13
  }
@@ -10,6 +10,8 @@ export interface SnapshotOptions {
10
10
  scenes: Scenes;
11
11
  /** The product's languages, its first the default. */
12
12
  locales: readonly string[];
13
+ /** Each frame's size (`frameSizes` of the product); unset, the presets. */
14
+ frames?: Run['frames'] | undefined;
13
15
  urls: Run['urls'];
14
16
  commit: string;
15
17
  /** `prototype/snapshots/`: the screenshots go in `<commit>/` there. */
@@ -29,6 +29,7 @@ function runOf(options) {
29
29
  sceneTimeout: options.sceneTimeout,
30
30
  checkCheckout: options.checkCheckout,
31
31
  looks,
32
+ frames: options.frames ?? FRAME_SIZES,
32
33
  product: (scenes.theme ?? looks[0])?.key ?? '',
33
34
  fontTheme: scenes.theme?.key,
34
35
  locales,
@@ -78,7 +79,7 @@ async function writeRun(options, run, picked) {
78
79
  return await withSnapshotProgress(options.progress, async () => {
79
80
  return [
80
81
  picked,
81
- picked.map(({ surface, frame }) => [surface, FRAME_SIZES[frame]]),
82
+ picked.map(({ surface, frame }) => [surface, run.frames[frame]]),
82
83
  picked.length ? await browserVersion() : null,
83
84
  run.looks,
84
85
  run.fontTheme,
@@ -59,8 +59,11 @@ declare const recordSchema: z.ZodObject<{
59
59
  commit: z.ZodString;
60
60
  change: z.ZodOptional<z.ZodString>;
61
61
  direction: z.ZodOptional<z.ZodEnum<{
62
+ bold: "bold";
63
+ clear: "clear";
62
64
  neutral: "neutral";
63
65
  soft: "soft";
66
+ warm: "warm";
64
67
  }>>;
65
68
  version: z.ZodOptional<z.ZodNumber>;
66
69
  screen: z.ZodOptional<z.ZodString>;
@@ -0,0 +1,9 @@
1
+ import type { UiRoute } from '../routes.ts';
2
+ import type { ChatEngine } from './turn.ts';
3
+ /**
4
+ * A person's "Allow this folder": the folder is the one the chat's own permission notice names,
5
+ * never one the request sends. Only the studio page reaches it (its token or the host's sign-in,
6
+ * Origin, the settings right); no MCP tool or agent command calls it. The chat records who allowed
7
+ * what, the studio's audit line for a settings change outside git.
8
+ */
9
+ export declare function allowFolderRoute(engine: ChatEngine): UiRoute;
@@ -0,0 +1,56 @@
1
+ import { allowFolderAnswer, allowFolderBody, chatIdSchema } from '@buffcore/contracts/workbench';
2
+ import { AllowRefusal, addAdditionalDirectory, allowableFolder } from './allow-folder.js';
3
+ import { t } from './prompt.js';
4
+ import { message } from './store.js';
5
+ import { lineText } from './stream-text.js';
6
+ const refused = (status, text) => ({ status, body: { error: text } });
7
+ /**
8
+ * A person's "Allow this folder": the folder is the one the chat's own permission notice names,
9
+ * never one the request sends. Only the studio page reaches it (its token or the host's sign-in,
10
+ * Origin, the settings right); no MCP tool or agent command calls it. The chat records who allowed
11
+ * what, the studio's audit line for a settings change outside git.
12
+ */
13
+ export function allowFolderRoute(engine) {
14
+ return {
15
+ method: 'POST',
16
+ path: '/api/chats/:id/allow-folder',
17
+ right: 'settings',
18
+ origin: true,
19
+ handle: async (request) => {
20
+ const id = request.params.id;
21
+ if (!chatIdSchema.safeParse(id).success)
22
+ return refused(400, t('chat.invalid'));
23
+ const body = allowFolderBody.safeParse(await request.body().catch(() => undefined));
24
+ if (!body.success)
25
+ return refused(400, t('chat.invalid'));
26
+ const chat = engine.get(id);
27
+ if (!chat)
28
+ return refused(404, t('chat.missing'));
29
+ const notice = chat.messages[body.data.at];
30
+ const permission = notice?.from === 'system' ? notice.permission : undefined;
31
+ if (permission?.setting !== 'permissions.additionalDirectories')
32
+ return refused(409, lineText('chat.allow.none'));
33
+ try {
34
+ const folder = await allowableFolder(engine.root, permission.path);
35
+ const added = await addAdditionalDirectory(engine.root, folder);
36
+ if (!permission.allowed) {
37
+ permission.allowed = true;
38
+ const by = request.identity?.viewer.name;
39
+ const line = message(chat, 'system', lineText('chat.lines.allowed', { by: by ?? '', path: folder }));
40
+ if (by)
41
+ line.by = by;
42
+ engine.store.saveRetry(chat);
43
+ }
44
+ return {
45
+ status: added ? 201 : 200,
46
+ body: allowFolderAnswer.parse({ ok: true, path: folder }),
47
+ };
48
+ }
49
+ catch (error) {
50
+ if (error instanceof AllowRefusal)
51
+ return refused(409, lineText(`chat.allow.${error.why}`));
52
+ return refused(500, t('chat.server'));
53
+ }
54
+ },
55
+ };
56
+ }
@@ -0,0 +1,18 @@
1
+ /** Why a folder may not be added; each has a sentence in stream.en.ts as `chat.allow.<why>`. */
2
+ export type FolderRefusal = 'notAbsolute' | 'missing' | 'notFolder' | 'root' | 'home' | 'inside' | 'linked' | 'secrets' | 'settings';
3
+ export declare class AllowRefusal extends Error {
4
+ readonly why: FolderRefusal;
5
+ constructor(why: FolderRefusal);
6
+ }
7
+ /**
8
+ * The folder the person may allow: absolute, there, a folder, itself (no link), not a whole disk,
9
+ * not the home folder or one that holds it, outside the product, and not a folder of sign-ins or
10
+ * keys (`.ssh`, `.aws`, `secrets` and the like). Returns its real path.
11
+ */
12
+ export declare function allowableFolder(product: string, path: string): Promise<string>;
13
+ /**
14
+ * Adds `folder` to `permissions.additionalDirectories` in `<product>/.claude/settings.local.json`:
15
+ * made when missing, every other setting kept, never twice, written whole or not at all.
16
+ * Returns false when the folder was there already.
17
+ */
18
+ export declare function addAdditionalDirectory(product: string, folder: string): Promise<boolean>;
@@ -0,0 +1,76 @@
1
+ import { promises as fs } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { isAbsolute, parse, relative, resolve, sep } from 'node:path';
4
+ import { isObject, SettingsRefusal, updateLocalSettings } from './local-settings.js';
5
+ import { holdsSecrets } from './secret-folders.js';
6
+ export class AllowRefusal extends Error {
7
+ why;
8
+ constructor(why) {
9
+ super(why);
10
+ this.why = why;
11
+ }
12
+ }
13
+ const windows = process.platform === 'win32';
14
+ const same = (a, b) => (windows ? a.toLowerCase() === b.toLowerCase() : a === b);
15
+ /** `child` is `parent` or inside it. */
16
+ function within(parent, child) {
17
+ const path = relative(parent, child);
18
+ return path === '' || (path !== '..' && !path.startsWith(`..${sep}`) && !isAbsolute(path));
19
+ }
20
+ /**
21
+ * The folder the person may allow: absolute, there, a folder, itself (no link), not a whole disk,
22
+ * not the home folder or one that holds it, outside the product, and not a folder of sign-ins or
23
+ * keys (`.ssh`, `.aws`, `secrets` and the like). Returns its real path.
24
+ */
25
+ export async function allowableFolder(product, path) {
26
+ // On Windows `\notes` counts as absolute yet means the current drive: a drive or share is required.
27
+ if (!isAbsolute(path) || (windows && !/^(?:[a-z]:[\\/]|[\\/]{2})/i.test(path)))
28
+ throw new AllowRefusal('notAbsolute');
29
+ const entry = await fs.stat(path).catch(() => undefined);
30
+ if (!entry)
31
+ throw new AllowRefusal('missing');
32
+ if (!entry.isDirectory())
33
+ throw new AllowRefusal('notFolder');
34
+ const [real, home, root] = await Promise.all([
35
+ fs.realpath(path),
36
+ fs.realpath(homedir()),
37
+ fs.realpath(product),
38
+ ]);
39
+ if (parse(real).root === real)
40
+ throw new AllowRefusal('root');
41
+ if (within(real, home))
42
+ throw new AllowRefusal('home');
43
+ if (within(root, real))
44
+ throw new AllowRefusal('inside');
45
+ if (holdsSecrets(real) || holdsSecrets(resolve(path)))
46
+ throw new AllowRefusal('secrets');
47
+ if (!same(real, resolve(path)))
48
+ throw new AllowRefusal('linked');
49
+ return real;
50
+ }
51
+ /**
52
+ * Adds `folder` to `permissions.additionalDirectories` in `<product>/.claude/settings.local.json`:
53
+ * made when missing, every other setting kept, never twice, written whole or not at all.
54
+ * Returns false when the folder was there already.
55
+ */
56
+ export async function addAdditionalDirectory(product, folder) {
57
+ try {
58
+ return await updateLocalSettings(product, (settings) => {
59
+ const permissions = settings.permissions ?? {};
60
+ if (!isObject(permissions))
61
+ throw new AllowRefusal('settings');
62
+ const list = permissions.additionalDirectories ?? [];
63
+ if (!Array.isArray(list))
64
+ throw new AllowRefusal('settings');
65
+ if (list.some((entry) => typeof entry === 'string' && same(resolve(product, entry), folder)))
66
+ return undefined;
67
+ return {
68
+ ...settings,
69
+ permissions: { ...permissions, additionalDirectories: [...list, folder] },
70
+ };
71
+ });
72
+ }
73
+ catch (error) {
74
+ throw error instanceof SettingsRefusal ? new AllowRefusal('settings') : error;
75
+ }
76
+ }
@@ -0,0 +1,17 @@
1
+ import type { Chat } from '@buffcore/contracts/workbench';
2
+ export type Waiting = NonNullable<Chat['waiting']>;
3
+ export declare function askInstructions(launchId: string): string;
4
+ /** The last valid ask line of this launch in the text, or nothing. */
5
+ export declare function askedQuestion(text: string, launchId: string): string | undefined;
6
+ /** Records the turn's question on the launch; the chat shows it once the turn ends. */
7
+ export declare function askReporter(selection: {
8
+ launchId: string;
9
+ record: {
10
+ id?: string;
11
+ };
12
+ asked?: Waiting;
13
+ }): (text: string) => void;
14
+ /** The panel shows the agent's question as plain words, without the line's marker. */
15
+ export declare function plainAsk(text: string): string;
16
+ /** A turn's end: waiting only when it ended well and asked; anything else clears the question. */
17
+ export declare function endWaiting(chat: Chat, asked: Waiting | undefined, failed: boolean): void;
@@ -0,0 +1,4 @@
1
+ export declare const en: {
2
+ 'ask.instructions': string;
3
+ 'ask.launchId': string;
4
+ };
@@ -0,0 +1,4 @@
1
+ export const en = {
2
+ 'ask.instructions': 'When you need the person’s decision, ask them in one short question (at most 500 characters): write it as the last line of your reply, on its own line, exactly as {line}, then stop and wait for their answer. The studio shows that question to the person.',
3
+ 'ask.launchId': 'Your launch id for that line is {id}; write it in place of {placeholder}. Do not copy it anywhere else.',
4
+ };
@@ -0,0 +1,4 @@
1
+ export declare const es: {
2
+ 'ask.instructions': string;
3
+ 'ask.launchId': string;
4
+ };
@@ -0,0 +1,4 @@
1
+ export const es = {
2
+ 'ask.instructions': 'Cuando necesites que la persona decida, pregúntale en una sola pregunta corta (500 caracteres como máximo): escríbela como la última línea de tu respuesta, en su propia línea, exactamente como {line}, y luego detente y espera su respuesta. El estudio le muestra esa pregunta a la persona.',
3
+ 'ask.launchId': 'Tu identificador de lanzamiento para esa línea es {id}; escríbelo en lugar de {placeholder}. No lo copies en ningún otro sitio.',
4
+ };
@@ -0,0 +1,60 @@
1
+ /**
2
+ * The agent asks the person for a decision on the same private channel as an Auto choice: one line
3
+ * of its own top-level reply, carrying this launch's id. Only the turn the studio started for this
4
+ * chat knows the id, so no request from outside the turn can make the page wait.
5
+ */
6
+ import { randomUUID, timingSafeEqual } from 'node:crypto';
7
+ import { createI18n, matchLocale } from '@buffcore/i18n';
8
+ import { en } from './ask-person.en.js';
9
+ import { es } from './ask-person.es.js';
10
+ const words = createI18n({ catalogs: [{ en, es }] });
11
+ const askText = (key, values) => words.t(matchLocale((process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || 'en')
12
+ .replace('_', '-')
13
+ .split('.')[0], words.locales), key, values);
14
+ const PLACEHOLDER = '<launch-id>';
15
+ const LINE = /^[ \t]*(?:>[ \t]*)*ape-ask: turn=(ape-[a-f0-9]{32}) (.+)$/;
16
+ // After launch ids are scrubbed from stored text, the line reads as the question alone.
17
+ const SCRUBBED = /^([ \t]*(?:>[ \t]*)*)ape-ask: (?:launchid|turn=\S+) (.+)$/gm;
18
+ export function askInstructions(launchId) {
19
+ return `${askText('ask.instructions', { line: `ape-ask: turn=${PLACEHOLDER} <question>` })}\n${askText('ask.launchId', { id: launchId, placeholder: PLACEHOLDER })}\n`;
20
+ }
21
+ /** The last valid ask line of this launch in the text, or nothing. */
22
+ export function askedQuestion(text, launchId) {
23
+ if (!/^ape-[a-f0-9]{32}$/.test(launchId))
24
+ return;
25
+ let asked;
26
+ for (const line of text.split(/\r?\n/)) {
27
+ if (line.length > 600)
28
+ continue;
29
+ const match = LINE.exec(line);
30
+ if (!match || !timingSafeEqual(Buffer.from(match[1]), Buffer.from(launchId)))
31
+ continue;
32
+ const question = match[2].replace(/[\p{Cc}\p{Cf}]/gu, '').trim();
33
+ if (question && question.length <= 500 && !question.includes(PLACEHOLDER))
34
+ asked = question;
35
+ }
36
+ return asked;
37
+ }
38
+ /** Records the turn's question on the launch; the chat shows it once the turn ends. */
39
+ export function askReporter(selection) {
40
+ return (text) => {
41
+ const question = askedQuestion(text, selection.launchId);
42
+ if (question)
43
+ selection.asked = {
44
+ question,
45
+ at: new Date().toISOString(),
46
+ turn: selection.record.id ?? randomUUID(),
47
+ };
48
+ };
49
+ }
50
+ /** The panel shows the agent's question as plain words, without the line's marker. */
51
+ export function plainAsk(text) {
52
+ return text.includes('ape-ask: ') ? text.replace(SCRUBBED, '$1$2') : text;
53
+ }
54
+ /** A turn's end: waiting only when it ended well and asked; anything else clears the question. */
55
+ export function endWaiting(chat, asked, failed) {
56
+ if (asked && !failed)
57
+ chat.waiting = asked;
58
+ else
59
+ delete chat.waiting;
60
+ }
@@ -0,0 +1,21 @@
1
+ import type { Chat } from '@buffcore/contracts/workbench';
2
+ import type { TurnGuard } from './turn-guard.ts';
3
+ /** The permission prompt tool's name: the studio's MCP server `ape_permission`, tool `ask`. */
4
+ export declare const PROMPT_TOOL = "mcp__ape_permission__ask";
5
+ /** Deny rules hold in every mode, bypass included: the file tools never read these folders. */
6
+ export declare const SECRET_READS: string[];
7
+ /**
8
+ * The turn's secret-folder denies. A folder name the turn's own folder lies in (a product kept
9
+ * under `secrets/`) is denied inside the product and in the person's home only, as the limits
10
+ * hook counts it; every other name is denied anywhere.
11
+ */
12
+ export declare function secretReads(folder: string): string[];
13
+ /**
14
+ * The level's permission mode. Autopilot runs Claude's `auto` (its classifier decides), or
15
+ * `bypassPermissions` with "Never ask", planning included. Below Autopilot, and in a launch
16
+ * without a guard, planning runs `dontAsk` (it writes plan/ only, with two commands) and every
17
+ * other work accepts edits and asks.
18
+ */
19
+ export declare function permissionMode(work: Chat['work'], guard?: Pick<TurnGuard, 'level' | 'neverAsk'>): "acceptEdits" | "auto" | "bypassPermissions" | "dontAsk";
20
+ /** Claude's permission flags for one turn, spliced in after the fixed start arguments. */
21
+ export declare function claudePermissions(args: string[], work: Chat['work'], product: string, folder: string, verification: readonly string[], guard?: TurnGuard): void;
@@ -0,0 +1,69 @@
1
+ import { claudeDenied, claudeLinked, claudeRules, isPlanning, PLANNING_SETTINGS, } from './permissions.js';
2
+ import { PLANNING_LIMITS } from './planning-limits.js';
3
+ import { enclosingSecrets, homeSecret, SECRET_FOLDERS } from './secret-folders.js';
4
+ import { stepRules } from './step-rules.js';
5
+ import { verificationRules } from './verification.js';
6
+ /** The permission prompt tool's name: the studio's MCP server `ape_permission`, tool `ask`. */
7
+ export const PROMPT_TOOL = 'mcp__ape_permission__ask';
8
+ /** Deny rules hold in every mode, bypass included: the file tools never read these folders. */
9
+ export const SECRET_READS = [...SECRET_FOLDERS].map((folder) => `Read(//**/${folder}/**)`);
10
+ /**
11
+ * The turn's secret-folder denies. A folder name the turn's own folder lies in (a product kept
12
+ * under `secrets/`) is denied inside the product and in the person's home only, as the limits
13
+ * hook counts it; every other name is denied anywhere.
14
+ */
15
+ export function secretReads(folder) {
16
+ const enclosing = enclosingSecrets(folder);
17
+ if (!enclosing.length)
18
+ return SECRET_READS;
19
+ return [...SECRET_FOLDERS].flatMap((name) => enclosing.includes(name)
20
+ ? [`Read(./**/${name}/**)`, ...(homeSecret(name, folder) ? [`Read(~/${name}/**)`] : [])]
21
+ : [`Read(//**/${name}/**)`]);
22
+ }
23
+ /**
24
+ * The level's permission mode. Autopilot runs Claude's `auto` (its classifier decides), or
25
+ * `bypassPermissions` with "Never ask", planning included. Below Autopilot, and in a launch
26
+ * without a guard, planning runs `dontAsk` (it writes plan/ only, with two commands) and every
27
+ * other work accepts edits and asks.
28
+ */
29
+ export function permissionMode(work, guard) {
30
+ if (guard?.level === 'auto')
31
+ return guard.neverAsk ? 'bypassPermissions' : 'auto';
32
+ return isPlanning(work) ? 'dontAsk' : 'acceptEdits';
33
+ }
34
+ /** Claude's permission flags for one turn, spliced in after the fixed start arguments. */
35
+ export function claudePermissions(args, work, product, folder, verification, guard) {
36
+ const linked = claudeLinked(product);
37
+ const mode = permissionMode(work, guard);
38
+ // dontAsk turns disable every hook, the limits hook included: deny rules hold their limits.
39
+ const unhooked = mode === 'dontAsk';
40
+ const asks = guard?.settings && guard.mcp
41
+ ? ['--settings', guard.settings, '--mcp-config', guard.mcp, '--permission-prompt-tool']
42
+ : [];
43
+ args.splice(5, 0, '--permission-mode', mode, ...(unhooked ? ['--settings', PLANNING_SETTINGS] : []), ...(asks.length ? [...asks, PROMPT_TOOL] : []));
44
+ // Autopilot has no step list, planning included: the classifier decides what it would allow.
45
+ // Planning's edits outside plan/ are still held by the studio's save.
46
+ const allowed = [
47
+ ...(guard?.level === 'auto' ? [] : claudeRules(work, folder)),
48
+ ...verificationRules(verification),
49
+ ...(asks.length ? stepRules(product, work) : []),
50
+ ...linked.allowed,
51
+ ];
52
+ if (allowed.length)
53
+ args.push('--allowedTools', ...allowed);
54
+ // The tool answers permission requests only: the model never sees it as a tool of its own.
55
+ const denied = [
56
+ ...claudeDenied(work, guard?.level === 'auto'),
57
+ ...linked.denied,
58
+ ...(guard ? secretReads(folder) : []),
59
+ ...(guard && unhooked ? PLANNING_LIMITS : []),
60
+ ...(asks.length ? [PROMPT_TOOL] : []),
61
+ ];
62
+ if (denied.length)
63
+ args.push('--disallowedTools', ...denied);
64
+ if (!guard)
65
+ return;
66
+ guard.allowed.splice(0, guard.allowed.length, ...allowed);
67
+ for (const arg of [...asks, PROMPT_TOOL, ...allowed, ...denied])
68
+ guard.args.add(arg);
69
+ }
@@ -9,6 +9,7 @@ export declare function watchCodexIdle(child: ChildProcess, adapter: ChatAdapter
9
9
  id: import("@buffcore/contracts/workbench").AgentId;
10
10
  buildArgs: (options: import("./prompt.ts").TurnOptions) => string[];
11
11
  reply?: (line: string) => string | undefined;
12
+ notice?: (line: string) => string | undefined;
12
13
  parse(line: string): ({
13
14
  kind: "text";
14
15
  text: string;
@@ -1,6 +1,7 @@
1
1
  import { changeWorktreeGit } from '../../worktree-git-trust.js';
2
2
  import { codexExampleEnv } from './codex-examples.js';
3
- import { codexFilesystem, codexTrust, inTree } from './permissions.js';
3
+ import { codexFilesystem, codexTrust } from './codex-permissions.js';
4
+ import { inTree } from './permissions.js';
4
5
  // An extended Windows path can use 32,767 UTF-16 code units. Every directory and its separator
5
6
  // consume at least two; a lower, arbitrary scan limit could miss a path the existing globs deny.
6
7
  export const CODEX_WINDOWS_OVERRIDES = [
@@ -0,0 +1,12 @@
1
+ import type { Chat } from '@buffcore/contracts/workbench';
2
+ /** JSON's string escaping is also valid for TOML basic keys, including quotes and backslashes. */
3
+ export declare function codexTrust(folder: string): string;
4
+ /** Share a scan between argument construction and shim validation, only for this launch. */
5
+ export declare function withLinkedPermissions<T>(launch: () => T): T;
6
+ /**
7
+ * Every turn denies comments and the approval record; design and validation, which write the
8
+ * product folder, also the change trees (planning writes plan/ only). Codex takes absolute
9
+ * paths only (0.166 rejects read globs), so a nested product's prototype/versions is not
10
+ * named here; Claude's rule covers it. Design/validation expand read paths.
11
+ */
12
+ export declare function codexFilesystem(work: Chat['work'], folder: string, product?: string, examples?: string): string[];