@davesheffer/hunch 1.18.1 → 1.19.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.
@@ -0,0 +1,40 @@
1
+ import { correctionStagePathPattern, inferIssueCorrectionStage, } from "../core/correctionStage.js";
2
+ import { compareCodeUnits } from "../core/canonicalOrder.js";
3
+ import { repoSourceInventory } from "./repoSource.js";
4
+ const SOURCE_FILE_LIMIT = 4_000;
5
+ const SOURCE_BYTE_LIMIT = 64 * 1024 * 1024;
6
+ /** Safely read a bounded working-tree TypeScript corpus. Stage-relevant paths
7
+ * are read first so a huge repository cannot crowd the likely correction layer
8
+ * out of the fixed source budget. */
9
+ export function collectCorrectionStageSources(root, issue) {
10
+ const pattern = correctionStagePathPattern(inferIssueCorrectionStage(issue), issue);
11
+ const eligible = repoSourceInventory(root, { kind: "working" }).entries
12
+ .filter((entry) => /^[A-Za-z0-9._/-]+\.tsx?$/.test(entry.path)
13
+ && !/(?:^|\/)(?:tests?|__tests__)(?:\/|$)|\.test\.tsx?$/.test(entry.path))
14
+ .sort((a, b) => Number(pattern.test(b.path)) - Number(pattern.test(a.path)) || compareCodeUnits(a.path, b.path));
15
+ const attempted = eligible.slice(0, SOURCE_FILE_LIMIT);
16
+ const sources = [];
17
+ let bytesRead = 0;
18
+ let filesSkipped = eligible.length - attempted.length;
19
+ for (const entry of attempted) {
20
+ const read = entry.read();
21
+ if (read.source === null) {
22
+ filesSkipped++;
23
+ continue;
24
+ }
25
+ const bytes = Buffer.byteLength(read.source, "utf8");
26
+ if (bytesRead + bytes > SOURCE_BYTE_LIMIT) {
27
+ filesSkipped++;
28
+ continue;
29
+ }
30
+ sources.push({ path: entry.path, content: read.source });
31
+ bytesRead += bytes;
32
+ }
33
+ return {
34
+ sources,
35
+ files_read: sources.length,
36
+ bytes_read: bytesRead,
37
+ files_skipped: filesSkipped,
38
+ };
39
+ }
40
+ //# sourceMappingURL=correctionSources.js.map