@granular-software/fractory 0.0.0-stage → 0.1.24
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/LICENSE +4 -0
- package/README.md +28 -2
- package/dist/activity-volume.d.ts +18 -0
- package/dist/activity-volume.js +94 -0
- package/dist/annotations.d.ts +118 -0
- package/dist/annotations.js +304 -0
- package/dist/benchmark-cli.d.ts +1 -0
- package/dist/benchmark-cli.js +95 -0
- package/dist/benchmark-worker.d.ts +2 -0
- package/dist/benchmark-worker.js +22 -0
- package/dist/benchmarks.d.ts +19 -0
- package/dist/benchmarks.js +414 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +63 -0
- package/dist/block-cli.d.ts +1 -0
- package/dist/block-cli.js +88 -0
- package/dist/block-documents.d.ts +35 -0
- package/dist/block-documents.js +84 -0
- package/dist/change-impact.d.ts +55 -0
- package/dist/change-impact.js +223 -0
- package/dist/check-source.d.ts +2 -0
- package/dist/check-source.js +66 -0
- package/dist/checks-model.d.ts +64 -0
- package/dist/checks-model.js +36 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +359 -0
- package/dist/code-model.d.ts +38 -0
- package/dist/code-model.js +94 -0
- package/dist/code-store.d.ts +9 -0
- package/dist/code-store.js +79 -0
- package/dist/compare-artifact.d.ts +6 -0
- package/dist/compare-artifact.js +277 -0
- package/dist/compare.d.ts +81 -0
- package/dist/compare.js +291 -0
- package/dist/compiler.d.ts +10 -0
- package/dist/compiler.js +1083 -0
- package/dist/compose.d.ts +9 -0
- package/dist/compose.js +72 -0
- package/dist/core.d.ts +86 -0
- package/dist/core.js +206 -0
- package/dist/coverage-cli.d.ts +1 -0
- package/dist/coverage-cli.js +42 -0
- package/dist/declaration-sources.d.ts +3 -0
- package/dist/declaration-sources.js +51 -0
- package/dist/declared-graph.d.ts +3 -0
- package/dist/declared-graph.js +66 -0
- package/dist/display-name.d.ts +2 -0
- package/dist/display-name.js +8 -0
- package/dist/error-heat.d.ts +58 -0
- package/dist/error-heat.js +96 -0
- package/dist/evidence.d.ts +3 -0
- package/dist/evidence.js +68 -0
- package/dist/factory-graph.d.ts +4 -0
- package/dist/factory-graph.js +318 -0
- package/dist/factory-model.d.ts +97 -0
- package/dist/factory-model.js +1 -0
- package/dist/git-code.d.ts +47 -0
- package/dist/git-code.js +352 -0
- package/dist/git-refs.d.ts +4 -0
- package/dist/git-refs.js +37 -0
- package/dist/history-activity.d.ts +4 -0
- package/dist/history-activity.js +129 -0
- package/dist/history-churn.d.ts +36 -0
- package/dist/history-churn.js +302 -0
- package/dist/history-git.d.ts +21 -0
- package/dist/history-git.js +125 -0
- package/dist/history-ledger.d.ts +43 -0
- package/dist/history-ledger.js +450 -0
- package/dist/history-ownership.d.ts +10 -0
- package/dist/history-ownership.js +75 -0
- package/dist/history-source.d.ts +13 -0
- package/dist/history-source.js +100 -0
- package/dist/integrations-cli.d.ts +2 -0
- package/dist/integrations-cli.js +159 -0
- package/dist/issue-cache.d.ts +9 -0
- package/dist/issue-cache.js +68 -0
- package/dist/issue-cli.d.ts +1 -0
- package/dist/issue-cli.js +89 -0
- package/dist/issue-links.d.ts +15 -0
- package/dist/issue-links.js +125 -0
- package/dist/linear-issues.d.ts +19 -0
- package/dist/linear-issues.js +124 -0
- package/dist/local-runtime.d.ts +8 -0
- package/dist/local-runtime.js +59 -0
- package/dist/map-activity.d.ts +73 -0
- package/dist/map-activity.js +234 -0
- package/dist/map-model.d.ts +5 -0
- package/dist/map-model.js +166 -0
- package/dist/map-quality.d.ts +14 -0
- package/dist/map-quality.js +56 -0
- package/dist/mapping-coverage.d.ts +87 -0
- package/dist/mapping-coverage.js +404 -0
- package/dist/model.d.ts +182 -0
- package/dist/model.js +66 -0
- package/dist/operation-benchmark-worker.d.ts +2 -0
- package/dist/operation-benchmark-worker.js +60 -0
- package/dist/operation-benchmark.d.ts +29 -0
- package/dist/operation-benchmark.js +1 -0
- package/dist/otel-metrics.d.ts +21 -0
- package/dist/otel-metrics.js +146 -0
- package/dist/performance-model.d.ts +185 -0
- package/dist/performance-model.js +396 -0
- package/dist/product-map.d.ts +69 -0
- package/dist/product-map.js +168 -0
- package/dist/provider-access.cjs +207 -0
- package/dist/provider-access.d.cts +14 -0
- package/dist/reports-cli.d.ts +1 -0
- package/dist/reports-cli.js +111 -0
- package/dist/reports-model.d.ts +27 -0
- package/dist/reports-model.js +39 -0
- package/dist/reports.d.ts +23 -0
- package/dist/reports.js +223 -0
- package/dist/repository-map.d.ts +22 -0
- package/dist/repository-map.js +151 -0
- package/dist/resource-cache.d.ts +17 -0
- package/dist/resource-cache.js +65 -0
- package/dist/review-cli.d.ts +19 -0
- package/dist/review-cli.js +224 -0
- package/dist/review.d.ts +48 -0
- package/dist/review.js +289 -0
- package/dist/runtime-metrics.d.ts +26 -0
- package/dist/runtime-metrics.js +290 -0
- package/dist/scope.d.ts +12 -0
- package/dist/scope.js +94 -0
- package/dist/sentry-activity.d.ts +39 -0
- package/dist/sentry-activity.js +174 -0
- package/dist/sentry.d.ts +130 -0
- package/dist/sentry.js +369 -0
- package/dist/service-release.d.ts +16 -0
- package/dist/service-release.js +14 -0
- package/dist/setup-cli.d.ts +2 -0
- package/dist/setup-cli.js +52 -0
- package/dist/setup-kit.cjs +163 -0
- package/dist/setup-kit.d.cts +32 -0
- package/dist/source-index.d.ts +37 -0
- package/dist/source-index.js +166 -0
- package/dist/source-review-git.d.ts +7 -0
- package/dist/source-review-git.js +103 -0
- package/dist/source-review.d.ts +16 -0
- package/dist/source-review.js +493 -0
- package/dist/telemetry.d.ts +17 -0
- package/dist/telemetry.js +51 -0
- package/dist/time-window.d.ts +9 -0
- package/dist/time-window.js +35 -0
- package/dist/trace-evidence.d.ts +23 -0
- package/dist/trace-evidence.js +55 -0
- package/dist/trace-model.d.ts +26 -0
- package/dist/trace-model.js +1 -0
- package/dist/tracing.d.ts +44 -0
- package/dist/tracing.js +123 -0
- package/dist/work-check.d.ts +17 -0
- package/dist/work-check.js +110 -0
- package/dist/work-cli.d.ts +1 -0
- package/dist/work-cli.js +148 -0
- package/dist/work-context.d.ts +57 -0
- package/dist/work-context.js +568 -0
- package/dist/work-intents.d.ts +6 -0
- package/dist/work-intents.js +140 -0
- package/dist/work-items.d.ts +58 -0
- package/dist/work-items.js +86 -0
- package/dist/work-model.d.ts +110 -0
- package/dist/work-model.js +261 -0
- package/dist/work-review-git.d.ts +8 -0
- package/dist/work-review-git.js +111 -0
- package/dist/work-review.d.ts +26 -0
- package/dist/work-review.js +426 -0
- package/dist/work-switcher-model.d.ts +43 -0
- package/dist/work-switcher-model.js +79 -0
- package/dist/work-switcher.d.ts +6 -0
- package/dist/work-switcher.js +171 -0
- package/dist/working-cli.d.ts +1 -0
- package/dist/working-cli.js +33 -0
- package/dist/working-code.d.ts +74 -0
- package/dist/working-code.js +421 -0
- package/dist/workspace-notes.d.ts +71 -0
- package/dist/workspace-notes.js +177 -0
- package/dist/workspace-tests.d.ts +21 -0
- package/dist/workspace-tests.js +573 -0
- package/package.json +547 -4
- package/src/activity-volume.ts +149 -0
- package/src/annotations.ts +481 -0
- package/src/benchmark-cli.ts +118 -0
- package/src/benchmark-worker.ts +22 -0
- package/src/benchmarks.ts +493 -0
- package/src/bin.ts +54 -0
- package/src/block-cli.ts +106 -0
- package/src/block-documents.ts +117 -0
- package/src/change-impact.ts +280 -0
- package/src/check-source.ts +82 -0
- package/src/checks-model.ts +108 -0
- package/src/cli.ts +440 -0
- package/src/code-model.ts +159 -0
- package/src/code-store.ts +98 -0
- package/src/compare-artifact.ts +314 -0
- package/src/compare.ts +440 -0
- package/src/compiler.ts +1326 -0
- package/src/compose.ts +94 -0
- package/src/core.ts +357 -0
- package/src/coverage-cli.ts +52 -0
- package/src/declaration-sources.ts +69 -0
- package/src/declared-graph.ts +74 -0
- package/src/display-name.ts +8 -0
- package/src/error-heat.ts +161 -0
- package/src/evidence.ts +94 -0
- package/src/factory-graph.ts +378 -0
- package/src/factory-model.ts +73 -0
- package/src/git-code.ts +461 -0
- package/src/git-refs.ts +43 -0
- package/src/history-activity.ts +146 -0
- package/src/history-churn.ts +416 -0
- package/src/history-git.ts +163 -0
- package/src/history-ledger.ts +636 -0
- package/src/history-ownership.ts +116 -0
- package/src/history-source.ts +117 -0
- package/src/integrations-cli.ts +187 -0
- package/src/issue-cache.ts +96 -0
- package/src/issue-cli.ts +137 -0
- package/src/issue-links.ts +153 -0
- package/src/linear-issues.ts +154 -0
- package/src/local-runtime.ts +70 -0
- package/src/map-activity.ts +309 -0
- package/src/map-model.ts +213 -0
- package/src/map-quality.ts +61 -0
- package/src/mapping-coverage.ts +570 -0
- package/src/model.ts +221 -0
- package/src/operation-benchmark-worker.ts +60 -0
- package/src/operation-benchmark.ts +28 -0
- package/src/otel-metrics.ts +176 -0
- package/src/performance-model.ts +575 -0
- package/src/product-map.ts +236 -0
- package/src/provider-access.cjs +207 -0
- package/src/provider-access.d.cts +14 -0
- package/src/reports-cli.ts +125 -0
- package/src/reports-model.ts +73 -0
- package/src/reports.ts +276 -0
- package/src/repository-map.ts +189 -0
- package/src/resource-cache.ts +76 -0
- package/src/review-cli.ts +256 -0
- package/src/review.ts +376 -0
- package/src/runtime-metrics.ts +386 -0
- package/src/scope.ts +103 -0
- package/src/sentry-activity.ts +234 -0
- package/src/sentry.ts +545 -0
- package/src/service-release.ts +18 -0
- package/src/setup-cli.ts +58 -0
- package/src/setup-kit.cjs +163 -0
- package/src/setup-kit.d.cts +32 -0
- package/src/source-index.ts +205 -0
- package/src/source-review-git.ts +129 -0
- package/src/source-review.ts +637 -0
- package/src/telemetry.ts +68 -0
- package/src/time-window.ts +51 -0
- package/src/trace-evidence.ts +80 -0
- package/src/trace-model.ts +26 -0
- package/src/tracing.ts +165 -0
- package/src/work-check.ts +143 -0
- package/src/work-cli.ts +195 -0
- package/src/work-context.ts +713 -0
- package/src/work-intents.ts +196 -0
- package/src/work-items.ts +151 -0
- package/src/work-model.ts +400 -0
- package/src/work-review-git.ts +130 -0
- package/src/work-review.ts +573 -0
- package/src/work-switcher-model.ts +121 -0
- package/src/work-switcher.ts +191 -0
- package/src/working-cli.ts +38 -0
- package/src/working-code.ts +582 -0
- package/src/workspace-notes.ts +203 -0
- package/src/workspace-tests.ts +654 -0
- package/toolkit/GUIDE.md +305 -0
- package/toolkit/SKILL.md +131 -0
- package/toolkit/bin/fractory +2 -0
- package/toolkit/build.json +1 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { DefinitionGraph, SourceRef } from "./model.js";
|
|
2
|
+
import type { CodeSnapshot } from "./code-model.js";
|
|
3
|
+
export declare const sourceDigest: (text: string) => string;
|
|
4
|
+
/** Cheap freshness validation. Read each referenced file once; never rebase or bless a changed reference. */
|
|
5
|
+
export declare function staleSourceRefs(refs: readonly SourceRef[], read: (file: string) => string | undefined): {
|
|
6
|
+
file: string;
|
|
7
|
+
line: number;
|
|
8
|
+
reason: string;
|
|
9
|
+
}[];
|
|
10
|
+
/** Parse only source files named by the definition, once each. Never execute application code. */
|
|
11
|
+
export declare function indexSources(graph: DefinitionGraph, read: (file: string) => string | undefined, cache?: {
|
|
12
|
+
get: (key: string) => {
|
|
13
|
+
ranges: CodeSnapshot["files"][string]["ranges"];
|
|
14
|
+
gaps: CodeSnapshot["gaps"];
|
|
15
|
+
} | undefined;
|
|
16
|
+
put: (key: string, value: {
|
|
17
|
+
ranges: CodeSnapshot["files"][string]["ranges"];
|
|
18
|
+
gaps: CodeSnapshot["gaps"];
|
|
19
|
+
}) => void;
|
|
20
|
+
}, options?: {
|
|
21
|
+
resolveUniqueAnchors?: boolean;
|
|
22
|
+
}): {
|
|
23
|
+
files: Record<string, {
|
|
24
|
+
digest: string;
|
|
25
|
+
ranges: {
|
|
26
|
+
elementId: string;
|
|
27
|
+
start: number;
|
|
28
|
+
end: number;
|
|
29
|
+
basis: "syntax" | "anchor" | "file";
|
|
30
|
+
}[];
|
|
31
|
+
}>;
|
|
32
|
+
gaps: {
|
|
33
|
+
elementId: string;
|
|
34
|
+
file: string;
|
|
35
|
+
reason: string;
|
|
36
|
+
}[];
|
|
37
|
+
};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
export const sourceDigest = (text) => createHash("sha256").update(text).digest("hex").slice(0, 16);
|
|
4
|
+
const safeFile = (file) => !file.startsWith("/") &&
|
|
5
|
+
!file.split(/[\\/]/).includes("..") &&
|
|
6
|
+
!file.includes("\0");
|
|
7
|
+
/** Cheap freshness validation. Read each referenced file once; never rebase or bless a changed reference. */
|
|
8
|
+
export function staleSourceRefs(refs, read) {
|
|
9
|
+
const files = new Map();
|
|
10
|
+
const gaps = [];
|
|
11
|
+
for (const ref of refs) {
|
|
12
|
+
if (!safeFile(ref.file))
|
|
13
|
+
throw new Error("Source paths must be repository relative");
|
|
14
|
+
if (!files.has(ref.file)) {
|
|
15
|
+
const text = read(ref.file);
|
|
16
|
+
files.set(ref.file, {
|
|
17
|
+
text,
|
|
18
|
+
...(text === undefined
|
|
19
|
+
? {}
|
|
20
|
+
: { digest: sourceDigest(text), lines: text.split(/\r?\n/) }),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const file = files.get(ref.file);
|
|
24
|
+
const reason = file.text === undefined
|
|
25
|
+
? "Source file unavailable"
|
|
26
|
+
: file.digest !== ref.digest
|
|
27
|
+
? "Source changed since review"
|
|
28
|
+
: !file.lines?.[ref.line - 1]?.includes(ref.symbol || "")
|
|
29
|
+
? "Source anchor moved or disappeared"
|
|
30
|
+
: undefined;
|
|
31
|
+
if (reason)
|
|
32
|
+
gaps.push({ file: ref.file, line: ref.line, reason });
|
|
33
|
+
}
|
|
34
|
+
return gaps;
|
|
35
|
+
}
|
|
36
|
+
/** Parse only source files named by the definition, once each. Never execute application code. */
|
|
37
|
+
export function indexSources(graph, read, cache, options = {}) {
|
|
38
|
+
const files = {}, gaps = [];
|
|
39
|
+
const refs = new Map();
|
|
40
|
+
for (const element of graph.elements) {
|
|
41
|
+
for (const ref of element.sources ||
|
|
42
|
+
(element.source ? [element.source] : [])) {
|
|
43
|
+
if (!safeFile(ref.file))
|
|
44
|
+
throw new Error("Source paths must be repository relative");
|
|
45
|
+
const list = refs.get(ref.file) || [];
|
|
46
|
+
list.push({ elementId: element.id, ref });
|
|
47
|
+
refs.set(ref.file, list);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
for (const [file, owners] of refs) {
|
|
51
|
+
const text = read(file);
|
|
52
|
+
if (text === undefined) {
|
|
53
|
+
for (const o of owners)
|
|
54
|
+
gaps.push({
|
|
55
|
+
elementId: o.elementId,
|
|
56
|
+
file,
|
|
57
|
+
reason: "Source file unavailable",
|
|
58
|
+
});
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const digest = sourceDigest(text);
|
|
62
|
+
const key = createHash("sha256")
|
|
63
|
+
.update(JSON.stringify({ version: 5, file, digest, owners, options }))
|
|
64
|
+
.digest("hex");
|
|
65
|
+
const saved = cache?.get(key);
|
|
66
|
+
if (saved) {
|
|
67
|
+
files[file] = { digest, ranges: saved.ranges };
|
|
68
|
+
gaps.push(...saved.gaps);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const gapStart = gaps.length;
|
|
72
|
+
const sf = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true);
|
|
73
|
+
const nodes = [];
|
|
74
|
+
const visit = (node) => {
|
|
75
|
+
if ((ts.isStatement(node) && !ts.isBlock(node)) ||
|
|
76
|
+
ts.isFunctionDeclaration(node) ||
|
|
77
|
+
ts.isMethodDeclaration(node) ||
|
|
78
|
+
ts.isClassDeclaration(node) ||
|
|
79
|
+
ts.isVariableDeclaration(node) ||
|
|
80
|
+
ts.isExpressionStatement(node) ||
|
|
81
|
+
ts.isPropertyDeclaration(node))
|
|
82
|
+
nodes.push(node);
|
|
83
|
+
ts.forEachChild(node, visit);
|
|
84
|
+
};
|
|
85
|
+
visit(sf);
|
|
86
|
+
const ranges = [];
|
|
87
|
+
for (const { elementId, ref } of owners) {
|
|
88
|
+
const shifted = digest !== ref.digest &&
|
|
89
|
+
options.resolveUniqueAnchors &&
|
|
90
|
+
ref.symbol &&
|
|
91
|
+
text.indexOf(ref.symbol) >= 0 &&
|
|
92
|
+
text.indexOf(ref.symbol, text.indexOf(ref.symbol) + ref.symbol.length) <
|
|
93
|
+
0;
|
|
94
|
+
if (digest !== ref.digest) {
|
|
95
|
+
gaps.push({
|
|
96
|
+
elementId,
|
|
97
|
+
file,
|
|
98
|
+
reason: "Source changed since this definition was reviewed",
|
|
99
|
+
});
|
|
100
|
+
if (!shifted)
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (ref.scope === "file") {
|
|
104
|
+
if (ref.line !== 1 || ref.symbol) {
|
|
105
|
+
gaps.push({
|
|
106
|
+
elementId,
|
|
107
|
+
file,
|
|
108
|
+
reason: "Invalid whole-module source reference",
|
|
109
|
+
});
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
ranges.push({
|
|
113
|
+
elementId,
|
|
114
|
+
start: 1,
|
|
115
|
+
end: sf.getLineStarts().length,
|
|
116
|
+
basis: "file",
|
|
117
|
+
});
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const anchorLine = shifted
|
|
121
|
+
? sf.getLineAndCharacterOfPosition(text.indexOf(ref.symbol)).line + 1
|
|
122
|
+
: ref.line;
|
|
123
|
+
if (anchorLine < 1 || anchorLine > sf.getLineStarts().length) {
|
|
124
|
+
gaps.push({ elementId, file, reason: "Source line unavailable" });
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const offset = sf.getPositionOfLineAndCharacter(anchorLine - 1, 0);
|
|
128
|
+
const lineEnd = sf.getLineStarts()[anchorLine] ?? text.length;
|
|
129
|
+
const indentation = Math.max(0, text.slice(offset, lineEnd).search(/\S/));
|
|
130
|
+
const position = shifted
|
|
131
|
+
? text.indexOf(ref.symbol)
|
|
132
|
+
: ref.symbol
|
|
133
|
+
? text.indexOf(ref.symbol, offset)
|
|
134
|
+
: offset + indentation;
|
|
135
|
+
// An anchor must occur on the reviewed line; never move it silently to another occurrence.
|
|
136
|
+
if (position < 0 ||
|
|
137
|
+
(!shifted &&
|
|
138
|
+
sf.getLineAndCharacterOfPosition(position).line + 1 !== ref.line)) {
|
|
139
|
+
gaps.push({
|
|
140
|
+
elementId,
|
|
141
|
+
file,
|
|
142
|
+
reason: "Reviewed source anchor unavailable",
|
|
143
|
+
});
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const node = nodes
|
|
147
|
+
.filter((n) => n.getStart(sf) <= position && n.getEnd() > position)
|
|
148
|
+
.sort((a, b) => a.getEnd() - a.getStart(sf) - (b.getEnd() - b.getStart(sf)))[0];
|
|
149
|
+
const start = node
|
|
150
|
+
? sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1
|
|
151
|
+
: anchorLine;
|
|
152
|
+
const end = node
|
|
153
|
+
? sf.getLineAndCharacterOfPosition(node.getEnd() - 1).line + 1
|
|
154
|
+
: anchorLine;
|
|
155
|
+
ranges.push({
|
|
156
|
+
elementId,
|
|
157
|
+
start,
|
|
158
|
+
end,
|
|
159
|
+
basis: shifted ? "anchor" : node ? "syntax" : "anchor",
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
files[file] = { digest, ranges };
|
|
163
|
+
cache?.put(key, { ranges, gaps: gaps.slice(gapStart) });
|
|
164
|
+
}
|
|
165
|
+
return { files, gaps };
|
|
166
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DefinitionGraph } from "./model.js";
|
|
2
|
+
import { type SourceArea } from "./source-review.js";
|
|
3
|
+
export declare function readMapSources(root: string, definition: DefinitionGraph, areas: SourceArea[], ref?: string): {
|
|
4
|
+
files: Map<string, string>;
|
|
5
|
+
revision: string | undefined;
|
|
6
|
+
};
|
|
7
|
+
export declare function revisionSourceMap(root: string, definition: DefinitionGraph, areas: SourceArea[], ref: string): DefinitionGraph;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/** Bounded source reads. Git blobs are read in batches; no checkout or compiler process. */
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import { readFileSync, realpathSync, statSync } from "node:fs";
|
|
4
|
+
import { resolve, sep } from "node:path";
|
|
5
|
+
import { readGit, resolveComparisonRef } from "./git-refs.js";
|
|
6
|
+
import { sourceReviewMap } from "./source-review.js";
|
|
7
|
+
export function readMapSources(root, definition, areas, ref) {
|
|
8
|
+
const revision = ref ? resolveComparisonRef(root, ref) : undefined;
|
|
9
|
+
const paths = (revision
|
|
10
|
+
? readGit(root, ["ls-tree", "-r", "--name-only", "-z", revision])
|
|
11
|
+
: readGit(root, [
|
|
12
|
+
"ls-files",
|
|
13
|
+
"--cached",
|
|
14
|
+
"--others",
|
|
15
|
+
"--exclude-standard",
|
|
16
|
+
"-z",
|
|
17
|
+
]))
|
|
18
|
+
.split("\0")
|
|
19
|
+
.filter(Boolean);
|
|
20
|
+
const known = new Set([
|
|
21
|
+
...definition.elements.flatMap((n) => (n.sources || (n.source ? [n.source] : [])).map((s) => s.file)),
|
|
22
|
+
...definition.tests.map((test) => test.source.file),
|
|
23
|
+
]);
|
|
24
|
+
const selected = [
|
|
25
|
+
...new Set(paths.filter((p) => /\.[cm]?[jt]sx?$/.test(p) &&
|
|
26
|
+
!/[\n\r]/.test(p) &&
|
|
27
|
+
!p.startsWith("/") &&
|
|
28
|
+
!p.split("/").includes("..") &&
|
|
29
|
+
(known.has(p) ||
|
|
30
|
+
areas.some((a) => a.matches(p)) ||
|
|
31
|
+
(/\.(?:test|spec|vitest)\.[cm]?[jt]sx?$/.test(p) &&
|
|
32
|
+
areas.some((area) => area.matches(p
|
|
33
|
+
.replace(/\/(?:__tests__|tests|test)\//g, "/")
|
|
34
|
+
.replace(/\.(?:test|spec|vitest)(\.[cm]?[jt]sx?)$/, "$1"))))))),
|
|
35
|
+
].sort();
|
|
36
|
+
if (selected.length > 2500)
|
|
37
|
+
throw Error("Source review exceeded 2,500 files; narrow the capability rules.");
|
|
38
|
+
const files = new Map();
|
|
39
|
+
let bytes = 0;
|
|
40
|
+
for (let at = 0; at < selected.length; at += 64) {
|
|
41
|
+
const batch = selected.slice(at, at + 64);
|
|
42
|
+
if (revision) {
|
|
43
|
+
const output = execFileSync("git", ["cat-file", "--batch"], {
|
|
44
|
+
cwd: root,
|
|
45
|
+
input: batch.map((p) => `${revision}:${p}\n`).join(""),
|
|
46
|
+
timeout: 15000,
|
|
47
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
48
|
+
});
|
|
49
|
+
let offset = 0;
|
|
50
|
+
for (const file of batch) {
|
|
51
|
+
const end = output.indexOf(10, offset);
|
|
52
|
+
if (end < 0)
|
|
53
|
+
throw Error("Incomplete Git source batch");
|
|
54
|
+
const header = output.subarray(offset, end).toString();
|
|
55
|
+
offset = end + 1;
|
|
56
|
+
if (header.endsWith(" missing"))
|
|
57
|
+
continue;
|
|
58
|
+
const [, type, sizeText] = header.split(" "), size = Number(sizeText);
|
|
59
|
+
if (type !== "blob" ||
|
|
60
|
+
!Number.isSafeInteger(size) ||
|
|
61
|
+
size < 0 ||
|
|
62
|
+
offset + size > output.length)
|
|
63
|
+
throw Error("Invalid Git source blob");
|
|
64
|
+
if (size <= 1024 * 1024)
|
|
65
|
+
files.set(file, output.subarray(offset, offset + size).toString());
|
|
66
|
+
offset += size + 1;
|
|
67
|
+
bytes += size;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const base = realpathSync(root);
|
|
72
|
+
for (const file of batch)
|
|
73
|
+
try {
|
|
74
|
+
const absolute = realpathSync(resolve(root, file));
|
|
75
|
+
if (!absolute.startsWith(base + sep) ||
|
|
76
|
+
statSync(absolute).size > 1024 * 1024)
|
|
77
|
+
continue;
|
|
78
|
+
const text = readFileSync(absolute, "utf8");
|
|
79
|
+
bytes += Buffer.byteLength(text);
|
|
80
|
+
files.set(file, text);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
/* Missing working-tree sources are not silently invented. */
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (bytes > 32 * 1024 * 1024)
|
|
87
|
+
throw Error("Source review exceeded its 32MB read budget.");
|
|
88
|
+
}
|
|
89
|
+
return { files, revision };
|
|
90
|
+
}
|
|
91
|
+
const revisions = new Map();
|
|
92
|
+
export function revisionSourceMap(root, definition, areas, ref) {
|
|
93
|
+
const revision = resolveComparisonRef(root, ref), key = `${root}:${definition.revision}:${revision}`;
|
|
94
|
+
const cached = revisions.get(key);
|
|
95
|
+
if (cached)
|
|
96
|
+
return cached;
|
|
97
|
+
const source = readMapSources(root, definition, areas, revision);
|
|
98
|
+
const graph = sourceReviewMap(definition, source.files, areas, revision);
|
|
99
|
+
revisions.set(key, graph);
|
|
100
|
+
if (revisions.size > 4)
|
|
101
|
+
revisions.delete(revisions.keys().next().value);
|
|
102
|
+
return graph;
|
|
103
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DefinitionGraph } from "./model.js";
|
|
2
|
+
export interface SourceArea {
|
|
3
|
+
id: string;
|
|
4
|
+
parent: string;
|
|
5
|
+
/** Retain a source namespace when its logical parts are regrouped. */
|
|
6
|
+
identityRoot?: string;
|
|
7
|
+
label: string;
|
|
8
|
+
description: string;
|
|
9
|
+
kind?: "block" | "interface";
|
|
10
|
+
/** False records module ownership only; annotated interactions remain authoritative. */
|
|
11
|
+
discoverMethods?: boolean;
|
|
12
|
+
matches: (file: string) => boolean;
|
|
13
|
+
/** Explicit import aliases supplied by the repository adapter; never guessed. */
|
|
14
|
+
aliases?: Record<string, string>;
|
|
15
|
+
}
|
|
16
|
+
export declare function sourceReviewMap(definition: DefinitionGraph, files: Map<string, string>, areas: SourceArea[], revision?: string): DefinitionGraph;
|