pi-odd-worktree 2.0.0 → 3.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 (160) hide show
  1. package/README.md +54 -311
  2. package/extensions/odd-worktree-tools.ts +4149 -2447
  3. package/lib/bash-activity.js +1164 -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 +1416 -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 +308 -14
  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 -711
  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 +1419 -0
  75. package/tools/bash-design.test.js +1091 -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 +610 -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 +1871 -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 +391 -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 +1512 -66
  121. package/tools/issues-open-guard.test.js +1096 -0
  122. package/tools/issues-section.test.js +4195 -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 +2569 -308
  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 +477 -93
  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
@@ -0,0 +1,326 @@
1
+ 'use strict';
2
+ // The file picker's listing orders (S10, S23, S33): the pure row builder the panel
3
+ // paints. `files` is one flat list, changed first by recency then clean; `tree` is
4
+ // an IDE-style folder tree where every folder's subfolders come first and its own
5
+ // files after them (so at the top level every folder group paints before the files
6
+ // at the repository root); `ext` is one level of extension groups named with their
7
+ // dot, alphabetical by path inside and the extensionless group last.
8
+ // S23 named the folder order `tree` everywhere — the id, the cycle, this builder
9
+ // and the footer — because `path` read as a file path, not as a folder tree. S33
10
+ // named the flat order `files` for the same reason: `modified` described a filter
11
+ // by modification, while the order is the listing without groups.
12
+ //
13
+ // The module only decides rows and their fold state: it paints nothing, reads
14
+ // no file and mutates neither its entries nor its options. The view holds one
15
+ // fold set per order and hands it in, so `toggleFold` / `groupKey` are the only
16
+ // single-row mutating surfaces, `toggleEveryFold` is the whole-tree one, and all
17
+ // of them touch only the set the caller owns. `holderGroup` answers the one
18
+ // structural question the view's `space` needs — which group row holds a file row
19
+ // — while `holderKeys` / `foldsFor` answer the ones S29, S30 and S39 need: which
20
+ // groups a file lives in, the fold set an order opens with, and the group the
21
+ // cursor returns to after the whole tree folds. `everyGroupFolded` states the
22
+ // direction S40's legend paints.
23
+ //
24
+ // Entry shape is the listing seam's (lib/files-index.js): `{ path, state:
25
+ // "new" | "updated" | "clean", mtimeMs? }`, already changed-first by recency
26
+ // then clean. `files` re-applies that rule here so the order is the module's own,
27
+ // not a property of the caller's array.
28
+
29
+ const { posix } = require('node:path');
30
+
31
+ const ORDERS = ['files', 'tree', 'ext'];
32
+ const DEFAULT_ORDER = 'files';
33
+ // The extensionless group's painted name; its key is the empty string.
34
+ const EXTENSIONLESS_GROUP = '(none)';
35
+
36
+ // Byte order, not locale order, so an order is the same on every machine.
37
+ function byCodePoint(left, right) {
38
+ return left < right ? -1 : left > right ? 1 : 0;
39
+ }
40
+
41
+ function lastSegment(path) {
42
+ const slash = path.lastIndexOf('/');
43
+ return slash < 0 ? path : path.slice(slash + 1);
44
+ }
45
+
46
+ // A dotfile such as `.gitignore` has no extension; `a.tar.gz` groups under `gz`.
47
+ function extensionOf(path) {
48
+ const extension = posix.extname(posix.basename(path));
49
+ return extension.startsWith('.') ? extension.slice(1) : extension;
50
+ }
51
+
52
+ function isEntry(entry) {
53
+ return Boolean(entry) && typeof entry === 'object' && typeof entry.path === 'string' && entry.path.length > 0;
54
+ }
55
+
56
+ function pushTo(map, key, value) {
57
+ const values = map.get(key);
58
+ if (values) values.push(value);
59
+ else map.set(key, [value]);
60
+ }
61
+
62
+ // A folder is reached once per file below it, but the tree paints it once.
63
+ function addSubfolder(map, parent, child) {
64
+ const children = map.get(parent);
65
+ if (children) children.add(child);
66
+ else map.set(parent, new Set([child]));
67
+ }
68
+
69
+ // The listing's own order: changed files first, newest first (an entry without
70
+ // an mtime after the timed ones), then clean files, ties by path.
71
+ function compareFiles(left, right) {
72
+ const leftChanged = left.state !== 'clean';
73
+ const rightChanged = right.state !== 'clean';
74
+ if (leftChanged !== rightChanged) return leftChanged ? -1 : 1;
75
+ if (leftChanged) {
76
+ const leftTimed = Number.isFinite(left.mtimeMs);
77
+ const rightTimed = Number.isFinite(right.mtimeMs);
78
+ if (leftTimed && rightTimed && left.mtimeMs !== right.mtimeMs) return right.mtimeMs - left.mtimeMs;
79
+ if (leftTimed !== rightTimed) return leftTimed ? -1 : 1;
80
+ }
81
+ return byCodePoint(left.path, right.path);
82
+ }
83
+
84
+ function matchesQuery(entry, query) {
85
+ if (query.length === 0) return true;
86
+ return entry.path.toLowerCase().includes(query.toLowerCase());
87
+ }
88
+
89
+ function foldSetHas(folded, key) {
90
+ if (folded instanceof Set) return folded.has(key);
91
+ if (Array.isArray(folded)) return folded.includes(key);
92
+ return false;
93
+ }
94
+
95
+ function fileRows(entries) {
96
+ return entries
97
+ .slice()
98
+ .sort(compareFiles)
99
+ .map((entry) => ({ kind: 'file', entry, depth: 0, showDirectory: true }));
100
+ }
101
+
102
+ // The `tree` order: every folder on the way down gets a group row (even one
103
+ // holding no file of its own), its subfolders paint before its own files, and
104
+ // both are alphabetical by name. A folded folder keeps its row and hides
105
+ // everything below it.
106
+ function treeRows(entries, isFolded) {
107
+ const ownFiles = new Map();
108
+ const subfolders = new Map();
109
+ for (const entry of entries) {
110
+ const directory = posix.dirname(entry.path);
111
+ const folder = directory === '.' ? '' : directory;
112
+ pushTo(ownFiles, folder, entry);
113
+ let current = folder;
114
+ while (current !== '') {
115
+ const slash = current.lastIndexOf('/');
116
+ const parent = slash < 0 ? '' : current.slice(0, slash);
117
+ addSubfolder(subfolders, parent, current);
118
+ current = parent;
119
+ }
120
+ }
121
+
122
+ const rows = [];
123
+ const paint = (folder, depth) => {
124
+ const children = [...(subfolders.get(folder) ?? [])].sort(
125
+ (left, right) => byCodePoint(lastSegment(left), lastSegment(right)) || byCodePoint(left, right),
126
+ );
127
+ for (const child of children) {
128
+ const folded = isFolded(child);
129
+ rows.push({ kind: 'group', key: child, label: lastSegment(child), depth, folded });
130
+ if (!folded) paint(child, depth + 1);
131
+ }
132
+ const files = [...(ownFiles.get(folder) ?? [])].sort(
133
+ (left, right) => byCodePoint(posix.basename(left.path), posix.basename(right.path)) || byCodePoint(left.path, right.path),
134
+ );
135
+ for (const entry of files) rows.push({ kind: 'file', entry, depth, showDirectory: false });
136
+ };
137
+ paint('', 0);
138
+ return rows;
139
+ }
140
+
141
+ // The `ext` tree, one level deep: one group per extension named with its dot,
142
+ // the files inside alphabetical by path, and the extensionless group last.
143
+ function extensionRows(entries, isFolded) {
144
+ const groups = new Map();
145
+ for (const entry of entries) pushTo(groups, extensionOf(entry.path), entry);
146
+ const extensions = [...groups.keys()].sort((left, right) =>
147
+ left === '' ? 1 : right === '' ? -1 : byCodePoint(left, right),
148
+ );
149
+ const rows = [];
150
+ for (const extension of extensions) {
151
+ const folded = isFolded(extension);
152
+ const label = extension === '' ? EXTENSIONLESS_GROUP : `.${extension}`;
153
+ rows.push({ kind: 'group', key: extension, label, depth: 0, folded });
154
+ if (folded) continue;
155
+ const files = [...(groups.get(extension) ?? [])].sort((left, right) => byCodePoint(left.path, right.path));
156
+ for (const entry of files) rows.push({ kind: 'file', entry, depth: 1, showDirectory: true });
157
+ }
158
+ return rows;
159
+ }
160
+
161
+ /**
162
+ * The next order `ctrl+o` selects. An order the module does not know starts the
163
+ * cycle at the default `files` instead of leaving the list unrendered.
164
+ */
165
+ function nextOrder(order) {
166
+ const index = ORDERS.indexOf(order);
167
+ return ORDERS[(index + 1) % ORDERS.length];
168
+ }
169
+
170
+ /**
171
+ * The rows the list paints for one order (S10). Pure: the entries, the options
172
+ * and the fold set are only read. `folded` is a group key set (or an array of
173
+ * keys) the view owns per order; a non-empty `query` filters file rows on their
174
+ * whole path, case-insensitively, and forces every group open, so a match is
175
+ * never hidden behind a fold.
176
+ */
177
+ function buildRows(entries, options = {}) {
178
+ const opts = options && typeof options === 'object' ? options : {};
179
+ const order = ORDERS.includes(opts.order) ? opts.order : DEFAULT_ORDER;
180
+ const query = typeof opts.query === 'string' ? opts.query : '';
181
+ const folded = opts.folded;
182
+ const matched = (Array.isArray(entries) ? entries : []).filter(
183
+ (entry) => isEntry(entry) && matchesQuery(entry, query),
184
+ );
185
+ if (matched.length === 0) return [];
186
+ if (order === 'files') return fileRows(matched);
187
+ // A non-empty query forces every group open: the fold keys are inert then.
188
+ const forced = query.length > 0;
189
+ const isFolded = (key) => !forced && foldSetHas(folded, key);
190
+ return order === 'tree' ? treeRows(matched, isFolded) : extensionRows(matched, isFolded);
191
+ }
192
+
193
+ /**
194
+ * The key a group row folds on, or null for a file row. `tree` keys are the
195
+ * folder's repository-relative path and `ext` keys are the bare extension (the
196
+ * empty string for the extensionless group), so each order's set is its own.
197
+ */
198
+ function groupKey(row) {
199
+ return row && row.kind === 'group' && typeof row.key === 'string' ? row.key : null;
200
+ }
201
+
202
+ /**
203
+ * space / Enter on a group row: toggle its key in the caller's per-order fold
204
+ * set. True when a group was toggled; a file row or no set changes nothing.
205
+ */
206
+ function toggleFold(row, foldedSet) {
207
+ const key = groupKey(row);
208
+ if (key === null || !(foldedSet instanceof Set)) return false;
209
+ if (foldedSet.has(key)) foldedSet.delete(key);
210
+ else foldedSet.add(key);
211
+ return true;
212
+ }
213
+
214
+ /**
215
+ * The group row that HOLDS the file row at `index`: the nearest group row above it
216
+ * exactly one depth shallower — the file's folder in `tree`, its extension group in
217
+ * `ext`. `space` folds that group from a file row (S10), so where a file lives is
218
+ * asked here rather than guessed by the view.
219
+ *
220
+ * Null for a group row, a file row at the top level (a repository-root file in
221
+ * `tree` has no folder to fold), the flat `files` list and an out-of-range
222
+ * index.
223
+ */
224
+ function holderGroup(rows, index) {
225
+ const list = Array.isArray(rows) ? rows : [];
226
+ const wanted = Number.isInteger(index) ? index : -1;
227
+ const row = wanted >= 0 && wanted < list.length ? list[wanted] : undefined;
228
+ if (!row || row.kind !== 'file') return null;
229
+ for (let at = wanted - 1; at >= 0; at -= 1) {
230
+ const candidate = list[at];
231
+ if (candidate && candidate.kind === 'group' && candidate.depth === row.depth - 1) return candidate;
232
+ }
233
+ return null;
234
+ }
235
+
236
+ /**
237
+ * The group keys that HOLD a file (S29, S30): in `tree` its folders from the top
238
+ * down (`src`, `src/web` for `src/web/test.ts`), in `ext` its extension group (the
239
+ * empty key for a file without an extension), and nothing for the flat `files`
240
+ * order or for a file at the repository root, which has no folder to open.
241
+ */
242
+ function holderKeys(path, order) {
243
+ if (typeof path !== 'string' || path.length === 0) return [];
244
+ if (order === 'tree') {
245
+ const directory = posix.dirname(path);
246
+ if (directory === '.' || directory === path) return [];
247
+ const keys = [];
248
+ let current = '';
249
+ for (const part of directory.split('/')) {
250
+ current = current === '' ? part : `${current}/${part}`;
251
+ keys.push(current);
252
+ }
253
+ return keys;
254
+ }
255
+ if (order === 'ext') return [extensionOf(path)];
256
+ return [];
257
+ }
258
+
259
+ /** Every group key one tree order paints for a listing, folded or not (S29, S34). */
260
+ function treeGroupKeys(entries, order) {
261
+ if (order !== 'tree' && order !== 'ext') return [];
262
+ const keys = [];
263
+ for (const row of buildRows(entries, { order })) {
264
+ if (row.kind === 'group') keys.push(row.key);
265
+ }
266
+ return keys;
267
+ }
268
+
269
+ /**
270
+ * The fold set an order opens with (S29, S30): every group folded except the ones
271
+ * holding `path`. Without a focused file every group is folded, which is how both
272
+ * trees start; a repository-root file has no folder, so it opens nothing and every
273
+ * group stays collapsed.
274
+ */
275
+ function foldsFor(entries, order, path) {
276
+ const open = new Set(holderKeys(path, order));
277
+ const folded = new Set();
278
+ for (const key of treeGroupKeys(entries, order)) {
279
+ if (!open.has(key)) folded.add(key);
280
+ }
281
+ return folded;
282
+ }
283
+
284
+ /**
285
+ * Whether every group of a tree order is collapsed (S40): the footer asks it to
286
+ * name the action `shift+space` would perform. The flat `files` order paints no
287
+ * group, so none of them is open and the answer is true; an empty listing is the
288
+ * same empty truth, and the key itself still does nothing there.
289
+ */
290
+ function everyGroupFolded(entries, order, foldedSet) {
291
+ return treeGroupKeys(entries, order).every((key) => foldSetHas(foldedSet, key));
292
+ }
293
+
294
+ /**
295
+ * `shift+space` in a tree order (S39): ONE toggle over every group of the active
296
+ * order. When every group is already collapsed it expands them all, otherwise it
297
+ * collapses them all — the groups holding the highlighted file included, so no
298
+ * group is ever held open across the toggle. The view is what parks the cursor on
299
+ * the group row the file came from. Mutates `foldedSet` the way `toggleFold` does
300
+ * and answers whether it changed anything: false for the flat `files` order, no set
301
+ * at all, or a listing that paints no group.
302
+ */
303
+ function toggleEveryFold(entries, order, foldedSet) {
304
+ if (!(foldedSet instanceof Set)) return false;
305
+ const keys = treeGroupKeys(entries, order);
306
+ if (keys.length === 0) return false;
307
+ const expanding = keys.every((key) => foldedSet.has(key));
308
+ for (const key of keys) {
309
+ if (expanding) foldedSet.delete(key);
310
+ else foldedSet.add(key);
311
+ }
312
+ return true;
313
+ }
314
+
315
+ module.exports = {
316
+ ORDERS,
317
+ nextOrder,
318
+ buildRows,
319
+ groupKey,
320
+ holderGroup,
321
+ holderKeys,
322
+ foldsFor,
323
+ everyGroupFolded,
324
+ toggleFold,
325
+ toggleEveryFold,
326
+ };