@buffcore/cli 0.8.43 → 0.8.45

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 (65) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/commands/prototype/mark-shot.d.ts +31 -0
  3. package/dist/commands/prototype/mark-shot.js +149 -0
  4. package/dist/commands/ui/chat/approval-folders.d.ts +20 -0
  5. package/dist/commands/ui/chat/approval-folders.js +134 -0
  6. package/dist/commands/ui/chat/approval-text.d.ts +11 -0
  7. package/dist/commands/ui/chat/approval-text.js +69 -0
  8. package/dist/commands/ui/chat/approval-writes.d.ts +32 -0
  9. package/dist/commands/ui/chat/approval-writes.js +179 -0
  10. package/dist/commands/ui/chat/claude-permissions.d.ts +4 -4
  11. package/dist/commands/ui/chat/claude-permissions.js +32 -4
  12. package/dist/commands/ui/chat/codex-idle.d.ts +1 -1
  13. package/dist/commands/ui/chat/commit-limits.d.ts +36 -0
  14. package/dist/commands/ui/chat/commit-limits.js +164 -0
  15. package/dist/commands/ui/chat/fresh-critique.js +3 -1
  16. package/dist/commands/ui/chat/fresh-launch.d.ts +5 -0
  17. package/dist/commands/ui/chat/fresh-launch.js +7 -4
  18. package/dist/commands/ui/chat/fresh.js +7 -1
  19. package/dist/commands/ui/chat/gh-api-limits.d.ts +14 -0
  20. package/dist/commands/ui/chat/gh-api-limits.js +74 -0
  21. package/dist/commands/ui/chat/git-words.d.ts +10 -0
  22. package/dist/commands/ui/chat/git-words.js +26 -0
  23. package/dist/commands/ui/chat/host-launched.d.ts +11 -0
  24. package/dist/commands/ui/chat/host-launched.js +35 -0
  25. package/dist/commands/ui/chat/limit-mentions.js +16 -2
  26. package/dist/commands/ui/chat/limit-text.d.ts +15 -0
  27. package/dist/commands/ui/chat/limit-text.js +36 -0
  28. package/dist/commands/ui/chat/limits-hook.js +2 -2
  29. package/dist/commands/ui/chat/limits.d.ts +7 -12
  30. package/dist/commands/ui/chat/limits.en.d.ts +2 -0
  31. package/dist/commands/ui/chat/limits.en.js +2 -0
  32. package/dist/commands/ui/chat/limits.es.js +2 -0
  33. package/dist/commands/ui/chat/limits.js +63 -59
  34. package/dist/commands/ui/chat/planning-limits.js +11 -0
  35. package/dist/commands/ui/chat/publish-limits.js +23 -7
  36. package/dist/commands/ui/chat/turn-guard.d.ts +8 -2
  37. package/dist/commands/ui/chat/turn-guard.js +8 -3
  38. package/dist/commands/ui/commands.en.d.ts +3 -0
  39. package/dist/commands/ui/commands.en.js +3 -0
  40. package/dist/commands/ui/commands.es.d.ts +3 -0
  41. package/dist/commands/ui/commands.es.js +3 -0
  42. package/dist/commands/ui/index.d.ts +42 -0
  43. package/dist/commands/ui/index.js +14 -2
  44. package/dist/commands/ui/plan-brief.d.ts +13 -0
  45. package/dist/commands/ui/plan-brief.js +91 -0
  46. package/dist/commands/ui/plan-files.d.ts +1 -11
  47. package/dist/commands/ui/plan-files.js +2 -48
  48. package/dist/commands/ui/prototype-main.d.ts +5 -0
  49. package/dist/commands/ui/prototype-shot-route.d.ts +16 -0
  50. package/dist/commands/ui/prototype-shot-route.js +98 -0
  51. package/dist/commands/ui/routes.d.ts +2 -0
  52. package/dist/commands/ui/server-core.js +2 -0
  53. package/dist/commands/ui/server-options.js +1 -0
  54. package/dist/commands/ui/server-request.js +5 -0
  55. package/dist/commands/ui/server.d.ts +7 -0
  56. package/dist/commands/ui/server.js +16 -1
  57. package/dist/commands/ui/studio-routes.d.ts +1 -0
  58. package/dist/commands/ui/studio-routes.js +3 -1
  59. package/dist/commands/ui/studio-state.d.ts +6 -0
  60. package/dist/ui/page.js +114 -95
  61. package/docs/PROTOTYPE.md +14 -2
  62. package/docs/WORKBENCH.md +12 -3
  63. package/package.json +11 -11
  64. package/skills/ape-plan-change/SKILL.md +8 -0
  65. package/templates/product/plan/brief.md +29 -0
