@bakers-build/addon-claude 0.8.0 → 0.8.1-next.2
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/dist/src/footprint.d.ts +7 -0
- package/dist/src/footprint.js +68 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/index.js +52 -12
- package/measure/agent-proxy.mjs +3 -3
- package/measure/claude-measure.mjs +3 -3
- package/options.schema.json +13 -0
- package/package.json +9 -7
package/dist/src/footprint.d.ts
CHANGED
|
@@ -20,3 +20,10 @@ import { type AgentFootprint } from '@bakers-build/conductor/contract';
|
|
|
20
20
|
* to its tool_result. Only timestamped entries take part; no threshold.
|
|
21
21
|
*/
|
|
22
22
|
export declare function parseClaudeTranscript(jsonl: string): AgentFootprint;
|
|
23
|
+
/**
|
|
24
|
+
* Every tool call `dontAsk` denied in a Claude-Code transcript, as `Tool(argument)`,
|
|
25
|
+
* but only when the run stopped on one: a denial is among the last batch of tool
|
|
26
|
+
* results, no call is outstanding and the agent has replied with text, no new call.
|
|
27
|
+
* A run that worked on, waits on a sub-agent or on the model gives `[]`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseClaudePermissionDenials(jsonl: string): string[];
|
package/dist/src/footprint.js
CHANGED
|
@@ -150,3 +150,71 @@ export function parseClaudeTranscript(jsonl) {
|
|
|
150
150
|
return wait;
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
+
/** Claude Code's tool_result text when `--permission-mode dontAsk` refuses a call. */
|
|
154
|
+
const DONT_ASK_DENIAL = /^Permission to use \S+ has been denied because Claude Code is running in don't ask mode\./;
|
|
155
|
+
/** The input field that names what a tool call acts on. */
|
|
156
|
+
const ACTION_KEYS = ['file_path', 'command', 'url', 'path', 'pattern', 'skill'];
|
|
157
|
+
/**
|
|
158
|
+
* Every tool call `dontAsk` denied in a Claude-Code transcript, as `Tool(argument)`,
|
|
159
|
+
* but only when the run stopped on one: a denial is among the last batch of tool
|
|
160
|
+
* results, no call is outstanding and the agent has replied with text, no new call.
|
|
161
|
+
* A run that worked on, waits on a sub-agent or on the model gives `[]`.
|
|
162
|
+
*/
|
|
163
|
+
export function parseClaudePermissionDenials(jsonl) {
|
|
164
|
+
const calls = new Map();
|
|
165
|
+
const pending = new Set();
|
|
166
|
+
const denied = [];
|
|
167
|
+
let batchDenied = false;
|
|
168
|
+
let batchMessage;
|
|
169
|
+
let replied = false;
|
|
170
|
+
for (const raw of jsonl.split('\n')) {
|
|
171
|
+
let entry;
|
|
172
|
+
try {
|
|
173
|
+
entry = JSON.parse(raw);
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const content = entry?.message?.content;
|
|
179
|
+
if (!Array.isArray(content))
|
|
180
|
+
continue;
|
|
181
|
+
const blocks = content;
|
|
182
|
+
// Claude Code writes each block of a response as its own entry, sometimes with a
|
|
183
|
+
// call's result before the response's next call: a call from a new response
|
|
184
|
+
// opens a new batch, a reply without one ends the turn.
|
|
185
|
+
if (entry?.type === 'assistant') {
|
|
186
|
+
if (blocks.some((b) => b?.type === 'tool_use')) {
|
|
187
|
+
const message = entry.message?.id;
|
|
188
|
+
const sameResponse = message !== undefined && message === batchMessage;
|
|
189
|
+
if (pending.size === 0 && !sameResponse)
|
|
190
|
+
batchDenied = false;
|
|
191
|
+
batchMessage = message;
|
|
192
|
+
replied = false;
|
|
193
|
+
}
|
|
194
|
+
else if (blocks.some((b) => b?.type === 'text')) {
|
|
195
|
+
// A thinking-only entry precedes the rest of its response, so it is no reply.
|
|
196
|
+
replied = true;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
for (const block of blocks) {
|
|
200
|
+
if (block?.type === 'tool_use' && typeof block.id === 'string') {
|
|
201
|
+
const input = (block.input ?? {});
|
|
202
|
+
const key = ACTION_KEYS.find((k) => typeof input[k] === 'string');
|
|
203
|
+
const name = String(block.name);
|
|
204
|
+
calls.set(block.id, key ? `${name}(${input[key]})` : name);
|
|
205
|
+
pending.add(block.id);
|
|
206
|
+
}
|
|
207
|
+
else if (block?.type === 'tool_result') {
|
|
208
|
+
pending.delete(String(block.tool_use_id));
|
|
209
|
+
replied = false;
|
|
210
|
+
if (block.is_error === true &&
|
|
211
|
+
typeof block.content === 'string' &&
|
|
212
|
+
DONT_ASK_DENIAL.test(block.content)) {
|
|
213
|
+
batchDenied = true;
|
|
214
|
+
denied.push(calls.get(String(block.tool_use_id)) ?? 'unknown tool');
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return batchDenied && replied && pending.size === 0 ? denied : [];
|
|
220
|
+
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -47,6 +47,15 @@ export declare class ClaudeAgent implements BbAgent {
|
|
|
47
47
|
launchCommand(prompt: string, run?: AgentRunIdentity, workspacePath?: string, tools?: {
|
|
48
48
|
url: string;
|
|
49
49
|
}, _env?: Readonly<Record<string, string>>, pluginArgs?: readonly string[]): string;
|
|
50
|
+
/**
|
|
51
|
+
* `claude --resume <id>` with the launch's own flags, so a run whose pane
|
|
52
|
+
* died continues its conversation. Not for a measured run: its wrapper
|
|
53
|
+
* profiles one fresh session.
|
|
54
|
+
*/
|
|
55
|
+
resumeCommand(sessionId: string, workspacePath?: string, tools?: {
|
|
56
|
+
url: string;
|
|
57
|
+
}, _env?: Readonly<Record<string, string>>, pluginArgs?: readonly string[]): string | undefined;
|
|
58
|
+
private command;
|
|
50
59
|
/**
|
|
51
60
|
* The sandbox's strict MCP config, plus the conductor's tool server when
|
|
52
61
|
* the run has one. A measured run stays without MCP servers. The token is
|
|
@@ -61,8 +70,12 @@ export declare class ClaudeAgent implements BbAgent {
|
|
|
61
70
|
* launch at all, silently (`claude` exits 0 on that error).
|
|
62
71
|
*/
|
|
63
72
|
sessionExists(worktreePath: string, sessionId: string): Promise<boolean>;
|
|
73
|
+
/** The run's pinned transcript only: the newest existing attempt, as {@link getRunLog} prefers it. */
|
|
74
|
+
runLogModified(worktreePath: string, run: AgentRunIdentity): Promise<number | undefined>;
|
|
64
75
|
getRunLog(worktreePath: string, run?: AgentRunIdentity): Promise<string>;
|
|
65
76
|
parseFootprint(log: string): AgentFootprint;
|
|
77
|
+
/** Only the sandbox launches in `dontAsk`; other modes are never reported. */
|
|
78
|
+
permissionDenials(log: string): string[];
|
|
66
79
|
/** Linux needs bwrap, socat and a user namespace; macOS ships Seatbelt. */
|
|
67
80
|
sandboxPreflight(host?: SandboxHost): Promise<SandboxPreflight>;
|
|
68
81
|
}
|
package/dist/src/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
7
7
|
import { promisify } from 'node:util';
|
|
8
8
|
import { CONDUCTOR_TOKEN_ENV, CONDUCTOR_TOOLS_SERVER, ensureHome, homeKey, homePath, installCommand, lastLine, resolveAgentCliOptions, resolveSecurityOptions, systemSandboxHost, validateOptionalBoolean, } from '@bakers-build/conductor/contract';
|
|
9
9
|
import { gitSandboxPaths, shellQuote, withoutGitDirs, } from '@bakers-build/core';
|
|
10
|
-
import { parseClaudeTranscript } from './footprint.js';
|
|
10
|
+
import { parseClaudePermissionDenials, parseClaudeTranscript, } from './footprint.js';
|
|
11
11
|
export { parseClaudeTranscript } from './footprint.js';
|
|
12
12
|
/** src/index.ts and dist/src/index.js both sit two levels below the package root. */
|
|
13
13
|
const MEASURE_WRAPPER = fileURLToPath(new URL(import.meta.url.includes('/dist/')
|
|
@@ -32,7 +32,7 @@ const SANDBOX_DEFAULTS = {
|
|
|
32
32
|
mcp_servers: {},
|
|
33
33
|
};
|
|
34
34
|
/** The launch flags a security mode owns (`docs/addons/claude.md`). */
|
|
35
|
-
function securityFlags({ mode, sandbox, config }, workspacePath, pluginsOn = false) {
|
|
35
|
+
function securityFlags({ mode, sandbox, config }, workspacePath, configDir, pluginsOn = false) {
|
|
36
36
|
if (mode === 'system')
|
|
37
37
|
return [];
|
|
38
38
|
if (mode === 'yolo')
|
|
@@ -59,18 +59,23 @@ function securityFlags({ mode, sandbox, config }, workspacePath, pluginsOn = fal
|
|
|
59
59
|
network: { allowedDomains: sandbox.network },
|
|
60
60
|
},
|
|
61
61
|
disableClaudeAiConnectors: true,
|
|
62
|
-
// What is allowed here runs without a prompt;
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
// Bash command is either sandboxed or a trusted command, and the
|
|
66
|
-
// deny covers the Read tool, which the OS sandbox does not confine.
|
|
62
|
+
// What is allowed here runs without a prompt; under dontAsk anything
|
|
63
|
+
// else, such as a write outside the worktree or to the protected
|
|
64
|
+
// `.claude/`, is denied at once, since nobody answers a prompt on a box.
|
|
65
|
+
// Every Bash command is either sandboxed or a trusted command, and the
|
|
66
|
+
// Read deny covers the Read tool, which the OS sandbox does not confine.
|
|
67
67
|
permissions: {
|
|
68
68
|
// The conductor's server binds every call to this run's worktree and project.
|
|
69
|
+
// The run's own plugins and skills live in its config dir, outside the worktree;
|
|
70
|
+
// Claude applies Read rules to Glob and Grep as well.
|
|
69
71
|
allow: [
|
|
70
72
|
'Bash',
|
|
71
73
|
'Edit(./**)',
|
|
72
74
|
'AskUserQuestion',
|
|
73
75
|
`mcp__${CONDUCTOR_TOOLS_SERVER}`,
|
|
76
|
+
'Skill',
|
|
77
|
+
`Read(/${join(configDir, 'plugins')}/**)`,
|
|
78
|
+
`Read(/${join(configDir, 'skills')}/**)`,
|
|
74
79
|
],
|
|
75
80
|
// Claude reads a single leading `/` as relative to the settings file;
|
|
76
81
|
// the plain rule covers a file entry, `/**` a directory's contents.
|
|
@@ -82,7 +87,7 @@ function securityFlags({ mode, sandbox, config }, workspacePath, pluginsOn = fal
|
|
|
82
87
|
};
|
|
83
88
|
return [
|
|
84
89
|
'--permission-mode',
|
|
85
|
-
'
|
|
90
|
+
'dontAsk',
|
|
86
91
|
// The agent home's user settings enable its plugins; the person's own stay out.
|
|
87
92
|
'--setting-sources',
|
|
88
93
|
pluginsOn ? 'user,project,local' : 'project,local',
|
|
@@ -219,6 +224,21 @@ export class ClaudeAgent {
|
|
|
219
224
|
if (prompt === '') {
|
|
220
225
|
return 'claude';
|
|
221
226
|
}
|
|
227
|
+
return this.command(this.measure
|
|
228
|
+
? ['node', shellQuote(MEASURE_WRAPPER), 'claude', shellQuote(prompt)]
|
|
229
|
+
: ['claude', shellQuote(prompt)], run, workspacePath, tools, pluginArgs);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* `claude --resume <id>` with the launch's own flags, so a run whose pane
|
|
233
|
+
* died continues its conversation. Not for a measured run: its wrapper
|
|
234
|
+
* profiles one fresh session.
|
|
235
|
+
*/
|
|
236
|
+
resumeCommand(sessionId, workspacePath, tools, _env, pluginArgs = []) {
|
|
237
|
+
if (this.measure)
|
|
238
|
+
return undefined;
|
|
239
|
+
return this.command(['claude', '--resume', shellQuote(sessionId)], undefined, workspacePath, tools, pluginArgs);
|
|
240
|
+
}
|
|
241
|
+
command(head, run, workspacePath, tools, pluginArgs) {
|
|
222
242
|
// Wait for project-declared plugins (extraKnownMarketplaces) to install
|
|
223
243
|
// before the first turn; a fresh worktree otherwise starts without them.
|
|
224
244
|
// A new worktree path would stop the run at Claude Code's trust dialog.
|
|
@@ -228,9 +248,7 @@ export class ClaudeAgent {
|
|
|
228
248
|
...(workspacePath
|
|
229
249
|
? ['node', shellQuote(TRUST_WRAPPER), shellQuote(workspacePath)]
|
|
230
250
|
: []),
|
|
231
|
-
...
|
|
232
|
-
? ['node', shellQuote(MEASURE_WRAPPER), 'claude', shellQuote(prompt)]
|
|
233
|
-
: ['claude', shellQuote(prompt)]),
|
|
251
|
+
...head,
|
|
234
252
|
];
|
|
235
253
|
if (this.model !== undefined && !this.overrides.model) {
|
|
236
254
|
parts.push('--model', shellQuote(this.model));
|
|
@@ -240,7 +258,7 @@ export class ClaudeAgent {
|
|
|
240
258
|
}
|
|
241
259
|
// The flags are constants; only their generated values need quoting.
|
|
242
260
|
parts.push(...[
|
|
243
|
-
...securityFlags(this.security, workspacePath, this.pluginsOn),
|
|
261
|
+
...securityFlags(this.security, workspacePath, this.configDir, this.pluginsOn),
|
|
244
262
|
...this.mcpFlags(tools),
|
|
245
263
|
].map((t) => (t.startsWith('--') ? t : shellQuote(t))));
|
|
246
264
|
// Pin the transcript's own session id to the run's UUID (BB-473), so
|
|
@@ -307,6 +325,22 @@ export class ClaudeAgent {
|
|
|
307
325
|
return false;
|
|
308
326
|
}
|
|
309
327
|
}
|
|
328
|
+
/** The run's pinned transcript only: the newest existing attempt, as {@link getRunLog} prefers it. */
|
|
329
|
+
async runLogModified(worktreePath, run) {
|
|
330
|
+
const dir = join(this.configDir, 'projects', encodeClaudeProjectDir(worktreePath));
|
|
331
|
+
const names = run.attemptFamily?.length
|
|
332
|
+
? [...run.attemptFamily].reverse()
|
|
333
|
+
: [run.sessionId];
|
|
334
|
+
for (const name of names) {
|
|
335
|
+
try {
|
|
336
|
+
return (await stat(join(dir, `${name}.jsonl`))).mtimeMs;
|
|
337
|
+
}
|
|
338
|
+
catch {
|
|
339
|
+
// try the next, lower-numbered attempt.
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return undefined;
|
|
343
|
+
}
|
|
310
344
|
async getRunLog(worktreePath, run) {
|
|
311
345
|
const dir = join(this.configDir, 'projects', encodeClaudeProjectDir(worktreePath));
|
|
312
346
|
const startedAtMs = run?.startedAt !== undefined ? new Date(run.startedAt).getTime() : null;
|
|
@@ -401,6 +435,12 @@ export class ClaudeAgent {
|
|
|
401
435
|
parseFootprint(log) {
|
|
402
436
|
return parseClaudeTranscript(log);
|
|
403
437
|
}
|
|
438
|
+
/** Only the sandbox launches in `dontAsk`; other modes are never reported. */
|
|
439
|
+
permissionDenials(log) {
|
|
440
|
+
if (this.securityMode !== 'sandbox')
|
|
441
|
+
return [];
|
|
442
|
+
return parseClaudePermissionDenials(log);
|
|
443
|
+
}
|
|
404
444
|
/** Linux needs bwrap, socat and a user namespace; macOS ships Seatbelt. */
|
|
405
445
|
async sandboxPreflight(host = systemSandboxHost()) {
|
|
406
446
|
if (this.securityMode !== 'sandbox' || host.platform !== 'linux') {
|
package/measure/agent-proxy.mjs
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* request writes a readable Markdown document — led by a ranked table of what
|
|
11
11
|
* is eating your context.
|
|
12
12
|
*
|
|
13
|
-
* Run:
|
|
13
|
+
* Run: BAKERS_TICKET_IDENTIFIER=BB-569 node measure/agent-proxy.mjs
|
|
14
14
|
* Point Claude Code at it:
|
|
15
15
|
* ANTHROPIC_BASE_URL=http://127.0.0.1:8787 claude
|
|
16
16
|
*
|
|
@@ -78,10 +78,10 @@ export function resolveLogDirectory({
|
|
|
78
78
|
ticketIdentifier,
|
|
79
79
|
subdir,
|
|
80
80
|
} = {}) {
|
|
81
|
-
const id = ticketIdentifier ?? process.env.
|
|
81
|
+
const id = ticketIdentifier ?? process.env.BAKERS_TICKET_IDENTIFIER;
|
|
82
82
|
if (typeof id !== 'string' || !TICKET_ID.test(id)) {
|
|
83
83
|
throw new Error(
|
|
84
|
-
'[agent-proxy]
|
|
84
|
+
'[agent-proxy] BAKERS_TICKET_IDENTIFIER is required (ticket identifier such as BB-569, not a UUID)',
|
|
85
85
|
);
|
|
86
86
|
}
|
|
87
87
|
const root = path.resolve(cwd, 'assets-ai', id, 'node');
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* exits. The proxy therefore lives exactly as long as the agent process: no
|
|
14
14
|
* conductor state, nothing to reap after a restart.
|
|
15
15
|
*
|
|
16
|
-
* Reads `
|
|
16
|
+
* Reads `BAKERS_STATE`, `BAKERS_TICKET_IDENTIFIER` and `BAKERS_RUN_UUID` from the run
|
|
17
17
|
* env; logs go to `assets-ai/<identifier>/node/<run uuid>/`, exported to the
|
|
18
18
|
* command as `BB_PROXY_LOG_DIR`. When the
|
|
19
19
|
* proxy cannot start (no identifier, log directory not gitignored) the command
|
|
@@ -64,7 +64,7 @@ function projectPlugins() {
|
|
|
64
64
|
|
|
65
65
|
// `--settings` outranks project settings, so fold the project's enabledPlugins
|
|
66
66
|
// into the copy: the profile is a default, the project has the last word.
|
|
67
|
-
const group = GROUPS[process.env.
|
|
67
|
+
const group = GROUPS[process.env.BAKERS_STATE] ?? 'ops';
|
|
68
68
|
let profile = JSON.parse(
|
|
69
69
|
fs.readFileSync(path.join(HERE, `keytec-${group}.json`), 'utf8'),
|
|
70
70
|
);
|
|
@@ -108,7 +108,7 @@ try {
|
|
|
108
108
|
port: 0,
|
|
109
109
|
cwd: process.cwd(),
|
|
110
110
|
quiet: true,
|
|
111
|
-
logSubdir: process.env.
|
|
111
|
+
logSubdir: process.env.BAKERS_RUN_UUID || undefined,
|
|
112
112
|
});
|
|
113
113
|
env.ANTHROPIC_BASE_URL = `http://127.0.0.1:${proxy.address.port}`;
|
|
114
114
|
env.BB_PROXY_LOG_DIR = proxy.logDirectory;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://bakers.build/schema/addon-claude/options.schema.json",
|
|
4
|
+
"title": "@bakers-build/addon-claude options",
|
|
5
|
+
"$ref": "https://bakers.build/schema/harness-options.schema.json",
|
|
6
|
+
"properties": {
|
|
7
|
+
"measure": {
|
|
8
|
+
"type": "boolean",
|
|
9
|
+
"description": "Run the launch through the measuring proxy. Default: false."
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"unevaluatedProperties": false
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/addon-claude",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1-next.2",
|
|
4
4
|
"description": "bakers.build agent plugin for the Claude CLI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./dist/src/index.js",
|
|
9
|
-
"./preset": "./dist/src/preset.js"
|
|
9
|
+
"./preset": "./dist/src/preset.js",
|
|
10
|
+
"./options.schema.json": "./options.schema.json"
|
|
10
11
|
},
|
|
11
12
|
"files": [
|
|
12
13
|
"dist/src",
|
|
13
14
|
"measure/*.json",
|
|
14
15
|
"measure/agent-proxy.mjs",
|
|
15
16
|
"measure/claude-measure.mjs",
|
|
16
|
-
"trust/claude-trust.mjs"
|
|
17
|
+
"trust/claude-trust.mjs",
|
|
18
|
+
"options.schema.json"
|
|
17
19
|
],
|
|
18
20
|
"publishConfig": {
|
|
19
21
|
"access": "public"
|
|
@@ -24,11 +26,11 @@
|
|
|
24
26
|
"directory": "bakers-cli/addons/claude"
|
|
25
27
|
},
|
|
26
28
|
"peerDependencies": {
|
|
27
|
-
"@bakers-build/conductor": "^0.8.
|
|
28
|
-
"@bakers-build/core": "^0.8.
|
|
29
|
+
"@bakers-build/conductor": "^0.8.1-next.2",
|
|
30
|
+
"@bakers-build/core": "^0.8.1-next.2"
|
|
29
31
|
},
|
|
30
32
|
"bakersBuild": {
|
|
31
|
-
"commit": "
|
|
32
|
-
"channel": "
|
|
33
|
+
"commit": "0177880667693d1c36c65ffced82d2f3a17cbf2a",
|
|
34
|
+
"channel": "next"
|
|
33
35
|
}
|
|
34
36
|
}
|