@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.
- package/CHANGELOG.md +15 -0
- package/dist/commands/ui/chat/approval-folders.d.ts +20 -0
- package/dist/commands/ui/chat/approval-folders.js +134 -0
- package/dist/commands/ui/chat/approval-text.d.ts +11 -0
- package/dist/commands/ui/chat/approval-text.js +69 -0
- package/dist/commands/ui/chat/approval-writes.d.ts +32 -0
- package/dist/commands/ui/chat/approval-writes.js +179 -0
- package/dist/commands/ui/chat/claude-permissions.d.ts +4 -4
- package/dist/commands/ui/chat/claude-permissions.js +32 -4
- package/dist/commands/ui/chat/codex-idle.d.ts +1 -1
- package/dist/commands/ui/chat/commit-limits.d.ts +36 -0
- package/dist/commands/ui/chat/commit-limits.js +164 -0
- package/dist/commands/ui/chat/fresh-critique.js +3 -1
- package/dist/commands/ui/chat/fresh-launch.d.ts +5 -0
- package/dist/commands/ui/chat/fresh-launch.js +7 -4
- package/dist/commands/ui/chat/fresh.js +7 -1
- package/dist/commands/ui/chat/gh-api-limits.d.ts +14 -0
- package/dist/commands/ui/chat/gh-api-limits.js +74 -0
- package/dist/commands/ui/chat/git-words.d.ts +10 -0
- package/dist/commands/ui/chat/git-words.js +26 -0
- package/dist/commands/ui/chat/host-launched.d.ts +11 -0
- package/dist/commands/ui/chat/host-launched.js +35 -0
- package/dist/commands/ui/chat/limit-mentions.js +16 -2
- package/dist/commands/ui/chat/limit-text.d.ts +15 -0
- package/dist/commands/ui/chat/limit-text.js +36 -0
- package/dist/commands/ui/chat/limits-hook.js +2 -2
- package/dist/commands/ui/chat/limits.d.ts +7 -12
- package/dist/commands/ui/chat/limits.en.d.ts +2 -0
- package/dist/commands/ui/chat/limits.en.js +2 -0
- package/dist/commands/ui/chat/limits.es.js +2 -0
- package/dist/commands/ui/chat/limits.js +63 -59
- package/dist/commands/ui/chat/planning-limits.js +11 -0
- package/dist/commands/ui/chat/publish-limits.js +23 -7
- package/dist/commands/ui/chat/turn-guard.d.ts +8 -2
- package/dist/commands/ui/chat/turn-guard.js +8 -3
- package/dist/commands/ui/index.d.ts +42 -0
- package/dist/commands/ui/index.js +14 -2
- package/dist/commands/ui/routes.d.ts +2 -0
- package/dist/commands/ui/server-options.js +1 -0
- package/dist/commands/ui/server-request.js +5 -0
- package/dist/commands/ui/server.d.ts +7 -0
- package/dist/commands/ui/server.js +3 -0
- package/dist/commands/ui/studio-routes.d.ts +1 -0
- package/dist/commands/ui/studio-routes.js +3 -1
- package/dist/commands/ui/studio-state.d.ts +1 -0
- package/dist/ui/page.js +78 -69
- package/docs/PROTOTYPE.md +11 -0
- package/docs/WORKBENCH.md +11 -2
- package/package.json +11 -11
|
@@ -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
|
|
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
|
-
|
|
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, {
|
|
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;
|
|
@@ -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
|
|
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 {
|
|
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
|
|
29
|
-
*
|
|
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
|
|
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.',
|