@bakers-build/conductor 0.14.1-next.1 → 0.14.1-next.10
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.
- package/dist/src/commands/conductor.js +11 -4
- package/dist/src/core/conductor.d.ts +2 -0
- package/dist/src/core/conductor.js +43 -1
- package/dist/src/core/self-restart.d.ts +6 -2
- package/dist/src/core/self-restart.js +21 -3
- package/dist/src/core/site-tools.js +2 -0
- package/dist/src/plugins/agent.d.ts +2 -0
- package/dist/src/plugins/executor.d.ts +17 -0
- package/package.json +4 -4
|
@@ -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 () => {
|
|
@@ -56,6 +56,8 @@ export declare class Conductor {
|
|
|
56
56
|
private readonly inboxAddons;
|
|
57
57
|
/** The per-item work each tick enqueues. */
|
|
58
58
|
private readonly queue;
|
|
59
|
+
/** Whether the executor's leftover-workspace sweep has finished this process. */
|
|
60
|
+
private workspaceSweepDone;
|
|
59
61
|
/** The local MCP server for addon tools; only the serve process runs one. */
|
|
60
62
|
private toolServer;
|
|
61
63
|
/** Where runs execute, chosen per ticket. */
|
|
@@ -219,6 +219,8 @@ export class Conductor {
|
|
|
219
219
|
inboxAddons;
|
|
220
220
|
/** The per-item work each tick enqueues. */
|
|
221
221
|
queue;
|
|
222
|
+
/** Whether the executor's leftover-workspace sweep has finished this process. */
|
|
223
|
+
workspaceSweepDone = false;
|
|
222
224
|
/** The local MCP server for addon tools; only the serve process runs one. */
|
|
223
225
|
toolServer;
|
|
224
226
|
/** Where runs execute, chosen per ticket. */
|
|
@@ -1071,6 +1073,25 @@ export class Conductor {
|
|
|
1071
1073
|
run: () => this.reapOne(t),
|
|
1072
1074
|
});
|
|
1073
1075
|
}
|
|
1076
|
+
const sweep = this.executor.sweepWorkspaces?.bind(this.executor);
|
|
1077
|
+
if (sweep &&
|
|
1078
|
+
!this.workspaceSweepDone &&
|
|
1079
|
+
this.executor.capabilities().persistent) {
|
|
1080
|
+
this.queue.enqueue({
|
|
1081
|
+
key: 'reap:workspace-sweep',
|
|
1082
|
+
lane: 'reap:workspace-sweep',
|
|
1083
|
+
run: async () => {
|
|
1084
|
+
try {
|
|
1085
|
+
this.workspaceSweepDone = await sweep();
|
|
1086
|
+
}
|
|
1087
|
+
catch (err) {
|
|
1088
|
+
// A sweep that throws would throw again: give up for this process.
|
|
1089
|
+
this.workspaceSweepDone = true;
|
|
1090
|
+
this.logger.warn({ err: String(err) }, 'workspace sweep failed');
|
|
1091
|
+
}
|
|
1092
|
+
},
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1074
1095
|
}
|
|
1075
1096
|
/**
|
|
1076
1097
|
* Record the merge request's size on a done ticket while its worktree still
|
|
@@ -1209,6 +1230,22 @@ export class Conductor {
|
|
|
1209
1230
|
return; // leave cleaned_up=0 → the next reconciliation retries.
|
|
1210
1231
|
}
|
|
1211
1232
|
}
|
|
1233
|
+
// The worktree is gone; close the branch workspace the executor opened
|
|
1234
|
+
// for it, which another workspace addon's teardown leaves behind.
|
|
1235
|
+
if (outcome !== 'unverified' &&
|
|
1236
|
+
this.executor.closeWorkspace &&
|
|
1237
|
+
this.executor.capabilities().persistent) {
|
|
1238
|
+
try {
|
|
1239
|
+
const closed = await this.executor.closeWorkspace(t.branchName, t.worktreePath || undefined);
|
|
1240
|
+
if (!closed) {
|
|
1241
|
+
this.logger.warn({ ticket: t.ticketUuid, branch: t.branchName }, 'branch workspace not safe to close — retrying next reap');
|
|
1242
|
+
return; // leave cleaned_up=0 → the next reconciliation retries.
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
catch (err) {
|
|
1246
|
+
this.logger.warn({ ticket: t.ticketUuid, branch: t.branchName, err: String(err) }, 'branch workspace close failed');
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1212
1249
|
if (outcome === 'already_absent') {
|
|
1213
1250
|
// BB-293: the worktree was gone before we got here. That is a
|
|
1214
1251
|
// FINISHED teardown, so it is recorded rather than swallowed and
|
|
@@ -1412,7 +1449,9 @@ export class Conductor {
|
|
|
1412
1449
|
}
|
|
1413
1450
|
/** `at.worktree` is set once the workspace exists, so a failure can signal it. */
|
|
1414
1451
|
async dispatch(run, at = {}) {
|
|
1415
|
-
const
|
|
1452
|
+
const fetched = await this.remote.getTicket(run.ticketUuid);
|
|
1453
|
+
// JSON:API can return the pre-transition state; the run knows the state it was started for.
|
|
1454
|
+
const t = { ...fetched, state: run.stateAtStart || fetched.state };
|
|
1416
1455
|
// Resolve the ticket alias and machine defaults, or the project selection hook.
|
|
1417
1456
|
// Persist the package id below so finalize can choose its transcript parser.
|
|
1418
1457
|
// The project's select_agent wins; then the machine's agents select.
|
|
@@ -1747,6 +1786,9 @@ export class Conductor {
|
|
|
1747
1786
|
instructions: ws.instructions,
|
|
1748
1787
|
command: wrapped.command,
|
|
1749
1788
|
env: wrapped.env,
|
|
1789
|
+
...(isolates && chosen.agent.herdrAgent
|
|
1790
|
+
? { agent: chosen.agent.herdrAgent }
|
|
1791
|
+
: {}),
|
|
1750
1792
|
});
|
|
1751
1793
|
launch.started = true;
|
|
1752
1794
|
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;
|
|
@@ -18,6 +18,8 @@ export const SITE_TOOLS = [
|
|
|
18
18
|
'bakers_label_list',
|
|
19
19
|
'bakers_project_read',
|
|
20
20
|
'bakers_user_read',
|
|
21
|
+
'bakers_user_search',
|
|
22
|
+
'bakers_team_members',
|
|
21
23
|
'bakers_conductor_list',
|
|
22
24
|
];
|
|
23
25
|
/** The site tools that change a ticket; a successful call signals `bakers ui`. */
|
|
@@ -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';
|
|
@@ -171,4 +173,19 @@ export interface BbExecutor {
|
|
|
171
173
|
* non-persistent executors.
|
|
172
174
|
*/
|
|
173
175
|
cleanupRun(branch: string, runId: number): Promise<void>;
|
|
176
|
+
/**
|
|
177
|
+
* Close the branch's hosted workspace once the reaper has torn its worktree
|
|
178
|
+
* down (`removed` or `already_absent`), whichever workspace addon did it.
|
|
179
|
+
* Optional; called only for a persistent executor. `false` = not safe yet
|
|
180
|
+
* (e.g. focused with nowhere to move focus): the ticket stays on the reap
|
|
181
|
+
* list and the next reap retries. A workspace that holds anything besides
|
|
182
|
+
* bakers terminals is kept, reported, and counts as `true`.
|
|
183
|
+
*/
|
|
184
|
+
closeWorkspace?(branch: string, worktreePath?: string): Promise<boolean>;
|
|
185
|
+
/**
|
|
186
|
+
* Close workspaces left over by earlier versions, whose tickets are already
|
|
187
|
+
* cleaned up. Optional; the reaper runs it once per process for a persistent
|
|
188
|
+
* executor and again on later passes while it returns `false`.
|
|
189
|
+
*/
|
|
190
|
+
sweepWorkspaces?(): Promise<boolean>;
|
|
174
191
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/conductor",
|
|
3
|
-
"version": "0.14.1-next.
|
|
3
|
+
"version": "0.14.1-next.10",
|
|
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.
|
|
36
|
-
"@bakers-build/message": "^0.14.1-next.
|
|
35
|
+
"@bakers-build/core": "^0.14.1-next.10",
|
|
36
|
+
"@bakers-build/message": "^0.14.1-next.10",
|
|
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": "
|
|
42
|
+
"commit": "a1604421ab259e7d70ead776e03a7773a16a961a",
|
|
43
43
|
"channel": "next"
|
|
44
44
|
}
|
|
45
45
|
}
|