pi-odd-worktree 2.1.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 -319
  2. package/extensions/odd-worktree-tools.ts +4145 -2529
  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 -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 +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 +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,7 +1,7 @@
1
1
  'use strict';
2
- // S7: the `## ODD worktrees` section and its append-only injection. The two
3
- // texts are the contract, so they are asserted verbatim; the gate is injected
4
- // so no test depends on whether the machine has the CLI.
2
+ // S7: the `## ODD worktrees` section and its append-only injection. The text is
3
+ // the contract, so it is asserted verbatim. There is exactly ONE section: the
4
+ // package promises no CodeGraph work, so no gate and no variant selection.
5
5
  const { test, describe, after } = require('node:test');
6
6
  const assert = require('node:assert/strict');
7
7
  const os = require('node:os');
@@ -12,10 +12,8 @@ const fs = require('node:fs');
12
12
  const path = require('node:path');
13
13
 
14
14
  const PROMPT_DIR = path.resolve(__dirname, '..', 'lib', 'odd-prompt');
15
- const WITH_FILE = path.join(PROMPT_DIR, 'odd-worktrees.with-codegraph.md');
16
- const WITHOUT_FILE = path.join(PROMPT_DIR, 'odd-worktrees.without-codegraph.md');
17
- const WITH_CODEGRAPH = fs.readFileSync(WITH_FILE, 'utf8').trim();
18
- const WITHOUT_CODEGRAPH = fs.readFileSync(WITHOUT_FILE, 'utf8').trim();
15
+ const SECTION_FILE = path.join(PROMPT_DIR, 'odd-worktrees.md');
16
+ const SECTION = fs.readFileSync(SECTION_FILE, 'utf8').trim();
19
17
 
20
18
  const savedEnv = { ...process.env };
