@bakers-build/addon-claude 0.9.1-next.5 → 0.9.1-next.6

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.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Point `path` at the single host login `host` again. Claude Code refreshes by
3
+ * renaming a new file over `path`, which replaces a symlink with a private copy;
4
+ * a copy newer than the host's login becomes the host's before it is relinked.
5
+ */
6
+ export declare function shareLogin(host: string, path: string): void;
@@ -0,0 +1,30 @@
1
+ import { existsSync, lstatSync, readFileSync, readlinkSync, renameSync, rmSync, symlinkSync, writeFileSync, } from 'node:fs';
2
+ /** The login's expiry; an unreadable file counts as oldest. */
3
+ function expiry(file) {
4
+ try {
5
+ return (Number(JSON.parse(readFileSync(file, 'utf8')).claudeAiOauth?.expiresAt) ||
6
+ 0);
7
+ }
8
+ catch {
9
+ return 0;
10
+ }
11
+ }
12
+ /**
13
+ * Point `path` at the single host login `host` again. Claude Code refreshes by
14
+ * renaming a new file over `path`, which replaces a symlink with a private copy;
15
+ * a copy newer than the host's login becomes the host's before it is relinked.
16
+ */
17
+ export function shareLogin(host, path) {
18
+ const stat = lstatSync(path, { throwIfNoEntry: false });
19
+ if (stat?.isSymbolicLink() && readlinkSync(path) === host)
20
+ return;
21
+ if (stat?.isFile() && (!existsSync(host) || expiry(path) > expiry(host)))
22
+ // In place, not by rename: runs bind-mount the host file's inode.
23
+ writeFileSync(host, readFileSync(path), { mode: 0o600 });
24
+ if (!existsSync(host))
25
+ throw new Error(`claude: no usable login at ${host}; log in on the host with \`claude /login\``);
26
+ const link = `${path}.${process.pid}.link`;
27
+ rmSync(link, { force: true });
28
+ symlinkSync(host, link);
29
+ renameSync(link, path);
30
+ }
@@ -52,7 +52,7 @@ export declare class ClaudeAgent implements BbAgent {
52
52
  get withoutConductorTools(): boolean;
53
53
  launchCommand(prompt: string, run?: AgentRunIdentity, workspacePath?: string, tools?: {
54
54
  url: string;
55
- }, _env?: Readonly<Record<string, string>>, pluginArgs?: readonly string[]): string;
55
+ }, _env?: Readonly<Record<string, string>>, pluginArgs?: readonly string[], isolatedGit?: boolean): string;
56
56
  /**
57
57
  * The sandbox's strict MCP config, plus the conductor's tool server when
58
58
  * the run has one. A measured run stays without MCP servers. The token is
package/dist/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { execFile } from 'node:child_process';
2
- import { existsSync, readFileSync, symlinkSync, writeFileSync } from 'node:fs';
2
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
3
3
  import { readdir, readFile, stat } from 'node:fs/promises';
4
4
  import { homedir } from 'node:os';
5
5
  import { join } from 'node:path';
@@ -7,6 +7,7 @@ import { fileURLToPath } from 'node:url';
7
7
  import { promisify } from 'node:util';
8
8
  import { CONDUCTOR_TOKEN_ENV, CONDUCTOR_TOOL_TIMEOUT_MS, 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 { shareLogin } from './credentials.js';
10
11
  import { parseClaudeTranscript } from './footprint.js';
11
12
  import { encodeClaudeProjectDir, prepareClaudeRun } from './run.js';
12
13
  import { claudeInstallCommand, claudeModelApi } from './setup.js';
@@ -36,7 +37,7 @@ const SANDBOX_DEFAULTS = {
36
37
  mcp_servers: {},
37
38
  };
38
39
  /** The launch flags a security mode owns (`docs/addons/claude.md`). */
