@bakers-build/core 0.10.1-next.1 → 0.10.1-next.10

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.
@@ -9,7 +9,13 @@ export declare const UPDATE_CHECK_TTL_MS: number;
9
9
  * the one place that decides where `.bakers` lives.
10
10
  */
11
11
  export declare function defaultUpdateCachePath(): string;
12
+ /** The version this process started with: the first read, cached. */
12
13
  export declare function resolveCliVersion(): string;
14
+ /**
15
+ * The `@bakers-build/core` version installed on disk now, read uncached, so a
16
+ * long-running process sees an upgrade that replaced its files.
17
+ */
18
+ export declare function readCliVersion(from?: string): string;
13
19
  export declare function fetchLatestVersion(fetchImpl?: typeof fetch, timeoutMs?: number): Promise<string | null>;
14
20
  export declare function updateNotice(current: string, latest: string): string | null;
15
21
  export interface UpdateCheckResult {
@@ -17,23 +17,27 @@ export function defaultUpdateCachePath() {
17
17
  return join(homeBbDir(), 'update-check.json');
18
18
  }
19
19
  let cachedCliVersion;
20
+ /** The version this process started with: the first read, cached. */
20
21
  export function resolveCliVersion() {
21
- if (cachedCliVersion)
22
- return cachedCliVersion;
23
- let dir = dirname(fileURLToPath(import.meta.url));
22
+ cachedCliVersion ??= readCliVersion();
23
+ return cachedCliVersion;
24
+ }
25
+ /**
26
+ * The `@bakers-build/core` version installed on disk now, read uncached, so a
27
+ * long-running process sees an upgrade that replaced its files.
28
+ */
29
+ export function readCliVersion(from = dirname(fileURLToPath(import.meta.url))) {
30
+ let dir = from;
24
31
  for (let i = 0; i < 7; i++) {
25
32
  try {
26
33
  const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'));
27
- if (pkg.name === '@bakers-build/core') {
28
- cachedCliVersion = pkg.version ?? UNKNOWN_VERSION;
29
- return cachedCliVersion;
30
- }
34
+ if (pkg.name === '@bakers-build/core')
35
+ return pkg.version ?? UNKNOWN_VERSION;
31
36
  }
32
37
  catch { }
33
38
  dir = dirname(dir);
34
39
  }
35
- cachedCliVersion = UNKNOWN_VERSION;
36
- return cachedCliVersion;
40
+ return UNKNOWN_VERSION;
37
41
  }
38
42
  export async function fetchLatestVersion(fetchImpl = globalThis.fetch, timeoutMs = 1500) {
39
43
  const controller = new AbortController();
@@ -1,4 +1,10 @@
1
1
  import type { RunClone } from './run-clone.js';
2
+ /**
3
+ * Set a registered run clone's host index to its branch tip, so host Git there
4
+ * shows no changes. Best effort: the index only feeds host status, and a host
5
+ * Git holding its lock must not fail a run start or a transfer.
6
+ */
7
+ export declare function refreshRunCloneIndex({ workspace }: RunClone): void;
2
8
  /** The run's ticket branch tip, read as plain files: Git never runs under the run's config. */
3
9
  export declare function runCloneTip(record: RunClone): string;
4
10
  /**
@@ -7,6 +7,23 @@ const git = (cwd, ...args) => execFileSync('git', args, {
7
7
  encoding: 'utf8',
8
8
  stdio: ['ignore', 'pipe', 'pipe'],
9
9
  }).trim();
10
+ /**
11
+ * Set a registered run clone's host index to its branch tip, so host Git there
12
+ * shows no changes. Best effort: the index only feeds host status, and a host
13
+ * Git holding its lock must not fail a run start or a transfer.
14
+ */
15
+ export function refreshRunCloneIndex({ workspace }) {
16
+ const stub = join(workspace, '.git');
17
+ // Only a registered stub links to the parent; a plain one has no HEAD commit.
18
+ if (!existsSync(join(stub, 'commondir')))
19
+ return;
20
+ try {
21
+ git(workspace, '--git-dir', stub, 'read-tree', 'HEAD');
22
+ }
23
+ catch {
24
+ // Stale index, see above.
25
+ }
26
+ }
10
27
  function normalizeProtectedPaths(paths) {
11
28
  return [
12
29
  ...new Set(['.bakers', ...paths].map((path) => {
@@ -241,6 +258,7 @@ export function transferIsolatedCommit(record, commit = runCloneTip(record)) {
241
258
  // Only scratch's clean config is read; the run's hooks/config never reach host Git.
242
259
  parent('-c', 'protocol.file.allow=always', 'fetch', '--no-tags', '--no-write-fetch-head', scratch, commit);
243
260
  parent('update-ref', `refs/heads/${record.branch}`, commit, record.expected);
261
+ refreshRunCloneIndex(record);
244
262
  return commit;
245
263
  }
246
264
  finally {
@@ -36,6 +36,13 @@ export declare function runCloneGitDir(workspace: string, env?: Env): string;
36
36
  export declare function saveRunClone(record: RunClone): void;
37
37
  /** The record of the workspace's current run clone; `undefined` for a linked worktree. */
38
38
  export declare function loadRunClone(workspace: string, env?: Env): RunClone | undefined;
39
+ /**
40
+ * Register the run clone as a linked worktree of the parent on the host, so
41
+ * herdr groups its workspace under the repository, with the branch tip as its
42
+ * index. The run never sees this: its own Git directory is mounted over the
43
+ * stub. Repeat after every {@link createRunClone}, which empties the stub.
44
+ */
45
+ export declare function registerRunCloneWorktree(record: RunClone): void;
39
46
  export declare function removeRunClone(workspace: string, env?: Env): void;
40
47
  /**
41
48
  * A fresh clone of the ticket branch for one isolated run. The previous run's
@@ -2,8 +2,8 @@ import { execFileSync } from 'node:child_process';
2
2
  import { createHash } from 'node:crypto';
3
3
  import { lstatSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync, } from 'node:fs';
4
4
  import { homedir } from 'node:os';
5
- import { dirname, join, resolve } from 'node:path';
6
- import { transferIsolatedCommit } from './isolated-git.js';
5
+ import { basename, dirname, join, resolve } from 'node:path';
6
+ import { refreshRunCloneIndex, transferIsolatedCommit, } from './isolated-git.js';
7
7
  import { UI_REFRESH_FILE } from './ui-refresh.js';
8
8
  /** Where a workspace's run Git directory lives: the conductor's cache, never the workspace. */
9
9
  export function runCloneGitDir(workspace, env = process.env) {
@@ -29,8 +29,71 @@ function loadRecord(gitDir) {
29
29
  return undefined;
30
30
  }
31
31
  }
32
+ /** The parent's worktree entry for a run clone; named after its Git directory, so it never clashes. */
33
+ const adminOf = ({ parentGitDir, gitDir }) => join(parentGitDir, 'worktrees', `run-${basename(gitDir, '.git')}`);
34
+ /**
35
+ * Register the run clone as a linked worktree of the parent on the host, so
36
+ * herdr groups its workspace under the repository, with the branch tip as its
37
+ * index. The run never sees this: its own Git directory is mounted over the
38
+ * stub. Repeat after every {@link createRunClone}, which empties the stub.
39
+ */
40
+ export function registerRunCloneWorktree(record) {
41
+ const admin = adminOf(record);
42
+ const stub = join(record.workspace, '.git');
43
+ mkdirSync(admin, { recursive: true });
44
+ writeFileSync(join(admin, 'HEAD'), `ref: refs/heads/${record.branch}\n`);
45
+ writeFileSync(join(admin, 'commondir'), '../..\n');
46
+ writeFileSync(join(admin, 'gitdir'), `${stub}\n`);
47
+ writeFileSync(join(stub, 'commondir'), `${record.parentGitDir}\n`);
48
+ writeFileSync(join(stub, 'gitdir'), `${stub}\n`);
49
+ // The run writes this work tree: a parent `core.hooksPath` relative to it
50
+ // (husky) must not make host Git there run the run's files.
51
+ const extension = [
52
+ '--git-dir',
53
+ record.parentGitDir,
54
+ 'config',
55
+ 'extensions.worktreeConfig',
56
+ ];
57
+ if (tryGit(extension) !== 'true')
58
+ git([...extension, 'true']);
59
+ const override = join(stub, 'config.worktree');
60
+ writeFileSync(override, '[core]\n\thooksPath = /dev/null\n\tfsmonitor = false\n');
61
+ // Likewise the parent's filter, diff and merge drivers: the run chooses
62
+ // their paths through `.gitattributes`, and a plain status or diff runs them.
63
+ const keys = tryGit([
64
+ '--git-dir',
65
+ record.parentGitDir,
66
+ 'config',
67
+ '--local',
68
+ '--includes',
69
+ '--name-only',
70
+ '--list',
71
+ '-z',
72
+ ]) ?? '';
73
+ for (const key of new Set(keys.split('\0'))) {
74
+ const value = driverOff(key);
75
+ if (value !== undefined)
76
+ git(['config', '--file', override, key, value]);
77
+ }
78
+ refreshRunCloneIndex(record);
79
+ }
80
+ /** The value that switches a command-valued driver key off; `undefined` for any other key. */
81
+ function driverOff(key) {
82
+ if (key === 'diff.external')
83
+ return '';
84
+ const [, section = '', name = ''] = /^(filter|diff|merge)\..+\.([^.]+)$/.exec(key) ?? [];
85
+ const off = {
86
+ filter: { clean: '', smudge: '', process: '', required: 'false' },
87
+ diff: { textconv: 'cat', command: '' },
88
+ merge: { driver: 'false' },
89
+ };
90
+ return off[section]?.[name];
91
+ }
32
92
  export function removeRunClone(workspace, env = process.env) {
33
93
  const gitDir = runCloneGitDir(workspace, env);
94
+ const record = loadRecord(gitDir);
95
+ if (record)
96
+ rmSync(adminOf(record), { recursive: true, force: true });
34
97
  rmSync(gitDir, { recursive: true, force: true });
35
98
  rmSync(recordOf(gitDir), { force: true });
36
99
  }
@@ -14,7 +14,7 @@ export { isValidMachineConnectionUrl } from './cli/machine-connection.js';
14
14
  export { type AgentRoutes, assertSchemaVersion, CONFIG_SCHEMA_VERSION, type MachineContext, 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
- 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';
17
+ export { BB_PACKAGE, checkForUpdate, declineUpdate, defaultUpdateCachePath, fetchLatestVersion, fetchUpdateNotice, printVersionLine, REGISTRY_LATEST_URL, readCliVersion, resolveCliVersion, UNKNOWN_VERSION, UPDATE_CHECK_TTL_MS, type UpdateCheckOptions, type UpdateCheckResult, updateNotice, } from './cli/version-check.js';
18
18
  export { discoverBbWorkspaces, loadReadyBbConnection, resolveWorkspaceSelector, type WorkspaceChoice, type WorkspaceRecoveryOptions, workspaceSearchCommand, } from './cli/workspace-recovery.js';
19
19
  export type { ConnectionConfig, MachineConfig, ProjectConfig, } from './config-types.generated.js';
20
20
  export { configHomeOf, defaultRootGitExec, deriveCheckoutRoot, type RootGitExec, } from './core/checkout-root.js';
@@ -26,7 +26,7 @@ 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';
27
27
  export { protectedProjectPaths } from './core/protected-project-paths.js';
28
28
  export { normalizeRepoUrl } from './core/repo-url.js';
29
- export { createRunClone, loadRunClone, type RunClone, type RunCloneOptions, removeRunClone, runCloneGitDir, saveRunClone, } from './core/run-clone.js';
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
31
  export { shellQuote } from './core/shell.js';
32
32
  export { DEFAULT_SLUG_MAX_LENGTH, slugify } from './core/slug.js';
package/dist/src/index.js CHANGED
@@ -16,7 +16,7 @@ export { isValidMachineConnectionUrl } from './cli/machine-connection.js';
16
16
  export { assertSchemaVersion, CONFIG_SCHEMA_VERSION, machineContextPath, readMachineContext, resolveMachineContextPath, } from './cli/machine-context.js';
17
17
  export { corePackageRoot } from './cli/paths.js';
18
18
  export { resolveModuleEslintStyle } from './cli/resolve-module.js';
19
- 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';
19
+ export { BB_PACKAGE, checkForUpdate, declineUpdate, defaultUpdateCachePath, fetchLatestVersion, fetchUpdateNotice, printVersionLine, REGISTRY_LATEST_URL, readCliVersion, resolveCliVersion, UNKNOWN_VERSION, UPDATE_CHECK_TTL_MS, updateNotice, } from './cli/version-check.js';
20
20
  export { discoverBbWorkspaces, loadReadyBbConnection, resolveWorkspaceSelector, workspaceSearchCommand, } from './cli/workspace-recovery.js';
21
21
  export { configHomeOf, defaultRootGitExec, deriveCheckoutRoot, } from './core/checkout-root.js';
22
22
  export { CommandRunner, ExecError, exec, setDefaultCommandRunner, } from './core/exec.js';
@@ -27,7 +27,7 @@ export { createLogger } from './core/logger.js';
27
27
  export { defaultProcProbe, defaultRunProcessProbe, killRunProcesses, signalVerifiedProcess, verifyConductorProcess, } from './core/proc.js';
28
28
  export { protectedProjectPaths } from './core/protected-project-paths.js';
29
29
  export { normalizeRepoUrl } from './core/repo-url.js';
30
- export { createRunClone, loadRunClone, removeRunClone, runCloneGitDir, saveRunClone, } from './core/run-clone.js';
30
+ export { createRunClone, loadRunClone, registerRunCloneWorktree, removeRunClone, runCloneGitDir, saveRunClone, } from './core/run-clone.js';
31
31
  export { cliRootOf } from './core/runtime-paths.js';
32
32
  export { shellQuote } from './core/shell.js';
33
33
  export { DEFAULT_SLUG_MAX_LENGTH, slugify } from './core/slug.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/core",
3
- "version": "0.10.1-next.1",
3
+ "version": "0.10.1-next.10",
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": "f9cee7721df536cac94906e7278d60a13e202502",
43
+ "commit": "d0f650fbe4c44eda2a26be62d28d30c22c56c386",
44
44
  "channel": "next"
45
45
  }
46
46
  }