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.
- package/README.md +54 -319
- package/extensions/odd-worktree-tools.ts +4145 -2529
- 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 -712
- 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 +2565 -309
- 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 +419 -199
- 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,261 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// S4 (issues-startup-performance T3): the DISK half of the issues read cache.
|
|
3
|
+
//
|
|
4
|
+
// `lib/related-issues-cache.js` stays PURE — no imports, no child process, no
|
|
5
|
+
// disk — and owns what a read MEANS (the plan, the merge, the count invariant).
|
|
6
|
+
// This module owns only where an entry sleeps between processes: ONE small
|
|
7
|
+
// versioned JSON document under `$XDG_CACHE_HOME/odd-worktree/` (falling back to
|
|
8
|
+
// `~/.cache/odd-worktree/`), one entry per repository identity, keyed exactly as
|
|
9
|
+
// the in-memory cache keys its own entries (`<host>/<owner>/<repo>`), so a
|
|
10
|
+
// hydrated entry can never be served under another repository's name.
|
|
11
|
+
//
|
|
12
|
+
// An entry holds what `plan`/`get` need: the three bucket rows, `counts`,
|
|
13
|
+
// `truncated`, `inconsistent`, `fullAt`, `syncedAt` and `lastApplied`. `fullAt`
|
|
14
|
+
// moves only on a FULL apply, exactly like the in-memory cache's own clock, so a
|
|
15
|
+
// steady stream of deltas can never postpone the full re-read across a restart.
|
|
16
|
+
//
|
|
17
|
+
// Best effort by contract: nothing here throws, and nothing here is on a session
|
|
18
|
+
// or paint path — the extension calls it from its async loader alone. A malformed
|
|
19
|
+
// document, a version this module does not know, an entry whose shape is wrong,
|
|
20
|
+
// an unreadable directory or a write that cannot be committed are all SILENCE
|
|
21
|
+
// (`null` / `false`), never an exception and never a half-written document: the
|
|
22
|
+
// write is a temp file in the same directory plus a rename, so a failure leaves
|
|
23
|
+
// the previous document exactly as it was.
|
|
24
|
+
//
|
|
25
|
+
// The `fs` seam and the directory are injectable, so a test never touches a real
|
|
26
|
+
// cache directory and a host whose `fs` is broken simply gets an in-process cache.
|
|
27
|
+
|
|
28
|
+
const path = require('node:path');
|
|
29
|
+
const os = require('node:os');
|
|
30
|
+
|
|
31
|
+
// The document carries its own version: a reader that does not recognize one
|
|
32
|
+
// answers nothing instead of guessing at a shape it never wrote.
|
|
33
|
+
const DOC_VERSION = 1;
|
|
34
|
+
const DIR_NAME = 'odd-worktree';
|
|
35
|
+
const FILE_NAME = 'issues-cache.json';
|
|
36
|
+
const BUCKET_KEYS = ['mine', 'assigned', 'involved'];
|
|
37
|
+
// The document is bounded: the oldest identities are dropped past this cap, so a
|
|
38
|
+
// long-lived machine never grows a cache file nobody asked for.
|
|
39
|
+
const DEFAULT_IDENTITY_LIMIT = 8;
|
|
40
|
+
|
|
41
|
+
function promisesSeam() {
|
|
42
|
+
try {
|
|
43
|
+
const fs = require('node:fs');
|
|
44
|
+
return fs && fs.promises ? fs.promises : null;
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function isObject(value) {
|
|
51
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// The rows of one bucket, dropped when they are not a row at all. A row without a
|
|
55
|
+
// usable number cannot be merged or counted, exactly like the in-memory cache, so
|
|
56
|
+
// it is not a row here either.
|
|
57
|
+
function normalizeRows(rows) {
|
|
58
|
+
if (!Array.isArray(rows)) return null;
|
|
59
|
+
const kept = [];
|
|
60
|
+
for (const row of rows) {
|
|
61
|
+
if (!isObject(row)) continue;
|
|
62
|
+
if (!Number.isInteger(row.number) || row.number <= 0) continue;
|
|
63
|
+
kept.push({ ...row });
|
|
64
|
+
}
|
|
65
|
+
return kept;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function normalizeFlags(value) {
|
|
69
|
+
if (!isObject(value)) return null;
|
|
70
|
+
const flags = {};
|
|
71
|
+
for (const key of BUCKET_KEYS) flags[key] = value[key] === true;
|
|
72
|
+
return flags;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// One stored entry, or `null` when its shape is not the one this module writes.
|
|
76
|
+
// A hostile entry is never repaired into something a caller would then trust.
|
|
77
|
+
function normalizeEntry(candidate) {
|
|
78
|
+
if (!isObject(candidate)) return null;
|
|
79
|
+
const identity = candidate.identity;
|
|
80
|
+
if (typeof identity !== 'string' || identity.length === 0) return null;
|
|
81
|
+
if (!isObject(candidate.buckets) || !isObject(candidate.counts)) return null;
|
|
82
|
+
const buckets = {};
|
|
83
|
+
const counts = {};
|
|
84
|
+
for (const key of BUCKET_KEYS) {
|
|
85
|
+
const rows = normalizeRows(candidate.buckets[key]);
|
|
86
|
+
if (rows === null) return null;
|
|
87
|
+
const count = candidate.counts[key];
|
|
88
|
+
if (!Number.isInteger(count) || count < 0) return null;
|
|
89
|
+
buckets[key] = rows;
|
|
90
|
+
counts[key] = count;
|
|
91
|
+
}
|
|
92
|
+
const truncated = normalizeFlags(candidate.truncated);
|
|
93
|
+
if (truncated === null) return null;
|
|
94
|
+
if (!Number.isFinite(candidate.fullAt) || !Number.isFinite(candidate.syncedAt)) return null;
|
|
95
|
+
return {
|
|
96
|
+
identity,
|
|
97
|
+
buckets,
|
|
98
|
+
counts,
|
|
99
|
+
truncated,
|
|
100
|
+
inconsistent: candidate.inconsistent === true,
|
|
101
|
+
fullAt: candidate.fullAt,
|
|
102
|
+
syncedAt: candidate.syncedAt,
|
|
103
|
+
lastApplied: Number.isFinite(candidate.lastApplied) ? candidate.lastApplied : null,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function copyEntry(entry) {
|
|
108
|
+
const normalized = normalizeEntry(entry);
|
|
109
|
+
if (normalized === null) return null;
|
|
110
|
+
const buckets = {};
|
|
111
|
+
for (const key of BUCKET_KEYS) buckets[key] = normalized.buckets[key].map((row) => ({ ...row }));
|
|
112
|
+
return { ...normalized, buckets, counts: { ...normalized.counts }, truncated: { ...normalized.truncated } };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function createIssuesCacheStore(options = {}) {
|
|
116
|
+
const opts = options && typeof options === 'object' ? options : {};
|
|
117
|
+
// `fs` is the promise-returning seam this module writes and reads through; the
|
|
118
|
+
// default is the real filesystem, and a test passes fakes.
|
|
119
|
+
const fsSeam = isObject(opts.fs) ? opts.fs : promisesSeam();
|
|
120
|
+
const env = isObject(opts.env) ? opts.env : process.env;
|
|
121
|
+
const limit = Number.isInteger(opts.limit) && opts.limit > 0 ? opts.limit : DEFAULT_IDENTITY_LIMIT;
|
|
122
|
+
let writes = 0;
|
|
123
|
+
|
|
124
|
+
// The directory the document lives in, resolved at CALL time so a host (and a
|
|
125
|
+
// test) can move it by environment alone. `dir` names the directory itself;
|
|
126
|
+
// otherwise `$XDG_CACHE_HOME/odd-worktree/`, else `~/.cache/odd-worktree/`.
|
|
127
|
+
// No home and no XDG means no directory at all — silence, not a guess.
|
|
128
|
+
function directory() {
|
|
129
|
+
try {
|
|
130
|
+
if (typeof opts.dir === 'string' && opts.dir.length > 0) return path.resolve(opts.dir);
|
|
131
|
+
const xdg = env ? env.XDG_CACHE_HOME : null;
|
|
132
|
+
if (typeof xdg === 'string' && xdg.trim() !== '') return path.join(path.resolve(xdg), DIR_NAME);
|
|
133
|
+
if (opts && 'home' in opts) {
|
|
134
|
+
const home = opts.home;
|
|
135
|
+
if (typeof home !== 'string' || home.length === 0) return null;
|
|
136
|
+
return path.join(path.resolve(home), '.cache', DIR_NAME);
|
|
137
|
+
}
|
|
138
|
+
const home = os.homedir();
|
|
139
|
+
if (typeof home !== 'string' || home.length === 0) return null;
|
|
140
|
+
return path.join(home, '.cache', DIR_NAME);
|
|
141
|
+
} catch {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function file() {
|
|
147
|
+
const dir = directory();
|
|
148
|
+
return dir === null ? null : path.join(dir, FILE_NAME);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// The document as a list of entries, oldest first. Anything this module cannot
|
|
152
|
+
// read is `null`; any entry whose shape is wrong is dropped on its own, so one
|
|
153
|
+
// hostile entry never costs the identity written beside it.
|
|
154
|
+
async function readIdentities() {
|
|
155
|
+
const target = file();
|
|
156
|
+
if (target === null || fsSeam === null) return null;
|
|
157
|
+
let text;
|
|
158
|
+
try {
|
|
159
|
+
text = await fsSeam.readFile(target, 'utf8');
|
|
160
|
+
} catch {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
let doc;
|
|
164
|
+
try {
|
|
165
|
+
doc = JSON.parse(text);
|
|
166
|
+
} catch {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
if (!isObject(doc) || doc.version !== DOC_VERSION || !Array.isArray(doc.identities)) return null;
|
|
170
|
+
const identities = [];
|
|
171
|
+
for (const candidate of doc.identities) {
|
|
172
|
+
const entry = normalizeEntry(candidate);
|
|
173
|
+
if (entry !== null) identities.push(entry);
|
|
174
|
+
}
|
|
175
|
+
return identities;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async function load(identity) {
|
|
179
|
+
if (typeof identity !== 'string' || identity.length === 0) return null;
|
|
180
|
+
try {
|
|
181
|
+
const identities = await readIdentities();
|
|
182
|
+
if (identities === null) return null;
|
|
183
|
+
for (let index = identities.length - 1; index >= 0; index -= 1) {
|
|
184
|
+
if (identities[index].identity === identity) return copyEntry(identities[index]);
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
187
|
+
} catch {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// One bucket set + the facts the loader knows, stored as one entry. `full` is
|
|
193
|
+
// what the caller's plan decided: it is the ONLY thing that moves `fullAt`.
|
|
194
|
+
function normalizeSnapshot(identity, snapshot) {
|
|
195
|
+
if (typeof identity !== 'string' || identity.length === 0) return null;
|
|
196
|
+
if (!isObject(snapshot)) return null;
|
|
197
|
+
const at = Number.isFinite(snapshot.syncedAt) ? snapshot.syncedAt : Date.now();
|
|
198
|
+
return normalizeEntry({
|
|
199
|
+
identity,
|
|
200
|
+
buckets: snapshot.buckets,
|
|
201
|
+
counts: snapshot.counts,
|
|
202
|
+
truncated: snapshot.truncated,
|
|
203
|
+
inconsistent: snapshot.inconsistent,
|
|
204
|
+
// Stamped here, then left alone below unless this answer WAS the full read.
|
|
205
|
+
fullAt: at,
|
|
206
|
+
syncedAt: at,
|
|
207
|
+
lastApplied: snapshot.lastApplied,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async function save(identity, snapshot) {
|
|
212
|
+
const dir = directory();
|
|
213
|
+
const target = file();
|
|
214
|
+
if (dir === null || target === null || fsSeam === null) return false;
|
|
215
|
+
const entry = normalizeSnapshot(identity, snapshot);
|
|
216
|
+
if (entry === null) return false;
|
|
217
|
+
try {
|
|
218
|
+
const existing = await readIdentities();
|
|
219
|
+
const identities = existing === null ? [] : existing;
|
|
220
|
+
const previous = identities.find((candidate) => candidate.identity === identity) || null;
|
|
221
|
+
const stored = {
|
|
222
|
+
...entry,
|
|
223
|
+
// A delta never invents a full read: it keeps the one already stored, or
|
|
224
|
+
// stamps this answer when it is all there is.
|
|
225
|
+
fullAt: snapshot.full === true
|
|
226
|
+
? entry.syncedAt
|
|
227
|
+
: (previous !== null && Number.isFinite(previous.fullAt) ? previous.fullAt : entry.syncedAt),
|
|
228
|
+
};
|
|
229
|
+
const kept = identities.filter((candidate) => candidate.identity !== identity);
|
|
230
|
+
kept.push(stored);
|
|
231
|
+
const body = JSON.stringify({ version: DOC_VERSION, identities: kept.slice(-limit) });
|
|
232
|
+
await fsSeam.mkdir(dir, { recursive: true });
|
|
233
|
+
writes += 1;
|
|
234
|
+
// Atomic: the temp file lives in the SAME directory (a rename across
|
|
235
|
+
// devices is not atomic, and a reader must never see half a document), and
|
|
236
|
+
// the rename is what makes the new one readable.
|
|
237
|
+
const temp = path.join(dir, `.${FILE_NAME}.${process.pid}.${writes}.tmp`);
|
|
238
|
+
try {
|
|
239
|
+
await fsSeam.writeFile(temp, body, 'utf8');
|
|
240
|
+
await fsSeam.rename(temp, target);
|
|
241
|
+
} catch {
|
|
242
|
+
// Its own just-created temp file: removed so a failed write leaves the
|
|
243
|
+
// directory exactly as it was. Best effort — the failure is already
|
|
244
|
+
// silence to the caller.
|
|
245
|
+
try {
|
|
246
|
+
if (typeof fsSeam.unlink === 'function') await fsSeam.unlink(temp);
|
|
247
|
+
} catch {
|
|
248
|
+
// A temp file that cannot be removed is still not the document.
|
|
249
|
+
}
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
return true;
|
|
253
|
+
} catch {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return { load, save, directory };
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
module.exports = { createIssuesCacheStore };
|