@buffcore/cli 0.8.43 → 0.8.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/commands/ui/chat/approval-folders.d.ts +20 -0
  3. package/dist/commands/ui/chat/approval-folders.js +134 -0
  4. package/dist/commands/ui/chat/approval-text.d.ts +11 -0
  5. package/dist/commands/ui/chat/approval-text.js +69 -0
  6. package/dist/commands/ui/chat/approval-writes.d.ts +32 -0
  7. package/dist/commands/ui/chat/approval-writes.js +179 -0
  8. package/dist/commands/ui/chat/claude-permissions.d.ts +4 -4
  9. package/dist/commands/ui/chat/claude-permissions.js +32 -4
  10. package/dist/commands/ui/chat/codex-idle.d.ts +1 -1
  11. package/dist/commands/ui/chat/commit-limits.d.ts +36 -0
  12. package/dist/commands/ui/chat/commit-limits.js +164 -0
  13. package/dist/commands/ui/chat/fresh-critique.js +3 -1
  14. package/dist/commands/ui/chat/fresh-launch.d.ts +5 -0
  15. package/dist/commands/ui/chat/fresh-launch.js +7 -4
  16. package/dist/commands/ui/chat/fresh.js +7 -1
  17. package/dist/commands/ui/chat/gh-api-limits.d.ts +14 -0
  18. package/dist/commands/ui/chat/gh-api-limits.js +74 -0
  19. package/dist/commands/ui/chat/git-words.d.ts +10 -0
  20. package/dist/commands/ui/chat/git-words.js +26 -0
  21. package/dist/commands/ui/chat/host-launched.d.ts +11 -0
  22. package/dist/commands/ui/chat/host-launched.js +35 -0
  23. package/dist/commands/ui/chat/limit-mentions.js +16 -2
  24. package/dist/commands/ui/chat/limit-text.d.ts +15 -0
  25. package/dist/commands/ui/chat/limit-text.js +36 -0
  26. package/dist/commands/ui/chat/limits-hook.js +2 -2
  27. package/dist/commands/ui/chat/limits.d.ts +7 -12
  28. package/dist/commands/ui/chat/limits.en.d.ts +2 -0
  29. package/dist/commands/ui/chat/limits.en.js +2 -0
  30. package/dist/commands/ui/chat/limits.es.js +2 -0
  31. package/dist/commands/ui/chat/limits.js +63 -59
  32. package/dist/commands/ui/chat/planning-limits.js +11 -0
  33. package/dist/commands/ui/chat/publish-limits.js +23 -7
  34. package/dist/commands/ui/chat/turn-guard.d.ts +8 -2
  35. package/dist/commands/ui/chat/turn-guard.js +8 -3
  36. package/dist/commands/ui/index.d.ts +42 -0
  37. package/dist/commands/ui/index.js +14 -2
  38. package/dist/commands/ui/routes.d.ts +2 -0
  39. package/dist/commands/ui/server-options.js +1 -0
  40. package/dist/commands/ui/server-request.js +5 -0
  41. package/dist/commands/ui/server.d.ts +7 -0
  42. package/dist/commands/ui/server.js +3 -0
  43. package/dist/commands/ui/studio-routes.d.ts +1 -0
  44. package/dist/commands/ui/studio-routes.js +3 -1
  45. package/dist/commands/ui/studio-state.d.ts +1 -0
  46. package/dist/ui/page.js +78 -69
  47. package/docs/PROTOTYPE.md +11 -0
  48. package/docs/WORKBENCH.md +11 -2
  49. package/package.json +11 -11
