@bakers-build/addon-claude 0.7.1-next.1 → 0.7.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/index.js CHANGED
@@ -10,6 +10,9 @@ export { parseClaudeTranscript } from './footprint.js';
10
10
  const MEASURE_WRAPPER = fileURLToPath(new URL(import.meta.url.includes('/dist/')
11
11
  ? '../../measure/claude-measure.mjs'
12
12
  : '../measure/claude-measure.mjs', import.meta.url));
13
+ const TRUST_WRAPPER = fileURLToPath(new URL(import.meta.url.includes('/dist/')
14
+ ? '../../trust/claude-trust.mjs'
15
+ : '../trust/claude-trust.mjs', import.meta.url));
13
16
  /** Flag → value pairs; a flag the security mode already passes is skipped. */
14
17
  const MEASURE_FLAGS = [
15
18
  ['--setting-sources', 'project,local'],
@@ -156,8 +159,12 @@ export class ClaudeAgent {
156
159
  }
157
160
  // Wait for project-declared plugins (extraKnownMarketplaces) to install
158
161
  // before the first turn; a fresh worktree otherwise starts without them.
162
+ // A new worktree path would stop the run at Claude Code's trust dialog.
159
163
  const parts = [
160
164
  'CLAUDE_CODE_SYNC_PLUGIN_INSTALL=1',
165
+ ...(workspacePath
166
+ ? ['node', shellQuote(TRUST_WRAPPER), shellQuote(workspacePath)]
167
+ : []),
161
168
  ...(this.measure
162
169
  ? ['node', shellQuote(MEASURE_WRAPPER), 'claude', shellQuote(prompt)]
163
170
  : ['claude', shellQuote(prompt)]),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-claude",
3
- "version": "0.7.1-next.1",
3
+ "version": "0.7.1-next.2",
4
4
  "description": "bakers.build agent plugin for the Claude CLI.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -12,7 +12,8 @@
12
12
  "dist/src",
13
13
  "measure/*.json",
14
14
  "measure/agent-proxy.mjs",
15
- "measure/claude-measure.mjs"
15
+ "measure/claude-measure.mjs",
16
+ "trust/claude-trust.mjs"
16
17
  ],
17
18
  "publishConfig": {
18
19
  "access": "public"
@@ -23,11 +24,11 @@
23
24
  "directory": "bakers-cli/addons/claude"
24
25
  },
25
26
  "peerDependencies": {
26
- "@bakers-build/conductor": "^0.7.1-next.1",
27
- "@bakers-build/core": "^0.7.1-next.1"
27
+ "@bakers-build/conductor": "^0.7.1-next.2",
28
+ "@bakers-build/core": "^0.7.1-next.2"
28
29
  },
29
30
  "bakersBuild": {
30
- "commit": "f75ebcfd83a8766b903db1aa8f000444af2b1754",
31
+ "commit": "52ccbdce27702162de032e85608b24c6ed161ac9",
31
32
  "channel": "next"
32
33
  }
33
34
  }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * claude-trust — launch wrapper of `@bakers-build/addon-claude` for a run in a worktree.
3
+ *
4
+ * node claude-trust.mjs <worktree> <command> [args…]
5
+ *
6
+ * Marks exactly <worktree> as trusted in `~/.claude.json`
7
+ * (`projects[<worktree>].hasTrustDialogAccepted`), so Claude Code does not stop the run at
8
+ * its workspace trust dialog, then runs the command. Every other key is kept; an already
9
+ * trusted worktree is not written. The write goes to a temporary file that is renamed over
10
+ * the original. When the file cannot be read or parsed, it is left untouched: the command
11
+ * still runs and shows the dialog, with a warning on stderr.
12
+ */
13
+
14
+ import { spawn } from 'node:child_process';
15
+ import fs from 'node:fs';
16
+ import os from 'node:os';
17
+ import path from 'node:path';
18
+
19
+ const [worktree, command, ...args] = process.argv.slice(2);
20
+ if (!worktree || !command) {
21
+ console.error('usage: node claude-trust.mjs <worktree> <command> [args…]');
22
+ process.exit(2);
23
+ }
24
+
25
+ function trust() {
26
+ if (!path.isAbsolute(worktree)) {
27
+ throw new Error(`not an absolute path: ${worktree}`);
28
+ }
29
+ const file = path.join(os.homedir(), '.claude.json');
30
+ let config = {};
31
+ let mode = 0o600;
32
+ try {
33
+ config = JSON.parse(fs.readFileSync(file, 'utf8'));
34
+ mode = fs.statSync(file).mode & 0o777;
35
+ } catch (err) {
36
+ if (err.code !== 'ENOENT') throw err;
37
+ }
38
+ if (config.projects?.[worktree]?.hasTrustDialogAccepted === true) return;
39
+ config.projects ??= {};
40
+ config.projects[worktree] = {
41
+ ...config.projects[worktree],
42
+ hasTrustDialogAccepted: true,
43
+ };
44
+ // shortcut: no lock; a Claude Code write in the same moment can be lost. Lock if one is.
45
+ const tmp = `${file}.${process.pid}.tmp`;
46
+ fs.writeFileSync(tmp, `${JSON.stringify(config, null, 2)}\n`, { mode });
47
+ fs.chmodSync(tmp, mode);
48
+ fs.renameSync(tmp, file);
49
+ }
50
+
51
+ try {
52
+ trust();
53
+ } catch (err) {
54
+ console.error(`claude-trust: ${err.message} — the trust dialog may show`);
55
+ }
56
+
57
+ const child = spawn(command, args, { stdio: 'inherit' });
58
+ // The terminal sends SIGINT to the whole process group; the child decides.
59
+ process.on('SIGINT', () => {});
60
+ for (const signal of ['SIGTERM', 'SIGHUP']) {
61
+ process.on(signal, () => child.kill(signal));
62
+ }
63
+ child.on('error', (err) => {
64
+ console.error(`claude-trust: ${err.message}`);
65
+ process.exit(127);
66
+ });
67
+ child.on('exit', (code, signal) => {
68
+ process.exit(code ?? (signal ? 128 + os.constants.signals[signal] : 1));
69
+ });