@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,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;
@@ -0,0 +1,164 @@
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 { commandParts, ESCAPE, partWords, programName } from './command-parts.js';
16
+ import { wrappedScripts } from './command-wrappers.js';
17
+ import { subcommandAt } from './git-words.js';
18
+ const DESIGN = new Set(['design', 'validation']);
19
+ const PLANNING = new Set(['planning', 'loop']);
20
+ const BELOW_AUTOPILOT = new Set(['guide', 'review', 'lead']);
21
+ /** On Autopilot, or at a level the hook was not told or does not know. */
22
+ const autopilot = (turn) => !BELOW_AUTOPILOT.has(turn.level);
23
+ /**
24
+ * A turn that writes the product's own folder, whose files the studio saves: design and
25
+ * validation at any level, planning and loop on Autopilot (below it they write plan/ only).
26
+ */
27
+ export const designWork = (turn) => !!turn && (DESIGN.has(turn.work) || (PLANNING.has(turn.work) && autopilot(turn)));
28
+ /** The turns that make no commit: design, validation, planning and loop on Autopilot. */
29
+ export const designAutopilot = (turn) => !!turn && (DESIGN.has(turn.work) || PLANNING.has(turn.work)) && autopilot(turn);
30
+ const COMMITS = [
31
+ 'commit',
32
+ 'commit-tree',
33
+ 'update-ref',
34
+ 'merge',
35
+ 'cherry-pick',
36
+ 'revert',
37
+ 'rebase',
38
+ 'am',
39
+ 'pull',
40
+ 'fast-import',
41
+ 'hash-object',
42
+ 'replace',
43
+ 'filter-branch',
44
+ 'filter-repo',
45
+ ];
46
+ const COMMIT_SET = new Set(COMMITS);
47
+ /** Configuration that could turn a word into another command: an alias, an included file. */
48
+ const CONFIG = /(?:^|[\s=])(?:alias|include|includeif)\./i;
49
+ /** Settings before git that make it read another configuration. */
50
+ const CONFIG_ENV = /^(?:GIT_CONFIG(?:_GLOBAL|_SYSTEM|_PARAMETERS|_KEY_\d+)?|HOME|XDG_CONFIG_HOME)=/i;
51
+ /** The words after a subcommand, up to `--`. */
52
+ const argsOf = (words, at) => {
53
+ const rest = words.slice(at + 1);
54
+ const end = rest.indexOf('--');
55
+ return end < 0 ? rest : rest.slice(0, end);
56
+ };
57
+ /** A subcommand that moves a branch with these words: `stash`, `reset <c>`, `branch -f` … */
58
+ function movesBranch(name, args) {
59
+ const flags = args.filter((word) => word.startsWith('-'));
60
+ if (name === 'stash')
61
+ return !['list', 'show'].includes(args[0] ?? '');
62
+ if (name === 'reset')
63
+ return args.some((word) => !word.startsWith('-'));
64
+ if (name === 'branch')
65
+ return flags.some((flag) => /^(?:-[a-zA-Z]*[fMC]|--force|--copy|--move)/.test(flag));
66
+ if (name === 'checkout')
67
+ return flags.some((flag) => /^-[a-zA-Z]*B/.test(flag));
68
+ if (name === 'switch')
69
+ return flags.some((flag) => /^(?:-[a-zA-Z]*C|--force-create)/.test(flag));
70
+ if (name === 'fetch')
71
+ return args.some((word) => !word.startsWith('-') && word.includes(':'));
72
+ // `git subtree add|merge|pull` commit; `split --rejoin` does too.
73
+ if (name === 'subtree')
74
+ return (['add', 'merge', 'pull'].includes(args.find((w) => !w.startsWith('-')) ?? '') ||
75
+ args.includes('--rejoin'));
76
+ return false;
77
+ }
78
+ /** True when a part's words make a commit or move a branch with git. */
79
+ export function commitWords(words) {
80
+ const git = words.findIndex((word) => programName(word) === 'git');
81
+ if (git < 0)
82
+ return false;
83
+ const configured = words.slice(0, git).some((word) => CONFIG_ENV.test(word));
84
+ return words.some((word, index) => {
85
+ if (programName(word) !== 'git')
86
+ return false;
87
+ const sub = subcommandAt(words, index + 1);
88
+ if (!sub)
89
+ return false;
90
+ // Another configuration counts only where a subcommand could commit through it.
91
+ if (configured && !KNOWN.has(sub.name))
92
+ return true;
93
+ const options = words.slice(index + 1, sub.at);
94
+ if (options.some((option) => CONFIG.test(option)))
95
+ return true;
96
+ if (sub.name === 'config')
97
+ return words.slice(sub.at + 1).some((rest) => CONFIG.test(rest));
98
+ return COMMIT_SET.has(sub.name) || movesBranch(sub.name, argsOf(words, sub.at));
99
+ });
100
+ }
101
+ const GIT = /(?<![\w.])git(?![\w-])/i;
102
+ const MOVES = 'stash|reset|branch|checkout|switch|fetch';
103
+ // `am` is left out of the text: as a word it is too common.
104
+ const VERBS = new RegExp(`(?<![\\w./\\\\-])(?:${COMMITS.filter((verb) => verb !== 'am').join('|')}|${MOVES})(?![\\w./\\\\-])|(?<![\\w-])(?:alias|include)\\.`, 'i');
105
+ /** git's own subcommands that neither commit nor move a branch as such; another may be an alias. */
106
+ const KNOWN = new Set([
107
+ 'log show diff status ls-files ls-tree blame annotate cat-file grep rev-parse rev-list',
108
+ 'shortlog whatchanged diff-tree diff-index diff-files check-ignore check-attr describe',
109
+ 'name-rev show-ref for-each-ref add mv rm restore checkout switch branch tag stash reset',
110
+ 'fetch remote config init clone worktree clean apply format-patch bisect reflog notes',
111
+ 'help version count-objects fsck gc prune var verify-commit verify-tag archive bundle',
112
+ 'submodule sparse-checkout lfs range-diff difftool mergetool merge-base merge-tree subtree',
113
+ 'ls-remote cherry show-branch check-ref-format check-mailmap get-tar-commit-id column',
114
+ 'interpret-trailers verify-pack count-objects merge-file mktree pack-refs maintenance',
115
+ ].flatMap((line) => line.split(' ')));
116
+ /** Settings anywhere in a command that make git read another configuration. */
117
+ const CONFIG_SET = /(?:^|[\s;&|(])(?:export\s+|set\s+|\$env:)?(?:HOME|XDG_CONFIG_HOME|GIT_CONFIG\w*)\s*=/i;
118
+ /**
119
+ * The parse found git and read each one: a subcommand of git's own that neither commits nor
120
+ * moves a branch (`git log --grep merge | grep revert`; not an alias such as `git ci`), in the
121
+ * command and the scripts it hands on.
122
+ */
123
+ function gitAllRead(command, shell, depth = 0) {
124
+ let found;
125
+ for (const part of commandParts(command, shell)) {
126
+ const words = partWords(part, ESCAPE[shell]);
127
+ for (const [index, word] of words.entries()) {
128
+ if (programName(word) !== 'git')
129
+ continue;
130
+ const sub = subcommandAt(words, index + 1)?.name ?? '';
131
+ if ((sub && !KNOWN.has(sub)) || commitWords(words))
132
+ return false;
133
+ found = true;
134
+ }
135
+ for (const { script, shell: inside } of depth < 4 ? wrappedScripts(words, 32) : []) {
136
+ const inner = gitAllRead(script, inside, depth + 1);
137
+ if (inner === false)
138
+ return false;
139
+ found ||= inner;
140
+ }
141
+ }
142
+ return found;
143
+ }
144
+ /**
145
+ * The fallback: git with a configuration set anywhere in the command (`export HOME=…`,
146
+ * `$env:GIT_CONFIG_GLOBAL=…`) is refused; git with a subcommand that is not git's own (an
147
+ * alias), or text naming git and a subcommand that commits where the parse could not read every
148
+ * git, goes to the card.
149
+ */
150
+ export function commitText(command, shell) {
151
+ const joined = command.replace(/[\\`^]\r?\n/g, '');
152
+ const plain = joined.replace(/['"`^]/g, '').replace(/\\(?=[\w.])/g, '');
153
+ const texts = [joined, plain];
154
+ if (!texts.some((text) => GIT.test(text)))
155
+ return;
156
+ const read = gitAllRead(command, shell);
157
+ if (read === true)
158
+ return;
159
+ // Another configuration set anywhere counts only beside a git that could commit through it.
160
+ if (texts.some((text) => CONFIG_SET.test(text)))
161
+ return 'deny';
162
+ if (read === false || texts.some((text) => VERBS.test(text)))
163
+ return 'ask';
164
+ }
@@ -9,6 +9,7 @@ import { factsChanged } from '../merge-events.js';
9
9
  import { runFresh, stopFresh } from './fresh-launch.js';
10
10
  import { critiquePrompt, critiqueText } from './fresh-prompts.js';
11
11
  import { passingFullReport } from './fresh-report.js';
12
+ import { hostLaunched } from './host-launched.js';
12
13
  import { plainPath } from './store.js';
13
14
  const REPORT = /^prototype\/snapshots\/[a-f0-9]{7,64}$/;
14
15
  const keyOf = ({ source, report }) => (report ? `${source.checkout}|${report}` : '');
@@ -69,7 +70,8 @@ export class CritiqueTurns {
69
70
  keep(() => this.store.saveCritique({ ...record, state: 'running' }));
70
71
  const folder = source.checkout;
71
72
  const prompt = critiquePrompt(report);
72
- const run = runFresh(this.start, { folder, prompt, checks: true, ...choice });
73
+ const host = hostLaunched(this.root);
74
+ const run = runFresh(this.start, { folder, prompt, checks: true, host, ...choice });
73
75
  this.run = { ...run, key };
74
76
  void run.result.then(({ text, seconds }) => {
75
77
  this.run = undefined;
@@ -12,6 +12,11 @@ export interface FreshLaunch {
12
12
  checks?: boolean;
13
13
  /** The person's home, whose Claude settings give their denies and sign-in (tests set it). */
14
14
  home?: string;
15
+ /**
16
+ * The host's launcher starts the turn (host-launched.ts): only arguments a 0.8.41 launch carried,
17
+ * so no settings file and no `--setting-sources=`; the launcher decides which settings load.
18
+ */
19
+ host?: boolean;
15
20
  }
16
21
  export interface FreshResult {
17
22
  /** The agent's final answer; absent when the turn failed. */
@@ -5,7 +5,7 @@ import { AGENT_DEFS } from './defs.js';
5
5
  import { openFreshSettings, settingDenies } from './fresh-settings.js';
6
6
  import { scrubLaunchIds } from './launch-ids.js';
7
7
  import { claudeAdapter } from './parse-claude.js';
8
- import { COMMENT_PATH } from './permissions.js';
8
+ import { COMMENT_PATH, PLANNING_SETTINGS } from './permissions.js';
9
9
  import { PLANNING_LIMITS } from './planning-limits.js';
10
10
  import { jsonLine } from './prompt.js';
11
11
  import { launchArguments } from './turn-guard.js';
@@ -30,7 +30,7 @@ export function freshArgs(launch, settings) {
30
30
  '--permission-mode',
31
31
  'dontAsk',
32
32
  // No user, project or local settings: their allow rules could widen what dontAsk runs.
33
- '--setting-sources=',
33
+ ...(launch.host ? [] : ['--setting-sources=']),
34
34
  '--settings',
35
35
  settings,
36
36
  '--allowedTools',
@@ -44,7 +44,7 @@ export function freshArgs(launch, settings) {
44
44
  `Read(//**/${COMMENT_PATH}/**)`,
45
45
  ...secretReads(launch.folder),
46
46
  ...PLANNING_LIMITS,
47
- ...settingDenies(launch.folder, launch.home),
47
+ ...(launch.host ? [] : settingDenies(launch.folder, launch.home)),
48
48
  ...turnOverrides('claude', { model: launch.model, effort: launch.effort }).args,
49
49
  ...turn.stdin,
50
50
  ];
@@ -53,7 +53,10 @@ export function freshArgs(launch, settings) {
53
53
  export function runFresh(start, launch) {
54
54
  const started = Date.now();
55
55
  const seconds = () => Math.max(0, Math.floor((Date.now() - started) / 1000));
56
- const settings = openFreshSettings(launch.home);
56
+ // Hooks stay off through the inline JSON a 0.8.41 planning launch carried too.
57
+ const settings = launch.host
58
+ ? { value: PLANNING_SETTINGS, close: () => { } }
59
+ : openFreshSettings(launch.home);
57
60
  const args = freshArgs(launch, settings.value);
58
61
  const allowed = launchArguments(args);
59
62
  const release = () => {
@@ -12,6 +12,7 @@ import { runFresh, stopFresh } from './fresh-launch.js';
12
12
  import { parseFindings, reviewPrompt, reviewStepOf, stepChoice } from './fresh-prompts.js';
13
13
  import { prototypeTurn } from './fresh-report.js';
14
14
  import { FreshStore } from './fresh-store.js';
15
+ import { hostLaunched } from './host-launched.js';
15
16
  export class FreshLooks {
16
17
  store;
17
18
  root;
@@ -61,7 +62,12 @@ export class FreshLooks {
61
62
  review(step, choice) {
62
63
  const record = { agent: 'claude', at: new Date().toISOString(), findings: [] };
63
64
  keep(() => this.store.saveReview(step, { ...record, state: 'running' }));
64
- const run = runFresh(this.start, { folder: this.root, prompt: reviewPrompt(step), ...choice });
65
+ const run = runFresh(this.start, {
66
+ folder: this.root,
67
+ prompt: reviewPrompt(step),
68
+ host: hostLaunched(this.root),
69
+ ...choice,
70
+ });
65
71
  this.runs.set(step, run);
66
72
  void run.result.then(({ text, seconds }) => {
67
73
  this.runs.delete(step);
@@ -0,0 +1,14 @@
1
+ /**
2
+ * A `gh api` call that creates or changes a release: a method other than GET or HEAD on a
3
+ * repository's releases (`repos/{owner}/{repo}/releases`, an asset upload on uploads.github.com
4
+ * included). gh's method is `-X`/`--method` when given (`-XPOST`, `--method=patch`); otherwise
5
+ * POST when the call sends fields or a body (`-f`, `-F`, `--field`, `--raw-field`, `--input`),
6
+ * GET when it sends none. So `gh api repos/o/r/releases` and `gh api -X GET … -f per_page=5`
7
+ * read and run. Plain Node only: the hook runs it.
8
+ */
9
+ /** `gh api`'s options that take the next word as their value. */
10
+ export declare const GH_API_VALUED: string[];
11
+ /** A repository's releases, as a path, a `{owner}/{repo}` template or a whole URL. */
12
+ export declare const RELEASES_PATH: RegExp;
13
+ /** True when the words after `gh api` (from `from`) create or change a release. */
14
+ export declare function releaseCall(words: string[], from: number): boolean;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * A `gh api` call that creates or changes a release: a method other than GET or HEAD on a
3
+ * repository's releases (`repos/{owner}/{repo}/releases`, an asset upload on uploads.github.com
4
+ * included). gh's method is `-X`/`--method` when given (`-XPOST`, `--method=patch`); otherwise
5
+ * POST when the call sends fields or a body (`-f`, `-F`, `--field`, `--raw-field`, `--input`),
6
+ * GET when it sends none. So `gh api repos/o/r/releases` and `gh api -X GET … -f per_page=5`
7
+ * read and run. Plain Node only: the hook runs it.
8
+ */
9
+ /** `gh api`'s options that take the next word as their value. */
10
+ export const GH_API_VALUED = [
11
+ '-X',
12
+ '--method',
13
+ '-H',
14
+ '--header',
15
+ '-f',
16
+ '--raw-field',
17
+ '-F',
18
+ '--field',
19
+ '--input',
20
+ '-q',
21
+ '--jq',
22
+ '-t',
23
+ '--template',
24
+ '-p',
25
+ '--preview',
26
+ '--cache',
27
+ '--hostname',
28
+ ];
29
+ const VALUED = new Set(GH_API_VALUED);
30
+ const SENDS = new Set(['-f', '--raw-field', '-F', '--field', '--input']);
31
+ const READS = new Set(['GET', 'HEAD']);
32
+ /** A repository's releases, as a path, a `{owner}/{repo}` template or a whole URL. */
33
+ export const RELEASES_PATH = /(?:^|\/)repos\/[^/\s]+\/[^/\s]+\/releases(?=$|[/?#])/i;
34
+ /** An option's name and its attached value (`-XPOST`, `--method=POST`, `-fname=x`). */
35
+ function option(word) {
36
+ const long = /^(--[\w-]+)=(.*)$/s.exec(word);
37
+ if (long)
38
+ return { name: long[1], value: long[2] };
39
+ const short = /^(-[A-Za-z])(.+)$/s.exec(word);
40
+ if (short && VALUED.has(short[1]))
41
+ return { name: short[1], value: short[2] };
42
+ return { name: word };
43
+ }
44
+ /** The endpoint with its `%`-escapes read (`repos/o/r/%72eleases`), as gh sends it. */
45
+ function decoded(endpoint) {
46
+ try {
47
+ return decodeURIComponent(endpoint);
48
+ }
49
+ catch {
50
+ return endpoint.replace(/%[0-9a-f]{2}/gi, (code) => String.fromCharCode(Number.parseInt(code.slice(1), 16)));
51
+ }
52
+ }
53
+ /** True when the words after `gh api` (from `from`) create or change a release. */
54
+ export function releaseCall(words, from) {
55
+ let endpoint;
56
+ let method;
57
+ let sends = false;
58
+ for (let index = from; index < words.length; index++) {
59
+ const word = words[index];
60
+ if (!word.startsWith('-') || word === '-') {
61
+ endpoint ??= word;
62
+ continue;
63
+ }
64
+ const { name, value: attached } = option(word);
65
+ const value = attached ?? (VALUED.has(name) ? words[++index] : undefined);
66
+ if (name === '-X' || name === '--method')
67
+ method = value?.toUpperCase();
68
+ if (SENDS.has(name))
69
+ sends = true;
70
+ }
71
+ if (!endpoint || !RELEASES_PATH.test(decoded(endpoint)))
72
+ return false;
73
+ return !READS.has(method ?? (sends ? 'POST' : 'GET'));
74
+ }
@@ -0,0 +1,10 @@
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
+ /** The first word after `from` that is not an option (or an option's value), and its index. */
6
+ export declare function subcommandAt(words: string[], from: number): {
7
+ name: string;
8
+ at: number;
9
+ } | undefined;
10
+ export declare const subcommand: (words: string[], from: number) => string | undefined;