@staff0rd/assist 0.1217.3 → 0.1217.5

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.
@@ -49,6 +49,9 @@ import {
49
49
  exitWithConfigErrors
50
50
  } from "./chunk-JPRADR2E.js";
51
51
  import "./chunk-C3MGHR3N.js";
52
+ import {
53
+ mapAsync
54
+ } from "./chunk-2JYMVJGZ.js";
52
55
  import {
53
56
  launchBlocker
54
57
  } from "./chunk-24YN3552.js";
@@ -88,6 +91,7 @@ import "./chunk-3VDV7VHX.js";
88
91
  import {
89
92
  configEntryLayers,
90
93
  ghFailure,
94
+ ghRawFileAtSha,
91
95
  highLevelProgressPath,
92
96
  highLevelReviewPath,
93
97
  loadHighLevelProgress,
@@ -95,7 +99,7 @@ import {
95
99
  readStoredHighLevelProgress,
96
100
  saveHighLevelProgress,
97
101
  writeJsonFile
98
- } from "./chunk-FLYNSV6L.js";
102
+ } from "./chunk-BAIGEXPY.js";
99
103
  import {
100
104
  stripAnsi
101
105
  } from "./chunk-YJ72SXVD.js";
@@ -549,153 +553,6 @@ function announceSavedReview(subject, force) {
549
553
  );
550
554
  }
551
555
 
552
- // src/commands/review/highLevel/groupFilesByDirectory.ts
553
- var emptyDirectoryGroup = () => ({
554
- dirs: /* @__PURE__ */ new Map(),
555
- files: []
556
- });
557
- function place(root, file) {
558
- const segments = file.path.split("/").filter(Boolean);
559
- segments.pop();
560
- let at = root;
561
- for (const segment of segments) {
562
- const next = at.dirs.get(segment) ?? emptyDirectoryGroup();
563
- at.dirs.set(segment, next);
564
- at = next;
565
- }
566
- at.files.push(file);
567
- }
568
- function groupFilesByDirectory(files) {
569
- const root = emptyDirectoryGroup();
570
- for (const file of files) place(root, file);
571
- return root;
572
- }
573
-
574
- // src/commands/review/highLevel/buildHighLevelTree.ts
575
- function basename(path) {
576
- return path.slice(path.lastIndexOf("/") + 1);
577
- }
578
- function sum(nodes, key) {
579
- return nodes.reduce((total, node) => total + node[key], 0);
580
- }
581
- function byName(a, b) {
582
- return a.name.localeCompare(b.name);
583
- }
584
- function nodesOf(at, prefix) {
585
- const dirs = [...at.dirs].map(
586
- ([name2, child]) => collapsedDirNode(name2, child, prefix)
587
- );
588
- const files = at.files.map((file) => ({
589
- kind: "file",
590
- name: basename(file.path),
591
- ...file
592
- }));
593
- return [...dirs.sort(byName), ...files.sort(byName)];
594
- }
595
- function collapsedDirNode(name2, at, prefix) {
596
- let label = name2;
597
- let path = prefix ? `${prefix}/${name2}` : name2;
598
- let node = at;
599
- while (node.files.length === 0 && node.dirs.size === 1) {
600
- const [childName, child] = [...node.dirs][0];
601
- label = `${label}/${childName}`;
602
- path = `${path}/${childName}`;
603
- node = child;
604
- }
605
- const children = nodesOf(node, path);
606
- return {
607
- kind: "dir",
608
- name: label,
609
- path,
610
- additions: sum(children, "additions"),
611
- deletions: sum(children, "deletions"),
612
- children
613
- };
614
- }
615
- function buildHighLevelTree(files) {
616
- return nodesOf(groupFilesByDirectory(files), "");
617
- }
618
-
619
- // src/commands/review/highLevel/buildHighLevelStructure.ts
620
- function sum2(files, key) {
621
- return files.reduce((total, file) => total + file[key], 0);
622
- }
623
- function countOf(files, status) {
624
- return files.filter((file) => file.status === status).length;
625
- }
626
- function buildHighLevelStructure(files) {
627
- return {
628
- tree: buildHighLevelTree(files),
629
- added: countOf(files, "added"),
630
- removed: countOf(files, "removed"),
631
- modified: countOf(files, "modified"),
632
- additions: sum2(files, "additions"),
633
- deletions: sum2(files, "deletions")
634
- };
635
- }
636
-
637
- // src/commands/review/highLevel/capHighLevelPatches.ts
638
- import { minimatch } from "minimatch";
639
-
640
- // src/commands/review/highLevel/hunksOf.ts
641
- function hunksOf(patch2) {
642
- const hunks = [];
643
- for (const line of patch2.split("\n")) {
644
- const last = hunks[hunks.length - 1];
645
- if (line.startsWith("@@") || last === void 0) hunks.push(line);
646
- else hunks[hunks.length - 1] = `${last}
647
- ${line}`;
648
- }
649
- return hunks;
650
- }
651
-
652
- // src/commands/review/highLevel/capPatchToBudget.ts
653
- function capPatchToBudget(patch2, budget) {
654
- const kept = [];
655
- let lines = 0;
656
- for (const hunk of hunksOf(patch2)) {
657
- const size = hunk.split("\n").length;
658
- if (lines + size > budget)
659
- return {
660
- ...kept.length > 0 ? { patch: kept.join("\n") } : {},
661
- truncated: true
662
- };
663
- kept.push(hunk);
664
- lines += size;
665
- }
666
- return { patch: patch2, truncated: false };
667
- }
668
-
669
- // src/commands/review/highLevel/capHighLevelPatches.ts
670
- var MAX_FILE_PATCH_LINES = 1500;
671
- var MAX_TOTAL_PATCH_LINES = 2e4;
672
- function criticalFirst(files, criticalPaths) {
673
- const isCritical = (file) => criticalPaths.some((glob) => minimatch(file.path, glob));
674
- return [...files].sort(
675
- (a, b) => Number(isCritical(b)) - Number(isCritical(a))
676
- );
677
- }
678
- function capped(file, budget) {
679
- if (file.patch === void 0) return file;
680
- const { patch: patch2, truncated } = capPatchToBudget(file.patch, budget);
681
- const { patch: _dropped, ...rest } = file;
682
- return {
683
- ...rest,
684
- ...patch2 === void 0 ? {} : { patch: patch2 },
685
- ...truncated ? { truncated: true } : {}
686
- };
687
- }
688
- function capHighLevelPatches(files, criticalPaths) {
689
- let remaining = MAX_TOTAL_PATCH_LINES;
690
- const byPath = /* @__PURE__ */ new Map();
691
- for (const file of criticalFirst(files, criticalPaths)) {
692
- const result = capped(file, Math.min(MAX_FILE_PATCH_LINES, remaining));
693
- remaining -= result.patch?.split("\n").length ?? 0;
694
- byPath.set(file.path, result);
695
- }
696
- return files.map((file) => byPath.get(file.path) ?? file);
697
- }
698
-
699
556
  // src/commands/review/highLevel/findIssueReference.ts
