@bakers-build/conductor 0.10.1-next.15 → 0.10.1-next.16

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.
@@ -2,7 +2,7 @@ import { execFile, spawnSync } from 'node:child_process';
2
2
  import { basename, dirname, join, resolve } from 'node:path';
3
3
  import { createInterface } from 'node:readline';
4
4
  import { promisify } from 'node:util';
5
- import { CommandRunner, checkForUpdate, configHomeOf, createBbConnectionClient, createLogger, declineUpdate, defaultProcProbe, deriveCheckoutRoot, deriveConductorLiveness, homeBbDir, loadReadyBbConnection, loadSecretsFile, printVersionLine, readCliVersion, readMachineContext, resolveCliVersion, resolveConfigPath, setDefaultCommandRunner, signalVerifiedProcess, stemForConfigFile, UNKNOWN_VERSION, updateNotice, verifyConductorProcess, } from '@bakers-build/core';
5
+ import { CommandRunner, checkForUpdate, configHomeOf, createBbConnectionClient, createLogger, declineUpdate, defaultProcProbe, deriveCheckoutRoot, deriveConductorLiveness, homeBbDir, loadReadyBbConnection, loadSecretsFile, printVersionLine, readCliVersion, readMachineContext, resolveCliVersion, resolveConfigPath, secretsFilePath, setDefaultCommandRunner, signalVerifiedProcess, stemForConfigFile, UNKNOWN_VERSION, updateNotice, verifyConductorProcess, } from '@bakers-build/core';
6
6
  import { Command } from 'commander';
7
7
  import { authStatus } from 'dropsh';
8
8
  import { resolveBbProjectContext } from '../bakers-project-context.js';
@@ -435,20 +435,67 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
435
435
  const execve = deps.execve ?? process.execve?.bind(process);
436
436
  let watcher;
437
437
  const check = deps.checkConfig ?? defaultCheckConfig;
438
+ // The restart re-runs loadSecretsOrFail, which exits on a bad file: check first.
439
+ const reloadSecrets = () => {
440
+ try {
441
+ return loadSecretsFile();
442
+ }
443
+ catch (err) {
444
+ logger.error({ path: secretsFilePath() }, `${err.message}; keeping the running conductor on its last good secrets`);
445
+ return undefined;
446
+ }
447
+ };
448
+ // Config changes a bad secrets file held back, re-checked on the next change.
449
+ const heldBack = new Set();
438
450
  const restartNow = () => {
439
451
  restart = true;
440
452
  watcher?.close();
441
453
  clearInterval(versionTimer);
442
454
  controller.abort();
443
455
  };
