@buffcore/cli 0.8.41 → 0.8.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/commands/agents-file.d.ts +5 -0
- package/dist/commands/agents-file.js +30 -7
- package/dist/commands/change.d.ts +4 -0
- package/dist/commands/change.js +12 -5
- package/dist/commands/create-block.d.ts +2 -1
- package/dist/commands/create-block.js +7 -5
- package/dist/commands/create.d.ts +3 -2
- package/dist/commands/create.en.js +1 -1
- package/dist/commands/create.es.js +1 -1
- package/dist/commands/create.js +8 -6
- package/dist/commands/design/check.d.ts +2 -0
- package/dist/commands/design/check.js +6 -0
- package/dist/commands/design/journey-roles.d.ts +6 -0
- package/dist/commands/design/journey-roles.js +60 -0
- package/dist/commands/design/references.d.ts +3 -0
- package/dist/commands/design/references.js +25 -0
- package/dist/commands/design/tells-text.js +2 -2
- package/dist/commands/design/tells.d.ts +3 -1
- package/dist/commands/design/tells.en.d.ts +2 -0
- package/dist/commands/design/tells.en.js +2 -0
- package/dist/commands/design/tells.es.js +2 -0
- package/dist/commands/design/tells.js +10 -7
- package/dist/commands/dev.js +3 -0
- package/dist/commands/port-claims.d.ts +23 -0
- package/dist/commands/port-claims.js +95 -0
- package/dist/commands/prototype/browser.d.ts +9 -4
- package/dist/commands/prototype/browser.js +26 -18
- package/dist/commands/prototype/export-base.d.ts +27 -0
- package/dist/commands/prototype/export-base.js +80 -0
- package/dist/commands/prototype/export.d.ts +3 -2
- package/dist/commands/prototype/export.js +13 -6
- package/dist/commands/prototype/index.js +1 -0
- package/dist/commands/prototype/media-ready.d.ts +8 -0
- package/dist/commands/prototype/media-ready.js +36 -0
- package/dist/commands/prototype/messages.en.d.ts +6 -0
- package/dist/commands/prototype/messages.en.js +6 -0
- package/dist/commands/prototype/messages.js +6 -0
- package/dist/commands/prototype/scene.d.ts +3 -1
- package/dist/commands/prototype/scene.js +22 -6
- package/dist/commands/prototype/snapshot-inputs.js +35 -7
- package/dist/commands/prototype/snapshot-setup.d.ts +1 -1
- package/dist/commands/prototype/snapshot-setup.js +2 -1
- package/dist/commands/prototype/snapshot.d.ts +2 -0
- package/dist/commands/prototype/snapshot.js +2 -1
- package/dist/commands/ui/chat/allow-folder.js +23 -77
- package/dist/commands/ui/chat/claude-permissions.d.ts +21 -0
- package/dist/commands/ui/chat/claude-permissions.js +69 -0
- package/dist/commands/ui/chat/codex-idle.d.ts +1 -0
- package/dist/commands/ui/chat/codex-overrides.js +2 -1
- package/dist/commands/ui/chat/codex-permissions.d.ts +12 -0
- package/dist/commands/ui/chat/codex-permissions.js +97 -0
- package/dist/commands/ui/chat/command-parts.d.ts +33 -0
- package/dist/commands/ui/chat/command-parts.js +219 -0
- package/dist/commands/ui/chat/command-wrappers.d.ts +21 -0
- package/dist/commands/ui/chat/command-wrappers.js +100 -0
- package/dist/commands/ui/chat/design-deletes.d.ts +1 -0
- package/dist/commands/ui/chat/design-deletes.js +39 -0
- package/dist/commands/ui/chat/launch-input.d.ts +4 -2
- package/dist/commands/ui/chat/launch-input.js +16 -3
- package/dist/commands/ui/chat/limit-mentions.d.ts +5 -0
- package/dist/commands/ui/chat/limit-mentions.js +74 -0
- package/dist/commands/ui/chat/limit-patterns.d.ts +15 -0
- package/dist/commands/ui/chat/limit-patterns.js +182 -0
- package/dist/commands/ui/chat/limits-hook.d.ts +1 -0
- package/dist/commands/ui/chat/limits-hook.js +30 -0
- package/dist/commands/ui/chat/limits.d.ts +37 -0
- package/dist/commands/ui/chat/limits.en.d.ts +18 -0
- package/dist/commands/ui/chat/limits.en.js +18 -0
- package/dist/commands/ui/chat/limits.es.d.ts +2 -0
- package/dist/commands/ui/chat/limits.es.js +17 -0
- package/dist/commands/ui/chat/limits.js +224 -0
- package/dist/commands/ui/chat/local-settings.d.ts +17 -0
- package/dist/commands/ui/chat/local-settings.js +73 -0
- package/dist/commands/ui/chat/opencode-config.d.ts +22 -0
- package/dist/commands/ui/chat/opencode-config.js +83 -0
- package/dist/commands/ui/chat/parse-claude.js +18 -2
- package/dist/commands/ui/chat/permission-ask.d.ts +44 -0
- package/dist/commands/ui/chat/permission-ask.js +142 -0
- package/dist/commands/ui/chat/permission-channel.d.ts +18 -0
- package/dist/commands/ui/chat/permission-channel.js +67 -0
- package/dist/commands/ui/chat/permission-route.d.ts +10 -0
- package/dist/commands/ui/chat/permission-route.js +47 -0
- package/dist/commands/ui/chat/permission-tool.d.ts +1 -0
- package/dist/commands/ui/chat/permission-tool.js +86 -0
- package/dist/commands/ui/chat/permissions.d.ts +11 -12
- package/dist/commands/ui/chat/permissions.js +20 -102
- package/dist/commands/ui/chat/planning-limits.d.ts +12 -0
- package/dist/commands/ui/chat/planning-limits.js +31 -0
- package/dist/commands/ui/chat/process.js +4 -1
- package/dist/commands/ui/chat/prompt.d.ts +8 -1
- package/dist/commands/ui/chat/prompt.en.d.ts +4 -0
- package/dist/commands/ui/chat/prompt.en.js +4 -0
- package/dist/commands/ui/chat/prompt.es.d.ts +4 -0
- package/dist/commands/ui/chat/prompt.es.js +4 -0
- package/dist/commands/ui/chat/prompt.js +18 -50
- package/dist/commands/ui/chat/recorded-turn.js +3 -0
- package/dist/commands/ui/chat/routes.js +2 -0
- package/dist/commands/ui/chat/secret-folders.d.ts +16 -0
- package/dist/commands/ui/chat/secret-folders.js +35 -0
- package/dist/commands/ui/chat/stdin-shells.d.ts +8 -0
- package/dist/commands/ui/chat/stdin-shells.js +102 -0
- package/dist/commands/ui/chat/step-rules.d.ts +13 -0
- package/dist/commands/ui/chat/step-rules.js +47 -0
- package/dist/commands/ui/chat/store.js +11 -2
- package/dist/commands/ui/chat/stream.en.d.ts +6 -0
- package/dist/commands/ui/chat/stream.en.js +6 -0
- package/dist/commands/ui/chat/stream.es.d.ts +6 -0
- package/dist/commands/ui/chat/stream.es.js +6 -0
- package/dist/commands/ui/chat/stream.js +4 -1
- package/dist/commands/ui/chat/turn-guard.d.ts +25 -0
- package/dist/commands/ui/chat/turn-guard.js +74 -0
- package/dist/commands/ui/chat/turn-input.d.ts +3 -2
- package/dist/commands/ui/chat/turn-input.js +3 -1
- package/dist/commands/ui/chat/turn-scenes.d.ts +19 -0
- package/dist/commands/ui/chat/turn-scenes.js +44 -0
- package/dist/commands/ui/chat/turn-state.d.ts +6 -0
- package/dist/commands/ui/chat/turn.js +8 -3
- package/dist/commands/ui/level-route.js +8 -3
- package/dist/commands/ui/page.d.ts +19 -1
- package/dist/commands/ui/page.js +9 -6
- package/dist/commands/ui/plan-structure.d.ts +9 -2
- package/dist/commands/ui/plan-structure.en.d.ts +1 -0
- package/dist/commands/ui/plan-structure.en.js +1 -0
- package/dist/commands/ui/plan-structure.es.d.ts +1 -0
- package/dist/commands/ui/plan-structure.es.js +1 -0
- package/dist/commands/ui/plan-structure.js +36 -10
- package/dist/commands/ui/prototype-main.d.ts +1 -0
- package/dist/commands/ui/prototype-scenes-child.js +3 -1
- package/dist/commands/ui/prototype-scenes-read.d.ts +1 -0
- package/dist/commands/ui/prototype-scenes-route.js +7 -1
- package/dist/commands/ui/save-commit.js +6 -2
- package/dist/commands/ui/server-options.js +2 -0
- package/dist/commands/ui/server.d.ts +5 -22
- package/dist/commands/ui/server.js +3 -45
- package/dist/commands/ui/snapshot-runners.d.ts +22 -0
- package/dist/commands/ui/snapshot-runners.js +45 -0
- package/dist/commands/ui/studio-routes.d.ts +1 -0
- package/dist/commands/ui/studio-routes.js +1 -0
- package/dist/commands/ui/studio-state.d.ts +3 -0
- package/dist/commands/ui/studio-state.js +1 -0
- package/dist/commands/ui/studio.en.d.ts +13 -0
- package/dist/commands/ui/studio.en.js +13 -0
- package/dist/commands/ui/studio.es.d.ts +13 -0
- package/dist/commands/ui/studio.es.js +13 -0
- package/dist/commands/ui/theme-option.d.ts +8 -0
- package/dist/commands/ui/theme-option.js +40 -0
- package/dist/commands/ui/theme-values.d.ts +5 -0
- package/dist/commands/ui/theme-values.js +113 -0
- package/dist/ui/page.js +93 -93
- package/docs/PROTOTYPE.md +4 -1
- package/docs/WORKBENCH.md +76 -22
- package/package.json +11 -11
- package/skills/ape-critique/SKILL.md +8 -4
- package/skills/ape-design-system/SKILL.md +3 -3
- package/skills/ape-plan-change/SKILL.md +7 -3
- package/skills/ape-prototype/SKILL.md +8 -1
- package/templates/example/apps/app/src/i18n/en.ts +2 -0
- package/templates/example/apps/app/src/i18n/es.json +2 -0
- package/templates/product/apps/admin/src/fonts.ts +2 -1
- package/templates/product/apps/app/src/fonts.ts +5 -1
- package/templates/product/apps/app/src/i18n/en.ts +2 -0
- package/templates/product/apps/app/src/i18n/es.json +2 -0
- package/templates/product/prototype/journeys.ts +3 -0
|
@@ -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 {
|
|
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
|
|
119
|
-
if (!
|
|
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
|
-
|
|
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-
|
|
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,
|
|
@@ -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,
|
|
82
|
+
picked.map(({ surface, frame }) => [surface, run.frames[frame]]),
|
|
82
83
|
picked.length ? await browserVersion() : null,
|
|
83
84
|
run.looks,
|
|
84
85
|
run.fontTheme,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
1
|
import { promises as fs } from 'node:fs';
|
|
3
2
|
import { homedir } from 'node:os';
|
|
4
|
-
import { isAbsolute,
|
|
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';
|
|
5
6
|
export class AllowRefusal extends Error {
|
|
6
7
|
why;
|
|
7
8
|
constructor(why) {
|
|
@@ -10,22 +11,6 @@ export class AllowRefusal extends Error {
|
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
const windows = process.platform === 'win32';
|
|
13
|
-
/**
|
|
14
|
-
* Folders that hold sign-ins and keys. The folder an agent was refused comes from what the agent
|
|
15
|
-
* tried to read, so one click must never hand it these, at any depth.
|
|
16
|
-
*/
|
|
17
|
-
const SECRET_FOLDERS = new Set([
|
|
18
|
-
'.ssh',
|
|
19
|
-
'.gnupg',
|
|
20
|
-
'.aws',
|
|
21
|
-
'.azure',
|
|
22
|
-
'.kube',
|
|
23
|
-
'.docker',
|
|
24
|
-
'.gcloud',
|
|
25
|
-
'.password-store',
|
|
26
|
-
'secrets',
|
|
27
|
-
]);
|
|
28
|
-
const holdsSecrets = (path) => path.split(/[\\/]+/).some((part) => SECRET_FOLDERS.has(part.toLowerCase()));
|
|
29
14
|
const same = (a, b) => (windows ? a.toLowerCase() === b.toLowerCase() : a === b);
|
|
30
15
|
/** `child` is `parent` or inside it. */
|
|
31
16
|
function within(parent, child) {
|
|
@@ -63,68 +48,29 @@ export async function allowableFolder(product, path) {
|
|
|
63
48
|
throw new AllowRefusal('linked');
|
|
64
49
|
return real;
|
|
65
50
|
}
|
|
66
|
-
const object = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
67
|
-
async function readSettings(file) {
|
|
68
|
-
let text;
|
|
69
|
-
try {
|
|
70
|
-
text = await fs.readFile(file, 'utf8');
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
if (error.code === 'ENOENT')
|
|
74
|
-
return {};
|
|
75
|
-
throw new AllowRefusal('settings');
|
|
76
|
-
}
|
|
77
|
-
try {
|
|
78
|
-
const value = JSON.parse(text);
|
|
79
|
-
if (object(value))
|
|
80
|
-
return value;
|
|
81
|
-
}
|
|
82
|
-
catch {
|
|
83
|
-
// Not JSON: never overwritten.
|
|
84
|
-
}
|
|
85
|
-
throw new AllowRefusal('settings');
|
|
86
|
-
}
|
|
87
|
-
/** A scanner or an editor can hold the file for a moment on Windows: a few short tries. */
|
|
88
|
-
async function replace(temporary, file) {
|
|
89
|
-
for (let n = 1;; n++) {
|
|
90
|
-
try {
|
|
91
|
-
return await fs.rename(temporary, file);
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
const code = error.code;
|
|
95
|
-
if (n >= 5 || !['EPERM', 'EBUSY', 'EACCES'].includes(code ?? '')) {
|
|
96
|
-
await fs.rm(temporary, { force: true });
|
|
97
|
-
throw error;
|
|
98
|
-
}
|
|
99
|
-
await new Promise((done) => setTimeout(done, 20 * n));
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
let queue = Promise.resolve();
|
|
104
51
|
/**
|
|
105
52
|
* Adds `folder` to `permissions.additionalDirectories` in `<product>/.claude/settings.local.json`:
|
|
106
53
|
* made when missing, every other setting kept, never twice, written whole or not at all.
|
|
107
54
|
* Returns false when the folder was there already.
|
|
108
55
|
*/
|
|
109
|
-
export function addAdditionalDirectory(product, folder) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return next;
|
|
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
|
+
}
|
|
130
76
|
}
|
|
@@ -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
|
|
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[];
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { globSync, readdirSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { join, matchesGlob, resolve } from 'node:path';
|
|
4
|
+
import { mergeHoldPath } from '../merge-hold.js';
|
|
5
|
+
import { windowsExampleDenials } from './codex-examples.js';
|
|
6
|
+
import { LINKED_SECRETS, linkedPackages } from './linked.js';
|
|
7
|
+
import { APPROVAL_PATH, CHAT_PATH, COMMAND_PATHS, COMMENT_PATH, LEVEL_PATHS, turnWriteDenials, } from './permissions.js';
|
|
8
|
+
/** JSON's string escaping is also valid for TOML basic keys, including quotes and backslashes. */
|
|
9
|
+
export function codexTrust(folder) {
|
|
10
|
+
return `projects={${JSON.stringify(realpathSync.native(folder))}={trust_level="trusted"}}`;
|
|
11
|
+
}
|
|
12
|
+
const linkedScans = new AsyncLocalStorage();
|
|
13
|
+
/** Share a scan between argument construction and shim validation, only for this launch. */
|
|
14
|
+
export function withLinkedPermissions(launch) {
|
|
15
|
+
return linkedScans.run(new Map(), launch);
|
|
16
|
+
}
|
|
17
|
+
function linkedSecrets(packages) {
|
|
18
|
+
const denied = new Set([join(packages, '.ape/comments')]);
|
|
19
|
+
const pending = [packages];
|
|
20
|
+
while (pending.length) {
|
|
21
|
+
const folder = pending.pop();
|
|
22
|
+
for (const entry of readdirSync(folder, { withFileTypes: true })) {
|
|
23
|
+
const path = join(folder, entry.name);
|
|
24
|
+
if (entry.name === 'node_modules')
|
|
25
|
+
continue;
|
|
26
|
+
if (entry.name === '.ape') {
|
|
27
|
+
denied.add(join(path, 'comments'));
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (entry.name === '.git' || entry.name === '.secrets') {
|
|
31
|
+
denied.add(path);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
// Dirent does not classify junctions/symlinks as directories; never follow one.
|
|
35
|
+
if (entry.isDirectory() && !entry.isSymbolicLink())
|
|
36
|
+
pending.push(path);
|
|
37
|
+
else if (LINKED_SECRETS.some((pattern) => matchesGlob(entry.name, pattern)))
|
|
38
|
+
denied.add(path);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return [...denied].sort();
|
|
42
|
+
}
|
|
43
|
+
function codexLinked(product) {
|
|
44
|
+
const cache = linkedScans.getStore();
|
|
45
|
+
const key = resolve(product);
|
|
46
|
+
const cached = cache?.get(key);
|
|
47
|
+
if (cached)
|
|
48
|
+
return cached;
|
|
49
|
+
const packages = linkedPackages(product);
|
|
50
|
+
const entries = packages
|
|
51
|
+
? [
|
|
52
|
+
`${JSON.stringify(packages)}="read"`,
|
|
53
|
+
...linkedSecrets(packages).map((secret) => `${JSON.stringify(secret)}="deny"`),
|
|
54
|
+
]
|
|
55
|
+
: [];
|
|
56
|
+
cache?.set(key, entries);
|
|
57
|
+
return entries;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Every turn denies comments and the approval record; design and validation, which write the
|
|
61
|
+
* product folder, also the change trees (planning writes plan/ only). Codex takes absolute
|
|
62
|
+
* paths only (0.166 rejects read globs), so a nested product's prototype/versions is not
|
|
63
|
+
* named here; Claude's rule covers it. Design/validation expand read paths.
|
|
64
|
+
*/
|
|
65
|
+
export function codexFilesystem(work, folder, product = folder, examples) {
|
|
66
|
+
const root = realpathSync.native(folder);
|
|
67
|
+
const bases = [...new Set([root, realpathSync.native(product)])];
|
|
68
|
+
const open = work === 'design' || work === 'validation';
|
|
69
|
+
// A change tree keeps its own copy of the record (git merge main writes it); the product's is guarded.
|
|
70
|
+
const guards = open
|
|
71
|
+
? bases.flatMap((base) => turnWriteDenials(work).map((path) => join(base, path)))
|
|
72
|
+
: [join(realpathSync.native(product), APPROVAL_PATH)];
|
|
73
|
+
const hold = mergeHoldPath(product);
|
|
74
|
+
const denied = [
|
|
75
|
+
...windowsExampleDenials,
|
|
76
|
+
...(examples ? [`${JSON.stringify(examples)}="read"`] : []),
|
|
77
|
+
...codexLinked(product),
|
|
78
|
+
...bases.map((base) => `${JSON.stringify(join(base, COMMENT_PATH))}="deny"`),
|
|
79
|
+
...bases.flatMap((base) => LEVEL_PATHS.map((path) => `${JSON.stringify(join(base, path))}="read"`)),
|
|
80
|
+
...guards.map((path) => `${JSON.stringify(path)}="read"`),
|
|
81
|
+
...(hold ? [hold, `${hold}.lock`].map((path) => `${JSON.stringify(path)}="deny"`) : []),
|
|
82
|
+
].join(',');
|
|
83
|
+
if (!open)
|
|
84
|
+
return [`permissions.ape.filesystem={${denied}}`];
|
|
85
|
+
const roots = [...COMMAND_PATHS.map((path) => path.replace(/\/\*\*$/, '')), CHAT_PATH];
|
|
86
|
+
const nested = globSync(roots.map((path) => `**/${path}`), {
|
|
87
|
+
cwd: root,
|
|
88
|
+
exclude: (path) => /(?:^|[/\\])(?:node_modules|\.git|\.ape)[/\\]/.test(path),
|
|
89
|
+
});
|
|
90
|
+
const paths = [...new Set([...roots, ...nested.map((path) => path.replaceAll('\\', '/'))])];
|
|
91
|
+
const entries = paths
|
|
92
|
+
.sort()
|
|
93
|
+
.map((path) => `${JSON.stringify(join(root, path))}="read"`)
|
|
94
|
+
.join(',');
|
|
95
|
+
// Absolute entries leave the product's :workspace_roots deny table untouched, including overlaps.
|
|
96
|
+
return [`permissions.ape.filesystem={${entries},${denied}}`];
|
|
97
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A shell command read the way the limits and the permission card need it: its parts (what runs
|
|
3
|
+
* between pipes, `;`, `&&`, `||`, `&`, new lines, subshells and command substitutions) and each
|
|
4
|
+
* part's words. Over-splitting is safe here: every part is checked, so a missed separator could
|
|
5
|
+
* only hide a part, never add one. A line continuation joins its lines first; a redirection
|
|
6
|
+
* (`2>&1`, `>&2`, `&>`) stays in its part; a here-document's body is data, not a command, unless
|
|
7
|
+
* it can run a substitution.
|
|
8
|
+
*/
|
|
9
|
+
export type Shell = 'bash' | 'powershell' | 'cmd';
|
|
10
|
+
/** Each shell's escape character: it also joins a line ending in it to the next. */
|
|
11
|
+
export declare const ESCAPE: Record<Shell, string>;
|
|
12
|
+
/**
|
|
13
|
+
* What reading a command could not follow, so the limits ask the person instead of trusting the
|
|
14
|
+
* parse: too much work (`budget`), a here-document whose end line never comes (`heredoc`), a shell
|
|
15
|
+
* or interpreter fed its script on standard input (`stdin`), or text run as a command (`expression`).
|
|
16
|
+
*/
|
|
17
|
+
export type Unsure = 'budget' | 'heredoc' | 'stdin' | 'expression';
|
|
18
|
+
/** A tally the limits share across one call's reading: characters parsed, and what was unsure. */
|
|
19
|
+
export interface Reading {
|
|
20
|
+
steps: number;
|
|
21
|
+
unsure?: Unsure;
|
|
22
|
+
}
|
|
23
|
+
export declare function commandParts(command: string, shell?: Shell, reading?: Reading): string[];
|
|
24
|
+
/**
|
|
25
|
+
* A part's words, quotes removed; a quoted word keeps its spaces. With the shell's escape
|
|
26
|
+
* character, an escaped character stands for itself (`p\ush` is `push`); without it, every
|
|
27
|
+
* character is kept as written, which keeps a Windows path's backslashes.
|
|
28
|
+
*/
|
|
29
|
+
export declare function partWords(part: string, escaper?: string): string[];
|
|
30
|
+
/** The program a word names, without its folder or a Windows extension, in lower case. */
|
|
31
|
+
export declare const programName: (word: string) => string;
|
|
32
|
+
/** The part's program: its first word after any `NAME=value` settings. */
|
|
33
|
+
export declare function partProgram(part: string): string;
|