@@ -0,0 +1,26 @@
1
+ /**
2
+ * A command's subcommand after a program's options (`git -C x push`): the options before it that
3
+ * take a value skip that value. Plain Node only: the hook runs it.
4
+ */
5
+ // Git's options before the subcommand that take the next word as their value.
6
+ const VALUED = new Set([
7
+ '-C',
8
+ '-c',
9
+ '--git-dir',
10
+ '--work-tree',
11
+ '--namespace',
12
+ '--super-prefix',
13
+ '--config-env',
14
+ '--attr-source',
15
+ ]);
16
+ /** The first word after `from` that is not an option (or an option's value), and its index. */
17
+ export function subcommandAt(words, from) {
18
+ for (let index = from; index < words.length; index++) {
19
+ const word = words[index];
20
+ if (VALUED.has(word))
21
+ index++;
22
+ else if (!word.startsWith('-'))
23
+ return { name: word.toLowerCase(), at: index };
24
+ }
25
+ }
26
+ export const subcommand = (words, from) => subcommandAt(words, from)?.name;
@@ -0,0 +1,11 @@
1
+ /** The variable a host that starts `ape ui` sets to `1`. */
2
+ export declare const HOST_LAUNCHED_ENV = "APE_HOST_LAUNCHED";
3
+ /**
4
+ * Records a server's choice for its product folder; returns what its close calls. A server created
5
+ * without the mode clears the folder's mark, so the mode never outlives the server that asked.
6
+ */
7
+ export declare function registerHostLaunched(root: string, on: boolean): () => void;
8
+ /** The product's turns are started by its host's launcher. */
9
+ export declare const hostLaunched: (root: string) => boolean;
10
+ /** `ape ui`'s reading of the variable: exactly `1` turns the mode on. */
11
+ export declare const hostLaunchedEnv: (env?: NodeJS.ProcessEnv) => boolean;
@@ -0,0 +1,35 @@
1
+ // A host whose own trusted launcher starts the agent's turns (0.8.44). Such a launcher checks each
2
+ // turn's arguments and cannot trust files or a socket the studio's process made, so with this mode
3
+ // on the studio launches turns as 0.8.41 did: no per-turn settings file with the limits hook, no
4
+ // MCP config with the permission tool, no permission prompt tool and no socket; 0.8.41's modes
5
+ // (`acceptEdits`, or `dontAsk` for planning) at every level and its deny rules. The host applies
6
+ // the limits. Off unless the host says so:
7
+ // `createUiServer({ hostLaunched: true })`, or `APE_HOST_LAUNCHED=1` for a host that starts `ape ui`.
8
+ import { existsSync, realpathSync } from 'node:fs';
9
+ import { resolve } from 'node:path';
10
+ /** The variable a host that starts `ape ui` sets to `1`. */
11
+ export const HOST_LAUNCHED_ENV = 'APE_HOST_LAUNCHED';
12
+ /** The product folders whose server a host created in this mode, each with its server's mark. */
13
+ const launched = new Map();
14
+ const keyOf = (root) => (existsSync(root) ? realpathSync.native(root) : resolve(root));
15
+ /**
16
+ * Records a server's choice for its product folder; returns what its close calls. A server created
17
+ * without the mode clears the folder's mark, so the mode never outlives the server that asked.
18
+ */
19
+ export function registerHostLaunched(root, on) {
20
+ const key = keyOf(root);
21
+ if (!on) {
22
+ launched.delete(key);
23
+ return () => { };
24
+ }
25
+ const mark = Symbol(key);
26
+ launched.set(key, mark);
27
+ return () => {
28
+ if (launched.get(key) === mark)
29
+ launched.delete(key);
30
+ };
31
+ }
32
+ /** The product's turns are started by its host's launcher. */
33
+ export const hostLaunched = (root) => launched.has(keyOf(root));
34
+ /** `ape ui`'s reading of the variable: exactly `1` turns the mode on. */
35
+ export const hostLaunchedEnv = (env = process.env) => env[HOST_LAUNCHED_ENV] === '1';
@@ -32,14 +32,26 @@ const DOWNLOAD_NAMES = [
32
32
  ];
33
33
  const DOWNLOADS = word(`(?:${DOWNLOAD_NAMES.join('|')})(?:\\.exe)?`, '(?![\\w.-])');
34
34
  // Publishing: a package manager and `publish` (or npm's shortened names, down to `pu`), or `gh`,
35
- // `release` and a verb that changes one. A path or a longer word (`src/publish.ts`,
35
+ // `release` and a verb that changes one, or `gh api`, a repository's releases and a method or
36
+ // field that changes one. A path or a longer word (`src/publish.ts`,
36
37
  // `publish-docs`) is not the subcommand; nor is one asked only for its help (`publish --help`,
37
38
  // `npm help publish`), which is taken out of the text first.
38
- const MANAGER = /(?<![\w.-])(npm|pnpm|yarn)(?![\w-])/i;
39
+ const MANAGER = /(?<![\w.-])(npm|pnpm|yarn|bun|lerna|changeset)s?(?![\w-])/i;
39
40
  const PUBLISH = /(?<![\w./\\-])pu(?:b(?:l(?:i(?:sh?)?)?)?)?(?![\w./\\-])/i;
40
41
  const GH = /(?<![\w.-])gh(?![\w-])/i;
41
42
  const RELEASE = /(?<![\w./\\-])release(?![\w./\\-])/i;
42
43
  const VERBS = 'create|new|upload|edit|delete(?:-asset)?';
44
+ const API = /(?<![\w.-])api(?![\w.-])/i;
45
+ const RELEASES = /(?<![\w-])repos\/\S*\/releases(?![\w-])/i;
46
+ const METHOD = /(?<!\S)(?:-X\s*|--method[\s=]+)(\w+)/gi;
47
+ const CHANGES = /(?<![\w-])(?:post|patch|put|delete)(?![\w-])|(?<!\S)(?:-[fF]|--(?:raw-)?field|--input)(?![\w-])/i;
48
+ /** A method named that changes; with none named, fields (gh's POST) or a changing verb at all. */
49
+ const apiChange = (text) => {
50
+ const methods = [...text.matchAll(METHOD)].map((match) => match[1].toUpperCase());
51
+ if (!methods.length)
52
+ return CHANGES.test(text);
53
+ return methods.some((method) => method !== 'GET' && method !== 'HEAD');
54
+ };
43
55
  const RELEASE_CHANGE = new RegExp(`(?<![\\w./\\\\-])(?:${VERBS})(?![\\w./\\\\-])`, 'i');