700
557
  var ISSUE_URL_PATTERN = /https?:\/\/github\.com\/[\w.-]+\/[\w.-]+\/issues\/\d+/;
701
558
  var CROSS_REPO_PATTERN = /\b[\w.-]+\/[\w.-]+#\d+/;
@@ -783,7 +640,7 @@ function checkNoMergeConflicts(mergeable, baseRef) {
783
640
  }
784
641
 
785
642
  // src/commands/review/highLevel/checkUiEvidence.ts
786
- import { minimatch as minimatch2 } from "minimatch";
643
+ import { minimatch } from "minimatch";
787
644
  var EVIDENCE_PATTERNS = [
788
645
  /!\[[^\]]*\]\([^)]+\)/g,
789
646
  /<(?:img|video)\b[^>]*>/gi,
@@ -806,7 +663,7 @@ function checkUiEvidence(body, changedFiles, uiPaths) {
806
663
  reason: "review.highLevel.uiPaths is unset, so no UI evidence is required"
807
664
  };
808
665
  const touched = changedFiles.filter(
809
- (file) => uiPaths.some((glob) => minimatch2(file, glob))
666
+ (file) => uiPaths.some((glob) => minimatch(file, glob))
810
667
  );
811
668
  if (touched.length === 0)
812
669
  return {
@@ -912,38 +769,6 @@ function evaluateHighLevelChecks(subject) {
912
769
  });
913
770
  }
914
771
 
