@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.
Files changed (164) hide show
  1. package/CHANGELOG.md +25 -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.d.ts +3 -2
  9. package/dist/commands/create.en.js +1 -1
  10. package/dist/commands/create.es.js +1 -1
  11. package/dist/commands/create.js +8 -6
  12. package/dist/commands/design/check.d.ts +2 -0
  13. package/dist/commands/design/check.js +6 -0
  14. package/dist/commands/design/journey-roles.d.ts +6 -0
  15. package/dist/commands/design/journey-roles.js +60 -0
  16. package/dist/commands/design/references.d.ts +3 -0
  17. package/dist/commands/design/references.js +25 -0
  18. package/dist/commands/design/tells-text.js +2 -2
  19. package/dist/commands/design/tells.d.ts +3 -1
  20. package/dist/commands/design/tells.en.d.ts +2 -0
  21. package/dist/commands/design/tells.en.js +2 -0
  22. package/dist/commands/design/tells.es.js +2 -0
  23. package/dist/commands/design/tells.js +10 -7
  24. package/dist/commands/dev.js +3 -0
  25. package/dist/commands/port-claims.d.ts +23 -0
  26. package/dist/commands/port-claims.js +95 -0
  27. package/dist/commands/prototype/browser.d.ts +9 -4
  28. package/dist/commands/prototype/browser.js +26 -18
  29. package/dist/commands/prototype/export-base.d.ts +27 -0
  30. package/dist/commands/prototype/export-base.js +80 -0
  31. package/dist/commands/prototype/export.d.ts +3 -2
  32. package/dist/commands/prototype/export.js +13 -6
  33. package/dist/commands/prototype/index.js +1 -0
  34. package/dist/commands/prototype/media-ready.d.ts +8 -0
  35. package/dist/commands/prototype/media-ready.js +36 -0
  36. package/dist/commands/prototype/messages.en.d.ts +6 -0
  37. package/dist/commands/prototype/messages.en.js +6 -0
  38. package/dist/commands/prototype/messages.js +6 -0
  39. package/dist/commands/prototype/scene.d.ts +3 -1
  40. package/dist/commands/prototype/scene.js +22 -6
  41. package/dist/commands/prototype/snapshot-inputs.js +35 -7
  42. package/dist/commands/prototype/snapshot-setup.d.ts +1 -1
  43. package/dist/commands/prototype/snapshot-setup.js +2 -1
  44. package/dist/commands/prototype/snapshot.d.ts +2 -0
  45. package/dist/commands/prototype/snapshot.js +2 -1
  46. package/dist/commands/ui/chat/allow-folder.js +23 -77
  47. package/dist/commands/ui/chat/claude-permissions.d.ts +21 -0
  48. package/dist/commands/ui/chat/claude-permissions.js +69 -0
  49. package/dist/commands/ui/chat/codex-idle.d.ts +1 -0
  50. package/dist/commands/ui/chat/codex-overrides.js +2 -1
  51. package/dist/commands/ui/chat/codex-permissions.d.ts +12 -0
  52. package/dist/commands/ui/chat/codex-permissions.js +97 -0
  53. package/dist/commands/ui/chat/command-parts.d.ts +33 -0
  54. package/dist/commands/ui/chat/command-parts.js +219 -0
  55. package/dist/commands/ui/chat/command-wrappers.d.ts +21 -0
  56. package/dist/commands/ui/chat/command-wrappers.js +100 -0
  57. package/dist/commands/ui/chat/design-deletes.d.ts +1 -0
  58. package/dist/commands/ui/chat/design-deletes.js +39 -0
  59. package/dist/commands/ui/chat/launch-input.d.ts +4 -2
  60. package/dist/commands/ui/chat/launch-input.js +16 -3
  61. package/dist/commands/ui/chat/limit-mentions.d.ts +5 -0
  62. package/dist/commands/ui/chat/limit-mentions.js +74 -0
  63. package/dist/commands/ui/chat/limit-patterns.d.ts +15 -0
  64. package/dist/commands/ui/chat/limit-patterns.js +182 -0
  65. package/dist/commands/ui/chat/limits-hook.d.ts +1 -0
  66. package/dist/commands/ui/chat/limits-hook.js +30 -0
  67. package/dist/commands/ui/chat/limits.d.ts +37 -0
  68. package/dist/commands/ui/chat/limits.en.d.ts +18 -0
  69. package/dist/commands/ui/chat/limits.en.js +18 -0
  70. package/dist/commands/ui/chat/limits.es.d.ts +2 -0
  71. package/dist/commands/ui/chat/limits.es.js +17 -0
  72. package/dist/commands/ui/chat/limits.js +224 -0
  73. package/dist/commands/ui/chat/local-settings.d.ts +17 -0
  74. package/dist/commands/ui/chat/local-settings.js +73 -0
  75. package/dist/commands/ui/chat/opencode-config.d.ts +22 -0
  76. package/dist/commands/ui/chat/opencode-config.js +83 -0
  77. package/dist/commands/ui/chat/parse-claude.js +18 -2
  78. package/dist/commands/ui/chat/permission-ask.d.ts +44 -0
  79. package/dist/commands/ui/chat/permission-ask.js +142 -0
  80. package/dist/commands/ui/chat/permission-channel.d.ts +18 -0
  81. package/dist/commands/ui/chat/permission-channel.js +67 -0
  82. package/dist/commands/ui/chat/permission-route.d.ts +10 -0
  83. package/dist/commands/ui/chat/permission-route.js +47 -0
  84. package/dist/commands/ui/chat/permission-tool.d.ts +1 -0
  85. package/dist/commands/ui/chat/permission-tool.js +86 -0
  86. package/dist/commands/ui/chat/permissions.d.ts +11 -12
  87. package/dist/commands/ui/chat/permissions.js +20 -102
  88. package/dist/commands/ui/chat/planning-limits.d.ts +12 -0
  89. package/dist/commands/ui/chat/planning-limits.js +31 -0
  90. package/dist/commands/ui/chat/process.js +4 -1
  91. package/dist/commands/ui/chat/prompt.d.ts +8 -1
  92. package/dist/commands/ui/chat/prompt.en.d.ts +4 -0
  93. package/dist/commands/ui/chat/prompt.en.js +4 -0
  94. package/dist/commands/ui/chat/prompt.es.d.ts +4 -0
  95. package/dist/commands/ui/chat/prompt.es.js +4 -0
  96. package/dist/commands/ui/chat/prompt.js +18 -50
  97. package/dist/commands/ui/chat/recorded-turn.js +3 -0
  98. package/dist/commands/ui/chat/routes.js +2 -0
  99. package/dist/commands/ui/chat/secret-folders.d.ts +16 -0
  100. package/dist/commands/ui/chat/secret-folders.js +35 -0
  101. package/dist/commands/ui/chat/stdin-shells.d.ts +8 -0
  102. package/dist/commands/ui/chat/stdin-shells.js +102 -0
  103. package/dist/commands/ui/chat/step-rules.d.ts +13 -0
  104. package/dist/commands/ui/chat/step-rules.js +47 -0
  105. package/dist/commands/ui/chat/store.js +11 -2
  106. package/dist/commands/ui/chat/stream.en.d.ts +6 -0
  107. package/dist/commands/ui/chat/stream.en.js +6 -0
  108. package/dist/commands/ui/chat/stream.es.d.ts +6 -0
  109. package/dist/commands/ui/chat/stream.es.js +6 -0
  110. package/dist/commands/ui/chat/stream.js +4 -1
  111. package/dist/commands/ui/chat/turn-guard.d.ts +25 -0
  112. package/dist/commands/ui/chat/turn-guard.js +74 -0
  113. package/dist/commands/ui/chat/turn-input.d.ts +3 -2
  114. package/dist/commands/ui/chat/turn-input.js +3 -1
  115. package/dist/commands/ui/chat/turn-scenes.d.ts +19 -0
  116. package/dist/commands/ui/chat/turn-scenes.js +44 -0
  117. package/dist/commands/ui/chat/turn-state.d.ts +6 -0
  118. package/dist/commands/ui/chat/turn.js +8 -3
  119. package/dist/commands/ui/level-route.js +8 -3
  120. package/dist/commands/ui/page.d.ts +19 -1
  121. package/dist/commands/ui/page.js +9 -6
  122. package/dist/commands/ui/plan-structure.d.ts +9 -2
  123. package/dist/commands/ui/plan-structure.en.d.ts +1 -0
  124. package/dist/commands/ui/plan-structure.en.js +1 -0
  125. package/dist/commands/ui/plan-structure.es.d.ts +1 -0
  126. package/dist/commands/ui/plan-structure.es.js +1 -0
  127. package/dist/commands/ui/plan-structure.js +36 -10
  128. package/dist/commands/ui/prototype-main.d.ts +1 -0
  129. package/dist/commands/ui/prototype-scenes-child.js +3 -1
  130. package/dist/commands/ui/prototype-scenes-read.d.ts +1 -0
  131. package/dist/commands/ui/prototype-scenes-route.js +7 -1
  132. package/dist/commands/ui/save-commit.js +6 -2
  133. package/dist/commands/ui/server-options.js +2 -0
  134. package/dist/commands/ui/server.d.ts +5 -22
  135. package/dist/commands/ui/server.js +3 -45
  136. package/dist/commands/ui/snapshot-runners.d.ts +22 -0
  137. package/dist/commands/ui/snapshot-runners.js +45 -0
  138. package/dist/commands/ui/studio-routes.d.ts +1 -0
  139. package/dist/commands/ui/studio-routes.js +1 -0
  140. package/dist/commands/ui/studio-state.d.ts +3 -0
  141. package/dist/commands/ui/studio-state.js +1 -0
  142. package/dist/commands/ui/studio.en.d.ts +13 -0
  143. package/dist/commands/ui/studio.en.js +13 -0
  144. package/dist/commands/ui/studio.es.d.ts +13 -0
  145. package/dist/commands/ui/studio.es.js +13 -0
  146. package/dist/commands/ui/theme-option.d.ts +8 -0
  147. package/dist/commands/ui/theme-option.js +40 -0
  148. package/dist/commands/ui/theme-values.d.ts +5 -0
  149. package/dist/commands/ui/theme-values.js +113 -0
  150. package/dist/ui/page.js +93 -93
  151. package/docs/PROTOTYPE.md +4 -1
  152. package/docs/WORKBENCH.md +76 -22
  153. package/package.json +11 -11
  154. package/skills/ape-critique/SKILL.md +8 -4
  155. package/skills/ape-design-system/SKILL.md +3 -3
  156. package/skills/ape-plan-change/SKILL.md +7 -3
  157. package/skills/ape-prototype/SKILL.md +8 -1
  158. package/templates/example/apps/app/src/i18n/en.ts +2 -0
  159. package/templates/example/apps/app/src/i18n/es.json +2 -0
  160. package/templates/product/apps/admin/src/fonts.ts +2 -1
  161. package/templates/product/apps/app/src/fonts.ts +5 -1
  162. package/templates/product/apps/app/src/i18n/en.ts +2 -0
  163. package/templates/product/apps/app/src/i18n/es.json +2 -0
  164. package/templates/product/prototype/journeys.ts +3 -0
