@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,64 @@
|
|
|
1
|
+
// The fresh turns' routes: read a step's review or the critique, Take or Leave a finding, and the
|
|
2
|
+
// review's setting (Settings › Agents), kept in plan/agents.md with the other agent settings.
|
|
3
|
+
import { freshAnswerBody, freshReplySchema, freshStepSchema, reviewSettingBody, } from '@buffcore/contracts/workbench';
|
|
4
|
+
import { readAgentsFile, writeAgentsFile } from '../../agents-file.js';
|
|
5
|
+
import { queueAgentsWrite } from '../agents-route.js';
|
|
6
|
+
import { factsChanged } from '../merge-events.js';
|
|
7
|
+
import { t } from './prompt.js';
|
|
8
|
+
const invalid = { status: 400, body: { error: t('chat.invalid') } };
|
|
9
|
+
async function saveSetting(root, on) {
|
|
10
|
+
const before = (await readAgentsFile(root)) ?? {
|
|
11
|
+
default: 'claude',
|
|
12
|
+
work: {},
|
|
13
|
+
level: 'guide',
|
|
14
|
+
};
|
|
15
|
+
const { review: _old, ...rest } = before;
|
|
16
|
+
if ((before.review !== false) === on)
|
|
17
|
+
return;
|
|
18
|
+
await writeAgentsFile(root, on ? rest : { ...rest, review: false });
|
|
19
|
+
factsChanged('levels', 'unsaved');
|
|
20
|
+
}
|
|
21
|
+
export function freshRoutes(fresh, root) {
|
|
22
|
+
return [
|
|
23
|
+
{
|
|
24
|
+
method: 'GET',
|
|
25
|
+
path: '/api/fresh/:step',
|
|
26
|
+
right: 'read:chats',
|
|
27
|
+
handle: ({ params }) => {
|
|
28
|
+
const step = freshStepSchema.safeParse(params.step);
|
|
29
|
+
if (!step.success)
|
|
30
|
+
return invalid;
|
|
31
|
+
return { status: 200, body: freshReplySchema.parse(fresh.read(step.data)) };
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
method: 'POST',
|
|
36
|
+
path: '/api/fresh/:step/answer',
|
|
37
|
+
right: 'build',
|
|
38
|
+
origin: true,
|
|
39
|
+
handle: async ({ params, body }) => {
|
|
40
|
+
const step = freshStepSchema.safeParse(params.step);
|
|
41
|
+
const answer = freshAnswerBody.safeParse(await body().catch(() => undefined));
|
|
42
|
+
if (!step.success || step.data === 'prototype' || !answer.success)
|
|
43
|
+
return invalid;
|
|
44
|
+
const { id, answer: choice } = answer.data;
|
|
45
|
+
return fresh.answer(step.data, id, choice)
|
|
46
|
+
? { status: 200, body: { ok: true } }
|
|
47
|
+
: { status: 404, body: { error: t('chat.missing') } };
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
method: 'POST',
|
|
52
|
+
path: '/api/agents/review',
|
|
53
|
+
right: 'settings',
|
|
54
|
+
origin: true,
|
|
55
|
+
handle: async ({ body }) => {
|
|
56
|
+
const setting = reviewSettingBody.safeParse(await body().catch(() => undefined));
|
|
57
|
+
if (!setting.success)
|
|
58
|
+
return invalid;
|
|
59
|
+
await queueAgentsWrite(root, () => saveSetting(root, setting.data.on));
|
|
60
|
+
return { status: 202, body: { ok: true } };
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The deny rules of the product's and the person's settings, as plain values a launch can quote. */
|
|
2
|
+
export declare function settingDenies(folder: string, home?: string): string[];
|
|
3
|
+
/** The turn's flag settings: hooks off, and the person's sign-in keys when they have any. */
|
|
4
|
+
export declare function freshSettings(home?: string): Record<string, unknown>;
|
|
5
|
+
/**
|
|
6
|
+
* The `--settings` value for one launch: the fixed JSON when the person has no sign-in keys, else
|
|
7
|
+
* a file of the launch's own (their values never pass through a command line), removed with it.
|
|
8
|
+
*/
|
|
9
|
+
export declare function openFreshSettings(home?: string): {
|
|
10
|
+
value: string;
|
|
11
|
+
close: () => void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// What a fresh turn keeps of the person's and the product's Claude settings, though it loads none
|
|
2
|
+
// of their files (`--setting-sources=`, so no allow rule can widen what it runs): their deny rules,
|
|
3
|
+
// and the person's sign-in setup. Never their allow rules, hooks or MCP servers.
|
|
4
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { homedir, tmpdir } from 'node:os';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { PLANNING_SETTINGS } from './permissions.js';
|
|
8
|
+
/** The product's settings files, under its folder. */
|
|
9
|
+
const PROJECT_SETTINGS = ['.claude/settings.json', '.claude/settings.local.json'];
|
|
10
|
+
/** The person's settings keys that only say how Claude Code signs in or reports. */
|
|
11
|
+
const SIGN_IN_KEYS = [
|
|
12
|
+
'env',
|
|
13
|
+
'apiKeyHelper',
|
|
14
|
+
'awsAuthRefresh',
|
|
15
|
+
'awsCredentialExport',
|
|
16
|
+
'otelHeadersHelper',
|
|
17
|
+
];
|
|
18
|
+
function settingsFile(path) {
|
|
19
|
+
try {
|
|
20
|
+
const value = JSON.parse(readFileSync(path, 'utf8'));
|
|
21
|
+
return value && typeof value === 'object' && !Array.isArray(value)
|
|
22
|
+
? value
|
|
23
|
+
: {};
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const denies = (settings) => {
|
|
30
|
+
const deny = settings.permissions?.deny;
|
|
31
|
+
return Array.isArray(deny)
|
|
32
|
+
? deny.filter((rule) => typeof rule === 'string' && rule.length <= 300 && !/["%!\r\n]/.test(rule))
|
|
33
|
+
: [];
|
|
34
|
+
};
|
|
35
|
+
/** The deny rules of the product's and the person's settings, as plain values a launch can quote. */
|
|
36
|
+
export function settingDenies(folder, home = homedir()) {
|
|
37
|
+
return [
|
|
38
|
+
...PROJECT_SETTINGS.map((file) => join(folder, file)),
|
|
39
|
+
join(home, '.claude', 'settings.json'),
|
|
40
|
+
]
|
|
41
|
+
.flatMap((file) => denies(settingsFile(file)))
|
|
42
|
+
.slice(0, 200);
|
|
43
|
+
}
|
|
44
|
+
/** The turn's flag settings: hooks off, and the person's sign-in keys when they have any. */
|
|
45
|
+
export function freshSettings(home = homedir()) {
|
|
46
|
+
const user = settingsFile(join(home, '.claude', 'settings.json'));
|
|
47
|
+
const signIn = Object.fromEntries(SIGN_IN_KEYS.filter((key) => user[key] !== undefined).map((key) => [key, user[key]]));
|
|
48
|
+
return { ...JSON.parse(PLANNING_SETTINGS), ...signIn };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The `--settings` value for one launch: the fixed JSON when the person has no sign-in keys, else
|
|
52
|
+
* a file of the launch's own (their values never pass through a command line), removed with it.
|
|
53
|
+
*/
|
|
54
|
+
export function openFreshSettings(home = homedir()) {
|
|
55
|
+
const settings = freshSettings(home);
|
|
56
|
+
if (Object.keys(settings).length === 1)
|
|
57
|
+
return { value: PLANNING_SETTINGS, close: () => { } };
|
|
58
|
+
const folder = mkdtempSync(join(tmpdir(), 'ape-fresh-'));
|
|
59
|
+
const file = join(folder, 'settings.json');
|
|
60
|
+
if (/["%!\r\n]/.test(file)) {
|
|
61
|
+
rmSync(folder, { recursive: true, force: true });
|
|
62
|
+
return { value: PLANNING_SETTINGS, close: () => { } };
|
|
63
|
+
}
|
|
64
|
+
writeFileSync(file, JSON.stringify(settings), { mode: 0o600 });
|
|
65
|
+
return { value: file, close: () => rmSync(folder, { recursive: true, force: true }) };
|
|
66
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type FreshCritique, type FreshReview, type ReviewStep } from '@buffcore/contracts/workbench';
|
|
2
|
+
export declare class FreshStore {
|
|
3
|
+
private readonly root;
|
|
4
|
+
constructor(root: string);
|
|
5
|
+
private file;
|
|
6
|
+
private read;
|
|
7
|
+
private write;
|
|
8
|
+
review(step: ReviewStep): FreshReview | undefined;
|
|
9
|
+
saveReview(step: ReviewStep, review: FreshReview): void;
|
|
10
|
+
critique(): FreshCritique | undefined;
|
|
11
|
+
saveCritique(critique: FreshCritique): void;
|
|
12
|
+
/** A studio that died left turns marked running: none runs now, so they failed. */
|
|
13
|
+
recover(): void;
|
|
14
|
+
/** Every report already critiqued, as `<checkout>|<report>`: none runs twice. */
|
|
15
|
+
critiqued(key: string): boolean;
|
|
16
|
+
markCritiqued(key: string): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Where fresh turns' answers are kept: beside the chats, in `.ape/fresh/` (never in git). One small
|
|
2
|
+
// file per planning step's review and one for the latest critique, replaced atomically.
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { freshCritiqueSchema, freshReviewSchema, REVIEW_STEPS, } from '@buffcore/contracts/workbench';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { plainPath } from './store.js';
|
|
9
|
+
const critiquedSchema = z.array(z.string().max(4000)).max(500);
|
|
10
|
+
export class FreshStore {
|
|
11
|
+
root;
|
|
12
|
+
constructor(root) {
|
|
13
|
+
this.root = root;
|
|
14
|
+
}
|
|
15
|
+
file(name) {
|
|
16
|
+
const ape = plainPath(join(this.root, '.ape'));
|
|
17
|
+
const folder = plainPath(join(ape, 'fresh'));
|
|
18
|
+
return plainPath(join(folder, `${name}.json`));
|
|
19
|
+
}
|
|
20
|
+
read(name, schema) {
|
|
21
|
+
try {
|
|
22
|
+
const parsed = schema.safeParse(JSON.parse(readFileSync(this.file(name), 'utf8')));
|
|
23
|
+
return parsed.success ? parsed.data : undefined;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
write(name, record) {
|
|
30
|
+
const file = this.file(name);
|
|
31
|
+
mkdirSync(join(file, '..'), { recursive: true, mode: 0o700 });
|
|
32
|
+
const temp = plainPath(`${file}.${randomUUID()}.tmp`);
|
|
33
|
+
writeFileSync(temp, JSON.stringify(record), { mode: 0o600 });
|
|
34
|
+
renameSync(temp, file);
|
|
35
|
+
}
|
|
36
|
+
review(step) {
|
|
37
|
+
return this.read(`review-${step}`, freshReviewSchema);
|
|
38
|
+
}
|
|
39
|
+
saveReview(step, review) {
|
|
40
|
+
this.write(`review-${step}`, freshReviewSchema.parse(review));
|
|
41
|
+
}
|
|
42
|
+
critique() {
|
|
43
|
+
return this.read('critique', freshCritiqueSchema);
|
|
44
|
+
}
|
|
45
|
+
saveCritique(critique) {
|
|
46
|
+
this.write('critique', freshCritiqueSchema.parse(critique));
|
|
47
|
+
}
|
|
48
|
+
/** A studio that died left turns marked running: none runs now, so they failed. */
|
|
49
|
+
recover() {
|
|
50
|
+
for (const step of REVIEW_STEPS) {
|
|
51
|
+
const review = this.review(step);
|
|
52
|
+
if (review?.state === 'running')
|
|
53
|
+
this.saveReview(step, { ...review, state: 'failed' });
|
|
54
|
+
}
|
|
55
|
+
const critique = this.critique();
|
|
56
|
+
if (critique?.state === 'running')
|
|
57
|
+
this.saveCritique({ ...critique, state: 'failed' });
|
|
58
|
+
}
|
|
59
|
+
/** Every report already critiqued, as `<checkout>|<report>`: none runs twice. */
|
|
60
|
+
critiqued(key) {
|
|
61
|
+
return this.read('critiqued', critiquedSchema)?.includes(key) ?? false;
|
|
62
|
+
}
|
|
63
|
+
markCritiqued(key) {
|
|
64
|
+
const known = this.read('critiqued', critiquedSchema) ?? [];
|
|
65
|
+
this.write('critiqued', [...known.filter((item) => item !== key), key].slice(-500));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Chat, FreshReply, FreshStep, ReviewStep } from '@buffcore/contracts/workbench';
|
|
2
|
+
import { type Start, stopTree } from '../runner.ts';
|
|
3
|
+
import { type CritiqueSource } from './fresh-critique.ts';
|
|
4
|
+
import { FreshStore } from './fresh-store.ts';
|
|
5
|
+
export declare class FreshLooks {
|
|
6
|
+
readonly store: FreshStore;
|
|
7
|
+
private readonly root;
|
|
8
|
+
private readonly start;
|
|
9
|
+
private readonly stop;
|
|
10
|
+
private readonly runs;
|
|
11
|
+
/** A step whose files changed again while its review ran: read once more after it. */
|
|
12
|
+
private readonly again;
|
|
13
|
+
private readonly critiques;
|
|
14
|
+
private closed;
|
|
15
|
+
constructor(root: string, start: Start, stop?: typeof stopTree);
|
|
16
|
+
private settings;
|
|
17
|
+
/**
|
|
18
|
+
* A turn ended: a planning step that wrote its own files gets a review; a Prototype turn that
|
|
19
|
+
* took a passing full snapshot since `startedAt` gets the critique.
|
|
20
|
+
*/
|
|
21
|
+
afterTurn(chat: Chat, firstMessage: number, startedAt?: number): void;
|
|
22
|
+
private review;
|
|
23
|
+
/** A full studio snapshot passed: the critique runs once per report, as its own turn. */
|
|
24
|
+
afterSnapshot(source: CritiqueSource, report?: string): boolean;
|
|
25
|
+
read(step: FreshStep): FreshReply;
|
|
26
|
+
/** Take or Leave one finding; false when the step has no such finding. */
|
|
27
|
+
answer(step: ReviewStep, id: string, answer: 'take' | 'leave'): boolean;
|
|
28
|
+
running(): number;
|
|
29
|
+
/** The studio is closing: stop every fresh turn; nothing is recorded after. */
|
|
30
|
+
close(): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const en = {
|
|
2
|
+
'fresh.review': 'You are a fresh reviewer, not the agent that wrote this step. Follow AGENTS.md. Read only: change no file and run no command. The step: {step}. Its files: {files}. The earlier steps’ files: {earlier}. Read them, then check the step against the brief, the earlier steps and the product’s rules in AGENTS.md: what is missing, what contradicts an earlier step, what breaks a rule. Reply with only one JSON object, nothing before or after it, in this shape:',
|
|
3
|
+
'fresh.reviewLimit': 'At most seven findings, each one plain sentence the person can act on; an empty list when the step holds up.',
|
|
4
|
+
'fresh.example': 'One sentence the person can act on.',
|
|
5
|
+
'fresh.none': 'none yet',
|
|
6
|
+
'fresh.critique': 'Follow AGENTS.md and the ape-critique skill: read .claude/skills/ape-critique/SKILL.md first, since this turn loads no skills by itself. You are the fresh agent it asks for: you did not draw these scenes, so read the repository and the passing full snapshot ({report}), not anyone’s account of them. Read only: change no file; you may run exactly `pnpm ape design check` and `pnpm ape i18n check`. In this fresh studio turn you do not write design/critique.md: reply with the report’s full Markdown in the skill’s shape (from “# Critique” through Scores, the seven dimensions, Keep, Fix and Quick wins) and nothing else, and the studio writes the file.',
|
|
7
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const es = {
|
|
2
|
+
'fresh.review': 'Eres un revisor nuevo, no el agente que escribió este paso. Sigue AGENTS.md. Solo lectura: no cambies ningún archivo ni ejecutes ningún comando. El paso: {step}. Sus archivos: {files}. Los archivos de los pasos anteriores: {earlier}. Léelos y revisa el paso frente al resumen, los pasos anteriores y las reglas del producto en AGENTS.md: qué falta, qué contradice un paso anterior, qué rompe una regla. Responde solo con un objeto JSON, sin nada antes ni después, con esta forma:',
|
|
3
|
+
'fresh.reviewLimit': 'Como mucho siete hallazgos, cada uno una frase sencilla sobre la que la persona pueda actuar; una lista vacía cuando el paso se sostiene.',
|
|
4
|
+
'fresh.example': 'Una frase sobre la que la persona pueda actuar.',
|
|
5
|
+
'fresh.none': 'ninguno aún',
|
|
6
|
+
'fresh.critique': 'Sigue AGENTS.md y la habilidad ape-critique: lee primero .claude/skills/ape-critique/SKILL.md, porque este turno no carga habilidades por sí solo. Eres el agente nuevo que pide: no dibujaste estas escenas, así que lee el repositorio y la captura completa que pasó ({report}), no el relato de nadie sobre ellas. Solo lectura: no cambies ningún archivo; puedes ejecutar exactamente `pnpm ape design check` y `pnpm ape i18n check`. En este turno nuevo del estudio no escribes design/critique.md: responde con el Markdown completo del informe con la forma de la habilidad (desde “# Critique” con Scores, las siete dimensiones, Keep, Fix y Quick wins) y nada más, y el estudio escribe el archivo.',
|
|
7
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Fresh agents' turns (0.8.43). After a planning step's turn writes the step's files, a fresh,
|
|
2
|
+
// read-only reviewer reads the step; after a passing full prototype snapshot, a fresh turn writes
|
|
3
|
+
// the critique (fresh-critique.ts). Neither is a chat: neither holds the step's tree, its session
|
|
4
|
+
// or its Save.
|
|
5
|
+
import { randomUUID } from 'node:crypto';
|
|
6
|
+
import { readFileSync } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { parseAgentsFile } from '../../agents-file.js';
|
|
9
|
+
import { stopTree } from '../runner.js';
|
|
10
|
+
import { CritiqueTurns, keep } from './fresh-critique.js';
|
|
11
|
+
import { runFresh, stopFresh } from './fresh-launch.js';
|
|
12
|
+
import { parseFindings, reviewPrompt, reviewStepOf, stepChoice } from './fresh-prompts.js';
|
|
13
|
+
import { prototypeTurn } from './fresh-report.js';
|
|
14
|
+
import { FreshStore } from './fresh-store.js';
|
|
15
|
+
import { hostLaunched } from './host-launched.js';
|
|
16
|
+
export class FreshLooks {
|
|
17
|
+
store;
|
|
18
|
+
root;
|
|
19
|
+
start;
|
|
20
|
+
stop;
|
|
21
|
+
runs = new Map();
|
|
22
|
+
/** A step whose files changed again while its review ran: read once more after it. */
|
|
23
|
+
again = new Map();
|
|
24
|
+
critiques;
|
|
25
|
+
closed = false;
|
|
26
|
+
constructor(root, start, stop = stopTree) {
|
|
27
|
+
this.root = root;
|
|
28
|
+
this.store = new FreshStore(root);
|
|
29
|
+
keep(() => this.store.recover());
|
|
30
|
+
this.start = start;
|
|
31
|
+
this.stop = stop;
|
|
32
|
+
this.critiques = new CritiqueTurns(root, start, stop, this.store, () => this.settings());
|
|
33
|
+
}
|
|
34
|
+
settings() {
|
|
35
|
+
try {
|
|
36
|
+
return parseAgentsFile(readFileSync(join(this.root, 'plan', 'agents.md'), 'utf8'));
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A turn ended: a planning step that wrote its own files gets a review; a Prototype turn that
|
|
44
|
+
* took a passing full snapshot since `startedAt` gets the critique.
|
|
45
|
+
*/
|
|
46
|
+
afterTurn(chat, firstMessage, startedAt) {
|
|
47
|
+
if (this.closed)
|
|
48
|
+
return;
|
|
49
|
+
if (prototypeTurn(chat) && startedAt !== undefined)
|
|
50
|
+
void this.critiques.afterTurn(startedAt);
|
|
51
|
+
const step = reviewStepOf(chat, firstMessage);
|
|
52
|
+
if (!step || chat.agent !== 'claude')
|
|
53
|
+
return;
|
|
54
|
+
if (this.settings()?.review === false)
|
|
55
|
+
return;
|
|
56
|
+
const choice = stepChoice(chat);
|
|
57
|
+
if (this.runs.has(step))
|
|
58
|
+
this.again.set(step, choice);
|
|
59
|
+
else
|
|
60
|
+
this.review(step, choice);
|
|
61
|
+
}
|
|
62
|
+
review(step, choice) {
|
|
63
|
+
const record = { agent: 'claude', at: new Date().toISOString(), findings: [] };
|
|
64
|
+
keep(() => this.store.saveReview(step, { ...record, state: 'running' }));
|
|
65
|
+
const run = runFresh(this.start, {
|
|
66
|
+
folder: this.root,
|
|
67
|
+
prompt: reviewPrompt(step),
|
|
68
|
+
host: hostLaunched(this.root),
|
|
69
|
+
...choice,
|
|
70
|
+
});
|
|
71
|
+
this.runs.set(step, run);
|
|
72
|
+
void run.result.then(({ text, seconds }) => {
|
|
73
|
+
this.runs.delete(step);
|
|
74
|
+
if (this.closed)
|
|
75
|
+
return;
|
|
76
|
+
const found = text === undefined ? undefined : parseFindings(text);
|
|
77
|
+
const findings = (found ?? []).map((finding) => ({ id: randomUUID(), text: finding }));
|
|
78
|
+
const state = found ? 'done' : 'failed';
|
|
79
|
+
keep(() => this.store.saveReview(step, { ...record, state, seconds, findings }));
|
|
80
|
+
const next = this.again.get(step);
|
|
81
|
+
this.again.delete(step);
|
|
82
|
+
if (next)
|
|
83
|
+
this.review(step, next);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/** A full studio snapshot passed: the critique runs once per report, as its own turn. */
|
|
87
|
+
afterSnapshot(source, report) {
|
|
88
|
+
return this.critiques.after(source, report);
|
|
89
|
+
}
|
|
90
|
+
read(step) {
|
|
91
|
+
if (step === 'prototype') {
|
|
92
|
+
const critique = this.store.critique();
|
|
93
|
+
return critique ? { critique } : {};
|
|
94
|
+
}
|
|
95
|
+
const review = this.store.review(step);
|
|
96
|
+
return review ? { review } : {};
|
|
97
|
+
}
|
|
98
|
+
/** Take or Leave one finding; false when the step has no such finding. */
|
|
99
|
+
answer(step, id, answer) {
|
|
100
|
+
const review = this.store.review(step);
|
|
101
|
+
const finding = review?.findings.find((item) => item.id === id);
|
|
102
|
+
if (!review || !finding)
|
|
103
|
+
return false;
|
|
104
|
+
finding.answer = answer === 'take' ? 'taken' : 'left';
|
|
105
|
+
this.store.saveReview(step, review);
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
running() {
|
|
109
|
+
return this.runs.size + (this.critiques.running() ? 1 : 0);
|
|
110
|
+
}
|
|
111
|
+
/** The studio is closing: stop every fresh turn; nothing is recorded after. */
|
|
112
|
+
close() {
|
|
113
|
+
this.closed = true;
|
|
114
|
+
for (const run of this.runs.values())
|
|
115
|
+
stopFresh(run, this.stop);
|
|
116
|
+
this.critiques.close();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -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';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The limit a command's text mentions, as the card names it (`git push`, `ape deploy`,
|
|
3
|
-
* `.env.production`, `curl`); nothing when it mentions none.
|
|
2
|
+
* The limit a command's text mentions, as the card names it (`git push`, `ape deploy`,
|
|
3
|
+
* `npm publish`, `gh release`, `.ssh`, `.env.production`, `curl`); nothing when it mentions none.
|
|
4
4
|
*/
|
|
5
5
|
export declare function mentionedLimit(command: string, cwd: string): string | undefined;
|