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
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// T3 (issues-startup-perf S4): lib/issues-cache-store.js — the DISK half of the
|
|
3
|
+
// issues read cache.
|
|
4
|
+
//
|
|
5
|
+
// Contract under test, through the public surface only (`load`, `save`,
|
|
6
|
+
// `directory`):
|
|
7
|
+
// - ONE small versioned JSON document holds an entry per repository identity,
|
|
8
|
+
// keyed exactly like `lib/related-issues-cache.js` keys its own entries, and
|
|
9
|
+
// under `$XDG_CACHE_HOME/odd-worktree/` (falling back to
|
|
10
|
+
// `~/.cache/odd-worktree/`);
|
|
11
|
+
// - an entry round-trips: the three bucket rows, `counts`, `truncated`,
|
|
12
|
+
// `inconsistent`, `fullAt`, `syncedAt` and `lastApplied`;
|
|
13
|
+
// - `fullAt` moves only on a FULL apply, exactly like the in-memory cache;
|
|
14
|
+
// - the document is bounded: the oldest identities are dropped past a small cap;
|
|
15
|
+
// - every failure is silence, never an exception and never a half-written
|
|
16
|
+
// document: a malformed document, a wrong version, a hostile entry, an
|
|
17
|
+
// unreadable directory, a failed atomic write and a machine with no home all
|
|
18
|
+
// answer `null`/`false`;
|
|
19
|
+
// - the write is atomic: a temp file in the same directory and a rename, so a
|
|
20
|
+
// failure leaves the previous document exactly as it was.
|
|
21
|
+
//
|
|
22
|
+
// The `fs` seam and the directory are injected, so nothing here touches a real
|
|
23
|
+
// cache directory and every temp tree lives under os.tmpdir() and is removed.
|
|
24
|
+
|
|
25
|
+
const { test, after } = require('node:test');
|
|
26
|
+
const assert = require('node:assert/strict');
|
|
27
|
+
const fs = require('node:fs');
|
|
28
|
+
const os = require('node:os');
|
|
29
|
+
const path = require('node:path');
|
|
30
|
+
|
|
31
|
+
const { createIssuesCacheStore } = require('../lib/issues-cache-store.js');
|
|
32
|
+
|
|
33
|
+
const FILE = 'issues-cache.json';
|
|
34
|
+
const IDENTITY = 'github.com/myfork/project';
|
|
35
|
+
const OTHER = 'github.com/myfork/other';
|
|
36
|
+
|
|
37
|
+
const roots = [];
|
|
38
|
+
after(() => {
|
|
39
|
+
for (const dir of roots) {
|
|
40
|
+
try { fs.rmSync(dir, { recursive: true, force: true }); } catch {}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
function tempDir(tag = 'store') {
|
|
45
|
+
const dir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), `odd-issues-${tag}-`)));
|
|
46
|
+
roots.push(dir);
|
|
47
|
+
return dir;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function row(number, extra = {}) {
|
|
51
|
+
return { number, title: `Issue ${number}`, updatedAt: '2024-01-01T00:00:00Z', state: 'OPEN', ...extra };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// What the loader hands over after a successful apply: the three bucket rows from
|
|
55
|
+
// the cache plus the facts only the loader and its response know.
|
|
56
|
+
function snapshot(overrides = {}) {
|
|
57
|
+
return {
|
|
58
|
+
buckets: { mine: [row(1)], assigned: [row(2), row(3)], involved: [] },
|
|
59
|
+
counts: { mine: 1, assigned: 2, involved: 0 },
|
|
60
|
+
truncated: { mine: false, assigned: false, involved: false },
|
|
61
|
+
inconsistent: false,
|
|
62
|
+
full: true,
|
|
63
|
+
syncedAt: 1000,
|
|
64
|
+
lastApplied: 4,
|
|
65
|
+
...overrides,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function documentAt(dir) {
|
|
70
|
+
return JSON.parse(fs.readFileSync(path.join(dir, FILE), 'utf8'));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function store(dir, extra = {}) {
|
|
74
|
+
return createIssuesCacheStore({ dir, env: {}, ...extra });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
test('S4: an entry round-trips through ONE small versioned document', async () => {
|
|
78
|
+
const dir = tempDir('store-roundtrip');
|
|
79
|
+
const cache = store(dir);
|
|
80
|
+
assert.equal(await cache.save(IDENTITY, snapshot()), true);
|
|
81
|
+
|
|
82
|
+
const entry = await cache.load(IDENTITY);
|
|
83
|
+
assert.ok(entry, 'the entry the save wrote is the entry the load answers');
|
|
84
|
+
assert.deepEqual(entry.buckets.mine.map((item) => item.number), [1]);
|
|
85
|
+
assert.deepEqual(entry.buckets.assigned.map((item) => item.number), [2, 3]);
|
|
86
|
+
assert.deepEqual(entry.buckets.involved, []);
|
|
87
|
+
assert.equal(entry.buckets.assigned[0].title, 'Issue 2', 'the row itself survives, not just its number');
|
|
88
|
+
assert.deepEqual(entry.counts, { mine: 1, assigned: 2, involved: 0 });
|
|
89
|
+
assert.deepEqual(entry.truncated, { mine: false, assigned: false, involved: false });
|
|
90
|
+
assert.equal(entry.inconsistent, false);
|
|
91
|
+
assert.equal(entry.fullAt, 1000, 'a full apply stamps fullAt');
|
|
92
|
+
assert.equal(entry.syncedAt, 1000);
|
|
93
|
+
assert.equal(entry.lastApplied, 4);
|
|
94
|
+
|
|
95
|
+
assert.deepEqual(fs.readdirSync(dir), [FILE], 'exactly one document, no stray file');
|
|
96
|
+
const doc = documentAt(dir);
|
|
97
|
+
assert.equal(doc.version, 1, 'the document is versioned');
|
|
98
|
+
assert.equal(doc.identities.length, 1);
|
|
99
|
+
assert.equal(doc.identities[0].identity, IDENTITY, 'the entry is keyed by the repository identity');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('S4: a delta keeps the stored fullAt, a full apply moves it', async () => {
|
|
103
|
+
const dir = tempDir('store-full-at');
|
|
104
|
+
const cache = store(dir);
|
|
105
|
+
await cache.save(IDENTITY, snapshot({ full: true, syncedAt: 1000, lastApplied: 1 }));
|
|
106
|
+
await cache.save(IDENTITY, snapshot({ full: false, syncedAt: 5000, lastApplied: 2 }));
|
|
107
|
+
|
|
108
|
+
const entry = await cache.load(IDENTITY);
|
|
109
|
+
assert.equal(entry.fullAt, 1000, 'a steady stream of deltas never postpones the full re-read');
|
|
110
|
+
assert.equal(entry.syncedAt, 5000, 'the sync time moves with every apply');
|
|
111
|
+
assert.equal(entry.lastApplied, 2);
|
|
112
|
+
|
|
113
|
+
await cache.save(IDENTITY, snapshot({ full: true, syncedAt: 9000, lastApplied: 3 }));
|
|
114
|
+
assert.equal((await cache.load(IDENTITY)).fullAt, 9000, 'a full apply moves it');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('S4: the document lives under $XDG_CACHE_HOME, else under the injected home', async () => {
|
|
118
|
+
const base = tempDir('store-xdg');
|
|
119
|
+
const fromXdg = createIssuesCacheStore({ env: { XDG_CACHE_HOME: base } });
|
|
120
|
+
assert.equal(fromXdg.directory(), path.join(base, 'odd-worktree'));
|
|
121
|
+
await fromXdg.save(IDENTITY, snapshot());
|
|
122
|
+
assert.ok(fs.existsSync(path.join(base, 'odd-worktree', FILE)), 'the document is inside the XDG directory');
|
|
123
|
+
|
|
124
|
+
const home = tempDir('store-home');
|
|
125
|
+
const fromHome = createIssuesCacheStore({ env: {}, home });
|
|
126
|
+
assert.equal(fromHome.directory(), path.join(home, '.cache', 'odd-worktree'),
|
|
127
|
+
'a machine without XDG falls back to ~/.cache');
|
|
128
|
+
await fromHome.save(IDENTITY, snapshot());
|
|
129
|
+
assert.ok(fs.existsSync(path.join(home, '.cache', 'odd-worktree', FILE)));
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('S4: the document is bounded — the oldest identities are dropped past the cap', async () => {
|
|
133
|
+
const dir = tempDir('store-bound');
|
|
134
|
+
const cache = store(dir);
|
|
135
|
+
for (let index = 1; index <= 9; index += 1) {
|
|
136
|
+
await cache.save(`github.com/myfork/project-${index}`, snapshot({ syncedAt: index }));
|
|
137
|
+
}
|
|
138
|
+
assert.equal(await cache.load('github.com/myfork/project-1'), null, 'the oldest identity is gone');
|
|
139
|
+
for (let index = 2; index <= 9; index += 1) {
|
|
140
|
+
assert.ok(await cache.load(`github.com/myfork/project-${index}`), `identity ${index} is kept`);
|
|
141
|
+
}
|
|
142
|
+
assert.equal(documentAt(dir).identities.length, 8, 'the document holds eight identities at most');
|
|
143
|
+
|
|
144
|
+
// Re-saving an identity moves it to the newest end, so it outlives a later save.
|
|
145
|
+
await cache.save('github.com/myfork/project-2', snapshot({ syncedAt: 20 }));
|
|
146
|
+
await cache.save('github.com/myfork/project-10', snapshot({ syncedAt: 10 }));
|
|
147
|
+
assert.ok(await cache.load('github.com/myfork/project-2'), 'a refreshed identity is the newest, not the oldest');
|
|
148
|
+
assert.equal(await cache.load('github.com/myfork/project-3'), null, 'and the identity that was oldest goes');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('S4: a malformed document is silence, and the next save replaces it', async () => {
|
|
152
|
+
const dir = tempDir('store-malformed');
|
|
153
|
+
fs.writeFileSync(path.join(dir, FILE), '{ this is not json');
|
|
154
|
+
const cache = store(dir);
|
|
155
|
+
assert.equal(await cache.load(IDENTITY), null, 'a document that does not parse answers nothing');
|
|
156
|
+
assert.equal(await cache.save(IDENTITY, snapshot()), true);
|
|
157
|
+
assert.ok(await cache.load(IDENTITY));
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('S4: a wrong version is silence, and the next save writes the current one', async () => {
|
|
161
|
+
const dir = tempDir('store-version');
|
|
162
|
+
fs.writeFileSync(path.join(dir, FILE), JSON.stringify({
|
|
163
|
+
version: 99,
|
|
164
|
+
identities: [{ identity: IDENTITY, buckets: { mine: [row(1)], assigned: [], involved: [] } }],
|
|
165
|
+
}));
|
|
166
|
+
const cache = store(dir);
|
|
167
|
+
assert.equal(await cache.load(IDENTITY), null, 'a version this module does not know is never read');
|
|
168
|
+
assert.equal(await cache.save(IDENTITY, snapshot()), true);
|
|
169
|
+
assert.equal(documentAt(dir).version, 1);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test('S4: a hostile entry is dropped and every other identity still answers', async () => {
|
|
173
|
+
const dir = tempDir('store-hostile');
|
|
174
|
+
const cache = store(dir);
|
|
175
|
+
await cache.save(OTHER, snapshot());
|
|
176
|
+
const doc = documentAt(dir);
|
|
177
|
+
doc.identities.push({ identity: IDENTITY, buckets: 'not buckets', counts: {}, truncated: {}, inconsistent: false, fullAt: 1, syncedAt: 1, lastApplied: 1 });
|
|
178
|
+
fs.writeFileSync(path.join(dir, FILE), JSON.stringify(doc));
|
|
179
|
+
|
|
180
|
+
assert.equal(await cache.load(IDENTITY), null, 'an entry whose shape is wrong is not a cached read');
|
|
181
|
+
assert.ok(await cache.load(OTHER), 'the neighbour it was written beside is untouched');
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('S4: a failed atomic write leaves the previous document and never throws', async () => {
|
|
185
|
+
const dir = tempDir('store-atomic');
|
|
186
|
+
const cache = store(dir);
|
|
187
|
+
await cache.save(IDENTITY, snapshot({ syncedAt: 1000, lastApplied: 1 }));
|
|
188
|
+
|
|
189
|
+
const failing = store(dir, {
|
|
190
|
+
fs: {
|
|
191
|
+
...fs.promises,
|
|
192
|
+
rename: async () => { throw Object.assign(new Error('EXDEV: cross-device link'), { code: 'EXDEV' }); },
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
assert.equal(await failing.save(IDENTITY, snapshot({ syncedAt: 9000, lastApplied: 2 })), false,
|
|
196
|
+
'a write that cannot be committed answers false instead of throwing');
|
|
197
|
+
|
|
198
|
+
const entry = await cache.load(IDENTITY);
|
|
199
|
+
assert.equal(entry.syncedAt, 1000, 'the previous document is exactly as it was');
|
|
200
|
+
assert.deepEqual(fs.readdirSync(dir), [FILE], 'and the temp file it wrote is not left behind');
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('S4: an unreadable directory or a missing document is silence', async () => {
|
|
204
|
+
const dir = tempDir('store-unreadable');
|
|
205
|
+
const missing = store(path.join(dir, 'not-created-yet'));
|
|
206
|
+
assert.equal(await missing.load(IDENTITY), null, 'a missing document is nothing to hydrate');
|
|
207
|
+
|
|
208
|
+
const unreadable = store(dir, {
|
|
209
|
+
fs: {
|
|
210
|
+
...fs.promises,
|
|
211
|
+
readFile: async () => { throw Object.assign(new Error('EACCES: permission denied'), { code: 'EACCES' }); },
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
assert.equal(await unreadable.load(IDENTITY), null, 'an unreadable directory answers nothing');
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('S4: a machine with no home and no XDG has no cache directory, and says so by silence', async () => {
|
|
218
|
+
const cache = createIssuesCacheStore({ env: {}, home: null });
|
|
219
|
+
assert.equal(cache.directory(), null, 'there is no directory to name');
|
|
220
|
+
assert.equal(await cache.load(IDENTITY), null);
|
|
221
|
+
assert.equal(await cache.save(IDENTITY, snapshot()), false);
|
|
222
|
+
});
|