915
- // src/commands/review/highLevel/fetchHighLevelFiles.ts
916
- import { execFileSync as execFileSync2 } from "child_process";
917
- import { createHash } from "crypto";
918
- var JQ = ".[] | {filename,status,additions,deletions,patch} | @json";
919
- function toStatus(status) {
920
- if (status === "added") return "added";
921
- if (status === "removed") return "removed";
922
- return "modified";
923
- }
924
- function diffUrl(repo, prNumber, path) {
925
- const anchor = createHash("sha256").update(path).digest("hex");
926
- return `https://github.com/${repo}/pull/${prNumber}/files#diff-${anchor}`;
927
- }
928
- function fetchHighLevelFiles(prNumber, repo) {
929
- const out = execFileSync2(
930
- "gh",
931
- ["api", `repos/${repo}/pulls/${prNumber}/files`, "--paginate", "--jq", JQ],
932
- { encoding: "utf8", maxBuffer: 64 * 1024 * 1024 }
933
- );
934
- return out.trim().split("\n").filter(Boolean).map((line) => {
935
- const file = JSON.parse(line);
936
- return {
937
- path: file.filename,
938
- status: toStatus(file.status),
939
- additions: file.additions,
940
- deletions: file.deletions,
941
- diffUrl: diffUrl(repo, prNumber, file.filename),
942
- ...file.patch ? { patch: file.patch } : {}
943
- };
944
- });
945
- }
946
-
947
772
  // src/commands/review/highLevel/waitForMergeable.ts
948
773
  var MAX_ATTEMPTS = 5;
949
774
  var DELAY_MS = 2e3;
@@ -960,9 +785,9 @@ function waitForMergeable(initial, refetch, delayMs = DELAY_MS) {
960
785
  }
961
786
 
962
787
  // src/commands/review/highLevel/ghPrView.ts