@@ -0,0 +1,219 @@
1
+ /** Each shell's escape character: it also joins a line ending in it to the next. */
2
+ export const ESCAPE = { bash: '\\', powershell: '`', cmd: '^' };
3
+ /**
4
+ * A here-document's operator at `index` (just past `<<`): its word as Bash reads it, quotes and
5
+ * backslashes removed (`E"OF"` and `E\OF` are `EOF`), and where the word ends. Any quoting makes
6
+ * the body plain text.
7
+ */
8
+ function heredocWord(command, index) {
9
+ let at = index;
10
+ const strip = command[at] === '-';
11
+ if (strip)
12
+ at++;
13
+ while (command[at] === ' ' || command[at] === '\t')
14
+ at++;
15
+ let word = '';
16
+ let quoted = false;
17
+ for (; at < command.length; at++) {
18
+ const char = command[at];
19
+ if (char === "'" || char === '"') {
20
+ const close = command.indexOf(char, at + 1);
21
+ if (close < 0)
22
+ return undefined;
23
+ word += command.slice(at + 1, close);
24
+ quoted = true;
25
+ at = close;
26
+ }
27
+ else if (char === '\\' && at + 1 < command.length) {
28
+ word += command[++at];
29
+ quoted = true;
30
+ }
31
+ else if (/[\s;|&<>()`]/.test(char))
32
+ break;
33
+ else
34
+ word += char;
35
+ }
36
+ if (!word && !quoted)
37
+ return undefined;
38
+ return { doc: { word, strip, expand: !quoted }, end: at };
39
+ }
40
+ /**
41
+ * Skips the bodies after a line's here-documents; returns the index of their last line's end. A
42
+ * body whose end line never comes swallows the rest of the command, so the reading marks it.
43
+ */
44
+ function skipBodies(command, from, docs, parts, reading) {
45
+ let at = from;
46
+ for (const doc of docs) {
47
+ const body = [];
48
+ let ended = false;
49
+ while (at < command.length) {
50
+ const end = command.indexOf('\n', at + 1);
51
+ const line = command.slice(at + 1, end < 0 ? command.length : end).replace(/\r$/, '');
52
+ at = end < 0 ? command.length : end;
53
+ ended = (doc.strip ? line.replace(/^\t+/, '') : line) === doc.word;
54
+ if (ended)
55
+ break;
56
+ body.push(line);
57
+ }
58
+ if (!ended && reading)
59
+ reading.unsure ??= 'heredoc';
60
+ // An unquoted word lets the body run `$(…)` and backticks: check the body as commands then.
61
+ const text = body.join('\n');
62
+ if (doc.expand && /`|\$\(/.test(text))
63
+ parts.push(...commandParts(text, 'bash', reading));
64
+ }
65
+ return at;
66
+ }
67
+ export function commandParts(command, shell = 'bash', reading) {
68
+ if (reading)
69
+ reading.steps += command.length;
70
+ const parts = [];
71
+ const escaper = ESCAPE[shell];
72
+ const stack = [{ text: '', depth: 0 }];
73
+ let frame = stack[0];
74
+ let docs = [];
75
+ const cut = () => {
76
+ if (frame.text.trim())
77
+ parts.push(frame.text.trim());
78
+ frame.text = '';
79
+ };
80
+ const open = (closer, arithmetic = false) => {
81
+ frame.text += '$(…)';
82
+ frame = { text: '', closer, depth: 0, arithmetic };
83
+ stack.push(frame);
84
+ };
85
+ const close = () => {
86
+ cut();
87
+ stack.pop();
88
+ frame = stack.at(-1);
89
+ };
90
+ for (let index = 0; index < command.length; index++) {
91
+ const char = command[index];
92
+ const next = command[index + 1];
93
+ if (frame.quote === "'") {
94
+ if (char === "'")
95
+ frame.quote = undefined;
96
+ frame.text += char;
97
+ continue;
98
+ }
99
+ if (char === escaper && next !== undefined && (shell !== 'cmd' || !frame.quote)) {
100
+ const crlf = next === '\r' && command[index + 2] === '\n';
101
+ if (next === '\n' || crlf)
102
+ index += crlf ? 2 : 1;
103
+ else
104
+ frame.text += char + command[++index];
105
+ continue;
106
+ }
107
+ // Command substitution runs inside double quotes too.
108
+ if (shell === 'bash' && char === '`') {
109
+ if (frame.closer === '`')
110
+ close();
111
+ else
112
+ open('`');
113
+ continue;
114
+ }
115
+ if (shell !== 'cmd' && char === '$' && next === '(') {
116
+ open(')', command[index + 2] === '(');
117
+ index++;
118
+ continue;
119
+ }
120
+ if (frame.quote === '"') {
121
+ if (char === '"')
122
+ frame.quote = undefined;
123
+ frame.text += char;
124
+ continue;
125
+ }
126
+ if (char === "'" || char === '"') {
127
+ if (char === '"' || shell !== 'cmd')
128
+ frame.quote = char;
129
+ frame.text += char;
130
+ continue;
131
+ }
132
+ const shift = frame.arithmetic || command[index + 2] === '<';
133
+ if (shell === 'bash' && char === '<' && next === '<' && !shift) {
134
+ const found = heredocWord(command, index + 2);
135
+ if (found) {
136
+ docs.push(found.doc);
137
+ frame.text += command.slice(index, found.end);
138
+ index = found.end - 1;
139
+ continue;
140
+ }
141
+ }
142
+ const last = frame.text.at(-1);
143
+ const redirect = (char === '&' && (last === '>' || last === '<' || next === '>')) ||
144
+ (char === '|' && last === '>');
145
+ if (redirect)
146
+ frame.text += char;
147
+ else if (char === '\n') {
148
+ cut();
149
+ if (docs.length)
150
+ index = skipBodies(command, index, docs, parts, reading) - 1;
151
+ docs = [];
152
+ }
153
+ else if (char === ')' && frame.closer === ')' && !frame.depth)
154
+ close();
155
+ else if ('|&;\r()'.includes(char)) {
156
+ if (frame.closer === ')')
157
+ frame.depth += char === '(' ? 1 : char === ')' ? -1 : 0;
158
+ cut();
159
+ }
160
+ else
161
+ frame.text += char;
162
+ }
163
+ while (stack.length > 1)
164
+ close();
165
+ cut();
166
+ return parts;
167
+ }
168
+ /**
169
+ * A part's words, quotes removed; a quoted word keeps its spaces. With the shell's escape
170
+ * character, an escaped character stands for itself (`p\ush` is `push`); without it, every
171
+ * character is kept as written, which keeps a Windows path's backslashes.
172
+ */
173
+ export function partWords(part, escaper) {
174
+ const words = [];
175
+ let word = '';
176
+ let quote;
177
+ let started = false;
178
+ for (let index = 0; index < part.length; index++) {
179
+ const char = part[index];
180
+ const next = part[index + 1];
181
+ if (escaper && char === escaper && next !== undefined && quote !== "'") {
182
+ // Bash's backslash keeps its meaning inside double quotes only before $ ` " \.
183
+ if (quote !== '"' || escaper !== '\\' || '$`"\\'.includes(next)) {
184
+ word += next;
185
+ index++;
186
+ started = true;
187
+ continue;
188
+ }
189
+ }
190
+ if (quote) {
191
+ if (char === quote)
192
+ quote = undefined;
193
+ else
194
+ word += char;
195
+ }
196
+ else if (char === "'" || char === '"') {
197
+ quote = char;
198
+ started = true;
199
+ }
200
+ else if (/\s/.test(char)) {
201
+ if (started || word)
202
+ words.push(word);
203
+ word = '';
204
+ started = false;
205
+ }
206
+ else
207
+ word += char;
208
+ }
209
+ if (started || word)
210
+ words.push(word);
211
+ return words;
212
+ }
213
+ /** The program a word names, without its folder or a Windows extension, in lower case. */
214
+ export const programName = (word) => (word.split(/[\\/]/).at(-1) ?? '').toLowerCase().replace(/\.(?:exe|cmd|bat|ps1|mjs|js)$/, '');
215
+ /** The part's program: its first word after any `NAME=value` settings. */
216
+ export function partProgram(part) {
217
+ const words = partWords(part);
218
+ return words.find((word) => !/^[A-Za-z_][A-Za-z0-9_]*=/.test(word)) ?? words[0] ?? part;
219
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The commands a part hands to another shell: `sh -c '…'`, `bash -lc "…"`, `cmd /c …`,
3
+ * `powershell -Command …` (or `-EncodedCommand`, or a bare command), `pwsh -c …`, `eval …` and
4
+ * `iex …` (`Invoke-Expression`),
5
+ * found anywhere in the part, so `pnpm exec sh -c "…"` and `env X=1 bash -c …` count too. The
6
+ * limits check each one with the same rules (limits.ts). Plain Node only: the hook runs it.
7
+ */
8
+ import { type Shell } from './command-parts.ts';
9
+ export interface Wrapped {
10
+ script: string;
11
+ shell: Shell;
12
+ }
13
+ export declare const POSIX: Set<string>;
14
+ export declare const POWERSHELL: Set<string>;
15
+ /** `sh`'s script: the first word after its options, when one of them is `-c` (`-lc`, `-ec`…). */
16
+ export declare function posixScript(words: string[], from: number): string | undefined;
17
+ /** PowerShell's command: after `-Command` (or any prefix), `-EncodedCommand`, or bare words. */
18
+ export declare function powershellScript(words: string[], from: number): string | undefined;
19
+ export declare const EXPRESSIONS: Set<string>;
20
+ /** Every script the part's words hand to another shell; past `cap` of them, one more and stop. */
21
+ export declare function wrappedScripts(words: string[], cap?: number): Wrapped[];
@@ -0,0 +1,100 @@
1
+ /**
2
+ * The commands a part hands to another shell: `sh -c '…'`, `bash -lc "…"`, `cmd /c …`,
3
+ * `powershell -Command …` (or `-EncodedCommand`, or a bare command), `pwsh -c …`, `eval …` and
4
+ * `iex …` (`Invoke-Expression`),
5
+ * found anywhere in the part, so `pnpm exec sh -c "…"` and `env X=1 bash -c …` count too. The
6
+ * limits check each one with the same rules (limits.ts). Plain Node only: the hook runs it.
7
+ */
8
+ import { programName } from './command-parts.js';
9
+ export const POSIX = new Set(['sh', 'bash', 'zsh', 'dash', 'ksh', 'ash', 'fish']);
10
+ export const POWERSHELL = new Set(['powershell', 'pwsh']);
11
+ // PowerShell options that take a value, by their shortest accepted names.
12
+ const VALUED = [
13
+ 'executionpolicy',
14
+ 'ep',
15
+ 'windowstyle',
16
+ 'workingdirectory',
17
+ 'wd',
18
+ 'configurationname',
19
+ 'outputformat',
20
+ 'inputformat',
21
+ 'settingsfile',
22
+ 'custompipename',
23
+ 'psconsolefile',
24
+ 'version',
25
+ ];
26
+ /** `sh`'s script: the first word after its options, when one of them is `-c` (`-lc`, `-ec`…). */
27
+ export function posixScript(words, from) {
28
+ let command = false;
29
+ for (let index = from; index < words.length; index++) {
30
+ const word = words[index];
31
+ if (/^[-+][oO]$/.test(word))
32
+ index++;
33
+ else if (/^-[A-Za-z]*c[A-Za-z]*$/.test(word))
34
+ command = true;
35
+ else if (!/^[-+]/.test(word))
36
+ return command ? word : undefined;
37
+ }
38
+ }
39
+ const decoded = (text) => {
40
+ try {
41
+ return text ? Buffer.from(text, 'base64').toString('utf16le') : undefined;
42
+ }
43
+ catch {
44
+ return undefined;
45
+ }
46
+ };
47
+ /** PowerShell's command: after `-Command` (or any prefix), `-EncodedCommand`, or bare words. */
48
+ export function powershellScript(words, from) {
49
+ for (let index = from; index < words.length; index++) {
50
+ const word = words[index];
51
+ if (!/^[-/]/.test(word))
52
+ return words.slice(index).join(' ');
53
+ const name = word.replace(/^[-/]+/, '').toLowerCase();
54
+ if (!name)
55
+ return words.slice(index + 1).join(' ');
56
+ if ('command'.startsWith(name))
57
+ return words.slice(index + 1).join(' ');
58
+ if (name === 'e' || name === 'ec' || (name.length > 1 && 'encodedcommand'.startsWith(name)))
59
+ return decoded(words[index + 1]);
60
+ if ('file'.startsWith(name))
61
+ return undefined;
62
+ if (VALUED.some((option) => option.startsWith(name) && name.length > 1))
63
+ index++;
64
+ }
65
+ }
66
+ export const EXPRESSIONS = new Set(['iex', 'invoke-expression']);
67
+ /** Every script the part's words hand to another shell; past `cap` of them, one more and stop. */
68
+ export function wrappedScripts(words, cap = Number.POSITIVE_INFINITY) {
69
+ const found = [];
70
+ for (let index = 0; index < words.length && found.length <= cap; index++) {
71
+ const name = programName(words[index]);
72
+ let script;
73
+ let shell = 'bash';
74
+ if (POSIX.has(name))
75
+ script = posixScript(words, index + 1);
76
+ else if (name === 'eval')
77
+ script = words.slice(index + 1).join(' ');
78
+ else if (EXPRESSIONS.has(name)) {
79
+ script = words
80
+ .slice(index + 1)
81
+ .filter((value) => !/^-command$/i.test(value))
82
+ .join(' ');
83
+ shell = 'powershell';
84
+ }
85
+ else if (name === 'cmd') {
86
+ const flag = words.findIndex((value, at) => at > index && /^\/[ck]$/i.test(value));
87
+ if (flag > 0) {
88
+ script = words.slice(flag + 1).join(' ');
89
+ shell = 'cmd';
90
+ }
91
+ }
92
+ else if (POWERSHELL.has(name)) {
93
+ script = powershellScript(words, index + 1);
94
+ shell = 'powershell';
95
+ }
96
+ if (script?.trim())
97
+ found.push({ script, shell });
98
+ }
99
+ return found;
100
+ }
@@ -0,0 +1 @@
1
+ export declare function designDelete(command: string, cwd: string): boolean;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Design turns may delete files inside `design/` and `prototype/` without asking: a single
3
+ * delete command, alone, whose every path stays below one of those folders. The approval record
4
+ * (`prototype/versions`) is never one of them, and neither is either folder as a whole.
5
+ */
6
+ import { isAbsolute, relative, resolve } from 'node:path';
7
+ import { commandParts, partWords, programName } from './command-parts.js';
8
+ const DELETES = new Set(['rm', 'del', 'erase', 'ri', 'remove-item', 'rmdir']);
9
+ const OPTION = /^-(?:[rRfv]+|-recursive|-force|recurse|force)$/i;
10
+ const GLOB = /[*?[\]]/;
11
+ function deletable(word, cwd) {
12
+ if (/[$`{}~%!]/.test(word))
13
+ return false;
14
+ const path = relative(cwd, resolve(cwd, word));
15
+ if (!path || isAbsolute(path))
16
+ return false;
17
+ const parts = path.split(/[\\/]+/);
18
+ const [top, second] = parts;
19
+ if (parts.includes('..') || parts.length < 2 || !top || !second)
20
+ return false;
21
+ if (top !== 'design' && top !== 'prototype')
22
+ return false;
23
+ // The first two names are literal, so a pattern can never reach the approval record.
24
+ if (GLOB.test(top) || GLOB.test(second))
25
+ return false;
26
+ return !(top === 'prototype' && second.toLowerCase() === 'versions');
27
+ }
28
+ export function designDelete(command, cwd) {
29
+ const parts = commandParts(command);
30
+ if (parts.length !== 1)
31
+ return false;
32
+ const [program, ...rest] = partWords(parts[0]);
33
+ if (!program || !DELETES.has(programName(program)) || program !== program.trim())
34
+ return false;
35
+ const paths = rest.filter((word) => !OPTION.test(word));
36
+ if (rest.some((word) => word.startsWith('-') && !OPTION.test(word)))
37
+ return false;
38
+ return paths.length > 0 && paths.every((word) => deletable(word, cwd));
39
+ }
@@ -2,17 +2,19 @@ import type { Chat } from '@buffcore/contracts/workbench';
2
2
  import type { AgentTurn, Start } from '../runner.ts';
3
3
  import { copyCodexExamples } from './codex-examples.ts';
4
4
  import type { TurnMigrations } from './migration-turn.ts';
5
+ import { type TurnGuard } from './turn-guard.ts';
5
6
  import { type Active } from './turn-state.ts';
6
7
  export declare function startAgentTurn(start: Start, spec: Parameters<Start>[0], folder: string, turn: AgentTurn, work: Chat['work']): ReturnType<Start>;
7
- export declare function startCodingTurn(start: Start, spec: Parameters<Start>[0], run: Active, migrations?: TurnMigrations, examples?: ReturnType<typeof copyCodexExamples>): import("child_process").ChildProcess;
8
+ export declare function startCodingTurn(start: Start, spec: Parameters<Start>[0], run: Active, migrations?: TurnMigrations, examples?: ReturnType<typeof copyCodexExamples>, guard?: TurnGuard): import("child_process").ChildProcess;
8
9
  /** Resolve flags, the start record and stdin from the same per-launch settings. */
9
- export declare function launchInput(run: Active, root: string, context: string): {
10
+ export declare function launchInput(run: Active, root: string, context: string, save: () => void): {
10
11
  adapter: import("./prompt.ts").ChatAdapter;
11
12
  input: string;
12
13
  examples: {
13
14
  folder: string;
14
15
  close: () => void;
15
16
  } | undefined;
17
+ guard: TurnGuard | undefined;
16
18
  spec: {
17
19
  program: 'pnpm';
18
20
  args: string[];
@@ -1,3 +1,4 @@
1
+ import { effectiveLevel } from '../../agents-file.js';
1
2
  import { migrationTurnEnv } from '../../migrate-create-protocol.js';
2
3
  import { stdinInput } from './attachments.js';
3
4
  import { startWithClaudeTaskOutput } from './claude-task-output.js';
@@ -7,6 +8,7 @@ import { scrubLaunchIds } from './launch-ids.js';
7
8
  import { inTree } from './permissions.js';
8
9
  import { buildEnv, chatError, composePrompt, t } from './prompt.js';
9
10
  import { message } from './store.js';
11
+ import { openTurnGuard } from './turn-guard.js';
10
12
  import { adapterFor, turnArgs } from './turn-input.js';
11
13
  import { turnContext } from './turn-state.js';
12
14
  import { writesInChange } from './worktree.js';
@@ -15,7 +17,7 @@ export function startAgentTurn(start, spec, folder, turn, work) {
15
17
  ? startWithClaudeTaskOutput(start, spec, folder, turn)
16
18
  : start(spec, folder, turn);
17
19
  }
18
- export function startCodingTurn(start, spec, run, migrations, examples) {
20
+ export function startCodingTurn(start, spec, run, migrations, examples, guard) {
19
21
  let grant;
20
22
  try {
21
23
  grant = writesInChange(run.chat)
@@ -29,16 +31,20 @@ export function startCodingTurn(start, spec, run, migrations, examples) {
29
31
  child.once(event, grant.close);
30
32
  if (examples)
31
33
  child.once('close', examples.close);
34
+ if (guard)
35
+ for (const event of ['error', 'close'])
36
+ child.once(event, guard.close);
32
37
  return child;
33
38
  }
34
39
  catch (error) {
35
40
  grant?.close();
36
41
  examples?.close();
42
+ guard?.close();
37
43
  throw error;
38
44
  }
39
45
  }
40
46
  /** Resolve flags, the start record and stdin from the same per-launch settings. */
41
- export function launchInput(run, root, context) {
47
+ export function launchInput(run, root, context, save) {
42
48
  const adapter = adapterFor(run.chat.agent);
43
49
  if (!adapter)
44
50
  throw chatError('chat.unavailable', { agent: run.chat.agent });
@@ -46,8 +52,12 @@ export function launchInput(run, root, context) {
46
52
  if (run.images.length && !def?.turn?.images)
47
53
  message(run.chat, 'system', t('chat.imagesUnavailable', { agent: adapter.id }));
48
54
  const examples = adapter.id === 'codex' && inTree(run.chat.work) ? copyCodexExamples(root) : undefined;
55
+ let guard;
49
56
  try {
50
- const args = turnArgs(run, root, adapter, examples?.folder);
57
+ guard = adapter.id === 'claude' ? openTurnGuard(run, root, save) : undefined;
58
+ // One read of the level serves the arguments and the settings alike.
59
+ const level = guard?.level ?? effectiveLevel(root);
60
+ const args = turnArgs(run, root, adapter, examples?.folder, guard, level);
51
61
  const input = stdinInput(adapter.id, scrubLaunchIds(context) +
52
62
  (run.selection?.instructions ?? '') +
53
63
  composePrompt(run.chat, root, run.retryNotice ? run.accepted : undefined), run.images);
@@ -58,6 +68,7 @@ export function launchInput(run, root, context) {
58
68
  root,
59
69
  folder: run.tree,
60
70
  contained: run.contained,
71
+ level,
61
72
  });
62
73
  if (examples)
63
74
  env = { ...env, ...codexExampleEnv(run.tree, examples.folder) };
@@ -65,6 +76,7 @@ export function launchInput(run, root, context) {
65
76
  adapter,
66
77
  input,
67
78
  examples,
79
+ guard,
68
80
  spec: {
69
81
  program: 'pnpm',
70
82
  args: ['exec', def?.bin, ...args],
@@ -75,6 +87,7 @@ export function launchInput(run, root, context) {
75
87
  }
76
88
  catch (error) {
77
89
  examples?.close();
90
+ guard?.close();
78
91
  throw error;
79
92
  }
80
93
  }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The limit a command's text mentions, as the card names it (`git push`, `ape deploy`, `.ssh`,
3
+ * `.env.production`, `curl`); nothing when it mentions none.
4
+ */
5
+ export declare function mentionedLimit(command: string, cwd: string): string | undefined;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * The limits' fail-safe: a command's whole text, read for every limit's words whatever the shape
3
+ * around them. When the parse (limits.ts) refused nothing but the text still mentions a limit,
4
+ * the call goes to the person's card for Allow once, so a shape the parse misses costs one click,
5
+ * not a hole. Case does not count; line continuations are joined first, and the text is also read
6
+ * with its quotes and escapes taken out (`'gi't pu\sh`). Plain Node only: the hook runs it.
7
+ */
8
+ import { SECRET_FOLDERS } from './secret-folders.js';
9
+ const escaped = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
10
+ /** A word on its own, not inside a longer word or file name. */
11
+ const word = (pattern, after = '(?![\\w-])') => new RegExp(`(?<![\\w.-])(?:${pattern})${after}`, 'gi');
12
+ const GIT = /(?<![\w.])git(?!\w)/i;
13
+ const PUSH = /(?<![\w.])(?:push|send-pack)(?!\w)/i;
14
+ const APE = word('ape');
15
+ const DEPLOY = word('deploy');
16
+ const PRODUCTION = /(?<![\w-])\.env\.(?:production|prod|staging)(?![\w-])[\w.-]*/i;
17
+ const SECRETS = word([...SECRET_FOLDERS].map(escaped).join('|'), '(?![\\w.-])');
18
+ const DOWNLOAD_NAMES = [
19
+ 'curl',
20
+ 'wget2?',
21
+ 'aria2c',
22
+ 'iwr',
23
+ 'irm',
24
+ 'invoke-webrequest',
25
+ 'invoke-restmethod',
26
+ 'start-bitstransfer',
27
+ 'bitsadmin',
28
+ 'net\\.webclient',
29
+ 'downloadstring',
30
+ 'downloadfile',
31
+ ];
32
+ const DOWNLOADS = word(`(?:${DOWNLOAD_NAMES.join('|')})(?:\\.exe)?`, '(?![\\w.-])');
33
+ const CERTUTIL = /(?<![\w.-])certutil(?:\.exe)?(?![\w-])/i;
34
+ const URLCACHE = /[-/]urlcache(?![\w-])/i;
35
+ const first = (pattern, text) => {
36
+ pattern.lastIndex = 0;
37
+ return pattern.exec(text)?.[0];
38
+ };
39
+ /** The text with the turn's own folder taken out, so a product kept under `secrets/` still works. */
40
+ function withoutFolder(text, cwd) {
41
+ const parts = cwd
42
+ .split(/[\\/]+/)
43
+ .filter(Boolean)
44
+ .map(escaped);
45
+ if (!parts.length)
46
+ return text;
47
+ return text.replace(new RegExp(parts.join('[\\\\/]+'), 'gi'), '.');
48
+ }
49
+ function mentionIn(text, cwd) {
50
+ // `git stash push` keeps work locally; any other `push` in the text still counts.
51
+ if (GIT.test(text) && PUSH.test(text.replace(/\bstash\s+push\b/gi, '')))
52
+ return 'git push';
53
+ if (first(APE, text) && first(DEPLOY, text))
54
+ return 'ape deploy';
55
+ const settings = PRODUCTION.exec(text)?.[0];
56
+ if (settings)
57
+ return settings;
58
+ const secret = first(SECRETS, withoutFolder(text, cwd))?.toLowerCase();
59
+ if (secret)
60
+ return secret;
61
+ // `certutil -urlcache` fetches a URL; its other uses read local files.
62
+ if (CERTUTIL.test(text) && URLCACHE.test(text))
63
+ return 'certutil';
64
+ return first(DOWNLOADS, text)?.toLowerCase();
65
+ }
66
+ /**
67
+ * The limit a command's text mentions, as the card names it (`git push`, `ape deploy`, `.ssh`,
68
+ * `.env.production`, `curl`); nothing when it mentions none.
69
+ */
70
+ export function mentionedLimit(command, cwd) {
71
+ const joined = command.replace(/[\\`^]\r?\n/g, '');
72
+ const plain = joined.replace(/['"`^]/g, '').replace(/\\(?=[\w.])/g, '');
73
+ return (mentionIn(joined, cwd) ?? mentionIn(plain, cwd))?.slice(0, 80);
74
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The limits' read of shell patterns: a word with `*`, `?`, `[…]` or `{a,b}` names whatever files
3
+ * the shell finds, so `cat .env.*` or `cat ~/.ss?/id_rsa` reaches a limit no word spells out. Each
4
+ * such word's braces are expanded (bounded), each path segment becomes a pattern, and the pattern
5
+ * is tried against every secret folder's name and production settings file's name; a match sends
6
+ * the call to the card (limits.ts). A segment of wildcards only (`*`, `**`, `[a-z]?`) names every
7
+ * file and tells nothing, so `dist/*` and `src/**` stay free. Plain Node only: the hook runs it.
8
+ */
9
+ import type { Reading } from './command-parts.ts';
10
+ /**
11
+ * The secret folder or settings file a pattern in the command could reach (`.ssh`,
12
+ * `.env.production`); nothing when none does. Its work counts in the reading's steps; past the
13
+ * cap, or a word whose braces expand too far, it marks the reading `budget` and names nothing.
14
+ */
15
+ export declare function patternReach(command: string, reading: Reading, cap: number): string | undefined;