@buffcore/cli 0.8.42 → 0.8.43
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 +11 -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/codex-idle.d.ts +1 -0
- package/dist/commands/ui/chat/fresh-critique.d.ts +28 -0
- package/dist/commands/ui/chat/fresh-critique.js +121 -0
- package/dist/commands/ui/chat/fresh-launch.d.ts +31 -0
- package/dist/commands/ui/chat/fresh-launch.js +122 -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 +112 -0
- package/dist/commands/ui/chat/limit-mentions.d.ts +2 -2
- package/dist/commands/ui/chat/limit-mentions.js +22 -2
- package/dist/commands/ui/chat/limits.d.ts +8 -1
- 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 +13 -1
- 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 +15 -0
- package/dist/commands/ui/chat/publish-limits.d.ts +4 -0
- package/dist/commands/ui/chat/publish-limits.js +97 -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 +2 -0
- package/dist/commands/ui/chat/turn-guard.js +12 -0
- 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.js +18 -6
- 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 +6 -3
- package/dist/commands/ui/routes.js +3 -3
- package/dist/commands/ui/save-publish.js +3 -0
- package/dist/commands/ui/server.d.ts +7 -0
- package/dist/commands/ui/server.js +7 -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.js +4 -0
- package/dist/commands/ui/studio-state.d.ts +6 -4
- package/dist/commands/ui/studio-versions.d.ts +3 -3
- package/dist/ui/page.js +81 -81
- package/docs/PROCESS.md +5 -0
- package/docs/PROTOTYPE.md +20 -0
- package/docs/WORKBENCH.md +2 -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,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,112 @@
|
|
|
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
|
+
export class FreshLooks {
|
|
16
|
+
store;
|
|
17
|
+
root;
|
|
18
|
+
start;
|
|
19
|
+
stop;
|
|
20
|
+
runs = new Map();
|
|
21
|
+
/** A step whose files changed again while its review ran: read once more after it. */
|
|
22
|
+
again = new Map();
|
|
23
|
+
critiques;
|
|
24
|
+
closed = false;
|
|
25
|
+
constructor(root, start, stop = stopTree) {
|
|
26
|
+
this.root = root;
|
|
27
|
+
this.store = new FreshStore(root);
|
|
28
|
+
keep(() => this.store.recover());
|
|
29
|
+
this.start = start;
|
|
30
|
+
this.stop = stop;
|
|
31
|
+
this.critiques = new CritiqueTurns(root, start, stop, this.store, () => this.settings());
|
|
32
|
+
}
|
|
33
|
+
settings() {
|
|
34
|
+
try {
|
|
35
|
+
return parseAgentsFile(readFileSync(join(this.root, 'plan', 'agents.md'), 'utf8'));
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A turn ended: a planning step that wrote its own files gets a review; a Prototype turn that
|
|
43
|
+
* took a passing full snapshot since `startedAt` gets the critique.
|
|
44
|
+
*/
|
|
45
|
+
afterTurn(chat, firstMessage, startedAt) {
|
|
46
|
+
if (this.closed)
|
|
47
|
+
return;
|
|
48
|
+
if (prototypeTurn(chat) && startedAt !== undefined)
|
|
49
|
+
void this.critiques.afterTurn(startedAt);
|
|
50
|
+
const step = reviewStepOf(chat, firstMessage);
|
|
51
|
+
if (!step || chat.agent !== 'claude')
|
|
52
|
+
return;
|
|
53
|
+
if (this.settings()?.review === false)
|
|
54
|
+
return;
|
|
55
|
+
const choice = stepChoice(chat);
|
|
56
|
+
if (this.runs.has(step))
|
|
57
|
+
this.again.set(step, choice);
|
|
58
|
+
else
|
|
59
|
+
this.review(step, choice);
|
|
60
|
+
}
|
|
61
|
+
review(step, choice) {
|
|
62
|
+
const record = { agent: 'claude', at: new Date().toISOString(), findings: [] };
|
|
63
|
+
keep(() => this.store.saveReview(step, { ...record, state: 'running' }));
|
|
64
|
+
const run = runFresh(this.start, { folder: this.root, prompt: reviewPrompt(step), ...choice });
|
|
65
|
+
this.runs.set(step, run);
|
|
66
|
+
void run.result.then(({ text, seconds }) => {
|
|
67
|
+
this.runs.delete(step);
|
|
68
|
+
if (this.closed)
|
|
69
|
+
return;
|
|
70
|
+
const found = text === undefined ? undefined : parseFindings(text);
|
|
71
|
+
const findings = (found ?? []).map((finding) => ({ id: randomUUID(), text: finding }));
|
|
72
|
+
const state = found ? 'done' : 'failed';
|
|
73
|
+
keep(() => this.store.saveReview(step, { ...record, state, seconds, findings }));
|
|
74
|
+
const next = this.again.get(step);
|
|
75
|
+
this.again.delete(step);
|
|
76
|
+
if (next)
|
|
77
|
+
this.review(step, next);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/** A full studio snapshot passed: the critique runs once per report, as its own turn. */
|
|
81
|
+
afterSnapshot(source, report) {
|
|
82
|
+
return this.critiques.after(source, report);
|
|
83
|
+
}
|
|
84
|
+
read(step) {
|
|
85
|
+
if (step === 'prototype') {
|
|
86
|
+
const critique = this.store.critique();
|
|
87
|
+
return critique ? { critique } : {};
|
|
88
|
+
}
|
|
89
|
+
const review = this.store.review(step);
|
|
90
|
+
return review ? { review } : {};
|
|
91
|
+
}
|
|
92
|
+
/** Take or Leave one finding; false when the step has no such finding. */
|
|
93
|
+
answer(step, id, answer) {
|
|
94
|
+
const review = this.store.review(step);
|
|
95
|
+
const finding = review?.findings.find((item) => item.id === id);
|
|
96
|
+
if (!review || !finding)
|
|
97
|
+
return false;
|
|
98
|
+
finding.answer = answer === 'take' ? 'taken' : 'left';
|
|
99
|
+
this.store.saveReview(step, review);
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
running() {
|
|
103
|
+
return this.runs.size + (this.critiques.running() ? 1 : 0);
|
|
104
|
+
}
|
|
105
|
+
/** The studio is closing: stop every fresh turn; nothing is recorded after. */
|
|
106
|
+
close() {
|
|
107
|
+
this.closed = true;
|
|
108
|
+
for (const run of this.runs.values())
|
|
109
|
+
stopFresh(run, this.stop);
|
|
110
|
+
this.critiques.close();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -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;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* not a hole. Case does not count; line continuations are joined first, and the text is also read
|
|
6
6
|
* with its quotes and escapes taken out (`'gi't pu\sh`). Plain Node only: the hook runs it.
|
|
7
7
|
*/
|
|
8
|
+
import { VALUED_OPTIONS } from './publish-limits.js';
|
|
8
9
|
import { SECRET_FOLDERS } from './secret-folders.js';
|
|
9
10
|
const escaped = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
10
11
|
/** A word on its own, not inside a longer word or file name. */
|
|
@@ -30,6 +31,19 @@ const DOWNLOAD_NAMES = [
|
|
|
30
31
|
'downloadfile',
|
|
31
32
|
];
|
|
32
33
|
const DOWNLOADS = word(`(?:${DOWNLOAD_NAMES.join('|')})(?:\\.exe)?`, '(?![\\w.-])');
|
|
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. A path or a longer word (`src/publish.ts`,
|
|
36
|
+
// `publish-docs`) is not the subcommand; nor is one asked only for its help (`publish --help`,
|
|
37
|
+
// `npm help publish`), which is taken out of the text first.
|
|
38
|
+
const MANAGER = /(?<![\w.-])(npm|pnpm|yarn)(?![\w-])/i;
|
|
39
|
+
const PUBLISH = /(?<![\w./\\-])pu(?:b(?:l(?:i(?:sh?)?)?)?)?(?![\w./\\-])/i;
|
|
40
|
+
const GH = /(?<![\w.-])gh(?![\w-])/i;
|
|
41
|
+
const RELEASE = /(?<![\w./\\-])release(?![\w./\\-])/i;
|
|
42
|
+
const VERBS = 'create|new|upload|edit|delete(?:-asset)?';
|
|
43
|
+
const RELEASE_CHANGE = new RegExp(`(?<![\\w./\\\\-])(?:${VERBS})(?![\\w./\\\\-])`, 'i');
|
|
44
|
+
const HELP = new RegExp(`(?<![\\w./\\\\-])(?:(?:pu\\w*|${VERBS})\\s+(?:--help|-h)|help\\s+pu\\w*)(?=\\s*(?:$|[;&|)'"\\r\\n]))`, 'gi');
|
|
45
|
+
/** A value-taking option and its value (`--filter publish`): case counts, as `-C` is not `-c`. */
|
|
46
|
+
const VALUES = new RegExp(`(?<!\\S)(?:${VALUED_OPTIONS.join('|')})(?:\\s+|=)\\S+`, 'g');
|
|
33
47
|
const CERTUTIL = /(?<![\w.-])certutil(?:\.exe)?(?![\w-])/i;
|
|
34
48
|
const URLCACHE = /[-/]urlcache(?![\w-])/i;
|
|
35
49
|
const first = (pattern, text) => {
|
|
@@ -52,6 +66,12 @@ function mentionIn(text, cwd) {
|
|
|
52
66
|
return 'git push';
|
|
53
67
|
if (first(APE, text) && first(DEPLOY, text))
|
|
54
68
|
return 'ape deploy';
|
|
69
|
+
const asked = text.replace(HELP, '').replace(VALUES, ' ');
|
|
70
|
+
const manager = MANAGER.exec(asked)?.[1];
|
|
71
|
+
if (manager && PUBLISH.test(asked))
|
|
72
|
+
return `${manager.toLowerCase()} publish`;
|
|
73
|
+
if (GH.test(asked) && RELEASE.test(asked) && RELEASE_CHANGE.test(asked))
|
|
74
|
+
return 'gh release';
|
|
55
75
|
const settings = PRODUCTION.exec(text)?.[0];
|
|
56
76
|
if (settings)
|
|
57
77
|
return settings;
|
|
@@ -64,8 +84,8 @@ function mentionIn(text, cwd) {
|
|
|
64
84
|
return first(DOWNLOADS, text)?.toLowerCase();
|
|
65
85
|
}
|
|
66
86
|
/**
|
|
67
|
-
* The limit a command's text mentions, as the card names it (`git push`, `ape deploy`,
|
|
68
|
-
* `.env.production`, `curl`); nothing when it mentions none.
|
|
87
|
+
* The limit a command's text mentions, as the card names it (`git push`, `ape deploy`,
|
|
88
|
+
* `npm publish`, `gh release`, `.ssh`, `.env.production`, `curl`); nothing when it mentions none.
|
|
69
89
|
*/
|
|
70
90
|
export function mentionedLimit(command, cwd) {
|
|
71
91
|
const joined = command.replace(/[\\`^]\r?\n/g, '');
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type Unsure } from './command-parts.ts';
|
|
2
2
|
import { en } from './limits.en.ts';
|
|
3
|
-
|
|
3
|
+
/** 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 LimitKind = RefusedKind | 'download' | 'unsure';
|
|
4
6
|
export interface Limit {
|
|
5
7
|
/** `ask` sends the call to the person's Allow card; `deny` refuses it at every level. */
|
|
6
8
|
decision: 'deny' | 'ask';
|
|
@@ -22,6 +24,11 @@ export interface Limit {
|
|
|
22
24
|
export declare function secretPath(path: string, cwd: string): boolean;
|
|
23
25
|
/** The first limit a tool call crosses, refusals before asks; nothing when it crosses none. */
|
|
24
26
|
export declare function crossedLimit(tool: string, input: unknown, cwd: string): Limit | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* The limit a refused call's result names: the hook's own sentence for it, in either language,
|
|
29
|
+
* came back as the result. Nothing when it names none.
|
|
30
|
+
*/
|
|
31
|
+
export declare function refusalLimit(text: string): RefusedKind | undefined;
|
|
25
32
|
/** The agent's words in the turn's language (LANG), with `{name}` values filled in. */
|
|
26
33
|
export declare function limitText(key: keyof typeof en, values?: Record<string, string>): string;
|
|
27
34
|
/** The sentence the agent reads for a crossed limit: it names the refused part. */
|
|
@@ -4,6 +4,8 @@ export declare const en: {
|
|
|
4
4
|
readonly 'limits.deploy': '`{part}` is not allowed here: only a person deploys, from the studio.';
|
|
5
5
|
readonly 'limits.push': '`{part}` is not allowed here: the studio saves and shares the work, not the agent.';
|
|
6
6
|
readonly 'limits.settings': '`{part}` is not allowed here: production settings stay with a person.';
|
|
7
|
+
readonly 'limits.publish': '`{part}` is not allowed here: publishing a package stays with a person, from their own terminal.';
|
|
8
|
+
readonly 'limits.release': '`{part}` is not allowed here: publishing a release stays with a person, from their own terminal.';
|
|
7
9
|
readonly 'limits.download': '`{part}` downloads from the network: the person must allow it, and did not.';
|
|
8
10
|
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.';
|
|
9
11
|
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.';
|
|
@@ -4,6 +4,8 @@ export const en = {
|
|
|
4
4
|
'limits.deploy': '`{part}` is not allowed here: only a person deploys, from the studio.',
|
|
5
5
|
'limits.push': '`{part}` is not allowed here: the studio saves and shares the work, not the agent.',
|
|
6
6
|
'limits.settings': '`{part}` is not allowed here: production settings stay with a person.',
|
|
7
|
+
'limits.publish': '`{part}` is not allowed here: publishing a package stays with a person, from their own terminal.',
|
|
8
|
+
'limits.release': '`{part}` is not allowed here: publishing a release stays with a person, from their own terminal.',
|
|
7
9
|
'limits.download': '`{part}` downloads from the network: the person must allow it, and did not.',
|
|
8
10
|
'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.',
|
|
9
11
|
'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.',
|
|
@@ -3,6 +3,8 @@ export const es = {
|
|
|
3
3
|
'limits.deploy': '`{part}` no está permitido aquí: solo una persona publica, desde el estudio.',
|
|
4
4
|
'limits.push': '`{part}` no está permitido aquí: el estudio guarda y comparte el trabajo, no el agente.',
|
|
5
5
|
'limits.settings': '`{part}` no está permitido aquí: los ajustes de producción quedan en manos de una persona.',
|
|
6
|
+
'limits.publish': '`{part}` no está permitido aquí: publicar un paquete queda en manos de una persona, desde su propia terminal.',
|
|
7
|
+
'limits.release': '`{part}` no está permitido aquí: publicar una versión queda en manos de una persona, desde su propia terminal.',
|
|
6
8
|
'limits.download': '`{part}` descarga de la red: la persona debe permitirlo, y no lo hizo.',
|
|
7
9
|
'limits.unsure.mention': 'Este comando menciona `{mention}` y el estudio no pudo saber si lo ejecuta: la persona debe permitirlo, y no lo hizo.',
|
|
8
10
|
'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.',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The limits every turn keeps at every level, "Never ask" included: no reading folders of sign-ins
|
|
3
3
|
* or keys, no deploy, no production settings, no `git push`, and no network download without a
|
|
4
|
-
* person's click. The studio's hook (limits-hook.ts) runs this before each tool call; the
|
|
4
|
+
* person's click, and no publishing a package or a release. The studio's hook (limits-hook.ts) runs this before each tool call; the
|
|
5
5
|
* permission mode never decides them. Plain Node only: the hook runs it without the CLI.
|
|
6
6
|
*/
|
|
7
7
|
import { relative, resolve } from 'node:path';
|
|
@@ -12,6 +12,7 @@ import { mentionedLimit } from './limit-mentions.js';
|
|
|
12
12
|
import { patternReach } from './limit-patterns.js';
|
|
13
13
|
import { en } from './limits.en.js';
|
|
14
14
|
import { es } from './limits.es.js';
|
|
15
|
+
import { publishLimit } from './publish-limits.js';
|
|
15
16
|
import { holdsSecrets } from './secret-folders.js';
|
|
16
17
|
import { readsStdin } from './stdin-shells.js';
|
|
17
18
|
const SHELLS = new Map([
|
|
@@ -101,6 +102,9 @@ function wordsLimit(words, cwd) {
|
|
|
101
102
|
if (next === 'deploy' || server === 'deploy')
|
|
102
103
|
return { decision: 'deny', kind: 'deploy' };
|
|
103
104
|
}
|
|
105
|
+
const published = publishLimit(checked);
|
|
106
|
+
if (published)
|
|
107
|
+
return { decision: 'deny', kind: published };
|
|
104
108
|
if (checked.some((word) => DOWNLOADS.test(word)))
|
|
105
109
|
return { decision: 'ask', kind: 'download' };
|
|
106
110
|
// `certutil -urlcache` fetches a URL; its other uses read local files.
|
|
@@ -187,6 +191,14 @@ export function crossedLimit(tool, input, cwd) {
|
|
|
187
191
|
return { decision: 'ask', kind: 'download', part: fields.url };
|
|
188
192
|
}
|
|
189
193
|
const catalogs = { en, es };
|
|
194
|
+
const REFUSED = ['secrets', 'deploy', 'push', 'settings', 'publish', 'release'];
|
|
195
|
+
/**
|
|
196
|
+
* The limit a refused call's result names: the hook's own sentence for it, in either language,
|
|
197
|
+
* came back as the result. Nothing when it names none.
|
|
198
|
+
*/
|
|
199
|
+
export function refusalLimit(text) {
|
|
200
|
+
return REFUSED.find((kind) => Object.values(catalogs).some((words) => text.includes(words[`limits.${kind}`].replace('`{part}`', ''))));
|
|
201
|
+
}
|
|
190
202
|
/** The agent's words in the turn's language (LANG), with `{name}` values filled in. */
|
|
191
203
|
export function limitText(key, values = {}) {
|
|
192
204
|
const locale = (process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || 'en')
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { choiceReply } from './choice-reply.js';
|
|
2
2
|
import { permissionMode } from './claude-permissions.js';
|
|
3
3
|
import { isClaudeTaskOutput } from './claude-task-output.js';
|
|
4
|
+
import { refusalLimit } from './limits.js';
|
|
4
5
|
import { buildArgs, failure, jsonLine, object, t } from './prompt.js';
|
|
5
6
|
const verbs = {
|
|
6
7
|
read: 'read',
|
|
@@ -66,9 +67,12 @@ function refusalEvents(value) {
|
|
|
66
67
|
block.is_error !== true ||
|
|
67
68
|
typeof block.tool_use_id !== 'string')
|
|
68
69
|
return [];
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
const text = JSON.stringify(block.content);
|
|
71
|
+
// The studio's limits hook refused it: its own sentence is the result.
|
|
72
|
+
const limit = refusalLimit(text);
|
|
73
|
+
if (limit)
|
|
74
|
+
return [{ kind: 'refused', id: block.tool_use_id, limit }];
|
|
75
|
+
return permissionRefused(text) ? [{ kind: 'refused', id: block.tool_use_id }] : [];
|
|
72
76
|
}
|
|
73
77
|
/** Claude's result lists the tool and input, with no structured permission decision. */
|
|
74
78
|
function refusalReason(tool) {
|
|
@@ -101,6 +101,9 @@ async function ask(turn, call, closed, wait) {
|
|
|
101
101
|
if (closed.aborted)
|
|
102
102
|
return { allow: false, message: refusal(askCard(call, turn), 'ended') };
|
|
103
103
|
const card = askCard(call, turn);
|
|
104
|
+
// A limit is never the person's to allow: the hook refuses it first, and so does the card.
|
|
105
|
+
if (card.limit?.decision === 'deny')
|
|
106
|
+
return { allow: false, message: limitReason(card.limit) };
|
|
104
107
|
if (keptSince(turn, call, card))
|
|
105
108
|
return { allow: true };
|
|
106
109
|
const id = randomUUID();
|
|
@@ -14,6 +14,21 @@ export const LIMIT_COMMANDS = [
|
|
|
14
14
|
'pnpm ape server deploy',
|
|
15
15
|
'npx ape deploy',
|
|
16
16
|
'npx ape server deploy',
|
|
17
|
+
'npm publish',
|
|
18
|
+
// npm resolves a shortened command name: from `npm pu`, it can only mean `npm publish`.
|
|
19
|
+
'npm pu',
|
|
20
|
+
'npm pub',
|
|
21
|
+
'npm publ',
|
|
22
|
+
'npm publi',
|
|
23
|
+
'npm publis',
|
|
24
|
+
'pnpm publish',
|
|
25
|
+
'yarn publish',
|
|
26
|
+
'yarn npm publish',
|
|
27
|
+
'gh release create',
|
|
28
|
+
'gh release new',
|
|
29
|
+
'gh release upload',
|
|
30
|
+
'gh release edit',
|
|
31
|
+
'gh release delete',
|
|
17
32
|
];
|
|
18
33
|
/** The production settings files the limits hook refuses (`.env.production`, `.env.prod`, `.env.staging`). */
|
|
19
34
|
export const PRODUCTION_FILES = ['.env.prod*', '.env.staging*'];
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Every option above, for the text fallback: their values are values, not a subcommand. */
|
|
2
|
+
export declare const VALUED_OPTIONS: string[];
|
|
3
|
+
/** The publishing limit a part's words cross: a package or a release; nothing otherwise. */
|
|
4
|
+
export declare function publishLimit(words: string[]): 'publish' | 'release' | undefined;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The publishing commands the limits refuse: a package (`npm publish`, and npm's shortened names
|
|
3
|
+
* down to `npm pu`; `pnpm publish`, `yarn publish`, `yarn npm publish`) and a release
|
|
4
|
+
* (`gh release create|new|upload|edit|delete`, and `delete-asset`). Every package manager or `gh`
|
|
5
|
+
* named in a part is read, so `npx npm publish`, `pnpm exec npm publish` and `env X=1 npm publish`
|
|
6
|
+
* count too. Before the subcommand, the options each tool takes a value for skip that value
|
|
7
|
+
* (`npm --registry x publish`, `gh -R owner/repo release create`); after any other option the next
|
|
8
|
+
* word is the subcommand, so `pnpm --filter publish build` runs (a shape the parse does not follow
|
|
9
|
+
* still goes to the card through the text fallback). Asking only for help (`pnpm publish --help`)
|
|
10
|
+
* runs. Plain Node only: the hook runs it.
|
|
11
|
+
*/
|
|
12
|
+
import { programName } from './command-parts.js';
|
|
13
|
+
/** The options before the subcommand that take the next word as their value, per tool. */
|
|
14
|
+
const VALUED = {
|
|
15
|
+
npm: new Set([
|
|
16
|
+
'--registry',
|
|
17
|
+
'--prefix',
|
|
18
|
+
'-C',
|
|
19
|
+
'--workspace',
|
|
20
|
+
'-w',
|
|
21
|
+
'--userconfig',
|
|
22
|
+
'--globalconfig',
|
|
23
|
+
'--cache',
|
|
24
|
+
'--loglevel',
|
|
25
|
+
'--otp',
|
|
26
|
+
'--tag',
|
|
27
|
+
'--access',
|
|
28
|
+
'--scope',
|
|
29
|
+
'--location',
|
|
30
|
+
]),
|
|
31
|
+
pnpm: new Set([
|
|
32
|
+
'-C',
|
|
33
|
+
'--dir',
|
|
34
|
+
'--filter',
|
|
35
|
+
'-F',
|
|
36
|
+
'--filter-prod',
|
|
37
|
+
'--workspace-dir',
|
|
38
|
+
'--registry',
|
|
39
|
+
'--reporter',
|
|
40
|
+
'--loglevel',
|
|
41
|
+
'--store-dir',
|
|
42
|
+
'--modules-dir',
|
|
43
|
+
'--lockfile-dir',
|
|
44
|
+
'--tag',
|
|
45
|
+
'--access',
|
|
46
|
+
'--otp',
|
|
47
|
+
'--publish-branch',
|
|
48
|
+
]),
|
|
49
|
+
yarn: new Set(['--cwd', '--registry', '--otp', '--tag', '--access', '--modules-folder']),
|
|
50
|
+
gh: new Set(['-R', '--repo', '--hostname']),
|
|
51
|
+
};
|
|
52
|
+
/** Every option above, for the text fallback: their values are values, not a subcommand. */
|
|
53
|
+
export const VALUED_OPTIONS = [
|
|
54
|
+
...new Set(Object.values(VALUED).flatMap((options) => [...options])),
|
|
55
|
+
];
|
|
56
|
+
const RELEASE = new Set(['create', 'new', 'upload', 'edit', 'delete', 'delete-asset']);
|
|
57
|
+
/** npm resolves a shortened command name: from `pu`, the only name it can mean is `publish`. */
|
|
58
|
+
const PUBLISHES = {
|
|
59
|
+
npm: (word) => word.length >= 2 && 'publish'.startsWith(word),
|
|
60
|
+
pnpm: (word) => word === 'publish',
|
|
61
|
+
yarn: (word) => word === 'publish',
|
|
62
|
+
};
|
|
63
|
+
const HELP = new Set(['--help', '-h']);
|
|
64
|
+
/** The program a word names, without a pinned version (`npm@10`, `pnpm@latest`). */
|
|
65
|
+
const toolName = (word) => programName(word).replace(/(?<=.)@[^@]*$/, '');
|
|
66
|
+
/** The index of the subcommand after `from` when `wanted` accepts it; -1 otherwise. */
|
|
67
|
+
function subcommandIs(words, from, valued, wanted) {
|
|
68
|
+
for (let index = from; index < words.length; index++) {
|
|
69
|
+
const word = words[index];
|
|
70
|
+
if (!word.startsWith('-'))
|
|
71
|
+
return wanted(word.toLowerCase()) ? index : -1;
|
|
72
|
+
if (valued.has(word))
|
|
73
|
+
index++;
|
|
74
|
+
}
|
|
75
|
+
return -1;
|
|
76
|
+
}
|
|
77
|
+
/** A subcommand followed only by `--help` or `-h` shows its help and does nothing else. */
|
|
78
|
+
const helpOnly = (words, at) => words.length === at + 2 && HELP.has(words[at + 1]);
|
|
79
|
+
/** The publishing limit a part's words cross: a package or a release; nothing otherwise. */
|
|
80
|
+
export function publishLimit(words) {
|
|
81
|
+
for (let index = 0; index < words.length; index++) {
|
|
82
|
+
const name = toolName(words[index]);
|
|
83
|
+
const publishes = PUBLISHES[name];
|
|
84
|
+
if (publishes) {
|
|
85
|
+
const at = subcommandIs(words, index + 1, VALUED[name], publishes);
|
|
86
|
+
if (at >= 0 && !helpOnly(words, at))
|
|
87
|
+
return 'publish';
|
|
88
|
+
}
|
|
89
|
+
if (name !== 'gh')
|
|
90
|
+
continue;
|
|
91
|
+
const valued = VALUED.gh;
|
|
92
|
+
const release = subcommandIs(words, index + 1, valued, (word) => word === 'release');
|
|
93
|
+
const at = release < 0 ? -1 : subcommandIs(words, release + 1, valued, (w) => RELEASE.has(w));
|
|
94
|
+
if (at >= 0 && !helpOnly(words, at))
|
|
95
|
+
return 'release';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -9,6 +9,7 @@ import { lineLocale, lineText } from './stream-text.js';
|
|
|
9
9
|
export function recordTurnEnd(run, failed, unsaved) {
|
|
10
10
|
if (!run.launched || run.startedAt === undefined)
|
|
11
11
|
return;
|
|
12
|
+
const startedAt = run.startedAt;
|
|
12
13
|
endTurn(run.chat, run.startedAt, run.firstMessage ?? 0, failed, unsaved, run.stopped === true);
|
|
13
14
|
const end = run.chat.messages.at(-1)?.end;
|
|
14
15
|
if (end && !failed && !run.stopped && run.scenes?.length)
|
|
@@ -17,6 +18,8 @@ export function recordTurnEnd(run, failed, unsaved) {
|
|
|
17
18
|
// The turn may have edited files: the unsaved list the studio holds is from before it.
|
|
18
19
|
factsChanged('unsaved');
|
|
19
20
|
delete run.startedAt;
|
|
21
|
+
if (!failed && !run.stopped)
|
|
22
|
+
run.fresh?.afterTurn(run.chat, run.firstMessage ?? 0, startedAt);
|
|
20
23
|
}
|
|
21
24
|
/** End facts come from the studio clock and stored calls, never agent usage or timing. */
|
|
22
25
|
export function endTurn(chat, startedAt, firstMessage, failed, unsaved, stopped = false) {
|
|
@@ -115,8 +115,11 @@ class TurnStream {
|
|
|
115
115
|
const { chat, folder } = this.options;
|
|
116
116
|
if (event.kind === 'refused') {
|
|
117
117
|
const call = this.calls.get(event.id);
|
|
118
|
+
// The limits refused a command: the chat shows the limit's card in place of its line.
|
|
119
|
+
if (event.limit && call?.tool?.verb === 'ran')
|
|
120
|
+
call.tool.limit = event.limit;
|
|
118
121
|
if (call)
|
|
119
|
-
this.refuse(call, inTree(chat.work) ? event.reason : undefined);
|
|
122
|
+
this.refuse(call, inTree(chat.work) && !event.limit ? event.reason : undefined);
|
|
120
123
|
return;
|
|
121
124
|
}
|
|
122
125
|
const existing = event.id ? this.calls.get(event.id) : undefined;
|
|
@@ -16,6 +16,8 @@ export interface TurnGuard {
|
|
|
16
16
|
}
|
|
17
17
|
/** A value only an open launch's own guard wrote into its arguments. */
|
|
18
18
|
export declare const guardArgument: (arg: string) => boolean;
|
|
19
|
+
/** A launch outside a chat (a fresh read) may quote its own code-owned values while it runs. */
|
|
20
|
+
export declare function launchArguments(args: readonly string[]): () => void;
|
|
19
21
|
/**
|
|
20
22
|
* Opens a Claude launch's guard: the level and "Never ask" read now, and the limits hook in a
|
|
21
23
|
* settings file and the permission tool's channel, in a folder of the launch's own that closes
|
|
@@ -10,6 +10,18 @@ import { chatError } from './prompt.js';
|
|
|
10
10
|
const live = new Set();
|
|
11
11
|
/** A value only an open launch's own guard wrote into its arguments. */
|
|
12
12
|
export const guardArgument = (arg) => [...live].some((guard) => guard.args.has(arg));
|
|
13
|
+
/** A launch outside a chat (a fresh read) may quote its own code-owned values while it runs. */
|
|
14
|
+
export function launchArguments(args) {
|
|
15
|
+
const guard = {
|
|
16
|
+
level: 'lead',
|
|
17
|
+
neverAsk: false,
|
|
18
|
+
allowed: [],
|
|
19
|
+
args: new Set(args),
|
|
20
|
+
close: () => live.delete(guard),
|
|
21
|
+
};
|
|
22
|
+
live.add(guard);
|
|
23
|
+
return guard.close;
|
|
24
|
+
}
|
|
13
25
|
const script = (name) => {
|
|
14
26
|
const suffix = import.meta.url.endsWith('.ts') ? 'ts' : 'js';
|
|
15
27
|
return fileURLToPath(new URL(`./${name}.${suffix}`, import.meta.url)).replaceAll('\\', '/');
|
|
@@ -5,6 +5,7 @@ import type { MergeConfiguration } from '../merge-authority.ts';
|
|
|
5
5
|
import type { AgentTurn, Start, stopTree } from '../runner.ts';
|
|
6
6
|
import type { ChatImage } from './defs.ts';
|
|
7
7
|
import type { findAgents } from './find.ts';
|
|
8
|
+
import type { FreshLooks } from './fresh.ts';
|
|
8
9
|
import type { Install } from './install.ts';
|
|
9
10
|
import type { TurnMigrations } from './migration-turn.ts';
|
|
10
11
|
import type { AskTurn } from './permission-ask.ts';
|
|
@@ -36,6 +37,8 @@ export interface Active {
|
|
|
36
37
|
scenes?: TurnScene[];
|
|
37
38
|
/** The launch's permission card, while its permission tool can ask; private, never saved. */
|
|
38
39
|
asks?: AskTurn;
|
|
40
|
+
/** Told when the turn ends, to start a fresh agent's review of the step. */
|
|
41
|
+
fresh?: Pick<FreshLooks, 'afterTurn'>;
|
|
39
42
|
}
|
|
40
43
|
export interface ChatEngineOptions extends MergeConfiguration {
|
|
41
44
|
start?: Start;
|
|
@@ -45,6 +48,8 @@ export interface ChatEngineOptions extends MergeConfiguration {
|
|
|
45
48
|
install?: Install;
|
|
46
49
|
environment?: NodeJS.ProcessEnv;
|
|
47
50
|
migrations?: TurnMigrations;
|
|
51
|
+
/** The studio's fresh turns: a review after a planning step's turn writes its files. */
|
|
52
|
+
fresh?: FreshLooks;
|
|
48
53
|
}
|
|
49
54
|
/** Permission answers are ordinary sends; a notice belongs only to the agent that asked. */
|
|
50
55
|
export declare function turnContext({ chat, person, firstMessage, retryNotice }: Active): AgentTurn;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ApprovalArtifact } from './approval-authority.ts';
|
|
2
|
+
import { type SaveSource } from './host-save.ts';
|
|
3
|
+
import type { UiAnswer } from './routes.ts';
|
|
4
|
+
export declare function compApproval(root: string, fingerprint: string, signer?: string, role?: string, agent?: string, source?: SaveSource): Promise<UiAnswer>;
|
|
5
|
+
/** What a host's authority judges: the comp the page showed, at the commit checked out. */
|
|
6
|
+
export declare function compResolver(root: string, fingerprint: string): Promise<() => ApprovalArtifact>;
|