456
+ // An upgrade replaces the installed files under this running process: once
457
+ // two polls read the same new version, migrate, check and come back on it.
458
+ const startVersion = resolveCliVersion();
459
+ const readVersion = deps.readCliVersion ?? readCliVersion;
460
+ const migrate = deps.migrateConfig ?? defaultMigrateConfig;
461
+ const prefix = process.env.BAKERS_CONDUCTOR
462
+ ? `bakers --conductor ${process.env.BAKERS_CONDUCTOR}`
463
+ : 'bakers';
464
+ let lastRead;
465
+ let settled; // the new version already handled or refused
466
+ let busy = false;
444
467
  if (config.restart_on_change !== false && config.watch_paths) {
445
468
  if (!execve) {
446
469
  logger.warn({ node: process.version }, 'restart_on_change needs process.execve (Node >= 22.15); the conductor does not restart itself on config changes');
447
470
  }
448
471
  else {
449
- watcher = (deps.watchForRestart ?? watchForRestart)(config.watch_paths, async (path) => {
472
+ watcher = (deps.watchForRestart ?? watchForRestart)(config.watch_paths, async (paths) => {
450
473
  if (controller.signal.aborted)
451
474
  return;
475
+ const secretsPath = secretsFilePath();
476
+ for (const p of paths)
477
+ if (p !== secretsPath)
478
+ heldBack.add(p);
479
+ if (!reloadSecrets())
480
+ return;
481
+ const configPaths = [...heldBack];
482
+ heldBack.clear();
483
+ if (!configPaths.length) {
484
+ const read = readVersion();
485
+ if (read !== UNKNOWN_VERSION && read !== startVersion) {
486
+ // A new CLI starts only after migrate and check: retry the upgrade on the next poll.
487
+ settled = undefined;
488
+ logger.info({ path: secretsPath, to: read }, 'secrets file changed; the pending CLI upgrade restarts the conductor');
489
+ return;
490
+ }
491
+ logger.info({ path: secretsPath }, 'secrets file changed; restarting conductor');
492
+ restartNow();
493
+ return;
494
+ }
495
+ const path = [
496
+ ...configPaths,
497
+ ...paths.filter((p) => p === secretsPath),
498
+ ].join(', ');
452
499
  logger.info({ path }, `restart_on_change: ${path} changed; checking config`);
453
500
  const error = await check();
454
501
  // A stop requested while the check ran stays a stop.
@@ -463,17 +510,6 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
463
510
  });
464
511
  }
465
512
  }
466
- // An upgrade replaces the installed files under this running process: once
467
- // two polls read the same new version, migrate, check and come back on it.
468
- const startVersion = resolveCliVersion();
469
- const readVersion = deps.readCliVersion ?? readCliVersion;
470
- const migrate = deps.migrateConfig ?? defaultMigrateConfig;
471
- const prefix = process.env.BAKERS_CONDUCTOR
472
- ? `bakers --conductor ${process.env.BAKERS_CONDUCTOR}`
473
- : 'bakers';
474
- let lastRead;
475
- let settled; // the new version already handled or refused
476
- let busy = false;
477
513
  const versionTimer = setInterval(async () => {
478
514
  if (busy || controller.signal.aborted)
479
515
  return;
@@ -498,6 +534,8 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
498
534
  logger.info({ from: startVersion, to: read }, `${changed}; upgrading config`);
499
535
  busy = true;
500
536
  try {
537
+ if (!reloadSecrets())
538
+ return;
501
539
  for (const [step, run] of [
502
540
  ['config upgrade', migrate],
503
541
  ['config check', check],
@@ -1,7 +1,7 @@
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, stemForConfigFile, } from '@bakers-build/core';
4
+ import { assertSchemaVersion, assertValidConfig, discoverAddons, discoverScoped, findDefaultExportObject, 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';
@@ -594,7 +594,7 @@ export async function loadConductorConfig(configFile) {
594
594
  config_path: configPath,
595
595
  restart_on_change: restartOnChange,
596
596
  watch_paths: {
597
- files: [configPath, machineContextPath()],
597
+ files: [configPath, machineContextPath(), secretsFilePath()],
598
598
  // A retired entry keeps its spec as key; only resolved modules have a dir.
599
599
  dirs: [
600
600
  ...new Set(effectiveAddons
@@ -4,12 +4,12 @@ export interface WatchPaths {
4
4
  dirs: string[];
5
5
  }
6
6
  /**
7
- * Call `trigger` with the last changed path after `debounceMs` without a
8
- * further change. Files are watched through their parent directory, so an
7
+ * Call `trigger` with every path changed since the last trigger, after
8
+ * `debounceMs` without a further change. Files are watched through their parent directory, so an
9
9
  * editor's rename-replace save and a newly created file both count; dirs are
10
10
  * watched recursively. At most one trigger runs at a time; changes during one
11
11
  * re-arm the debounce once it returns.
12
12
  */
13
- export declare function watchForRestart(paths: WatchPaths, trigger: (path: string) => Promise<void>, debounceMs?: number): {
13
+ export declare function watchForRestart(paths: WatchPaths, trigger: (paths: string[]) => Promise<void>, debounceMs?: number): {
14
14
  close(): void;
15
15
  };
@@ -1,12 +1,13 @@
1
1
  // The foreground conductor restarts itself when a file it loaded changes:
2
- // its config files, the machine config, or a configured addon's build. This
3
- // module only watches, debounces and serializes; the caller decides whether a
4
- // change becomes a restart (config check, drain, execve).
2
+ // its config files, the machine config, the secrets file, or a configured
3
+ // addon's build. This module only watches, debounces and serializes; the
4
+ // caller decides whether a change becomes a restart (config check, drain,
5
+ // execve).
5
6
  import { watch } from 'node:fs';
6
7
  import { basename, dirname, join } from 'node:path';
7
8
  /**
8
- * Call `trigger` with the last changed path after `debounceMs` without a
9
- * further change. Files are watched through their parent directory, so an
9
+ * Call `trigger` with every path changed since the last trigger, after
10
+ * `debounceMs` without a further change. Files are watched through their parent directory, so an
10
11
  * editor's rename-replace save and a newly created file both count; dirs are
11
12
  * watched recursively. At most one trigger runs at a time; changes during one
12
13
  * re-arm the debounce once it returns.
@@ -14,7 +15,7 @@ import { basename, dirname, join } from 'node:path';
14
15
  export function watchForRestart(paths, trigger, debounceMs = 2000) {
15
16
  const watchers = [];
16
17
  let timer;
17
- let last;
18
+ const changedPaths = new Set();
18
19
  let running = false;
19
20
  let pending = false;
20
21
  let closed = false;
@@ -22,7 +23,9 @@ export function watchForRestart(paths, trigger, debounceMs = 2000) {
22
23
  timer = undefined;
23
24
  running = true;
24
25
  try {
25
- await trigger(last);
26
+ const paths = [...changedPaths];
27
+ changedPaths.clear();
28
+ await trigger(paths);
26
29
  }
27
30
  finally {
28
31
  running = false;
@@ -39,7 +42,7 @@ export function watchForRestart(paths, trigger, debounceMs = 2000) {
39
42
  const changed = (path) => {
40
43
  if (closed)
41
44
  return;
42
- last = path;
45
+ changedPaths.add(path);
43
46
  if (running)
44
47
  pending = true;
45
48
  else
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/conductor",
3
- "version": "0.10.1-next.15",
3
+ "version": "0.10.1-next.16",
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.10.1-next.15",
36
- "@bakers-build/message": "^0.10.1-next.15",
35
+ "@bakers-build/core": "^0.10.1-next.16",
36
+ "@bakers-build/message": "^0.10.1-next.16",
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": "4e1d1a59439a6a0019f3b5b213d9cc9f09d14381",
42
+ "commit": "940ae2f2e37b915a7c15c59179d8ebc4f4fbd0a4",
43
43
  "channel": "next"
44
44
  }
45
45
  }