@self-review/core 1.43.4 → 1.45.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/index.js CHANGED
@@ -1,162 +1,17 @@
1
- // src/diff-parser.ts
2
- function parseDiff(rawDiff) {
3
- if (!rawDiff.trim()) {
4
- return [];
5
- }
6
- const lines = rawDiff.split("\n");
7
- const files = [];
8
- let currentFile = null;
9
- let currentHunk = null;
10
- let oldLineNumber = 0;
11
- let newLineNumber = 0;
12
- for (let i = 0; i < lines.length; i++) {
13
- const line = lines[i];
14
- if (line.startsWith("diff --git ")) {
15
- if (currentHunk && currentHunk.header && currentFile) {
16
- currentFile.hunks.push(currentHunk);
17
- currentHunk = null;
18
- }
19
- if (currentFile && currentFile.oldPath !== void 0 && currentFile.newPath !== void 0) {
20
- if (currentFile.isBinary || currentFile.hunks && currentFile.hunks.length > 0 || currentFile.changeType === "added") {
21
- files.push(currentFile);
22
- }
23
- }
24
- const gitPaths = parseGitDiffHeader(line);
25
- currentFile = {
26
- oldPath: gitPaths.oldPath,
27
- newPath: gitPaths.newPath,
28
- changeType: "modified",
29
- isBinary: false,
30
- hunks: []
31
- };
32
- currentHunk = null;
33
- continue;
34
- }
35
- if (!currentFile) continue;
36
- if (line.startsWith("new file mode")) {
37
- currentFile.changeType = "added";
38
- continue;
39
- }
40
- if (line.startsWith("deleted file mode")) {
41
- currentFile.changeType = "deleted";
42
- continue;
43
- }
44
- if (line.startsWith("rename from ")) {
45
- currentFile.changeType = "renamed";
46
- continue;
47
- }
48
- if (line.startsWith("--- ")) {
49
- const path3 = line.substring(4);
50
- currentFile.oldPath = path3 === "/dev/null" ? "" : stripPrefix(path3);
51
- continue;
52
- }
53
- if (line.startsWith("+++ ")) {
54
- const path3 = line.substring(4);
55
- currentFile.newPath = path3 === "/dev/null" ? "" : stripPrefix(path3);
56
- continue;
57
- }
58
- if (line.startsWith("Binary files ")) {
59
- currentFile.isBinary = true;
60
- continue;
61
- }
62
- if (line.startsWith("@@")) {
63
- if (currentHunk && currentHunk.header) {
64
- currentFile.hunks.push(currentHunk);
65
- }
66
- const match = line.match(
67
- /@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/
68
- );
69
- if (match) {
70
- const oldStart = parseInt(match[1], 10);
71
- const oldLines = match[2] ? parseInt(match[2], 10) : 1;
72
- const newStart = parseInt(match[3], 10);
73
- const newLines = match[4] ? parseInt(match[4], 10) : 1;
74
- const _context = match[5];
75
- currentHunk = {
76
- header: line,
77
- oldStart,
78
- oldLines,
79
- newStart,
80
- newLines,
81
- lines: []
82
- };
83
- oldLineNumber = oldStart;
84
- newLineNumber = newStart;
85
- }
86
- continue;
87
- }
88
- if (currentHunk && currentHunk.lines) {
89
- if (line.startsWith("+")) {
90
- currentHunk.lines.push({
91
- type: "addition",
92
- oldLineNumber: null,
93
- newLineNumber,
94
- content: line.substring(1)
95
- });
96
- newLineNumber++;
97
- } else if (line.startsWith("-")) {
98
- currentHunk.lines.push({
99
- type: "deletion",
100
- oldLineNumber,
101
- newLineNumber: null,
102
- content: line.substring(1)
103
- });
104
- oldLineNumber++;
105
- } else if (line.startsWith(" ")) {
106
- currentHunk.lines.push({
107
- type: "context",
108
- oldLineNumber,
109
- newLineNumber,
110
- content: line.substring(1)
111
- });
112
- oldLineNumber++;
113
- newLineNumber++;
114
- } else if (line.startsWith("\\")) {
115
- continue;
116
- } else {
117
- if (currentHunk.lines.length > 0) {
118
- currentHunk.lines.push({
119
- type: "context",
120
- oldLineNumber,
121
- newLineNumber,
122
- content: line
123
- });
124
- oldLineNumber++;
125
- newLineNumber++;
126
- }
127
- }
128
- }
129
- }
130
- if (currentHunk && currentHunk.header && currentFile) {
131
- currentFile.hunks.push(currentHunk);
132
- }
133
- if (currentFile && currentFile.oldPath !== void 0 && currentFile.newPath !== void 0) {
134
- if (currentFile.isBinary || currentFile.hunks && currentFile.hunks.length > 0 || currentFile.changeType === "added") {
135
- files.push(currentFile);
136
- }
137
- }
138
- return files;
139
- }
140
- function stripPrefix(path3) {
141
- if (path3.length > 2 && path3[1] === "/") {
142
- return path3.substring(2);
143
- }
144
- return path3;
145
- }
146
- function parseGitDiffHeader(line) {
147
- const withoutPrefix = line.substring("diff --git ".length);
148
- let bIdx = -1;
149
- for (const prefix of [" b/", " w/", " i/", " c/", " o/"]) {
150
- bIdx = withoutPrefix.indexOf(prefix);
151
- if (bIdx !== -1) break;
152
- }
153
- if (bIdx === -1) {
154
- return { oldPath: "", newPath: "" };
155
- }
156
- const oldPath = stripPrefix(withoutPrefix.substring(0, bIdx));
157
- const newPath = stripPrefix(withoutPrefix.substring(bIdx + 1));
158
- return { oldPath, newPath };
159
- }
1
+ import {
2
+ parseDiff
3
+ } from "./chunk-OQRS7NDT.js";
4
+ import {
5
+ generateSyntheticDiffs,
6
+ generateUntrackedDiffs,
7
+ getRepoRoot,
8
+ getRepoRootAsync,
9
+ getUntrackedFilesAsync,
10
+ runGitDiff,
11
+ runGitDiffAsync,
12
+ stripTrailingNewline,
13
+ validateGitAvailable
14
+ } from "./chunk-A7A5ZFT3.js";
160
15
 
161
16
  // src/xml-serializer.ts
162
17
  import * as path from "path";
@@ -791,18 +646,25 @@ function extFromMediaType(mediaType) {
791
646
  };
792
647
  return map[mediaType] || "png";
793
648
  }
649
+ function assetNameComponent(idPrefix) {
650
+ return String(idPrefix ?? "").replace(/[^A-Za-z0-9_-]/g, "_");
651
+ }
794
652
  function persistAttachments(attachments, idPrefix, assetDir, onWrite) {
795
653
  if (!attachments?.length) return attachments;
796
654
  return attachments.map((att, index) => {
797
655
  if (!att.data) return att;
798
656
  onWrite();
799
657
  const ext = extFromMediaType(att.mediaType);
800
- const fileName = `${idPrefix}-${index}.${ext}`;
658
+ const fileName = `${assetNameComponent(idPrefix)}-${index}.${ext}`;
801
659
  const relativePath = `.self-review-assets/${fileName}`;
660
+ const target = path.join(assetDir, fileName);
661
+ if (path.dirname(path.resolve(target)) !== path.resolve(assetDir)) {
662
+ throw new Error(`Refusing to write an attachment outside ${assetDir}: ${fileName}`);
663
+ }
802
664
  if (!fs.existsSync(assetDir)) {
803
665
  fs.mkdirSync(assetDir, { recursive: true });
804
666
  }
805
- fs.writeFileSync(path.join(assetDir, fileName), Buffer.from(att.data));
667
+ fs.writeFileSync(target, Buffer.from(att.data));
806
668
  return { ...att, fileName: relativePath, data: void 0 };
807
669
  });
808
670
  }
@@ -857,9 +719,13 @@ async function serializeReview(state, outputFilePath) {
857
719
  throw error;
858
720
  }
859
721
  if (error instanceof Error) {
860
- console.error(`[main] XML validation infrastructure failed: ${error.message} - emitting XML without validation`);
722
+ console.error(
723
+ `[main] XML validation infrastructure failed: ${error.message} - emitting XML without validation`
724
+ );
861
725
  } else {
862
- console.error("[main] XML validation infrastructure failed - emitting XML without validation");
726
+ console.error(
727
+ "[main] XML validation infrastructure failed - emitting XML without validation"
728
+ );
863
729
  }
864
730
  return xml;
865
731
  }
@@ -1373,9 +1239,7 @@ async function parseGuideXml(xmlContent) {
1373
1239
  try {
1374
1240
  const validationResult = await validateXML2({
1375
1241
  xml: [{ fileName: "guide.xml", contents: xmlContent }],
1376
- schema: [
1377
- { fileName: "self-review-guide-v1.xsd", contents: GUIDE_XSD_SCHEMA }
1378
- ]
1242
+ schema: [{ fileName: "self-review-guide-v1.xsd", contents: GUIDE_XSD_SCHEMA }]
1379
1243
  });
1380
1244
  if (!validationResult.valid) {
1381
1245
  const details = (validationResult.errors || []).map((err) => typeof err === "string" ? err : err.message).join("; ");
@@ -1450,191 +1314,17 @@ function reconcileGuide(guide, diffFilePaths) {
1450
1314
  });
1451
1315
  }
1452
1316
  }
