@bakers-build/conductor 0.10.1-next.8 → 0.11.0
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, 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, 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';
|
|
@@ -161,6 +161,24 @@ function logOptsOf(cmd) {
|
|
|
161
161
|
};
|
|
162
162
|
}
|
|
163
163
|
/** Create the conductor logger (with CLI log overrides) and route all exec logging through it. */
|
|
164
|
+
/**
|
|
165
|
+
* `~/.bakers/.bakers.env`, or undefined after printing why it was refused and
|
|
166
|
+
* setting exit 1. The log names the loaded keys, never their values.
|
|
167
|
+
*/
|
|
168
|
+
function loadSecretsOrFail(logger) {
|
|
169
|
+
try {
|
|
170
|
+
const secrets = loadSecretsFile();
|
|
171
|
+
const names = Object.keys(secrets);
|
|
172
|
+
if (names.length)
|
|
173
|
+
logger?.info({ secrets: names }, `secrets file: ${names.join(', ')} set`);
|
|
174
|
+
return secrets;
|
|
175
|
+
}
|
|
176
|
+
catch (err) {
|
|
177
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
178
|
+
process.exitCode = 1;
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
164
182
|
function loggerFor(checkoutRoot, log = {}) {
|
|
165
183
|
const logger = createLogger({ checkoutRoot, ...log });
|
|
166
184
|
setDefaultCommandRunner(new CommandRunner(logger));
|
|
@@ -256,13 +274,16 @@ async function cmdPoll(deps, log = {}) {
|
|
|
256
274
|
const config = await resolveConfig(deps, undefined, true);
|
|
257
275
|
const checkoutRoot = await checkoutRootOf(config);
|
|
258
276
|
const logger = loggerFor(checkoutRoot, log);
|
|
277
|
+
const secrets = loadSecretsOrFail(logger);
|
|
278
|
+
if (!secrets)
|
|
279
|
+
return;
|
|
259
280
|
if (!(await ensureAuthenticated(config, logger)))
|
|
260
281
|
return;
|
|
261
282
|
const remote = await resolveRemote(deps, config);
|
|
262
283
|
const executor = deps.executor ?? (await selectExecutor(config, logger));
|
|
263
284
|
const workspace = deps.workspace ?? (await selectWorkspace(config, logger));
|
|
264
285
|
const agents = deps.agents ?? (await selectAgents(config));
|
|
265
|
-
const conductor = new Conductor(config, remote, executor, workspace, agents, logger, checkoutRoot, frozenStateFileOf(config), undefined, readMachineContext);
|
|
286
|
+
const conductor = new Conductor(config, remote, executor, workspace, agents, logger, checkoutRoot, frozenStateFileOf(config), undefined, readMachineContext, secrets);
|
|
266
287
|
await conductor.start();
|
|
267
288
|
await conductor.tick();
|
|
268
289
|
}
|
|
@@ -373,6 +394,10 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
|
|
|
373
394
|
const config = await resolveConfig(deps, undefined, true);
|
|
374
395
|
const checkoutRoot = await checkoutRootOf(config);
|
|
375
396
|
const logger = loggerFor(checkoutRoot, log);
|
|
397
|
+
// Every start path ends here: detached child, self-restart and update re-exec.
|
|
398
|
+
const secrets = loadSecretsOrFail(logger);
|
|
399
|
+
if (!secrets)
|
|
400
|
+
return;
|
|
376
401
|
if (!(await ensureAuthenticated(config, logger)))
|
|
377
402
|
return;
|
|
378
403
|
const remote = await resolveRemote(deps, config);
|
|
@@ -390,7 +415,7 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
|
|
|
390
415
|
const executor = deps.executor ?? (await selectExecutor(config, logger));
|
|
391
416
|
const workspace = deps.workspace ?? (await selectWorkspace(config, logger));
|
|
392
417
|
const agents = deps.agents ?? (await selectAgents(config));
|
|
393
|
-
const conductor = new Conductor(config, remote, executor, workspace, agents, logger, checkoutRoot, frozenStateFileOf(config), undefined, readMachineContext);
|
|
418
|
+
const conductor = new Conductor(config, remote, executor, workspace, agents, logger, checkoutRoot, frozenStateFileOf(config), undefined, readMachineContext, secrets);
|
|
394
419
|
// This process IS the conductor, so it may report its own pid and config
|
|
395
420
|
// name — the two values a cockpit needs to stop it later. poll/reap build a
|
|
396
421
|
// Conductor too but never claim, so they cannot overwrite this pid.
|
|
@@ -617,6 +642,9 @@ async function settleTakeover(deps, remote, registration, choice) {
|
|
|
617
642
|
}
|
|
618
643
|
async function cmdStart(deps, log = {}, updateCheck = true, body = cmdStartBody, force = false, foreground = false) {
|
|
619
644
|
const current = printVersionLine();
|
|
645
|
+
// The detached child loads it again; checking here shows a refusal in this shell.
|
|
646
|
+
if (!foreground && !loadSecretsOrFail())
|
|
647
|
+
return;
|
|
620
648
|
if (updateCheck) {
|
|
621
649
|
const options = {
|
|
622
650
|
fetchImpl: deps.fetch ?? globalThis.fetch,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ConductorLogger, type MachineContext } from '@bakers-build/core';
|
|
1
|
+
import { type ConductorLogger, type MachineContext, type Secrets } 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';
|
|
@@ -38,6 +38,8 @@ export declare class Conductor {
|
|
|
38
38
|
private readonly runHook;
|
|
39
39
|
/** Re-reads machine.config.js per run; absent, `config.tunnel` stays. */
|
|
40
40
|
private readonly readMachine?;
|
|
41
|
+
/** `~/.bakers/.bakers.env`, loaded at start; runs get declared names only. */
|
|
42
|
+
private readonly secrets;
|
|
41
43
|
private uuid;
|
|
42
44
|
/**
|
|
43
45
|
* Frozen tickets seen on the last poll, by uuid, with the worktree their
|
|
@@ -60,7 +62,9 @@ export declare class Conductor {
|
|
|
60
62
|
private tunnel;
|
|
61
63
|
constructor(config: ConductorFileConfig, remote: BbRemote, executor: BbExecutor, workspace: BbWorkspace, agents: ResolvedAgent[], logger: ConductorLogger, checkoutRoot?: string, frozenStateFile?: string | undefined, runHook?: HookRunner,
|
|
62
64
|
/** Re-reads machine.config.js per run; absent, `config.tunnel` stays. */
|
|
63
|
-
readMachine?: (() => Promise<Partial<MachineContext>>) | undefined
|
|
65
|
+
readMachine?: (() => Promise<Partial<MachineContext>>) | undefined,
|
|
66
|
+
/** `~/.bakers/.bakers.env`, loaded at start; runs get declared names only. */
|
|
67
|
+
secrets?: Secrets);
|
|
64
68
|
private serialGit;
|
|
65
69
|
/**
|
|
66
70
|
* `conductor_id` is derived by the loader from the machine UUID, project and
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { basename, dirname, join } from 'node:path';
|
|
3
|
-
import { killRunProcesses, loadRunClone, protectedProjectPaths, saveRunClone, shellQuote, stemForConfigFile, transferIsolatedCommit, } from '@bakers-build/core';
|
|
3
|
+
import { killRunProcesses, loadRunClone, pickSecrets, protectedProjectPaths, saveRunClone, shellQuote, stemForConfigFile, transferIsolatedCommit, } from '@bakers-build/core';
|
|
4
4
|
import { CONDUCTOR_TOKEN_ENV, CONDUCTOR_URL_ENV, DEFAULT_ENV_DENY, matchesEnvDeny, } from '../plugins/agent.js';
|
|
5
5
|
import { homeKey, homePath } from '../plugins/agent-home.js';
|
|
6
6
|
import { resolveAgent } from '../plugins/plugins.js';
|
|
@@ -197,6 +197,7 @@ export class Conductor {
|
|
|
197
197
|
frozenStateFile;
|
|
198
198
|
runHook;
|
|
199
199
|
readMachine;
|
|
200
|
+
secrets;
|
|
200
201
|
uuid = null;
|
|
201
202
|
/**
|
|
202
203
|
* Frozen tickets seen on the last poll, by uuid, with the worktree their
|
|
@@ -219,7 +220,9 @@ export class Conductor {
|
|
|
219
220
|
tunnel;
|
|
220
221
|
constructor(config, remote, executor, workspace, agents, logger, checkoutRoot = process.cwd(), frozenStateFile, runHook = shellHookRunner(config.hooks, logger),
|
|
221
222
|
/** Re-reads machine.config.js per run; absent, `config.tunnel` stays. */
|
|
222
|
-
readMachine
|
|
223
|
+
readMachine,
|
|
224
|
+
/** `~/.bakers/.bakers.env`, loaded at start; runs get declared names only. */
|
|
225
|
+
secrets = {}) {
|
|
223
226
|
this.config = config;
|
|
224
227
|
this.remote = remote;
|
|
225
228
|
this.executor = executor;
|
|
@@ -230,6 +233,7 @@ export class Conductor {
|
|
|
230
233
|
this.frozenStateFile = frozenStateFile;
|
|
231
234
|
this.runHook = runHook;
|
|
232
235
|
this.readMachine = readMachine;
|
|
236
|
+
this.secrets = secrets;
|
|
233
237
|
this.tunnel = config.tunnel === true;
|
|
234
238
|
this.inboxAddons = new InboxRuntime(config.inboxAddons ?? [], remote, logger, (ticket) => this.runEnv(ticket, undefined, ticket.state), config.tools);
|
|
235
239
|
this.queue = new ActionQueue(logger);
|
|
@@ -1168,6 +1172,10 @@ export class Conductor {
|
|
|
1168
1172
|
const core = {
|
|
1169
1173
|
BAKERS_URL: this.config.site.base_url,
|
|
1170
1174
|
BAKERS_ID: t.uuid,
|
|
1175
|
+
// The agent finds its own conductor in bakers_user_read by this id.
|
|
1176
|
+
...(this.config.conductor_id
|
|
1177
|
+
? { BAKERS_CONDUCTOR_ID: this.config.conductor_id }
|
|
1178
|
+
: {}),
|
|
1171
1179
|
// BB-569: lets a launch wrapper key off the ticket and the run's
|
|
1172
1180
|
// start state without parsing the prompt (addon-claude `measure`).
|
|
1173
1181
|
...(t.identifier ? { BAKERS_TICKET_IDENTIFIER: t.identifier } : {}),
|
|
@@ -1441,7 +1449,7 @@ export class Conductor {
|
|
|
1441
1449
|
'Commit before you end: uncommitted work is not carried over. ' +
|
|
1442
1450
|
'forge_fetch refreshes the origin refs and forge_push transfers and pushes your commits. ' +
|
|
1443
1451
|
`Read-only here: ${['.bakers', ...(this.config.readOnly ?? [])].filter((path, index, all) => all.indexOf(path) === index).join(', ')}. ` +
|
|
1444
|
-
'
|
|
1452
|
+
'forge_update_branch merges the target into your branch; follow its sync: in_place, run the returned git merge --ff-only before further work; restart, stop and cancel this run with bakers_run_cancel; a conflict, stop and report it to the developers.';
|
|
1445
1453
|
// BB-473 review round 2 (Critical 1): pinning the run's own UUID
|
|
1446
1454
|
// unconditionally makes a re-dispatch of the same run — an existing,
|
|
1447
1455
|
// supported path (see the cleanupRun comment above) — fail to launch,
|
|
@@ -1489,11 +1497,14 @@ export class Conductor {
|
|
|
1489
1497
|
: undefined;
|
|
1490
1498
|
const plugins = await this.installPlugins(chosen, t, run);
|
|
1491
1499
|
Object.assign(env, plugins.env);
|
|
1500
|
+
// Only the names the agent declares; a value exported in the shell wins.
|
|
1501
|
+
const secrets = pickSecrets(chosen.agent.secretEnv ?? [], this.secrets);
|
|
1492
1502
|
const agentInfo = {
|
|
1493
1503
|
...(chosen.agent.installCommand
|
|
1494
1504
|
? { installCommand: chosen.agent.installCommand }
|
|
1495
1505
|
: {}),
|
|
1496
1506
|
...(chosen.agent.modelApi ? { modelApi: chosen.agent.modelApi } : {}),
|
|
1507
|
+
secrets,
|
|
1497
1508
|
};
|
|
1498
1509
|
const isolates = this.config.runtime?.isolates === true;
|
|
1499
1510
|
// Without it the run starts in an empty private home and cannot sign in.
|
|
@@ -1510,10 +1521,16 @@ export class Conductor {
|
|
|
1510
1521
|
...runtimeContext,
|
|
1511
1522
|
workspacePath: ws.path,
|
|
1512
1523
|
env,
|
|
1524
|
+
secrets,
|
|
1513
1525
|
})
|
|
1514
1526
|
: undefined;
|
|
1515
1527
|
if (preparation)
|
|
1516
1528
|
Object.assign(env, preparation.env);
|
|
1529
|
+
// A host run inherits the shell's values; it lacks only the file's.
|
|
1530
|
+
if (!runtimeContext)
|
|
1531
|
+
for (const [name, value] of Object.entries(secrets))
|
|
1532
|
+
if (!process.env[name])
|
|
1533
|
+
env[name] = value;
|
|
1517
1534
|
// An isolated run without its own clone would share the parent's Git data.
|
|
1518
1535
|
if (isolates && !ws.clone)
|
|
1519
1536
|
throw new Error('the runtime isolates runs, but the workspace provides no run clone');
|
|
@@ -11,13 +11,14 @@ export const SITE_TOOLS = [
|
|
|
11
11
|
'bakers_ticket_classify',
|
|
12
12
|
'bakers_ticket_transition',
|
|
13
13
|
'bakers_run_cancel',
|
|
14
|
-
'
|
|
14
|
+
'bakers_comment_create',
|
|
15
15
|
'bakers_metric_write',
|
|
16
16
|
'bakers_ticket_list',
|
|
17
|
-
'
|
|
17
|
+
'bakers_run_list',
|
|
18
18
|
'bakers_label_list',
|
|
19
19
|
'bakers_project_read',
|
|
20
20
|
'bakers_user_read',
|
|
21
|
+
'bakers_conductor_list',
|
|
21
22
|
];
|
|
22
23
|
/** The site tools that change a ticket; a successful call signals `bakers ui`. */
|
|
23
24
|
export const SITE_WRITE_TOOLS = [
|
|
@@ -26,7 +27,7 @@ export const SITE_WRITE_TOOLS = [
|
|
|
26
27
|
'bakers_ticket_classify',
|
|
27
28
|
'bakers_ticket_transition',
|
|
28
29
|
'bakers_run_cancel',
|
|
29
|
-
'
|
|
30
|
+
'bakers_comment_create',
|
|
30
31
|
];
|
|
31
32
|
const WIRE = 'tool_api__';
|
|
32
33
|
export function siteToolProxy(client, logger) {
|
|
@@ -112,6 +112,8 @@ export interface AgentRunContext {
|
|
|
112
112
|
homePath: string;
|
|
113
113
|
workspacePath: string;
|
|
114
114
|
env: Readonly<Record<string, string>>;
|
|
115
|
+
/** The agent's declared `secretEnv` values the conductor hands this run. */
|
|
116
|
+
secrets?: Readonly<Record<string, string>>;
|
|
115
117
|
}
|
|
116
118
|
/** Files and environment an agent needs, independent of its execution backend. */
|
|
117
119
|
export interface AgentRunPreparation {
|
|
@@ -141,6 +143,13 @@ export interface AgentModelApi {
|
|
|
141
143
|
export interface AgentRuntimeInfo {
|
|
142
144
|
readonly installCommand?: string;
|
|
143
145
|
readonly modelApi?: AgentModelApi;
|
|
146
|
+
/**
|
|
147
|
+
* Env names this agent's runs may receive from `~/.bakers/.bakers.env` or
|
|
148
|
+
* the conductor's shell; no other secrets-file value reaches a run.
|
|
149
|
+
*/
|
|
150
|
+
readonly secretEnv?: readonly string[];
|
|
151
|
+
/** The declared values the conductor hands this run; never logged. */
|
|
152
|
+
readonly secrets?: Readonly<Record<string, string>>;
|
|
144
153
|
}
|
|
145
154
|
export interface BbAgent extends AgentRuntimeInfo {
|
|
146
155
|
/** Stable id, e.g. 'claude'. */
|
|
@@ -43,6 +43,8 @@ export interface AgentPlugin extends DropSHPlugin {
|
|
|
43
43
|
readonly requiredModules: string[];
|
|
44
44
|
/** The effective run permissions and their source layers (`bakers agents`). */
|
|
45
45
|
readonly permissions?: SecurityReport;
|
|
46
|
+
/** The secrets-file names its runs may receive (`bakers agents`). */
|
|
47
|
+
readonly secretEnv?: readonly string[];
|
|
46
48
|
createAgent(config: ConductorFileConfig): Promise<BbAgent>;
|
|
47
49
|
}
|
|
48
50
|
/** Resolves the remote from its named config slot. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/conductor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
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.
|
|
36
|
-
"@bakers-build/message": "^0.
|
|
35
|
+
"@bakers-build/core": "^0.11.0",
|
|
36
|
+
"@bakers-build/message": "^0.11.0",
|
|
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": "
|
|
43
|
-
"channel": "
|
|
42
|
+
"commit": "4e1d1a59439a6a0019f3b5b213d9cc9f09d14381",
|
|
43
|
+
"channel": "latest"
|
|
44
44
|
}
|
|
45
45
|
}
|