@bakers-build/conductor 0.8.0 → 0.8.1-next.1

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.
@@ -8,10 +8,10 @@ import { applyMigrations, BB_CONFIG_SCHEMA_VERSION } from './config-schema.js';
8
8
  import { ConfigSourceEditor, redactConfigSource, } from './config-source-edit.js';
9
9
  import { renderCommittedConfig, renderGlobalConnection, renderHostMachine, } from './config-templates.js';
10
10
  import { validateConfigSources } from './config-validation.js';
11
- // Every config file restarted at schema v1; no migration step exists.
11
+ // Every config file is at schema v1; no migration step exists yet.
12
12
  const CURRENT = {
13
13
  machine: 1,
14
- conductor: 1,
14
+ project: 1,
15
15
  connection: 1,
16
16
  'project-connection': 1,
17
17
  };
@@ -274,11 +274,6 @@ export function planConfig(options = {}) {
274
274
  }
275
275
  if (currentRoute === undefined)
276
276
  machineEditor.set('agents.routes.default', expression);
277
- const catchAll = source.property('default_agent.*');
278
- if (catchAll?.staticallyDetermined &&
279
- typeof catchAll.value === 'string' &&
280
- !machineEditor.property('agents.default_agent'))
281
- machineEditor.set('agents.default_agent', JSON.stringify(catchAll.value));
282
277
  source.remove('default_agent');
283
278
  };
284
279
  const migrateCatalog = (sourceFile, source) => {
@@ -395,13 +390,6 @@ export function planConfig(options = {}) {
395
390
  }
396
391
  source.remove('agent');
397
392
  };
