@self-review/core 1.43.4 → 1.44.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/dist/chunk-A7A5ZFT3.js +233 -0
- package/dist/chunk-A7A5ZFT3.js.map +1 -0
- package/dist/chunk-OQRS7NDT.js +200 -0
- package/dist/chunk-OQRS7NDT.js.map +1 -0
- package/dist/diff-parser-2JM4CZR3.js +7 -0
- package/dist/diff-parser-2JM4CZR3.js.map +1 -0
- package/dist/git-E7WZPKRC.js +23 -0
- package/dist/git-E7WZPKRC.js.map +1 -0
- package/dist/index.cjs +1520 -377
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +454 -6
- package/dist/index.d.ts +454 -6
- package/dist/index.js +1091 -429
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
8
11
|
var __export = (target, all) => {
|
|
9
12
|
for (var name in all)
|
|
10
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -27,54 +30,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
30
|
));
|
|
28
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
32
|
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
ForgeCliUnavailableError: () => ForgeCliUnavailableError,
|
|
34
|
-
GUIDE_XSD_SCHEMA: () => GUIDE_XSD_SCHEMA,
|
|
35
|
-
IMPLICIT_GUIDE_GROUP_NAME: () => IMPLICIT_GUIDE_GROUP_NAME,
|
|
36
|
-
REVIEW_LEVEL_FILE_PATH: () => REVIEW_LEVEL_FILE_PATH,
|
|
37
|
-
checkWritability: () => checkWritability,
|
|
38
|
-
computePayloadStats: () => computePayloadStats,
|
|
39
|
-
countTotalLines: () => countTotalLines,
|
|
40
|
-
createGitHubProvider: () => createGitHubProvider,
|
|
41
|
-
createGitLabProvider: () => createGitLabProvider,
|
|
42
|
-
createIgnoreFilter: () => createIgnoreFilter,
|
|
43
|
-
defaultGitRunner: () => defaultGitRunner,
|
|
44
|
-
detectExistingClone: () => detectExistingClone,
|
|
45
|
-
generateSyntheticDiffs: () => generateSyntheticDiffs,
|
|
46
|
-
generateUntrackedDiffs: () => generateUntrackedDiffs,
|
|
47
|
-
getGitDiffStats: () => getGitDiffStats,
|
|
48
|
-
getLanguageFromPath: () => getLanguageFromPath,
|
|
49
|
-
getRenderedTextMode: () => getRenderedTextMode,
|
|
50
|
-
getRepoRoot: () => getRepoRoot,
|
|
51
|
-
getRepoRootAsync: () => getRepoRootAsync,
|
|
52
|
-
getUntrackedFilesAsync: () => getUntrackedFilesAsync,
|
|
53
|
-
isHtmlFile: () => isHtmlFile,
|
|
54
|
-
isMarkdownFile: () => isMarkdownFile,
|
|
55
|
-
isPreviewableImage: () => isPreviewableImage,
|
|
56
|
-
isPreviewableRenderedText: () => isPreviewableRenderedText,
|
|
57
|
-
isPreviewableSvg: () => isPreviewableSvg,
|
|
58
|
-
loadConfig: () => loadConfig,
|
|
59
|
-
mapThreadsToReviewComments: () => mapThreadsToReviewComments,
|
|
60
|
-
materialize: () => materialize,
|
|
61
|
-
parseDiff: () => parseDiff,
|
|
62
|
-
parseForgeUrl: () => parseForgeUrl,
|
|
63
|
-
parseGuideXml: () => parseGuideXml,
|
|
64
|
-
parseReviewXml: () => parseReviewXml,
|
|
65
|
-
parseReviewXmlString: () => parseReviewXmlString,
|
|
66
|
-
reconcileGuide: () => reconcileGuide,
|
|
67
|
-
resolveRemoteDefaultBranch: () => resolveRemoteDefaultBranch,
|
|
68
|
-
runGitDiff: () => runGitDiff,
|
|
69
|
-
runGitDiffAsync: () => runGitDiffAsync,
|
|
70
|
-
scanDirectory: () => scanDirectory,
|
|
71
|
-
scanFile: () => scanFile,
|
|
72
|
-
serializeReview: () => serializeReview,
|
|
73
|
-
validateGitAvailable: () => validateGitAvailable
|
|
74
|
-
});
|
|
75
|
-
module.exports = __toCommonJS(index_exports);
|
|
76
|
-
|
|
77
33
|
// src/diff-parser.ts
|
|
34
|
+
var diff_parser_exports = {};
|
|
35
|
+
__export(diff_parser_exports, {
|
|
36
|
+
parseDiff: () => parseDiff
|
|
37
|
+
});
|
|
78
38
|
function parseDiff(rawDiff) {
|
|
79
39
|
if (!rawDiff.trim()) {
|
|
80
40
|
return [];
|
|
@@ -85,6 +45,12 @@ function parseDiff(rawDiff) {
|
|
|
85
45
|
let currentHunk = null;
|
|
86
46
|
let oldLineNumber = 0;
|
|
87
47
|
let newLineNumber = 0;
|
|
48
|
+
let hasModeChange = false;
|
|
49
|
+
function flushFile() {
|
|
50
|
+
if (currentFile && (currentFile.oldPath || currentFile.newPath) && (currentFile.isBinary || currentFile.hunks.length > 0 || currentFile.changeType !== "modified" || hasModeChange)) {
|
|
51
|
+
files.push(currentFile);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
88
54
|
for (let i = 0; i < lines.length; i++) {
|
|
89
55
|
const line = lines[i];
|
|
90
56
|
if (line.startsWith("diff --git ")) {
|
|
@@ -92,11 +58,7 @@ function parseDiff(rawDiff) {
|
|
|
92
58
|
currentFile.hunks.push(currentHunk);
|
|
93
59
|
currentHunk = null;
|
|
94
60
|
}
|
|
95
|
-
|
|
96
|
-
if (currentFile.isBinary || currentFile.hunks && currentFile.hunks.length > 0 || currentFile.changeType === "added") {
|
|
97
|
-
files.push(currentFile);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
61
|
+
flushFile();
|
|
100
62
|
const gitPaths = parseGitDiffHeader(line);
|
|
101
63
|
currentFile = {
|
|
102
64
|
oldPath: gitPaths.oldPath,
|
|
@@ -106,29 +68,41 @@ function parseDiff(rawDiff) {
|
|
|
106
68
|
hunks: []
|
|
107
69
|
};
|
|
108
70
|
currentHunk = null;
|
|
71
|
+
hasModeChange = false;
|
|
109
72
|
continue;
|
|
110
73
|
}
|
|
111
74
|
if (!currentFile) continue;
|
|
112
75
|
if (line.startsWith("new file mode")) {
|
|
113
76
|
currentFile.changeType = "added";
|
|
77
|
+
currentFile.oldPath = "";
|
|
114
78
|
continue;
|
|
115
79
|
}
|
|
116
80
|
if (line.startsWith("deleted file mode")) {
|
|
117
81
|
currentFile.changeType = "deleted";
|
|
82
|
+
currentFile.newPath = "";
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (line.startsWith("new mode ")) {
|
|
86
|
+
hasModeChange = true;
|
|
118
87
|
continue;
|
|
119
88
|
}
|
|
120
89
|
if (line.startsWith("rename from ")) {
|
|
121
90
|
currentFile.changeType = "renamed";
|
|
91
|
+
currentFile.oldPath = decodeGitPath(line.substring("rename from ".length));
|
|
122
92
|
continue;
|
|
123
93
|
}
|
|
124
|
-
if (line.startsWith("
|
|
125
|
-
|
|
126
|
-
currentFile.oldPath = path3 === "/dev/null" ? "" : stripPrefix(path3);
|
|
94
|
+
if (line.startsWith("rename to ")) {
|
|
95
|
+
currentFile.newPath = decodeGitPath(line.substring("rename to ".length));
|
|
127
96
|
continue;
|
|
128
97
|
}
|
|
129
|
-
if (line.startsWith("
|
|
130
|
-
const
|
|
131
|
-
currentFile.
|
|
98
|
+
if (!currentHunk && line.startsWith("--- ")) {
|
|
99
|
+
const path4 = decodeGitPath(line.substring(4).split(" ")[0]);
|
|
100
|
+
currentFile.oldPath = path4 === "/dev/null" ? "" : stripPrefix(path4);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (!currentHunk && line.startsWith("+++ ")) {
|
|
104
|
+
const path4 = decodeGitPath(line.substring(4).split(" ")[0]);
|
|
105
|
+
currentFile.newPath = path4 === "/dev/null" ? "" : stripPrefix(path4);
|
|
132
106
|
continue;
|
|
133
107
|
}
|
|
134
108
|
if (line.startsWith("Binary files ")) {
|
|
@@ -139,9 +113,7 @@ function parseDiff(rawDiff) {
|
|
|
139
113
|
if (currentHunk && currentHunk.header) {
|
|
140
114
|
currentFile.hunks.push(currentHunk);
|
|
141
115
|
}
|
|
142
|
-
const match = line.match(
|
|
143
|
-
/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/
|
|
144
|
-
);
|
|
116
|
+
const match = line.match(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/);
|
|
145
117
|
if (match) {
|
|
146
118
|
const oldStart = parseInt(match[1], 10);
|
|
147
119
|
const oldLines = match[2] ? parseInt(match[2], 10) : 1;
|
|
@@ -206,52 +178,403 @@ function parseDiff(rawDiff) {
|
|
|
206
178
|
if (currentHunk && currentHunk.header && currentFile) {
|
|
207
179
|
currentFile.hunks.push(currentHunk);
|
|
208
180
|
}
|
|
209
|
-
|
|
210
|
-
if (currentFile.isBinary || currentFile.hunks && currentFile.hunks.length > 0 || currentFile.changeType === "added") {
|
|
211
|
-
files.push(currentFile);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
181
|
+
flushFile();
|
|
214
182
|
return files;
|
|
215
183
|
}
|
|
216
|
-
function stripPrefix(
|
|
217
|
-
if (
|
|
218
|
-
return
|
|
219
|
-
}
|
|
220
|
-
return
|
|
184
|
+
function stripPrefix(path4) {
|
|
185
|
+
if (path4.length > 2 && path4[1] === "/") {
|
|
186
|
+
return path4.substring(2);
|
|
187
|
+
}
|
|
188
|
+
return path4;
|
|
189
|
+
}
|
|
190
|
+
function decodeGitPath(path4) {
|
|
191
|
+
if (!path4.startsWith('"') || !path4.endsWith('"')) return path4;
|
|
192
|
+
const escapes = {
|
|
193
|
+
a: "\x07",
|
|
194
|
+
b: "\b",
|
|
195
|
+
f: "\f",
|
|
196
|
+
n: "\n",
|
|
197
|
+
r: "\r",
|
|
198
|
+
t: " ",
|
|
199
|
+
v: "\v",
|
|
200
|
+
'"': '"',
|
|
201
|
+
"\\": "\\"
|
|
202
|
+
};
|
|
203
|
+
return path4.slice(1, -1).replace(/(?:\\[0-7]{1,3})+|\\[abfnrtv"\\]/g, (escape) => {
|
|
204
|
+
if (/^\\[0-7]/.test(escape)) {
|
|
205
|
+
const bytes = escape.slice(1).split("\\").map((byte) => parseInt(byte, 8));
|
|
206
|
+
return Buffer.from(bytes).toString("utf8");
|
|
207
|
+
}
|
|
208
|
+
return escapes[escape[1]];
|
|
209
|
+
});
|
|
221
210
|
}
|
|
222
211
|
function parseGitDiffHeader(line) {
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
212
|
+
const paths = line.substring("diff --git ".length);
|
|
213
|
+
const quotedOld = paths.match(/^("(?:\\.|[^"\\])*") (.+)$/);
|
|
214
|
+
const quotedNew = paths.match(/^(.+) ("(?:\\.|[^"\\])*")$/);
|
|
215
|
+
const quoted = quotedOld || quotedNew;
|
|
216
|
+
if (quoted) {
|
|
217
|
+
return {
|
|
218
|
+
oldPath: stripPrefix(decodeGitPath(quoted[1])),
|
|
219
|
+
newPath: stripPrefix(decodeGitPath(quoted[2]))
|
|
220
|
+
};
|
|
231
221
|
}
|
|
232
|
-
const
|
|
233
|
-
const
|
|
234
|
-
|
|
222
|
+
const separators = [...paths.matchAll(/ [bwico]\//g)];
|
|
223
|
+
const boundary = separators.find(
|
|
224
|
+
(match) => stripPrefix(paths.substring(0, match.index)) === stripPrefix(paths.substring(match.index + 1))
|
|
225
|
+
) || separators[0];
|
|
226
|
+
if (!boundary) return { oldPath: "", newPath: "" };
|
|
227
|
+
return {
|
|
228
|
+
oldPath: stripPrefix(paths.substring(0, boundary.index)),
|
|
229
|
+
newPath: stripPrefix(paths.substring(boundary.index + 1))
|
|
230
|
+
};
|
|
235
231
|
}
|
|
232
|
+
var init_diff_parser = __esm({
|
|
233
|
+
"src/diff-parser.ts"() {
|
|
234
|
+
"use strict";
|
|
235
|
+
}
|
|
236
|
+
});
|
|
236
237
|
|
|
237
|
-
// src/
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
238
|
+
// src/synthetic-diff.ts
|
|
239
|
+
function needsQuoting(byte) {
|
|
240
|
+
return byte < 32 || byte >= 127 || byte === 34 || byte === 92;
|
|
241
|
+
}
|
|
242
|
+
function quoteGitPath(path4) {
|
|
243
|
+
const bytes = Buffer.from(path4, "utf-8");
|
|
244
|
+
if (!bytes.some(needsQuoting)) return path4;
|
|
245
|
+
let quoted = '"';
|
|
246
|
+
for (const byte of bytes) {
|
|
247
|
+
const escape = C_STYLE_ESCAPES[byte];
|
|
248
|
+
if (escape) {
|
|
249
|
+
quoted += escape;
|
|
250
|
+
} else if (byte < 32 || byte >= 127) {
|
|
251
|
+
quoted += `\\${byte.toString(8).padStart(3, "0")}`;
|
|
252
|
+
} else {
|
|
253
|
+
quoted += String.fromCharCode(byte);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return `${quoted}"`;
|
|
257
|
+
}
|
|
258
|
+
function generateSyntheticDiffs(paths, rootDir) {
|
|
259
|
+
const diffs = [];
|
|
260
|
+
for (const filePath of paths) {
|
|
261
|
+
const fullPath = (0, import_path.join)(rootDir, filePath);
|
|
262
|
+
let content;
|
|
263
|
+
try {
|
|
264
|
+
content = (0, import_fs2.readFileSync)(fullPath);
|
|
265
|
+
} catch {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
const oldHeaderPath = quoteGitPath(`a/${filePath}`);
|
|
269
|
+
const newHeaderPath = quoteGitPath(`b/${filePath}`);
|
|
270
|
+
const sample = content.subarray(0, 8192);
|
|
271
|
+
const isBinary = sample.includes(0);
|
|
272
|
+
if (isBinary) {
|
|
273
|
+
diffs.push(
|
|
274
|
+
`diff --git ${oldHeaderPath} ${newHeaderPath}
|
|
275
|
+
new file mode 100644
|
|
276
|
+
Binary files /dev/null and ${newHeaderPath} differ`
|
|
277
|
+
);
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
const text = content.toString("utf-8");
|
|
281
|
+
const lines = text.split("\n");
|
|
282
|
+
if (lines.length > 0 && lines[lines.length - 1] === "") {
|
|
283
|
+
lines.pop();
|
|
284
|
+
}
|
|
285
|
+
const lineCount = lines.length;
|
|
286
|
+
const addedLines = lines.map((line) => `+${line}`).join("\n");
|
|
287
|
+
let diff = `diff --git ${oldHeaderPath} ${newHeaderPath}
|
|
288
|
+
new file mode 100644
|
|
289
|
+
--- /dev/null
|
|
290
|
+
+++ ${newHeaderPath}
|
|
291
|
+
@@ -0,0 +1,${lineCount} @@
|
|
292
|
+
` + addedLines;
|
|
293
|
+
if (text.length > 0 && !text.endsWith("\n")) {
|
|
294
|
+
diff += "\n\";
|
|
295
|
+
}
|
|
296
|
+
diffs.push(diff);
|
|
297
|
+
}
|
|
298
|
+
return diffs.join("\n");
|
|
299
|
+
}
|
|
300
|
+
var import_fs2, import_path, C_STYLE_ESCAPES;
|
|
301
|
+
var init_synthetic_diff = __esm({
|
|
302
|
+
"src/synthetic-diff.ts"() {
|
|
303
|
+
"use strict";
|
|
304
|
+
import_fs2 = require("fs");
|
|
305
|
+
import_path = require("path");
|
|
306
|
+
C_STYLE_ESCAPES = {
|
|
307
|
+
7: "\\a",
|
|
308
|
+
8: "\\b",
|
|
309
|
+
9: "\\t",
|
|
310
|
+
10: "\\n",
|
|
311
|
+
11: "\\v",
|
|
312
|
+
12: "\\f",
|
|
313
|
+
13: "\\r",
|
|
314
|
+
34: '\\"',
|
|
315
|
+
92: "\\\\"
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
});
|
|
248
319
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
320
|
+
// src/git.ts
|
|
321
|
+
var git_exports = {};
|
|
322
|
+
__export(git_exports, {
|
|
323
|
+
generateUntrackedDiffs: () => generateUntrackedDiffs,
|
|
324
|
+
getRepoRoot: () => getRepoRoot,
|
|
325
|
+
getRepoRootAsync: () => getRepoRootAsync,
|
|
326
|
+
getUntrackedFilesAsync: () => getUntrackedFilesAsync,
|
|
327
|
+
readGitBlobAsync: () => readGitBlobAsync,
|
|
328
|
+
runGitDiff: () => runGitDiff,
|
|
329
|
+
runGitDiffAsync: () => runGitDiffAsync,
|
|
330
|
+
stripTrailingNewline: () => stripTrailingNewline,
|
|
331
|
+
validateGitAvailable: () => validateGitAvailable
|
|
332
|
+
});
|
|
333
|
+
function stripTrailingNewline(text) {
|
|
334
|
+
return text.replace(/\r?\n$/, "");
|
|
335
|
+
}
|
|
336
|
+
function runGitDiff(args) {
|
|
337
|
+
try {
|
|
338
|
+
try {
|
|
339
|
+
(0, import_child_process.execSync)("git --version", { stdio: "ignore" });
|
|
340
|
+
} catch {
|
|
341
|
+
console.error("Error: git is not installed or not in PATH");
|
|
342
|
+
process.exit(1);
|
|
343
|
+
}
|
|
344
|
+
try {
|
|
345
|
+
(0, import_child_process.execSync)("git rev-parse --git-dir", { stdio: "ignore" });
|
|
346
|
+
} catch {
|
|
347
|
+
console.error("Error: not a git repository (or any parent up to mount point)");
|
|
348
|
+
process.exit(1);
|
|
349
|
+
}
|
|
350
|
+
const result = (0, import_child_process.execFileSync)("git", ["diff", ...args], {
|
|
351
|
+
encoding: "utf-8",
|
|
352
|
+
maxBuffer: 50 * 1024 * 1024
|
|
353
|
+
// 50MB buffer for large diffs
|
|
354
|
+
});
|
|
355
|
+
return result;
|
|
356
|
+
} catch (error) {
|
|
357
|
+
if (error instanceof Error) {
|
|
358
|
+
console.error(`Error running git diff: ${error.message}`);
|
|
359
|
+
} else {
|
|
360
|
+
console.error("Error running git diff: unknown error");
|
|
361
|
+
}
|
|
362
|
+
process.exit(1);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
function getRepoRoot() {
|
|
366
|
+
try {
|
|
367
|
+
const result = (0, import_child_process.execSync)("git rev-parse --show-toplevel", {
|
|
368
|
+
encoding: "utf-8"
|
|
369
|
+
});
|
|
370
|
+
return stripTrailingNewline(result);
|
|
371
|
+
} catch (error) {
|
|
372
|
+
if (error instanceof Error) {
|
|
373
|
+
console.error(`Error getting repository root: ${error.message}`);
|
|
374
|
+
} else {
|
|
375
|
+
console.error("Error getting repository root: unknown error");
|
|
376
|
+
}
|
|
377
|
+
process.exit(1);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
function validateGitAvailable() {
|
|
381
|
+
try {
|
|
382
|
+
(0, import_child_process.execSync)("git --version", { stdio: "ignore" });
|
|
383
|
+
} catch {
|
|
384
|
+
console.error("Error: git is not installed or not in PATH");
|
|
385
|
+
process.exit(1);
|
|
386
|
+
}
|
|
387
|
+
try {
|
|
388
|
+
(0, import_child_process.execSync)("git rev-parse --git-dir", { stdio: "ignore" });
|
|
389
|
+
} catch {
|
|
390
|
+
console.error("Error: not a git repository (or any parent up to mount point)");
|
|
391
|
+
process.exit(1);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
async function getRepoRootAsync(cwd) {
|
|
395
|
+
try {
|
|
396
|
+
const { stdout } = await execFileAsync("git", ["rev-parse", "--show-toplevel"], {
|
|
397
|
+
timeout: 1e4,
|
|
398
|
+
// 10 second timeout
|
|
399
|
+
cwd
|
|
400
|
+
});
|
|
401
|
+
return stripTrailingNewline(stdout);
|
|
402
|
+
} catch (error) {
|
|
403
|
+
if (error instanceof Error) {
|
|
404
|
+
console.error(`Error getting repository root: ${error.message}`);
|
|
405
|
+
} else {
|
|
406
|
+
console.error("Error getting repository root: unknown error");
|
|
407
|
+
}
|
|
408
|
+
throw error;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
async function runGitDiffAsync(args, cwd) {
|
|
412
|
+
try {
|
|
413
|
+
const { stdout } = await execFileAsync("git", ["diff", ...args], {
|
|
414
|
+
maxBuffer: 50 * 1024 * 1024,
|
|
415
|
+
// 50MB buffer
|
|
416
|
+
timeout: 3e4,
|
|
417
|
+
// 30 second timeout
|
|
418
|
+
cwd
|
|
419
|
+
});
|
|
420
|
+
return stdout;
|
|
421
|
+
} catch (error) {
|
|
422
|
+
if (error instanceof Error) {
|
|
423
|
+
console.error(`Error running git diff: ${error.message}`);
|
|
424
|
+
} else {
|
|
425
|
+
console.error("Error running git diff: unknown error");
|
|
426
|
+
}
|
|
427
|
+
throw error;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
async function readGitBlobAsync(repoPath, spec) {
|
|
431
|
+
return await new Promise((resolve6, reject) => {
|
|
432
|
+
(0, import_child_process.execFile)(
|
|
433
|
+
"git",
|
|
434
|
+
["-C", repoPath, "show", spec],
|
|
435
|
+
{ encoding: "buffer", maxBuffer: 50 * 1024 * 1024, timeout: 3e4 },
|
|
436
|
+
(error, stdout) => {
|
|
437
|
+
if (error) {
|
|
438
|
+
reject(error);
|
|
439
|
+
} else {
|
|
440
|
+
resolve6(stdout);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
);
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
async function getUntrackedFilesAsync(repoRoot) {
|
|
447
|
+
try {
|
|
448
|
+
const { stdout } = await execFileAsync(
|
|
449
|
+
"git",
|
|
450
|
+
["ls-files", "--others", "--exclude-standard", "-z"],
|
|
451
|
+
{
|
|
452
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
453
|
+
timeout: 1e4,
|
|
454
|
+
cwd: repoRoot
|
|
455
|
+
}
|
|
456
|
+
);
|
|
457
|
+
return stdout.split("\0").filter((name) => name.length > 0);
|
|
458
|
+
} catch (error) {
|
|
459
|
+
if (error instanceof Error) {
|
|
460
|
+
console.error(`Warning: Failed to list untracked files: ${error.message}`);
|
|
461
|
+
} else {
|
|
462
|
+
console.error("Warning: Failed to list untracked files: unknown error");
|
|
463
|
+
}
|
|
464
|
+
return [];
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
function generateUntrackedDiffs(paths, repoRoot) {
|
|
468
|
+
return generateSyntheticDiffs(paths, repoRoot);
|
|
469
|
+
}
|
|
470
|
+
var import_child_process, import_util, execFileAsync;
|
|
471
|
+
var init_git = __esm({
|
|
472
|
+
"src/git.ts"() {
|
|
473
|
+
"use strict";
|
|
474
|
+
import_child_process = require("child_process");
|
|
475
|
+
import_util = require("util");
|
|
476
|
+
init_synthetic_diff();
|
|
477
|
+
execFileAsync = (0, import_util.promisify)(import_child_process.execFile);
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
// src/index.ts
|
|
482
|
+
var index_exports = {};
|
|
483
|
+
__export(index_exports, {
|
|
484
|
+
ForgeCliUnavailableError: () => ForgeCliUnavailableError,
|
|
485
|
+
GUIDE_XSD_SCHEMA: () => GUIDE_XSD_SCHEMA,
|
|
486
|
+
IMPLICIT_GUIDE_GROUP_NAME: () => IMPLICIT_GUIDE_GROUP_NAME,
|
|
487
|
+
REVIEW_LEVEL_FILE_PATH: () => REVIEW_LEVEL_FILE_PATH,
|
|
488
|
+
applyRemoteProvenance: () => applyRemoteProvenance,
|
|
489
|
+
applyStagedUntrackedDefault: () => applyStagedUntrackedDefault,
|
|
490
|
+
applySuggestion: () => applySuggestion,
|
|
491
|
+
applySuggestionForSession: () => applySuggestionForSession,
|
|
492
|
+
bootstrapRemoteDiff: () => bootstrapRemoteDiff,
|
|
493
|
+
buildRemoteReviewState: () => buildRemoteReviewState,
|
|
494
|
+
checkWritability: () => checkWritability,
|
|
495
|
+
commitReviewStart: () => commitReviewStart,
|
|
496
|
+
computePayloadStats: () => computePayloadStats,
|
|
497
|
+
computeRemoteDrift: () => computeRemoteDrift,
|
|
498
|
+
countTotalLines: () => countTotalLines,
|
|
499
|
+
createGitHubProvider: () => createGitHubProvider,
|
|
500
|
+
createGitLabProvider: () => createGitLabProvider,
|
|
501
|
+
createIgnoreFilter: () => createIgnoreFilter,
|
|
502
|
+
createReviewSession: () => createReviewSession,
|
|
503
|
+
defaultGitRunner: () => defaultGitRunner,
|
|
504
|
+
deriveGuidePath: () => deriveGuidePath,
|
|
505
|
+
detectExistingClone: () => detectExistingClone,
|
|
506
|
+
determineMode: () => determineMode,
|
|
507
|
+
expandContext: () => expandContext,
|
|
508
|
+
generateSyntheticDiffs: () => generateSyntheticDiffs,
|
|
509
|
+
generateUntrackedDiffs: () => generateUntrackedDiffs,
|
|
510
|
+
getConfigLoad: () => getConfigLoad,
|
|
511
|
+
getDiffLoad: () => getDiffLoad,
|
|
512
|
+
getFileHunks: () => getFileHunks,
|
|
513
|
+
getGitDiffStats: () => getGitDiffStats,
|
|
514
|
+
getLanguageFromPath: () => getLanguageFromPath,
|
|
515
|
+
getRenderedTextMode: () => getRenderedTextMode,
|
|
516
|
+
getRepoRoot: () => getRepoRoot,
|
|
517
|
+
getRepoRootAsync: () => getRepoRootAsync,
|
|
518
|
+
getResumeLoad: () => getResumeLoad,
|
|
519
|
+
getUntrackedFilesAsync: () => getUntrackedFilesAsync,
|
|
520
|
+
isHtmlFile: () => isHtmlFile,
|
|
521
|
+
isMarkdownFile: () => isMarkdownFile,
|
|
522
|
+
isPreviewableImage: () => isPreviewableImage,
|
|
523
|
+
isPreviewableRenderedText: () => isPreviewableRenderedText,
|
|
524
|
+
isPreviewableSvg: () => isPreviewableSvg,
|
|
525
|
+
loadConfig: () => loadConfig,
|
|
526
|
+
loadGitDiffWithUntracked: () => loadGitDiffWithUntracked,
|
|
527
|
+
loadGuide: () => loadGuide,
|
|
528
|
+
loadImage: () => loadImage,
|
|
529
|
+
mapThreadsToReviewComments: () => mapThreadsToReviewComments,
|
|
530
|
+
materialize: () => materialize,
|
|
531
|
+
mergeRemoteThreads: () => mergeRemoteThreads,
|
|
532
|
+
normalizeGitDiffArgs: () => normalizeGitDiffArgs,
|
|
533
|
+
parseDiff: () => parseDiff,
|
|
534
|
+
parseForgeUrl: () => parseForgeUrl,
|
|
535
|
+
parseGuideXml: () => parseGuideXml,
|
|
536
|
+
parseReviewXml: () => parseReviewXml,
|
|
537
|
+
parseReviewXmlString: () => parseReviewXmlString,
|
|
538
|
+
prepareDirectoryReview: () => prepareDirectoryReview,
|
|
539
|
+
preparePayload: () => preparePayload,
|
|
540
|
+
readAttachment: () => readAttachment,
|
|
541
|
+
reconcileGuide: () => reconcileGuide,
|
|
542
|
+
resolveApplyDestination: () => resolveApplyDestination,
|
|
543
|
+
resolveGuidePath: () => resolveGuidePath,
|
|
544
|
+
resolveRemoteDefaultBranch: () => resolveRemoteDefaultBranch,
|
|
545
|
+
resolveSourceBaseDir: () => resolveSourceBaseDir,
|
|
546
|
+
runFetchComments: () => runFetchComments,
|
|
547
|
+
runGitDiff: () => runGitDiff,
|
|
548
|
+
runGitDiffAsync: () => runGitDiffAsync,
|
|
549
|
+
scanDirectory: () => scanDirectory,
|
|
550
|
+
scanFile: () => scanFile,
|
|
551
|
+
serializeReview: () => serializeReview,
|
|
552
|
+
startRemoteSession: () => startRemoteSession,
|
|
553
|
+
submitReviewState: () => submitReviewState,
|
|
554
|
+
takeReviewState: () => takeReviewState,
|
|
555
|
+
validateGitAvailable: () => validateGitAvailable
|
|
556
|
+
});
|
|
557
|
+
module.exports = __toCommonJS(index_exports);
|
|
558
|
+
init_diff_parser();
|
|
559
|
+
|
|
560
|
+
// src/xml-serializer.ts
|
|
561
|
+
var path = __toESM(require("path"), 1);
|
|
562
|
+
var fs = __toESM(require("fs"), 1);
|
|
563
|
+
var import_xmllint_wasm = require("xmllint-wasm");
|
|
564
|
+
var XSD_SCHEMA = `<?xml version="1.0" encoding="UTF-8"?>
|
|
565
|
+
<xs:schema
|
|
566
|
+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
|
567
|
+
xmlns:sr="urn:self-review:v3"
|
|
568
|
+
targetNamespace="urn:self-review:v3"
|
|
569
|
+
elementFormDefault="qualified"
|
|
570
|
+
>
|
|
571
|
+
|
|
572
|
+
<!--
|
|
573
|
+
self-review XML Schema v3
|
|
574
|
+
=========================
|
|
575
|
+
Defines the output format for the self-review application.
|
|
576
|
+
This schema is designed to be both machine-validated and
|
|
577
|
+
fed to an LLM so it can understand the structure of review feedback.
|
|
255
578
|
|
|
256
579
|
Key concepts:
|
|
257
580
|
- A <review> contains one <file> per file in the diff.
|
|
@@ -933,9 +1256,13 @@ async function serializeReview(state, outputFilePath) {
|
|
|
933
1256
|
throw error;
|
|
934
1257
|
}
|
|
935
1258
|
if (error instanceof Error) {
|
|
936
|
-
console.error(
|
|
1259
|
+
console.error(
|
|
1260
|
+
`[main] XML validation infrastructure failed: ${error.message} - emitting XML without validation`
|
|
1261
|
+
);
|
|
937
1262
|
} else {
|
|
938
|
-
console.error(
|
|
1263
|
+
console.error(
|
|
1264
|
+
"[main] XML validation infrastructure failed - emitting XML without validation"
|
|
1265
|
+
);
|
|
939
1266
|
}
|
|
940
1267
|
return xml;
|
|
941
1268
|
}
|
|
@@ -1449,9 +1776,7 @@ async function parseGuideXml(xmlContent) {
|
|
|
1449
1776
|
try {
|
|
1450
1777
|
const validationResult = await (0, import_xmllint_wasm2.validateXML)({
|
|
1451
1778
|
xml: [{ fileName: "guide.xml", contents: xmlContent }],
|
|
1452
|
-
schema: [
|
|
1453
|
-
{ fileName: "self-review-guide-v1.xsd", contents: GUIDE_XSD_SCHEMA }
|
|
1454
|
-
]
|
|
1779
|
+
schema: [{ fileName: "self-review-guide-v1.xsd", contents: GUIDE_XSD_SCHEMA }]
|
|
1455
1780
|
});
|
|
1456
1781
|
if (!validationResult.valid) {
|
|
1457
1782
|
const details = (validationResult.errors || []).map((err) => typeof err === "string" ? err : err.message).join("; ");
|
|
@@ -1526,190 +1851,19 @@ function reconcileGuide(guide, diffFilePaths) {
|
|
|
1526
1851
|
});
|
|
1527
1852
|
}
|
|
1528
1853
|
}
|
|
1529
|
-
const leftover = diffFilePaths.filter((
|
|
1854
|
+
const leftover = diffFilePaths.filter((path4) => !claimed.has(path4));
|
|
1530
1855
|
if (leftover.length > 0) {
|
|
1531
1856
|
resolved.push({
|
|
1532
1857
|
name: IMPLICIT_GUIDE_GROUP_NAME,
|
|
1533
1858
|
implicit: true,
|
|
1534
|
-
files: leftover.map((
|
|
1859
|
+
files: leftover.map((path4) => ({ path: path4 }))
|
|
1535
1860
|
});
|
|
1536
1861
|
}
|
|
1537
1862
|
return resolved;
|
|
1538
1863
|
}
|
|
1539
1864
|
|
|
1540
|
-
// src/
|
|
1541
|
-
|
|
1542
|
-
var import_util = require("util");
|
|
1543
|
-
|
|
1544
|
-
// src/synthetic-diff.ts
|
|
1545
|
-
var import_fs2 = require("fs");
|
|
1546
|
-
function generateSyntheticDiffs(paths, rootDir) {
|
|
1547
|
-
const diffs = [];
|
|
1548
|
-
for (const filePath of paths) {
|
|
1549
|
-
const fullPath = `${rootDir}/${filePath}`;
|
|
1550
|
-
let content;
|
|
1551
|
-
try {
|
|
1552
|
-
content = (0, import_fs2.readFileSync)(fullPath);
|
|
1553
|
-
} catch {
|
|
1554
|
-
continue;
|
|
1555
|
-
}
|
|
1556
|
-
const sample = content.subarray(0, 8192);
|
|
1557
|
-
const isBinary = sample.includes(0);
|
|
1558
|
-
if (isBinary) {
|
|
1559
|
-
diffs.push(
|
|
1560
|
-
`diff --git a/${filePath} b/${filePath}
|
|
1561
|
-
new file mode 100644
|
|
1562
|
-
Binary files /dev/null and b/${filePath} differ`
|
|
1563
|
-
);
|
|
1564
|
-
continue;
|
|
1565
|
-
}
|
|
1566
|
-
const text = content.toString("utf-8");
|
|
1567
|
-
const lines = text.split("\n");
|
|
1568
|
-
if (lines.length > 0 && lines[lines.length - 1] === "") {
|
|
1569
|
-
lines.pop();
|
|
1570
|
-
}
|
|
1571
|
-
const lineCount = lines.length;
|
|
1572
|
-
const addedLines = lines.map((line) => `+${line}`).join("\n");
|
|
1573
|
-
let diff = `diff --git a/${filePath} b/${filePath}
|
|
1574
|
-
new file mode 100644
|
|
1575
|
-
--- /dev/null
|
|
1576
|
-
+++ b/${filePath}
|
|
1577
|
-
@@ -0,0 +1,${lineCount} @@
|
|
1578
|
-
` + addedLines;
|
|
1579
|
-
if (text.length > 0 && !text.endsWith("\n")) {
|
|
1580
|
-
diff += "\n\";
|
|
1581
|
-
}
|
|
1582
|
-
diffs.push(diff);
|
|
1583
|
-
}
|
|
1584
|
-
return diffs.join("\n");
|
|
1585
|
-
}
|
|
1586
|
-
|
|
1587
|
-
// src/git.ts
|
|
1588
|
-
var execAsync = (0, import_util.promisify)(import_child_process.exec);
|
|
1589
|
-
var execFileAsync = (0, import_util.promisify)(import_child_process.execFile);
|
|
1590
|
-
function runGitDiff(args) {
|
|
1591
|
-
try {
|
|
1592
|
-
try {
|
|
1593
|
-
(0, import_child_process.execSync)("git --version", { stdio: "ignore" });
|
|
1594
|
-
} catch {
|
|
1595
|
-
console.error("Error: git is not installed or not in PATH");
|
|
1596
|
-
process.exit(1);
|
|
1597
|
-
}
|
|
1598
|
-
try {
|
|
1599
|
-
(0, import_child_process.execSync)("git rev-parse --git-dir", { stdio: "ignore" });
|
|
1600
|
-
} catch {
|
|
1601
|
-
console.error(
|
|
1602
|
-
"Error: not a git repository (or any parent up to mount point)"
|
|
1603
|
-
);
|
|
1604
|
-
process.exit(1);
|
|
1605
|
-
}
|
|
1606
|
-
const result = (0, import_child_process.execFileSync)("git", ["diff", ...args], {
|
|
1607
|
-
encoding: "utf-8",
|
|
1608
|
-
maxBuffer: 50 * 1024 * 1024
|
|
1609
|
-
// 50MB buffer for large diffs
|
|
1610
|
-
});
|
|
1611
|
-
return result;
|
|
1612
|
-
} catch (error) {
|
|
1613
|
-
if (error instanceof Error) {
|
|
1614
|
-
console.error(`Error running git diff: ${error.message}`);
|
|
1615
|
-
} else {
|
|
1616
|
-
console.error("Error running git diff: unknown error");
|
|
1617
|
-
}
|
|
1618
|
-
process.exit(1);
|
|
1619
|
-
}
|
|
1620
|
-
}
|
|
1621
|
-
function getRepoRoot() {
|
|
1622
|
-
try {
|
|
1623
|
-
const result = (0, import_child_process.execSync)("git rev-parse --show-toplevel", {
|
|
1624
|
-
encoding: "utf-8"
|
|
1625
|
-
});
|
|
1626
|
-
return result.trim();
|
|
1627
|
-
} catch (error) {
|
|
1628
|
-
if (error instanceof Error) {
|
|
1629
|
-
console.error(`Error getting repository root: ${error.message}`);
|
|
1630
|
-
} else {
|
|
1631
|
-
console.error("Error getting repository root: unknown error");
|
|
1632
|
-
}
|
|
1633
|
-
process.exit(1);
|
|
1634
|
-
}
|
|
1635
|
-
}
|
|
1636
|
-
function validateGitAvailable() {
|
|
1637
|
-
try {
|
|
1638
|
-
(0, import_child_process.execSync)("git --version", { stdio: "ignore" });
|
|
1639
|
-
} catch {
|
|
1640
|
-
console.error("Error: git is not installed or not in PATH");
|
|
1641
|
-
process.exit(1);
|
|
1642
|
-
}
|
|
1643
|
-
try {
|
|
1644
|
-
(0, import_child_process.execSync)("git rev-parse --git-dir", { stdio: "ignore" });
|
|
1645
|
-
} catch {
|
|
1646
|
-
console.error(
|
|
1647
|
-
"Error: not a git repository (or any parent up to mount point)"
|
|
1648
|
-
);
|
|
1649
|
-
process.exit(1);
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
async function getRepoRootAsync(cwd) {
|
|
1653
|
-
try {
|
|
1654
|
-
const { stdout } = await execAsync("git rev-parse --show-toplevel", {
|
|
1655
|
-
timeout: 1e4,
|
|
1656
|
-
// 10 second timeout
|
|
1657
|
-
cwd
|
|
1658
|
-
});
|
|
1659
|
-
return stdout.trim();
|
|
1660
|
-
} catch (error) {
|
|
1661
|
-
if (error instanceof Error) {
|
|
1662
|
-
console.error(`Error getting repository root: ${error.message}`);
|
|
1663
|
-
} else {
|
|
1664
|
-
console.error("Error getting repository root: unknown error");
|
|
1665
|
-
}
|
|
1666
|
-
throw error;
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1669
|
-
async function runGitDiffAsync(args, cwd) {
|
|
1670
|
-
try {
|
|
1671
|
-
const { stdout } = await execFileAsync("git", ["diff", ...args], {
|
|
1672
|
-
maxBuffer: 50 * 1024 * 1024,
|
|
1673
|
-
// 50MB buffer
|
|
1674
|
-
timeout: 3e4,
|
|
1675
|
-
// 30 second timeout
|
|
1676
|
-
cwd
|
|
1677
|
-
});
|
|
1678
|
-
return stdout;
|
|
1679
|
-
} catch (error) {
|
|
1680
|
-
if (error instanceof Error) {
|
|
1681
|
-
console.error(`Error running git diff: ${error.message}`);
|
|
1682
|
-
} else {
|
|
1683
|
-
console.error("Error running git diff: unknown error");
|
|
1684
|
-
}
|
|
1685
|
-
throw error;
|
|
1686
|
-
}
|
|
1687
|
-
}
|
|
1688
|
-
async function getUntrackedFilesAsync(cwd) {
|
|
1689
|
-
try {
|
|
1690
|
-
const { stdout } = await execAsync(
|
|
1691
|
-
"git ls-files --others --exclude-standard",
|
|
1692
|
-
{
|
|
1693
|
-
maxBuffer: 10 * 1024 * 1024,
|
|
1694
|
-
timeout: 1e4,
|
|
1695
|
-
cwd
|
|
1696
|
-
}
|
|
1697
|
-
);
|
|
1698
|
-
return stdout.trim().split("\n").filter((line) => line.length > 0);
|
|
1699
|
-
} catch (error) {
|
|
1700
|
-
if (error instanceof Error) {
|
|
1701
|
-
console.error(
|
|
1702
|
-
`Warning: Failed to list untracked files: ${error.message}`
|
|
1703
|
-
);
|
|
1704
|
-
} else {
|
|
1705
|
-
console.error("Warning: Failed to list untracked files: unknown error");
|
|
1706
|
-
}
|
|
1707
|
-
return [];
|
|
1708
|
-
}
|
|
1709
|
-
}
|
|
1710
|
-
function generateUntrackedDiffs(paths, repoRoot) {
|
|
1711
|
-
return generateSyntheticDiffs(paths, repoRoot);
|
|
1712
|
-
}
|
|
1865
|
+
// src/index.ts
|
|
1866
|
+
init_git();
|
|
1713
1867
|
|
|
1714
1868
|
// src/forge-provider.ts
|
|
1715
1869
|
var ForgeCliUnavailableError = class extends Error {
|
|
@@ -1755,9 +1909,14 @@ function parseForgeUrl(url) {
|
|
|
1755
1909
|
return null;
|
|
1756
1910
|
}
|
|
1757
1911
|
|
|
1912
|
+
// src/index.ts
|
|
1913
|
+
init_synthetic_diff();
|
|
1914
|
+
|
|
1758
1915
|
// src/directory-scanner.ts
|
|
1759
1916
|
var import_promises = require("fs/promises");
|
|
1760
|
-
var
|
|
1917
|
+
var import_path2 = require("path");
|
|
1918
|
+
init_synthetic_diff();
|
|
1919
|
+
init_diff_parser();
|
|
1761
1920
|
|
|
1762
1921
|
// src/ignore-filter.ts
|
|
1763
1922
|
var import_ignore = __toESM(require("ignore"), 1);
|
|
@@ -1772,20 +1931,14 @@ async function scanDirectory(directoryPath, ignorePatterns = []) {
|
|
|
1772
1931
|
try {
|
|
1773
1932
|
const dirStat = await (0, import_promises.stat)(directoryPath);
|
|
1774
1933
|
if (!dirStat.isDirectory()) {
|
|
1775
|
-
console.error(
|
|
1776
|
-
`Error: "${directoryPath}" is not a directory`
|
|
1777
|
-
);
|
|
1934
|
+
console.error(`Error: "${directoryPath}" is not a directory`);
|
|
1778
1935
|
return [];
|
|
1779
1936
|
}
|
|
1780
1937
|
} catch (error) {
|
|
1781
1938
|
if (error instanceof Error) {
|
|
1782
|
-
console.error(
|
|
1783
|
-
`Error accessing directory "${directoryPath}": ${error.message}`
|
|
1784
|
-
);
|
|
1939
|
+
console.error(`Error accessing directory "${directoryPath}": ${error.message}`);
|
|
1785
1940
|
} else {
|
|
1786
|
-
console.error(
|
|
1787
|
-
`Error accessing directory "${directoryPath}": unknown error`
|
|
1788
|
-
);
|
|
1941
|
+
console.error(`Error accessing directory "${directoryPath}": unknown error`);
|
|
1789
1942
|
}
|
|
1790
1943
|
return [];
|
|
1791
1944
|
}
|
|
@@ -1800,19 +1953,15 @@ async function scanDirectory(directoryPath, ignorePatterns = []) {
|
|
|
1800
1953
|
continue;
|
|
1801
1954
|
}
|
|
1802
1955
|
const parentDir = entry.parentPath ?? entry.path;
|
|
1803
|
-
const fullPath = (0,
|
|
1804
|
-
const relativePath = (0,
|
|
1956
|
+
const fullPath = (0, import_path2.join)(parentDir, entry.name);
|
|
1957
|
+
const relativePath = (0, import_path2.relative)(directoryPath, fullPath);
|
|
1805
1958
|
filePaths.push(relativePath);
|
|
1806
1959
|
}
|
|
1807
1960
|
} catch (error) {
|
|
1808
1961
|
if (error instanceof Error) {
|
|
1809
|
-
console.error(
|
|
1810
|
-
`Error reading directory "${directoryPath}": ${error.message}`
|
|
1811
|
-
);
|
|
1962
|
+
console.error(`Error reading directory "${directoryPath}": ${error.message}`);
|
|
1812
1963
|
} else {
|
|
1813
|
-
console.error(
|
|
1814
|
-
`Error reading directory "${directoryPath}": unknown error`
|
|
1815
|
-
);
|
|
1964
|
+
console.error(`Error reading directory "${directoryPath}": unknown error`);
|
|
1816
1965
|
}
|
|
1817
1966
|
return [];
|
|
1818
1967
|
}
|
|
@@ -1840,15 +1989,15 @@ async function scanFile(filePath) {
|
|
|
1840
1989
|
}
|
|
1841
1990
|
return [];
|
|
1842
1991
|
}
|
|
1843
|
-
const fileName = (0,
|
|
1844
|
-
const rootDir = (0,
|
|
1992
|
+
const fileName = (0, import_path2.basename)(filePath);
|
|
1993
|
+
const rootDir = (0, import_path2.dirname)(filePath);
|
|
1845
1994
|
const diffText = generateSyntheticDiffs([fileName], rootDir);
|
|
1846
1995
|
return parseDiff(diffText);
|
|
1847
1996
|
}
|
|
1848
1997
|
|
|
1849
1998
|
// src/config.ts
|
|
1850
1999
|
var import_fs3 = require("fs");
|
|
1851
|
-
var
|
|
2000
|
+
var import_path3 = require("path");
|
|
1852
2001
|
var import_os = require("os");
|
|
1853
2002
|
var import_yaml = require("yaml");
|
|
1854
2003
|
var defaults = {
|
|
@@ -1924,37 +2073,28 @@ var defaults = {
|
|
|
1924
2073
|
};
|
|
1925
2074
|
function loadConfig() {
|
|
1926
2075
|
let config = { ...defaults };
|
|
1927
|
-
const userConfigPath = (0,
|
|
1928
|
-
(0, import_os.homedir)(),
|
|
1929
|
-
".config",
|
|
1930
|
-
"self-review",
|
|
1931
|
-
"config.yaml"
|
|
1932
|
-
);
|
|
2076
|
+
const userConfigPath = (0, import_path3.join)((0, import_os.homedir)(), ".config", "self-review", "config.yaml");
|
|
1933
2077
|
if ((0, import_fs3.existsSync)(userConfigPath)) {
|
|
1934
2078
|
try {
|
|
1935
2079
|
const userConfig = loadYamlConfig(userConfigPath);
|
|
1936
2080
|
config = mergeConfig(config, userConfig);
|
|
1937
2081
|
} catch (error) {
|
|
1938
|
-
console.error(
|
|
1939
|
-
`Warning: Failed to load user config from ${userConfigPath}: ${error}`
|
|
1940
|
-
);
|
|
2082
|
+
console.error(`Warning: Failed to load user config from ${userConfigPath}: ${error}`);
|
|
1941
2083
|
}
|
|
1942
2084
|
}
|
|
1943
|
-
const projectConfigPath = (0,
|
|
2085
|
+
const projectConfigPath = (0, import_path3.join)(process.cwd(), ".self-review.yaml");
|
|
1944
2086
|
if ((0, import_fs3.existsSync)(projectConfigPath)) {
|
|
1945
2087
|
try {
|
|
1946
2088
|
const projectConfig = loadYamlConfig(projectConfigPath);
|
|
1947
2089
|
config = mergeConfig(config, projectConfig);
|
|
1948
2090
|
} catch (error) {
|
|
1949
|
-
console.error(
|
|
1950
|
-
`Warning: Failed to load project config from ${projectConfigPath}: ${error}`
|
|
1951
|
-
);
|
|
2091
|
+
console.error(`Warning: Failed to load project config from ${projectConfigPath}: ${error}`);
|
|
1952
2092
|
}
|
|
1953
2093
|
}
|
|
1954
2094
|
return config;
|
|
1955
2095
|
}
|
|
1956
|
-
function loadYamlConfig(
|
|
1957
|
-
const content = (0, import_fs3.readFileSync)(
|
|
2096
|
+
function loadYamlConfig(path4) {
|
|
2097
|
+
const content = (0, import_fs3.readFileSync)(path4, "utf-8");
|
|
1958
2098
|
const raw = (0, import_yaml.parse)(content);
|
|
1959
2099
|
if (raw === null || raw === void 0) {
|
|
1960
2100
|
return {};
|
|
@@ -1967,18 +2107,14 @@ function loadYamlConfig(path3) {
|
|
|
1967
2107
|
if (["light", "dark", "system"].includes(raw.theme)) {
|
|
1968
2108
|
config.theme = raw.theme;
|
|
1969
2109
|
} else {
|
|
1970
|
-
console.error(
|
|
1971
|
-
`Warning: Invalid theme value "${raw.theme}", using default`
|
|
1972
|
-
);
|
|
2110
|
+
console.error(`Warning: Invalid theme value "${raw.theme}", using default`);
|
|
1973
2111
|
}
|
|
1974
2112
|
}
|
|
1975
2113
|
if ("diff-view" in raw) {
|
|
1976
2114
|
if (["split", "unified"].includes(raw["diff-view"])) {
|
|
1977
2115
|
config.diffView = raw["diff-view"];
|
|
1978
2116
|
} else {
|
|
1979
|
-
console.error(
|
|
1980
|
-
`Warning: Invalid diff-view value "${raw["diff-view"]}", using default`
|
|
1981
|
-
);
|
|
2117
|
+
console.error(`Warning: Invalid diff-view value "${raw["diff-view"]}", using default`);
|
|
1982
2118
|
}
|
|
1983
2119
|
}
|
|
1984
2120
|
if ("font-size" in raw && typeof raw["font-size"] === "number") {
|
|
@@ -1988,14 +2124,19 @@ function loadYamlConfig(path3) {
|
|
|
1988
2124
|
config.outputFormat = raw["output-format"];
|
|
1989
2125
|
}
|
|
1990
2126
|
if ("ignore" in raw && Array.isArray(raw.ignore)) {
|
|
1991
|
-
config.ignore = raw.ignore.filter(
|
|
1992
|
-
(item) => typeof item === "string"
|
|
1993
|
-
);
|
|
2127
|
+
config.ignore = raw.ignore.filter((item) => typeof item === "string");
|
|
1994
2128
|
}
|
|
1995
2129
|
if ("categories" in raw && Array.isArray(raw.categories)) {
|
|
1996
|
-
|
|
1997
|
-
(cat) => cat !== null && typeof cat === "object" && typeof cat.name === "string" && typeof cat.description === "string" && typeof cat.color === "string"
|
|
2130
|
+
const usableCategories = raw.categories.filter(
|
|
2131
|
+
(cat) => cat !== null && typeof cat === "object" && typeof cat.name === "string" && cat.name !== "" && typeof cat.description === "string" && typeof cat.color === "string"
|
|
1998
2132
|
);
|
|
2133
|
+
if (usableCategories.length > 0) {
|
|
2134
|
+
config.categories = usableCategories;
|
|
2135
|
+
} else {
|
|
2136
|
+
console.error(
|
|
2137
|
+
"Warning: Category configuration has no usable categories, using default categories"
|
|
2138
|
+
);
|
|
2139
|
+
}
|
|
1999
2140
|
}
|
|
2000
2141
|
if ("default-diff-args" in raw && typeof raw["default-diff-args"] === "string") {
|
|
2001
2142
|
config.defaultDiffArgs = raw["default-diff-args"];
|
|
@@ -2034,7 +2175,7 @@ function mergeConfig(base, override) {
|
|
|
2034
2175
|
// src/payload-sizing.ts
|
|
2035
2176
|
var import_child_process2 = require("child_process");
|
|
2036
2177
|
var import_util2 = require("util");
|
|
2037
|
-
var
|
|
2178
|
+
var execFileAsync2 = (0, import_util2.promisify)(import_child_process2.execFile);
|
|
2038
2179
|
function computePayloadStats(fileCount, totalLines, config) {
|
|
2039
2180
|
const maxFiles = config.maxFiles;
|
|
2040
2181
|
const maxTotalLines = config.maxTotalLines;
|
|
@@ -2059,7 +2200,7 @@ function countTotalLines(files) {
|
|
|
2059
2200
|
}
|
|
2060
2201
|
async function getGitDiffStats(args, repoRoot) {
|
|
2061
2202
|
try {
|
|
2062
|
-
const { stdout } = await
|
|
2203
|
+
const { stdout } = await execFileAsync2("git", ["diff", "--numstat", ...args], {
|
|
2063
2204
|
maxBuffer: 10 * 1024 * 1024,
|
|
2064
2205
|
timeout: 15e3,
|
|
2065
2206
|
cwd: repoRoot
|
|
@@ -2088,10 +2229,10 @@ async function getGitDiffStats(args, repoRoot) {
|
|
|
2088
2229
|
|
|
2089
2230
|
// src/fs-utils.ts
|
|
2090
2231
|
var import_fs4 = require("fs");
|
|
2091
|
-
var
|
|
2232
|
+
var import_path4 = require("path");
|
|
2092
2233
|
function checkWritability(filePath) {
|
|
2093
2234
|
try {
|
|
2094
|
-
const dir = (0,
|
|
2235
|
+
const dir = (0, import_path4.dirname)(filePath);
|
|
2095
2236
|
(0, import_fs4.accessSync)(dir, import_fs4.constants.W_OK);
|
|
2096
2237
|
return true;
|
|
2097
2238
|
} catch {
|
|
@@ -2099,9 +2240,111 @@ function checkWritability(filePath) {
|
|
|
2099
2240
|
}
|
|
2100
2241
|
}
|
|
2101
2242
|
|
|
2102
|
-
// src/
|
|
2103
|
-
var
|
|
2104
|
-
var
|
|
2243
|
+
// src/apply-suggestion.ts
|
|
2244
|
+
var import_fs5 = require("fs");
|
|
2245
|
+
var import_path5 = require("path");
|
|
2246
|
+
function refuse(filePath, reason, detail) {
|
|
2247
|
+
return { status: "refused", filePath, reason, detail };
|
|
2248
|
+
}
|
|
2249
|
+
function errorCode(error) {
|
|
2250
|
+
return error?.code;
|
|
2251
|
+
}
|
|
2252
|
+
function splitLines(content) {
|
|
2253
|
+
if (content === "") return [];
|
|
2254
|
+
const lines = content.split("\n");
|
|
2255
|
+
if (lines[lines.length - 1] === "") lines.pop();
|
|
2256
|
+
return lines;
|
|
2257
|
+
}
|
|
2258
|
+
function isCrlfRegion(anchored) {
|
|
2259
|
+
return anchored.length > 0 && anchored.every((line) => line.endsWith("\r"));
|
|
2260
|
+
}
|
|
2261
|
+
function applySuggestion(request) {
|
|
2262
|
+
const { destinationRoot, filePath, lineRange, suggestion } = request;
|
|
2263
|
+
if (!lineRange) {
|
|
2264
|
+
return refuse(
|
|
2265
|
+
filePath,
|
|
2266
|
+
"no-anchor",
|
|
2267
|
+
"This suggestion is file-level, so there are no lines to replace."
|
|
2268
|
+
);
|
|
2269
|
+
}
|
|
2270
|
+
if (lineRange.side === "old") {
|
|
2271
|
+
return refuse(
|
|
2272
|
+
filePath,
|
|
2273
|
+
"old-side-anchor",
|
|
2274
|
+
"This suggestion is anchored to deleted lines, which are not in the working file."
|
|
2275
|
+
);
|
|
2276
|
+
}
|
|
2277
|
+
if (!(0, import_path5.isAbsolute)(destinationRoot)) {
|
|
2278
|
+
return refuse(
|
|
2279
|
+
filePath,
|
|
2280
|
+
"destination-not-absolute",
|
|
2281
|
+
"The destination directory must be an absolute path."
|
|
2282
|
+
);
|
|
2283
|
+
}
|
|
2284
|
+
const root = (0, import_path5.resolve)(destinationRoot);
|
|
2285
|
+
const absolutePath = (0, import_path5.resolve)(root, filePath);
|
|
2286
|
+
const rel = (0, import_path5.relative)(root, absolutePath);
|
|
2287
|
+
if ((0, import_path5.isAbsolute)(filePath) || rel === "" || rel === ".." || rel.startsWith(`..${import_path5.sep}`)) {
|
|
2288
|
+
return refuse(
|
|
2289
|
+
filePath,
|
|
2290
|
+
"path-escapes-destination",
|
|
2291
|
+
"The file path resolves outside the destination directory."
|
|
2292
|
+
);
|
|
2293
|
+
}
|
|
2294
|
+
let buffer;
|
|
2295
|
+
try {
|
|
2296
|
+
buffer = (0, import_fs5.readFileSync)(absolutePath);
|
|
2297
|
+
} catch (error) {
|
|
2298
|
+
const code = errorCode(error);
|
|
2299
|
+
if (code === "ENOENT" || code === "ENOTDIR") {
|
|
2300
|
+
return refuse(filePath, "file-missing", "The file is not in the destination directory.");
|
|
2301
|
+
}
|
|
2302
|
+
return refuse(
|
|
2303
|
+
filePath,
|
|
2304
|
+
"file-unreadable",
|
|
2305
|
+
`The file could not be read (${code ?? "unknown"}).`
|
|
2306
|
+
);
|
|
2307
|
+
}
|
|
2308
|
+
const content = buffer.toString("utf8");
|
|
2309
|
+
if (!Buffer.from(content, "utf8").equals(buffer)) {
|
|
2310
|
+
return refuse(filePath, "file-not-utf8", "The file is not valid UTF-8 text.");
|
|
2311
|
+
}
|
|
2312
|
+
const lines = splitLines(content);
|
|
2313
|
+
const { start, end } = lineRange;
|
|
2314
|
+
if (start < 1 || end < start || end > lines.length) {
|
|
2315
|
+
return refuse(
|
|
2316
|
+
filePath,
|
|
2317
|
+
"anchor-out-of-range",
|
|
2318
|
+
`Lines ${start}-${end} are outside this file, which has ${lines.length} line(s).`
|
|
2319
|
+
);
|
|
2320
|
+
}
|
|
2321
|
+
const anchored = lines.slice(start - 1, end);
|
|
2322
|
+
if (anchored.join("\n") !== suggestion.originalCode) {
|
|
2323
|
+
return refuse(
|
|
2324
|
+
filePath,
|
|
2325
|
+
"context-mismatch",
|
|
2326
|
+
`Lines ${start}-${end} no longer match the code this suggestion was written against.`
|
|
2327
|
+
);
|
|
2328
|
+
}
|
|
2329
|
+
const proposed = suggestion.proposedCode.split("\n");
|
|
2330
|
+
const replacement = isCrlfRegion(anchored) ? proposed.map((line) => line.endsWith("\r") ? line : `${line}\r`) : proposed;
|
|
2331
|
+
const updated = [...lines.slice(0, start - 1), ...replacement, ...lines.slice(end)];
|
|
2332
|
+
const output = updated.join("\n") + (content.endsWith("\n") ? "\n" : "");
|
|
2333
|
+
try {
|
|
2334
|
+
(0, import_fs5.writeFileSync)(absolutePath, output, "utf8");
|
|
2335
|
+
} catch (error) {
|
|
2336
|
+
return refuse(
|
|
2337
|
+
filePath,
|
|
2338
|
+
"write-failed",
|
|
2339
|
+
`The file could not be written (${errorCode(error) ?? "unknown"}).`
|
|
2340
|
+
);
|
|
2341
|
+
}
|
|
2342
|
+
return { status: "applied", filePath, absolutePath, replacedLines: anchored.length };
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
// src/file-type-utils.ts
|
|
2346
|
+
var RASTER_IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([".jpg", ".jpeg", ".png", ".gif", ".webp", ".ico", ".bmp"]);
|
|
2347
|
+
var MARKDOWN_EXTENSIONS = /* @__PURE__ */ new Set([".md", ".markdown"]);
|
|
2105
2348
|
var HTML_EXTENSIONS = /* @__PURE__ */ new Set([".html", ".htm"]);
|
|
2106
2349
|
function getExtension(filePath) {
|
|
2107
2350
|
const lastDot = filePath.lastIndexOf(".");
|
|
@@ -2203,11 +2446,7 @@ async function runGh(runCommand, args) {
|
|
|
2203
2446
|
result = await runCommand(GH_CLI, args);
|
|
2204
2447
|
} catch (error) {
|
|
2205
2448
|
const detail = error instanceof Error ? error.message : String(error);
|
|
2206
|
-
throw new ForgeCliUnavailableError(
|
|
2207
|
-
"github",
|
|
2208
|
-
GH_CLI,
|
|
2209
|
-
`Failed to run the gh CLI: ${detail}`
|
|
2210
|
-
);
|
|
2449
|
+
throw new ForgeCliUnavailableError("github", GH_CLI, `Failed to run the gh CLI: ${detail}`);
|
|
2211
2450
|
}
|
|
2212
2451
|
if (result.exitCode !== 0) {
|
|
2213
2452
|
const detail = result.stderr.trim() || `exit code ${result.exitCode}`;
|
|
@@ -2286,11 +2525,7 @@ function createGitHubProvider(runCommand) {
|
|
|
2286
2525
|
]);
|
|
2287
2526
|
const parsed = parseGhJson(stdout, "pr view");
|
|
2288
2527
|
if (typeof parsed?.baseRefName !== "string" || parsed.baseRefName === "") {
|
|
2289
|
-
throw new ForgeCliUnavailableError(
|
|
2290
|
-
"github",
|
|
2291
|
-
GH_CLI,
|
|
2292
|
-
"gh pr view returned no baseRefName"
|
|
2293
|
-
);
|
|
2528
|
+
throw new ForgeCliUnavailableError("github", GH_CLI, "gh pr view returned no baseRefName");
|
|
2294
2529
|
}
|
|
2295
2530
|
return parsed.baseRefName;
|
|
2296
2531
|
},
|
|
@@ -2343,6 +2578,69 @@ function mapAnchorToLineRange(anchor) {
|
|
|
2343
2578
|
function internalId(turn) {
|
|
2344
2579
|
return `remote-${turn.remoteId}`;
|
|
2345
2580
|
}
|
|
2581
|
+
var FENCE_OPEN = /^( {0,3})(`{3,}|~{3,})(.*)$/;
|
|
2582
|
+
function stripCr(line) {
|
|
2583
|
+
return line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
2584
|
+
}
|
|
2585
|
+
function stripIndent(line, width) {
|
|
2586
|
+
let i = 0;
|
|
2587
|
+
while (i < width && line[i] === " ") i++;
|
|
2588
|
+
return line.slice(i);
|
|
2589
|
+
}
|
|
2590
|
+
function isClosingFence(line, marker) {
|
|
2591
|
+
const match = FENCE_OPEN.exec(line);
|
|
2592
|
+
return match !== null && match[2][0] === marker[0] && match[2].length >= marker.length && match[3].trim() === "";
|
|
2593
|
+
}
|
|
2594
|
+
function findSuggestionBlocks(body) {
|
|
2595
|
+
const lines = body.split("\n").map(stripCr);
|
|
2596
|
+
const blocks = [];
|
|
2597
|
+
let i = 0;
|
|
2598
|
+
while (i < lines.length) {
|
|
2599
|
+
const open = FENCE_OPEN.exec(lines[i]);
|
|
2600
|
+
if (!open) {
|
|
2601
|
+
i++;
|
|
2602
|
+
continue;
|
|
2603
|
+
}
|
|
2604
|
+
const [, indent, marker, info] = open;
|
|
2605
|
+
if (marker[0] === "`" && info.includes("`")) {
|
|
2606
|
+
i++;
|
|
2607
|
+
continue;
|
|
2608
|
+
}
|
|
2609
|
+
const content = [];
|
|
2610
|
+
let j = i + 1;
|
|
2611
|
+
for (; j < lines.length && !isClosingFence(lines[j], marker); j++) {
|
|
2612
|
+
content.push(stripIndent(lines[j], indent.length));
|
|
2613
|
+
}
|
|
2614
|
+
if (info.trim().toLowerCase() === "suggestion") {
|
|
2615
|
+
blocks.push(content.join("\n"));
|
|
2616
|
+
}
|
|
2617
|
+
i = j + 1;
|
|
2618
|
+
}
|
|
2619
|
+
return blocks;
|
|
2620
|
+
}
|
|
2621
|
+
function readAnchoredLines(diffFiles, filePath, range) {
|
|
2622
|
+
const sidePath = (file2) => range.side === "old" ? file2.oldPath : file2.newPath;
|
|
2623
|
+
const file = diffFiles.find((f) => sidePath(f) === filePath) ?? diffFiles.find((f) => f.oldPath === filePath || f.newPath === filePath);
|
|
2624
|
+
if (!file) return null;
|
|
2625
|
+
const found = [];
|
|
2626
|
+
for (const hunk of file.hunks) {
|
|
2627
|
+
for (const line of hunk.lines) {
|
|
2628
|
+
const number = range.side === "old" ? line.oldLineNumber : line.newLineNumber;
|
|
2629
|
+
if (number !== null && number >= range.start && number <= range.end) {
|
|
2630
|
+
found.push(line.content);
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
return found.length === range.end - range.start + 1 ? found.join("\n") : null;
|
|
2635
|
+
}
|
|
2636
|
+
function extractSuggestion(body, filePath, range, diffFiles) {
|
|
2637
|
+
if (!range) return null;
|
|
2638
|
+
const blocks = findSuggestionBlocks(body);
|
|
2639
|
+
if (blocks.length !== 1) return null;
|
|
2640
|
+
const originalCode = readAnchoredLines(diffFiles, filePath, range);
|
|
2641
|
+
if (originalCode === null) return null;
|
|
2642
|
+
return { originalCode, proposedCode: blocks[0] };
|
|
2643
|
+
}
|
|
2346
2644
|
function mapReply(turn) {
|
|
2347
2645
|
return {
|
|
2348
2646
|
id: internalId(turn),
|
|
@@ -2351,15 +2649,17 @@ function mapReply(turn) {
|
|
|
2351
2649
|
remoteId: turn.remoteId
|
|
2352
2650
|
};
|
|
2353
2651
|
}
|
|
2354
|
-
function mapThreadsToReviewComments(threads) {
|
|
2652
|
+
function mapThreadsToReviewComments(threads, diffFiles = []) {
|
|
2355
2653
|
return threads.map((thread) => {
|
|
2654
|
+
const filePath = thread.anchor?.filePath ?? REVIEW_LEVEL_FILE_PATH;
|
|
2655
|
+
const lineRange = thread.anchor ? mapAnchorToLineRange(thread.anchor) : null;
|
|
2356
2656
|
const comment = {
|
|
2357
2657
|
id: internalId(thread.root),
|
|
2358
|
-
filePath
|
|
2359
|
-
lineRange
|
|
2658
|
+
filePath,
|
|
2659
|
+
lineRange,
|
|
2360
2660
|
body: thread.root.body,
|
|
2361
2661
|
category: "",
|
|
2362
|
-
suggestion:
|
|
2662
|
+
suggestion: extractSuggestion(thread.root.body, filePath, lineRange, diffFiles),
|
|
2363
2663
|
author: thread.root.author,
|
|
2364
2664
|
remoteId: thread.root.remoteId
|
|
2365
2665
|
};
|
|
@@ -2516,27 +2816,23 @@ var import_child_process3 = require("child_process");
|
|
|
2516
2816
|
var fs2 = __toESM(require("fs"), 1);
|
|
2517
2817
|
var os = __toESM(require("os"), 1);
|
|
2518
2818
|
var path2 = __toESM(require("path"), 1);
|
|
2819
|
+
init_git();
|
|
2519
2820
|
var LOCAL_BASE_REF = "refs/self-review/base";
|
|
2520
2821
|
var LOCAL_HEAD_REF = "refs/self-review/head";
|
|
2521
2822
|
var AUTH_HINT = "Hint: if this repository is private or requires authentication, run `gh auth setup-git` (GitHub) or `glab auth git-credential` (GitLab) to wire your CLI credentials into git.";
|
|
2522
|
-
var defaultGitRunner = (command, args) => new Promise((
|
|
2523
|
-
(0, import_child_process3.execFile)(
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
const spawnCode = error?.code;
|
|
2529
|
-
if (error && typeof spawnCode === "string") {
|
|
2530
|
-
reject(error);
|
|
2531
|
-
return;
|
|
2532
|
-
}
|
|
2533
|
-
resolve({
|
|
2534
|
-
stdout: stdout ?? "",
|
|
2535
|
-
stderr: stderr ?? "",
|
|
2536
|
-
exitCode: error ? typeof spawnCode === "number" ? spawnCode : 1 : 0
|
|
2537
|
-
});
|
|
2823
|
+
var defaultGitRunner = (command, args) => new Promise((resolve6, reject) => {
|
|
2824
|
+
(0, import_child_process3.execFile)(command, args, { maxBuffer: 50 * 1024 * 1024 }, (error, stdout, stderr) => {
|
|
2825
|
+
const spawnCode = error?.code;
|
|
2826
|
+
if (error && typeof spawnCode === "string") {
|
|
2827
|
+
reject(error);
|
|
2828
|
+
return;
|
|
2538
2829
|
}
|
|
2539
|
-
|
|
2830
|
+
resolve6({
|
|
2831
|
+
stdout: stdout ?? "",
|
|
2832
|
+
stderr: stderr ?? "",
|
|
2833
|
+
exitCode: error ? typeof spawnCode === "number" ? spawnCode : 1 : 0
|
|
2834
|
+
});
|
|
2835
|
+
});
|
|
2540
2836
|
});
|
|
2541
2837
|
function headRefFor(url) {
|
|
2542
2838
|
return url.forge === "github" ? `refs/pull/${url.number}/head` : `refs/merge-requests/${url.number}/head`;
|
|
@@ -2605,7 +2901,7 @@ async function detectExistingClone(url, cwd, runner = defaultGitRunner) {
|
|
|
2605
2901
|
if (toplevel.exitCode !== 0) {
|
|
2606
2902
|
return null;
|
|
2607
2903
|
}
|
|
2608
|
-
const repoPath = toplevel.stdout
|
|
2904
|
+
const repoPath = stripTrailingNewline(toplevel.stdout);
|
|
2609
2905
|
const remotes = await runner("git", ["-C", repoPath, "remote", "-v"]);
|
|
2610
2906
|
if (remotes.exitCode !== 0) {
|
|
2611
2907
|
return null;
|
|
@@ -2614,9 +2910,7 @@ async function detectExistingClone(url, cwd, runner = defaultGitRunner) {
|
|
|
2614
2910
|
return remoteName === null ? null : { repoPath, remoteName };
|
|
2615
2911
|
}
|
|
2616
2912
|
async function materializeIntoExistingClone(runner, url, baseBranch, repoPath, remoteName) {
|
|
2617
|
-
console.error(
|
|
2618
|
-
`self-review: reusing existing clone at ${repoPath} (remote "${remoteName}")`
|
|
2619
|
-
);
|
|
2913
|
+
console.error(`self-review: reusing existing clone at ${repoPath} (remote "${remoteName}")`);
|
|
2620
2914
|
const fetch = await runner("git", [
|
|
2621
2915
|
"-C",
|
|
2622
2916
|
repoPath,
|
|
@@ -2646,16 +2940,9 @@ async function materializeIntoTempClone(runner, url, baseBranch) {
|
|
|
2646
2940
|
fs2.rmSync(tempDir, { recursive: true, force: true });
|
|
2647
2941
|
};
|
|
2648
2942
|
try {
|
|
2649
|
-
console.error(
|
|
2650
|
-
`self-review: created temporary blobless clone at ${tempDir}`
|
|
2651
|
-
);
|
|
2943
|
+
console.error(`self-review: created temporary blobless clone at ${tempDir}`);
|
|
2652
2944
|
const cloneUrl = cloneUrlFor(url);
|
|
2653
|
-
const clone = await runner("git", [
|
|
2654
|
-
"clone",
|
|
2655
|
-
"--filter=blob:none",
|
|
2656
|
-
cloneUrl,
|
|
2657
|
-
tempDir
|
|
2658
|
-
]);
|
|
2945
|
+
const clone = await runner("git", ["clone", "--filter=blob:none", cloneUrl, tempDir]);
|
|
2659
2946
|
if (clone.exitCode !== 0) {
|
|
2660
2947
|
throw gitFailure(`clone of ${cloneUrl}`, clone, true);
|
|
2661
2948
|
}
|
|
@@ -2711,27 +2998,868 @@ async function resolveRemoteDefaultBranch(url, runner = defaultGitRunner, existi
|
|
|
2711
2998
|
}
|
|
2712
2999
|
return match[1];
|
|
2713
3000
|
}
|
|
3001
|
+
|
|
3002
|
+
// src/review-handlers.ts
|
|
3003
|
+
var fs3 = __toESM(require("fs"), 1);
|
|
3004
|
+
var import_path7 = __toESM(require("path"), 1);
|
|
3005
|
+
|
|
3006
|
+
// src/git-diff-args.ts
|
|
3007
|
+
var import_fs6 = require("fs");
|
|
3008
|
+
var import_path6 = require("path");
|
|
3009
|
+
var OPTIONS_WITH_SEPARATE_VALUES = /* @__PURE__ */ new Set([
|
|
3010
|
+
"--output",
|
|
3011
|
+
"--src-prefix",
|
|
3012
|
+
"--dst-prefix",
|
|
3013
|
+
"--line-prefix",
|
|
3014
|
+
"--output-indicator-new",
|
|
3015
|
+
"--output-indicator-old",
|
|
3016
|
+
"--output-indicator-context",
|
|
3017
|
+
"--inter-hunk-context",
|
|
3018
|
+
"--stat-width",
|
|
3019
|
+
"--stat-name-width",
|
|
3020
|
+
"--stat-graph-width",
|
|
3021
|
+
"--stat-count",
|
|
3022
|
+
"--diff-algorithm",
|
|
3023
|
+
"--word-diff-regex",
|
|
3024
|
+
"--ignore-matching-lines",
|
|
3025
|
+
"--anchored",
|
|
3026
|
+
"--diff-filter",
|
|
3027
|
+
"--find-object",
|
|
3028
|
+
"--rotate-to",
|
|
3029
|
+
"--skip-to",
|
|
3030
|
+
"--ws-error-highlight",
|
|
3031
|
+
"--color-moved-ws"
|
|
3032
|
+
]);
|
|
3033
|
+
function consumesNextArgument(arg) {
|
|
3034
|
+
if (arg.startsWith("--")) return OPTIONS_WITH_SEPARATE_VALUES.has(arg);
|
|
3035
|
+
if (!arg.startsWith("-")) return false;
|
|
3036
|
+
for (let i = 1; i < arg.length; i++) {
|
|
3037
|
+
if ("SGOIl".includes(arg[i])) return i === arg.length - 1;
|
|
3038
|
+
if ("UBMC".includes(arg[i])) return false;
|
|
3039
|
+
}
|
|
3040
|
+
return false;
|
|
3041
|
+
}
|
|
3042
|
+
function classifyGitDiffArgs(args) {
|
|
3043
|
+
const positionalIndices = [];
|
|
3044
|
+
let hasSeparator = false;
|
|
3045
|
+
for (let i = 0; i < args.length; i++) {
|
|
3046
|
+
const arg = args[i];
|
|
3047
|
+
if (!hasSeparator) {
|
|
3048
|
+
if (arg === "--") {
|
|
3049
|
+
hasSeparator = true;
|
|
3050
|
+
continue;
|
|
3051
|
+
}
|
|
3052
|
+
if (consumesNextArgument(arg)) {
|
|
3053
|
+
i++;
|
|
3054
|
+
continue;
|
|
3055
|
+
}
|
|
3056
|
+
if (arg.startsWith("-")) continue;
|
|
3057
|
+
}
|
|
3058
|
+
positionalIndices.push(i);
|
|
3059
|
+
}
|
|
3060
|
+
return { positionalIndices, hasSeparator };
|
|
3061
|
+
}
|
|
3062
|
+
function normalizeGitDiffArgs(args, cwd = process.cwd()) {
|
|
3063
|
+
const { positionalIndices, hasSeparator } = classifyGitDiffArgs(args);
|
|
3064
|
+
if (hasSeparator) return args;
|
|
3065
|
+
for (const i of positionalIndices) {
|
|
3066
|
+
const arg = args[i];
|
|
3067
|
+
if ((0, import_fs6.existsSync)((0, import_path6.resolve)(cwd, arg))) {
|
|
3068
|
+
return [...args.slice(0, i), "--", ...args.slice(i)];
|
|
3069
|
+
}
|
|
3070
|
+
}
|
|
3071
|
+
return args;
|
|
3072
|
+
}
|
|
3073
|
+
function tokenizeGitDiffArgs(value) {
|
|
3074
|
+
const args = [];
|
|
3075
|
+
let current = "";
|
|
3076
|
+
let started = false;
|
|
3077
|
+
let quote = null;
|
|
3078
|
+
for (let i = 0; i < value.length; i++) {
|
|
3079
|
+
const char = value[i];
|
|
3080
|
+
if (quote === "'") {
|
|
3081
|
+
if (char === "'") quote = null;
|
|
3082
|
+
else current += char;
|
|
3083
|
+
continue;
|
|
3084
|
+
}
|
|
3085
|
+
if (quote === '"') {
|
|
3086
|
+
if (char === "\\" && (value[i + 1] === '"' || value[i + 1] === "\\")) {
|
|
3087
|
+
current += value[++i];
|
|
3088
|
+
} else if (char === '"') {
|
|
3089
|
+
quote = null;
|
|
3090
|
+
} else {
|
|
3091
|
+
current += char;
|
|
3092
|
+
}
|
|
3093
|
+
continue;
|
|
3094
|
+
}
|
|
3095
|
+
if (char === "'" || char === '"') {
|
|
3096
|
+
quote = char;
|
|
3097
|
+
started = true;
|
|
3098
|
+
continue;
|
|
3099
|
+
}
|
|
3100
|
+
if (char === "\\" && i + 1 < value.length) {
|
|
3101
|
+
current += value[++i];
|
|
3102
|
+
started = true;
|
|
3103
|
+
continue;
|
|
3104
|
+
}
|
|
3105
|
+
if (/\s/.test(char)) {
|
|
3106
|
+
if (started) {
|
|
3107
|
+
args.push(current);
|
|
3108
|
+
current = "";
|
|
3109
|
+
started = false;
|
|
3110
|
+
}
|
|
3111
|
+
continue;
|
|
3112
|
+
}
|
|
3113
|
+
current += char;
|
|
3114
|
+
started = true;
|
|
3115
|
+
}
|
|
3116
|
+
if (started) args.push(current);
|
|
3117
|
+
return args;
|
|
3118
|
+
}
|
|
3119
|
+
function needsQuoting2(arg) {
|
|
3120
|
+
return arg.length === 0 || /[\s'"\\]/.test(arg);
|
|
3121
|
+
}
|
|
3122
|
+
function formatGitDiffArgs(args) {
|
|
3123
|
+
return args.map((arg) => needsQuoting2(arg) ? `'${arg.replace(/'/g, "'\\''")}'` : arg).join(" ");
|
|
3124
|
+
}
|
|
3125
|
+
|
|
3126
|
+
// src/review-handlers.ts
|
|
3127
|
+
function createReviewSession() {
|
|
3128
|
+
return {
|
|
3129
|
+
reviewState: null,
|
|
3130
|
+
diffData: null,
|
|
3131
|
+
guideData: null,
|
|
3132
|
+
config: null,
|
|
3133
|
+
outputPathInfo: null,
|
|
3134
|
+
resumeComments: [],
|
|
3135
|
+
resumeViewedFiles: [],
|
|
3136
|
+
resumeRemoteDrift: null,
|
|
3137
|
+
applyDestinationRoot: null
|
|
3138
|
+
};
|
|
3139
|
+
}
|
|
3140
|
+
function preparePayload(payload) {
|
|
3141
|
+
if (payload.isLargePayload) {
|
|
3142
|
+
return {
|
|
3143
|
+
...payload,
|
|
3144
|
+
files: payload.files.map((f) => ({ ...f, hunks: [], contentLoaded: false }))
|
|
3145
|
+
};
|
|
3146
|
+
}
|
|
3147
|
+
return {
|
|
3148
|
+
...payload,
|
|
3149
|
+
files: payload.files.map((f) => ({ ...f, contentLoaded: true }))
|
|
3150
|
+
};
|
|
3151
|
+
}
|
|
3152
|
+
function getDiffLoad(session) {
|
|
3153
|
+
if (!session.diffData) {
|
|
3154
|
+
return null;
|
|
3155
|
+
}
|
|
3156
|
+
return {
|
|
3157
|
+
diff: preparePayload(session.diffData),
|
|
3158
|
+
guide: session.guideData
|
|
3159
|
+
};
|
|
3160
|
+
}
|
|
3161
|
+
function resolveSourceBaseDir(session) {
|
|
3162
|
+
const source = session.diffData?.source;
|
|
3163
|
+
if (!source) return null;
|
|
3164
|
+
if (source.type === "git") return source.repository;
|
|
3165
|
+
if (source.type === "directory") return source.sourcePath;
|
|
3166
|
+
if (source.type === "file") return import_path7.default.dirname(source.sourcePath);
|
|
3167
|
+
return null;
|
|
3168
|
+
}
|
|
3169
|
+
async function loadImage(session, filePath) {
|
|
3170
|
+
const MIME_MAP = {
|
|
3171
|
+
".jpg": "image/jpeg",
|
|
3172
|
+
".jpeg": "image/jpeg",
|
|
3173
|
+
".png": "image/png",
|
|
3174
|
+
".gif": "image/gif",
|
|
3175
|
+
".webp": "image/webp",
|
|
3176
|
+
".ico": "image/x-icon",
|
|
3177
|
+
".bmp": "image/bmp",
|
|
3178
|
+
".svg": "image/svg+xml"
|
|
3179
|
+
};
|
|
3180
|
+
const MAX_SIZE = 10 * 1024 * 1024;
|
|
3181
|
+
const baseDir = resolveSourceBaseDir(session) ?? process.cwd();
|
|
3182
|
+
const resolved = import_path7.default.isAbsolute(filePath) ? filePath : import_path7.default.resolve(baseDir, filePath);
|
|
3183
|
+
const ext = import_path7.default.extname(filePath).toLowerCase();
|
|
3184
|
+
const mimeType = MIME_MAP[ext] ?? "application/octet-stream";
|
|
3185
|
+
const remote = session.diffData?.remote;
|
|
3186
|
+
if (remote && session.diffData?.source.type === "git") {
|
|
3187
|
+
try {
|
|
3188
|
+
const { readGitBlobAsync: readGitBlobAsync2 } = await Promise.resolve().then(() => (init_git(), git_exports));
|
|
3189
|
+
const data = await readGitBlobAsync2(
|
|
3190
|
+
session.diffData.source.repository,
|
|
3191
|
+
`${remote.remoteHeadSha}:${filePath}`
|
|
3192
|
+
);
|
|
3193
|
+
if (data.length > MAX_SIZE) {
|
|
3194
|
+
return { error: "File too large to preview (>10 MB)" };
|
|
3195
|
+
}
|
|
3196
|
+
return { dataUri: `data:${mimeType};base64,${data.toString("base64")}` };
|
|
3197
|
+
} catch {
|
|
3198
|
+
return {
|
|
3199
|
+
error: "Image preview unavailable \u2014 blob not found at the reviewed commit."
|
|
3200
|
+
};
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3203
|
+
try {
|
|
3204
|
+
const stat2 = await fs3.promises.stat(resolved);
|
|
3205
|
+
if (stat2.size > MAX_SIZE) {
|
|
3206
|
+
return { error: "File too large to preview (>10 MB)" };
|
|
3207
|
+
}
|
|
3208
|
+
const data = await fs3.promises.readFile(resolved);
|
|
3209
|
+
return { dataUri: `data:${mimeType};base64,${data.toString("base64")}` };
|
|
3210
|
+
} catch {
|
|
3211
|
+
return { error: "Image preview unavailable \u2014 file not found on disk." };
|
|
3212
|
+
}
|
|
3213
|
+
}
|
|
3214
|
+
function getFileHunks(session, filePath) {
|
|
3215
|
+
if (!session.diffData) return null;
|
|
3216
|
+
const file = session.diffData.files.find((f) => (f.newPath || f.oldPath) === filePath);
|
|
3217
|
+
if (!file) return null;
|
|
3218
|
+
return file.hunks;
|
|
3219
|
+
}
|
|
3220
|
+
function getConfigLoad(session) {
|
|
3221
|
+
if (!session.config) {
|
|
3222
|
+
return null;
|
|
3223
|
+
}
|
|
3224
|
+
return { config: session.config, outputPathInfo: session.outputPathInfo };
|
|
3225
|
+
}
|
|
3226
|
+
function submitReviewState(session, state) {
|
|
3227
|
+
console.error(
|
|
3228
|
+
"[review] Review state submitted:",
|
|
3229
|
+
JSON.stringify({
|
|
3230
|
+
timestamp: state.timestamp,
|
|
3231
|
+
source: state.source,
|
|
3232
|
+
fileCount: state.files.length
|
|
3233
|
+
})
|
|
3234
|
+
);
|
|
3235
|
+
session.reviewState = state;
|
|
3236
|
+
}
|
|
3237
|
+
function takeReviewState(session) {
|
|
3238
|
+
const state = session.reviewState;
|
|
3239
|
+
session.reviewState = null;
|
|
3240
|
+
return state;
|
|
3241
|
+
}
|
|
3242
|
+
function isTemporaryCloneSession(session) {
|
|
3243
|
+
return session.diffData?.remote?.temporaryClone === true;
|
|
3244
|
+
}
|
|
3245
|
+
function resolveApplyDestination(session) {
|
|
3246
|
+
if (isTemporaryCloneSession(session)) {
|
|
3247
|
+
return session.applyDestinationRoot;
|
|
3248
|
+
}
|
|
3249
|
+
return resolveSourceBaseDir(session);
|
|
3250
|
+
}
|
|
3251
|
+
function applySuggestionForSession(session, request) {
|
|
3252
|
+
const destinationRoot = resolveApplyDestination(session);
|
|
3253
|
+
if (!destinationRoot) {
|
|
3254
|
+
const temporary = isTemporaryCloneSession(session);
|
|
3255
|
+
return {
|
|
3256
|
+
status: "refused",
|
|
3257
|
+
filePath: request.filePath,
|
|
3258
|
+
reason: temporary ? "destination-required" : "no-destination",
|
|
3259
|
+
detail: temporary ? "This pull request was cloned into a temporary directory that is deleted when the review ends. Choose a destination directory to apply into." : "This review has no working directory to write into."
|
|
3260
|
+
};
|
|
3261
|
+
}
|
|
3262
|
+
const result = applySuggestion({
|
|
3263
|
+
destinationRoot,
|
|
3264
|
+
filePath: request.filePath,
|
|
3265
|
+
lineRange: request.lineRange,
|
|
3266
|
+
suggestion: request.suggestion
|
|
3267
|
+
});
|
|
3268
|
+
console.error(
|
|
3269
|
+
`[suggestion:apply] ${request.filePath}: ${result.status === "applied" ? "applied" : `refused (${result.reason})`}`
|
|
3270
|
+
);
|
|
3271
|
+
if (result.status === "applied") {
|
|
3272
|
+
return {
|
|
3273
|
+
status: "applied",
|
|
3274
|
+
filePath: result.filePath,
|
|
3275
|
+
replacedLines: result.replacedLines
|
|
3276
|
+
};
|
|
3277
|
+
}
|
|
3278
|
+
return {
|
|
3279
|
+
status: "refused",
|
|
3280
|
+
filePath: result.filePath,
|
|
3281
|
+
reason: result.reason,
|
|
3282
|
+
detail: result.detail
|
|
3283
|
+
};
|
|
3284
|
+
}
|
|
3285
|
+
async function readAttachment(filePath) {
|
|
3286
|
+
try {
|
|
3287
|
+
const buffer = await fs3.promises.readFile(filePath);
|
|
3288
|
+
return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
3289
|
+
} catch {
|
|
3290
|
+
console.error(`[attachment:read] Failed to read file: ${filePath}`);
|
|
3291
|
+
return null;
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
3294
|
+
function getResumeLoad(session) {
|
|
3295
|
+
if (session.resumeComments.length > 0 || session.resumeViewedFiles.length > 0 || session.resumeRemoteDrift !== null) {
|
|
3296
|
+
const payload = {
|
|
3297
|
+
comments: session.resumeComments,
|
|
3298
|
+
viewedFiles: session.resumeViewedFiles
|
|
3299
|
+
};
|
|
3300
|
+
if (session.resumeRemoteDrift !== null) {
|
|
3301
|
+
payload.remoteDrift = session.resumeRemoteDrift;
|
|
3302
|
+
}
|
|
3303
|
+
return payload;
|
|
3304
|
+
}
|
|
3305
|
+
return null;
|
|
3306
|
+
}
|
|
3307
|
+
async function expandContext(session, request) {
|
|
3308
|
+
const diffData = session.diffData;
|
|
3309
|
+
if (!diffData || diffData.source.type !== "git") {
|
|
3310
|
+
return null;
|
|
3311
|
+
}
|
|
3312
|
+
try {
|
|
3313
|
+
const { runGitDiffAsync: runGitDiffAsync2 } = await Promise.resolve().then(() => (init_git(), git_exports));
|
|
3314
|
+
const { parseDiff: parseDiff2 } = await Promise.resolve().then(() => (init_diff_parser(), diff_parser_exports));
|
|
3315
|
+
const source = diffData.source;
|
|
3316
|
+
const originalArgs = tokenizeGitDiffArgs(source.gitDiffArgs);
|
|
3317
|
+
const filteredArgs = [];
|
|
3318
|
+
for (let i = 0; i < originalArgs.length; i++) {
|
|
3319
|
+
const arg = originalArgs[i];
|
|
3320
|
+
if (arg.match(/^-U\d+$/) || arg.match(/^--unified=\d+$/)) {
|
|
3321
|
+
continue;
|
|
3322
|
+
}
|
|
3323
|
+
if (arg === "-U" || arg === "--unified") {
|
|
3324
|
+
i++;
|
|
3325
|
+
continue;
|
|
3326
|
+
}
|
|
3327
|
+
if (arg === "--") {
|
|
3328
|
+
break;
|
|
3329
|
+
}
|
|
3330
|
+
filteredArgs.push(arg);
|
|
3331
|
+
}
|
|
3332
|
+
const expandArgs = [...filteredArgs, `-U${request.contextLines}`, "--", request.filePath];
|
|
3333
|
+
const rawDiff = await runGitDiffAsync2(expandArgs, source.repository);
|
|
3334
|
+
const parsedFiles = parseDiff2(rawDiff);
|
|
3335
|
+
if (parsedFiles.length === 0) {
|
|
3336
|
+
return null;
|
|
3337
|
+
}
|
|
3338
|
+
const expandedFile = parsedFiles[0];
|
|
3339
|
+
let totalLines = 0;
|
|
3340
|
+
try {
|
|
3341
|
+
const content = await fs3.promises.readFile(
|
|
3342
|
+
import_path7.default.resolve(source.repository, request.filePath),
|
|
3343
|
+
"utf-8"
|
|
3344
|
+
);
|
|
3345
|
+
totalLines = content.split("\n").length;
|
|
3346
|
+
if (content.endsWith("\n")) totalLines--;
|
|
3347
|
+
} catch {
|
|
3348
|
+
}
|
|
3349
|
+
session.diffData = {
|
|
3350
|
+
...diffData,
|
|
3351
|
+
files: diffData.files.map((f) => {
|
|
3352
|
+
const fPath = f.newPath || f.oldPath;
|
|
3353
|
+
if (fPath === request.filePath) {
|
|
3354
|
+
return { ...f, hunks: expandedFile.hunks };
|
|
3355
|
+
}
|
|
3356
|
+
return f;
|
|
3357
|
+
})
|
|
3358
|
+
};
|
|
3359
|
+
return { hunks: expandedFile.hunks, totalLines };
|
|
3360
|
+
} catch (error) {
|
|
3361
|
+
console.error(`[review] Failed to expand context for ${request.filePath}:`, error);
|
|
3362
|
+
return null;
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
async function prepareDirectoryReview(session, directoryPath) {
|
|
3366
|
+
console.error("[review] Starting directory review for:", directoryPath);
|
|
3367
|
+
let isFile = false;
|
|
3368
|
+
try {
|
|
3369
|
+
isFile = fs3.statSync(directoryPath).isFile();
|
|
3370
|
+
} catch {
|
|
3371
|
+
}
|
|
3372
|
+
let payload;
|
|
3373
|
+
if (isFile) {
|
|
3374
|
+
const files = await scanFile(directoryPath);
|
|
3375
|
+
payload = {
|
|
3376
|
+
files,
|
|
3377
|
+
source: { type: "file", sourcePath: directoryPath }
|
|
3378
|
+
};
|
|
3379
|
+
} else {
|
|
3380
|
+
const ignorePatterns = session.config?.ignore ?? [];
|
|
3381
|
+
const files = await scanDirectory(directoryPath, ignorePatterns);
|
|
3382
|
+
payload = {
|
|
3383
|
+
files,
|
|
3384
|
+
source: { type: "directory", sourcePath: directoryPath }
|
|
3385
|
+
};
|
|
3386
|
+
}
|
|
3387
|
+
if (!session.config) {
|
|
3388
|
+
return { payload, stats: null, exceedsThresholds: false };
|
|
3389
|
+
}
|
|
3390
|
+
const stats = computePayloadStats(
|
|
3391
|
+
payload.files.length,
|
|
3392
|
+
countTotalLines(payload.files),
|
|
3393
|
+
session.config
|
|
3394
|
+
);
|
|
3395
|
+
return { payload, stats, exceedsThresholds: stats.exceedsAny };
|
|
3396
|
+
}
|
|
3397
|
+
function commitReviewStart(session, payload) {
|
|
3398
|
+
session.diffData = payload;
|
|
3399
|
+
return preparePayload(payload);
|
|
3400
|
+
}
|
|
3401
|
+
|
|
3402
|
+
// src/startup-mode.ts
|
|
3403
|
+
var import_fs7 = require("fs");
|
|
3404
|
+
var import_child_process4 = require("child_process");
|
|
3405
|
+
var import_path8 = require("path");
|
|
3406
|
+
function isInGitRepo() {
|
|
3407
|
+
try {
|
|
3408
|
+
(0, import_child_process4.execSync)("git rev-parse --git-dir", { stdio: "ignore" });
|
|
3409
|
+
return true;
|
|
3410
|
+
} catch {
|
|
3411
|
+
return false;
|
|
3412
|
+
}
|
|
3413
|
+
}
|
|
3414
|
+
function isGitTracked(filePath) {
|
|
3415
|
+
try {
|
|
3416
|
+
(0, import_child_process4.execFileSync)("git", ["ls-files", "--error-unmatch", "--", filePath], {
|
|
3417
|
+
stdio: "ignore"
|
|
3418
|
+
});
|
|
3419
|
+
return true;
|
|
3420
|
+
} catch {
|
|
3421
|
+
return false;
|
|
3422
|
+
}
|
|
3423
|
+
}
|
|
3424
|
+
function determineMode(gitDiffArgs) {
|
|
3425
|
+
const { positionalIndices } = classifyGitDiffArgs(gitDiffArgs);
|
|
3426
|
+
const firstPositional = gitDiffArgs[positionalIndices[0]];
|
|
3427
|
+
if (firstPositional) {
|
|
3428
|
+
const candidate = (0, import_path8.resolve)(process.cwd(), firstPositional);
|
|
3429
|
+
try {
|
|
3430
|
+
if ((0, import_fs7.existsSync)(candidate) && (0, import_fs7.statSync)(candidate).isFile()) {
|
|
3431
|
+
if (isInGitRepo()) {
|
|
3432
|
+
return isGitTracked(firstPositional) ? "git" : "file";
|
|
3433
|
+
}
|
|
3434
|
+
return "file";
|
|
3435
|
+
}
|
|
3436
|
+
} catch {
|
|
3437
|
+
}
|
|
3438
|
+
}
|
|
3439
|
+
if (isInGitRepo()) {
|
|
3440
|
+
return "git";
|
|
3441
|
+
}
|
|
3442
|
+
if (firstPositional) {
|
|
3443
|
+
const candidate = (0, import_path8.resolve)(process.cwd(), firstPositional);
|
|
3444
|
+
try {
|
|
3445
|
+
if ((0, import_fs7.existsSync)(candidate) && (0, import_fs7.statSync)(candidate).isDirectory()) {
|
|
3446
|
+
return "directory";
|
|
3447
|
+
}
|
|
3448
|
+
} catch {
|
|
3449
|
+
}
|
|
3450
|
+
}
|
|
3451
|
+
return "welcome";
|
|
3452
|
+
}
|
|
3453
|
+
|
|
3454
|
+
// src/guide-loader.ts
|
|
3455
|
+
var import_promises2 = require("fs/promises");
|
|
3456
|
+
var import_path9 = require("path");
|
|
3457
|
+
function deriveGuidePath(outputPath) {
|
|
3458
|
+
const ext = (0, import_path9.extname)(outputPath);
|
|
3459
|
+
const base = ext ? outputPath.slice(0, -ext.length) : outputPath;
|
|
3460
|
+
return `${base}.guide.xml`;
|
|
3461
|
+
}
|
|
3462
|
+
function resolveGuidePath(outputPath, config) {
|
|
3463
|
+
if (config.guideFile) {
|
|
3464
|
+
return (0, import_path9.resolve)(process.cwd(), config.guideFile);
|
|
3465
|
+
}
|
|
3466
|
+
return deriveGuidePath(outputPath);
|
|
3467
|
+
}
|
|
3468
|
+
async function loadGuide(outputPath, config, diffFilePaths) {
|
|
3469
|
+
let guidePath;
|
|
3470
|
+
try {
|
|
3471
|
+
guidePath = resolveGuidePath(outputPath, config);
|
|
3472
|
+
} catch {
|
|
3473
|
+
return null;
|
|
3474
|
+
}
|
|
3475
|
+
try {
|
|
3476
|
+
let content;
|
|
3477
|
+
try {
|
|
3478
|
+
content = await (0, import_promises2.readFile)(guidePath, "utf-8");
|
|
3479
|
+
} catch (error) {
|
|
3480
|
+
const code = error.code;
|
|
3481
|
+
if (code === "ENOENT") {
|
|
3482
|
+
return null;
|
|
3483
|
+
}
|
|
3484
|
+
console.error(
|
|
3485
|
+
`[guide] Ignoring guide at ${guidePath}: unreadable (${code ?? "unknown error"})`
|
|
3486
|
+
);
|
|
3487
|
+
return null;
|
|
3488
|
+
}
|
|
3489
|
+
const result = await parseGuideXml(content);
|
|
3490
|
+
if (result.ok === false) {
|
|
3491
|
+
console.error(`[guide] Ignoring guide at ${guidePath}: invalid (${result.reason})`);
|
|
3492
|
+
return null;
|
|
3493
|
+
}
|
|
3494
|
+
const payload = {
|
|
3495
|
+
groups: reconcileGuide(result.guide, diffFilePaths)
|
|
3496
|
+
};
|
|
3497
|
+
if (result.guide.overview !== void 0) {
|
|
3498
|
+
payload.overview = result.guide.overview;
|
|
3499
|
+
}
|
|
3500
|
+
return payload;
|
|
3501
|
+
} catch (error) {
|
|
3502
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3503
|
+
console.error(`[guide] Ignoring guide at ${guidePath}: invalid (${message})`);
|
|
3504
|
+
return null;
|
|
3505
|
+
}
|
|
3506
|
+
}
|
|
3507
|
+
|
|
3508
|
+
// src/git-diff-loader.ts
|
|
3509
|
+
init_git();
|
|
3510
|
+
init_diff_parser();
|
|
3511
|
+
async function loadGitDiffWithUntracked(gitDiffArgs, cwd, options = {}) {
|
|
3512
|
+
const { includeUntracked = true } = options;
|
|
3513
|
+
const repository = await getRepoRootAsync(cwd);
|
|
3514
|
+
const rawDiff = await runGitDiffAsync(gitDiffArgs, cwd);
|
|
3515
|
+
const files = parseDiff(rawDiff);
|
|
3516
|
+
if (!includeUntracked) {
|
|
3517
|
+
return { files, repository };
|
|
3518
|
+
}
|
|
3519
|
+
const untrackedPaths = await getUntrackedFilesAsync(repository);
|
|
3520
|
+
let allFiles = files;
|
|
3521
|
+
if (untrackedPaths.length > 0) {
|
|
3522
|
+
const untrackedDiffStr = generateUntrackedDiffs(untrackedPaths, repository);
|
|
3523
|
+
if (untrackedDiffStr.length > 0) {
|
|
3524
|
+
const untrackedFiles = parseDiff(untrackedDiffStr);
|
|
3525
|
+
for (const file of untrackedFiles) {
|
|
3526
|
+
file.isUntracked = true;
|
|
3527
|
+
}
|
|
3528
|
+
allFiles = [...files, ...untrackedFiles];
|
|
3529
|
+
}
|
|
3530
|
+
}
|
|
3531
|
+
return { files: allFiles, repository };
|
|
3532
|
+
}
|
|
3533
|
+
|
|
3534
|
+
// src/staged-untracked.ts
|
|
3535
|
+
function applyStagedUntrackedDefault(config, gitDiffArgs) {
|
|
3536
|
+
const stagedMode = gitDiffArgs.includes("--staged") || gitDiffArgs.includes("--cached");
|
|
3537
|
+
if (!stagedMode) return config;
|
|
3538
|
+
const userExplicitOptIn = config.showUntrackedExplicit && config.showUntracked;
|
|
3539
|
+
if (userExplicitOptIn) return config;
|
|
3540
|
+
return { ...config, showUntracked: false };
|
|
3541
|
+
}
|
|
3542
|
+
|
|
3543
|
+
// src/remote-mode.ts
|
|
3544
|
+
function defaultCreateProvider(forge, runner) {
|
|
3545
|
+
return forge === "github" ? createGitHubProvider(runner) : createGitLabProvider(runner);
|
|
3546
|
+
}
|
|
3547
|
+
var defaultDeps = {
|
|
3548
|
+
createProvider: defaultCreateProvider,
|
|
3549
|
+
detectExistingClone,
|
|
3550
|
+
materialize,
|
|
3551
|
+
resolveRemoteDefaultBranch,
|
|
3552
|
+
runner: defaultGitRunner,
|
|
3553
|
+
loadDiff: (gitDiffArgs, cwd) => (
|
|
3554
|
+
// A base...head diff of a remote PR/MR must never pick up local
|
|
3555
|
+
// untracked files (an existing clone may have unrelated ones).
|
|
3556
|
+
loadGitDiffWithUntracked(gitDiffArgs, cwd, { includeUntracked: false })
|
|
3557
|
+
)
|
|
3558
|
+
};
|
|
3559
|
+
async function startRemoteSession(url, cwd, deps = {}) {
|
|
3560
|
+
const d = { ...defaultDeps, ...deps };
|
|
3561
|
+
const forgeUrl = parseForgeUrl(url);
|
|
3562
|
+
if (!forgeUrl) {
|
|
3563
|
+
throw new Error(`Not a recognized pull-request or merge-request URL: ${url}`);
|
|
3564
|
+
}
|
|
3565
|
+
const provider = d.createProvider(forgeUrl.forge, d.runner);
|
|
3566
|
+
let cliAvailable = true;
|
|
3567
|
+
let baseBranch;
|
|
3568
|
+
let existingClone;
|
|
3569
|
+
try {
|
|
3570
|
+
baseBranch = await provider.fetchBaseBranch(forgeUrl);
|
|
3571
|
+
} catch (error) {
|
|
3572
|
+
if (!(error instanceof ForgeCliUnavailableError)) {
|
|
3573
|
+
throw error;
|
|
3574
|
+
}
|
|
3575
|
+
cliAvailable = false;
|
|
3576
|
+
console.error(
|
|
3577
|
+
`[remote] Forge CLI unavailable (${error.cli}): ${error.message} \u2014 falling back to the remote default branch via git.`
|
|
3578
|
+
);
|
|
3579
|
+
existingClone = await d.detectExistingClone(forgeUrl, cwd, d.runner);
|
|
3580
|
+
baseBranch = await d.resolveRemoteDefaultBranch(forgeUrl, d.runner, existingClone);
|
|
3581
|
+
}
|
|
3582
|
+
const materialized = await d.materialize(forgeUrl, baseBranch, cwd, d.runner, existingClone);
|
|
3583
|
+
let fetchedThreads = [];
|
|
3584
|
+
let threadSyncAvailable = false;
|
|
3585
|
+
if (cliAvailable) {
|
|
3586
|
+
try {
|
|
3587
|
+
fetchedThreads = await provider.fetchThreads(forgeUrl);
|
|
3588
|
+
threadSyncAvailable = true;
|
|
3589
|
+
} catch (error) {
|
|
3590
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3591
|
+
console.error(
|
|
3592
|
+
`[remote] thread sync unavailable \u2014 continuing without forge threads: ${message}`
|
|
3593
|
+
);
|
|
3594
|
+
}
|
|
3595
|
+
} else {
|
|
3596
|
+
console.error(
|
|
3597
|
+
"[remote] thread sync unavailable \u2014 forge CLI missing, continuing without forge threads."
|
|
3598
|
+
);
|
|
3599
|
+
}
|
|
3600
|
+
return {
|
|
3601
|
+
forgeUrl,
|
|
3602
|
+
repoPath: materialized.repoPath,
|
|
3603
|
+
gitDiffArgs: [`${materialized.baseSha}...${materialized.headSha}`],
|
|
3604
|
+
mode: materialized.mode,
|
|
3605
|
+
cleanup: materialized.cleanup,
|
|
3606
|
+
remote: {
|
|
3607
|
+
remoteUrl: url,
|
|
3608
|
+
remoteBaseSha: materialized.baseSha,
|
|
3609
|
+
remoteHeadSha: materialized.headSha,
|
|
3610
|
+
remoteForge: forgeUrl.forge,
|
|
3611
|
+
threadSyncAvailable,
|
|
3612
|
+
// A temporary clone is deleted on exit, so nothing may be written
|
|
3613
|
+
// into it; the front end needs the fact, not the path.
|
|
3614
|
+
temporaryClone: materialized.mode === "temp-clone"
|
|
3615
|
+
},
|
|
3616
|
+
fetchedComments: mapThreadsToReviewComments(fetchedThreads),
|
|
3617
|
+
fetchedThreads
|
|
3618
|
+
};
|
|
3619
|
+
}
|
|
3620
|
+
async function bootstrapRemoteDiff(url, cwd, ignorePatterns, deps = {}) {
|
|
3621
|
+
const d = { ...defaultDeps, ...deps };
|
|
3622
|
+
const started = await startRemoteSession(url, cwd, d);
|
|
3623
|
+
let files;
|
|
3624
|
+
let repository;
|
|
3625
|
+
try {
|
|
3626
|
+
({ files, repository } = await d.loadDiff(started.gitDiffArgs, started.repoPath));
|
|
3627
|
+
} catch (error) {
|
|
3628
|
+
started.cleanup();
|
|
3629
|
+
throw error;
|
|
3630
|
+
}
|
|
3631
|
+
const shouldKeep = createIgnoreFilter(ignorePatterns);
|
|
3632
|
+
const filteredFiles = files.filter((f) => shouldKeep(f.newPath || f.oldPath));
|
|
3633
|
+
const session = {
|
|
3634
|
+
...started,
|
|
3635
|
+
fetchedComments: mapThreadsToReviewComments(started.fetchedThreads, filteredFiles)
|
|
3636
|
+
};
|
|
3637
|
+
return {
|
|
3638
|
+
session,
|
|
3639
|
+
payload: {
|
|
3640
|
+
files: filteredFiles,
|
|
3641
|
+
source: {
|
|
3642
|
+
type: "git",
|
|
3643
|
+
// Same renderer the git-mode path uses, so expand-context can
|
|
3644
|
+
// tokenize this string back into the exact argv.
|
|
3645
|
+
gitDiffArgs: formatGitDiffArgs(session.gitDiffArgs),
|
|
3646
|
+
repository
|
|
3647
|
+
},
|
|
3648
|
+
remote: session.remote
|
|
3649
|
+
}
|
|
3650
|
+
};
|
|
3651
|
+
}
|
|
3652
|
+
function mergeRemoteThreads(resumed, fetched) {
|
|
3653
|
+
const resumedRemoteIds = new Set(
|
|
3654
|
+
resumed.map((c) => c.remoteId).filter((id) => id !== void 0)
|
|
3655
|
+
);
|
|
3656
|
+
return [
|
|
3657
|
+
...resumed,
|
|
3658
|
+
...fetched.filter((c) => c.remoteId === void 0 || !resumedRemoteIds.has(c.remoteId))
|
|
3659
|
+
];
|
|
3660
|
+
}
|
|
3661
|
+
function applyRemoteProvenance(state, remote) {
|
|
3662
|
+
return {
|
|
3663
|
+
...state,
|
|
3664
|
+
// The three source shapes are mutually exclusive in the document: the
|
|
3665
|
+
// remote-* attributes ARE the source, so the in-session git source
|
|
3666
|
+
// (the materialized clone) must not leak into the saved review. The
|
|
3667
|
+
// welcome source emits no source attributes, mirroring fetch-comments.
|
|
3668
|
+
source: { type: "welcome" },
|
|
3669
|
+
remoteUrl: remote.remoteUrl,
|
|
3670
|
+
remoteBaseSha: remote.remoteBaseSha,
|
|
3671
|
+
remoteHeadSha: remote.remoteHeadSha,
|
|
3672
|
+
remoteForge: remote.remoteForge
|
|
3673
|
+
};
|
|
3674
|
+
}
|
|
3675
|
+
function computeRemoteDrift(recordedHeadSha, liveHeadSha) {
|
|
3676
|
+
if (recordedHeadSha === void 0) {
|
|
3677
|
+
return null;
|
|
3678
|
+
}
|
|
3679
|
+
return {
|
|
3680
|
+
recordedHeadSha,
|
|
3681
|
+
liveHeadSha,
|
|
3682
|
+
drifted: recordedHeadSha !== liveHeadSha
|
|
3683
|
+
};
|
|
3684
|
+
}
|
|
3685
|
+
|
|
3686
|
+
// src/fetch-comments.ts
|
|
3687
|
+
var import_fs8 = require("fs");
|
|
3688
|
+
var import_path10 = require("path");
|
|
3689
|
+
init_diff_parser();
|
|
3690
|
+
init_git();
|
|
3691
|
+
function defaultDeps2() {
|
|
3692
|
+
return {
|
|
3693
|
+
runner: defaultGitRunner,
|
|
3694
|
+
createProvider: (forge, runner) => forge === "github" ? createGitHubProvider(runner) : createGitLabProvider(runner),
|
|
3695
|
+
detectExistingClone,
|
|
3696
|
+
materialize,
|
|
3697
|
+
resolveRemoteDefaultBranch,
|
|
3698
|
+
loadDiffFiles: async (repoPath, baseSha, headSha) => (
|
|
3699
|
+
// Triple-dot: diff from the merge base, matching how forges present a
|
|
3700
|
+
// PR/MR diff. Runs inside the materialized clone.
|
|
3701
|
+
parseDiff(await runGitDiffAsync([`${baseSha}...${headSha}`], repoPath))
|
|
3702
|
+
),
|
|
3703
|
+
serialize: serializeReview,
|
|
3704
|
+
writeFile: (path4, content) => (0, import_fs8.writeFileSync)(path4, content, "utf-8"),
|
|
3705
|
+
loadConfig,
|
|
3706
|
+
now: () => /* @__PURE__ */ new Date()
|
|
3707
|
+
};
|
|
3708
|
+
}
|
|
3709
|
+
function buildRemoteReviewState(args) {
|
|
3710
|
+
const commentsByPath = /* @__PURE__ */ new Map();
|
|
3711
|
+
for (const comment of args.comments) {
|
|
3712
|
+
const list = commentsByPath.get(comment.filePath);
|
|
3713
|
+
if (list) {
|
|
3714
|
+
list.push(comment);
|
|
3715
|
+
} else {
|
|
3716
|
+
commentsByPath.set(comment.filePath, [comment]);
|
|
3717
|
+
}
|
|
3718
|
+
}
|
|
3719
|
+
const files = [];
|
|
3720
|
+
const diffPaths = /* @__PURE__ */ new Set();
|
|
3721
|
+
for (const diffFile of args.diffFiles) {
|
|
3722
|
+
const path4 = diffFile.changeType === "deleted" ? diffFile.oldPath : diffFile.newPath;
|
|
3723
|
+
diffPaths.add(path4);
|
|
3724
|
+
files.push({
|
|
3725
|
+
path: path4,
|
|
3726
|
+
changeType: diffFile.changeType,
|
|
3727
|
+
viewed: false,
|
|
3728
|
+
comments: commentsByPath.get(path4) ?? []
|
|
3729
|
+
});
|
|
3730
|
+
}
|
|
3731
|
+
for (const [path4, comments] of commentsByPath) {
|
|
3732
|
+
if (path4 === REVIEW_LEVEL_FILE_PATH || diffPaths.has(path4)) continue;
|
|
3733
|
+
files.push({ path: path4, changeType: "modified", viewed: false, comments });
|
|
3734
|
+
}
|
|
3735
|
+
const reviewLevel = commentsByPath.get(REVIEW_LEVEL_FILE_PATH);
|
|
3736
|
+
if (reviewLevel && reviewLevel.length > 0) {
|
|
3737
|
+
files.push({
|
|
3738
|
+
path: REVIEW_LEVEL_FILE_PATH,
|
|
3739
|
+
changeType: "modified",
|
|
3740
|
+
viewed: false,
|
|
3741
|
+
comments: reviewLevel
|
|
3742
|
+
});
|
|
3743
|
+
}
|
|
3744
|
+
return {
|
|
3745
|
+
timestamp: args.timestamp,
|
|
3746
|
+
source: { type: "welcome" },
|
|
3747
|
+
files,
|
|
3748
|
+
remoteUrl: args.remoteUrl,
|
|
3749
|
+
remoteBaseSha: args.baseSha,
|
|
3750
|
+
remoteHeadSha: args.headSha,
|
|
3751
|
+
remoteForge: args.forge
|
|
3752
|
+
};
|
|
3753
|
+
}
|
|
3754
|
+
async function runFetchComments(url, options = {}) {
|
|
3755
|
+
const deps = { ...defaultDeps2(), ...options.deps };
|
|
3756
|
+
const cwd = options.cwd ?? process.cwd();
|
|
3757
|
+
const forgeUrl = parseForgeUrl(url);
|
|
3758
|
+
if (forgeUrl === null) {
|
|
3759
|
+
throw new Error(
|
|
3760
|
+
`Not a recognized pull/merge request URL: ${url}
|
|
3761
|
+
Expected a GitHub PR URL (\u2026/pull/N) or a GitLab MR URL (\u2026/-/merge_requests/N).`
|
|
3762
|
+
);
|
|
3763
|
+
}
|
|
3764
|
+
const provider = deps.createProvider(forgeUrl.forge, deps.runner);
|
|
3765
|
+
let baseBranch;
|
|
3766
|
+
let existingClone;
|
|
3767
|
+
try {
|
|
3768
|
+
baseBranch = await provider.fetchBaseBranch(forgeUrl);
|
|
3769
|
+
} catch (error) {
|
|
3770
|
+
if (!(error instanceof ForgeCliUnavailableError)) throw error;
|
|
3771
|
+
console.error(`[fetch-comments] ${error.message}`);
|
|
3772
|
+
console.error(
|
|
3773
|
+
`[fetch-comments] ${error.cli} unavailable for the base-branch lookup \u2014 falling back to the remote default branch via git ls-remote.`
|
|
3774
|
+
);
|
|
3775
|
+
existingClone = await deps.detectExistingClone(forgeUrl, cwd, deps.runner);
|
|
3776
|
+
baseBranch = await deps.resolveRemoteDefaultBranch(forgeUrl, deps.runner, existingClone);
|
|
3777
|
+
}
|
|
3778
|
+
console.error(`[fetch-comments] Base branch: ${baseBranch}`);
|
|
3779
|
+
const materialized = await deps.materialize(
|
|
3780
|
+
forgeUrl,
|
|
3781
|
+
baseBranch,
|
|
3782
|
+
cwd,
|
|
3783
|
+
deps.runner,
|
|
3784
|
+
existingClone
|
|
3785
|
+
);
|
|
3786
|
+
try {
|
|
3787
|
+
let threads;
|
|
3788
|
+
try {
|
|
3789
|
+
threads = await provider.fetchThreads(forgeUrl, {
|
|
3790
|
+
includeResolved: options.includeResolved ?? false
|
|
3791
|
+
});
|
|
3792
|
+
} catch (error) {
|
|
3793
|
+
if (error instanceof ForgeCliUnavailableError) {
|
|
3794
|
+
throw new Error(
|
|
3795
|
+
`Cannot fetch discussion threads: ${error.message}
|
|
3796
|
+
fetch-comments requires the ${error.cli} CLI to be installed and authenticated.`
|
|
3797
|
+
);
|
|
3798
|
+
}
|
|
3799
|
+
throw error;
|
|
3800
|
+
}
|
|
3801
|
+
console.error(`[fetch-comments] Fetched ${threads.length} threads`);
|
|
3802
|
+
const diffFiles = await deps.loadDiffFiles(
|
|
3803
|
+
materialized.repoPath,
|
|
3804
|
+
materialized.baseSha,
|
|
3805
|
+
materialized.headSha
|
|
3806
|
+
);
|
|
3807
|
+
const comments = mapThreadsToReviewComments(threads, diffFiles);
|
|
3808
|
+
const state = buildRemoteReviewState({
|
|
3809
|
+
remoteUrl: url,
|
|
3810
|
+
forge: forgeUrl.forge,
|
|
3811
|
+
baseSha: materialized.baseSha,
|
|
3812
|
+
headSha: materialized.headSha,
|
|
3813
|
+
diffFiles,
|
|
3814
|
+
comments,
|
|
3815
|
+
timestamp: deps.now().toISOString()
|
|
3816
|
+
});
|
|
3817
|
+
const config = deps.loadConfig();
|
|
3818
|
+
const outputPath = (0, import_path10.resolve)(cwd, config.outputFile);
|
|
3819
|
+
const xml = await deps.serialize(state, outputPath);
|
|
3820
|
+
deps.writeFile(outputPath, xml + "\n");
|
|
3821
|
+
console.error(`[fetch-comments] ${comments.length} threads written to ${outputPath}`);
|
|
3822
|
+
} finally {
|
|
3823
|
+
materialized.cleanup();
|
|
3824
|
+
}
|
|
3825
|
+
}
|
|
2714
3826
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2715
3827
|
0 && (module.exports = {
|
|
2716
3828
|
ForgeCliUnavailableError,
|
|
2717
3829
|
GUIDE_XSD_SCHEMA,
|
|
2718
3830
|
IMPLICIT_GUIDE_GROUP_NAME,
|
|
2719
3831
|
REVIEW_LEVEL_FILE_PATH,
|
|
3832
|
+
applyRemoteProvenance,
|
|
3833
|
+
applyStagedUntrackedDefault,
|
|
3834
|
+
applySuggestion,
|
|
3835
|
+
applySuggestionForSession,
|
|
3836
|
+
bootstrapRemoteDiff,
|
|
3837
|
+
buildRemoteReviewState,
|
|
2720
3838
|
checkWritability,
|
|
3839
|
+
commitReviewStart,
|
|
2721
3840
|
computePayloadStats,
|
|
3841
|
+
computeRemoteDrift,
|
|
2722
3842
|
countTotalLines,
|
|
2723
3843
|
createGitHubProvider,
|
|
2724
3844
|
createGitLabProvider,
|
|
2725
3845
|
createIgnoreFilter,
|
|
3846
|
+
createReviewSession,
|
|
2726
3847
|
defaultGitRunner,
|
|
3848
|
+
deriveGuidePath,
|
|
2727
3849
|
detectExistingClone,
|
|
3850
|
+
determineMode,
|
|
3851
|
+
expandContext,
|
|
2728
3852
|
generateSyntheticDiffs,
|
|
2729
3853
|
generateUntrackedDiffs,
|
|
3854
|
+
getConfigLoad,
|
|
3855
|
+
getDiffLoad,
|
|
3856
|
+
getFileHunks,
|
|
2730
3857
|
getGitDiffStats,
|
|
2731
3858
|
getLanguageFromPath,
|
|
2732
3859
|
getRenderedTextMode,
|
|
2733
3860
|
getRepoRoot,
|
|
2734
3861
|
getRepoRootAsync,
|
|
3862
|
+
getResumeLoad,
|
|
2735
3863
|
getUntrackedFilesAsync,
|
|
2736
3864
|
isHtmlFile,
|
|
2737
3865
|
isMarkdownFile,
|
|
@@ -2739,20 +3867,35 @@ async function resolveRemoteDefaultBranch(url, runner = defaultGitRunner, existi
|
|
|
2739
3867
|
isPreviewableRenderedText,
|
|
2740
3868
|
isPreviewableSvg,
|
|
2741
3869
|
loadConfig,
|
|
3870
|
+
loadGitDiffWithUntracked,
|
|
3871
|
+
loadGuide,
|
|
3872
|
+
loadImage,
|
|
2742
3873
|
mapThreadsToReviewComments,
|
|
2743
3874
|
materialize,
|
|
3875
|
+
mergeRemoteThreads,
|
|
3876
|
+
normalizeGitDiffArgs,
|
|
2744
3877
|
parseDiff,
|
|
2745
3878
|
parseForgeUrl,
|
|
2746
3879
|
parseGuideXml,
|
|
2747
3880
|
parseReviewXml,
|
|
2748
3881
|
parseReviewXmlString,
|
|
3882
|
+
prepareDirectoryReview,
|
|
3883
|
+
preparePayload,
|
|
3884
|
+
readAttachment,
|
|
2749
3885
|
reconcileGuide,
|
|
3886
|
+
resolveApplyDestination,
|
|
3887
|
+
resolveGuidePath,
|
|
2750
3888
|
resolveRemoteDefaultBranch,
|
|
3889
|
+
resolveSourceBaseDir,
|
|
3890
|
+
runFetchComments,
|
|
2751
3891
|
runGitDiff,
|
|
2752
3892
|
runGitDiffAsync,
|
|
2753
3893
|
scanDirectory,
|
|
2754
3894
|
scanFile,
|
|
2755
3895
|
serializeReview,
|
|
3896
|
+
startRemoteSession,
|
|
3897
|
+
submitReviewState,
|
|
3898
|
+
takeReviewState,
|
|
2756
3899
|
validateGitAvailable
|
|
2757
3900
|
});
|
|
2758
3901
|
//# sourceMappingURL=index.cjs.map
|