@bakers-build/core 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.
@@ -94,6 +94,7 @@ export interface ProjectConfig {
94
94
  url: string;
95
95
  /** Branch or tag. */
96
96
  ref: string;
97
+ /** Plugins to install from this marketplace, at least one. */
97
98
  plugins: Array<string>;
98
99
  }>;
99
100
  /** Function choosing the agent for a ticket; replaces the shipped selection. */
@@ -5,14 +5,16 @@ import type { RunClone } from './run-clone.js';
5
5
  * Git holding its lock must not fail a run start or a transfer.
6
6
  */
7
7
  export declare function refreshRunCloneIndex({ workspace }: RunClone): void;
8
+ /** Protected paths `to` changes against `from`, both commits of the parent. */
9
+ export declare function changedProtectedPaths(record: RunClone, from: string, to: string): string[];
8
10
  /** The run's ticket branch tip, read as plain files: Git never runs under the run's config. */
9
11
  export declare function runCloneTip(record: RunClone): string;
10
12
  /**
11
13
  * Give the run the parent's current `origin/<branch>` refs (default: its
12
- * target): objects as one new pack, each ref as a plain file. Nothing here
13
- * runs Git inside the run's directory.
14
+ * target) and the objects of `commits`, which get no ref: objects as one new
15
+ * pack, each ref as a plain file. Nothing here runs Git inside the run's directory.
14
16
  */
