@bakers-build/core 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.
@@ -7,7 +7,6 @@ import { configRecheckCommand, finalizeConfigReport, } from './config-report.js'
7
7
  import { inspectConfigSource, } from './config-source.js';
8
8
  const SCOPES = ['machine', 'connection', 'project', 'all'];
9
9
  const SECRET_KEY = /secret|token|password|credential|client_id|authorization/i;
10
- const IDENTIFIER = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
11
10
  /** Public observed values never include expressions, objects or credentials. */
12
11
  function observed(property, key) {
13
12
  if (SECRET_KEY.test(key))
@@ -244,8 +243,10 @@ export function inventoryConfig(options = {}) {
244
243
  add('version_marker_disagreement', 'schema_version', 'Header and schema_version markers agree.', `Reconcile version markers in ${shellQuote(path)} with its actual schema before upgrading.`, 'schema', 'error', field);
245
244
  const currentVersion = file.version.current;
246
245
  if (currentVersion !== null &&
247
- markers.some((version) => version > currentVersion)) {
248
- add('future_schema_version', 'schema_version', `Schema version is at most ${file.version.current}.`, 'Install a bakers.build release that supports this schema; do not downgrade the file.', 'schema', 'error', field);
246
+ markers.some((version) => version !== currentVersion)) {
247
+ add('unsupported_schema_version', 'schema_version', `Schema version is ${currentVersion}.`, kind === 'machine'
248
+ ? 'Run bakers init to rewrite it at version 1.'
249
+ : `Remove ${shellQuote(path)} and run bakers init to recreate it.`, 'schema', 'error', field);
249
250
  }
250
251
  const requireValue = (key, expected, valid, requiredKey = true) => {
251
252
  const property = source.properties.get(key);
@@ -280,9 +281,12 @@ export function inventoryConfig(options = {}) {
280
281
  Number.isInteger(property.value) &&
281
282
  property.value > 0);
282
283
  if (kind === 'machine') {
283
- for (const key of ['machine_id', 'user_id'])
284
- requireValue(key, 'A nonempty identifier using letters, numbers, dots, underscores or hyphens.', (property) => typeof property.value === 'string' &&
285
- IDENTIFIER.test(property.value));
284
+ // New machines get a UUID from bakers init; existing ones keep their id.
285
+ requireValue('machine_id', 'A nonempty machine id.', nonempty);
286
+ requireValue('label', 'A nonempty display label.', nonempty);
287
+ const userId = source.properties.get('user_id');
288
+ if (userId)
289
+ add('retired_key', 'user_id', 'No user_id: the server takes the owner from sign-in.', 'Run bakers init to rewrite the file without it.', 'schema', 'error', userId);
286
290
  requireValue('max_parallel', 'A positive integer host capacity.', (property) => typeof property.value === 'number' &&
287
291
  Number.isInteger(property.value) &&
288
292
  property.value > 0);
@@ -313,11 +317,11 @@ export function inventoryConfig(options = {}) {
313
317
  const agentAddons = source.properties.get('agents.addons');
314
318
  if (agentAddons) {
315
319
  const items = fragmentOf(agentAddons).replace(/^\[\s*|\s*\]$/g, '');
316
- add('retired_key', 'agents.addons', 'Agent harnesses are listed in the top-level addons[].', `Move agents.addons into the top-level addons[] of ${shellQuote(path)}: addons: [${items}] (or run bakers config upgrade --scope machine).`, 'schema', 'error', agentAddons);
320
+ add('retired_key', 'agents.addons', 'Agent harnesses are listed in the top-level addons[].', `Move agents.addons into the top-level addons[] of ${shellQuote(path)}: addons: [${items}].`, 'schema', 'error', agentAddons);
317
321
  }
318
322
  const ports = source.properties.get('ports');
319
323
  if (ports)
320
- add('retired_key', 'ports', 'The ports transport is set in the @bakers-build/addon-ports addons[] entry.', `Move ports into the addons[] of ${shellQuote(path)}: addons: [{ use: '@bakers-build/addon-ports', with: ${fragmentOf(ports)} }] (or run bakers config upgrade --scope machine).`, 'schema', 'error', ports);
324
+ add('retired_key', 'ports', 'The ports transport is set in the @bakers-build/addon-ports addons[] entry.', `Move ports into the addons[] of ${shellQuote(path)}: addons: [{ use: '@bakers-build/addon-ports', with: ${fragmentOf(ports)} }].`, 'schema', 'error', ports);
321
325
  for (const key of [
322
326
  'base_url',
323
327
  'client_id',
@@ -326,7 +330,7 @@ export function inventoryConfig(options = {}) {
326
330
  ]) {
327
331
  const property = source.properties.get(key);
328
332
  if (property)
329
- add('misplaced_key', key, `Connection-owned ${key} belongs in ${connectionPath}.`, `bakers config upgrade --scope all`, 'ownership', 'error', property, 'connection');
333
+ add('misplaced_key', key, `Connection-owned ${key} belongs in ${connectionPath}.`, `Move ${key} from ${shellQuote(path)} into ${shellQuote(connectionPath)}.`, 'ownership', 'error', property, 'connection');
330
334
  }
331
335
  }
332
336
  if (kind === 'project-connection')
@@ -391,7 +395,7 @@ export function inventoryConfig(options = {}) {
391
395
  if (property)
392
396
  add('misplaced_key', key, key === 'tunnel'
393
397
  ? `Machine-owned tunnel belongs in ${machinePath}.`
394
- : `Host capacity belongs in ${machinePath} at max_parallel.`, 'bakers config upgrade --scope all', 'ownership', 'error', property, 'machine');
398
+ : `Host capacity belongs in ${machinePath} at max_parallel.`, `Move ${key} from ${shellQuote(path)} into ${shellQuote(machinePath)}.`, 'ownership', 'error', property, 'machine');
395
399
  }
396
400
  }
397
401
  const findings = report.findings.slice(startFindings);
@@ -486,7 +490,7 @@ export function inventoryConfig(options = {}) {
486
490
  ...finding,
487
491
  code: 'conflicting_values',
488
492
  expected: 'Source and destination values agree before relocation.',
489
- remediation: `Choose the intended ${finding.key} value between ${shellQuote(finding.path)} and ${shellQuote(destinationPath)}, then run bakers config upgrade --scope all.`,
493
+ remediation: `Choose the intended ${finding.key} value between ${shellQuote(finding.path)} and ${shellQuote(destinationPath)}, then keep it only in ${shellQuote(destinationPath)}.`,
490
494
  });
491
495
  }
492
496
  if (!resolved.includes(finding.owner)) {
@@ -494,7 +498,7 @@ export function inventoryConfig(options = {}) {
494
498
  ...finding,
495
499
  code: 'out_of_scope_write_required',
496
500
  expected: `Repair requires writing ${destinationPath}, outside selected scope ${scope}.`,
497
- remediation: 'bakers config upgrade --scope all',
501
+ remediation: `Move ${finding.key} into ${shellQuote(destinationPath)}.`,
498
502
  });
499
503
  }
