@buffcore/cli 0.8.42 → 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 +26 -0
- package/dist/commands/design/references.d.ts +9 -0
- package/dist/commands/design/references.js +20 -1
- package/dist/commands/extension/places-approval.d.ts +1 -1
- package/dist/commands/prototype/comp-record.d.ts +27 -0
- package/dist/commands/prototype/comp-record.js +85 -0
- package/dist/commands/prototype/comp-words.d.ts +12 -0
- package/dist/commands/prototype/comp-words.js +24 -0
- package/dist/commands/prototype/comp.d.ts +26 -0
- package/dist/commands/prototype/comp.js +71 -0
- package/dist/commands/prototype/milestone-versions.d.ts +1 -1
- package/dist/commands/prototype/record-look-child.js +4 -1
- package/dist/commands/prototype/snapshot-command.js +1 -1
- package/dist/commands/prototype/snapshot-setup.d.ts +11 -0
- package/dist/commands/prototype/snapshot-setup.js +29 -5
- package/dist/commands/prototype/versions.d.ts +3 -3
- package/dist/commands/ui/agents-route.d.ts +2 -0
- package/dist/commands/ui/agents-route.js +8 -5
- package/dist/commands/ui/approval-authority.d.ts +1 -1
- package/dist/commands/ui/approve.js +7 -1
- 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 -0
- 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.d.ts +28 -0
- package/dist/commands/ui/chat/fresh-critique.js +123 -0
- package/dist/commands/ui/chat/fresh-launch.d.ts +36 -0
- package/dist/commands/ui/chat/fresh-launch.js +125 -0
- package/dist/commands/ui/chat/fresh-prompts.d.ts +17 -0
- package/dist/commands/ui/chat/fresh-prompts.js +76 -0
- package/dist/commands/ui/chat/fresh-report.d.ts +8 -0
- package/dist/commands/ui/chat/fresh-report.js +36 -0
- package/dist/commands/ui/chat/fresh-routes.d.ts +3 -0
- package/dist/commands/ui/chat/fresh-routes.js +64 -0
- package/dist/commands/ui/chat/fresh-settings.d.ts +12 -0
- package/dist/commands/ui/chat/fresh-settings.js +66 -0
- package/dist/commands/ui/chat/fresh-store.d.ts +17 -0
- package/dist/commands/ui/chat/fresh-store.js +67 -0
- package/dist/commands/ui/chat/fresh.d.ts +31 -0
- package/dist/commands/ui/chat/fresh.en.d.ts +7 -0
- package/dist/commands/ui/chat/fresh.en.js +7 -0
- package/dist/commands/ui/chat/fresh.es.d.ts +7 -0
- package/dist/commands/ui/chat/fresh.es.js +7 -0
- package/dist/commands/ui/chat/fresh.js +118 -0
- 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.d.ts +2 -2
- package/dist/commands/ui/chat/limit-mentions.js +36 -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 +11 -9
- package/dist/commands/ui/chat/limits.en.d.ts +4 -0
- package/dist/commands/ui/chat/limits.en.js +4 -0
- package/dist/commands/ui/chat/limits.es.js +4 -0
- package/dist/commands/ui/chat/limits.js +67 -51
- package/dist/commands/ui/chat/parse-claude.js +7 -3
- package/dist/commands/ui/chat/permission-ask.js +3 -0
- package/dist/commands/ui/chat/planning-limits.js +26 -0
- package/dist/commands/ui/chat/publish-limits.d.ts +4 -0
- package/dist/commands/ui/chat/publish-limits.js +113 -0
- package/dist/commands/ui/chat/recorded-turn.js +3 -0
- package/dist/commands/ui/chat/stream.js +4 -1
- package/dist/commands/ui/chat/turn-guard.d.ts +10 -2
- package/dist/commands/ui/chat/turn-guard.js +20 -3
- package/dist/commands/ui/chat/turn-state.d.ts +5 -0
- package/dist/commands/ui/chat/turn.js +1 -0
- package/dist/commands/ui/comp-approval.d.ts +6 -0
- package/dist/commands/ui/comp-approval.js +42 -0
- package/dist/commands/ui/host.js +3 -0
- package/dist/commands/ui/index.d.ts +42 -0
- package/dist/commands/ui/index.js +32 -8
- package/dist/commands/ui/loop-approve.d.ts +4 -4
- package/dist/commands/ui/places-change.d.ts +1 -1
- package/dist/commands/ui/plan-structure.d.ts +3 -0
- package/dist/commands/ui/plan-structure.en.d.ts +3 -0
- package/dist/commands/ui/plan-structure.en.js +3 -0
- package/dist/commands/ui/plan-structure.es.d.ts +3 -0
- package/dist/commands/ui/plan-structure.es.js +3 -0
- package/dist/commands/ui/plan-structure.js +12 -4
- package/dist/commands/ui/prototype-comp-route.d.ts +7 -0
- package/dist/commands/ui/prototype-comp-route.js +109 -0
- package/dist/commands/ui/prototype-main.d.ts +2 -1
- package/dist/commands/ui/prototype-scenes-child.js +4 -1
- package/dist/commands/ui/prototype-snapshot-session.d.ts +1 -1
- package/dist/commands/ui/prototype-snapshot-session.js +3 -0
- package/dist/commands/ui/prototype-snapshot.d.ts +1 -1
- package/dist/commands/ui/routes.d.ts +8 -3
- package/dist/commands/ui/routes.js +3 -3
- package/dist/commands/ui/save-publish.js +3 -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 +14 -0
- package/dist/commands/ui/server.js +10 -3
- package/dist/commands/ui/structure-surface.d.ts +6 -0
- package/dist/commands/ui/structure-surface.js +94 -0
- package/dist/commands/ui/studio-routes.d.ts +1 -0
- package/dist/commands/ui/studio-routes.js +7 -1
- package/dist/commands/ui/studio-state.d.ts +7 -4
- package/dist/commands/ui/studio-versions.d.ts +3 -3
- package/dist/ui/page.js +98 -89
- package/docs/PROCESS.md +5 -0
- package/docs/PROTOTYPE.md +31 -0
- package/docs/WORKBENCH.md +11 -2
- package/package.json +11 -11
- package/skills/ape-critique/SKILL.md +9 -3
- package/skills/ape-design-system/SKILL.md +2 -1
- package/skills/ape-prototype/SKILL.md +5 -1
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type AgentsFile } from '@buffcore/contracts/workbench';
|
|
2
|
+
import type { Start, stopTree } from '../runner.ts';
|
|
3
|
+
import type { FreshStore } from './fresh-store.ts';
|
|
4
|
+
export interface CritiqueSource {
|
|
5
|
+
change?: string;
|
|
6
|
+
checkout: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class CritiqueTurns {
|
|
9
|
+
private run?;
|
|
10
|
+
private queued?;
|
|
11
|
+
private closed;
|
|
12
|
+
private readonly root;
|
|
13
|
+
private readonly start;
|
|
14
|
+
private readonly stop;
|
|
15
|
+
private readonly store;
|
|
16
|
+
private readonly settings;
|
|
17
|
+
constructor(root: string, start: Start, stop: typeof stopTree, store: FreshStore, settings: () => AgentsFile | undefined);
|
|
18
|
+
/** A Prototype turn ended: a passing full snapshot it took itself (since it began) starts one. */
|
|
19
|
+
afterTurn(startedAt: number): Promise<void>;
|
|
20
|
+
/** A full snapshot passed: start its critique, or queue it behind the one running. */
|
|
21
|
+
after(source: CritiqueSource, report?: string): boolean;
|
|
22
|
+
private agent;
|
|
23
|
+
private begin;
|
|
24
|
+
running(): boolean;
|
|
25
|
+
close(): void;
|
|
26
|
+
}
|
|
27
|
+
/** A record that cannot be written never fails the turn that started it. */
|
|
28
|
+
export declare function keep(write: () => void): boolean;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// The critique as its own turn (0.8.43): after a passing full snapshot (taken from the Prototype
|
|
2
|
+
// page, or by the Prototype step's agent during its turn) a fresh, read-only turn reads it and the
|
|
3
|
+
// studio writes design/critique.md from its answer. One at a time, one queued, and never twice for
|
|
4
|
+
// the same report in the same checkout.
|
|
5
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { CRITIQUE_FILE } from '@buffcore/contracts/workbench';
|
|
8
|
+
import { factsChanged } from '../merge-events.js';
|
|
9
|
+
import { runFresh, stopFresh } from './fresh-launch.js';
|
|
10
|
+
import { critiquePrompt, critiqueText } from './fresh-prompts.js';
|
|
11
|
+
import { passingFullReport } from './fresh-report.js';
|
|
12
|
+
import { hostLaunched } from './host-launched.js';
|
|
13
|
+
import { plainPath } from './store.js';
|
|
14
|
+
const REPORT = /^prototype\/snapshots\/[a-f0-9]{7,64}$/;
|
|
15
|
+
const keyOf = ({ source, report }) => (report ? `${source.checkout}|${report}` : '');
|
|
16
|
+
export class CritiqueTurns {
|
|
17
|
+
run;
|
|
18
|
+
queued;
|
|
19
|
+
closed = false;
|
|
20
|
+
root;
|
|
21
|
+
start;
|
|
22
|
+
stop;
|
|
23
|
+
store;
|
|
24
|
+
settings;
|
|
25
|
+
constructor(root, start, stop, store, settings) {
|
|
26
|
+
this.root = root;
|
|
27
|
+
this.start = start;
|
|
28
|
+
this.stop = stop;
|
|
29
|
+
this.store = store;
|
|
30
|
+
this.settings = settings;
|
|
31
|
+
}
|
|
32
|
+
/** A Prototype turn ended: a passing full snapshot it took itself (since it began) starts one. */
|
|
33
|
+
async afterTurn(startedAt) {
|
|
34
|
+
const report = await passingFullReport(this.root, startedAt).catch(() => undefined);
|
|
35
|
+
if (report)
|
|
36
|
+
this.after({ checkout: this.root }, report);
|
|
37
|
+
}
|
|
38
|
+
/** A full snapshot passed: start its critique, or queue it behind the one running. */
|
|
39
|
+
after(source, report) {
|
|
40
|
+
const pending = { source, ...(report && REPORT.test(report) ? { report } : {}) };
|
|
41
|
+
const key = keyOf(pending);
|
|
42
|
+
if (this.closed || (key && (this.store.critiqued(key) || this.run?.key === key)))
|
|
43
|
+
return false;
|
|
44
|
+
if (this.agent() !== 'claude')
|
|
45
|
+
return false;
|
|
46
|
+
if (this.run) {
|
|
47
|
+
this.queued = pending;
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
this.begin(pending, key);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
agent() {
|
|
54
|
+
const settings = this.settings();
|
|
55
|
+
return settings?.work.validation ?? settings?.default ?? 'claude';
|
|
56
|
+
}
|
|
57
|
+
begin(pending, key) {
|
|
58
|
+
const settings = this.settings();
|
|
59
|
+
const choice = {
|
|
60
|
+
...(settings?.model?.validation ? { model: settings.model.validation } : {}),
|
|
61
|
+
...(settings?.effort?.validation ? { effort: settings.effort.validation } : {}),
|
|
62
|
+
};
|
|
63
|
+
const { source, report } = pending;
|
|
64
|
+
const record = {
|
|
65
|
+
agent: 'claude',
|
|
66
|
+
at: new Date().toISOString(),
|
|
67
|
+
...(source.change ? { change: source.change } : {}),
|
|
68
|
+
...(report ? { report } : {}),
|
|
69
|
+
};
|
|
70
|
+
keep(() => this.store.saveCritique({ ...record, state: 'running' }));
|
|
71
|
+
const folder = source.checkout;
|
|
72
|
+
const prompt = critiquePrompt(report);
|
|
73
|
+
const host = hostLaunched(this.root);
|
|
74
|
+
const run = runFresh(this.start, { folder, prompt, checks: true, host, ...choice });
|
|
75
|
+
this.run = { ...run, key };
|
|
76
|
+
void run.result.then(({ text, seconds }) => {
|
|
77
|
+
this.run = undefined;
|
|
78
|
+
if (this.closed)
|
|
79
|
+
return;
|
|
80
|
+
const body = text === undefined ? undefined : critiqueText(text);
|
|
81
|
+
const written = !!body && keep(() => writeCritique(folder, body));
|
|
82
|
+
if (written && key)
|
|
83
|
+
keep(() => this.store.markCritiqued(key));
|
|
84
|
+
keep(() => this.store.saveCritique({
|
|
85
|
+
...record,
|
|
86
|
+
seconds,
|
|
87
|
+
state: written ? 'done' : 'failed',
|
|
88
|
+
...(written ? { file: CRITIQUE_FILE } : {}),
|
|
89
|
+
}));
|
|
90
|
+
if (written)
|
|
91
|
+
factsChanged('unsaved');
|
|
92
|
+
const next = this.queued;
|
|
93
|
+
this.queued = undefined;
|
|
94
|
+
if (next)
|
|
95
|
+
this.after(next.source, next.report);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
running() {
|
|
99
|
+
return !!this.run;
|
|
100
|
+
}
|
|
101
|
+
close() {
|
|
102
|
+
this.closed = true;
|
|
103
|
+
this.queued = undefined;
|
|
104
|
+
if (this.run)
|
|
105
|
+
stopFresh(this.run, this.stop);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/** A record that cannot be written never fails the turn that started it. */
|
|
109
|
+
export function keep(write) {
|
|
110
|
+
try {
|
|
111
|
+
write();
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/** The studio writes the critique; the agent's turn wrote nothing. Never through a link. */
|
|
119
|
+
function writeCritique(folder, body) {
|
|
120
|
+
const design = plainPath(join(folder, 'design'));
|
|
121
|
+
mkdirSync(design, { recursive: true });
|
|
122
|
+
writeFileSync(plainPath(join(design, 'critique.md')), body);
|
|
123
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ChildProcess } from 'node:child_process';
|
|
2
|
+
import type { AgentEffort } from '@buffcore/contracts/workbench';
|
|
3
|
+
import type { Start } from '../runner.ts';
|
|
4
|
+
import { stopTree } from '../runner.ts';
|
|
5
|
+
export interface FreshLaunch {
|
|
6
|
+
/** The product folder the turn reads. */
|
|
7
|
+
folder: string;
|
|
8
|
+
prompt: string;
|
|
9
|
+
model?: string;
|
|
10
|
+
effort?: AgentEffort;
|
|
11
|
+
/** The critique may run the design and i18n checks; the review runs nothing. */
|
|
12
|
+
checks?: boolean;
|
|
13
|
+
/** The person's home, whose Claude settings give their denies and sign-in (tests set it). */
|
|
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;
|
|
20
|
+
}
|
|
21
|
+
export interface FreshResult {
|
|
22
|
+
/** The agent's final answer; absent when the turn failed. */
|
|
23
|
+
text?: string;
|
|
24
|
+
seconds: number;
|
|
25
|
+
}
|
|
26
|
+
/** The read-only arguments for one fresh Claude turn. */
|
|
27
|
+
export declare function freshArgs(launch: FreshLaunch, settings: string): string[];
|
|
28
|
+
/** A running fresh turn: its child, to stop it, and its result. */
|
|
29
|
+
export interface FreshRun {
|
|
30
|
+
child?: ChildProcess;
|
|
31
|
+
result: Promise<FreshResult>;
|
|
32
|
+
}
|
|
33
|
+
/** Start one fresh turn; its result never rejects (a failure has no text). */
|
|
34
|
+
export declare function runFresh(start: Start, launch: FreshLaunch): FreshRun;
|
|
35
|
+
/** Stop a fresh turn's process tree. */
|
|
36
|
+
export declare function stopFresh(run: FreshRun, stop?: typeof stopTree): void;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { stopTree } from '../runner.js';
|
|
2
|
+
import { stdinInput } from './attachments.js';
|
|
3
|
+
import { secretReads } from './claude-permissions.js';
|
|
4
|
+
import { AGENT_DEFS } from './defs.js';
|
|
5
|
+
import { openFreshSettings, settingDenies } from './fresh-settings.js';
|
|
6
|
+
import { scrubLaunchIds } from './launch-ids.js';
|
|
7
|
+
import { claudeAdapter } from './parse-claude.js';
|
|
8
|
+
import { COMMENT_PATH, PLANNING_SETTINGS } from './permissions.js';
|
|
9
|
+
import { PLANNING_LIMITS } from './planning-limits.js';
|
|
10
|
+
import { jsonLine } from './prompt.js';
|
|
11
|
+
import { launchArguments } from './turn-guard.js';
|
|
12
|
+
import { turnOverrides } from './turn-overrides.js';
|
|
13
|
+
/**
|
|
14
|
+
* Checks the critique may run, exactly as written: no prefix rule, so no added argument or
|
|
15
|
+
* redirection to a file matches. The review runs none.
|
|
16
|
+
*/
|
|
17
|
+
const CRITIQUE_CHECKS = ['pnpm ape design check', 'pnpm ape i18n check'];
|
|
18
|
+
/** Every tool that writes, runs or reaches out, or starts another agent; reads stay. */
|
|
19
|
+
const WRITES = ['Edit', 'Write', 'NotebookEdit', 'WebFetch', 'WebSearch', 'Task', 'Agent'];
|
|
20
|
+
/** The read-only arguments for one fresh Claude turn. */
|
|
21
|
+
export function freshArgs(launch, settings) {
|
|
22
|
+
const turn = AGENT_DEFS.find((def) => def.id === 'claude')?.turn;
|
|
23
|
+
if (!turn)
|
|
24
|
+
throw new Error('claude has no headless turn');
|
|
25
|
+
const checks = launch.checks
|
|
26
|
+
? CRITIQUE_CHECKS.flatMap((command) => [`Bash(${command})`, `PowerShell(${command})`])
|
|
27
|
+
: [];
|
|
28
|
+
return [
|
|
29
|
+
...turn.start,
|
|
30
|
+
'--permission-mode',
|
|
31
|
+
'dontAsk',
|
|
32
|
+
// No user, project or local settings: their allow rules could widen what dontAsk runs.
|
|
33
|
+
...(launch.host ? [] : ['--setting-sources=']),
|
|
34
|
+
'--settings',
|
|
35
|
+
settings,
|
|
36
|
+
'--allowedTools',
|
|
37
|
+
'Read',
|
|
38
|
+
'Glob',
|
|
39
|
+
'Grep',
|
|
40
|
+
...checks,
|
|
41
|
+
'--disallowedTools',
|
|
42
|
+
...WRITES,
|
|
43
|
+
...(launch.checks ? [] : ['Bash', 'PowerShell']),
|
|
44
|
+
`Read(//**/${COMMENT_PATH}/**)`,
|
|
45
|
+
...secretReads(launch.folder),
|
|
46
|
+
...PLANNING_LIMITS,
|
|
47
|
+
...(launch.host ? [] : settingDenies(launch.folder, launch.home)),
|
|
48
|
+
...turnOverrides('claude', { model: launch.model, effort: launch.effort }).args,
|
|
49
|
+
...turn.stdin,
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
/** Start one fresh turn; its result never rejects (a failure has no text). */
|
|
53
|
+
export function runFresh(start, launch) {
|
|
54
|
+
const started = Date.now();
|
|
55
|
+
const seconds = () => Math.max(0, Math.floor((Date.now() - started) / 1000));
|
|
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);
|
|
60
|
+
const args = freshArgs(launch, settings.value);
|
|
61
|
+
const allowed = launchArguments(args);
|
|
62
|
+
const release = () => {
|
|
63
|
+
allowed();
|
|
64
|
+
settings.close();
|
|
65
|
+
};
|
|
66
|
+
let child;
|
|
67
|
+
try {
|
|
68
|
+
child = start({ program: 'pnpm', args: ['exec', 'claude', ...args], json: true }, launch.folder);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
release();
|
|
72
|
+
return { result: Promise.resolve({ seconds: seconds() }) };
|
|
73
|
+
}
|
|
74
|
+
const result = new Promise((done) => {
|
|
75
|
+
const adapter = claudeAdapter();
|
|
76
|
+
let pending = '';
|
|
77
|
+
let answer;
|
|
78
|
+
let last;
|
|
79
|
+
let failed = false;
|
|
80
|
+
const line = (text) => {
|
|
81
|
+
const record = jsonLine(text);
|
|
82
|
+
if (record.type === 'result') {
|
|
83
|
+
if (record.is_error === true || record.subtype !== 'success')
|
|
84
|
+
failed = true;
|
|
85
|
+
else if (typeof record.result === 'string')
|
|
86
|
+
answer = record.result;
|
|
87
|
+
}
|
|
88
|
+
for (const event of adapter.parse(text)) {
|
|
89
|
+
if (event.kind === 'text')
|
|
90
|
+
last = event.text;
|
|
91
|
+
if (event.kind === 'error')
|
|
92
|
+
failed = true;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
child.stdout?.setEncoding('utf8');
|
|
96
|
+
child.stdout?.on('data', (chunk) => {
|
|
97
|
+
const lines = (pending + chunk).split('\n');
|
|
98
|
+
pending = lines.pop() ?? '';
|
|
99
|
+
for (const text of lines)
|
|
100
|
+
if (text.trim())
|
|
101
|
+
line(text);
|
|
102
|
+
});
|
|
103
|
+
let ended = false;
|
|
104
|
+
const end = (code) => {
|
|
105
|
+
if (ended)
|
|
106
|
+
return;
|
|
107
|
+
ended = true;
|
|
108
|
+
release();
|
|
109
|
+
if (pending.trim())
|
|
110
|
+
line(pending);
|
|
111
|
+
const text = failed || code !== 0 ? undefined : (answer ?? last);
|
|
112
|
+
done({ ...(text?.trim() ? { text: scrubLaunchIds(text) } : {}), seconds: seconds() });
|
|
113
|
+
};
|
|
114
|
+
child.once('error', () => end(1));
|
|
115
|
+
child.once('close', (code) => end(code));
|
|
116
|
+
});
|
|
117
|
+
child.stdin?.on('error', () => { });
|
|
118
|
+
child.stdin?.end(stdinInput('claude', launch.prompt, []));
|
|
119
|
+
return { child, result };
|
|
120
|
+
}
|
|
121
|
+
/** Stop a fresh turn's process tree. */
|
|
122
|
+
export function stopFresh(run, stop = stopTree) {
|
|
123
|
+
if (run.child)
|
|
124
|
+
stop(run.child, true);
|
|
125
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Chat, type ReviewStep } from '@buffcore/contracts/workbench';
|
|
2
|
+
/** A review step whose turn just wrote one of its own files, by the turn's own edit calls. */
|
|
3
|
+
export declare function reviewStepOf(chat: Chat, firstMessage: number): ReviewStep | undefined;
|
|
4
|
+
/** The step's last recorded model and effort, as its own turn asked for them. */
|
|
5
|
+
export declare function stepChoice(chat: Chat): {
|
|
6
|
+
model?: string | undefined;
|
|
7
|
+
effort?: "high" | "low" | "max" | "medium" | "xhigh" | undefined;
|
|
8
|
+
};
|
|
9
|
+
export declare function reviewPrompt(step: ReviewStep): string;
|
|
10
|
+
export declare function critiquePrompt(report: string | undefined): string;
|
|
11
|
+
/** The findings in a reviewer's answer: one JSON object, perhaps fenced; else none. */
|
|
12
|
+
export declare function parseFindings(text: string): string[] | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* The critique's Markdown, without a fence the agent may have wrapped it in; none unless it has
|
|
15
|
+
* the skill's shape (a reply such as "I couldn't write the file" is not a critique).
|
|
16
|
+
*/
|
|
17
|
+
export declare function critiqueText(text: string): string | undefined;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// What a fresh turn is asked, and how its answer is read: the review's findings (at most seven, one
|
|
2
|
+
// sentence each; anything malformed is dropped quietly) and the critique's Markdown.
|
|
3
|
+
import { FINDING_LENGTH, MAX_FINDINGS, REVIEW_STEPS, stepOwnsFile, stepSaveFiles, } from '@buffcore/contracts/workbench';
|
|
4
|
+
import { createI18n, matchLocale } from '@buffcore/i18n';
|
|
5
|
+
import { en } from './fresh.en.js';
|
|
6
|
+
import { es } from './fresh.es.js';
|
|
7
|
+
import { isPlanning } from './permissions.js';
|
|
8
|
+
import { writtenFiles } from './turn-scenes.js';
|
|
9
|
+
const messages = createI18n({ catalogs: [{ en, es }] });
|
|
10
|
+
const t = (key, values) => messages.t(matchLocale((process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || 'en')
|
|
11
|
+
.replace('_', '-')
|
|
12
|
+
.split('.')[0], messages.locales), key, values);
|
|
13
|
+
/** A review step whose turn just wrote one of its own files, by the turn's own edit calls. */
|
|
14
|
+
export function reviewStepOf(chat, firstMessage) {
|
|
15
|
+
const step = REVIEW_STEPS.find((name) => name === chat.page);
|
|
16
|
+
if (!step || chat.change || !isPlanning(chat.work) || chat.title !== step)
|
|
17
|
+
return;
|
|
18
|
+
const written = [...writtenFiles(chat, firstMessage)];
|
|
19
|
+
return written.some((file) => stepOwnsFile(step, file)) ? step : undefined;
|
|
20
|
+
}
|
|
21
|
+
/** The step's last recorded model and effort, as its own turn asked for them. */
|
|
22
|
+
export function stepChoice(chat) {
|
|
23
|
+
const turn = chat.messages.findLast((message) => message.turn)?.turn;
|
|
24
|
+
const model = turn?.model.requested ?? undefined;
|
|
25
|
+
const effort = turn?.effort.requested ?? undefined;
|
|
26
|
+
return {
|
|
27
|
+
...(model && model !== 'auto' ? { model } : {}),
|
|
28
|
+
...(effort && effort !== 'auto' ? { effort } : {}),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const files = (steps) => steps.flatMap((step) => stepSaveFiles[step]).join(', ') || t('fresh.none');
|
|
32
|
+
export function reviewPrompt(step) {
|
|
33
|
+
const earlier = REVIEW_STEPS.slice(0, REVIEW_STEPS.indexOf(step));
|
|
34
|
+
const shape = JSON.stringify({ findings: [t('fresh.example')] });
|
|
35
|
+
return `${t('fresh.review', { step, files: files([step]), earlier: files(earlier) })}\n${shape}\n${t('fresh.reviewLimit')}\n`;
|
|
36
|
+
}
|
|
37
|
+
export function critiquePrompt(report) {
|
|
38
|
+
return `${t('fresh.critique', { report: report ? `${report}/report.json` : 'prototype/snapshots/' })}\n`;
|
|
39
|
+
}
|
|
40
|
+
/** The findings in a reviewer's answer: one JSON object, perhaps fenced; else none. */
|
|
41
|
+
export function parseFindings(text) {
|
|
42
|
+
const start = text.indexOf('{');
|
|
43
|
+
const end = text.lastIndexOf('}');
|
|
44
|
+
if (start < 0 || end <= start)
|
|
45
|
+
return;
|
|
46
|
+
let value;
|
|
47
|
+
try {
|
|
48
|
+
value = JSON.parse(text.slice(start, end + 1));
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const list = value?.findings;
|
|
54
|
+
if (!Array.isArray(list))
|
|
55
|
+
return;
|
|
56
|
+
const findings = list
|
|
57
|
+
.filter((item) => typeof item === 'string')
|
|
58
|
+
.map((item) => item.replace(/\s+/g, ' ').trim())
|
|
59
|
+
.filter((item) => item.length > 0 && item.length <= FINDING_LENGTH)
|
|
60
|
+
.slice(0, MAX_FINDINGS);
|
|
61
|
+
// Findings that were all malformed are no answer, never a clean read.
|
|
62
|
+
return list.length && !findings.length ? undefined : findings;
|
|
63
|
+
}
|
|
64
|
+
/** The report's shape in the ape-critique skill: its title and the sections it always has. */
|
|
65
|
+
const CRITIQUE_SECTIONS = [/^## Scores\b/m, /^## Keep\b/m, /^## Fix\b/m];
|
|
66
|
+
/**
|
|
67
|
+
* The critique's Markdown, without a fence the agent may have wrapped it in; none unless it has
|
|
68
|
+
* the skill's shape (a reply such as "I couldn't write the file" is not a critique).
|
|
69
|
+
*/
|
|
70
|
+
export function critiqueText(text) {
|
|
71
|
+
const fenced = /^```(?:markdown|md)?\r?\n([\s\S]*?)\r?\n```\s*$/.exec(text.trim());
|
|
72
|
+
const body = (fenced?.[1] ?? text).trim();
|
|
73
|
+
if (!/^# Critique\b/.test(body) || !CRITIQUE_SECTIONS.every((section) => section.test(body)))
|
|
74
|
+
return;
|
|
75
|
+
return `${body.slice(0, 200_000)}\n`;
|
|
76
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Chat } from '@buffcore/contracts/workbench';
|
|
2
|
+
/** A Prototype step's own chat: its turns draw the scenes and take the snapshots. */
|
|
3
|
+
export declare const prototypeTurn: (chat: Chat) => boolean;
|
|
4
|
+
/**
|
|
5
|
+
* The newest report's folder (`prototype/snapshots/<commit>`) when it is full, passed and was
|
|
6
|
+
* written at or after `since` (the turn's start): a report the turn never took does not count.
|
|
7
|
+
*/
|
|
8
|
+
export declare function passingFullReport(root: string, since: number): Promise<string | undefined>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// The snapshot a Prototype turn's own `ape prototype snapshot` wrote: the newest report under
|
|
2
|
+
// prototype/snapshots/, read only. A full one (no scene filter) with no problems passed.
|
|
3
|
+
import { readdir, readFile } from 'node:fs/promises';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
const isReport = (value) => {
|
|
6
|
+
const report = value;
|
|
7
|
+
return (typeof report?.commit === 'string' &&
|
|
8
|
+
/^[a-f0-9]{7,64}$/.test(report.commit) &&
|
|
9
|
+
typeof report.createdAt === 'string' &&
|
|
10
|
+
Array.isArray(report.problems));
|
|
11
|
+
};
|
|
12
|
+
/** A Prototype step's own chat: its turns draw the scenes and take the snapshots. */
|
|
13
|
+
export const prototypeTurn = (chat) => chat.page === 'prototype' && chat.title === 'prototype' && chat.work === 'design';
|
|
14
|
+
/**
|
|
15
|
+
* The newest report's folder (`prototype/snapshots/<commit>`) when it is full, passed and was
|
|
16
|
+
* written at or after `since` (the turn's start): a report the turn never took does not count.
|
|
17
|
+
*/
|
|
18
|
+
export async function passingFullReport(root, since) {
|
|
19
|
+
const dir = join(root, 'prototype', 'snapshots');
|
|
20
|
+
const folders = await readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
21
|
+
const reports = await Promise.all(folders
|
|
22
|
+
.filter((folder) => folder.isDirectory() && !folder.isSymbolicLink())
|
|
23
|
+
.map((folder) => readFile(join(dir, folder.name, 'report.json'), 'utf8').then((text) => {
|
|
24
|
+
const report = JSON.parse(text);
|
|
25
|
+
return isReport(report) && report.commit === folder.name ? report : undefined;
|
|
26
|
+
}, () => undefined)));
|
|
27
|
+
const newest = reports
|
|
28
|
+
.filter((report) => report !== undefined)
|
|
29
|
+
.sort((a, b) => b.createdAt.localeCompare(a.createdAt))[0];
|
|
30
|
+
if (!newest || newest.scene !== undefined || newest.problems.length)
|
|
31
|
+
return;
|
|
32
|
+
const created = Date.parse(newest.createdAt);
|
|
33
|
+
if (!(created >= since))
|
|
34
|
+
return;
|
|
35
|
+
return `prototype/snapshots/${newest.commit}`;
|
|
36
|
+
}
|