@hcflabs/pi-herdr-tools 1.7.0 → 1.7.1

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/README.md CHANGED
@@ -114,7 +114,9 @@ Status clears on answer, cancellation, failure, `/reload`, session switch, or ex
114
114
 
115
115
  ![Worktree removal and primary-checkout update.](./docs/done-flow.svg)
116
116
 
117
- `/done` requires `HERDR_ENV=1`, `HERDR_WORKSPACE_ID`, and `HERDR_TAB_ID`. Commit or discard changes, then confirm removal; declining changes nothing. Normal and forced completion wait for idle Pi.
117
+ `/done` requires `HERDR_ENV=1`, `HERDR_PANE_ID`, and `HERDR_TAB_ID`. Commit or discard changes, then confirm removal; declining changes nothing. Normal and forced completion wait for idle Pi.
118
+
119
+ `/done` gets the checkout from the Herdr workspace of the current pane, not from the Pi working directory. Pi can run in a subdirectory of the checkout. `/done` refuses a workspace that is not a linked Git worktree, and it then changes nothing.
118
120
 
119
121
  Normal removal rejects dirty worktrees and checkout use by other workspaces. Close listed tabs and retry; labels identify them, or IDs without labels. Primary-checkout tabs do not block removal or updates.
120
122
 
package/internal/done.ts CHANGED
@@ -1,6 +1,8 @@
1
+ import { realpath } from "node:fs/promises";
1
2
  import { tmpdir } from "node:os";
2
3
  import type { ExecResult, ExtensionAPI } from "@earendil-works/pi-coding-agent";
3
4
  import { createHerdrClient, withWorktreeLock } from "@hcflabs/pi-herdr";
5
+ import { resolveWorkspace } from "./worktree.ts";
4
6
 
5
7
  type SnapshotPane = { tab_id?: unknown; cwd?: unknown };
6
8
  type TabEntry = { tab_id?: unknown; workspace_id?: unknown; label?: unknown };
@@ -27,8 +29,8 @@ export default function herdrDoneExtension(pi: ExtensionAPI): void {
27
29
  }
28
30
  const tabId = process.env.HERDR_TAB_ID?.trim();
29
31
  if (!tabId) throw new Error("HERDR_TAB_ID is missing.");
30
- const workspaceId = process.env.HERDR_WORKSPACE_ID?.trim();
31
- if (!workspaceId) throw new Error("HERDR_WORKSPACE_ID is missing.");
32
+ const paneId = process.env.HERDR_PANE_ID?.trim();
33
+ if (!paneId) throw new Error("HERDR_PANE_ID is missing.");
32
34
 
33
35
  if (!force) {
34
36
  const confirmed = await ctx.ui.confirm("Done", "Close its Herdr tabs and remove the current worktree?");
@@ -36,7 +38,15 @@ export default function herdrDoneExtension(pi: ExtensionAPI): void {
36
38
  }
37
39
 
38
40
  await ctx.waitForIdle();
39
- const checkout = (await execOrThrow("git", ["rev-parse", "--show-toplevel"], ctx.cwd)).trim();
41
+ // The checkout comes from the Herdr workspace of this pane, not from the Pi working directory.
42
+ // Pi can run in a parent directory or a subdirectory of the checkout.
43
+ const workspace = await resolveWorkspace(herdr, ctx.cwd, paneId);
44
+ const workspaceId = workspace.workspaceId;
45
+ if (!workspace.isLinkedWorktree || !workspace.checkout) {
46
+ throw new Error(`/done: Herdr workspace ${workspaceId} is not a linked Git worktree. Nothing was removed.`);
47
+ }
48
+ // Herdr can report a path without symlink resolution. Git and pane paths use the real path.
49
+ const checkout = await realpath(workspace.checkout);
40
50
  // First record of the NUL-delimited list is always the main worktree;
41
51
  // -z keeps paths containing newlines parseable.
42
52
  const worktreeFields = (await execOrThrow("git", ["worktree", "list", "--porcelain", "-z"], checkout)).split("\0");
@@ -78,9 +88,10 @@ export default function herdrDoneExtension(pi: ExtensionAPI): void {
78
88
  throw new Error(`Worktree still used by Herdr tabs ${names.join(", ")}; close them first.`);
79
89
  }
80
90
 
91
+ // Run Git in the primary checkout of the same repository. Pi's cwd can be outside it.
81
92
  await execOrThrow("git", [
82
93
  "worktree", "remove", ...(force ? ["--force"] : []), checkout,
83
- ], ctx.cwd);
94
+ ], mainCheckout);
84
95
  return siblingTabIds;
85
96
  });
86
97
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hcflabs/pi-herdr-tools",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "Clone, hand off, name, and finish Pi conversations in Herdr, with mergeable side questions.",
5
5
  "keywords": ["pi-package", "pi", "herdr", "session", "clone", "side-thread", "title"],
6
6
  "type": "module",