@bakers-build/conductor 0.9.1-next.5 → 0.9.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.
@@ -1,6 +1,9 @@
1
- import { type ConfigInventoryOptions, type ConfigReport } from '@bakers-build/core';
1
+ import { type AddonCapabilities, type ConfigInventoryOptions, type ConfigReport } from '@bakers-build/core';
2
2
  import { type ConnectionAuthType } from './config-templates.js';
3
+ export { DEFAULT_SLOT_ADDON } from './config-templates.js';
3
4
  export interface ConfigPlanOptions extends ConfigInventoryOptions {
5
+ capabilities?: AddonCapabilities;
6
+ slots?: Partial<Record<'server' | 'executor' | 'worktree', string>>;
4
7
  inputs?: {
5
8
  /** Machine display label; the machine UUID is always generated. */
6
9
  label?: string;
@@ -6,8 +6,10 @@ import { dirname } from 'node:path';
6
6
  import { configRecheckCommand, finalizeConfigReport, inspectConfigSource, inventoryConfig, shellQuote, } from '@bakers-build/core';
7
7
  import { applyMigrations, BB_CONFIG_SCHEMA_VERSION } from './config-schema.js';
8
8
  import { ConfigSourceEditor, redactConfigSource, } from './config-source-edit.js';
9
- import { renderCommittedConfig, renderGlobalConnection, renderHostMachine, } from './config-templates.js';
9
+ import { DEFAULT_SLOT_ADDON, renderCommittedConfig, renderGlobalConnection, renderHostMachine, } from './config-templates.js';
10
10
  import { validateConfigSources } from './config-validation.js';
11
+ // The host reads this addon's capabilities before a fresh project file exists.
12
+ export { DEFAULT_SLOT_ADDON } from './config-templates.js';
11
13
  // Every config file is at schema v1; no migration step exists yet.
12
14
  const CURRENT = {
13
15
  machine: 1,
@@ -30,6 +32,21 @@ function readFingerprint(path) {
30
32
  }
31
33
  /** Inventory, transform in memory, validate the complete proposed installation. */
32
34
  export function planConfig(options = {}) {
35
+ const capabilities = options.capabilities ?? {};
36
+ const selectedSlots = Object.entries(options.slots ?? {});
37
+ if (selectedSlots.length &&
38
+ (options.operation !== 'init' ||
39
+ !['project', 'all'].includes(options.scope ?? '')))
40
+ throw new Error('Slot flags require config init --scope project (or all).');
41
+ for (const [slot, spec] of selectedSlots) {
42
+ const capability = capabilities[spec];
43
+ if (!capability)
44
+ throw new Error(`--${slot}: cannot resolve addon '${spec}'.`);
45
+ if (!capability.scopes.includes('project'))
46
+ throw new Error(`--${slot}: '${spec}' does not allow project scope.`);
47
+ if (!capability.slots.includes(slot))
48
+ throw new Error(`--${slot}: '${spec}' contributes no ${slot}.`);
49
+ }
33
50
  // `conductor` is a bakers.build-specific sub-scope of `project`: it selects the same
34
51
  // files but communicates to the planner that only conductor-config changes are
35
52
  // requested. We map it to `project` for the inventory, which uses a strict
@@ -59,7 +76,7 @@ export function planConfig(options = {}) {
59
76
  const machine = files.find((f) => f.kind === 'machine');
60
77
  const connection = files.find((f) => f.kind === 'connection');
61
78
  if (options.operation === 'check') {
62
- const validated = validateConfigSources(inventoryOptions, new Map(original), files);
79
+ const validated = validateConfigSources(inventoryOptions, new Map(original), files, options.capabilities);
63
80
  return {
64
81
  report: finalizeConfigReport(validated),
65
82
  writes: [],
@@ -448,9 +465,8 @@ export function planConfig(options = {}) {
448
465
  editor(file).stamp(1);
449
466
  }
450
467
  if (file.kind === 'project') {
451
- if ((!e || e.text.trim() === 'export default {};') &&
452
- file.required &&
453
- options.project) {
468
+ const fresh = !e || e.text.trim() === 'export default {};';
469
+ if (fresh && file.required && options.project) {
454
470
  e = new ConfigSourceEditor(renderCommittedConfig({
455
471
  project: options.project,
456
472
  ...(options.inputs?.hooks ? { hooks: options.inputs.hooks } : {}),
@@ -458,6 +474,19 @@ export function planConfig(options = {}) {
458
474
  ? { bakersWorkspace: options.inputs.workspace }
459
475
  : {}),
460
476
  }));
477
+ if (selectedSlots.length) {
478
+ const contributed = new Set(selectedSlots.flatMap(([, spec]) => capabilities[spec]?.slots ?? []));
479
+ if (options.slots?.executor) {
480
+ const entries = Array.from({ length: e.property('addons')?.arrayLength ?? 0 }, (_, index) => `addons[${index}]`);
481
+ e.set('addons', `[${entries
482
+ .filter((key) => (e?.property(`${key}.use`)?.value ??
483
+ e?.property(key)?.value) !== DEFAULT_SLOT_ADDON)
484
+ .map((key) => e?.expression(key))
485
+ .join(', ')}]`);
486
+ }
487
+ for (const slot of contributed)
488
+ e.remove(slot);
489
+ }
461
490
  editors.set(file.path, e);
462
491
  }
463
492
  if (!e)
@@ -465,30 +494,49 @@ export function planConfig(options = {}) {
465
494
  {
466
495
  e = editor(file);
467
496
  fill(file, 'project.name', options.project);
468
- const canonical = new ConfigSourceEditor(renderCommittedConfig({
469
- project: options.project ?? 'project',
470
- }));
471
497
  const addonPackages = new Set([...e.source.properties]
472
498
  .filter(([key]) => /^addons\[\d+\](?:\.use)?$/.test(key))
473
499
  .map(([, property]) => property.value)
474
500
  .filter((value) => typeof value === 'string'));
475
- const providers = {
476
- server: [
477
- '@bakers-build/addon-remote-drupal',
478
- '@bakers-build/addon-fake',
479
- ],
480
- executor: ['@bakers-build/addon-herdr', '@bakers-build/addon-fake'],
481
- worktree: [
482
- '@bakers-build/addon-herdr',
483
- '@bakers-build/addon-fake',
484
- '@bakers-build/addon-workspace-git',
485
- ],
501
+ const existingPackages = [...addonPackages];
502
+ // Text is spliced into addons, so only a literal array can take it.
503
+ const literalAddons = () => {
504
+ const addons = e?.property('addons');
505
+ if (!addons || addons.nodeType === 'ArrayExpression')
506
+ return true;
507
+ problem(file, 'unsupported_source_shape', 'addons', 'A literal addons array is required to add a slot provider.');
508
+ return false;
486
509
  };
487
- for (const slot of ['server', 'executor', 'worktree']) {
510
+ for (const [slot, spec] of selectedSlots) {
488
511
  if (e.property(slot) ||
489
- providers[slot]?.some((provider) => addonPackages.has(provider)))
512
+ existingPackages.some((pkg) => capabilities[pkg]?.slots.includes(slot)))
513
+ continue;
514
+ if (!literalAddons())
515
+ continue;
516
+ if (!addonPackages.has(spec)) {
517
+ const expression = e.expression('addons') ?? '[]';
518
+ const before = expression.slice(0, -1).trimEnd();
519
+ e.set('addons', `${before}${before.endsWith('[') || before.endsWith(',') ? '' : ','} { use: ${JSON.stringify(spec)} }]`);
520
+ addonPackages.add(spec);
521
+ }
522
+ }
523
+ const supplied = (slot) => e?.property(slot) ||
524
+ [...addonPackages].some((pkg) => capabilities[pkg]?.slots.includes(slot) ??
525
+ pkg === DEFAULT_SLOT_ADDON);
526
+ if (options.slots?.executor && !supplied('worktree'))
527
+ problem(file, 'missing_required_key', 'worktree', 'The selected executor supplies no worktree; pass --worktree <package>.');
528
+ // The server comes from the connection; herdr fills a missing executor or worktree.
529
+ for (const slot of ['executor', 'worktree']) {
530
+ if (supplied(slot))
531
+ continue;
532
+ if (slot === 'worktree' && options.slots?.executor)
490
533
  continue;
491
- e.set(slot, canonical.expression(slot));
534
+ if (!literalAddons())
535
+ break;
536
+ const expression = e.expression('addons') ?? '[]';
537
+ const before = expression.slice(0, -1).trimEnd();
538
+ e.set('addons', `${before}${before.endsWith('[') || before.endsWith(',') ? '' : ','} '${DEFAULT_SLOT_ADDON}']`);
539
+ addonPackages.add(DEFAULT_SLOT_ADDON);
492
540
  }
493
541
  if (options.operation === 'init' &&
494
542
  options.inputs?.workspace &&
@@ -550,11 +598,13 @@ export function planConfig(options = {}) {
550
598
  for (const [path] of original)
551
599
  if (!editors.has(path))
552
600
  overlay.set(path, null);
553
- const proposed = validateConfigSources(inventoryOptions, overlay, files);
601
+ const proposed = validateConfigSources(inventoryOptions, overlay, files, options.capabilities);
554
602
  report.findings = [
555
603
  ...errors,
556
604
  ...proposed.findings.filter((f) => !errors.some((e) => e.path === f.path && e.code === f.code && e.key === f.key)),
557
605
  ];
606
+ if (proposed.slot_sources)
607
+ report.slot_sources = proposed.slot_sources;
558
608
  report.verification.skipped = proposed.verification.skipped;
559
609
  const writes = [];
560
610
  for (const file of files.filter((f) => f.selected)) {
@@ -1,4 +1,6 @@
1
- export declare const DEFAULT_CONDUCTOR_AGENT_ADDONS = "[{ use: '@bakers-build/addon-herdr' }, { use: '@bakers-build/addon-claude', alias: 'opus' }]";
1
+ /** Supplies the executor and the worktree slot through its preset. */
2
+ export declare const DEFAULT_SLOT_ADDON = "@bakers-build/addon-herdr";
3
+ export declare const DEFAULT_CONDUCTOR_AGENT_ADDONS = "['@bakers-build/addon-herdr']";
2
4
  export type ConnectionAuthType = 'oauth2_client_credentials' | 'oauth2_device_code';
3
5
  /** Current connection template inputs never come from machine context. */
4
6
  export interface ConnectionInputs {
@@ -1,4 +1,6 @@
1
- export const DEFAULT_CONDUCTOR_AGENT_ADDONS = "[{ use: '@bakers-build/addon-herdr' }, { use: '@bakers-build/addon-claude', alias: 'opus' }]";
1
+ /** Supplies the executor and the worktree slot through its preset. */
2
+ export const DEFAULT_SLOT_ADDON = '@bakers-build/addon-herdr';
3
+ export const DEFAULT_CONDUCTOR_AGENT_ADDONS = `['${DEFAULT_SLOT_ADDON}']`;
2
4
  export function renderGlobalConnection(inputs) {
3
5
  // The device-code grant has no client_secret in @dropsh/plugin-oauth2's
4
6
  // config union, so the key is omitted rather than rendered undefined
@@ -50,10 +52,9 @@ export function renderCommittedConfig(inputs) {
50
52
  // everyone. A conductor is this machine (machine.config.js) + this project +
51
53
  // the variant (project.<name>.config.js). Connections are private files.
52
54
  //
53
- // The slots are \`{ use, export?, with? }\` descriptors naming the published
54
- // package; the loader resolves each name (config dir → cwd → CLI install).
55
- // \`@bakers-build/addon-herdr\` default-exports the executor, so the worktree
56
- // slot names \`export: 'herdrWorkspace'\`.
55
+ // Each addon in \`addons\` fills its slots through its preset: herdr supplies
56
+ // the executor and the worktree. The server comes from the connection,
57
+ // by default @bakers-build/addon-remote-drupal.
57
58
 
58
59
  /** @type {import('@bakers-build/core').ProjectConfig} */
59
60
  export default {
@@ -76,10 +77,7 @@ ${inputs.hooks?.after_create || inputs.hooks?.after_done
76
77
  ]
77
78
  .filter(Boolean)
78
79
  .join(', ')} },\n`
79
- : ''} server: { use: '@bakers-build/addon-remote-drupal' },
80
- executor: { use: '@bakers-build/addon-herdr' },
81
- addons: ${DEFAULT_CONDUCTOR_AGENT_ADDONS},
82
- worktree: { use: '@bakers-build/addon-herdr', export: 'herdrWorkspace' },
80
+ : ''} addons: ${DEFAULT_CONDUCTOR_AGENT_ADDONS},
83
81
  };
84
82
  `;
85
83
  }
@@ -1,12 +1,3 @@
1
- import { type ConfigFileReport, type ConfigInventoryOptions, type ConfigReport } from '@bakers-build/core';
2
- /**
3
- * Known addons and the CONDUCTOR slots each fills. An empty list means "known
4
- * addon, fills no conductor slot" — a UI-only addon (BB-562) belongs in a
5
- * conductor `addons[]` but contributes a cockpit tab, not a slot. Listing it is
6
- * not cosmetic: an UNKNOWN specifier sets `addonsAreOpaque` below, which
7
- * downgrades a genuinely missing server/executor/worktree from
8
- * `missing_required_key` to `unknown_value`.
9
- */
10
- export declare const CONDUCTOR_ADDON_SLOTS: Record<string, string[]>;
1
+ import { type AddonCapabilities, type ConfigFileReport, type ConfigInventoryOptions, type ConfigReport } from '@bakers-build/core';
11
2
  /** Resolve only documented generated wiring and primitive const bindings. Never execute code. */
12
- export declare function validateConfigSources(options: ConfigInventoryOptions, texts: Map<string, string | null>, files: ConfigFileReport[]): ConfigReport;
3
+ export declare function validateConfigSources(options: ConfigInventoryOptions, texts: Map<string, string | null>, files: ConfigFileReport[], capabilities?: AddonCapabilities): ConfigReport;
@@ -1,50 +1,6 @@
1
1
  import { configRecheckCommand, inventoryConfig, shellQuote, } from '@bakers-build/core';
2
2
  import { ConfigSourceEditor } from './config-source-edit.js';
3
- /**
4
- * Known addons and the CONDUCTOR slots each fills. An empty list means "known
5
- * addon, fills no conductor slot" — a UI-only addon (BB-562) belongs in a
6
- * conductor `addons[]` but contributes a cockpit tab, not a slot. Listing it is
7
- * not cosmetic: an UNKNOWN specifier sets `addonsAreOpaque` below, which
8
- * downgrades a genuinely missing server/executor/worktree from
9
- * `missing_required_key` to `unknown_value`.
10
- */
11
- export const CONDUCTOR_ADDON_SLOTS = {
12
- '@bakers-build/addon-remote-drupal': ['server'],
13
- '@bakers-build/addon-herdr': ['executor', 'worktree'],
14
- '@bakers-build/addon-orca': ['executor', 'worktree'],
15
- '@bakers-build/addon-herdr-core': ['executor'],
16
- '@bakers-build/addon-fake': ['server', 'executor', 'worktree'],
17
- '@bakers-build/addon-workspace-git': ['worktree'],
18
- '@bakers-build/addon-claude': ['agent'],
19
- '@bakers-build/addon-codex': ['agent'],
20
- '@bakers-build/addon-grok': ['agent'],
21
- '@bakers-build/addon-kimi': ['agent'],
22
- '@bakers-build/addon-opencode': ['agent'],
23
- '@bakers-build/addon-pi': ['agent'],
24
- '@bakers-build/addon-runtime-docker': ['runtime'],
25
- '@bakers-build/addon-runtime-bwrap': ['runtime'],
26
- '@bakers-build/addon-ports': [],
27
- '@bakers-build/addon-ports-cloudflare': [],
28
- '@bakers-build/addon-ports-cloudflare-quick': [],
29
- '@bakers-build/addon-ports-frp': [],
30
- '@bakers-build/addon-forge': [],
31
- '@bakers-build/addon-forge-github': [],
32
- '@bakers-build/addon-forge-gitlab': [],
33
- '@bakers-build/addon-bakers-ui': [],
34
- '@bakers-build/addon-bakers-ui-artifacts': [],
35
- '@bakers-build/addon-agents': [],
36
- '@bakers-build/addon-auth-basic': [],
37
- '@bakers-build/addon-ddev': [],
38
- '@bakers-build/addon-deployment': [],
39
- '@bakers-build/addon-docker-compose': [],
40
- '@bakers-build/addon-dropsh': [],
41
- '@bakers-build/addon-essentials': [],
42
- '@bakers-build/addon-info': [],
43
- '@bakers-build/addon-name-refs': [],
44
- '@bakers-build/addon-track': [],
45
- '@bakers-build/addon-workspace': [],
46
- };
47
- function validateConductorSources(options, editors, report) {
3
+ function validateConductorSources(options, editors, report, capabilities) {
48
4
  const recheck = configRecheckCommand((options.scope ?? 'all'), report.roots.project);
49
5
  for (const file of report.files.filter((candidate) => candidate.selected && candidate.kind === 'project')) {
50
6
  const editor = editors.get(file.path);
@@ -73,6 +29,7 @@ function validateConductorSources(options, editors, report) {
73
29
  };
74
30
  const addon = editor.property('addons');
75
31
  const addonSlots = new Set();
32
+ const origins = {};
76
33
  let addonsAreOpaque = false;
77
34
  if (addon) {
78
35
  if (addon.nodeType !== 'ArrayExpression')
@@ -85,16 +42,28 @@ function validateConductorSources(options, editors, report) {
85
42
  if (typeof specifier !== 'string')
86
43
  addonsAreOpaque = true;
87
44
  else {
88
- const contributions = CONDUCTOR_ADDON_SLOTS[specifier];
45
+ const contributions = capabilities[specifier]?.slots;
89
46
  if (!contributions)
90
47
  addonsAreOpaque = true;
91
- else
48
+ else {
92
49
  for (const slot of contributions)
93
50
  addonSlots.add(slot);
51
+ for (const contribution of capabilities[specifier]
52
+ ?.contributions ?? [])
53
+ origins[contribution.slot] =
54
+ `${contribution.spec}${contribution.via ? ` (via ${contribution.via})` : ''}`;
55
+ }
94
56
  }
95
57
  }
96
58
  }
59
+ report.slot_sources = origins;
97
60
  for (const slot of ['server', 'executor', 'worktree']) {
61
+ const explicit = editor.property(`${slot}.use`)?.value;
62
+ if (typeof explicit === 'string')
63
+ origins[slot] = explicit;
64
+ // Without one here, the conductor takes the connection's server or the default.
65
+ if (slot === 'server')
66
+ continue;
98
67
  if (editor.property(slot) || addonSlots.has(slot))
99
68
  continue;
100
69
  add(addon && addonsAreOpaque ? 'unknown_value' : 'missing_required_key', slot, `A ${slot} supplied by an explicit slot or a listed addon.`);
@@ -107,7 +76,7 @@ function validateConductorSources(options, editors, report) {
107
76
  }
108
77
  }
109
78
  /** Resolve only documented generated wiring and primitive const bindings. Never execute code. */
110
- export function validateConfigSources(options, texts, files) {
79
+ export function validateConfigSources(options, texts, files, capabilities = {}) {
111
80
  const editors = new Map([...texts]
112
81
  .filter((entry) => entry[1] !== null)
113
82
  .map(([path, text]) => [path, new ConfigSourceEditor(text)]));
@@ -200,7 +169,7 @@ export function validateConfigSources(options, texts, files) {
200
169
  for (const [path, e] of editors)
201
170
  overlay.set(path, e.text);
202
171
  const report = inventoryConfig({ ...options, sourceTexts: overlay }).report;
203
- validateConductorSources(options, editors, report);
172
+ validateConductorSources(options, editors, report, capabilities);
204
173
  // Literal values resolved from generated wiring are not secrets stored in the committed file.
205
174
  report.findings = report.findings.filter((f) => !(f.code === 'misplaced_key' &&
206
175
  f.key?.endsWith('client_secret') &&
@@ -83,7 +83,7 @@ async function resolveConfig(deps, configPathOverride, resolveProject = false) {
83
83
  ? { workspaceSelector: engine.bakers.workspace }
84
84
  : {}),
85
85
  });
86
- return composeConductorConfig(engine, connection);
86
+ return await composeConductorConfig(engine, connection);
87
87
  }
88
88
  const unscoped = await loadReadyBbConnection(host, {
89
89
  workspaceIdOverride: '',
@@ -95,7 +95,7 @@ async function resolveConfig(deps, configPathOverride, resolveProject = false) {
95
95
  workspaceSelector: context.workspaceId,
96
96
  });
97
97
  return {
98
- ...composeConductorConfig(engine, connection),
98
+ ...(await composeConductorConfig(engine, connection)),
99
99
  resolved_bakers: context,
100
100
  };
101
101
  }
@@ -249,6 +249,16 @@ async function cmdPoll(deps, log = {}) {
249
249
  /** `bakers conductor check`: whether each enabled agent can start its sandbox. */
250
250
  async function cmdCheck(deps) {
251
251
  const config = await resolveConfig(deps);
252
+ const sources = config.slot_sources ?? {};
253
+ const packages = config.slot_packages ?? {};
254
+ for (const [slot, plugin] of [
255
+ ['server', config.remote],
256
+ ['executor', config.executor],
257
+ ['worktree', config.workspace],
258
+ ]) {
259
+ const source = sources[slot];
260
+ console.log(`${slot}: ${packages[slot] ?? plugin.id}${source ? ` (${source})` : ''}`);
261
+ }
252
262
  const warning = runtimeSandboxWarning(config.runtime?.id);
253
263
  if (warning)
254
264
  console.warn(`warning: ${warning}`);
@@ -763,14 +773,20 @@ async function cmdStartBody(deps, log, force = false, choice = {}) {
763
773
  // is what tells a genuine new heartbeat apart from the killed conductor's
764
774
  // stale-but-still-in-window one.
765
775
  const priorLastSeen = existing?.lastSeen;
766
- if (existing && classify(existing) === 'online') {
776
+ const probe = deps.procProbe ?? defaultProcProbe();
777
+ // A record online by heartbeat whose pid is provably gone or recycled on
778
+ // this host (same proof as `ls`) is offline: its offline write was lost.
779
+ const recordOnline = existing !== undefined && classify(existing) === 'online';
780
+ if (recordOnline && classify(existing, thisHostKey, probe) !== 'online') {
781
+ console.log(`conductor ${id}: recorded pid ${existing.lastPid} is not running here; starting`);
782
+ }
783
+ else if (recordOnline) {
767
784
  if (!force) {
768
785
  const age = heartbeatAgeSeconds(existing);
769
786
  console.log(`conductor ${id} already running (pid ${existing.lastPid ?? 'unknown'}, ` +
770
787
  `heartbeat ${age === undefined ? 'age unknown' : `${age}s old`})`);
771
788
  return;
772
789
  }
773
- const probe = deps.procProbe ?? defaultProcProbe();
774
790
  const stopOutcome = signalVerifiedProcess({
775
791
  pid: existing.lastPid,
776
792
  hostKey: existing.hostKey,
@@ -80,7 +80,9 @@ export declare function loadConductorConfig(configFile: string): Promise<Conduct
80
80
  * `selectRemote` read them exactly as before — the fields just arrive from
81
81
  * connection file now.
82
82
  */
83
- export declare function composeConductorConfig(engine: ConductorEngineConfig, connection: Pick<BbConnectionConfig, 'site' | 'plugins'>): ConductorFileConfig;
83
+ export declare function composeConductorConfig(engine: ConductorEngineConfig, connection: Pick<BbConnectionConfig, 'site' | 'plugins' | 'config_path'> & Partial<Pick<BbConnectionConfig, 'server'>>): Promise<ConductorFileConfig>;
84
+ /** The server a connection gets when neither it nor the project names one. */
85
+ export declare const DEFAULT_SERVER_ADDON = "@bakers-build/addon-remote-drupal";
84
86
  /**
85
87
  * The conductor variants in a `.bakers/` dir (`conductor` for
86
88
  * `project.config.js`), by the loader's own naming rule.
@@ -5,9 +5,10 @@ import { assertSchemaVersion, assertValidConfig, discoverAddons, discoverScoped,
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
+ import { assertProtectedEntryPoints } from './plugins/host-commands.js';
8
9
  import { loadInbox } from './plugins/message.js';
9
10
  import { narrowConductorContributions, } from './plugins/preset.js';
10
- import { loadTools, provisionRuns, provisionTools } from './plugins/tools.js';
11
+ import { loadTools, provisionRuns, provisionTools, } from './plugins/tools.js';
11
12
  // BB-201: the `.bakers/` walk-up + connection resolution moved to `@bakers-build/core`
12
13
  // (`resolveConfigPath` / `resolveBbConfigPath` / `findBbDir`). Re-export the
13
14
  // engine resolver here so existing conductor callers/tests keep importing it
@@ -172,6 +173,10 @@ function requirePlugin(value, kind) {
172
173
  * "unknown command dropsh" breakage after the @bakers → @bakers-ai scope rename).
173
174
  * Mirror of dropsh 0.4.1 `loadNamedPlugin` / `resolveSlot`.
174
175
  */
176
+ /** The `use` package of each slot value that is a descriptor. */
177
+ function packagesOf(slots) {
178
+ return Object.fromEntries(Object.entries(slots).flatMap(([slot, value]) => isPluginDescriptor(value) ? [[slot, value.use]] : []));
179
+ }
175
180
  function isPluginDescriptor(entry) {
176
181
  return isRecord(entry) && typeof entry.use === 'string';
177
182
  }
@@ -371,22 +376,62 @@ export async function loadConductorConfig(configFile) {
371
376
  ]);
372
377
  const discovered = narrowConductorContributions(await discoverScoped(effectiveAddons, 'conductor', { agentGlobals }));
373
378
  const wired = resolveConductorSlots(discovered);
379
+ // The schema has checked the shape; the list is the project's alone.
380
+ const readOnly = config.runtime
381
+ ?.read_only;
382
+ const isolates = wired.runtime?.isolates === true;
383
+ if (isolates) {
384
+ try {
385
+ assertProtectedEntryPoints(config.hooks, readOnly ?? []);
386
+ }
387
+ catch (error) {
388
+ throw new Error(`${configPath}: ${error.message}`);
389
+ }
390
+ }
374
391
  const hookListeners = validateHookListeners(discovered.hooks);
375
392
  // Unlike the inbox, a broken or ambiguous tool set stops the conductor.
376
393
  // Tools load first so inbox bindings can be checked against them.
377
394
  const provisioning = provisionRuns();
378
395
  const toolSets = [
379
396
  ...discovered.addonTools,
380
- ...provisionTools(config.hooks?.provision_up, provisioning),
397
+ ...provisionTools(config.hooks?.provision_up, provisioning, {
398
+ ...(config.hooks?.provision_exec
399
+ ? { exec: config.hooks.provision_exec }
400
+ : {}),
401
+ isolates,
402
+ }),
381
403
  ];
382
- const tools = toolSets.length > 0 ? await loadTools(toolSets) : undefined;
404
+ let agentCatalog;
405
+ const tools = toolSets.length > 0
406
+ ? await loadTools(toolSets, {
407
+ agentCatalog: () => {
408
+ if (!agentCatalog)
409
+ throw new Error('agent catalog is not resolved yet');
410
+ return agentCatalog;
411
+ },
412
+ })
413
+ : undefined;
383
414
  const inboxAddons = await loadInboxAddons(discovered.addonInbox, new Set(tools?.list().map((t) => t.name)));
415
+ // No server here is fine: composeConductorConfig takes the connection's or the default.
384
416
  const remote = config.server !== undefined
385
417
  ? await resolveSlot(config.server, 'server', configPath)
386
418
  : wired.remote;
387
- if (!remote) {
388
- throw new Error('project config resolves no server — name a server addon in addons[] or set the server slot');
389
- }
419
+ const slotSources = {
420
+ ...(remote
421
+ ? { server: config.server !== undefined ? 'slot' : 'addons' }
422
+ : {}),
423
+ executor: machineCtx.executor !== undefined
424
+ ? 'machine'
425
+ : config.executor !== undefined
426
+ ? 'slot'
427
+ : 'addons',
428
+ worktree: config.worktree !== undefined ? 'slot' : 'addons',
429
+ };
430
+ const slotPackages = packagesOf({
431
+ server: config.server,
432
+ executor: machineCtx.executor ?? config.executor,
433
+ worktree: config.worktree,
434
+ });
390
435
  // The machine may run its own installed tool: its explicit executor wins
391
436
  // over the project's, which wins over the one discovered from addons[].
392
437
  const executor = machineCtx.executor !== undefined
@@ -505,8 +550,17 @@ export async function loadConductorConfig(configFile) {
505
550
  throw new Error(`agents.routes.default names unavailable alias '${defaultAgent}'`);
506
551
  if (!routes.default)
507
552
  routes.default = { '*': defaultAgent };
553
+ agentCatalog = {
554
+ agents: candidates,
555
+ enabled_agents: enabledAgents,
556
+ disabled_agents: disabled,
557
+ default_agent: defaultAgent,
558
+ routes,
559
+ };
508
560
  return {
509
- remote,
561
+ ...(remote ? { remote } : {}),
562
+ slot_sources: slotSources,
563
+ slot_packages: slotPackages,
510
564
  executor,
511
565
  agents: candidates,
512
566
  enabled_agents: enabledAgents,
@@ -520,6 +574,7 @@ export async function loadConductorConfig(configFile) {
520
574
  : {}),
521
575
  workspace,
522
576
  ...(wired.runtime ? { runtime: wired.runtime } : {}),
577
+ ...(readOnly ? { readOnly } : {}),
523
578
  marketplaces,
524
579
  hookListeners,
525
580
  ...(inboxAddons.length > 0 ? { inboxAddons } : {}),
@@ -563,13 +618,36 @@ export async function loadConductorConfig(configFile) {
563
618
  * `selectRemote` read them exactly as before — the fields just arrive from
564
619
  * connection file now.
565
620
  */
566
- export function composeConductorConfig(engine, connection) {
621
+ export async function composeConductorConfig(engine, connection) {
622
+ // The project's server wins, then the connection's, then the Drupal default.
623
+ const descriptor = engine.remote
624
+ ? undefined
625
+ : (connection.server ?? { use: DEFAULT_SERVER_ADDON });
626
+ const [remote, server] = engine.remote
627
+ ? [engine.remote, engine.slot_sources?.server ?? 'slot']
628
+ : connection.server !== undefined
629
+ ? [
630
+ await resolveSlot(connection.server, 'server', connection.config_path),
631
+ 'connection',
632
+ ]
633
+ : [
634
+ await resolveSlot({ use: DEFAULT_SERVER_ADDON }, 'server', engine.config_path),
635
+ 'default',
636
+ ];
567
637
  return {
568
638
  ...engine,
639
+ remote,
640
+ slot_sources: { ...engine.slot_sources, server },
641
+ slot_packages: {
642
+ ...engine.slot_packages,
643
+ ...packagesOf({ server: descriptor }),
644
+ },
569
645
  site: connection.site,
570
646
  ...(connection.plugins.length > 0 ? { plugins: connection.plugins } : {}),
571
647
  };
572
648
  }
649
+ /** The server a connection gets when neither it nor the project names one. */
650
+ export const DEFAULT_SERVER_ADDON = '@bakers-build/addon-remote-drupal';
573
651
  /**
574
652
  * The conductor variants in a `.bakers/` dir (`conductor` for
575
653
  * `project.config.js`), by the loader's own naming rule.
@@ -1,5 +1,5 @@
1
1
  export { AmbiguousProjectNameError, type ResolvedBbProjectContext, resolveBbProjectContext, } from './bakers-project-context.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 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';
@@ -12,6 +12,6 @@ export type { ActiveRun, AddonDefinitionV2, AddonRegistration, BbRemote, Claimed
12
12
  export { ConductorTakeoverRequired } from './plugins/remote.js';
13
13
  export { type BbRuntime, hostRuntime, type RuntimeLaunch, type RuntimePlugin, type RuntimeRun, } from './plugins/runtime.js';
14
14
  export { installCommand, lastLine, type SandboxHost, type SandboxPreflight, sandboxFailures, systemSandboxHost, } from './plugins/sandbox-preflight.js';
15
- 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';
16
16
  export type { BbWorkspace, EnsuredWorkspace, } from './plugins/workspace.js';
17
17
  export type { ConductorEngineConfig, ConductorFileConfig, ConductorSettings, } from './types.js';
@@ -127,6 +127,12 @@ export declare class Conductor {
127
127
  private enqueueFinalize;
128
128
  /** Finalises one run; a failure is logged and retried next tick. */
129
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;
130
136
  /** Read the run's transcript and parse its footprint for the close write. */
131
137
  private captureRun;
132
138
  /**