@bakers-build/conductor 0.19.1-next.6 → 0.19.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,4 +1,4 @@
1
- import { type BbCommandHost, type BbCommandPlugin, type ConductorLogger, type ProcProbe, type UpdateCheckOptions } from '@bakers-build/core';
1
+ import { type BbCommandHost, type BbCommandPlugin, type ConductorLiveness, type ConductorLogger, type ProcProbe, type UpdateCheckOptions } from '@bakers-build/core';
2
2
  import { Command } from 'commander';
3
3
  import { watchForRestart } from '../core/self-restart.js';
4
4
  import type { BbExecutor } from '../plugins/executor.js';
@@ -75,6 +75,36 @@ export interface BbCliDeps {
75
75
  migrateConfig?: () => Promise<string | undefined>;
76
76
  }
77
77
  type Execve = (file: string, args: string[], env: NodeJS.ProcessEnv) => void;
78
+ /**
79
+ * The liveness words, owned by core.
80
+ *
81
+ * The per-config freshness threshold that used to live here is gone with the
82
+ * registry: core applies the same stale window as the server-side deriver and
83
+ * additionally honours the lease, which is the more accurate signal a
84
+ * hand-tuned `lease_seconds * 2` was approximating.
85
+ */
86
+ type StatusLabel = ConductorLiveness;
87
+ /**
88
+ * The liveness words this CLI prints.
89
+ *
90
+ * Delegated to core so `bakers conductor ls`, the cockpit and the server-side
91
+ * deriver describe one conductor identically. The previous CLI-only vocabulary
92
+ * (`wedged`, `stopped`, `host-missing`, `registry-only`) went with the registry
93
+ * that made those distinctions expressible.
94
+ *
95
+ * BB-473: `deriveConductorLiveness` MUST NOT change — it also classifies
96
+ * REMOTE conductors this machine cannot probe. This function additionally
97
+ * probes the LOCAL pid, when both `thisHostKey` is given and it is this
98
+ * conductor's own host (`hub.hostKey === thisHostKey`) with a positive
99
+ * `lastPid` on record. `verifyConductorProcess` (the read-only half of the
100
+ * pid-signal proof; BB-450 D1) either leaves the record's word alone
101
+ * (host-mismatch / no-pid / an unverifiable platform, or a genuinely live,
102
+ * verified pid) or, on `stale-pid` — the process is provably gone or was
103
+ * recycled by something else — overrides it to `offline`: positive proof the
104
+ * process is gone beats a lease-derived guess. The printed word always stays
105
+ * one of `online | stale | offline` — no fourth word is invented.
106
+ */
107
+ export declare function classify(hub: ConductorStatus, thisHostKey?: string, probe?: ProcProbe): StatusLabel;
78
108
  /**
79
109
  * Start-time auth gate. Returns true if authenticated (session or session-less
80
110
  * provider); otherwise logs a single clear line and returns false.
@@ -1,9 +1,9 @@
1
1
  import { execFile, spawnSync } from 'node:child_process';
2
- import { mkdirSync } from 'node:fs';
2
+ import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
3
3
  import { basename, dirname, join, resolve, sep } from 'node:path';
4
4
  import { createInterface } from 'node:readline';
5
5
  import { promisify } from 'node:util';
6
- import { addonEnvSources, CommandRunner, checkForUpdate, configHomeOf, createBbConnectionClient, createLogger, declineUpdate, defaultProcProbe, deriveCheckoutRoot, deriveConductorLiveness, envsDir, homeBbDir, loadEnvFiles, loadReadyBbConnection, printVersionLine, readCliVersion, readMachineContext, resolveCliVersion, resolveConfigPath, secretsFilePath, setDefaultCommandRunner, signalVerifiedProcess, stemForConfigFile, UNKNOWN_VERSION, updateNotice, verifyConductorProcess, } from '@bakers-build/core';
6
+ import { addonEnvSources, CommandRunner, checkForUpdate, configHomeOf, createBbConnectionClient, createLogger, declineUpdate, defaultProcProbe, deriveCheckoutRoot, deriveConductorLiveness, envsDir, homeBbDir, loadEnvFiles, loadReadyBbConnection, printVersionLine, readCliVersion, readMachineContext, resolveCliVersion, resolveConfigPath, secretsFilePath, setDefaultCommandRunner, signalVerifiedProcess, stemForConfigFile, stopMarkerOf, UNKNOWN_VERSION, updateNotice, verifyConductorProcess, } from '@bakers-build/core';
7
7
  import { Command } from 'commander';
8
8
  import { authStatus } from 'dropsh';
9
9
  import { resolveBbProjectContext } from '../bakers-project-context.js';
@@ -12,6 +12,7 @@ import { Conductor, registrationOf } from '../core/conductor.js';
12
12
  import { watchForRestart } from '../core/self-restart.js';
13
13
  import { selectAgents, selectExecutor, selectRemote, selectWorkspace, } from '../plugins/plugins.js';
14
14
  import { runtimeSandboxWarning, sandboxFailures, } from '../plugins/sandbox-preflight.js';
15
+ import { readDaemonState } from '../process/daemon-state.js';
15
16
  import { spawnDetachedConductor, } from '../process/detached-spawn.js';
16
17
  import { ovenTools } from './oven-tools.js';
17
18
  /**
@@ -210,7 +211,7 @@ function loggerFor(checkoutRoot, log = {}) {
210
211
  * process is gone beats a lease-derived guess. The printed word always stays
211
212
  * one of `online | stale | offline` — no fourth word is invented.
212
213
  */
