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
@@ -0,0 +1,200 @@
1
+ 'use strict';
2
+ // T1 (S1): which file a read/edit/write call names, and what the card that heads as
3
+ // it says — the pure classification lib/file-card.js will draw. Only the module's
4
+ // public surface is asserted: the identity a path wears, the file's name, whether it
5
+ // is Markdown, the line range only a read states, and the document a call draws.
6
+ //
7
+ // Paths are components, never substrings, so `lib/skillset/x.ts` is an ordinary file;
8
+ // both separators read alike, so a Windows path classifies exactly like a POSIX one. The
9
+ // convention is the FOLDER: everything below a `skills` folder is that skill and
10
+ // everything below an `odd` folder is an ODD artifact, whatever the file is called.
11
+ const { test } = require('node:test');
12
+ const assert = require('node:assert/strict');
13
+ const {
14
+ FILE_CARD_IDENTITY,
15
+ ODD_FILE_CARD,
16
+ SKILL_FILE_CARD,
17
+ fileCardIdentity,
18
+ fileCardLineRange,
19
+ fileCardName,
20
+ fileCardSkillPath,
21
+ isMarkdownFile,
22
+ markdownDocumentSource,
23
+ } = require('../lib/skill-odd-card.js');
24
+
25
+ const identity = (path) => fileCardIdentity(path)?.identity;
26
+
27
+ // A skill is EVERYTHING a `skills` folder holds: its document, its references, its
28
+ // scripts. The skill is the folder, so a reference file belongs to the skill it serves.
29
+ test('any file below a skills folder is a skill', () => {
30
+ for (const path of [
31
+ 'skills/gentle-ai/SKILL.md',
32
+ 'skills/gentle-ai/references/commands.md',
33
+ 'skills/gentle-ai/references/deep/x.txt',
34
+ 'packages/gentle/skills/tdd/SKILL.md',
35
+ 'skills/tdd/references/SKILL.md',
36
+ 'skills/tdd/skill.md',
37
+ 'skills/tdd/notes.md',
38
+ 'Skills/tdd/references/chain.md',
39
+ 'C:\\repo\\skills\\tdd\\SKILL.md',
40
+ 'C:\\repo\\skills\\tdd\\references\\commands.md',
41
+ '\\\\server\\share\\skills\\tdd\\SKILL.md',
42
+ ]) {
43
+ assert.equal(identity(path), FILE_CARD_IDENTITY.SKILL, path);
44
+ assert.equal(fileCardIdentity(path), SKILL_FILE_CARD, path);
45
+ }
46
+ });
47
+
48
+ // The same convention for ODD: the folder decides, not the file's own name nor its depth.
49
+ test('any file below an odd folder is an ODD artifact', () => {
50
+ for (const path of [
51
+ 'odd/tasks/checkout.md',
52
+ 'odd/tasks/checkout/design.md',
53
+ 'odd/tasks/checkout/references/readme.txt',
54
+ 'odd/work/a.md',
55
+ 'odd/design.md',
56
+ 'odd/tasks.md',
57
+ 'src/odd/tasks/design.md',
58
+ 'C:\\repo\\odd\\tasks\\design.md',
59
+ 'C:\\repo\\odd\\work\\design.md',
60
+ '\\\\server\\share\\odd\\tasks\\design.md',
61
+ ]) {
62
+ assert.equal(identity(path), FILE_CARD_IDENTITY.ODD, path);
63
+ assert.equal(fileCardIdentity(path), ODD_FILE_CARD, path);
64
+ }
65
+ });
66
+
67
+ // A path can name both kinds, and then the marker closest to the file decides.
68
+ test('a path both rules name is judged by the marker closest to the file', () => {
69
+ assert.equal(identity('odd/tasks/skills/tdd/SKILL.md'), FILE_CARD_IDENTITY.SKILL);
70
+ assert.equal(identity('odd/tasks/skills/tdd/notes.md'), FILE_CARD_IDENTITY.SKILL);
71
+ assert.equal(identity('skills/pack/odd/tasks/SKILL.md'), FILE_CARD_IDENTITY.ODD);
72
+ assert.equal(identity('odd/tasks/skills/x/SKILL.md'), FILE_CARD_IDENTITY.SKILL);
73
+ });
74
+
75
+ // Every other file wears nothing, because a folder name is never a substring.
76
+ test('every other file wears no card identity', () => {
77
+ for (const path of [
78
+ 'lib/skillset/x.ts',
79
+ 'lib/my-skills/notes.md',
80
+ 'lib/odd-work/notes.md',
81
+ 'odd-work/notes.md',
82
+ 'docs/oddity.md',
83
+ 'docs/odd',
84
+ 'docs/readme.md',
85
+ 'docs/tasks.md.bak',
86
+ 'skills.md',
87
+ 'SKILL.md',
88
+ '/home/dev/repo/SKILL.md',
89
+ 'docs/SKILL.md',
90
+ 'lib/x.ts',
91
+ ]) {
92
+ assert.equal(fileCardIdentity(path), undefined, path);
93
+ }
94
+ });
95
+
96
+ // Nothing to classify is not an error.
97
+ test('a non-string or an empty path is nothing, not an error', () => {
98
+ for (const path of [undefined, null, 42, {}, [], '', '/', 'C:\\']) {
99
+ assert.equal(fileCardIdentity(path), undefined, String(path));
100
+ }
101
+ assert.equal(fileCardIdentity(), undefined);
102
+ });
103
+
104
+ // Each kind ships its own label, mark and theme role; the roles are the theme's to paint.
105
+ test('each identity carries its own label, mark and theme role', () => {
106
+ assert.deepEqual(FILE_CARD_IDENTITY, { SKILL: 'skill', ODD: 'odd' });
107
+ assert.deepEqual(SKILL_FILE_CARD, { identity: 'skill', title: 'skill', glyph: '▤', titleRole: 'mdHeading' });
108
+ assert.deepEqual(ODD_FILE_CARD, { identity: 'odd', title: 'odd', glyph: '📑', titleRole: 'mdHeading' });
109
+ for (const value of [FILE_CARD_IDENTITY, SKILL_FILE_CARD, ODD_FILE_CARD]) assert.ok(Object.isFrozen(value));
110
+ // BOTH headings wear the theme's own heading role, never a status color.
111
+ for (const card of [SKILL_FILE_CARD, ODD_FILE_CARD]) {
112
+ for (const role of ['warning', 'error', 'success', 'toolTitle']) assert.notEqual(card.titleRole, role, role);
113
+ }
114
+ });
115
+
116
+ // The file's own name is the last component on either separator, and nothing else.
117
+ test('the collapsed heading can name the file itself', () => {
118
+ assert.equal(fileCardName('odd/work/design.md'), 'design.md');
119
+ assert.equal(fileCardName('C:\\repo\\odd\\work\\design.md'), 'design.md');
120
+ assert.equal(fileCardName('odd/my design doc.md'), 'my design doc.md');
121
+ assert.equal(fileCardName('odd/work/'), 'work', 'a trailing separator names no empty file');
122
+ assert.equal(fileCardName('design.md'), 'design.md');
123
+ // A drive with no file after it still names its last component, and never a blank.
124
+ assert.equal(fileCardName('C:\\'), 'C:');
125
+ // Nothing to name is nothing, never an invented file.
126
+ for (const value of ['', '/', undefined, null, 7]) assert.equal(fileCardName(value), '', String(value));
127
+ });
128
+
129
+ // A skill's collapsed heading names the path from the skill's own folder down, however
130
+ // deep the file sits: the folders above `skills` are what a reader already knows.
131
+ test('a skill card can name its path from its skill folder down', () => {
132
+ assert.equal(fileCardSkillPath('/x/skills/gentle-ai/SKILL.md'), 'gentle-ai/SKILL.md');
133
+ assert.equal(fileCardSkillPath('/x/skills/gentle-ai/references/chain.md'), 'gentle-ai/references/chain.md');
134
+ assert.equal(fileCardSkillPath('/x/skills/gentle-ai/references/deep/x.md'), 'gentle-ai/references/deep/x.md');
135
+ // Both separators are read, so a Windows path names the same components.
136
+ assert.equal(fileCardSkillPath('C:\\repo\\skills\\tdd\\SKILL.md'), 'tdd/SKILL.md');
137
+ assert.equal(fileCardSkillPath('\\\\server\\share\\skills\\tdd\\references\\chain.md'), 'tdd/references/chain.md');
138
+ // The folder is a component, never a substring, and any case reads alike.
139
+ assert.equal(fileCardSkillPath('Skills/one/SKILL.md'), 'one/SKILL.md');
140
+ // A path with no `skills` folder names its file, exactly as the collapsed heading did.
141
+ for (const path of ['docs/readme.md', 'C:\\repo\\docs\\readme.md', 'lib/skillset/x.ts', 'design.md', 'skills']) {
142
+ assert.equal(fileCardSkillPath(path), fileCardName(path), path);
143
+ }
144
+ // Nothing to name is nothing, never an invented path.
145
+ for (const value of ['', '/', undefined, null, 7]) assert.equal(fileCardSkillPath(value), '', String(value));
146
+ });
147
+
148
+ // Markdown is the shape a document is written in: the extension, and the extension alone.
149
+ test('only a .md file is a Markdown file', () => {
150
+ for (const path of ['skills/a/SKILL.md', 'odd/work/a.md', 'odd/work/a.MD', 'C:\\repo\\odd\\a.Md']) {
151
+ assert.equal(isMarkdownFile(path), true, path);
152
+ }
153
+ for (const path of ['skills/a/notes.markdown', 'odd/work/a.md.bak', 'lib/x.ts', 'a.md/x.ts', '', '/', undefined, 7]) {
154
+ assert.equal(isMarkdownFile(path), false, String(path));
155
+ }
156
+ });
157
+
158
+ // Only a read states a line range, and a range it cannot read states nothing.
159
+ test('a read names the line range it asked for, and no other tool states one', () => {
160
+ assert.equal(fileCardLineRange('read', { path: 'a.md', offset: 142, limit: 4 }), ':142-145');
161
+ assert.equal(fileCardLineRange('read', { path: 'a.md', limit: 4 }), ':1-4');
162
+ assert.equal(fileCardLineRange('read', { path: 'a.md', offset: 5 }), ':5');
163
+ assert.equal(fileCardLineRange('read', { path: 'a.md' }), undefined);
164
+ assert.equal(fileCardLineRange('read', { path: 'a.md', offset: 2, limit: 1 }), ':2-2');
165
+ // Half a range is never guessed at: a malformed offset or limit states nothing.
166
+ assert.equal(fileCardLineRange('read', { offset: '2', limit: 3 }), undefined);
167
+ assert.equal(fileCardLineRange('read', { offset: 2, limit: 3.5 }), undefined);
168
+ assert.equal(fileCardLineRange('read', { offset: 0, limit: 2 }), undefined);
169
+ assert.equal(fileCardLineRange('read', { offset: 2, limit: 0 }), undefined);
170
+ assert.equal(fileCardLineRange('read', { offset: 2, limit: -1 }), undefined);
171
+ // A write and an edit know how many lines they write, never where those lines land.
172
+ assert.equal(fileCardLineRange('write', { path: 'a.md', content: 'one\ntwo' }), undefined);
173
+ assert.equal(fileCardLineRange('edit', { path: 'a.md', oldText: 'a', newText: 'b' }), undefined);
174
+ assert.equal(fileCardLineRange('grep', { path: 'a.md', limit: 2 }), undefined);
175
+ assert.equal(fileCardLineRange('read', undefined), undefined);
176
+ });
177
+
178
+ // A Markdown document is drawn as a document only when expanded and successful; a read
179
+ // draws what it returned, a write what its call carried, and nothing to draw keeps the rows.
180
+ test('only an expanded, successful read or write of a Markdown file draws a document', () => {
181
+ const markdown = '## Handoff\n\nBody.';
182
+ const draw = (tool, args, result, options = {}) =>
183
+ markdownDocumentSource(tool, args, result, { expanded: true, ...options });
184
+ assert.equal(draw('read', { path: 'docs/a.md' }, markdown), markdown);
185
+ assert.equal(draw('write', { path: 'docs/a.md', content: markdown }, 'Successfully wrote 20 bytes'), markdown);
186
+ // Collapsed, failed, non-Markdown and every other tool keep their rows.
187
+ assert.equal(draw('read', { path: 'docs/a.md' }, markdown, { expanded: false }), undefined);
188
+ assert.equal(draw('read', { path: 'docs/a.md' }, markdown, { isError: true }), undefined);
189
+ assert.equal(draw('write', { path: 'docs/a.md', content: markdown }, 'ok', { isError: true }), undefined);
190
+ assert.equal(draw('edit', { path: 'docs/a.md', oldText: 'a', newText: markdown }, 'Applied'), undefined);
191
+ assert.equal(draw('grep', { path: 'docs/a.md' }, markdown), undefined);
192
+ assert.equal(draw('read', { path: 'docs/a.txt' }, markdown), undefined);
193
+ assert.equal(draw('write', { path: 'lib/x.ts', content: markdown }, 'ok'), undefined);
194
+ // Nothing to draw is not a document: an empty body keeps the result it has.
195
+ assert.equal(draw('read', { path: 'docs/a.md' }, ''), undefined);
196
+ assert.equal(draw('read', { path: 'docs/a.md' }, ' \n\n'), undefined);
197
+ assert.equal(draw('write', { path: 'docs/a.md', content: '' }, 'Successfully wrote 0 bytes'), undefined);
198
+ assert.equal(draw('write', { path: 'docs/a.md' }, 'Successfully wrote 0 bytes'), undefined);
199
+ assert.equal(draw('read', undefined, markdown), undefined);
200
+ });
@@ -14,8 +14,9 @@
14
14
  // names that session. Nothing else may: no label, no prefix, no saved history.
