@bakers-build/conductor 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/cli/config-plan.d.ts +4 -1
- package/dist/src/cli/config-plan.js +73 -23
- package/dist/src/cli/config-templates.d.ts +3 -1
- package/dist/src/cli/config-templates.js +7 -9
- package/dist/src/cli/config-validation.d.ts +2 -11
- package/dist/src/cli/config-validation.js +18 -47
- package/dist/src/commands/conductor.js +27 -5
- package/dist/src/config.d.ts +6 -8
- package/dist/src/config.js +96 -22
- package/dist/src/contract.d.ts +3 -2
- package/dist/src/contract.js +1 -0
- package/dist/src/core/conductor.d.ts +11 -0
- package/dist/src/core/conductor.js +154 -17
- package/dist/src/core/mr-changes.d.ts +3 -1
- package/dist/src/core/mr-changes.js +9 -2
- package/dist/src/core/site-tools.js +6 -0
- package/dist/src/core/tool-server.d.ts +2 -0
- package/dist/src/core/tool-server.js +21 -8
- package/dist/src/core/ui-signal.d.ts +5 -2
- package/dist/src/core/ui-signal.js +7 -3
- package/dist/src/plugins/agent-args.js +4 -3
- package/dist/src/plugins/agent.d.ts +41 -2
- package/dist/src/plugins/host-commands.d.ts +9 -0
- package/dist/src/plugins/host-commands.js +35 -0
- package/dist/src/plugins/preset.d.ts +5 -1
- package/dist/src/plugins/remote.d.ts +4 -2
- package/dist/src/plugins/runtime.d.ts +58 -0
- package/dist/src/plugins/runtime.js +15 -0
- package/dist/src/plugins/sandbox-preflight.d.ts +1 -0
- package/dist/src/plugins/sandbox-preflight.js +5 -0
- package/dist/src/plugins/tools.d.ts +31 -8
- package/dist/src/plugins/tools.js +61 -39
- package/dist/src/plugins/workspace.d.ts +7 -0
- package/dist/src/types.d.ts +22 -1
- package/package.json +4 -4
package/dist/src/contract.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { AmbiguousProjectNameError, type ResolvedBbProjectContext, resolveBbProjectContext, } from './bakers-project-context.js';
|
|
2
|
-
export { type AgentFootprint, type AgentRunIdentity, type BbAgent, CONDUCTOR_TOKEN_ENV, CONDUCTOR_TOOL_TIMEOUT_MS, CONDUCTOR_TOOLS_SERVER, CONDUCTOR_URL_ENV, DEFAULT_ENV_DENY, emptyAgentFootprint, matchesEnvDeny, type PluginLaunch, type RunEnvPolicy, } from './plugins/agent.js';
|
|
2
|
+
export { type AgentFootprint, type AgentModelApi, type AgentRunContext, type AgentRunIdentity, type AgentRunPreparation, type AgentRuntimeInfo, type BbAgent, CONDUCTOR_TOKEN_ENV, CONDUCTOR_TOOL_TIMEOUT_MS, CONDUCTOR_TOOLS_SERVER, CONDUCTOR_URL_ENV, DEFAULT_ENV_DENY, emptyAgentFootprint, matchesEnvDeny, type PluginLaunch, type RunBind, type RunEnvPolicy, } from './plugins/agent.js';
|
|
3
3
|
export { detectKnownOverrides, type KnownOptionSpec, type KnownOverrides, type KnownScalarKind, type ResolvedSecurity, resolveAgentCliOptions, resolveSecurityOptions, type SandboxOptions, SECURITY_MODES, type SecurityMode, type SecurityOptions, type SecurityReport, SHARED_SECURITY_KEY, type SharedListKey, type SharedSecurity, validateAgentArgs, validateOptionalBoolean, validateOptionalString, validateSharedSecurity, } from './plugins/agent-args.js';
|
|
4
4
|
export { ensureHome, homeKey, homePath, type MarketplaceDeclaration, validateMarketplaces, } from './plugins/agent-home.js';
|
|
5
5
|
export type { BbExecutor, ConductorStartContext, ExecutorCapabilities, HookContext, HookListener, HookListenerContext, HookListenerFn, HookName, HookResult, MachineRegistrationData, OpenWorkspaceContext, SpawnedSession, SpawnRunInput, WorktreeTeardown, } from './plugins/executor.js';
|
|
@@ -10,7 +10,8 @@ export { resolveAgent, selectAgent, selectAgents, selectExecutor, selectRemote,
|
|
|
10
10
|
export { type ConductorAddonEntry, type ConductorContributions, narrowConductorContributions, type Preset, } from './plugins/preset.js';
|
|
11
11
|
export type { ActiveRun, AddonDefinitionV2, AddonRegistration, BbRemote, ClaimedRun, ClaimOptions, ClaimWithheld, ConductorRegistration, ConductorStatus, FinalizableRun, FrozenTicket, InboxMessage, InboxSnapshot, RunMetrics, RunWriteAttributes, SiteToolClient, Ticket, TicketMetric, UncleanTicket, } from './plugins/remote.js';
|
|
12
12
|
export { ConductorTakeoverRequired } from './plugins/remote.js';
|
|
13
|
+
export { type BbRuntime, hostRuntime, type RuntimeLaunch, type RuntimePlugin, type RuntimeRun, } from './plugins/runtime.js';
|
|
13
14
|
export { installCommand, lastLine, type SandboxHost, type SandboxPreflight, sandboxFailures, systemSandboxHost, } from './plugins/sandbox-preflight.js';
|
|
14
|
-
export type { AddonTools, ToolBinding, ToolDefinition, ToolHandler, ToolRequest, ToolResult, } from './plugins/tools.js';
|
|
15
|
+
export type { AddonTools, AgentCatalog, ToolBinding, ToolDefinition, ToolHandler, ToolHost, ToolRequest, ToolResult, } from './plugins/tools.js';
|
|
15
16
|
export type { BbWorkspace, EnsuredWorkspace, } from './plugins/workspace.js';
|
|
16
17
|
export type { ConductorEngineConfig, ConductorFileConfig, ConductorSettings, } from './types.js';
|
package/dist/src/contract.js
CHANGED
|
@@ -19,4 +19,5 @@ export { loadInbox, validateRequestPayload, } from './plugins/message.js';
|
|
|
19
19
|
export { resolveAgent, selectAgent, selectAgents, selectExecutor, selectRemote, selectWorkspace, } from './plugins/plugins.js';
|
|
20
20
|
export { narrowConductorContributions, } from './plugins/preset.js';
|
|
21
21
|
export { ConductorTakeoverRequired } from './plugins/remote.js';
|
|
22
|
+
export { hostRuntime, } from './plugins/runtime.js';
|
|
22
23
|
export { installCommand, lastLine, sandboxFailures, systemSandboxHost, } from './plugins/sandbox-preflight.js';
|
|
@@ -52,6 +52,8 @@ export declare class Conductor {
|
|
|
52
52
|
private readonly queue;
|
|
53
53
|
/** The local MCP server for addon tools; only the serve process runs one. */
|
|
54
54
|
private toolServer;
|
|
55
|
+
/** Where runs execute; created once, on first use. */
|
|
56
|
+
private runtimeOnce;
|
|
55
57
|
/** Serializes git worktree add/remove: parallel ones fight over git locks. */
|
|
56
58
|
private gitLock;
|
|
57
59
|
/** The last good machine `tunnel` policy, re-read for each run's env. */
|
|
@@ -94,6 +96,9 @@ export declare class Conductor {
|
|
|
94
96
|
* it to the CLI.
|
|
95
97
|
*/
|
|
96
98
|
startTools(endpointFile?: string): Promise<void>;
|
|
99
|
+
private runtime;
|
|
100
|
+
/** Best-effort, like the tab close: logged, never thrown. */
|
|
101
|
+
private cleanupRuntime;
|
|
97
102
|
/** Tell an open `bakers ui` in the checkout (and the run's worktree) to reload. */
|
|
98
103
|
private signalUi;
|
|
99
104
|
stopTools(): Promise<void>;
|
|
@@ -122,6 +127,12 @@ export declare class Conductor {
|
|
|
122
127
|
private enqueueFinalize;
|
|
123
128
|
/** Finalises one run; a failure is logged and retried next tick. */
|
|
124
129
|
private finalizeOne;
|
|
130
|
+
/**
|
|
131
|
+
* Bring an isolated run's commits to the ticket branch in the parent
|
|
132
|
+
* repository. Best-effort: a refused transfer is logged and leaves the run's
|
|
133
|
+
* Git directory in place until the next run of the ticket starts.
|
|
134
|
+
*/
|
|
135
|
+
private transferRunCommits;
|
|
125
136
|
/** Read the run's transcript and parse its footprint for the close write. */
|
|
126
137
|
private captureRun;
|
|
127
138
|
/**
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { basename, dirname, join } from 'node:path';
|
|
3
|
-
import { killRunProcesses, shellQuote, stemForConfigFile, } from '@bakers-build/core';
|
|
3
|
+
import { killRunProcesses, loadRunClone, protectedProjectPaths, saveRunClone, shellQuote, stemForConfigFile, transferIsolatedCommit, } from '@bakers-build/core';
|
|
4
4
|
import { CONDUCTOR_TOKEN_ENV, CONDUCTOR_URL_ENV, DEFAULT_ENV_DENY, matchesEnvDeny, } from '../plugins/agent.js';
|
|
5
5
|
import { homeKey, homePath } from '../plugins/agent-home.js';
|
|
6
6
|
import { resolveAgent } from '../plugins/plugins.js';
|
|
7
|
-
import {
|
|
7
|
+
import { hostRuntime } from '../plugins/runtime.js';
|
|
8
|
+
import { runtimeSandboxWarning, sandboxFailures, } from '../plugins/sandbox-preflight.js';
|
|
8
9
|
import { loadTools } from '../plugins/tools.js';
|
|
9
10
|
import { ActionQueue } from './action-queue.js';
|
|
10
11
|
import { attemptFamily } from './attempt.js';
|
|
@@ -210,6 +211,8 @@ export class Conductor {
|
|
|
210
211
|
queue;
|
|
211
212
|
/** The local MCP server for addon tools; only the serve process runs one. */
|
|
212
213
|
toolServer;
|
|
214
|
+
/** Where runs execute; created once, on first use. */
|
|
215
|
+
runtimeOnce;
|
|
213
216
|
/** Serializes git worktree add/remove: parallel ones fight over git locks. */
|
|
214
217
|
gitLock = Promise.resolve();
|
|
215
218
|
/** The last good machine `tunnel` policy, re-read for each run's env. */
|
|
@@ -290,29 +293,47 @@ export class Conductor {
|
|
|
290
293
|
*/
|
|
291
294
|
async startTools(endpointFile) {
|
|
292
295
|
const { siteTools } = this.remote;
|
|
296
|
+
const runtime = await this.runtime();
|
|
293
297
|
if ((!this.config.tools && !siteTools) || this.toolServer)
|
|
294
298
|
return;
|
|
299
|
+
const hosts = (await runtime.toolServerHosts?.()) ?? [];
|
|
300
|
+
const registry = this.config.tools ?? (await loadTools([]));
|
|
295
301
|
// Runs closed while no server ran (`oven once`, a crash) lose their grant here.
|
|
296
302
|
const openRuns = await this.remote.fetchActiveRuns(this.id).then((runs) => runs.map((r) => r.runUuid), (err) => {
|
|
297
303
|
this.logger.warn({ err: String(err) }, 'active runs unreadable, keeping every persisted run grant');
|
|
298
304
|
return undefined;
|
|
299
305
|
});
|
|
300
306
|
this.toolServer = await startToolServer({
|
|
301
|
-
registry
|
|
307
|
+
registry,
|
|
302
308
|
workspaceRoot: this.checkoutRoot,
|
|
303
309
|
logger: this.logger,
|
|
304
310
|
...(endpointFile ? { endpointFile } : {}),
|
|
305
311
|
...(openRuns ? { openRuns } : {}),
|
|
306
312
|
...(siteTools ? { siteTools } : {}),
|
|
313
|
+
...(hosts.length > 0 ? { hosts } : {}),
|
|
307
314
|
onSiteWrite: (b) => this.signalUi(b.worktreePath),
|
|
308
315
|
});
|
|
309
316
|
this.logger.info({ conductorId: this.config.conductor_id, url: this.toolServer.url }, 'tool server started');
|
|
310
317
|
}
|
|
318
|
+
runtime() {
|
|
319
|
+
this.runtimeOnce ??= (this.config.runtime ?? hostRuntime).createRuntime(this.config, { logger: this.logger });
|
|
320
|
+
return this.runtimeOnce;
|
|
321
|
+
}
|
|
322
|
+
/** Best-effort, like the tab close: logged, never thrown. */
|
|
323
|
+
async cleanupRuntime(runUuid, runId) {
|
|
324
|
+
try {
|
|
325
|
+
await (await this.runtime()).cleanup({ uuid: runUuid, id: runId });
|
|
326
|
+
}
|
|
327
|
+
catch (err) {
|
|
328
|
+
this.logger.warn({ run: runUuid, err: String(err) }, 'runtime cleanup failed');
|
|
329
|
+
}
|
|
330
|
+
}
|
|
311
331
|
/** Tell an open `bakers ui` in the checkout (and the run's worktree) to reload. */
|
|
312
332
|
signalUi(worktree) {
|
|
313
333
|
signalUi(this.checkoutRoot);
|
|
334
|
+
// A run clone keeps its own exclude; the host runs no Git in its workspace.
|
|
314
335
|
if (worktree)
|
|
315
|
-
signalUi(worktree);
|
|
336
|
+
signalUi(worktree, !loadRunClone(worktree));
|
|
316
337
|
}
|
|
317
338
|
async stopTools() {
|
|
318
339
|
// Server first, so no new provision_up starts a run after the stop.
|
|
@@ -386,6 +407,9 @@ export class Conductor {
|
|
|
386
407
|
const log = this.inboxAddons.empty ? this.logger.warn : this.logger.error;
|
|
387
408
|
log.call(this.logger, { conductorId: this.id, err: String(err) }, 'addon registration failed');
|
|
388
409
|
}
|
|
410
|
+
const warning = runtimeSandboxWarning(this.config.runtime?.id);
|
|
411
|
+
if (warning)
|
|
412
|
+
this.logger.warn({ conductorId: this.id }, warning);
|
|
389
413
|
for (const line of await sandboxFailures(this.agents)) {
|
|
390
414
|
this.logger.error({ conductorId: this.id }, line);
|
|
391
415
|
}
|
|
@@ -548,6 +572,7 @@ export class Conductor {
|
|
|
548
572
|
// The transcript is captured, so killing the PTY is safe (BB-171).
|
|
549
573
|
if (branch)
|
|
550
574
|
await this.closeRunTab(branch, r.runUuid, r.runId);
|
|
575
|
+
await this.transferRunCommits(r.worktreePath, r.runUuid);
|
|
551
576
|
// BB-599: `after_run` fires at run end — after the worker is gone,
|
|
552
577
|
// before the durable close. A failed close write repeats it next tick,
|
|
553
578
|
// which is why listeners must be idempotent.
|
|
@@ -571,6 +596,25 @@ export class Conductor {
|
|
|
571
596
|
this.logger.warn({ run: r.runUuid, err: String(err) }, 'run finalise failed');
|
|
572
597
|
}
|
|
573
598
|
}
|
|
599
|
+
/**
|
|
600
|
+
* Bring an isolated run's commits to the ticket branch in the parent
|
|
601
|
+
* repository. Best-effort: a refused transfer is logged and leaves the run's
|
|
602
|
+
* Git directory in place until the next run of the ticket starts.
|
|
603
|
+
*/
|
|
604
|
+
async transferRunCommits(worktreePath, runUuid) {
|
|
605
|
+
const clone = worktreePath ? loadRunClone(worktreePath) : undefined;
|
|
606
|
+
if (!clone)
|
|
607
|
+
return;
|
|
608
|
+
try {
|
|
609
|
+
await this.serialGit(async () => {
|
|
610
|
+
const tip = transferIsolatedCommit(clone);
|
|
611
|
+
saveRunClone({ ...clone, expected: tip });
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
catch (err) {
|
|
615
|
+
this.logger.warn({ run: runUuid, branch: clone.branch, err: String(err) }, 'run commits not transferred to the ticket branch');
|
|
616
|
+
}
|
|
617
|
+
}
|
|
574
618
|
/** Read the run's transcript and parse its footprint for the close write. */
|
|
575
619
|
async captureRun(r) {
|
|
576
620
|
// Route to the agent that actually ran (BB-144): the persisted
|
|
@@ -652,6 +696,7 @@ export class Conductor {
|
|
|
652
696
|
catch (err) {
|
|
653
697
|
this.logger.warn({ run: runUuid, err: String(err) }, 'run tab cleanup failed');
|
|
654
698
|
}
|
|
699
|
+
await this.cleanupRuntime(runUuid, runId);
|
|
655
700
|
// Background commands and their sandboxes outlive the closed PTY.
|
|
656
701
|
try {
|
|
657
702
|
const { pids } = await killRunProcesses(runUuid);
|
|
@@ -751,7 +796,8 @@ export class Conductor {
|
|
|
751
796
|
});
|
|
752
797
|
}
|
|
753
798
|
}
|
|
754
|
-
|
|
799
|
+
// Host scripts take the worktree from here: a run clone has no Git to ask.
|
|
800
|
+
const shell = await this.runHook(name, cwd, { ticket: ticketRef }, { ...shellEnv, BAKERS_WORKTREE_PATH: cwd });
|
|
755
801
|
if (failed.length === 0)
|
|
756
802
|
return shell;
|
|
757
803
|
const error = `hook listener failed: ${failed.join(', ')}`;
|
|
@@ -940,7 +986,11 @@ export class Conductor {
|
|
|
940
986
|
if (!t.baseBranch)
|
|
941
987
|
throw new Error('ticket has no base branch');
|
|
942
988
|
// Under the git lock: workspace.ensure fetches the same ref into this repo.
|
|
943
|
-
const values = await this.serialGit(() =>
|
|
989
|
+
const values = await this.serialGit(() =>
|
|
990
|
+
// A run clone has no Git on the host: measure its branch in the parent.
|
|
991
|
+
loadRunClone(t.worktreePath)
|
|
992
|
+
? measureMrChanges(this.checkoutRoot, t.baseBranch, t.branchName)
|
|
993
|
+
: measureMrChanges(t.worktreePath, t.baseBranch));
|
|
944
994
|
await this.remote.replaceTicketMetrics(t.ticketUuid, 'mr_changes.', mrChangesRows(values, Math.floor(Date.now() / 1000)));
|
|
945
995
|
}
|
|
946
996
|
catch (err) {
|
|
@@ -1122,7 +1172,11 @@ export class Conductor {
|
|
|
1122
1172
|
...(t.identifier ? { BAKERS_TICKET_IDENTIFIER: t.identifier } : {}),
|
|
1123
1173
|
...(state ? { BAKERS_STATE: state } : {}),
|
|
1124
1174
|
...(runUuid ? { BAKERS_RUN_UUID: runUuid } : {}),
|
|
1175
|
+
// A host script names the worktree's DDEV project after it without asking Git.
|
|
1176
|
+
...(t.branchName ? { BAKERS_BRANCH_NAME: t.branchName } : {}),
|
|
1125
1177
|
BAKERS_TUNNEL: (await this.currentTunnel()) ? '1' : '0',
|
|
1178
|
+
// Host scripts skip what an isolated run does in its own container.
|
|
1179
|
+
BAKERS_RUNTIME_ISOLATES: this.config.runtime?.isolates ? '1' : '0',
|
|
1126
1180
|
WORKSPACE_ROOT: this.checkoutRoot,
|
|
1127
1181
|
...(t.issueUrl ? { TICKET_URL: t.issueUrl } : {}),
|
|
1128
1182
|
...(t.projectName ? { BAKERS_PROJECT: t.projectName } : {}),
|
|
@@ -1255,6 +1309,13 @@ export class Conductor {
|
|
|
1255
1309
|
const env = await this.runEnv(t, run.runUuid, run.stateAtStart, chosen.agent);
|
|
1256
1310
|
const ws = await this.serialGit(() => this.workspace.ensure(t.identifier, t.branchName, baseRef));
|
|
1257
1311
|
at.worktree = ws.path;
|
|
1312
|
+
// The transfer checks the project's list; the record is the host's alone.
|
|
1313
|
+
if (ws.clone)
|
|
1314
|
+
saveRunClone({
|
|
1315
|
+
...ws.clone,
|
|
1316
|
+
protectedPaths: this.config.readOnly ?? [],
|
|
1317
|
+
});
|
|
1318
|
+
env.BAKERS_WORKTREE_PATH = ws.path;
|
|
1258
1319
|
// The backend's own vars (Git config) join the run env; core keys still win.
|
|
1259
1320
|
for (const [key, value] of Object.entries(ws.env ?? {})) {
|
|
1260
1321
|
if (!isReservedEnvKey(key))
|
|
@@ -1363,7 +1424,9 @@ export class Conductor {
|
|
|
1363
1424
|
// a re-dispatch of the same run drops its stale duplicate before startRun
|
|
1364
1425
|
// re-creates it. Sibling prior-state run tabs are left to the worktree reap.
|
|
1365
1426
|
await this.executor.cleanupRun(t.branchName, run.runId);
|
|
1366
|
-
|
|
1427
|
+
await this.cleanupRuntime(run.runUuid, run.runId);
|
|
1428
|
+
const runtime = await this.runtime();
|
|
1429
|
+
let prompt = ws.instructions
|
|
1367
1430
|
? renderPrompt(this.config.prompt, {
|
|
1368
1431
|
identifier: t.identifier,
|
|
1369
1432
|
state: t.state || 'qualification',
|
|
@@ -1371,6 +1434,13 @@ export class Conductor {
|
|
|
1371
1434
|
ticketUuid: t.uuid,
|
|
1372
1435
|
})
|
|
1373
1436
|
: '';
|
|
1437
|
+
if (prompt && ws.clone)
|
|
1438
|
+
prompt +=
|
|
1439
|
+
'\n\nRuntime context: this run works in a fresh clone of the ticket branch. ' +
|
|
1440
|
+
'Commit before you end: uncommitted work is not carried over. ' +
|
|
1441
|
+
'forge_fetch refreshes the origin refs and forge_push transfers and pushes your commits. ' +
|
|
1442
|
+
`Read-only here: ${['.bakers', ...(this.config.readOnly ?? [])].filter((path, index, all) => all.indexOf(path) === index).join(', ')}. ` +
|
|
1443
|
+
'If merging the target fails on one of them, report it: a maintainer merges the target outside the run.';
|
|
1374
1444
|
// BB-473 review round 2 (Critical 1): pinning the run's own UUID
|
|
1375
1445
|
// unconditionally makes a re-dispatch of the same run — an existing,
|
|
1376
1446
|
// supported path (see the cleanupRun comment above) — fail to launch,
|
|
@@ -1413,9 +1483,40 @@ export class Conductor {
|
|
|
1413
1483
|
const tools = chosen.agent.withoutConductorTools
|
|
1414
1484
|
? undefined
|
|
1415
1485
|
: this.issueRunTools(run.runUuid, { worktreePath: ws.path, ticket: t });
|
|
1486
|
+
const toolsUrl = tools
|
|
1487
|
+
? (runtime.toolsUrl?.(tools.url) ?? tools.url)
|
|
1488
|
+
: undefined;
|
|
1416
1489
|
const plugins = await this.installPlugins(chosen, t, run);
|
|
1417
1490
|
Object.assign(env, plugins.env);
|
|
1418
|
-
const
|
|
1491
|
+
const agentInfo = {
|
|
1492
|
+
...(chosen.agent.installCommand
|
|
1493
|
+
? { installCommand: chosen.agent.installCommand }
|
|
1494
|
+
: {}),
|
|
1495
|
+
...(chosen.agent.modelApi ? { modelApi: chosen.agent.modelApi } : {}),
|
|
1496
|
+
};
|
|
1497
|
+
const runtimeContext = await runtime.prepareRun?.({
|
|
1498
|
+
uuid: run.runUuid,
|
|
1499
|
+
id: run.runId,
|
|
1500
|
+
}, agentInfo);
|
|
1501
|
+
if (runtimeContext?.env)
|
|
1502
|
+
Object.assign(env, runtimeContext.env);
|
|
1503
|
+
const preparation = runtimeContext
|
|
1504
|
+
? await chosen.agent.prepareRun?.({
|
|
1505
|
+
...runtimeContext,
|
|
1506
|
+
workspacePath: ws.path,
|
|
1507
|
+
env,
|
|
1508
|
+
})
|
|
1509
|
+
: undefined;
|
|
1510
|
+
if (preparation)
|
|
1511
|
+
Object.assign(env, preparation.env);
|
|
1512
|
+
const isolates = this.config.runtime?.isolates === true;
|
|
1513
|
+
// An isolated run without its own clone would share the parent's Git data.
|
|
1514
|
+
if (isolates && !ws.clone)
|
|
1515
|
+
throw new Error('the runtime isolates runs, but the workspace provides no run clone');
|
|
1516
|
+
const protectedPaths = isolates
|
|
1517
|
+
? protectedProjectPaths(ws.path, this.config.readOnly ?? [])
|
|
1518
|
+
: [];
|
|
1519
|
+
const command = chosen.agent.launchCommand(prompt, identity, ws.path, toolsUrl ? { url: toolsUrl } : undefined, env, plugins.args, isolates);
|
|
1419
1520
|
// Read after launchCommand: a warning may depend on what this launch got.
|
|
1420
1521
|
const warnings = chosen.agent.launchWarnings;
|
|
1421
1522
|
if (warnings?.length) {
|
|
@@ -1429,6 +1530,45 @@ export class Conductor {
|
|
|
1429
1530
|
}, `${chosen.agent.id}/${alias}: ${warning}`);
|
|
1430
1531
|
}
|
|
1431
1532
|
}
|
|
1533
|
+
// The token travels in the env, never in argv or the launch log.
|
|
1534
|
+
const runEnv = tools
|
|
1535
|
+
? {
|
|
1536
|
+
...env,
|
|
1537
|
+
[CONDUCTOR_URL_ENV]: toolsUrl,
|
|
1538
|
+
[CONDUCTOR_TOKEN_ENV]: tools.token,
|
|
1539
|
+
}
|
|
1540
|
+
: env;
|
|
1541
|
+
// A wrap failure fails the dispatch: an isolated run never falls back to the host.
|
|
1542
|
+
const wrapped = await runtime.wrap({
|
|
1543
|
+
command,
|
|
1544
|
+
env: runEnv,
|
|
1545
|
+
workspacePath: ws.path,
|
|
1546
|
+
...(ws.clone
|
|
1547
|
+
? {
|
|
1548
|
+
gitDir: ws.clone.gitDir,
|
|
1549
|
+
...(ws.clone.shared
|
|
1550
|
+
? { sharedObjects: join(ws.clone.parentGitDir, 'objects') }
|
|
1551
|
+
: {}),
|
|
1552
|
+
}
|
|
1553
|
+
: {}),
|
|
1554
|
+
run: { uuid: run.runUuid, id: run.runId },
|
|
1555
|
+
harness: chosen.agent.id,
|
|
1556
|
+
...agentInfo,
|
|
1557
|
+
...(runtimeContext
|
|
1558
|
+
? {
|
|
1559
|
+
homePath: runtimeContext.homePath,
|
|
1560
|
+
readPaths: [
|
|
1561
|
+
...(preparation?.readPaths ?? []),
|
|
1562
|
+
...(isolates ? protectedPaths : []),
|
|
1563
|
+
],
|
|
1564
|
+
writePaths: preparation?.writePaths ?? [],
|
|
1565
|
+
...(preparation?.bindPaths?.length
|
|
1566
|
+
? { bindPaths: preparation.bindPaths }
|
|
1567
|
+
: {}),
|
|
1568
|
+
}
|
|
1569
|
+
: {}),
|
|
1570
|
+
...(isolates && !runtimeContext ? { readPaths: protectedPaths } : {}),
|
|
1571
|
+
});
|
|
1432
1572
|
await this.executor.startRun({
|
|
1433
1573
|
ticket: {
|
|
1434
1574
|
uuid: t.uuid,
|
|
@@ -1441,15 +1581,8 @@ export class Conductor {
|
|
|
1441
1581
|
run: { uuid: run.runUuid, id: run.runId, handler: run.handler },
|
|
1442
1582
|
workspacePath: ws.path,
|
|
1443
1583
|
instructions: ws.instructions,
|
|
1444
|
-
command,
|
|
1445
|
-
|
|
1446
|
-
env: tools
|
|
1447
|
-
? {
|
|
1448
|
-
...env,
|
|
1449
|
-
[CONDUCTOR_URL_ENV]: tools.url,
|
|
1450
|
-
[CONDUCTOR_TOKEN_ENV]: tools.token,
|
|
1451
|
-
}
|
|
1452
|
-
: env,
|
|
1584
|
+
command: wrapped.command,
|
|
1585
|
+
env: wrapped.env,
|
|
1453
1586
|
});
|
|
1454
1587
|
launch.started = true;
|
|
1455
1588
|
this.logger.info({
|
|
@@ -1461,6 +1594,7 @@ export class Conductor {
|
|
|
1461
1594
|
envKeys: Object.keys(env),
|
|
1462
1595
|
harness: chosen.agent.id,
|
|
1463
1596
|
alias: chosen.alias ?? chosen.id,
|
|
1597
|
+
runtime: runtime.id,
|
|
1464
1598
|
// The launch with its options; the prompt is long and in the ticket.
|
|
1465
1599
|
launch: command.replace(shellQuote(prompt), "'<prompt>'"),
|
|
1466
1600
|
}, 'dispatched run');
|
|
@@ -1493,6 +1627,9 @@ export class Conductor {
|
|
|
1493
1627
|
}
|
|
1494
1628
|
await this.closeRunTab(ctx.ticket.branchName, runUuid, ctx.run?.id ?? 0);
|
|
1495
1629
|
}
|
|
1630
|
+
else {
|
|
1631
|
+
await this.cleanupRuntime(runUuid, ctx.run?.id ?? 0);
|
|
1632
|
+
}
|
|
1496
1633
|
await this.runSlot('after_run', ctx.worktreePath, ctx.ticket.identifier, ctx, ctx.env);
|
|
1497
1634
|
}
|
|
1498
1635
|
catch (err) {
|
|
@@ -14,5 +14,7 @@ export declare function mrChangesRows(v: MrChanges, recorded: number): TicketMet
|
|
|
14
14
|
* Measures the ticket branch checked out in `worktreePath` against the merge
|
|
15
15
|
* base with `origin/<baseBranch>` — the diff the merge request's Changes tab
|
|
16
16
|
* shows. `HEAD`, not the remote branch: a merge deletes the remote branch.
|
|
17
|
+
* With `branch`, `worktreePath` is the parent repository and the local branch
|
|
18
|
+
* is measured: an isolated run's workspace has no Git on the host.
|
|
17
19
|
*/
|
|
18
|
-
export declare function measureMrChanges(worktreePath: string, baseBranch: string): Promise<MrChanges>;
|
|
20
|
+
export declare function measureMrChanges(worktreePath: string, baseBranch: string, branch?: string): Promise<MrChanges>;
|
|
@@ -39,11 +39,18 @@ export function mrChangesRows(v, recorded) {
|
|
|
39
39
|
* Measures the ticket branch checked out in `worktreePath` against the merge
|
|
40
40
|
* base with `origin/<baseBranch>` — the diff the merge request's Changes tab
|
|
41
41
|
* shows. `HEAD`, not the remote branch: a merge deletes the remote branch.
|
|
42
|
+
* With `branch`, `worktreePath` is the parent repository and the local branch
|
|
43
|
+
* is measured: an isolated run's workspace has no Git on the host.
|
|
42
44
|
*/
|
|
43
|
-
export async function measureMrChanges(worktreePath, baseBranch) {
|
|
45
|
+
export async function measureMrChanges(worktreePath, baseBranch, branch) {
|
|
44
46
|
await exec('git', ['fetch', 'origin', '--', baseBranch], {
|
|
45
47
|
cwd: worktreePath,
|
|
46
48
|
});
|
|
47
|
-
const out = await exec('git', [
|
|
49
|
+
const out = await exec('git', [
|
|
50
|
+
'diff',
|
|
51
|
+
'--numstat',
|
|
52
|
+
'-M',
|
|
53
|
+
`origin/${baseBranch}...${branch ? `refs/heads/${branch}` : 'HEAD'}`,
|
|
54
|
+
], { cwd: worktreePath });
|
|
48
55
|
return parseNumstat(out);
|
|
49
56
|
}
|
|
@@ -10,6 +10,7 @@ export const SITE_TOOLS = [
|
|
|
10
10
|
'bakers_ticket_update',
|
|
11
11
|
'bakers_ticket_classify',
|
|
12
12
|
'bakers_ticket_transition',
|
|
13
|
+
'bakers_run_cancel',
|
|
13
14
|
'bakers_comment_publish',
|
|
14
15
|
'bakers_metric_write',
|
|
15
16
|
'bakers_ticket_list',
|
|
@@ -24,6 +25,7 @@ export const SITE_WRITE_TOOLS = [
|
|
|
24
25
|
'bakers_ticket_update',
|
|
25
26
|
'bakers_ticket_classify',
|
|
26
27
|
'bakers_ticket_transition',
|
|
28
|
+
'bakers_run_cancel',
|
|
27
29
|
'bakers_comment_publish',
|
|
28
30
|
];
|
|
29
31
|
const WIRE = 'tool_api__';
|
|
@@ -74,6 +76,10 @@ export function siteToolProxy(client, logger) {
|
|
|
74
76
|
// The site reads an empty project or workspace as no filter, so empty counts as missing.
|
|
75
77
|
const blank = (v) => v === undefined || v === null || v === '';
|
|
76
78
|
const scoped = { ...args };
|
|
79
|
+
// Machine-wide cancellation can reach projects outside this run's scope.
|
|
80
|
+
if (name === 'bakers_run_cancel' &&
|
|
81
|
+
(blank(scoped.ticket) || !blank(scoped.machine_id)))
|
|
82
|
+
throw new Error('In a run, cancel by ticket only; machine_id is not allowed.');
|
|
77
83
|
if (FILLS_PROJECT.includes(name) && blank(scoped.project))
|
|
78
84
|
scoped.project = project;
|
|
79
85
|
if (name === 'bakers_label_list' &&
|
|
@@ -29,5 +29,7 @@ export interface ToolServerOptions {
|
|
|
29
29
|
onSiteWrite?: (binding: ToolBinding) => void;
|
|
30
30
|
/** The runs still open; persisted grants of any other run are dropped. Absent: keep all. */
|
|
31
31
|
openRuns?: string[];
|
|
32
|
+
/** Further addresses to listen on, on the same port (a runtime's container network). */
|
|
33
|
+
hosts?: string[];
|
|
32
34
|
}
|
|
33
35
|
export declare function startToolServer(options: ToolServerOptions): Promise<ToolServer>;
|
|
@@ -144,7 +144,7 @@ export async function startToolServer(options) {
|
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
146
|
};
|
|
147
|
-
const
|
|
147
|
+
const handler = (req, res) => {
|
|
148
148
|
const handle = async () => {
|
|
149
149
|
if (req.method === 'POST' && req.url === '/call')
|
|
150
150
|
return operatorCall(req, res);
|
|
@@ -171,11 +171,13 @@ export async function startToolServer(options) {
|
|
|
171
171
|
if (!res.headersSent)
|
|
172
172
|
send(res, 500, { error: 'internal error' });
|
|
173
173
|
});
|
|
174
|
-
}
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
174
|
+
};
|
|
175
|
+
const http = createServer(handler);
|
|
176
|
+
const extra = (options.hosts ?? []).map(() => createServer(handler));
|
|
177
|
+
const listen = (at, server = http, host = '127.0.0.1') => new Promise((done, fail) => {
|
|
178
|
+
server.once('error', fail);
|
|
179
|
+
server.listen(at, host, () => {
|
|
180
|
+
server.off('error', fail);
|
|
179
181
|
done();
|
|
180
182
|
});
|
|
181
183
|
});
|
|
@@ -191,6 +193,15 @@ export async function startToolServer(options) {
|
|
|
191
193
|
}
|
|
192
194
|
port = http.address().port;
|
|
193
195
|
const url = `http://127.0.0.1:${port}`;
|
|
196
|
+
try {
|
|
197
|
+
for (const [i, host] of (options.hosts ?? []).entries())
|
|
198
|
+
await listen(port, extra[i], host);
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
for (const s of [http, ...extra])
|
|
202
|
+
s.close();
|
|
203
|
+
throw err;
|
|
204
|
+
}
|
|
194
205
|
if (options.endpointFile) {
|
|
195
206
|
mkdirSync(dirname(options.endpointFile), { recursive: true, mode: 0o700 });
|
|
196
207
|
persist();
|
|
@@ -220,8 +231,10 @@ export async function startToolServer(options) {
|
|
|
220
231
|
// The state file stays: the next start serves the same grants.
|
|
221
232
|
if (options.endpointFile)
|
|
222
233
|
rmSync(options.endpointFile, { force: true });
|
|
223
|
-
http.
|
|
224
|
-
|
|
234
|
+
await Promise.all([http, ...extra].map((s) => {
|
|
235
|
+
s.closeAllConnections();
|
|
236
|
+
return new Promise((done) => s.close(() => done()));
|
|
237
|
+
}));
|
|
225
238
|
},
|
|
226
239
|
};
|
|
227
240
|
}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Touch `<dir>/.bakers/ui-refresh` so a `bakers ui` there reloads. Never throws.
|
|
3
|
+
* `exclude: false` runs no Git in `dir`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function signalUi(dir: string, exclude?: boolean): void;
|
|
@@ -31,11 +31,15 @@ function ensureExcluded(dir) {
|
|
|
31
31
|
// Not a git dir, or unwritable: the file just shows as untracked.
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
/**
|
|
35
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Touch `<dir>/.bakers/ui-refresh` so a `bakers ui` there reloads. Never throws.
|
|
36
|
+
* `exclude: false` runs no Git in `dir`.
|
|
37
|
+
*/
|
|
38
|
+
export function signalUi(dir, exclude = true) {
|
|
36
39
|
const bakersDir = configHomeOf(dir);
|
|
37
40
|
if (!existsSync(bakersDir))
|
|
38
41
|
return;
|
|
39
|
-
|
|
42
|
+
if (exclude)
|
|
43
|
+
ensureExcluded(dir);
|
|
40
44
|
bumpUiRefresh(bakersDir);
|
|
41
45
|
}
|
|
@@ -304,12 +304,13 @@ export function resolveSecurityOptions(input, defaults, opts = {}) {
|
|
|
304
304
|
if (mode === 'custom' && input.config === undefined) {
|
|
305
305
|
throw new Error("permissions: 'custom' requires config");
|
|
306
306
|
}
|
|
307
|
-
|
|
307
|
+
const entrySandbox = input.sandbox;
|
|
308
|
+
if (mode !== 'sandbox' && entrySandbox !== undefined) {
|
|
308
309
|
throw new Error(`sandbox is only valid with permissions: 'sandbox' (the ${modeSource} layer sets '${mode}')`);
|
|
309
310
|
}
|
|
310
|
-
const given =
|
|
311
|
+
const given = entrySandbox === undefined
|
|
311
312
|
? {}
|
|
312
|
-
: validatePlainObject(
|
|
313
|
+
: validatePlainObject(entrySandbox, 'sandbox');
|
|
313
314
|
const sandbox = { ...defaults };
|
|
314
315
|
const report = {
|
|
315
316
|
mode: { value: mode, source: modeSource },
|
|
@@ -107,9 +107,46 @@ export interface PluginLaunch {
|
|
|
107
107
|
/** Declared plugins the harness cannot load, for the same entry. */
|
|
108
108
|
gaps?: string[];
|
|
109
109
|
}
|
|
110
|
-
|
|
110
|
+
/** Inputs for preparing an agent in a runtime-provided home. */
|
|
111
|
+
export interface AgentRunContext {
|
|
112
|
+
homePath: string;
|
|
113
|
+
workspacePath: string;
|
|
114
|
+
env: Readonly<Record<string, string>>;
|
|
115
|
+
}
|
|
116
|
+
/** Files and environment an agent needs, independent of its execution backend. */
|
|
117
|
+
export interface AgentRunPreparation {
|
|
118
|
+
env: Record<string, string>;
|
|
119
|
+
readPaths: string[];
|
|
120
|
+
writePaths: string[];
|
|
121
|
+
/** Host files mounted read-write over a target inside the run home. */
|
|
122
|
+
bindPaths?: RunBind[];
|
|
123
|
+
}
|
|
124
|
+
/** One host file the run shares, mounted over `target` in the run home. */
|
|
125
|
+
export interface RunBind {
|
|
126
|
+
source: string;
|
|
127
|
+
target: string;
|
|
128
|
+
}
|
|
129
|
+
/** Model API facts used by credential relays, independent of an execution backend. */
|
|
130
|
+
export interface AgentModelApi {
|
|
131
|
+
target: string;
|
|
132
|
+
baseUrlEnv: string;
|
|
133
|
+
keyEnv: string;
|
|
134
|
+
credentialHint: string;
|
|
135
|
+
auth: Record<string, {
|
|
136
|
+
set: Record<string, string>;
|
|
137
|
+
append?: Record<string, string>;
|
|
138
|
+
}>;
|
|
139
|
+
}
|
|
140
|
+
/** Optional software and API facts; the runtime owns installation and transport. */
|
|
141
|
+
export interface AgentRuntimeInfo {
|
|
142
|
+
readonly installCommand?: string;
|
|
143
|
+
readonly modelApi?: AgentModelApi;
|
|
144
|
+
}
|
|
145
|
+
export interface BbAgent extends AgentRuntimeInfo {
|
|
111
146
|
/** Stable id, e.g. 'claude'. */
|
|
112
147
|
readonly id: string;
|
|
148
|
+
/** Prepare configuration in a private run home without runtime-specific flags. */
|
|
149
|
+
prepareRun?(context: AgentRunContext): AgentRunPreparation | Promise<AgentRunPreparation>;
|
|
113
150
|
/** True when the catalog entry sets `plugins: false`: the run uses the user's own agent home. */
|
|
114
151
|
readonly pluginsDisabled?: boolean;
|
|
115
152
|
/**
|
|
@@ -161,7 +198,9 @@ export interface BbAgent {
|
|
|
161
198
|
*/
|
|
162
199
|
launchCommand(prompt: string, run?: AgentRunIdentity, workspacePath?: string, tools?: {
|
|
163
200
|
url: string;
|
|
164
|
-
}, env?: Readonly<Record<string, string>>, args?: readonly string[]
|
|
201
|
+
}, env?: Readonly<Record<string, string>>, args?: readonly string[],
|
|
202
|
+
/** The workspace is a run clone: grant `<workspace>/.git`, ask Git nothing. */
|
|
203
|
+
isolatedGit?: boolean): string;
|
|
165
204
|
/**
|
|
166
205
|
* Locate and read this agent's run transcript for a run that executed in
|
|
167
206
|
* `worktreePath`. MUST return '' (never throw) when nothing is found.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ConductorSettings } from '../types.js';
|
|
2
|
+
/** The script a host command starts: its first word, or the word after `bash`, `sh` or `node`. */
|
|
3
|
+
export declare function hostCommandEntry(command: string): string | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Throws naming the first hook or provision command whose entry point lies
|
|
6
|
+
* outside `protectedPaths`. Only the entry is checked: what that script calls
|
|
7
|
+
* is the project's responsibility.
|
|
8
|
+
*/
|
|
9
|
+
export declare function assertProtectedEntryPoints(hooks: ConductorSettings['hooks'], protectedPaths: readonly string[]): void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Under an isolating runtime the host runs only code the run cannot write:
|
|
2
|
+
// every project hook and provision command must start in a protected path.
|
|
3
|
+
import { posix } from 'node:path';
|
|
4
|
+
const INTERPRETERS = new Set(['bash', 'sh', 'node']);
|
|
5
|
+
/** The script a host command starts: its first word, or the word after `bash`, `sh` or `node`. */
|
|
6
|
+
export function hostCommandEntry(command) {
|
|
7
|
+
const [first, second] = command
|
|
8
|
+
.trim()
|
|
9
|
+
.split(/[\s;&|]+/)
|
|
10
|
+
.filter(Boolean);
|
|
11
|
+
return first !== undefined && INTERPRETERS.has(first) ? second : first;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Throws naming the first hook or provision command whose entry point lies
|
|
15
|
+
* outside `protectedPaths`. Only the entry is checked: what that script calls
|
|
16
|
+
* is the project's responsibility.
|
|
17
|
+
*/
|
|
18
|
+
export function assertProtectedEntryPoints(hooks, protectedPaths) {
|
|
19
|
+
const roots = ['.bakers', ...protectedPaths].map((path) => posix.normalize(path));
|
|
20
|
+
for (const [name, value] of Object.entries(hooks ?? {})) {
|
|
21
|
+
const commands = typeof value === 'string'
|
|
22
|
+
? [[`hooks.${name}`, value]]
|
|
23
|
+
: Object.entries(value ?? {}).map(([key, command]) => [
|
|
24
|
+
`hooks.${name}.${key}`,
|
|
25
|
+
command,
|
|
26
|
+
]);
|
|
27
|
+
for (const [label, command] of commands) {
|
|
28
|
+
const entry = hostCommandEntry(command);
|
|
29
|
+
const path = entry === undefined ? undefined : posix.normalize(entry);
|
|
30
|
+
if (path === undefined ||
|
|
31
|
+
!roots.some((root) => path === root || path.startsWith(`${root}/`)))
|
|
32
|
+
throw new Error(`${label}: under an isolating runtime a host command must start with a script in a protected path (${roots.join(', ')}); got ${JSON.stringify(command)}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|