@bakers-build/addon-claude 0.9.1-next.3 → 0.9.1-next.4

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.
@@ -15,6 +15,11 @@ export interface ClaudeAgentOptions extends SecurityOptions {
15
15
  * applies the state-group settings shipped with the addon.
16
16
  */
17
17
  measure?: boolean;
18
+ /**
19
+ * When true (and `measure` is not), the unchanged launch runs through
20
+ * `claude-measure.mjs --capture`, which only logs every model request.
21
+ */
22
+ proxy?: boolean;
18
23
  /** False runs this agent in the user's own `~/.claude`, without the project's plugins. */
19
24
  plugins?: boolean;
20
25
  }
@@ -32,6 +37,7 @@ export declare class ClaudeAgent implements BbAgent {
32
37
  /** Set by the last launch: the conductor's server replaced the sandbox's own `bakers`. */
33
38
  private replacedBakersServer;
34
39
  private readonly measure;
40
+ private readonly proxy;
35
41
  private readonly overrides;
36
42
  readonly pluginsDisabled: boolean;
37
43
  /** The Claude config dir runs read and write: the agent home while plugins are on. */
package/dist/src/index.js CHANGED
@@ -139,6 +139,7 @@ export class ClaudeAgent {
139
139
  /** Set by the last launch: the conductor's server replaced the sandbox's own `bakers`. */
140
140
  replacedBakersServer = false;
141
141
  measure;
142
+ proxy;
142
143
  overrides;
143
144
  pluginsDisabled;
144
145
  /** The Claude config dir runs read and write: the agent home while plugins are on. */
@@ -164,6 +165,7 @@ export class ClaudeAgent {
164
165
  this.securityMode = security.mode;
165
166
  this.runEnvPolicy = security.runEnvPolicy;
166
167
  this.measure = validateOptionalBoolean(options.measure, 'measure') ?? false;
168
+ this.proxy = validateOptionalBoolean(options.proxy, 'proxy') ?? false;
167
169
  this.pluginsDisabled =
168
170
  validateOptionalBoolean(options.plugins, 'plugins') === false;
169
171
  this.configDir = join(home, '.claude');
@@ -229,8 +231,12 @@ export class ClaudeAgent {
229
231
  ? ['node', shellQuote(TRUST_WRAPPER), shellQuote(workspacePath)]
230
232
  : []),
231
233
  ...(this.measure
232
- ? ['node', shellQuote(MEASURE_WRAPPER), 'claude', shellQuote(prompt)]
233
- : ['claude', shellQuote(prompt)]),
234
+ ? ['node', shellQuote(MEASURE_WRAPPER)]
235
+ : this.proxy
236
+ ? ['node', shellQuote(MEASURE_WRAPPER), '--capture']
237
+ : []),
238
+ 'claude',
239
+ shellQuote(prompt),
234
240
  ];
235
241
  if (this.model !== undefined && !this.overrides.model) {
236
242
  parts.push('--model', shellQuote(this.model));
@@ -27,11 +27,23 @@ export const agents = (acc, opts) => {
27
27
  description: 'Demanding problems and long-running autonomous work.',
28
28
  model: 'fable',
29
29
  },
30
+ {
31
+ alias: 'opus-proxy',
32
+ description: 'Opus with every model request logged to `assets-ai/`; for diagnostics, not routine work.',
33
+ model: 'opus',
34
+ proxy: true,
35
+ },
30
36
  ].map((candidate) => 'agent' in candidate
31
37
  ? candidate
32
38
  : {
33
- ...candidate,
34
- agent: claudeAgent({ ...opts, model: candidate.model }),
39
+ alias: candidate.alias,
40
+ description: candidate.description,
41
+ model: candidate.model,
42
+ agent: claudeAgent({
43
+ ...opts,
44
+ model: candidate.model,
45
+ ...('proxy' in candidate && { proxy: candidate.proxy }),
46
+ }),
35
47
  });
36
48
  };
37
49
  // Agents are per machine: list this addon in ~/.bakers/machine.config.js addons[].
@@ -37,6 +37,7 @@ const USAGE_KEYS = [
37
37
  'input_tokens',
38
38
  'cache_read_input_tokens',
39
39
  'cache_creation_input_tokens',
40
+ 'output_tokens',
40
41
  ];
41
42
  const REDACT = new Set(['authorization', 'x-api-key', 'api-key']);
42
43
 
@@ -191,6 +192,7 @@ function renderAudit(a) {
191
192
  `- **input_tokens**: ${a.usage.input_tokens}`,
192
193
  `- **cache_read_input_tokens**: ${a.usage.cache_read_input_tokens}`,
193
194
  `- **cache_creation_input_tokens**: ${a.usage.cache_creation_input_tokens}`,
195
+ `- **output_tokens**: ${a.usage.output_tokens}`,
194
196
  ]