398
- const deriveMachineDefault = () => {
399
- if (machineEditor.property('agents.default_agent'))
400
- return;
401
- const catchAll = machineEditor.property('agents.routes.default.*');
402
- if (catchAll?.staticallyDetermined && typeof catchAll.value === 'string')
403
- machineEditor.set('agents.default_agent', JSON.stringify(catchAll.value));
404
- };
405
393
  if (machine.selected && !protectedFile(machine)) {
406
394
  const oldAgents = machineEditor.property('agents');
407
395
  if (oldAgents?.nodeType === 'ArrayExpression') {
@@ -427,9 +415,8 @@ export function planConfig(options = {}) {
427
415
  if (routes !== undefined)
428
416
  setMachineAgentValue(machine, machineEditor, 'agent_routes', 'agents.routes', routes);
429
417
  migrateStateDefaults(machine, machineEditor);
430
- deriveMachineDefault();
431
418
  }
432
- for (const file of files.filter((candidate) => candidate.selected && ['conductor', 'local'].includes(candidate.kind))) {
419
+ for (const file of files.filter((candidate) => candidate.selected && candidate.kind === 'project')) {
433
420
  const source = editors.get(file.path);
434
421
  if (!source || protectedFile(file))
435
422
  continue;
@@ -443,9 +430,7 @@ export function planConfig(options = {}) {
443
430
  if (routes !== undefined)
444
431
  setMachineAgentValue(file, source, 'agent_routes', 'agents.routes', routes);
445
432
  migrateStateDefaults(file, source);
446
- if (file.kind === 'conductor')
447
- migrateCatalog(file, source);
448
- deriveMachineDefault();
433
+ migrateCatalog(file, source);
449
434
  }
450
435
  for (const file of files) {
451
436
  if (protectedFile(file) || !file.selected)
@@ -462,7 +447,7 @@ export function planConfig(options = {}) {
462
447
  fill(file, 'label', options.inputs?.label);
463
448
  editor(file).stamp(1);
464
449
  }
465
- if (file.kind === 'conductor' || file.kind === 'local') {
450
+ if (file.kind === 'project') {
466
451
  if ((!e || e.text.trim() === 'export default {};') &&
467
452
  file.required &&
468
453
  options.project) {
@@ -477,9 +462,9 @@ export function planConfig(options = {}) {
477
462
  }
478
463
  if (!e)
479
464
  continue;
480
- if (file.kind === 'conductor') {
465
+ {
481
466
  e = editor(file);
482
- fill(file, 'bakers.project', options.project);
467
+ fill(file, 'project.name', options.project);
483
468
  const canonical = new ConfigSourceEditor(renderCommittedConfig({
484
469
  project: options.project ?? 'project',
485
470
  }));
@@ -488,18 +473,18 @@ export function planConfig(options = {}) {
488
473
  .map(([, property]) => property.value)
489
474
  .filter((value) => typeof value === 'string'));
490
475
  const providers = {
491
- remote: [
476
+ server: [
492
477
  '@bakers-build/addon-remote-drupal',
493
478
  '@bakers-build/addon-fake',
494
479
  ],
495
480
  executor: ['@bakers-build/addon-herdr', '@bakers-build/addon-fake'],
496
- workspace: [
481
+ worktree: [
497
482
  '@bakers-build/addon-herdr',
498
483
  '@bakers-build/addon-fake',
499
484
  '@bakers-build/addon-workspace-git',
500
485
  ],
501
486
  };
502
- for (const slot of ['remote', 'executor', 'workspace']) {
487
+ for (const slot of ['server', 'executor', 'worktree']) {
503
488
  if (e.property(slot) ||
504
489
  providers[slot]?.some((provider) => addonPackages.has(provider)))
505
490
  continue;
@@ -507,8 +492,8 @@ export function planConfig(options = {}) {
507
492
  }
508
493
  if (options.operation === 'init' &&
509
494
  options.inputs?.workspace &&
510
- !e.property('bakers.workspace'))
511
- e.set('bakers.workspace', JSON.stringify(options.inputs.workspace));
495
+ !e.property('project.workspace'))
496
+ e.set('project.workspace', JSON.stringify(options.inputs.workspace));
512
497
  e.stamp(1);
513
498
  }
514
499
  }
@@ -585,7 +570,7 @@ export function planConfig(options = {}) {
585
570
  after,
586
571
  mode: before !== null
587
572
  ? statSync(file.path).mode & 0o777
588
- : file.kind === 'project-connection' || file.kind === 'conductor'
573
+ : file.kind === 'project'
589
574
  ? 0o644
590
575
  : 0o600,
591
576
  });
@@ -593,7 +578,7 @@ export function planConfig(options = {}) {
593
578
  path: file.path,
594
579
  layer: file.layer,
595
580
  before_version: file.version.effective,
596
- after_version: after === null || file.kind === 'local' ? null : CURRENT[file.kind],
581
+ after_version: after === null ? null : CURRENT[file.kind],
597
582
  diff: `--- ${file.path}\n+++ ${file.path}\n${before === null
598
583
  ? ''
599
584
  : redactConfigSource(before)
@@ -18,10 +18,10 @@ export interface ConnectionConfigMigration {
18
18
  apply(currentText: string): string;
19
19
  }
20
20
  /**
21
- * The ordered, contiguous migration chain. bakers restarted every config file
22
- * at schema v1, so the chain is empty; a later shape change adds
23
- * its `v1 → v2` step here. `BB_CONFIG_SCHEMA_VERSION` derives from the chain's
24
- * last `to` — never hardcode it.
21
+ * The ordered, contiguous migration chain. Every config file is at schema v1,
22
+ * so the chain is empty; a later shape change adds its `v1 → v2` step here.
23
+ * `BB_CONFIG_SCHEMA_VERSION` derives from the chain's last `to` — never
24
+ * hardcode it.
25
25
  */
26
26
  export declare const CONNECTION_MIGRATIONS: ConnectionConfigMigration[];
27
27
  /** The current connection-config schema version — single source of truth. */
@@ -1,6 +1,6 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  // BB-216: schema versioning for the generated CONNECTION config
3
- // (`bakers.config.js`, project + home). Decoupled from the npm package semver —
3
+ // (connection file, project + home). Decoupled from the npm package semver —
4
4
  // the schema version bumps only when the config SHAPE changes, not every
5
5
  // release. Every generated connection config carries a machine-readable header
6
6
  // comment `// @bakers-schema-version <N>` (the source of truth for the upgrade
@@ -11,10 +11,10 @@ import { readFileSync } from 'node:fs';
11
11
  const MARKER_RE = /@bakers-schema-version\s+(\d+)/;
12
12
  const HEADER_LINE_RE = /^\/\/ @bakers-schema-version \d+\n/;
13
13
  /**
14
- * The ordered, contiguous migration chain. bakers restarted every config file
15
- * at schema v1, so the chain is empty; a later shape change adds
16
- * its `v1 → v2` step here. `BB_CONFIG_SCHEMA_VERSION` derives from the chain's
17
- * last `to` — never hardcode it.
14
+ * The ordered, contiguous migration chain. Every config file is at schema v1,
15
+ * so the chain is empty; a later shape change adds its `v1 → v2` step here.
16
+ * `BB_CONFIG_SCHEMA_VERSION` derives from the chain's last `to` — never
17
+ * hardcode it.
18
18
  */
19
19
  export const CONNECTION_MIGRATIONS = [];
20
20
  /** The current connection-config schema version — single source of truth. */
@@ -15,7 +15,8 @@ export function renderGlobalConnection(inputs) {
15
15
  device_authorization_url: ${JSON.stringify(`${baseUrl}/oauth/device_authorization`)},`
16
16
  : `client_id: ${JSON.stringify(inputs.clientId)}, client_secret: ${JSON.stringify(inputs.secret ?? '')},`;
17
17
  return `// @bakers-schema-version 1
18
- // Global bakers.build connection: credentials and optional legacy workspace. Keep this file private.
18
+ // A bakers.build connection: credentials and optional workspace. Keep this file private.
19
+ /** @type {import('@bakers-build/core').ConnectionConfig} */
19
20
  export default {
20
21
  schema_version: 1,
21
22
  site: { base_url: ${JSON.stringify(inputs.baseUrl)}, jsonapi_prefix: '/jsonapi' },
@@ -34,9 +35,10 @@ ${inputs.workspaceId ? ` workspace_id: ${JSON.stringify(inputs.workspaceId)},\n
34
35
  export function renderHostMachine(inputs) {
35
36
  return `// @bakers-schema-version 1
36
37
  // Local host identity. The run budget is set on the machine in the backend;
37
- // server credentials belong to bakers.config.js. An \`executor\` slot here
38
- // (e.g. \`{ plugin: '@bakers-build/addon-herdr-core' }\`) overrides every
39
- // project's executor on this machine.
38
+ // server credentials belong to the connection (connections/default.js). An
39
+ // \`executor\` slot here (e.g. \`{ use: '@bakers-build/addon-herdr-core' }\`)
40
+ // overrides every project's executor on this machine.
41
+ /** @type {import('@bakers-build/core').MachineConfig} */
40
42
  export default {
41
43
  schema_version: 1,
42
44
  machine_id: ${JSON.stringify(inputs.machineId)},
@@ -44,21 +46,18 @@ ${inputs.label ? ` label: ${JSON.stringify(inputs.label)},\n` : ''}};
44
46
  `;
45
47
  }
46
48
  export function renderCommittedConfig(inputs) {
47
- return `// Canonical bakers.build conductor engine configuration — committed and
48
- // identical for everyone. It carries no identity: a conductor is this machine
49
- // (machine.config.js) + this project + the variant (this file's stem).
50
- // Connections belong to bakers.config.js.
49
+ return `// The project's bakers.build configuration — committed and identical for
50
+ // everyone. A conductor is this machine (machine.config.js) + this project +
51
+ // the variant (project.<name>.config.js). Connections are private files.
51
52
  //
52
- // IMPORT-FREE (BB-78): the plugin slots are \`{ plugin, with }\` descriptors
53
- // naming the REAL published package, not \`import\`ed constructors.
54
- // loadConductorConfig resolves each name ESLint-style (config dir → cwd →
55
- // conductor install). Every addon package default-exports its single factory, so
56
- // no slot needs an \`export:\` — EXCEPT the merged herdr workspace
57
- // (\`@bakers-build/addon-herdr\` default-exports the executor, so the workspace names
58
- // \`export: 'herdrWorkspace'\` — BB-139).
53
+ // The slots are \`{ use, export?, with? }\` descriptors naming the published
54
+ // package; the loader resolves each name (config dir → cwd → CLI install).
55
+ // \`@bakers-build/addon-herdr\` default-exports the executor, so the worktree
56
+ // slot names \`export: 'herdrWorkspace'\`.
59
57
 
58
+ /** @type {import('@bakers-build/core').ProjectConfig} */
60
59
  export default {
61
- bakers: { project: ${JSON.stringify(inputs.project)}${inputs.bakersWorkspace ? `, workspace: ${JSON.stringify(inputs.bakersWorkspace)}` : ''} },
60
+ project: { name: ${JSON.stringify(inputs.project)}${inputs.bakersWorkspace ? `, workspace: ${JSON.stringify(inputs.bakersWorkspace)}` : ''} },
62
61
  // The run budget (max_parallel) is set on the machine in the backend.
63
62
  // Transcripts upload only where the server's run-log storage allows it.
64
63
  // Set to false to keep this conductor's transcripts local even then.
@@ -77,15 +76,10 @@ ${inputs.hooks?.after_create || inputs.hooks?.after_done
77
76
  ]
78
77
  .filter(Boolean)
79
78
  .join(', ')} },\n`
80
- : ''} remote: { plugin: '@bakers-build/addon-remote-drupal' },
81
- executor: { plugin: '@bakers-build/addon-herdr' },
79
+ : ''} server: { use: '@bakers-build/addon-remote-drupal' },
80
+ executor: { use: '@bakers-build/addon-herdr' },
82
81
  addons: ${DEFAULT_CONDUCTOR_AGENT_ADDONS},
83
- // BB-139: the herdr workspace ships in @bakers-build/addon-herdr, which
84
- // default-exports the EXECUTOR — so the workspace slot names export: 'herdrWorkspace'.
85
- workspace: {
86
- plugin: '@bakers-build/addon-herdr',
87
- export: 'herdrWorkspace',
88
- },
82
+ worktree: { use: '@bakers-build/addon-herdr', export: 'herdrWorkspace' },
89
83
  };
90
84
  `;
91
85
  }
@@ -4,7 +4,7 @@ import { type ConfigFileReport, type ConfigInventoryOptions, type ConfigReport }
4
4
  * addon, fills no conductor slot" — a UI-only addon (BB-562) belongs in a
5
5
  * conductor `addons[]` but contributes a cockpit tab, not a slot. Listing it is
6
6
  * not cosmetic: an UNKNOWN specifier sets `addonsAreOpaque` below, which
7
- * downgrades a genuinely missing remote/executor/workspace from
7
+ * downgrades a genuinely missing server/executor/worktree from
8
8
  * `missing_required_key` to `unknown_value`.
9
9
  */
10
10
  export declare const CONDUCTOR_ADDON_SLOTS: Record<string, string[]>;
@@ -5,16 +5,16 @@ import { ConfigSourceEditor } from './config-source-edit.js';
5
5
  * addon, fills no conductor slot" — a UI-only addon (BB-562) belongs in a
6
6
  * conductor `addons[]` but contributes a cockpit tab, not a slot. Listing it is
7
7
  * not cosmetic: an UNKNOWN specifier sets `addonsAreOpaque` below, which
8
- * downgrades a genuinely missing remote/executor/workspace from
8
+ * downgrades a genuinely missing server/executor/worktree from
9
9
  * `missing_required_key` to `unknown_value`.
10
10
  */
11
11
  export const CONDUCTOR_ADDON_SLOTS = {
12
- '@bakers-build/addon-remote-drupal': ['remote'],
13
- '@bakers-build/addon-herdr': ['executor', 'workspace'],
14
- '@bakers-build/addon-orca': ['executor', 'workspace'],
12
+ '@bakers-build/addon-remote-drupal': ['server'],
13
+ '@bakers-build/addon-herdr': ['executor', 'worktree'],
14
+ '@bakers-build/addon-orca': ['executor', 'worktree'],
15
15
  '@bakers-build/addon-herdr-core': ['executor'],
16
- '@bakers-build/addon-fake': ['remote', 'executor', 'workspace'],
17
- '@bakers-build/addon-workspace-git': ['workspace'],
16
+ '@bakers-build/addon-fake': ['server', 'executor', 'worktree'],
17
+ '@bakers-build/addon-workspace-git': ['worktree'],
18
18
  '@bakers-build/addon-claude': ['agent'],
19
19
  '@bakers-build/addon-codex': ['agent'],
20
20
  '@bakers-build/addon-grok': ['agent'],
@@ -41,83 +41,31 @@ export const CONDUCTOR_ADDON_SLOTS = {
41
41
  };
42
42
  function validateConductorSources(options, editors, report) {
43
43
  const recheck = configRecheckCommand((options.scope ?? 'all'), report.roots.project);
44
- const localFile = report.files.find((candidate) => candidate.kind === 'local');
45
- const localEditor = localFile ? editors.get(localFile.path) : undefined;
46
- for (const file of report.files.filter((candidate) => candidate.selected && candidate.kind === 'conductor')) {
44
+ for (const file of report.files.filter((candidate) => candidate.selected && candidate.kind === 'project')) {
47
45
  const editor = editors.get(file.path);
48
46
  if (editor?.source.shape !== 'object')
49
47
  continue;
50
48
  const start = report.findings.length;
51
- const add = (code, key, expected, property = editor.property(key), findingPath = file.path) => {
49
+ // Field shapes are the schema's; only what a schema cannot know is here:
50
+ // which slots the listed addons fill.
51
+ const add = (code, key, expected, property = editor.property(key)) => {
52
52
  const unknown = code === 'unknown_value';
53
53
  report.findings.push({
54
54
  code,
55
55
  severity: unknown ? 'warning' : 'error',
56
56
  stage: 'schema',
57
- path: findingPath,
57
+ path: file.path,
58
58
  key,
59
59
  expected,
60
60
  observed: unknown ? '[COMPUTED]' : (property?.value ?? null),
61
61
  owner: 'project',
62
62
  related: [],
63
63
  statically_determined: property?.staticallyDetermined ?? false,
64
- remediation: `${unknown ? 'Determine' : 'Set'} ${key} in ${shellQuote(findingPath)}, then run ${recheck}.`,
64
+ remediation: `${unknown ? 'Determine' : 'Set'} ${key} in ${shellQuote(file.path)}, then run ${recheck}.`,
65
65
  recheck,
66
66
  ...(property ? { line: property.line, column: property.column } : {}),
67
67
  });
68
68
  };
69
- for (const legacy of ['project', 'bb_workspace']) {
70
- if (!editor.property(legacy))
71
- continue;
72
- add('misplaced_key', legacy, `Committed bakers.build identity belongs under bakers.${legacy === 'project' ? 'project' : 'workspace'}.`);
73
- const finding = report.findings.at(-1);
74
- if (finding)
75
- finding.remediation = `Move ${legacy} to bakers.${legacy === 'project' ? 'project' : 'workspace'} in ${shellQuote(file.path)}, then run ${recheck}.`;
76
- }
77
- // A conductor is machine + project + variant: no project file names an id.
78
- for (const [source, path] of [
79
- [editor, file.path],
80
- [localEditor, localFile?.path],
81
- ]) {
82
- if (!source || !path)
83
- continue;
84
- for (const key of ['conductor_id', 'machine_id', 'label']) {
85
- const property = source.property(key);
86
- if (!property)
87
- continue;
88
- add('retired_key', key, 'No identity in a project config: a conductor is machine + project + variant.', property, path);
89
- const finding = report.findings.at(-1);
90
- if (finding)
91
- finding.remediation = `Remove ${key} from ${shellQuote(path)}; the machine identity comes from bakers init.`;
92
- }
93
- }
94
- const bakers = editor.property('bakers');
95
- const bakersExpression = editor.expression('bakers');
96
- if (bakers &&
97
- (bakers.nodeType !== 'ObjectExpression' ||
98
- (bakersExpression &&
99
- new ConfigSourceEditor(`export default ${bakersExpression};`).source
100
- .unknownKeys))) {
101
- add('unsupported_source_shape', 'bakers', 'A statically inspectable bakers object without spreads is required.');
102
- const finding = report.findings.at(-1);
103
- if (finding)
104
- finding.remediation = `Write bakers as a literal object without spreads in ${shellQuote(file.path)}, then run ${recheck}.`;
105
- }
106
- const validateIdentity = (key) => {
107
- const property = editor.property(key);
108
- if (!property) {
109
- add(editor.source.unknownKeys ? 'unknown_value' : 'missing_required_key', key, 'A nonempty conductor project.');
110
- }
111
- else if (property.staticallyDetermined &&
112
- typeof property.value === 'string' &&
113
- property.value.trim() !== '') {
114
- return;
115
- }
116
- else {
117
- add(property.staticallyDetermined ? 'invalid_value' : 'unknown_value', key, 'A nonempty conductor project.', property);
118
- }
119
- };
120
- validateIdentity('bakers.project');
121
69
  const addon = editor.property('addons');
122
70
  const addonSlots = new Set();
123
71
  let addonsAreOpaque = false;
@@ -141,57 +89,10 @@ function validateConductorSources(options, editors, report) {
141
89
  }
142
90
  }
143
91
  }
144
- // The `agent` slot is intentionally excluded: agent ownership now belongs to
145
- // machine.config.js (machine schema v3+). A conductor config that declares
146
- // no agent slot or no agent-contributing addons is valid — machine.config.js
147
- // provides the candidates at runtime. Existing pre-migration configs that
148
- // still carry agent addons continue to validate until the conductor 0→1
149
- // migration removes them.
150
- for (const slot of ['remote', 'executor', 'workspace']) {
151
- const property = editor.property(slot);
152
- if (slot === 'workspace' &&
153
- property?.staticallyDetermined &&
154
- typeof property.value === 'string' &&
155
- property.value.trim() !== '' &&
156
- addonSlots.has('workspace'))
92
+ for (const slot of ['server', 'executor', 'worktree']) {
93
+ if (editor.property(slot) || addonSlots.has(slot))
157
94
  continue;
158
- if (!property) {
159
- if (addonSlots.has(slot))
160
- continue;
161
- add(addon && addonsAreOpaque ? 'unknown_value' : 'missing_required_key', slot, `A conductor ${slot} plugin supplied by an explicit slot or known addon.`);
162
- continue;
163
- }
164
- if (!property.staticallyDetermined) {
165
- add('unknown_value', slot, `A conductor ${slot} plugin supplied by an explicit slot or known addon.`, property);
166
- continue;
167
- }
168
- const descriptor = (prefix, kind) => {
169
- const plugin = editor.property(`${prefix}.plugin`)?.value;
170
- return ((typeof plugin === 'string' && plugin.trim() !== '') ||
171
- editor.property(`${prefix}.kind`)?.value === kind);
172
- };
173
- if (slot === 'agent' && property.nodeType === 'ArrayExpression') {
174
- let unknownCandidate = false;
175
- let invalidCandidate = (property.arrayLength ?? 0) === 0;
176
- for (let index = 0; index < (property.arrayLength ?? 0); index++) {
177
- const prefix = `agent[${index}]`;
178
- const candidate = editor.property(prefix);
179
- const wrapped = editor.property(`${prefix}.agent`);
180
- if (!candidate?.staticallyDetermined ||
181
- wrapped?.staticallyDetermined === false)
182
- unknownCandidate = true;
183
- else if (!descriptor(prefix, 'agent') &&
184
- !descriptor(`${prefix}.agent`, 'agent'))
185
- invalidCandidate = true;
186
- }
187
- if (unknownCandidate)
188
- add('unknown_value', slot, `A conductor ${slot} plugin supplied by an explicit slot or known addon.`, property);
189
- else if (invalidCandidate)
190
- add('invalid_value', slot, `A conductor ${slot} plugin supplied by an explicit slot or known addon.`, property);
191
- continue;
192
- }
193
- if (property.nodeType !== 'ObjectExpression' || !descriptor(slot, slot))
194
- add('invalid_value', slot, `A conductor ${slot} plugin supplied by an explicit slot or known addon.`, property);
95
+ add(addon && addonsAreOpaque ? 'unknown_value' : 'missing_required_key', slot, `A ${slot} supplied by an explicit slot or a listed addon.`);
195
96
  }
196
97
  const findings = report.findings.slice(start);
197
98
  if (findings.some((finding) => finding.severity === 'error'))
@@ -207,21 +108,13 @@ export function validateConfigSources(options, texts, files) {
207
108
  .map(([path, text]) => [path, new ConfigSourceEditor(text)]));
208
109
  const resolved = new Set();
209
110
  const global = files.find((f) => f.kind === 'connection');
210
- const local = files.find((f) => f.kind === 'local');
211
111
  const globalEditor = global ? editors.get(global.path) : undefined;
212
- const localEditor = local ? editors.get(local.path) : undefined;
213
112
  const primitive = (e, key) => {
214
113
  const p = e?.property(key);
215
114
  return p?.staticallyDetermined && p.value !== undefined
216
115
  ? JSON.stringify(p.value)
217
116
  : undefined;
218
117
  };
219
- const fallback = (localKey, defaultExpression) => {
220
- const p = localEditor?.property(localKey);
221
- if (!p || (p.staticallyDetermined && p.value === null))
222
- return defaultExpression;
223
- return primitive(localEditor, localKey);
224
- };
225
118
  let inherits = false;
226
119
  for (const file of files) {
227
120
  const e = editors.get(file.path);
@@ -247,12 +140,14 @@ export function validateConfigSources(options, texts, files) {
247
140
  p.value === '@dropsh/plugin-oauth2')?.[0]
248
141
  .replace(/\.plugin$/, '');
249
142
  const values = {
250
- baseUrl: fallback('base_url', primitive(globalEditor, 'site.base_url')),
251
- workspaceId: fallback('workspace_id', primitive(globalEditor, 'workspace_id')),
252
- clientId: fallback('oauth.client_id', auth ? primitive(globalEditor, `${auth}.with.client_id`) : undefined),
253
- clientSecret: fallback('oauth.client_secret', auth
143
+ baseUrl: primitive(globalEditor, 'site.base_url'),
144
+ workspaceId: primitive(globalEditor, 'workspace_id'),
145
+ clientId: auth
146
+ ? primitive(globalEditor, `${auth}.with.client_id`)
147
+ : undefined,
148
+ clientSecret: auth
254
149
  ? primitive(globalEditor, `${auth}.with.client_secret`)
255
- : undefined),
150
+ : undefined,
256
151
  };
257
152
  for (const [name, value] of Object.entries(values))
258
153
  if (value !== undefined)
@@ -289,9 +184,7 @@ export function validateConfigSources(options, texts, files) {
289
184
  }
290
185
  for (const key of [...e.source.properties.keys()]) {
291
186
  const expression = e.expression(key);
292
- let value = expression ? declarations.get(expression) : undefined;
293
- if (expression === 'local.oauth?.client_secret')
294
- value = primitive(localEditor, 'oauth.client_secret');
187
+ const value = expression ? declarations.get(expression) : undefined;
295
188
  if (value !== undefined) {
296
189
  e.set(key, value);
297
190
  resolved.add(`${file.path}:${key}`);
@@ -303,7 +196,7 @@ export function validateConfigSources(options, texts, files) {
303
196
  overlay.set(path, e.text);
304
197
  const report = inventoryConfig({ ...options, sourceTexts: overlay }).report;
305
198
  validateConductorSources(options, editors, report);
306
- // Literal values resolved from the local file are not secrets stored in the committed file.
199
+ // Literal values resolved from generated wiring are not secrets stored in the committed file.
307
200
  report.findings = report.findings.filter((f) => !(f.code === 'misplaced_key' &&
308
201
  f.key?.endsWith('client_secret') &&
309
202
  resolved.has(`${f.path}:${f.key}`)));
@@ -7,15 +7,12 @@ export interface BbProjectSelection {
7
7
  workspace?: string;
8
8
  }
9
9
  export type BbProjectOwner = BbWorkspaceOwner;
10
- /** Read committed bakers.build identity without executing conductor source. */
11
- export declare function readBbProjectSelection(path: string): BbProjectSelection;
10
+ /**
11
+ * Read the committed `project: { name, workspace }` without executing the
12
+ * file. `BAKERS_PROJECT` overrides the name for this process.
13
+ */
14
+ export declare function readBbProjectSelection(path: string, env?: NodeJS.ProcessEnv): BbProjectSelection;
12
15
  /** Establish the exact file that can receive a nested workspace choice. */
13
16
  export declare function bakersProjectOwner(path: string): BbProjectOwner;
14
- /** Read the committed project name without executing engine config. */
15
- export declare function readProjectSelection(path: string): string | undefined;
16
- /** Read the committed product-workspace name without executing engine config. */
17
- export declare function readBbWorkspaceSelection(path: string): string | undefined;
18
- /** Establish the conductor-owned source that the cockpit may update. */
19
- export declare function bakersWorkspaceOwner(path: string): BbWorkspaceOwner;
20
17
  /** Atomically update only the product-workspace field, preserving plugin slots. */
21
18
  export declare function writeBbWorkspaceSelection(owner: BbWorkspaceOwner, selected: string, hint: string): Promise<void>;
@@ -1,91 +1,48 @@
1
1
  import { existsSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync, } from 'node:fs';
2
2
  import { basename } from 'node:path';
3
+ import { stemForConfigFile } from '@bakers-build/core';
3
4
  import { ConfigSourceEditor } from './config-source-edit.js';
4
- /** Read committed bakers.build identity without executing conductor source. */
5
- export function readBbProjectSelection(path) {
5
+ /**
6
+ * Read the committed `project: { name, workspace }` without executing the
7
+ * file. `BAKERS_PROJECT` overrides the name for this process.
8
+ */
9
+ export function readBbProjectSelection(path, env = process.env) {
6
10
  const editor = new ConfigSourceEditor(readFileSync(path, 'utf8'));
7
- const invalid = () => new Error(`Cannot read committed bakers.project in ${path}; set bakers: { project: '<name>' } as a literal, without a top-level project or bb_workspace.`);
8
- const bakers = editor.property('bakers');
9
- const bakersExpression = editor.expression('bakers');
10
- const bakersHasSpread = bakersExpression
11
- ? new ConfigSourceEditor(`export default ${bakersExpression};`).source
11
+ const invalid = () => new Error(`Cannot read the committed project in ${path}; set project: { name: '<name>' } as a literal object without spreads.`);
12
+ const block = editor.property('project');
13
+ const blockExpression = editor.expression('project');
14
+ const hasSpread = blockExpression
15
+ ? new ConfigSourceEditor(`export default ${blockExpression};`).source
12
16
  .unknownKeys
13
17
  : false;
14
- const project = editor.property('bakers.project');
15
- const workspace = editor.property('bakers.workspace');
18
+ const override = env.BAKERS_PROJECT?.trim();
19
+ const name = editor.property('project.name');
20
+ const workspace = editor.property('project.workspace');
21
+ const literal = (p) => p?.staticallyDetermined &&
22
+ typeof p.value === 'string' &&
23
+ p.value.trim() !== '';
16
24
  if (editor.source.shape !== 'object' ||
17
- bakersHasSpread ||
18
- editor.property('project') ||
19
- editor.property('bb_workspace') ||
20
- bakers?.nodeType !== 'ObjectExpression' ||
21
- !project?.staticallyDetermined ||
22
- typeof project.value !== 'string' ||
23
- !project.value.trim() ||
24
- (workspace !== undefined &&
25
- (!workspace.staticallyDetermined ||
26
- typeof workspace.value !== 'string' ||
27
- !workspace.value.trim())))
25
+ hasSpread ||
26
+ block?.nodeType !== 'ObjectExpression' ||
27
+ (!override && !literal(name)) ||
28
+ (workspace !== undefined && !literal(workspace)))
28
29
  throw invalid();
29
30
  return {
30
- project: project.value.trim(),
31
+ project: override || String(name?.value).trim(),
31
32
  ...(workspace ? { workspace: workspace.value.trim() } : {}),
32
33
  };
33
34
  }
34
35
  /** Establish the exact file that can receive a nested workspace choice. */
35
36
  export function bakersProjectOwner(path) {
36
- const file = basename(path);
37
- if (file !== 'conductor.config.js' && !file.endsWith('.conductor.config.js'))
38
- throw new Error(`Cannot write bakers.build workspace selection to ${path}.`);
37
+ if (stemForConfigFile(basename(path)) === undefined)
38
+ throw new Error(`Cannot write bakers.build workspace selection to ${path}; expected project.config.js or a project.<name>.config.js variant. No configuration was written.`);
39
39
  readBbProjectSelection(path);
40
40
  return { path, before: readFileSync(path, 'utf8') };
41
41
  }
42
- /** Read the committed project name without executing engine config. */
43
- export function readProjectSelection(path) {
44
- try {
45
- const property = new ConfigSourceEditor(readFileSync(path, 'utf8')).property('project');
46
- return property?.staticallyDetermined &&
47
- typeof property.value === 'string' &&
48
- property.value.trim() !== ''
49
- ? property.value.trim()
50
- : undefined;
51
- }
52
- catch {
53
- return undefined;
54
- }
55
- }
56
- /** Read the committed product-workspace name without executing engine config. */
57
- export function readBbWorkspaceSelection(path) {
58
- try {
59
- const property = new ConfigSourceEditor(readFileSync(path, 'utf8')).property('bb_workspace');
60
- return property?.staticallyDetermined &&
61
- typeof property.value === 'string' &&
62
- property.value.trim() !== ''
63
- ? property.value.trim()
64
- : undefined;
65
- }
66
- catch {
67
- return undefined;
68
- }
69
- }
70
- /** Establish the conductor-owned source that the cockpit may update. */
71
- export function bakersWorkspaceOwner(path) {
72
- const file = basename(path);
73
- if (file !== 'conductor.config.js' && !file.endsWith('.conductor.config.js'))
74
- throw new Error(`Cannot write bakers.build workspace selection to ${path}; expected conductor.config.js or a named conductor variant. No configuration was written.`);
75
- const before = readFileSync(path, 'utf8');
76
- const editor = new ConfigSourceEditor(before);
77
- const property = editor.property('bb_workspace');
78
- if (editor.source.shape === 'object' &&
79
- !editor.source.unknownKeys &&
80
- (!property ||
81
- (property.staticallyDetermined && typeof property.value === 'string')))
82
- return { path, before };
83
- throw new Error(`Cannot establish a literal writable bb_workspace in ${path}. No configuration was written.`);
84
- }
85
42
  /** Atomically update only the product-workspace field, preserving plugin slots. */
86
43
  export async function writeBbWorkspaceSelection(owner, selected, hint) {
87
44
  const editor = new ConfigSourceEditor(owner.before);
88
- editor.set(editor.property('bakers.project') ? 'bakers.workspace' : 'bb_workspace', JSON.stringify(selected));
45
+ editor.set('project.workspace', JSON.stringify(selected));
89
46
  if ((existsSync(owner.path) ? readFileSync(owner.path, 'utf8') : null) !==
90
47
  owner.before)
91
48
  throw new Error(`Configuration changed while choosing; recheck ${owner.path} before retrying. No configuration was written.`);