15
15
  //
16
16
  // These cases are written against the PUBLIC surfaces only — the two exported
17
- // guard functions and the registered `worktree_delete` tool — so they keep
18
- // working if internals move. Every fixture is a throwaway repository and agent
17
+ // guard functions and the extension's exported `executeWorktreeClose` (the seam
18
+ // the warp panel's ctrl+d drives; the `worktree_delete` tool is unregistered,
19
+ // T6/S4) — so they keep working if internals move. Every fixture is a throwaway repository and agent
19
20
  // home under the system temp directory; no real worktree, presence store or
20
21
  // session is touched.
21
22
 
@@ -26,7 +27,8 @@ const fs = require('node:fs');
26
27
  const os = require('node:os');
27
28
  const path = require('node:path');
28
29
  const { spawnSync } = require('node:child_process');
29
- const { loadExtension } = require('./fixtures/load-extension.js');
30
+ const { pathToFileURL } = require('node:url');
31
+ const { LIB_DIR, loadExtension, stubbedSource } = require('./fixtures/load-extension.js');
30
32
 
31
33
  const guard = require('../lib/worktree-session-guard.js');
32
34
 
@@ -191,23 +193,38 @@ describe('S7 identity join: hash -> raw session id', () => {
191
193
  });
192
194
  });
