pi-odd-worktree 2.1.0 → 3.0.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.
Files changed (160) hide show
  1. package/README.md +54 -319
  2. package/extensions/odd-worktree-tools.ts +4182 -2539
  3. package/lib/bash-activity.js +1166 -0
  4. package/lib/bash-design.js +684 -0
  5. package/lib/bash-destructive.js +559 -0
  6. package/lib/bash-frame.js +205 -0
  7. package/lib/card-content.js +23 -0
  8. package/lib/card-style.js +175 -0
  9. package/lib/checkout-facts.js +30 -70
  10. package/lib/codegraph-card-preview.js +628 -0
  11. package/lib/codegraph-card.js +515 -0
  12. package/lib/codegraph-compaction.js +76 -0
  13. package/lib/codegraph-daemon.js +246 -0
  14. package/lib/codegraph-edit-sync.js +182 -0
  15. package/lib/codegraph-guard-target.js +337 -0
  16. package/lib/codegraph-guard.js +211 -0
  17. package/lib/codegraph-index.js +1020 -0
  18. package/lib/codegraph-lock.js +607 -0
  19. package/lib/codegraph-mcp-config.js +134 -0
  20. package/lib/codegraph-mcp.js +123 -0
  21. package/lib/codegraph-paths.js +69 -0
  22. package/lib/codegraph-prompt/explore.md +11 -0
  23. package/lib/codegraph-prompt/fix.md +6 -0
  24. package/lib/codegraph-prompt/generic.md +8 -0
  25. package/lib/codegraph-prompt/judge.md +9 -0
  26. package/lib/codegraph-prompt/orchestrator.md +17 -0
  27. package/lib/codegraph-prompt/verify.md +10 -0
  28. package/lib/codegraph-prompt/worker.md +7 -0
  29. package/lib/codegraph-role.js +55 -0
  30. package/lib/codegraph-rules.js +146 -0
  31. package/lib/codegraph-session.js +303 -383
  32. package/lib/codegraph-warmup.js +139 -0
  33. package/lib/file-card-markdown.js +141 -0
  34. package/lib/file-card-resolver.js +245 -0
  35. package/lib/file-card.js +659 -0
  36. package/lib/files-index.js +387 -0
  37. package/lib/files-insert.js +81 -0
  38. package/lib/files-orders.js +326 -0
  39. package/lib/files-picker-view.js +1421 -0
  40. package/lib/files-preview.js +338 -0
  41. package/lib/files-scope-detail.js +171 -0
  42. package/lib/files-scope-view.js +507 -0
  43. package/lib/gh-issues.js +323 -15
  44. package/lib/issue-preview.js +26 -7
  45. package/lib/issues-bash-mutation.js +206 -0
  46. package/lib/issues-cache-store.js +261 -0
  47. package/lib/issues-section.js +710 -0
  48. package/lib/issues-view.js +649 -52
  49. package/lib/odd-prompt/odd-worktrees.md +21 -0
  50. package/lib/odd-worktrees-prompt.js +10 -28
  51. package/lib/related-issues-cache.js +210 -0
  52. package/lib/shell-card.js +825 -0
  53. package/lib/skill-odd-card.js +183 -0
  54. package/lib/tui-paint.js +4 -5
  55. package/lib/warp-create-panel.js +538 -250
  56. package/lib/warp-create-picker.js +56 -9
  57. package/lib/warp-delete-confirm.js +19 -28
  58. package/lib/warp-selector-view.js +160 -82
  59. package/lib/which-command.js +90 -0
  60. package/lib/worktree-card.js +267 -897
  61. package/lib/worktree-cards.js +383 -0
  62. package/lib/worktree-create.js +287 -0
  63. package/lib/worktree-git.js +3 -3
  64. package/lib/worktree-guard.js +548 -0
  65. package/lib/worktree-hooks.js +421 -712
  66. package/lib/worktree-list.js +120 -0
  67. package/lib/worktree-registry.js +162 -879
  68. package/lib/{worktree-close-herdr.js → worktree-remove.js} +9 -11
  69. package/lib/worktree-setup-runner.js +376 -0
  70. package/lib/worktree-setup.js +140 -0
  71. package/lib/worktree-warp-busy.js +462 -85
  72. package/lib/worktree-warp-sessions.js +1 -2
  73. package/package.json +2 -2
  74. package/tools/bash-activity.test.js +1420 -0
  75. package/tools/bash-design.test.js +1093 -0
  76. package/tools/bash-destructive.test.js +139 -0
  77. package/tools/card-content.test.js +44 -0
  78. package/tools/card-style.test.js +298 -0
  79. package/tools/codegraph-card-preview.test.js +254 -0
  80. package/tools/codegraph-card.test.js +1080 -0
  81. package/tools/codegraph-compaction.test.js +378 -0
  82. package/tools/codegraph-daemon.test.js +248 -0
  83. package/tools/codegraph-edit-sync.test.js +295 -0
  84. package/tools/codegraph-guard-target.test.js +174 -0
  85. package/tools/codegraph-guard.test.js +238 -0
  86. package/tools/codegraph-index.test.js +1948 -0
  87. package/tools/codegraph-lock.test.js +932 -0
  88. package/tools/codegraph-mcp-config.test.js +181 -0
  89. package/tools/codegraph-mcp.test.js +194 -0
  90. package/tools/codegraph-paths.test.js +44 -0
  91. package/tools/codegraph-role.test.js +30 -0
  92. package/tools/codegraph-rules.test.js +250 -0
  93. package/tools/codegraph-session.test.js +660 -391
  94. package/tools/codegraph-warmup.test.js +316 -0
  95. package/tools/commands.test.js +510 -31
  96. package/tools/file-card-markdown.test.js +188 -0
  97. package/tools/file-card.test.js +1289 -0
  98. package/tools/files-bridge.test.js +575 -0
  99. package/tools/files-command.test.js +613 -0
  100. package/tools/files-index.test.js +473 -0
  101. package/tools/files-insert.test.js +139 -0
  102. package/tools/files-orders.test.js +597 -0
  103. package/tools/files-picker-view.test.js +1889 -0
  104. package/tools/files-preview.test.js +452 -0
  105. package/tools/files-scope-detail.test.js +264 -0
  106. package/tools/files-scope-view.test.js +614 -0
  107. package/tools/fixtures/card-codegraph-outputs.js +110 -0
  108. package/tools/fixtures/codegraph-cli-stub.js +16 -0
  109. package/tools/fixtures/codegraph-init-process.js +28 -0
  110. package/tools/fixtures/codegraph-lock-worker.js +117 -0
  111. package/tools/fixtures/daemon-fake.js +98 -0
  112. package/tools/fixtures/daemon-mcp-server.js +39 -0
  113. package/tools/fixtures/daemon-warmup-worker.js +12 -0
  114. package/tools/fixtures/load-extension.js +136 -3
  115. package/tools/gh-issues-feedback.test.js +31 -7
  116. package/tools/gh-issues.test.js +417 -1
  117. package/tools/issue-preview.test.js +44 -7
  118. package/tools/issues-bash-mutation.test.js +101 -0
  119. package/tools/issues-cache-store.test.js +222 -0
  120. package/tools/issues-command.test.js +1517 -67
  121. package/tools/issues-open-guard.test.js +1096 -0
  122. package/tools/issues-section.test.js +4235 -0
  123. package/tools/issues-seed-query-regression.test.js +67 -0
  124. package/tools/issues-view.test.js +1489 -60
  125. package/tools/odd-worktrees-prompt.test.js +98 -65
  126. package/tools/package-surface.test.js +431 -36
  127. package/tools/related-issues-cache.test.js +324 -0
  128. package/tools/shell-card.test.js +834 -0
  129. package/tools/skill-odd-card.test.js +200 -0
  130. package/tools/t5-session-identity.test.js +44 -22
  131. package/tools/warp-busy-guard.test.js +2565 -309
  132. package/tools/warp-create-panel.test.js +499 -74
  133. package/tools/warp-create-picker.test.js +101 -5
  134. package/tools/warp-delete-confirm.test.js +49 -15
  135. package/tools/warp-empty-session.test.js +0 -1
  136. package/tools/warp-fallback-regression.test.js +533 -0
  137. package/tools/warp-selector-view.test.js +460 -196
  138. package/tools/which-command.test.js +126 -0
  139. package/tools/worktree-card.test.js +551 -0
  140. package/tools/worktree-cards.test.js +845 -0
  141. package/tools/worktree-changes.test.js +4 -5
  142. package/tools/worktree-create.test.js +489 -0
  143. package/tools/worktree-guard.test.js +823 -0
  144. package/tools/worktree-hooks.test.js +905 -0
  145. package/tools/worktree-list.test.js +170 -0
  146. package/tools/worktree-registry.test.js +89 -230
  147. package/tools/worktree-remove-async.test.js +318 -0
  148. package/tools/worktree-setup-runner.test.js +276 -0
  149. package/tools/worktree-setup.test.js +140 -0
  150. package/tools/worktree-tools.test.js +419 -199
  151. package/lib/codegraph-commands.js +0 -165
  152. package/lib/odd-prompt/odd-worktrees.with-codegraph.md +0 -19
  153. package/lib/odd-prompt/odd-worktrees.without-codegraph.md +0 -15
  154. package/lib/worktree-model-result.js +0 -291
  155. package/tools/codegraph-commands.test.js +0 -371
  156. package/tools/herdr-free-create.test.js +0 -161
  157. package/tools/worktree-close-herdr-async.test.js +0 -204
  158. package/tools/worktree-odd-migration.test.js +0 -224
  159. package/tools/worktree-registry-cache.test.js +0 -163
  160. package/tools/worktree-registry-odd.test.js +0 -231