39
- function securityFlags({ mode, sandbox, config }, workspacePath, pluginsOn = false) {
40
+ function securityFlags({ mode, sandbox, config }, workspacePath, pluginsOn = false, isolatedGit = false) {
40
41
  if (mode === 'system')
41
42
  return [];
42
43
  if (mode === 'yolo')
@@ -46,7 +47,7 @@ function securityFlags({ mode, sandbox, config }, workspacePath, pluginsOn = fal
46
47
  // Git metadata only for a known workspace; the conductor always passes one.
47
48
  const git = workspacePath === undefined
48
49
  ? { write: [], protect: [] }
49
- : gitSandboxPaths(workspacePath);
50
+ : gitSandboxPaths(workspacePath, isolatedGit);
50
51
  const settings = {
51
52
  sandbox: {
52
53
  enabled: true,
@@ -180,11 +181,10 @@ export class ClaudeAgent {
180
181
  return prepareClaudeRun(context, this.configDir);
181
182
  }
182
183
  async installPlugins(marketplaces, home) {
184
+ const credentials = join(this.home, '.claude', '.credentials.json');
183
185
  const outcome = await ensureHome(home, async (dir) => {
184
- const credentials = join(this.home, '.claude', '.credentials.json');
185
186
  if (!existsSync(credentials))
186
187
  throw new Error(`claude: no credential file at ${credentials} (a keychain login cannot be shared with an agent home); log in with a file-based credential`);
187
- symlinkSync(credentials, join(dir, '.credentials.json'));
188
188
  for (const { url, ref, plugins } of marketplaces) {
189
189
  const added = await claudeJson(dir, url, [
190
190
  'plugin',
@@ -206,6 +206,8 @@ export class ClaudeAgent {
206
206
  : {};
207
207
  writeFileSync(state, `${JSON.stringify({ ...seeded, hasCompletedOnboarding: true }, null, 2)}\n`, { mode: 0o600 });
208
208
  });
209
+ // Every use: a token refresh inside the home replaced the link with a copy.
210
+ shareLogin(credentials, join(home, '.credentials.json'));
209
211
  return { env: { CLAUDE_CONFIG_DIR: home }, args: [], home: outcome };
210
212
  }
211
213
  get launchWarnings() {
@@ -219,7 +221,7 @@ export class ClaudeAgent {
219
221
  get withoutConductorTools() {
220
222
  return this.measure;
221
223
  }
222
- launchCommand(prompt, run, workspacePath, tools, _env, pluginArgs = []) {
224
+ launchCommand(prompt, run, workspacePath, tools, _env, pluginArgs = [], isolatedGit = false) {
223
225
  if (prompt === '') {
224
226
  return 'claude';
225
227
  }
@@ -248,7 +250,7 @@ export class ClaudeAgent {
248
250
  }
249
251
  // The flags are constants; only their generated values need quoting.
250
252
  parts.push(...[
251
- ...securityFlags(this.security, workspacePath, this.pluginsOn),
253
+ ...securityFlags(this.security, workspacePath, this.pluginsOn, isolatedGit),
252
254
  ...this.mcpFlags(tools),
253
255
  ].map((t) => (t.startsWith('--') ? t : shellQuote(t))));
254
256
  // Pin the transcript's own session id to the run's UUID (BB-473), so
package/dist/src/run.js CHANGED
@@ -1,4 +1,4 @@
1
- import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, symlinkSync, writeFileSync, } from 'node:fs';
1
+ import { existsSync, mkdirSync, readFileSync, realpathSync, symlinkSync, writeFileSync, } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  export function encodeClaudeProjectDir(cwd) {
4
4
  return cwd.replace(/[^a-zA-Z0-9]/g, '-');
@@ -8,8 +8,12 @@ export function prepareClaudeRun(context, configDir, hostEnv = process.env) {
8
8
  const source = context.env.CLAUDE_CONFIG_DIR ?? configDir;
9
9
  const config = join(context.homePath, '.claude');
10
10
  mkdirSync(config, { recursive: true });
11
- if (existsSync(join(source, 'settings.json')))
12
- copyFileSync(join(source, 'settings.json'), join(config, 'settings.json'));
11
+ // Bypass consent is a user setting. A new private home has none, so a
12
+ // `yolo` run would stop at Claude Code's bypass permissions dialog.
13
+ const settings = existsSync(join(source, 'settings.json'))
14
+ ? JSON.parse(readFileSync(join(source, 'settings.json'), 'utf8'))
15
+ : {};
16
+ writeFileSync(join(config, 'settings.json'), JSON.stringify({ ...settings, skipDangerousModePermissionPrompt: true }));
13
17
  const state = existsSync(join(source, '.claude.json'))
14
18
  ? JSON.parse(readFileSync(join(source, '.claude.json'), 'utf8'))
15
19
  : {};
@@ -17,14 +21,20 @@ export function prepareClaudeRun(context, configDir, hostEnv = process.env) {
17
21
  const keys = ['CLAUDE_CODE_OAUTH_TOKEN', 'ANTHROPIC_API_KEY'];
18
22
  const env = { CLAUDE_CONFIG_DIR: config };
19
23
  const supplied = keys.some((key) => context.env[key]);
24
+ const bindPaths = [];
20
25
  if (!supplied) {
21
26
  const key = keys.find((name) => hostEnv[name]);
22
27
  if (key)
23
28
  env[key] = hostEnv[key];
24
29
  else if (existsSync(join(source, '.credentials.json'))) {
30
+ // The run shares the host's login file, never a copy: a refresh in one
31
+ // copy rotates the token and logs every other copy out.
25
32
  const login = join(config, '.credentials.json');
26
- copyFileSync(join(source, '.credentials.json'), login);
27
- chmodSync(login, 0o600);
33
+ writeFileSync(login, '', { mode: 0o600 });
34
+ bindPaths.push({
35
+ source: realpathSync(join(source, '.credentials.json')),
36
+ target: login,
37
+ });
28
38
  }
29
39
  }
30
40
  const apiKey = context.env.ANTHROPIC_API_KEY ?? env.ANTHROPIC_API_KEY;
@@ -51,5 +61,10 @@ export function prepareClaudeRun(context, configDir, hostEnv = process.env) {
51
61
  mkdirSync(transcripts, { recursive: true });
52
62
  mkdirSync(join(config, 'projects'), { recursive: true });
53
63
  symlinkSync(transcripts, join(config, 'projects', key));
54
- return { env, readPaths, writePaths: [transcripts] };
64
+ return {
65
+ env,
66
+ readPaths,
67
+ writePaths: [transcripts],
68
+ ...(bindPaths.length ? { bindPaths } : {}),
69
+ };
55
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-claude",
3
- "version": "0.9.1-next.5",
3
+ "version": "0.9.1-next.6",
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.5",
30
- "@bakers-build/core": "^0.9.1-next.5"
29
+ "@bakers-build/conductor": "^0.9.1-next.6",
30
+ "@bakers-build/core": "^0.9.1-next.6"
31
31
  },
32
32
  "bakersBuild": {
33
- "commit": "d9242cad6cabee1faf010b5d46ac1bac33f6e0a1",
33
+ "commit": "e7d9921d51d5c045f29ca7e35d1e6a348e6ddf08",
34
34
  "channel": "next"
35
35
  }
36
36
  }