@henryqw/pi-herdr-done 0.5.0 → 0.5.2
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 +5 -0
- package/extensions/done.ts +4 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Pi extension that closes and removes the current Herdr-managed linked worktree. Requires Pi Coding Agent 0.84.x (minimum 0.84.2) running inside Herdr.
|
|
4
4
|
|
|
5
|
+
## Why
|
|
6
|
+
|
|
7
|
+
- **Created for**: Automating safe cleanup after finishing worktree-based tasks instead of manually removing checkouts, closing tabs, and pulling parents.
|
|
8
|
+
- **Advantage**: `/done` removes the checkout, closes workspace tabs, fast-forwards the parent with `--ff-only`, and refuses unsafe cases unless forced.
|
|
9
|
+
|
|
5
10
|
## Install
|
|
6
11
|
|
|
7
12
|
```bash
|
package/extensions/done.ts
CHANGED
|
@@ -64,15 +64,13 @@ export default function herdrDoneExtension(pi: ExtensionAPI): void {
|
|
|
64
64
|
const listing = await herdr.json(["tab", "list"], { cwd: ctx.cwd });
|
|
65
65
|
const tabs = (listing.result as { tabs?: TabEntry[] } | undefined)?.tabs;
|
|
66
66
|
if (!Array.isArray(tabs)) throw new Error("herdr tab list returned no tabs.");
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
.map((tab) => [tab.tab_id, tab]));
|
|
67
|
+
const validTabs = tabs.filter((tab): tab is TabEntry & { tab_id: string } => typeof tab.tab_id === "string");
|
|
68
|
+
const tabsById = new Map(validTabs.map((tab) => [tab.tab_id, tab]));
|
|
70
69
|
if (tabsById.get(tabId)?.workspace_id !== workspaceId) {
|
|
71
70
|
throw new Error(`Herdr tab ${tabId} does not belong to workspace ${workspaceId}.`);
|
|
72
71
|
}
|
|
73
|
-
siblingTabIds =
|
|
74
|
-
.filter((tab)
|
|
75
|
-
typeof tab.tab_id === "string" && tab.tab_id !== tabId && tab.workspace_id === workspaceId)
|
|
72
|
+
siblingTabIds = validTabs
|
|
73
|
+
.filter((tab) => tab.tab_id !== tabId && tab.workspace_id === workspaceId)
|
|
76
74
|
.map((tab) => tab.tab_id);
|
|
77
75
|
const blockers = dependentIds.filter((id) => tabsById.get(id)?.workspace_id !== workspaceId);
|
|
78
76
|
if (blockers.length > 0) {
|