21
19
  after(() => {
@@ -34,21 +32,13 @@ function run(event, deps = {}) {
34
32
  return prompt.appendOddWorktreesSection(event, deps);
35
33
  }
36
34
 
37
- const present = () => true;
38
- const absent = () => false;
39
35
  const primaryEvent = (options) => ({ systemPromptOptions: options });
40
36
 
41
37
  describe('section text', () => {
42
- test('the CodeGraph variant is exactly the specified text', () => {
38
+ test('the section is exactly the specified text', () => {
43
39
  const options = {};
44
- assert.equal(run(primaryEvent(options), { env: {}, hasCodegraph: present }), undefined);
45
- assert.equal(options.appendSystemPrompt, WITH_CODEGRAPH);
46
- });
47
-
48
- test('the variant without CodeGraph is exactly the specified text', () => {
49
- const options = {};
50
- run(primaryEvent(options), { env: {}, hasCodegraph: absent });
51
- assert.equal(options.appendSystemPrompt, WITHOUT_CODEGRAPH);
40
+ assert.equal(run(primaryEvent(options), { env: {} }), undefined);
41
+ assert.equal(options.appendSystemPrompt, SECTION);
52
42
  });
53
43
  });
54
44
 
@@ -56,21 +46,21 @@ describe('append-only injection', () => {
56
46
  test('existing harness text is preserved verbatim and the block follows it', () => {
57
47
  const harness = 'You are Pi.\n\nUse the tools.';
58
48
  const options = { appendSystemPrompt: harness };
59
- run(primaryEvent(options), { env: {}, hasCodegraph: absent });
49
+ run(primaryEvent(options), { env: {} });
60
50
  assert.ok(options.appendSystemPrompt.startsWith(harness), 'existing text is the prefix');
61
- assert.equal(options.appendSystemPrompt, `${harness}\n\n${WITHOUT_CODEGRAPH}`);
51
+ assert.equal(options.appendSystemPrompt, `${harness}\n\n${SECTION}`);
62
52
  });
63
53
 
64
54
  test('a trailing newline in the existing text keeps the separator minimal', () => {
65
55
  const harness = 'You are Pi.\n';
66
56
  const options = { appendSystemPrompt: harness };
67
- run(primaryEvent(options), { env: {}, hasCodegraph: absent });
68
- assert.equal(options.appendSystemPrompt, `${harness}\n${WITHOUT_CODEGRAPH}`);
57
+ run(primaryEvent(options), { env: {} });
58
+ assert.equal(options.appendSystemPrompt, `${harness}\n${SECTION}`);
69
59
  });
70
60
 
71
61
  test('never returns or assigns systemPrompt', () => {
72
62
  const event = { systemPromptOptions: {}, systemPrompt: 'harness-owned' };
73
- const returned = run(event, { env: {}, hasCodegraph: absent });
63
+ const returned = run(event, { env: {} });
74
64
  assert.equal(returned, undefined);
75
65
  assert.equal(event.systemPrompt, 'harness-owned');
76
66
  assert.ok(!('systemPrompt' in event.systemPromptOptions));
@@ -78,19 +68,11 @@ describe('append-only injection', () => {
78
68
 
79
69
  test('idempotent across two calls', () => {
80
70
  const options = {};
81
- run(primaryEvent(options), { env: {}, hasCodegraph: present });
71
+ run(primaryEvent(options), { env: {} });
82
72
  const once = options.appendSystemPrompt;
83
- run(primaryEvent(options), { env: {}, hasCodegraph: present });
73
+ run(primaryEvent(options), { env: {} });
84
74
  assert.equal(options.appendSystemPrompt, once);
85
- assert.equal(options.appendSystemPrompt, WITH_CODEGRAPH);
86
- });
87
-
88
- test('a variant switch mid-session never duplicates the heading', () => {
89
- const options = {};
90
- run(primaryEvent(options), { env: {}, hasCodegraph: absent });
91
- run(primaryEvent(options), { env: {}, hasCodegraph: present });
92
- const headings = options.appendSystemPrompt.split('## ODD worktrees').length - 1;
93
- assert.equal(headings, 1, 'the section is injected once, whatever the variant');
75
+ assert.equal(options.appendSystemPrompt, SECTION);
94
76
  });
95
77
  });
96
78
 
@@ -103,7 +85,7 @@ describe('session gating', () => {
103
85
  { name: 'worker', systemPromptOptions: {} },
104
86
  { subagent: { name: 'worker' }, systemPromptOptions: {} },
105
87
  ]) {
106
- run(event, { env: {}, hasCodegraph: present });
88
+ run(event, { env: {} });
107
89
  assert.equal(event.systemPromptOptions.appendSystemPrompt, undefined);
108
90
  }
109
91
  });
@@ -112,7 +94,7 @@ describe('session gating', () => {
112
94
  clearEnv();
113
95
  process.env.GENTLE_PI_AGENTS_CHILD = '1';
114
96
  const options = {};
115
- run(primaryEvent(options), { env: process.env, hasCodegraph: present });
97
+ run(primaryEvent(options), { env: process.env });
116
98
  assert.equal(options.appendSystemPrompt, undefined);
117
99
  });
118
100
 
@@ -120,14 +102,14 @@ describe('session gating', () => {
120
102
  clearEnv();
121
103
  process.env.ODD_WORKTREE_PROMPT = '0';
122
104
  const options = {};
123
- run(primaryEvent(options), { env: process.env, hasCodegraph: present });
105
+ run(primaryEvent(options), { env: process.env });
124
106
  assert.equal(options.appendSystemPrompt, undefined);
125
107
  });
126
108
 
127
109
  test('missing systemPromptOptions is a no-op that never throws', () => {
128
- assert.doesNotThrow(() => run({}, { env: {}, hasCodegraph: present }));
129
- assert.doesNotThrow(() => run(undefined, { env: {}, hasCodegraph: present }));
130
- assert.doesNotThrow(() => run({ systemPromptOptions: null }, { env: {}, hasCodegraph: present }));
110
+ assert.doesNotThrow(() => run({}, { env: {} }));
111
+ assert.doesNotThrow(() => run(undefined, { env: {} }));
112
+ assert.doesNotThrow(() => run({ systemPromptOptions: null }, { env: {} }));
131
113
  });
132
114
  });
133
115
 
@@ -137,41 +119,92 @@ describe('extension wiring (T3)', () => {
137
119
  const { loadExtension } = require('./fixtures/load-extension.js');
138
120
  const { hooks } = await loadExtension({});
139
121
  const handlers = hooks.filter(([name]) => name === 'before_agent_start').map(([, handler]) => handler);
140
- assert.equal(handlers.length, 1, 'exactly one before_agent_start handler');
122
+ assert.ok(handlers.length >= 1, 'the section has a before_agent_start handler');
141
123
  const options = {};
142
- await handlers[0]({ systemPromptOptions: options }, { cwd: os.tmpdir() });
143
- assert.ok(
144
- options.appendSystemPrompt === WITH_CODEGRAPH || options.appendSystemPrompt === WITHOUT_CODEGRAPH,
145
- 'the injected block is one of the two exact variants',
146
- );
147
- assert.doesNotThrow(() => handlers[0]({}, {}));
124
+ for (const handler of handlers) await handler({ systemPromptOptions: options }, { cwd: os.tmpdir() });
125
+ assert.equal(options.appendSystemPrompt, SECTION, 'the injected block is the one exact section, appended once');
126
+ for (const handler of handlers) assert.doesNotThrow(() => handler({}, {}));
148
127
  });
149
128
  });
150
129
 
151
130
  describe('the section is prose on disk', () => {
152
- test('both variants live in their own Markdown file and are what gets injected', () => {
153
- assert.ok(fs.existsSync(WITH_FILE), 'the CodeGraph variant file exists');
154
- assert.ok(fs.existsSync(WITHOUT_FILE), 'the plain variant file exists');
155
- assert.equal(prompt.WITH_CODEGRAPH, WITH_CODEGRAPH);
156
- assert.equal(prompt.WITHOUT_CODEGRAPH, WITHOUT_CODEGRAPH);
131
+ test('the section lives in its own Markdown file and is what gets injected', () => {
132
+ assert.ok(fs.existsSync(SECTION_FILE), 'the section file exists');
133
+ assert.equal(prompt.SECTION, SECTION);
157
134
  });
158
135
 
159
- test('each file opens with the section heading that makes injection idempotent', () => {
160
- for (const text of [WITH_CODEGRAPH, WITHOUT_CODEGRAPH]) {
161
- assert.ok(text.startsWith('## ODD worktrees'), text.split('\n')[0]);
162
- }
136
+ test('the file opens with the section heading that makes injection idempotent', () => {
137
+ assert.ok(SECTION.startsWith('## ODD worktrees'), SECTION.split('\n')[0]);
163
138
  });
164
139
 
165
- test('only the CodeGraph variant mentions CodeGraph', () => {
166
- assert.match(WITH_CODEGRAPH, /codegraph init/);
167
- assert.match(WITH_CODEGRAPH, /codegraph sync/);
168
- assert.doesNotMatch(WITHOUT_CODEGRAPH, /codegraph/i);
140
+ test('the one section promises no CodeGraph work', () => {
141
+ assert.doesNotMatch(SECTION, /codegraph/i);
169
142
  });
170
143
 
171
- test('neither variant instructs the agent to warp', () => {
172
- for (const text of [WITH_CODEGRAPH, WITHOUT_CODEGRAPH]) {
173
- assert.doesNotMatch(text, /worktree_warp/);
174
- assert.doesNotMatch(text, /move the session/i);
175
- }
144
+ test('the section states the checkout naming rule once, as the ODD', () => {
145
+ const prose = SECTION.replace(/\s+/g, ' ');
146
+ assert.equal(
147
+ SECTION.match(/<repo-parent>\/<repo-name>-worktrees\//g).length,
148
+ 1,
149
+ 'the destination is stated once',
150
+ );
151
+ assert.match(prose, /directory IS the ODD/);
152
+ assert.doesNotMatch(prose, /defaults to the branch/i);
153
+ assert.doesNotMatch(prose, /first segment/i);
154
+ assert.doesNotMatch(prose, /<name>/);
155
+ });
156
+
157
+ test('the section never instructs the agent to warp', () => {
158
+ assert.doesNotMatch(SECTION, /worktree_warp/);
159
+ assert.doesNotMatch(SECTION, /move the session/i);
160
+ });
161
+ });
162
+
163
+ // The policy the block states, in its five paragraphs.
164
+ describe('the section states the worktree policy', () => {
165
+ const prose = () => SECTION.replace(/\s+/g, ' ');
166
+
167
+ test('the work happens in the ODD\'s worktree, never in the primary checkout or on the default branch', () => {
168
+ const text = prose();
169
+ assert.match(text, /An ODD writes only in its own worktree, never in the primary checkout or on the default branch; the feature branch lives there/, text);
170
+ assert.match(text, /Reading anywhere is fine, and a request that stays read-only needs no worktree/, text);
171
+ // The rule is the premise: it opens the section, before the worktree is described.
172
+ assert.ok(text.indexOf('never in the primary checkout') < text.indexOf('A worktree lives at'), text);
173
+ });
174
+
175
+ test('a worktree is the ODD: find the assignment, resume it, create it, carry pending work', () => {
176
+ const text = prose();
177
+ assert.match(text, /A worktree lives at `/, text);
178
+ assert.match(text, /directory IS the ODD/, text);
179
+ assert.match(text, /Before the ODD's first write, call `worktree_list`/, text);
180
+ assert.match(text, /if it already has a worktree, work there/, text);
181
+ assert.match(text, /if not, create it with `worktree_create`/, text);
182
+ assert.match(text, /use `copy_changes: true` if the pending changes of the current checkout belong to that work/, text);
183
+ });
184
+
185
+ test('one ODD, one worktree', () => {
186
+ const text = prose();
187
+ assert.match(text, /One ODD, one worktree\./, text);
188
+ assert.match(text, /An ODD is one request and its follow-ups, big or small: everything that belongs to it goes into the same ODD and worktree/, text);
189
+ assert.match(text, /an unrelated request is another ODD with its own worktree/, text);
190
+ assert.doesNotMatch(text, /area of work/i, 'the unit is a request, never an area of the code');
191
+ });
192
+
193
+ test('independent units are delegated in parallel, each into the ODD\'s worktree, and never onto the same file', () => {
194
+ const text = prose();
195
+ assert.match(text, /Delegate an ODD's independent units of behavior to agents in parallel, each with the `workspace_root` of that ODD's worktree; the only limit is that two agents never edit the same file/, text);
196
+ assert.doesNotMatch(text, /same or different worktrees/, 'one ODD has one worktree, so the choice does not exist');
197
+ });
198
+
199
+ test('after the merge the default branch is always updated; only the removal waits for a dirty tree or a session standing there', () => {
200
+ const text = prose();
201
+ assert.match(text, /After the merge, update the default branch\. Then remove the worktree, keeping its branch, unless its tree is dirty or a session is standing in it/, text);
202
+ assert.doesNotMatch(text, /never remove/i);
203
+ });
204
+
205
+ // The rule only: no removal mechanism reaches the agent, because none is the
206
+ // agent's. This is the whole point of the paragraph.
207
+ test('the section names no removal mechanism', () => {
208
+ assert.doesNotMatch(SECTION, /ctrl\+d|git worktree remove|worktree_remove|\/warp/);
176
209
  });
177
210
  });