15
- export declare function refreshRunTarget(record: RunClone, branches?: readonly string[]): void;
17
+ export declare function refreshRunTarget(record: RunClone, branches?: readonly string[], commits?: readonly string[]): void;
16
18
  /**
17
19
  * Import verified objects through clean metadata and fast-forward the ticket
18
20
  * branch in the parent with compare-and-swap. Defaults to the run's branch tip.
@@ -41,6 +41,16 @@ function normalizeProtectedPaths(paths) {
41
41
  })),
42
42
  ];
43
43
  }
44
+ /** Protected paths `to` changes against `from`, NUL-separated; empty when none. */
45
+ function protectedDiff(run, record, from, to) {
46
+ return run('diff-tree', '-r', '--name-only', '-z', '--no-renames', from, to, '--', ...normalizeProtectedPaths(record.protectedPaths ?? []).map((path) => `:(literal)${path}`));
47
+ }
48
+ /** Protected paths `to` changes against `from`, both commits of the parent. */
49
+ export function changedProtectedPaths(record, from, to) {
50
+ return protectedDiff((...args) => git(record.parentGitDir, `--git-dir=${record.parentGitDir}`, ...args), record, from, to)
51
+ .split('\0')
52
+ .filter(Boolean);
53
+ }
44
54
  function rejectGitlinks(entries) {
45
55
  if (entries.split('\0').some((entry) => entry.startsWith('160000 ')))
46
56
  throw new Error('isolated Git: submodules are not supported');
@@ -184,16 +194,19 @@ function writeRunRef(record, ref, tip) {
184
194
  }
185
195
  /**
186
196
  * Give the run the parent's current `origin/<branch>` refs (default: its
187
- * target): objects as one new pack, each ref as a plain file. Nothing here
188
- * runs Git inside the run's directory.
197
+ * target) and the objects of `commits`, which get no ref: objects as one new
198
+ * pack, each ref as a plain file. Nothing here runs Git inside the run's directory.
189
199
  */
190
- export function refreshRunTarget(record, branches = record.target ? [record.target] : []) {
200
+ export function refreshRunTarget(record, branches = record.target ? [record.target] : [], commits = []) {
191
201
  const tips = branches.flatMap((branch) => {
192
202
  git(record.parentGitDir, 'check-ref-format', `refs/heads/${branch}`);
193
203
  const tip = parentOrigin(record, branch);
194
204
  return tip ? [{ branch, tip }] : [];
195
205
  });
196
- if (tips.length === 0)
206
+ if (commits.some((commit) => !HASH.test(commit)))
207
+ throw new Error('isolated Git: hand-off requires full commit hashes');
208
+ const wanted = [...tips.map(({ tip }) => tip), ...commits];
209
+ if (wanted.length === 0)
197
210
  return;
198
211
  // pack-objects renames its pack from the parent's objects dir; /tmp may be another filesystem (EXDEV).
199
212
  const scratch = mkdtempSync(join(record.parentGitDir, 'bb-target-refresh-'));
@@ -205,7 +218,7 @@ export function refreshRunTarget(record, branches = record.target ? [record.targ
205
218
  '--revs',
206
219
  join(scratch, 'pack'),
207
220
  ], {
208
- input: `${tips.map(({ tip }) => tip).join('\n')}\n^${record.expected}\n`,
221
+ input: `${wanted.join('\n')}\n^${record.expected}\n`,
209
222
  stdio: ['pipe', 'ignore', 'pipe'],
210
223
  });
211
224
  const pack = pinDir(record.gitDir, 'objects/pack', true);
@@ -240,6 +253,14 @@ export function transferIsolatedCommit(record, commit = runCloneTip(record)) {
240
253
  if (commit === record.expected)
241
254
  return commit;
242
255
  const parent = (...args) => git(record.parentGitDir, `--git-dir=${record.parentGitDir}`, ...args);
256
+ // A run still at a tip the host moved its branch past (forge_update_branch) has nothing to bring.
257
+ try {
258
+ parent('merge-base', '--is-ancestor', commit, record.expected);
259
+ return record.expected;
260
+ }
261
+ catch {
262
+ // Not an ancestor, or not in the parent yet: transfer it.
263
+ }
243
264
  const scratch = mkdtempSync(join(tmpdir(), 'bb-commit-transfer-'));
244
265
  try {
245
266
  git(scratch, 'init', '--bare', '--template=', `--object-format=${commit.length === 64 ? 'sha256' : 'sha1'}`, '-q');
@@ -253,7 +274,7 @@ export function transferIsolatedCommit(record, commit = runCloneTip(record)) {
253
274
  rejectGitlinks(git(scratch, 'ls-tree', '-r', '-z', commit));
254
275
  git(scratch, 'merge-base', '--is-ancestor', record.expected, commit);
255
276
  // Against the tip the run started from, so a merge of the target passes.
256
- if (git(scratch, 'diff-tree', '-r', '--name-only', '-z', '--no-renames', record.expected, commit, '--', ...normalizeProtectedPaths(record.protectedPaths ?? []).map((path) => `:(literal)${path}`)))
277
+ if (protectedDiff((...args) => git(scratch, ...args), record, record.expected, commit))
257
278
  throw new Error(`isolated Git: commit ${commit} changes a protected path`);
258
279
  // Only scratch's clean config is read; the run's hooks/config never reach host Git.
259
280
  parent('-c', 'protocol.file.allow=always', 'fetch', '--no-tags', '--no-write-fetch-head', scratch, commit);
@@ -15,6 +15,8 @@ export interface RunClone {
15
15
  target?: string;
16
16
  shared: boolean;
17
17
  protectedPaths?: string[];
18
+ /** Set when forge_update_branch changed protected paths the run cannot see: push refuses until a fresh clone. */
19
+ restartPending?: string;
18
20
  }
19
21
  export interface RunCloneOptions {
20
22
  /** Any path inside the parent checkout. */
@@ -0,0 +1,9 @@
1
+ export type Secrets = Readonly<Record<string, string>>;
2
+ /** `~/.bakers/.bakers.env`, beside `machine.config.js`; `BAKERS_HOME` applies. */
3
+ export declare function secretsFilePath(home?: string): string;
4
+ /** Throws naming each bad line by number, never its text: it may hold a value. */
5
+ export declare function parseSecretsFile(text: string): Record<string, string>;
6
+ /** The file's values; `{}` when it does not exist. Refuses a file others can read. */
7
+ export declare function loadSecretsFile(path?: string): Record<string, string>;
8
+ /** The declared `names` a run gets: a non-empty shell value wins over the file. */
9
+ export declare function pickSecrets(names: readonly string[], file: Secrets, env?: Readonly<Record<string, string | undefined>>): Record<string, string>;
@@ -0,0 +1,62 @@
1
+ // The machine's secrets file: `KEY=value` lines a conductor reads at start
2
+ // and hands to a run only for names an agent declares. Parsed, never sourced.
3
+ import { readFileSync, statSync } from 'node:fs';
4
+ import { join } from 'node:path';
5
+ import { homeBbDir } from '../cli/bakers-dir.js';
6
+ /** `~/.bakers/.bakers.env`, beside `machine.config.js`; `BAKERS_HOME` applies. */
7
+ export function secretsFilePath(home) {
8
+ return join(homeBbDir(home), '.bakers.env');
9
+ }
10
+ const LINE = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)=(.*)$/;
11
+ /** Throws naming each bad line by number, never its text: it may hold a value. */
12
+ export function parseSecretsFile(text) {
13
+ const values = {};
14
+ const bad = [];
15
+ text.split(/\r?\n/).forEach((line, index) => {
16
+ if (line.trim() === '' || line.trimStart().startsWith('#'))
17
+ return;
18
+ const match = LINE.exec(line);
19
+ if (!match) {
20
+ bad.push(index + 1);
21
+ return;
22
+ }
23
+ const raw = match[2].trim();
24
+ const quoted = raw.length >= 2 &&
25
+ (raw[0] === "'" || raw[0] === '"') &&
26
+ raw.endsWith(raw[0]);
27
+ values[match[1]] = quoted ? raw.slice(1, -1) : raw;
28
+ });
29
+ if (bad.length)
30
+ throw new Error(bad.map((n) => `line ${n}: expected KEY=value`).join('; '));
31
+ return values;
32
+ }
33
+ /** The file's values; `{}` when it does not exist. Refuses a file others can read. */
34
+ export function loadSecretsFile(path = secretsFilePath()) {
35
+ let mode;
36
+ try {
37
+ mode = statSync(path).mode;
38
+ }
39
+ catch (err) {
40
+ if (err.code === 'ENOENT')
41
+ return {};
42
+ throw err;
43
+ }
44
+ if (mode & 0o077)
45
+ throw new Error(`${path} is readable by group or others; not loaded. Fix it with: chmod 600 ${path}`);
46
+ try {
47
+ return parseSecretsFile(readFileSync(path, 'utf8'));
48
+ }
49
+ catch (err) {
50
+ throw new Error(`${path}: ${err.message}`);
51
+ }
52
+ }
53
+ /** The declared `names` a run gets: a non-empty shell value wins over the file. */
54
+ export function pickSecrets(names, file, env = process.env) {
55
+ const picked = {};
56
+ for (const name of names) {
57
+ const value = env[name] || file[name];
58
+ if (value)
59
+ picked[name] = value;
60
+ }
61
+ return picked;
62
+ }
@@ -20,7 +20,7 @@ export type { ConnectionConfig, MachineConfig, ProjectConfig, } from './config-t
20
20
  export { configHomeOf, defaultRootGitExec, deriveCheckoutRoot, type RootGitExec, } from './core/checkout-root.js';
21
21
  export { CommandRunner, ExecError, exec, setDefaultCommandRunner, } from './core/exec.js';
22
22
  export { type GitSandboxPaths, gitSandboxPaths, withoutGitDirs, } from './core/git-sandbox.js';
23
- export { refreshRunTarget, runCloneTip, transferIsolatedCommit, } from './core/isolated-git.js';
23
+ export { changedProtectedPaths, refreshRunTarget, runCloneTip, transferIsolatedCommit, } from './core/isolated-git.js';
24
24
  export { type ConductorLiveness, type ConductorLivenessInput, deriveConductorLiveness, toUnixSeconds, } from './core/liveness.js';
25
25
  export { type ConductorLogger, createLogger } from './core/logger.js';
26
26
  export { defaultProcProbe, defaultRunProcessProbe, killRunProcesses, type ProcProbe, type RunProcessProbe, type SignalFailureReason, type SignalOutcome, type SignalVerifiedInput, signalVerifiedProcess, type VerifyOutcome, type VerifyProcessInput, verifyConductorProcess, } from './core/proc.js';
@@ -28,6 +28,7 @@ export { protectedProjectPaths } from './core/protected-project-paths.js';
28
28
  export { normalizeRepoUrl } from './core/repo-url.js';
29
29
  export { createRunClone, loadRunClone, type RunClone, type RunCloneOptions, registerRunCloneWorktree, removeRunClone, runCloneGitDir, saveRunClone, } from './core/run-clone.js';
30
30
  export { cliRootOf } from './core/runtime-paths.js';
31
+ export { loadSecretsFile, parseSecretsFile, pickSecrets, type Secrets, secretsFilePath, } from './core/secrets-file.js';
31
32
  export { shellQuote } from './core/shell.js';
32
33
  export { DEFAULT_SLUG_MAX_LENGTH, slugify } from './core/slug.js';
33
34
  export { bumpUiRefresh, UI_REFRESH_FILE } from './core/ui-refresh.js';
package/dist/src/index.js CHANGED
@@ -21,7 +21,7 @@ export { discoverBbWorkspaces, loadReadyBbConnection, resolveWorkspaceSelector,
21
21
  export { configHomeOf, defaultRootGitExec, deriveCheckoutRoot, } from './core/checkout-root.js';
22
22
  export { CommandRunner, ExecError, exec, setDefaultCommandRunner, } from './core/exec.js';
23
23
  export { gitSandboxPaths, withoutGitDirs, } from './core/git-sandbox.js';
24
- export { refreshRunTarget, runCloneTip, transferIsolatedCommit, } from './core/isolated-git.js';
24
+ export { changedProtectedPaths, refreshRunTarget, runCloneTip, transferIsolatedCommit, } from './core/isolated-git.js';
25
25
  export { deriveConductorLiveness, toUnixSeconds, } from './core/liveness.js';
26
26
  export { createLogger } from './core/logger.js';
27
27
  export { defaultProcProbe, defaultRunProcessProbe, killRunProcesses, signalVerifiedProcess, verifyConductorProcess, } from './core/proc.js';
@@ -29,6 +29,7 @@ export { protectedProjectPaths } from './core/protected-project-paths.js';
29
29
  export { normalizeRepoUrl } from './core/repo-url.js';
30
30
  export { createRunClone, loadRunClone, registerRunCloneWorktree, removeRunClone, runCloneGitDir, saveRunClone, } from './core/run-clone.js';
31
31
  export { cliRootOf } from './core/runtime-paths.js';
32
+ export { loadSecretsFile, parseSecretsFile, pickSecrets, secretsFilePath, } from './core/secrets-file.js';
32
33
  export { shellQuote } from './core/shell.js';
33
34
  export { DEFAULT_SLUG_MAX_LENGTH, slugify } from './core/slug.js';
34
35
  export { bumpUiRefresh, UI_REFRESH_FILE } from './core/ui-refresh.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/core",
3
- "version": "0.10.1-next.8",
3
+ "version": "0.11.0",
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",
@@ -40,7 +40,7 @@
40
40
  "yaml": "^2.7.0"
41
41
  },
42
42
  "bakersBuild": {
43
- "commit": "6d6a551127b476e4a073f4d842b7fdb10ef6ccb1",
44
- "channel": "next"
43
+ "commit": "4e1d1a59439a6a0019f3b5b213d9cc9f09d14381",
44
+ "channel": "latest"
45
45
  }
46
46
  }
@@ -164,6 +164,7 @@
164
164
  },
165
165
  "plugins": {
166
166
  "type": "array",
167
+ "description": "Plugins to install from this marketplace, at least one.",
167
168
  "minItems": 1,
168
169
  "items": {
169
170
  "$ref": "#/$defs/nonempty"