pi-odd-worktree 0.0.0-stage → 1.0.0

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.
Files changed (60) hide show
  1. package/README.md +234 -2
  2. package/extensions/odd-worktree-tools.ts +7593 -0
  3. package/lib/checkout-facts.js +598 -0
  4. package/lib/clipboard.js +226 -0
  5. package/lib/gh-issues.js +1555 -0
  6. package/lib/issue-preview.js +273 -0
  7. package/lib/issues-view.js +2274 -0
  8. package/lib/odd-docs.js +505 -0
  9. package/lib/odd-markdown.js +413 -0
  10. package/lib/odd-view.js +990 -0
  11. package/lib/open-external.js +106 -0
  12. package/lib/preview-scroll-keys.js +192 -0
  13. package/lib/session-auto-name.js +292 -0
  14. package/lib/session-worktree-register.js +62 -0
  15. package/lib/tui-paint.js +273 -0
  16. package/lib/view-layout.js +368 -0
  17. package/lib/warp-create-panel.js +722 -0
  18. package/lib/warp-create-picker.js +906 -0
  19. package/lib/warp-delete-confirm.js +465 -0
  20. package/lib/warp-selector-view.js +1265 -0
  21. package/lib/worktree-card.js +1117 -0
  22. package/lib/worktree-changes.js +1395 -0
  23. package/lib/worktree-close-herdr.js +73 -0
  24. package/lib/worktree-git.js +1048 -0
  25. package/lib/worktree-hooks.js +738 -0
  26. package/lib/worktree-model-result.js +291 -0
  27. package/lib/worktree-registry.js +886 -0
  28. package/lib/worktree-session-guard.js +595 -0
  29. package/lib/worktree-symlinks.js +336 -0
  30. package/lib/worktree-warp-sessions.js +566 -0
  31. package/package.json +36 -4
  32. package/tools/commands.test.js +176 -0
  33. package/tools/fixtures/gh-api-user.json +1 -0
  34. package/tools/fixtures/gh-issue-list.json +1 -0
  35. package/tools/fixtures/gh-issue-view.json +1 -0
  36. package/tools/fixtures/gh-label-list.json +1 -0
  37. package/tools/fixtures/gh-repo-view.json +1 -0
  38. package/tools/fixtures/load-extension.js +66 -0
  39. package/tools/gh-issues-feedback.test.js +359 -0
  40. package/tools/gh-issues.test.js +1502 -0
  41. package/tools/issue-preview.test.js +216 -0
  42. package/tools/issues-command.test.js +1217 -0
  43. package/tools/issues-view.test.js +4401 -0
  44. package/tools/odd-docs.test.js +803 -0
  45. package/tools/odd-markdown.test.js +236 -0
  46. package/tools/odd-view.test.js +2328 -0
  47. package/tools/package-surface.test.js +138 -0
  48. package/tools/t5-session-identity.test.js +306 -0
  49. package/tools/warp-create-panel.test.js +185 -0
  50. package/tools/warp-create-picker.test.js +1357 -0
  51. package/tools/warp-delete-confirm.test.js +616 -0
  52. package/tools/warp-selector-view.test.js +1463 -0
  53. package/tools/worktree-changes.test.js +951 -0
  54. package/tools/worktree-close-herdr-async.test.js +204 -0
  55. package/tools/worktree-odd-migration.test.js +224 -0
  56. package/tools/worktree-registry-cache.test.js +163 -0
  57. package/tools/worktree-registry-odd.test.js +231 -0
  58. package/tools/worktree-registry.test.js +244 -0
  59. package/tools/worktree-session-guard.test.js +507 -0
  60. package/tools/worktree-tools.test.js +434 -0