@@ -1,231 +0,0 @@
1
- 'use strict';
2
- // T8 / S8-S8b: the ENTITY rule — a worktree carries AT MOST ONE odd
3
- // document. It is an invariant of the registry row, not a UI convention:
4
- // the row holds one document path string or `null`, and the registry
5
- // enforces it on EVERY read and EVERY write so no caller can reintroduce a
6
- // second one.
7
- //
8
- // S8b migration: a legacy row that already stores an array normalizes
9
- // deterministically to its FIRST entry, reads never fail on it, and the
10
- // write that normalized it REPORTS the dropped entries once (`dropped`)
11
- // instead of letting a stored association disappear silently.
12
- //
13
- // Every test builds its own isolated fixture repository under os.tmpdir()
14
- // and asserts through the public registry interface plus the bytes on disk,
15
- // never an internal helper. Only the fixture dirs tracked in `roots` are
16
- // removed.
17
-
18
- const { test, describe, after } = require('node:test');
19
- const assert = require('node:assert/strict');
20
- const fs = require('node:fs');
21
- const os = require('node:os');
22
- const path = require('node:path');
23
- const { spawnSync } = require('node:child_process');
24
-
25
- const registryLib = require('../lib/worktree-registry.js');
26
-
27
- const roots = [];
28
- after(() => {
29
- for (const dir of roots) {
30
- fs.rmSync(dir, { recursive: true, force: true });
31
- }
32
- });
33
-
34
- function track(dir) {
35
- roots.push(dir);
36
- return dir;
37
- }
38
-
39
- function git(cwd, args) {
40
- const result = spawnSync('git', args, { cwd, encoding: 'utf8' });
41
- assert.equal(result.status, 0, `git ${args.join(' ')} failed: ${result.stderr}`);
42
- return (result.stdout || '').trim();
43
- }
44
-
45
- function makeRepo(tag) {
46
- const dir = track(fs.mkdtempSync(path.join(os.tmpdir(), `wt-regodd-${tag}-`)));
47
- git(dir, ['init']);
48
- git(dir, ['config', 'user.email', 'test@example.com']);
49
- git(dir, ['config', 'user.name', 'Test']);
50
- git(dir, ['commit', '--allow-empty', '-m', 'init']);
51
- return fs.realpathSync(dir);
52
- }
53
-
54
- function checkoutPath(root, slug) {
55
- return path.join(path.dirname(root), `${path.basename(root)}-${slug}-wt`);
56
- }
57
-
58
- function entry(branch, root, extra = {}) {
59
- return {
60
- branch,
61
- path: checkoutPath(root, branch.replace(/[^a-z0-9]+/gi, '-')),
62
- thread: `thread-${branch}`,
63
- issues: [],
64
- ...extra,
65
- };
66
- }
67
-
68
- // The row exactly as it sits in the registry FILE: proof that the entity —
69
- // not just the in-memory read — holds one document or none.
70
- function storedRows(root) {
71
- const raw = fs.readFileSync(registryLib.registryPath(root), 'utf8');
72
- return JSON.parse(raw).worktrees;
73
- }
74
-
75
- function storedRow(root, branch) {
76
- return storedRows(root).find((row) => row.branch === branch);
77
- }
78
-
79
- // Hand-write a registry file, exactly as an older version of this package
80
- // left it (rows carrying `odd[]`).
81
- function writeLegacyRegistry(root, rows) {
82
- const file = registryLib.registryPath(root);
83
- fs.mkdirSync(path.dirname(file), { recursive: true });
84
- const payload = JSON.stringify({ version: registryLib.REGISTRY_VERSION, worktrees: rows }, null, 2);
85
- fs.writeFileSync(file, `${payload}\n`);
86
- return file;
87
- }
88
-
89
- describe('S8: a worktree carries at most ONE odd document', { concurrency: false }, () => {
90
- test('a write of one document stores it as a single path string, never a list', () => {
91
- const root = makeRepo('one');
92
- const written = registryLib.upsertWorktree(root, entry('feat/one', root, { odd: 'odd/tasks/a.md' }));
93
- assert.equal(written.ok, true, `expected the write to succeed: ${JSON.stringify(written)}`);
94
- assert.equal(written.entry.odd, 'odd/tasks/a.md', 'the write result carries the single path');
95
- assert.ok(!Array.isArray(written.entry.odd), 'the write result never carries a list');
96
-
97
- const read = registryLib.readRegistry(root);
98
- assert.equal(read.ok, true);
99
- assert.equal(read.worktrees.length, 1);
100
- assert.equal(read.worktrees[0].odd, 'odd/tasks/a.md', 'a read returns the same single path');
101
- assert.equal(registryLib.findByBranch(root, 'feat/one').odd, 'odd/tasks/a.md', 'the lookups inherit it');
102
-
103
- const stored = storedRow(root, 'feat/one');
104
- assert.equal(stored.odd, 'odd/tasks/a.md', 'the row on disk holds the string');
105
- assert.equal(Array.isArray(stored.odd), false, 'the row on disk never holds a list');
106
- });
107
-
108
- test('an empty list is "no association": the row stores null, not []', () => {
109
- const root = makeRepo('empty');
110
- const written = registryLib.upsertWorktree(root, entry('feat/empty', root, { odd: [] }));
111
- assert.equal(written.ok, true);
112
- assert.equal(written.entry.odd, null, 'an empty list normalizes to null');
113
- assert.equal(storedRow(root, 'feat/empty').odd, null, 'the row on disk holds null');
114
- assert.equal(registryLib.findByBranch(root, 'feat/empty').odd, null);
115
- });
116
-
117
- test('a write of two legacy entries collapses to the FIRST and reports the dropped ones once', () => {
118
- const root = makeRepo('legacy-write');
119
- const written = registryLib.upsertWorktree(root, entry('feat/drop', root, {
120
- odd: ['odd/tasks/first.md', 'odd/tasks/second.md', 'odd/tasks/third.md'],
121
- }));
122
- assert.equal(written.ok, true, 'a legacy list is normalized, never refused by the registry');
123
- assert.equal(written.entry.odd, 'odd/tasks/first.md', 'the FIRST stored entry wins deterministically');
124
- assert.deepEqual(written.dropped, ['odd/tasks/second.md', 'odd/tasks/third.md'], 'the dropped entries are reported');
125
- assert.equal(storedRow(root, 'feat/drop').odd, 'odd/tasks/first.md', 'only one document reaches the file');
126
-
127
- // Reported ONCE: the row is normalized now, so the next write drops nothing.
128
- const again = registryLib.updateWorktree(root, 'feat/drop', { issues: [] });
129
- assert.equal(again.ok, true);
130
- assert.equal('dropped' in again, false, 'a write that normalizes nothing reports nothing');
131
- assert.equal(registryLib.findByBranch(root, 'feat/drop').odd, 'odd/tasks/first.md', 'and the association survives');
132
- });
133
-
134
- test('a legacy row already storing a list reads as its FIRST entry and never fails', () => {
135
- const root = makeRepo('legacy-read');
136
- const file = writeLegacyRegistry(root, [
137
- { ...entry('feat/legacy', root), odd: ['odd/tasks/first.md', 'odd/tasks/second.md'] },
138
- { ...entry('feat/blank', root), odd: [] },
139
- { ...entry('feat/missing', root) },
140
- ]);
141
- const before = fs.readFileSync(file, 'utf8');
142
-
143
- const read = registryLib.readRegistry(root);
144
- assert.equal(read.ok, true, 'a read never fails on a legacy array');
145
- assert.equal(read.error, null);
146
- const oddOf = (branch) => read.worktrees.find((row) => row.branch === branch).odd;
147
- assert.equal(oddOf('feat/legacy'), 'odd/tasks/first.md', 'the legacy list reads as one document');
148
- assert.equal(oddOf('feat/blank'), null, 'an empty list reads as no association');
149
- assert.equal(oddOf('feat/missing'), null, 'a row without the field reads as no association');
150
- assert.equal(registryLib.findByBranch(root, 'feat/legacy').odd, 'odd/tasks/first.md');
151
- assert.equal(fs.readFileSync(file, 'utf8'), before, 'a read never rewrites the file');
152
- });
153
-
154
- test('the write over a legacy row normalizes the file and reports the drop', () => {
155
- const root = makeRepo('legacy-migrate');
156
- writeLegacyRegistry(root, [
157
- { ...entry('feat/legacy', root), odd: ['odd/tasks/first.md', 'odd/tasks/second.md'] },
158
- ]);
159
- const updated = registryLib.updateWorktree(root, 'feat/legacy', { issues: [] });
160
- assert.equal(updated.ok, true);
161
- assert.deepEqual(updated.dropped, ['odd/tasks/second.md'], 'the collapsing write reports what it dropped');
162
- assert.equal(storedRow(root, 'feat/legacy').odd, 'odd/tasks/first.md', 'the file now holds one document');
163
- assert.equal(registryLib.updateWorktree(root, 'feat/legacy', { issues: [] }).dropped, undefined, 'reported once');
164
- });
165
-
166
- test('associating another document REPLACES the stored one and never adds a second', () => {
167
- const root = makeRepo('replace');
168
- registryLib.upsertWorktree(root, entry('feat/replace', root, { odd: 'odd/tasks/a.md' }));
169
-
170
- const swapped = registryLib.addOddDoc(root, 'feat/replace', 'odd/tasks/b.md');
171
- assert.equal(swapped.ok, true);
172
- assert.equal(swapped.entry.odd, 'odd/tasks/b.md', 'the new document is the ONLY association');
173
- assert.equal(swapped.added, true);
174
- assert.equal(swapped.replaced, 'odd/tasks/a.md', 'the replaced association is reported, never dropped silently');
175
- assert.equal(storedRow(root, 'feat/replace').odd, 'odd/tasks/b.md');
176
-
177
- const same = registryLib.addOddDoc(root, 'feat/replace', 'odd/tasks/b.md');
178
- assert.equal(same.ok, true);
179
- assert.equal(same.added, false, 'a repeat association is idempotent');
180
- assert.equal(same.replaced, null, 'and replaces nothing');
181
- assert.equal(registryLib.findByBranch(root, 'feat/replace').odd, 'odd/tasks/b.md');
182
- });
183
-
184
- test('no write path can leave two documents behind: update, add and upsert agree', () => {
185
- const root = makeRepo('all-writes');
186
- registryLib.upsertWorktree(root, entry('feat/w', root, { odd: 'odd/tasks/a.md' }));
187
-
188
- const patched = registryLib.updateWorktree(root, 'feat/w', { odd: ['odd/tasks/x.md', 'odd/tasks/y.md'] });
189
- assert.equal(patched.ok, true, `the registry normalizes a legacy list instead of failing: ${JSON.stringify(patched)}`);
190
- assert.equal(patched.entry.odd, 'odd/tasks/x.md');
191
- assert.deepEqual(patched.dropped, ['odd/tasks/y.md']);
192
-
193
- const cleared = registryLib.updateWorktree(root, 'feat/w', { odd: null });
194
- assert.equal(cleared.ok, true);
195
- assert.equal(cleared.entry.odd, null, 'null clears the association');
196
-
197
- const replaced = registryLib.updateWorktree(root, 'feat/w', { odd: 'odd/tasks/z.md' });
198
- assert.equal(replaced.ok, true);
199
- assert.equal(replaced.entry.odd, 'odd/tasks/z.md');
200
-
201
- // An upsert that says nothing about odd keeps the stored association.
202
- const untouched = registryLib.upsertWorktree(root, entry('feat/w', root, {}));
203
- assert.equal(untouched.ok, true);
204
- assert.equal(untouched.entry.odd, 'odd/tasks/z.md', 'an omitted odd keeps the single association');
205
-
206
- for (const row of storedRows(root)) {
207
- assert.ok(row.odd === null || typeof row.odd === 'string', `row holds one document or none: ${JSON.stringify(row.odd)}`);
208
- }
209
- });
210
-
211
- test('startup discovery registers rows with no association, never an empty list', () => {
212
- const root = makeRepo('discovery');
213
- const live = [{ branch: 'feat/live', path: root }];
214
- const registered = registryLib.registerMissingWorktrees(root, live, root);
215
- assert.equal(registered.ok, true, `expected discovery to register: ${JSON.stringify(registered)}`);
216
- assert.deepEqual(registered.registered.map((row) => row.branch), ['feat/live']);
217
- const row = registryLib.findByBranch(root, 'feat/live');
218
- assert.equal(row.odd, null, 'a discovered row carries no association');
219
- assert.equal(storedRow(root, 'feat/live').odd, null, 'and the file holds null');
220
- });
221
-
222
- test('a value that is neither a path nor a list is refused without writing', () => {
223
- const root = makeRepo('refuse');
224
- registryLib.upsertWorktree(root, entry('feat/r', root, { odd: 'odd/tasks/a.md' }));
225
- const before = fs.readFileSync(registryLib.registryPath(root), 'utf8');
226
- const refused = registryLib.updateWorktree(root, 'feat/r', { odd: 42 });
227
- assert.equal(refused.ok, false, 'a non-path odd value is refused');
228
- assert.match(refused.error, /odd/i, `the refusal names odd: ${refused.error}`);
229
- assert.equal(fs.readFileSync(registryLib.registryPath(root), 'utf8'), before, 'a refused write changes nothing');
230
- });
231
- });