@bakers-build/addon-claude 0.9.1-next.4 → 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.
- package/dist/src/credentials.d.ts +6 -0
- package/dist/src/credentials.js +30 -0
- package/dist/src/index.d.ts +7 -7
- package/dist/src/index.js +18 -14
- package/dist/src/run.d.ts +4 -0
- package/dist/src/run.js +70 -0
- package/dist/src/setup.d.ts +3 -0
- package/dist/src/setup.js +14 -0
- package/package.json +4 -4
|
@@ -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
|
+
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { type AgentFootprint, type AgentPlugin, type AgentRunIdentity, type BbAgent, type MarketplaceDeclaration, type PluginLaunch, type ResolvedSecurity, type RunEnvPolicy, type SandboxHost, type SandboxPreflight, type SecurityOptions } from '@bakers-build/conductor/contract';
|
|
1
|
+
import { type AgentFootprint, type AgentPlugin, type AgentRunContext, type AgentRunIdentity, type BbAgent, type MarketplaceDeclaration, type PluginLaunch, type ResolvedSecurity, type RunEnvPolicy, type SandboxHost, type SandboxPreflight, type SecurityOptions } from '@bakers-build/conductor/contract';
|
|
2
2
|
export { parseClaudeTranscript } from './footprint.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* directory under `~/.claude/projects/`: every non-alphanumeric char → `-`.
|
|
6
|
-
*/
|
|
7
|
-
export declare function encodeClaudeProjectDir(cwd: string): string;
|
|
3
|
+
export { encodeClaudeProjectDir } from './run.js';
|
|
4
|
+
export { claudeInstallCommand, claudeModelApi } from './setup.js';
|
|
8
5
|
export interface ClaudeAgentOptions extends SecurityOptions {
|
|
9
6
|
model?: string;
|
|
10
7
|
effort?: string;
|
|
@@ -26,6 +23,8 @@ export interface ClaudeAgentOptions extends SecurityOptions {
|
|
|
26
23
|
export declare class ClaudeAgent implements BbAgent {
|
|
27
24
|
private readonly home;
|
|
28
25
|
readonly id = "claude";
|
|
26
|
+
readonly installCommand = "npm install -g @anthropic-ai/claude-code@latest";
|
|
27
|
+
readonly modelApi: import("@bakers-build/conductor/contract").AgentModelApi;
|
|
29
28
|
private readonly args;
|
|
30
29
|
private readonly model;
|
|
31
30
|
private readonly effort;
|
|
@@ -46,13 +45,14 @@ export declare class ClaudeAgent implements BbAgent {
|
|
|
46
45
|
constructor(options?: ClaudeAgentOptions, home?: string);
|
|
47
46
|
/** Point this agent at the agent home of the project's declared marketplaces. */
|
|
48
47
|
useMarketplaces(marketplaces: readonly MarketplaceDeclaration[]): void;
|
|
48
|
+
prepareRun(context: AgentRunContext): import("@bakers-build/conductor/contract").AgentRunPreparation;
|
|
49
49
|
installPlugins(marketplaces: readonly MarketplaceDeclaration[], home: string): Promise<PluginLaunch>;
|
|
50
50
|
get launchWarnings(): readonly string[];
|
|
51
51
|
/** A measured run stays without the conductor's tools, MCP or bridge. */
|
|
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,
|
|
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,8 +7,13 @@ 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';
|
|
12
|
+
import { encodeClaudeProjectDir, prepareClaudeRun } from './run.js';
|
|
13
|
+
import { claudeInstallCommand, claudeModelApi } from './setup.js';
|
|
11
14
|
export { parseClaudeTranscript } from './footprint.js';
|
|
15
|
+
export { encodeClaudeProjectDir } from './run.js';
|
|
16
|
+
export { claudeInstallCommand, claudeModelApi } from './setup.js';
|
|
12
17
|
/** src/index.ts and dist/src/index.js both sit two levels below the package root. */
|
|
13
18
|
const MEASURE_WRAPPER = fileURLToPath(new URL(import.meta.url.includes('/dist/')
|
|
14
19
|
? '../../measure/claude-measure.mjs'
|
|
@@ -32,7 +37,7 @@ const SANDBOX_DEFAULTS = {
|
|
|
32
37
|
mcp_servers: {},
|
|
33
38
|
};
|
|
34
39
|
/** The launch flags a security mode owns (`docs/addons/claude.md`). */
|
|
35
|
-
function securityFlags({ mode, sandbox, config }, workspacePath, pluginsOn = false) {
|
|
40
|
+
function securityFlags({ mode, sandbox, config }, workspacePath, pluginsOn = false, isolatedGit = false) {
|
|
36
41
|
if (mode === 'system')
|
|
37
42
|
return [];
|
|
38
43
|
if (mode === 'yolo')
|
|
@@ -42,7 +47,7 @@ function securityFlags({ mode, sandbox, config }, workspacePath, pluginsOn = fal
|
|
|
42
47
|
// Git metadata only for a known workspace; the conductor always passes one.
|
|
43
48
|
const git = workspacePath === undefined
|
|
44
49
|
? { write: [], protect: [] }
|
|
45
|
-
: gitSandboxPaths(workspacePath);
|
|
50
|
+
: gitSandboxPaths(workspacePath, isolatedGit);
|
|
46
51
|
const settings = {
|
|
47
52
|
sandbox: {
|
|
48
53
|
enabled: true,
|
|
@@ -90,13 +95,6 @@ function securityFlags({ mode, sandbox, config }, workspacePath, pluginsOn = fal
|
|
|
90
95
|
JSON.stringify(settings),
|
|
91
96
|
];
|
|
92
97
|
}
|
|
93
|
-
/**
|
|
94
|
-
* Encode an absolute cwd the way Claude Code names its per-project transcript
|
|
95
|
-
* directory under `~/.claude/projects/`: every non-alphanumeric char → `-`.
|
|
96
|
-
*/
|
|
97
|
-
export function encodeClaudeProjectDir(cwd) {
|
|
98
|
-
return cwd.replace(/[^a-zA-Z0-9]/g, '-');
|
|
99
|
-
}
|
|
100
98
|
const run = promisify(execFile);
|
|
101
99
|
/** Run `claude <args> --json` in `configDir`; a failure names `what` and the CLI's output. */
|
|
102
100
|
async function claudeJson(configDir, what, args) {
|
|
@@ -128,6 +126,8 @@ const CLAUDE_KNOWN = [
|
|
|
128
126
|
export class ClaudeAgent {
|
|
129
127
|
home;
|
|
130
128
|
id = 'claude';
|
|
129
|
+
installCommand = claudeInstallCommand;
|
|
130
|
+
modelApi = claudeModelApi;
|
|
131
131
|
args;
|
|
132
132
|
model;
|
|
133
133
|
effort;
|
|
@@ -177,12 +177,14 @@ export class ClaudeAgent {
|
|
|
177
177
|
this.pluginsOn = true;
|
|
178
178
|
this.configDir = homePath(this.id, homeKey([...marketplaces]));
|
|
179
179
|
}
|
|
180
|
+
prepareRun(context) {
|
|
181
|
+
return prepareClaudeRun(context, this.configDir);
|
|
182
|
+
}
|
|
180
183
|
async installPlugins(marketplaces, home) {
|
|
184
|
+
const credentials = join(this.home, '.claude', '.credentials.json');
|
|
181
185
|
const outcome = await ensureHome(home, async (dir) => {
|
|
182
|
-
const credentials = join(this.home, '.claude', '.credentials.json');
|
|
183
186
|
if (!existsSync(credentials))
|
|
184
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`);
|
|
185
|
-
symlinkSync(credentials, join(dir, '.credentials.json'));
|
|
186
188
|
for (const { url, ref, plugins } of marketplaces) {
|
|
187
189
|
const added = await claudeJson(dir, url, [
|
|
188
190
|
'plugin',
|
|
@@ -204,6 +206,8 @@ export class ClaudeAgent {
|
|
|
204
206
|
: {};
|
|
205
207
|
writeFileSync(state, `${JSON.stringify({ ...seeded, hasCompletedOnboarding: true }, null, 2)}\n`, { mode: 0o600 });
|
|
206
208
|
});
|
|
209
|
+
// Every use: a token refresh inside the home replaced the link with a copy.
|
|
210
|
+
shareLogin(credentials, join(home, '.credentials.json'));
|
|
207
211
|
return { env: { CLAUDE_CONFIG_DIR: home }, args: [], home: outcome };
|
|
208
212
|
}
|
|
209
213
|
get launchWarnings() {
|
|
@@ -217,7 +221,7 @@ export class ClaudeAgent {
|
|
|
217
221
|
get withoutConductorTools() {
|
|
218
222
|
return this.measure;
|
|
219
223
|
}
|
|
220
|
-
launchCommand(prompt, run, workspacePath, tools, _env, pluginArgs = []) {
|
|
224
|
+
launchCommand(prompt, run, workspacePath, tools, _env, pluginArgs = [], isolatedGit = false) {
|
|
221
225
|
if (prompt === '') {
|
|
222
226
|
return 'claude';
|
|
223
227
|
}
|
|
@@ -246,7 +250,7 @@ export class ClaudeAgent {
|
|
|
246
250
|
}
|
|
247
251
|
// The flags are constants; only their generated values need quoting.
|
|
248
252
|
parts.push(...[
|
|
249
|
-
...securityFlags(this.security, workspacePath, this.pluginsOn),
|
|
253
|
+
...securityFlags(this.security, workspacePath, this.pluginsOn, isolatedGit),
|
|
250
254
|
...this.mcpFlags(tools),
|
|
251
255
|
].map((t) => (t.startsWith('--') ? t : shellQuote(t))));
|
|
252
256
|
// Pin the transcript's own session id to the run's UUID (BB-473), so
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AgentRunContext, AgentRunPreparation } from '@bakers-build/conductor/contract';
|
|
2
|
+
export declare function encodeClaudeProjectDir(cwd: string): string;
|
|
3
|
+
/** Prepare Claude's files in the home supplied by any execution backend. */
|
|
4
|
+
export declare function prepareClaudeRun(context: AgentRunContext, configDir: string, hostEnv?: Readonly<Record<string, string | undefined>>): AgentRunPreparation;
|
package/dist/src/run.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, symlinkSync, writeFileSync, } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
export function encodeClaudeProjectDir(cwd) {
|
|
4
|
+
return cwd.replace(/[^a-zA-Z0-9]/g, '-');
|
|
5
|
+
}
|
|
6
|
+
/** Prepare Claude's files in the home supplied by any execution backend. */
|
|
7
|
+
export function prepareClaudeRun(context, configDir, hostEnv = process.env) {
|
|
8
|
+
const source = context.env.CLAUDE_CONFIG_DIR ?? configDir;
|
|
9
|
+
const config = join(context.homePath, '.claude');
|
|
10
|
+
mkdirSync(config, { recursive: true });
|
|
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 }));
|
|
17
|
+
const state = existsSync(join(source, '.claude.json'))
|
|
18
|
+
? JSON.parse(readFileSync(join(source, '.claude.json'), 'utf8'))
|
|
19
|
+
: {};
|
|
20
|
+
delete state.primaryApiKey;
|
|
21
|
+
const keys = ['CLAUDE_CODE_OAUTH_TOKEN', 'ANTHROPIC_API_KEY'];
|
|
22
|
+
const env = { CLAUDE_CONFIG_DIR: config };
|
|
23
|
+
const supplied = keys.some((key) => context.env[key]);
|
|
24
|
+
const bindPaths = [];
|
|
25
|
+
if (!supplied) {
|
|
26
|
+
const key = keys.find((name) => hostEnv[name]);
|
|
27
|
+
if (key)
|
|
28
|
+
env[key] = hostEnv[key];
|
|
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.
|
|
32
|
+
const login = join(config, '.credentials.json');
|
|
33
|
+
writeFileSync(login, '', { mode: 0o600 });
|
|
34
|
+
bindPaths.push({
|
|
35
|
+
source: realpathSync(join(source, '.credentials.json')),
|
|
36
|
+
target: login,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const apiKey = context.env.ANTHROPIC_API_KEY ?? env.ANTHROPIC_API_KEY;
|
|
41
|
+
writeFileSync(join(config, '.claude.json'), JSON.stringify({
|
|
42
|
+
...state,
|
|
43
|
+
hasCompletedOnboarding: true,
|
|
44
|
+
...(apiKey
|
|
45
|
+
? {
|
|
46
|
+
customApiKeyResponses: {
|
|
47
|
+
approved: [apiKey.slice(-20)],
|
|
48
|
+
rejected: [],
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
: {}),
|
|
52
|
+
}), { mode: 0o600 });
|
|
53
|
+
const readPaths = [];
|
|
54
|
+
const plugins = join(source, 'plugins');
|
|
55
|
+
if (existsSync(plugins)) {
|
|
56
|
+
symlinkSync(plugins, join(config, 'plugins'));
|
|
57
|
+
readPaths.push(plugins);
|
|
58
|
+
}
|
|
59
|
+
const key = encodeClaudeProjectDir(context.workspacePath);
|
|
60
|
+
const transcripts = join(source, 'projects', key);
|
|
61
|
+
mkdirSync(transcripts, { recursive: true });
|
|
62
|
+
mkdirSync(join(config, 'projects'), { recursive: true });
|
|
63
|
+
symlinkSync(transcripts, join(config, 'projects', key));
|
|
64
|
+
return {
|
|
65
|
+
env,
|
|
66
|
+
readPaths,
|
|
67
|
+
writePaths: [transcripts],
|
|
68
|
+
...(bindPaths.length ? { bindPaths } : {}),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const claudeInstallCommand = 'npm install -g @anthropic-ai/claude-code@latest';
|
|
2
|
+
export const claudeModelApi = {
|
|
3
|
+
target: 'https://api.anthropic.com',
|
|
4
|
+
baseUrlEnv: 'ANTHROPIC_BASE_URL',
|
|
5
|
+
keyEnv: 'ANTHROPIC_API_KEY',
|
|
6
|
+
auth: {
|
|
7
|
+
CLAUDE_CODE_OAUTH_TOKEN: {
|
|
8
|
+
set: { authorization: 'Bearer {value}' },
|
|
9
|
+
append: { 'anthropic-beta': 'oauth-2025-04-20' },
|
|
10
|
+
},
|
|
11
|
+
ANTHROPIC_API_KEY: { set: { 'x-api-key': '{value}' } },
|
|
12
|
+
},
|
|
13
|
+
credentialHint: 'set CLAUDE_CODE_OAUTH_TOKEN (from `claude setup-token`) or ANTHROPIC_API_KEY in the conductor environment',
|
|
14
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/addon-claude",
|
|
3
|
-
"version": "0.9.1-next.
|
|
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.
|
|
30
|
-
"@bakers-build/core": "^0.9.1-next.
|
|
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": "
|
|
33
|
+
"commit": "e7d9921d51d5c045f29ca7e35d1e6a348e6ddf08",
|
|
34
34
|
"channel": "next"
|
|
35
35
|
}
|
|
36
36
|
}
|