@bakers-build/conductor 0.6.1-next.5 → 0.6.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.
- package/dist/src/cli/config-templates.js +7 -5
- package/dist/src/cli/config-validation.js +1 -0
- package/dist/src/commands/conductor.d.ts +4 -6
- package/dist/src/commands/conductor.js +47 -35
- package/dist/src/commands/oven-tools.js +1 -1
- package/dist/src/config.d.ts +3 -1
- package/dist/src/config.js +63 -46
- package/dist/src/contract.d.ts +3 -4
- package/dist/src/contract.js +1 -1
- package/dist/src/core/conductor.d.ts +12 -7
- package/dist/src/core/conductor.js +144 -119
- package/dist/src/core/hook-runner.d.ts +23 -0
- package/dist/src/core/hook-runner.js +22 -0
- package/dist/src/core/site-tools.d.ts +21 -0
- package/dist/src/core/site-tools.js +142 -0
- package/dist/src/core/tool-server.d.ts +10 -2
- package/dist/src/core/tool-server.js +95 -13
- package/dist/src/core/ui-signal.d.ts +2 -0
- package/dist/src/core/ui-signal.js +41 -0
- package/dist/src/plugins/agent-args.d.ts +54 -5
- package/dist/src/plugins/agent-args.js +99 -11
- package/dist/src/plugins/agent.d.ts +1 -1
- package/dist/src/plugins/agent.js +1 -1
- package/dist/src/plugins/executor.d.ts +28 -47
- package/dist/src/plugins/plugins.d.ts +3 -0
- package/dist/src/plugins/preset.d.ts +1 -5
- package/dist/src/plugins/remote.d.ts +25 -0
- package/dist/src/plugins/workspace.d.ts +21 -32
- package/dist/src/process/detached-spawn.d.ts +20 -0
- package/dist/src/process/detached-spawn.js +34 -0
- package/dist/src/types.d.ts +6 -15
- package/package.json +4 -4
- package/dist/src/plugins/process-host.d.ts +0 -7
- package/dist/src/plugins/process-host.js +0 -1
|
@@ -4,11 +4,14 @@ import { killRunProcesses, shellQuote, stemForConfigFile, } from '@bakers-build/
|
|
|
4
4
|
import { CONDUCTOR_TOKEN_ENV, CONDUCTOR_URL_ENV, DEFAULT_ENV_DENY, matchesEnvDeny, } from '../plugins/agent.js';
|
|
5
5
|
import { resolveAgent } from '../plugins/plugins.js';
|
|
6
6
|
import { sandboxFailures } from '../plugins/sandbox-preflight.js';
|
|
7
|
+
import { loadTools } from '../plugins/tools.js';
|
|
7
8
|
import { ActionQueue } from './action-queue.js';
|
|
8
9
|
import { attemptFamily } from './attempt.js';
|
|
10
|
+
import { shellHookRunner } from './hook-runner.js';
|
|
9
11
|
import { InboxRuntime, runInbox } from './inbox-runtime.js';
|
|
10
12
|
import { measureMrChanges, mrChangesRows } from './mr-changes.js';
|
|
11
13
|
import { startToolServer } from './tool-server.js';
|
|
14
|
+
import { signalUi } from './ui-signal.js';
|
|
12
15
|
function sleep(ms, signal) {
|
|
13
16
|
return new Promise((resolve) => {
|
|
14
17
|
if (signal?.aborted) {
|
|
@@ -185,6 +188,7 @@ export class Conductor {
|
|
|
185
188
|
logger;
|
|
186
189
|
checkoutRoot;
|
|
187
190
|
frozenStateFile;
|
|
191
|
+
runHook;
|
|
188
192
|
uuid = null;
|
|
189
193
|
/**
|
|
190
194
|
* Frozen tickets seen on the last poll, by uuid, with the worktree their
|
|
@@ -199,11 +203,9 @@ export class Conductor {
|
|
|
199
203
|
queue;
|
|
200
204
|
/** The local MCP server for addon tools; only the serve process runs one. */
|
|
201
205
|
toolServer;
|
|
202
|
-
/** The live run token per run UUID, revoked when the run is finalised. */
|
|
203
|
-
runTokens = new Map();
|
|
204
206
|
/** Serializes git worktree add/remove: parallel ones fight over git locks. */
|
|
205
207
|
gitLock = Promise.resolve();
|
|
206
|
-
constructor(config, remote, executor, workspace, agents, logger, checkoutRoot = process.cwd(), frozenStateFile) {
|
|
208
|
+
constructor(config, remote, executor, workspace, agents, logger, checkoutRoot = process.cwd(), frozenStateFile, runHook = shellHookRunner(config.hooks, logger)) {
|
|
207
209
|
this.config = config;
|
|
208
210
|
this.remote = remote;
|
|
209
211
|
this.executor = executor;
|
|
@@ -212,6 +214,7 @@ export class Conductor {
|
|
|
212
214
|
this.logger = logger;
|
|
213
215
|
this.checkoutRoot = checkoutRoot;
|
|
214
216
|
this.frozenStateFile = frozenStateFile;
|
|
217
|
+
this.runHook = runHook;
|
|
215
218
|
this.inboxAddons = new InboxRuntime(config.inboxAddons ?? [], remote, logger, (ticket) => this.runEnv(ticket, undefined, ticket.state), config.tools);
|
|
216
219
|
this.queue = new ActionQueue(logger);
|
|
217
220
|
}
|
|
@@ -268,41 +271,58 @@ export class Conductor {
|
|
|
268
271
|
return this.ownsServeProcess ? { ...base, last_pid: process.pid } : base;
|
|
269
272
|
}
|
|
270
273
|
/**
|
|
271
|
-
* Starts the tool server when an addon declares tools
|
|
272
|
-
* process calls this; `endpointFile` publishes
|
|
274
|
+
* Starts the tool server when an addon declares tools or the remote serves
|
|
275
|
+
* site tools. Only the serve process calls this; `endpointFile` publishes
|
|
276
|
+
* it to the CLI.
|
|
273
277
|
*/
|
|
274
278
|
async startTools(endpointFile) {
|
|
275
|
-
|
|
279
|
+
const { siteTools } = this.remote;
|
|
280
|
+
if ((!this.config.tools && !siteTools) || this.toolServer)
|
|
276
281
|
return;
|
|
282
|
+
// Runs closed while no server ran (`oven once`, a crash) lose their grant here.
|
|
283
|
+
const openRuns = await this.remote.fetchActiveRuns(this.id).then((runs) => runs.map((r) => r.runUuid), (err) => {
|
|
284
|
+
this.logger.warn({ err: String(err) }, 'active runs unreadable, keeping every persisted run grant');
|
|
285
|
+
return undefined;
|
|
286
|
+
});
|
|
277
287
|
this.toolServer = await startToolServer({
|
|
278
|
-
registry: this.config.tools,
|
|
288
|
+
registry: this.config.tools ?? (await loadTools([])),
|
|
279
289
|
workspaceRoot: this.checkoutRoot,
|
|
280
290
|
logger: this.logger,
|
|
281
291
|
...(endpointFile ? { endpointFile } : {}),
|
|
292
|
+
...(openRuns ? { openRuns } : {}),
|
|
293
|
+
...(siteTools ? { siteTools } : {}),
|
|
294
|
+
onSiteWrite: (b) => this.signalUi(b.worktreePath),
|
|
282
295
|
});
|
|
283
296
|
this.logger.info({ conductorId: this.config.conductor_id, url: this.toolServer.url }, 'tool server started');
|
|
284
297
|
}
|
|
298
|
+
/** Tell an open `bakers ui` in the checkout (and the run's worktree) to reload. */
|
|
299
|
+
signalUi(worktree) {
|
|
300
|
+
signalUi(this.checkoutRoot);
|
|
301
|
+
if (worktree)
|
|
302
|
+
signalUi(worktree);
|
|
303
|
+
}
|
|
285
304
|
async stopTools() {
|
|
286
305
|
// Server first, so no new provision_up starts a run after the stop.
|
|
287
306
|
await this.toolServer?.stop();
|
|
288
307
|
await this.config.provisioning?.stop();
|
|
308
|
+
await this.remote.siteTools?.close();
|
|
289
309
|
this.toolServer = undefined;
|
|
290
|
-
this.runTokens.clear();
|
|
291
310
|
}
|
|
292
311
|
/** A fresh token for this run's worktree; a re-dispatch replaces the old one. */
|
|
293
312
|
issueRunTools(runUuid, binding) {
|
|
294
313
|
if (!this.toolServer)
|
|
295
314
|
return undefined;
|
|
296
|
-
this.
|
|
297
|
-
const token = this.toolServer.issueRunToken(binding);
|
|
298
|
-
this.runTokens.set(runUuid, token);
|
|
315
|
+
const token = this.toolServer.issueRunToken(runUuid, binding);
|
|
299
316
|
return { url: this.toolServer.url, token };
|
|
300
317
|
}
|
|
318
|
+
/** Never throws: a failed state write leaves the grant on disk, and the next start prunes it. */
|
|
301
319
|
revokeRunTools(runUuid) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
320
|
+
try {
|
|
321
|
+
this.toolServer?.revokeRunToken(runUuid);
|
|
322
|
+
}
|
|
323
|
+
catch (err) {
|
|
324
|
+
this.logger.warn({ run: runUuid, err: String(err) }, 'run tool revoke failed');
|
|
325
|
+
}
|
|
306
326
|
}
|
|
307
327
|
async start() {
|
|
308
328
|
this.uuid = await this.remote.registerConductor(this.registration());
|
|
@@ -399,6 +419,7 @@ export class Conductor {
|
|
|
399
419
|
break;
|
|
400
420
|
}
|
|
401
421
|
this.logger.info({ conductorId: this.id, run: run.runUuid, ticket: run.ticketUuid }, 'claimed run');
|
|
422
|
+
this.signalUi();
|
|
402
423
|
this.queue.enqueue({
|
|
403
424
|
key: `dispatch:${run.runUuid}`,
|
|
404
425
|
lane: run.ticketUuid,
|
|
@@ -449,7 +470,7 @@ export class Conductor {
|
|
|
449
470
|
try {
|
|
450
471
|
// Signal the agent to stop before capturing its log. Best-effort and
|
|
451
472
|
// gated on the persistent capability (only hosted executors have a live
|
|
452
|
-
// agent)
|
|
473
|
+
// agent). For herdr this is a no-op
|
|
453
474
|
// (the tab-close in closeRunTab kills the PTY); a stop failure must
|
|
454
475
|
// never block finalisation.
|
|
455
476
|
const branch = this.executor.capabilities().persistent
|
|
@@ -483,14 +504,17 @@ export class Conductor {
|
|
|
483
504
|
await this.runFinalizeHook(r);
|
|
484
505
|
if (!captured)
|
|
485
506
|
throw captureError;
|
|
486
|
-
//
|
|
487
|
-
//
|
|
488
|
-
//
|
|
489
|
-
//
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
507
|
+
// The server's policy decides first (missing means no), and the local
|
|
508
|
+
// `capture_logs` opt-out can only narrow it. `finalizeRun()` spreads
|
|
509
|
+
// `...(log ? { log } : {})`, so an empty string omits the attribute
|
|
510
|
+
// from the PATCH entirely; the server re-checks its policy anyway.
|
|
511
|
+
const uploadedLog = r.runLogStorageAllowed === true && (this.config.capture_logs ?? true)
|
|
512
|
+
? captured.log
|
|
513
|
+
: '';
|
|
514
|
+
// Revoke before the durable close: a crash between the two must not leave a closed run's grant.
|
|
493
515
|
this.revokeRunTools(r.runUuid);
|
|
516
|
+
await this.remote.finalizeRun(r.runUuid, uploadedLog, captured.metrics);
|
|
517
|
+
this.signalUi(r.worktreePath);
|
|
494
518
|
this.logger.info({ run: r.runUuid, state: r.state, footprint: captured.metrics }, 'run finalised');
|
|
495
519
|
}
|
|
496
520
|
catch (err) {
|
|
@@ -640,7 +664,7 @@ export class Conductor {
|
|
|
640
664
|
}
|
|
641
665
|
/**
|
|
642
666
|
* Run one lifecycle slot (BB-599): every addon listener in accumulator
|
|
643
|
-
* order, awaited, then the project shell hook through
|
|
667
|
+
* order, awaited, then the project shell hook through {@link runHook}. Never
|
|
644
668
|
* throws. A failing listener is logged by slot, listener, ticket and run —
|
|
645
669
|
* never with its message or the env — and reported in the returned result
|
|
646
670
|
* the same way a failing shell command is, so the rest of the slot, the
|
|
@@ -677,7 +701,7 @@ export class Conductor {
|
|
|
677
701
|
});
|
|
678
702
|
}
|
|
679
703
|
}
|
|
680
|
-
const shell = await this.
|
|
704
|
+
const shell = await this.runHook(name, cwd, { ticket: ticketRef }, shellEnv);
|
|
681
705
|
if (failed.length === 0)
|
|
682
706
|
return shell;
|
|
683
707
|
const error = `hook listener failed: ${failed.join(', ')}`;
|
|
@@ -817,7 +841,7 @@ export class Conductor {
|
|
|
817
841
|
* `BbTicket::preSave()` on any save of a terminal, unclosed ticket, so it
|
|
818
842
|
* holds for every write path and cannot be withheld by a teardown hiccup —
|
|
819
843
|
* the reap reasons about `cleaned_up` alone. `cleaned_up` is withheld unless
|
|
820
|
-
* the teardown is ACCOUNTED FOR (BB-141 RC-2), which `
|
|
844
|
+
* the teardown is ACCOUNTED FOR (BB-141 RC-2), which `workspace.remove`
|
|
821
845
|
* reports as one of three outcomes (BB-293):
|
|
822
846
|
* - `removed` — gone because this host tore it down → flag cleaned;
|
|
823
847
|
* - `already_absent` — nothing was there to tear down. A FINISHED teardown,
|
|
@@ -876,14 +900,13 @@ export class Conductor {
|
|
|
876
900
|
/** Reaps one ticket; isolated, so one failure never aborts the rest. */
|
|
877
901
|
async reapOne(t) {
|
|
878
902
|
try {
|
|
879
|
-
// Infra teardown. The `after_done` hook runs in the worktree
|
|
880
|
-
//
|
|
881
|
-
//
|
|
882
|
-
//
|
|
883
|
-
//
|
|
884
|
-
//
|
|
885
|
-
//
|
|
886
|
-
// no-op / on-disk reclaim, not a failure.
|
|
903
|
+
// Infra teardown. The `after_done` hook runs in the worktree, then the
|
|
904
|
+
// workspace removes it — for every executor kind: a non-persistent
|
|
905
|
+
// executor still leaves an on-disk worktree behind. Pass the stable
|
|
906
|
+
// worktreePath so the workspace resolves the worktree by path, not by
|
|
907
|
+
// the mutable checked-out branch (the coding agent may rename it).
|
|
908
|
+
// Teardown is idempotent: a worktree no longer tracked is a no-op /
|
|
909
|
+
// on-disk reclaim, not a failure.
|
|
887
910
|
//
|
|
888
911
|
// The hook needs the DIRECTORY, not just a recorded path (BB-293): a
|
|
889
912
|
// hook is a shell spawned with the worktree as its `cwd`, so against an
|
|
@@ -893,17 +916,16 @@ export class Conductor {
|
|
|
893
916
|
// that must run inside the worktree cannot run anywhere else.
|
|
894
917
|
//
|
|
895
918
|
// The absence is logged rather than passed over in silence, because an
|
|
896
|
-
// `after_done` can reach beyond the directory it runs in —
|
|
897
|
-
//
|
|
919
|
+
// `after_done` can reach beyond the directory it runs in — deleting a
|
|
920
|
+
// container runtime's project also drops its registration and database — and
|
|
898
921
|
// that leftover is then an operator's to clear by hand.
|
|
899
922
|
//
|
|
900
|
-
// But the line states the CONDITION, not a decision about a hook:
|
|
901
|
-
//
|
|
902
|
-
//
|
|
903
|
-
//
|
|
904
|
-
//
|
|
905
|
-
//
|
|
906
|
-
// either configuration.
|
|
923
|
+
// But the line states the CONDITION, not a decision about a hook: an
|
|
924
|
+
// `after_done` may be a listener, a shell command or nothing at all.
|
|
925
|
+
// Saying a hook was "skipped" would be false wherever none exists (the
|
|
926
|
+
// generated playground config is exactly such a case). What the core
|
|
927
|
+
// does know is that the directory is gone and that no `after_done` ran —
|
|
928
|
+
// both true in every configuration.
|
|
907
929
|
//
|
|
908
930
|
// `existsSync` here is a plain filesystem question, not worktree
|
|
909
931
|
// knowledge: the core stays executor-agnostic and asks nothing about
|
|
@@ -939,83 +961,80 @@ export class Conductor {
|
|
|
939
961
|
}, 'worktree directory absent — after_done not run');
|
|
940
962
|
}
|
|
941
963
|
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
964
|
+
let outcome;
|
|
965
|
+
try {
|
|
966
|
+
// workspace.remove reports what the teardown DID (BB-293):
|
|
967
|
+
// `removed` = the worktree is gone because this host removed it;
|
|
968
|
+
// `already_absent` = there was nothing to tear down; `unverified` =
|
|
969
|
+
// it could NOT be resolved and may still be on disk (BB-141 RC-2
|
|
970
|
+
// — e.g. worktree_path was never persisted and herdr lost track of
|
|
971
|
+
// the branch). A THROW is a hard failure.
|
|
972
|
+
outcome = await this.serialGit(() => this.workspace.remove(t.branchName, t.worktreePath || undefined));
|
|
973
|
+
}
|
|
974
|
+
catch (err) {
|
|
975
|
+
this.logger.warn({
|
|
976
|
+
ticket: t.ticketUuid,
|
|
977
|
+
branch: t.branchName,
|
|
978
|
+
worktreePath: t.worktreePath,
|
|
979
|
+
err: String(err),
|
|
980
|
+
}, 'worktree teardown failed');
|
|
981
|
+
return; // leave cleaned_up=0 → the next reconciliation retries.
|
|
982
|
+
}
|
|
983
|
+
if (outcome === 'unverified') {
|
|
984
|
+
// BB-468 — an unverified teardown with NO run and NO recorded
|
|
985
|
+
// path has nothing left for a later reap to resolve: no run will
|
|
986
|
+
// appear on a terminal ticket, and no branch will appear for work
|
|
987
|
+
// that never started (`reap()` passes `t.worktreePath ||
|
|
988
|
+
// undefined`, so a never-ran ticket and a lost-path ticket reach
|
|
989
|
+
// the executor byte-identically — only the reaper, which alone
|
|
990
|
+
// knows `runUuid === ''`, can tell them apart). That retry is not
|
|
991
|
+
// deferred, it is unreachable, so it is logged ONCE at info and
|
|
992
|
+
// accounted for below rather than retried forever. BB-141 RC-2
|
|
993
|
+
// is unchanged for every ticket that DOES carry a run or a
|
|
994
|
+
// recorded path: those keep retrying below, unaffected.
|
|
995
|
+
if (!t.runUuid && !t.worktreePath) {
|
|
996
|
+
this.logger.info({ ticket: t.ticketUuid, branch: t.branchName }, 'no run and no recorded path — nothing to tear down');
|
|
952
997
|
}
|
|
953
|
-
|
|
998
|
+
else {
|
|
999
|
+
// Unverified teardown (BB-141 RC-2): do NOT flag cleaned_up, or
|
|
1000
|
+
// the ticket drops off fetchUncleanedTickets (which filters
|
|
1001
|
+
// cleaned_up=0) and the orphan is never retried. Leave it on the
|
|
1002
|
+
// work list so a later reap — with a persisted path, or once the
|
|
1003
|
+
// executor resolves it via the parent-repo git worktree list —
|
|
1004
|
+
// can finish the job.
|
|
954
1005
|
this.logger.warn({
|
|
955
1006
|
ticket: t.ticketUuid,
|
|
956
1007
|
branch: t.branchName,
|
|
957
1008
|
worktreePath: t.worktreePath,
|
|
958
|
-
|
|
959
|
-
}, 'worktree teardown failed');
|
|
1009
|
+
}, 'worktree teardown unverified — retrying next reap');
|
|
960
1010
|
return; // leave cleaned_up=0 → the next reconciliation retries.
|
|
961
1011
|
}
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
// Unverified teardown (BB-141 RC-2): do NOT flag cleaned_up, or
|
|
979
|
-
// the ticket drops off fetchUncleanedTickets (which filters
|
|
980
|
-
// cleaned_up=0) and the orphan is never retried. Leave it on the
|
|
981
|
-
// work list so a later reap — with a persisted path, or once the
|
|
982
|
-
// executor resolves it via the parent-repo git worktree list —
|
|
983
|
-
// can finish the job.
|
|
984
|
-
this.logger.warn({
|
|
985
|
-
ticket: t.ticketUuid,
|
|
986
|
-
branch: t.branchName,
|
|
987
|
-
worktreePath: t.worktreePath,
|
|
988
|
-
}, 'worktree teardown unverified — retrying next reap');
|
|
989
|
-
return; // leave cleaned_up=0 → the next reconciliation retries.
|
|
1012
|
+
}
|
|
1013
|
+
if (outcome === 'already_absent') {
|
|
1014
|
+
// BB-293: the worktree was gone before we got here. That is a
|
|
1015
|
+
// FINISHED teardown, so it is recorded rather than swallowed and
|
|
1016
|
+
// the ticket is flagged cleaned below — the next reap will not
|
|
1017
|
+
// retry it.
|
|
1018
|
+
this.logger.info({
|
|
1019
|
+
ticket: t.ticketUuid,
|
|
1020
|
+
branch: t.branchName,
|
|
1021
|
+
worktreePath: t.worktreePath,
|
|
1022
|
+
}, 'worktree already absent — teardown complete');
|
|
1023
|
+
// A ticket with no run has no record to write to — the conductor
|
|
1024
|
+
// log above is then the whole account.
|
|
1025
|
+
if (t.runUuid) {
|
|
1026
|
+
try {
|
|
1027
|
+
await this.remote.appendRunNote(t.runUuid, `worktree already absent at teardown: ${t.worktreePath || '(path unknown)'}`);
|
|
990
1028
|
}
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
// the ticket is flagged cleaned below — the next reap will not
|
|
996
|
-
// retry it.
|
|
997
|
-
this.logger.info({
|
|
998
|
-
ticket: t.ticketUuid,
|
|
999
|
-
branch: t.branchName,
|
|
1000
|
-
worktreePath: t.worktreePath,
|
|
1001
|
-
}, 'worktree already absent — teardown complete');
|
|
1002
|
-
// A ticket with no run has no record to write to — the conductor
|
|
1003
|
-
// log above is then the whole account.
|
|
1004
|
-
if (t.runUuid) {
|
|
1005
|
-
try {
|
|
1006
|
-
await this.remote.appendRunNote(t.runUuid, `worktree already absent at teardown: ${t.worktreePath || '(path unknown)'}`);
|
|
1007
|
-
}
|
|
1008
|
-
catch (err) {
|
|
1009
|
-
// Best-effort: an unreachable control plane must not keep a
|
|
1010
|
-
// finished teardown from being flagged.
|
|
1011
|
-
this.logger.warn({ ticket: t.ticketUuid, run: t.runUuid, err: String(err) }, 'run note write failed');
|
|
1012
|
-
}
|
|
1029
|
+
catch (err) {
|
|
1030
|
+
// Best-effort: an unreachable control plane must not keep a
|
|
1031
|
+
// finished teardown from being flagged.
|
|
1032
|
+
this.logger.warn({ ticket: t.ticketUuid, run: t.runUuid, err: String(err) }, 'run note write failed');
|
|
1013
1033
|
}
|
|
1014
1034
|
}
|
|
1015
1035
|
}
|
|
1016
|
-
// Teardown verified locally
|
|
1017
|
-
//
|
|
1018
|
-
// work list.
|
|
1036
|
+
// Teardown verified locally or the worktree was already absent: flag it
|
|
1037
|
+
// cleaned so it drops off the work list.
|
|
1019
1038
|
await this.remote.markTicketCleanedUp(t.ticketUuid);
|
|
1020
1039
|
this.logger.info({ ticket: t.ticketUuid }, 'ticket cleaned up');
|
|
1021
1040
|
}
|
|
@@ -1069,8 +1088,9 @@ export class Conductor {
|
|
|
1069
1088
|
}
|
|
1070
1089
|
/** Dispatches one claimed run; a failure terminalises it (BB-149). */
|
|
1071
1090
|
async dispatchOrFail(run) {
|
|
1091
|
+
const at = {};
|
|
1072
1092
|
try {
|
|
1073
|
-
await this.dispatch(run);
|
|
1093
|
+
await this.dispatch(run, at);
|
|
1074
1094
|
}
|
|
1075
1095
|
catch (err) {
|
|
1076
1096
|
// BB-149: terminalise the run to `failed` with the error captured,
|
|
@@ -1087,13 +1107,15 @@ export class Conductor {
|
|
|
1087
1107
|
this.logger.error({ run: run.runUuid, err: String(err) }, 'dispatch failed');
|
|
1088
1108
|
try {
|
|
1089
1109
|
await this.remote.markFailed(run.runUuid, String(err));
|
|
1110
|
+
this.signalUi(at.worktree);
|
|
1090
1111
|
}
|
|
1091
1112
|
catch (markErr) {
|
|
1092
1113
|
this.logger.warn({ run: run.runUuid, err: String(markErr) }, 'markFailed failed');
|
|
1093
1114
|
}
|
|
1094
1115
|
}
|
|
1095
1116
|
}
|
|
1096
|
-
|
|
1117
|
+
/** `at.worktree` is set once the workspace exists, so a failure can signal it. */
|
|
1118
|
+
async dispatch(run, at = {}) {
|
|
1097
1119
|
const t = await this.remote.getTicket(run.ticketUuid);
|
|
1098
1120
|
// Resolve the ticket alias and machine defaults, or the project selection hook.
|
|
1099
1121
|
// Persist the package id below so finalize can choose its transcript parser.
|
|
@@ -1109,11 +1131,12 @@ export class Conductor {
|
|
|
1109
1131
|
throw new Error(unavailable);
|
|
1110
1132
|
const baseRef = t.baseBranch ? `origin/${t.baseBranch}` : undefined;
|
|
1111
1133
|
// Resolve the run env once (per-ticket env_vars + core BB_* vars) and
|
|
1112
|
-
// inject it into BOTH the
|
|
1134
|
+
// inject it into BOTH the lifecycle hooks AND the agent run
|
|
1113
1135
|
// env (BB-99). Reserved core keys always win; values may be sensitive so
|
|
1114
1136
|
// only key names are ever logged.
|
|
1115
1137
|
const env = await this.runEnv(t, run.runUuid, run.stateAtStart, chosen.agent);
|
|
1116
1138
|
const ws = await this.serialGit(() => this.workspace.ensure(t.identifier, t.branchName, baseRef));
|
|
1139
|
+
at.worktree = ws.path;
|
|
1117
1140
|
// The backend's own vars (Git config) join the run env; core keys still win.
|
|
1118
1141
|
for (const [key, value] of Object.entries(ws.env ?? {})) {
|
|
1119
1142
|
if (!isReservedEnvKey(key))
|
|
@@ -1151,7 +1174,7 @@ export class Conductor {
|
|
|
1151
1174
|
*/
|
|
1152
1175
|
async launch(run, t, chosen, ws, ctx, launch) {
|
|
1153
1176
|
const env = ctx.env;
|
|
1154
|
-
// Lifecycle hooks are
|
|
1177
|
+
// Lifecycle hooks are conductor-owned + best-effort (BB-84): runHook never
|
|
1155
1178
|
// throws, so neither call can abort dispatch or wedge a run in `claimed`.
|
|
1156
1179
|
// `runSlot` runs the addon listeners first under the same rule (BB-599).
|
|
1157
1180
|
// Both get the resolved run env so a setup/pre hook sees the same vars (e.g.
|
|
@@ -1195,7 +1218,7 @@ export class Conductor {
|
|
|
1195
1218
|
err: provisioning.error,
|
|
1196
1219
|
}, 'lifecycle hook failed');
|
|
1197
1220
|
}
|
|
1198
|
-
// BB-237:
|
|
1221
|
+
// BB-237: open the fresh worktree in the executor HERE — after `after_create`,
|
|
1199
1222
|
// before the run starts. The layout's startup command names the bakers CLI
|
|
1200
1223
|
// that `after_create` builds; applied inside `workspace.ensure()` (where it
|
|
1201
1224
|
// used to live) it necessarily fired first, so a self-hosting checkout had
|
|
@@ -1209,7 +1232,7 @@ export class Conductor {
|
|
|
1209
1232
|
// Optional on the contract, so a workspace with no layout concept is a
|
|
1210
1233
|
// no-op. Best-effort by contract: implementations swallow their own errors.
|
|
1211
1234
|
if (ws.created) {
|
|
1212
|
-
await this.
|
|
1235
|
+
await this.executor.openWorkspace?.(ws.path, {
|
|
1213
1236
|
identifier: t.identifier,
|
|
1214
1237
|
branch: t.branchName,
|
|
1215
1238
|
title: t.title,
|
|
@@ -1269,6 +1292,11 @@ export class Conductor {
|
|
|
1269
1292
|
// field's accepted formats and the PATCH would be rejected (review round
|
|
1270
1293
|
// 4, Critical 1).
|
|
1271
1294
|
const dispatchedAt = Math.floor(Date.now() / 1000);
|
|
1295
|
+
const tools = chosen.agent.withoutConductorTools
|
|
1296
|
+
? undefined
|
|
1297
|
+
: this.issueRunTools(run.runUuid, { worktreePath: ws.path, ticket: t });
|
|
1298
|
+
const command = chosen.agent.launchCommand(prompt, identity, ws.path, tools ? { url: tools.url } : undefined, env);
|
|
1299
|
+
// Read after launchCommand: a warning may depend on what this launch got.
|
|
1272
1300
|
const warnings = chosen.agent.launchWarnings;
|
|
1273
1301
|
if (warnings?.length) {
|
|
1274
1302
|
const alias = chosen.alias ?? chosen.id;
|
|
@@ -1281,10 +1309,6 @@ export class Conductor {
|
|
|
1281
1309
|
}, `${chosen.agent.id}/${alias}: ${warning}`);
|
|
1282
1310
|
}
|
|
1283
1311
|
}
|
|
1284
|
-
const tools = chosen.agent.withoutConductorTools
|
|
1285
|
-
? undefined
|
|
1286
|
-
: this.issueRunTools(run.runUuid, { worktreePath: ws.path, ticket: t });
|
|
1287
|
-
const command = chosen.agent.launchCommand(prompt, identity, ws.path, tools ? { url: tools.url } : undefined, env);
|
|
1288
1312
|
await this.executor.startRun({
|
|
1289
1313
|
ticket: {
|
|
1290
1314
|
uuid: t.uuid,
|
|
@@ -1329,6 +1353,7 @@ export class Conductor {
|
|
|
1329
1353
|
agent: chosen.id,
|
|
1330
1354
|
startedAt: dispatchedAt,
|
|
1331
1355
|
});
|
|
1356
|
+
this.signalUi(ws.path);
|
|
1332
1357
|
}
|
|
1333
1358
|
/**
|
|
1334
1359
|
* Stop what a failed dispatch started (BB-599): the worker if it was
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ConductorLogger } from '@bakers-build/core';
|
|
2
|
+
import type { HookContext, HookName, HookResult } from '../plugins/executor.js';
|
|
3
|
+
import type { ConductorSettings } from '../types.js';
|
|
4
|
+
/** Runs a lifecycle-hook shell command in a cwd; rejects on non-zero exit. */
|
|
5
|
+
export type ShellRunner = (command: string, cwd: string, env?: Record<string, string>) => Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* Runs the project shell hook of one lifecycle slot. The SINGLE catch point for
|
|
8
|
+
* all lifecycle hooks:
|
|
9
|
+
*
|
|
10
|
+
* - NEVER throws. No configured command → silent no-op. A failing command →
|
|
11
|
+
* `logger.error({hook,worktree,ticket,err}, 'lifecycle hook failed')`, so a
|
|
12
|
+
* hook failure never aborts dispatch or wedges a run in `claimed`.
|
|
13
|
+
* - Reports the outcome as a {@link HookResult} (BB-237): the caller decides
|
|
14
|
+
* what a failure means for the run it is dispatching.
|
|
15
|
+
*
|
|
16
|
+
* `env`, when given, is the run's resolved environment, merged over the hook
|
|
17
|
+
* process's inherited env. Values may be secret: only key names are ever logged.
|
|
18
|
+
*/
|
|
19
|
+
export type HookRunner = (name: HookName, cwd: string, ctx: HookContext, env?: Record<string, string>) => Promise<HookResult>;
|
|
20
|
+
/** Default shell runner: `sh -c <command>` in the worktree — fails honestly. */
|
|
21
|
+
export declare const defaultShellRunner: ShellRunner;
|
|
22
|
+
/** The conductor's hook runner over the project's `hooks` commands. */
|
|
23
|
+
export declare function shellHookRunner(hooks: ConductorSettings['hooks'], logger: ConductorLogger, runShell?: ShellRunner): HookRunner;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { exec } from '@bakers-build/core';
|
|
2
|
+
/** Default shell runner: `sh -c <command>` in the worktree — fails honestly. */
|
|
3
|
+
export const defaultShellRunner = async (command, cwd, env) => {
|
|
4
|
+
await exec('sh', ['-c', command], { cwd, ...(env ? { env } : {}) });
|
|
5
|
+
};
|
|
6
|
+
/** The conductor's hook runner over the project's `hooks` commands. */
|
|
7
|
+
export function shellHookRunner(hooks, logger, runShell = defaultShellRunner) {
|
|
8
|
+
return async (name, cwd, ctx, env) => {
|
|
9
|
+
const command = hooks?.[name];
|
|
10
|
+
if (!command) {
|
|
11
|
+
return { hook: name, ran: false, ok: true };
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
await runShell(command, cwd, env);
|
|
15
|
+
return { hook: name, ran: true, ok: true };
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
logger.error({ hook: name, worktree: cwd, ticket: ctx.ticket, err: String(err) }, 'lifecycle hook failed');
|
|
19
|
+
return { hook: name, ran: true, ok: false, error: String(err) };
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ConductorLogger } from '@bakers-build/core';
|
|
2
|
+
import type { SiteToolClient } from '../plugins/remote.js';
|
|
3
|
+
import type { ToolBinding } from '../plugins/tools.js';
|
|
4
|
+
/** The site tools a run may call. */
|
|
5
|
+
export declare const SITE_TOOLS: readonly string[];
|
|
6
|
+
/** The site tools that change a ticket; a successful call signals `bakers ui`. */
|
|
7
|
+
export declare const SITE_WRITE_TOOLS: readonly string[];
|
|
8
|
+
export interface SiteTool {
|
|
9
|
+
name: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
inputSchema: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
export interface SiteToolProxy {
|
|
14
|
+
/** The allowlisted site tools; none while the site is unreachable. */
|
|
15
|
+
list(): Promise<SiteTool[]>;
|
|
16
|
+
/** Forwards an allowed call; throws a refusal or the site's error text. */
|
|
17
|
+
call(name: string, args: Record<string, unknown>, binding: ToolBinding): Promise<{
|
|
18
|
+
content: unknown[];
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
export declare function siteToolProxy(client: SiteToolClient, logger?: ConductorLogger): SiteToolProxy;
|