@bakers-build/conductor 0.8.1-next.4 → 0.8.1-next.5

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.
@@ -144,7 +144,7 @@ function validateHookListeners(value) {
144
144
  for (const [index, listener] of value.entries()) {
145
145
  if (!isRecord(listener))
146
146
  throw new Error(`hooks[${index}] must be a listener object`);
147
- for (const slot of HOOK_SLOTS) {
147
+ for (const slot of [...HOOK_SLOTS, 'before_conductor_start']) {
148
148
  if (listener[slot] !== undefined && typeof listener[slot] !== 'function')
149
149
  throw new Error(`hooks[${index}].${slot} must be a function`);
150
150
  }
@@ -520,6 +520,9 @@ export async function loadConductorConfig(configFile) {
520
520
  ...(config.hooks?.provision_up !== undefined ? { provisioning } : {}),
521
521
  bakers,
522
522
  ...identityOf(machineCtx, project, variant),
523
+ ...(machineCtx.connection_url !== undefined
524
+ ? { connection_url: machineCtx.connection_url }
525
+ : {}),
523
526
  variant,
524
527
  project,
525
528
  states,
@@ -2,7 +2,7 @@ export { AmbiguousProjectNameError, type ResolvedBbProjectContext, resolveBbProj
2
2
  export { type AgentFootprint, type AgentRunIdentity, type BbAgent, CONDUCTOR_TOKEN_ENV, CONDUCTOR_TOOLS_SERVER, CONDUCTOR_URL_ENV, DEFAULT_ENV_DENY, emptyAgentFootprint, matchesEnvDeny, type PluginLaunch, 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
- export type { BbExecutor, ExecutorCapabilities, HookContext, HookListener, HookListenerContext, HookListenerFn, HookName, HookResult, OpenWorkspaceContext, SpawnedSession, SpawnRunInput, WorktreeTeardown, } from './plugins/executor.js';
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';
8
8
  export type { AgentCandidate, AgentPlugin, ExecutorDeps, ExecutorPlugin, RemotePlugin, ResolvedAgent, WorkspacePlugin, } from './plugins/plugins.js';
@@ -12,6 +12,7 @@ import { shellHookRunner } from './hook-runner.js';
12
12
  import { InboxRuntime, runInbox } from './inbox-runtime.js';
13
13
  import { measureMrChanges, mrChangesRows } from './mr-changes.js';
14
14
  import { checkRequiredSkills } from './required-skills.js';
15
+ import { runStartHooks } from './start-hooks.js';
15
16
  import { startToolServer } from './tool-server.js';
16
17
  import { signalUi } from './ui-signal.js';
17
18
  function sleep(ms, signal) {
@@ -338,7 +339,44 @@ export class Conductor {
338
339
  }
339
340
  }
340
341
  async start() {
341
- this.uuid = await this.remote.registerConductor(this.registration());
342
+ const registration = this.registration();
343
+ const machine = this.ownsServeProcess
344
+ ? await runStartHooks(this.config.hookListeners ?? [], {
345
+ ...(registration.host_key !== undefined
346
+ ? { host_key: registration.host_key }
347
+ : {}),
348
+ ...(registration.machine_label !== undefined
349
+ ? { machine_label: registration.machine_label }
350
+ : {}),
351
+ ...(this.config.connection_url !== undefined
352
+ ? { connection_url: this.config.connection_url }
353
+ : {}),
354
+ }, {
355
+ id: registration.id,
356
+ project: registration.project,
357
+ variant: registration.conductor_name ?? this.config.variant,
358
+ }, (reason) => this.logger.warn({ conductorId: this.id }, reason))
359
+ : {};
360
+ try {
361
+ this.uuid = await this.remote.registerConductor({
362
+ ...registration,
363
+ ...machine,
364
+ });
365
+ }
366
+ catch (err) {
367
+ if (typeof machine.connection_url !== 'string')
368
+ throw err;
369
+ // A server that refuses the address must not stop the start; without
370
+ // the field the stored address stays unchanged.
371
+ // Value-free: the error may quote the address.
372
+ this.logger.warn({ conductorId: this.id }, 'registration failed with the connection URL; retrying without it');
373
+ const rest = { ...machine };
374
+ delete rest.connection_url;
375
+ this.uuid = await this.remote.registerConductor({
376
+ ...registration,
377
+ ...rest,
378
+ });
379
+ }
342
380
  this.logger.info({ conductorId: this.id, uuid: this.uuid, project: this.config.project }, 'conductor started');
343
381
  try {
344
382
  await this.inboxAddons.register(this.id);
@@ -0,0 +1,3 @@
1
+ import type { ConductorStartContext, HookListener, MachineRegistrationData } from '../plugins/executor.js';
2
+ /** Dispatch atomically: failures retain the validated baseline, never partial data. */
3
+ export declare function runStartHooks(listeners: readonly HookListener[], machine: MachineRegistrationData, conductor: Readonly<ConductorStartContext>, warn: (reason: string) => void): Promise<MachineRegistrationData>;
@@ -0,0 +1,58 @@
1
+ import { isValidMachineConnectionUrl } from '@bakers-build/core';
2
+ /** Dispatch atomically: failures retain the validated baseline, never partial data. */
3
+ export async function runStartHooks(listeners, machine, conductor, warn) {
4
+ const baseline = { ...machine };
5
+ if (baseline.connection_url !== undefined &&
6
+ baseline.connection_url !== null &&
7
+ !isValidMachineConnectionUrl(baseline.connection_url)) {
8
+ delete baseline.connection_url;
9
+ warn('invalid manual connection URL; start hooks skipped');
10
+ return baseline;
11
+ }
12
+ const shared = { ...baseline };
13
+ const context = Object.freeze({ ...conductor });
14
+ let closed = false;
15
+ let timer;
16
+ const validate = () => {
17
+ if (Reflect.ownKeys(shared).some((key) => !['host_key', 'machine_label', 'connection_url'].includes(String(key))) ||
18
+ shared.host_key !== baseline.host_key ||
19
+ (shared.machine_label !== undefined &&
20
+ (typeof shared.machine_label !== 'string' ||
21
+ !shared.machine_label.trim() ||
22
+ shared.machine_label.length > 255)) ||
23
+ (shared.connection_url !== undefined &&
24
+ shared.connection_url !== null &&
25
+ !isValidMachineConnectionUrl(shared.connection_url)) ||
26
+ (baseline.connection_url !== undefined &&
27
+ shared.connection_url !== baseline.connection_url))
28
+ throw new Error('invalid start hook data');
29
+ };
30
+ try {
31
+ return await Promise.race([
32
+ (async () => {
33
+ for (const listener of listeners) {
34
+ await listener.before_conductor_start?.(shared, context);
35
+ if (closed)
36
+ return baseline;
37
+ validate();
38
+ }
39
+ validate();
40
+ return { ...shared };
41
+ })(),
42
+ new Promise((_, reject) => {
43
+ timer = setTimeout(() => {
44
+ closed = true;
45
+ reject(new Error('deadline'));
46
+ }, 5000);
47
+ }),
48
+ ]);
49
+ }
50
+ catch {
51
+ warn('start hooks discarded after failure, invalid data or timeout');
52
+ return baseline;
53
+ }
54
+ finally {
55
+ closed = true;
56
+ clearTimeout(timer);
57
+ }
58
+ }
@@ -57,6 +57,16 @@ export interface HookListenerContext {
57
57
  }
58
58
  /** A listener's callback for one slot. Awaited; a failure is logged, never fatal. */
59
59
  export type HookListenerFn = (ctx: HookListenerContext) => void | Promise<void>;
60
+ export interface MachineRegistrationData {
61
+ host_key?: string;
62
+ machine_label?: string;
63
+ connection_url?: string | null;
64
+ }
65
+ export interface ConductorStartContext {
66
+ id: string;
67
+ project: string;
68
+ variant: string;
69
+ }
60
70
  /**
61
71
  * One addon contribution to the conductor `hooks` accumulator (BB-599): an
62
72
  * object with an optional function per lifecycle slot. Listeners run in
@@ -65,6 +75,7 @@ export type HookListenerFn = (ctx: HookListenerContext) => void | Promise<void>;
65
75
  export type HookListener = {
66
76
  [K in HookName]?: HookListenerFn;
67
77
  } & {
78
+ before_conductor_start?: (machine: MachineRegistrationData, conductor: Readonly<ConductorStartContext>) => void | Promise<void>;
68
79
  /** Names the listener in conductor logs. */
69
80
  id?: string;
70
81
  };
@@ -15,6 +15,7 @@ export interface ConductorRegistration {
15
15
  host_key?: string;
16
16
  /** This machine's display label; names a newly created bb_machine. */
17
17
  machine_label?: string;
18
+ connection_url?: string | null;
18
19
  project: string;
19
20
  /** Empty = serve all claimable states in the project (BB-207). */
20
21
  states: string[];
@@ -22,6 +22,7 @@ export interface ConductorSettings {
22
22
  variant: string;
23
23
  /** This machine's display label (`machine.config.js` label). */
24
24
  machine_label?: string;
25
+ connection_url?: string | null;
25
26
  /** Project name (bb_project.name); resolved at registration. */
26
27
  project: string;
27
28
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/conductor",
3
- "version": "0.8.1-next.4",
3
+ "version": "0.8.1-next.5",
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.8.1-next.4",
36
- "@bakers-build/message": "^0.8.1-next.4",
35
+ "@bakers-build/core": "^0.8.1-next.5",
36
+ "@bakers-build/message": "^0.8.1-next.5",
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": "ba56bec9e0a2d128491f52088a07061938e77832",
42
+ "commit": "0a852637a4317a2ba18e831a2dcee4be2e67d060",
43
43
  "channel": "next"
44
44
  }
45
45
  }