@bakers-build/conductor 0.11.1-next.2 → 0.11.1-next.4
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/config.d.ts +5 -0
- package/dist/src/config.js +106 -7
- package/dist/src/contract.d.ts +1 -1
- package/dist/src/contract.js +1 -1
- package/dist/src/core/conductor.d.ts +23 -4
- package/dist/src/core/conductor.js +158 -28
- package/dist/src/plugins/agent-home.d.ts +2 -0
- package/dist/src/plugins/agent-home.js +1 -1
- package/dist/src/plugins/agent.d.ts +10 -3
- package/dist/src/plugins/plugins.d.ts +6 -0
- package/dist/src/plugins/plugins.js +23 -0
- package/dist/src/plugins/remote.d.ts +2 -0
- package/dist/src/plugins/slot-catalog.d.ts +33 -0
- package/dist/src/plugins/slot-catalog.js +86 -0
- package/dist/src/plugins/tools.d.ts +2 -2
- package/dist/src/plugins/tools.js +5 -1
- package/dist/src/plugins/workspace.d.ts +8 -1
- package/dist/src/types.d.ts +13 -1
- package/package.json +4 -4
package/dist/src/config.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type BbConnectionConfig } from '@bakers-build/core';
|
|
2
2
|
import type { AgentCandidate } from './plugins/plugins.js';
|
|
3
|
+
import type { SlotCatalog, SlotName } from './plugins/slot-catalog.js';
|
|
3
4
|
import type { ConductorEngineConfig, ConductorFileConfig } from './types.js';
|
|
4
5
|
export { findBbDir, resolveConfigPath, } from '@bakers-build/core';
|
|
5
6
|
/**
|
|
@@ -56,6 +57,10 @@ export declare const DEFAULT_AGENT_PROMPT: string;
|
|
|
56
57
|
* verbatim (AC-1, AC-2). Normalization to a list happens at selection time.
|
|
57
58
|
*/
|
|
58
59
|
export declare function resolveAgents(raw: unknown, configPath: string): Promise<AgentCandidate | AgentCandidate[]>;
|
|
60
|
+
/** A slot that runs one plugin per conductor: its catalog has one entry. */
|
|
61
|
+
export declare function singleEntryCatalog<P extends {
|
|
62
|
+
id: string;
|
|
63
|
+
}>(slot: SlotName, plugins: P[]): SlotCatalog<P>;
|
|
59
64
|
/**
|
|
60
65
|
* Load the ENGINE half of a conductor config (BB-201 split model). Reads
|
|
61
66
|
* remote/executor/agent/workspace + project/states/prompt/
|
package/dist/src/config.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { readdirSync } from 'node:fs';
|
|
2
2
|
import { basename, dirname, isAbsolute, resolve } from 'node:path';
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
|
-
import { assertSchemaVersion, assertValidConfig, discoverAddons, discoverScoped, findDefaultExportObject, machineContextPath, matchDelimiter, readMachineContext, resolveConductorSlots, resolveModuleEslintStyle, scanTopLevelProperties, scopeAddons, secretsFilePath, stemForConfigFile, } from '@bakers-build/core';
|
|
4
|
+
import { assertSchemaVersion, assertValidConfig, discoverAddons, discoverScoped, findDefaultExportObject, loadRunClone, machineContextPath, matchDelimiter, readMachineContext, resolveConductorSlots, resolveModuleEslintStyle, scanTopLevelProperties, scopeAddons, secretsFilePath, stemForConfigFile, } from '@bakers-build/core';
|
|
5
5
|
import { readBbProjectSelection } from './cli/project-context.js';
|
|
6
6
|
import { SHARED_SECURITY_KEY, validateSharedSecurity, } from './plugins/agent-args.js';
|
|
7
7
|
import { validateMarketplaces } from './plugins/agent-home.js';
|
|
8
8
|
import { assertProtectedEntryPoints } from './plugins/host-commands.js';
|
|
9
9
|
import { loadInbox } from './plugins/message.js';
|
|
10
10
|
import { narrowConductorContributions, } from './plugins/preset.js';
|
|
11
|
+
import { hostRuntime } from './plugins/runtime.js';
|
|
11
12
|
import { loadTools, provisionRuns, provisionTools, } from './plugins/tools.js';
|
|
12
13
|
// BB-201: the `.bakers/` walk-up + connection resolution moved to `@bakers-build/core`
|
|
13
14
|
// (`resolveConfigPath` / `resolveBbConfigPath` / `findBbDir`). Re-export the
|
|
@@ -262,6 +263,79 @@ export async function resolveAgents(raw, configPath) {
|
|
|
262
263
|
? Promise.all(raw.map(resolveOne))
|
|
263
264
|
: resolveOne(raw);
|
|
264
265
|
}
|
|
266
|
+
/** A slot that runs one plugin per conductor: its catalog has one entry. */
|
|
267
|
+
export function singleEntryCatalog(slot, plugins) {
|
|
268
|
+
if (plugins.length > 1)
|
|
269
|
+
throw new Error(`${slot} catalog: only one entry is supported`);
|
|
270
|
+
const [only] = plugins;
|
|
271
|
+
return { slot, entries: { [only.id]: only }, default: only.id, routes: {} };
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* The runtime catalog: built-in `system` (the host), the addon runtime as the
|
|
275
|
+
* preset under its id, then the machine entries (an alias equal to the preset
|
|
276
|
+
* id replaces it). The project only restricts it and names its default.
|
|
277
|
+
*/
|
|
278
|
+
async function loadRuntimeCatalog(preset, machine, project, bases) {
|
|
279
|
+
const entries = { system: hostRuntime };
|
|
280
|
+
if (preset)
|
|
281
|
+
entries[preset.id] = preset;
|
|
282
|
+
for (const [index, entry] of (machine?.catalog ?? []).entries()) {
|
|
283
|
+
if (entry.alias === 'system')
|
|
284
|
+
throw new Error("runtime catalog: alias 'system' is reserved for the built-in host runtime");
|
|
285
|
+
const found = narrowConductorContributions(await discoverAddons([
|
|
286
|
+
{
|
|
287
|
+
use: entry.use,
|
|
288
|
+
...(entry.with !== undefined ? { with: entry.with } : {}),
|
|
289
|
+
},
|
|
290
|
+
], 'conductor', bases, { only: ['runtimes'] })).runtimes.at(-1);
|
|
291
|
+
if (found?.kind !== 'runtime')
|
|
292
|
+
throw new Error(`runtime.catalog[${index}] '${entry.use}' contributes no runtime`);
|
|
293
|
+
entries[entry.alias] = found;
|
|
294
|
+
}
|
|
295
|
+
const routes = { ...(machine?.routes ?? {}) };
|
|
296
|
+
const checkRoutes = (problem) => {
|
|
297
|
+
for (const [name, route] of Object.entries(routes))
|
|
298
|
+
for (const alias of Object.values(route))
|
|
299
|
+
if (!Object.hasOwn(entries, alias))
|
|
300
|
+
throw new Error(`runtime.routes.${name} names ${problem(alias)}`);
|
|
301
|
+
};
|
|
302
|
+
checkRoutes((alias) => `unknown alias '${alias}'`);
|
|
303
|
+
if (project?.enabled) {
|
|
304
|
+
const unknown = project.enabled.find((a) => !Object.hasOwn(entries, a));
|
|
305
|
+
if (unknown !== undefined)
|
|
306
|
+
throw new Error(`runtime.enabled names unknown alias '${unknown}'`);
|
|
307
|
+
for (const alias of Object.keys(entries))
|
|
308
|
+
if (!project.enabled.includes(alias))
|
|
309
|
+
delete entries[alias];
|
|
310
|
+
if (Object.keys(entries).length === 0)
|
|
311
|
+
throw new Error('runtime.enabled leaves no runtime');
|
|
312
|
+
checkRoutes((alias) => `alias '${alias}', which the project's runtime.enabled removes`);
|
|
313
|
+
}
|
|
314
|
+
const has = (alias) => alias !== undefined && Object.hasOwn(entries, alias);
|
|
315
|
+
if (project?.default !== undefined && !has(project.default))
|
|
316
|
+
throw new Error(`runtime.default names unavailable alias '${project.default}'`);
|
|
317
|
+
const presetAlias = preset && has(preset.id) ? preset.id : undefined;
|
|
318
|
+
const fallback = has('system') ? 'system' : undefined;
|
|
319
|
+
const dflt = [
|
|
320
|
+
routes.default?.['*'],
|
|
321
|
+
project?.default,
|
|
322
|
+
presetAlias,
|
|
323
|
+
fallback,
|
|
324
|
+
Object.keys(entries)[0],
|
|
325
|
+
].find(has);
|
|
326
|
+
return {
|
|
327
|
+
slot: 'runtime',
|
|
328
|
+
entries,
|
|
329
|
+
default: dflt,
|
|
330
|
+
routes,
|
|
331
|
+
...(machine?.select ? { select: machine.select } : {}),
|
|
332
|
+
...(project?.default !== undefined
|
|
333
|
+
? { projectDefault: project.default }
|
|
334
|
+
: {}),
|
|
335
|
+
...(presetAlias ? { preset: presetAlias } : {}),
|
|
336
|
+
...(fallback ? { fallback } : {}),
|
|
337
|
+
};
|
|
338
|
+
}
|
|
265
339
|
function isRecord(value) {
|
|
266
340
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
267
341
|
}
|
|
@@ -370,10 +444,13 @@ export async function loadConductorConfig(configFile) {
|
|
|
370
444
|
const discovered = narrowConductorContributions(await discoverScoped(effectiveAddons, 'conductor', { agentGlobals }));
|
|
371
445
|
const wired = resolveConductorSlots(discovered);
|
|
372
446
|
// The schema has checked the shape; the list is the project's alone.
|
|
373
|
-
const
|
|
374
|
-
|
|
375
|
-
const
|
|
376
|
-
|
|
447
|
+
const projectRuntime = config.runtime;
|
|
448
|
+
const readOnly = projectRuntime?.read_only;
|
|
449
|
+
const runtimes = await loadRuntimeCatalog(wired.runtime, machineCtx.runtime, projectRuntime, machineBases).catch((error) => {
|
|
450
|
+
throw new Error(`${configPath}: ${error.message}`);
|
|
451
|
+
});
|
|
452
|
+
const defaultRuntime = runtimes.entries[runtimes.default];
|
|
453
|
+
if (Object.values(runtimes.entries).some((r) => r.isolates)) {
|
|
377
454
|
try {
|
|
378
455
|
assertProtectedEntryPoints(config.hooks, readOnly ?? []);
|
|
379
456
|
}
|
|
@@ -385,13 +462,17 @@ export async function loadConductorConfig(configFile) {
|
|
|
385
462
|
// Unlike the inbox, a broken or ambiguous tool set stops the conductor.
|
|
386
463
|
// Tools load first so inbox bindings can be checked against them.
|
|
387
464
|
const provisioning = provisionRuns();
|
|
465
|
+
const runtimeIsolation = new Map();
|
|
388
466
|
const toolSets = [
|
|
389
467
|
...discovered.addonTools,
|
|
390
468
|
...provisionTools(config.hooks?.provision_up, provisioning, {
|
|
391
469
|
...(config.hooks?.provision_exec
|
|
392
470
|
? { exec: config.hooks.provision_exec }
|
|
393
471
|
: {}),
|
|
394
|
-
|
|
472
|
+
// A run dispatched before a restart is not in the map; an isolating
|
|
473
|
+
// run always has a run clone, a host run never.
|
|
474
|
+
isolates: (worktreePath) => runtimeIsolation.get(worktreePath) ??
|
|
475
|
+
loadRunClone(worktreePath) !== undefined,
|
|
395
476
|
}),
|
|
396
477
|
];
|
|
397
478
|
let agentCatalog;
|
|
@@ -550,6 +631,8 @@ export async function loadConductorConfig(configFile) {
|
|
|
550
631
|
default_agent: defaultAgent,
|
|
551
632
|
routes,
|
|
552
633
|
};
|
|
634
|
+
if (typeof config.select_agent === 'function')
|
|
635
|
+
console.warn("select_agent in the project config is deprecated; the machine config's select replaces it.");
|
|
553
636
|
return {
|
|
554
637
|
...(remote ? { remote } : {}),
|
|
555
638
|
slot_sources: slotSources,
|
|
@@ -560,13 +643,29 @@ export async function loadConductorConfig(configFile) {
|
|
|
560
643
|
disabled_agents: disabled,
|
|
561
644
|
default_agent: defaultAgent,
|
|
562
645
|
routes,
|
|
646
|
+
catalogs: {
|
|
647
|
+
agent: {
|
|
648
|
+
slot: 'agent',
|
|
649
|
+
entries: Object.fromEntries(candidates.map((candidate) => [candidate.alias, candidate])),
|
|
650
|
+
default: defaultAgent,
|
|
651
|
+
routes,
|
|
652
|
+
...(policy?.select ? { select: policy.select } : {}),
|
|
653
|
+
},
|
|
654
|
+
runtime: runtimes,
|
|
655
|
+
executor: singleEntryCatalog('executor', [executor]),
|
|
656
|
+
workspace: singleEntryCatalog('workspace', [workspace]),
|
|
657
|
+
},
|
|
658
|
+
...(machineCtx.runtime?.allow_unsandboxed === true
|
|
659
|
+
? { allow_unsandboxed: true }
|
|
660
|
+
: {}),
|
|
661
|
+
runtime_isolation: runtimeIsolation,
|
|
563
662
|
...(typeof config.select_agent === 'function'
|
|
564
663
|
? {
|
|
565
664
|
selectAgent: config.select_agent,
|
|
566
665
|
}
|
|
567
666
|
: {}),
|
|
568
667
|
workspace,
|
|
569
|
-
...(
|
|
668
|
+
...(defaultRuntime !== hostRuntime ? { runtime: defaultRuntime } : {}),
|
|
570
669
|
...(readOnly ? { readOnly } : {}),
|
|
571
670
|
marketplaces,
|
|
572
671
|
hookListeners,
|
package/dist/src/contract.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { AmbiguousProjectNameError, type ResolvedBbProjectContext, resolveBbProjectContext, } from './bakers-project-context.js';
|
|
2
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
|
-
export { ensureHome, homeKey, homePath, type MarketplaceDeclaration, validateMarketplaces, } from './plugins/agent-home.js';
|
|
4
|
+
export { ensureHome, homeKey, homePath, lock, 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';
|
|
6
6
|
export type { DiscoveredInbox, InboxBinding, InboxMessageHandler, InboxMessageRequest, InboxMessages, LoadedInbox, } from './plugins/message.js';
|
|
7
7
|
export { loadInbox, validateRequestPayload, } from './plugins/message.js';
|
package/dist/src/contract.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
export { AmbiguousProjectNameError, resolveBbProjectContext, } from './bakers-project-context.js';
|
|
15
15
|
export { CONDUCTOR_TOKEN_ENV, CONDUCTOR_TOOL_TIMEOUT_MS, CONDUCTOR_TOOLS_SERVER, CONDUCTOR_URL_ENV, DEFAULT_ENV_DENY, emptyAgentFootprint, matchesEnvDeny, } from './plugins/agent.js';
|
|
16
16
|
export { detectKnownOverrides, resolveAgentCliOptions, resolveSecurityOptions, SECURITY_MODES, SHARED_SECURITY_KEY, validateAgentArgs, validateOptionalBoolean, validateOptionalString, validateSharedSecurity, } from './plugins/agent-args.js';
|
|
17
|
-
export { ensureHome, homeKey, homePath, validateMarketplaces, } from './plugins/agent-home.js';
|
|
17
|
+
export { ensureHome, homeKey, homePath, lock, validateMarketplaces, } from './plugins/agent-home.js';
|
|
18
18
|
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';
|
|
@@ -54,8 +54,12 @@ export declare class Conductor {
|
|
|
54
54
|
private readonly queue;
|
|
55
55
|
/** The local MCP server for addon tools; only the serve process runs one. */
|
|
56
56
|
private toolServer;
|
|
57
|
-
/** Where runs execute
|
|
58
|
-
private
|
|
57
|
+
/** Where runs execute, chosen per ticket. */
|
|
58
|
+
private readonly runtimes;
|
|
59
|
+
/** One instance per runtime alias, created on first use. */
|
|
60
|
+
private readonly slots;
|
|
61
|
+
/** The runtime alias of each run this process dispatched. */
|
|
62
|
+
private readonly runRuntimes;
|
|
59
63
|
/** Serializes git worktree add/remove: parallel ones fight over git locks. */
|
|
60
64
|
private gitLock;
|
|
61
65
|
/** The last good machine `tunnel` policy, re-read for each run's env. */
|
|
@@ -100,8 +104,19 @@ export declare class Conductor {
|
|
|
100
104
|
* it to the CLI.
|
|
101
105
|
*/
|
|
102
106
|
startTools(endpointFile?: string): Promise<void>;
|
|
103
|
-
private
|
|
104
|
-
/**
|
|
107
|
+
private runtimeFor;
|
|
108
|
+
/** The run's runtime entry; the default for a run this process did not dispatch. */
|
|
109
|
+
private runtimePlugin;
|
|
110
|
+
/**
|
|
111
|
+
* Whether the run isolates. A run this process did not dispatch (before a
|
|
112
|
+
* restart) is read from its worktree: an isolating run always has a run
|
|
113
|
+
* clone, a host run never.
|
|
114
|
+
*/
|
|
115
|
+
private runIsolates;
|
|
116
|
+
/**
|
|
117
|
+
* Best-effort, like the tab close: logged, never thrown. A run of unknown
|
|
118
|
+
* runtime (dispatched before a restart) is cleaned in every entry.
|
|
119
|
+
*/
|
|
105
120
|
private cleanupRuntime;
|
|
106
121
|
/** Tell an open `bakers ui` in the checkout (and the run's worktree) to reload. */
|
|
107
122
|
private signalUi;
|
|
@@ -255,6 +270,8 @@ export declare class Conductor {
|
|
|
255
270
|
* one `plugins` entry. A failed install throws, failing the run start.
|
|
256
271
|
*/
|
|
257
272
|
private installPlugins;
|
|
273
|
+
/** The agent a machine `agents.select` named. */
|
|
274
|
+
private agentFor;
|
|
258
275
|
/** `at.worktree` is set once the workspace exists, so a failure can signal it. */
|
|
259
276
|
private dispatch;
|
|
260
277
|
/**
|
|
@@ -262,6 +279,8 @@ export declare class Conductor {
|
|
|
262
279
|
* (BB-599): its caller unwinds it through `after_run` on any failure.
|
|
263
280
|
*/
|
|
264
281
|
private launch;
|
|
282
|
+
/** The run's slot choices as a run note, and a ticket comment when a label put it on a runtime that does not isolate. Never fails the run. */
|
|
283
|
+
private recordChoices;
|
|
265
284
|
/**
|
|
266
285
|
* Stop what a failed dispatch started (BB-599): the worker if it was
|
|
267
286
|
* launched, then the `after_run` listeners and shell hook. Best-effort — it
|
|
@@ -3,9 +3,10 @@ import { basename, dirname, join } from 'node:path';
|
|
|
3
3
|
import { killRunProcesses, loadRunClone, pickSecrets, 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
|
-
import { resolveAgent } from '../plugins/plugins.js';
|
|
7
|
-
import { hostRuntime } from '../plugins/runtime.js';
|
|
6
|
+
import { agentReason, resolveAgent, } from '../plugins/plugins.js';
|
|
7
|
+
import { hostRuntime, } from '../plugins/runtime.js';
|
|
8
8
|
import { runtimeSandboxWarning, sandboxFailures, } from '../plugins/sandbox-preflight.js';
|
|
9
|
+
import { SlotResolver, selectSlot, } from '../plugins/slot-catalog.js';
|
|
9
10
|
import { loadTools } from '../plugins/tools.js';
|
|
10
11
|
import { ActionQueue } from './action-queue.js';
|
|
11
12
|
import { attemptFamily } from './attempt.js';
|
|
@@ -212,8 +213,12 @@ export class Conductor {
|
|
|
212
213
|
queue;
|
|
213
214
|
/** The local MCP server for addon tools; only the serve process runs one. */
|
|
214
215
|
toolServer;
|
|
215
|
-
/** Where runs execute
|
|
216
|
-
|
|
216
|
+
/** Where runs execute, chosen per ticket. */
|
|
217
|
+
runtimes;
|
|
218
|
+
/** One instance per runtime alias, created on first use. */
|
|
219
|
+
slots = new SlotResolver();
|
|
220
|
+
/** The runtime alias of each run this process dispatched. */
|
|
221
|
+
runRuntimes = new Map();
|
|
217
222
|
/** Serializes git worktree add/remove: parallel ones fight over git locks. */
|
|
218
223
|
gitLock = Promise.resolve();
|
|
219
224
|
/** The last good machine `tunnel` policy, re-read for each run's env. */
|
|
@@ -235,6 +240,19 @@ export class Conductor {
|
|
|
235
240
|
this.readMachine = readMachine;
|
|
236
241
|
this.secrets = secrets;
|
|
237
242
|
this.tunnel = config.tunnel === true;
|
|
243
|
+
// A config built without the loader: its one runtime beside the host.
|
|
244
|
+
const runtime = config.runtime;
|
|
245
|
+
this.runtimes = config.catalogs?.runtime ?? {
|
|
246
|
+
slot: 'runtime',
|
|
247
|
+
entries: {
|
|
248
|
+
system: hostRuntime,
|
|
249
|
+
...(runtime ? { [runtime.id]: runtime } : {}),
|
|
250
|
+
},
|
|
251
|
+
default: runtime?.id ?? 'system',
|
|
252
|
+
routes: {},
|
|
253
|
+
...(runtime ? { preset: runtime.id } : {}),
|
|
254
|
+
fallback: 'system',
|
|
255
|
+
};
|
|
238
256
|
this.inboxAddons = new InboxRuntime(config.inboxAddons ?? [], remote, logger, (ticket) => this.runEnv(ticket, undefined, ticket.state), config.tools);
|
|
239
257
|
this.queue = new ActionQueue(logger);
|
|
240
258
|
}
|
|
@@ -297,10 +315,12 @@ export class Conductor {
|
|
|
297
315
|
*/
|
|
298
316
|
async startTools(endpointFile) {
|
|
299
317
|
const { siteTools } = this.remote;
|
|
300
|
-
const
|
|
318
|
+
const runtimes = await Promise.all(Object.keys(this.runtimes.entries).map((alias) => this.runtimeFor(alias)));
|
|
301
319
|
if ((!this.config.tools && !siteTools) || this.toolServer)
|
|
302
320
|
return;
|
|
303
|
-
const hosts =
|
|
321
|
+
const hosts = [
|
|
322
|
+
...new Set((await Promise.all(runtimes.map((r) => r.toolServerHosts?.() ?? []))).flat()),
|
|
323
|
+
];
|
|
304
324
|
const registry = this.config.tools ?? (await loadTools([]));
|
|
305
325
|
// Runs closed while no server ran (`oven once`, a crash) lose their grant here.
|
|
306
326
|
const openRuns = await this.remote.fetchActiveRuns(this.id).then((runs) => runs.map((r) => r.runUuid), (err) => {
|
|
@@ -320,17 +340,43 @@ export class Conductor {
|
|
|
320
340
|
});
|
|
321
341
|
this.logger.info({ conductorId: this.config.conductor_id, url: this.toolServer.url }, 'tool server started');
|
|
322
342
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
343
|
+
runtimeFor(alias) {
|
|
344
|
+
const plugin = this.runtimes.entries[alias];
|
|
345
|
+
if (!plugin)
|
|
346
|
+
return Promise.reject(new Error(`runtime alias '${alias}' is unknown`));
|
|
347
|
+
return this.slots.instance('runtime', alias, () => plugin.createRuntime(this.config, { logger: this.logger }));
|
|
348
|
+
}
|
|
349
|
+
/** The run's runtime entry; the default for a run this process did not dispatch. */
|
|
350
|
+
runtimePlugin(runUuid) {
|
|
351
|
+
const alias = (runUuid && this.runRuntimes.get(runUuid)) || this.runtimes.default;
|
|
352
|
+
return this.runtimes.entries[alias] ?? hostRuntime;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Whether the run isolates. A run this process did not dispatch (before a
|
|
356
|
+
* restart) is read from its worktree: an isolating run always has a run
|
|
357
|
+
* clone, a host run never.
|
|
358
|
+
*/
|
|
359
|
+
runIsolates(runUuid, worktreePath) {
|
|
360
|
+
if (worktreePath && !(runUuid && this.runRuntimes.has(runUuid)))
|
|
361
|
+
return loadRunClone(worktreePath) !== undefined;
|
|
362
|
+
return this.runtimePlugin(runUuid).isolates === true;
|
|
326
363
|
}
|
|
327
|
-
/**
|
|
364
|
+
/**
|
|
365
|
+
* Best-effort, like the tab close: logged, never thrown. A run of unknown
|
|
366
|
+
* runtime (dispatched before a restart) is cleaned in every entry.
|
|
367
|
+
*/
|
|
328
368
|
async cleanupRuntime(runUuid, runId) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
369
|
+
const known = this.runRuntimes.get(runUuid);
|
|
370
|
+
for (const alias of known ? [known] : Object.keys(this.runtimes.entries)) {
|
|
371
|
+
try {
|
|
372
|
+
await (await this.runtimeFor(alias)).cleanup({
|
|
373
|
+
uuid: runUuid,
|
|
374
|
+
id: runId,
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
catch (err) {
|
|
378
|
+
this.logger.warn({ run: runUuid, runtime: alias, err: String(err) }, 'runtime cleanup failed');
|
|
379
|
+
}
|
|
334
380
|
}
|
|
335
381
|
}
|
|
336
382
|
/** Tell an open `bakers ui` in the checkout (and the run's worktree) to reload. */
|
|
@@ -415,6 +461,8 @@ export class Conductor {
|
|
|
415
461
|
const warning = runtimeSandboxWarning(this.config.runtime?.id);
|
|
416
462
|
if (warning)
|
|
417
463
|
this.logger.warn({ conductorId: this.id }, warning);
|
|
464
|
+
if (Object.keys(this.runtimes.entries).join() === 'system')
|
|
465
|
+
this.logger.info({ conductorId: this.id }, 'no runtime configured; runs start on the host (system)');
|
|
418
466
|
for (const line of await sandboxFailures(this.agents)) {
|
|
419
467
|
this.logger.error({ conductorId: this.id }, line);
|
|
420
468
|
}
|
|
@@ -594,6 +642,9 @@ export class Conductor {
|
|
|
594
642
|
// Revoke before the durable close: a crash between the two must not leave a closed run's grant.
|
|
595
643
|
this.revokeRunTools(r.runUuid);
|
|
596
644
|
await this.remote.finalizeRun(r.runUuid, uploadedLog, captured.metrics);
|
|
645
|
+
this.runRuntimes.delete(r.runUuid);
|
|
646
|
+
if (r.worktreePath)
|
|
647
|
+
this.config.runtime_isolation?.delete(r.worktreePath);
|
|
597
648
|
this.signalUi(r.worktreePath);
|
|
598
649
|
this.logger.info({ run: r.runUuid, state: r.state, footprint: captured.metrics }, 'run finalised');
|
|
599
650
|
}
|
|
@@ -745,7 +796,7 @@ export class Conductor {
|
|
|
745
796
|
worktreePath,
|
|
746
797
|
ticket,
|
|
747
798
|
state: opts.state ?? ticket.state,
|
|
748
|
-
env: await this.runEnv(ticket, opts.run?.uuid, opts.state ?? ticket.state, opts.agent),
|
|
799
|
+
env: await this.runEnv(ticket, opts.run?.uuid, opts.state ?? ticket.state, opts.agent, worktreePath),
|
|
749
800
|
...(opts.run ? { run: opts.run } : {}),
|
|
750
801
|
};
|
|
751
802
|
}
|
|
@@ -1152,7 +1203,7 @@ export class Conductor {
|
|
|
1152
1203
|
* vars. Used at dispatch and, rebuilt from the current ticket, for the
|
|
1153
1204
|
* `after_run` / `after_done` listener contexts (BB-599).
|
|
1154
1205
|
*/
|
|
1155
|
-
async runEnv(t, runUuid, state, agent) {
|
|
1206
|
+
async runEnv(t, runUuid, state, agent, worktreePath) {
|
|
1156
1207
|
// BB-495: the agent names the workspace on its own calls now (the
|
|
1157
1208
|
// dropsh transport stamps none), so it has to know which one it is
|
|
1158
1209
|
// standing in and the full radius it may reach. Reserved core keys
|
|
@@ -1185,7 +1236,9 @@ export class Conductor {
|
|
|
1185
1236
|
...(t.branchName ? { BAKERS_BRANCH_NAME: t.branchName } : {}),
|
|
1186
1237
|
BAKERS_TUNNEL: (await this.currentTunnel()) ? '1' : '0',
|
|
1187
1238
|
// Host scripts skip what an isolated run does in its own container.
|
|
1188
|
-
BAKERS_RUNTIME_ISOLATES: this.
|
|
1239
|
+
BAKERS_RUNTIME_ISOLATES: this.runIsolates(runUuid, worktreePath)
|
|
1240
|
+
? '1'
|
|
1241
|
+
: '0',
|
|
1189
1242
|
WORKSPACE_ROOT: this.checkoutRoot,
|
|
1190
1243
|
...(t.issueUrl ? { TICKET_URL: t.issueUrl } : {}),
|
|
1191
1244
|
...(t.projectName ? { BAKERS_PROJECT: t.projectName } : {}),
|
|
@@ -1239,6 +1292,10 @@ export class Conductor {
|
|
|
1239
1292
|
// that itself errors must not stop the claim loop, so it is swallowed
|
|
1240
1293
|
// (the run then falls back to lease-expiry recovery).
|
|
1241
1294
|
this.logger.error({ run: run.runUuid, err: String(err) }, 'dispatch failed');
|
|
1295
|
+
// A failed dispatch keeps no per-run runtime state behind.
|
|
1296
|
+
this.runRuntimes.delete(run.runUuid);
|
|
1297
|
+
if (at.worktree)
|
|
1298
|
+
this.config.runtime_isolation?.delete(at.worktree);
|
|
1242
1299
|
try {
|
|
1243
1300
|
await this.remote.markFailed(run.runUuid, String(err));
|
|
1244
1301
|
this.signalUi(at.worktree);
|
|
@@ -1278,14 +1335,22 @@ export class Conductor {
|
|
|
1278
1335
|
Object.assign(entry, { state: 'on', hash, home, marketplaces });
|
|
1279
1336
|
let launch;
|
|
1280
1337
|
try {
|
|
1281
|
-
launch = await chosen.agent.installPlugins(marketplaces, home);
|
|
1338
|
+
launch = await chosen.agent.installPlugins(marketplaces, home, pickSecrets(chosen.agent.secretEnv ?? [], this.secrets));
|
|
1339
|
+
// A host install used the person's own config dir, not this home.
|
|
1340
|
+
if (launch.home === 'host') {
|
|
1341
|
+
delete entry.hash;
|
|
1342
|
+
delete entry.home;
|
|
1343
|
+
}
|
|
1282
1344
|
Object.assign(entry, {
|
|
1283
1345
|
outcome: launch.home,
|
|
1284
1346
|
...(launch.trust_bypass?.length
|
|
1285
1347
|
? { trust_bypass: launch.trust_bypass }
|
|
1286
1348
|
: {}),
|
|
1287
1349
|
...(launch.gaps?.length ? { gaps: launch.gaps } : {}),
|
|
1350
|
+
...(launch.warnings?.length ? { warnings: launch.warnings } : {}),
|
|
1288
1351
|
});
|
|
1352
|
+
for (const warning of launch.warnings ?? [])
|
|
1353
|
+
this.logger.warn({ ticket: t.identifier, run: run.runUuid }, warning);
|
|
1289
1354
|
}
|
|
1290
1355
|
catch (err) {
|
|
1291
1356
|
entry.failure = err instanceof Error ? err.message : String(err);
|
|
@@ -1295,17 +1360,46 @@ export class Conductor {
|
|
|
1295
1360
|
log();
|
|
1296
1361
|
return { env: launch.env, args: launch.args };
|
|
1297
1362
|
}
|
|
1363
|
+
/** The agent a machine `agents.select` named. */
|
|
1364
|
+
agentFor(alias) {
|
|
1365
|
+
const agent = this.agents.find((a) => (a.alias ?? a.id) === alias);
|
|
1366
|
+
if (!agent)
|
|
1367
|
+
throw new Error(`agent alias '${alias}' is not loaded`);
|
|
1368
|
+
return agent;
|
|
1369
|
+
}
|
|
1298
1370
|
/** `at.worktree` is set once the workspace exists, so a failure can signal it. */
|
|
1299
1371
|
async dispatch(run, at = {}) {
|
|
1300
1372
|
const t = await this.remote.getTicket(run.ticketUuid);
|
|
1301
1373
|
// Resolve the ticket alias and machine defaults, or the project selection hook.
|
|
1302
1374
|
// Persist the package id below so finalize can choose its transcript parser.
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1375
|
+
// The project's select_agent wins; then the machine's agents select.
|
|
1376
|
+
const agentCatalog = this.config.catalogs?.agent;
|
|
1377
|
+
let agentWhy = 'function';
|
|
1378
|
+
let chosen;
|
|
1379
|
+
if (!this.config.selectAgent && agentCatalog?.select) {
|
|
1380
|
+
const pick = selectSlot(agentCatalog, t);
|
|
1381
|
+
agentWhy = pick.reason;
|
|
1382
|
+
chosen = this.agentFor(pick.alias);
|
|
1383
|
+
}
|
|
1384
|
+
else {
|
|
1385
|
+
chosen = resolveAgent(this.agents, t, {
|
|
1386
|
+
selectAgent: this.config.selectAgent,
|
|
1387
|
+
routes: this.config.routes,
|
|
1388
|
+
defaultAgent: this.config.default_agent,
|
|
1389
|
+
warn: (message) => this.logger.warn({ ticket: t.identifier }, message),
|
|
1390
|
+
});
|
|
1391
|
+
if (!this.config.selectAgent)
|
|
1392
|
+
agentWhy = agentReason(t, chosen.alias ?? chosen.id, this.config.routes);
|
|
1393
|
+
}
|
|
1394
|
+
// An unknown alias throws and fails the run. A label may choose a
|
|
1395
|
+
// runtime that does not isolate only where the machine allows it.
|
|
1396
|
+
const runtime = selectSlot(this.runtimes, t, {
|
|
1397
|
+
labelAllowed: (alias) => this.runtimes.entries[alias]?.isolates === true ||
|
|
1398
|
+
this.config.allow_unsandboxed === true,
|
|
1399
|
+
denied: 'does not isolate runs; ignored (set allow_unsandboxed to allow it)',
|
|
1307
1400
|
warn: (message) => this.logger.warn({ ticket: t.identifier }, message),
|
|
1308
1401
|
});
|
|
1402
|
+
this.runRuntimes.set(run.runUuid, runtime.alias);
|
|
1309
1403
|
// The tick's gate may be stale by now; spawn nothing that cannot start.
|
|
1310
1404
|
const [unavailable] = await sandboxFailures([chosen]);
|
|
1311
1405
|
if (unavailable)
|
|
@@ -1316,7 +1410,12 @@ export class Conductor {
|
|
|
1316
1410
|
// env (BB-99). Reserved core keys always win; values may be sensitive so
|
|
1317
1411
|
// only key names are ever logged.
|
|
1318
1412
|
const env = await this.runEnv(t, run.runUuid, run.stateAtStart, chosen.agent);
|
|
1319
|
-
const
|
|
1413
|
+
const runPlugin = this.runtimePlugin(run.runUuid);
|
|
1414
|
+
const ws = await this.serialGit(() => this.workspace.ensure(t.identifier, t.branchName, baseRef, {
|
|
1415
|
+
clone: runPlugin.isolates === true,
|
|
1416
|
+
// Only a runtime that states `shared` overrides the workspace option.
|
|
1417
|
+
...(runPlugin.shared !== undefined && { shared: runPlugin.shared }),
|
|
1418
|
+
}));
|
|
1320
1419
|
at.worktree = ws.path;
|
|
1321
1420
|
// The transfer checks the project's list; the record is the host's alone.
|
|
1322
1421
|
if (ws.clone)
|
|
@@ -1349,7 +1448,7 @@ export class Conductor {
|
|
|
1349
1448
|
};
|
|
1350
1449
|
const launch = { started: false };
|
|
1351
1450
|
try {
|
|
1352
|
-
await this.launch(run, t, chosen, ws, ctx, launch);
|
|
1451
|
+
await this.launch(run, t, chosen, runtime, agentWhy, ws, ctx, launch);
|
|
1353
1452
|
}
|
|
1354
1453
|
catch (err) {
|
|
1355
1454
|
await this.unwindDispatch(ctx, launch.started);
|
|
@@ -1360,7 +1459,7 @@ export class Conductor {
|
|
|
1360
1459
|
* The part of a dispatch that can leave a sidecar or a worker behind
|
|
1361
1460
|
* (BB-599): its caller unwinds it through `after_run` on any failure.
|
|
1362
1461
|
*/
|
|
1363
|
-
async launch(run, t, chosen, ws, ctx, launch) {
|
|
1462
|
+
async launch(run, t, chosen, runtimeChoice, agentWhy, ws, ctx, launch) {
|
|
1364
1463
|
const env = ctx.env;
|
|
1365
1464
|
// Lifecycle hooks are conductor-owned + best-effort (BB-84): runHook never
|
|
1366
1465
|
// throws, so neither call can abort dispatch or wedge a run in `claimed`.
|
|
@@ -1434,7 +1533,7 @@ export class Conductor {
|
|
|
1434
1533
|
// re-creates it. Sibling prior-state run tabs are left to the worktree reap.
|
|
1435
1534
|
await this.executor.cleanupRun(t.branchName, run.runId);
|
|
1436
1535
|
await this.cleanupRuntime(run.runUuid, run.runId);
|
|
1437
|
-
const runtime = await this.
|
|
1536
|
+
const runtime = await this.runtimeFor(runtimeChoice.alias);
|
|
1438
1537
|
let prompt = ws.instructions
|
|
1439
1538
|
? renderPrompt(this.config.prompt, {
|
|
1440
1539
|
identifier: t.identifier,
|
|
@@ -1506,7 +1605,8 @@ export class Conductor {
|
|
|
1506
1605
|
...(chosen.agent.modelApi ? { modelApi: chosen.agent.modelApi } : {}),
|
|
1507
1606
|
secrets,
|
|
1508
1607
|
};
|
|
1509
|
-
const isolates = this.
|
|
1608
|
+
const isolates = this.runtimePlugin(run.runUuid).isolates === true;
|
|
1609
|
+
this.config.runtime_isolation?.set(ws.path, isolates);
|
|
1510
1610
|
// Without it the run starts in an empty private home and cannot sign in.
|
|
1511
1611
|
if (isolates && !chosen.agent.prepareRun)
|
|
1512
1612
|
throw new Error(`agent ${chosen.alias ?? chosen.id}: the runtime isolates runs, but the agent has no prepareRun to prepare its login and configuration`);
|
|
@@ -1616,9 +1716,14 @@ export class Conductor {
|
|
|
1616
1716
|
harness: chosen.agent.id,
|
|
1617
1717
|
alias: chosen.alias ?? chosen.id,
|
|
1618
1718
|
runtime: runtime.id,
|
|
1719
|
+
runtimeAlias: runtimeChoice.alias,
|
|
1720
|
+
runtimeReason: runtimeChoice.reason,
|
|
1721
|
+
agentReason: agentWhy,
|
|
1722
|
+
conductorOwner: t.conductorOwner ?? 'unknown',
|
|
1619
1723
|
// The launch with its options; the prompt is long and in the ticket.
|
|
1620
1724
|
launch: command.replace(shellQuote(prompt), "'<prompt>'"),
|
|
1621
1725
|
}, 'dispatched run');
|
|
1726
|
+
await this.recordChoices(run.runUuid, t, chosen.alias ?? chosen.id, agentWhy, runtimeChoice, this.runtimePlugin(run.runUuid).isolates === true);
|
|
1622
1727
|
// The conductor — not the agent — knows the per-run git worktree path, so
|
|
1623
1728
|
// it persists `worktree_path` to bb_run here alongside the running state.
|
|
1624
1729
|
// It also persists the chosen agent id (BB-144) for finalize footprint
|
|
@@ -1630,6 +1735,30 @@ export class Conductor {
|
|
|
1630
1735
|
});
|
|
1631
1736
|
this.signalUi(ws.path);
|
|
1632
1737
|
}
|
|
1738
|
+
/** The run's slot choices as a run note, and a ticket comment when a label put it on a runtime that does not isolate. Never fails the run. */
|
|
1739
|
+
async recordChoices(runUuid, t, agent, agentWhy, runtime, isolates) {
|
|
1740
|
+
const owner = t.conductorOwner
|
|
1741
|
+
? `conductor owner ${t.conductorOwner}`
|
|
1742
|
+
: 'conductor owner unknown';
|
|
1743
|
+
try {
|
|
1744
|
+
await this.remote.appendRunNote(runUuid, `agent ${agent} (${agentWhy}); runtime ${runtime.alias} (${runtime.reason}); ${owner}`);
|
|
1745
|
+
}
|
|
1746
|
+
catch (err) {
|
|
1747
|
+
this.logger.warn({ ticket: t.identifier, err: String(err) }, 'run note write failed');
|
|
1748
|
+
}
|
|
1749
|
+
if (isolates || runtime.reason !== 'label' || !this.remote.siteTools)
|
|
1750
|
+
return;
|
|
1751
|
+
try {
|
|
1752
|
+
await this.remote.siteTools.call('bakers_comment_create', {
|
|
1753
|
+
ticket: t.identifier,
|
|
1754
|
+
type: 'comment',
|
|
1755
|
+
body: `Run ${runUuid} uses runtime '${runtime.alias}', chosen by the label ${runtime.label ?? `runtime:${runtime.alias}`}; it is unsandboxed (does not isolate the run). ${owner}.`,
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1758
|
+
catch (err) {
|
|
1759
|
+
this.logger.warn({ ticket: t.identifier, err: String(err) }, 'unsandboxed comment failed');
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1633
1762
|
/**
|
|
1634
1763
|
* Stop what a failed dispatch started (BB-599): the worker if it was
|
|
1635
1764
|
* launched, then the `after_run` listeners and shell hook. Best-effort — it
|
|
@@ -1656,6 +1785,7 @@ export class Conductor {
|
|
|
1656
1785
|
catch (err) {
|
|
1657
1786
|
this.logger.warn({ run: runUuid, err: String(err) }, 'dispatch cleanup failed');
|
|
1658
1787
|
}
|
|
1788
|
+
this.runRuntimes.delete(runUuid);
|
|
1659
1789
|
}
|
|
1660
1790
|
async serve(signal) {
|
|
1661
1791
|
await this.pollLoop(signal);
|
|
@@ -14,6 +14,8 @@ export declare function validateMarketplaces(value: unknown): MarketplaceDeclara
|
|
|
14
14
|
export declare function homeKey(marketplaces: MarketplaceDeclaration[]): string;
|
|
15
15
|
/** `~/.cache/bakers/agent-homes/<harness>/<key>`, outside the sandbox-hidden `~/.bakers`. */
|
|
16
16
|
export declare function homePath(harness: string, key: string): string;
|
|
17
|
+
/** Take `<home>.lock`; a lock whose owner process is gone is taken over. */
|
|
18
|
+
export declare function lock(path: string): Promise<() => void>;
|
|
17
19
|
/**
|
|
18
20
|
* Make `path` a complete agent home: `reused` when a previous build finished,
|
|
19
21
|
* else `build(path)` runs under the lock and the home is `built`. A failed
|
|
@@ -62,7 +62,7 @@ function alive(pid) {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
/** Take `<home>.lock`; a lock whose owner process is gone is taken over. */
|
|
65
|
-
async function lock(path) {
|
|
65
|
+
export async function lock(path) {
|
|
66
66
|
const file = `${path}.lock`;
|
|
67
67
|
const owner = `${process.pid}:${Math.random()}`;
|
|
68
68
|
for (;;) {
|
|
@@ -100,8 +100,13 @@ export interface PluginLaunch {
|
|
|
100
100
|
env: Record<string, string>;
|
|
101
101
|
/** Passed to `launchCommand` as its `args`. */
|
|
102
102
|
args: string[];
|
|
103
|
-
/**
|
|
104
|
-
|
|
103
|
+
/**
|
|
104
|
+
* `built` when this call built the home, `reused` when it was complete,
|
|
105
|
+
* `host` when the run uses the person's own config dir instead.
|
|
106
|
+
*/
|
|
107
|
+
home: 'built' | 'reused' | 'host';
|
|
108
|
+
/** Differences from the declaration left unchanged, logged at run start. */
|
|
109
|
+
warnings?: string[];
|
|
105
110
|
/** Trust checks this run skips, for the run's `plugins` log entry. */
|
|
106
111
|
trust_bypass?: string[];
|
|
107
112
|
/** Declared plugins the harness cannot load, for the same entry. */
|
|
@@ -164,7 +169,9 @@ export interface BbAgent extends AgentRuntimeInfo {
|
|
|
164
169
|
* launches. Called before every launch, in every security mode. Throws,
|
|
165
170
|
* naming the plugin and the harness output, when the install fails.
|
|
166
171
|
*/
|
|
167
|
-
installPlugins?(marketplaces: readonly MarketplaceDeclaration[], home: string
|
|
172
|
+
installPlugins?(marketplaces: readonly MarketplaceDeclaration[], home: string,
|
|
173
|
+
/** The run's picked {@link secretEnv} values, for a token login. */
|
|
174
|
+
secrets?: Readonly<Record<string, string>>): Promise<PluginLaunch>;
|
|
168
175
|
/**
|
|
169
176
|
* How the conductor treats ticket/project env_vars whose names match
|
|
170
177
|
* `deny`: dropped when `drop`, kept (and still logged) otherwise. Omitted →
|
|
@@ -5,6 +5,7 @@ import type { BbAgent } from './agent.js';
|
|
|
5
5
|
import type { SecurityMode, SecurityReport } from './agent-args.js';
|
|
6
6
|
import type { BbExecutor } from './executor.js';
|
|
7
7
|
import type { BbRemote, Ticket } from './remote.js';
|
|
8
|
+
import type { SlotChoice } from './slot-catalog.js';
|
|
8
9
|
import type { BbWorkspace } from './workspace.js';
|
|
9
10
|
/** Runtime dependencies handed to a plugin factory at selection time. */
|
|
10
11
|
export interface ExecutorDeps {
|
|
@@ -101,3 +102,8 @@ export declare function resolveAgent(candidates: ResolvedAgent[], ticket: Ticket
|
|
|
101
102
|
routes?: AgentRoutes;
|
|
102
103
|
defaultAgent?: string;
|
|
103
104
|
}): ResolvedAgent;
|
|
105
|
+
/**
|
|
106
|
+
* Why `resolveAgent` chose `alias`, in selectSlot's vocabulary. Pure; the
|
|
107
|
+
* choice itself is never re-derived, so a surprise here only mislabels a note.
|
|
108
|
+
*/
|
|
109
|
+
export declare function agentReason(ticket: Ticket, alias: string, routes?: AgentRoutes): SlotChoice['reason'];
|
|
@@ -121,3 +121,26 @@ export function resolveAgent(candidates, ticket, options = {}) {
|
|
|
121
121
|
}
|
|
122
122
|
return selectAgent(candidates, ticket);
|
|
123
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Why `resolveAgent` chose `alias`, in selectSlot's vocabulary. Pure; the
|
|
126
|
+
* choice itself is never re-derived, so a surprise here only mislabels a note.
|
|
127
|
+
*/
|
|
128
|
+
export function agentReason(ticket, alias, routes = {}) {
|
|
129
|
+
for (const label of ticket.labels) {
|
|
130
|
+
if (!label.startsWith('agent:'))
|
|
131
|
+
continue;
|
|
132
|
+
const [name, state] = label.slice('agent:'.length).split('@');
|
|
133
|
+
if (!name || (state !== undefined && state !== ticket.state))
|
|
134
|
+
continue;
|
|
135
|
+
const via = Object.hasOwn(routes, name)
|
|
136
|
+
? (routes[name]?.[ticket.state] ?? routes[name]?.['*'])
|
|
137
|
+
: name;
|
|
138
|
+
if (via === alias)
|
|
139
|
+
return 'label';
|
|
140
|
+
}
|
|
141
|
+
if (routes.default?.[ticket.state] === alias)
|
|
142
|
+
return 'route';
|
|
143
|
+
if (routes.default?.['*'] === alias)
|
|
144
|
+
return 'default-route';
|
|
145
|
+
return 'fallback';
|
|
146
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AgentRoutes } from '@bakers-build/core';
|
|
2
|
+
import type { Ticket } from './remote.js';
|
|
3
|
+
export type SlotName = 'agent' | 'runtime' | 'workspace' | 'executor';
|
|
4
|
+
export interface SlotCatalog<P> {
|
|
5
|
+
slot: SlotName;
|
|
6
|
+
entries: Record<string, P>;
|
|
7
|
+
default: string;
|
|
8
|
+
/** Named routes (`name -> state|'*' -> alias`); `default` is the catalog-wide route. */
|
|
9
|
+
routes: AgentRoutes;
|
|
10
|
+
/** Machine function replacing the whole order. */
|
|
11
|
+
select?: (candidates: string[], ticket: Ticket) => string;
|
|
12
|
+
projectDefault?: string;
|
|
13
|
+
preset?: string;
|
|
14
|
+
fallback?: string;
|
|
15
|
+
}
|
|
16
|
+
export type SlotChoice = {
|
|
17
|
+
alias: string;
|
|
18
|
+
reason: 'label' | 'function' | 'route' | 'default-route' | 'project' | 'preset' | 'fallback';
|
|
19
|
+
/** The ticket label that chose the entry, for reason `label`. */
|
|
20
|
+
label?: string;
|
|
21
|
+
};
|
|
22
|
+
/** Order, first hit wins: label (alias or named route), machine route for the state, default route (`*`), project, preset, fallback. */
|
|
23
|
+
export declare function selectSlot<P>(c: SlotCatalog<P>, t: Ticket, o?: {
|
|
24
|
+
labelAllowed?: (alias: string) => boolean;
|
|
25
|
+
/** Why a refused label's entry is refused, ending the warning after "which". */
|
|
26
|
+
denied?: string;
|
|
27
|
+
warn?: (m: string) => void;
|
|
28
|
+
}): SlotChoice;
|
|
29
|
+
/** One instance promise per `slot/alias`, so preflights run once per entry. */
|
|
30
|
+
export declare class SlotResolver {
|
|
31
|
+
private readonly cache;
|
|
32
|
+
instance<I>(slot: SlotName, alias: string, build: () => Promise<I>): Promise<I>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** Order, first hit wins: label (alias or named route), machine route for the state, default route (`*`), project, preset, fallback. */
|
|
2
|
+
export function selectSlot(c, t, o = {}) {
|
|
3
|
+
const aliases = Object.keys(c.entries);
|
|
4
|
+
const known = (alias, where) => {
|
|
5
|
+
if (!Object.hasOwn(c.entries, alias)) {
|
|
6
|
+
throw new Error(`${t.identifier}: ${c.slot} ${where} names unknown alias '${alias}'`);
|
|
7
|
+
}
|
|
8
|
+
return alias;
|
|
9
|
+
};
|
|
10
|
+
if (c.select) {
|
|
11
|
+
let alias;
|
|
12
|
+
try {
|
|
13
|
+
alias = c.select(aliases, t);
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
throw new Error(`${t.identifier}: ${c.slot} select failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
alias: known(alias, `select returned '${alias}'; it`),
|
|
20
|
+
reason: 'function',
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const prefix = `${c.slot}:`;
|
|
24
|
+
const scoped = [];
|
|
25
|
+
const general = [];
|
|
26
|
+
for (const label of t.labels.filter((l) => l.startsWith(prefix))) {
|
|
27
|
+
const [alias, state, extra] = label.slice(prefix.length).split('@');
|
|
28
|
+
if (!alias || extra !== undefined) {
|
|
29
|
+
throw new Error(`${t.identifier}: malformed ${c.slot} label '${label}'`);
|
|
30
|
+
}
|
|
31
|
+
if (state === t.state)
|
|
32
|
+
scoped.push([alias, label]);
|
|
33
|
+
else if (state === undefined)
|
|
34
|
+
general.push([alias, label]);
|
|
35
|
+
}
|
|
36
|
+
const warn = o.warn ?? console.warn;
|
|
37
|
+
for (const [name, label] of [...scoped, ...general]) {
|
|
38
|
+
let alias = name;
|
|
39
|
+
if (!Object.hasOwn(c.entries, name)) {
|
|
40
|
+
const route = name !== 'default' && Object.hasOwn(c.routes, name)
|
|
41
|
+
? c.routes[name]
|
|
42
|
+
: undefined;
|
|
43
|
+
if (!route)
|
|
44
|
+
throw new Error(`${t.identifier}: ${c.slot} label names unknown alias '${name}'`);
|
|
45
|
+
const viaRoute = route[t.state] ?? route['*'];
|
|
46
|
+
if (viaRoute === undefined) {
|
|
47
|
+
warn(`${t.identifier}: ${c.slot} route '${name}' has no entry for '${t.state}' or '*'; ignored`);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
alias = known(viaRoute, `route '${name}'`);
|
|
51
|
+
}
|
|
52
|
+
if (o.labelAllowed && !o.labelAllowed(alias)) {
|
|
53
|
+
warn(o.denied
|
|
54
|
+
? `${t.identifier}: ${c.slot} label '${name}' chooses ${c.slot} '${alias}', which ${o.denied}`
|
|
55
|
+
: `${t.identifier}: ${c.slot} label '${name}' is not allowed; ignored`);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
return { alias, reason: 'label', label };
|
|
59
|
+
}
|
|
60
|
+
const machine = c.routes.default?.[t.state];
|
|
61
|
+
if (machine !== undefined)
|
|
62
|
+
return { alias: known(machine, "route 'default'"), reason: 'route' };
|
|
63
|
+
const dflt = c.routes.default?.['*'];
|
|
64
|
+
if (dflt !== undefined)
|
|
65
|
+
return { alias: known(dflt, "route 'default'"), reason: 'default-route' };
|
|
66
|
+
if (c.projectDefault !== undefined)
|
|
67
|
+
return { alias: c.projectDefault, reason: 'project' };
|
|
68
|
+
if (c.preset !== undefined)
|
|
69
|
+
return { alias: c.preset, reason: 'preset' };
|
|
70
|
+
return { alias: c.fallback ?? c.default, reason: 'fallback' };
|
|
71
|
+
}
|
|
72
|
+
/** One instance promise per `slot/alias`, so preflights run once per entry. */
|
|
73
|
+
export class SlotResolver {
|
|
74
|
+
cache = new Map();
|
|
75
|
+
instance(slot, alias, build) {
|
|
76
|
+
const key = `${slot}/${alias}`;
|
|
77
|
+
let p = this.cache.get(key);
|
|
78
|
+
if (!p) {
|
|
79
|
+
p = build();
|
|
80
|
+
this.cache.set(key, p);
|
|
81
|
+
// A failed build (e.g. a daemon not up yet) is retried by the next run.
|
|
82
|
+
p.catch(() => this.cache.delete(key));
|
|
83
|
+
}
|
|
84
|
+
return p;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -92,8 +92,8 @@ export declare function provisionRuns(timeoutMs?: number): ProvisionRuns;
|
|
|
92
92
|
export interface ProvisionOptions {
|
|
93
93
|
/** `hooks.provision_exec`: commands by key. */
|
|
94
94
|
exec?: Record<string, ProvisionExecCommand>;
|
|
95
|
-
/** Whether the runtime isolates
|
|
96
|
-
isolates?: boolean;
|
|
95
|
+
/** Whether the run's runtime isolates, or how to read it per worktree; exported to every host command. */
|
|
96
|
+
isolates?: boolean | ((worktreePath: string) => boolean);
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* The core `provision_up(profile?)` and `provision_exec(key, args?)` tools,
|
|
@@ -60,7 +60,11 @@ export function provisionTools(hook, runs = provisionRuns(), options = {}) {
|
|
|
60
60
|
// What a host script needs instead of asking Git in a workspace without one.
|
|
61
61
|
const envFor = (worktreePath) => ({
|
|
62
62
|
BAKERS_WORKTREE_PATH: worktreePath,
|
|
63
|
-
BAKERS_RUNTIME_ISOLATES: options.isolates
|
|
63
|
+
BAKERS_RUNTIME_ISOLATES: (typeof options.isolates === 'function'
|
|
64
|
+
? options.isolates(worktreePath)
|
|
65
|
+
: options.isolates)
|
|
66
|
+
? '1'
|
|
67
|
+
: '0',
|
|
64
68
|
});
|
|
65
69
|
const report = ({ exitCode, output }) => {
|
|
66
70
|
const text = `exit ${exitCode}\n${output}`;
|
|
@@ -45,8 +45,15 @@ export interface BbWorkspace {
|
|
|
45
45
|
* run (fresh worktree, or no recorded success for this one — BB-663).
|
|
46
46
|
* Lifecycle-hook invocation is NOT a workspace responsibility — the
|
|
47
47
|
* conductor runs all hooks.
|
|
48
|
+
*
|
|
49
|
+
* `options.clone`, when given, overrides the build-time clone mode for this
|
|
50
|
+
* call: the conductor passes whether the run's runtime isolates and shares objects. A workspace
|
|
51
|
+
* without run clones may ignore it.
|
|
48
52
|
*/
|
|
49
|
-
ensure(identifier: string, branch?: string, baseRef?: string
|
|
53
|
+
ensure(identifier: string, branch?: string, baseRef?: string, options?: {
|
|
54
|
+
clone?: boolean;
|
|
55
|
+
shared?: boolean;
|
|
56
|
+
}): Promise<EnsuredWorkspace>;
|
|
50
57
|
/**
|
|
51
58
|
* Tear down the branch's worktree, reclaiming its disk. Called by the
|
|
52
59
|
* conductor's ticket-cleanup pass once a ticket is done, after `after_done`,
|
package/dist/src/types.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type { LoadedInbox } from './plugins/message.js';
|
|
|
8
8
|
import type { AgentCandidate, ExecutorPlugin, RemotePlugin, ResolvedAgent, WorkspacePlugin } from './plugins/plugins.js';
|
|
9
9
|
import type { Ticket } from './plugins/remote.js';
|
|
10
10
|
import type { RuntimePlugin } from './plugins/runtime.js';
|
|
11
|
+
import type { SlotCatalog } from './plugins/slot-catalog.js';
|
|
11
12
|
import type { ProvisionHook, ProvisionRuns, ToolRegistry } from './plugins/tools.js';
|
|
12
13
|
/** Normalized single conductor. */
|
|
13
14
|
export interface ConductorSettings {
|
|
@@ -114,10 +115,21 @@ export interface ConductorFileConfig extends ConductorSettings {
|
|
|
114
115
|
disabled_agents: string[];
|
|
115
116
|
default_agent: string;
|
|
116
117
|
routes: AgentRoutes;
|
|
118
|
+
catalogs: {
|
|
119
|
+
agent: SlotCatalog<AgentCandidate>;
|
|
120
|
+
/** Absent: `runtime` alone, beside the built-in `system`. */
|
|
121
|
+
runtime?: SlotCatalog<RuntimePlugin>;
|
|
122
|
+
executor?: SlotCatalog<ExecutorPlugin>;
|
|
123
|
+
workspace?: SlotCatalog<WorkspacePlugin>;
|
|
124
|
+
};
|
|
125
|
+
/** Machine `runtime.allow_unsandboxed`: a label may choose a runtime that does not isolate. */
|
|
126
|
+
allow_unsandboxed?: boolean;
|
|
127
|
+
/** Whether the run in a worktree isolates, by worktree path; provision tools read it. */
|
|
128
|
+
runtime_isolation?: Map<string, boolean>;
|
|
117
129
|
/** Replaces the shipped label/default resolution for this project. */
|
|
118
130
|
selectAgent?: (candidates: ResolvedAgent[], ticket: Ticket) => ResolvedAgent;
|
|
119
131
|
workspace: WorkspacePlugin;
|
|
120
|
-
/**
|
|
132
|
+
/** The default runtime entry; the workspace reads it. Absent means on the host. */
|
|
121
133
|
runtime?: RuntimePlugin;
|
|
122
134
|
/** The project's `runtime.read_only`: paths an isolated run sees read-only. */
|
|
123
135
|
readOnly?: string[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/conductor",
|
|
3
|
-
"version": "0.11.1-next.
|
|
3
|
+
"version": "0.11.1-next.4",
|
|
4
4
|
"description": "bakers.build conductor engine + CLI: registers, claims tickets via JSON:API, dispatches agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@dropsh/plugin-jsonapi-schema": "^0.8.2",
|
|
34
34
|
"@dropsh/plugin-oauth2": "^0.8.2",
|
|
35
|
-
"@bakers-build/core": "^0.11.1-next.
|
|
36
|
-
"@bakers-build/message": "^0.11.1-next.
|
|
35
|
+
"@bakers-build/core": "^0.11.1-next.4",
|
|
36
|
+
"@bakers-build/message": "^0.11.1-next.4",
|
|
37
37
|
"@modelcontextprotocol/sdk": "1.32.1",
|
|
38
38
|
"commander": "^12.1.0",
|
|
39
39
|
"dropsh": "^0.8.2"
|
|
40
40
|
},
|
|
41
41
|
"bakersBuild": {
|
|
42
|
-
"commit": "
|
|
42
|
+
"commit": "567bf12252184152b86d67a8a083d09755d29e0b",
|
|
43
43
|
"channel": "next"
|
|
44
44
|
}
|
|
45
45
|
}
|