@bakers-build/addon-herdr 0.9.1-next.4 → 0.9.1-next.6

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.
package/dist/src/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { rmSync } from 'node:fs';
2
- import { exec, shellQuote, slugify } from '@bakers-build/core';
2
+ import { exec, loadRunClone, shellQuote, slugify } from '@bakers-build/core';
3
3
  import { renderTemplate, resolveStateConfig, } from './config.js';
4
4
  import { watchLaunch, writeLaunchScript, } from './launch-script.js';
5
5
  import { applyOpenLayout, DEFAULT_OPEN_LAYOUT, isEmptyLayout, parseFirstPane, parseRootPane, } from './open-layout.js';
6
6
  import { applyPaneLayout, isRecord, parseJson, } from './pane-layout.js';
7
7
  import { AGENT_SHELL_ENV, envArgs } from './panes.js';
8
8
  import { deriveHerdrRoot } from './root-anchor.js';
9
- import { listWorktrees, resolveWorktreeEntry, } from './worktrees.js';
9
+ import { cloneWorkspaceId, listWorktrees, openCloneWorkspace, resolveWorktreeEntry, } from './worktrees.js';
10
10
  export { DEFAULT_OPEN_LAYOUT } from './open-layout.js';
11
11
  export { envArgs } from './panes.js';
12
12
  // BB-139: the herdr workspace lives in the same package now (the separate
