@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
|
@@ -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,31 @@ 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, or `gh api`, a repository's releases and a method or
|
|
36
|
+
// field that changes one. A path or a longer word (`src/publish.ts`,
|
|
37
|
+
// `publish-docs`) is not the subcommand; nor is one asked only for its help (`publish --help`,
|
|
38
|
+
// `npm help publish`), which is taken out of the text first.
|
|
39
|
+
const MANAGER = /(?<![\w.-])(npm|pnpm|yarn|bun|lerna|changeset)s?(?![\w-])/i;
|
|
40
|
+
const PUBLISH = /(?<![\w./\\-])pu(?:b(?:l(?:i(?:sh?)?)?)?)?(?![\w./\\-])/i;
|
|
41
|
+
const GH = /(?<![\w.-])gh(?![\w-])/i;
|
|
42
|
+
const RELEASE = /(?<![\w./\\-])release(?![\w./\\-])/i;
|
|
43
|
+
const VERBS = 'create|new|upload|edit|delete(?:-asset)?';
|
|
44
|
+
const API = /(?<![\w.-])api(?![\w.-])/i;
|
|
45
|
+
const RELEASES = /(?<![\w-])repos\/\S*\/releases(?![\w-])/i;
|
|
46
|
+
const METHOD = /(?<!\S)(?:-X\s*|--method[\s=]+)(\w+)/gi;
|
|
47
|
+
const CHANGES = /(?<![\w-])(?:post|patch|put|delete)(?![\w-])|(?<!\S)(?:-[fF]|--(?:raw-)?field|--input)(?![\w-])/i;
|
|
48
|
+
/** A method named that changes; with none named, fields (gh's POST) or a changing verb at all. */
|
|
49
|
+
const apiChange = (text) => {
|
|
50
|
+
const methods = [...text.matchAll(METHOD)].map((match) => match[1].toUpperCase());
|
|
51
|
+
if (!methods.length)
|
|
52
|
+
return CHANGES.test(text);
|
|
53
|
+
return methods.some((method) => method !== 'GET' && method !== 'HEAD');
|
|
54
|
+
};
|
|
55
|
+
const RELEASE_CHANGE = new RegExp(`(?<![\\w./\\\\-])(?:${VERBS})(?![\\w./\\\\-])`, 'i');
|
|
56
|
+
const HELP = new RegExp(`(?<![\\w./\\\\-])(?:(?:pu\\w*|${VERBS})\\s+(?:--help|-h)|help\\s+pu\\w*)(?=\\s*(?:$|[;&|)'"\\r\\n]))`, 'gi');
|
|
57
|
+
/** A value-taking option and its value (`--filter publish`): case counts, as `-C` is not `-c`. */
|
|
58
|
+
const VALUES = new RegExp(`(?<!\\S)(?:${VALUED_OPTIONS.join('|')})(?:\\s+|=)\\S+`, 'g');
|
|
33
59
|
const CERTUTIL = /(?<![\w.-])certutil(?:\.exe)?(?![\w-])/i;
|
|
34
60
|
const URLCACHE = /[-/]urlcache(?![\w-])/i;
|
|
35
61
|
const first = (pattern, text) => {
|
|
@@ -52,6 +78,14 @@ function mentionIn(text, cwd) {
|
|
|
52
78
|
return 'git push';
|
|
53
79
|
if (first(APE, text) && first(DEPLOY, text))
|
|
54
80
|
return 'ape deploy';
|
|
81
|
+
const asked = text.replace(HELP, '').replace(VALUES, ' ');
|
|
82
|
+
const manager = MANAGER.exec(asked)?.[1];
|
|
83
|
+
if (manager && PUBLISH.test(asked))
|
|
84
|
+
return `${manager.toLowerCase()} publish`;
|
|
85
|
+
if (GH.test(asked) && RELEASE.test(asked) && RELEASE_CHANGE.test(asked))
|
|
86
|
+
return 'gh release';
|
|
87
|
+
if (GH.test(text) && API.test(text) && RELEASES.test(text) && apiChange(text))
|
|
88
|
+
return 'gh api releases';
|
|
55
89
|
const settings = PRODUCTION.exec(text)?.[0];
|
|
56
90
|
if (settings)
|
|
57
91
|
return settings;
|
|
@@ -64,8 +98,8 @@ function mentionIn(text, cwd) {
|
|
|
64
98
|
return first(DOWNLOADS, text)?.toLowerCase();
|
|
65
99
|
}
|
|
66
100
|
/**
|
|
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.
|
|
101
|
+
* The limit a command's text mentions, as the card names it (`git push`, `ape deploy`,
|
|
102
|
+
* `npm publish`, `gh release`, `.ssh`, `.env.production`, `curl`); nothing when it mentions none.
|
|
69
103
|
*/
|
|
70
104
|
export function mentionedLimit(command, cwd) {
|
|
71
105
|
const joined = command.replace(/[\\`^]\r?\n/g, '');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The limits' words: the sentence the agent reads for a crossed limit, in the turn's language,
|
|
3
|
+
* and the limit a refused call's result names. Plain Node only: the hook runs it.
|
|
4
|
+
*/
|
|
5
|
+
import { en } from './limits.en.ts';
|
|
6
|
+
import type { Limit, RefusedKind } from './limits.ts';
|
|
7
|
+
/**
|
|
8
|
+
* The limit a refused call's result names: the hook's own sentence for it, in either language,
|
|
9
|
+
* came back as the result. Nothing when it names none.
|
|
10
|
+
*/
|
|
11
|
+
export declare function refusalLimit(text: string): RefusedKind | undefined;
|
|
12
|
+
/** The agent's words in the turn's language (LANG), with `{name}` values filled in. */
|
|
13
|
+
export declare function limitText(key: keyof typeof en, values?: Record<string, string>): string;
|
|
14
|
+
/** The sentence the agent reads for a crossed limit: it names the refused part. */
|
|
15
|
+
export declare const limitReason: (limit: Limit) => string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The limits' words: the sentence the agent reads for a crossed limit, in the turn's language,
|
|
3
|
+
* and the limit a refused call's result names. Plain Node only: the hook runs it.
|
|
4
|
+
*/
|
|
5
|
+
import { en } from './limits.en.js';
|
|
6
|
+
import { es } from './limits.es.js';
|
|
7
|
+
const catalogs = { en, es };
|
|
8
|
+
const REFUSED = [
|
|
9
|
+
'secrets',
|
|
10
|
+
'deploy',
|
|
11
|
+
'push',
|
|
12
|
+
'settings',
|
|
13
|
+
'publish',
|
|
14
|
+
'release',
|
|
15
|
+
'approval',
|
|
16
|
+
'commit',
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* The limit a refused call's result names: the hook's own sentence for it, in either language,
|
|
20
|
+
* came back as the result. Nothing when it names none.
|
|
21
|
+
*/
|
|
22
|
+
export function refusalLimit(text) {
|
|
23
|
+
return REFUSED.find((kind) => Object.values(catalogs).some((words) => text.includes(words[`limits.${kind}`].replace('`{part}`', ''))));
|
|
24
|
+
}
|
|
25
|
+
/** The agent's words in the turn's language (LANG), with `{name}` values filled in. */
|
|
26
|
+
export function limitText(key, values = {}) {
|
|
27
|
+
const locale = (process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || 'en')
|
|
28
|
+
.slice(0, 2)
|
|
29
|
+
.toLowerCase();
|
|
30
|
+
const words = catalogs[locale === 'es' ? 'es' : 'en'];
|
|
31
|
+
return words[key].replace(/\{(\w+)\}/g, (_, name) => values[name] ?? '');
|
|
32
|
+
}
|
|
33
|
+
/** The sentence the agent reads for a crossed limit: it names the refused part. */
|
|
34
|
+
export const limitReason = (limit) => limit.kind === 'unsure'
|
|
35
|
+
? limitText(`limits.unsure.${limit.unsure ?? 'mention'}`, { mention: limit.mention ?? '' })
|
|
36
|
+
: limitText(`limits.${limit.kind}`, { part: limit.part.slice(0, 200) });
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The studio's PreToolUse hook, installed for each Claude turn through `--settings`: it reads the
|
|
3
3
|
* call from stdin and answers with Claude Code's hook output. Run by plain Node, as
|
|
4
|
-
* `node limits-hook.ts <work>`; the decision is `hookAnswer` in limits.ts. Anything unexpected
|
|
4
|
+
* `node limits-hook.ts <work> <level>`; the decision is `hookAnswer` in limits.ts. Anything unexpected
|
|
5
5
|
* refuses the call (exit 2, the reason on stderr): an exit 1 would let it run.
|
|
6
6
|
*/
|
|
7
7
|
import { readFileSync } from 'node:fs';
|
|
8
8
|
try {
|
|
9
9
|
const { hookAnswer } = await import('./limits.js');
|
|
10
|
-
const answer = hookAnswer(readFileSync(0, 'utf8'), process.argv[2] ?? '');
|
|
10
|
+
const answer = hookAnswer(readFileSync(0, 'utf8'), process.argv[2] ?? '', process.argv[3] ?? '');
|
|
11
11
|
if (answer)
|
|
12
12
|
process.stdout.write(JSON.stringify({
|
|
13
13
|
hookSpecificOutput: {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type Unsure } from './command-parts.ts';
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
2
|
+
import { type Turn } from './commit-limits.ts';
|
|
3
|
+
export { limitReason, limitText, refusalLimit } from './limit-text.ts';
|
|
4
|
+
/** The limits a call is refused for at every level; a person can never allow them. */
|
|
5
|
+
export type RefusedKind = 'secrets' | 'deploy' | 'push' | 'settings' | 'publish' | 'release' | 'approval' | 'commit';
|
|
6
|
+
export type LimitKind = RefusedKind | 'download' | 'unsure';
|
|
4
7
|
export interface Limit {
|
|
5
8
|
/** `ask` sends the call to the person's Allow card; `deny` refuses it at every level. */
|
|
6
9
|
decision: 'deny' | 'ask';
|
|
@@ -20,18 +23,17 @@ export interface Limit {
|
|
|
20
23
|
* the turn's folder counts, so a product kept under such a folder still works.
|
|
21
24
|
*/
|
|
22
25
|
export declare function secretPath(path: string, cwd: string): boolean;
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
export declare const limitReason: (limit: Limit) => string;
|
|
26
|
+
/**
|
|
27
|
+
* The first limit a tool call crosses, refusals before asks; nothing when it crosses none. The
|
|
28
|
+
* turn, when known, adds the limits only some turns keep (a design turn's commit on Autopilot).
|
|
29
|
+
*/
|
|
30
|
+
export declare function crossedLimit(tool: string, input: unknown, cwd: string, turn?: Turn): Limit | undefined;
|
|
29
31
|
/**
|
|
30
32
|
* The hook's answer to one call: a crossed limit, a design turn's delete inside `design/` or
|
|
31
33
|
* `prototype/` (allowed), or nothing. A call it cannot read is refused, so a broken call never
|
|
32
34
|
* slips past the limits.
|
|
33
35
|
*/
|
|
34
|
-
export declare function hookAnswer(text: string, work: string): {
|
|
36
|
+
export declare function hookAnswer(text: string, work: string, level?: string): {
|
|
35
37
|
decision: 'allow' | 'deny' | 'ask';
|
|
36
38
|
reason: string;
|
|
37
39
|
} | undefined;
|
|
@@ -4,6 +4,10 @@ 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.';
|
|
9
|
+
readonly 'limits.approval': '`{part}` is not allowed here: approval records are written only by the studio, when a person approves.';
|
|
10
|
+
readonly 'limits.commit': '`{part}` is not allowed here: on Autopilot the studio saves a design step’s work; the agent makes no commit.';
|
|
7
11
|
readonly 'limits.download': '`{part}` downloads from the network: the person must allow it, and did not.';
|
|
8
12
|
readonly 'limits.unsure.mention': 'This command mentions `{mention}`, and the studio couldn’t tell if it runs it: the person must allow it, and did not.';
|
|
9
13
|
readonly 'limits.unsure.pattern': 'This command uses a pattern that could reach `{mention}`; the studio couldn’t tell: the person must allow it, and did not. Name the files you need.';
|
|
@@ -4,6 +4,10 @@ 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.',
|
|
9
|
+
'limits.approval': '`{part}` is not allowed here: approval records are written only by the studio, when a person approves.',
|
|
10
|
+
'limits.commit': '`{part}` is not allowed here: on Autopilot the studio saves a design step’s work; the agent makes no commit.',
|
|
7
11
|
'limits.download': '`{part}` downloads from the network: the person must allow it, and did not.',
|
|
8
12
|
'limits.unsure.mention': 'This command mentions `{mention}`, and the studio couldn’t tell if it runs it: the person must allow it, and did not.',
|
|
9
13
|
'limits.unsure.pattern': 'This command uses a pattern that could reach `{mention}`; the studio couldn’t tell: the person must allow it, and did not. Name the files you need.',
|
|
@@ -3,6 +3,10 @@ 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.',
|
|
8
|
+
'limits.approval': '`{part}` no está permitido aquí: los registros de aprobación solo los escribe el estudio, cuando una persona aprueba.',
|
|
9
|
+
'limits.commit': '`{part}` no está permitido aquí: en Piloto automático el estudio guarda el trabajo de un paso de diseño; el agente no hace commits.',
|
|
6
10
|
'limits.download': '`{part}` descarga de la red: la persona debe permitirlo, y no lo hizo.',
|
|
7
11
|
'limits.unsure.mention': 'Este comando menciona `{mention}` y el estudio no pudo saber si lo ejecuta: la persona debe permitirlo, y no lo hizo.',
|
|
8
12
|
'limits.unsure.pattern': 'Este comando usa un patrón que podría llegar a `{mention}`; el estudio no pudo saberlo: la persona debe permitirlo, y no lo hizo. Nombra los archivos que necesitas.',
|
|
@@ -1,19 +1,27 @@
|
|
|
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
|
|
5
|
-
*
|
|
4
|
+
* person's click, no publishing a package or a release, and no shell write into the approval
|
|
5
|
+
* records (`prototype/versions/`); a design turn on Autopilot makes no commit either. The
|
|
6
|
+
* studio's hook (limits-hook.ts) runs this before each tool call; the permission mode never
|
|
7
|
+
* decides them. Plain Node only: the hook runs it without the CLI.
|
|
6
8
|
*/
|
|
7
9
|
import { relative, resolve } from 'node:path';
|
|
10
|
+
import { folderWrite } from './approval-folders.js';
|
|
11
|
+
import { approvalText } from './approval-text.js';
|
|
12
|
+
import { approvalWrite } from './approval-writes.js';
|
|
8
13
|
import { commandParts, ESCAPE, partWords, programName, } from './command-parts.js';
|
|
9
14
|
import { EXPRESSIONS, wrappedScripts } from './command-wrappers.js';
|
|
15
|
+
import { commitText, commitWords, designAutopilot, designWork, } from './commit-limits.js';
|
|
10
16
|
import { designDelete } from './design-deletes.js';
|
|
17
|
+
import { subcommand, subcommandAt } from './git-words.js';
|
|
11
18
|
import { mentionedLimit } from './limit-mentions.js';
|
|
12
19
|
import { patternReach } from './limit-patterns.js';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
20
|
+
import { limitReason, limitText } from './limit-text.js';
|
|
21
|
+
import { publishLimit } from './publish-limits.js';
|
|
15
22
|
import { holdsSecrets } from './secret-folders.js';
|
|
16
23
|
import { readsStdin } from './stdin-shells.js';
|
|
24
|
+
export { limitReason, limitText, refusalLimit } from './limit-text.js';
|
|
17
25
|
const SHELLS = new Map([
|
|
18
26
|
['Bash', 'bash'],
|
|
19
27
|
['PowerShell', 'powershell'],
|
|
@@ -51,28 +59,6 @@ export function secretPath(path, cwd) {
|
|
|
51
59
|
}
|
|
52
60
|
/** A word worth reading as a path: it has a separator, or starts like a hidden or home folder. */
|
|
53
61
|
const pathLike = (word) => /[\\/]/.test(word) || /^[.~]/.test(word);
|
|
54
|
-
// Git's options before the subcommand that take the next word as their value.
|
|
55
|
-
const VALUED = new Set([
|
|
56
|
-
'-C',
|
|
57
|
-
'-c',
|
|
58
|
-
'--git-dir',
|
|
59
|
-
'--work-tree',
|
|
60
|
-
'--namespace',
|
|
61
|
-
'--super-prefix',
|
|
62
|
-
'--config-env',
|
|
63
|
-
'--attr-source',
|
|
64
|
-
]);
|
|
65
|
-
/** The first word after `from` that is not an option (or an option's value), and its index. */
|
|
66
|
-
function subcommandAt(words, from) {
|
|
67
|
-
for (let index = from; index < words.length; index++) {
|
|
68
|
-
const word = words[index];
|
|
69
|
-
if (VALUED.has(word))
|
|
70
|
-
index++;
|
|
71
|
-
else if (!word.startsWith('-'))
|
|
72
|
-
return { name: word.toLowerCase(), at: index };
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
const subcommand = (words, from) => subcommandAt(words, from)?.name;
|
|
76
62
|
/** A commit's or tag's message is words, not a command or a path: `git commit -m "…"`. */
|
|
77
63
|
function withoutMessages(words) {
|
|
78
64
|
const git = words.findIndex((word) => programName(word) === 'git');
|
|
@@ -82,7 +68,7 @@ function withoutMessages(words) {
|
|
|
82
68
|
const at = sub.at;
|
|
83
69
|
return words.filter((_, index) => index <= at || !/^(?:-[A-Za-z]*m|--message)$/.test(words[index - 1] ?? ''));
|
|
84
70
|
}
|
|
85
|
-
function wordsLimit(words, cwd) {
|
|
71
|
+
function wordsLimit(words, cwd, turn) {
|
|
86
72
|
const names = words.map(programName);
|
|
87
73
|
const checked = withoutMessages(words);
|
|
88
74
|
if (checked.some((word) => pathLike(word) && secretPath(word, cwd)))
|
|
@@ -92,7 +78,9 @@ function wordsLimit(words, cwd) {
|
|
|
92
78
|
const git = names.indexOf('git');
|
|
93
79
|
// `git send-pack` is the plumbing under `git push`.
|
|
94
80
|
const sub = git >= 0 ? subcommand(words, git + 1) : undefined;
|
|
95
|
-
|
|
81
|
+
// `git subtree push` pushes too.
|
|
82
|
+
const subtreePush = sub === 'subtree' && subcommand(words, words.indexOf('subtree', git) + 1) === 'push';
|
|
83
|
+
if (sub === 'push' || sub === 'send-pack' || subtreePush)
|
|
96
84
|
return { decision: 'deny', kind: 'push' };
|
|
97
85
|
const ape = names.indexOf('ape');
|
|
98
86
|
if (ape >= 0) {
|
|
@@ -101,6 +89,13 @@ function wordsLimit(words, cwd) {
|
|
|
101
89
|
if (next === 'deploy' || server === 'deploy')
|
|
102
90
|
return { decision: 'deny', kind: 'deploy' };
|
|
103
91
|
}
|
|
92
|
+
const published = publishLimit(checked);
|
|
93
|
+
if (published)
|
|
94
|
+
return { decision: 'deny', kind: published };
|
|
95
|
+
if (approvalWrite(checked, cwd) || (designWork(turn) && folderWrite(checked, cwd)))
|
|
96
|
+
return { decision: 'deny', kind: 'approval' };
|
|
97
|
+
if (designAutopilot(turn) && commitWords(words))
|
|
98
|
+
return { decision: 'deny', kind: 'commit' };
|
|
104
99
|
if (checked.some((word) => DOWNLOADS.test(word)))
|
|
105
100
|
return { decision: 'ask', kind: 'download' };
|
|
106
101
|
// `certutil -urlcache` fetches a URL; its other uses read local files.
|
|
@@ -114,7 +109,7 @@ function wordsLimit(words, cwd) {
|
|
|
114
109
|
function partLimits(part, check, shell, depth) {
|
|
115
110
|
const raw = partWords(part);
|
|
116
111
|
const plain = partWords(part, ESCAPE[shell]);
|
|
117
|
-
const own = wordsLimit(raw, check.cwd) ?? wordsLimit(plain, check.cwd);
|
|
112
|
+
const own = wordsLimit(raw, check.cwd, check.turn) ?? wordsLimit(plain, check.cwd, check.turn);
|
|
118
113
|
if (readsStdin(plain))
|
|
119
114
|
check.unsure ??= 'stdin';
|
|
120
115
|
if (plain.some((word) => EXPRESSIONS.has(programName(word))))
|
|
@@ -128,7 +123,14 @@ function partLimits(part, check, shell, depth) {
|
|
|
128
123
|
if (check.seen.has(key))
|
|
129
124
|
return [];
|
|
130
125
|
check.seen.add(key);
|
|
131
|
-
|
|
126
|
+
// A handed-on script's text is read too: an encoded one never showed it in the command.
|
|
127
|
+
const text = fallback(script, inside, check.cwd, check.turn);
|
|
128
|
+
if (text?.decision === 'deny')
|
|
129
|
+
return [{ ...text, part }];
|
|
130
|
+
return [
|
|
131
|
+
...(text ? [{ ...text, part }] : []),
|
|
132
|
+
...commandLimits(script, check, inside, depth + 1),
|
|
133
|
+
];
|
|
132
134
|
});
|
|
133
135
|
return [...(own ? [{ ...own, part }] : []), ...inner];
|
|
134
136
|
}
|
|
@@ -139,16 +141,40 @@ function commandLimits(command, check, shell, depth = 0) {
|
|
|
139
141
|
}
|
|
140
142
|
return commandParts(command, shell, check).flatMap((part) => partLimits(part, check, shell, depth));
|
|
141
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* The text fallbacks for a write into the approval records (refused, or asked when every part
|
|
146
|
+
* only reads) and a design turn's commit on Autopilot (asked).
|
|
147
|
+
*/
|
|
148
|
+
function fallback(command, shell, cwd, turn) {
|
|
149
|
+
const ask = (mention) => ({
|
|
150
|
+
decision: 'ask',
|
|
151
|
+
kind: 'unsure',
|
|
152
|
+
part: command,
|
|
153
|
+
unsure: 'mention',
|
|
154
|
+
mention,
|
|
155
|
+
});
|
|
156
|
+
const approval = approvalText(command, shell, cwd, designWork(turn));
|
|
157
|
+
if (approval === 'deny')
|
|
158
|
+
return { decision: 'deny', kind: 'approval', part: command };
|
|
159
|
+
if (approval)
|
|
160
|
+
return ask('prototype/versions');
|
|
161
|
+
const commit = designAutopilot(turn) ? commitText(command, shell) : undefined;
|
|
162
|
+
if (commit === 'deny')
|
|
163
|
+
return { decision: 'deny', kind: 'commit', part: command };
|
|
164
|
+
if (commit)
|
|
165
|
+
return ask('git commit');
|
|
166
|
+
}
|
|
142
167
|
/**
|
|
143
168
|
* A shell command's first limit: what the parse refuses, then what it asks; when it found
|
|
144
169
|
* neither, a reading it could not follow, or a limit the text still mentions, asks the person.
|
|
145
170
|
*/
|
|
146
|
-
function shellLimit(command, cwd, shell) {
|
|
147
|
-
const check = { cwd, steps: 0, until: Date.now() + TIME_CAP, seen: new Set() };
|
|
171
|
+
function shellLimit(command, cwd, shell, turn) {
|
|
172
|
+
const check = { cwd, turn, steps: 0, until: Date.now() + TIME_CAP, seen: new Set() };
|
|
148
173
|
if (command.length > TEXT_CAP)
|
|
149
174
|
check.unsure = 'budget';
|
|
150
175
|
else {
|
|
151
|
-
const
|
|
176
|
+
const text = fallback(command, shell, cwd, turn);
|
|
177
|
+
const limits = [...commandLimits(command, check, shell), ...(text ? [text] : [])];
|
|
152
178
|
const found = limits.find((limit) => limit.decision === 'deny') ?? limits[0];
|
|
153
179
|
if (found)
|
|
154
180
|
return found;
|
|
@@ -167,12 +193,15 @@ function shellLimit(command, cwd, shell) {
|
|
|
167
193
|
...(mention ? { mention } : {}),
|
|
168
194
|
};
|
|
169
195
|
}
|
|
170
|
-
/**
|
|
171
|
-
|
|
196
|
+
/**
|
|
197
|
+
* The first limit a tool call crosses, refusals before asks; nothing when it crosses none. The
|
|
198
|
+
* turn, when known, adds the limits only some turns keep (a design turn's commit on Autopilot).
|
|
199
|
+
*/
|
|
200
|
+
export function crossedLimit(tool, input, cwd, turn) {
|
|
172
201
|
const fields = (input ?? {});
|
|
173
202
|
const shell = SHELLS.get(tool);
|
|
174
203
|
if (shell) {
|
|
175
|
-
return shellLimit(typeof fields.command === 'string' ? fields.command : '', cwd, shell);
|
|
204
|
+
return shellLimit(typeof fields.command === 'string' ? fields.command : '', cwd, shell, turn);
|
|
176
205
|
}
|
|
177
206
|
for (const field of fileFields(tool)) {
|
|
178
207
|
const value = fields[field];
|
|
@@ -186,25 +215,12 @@ export function crossedLimit(tool, input, cwd) {
|
|
|
186
215
|
if (tool === 'WebFetch' && typeof fields.url === 'string')
|
|
187
216
|
return { decision: 'ask', kind: 'download', part: fields.url };
|
|
188
217
|
}
|
|
189
|
-
const catalogs = { en, es };
|
|
190
|
-
/** The agent's words in the turn's language (LANG), with `{name}` values filled in. */
|
|
191
|
-
export function limitText(key, values = {}) {
|
|
192
|
-
const locale = (process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || 'en')
|
|
193
|
-
.slice(0, 2)
|
|
194
|
-
.toLowerCase();
|
|
195
|
-
const words = catalogs[locale === 'es' ? 'es' : 'en'];
|
|
196
|
-
return words[key].replace(/\{(\w+)\}/g, (_, name) => values[name] ?? '');
|
|
197
|
-
}
|
|
198
|
-
/** The sentence the agent reads for a crossed limit: it names the refused part. */
|
|
199
|
-
export const limitReason = (limit) => limit.kind === 'unsure'
|
|
200
|
-
? limitText(`limits.unsure.${limit.unsure ?? 'mention'}`, { mention: limit.mention ?? '' })
|
|
201
|
-
: limitText(`limits.${limit.kind}`, { part: limit.part.slice(0, 200) });
|
|
202
218
|
/**
|
|
203
219
|
* The hook's answer to one call: a crossed limit, a design turn's delete inside `design/` or
|
|
204
220
|
* `prototype/` (allowed), or nothing. A call it cannot read is refused, so a broken call never
|
|
205
221
|
* slips past the limits.
|
|
206
222
|
*/
|
|
207
|
-
export function hookAnswer(text, work) {
|
|
223
|
+
export function hookAnswer(text, work, level = '') {
|
|
208
224
|
let call;
|
|
209
225
|
try {
|
|
210
226
|
call = JSON.parse(text);
|
|
@@ -214,7 +230,7 @@ export function hookAnswer(text, work) {
|
|
|
214
230
|
}
|
|
215
231
|
const tool = typeof call.tool_name === 'string' ? call.tool_name : '';
|
|
216
232
|
const cwd = typeof call.cwd === 'string' && call.cwd ? call.cwd : process.cwd();
|
|
217
|
-
const limit = crossedLimit(tool, call.tool_input, cwd);
|
|
233
|
+
const limit = crossedLimit(tool, call.tool_input, cwd, { work, level });
|
|
218
234
|
if (limit)
|
|
219
235
|
return { decision: limit.decision, reason: limitReason(limit) };
|
|
220
236
|
const command = call.tool_input?.command;
|
|
@@ -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,32 @@ 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
|
+
'bun publish',
|
|
28
|
+
'lerna publish',
|
|
29
|
+
'changeset publish',
|
|
30
|
+
'npx lerna publish',
|
|
31
|
+
'npx changeset publish',
|
|
32
|
+
'pnpm lerna publish',
|
|
33
|
+
'pnpm changeset publish',
|
|
34
|
+
'pnpm exec lerna publish',
|
|
35
|
+
'pnpm exec changeset publish',
|
|
36
|
+
'yarn lerna publish',
|
|
37
|
+
'yarn changeset publish',
|
|
38
|
+
'gh release create',
|
|
39
|
+
'gh release new',
|
|
40
|
+
'gh release upload',
|
|
41
|
+
'gh release edit',
|
|
42
|
+
'gh release delete',
|
|
17
43
|
];
|
|
18
44
|
/** The production settings files the limits hook refuses (`.env.production`, `.env.prod`, `.env.staging`). */
|
|
19
45
|
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,113 @@
|
|
|
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`, `bun publish`,
|
|
4
|
+
* `lerna publish`, `changeset publish`) and a release (`gh release create|new|upload|edit|delete`,
|
|
5
|
+
* and `delete-asset`; `gh api` calls that create or change one, gh-api-limits.ts). Every package
|
|
6
|
+
* manager or `gh` named in a part is read, so `npx npm publish`, `pnpm exec changeset publish` and
|
|
7
|
+
* `env X=1 npm publish` count too. Before the subcommand, the options each tool takes a value for skip that value
|
|
8
|
+
* (`npm --registry x publish`, `gh -R owner/repo release create`); after any other option the next
|
|
9
|
+
* word is the subcommand, so `pnpm --filter publish build` runs (a shape the parse does not follow
|
|
10
|
+
* still goes to the card through the text fallback). Asking only for help (`pnpm publish --help`)
|
|
11
|
+
* runs. Plain Node only: the hook runs it.
|
|
12
|
+
*/
|
|
13
|
+
import { programName } from './command-parts.js';
|
|
14
|
+
import { GH_API_VALUED, releaseCall } from './gh-api-limits.js';
|
|
15
|
+
/** The options before the subcommand that take the next word as their value, per tool. */
|
|
16
|
+
const VALUED = {
|
|
17
|
+
npm: new Set([
|
|
18
|
+
'--registry',
|
|
19
|
+
'--prefix',
|
|
20
|
+
'-C',
|
|
21
|
+
'--workspace',
|
|
22
|
+
'-w',
|
|
23
|
+
'--userconfig',
|
|
24
|
+
'--globalconfig',
|
|
25
|
+
'--cache',
|
|
26
|
+
'--loglevel',
|
|
27
|
+
'--otp',
|
|
28
|
+
'--tag',
|
|
29
|
+
'--access',
|
|
30
|
+
'--scope',
|
|
31
|
+
'--location',
|
|
32
|
+
]),
|
|
33
|
+
pnpm: new Set([
|
|
34
|
+
'-C',
|
|
35
|
+
'--dir',
|
|
36
|
+
'--filter',
|
|
37
|
+
'-F',
|
|
38
|
+
'--filter-prod',
|
|
39
|
+
'--workspace-dir',
|
|
40
|
+
'--registry',
|
|
41
|
+
'--reporter',
|
|
42
|
+
'--loglevel',
|
|
43
|
+
'--store-dir',
|
|
44
|
+
'--modules-dir',
|
|
45
|
+
'--lockfile-dir',
|
|
46
|
+
'--tag',
|
|
47
|
+
'--access',
|
|
48
|
+
'--otp',
|
|
49
|
+
'--publish-branch',
|
|
50
|
+
]),
|
|
51
|
+
yarn: new Set(['--cwd', '--registry', '--otp', '--tag', '--access', '--modules-folder']),
|
|
52
|
+
bun: new Set(['--cwd', '--registry', '--otp', '--tag', '--access', '--config', '-c']),
|
|
53
|
+
lerna: new Set(['--loglevel', '--concurrency']),
|
|
54
|
+
changeset: new Set(['--cwd']),
|
|
55
|
+
gh: new Set(['-R', '--repo', '--hostname']),
|
|
56
|
+
};
|
|
57
|
+
/** Every option above, for the text fallback: their values are values, not a subcommand. */
|
|
58
|
+
export const VALUED_OPTIONS = [
|
|
59
|
+
...new Set([...Object.values(VALUED).flatMap((options) => [...options]), ...GH_API_VALUED]),
|
|
60
|
+
];
|
|
61
|
+
const RELEASE = new Set(['create', 'new', 'upload', 'edit', 'delete', 'delete-asset']);
|
|
62
|
+
/** npm resolves a shortened command name: from `pu`, the only name it can mean is `publish`. */
|
|
63
|
+
const PUBLISHES = {
|
|
64
|
+
npm: (word) => word.length >= 2 && 'publish'.startsWith(word),
|
|
65
|
+
pnpm: (word) => word === 'publish',
|
|
66
|
+
yarn: (word) => word === 'publish',
|
|
67
|
+
bun: (word) => word === 'publish',
|
|
68
|
+
lerna: (word) => word === 'publish',
|
|
69
|
+
changeset: (word) => word === 'publish',
|
|
70
|
+
};
|
|
71
|
+
const HELP = new Set(['--help', '-h']);
|
|
72
|
+
/**
|
|
73
|
+
* The program a word names, without a pinned version (`npm@10`, `pnpm@latest`); the changesets
|
|
74
|
+
* package run by its name (`npx @changesets/cli publish`) is its `changeset` command.
|
|
75
|
+
*/
|
|
76
|
+
const toolName = (word) => /^@changesets\/cli(?:@[^@]*)?$/i.test(word)
|
|
77
|
+
? 'changeset'
|
|
78
|
+
: programName(word).replace(/(?<=.)@[^@]*$/, '');
|
|
79
|
+
/** The index of the subcommand after `from` when `wanted` accepts it; -1 otherwise. */
|
|
80
|
+
function subcommandIs(words, from, valued, wanted) {
|
|
81
|
+
for (let index = from; index < words.length; index++) {
|
|
82
|
+
const word = words[index];
|
|
83
|
+
if (!word.startsWith('-'))
|
|
84
|
+
return wanted(word.toLowerCase()) ? index : -1;
|
|
85
|
+
if (valued.has(word))
|
|
86
|
+
index++;
|
|
87
|
+
}
|
|
88
|
+
return -1;
|
|
89
|
+
}
|
|
90
|
+
/** A subcommand followed only by `--help` or `-h` shows its help and does nothing else. */
|
|
91
|
+
const helpOnly = (words, at) => words.length === at + 2 && HELP.has(words[at + 1]);
|
|
92
|
+
/** The publishing limit a part's words cross: a package or a release; nothing otherwise. */
|
|
93
|
+
export function publishLimit(words) {
|
|
94
|
+
for (let index = 0; index < words.length; index++) {
|
|
95
|
+
const name = toolName(words[index]);
|
|
96
|
+
const publishes = PUBLISHES[name];
|
|
97
|
+
if (publishes) {
|
|
98
|
+
const at = subcommandIs(words, index + 1, VALUED[name], publishes);
|
|
99
|
+
if (at >= 0 && !helpOnly(words, at))
|
|
100
|
+
return 'publish';
|
|
101
|
+
}
|
|
102
|
+
if (name !== 'gh')
|
|
103
|
+
continue;
|
|
104
|
+
const valued = VALUED.gh;
|
|
105
|
+
const api = subcommandIs(words, index + 1, valued, (word) => word === 'api');
|
|
106
|
+
if (api >= 0 && releaseCall(words, api + 1))
|
|
107
|
+
return 'release';
|
|
108
|
+
const release = subcommandIs(words, index + 1, valued, (word) => word === 'release');
|
|
109
|
+
const at = release < 0 ? -1 : subcommandIs(words, release + 1, valued, (w) => RELEASE.has(w));
|
|
110
|
+
if (at >= 0 && !helpOnly(words, at))
|
|
111
|
+
return 'release';
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -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) {
|