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.
- package/README.md +54 -311
- package/extensions/odd-worktree-tools.ts +4149 -2447
- package/lib/bash-activity.js +1164 -0
- package/lib/bash-design.js +684 -0
- package/lib/bash-destructive.js +559 -0
- package/lib/bash-frame.js +205 -0
- package/lib/card-content.js +23 -0
- package/lib/card-style.js +175 -0
- package/lib/checkout-facts.js +30 -70
- package/lib/codegraph-card-preview.js +628 -0
- package/lib/codegraph-card.js +515 -0
- package/lib/codegraph-compaction.js +76 -0
- package/lib/codegraph-daemon.js +246 -0
- package/lib/codegraph-edit-sync.js +182 -0
- package/lib/codegraph-guard-target.js +337 -0
- package/lib/codegraph-guard.js +211 -0
- package/lib/codegraph-index.js +1020 -0
- package/lib/codegraph-lock.js +607 -0
- package/lib/codegraph-mcp-config.js +134 -0
- package/lib/codegraph-mcp.js +123 -0
- package/lib/codegraph-paths.js +69 -0
- package/lib/codegraph-prompt/explore.md +11 -0
- package/lib/codegraph-prompt/fix.md +6 -0
- package/lib/codegraph-prompt/generic.md +8 -0
- package/lib/codegraph-prompt/judge.md +9 -0
- package/lib/codegraph-prompt/orchestrator.md +17 -0
- package/lib/codegraph-prompt/verify.md +10 -0
- package/lib/codegraph-prompt/worker.md +7 -0
- package/lib/codegraph-role.js +55 -0
- package/lib/codegraph-rules.js +146 -0
- package/lib/codegraph-session.js +303 -383
- package/lib/codegraph-warmup.js +139 -0
- package/lib/file-card-markdown.js +141 -0
- package/lib/file-card-resolver.js +245 -0
- package/lib/file-card.js +659 -0
- package/lib/files-index.js +387 -0
- package/lib/files-insert.js +81 -0
- package/lib/files-orders.js +326 -0
- package/lib/files-picker-view.js +1416 -0
- package/lib/files-preview.js +338 -0
- package/lib/files-scope-detail.js +171 -0
- package/lib/files-scope-view.js +507 -0
- package/lib/gh-issues.js +308 -14
- package/lib/issue-preview.js +26 -7
- package/lib/issues-bash-mutation.js +206 -0
- package/lib/issues-cache-store.js +261 -0
- package/lib/issues-section.js +710 -0
- package/lib/issues-view.js +649 -52
- package/lib/odd-prompt/odd-worktrees.md +21 -0
- package/lib/odd-worktrees-prompt.js +10 -28
- package/lib/related-issues-cache.js +210 -0
- package/lib/shell-card.js +825 -0
- package/lib/skill-odd-card.js +183 -0
- package/lib/tui-paint.js +4 -5
- package/lib/warp-create-panel.js +538 -250
- package/lib/warp-create-picker.js +56 -9
- package/lib/warp-delete-confirm.js +19 -28
- package/lib/warp-selector-view.js +160 -82
- package/lib/which-command.js +90 -0
- package/lib/worktree-card.js +267 -897
- package/lib/worktree-cards.js +383 -0
- package/lib/worktree-create.js +287 -0
- package/lib/worktree-git.js +3 -3
- package/lib/worktree-guard.js +548 -0
- package/lib/worktree-hooks.js +421 -711
- package/lib/worktree-list.js +120 -0
- package/lib/worktree-registry.js +162 -879
- package/lib/{worktree-close-herdr.js → worktree-remove.js} +9 -11
- package/lib/worktree-setup-runner.js +376 -0
- package/lib/worktree-setup.js +140 -0
- package/lib/worktree-warp-busy.js +462 -85
- package/lib/worktree-warp-sessions.js +1 -2
- package/package.json +2 -2
- package/tools/bash-activity.test.js +1419 -0
- package/tools/bash-design.test.js +1091 -0
- package/tools/bash-destructive.test.js +139 -0
- package/tools/card-content.test.js +44 -0
- package/tools/card-style.test.js +298 -0
- package/tools/codegraph-card-preview.test.js +254 -0
- package/tools/codegraph-card.test.js +1080 -0
- package/tools/codegraph-compaction.test.js +378 -0
- package/tools/codegraph-daemon.test.js +248 -0
- package/tools/codegraph-edit-sync.test.js +295 -0
- package/tools/codegraph-guard-target.test.js +174 -0
- package/tools/codegraph-guard.test.js +238 -0
- package/tools/codegraph-index.test.js +1948 -0
- package/tools/codegraph-lock.test.js +932 -0
- package/tools/codegraph-mcp-config.test.js +181 -0
- package/tools/codegraph-mcp.test.js +194 -0
- package/tools/codegraph-paths.test.js +44 -0
- package/tools/codegraph-role.test.js +30 -0
- package/tools/codegraph-rules.test.js +250 -0
- package/tools/codegraph-session.test.js +660 -391
- package/tools/codegraph-warmup.test.js +316 -0
- package/tools/commands.test.js +510 -31
- package/tools/file-card-markdown.test.js +188 -0
- package/tools/file-card.test.js +1289 -0
- package/tools/files-bridge.test.js +575 -0
- package/tools/files-command.test.js +610 -0
- package/tools/files-index.test.js +473 -0
- package/tools/files-insert.test.js +139 -0
- package/tools/files-orders.test.js +597 -0
- package/tools/files-picker-view.test.js +1871 -0
- package/tools/files-preview.test.js +452 -0
- package/tools/files-scope-detail.test.js +264 -0
- package/tools/files-scope-view.test.js +614 -0
- package/tools/fixtures/card-codegraph-outputs.js +110 -0
- package/tools/fixtures/codegraph-cli-stub.js +16 -0
- package/tools/fixtures/codegraph-init-process.js +28 -0
- package/tools/fixtures/codegraph-lock-worker.js +117 -0
- package/tools/fixtures/daemon-fake.js +98 -0
- package/tools/fixtures/daemon-mcp-server.js +39 -0
- package/tools/fixtures/daemon-warmup-worker.js +12 -0
- package/tools/fixtures/load-extension.js +136 -3
- package/tools/gh-issues-feedback.test.js +31 -7
- package/tools/gh-issues.test.js +391 -1
- package/tools/issue-preview.test.js +44 -7
- package/tools/issues-bash-mutation.test.js +101 -0
- package/tools/issues-cache-store.test.js +222 -0
- package/tools/issues-command.test.js +1512 -66
- package/tools/issues-open-guard.test.js +1096 -0
- package/tools/issues-section.test.js +4195 -0
- package/tools/issues-seed-query-regression.test.js +67 -0
- package/tools/issues-view.test.js +1489 -60
- package/tools/odd-worktrees-prompt.test.js +98 -65
- package/tools/package-surface.test.js +431 -36
- package/tools/related-issues-cache.test.js +324 -0
- package/tools/shell-card.test.js +834 -0
- package/tools/skill-odd-card.test.js +200 -0
- package/tools/t5-session-identity.test.js +44 -22
- package/tools/warp-busy-guard.test.js +2569 -308
- package/tools/warp-create-panel.test.js +499 -74
- package/tools/warp-create-picker.test.js +101 -5
- package/tools/warp-delete-confirm.test.js +49 -15
- package/tools/warp-empty-session.test.js +0 -1
- package/tools/warp-fallback-regression.test.js +533 -0
- package/tools/warp-selector-view.test.js +460 -196
- package/tools/which-command.test.js +126 -0
- package/tools/worktree-card.test.js +551 -0
- package/tools/worktree-cards.test.js +845 -0
- package/tools/worktree-changes.test.js +4 -5
- package/tools/worktree-create.test.js +489 -0
- package/tools/worktree-guard.test.js +823 -0
- package/tools/worktree-hooks.test.js +905 -0
- package/tools/worktree-list.test.js +170 -0
- package/tools/worktree-registry.test.js +89 -230
- package/tools/worktree-remove-async.test.js +318 -0
- package/tools/worktree-setup-runner.test.js +276 -0
- package/tools/worktree-setup.test.js +140 -0
- package/tools/worktree-tools.test.js +477 -93
- package/lib/codegraph-commands.js +0 -165
- package/lib/odd-prompt/odd-worktrees.with-codegraph.md +0 -19
- package/lib/odd-prompt/odd-worktrees.without-codegraph.md +0 -15
- package/lib/worktree-model-result.js +0 -291
- package/tools/codegraph-commands.test.js +0 -371
- package/tools/herdr-free-create.test.js +0 -161
- package/tools/worktree-close-herdr-async.test.js +0 -204
- package/tools/worktree-odd-migration.test.js +0 -224
- package/tools/worktree-registry-cache.test.js +0 -163
- package/tools/worktree-registry-odd.test.js +0 -231
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
//
|
|
3
|
-
// /issues plus the
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
2
|
+
// S4 surface: the standalone package always registers /warp, /odd, /files
|
|
3
|
+
// and /issues plus the TWO agent worktree tools (S3/S4: `worktree_delete` and
|
|
4
|
+
// `worktree_warp` are not registered, so `/warp` is the only front that moves
|
|
5
|
+
// the session and the panel's ctrl+d the only one that removes a checkout),
|
|
6
|
+
// loads in plain Pi with git as its only external dependency, and ships none of
|
|
7
|
+
// the removed functionality
|
|
8
|
+
// (customize panel, plugin-tools toggles, worktree mode file, perf tracing,
|
|
9
|
+
// CodeGraph commands, a CodeGraph gate or any CodeGraph probe or sync; the one
|
|
10
|
+
// CodeGraph touch is the append-only `## CodeGraph` prompt section).
|
|
8
11
|
// The issues reader, preview formatter and view are the migrated T2 units and
|
|
9
12
|
// are shipped; `/issues` is the T3 command that mounts them, without any
|
|
10
13
|
// worktree↔issue association.
|
|
11
14
|
//
|
|
15
|
+
// The bash activity is not a preference here: it is a design on gentle-shell-bridge's
|
|
16
|
+
// own `Card tools` line, so the shipped surface is exactly four commands, two tools, one
|
|
17
|
+
// sidebar section, one tools design and the one `Cards` row group the two file-card
|
|
18
|
+
// switches carry.
|
|
19
|
+
//
|
|
12
20
|
// Everything here reads the observable surface: the registered command and
|
|
13
21
|
// tool objects, the manifest, the files on disk. No internal state is read.
|
|
14
22
|
const { test, describe, after } = require('node:test');
|
|
15
23
|
const assert = require('node:assert/strict');
|
|
16
24
|
const fs = require('node:fs');
|
|
17
|
-
const os = require('node:os');
|
|
18
25
|
const path = require('node:path');
|
|
19
|
-
const { LIB_DIR,
|
|
26
|
+
const { LIB_DIR, loadExtension, stubbedSource } = require('./fixtures/load-extension.js');
|
|
20
27
|
|
|
21
28
|
const ROOT = path.resolve(__dirname, '..');
|
|
22
29
|
const PKG = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8'));
|
|
@@ -29,11 +36,6 @@ after(() => {
|
|
|
29
36
|
for (const [key, value] of Object.entries(savedEnv)) process.env[key] = value;
|
|
30
37
|
});
|
|
31
38
|
|
|
32
|
-
// A nonexistent absolute path is provably not a live Herdr binary, so the
|
|
33
|
-
// shared resolver returns it and every Herdr call fails instead of reaching a
|
|
34
|
-
// real workspace.
|
|
35
|
-
const NO_HERDR = path.join(os.tmpdir(), 'odd-worktree-no-such-herdr-binary');
|
|
36
|
-
|
|
37
39
|
describe('manifest', () => {
|
|
38
40
|
test('declares one Pi extension entry point and ships only that surface', () => {
|
|
39
41
|
assert.equal(PKG.name, 'pi-odd-worktree');
|
|
@@ -45,7 +47,7 @@ describe('manifest', () => {
|
|
|
45
47
|
assert.equal(PKG.peerDependencies['@earendil-works/pi-coding-agent'], '*');
|
|
46
48
|
assert.equal(PKG.peerDependencies['@earendil-works/pi-tui'], '*');
|
|
47
49
|
assert.ok(!('dependencies' in PKG), 'no runtime dependencies are installed');
|
|
48
|
-
assert.
|
|
50
|
+
assert.equal(/herdr/i.test(JSON.stringify(PKG)), false, 'the manifest claims no integration the package does not have');
|
|
49
51
|
});
|
|
50
52
|
|
|
51
53
|
test('ships no module for the removed commands', () => {
|
|
@@ -66,30 +68,94 @@ describe('manifest', () => {
|
|
|
66
68
|
// The issue reader, preview formatter and view are the migrated units (T2
|
|
67
69
|
// S1,S3): the per-tab cache is still gone, but the `gh` client, the
|
|
68
70
|
// formatter and the issues view `/issues` mounts are shipped, so their
|
|
69
|
-
// presence is asserted rather than forbidden.
|
|
70
|
-
|
|
71
|
+
// presence is asserted rather than forbidden. The bash drawing is the
|
|
72
|
+
// classifier and the one design registered on the bridge. The file cards add
|
|
73
|
+
// their own four modules — a classifier, the card, its resolver and the document
|
|
74
|
+
// body Pi's Markdown draws — and own no preference at all (S1): they are gated by
|
|
75
|
+
// the bridge's `Card tools` line, which is the bridge's, not ours.
|
|
76
|
+
for (const kept of ['gh-issues.js', 'issue-preview.js', 'issues-view.js', 'warp-selector-view.js', 'odd-view.js', 'worktree-git.js', 'worktree-registry.js', 'worktree-session-guard.js', 'bash-activity.js', 'bash-design.js', 'bash-frame.js', 'skill-odd-card.js', 'file-card.js', 'file-card-resolver.js', 'file-card-markdown.js']) {
|
|
71
77
|
assert.ok(shipped.includes(kept), `lib/${kept} is shipped`);
|
|
72
78
|
}
|
|
79
|
+
for (const gone of ['card-files-mode.js', 'cards-customize.js']) {
|
|
80
|
+
assert.equal(shipped.includes(gone), false, `lib/${gone} is gone (S1)`);
|
|
81
|
+
}
|
|
73
82
|
});
|
|
74
83
|
});
|
|
75
84
|
|
|
76
85
|
describe('registration', () => {
|
|
77
|
-
test('registers /warp, /odd
|
|
78
|
-
process.env.HERDR_BIN_PATH = NO_HERDR;
|
|
86
|
+
test('registers /warp, /odd, /files, /issues and the two worktree tools', async () => {
|
|
79
87
|
delete process.env.GENTLE_WORKTREE_THREAD;
|
|
80
88
|
const { commands, tools, messageRenderers } = await loadExtension({});
|
|
81
89
|
const registered = [...commands.keys()].sort();
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
for (const name of base) assert.ok(registered.includes(name), `/${name} is registered`);
|
|
85
|
-
// S9: the codegraph triple is gated on the CLI, never on anything else.
|
|
86
|
-
const { hasCodegraph } = require('../lib/codegraph-session.js');
|
|
87
|
-
const expected = hasCodegraph(process.env) ? [...base, ...codegraph].sort() : base;
|
|
88
|
-
assert.deepEqual(registered, expected, 'the command list is the base three plus the codegraph triple exactly when the CLI is present');
|
|
89
|
-
assert.deepEqual([...tools.keys()].sort(), ['worktree_create', 'worktree_delete', 'worktree_list', 'worktree_warp']);
|
|
90
|
+
assert.deepEqual(registered, ['files', 'issues', 'odd', 'warp'], 'the command list is exactly the four panels');
|
|
91
|
+
assert.deepEqual([...tools.keys()].sort(), ['worktree_create', 'worktree_list'], 'exactly two agent tools');
|
|
90
92
|
assert.deepEqual([...messageRenderers.keys()], ['worktree-warp']);
|
|
91
93
|
});
|
|
92
94
|
|
|
95
|
+
// The bash activity is a design on the bridge's own line, not a preference. The
|
|
96
|
+
// two file-card switches ARE preferences of this package: one strict document in
|
|
97
|
+
// the Pi home for the pair, whose only control is the customize row group
|
|
98
|
+
// contributed through the bridge API (asserted below), never a command of ours.
|
|
99
|
+
test('the bash activity is a design, and this package owns no switch of its own', async () => {
|
|
100
|
+
const source = stubbedSource();
|
|
101
|
+
assert.ok(source.includes('libRequire("bash-design.js")'), 'the design reaches the bridge through its published API');
|
|
102
|
+
assert.equal(source.includes('registerCommand("card:bash"'), false, 'the design has no command name');
|
|
103
|
+
const lib = path.join(ROOT, 'lib');
|
|
104
|
+
for (const gone of ['card-bash-mode.js', 'card-bash-customize.js', 'bash-card.js', 'bash-card-resolver.js']) {
|
|
105
|
+
assert.equal(fs.existsSync(path.join(lib, gone)), false, `lib/${gone} is gone`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// S1: the two file-card switches and their document are gone, and the extension
|
|
109
|
+
// names neither. The file card is gated by the bridge's own `Card tools` line.
|
|
110
|
+
assert.equal(source.includes('registerCardsCustomize'), false, 'no row provider is registered for a switch');
|
|
111
|
+
assert.equal(source.includes('card-files'), false, 'the extension never names their document');
|
|
112
|
+
const modules = fs.readdirSync(lib).filter((entry) => entry.endsWith('.js'));
|
|
113
|
+
const writers = modules.filter((entry) => /writeCardFileSwitch\b/.test(fs.readFileSync(path.join(lib, entry), 'utf8')));
|
|
114
|
+
assert.deepEqual(writers, [], 'no module writes a card-file switch any more');
|
|
115
|
+
const { commands } = await loadExtension({});
|
|
116
|
+
assert.equal(commands.has('card:bash'), false, 'no /card:bash command is registered');
|
|
117
|
+
for (const gone of ['card-style', 'card-bash', 'card-skill', 'card-odd', 'customize', 'worktree-mode']) {
|
|
118
|
+
assert.equal(commands.has(gone), false, `no /${gone} command`);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('the bridge is never imported, and the surface reaches it through its published object', () => {
|
|
123
|
+
const source = stubbedSource();
|
|
124
|
+
assert.equal(/from\s+["']gentle-shell-bridge/.test(source), false, 'no import of the bridge package anywhere');
|
|
125
|
+
assert.equal(/require\(\s*["']gentle-shell-bridge/.test(source), false, 'no require of the bridge package anywhere');
|
|
126
|
+
assert.equal(source.split('api.registerSection(').length - 1, 1, 'exactly one sidebar section is contributed');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('the bash design is wired through exactly one registration and adds no name', async () => {
|
|
130
|
+
const source = stubbedSource();
|
|
131
|
+
assert.equal(source.split('design.registerBashDesign(').length - 1, 1, 'one registration call');
|
|
132
|
+
assert.equal(source.includes('registerBashCard'), false, 'no resolver of ours draws bash');
|
|
133
|
+
const { commands, tools } = await loadExtension({});
|
|
134
|
+
for (const gone of ['bash-card', 'card-bash', 'bash']) {
|
|
135
|
+
assert.equal(commands.has(gone), false, `the design adds no /${gone} command`);
|
|
136
|
+
assert.equal(tools.has(gone), false, `the design adds no ${gone} tool`);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('the file cards register through one hook call and own no preference (T2)', async () => {
|
|
141
|
+
// S1/S7: the card is drawn through the host's `registerToolRenderer`, and the ONE switch
|
|
142
|
+
// it obeys is the bridge's own line, asked through the published reader on every paint.
|
|
143
|
+
// Nothing of ours is registered for it: no command, no tool, no row provider, no store.
|
|
144
|
+
const source = stubbedSource();
|
|
145
|
+
const lines = source.split('\n').map((line) => line.trim());
|
|
146
|
+
assert.deepEqual(
|
|
147
|
+
lines.filter((line) => line.includes('registerFileCard(')),
|
|
148
|
+
['libRequire("file-card-resolver.js").registerFileCard(pi, { metrics: () => resolveWorktreeToolCardMetrics() });'],
|
|
149
|
+
'the file card is wired through exactly one call',
|
|
150
|
+
);
|
|
151
|
+
assert.equal(source.includes('registerCardsCustomize'), false, 'and no switch provider is wired at all');
|
|
152
|
+
const { commands, tools } = await loadExtension({});
|
|
153
|
+
for (const gone of ['file-card', 'card-skill', 'card-odd']) {
|
|
154
|
+
assert.equal(commands.has(gone), false, `the card adds no /${gone} command`);
|
|
155
|
+
assert.equal(tools.has(gone), false, `the card adds no ${gone} tool`);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
93
159
|
test('every tool keeps its declared name and description', async () => {
|
|
94
160
|
const { tools } = await loadExtension({});
|
|
95
161
|
const summary = (name) => {
|
|
@@ -98,18 +164,20 @@ describe('registration', () => {
|
|
|
98
164
|
};
|
|
99
165
|
assert.deepEqual(summary('worktree_create'), { name: 'worktree_create', label: 'Worktree Create' });
|
|
100
166
|
assert.deepEqual(summary('worktree_list'), { name: 'worktree_list', label: 'Worktree List' });
|
|
101
|
-
assert.deepEqual(summary('worktree_delete'), { name: 'worktree_delete', label: 'Worktree Delete' });
|
|
102
|
-
assert.deepEqual(summary('worktree_warp'), { name: 'worktree_warp', label: 'Worktree Warp' });
|
|
103
167
|
});
|
|
104
168
|
|
|
105
|
-
|
|
169
|
+
// S3/S4: neither removal nor warp is an agent surface any more, so nothing the
|
|
170
|
+
// model can call names them. The guard they both used still refuses a live
|
|
171
|
+
// session (tools/worktree-tools.test.js), and the panel still discloses its
|
|
172
|
+
// caveats (tools/warp-delete-confirm.test.js) — those are the surviving checks.
|
|
173
|
+
test('no tool deletes a checkout or moves the session', async () => {
|
|
106
174
|
const { tools } = await loadExtension({});
|
|
107
|
-
|
|
108
|
-
assert.
|
|
109
|
-
|
|
110
|
-
assert.
|
|
111
|
-
assert.equal(/
|
|
112
|
-
assert.
|
|
175
|
+
assert.equal(tools.has('worktree_delete'), false, 'no delete tool is registered');
|
|
176
|
+
assert.equal(tools.has('worktree_warp'), false, 'no warp tool is registered');
|
|
177
|
+
const source = stubbedSource();
|
|
178
|
+
assert.equal(/registerTool\(worktreeCloseTool\)/.test(source), false, 'the close tool stays unregistered');
|
|
179
|
+
assert.equal(/registerTool\(worktreeWarpTool\)/.test(source), false, 'the warp tool stays unregistered');
|
|
180
|
+
assert.equal(/herdr/i.test(source), false, 'no Herdr workspace removal is promised anywhere');
|
|
113
181
|
});
|
|
114
182
|
});
|
|
115
183
|
|
|
@@ -125,6 +193,87 @@ describe('removed surface', () => {
|
|
|
125
193
|
}
|
|
126
194
|
});
|
|
127
195
|
|
|
196
|
+
test('CodeGraph is wired through one registration and adds no command or tool (S2)', async () => {
|
|
197
|
+
const source = stubbedSource();
|
|
198
|
+
// The extension mentions CodeGraph only to require the prompt section and the one registration.
|
|
199
|
+
const mentions = source.split('\n').filter((line) => /codegraph/i.test(line.replace(/\/\/.*$/, '')));
|
|
200
|
+
assert.deepEqual(
|
|
201
|
+
mentions.map((line) => line.trim()),
|
|
202
|
+
['libRequire("codegraph-rules.js").appendCodegraphSection(event);', 'libRequire("codegraph-session.js").registerCodegraph(pi, { metrics: () => resolveWorktreeToolCardMetrics() });'],
|
|
203
|
+
'the only CodeGraph references in the extension are the prompt section and the one registration',
|
|
204
|
+
);
|
|
205
|
+
const { commands, tools } = await loadExtension({});
|
|
206
|
+
for (const gone of ['codegraph-hook', 'codegraph-init', 'codegraph-sync', 'codegraph']) {
|
|
207
|
+
assert.equal(commands.has(gone), false, `no /${gone} command`);
|
|
208
|
+
assert.equal(tools.has(gone), false, `no ${gone} tool`);
|
|
209
|
+
}
|
|
210
|
+
assert.deepEqual([...tools.keys()].sort(), ['worktree_create', 'worktree_list'], 'the model-facing tools are still exactly the two');
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test('both worktree tools frame their own card, so the host draws no filled box under it', async () => {
|
|
214
|
+
const { tools } = await loadExtension({});
|
|
215
|
+
for (const name of ['worktree_create', 'worktree_list']) {
|
|
216
|
+
assert.equal(tools.get(name).renderShell, 'self', `${name} declares renderShell: self`);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test('worktree_create takes an optional base branch, and only that tool does', async () => {
|
|
221
|
+
const { tools } = await loadExtension({});
|
|
222
|
+
const create = tools.get('worktree_create').parameters;
|
|
223
|
+
assert.ok(create.properties.base, 'worktree_create has a base parameter');
|
|
224
|
+
// The host's schema builder is a shim in this harness, so optionality is read where it is
|
|
225
|
+
// declared: `base` goes through `opt(...)` like `copy_changes`, `odd` and `branch` do not.
|
|
226
|
+
const source = fs.readFileSync(path.join(ROOT, 'extensions', 'odd-worktree-tools.ts'), 'utf8');
|
|
227
|
+
assert.match(source, /\n base: opt\(Type\.String\(/, 'base is optional: nothing changes without it');
|
|
228
|
+
assert.doesNotMatch(source, /\n (odd|branch): opt\(/, 'odd and branch stay required');
|
|
229
|
+
assert.match(tools.get('worktree_create').description, /`base`/, 'the description names it');
|
|
230
|
+
assert.equal('base' in tools.get('worktree_list').parameters.properties, false, 'worktree_list is untouched');
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test('the CodeGraph modules are a closed list with narrow powers (S1, S2)', () => {
|
|
234
|
+
const lib = path.join(ROOT, 'lib');
|
|
235
|
+
const shipped = fs.readdirSync(lib).filter((entry) => /^codegraph-/.test(entry)).sort();
|
|
236
|
+
const allowed = [
|
|
237
|
+
'codegraph-card-preview.js', 'codegraph-card.js', 'codegraph-compaction.js', 'codegraph-daemon.js',
|
|
238
|
+
'codegraph-edit-sync.js', 'codegraph-guard-target.js', 'codegraph-guard.js', 'codegraph-index.js',
|
|
239
|
+
'codegraph-lock.js', 'codegraph-mcp-config.js', 'codegraph-mcp.js', 'codegraph-paths.js', 'codegraph-prompt',
|
|
240
|
+
'codegraph-role.js', 'codegraph-rules.js', 'codegraph-session.js', 'codegraph-warmup.js',
|
|
241
|
+
];
|
|
242
|
+
for (const entry of shipped) assert.ok(allowed.includes(entry), `lib/${entry} is not an allowed CodeGraph module`);
|
|
243
|
+
const read = (name) => fs.readFileSync(path.join(lib, name), 'utf8');
|
|
244
|
+
// Code only: a comment may say what a module does not do.
|
|
245
|
+
const code = (name) => read(name).replace(/\/\*[\s\S]*?\*\//g, '').replace(/^\s*\/\/.*$/gm, '');
|
|
246
|
+
for (const entry of shipped.filter((name) => name.endsWith('.js'))) {
|
|
247
|
+
const text = code(entry);
|
|
248
|
+
for (const blocked of ['spawnSync', 'execSync', 'execFileSync']) {
|
|
249
|
+
assert.equal(text.includes(blocked), false, `${entry} never uses ${blocked}`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// The prompt section only advises: it runs, probes and writes nothing.
|
|
253
|
+
const rules = code('codegraph-rules.js');
|
|
254
|
+
for (const forbidden of ['spawn', 'exec(', 'execFile', 'child_process', 'writeFile', 'codegraph.db']) {
|
|
255
|
+
assert.equal(rules.includes(forbidden), false, `the prompt section module never uses ${forbidden}`);
|
|
256
|
+
}
|
|
257
|
+
// The user's MCP configuration has exactly one writer, and it touches only its own entry.
|
|
258
|
+
for (const entry of shipped.filter((name) => name.endsWith('.js') && name !== 'codegraph-mcp-config.js')) {
|
|
259
|
+
assert.equal(/mcp\.json/.test(read(entry).replace(/\/\/.*$/gm, '')) && /writeFile|rename\(/.test(read(entry)), false, `${entry} does not write mcp.json`);
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test('the two reminders advise only: one text, no surface, no child of their own', () => {
|
|
264
|
+
const lib = path.join(ROOT, 'lib');
|
|
265
|
+
const read = (name) => fs.readFileSync(path.join(lib, name), 'utf8');
|
|
266
|
+
const code = (name) => read(name).replace(/\/\*[\s\S]*?\*\//g, '').replace(/^\s*\/\/.*$/gm, '');
|
|
267
|
+
for (const entry of ['codegraph-guard.js', 'codegraph-guard-target.js']) {
|
|
268
|
+
const text = code(entry);
|
|
269
|
+
for (const forbidden of ['registerTool', 'registerCommand', 'ui.notify', 'writeFile', 'appendFile', 'rename(', 'child_process', 'spawn']) {
|
|
270
|
+
assert.equal(text.includes(forbidden), false, `${entry} never does ${forbidden}: a reminder is one text on a result`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
// The git toplevel is the ONE child, and it is the async bounded runner the edit sync already owns.
|
|
274
|
+
assert.ok(code('codegraph-guard-target.js').includes("require('./codegraph-edit-sync.js')"), 'the target reuses the bounded git read');
|
|
275
|
+
});
|
|
276
|
+
|
|
128
277
|
test('the /issues command keeps its migrated client and view', () => {
|
|
129
278
|
const source = stubbedSource();
|
|
130
279
|
assert.ok(source.includes('pi.registerCommand("issues"'), 'the /issues command is registered');
|
|
@@ -135,7 +284,9 @@ describe('removed surface', () => {
|
|
|
135
284
|
|
|
136
285
|
test('the loaded extension holds no reference to the removed packages', async () => {
|
|
137
286
|
const { commands } = await loadExtension({});
|
|
138
|
-
|
|
287
|
+
// `odd` is NOT in this list any more: it is the odd viewer's own name now. What must
|
|
288
|
+
// never come back is the customize panel and the Herdr worktree panel.
|
|
289
|
+
for (const gone of ['customize', 'herdr-gentle:warp']) {
|
|
139
290
|
assert.equal(commands.has(gone), false, `no /${gone} command`);
|
|
140
291
|
}
|
|
141
292
|
assert.equal(commands.has('issues'), true, '/issues is the migrated command');
|
|
@@ -148,3 +299,247 @@ describe('removed surface', () => {
|
|
|
148
299
|
}
|
|
149
300
|
});
|
|
150
301
|
});
|
|
302
|
+
|
|
303
|
+
// ---- how the extension loads its own lib/ modules ----
|
|
304
|
+
//
|
|
305
|
+
// Pi loads an extension with jiti `moduleCache: false`
|
|
306
|
+
// (`@earendil-works/pi-coding-agent` dist/core/extensions/loader.js:
|
|
307
|
+
// `createJitiImpl(import.meta.url, { moduleCache: false, ... })`), so the
|
|
308
|
+
// extension file is re-read on every load. Node's own require cache is a
|
|
309
|
+
// different cache and it outlives a load, so a reloaded extension used to run
|
|
310
|
+
// against the lib modules of the FIRST load. These cases prove the observable
|
|
311
|
+
// half of that: a module rewritten on disk is seen by the NEXT load, and only by
|
|
312
|
+
// the next load.
|
|
313
|
+
const os = require('node:os');
|
|
314
|
+
const { pathToFileURL } = require('node:url');
|
|
315
|
+
|
|
316
|
+
const scratchDirs = [];
|
|
317
|
+
after(() => {
|
|
318
|
+
for (const dir of scratchDirs) {
|
|
319
|
+
try { fs.rmSync(dir, { recursive: true, force: true }); } catch { /* best effort */ }
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
function scratch(prefix) {
|
|
324
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
325
|
+
scratchDirs.push(dir);
|
|
326
|
+
return dir;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// The listing module this test rewrites: nothing else of the tool is replaced, so
|
|
330
|
+
// what the assertion reads is the module on disk, reached through the public tool.
|
|
331
|
+
const listingProbe = (marker) => [
|
|
332
|
+
"'use strict';",
|
|
333
|
+
`const MARKER = ${JSON.stringify(marker)};`,
|
|
334
|
+
'module.exports = {',
|
|
335
|
+
' worktreeListView: () => ({ text: MARKER, details: { worktrees: [], hiddenOutside: 0 } }),',
|
|
336
|
+
'};',
|
|
337
|
+
'',
|
|
338
|
+
].join('\n');
|
|
339
|
+
|
|
340
|
+
// The git seam the list reads, faked so this case spawns no child: a repository
|
|
341
|
+
// root and one main checkout are all `worktree_list` needs to reach the view.
|
|
342
|
+
const gitStub = (root) => [
|
|
343
|
+
"'use strict';",
|
|
344
|
+
`const ROOT = ${JSON.stringify(root)};`,
|
|
345
|
+
'module.exports = {',
|
|
346
|
+
' runArgvAsync: async () => ({ status: 1, stdout: "", stderr: "" }),',
|
|
347
|
+
' repoIdentityAsync: async () => ({ root: ROOT }),',
|
|
348
|
+
' listWorktreesAsync: async () => [{ path: ROOT, branch: "main", head: "1a2b3c4" }],',
|
|
349
|
+
'};',
|
|
350
|
+
'',
|
|
351
|
+
].join('\n');
|
|
352
|
+
|
|
353
|
+
/** Register an already-imported extension module against a fake host and hand back what the host received. */
|
|
354
|
+
async function registered(copy) {
|
|
355
|
+
const mod = await import(pathToFileURL(copy).href);
|
|
356
|
+
const tools = new Map();
|
|
357
|
+
const messageRenderers = new Map();
|
|
358
|
+
const hooks = [];
|
|
359
|
+
mod.default({
|
|
360
|
+
registerCommand: () => {},
|
|
361
|
+
registerTool: (tool) => { tools.set(tool.name, tool); },
|
|
362
|
+
registerMessageRenderer: (type, renderer) => { messageRenderers.set(type, renderer); },
|
|
363
|
+
on: (event, handler) => { hooks.push([event, handler]); },
|
|
364
|
+
});
|
|
365
|
+
return { mod, tools, messageRenderers, hooks };
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** Load the extension against `libDir`, exactly as the host loads it: a fresh module each time. */
|
|
369
|
+
async function loadFromLibDir(libDir) {
|
|
370
|
+
process.env.GENTLE_WORKTREE_LIB_DIR = libDir;
|
|
371
|
+
const copy = path.join(scratch('odd-ext-load-'), 'odd-worktree-tools.mjs');
|
|
372
|
+
fs.writeFileSync(copy, stubbedSource());
|
|
373
|
+
return registered(copy);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const listText = async (tools, cwd) => {
|
|
377
|
+
const result = await tools.get('worktree_list').execute('probe', {}, undefined, undefined, { cwd });
|
|
378
|
+
assert.notEqual(result.isError, true, JSON.stringify(result));
|
|
379
|
+
return result.content.map((part) => part.text).join('');
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
describe('the extension loads its lib modules once per load', () => {
|
|
383
|
+
const savedLibDir = process.env.GENTLE_WORKTREE_LIB_DIR;
|
|
384
|
+
after(() => {
|
|
385
|
+
if (savedLibDir === undefined) delete process.env.GENTLE_WORKTREE_LIB_DIR;
|
|
386
|
+
else process.env.GENTLE_WORKTREE_LIB_DIR = savedLibDir;
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
test('a rewritten module is seen by the next extension load, and only by it', async () => {
|
|
390
|
+
const libDir = path.join(scratch('odd-lib-fresh-'), 'lib');
|
|
391
|
+
fs.cpSync(LIB_DIR, libDir, { recursive: true });
|
|
392
|
+
const root = fs.realpathSync(scratch('odd-lib-root-'));
|
|
393
|
+
fs.writeFileSync(path.join(libDir, 'worktree-git.js'), gitStub(root));
|
|
394
|
+
fs.writeFileSync(path.join(libDir, 'worktree-list.js'), listingProbe('probe: first'));
|
|
395
|
+
|
|
396
|
+
const first = await loadFromLibDir(libDir);
|
|
397
|
+
assert.equal(await listText(first.tools, root), 'probe: first', 'the first load reads the module on disk');
|
|
398
|
+
|
|
399
|
+
fs.writeFileSync(path.join(libDir, 'worktree-list.js'), listingProbe('probe: second'));
|
|
400
|
+
|
|
401
|
+
assert.equal(await listText(first.tools, root), 'probe: first', 'one load reads its lib modules once, never again per call');
|
|
402
|
+
|
|
403
|
+
const second = await loadFromLibDir(libDir);
|
|
404
|
+
assert.notEqual(second.mod, first.mod, 'a load is a new extension instance');
|
|
405
|
+
assert.equal(await listText(second.tools, root), 'probe: second', 'a reloaded extension runs the NEW module, not the one the first load cached');
|
|
406
|
+
assert.equal(await listText(second.tools, root), 'probe: second', 'and it keeps reading it for its whole lifetime');
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
test('with no override the extension reads the lib/ beside itself', async () => {
|
|
410
|
+
// The production layout: <pkg>/extensions/<entry> with <pkg>/lib beside it, and
|
|
411
|
+
// no GENTLE_WORKTREE_LIB_DIR set at all.
|
|
412
|
+
const pkg = scratch('odd-pkg-');
|
|
413
|
+
fs.mkdirSync(path.join(pkg, 'extensions'));
|
|
414
|
+
fs.cpSync(LIB_DIR, path.join(pkg, 'lib'), { recursive: true });
|
|
415
|
+
const copy = path.join(pkg, 'extensions', 'odd-worktree-tools.mjs');
|
|
416
|
+
fs.writeFileSync(copy, stubbedSource());
|
|
417
|
+
delete process.env.GENTLE_WORKTREE_LIB_DIR;
|
|
418
|
+
const { tools } = await registered(copy);
|
|
419
|
+
// A directory outside any repository is refused by the READ module, so the
|
|
420
|
+
// answer proves the package's own lib directory resolved to real modules.
|
|
421
|
+
const loose = fs.realpathSync(scratch('odd-lib-loose-'));
|
|
422
|
+
const result = await tools.get('worktree_list').execute('probe', {}, undefined, undefined, { cwd: loose });
|
|
423
|
+
assert.equal(result.isError, true);
|
|
424
|
+
assert.equal(result.content.map((part) => part.text).join(''), `not a git repository: ${loose}`);
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
// ---- the click seam, wired end to end ----
|
|
429
|
+
//
|
|
430
|
+
// pi-tui's alternate screen delivers a click only to the component that claimed
|
|
431
|
+
// the press, and the component it reaches is the one the host put in the
|
|
432
|
+
// transcript — the card the render hook returned. A click moves the card it hit
|
|
433
|
+
// and NOTHING else: expansion is resolved per row from the row's own state, so
|
|
434
|
+
// these cases drive the registered surfaces with two cards at a time and assert
|
|
435
|
+
// which one repainted and which one expanded. `ctrl+o`, the host's own
|
|
436
|
+
// session-wide flag, still expands every card and is never written by a click.
|
|
437
|
+
const probeMetrics = {
|
|
438
|
+
visibleWidth: (value) => [...value.replace(/\u001B\[[0-9;]*m/g, '')].length,
|
|
439
|
+
truncateToWidth: (value, width, ellipsis = '') => {
|
|
440
|
+
const text = value.replace(/\u001B\[[0-9;]*m/g, '');
|
|
441
|
+
if (width <= 0) return '';
|
|
442
|
+
if ([...text].length <= width) return value;
|
|
443
|
+
return `${[...text].slice(0, Math.max(0, width - [...String(ellipsis ?? '')].length)).join('')}${String(ellipsis ?? '')}`;
|
|
444
|
+
},
|
|
445
|
+
wrapTextWithAnsi: (value, width) => {
|
|
446
|
+
const text = value.replace(/\u001B\[[0-9;]*m/g, '');
|
|
447
|
+
if (width <= 0) return [text];
|
|
448
|
+
const rows = [];
|
|
449
|
+
const chars = [...text];
|
|
450
|
+
while (chars.length > width) rows.push(chars.splice(0, width).join(''));
|
|
451
|
+
rows.push(chars.join(''));
|
|
452
|
+
return rows;
|
|
453
|
+
},
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
const probeTheme = { fg: (_role, value) => value };
|
|
457
|
+
|
|
458
|
+
function mouse(component, rows, type, x = 3, y = 0) {
|
|
459
|
+
return component.handleMouse({
|
|
460
|
+
type,
|
|
461
|
+
button: 'left',
|
|
462
|
+
x,
|
|
463
|
+
y,
|
|
464
|
+
width: 60,
|
|
465
|
+
height: rows.length,
|
|
466
|
+
screenX: x,
|
|
467
|
+
screenY: y,
|
|
468
|
+
shift: false,
|
|
469
|
+
alt: false,
|
|
470
|
+
ctrl: false,
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const probeText = (label) => [1, 2, 3, 4, 5, 6, 7, 8].map((line) => `${label} line ${line}`).join('\n');
|
|
475
|
+
const probeResult = (label) => ({ content: [{ type: 'text', text: probeText(label) }], details: {} });
|
|
476
|
+
|
|
477
|
+
/** One tool row as the host drives it: one state per execution, a fresh context per render. */
|
|
478
|
+
function toolRow(tool, label, expanded = false) {
|
|
479
|
+
const state = {};
|
|
480
|
+
const counter = { invalidations: 0 };
|
|
481
|
+
const build = (hostExpanded) => tool.renderResult(probeResult(label), { expanded: hostExpanded, isPartial: false }, probeTheme, {
|
|
482
|
+
isPartial: false,
|
|
483
|
+
expanded: hostExpanded,
|
|
484
|
+
state,
|
|
485
|
+
invalidate: () => { counter.invalidations += 1; },
|
|
486
|
+
});
|
|
487
|
+
const component = build(expanded);
|
|
488
|
+
const rows = component.render(60);
|
|
489
|
+
return {
|
|
490
|
+
component,
|
|
491
|
+
rows,
|
|
492
|
+
counter,
|
|
493
|
+
click: (x = 2, y = 0) => mouse(component, rows, 'click', x, y),
|
|
494
|
+
press: (x = 2, y = 0) => mouse(component, rows, 'press', x, y),
|
|
495
|
+
repaint: () => build(expanded).render(60),
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
describe('a click expands only the card it hit', () => {
|
|
500
|
+
test('one tool card expands, its sibling is untouched, and the host flag is never written', async () => {
|
|
501
|
+
const { mod, tools } = await loadFromLibDir(LIB_DIR);
|
|
502
|
+
try {
|
|
503
|
+
mod.setWorktreeToolCardMetrics(probeMetrics);
|
|
504
|
+
const clicked = toolRow(tools.get('worktree_create'), 'clicked');
|
|
505
|
+
const sibling = toolRow(tools.get('worktree_list'), 'sibling');
|
|
506
|
+
assert.ok(clicked.rows.length > 2 && sibling.rows.length > 2, 'both cards draw a body');
|
|
507
|
+
|
|
508
|
+
assert.deepEqual(clicked.press(2, 0), { handled: true, render: false }, 'the press claims the card so the host retargets the click');
|
|
509
|
+
assert.deepEqual(clicked.click(2, 0), { handled: true }, 'the click on the card is handled');
|
|
510
|
+
assert.equal(clicked.counter.invalidations, 1, 'the click repaints the card it hit');
|
|
511
|
+
assert.equal(sibling.counter.invalidations, 0, 'the sibling card is not repainted');
|
|
512
|
+
|
|
513
|
+
assert.ok(clicked.repaint().length > clicked.rows.length, 'the clicked card is expanded');
|
|
514
|
+
assert.deepEqual(sibling.repaint(), sibling.rows, 'the sibling card stays exactly as it was');
|
|
515
|
+
} finally {
|
|
516
|
+
mod.setWorktreeToolCardMetrics(undefined);
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
test('the warp confirmation card expands by itself and leaves another warp card collapsed', async () => {
|
|
521
|
+
const { messageRenderers } = await loadFromLibDir(LIB_DIR);
|
|
522
|
+
const warp = messageRenderers.get('worktree-warp');
|
|
523
|
+
const message = { customType: 'worktree-warp', content: 'session warped', details: { fromName: 'feat-one', name: 'feat-two', to: '/clone-worktrees/feat-two', branch: 'feat/two' } };
|
|
524
|
+
const other = { customType: 'worktree-warp', content: 'session warped', details: { fromName: 'feat-two', name: 'feat-three', to: '/clone-worktrees/feat-three', branch: 'feat/three' } };
|
|
525
|
+
|
|
526
|
+
const card = warp(message, {}, probeTheme);
|
|
527
|
+
const rows = card.render(60);
|
|
528
|
+
const sibling = warp(other, {}, probeTheme);
|
|
529
|
+
const siblingRows = sibling.render(60);
|
|
530
|
+
|
|
531
|
+
assert.deepEqual(mouse(card, rows, 'press', 3, 0), { handled: true, render: false }, 'the press claims the card');
|
|
532
|
+
assert.deepEqual(mouse(card, rows, 'click', 3, 0), { handled: true }, 'the click is handled');
|
|
533
|
+
const expanded = card.render(60);
|
|
534
|
+
assert.ok(expanded.length > rows.length, 'the clicked warp card is expanded');
|
|
535
|
+
assert.ok(expanded.some((row) => row.includes('/clone-worktrees/feat-two')), 'and shows its own path');
|
|
536
|
+
assert.deepEqual(sibling.render(60), siblingRows, 'the sibling warp card is untouched');
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
test('no click reaches for the session-wide expansion flag', () => {
|
|
540
|
+
const source = fs.readFileSync(path.join(ROOT, 'extensions', 'odd-worktree-tools.ts'), 'utf8');
|
|
541
|
+
for (const name of ['getToolsExpanded', 'setToolsExpanded']) {
|
|
542
|
+
assert.equal(source.includes(name), false, `${name} is not on a click path: one click moves one card, and ctrl+o stays the global one`);
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
});
|