@bakers-build/addon-claude 0.9.1-next.4 → 0.9.1-next.5
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.d.ts +6 -6
- package/dist/src/index.js +9 -7
- package/dist/src/run.d.ts +4 -0
- package/dist/src/run.js +55 -0
- package/dist/src/setup.d.ts +3 -0
- package/dist/src/setup.js +14 -0
- package/package.json +4 -4
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,6 +45,7 @@ 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. */
|
package/dist/src/index.js
CHANGED
|
@@ -8,7 +8,11 @@ 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
10
|
import { parseClaudeTranscript } from './footprint.js';
|
|
11
|
+
import { encodeClaudeProjectDir, prepareClaudeRun } from './run.js';
|
|
12
|
+
import { claudeInstallCommand, claudeModelApi } from './setup.js';
|
|
11
13
|
export { parseClaudeTranscript } from './footprint.js';
|
|
14
|
+
export { encodeClaudeProjectDir } from './run.js';
|
|
15
|
+
export { claudeInstallCommand, claudeModelApi } from './setup.js';
|
|
12
16
|
/** src/index.ts and dist/src/index.js both sit two levels below the package root. */
|
|
13
17
|
const MEASURE_WRAPPER = fileURLToPath(new URL(import.meta.url.includes('/dist/')
|
|
14
18
|
? '../../measure/claude-measure.mjs'
|
|
@@ -90,13 +94,6 @@ function securityFlags({ mode, sandbox, config }, workspacePath, pluginsOn = fal
|
|
|
90
94
|
JSON.stringify(settings),
|
|
91
95
|
];
|
|
92
96
|
}
|
|
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
97
|
const run = promisify(execFile);
|
|
101
98
|
/** Run `claude <args> --json` in `configDir`; a failure names `what` and the CLI's output. */
|
|
102
99
|
async function claudeJson(configDir, what, args) {
|
|
@@ -128,6 +125,8 @@ const CLAUDE_KNOWN = [
|
|
|
128
125
|
export class ClaudeAgent {
|
|
129
126
|
home;
|
|
130
127
|
id = 'claude';
|
|
128
|
+
installCommand = claudeInstallCommand;
|
|
129
|
+
modelApi = claudeModelApi;
|
|
131
130
|
args;
|
|
132
131
|
model;
|
|
133
132
|
effort;
|
|
@@ -177,6 +176,9 @@ export class ClaudeAgent {
|
|
|
177
176
|
this.pluginsOn = true;
|
|
178
177
|
this.configDir = homePath(this.id, homeKey([...marketplaces]));
|
|
179
178
|
}
|
|
179
|
+
prepareRun(context) {
|
|
180
|
+
return prepareClaudeRun(context, this.configDir);
|
|
181
|
+
}
|
|
180
182
|
async installPlugins(marketplaces, home) {
|
|
181
183
|
const outcome = await ensureHome(home, async (dir) => {
|
|
182
184
|
const credentials = join(this.home, '.claude', '.credentials.json');
|
|
@@ -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,55 @@
|
|
|
1
|
+
import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, 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
|
+
if (existsSync(join(source, 'settings.json')))
|
|
12
|
+
copyFileSync(join(source, 'settings.json'), join(config, 'settings.json'));
|
|
13
|
+
const state = existsSync(join(source, '.claude.json'))
|
|
14
|
+
? JSON.parse(readFileSync(join(source, '.claude.json'), 'utf8'))
|
|
15
|
+
: {};
|
|
16
|
+
delete state.primaryApiKey;
|
|
17
|
+
const keys = ['CLAUDE_CODE_OAUTH_TOKEN', 'ANTHROPIC_API_KEY'];
|
|
18
|
+
const env = { CLAUDE_CONFIG_DIR: config };
|
|
19
|
+
const supplied = keys.some((key) => context.env[key]);
|
|
20
|
+
if (!supplied) {
|
|
21
|
+
const key = keys.find((name) => hostEnv[name]);
|
|
22
|
+
if (key)
|
|
23
|
+
env[key] = hostEnv[key];
|
|
24
|
+
else if (existsSync(join(source, '.credentials.json'))) {
|
|
25
|
+
const login = join(config, '.credentials.json');
|
|
26
|
+
copyFileSync(join(source, '.credentials.json'), login);
|
|
27
|
+
chmodSync(login, 0o600);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const apiKey = context.env.ANTHROPIC_API_KEY ?? env.ANTHROPIC_API_KEY;
|
|
31
|
+
writeFileSync(join(config, '.claude.json'), JSON.stringify({
|
|
32
|
+
...state,
|
|
33
|
+
hasCompletedOnboarding: true,
|
|
34
|
+
...(apiKey
|
|
35
|
+
? {
|
|
36
|
+
customApiKeyResponses: {
|
|
37
|
+
approved: [apiKey.slice(-20)],
|
|
38
|
+
rejected: [],
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
: {}),
|
|
42
|
+
}), { mode: 0o600 });
|
|
43
|
+
const readPaths = [];
|
|
44
|
+
const plugins = join(source, 'plugins');
|
|
45
|
+
if (existsSync(plugins)) {
|
|
46
|
+
symlinkSync(plugins, join(config, 'plugins'));
|
|
47
|
+
readPaths.push(plugins);
|
|
48
|
+
}
|
|
49
|
+
const key = encodeClaudeProjectDir(context.workspacePath);
|
|
50
|
+
const transcripts = join(source, 'projects', key);
|
|
51
|
+
mkdirSync(transcripts, { recursive: true });
|
|
52
|
+
mkdirSync(join(config, 'projects'), { recursive: true });
|
|
53
|
+
symlinkSync(transcripts, join(config, 'projects', key));
|
|
54
|
+
return { env, readPaths, writePaths: [transcripts] };
|
|
55
|
+
}
|
|
@@ -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.5",
|
|
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.5",
|
|
30
|
+
"@bakers-build/core": "^0.9.1-next.5"
|
|
31
31
|
},
|
|
32
32
|
"bakersBuild": {
|
|
33
|
-
"commit": "
|
|
33
|
+
"commit": "d9242cad6cabee1faf010b5d46ac1bac33f6e0a1",
|
|
34
34
|
"channel": "next"
|
|
35
35
|
}
|
|
36
36
|
}
|