1453
- const leftover = diffFilePaths.filter((path3) => !claimed.has(path3));
1317
+ const leftover = diffFilePaths.filter((path4) => !claimed.has(path4));
1454
1318
  if (leftover.length > 0) {
1455
1319
  resolved.push({
1456
1320
  name: IMPLICIT_GUIDE_GROUP_NAME,
1457
1321
  implicit: true,
1458
- files: leftover.map((path3) => ({ path: path3 }))
1322
+ files: leftover.map((path4) => ({ path: path4 }))
1459
1323
  });
1460
1324
  }
1461
1325
  return resolved;
1462
1326
  }
1463
1327
 
1464
- // src/git.ts
1465
- import { execSync, exec, execFile, execFileSync } from "child_process";
1466
- import { promisify } from "util";
1467
-
1468
- // src/synthetic-diff.ts
1469
- import { readFileSync as readFileSync2 } from "fs";
1470
- function generateSyntheticDiffs(paths, rootDir) {
1471
- const diffs = [];
1472
- for (const filePath of paths) {
1473
- const fullPath = `${rootDir}/${filePath}`;
1474
- let content;
1475
- try {
1476
- content = readFileSync2(fullPath);
1477
- } catch {
1478
- continue;
1479
- }
1480
- const sample = content.subarray(0, 8192);
1481
- const isBinary = sample.includes(0);
1482
- if (isBinary) {
1483
- diffs.push(
1484
- `diff --git a/${filePath} b/${filePath}
1485
- new file mode 100644
1486
- Binary files /dev/null and b/${filePath} differ`
1487
- );
1488
- continue;
1489
- }
1490
- const text = content.toString("utf-8");
1491
- const lines = text.split("\n");
1492
- if (lines.length > 0 && lines[lines.length - 1] === "") {
1493
- lines.pop();
1494
- }
1495
- const lineCount = lines.length;
1496
- const addedLines = lines.map((line) => `+${line}`).join("\n");
1497
- let diff = `diff --git a/${filePath} b/${filePath}
1498
- new file mode 100644
1499
- --- /dev/null
1500
- +++ b/${filePath}
1501
- @@ -0,0 +1,${lineCount} @@
1502
- ` + addedLines;
1503
- if (text.length > 0 && !text.endsWith("\n")) {
1504
- diff += "\n\";
1505
- }
1506
- diffs.push(diff);
1507
- }
1508
- return diffs.join("\n");
1509
- }
1510
-
1511
- // src/git.ts
1512
- var execAsync = promisify(exec);
1513
- var execFileAsync = promisify(execFile);
1514
- function runGitDiff(args) {
1515
- try {
1516
- try {
1517
- execSync("git --version", { stdio: "ignore" });
1518
- } catch {
1519
- console.error("Error: git is not installed or not in PATH");
1520
- process.exit(1);
1521
- }
1522
- try {
1523
- execSync("git rev-parse --git-dir", { stdio: "ignore" });
1524
- } catch {
1525
- console.error(
1526
- "Error: not a git repository (or any parent up to mount point)"
1527
- );
1528
- process.exit(1);
1529
- }
1530
- const result = execFileSync("git", ["diff", ...args], {
1531
- encoding: "utf-8",
1532
- maxBuffer: 50 * 1024 * 1024
1533
- // 50MB buffer for large diffs
1534
- });
1535
- return result;
1536
- } catch (error) {
1537
- if (error instanceof Error) {
1538
- console.error(`Error running git diff: ${error.message}`);
1539
- } else {
1540
- console.error("Error running git diff: unknown error");
1541
- }
1542
- process.exit(1);
1543
- }
1544
- }
1545
- function getRepoRoot() {
1546
- try {
1547
- const result = execSync("git rev-parse --show-toplevel", {
1548
- encoding: "utf-8"
1549
- });
1550
- return result.trim();
1551
- } catch (error) {
1552
- if (error instanceof Error) {
1553
- console.error(`Error getting repository root: ${error.message}`);
1554
- } else {
1555
- console.error("Error getting repository root: unknown error");
1556
- }
1557
- process.exit(1);
1558
- }
1559
- }
1560
- function validateGitAvailable() {
1561
- try {
1562
- execSync("git --version", { stdio: "ignore" });
1563
- } catch {
1564
- console.error("Error: git is not installed or not in PATH");
1565
- process.exit(1);
1566
- }
1567
- try {
1568
- execSync("git rev-parse --git-dir", { stdio: "ignore" });
1569
- } catch {
1570
- console.error(
1571
- "Error: not a git repository (or any parent up to mount point)"
1572
- );
1573
- process.exit(1);
1574
- }
1575
- }
1576
- async function getRepoRootAsync(cwd) {
1577
- try {
1578
- const { stdout } = await execAsync("git rev-parse --show-toplevel", {
1579
- timeout: 1e4,
1580
- // 10 second timeout
1581
- cwd
1582
- });
1583
- return stdout.trim();
1584
- } catch (error) {
1585
- if (error instanceof Error) {
1586
- console.error(`Error getting repository root: ${error.message}`);
1587
- } else {
1588
- console.error("Error getting repository root: unknown error");
1589
- }
1590
- throw error;
1591
- }
1592
- }
1593
- async function runGitDiffAsync(args, cwd) {
1594
- try {
1595
- const { stdout } = await execFileAsync("git", ["diff", ...args], {
1596
- maxBuffer: 50 * 1024 * 1024,
1597
- // 50MB buffer
1598
- timeout: 3e4,
1599
- // 30 second timeout
1600
- cwd
1601
- });
1602
- return stdout;
1603
- } catch (error) {
1604
- if (error instanceof Error) {
1605
- console.error(`Error running git diff: ${error.message}`);
1606
- } else {
1607
- console.error("Error running git diff: unknown error");
1608
- }
1609
- throw error;
1610
- }
1611
- }
1612
- async function getUntrackedFilesAsync(cwd) {
1613
- try {
1614
- const { stdout } = await execAsync(
1615
- "git ls-files --others --exclude-standard",
1616
- {
1617
- maxBuffer: 10 * 1024 * 1024,
1618
- timeout: 1e4,
1619
- cwd
1620
- }
1621
- );
1622
- return stdout.trim().split("\n").filter((line) => line.length > 0);
1623
- } catch (error) {
1624
- if (error instanceof Error) {
1625
- console.error(
1626
- `Warning: Failed to list untracked files: ${error.message}`
1627
- );
1628
- } else {
1629
- console.error("Warning: Failed to list untracked files: unknown error");
1630
- }
1631
- return [];
1632
- }
1633
- }
1634
- function generateUntrackedDiffs(paths, repoRoot) {
1635
- return generateSyntheticDiffs(paths, repoRoot);
1636
- }
1637
-
1638
1328
  // src/forge-provider.ts