213
- function classify(hub, thisHostKey, probe) {
214
+ export function classify(hub, thisHostKey, probe) {
214
215
  const recordDerived = deriveConductorLiveness(hub, Math.floor(Date.now() / 1000));
215
216
  if (!thisHostKey ||
216
217
  hub.hostKey !== thisHostKey ||
@@ -249,6 +250,7 @@ async function buildLsRows(remote, config, onlyId, probe) {
249
250
  label: c.label,
250
251
  workspaceRoot: c.workspaceRoot,
251
252
  status: classify(c, thisHostKey, probe),
253
+ autostart: c.autostart,
252
254
  }));
253
255
  }
254
256
  function printRows(rows) {
@@ -257,7 +259,7 @@ function printRows(rows) {
257
259
  return;
258
260
  }
259
261
  for (const r of rows) {
260
- console.log(`${r.label}\t${r.status}\t${r.project}\t${r.workspaceRoot}\t${r.id}`);
262
+ console.log(`${r.label}\t${r.status}\t${r.project}\t${r.workspaceRoot}\t${r.autostart ? 'yes' : 'no'}\t${r.id}`);
261
263
  }
262
264
  }
263
265
  // --- command handlers -------------------------------------------------------
@@ -409,6 +411,11 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
409
411
  const config = await resolveConfig(deps, undefined, true);
410
412
  const checkoutRoot = await checkoutRootOf(config);
411
413
  const logger = loggerFor(checkoutRoot, log);
414
+ // A supervisor reads this as "stopped on purpose, do not restart"; a start clears it.
415
+ const stoppedMarker = stopMarkerOf(checkoutRoot, registrationOf(config, checkoutRoot).conductor_name);
416
+ // A daemon restarts the process on exit 75, so no execve is needed; a
417
+ // daemon stopped or removed since the spawn restarts nothing.
418
+ const supervised = () => process.env.BAKERS_SUPERVISED === '1' && readDaemonState() === 'running';
412
419
  const execve = deps.execve ?? process.execve?.bind(process);
413
420
  const reExec = (env) => execve?.(process.execPath, [process.execPath, ...process.execArgv, ...process.argv.slice(1)], env);
414
421
  // Run cleanup SIGTERMs every process whose environ holds the run's marker.
@@ -434,6 +441,8 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
434
441
  const thisHostKey = config.host_key?.trim() ?? '';
435
442
  if (await refuseIfAlreadyRunning(remote, id, thisHostKey, force, deps))
436
443
  return;
444
+ // After the takeover: a process replaced by --force writes its marker as it exits.
445
+ rmSync(stoppedMarker, { force: true });
437
446
  // This process is the conductor: its takeover registration carries its pid.
