@bakers-build/conductor 0.14.1-next.1 → 0.14.1-next.3

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.
@@ -391,6 +391,10 @@ async function refuseIfAlreadyRunning(remote, id, thisHostKey, force, deps) {
391
391
  return false;
392
392
  }
393
393
  async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
394
+ // A watched file changed after this instant was not loaded: the watcher restarts on it.
395
+ // A self-restart hands over when its watcher stopped looking, so a write during its drain counts.
396
+ const loadedAt = Number(process.env.BAKERS_RESTART_SINCE) || Date.now();
397
+ delete process.env.BAKERS_RESTART_SINCE;
394
398
  const config = await resolveConfig(deps, undefined, true);
395
399
  const checkoutRoot = await checkoutRootOf(config);
396
400
  const logger = loggerFor(checkoutRoot, log);
@@ -447,8 +451,9 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
447
451
  };
448
452
  // Config changes a bad secrets file held back, re-checked on the next change.
449
453
  const heldBack = new Set();
450
- const restartNow = () => {
454
+ const restartNow = (since = Date.now()) => {
451
455
  restart = true;
456
+ process.env.BAKERS_RESTART_SINCE = String(since);
452
457
  watcher?.close();
453
458
  clearInterval(versionTimer);
454
459
  controller.abort();
@@ -470,6 +475,8 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
470
475
  }
471
476
  else {
472
477
  watcher = (deps.watchForRestart ?? watchForRestart)(config.watch_paths, async (paths) => {
478
+ // Changes after this batch was taken are lost when the watcher closes.
479
+ const cut = Date.now();
473
480
  if (controller.signal.aborted)
474
481
  return;
475
482
  const secretsPath = secretsFilePath();
@@ -489,7 +496,7 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
489
496
  return;
490
497
  }
491
498
  logger.info({ path: secretsPath }, 'secrets file changed; restarting conductor');
492
- restartNow();
499
+ restartNow(cut);
493
500
  return;
494
501
  }
495
502
  const path = [
@@ -506,8 +513,8 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
506
513
  return;
507
514
  }
508
515
  logger.info({ path }, 'config check passed; restarting conductor');
509
- restartNow();
510
- });
516
+ restartNow(cut);
517
+ }, undefined, loadedAt);
511
518
  }
512
519
  }