1639
1329
  var ForgeCliUnavailableError = class extends Error {
1640
1330
  constructor(forge, cli, message) {
@@ -1696,20 +1386,14 @@ async function scanDirectory(directoryPath, ignorePatterns = []) {
1696
1386
  try {
1697
1387
  const dirStat = await stat(directoryPath);
1698
1388
  if (!dirStat.isDirectory()) {
1699
- console.error(
1700
- `Error: "${directoryPath}" is not a directory`
1701
- );
1389
+ console.error(`Error: "${directoryPath}" is not a directory`);
1702
1390
  return [];
1703
1391
  }
1704
1392
  } catch (error) {
1705
1393
  if (error instanceof Error) {
1706
- console.error(
1707
- `Error accessing directory "${directoryPath}": ${error.message}`
1708
- );
1394
+ console.error(`Error accessing directory "${directoryPath}": ${error.message}`);
1709
1395
  } else {
1710
- console.error(
1711
- `Error accessing directory "${directoryPath}": unknown error`
1712
- );
1396
+ console.error(`Error accessing directory "${directoryPath}": unknown error`);
1713
1397
  }
1714
1398
  return [];
1715
1399
  }
@@ -1730,13 +1414,9 @@ async function scanDirectory(directoryPath, ignorePatterns = []) {
1730
1414
  }
1731
1415
  } catch (error) {
1732
1416
  if (error instanceof Error) {
1733
- console.error(
1734
- `Error reading directory "${directoryPath}": ${error.message}`
1735
- );
1417
+ console.error(`Error reading directory "${directoryPath}": ${error.message}`);
1736
1418
  } else {
1737
- console.error(
1738
- `Error reading directory "${directoryPath}": unknown error`
1739
- );
1419
+ console.error(`Error reading directory "${directoryPath}": unknown error`);
1740
1420
  }
1741
1421
  return [];
1742
1422
  }
@@ -1771,7 +1451,7 @@ async function scanFile(filePath) {
1771
1451
  }
1772
1452
 
1773
1453
  // src/config.ts
1774
- import { readFileSync as readFileSync3, existsSync as existsSync2 } from "fs";
1454
+ import { readFileSync as readFileSync2, existsSync as existsSync2 } from "fs";
1775
1455
  import { join as join3 } from "path";
1776
1456
  import { homedir } from "os";
1777
1457
  import { parse as parseYaml } from "yaml";
@@ -1848,20 +1528,13 @@ var defaults = {
1848
1528
  };
1849
1529
  function loadConfig() {
1850
1530
  let config = { ...defaults };
1851
- const userConfigPath = join3(
1852
- homedir(),
1853
- ".config",
1854
- "self-review",
1855
- "config.yaml"
1856
- );
1531
+ const userConfigPath = join3(homedir(), ".config", "self-review", "config.yaml");
1857
1532
  if (existsSync2(userConfigPath)) {
1858
1533
  try {
1859
1534
  const userConfig = loadYamlConfig(userConfigPath);
1860
1535
  config = mergeConfig(config, userConfig);
1861
1536
  } catch (error) {
1862
- console.error(
1863
- `Warning: Failed to load user config from ${userConfigPath}: ${error}`
1864
- );
1537
+ console.error(`Warning: Failed to load user config from ${userConfigPath}: ${error}`);
1865
1538
  }
1866
1539
  }
1867
1540
  const projectConfigPath = join3(process.cwd(), ".self-review.yaml");
@@ -1870,15 +1543,13 @@ function loadConfig() {
1870
1543
  const projectConfig = loadYamlConfig(projectConfigPath);
1871
1544
  config = mergeConfig(config, projectConfig);
1872
1545
  } catch (error) {
1873
- console.error(
1874
- `Warning: Failed to load project config from ${projectConfigPath}: ${error}`
1875
- );
1546
+ console.error(`Warning: Failed to load project config from ${projectConfigPath}: ${error}`);
1876
1547
  }
1877
1548
  }
1878
1549
  return config;
1879
1550
  }
1880
- function loadYamlConfig(path3) {
1881
- const content = readFileSync3(path3, "utf-8");
1551
+ function loadYamlConfig(path4) {
1552
+ const content = readFileSync2(path4, "utf-8");
1882
1553
  const raw = parseYaml(content);
1883
1554
  if (raw === null || raw === void 0) {
1884
1555
  return {};
@@ -1891,18 +1562,14 @@ function loadYamlConfig(path3) {
1891
1562
  if (["light", "dark", "system"].includes(raw.theme)) {
1892
1563
  config.theme = raw.theme;
1893
1564
  } else {
1894
- console.error(
1895
- `Warning: Invalid theme value "${raw.theme}", using default`
1896
- );
1565
+ console.error(`Warning: Invalid theme value "${raw.theme}", using default`);
1897
1566
  }
1898
1567
  }
1899
1568
  if ("diff-view" in raw) {
1900
1569
  if (["split", "unified"].includes(raw["diff-view"])) {
1901
1570
  config.diffView = raw["diff-view"];
1902
1571
  } else {
1903
- console.error(
1904
- `Warning: Invalid diff-view value "${raw["diff-view"]}", using default`
1905
- );
1572
+ console.error(`Warning: Invalid diff-view value "${raw["diff-view"]}", using default`);
1906
1573
  }
1907
1574
  }
1908
1575
  if ("font-size" in raw && typeof raw["font-size"] === "number") {
@@ -1912,14 +1579,19 @@ function loadYamlConfig(path3) {
1912
1579
  config.outputFormat = raw["output-format"];
1913
1580
  }
1914
1581
  if ("ignore" in raw && Array.isArray(raw.ignore)) {
1915
- config.ignore = raw.ignore.filter(
1916
- (item) => typeof item === "string"
1917
- );
1582
+ config.ignore = raw.ignore.filter((item) => typeof item === "string");
1918
1583
  }
1919
1584
  if ("categories" in raw && Array.isArray(raw.categories)) {
1920
- config.categories = raw.categories.filter(
1921
- (cat) => cat !== null && typeof cat === "object" && typeof cat.name === "string" && typeof cat.description === "string" && typeof cat.color === "string"
1585
+ const usableCategories = raw.categories.filter(
1586
+ (cat) => cat !== null && typeof cat === "object" && typeof cat.name === "string" && cat.name !== "" && typeof cat.description === "string" && typeof cat.color === "string"
1922
1587
  );
1588
+ if (usableCategories.length > 0) {
1589
+ config.categories = usableCategories;
1590
+ } else {
1591
+ console.error(
1592
+ "Warning: Category configuration has no usable categories, using default categories"
1593
+ );
1594
+ }
1923
1595
  }
1924
1596
  if ("default-diff-args" in raw && typeof raw["default-diff-args"] === "string") {
1925
1597
  config.defaultDiffArgs = raw["default-diff-args"];
@@ -1956,9 +1628,9 @@ function mergeConfig(base, override) {
1956
1628
  }
1957
1629
 
1958
1630
  // src/payload-sizing.ts
1959
- import { exec as exec2 } from "child_process";
1960
- import { promisify as promisify2 } from "util";
1961
- var execAsync2 = promisify2(exec2);
1631
+ import { execFile } from "child_process";
1632
+ import { promisify } from "util";
1633
+ var execFileAsync = promisify(execFile);
1962
1634
  function computePayloadStats(fileCount, totalLines, config) {
1963
1635
  const maxFiles = config.maxFiles;
1964
1636
  const maxTotalLines = config.maxTotalLines;
@@ -1983,7 +1655,7 @@ function countTotalLines(files) {
1983
1655
  }
1984
1656
  async function getGitDiffStats(args, repoRoot) {
1985
1657
  try {
1986
- const { stdout } = await execAsync2(`git diff --numstat ${args.join(" ")}`, {
1658
+ const { stdout } = await execFileAsync("git", ["diff", "--numstat", ...args], {
1987
1659
  maxBuffer: 10 * 1024 * 1024,
1988
1660
  timeout: 15e3,
1989
1661
  cwd: repoRoot
@@ -2023,6 +1695,108 @@ function checkWritability(filePath) {
2023
1695
  }
2024
1696
  }
2025
1697
 
1698
+ // src/apply-suggestion.ts
1699
+ import { readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
1700
+ import { isAbsolute, relative as relative2, resolve as resolve2, sep } from "path";
1701
+ function refuse(filePath, reason, detail) {
1702
+ return { status: "refused", filePath, reason, detail };
1703
+ }
1704
+ function errorCode(error) {
1705
+ return error?.code;
1706
+ }
1707
+ function splitLines(content) {
1708
+ if (content === "") return [];
1709
+ const lines = content.split("\n");
1710
+ if (lines[lines.length - 1] === "") lines.pop();
1711
+ return lines;
1712
+ }
1713
+ function isCrlfRegion(anchored) {
1714
+ return anchored.length > 0 && anchored.every((line) => line.endsWith("\r"));
1715
+ }
1716
+ function applySuggestion(request) {
1717
+ const { destinationRoot, filePath, lineRange, suggestion } = request;
1718
+ if (!lineRange) {
1719
+ return refuse(
1720
+ filePath,
1721
+ "no-anchor",
1722
+ "This suggestion is file-level, so there are no lines to replace."
1723
+ );
1724
+ }
1725
+ if (lineRange.side === "old") {
1726
+ return refuse(
1727
+ filePath,
1728
+ "old-side-anchor",
1729
+ "This suggestion is anchored to deleted lines, which are not in the working file."
1730
+ );
1731
+ }
1732
+ if (!isAbsolute(destinationRoot)) {
1733
+ return refuse(
1734
+ filePath,
1735
+ "destination-not-absolute",
1736
+ "The destination directory must be an absolute path."
1737
+ );
1738
+ }
1739
+ const root = resolve2(destinationRoot);
1740
+ const absolutePath = resolve2(root, filePath);
1741
+ const rel = relative2(root, absolutePath);
1742
+ if (isAbsolute(filePath) || rel === "" || rel === ".." || rel.startsWith(`..${sep}`)) {
1743
+ return refuse(
1744
+ filePath,
1745
+ "path-escapes-destination",
1746
+ "The file path resolves outside the destination directory."
1747
+ );
1748
+ }
1749
+ let buffer;
1750
+ try {
1751
+ buffer = readFileSync3(absolutePath);
1752
+ } catch (error) {
1753
+ const code = errorCode(error);
1754
+ if (code === "ENOENT" || code === "ENOTDIR") {
1755
+ return refuse(filePath, "file-missing", "The file is not in the destination directory.");
1756
+ }
1757
+ return refuse(
1758
+ filePath,
1759
+ "file-unreadable",
1760
+ `The file could not be read (${code ?? "unknown"}).`
1761
+ );
1762
+ }
1763
+ const content = buffer.toString("utf8");
1764
+ if (!Buffer.from(content, "utf8").equals(buffer)) {
1765
+ return refuse(filePath, "file-not-utf8", "The file is not valid UTF-8 text.");
1766
+ }
1767
+ const lines = splitLines(content);
1768
+ const { start, end } = lineRange;
1769
+ if (start < 1 || end < start || end > lines.length) {
1770
+ return refuse(
1771
+ filePath,
1772
+ "anchor-out-of-range",
1773
+ `Lines ${start}-${end} are outside this file, which has ${lines.length} line(s).`
1774
+ );
1775
+ }
1776
+ const anchored = lines.slice(start - 1, end);
1777
+ if (anchored.join("\n") !== suggestion.originalCode) {
1778
+ return refuse(
1779
+ filePath,
1780
+ "context-mismatch",
1781
+ `Lines ${start}-${end} no longer match the code this suggestion was written against.`
1782
+ );
1783
+ }
1784
+ const proposed = suggestion.proposedCode.split("\n");
1785
+ const replacement = isCrlfRegion(anchored) ? proposed.map((line) => line.endsWith("\r") ? line : `${line}\r`) : proposed;
1786
+ const updated = [...lines.slice(0, start - 1), ...replacement, ...lines.slice(end)];
1787
+ const output = updated.join("\n") + (content.endsWith("\n") ? "\n" : "");
1788
+ try {
1789
+ writeFileSync2(absolutePath, output, "utf8");
1790
+ } catch (error) {
1791
+ return refuse(
1792
+ filePath,
1793
+ "write-failed",
1794
+ `The file could not be written (${errorCode(error) ?? "unknown"}).`
1795
+ );
1796
+ }
1797
+ return { status: "applied", filePath, absolutePath, replacedLines: anchored.length };
1798
+ }
1799
+
2026
1800
  // src/file-type-utils.ts
2027
1801
  var RASTER_IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([".jpg", ".jpeg", ".png", ".gif", ".webp", ".ico", ".bmp"]);
2028
1802
  var MARKDOWN_EXTENSIONS = /* @__PURE__ */ new Set([".md", ".markdown"]);
@@ -2127,11 +1901,7 @@ async function runGh(runCommand, args) {
2127
1901
  result = await runCommand(GH_CLI, args);
2128
1902
  } catch (error) {
2129
1903
  const detail = error instanceof Error ? error.message : String(error);
2130
- throw new ForgeCliUnavailableError(
2131
- "github",
2132
- GH_CLI,
2133
- `Failed to run the gh CLI: ${detail}`
2134
- );
1904
+ throw new ForgeCliUnavailableError("github", GH_CLI, `Failed to run the gh CLI: ${detail}`);
2135
1905
  }
2136
1906
  if (result.exitCode !== 0) {
2137
1907
  const detail = result.stderr.trim() || `exit code ${result.exitCode}`;
@@ -2210,11 +1980,7 @@ function createGitHubProvider(runCommand) {
2210
1980
  ]);
2211
1981
  const parsed = parseGhJson(stdout, "pr view");
2212
1982
  if (typeof parsed?.baseRefName !== "string" || parsed.baseRefName === "") {
2213
- throw new ForgeCliUnavailableError(
2214
- "github",
2215
- GH_CLI,
2216
- "gh pr view returned no baseRefName"
2217
- );
1983
+ throw new ForgeCliUnavailableError("github", GH_CLI, "gh pr view returned no baseRefName");
2218
1984
  }
2219
1985
  return parsed.baseRefName;
2220
1986
  },
@@ -2267,6 +2033,69 @@ function mapAnchorToLineRange(anchor) {
2267
2033
  function internalId(turn) {
2268
2034
  return `remote-${turn.remoteId}`;
2269
2035
  }
2036
+ var FENCE_OPEN = /^( {0,3})(`{3,}|~{3,})(.*)$/;
2037
+ function stripCr(line) {
2038
+ return line.endsWith("\r") ? line.slice(0, -1) : line;
2039
+ }
2040
+ function stripIndent(line, width) {
2041
+ let i = 0;
2042
+ while (i < width && line[i] === " ") i++;
2043
+ return line.slice(i);
2044
+ }
2045
+ function isClosingFence(line, marker) {
2046
+ const match = FENCE_OPEN.exec(line);
2047
+ return match !== null && match[2][0] === marker[0] && match[2].length >= marker.length && match[3].trim() === "";
2048
+ }
2049
+ function findSuggestionBlocks(body) {
2050
+ const lines = body.split("\n").map(stripCr);
2051
+ const blocks = [];
2052
+ let i = 0;
2053
+ while (i < lines.length) {
2054
+ const open = FENCE_OPEN.exec(lines[i]);
2055
+ if (!open) {
2056
+ i++;
2057
+ continue;
2058
+ }
2059
+ const [, indent, marker, info] = open;
2060
+ if (marker[0] === "`" && info.includes("`")) {
2061
+ i++;
2062
+ continue;
2063
+ }
2064
+ const content = [];
2065
+ let j = i + 1;
2066
+ for (; j < lines.length && !isClosingFence(lines[j], marker); j++) {
2067
+ content.push(stripIndent(lines[j], indent.length));
2068
+ }
2069
+ if (info.trim().toLowerCase() === "suggestion") {
2070
+ blocks.push(content.join("\n"));
2071
+ }
2072
+ i = j + 1;
2073
+ }
2074
+ return blocks;
2075
+ }
2076
+ function readAnchoredLines(diffFiles, filePath, range) {
2077
+ const sidePath = (file2) => range.side === "old" ? file2.oldPath : file2.newPath;
2078
+ const file = diffFiles.find((f) => sidePath(f) === filePath) ?? diffFiles.find((f) => f.oldPath === filePath || f.newPath === filePath);
2079
+ if (!file) return null;
2080
+ const found = [];
2081
+ for (const hunk of file.hunks) {
2082
+ for (const line of hunk.lines) {
2083
+ const number = range.side === "old" ? line.oldLineNumber : line.newLineNumber;
2084
+ if (number !== null && number >= range.start && number <= range.end) {
2085
+ found.push(line.content);
2086
+ }
2087
+ }
2088
+ }
2089
+ return found.length === range.end - range.start + 1 ? found.join("\n") : null;
2090
+ }
2091
+ function extractSuggestion(body, filePath, range, diffFiles) {
2092
+ if (!range) return null;
2093
+ const blocks = findSuggestionBlocks(body);
2094
+ if (blocks.length !== 1) return null;
2095
+ const originalCode = readAnchoredLines(diffFiles, filePath, range);
2096
+ if (originalCode === null) return null;
2097
+ return { originalCode, proposedCode: blocks[0] };
2098
+ }
2270
2099
  function mapReply(turn) {
2271
2100
  return {
2272
2101
  id: internalId(turn),
@@ -2275,15 +2104,17 @@ function mapReply(turn) {
2275
2104
  remoteId: turn.remoteId
2276
2105
  };
2277
2106
  }
2278
- function mapThreadsToReviewComments(threads) {
2107
+ function mapThreadsToReviewComments(threads, diffFiles = []) {
2279
2108
  return threads.map((thread) => {
2109
+ const filePath = thread.anchor?.filePath ?? REVIEW_LEVEL_FILE_PATH;
2110
+ const lineRange = thread.anchor ? mapAnchorToLineRange(thread.anchor) : null;
2280
2111
  const comment = {
2281
2112
  id: internalId(thread.root),
2282
- filePath: thread.anchor?.filePath ?? REVIEW_LEVEL_FILE_PATH,
2283
- lineRange: thread.anchor ? mapAnchorToLineRange(thread.anchor) : null,
2113
+ filePath,
2114
+ lineRange,
2284
2115
  body: thread.root.body,
2285
2116
  category: "",
2286
- suggestion: null,
2117
+ suggestion: extractSuggestion(thread.root.body, filePath, lineRange, diffFiles),
2287
2118
  author: thread.root.author,
2288
2119
  remoteId: thread.root.remoteId
2289
2120
  };
@@ -2443,24 +2274,19 @@ import * as path2 from "path";
2443
2274
  var LOCAL_BASE_REF = "refs/self-review/base";
2444
2275
  var LOCAL_HEAD_REF = "refs/self-review/head";
2445
2276
  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.";
2446
- var defaultGitRunner = (command, args) => new Promise((resolve, reject) => {
2447
- execFile2(
2448
- command,
2449
- args,
2450
- { maxBuffer: 50 * 1024 * 1024 },
2451
- (error, stdout, stderr) => {
2452
- const spawnCode = error?.code;
2453
- if (error && typeof spawnCode === "string") {
2454
- reject(error);
2455
- return;
2456
- }
2457
- resolve({
2458
- stdout: stdout ?? "",
2459
- stderr: stderr ?? "",
2460
- exitCode: error ? typeof spawnCode === "number" ? spawnCode : 1 : 0
2461
- });
2277
+ var defaultGitRunner = (command, args) => new Promise((resolve7, reject) => {
2278
+ execFile2(command, args, { maxBuffer: 50 * 1024 * 1024 }, (error, stdout, stderr) => {
2279
+ const spawnCode = error?.code;
2280
+ if (error && typeof spawnCode === "string") {
2281
+ reject(error);
2282
+ return;
2462
2283
  }
2463
- );
2284
+ resolve7({
2285
+ stdout: stdout ?? "",
2286
+ stderr: stderr ?? "",
2287
+ exitCode: error ? typeof spawnCode === "number" ? spawnCode : 1 : 0
2288
+ });
2289
+ });
2464
2290
  });
2465
2291
  function headRefFor(url) {
2466
2292
  return url.forge === "github" ? `refs/pull/${url.number}/head` : `refs/merge-requests/${url.number}/head`;
@@ -2529,7 +2355,7 @@ async function detectExistingClone(url, cwd, runner = defaultGitRunner) {
2529
2355
  if (toplevel.exitCode !== 0) {
2530
2356
  return null;
2531
2357
  }
2532
- const repoPath = toplevel.stdout.trim();
2358
+ const repoPath = stripTrailingNewline(toplevel.stdout);
2533
2359
  const remotes = await runner("git", ["-C", repoPath, "remote", "-v"]);
2534
2360
  if (remotes.exitCode !== 0) {
2535
2361
  return null;
@@ -2538,9 +2364,7 @@ async function detectExistingClone(url, cwd, runner = defaultGitRunner) {
2538
2364
  return remoteName === null ? null : { repoPath, remoteName };
2539
2365
  }
2540
2366
  async function materializeIntoExistingClone(runner, url, baseBranch, repoPath, remoteName) {
2541
- console.error(
2542
- `self-review: reusing existing clone at ${repoPath} (remote "${remoteName}")`
2543
- );
2367
+ console.error(`self-review: reusing existing clone at ${repoPath} (remote "${remoteName}")`);
2544
2368
  const fetch = await runner("git", [
2545
2369
  "-C",
2546
2370
  repoPath,
@@ -2570,16 +2394,9 @@ async function materializeIntoTempClone(runner, url, baseBranch) {
2570
2394
  fs2.rmSync(tempDir, { recursive: true, force: true });
2571
2395
  };
2572
2396
  try {
2573
- console.error(
2574
- `self-review: created temporary blobless clone at ${tempDir}`
2575
- );
2397
+ console.error(`self-review: created temporary blobless clone at ${tempDir}`);
2576
2398
  const cloneUrl = cloneUrlFor(url);
2577
- const clone = await runner("git", [
2578
- "clone",
2579
- "--filter=blob:none",
2580
- cloneUrl,
2581
- tempDir
2582
- ]);
2399
+ const clone = await runner("git", ["clone", "--filter=blob:none", cloneUrl, tempDir]);
2583
2400
  if (clone.exitCode !== 0) {
2584
2401
  throw gitFailure(`clone of ${cloneUrl}`, clone, true);
2585
2402
  }
@@ -2635,26 +2452,863 @@ async function resolveRemoteDefaultBranch(url, runner = defaultGitRunner, existi
2635
2452
  }
2636
2453
  return match[1];
2637
2454
  }
2455
+
2456
+ // src/review-handlers.ts
2457
+ import * as fs3 from "fs";
2458
+ import path3 from "path";
2459
+
2460
+ // src/git-diff-args.ts
2461
+ import { existsSync as existsSync3 } from "fs";
2462
+ import { resolve as resolve3 } from "path";
2463
+ var OPTIONS_WITH_SEPARATE_VALUES = /* @__PURE__ */ new Set([
2464
+ "--output",
2465
+ "--src-prefix",
2466
+ "--dst-prefix",
2467
+ "--line-prefix",
2468
+ "--output-indicator-new",
2469
+ "--output-indicator-old",
2470
+ "--output-indicator-context",
2471
+ "--inter-hunk-context",
2472
+ "--stat-width",
2473
+ "--stat-name-width",
2474
+ "--stat-graph-width",
2475
+ "--stat-count",
2476
+ "--diff-algorithm",
2477
+ "--word-diff-regex",
2478
+ "--ignore-matching-lines",
2479
+ "--anchored",
2480
+ "--diff-filter",
2481
+ "--find-object",
2482
+ "--rotate-to",
2483
+ "--skip-to",
2484
+ "--ws-error-highlight",
2485
+ "--color-moved-ws"
2486
+ ]);
2487
+ function consumesNextArgument(arg) {
2488
+ if (arg.startsWith("--")) return OPTIONS_WITH_SEPARATE_VALUES.has(arg);
2489
+ if (!arg.startsWith("-")) return false;
2490
+ for (let i = 1; i < arg.length; i++) {
2491
+ if ("SGOIl".includes(arg[i])) return i === arg.length - 1;
2492
+ if ("UBMC".includes(arg[i])) return false;
2493
+ }
2494
+ return false;
2495
+ }
2496
+ function classifyGitDiffArgs(args) {
2497
+ const positionalIndices = [];
2498
+ let hasSeparator = false;
2499
+ for (let i = 0; i < args.length; i++) {
2500
+ const arg = args[i];
2501
+ if (!hasSeparator) {
2502
+ if (arg === "--") {
2503
+ hasSeparator = true;
2504
+ continue;
2505
+ }
2506
+ if (consumesNextArgument(arg)) {
2507
+ i++;
2508
+ continue;
2509
+ }
2510
+ if (arg.startsWith("-")) continue;
2511
+ }
2512
+ positionalIndices.push(i);
2513
+ }
2514
+ return { positionalIndices, hasSeparator };
2515
+ }
2516
+ function normalizeGitDiffArgs(args, cwd = process.cwd()) {
2517
+ const { positionalIndices, hasSeparator } = classifyGitDiffArgs(args);
2518
+ if (hasSeparator) return args;
2519
+ for (const i of positionalIndices) {
2520
+ const arg = args[i];
2521
+ if (existsSync3(resolve3(cwd, arg))) {
2522
+ return [...args.slice(0, i), "--", ...args.slice(i)];
2523
+ }
2524
+ }
2525
+ return args;
2526
+ }
2527
+ function tokenizeGitDiffArgs(value) {
2528
+ const args = [];
2529
+ let current = "";
2530
+ let started = false;
2531
+ let quote = null;
2532
+ for (let i = 0; i < value.length; i++) {
2533
+ const char = value[i];
2534
+ if (quote === "'") {
2535
+ if (char === "'") quote = null;
2536
+ else current += char;
2537
+ continue;
2538
+ }
2539
+ if (quote === '"') {
2540
+ if (char === "\\" && (value[i + 1] === '"' || value[i + 1] === "\\")) {
2541
+ current += value[++i];
2542
+ } else if (char === '"') {
2543
+ quote = null;
2544
+ } else {
2545
+ current += char;
2546
+ }
2547
+ continue;
2548
+ }
2549
+ if (char === "'" || char === '"') {
2550
+ quote = char;
2551
+ started = true;
2552
+ continue;
2553
+ }
2554
+ if (char === "\\" && i + 1 < value.length) {
2555
+ current += value[++i];
2556
+ started = true;
2557
+ continue;
2558
+ }
2559
+ if (/\s/.test(char)) {
2560
+ if (started) {
2561
+ args.push(current);
2562
+ current = "";
2563
+ started = false;
2564
+ }
2565
+ continue;
2566
+ }
2567
+ current += char;
2568
+ started = true;
2569
+ }
2570
+ if (started) args.push(current);
2571
+ return args;
2572
+ }
2573
+ function needsQuoting(arg) {
2574
+ return arg.length === 0 || /[\s'"\\]/.test(arg);
2575
+ }
2576
+ function formatGitDiffArgs(args) {
2577
+ return args.map((arg) => needsQuoting(arg) ? `'${arg.replace(/'/g, "'\\''")}'` : arg).join(" ");
2578
+ }
2579
+
2580
+ // src/review-handlers.ts
2581
+ function createReviewSession() {
2582
+ return {
2583
+ reviewState: null,
2584
+ diffData: null,
2585
+ guideData: null,
2586
+ config: null,
2587
+ outputPathInfo: null,
2588
+ resumeComments: [],
2589
+ resumeViewedFiles: [],
2590
+ resumeRemoteDrift: null,
2591
+ applyDestinationRoot: null
2592
+ };
2593
+ }
2594
+ function preparePayload(payload) {
2595
+ if (payload.isLargePayload) {
2596
+ return {
2597
+ ...payload,
2598
+ files: payload.files.map((f) => ({ ...f, hunks: [], contentLoaded: false }))
2599
+ };
2600
+ }
2601
+ return {
2602
+ ...payload,
2603
+ files: payload.files.map((f) => ({ ...f, contentLoaded: true }))
2604
+ };
2605
+ }
2606
+ function getDiffLoad(session) {
2607
+ if (!session.diffData) {
2608
+ return null;
2609
+ }
2610
+ return {
2611
+ diff: preparePayload(session.diffData),
2612
+ guide: session.guideData
2613
+ };
2614
+ }
2615
+ function resolveSourceBaseDir(session) {
2616
+ const source = session.diffData?.source;
2617
+ if (!source) return null;
2618
+ if (source.type === "git") return source.repository;
2619
+ if (source.type === "directory") return source.sourcePath;
2620
+ if (source.type === "file") return path3.dirname(source.sourcePath);
2621
+ return null;
2622
+ }
2623
+ async function loadImage(session, filePath) {
2624
+ const MIME_MAP = {
2625
+ ".jpg": "image/jpeg",
2626
+ ".jpeg": "image/jpeg",
2627
+ ".png": "image/png",
2628
+ ".gif": "image/gif",
2629
+ ".webp": "image/webp",
2630
+ ".ico": "image/x-icon",
2631
+ ".bmp": "image/bmp",
2632
+ ".svg": "image/svg+xml"
2633
+ };
2634
+ const MAX_SIZE = 10 * 1024 * 1024;
2635
+ const baseDir = resolveSourceBaseDir(session) ?? process.cwd();
2636
+ const resolved = path3.isAbsolute(filePath) ? filePath : path3.resolve(baseDir, filePath);
2637
+ const ext = path3.extname(filePath).toLowerCase();
2638
+ const mimeType = MIME_MAP[ext] ?? "application/octet-stream";
2639
+ const remote = session.diffData?.remote;
2640
+ if (remote && session.diffData?.source.type === "git") {
2641
+ try {
2642
+ const { readGitBlobAsync } = await import("./git-E7WZPKRC.js");
2643
+ const data = await readGitBlobAsync(
2644
+ session.diffData.source.repository,
2645
+ `${remote.remoteHeadSha}:${filePath}`
2646
+ );
2647
+ if (data.length > MAX_SIZE) {
2648
+ return { error: "File too large to preview (>10 MB)" };
2649
+ }
2650
+ return { dataUri: `data:${mimeType};base64,${data.toString("base64")}` };
2651
+ } catch {
2652
+ return {
2653
+ error: "Image preview unavailable \u2014 blob not found at the reviewed commit."
2654
+ };
2655
+ }
2656
+ }
2657
+ try {
2658
+ const stat2 = await fs3.promises.stat(resolved);
2659
+ if (stat2.size > MAX_SIZE) {
2660
+ return { error: "File too large to preview (>10 MB)" };
2661
+ }
2662
+ const data = await fs3.promises.readFile(resolved);
2663
+ return { dataUri: `data:${mimeType};base64,${data.toString("base64")}` };
2664
+ } catch {
2665
+ return { error: "Image preview unavailable \u2014 file not found on disk." };
2666
+ }
2667
+ }
2668
+ function getFileHunks(session, filePath) {
2669
+ if (!session.diffData) return null;
2670
+ const file = session.diffData.files.find((f) => (f.newPath || f.oldPath) === filePath);
2671
+ if (!file) return null;
2672
+ return file.hunks;
2673
+ }
2674
+ function getConfigLoad(session) {
2675
+ if (!session.config) {
2676
+ return null;
2677
+ }
2678
+ return { config: session.config, outputPathInfo: session.outputPathInfo };
2679
+ }
2680
+ function submitReviewState(session, state) {
2681
+ console.error(
2682
+ "[review] Review state submitted:",
2683
+ JSON.stringify({
2684
+ timestamp: state.timestamp,
2685
+ source: state.source,
2686
+ fileCount: state.files.length
2687
+ })
2688
+ );
2689
+ session.reviewState = state;
2690
+ }
2691
+ function takeReviewState(session) {
2692
+ const state = session.reviewState;
2693
+ session.reviewState = null;
2694
+ return state;
2695
+ }
2696
+ function isTemporaryCloneSession(session) {
2697
+ return session.diffData?.remote?.temporaryClone === true;
2698
+ }
2699
+ function resolveApplyDestination(session) {
2700
+ if (isTemporaryCloneSession(session)) {
2701
+ return session.applyDestinationRoot;
2702
+ }
2703
+ return resolveSourceBaseDir(session);
2704
+ }
2705
+ function applySuggestionForSession(session, request) {
2706
+ const destinationRoot = resolveApplyDestination(session);
2707
+ if (!destinationRoot) {
2708
+ const temporary = isTemporaryCloneSession(session);
2709
+ return {
2710
+ status: "refused",
2711
+ filePath: request.filePath,
2712
+ reason: temporary ? "destination-required" : "no-destination",
2713
+ 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."
2714
+ };
2715
+ }
2716
+ const result = applySuggestion({
2717
+ destinationRoot,
2718
+ filePath: request.filePath,
2719
+ lineRange: request.lineRange,
2720
+ suggestion: request.suggestion
2721
+ });
2722
+ console.error(
2723
+ `[suggestion:apply] ${request.filePath}: ${result.status === "applied" ? "applied" : `refused (${result.reason})`}`
2724
+ );
2725
+ if (result.status === "applied") {
2726
+ return {
2727
+ status: "applied",
2728
+ filePath: result.filePath,
2729
+ replacedLines: result.replacedLines
2730
+ };
2731
+ }
2732
+ return {
2733
+ status: "refused",
2734
+ filePath: result.filePath,
2735
+ reason: result.reason,
2736
+ detail: result.detail
2737
+ };
2738
+ }
2739
+ async function readAttachment(filePath) {
2740
+ try {
2741
+ const buffer = await fs3.promises.readFile(filePath);
2742
+ return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
2743
+ } catch {
2744
+ console.error(`[attachment:read] Failed to read file: ${filePath}`);
2745
+ return null;
2746
+ }
2747
+ }
2748
+ function getResumeLoad(session) {
2749
+ if (session.resumeComments.length > 0 || session.resumeViewedFiles.length > 0 || session.resumeRemoteDrift !== null) {
2750
+ const payload = {
2751
+ comments: session.resumeComments,
2752
+ viewedFiles: session.resumeViewedFiles
2753
+ };
2754
+ if (session.resumeRemoteDrift !== null) {
2755
+ payload.remoteDrift = session.resumeRemoteDrift;
2756
+ }
2757
+ return payload;
2758
+ }
2759
+ return null;
2760
+ }
2761
+ async function expandContext(session, request) {
2762
+ const diffData = session.diffData;
2763
+ if (!diffData || diffData.source.type !== "git") {
2764
+ return null;
2765
+ }
2766
+ try {
2767
+ const { runGitDiffAsync: runGitDiffAsync2 } = await import("./git-E7WZPKRC.js");
2768
+ const { parseDiff: parseDiff2 } = await import("./diff-parser-2JM4CZR3.js");
2769
+ const source = diffData.source;
2770
+ const originalArgs = tokenizeGitDiffArgs(source.gitDiffArgs);
2771
+ const filteredArgs = [];
2772
+ for (let i = 0; i < originalArgs.length; i++) {
2773
+ const arg = originalArgs[i];
2774
+ if (arg.match(/^-U\d+$/) || arg.match(/^--unified=\d+$/)) {
2775
+ continue;
2776
+ }
2777
+ if (arg === "-U" || arg === "--unified") {
2778
+ i++;
2779
+ continue;
2780
+ }
2781
+ if (arg === "--") {
2782
+ break;
2783
+ }
2784
+ filteredArgs.push(arg);
2785
+ }
2786
+ const expandArgs = [...filteredArgs, `-U${request.contextLines}`, "--", request.filePath];
2787
+ const rawDiff = await runGitDiffAsync2(expandArgs, source.repository);
2788
+ const parsedFiles = parseDiff2(rawDiff);
2789
+ if (parsedFiles.length === 0) {
2790
+ return null;
2791
+ }
2792
+ const expandedFile = parsedFiles[0];
2793
+ let totalLines = 0;
2794
+ try {
2795
+ const content = await fs3.promises.readFile(
2796
+ path3.resolve(source.repository, request.filePath),
2797
+ "utf-8"
2798
+ );
2799
+ totalLines = content.split("\n").length;
2800
+ if (content.endsWith("\n")) totalLines--;
2801
+ } catch {
2802
+ }
2803
+ session.diffData = {
2804
+ ...diffData,
2805
+ files: diffData.files.map((f) => {
2806
+ const fPath = f.newPath || f.oldPath;
2807
+ if (fPath === request.filePath) {
2808
+ return { ...f, hunks: expandedFile.hunks };
2809
+ }
2810
+ return f;
2811
+ })
2812
+ };
2813
+ return { hunks: expandedFile.hunks, totalLines };
2814
+ } catch (error) {
2815
+ console.error(`[review] Failed to expand context for ${request.filePath}:`, error);
2816
+ return null;
2817
+ }
2818
+ }
2819
+ async function prepareDirectoryReview(session, directoryPath) {
2820
+ console.error("[review] Starting directory review for:", directoryPath);
2821
+ let isFile = false;
2822
+ try {
2823
+ isFile = fs3.statSync(directoryPath).isFile();
2824
+ } catch {
2825
+ }
2826
+ let payload;
2827
+ if (isFile) {
2828
+ const files = await scanFile(directoryPath);
2829
+ payload = {
2830
+ files,
2831
+ source: { type: "file", sourcePath: directoryPath }
2832
+ };
2833
+ } else {
2834
+ const ignorePatterns = session.config?.ignore ?? [];
2835
+ const files = await scanDirectory(directoryPath, ignorePatterns);
2836
+ payload = {
2837
+ files,
2838
+ source: { type: "directory", sourcePath: directoryPath }
2839
+ };
2840
+ }
2841
+ if (!session.config) {
2842
+ return { payload, stats: null, exceedsThresholds: false };
2843
+ }
2844
+ const stats = computePayloadStats(
2845
+ payload.files.length,
2846
+ countTotalLines(payload.files),
2847
+ session.config
2848
+ );
2849
+ return { payload, stats, exceedsThresholds: stats.exceedsAny };
2850
+ }
2851
+ function commitReviewStart(session, payload) {
2852
+ session.diffData = payload;
2853
+ return preparePayload(payload);
2854
+ }
2855
+
2856
+ // src/startup-mode.ts
2857
+ import { existsSync as existsSync4, statSync as statSync2 } from "fs";
2858
+ import { execFileSync, execSync } from "child_process";
2859
+ import { resolve as resolve4 } from "path";
2860
+ function isInGitRepo() {
2861
+ try {
2862
+ execSync("git rev-parse --git-dir", { stdio: "ignore" });
2863
+ return true;
2864
+ } catch {
2865
+ return false;
2866
+ }
2867
+ }
2868
+ function isGitTracked(filePath) {
2869
+ try {
2870
+ execFileSync("git", ["ls-files", "--error-unmatch", "--", filePath], {
2871
+ stdio: "ignore"
2872
+ });
2873
+ return true;
2874
+ } catch {
2875
+ return false;
2876
+ }
2877
+ }
2878
+ function determineMode(gitDiffArgs) {
2879
+ const { positionalIndices } = classifyGitDiffArgs(gitDiffArgs);
2880
+ const firstPositional = gitDiffArgs[positionalIndices[0]];
2881
+ if (firstPositional) {
2882
+ const candidate = resolve4(process.cwd(), firstPositional);
2883
+ try {
2884
+ if (existsSync4(candidate) && statSync2(candidate).isFile()) {
2885
+ if (isInGitRepo()) {
2886
+ return isGitTracked(firstPositional) ? "git" : "file";
2887
+ }
2888
+ return "file";
2889
+ }
2890
+ } catch {
2891
+ }
2892
+ }
2893
+ if (isInGitRepo()) {
2894
+ return "git";
2895
+ }
2896
+ if (firstPositional) {
2897
+ const candidate = resolve4(process.cwd(), firstPositional);
2898
+ try {
2899
+ if (existsSync4(candidate) && statSync2(candidate).isDirectory()) {
2900
+ return "directory";
2901
+ }
2902
+ } catch {
2903
+ }
2904
+ }
2905
+ return "welcome";
2906
+ }
2907
+
2908
+ // src/guide-loader.ts
2909
+ import { readFile } from "fs/promises";
2910
+ import { extname, resolve as resolve5 } from "path";
2911
+ function deriveGuidePath(outputPath) {
2912
+ const ext = extname(outputPath);
2913
+ const base = ext ? outputPath.slice(0, -ext.length) : outputPath;
2914
+ return `${base}.guide.xml`;
2915
+ }
2916
+ function resolveGuidePath(outputPath, config) {
2917
+ if (config.guideFile) {
2918
+ return resolve5(process.cwd(), config.guideFile);
2919
+ }
2920
+ return deriveGuidePath(outputPath);
2921
+ }
2922
+ async function loadGuide(outputPath, config, diffFilePaths) {
2923
+ let guidePath;
2924
+ try {
2925
+ guidePath = resolveGuidePath(outputPath, config);
2926
+ } catch {
2927
+ return null;
2928
+ }
2929
+ try {
2930
+ let content;
2931
+ try {
2932
+ content = await readFile(guidePath, "utf-8");
2933
+ } catch (error) {
2934
+ const code = error.code;
2935
+ if (code === "ENOENT") {
2936
+ return null;
2937
+ }
2938
+ console.error(
2939
+ `[guide] Ignoring guide at ${guidePath}: unreadable (${code ?? "unknown error"})`
2940
+ );
2941
+ return null;
2942
+ }
2943
+ const result = await parseGuideXml(content);
2944
+ if (result.ok === false) {
2945
+ console.error(`[guide] Ignoring guide at ${guidePath}: invalid (${result.reason})`);
2946
+ return null;
2947
+ }
2948
+ const payload = {
2949
+ groups: reconcileGuide(result.guide, diffFilePaths)
2950
+ };
2951
+ if (result.guide.overview !== void 0) {
2952
+ payload.overview = result.guide.overview;
2953
+ }
2954
+ return payload;
2955
+ } catch (error) {
2956
+ const message = error instanceof Error ? error.message : String(error);
2957
+ console.error(`[guide] Ignoring guide at ${guidePath}: invalid (${message})`);
2958
+ return null;
2959
+ }
2960
+ }
2961
+
2962
+ // src/git-diff-loader.ts
2963
+ async function loadGitDiffWithUntracked(gitDiffArgs, cwd, options = {}) {
2964
+ const { includeUntracked = true } = options;
2965
+ const repository = await getRepoRootAsync(cwd);
2966
+ const rawDiff = await runGitDiffAsync(gitDiffArgs, cwd);
2967
+ const files = parseDiff(rawDiff);
2968
+ if (!includeUntracked) {
2969
+ return { files, repository };
2970
+ }
2971
+ const untrackedPaths = await getUntrackedFilesAsync(repository);
2972
+ let allFiles = files;
2973
+ if (untrackedPaths.length > 0) {
2974
+ const untrackedDiffStr = generateUntrackedDiffs(untrackedPaths, repository);
2975
+ if (untrackedDiffStr.length > 0) {
2976
+ const untrackedFiles = parseDiff(untrackedDiffStr);
2977
+ for (const file of untrackedFiles) {
2978
+ file.isUntracked = true;
2979
+ }
2980
+ allFiles = [...files, ...untrackedFiles];
2981
+ }
2982
+ }
2983
+ return { files: allFiles, repository };
2984
+ }
2985
+
2986
+ // src/staged-untracked.ts
2987
+ function applyStagedUntrackedDefault(config, gitDiffArgs) {
2988
+ const stagedMode = gitDiffArgs.includes("--staged") || gitDiffArgs.includes("--cached");
2989
+ if (!stagedMode) return config;
2990
+ const userExplicitOptIn = config.showUntrackedExplicit && config.showUntracked;
2991
+ if (userExplicitOptIn) return config;
2992
+ return { ...config, showUntracked: false };
2993
+ }
2994
+
2995
+ // src/remote-mode.ts
2996
+ function defaultCreateProvider(forge, runner) {
2997
+ return forge === "github" ? createGitHubProvider(runner) : createGitLabProvider(runner);
2998
+ }
2999
+ var defaultDeps = {
3000
+ createProvider: defaultCreateProvider,
3001
+ detectExistingClone,
3002
+ materialize,
3003
+ resolveRemoteDefaultBranch,
3004
+ runner: defaultGitRunner,
3005
+ loadDiff: (gitDiffArgs, cwd) => (
3006
+ // A base...head diff of a remote PR/MR must never pick up local
3007
+ // untracked files (an existing clone may have unrelated ones).
3008
+ loadGitDiffWithUntracked(gitDiffArgs, cwd, { includeUntracked: false })
3009
+ )
3010
+ };
3011
+ async function startRemoteSession(url, cwd, deps = {}) {
3012
+ const d = { ...defaultDeps, ...deps };
3013
+ const forgeUrl = parseForgeUrl(url);
3014
+ if (!forgeUrl) {
3015
+ throw new Error(`Not a recognized pull-request or merge-request URL: ${url}`);
3016
+ }
3017
+ const provider = d.createProvider(forgeUrl.forge, d.runner);
3018
+ let cliAvailable = true;
3019
+ let baseBranch;
3020
+ let existingClone;
3021
+ try {
3022
+ baseBranch = await provider.fetchBaseBranch(forgeUrl);
3023
+ } catch (error) {
3024
+ if (!(error instanceof ForgeCliUnavailableError)) {
3025
+ throw error;
3026
+ }
3027
+ cliAvailable = false;
3028
+ console.error(
3029
+ `[remote] Forge CLI unavailable (${error.cli}): ${error.message} \u2014 falling back to the remote default branch via git.`
3030
+ );
3031
+ existingClone = await d.detectExistingClone(forgeUrl, cwd, d.runner);
3032
+ baseBranch = await d.resolveRemoteDefaultBranch(forgeUrl, d.runner, existingClone);
3033
+ }
3034
+ const materialized = await d.materialize(forgeUrl, baseBranch, cwd, d.runner, existingClone);
3035
+ let fetchedThreads = [];
3036
+ let threadSyncAvailable = false;
3037
+ if (cliAvailable) {
3038
+ try {
3039
+ fetchedThreads = await provider.fetchThreads(forgeUrl);
3040
+ threadSyncAvailable = true;
3041
+ } catch (error) {
3042
+ const message = error instanceof Error ? error.message : String(error);
3043
+ console.error(
3044
+ `[remote] thread sync unavailable \u2014 continuing without forge threads: ${message}`
3045
+ );
3046
+ }
3047
+ } else {
3048
+ console.error(
3049
+ "[remote] thread sync unavailable \u2014 forge CLI missing, continuing without forge threads."
3050
+ );
3051
+ }
3052
+ return {
3053
+ forgeUrl,
3054
+ repoPath: materialized.repoPath,
3055
+ gitDiffArgs: [`${materialized.baseSha}...${materialized.headSha}`],
3056
+ mode: materialized.mode,
3057
+ cleanup: materialized.cleanup,
3058
+ remote: {
3059
+ remoteUrl: url,
3060
+ remoteBaseSha: materialized.baseSha,
3061
+ remoteHeadSha: materialized.headSha,
3062
+ remoteForge: forgeUrl.forge,
3063
+ threadSyncAvailable,
3064
+ // A temporary clone is deleted on exit, so nothing may be written
3065
+ // into it; the front end needs the fact, not the path.
3066
+ temporaryClone: materialized.mode === "temp-clone"
3067
+ },
3068
+ fetchedComments: mapThreadsToReviewComments(fetchedThreads),
3069
+ fetchedThreads
3070
+ };
3071
+ }
3072
+ async function bootstrapRemoteDiff(url, cwd, ignorePatterns, deps = {}) {
3073
+ const d = { ...defaultDeps, ...deps };
3074
+ const started = await startRemoteSession(url, cwd, d);
3075
+ let files;
3076
+ let repository;
3077
+ try {
3078
+ ({ files, repository } = await d.loadDiff(started.gitDiffArgs, started.repoPath));
3079
+ } catch (error) {
3080
+ started.cleanup();
3081
+ throw error;
3082
+ }
3083
+ const shouldKeep = createIgnoreFilter(ignorePatterns);
3084
+ const filteredFiles = files.filter((f) => shouldKeep(f.newPath || f.oldPath));
3085
+ const session = {
3086
+ ...started,
3087
+ fetchedComments: mapThreadsToReviewComments(started.fetchedThreads, filteredFiles)
3088
+ };
3089
+ return {
3090
+ session,
3091
+ payload: {
3092
+ files: filteredFiles,
3093
+ source: {
3094
+ type: "git",
3095
+ // Same renderer the git-mode path uses, so expand-context can
3096
+ // tokenize this string back into the exact argv.
3097
+ gitDiffArgs: formatGitDiffArgs(session.gitDiffArgs),
3098
+ repository
3099
+ },
3100
+ remote: session.remote
3101
+ }
3102
+ };
3103
+ }
3104
+ function mergeRemoteThreads(resumed, fetched) {
3105
+ const resumedRemoteIds = new Set(
3106
+ resumed.map((c) => c.remoteId).filter((id) => id !== void 0)
3107
+ );
3108
+ return [
3109
+ ...resumed,
3110
+ ...fetched.filter((c) => c.remoteId === void 0 || !resumedRemoteIds.has(c.remoteId))
3111
+ ];
3112
+ }
3113
+ function applyRemoteProvenance(state, remote) {
3114
+ return {
3115
+ ...state,
3116
+ // The three source shapes are mutually exclusive in the document: the
3117
+ // remote-* attributes ARE the source, so the in-session git source
3118
+ // (the materialized clone) must not leak into the saved review. The
3119
+ // welcome source emits no source attributes, mirroring fetch-comments.
3120
+ source: { type: "welcome" },
3121
+ remoteUrl: remote.remoteUrl,
3122
+ remoteBaseSha: remote.remoteBaseSha,
3123
+ remoteHeadSha: remote.remoteHeadSha,
3124
+ remoteForge: remote.remoteForge
3125
+ };
3126
+ }
3127
+ function computeRemoteDrift(recordedHeadSha, liveHeadSha) {
3128
+ if (recordedHeadSha === void 0) {
3129
+ return null;
3130
+ }
3131
+ return {
3132
+ recordedHeadSha,
3133
+ liveHeadSha,
3134
+ drifted: recordedHeadSha !== liveHeadSha
3135
+ };
3136
+ }
3137
+
3138
+ // src/fetch-comments.ts
3139
+ import { writeFileSync as writeFileSync3 } from "fs";
3140
+ import { resolve as resolve6 } from "path";
3141
+ function defaultDeps2() {
3142
+ return {
3143
+ runner: defaultGitRunner,
3144
+ createProvider: (forge, runner) => forge === "github" ? createGitHubProvider(runner) : createGitLabProvider(runner),
3145
+ detectExistingClone,
3146
+ materialize,
3147
+ resolveRemoteDefaultBranch,
3148
+ loadDiffFiles: async (repoPath, baseSha, headSha) => (
3149
+ // Triple-dot: diff from the merge base, matching how forges present a
3150
+ // PR/MR diff. Runs inside the materialized clone.
3151
+ parseDiff(await runGitDiffAsync([`${baseSha}...${headSha}`], repoPath))
3152
+ ),
3153
+ serialize: serializeReview,
3154
+ writeFile: (path4, content) => writeFileSync3(path4, content, "utf-8"),
3155
+ loadConfig,
3156
+ now: () => /* @__PURE__ */ new Date()
3157
+ };
3158
+ }
3159
+ function buildRemoteReviewState(args) {
3160
+ const commentsByPath = /* @__PURE__ */ new Map();
3161
+ for (const comment of args.comments) {
3162
+ const list = commentsByPath.get(comment.filePath);
3163
+ if (list) {
3164
+ list.push(comment);
3165
+ } else {
3166
+ commentsByPath.set(comment.filePath, [comment]);
3167
+ }
3168
+ }
3169
+ const files = [];
3170
+ const diffPaths = /* @__PURE__ */ new Set();
3171
+ for (const diffFile of args.diffFiles) {
3172
+ const path4 = diffFile.changeType === "deleted" ? diffFile.oldPath : diffFile.newPath;
3173
+ diffPaths.add(path4);
3174
+ files.push({
3175
+ path: path4,
3176
+ changeType: diffFile.changeType,
3177
+ viewed: false,
3178
+ comments: commentsByPath.get(path4) ?? []
3179
+ });
3180
+ }
3181
+ for (const [path4, comments] of commentsByPath) {
3182
+ if (path4 === REVIEW_LEVEL_FILE_PATH || diffPaths.has(path4)) continue;
3183
+ files.push({ path: path4, changeType: "modified", viewed: false, comments });
3184
+ }
3185
+ const reviewLevel = commentsByPath.get(REVIEW_LEVEL_FILE_PATH);
3186
+ if (reviewLevel && reviewLevel.length > 0) {
3187
+ files.push({
3188
+ path: REVIEW_LEVEL_FILE_PATH,
3189
+ changeType: "modified",
3190
+ viewed: false,
3191
+ comments: reviewLevel
3192
+ });
3193
+ }
3194
+ return {
3195
+ timestamp: args.timestamp,
3196
+ source: { type: "welcome" },
3197
+ files,
3198
+ remoteUrl: args.remoteUrl,
3199
+ remoteBaseSha: args.baseSha,
3200
+ remoteHeadSha: args.headSha,
3201
+ remoteForge: args.forge
3202
+ };
3203
+ }
3204
+ async function runFetchComments(url, options = {}) {
3205
+ const deps = { ...defaultDeps2(), ...options.deps };
3206
+ const cwd = options.cwd ?? process.cwd();
3207
+ const forgeUrl = parseForgeUrl(url);
3208
+ if (forgeUrl === null) {
3209
+ throw new Error(
3210
+ `Not a recognized pull/merge request URL: ${url}
3211
+ Expected a GitHub PR URL (\u2026/pull/N) or a GitLab MR URL (\u2026/-/merge_requests/N).`
3212
+ );
3213
+ }
3214
+ const provider = deps.createProvider(forgeUrl.forge, deps.runner);
3215
+ let baseBranch;
3216
+ let existingClone;
3217
+ try {
3218
+ baseBranch = await provider.fetchBaseBranch(forgeUrl);
3219
+ } catch (error) {
3220
+ if (!(error instanceof ForgeCliUnavailableError)) throw error;
3221
+ console.error(`[fetch-comments] ${error.message}`);
3222
+ console.error(
3223
+ `[fetch-comments] ${error.cli} unavailable for the base-branch lookup \u2014 falling back to the remote default branch via git ls-remote.`
3224
+ );
3225
+ existingClone = await deps.detectExistingClone(forgeUrl, cwd, deps.runner);
3226
+ baseBranch = await deps.resolveRemoteDefaultBranch(forgeUrl, deps.runner, existingClone);
3227
+ }
3228
+ console.error(`[fetch-comments] Base branch: ${baseBranch}`);
3229
+ const materialized = await deps.materialize(
3230
+ forgeUrl,
3231
+ baseBranch,
3232
+ cwd,
3233
+ deps.runner,
3234
+ existingClone
3235
+ );
3236
+ try {
3237
+ let threads;
3238
+ try {
3239
+ threads = await provider.fetchThreads(forgeUrl, {
3240
+ includeResolved: options.includeResolved ?? false
3241
+ });
3242
+ } catch (error) {
3243
+ if (error instanceof ForgeCliUnavailableError) {
3244
+ throw new Error(
3245
+ `Cannot fetch discussion threads: ${error.message}
3246
+ fetch-comments requires the ${error.cli} CLI to be installed and authenticated.`
3247
+ );
3248
+ }
3249
+ throw error;
3250
+ }
3251
+ console.error(`[fetch-comments] Fetched ${threads.length} threads`);
3252
+ const diffFiles = await deps.loadDiffFiles(
3253
+ materialized.repoPath,
3254
+ materialized.baseSha,
3255
+ materialized.headSha
3256
+ );
3257
+ const comments = mapThreadsToReviewComments(threads, diffFiles);
3258
+ const state = buildRemoteReviewState({
3259
+ remoteUrl: url,
3260
+ forge: forgeUrl.forge,
3261
+ baseSha: materialized.baseSha,
3262
+ headSha: materialized.headSha,
3263
+ diffFiles,
3264
+ comments,
3265
+ timestamp: deps.now().toISOString()
3266
+ });
3267
+ const config = deps.loadConfig();
3268
+ const outputPath = resolve6(cwd, config.outputFile);
3269
+ const xml = await deps.serialize(state, outputPath);
3270
+ deps.writeFile(outputPath, xml + "\n");
3271
+ console.error(`[fetch-comments] ${comments.length} threads written to ${outputPath}`);
3272
+ } finally {
3273
+ materialized.cleanup();
3274
+ }
3275
+ }
2638
3276
  export {
2639
3277
  ForgeCliUnavailableError,
2640
3278
  GUIDE_XSD_SCHEMA,
2641
3279
  IMPLICIT_GUIDE_GROUP_NAME,
2642
3280
  REVIEW_LEVEL_FILE_PATH,
3281
+ applyRemoteProvenance,
3282
+ applyStagedUntrackedDefault,
3283
+ applySuggestion,
3284
+ applySuggestionForSession,
3285
+ bootstrapRemoteDiff,
3286
+ buildRemoteReviewState,
2643
3287
  checkWritability,
3288
+ commitReviewStart,
2644
3289
  computePayloadStats,
3290
+ computeRemoteDrift,
2645
3291
  countTotalLines,
2646
3292
  createGitHubProvider,
2647
3293
  createGitLabProvider,
2648
3294
  createIgnoreFilter,
3295
+ createReviewSession,
2649
3296
  defaultGitRunner,
3297
+ deriveGuidePath,
2650
3298
  detectExistingClone,
3299
+ determineMode,
3300
+ expandContext,
2651
3301
  generateSyntheticDiffs,
2652
3302
  generateUntrackedDiffs,
3303
+ getConfigLoad,
3304
+ getDiffLoad,
3305
+ getFileHunks,
2653
3306
  getGitDiffStats,
2654
3307
  getLanguageFromPath,
2655
3308
  getRenderedTextMode,
2656
3309
  getRepoRoot,
2657
3310
  getRepoRootAsync,
3311
+ getResumeLoad,
2658
3312
  getUntrackedFilesAsync,
2659
3313
  isHtmlFile,
2660
3314
  isMarkdownFile,
@@ -2662,20 +3316,35 @@ export {
2662
3316
  isPreviewableRenderedText,
2663
3317
  isPreviewableSvg,
2664
3318
  loadConfig,
3319
+ loadGitDiffWithUntracked,
3320
+ loadGuide,
3321
+ loadImage,
2665
3322
  mapThreadsToReviewComments,
2666
3323
  materialize,
3324
+ mergeRemoteThreads,
3325
+ normalizeGitDiffArgs,
2667
3326
  parseDiff,
2668
3327
  parseForgeUrl,
2669
3328
  parseGuideXml,
2670
3329
  parseReviewXml,
2671
3330
  parseReviewXmlString,
3331
+ prepareDirectoryReview,
3332
+ preparePayload,
3333
+ readAttachment,
2672
3334
  reconcileGuide,
3335
+ resolveApplyDestination,
3336
+ resolveGuidePath,
2673
3337
  resolveRemoteDefaultBranch,
3338
+ resolveSourceBaseDir,
3339
+ runFetchComments,
2674
3340
  runGitDiff,
2675
3341
  runGitDiffAsync,
2676
3342
  scanDirectory,
2677
3343
  scanFile,
2678
3344
  serializeReview,
3345
+ startRemoteSession,
3346
+ submitReviewState,
3347
+ takeReviewState,
2679
3348
  validateGitAvailable
2680
3349
  };
2681
3350
  //# sourceMappingURL=index.js.map