@bakers-build/conductor 0.17.0 → 0.17.1-next.2
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.
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { execFile, spawnSync } from 'node:child_process';
|
|
2
|
-
import {
|
|
2
|
+
import { mkdirSync } from 'node:fs';
|
|
3
|
+
import { basename, dirname, join, resolve, sep } from 'node:path';
|
|
3
4
|
import { createInterface } from 'node:readline';
|
|
4
5
|
import { promisify } from 'node:util';
|
|
5
|
-
import { CommandRunner, checkForUpdate, configHomeOf, createBbConnectionClient, createLogger, declineUpdate, defaultProcProbe, deriveCheckoutRoot, deriveConductorLiveness, homeBbDir,
|
|
6
|
+
import { CommandRunner, checkForUpdate, configHomeOf, createBbConnectionClient, createLogger, declineUpdate, defaultProcProbe, deriveCheckoutRoot, deriveConductorLiveness, envsDir, homeBbDir, loadEnvFiles, loadReadyBbConnection, printVersionLine, readCliVersion, readMachineContext, resolveCliVersion, resolveConfigPath, secretsFilePath, setDefaultCommandRunner, signalVerifiedProcess, stemForConfigFile, UNKNOWN_VERSION, updateNotice, verifyConductorProcess, } from '@bakers-build/core';
|
|
6
7
|
import { Command } from 'commander';
|
|
7
8
|
import { authStatus } from 'dropsh';
|
|
8
9
|
import { resolveBbProjectContext } from '../bakers-project-context.js';
|
|
@@ -162,16 +163,17 @@ function logOptsOf(cmd) {
|
|
|
162
163
|
}
|
|
163
164
|
/** Create the conductor logger (with CLI log overrides) and route all exec logging through it. */
|
|
164
165
|
/**
|
|
165
|
-
*
|
|
166
|
-
* setting exit 1. The log names
|
|
166
|
+
* Every bakers env file, or undefined after printing why one was refused and
|
|
167
|
+
* setting exit 1. The log names each file's keys, never their values.
|
|
167
168
|
*/
|
|
168
169
|
function loadSecretsOrFail(logger) {
|
|
169
170
|
try {
|
|
170
|
-
const
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
logger?.info({ secrets: names },
|
|
174
|
-
|
|
171
|
+
const files = loadEnvFiles();
|
|
172
|
+
for (const [path, values] of Object.entries(files)) {
|
|
173
|
+
const names = Object.keys(values);
|
|
174
|
+
logger?.info({ path, secrets: names }, `${path}: ${names.join(', ')} set`);
|
|
175
|
+
}
|
|
176
|
+
return files;
|
|
175
177
|
}
|
|
176
178
|
catch (err) {
|
|
177
179
|
console.error(err instanceof Error ? err.message : String(err));
|
|
@@ -448,7 +450,7 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
|
|
|
448
450
|
// The restart re-runs loadSecretsOrFail, which exits on a bad file: check first.
|
|
449
451
|
const reloadSecrets = () => {
|
|
450
452
|
try {
|
|
451
|
-
return
|
|
453
|
+
return loadEnvFiles();
|
|
452
454
|
}
|
|
453
455
|
catch (err) {
|
|
454
456
|
logger.error({ path: secretsFilePath() }, `${err.message}; keeping the running conductor on its last good secrets`);
|
|
@@ -475,20 +477,33 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
|
|
|
475
477
|
let lastRead;
|
|
476
478
|
let settled; // the new version already handled or refused
|
|
477
479
|
let busy = false;
|
|
480
|
+
// An unwatched missing folder would miss its first env file: create them.
|
|
481
|
+
for (const level of ['project', 'runtime', 'agent'])
|
|
482
|
+
mkdirSync(join(envsDir(), level), { recursive: true, mode: 0o700 });
|
|
478
483
|
if (config.restart_on_change !== false && config.watch_paths) {
|
|
479
484
|
if (!execve) {
|
|
480
485
|
logger.warn({ node: process.version }, 'restart_on_change needs process.execve (Node >= 22.15); the conductor does not restart itself on config changes');
|
|
481
486
|
}
|
|
482
487
|
else {
|
|
483
|
-
watcher = (deps.watchForRestart ?? watchForRestart)(
|
|
488
|
+
watcher = (deps.watchForRestart ?? watchForRestart)({
|
|
489
|
+
...config.watch_paths,
|
|
490
|
+
dirs: [...config.watch_paths.dirs, envsDir()],
|
|
491
|
+
}, async (paths) => {
|
|
484
492
|
// Changes after this batch was taken are lost when the watcher closes.
|
|
485
493
|
const cut = Date.now();
|
|
486
494
|
if (controller.signal.aborted)
|
|
487
495
|
return;
|
|
488
496
|
const secretsPath = secretsFilePath();
|
|
497
|
+
const envs = envsDir() + sep;
|
|
498
|
+
// Only the files loadEnvFiles reads count; a swap or backup file does not.
|
|
499
|
+
const isEnvPath = (p) => p === secretsPath ||
|
|
500
|
+
(p.startsWith(envs) && /^\.bakers-.+\.env$/.test(basename(p)));
|
|
489
501
|
for (const p of paths)
|
|
490
|
-
if (p
|
|
502
|
+
if (!isEnvPath(p) && !p.startsWith(envs))
|
|
491
503
|
heldBack.add(p);
|
|
504
|
+
const envPath = paths.filter(isEnvPath).join(', ');
|
|
505
|
+
if (!envPath && !heldBack.size)
|
|
506
|
+
return;
|
|
492
507
|
if (!reloadSecrets())
|
|
493
508
|
return;
|
|
494
509
|
const configPaths = [...heldBack];
|
|
@@ -498,17 +513,14 @@ async function cmdStartForeground(deps, log = {}, force = false, choice = {}) {
|
|
|
498
513
|
if (read !== UNKNOWN_VERSION && read !== startVersion) {
|
|
499
514
|
// A new CLI starts only after migrate and check: retry the upgrade on the next poll.
|
|
500
515
|
settled = undefined;
|
|
501
|
-
logger.info({ path:
|
|
516
|
+
logger.info({ path: envPath, to: read }, 'secrets file changed; the pending CLI upgrade restarts the conductor');
|
|
502
517
|
return;
|
|
503
518
|
}
|
|
504
|
-
logger.info({ path:
|
|
519
|
+
logger.info({ path: envPath }, 'secrets file changed; restarting conductor');
|
|
505
520
|
restartNow(cut);
|
|
506
521
|
return;
|
|
507
522
|
}
|
|
508
|
-
const path = [
|
|
509
|
-
...configPaths,
|
|
510
|
-
...paths.filter((p) => p === secretsPath),
|
|
511
|
-
].join(', ');
|
|
523
|
+
const path = [...configPaths, ...(envPath ? [envPath] : [])].join(', ');
|
|
512
524
|
logger.info({ path }, `restart_on_change: ${path} changed; checking config`);
|
|
513
525
|
const error = await check();
|
|
514
526
|
// A stop requested while the check ran stays a stop.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ConductorLogger, type
|
|
1
|
+
import { type ConductorLogger, type EnvFiles, type MachineContext } 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,8 +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
|
-
/**
|
|
42
|
-
private readonly
|
|
41
|
+
/** Every env file, loaded at start; a run gets its layers (`layeredEnv`). */
|
|
42
|
+
private readonly envFiles;
|
|
43
43
|
private uuid;
|
|
44
44
|
/** While the server refuses claims (426): the current backoff, else 0. */
|
|
45
45
|
private claimBackoffMs;
|
|
@@ -73,8 +73,8 @@ export declare class Conductor {
|
|
|
73
73
|
constructor(config: ConductorFileConfig, remote: BbRemote, executor: BbExecutor, workspace: BbWorkspace, agents: ResolvedAgent[], logger: ConductorLogger, checkoutRoot?: string, frozenStateFile?: string | undefined, runHook?: HookRunner,
|
|
74
74
|
/** Re-reads machine.config.js per run; absent, `config.tunnel` stays. */
|
|
75
75
|
readMachine?: (() => Promise<Partial<MachineContext>>) | undefined,
|
|
76
|
-
/**
|
|
77
|
-
|
|
76
|
+
/** Every env file, loaded at start; a run gets its layers (`layeredEnv`). */
|
|
77
|
+
envFiles?: EnvFiles);
|
|
78
78
|
private serialGit;
|
|
79
79
|
/**
|
|
80
80
|
* `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, pickSecrets, protectedProjectPaths, saveRunClone, shellQuote, stemForConfigFile, transferIsolatedCommit, } from '@bakers-build/core';
|
|
3
|
+
import { killRunProcesses, layeredEnv, loadRunClone, pickSecrets, protectedProjectPaths, saveRunClone, secretsFilePath, shellQuote, stemForConfigFile, transferIsolatedCommit, } from '@bakers-build/core';
|
|
4
4
|
import { HttpError } from 'dropsh/plugin';
|
|
5
5
|
import { CONDUCTOR_TOKEN_ENV, CONDUCTOR_URL_ENV, DEFAULT_ENV_DENY, matchesEnvDeny, } from '../plugins/agent.js';
|
|
6
6
|
import { homeKey, homePath } from '../plugins/agent-home.js';
|
|
@@ -202,7 +202,7 @@ export class Conductor {
|
|
|
202
202
|
frozenStateFile;
|
|
203
203
|
runHook;
|
|
204
204
|
readMachine;
|
|
205
|
-
|
|
205
|
+
envFiles;
|
|
206
206
|
uuid = null;
|
|
207
207
|
/** While the server refuses claims (426): the current backoff, else 0. */
|
|
208
208
|
claimBackoffMs = 0;
|
|
@@ -236,8 +236,8 @@ export class Conductor {
|
|
|
236
236
|
constructor(config, remote, executor, workspace, agents, logger, checkoutRoot = process.cwd(), frozenStateFile, runHook = shellHookRunner(config.hooks, logger),
|
|
237
237
|
/** Re-reads machine.config.js per run; absent, `config.tunnel` stays. */
|
|
238
238
|
readMachine,
|
|
239
|
-
/**
|
|
240
|
-
|
|
239
|
+
/** Every env file, loaded at start; a run gets its layers (`layeredEnv`). */
|
|
240
|
+
envFiles = {}) {
|
|
241
241
|
this.config = config;
|
|
242
242
|
this.remote = remote;
|
|
243
243
|
this.executor = executor;
|
|
@@ -248,7 +248,7 @@ export class Conductor {
|
|
|
248
248
|
this.frozenStateFile = frozenStateFile;
|
|
249
249
|
this.runHook = runHook;
|
|
250
250
|
this.readMachine = readMachine;
|
|
251
|
-
this.
|
|
251
|
+
this.envFiles = envFiles;
|
|
252
252
|
this.tunnel = config.tunnel === true;
|
|
253
253
|
// A config built without the loader: its one runtime beside the host.
|
|
254
254
|
const runtime = config.runtime;
|
|
@@ -1389,7 +1389,7 @@ export class Conductor {
|
|
|
1389
1389
|
* Install the project's `marketplaces` into the run's agent home and log
|
|
1390
1390
|
* one `plugins` entry. A failed install throws, failing the run start.
|
|
1391
1391
|
*/
|
|
1392
|
-
async installPlugins(chosen, t, run) {
|
|
1392
|
+
async installPlugins(chosen, t, run, secrets) {
|
|
1393
1393
|
const marketplaces = this.config.marketplaces ?? [];
|
|
1394
1394
|
const harness = chosen.agent.id;
|
|
1395
1395
|
const entry = {
|
|
@@ -1415,7 +1415,7 @@ export class Conductor {
|
|
|
1415
1415
|
Object.assign(entry, { state: 'on', hash, home, marketplaces });
|
|
1416
1416
|
let launch;
|
|
1417
1417
|
try {
|
|
1418
|
-
launch = await chosen.agent.installPlugins(marketplaces, home,
|
|
1418
|
+
launch = await chosen.agent.installPlugins(marketplaces, home, secrets);
|
|
1419
1419
|
// A host install used the person's own config dir, not this home.
|
|
1420
1420
|
if (launch.home === 'host') {
|
|
1421
1421
|
delete entry.hash;
|
|
@@ -1676,10 +1676,17 @@ export class Conductor {
|
|
|
1676
1676
|
const toolsUrl = tools
|
|
1677
1677
|
? (runtime.toolsUrl?.(tools.url) ?? tools.url)
|
|
1678
1678
|
: undefined;
|
|
1679
|
-
const
|
|
1679
|
+
const layered = layeredEnv({
|
|
1680
|
+
project: this.config.project,
|
|
1681
|
+
runtime: runtimeChoice.alias,
|
|
1682
|
+
harness: chosen.agent.id,
|
|
1683
|
+
alias: chosen.alias ?? chosen.id,
|
|
1684
|
+
}, this.envFiles);
|
|
1685
|
+
// Declared names go through secrets; a value exported in the shell wins.
|
|
1686
|
+
const declared = chosen.agent.secretEnv ?? [];
|
|
1687
|
+
const secrets = pickSecrets(declared, layered.values);
|
|
1688
|
+
const plugins = await this.installPlugins(chosen, t, run, secrets);
|
|
1680
1689
|
Object.assign(env, plugins.env);
|
|
1681
|
-
// Only the names the agent declares; a value exported in the shell wins.
|
|
1682
|
-
const secrets = pickSecrets(chosen.agent.secretEnv ?? [], this.secrets);
|
|
1683
1690
|
const agentInfo = {
|
|
1684
1691
|
...(chosen.agent.installCommand
|
|
1685
1692
|
? { installCommand: chosen.agent.installCommand }
|
|
@@ -1713,6 +1720,18 @@ export class Conductor {
|
|
|
1713
1720
|
for (const [name, value] of Object.entries(secrets))
|
|
1714
1721
|
if (!process.env[name])
|
|
1715
1722
|
env[name] = value;
|
|
1723
|
+
// A name placed in a project, runtime or agent file reaches the run undeclared;
|
|
1724
|
+
// the conductor's own run values stay.
|
|
1725
|
+
const machineFile = secretsFilePath();
|
|
1726
|
+
for (const [name, source] of Object.entries(layered.sources)) {
|
|
1727
|
+
if (source === machineFile || declared.includes(name) || name in env)
|
|
1728
|
+
continue;
|
|
1729
|
+
const shell = process.env[name];
|
|
1730
|
+
if (!shell)
|
|
1731
|
+
env[name] = layered.values[name];
|
|
1732
|
+
else if (runtimeContext)
|
|
1733
|
+
env[name] = shell;
|
|
1734
|
+
}
|
|
1716
1735
|
// An isolated run without its own clone would share the parent's Git data.
|
|
1717
1736
|
if (isolates && !ws.clone)
|
|
1718
1737
|
throw new Error('the runtime isolates runs, but the workspace provides no run clone');
|
|
@@ -149,8 +149,8 @@ export interface AgentRuntimeInfo {
|
|
|
149
149
|
readonly installCommand?: string;
|
|
150
150
|
readonly modelApi?: AgentModelApi;
|
|
151
151
|
/**
|
|
152
|
-
* Env names this agent's runs
|
|
153
|
-
*
|
|
152
|
+
* Env names this agent's runs receive from the bakers env files or the
|
|
153
|
+
* conductor's shell; an undeclared name in `~/.bakers/.bakers.env` never reaches a run.
|
|
154
154
|
*/
|
|
155
155
|
readonly secretEnv?: readonly string[];
|
|
156
156
|
/** The declared values the conductor hands this run; never logged. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/conductor",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.1-next.2",
|
|
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.17.
|
|
36
|
-
"@bakers-build/message": "^0.17.
|
|
35
|
+
"@bakers-build/core": "^0.17.1-next.2",
|
|
36
|
+
"@bakers-build/message": "^0.17.1-next.2",
|
|
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": "035506c7ccbdf8641f605a5dcb07d50ccf42d72d",
|
|
43
|
+
"channel": "next"
|
|
44
44
|
}
|
|
45
45
|
}
|