@bakers-build/addon-herdr 0.10.0 → 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.
package/dist/src/index.js CHANGED
@@ -6,7 +6,8 @@ import { applyOpenLayout, DEFAULT_OPEN_LAYOUT, isEmptyLayout, parseFirstPane, pa
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 { cloneWorkspaceId, listWorktrees, openCloneWorkspace, resolveWorktreeEntry, } from './worktrees.js';
9
+ import { parseWorkspaceList } from './workspace-list.js';
10
+ import { listWorktrees, openCloneWorkspace, resolveWorktreeEntry, } from './worktrees.js';
10
11
  export { DEFAULT_OPEN_LAYOUT } from './open-layout.js';
11
12
  export { envArgs } from './panes.js';
12
13
  // BB-139: the herdr workspace lives in the same package now (the separate
@@ -149,10 +150,10 @@ export class HerdrExecutor {
149
150
  let root = null;
150
151
  try {
151
152
  const entry = resolveWorktreeEntry(await this.listWorktrees(), ctx.branch, path);
152
- // A run clone is no herdr worktree: its plain workspace is opened by label.
153
+ // A run clone is a worktree only the host registered: open it by path.
153
154
  const open = entry?.open_workspace_id ??
154
155
  (loadRunClone(path)
155
- ? await openCloneWorkspace(this.execHerdr, ctx.branch, path)
156
+ ? await openCloneWorkspace(this.execHerdr, this.options.root, ctx.branch, path)
156
157
  : undefined);
157
158
  if (open) {
158
159
  root = parseFirstPane(await this.execHerdr(['pane', 'list', '--workspace', open]));
@@ -188,9 +189,9 @@ export class HerdrExecutor {
188
189
  // branch is mutable (a coding agent may switch/rename it) and herdr
189
190
  // reports `null` for a detached HEAD, so a branch match is unreliable.
190
191
  let workspaceId = await this.findOpenWorkspace(branchName, workspacePath);
191
- // A run clone is no herdr worktree: its plain workspace is opened by label.
192
+ // A run clone is a worktree only the host registered: open it by path.
192
193
  if (!workspaceId && loadRunClone(workspacePath))
193
- workspaceId = await openCloneWorkspace(this.execHerdr, branchName, workspacePath);
194
+ workspaceId = await openCloneWorkspace(this.execHerdr, this.options.root, branchName, workspacePath);
194
195
  // 2. Open workspace if not already open. Reattach from the PARENT repo
195
196
  // root, never the linked worktree path: herdr rejects an open whose
196
197
  // --cwd is a linked worktree with `linked_worktree_source` ("New and
@@ -316,11 +317,12 @@ export class HerdrExecutor {
316
317
  * The branch worktree is untouched (that is `HerdrWorkspace.remove`).
317
318
  */
318
319
  async cleanupRun(branch, runId) {
319
- // A branch without a herdr worktree may be a run clone, found by its label.
320
+ // A branch without a herdr worktree may be an older run clone's plain
321
+ // workspace, found by its label.
320
322
  const entry = await this.findWorktreeByBranch(branch);
321
323
  const workspaceId = entry
322
324
  ? (entry.open_workspace_id ?? null)
323
- : await cloneWorkspaceId(this.execHerdr, branch);
325
+ : (parseWorkspaceList(await this.execHerdr(['workspace', 'list'])).find((workspace) => workspace.label === branch)?.workspaceId ?? null);
324
326
  if (!workspaceId) {
325
327
  return;
326
328
  }
@@ -56,8 +56,8 @@ export declare class HerdrWorkspace implements BbWorkspace {
56
56
  ensure(_identifier: string, branch?: string, baseRefOverride?: string): Promise<EnsuredWorkspace>;
57
57
  /**
58
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.
59
+ * path, opened in herdr as a worktree of the parent. The parent keeps the
60
+ * ticket branch; the host's `.git` there is only the stub that links to it.
61
61
  */
62
62
  private ensureClone;
63
63
  /**
@@ -160,8 +160,8 @@ export class HerdrWorkspace {
160
160
  }
161
161
  /**
162
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.
163
+ * path, opened in herdr as a worktree of the parent. The parent keeps the
164
+ * ticket branch; the host's `.git` there is only the stub that links to it.
165
165
  */
166
166
  async ensureClone(branch, baseRefOverride) {
167
167
  const path = resolve(this.root, this.worktreeDir, branch);
@@ -201,7 +201,7 @@ export class HerdrWorkspace {
201
201
  ...(target ? { target } : {}),
202
202
  shared: this.options.shared ?? false,
203
203
  });
204
- await openCloneWorkspace(this.execHerdr, branch, path);
204
+ await openCloneWorkspace(this.execHerdr, this.root, branch, path);
205
205
  return { path, instructions: loadInstructions(path), created, clone };
206
206
  }
207
207
  /**
@@ -238,7 +238,8 @@ export function herdrWorkspace(opts = {}) {
238
238
  ...(opts.auto_setup_merge ? { autoSetupMerge: true } : {}),
239
239
  ...(deps?.logger ? { logger: deps.logger } : {}),
240
240
  clone: config.runtime?.isolates === true,
241
- ...(opts.shared ? { shared: true } : {}),
241
+ // A runtime's `shared` wins; the workspace option is the deprecated fallback.
242
+ shared: config.runtime?.shared ?? opts.shared ?? false,
242
243
  });
243
244
  },
244
245
  };
@@ -39,12 +39,17 @@ export declare function resolveWorktreeEntry(entries: WorktreeEntry[], branch: s
39
39
  */
40
40
  export declare function listWorktrees(execHerdr: HerdrExec, root: string | undefined): Promise<WorktreeEntry[]>;
41
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.
42
+ * The run clone's open herdr workspace: the worktree herdr opened at `path`,
43
+ * or a plain workspace labelled with the branch that a run opened before the
44
+ * host registered its clone as a worktree.
44
45
  */
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>;
46
+ export declare function cloneWorkspaceId(execHerdr: HerdrExec, root: string | undefined, branch: string, path: string): Promise<string | null>;
47
+ /**
48
+ * The run clone's herdr workspace, opened as a worktree of `root` when none is
49
+ * open, so herdr groups it under the repository. Registers the clone as a
50
+ * worktree first, whichever addon made it: every refresh empties its stub.
51
+ */
52
+ export declare function openCloneWorkspace(execHerdr: HerdrExec, root: string | undefined, branch: string, path: string): Promise<string>;
48
53
  /** What the herdr worktree teardown needs. */
49
54
  export interface HerdrTeardownDeps {
50
55
  /** The parent repo root; absent only for rootless test callers. */
@@ -1,6 +1,6 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { removeGitWorktree, removeRunCloneWorkspace, restoreWritable, } from '@bakers-build/addon-workspace-git';
3
- import { loadRunClone } from '@bakers-build/core';
3
+ import { loadRunClone, registerRunCloneWorktree, } from '@bakers-build/core';
4
4
  import { isRecord, parseJson } from './pane-layout.js';
5
5
  import { parseWorkspaceList } from './workspace-list.js';
6
6
  export function parseWorktreeList(output) {
@@ -77,29 +77,43 @@ export async function listWorktrees(execHerdr, root) {
77
77
  return parseWorktreeList(output);
78
78
  }
79
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.
80
+ * The run clone's open herdr workspace: the worktree herdr opened at `path`,
81
+ * or a plain workspace labelled with the branch that a run opened before the
82
+ * host registered its clone as a worktree.
82
83
  */
83
- export async function cloneWorkspaceId(execHerdr, branch) {
84
- return (parseWorkspaceList(await execHerdr(['workspace', 'list'])).find((workspace) => workspace.label === branch)?.workspaceId ?? null);
84
+ export async function cloneWorkspaceId(execHerdr, root, branch, path) {
85
+ const entry = (await listWorktrees(execHerdr, root)).find((worktree) => normPath(worktree.path) === normPath(path));
86
+ return (entry?.open_workspace_id ??
87
+ parseWorkspaceList(await execHerdr(['workspace', 'list'])).find((workspace) => workspace.label === branch)?.workspaceId ??
88
+ null);
85
89
  }
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);
90
+ /**
91
+ * The run clone's herdr workspace, opened as a worktree of `root` when none is
92
+ * open, so herdr groups it under the repository. Registers the clone as a
93
+ * worktree first, whichever addon made it: every refresh empties its stub.
94
+ */
95
+ export async function openCloneWorkspace(execHerdr, root, branch, path) {
96
+ const clone = loadRunClone(path);
97
+ if (clone)
98
+ registerRunCloneWorktree(clone);
99
+ const open = await cloneWorkspaceId(execHerdr, root, branch, path);
89
100
  if (open)
90
101
  return open;
91
102
  const output = await execHerdr([
92
- 'workspace',
93
- 'create',
103
+ 'worktree',
104
+ 'open',
94
105
  '--cwd',
106
+ root ?? path,
107
+ '--path',
95
108
  path,
96
109
  '--label',
97
110
  branch,
98
111
  '--no-focus',
112
+ '--json',
99
113
  ]);
100
114
  let created;
101
115
  try {
102
- const parsed = parseJson(output, 'workspace create');
116
+ const parsed = parseJson(output, 'worktree open');
103
117
  created = isRecord(parsed)
104
118
  ? parsed.result?.workspace
105
119
  ?.workspace_id
@@ -110,9 +124,9 @@ export async function openCloneWorkspace(execHerdr, branch, path) {
110
124
  }
111
125
  const id = typeof created === 'string' && created
112
126
  ? created
113
- : await cloneWorkspaceId(execHerdr, branch);
127
+ : await cloneWorkspaceId(execHerdr, root, branch, path);
114
128
  if (!id)
115
- throw new Error(`herdr workspace create did not yield a workspace for ${path} (branch ${branch}): ${output.trim()}`);
129
+ throw new Error(`herdr worktree open did not yield a workspace for ${path} (branch ${branch}): ${output.trim()}`);
116
130
  return id;
117
131
  }
118
132
  /**
@@ -191,7 +205,7 @@ export async function removeHerdrWorktree(deps, branch, worktreePath) {
191
205
  return 'unverified';
192
206
  }
193
207
  if (worktreePath && loadRunClone(worktreePath)) {
194
- const open = await cloneWorkspaceId(execHerdr, branch);
208
+ const open = await cloneWorkspaceId(execHerdr, root, branch, worktreePath);
195
209
  if (open) {
196
210
  if (!(await ensureFocusSafeToRemove(deps, open)))
197
211
  return 'unverified';
@@ -98,7 +98,8 @@
98
98
  "shared": {
99
99
  "type": "boolean",
100
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."
101
+ "description": "Deprecated: set shared on the isolating runtime (runtime-bwrap, runtime-docker) instead; a value set there wins. Run clones borrow the parent repository's objects (git clone --shared) instead of copying them.",
102
+ "deprecated": true
102
103
  }
103
104
  },
104
105
  "additionalProperties": false,
@@ -107,10 +108,7 @@
107
108
  "type": "object",
108
109
  "properties": {
109
110
  "direction": {
110
- "enum": [
111
- "right",
112
- "down"
113
- ],
111
+ "enum": ["right", "down"],
114
112
  "description": "Where the split opens."
115
113
  },
116
114
  "command": {
@@ -122,10 +120,7 @@
122
120
  "description": "Focus this split after opening."
123
121
  }
124
122
  },
125
- "required": [
126
- "direction",
127
- "command"
128
- ],
123
+ "required": ["direction", "command"],
129
124
  "additionalProperties": false,
130
125
  "description": "One extra split; not the agent command."
131
126
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-herdr",
3
- "version": "0.10.0",
3
+ "version": "0.10.1-next.10",
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.10.0"
26
+ "@bakers-build/addon-workspace-git": "^0.10.1-next.10"
27
27
  },
28
28
  "peerDependencies": {
29
- "@bakers-build/conductor": "^0.10.0",
30
- "@bakers-build/core": "^0.10.0"
29
+ "@bakers-build/conductor": "^0.10.1-next.10",
30
+ "@bakers-build/core": "^0.10.1-next.10"
31
31
  },
32
32
  "bakersBuild": {
33
- "commit": "5857b00008bc0926fd52fdc8d9366d6d52444e35",
34
- "channel": "latest"
33
+ "commit": "d0f650fbe4c44eda2a26be62d28d30c22c56c386",
34
+ "channel": "next"
35
35
  }
36
36
  }