@@ -149,13 +149,13 @@ export class HerdrExecutor {
149
149
  let root = null;
150
150
  try {
151
151
  const entry = resolveWorktreeEntry(await this.listWorktrees(), ctx.branch, path);
152
- if (entry?.open_workspace_id) {
153
- root = parseFirstPane(await this.execHerdr([
154
- 'pane',
155
- 'list',
156
- '--workspace',
157
- entry.open_workspace_id,
158
- ]));
152
+ // A run clone is no herdr worktree: its plain workspace is opened by label.
153
+ const open = entry?.open_workspace_id ??
154
+ (loadRunClone(path)
155
+ ? await openCloneWorkspace(this.execHerdr, ctx.branch, path)
156
+ : undefined);
157
+ if (open) {
158
+ root = parseFirstPane(await this.execHerdr(['pane', 'list', '--workspace', open]));
159
159
  }
160
160
  else {
161
161
  root = parseRootPane(await this.execHerdr([
@@ -188,6 +188,9 @@ export class HerdrExecutor {
188
188
  // branch is mutable (a coding agent may switch/rename it) and herdr
189
189
  // reports `null` for a detached HEAD, so a branch match is unreliable.
190
190
  let workspaceId = await this.findOpenWorkspace(branchName, workspacePath);
191
+ // A run clone is no herdr worktree: its plain workspace is opened by label.
192
+ if (!workspaceId && loadRunClone(workspacePath))
193
+ workspaceId = await openCloneWorkspace(this.execHerdr, branchName, workspacePath);
191
194
  // 2. Open workspace if not already open. Reattach from the PARENT repo
192
195
  // root, never the linked worktree path: herdr rejects an open whose
193
196
  // --cwd is a linked worktree with `linked_worktree_source` ("New and
@@ -313,7 +316,11 @@ export class HerdrExecutor {
313
316
  * The branch worktree is untouched (that is `HerdrWorkspace.remove`).
314
317
  */
315
318
  async cleanupRun(branch, runId) {
316
- const workspaceId = await this.findWorkspaceByBranch(branch);
319
+ // A branch without a herdr worktree may be a run clone, found by its label.
320
+ const entry = await this.findWorktreeByBranch(branch);
321
+ const workspaceId = entry
322
+ ? (entry.open_workspace_id ?? null)
323
+ : await cloneWorkspaceId(this.execHerdr, branch);
317
324
  if (!workspaceId) {
318
325
  return;
319
326
  }
@@ -28,6 +28,10 @@ export interface HerdrWorkspaceOptions {
28
28
  * in `root`, and give runs `push.default=current`. `true` leaves Git alone.
29
29
  */
30
30
  autoSetupMerge?: boolean;
31
+ /** The runtime isolates: a fresh run clone per ensure instead of a herdr worktree. */
32
+ clone?: boolean;
33
+ /** Run clones borrow the root's objects (`git clone --shared`). */
34
+ shared?: boolean;
31
35
  }
32
36
  export declare class HerdrWorkspace implements BbWorkspace {
33
37
  private readonly options;
@@ -50,6 +54,12 @@ export declare class HerdrWorkspace implements BbWorkspace {
50
54
  * remains the reason the contract carries it at all.
51
55
  */
52
56
  ensure(_identifier: string, branch?: string, baseRefOverride?: string): Promise<EnsuredWorkspace>;
57
+ /**
58
+ * The isolating-runtime variant: a fresh run clone at the worktree's stable
59
+ * path, shown in a plain herdr workspace. The parent keeps the ticket
60
+ * branch; no linked worktree and no `.git` exist on the host.
61
+ */
62
+ private ensureClone;
53
63
  /**
54
64
  * Tear down the branch's worktree and its herdr workspace
55
65
  * (`herdr worktree remove --force`); a worktree herdr no longer tracks is
@@ -66,6 +76,8 @@ export declare function herdrWorkspace(opts?: {
66
76
  worktree_dir?: string;
67
77
  base_branch?: string;
68
78
  auto_setup_merge?: boolean;
79
+ /** Isolating runtimes: run clones borrow the root's objects. */
80
+ shared?: boolean;
69
81
  /** Overrideable git exec for root derivation (tests). */
70
82
  execGit?: RootGitExec;
71
83
  /** Overrideable herdr exec (tests) — sibling of `execGit`. */
@@ -1,10 +1,11 @@
1
+ import { existsSync } from 'node:fs';
1
2
  import { resolve } from 'node:path';
2
- import { loadInstructions, runBranchGit, } from '@bakers-build/addon-workspace-git';
3
+ import { ensureRunClone, loadInstructions, runBranchGit, targetOf, } from '@bakers-build/addon-workspace-git';
3
4
  import { exec } from '@bakers-build/core';
4
5
  import { isRecord, parseJson } from './pane-layout.js';
5
6
  import { deriveHerdrRoot } from './root-anchor.js';
6
7
  import { resolveBaseRef } from './shared.js';
7
- import { removeHerdrWorktree } from './worktrees.js';
8
+ import { openCloneWorkspace, removeHerdrWorktree } from './worktrees.js';
8
9
  const defaultExec = (args) => exec('herdr', args);
9
10
  const defaultGitExec = (args) => exec('git', args);
10
11
  const defaultRunGit = (args, cwd) => exec('git', args, { cwd });
@@ -81,6 +82,12 @@ export class HerdrWorkspace {
81
82
  const extra = this.options.autoSetupMerge
82
83
  ? {}
83
84
  : { env: await runBranchGit(this.root, this.logger) };
85
+ if (this.options.clone) {
86
+ return {
87
+ ...(await this.ensureClone(branch, baseRefOverride)),
88
+ ...extra,
89
+ };
90
+ }
84
91
  const worktrees = parseWorktreeList(await this.execHerdr(['worktree', 'list', '--cwd', this.root, '--json']));
85
92
  const existing = worktrees.find((w) => w.branch === branch);
86
93
  if (existing) {
@@ -151,6 +158,52 @@ export class HerdrWorkspace {
151
158
  ...extra,
152
159
  };
153
160
  }
161
+ /**
162
+ * The isolating-runtime variant: a fresh run clone at the worktree's stable
163
+ * path, shown in a plain herdr workspace. The parent keeps the ticket
164
+ * branch; no linked worktree and no `.git` exist on the host.
165
+ */
166
+ async ensureClone(branch, baseRefOverride) {
167
+ const path = resolve(this.root, this.worktreeDir, branch);
168
+ const created = !existsSync(path);
169
+ // Fetches the base, so the clone carries the current target.
170
+ const baseRef = await resolveBaseRef(this.root, this.execGit, {
171
+ ...(this.options.baseBranch
172
+ ? { baseBranch: this.options.baseBranch }
173
+ : {}),
174
+ ...(baseRefOverride !== undefined ? { override: baseRefOverride } : {}),
175
+ });
176
+ try {
177
+ await this.execGit([
178
+ '-C',
179
+ this.root,
180
+ 'rev-parse',
181
+ '--verify',
182
+ '--quiet',
183
+ `refs/heads/${branch}`,
184
+ ]);
185
+ }
186
+ catch {
187
+ await this.execGit([
188
+ '-C',
189
+ this.root,
190
+ 'branch',
191
+ '--no-track',
192
+ branch,
193
+ ...(baseRef !== undefined ? [baseRef] : []),
194
+ ]);
195
+ }
196
+ const target = targetOf(baseRefOverride ?? baseRef);
197
+ const clone = ensureRunClone({
198
+ parent: this.root,
199
+ workspace: path,
200
+ branch,
201
+ ...(target ? { target } : {}),
202
+ shared: this.options.shared ?? false,
203
+ });
204
+ await openCloneWorkspace(this.execHerdr, branch, path);
205
+ return { path, instructions: loadInstructions(path), created, clone };
206
+ }
154
207
  /**
155
208
  * Tear down the branch's worktree and its herdr workspace
156
209
  * (`herdr worktree remove --force`); a worktree herdr no longer tracks is
@@ -184,6 +237,8 @@ export function herdrWorkspace(opts = {}) {
184
237
  ...(opts.execHerdr ? { execHerdr: opts.execHerdr } : {}),
185
238
  ...(opts.auto_setup_merge ? { autoSetupMerge: true } : {}),
186
239
  ...(deps?.logger ? { logger: deps.logger } : {}),
240
+ clone: config.runtime?.isolates === true,
241
+ ...(opts.shared ? { shared: true } : {}),
187
242
  });
188
243
  },
189
244
  };
@@ -1,6 +1,6 @@
1
1
  import { type WorktreeGitExec } from '@bakers-build/addon-workspace-git';
2
2
  import type { WorktreeTeardown } from '@bakers-build/conductor/contract';
3
- import type { ConductorLogger } from '@bakers-build/core';
3
+ import { type ConductorLogger } from '@bakers-build/core';
4
4
  import { type HerdrExec } from './pane-layout.js';
5
5
  export interface WorktreeEntry {
6
6
  /** herdr's reported git branch — null when the worktree HEAD is detached. */
@@ -38,6 +38,13 @@ export declare function resolveWorktreeEntry(entries: WorktreeEntry[], branch: s
38
38
  * message, so a future context failure is diagnosable.
39
39
  */
40
40
  export declare function listWorktrees(execHerdr: HerdrExec, root: string | undefined): Promise<WorktreeEntry[]>;
41
+ /**
42
+ * A run clone is no Git worktree on the host, so herdr lists none for it: its
43
+ * plain workspace is found by its label, the ticket branch.
44
+ */
45
+ export declare function cloneWorkspaceId(execHerdr: HerdrExec, branch: string): Promise<string | null>;
46
+ /** The run clone's herdr workspace, created at `path` when none is open. */
47
+ export declare function openCloneWorkspace(execHerdr: HerdrExec, branch: string, path: string): Promise<string>;
41
48
  /** What the herdr worktree teardown needs. */
42
49
  export interface HerdrTeardownDeps {
43
50
  /** The parent repo root; absent only for rootless test callers. */
@@ -1,5 +1,6 @@
1
1
  import { existsSync } from 'node:fs';
2
- import { removeGitWorktree, restoreWritable, } from '@bakers-build/addon-workspace-git';
2
+ import { removeGitWorktree, removeRunCloneWorkspace, restoreWritable, } from '@bakers-build/addon-workspace-git';
3
+ import { loadRunClone } from '@bakers-build/core';
3
4
  import { isRecord, parseJson } from './pane-layout.js';
4
5
  import { parseWorkspaceList } from './workspace-list.js';
5
6
  export function parseWorktreeList(output) {
@@ -75,6 +76,45 @@ export async function listWorktrees(execHerdr, root) {
75
76
  }
76
77
  return parseWorktreeList(output);
77
78
  }
79
+ /**
80
+ * A run clone is no Git worktree on the host, so herdr lists none for it: its
81
+ * plain workspace is found by its label, the ticket branch.
82
+ */
83
+ export async function cloneWorkspaceId(execHerdr, branch) {
84
+ return (parseWorkspaceList(await execHerdr(['workspace', 'list'])).find((workspace) => workspace.label === branch)?.workspaceId ?? null);
85
+ }
86
+ /** The run clone's herdr workspace, created at `path` when none is open. */
87
+ export async function openCloneWorkspace(execHerdr, branch, path) {
88
+ const open = await cloneWorkspaceId(execHerdr, branch);
89
+ if (open)
90
+ return open;
91
+ const output = await execHerdr([
92
+ 'workspace',
93
+ 'create',
94
+ '--cwd',
95
+ path,
96
+ '--label',
97
+ branch,
98
+ '--no-focus',
99
+ ]);
100
+ let created;
101
+ try {
102
+ const parsed = parseJson(output, 'workspace create');
103
+ created = isRecord(parsed)
104
+ ? parsed.result?.workspace
105
+ ?.workspace_id
106
+ : undefined;
107
+ }
108
+ catch {
109
+ // Not JSON: fall back to the list below.
110
+ }
111
+ const id = typeof created === 'string' && created
112
+ ? created
113
+ : await cloneWorkspaceId(execHerdr, branch);
114
+ if (!id)
115
+ throw new Error(`herdr workspace create did not yield a workspace for ${path} (branch ${branch}): ${output.trim()}`);
116
+ return id;
117
+ }
78
118
  /**
79
119
  * BB-166 focus guard. herdr's `worktree remove` deletes the ticket
80
120
  * worktree's on-disk directory; if that workspace is the CURRENTLY FOCUSED
@@ -150,6 +190,15 @@ export async function removeHerdrWorktree(deps, branch, worktreePath) {
150
190
  logger.warn({ branch, worktreePath, root }, 'refusing to tear down the main checkout');
151
191
  return 'unverified';
152
192
  }
193
+ if (worktreePath && loadRunClone(worktreePath)) {
194
+ const open = await cloneWorkspaceId(execHerdr, branch);
195
+ if (open) {
196
+ if (!(await ensureFocusSafeToRemove(deps, open)))
197
+ return 'unverified';
198
+ await execHerdr(['workspace', 'close', open]);
199
+ }
200
+ return removeRunCloneWorkspace(worktreePath) ?? 'unverified';
201
+ }
153
202
  const entry = resolveWorktreeEntry(await listWorktrees(execHerdr, root), branch, worktreePath);
154
203
  if (!entry) {
155
204
  // herdr no longer tracks it. herdr still tracking the worktree is itself
@@ -94,6 +94,11 @@
94
94
  "type": "boolean",
95
95
  "description": "`false` sets Git's `branch.autoSetupMerge=false` in the root repository, so run branches have no upstream and push with `push.default=current` (see workspace-git); `true` leaves Git alone.",
96
96
  "default": false
97
+ },
98
+ "shared": {
99
+ "type": "boolean",
100
+ "default": false,
101
+ "description": "Isolating runtimes only: run clones borrow the parent repository's objects (git clone --shared) instead of copying them. Faster and smaller, but never prune or repack the parent with -d while a run is open."
97
102
  }
98
103
  },
99
104
  "additionalProperties": false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-herdr",
3
- "version": "0.9.1-next.4",
3
+ "version": "0.9.1-next.6",
4
4
  "description": "bakers.build herdr integration: spawn executor + per-ticket worktree workspace.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -23,14 +23,14 @@
23
23
  "directory": "bakers-cli/addons/herdr"
24
24
  },
25
25
  "dependencies": {
26
- "@bakers-build/addon-workspace-git": "^0.9.1-next.4"
26
+ "@bakers-build/addon-workspace-git": "^0.9.1-next.6"
27
27
  },
28
28
  "peerDependencies": {
29
- "@bakers-build/conductor": "^0.9.1-next.4",
30
- "@bakers-build/core": "^0.9.1-next.4"
29
+ "@bakers-build/conductor": "^0.9.1-next.6",
30
+ "@bakers-build/core": "^0.9.1-next.6"
31
31
  },
32
32
  "bakersBuild": {
33
- "commit": "e5f8dc988628be67c3d92064cb3229e30ad2edde",
33
+ "commit": "e7d9921d51d5c045f29ca7e35d1e6a348e6ddf08",
34
34
  "channel": "next"
35
35
  }
36
36
  }