513
520
  const versionTimer = setInterval(async () => {
@@ -1747,6 +1747,9 @@ export class Conductor {
1747
1747
  instructions: ws.instructions,
1748
1748
  command: wrapped.command,
1749
1749
  env: wrapped.env,
1750
+ ...(isolates && chosen.agent.herdrAgent
1751
+ ? { agent: chosen.agent.herdrAgent }
1752
+ : {}),
1750
1753
  });
1751
1754
  launch.started = true;
1752
1755
  this.logger.info({
@@ -8,8 +8,12 @@ export interface WatchPaths {
8
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
- * re-arm the debounce once it returns.
11
+ * re-arm the debounce once it returns. With `since` (when the config was
12
+ * read), a watched file modified after it counts as changed at once, so a
13
+ * write during start-up, before watching began, is not lost.
14
+ * shortcut: dirs (addon builds) are not mtime-checked; walk them if a build
15
+ * during start-up is ever missed.
12
16
  */
13
- export declare function watchForRestart(paths: WatchPaths, trigger: (paths: string[]) => Promise<void>, debounceMs?: number): {
17
+ export declare function watchForRestart(paths: WatchPaths, trigger: (paths: string[]) => Promise<void>, debounceMs?: number, since?: number): {
14
18
  close(): void;
15
19
  };
@@ -3,16 +3,27 @@
3
3
  // addon's build. This module only watches, debounces and serializes; the
4
4
  // caller decides whether a change becomes a restart (config check, drain,
5
5
  // execve).
6
- import { watch } from 'node:fs';
6
+ import { statSync, watch } from 'node:fs';
7
7
  import { basename, dirname, join } from 'node:path';
8
+ /**
9
+ * File mtimes come from the kernel's coarse clock and trail `Date.now()` by up
10
+ * to one tick (measured 5.6 ms on Linux), and a sub-millisecond `mtimeMs` can
11
+ * lead the whole-millisecond `Date.now()`. Well under one restart, so the slack
12
+ * on both sides adds at most one checked restart and never a loop.
13
+ */
14
+ const MTIME_LAG_MS = 50;
8
15
  /**
9
16
  * Call `trigger` with every path changed since the last trigger, after
10
17
  * `debounceMs` without a further change. Files are watched through their parent directory, so an
11
18
  * editor's rename-replace save and a newly created file both count; dirs are
12
19
  * watched recursively. At most one trigger runs at a time; changes during one
13
- * re-arm the debounce once it returns.
20
+ * re-arm the debounce once it returns. With `since` (when the config was
21
+ * read), a watched file modified after it counts as changed at once, so a
22
+ * write during start-up, before watching began, is not lost.
23
+ * shortcut: dirs (addon builds) are not mtime-checked; walk them if a build
24
+ * during start-up is ever missed.
14
25
  */
15
- export function watchForRestart(paths, trigger, debounceMs = 2000) {
26
+ export function watchForRestart(paths, trigger, debounceMs = 2000, since) {
16
27
  const watchers = [];
17
28
  let timer;
18
29
  const changedPaths = new Set();
@@ -72,6 +83,13 @@ export function watchForRestart(paths, trigger, debounceMs = 2000) {
72
83
  });
73
84
  for (const dir of new Set(paths.dirs))
74
85
  tryWatch(dir, true, (f) => changed(join(dir, f)));
86
+ if (since !== undefined)
87
+ for (const file of new Set(paths.files)) {
88
+ const mtime = statSync(file, { throwIfNoEntry: false })?.mtimeMs ?? 0;
89
+ // A future mtime (clock stepped back, touched or extracted file) would fire on every start.
90
+ if (mtime > since - MTIME_LAG_MS && mtime <= Date.now() + MTIME_LAG_MS)
91
+ changed(file);
92
+ }
75
93
  return {
76
94
  close() {
77
95
  closed = true;
@@ -159,6 +159,8 @@ export interface AgentRuntimeInfo {
159
159
  export interface BbAgent extends AgentRuntimeInfo {
160
160
  /** Stable id, e.g. 'claude'. */
161
161
  readonly id: string;
162
+ /** herdr agent manifest name; an isolated run's launcher carries it so herdr and hc identify the pane. */
163
+ readonly herdrAgent?: string;
162
164
  /** Prepare configuration in a private run home without runtime-specific flags. */
163
165
  prepareRun?(context: AgentRunContext): AgentRunPreparation | Promise<AgentRunPreparation>;
164
166
  /** True when the catalog entry sets `plugins: false`: the run uses the user's own agent home. */
@@ -27,6 +27,8 @@ export interface SpawnRunInput {
27
27
  } | null;
28
28
  command?: string;
29
29
  env?: Record<string, string>;
30
+ /** The harness's herdr agent name, set only for an isolated run: the launcher carries it. */
31
+ agent?: string;
30
32
  }
31
33
  /** The lifecycle-hook slots, keyed exactly like `config.hooks`. */
32
34
  export type HookName = 'after_create' | 'before_run' | 'after_run' | 'after_done' | 'on_freeze' | 'on_resume';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/conductor",
3
- "version": "0.14.1-next.1",
3
+ "version": "0.14.1-next.3",
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.14.1-next.1",
36
- "@bakers-build/message": "^0.14.1-next.1",
35
+ "@bakers-build/core": "^0.14.1-next.3",
36
+ "@bakers-build/message": "^0.14.1-next.3",
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": "e6b3d200ba14c56b2fb9d3695f273ea349a97f65",
42
+ "commit": "e28f0222a6ad209e8c848a1648075e0441ba069e",
43
43
  "channel": "next"
44
44
  }
45
45
  }