500
504
  }
@@ -2,7 +2,7 @@ export type ConfigScope = 'machine' | 'connection' | 'project' | 'all';
2
2
  export type ConfigLayer = Exclude<ConfigScope, 'all'>;
3
3
  export type ConfigOperation = 'init' | 'upgrade' | 'check';
4
4
  export type ConfigFileKind = 'machine' | 'connection' | 'project-connection' | 'conductor' | 'local';
5
- export type ConfigFindingCode = 'scope_required' | 'invalid_scope' | 'project_required' | 'missing_required_file' | 'missing_required_key' | 'unreadable_file' | 'syntax_error' | 'unsupported_source_shape' | 'unknown_value' | 'invalid_value' | 'version_marker_disagreement' | 'future_schema_version' | 'misplaced_key' | 'conflicting_values' | 'out_of_scope_write_required' | 'changed_since_planning' | 'authentication_failure' | 'no_workspace' | 'cancelled_selection' | 'superseded_file' | 'dead_key' | 'retired_key' | 'addon_scope_not_allowed' | 'addon_scope_skipped' | 'addon_with_invalid' | 'write_failure';
5
+ export type ConfigFindingCode = 'scope_required' | 'invalid_scope' | 'project_required' | 'missing_required_file' | 'missing_required_key' | 'unreadable_file' | 'syntax_error' | 'unsupported_source_shape' | 'unknown_value' | 'invalid_value' | 'version_marker_disagreement' | 'unsupported_schema_version' | 'misplaced_key' | 'conflicting_values' | 'out_of_scope_write_required' | 'changed_since_planning' | 'authentication_failure' | 'no_workspace' | 'cancelled_selection' | 'superseded_file' | 'dead_key' | 'retired_key' | 'addon_scope_not_allowed' | 'addon_scope_skipped' | 'addon_with_invalid' | 'write_failure';
6
6
  export interface ConfigLocation {
7
7
  path: string;
8
8
  key: string | null;
@@ -8,6 +8,7 @@ import { findConfigProjectBbDir, homeBbDir, resolveBbConfigPath, } from './baker
8
8
  import { inspectConfigSource } from './config-source.js';
9
9
  import { importConfig } from './import-config.js';
10
10
  import { machineUiConfigPath, projectConductorConfigPath, readUiEntryLayers, } from './layered-ui-entries.js';
11
+ import { assertSchemaVersion1 } from './machine-context.js';
11
12
  import { resolveModuleEslintStyle } from './resolve-module.js';
12
13
  /**
13
14
  * A connection config that was RESOLVED but is not usable — a missing
@@ -257,6 +258,7 @@ export async function loadBbConnectionBootstrap(host, opts = {}) {
257
258
  if (!isRecord(raw)) {
258
259
  throw new Error(`bakers connection config default export must be an object (${configPath})`);
259
260
  }
261
+ assertSchemaVersion1(configPath, raw);
260
262
  const site = isRecord(raw.site) ? raw.site : {};
261
263
  const baseUrl = typeof site.base_url === 'string' ? site.base_url : '';
262
264
  if (baseUrl.trim() === '') {
@@ -14,10 +14,12 @@ export interface MachineAgentPolicy {
14
14
  default_agent?: string;
15
15
  routes?: AgentRoutes;
16
16
  }
17
- /** Local host identity, operator short name and shared capacity. */
17
+ /** Local host identity, display label and shared capacity. */
18
18
  export interface MachineContext {
19
+ /** Host key: a UUID from `bakers init` for a new machine (lowercased); an existing id stays. */
19
20
  machine_id: string;
20
- user_id: string;
21
+ /** Display name for people; never a key. */
22
+ label: string;
21
23
  /**
22
24
  * Host concurrent-run budget (BB-353). Optional; consumers default to 1.
23
25
  * Source of truth for capacity — not the engine conductor.config.js.
@@ -42,5 +44,16 @@ export interface MachineContext {
42
44
  export declare function machineContextPath(): string;
43
45
  /** Resolve explicit or canonical current host context. */
44
46
  export declare function resolveMachineContextPath(path?: string): string;
45
- /** Import an existing context module's default export, or `{}` if absent/broken. */
47
+ /**
48
+ * Every config file (machine, connection, project) is at schema version 1.
49
+ * Any other version, in the `schema_version` field or the
50
+ * `@bakers-schema-version` header, predates the fresh start and is refused.
51
+ */
52
+ export declare function assertSchemaVersion1(path: string, raw: Record<string, unknown>, remedy?: string): void;
53
+ /**
54
+ * Import an existing context module's default export, or `{}` if absent/broken.
55
+ * An old file (`user_id`, a schema version other than 1) throws, naming
56
+ * `bakers init`, which rewrites it in place. An existing machine keeps its
57
+ * `machine_id` as it is; only a UUID is normalised to lowercase.
58
+ */
46
59
  export declare function readMachineContext(path?: string): Promise<Partial<MachineContext>>;
@@ -1,4 +1,4 @@
1
- import { existsSync } from 'node:fs';
1
+ import { existsSync, readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { pathToFileURL } from 'node:url';
4
4
  import { homeBbDir } from './bakers-dir.js';
@@ -12,20 +12,59 @@ export function resolveMachineContextPath(path) {
12
12
  return path;
13
13
  return machineContextPath();
14
14
  }
15
- /** Import an existing context module's default export, or `{}` if absent/broken. */
15
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
16
+ /** Whether a value is a UUID, in any case. */
17
+ function isUuid(value) {
18
+ return typeof value === 'string' && UUID.test(value);
19
+ }
20
+ /**
21
+ * Every config file (machine, connection, project) is at schema version 1.
22
+ * Any other version, in the `schema_version` field or the
23
+ * `@bakers-schema-version` header, predates the fresh start and is refused.
24
+ */
25
+ export function assertSchemaVersion1(path, raw, remedy = 'remove the file and run bakers init') {
26
+ let text = '';
27
+ try {
28
+ text = readFileSync(path, 'utf8');
29
+ }
30
+ catch { }
31
+ const versions = [
32
+ ...(raw.schema_version !== undefined ? [raw.schema_version] : []),
33
+ ...[...text.matchAll(/@bakers-schema-version\s+(\d+)/g)].map((m) => Number(m[1])),
34
+ ];
35
+ const other = versions.find((version) => version !== 1);
36
+ if (other !== undefined)
37
+ throw new Error(`${path}: schema version ${String(other)} is not supported; ${remedy}`);
38
+ }
39
+ /**
40
+ * Import an existing context module's default export, or `{}` if absent/broken.
41
+ * An old file (`user_id`, a schema version other than 1) throws, naming
42
+ * `bakers init`, which rewrites it in place. An existing machine keeps its
43
+ * `machine_id` as it is; only a UUID is normalised to lowercase.
44
+ */
16
45
  export async function readMachineContext(path) {
17
46
  const resolved = resolveMachineContextPath(path);
18
47
  if (!existsSync(resolved))
19
48
  return {};
49
+ let raw;
20
50
  try {
21
51
  // Cache-bust so a re-render within one process re-reads fresh.
22
- const mod = await import(`${pathToFileURL(resolved).href}?t=${Date.now()}`);
23
- const raw = mod.default;
24
- return raw && typeof raw === 'object'
25
- ? raw
26
- : {};
52
+ raw = (await import(`${pathToFileURL(resolved).href}?t=${Date.now()}`))
53
+ .default;
27
54
  }
28
55
  catch {
29
56
  return {};
30
57
  }
58
+ if (!raw || typeof raw !== 'object')
59
+ return {};
60
+ const ctx = raw;
61
+ assertSchemaVersion1(resolved, ctx, 'run bakers init to rewrite it');
62
+ if ('user_id' in ctx)
63
+ throw new Error(`${resolved}: user_id is retired (the server takes the owner from sign-in); run bakers init to rewrite the file`);
64
+ return {
65
+ ...ctx,
66
+ ...(isUuid(ctx.machine_id)
67
+ ? { machine_id: ctx.machine_id.toLowerCase() }
68
+ : {}),
69
+ };
31
70
  }
@@ -9,13 +9,12 @@ export { type ConfigSourceInspection, type ConfigSourceProperty, declaresTopLeve
9
9
  export { HOME_IMPORT_EXPRESSION_PATTERN, importConfig, } from './cli/import-config.js';
10
10
  export { type LayeredUiEntryLayer, machineUiConfigPath, projectConductorConfigPath, readUiEntryLayers, } from './cli/layered-ui-entries.js';
11
11
  export { type BbConnectionConfig, BbConnectionConfigError, type BbConnectionGlobals, type BbConnectionLoadOptions, type BbConnectionSelection, type EffectiveConnectionField, loadBbConfig, loadBbConnectionBootstrap, reportLoadedBbConfigFields, resolveBbConnectionSelection, } from './cli/load-bakers-config.js';
12
- export { type AgentRoutes, type MachineContext, machineContextPath, readMachineContext, resolveMachineContextPath, } from './cli/machine-context.js';
12
+ export { type AgentRoutes, assertSchemaVersion1, type MachineContext, machineContextPath, readMachineContext, resolveMachineContextPath, } from './cli/machine-context.js';
13
13
  export { corePackageRoot } from './cli/paths.js';
14
14
  export { resolveModuleEslintStyle } from './cli/resolve-module.js';
15
15
  export { BB_PACKAGE, checkForUpdate, declineUpdate, defaultUpdateCachePath, fetchLatestVersion, fetchUpdateNotice, printVersionLine, REGISTRY_LATEST_URL, resolveCliVersion, UNKNOWN_VERSION, UPDATE_CHECK_TTL_MS, type UpdateCheckOptions, type UpdateCheckResult, updateNotice, } from './cli/version-check.js';
16
16
  export { discoverBbWorkspaces, loadReadyBbConnection, resolveWorkspaceSelector, type WorkspaceChoice, type WorkspaceRecoveryOptions, workspaceSearchCommand, } from './cli/workspace-recovery.js';
17
17
  export { configHomeOf, defaultRootGitExec, deriveCheckoutRoot, type RootGitExec, } from './core/checkout-root.js';
18
- export { conductorId } from './core/conductor-id.js';
19
18
  export { CommandRunner, ExecError, exec, setDefaultCommandRunner, } from './core/exec.js';
20
19
  export { type ConductorLiveness, type ConductorLivenessInput, deriveConductorLiveness, toUnixSeconds, } from './core/liveness.js';
21
20
  export { type ConductorLogger, createLogger } from './core/logger.js';
package/dist/src/index.js CHANGED
@@ -11,13 +11,12 @@ export { declaresTopLevelKey, findDefaultExportObject, inspectConfigSource, matc
11
11
  export { HOME_IMPORT_EXPRESSION_PATTERN, importConfig, } from './cli/import-config.js';
12
12
  export { machineUiConfigPath, projectConductorConfigPath, readUiEntryLayers, } from './cli/layered-ui-entries.js';
13
13
  export { BbConnectionConfigError, loadBbConfig, loadBbConnectionBootstrap, reportLoadedBbConfigFields, resolveBbConnectionSelection, } from './cli/load-bakers-config.js';
14
- export { machineContextPath, readMachineContext, resolveMachineContextPath, } from './cli/machine-context.js';
14
+ export { assertSchemaVersion1, machineContextPath, readMachineContext, resolveMachineContextPath, } from './cli/machine-context.js';
15
15
  export { corePackageRoot } from './cli/paths.js';
16
16
  export { resolveModuleEslintStyle } from './cli/resolve-module.js';
17
17
  export { BB_PACKAGE, checkForUpdate, declineUpdate, defaultUpdateCachePath, fetchLatestVersion, fetchUpdateNotice, printVersionLine, REGISTRY_LATEST_URL, resolveCliVersion, UNKNOWN_VERSION, UPDATE_CHECK_TTL_MS, updateNotice, } from './cli/version-check.js';
18
18
  export { discoverBbWorkspaces, loadReadyBbConnection, resolveWorkspaceSelector, workspaceSearchCommand, } from './cli/workspace-recovery.js';
19
19
  export { configHomeOf, defaultRootGitExec, deriveCheckoutRoot, } from './core/checkout-root.js';
20
- export { conductorId } from './core/conductor-id.js';
21
20
  export { CommandRunner, ExecError, exec, setDefaultCommandRunner, } from './core/exec.js';
22
21
  export { deriveConductorLiveness, toUnixSeconds, } from './core/liveness.js';
23
22
  export { createLogger } from './core/logger.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/core",
3
- "version": "0.5.1-next.849",
3
+ "version": "0.5.1-next.851",
4
4
  "description": "bakers.build surface-agnostic kernel: host contract, split-config helpers, addon preset/discovery machinery, shared primitives.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -38,7 +38,7 @@
38
38
  "yaml": "^2.7.0"
39
39
  },
40
40
  "bakersBuild": {
41
- "commit": "6405d5033ed2d034f264fc341db06ada455168a9",
41
+ "commit": "9547fdedfc72a8623ba101d72a39c20a9fef5a8e",
42
42
  "channel": "next"
43
43
  }
44
44
  }
@@ -1 +0,0 @@
1
- export declare function conductorId(absPath: string): string;
@@ -1,8 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import { hostname } from 'node:os';
3
- export function conductorId(absPath) {
4
- return createHash('sha256')
5
- .update(`${hostname()}:${absPath}`)
6
- .digest('hex')
7
- .slice(0, 16);
8
- }