@moberg_hr/work-tree 1.16.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -142
- package/dist/answer-2J4XLIP7.js +63 -0
- package/dist/answer-2J4XLIP7.js.map +1 -0
- package/dist/attach-CZKRNPAJ.js +59 -0
- package/dist/attach-CZKRNPAJ.js.map +1 -0
- package/dist/bin.js +26 -11924
- package/dist/bin.js.map +1 -1
- package/dist/block-RAIDCJ4F.js +84 -0
- package/dist/block-RAIDCJ4F.js.map +1 -0
- package/dist/broadcast-BSI5NDDB.js +104 -0
- package/dist/broadcast-BSI5NDDB.js.map +1 -0
- package/dist/catchup-VVOPL2S5.js +51 -0
- package/dist/catchup-VVOPL2S5.js.map +1 -0
- package/dist/chunk-3JWTO5VZ.js +135 -0
- package/dist/chunk-3JWTO5VZ.js.map +1 -0
- package/dist/chunk-4BOK2GXL.js +210 -0
- package/dist/chunk-4BOK2GXL.js.map +1 -0
- package/dist/chunk-5QK7GB5K.js +112 -0
- package/dist/chunk-5QK7GB5K.js.map +1 -0
- package/dist/chunk-6AQRYLOB.js +16 -0
- package/dist/chunk-6AQRYLOB.js.map +1 -0
- package/dist/chunk-6FTIY5M6.js +120 -0
- package/dist/chunk-6FTIY5M6.js.map +1 -0
- package/dist/chunk-6H3MLDGG.js +48 -0
- package/dist/chunk-6H3MLDGG.js.map +1 -0
- package/dist/chunk-77XFJQGC.js +103 -0
- package/dist/chunk-77XFJQGC.js.map +1 -0
- package/dist/chunk-7HEB6SQS.js +257 -0
- package/dist/chunk-7HEB6SQS.js.map +1 -0
- package/dist/chunk-7NAXFBFI.js +206 -0
- package/dist/chunk-7NAXFBFI.js.map +1 -0
- package/dist/chunk-7NCW3LUT.js +358 -0
- package/dist/chunk-7NCW3LUT.js.map +1 -0
- package/dist/chunk-7OLPI334.js +537 -0
- package/dist/chunk-7OLPI334.js.map +1 -0
- package/dist/chunk-ABQYKTG4.js +38 -0
- package/dist/chunk-ABQYKTG4.js.map +1 -0
- package/dist/chunk-AH5TM3NB.js +21 -0
- package/dist/chunk-AH5TM3NB.js.map +1 -0
- package/dist/chunk-AKMPF72Y.js +274 -0
- package/dist/chunk-AKMPF72Y.js.map +1 -0
- package/dist/chunk-BR6OPEE4.js +162 -0
- package/dist/chunk-BR6OPEE4.js.map +1 -0
- package/dist/chunk-C2BK6EBN.js +162 -0
- package/dist/chunk-C2BK6EBN.js.map +1 -0
- package/dist/chunk-C2THFSXA.js +37 -0
- package/dist/chunk-C2THFSXA.js.map +1 -0
- package/dist/chunk-C7W5TMFB.js +308 -0
- package/dist/chunk-C7W5TMFB.js.map +1 -0
- package/dist/chunk-CLGVSX36.js +668 -0
- package/dist/chunk-CLGVSX36.js.map +1 -0
- package/dist/chunk-CVAVYDXO.js +295 -0
- package/dist/chunk-CVAVYDXO.js.map +1 -0
- package/dist/chunk-DW4JPVXB.js +41 -0
- package/dist/chunk-DW4JPVXB.js.map +1 -0
- package/dist/chunk-FPKERDK7.js +142 -0
- package/dist/chunk-FPKERDK7.js.map +1 -0
- package/dist/chunk-FR3EWVXI.js +188 -0
- package/dist/chunk-FR3EWVXI.js.map +1 -0
- package/dist/chunk-H5LKMR45.js +117 -0
- package/dist/chunk-H5LKMR45.js.map +1 -0
- package/dist/chunk-HIZBWYPL.js +267 -0
- package/dist/chunk-HIZBWYPL.js.map +1 -0
- package/dist/chunk-HSICXDMZ.js +41 -0
- package/dist/chunk-HSICXDMZ.js.map +1 -0
- package/dist/chunk-HUXS3VAI.js +90 -0
- package/dist/chunk-HUXS3VAI.js.map +1 -0
- package/dist/chunk-HWUINPIL.js +151 -0
- package/dist/chunk-HWUINPIL.js.map +1 -0
- package/dist/chunk-IXKVCR4Y.js +487 -0
- package/dist/chunk-IXKVCR4Y.js.map +1 -0
- package/dist/chunk-JNBYNRFS.js +54 -0
- package/dist/chunk-JNBYNRFS.js.map +1 -0
- package/dist/chunk-JYTMT5DF.js +421 -0
- package/dist/chunk-JYTMT5DF.js.map +1 -0
- package/dist/chunk-KGZ6OZ2T.js +102 -0
- package/dist/chunk-KGZ6OZ2T.js.map +1 -0
- package/dist/chunk-LMIEEDDC.js +9 -0
- package/dist/chunk-LMIEEDDC.js.map +1 -0
- package/dist/chunk-LNHSBM4L.js +26 -0
- package/dist/chunk-LNHSBM4L.js.map +1 -0
- package/dist/chunk-M4FVCAT6.js +2406 -0
- package/dist/chunk-M4FVCAT6.js.map +1 -0
- package/dist/chunk-N4EYQKSM.js +104 -0
- package/dist/chunk-N4EYQKSM.js.map +1 -0
- package/dist/chunk-NDWSLQPB.js +112 -0
- package/dist/chunk-NDWSLQPB.js.map +1 -0
- package/dist/chunk-O3QTWVSK.js +323 -0
- package/dist/chunk-O3QTWVSK.js.map +1 -0
- package/dist/chunk-P3BL4EOP.js +37 -0
- package/dist/chunk-P3BL4EOP.js.map +1 -0
- package/dist/chunk-PN44M5EE.js +887 -0
- package/dist/chunk-PN44M5EE.js.map +1 -0
- package/dist/chunk-Q6WZCO45.js +47 -0
- package/dist/chunk-Q6WZCO45.js.map +1 -0
- package/dist/chunk-QBAZG4CY.js +230 -0
- package/dist/chunk-QBAZG4CY.js.map +1 -0
- package/dist/chunk-R2LN3JJJ.js +132 -0
- package/dist/chunk-R2LN3JJJ.js.map +1 -0
- package/dist/chunk-RCYI7SRA.js +15 -0
- package/dist/chunk-RCYI7SRA.js.map +1 -0
- package/dist/chunk-RYNBBSLY.js +67 -0
- package/dist/chunk-RYNBBSLY.js.map +1 -0
- package/dist/chunk-S5HJT7CM.js +30 -0
- package/dist/chunk-S5HJT7CM.js.map +1 -0
- package/dist/chunk-SNAQOHNL.js +285 -0
- package/dist/chunk-SNAQOHNL.js.map +1 -0
- package/dist/chunk-SOCPIHCS.js +181 -0
- package/dist/chunk-SOCPIHCS.js.map +1 -0
- package/dist/chunk-TUC4QY4O.js +147 -0
- package/dist/chunk-TUC4QY4O.js.map +1 -0
- package/dist/chunk-TUFQJXXO.js +19 -0
- package/dist/chunk-TUFQJXXO.js.map +1 -0
- package/dist/chunk-UFY7C5PP.js +90 -0
- package/dist/chunk-UFY7C5PP.js.map +1 -0
- package/dist/chunk-UQ35KLHH.js +34 -0
- package/dist/chunk-UQ35KLHH.js.map +1 -0
- package/dist/chunk-VJ7SVDED.js +177 -0
- package/dist/chunk-VJ7SVDED.js.map +1 -0
- package/dist/chunk-VJNSIDOA.js +23 -0
- package/dist/chunk-VJNSIDOA.js.map +1 -0
- package/dist/chunk-WF5SBVPZ.js +190 -0
- package/dist/chunk-WF5SBVPZ.js.map +1 -0
- package/dist/chunk-WMJIU3YW.js +29 -0
- package/dist/chunk-WMJIU3YW.js.map +1 -0
- package/dist/chunk-XJDEROHY.js +19 -0
- package/dist/chunk-XJDEROHY.js.map +1 -0
- package/dist/chunk-YKODIG22.js +221 -0
- package/dist/chunk-YKODIG22.js.map +1 -0
- package/dist/chunk-YNKWLC45.js +122 -0
- package/dist/chunk-YNKWLC45.js.map +1 -0
- package/dist/chunk-YZDD5YGE.js +165 -0
- package/dist/chunk-YZDD5YGE.js.map +1 -0
- package/dist/chunk-YZWADOEW.js +151 -0
- package/dist/chunk-YZWADOEW.js.map +1 -0
- package/dist/chunk-ZJN5RWZD.js +76 -0
- package/dist/chunk-ZJN5RWZD.js.map +1 -0
- package/dist/chunk-ZSHWP2VS.js +22 -0
- package/dist/chunk-ZSHWP2VS.js.map +1 -0
- package/dist/chunk-ZXPYWZL5.js +307 -0
- package/dist/chunk-ZXPYWZL5.js.map +1 -0
- package/dist/cleanup-LDBGWEKZ.js +192 -0
- package/dist/cleanup-LDBGWEKZ.js.map +1 -0
- package/dist/cli-UATB4RM2.js +18 -0
- package/dist/cli-UATB4RM2.js.map +1 -0
- package/dist/command-hook-installer-SGEJTZ2Y.js +204 -0
- package/dist/command-hook-installer-SGEJTZ2Y.js.map +1 -0
- package/dist/completion-MXX5TRIV.js +118 -0
- package/dist/completion-MXX5TRIV.js.map +1 -0
- package/dist/config-IEIU7A66.js +410 -0
- package/dist/config-IEIU7A66.js.map +1 -0
- package/dist/console-reporter-XU6VFUZE.js +10 -0
- package/dist/console-reporter-XU6VFUZE.js.map +1 -0
- package/dist/diff-K47HB6SA.js +582 -0
- package/dist/diff-K47HB6SA.js.map +1 -0
- package/dist/digest-FBZTBXQO.js +100 -0
- package/dist/digest-FBZTBXQO.js.map +1 -0
- package/dist/fork-BKI5UNNS.js +120 -0
- package/dist/fork-BKI5UNNS.js.map +1 -0
- package/dist/hook-SLMZT5OV.js +220 -0
- package/dist/hook-SLMZT5OV.js.map +1 -0
- package/dist/hydrate-Y2AAMZTA.js +121 -0
- package/dist/hydrate-Y2AAMZTA.js.map +1 -0
- package/dist/init-7ESFTYZC.js +187 -0
- package/dist/init-7ESFTYZC.js.map +1 -0
- package/dist/install-skills-O34BHFHD.js +14 -0
- package/dist/install-skills-O34BHFHD.js.map +1 -0
- package/dist/install-skills-bin.js +12 -0
- package/dist/install-skills-bin.js.map +1 -0
- package/dist/list-KEF73NLQ.js +126 -0
- package/dist/list-KEF73NLQ.js.map +1 -0
- package/dist/move-FKT2P5LY.js +313 -0
- package/dist/move-FKT2P5LY.js.map +1 -0
- package/dist/note-WGM6LCP2.js +78 -0
- package/dist/note-WGM6LCP2.js.map +1 -0
- package/dist/overlaps-FRLMMIGC.js +56 -0
- package/dist/overlaps-FRLMMIGC.js.map +1 -0
- package/dist/pin-MQ5ZE37R.js +45 -0
- package/dist/pin-MQ5ZE37R.js.map +1 -0
- package/dist/pr-527S5HXB.js +122 -0
- package/dist/pr-527S5HXB.js.map +1 -0
- package/dist/prune-AIS5YEXP.js +92 -0
- package/dist/prune-AIS5YEXP.js.map +1 -0
- package/dist/pty-host-RWIS55N4.js +826 -0
- package/dist/pty-host-RWIS55N4.js.map +1 -0
- package/dist/read-AP6T3ZGN.js +57 -0
- package/dist/read-AP6T3ZGN.js.map +1 -0
- package/dist/recent-IE3LYQ65.js +111 -0
- package/dist/recent-IE3LYQ65.js.map +1 -0
- package/dist/remove-YGUTSKZP.js +108 -0
- package/dist/remove-YGUTSKZP.js.map +1 -0
- package/dist/report-KM4OZCZB.js +16 -0
- package/dist/report-KM4OZCZB.js.map +1 -0
- package/dist/resume-UUP6R2IE.js +81 -0
- package/dist/resume-UUP6R2IE.js.map +1 -0
- package/dist/run-V4755W7C.js +263 -0
- package/dist/run-V4755W7C.js.map +1 -0
- package/dist/screen-DNX4K23V.js +58 -0
- package/dist/screen-DNX4K23V.js.map +1 -0
- package/dist/search-3JZXLCR2.js +46 -0
- package/dist/search-3JZXLCR2.js.map +1 -0
- package/dist/section-TXLC5XO3.js +79 -0
- package/dist/section-TXLC5XO3.js.map +1 -0
- package/dist/send-6X46WZLC.js +87 -0
- package/dist/send-6X46WZLC.js.map +1 -0
- package/dist/sessions-T3QDTNP7.js +135 -0
- package/dist/sessions-T3QDTNP7.js.map +1 -0
- package/dist/snooze-KYSFXLPY.js +65 -0
- package/dist/snooze-KYSFXLPY.js.map +1 -0
- package/dist/start-SQSDQK4F.js +56 -0
- package/dist/start-SQSDQK4F.js.map +1 -0
- package/dist/state-4DFV6SHG.js +147 -0
- package/dist/state-4DFV6SHG.js.map +1 -0
- package/dist/status-H5OW4LYE.js +118 -0
- package/dist/status-H5OW4LYE.js.map +1 -0
- package/dist/stop-HC7XPSSP.js +45 -0
- package/dist/stop-HC7XPSSP.js.map +1 -0
- package/dist/sync-ITK5UYGM.js +96 -0
- package/dist/sync-ITK5UYGM.js.map +1 -0
- package/dist/time-GN6B4QD6.js +111 -0
- package/dist/time-GN6B4QD6.js.map +1 -0
- package/dist/todo-LWMQY6XW.js +152 -0
- package/dist/todo-LWMQY6XW.js.map +1 -0
- package/dist/tree-7BMORJ6J.js +235 -0
- package/dist/tree-7BMORJ6J.js.map +1 -0
- package/dist/update-6LQNLRA4.js +57 -0
- package/dist/update-6LQNLRA4.js.map +1 -0
- package/dist/wait-MZOZQ3CI.js +57 -0
- package/dist/wait-MZOZQ3CI.js.map +1 -0
- package/dist/wd-bin.js +21 -11912
- package/dist/wd-bin.js.map +1 -1
- package/dist/web/assets/PtyView-BrP-ENHg.css +1 -0
- package/dist/web/assets/PtyView-DYvawzWb.js +90 -0
- package/dist/web/assets/PtyView-DYvawzWb.js.map +1 -0
- package/dist/web/assets/index-C5lJhIwK.js +116 -0
- package/dist/web/assets/index-C5lJhIwK.js.map +1 -0
- package/dist/web/assets/index-L8mjakHP.css +1 -0
- package/dist/web/index.html +3 -5
- package/dist/web-IC3P7EHZ.js +7689 -0
- package/dist/web-IC3P7EHZ.js.map +1 -0
- package/npm-shrinkwrap.json +6947 -0
- package/package.json +52 -34
- package/plugins/work-tree/.claude-plugin/plugin.json +1 -1
- package/plugins/work-tree/skills/wd-review/SKILL.md +4 -4
- package/plugins/work-tree/skills/work-sessions/SKILL.md +62 -0
- package/scripts/postinstall.mjs +15 -45
- package/dist/web/assets/index-B9H3vCtL.js +0 -107
- package/dist/web/assets/index-B9H3vCtL.js.map +0 -1
- package/dist/web/assets/index-BseMpW5i.css +0 -1
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
git
|
|
4
|
+
} from "./chunk-7NAXFBFI.js";
|
|
5
|
+
import {
|
|
6
|
+
writeTempTree
|
|
7
|
+
} from "./chunk-M4FVCAT6.js";
|
|
8
|
+
import {
|
|
9
|
+
spawn_default
|
|
10
|
+
} from "./chunk-RCYI7SRA.js";
|
|
11
|
+
import {
|
|
12
|
+
report
|
|
13
|
+
} from "./chunk-DW4JPVXB.js";
|
|
14
|
+
|
|
15
|
+
// src/core/diff/diff-pipeline.ts
|
|
16
|
+
import fs2 from "fs";
|
|
17
|
+
import path2 from "path";
|
|
18
|
+
|
|
19
|
+
// src/core/diff/diff-parse.ts
|
|
20
|
+
var HUNK_RE = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/;
|
|
21
|
+
function parseGitDiff(input) {
|
|
22
|
+
const lines = input.split(/\r?\n/);
|
|
23
|
+
const files = [];
|
|
24
|
+
let current = null;
|
|
25
|
+
let currentHunk = null;
|
|
26
|
+
let oldLineNum = 0;
|
|
27
|
+
let newLineNum = 0;
|
|
28
|
+
function startFile(oldPath, newPath) {
|
|
29
|
+
const f = {
|
|
30
|
+
path: newPath !== "/dev/null" ? newPath : oldPath,
|
|
31
|
+
oldPath,
|
|
32
|
+
newPath,
|
|
33
|
+
status: "modified",
|
|
34
|
+
isBinary: false,
|
|
35
|
+
added: 0,
|
|
36
|
+
deleted: 0,
|
|
37
|
+
hunks: []
|
|
38
|
+
};
|
|
39
|
+
files.push(f);
|
|
40
|
+
return f;
|
|
41
|
+
}
|
|
42
|
+
for (let i = 0; i < lines.length; i++) {
|
|
43
|
+
const line = lines[i];
|
|
44
|
+
if (line.startsWith("diff --git ")) {
|
|
45
|
+
current = null;
|
|
46
|
+
currentHunk = null;
|
|
47
|
+
const match = line.match(/^diff --git "?a\/(.+?)"? "?b\/(.+?)"?$/);
|
|
48
|
+
if (match) {
|
|
49
|
+
current = startFile(match[1], match[2]);
|
|
50
|
+
}
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (!current) continue;
|
|
54
|
+
if (line.startsWith("new file mode")) {
|
|
55
|
+
current.status = "added";
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (line.startsWith("deleted file mode")) {
|
|
59
|
+
current.status = "deleted";
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (line.startsWith("rename from ")) {
|
|
63
|
+
current.status = "renamed";
|
|
64
|
+
current.oldPath = line.slice("rename from ".length);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (line.startsWith("rename to ")) {
|
|
68
|
+
current.newPath = line.slice("rename to ".length);
|
|
69
|
+
current.path = current.newPath;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (line.startsWith("Binary files ")) {
|
|
73
|
+
current.isBinary = true;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (line.startsWith("--- ")) {
|
|
77
|
+
const p = stripPathPrefix(line.slice(4));
|
|
78
|
+
if (p === "/dev/null") {
|
|
79
|
+
current.status = "added";
|
|
80
|
+
} else {
|
|
81
|
+
current.oldPath = p;
|
|
82
|
+
}
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (line.startsWith("+++ ")) {
|
|
86
|
+
const p = stripPathPrefix(line.slice(4));
|
|
87
|
+
if (p === "/dev/null") {
|
|
88
|
+
current.status = "deleted";
|
|
89
|
+
} else {
|
|
90
|
+
current.newPath = p;
|
|
91
|
+
current.path = p;
|
|
92
|
+
}
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const hunkMatch = line.match(HUNK_RE);
|
|
96
|
+
if (hunkMatch) {
|
|
97
|
+
currentHunk = {
|
|
98
|
+
oldStart: Number(hunkMatch[1]),
|
|
99
|
+
oldLines: hunkMatch[2] ? Number(hunkMatch[2]) : 1,
|
|
100
|
+
newStart: Number(hunkMatch[3]),
|
|
101
|
+
newLines: hunkMatch[4] ? Number(hunkMatch[4]) : 1,
|
|
102
|
+
context: hunkMatch[5].trim(),
|
|
103
|
+
lines: []
|
|
104
|
+
};
|
|
105
|
+
oldLineNum = currentHunk.oldStart;
|
|
106
|
+
newLineNum = currentHunk.newStart;
|
|
107
|
+
current.hunks.push(currentHunk);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (!currentHunk) continue;
|
|
111
|
+
const marker = line[0] ?? " ";
|
|
112
|
+
const body = line.slice(1);
|
|
113
|
+
if (marker === "\\") {
|
|
114
|
+
currentHunk.lines.push({
|
|
115
|
+
kind: "no-newline",
|
|
116
|
+
content: line,
|
|
117
|
+
oldNum: null,
|
|
118
|
+
newNum: null
|
|
119
|
+
});
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (marker === "+") {
|
|
123
|
+
currentHunk.lines.push({
|
|
124
|
+
kind: "add",
|
|
125
|
+
content: body,
|
|
126
|
+
oldNum: null,
|
|
127
|
+
newNum: newLineNum++
|
|
128
|
+
});
|
|
129
|
+
current.added++;
|
|
130
|
+
} else if (marker === "-") {
|
|
131
|
+
currentHunk.lines.push({
|
|
132
|
+
kind: "delete",
|
|
133
|
+
content: body,
|
|
134
|
+
oldNum: oldLineNum++,
|
|
135
|
+
newNum: null
|
|
136
|
+
});
|
|
137
|
+
current.deleted++;
|
|
138
|
+
} else {
|
|
139
|
+
currentHunk.lines.push({
|
|
140
|
+
kind: "context",
|
|
141
|
+
content: body,
|
|
142
|
+
oldNum: oldLineNum++,
|
|
143
|
+
newNum: newLineNum++
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
for (const f of files) {
|
|
148
|
+
if (f.status === "modified" && f.oldPath !== f.newPath) {
|
|
149
|
+
f.status = "renamed";
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return files;
|
|
153
|
+
}
|
|
154
|
+
function stripPathPrefix(p) {
|
|
155
|
+
const trimmed = p.trim().replace(/^"|"$/g, "");
|
|
156
|
+
if (trimmed === "/dev/null") return trimmed;
|
|
157
|
+
if (trimmed.startsWith("a/") || trimmed.startsWith("b/")) {
|
|
158
|
+
return trimmed.slice(2);
|
|
159
|
+
}
|
|
160
|
+
return trimmed;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// src/core/diff/lcov.ts
|
|
164
|
+
import fs from "fs";
|
|
165
|
+
import path from "path";
|
|
166
|
+
function parseLcov(content) {
|
|
167
|
+
const result = /* @__PURE__ */ new Map();
|
|
168
|
+
let sf = null;
|
|
169
|
+
let lf = null;
|
|
170
|
+
let lh = null;
|
|
171
|
+
let daTotal = 0;
|
|
172
|
+
let daHit = 0;
|
|
173
|
+
const finish = () => {
|
|
174
|
+
if (sf === null) return;
|
|
175
|
+
let pct;
|
|
176
|
+
if (lf !== null && lf > 0) {
|
|
177
|
+
pct = (lh ?? 0) / lf * 100;
|
|
178
|
+
} else if (lf === 0) {
|
|
179
|
+
pct = 0;
|
|
180
|
+
} else if (daTotal > 0) {
|
|
181
|
+
pct = daHit / daTotal * 100;
|
|
182
|
+
} else {
|
|
183
|
+
pct = 0;
|
|
184
|
+
}
|
|
185
|
+
result.set(sf, pct);
|
|
186
|
+
};
|
|
187
|
+
const reset = () => {
|
|
188
|
+
sf = null;
|
|
189
|
+
lf = null;
|
|
190
|
+
lh = null;
|
|
191
|
+
daTotal = 0;
|
|
192
|
+
daHit = 0;
|
|
193
|
+
};
|
|
194
|
+
for (const raw of content.split("\n")) {
|
|
195
|
+
const line = raw.trim();
|
|
196
|
+
if (line.startsWith("SF:")) {
|
|
197
|
+
sf = line.slice(3).trim();
|
|
198
|
+
} else if (line.startsWith("DA:")) {
|
|
199
|
+
const rest = line.slice(3);
|
|
200
|
+
const comma = rest.indexOf(",");
|
|
201
|
+
if (comma !== -1) {
|
|
202
|
+
const hits = Number(rest.slice(comma + 1).split(",")[0]);
|
|
203
|
+
if (Number.isFinite(hits)) {
|
|
204
|
+
daTotal += 1;
|
|
205
|
+
if (hits > 0) daHit += 1;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
} else if (line.startsWith("LF:")) {
|
|
209
|
+
const n = Number(line.slice(3).trim());
|
|
210
|
+
if (Number.isFinite(n)) lf = n;
|
|
211
|
+
} else if (line.startsWith("LH:")) {
|
|
212
|
+
const n = Number(line.slice(3).trim());
|
|
213
|
+
if (Number.isFinite(n)) lh = n;
|
|
214
|
+
} else if (line === "end_of_record") {
|
|
215
|
+
finish();
|
|
216
|
+
reset();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
finish();
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
222
|
+
function findLcov(root) {
|
|
223
|
+
const candidates = [path.join(root, "coverage", "lcov.info"), path.join(root, "lcov.info")];
|
|
224
|
+
for (const c of candidates) {
|
|
225
|
+
try {
|
|
226
|
+
if (fs.statSync(c).isFile()) return c;
|
|
227
|
+
} catch {
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
var lcovCache = /* @__PURE__ */ new Map();
|
|
233
|
+
function readParsedLcov(lcovPath) {
|
|
234
|
+
let mtimeMs;
|
|
235
|
+
try {
|
|
236
|
+
mtimeMs = fs.statSync(lcovPath).mtimeMs;
|
|
237
|
+
} catch {
|
|
238
|
+
lcovCache.delete(lcovPath);
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
const cached = lcovCache.get(lcovPath);
|
|
242
|
+
if (cached && cached.mtimeMs === mtimeMs) {
|
|
243
|
+
return { parsed: cached.parsed, mtimeMs };
|
|
244
|
+
}
|
|
245
|
+
let content;
|
|
246
|
+
try {
|
|
247
|
+
content = fs.readFileSync(lcovPath, "utf-8");
|
|
248
|
+
} catch {
|
|
249
|
+
lcovCache.delete(lcovPath);
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
const parsed = parseLcov(content);
|
|
253
|
+
lcovCache.set(lcovPath, { mtimeMs, parsed });
|
|
254
|
+
return { parsed, mtimeMs };
|
|
255
|
+
}
|
|
256
|
+
function normRel(p) {
|
|
257
|
+
return path.normalize(p).replace(/\\/g, "/").replace(/^\.\//, "");
|
|
258
|
+
}
|
|
259
|
+
function realRoot(root) {
|
|
260
|
+
try {
|
|
261
|
+
return fs.realpathSync(path.resolve(root));
|
|
262
|
+
} catch {
|
|
263
|
+
return path.resolve(root);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function canonicalize(absPath) {
|
|
267
|
+
const resolved = path.resolve(absPath);
|
|
268
|
+
let dir = resolved;
|
|
269
|
+
const tail = [];
|
|
270
|
+
for (; ; ) {
|
|
271
|
+
try {
|
|
272
|
+
const realDir = fs.realpathSync(dir);
|
|
273
|
+
return tail.length ? path.join(realDir, ...tail.reverse()) : realDir;
|
|
274
|
+
} catch {
|
|
275
|
+
const parent = path.dirname(dir);
|
|
276
|
+
if (parent === dir) return resolved;
|
|
277
|
+
tail.push(path.basename(dir));
|
|
278
|
+
dir = parent;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function relForAbsSf(absSf, canonRoot) {
|
|
283
|
+
return path.relative(canonRoot, canonicalize(absSf));
|
|
284
|
+
}
|
|
285
|
+
function coverageLookup(root, relPaths) {
|
|
286
|
+
const out = /* @__PURE__ */ new Map();
|
|
287
|
+
const lcovPath = findLcov(root);
|
|
288
|
+
if (!lcovPath) return { byPath: out, lcovMtimeMs: null };
|
|
289
|
+
const read = readParsedLcov(lcovPath);
|
|
290
|
+
if (!read || read.parsed.size === 0) {
|
|
291
|
+
return { byPath: out, lcovMtimeMs: read?.mtimeMs ?? null };
|
|
292
|
+
}
|
|
293
|
+
const canonRoot = realRoot(root);
|
|
294
|
+
const byRel = /* @__PURE__ */ new Map();
|
|
295
|
+
for (const [sf, pct] of read.parsed) {
|
|
296
|
+
const rel = path.isAbsolute(sf) ? relForAbsSf(sf, canonRoot) : sf;
|
|
297
|
+
byRel.set(normRel(rel), pct);
|
|
298
|
+
}
|
|
299
|
+
for (const rp of relPaths) {
|
|
300
|
+
const pct = byRel.get(normRel(rp));
|
|
301
|
+
if (typeof pct === "number") out.set(rp, pct);
|
|
302
|
+
}
|
|
303
|
+
return { byPath: out, lcovMtimeMs: read.mtimeMs };
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// src/core/diff/diff-pipeline.ts
|
|
307
|
+
var RENAME_DETECT = "-M";
|
|
308
|
+
var MARKDOWN_EXT_RE = /\.(md|markdown|mdx)$/i;
|
|
309
|
+
var MARKDOWN_SIZE_CAP = 256 * 1024;
|
|
310
|
+
function isMarkdownPath(p) {
|
|
311
|
+
return p !== "/dev/null" && MARKDOWN_EXT_RE.test(p);
|
|
312
|
+
}
|
|
313
|
+
function isInsideRoot(root, rel) {
|
|
314
|
+
const resolvedRoot = path2.resolve(root);
|
|
315
|
+
const resolvedTarget = path2.resolve(resolvedRoot, rel);
|
|
316
|
+
const r = path2.relative(resolvedRoot, resolvedTarget);
|
|
317
|
+
if (r === "") return true;
|
|
318
|
+
if (r.startsWith("..")) return false;
|
|
319
|
+
if (path2.isAbsolute(r)) return false;
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
function readMarkdownContent(root, file, fromRef, toRef) {
|
|
323
|
+
if (file.isBinary) return void 0;
|
|
324
|
+
if (!isMarkdownPath(file.oldPath) && !isMarkdownPath(file.newPath)) {
|
|
325
|
+
return void 0;
|
|
326
|
+
}
|
|
327
|
+
const showAt = (ref, p) => {
|
|
328
|
+
const r = spawn_default.sync("git", ["show", "--end-of-options", `${ref}:${p}`], {
|
|
329
|
+
cwd: root,
|
|
330
|
+
encoding: "utf-8",
|
|
331
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
332
|
+
windowsHide: true
|
|
333
|
+
});
|
|
334
|
+
if (r.status === 0 && typeof r.stdout === "string") return r.stdout;
|
|
335
|
+
return void 0;
|
|
336
|
+
};
|
|
337
|
+
const result = {};
|
|
338
|
+
if (file.status !== "added" && isMarkdownPath(file.oldPath) && isInsideRoot(root, file.oldPath)) {
|
|
339
|
+
result.before = showAt(fromRef, file.oldPath);
|
|
340
|
+
}
|
|
341
|
+
if (file.status !== "deleted" && isMarkdownPath(file.newPath) && isInsideRoot(root, file.newPath)) {
|
|
342
|
+
if (toRef === "working") {
|
|
343
|
+
try {
|
|
344
|
+
const absPath = path2.join(root, file.newPath);
|
|
345
|
+
const realRoot2 = fs2.realpathSync(path2.resolve(root));
|
|
346
|
+
const realPath = fs2.realpathSync(absPath);
|
|
347
|
+
const sep = path2.sep;
|
|
348
|
+
if (realPath === realRoot2 || realPath.startsWith(realRoot2 + sep)) {
|
|
349
|
+
result.after = fs2.readFileSync(absPath, "utf-8");
|
|
350
|
+
}
|
|
351
|
+
} catch {
|
|
352
|
+
}
|
|
353
|
+
} else {
|
|
354
|
+
result.after = showAt(toRef, file.newPath);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (result.before === void 0 && result.after === void 0) {
|
|
358
|
+
return void 0;
|
|
359
|
+
}
|
|
360
|
+
const tooBig = result.before !== void 0 && Buffer.byteLength(result.before, "utf-8") > MARKDOWN_SIZE_CAP || result.after !== void 0 && Buffer.byteLength(result.after, "utf-8") > MARKDOWN_SIZE_CAP;
|
|
361
|
+
if (tooBig) {
|
|
362
|
+
return { tooLarge: true };
|
|
363
|
+
}
|
|
364
|
+
return result;
|
|
365
|
+
}
|
|
366
|
+
function workingTreeTreeSha(root) {
|
|
367
|
+
return writeTempTree(root, { includeWorkingTree: true })?.treeSha ?? null;
|
|
368
|
+
}
|
|
369
|
+
function isBinaryContent(buffer) {
|
|
370
|
+
const len = Math.min(buffer.length, 8192);
|
|
371
|
+
for (let i = 0; i < len; i++) {
|
|
372
|
+
if (buffer[i] === 0) return true;
|
|
373
|
+
}
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
function synthesizeUntrackedDiff(root, relPath) {
|
|
377
|
+
const absPath = path2.join(root, relPath);
|
|
378
|
+
let buffer;
|
|
379
|
+
try {
|
|
380
|
+
buffer = fs2.readFileSync(absPath);
|
|
381
|
+
} catch {
|
|
382
|
+
return "";
|
|
383
|
+
}
|
|
384
|
+
const header = `diff --git a/${relPath} b/${relPath}
|
|
385
|
+
new file mode 100644
|
|
386
|
+
`;
|
|
387
|
+
if (isBinaryContent(buffer)) {
|
|
388
|
+
return `${header}Binary files /dev/null and b/${relPath} differ
|
|
389
|
+
`;
|
|
390
|
+
}
|
|
391
|
+
const content = buffer.toString("utf-8");
|
|
392
|
+
if (content.length === 0) {
|
|
393
|
+
return `${header}--- /dev/null
|
|
394
|
+
+++ b/${relPath}
|
|
395
|
+
`;
|
|
396
|
+
}
|
|
397
|
+
const hasTrailingNewline = content.endsWith("\n");
|
|
398
|
+
const lines = content.split("\n");
|
|
399
|
+
if (hasTrailingNewline) lines.pop();
|
|
400
|
+
let out = `${header}--- /dev/null
|
|
401
|
+
+++ b/${relPath}
|
|
402
|
+
@@ -0,0 +1,${lines.length} @@
|
|
403
|
+
`;
|
|
404
|
+
for (const line of lines) {
|
|
405
|
+
out += `+${line}
|
|
406
|
+
`;
|
|
407
|
+
}
|
|
408
|
+
if (!hasTrailingNewline) {
|
|
409
|
+
out += `\
|
|
410
|
+
`;
|
|
411
|
+
}
|
|
412
|
+
return out;
|
|
413
|
+
}
|
|
414
|
+
function computeDiff(opts) {
|
|
415
|
+
const { root, diffArg } = opts;
|
|
416
|
+
const trackedResult = spawn_default.sync(
|
|
417
|
+
"git",
|
|
418
|
+
// -w (ignore-all-space) hides pure whitespace changes so a reformat
|
|
419
|
+
// of indentation doesn't drown out the real changes. RENAME_DETECT turns
|
|
420
|
+
// on rename detection so a `git mv` (+ edits) shows as one renamed entry
|
|
421
|
+
// with its inline diff instead of a separate delete + add pair.
|
|
422
|
+
["diff", "--no-color", "--no-ext-diff", "-w", RENAME_DETECT, diffArg],
|
|
423
|
+
{
|
|
424
|
+
cwd: root,
|
|
425
|
+
encoding: "utf-8",
|
|
426
|
+
maxBuffer: 500 * 1024 * 1024,
|
|
427
|
+
windowsHide: true
|
|
428
|
+
}
|
|
429
|
+
);
|
|
430
|
+
if (trackedResult.status !== 0) {
|
|
431
|
+
if (trackedResult.stderr) report("error", trackedResult.stderr);
|
|
432
|
+
return [];
|
|
433
|
+
}
|
|
434
|
+
let combined = trackedResult.stdout;
|
|
435
|
+
const untrackedResult = git(["ls-files", "--others", "--exclude-standard"], root);
|
|
436
|
+
if (untrackedResult.exitCode === 0 && untrackedResult.stdout) {
|
|
437
|
+
const files2 = untrackedResult.stdout.split("\n").filter(Boolean);
|
|
438
|
+
for (const file of files2) {
|
|
439
|
+
const block = synthesizeUntrackedDiff(root, file);
|
|
440
|
+
if (block) combined += block;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
const files = parseGitDiff(combined);
|
|
444
|
+
attachCoverage(root, files);
|
|
445
|
+
for (const file of files) {
|
|
446
|
+
const md = readMarkdownContent(root, file, diffArg, "working");
|
|
447
|
+
if (md) file.mdContent = md;
|
|
448
|
+
}
|
|
449
|
+
return files;
|
|
450
|
+
}
|
|
451
|
+
function attachCoverage(root, files) {
|
|
452
|
+
const { byPath, lcovMtimeMs } = coverageLookup(
|
|
453
|
+
root,
|
|
454
|
+
files.map((f) => f.path)
|
|
455
|
+
);
|
|
456
|
+
if (byPath.size === 0) return;
|
|
457
|
+
for (const f of files) {
|
|
458
|
+
const pct = byPath.get(f.path);
|
|
459
|
+
if (typeof pct !== "number") continue;
|
|
460
|
+
f.coverage = pct;
|
|
461
|
+
if (lcovMtimeMs != null) {
|
|
462
|
+
f.coverageMtimeMs = lcovMtimeMs;
|
|
463
|
+
let srcMtimeMs;
|
|
464
|
+
try {
|
|
465
|
+
srcMtimeMs = fs2.statSync(path2.join(root, f.path)).mtimeMs;
|
|
466
|
+
} catch {
|
|
467
|
+
srcMtimeMs = null;
|
|
468
|
+
}
|
|
469
|
+
if (srcMtimeMs != null && srcMtimeMs > lcovMtimeMs) {
|
|
470
|
+
f.coverageStale = true;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
function computeRangeDiff(opts) {
|
|
476
|
+
const { root, fromRef, toRef } = opts;
|
|
477
|
+
if (toRef === "working") {
|
|
478
|
+
if (fromRef === "HEAD") {
|
|
479
|
+
return computeDiff({ root, diffArg: fromRef });
|
|
480
|
+
}
|
|
481
|
+
const wtTreeSha = workingTreeTreeSha(root);
|
|
482
|
+
if (!wtTreeSha) return [];
|
|
483
|
+
const result2 = spawn_default.sync(
|
|
484
|
+
"git",
|
|
485
|
+
// RENAME_DETECT: detect renames between the checkpoint tree and the
|
|
486
|
+
// working tree so a rename (with or without edits) renders as one
|
|
487
|
+
// entry, matching the HEAD-vs-working path above.
|
|
488
|
+
["diff-tree", "-r", "-p", RENAME_DETECT, "--no-color", "--no-ext-diff", fromRef, wtTreeSha],
|
|
489
|
+
{
|
|
490
|
+
cwd: root,
|
|
491
|
+
encoding: "utf-8",
|
|
492
|
+
maxBuffer: 500 * 1024 * 1024,
|
|
493
|
+
windowsHide: true
|
|
494
|
+
}
|
|
495
|
+
);
|
|
496
|
+
if (result2.status !== 0) {
|
|
497
|
+
if (result2.stderr) report("error", result2.stderr);
|
|
498
|
+
return [];
|
|
499
|
+
}
|
|
500
|
+
const parsed = parseGitDiff(result2.stdout);
|
|
501
|
+
for (const file of parsed) {
|
|
502
|
+
const md = readMarkdownContent(root, file, fromRef, "working");
|
|
503
|
+
if (md) file.mdContent = md;
|
|
504
|
+
}
|
|
505
|
+
return parsed;
|
|
506
|
+
}
|
|
507
|
+
const result = spawn_default.sync(
|
|
508
|
+
"git",
|
|
509
|
+
// RENAME_DETECT: rename detection between two checkpoint commits (no -w
|
|
510
|
+
// here — see the note above on why range diffs keep whitespace changes).
|
|
511
|
+
["diff", "--no-color", "--no-ext-diff", RENAME_DETECT, fromRef, toRef],
|
|
512
|
+
{
|
|
513
|
+
cwd: root,
|
|
514
|
+
encoding: "utf-8",
|
|
515
|
+
maxBuffer: 500 * 1024 * 1024,
|
|
516
|
+
windowsHide: true
|
|
517
|
+
}
|
|
518
|
+
);
|
|
519
|
+
if (result.status !== 0) {
|
|
520
|
+
if (result.stderr) report("error", result.stderr);
|
|
521
|
+
return [];
|
|
522
|
+
}
|
|
523
|
+
const files = parseGitDiff(result.stdout);
|
|
524
|
+
for (const file of files) {
|
|
525
|
+
const md = readMarkdownContent(root, file, fromRef, toRef);
|
|
526
|
+
if (md) file.mdContent = md;
|
|
527
|
+
}
|
|
528
|
+
return files;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
export {
|
|
532
|
+
parseGitDiff,
|
|
533
|
+
isInsideRoot,
|
|
534
|
+
computeDiff,
|
|
535
|
+
computeRangeDiff
|
|
536
|
+
};
|
|
537
|
+
//# sourceMappingURL=chunk-7OLPI334.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/diff/diff-pipeline.ts","../src/core/diff/diff-parse.ts","../src/core/diff/lcov.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport spawn from '../platform/spawn.js';\nimport { git } from '../git/git.js';\nimport { parseGitDiff, type MarkdownContent, type ParsedFile } from './diff-parse.js';\nimport { coverageLookup } from './lcov.js';\nimport { writeTempTree } from './git-tree-snapshot.js';\nimport { report } from '../platform/report.js';\n\n/** `git`'s rename-detection flag. Centralised so the three diff invocations\n * (HEAD-vs-working, checkpoint-vs-working, checkpoint-vs-checkpoint) stay in\n * lockstep — tuning the threshold (e.g. `-M40%`) or disabling it is a\n * one-line change here. */\nconst RENAME_DETECT = '-M';\n\nconst MARKDOWN_EXT_RE = /\\.(md|markdown|mdx)$/i;\n\n/** Per-side cap on markdown content embedded in the diff payload. A\n * 256 KiB ceiling covers normal docs (README, CHANGELOG up to a year\n * of releases, design docs) while preventing auto-generated multi-MB\n * markdown (API refs, vendored docs) from ballooning SSE reload\n * traffic and the browser heap. When either side hits the cap, both\n * sides are dropped and `tooLarge: true` is set so the SPA hides the\n * Preview/Split toggle. */\nconst MARKDOWN_SIZE_CAP = 256 * 1024;\n\nfunction isMarkdownPath(p: string): boolean {\n return p !== '/dev/null' && MARKDOWN_EXT_RE.test(p);\n}\n\n/**\n * Reject paths that would resolve outside the repo root. Diff output is\n * parsed text — a pathological commit (or a manipulated diff stream) could\n * carry `../../etc/passwd`-style entries. Without this check, the markdown\n * \"after\" read would happily exfiltrate arbitrary local files into the\n * SPA's diff payload.\n *\n * Exported for unit testing — also useful to other call sites that\n * consume `ParsedFile.path` for filesystem access.\n */\nexport function isInsideRoot(root: string, rel: string): boolean {\n const resolvedRoot = path.resolve(root);\n const resolvedTarget = path.resolve(resolvedRoot, rel);\n // path.relative returns \"\" for the same dir, \"subdir/x\" for nested, or\n // a \"../\" path for escapes — easiest portable check.\n const r = path.relative(resolvedRoot, resolvedTarget);\n if (r === '') return true;\n if (r.startsWith('..')) return false;\n if (path.isAbsolute(r)) return false;\n return true;\n}\n\n/**\n * For markdown files, fetch the \"before\" content via `git show <fromRef>:<oldPath>`\n * and the \"after\" content either from the working tree (when comparing\n * against the working tree) or from `git show <toRef>:<newPath>` (when\n * comparing two committed snapshots). Either side may be absent for added\n * / deleted / failed fetches.\n *\n * Uses `cross-spawn` directly (not the `git()` helper) because that helper\n * trims stdout, which would silently drop trailing newlines in the source.\n */\nfunction readMarkdownContent(root: string, file: ParsedFile, fromRef: string, toRef: string | 'working'): MarkdownContent | undefined {\n if (file.isBinary) return undefined;\n if (!isMarkdownPath(file.oldPath) && !isMarkdownPath(file.newPath)) {\n return undefined;\n }\n\n const showAt = (ref: string, p: string): string | undefined => {\n const r = spawn.sync('git', ['show', '--end-of-options', `${ref}:${p}`], {\n cwd: root,\n encoding: 'utf-8',\n maxBuffer: 16 * 1024 * 1024,\n windowsHide: true,\n });\n if (r.status === 0 && typeof r.stdout === 'string') return r.stdout;\n return undefined;\n };\n\n const result: MarkdownContent = {};\n\n if (file.status !== 'added' && isMarkdownPath(file.oldPath) && isInsideRoot(root, file.oldPath)) {\n result.before = showAt(fromRef, file.oldPath);\n }\n\n if (file.status !== 'deleted' && isMarkdownPath(file.newPath) && isInsideRoot(root, file.newPath)) {\n if (toRef === 'working') {\n try {\n const absPath = path.join(root, file.newPath);\n // Resolve symlinks BEFORE reading. The `isInsideRoot` check\n // above blocks `../`-style traversal in the textual path, but\n // a repo could legitimately contain a symlink whose target\n // sits outside the worktree (e.g. `notes.md -> /etc/passwd`).\n // Without this, opening a clone of an adversarial repo would\n // exfiltrate the target into the diff payload.\n //\n // Both sides of the containment comparison MUST be canonical:\n // on macOS `/tmp` and `/var` are themselves symlinks (to\n // `/private/tmp` and `/private/var`), and `path.resolve` does\n // NOT follow symlinks — only `realpath` does. Without\n // canonicalising `root` too, every working-tree path under a\n // symlinked ancestor (default `/var/folders/...` TMPDIR target\n // on macOS, plus Linux mounts and Windows directory junctions)\n // resolves to a different namespace from `root`, the relative\n // path comes out `..`-prefixed, and the guard silently rejects\n // legitimate in-repo files.\n const realRoot = fs.realpathSync(path.resolve(root));\n const realPath = fs.realpathSync(absPath);\n const sep = path.sep;\n if (realPath === realRoot || realPath.startsWith(realRoot + sep)) {\n result.after = fs.readFileSync(absPath, 'utf-8');\n }\n } catch {\n // Working-tree file missing OR realpath failed — no after-content.\n }\n } else {\n result.after = showAt(toRef, file.newPath);\n }\n }\n\n if (result.before === undefined && result.after === undefined) {\n return undefined;\n }\n // Drop both sides when either exceeds the cap. We compare byte length\n // (Buffer.byteLength) rather than `.length`, which counts UTF-16\n // code units in JS and undercounts multi-byte characters — the\n // browser pays for bytes, not chars.\n const tooBig =\n (result.before !== undefined && Buffer.byteLength(result.before, 'utf-8') > MARKDOWN_SIZE_CAP) ||\n (result.after !== undefined && Buffer.byteLength(result.after, 'utf-8') > MARKDOWN_SIZE_CAP);\n if (tooBig) {\n return { tooLarge: true };\n }\n return result;\n}\n\nexport interface ComputeDiffOptions {\n /** Git toplevel working directory. */\n root: string;\n /** Argument to `git diff` (ref, sha, or \"HEAD\"). */\n diffArg: string;\n}\n\n/**\n * Tree-sha snapshot of the current working tree (incl. untracked, subject to\n * .gitignore) without disturbing the real git index. Used by\n * `computeRangeDiff` to do a true tree-vs-tree diff against a checkpoint\n * commit: `git diff <ref>` would otherwise produce phantom \"deleted\" entries\n * for files that were untracked-at-snapshot-time, because git's working-tree\n * diff goes through the real index and untracked files appear \"absent\".\n *\n * Thin wrapper over the shared `writeTempTree` helper (also used by\n * `checkpoint.ts::snapshotRepo`).\n */\nfunction workingTreeTreeSha(root: string): string | null {\n return writeTempTree(root, { includeWorkingTree: true })?.treeSha ?? null;\n}\n\n/**\n * Detect binary content by scanning the first 8 KiB for null bytes. Matches\n * what most text-handling tools (git itself, less, vim) use as a heuristic.\n */\nfunction isBinaryContent(buffer: Buffer): boolean {\n const len = Math.min(buffer.length, 8192);\n for (let i = 0; i < len; i++) {\n if (buffer[i] === 0) return true;\n }\n return false;\n}\n\n/**\n * Render a unified-diff block for a single untracked file as if it were\n * being added. Avoids mutating the git index (which the previous\n * `add --intent-to-add` / `reset` approach did, with risk of leaving stale\n * index entries on crash).\n */\nfunction synthesizeUntrackedDiff(root: string, relPath: string): string {\n const absPath = path.join(root, relPath);\n let buffer: Buffer;\n try {\n buffer = fs.readFileSync(absPath);\n } catch {\n return '';\n }\n\n const header = `diff --git a/${relPath} b/${relPath}\\nnew file mode 100644\\n`;\n\n if (isBinaryContent(buffer)) {\n return `${header}Binary files /dev/null and b/${relPath} differ\\n`;\n }\n\n const content = buffer.toString('utf-8');\n if (content.length === 0) {\n // Empty file — no hunks, just the headers.\n return `${header}--- /dev/null\\n+++ b/${relPath}\\n`;\n }\n\n const hasTrailingNewline = content.endsWith('\\n');\n const lines = content.split('\\n');\n if (hasTrailingNewline) lines.pop();\n\n let out = `${header}--- /dev/null\\n+++ b/${relPath}\\n@@ -0,0 +1,${lines.length} @@\\n`;\n for (const line of lines) {\n out += `+${line}\\n`;\n }\n if (!hasTrailingNewline) {\n out += `\\\\\n`;\n }\n return out;\n}\n\n/**\n * Run `git diff <ref>` against the working tree, then synthesize unified-diff\n * blocks for any untracked files (so they show up as new). Read-only — no\n * changes to the git index, safe under concurrent invocations and crash.\n */\nexport function computeDiff(opts: ComputeDiffOptions): ParsedFile[] {\n const { root, diffArg } = opts;\n\n const trackedResult = spawn.sync(\n 'git',\n // -w (ignore-all-space) hides pure whitespace changes so a reformat\n // of indentation doesn't drown out the real changes. RENAME_DETECT turns\n // on rename detection so a `git mv` (+ edits) shows as one renamed entry\n // with its inline diff instead of a separate delete + add pair.\n ['diff', '--no-color', '--no-ext-diff', '-w', RENAME_DETECT, diffArg],\n {\n cwd: root,\n encoding: 'utf-8',\n maxBuffer: 500 * 1024 * 1024,\n windowsHide: true,\n },\n );\n if (trackedResult.status !== 0) {\n if (trackedResult.stderr) report('error', trackedResult.stderr);\n return [];\n }\n\n let combined = trackedResult.stdout;\n\n // Append synthetic diffs for untracked files (respecting .gitignore).\n const untrackedResult = git(['ls-files', '--others', '--exclude-standard'], root);\n if (untrackedResult.exitCode === 0 && untrackedResult.stdout) {\n const files = untrackedResult.stdout.split('\\n').filter(Boolean);\n for (const file of files) {\n const block = synthesizeUntrackedDiff(root, file);\n if (block) combined += block;\n }\n }\n\n const files = parseGitDiff(combined);\n\n // Attach per-file line-coverage from an lcov.info if the repo has one.\n // Conservative: only files with a confident repo-relative path match get a\n // coverage value; everything else is left undefined (no badge rendered).\n // The lcov parse is memoized by (path, mtimeMs) inside `coverageLookup`, so\n // a multi-MB lcov is NOT re-read on every SSE / chokidar refresh tick.\n attachCoverage(root, files);\n\n // Augment markdown files with full before/after content so the SPA can\n // render a preview alongside the diff. Cheap (one `git show` + one fs\n // read per .md file), skipped entirely for non-markdown files.\n for (const file of files) {\n const md = readMarkdownContent(root, file, diffArg, 'working');\n if (md) file.mdContent = md;\n }\n\n return files;\n}\n\n/**\n * Attach line-coverage (+ lcov mtime + staleness) to each file in place.\n * Staleness: a file whose working-tree source `mtimeMs` is NEWER than the\n * lcov.info it was measured against has been edited since coverage was last\n * recorded, so its percent is no longer authoritative. We flag it\n * (`coverageStale`) rather than dropping the number outright — the SPA\n * de-emphasizes / suppresses the badge and the tooltip carries the lcov\n * timestamp so stale coverage is never presented as current.\n */\nfunction attachCoverage(root: string, files: ParsedFile[]): void {\n const { byPath, lcovMtimeMs } = coverageLookup(\n root,\n files.map((f) => f.path),\n );\n if (byPath.size === 0) return;\n for (const f of files) {\n const pct = byPath.get(f.path);\n if (typeof pct !== 'number') continue;\n f.coverage = pct;\n if (lcovMtimeMs != null) {\n f.coverageMtimeMs = lcovMtimeMs;\n let srcMtimeMs: number | null;\n try {\n srcMtimeMs = fs.statSync(path.join(root, f.path)).mtimeMs;\n } catch {\n srcMtimeMs = null;\n }\n if (srcMtimeMs != null && srcMtimeMs > lcovMtimeMs) {\n f.coverageStale = true;\n }\n }\n }\n}\n\nexport interface ComputeRangeDiffOptions {\n /** Git toplevel working directory. */\n root: string;\n /** Commit sha (or ref) for the left side. */\n fromRef: string;\n /** Commit sha (or ref) for the right side, or `'working'` for the\n * working tree (in which case behaviour matches `computeDiff` and\n * untracked files are synthesised). */\n toRef: string | 'working';\n}\n\n/**\n * Diff between two snapshot points. When `toRef === 'working'` this is\n * `computeDiff` with the same diffArg — the only path that needs untracked\n * synthesis. When `toRef` is a real commit, both sides are committed trees\n * (checkpoints already include what was untracked at capture time via the\n * temp-index `git add -A`), so a plain `git diff <from> <to>` covers it.\n *\n * Markdown content is fetched from the appropriate ref on each side so the\n * Preview/Split view works for historical range views too.\n */\nexport function computeRangeDiff(opts: ComputeRangeDiffOptions): ParsedFile[] {\n const { root, fromRef, toRef } = opts;\n\n if (toRef === 'working') {\n if (fromRef === 'HEAD') {\n // Legacy HEAD-vs-working path — keep the existing untracked\n // synthesis. This is what `wd` (no checkpoints) has always done.\n return computeDiff({ root, diffArg: fromRef });\n }\n // Range against a real checkpoint commit. `git diff <ref>` can't be\n // used directly here: it routes through the real index, so any file\n // that was untracked-at-snapshot-time (and captured into the\n // checkpoint's tree via the temp-index `add -A`) appears DELETED\n // from the working tree — a phantom that would render as\n // \"removed\" on every range view. Build a tree-sha snapshot of the\n // live working tree (same temp-index dance) and do a clean\n // tree-vs-tree diff. No untracked synth needed; the working-tree\n // tree already contains everything.\n const wtTreeSha = workingTreeTreeSha(root);\n if (!wtTreeSha) return [];\n const result = spawn.sync(\n 'git',\n // RENAME_DETECT: detect renames between the checkpoint tree and the\n // working tree so a rename (with or without edits) renders as one\n // entry, matching the HEAD-vs-working path above.\n ['diff-tree', '-r', '-p', RENAME_DETECT, '--no-color', '--no-ext-diff', fromRef, wtTreeSha],\n {\n cwd: root,\n encoding: 'utf-8',\n maxBuffer: 500 * 1024 * 1024,\n windowsHide: true,\n },\n );\n if (result.status !== 0) {\n if (result.stderr) report('error', result.stderr);\n return [];\n }\n const parsed = parseGitDiff(result.stdout);\n for (const file of parsed) {\n const md = readMarkdownContent(root, file, fromRef, 'working');\n if (md) file.mdContent = md;\n }\n return parsed;\n }\n\n // No `-w` here. `computeDiff` (HEAD-vs-working-tree) uses `-w` to hide\n // reformatting noise — but checkpoint-to-checkpoint diffs are user-\n // selected ranges where a whitespace-only change between snapshots is\n // a legitimate change the user explicitly asked to see. Suppressing it\n // would make the strip silently show \"no changes\" for a turn that did\n // exactly one reformatting pass.\n const result = spawn.sync(\n 'git',\n // RENAME_DETECT: rename detection between two checkpoint commits (no -w\n // here — see the note above on why range diffs keep whitespace changes).\n ['diff', '--no-color', '--no-ext-diff', RENAME_DETECT, fromRef, toRef],\n {\n cwd: root,\n encoding: 'utf-8',\n maxBuffer: 500 * 1024 * 1024,\n windowsHide: true,\n },\n );\n if (result.status !== 0) {\n if (result.stderr) report('error', result.stderr);\n return [];\n }\n\n const files = parseGitDiff(result.stdout);\n for (const file of files) {\n const md = readMarkdownContent(root, file, fromRef, toRef);\n if (md) file.mdContent = md;\n }\n return files;\n}\n","export type FileStatus = 'added' | 'deleted' | 'modified' | 'renamed' | 'binary';\n\nexport interface ParsedFile {\n /** Path used by GitHub-style anchors / sidebar tree. For renames, this is the new path. */\n path: string;\n oldPath: string;\n newPath: string;\n status: FileStatus;\n isBinary: boolean;\n added: number;\n deleted: number;\n hunks: Hunk[];\n /** Line-coverage percent for this file (from lcov). undefined when no lcov data is available. */\n coverage?: number;\n /** Epoch-ms mtime of the lcov.info the `coverage` value came from. Lets the\n * SPA show *when* the coverage was measured. undefined when no lcov data. */\n coverageMtimeMs?: number;\n /** True when this file's working-tree source is newer than the lcov.info the\n * coverage came from — i.e. the percent is stale and MUST NOT be presented\n * as authoritative. The SPA suppresses / de-emphasizes the badge. */\n coverageStale?: boolean;\n /** Full file contents for markdown rendering. Populated only for `.md` /\n * `.markdown` / `.mdx` files by the diff pipeline so the SPA can show a\n * rendered preview. `before` is from `git show <diffArg>:<oldPath>`,\n * `after` is the working-tree file. Either side may be absent for\n * added / deleted files. */\n mdContent?: MarkdownContent;\n}\n\nexport interface MarkdownContent {\n before?: string;\n after?: string;\n /** Set when either side exceeded the per-side size cap. The SPA uses\n * this to hide the Preview/Split toggle — rendering a 10 MB\n * markdown blob in the diff payload would balloon SSE reloads and\n * blow the browser heap. */\n tooLarge?: boolean;\n}\n\nexport interface Hunk {\n oldStart: number;\n oldLines: number;\n newStart: number;\n newLines: number;\n /** Trailing text after \"@@ ... @@\" — typically the enclosing function/class. */\n context: string;\n lines: HunkLine[];\n}\n\nexport type LineKind = 'context' | 'add' | 'delete' | 'no-newline';\n\nexport interface HunkLine {\n kind: LineKind;\n content: string;\n oldNum: number | null;\n newNum: number | null;\n}\n\nconst HUNK_RE = /^@@ -(\\d+)(?:,(\\d+))? \\+(\\d+)(?:,(\\d+))? @@(.*)$/;\n\n/**\n * Parse the output of `git diff` (or `git diff <ref>`) into a list of files\n * with hunks. The input is assumed to be in unified diff format with the\n * default git headers (`diff --git`, `--- a/...`, `+++ b/...`).\n */\nexport function parseGitDiff(input: string): ParsedFile[] {\n const lines = input.split(/\\r?\\n/);\n const files: ParsedFile[] = [];\n let current: ParsedFile | null = null;\n let currentHunk: Hunk | null = null;\n let oldLineNum = 0;\n let newLineNum = 0;\n\n function startFile(oldPath: string, newPath: string): ParsedFile {\n const f: ParsedFile = {\n path: newPath !== '/dev/null' ? newPath : oldPath,\n oldPath,\n newPath,\n status: 'modified',\n isBinary: false,\n added: 0,\n deleted: 0,\n hunks: [],\n };\n files.push(f);\n return f;\n }\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n\n // `diff --git a/path b/path` — start of a new file. We may not learn\n // the real paths until the `---`/`+++` lines below, so just close out\n // the previous file here.\n if (line.startsWith('diff --git ')) {\n current = null;\n currentHunk = null;\n const match = line.match(/^diff --git \"?a\\/(.+?)\"? \"?b\\/(.+?)\"?$/);\n if (match) {\n current = startFile(match[1], match[2]);\n }\n continue;\n }\n\n if (!current) continue;\n\n if (line.startsWith('new file mode')) {\n current.status = 'added';\n continue;\n }\n if (line.startsWith('deleted file mode')) {\n current.status = 'deleted';\n continue;\n }\n if (line.startsWith('rename from ')) {\n current.status = 'renamed';\n current.oldPath = line.slice('rename from '.length);\n continue;\n }\n if (line.startsWith('rename to ')) {\n current.newPath = line.slice('rename to '.length);\n current.path = current.newPath;\n continue;\n }\n if (line.startsWith('Binary files ')) {\n current.isBinary = true;\n continue;\n }\n if (line.startsWith('--- ')) {\n const p = stripPathPrefix(line.slice(4));\n if (p === '/dev/null') {\n current.status = 'added';\n } else {\n current.oldPath = p;\n }\n continue;\n }\n if (line.startsWith('+++ ')) {\n const p = stripPathPrefix(line.slice(4));\n if (p === '/dev/null') {\n current.status = 'deleted';\n } else {\n current.newPath = p;\n current.path = p;\n }\n continue;\n }\n\n const hunkMatch = line.match(HUNK_RE);\n if (hunkMatch) {\n currentHunk = {\n oldStart: Number(hunkMatch[1]),\n oldLines: hunkMatch[2] ? Number(hunkMatch[2]) : 1,\n newStart: Number(hunkMatch[3]),\n newLines: hunkMatch[4] ? Number(hunkMatch[4]) : 1,\n context: hunkMatch[5].trim(),\n lines: [],\n };\n oldLineNum = currentHunk.oldStart;\n newLineNum = currentHunk.newStart;\n current.hunks.push(currentHunk);\n continue;\n }\n\n if (!currentHunk) continue;\n\n // Inside a hunk: the first character of each line says what kind it is.\n // We accept empty lines defensively (some diffs trim trailing space).\n const marker = line[0] ?? ' ';\n const body = line.slice(1);\n\n if (marker === '\\\\') {\n // \"\\" — attach to previous line, don't count.\n currentHunk.lines.push({\n kind: 'no-newline',\n content: line,\n oldNum: null,\n newNum: null,\n });\n continue;\n }\n\n if (marker === '+') {\n currentHunk.lines.push({\n kind: 'add',\n content: body,\n oldNum: null,\n newNum: newLineNum++,\n });\n current.added++;\n } else if (marker === '-') {\n currentHunk.lines.push({\n kind: 'delete',\n content: body,\n oldNum: oldLineNum++,\n newNum: null,\n });\n current.deleted++;\n } else {\n // Context (space) and anything else gets treated as context.\n currentHunk.lines.push({\n kind: 'context',\n content: body,\n oldNum: oldLineNum++,\n newNum: newLineNum++,\n });\n }\n }\n\n // Derive status for renames where the diff omitted /dev/null markers.\n for (const f of files) {\n if (f.status === 'modified' && f.oldPath !== f.newPath) {\n f.status = 'renamed';\n }\n }\n\n return files;\n}\n\nfunction stripPathPrefix(p: string): string {\n // `--- a/path/to/file` / `+++ b/path/to/file` / `--- /dev/null`\n const trimmed = p.trim().replace(/^\"|\"$/g, '');\n if (trimmed === '/dev/null') return trimmed;\n if (trimmed.startsWith('a/') || trimmed.startsWith('b/')) {\n return trimmed.slice(2);\n }\n return trimmed;\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\n\n/**\n * Parse standard lcov.info content into a map of file path → line-coverage\n * percent (a float in [0, 100]). Keys are the `SF:` paths exactly as written\n * in the file (may be absolute or repo-relative depending on the tool).\n *\n * Per-file percent prefers the `LF`/`LH` summary lines (lines found / lines\n * hit) when present; otherwise it is derived from the individual `DA:` line\n * records (`DA:<line>,<hits>`). A file with zero lines found yields 0.\n */\nexport function parseLcov(content: string): Map<string, number> {\n const result = new Map<string, number>();\n\n let sf: string | null = null;\n let lf: number | null = null;\n let lh: number | null = null;\n let daTotal = 0;\n let daHit = 0;\n\n const finish = () => {\n if (sf === null) return;\n let pct: number;\n if (lf !== null && lf > 0) {\n pct = ((lh ?? 0) / lf) * 100;\n } else if (lf === 0) {\n pct = 0;\n } else if (daTotal > 0) {\n pct = (daHit / daTotal) * 100;\n } else {\n pct = 0;\n }\n result.set(sf, pct);\n };\n\n const reset = () => {\n sf = null;\n lf = null;\n lh = null;\n daTotal = 0;\n daHit = 0;\n };\n\n for (const raw of content.split('\\n')) {\n const line = raw.trim();\n if (line.startsWith('SF:')) {\n sf = line.slice(3).trim();\n } else if (line.startsWith('DA:')) {\n const rest = line.slice(3);\n const comma = rest.indexOf(',');\n if (comma !== -1) {\n const hits = Number(rest.slice(comma + 1).split(',')[0]);\n if (Number.isFinite(hits)) {\n daTotal += 1;\n if (hits > 0) daHit += 1;\n }\n }\n } else if (line.startsWith('LF:')) {\n const n = Number(line.slice(3).trim());\n if (Number.isFinite(n)) lf = n;\n } else if (line.startsWith('LH:')) {\n const n = Number(line.slice(3).trim());\n if (Number.isFinite(n)) lh = n;\n } else if (line === 'end_of_record') {\n finish();\n reset();\n }\n }\n // Tolerate a trailing record with no terminating `end_of_record`.\n finish();\n\n return result;\n}\n\n/**\n * Locate an lcov.info file for a repo root. Checks `<root>/coverage/lcov.info`\n * then `<root>/lcov.info`. Returns the first that exists, else null.\n */\nexport function findLcov(root: string): string | null {\n const candidates = [path.join(root, 'coverage', 'lcov.info'), path.join(root, 'lcov.info')];\n for (const c of candidates) {\n try {\n if (fs.statSync(c).isFile()) return c;\n } catch {\n // not present — try next\n }\n }\n return null;\n}\n\n/**\n * Cache of parsed lcov files keyed by absolute lcov path. `computeDiff` runs\n * on every SSE / chokidar tick; an lcov.info can be multiple MB, so we MUST\n * NOT re-read + re-parse it each refresh. The cache is invalidated when the\n * file's `mtimeMs` changes (a fresh `npm test -- --coverage` run rewrites it).\n */\ninterface LcovCacheEntry {\n mtimeMs: number;\n parsed: Map<string, number>;\n}\nconst lcovCache = new Map<string, LcovCacheEntry>();\n\n/**\n * Read + parse the lcov at `lcovPath`, memoizing by `(path, mtimeMs)`. Returns\n * the parsed `SF: → percent` map and the lcov's mtime (ms-since-epoch), or\n * null when the file can't be stat'd / read. A multi-MB lcov is parsed once\n * and reused until it is rewritten.\n *\n * Exported for testing the cache behavior.\n */\nexport function readParsedLcov(lcovPath: string): { parsed: Map<string, number>; mtimeMs: number } | null {\n let mtimeMs: number;\n try {\n mtimeMs = fs.statSync(lcovPath).mtimeMs;\n } catch {\n lcovCache.delete(lcovPath);\n return null;\n }\n\n const cached = lcovCache.get(lcovPath);\n if (cached && cached.mtimeMs === mtimeMs) {\n return { parsed: cached.parsed, mtimeMs };\n }\n\n let content: string;\n try {\n content = fs.readFileSync(lcovPath, 'utf-8');\n } catch {\n lcovCache.delete(lcovPath);\n return null;\n }\n\n const parsed = parseLcov(content);\n lcovCache.set(lcovPath, { mtimeMs, parsed });\n return { parsed, mtimeMs };\n}\n\n/** Test hook: drop the in-memory parse cache. */\nexport function clearLcovCache(): void {\n lcovCache.clear();\n}\n\n/** Normalize a path for comparison: forward slashes, drop a leading `./`. */\nfunction normRel(p: string): string {\n return path.normalize(p).replace(/\\\\/g, '/').replace(/^\\.\\//, '');\n}\n\n/**\n * Canonicalize `root` once so SF:-path matching survives symlink / realpath\n * divergence (macOS `/tmp` → `/private/tmp`, Linux bind mounts, Windows\n * junctions) and case-insensitive filesystems. An absolute `SF:` path emitted\n * by the coverage tool is resolved through `realpath` too, so both sides share\n * a canonical namespace before `path.relative` runs — otherwise the relative\n * path comes out `..`-prefixed and the match is silently lost.\n */\nfunction realRoot(root: string): string {\n try {\n return fs.realpathSync(path.resolve(root));\n } catch {\n return path.resolve(root);\n }\n}\n\n/**\n * Canonicalize an absolute path by realpath-ing its deepest EXISTING ancestor\n * and re-appending the not-yet-existing tail. `fs.realpathSync(absSf)` throws\n * when the leaf doesn\\'t exist on disk (lcov records files that may since have\n * moved, or simply aren\\'t present in a sparse checkout); a plain\n * `path.resolve` fallback would leave the path in a different symlink\n * namespace from `canonRoot` (macOS `/var/folders` TMPDIR, etc.) and the\n * relative path would come out `..`-prefixed — silently dropping the match.\n * Resolving the existing prefix keeps both sides in one canonical namespace.\n */\nfunction canonicalize(absPath: string): string {\n const resolved = path.resolve(absPath);\n let dir = resolved;\n const tail: string[] = [];\n // Walk up until we hit a path that exists (realpath-able) or the root.\n for (;;) {\n try {\n const realDir = fs.realpathSync(dir);\n return tail.length ? path.join(realDir, ...tail.reverse()) : realDir;\n } catch {\n const parent = path.dirname(dir);\n if (parent === dir) return resolved; // reached fs root, nothing realpath-able\n tail.push(path.basename(dir));\n dir = parent;\n }\n }\n}\n\n/** Resolve an absolute `SF:` path to repo-relative against the canonical root,\n * following symlinks (even when the leaf file is absent) so realpath\n * divergence and case-insensitive filesystems don\\'t break the match. */\nfunction relForAbsSf(absSf: string, canonRoot: string): string {\n return path.relative(canonRoot, canonicalize(absSf));\n}\n\n/**\n * Result of a per-repo coverage lookup. `byPath` maps each requested\n * repo-relative path that matched to its line-coverage percent. `lcovMtimeMs`\n * is the mtime of the lcov.info the data came from (so callers can surface\n * staleness), or null when no lcov was found.\n */\nexport interface CoverageLookup {\n byPath: Map<string, number>;\n lcovMtimeMs: number | null;\n}\n\n/**\n * Read and parse the repo's lcov (if any) and return a map of repo-relative\n * path → line-coverage percent for the requested files only, plus the lcov\n * mtime. lcov `SF:` paths may be absolute or relative; both sides are\n * normalized to a canonical repo-relative path and compared. Entries are only\n * included on a confident path match.\n *\n * The underlying lcov parse is memoized by `(path, mtimeMs)` (see\n * `readParsedLcov`) so a multi-MB file isn't re-read on every diff refresh.\n */\nexport function coverageLookup(root: string, relPaths: string[]): CoverageLookup {\n const out = new Map<string, number>();\n const lcovPath = findLcov(root);\n if (!lcovPath) return { byPath: out, lcovMtimeMs: null };\n\n const read = readParsedLcov(lcovPath);\n if (!read || read.parsed.size === 0) {\n return { byPath: out, lcovMtimeMs: read?.mtimeMs ?? null };\n }\n\n // Build a lookup keyed by normalized repo-relative SF path.\n const canonRoot = realRoot(root);\n const byRel = new Map<string, number>();\n for (const [sf, pct] of read.parsed) {\n const rel = path.isAbsolute(sf) ? relForAbsSf(sf, canonRoot) : sf;\n byRel.set(normRel(rel), pct);\n }\n\n for (const rp of relPaths) {\n const pct = byRel.get(normRel(rp));\n if (typeof pct === 'number') out.set(rp, pct);\n }\n\n return { byPath: out, lcovMtimeMs: read.mtimeMs };\n}\n\n/**\n * Back-compat thin wrapper: returns just the `repo-relative path → percent`\n * map (drops the lcov mtime). Prefer `coverageLookup` when you need staleness\n * information.\n */\nexport function coverageForFiles(root: string, relPaths: string[]): Map<string, number> {\n return coverageLookup(root, relPaths).byPath;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA,OAAOA,SAAQ;AACf,OAAOC,WAAU;;;AC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A,MACE,KAAK;AAAA,MACL,UAAU;AAAA,MACV,WAAW,MAAM,OAAO;AAAA,MACxB,aAAa;AAAA,IACf;AAAA,EACF;AACA,MAAI,OAAO,WAAW,GAAG;AACvB,QAAI,OAAO,OAAQ,QAAO,SAAS,OAAO,MAAM;AAChD,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,QAAQ,aAAa,OAAO,MAAM;AACxC,aAAW,QAAQ,OAAO;AACxB,UAAM,KAAK,oBAAoB,MAAM,MAAM,SAAS,KAAK;AACzD,QAAI,GAAI,MAAK,YAAY;AAAA,EAC3B;AACA,SAAO;AACT;","names":["fs","path","path","realRoot","fs","files","result"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/commands/shared/cleanup-print.ts
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
function removable(candidates, opts) {
|
|
6
|
+
return candidates.filter((c) => {
|
|
7
|
+
if (c.verdict === "gone") return true;
|
|
8
|
+
const merged = c.repos.every((r) => !r.exists || r.merged !== null);
|
|
9
|
+
if (!merged) return false;
|
|
10
|
+
if (!opts.includeSquash && c.repos.some((r) => r.merged === "squash")) return false;
|
|
11
|
+
return c.verdict === "merged" || !!opts.dirtyToo && c.verdict === "dirty";
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function printCleanupResults(chosen, results) {
|
|
15
|
+
const byId = new Map(chosen.map((c) => [c.sessionId, c]));
|
|
16
|
+
let ok = 0;
|
|
17
|
+
let failed = 0;
|
|
18
|
+
for (const r of results) {
|
|
19
|
+
const c = byId.get(r.sessionId);
|
|
20
|
+
const name = c ? `${c.target}: ${c.branch}` : r.sessionId;
|
|
21
|
+
if (r.ok) {
|
|
22
|
+
ok++;
|
|
23
|
+
console.log(chalk.green(` \u2713 ${name} \u2014 ${r.message}`));
|
|
24
|
+
} else {
|
|
25
|
+
failed++;
|
|
26
|
+
console.log(chalk.yellow(` \u2717 ${name} \u2014 ${r.message}`));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
console.log("");
|
|
30
|
+
console.log(chalk.green(`Removed ${ok} worktree(s).`) + (failed ? chalk.yellow(` Left ${failed} alone.`) : ""));
|
|
31
|
+
return { ok, failed };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
removable,
|
|
36
|
+
printCleanupResults
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=chunk-ABQYKTG4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/shared/cleanup-print.ts"],"sourcesContent":["import chalk from 'chalk';\nimport type { CleanupCandidate } from '../../core/api-types.js';\nimport type { CleanupResult } from '../../core/cleanup/cleanup.js';\n\n/**\n * What prune / sync may remove: merged (or never committed to) and clean,\n * or its folder is gone. Squash-merge detection is a heuristic, so\n * unattended `sync` asks for it explicitly; `prune` (you pick) offers it.\n * With `dirtyToo`, merged worktrees with uncommitted changes as well.\n */\nexport function removable(candidates: CleanupCandidate[], opts: { includeSquash: boolean; dirtyToo?: boolean }): CleanupCandidate[] {\n return candidates.filter((c) => {\n if (c.verdict === 'gone') return true;\n const merged = c.repos.every((r) => !r.exists || r.merged !== null);\n if (!merged) return false;\n if (!opts.includeSquash && c.repos.some((r) => r.merged === 'squash')) return false;\n return c.verdict === 'merged' || (!!opts.dirtyToo && c.verdict === 'dirty');\n });\n}\n\n/** Per worktree: done, or left alone with the reason; then a total. */\nexport function printCleanupResults(chosen: CleanupCandidate[], results: CleanupResult[]): { ok: number; failed: number } {\n const byId = new Map(chosen.map((c) => [c.sessionId, c]));\n let ok = 0;\n let failed = 0;\n for (const r of results) {\n const c = byId.get(r.sessionId);\n const name = c ? `${c.target}: ${c.branch}` : r.sessionId;\n if (r.ok) {\n ok++;\n console.log(chalk.green(` ✓ ${name} — ${r.message}`));\n } else {\n failed++;\n console.log(chalk.yellow(` ✗ ${name} — ${r.message}`));\n }\n }\n console.log('');\n console.log(chalk.green(`Removed ${ok} worktree(s).`) + (failed ? chalk.yellow(` Left ${failed} alone.`) : ''));\n return { ok, failed };\n}\n"],"mappings":";;;AAAA,OAAO,WAAW;AAUX,SAAS,UAAU,YAAgC,MAA0E;AAClI,SAAO,WAAW,OAAO,CAAC,MAAM;AAC9B,QAAI,EAAE,YAAY,OAAQ,QAAO;AACjC,UAAM,SAAS,EAAE,MAAM,MAAM,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,WAAW,IAAI;AAClE,QAAI,CAAC,OAAQ,QAAO;AACpB,QAAI,CAAC,KAAK,iBAAiB,EAAE,MAAM,KAAK,CAAC,MAAM,EAAE,WAAW,QAAQ,EAAG,QAAO;AAC9E,WAAO,EAAE,YAAY,YAAa,CAAC,CAAC,KAAK,YAAY,EAAE,YAAY;AAAA,EACrE,CAAC;AACH;AAGO,SAAS,oBAAoB,QAA4B,SAA0D;AACxH,QAAM,OAAO,IAAI,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC;AACxD,MAAI,KAAK;AACT,MAAI,SAAS;AACb,aAAW,KAAK,SAAS;AACvB,UAAM,IAAI,KAAK,IAAI,EAAE,SAAS;AAC9B,UAAM,OAAO,IAAI,GAAG,EAAE,MAAM,KAAK,EAAE,MAAM,KAAK,EAAE;AAChD,QAAI,EAAE,IAAI;AACR;AACA,cAAQ,IAAI,MAAM,MAAM,YAAO,IAAI,WAAM,EAAE,OAAO,EAAE,CAAC;AAAA,IACvD,OAAO;AACL;AACA,cAAQ,IAAI,MAAM,OAAO,YAAO,IAAI,WAAM,EAAE,OAAO,EAAE,CAAC;AAAA,IACxD;AAAA,EACF;AACA,UAAQ,IAAI,EAAE;AACd,UAAQ,IAAI,MAAM,MAAM,WAAW,EAAE,eAAe,KAAK,SAAS,MAAM,OAAO,SAAS,MAAM,SAAS,IAAI,GAAG;AAC9G,SAAO,EAAE,IAAI,OAAO;AACtB;","names":[]}
|