package/CHANGELOG.md CHANGED
@@ -4,6 +4,21 @@ One section per release (a git tag). **Upgrade notes** list anything that breaks
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## v0.8.44 (2026-12-02)
8
+
9
+ - A host whose own trusted launcher starts the agent's turns can say so: `createUiServer({ hostLaunched: true })`, or `APE_HOST_LAUNCHED=1` in the environment of `ape ui` (exactly `1`). Every Claude Code turn (coding, Build, design, validation, tests, fixes, planning on Autopilot) then launches exactly as a 0.8.41 turn did: no per-turn `--settings` file with the limits hook, no `--mcp-config` with the permission tool, no `--permission-prompt-tool` and no per-turn socket; `acceptEdits`, or `dontAsk` with hooks off for planning, at every level (never `auto` or `bypassPermissions`, Autopilot and Never ask included), with 0.8.41's allow and deny lists. Fresh turns (the review before Save and the critique) follow it: hooks off through the inline `--settings` JSON, no settings file and no `--setting-sources=`. Settings says once that the host starts the agents and applies their limits (English and Spanish), and the studio state gains an optional `hostLaunched`. Off by default: nothing changes for a host that passes nothing.
10
+
11
+ **Upgrade notes** (hosts that build their own studio server): with `hostLaunched` on, the studio's limits hook, its permission card and its later deny rules are not in the turns, so your launcher must enforce everything the hook does, through every wrapper and shell it reads: the limit commands (`git push`; downloads with `curl`, `wget`, `iwr`, `irm`, `Invoke-WebRequest`, `Invoke-RestMethod` and `Start-BitsTransfer`, which the hook holds for the person; `ape deploy` and `ape server deploy` however started; `npm publish` with npm's short forms `npm pu`, `npm pub`, `npm publ`, `npm publi` and `npm publis`, `pnpm publish`, `yarn publish` and `yarn npm publish`; `gh release create`, `new`, `upload`, `edit` and `delete`), reads and writes of production settings files (`.env.production`, `.env.prod*`, `.env.staging*`) and of the secret folders (`.ssh`, `.gnupg`, `.aws`, `.azure`, `.kube`, `.docker`, `.gcloud`, `.password-store`, `secrets`), WebFetch, and the calls it refuses when unsure: a command it cannot read or that is too long or too deeply nested, a here-document whose end line never comes, a shell or interpreter given its script on standard input, `Invoke-Expression` (`iex`), and a file pattern or mention that could reach a limit. The source of truth, which later releases add to, is the limits files in `packages/cli/src/commands/ui/chat/`: `limits.ts`, `planning-limits.ts`, `publish-limits.ts`, `limit-patterns.ts`, `limit-mentions.ts`, `stdin-shells.ts` and `secret-folders.ts`. Your launcher also checks the turn's arguments and decides which settings files a turn loads (the person's and the product's allow rules widen what a fresh turn's `dontAsk` runs unless it keeps them out). The mode belongs to the product folder of the `runner` you pass (`runner.cwd`), one mode per folder (the last server created for it decides), and ends when the server closes; build `ChatEngine` and `FreshLooks` on that same folder. `APE_HOST_LAUNCHED` counts only from the environment `ape ui` starts with, never from the product's `.env`.
12
+ - The studio's chat box empties the moment Send (or Enter) is pressed; the words show in the chat as sending, and a refused or interrupted send puts them back in the box, with the reason under it, never losing them: anything typed meanwhile follows them after a blank line.
13
+ - Play on the Journeys page opens the Prototype with that journey selected at its first step, once the app lists it (by its key, or else by its planned name).
14
+ - The Prototype preview's step bar (Back, the step and its caption, Next) sits under the device frame at every device and width, no longer over the app.
15
+ - Stepping through a journey, choosing one and choosing sample data no longer reload the app: the studio tells the running prototype home what to show by an `ape:prototype:show` message on the private port its hello opened, and the home answers the new step's caption on that port. A home that reloads itself gets the current choice again; one that does not say it plays (`ape:prototype:player`) is reloaded at each step, as before. The app reloads only when its address, the language or the mode changes. The message carries only a journey key and step, or a data state, and the studio still takes nothing from the app but its journey list, liveness and that caption.
16
+
17
+ **Upgrade notes** (every product): keep `@buffcore/app-shell` and `@buffcore/admin-shell` on the same release (`ape upgrade` does); an older prototype home still plays, reloading at each step.
18
+ - The studio's scroll bars are thin and drawn in the theme's colors, light and dark, in every panel inside the studio frame.
19
+ - An agent cannot make its own approval from the shell, "Never ask" included. A shell command that could write into the approval records, `prototype/versions/`, is refused at every level: a redirect into the folder (`>`, `>>`, `&>`, `2>`, `>|`), or any program that names a path in it other than a read (`cp`, `mv`, `tee`, `sed -i`, `node -e`, `python -c`, `git checkout … --`, `Set-Content`, `Out-File` and the rest), read against the shell's folder with `..`, case and patterns counted; on design and validation turns at any level, and planning and loop turns on Autopilot, so is a program that writes the paths it names aimed at a folder that holds the records, `prototype` taking only a single file copied in (`cp design/logo.svg prototype/`), and a patch or archive (`git apply`, `git am`, `patch`, `Expand-Archive`), with `$PWD`, `~+`, `$OLDPWD` and `(Get-Location)` read as folders (coding, tests and fixes turns keep writing their own tree; `rm -rf prototype`, `cp -r x/. prototype/`, `cp x .`, `git checkout <ref> -- .`, `find prototype … -delete` or `-exec`, `tar -x` or `unzip` into the shell's folder, `Copy-Item -Recurse … prototype`, `ls prototype | xargs rm`, `gci -r prototype | Set-Content`). A command whose text names both folders and looks like a write is refused when any part of it is more than a read, and goes to the card when every part only reads. A design or validation turn on Autopilot, and a planning or loop turn on Autopilot, (or one whose level the hook was not told) makes no commit and moves no branch: `git commit`, `commit-tree`, `update-ref`, `merge`, `cherry-pick`, `revert`, `rebase`, `am`, `pull`, `hash-object`, `fast-import`, `stash` (but `list` and `show`), `reset` to a commit, `branch -f`/`-M`/`-C`, `checkout -B`, `switch -C`, `fetch` into a branch, `git subtree add|merge|pull` and `split --rejoin`, and git with a configuration set anywhere in the command (`-c alias.…`, `-c include.path=…`, `export HOME=…`, `$env:GIT_CONFIG_GLOBAL=…`) beside a subcommand that commits or is not git's own are refused there (`export HOME=x; git log` runs), a git subcommand that is not git's own (an alias such as `git ci`) goes to the card, and a shape the parse cannot follow (`$g commit`) goes to the card; coding turns still commit in their own change tree. Reads still run, their output redirected anywhere else too (`cat`, `ls`, `grep`, `head`, `tail`, `wc`, `sed -n`, `awk`, `sort`, `find`, `git log --grep merge`, `git show`, `git diff`, `Get-Content`). The limit card names each: **Writing an approval record**, **Committing from a design step on Autopilot**; the chat contract's limit gains `approval` and `commit`. The limits hook now takes the turn's level after its work (`limits-hook.ts <work> <level>`). On those turns a write the parse cannot place goes to the card: a write after a `cd` in the same command, a write to a `$variable` path, `bsdtar -x` and `7z x … -o…`; `sed` counts as a pipe writer only with `-i`, and `%`/`ForEach-Object` only when its block holds a writer. Not caught (known limits): a write that reaches the folder through a `cd` earlier in the same command and is otherwise only reads (it goes to the card); a variable, an alias, a function or a symbolic link set in an earlier call (`d=prototype/versions` then `cp x $d`, `ln -s prototype/versions v` then `cp x v/`); a path built from strings (`printf`, string joins in `node -e` or `python -c`); a script file written earlier and run later; a commit through an alias already in the product's own git configuration (it goes to the card), or through a tool other than git (a library from `node -e`); and OpenCode and planning turns below Autopilot, which use prefix rules and have none for these writes.
20
+ - More publishing commands are limits at every level, "Never ask" included: `bun publish`, `lerna publish` and `changeset publish` (also as `npx @changesets/cli publish`) are refused as publishing a package, and `gh api` calls that create or change a release (a method other than GET or HEAD on `repos/{owner}/{repo}/releases`, or fields or a body with no method named, an asset upload included) as publishing a release, through every wrapper the limits read. `gh api` reads of releases (`gh api repos/o/r/releases`, `-X GET … -f per_page=5`), `changeset version`, `lerna run` and `bun install` still run.
21
+
7
22
  ## v0.8.43 (2026-12-02)