package/README.md CHANGED
@@ -1,3 +1,235 @@
1
- # Temporary Holding Version
1
+ # pi-odd-worktree
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A Pi extension package for agent worktrees, ODD documents and GitHub issues.
4
+ Four agent tools, three panels, one extension entry point. It works in Pi
5
+ alone; Herdr is optional.
6
+
7
+ ## What It Does
8
+
9
+ `package.json` declares one Pi extension,
10
+ `./extensions/odd-worktree-tools.ts`, and that file registers everything below.
11
+
12
+ | Surface | Kind | What it does |
13
+ | --- | --- | --- |
14
+ | `worktree_list` | tool | Lists the principal checkout, then this session's own checkout, then the rest, cross-checked against live git checkouts. Rows whose path is gone are excluded and pruned from the registry. |
15
+ | `worktree_create` | tool | Creates a branch and its checkout from the **local** `main`, registers it, runs the creation hooks, and copies the pending changes you name. |
16
+ | `worktree_warp` | tool | Queues the session move to another checkout as a `/warp` handoff; the command performs the move when the turn ends. |
17
+ | `worktree_close` | tool | Removes a registered checkout with `git worktree remove`, keeping the branch, and refuses while a live Pi session is working in it. |
18
+ | `/warp` | panel | Moves this session to another checkout: no argument opens the selector (list, create, delete, extended list); `/warp <name>` jumps straight there. |
19
+ | `/odd-list` | panel | Two-pane reader of this checkout's `odd/tasks/*.md`: list on the left, styled markdown on the right. |
20
+ | `/issues` | panel | Full-screen reader of this checkout's repository issues — My issues / Assigned / Involved / All — with preview, comments, labels, assignees and close, gated on your repository role. |
21
+
22
+ A checkout's **name** is the slug of its branch, and its path is
23
+ `<repo-parent>/<repo-name>-worktrees/<slug>`: the slug lowercases the branch and
24
+ turns every non-alphanumeric run into `-` (`feat/login` → `feat-login`). The
25
+ principal checkout is `principal`. Names, paths and branches are accepted
26
+ interchangeably by `worktree_close`, and by `/warp`.
27
+
28
+ ## Quick Start
29
+
30
+ | Requirement | Why it is needed |
31
+ | --- | --- |
32
+ | Pi (`@earendil-works/pi-coding-agent`, `@earendil-works/pi-tui`) | Peer dependencies at `*`, supplied by the host. The package installs no runtime dependencies. |
33
+ | Node.js >= 18 and `git` | `engines` declares 18 as the floor, and every repository operation is a git child process. |
34
+ | `herdr` — optional | Not required: only `worktree_create` tries a Herdr workspace association, and it falls back to plain `git`. |
35
+ | `gh`, authenticated (`gh auth login`) | `/issues` only. Without it the command stays registered, says once per session what is missing, and never opens. |
36
+ | Gentle Shell — recommended | Supplies the presence and transport records the deletion guard reads to see sessions other than this one. |
37
+
38
+ ```bash
39
+ pi install npm:pi-odd-worktree
40
+ ```
41
+
42
+ Inside a Gentle Shell session, the same package is installed through the shell's
43
+ launcher:
44
+
45
+ ```bash
46
+ gentle-shell install npm:pi-odd-worktree
47
+ ```
48
+
49
+ From a local clone, `pi install .` installs the working copy instead. Neither
50
+ command takes a version, so the install tracks whatever npm publishes.
51
+
52
+ Herdr is not required; Gentle Shell is recommended for the live-session deletion
53
+ guard.
54
+
55
+ `pi.extensions` in `package.json` points at
56
+ `./extensions/odd-worktree-tools.ts`, so Pi loads it without any extra
57
+ registration. Expected result: `/warp`, `/odd-list` and `/issues` are available
58
+ as commands, and the four `worktree_*` tools are offered to the agent.
59
+
60
+ ## Core Workflow
61
+
62
+ 1. **Create** — ask the agent for a worktree, or press `c` in `/warp`.
63
+ `worktree_create` needs a `branch` and a mandatory `changes` selection:
64
+ `"all"`, `"none"`, or a list of checkout-relative paths. It never guesses,
65
+ and a repository with no local `main` is refused before anything is written.
66
+ An existing branch is adopted as-is instead of being recreated.
67
+ 2. **List** — `worktree_list`, or open `/warp`. Pass `all: true` to the tool (or
68
+ `v` in the panel) to also see live checkouts the registry does not know.
69
+ 3. **Move** — `/warp <name>`, the selector's `enter`, or `worktree_warp`. The
70
+ selector never offers the checkout you are already in; the exclusion is by
71
+ resolved real path, so a differently-spelled path to the same checkout is
72
+ excluded too.
73
+ 4. **Close** — `worktree_close` with exactly one of `name`, `path` or `branch`,
74
+ plus `force: true` for a dirty checkout. Closing asks for approval when the
75
+ host offers dialog UI; creating never does, because it touches no existing
76
+ data.
77
+
78
+ ## Key Features You Should Know About
79
+
80
+ ### Panel keys
81
+
82
+ `/warp` selector — the footer legend is the key reference.
83
+
84
+ | Key | Action |
85
+ | --- | --- |
86
+ | `↑`/`↓`, `j`/`k` | Move the selection |
87
+ | `enter` | Warp to the focused checkout (`enter` on the `view all worktrees` row opens the extended list) |
88
+ | `c` | Open the create flow |
89
+ | `ctrl+d` | Ask to delete the focused checkout; the extension owns the confirmation, the evidence and the removal |
90
+ | `v` | Open the extended list of every other checkout (`↑`/`↓`, `pgUp`/`pgDn`, `enter`, `T` or `/` to filter, `esc` back) |
91
+ | `r` | Reload the listing |
92
+ | `esc`, `ctrl+c` | Close the panel |
93
+
94
+ `/odd-list` — `↑`/`↓` select, `t` search (`T` and `/` also open the box), `o`
95
+ open the document in `$VISUAL`/`$EDITOR`, `s` toggles the order between `recent`
96
+ and `name`, `r` reload, `esc` close. `←`/`→` and `[`/`]` scroll the list; the
97
+ document pane pages with `ctrl+j`/`ctrl+k`.
98
+
99
+ `/issues` — bucket tabs are `My issues`, `Assigned`, `Involved` and `All`.
100
+
101
+ | Key | Action | Needs |
102
+ | --- | --- | --- |
103
+ | `↑`/`↓`, `j`/`k` | Move the selection | — |
104
+ | `←`/`→` (also `tab`/`shift+tab`) | Switch bucket | — |
105
+ | `]`/`[` | Scroll the list one page; the hint is deliberately absent from the footer | — |
106
+ | `ctrl+j`/`ctrl+k` | Scroll the preview a page (`ctrl+shift+j/k`, `shift+J/K` and `pgUp`/`pgDn` also work; `ctrl+d`/`ctrl+u` scroll half a page) | — |
107
+ | `t` | Open the search box (`T` and `/` also open it) | — |
108
+ | `o` | Open the issue in the browser through `gh issue view <n> --web -R` | — |
109
+ | `r` | Re-read the list and the preview freshly, and re-read your repository role | — |
110
+ | `l` | Labels editor: apply or remove an existing label | triage |
111
+ | `a` | Assignee editor | triage |
112
+ | `c` | Comment | read access |
113
+ | `x` (and `X`) | Close the issue, after the host's confirmation; only `x` rides the legend | triage |
114
+ | `esc`, `q`, `ctrl+c` | Close the reader | — |
115
+
116
+ Creating a **new** label is a separate capability inside the labels editor and
117
+ needs `write`, so a triage-only viewer opens the editor normally and sees
118
+ neither a create row nor its `n` keybinding. Commenting is deliberately ungated:
119
+ GitHub lets anyone with read access comment, so requiring triage would hide an
120
+ action the viewer is allowed to take. Anything but a confirmed capability fails
121
+ closed — no hint, the key refuses on screen, no editor opens, no mutation is
122
+ attempted.
123
+
124
+ ### The deletion guard, and its honest limit
125
+
126
+ Deleting a checkout is refused while a live Pi session is working in it, and
127
+ the **same** check runs for `worktree_close` and for the panel's `ctrl+d`, both
128
+ before the pending-change question and again immediately before the removal.
129
+ This session's own checkout is refused with "warp first"; another session's is
130
+ refused naming its real session id, resolved by joining the published presence
131
+ hash to Gentle Shell's transport activation record. When no record joins, the
132
+ refusal shows the presence hash and says the id could not be resolved — it never
133
+ invents one from a label. Nothing is auto-warped and nothing is closed on your
134
+ behalf.
135
+
136
+ That check is **best effort, not a guarantee**:
137
+
138
+ - It reads Gentle Shell's presence records (heartbeat plus workspace) and its
139
+ transport activation records when Gentle Shell is installed and running, and
140
+ it always catches the checkout this session stands on.
141
+ - A heartbeat older than 15 s cannot prove a session is gone, so it is reported
142
+ in the close output as a stale record instead of blocking the removal forever.
143
+ - Live records that published no workspace, and a scan that hit its bound, are
144
+ disclosed too. An absent or unreadable presence store blocks nothing and is
145
+ disclosed as unavailable.
146
+ - Gentle Shell's scratch ledger is deliberately not consulted: it records what a
147
+ session *created*, not where it is working.
148
+
149
+ Removal is `git worktree remove <absolute path>`, with `--force` only when the
150
+ caller asked for it. The branch is kept, and **no Herdr workspace is closed,
151
+ opened or removed** on any path.
152
+
153
+ ### `/issues` pins the repository
154
+
155
+ The repository identity (`<host>/<owner>/<repo>`) is pinned when the list loads,
156
+ and the host is part of it. Every page, detail, label, assignee and comment read
157
+ binds that pin, and so do every action and the `o` browser opener. If
158
+ the checkout's remote moves while the reader is open, mutations refuse with
159
+ `the checkout's repository changed since this issue list loaded (now … instead of
160
+ …); reopen /issues`, and the reads keep the displayed repository. An issue
161
+ number on screen can never be sent to another repository.
162
+
163
+ ### Where state lives
164
+
165
+ The worktree registry is per repository at `<git-common-dir>/pi-worktrees.json`,
166
+ so every worktree of the same clone sees the same rows. Session names derived
167
+ from an ODD write, and the warp's fork/resume bookkeeping, travel in the Pi
168
+ session files the host already owns. Nothing is written to user configuration.
169
+
170
+ ### Deliberately absent
171
+
172
+ This package is the worktree / ODD / issues surface only: no customize panel, no
173
+ plugin-tools toggles, no Herdr plugin management, and no worktree↔issue
174
+ association. There is nothing to configure, and the three commands are always on.
175
+ Paths, branches and arguments reach `git`, `herdr` and `gh` as fixed argv arrays,
176
+ never as a shell string.
177
+
178
+ ## Tests
179
+
180
+ ```bash
181
+ node --test tools/*.test.js # package.json `test`
182
+ ```
183
+
184
+ The suite uses Node builtins only — no install step, no lockfile, no network.
185
+ Every temporary repository, stub binary and extension copy lives under the
186
+ system temp directory and is removed on exit. `tools/fixtures/load-extension.js`
187
+ copies the extension to a scratch `.mjs` with the two Pi imports stubbed and
188
+ loads it against a fake host, which is how the registered commands, tools and
189
+ manifest are asserted from the outside.
190
+
191
+ ## CI and releases
192
+
193
+ | Workflow | Trigger | What it runs |
194
+ | --- | --- | --- |
195
+ | `ci.yml` | push to `main`, every pull request | `node --test tools/*.test.js` on Node 18, 20, 22 and 24 — the range `engines` declares, 18 as its floor |
196
+ | `pr-check.yml` | pull request opened, edited, reopened or synchronized | the PR title and every non-merge commit subject must follow [Conventional Commits](https://www.conventionalcommits.org/), plus one suite run on Node 22 |
197
+ | `release.yml` | tag `v*` push, or a manual dispatch naming an existing tag | tag/`package.json` version parity, the suite, the GitHub Release, then `npm publish`, then verification |
198
+
199
+ The npm package is `pi-odd-worktree`, published at 0.1.0. A release is the tag
200
+ `v` plus the exact `package.json` version — the 1.0.0 release is `v1.0.0` — and
201
+ preflight stops the run when the two disagree. Publication uses
202
+ [Trusted Publishing](https://docs.npmjs.com/trusted-publishers): `id-token:
203
+ write` is granted to the `release` job and nowhere else, and no npm credential
204
+ exists in the workflow or in the protected environment. A version npm already
205
+ serves is reported and left alone; a published version is immutable.
206
+
207
+ The `release` environment is where a release pauses for approval when reviewers
208
+ are attached to it, and the trusted publisher binds to this workflow file plus
209
+ that environment name. Publication therefore needs the trusted publisher bound
210
+ to this repository, this workflow file and the `release` environment, and the
211
+ provenance attestation binds to the public `repository` `package.json` names,
212
+ case-sensitively.
213
+
214
+ Release notes are generated when the GitHub Release is created and curated
215
+ afterwards by editing the published release (`gh release edit`); no notes file is
216
+ committed.
217
+
218
+ Cutting a release, contributor rules and the repository invariants are in
219
+ [`AGENTS.md`](AGENTS.md).
220
+
221
+ ## Documentation
222
+
223
+ | Your task | Start here |
224
+ | --- | --- |
225
+ | Change the package, run the suite, cut a release | [`AGENTS.md`](AGENTS.md) |
226
+ | Report a bug or request a feature | [`.github/ISSUE_TEMPLATE/`](.github/ISSUE_TEMPLATE/) |
227
+ | Open a pull request | [`.github/PULL_REQUEST_TEMPLATE.md`](.github/PULL_REQUEST_TEMPLATE.md) |
228
+
229
+ ## Next Steps
230
+
231
+ - Run `/warp` in a repository with at least one other checkout to see the
232
+ selector, then `worktree_list` from the agent to confirm both surfaces agree.
233
+ - Install `gh` and authenticate if you want `/issues`; run `gh auth login` once.
234
+ - Install Gentle Shell if the deletion guard should see sessions other than the
235
+ one you are in.