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,205 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// The bash card's FRAME and CLOSING RULE, as rows. Pure: strings in, strings out — no Pi, no
|
|
3
|
+
// theme object, no filesystem. A caller passes a `paint(text)` function, so the colour is
|
|
4
|
+
// whichever theme role the caller resolved and this module never names a palette.
|
|
5
|
+
//
|
|
6
|
+
// Two jobs, both on rows the host already drew:
|
|
7
|
+
// * `paintFrame` repaints every frame cell of a row (corners, rules, the side bars) in ONE
|
|
8
|
+
// role, so no row shows two colours side by side and the whole box reads as part of the label
|
|
9
|
+
// it belongs to. Text between the cells is never touched.
|
|
10
|
+
// * `elapsedRow` writes a finished call's duration into the closing rule, right-aligned
|
|
11
|
+
// against the corner (neon) or the end of the bar row (float), when it fits.
|
|
12
|
+
//
|
|
13
|
+
// Both keep every row's width and re-issue the host's own escapes after what they paint, so the
|
|
14
|
+
// content that follows keeps the host's colour.
|
|
15
|
+
|
|
16
|
+
const ESCAPE = /\u001b\[[0-9;]*m|\u001b\]8;;[^\u0007\u001b]*(?:\u0007|\u001b\\)/uy;
|
|
17
|
+
|
|
18
|
+
/** The row's visible characters with their raw offsets (SGR and OSC-8 skipped). */
|
|
19
|
+
function visibleChars(line) {
|
|
20
|
+
const chars = [];
|
|
21
|
+
let index = 0;
|
|
22
|
+
while (index < line.length) {
|
|
23
|
+
if (line[index] === '\u001b') {
|
|
24
|
+
ESCAPE.lastIndex = index;
|
|
25
|
+
const escape = ESCAPE.exec(line);
|
|
26
|
+
if (escape !== null) {
|
|
27
|
+
index += escape[0].length;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const char = String.fromCodePoint(line.codePointAt(index));
|
|
32
|
+
chars.push({ char, raw: index });
|
|
33
|
+
index += char.length;
|
|
34
|
+
}
|
|
35
|
+
return chars;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Columns one character takes: combining marks none, East Asian wide and emoji two. */
|
|
39
|
+
function charColumns(char) {
|
|
40
|
+
const code = char.codePointAt(0);
|
|
41
|
+
if (/\p{M}/u.test(char) || code === 0x200d || (code >= 0xfe00 && code <= 0xfe0f)) return 0;
|
|
42
|
+
if (
|
|
43
|
+
(code >= 0x1100 && code <= 0x115f) ||
|
|
44
|
+
(code >= 0x2e80 && code <= 0xa4cf) ||
|
|
45
|
+
(code >= 0xac00 && code <= 0xd7a3) ||
|
|
46
|
+
(code >= 0xf900 && code <= 0xfaff) ||
|
|
47
|
+
(code >= 0xfe30 && code <= 0xfe6f) ||
|
|
48
|
+
(code >= 0xff00 && code <= 0xff60) ||
|
|
49
|
+
(code >= 0xffe0 && code <= 0xffe6) ||
|
|
50
|
+
(code >= 0x1f300 && code <= 0x1faff)
|
|
51
|
+
) {
|
|
52
|
+
return 2;
|
|
53
|
+
}
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const textColumns = (text) => Array.from(text).reduce((sum, char) => sum + charColumns(char), 0);
|
|
58
|
+
const rowColumns = (line) => visibleChars(line).reduce((sum, entry) => sum + charColumns(entry.char), 0);
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The SGR state in force at a raw offset, as the shortest escapes that restore it: foreground,
|
|
62
|
+
* background, then the text attributes. Tracked NET (a reset or a closing code clears what it
|
|
63
|
+
* closes), so a span the host opened and closed — or one the design painted itself — is never
|
|
64
|
+
* re-issued, and a row with nothing in force yields an empty string.
|
|
65
|
+
*/
|
|
66
|
+
function sgrBefore(row, raw) {
|
|
67
|
+
const state = { fg: '', bg: '', bold: false, dim: false, italic: false, underline: false, inverse: false, strike: false };
|
|
68
|
+
for (const match of row.slice(0, raw).matchAll(/\u001b\[([0-9;]*)m/gu)) {
|
|
69
|
+
const params = match[1] === '' ? ['0'] : match[1].split(';');
|
|
70
|
+
for (let i = 0; i < params.length; i += 1) {
|
|
71
|
+
const code = Number(params[i]);
|
|
72
|
+
if (code === 0) {
|
|
73
|
+
Object.assign(state, { fg: '', bg: '', bold: false, dim: false, italic: false, underline: false, inverse: false, strike: false });
|
|
74
|
+
} else if (code === 1) state.bold = true;
|
|
75
|
+
else if (code === 2) state.dim = true;
|
|
76
|
+
else if (code === 3) state.italic = true;
|
|
77
|
+
else if (code === 4) state.underline = true;
|
|
78
|
+
else if (code === 7) state.inverse = true;
|
|
79
|
+
else if (code === 9) state.strike = true;
|
|
80
|
+
else if (code === 22) { state.bold = false; state.dim = false; }
|
|
81
|
+
else if (code === 23) state.italic = false;
|
|
82
|
+
else if (code === 24) state.underline = false;
|
|
83
|
+
else if (code === 27) state.inverse = false;
|
|
84
|
+
else if (code === 29) state.strike = false;
|
|
85
|
+
else if (code === 39) state.fg = '';
|
|
86
|
+
else if (code === 49) state.bg = '';
|
|
87
|
+
else if ((code >= 30 && code <= 37) || (code >= 90 && code <= 97)) state.fg = String(code);
|
|
88
|
+
else if ((code >= 40 && code <= 47) || (code >= 100 && code <= 107)) state.bg = String(code);
|
|
89
|
+
else if (code === 38 || code === 48) {
|
|
90
|
+
// 38;5;n and 38;2;r;g;b: the extended colour carries its own parameters.
|
|
91
|
+
const width = params[i + 1] === '2' ? 4 : params[i + 1] === '5' ? 2 : 0;
|
|
92
|
+
const value = params.slice(i, i + 1 + width).join(';');
|
|
93
|
+
if (code === 38) state.fg = value;
|
|
94
|
+
else state.bg = value;
|
|
95
|
+
i += width;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const out = [state.fg, state.bg, state.bold ? '1' : '', state.dim ? '2' : '', state.italic ? '3' : '', state.underline ? '4' : '', state.inverse ? '7' : '', state.strike ? '9' : ''];
|
|
100
|
+
return out.filter((code) => code !== '').map((code) => `\u001b[${code}m`).join('');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const RULE = '─';
|
|
104
|
+
// The first cell of a framed row: the outline's corners and side, or the float bar.
|
|
105
|
+
const FIRST_CELLS = new Set(['╭', '│', '╰', '▎']);
|
|
106
|
+
const OUTLINE = new Set(['╭', '│', '╰']);
|
|
107
|
+
const LAST_CELLS = new Set(['╮', '│', '╯']);
|
|
108
|
+
|
|
109
|
+
/** The indexes (into `chars`) of the cells that draw the frame on this row. */
|
|
110
|
+
function frameCells(chars) {
|
|
111
|
+
const cells = new Set();
|
|
112
|
+
const first = chars.findIndex((entry) => entry.char.trim() !== '');
|
|
113
|
+
if (first < 0 || !FIRST_CELLS.has(chars[first].char)) return cells;
|
|
114
|
+
cells.add(first);
|
|
115
|
+
if (!OUTLINE.has(chars[first].char)) return cells;
|
|
116
|
+
let last = chars.length - 1;
|
|
117
|
+
while (last > first && chars[last].char.trim() === '') last -= 1;
|
|
118
|
+
if (last > first && LAST_CELLS.has(chars[last].char)) cells.add(last);
|
|
119
|
+
if (chars[first].char === '│') return cells;
|
|
120
|
+
// A top or closing rule: its lead, the rule before the corner, and every long run of rule.
|
|
121
|
+
if (chars[first + 1]?.char === RULE) cells.add(first + 1);
|
|
122
|
+
if (cells.has(last) && chars[last - 1]?.char === RULE) cells.add(last - 1);
|
|
123
|
+
for (let index = first; index <= last; index += 1) {
|
|
124
|
+
if (chars[index].char !== RULE) continue;
|
|
125
|
+
let end = index;
|
|
126
|
+
while (end + 1 <= last && chars[end + 1].char === RULE && chars[end + 1].raw === chars[end].raw + 1) end += 1;
|
|
127
|
+
if (end - index + 1 >= 3) for (let at = index; at <= end; at += 1) cells.add(at);
|
|
128
|
+
index = end;
|
|
129
|
+
}
|
|
130
|
+
return cells;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The row with every frame cell painted by `paint(text)`; the row itself when it has none.
|
|
135
|
+
* A contiguous run is painted in one call, and the host's escapes in force at its end are issued
|
|
136
|
+
* again after it.
|
|
137
|
+
*/
|
|
138
|
+
function paintFrame(row, paint) {
|
|
139
|
+
const chars = visibleChars(row);
|
|
140
|
+
const cells = frameCells(chars);
|
|
141
|
+
if (cells.size === 0) return row;
|
|
142
|
+
const runs = [];
|
|
143
|
+
for (const index of [...cells].sort((a, b) => a - b)) {
|
|
144
|
+
const run = runs[runs.length - 1];
|
|
145
|
+
if (run !== undefined && run.end === index - 1) run.end = index;
|
|
146
|
+
else runs.push({ start: index, end: index });
|
|
147
|
+
}
|
|
148
|
+
let next = row;
|
|
149
|
+
for (const run of runs.reverse()) {
|
|
150
|
+
const from = chars[run.start].raw;
|
|
151
|
+
const to = chars[run.end].raw + chars[run.end].char.length;
|
|
152
|
+
const text = chars.slice(run.start, run.end + 1).map((entry) => entry.char).join('');
|
|
153
|
+
next = `${next.slice(0, from)}${paint(text)}${sgrBefore(row, to)}${next.slice(to)}`;
|
|
154
|
+
}
|
|
155
|
+
return next;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Elapsed time for a closing rule, or `undefined` when there is no reliable duration.
|
|
160
|
+
* Sub-second runs read in milliseconds, longer ones in seconds with one decimal.
|
|
161
|
+
*/
|
|
162
|
+
function cardElapsed(durationMs) {
|
|
163
|
+
if (typeof durationMs !== 'number' || !Number.isFinite(durationMs) || durationMs < 0) return undefined;
|
|
164
|
+
return durationMs < 1000 ? `${Math.round(durationMs)}ms` : `${(durationMs / 1000).toFixed(1)}s`;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// A closing rule keeps at least this much rule beside the duration, or it stays a plain rule.
|
|
168
|
+
const MIN_RULE = 3;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The closing row with `text` right-aligned in it, or `undefined` when the row is not a closing
|
|
172
|
+
* row or has no room. `paint` colours the duration only. Neon: `╰──── 120ms ─╯`. Float: the bar
|
|
173
|
+
* and spaces, the duration ending one space before the row's end.
|
|
174
|
+
*/
|
|
175
|
+
function elapsedRow(row, text, paint) {
|
|
176
|
+
const chars = visibleChars(row);
|
|
177
|
+
const first = chars.findIndex((entry) => entry.char.trim() !== '');
|
|
178
|
+
if (first < 0) return undefined;
|
|
179
|
+
let last = chars.length - 1;
|
|
180
|
+
while (last > first && chars[last].char.trim() === '') last -= 1;
|
|
181
|
+
const width = textColumns(text);
|
|
182
|
+
let span;
|
|
183
|
+
let tail = '';
|
|
184
|
+
if (chars[first].char === '╰' && chars[last].char === '╯') {
|
|
185
|
+
const rule = chars.slice(first + 1, last);
|
|
186
|
+
if (rule.length === 0 || !rule.every((entry) => entry.char === RULE)) return undefined;
|
|
187
|
+
if (rule.length - (width + 2) < MIN_RULE) return undefined;
|
|
188
|
+
span = { from: last - (width + 2), to: last - 1, lead: ' ', trail: ' ' };
|
|
189
|
+
} else if (chars[first].char === '▎' && last === first) {
|
|
190
|
+
const spaces = chars.length - 1 - first;
|
|
191
|
+
if (spaces < width + 1 + MIN_RULE) return undefined;
|
|
192
|
+
span = { from: chars.length - 1 - width, to: chars.length - 1, lead: '', trail: '' };
|
|
193
|
+
tail = ' ';
|
|
194
|
+
} else {
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
const from = chars[span.from].raw;
|
|
198
|
+
const to = chars[span.to].raw + chars[span.to].char.length;
|
|
199
|
+
const inner = `${span.lead}${paint(text)}${span.trail}`;
|
|
200
|
+
// Float: the duration replaces the last `width + 1` columns, so the closing space stays.
|
|
201
|
+
const replaced = span.lead === '' ? `${paint(text)}${tail}` : inner;
|
|
202
|
+
return `${row.slice(0, from)}${replaced}${sgrBefore(row, from)}${row.slice(to)}`;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
module.exports = { cardElapsed, charColumns, elapsedRow, paintFrame, rowColumns, sgrBefore, textColumns, visibleChars };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// The conversation card content level, read by every card of this package.
|
|
3
|
+
//
|
|
4
|
+
// `default` draws a card with its bounded preview (at most three body rows collapsed); `minimal` draws it as one line, with
|
|
5
|
+
// no body at all until the card is expanded. The level is the user's choice in Gentle Shell, which publishes it on a
|
|
6
|
+
// process-wide slot because Pi loads every extension with its own module cache. Reading that slot is the whole inheritance
|
|
7
|
+
// this package can have: it needs no file of its own, a host without Gentle Shell leaves it unset, and the safe level then is
|
|
8
|
+
// `default` (never the whole output). It is read at paint time, so a level switched while the transcript is on screen applies
|
|
9
|
+
// to the next paint.
|
|
10
|
+
|
|
11
|
+
const CARD_CONTENT = Object.freeze({ DEFAULT: 'default', MINIMAL: 'minimal' });
|
|
12
|
+
const CARD_CONTENT_SLOT = Symbol.for('gentle-pi.card-content');
|
|
13
|
+
|
|
14
|
+
function cardContentLevel(host = globalThis) {
|
|
15
|
+
try {
|
|
16
|
+
const value = host === undefined || host === null ? undefined : host[CARD_CONTENT_SLOT];
|
|
17
|
+
return value === CARD_CONTENT.MINIMAL ? CARD_CONTENT.MINIMAL : CARD_CONTENT.DEFAULT;
|
|
18
|
+
} catch {
|
|
19
|
+
return CARD_CONTENT.DEFAULT;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = { CARD_CONTENT, CARD_CONTENT_SLOT, cardContentLevel };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// S5: which of the two card looks the transcript follows, read from Gentle Shell
|
|
3
|
+
// when it is there and from the user's own preference document when it is not.
|
|
4
|
+
//
|
|
5
|
+
// Styles: "neon" (the rounded `╭ ╮ ╰ ╯ │` frame) and "float" (the `▎` rail, no
|
|
6
|
+
// box). FLOAT is the default: an absent host, an absent document and every
|
|
7
|
+
// malformed document all read as float.
|
|
8
|
+
//
|
|
9
|
+
// The choice lives in two places:
|
|
10
|
+
// * the process-wide slot Gentle Shell keeps at
|
|
11
|
+
// `globalThis[Symbol.for("gentle-pi.card-style")]`. It is the LIVE value:
|
|
12
|
+
// the shell refreshes it at startup, on every `session_start` and right
|
|
13
|
+
// after its Customize save, so a change made while this session runs is
|
|
14
|
+
// seen by the very next render — a property read, no watcher, no restart.
|
|
15
|
+
// This is the runtime path.
|
|
16
|
+
// * the strict document `<home>/card-style.json`, written per user by Gentle
|
|
17
|
+
// Shell: `{"schema":"gentle-pi.card-style/v1","style":"neon"|"float"}` and
|
|
18
|
+
// nothing else. It is the fallback when no host is present, and it is read on
|
|
19
|
+
// every render, so a hand edit is visible on the next card.
|
|
20
|
+
// `<home>` resolves `GENTLE_PI_CONFIG_HOME` → `GENTLE_SHELL_CONFIG_HOME` →
|
|
21
|
+
// `~/.pi/gentle-ai`, in that order.
|
|
22
|
+
//
|
|
23
|
+
// One decision order, never a guess and never a throw:
|
|
24
|
+
// global slot → preference document → float
|
|
25
|
+
// A slot holding a known style always wins, because that is what the running
|
|
26
|
+
// shell says; a slot holding anything else is not a decision and the document
|
|
27
|
+
// answers. A missing, unreadable, malformed, wrong-schema, extra-key or
|
|
28
|
+
// unknown-style document reads as float.
|
|
29
|
+
//
|
|
30
|
+
// `resolveCardStyle()` reports which branch answered (`source`) and why it fell
|
|
31
|
+
// back (`reason`) — evidence for a test or a bug report, never painted into a
|
|
32
|
+
// card. `cardStyle()` is the same decision without the report and is what the
|
|
33
|
+
// card substrate calls on every render.
|
|
34
|
+
//
|
|
35
|
+
// There is no cache and no watcher, by design. With a host running the slot is
|
|
36
|
+
// live, so a render reads one property. Without a host there is no
|
|
37
|
+
// notification channel for a document edit, so the document is read on EVERY
|
|
38
|
+
// render, which is what makes an edit made while no host runs visible on the
|
|
39
|
+
// next render instead of at the next `session_start`. One small synchronous
|
|
40
|
+
// read per render (a few hundred bytes, no network, no directory walk) is an
|
|
41
|
+
// accepted cost: it is a decision, not an oversight. Nothing is cached across
|
|
42
|
+
// calls, so two renders can never disagree with the file on disk.
|
|
43
|
+
|
|
44
|
+
const { readFileSync } = require('node:fs');
|
|
45
|
+
const { homedir } = require('node:os');
|
|
46
|
+
const { join } = require('node:path');
|
|
47
|
+
|
|
48
|
+
const CARD_STYLE = {
|
|
49
|
+
NEON: 'neon',
|
|
50
|
+
FLOAT: 'float',
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// The exact document Gentle Shell writes: this schema string and the one style.
|
|
54
|
+
const CARD_STYLE_SCHEMA = 'gentle-pi.card-style/v1';
|
|
55
|
+
const CARD_STYLE_FILE = 'card-style.json';
|
|
56
|
+
|
|
57
|
+
// The slot Gentle Shell resolves the style into. `Symbol.for` is process-wide,
|
|
58
|
+
// so every extension copy reads the same cell.
|
|
59
|
+
const CARD_STYLE_SLOT = Symbol.for('gentle-pi.card-style');
|
|
60
|
+
|
|
61
|
+
const isCardStyle = (value) => value === CARD_STYLE.NEON || value === CARD_STYLE.FLOAT;
|
|
62
|
+
|
|
63
|
+
function envText(value) {
|
|
64
|
+
return typeof value === 'string' && value.trim().length > 0 ? value : undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** `<home>`: `GENTLE_PI_CONFIG_HOME` → `GENTLE_SHELL_CONFIG_HOME` → `~/.pi/gentle-ai`. */
|
|
68
|
+
function cardStyleHome(env) {
|
|
69
|
+
const source = env !== null && typeof env === 'object' ? env : {};
|
|
70
|
+
const explicit = envText(source.GENTLE_PI_CONFIG_HOME) ?? envText(source.GENTLE_SHELL_CONFIG_HOME);
|
|
71
|
+
if (explicit !== undefined) return explicit;
|
|
72
|
+
try {
|
|
73
|
+
return join(homedir(), '.pi', 'gentle-ai');
|
|
74
|
+
} catch {
|
|
75
|
+
// No usable home directory: there is no document to read.
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The document path for one home, or null when no home resolves. */
|
|
81
|
+
function cardStyleFile(options) {
|
|
82
|
+
const chosen = options !== null && typeof options === 'object' && envText(options.gentlePiConfigHome) !== undefined
|
|
83
|
+
? options.gentlePiConfigHome
|
|
84
|
+
: cardStyleHome(process.env);
|
|
85
|
+
return chosen === null || chosen === undefined || chosen === '' ? null : join(chosen, CARD_STYLE_FILE);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The live slot value, or undefined when the host is absent or the cell holds something else. */
|
|
89
|
+
function slotStyle() {
|
|
90
|
+
try {
|
|
91
|
+
const value = globalThis[CARD_STYLE_SLOT];
|
|
92
|
+
return isCardStyle(value) ? value : undefined;
|
|
93
|
+
} catch {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The style a document states, or undefined when it states nothing usable. The
|
|
100
|
+
* document is strict: exactly `schema` and `style`, the schema string verbatim
|
|
101
|
+
* and one of the two known styles.
|
|
102
|
+
*/
|
|
103
|
+
function parseCardStyleFile(raw) {
|
|
104
|
+
if (typeof raw !== 'string') return undefined;
|
|
105
|
+
let value;
|
|
106
|
+
try {
|
|
107
|
+
value = JSON.parse(raw);
|
|
108
|
+
} catch {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) return undefined;
|
|
112
|
+
if (Object.keys(value).length !== 2) return undefined;
|
|
113
|
+
if (value.schema !== CARD_STYLE_SCHEMA) return undefined;
|
|
114
|
+
if (!Object.prototype.hasOwnProperty.call(value, 'style')) return undefined;
|
|
115
|
+
return isCardStyle(value.style) ? value.style : undefined;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The document branch of the decision, read fresh from `globalFile` on every call
|
|
120
|
+
* that reaches it: there is no cache, so no render can answer with a style the
|
|
121
|
+
* file no longer states. Every failure reads as float and says which one it was.
|
|
122
|
+
*/
|
|
123
|
+
function readFileResolution(globalFile) {
|
|
124
|
+
if (globalFile === null) {
|
|
125
|
+
return { style: CARD_STYLE.FLOAT, source: 'default', reason: 'missing_file', globalFile };
|
|
126
|
+
}
|
|
127
|
+
let raw;
|
|
128
|
+
try {
|
|
129
|
+
raw = readFileSync(globalFile, 'utf8');
|
|
130
|
+
} catch (error) {
|
|
131
|
+
const missing = error !== null && typeof error === 'object' && error.code === 'ENOENT';
|
|
132
|
+
return { style: CARD_STYLE.FLOAT, source: 'default', reason: missing ? 'missing_file' : 'unreadable_file', globalFile };
|
|
133
|
+
}
|
|
134
|
+
const style = parseCardStyleFile(raw);
|
|
135
|
+
if (style === undefined) return { style: CARD_STYLE.FLOAT, source: 'default', reason: 'malformed_file', globalFile };
|
|
136
|
+
return { style, source: 'file', reason: null, globalFile };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The whole decision: the live slot, else the document read now, else float. The
|
|
141
|
+
* document is read only when the slot cannot answer, so a hosted render never
|
|
142
|
+
* touches the disk.
|
|
143
|
+
*/
|
|
144
|
+
function resolution(options) {
|
|
145
|
+
const slot = slotStyle();
|
|
146
|
+
const globalFile = cardStyleFile(options);
|
|
147
|
+
if (slot !== undefined) return { style: slot, source: 'slot', reason: 'slot', slot, globalFile };
|
|
148
|
+
const file = readFileResolution(globalFile);
|
|
149
|
+
return { style: file.style, source: file.source, reason: file.reason, slot: undefined, globalFile };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Where the style came from and why it fell back — `{style, source, reason,
|
|
154
|
+
* slot, globalFile}`. Same decision as `cardStyle()`, with the report attached.
|
|
155
|
+
*/
|
|
156
|
+
function resolveCardStyle(options) {
|
|
157
|
+
return resolution(options);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The style a card must be drawn in: the slot, else the document, else float. Never throws. */
|
|
161
|
+
function cardStyle(options) {
|
|
162
|
+
return resolution(options).style;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
module.exports = {
|
|
166
|
+
CARD_STYLE,
|
|
167
|
+
CARD_STYLE_FILE,
|
|
168
|
+
CARD_STYLE_SCHEMA,
|
|
169
|
+
CARD_STYLE_SLOT,
|
|
170
|
+
cardStyle,
|
|
171
|
+
cardStyleFile,
|
|
172
|
+
cardStyleHome,
|
|
173
|
+
parseCardStyleFile,
|
|
174
|
+
resolveCardStyle,
|
|
175
|
+
};
|
package/lib/checkout-facts.js
CHANGED
|
@@ -7,23 +7,20 @@
|
|
|
7
7
|
// counts of the tracked diff and of every untracked file, S16), and the
|
|
8
8
|
// commits it is ahead of / behind a base branch. S1: a worktree no longer
|
|
9
9
|
// receives issues or ODD documents, so the payload carries NO association
|
|
10
|
-
// field at all
|
|
11
|
-
//
|
|
12
|
-
// read here. The row is still read for the ONE fact it legitimately owns — a
|
|
13
|
-
// linked worktree's `createdAt` (S12).
|
|
10
|
+
// field at all, and S3 removed the stored record the `createdAt` fact used to
|
|
11
|
+
// read from.
|
|
14
12
|
//
|
|
15
13
|
// Each fact is its own envelope — `{available:true, value, reason:null}` or
|
|
16
14
|
// `{available:false, value:null, reason}` — because S9 forbids rendering an
|
|
17
|
-
// unreadable value as a number. A failing git read
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
// facts intact and vice versa. Two facts are about TIME, and what they answer
|
|
15
|
+
// unreadable value as a number. A failing git read is therefore "unavailable",
|
|
16
|
+
// never zero and never an empty list. Facts fail independently.
|
|
17
|
+
// Two facts are about TIME, and what they answer
|
|
21
18
|
// depends on the KIND of checkout (S12) rather than on one rule for all: the
|
|
22
19
|
// PRINCIPAL is the checkout git lists first, so its `createdAt` is when its
|
|
23
20
|
// git history began (the oldest root commit, `source:'root-commit'`), while a
|
|
24
|
-
// linked worktree reports when THAT checkout was created — its
|
|
25
|
-
//
|
|
26
|
-
//
|
|
21
|
+
// linked worktree reports when THAT checkout was created — its directory's
|
|
22
|
+
// birth time (`source:'birthtime'`), because nothing is stored that could say
|
|
23
|
+
// otherwise. `lastActivity` is the
|
|
27
24
|
// winning side of `last commit` vs `newest uncommitted file` for either kind
|
|
28
25
|
// (S12), and S8 adds its provenance: an inherited commit older than the
|
|
29
26
|
// checkout's own creation is not local modification and is dropped, while a
|
|
@@ -37,25 +34,24 @@
|
|
|
37
34
|
// principal — only ever run for the checkout the caller names, and the whole
|
|
38
35
|
// per-path result is cached for `ttlMs`, so a selector that repaints per
|
|
39
36
|
// keystroke does not re-spawn git. The dirty summary is computed once and
|
|
40
|
-
// feeds both `changes` and the dirty side of `lastActivity`; the birth
|
|
41
|
-
//
|
|
37
|
+
// feeds both `changes` and the dirty side of `lastActivity`; the birth time is
|
|
38
|
+
// only stat'ed for a linked worktree.
|
|
42
39
|
// Concurrent callers for the same path share one in-flight read. `facts()`
|
|
43
40
|
// is async (the git work is awaited, never spawned inline) and `peek()`
|
|
44
41
|
// answers from the cache synchronously at paint time.
|
|
45
42
|
//
|
|
46
43
|
// Reuse, not duplication: the dirty summary comes from
|
|
47
|
-
// lib/worktree-changes.js, the
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
44
|
+
// lib/worktree-changes.js, the branch from `listWorktrees`, and the comparison from
|
|
45
|
+
// lib/worktree-git.js's `aheadBehind`. There is no stored record to read (S3): a
|
|
46
|
+
// linked worktree's creation time is its directory's birth time, and every
|
|
47
|
+
// net-capable or heavier read, the repository listing included, is async so it never
|
|
48
|
+
// blocks the host event loop.
|
|
52
49
|
|
|
53
50
|
const path = require('node:path');
|
|
54
51
|
const fs = require('node:fs');
|
|
55
52
|
|
|
56
53
|
const gitLib = require('./worktree-git.js');
|
|
57
54
|
const changesLib = require('./worktree-changes.js');
|
|
58
|
-
const registryLib = require('./worktree-registry.js');
|
|
59
55
|
|
|
60
56
|
const DEFAULT_TTL_MS = 5000;
|
|
61
57
|
|
|
@@ -84,8 +80,7 @@ async function attempt(fn, label) {
|
|
|
84
80
|
// Build a facts provider for one repository.
|
|
85
81
|
//
|
|
86
82
|
// Options (every seam is injectable so tests and hosts can substitute it):
|
|
87
|
-
// repoRoot repository whose
|
|
88
|
-
// readRegistry (repoRoot) -> {ok, worktrees, error}
|
|
83
|
+
// repoRoot repository whose worktree listing is read
|
|
89
84
|
// listWorktrees (repoRoot) -> [{path, branch, detached}] or a promise of
|
|
90
85
|
// the same; the default is the async repository listing
|
|
91
86
|
// summarize (checkoutPath) -> Promise<summary> (worktree-changes shape)
|
|
@@ -105,9 +100,6 @@ function createCheckoutFacts(opts = {}) {
|
|
|
105
100
|
const runAsync = typeof opts.runAsync === 'function' ? opts.runAsync : null;
|
|
106
101
|
const fsImpl = opts.fs && typeof opts.fs.statSync === 'function' ? opts.fs : fs;
|
|
107
102
|
|
|
108
|
-
const readRegistry = typeof opts.readRegistry === 'function'
|
|
109
|
-
? opts.readRegistry
|
|
110
|
-
: (root) => registryLib.readRegistry(root);
|
|
111
103
|
const listWorktrees = typeof opts.listWorktrees === 'function'
|
|
112
104
|
? opts.listWorktrees
|
|
113
105
|
: (root) => gitLib.listWorktreesAsync(root, runAsync ? { runAsync } : {});
|
|
@@ -210,9 +202,9 @@ function createCheckoutFacts(opts = {}) {
|
|
|
210
202
|
return Boolean(first) && sameCheckout(first.path, checkout);
|
|
211
203
|
}
|
|
212
204
|
|
|
213
|
-
// The listing entry for exactly this checkout (resolve-equality
|
|
214
|
-
//
|
|
215
|
-
//
|
|
205
|
+
// The listing entry for exactly this checkout (resolve-equality).
|
|
206
|
+
// Unavailable when the listing fails or the path is not a checkout git
|
|
207
|
+
// knows about.
|
|
216
208
|
function branchFact(checkout, listed) {
|
|
217
209
|
if (!listed.ok) return unavailable(listed.error);
|
|
218
210
|
const entries = Array.isArray(listed.value) ? listed.value : [];
|
|
@@ -225,41 +217,16 @@ function createCheckoutFacts(opts = {}) {
|
|
|
225
217
|
return { ...available(entry.branch), detached: entry.detached === true };
|
|
226
218
|
}
|
|
227
219
|
|
|
228
|
-
// Registry row for this checkout — read ONLY for the one fact it owns, a
|
|
229
|
-
// linked worktree's `createdAt`. `ok:false` (malformed/unreadable registry)
|
|
230
|
-
// and "no row" are different reasons but the same verdict: that creation
|
|
231
|
-
// has no registry answer, so the birth-time fallback decides.
|
|
232
|
-
function registryRow(checkout) {
|
|
233
|
-
let read;
|
|
234
|
-
try {
|
|
235
|
-
read = readRegistry(repoRoot || checkout);
|
|
236
|
-
} catch (err) {
|
|
237
|
-
return { row: null, reason: `registry: ${errorText(err)}` };
|
|
238
|
-
}
|
|
239
|
-
if (!read || read.ok !== true) {
|
|
240
|
-
const reason = (read && read.error) || 'cannot read registry';
|
|
241
|
-
return { row: null, reason };
|
|
242
|
-
}
|
|
243
|
-
const rows = Array.isArray(read.worktrees) ? read.worktrees : [];
|
|
244
|
-
const row = rows.find((candidate) => candidate && typeof candidate.path === 'string'
|
|
245
|
-
&& path.isAbsolute(candidate.path)
|
|
246
|
-
&& path.resolve(candidate.path) === checkout);
|
|
247
|
-
if (!row) return { row: null, reason: 'no registry entry for this checkout' };
|
|
248
|
-
return { row, reason: null };
|
|
249
|
-
}
|
|
250
|
-
|
|
251
220
|
// When the checkout was created (S12). The answer depends on the KIND:
|
|
252
221
|
// principal — when its git HISTORY began: the oldest root commit. Git
|
|
253
222
|
// records nothing older, so an unreadable history stays
|
|
254
223
|
// unavailable instead of borrowing the directory's birth
|
|
255
224
|
// time (which is when the folder was made, not when the
|
|
256
225
|
// project started).
|
|
257
|
-
// worktree — when THAT checkout was created:
|
|
258
|
-
//
|
|
259
|
-
//
|
|
260
|
-
//
|
|
261
|
-
// `source` names which answer came back — 'root-commit', 'registry' or
|
|
262
|
-
// 'birthtime' — and with none readable the fact stays unavailable.
|
|
226
|
+
// worktree — when THAT checkout was created: the directory's birth time.
|
|
227
|
+
// Nothing is stored that could say otherwise (S3).
|
|
228
|
+
// `source` names which answer came back — 'root-commit' or 'birthtime' — and
|
|
229
|
+
// with none readable the fact stays unavailable.
|
|
263
230
|
function birthTimeMs(checkout) {
|
|
264
231
|
try {
|
|
265
232
|
const ms = Number(fsImpl.statSync(checkout).birthtimeMs);
|
|
@@ -270,18 +237,14 @@ function createCheckoutFacts(opts = {}) {
|
|
|
270
237
|
return null;
|
|
271
238
|
}
|
|
272
239
|
|
|
273
|
-
function createdAtFact(checkout,
|
|
240
|
+
function createdAtFact(checkout, principal, root) {
|
|
274
241
|
if (principal) {
|
|
275
242
|
if (root.ok) return { ...available(new Date(root.ms).toISOString()), source: 'root-commit' };
|
|
276
243
|
return { ...unavailable(root.reason), source: null };
|
|
277
244
|
}
|
|
278
|
-
if (row && typeof row.createdAt === 'string' && row.createdAt.length > 0
|
|
279
|
-
&& Number.isFinite(Date.parse(row.createdAt))) {
|
|
280
|
-
return { ...available(row.createdAt), source: 'registry' };
|
|
281
|
-
}
|
|
282
245
|
const birth = birthTimeMs(checkout);
|
|
283
246
|
if (birth === null) {
|
|
284
|
-
return { ...unavailable(
|
|
247
|
+
return { ...unavailable('no readable birth time for this checkout'), source: null };
|
|
285
248
|
}
|
|
286
249
|
return { ...available(new Date(birth).toISOString()), source: 'birthtime' };
|
|
287
250
|
}
|
|
@@ -485,13 +448,10 @@ function createCheckoutFacts(opts = {}) {
|
|
|
485
448
|
|
|
486
449
|
async function read(checkout) {
|
|
487
450
|
const startedAt = now();
|
|
488
|
-
// The expensive git reads run together but only for THIS checkout; the
|
|
489
|
-
//
|
|
490
|
-
// linked worktree's `createdAt`), and the listing is read once because
|
|
491
|
-
// both the branch fact and the checkout KIND need it. The dirty summary is
|
|
451
|
+
// The expensive git reads run together but only for THIS checkout; the listing is
|
|
452
|
+
// read once because both the branch fact and the checkout KIND need it. The dirty summary is
|
|
492
453
|
// computed once and feeds both `changes` and the dirty side of
|
|
493
454
|
// `lastActivity`.
|
|
494
|
-
const registry = registryRow(checkout);
|
|
495
455
|
// The listing is started FIRST and awaited by both the branch fact and the
|
|
496
456
|
// ahead/behind base, so one `git worktree list` serves the whole read.
|
|
497
457
|
const listingRead = attempt(() => listingFor(repoRoot || checkout), 'git worktree list');
|
|
@@ -507,7 +467,7 @@ function createCheckoutFacts(opts = {}) {
|
|
|
507
467
|
const root = principal
|
|
508
468
|
? await rootCommitRead(checkout)
|
|
509
469
|
: { ok: false, reason: 'not the principal checkout' };
|
|
510
|
-
const createdAt = createdAtFact(checkout,
|
|
470
|
+
const createdAt = createdAtFact(checkout, principal, root);
|
|
511
471
|
return {
|
|
512
472
|
checkout,
|
|
513
473
|
fetchedAt: startedAt,
|
|
@@ -573,8 +533,8 @@ function createCheckoutFacts(opts = {}) {
|
|
|
573
533
|
return clone(entry, { stale: !fresh(entry) });
|
|
574
534
|
}
|
|
575
535
|
|
|
576
|
-
// Drop one checkout's cached facts, or all of them (after a create
|
|
577
|
-
//
|
|
536
|
+
// Drop one checkout's cached facts, or all of them (after a create or a
|
|
537
|
+
// commit the selector itself performed).
|
|
578
538
|
function invalidate(checkoutPath) {
|
|
579
539
|
const checkout = keyOf(checkoutPath);
|
|
580
540
|
if (checkout === null) {
|