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,238 @@
1
+ 'use strict';
2
+ // T1 (S1, S2, S5, S6, S7): the decision core of the two CodeGraph reminders. From one finished tool
3
+ // call, the session's own checkout, the role and what the session already used, it decides one text or
4
+ // none, keeps the once-per-key state, and forgets it on a compaction or a new session. Git is a fake
5
+ // toplevel map here: no child, no network, no real agent directory.
6
+ const { test } = require('node:test');
7
+ const assert = require('node:assert/strict');
8
+ const { createCodegraphGuard } = require('../lib/codegraph-guard.js');
9
+
10
+ // The approved texts of S1 and S2, written out so a reworded reminder fails here.
11
+ const ANOTHER = (root) => `This call went to ${root}, another checkout. Follow the CodeGraph rule: call \`mcp__codegraph__codegraph_explore\` with \`projectPath\` set to ${root} first.`;
12
+ const NATIVE = 'Follow the CodeGraph rule: run `codegraph` `query` or `explore` first, if it applies.';
13
+ const MCP = 'Follow the CodeGraph rule: call `mcp__codegraph__codegraph_explore` first, if it applies.';
14
+
15
+ const ROOTS = {
16
+ '/repo': '/repo',
17
+ '/repo/src': '/repo',
18
+ '/repo/a.ts': undefined, // a file has no toplevel: the resolver falls back to its directory
19
+ '/repo/src/a.ts': undefined,
20
+ '/other': '/other',
21
+ '/other/src': '/other',
22
+ '/other/a.ts': undefined,
23
+ '/other/src/a.ts': undefined,
24
+ '/third': '/third',
25
+ '/third/a.ts': undefined,
26
+ '/tmp': undefined,
27
+ };
28
+
29
+ function setup(overrides = {}) {
30
+ const reads = [];
31
+ const toplevel = overrides.toplevel || (async (dir) => {
32
+ reads.push(dir);
33
+ return ROOTS[dir];
34
+ });
35
+ const guard = createCodegraphGuard({
36
+ env: { ...(overrides.env || {}) },
37
+ argv: overrides.argv || ['node', '/bin/pi'],
38
+ toplevel,
39
+ // The fake checkouts are not real directories: every path here is a directory, so one git read answers.
40
+ isDirectory: overrides.isDirectory || (() => true),
41
+ });
42
+ guard.observeTools(overrides.tools || ['read', 'grep', 'bash', 'codegraph', 'mcp__codegraph__codegraph_explore']);
43
+ return { guard, reads, ctx: overrides.ctx || { cwd: '/repo' } };
44
+ }
45
+
46
+ const read = (path) => ({ toolName: 'read', input: { path }, isError: false, content: [] });
47
+ const grep = (path) => (path === undefined
48
+ ? { toolName: 'grep', input: { pattern: 'x' }, isError: false, content: [] }
49
+ : { toolName: 'grep', input: { pattern: 'x', path }, isError: false, content: [] });
50
+ const bash = (command) => ({ toolName: 'bash', input: { command }, isError: false, content: [] });
51
+ const explore = (projectPath) => ({
52
+ toolName: 'mcp__codegraph__codegraph_explore',
53
+ input: projectPath === undefined ? {} : { projectPath },
54
+ isError: false,
55
+ content: [],
56
+ });
57
+
58
+ // ---- the texts (S1, S2) ----
59
+
60
+ test('a call to another checkout is told to explore it with projectPath, once per checkout', async () => {
61
+ const { guard, ctx } = setup();
62
+ assert.equal(await guard.onToolResult(read('/other/src/a.ts'), ctx), ANOTHER('/other'));
63
+ assert.equal(await guard.onToolResult(read('/other/a.ts'), ctx), undefined, 'the same checkout is reminded once');
64
+ assert.equal(await guard.onToolResult(grep('/third'), ctx), ANOTHER('/third'), 'a second checkout gets its own reminder');
65
+ });
66
+
67
+ test('the primary session is pointed at the native operations when it holds the native tool', async () => {
68
+ const { guard, ctx } = setup();
69
+ assert.equal(await guard.onToolResult(grep(), ctx), NATIVE);
70
+ });
71
+
72
+ test('a session holding only the MCP tool is pointed at the MCP call instead', async () => {
73
+ const { guard, ctx } = setup({ tools: ['grep', 'mcp__codegraph__codegraph_explore'] });
74
+ assert.equal(await guard.onToolResult(grep(), ctx), MCP);
75
+ });
76
+
77
+ test('an explore agent gets the native wording, every other child the MCP one', async () => {
78
+ const child = (agent, tools) => setup({
79
+ env: { GENTLE_PI_AGENTS_CHILD: '1', GENTLE_PI_AGENTS_REQUESTED_TOOLS: tools },
80
+ argv: ['node', `/tmp/gentle-pi-subagent-${agent}-a1b2c3/bin.js`],
81
+ tools: [],
82
+ });
83
+ const explorer = child('gentle-ai-explore', 'read,bash,codegraph');
84
+ assert.equal(await explorer.guard.onToolResult(bash('cat src/a.ts'), explorer.ctx), NATIVE);
85
+ const worker = child('gentle-ai-worker', 'read,bash,mcp__codegraph__codegraph_explore');
86
+ assert.equal(await worker.guard.onToolResult(bash('cat src/a.ts'), worker.ctx), MCP);
87
+ });
88
+
89
+ // ---- who gets which guard (S1, S2) ----
90
+
91
+ test('guard 1 belongs to the primary session: a child is never told it reached another checkout', async () => {
92
+ const { guard, ctx } = setup({
93
+ env: { GENTLE_PI_AGENTS_CHILD: '1', GENTLE_PI_AGENTS_REQUESTED_TOOLS: 'read,bash,mcp__codegraph__codegraph_explore' },
94
+ argv: ['node', '/tmp/gentle-pi-subagent-gentle-ai-worker-a1b2c3/bin.js'],
95
+ tools: [],
96
+ });
97
+ assert.equal(await guard.onToolResult(read('/other/src/a.ts'), ctx), undefined);
98
+ });
99
+
100
+ test('a review agent gets no reminder at all', async () => {
101
+ const { guard, ctx } = setup({
102
+ env: { GENTLE_PI_AGENTS_CHILD: '1', GENTLE_PI_AGENTS_REQUESTED_TOOLS: 'read,bash,mcp__codegraph__codegraph_explore' },
103
+ argv: ['node', '/tmp/gentle-pi-subagent-review-code-a1b2c3/bin.js'],
104
+ tools: [],
105
+ });
106
+ assert.equal(await guard.onToolResult(bash('cat src/a.ts'), ctx), undefined);
107
+ assert.equal(await guard.onToolResult(read('/other/a.ts'), ctx), undefined);
108
+ });
109
+
110
+ test('a session holding no CodeGraph tool gets nothing (the prompt section\'s gate)', async () => {
111
+ const { guard, reads, ctx } = setup({ tools: ['read', 'grep', 'bash'] });
112
+ assert.equal(await guard.onToolResult(read('src/a.ts'), ctx), undefined);
113
+ assert.equal(await guard.onToolResult(read('/other/a.ts'), ctx), undefined);
114
+ assert.deepEqual(reads, [], 'and no git read is spent on it');
115
+ });
116
+
117
+ // ---- what counts (S3) ----
118
+
119
+ test('a call that is not a search or read is never a subject', async () => {
120
+ const { guard, reads, ctx } = setup();
121
+ for (const event of [
122
+ { toolName: 'edit', input: { path: '/repo/a.ts' }, isError: false, content: [] },
123
+ { toolName: 'write', input: { path: '/repo/a.ts' }, isError: false, content: [] },
124
+ { toolName: 'worktree_list', input: {}, isError: false, content: [] },
125
+ ]) {
126
+ assert.equal(await guard.onToolResult(event, ctx), undefined);
127
+ }
128
+ assert.deepEqual(reads, []);
129
+ });
130
+
131
+ test('a read of a config or a doc is not a code read', async () => {
132
+ const { guard, ctx } = setup();
133
+ for (const file of ['src/README.md', 'package.json', 'a.yml', 'a.yaml', 'a.toml', 'notes.txt']) {
134
+ assert.equal(await guard.onToolResult(read(file), ctx), undefined, file);
135
+ }
136
+ assert.equal(await guard.onToolResult(read('src/a.ts'), ctx), NATIVE);
137
+ });
138
+
139
+ test('a path with no git checkout triggers nothing, and uses up no slot', async () => {
140
+ const { guard, ctx } = setup();
141
+ assert.equal(await guard.onToolResult(read('/tmp/a.ts'), ctx), undefined);
142
+ assert.equal(await guard.onToolResult(read('src/a.ts'), ctx), NATIVE, 'the own checkout was still unreminded');
143
+ });
144
+
145
+ // ---- guard 2's key is the session's own checkout (S7) ----
146
+
147
+ test('guard 2 is once per session, and a warp to another checkout re-arms it', async () => {
148
+ const { guard, ctx } = setup();
149
+ assert.equal(await guard.onToolResult(grep(), ctx), NATIVE);
150
+ assert.equal(await guard.onToolResult(grep(), ctx), undefined);
151
+ const warped = { cwd: '/third' };
152
+ assert.equal(await guard.onToolResult(read('/third/a.ts'), warped), NATIVE, 'the new checkout has not been reminded');
153
+ });
154
+
155
+ // ---- precision (S5) ----
156
+
157
+ test('guard 1 stays silent for a checkout this session already explored, without using its slot', async () => {
158
+ const { guard, ctx } = setup();
159
+ assert.equal(await guard.onToolResult(explore('/other'), ctx), undefined, 'an explore call is no search call');
160
+ assert.equal(await guard.onToolResult(read('/other/a.ts'), ctx), undefined, 'already explored');
161
+ assert.equal(await guard.onToolResult(read('/third/a.ts'), ctx), ANOTHER('/third'), 'another checkout still gets its reminder');
162
+ assert.equal(await guard.onToolResult(read('/other/a.ts'), ctx), undefined);
163
+ });
164
+
165
+ test('guard 1 understands an explore aimed at a directory inside that checkout', async () => {
166
+ const { guard, ctx } = setup();
167
+ await guard.onToolResult(explore('/other/src'), ctx);
168
+ assert.equal(await guard.onToolResult(read('/other/a.ts'), ctx), undefined);
169
+ });
170
+
171
+ test('guard 2 stays silent once the session used CodeGraph, and the silent attempt used no slot', async () => {
172
+ const { guard, ctx } = setup();
173
+ await guard.onToolResult({ toolName: 'codegraph', input: { operation: 'query' }, isError: false, content: [] }, ctx);
174
+ assert.equal(await guard.onToolResult(grep(), ctx), undefined, 'the graph was already used');
175
+ guard.onCompacted();
176
+ assert.equal(await guard.onToolResult(grep(), ctx), NATIVE, 'the slot was never consumed');
177
+ });
178
+
179
+ test('a call that failed earns no reminder and spends no slot', async () => {
180
+ const { guard, ctx } = setup();
181
+ const failed = (event) => ({ ...event, isError: true });
182
+ assert.equal(await guard.onToolResult(failed(grep()), ctx), undefined, 'a failed grep gave the model nothing to read');
183
+ assert.equal(await guard.onToolResult(failed(read('/other/a.ts')), ctx), undefined, 'nor did a failed read of another checkout');
184
+ assert.equal(await guard.onToolResult(grep(), ctx), NATIVE, 'the slot it would have used is still free');
185
+ assert.equal(await guard.onToolResult(read('/other/a.ts'), ctx), ANOTHER('/other'));
186
+ });
187
+
188
+ test('a failed CodeGraph call is no use of it either', async () => {
189
+ const { guard, ctx } = setup();
190
+ await guard.onToolResult({ toolName: 'codegraph', input: { operation: 'query' }, isError: true, content: [] }, ctx);
191
+ assert.equal(await guard.onToolResult(grep(), ctx), NATIVE, 'a call that failed proved nothing');
192
+ });
193
+
194
+ // ---- reset (S7) ----
195
+
196
+ test('a compaction forgets both guards', async () => {
197
+ const { guard, ctx } = setup();
198
+ assert.equal(await guard.onToolResult(grep(), ctx), NATIVE);
199
+ assert.equal(await guard.onToolResult(read('/other/a.ts'), ctx), ANOTHER('/other'));
200
+ guard.onCompacted();
201
+ assert.equal(await guard.onToolResult(grep(), ctx), NATIVE);
202
+ assert.equal(await guard.onToolResult(read('/other/a.ts'), ctx), ANOTHER('/other'));
203
+ });
204
+
205
+ test('a new session in the same process forgets both guards too', async () => {
206
+ const { guard, ctx } = setup();
207
+ assert.equal(await guard.onToolResult(grep(), ctx), NATIVE);
208
+ assert.equal(await guard.onToolResult(read('/other/a.ts'), ctx), ANOTHER('/other'));
209
+ guard.onNewSession();
210
+ assert.equal(await guard.onToolResult(grep(), ctx), NATIVE);
211
+ assert.equal(await guard.onToolResult(read('/other/a.ts'), ctx), ANOTHER('/other'));
212
+ });
213
+
214
+ test('a compaction forgets what the session already explored and used', async () => {
215
+ const { guard, ctx } = setup();
216
+ await guard.onToolResult(explore('/other'), ctx);
217
+ await guard.onToolResult({ toolName: 'codegraph', input: { operation: 'query' }, isError: false, content: [] }, ctx);
218
+ assert.equal(await guard.onToolResult(read('/other/a.ts'), ctx), undefined);
219
+ assert.equal(await guard.onToolResult(grep(), ctx), undefined);
220
+ guard.onCompacted();
221
+ assert.equal(await guard.onToolResult(read('/other/a.ts'), ctx), ANOTHER('/other'));
222
+ assert.equal(await guard.onToolResult(grep(), ctx), NATIVE);
223
+ });
224
+
225
+ // ---- robustness (S8) ----
226
+
227
+ test('a git read that throws or answers nothing never fails the tool result', async () => {
228
+ let calls = 0;
229
+ const { guard, ctx } = setup({
230
+ toplevel: async () => {
231
+ calls += 1;
232
+ if (calls === 1) throw new Error('git is gone');
233
+ return undefined;
234
+ },
235
+ });
236
+ assert.equal(await guard.onToolResult(grep(), ctx), undefined);
237
+ assert.equal(await guard.onToolResult(grep(), ctx), undefined);
238
+ });