195
197
  : ['- **usage**: unknown'];
196
198
 
@@ -219,7 +221,7 @@ function printAudit(a, base, logDir) {
219
221
  const top = a.toolRows.slice(0, 12);
220
222
  const w = Math.max(4, ...top.map((r) => r.name.length));
221
223
  const usage = a.usage
222
- ? ` · in ${a.usage.input_tokens} / cache-read ${a.usage.cache_read_input_tokens} / cache-create ${a.usage.cache_creation_input_tokens}`
224
+ ? ` · in ${a.usage.input_tokens} / cache-read ${a.usage.cache_read_input_tokens} / cache-create ${a.usage.cache_creation_input_tokens} / out ${a.usage.output_tokens}`
223
225
  : '';
224
226
  console.log(
225
227
  `\n[agent-proxy] ${a.toolCount} tools · ${a.toolsBytes.toLocaleString()} tool bytes · first user ${a.firstUserBytes.toLocaleString()} B${usage}`,
@@ -18,6 +18,12 @@
18
18
  * command as `BB_PROXY_LOG_DIR`. When the
19
19
  * proxy cannot start (no identifier, log directory not gitignored) the command
20
20
  * still runs, unmeasured, with a warning on stderr.
21
+ *
22
+ * node claude-measure.mjs --capture claude <claude args…>
23
+ *
24
+ * The `with.proxy` mode: only the proxy, its log directory and
25
+ * `ANTHROPIC_BASE_URL`; argv and settings pass through unchanged and no
26
+ * settings file is written, so the log shows what a normal run sends.
21
27
  */
22
28
 
23
29
  import { spawn, spawnSync } from 'node:child_process';
@@ -39,9 +45,12 @@ const GROUPS = {
39
45
  review: 'review',
40
46
  };
41
47
 
42
- const [command, ...args] = process.argv.slice(2);
48
+ const argv = process.argv.slice(2);
49
+ // `--capture` only logs: argv and the caller's settings stay untouched.
50
+ const capture = argv[0] === '--capture';
51
+ const [command, ...args] = capture ? argv.slice(1) : argv;
43
52
  if (!command) {
44
- console.error('usage: node claude-measure.mjs <command> [args…]');
53
+ console.error('usage: node claude-measure.mjs [--capture] <command> [args…]');
45
54
  process.exit(2);
46
55
  }
47
56
 
@@ -62,43 +71,48 @@ function projectPlugins() {
62
71
  return merged;
63
72
  }
64
73
 
65
- // `--settings` outranks project settings, so fold the project's enabledPlugins
66
- // into the copy: the profile is a default, the project has the last word.
67
- const group = GROUPS[process.env.BAKERS_STATE] ?? 'ops';
68
- let profile = JSON.parse(
69
- fs.readFileSync(path.join(HERE, `keytec-${group}.json`), 'utf8'),
70
- );
71
- // The last one: an alias's own `--settings` precedes the measure flags.
72
- const settingsAt = args.lastIndexOf('--settings');
73
- // A security mode's inline settings (sandbox, custom) win over the profile;
74
- // permission lists are joined so neither side's rules are lost.
75
- const inline = settingsAt === -1 ? undefined : args[settingsAt + 1];
76
- if (inline?.trimStart().startsWith('{')) {
77
- const own = JSON.parse(inline);
78
- const join = (key) => [
79
- ...(profile.permissions?.[key] ?? []),
80
- ...(own.permissions?.[key] ?? []),
81
- ];
82
- profile = {
83
- ...profile,
84
- ...own,
85
- permissions: {
86
- ...profile.permissions,
87
- ...own.permissions,
88
- allow: join('allow'),
89
- deny: join('deny'),
90
- },
91
- };
74
+ /** Write the measure settings file; returns the temporary file to remove, if any. */
75
+ function writeMeasureSettings() {
76
+ // `--settings` outranks project settings, so fold the project's enabledPlugins
77
+ // into the copy: the profile is a default, the project has the last word.
78
+ const group = GROUPS[process.env.BAKERS_STATE] ?? 'ops';
79
+ let profile = JSON.parse(
80
+ fs.readFileSync(path.join(HERE, `keytec-${group}.json`), 'utf8'),
81
+ );
82
+ // The last one: an alias's own `--settings` precedes the measure flags.
83
+ const settingsAt = args.lastIndexOf('--settings');
84
+ // A security mode's inline settings (sandbox, custom) win over the profile;
85
+ // permission lists are joined so neither side's rules are lost.
86
+ const inline = settingsAt === -1 ? undefined : args[settingsAt + 1];
87
+ if (inline?.trimStart().startsWith('{')) {
88
+ const own = JSON.parse(inline);
89
+ const join = (key) => [
90
+ ...(profile.permissions?.[key] ?? []),
91
+ ...(own.permissions?.[key] ?? []),
92
+ ];
93
+ profile = {
94
+ ...profile,
95
+ ...own,
96
+ permissions: {
97
+ ...profile.permissions,
98
+ ...own.permissions,
99
+ allow: join('allow'),
100
+ deny: join('deny'),
101
+ },
102
+ };
103
+ }
104
+ profile.enabledPlugins = { ...profile.enabledPlugins, ...projectPlugins() };
105
+ const ignored =
106
+ spawnSync('git', ['check-ignore', '-q', SETTINGS_REL]).status === 0;
107
+ const settingsFile = ignored
108
+ ? SETTINGS_REL
109
+ : path.join(os.tmpdir(), `claude-measure-${randomUUID()}.settings.json`);
110
+ if (settingsAt !== -1) args[settingsAt + 1] = settingsFile;
111
+ fs.mkdirSync(path.dirname(settingsFile), { recursive: true });
112
+ fs.writeFileSync(settingsFile, `${JSON.stringify(profile, null, 2)}\n`);
113
+ return ignored ? undefined : settingsFile;
92
114
  }
93
- profile.enabledPlugins = { ...profile.enabledPlugins, ...projectPlugins() };
94
- const ignored =
95
- spawnSync('git', ['check-ignore', '-q', SETTINGS_REL]).status === 0;
96
- const settingsFile = ignored
97
- ? SETTINGS_REL
98
- : path.join(os.tmpdir(), `claude-measure-${randomUUID()}.settings.json`);
99
- if (settingsAt !== -1) args[settingsAt + 1] = settingsFile;
100
- fs.mkdirSync(path.dirname(settingsFile), { recursive: true });
101
- fs.writeFileSync(settingsFile, `${JSON.stringify(profile, null, 2)}\n`);
115
+ const tempSettings = capture ? undefined : writeMeasureSettings();
102
116
 
103
117
  const env = { ...process.env };
104
118
  let proxy;
@@ -124,11 +138,11 @@ for (const signal of ['SIGTERM', 'SIGHUP']) {
124
138
  }
125
139
  child.on('error', (err) => {
126
140
  console.error(`claude-measure: ${err.message}`);
127
- if (!ignored) fs.rmSync(settingsFile, { force: true });
141
+ if (tempSettings) fs.rmSync(tempSettings, { force: true });
128
142
  process.exit(127);
129
143
  });
130
144
  child.on('exit', async (code, signal) => {
131
145
  await proxy?.close();
132
- if (!ignored) fs.rmSync(settingsFile, { force: true });
146
+ if (tempSettings) fs.rmSync(tempSettings, { force: true });
133
147
  process.exit(code ?? (signal ? 128 + os.constants.signals[signal] : 1));
134
148
  });
@@ -9,8 +9,13 @@
9
9
  "description": "Start the launch through the addon's measuring proxy.",
10
10
  "default": false
11
11
  },
12
+ "proxy": {
13
+ "type": "boolean",
14
+ "description": "Log every model request of the unchanged launch to `assets-ai/`; `measure` wins.",
15
+ "default": false
16
+ },
12
17
  "model": {
13
- "description": "Passed as `--model`; replaces `opus`, `sonnet` and `fable` with one custom candidate."
18
+ "description": "Passed as `--model`; replaces `opus`, `sonnet`, `fable` and `opus-proxy` with one custom candidate."
14
19
  },
15
20
  "effort": {
16
21
  "description": "Passed as `--effort`."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-claude",
3
- "version": "0.9.1-next.3",
3
+ "version": "0.9.1-next.4",
4
4
  "description": "bakers.build agent plugin for the Claude CLI.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -26,11 +26,11 @@
26
26
  "directory": "bakers-cli/addons/claude"
27
27
  },
28
28
  "peerDependencies": {
29
- "@bakers-build/conductor": "^0.9.1-next.3",
30
- "@bakers-build/core": "^0.9.1-next.3"
29
+ "@bakers-build/conductor": "^0.9.1-next.4",
30
+ "@bakers-build/core": "^0.9.1-next.4"
31
31
  },
32
32
  "bakersBuild": {
33
- "commit": "f544c368eb0b64e6512432ac2ca8c3ab8b14ceef",
33
+ "commit": "e5f8dc988628be67c3d92064cb3229e30ad2edde",
34
34
  "channel": "next"
35
35
  }
36
36
  }