193
195
 
194
- describe('S7 identity join through the registered tool', () => {
196
+ describe('S7 identity join through the removal the panel drives', () => {
195
197
  const savedEnv = { ...process.env };
196
- const NO_HERDR = path.join(os.tmpdir(), 't5-identity-no-such-herdr');
197
198
  const HOOK_BIN = track(fs.mkdtempSync(path.join(os.tmpdir(), 't5-identity-hookbin-')));
198
- fs.writeFileSync(path.join(HOOK_BIN, 'codegraph'), '#!/bin/sh\nexit 0\n', { mode: 0o755 });
199
199
  const AGENT_HOME = agentHome();
200
200
 
201
201
  let tools;
202
+ let mod;
202
203
  before(async () => {
203
- process.env.HERDR_BIN_PATH = NO_HERDR;
204
204
  process.env.GENTLE_WORKTREE_THREAD = 't5-thread';
205
205
  delete process.env.GENTLE_PI_AGENT_HOME;
206
206
  process.env.PI_CODING_AGENT_DIR = AGENT_HOME;
207
207
  process.env.PATH = `${HOOK_BIN}${path.delimiter}${process.env.PATH || ''}`;
208
208
  ({ tools } = await loadExtension({}));
209
+ mod = await loadStubbedModule();
209
210
  });
210
211
 
212
+ // The removal these refusals are observed through is the extension module's
213
+ // exported close — the seam the warp panel's ctrl+d drives. The
214
+ // `worktree_delete` TOOL that used to wrap it is unregistered (T6/S4), so the
215
+ // namespace is loaded beside the registrations: same stubs, same lib override.
216
+ async function loadStubbedModule() {
217
+ process.env.GENTLE_WORKTREE_LIB_DIR = LIB_DIR;
218
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 't5-identity-mod-'));
219
+ try {
220
+ const copy = path.join(dir, 'odd-worktree-tools.mjs');
221
+ fs.writeFileSync(copy, stubbedSource());
222
+ return await import(pathToFileURL(copy).href);
223
+ } finally {
224
+ fs.rmSync(dir, { recursive: true, force: true });
225
+ }
226
+ }
227
+
211
228
  after(() => {
212
229
  for (const key of Object.keys(process.env)) {
213
230
  if (!(key in savedEnv)) delete process.env[key];
@@ -246,16 +263,16 @@ describe('S7 identity join through the registered tool', () => {
246
263
  return (result.content || []).map((part) => (part && part.text) || '').join('\n');
247
264
  }
248
265
 
249
- test('the tool refusal shows the raw id and leaves the checkout, branch and registry intact', async () => {
266
+ test('the refusal shows the raw id and leaves the checkout, branch and registry intact', async () => {
250
267
  const repo = makeRepo('joined');
251
268
  const ctx = makeCtx(repo);
252
- const created = await tools.get('worktree_create').execute('t5-c1', { branch: 'feat/t5-joined', changes: 'none' }, undefined, undefined, ctx);
269
+ const created = await tools.get('worktree_create').execute('t5-c1', { branch: 'feat/t5-joined', odd: 't5-joined' }, undefined, undefined, ctx);
253
270
  assert.notEqual(created.isError, true, resultText(created));
254
- const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'feat-t5-joined');
271
+ const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 't5-joined');
255
272
  const sessionHash = publishPresence(AGENT_HOME, { sessionId: 'raw-session-7', label: 'Worker', workspace: target, heartbeat: Date.now(), incarnationIndex: 4 });
256
273
  publishTransport(AGENT_HOME, { sessionId: 'raw-session-7' });
257
274
 
258
- const closed = await tools.get('worktree_delete').execute('t5-c2', { name: 'feat-t5-joined' }, undefined, undefined, ctx);
275
+ const closed = await mod.executeWorktreeClose({ name: 'feat-t5-joined' }, ctx);
259
276
  assert.equal(closed.isError, true);
260
277
  const text = resultText(closed);
261
278
  assert.ok(text.includes('id raw-session-7'), text);
@@ -267,17 +284,17 @@ describe('S7 identity join through the registered tool', () => {
267
284
  assert.ok(git(repo, ['worktree', 'list', '--porcelain']).includes(target), 'git still lists it');
268
285
  assert.ok(git(repo, ['branch', '--format=%(refname:short)']).split('\n').includes('feat/t5-joined'), 'the branch survives');
269
286
  const listed = await tools.get('worktree_list').execute('t5-c3', {}, undefined, undefined, ctx);
270
- assert.equal(resultText(listed).split('\n').length, 3, 'the registry row survives');
287
+ assert.equal(resultText(listed).split('\n').length, 4, 'the registry row survives');
271
288
  });
272
289
 
273
- test('the tool refusal discloses an unresolved id instead of inventing one', async () => {
290
+ test('the refusal discloses an unresolved id instead of inventing one', async () => {
274
291
  const repo = makeRepo('unjoined');
275
292
  const ctx = makeCtx(repo);
276
- await tools.get('worktree_create').execute('t5-c4', { branch: 'feat/t5-unjoined', changes: 'none' }, undefined, undefined, ctx);
277
- const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'feat-t5-unjoined');
293
+ await tools.get('worktree_create').execute('t5-c4', { branch: 'feat/t5-unjoined', odd: 't5-unjoined' }, undefined, undefined, ctx);
294
+ const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 't5-unjoined');
278
295
  const sessionHash = publishPresence(AGENT_HOME, { sessionId: 'raw-session-8', label: 'Worker', workspace: target, heartbeat: Date.now(), incarnationIndex: 5 });
279
296
 
280
- const closed = await tools.get('worktree_delete').execute('t5-c5', { name: 'feat-t5-unjoined' }, undefined, undefined, ctx);
297
+ const closed = await mod.executeWorktreeClose({ name: 'feat-t5-unjoined' }, ctx);
281
298
  assert.equal(closed.isError, true);
282
299
  const text = resultText(closed);
283
300
  assert.ok(text.includes(`presence ${sessionHash.slice(0, 12)}`), text);
@@ -289,18 +306,23 @@ describe('S7 identity join through the registered tool', () => {
289
306
  test('the clear path shows the best-effort notices and still removes the checkout', async () => {
290
307
  const repo = makeRepo('notices');
291
308
  const ctx = makeCtx(repo);
292
- await tools.get('worktree_create').execute('t5-c6', { branch: 'feat/t5-notice', changes: 'none' }, undefined, undefined, ctx);
293
- const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'feat-t5-notice');
309
+ await tools.get('worktree_create').execute('t5-c6', { branch: 'feat/t5-notice', odd: 't5-notice' }, undefined, undefined, ctx);
310
+ const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 't5-notice');
294
311
  // A live peer whose discovery sidecar never published a workspace: it can
295
312
  // never be attributed to this checkout, and it must never block.
296
313
  publishPresence(AGENT_HOME, { sessionId: 'legacy-peer', label: 'Legacy', heartbeat: Date.now(), incarnationIndex: 6, discovery: false });
297
314
 
298
- const closed = await tools.get('worktree_delete').execute('t5-c7', { name: 'feat-t5-notice' }, undefined, undefined, ctx);
315
+ const closed = await mod.executeWorktreeClose({ name: 'feat-t5-notice' }, ctx);
299
316
  assert.notEqual(closed.isError, true, resultText(closed));
300
- const text = resultText(closed);
301
- assert.match(text, /published no workspace/);
302
- assert.match(text, /best effort/);
303
317
  assert.ok(Array.isArray(closed.details.warnings) && closed.details.warnings.length > 0, 'the notice travels in details');
318
+ assert.ok(
319
+ closed.details.warnings.some((warning) => /published no workspace/.test(warning)),
320
+ JSON.stringify(closed.details.warnings),
321
+ );
322
+ assert.ok(
323
+ closed.details.warnings.every((warning) => /best effort/.test(warning)),
324
+ `every caveat is disclosed as best effort: ${JSON.stringify(closed.details.warnings)}`,
325
+ );
304
326
  assert.equal(fs.existsSync(target), false, 'the notice never blocks the removal');
305
327
  });
306
328
  });