weavatrix 0.1.0 → 0.1.2
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/README.md +59 -18
- package/SECURITY.md +31 -0
- package/package.json +16 -4
- package/skill/SKILL.md +16 -10
- package/src/analysis/coverage-reports.js +14 -11
- package/src/analysis/dead-check.js +7 -2
- package/src/analysis/duplicates.compute.js +221 -215
- package/src/analysis/duplicates.js +15 -15
- package/src/analysis/duplicates.run.js +52 -51
- package/src/analysis/duplicates.tokenize.js +182 -182
- package/src/analysis/endpoints.js +5 -3
- package/src/analysis/graph-analysis.aggregate.js +5 -1
- package/src/analysis/internal-audit.collect.js +37 -11
- package/src/analysis/internal-audit.run.js +8 -5
- package/src/build-graph.js +2 -1
- package/src/child-env.js +7 -0
- package/src/graph/internal-builder.build.js +6 -3
- package/src/graph/internal-builder.langs.js +17 -6
- package/src/graph/internal-builder.resolvers.js +10 -3
- package/src/mcp/catalog.mjs +9 -7
- package/src/mcp/graph-context.mjs +8 -5
- package/src/mcp/sync-payload.mjs +102 -0
- package/src/mcp/tools-actions.mjs +22 -13
- package/src/mcp/tools-impact.mjs +3 -2
- package/src/mcp-rg.mjs +2 -1
- package/src/mcp-server.mjs +26 -17
- package/src/mcp-source-tools.mjs +16 -5
- package/src/process.js +4 -3
- package/src/repo-path.js +53 -0
- package/src/security/installed.js +44 -31
- package/src/security/malware-heuristics.exclusions.js +134 -134
- package/src/security/malware-heuristics.js +15 -15
- package/src/security/malware-heuristics.roots.js +142 -142
- package/src/security/malware-heuristics.scan.js +85 -85
- package/src/security/malware-heuristics.sweep.js +122 -122
|
@@ -1,215 +1,221 @@
|
|
|
1
|
-
// duplicates.compute.js — fragment extraction, inverted-index pairing, and the computeDuplicates
|
|
2
|
-
// pipeline (split from duplicates.js; see the facade there for the full algorithm overview).
|
|
3
|
-
import { readFileSync, readdirSync } from "node:fs";
|
|
4
|
-
import { join, extname } from "node:path";
|
|
5
|
-
import { isTestPath } from "../graph/graph-filter.js";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
a.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (s
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
for (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
arr.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
// symbol
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
//
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
1
|
+
// duplicates.compute.js — fragment extraction, inverted-index pairing, and the computeDuplicates
|
|
2
|
+
// pipeline (split from duplicates.js; see the facade there for the full algorithm overview).
|
|
3
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
4
|
+
import { join, extname } from "node:path";
|
|
5
|
+
import { isTestPath } from "../graph/graph-filter.js";
|
|
6
|
+
import { createRepoBoundary } from "../repo-path.js";
|
|
7
|
+
import { stripNonCode, bodyEndLineCount, tokenize, fingerprints, extractLargeStrings } from "./duplicates.tokenize.js";
|
|
8
|
+
|
|
9
|
+
const FLOOR_TOKENS = 30; // fragments below this never enter the index (UI slider min)
|
|
10
|
+
const FLOOR_SIM = 0.5; // pairs below this are not reported (UI slider min)
|
|
11
|
+
const MAX_BODY_LINES = 400;
|
|
12
|
+
// File types with no code SYMBOLS to fragment (stylesheets, markup, docs, single-file components). The
|
|
13
|
+
// user still wants them clone-checked ("check the frontend / md too"), so each is sliced into fixed line
|
|
14
|
+
// WINDOWS and each window is fingerprinted like a function body — a duplicated CSS rule block / HTML
|
|
15
|
+
// section / doc passage then clones the same way.
|
|
16
|
+
const WINDOW_EXTS = /\.(css|scss|sass|less|styl|html?|md|markdown|mdx|vue|svelte|astro)$/i;
|
|
17
|
+
const WINDOW_LINES = 24; // non-overlapping block size for windowed files
|
|
18
|
+
// Asset files are DEDUP-ONLY — they are NOT put in the code graph (that would score md/css as fake
|
|
19
|
+
// "methods" in Health and clutter the GUI board), so the clone scanner finds them by walking the repo.
|
|
20
|
+
const WALK_SKIP = new Set(["node_modules", ".git", "dist", "build", "coverage", "vendor", "weavatrix-graphs", ".next", "out", "__pycache__", ".venv", "venv", "site-packages"]);
|
|
21
|
+
const MAX_ASSET_FILES = 4000;
|
|
22
|
+
function walkAssets(root, dir, acc, depth) {
|
|
23
|
+
if (depth > 40 || acc.length >= MAX_ASSET_FILES) return acc;
|
|
24
|
+
let entries; try { entries = readdirSync(dir, { withFileTypes: true }); } catch { return acc; }
|
|
25
|
+
for (const e of entries) {
|
|
26
|
+
if (acc.length >= MAX_ASSET_FILES) break;
|
|
27
|
+
if (e.name.startsWith(".") || WALK_SKIP.has(e.name)) continue;
|
|
28
|
+
const full = join(dir, e.name);
|
|
29
|
+
if (e.isDirectory()) walkAssets(root, full, acc, depth + 1);
|
|
30
|
+
else if (WINDOW_EXTS.test(e.name)) acc.push(full.slice(root.length + 1).replace(/\\/g, "/"));
|
|
31
|
+
}
|
|
32
|
+
return acc;
|
|
33
|
+
}
|
|
34
|
+
// Fingerprints shared by MORE than this many fragments are ubiquitous boilerplate and are excluded
|
|
35
|
+
// from BOTH the shared count AND the union (so jaccard stays honest — see pairsForMode). Set well
|
|
36
|
+
// above realistic clone multiplicity: N byte-identical copies each put all their fingerprints in
|
|
37
|
+
// buckets of size N, so the cap must exceed N or the whole clone family is invisible. 120 covers all
|
|
38
|
+
// but pathological mass-duplication; the O(n²) pair work per bucket stays bounded by it.
|
|
39
|
+
const BUCKET_CAP = 120;
|
|
40
|
+
// A clone must share at least this many DISTINCT (non-ubiquitous) fingerprints. Winnowing collapses a
|
|
41
|
+
// UNIFORM repetitive body (a constant table where every line is `KEY: 'VALUE',` → renamed `I: <str>`) to a
|
|
42
|
+
// handful of fingerprints, so two UNRELATED such tables hit 100% renamed Jaccard on ~3-6 shared fingerprints
|
|
43
|
+
// — "same shape, zero shared content". Requiring real shared evidence drops those false positives while a
|
|
44
|
+
// genuine clone (which shares dozens of fingerprints) is untouched.
|
|
45
|
+
const MIN_SHARED_FP = 8;
|
|
46
|
+
|
|
47
|
+
// Same-name symbols across DIFFERENT files — the semantic complement to token clones. A token clone
|
|
48
|
+
// says "same body"; a name twin with LOW similarity says "same name, different behavior" — the
|
|
49
|
+
// drift-hazard class of duplicate (three divergent uniqueStrings() implementations) that jaccard
|
|
50
|
+
// ranks too low to surface. OOP-generic lifecycle names are stoplisted; interface implementations
|
|
51
|
+
// still appear, so the caller's report keeps neutral wording.
|
|
52
|
+
const TWIN_STOP = new Set(["constructor", "tostring", "valueof", "dispose", "close", "render", "setup", "teardown", "initialize", "destroy", "connect", "disconnect", "update", "reset", "clear", "create", "handle", "execute", "invoke", "main", "start", "stop", "build", "parse", "value", "index"]);
|
|
53
|
+
function computeNameTwins(frags) {
|
|
54
|
+
const byName = new Map();
|
|
55
|
+
frags.forEach((f, i) => {
|
|
56
|
+
if (f.kind === "string") return;
|
|
57
|
+
const name = String(f.label || "").trim().replace(/\(\)$/, "");
|
|
58
|
+
if (name.length < 5 || !/^[A-Za-z_$][\w$]*$/.test(name) || TWIN_STOP.has(name.toLowerCase())) return;
|
|
59
|
+
const key = name.toLowerCase();
|
|
60
|
+
let a = byName.get(key); if (!a) byName.set(key, (a = []));
|
|
61
|
+
a.push(i);
|
|
62
|
+
});
|
|
63
|
+
const jac = (A, B) => { let inter = 0; for (const h of A) if (B.has(h)) inter++; const u = A.size + B.size - inter; return u ? inter / u : 0; };
|
|
64
|
+
const out = [];
|
|
65
|
+
for (const idxs of byName.values()) {
|
|
66
|
+
const files = new Set(idxs.map((i) => frags[i].file));
|
|
67
|
+
if (files.size < 2 || idxs.length > 12) continue; // single-file overloads / framework-name explosions
|
|
68
|
+
let simMin = 1, simMax = 0;
|
|
69
|
+
for (let a = 0; a < idxs.length; a++) for (let b = a + 1; b < idxs.length; b++) {
|
|
70
|
+
if (frags[idxs[a]].file === frags[idxs[b]].file) continue;
|
|
71
|
+
const s = jac(frags[idxs[a]].fp.renamed, frags[idxs[b]].fp.renamed);
|
|
72
|
+
if (s < simMin) simMin = s;
|
|
73
|
+
if (s > simMax) simMax = s;
|
|
74
|
+
}
|
|
75
|
+
out.push({
|
|
76
|
+
label: String(frags[idxs[0]].label || "").replace(/\(\)$/, ""), members: idxs, files: files.size,
|
|
77
|
+
simMin: Math.round(simMin * 100), simMax: Math.round(simMax * 100),
|
|
78
|
+
tokens: idxs.reduce((n, i) => n + frags[i].n, 0),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return out.sort((x, y) => y.tokens - x.tokens).slice(0, 200);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function pairsForMode(frags, mode) {
|
|
85
|
+
const index = new Map();
|
|
86
|
+
frags.forEach((f, i) => { for (const h of f.fp[mode]) { let a = index.get(h); if (!a) index.set(h, (a = [])); a.push(i); } });
|
|
87
|
+
// eff[i] = count of i's fingerprints that sit in NON-ubiquitous buckets. Jaccard's numerator (shared)
|
|
88
|
+
// and denominator (union) are BOTH computed over this same restricted set, so excluding a boilerplate
|
|
89
|
+
// fingerprint never deflates similarity — two real clones sharing a widely-repeated preamble still
|
|
90
|
+
// pair at 100% on their unique bodies, and the sim is a true jaccard, not an under-count.
|
|
91
|
+
const eff = new Array(frags.length).fill(0);
|
|
92
|
+
const shared = new Map();
|
|
93
|
+
for (const arr of index.values()) {
|
|
94
|
+
if (arr.length > BUCKET_CAP) continue; // ubiquitous k-gram → excluded from count AND size (both sides)
|
|
95
|
+
for (const idx of arr) eff[idx]++;
|
|
96
|
+
for (let a = 0; a < arr.length; a++) for (let b = a + 1; b < arr.length; b++) {
|
|
97
|
+
const key = arr[a] * 1000000 + arr[b]; // frag count is bounded way below 1e6
|
|
98
|
+
shared.set(key, (shared.get(key) || 0) + 1);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const pairs = [];
|
|
102
|
+
for (const [key, count] of shared) {
|
|
103
|
+
const i = Math.floor(key / 1000000), j = key % 1000000;
|
|
104
|
+
const union = eff[i] + eff[j] - count;
|
|
105
|
+
const sim = union > 0 ? count / union : 0;
|
|
106
|
+
if (sim >= FLOOR_SIM && count >= MIN_SHARED_FP) pairs.push([i, j, Math.round(sim * 100)]);
|
|
107
|
+
}
|
|
108
|
+
return pairs;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Parse "L<line>" graph symbol locations into per-file ordered symbol lists.
|
|
112
|
+
function symbolRanges(graph) {
|
|
113
|
+
const byFile = new Map();
|
|
114
|
+
for (const n of graph.nodes || []) {
|
|
115
|
+
if (!n.source_file || !String(n.id || "").includes("#")) continue;
|
|
116
|
+
const line = Number((String(n.source_location || "").match(/L(\d+)/) || [])[1] || 0);
|
|
117
|
+
if (!line) continue;
|
|
118
|
+
let arr = byFile.get(n.source_file);
|
|
119
|
+
if (!arr) byFile.set(n.source_file, (arr = []));
|
|
120
|
+
arr.push({ id: n.id, label: n.label || n.id, line });
|
|
121
|
+
}
|
|
122
|
+
for (const arr of byFile.values()) arr.sort((a, b) => a.line - b.line);
|
|
123
|
+
return byFile;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function computeDuplicates(repoPath, graphJsonPath, opts = {}) {
|
|
127
|
+
const includeStrings = !!opts.includeStrings;
|
|
128
|
+
const graph = JSON.parse(readFileSync(graphJsonPath, "utf8"));
|
|
129
|
+
const byFile = symbolRanges(graph);
|
|
130
|
+
// total symbol nodes in the graph — 0 means a file-only graph (built by an older builder before
|
|
131
|
+
// symbol extraction, or a stale graph): clone detection has nothing to work with, and the UI must
|
|
132
|
+
// say "rebuild the graph" instead of the misleading "no clones at these thresholds".
|
|
133
|
+
let graphSymbols = 0;
|
|
134
|
+
for (const arr of byFile.values()) graphSymbols += arr.length;
|
|
135
|
+
const frags = [];
|
|
136
|
+
const boundary = createRepoBoundary(repoPath);
|
|
137
|
+
for (const [file, syms] of byFile) {
|
|
138
|
+
const resolved = boundary.resolve(file);
|
|
139
|
+
if (!resolved.ok) continue;
|
|
140
|
+
const full = resolved.path;
|
|
141
|
+
let lines;
|
|
142
|
+
try { lines = readFileSync(full, "utf8").split(/\r?\n/); } catch { continue; }
|
|
143
|
+
const py = /\.py$/i.test(file);
|
|
144
|
+
for (let i = 0; i < syms.length; i++) {
|
|
145
|
+
const start = syms[i].line;
|
|
146
|
+
// hard cap first (next symbol, or EOF, whichever comes first, ≤ MAX_BODY_LINES) …
|
|
147
|
+
const hardEnd = Math.min(i + 1 < syms.length ? syms[i + 1].line - 1 : lines.length, start + MAX_BODY_LINES);
|
|
148
|
+
if (hardEnd - start < 2) continue; // one-liners can't be meaningful clones
|
|
149
|
+
// … then shrink to where the construct actually closes, so the last symbol doesn't absorb
|
|
150
|
+
// trailing module-level code (module.exports tables, main() calls) up to EOF.
|
|
151
|
+
const bodyLines = lines.slice(start - 1, hardEnd);
|
|
152
|
+
const body = bodyLines.slice(0, bodyEndLineCount(bodyLines, py));
|
|
153
|
+
const end = start + body.length - 1;
|
|
154
|
+
if (end - start < 2) continue;
|
|
155
|
+
const toks = tokenize(stripNonCode(body.join("\n"), py));
|
|
156
|
+
if (toks.strict.length < FLOOR_TOKENS) continue;
|
|
157
|
+
frags.push({
|
|
158
|
+
id: syms[i].id, label: syms[i].label, file, start, end,
|
|
159
|
+
n: toks.strict.length,
|
|
160
|
+
test: isTestPath(file),
|
|
161
|
+
fp: { strict: fingerprints(toks.strict), renamed: fingerprints(toks.renamed) },
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
// ---- opt-in: large multi-line string literals as their own fragments. The code pass above strips
|
|
165
|
+
// string bodies (correctly — content isn't code), which makes embedded DSL templates (inline
|
|
166
|
+
// C#/SQL/PowerShell) invisible to clone detection. Tokenized RAW: the content IS the payload.
|
|
167
|
+
if (includeStrings) {
|
|
168
|
+
const base = file.split("/").pop();
|
|
169
|
+
const pushStr = (startLine, endLine, content) => {
|
|
170
|
+
const toks = tokenize(content);
|
|
171
|
+
if (toks.strict.length < FLOOR_TOKENS) return;
|
|
172
|
+
frags.push({
|
|
173
|
+
id: `${file}#str@${startLine}`, label: `${base}:${startLine} ~${endLine - startLine + 1}-line string`,
|
|
174
|
+
file, start: startLine, end: endLine, n: toks.strict.length, test: isTestPath(file), kind: "string",
|
|
175
|
+
fp: { strict: fingerprints(toks.strict), renamed: fingerprints(toks.renamed) },
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
for (const str of extractLargeStrings(lines.join("\n"), { py, cs: /\.cs$/i.test(file) })) {
|
|
179
|
+
const strLines = str.content.split(/\r?\n/).slice(0, MAX_BODY_LINES);
|
|
180
|
+
// A SECTION shared between two big templates dilutes below the similarity floor when the whole
|
|
181
|
+
// literals are compared (70 shared lines inside 220- and 107-line strings ≈ 27% jaccard). Big
|
|
182
|
+
// literals therefore get the same WINDOW treatment as CSS/HTML files; small ones stay whole.
|
|
183
|
+
if (strLines.length <= WINDOW_LINES * 2) {
|
|
184
|
+
pushStr(str.start, str.start + strLines.length - 1, strLines.join("\n"));
|
|
185
|
+
} else {
|
|
186
|
+
for (let off = 0; off < strLines.length; off += WINDOW_LINES) {
|
|
187
|
+
const chunk = strLines.slice(off, off + WINDOW_LINES);
|
|
188
|
+
if (chunk.length < 3) break;
|
|
189
|
+
pushStr(str.start + off, str.start + off + chunk.length - 1, chunk.join("\n"));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// ---- windowed fragments for symbol-less file types (CSS/HTML/MD/…), found by walking the repo (NOT the
|
|
196
|
+
// graph — assets are dedup-only). Each file is sliced into WINDOW_LINES blocks and fingerprinted.
|
|
197
|
+
const symFiles = new Set(byFile.keys());
|
|
198
|
+
for (const file of walkAssets(repoPath, repoPath, [], 0)) {
|
|
199
|
+
if (symFiles.has(file)) continue;
|
|
200
|
+
const resolved = boundary.resolve(file);
|
|
201
|
+
if (!resolved.ok) continue;
|
|
202
|
+
let lines;
|
|
203
|
+
try { lines = readFileSync(resolved.path, "utf8").split(/\r?\n/); } catch { continue; }
|
|
204
|
+
for (let start = 1; start <= lines.length; start += WINDOW_LINES) {
|
|
205
|
+
const end = Math.min(start + WINDOW_LINES - 1, lines.length);
|
|
206
|
+
if (end - start < 2) continue;
|
|
207
|
+
const toks = tokenize(stripNonCode(lines.slice(start - 1, end).join("\n"), false));
|
|
208
|
+
if (toks.strict.length < FLOOR_TOKENS) continue;
|
|
209
|
+
frags.push({
|
|
210
|
+
id: `${file}#win@${start}`, label: `${file.split("/").pop()}:${start}-${end}`, file, start, end,
|
|
211
|
+
n: toks.strict.length, test: isTestPath(file),
|
|
212
|
+
fp: { strict: fingerprints(toks.strict), renamed: fingerprints(toks.renamed) },
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const modes = { strict: pairsForMode(frags, "strict"), renamed: pairsForMode(frags, "renamed") };
|
|
217
|
+
const nameTwins = opts.nameTwins ? computeNameTwins(frags) : null;
|
|
218
|
+
// fp sets are worker-internal — strip them from the payload that crosses the thread boundary
|
|
219
|
+
const slim = frags.map(({ fp, ...rest }) => rest);
|
|
220
|
+
return { ok: true, frags: slim, modes, ...(nameTwins ? { nameTwins } : {}), graphSymbols, floors: { tokens: FLOOR_TOKENS, sim: FLOOR_SIM * 100 } };
|
|
221
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
// duplicates.js — content-based clone detection over the repo's OWN graph.json symbols (the Health
|
|
2
|
-
// tab's engine). MOSS-style pipeline: symbol bodies (line ranges from the graph) → strip comments &
|
|
3
|
-
// string bodies → tokenize → k-gram rolling hashes → winnowing fingerprints → inverted index (no
|
|
4
|
-
// O(n²) all-pairs) → jaccard similarity. BOTH normalization modes are computed in one pass so every
|
|
5
|
-
// UI knob (similarity %, min size, strict/renamed) filters instantly on the renderer side:
|
|
6
|
-
// strict — identifiers kept: only literal copy-paste (Type-1 clones)
|
|
7
|
-
// renamed — identifiers canonicalized to "I": catches copy-paste-then-rename (Type-2 clones)
|
|
8
|
-
// Pairs are reported down to the FLOOR values; the renderer slices from there upward.
|
|
9
|
-
//
|
|
10
|
-
// Facade: the implementation lives in the sibling modules —
|
|
11
|
-
// duplicates.tokenize.js — stripping, body-end detection, tokenization, winnowing fingerprints
|
|
12
|
-
// duplicates.compute.js — fragment extraction, inverted-index pairing, computeDuplicates
|
|
13
|
-
// duplicates.run.js — worker offload + mtime cache (runDuplicates entry)
|
|
14
|
-
export { computeDuplicates } from "./duplicates.compute.js";
|
|
15
|
-
export { runDuplicates } from "./duplicates.run.js";
|
|
1
|
+
// duplicates.js — content-based clone detection over the repo's OWN graph.json symbols (the Health
|
|
2
|
+
// tab's engine). MOSS-style pipeline: symbol bodies (line ranges from the graph) → strip comments &
|
|
3
|
+
// string bodies → tokenize → k-gram rolling hashes → winnowing fingerprints → inverted index (no
|
|
4
|
+
// O(n²) all-pairs) → jaccard similarity. BOTH normalization modes are computed in one pass so every
|
|
5
|
+
// UI knob (similarity %, min size, strict/renamed) filters instantly on the renderer side:
|
|
6
|
+
// strict — identifiers kept: only literal copy-paste (Type-1 clones)
|
|
7
|
+
// renamed — identifiers canonicalized to "I": catches copy-paste-then-rename (Type-2 clones)
|
|
8
|
+
// Pairs are reported down to the FLOOR values; the renderer slices from there upward.
|
|
9
|
+
//
|
|
10
|
+
// Facade: the implementation lives in the sibling modules —
|
|
11
|
+
// duplicates.tokenize.js — stripping, body-end detection, tokenization, winnowing fingerprints
|
|
12
|
+
// duplicates.compute.js — fragment extraction, inverted-index pairing, computeDuplicates
|
|
13
|
+
// duplicates.run.js — worker offload + mtime cache (runDuplicates entry)
|
|
14
|
+
export { computeDuplicates } from "./duplicates.compute.js";
|
|
15
|
+
export { runDuplicates } from "./duplicates.run.js";
|