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,120 @@
1
+ 'use strict';
2
+ // The agent-facing rendering of `worktree_list`.
3
+ //
4
+ // Git answers which checkouts exist and on which branch; lib/worktree-registry.js
5
+ // answers which of them this package created (the ones under
6
+ // `<repo-parent>/<repo-name>-worktrees`). This module only decides what a reader
7
+ // sees: the main checkout first and unnumbered, then this package's own checkouts in
8
+ // name order, then — with `all` — the worktrees Git knows outside the directory.
9
+ //
10
+ // A row is its directory's basename, which IS the ODD, and the branch Git reports.
11
+ // There is no `odd:` field, no date, no setup line, no hooks line and no stored
12
+ // state: a directory that exists is a worktree and one that does not is simply not
13
+ // listed (S2, S3). Nothing here reads the filesystem or spawns Git, and this module
14
+ // writes nothing at all.
15
+
16
+ const { basename } = require('node:path');
17
+ const { outsideCheckouts, ownedCheckouts } = require('./worktree-registry.js');
18
+
19
+ const strew = (value) => (typeof value === 'string' && value.length > 0 ? value : '-');
20
+
21
+ const compareText = (a, b) => (a === b ? 0 : a < b ? -1 : 1);
22
+
23
+ /** Worktrees print by name, so the order never depends on Git's own. */
24
+ function compareCheckout(a, b) {
25
+ const named = compareText(basename(a.path), basename(b.path));
26
+ return named === 0 ? compareText(a.path, b.path) : named;
27
+ }
28
+
29
+ function rowFor(entry, index) {
30
+ return {
31
+ index,
32
+ name: basename(entry.path),
33
+ path: entry.path,
34
+ branch: strew(entry.branch),
35
+ };
36
+ }
37
+
38
+ function mainRow(input, main) {
39
+ return {
40
+ name: basename(input.mainRoot ?? main.path),
41
+ path: main.path,
42
+ branch: strew(main.branch),
43
+ shortSha: typeof main.head === 'string' ? main.head.slice(0, 7) : '',
44
+ };
45
+ }
46
+
47
+ const samePath = (a, b) => a.length > 1 && b.length > 1 && a.replace(/[\\/]+$/, '') === b.replace(/[\\/]+$/, '');
48
+
49
+ /**
50
+ * The single structured truth behind both layers: the main row, the rows the view
51
+ * prints in order, and how many outside worktrees the footer hides.
52
+ */
53
+ function worktreeListDetails(input) {
54
+ const all = input.all === true;
55
+ const entries = Array.isArray(input.entries) ? input.entries : [];
56
+ // `git worktree list` prints the main checkout first; that entry is the main row.
57
+ const main = entries[0];
58
+ const rest = entries.filter((entry) => entry !== main && !samePath(entry.path, main.path));
59
+ const mainRoot = input.mainRoot ?? main.path;
60
+
61
+ const worktrees = [mainRow(input, main)];
62
+ for (const entry of ownedCheckouts(rest, mainRoot).sort(compareCheckout)) {
63
+ worktrees.push(rowFor(entry, worktrees.length));
64
+ }
65
+ const outside = outsideCheckouts(rest, mainRoot).sort(compareCheckout);
66
+ if (all) for (const entry of outside) worktrees.push(rowFor(entry, worktrees.length));
67
+
68
+ return {
69
+ project: input.project,
70
+ path: main.path,
71
+ all,
72
+ worktrees,
73
+ hiddenOutside: all ? 0 : outside.length,
74
+ };
75
+ }
76
+
77
+ /** The footer the list prints while it hides outside worktrees, and only then. */
78
+ function worktreeListFooters(details) {
79
+ if (!(details.hiddenOutside > 0)) return [];
80
+ return [`${details.hiddenOutside} worktrees outside the list (--all to list them)`];
81
+ }
82
+
83
+ // The main checkout is the BASE every other checkout forks from, so its row reads
84
+ // exactly like the `base:` line `worktree_create` prints: `<branch>@<sha>`. The
85
+ // branch is always named, because a main checkout standing on another branch is the
86
+ // information the row exists to give; with no stored head only the branch is left,
87
+ // never a dangling `@`.
88
+ function mainLine(row) {
89
+ const head = row.shortSha.length > 0 ? `@${row.shortSha}` : '';
90
+ return `base: ${row.branch}${head}`;
91
+ }
92
+
93
+ // The ODD and its branch are two facts, so a middle dot keeps them visibly apart:
94
+ // `1 <name> · <branch>`.
95
+ function rowLine(row) {
96
+ return `${row.index} ${row.name} · ${row.branch}`;
97
+ }
98
+
99
+ /** The agent-facing text: fixed field order, single spaces, no decoration. */
100
+ function renderWorktreeListText(details) {
101
+ const lines = [`project: ${details.project}`, `path: ${details.path}`];
102
+ for (const row of details.worktrees) {
103
+ lines.push(row.index === undefined ? mainLine(row) : rowLine(row));
104
+ }
105
+ lines.push(...worktreeListFooters(details));
106
+ return lines.join('\n');
107
+ }
108
+
109
+ /** Both presentation layers from one row list: the text an agent reads and the details a card renders. */
110
+ function worktreeListView(input) {
111
+ const details = worktreeListDetails(input);
112
+ return { text: renderWorktreeListText(details), details };
113
+ }
114
+
115
+ module.exports = {
116
+ worktreeListDetails,
117
+ worktreeListFooters,
118
+ renderWorktreeListText,
119
+ worktreeListView,
120
+ };