@bakers-build/conductor 0.6.1-next.5 → 0.6.1-next.7
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/cli/config-templates.js +7 -5
- package/dist/src/cli/config-validation.js +1 -0
- package/dist/src/commands/conductor.d.ts +4 -6
- package/dist/src/commands/conductor.js +47 -35
- package/dist/src/commands/oven-tools.js +1 -1
- package/dist/src/config.d.ts +3 -1
- package/dist/src/config.js +63 -46
- package/dist/src/contract.d.ts +3 -4
- package/dist/src/contract.js +1 -1
- package/dist/src/core/conductor.d.ts +12 -7
- package/dist/src/core/conductor.js +144 -119
- package/dist/src/core/hook-runner.d.ts +23 -0
- package/dist/src/core/hook-runner.js +22 -0
- package/dist/src/core/site-tools.d.ts +21 -0
- package/dist/src/core/site-tools.js +142 -0
- package/dist/src/core/tool-server.d.ts +10 -2
- package/dist/src/core/tool-server.js +95 -13
- package/dist/src/core/ui-signal.d.ts +2 -0
- package/dist/src/core/ui-signal.js +41 -0
- package/dist/src/plugins/agent-args.d.ts +54 -5
- package/dist/src/plugins/agent-args.js +99 -11
- package/dist/src/plugins/agent.d.ts +1 -1
- package/dist/src/plugins/agent.js +1 -1
- package/dist/src/plugins/executor.d.ts +28 -47
- package/dist/src/plugins/plugins.d.ts +3 -0
- package/dist/src/plugins/preset.d.ts +1 -5
- package/dist/src/plugins/remote.d.ts +25 -0
- package/dist/src/plugins/workspace.d.ts +21 -32
- package/dist/src/process/detached-spawn.d.ts +20 -0
- package/dist/src/process/detached-spawn.js +34 -0
- package/dist/src/types.d.ts +6 -15
- package/package.json +4 -4
- package/dist/src/plugins/process-host.d.ts +0 -7
- package/dist/src/plugins/process-host.js +0 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// The site's bakers tools, proxied on the `bakers` MCP server with the
|
|
2
|
+
// conductor's own credentials. Only the allowlist is served, under the plain
|
|
3
|
+
// name, and every call is held to the run ticket's project before it leaves.
|
|
4
|
+
/** The site tools a run may call. */
|
|
5
|
+
export const SITE_TOOLS = [
|
|
6
|
+
'bakers_ticket_read',
|
|
7
|
+
'bakers_ticket_search',
|
|
8
|
+
'bakers_ticket_create',
|
|
9
|
+
'bakers_ticket_update',
|
|
10
|
+
'bakers_ticket_classify',
|
|
11
|
+
'bakers_ticket_transition',
|
|
12
|
+
'bakers_comment_publish',
|
|
13
|
+
'bakers_metric_write',
|
|
14
|
+
'bakers_ticket_list',
|
|
15
|
+
'bakers_ticket_runs_list',
|
|
16
|
+
'bakers_label_list',
|
|
17
|
+
'bakers_project_read',
|
|
18
|
+
'bakers_user_read',
|
|
19
|
+
];
|
|
20
|
+
/** The site tools that change a ticket; a successful call signals `bakers ui`. */
|
|
21
|
+
export const SITE_WRITE_TOOLS = [
|
|
22
|
+
'bakers_ticket_create',
|
|
23
|
+
'bakers_ticket_update',
|
|
24
|
+
'bakers_ticket_classify',
|
|
25
|
+
'bakers_ticket_transition',
|
|
26
|
+
'bakers_comment_publish',
|
|
27
|
+
];
|
|
28
|
+
const WIRE = 'tool_api__';
|
|
29
|
+
export function siteToolProxy(client, logger) {
|
|
30
|
+
return {
|
|
31
|
+
async list() {
|
|
32
|
+
try {
|
|
33
|
+
return (await client.list()).flatMap((t) => {
|
|
34
|
+
const name = t.name.slice(WIRE.length);
|
|
35
|
+
if (!t.name.startsWith(WIRE) || !SITE_TOOLS.includes(name))
|
|
36
|
+
return [];
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
name,
|
|
40
|
+
...(t.description === undefined
|
|
41
|
+
? {}
|
|
42
|
+
: { description: t.description }),
|
|
43
|
+
inputSchema: t.inputSchema,
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
// The client forgets a failed listing, so the next tools/list retries.
|
|
50
|
+
logger?.warn({ err }, 'site tools unreachable; serving addon tools only');
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
async call(name, args, binding) {
|
|
55
|
+
const ticket = binding.ticket;
|
|
56
|
+
const project = ticket?.projectId;
|
|
57
|
+
if (!ticket || !project)
|
|
58
|
+
throw new Error(`${name}: this run's ticket has no project, so it may call no site tool`);
|
|
59
|
+
const owners = ownersOf(binding, project);
|
|
60
|
+
const ownerOf = async (kind, ref) => {
|
|
61
|
+
const key = `${kind}:${ref}`;
|
|
62
|
+
let owner = owners.get(key);
|
|
63
|
+
if (owner === undefined) {
|
|
64
|
+
const read = await client.call(`${WIRE}bakers_${kind}_read`, {
|
|
65
|
+
[kind]: ref,
|
|
66
|
+
});
|
|
67
|
+
const out = resultJson(read);
|
|
68
|
+
owner = String(kind === 'ticket' ? out.project : out.uuid);
|
|
69
|
+
owners.set(key, owner);
|
|
70
|
+
}
|
|
71
|
+
return owner;
|
|
72
|
+
};
|
|
73
|
+
// The site reads an empty project or workspace as no filter, so empty counts as missing.
|
|
74
|
+
const blank = (v) => v === undefined || v === null || v === '';
|
|
75
|
+
const scoped = { ...args };
|
|
76
|
+
if (FILLS_PROJECT.includes(name) && blank(scoped.project))
|
|
77
|
+
scoped.project = project;
|
|
78
|
+
if (name === 'bakers_label_list' &&
|
|
79
|
+
ticket.workspaceId &&
|
|
80
|
+
blank(scoped.workspace))
|
|
81
|
+
scoped.workspace = ticket.workspaceId;
|
|
82
|
+
const refs = [
|
|
83
|
+
['ticket', 'ticket', scoped.ticket],
|
|
84
|
+
['ticket', 'parent', scoped.parent],
|
|
85
|
+
...[scoped.referenced_tickets_add ?? []]
|
|
86
|
+
.flat()
|
|
87
|
+
.map((r) => [
|
|
88
|
+
'ticket',
|
|
89
|
+
'referenced_tickets_add',
|
|
90
|
+
r,
|
|
91
|
+
]),
|
|
92
|
+
['project', 'project', scoped.project],
|
|
93
|
+
];
|
|
94
|
+
for (const [kind, arg, value] of refs) {
|
|
95
|
+
if (value === undefined || value === null)
|
|
96
|
+
continue;
|
|
97
|
+
if (value === '') {
|
|
98
|
+
// the site reads an empty ticket ref as none
|
|
99
|
+
if (kind === 'ticket')
|
|
100
|
+
continue;
|
|
101
|
+
throw new Error(`${name}: an empty ${arg} would mean every project; this run may only touch project ${project}`);
|
|
102
|
+
}
|
|
103
|
+
const owner = await ownerOf(kind, String(value));
|
|
104
|
+
if (owner !== project)
|
|
105
|
+
throw new Error(`${name}: ${arg} ${String(value)} belongs to project ${owner}, this run may only touch project ${project}`);
|
|
106
|
+
}
|
|
107
|
+
if (scoped.workspace !== undefined &&
|
|
108
|
+
scoped.workspace !== ticket.workspaceId)
|
|
109
|
+
throw new Error(`${name}: workspace ${String(scoped.workspace)} is not the workspace ${ticket.workspaceId ?? '(none)'} of project ${project}`);
|
|
110
|
+
const { content } = await client.call(`${WIRE}${name}`, scoped);
|
|
111
|
+
return { content };
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** Tools whose missing `project` means the run's project. */
|
|
116
|
+
const FILLS_PROJECT = [
|
|
117
|
+
'bakers_ticket_search',
|
|
118
|
+
'bakers_ticket_list',
|
|
119
|
+
'bakers_ticket_create',
|
|
120
|
+
];
|
|
121
|
+
/** Ticket and project refs already resolved, per run token; the run's own ticket is known. */
|
|
122
|
+
const resolved = new WeakMap();
|
|
123
|
+
function ownersOf(binding, project) {
|
|
124
|
+
let owners = resolved.get(binding);
|
|
125
|
+
if (!owners) {
|
|
126
|
+
owners = new Map([[`project:${project}`, project]]);
|
|
127
|
+
const { ticket } = binding;
|
|
128
|
+
if (ticket?.uuid)
|
|
129
|
+
owners.set(`ticket:${ticket.uuid}`, project);
|
|
130
|
+
if (ticket?.identifier)
|
|
131
|
+
owners.set(`ticket:${ticket.identifier}`, project);
|
|
132
|
+
resolved.set(binding, owners);
|
|
133
|
+
}
|
|
134
|
+
return owners;
|
|
135
|
+
}
|
|
136
|
+
/** A site tool's JSON result: structured content, else its first text part. */
|
|
137
|
+
function resultJson(result) {
|
|
138
|
+
if (result.structuredContent && typeof result.structuredContent === 'object')
|
|
139
|
+
return result.structuredContent;
|
|
140
|
+
const first = result.content[0];
|
|
141
|
+
return JSON.parse(first?.text ?? '{}');
|
|
142
|
+
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { ConductorLogger } from '@bakers-build/core';
|
|
2
|
+
import type { SiteToolClient } from '../plugins/remote.js';
|
|
2
3
|
import type { ToolBinding, ToolRegistry } from '../plugins/tools.js';
|
|
3
4
|
export interface ToolServer {
|
|
4
5
|
/** The MCP endpoint. */
|
|
5
6
|
url: string;
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
/** A fresh token for the run; replaces the run's earlier grant. */
|
|
8
|
+
issueRunToken(runUuid: string, binding: ToolBinding): string;
|
|
9
|
+
revokeRunToken(runUuid: string): void;
|
|
8
10
|
stop(): Promise<void>;
|
|
9
11
|
}
|
|
10
12
|
/** What the conductor publishes for the CLI in the endpoint file. */
|
|
@@ -21,5 +23,11 @@ export interface ToolServerOptions {
|
|
|
21
23
|
/** The operator may only name worktrees below this directory. */
|
|
22
24
|
workspaceRoot?: string;
|
|
23
25
|
logger?: ConductorLogger;
|
|
26
|
+
/** The site's tools, served to run tokens only; absent: none. */
|
|
27
|
+
siteTools?: SiteToolClient;
|
|
28
|
+
/** Called after a run's successful ticket write through a site tool. */
|
|
29
|
+
onSiteWrite?: (binding: ToolBinding) => void;
|
|
30
|
+
/** The runs still open; persisted grants of any other run are dropped. Absent: keep all. */
|
|
31
|
+
openRuns?: string[];
|
|
24
32
|
}
|
|
25
33
|
export declare function startToolServer(options: ToolServerOptions): Promise<ToolServer>;
|
|
@@ -1,17 +1,43 @@
|
|
|
1
|
-
// The conductor's local MCP server, `bakers
|
|
1
|
+
// The conductor's local MCP server, `bakers`: serves the addon
|
|
2
2
|
// tools to agent runs over Streamable HTTP on 127.0.0.1. A run token, issued
|
|
3
3
|
// at launch, binds every call to that run's worktree. The operator token
|
|
4
4
|
// (endpoint file, 0600) may name a worktree under the workspace root, for
|
|
5
5
|
// the CLI's plain JSON `POST /call`.
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
//
|
|
7
|
+
// With an endpoint file, the port and the run grants (token hash and binding,
|
|
8
|
+
// never the raw token) persist in `<id>.tools.json` beside it, so a running
|
|
9
|
+
// agent's baked-in URL and token survive a conductor restart.
|
|
10
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
11
|
+
import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync, } from 'node:fs';
|
|
8
12
|
import { createServer, } from 'node:http';
|
|
9
13
|
import { dirname, relative, resolve } from 'node:path';
|
|
10
14
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
11
15
|
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
12
16
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
13
17
|
import { CONDUCTOR_TOOLS_SERVER } from '../plugins/agent.js';
|
|
18
|
+
import { SITE_TOOLS, SITE_WRITE_TOOLS, siteToolProxy } from './site-tools.js';
|
|
14
19
|
const newToken = () => randomBytes(32).toString('hex');
|
|
20
|
+
const hashOf = (token) => createHash('sha256').update(token).digest('hex');
|
|
21
|
+
function readState(file, logger) {
|
|
22
|
+
if (!file)
|
|
23
|
+
return { runs: {} };
|
|
24
|
+
try {
|
|
25
|
+
const saved = JSON.parse(readFileSync(file, 'utf8'));
|
|
26
|
+
const runs = saved?.runs;
|
|
27
|
+
const port = saved?.port;
|
|
28
|
+
return {
|
|
29
|
+
runs: typeof runs === 'object' && runs
|
|
30
|
+
? runs
|
|
31
|
+
: {},
|
|
32
|
+
...(Number.isInteger(port) ? { port: port } : {}),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
if (err.code !== 'ENOENT')
|
|
37
|
+
logger?.warn({ err, file }, 'tool server state unreadable, starting empty');
|
|
38
|
+
return { runs: {} };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
15
41
|
function bearer(req) {
|
|
16
42
|
const m = /^Bearer (.+)$/.exec(req.headers.authorization ?? '');
|
|
17
43
|
return m?.[1];
|
|
@@ -32,12 +58,36 @@ function isInside(root, path) {
|
|
|
32
58
|
}
|
|
33
59
|
export async function startToolServer(options) {
|
|
34
60
|
const { registry, logger } = options;
|
|
35
|
-
const
|
|
61
|
+
const site = options.siteTools
|
|
62
|
+
? siteToolProxy(options.siteTools, logger)
|
|
63
|
+
: undefined;
|
|
64
|
+
if (site) {
|
|
65
|
+
const clash = registry.list().find((t) => SITE_TOOLS.includes(t.name));
|
|
66
|
+
if (clash)
|
|
67
|
+
throw new Error(`addon tool ${clash.name} has the name of a bakers site tool`);
|
|
68
|
+
}
|
|
69
|
+
const stateFile = options.endpointFile?.replace(/(\.json)?$/, '.tools.json');
|
|
70
|
+
const saved = readState(stateFile, logger);
|
|
71
|
+
const runs = new Map(Object.entries(saved.runs).filter(([run]) => !options.openRuns || options.openRuns.includes(run)));
|
|
36
72
|
const operatorToken = newToken();
|
|
73
|
+
let port = 0;
|
|
74
|
+
const persist = () => {
|
|
75
|
+
if (!stateFile)
|
|
76
|
+
return;
|
|
77
|
+
const state = { port, runs: Object.fromEntries(runs) };
|
|
78
|
+
writeFileSync(`${stateFile}.tmp`, JSON.stringify(state), { mode: 0o600 });
|
|
79
|
+
renameSync(`${stateFile}.tmp`, stateFile);
|
|
80
|
+
};
|
|
81
|
+
const bindingOf = (token) => {
|
|
82
|
+
if (!token)
|
|
83
|
+
return undefined;
|
|
84
|
+
const hash = hashOf(token);
|
|
85
|
+
return [...runs.values()].find((g) => g.hash === hash)?.binding;
|
|
86
|
+
};
|
|
37
87
|
const mcpServer = (binding) => {
|
|
38
88
|
const server = new Server({ name: CONDUCTOR_TOOLS_SERVER, version: '1.0.0' }, { capabilities: { tools: {} } });
|
|
39
89
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
40
|
-
tools: registry.list().map((t) => ({
|
|
90
|
+
tools: [...registry.list(), ...((await site?.list()) ?? [])].map((t) => ({
|
|
41
91
|
name: t.name,
|
|
42
92
|
description: t.description,
|
|
43
93
|
inputSchema: t.inputSchema,
|
|
@@ -45,6 +95,19 @@ export async function startToolServer(options) {
|
|
|
45
95
|
}));
|
|
46
96
|
server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
47
97
|
try {
|
|
98
|
+
if (site && SITE_TOOLS.includes(request.params.name)) {
|
|
99
|
+
const result = await site.call(request.params.name, request.params.arguments ?? {}, binding);
|
|
100
|
+
if (SITE_WRITE_TOOLS.includes(request.params.name)) {
|
|
101
|
+
// The write already succeeded: a failing hook must not make the agent retry it.
|
|
102
|
+
try {
|
|
103
|
+
options.onSiteWrite?.(binding);
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
logger?.warn({ err: String(err) }, 'site write hook failed');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
48
111
|
const result = await registry.call(request.params.name, request.params.arguments, binding, { signal: extra.signal, ...(logger ? { logger } : {}) });
|
|
49
112
|
return { content: [{ type: 'text', text: result.text }] };
|
|
50
113
|
}
|
|
@@ -85,7 +148,7 @@ export async function startToolServer(options) {
|
|
|
85
148
|
const handle = async () => {
|
|
86
149
|
if (req.method === 'POST' && req.url === '/call')
|
|
87
150
|
return operatorCall(req, res);
|
|
88
|
-
const binding =
|
|
151
|
+
const binding = bindingOf(bearer(req));
|
|
89
152
|
if (!binding)
|
|
90
153
|
return send(res, 401, {
|
|
91
154
|
error: 'unknown run token — conductor restarted?',
|
|
@@ -109,11 +172,28 @@ export async function startToolServer(options) {
|
|
|
109
172
|
send(res, 500, { error: 'internal error' });
|
|
110
173
|
});
|
|
111
174
|
});
|
|
112
|
-
|
|
113
|
-
|
|
175
|
+
const listen = (at) => new Promise((done, fail) => {
|
|
176
|
+
http.once('error', fail);
|
|
177
|
+
http.listen(at, '127.0.0.1', () => {
|
|
178
|
+
http.off('error', fail);
|
|
179
|
+
done();
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
try {
|
|
183
|
+
await listen(saved.port ?? 0);
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
if (err.code !== 'EADDRINUSE' || !saved.port)
|
|
187
|
+
throw err;
|
|
188
|
+
// shortcut: runs launched before the restart lose their tools until re-dispatched.
|
|
189
|
+
logger?.warn({ port: saved.port }, 'tool server port taken, falling back to a random port');
|
|
190
|
+
await listen(0);
|
|
191
|
+
}
|
|
192
|
+
port = http.address().port;
|
|
114
193
|
const url = `http://127.0.0.1:${port}`;
|
|
115
194
|
if (options.endpointFile) {
|
|
116
195
|
mkdirSync(dirname(options.endpointFile), { recursive: true, mode: 0o700 });
|
|
196
|
+
persist();
|
|
117
197
|
const endpoint = {
|
|
118
198
|
url,
|
|
119
199
|
operatorToken,
|
|
@@ -126,18 +206,20 @@ export async function startToolServer(options) {
|
|
|
126
206
|
}
|
|
127
207
|
return {
|
|
128
208
|
url,
|
|
129
|
-
issueRunToken: (binding) => {
|
|
209
|
+
issueRunToken: (runUuid, binding) => {
|
|
130
210
|
const token = newToken();
|
|
131
|
-
runs.set(token, binding);
|
|
211
|
+
runs.set(runUuid, { hash: hashOf(token), binding });
|
|
212
|
+
persist();
|
|
132
213
|
return token;
|
|
133
214
|
},
|
|
134
|
-
revokeRunToken: (
|
|
135
|
-
runs.delete(
|
|
215
|
+
revokeRunToken: (runUuid) => {
|
|
216
|
+
if (runs.delete(runUuid))
|
|
217
|
+
persist();
|
|
136
218
|
},
|
|
137
219
|
stop: async () => {
|
|
220
|
+
// The state file stays: the next start serves the same grants.
|
|
138
221
|
if (options.endpointFile)
|
|
139
222
|
rmSync(options.endpointFile, { force: true });
|
|
140
|
-
runs.clear();
|
|
141
223
|
http.closeAllConnections();
|
|
142
224
|
await new Promise((done) => http.close(() => done()));
|
|
143
225
|
},
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { bumpUiRefresh, configHomeOf, UI_REFRESH_FILE, } from '@bakers-build/core';
|
|
5
|
+
// shortcut: root-anchored, so it misses a project in a repo subdirectory; build it from `git rev-parse --show-prefix` when one exists.
|
|
6
|
+
const EXCLUDE_LINE = `/.bakers/${UI_REFRESH_FILE}`;
|
|
7
|
+
/** Repos (by dir) already checked this process, so git runs once per dir. */
|
|
8
|
+
const excluded = new Set();
|
|
9
|
+
/**
|
|
10
|
+
* Keep the signal file out of `git status` in projects that don't ignore it:
|
|
11
|
+
* one line in the repo's local `info/exclude`, never a tracked file.
|
|
12
|
+
*/
|
|
13
|
+
function ensureExcluded(dir) {
|
|
14
|
+
if (excluded.has(dir))
|
|
15
|
+
return;
|
|
16
|
+
excluded.add(dir);
|
|
17
|
+
try {
|
|
18
|
+
const common = resolve(dir, execFileSync('git', ['rev-parse', '--git-common-dir'], {
|
|
19
|
+
cwd: dir,
|
|
20
|
+
encoding: 'utf8',
|
|
21
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
22
|
+
}).trim());
|
|
23
|
+
const file = join(common, 'info', 'exclude');
|
|
24
|
+
const text = existsSync(file) ? readFileSync(file, 'utf8') : '';
|
|
25
|
+
if (text.split('\n').includes(EXCLUDE_LINE))
|
|
26
|
+
return;
|
|
27
|
+
mkdirSync(join(common, 'info'), { recursive: true });
|
|
28
|
+
appendFileSync(file, `${text === '' || text.endsWith('\n') ? '' : '\n'}${EXCLUDE_LINE}\n`);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// Not a git dir, or unwritable: the file just shows as untracked.
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Touch `<dir>/.bakers/ui-refresh` so a `bakers ui` there reloads. Never throws. */
|
|
35
|
+
export function signalUi(dir) {
|
|
36
|
+
const bakersDir = configHomeOf(dir);
|
|
37
|
+
if (!existsSync(bakersDir))
|
|
38
|
+
return;
|
|
39
|
+
ensureExcluded(dir);
|
|
40
|
+
bumpUiRefresh(bakersDir);
|
|
41
|
+
}
|
|
@@ -58,18 +58,67 @@ export interface SecurityOptions {
|
|
|
58
58
|
config?: Record<string, unknown>;
|
|
59
59
|
env_deny?: string[];
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* The `with` key the conductor fills with the top-level `security` blocks of
|
|
63
|
+
* the project and machine config; every harness addon passes it on here.
|
|
64
|
+
*/
|
|
65
|
+
export declare const SHARED_SECURITY_KEY = "shared_security";
|
|
66
|
+
declare const SHARED_MODES: readonly ["sandbox", "system", "yolo"];
|
|
67
|
+
declare const SHARED_LIST_KEYS: readonly ["deny_read", "allow_write", "trusted_commands"];
|
|
68
|
+
export type SharedListKey = (typeof SHARED_LIST_KEYS)[number];
|
|
69
|
+
export type SharedLayer = 'project' | 'machine';
|
|
70
|
+
export type SecuritySource = 'default' | SharedLayer | 'agent';
|
|
71
|
+
/** A top-level `security` block of the machine or project config. */
|
|
72
|
+
export interface SharedSecurity {
|
|
73
|
+
mode?: (typeof SHARED_MODES)[number];
|
|
74
|
+
sandbox?: Partial<Record<SharedListKey, string[]>>;
|
|
75
|
+
}
|
|
76
|
+
/** The effective settings with the layer each value came from (`bakers agents`). */
|
|
77
|
+
export interface SecurityReport {
|
|
78
|
+
mode: {
|
|
79
|
+
value: SecurityMode;
|
|
80
|
+
source: SecuritySource;
|
|
81
|
+
};
|
|
82
|
+
sandbox: Record<SharedListKey, {
|
|
83
|
+
entries: {
|
|
84
|
+
value: string;
|
|
85
|
+
source: SecuritySource;
|
|
86
|
+
}[];
|
|
87
|
+
removed: string[];
|
|
88
|
+
}>;
|
|
89
|
+
/** Shared values this run does not apply: the harness cannot express the
|
|
90
|
+
* key, or the effective mode is not `sandbox`. */
|
|
91
|
+
not_applied: {
|
|
92
|
+
key: SharedListKey;
|
|
93
|
+
source: SharedLayer;
|
|
94
|
+
reason: 'unsupported' | 'mode';
|
|
95
|
+
}[];
|
|
96
|
+
}
|
|
61
97
|
export interface ResolvedSecurity {
|
|
62
98
|
mode: SecurityMode;
|
|
63
|
-
/** Every key set: the harness default unless
|
|
99
|
+
/** Every key set: the harness default unless a layer replaced it. */
|
|
64
100
|
sandbox: Required<SandboxOptions>;
|
|
65
101
|
config: Record<string, unknown> | undefined;
|
|
66
102
|
runEnvPolicy: RunEnvPolicy;
|
|
103
|
+
report: SecurityReport;
|
|
67
104
|
}
|
|
68
105
|
/**
|
|
69
|
-
* Validate
|
|
70
|
-
*
|
|
71
|
-
|
|
106
|
+
* Validate one shared `security` block; `layer` names it in the error. Only
|
|
107
|
+
* `mode` and the three sandbox lists may be shared, so any other key fails.
|
|
108
|
+
*/
|
|
109
|
+
export declare function validateSharedSecurity(value: unknown, layer: SharedLayer): SharedSecurity | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* Validate the security options an agent addon takes in `with` and resolve
|
|
112
|
+
* them over the harness defaults and the shared project and machine layers
|
|
113
|
+
* (`with.shared_security`): default → project → machine → entry, a set key
|
|
114
|
+
* replaces the layer below and `'$inherit'` inserts it. Any misconfiguration
|
|
115
|
+
* of the entry is a load error, so a run never starts with rights the operator
|
|
116
|
+
* did not choose; a shared key in `unsupported` is reported, not applied.
|
|
72
117
|
*/
|
|
73
118
|
export declare function resolveSecurityOptions(input: SecurityOptions & {
|
|
74
119
|
skip_permissions?: unknown;
|
|
75
|
-
|
|
120
|
+
[SHARED_SECURITY_KEY]?: unknown;
|
|
121
|
+
}, defaults: Required<SandboxOptions>, opts?: {
|
|
122
|
+
unsupported?: readonly SharedListKey[];
|
|
123
|
+
}): ResolvedSecurity;
|
|
124
|
+
export {};
|
|
@@ -214,6 +214,47 @@ export function resolveAgentCliOptions(input, reserved, known) {
|
|
|
214
214
|
};
|
|
215
215
|
}
|
|
216
216
|
export const SECURITY_MODES = ['sandbox', 'system', 'yolo', 'custom'];
|
|
217
|
+
/**
|
|
218
|
+
* The `with` key the conductor fills with the top-level `security` blocks of
|
|
219
|
+
* the project and machine config; every harness addon passes it on here.
|
|
220
|
+
*/
|
|
221
|
+
export const SHARED_SECURITY_KEY = 'shared_security';
|
|
222
|
+
/** A list element that inserts the value of the layer below. */
|
|
223
|
+
const INHERIT = '$inherit';
|
|
224
|
+
const SHARED_MODES = ['sandbox', 'system', 'yolo'];
|
|
225
|
+
const SHARED_LIST_KEYS = [
|
|
226
|
+
'deny_read',
|
|
227
|
+
'allow_write',
|
|
228
|
+
'trusted_commands',
|
|
229
|
+
];
|
|
230
|
+
/**
|
|
231
|
+
* Validate one shared `security` block; `layer` names it in the error. Only
|
|
232
|
+
* `mode` and the three sandbox lists may be shared, so any other key fails.
|
|
233
|
+
*/
|
|
234
|
+
export function validateSharedSecurity(value, layer) {
|
|
235
|
+
if (value === undefined)
|
|
236
|
+
return undefined;
|
|
237
|
+
const block = validatePlainObject(value, `${layer} security`);
|
|
238
|
+
for (const key of Object.keys(block))
|
|
239
|
+
if (key !== 'mode' && key !== 'sandbox')
|
|
240
|
+
throw new Error(`${layer} security: unknown key ${key}`);
|
|
241
|
+
if (block.mode !== undefined &&
|
|
242
|
+
!SHARED_MODES.includes(block.mode))
|
|
243
|
+
throw new Error(`${layer} security.mode must be one of ${SHARED_MODES.join(', ')}`);
|
|
244
|
+
const sandbox = {};
|
|
245
|
+
if (block.sandbox !== undefined)
|
|
246
|
+
for (const [key, list] of Object.entries(validatePlainObject(block.sandbox, `${layer} security.sandbox`))) {
|
|
247
|
+
if (!SHARED_LIST_KEYS.includes(key))
|
|
248
|
+
throw new Error(`${layer} security.sandbox: unknown key ${key}`);
|
|
249
|
+
sandbox[key] = validateStringList(list, `${layer} security.sandbox.${key}`);
|
|
250
|
+
}
|
|
251
|
+
return {
|
|
252
|
+
...(block.mode !== undefined
|
|
253
|
+
? { mode: block.mode }
|
|
254
|
+
: {}),
|
|
255
|
+
...(block.sandbox !== undefined ? { sandbox } : {}),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
217
258
|
function validateStringList(value, field) {
|
|
218
259
|
if (!Array.isArray(value) ||
|
|
219
260
|
value.some((v) => typeof v !== 'string' || v.includes('\0'))) {
|
|
@@ -228,15 +269,27 @@ function validatePlainObject(value, field) {
|
|
|
228
269
|
return value;
|
|
229
270
|
}
|
|
230
271
|
/**
|
|
231
|
-
* Validate the security options an agent addon takes in `with` and
|
|
232
|
-
*
|
|
233
|
-
*
|
|
272
|
+
* Validate the security options an agent addon takes in `with` and resolve
|
|
273
|
+
* them over the harness defaults and the shared project and machine layers
|
|
274
|
+
* (`with.shared_security`): default → project → machine → entry, a set key
|
|
275
|
+
* replaces the layer below and `'$inherit'` inserts it. Any misconfiguration
|
|
276
|
+
* of the entry is a load error, so a run never starts with rights the operator
|
|
277
|
+
* did not choose; a shared key in `unsupported` is reported, not applied.
|
|
234
278
|
*/
|
|
235
|
-
export function resolveSecurityOptions(input, defaults) {
|
|
279
|
+
export function resolveSecurityOptions(input, defaults, opts = {}) {
|
|
236
280
|
if (input.skip_permissions !== undefined) {
|
|
237
281
|
throw new Error("skip_permissions was removed: use security: 'yolo' for a permission bypass");
|
|
238
282
|
}
|
|
239
|
-
const
|
|
283
|
+
const shared = input[SHARED_SECURITY_KEY] === undefined
|
|
284
|
+
? {}
|
|
285
|
+
: validatePlainObject(input[SHARED_SECURITY_KEY], SHARED_SECURITY_KEY);
|
|
286
|
+
const layers = ['project', 'machine'].flatMap((source) => {
|
|
287
|
+
const block = validateSharedSecurity(shared[source], source);
|
|
288
|
+
return block ? [{ source, block }] : [];
|
|
289
|
+
});
|
|
290
|
+
const modeLayer = [...layers].reverse().find((l) => l.block.mode);
|
|
291
|
+
const mode = input.security ?? modeLayer?.block.mode ?? 'sandbox';
|
|
292
|
+
const modeSource = input.security !== undefined ? 'agent' : (modeLayer?.source ?? 'default');
|
|
240
293
|
if (!SECURITY_MODES.includes(mode)) {
|
|
241
294
|
throw new Error(`security must be one of ${SECURITY_MODES.join(', ')}`);
|
|
242
295
|
}
|
|
@@ -247,29 +300,64 @@ export function resolveSecurityOptions(input, defaults) {
|
|
|
247
300
|
throw new Error("security: 'custom' requires config");
|
|
248
301
|
}
|
|
249
302
|
if (mode !== 'sandbox' && input.sandbox !== undefined) {
|
|
250
|
-
throw new Error(
|
|
303
|
+
throw new Error(`sandbox is only valid with security: 'sandbox' (the ${modeSource} layer sets '${mode}')`);
|
|
251
304
|
}
|
|
252
305
|
const given = input.sandbox === undefined
|
|
253
306
|
? {}
|
|
254
307
|
: validatePlainObject(input.sandbox, 'sandbox');
|
|
255
308
|
const sandbox = { ...defaults };
|
|
309
|
+
const report = {
|
|
310
|
+
mode: { value: mode, source: modeSource },
|
|
311
|
+
sandbox: {},
|
|
312
|
+
not_applied: [],
|
|
313
|
+
};
|
|
314
|
+
for (const key of SHARED_LIST_KEYS) {
|
|
315
|
+
let entries = defaults[key].map((value) => ({ value, source: 'default' }));
|
|
316
|
+
const stack = [];
|
|
317
|
+
for (const { source, block } of layers) {
|
|
318
|
+
const list = block.sandbox?.[key];
|
|
319
|
+
if (list === undefined)
|
|
320
|
+
continue;
|
|
321
|
+
const reason = mode !== 'sandbox'
|
|
322
|
+
? 'mode'
|
|
323
|
+
: opts.unsupported?.includes(key)
|
|
324
|
+
? 'unsupported'
|
|
325
|
+
: undefined;
|
|
326
|
+
if (reason)
|
|
327
|
+
report.not_applied.push({ key, source, reason });
|
|
328
|
+
else
|
|
329
|
+
stack.push({ source, list });
|
|
330
|
+
}
|
|
331
|
+
if (given[key] !== undefined)
|
|
332
|
+
stack.push({
|
|
333
|
+
source: 'agent',
|
|
334
|
+
list: validateStringList(given[key], `sandbox.${key}`),
|
|
335
|
+
});
|
|
336
|
+
for (const { source, list } of stack) {
|
|
337
|
+
const next = list.flatMap((value) => value === INHERIT ? entries : [{ value, source }]);
|
|
338
|
+
entries = next.filter((e, i) => next.findIndex((o) => o.value === e.value) === i);
|
|
339
|
+
}
|
|
340
|
+
sandbox[key] = entries.map((e) => e.value);
|
|
341
|
+
report.sandbox[key] = {
|
|
342
|
+
entries,
|
|
343
|
+
removed: defaults[key].filter((d) => !sandbox[key].includes(d)),
|
|
344
|
+
};
|
|
345
|
+
}
|
|
256
346
|
for (const [key, value] of Object.entries(given)) {
|
|
257
347
|
if (key === 'mcp_servers') {
|
|
258
348
|
sandbox.mcp_servers = validatePlainObject(value, 'sandbox.mcp_servers');
|
|
259
349
|
}
|
|
260
|
-
else if (key === '
|
|
261
|
-
key === 'deny_read' ||
|
|
262
|
-
key === 'allow_write' ||
|
|
263
|
-
key === 'network') {
|
|
350
|
+
else if (key === 'network') {
|
|
264
351
|
sandbox[key] = validateStringList(value, `sandbox.${key}`);
|
|
265
352
|
}
|
|
266
|
-
else {
|
|
353
|
+
else if (!SHARED_LIST_KEYS.includes(key)) {
|
|
267
354
|
throw new Error(`unknown sandbox key ${key}`);
|
|
268
355
|
}
|
|
269
356
|
}
|
|
270
357
|
return {
|
|
271
358
|
mode,
|
|
272
359
|
sandbox,
|
|
360
|
+
report,
|
|
273
361
|
config: input.config === undefined
|
|
274
362
|
? undefined
|
|
275
363
|
: validatePlainObject(input.config, 'config'),
|
|
@@ -81,7 +81,7 @@ export interface AgentRunIdentity {
|
|
|
81
81
|
attemptFamily?: string[];
|
|
82
82
|
}
|
|
83
83
|
/** The MCP server name agents see for the conductor's addon tools. */
|
|
84
|
-
export declare const CONDUCTOR_TOOLS_SERVER = "bakers
|
|
84
|
+
export declare const CONDUCTOR_TOOLS_SERVER = "bakers";
|
|
85
85
|
/** The run env var holding the run's bearer token for that server. */
|
|
86
86
|
export declare const CONDUCTOR_TOKEN_ENV = "BB_CONDUCTOR_TOKEN";
|
|
87
87
|
/** The run env var holding that server's URL, for `bakers oven tools`. */
|
|
@@ -38,7 +38,7 @@ export function matchesEnvDeny(name, patterns) {
|
|
|
38
38
|
.join('.*')}$`).test(name));
|
|
39
39
|
}
|
|
40
40
|
/** The MCP server name agents see for the conductor's addon tools. */
|
|
41
|
-
export const CONDUCTOR_TOOLS_SERVER = 'bakers
|
|
41
|
+
export const CONDUCTOR_TOOLS_SERVER = 'bakers';
|
|
42
42
|
/** The run env var holding the run's bearer token for that server. */
|
|
43
43
|
export const CONDUCTOR_TOKEN_ENV = 'BB_CONDUCTOR_TOKEN';
|
|
44
44
|
/** The run env var holding that server's URL, for `bakers oven tools`. */
|