@bakers-build/conductor 0.5.1-next.849 → 0.5.1-next.851
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-plan.d.ts +2 -2
- package/dist/src/cli/config-plan.js +22 -503
- package/dist/src/cli/config-schema.d.ts +4 -78
- package/dist/src/cli/config-schema.js +5 -144
- package/dist/src/cli/config-templates.d.ts +1 -12
- package/dist/src/cli/config-templates.js +11 -52
- package/dist/src/cli/config-validation.js +22 -39
- package/dist/src/cli/project-context.js +1 -1
- package/dist/src/commands/conductor.d.ts +9 -1
- package/dist/src/commands/conductor.js +103 -21
- package/dist/src/config.d.ts +1 -1
- package/dist/src/config.js +31 -37
- package/dist/src/contract.d.ts +1 -0
- package/dist/src/contract.js +1 -0
- package/dist/src/core/conductor.d.ts +11 -18
- package/dist/src/core/conductor.js +33 -37
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.js +0 -7
- package/dist/src/plugins/remote.d.ts +19 -1
- package/dist/src/plugins/remote.js +13 -1
- package/dist/src/types.d.ts +9 -14
- package/package.json +4 -4
- package/dist/src/cli/migrate-addon-names.d.ts +0 -82
- package/dist/src/cli/migrate-addon-names.js +0 -334
- package/dist/src/core/host-key.d.ts +0 -19
- package/dist/src/core/host-key.js +0 -27
|
@@ -6,8 +6,7 @@ import { Command } from 'commander';
|
|
|
6
6
|
import { authStatus } from 'dropsh';
|
|
7
7
|
import { resolveBbProjectContext } from '../bakers-project-context.js';
|
|
8
8
|
import { composeConductorConfig, loadConductorConfig } from '../config.js';
|
|
9
|
-
import { Conductor } from '../core/conductor.js';
|
|
10
|
-
import { hostKeyOf } from '../core/host-key.js';
|
|
9
|
+
import { Conductor, registrationOf } from '../core/conductor.js';
|
|
11
10
|
import { selectAgents, selectExecutor, selectRemote, selectWorkspace, } from '../plugins/plugins.js';
|
|
12
11
|
import { sandboxFailures } from '../plugins/sandbox-preflight.js';
|
|
13
12
|
/** Default host bases for connection/plugin resolution when none is injected. */
|
|
@@ -63,14 +62,14 @@ function checkoutRootOf(config) {
|
|
|
63
62
|
return deriveCheckoutRoot(config.config_path);
|
|
64
63
|
}
|
|
65
64
|
/**
|
|
66
|
-
* The conductor's
|
|
67
|
-
* the
|
|
68
|
-
*
|
|
65
|
+
* The conductor's identity (bb_conductor.conductor_id), derived by the
|
|
66
|
+
* loader from the machine UUID, project and variant; lifecycle commands read
|
|
67
|
+
* it here, never re-derive.
|
|
69
68
|
*/
|
|
70
69
|
function conductorIdOf(config) {
|
|
71
|
-
const id = config.conductor_id
|
|
70
|
+
const id = config.conductor_id;
|
|
72
71
|
if (id === undefined || id.trim() === '') {
|
|
73
|
-
throw new Error('
|
|
72
|
+
throw new Error('machine.config.js has no machine_id; run bakers init');
|
|
74
73
|
}
|
|
75
74
|
return id;
|
|
76
75
|
}
|
|
@@ -153,7 +152,7 @@ async function buildLsRows(remote, config, onlyId, probe) {
|
|
|
153
152
|
// host_key (to gate it to rows that are this machine's own conductor) —
|
|
154
153
|
// `config` used to be ignored here, which is why `ls`/`status` never probed
|
|
155
154
|
// the local pid at all and relied purely on the record.
|
|
156
|
-
const thisHostKey = config ?
|
|
155
|
+
const thisHostKey = config ? (config.host_key?.trim() ?? '') : undefined;
|
|
157
156
|
return hub
|
|
158
157
|
.filter((c) => !onlyId || c.id === onlyId)
|
|
159
158
|
.map((c) => ({
|
|
@@ -170,7 +169,7 @@ function printRows(rows) {
|
|
|
170
169
|
return;
|
|
171
170
|
}
|
|
172
171
|
for (const r of rows) {
|
|
173
|
-
console.log(`${r.
|
|
172
|
+
console.log(`${r.label}\t${r.status}\t${r.project}\t${r.workspaceRoot}\t${r.id}`);
|
|
174
173
|
}
|
|
175
174
|
}
|
|
176
175
|
// --- command handlers -------------------------------------------------------
|
|
@@ -290,7 +289,7 @@ async function refuseIfAlreadyRunning(remote, id, thisHostKey, force, deps) {
|
|
|
290
289
|
console.log(`stopped conductor ${id} for restart (--force)`);
|
|
291
290
|
return false;
|
|
292
291
|
}
|
|
293
|
-
async function cmdStartForeground(deps, log = {}, force = false) {
|
|
292
|
+
async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
|
|
294
293
|
const config = await resolveConfig(deps, undefined, true);
|
|
295
294
|
const checkoutRoot = await checkoutRootOf(config);
|
|
296
295
|
const logger = loggerFor(checkoutRoot, log);
|
|
@@ -298,9 +297,16 @@ async function cmdStartForeground(deps, log = {}, force = false) {
|
|
|
298
297
|
return;
|
|
299
298
|
const remote = await resolveRemote(deps, config);
|
|
300
299
|
const id = conductorIdOf(config);
|
|
301
|
-
const thisHostKey =
|
|
300
|
+
const thisHostKey = config.host_key?.trim() ?? '';
|
|
302
301
|
if (await refuseIfAlreadyRunning(remote, id, thisHostKey, force, deps))
|
|
303
302
|
return;
|
|
303
|
+
// This process is the conductor: its takeover registration carries its pid.
|
|
304
|
+
const serve = {
|
|
305
|
+
...registrationOf(config, checkoutRoot),
|
|
306
|
+
last_pid: process.pid,
|
|
307
|
+
};
|
|
308
|
+
if (!(await settleTakeover(deps, remote, serve, choice)))
|
|
309
|
+
return;
|
|
304
310
|
const executor = deps.executor ?? (await selectExecutor(config, logger));
|
|
305
311
|
const workspace = deps.workspace ?? (await selectWorkspace(config, logger));
|
|
306
312
|
const agents = deps.agents ?? (await selectAgents(config));
|
|
@@ -363,6 +369,71 @@ async function defaultAskUpdate(question) {
|
|
|
363
369
|
rl.close();
|
|
364
370
|
}
|
|
365
371
|
}
|
|
372
|
+
/** Whether a human can answer a question on this terminal. */
|
|
373
|
+
function isInteractive(deps) {
|
|
374
|
+
return ((deps.stdinIsTTY ?? Boolean(process.stdin.isTTY)) &&
|
|
375
|
+
(deps.stdoutIsTTY ?? Boolean(process.stdout.isTTY)) &&
|
|
376
|
+
!(deps.env ?? process.env).CI);
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Settles, once, a conductor whose derived id the control plane does not know
|
|
380
|
+
* yet: registering it either succeeds, or the control plane offers the
|
|
381
|
+
* conductor this machine, project and variant already have under an older id.
|
|
382
|
+
* A terminal asks whether to take it over (or which, when there are several);
|
|
383
|
+
* any other answer than a choice or no cancels. Without one the start stops with
|
|
384
|
+
* the control plane's own `--adopt`/`--new` hint. After this the id is known,
|
|
385
|
+
* so no later start (nor the herdr child, which has no terminal) asks again.
|
|
386
|
+
* Returns false when the start must stop.
|
|
387
|
+
*/
|
|
388
|
+
async function settleTakeover(deps, remote, registration, choice) {
|
|
389
|
+
const id = registration.id;
|
|
390
|
+
if ((await remote.listConductors('me')).some((c) => c.id === id))
|
|
391
|
+
return true;
|
|
392
|
+
const reg = {
|
|
393
|
+
...registration,
|
|
394
|
+
...(choice.adopt ? { adopt: choice.adopt } : {}),
|
|
395
|
+
...(choice.createNew ? { create_new: true } : {}),
|
|
396
|
+
};
|
|
397
|
+
try {
|
|
398
|
+
await remote.registerConductor(reg);
|
|
399
|
+
return true;
|
|
400
|
+
}
|
|
401
|
+
catch (caught) {
|
|
402
|
+
// By name: the remote addon may load its own copy of the contract class.
|
|
403
|
+
if (caught?.name !== 'ConductorTakeoverRequired')
|
|
404
|
+
throw caught;
|
|
405
|
+
const err = caught;
|
|
406
|
+
const { adoptable } = err;
|
|
407
|
+
if (!isInteractive(deps) || adoptable.length === 0) {
|
|
408
|
+
console.error(err.message);
|
|
409
|
+
process.exitCode = 1;
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
const one = adoptable.length === 1;
|
|
413
|
+
const question = one
|
|
414
|
+
? `${err.message}\nTake it over? [Y/n]`
|
|
415
|
+
: `${err.message}\n${adoptable.map((uuid, i) => `${i + 1}) ${uuid}`).join('\n')}\nTake over which? [1-${adoptable.length}, n for a new one]`;
|
|
416
|
+
let answer;
|
|
417
|
+
try {
|
|
418
|
+
answer = (await (deps.askUpdate ?? defaultAskUpdate)(question))
|
|
419
|
+
.trim()
|
|
420
|
+
.toLowerCase();
|
|
421
|
+
}
|
|
422
|
+
catch {
|
|
423
|
+
answer = 'cancel';
|
|
424
|
+
}
|
|
425
|
+
const adopt = one && ['', 'y', 'yes'].includes(answer)
|
|
426
|
+
? adoptable[0]
|
|
427
|
+
: adoptable[Number(answer) - 1];
|
|
428
|
+
if (!adopt && answer !== 'n' && answer !== 'no') {
|
|
429
|
+
console.error('Start cancelled.');
|
|
430
|
+
process.exitCode = 1;
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
await remote.registerConductor(adopt ? { ...reg, adopt } : { ...reg, create_new: true });
|
|
434
|
+
return true;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
366
437
|
async function cmdStart(deps, log = {}, updateCheck = true, body = cmdStartBody, force = false, foreground = false) {
|
|
367
438
|
const current = printVersionLine();
|
|
368
439
|
if (updateCheck) {
|
|
@@ -378,10 +449,7 @@ async function cmdStart(deps, log = {}, updateCheck = true, body = cmdStartBody,
|
|
|
378
449
|
? updateNotice(current, result.latestVersion)
|
|
379
450
|
: null;
|
|
380
451
|
const env = deps.env ?? process.env;
|
|
381
|
-
const interactive = !foreground &&
|
|
382
|
-
(deps.stdinIsTTY ?? Boolean(process.stdin.isTTY)) &&
|
|
383
|
-
(deps.stdoutIsTTY ?? Boolean(process.stdout.isTTY)) &&
|
|
384
|
-
!env.CI;
|
|
452
|
+
const interactive = !foreground && isInteractive(deps);
|
|
385
453
|
if (notice && interactive && result.declined !== true) {
|
|
386
454
|
console.log('Installing accepts the newer release and runs configuration migration.');
|
|
387
455
|
console.log('After a successful install this start exits; rerun the start command to use the new release.');
|
|
@@ -567,7 +635,7 @@ async function waitForNotRunning(probe, pid, deps) {
|
|
|
567
635
|
* `no-pid` refusal `signalVerifiedProcess` already gives — is **failed** and
|
|
568
636
|
* never falls through to a second spawn (AC-14/AC-20's two-conductors risk).
|
|
569
637
|
*/
|
|
570
|
-
async function cmdStartBody(deps, log, force = false) {
|
|
638
|
+
async function cmdStartBody(deps, log, force = false, choice = {}) {
|
|
571
639
|
const config = await resolveConfig(deps, undefined, true);
|
|
572
640
|
const checkoutRoot = await checkoutRootOf(config);
|
|
573
641
|
const logger = loggerFor(checkoutRoot, log);
|
|
@@ -583,7 +651,7 @@ async function cmdStartBody(deps, log, force = false) {
|
|
|
583
651
|
catch { }
|
|
584
652
|
const remote = await resolveRemote(deps, config);
|
|
585
653
|
const id = conductorIdOf(config);
|
|
586
|
-
const thisHostKey =
|
|
654
|
+
const thisHostKey = config.host_key?.trim() ?? '';
|
|
587
655
|
// Block on the DERIVED status, not the raw one. A crashed conductor keeps
|
|
588
656
|
// `status: online` on its record until the cron reaper notices the lapsed
|
|
589
657
|
// lease, and those are precisely the minutes in which someone wants to
|
|
@@ -639,8 +707,10 @@ async function cmdStartBody(deps, log, force = false) {
|
|
|
639
707
|
}
|
|
640
708
|
console.log(`stopped conductor ${id} for restart (--force)`);
|
|
641
709
|
}
|
|
642
|
-
// The
|
|
643
|
-
|
|
710
|
+
// The herdr child has no terminal, so a takeover is settled here first.
|
|
711
|
+
if (!existing &&
|
|
712
|
+
!(await settleTakeover(deps, remote, registrationOf(config, checkoutRoot), choice)))
|
|
713
|
+
return;
|
|
644
714
|
const handle = `bakers-conductor:${id}`;
|
|
645
715
|
const fgFlags = [
|
|
646
716
|
log.level ? `--log-level ${log.level}` : '',
|
|
@@ -711,7 +781,7 @@ async function cmdStop(deps, now) {
|
|
|
711
781
|
const config = await resolveConfig(deps);
|
|
712
782
|
const remote = await resolveRemote(deps, config);
|
|
713
783
|
const id = conductorIdOf(config);
|
|
714
|
-
const thisHostKey =
|
|
784
|
+
const thisHostKey = config.host_key?.trim() ?? '';
|
|
715
785
|
const rows = await remote.listConductors('me');
|
|
716
786
|
const row = rows.find((c) => c.id === id);
|
|
717
787
|
if (!row) {
|
|
@@ -793,8 +863,20 @@ Examples:
|
|
|
793
863
|
.option('--force', 'restart: verify-stop the already-running conductor (SIGTERM, a grace ' +
|
|
794
864
|
'period, then SIGKILL) and start a new one. Fails rather than starting ' +
|
|
795
865
|
'a second conductor if the running one cannot be verified or stopped.', false)
|
|
866
|
+
.option('--adopt <uuid>', 'take over the conductor this machine, project and variant already have')
|
|
867
|
+
.option('--new', 'register a new conductor instead of taking one over')
|
|
796
868
|
.action(async function (opts) {
|
|
797
|
-
|
|
869
|
+
if (opts.adopt && opts.new) {
|
|
870
|
+
console.error('Choose either --adopt <uuid> or --new, not both.');
|
|
871
|
+
process.exitCode = 1;
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
const choice = {
|
|
875
|
+
...(opts.adopt ? { adopt: opts.adopt } : {}),
|
|
876
|
+
...(opts.new ? { createNew: true } : {}),
|
|
877
|
+
};
|
|
878
|
+
const body = opts.foreground ? cmdStartForeground : cmdStartBody;
|
|
879
|
+
await cmdStart(deps, logOptsOf(this), opts.updateCheck, (d, l, f) => body(d, l, f, choice), opts.force, opts.foreground);
|
|
798
880
|
});
|
|
799
881
|
conductor
|
|
800
882
|
.command('once')
|
package/dist/src/config.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ export declare const DEFAULT_AGENT_PROMPT: string;
|
|
|
57
57
|
export declare function resolveAgents(raw: unknown, configPath: string): Promise<AgentCandidate | AgentCandidate[]>;
|
|
58
58
|
/**
|
|
59
59
|
* Load the ENGINE half of a conductor config (BB-201 split model). Reads
|
|
60
|
-
* remote/executor/agent/workspace + project/states/
|
|
60
|
+
* remote/executor/agent/workspace + project/states/prompt/
|
|
61
61
|
* scheduler/hooks — and deliberately NOT `site` or the auth `plugins`, which now
|
|
62
62
|
* live in a `bakers.config.js` connection config. The conductor command composes
|
|
63
63
|
* the two via `composeConductorConfig`. A legacy `conductor.config.js` still
|
package/dist/src/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readdirSync } from 'node:fs';
|
|
2
|
-
import { resolve } from 'node:path';
|
|
2
|
+
import { basename, resolve } from 'node:path';
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
|
-
import { discoverAddons, discoverScoped, findDefaultExportObject, machineContextPath, matchDelimiter, readMachineContext, resolveConductorSlots, resolveModuleEslintStyle, scanTopLevelProperties, scopeAddons, } from '@bakers-build/core';
|
|
4
|
+
import { assertSchemaVersion1, discoverAddons, discoverScoped, findDefaultExportObject, machineContextPath, matchDelimiter, readMachineContext, resolveConductorSlots, resolveModuleEslintStyle, scanTopLevelProperties, scopeAddons, stemForConfigFile, } from '@bakers-build/core';
|
|
5
5
|
import { readBbProjectSelection } from './cli/project-context.js';
|
|
6
6
|
import { loadInbox } from './plugins/message.js';
|
|
7
7
|
import { narrowConductorContributions, } from './plugins/preset.js';
|
|
@@ -242,9 +242,27 @@ function optionalPositiveInteger(value, fallback, key) {
|
|
|
242
242
|
}
|
|
243
243
|
return value;
|
|
244
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* A conductor is machine + project + variant: its registration key and label
|
|
247
|
+
* are derived here and never written to a config.
|
|
248
|
+
*/
|
|
249
|
+
function identityOf(machine, project, variant) {
|
|
250
|
+
const suffix = variant === 'conductor' ? '' : `/${variant}`;
|
|
251
|
+
const label = machine.label?.trim() || undefined;
|
|
252
|
+
return {
|
|
253
|
+
label: `${label ? `${label} · ` : ''}${project}${suffix}`,
|
|
254
|
+
...(machine.machine_id
|
|
255
|
+
? {
|
|
256
|
+
host_key: machine.machine_id,
|
|
257
|
+
conductor_id: `${machine.machine_id}-${project}-${variant}`,
|
|
258
|
+
}
|
|
259
|
+
: {}),
|
|
260
|
+
...(label ? { machine_label: label } : {}),
|
|
261
|
+
};
|
|
262
|
+
}
|
|
245
263
|
/**
|
|
246
264
|
* Load the ENGINE half of a conductor config (BB-201 split model). Reads
|
|
247
|
-
* remote/executor/agent/workspace + project/states/
|
|
265
|
+
* remote/executor/agent/workspace + project/states/prompt/
|
|
248
266
|
* scheduler/hooks — and deliberately NOT `site` or the auth `plugins`, which now
|
|
249
267
|
* live in a `bakers.config.js` connection config. The conductor command composes
|
|
250
268
|
* the two via `composeConductorConfig`. A legacy `conductor.config.js` still
|
|
@@ -268,6 +286,11 @@ export async function loadConductorConfig(configFile) {
|
|
|
268
286
|
console.warn(`warning: ${configPath} declares ${leftover.join('/')} — ignored; ` +
|
|
269
287
|
'auth/connection belong in the sibling bakers.config.js (BB-218)');
|
|
270
288
|
}
|
|
289
|
+
assertSchemaVersion1(configPath, raw);
|
|
290
|
+
// A conductor is machine + project + variant: the project config names no id.
|
|
291
|
+
const identity = ['conductor_id', 'machine_id', 'label'].filter((key) => key in raw);
|
|
292
|
+
if (identity.length > 0)
|
|
293
|
+
throw new Error(`${configPath}: ${identity.join(', ')} no longer belong in a project config (a conductor is machine + project + variant); remove them and run bakers init`);
|
|
271
294
|
const config = raw;
|
|
272
295
|
const retiredAgentKeys = [
|
|
273
296
|
'agent',
|
|
@@ -285,30 +308,9 @@ export async function loadConductorConfig(configFile) {
|
|
|
285
308
|
const states = Array.isArray(config.states)
|
|
286
309
|
? config.states.map((state) => requireNonEmptyString(state, 'states'))
|
|
287
310
|
: [];
|
|
288
|
-
// conductor_id is required (BB-353 renamed from machine_id). Prefer the new
|
|
289
|
-
// key; accept legacy machine_id with a one-shot warning. No derived fallback.
|
|
290
|
-
// A repo's committed config composes it from the machine context
|
|
291
|
-
// (`${user_id}-${host}-${project}`); co-located configs each compose their
|
|
292
|
-
// own from their project.
|
|
293
|
-
let conductorId;
|
|
294
|
-
if (typeof config.conductor_id === 'string' &&
|
|
295
|
-
config.conductor_id.trim() !== '') {
|
|
296
|
-
conductorId = config.conductor_id.trim();
|
|
297
|
-
}
|
|
298
|
-
else if (typeof config.machine_id === 'string' &&
|
|
299
|
-
config.machine_id.trim() !== '') {
|
|
300
|
-
console.warn(`[bakers] ${configPath}: engine key "machine_id" is deprecated; use "conductor_id" (BB-353)`);
|
|
301
|
-
conductorId = config.machine_id.trim();
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
throw new Error(`conductor config requires non-empty conductor_id (legacy machine_id accepted)`);
|
|
305
|
-
}
|
|
306
|
-
const label = typeof config.label === 'string' && config.label.trim() !== ''
|
|
307
|
-
? config.label
|
|
308
|
-
: conductorId;
|
|
309
311
|
// Host capacity has one owner. Stale engine values need an explicit migration.
|
|
310
312
|
if (config.max_parallel !== undefined) {
|
|
311
|
-
throw new Error(`${configPath}: misplaced max_parallel belongs in ${machineContextPath()};
|
|
313
|
+
throw new Error(`${configPath}: misplaced max_parallel belongs in ${machineContextPath()}; move it there`);
|
|
312
314
|
}
|
|
313
315
|
const machineCtx = await readMachineContext();
|
|
314
316
|
const maxParallel = typeof machineCtx.max_parallel === 'number' &&
|
|
@@ -317,12 +319,7 @@ export async function loadConductorConfig(configFile) {
|
|
|
317
319
|
? Math.floor(machineCtx.max_parallel)
|
|
318
320
|
: 1;
|
|
319
321
|
const tunnel = machineCtx.tunnel === true;
|
|
320
|
-
|
|
321
|
-
// context id over hyphen-splitting the composed conductor_id.
|
|
322
|
-
const hostKey = typeof machineCtx.machine_id === 'string' &&
|
|
323
|
-
machineCtx.machine_id.trim() !== ''
|
|
324
|
-
? machineCtx.machine_id.trim()
|
|
325
|
-
: undefined;
|
|
322
|
+
const variant = stemForConfigFile(basename(configPath)) ?? 'conductor';
|
|
326
323
|
// BB-215: discover the conductor `addons: []` surface (last-wins singletons,
|
|
327
324
|
// agent candidate list). A pre-existing per-slot descriptor still loads and
|
|
328
325
|
// WINS over a discovered contributor of the same kind (back-compat additive).
|
|
@@ -338,7 +335,7 @@ export async function loadConductorConfig(configFile) {
|
|
|
338
335
|
if (policy !== undefined && !isRecord(policy))
|
|
339
336
|
throw new Error('machine agents must be an object');
|
|
340
337
|
if (policy?.addons !== undefined)
|
|
341
|
-
throw new Error('machine agents.addons is retired: move its entries into machine.config.js addons[]
|
|
338
|
+
throw new Error('machine agents.addons is retired: move its entries into machine.config.js addons[]');
|
|
342
339
|
const machineAddons = machineCtx.addons ?? [];
|
|
343
340
|
if (!Array.isArray(machineAddons))
|
|
344
341
|
throw new Error('machine addons must be an array');
|
|
@@ -545,10 +542,8 @@ export async function loadConductorConfig(configFile) {
|
|
|
545
542
|
...(inboxAddons.length > 0 ? { inboxAddons } : {}),
|
|
546
543
|
...(processHost !== undefined ? { processHost } : {}),
|
|
547
544
|
bakers,
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
// Soft alias so callers that still read machine_id keep working this cut.
|
|
551
|
-
machine_id: conductorId,
|
|
545
|
+
...identityOf(machineCtx, project, variant),
|
|
546
|
+
variant,
|
|
552
547
|
project,
|
|
553
548
|
states,
|
|
554
549
|
prompt: typeof config.prompt === 'string' && config.prompt.trim() !== ''
|
|
@@ -556,7 +551,6 @@ export async function loadConductorConfig(configFile) {
|
|
|
556
551
|
: DEFAULT_AGENT_PROMPT,
|
|
557
552
|
max_parallel: maxParallel,
|
|
558
553
|
tunnel,
|
|
559
|
-
...(hostKey !== undefined ? { host_key: hostKey } : {}),
|
|
560
554
|
poll_interval_ms: optionalPositiveInteger(config.poll_interval_ms, 5000, 'poll_interval_ms'),
|
|
561
555
|
lease_seconds: optionalPositiveInteger(config.lease_seconds, 300, 'lease_seconds'),
|
|
562
556
|
...(config.hooks !== undefined ? { hooks: config.hooks } : {}),
|
package/dist/src/contract.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export { resolveAgent, selectAgent, selectAgents, selectExecutor, selectRemote,
|
|
|
9
9
|
export { type ConductorAddonEntry, type ConductorContributions, narrowConductorContributions, type Preset, } from './plugins/preset.js';
|
|
10
10
|
export type { HerdrHost } from './plugins/process-host.js';
|
|
11
11
|
export type { ActiveRun, AddonDefinitionV2, AddonRegistration, BbRemote, ClaimedRun, ClaimOptions, ClaimWithheld, ConductorRegistration, ConductorStatus, FinalizableRun, FrozenTicket, InboxMessage, InboxSnapshot, RunMetrics, RunWriteAttributes, Ticket, TicketMetric, UncleanTicket, } from './plugins/remote.js';
|
|
12
|
+
export { ConductorTakeoverRequired } from './plugins/remote.js';
|
|
12
13
|
export { installCommand, lastLine, type SandboxHost, type SandboxPreflight, sandboxFailures, systemSandboxHost, } from './plugins/sandbox-preflight.js';
|
|
13
14
|
export type { BbWorkspace, EnsuredWorkspace, } from './plugins/workspace.js';
|
|
14
15
|
export type { ConductorEngineConfig, ConductorFileConfig, ConductorSettings, } from './types.js';
|
package/dist/src/contract.js
CHANGED
|
@@ -17,4 +17,5 @@ export { detectKnownOverrides, resolveAgentCliOptions, resolveSecurityOptions, S
|
|
|
17
17
|
export { loadInbox, validateRequestPayload, } from './plugins/message.js';
|
|
18
18
|
export { resolveAgent, selectAgent, selectAgents, selectExecutor, selectRemote, selectWorkspace, } from './plugins/plugins.js';
|
|
19
19
|
export { narrowConductorContributions, } from './plugins/preset.js';
|
|
20
|
+
export { ConductorTakeoverRequired } from './plugins/remote.js';
|
|
20
21
|
export { installCommand, lastLine, sandboxFailures, systemSandboxHost, } from './plugins/sandbox-preflight.js';
|
|
@@ -2,7 +2,7 @@ import { type ConductorLogger } from '@bakers-build/core';
|
|
|
2
2
|
import { type RunEnvPolicy } from '../plugins/agent.js';
|
|
3
3
|
import type { BbExecutor } from '../plugins/executor.js';
|
|
4
4
|
import { type ResolvedAgent } from '../plugins/plugins.js';
|
|
5
|
-
import type { BbRemote } from '../plugins/remote.js';
|
|
5
|
+
import type { BbRemote, ConductorRegistration } from '../plugins/remote.js';
|
|
6
6
|
import type { BbWorkspace } from '../plugins/workspace.js';
|
|
7
7
|
import type { ConductorFileConfig } from '../types.js';
|
|
8
8
|
/**
|
|
@@ -18,6 +18,13 @@ export declare function resolveRunEnv(effectiveEnvVars: string | undefined, core
|
|
|
18
18
|
ticket?: string;
|
|
19
19
|
policy?: RunEnvPolicy;
|
|
20
20
|
}): Record<string, string>;
|
|
21
|
+
/**
|
|
22
|
+
* A conductor's registration payload, built from its config: what the engine
|
|
23
|
+
* heartbeats with, and what `oven start` registers before it spawns one.
|
|
24
|
+
* `conductor_name` is the variant (the config stem, derived through core's
|
|
25
|
+
* own mapping), which the control plane matches a takeover on.
|
|
26
|
+
*/
|
|
27
|
+
export declare function registrationOf(config: ConductorFileConfig, checkoutRoot: string): ConductorRegistration;
|
|
21
28
|
export declare class Conductor {
|
|
22
29
|
private readonly config;
|
|
23
30
|
private readonly remote;
|
|
@@ -44,17 +51,11 @@ export declare class Conductor {
|
|
|
44
51
|
constructor(config: ConductorFileConfig, remote: BbRemote, executor: BbExecutor, workspace: BbWorkspace, agents: ResolvedAgent[], logger: ConductorLogger, checkoutRoot?: string, frozenStateFile?: string | undefined);
|
|
45
52
|
private serialGit;
|
|
46
53
|
/**
|
|
47
|
-
* `conductor_id` is
|
|
48
|
-
* there is no directory-derived fallback
|
|
49
|
-
* was the mechanism by which one checkout came to be registered under two
|
|
50
|
-
* different ids.
|
|
54
|
+
* `conductor_id` is derived by the loader from the machine UUID, project and
|
|
55
|
+
* variant; there is no directory-derived fallback (BB-450 D5).
|
|
51
56
|
*/
|
|
52
57
|
get id(): string;
|
|
53
|
-
/**
|
|
54
|
-
* Host stem for bb_machine.host_key. Prefer config.host_key from
|
|
55
|
-
* MachineContext.machine_id; fall back to a best-effort parse of the composed
|
|
56
|
-
* conductor_id only when the loader could not supply the stem.
|
|
57
|
-
*/
|
|
58
|
+
/** This machine's id (machine_id), bb_machine.host_key. */
|
|
58
59
|
private get hostKey();
|
|
59
60
|
/**
|
|
60
61
|
* Whether this instance is the serve-loop process itself (BB-232).
|
|
@@ -77,14 +78,6 @@ export declare class Conductor {
|
|
|
77
78
|
claimServeProcess(): void;
|
|
78
79
|
/** This conductor's registration payload, built from config. */
|
|
79
80
|
private registration;
|
|
80
|
-
/**
|
|
81
|
-
* The stem of the config file this conductor was loaded from.
|
|
82
|
-
*
|
|
83
|
-
* Derived through core's own mapping rather than by slicing the filename
|
|
84
|
-
* here, so the CLI and the conductor cannot disagree about which files count
|
|
85
|
-
* as a conductor config.
|
|
86
|
-
*/
|
|
87
|
-
private get conductorName();
|
|
88
81
|
start(): Promise<void>;
|
|
89
82
|
/** One tick that also waits for its actions: `bakers oven once`, tests. */
|
|
90
83
|
tick(): Promise<void>;
|
|
@@ -6,7 +6,6 @@ import { resolveAgent } from '../plugins/plugins.js';
|
|
|
6
6
|
import { sandboxFailures } from '../plugins/sandbox-preflight.js';
|
|
7
7
|
import { ActionQueue } from './action-queue.js';
|
|
8
8
|
import { attemptFamily } from './attempt.js';
|
|
9
|
-
import { hostKeyOf } from './host-key.js';
|
|
10
9
|
import { InboxRuntime, runInbox } from './inbox-runtime.js';
|
|
11
10
|
import { measureMrChanges, mrChangesRows } from './mr-changes.js';
|
|
12
11
|
function sleep(ms, signal) {
|
|
@@ -155,6 +154,28 @@ function renderPrompt(template, values) {
|
|
|
155
154
|
.replaceAll('{runUuid}', values.runUuid)
|
|
156
155
|
.replaceAll('{ticketUuid}', values.ticketUuid);
|
|
157
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* A conductor's registration payload, built from its config: what the engine
|
|
159
|
+
* heartbeats with, and what `oven start` registers before it spawns one.
|
|
160
|
+
* `conductor_name` is the variant (the config stem, derived through core's
|
|
161
|
+
* own mapping), which the control plane matches a takeover on.
|
|
162
|
+
*/
|
|
163
|
+
export function registrationOf(config, checkoutRoot) {
|
|
164
|
+
const stem = config.config_path
|
|
165
|
+
? stemForConfigFile(basename(config.config_path))
|
|
166
|
+
: undefined;
|
|
167
|
+
return {
|
|
168
|
+
id: config.conductor_id ?? '',
|
|
169
|
+
...(config.host_key ? { host_key: config.host_key } : {}),
|
|
170
|
+
project: config.project,
|
|
171
|
+
states: config.states,
|
|
172
|
+
workspace: checkoutRoot,
|
|
173
|
+
label: config.label,
|
|
174
|
+
...(config.machine_label ? { machine_label: config.machine_label } : {}),
|
|
175
|
+
max_parallel: config.max_parallel,
|
|
176
|
+
conductor_name: stem ?? config.variant,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
158
179
|
export class Conductor {
|
|
159
180
|
config;
|
|
160
181
|
remote;
|
|
@@ -196,25 +217,19 @@ export class Conductor {
|
|
|
196
217
|
return result;
|
|
197
218
|
}
|
|
198
219
|
/**
|
|
199
|
-
* `conductor_id` is
|
|
200
|
-
* there is no directory-derived fallback
|
|
201
|
-
* was the mechanism by which one checkout came to be registered under two
|
|
202
|
-
* different ids.
|
|
220
|
+
* `conductor_id` is derived by the loader from the machine UUID, project and
|
|
221
|
+
* variant; there is no directory-derived fallback (BB-450 D5).
|
|
203
222
|
*/
|
|
204
223
|
get id() {
|
|
205
|
-
const id = this.config.conductor_id
|
|
224
|
+
const id = this.config.conductor_id;
|
|
206
225
|
if (id === undefined || id.trim() === '') {
|
|
207
|
-
throw new Error('
|
|
226
|
+
throw new Error('machine.config.js has no machine_id; run bakers init');
|
|
208
227
|
}
|
|
209
228
|
return id;
|
|
210
229
|
}
|
|
211
|
-
/**
|
|
212
|
-
* Host stem for bb_machine.host_key. Prefer config.host_key from
|
|
213
|
-
* MachineContext.machine_id; fall back to a best-effort parse of the composed
|
|
214
|
-
* conductor_id only when the loader could not supply the stem.
|
|
215
|
-
*/
|
|
230
|
+
/** This machine's id (machine_id), bb_machine.host_key. */
|
|
216
231
|
get hostKey() {
|
|
217
|
-
return
|
|
232
|
+
return this.config.host_key?.trim() ?? '';
|
|
218
233
|
}
|
|
219
234
|
/**
|
|
220
235
|
* Whether this instance is the serve-loop process itself (BB-232).
|
|
@@ -239,33 +254,14 @@ export class Conductor {
|
|
|
239
254
|
}
|
|
240
255
|
/** This conductor's registration payload, built from config. */
|
|
241
256
|
registration() {
|
|
257
|
+
// `this.id` throws, naming bakers init, before anything is sent.
|
|
242
258
|
const base = {
|
|
259
|
+
...registrationOf(this.config, this.checkoutRoot),
|
|
243
260
|
id: this.id,
|
|
244
|
-
host_key: this.hostKey,
|
|
245
|
-
project: this.config.project,
|
|
246
|
-
states: this.config.states,
|
|
247
|
-
workspace: this.checkoutRoot,
|
|
248
|
-
label: this.config.label,
|
|
249
|
-
max_parallel: this.config.max_parallel,
|
|
250
261
|
};
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
return {
|
|
254
|
-
...base,
|
|
255
|
-
last_pid: process.pid,
|
|
256
|
-
...(this.conductorName ? { conductor_name: this.conductorName } : {}),
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* The stem of the config file this conductor was loaded from.
|
|
261
|
-
*
|
|
262
|
-
* Derived through core's own mapping rather than by slicing the filename
|
|
263
|
-
* here, so the CLI and the conductor cannot disagree about which files count
|
|
264
|
-
* as a conductor config.
|
|
265
|
-
*/
|
|
266
|
-
get conductorName() {
|
|
267
|
-
const path = this.config.config_path;
|
|
268
|
-
return path ? stemForConfigFile(basename(path)) : undefined;
|
|
262
|
+
// Only the serve process reports its pid; poll and reap must not
|
|
263
|
+
// overwrite the running conductor's.
|
|
264
|
+
return this.ownsServeProcess ? { ...base, last_pid: process.pid } : base;
|
|
269
265
|
}
|
|
270
266
|
async start() {
|
|
271
267
|
this.uuid = await this.remote.registerConductor(this.registration());
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export type * from '@bakers-build/core';
|
|
2
|
-
export { conductorId } from '@bakers-build/core';
|
|
3
2
|
export { BB_CONFIG_SCHEMA_VERSION, readConfigSchemaVersion, } from './cli/config-schema.js';
|
|
4
|
-
export { type AddonRenameResult, type ConfigSurface, HOST_BARREL_PATHS, migrateAddonNames, migrateAddonNamesInFile, RENAMED_ADDONS, runAddonRenameMigration, } from './cli/migrate-addon-names.js';
|
|
5
3
|
export { type BbCliDeps, default as conductorCommandPlugin, runConductorCli, } from './commands/conductor.js';
|
|
6
4
|
export { composeConductorConfig, DEFAULT_AGENT_PROMPT, loadConductorConfig, resolveConfigPath, stripLegacyConnectionFromConfigSource, } from './config.js';
|
|
7
5
|
export * from './contract.js';
|
package/dist/src/index.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
// BB-224: the conductor registry lives ONLY in `@bakers-build/core` — the former
|
|
2
|
-
// thin re-export shim under `./cli/` is deleted and importers name core direct.
|
|
3
|
-
export { conductorId } from '@bakers-build/core';
|
|
4
1
|
// BB-216: the connection-config schema version + its regex reader. BB-230:
|
|
5
2
|
// the host's `bakers config upgrade` intro prints the `from → to` pair from these.
|
|
6
3
|
export { BB_CONFIG_SCHEMA_VERSION, readConfigSchemaVersion, } from './cli/config-schema.js';
|
|
7
|
-
// BB-224 (Finding 8b): the addon package-name rename pass `bakers config upgrade` runs
|
|
8
|
-
// as its last step (`@bakers-build/plugin-*` + the deleted `@bakers-build/core/builtins`
|
|
9
|
-
// and `@bakers-build/core/plugins` → `@bakers-build/addon-*`).
|
|
10
|
-
export { HOST_BARREL_PATHS, migrateAddonNames, migrateAddonNamesInFile, RENAMED_ADDONS, runAddonRenameMigration, } from './cli/migrate-addon-names.js';
|
|
11
4
|
// BB-201: the conductor is now a COMMAND PLUGIN mounted by the `@bakers-build/bakers`
|
|
12
5
|
// host, not the CLI entrypoint. `main`/`runBbCli` are gone; the default export
|
|
13
6
|
// is the `BbCommandPlugin`, exposed here as `./commands/conductor` too.
|
|
@@ -11,8 +11,10 @@ export interface AddonDefinitionV2 {
|
|
|
11
11
|
export interface ConductorRegistration {
|
|
12
12
|
/** Conductor process registration key (bb_conductor.conductor_id). */
|
|
13
13
|
id: string;
|
|
14
|
-
/**
|
|
14
|
+
/** This machine's UUID (bb_machine.host_key / MachineContext.machine_id). */
|
|
15
15
|
host_key?: string;
|
|
16
|
+
/** This machine's display label; names a newly created bb_machine. */
|
|
17
|
+
machine_label?: string;
|
|
16
18
|
project: string;
|
|
17
19
|
/** Empty = serve all claimable states in the project (BB-207). */
|
|
18
20
|
states: string[];
|
|
@@ -35,6 +37,22 @@ export interface ConductorRegistration {
|
|
|
35
37
|
* conductor in a repo that holds several.
|
|
36
38
|
*/
|
|
37
39
|
conductor_name?: string;
|
|
40
|
+
/**
|
|
41
|
+
* The answer to {@link ConductorTakeoverRequired}: take over this conductor
|
|
42
|
+
* (its UUID), or register another one (`create_new`).
|
|
43
|
+
*/
|
|
44
|
+
adopt?: string;
|
|
45
|
+
create_new?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A registration the control plane refused because this machine, project and
|
|
49
|
+
* variant already have a conductor under another id. `adoptable` are the
|
|
50
|
+
* UUIDs it offers; the message says how to decide.
|
|
51
|
+
*/
|
|
52
|
+
export declare class ConductorTakeoverRequired extends Error {
|
|
53
|
+
readonly adoptable: string[];
|
|
54
|
+
readonly name = "ConductorTakeoverRequired";
|
|
55
|
+
constructor(message: string, adoptable: string[]);
|
|
38
56
|
}
|
|
39
57
|
export interface ClaimOptions {
|
|
40
58
|
leaseSeconds: number;
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A registration the control plane refused because this machine, project and
|
|
3
|
+
* variant already have a conductor under another id. `adoptable` are the
|
|
4
|
+
* UUIDs it offers; the message says how to decide.
|
|
5
|
+
*/
|
|
6
|
+
export class ConductorTakeoverRequired extends Error {
|
|
7
|
+
adoptable;
|
|
8
|
+
name = 'ConductorTakeoverRequired';
|
|
9
|
+
constructor(message, adoptable) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.adoptable = adoptable;
|
|
12
|
+
}
|
|
13
|
+
}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -9,19 +9,18 @@ import type { HerdrHost } from './plugins/process-host.js';
|
|
|
9
9
|
import type { Ticket } from './plugins/remote.js';
|
|
10
10
|
/** Normalized single conductor. */
|
|
11
11
|
export interface ConductorSettings {
|
|
12
|
-
/**
|
|
12
|
+
/** Display label, sent once at registration: `<machine label> · <project>[/<variant>]`. */
|
|
13
13
|
label: string;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
* as
|
|
17
|
-
*
|
|
18
|
-
* it (conductor assignment is the run-start trigger).
|
|
15
|
+
* Conductor registration key (bb_conductor.conductor_id), derived at load
|
|
16
|
+
* time as `<machine_id>-<project>-<variant>` and never written to a config.
|
|
17
|
+
* Absent until `bakers init` gave the machine its UUID.
|
|
19
18
|
*/
|
|
20
19
|
conductor_id?: string;
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
/** The selected config file's stem: `conductor` for `conductor.config.js`. */
|
|
21
|
+
variant: string;
|
|
22
|
+
/** This machine's display label (`machine.config.js` label). */
|
|
23
|
+
machine_label?: string;
|
|
25
24
|
/** Project name (bb_project.name); resolved at registration. */
|
|
26
25
|
project: string;
|
|
27
26
|
/**
|
|
@@ -47,11 +46,7 @@ export interface ConductorSettings {
|
|
|
47
46
|
* Runtime-derived; ticket and project env cannot override it.
|
|
48
47
|
*/
|
|
49
48
|
tunnel?: boolean;
|
|
50
|
-
/**
|
|
51
|
-
* Host identity stem (bb_machine.host_key). Sourced from
|
|
52
|
-
* MachineContext.machine_id — not derived by hyphen-splitting conductor_id
|
|
53
|
-
* (that mis-parses when project or host segments contain hyphens).
|
|
54
|
-
*/
|
|
49
|
+
/** This machine's UUID (bb_machine.host_key), from `machine.config.js` machine_id. */
|
|
55
50
|
host_key?: string;
|
|
56
51
|
poll_interval_ms: number;
|
|
57
52
|
lease_seconds: number;
|