@bakers-build/addon-claude 0.3.0 → 0.4.0
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 +4 -4
- package/dist/src/index.js +76 -16
- package/measure/claude-measure.mjs +26 -5
- package/package.json +3 -3
package/dist/src/index.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { type AgentFootprint, type AgentPlugin, type AgentRunIdentity, type BbAgent } from '@bakers-build/conductor/contract';
|
|
1
|
+
import { type AgentFootprint, type AgentPlugin, type AgentRunIdentity, type BbAgent, type RunEnvPolicy, type SecurityOptions } from '@bakers-build/conductor/contract';
|
|
2
2
|
export { parseClaudeTranscript } from './footprint.js';
|
|
3
3
|
/**
|
|
4
4
|
* Encode an absolute cwd the way Claude Code names its per-project transcript
|
|
5
5
|
* directory under `~/.claude/projects/`: every non-alphanumeric char → `-`.
|
|
6
6
|
*/
|
|
7
7
|
export declare function encodeClaudeProjectDir(cwd: string): string;
|
|
8
|
-
export interface ClaudeAgentOptions {
|
|
8
|
+
export interface ClaudeAgentOptions extends SecurityOptions {
|
|
9
9
|
model?: string;
|
|
10
10
|
effort?: string;
|
|
11
11
|
args?: string[];
|
|
12
|
-
skip_permissions?: boolean;
|
|
13
12
|
/**
|
|
14
13
|
* When true, the launch runs through `measure/claude-measure.mjs`, which
|
|
15
14
|
* starts the logging proxy for the lifetime of this Claude process and
|
|
@@ -23,7 +22,8 @@ export declare class ClaudeAgent implements BbAgent {
|
|
|
23
22
|
private readonly args;
|
|
24
23
|
private readonly model;
|
|
25
24
|
private readonly effort;
|
|
26
|
-
private readonly
|
|
25
|
+
private readonly securityFlags;
|
|
26
|
+
readonly runEnvPolicy: RunEnvPolicy;
|
|
27
27
|
private readonly measure;
|
|
28
28
|
private readonly overrides;
|
|
29
29
|
constructor(options?: ClaudeAgentOptions, home?: string);
|
package/dist/src/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { readdir, readFile, stat } from 'node:fs/promises';
|
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { resolveAgentCliOptions, validateOptionalBoolean, } from '@bakers-build/conductor/contract';
|
|
5
|
+
import { resolveAgentCliOptions, resolveSecurityOptions, validateOptionalBoolean, } from '@bakers-build/conductor/contract';
|
|
6
6
|
import { shellQuote } from '@bakers-build/core';
|
|
7
7
|
import { parseClaudeTranscript } from './footprint.js';
|
|
8
8
|
export { parseClaudeTranscript } from './footprint.js';
|
|
@@ -10,15 +10,66 @@ 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
|
+
/** Flag → value pairs; a flag the security mode already passes is skipped. */
|
|
13
14
|
const MEASURE_FLAGS = [
|
|
14
|
-
'--setting-sources',
|
|
15
|
-
'
|
|
16
|
-
'--
|
|
17
|
-
'
|
|
18
|
-
'--strict-mcp-config',
|
|
19
|
-
'--mcp-config',
|
|
20
|
-
'{"mcpServers":{}}',
|
|
15
|
+
['--setting-sources', 'project,local'],
|
|
16
|
+
['--settings', '.bakers/claude-measure.settings.json'],
|
|
17
|
+
['--strict-mcp-config'],
|
|
18
|
+
['--mcp-config', '{"mcpServers":{}}'],
|
|
21
19
|
];
|
|
20
|
+
const SANDBOX_DEFAULTS = {
|
|
21
|
+
trusted_commands: ['bakers', 'git', 'ddev'],
|
|
22
|
+
deny_read: ['~/.ssh', '~/.bakers'],
|
|
23
|
+
allow_write: [],
|
|
24
|
+
network: ['*'],
|
|
25
|
+
mcp_servers: {},
|
|
26
|
+
};
|
|
27
|
+
/** The launch flags a security mode owns (`docs/addons/claude.md`). */
|
|
28
|
+
function securityFlags({ mode, sandbox, config }) {
|
|
29
|
+
if (mode === 'system')
|
|
30
|
+
return [];
|
|
31
|
+
if (mode === 'yolo')
|
|
32
|
+
return ['--dangerously-skip-permissions'];
|
|
33
|
+
if (mode === 'custom')
|
|
34
|
+
return ['--settings', JSON.stringify(config)];
|
|
35
|
+
const settings = {
|
|
36
|
+
sandbox: {
|
|
37
|
+
enabled: true,
|
|
38
|
+
failIfUnavailable: true,
|
|
39
|
+
allowUnsandboxedCommands: false,
|
|
40
|
+
excludedCommands: sandbox.trusted_commands,
|
|
41
|
+
filesystem: {
|
|
42
|
+
denyRead: sandbox.deny_read,
|
|
43
|
+
allowWrite: sandbox.allow_write,
|
|
44
|
+
},
|
|
45
|
+
network: { allowedDomains: sandbox.network },
|
|
46
|
+
},
|
|
47
|
+
disableClaudeAiConnectors: true,
|
|
48
|
+
// dontAsk denies whatever is not allowed here; every Bash command is
|
|
49
|
+
// either sandboxed or a trusted command, and the Read deny covers the
|
|
50
|
+
// Read tool, which the OS sandbox does not confine.
|
|
51
|
+
permissions: {
|
|
52
|
+
allow: ['Bash', 'Edit(./**)'],
|
|
53
|
+
// Claude reads a single leading `/` as relative to the settings file;
|
|
54
|
+
// the plain rule covers a file entry, `/**` a directory's contents.
|
|
55
|
+
deny: sandbox.deny_read.flatMap((path) => {
|
|
56
|
+
const rule = path.startsWith('/') ? `/${path}` : path;
|
|
57
|
+
return [`Read(${rule})`, `Read(${rule}/**)`];
|
|
58
|
+
}),
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
return [
|
|
62
|
+
'--permission-mode',
|
|
63
|
+
'dontAsk',
|
|
64
|
+
'--setting-sources',
|
|
65
|
+
'project,local',
|
|
66
|
+
'--settings',
|
|
67
|
+
JSON.stringify(settings),
|
|
68
|
+
'--strict-mcp-config',
|
|
69
|
+
'--mcp-config',
|
|
70
|
+
JSON.stringify({ mcpServers: sandbox.mcp_servers }),
|
|
71
|
+
];
|
|
72
|
+
}
|
|
22
73
|
/**
|
|
23
74
|
* Encode an absolute cwd the way Claude Code names its per-project transcript
|
|
24
75
|
* directory under `~/.claude/projects/`: every non-alphanumeric char → `-`.
|
|
@@ -31,6 +82,10 @@ const CLAUDE_RESERVED = [
|
|
|
31
82
|
'--dangerously-skip-permissions',
|
|
32
83
|
'--allow-dangerously-skip-permissions',
|
|
33
84
|
'--permission-mode',
|
|
85
|
+
'--settings',
|
|
86
|
+
'--setting-sources',
|
|
87
|
+
'--strict-mcp-config',
|
|
88
|
+
'--mcp-config',
|
|
34
89
|
];
|
|
35
90
|
const CLAUDE_KNOWN = [
|
|
36
91
|
{ kind: 'model', flags: ['--model'] },
|
|
@@ -42,7 +97,8 @@ export class ClaudeAgent {
|
|
|
42
97
|
args;
|
|
43
98
|
model;
|
|
44
99
|
effort;
|
|
45
|
-
|
|
100
|
+
securityFlags;
|
|
101
|
+
runEnvPolicy;
|
|
46
102
|
measure;
|
|
47
103
|
overrides;
|
|
48
104
|
constructor(options = {}, home = homedir()) {
|
|
@@ -52,9 +108,9 @@ export class ClaudeAgent {
|
|
|
52
108
|
this.model = cli.model;
|
|
53
109
|
this.effort = cli.effort;
|
|
54
110
|
this.overrides = cli.overrides;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
111
|
+
const security = resolveSecurityOptions(options, SANDBOX_DEFAULTS);
|
|
112
|
+
this.securityFlags = securityFlags(security);
|
|
113
|
+
this.runEnvPolicy = security.runEnvPolicy;
|
|
58
114
|
this.measure = validateOptionalBoolean(options.measure, 'measure') ?? false;
|
|
59
115
|
}
|
|
60
116
|
launchCommand(prompt, run) {
|
|
@@ -70,9 +126,8 @@ export class ClaudeAgent {
|
|
|
70
126
|
if (this.effort !== undefined && !this.overrides.effort) {
|
|
71
127
|
parts.push('--effort', shellQuote(this.effort));
|
|
72
128
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
129
|
+
// The flags are constants; only their generated values need quoting.
|
|
130
|
+
parts.push(...this.securityFlags.map((t) => t.startsWith('--') ? t : shellQuote(t)));
|
|
76
131
|
// Pin the transcript's own session id to the run's UUID (BB-473), so
|
|
77
132
|
// `getRunLog` can read that ONE file directly instead of scanning the
|
|
78
133
|
// worktree-keyed directory by mtime — the scan is what let a
|
|
@@ -82,7 +137,12 @@ export class ClaudeAgent {
|
|
|
82
137
|
}
|
|
83
138
|
parts.push(...this.args.map(shellQuote));
|
|
84
139
|
if (this.measure) {
|
|
85
|
-
|
|
140
|
+
// The wrapper folds an inline --settings JSON into its profile file.
|
|
141
|
+
for (const pair of MEASURE_FLAGS) {
|
|
142
|
+
if (!this.securityFlags.includes(pair[0])) {
|
|
143
|
+
parts.push(...pair.map(shellQuote));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
86
146
|
}
|
|
87
147
|
return parts.join(' ');
|
|
88
148
|
}
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* node claude-measure.mjs claude <claude args…>
|
|
5
5
|
*
|
|
6
|
-
* Writes the state group's settings, with
|
|
7
|
-
* on top, to `.bakers/claude-measure.settings.json`
|
|
6
|
+
* Writes the state group's settings, with an inline `--settings` JSON and the
|
|
7
|
+
* project's own `enabledPlugins` on top, to `.bakers/claude-measure.settings.json`
|
|
8
|
+
* — or, where git does not
|
|
8
9
|
* ignore that path, to a temporary file whose path replaces the `--settings`
|
|
9
10
|
* argument, so a foreign repository gains no untracked file. It then
|
|
10
11
|
* starts agent-proxy on an ephemeral loopback port, runs the command with
|
|
@@ -64,17 +65,37 @@ function projectPlugins() {
|
|
|
64
65
|
// `--settings` outranks project settings, so fold the project's enabledPlugins
|
|
65
66
|
// into the copy: the profile is a default, the project has the last word.
|
|
66
67
|
const group = GROUPS[process.env.BB_STATE] ?? 'ops';
|
|
67
|
-
|
|
68
|
+
let profile = JSON.parse(
|
|
68
69
|
fs.readFileSync(path.join(HERE, `keytec-${group}.json`), 'utf8'),
|
|
69
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
|
+
};
|
|
92
|
+
}
|
|
70
93
|
profile.enabledPlugins = { ...profile.enabledPlugins, ...projectPlugins() };
|
|
71
94
|
const ignored =
|
|
72
95
|
spawnSync('git', ['check-ignore', '-q', SETTINGS_REL]).status === 0;
|
|
73
96
|
const settingsFile = ignored
|
|
74
97
|
? SETTINGS_REL
|
|
75
98
|
: path.join(os.tmpdir(), `claude-measure-${randomUUID()}.settings.json`);
|
|
76
|
-
// The last one: an alias's own `--settings` precedes the measure flags.
|
|
77
|
-
const settingsAt = args.lastIndexOf('--settings');
|
|
78
99
|
if (settingsAt !== -1) args[settingsAt + 1] = settingsFile;
|
|
79
100
|
fs.mkdirSync(path.dirname(settingsFile), { recursive: true });
|
|
80
101
|
fs.writeFileSync(settingsFile, `${JSON.stringify(profile, null, 2)}\n`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/addon-claude",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "bakers.build agent plugin for the Claude CLI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"directory": "bakers-cli/addons/claude"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@bakers-build/conductor": "^0.
|
|
27
|
-
"@bakers-build/core": "^0.
|
|
26
|
+
"@bakers-build/conductor": "^0.4.0",
|
|
27
|
+
"@bakers-build/core": "^0.4.0"
|
|
28
28
|
}
|
|
29
29
|
}
|