@bakers-build/addon-claude 0.7.1-next.7 → 0.8.1-next.1

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.
@@ -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[];
@@ -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
+ }
@@ -61,8 +61,12 @@ export declare class ClaudeAgent implements BbAgent {
61
61
  * launch at all, silently (`claude` exits 0 on that error).
62
62
  */
63
63
  sessionExists(worktreePath: string, sessionId: string): Promise<boolean>;
64
+ /** The run's pinned transcript only: the newest existing attempt, as {@link getRunLog} prefers it. */
65
+ runLogModified(worktreePath: string, run: AgentRunIdentity): Promise<number | undefined>;
64
66
  getRunLog(worktreePath: string, run?: AgentRunIdentity): Promise<string>;
65
67
  parseFootprint(log: string): AgentFootprint;
68
+ /** Only the sandbox launches in `dontAsk`; other modes are never reported. */
69
+ permissionDenials(log: string): string[];
66
70
  /** Linux needs bwrap, socat and a user namespace; macOS ships Seatbelt. */
67
71
  sandboxPreflight(host?: SandboxHost): Promise<SandboxPreflight>;
68
72
  }
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; anything else, such as a
63
- // write to the protected `.claude/`, asks the human watching the run's
64
- // terminal (dontAsk would deny it, and no allow rule lifts that). Every
65
- // Bash command is either sandboxed or a trusted command, and the Read
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
- 'default',
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',
@@ -240,7 +245,7 @@ export class ClaudeAgent {
240
245
  }
241
246
  // The flags are constants; only their generated values need quoting.
242
247
  parts.push(...[
243
- ...securityFlags(this.security, workspacePath, this.pluginsOn),
248
+ ...securityFlags(this.security, workspacePath, this.configDir, this.pluginsOn),
244
249
  ...this.mcpFlags(tools),
245
250
  ].map((t) => (t.startsWith('--') ? t : shellQuote(t))));
246
251
  // Pin the transcript's own session id to the run's UUID (BB-473), so
@@ -307,6 +312,22 @@ export class ClaudeAgent {
307
312
  return false;
308
313
  }
309
314
  }
315
+ /** The run's pinned transcript only: the newest existing attempt, as {@link getRunLog} prefers it. */
316
+ async runLogModified(worktreePath, run) {
317
+ const dir = join(this.configDir, 'projects', encodeClaudeProjectDir(worktreePath));
318
+ const names = run.attemptFamily?.length
319
+ ? [...run.attemptFamily].reverse()
320
+ : [run.sessionId];
321
+ for (const name of names) {
322
+ try {
323
+ return (await stat(join(dir, `${name}.jsonl`))).mtimeMs;
324
+ }
325
+ catch {
326
+ // try the next, lower-numbered attempt.
327
+ }
328
+ }
329
+ return undefined;
330
+ }
310
331
  async getRunLog(worktreePath, run) {
311
332
  const dir = join(this.configDir, 'projects', encodeClaudeProjectDir(worktreePath));
312
333
  const startedAtMs = run?.startedAt !== undefined ? new Date(run.startedAt).getTime() : null;
@@ -401,6 +422,12 @@ export class ClaudeAgent {
401
422
  parseFootprint(log) {
402
423
  return parseClaudeTranscript(log);
403
424
  }
425
+ /** Only the sandbox launches in `dontAsk`; other modes are never reported. */
426
+ permissionDenials(log) {
427
+ if (this.securityMode !== 'sandbox')
428
+ return [];
429
+ return parseClaudePermissionDenials(log);
430
+ }
404
431
  /** Linux needs bwrap, socat and a user namespace; macOS ships Seatbelt. */
405
432
  async sandboxPreflight(host = systemSandboxHost()) {
406
433
  if (this.securityMode !== 'sandbox' || host.platform !== 'linux') {
@@ -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: BB_TICKET_IDENTIFIER=BB-569 node measure/agent-proxy.mjs
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.BB_TICKET_IDENTIFIER;
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] BB_TICKET_IDENTIFIER is required (ticket identifier such as BB-569, not a UUID)',
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 `BB_STATE`, `BB_TICKET_IDENTIFIER` and `BB_RUN_UUID` from the run
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.BB_STATE] ?? 'ops';
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.BB_RUN_UUID || undefined,
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.7.1-next.7",
3
+ "version": "0.8.1-next.1",
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.7.1-next.7",
28
- "@bakers-build/core": "^0.7.1-next.7"
29
+ "@bakers-build/conductor": "^0.8.1-next.1",
30
+ "@bakers-build/core": "^0.8.1-next.1"
29
31
  },
30
32
  "bakersBuild": {
31
- "commit": "082d8c57436f78e751f5a9a26a4446cec42209ce",
33
+ "commit": "c4a887bee37bb2fed14bb9ba15ad0aacf0e26f7e",
32
34
  "channel": "next"
33
35
  }
34
36
  }