44
56
  const HELP = new RegExp(`(?<![\\w./\\\\-])(?:(?:pu\\w*|${VERBS})\\s+(?:--help|-h)|help\\s+pu\\w*)(?=\\s*(?:$|[;&|)'"\\r\\n]))`, 'gi');
45
57
  /** A value-taking option and its value (`--filter publish`): case counts, as `-C` is not `-c`. */
@@ -72,6 +84,8 @@ function mentionIn(text, cwd) {
72
84
  return `${manager.toLowerCase()} publish`;
73
85
  if (GH.test(asked) && RELEASE.test(asked) && RELEASE_CHANGE.test(asked))
74
86
  return 'gh release';
87
+ if (GH.test(text) && API.test(text) && RELEASES.test(text) && apiChange(text))
88
+ return 'gh api releases';
75
89
  const settings = PRODUCTION.exec(text)?.[0];
76
90
  if (settings)
77
91
  return settings;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The limits' words: the sentence the agent reads for a crossed limit, in the turn's language,
3
+ * and the limit a refused call's result names. Plain Node only: the hook runs it.
4
+ */
5
+ import { en } from './limits.en.ts';
6
+ import type { Limit, RefusedKind } from './limits.ts';
7
+ /**
8
+ * The limit a refused call's result names: the hook's own sentence for it, in either language,
9
+ * came back as the result. Nothing when it names none.
10
+ */
11
+ export declare function refusalLimit(text: string): RefusedKind | undefined;
12
+ /** The agent's words in the turn's language (LANG), with `{name}` values filled in. */
13
+ export declare function limitText(key: keyof typeof en, values?: Record<string, string>): string;
14
+ /** The sentence the agent reads for a crossed limit: it names the refused part. */
15
+ export declare const limitReason: (limit: Limit) => string;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The limits' words: the sentence the agent reads for a crossed limit, in the turn's language,
3
+ * and the limit a refused call's result names. Plain Node only: the hook runs it.
4
+ */
5
+ import { en } from './limits.en.js';
6
+ import { es } from './limits.es.js';
7
+ const catalogs = { en, es };
8
+ const REFUSED = [
9
+ 'secrets',
10
+ 'deploy',
11
+ 'push',
12
+ 'settings',
13
+ 'publish',
14
+ 'release',
15
+ 'approval',
16
+ 'commit',
17
+ ];
18
+ /**
19
+ * The limit a refused call's result names: the hook's own sentence for it, in either language,
20
+ * came back as the result. Nothing when it names none.
21
+ */
22
+ export function refusalLimit(text) {
23
+ return REFUSED.find((kind) => Object.values(catalogs).some((words) => text.includes(words[`limits.${kind}`].replace('`{part}`', ''))));
24
+ }
25
+ /** The agent's words in the turn's language (LANG), with `{name}` values filled in. */
26
+ export function limitText(key, values = {}) {
27
+ const locale = (process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || 'en')
28
+ .slice(0, 2)
29
+ .toLowerCase();
30
+ const words = catalogs[locale === 'es' ? 'es' : 'en'];
31
+ return words[key].replace(/\{(\w+)\}/g, (_, name) => values[name] ?? '');
32
+ }
33
+ /** The sentence the agent reads for a crossed limit: it names the refused part. */
34
+ export const limitReason = (limit) => limit.kind === 'unsure'
35
+ ? limitText(`limits.unsure.${limit.unsure ?? 'mention'}`, { mention: limit.mention ?? '' })
36
+ : limitText(`limits.${limit.kind}`, { part: limit.part.slice(0, 200) });
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * The studio's PreToolUse hook, installed for each Claude turn through `--settings`: it reads the
3
3
  * call from stdin and answers with Claude Code's hook output. Run by plain Node, as
4
- * `node limits-hook.ts <work>`; the decision is `hookAnswer` in limits.ts. Anything unexpected
4
+ * `node limits-hook.ts <work> <level>`; the decision is `hookAnswer` in limits.ts. Anything unexpected
5
5
  * refuses the call (exit 2, the reason on stderr): an exit 1 would let it run.
6
6
  */
7
7
  import { readFileSync } from 'node:fs';
8
8
  try {
9
9
  const { hookAnswer } = await import('./limits.js');
10
- const answer = hookAnswer(readFileSync(0, 'utf8'), process.argv[2] ?? '');
10
+ const answer = hookAnswer(readFileSync(0, 'utf8'), process.argv[2] ?? '', process.argv[3] ?? '');
11
11
  if (answer)
12
12
  process.stdout.write(JSON.stringify({
13
13
  hookSpecificOutput: {
@@ -1,7 +1,8 @@
1
1
  import { type Unsure } from './command-parts.ts';
2
- import { en } from './limits.en.ts';
2
+ import { type Turn } from './commit-limits.ts';
3
+ export { limitReason, limitText, refusalLimit } from './limit-text.ts';
3
4
  /** The limits a call is refused for at every level; a person can never allow them. */
4
- export type RefusedKind = 'secrets' | 'deploy' | 'push' | 'settings' | 'publish' | 'release';
5
+ export type RefusedKind = 'secrets' | 'deploy' | 'push' | 'settings' | 'publish' | 'release' | 'approval' | 'commit';
5
6
  export type LimitKind = RefusedKind | 'download' | 'unsure';
6
7
  export interface Limit {
7
8
  /** `ask` sends the call to the person's Allow card; `deny` refuses it at every level. */
@@ -22,23 +23,17 @@ export interface Limit {
22
23
  * the turn's folder counts, so a product kept under such a folder still works.
23
24
  */
24
25
  export declare function secretPath(path: string, cwd: string): boolean;
25
- /** The first limit a tool call crosses, refusals before asks; nothing when it crosses none. */
26
- export declare function crossedLimit(tool: string, input: unknown, cwd: string): Limit | undefined;
27
26
  /**
28
- * The limit a refused call's result names: the hook's own sentence for it, in either language,
29
- * came back as the result. Nothing when it names none.
27
+ * The first limit a tool call crosses, refusals before asks; nothing when it crosses none. The
28
+ * turn, when known, adds the limits only some turns keep (a design turn's commit on Autopilot).
30
29
  */
31
- export declare function refusalLimit(text: string): RefusedKind | undefined;
32
- /** The agent's words in the turn's language (LANG), with `{name}` values filled in. */
33
- export declare function limitText(key: keyof typeof en, values?: Record<string, string>): string;
34
- /** The sentence the agent reads for a crossed limit: it names the refused part. */
35
- export declare const limitReason: (limit: Limit) => string;
30
+ export declare function crossedLimit(tool: string, input: unknown, cwd: string, turn?: Turn): Limit | undefined;
36
31
  /**
37
32
  * The hook's answer to one call: a crossed limit, a design turn's delete inside `design/` or
38
33
  * `prototype/` (allowed), or nothing. A call it cannot read is refused, so a broken call never
39
34
  * slips past the limits.
40
35
  */
41
- export declare function hookAnswer(text: string, work: string): {
36
+ export declare function hookAnswer(text: string, work: string, level?: string): {
42
37
  decision: 'allow' | 'deny' | 'ask';
43
38
  reason: string;
44
39
  } | undefined;
@@ -6,6 +6,8 @@ export declare const en: {
6
6
  readonly 'limits.settings': '`{part}` is not allowed here: production settings stay with a person.';
7
7
  readonly 'limits.publish': '`{part}` is not allowed here: publishing a package stays with a person, from their own terminal.';
8
8
  readonly 'limits.release': '`{part}` is not allowed here: publishing a release stays with a person, from their own terminal.';
9
+ readonly 'limits.approval': '`{part}` is not allowed here: approval records are written only by the studio, when a person approves.';
10
+ readonly 'limits.commit': '`{part}` is not allowed here: on Autopilot the studio saves a design step’s work; the agent makes no commit.';
9
11
  readonly 'limits.download': '`{part}` downloads from the network: the person must allow it, and did not.';
10
12
  readonly 'limits.unsure.mention': 'This command mentions `{mention}`, and the studio couldn’t tell if it runs it: the person must allow it, and did not.';
11
13
  readonly 'limits.unsure.pattern': 'This command uses a pattern that could reach `{mention}`; the studio couldn’t tell: the person must allow it, and did not. Name the files you need.';
@@ -6,6 +6,8 @@ export const en = {
6
6
  'limits.settings': '`{part}` is not allowed here: production settings stay with a person.',
7
7
  'limits.publish': '`{part}` is not allowed here: publishing a package stays with a person, from their own terminal.',
8
8
  'limits.release': '`{part}` is not allowed here: publishing a release stays with a person, from their own terminal.',
9
+ 'limits.approval': '`{part}` is not allowed here: approval records are written only by the studio, when a person approves.',
10
+ 'limits.commit': '`{part}` is not allowed here: on Autopilot the studio saves a design step’s work; the agent makes no commit.',
9
11
  'limits.download': '`{part}` downloads from the network: the person must allow it, and did not.',
10
12
  'limits.unsure.mention': 'This command mentions `{mention}`, and the studio couldn’t tell if it runs it: the person must allow it, and did not.',
11
13
  'limits.unsure.pattern': 'This command uses a pattern that could reach `{mention}`; the studio couldn’t tell: the person must allow it, and did not. Name the files you need.',
@@ -5,6 +5,8 @@ export const es = {
5
5
  'limits.settings': '`{part}` no está permitido aquí: los ajustes de producción quedan en manos de una persona.',
6
6
  'limits.publish': '`{part}` no está permitido aquí: publicar un paquete queda en manos de una persona, desde su propia terminal.',
7
7
  'limits.release': '`{part}` no está permitido aquí: publicar una versión queda en manos de una persona, desde su propia terminal.',
8
+ 'limits.approval': '`{part}` no está permitido aquí: los registros de aprobación solo los escribe el estudio, cuando una persona aprueba.',
9
+ 'limits.commit': '`{part}` no está permitido aquí: en Piloto automático el estudio guarda el trabajo de un paso de diseño; el agente no hace commits.',
8
10
  'limits.download': '`{part}` descarga de la red: la persona debe permitirlo, y no lo hizo.',
9
11
  'limits.unsure.mention': 'Este comando menciona `{mention}` y el estudio no pudo saber si lo ejecuta: la persona debe permitirlo, y no lo hizo.',
10
12
  'limits.unsure.pattern': 'Este comando usa un patrón que podría llegar a `{mention}`; el estudio no pudo saberlo: la persona debe permitirlo, y no lo hizo. Nombra los archivos que necesitas.',
@@ -1,20 +1,27 @@
1
1
  /**
2
2
  * The limits every turn keeps at every level, "Never ask" included: no reading folders of sign-ins
3
3
  * or keys, no deploy, no production settings, no `git push`, and no network download without a
4
- * person's click, and no publishing a package or a release. The studio's hook (limits-hook.ts) runs this before each tool call; the
5
- * permission mode never decides them. Plain Node only: the hook runs it without the CLI.
4
+ * person's click, no publishing a package or a release, and no shell write into the approval
5
+ * records (`prototype/versions/`); a design turn on Autopilot makes no commit either. The
6
+ * studio's hook (limits-hook.ts) runs this before each tool call; the permission mode never
7
+ * decides them. Plain Node only: the hook runs it without the CLI.
6
8
  */
7
9
  import { relative, resolve } from 'node:path';
10
+ import { folderWrite } from './approval-folders.js';
11
+ import { approvalText } from './approval-text.js';
12
+ import { approvalWrite } from './approval-writes.js';
8
13
  import { commandParts, ESCAPE, partWords, programName, } from './command-parts.js';
9
14
  import { EXPRESSIONS, wrappedScripts } from './command-wrappers.js';
15
+ import { commitText, commitWords, designAutopilot, designWork, } from './commit-limits.js';
10
16
  import { designDelete } from './design-deletes.js';
17
+ import { subcommand, subcommandAt } from './git-words.js';
11
18
  import { mentionedLimit } from './limit-mentions.js';
12
19
  import { patternReach } from './limit-patterns.js';
13
- import { en } from './limits.en.js';
14
- import { es } from './limits.es.js';
20
+ import { limitReason, limitText } from './limit-text.js';
15
21
  import { publishLimit } from './publish-limits.js';
16
22
  import { holdsSecrets } from './secret-folders.js';
17
23
  import { readsStdin } from './stdin-shells.js';
24
+ export { limitReason, limitText, refusalLimit } from './limit-text.js';
18
25
  const SHELLS = new Map([
19
26
  ['Bash', 'bash'],
20
27
  ['PowerShell', 'powershell'],
@@ -52,28 +59,6 @@ export function secretPath(path, cwd) {
52
59
  }
53
60
  /** A word worth reading as a path: it has a separator, or starts like a hidden or home folder. */
54
61
  const pathLike = (word) => /[\\/]/.test(word) || /^[.~]/.test(word);
55
- // Git's options before the subcommand that take the next word as their value.
56
- const VALUED = new Set([
57
- '-C',
58
- '-c',
59
- '--git-dir',
60
- '--work-tree',
61
- '--namespace',
62
- '--super-prefix',
63
- '--config-env',
64
- '--attr-source',
65
- ]);
66
- /** The first word after `from` that is not an option (or an option's value), and its index. */
67
- function subcommandAt(words, from) {
68
- for (let index = from; index < words.length; index++) {
69
- const word = words[index];
70
- if (VALUED.has(word))
71
- index++;
72
- else if (!word.startsWith('-'))
73
- return { name: word.toLowerCase(), at: index };
74
- }
75
- }
76
- const subcommand = (words, from) => subcommandAt(words, from)?.name;
77
62
  /** A commit's or tag's message is words, not a command or a path: `git commit -m "…"`. */
78
63
  function withoutMessages(words) {
79
64
  const git = words.findIndex((word) => programName(word) === 'git');
@@ -83,7 +68,7 @@ function withoutMessages(words) {
83
68
  const at = sub.at;
84
69
  return words.filter((_, index) => index <= at || !/^(?:-[A-Za-z]*m|--message)$/.test(words[index - 1] ?? ''));
85
70
  }
86
- function wordsLimit(words, cwd) {
71
+ function wordsLimit(words, cwd, turn) {
87
72
  const names = words.map(programName);
88
73
  const checked = withoutMessages(words);
89
74
  if (checked.some((word) => pathLike(word) && secretPath(word, cwd)))
@@ -93,7 +78,9 @@ function wordsLimit(words, cwd) {
93
78
  const git = names.indexOf('git');
94
79
  // `git send-pack` is the plumbing under `git push`.
95
80
  const sub = git >= 0 ? subcommand(words, git + 1) : undefined;
96
- if (sub === 'push' || sub === 'send-pack')
81
+ // `git subtree push` pushes too.
82
+ const subtreePush = sub === 'subtree' && subcommand(words, words.indexOf('subtree', git) + 1) === 'push';
83
+ if (sub === 'push' || sub === 'send-pack' || subtreePush)
97
84
  return { decision: 'deny', kind: 'push' };
98
85
  const ape = names.indexOf('ape');
99
86
  if (ape >= 0) {
@@ -105,6 +92,10 @@ function wordsLimit(words, cwd) {
105
92
  const published = publishLimit(checked);
106
93
  if (published)
107
94
  return { decision: 'deny', kind: published };
95
+ if (approvalWrite(checked, cwd) || (designWork(turn) && folderWrite(checked, cwd)))
96
+ return { decision: 'deny', kind: 'approval' };
97
+ if (designAutopilot(turn) && commitWords(words))
98
+ return { decision: 'deny', kind: 'commit' };
108
99
  if (checked.some((word) => DOWNLOADS.test(word)))
109
100
  return { decision: 'ask', kind: 'download' };
110
101
  // `certutil -urlcache` fetches a URL; its other uses read local files.
@@ -118,7 +109,7 @@ function wordsLimit(words, cwd) {
118
109
  function partLimits(part, check, shell, depth) {
119
110
  const raw = partWords(part);
120
111
  const plain = partWords(part, ESCAPE[shell]);
121
- const own = wordsLimit(raw, check.cwd) ?? wordsLimit(plain, check.cwd);
112
+ const own = wordsLimit(raw, check.cwd, check.turn) ?? wordsLimit(plain, check.cwd, check.turn);
122
113
  if (readsStdin(plain))
123
114
  check.unsure ??= 'stdin';
124
115
  if (plain.some((word) => EXPRESSIONS.has(programName(word))))
@@ -132,7 +123,14 @@ function partLimits(part, check, shell, depth) {
132
123
  if (check.seen.has(key))
133
124
  return [];
134
125
  check.seen.add(key);
135
- return commandLimits(script, check, inside, depth + 1);
126
+ // A handed-on script's text is read too: an encoded one never showed it in the command.
127
+ const text = fallback(script, inside, check.cwd, check.turn);
128
+ if (text?.decision === 'deny')
129
+ return [{ ...text, part }];
130
+ return [
131
+ ...(text ? [{ ...text, part }] : []),
132
+ ...commandLimits(script, check, inside, depth + 1),
133
+ ];
136
134
  });
137
135
  return [...(own ? [{ ...own, part }] : []), ...inner];
138
136
  }
@@ -143,16 +141,40 @@ function commandLimits(command, check, shell, depth = 0) {
143
141
  }
144
142
  return commandParts(command, shell, check).flatMap((part) => partLimits(part, check, shell, depth));
145
143
  }
144
+ /**
145
+ * The text fallbacks for a write into the approval records (refused, or asked when every part
146
+ * only reads) and a design turn's commit on Autopilot (asked).
147
+ */
148
+ function fallback(command, shell, cwd, turn) {
149
+ const ask = (mention) => ({
150
+ decision: 'ask',
151
+ kind: 'unsure',
152
+ part: command,
153
+ unsure: 'mention',
154
+ mention,
155
+ });
156
+ const approval = approvalText(command, shell, cwd, designWork(turn));
157
+ if (approval === 'deny')
158
+ return { decision: 'deny', kind: 'approval', part: command };
159
+ if (approval)
160
+ return ask('prototype/versions');
161
+ const commit = designAutopilot(turn) ? commitText(command, shell) : undefined;
162
+ if (commit === 'deny')
163
+ return { decision: 'deny', kind: 'commit', part: command };
164
+ if (commit)
165
+ return ask('git commit');
166
+ }
146
167
  /**
147
168
  * A shell command's first limit: what the parse refuses, then what it asks; when it found
148
169
  * neither, a reading it could not follow, or a limit the text still mentions, asks the person.
149
170
  */
150
- function shellLimit(command, cwd, shell) {
151
- const check = { cwd, steps: 0, until: Date.now() + TIME_CAP, seen: new Set() };
171
+ function shellLimit(command, cwd, shell, turn) {
172
+ const check = { cwd, turn, steps: 0, until: Date.now() + TIME_CAP, seen: new Set() };
152
173
  if (command.length > TEXT_CAP)
153
174
  check.unsure = 'budget';
154
175
  else {
155
- const limits = commandLimits(command, check, shell);
176
+ const text = fallback(command, shell, cwd, turn);
177
+ const limits = [...commandLimits(command, check, shell), ...(text ? [text] : [])];
156
178
  const found = limits.find((limit) => limit.decision === 'deny') ?? limits[0];
157
179
  if (found)
158
180
  return found;
@@ -171,12 +193,15 @@ function shellLimit(command, cwd, shell) {
171
193
  ...(mention ? { mention } : {}),
172
194
  };
173
195
  }
174
- /** The first limit a tool call crosses, refusals before asks; nothing when it crosses none. */
175
- export function crossedLimit(tool, input, cwd) {
196
+ /**
197
+ * The first limit a tool call crosses, refusals before asks; nothing when it crosses none. The
198
+ * turn, when known, adds the limits only some turns keep (a design turn's commit on Autopilot).
199
+ */
200
+ export function crossedLimit(tool, input, cwd, turn) {
176
201
  const fields = (input ?? {});
177
202
  const shell = SHELLS.get(tool);
178
203
  if (shell) {
179
- return shellLimit(typeof fields.command === 'string' ? fields.command : '', cwd, shell);
204
+ return shellLimit(typeof fields.command === 'string' ? fields.command : '', cwd, shell, turn);
180
205
  }
181
206
  for (const field of fileFields(tool)) {
182
207
  const value = fields[field];
@@ -190,33 +215,12 @@ export function crossedLimit(tool, input, cwd) {
190
215
  if (tool === 'WebFetch' && typeof fields.url === 'string')
191
216
  return { decision: 'ask', kind: 'download', part: fields.url };
192
217
  }
193
- const catalogs = { en, es };
194
- const REFUSED = ['secrets', 'deploy', 'push', 'settings', 'publish', 'release'];
195
- /**
196
- * The limit a refused call's result names: the hook's own sentence for it, in either language,
197
- * came back as the result. Nothing when it names none.
198
- */
199
- export function refusalLimit(text) {
200
- return REFUSED.find((kind) => Object.values(catalogs).some((words) => text.includes(words[`limits.${kind}`].replace('`{part}`', ''))));
201
- }
202
- /** The agent's words in the turn's language (LANG), with `{name}` values filled in. */
203
- export function limitText(key, values = {}) {
204
- const locale = (process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || 'en')
205
- .slice(0, 2)
206
- .toLowerCase();
207
- const words = catalogs[locale === 'es' ? 'es' : 'en'];
208
- return words[key].replace(/\{(\w+)\}/g, (_, name) => values[name] ?? '');
209
- }
210
- /** The sentence the agent reads for a crossed limit: it names the refused part. */
211
- export const limitReason = (limit) => limit.kind === 'unsure'
212
- ? limitText(`limits.unsure.${limit.unsure ?? 'mention'}`, { mention: limit.mention ?? '' })
213
- : limitText(`limits.${limit.kind}`, { part: limit.part.slice(0, 200) });
214
218
  /**
215
219
  * The hook's answer to one call: a crossed limit, a design turn's delete inside `design/` or
216
220
  * `prototype/` (allowed), or nothing. A call it cannot read is refused, so a broken call never
217
221
  * slips past the limits.
218
222
  */
219
- export function hookAnswer(text, work) {
223
+ export function hookAnswer(text, work, level = '') {
220
224
  let call;
221
225
  try {
222
226
  call = JSON.parse(text);
@@ -226,7 +230,7 @@ export function hookAnswer(text, work) {
226
230
  }
227
231
  const tool = typeof call.tool_name === 'string' ? call.tool_name : '';
228
232
  const cwd = typeof call.cwd === 'string' && call.cwd ? call.cwd : process.cwd();
229
- const limit = crossedLimit(tool, call.tool_input, cwd);
233
+ const limit = crossedLimit(tool, call.tool_input, cwd, { work, level });
230
234
  if (limit)
231
235
  return { decision: limit.decision, reason: limitReason(limit) };
232
236
  const command = call.tool_input?.command;
@@ -24,6 +24,17 @@ export const LIMIT_COMMANDS = [
24
24
  'pnpm publish',
25
25
  'yarn publish',
26
26
  'yarn npm publish',
27
+ 'bun publish',
28
+ 'lerna publish',
29
+ 'changeset publish',
30
+ 'npx lerna publish',
31
+ 'npx changeset publish',
32
+ 'pnpm lerna publish',
33
+ 'pnpm changeset publish',
34
+ 'pnpm exec lerna publish',
35
+ 'pnpm exec changeset publish',
36
+ 'yarn lerna publish',
37
+ 'yarn changeset publish',
27
38
  'gh release create',
28
39
  'gh release new',
29
40
  'gh release upload',
@@ -1,15 +1,17 @@
1
1
  /**
2
2
  * The publishing commands the limits refuse: a package (`npm publish`, and npm's shortened names
3
- * down to `npm pu`; `pnpm publish`, `yarn publish`, `yarn npm publish`) and a release
4
- * (`gh release create|new|upload|edit|delete`, and `delete-asset`). Every package manager or `gh`
5
- * named in a part is read, so `npx npm publish`, `pnpm exec npm publish` and `env X=1 npm publish`
6
- * count too. Before the subcommand, the options each tool takes a value for skip that value
3
+ * down to `npm pu`; `pnpm publish`, `yarn publish`, `yarn npm publish`, `bun publish`,
4
+ * `lerna publish`, `changeset publish`) and a release (`gh release create|new|upload|edit|delete`,
5
+ * and `delete-asset`; `gh api` calls that create or change one, gh-api-limits.ts). Every package
6
+ * manager or `gh` named in a part is read, so `npx npm publish`, `pnpm exec changeset publish` and
7
+ * `env X=1 npm publish` count too. Before the subcommand, the options each tool takes a value for skip that value
7
8
  * (`npm --registry x publish`, `gh -R owner/repo release create`); after any other option the next
8
9
  * word is the subcommand, so `pnpm --filter publish build` runs (a shape the parse does not follow
9
10
  * still goes to the card through the text fallback). Asking only for help (`pnpm publish --help`)
10
11
  * runs. Plain Node only: the hook runs it.
11
12
  */
12
13
  import { programName } from './command-parts.js';
14
+ import { GH_API_VALUED, releaseCall } from './gh-api-limits.js';
13
15
  /** The options before the subcommand that take the next word as their value, per tool. */
14
16
  const VALUED = {
15
17
  npm: new Set([
@@ -47,11 +49,14 @@ const VALUED = {
47
49
  '--publish-branch',
48
50
  ]),
49
51
  yarn: new Set(['--cwd', '--registry', '--otp', '--tag', '--access', '--modules-folder']),
52
+ bun: new Set(['--cwd', '--registry', '--otp', '--tag', '--access', '--config', '-c']),
53
+ lerna: new Set(['--loglevel', '--concurrency']),
54
+ changeset: new Set(['--cwd']),
50
55
  gh: new Set(['-R', '--repo', '--hostname']),
51
56
  };
52
57
  /** Every option above, for the text fallback: their values are values, not a subcommand. */
53
58
  export const VALUED_OPTIONS = [
54
- ...new Set(Object.values(VALUED).flatMap((options) => [...options])),
59
+ ...new Set([...Object.values(VALUED).flatMap((options) => [...options]), ...GH_API_VALUED]),
55
60
  ];
56
61
  const RELEASE = new Set(['create', 'new', 'upload', 'edit', 'delete', 'delete-asset']);
57
62
  /** npm resolves a shortened command name: from `pu`, the only name it can mean is `publish`. */
@@ -59,10 +64,18 @@ const PUBLISHES = {
59
64
  npm: (word) => word.length >= 2 && 'publish'.startsWith(word),
60
65
  pnpm: (word) => word === 'publish',
61
66
  yarn: (word) => word === 'publish',
67
+ bun: (word) => word === 'publish',
68
+ lerna: (word) => word === 'publish',
69
+ changeset: (word) => word === 'publish',
62
70
  };
63
71
  const HELP = new Set(['--help', '-h']);
64
- /** The program a word names, without a pinned version (`npm@10`, `pnpm@latest`). */
65
- const toolName = (word) => programName(word).replace(/(?<=.)@[^@]*$/, '');
72
+ /**
73
+ * The program a word names, without a pinned version (`npm@10`, `pnpm@latest`); the changesets
74
+ * package run by its name (`npx @changesets/cli publish`) is its `changeset` command.
75
+ */
76
+ const toolName = (word) => /^@changesets\/cli(?:@[^@]*)?$/i.test(word)
77
+ ? 'changeset'
78
+ : programName(word).replace(/(?<=.)@[^@]*$/, '');
66
79
  /** The index of the subcommand after `from` when `wanted` accepts it; -1 otherwise. */
67
80
  function subcommandIs(words, from, valued, wanted) {
68
81
  for (let index = from; index < words.length; index++) {
@@ -89,6 +102,9 @@ export function publishLimit(words) {
89
102
  if (name !== 'gh')
90
103
  continue;
91
104
  const valued = VALUED.gh;
105
+ const api = subcommandIs(words, index + 1, valued, (word) => word === 'api');
106
+ if (api >= 0 && releaseCall(words, api + 1))
107
+ return 'release';
92
108
  const release = subcommandIs(words, index + 1, valued, (word) => word === 'release');
93
109
  const at = release < 0 ? -1 : subcommandIs(words, release + 1, valued, (w) => RELEASE.has(w));
94
110
  if (at >= 0 && !helpOnly(words, at))
@@ -4,8 +4,13 @@ import type { Active } from './turn-state.ts';
4
4
  export interface TurnGuard {
5
5
  level: Level;
6
6
  neverAsk: boolean;
7
- /** Settings with the limits hook; absent on planning below Autopilot, which disables every hook. */
7
+ /**
8
+ * Settings with the limits hook; absent on planning below Autopilot, which disables every hook,
9
+ * and when the host's launcher starts the turn (host-launched.ts): the host applies the limits.
10
+ */
8
11
  settings?: string;
12
+ /** The host's launcher starts this turn: no settings, MCP config or prompt tool, ever. */
13
+ host?: boolean;
9
14
  /** The MCP config that serves the permission prompt tool; absent where `settings` is. */
10
15
  mcp?: string;
11
16
  /** The rules this launch passed to `--allowedTools`, filled by the arguments. */
@@ -22,6 +27,7 @@ export declare function launchArguments(args: readonly string[]): () => void;
22
27
  * Opens a Claude launch's guard: the level and "Never ask" read now, and the limits hook in a
23
28
  * settings file and the permission tool's channel, in a folder of the launch's own that closes
24
29
  * with it. The hook runs before every call at every level, Never ask included; only planning below
25
- * Autopilot, which runs `dontAsk` with every hook off, gets neither (deny rules hold its limits).
30
+ * Autopilot, which runs `dontAsk` with every hook off, gets neither (deny rules hold its limits),
31
+ * and no turn of a product whose host launches its turns, as in 0.8.41 (the host applies them).
26
32
  */
27
33
  export declare function openTurnGuard(run: Active, root: string, save: () => void): TurnGuard;
@@ -3,6 +3,7 @@ import { tmpdir } from 'node:os';
3
3
  import { join } from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
5
  import { effectiveLevel, effectiveNeverAsk } from '../../agents-file.js';
6
+ import { hostLaunched } from './host-launched.js';
6
7
  import { askPerson } from './permission-ask.js';
7
8
  import { openPermissionChannel } from './permission-channel.js';
8
9
  import { isPlanning } from './permissions.js';
@@ -30,7 +31,8 @@ const script = (name) => {
30
31
  * Opens a Claude launch's guard: the level and "Never ask" read now, and the limits hook in a
31
32
  * settings file and the permission tool's channel, in a folder of the launch's own that closes
32
33
  * with it. The hook runs before every call at every level, Never ask included; only planning below
33
- * Autopilot, which runs `dontAsk` with every hook off, gets neither (deny rules hold its limits).
34
+ * Autopilot, which runs `dontAsk` with every hook off, gets neither (deny rules hold its limits),
35
+ * and no turn of a product whose host launches its turns, as in 0.8.41 (the host applies them).
34
36
  */
35
37
  export function openTurnGuard(run, root, save) {
36
38
  const guard = {
@@ -41,7 +43,9 @@ export function openTurnGuard(run, root, save) {
41
43
  close: () => { },
42
44
  };
43
45
  live.add(guard);
44
- if (isPlanning(run.chat.work) && guard.level !== 'auto') {
46
+ if (hostLaunched(root))
47
+ guard.host = true;
48
+ if (guard.host || (isPlanning(run.chat.work) && guard.level !== 'auto')) {
45
49
  guard.close = () => live.delete(guard);
46
50
  return guard;
47
51
  }
@@ -64,7 +68,8 @@ export function openTurnGuard(run, root, save) {
64
68
  const channel = openPermissionChannel((call) => askPerson(turn, call, closed.signal));
65
69
  guard.settings = join(folder, 'settings.json');
66
70
  guard.mcp = join(folder, 'mcp.json');
67
- const command = `"${node}" "${hook}" ${run.chat.work}`;
71
+ // The work and the level are code-owned words: the hook holds some limits only on some turns.
72
+ const command = `"${node}" "${hook}" ${run.chat.work} ${guard.level}`;
68
73
  writeFileSync(guard.settings, JSON.stringify({
69
74
  // Flag settings outrank the product's own, so a product file cannot switch the hook off.
70
75
  disableAllHooks: false,