438
447
  const serve = {
439
448
  ...registrationOf(config, checkoutRoot),
@@ -455,9 +464,11 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
455
464
  const controller = new AbortController();
456
465
  let restart = false;
457
466
  let reason = 'serve ended';
467
+ let signalled = false;
458
468
  // A stop wins over a restart already decided: `oven stop` must stay a stop.
459
469
  const onSignal = (signal) => {
460
470
  restart = false;
471
+ signalled = true;
461
472
  reason = signal;
462
473
  logger.info({ signal }, `stopping on ${signal}`);
463
474
  controller.abort();
@@ -520,7 +531,7 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
520
531
  for (const level of ['project', 'runtime', 'agent'])
521
532
  mkdirSync(join(envsDir(), level), { recursive: true, mode: 0o700 });
522
533
  if (config.restart_on_change !== false && config.watch_paths) {
523
- if (!execve) {
534
+ if (!execve && !supervised()) {
524
535
  logger.warn({ node: process.version }, 'restart_on_change needs process.execve (Node >= 22.15); the conductor does not restart itself on config changes');
525
536
  }
526
537
  else {
@@ -615,7 +626,7 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
615
626
  logger.warn({ from: startVersion, to: read }, `${changed}; restart_on_change is off, restart with \`${prefix} oven start --force\``);
616
627
  return;
617
628
  }
618
- if (!execve) {
629
+ if (!execve && !supervised()) {
619
630
  logger.error({ from: startVersion, to: read, node: process.version }, `${changed}; restarting needs process.execve (Node >= 22.15), restart with \`${prefix} oven start --force\``);
620
631
  return;
621
632
  }
@@ -666,6 +677,9 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
666
677
  // out must still exit, and the reaper flips it on lease expiry anyway.
667
678
  // A self-restart skips it: the same conductor id comes straight back.
668
679
  if (!restart) {
680
+ // First: the offline call below may hang or fail.
681
+ if (signalled)
682
+ writeFileSync(stoppedMarker, '');
669
683
  try {
670
684
  await remote.setConductorStatus(conductor.id, 'offline');
671
685
  }
@@ -675,6 +689,11 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
675
689
  }
676
690
  logger.info({ reason }, 'conductor stopped');
677
691
  }
692
+ if (restart && supervised()) {
693
+ logger.info({ reason }, `restart requested; exiting for supervisor (${reason})`);
694
+ process.exitCode = 75;
695
+ return;
696
+ }
678
697
  // Same pid and log.
679
698
  if (restart)
680
699
  reExec(process.env);
@@ -48,6 +48,12 @@ export { findBbDir, resolveConfigPath, } from '@bakers-build/core';
48
48
  * No semicolon in the text: the freshness test cuts the initializer at the first one.
49
49
  */
50
50
  export declare const DEFAULT_AGENT_PROMPT: string;
51
+ /**
52
+ * Resolve a slot value: a descriptor is constructed via `loadNamedPlugin`, an
53
+ * already-constructed plugin passes straight through (backward-compat). Either
54
+ * way the kind-guard runs, so a wrong-target descriptor still errors.
55
+ */
56
+ export declare function resolveSlot<T>(value: unknown, kind: string, configPath: string): Promise<T>;
51
57
  /**
52
58
  * Resolve the `agent` slot into candidate(s), **preserving the authored shape**:
53
59
  * a single descriptor/plugin/wrapper → a single `AgentCandidate`, an array →
@@ -306,7 +306,7 @@ async function loadNamedPlugin(entry, configPath) {
306
306
  * already-constructed plugin passes straight through (backward-compat). Either
307
307
  * way the kind-guard runs, so a wrong-target descriptor still errors.
308
308
  */
309
- async function resolveSlot(value, kind, configPath) {
309
+ export async function resolveSlot(value, kind, configPath) {
310
310
  const resolved = isPluginDescriptor(value)
311
311
  ? await loadNamedPlugin(value, configPath)
312
312
  : value;
@@ -9,6 +9,7 @@ import { hostRuntime, } from '../plugins/runtime.js';
9
9
  import { runtimeSandboxWarning, sandboxFailures, } from '../plugins/sandbox-preflight.js';
10
10
  import { SlotResolver, selectSlot, } from '../plugins/slot-catalog.js';
11
11
  import { loadTools } from '../plugins/tools.js';
12
+ import { readDaemonState } from '../process/daemon-state.js';
12
13
  import { ActionQueue } from './action-queue.js';
13
14
  import { attemptFamily } from './attempt.js';
14
15
  import { shellHookRunner } from './hook-runner.js';
@@ -189,6 +190,7 @@ export function registrationOf(config, checkoutRoot) {
189
190
  label: config.label,
190
191
  ...(config.machine_label ? { machine_label: config.machine_label } : {}),
191
192
  conductor_name: stem ?? config.variant,
193
+ daemon: readDaemonState(),
192
194
  };
193
195
  }
194
196
  export class Conductor {
@@ -22,6 +22,7 @@ export const SITE_TOOLS = [
22
22
  'bakers_user_search',
23
23
  'bakers_team_members',
24
24
  'bakers_conductor_list',
25
+ 'bakers_conductor_update',
25
26
  ];
26
27
  /** The site tools that change a ticket; a successful call signals `bakers ui`. */
27
28
  export const SITE_WRITE_TOOLS = [
@@ -1,6 +1,9 @@
1
1
  export type * from '@bakers-build/core';
2
2
  export { BB_CONFIG_SCHEMA_VERSION, readConfigSchemaVersion, } from './cli/config-schema.js';
3
- export { type BbCliDeps, default as conductorCommandPlugin, runConductorCli, } from './commands/conductor.js';
3
+ export { type BbCliDeps, classify, default as conductorCommandPlugin, runConductorCli, } from './commands/conductor.js';
4
4
  export { composeConductorConfig, DEFAULT_AGENT_PROMPT, loadConductorConfig, resolveConfigPath, stripLegacyConnectionFromConfigSource, } from './config.js';
5
5
  export * from './contract.js';
6
6
  export { Conductor } from './core/conductor.js';
7
+ export { daemonStatePath, readDaemonState } from './process/daemon-state.js';
8
+ export { type DetachedChild, type DetachedSpawnRequest, spawnDetachedConductor, } from './process/detached-spawn.js';
9
+ export { machineRemote } from './process/machine-remote.js';
package/dist/src/index.js CHANGED
@@ -4,7 +4,7 @@ export { BB_CONFIG_SCHEMA_VERSION, readConfigSchemaVersion, } from './cli/config
4
4
  // BB-201: the conductor is now a COMMAND PLUGIN mounted by the `@bakers-build/bakers`
5
5
  // host, not the CLI entrypoint. `main`/`runBbCli` are gone; the default export
6
6
  // is the `BbCommandPlugin`, exposed here as `./commands/conductor` too.
7
- export { default as conductorCommandPlugin, runConductorCli, } from './commands/conductor.js';
7
+ export { classify, default as conductorCommandPlugin, runConductorCli, } from './commands/conductor.js';
8
8
  // BB-218: the balanced strip is exported for the host/tests + reuse.
9
9
  export { composeConductorConfig, DEFAULT_AGENT_PROMPT, loadConductorConfig, resolveConfigPath, stripLegacyConnectionFromConfigSource, } from './config.js';
10
10
  // BB-224 (Finding 6): this package now OWNS the conductor-surface contract —
@@ -18,3 +18,7 @@ export { composeConductorConfig, DEFAULT_AGENT_PROMPT, loadConductorConfig, reso
18
18
  // re-exported: the engine must not edge an addon (acyclic layer rule).
19
19
  export * from './contract.js';
20
20
  export { Conductor } from './core/conductor.js';
21
+ // The daemon addon's machine-scope halves: its state file and its remote.
22
+ export { daemonStatePath, readDaemonState } from './process/daemon-state.js';
23
+ export { spawnDetachedConductor, } from './process/detached-spawn.js';
24
+ export { machineRemote } from './process/machine-remote.js';
@@ -43,6 +43,8 @@ export interface ConductorRegistration {
43
43
  */
44
44
  adopt?: string;
45
45
  create_new?: boolean;
46
+ /** The machine daemon's state, reported on each heartbeat; absent leaves the stored value. */
47
+ daemon?: 'none' | 'installed' | 'running';
46
48
  }
47
49
  /**
48
50
  * A registration the control plane refused because this machine, project and
@@ -150,6 +152,8 @@ export interface ConductorStatus {
150
152
  * conductor on another host. Empty when never reported.
151
153
  */
152
154
  hostKey?: string;
155
+ /** Whether the daemon starts this conductor at boot or login. */
156
+ autostart: boolean;
153
157
  }
154
158
  export interface FinalizableRun {
155
159
  runUuid: string;
@@ -0,0 +1,4 @@
1
+ /** The machine daemon's state file: `{ installed, pid, last_exit }`, written by the daemon addon. */
2
+ export declare function daemonStatePath(): string;
3
+ /** What a heartbeat reports as `daemon`: the state file plus a liveness check of its pid. */
4
+ export declare function readDaemonState(alive?: (pid: number) => boolean): 'none' | 'installed' | 'running';
@@ -0,0 +1,33 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { homeBbDir } from '@bakers-build/core';
4
+ /** The machine daemon's state file: `{ installed, pid, last_exit }`, written by the daemon addon. */
5
+ export function daemonStatePath() {
6
+ return join(homeBbDir(), 'daemon.json');
7
+ }
8
+ function pidAlive(pid) {
9
+ try {
10
+ process.kill(pid, 0);
11
+ return true;
12
+ }
13
+ catch (err) {
14
+ // EPERM: the pid exists but belongs to another user.
15
+ return err.code === 'EPERM';
16
+ }
17
+ }
18
+ /** What a heartbeat reports as `daemon`: the state file plus a liveness check of its pid. */
19
+ export function readDaemonState(alive = pidAlive) {
20
+ let state;
21
+ try {
22
+ state = JSON.parse(readFileSync(daemonStatePath(), 'utf8'));
23
+ }
24
+ catch {
25
+ return 'none';
26
+ }
27
+ if (state?.installed !== true)
28
+ return 'none';
29
+ const pid = state.pid;
30
+ return typeof pid === 'number' && pid > 0 && alive(pid)
31
+ ? 'running'
32
+ : 'installed';
33
+ }
@@ -0,0 +1,8 @@
1
+ import { type BbCommandHost } from '@bakers-build/core';
2
+ import type { BbRemote } from '../plugins/remote.js';
3
+ /**
4
+ * The remote of this machine's own connection, with no project: what the
5
+ * daemon lists conductors through. Rejects with a fix hint when the
6
+ * connection or its login is missing, like `ensureAuthenticated`.
7
+ */
8
+ export declare function machineRemote(host?: BbCommandHost): Promise<BbRemote>;
@@ -0,0 +1,28 @@
1
+ import { homeBbDir, loadBbConnectionBootstrap, } from '@bakers-build/core';
2
+ import { authStatus } from 'dropsh';
3
+ import { DEFAULT_SERVER_ADDON, resolveSlot } from '../config.js';
4
+ /**
5
+ * The remote of this machine's own connection, with no project: what the
6
+ * daemon lists conductors through. Rejects with a fix hint when the
7
+ * connection or its login is missing, like `ensureAuthenticated`.
8
+ */
9
+ export async function machineRemote(host = { resolveBases: [import.meta.url] }) {
10
+ // Resolved from the home dir, so a project's connection never applies.
11
+ const connection = await loadBbConnectionBootstrap(host, {
12
+ cwd: homeBbDir(),
13
+ });
14
+ const { base_url } = connection.site;
15
+ const st = await authStatus({
16
+ baseUrl: base_url,
17
+ plugins: connection.plugins,
18
+ });
19
+ if (!st.loggedIn)
20
+ throw new Error(`not logged in against ${base_url} — run 'bakers auth login'`);
21
+ const plugin = await resolveSlot(connection.server ?? { use: DEFAULT_SERVER_ADDON }, 'server', connection.config_path);
22
+ // A remote reads only the connection half of the config; no project is selected.
23
+ // shortcut: one site per daemon, take a site list when a machine serves several sites
24
+ return plugin.createRemote({
25
+ site: connection.site,
26
+ plugins: connection.plugins,
27
+ });
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/conductor",
3
- "version": "0.19.1-next.6",
3
+ "version": "0.19.1-next.7",
4
4
  "description": "bakers.build, the open source AI software factory: conductor engine + CLI: registers, claims tickets via JSON:API, dispatches agents.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -43,14 +43,14 @@
43
43
  "dependencies": {
44
44
  "@dropsh/plugin-jsonapi-schema": "^0.8.2",
45
45
  "@dropsh/plugin-oauth2": "^0.8.2",
46
- "@bakers-build/core": "^0.19.1-next.6",
47
- "@bakers-build/message": "^0.19.1-next.6",
46
+ "@bakers-build/core": "^0.19.1-next.7",
47
+ "@bakers-build/message": "^0.19.1-next.7",
48
48
  "@modelcontextprotocol/sdk": "1.32.1",
49
49
  "commander": "^12.1.0",
50
50
  "dropsh": "^0.8.2"
51
51
  },
52
52
  "bakersBuild": {
53
- "commit": "e60d27717c047e63bb0e68d87b819bb43ae2e703",
53
+ "commit": "fcf15c6f0cb6e8317fdc683ac1638e0b84ed861c",
54
54
  "channel": "next"
55
55
  }
56
56
  }