8
23
 
9
24
  - Publishing is a limit at every level, "Never ask" included: `npm publish` (and the short names npm accepts, `npm pu` to `npm publis`), `pnpm publish`, `yarn publish`, `yarn npm publish` and `gh release create|new|upload|edit|delete` are refused through every wrapper the limits read; `npm view`, `gh release list` and other reads still run, and a command that only asks for `--help` runs. A command a limit refused now shows a card in the step's chat, **This can't be allowed here**, naming the limit and the command, with **Copy the command** and no Allow (Claude Code turns; the card is marked from the hook's own refusal). The chat contract's refused event gains an optional `limit`. Not caught: `bun publish`, `lerna publish`, `changeset publish` and `gh api` release calls.
@@ -0,0 +1,20 @@
1
+ /**
2
+ * On the turns that write the product's own folder (design and validation at any level;
3
+ * planning and loop on Autopilot), a write aimed at a folder that holds the approval records is
4
+ * refused as well as one into them: `rm -rf prototype`, `cp -r x/. prototype/`, `cp x .`,
5
+ * `git checkout <ref> -- .`, `find prototype … -delete`, `tar -x` or `unzip` into the shell's
6
+ * folder, `Copy-Item -Recurse … prototype`. `prototype` itself takes a single file copied in
7
+ * (`cp design/logo.svg prototype/`); a whole folder copied, moved or linked there could become
8
+ * `prototype/versions`. A patch or an archive that could reach anywhere (`git apply`, `git am`,
9
+ * `patch`, `Expand-Archive`) is refused there outright. Plain Node only: the hook runs it.
10
+ */
11
+ /** True when a part writes into, or is aimed at, a folder that holds the approval records. */
12
+ export declare function folderWrite(words: string[], cwd: string): boolean;
13
+ /**
14
+ * What a design turn's command could write that the parse cannot place, for the person's card:
15
+ * a write after a `cd` in the same command, a write to a `$variable` path, `bsdtar -x`, and
16
+ * `7z x … -o…` (its folder is fused to the option).
17
+ */
18
+ export declare function folderUnsure(parts: string[][]): boolean;
19
+ /** A word that names a folder holding the records (a pipe's source, for the fallback). */
20
+ export declare const holdsRecords: (word: string, cwd: string) => boolean;
@@ -0,0 +1,134 @@
1
+ /**
2
+ * On the turns that write the product's own folder (design and validation at any level;
3
+ * planning and loop on Autopilot), a write aimed at a folder that holds the approval records is
4
+ * refused as well as one into them: `rm -rf prototype`, `cp -r x/. prototype/`, `cp x .`,
5
+ * `git checkout <ref> -- .`, `find prototype … -delete`, `tar -x` or `unzip` into the shell's
6
+ * folder, `Copy-Item -Recurse … prototype`. `prototype` itself takes a single file copied in
7
+ * (`cp design/logo.svg prototype/`); a whole folder copied, moved or linked there could become
8
+ * `prototype/versions`. A patch or an archive that could reach anywhere (`git apply`, `git am`,
9
+ * `patch`, `Expand-Archive`) is refused there outright. Plain Node only: the hook runs it.
10
+ */
11
+ import { FIND_WRITES, GIT_TREE_WRITES, programAt, segmentsOf, TREE_WRITES, wordPaths, } from './approval-writes.js';
12
+ import { programName } from './command-parts.js';
13
+ import { subcommandAt } from './git-words.js';
14
+ /**
15
+ * How far above `prototype/versions` a path lies: 1 for `prototype`, 2 and more for the folders
16
+ * above (`.`, `..`, `/`); nothing when it holds no records. The records' folder is the one below
17
+ * the shell's folder, or the one the shell's folder lies in.
18
+ */
19
+ function heightAbove(path, cwd) {
20
+ const { base, segments, could } = segmentsOf(path, cwd);
21
+ const lower = base.map((segment) => segment.toLowerCase());
22
+ const at = lower.findIndex((name, i) => name === 'prototype' && lower[i + 1] === 'versions');
23
+ const folders = [[...base, 'prototype', 'versions']];
24
+ if (at >= 0)
25
+ folders.push(base.slice(0, at + 2));
26
+ if (lower.at(-1) === 'prototype')
27
+ folders.push([...base, 'versions']);
28
+ const heights = folders
29
+ .filter((folder) => segments.length < folder.length &&
30
+ segments.every((_, index) => could(index, folder[index])))
31
+ .map((folder) => folder.length - segments.length);
32
+ return heights.length ? Math.max(...heights) : undefined;
33
+ }
34
+ /** `tar` extracts: `-x…` anywhere, `x…` bundled as its first word, `--extract`, `--get`. */
35
+ const tarExtracts = (rest) => /^[a-zA-Z]*x[a-zA-Z]*$/.test(rest[0] ?? '') ||
36
+ rest.some((word) => /^(?:-[a-zA-Z]*x[a-zA-Z]*|--extract|--get)$/.test(word));
37
+ /** The part writes the paths it names: a writing program, git or find writing, `tar -x`. */
38
+ function writesPaths(name, words, at) {
39
+ const rest = words.slice(at + 1);
40
+ if (TREE_WRITES.has(name))
41
+ return true;
42
+ if (name === 'find')
43
+ return rest.some((word) => FIND_WRITES.test(word));
44
+ if (name === 'sed' || name === 'perl')
45
+ return rest.some((word) => /^(?:-[a-zA-Z]*i|--in-place)/.test(word));
46
+ if (name === 'git')
47
+ return GIT_TREE_WRITES.has(subcommandAt(words, at + 1)?.name ?? '');
48
+ if (name === 'tar')
49
+ return tarExtracts(rest);
50
+ if (name === '7z')
51
+ return /^[ex]$/i.test(rest[0] ?? '');
52
+ return name === 'unzip';
53
+ }
54
+ /** An archive unpacked into the shell's folder: `tar -x` without `-C`, `unzip` without `-d`. */
55
+ function unpacksHere(name, rest) {
56
+ if (name === 'tar')
57
+ return tarExtracts(rest) && !rest.some((word) => /^(?:-[a-zA-Z]*C|--directory)/.test(word));
58
+ if (name === '7z')
59
+ return /^[ex]$/i.test(rest[0] ?? '') && !rest.some((w) => /^-o/.test(w));
60
+ // `unzip -l`, `-t`, `-v` and `-Z` list or test, writing nothing.
61
+ return name === 'unzip' && !rest.some((word) => /^-(?:[a-zA-Z]*[ltvZ]|d)/.test(word));
62
+ }
63
+ /** A patch or an archive whose own contents say where it writes. */
64
+ function writesAnywhere(name, words, at) {
65
+ if (name === 'patch' || name === 'expand-archive')
66
+ return true;
67
+ if (name !== 'git')
68
+ return false;
69
+ const sub = subcommandAt(words, at + 1);
70
+ if (sub?.name === 'am')
71
+ return true;
72
+ // `git apply --check` (or `--stat`, `--numstat`, `--summary`) only reads the patch.
73
+ return (sub?.name === 'apply' &&
74
+ !words.slice(sub.at + 1).some((word) => /^--(?:check|stat|numstat|summary)$/.test(word)));
75
+ }
76
+ /** A single file copied in: `cp`, `copy` or `Copy-Item`, nothing recursive. */
77
+ function copiesOneFile(name, rest) {
78
+ if (name === 'cp')
79
+ return !rest.some((word) => /^(?:-[a-zA-Z]*[rRa]|--(?:recursive|archive))/.test(word));
80
+ if (['copy', 'copy-item', 'cpi'].includes(name))
81
+ return !rest.some((word) => /^-rec/i.test(word));
82
+ return false;
83
+ }
84
+ /** True when a part writes into, or is aimed at, a folder that holds the approval records. */
85
+ export function folderWrite(words, cwd) {
86
+ const at = programAt(words);
87
+ const name = programName(words[at] ?? '');
88
+ const rest = words.slice(at + 1);
89
+ if (writesAnywhere(name, words, at))
90
+ return true;
91
+ if (unpacksHere(name, rest))
92
+ return true;
93
+ if (!writesPaths(name, words, at))
94
+ return false;
95
+ const single = copiesOneFile(name, rest);
96
+ return rest.some((word) => wordPaths(word).some((path) => {
97
+ const height = heightAbove(path, cwd);
98
+ return height !== undefined && (height > 1 || !single);
99
+ }));
100
+ }
101
+ /** A write after `cd` (or `pushd`, `Set-Location`) in the same command: its folder is unknown. */
102
+ const MOVES_FOLDER = new Set([
103
+ 'cd',
104
+ 'pushd',
105
+ 'popd',
106
+ 'set-location',
107
+ 'sl',
108
+ 'push-location',
109
+ 'chdir',
110
+ ]);
111
+ /**
112
+ * What a design turn's command could write that the parse cannot place, for the person's card:
113
+ * a write after a `cd` in the same command, a write to a `$variable` path, `bsdtar -x`, and
114
+ * `7z x … -o…` (its folder is fused to the option).
115
+ */
116
+ export function folderUnsure(parts) {
117
+ let moved = false;
118
+ return parts.some((words) => {
119
+ const at = programAt(words);
120
+ const name = programName(words[at] ?? '');
121
+ const rest = words.slice(at + 1);
122
+ if (MOVES_FOLDER.has(name))
123
+ moved = true;
124
+ if (name === 'bsdtar')
125
+ return tarExtracts(rest);
126
+ if (name === '7z')
127
+ return /^[ex]$/i.test(rest[0] ?? '');
128
+ if (!writesPaths(name, words, at) && !writesAnywhere(name, words, at))
129
+ return false;
130
+ return moved || rest.some((word) => /\$(?!\()\{?\w/.test(word));
131
+ });
132
+ }
133
+ /** A word that names a folder holding the records (a pipe's source, for the fallback). */
134
+ export const holdsRecords = (word, cwd) => wordPaths(word).some((path) => heightAbove(path, cwd) !== undefined);
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The approval records' fallbacks, for what one part's words cannot show. A pipe that hands a
3
+ * folder holding the records to a program that writes what it is given (`gci -r prototype |
4
+ * Set-Content`, `ls prototype | xargs rm`) is refused. A command whose text names both folders
5
+ * and looks like a write (a writing program, or a redirect to a path that names a folder, a
6
+ * variable or a pattern) is refused when any of its parts is more than a read, and sent to the
7
+ * card when every part only reads (`cd prototype; echo x > versions/a`). Plain Node only.
8
+ */
9
+ import { type Shell } from './command-parts.ts';
10
+ /** What the approval fallbacks say of a command: refuse, ask the person, or nothing. */
11
+ export declare function approvalText(command: string, shell: Shell, cwd: string, folders?: boolean): 'deny' | 'ask' | undefined;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * The approval records' fallbacks, for what one part's words cannot show. A pipe that hands a
3
+ * folder holding the records to a program that writes what it is given (`gci -r prototype |
4
+ * Set-Content`, `ls prototype | xargs rm`) is refused. A command whose text names both folders
5
+ * and looks like a write (a writing program, or a redirect to a path that names a folder, a
6
+ * variable or a pattern) is refused when any of its parts is more than a read, and sent to the
7
+ * card when every part only reads (`cd prototype; echo x > versions/a`). Plain Node only.
8
+ */
9
+ import { folderUnsure, holdsRecords } from './approval-folders.js';
10
+ import { names, onlyReads, programAt, TREE_WRITES } from './approval-writes.js';
11
+ import { commandParts, partWords, programName } from './command-parts.js';
12
+ /** Programs that take the paths to write from a pipe: item cmdlets, `xargs`. */
13
+ const PIPED = new Set([...TREE_WRITES].filter((name) => !/^(?:tee|tee-object|out-file)$/.test(name)));
14
+ const EACH = new Set(['foreach-object', 'foreach', '%']);
15
+ /** A pipe's stage that writes what it is given: `sed -i`, a `%` block holding a writer. */
16
+ function pipeWriter(words) {
17
+ const at = programAt(words);
18
+ const name = programName(words[at] ?? '');
19
+ const rest = words.slice(at + 1);
20
+ if (name === 'sed')
21
+ return rest.some((word) => /^(?:-[a-zA-Z]*i|--in-place)/.test(word));
22
+ if (EACH.has(name))
23
+ return rest.some((word) => PIPED.has(programName(word.replace(/^[{(;]+/, ''))));
24
+ return PIPED.has(name);
25
+ }
26
+ /** The shell's folder named where a part's words cannot read it: `(Get-Location)`, `(pwd)`. */
27
+ const HERE = /\((?:get-location|gl|pwd)\)|\$\((?:pwd|get-location)\)/i;
28
+ /** A pipe from a folder holding the records into a program that writes what it is given. */
29
+ function pipedWrite(command, cwd, folders) {
30
+ return command.split(/\r?\n|;|&&|\|\|/).some((statement) => {
31
+ const stages = statement.split(/(?<!\|)\|(?!\|)/).map((stage) => partWords(stage));
32
+ return stages.some((words, index) => index > 0 &&
33
+ pipeWriter(words) &&
34
+ stages
35
+ .slice(0, index)
36
+ .some((earlier) => earlier.some((w) => names(w, cwd) || (folders && holdsRecords(w, cwd)))));
37
+ });
38
+ }
39
+ const PROTOTYPE = /(?<![\w.-])prototype(?![\w-])/i;
40
+ const VERSIONS = /(?<![\w.-])versions(?![\w.-])/i;
41
+ /** A redirect whose target names a folder, a variable or a pattern (not `/tmp/x`, `out.json`). */
42
+ const REDIRECT = /(?<![-=<>])>>?\|?(?![&=>])\s*(?:\S*(?:prototype|versions)|[$`*?{[%~])/i;
43
+ const WRITERS = new RegExp(`(?<![\\w.-])(?:${[
44
+ 'cp|mv|tee|dd|install|ln|rsync|touch|truncate|mkdir|rm|rmdir|unlink|tar|unzip|7z|patch',
45
+ 'perl|node|deno|bun|python[\\d.]*|py|ruby|php|copy|move|ren|rename|del|erase',
46
+ 'xcopy|robocopy|set-content|add-content|out-file|new-item|copy-item|move-item|rename-item',
47
+ 'remove-item|tee-object|sc|ac|ni|cpi|mi|rni|ri|checkout|restore|apply|am|stash|reset',
48
+ 'clean|switch|merge|pull|cherry-pick|revert|rebase|read-tree|checkout-index|update-index',
49
+ 'write(?:all|file)\\w*|append\\w*',
50
+ ].join('|')})(?![\\w-])|\\[(?:system\\.)?io\\.|(?<![\\w.-])(?:sed|perl)\\s[^|;&]*?\\s(?:-[a-zA-Z]*i|--in-place)`, 'i');
51
+ /** The text names both folders and looks like a write, its quotes and escapes taken out too. */
52
+ function looksLikeWrite(command) {
53
+ const joined = command.replace(/[\\`^]\r?\n/g, '');
54
+ const plain = joined.replace(/['"`^]/g, '').replace(/\\(?=[\w.])/g, '');
55
+ return [joined, plain].some((text) => PROTOTYPE.test(text) && VERSIONS.test(text) && (REDIRECT.test(text) || WRITERS.test(text)));
56
+ }
57
+ /** What the approval fallbacks say of a command: refuse, ask the person, or nothing. */
58
+ export function approvalText(command, shell, cwd, folders = false) {
59
+ if (pipedWrite(command, cwd, folders))
60
+ return 'deny';
61
+ if (folders && HERE.test(command) && WRITERS.test(command))
62
+ return 'deny';
63
+ const parts = commandParts(command, shell).map((part) => partWords(part));
64
+ if (looksLikeWrite(command))
65
+ return parts.every((words) => onlyReads(words)) ? 'ask' : 'deny';
66
+ // What a design turn writes where the parse cannot place it: the person's card.
67
+ if (folders && folderUnsure(parts))
68
+ return 'ask';
69
+ }
@@ -0,0 +1,32 @@
1
+ /** `find`'s actions that write, delete or run something. */
2
+ export declare const FIND_WRITES: RegExp;
3
+ /** git's subcommands that only read. */
4
+ export declare const GIT_READS: Set<string>;
5
+ /** git's subcommands that write the working tree's files. */
6
+ export declare const GIT_TREE_WRITES: Set<string>;
7
+ /** Programs that write, move or delete the paths they name (and PowerShell's aliases for them). */
8
+ export declare const TREE_WRITES: Set<string>;
9
+ /** A path's segments read against `cwd`; the first `literal` are the shell folder's own. */
10
+ export declare function segmentsOf(path: string, cwd: string): {
11
+ base: string[];
12
+ segments: string[];
13
+ could: (index: number, name: string) => boolean;
14
+ };
15
+ /** A path that is, or lies in, `prototype/versions`. */
16
+ export declare function inVersions(path: string, cwd: string): boolean;
17
+ /**
18
+ * A word's paths: the word, what follows an `=`, `:` or `,` in it (`HEAD:prototype/…`,
19
+ * `--target=…`), and each of its own words (a script's `w file`); an option is read only after
20
+ * its `=`.
21
+ */
22
+ export declare function wordPaths(word: string): string[];
23
+ export declare const names: (word: string, cwd: string) => boolean;
24
+ /** The index of the part's program: after `NAME=value` settings and runners (`env`, `xargs`). */
25
+ export declare function programAt(words: string[]): number;
26
+ /** The part only reads the paths it names: a read program, with none of its writing options. */
27
+ export declare function onlyReads(words: string[]): boolean;
28
+ /**
29
+ * True when a part's words could write into `prototype/versions` itself; a write aimed at a
30
+ * folder holding it is approval-folders.ts's, on the turns that keep that rule.
31
+ */
32
+ export declare function approvalWrite(words: string[], cwd: string): boolean;
@@ -0,0 +1,179 @@
1
+ /**
2
+ * The approval records, `prototype/versions/`, are written only by the studio, each as its own
3
+ * commit; the file tools already deny them. A shell command part that could write there is
4
+ * refused at every level, "Never ask" included: a redirect into the folder (`>`, `>>`, `&>`,
5
+ * `2>`, `>|`); any program that names a path in it and is not a read (`cp`, `mv`, `tee`,
6
+ * `sed -i`, `node -e`, `Set-Content` and every other one). A write aimed at a folder holding
7
+ * the records is approval-folders.ts's, on the turns that keep that rule. A path is read
8
+ * against the shell's folder (`$PWD`, `~+` too), `..` resolved, any case; a pattern, a brace list or
9
+ * a command's output (`$(…)`) that could stand for a folder counts. The reads (`cat`, `ls`,
10
+ * `grep`, `sed -n`, `awk`, `sort`, `git log`, `git show`, `Get-Content` and the rest) run, their
11
+ * output redirected anywhere else too. Plain Node only: the hook runs it.
12
+ */
13
+ import { homedir } from 'node:os';
14
+ import { resolve } from 'node:path';
15
+ import { programName } from './command-parts.js';
16
+ import { subcommandAt } from './git-words.js';
17
+ /** Programs that only read the paths they name (they write only to standard output). */
18
+ const READS = new Set([
19
+ 'cat ls dir head tail less more grep egrep fgrep rg wc stat file diff cmp jq du realpath cut',
20
+ 'readlink basename dirname test [ md5sum sha1sum sha256sum shasum type echo printf cd pushd',
21
+ 'popd bat od hexdump strings column nl which where findstr get-content gc get-childitem gci',
22
+ 'select-string sls test-path get-item gi resolve-path rvpa get-filehash set-location sl',
23
+ 'push-location pop-location write-output write-host find git sed awk gawk sort',
24
+ ].flatMap((line) => line.split(' ')));
25
+ /** `find`'s actions that write, delete or run something. */
26
+ export const FIND_WRITES = /^-(?:delete|exec|execdir|ok|okdir|fprint0?|fprintf|fls)$/;
27
+ /** git's subcommands that only read. */
28
+ export const GIT_READS = new Set([
29
+ 'log show diff status ls-files ls-tree blame annotate cat-file grep rev-parse rev-list',
30
+ 'shortlog whatchanged diff-tree diff-index diff-files check-ignore check-attr describe',
31
+ 'name-rev show-ref for-each-ref',
32
+ ].flatMap((line) => line.split(' ')));
33
+ /** git's subcommands that write the working tree's files. */
34
+ export const GIT_TREE_WRITES = new Set([
35
+ 'checkout restore reset clean stash apply am read-tree checkout-index mv rm switch merge',
36
+ 'pull cherry-pick revert rebase',
37
+ ].flatMap((line) => line.split(' ')));
38
+ /** Programs that write, move or delete the paths they name (and PowerShell's aliases for them). */
39
+ export const TREE_WRITES = new Set([
40
+ 'cp mv rm rmdir rsync ln install patch dd copy move del erase rd xcopy robocopy ren rename',
41
+ 'copy-item cpi move-item mi remove-item ri rename-item rni set-content sc add-content ac',
42
+ 'clear-content clc new-item ni out-file tee tee-object',
43
+ ].flatMap((line) => line.split(' ')));
44
+ /** Programs that run the command after them: the program that reads or writes comes later. */
45
+ const RUNNERS = new Set(['env', 'command', 'builtin', 'exec', 'time', 'nohup', 'sudo', 'xargs']);
46
+ const ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/;
47
+ /**
48
+ * A segment could be `name`: itself, a pattern (`*`, `v*`, `[pP]rototype`), a brace list
49
+ * (`{a,b}`, `{1..3}`; `{owner}` alone is a word) or a command's output (`$(…)`, backticks). A
50
+ * variable (`$dir`) is left to the text fallback, which reads where it was set.
51
+ */
52
+ function couldBe(segment, name) {
53
+ const lower = segment.toLowerCase();
54
+ if (lower === name)
55
+ return true;
56
+ if (/\$\(|`|\{[^}]*(?:,|\.\.)[^}]*\}/.test(lower))
57
+ return true;
58
+ if (!/[*?[\]]/.test(lower))
59
+ return false;
60
+ const pattern = lower
61
+ .replace(/[.+^()|\\]/g, '\\$&')
62
+ .replace(/\[!/g, '[^')
63
+ .replace(/\*+/g, '.*')
64
+ .replace(/\?/g, '.');
65
+ try {
66
+ return new RegExp(`^${pattern}$`).test(name);
67
+ }
68
+ catch {
69
+ return true;
70
+ }
71
+ }
72
+ /** A path's segments read against `cwd`; the first `literal` are the shell folder's own. */
73
+ export function segmentsOf(path, cwd) {
74
+ // The shell's folder by name (`$PWD`, `~+`); the one before it (`$OLDPWD`, `~-`) could be any.
75
+ const expanded = path
76
+ .replace(/^(?:\$PWD|\$\{PWD\}|~\+)(?=$|[\\/])/, '.')
77
+ .replace(/^(?:\$OLDPWD|\$\{OLDPWD\}|~-)(?=$|[\\/])/, '/')
78
+ .replace(/^~(?=$|[\\/])/, homedir());
79
+ const split = (text) => text.split(/[\\/]+/).filter(Boolean);
80
+ const base = split(resolve(cwd));
81
+ const segments = split(resolve(cwd, expanded));
82
+ let literal = 0;
83
+ while (literal < base.length && segments[literal] === base[literal])
84
+ literal++;
85
+ const could = (index, name) => {
86
+ const segment = segments[index];
87
+ return index < literal ? segment.toLowerCase() === name.toLowerCase() : couldBe(segment, name);
88
+ };
89
+ return { base, segments, could };
90
+ }
91
+ /** A path that is, or lies in, `prototype/versions`. */
92
+ export function inVersions(path, cwd) {
93
+ const { segments, could } = segmentsOf(path, cwd);
94
+ return segments.some((_, index) => index + 1 < segments.length && could(index, 'prototype') && could(index + 1, 'versions'));
95
+ }
96
+ /**
97
+ * A word's paths: the word, what follows an `=`, `:` or `,` in it (`HEAD:prototype/…`,
98
+ * `--target=…`), and each of its own words (a script's `w file`); an option is read only after
99
+ * its `=`.
100
+ */
101
+ export function wordPaths(word) {
102
+ const pieces = [
103
+ ...(word.startsWith('-') ? [] : [word, ...word.split(/\s+/)]),
104
+ ...word.split(/[=:,]/).slice(1),
105
+ ];
106
+ return pieces
107
+ .map((piece) => piece.replace(/^[<>|&(@"'{]+/, '').replace(/[,;)"'}]+$/, ''))
108
+ .filter(Boolean);
109
+ }
110
+ export const names = (word, cwd) => wordPaths(word).some((path) => inVersions(path, cwd));
111
+ /** The paths a part's redirects write to: `>x`, `> x`, `2>> x`, `&> x`, `>& x`, not `>&2`. */
112
+ function redirectTargets(words) {
113
+ const targets = [];
114
+ words.forEach((word, index) => {
115
+ const at = word.lastIndexOf('>');
116
+ if (at < 0)
117
+ return;
118
+ let rest = word.slice(at + 1).replace(/^\|/, '');
119
+ const both = rest.startsWith('&');
120
+ if (both)
121
+ rest = rest.slice(1);
122
+ // `>&2`, `>&-`: a copy of another output, not a file.
123
+ if (both && rest && /^\d*-?$/.test(rest))
124
+ return;
125
+ const target = rest || words[index + 1];
126
+ if (target && !(both && /^\d+-?$/.test(target)))
127
+ targets.push(target);
128
+ });
129
+ return targets;
130
+ }
131
+ /** The index of the part's program: after `NAME=value` settings and runners (`env`, `xargs`). */
132
+ export function programAt(words) {
133
+ let index = 0;
134
+ while (index < words.length) {
135
+ const word = words[index];
136
+ if (ASSIGNMENT.test(word))
137
+ index++;
138
+ else if (RUNNERS.has(programName(word))) {
139
+ index++;
140
+ while ((words[index] ?? '').startsWith('-'))
141
+ index++;
142
+ }
143
+ else
144
+ return index;
145
+ }
146
+ return index;
147
+ }
148
+ /** The part only reads the paths it names: a read program, with none of its writing options. */
149
+ export function onlyReads(words) {
150
+ const at = programAt(words);
151
+ const name = programName(words[at] ?? '');
152
+ if (!READS.has(name))
153
+ return false;
154
+ const rest = words.slice(at + 1);
155
+ if (name === 'find')
156
+ return !rest.some((word) => FIND_WRITES.test(word));
157
+ // `sed -i` edits in place and a `w` command writes; awk can print to a file or a program.
158
+ if (name === 'sed')
159
+ return !rest.some((word) => /^(?:-[a-zA-Z]*i|--in-place)/.test(word) || /\b[wW]\s/.test(word));
160
+ if (name === 'awk' || name === 'gawk')
161
+ return !rest.some((word) => /[>|]|system\s*\(|-i\s*inplace/.test(word));
162
+ if (name === 'sort')
163
+ return !rest.some((word) => /^(?:-[a-zA-Z]*o|--output)/.test(word));
164
+ if (name !== 'git')
165
+ return true;
166
+ const sub = subcommandAt(words, at + 1)?.name;
167
+ return !!sub && GIT_READS.has(sub) && !rest.some((word) => /^--output(?:=|$)/.test(word));
168
+ }
169
+ /**
170
+ * True when a part's words could write into `prototype/versions` itself; a write aimed at a
171
+ * folder holding it is approval-folders.ts's, on the turns that keep that rule.
172
+ */
173
+ export function approvalWrite(words, cwd) {
174
+ if (redirectTargets(words).some((target) => names(target, cwd)))
175
+ return true;
176
+ if (!words.some((word) => names(word, cwd)))
177
+ return false;
178
+ return !onlyReads(words);
179
+ }
@@ -12,10 +12,10 @@ export declare const SECRET_READS: string[];
12
12
  export declare function secretReads(folder: string): string[];
13
13
  /**
14
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.
15
+ * `bypassPermissions` with "Never ask", planning included. Below Autopilot, in a launch without a
16
+ * guard, and at every level of a host-launched turn (0.8.41's modes), planning runs `dontAsk` (it
17
+ * writes plan/ only, with two commands) and every other work accepts edits and asks.
18
18
  */
19
- export declare function permissionMode(work: Chat['work'], guard?: Pick<TurnGuard, 'level' | 'neverAsk'>): "acceptEdits" | "auto" | "bypassPermissions" | "dontAsk";
19
+ export declare function permissionMode(work: Chat['work'], guard?: Pick<TurnGuard, 'level' | 'neverAsk' | 'host'>): "acceptEdits" | "auto" | "bypassPermissions" | "dontAsk";
20
20
  /** Claude's permission flags for one turn, spliced in after the fixed start arguments. */
21
21
  export declare function claudePermissions(args: string[], work: Chat['work'], product: string, folder: string, verification: readonly string[], guard?: TurnGuard): void;
@@ -22,17 +22,21 @@ export function secretReads(folder) {
22
22
  }
23
23
  /**
24
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.
25
+ * `bypassPermissions` with "Never ask", planning included. Below Autopilot, in a launch without a
26
+ * guard, and at every level of a host-launched turn (0.8.41's modes), planning runs `dontAsk` (it
27
+ * writes plan/ only, with two commands) and every other work accepts edits and asks.
28
28
  */
29
29
  export function permissionMode(work, guard) {
30
- if (guard?.level === 'auto')
30
+ if (guard?.level === 'auto' && !guard.host)
31
31
  return guard.neverAsk ? 'bypassPermissions' : 'auto';
32
32
  return isPlanning(work) ? 'dontAsk' : 'acceptEdits';
33
33
  }
34
34
  /** Claude's permission flags for one turn, spliced in after the fixed start arguments. */
35
35
  export function claudePermissions(args, work, product, folder, verification, guard) {
36
+ if (guard?.host) {
37
+ hostLaunchedPermissions(args, work, product, folder, verification, guard);
38
+ return;
39
+ }
36
40
  const linked = claudeLinked(product);
37
41
  const mode = permissionMode(work, guard);
38
42
  // dontAsk turns disable every hook, the limits hook included: deny rules hold their limits.
@@ -67,3 +71,27 @@ export function claudePermissions(args, work, product, folder, verification, gua
67
71
  for (const arg of [...asks, PROMPT_TOOL, ...allowed, ...denied])
68
72
  guard.args.add(arg);
69
73
  }
74
+ /** Allow rules added since 0.8.41, left out of a host-launched turn. */
75
+ const SINCE_0841 = new Set(['Bash(pnpm format)', 'PowerShell(pnpm format)']);
76
+ /**
77
+ * A host-launched turn's flags, exactly as 0.8.41 built them (its launcher accepts only that
78
+ * policy): `dontAsk` with hooks off for planning, else `acceptEdits`, at every level, Autopilot
79
+ * and Never ask included; the step's allow list and 0.8.41's deny list. The host applies the limits.
80
+ */
81
+ function hostLaunchedPermissions(args, work, product, folder, verification, guard) {
82
+ const linked = claudeLinked(product);
83
+ const mode = permissionMode(work, guard);
84
+ args.splice(5, 0, '--permission-mode', mode, ...(mode === 'dontAsk' ? ['--settings', PLANNING_SETTINGS] : []));
85
+ const allowed = [
86
+ ...claudeRules(work, folder).filter((rule) => !SINCE_0841.has(rule)),
87
+ ...verificationRules(verification),
88
+ ...linked.allowed,
89
+ ];
90
+ args.push('--allowedTools', ...allowed);
91
+ const denied = [...claudeDenied(work), ...linked.denied];
92
+ if (denied.length)
93
+ args.push('--disallowedTools', ...denied);
94
+ guard.allowed.splice(0, guard.allowed.length, ...allowed);
95
+ for (const arg of [...allowed, ...denied])
96
+ guard.args.add(arg);
97
+ }
@@ -25,7 +25,7 @@ export declare function watchCodexIdle(child: ChildProcess, adapter: ChatAdapter
25
25
  kind: "refused";
26
26
  id: string;
27
27
  reason?: "command" | "monitor" | "permission" | "redirect" | "taskOutput" | undefined;
28
- limit?: "deploy" | "publish" | "push" | "release" | "secrets" | "settings" | undefined;
28
+ limit?: "approval" | "commit" | "deploy" | "publish" | "push" | "release" | "secrets" | "settings" | undefined;
29
29
  } | {
30
30
  kind: "file";
31
31
  path: string;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * A design turn on Autopilot (design or validation work at the `auto` level, "Never ask" or not;
3
+ * a level the hook was not told, or does not know, counts as Autopilot) never makes a commit or
4
+ * moves a branch: the studio saves its work, and an approval is a commit only the studio makes.
5
+ * So git's ways to do either are refused there: `commit`, `commit-tree`, `update-ref`, `merge`,
6
+ * `cherry-pick`, `revert`, `rebase`, `am`, `pull`, `fast-import`, `hash-object`, `replace`,
7
+ * `filter-branch`, `stash` (but `stash list` and `stash show`), `reset` to a commit,
8
+ * `branch -f`/`-M`/`-C`, `checkout -B`, `switch -C`, `fetch` into a branch (`x:y`), and git run
9
+ * with configuration made for the call (`-c alias.x=…`, `-c include.path=…`, `git config
10
+ * alias.x …`, `GIT_CONFIG_GLOBAL=…`, `HOME=…`). `push` is refused at every level already. Reads
11
+ * (`git log`, `git show`, `git status`, `git diff`) run; coding turns, which commit in their own
12
+ * change tree, are not touched. The text fallback sends the person's card a command that names
13
+ * git and one of those subcommands, unless the parse read every git in it and none commits. Plain Node only.
14
+ */
15
+ import { type Shell } from './command-parts.ts';
16
+ /** What the hook knows of its turn: the work (`design`) and the level (`auto`). */
17
+ export interface Turn {
18
+ work: string;
19
+ level: string;
20
+ }
21
+ /**
22
+ * A turn that writes the product's own folder, whose files the studio saves: design and
23
+ * validation at any level, planning and loop on Autopilot (below it they write plan/ only).
24
+ */
25
+ export declare const designWork: (turn?: Turn) => boolean;
26
+ /** The turns that make no commit: design, validation, planning and loop on Autopilot. */
27
+ export declare const designAutopilot: (turn?: Turn) => boolean;
28
+ /** True when a part's words make a commit or move a branch with git. */
29
+ export declare function commitWords(words: string[]): boolean;
30
+ /**
31
+ * The fallback: git with a configuration set anywhere in the command (`export HOME=…`,
32
+ * `$env:GIT_CONFIG_GLOBAL=…`) is refused; git with a subcommand that is not git's own (an
33
+ * alias), or text naming git and a subcommand that commits where the parse could not read every
34
+ * git, goes to the card.
35
+ */
36
+ export declare function commitText(command: string, shell: Shell): 'deny' | 'ask' | undefined;