963
- import { execFileSync as execFileSync3 } from "child_process";
788
+ import { execFileSync as execFileSync2 } from "child_process";
964
789
  function ghPrView(prNumber, repo, fields) {
965
- const raw = execFileSync3(
790
+ const raw = execFileSync2(
966
791
  "gh",
967
792
  [
968
793
  "pr",
@@ -1001,6 +826,185 @@ function fetchHighLevelPr(prNumber, repo) {
1001
826
  };
1002
827
  }
1003
828
 
829
+ // src/commands/review/highLevel/groupFilesByDirectory.ts
830
+ var emptyDirectoryGroup = () => ({
831
+ dirs: /* @__PURE__ */ new Map(),
832
+ files: []
833
+ });
834
+ function place(root, file) {
835
+ const segments = file.path.split("/").filter(Boolean);
836
+ segments.pop();
837
+ let at = root;
838
+ for (const segment of segments) {
839
+ const next = at.dirs.get(segment) ?? emptyDirectoryGroup();
840
+ at.dirs.set(segment, next);
841
+ at = next;
842
+ }
843
+ at.files.push(file);
844
+ }
845
+ function groupFilesByDirectory(files) {
846
+ const root = emptyDirectoryGroup();
847
+ for (const file of files) place(root, file);
848
+ return root;
849
+ }
850
+
851
+ // src/commands/review/highLevel/buildHighLevelTree.ts
852
+ function basename(path) {
853
+ return path.slice(path.lastIndexOf("/") + 1);
854
+ }
855
+ function sum(nodes, key) {
856
+ return nodes.reduce((total, node) => total + node[key], 0);
857
+ }
858
+ function byName(a, b) {
859
+ return a.name.localeCompare(b.name);
860
+ }
861
+ function nodesOf(at, prefix) {
862
+ const dirs = [...at.dirs].map(
863
+ ([name2, child]) => collapsedDirNode(name2, child, prefix)
864
+ );
865
+ const files = at.files.map((file) => ({
866
+ kind: "file",
867
+ name: basename(file.path),
868
+ ...file
869
+ }));
870
+ return [...dirs.sort(byName), ...files.sort(byName)];
871
+ }
872
+ function collapsedDirNode(name2, at, prefix) {
873
+ let label = name2;
874
+ let path = prefix ? `${prefix}/${name2}` : name2;
875
+ let node = at;
876
+ while (node.files.length === 0 && node.dirs.size === 1) {
877
+ const [childName, child] = [...node.dirs][0];
878
+ label = `${label}/${childName}`;
879
+ path = `${path}/${childName}`;
880
+ node = child;
881
+ }
882
+ const children = nodesOf(node, path);
883
+ return {
884
+ kind: "dir",
885
+ name: label,
886
+ path,
887
+ additions: sum(children, "additions"),
888
+ deletions: sum(children, "deletions"),
889
+ children
890
+ };
891
+ }
892
+ function buildHighLevelTree(files) {
893
+ return nodesOf(groupFilesByDirectory(files), "");
894
+ }
895
+
896
+ // src/commands/review/highLevel/buildHighLevelStructure.ts
897
+ function sum2(files, key) {
898
+ return files.reduce((total, file) => total + file[key], 0);
899
+ }
900
+ function countOf(files, status) {
901
+ return files.filter((file) => file.status === status).length;
902
+ }
903
+ function buildHighLevelStructure(files) {
904
+ return {
905
+ tree: buildHighLevelTree(files),
906
+ added: countOf(files, "added"),
907
+ removed: countOf(files, "removed"),
908
+ modified: countOf(files, "modified"),
909
+ additions: sum2(files, "additions"),
910
+ deletions: sum2(files, "deletions")
911
+ };
912
+ }
913
+
914
+ // src/commands/review/highLevel/capHighLevelPatches.ts
915
+ import { minimatch as minimatch2 } from "minimatch";
916
+
917
+ // src/commands/review/highLevel/hunksOf.ts
918
+ function hunksOf(patch2) {
919
+ const hunks = [];
920
+ for (const line of patch2.split("\n")) {
921
+ const last = hunks[hunks.length - 1];
922
+ if (line.startsWith("@@") || last === void 0) hunks.push(line);
923
+ else hunks[hunks.length - 1] = `${last}
924
+ ${line}`;
925
+ }
926
+ return hunks;
927
+ }
928
+
929
+ // src/commands/review/highLevel/capPatchToBudget.ts
930
+ function capPatchToBudget(patch2, budget) {
931
+ const kept = [];
932
+ let lines = 0;
933
+ for (const hunk of hunksOf(patch2)) {
934
+ const size = hunk.split("\n").length;
935
+ if (lines + size > budget)
936
+ return {
937
+ ...kept.length > 0 ? { patch: kept.join("\n") } : {},
938
+ truncated: true
939
+ };
940
+ kept.push(hunk);
941
+ lines += size;
942
+ }
943
+ return { patch: patch2, truncated: false };
944
+ }
945
+
946
+ // src/commands/review/highLevel/capHighLevelPatches.ts
947
+ var MAX_FILE_PATCH_LINES = 1500;
948
+ var MAX_TOTAL_PATCH_LINES = 2e4;
949
+ function criticalFirst(files, criticalPaths) {
950
+ const isCritical = (file) => criticalPaths.some((glob) => minimatch2(file.path, glob));
951
+ return [...files].sort(
952
+ (a, b) => Number(isCritical(b)) - Number(isCritical(a))
953
+ );
954
+ }
955
+ function capped(file, budget) {
956
+ if (file.patch === void 0) return file;
957
+ const { patch: patch2, truncated } = capPatchToBudget(file.patch, budget);
958
+ const { patch: _dropped, ...rest } = file;
959
+ return {
960
+ ...rest,
961
+ ...patch2 === void 0 ? {} : { patch: patch2 },
962
+ ...truncated ? { truncated: true } : {}
963
+ };
964
+ }
965
+ function capHighLevelPatches(files, criticalPaths) {
966
+ let remaining = MAX_TOTAL_PATCH_LINES;
967
+ const byPath = /* @__PURE__ */ new Map();
968
+ for (const file of criticalFirst(files, criticalPaths)) {
969
+ const result = capped(file, Math.min(MAX_FILE_PATCH_LINES, remaining));
970
+ remaining -= result.patch?.split("\n").length ?? 0;
971
+ byPath.set(file.path, result);
972
+ }
973
+ return files.map((file) => byPath.get(file.path) ?? file);
974
+ }
975
+
976
+ // src/commands/review/highLevel/fetchHighLevelFiles.ts
977
+ import { execFileSync as execFileSync3 } from "child_process";
978
+ import { createHash } from "crypto";
979
+ var JQ = ".[] | {filename,status,additions,deletions,patch} | @json";
980
+ function toStatus(status) {
981
+ if (status === "added") return "added";
982
+ if (status === "removed") return "removed";
983
+ return "modified";
984
+ }
985
+ function diffUrl(repo, prNumber, path) {
986
+ const anchor = createHash("sha256").update(path).digest("hex");
987
+ return `https://github.com/${repo}/pull/${prNumber}/files#diff-${anchor}`;
988
+ }
989
+ function fetchHighLevelFiles(prNumber, repo) {
990
+ const out = execFileSync3(
991
+ "gh",
992
+ ["api", `repos/${repo}/pulls/${prNumber}/files`, "--paginate", "--jq", JQ],
993
+ { encoding: "utf8", maxBuffer: 64 * 1024 * 1024 }
994
+ );
995
+ return out.trim().split("\n").filter(Boolean).map((line) => {
996
+ const file = JSON.parse(line);
997
+ return {
998
+ path: file.filename,
999
+ status: toStatus(file.status),
1000
+ additions: file.additions,
1001
+ deletions: file.deletions,
1002
+ diffUrl: diffUrl(repo, prNumber, file.filename),
1003
+ ...file.patch ? { patch: file.patch } : {}
1004
+ };
1005
+ });
1006
+ }
1007
+
1004
1008
  // src/commands/review/highLevel/gatherHighLevelSlices.ts
1005
1009
  import { readFileSync } from "fs";
1006
1010
 
@@ -1285,9 +1289,6 @@ function capHighLevelTestSources(files) {
1285
1289
  return files.map((file) => ({ ...file, tests: file.tests.map(capNode) }));
1286
1290
  }
1287
1291
 
1288
- // src/commands/review/highLevel/collectHighLevelTests.ts
1289
- import { minimatch as minimatch3 } from "minimatch";
1290
-
1291
1292
  // src/commands/review/highLevel/extractTestHierarchy.ts
1292
1293
  import { Node as Node3, Project } from "ts-morph";
1293
1294
 
@@ -1398,6 +1399,14 @@ function extractTestHierarchy(path, text, changed) {
1398
1399
  return collect(source, { path, ...changed ? { changed } : {} });
1399
1400
  }
1400
1401
 
1402
+ // src/commands/review/highLevel/highLevelTestCandidates.ts
1403
+ import { minimatch as minimatch3 } from "minimatch";
1404
+ function highLevelTestCandidates(files, testPaths) {
1405
+ return files.filter(
1406
+ (file) => file.status !== "removed" && testPaths.some((glob) => minimatch3(file.path, glob))
1407
+ );
1408
+ }
1409
+
1401
1410
  // src/commands/review/highLevel/patchAddedLines.ts
1402
1411
  var HUNK_HEADER = /^@@ -\d+(?:,\d+)? \+(\d+)/;
1403
1412
  function patchAddedLines(patch2) {
@@ -1421,30 +1430,15 @@ function testFile(file, readSource) {
1421
1430
  return [{ path, status, additions, deletions, diffUrl: diffUrl2, tests }];
1422
1431
  }
1423
1432
  function collectHighLevelTests(files, testPaths, readSource) {
1424
- return files.filter(
1425
- (file) => file.status !== "removed" && testPaths.some((glob) => minimatch3(file.path, glob))
1426
- ).flatMap((file) => testFile(file, readSource));
1433
+ return highLevelTestCandidates(files, testPaths).flatMap(
1434
+ (file) => testFile(file, readSource)
1435
+ );
1427
1436
  }
1428
1437
 
1429
1438
  // src/commands/review/highLevel/fetchFileAtSha.ts
1430
- import { execFileSync as execFileSync4 } from "child_process";
1431
- function fetchFileAtSha(repo, sha, path) {
1432
- const encodedPath = path.split("/").map(encodeURIComponent).join("/");
1439
+ async function fetchFileAtSha(repo, sha, path) {
1433
1440
  try {
1434
- return execFileSync4(
1435
- "gh",
1436
- [
1437
- "api",
1438
- "-H",
1439
- "Accept: application/vnd.github.raw",
1440
- `repos/${repo}/contents/${encodedPath}?ref=${sha}`
1441
- ],
1442
- {
1443
- encoding: "utf8",
1444
- maxBuffer: 64 * 1024 * 1024,
1445
- stdio: ["ignore", "pipe", "pipe"]
1446
- }
1447
- );
1441
+ return await ghRawFileAtSha(repo, sha, path, 64 * 1024 * 1024);
1448
1442
  } catch (error) {
1449
1443
  throw new Error(
1450
1444
  `Could not read ${path} at PR head ${sha.slice(0, 7)}: ${ghFailure(error)}`
@@ -1453,29 +1447,33 @@ function fetchFileAtSha(repo, sha, path) {
1453
1447
  }
1454
1448
 
1455
1449
  // src/commands/review/highLevel/gatherHighLevelTests.ts
1456
- function gatherHighLevelTests(files, testPaths, repo, headSha) {
1450
+ var FETCH_CONCURRENCY = 8;
1451
+ async function gatherHighLevelTests(files, testPaths, repo, headSha) {
1452
+ const paths = highLevelTestCandidates(files, testPaths).map(
1453
+ (file) => file.path
1454
+ );
1455
+ const contents = await mapAsync(
1456
+ paths,
1457
+ FETCH_CONCURRENCY,
1458
+ (path) => fetchFileAtSha(repo, headSha, path)
1459
+ );
1460
+ const sources = new Map(paths.map((path, i) => [path, contents[i]]));
1457
1461
  return capHighLevelTestSources(
1458
- collectHighLevelTests(
1459
- files,
1460
- testPaths,
1461
- (path) => fetchFileAtSha(repo, headSha, path)
1462
- )
1462
+ collectHighLevelTests(files, testPaths, (path) => sources.get(path) ?? "")
1463
1463
  );
1464
1464
  }
1465
1465
 
1466
- // src/commands/review/highLevel/loadHighLevelReview.ts
1467
- function loadHighLevelReview(repo, headRef, headSha) {
1468
- return readJsonFile(highLevelReviewPath(repo, headRef, headSha));
1466
+ // src/commands/review/highLevel/highLevelSubjectCachePath.ts
1467
+ function highLevelSubjectCachePath(repo, headRef, headSha) {
1468
+ return highLevelReviewPath(repo, headRef, headSha).replace(
1469
+ /\.json$/,
1470
+ ".subject.json"
1471
+ );
1469
1472
  }
1470
1473
 
1471
- // src/commands/review/highLevel/loadReopenedReview.ts
1472
- function loadReopenedReview({ repo, prNumber, headRef, headSha }, force) {
1473
- const saved = force ? void 0 : loadHighLevelReview(repo, headRef, headSha);
1474
- const progress = loadHighLevelProgress(repo, prNumber, headSha);
1475
- return {
1476
- ...saved ? { saved } : {},
1477
- ...progress ? { progress } : {}
1478
- };
1474
+ // src/commands/review/highLevel/saveHighLevelSubjectCache.ts
1475
+ function saveHighLevelSubjectCache({ repo, headRef, headSha }, cache) {
1476
+ writeJsonFile(highLevelSubjectCachePath(repo, headRef, headSha), cache);
1479
1477
  }
1480
1478
 
1481
1479
  // src/commands/review/highLevel/selectCriticalDiffs.ts
@@ -1495,16 +1493,74 @@ function selectCriticalDiffs(files, criticalPaths) {
1495
1493
  );
1496
1494
  }
1497
1495
 
1496
+ // src/commands/review/highLevel/gatherFreshHighLevelSubject.ts
1497
+ async function gatherFreshHighLevelSubject(head, config, slicing) {
1498
+ const fetched = fetchHighLevelFiles(head.prNumber, head.repo);
1499
+ const files = capHighLevelPatches(fetched, config.criticalPaths);
1500
+ const sliced = slicing ? gatherHighLevelSlices(head, files, slicing) : void 0;
1501
+ const cache = {
1502
+ criticalPaths: config.criticalPaths,
1503
+ testPaths: config.testPaths,
1504
+ changedFiles: files.map((file) => file.path),
1505
+ structure: buildHighLevelStructure(files),
1506
+ criticalDiffs: selectCriticalDiffs(files, config.criticalPaths),
1507
+ tests: await gatherHighLevelTests(
1508
+ fetched,
1509
+ config.testPaths,
1510
+ head.repo,
1511
+ head.headSha
1512
+ )
1513
+ };
1514
+ saveHighLevelSubjectCache(head, cache);
1515
+ return { cache, sliced };
1516
+ }
1517
+
1518
+ // src/commands/review/highLevel/loadHighLevelReview.ts
1519
+ function loadHighLevelReview(repo, headRef, headSha) {
1520
+ return readJsonFile(highLevelReviewPath(repo, headRef, headSha));
1521
+ }
1522
+
1523
+ // src/commands/review/highLevel/loadReopenedReview.ts
1524
+ function loadReopenedReview({ repo, prNumber, headRef, headSha }, force) {
1525
+ const saved = force ? void 0 : loadHighLevelReview(repo, headRef, headSha);
1526
+ const progress = loadHighLevelProgress(repo, prNumber, headSha);
1527
+ return {
1528
+ ...saved ? { saved } : {},
1529
+ ...progress ? { progress } : {}
1530
+ };
1531
+ }
1532
+
1533
+ // src/commands/review/highLevel/loadHighLevelSubjectCache.ts
1534
+ function samePaths(a, b) {
1535
+ return a !== void 0 && a.length === b.length && a.every((p, i) => p === b[i]);
1536
+ }
1537
+ function loadHighLevelSubjectCache({ repo, headRef, headSha }, config) {
1538
+ const cached = readJsonFile(
1539
+ highLevelSubjectCachePath(repo, headRef, headSha)
1540
+ );
1541
+ if (!cached) return void 0;
1542
+ return samePaths(cached.criticalPaths, config.criticalPaths) && samePaths(cached.testPaths, config.testPaths) ? cached : void 0;
1543
+ }
1544
+
1545
+ // src/commands/review/highLevel/reuseCachedHighLevelSubject.ts
1546
+ function reuseCachedHighLevelSubject(head, config, slicing) {
1547
+ if (!slicing?.reuseOnly || slicing.slicesFile) return void 0;
1548
+ const cache = loadHighLevelSubjectCache(head, config);
1549
+ if (!cache) return void 0;
1550
+ return { cache, sliced: gatherHighLevelSlices(head, [], slicing) };
1551
+ }
1552
+
1498
1553
  // src/commands/review/highLevel/gatherHighLevelSubject.ts
1499
- function gatherHighLevelSubject(prNumber, force, slicing) {
1554
+ async function gatherHighLevelSubject(prNumber, force, slicing) {
1500
1555
  const { org, repo } = getRepoInfo();
1501
- const slug = `${org}/${repo}`;
1502
1556
  const pr = fetchHighLevelPr(prNumber, { org, repo });
1503
1557
  const config = resolveHighLevelConfig(loadConfig());
1504
- const fetched = fetchHighLevelFiles(prNumber, slug);
1505
- const files = capHighLevelPatches(fetched, config.criticalPaths);
1506
- const head = { repo: slug, headRef: pr.headRef, headSha: pr.headSha };
1507
- const sliced = slicing ? gatherHighLevelSlices({ ...head, prNumber }, files, slicing) : void 0;
1558
+ const head = {
1559
+ repo: `${org}/${repo}`,
1560
+ headRef: pr.headRef,
1561
+ headSha: pr.headSha
1562
+ };
1563
+ const { cache, sliced } = reuseCachedHighLevelSubject({ ...head, prNumber }, config, slicing) ?? await gatherFreshHighLevelSubject({ ...head, prNumber }, config, slicing);
1508
1564
  return {
1509
1565
  ...head,
1510
1566
  prNumber,
@@ -1512,14 +1568,14 @@ function gatherHighLevelSubject(prNumber, force, slicing) {
1512
1568
  body: pr.body,
1513
1569
  checks: evaluateHighLevelChecks({
1514
1570
  ...pr,
1515
- changedFiles: files.map((file) => file.path),
1571
+ changedFiles: cache.changedFiles,
1516
1572
  config,
1517
1573
  sliced: sliced !== void 0
1518
1574
  }),
1519
- structure: buildHighLevelStructure(files),
1520
- criticalDiffs: selectCriticalDiffs(files, config.criticalPaths),
1575
+ structure: cache.structure,
1576
+ criticalDiffs: cache.criticalDiffs,
1521
1577
  criticalPaths: config.criticalPaths,
1522
- tests: gatherHighLevelTests(fetched, config.testPaths, slug, pr.headSha),
1578
+ tests: cache.tests,
1523
1579
  testPaths: config.testPaths,
1524
1580
  collapsedPaths: config.collapsedPaths,
1525
1581
  ...sliced,
@@ -2082,9 +2138,9 @@ function resolvePrNumber(number) {
2082
2138
  }
2083
2139
  return parsed;
2084
2140
  }
2085
- function gatherSubject(prNumber, force, slicing) {
2141
+ async function gatherSubject(prNumber, force, slicing) {
2086
2142
  try {
2087
- return gatherHighLevelSubject(prNumber, force, slicing);
2143
+ return await gatherHighLevelSubject(prNumber, force, slicing);
2088
2144
  } catch (error) {
2089
2145
  console.error(
2090
2146
  `Error: ${error instanceof Error ? error.message : String(error)}`
@@ -2104,7 +2160,7 @@ async function runHighLevelReview(number, options = {}) {
2104
2160
  ...options.slices ? { slicesFile: options.slices } : {},
2105
2161
  ...options.reuseSlices ? { reuseOnly: true } : {}
2106
2162
  } : void 0;
2107
- const subject = gatherSubject(resolvePrNumber(number), force, slicing);
2163
+ const subject = await gatherSubject(resolvePrNumber(number), force, slicing);
2108
2164
  announceSavedReview(subject, force);
2109
2165
  if (!session) return printHighLevelChecklist(subject);
2110
2166
  await openHighLevelOverlay(
@@ -3020,9 +3076,9 @@ function buildReviewPaths(repoRoot, key) {
3020
3076
  }
3021
3077
 
3022
3078
  // src/commands/review/fetchExistingComments.ts
3023
- import { execFileSync as execFileSync5 } from "child_process";
3079
+ import { execFileSync as execFileSync4 } from "child_process";
3024
3080
  function fetchRawComments(org, repo, prNumber) {
3025
- const out = execFileSync5(
3081
+ const out = execFileSync4(
3026
3082
  "gh",
3027
3083
  ["api", "--paginate", `repos/${org}/${repo}/pulls/${prNumber}/comments`],
3028
3084
  { encoding: "utf8", maxBuffer: 64 * 1024 * 1024 }
@@ -3087,11 +3143,11 @@ function logPriorComments(count) {
3087
3143
  import { execSync as execSync2 } from "child_process";
3088
3144
 
3089
3145
  // src/commands/review/fetchPrDiff.ts
3090
- import { execFileSync as execFileSync6 } from "child_process";
3146
+ import { execFileSync as execFileSync5 } from "child_process";
3091
3147
  function fetchPrDiff(prNumber, baseSha, headSha) {
3092
3148
  const { org, repo } = getRepoInfo();
3093
3149
  try {
3094
- return execFileSync6(
3150
+ return execFileSync5(
3095
3151
  "gh",
3096
3152
  ["pr", "diff", String(prNumber), "-R", `${org}/${repo}`],
3097
3153
  {
@@ -3110,19 +3166,19 @@ function isDiffTooLarge(error) {
3110
3166
  }
3111
3167
  function fetchDiffViaGit(baseSha, headSha) {
3112
3168
  try {
3113
- execFileSync6("git", ["fetch", "origin", baseSha, headSha], {
3169
+ execFileSync5("git", ["fetch", "origin", baseSha, headSha], {
3114
3170
  stdio: "ignore"
3115
3171
  });
3116
3172
  } catch {
3117
3173
  }
3118
- return execFileSync6("git", ["diff", `${baseSha}...${headSha}`], {
3174
+ return execFileSync5("git", ["diff", `${baseSha}...${headSha}`], {
3119
3175
  encoding: "utf8",
3120
3176
  maxBuffer: 256 * 1024 * 1024
3121
3177
  });
3122
3178
  }
3123
3179
 
3124
3180
  // src/commands/review/fetchPrDiffInfo.ts
3125
- import { execFileSync as execFileSync7, execSync } from "child_process";
3181
+ import { execFileSync as execFileSync6, execSync } from "child_process";
3126
3182
  function getCurrentBranch() {
3127
3183
  return execSync("git rev-parse --abbrev-ref HEAD", {
3128
3184
  encoding: "utf8"
@@ -3130,7 +3186,7 @@ function getCurrentBranch() {
3130
3186
  }
3131
3187
  var FIELDS = "number,baseRefName,baseRefOid,headRefName,headRefOid";
3132
3188
  function runGh(...args) {
3133
- return execFileSync7("gh", args, {
3189
+ return execFileSync6("gh", args, {
3134
3190
  encoding: "utf8",
3135
3191
  stdio: ["ignore", "pipe", "pipe"]
3136
3192
  });
@@ -3172,7 +3228,7 @@ function fetchPrDiffInfo() {
3172
3228
  }
3173
3229
  function fetchPrChangedFiles(prNumber) {
3174
3230
  const { org, repo } = getRepoInfo();
3175
- const out = execFileSync7(
3231
+ const out = execFileSync6(
3176
3232
  "gh",
3177
3233
  [
3178
3234
  "api",