@goshenkata/dryscan-core 1.2.6 → 1.2.7
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/chunk-ZZC4V5LV.js +52 -0
- package/dist/chunk-ZZC4V5LV.js.map +1 -0
- package/dist/index.js +10 -17
- package/dist/index.js.map +1 -1
- package/dist/services/ParallelSimilarity.d.ts +8 -0
- package/dist/services/ParallelSimilarity.js +7 -0
- package/dist/services/ParallelSimilarity.js.map +1 -0
- package/dist/services/cosineSimilarityWorker.d.ts +2 -0
- package/dist/services/cosineSimilarityWorker.js +12 -0
- package/dist/services/cosineSimilarityWorker.js.map +1 -0
- package/package.json +1 -1
- package/src/services/DuplicateService.ts +4 -4
- package/src/services/DuplicationCache.ts +4 -4
- package/src/services/ParallelSimilarity.ts +59 -0
- package/src/services/cosineSimilarityWorker.ts +20 -0
- package/tsup.config.ts +1 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/services/ParallelSimilarity.ts
|
|
13
|
+
import os from "os";
|
|
14
|
+
import { Worker } from "worker_threads";
|
|
15
|
+
import { cosineSimilarity } from "@langchain/core/utils/math";
|
|
16
|
+
var MIN_PARALLEL_ROWS = 50;
|
|
17
|
+
async function parallelCosineSimilarity(A, B) {
|
|
18
|
+
if (A.length === 0 || B.length === 0) return [];
|
|
19
|
+
if (A.length < MIN_PARALLEL_ROWS) return cosineSimilarity(A, B);
|
|
20
|
+
const dims = A[0].length;
|
|
21
|
+
const chunkSize = Math.ceil(A.length / os.cpus().length);
|
|
22
|
+
const sharedB = new SharedArrayBuffer(B.length * dims * 8);
|
|
23
|
+
const bView = new Float64Array(sharedB);
|
|
24
|
+
B.forEach((row, i) => bView.set(row, i * dims));
|
|
25
|
+
const workerUrl = new URL("./services/cosineSimilarityWorker.js", import.meta.url);
|
|
26
|
+
const execArgv = workerUrl.pathname.endsWith(".ts") ? ["--import", "tsx/esm"] : [];
|
|
27
|
+
const chunks = Array.from(
|
|
28
|
+
{ length: Math.ceil(A.length / chunkSize) },
|
|
29
|
+
(_, i) => A.slice(i * chunkSize, (i + 1) * chunkSize)
|
|
30
|
+
);
|
|
31
|
+
const results = await Promise.all(chunks.map((chunk) => runWorker(chunk, sharedB, B.length, dims, workerUrl, execArgv)));
|
|
32
|
+
return results.flat();
|
|
33
|
+
}
|
|
34
|
+
function runWorker(chunk, sharedB, bCount, dims, workerUrl, execArgv) {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
const rowsFlat = new Float64Array(chunk.length * dims);
|
|
37
|
+
chunk.forEach((row, i) => rowsFlat.set(row, i * dims));
|
|
38
|
+
const worker = new Worker(workerUrl, {
|
|
39
|
+
workerData: { rowsBuffer: rowsFlat.buffer, rowCount: chunk.length, allBuffer: sharedB, allCount: bCount, dims },
|
|
40
|
+
transferList: [rowsFlat.buffer],
|
|
41
|
+
execArgv
|
|
42
|
+
});
|
|
43
|
+
worker.once("message", ({ result }) => resolve(result));
|
|
44
|
+
worker.once("error", reject);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
__decorateClass,
|
|
50
|
+
parallelCosineSimilarity
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=chunk-ZZC4V5LV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/ParallelSimilarity.ts"],"sourcesContent":["import os from \"node:os\";\nimport { Worker } from \"node:worker_threads\";\nimport { cosineSimilarity } from \"@langchain/core/utils/math\";\n\n/** Minimum row count below which synchronous is faster than worker overhead. */\nconst MIN_PARALLEL_ROWS = 50;\n\n/**\n * Computes cosineSimilarity(A, B) using worker threads for large inputs,\n * falling back to the synchronous library call for small ones.\n * B is packed into a SharedArrayBuffer shared across all workers — no copies.\n */\nexport async function parallelCosineSimilarity(A: number[][], B: number[][]): Promise<number[][]> {\n if (A.length === 0 || B.length === 0) return [];\n if (A.length < MIN_PARALLEL_ROWS) return cosineSimilarity(A, B);\n\n const dims = A[0].length;\n const chunkSize = Math.ceil(A.length / os.cpus().length);\n\n const sharedB = new SharedArrayBuffer(B.length * dims * 8);\n const bView = new Float64Array(sharedB);\n B.forEach((row, i) => bView.set(row, i * dims));\n\n // import.meta.resolve respects the active module loader:\n // under tsx it remaps .js → .ts; in compiled output it stays .js.\n const workerUrl = new URL(\"./services/cosineSimilarityWorker.js\", import.meta.url);\n const execArgv = workerUrl.pathname.endsWith(\".ts\") ? [\"--import\", \"tsx/esm\"] : [];\n\n const chunks = Array.from(\n { length: Math.ceil(A.length / chunkSize) },\n (_, i) => A.slice(i * chunkSize, (i + 1) * chunkSize),\n );\n\n const results = await Promise.all(chunks.map(chunk => runWorker(chunk, sharedB, B.length, dims, workerUrl, execArgv)));\n return results.flat();\n}\n\nfunction runWorker(\n chunk: number[][],\n sharedB: SharedArrayBuffer,\n bCount: number,\n dims: number,\n workerUrl: URL,\n execArgv: string[],\n): Promise<number[][]> {\n return new Promise((resolve, reject) => {\n const rowsFlat = new Float64Array(chunk.length * dims);\n chunk.forEach((row, i) => rowsFlat.set(row, i * dims));\n\n const worker = new Worker(workerUrl, {\n workerData: { rowsBuffer: rowsFlat.buffer, rowCount: chunk.length, allBuffer: sharedB, allCount: bCount, dims },\n transferList: [rowsFlat.buffer],\n execArgv,\n });\n\n worker.once(\"message\", ({ result }) => resolve(result));\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AAS,IAAI,OAAO,WAAW;AAAA,MACnC,YAAY,EAAE,YAAY,SAAS,QAAQ,UAAU,MAAM,QAAQ,WAAW,SAAS,UAAU,QAAQ,KAAK;AAAA,MAC9G,cAAc,CAAC,SAAS,MAAM;AAAA,MAC9B;AAAA,IACF,CAAC;AAED,WAAO,KAAK,WAAW,CAAC,EAAE,OAAO,MAAM,QAAQ,MAAM,CAAC;AACtD,WAAO,KAAK,SAAS,MAAM;AAAA,EAC7B,CAAC;AACH;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
-
if (decorator = decorators[i])
|
|
7
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
-
if (kind && result) __defProp(target, key, result);
|
|
9
|
-
return result;
|
|
10
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
__decorateClass,
|
|
3
|
+
parallelCosineSimilarity
|
|
4
|
+
} from "./chunk-ZZC4V5LV.js";
|
|
11
5
|
|
|
12
6
|
// src/DryScan.ts
|
|
13
7
|
import upath6 from "upath";
|
|
@@ -1156,7 +1150,6 @@ async function performIncrementalUpdate(repoPath, extractor, db) {
|
|
|
1156
1150
|
|
|
1157
1151
|
// src/services/DuplicationCache.ts
|
|
1158
1152
|
import debug4 from "debug";
|
|
1159
|
-
import { cosineSimilarity } from "@langchain/core/utils/math";
|
|
1160
1153
|
var log4 = debug4("DryScan:DuplicationCache");
|
|
1161
1154
|
var DuplicationCache = class _DuplicationCache {
|
|
1162
1155
|
static instance = null;
|
|
@@ -1251,7 +1244,7 @@ var DuplicationCache = class _DuplicationCache {
|
|
|
1251
1244
|
* cells from the old matrix and recomputes only dirty rows via one batched
|
|
1252
1245
|
* cosineSimilarity call — O(d·n) where d = number of dirty units.
|
|
1253
1246
|
*/
|
|
1254
|
-
buildEmbSimCache(units, dirtyPaths) {
|
|
1247
|
+
async buildEmbSimCache(units, dirtyPaths) {
|
|
1255
1248
|
const embedded = units.filter((u) => Array.isArray(u.embedding) && u.embedding.length > 0);
|
|
1256
1249
|
if (embedded.length < 2) {
|
|
1257
1250
|
this.embSimMatrix = [];
|
|
@@ -1264,7 +1257,7 @@ var DuplicationCache = class _DuplicationCache {
|
|
|
1264
1257
|
const hasPriorMatrix = this.embSimMatrix.length > 0;
|
|
1265
1258
|
if (!dirtySet || !hasPriorMatrix) {
|
|
1266
1259
|
this.embSimIndex = newIndex;
|
|
1267
|
-
this.embSimMatrix =
|
|
1260
|
+
this.embSimMatrix = await parallelCosineSimilarity(embeddings, embeddings);
|
|
1268
1261
|
log4("Built full embedding similarity matrix: %d units", embedded.length);
|
|
1269
1262
|
return;
|
|
1270
1263
|
}
|
|
@@ -1284,7 +1277,7 @@ var DuplicationCache = class _DuplicationCache {
|
|
|
1284
1277
|
}
|
|
1285
1278
|
}
|
|
1286
1279
|
const dirtyIndices = embedded.reduce((acc, u, i) => dirtyIds.has(u.id) ? [...acc, i] : acc, []);
|
|
1287
|
-
const dirtyRows =
|
|
1280
|
+
const dirtyRows = await parallelCosineSimilarity(dirtyIndices.map((i) => embeddings[i]), embeddings);
|
|
1288
1281
|
dirtyIndices.forEach((rowIdx, di) => {
|
|
1289
1282
|
for (let j = 0; j < n; j++) {
|
|
1290
1283
|
newMatrix[rowIdx][j] = dirtyRows[di][j];
|
|
@@ -1372,7 +1365,7 @@ var DuplicateService = class {
|
|
|
1372
1365
|
return { duplicates: [], score: this.computeDuplicationScore([], allUnits) };
|
|
1373
1366
|
}
|
|
1374
1367
|
const thresholds = this.resolveThresholds(config.threshold);
|
|
1375
|
-
const duplicates = this.computeDuplicates(allUnits, thresholds, dirtyPaths);
|
|
1368
|
+
const duplicates = await this.computeDuplicates(allUnits, thresholds, dirtyPaths);
|
|
1376
1369
|
const filtered = duplicates.filter((g) => !this.isGroupExcluded(g));
|
|
1377
1370
|
log6("Found %d duplicate groups (%d excluded)", filtered.length, duplicates.length - filtered.length);
|
|
1378
1371
|
this.cache.update(filtered).catch((err) => log6("Cache update failed: %O", err));
|
|
@@ -1390,9 +1383,9 @@ var DuplicateService = class {
|
|
|
1390
1383
|
class: clamp(fn + d.class - d.function)
|
|
1391
1384
|
};
|
|
1392
1385
|
}
|
|
1393
|
-
computeDuplicates(units, thresholds, dirtyPaths) {
|
|
1386
|
+
async computeDuplicates(units, thresholds, dirtyPaths) {
|
|
1394
1387
|
this.cache.clearRunCaches();
|
|
1395
|
-
this.cache.buildEmbSimCache(units, dirtyPaths);
|
|
1388
|
+
await this.cache.buildEmbSimCache(units, dirtyPaths);
|
|
1396
1389
|
const duplicates = [];
|
|
1397
1390
|
const t0 = performance.now();
|
|
1398
1391
|
for (const [type, typedUnits] of this.groupByType(units)) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/DryScan.ts","../src/const.ts","../src/IndexUnitExtractor.ts","../src/extractors/java.ts","../src/config/indexConfig.ts","../src/config/configStore.ts","../src/config/dryconfig.ts","../src/Gitignore.ts","../src/db/DryScanDatabase.ts","../src/db/entities/FileEntity.ts","../src/db/entities/IndexUnitEntity.ts","../src/services/RepositoryInitializer.ts","../src/services/EmbeddingService.ts","../src/services/UpdateService.ts","../src/DryScanUpdater.ts","../src/services/DuplicationCache.ts","../src/services/DuplicateService.ts","../src/services/ExclusionService.ts","../src/services/PairingService.ts"],"sourcesContent":["import upath from \"upath\";\nimport fs from \"fs/promises\";\nimport { DuplicateAnalysisResult, DuplicateReport } from \"./types\";\nimport { DRYSCAN_DIR, INDEX_DB } from \"./const\";\nimport { defaultExtractors, IndexUnitExtractor } from \"./IndexUnitExtractor\";\nimport { DryScanDatabase } from \"./db/DryScanDatabase\";\nimport { RepositoryInitializer, InitOptions as InitServiceOptions } from \"./services/RepositoryInitializer\";\nimport { UpdateService } from \"./services/UpdateService\";\nimport { DuplicateService } from \"./services/DuplicateService\";\nimport { ExclusionService } from \"./services/ExclusionService\";\nimport { DryScanServiceDeps } from \"./services/types\";\nimport { configStore } from \"./config/configStore\";\nimport { DryConfig } from \"./types\";\nimport { PairingService } from \"./services/PairingService\";\nimport { existsSync } from \"fs\";\n\nexport type InitOptions = InitServiceOptions;\n\n\nexport class DryScan {\n repoPath: string;\n private readonly extractor: IndexUnitExtractor;\n private db: DryScanDatabase;\n private readonly services: {\n initializer: RepositoryInitializer;\n updater: UpdateService;\n duplicate: DuplicateService;\n exclusion: ExclusionService;\n };\n private readonly serviceDeps: DryScanServiceDeps;\n\n constructor(\n repoPath: string,\n extractor?: IndexUnitExtractor,\n db?: DryScanDatabase\n ) {\n this.repoPath = repoPath;\n this.extractor = extractor ?? new IndexUnitExtractor(repoPath, defaultExtractors(repoPath));\n this.db = db ?? new DryScanDatabase();\n\n this.serviceDeps = {\n repoPath: this.repoPath,\n db: this.db,\n extractor: this.extractor,\n pairing: new PairingService(this.extractor),\n };\n\n const exclusion = new ExclusionService(this.serviceDeps);\n this.services = {\n initializer: new RepositoryInitializer(this.serviceDeps, exclusion),\n updater: new UpdateService(this.serviceDeps, exclusion),\n duplicate: new DuplicateService(this.serviceDeps),\n exclusion,\n };\n }\n\n /**\n * Initializes the DryScan repository with a 3-phase analysis:\n * Phase 1: Extract and save all functions\n * Phase 2: Resolve and save internal dependencies\n * Phase 3: Compute and save semantic embeddings\n */\n async init(options?: InitOptions): Promise<void> {\n console.log(`[DryScan] Initializing repository at ${this.repoPath}`);\n\n const dryDir = upath.join(this.repoPath, DRYSCAN_DIR);\n if (existsSync(dryDir)) {\n console.warn(`[DryScan] Warning: a '.dry' folder already exists at ${dryDir}.`);\n }\n console.log(\"[DryScan] Preparing database and cache...\");\n await configStore.init(this.repoPath);\n await this.ensureDatabase();\n console.log(\"[DryScan] Starting initial scan (may take a moment)...\");\n await this.services.initializer.init(options);\n console.log(\"[DryScan] Initial scan complete.\");\n }\n\n /**\n * Updates the index by detecting changed, new, and deleted files.\n * Only reprocesses units in changed files for efficiency.\n * Delegates to DryScanUpdater module for implementation.\n * \n * Update process:\n * 1. List all current source files in repository\n * 2. For each file, check if it's new, changed, or unchanged (via mtime + checksum)\n * 3. Remove old units from changed/deleted files\n * 4. Extract and save units from new/changed files\n * 5. Recompute internal dependencies for affected units\n * 6. Recompute embeddings for affected units\n * 7. Update file tracking metadata\n */\n async updateIndex(): Promise<string[]> {\n console.log(`[DryScan] Updating index at ${this.repoPath}...`);\n console.log(\"[DryScan] Checking for file changes...\");\n const start = Date.now();\n await this.ensureDatabase();\n const dirtyPaths = await this.services.updater.updateIndex();\n const duration = Date.now() - start;\n console.log(`[DryScan] Index update complete. Took ${duration}ms.`);\n return dirtyPaths;\n }\n\n\n /**\n * Runs duplicate detection and returns a normalized report payload ready for persistence or display.\n */\n async buildDuplicateReport(): Promise<DuplicateReport> {\n const config = await this.loadConfig();\n const analysis = await this.findDuplicates(config);\n return {\n version: 1,\n generatedAt: new Date().toISOString(),\n threshold: config.threshold,\n grade: analysis.score.grade,\n score: analysis.score,\n duplicates: analysis.duplicates,\n };\n }\n\n /**\n * Finds duplicate code blocks using cosine similarity on embeddings.\n * Automatically updates the index before searching to ensure results are current.\n * Compares all function pairs and returns groups with similarity above the configured threshold.\n *\n * @returns Analysis result with duplicate groups and duplication score\n */\n private async findDuplicates(config: DryConfig): Promise<DuplicateAnalysisResult> {\n console.log(`[DryScan] Finding duplicates (threshold: ${config.threshold})...`);\n await this.ensureDatabase();\n\n console.log(\"[DryScan] Updating index...\");\n const updateStart = Date.now();\n const dirtyPaths = await this.updateIndex();\n const updateDuration = Date.now() - updateStart;\n console.log(`[DryScan] Index update took ${updateDuration}ms.`);\n\n console.log(\"[DryScan] Detecting duplicates...\");\n const dupStart = Date.now();\n const result = await this.services.duplicate.findDuplicates(config, dirtyPaths);\n const dupDuration = Date.now() - dupStart;\n console.log(`[DryScan] Duplicate detection took ${dupDuration}ms.`);\n\n return result;\n }\n\n /**\n * Cleans excludedPairs entries that no longer match any indexed units.\n * Runs an update first to ensure the index reflects current code.\n */\n async cleanExclusions(): Promise<{ removed: number; kept: number }> {\n await this.updateIndex();\n return this.services.exclusion.cleanExclusions();\n }\n\n private async ensureDatabase(): Promise<void> {\n if (this.db.isInitialized()) return;\n const dbPath = upath.join(this.repoPath, DRYSCAN_DIR, INDEX_DB);\n await fs.mkdir(upath.dirname(dbPath), { recursive: true });\n await this.db.init(dbPath);\n }\n\n private async loadConfig(): Promise<DryConfig> {\n return configStore.get(this.repoPath);\n }\n\n}\n","export const DRYSCAN_DIR = \".dry\";\nexport const INDEX_DB = \"index.db\";\nexport const REPORTS_DIR = \"reports\";\nexport const FILE_CHECKSUM_ALGO = \"md5\";\nexport const BLOCK_HASH_ALGO = \"sha1\";","import path from \"path\";\nimport type { Stats } from \"fs\";\nimport fs from \"fs/promises\";\nimport upath from \"upath\";\nimport crypto from \"node:crypto\";\nimport debug from \"debug\";\nimport { glob } from \"glob-gitignore\";\nimport { IndexUnit } from \"./types\";\nimport { LanguageExtractor } from \"./extractors/LanguageExtractor\";\nimport { JavaExtractor } from \"./extractors/java\";\nimport { FILE_CHECKSUM_ALGO } from \"./const\";\nimport { configStore } from \"./config/configStore\";\nimport { DryConfig } from \"./types\";\nimport { Gitignore } from \"./Gitignore\"\nimport { Ignore } from \"ignore\";\n\nconst log = debug(\"DryScan:Extractor\");\n\nexport type { LanguageExtractor } from \"./extractors/LanguageExtractor\";\n/**\n * Returns the default set of language extractors supported by DryScan.\n * Extend/override by passing custom extractors into the IndexUnitExtractor constructor.\n */\nexport function defaultExtractors(repoPath: string): LanguageExtractor[] {\n return [new JavaExtractor(repoPath)];\n}\n\n/**\n * Extracts and indexes code units (classes, functions, blocks) for a repository.\n * Owns shared file-system helpers and delegates language-specific parsing to LanguageExtractors.\n */\nexport class IndexUnitExtractor {\n private readonly root: string;\n readonly extractors: LanguageExtractor[];\n private readonly gitignore: Gitignore;\n\n constructor(\n rootPath: string,\n extractors?: LanguageExtractor[]\n ) {\n this.root = rootPath;\n this.extractors = extractors ?? defaultExtractors(rootPath);\n this.gitignore = new Gitignore(this.root);\n log(\"Initialized extractor for %s\", this.root);\n }\n\n /**\n * Lists all supported source files from a path. Honors exclusion globs from config.\n */\n async listSourceFiles(dirPath: string): Promise<string[]> {\n const target = await this.resolveTarget(dirPath);\n const config = await this.loadConfig();\n const ignoreMatcher = await this.gitignore.buildMatcher(config);\n\n if (target.stat.isFile()) {\n return this.filterSingleFile(target.baseRel, ignoreMatcher);\n }\n\n const matches = await this.globSourceFiles(target.baseRel);\n return this.filterSupportedFiles(matches, ignoreMatcher);\n }\n\n /**\n * Computes MD5 checksum of file content to track changes.\n */\n async computeChecksum(filePath: string): Promise<string> {\n const fullPath = path.isAbsolute(filePath)\n ? filePath\n : path.join(this.root, filePath);\n\n const content = await fs.readFile(fullPath, \"utf8\");\n return crypto.createHash(FILE_CHECKSUM_ALGO).update(content).digest(\"hex\");\n }\n\n /**\n * Scans a file or directory and extracts indexable units using the matching LanguageExtractor.\n * The returned units have repo-relative file paths and no embedding attached.\n */\n async scan(targetPath: string): Promise<IndexUnit[]> {\n const fullPath = path.isAbsolute(targetPath)\n ? targetPath\n : path.join(this.root, targetPath);\n\n const stat = await fs.stat(fullPath).catch(() => null);\n if (!stat) {\n throw new Error(`Path not found: ${fullPath}`);\n }\n\n if (stat.isDirectory()) {\n log(\"Scanning directory %s\", fullPath);\n return this.scanDirectory(fullPath);\n }\n\n return this.scanFile(fullPath);\n }\n\n\n /**\n * Scans a directory recursively, extracting units from supported files while honoring exclusions.\n */\n private async scanDirectory(dir: string): Promise<IndexUnit[]> {\n const out: IndexUnit[] = [];\n const relDir = this.relPath(dir);\n const files = await this.listSourceFiles(relDir);\n for (const relFile of files) {\n const absFile = path.join(this.root, relFile);\n const extracted = await this.tryScanSupportedFile(absFile);\n out.push(...extracted);\n }\n return out;\n }\n\n /**\n * Scans a single file and extracts supported units.\n */\n private async scanFile(filePath: string): Promise<IndexUnit[]> {\n return this.tryScanSupportedFile(filePath, true);\n }\n\n /**\n * Extracts units from a supported file.\n * Optionally throws when the file type is unsupported (used when scanning an explicit file).\n */\n private async tryScanSupportedFile(filePath: string, throwOnUnsupported = false): Promise<IndexUnit[]> {\n const extractor = this.extractors.find(ex => ex.supports(filePath));\n if (!extractor) {\n if (throwOnUnsupported) {\n throw new Error(`Unsupported file type: ${filePath}`);\n }\n return [];\n }\n const rel = this.relPath(filePath);\n if (await this.shouldExclude(rel)) {\n log(\"Skipping excluded file %s\", rel);\n return [];\n }\n const source = await fs.readFile(filePath, \"utf8\");\n const units = await extractor.extractFromText(rel, source);\n log(\"Extracted %d units from %s\", units.length, rel);\n return units.map(unit => ({\n ...unit,\n filePath: rel,\n embedding: undefined,\n }));\n }\n\n /**\n * Converts an absolute path to a repo-relative, normalized (POSIX-style) path.\n * This keeps paths stable across platforms and consistent in the index/DB.\n */\n private relPath(absPath: string): string {\n return this.normalizeRelPath(upath.relative(this.root, absPath));\n }\n\n /**\n * Returns true if a repo-relative path matches any configured exclusion glob.\n */\n private async shouldExclude(relPath: string): Promise<boolean> {\n const config = await this.loadConfig();\n const ignoreMatcher = await this.gitignore.buildMatcher(config);\n return ignoreMatcher.ignores(this.normalizeRelPath(relPath));\n }\n\n private async loadConfig(): Promise<DryConfig> {\n return await configStore.get(this.root);\n }\n\n /**\n * Normalizes repo-relative paths and strips leading \"./\" to keep matcher inputs consistent.\n */\n private normalizeRelPath(relPath: string): string {\n const normalized = upath.normalizeTrim(relPath);\n return normalized.startsWith(\"./\") ? normalized.slice(2) : normalized;\n }\n\n private async resolveTarget(dirPath: string): Promise<{ fullPath: string; baseRel: string; stat: Stats; }> {\n const fullPath = path.isAbsolute(dirPath) ? dirPath : path.join(this.root, dirPath);\n const stat = await fs.stat(fullPath).catch(() => null);\n if (!stat) {\n throw new Error(`Path not found: ${fullPath}`);\n }\n const baseRel = this.relPath(fullPath);\n log(\"Listing source files under %s\", fullPath);\n return { fullPath, baseRel, stat };\n }\n\n private async filterSingleFile(baseRel: string, ignoreMatcher: Ignore): Promise<string[]> {\n const relFile = this.normalizeRelPath(baseRel);\n if (ignoreMatcher.ignores(relFile)) return [];\n return this.extractors.some((ex) => ex.supports(relFile)) ? [relFile] : [];\n }\n\n private async globSourceFiles(baseRel: string): Promise<string[]> {\n const pattern = baseRel ? `${baseRel.replace(/\\\\/g, \"/\")}/**/*` : \"**/*\";\n const matches = await glob(pattern, {\n cwd: this.root,\n dot: false,\n nodir: true,\n });\n return matches.map((p: string) => this.normalizeRelPath(p));\n }\n\n private filterSupportedFiles(relPaths: string[], ignoreMatcher: Ignore): string[] {\n return relPaths\n .filter((relPath: string) => !ignoreMatcher.ignores(relPath))\n .filter((relPath: string) => this.extractors.some((ex) => ex.supports(relPath)));\n }\n}\n","import crypto from \"node:crypto\";\nimport Parser from \"tree-sitter\";\nimport Java from \"tree-sitter-java\";\nimport { LanguageExtractor } from \"./LanguageExtractor\";\nimport { IndexUnit, IndexUnitType } from \"../types\";\nimport { indexConfig } from \"../config/indexConfig\";\nimport { DryConfig } from \"../types\";\nimport { configStore } from \"../config/configStore\";\nimport { BLOCK_HASH_ALGO } from \"../const\";\n\nexport class JavaExtractor implements LanguageExtractor {\n readonly id = \"java\";\n readonly exts = [\".java\"];\n\n private parser: Parser;\n private readonly repoPath: string;\n private config?: DryConfig;\n\n constructor(repoPath: string) {\n this.repoPath = repoPath;\n this.parser = new Parser();\n this.parser.setLanguage(Java);\n }\n\n supports(filePath: string): boolean {\n const lower = filePath.toLowerCase();\n return this.exts.some((ext) => lower.endsWith(ext));\n }\n\n async extractFromText(fileRelPath: string, source: string): Promise<IndexUnit[]> {\n if (!source.trim()) return [];\n\n this.config = await configStore.get(this.repoPath);\n\n const tree = this.parser.parse(source);\n const units: IndexUnit[] = [];\n\n const visit = (node: Parser.SyntaxNode, currentClass?: IndexUnit) => {\n if (this.isClassNode(node)) {\n const className = this.getClassName(node, source) || \"<anonymous>\";\n if (this.isDtoClass(node, source, className)) {\n return;\n }\n const startLine = node.startPosition.row;\n const endLine = node.endPosition.row;\n const classLength = endLine - startLine;\n const skipClass = this.shouldSkip(IndexUnitType.CLASS, className, classLength);\n const classId = this.buildId(IndexUnitType.CLASS, className, startLine, endLine);\n const code = this.stripComments(this.stripClassBody(node, source));\n const classUnit: IndexUnit = {\n id: classId,\n name: className,\n filePath: fileRelPath,\n startLine,\n endLine,\n code,\n unitType: IndexUnitType.CLASS,\n children: [],\n };\n if (!skipClass) {\n units.push(classUnit);\n }\n\n for (let i = 0; i < node.namedChildCount; i++) {\n const child = node.namedChild(i);\n if (child) visit(child, skipClass ? undefined : classUnit);\n }\n return;\n }\n\n if (this.isFunctionNode(node)) {\n const fnUnit = this.buildFunctionUnit(node, source, fileRelPath, currentClass);\n const fnLength = fnUnit.endLine - fnUnit.startLine;\n const bodyNode = this.getFunctionBody(node);\n const fnArity = this.getNodeArity(node);\n const skipFunction = this.shouldSkip(IndexUnitType.FUNCTION, fnUnit.name, fnLength, fnArity);\n\n if (skipFunction) {\n return;\n }\n\n units.push(fnUnit);\n\n if (bodyNode) {\n const blocks = this.extractBlocks(bodyNode, source, fileRelPath, fnUnit);\n units.push(...blocks);\n }\n }\n\n for (let i = 0; i < node.namedChildCount; i++) {\n const child = node.namedChild(i);\n if (child) visit(child, currentClass);\n }\n };\n\n visit(tree.rootNode);\n\n //remove duplicates if any\n return this.removeDuplicates(units);\n }\n\n unitLabel(unit: IndexUnit): string | null {\n if (unit.unitType === IndexUnitType.CLASS) return unit.filePath;\n if (unit.unitType === IndexUnitType.FUNCTION) return this.canonicalFunctionSignature(unit);\n if (unit.unitType === IndexUnitType.BLOCK) return this.normalizedBlockHash(unit);\n return unit.name;\n }\n\n private isClassNode(node: Parser.SyntaxNode): boolean {\n return node.type === \"class_declaration\";\n }\n\n private getClassName(node: Parser.SyntaxNode, source: string): string | null {\n const nameNode = node.childForFieldName?.(\"name\");\n return nameNode ? source.slice(nameNode.startIndex, nameNode.endIndex) : null;\n }\n\n private isFunctionNode(node: Parser.SyntaxNode): boolean {\n return node.type === \"method_declaration\" || node.type === \"constructor_declaration\";\n }\n\n private getFunctionName(node: Parser.SyntaxNode, source: string, parentClass?: IndexUnit): string | null {\n const nameNode = node.childForFieldName?.(\"name\");\n const nameText = nameNode ? source.slice(nameNode.startIndex, nameNode.endIndex) : \"<anonymous>\";\n return parentClass ? `${parentClass.name}.${nameText}` : nameText;\n }\n\n private getFunctionBody(node: Parser.SyntaxNode): Parser.SyntaxNode | null {\n return node.childForFieldName?.(\"body\") ?? null;\n }\n\n private isBlockNode(node: Parser.SyntaxNode): boolean {\n return node.type === \"block\";\n }\n\n private getMethodBodiesForClass(node: Parser.SyntaxNode): Parser.SyntaxNode[] {\n const bodies: Parser.SyntaxNode[] = [];\n const classBody = node.children.find(child => child.type === \"class_body\");\n if (!classBody) return bodies;\n \n for (let i = 0; i < classBody.namedChildCount; i++) {\n const child = classBody.namedChild(i);\n if (!child) continue;\n if (child.type === \"method_declaration\" || child.type === \"constructor_declaration\") {\n const body = child.childForFieldName?.(\"body\");\n if (body) bodies.push(body);\n }\n }\n return bodies;\n }\n\n private canonicalFunctionSignature(unit: IndexUnit): string {\n const arity = this.extractArity(unit.code);\n return `${unit.name}(arity:${arity})`;\n }\n\n private normalizedBlockHash(unit: IndexUnit): string {\n const normalized = this.normalizeCode(unit.code);\n return crypto.createHash(BLOCK_HASH_ALGO).update(normalized).digest(\"hex\");\n }\n\n private shouldSkip(unitType: IndexUnitType, name: string, lineCount: number, arity?: number): boolean {\n if (!this.config) {\n throw new Error(\"Config not loaded before skip evaluation\");\n }\n const config = this.config;\n const minLines = unitType === IndexUnitType.BLOCK\n ? Math.max(indexConfig.blockMinLines, config.minBlockLines ?? 0)\n : config.minLines;\n const belowMin = minLines > 0 && lineCount < minLines;\n const trivial = unitType === IndexUnitType.FUNCTION && this.isTrivialFunction(name, arity ?? 0);\n return belowMin || trivial;\n }\n\n /**\n * A function is trivial if it follows a simple accessor pattern:\n * - getters/isers: name matches get[A-Z] or is[A-Z] with exactly 0 parameters\n * - setters: name matches set[A-Z] with at most 1 parameter\n * Methods like getUserById(Long id) have arity > 0 and are NOT trivial.\n */\n private isTrivialFunction(fullName: string, arity: number): boolean {\n const simpleName = fullName.split(\".\").pop() || fullName;\n const isGetter = /^(get|is)[A-Z]/.test(simpleName) && arity === 0;\n const isSetter = /^set[A-Z]/.test(simpleName) && arity <= 1;\n return isGetter || isSetter;\n }\n\n /** Counts the formal parameters of a method or constructor node. */\n private getNodeArity(node: Parser.SyntaxNode): number {\n const params = node.childForFieldName?.(\"parameters\");\n if (!params) return 0;\n return params.namedChildren.filter(c => c.type === \"formal_parameter\" || c.type === \"spread_parameter\").length;\n }\n\n private isDtoClass(node: Parser.SyntaxNode, source: string, className: string): boolean {\n const classBody = node.children.find((child) => child.type === \"class_body\");\n if (!classBody) return false;\n\n let hasField = false;\n\n for (let i = 0; i < classBody.namedChildCount; i++) {\n const child = classBody.namedChild(i);\n if (!child) continue;\n\n if (child.type === \"field_declaration\") {\n hasField = true;\n continue;\n }\n\n if (child.type.includes(\"annotation\")) {\n continue;\n }\n\n if (child.type === \"method_declaration\" || child.type === \"constructor_declaration\") {\n const simpleName = this.getSimpleFunctionName(child, source);\n const fullName = `${className}.${simpleName}`;\n const arity = this.getNodeArity(child);\n if (!this.isTrivialFunction(fullName, arity)) {\n return false;\n }\n continue;\n }\n\n return false;\n }\n\n return hasField;\n }\n\n private getSimpleFunctionName(node: Parser.SyntaxNode, source: string): string {\n const nameNode = node.childForFieldName?.(\"name\");\n return nameNode ? source.slice(nameNode.startIndex, nameNode.endIndex) : \"<anonymous>\";\n }\n\n private buildFunctionUnit(\n node: Parser.SyntaxNode,\n source: string,\n file: string,\n parentClass?: IndexUnit\n ): IndexUnit {\n const name = this.getFunctionName(node, source, parentClass) || \"<anonymous>\";\n const startLine = node.startPosition.row;\n const endLine = node.endPosition.row;\n const id = this.buildId(IndexUnitType.FUNCTION, name, startLine, endLine);\n const unit: IndexUnit = {\n id,\n name,\n filePath: file,\n startLine,\n endLine,\n children: [],\n code: this.stripComments(source.slice(node.startIndex, node.endIndex)),\n unitType: IndexUnitType.FUNCTION,\n parentId: parentClass?.id,\n parent: parentClass,\n };\n if (parentClass) {\n parentClass.children = parentClass.children || [];\n parentClass.children.push(unit);\n }\n return unit;\n }\n\n private extractBlocks(\n bodyNode: Parser.SyntaxNode,\n source: string,\n file: string,\n parentFunction: IndexUnit\n ): IndexUnit[] {\n const blocks: IndexUnit[] = [];\n\n const visit = (n: Parser.SyntaxNode) => {\n if (this.isBlockNode(n)) {\n const startLine = n.startPosition.row;\n const endLine = n.endPosition.row;\n const lineCount = endLine - startLine;\n if (this.shouldSkip(IndexUnitType.BLOCK, parentFunction.name, lineCount)) {\n return;\n }\n if (lineCount >= indexConfig.blockMinLines) {\n const id = this.buildId(IndexUnitType.BLOCK, parentFunction.name, startLine, endLine);\n const blockUnit: IndexUnit = {\n id,\n name: parentFunction.name,\n filePath: file,\n startLine,\n endLine,\n code: this.stripComments(source.slice(n.startIndex, n.endIndex)),\n unitType: IndexUnitType.BLOCK,\n parentId: parentFunction.id,\n parent: parentFunction,\n };\n const contextLength = this.config?.contextLength ?? 2048;\n const splitBlocks = this.textSplitBlockIfOverContextLimit(blockUnit, contextLength);\n parentFunction.children = parentFunction.children || [];\n parentFunction.children.push(...splitBlocks);\n blocks.push(...splitBlocks);\n }\n }\n\n for (let i = 0; i < n.namedChildCount; i++) {\n const child = n.namedChild(i);\n if (child) visit(child);\n }\n };\n\n visit(bodyNode);\n return blocks;\n }\n\n private stripClassBody(node: Parser.SyntaxNode, source: string): string {\n const classStart = node.startIndex;\n let code = source.slice(classStart, node.endIndex);\n\n const methodBodies: Array<{ start: number; end: number }> = [];\n const candidates = this.getMethodBodiesForClass(node);\n\n for (const body of candidates) {\n methodBodies.push({ start: body.startIndex - classStart, end: body.endIndex - classStart });\n }\n\n methodBodies.sort((a, b) => b.start - a.start);\n for (const body of methodBodies) {\n code = code.slice(0, body.start) + \" { }\" + code.slice(body.end);\n }\n\n return code;\n }\n\n private buildId(type: IndexUnitType, name: string, startLine: number, endLine: number): string {\n return `${type}:${name}:${startLine}-${endLine}`;\n }\n\n private extractArity(code: string): number {\n const match = code.match(/^[^{]*?\\(([^)]*)\\)/s);\n if (!match) return 0;\n const params = match[1]\n .split(\",\")\n .map((p) => p.trim())\n .filter(Boolean);\n return params.length;\n }\n\n private normalizeCode(code: string): string {\n const withoutBlockComments = code.replace(/\\/\\*[\\s\\S]*?\\*\\//g, \"\");\n const withoutLineComments = withoutBlockComments.replace(/\\/\\/[^\\n\\r]*/g, \"\");\n return withoutLineComments.replace(/\\s+/g, \"\");\n }\n\n private stripComments(code: string): string {\n const withoutBlockComments = code.replace(/\\/\\*[\\s\\S]*?\\*\\//g, (match) => match.replace(/[^\\n\\r]/g, \"\"));\n return withoutBlockComments.replace(/\\/\\/[^\\n\\r]*/g, \"\");\n }\n\n private removeDuplicates(units: IndexUnit[]): IndexUnit[] | PromiseLike<IndexUnit[]> {\n return Array.from(new Map(units.map(u => [u.id, u])).values());\n }\n\n /** Splits a block unit's code into chunks if it exceeds the context length limit. */\n private textSplitBlockIfOverContextLimit(unit: IndexUnit, contextLength: number): IndexUnit[] {\n if (unit.code.length <= contextLength) return [unit];\n\n const chunks: IndexUnit[] = [];\n let chunkIndex = 0;\n for (let i = 0; i < unit.code.length; i += contextLength) {\n chunks.push({\n ...unit,\n id: `${unit.id}:chunk${chunkIndex}`,\n code: unit.code.slice(i, i + contextLength),\n });\n chunkIndex++;\n }\n return chunks;\n }\n}\n\n","export const indexConfig = {\n blockMinLines: 5,\n thresholds: {\n class: 0.88,\n function: 0.88,\n block: 0.88,\n },\n weights: {\n class: { self: 1 },\n function: { self: 0.8, parentClass: 0.2 },\n block: { self: 0.7, parentFunction: 0.2, parentClass: 0.1 },\n },\n};\n","import upath from \"upath\";\nimport { DryConfig } from \"../types\";\nimport { ensureDefaultConfig, resolveDryConfig, saveDryConfig } from \"./dryconfig\";\n\nclass ConfigStore {\n private readonly cache = new Map<string, DryConfig>();\n private readonly loading = new Map<string, Promise<DryConfig>>();\n\n async init(repoPath: string): Promise<DryConfig> {\n const key = this.normalize(repoPath);\n return this.load(key, repoPath);\n }\n\n async get(repoPath: string): Promise<DryConfig> {\n const key = this.normalize(repoPath);\n const cached = this.cache.get(key);\n if (cached) return cached;\n return this.load(key, repoPath);\n }\n\n async refresh(repoPath: string): Promise<DryConfig> {\n const key = this.normalize(repoPath);\n this.cache.delete(key);\n return this.load(key, repoPath);\n }\n\n async save(repoPath: string, config: DryConfig): Promise<void> {\n const key = this.normalize(repoPath);\n await saveDryConfig(repoPath, config);\n this.cache.set(key, config);\n }\n\n private async load(key: string, repoPath: string): Promise<DryConfig> {\n const existing = this.loading.get(key);\n if (existing) return existing;\n\n const promise = ensureDefaultConfig(repoPath).then(() => resolveDryConfig(repoPath)).then((config) => {\n this.cache.set(key, config);\n this.loading.delete(key);\n return config;\n }).catch((err) => {\n this.loading.delete(key);\n throw err;\n });\n\n this.loading.set(key, promise);\n return promise;\n }\n\n private normalize(repoPath: string): string {\n return upath.normalizeTrim(upath.resolve(repoPath));\n }\n}\n\nexport const configStore = new ConfigStore();\n","import fs from \"fs/promises\";\nimport upath from \"upath\";\nimport { Validator, Schema } from \"jsonschema\";\nimport { DryConfig } from \"../types\";\n\n// Baseline config used when no file is present; exported so tests and constructors can seed defaults.\nexport const DEFAULT_CONFIG: DryConfig = {\n excludedPaths: [\n \"**/test/**\",\n ],\n excludedPairs: [],\n minLines: 3,\n minBlockLines: 5,\n threshold: 0.8,\n embeddingSource: \"http://localhost:11434\",\n contextLength: 2048,\n};\n\nconst validator = new Validator();\n\nconst partialConfigSchema: Schema = {\n type: \"object\",\n properties: {\n excludedPaths: { type: \"array\", items: { type: \"string\" } },\n excludedPairs: { type: \"array\", items: { type: \"string\" } },\n minLines: { type: \"number\" },\n minBlockLines: { type: \"number\" },\n threshold: { type: \"number\" },\n embeddingSource: { type: \"string\" },\n contextLength: { type: \"number\" },\n },\n};\n\nconst fullConfigSchema: Schema = {\n ...partialConfigSchema,\n required: [\n \"excludedPaths\",\n \"excludedPairs\",\n \"minLines\",\n \"minBlockLines\",\n \"threshold\",\n \"embeddingSource\",\n \"contextLength\",\n ],\n};\n\nfunction validateConfig(raw: unknown, schema: Schema, source: string): any {\n const result = validator.validate(raw, schema);\n if (!result.valid) {\n const details = result.errors.map((e) => e.stack).join(\"; \");\n throw new Error(`${source} config is invalid: ${details}`);\n }\n return raw;\n}\n\nasync function readConfigFile(repoPath: string): Promise<Partial<DryConfig>> {\n const configPath = upath.join(repoPath, \"dryconfig.json\");\n try {\n const content = await fs.readFile(configPath, \"utf8\");\n let parsed: Partial<DryConfig> = {};\n try {\n parsed = JSON.parse(content) as Partial<DryConfig>;\n } catch (parseErr) {\n throw new Error(`Invalid JSON in ${configPath}: ${(parseErr as Error).message}`);\n }\n return parsed;\n } catch (err: any) {\n if (err?.code === \"ENOENT\") {\n return {};\n }\n throw err;\n }\n}\n\n/**\n * Resolves the effective config for a repo using defaults merged with any file config.\n */\nexport async function resolveDryConfig(repoPath: string): Promise<DryConfig> {\n const fileConfigRaw = await readConfigFile(repoPath);\n validateConfig(fileConfigRaw, partialConfigSchema, \"Config file\");\n\n const merged = { ...DEFAULT_CONFIG, ...fileConfigRaw };\n validateConfig(merged, fullConfigSchema, \"Merged\");\n return merged as DryConfig;\n}\n\n// Backwards-compatible helper used by existing callers (file + defaults).\nexport async function loadDryConfig(repoPath: string): Promise<DryConfig> {\n return resolveDryConfig(repoPath);\n}\n\nexport async function saveDryConfig(repoPath: string, config: DryConfig): Promise<void> {\n const configPath = upath.join(repoPath, \"dryconfig.json\");\n validateConfig(config, fullConfigSchema, \"Config to save\");\n await fs.writeFile(configPath, JSON.stringify(config, null, 2), \"utf8\");\n}\n\nexport async function ensureDefaultConfig(repoPath: string): Promise<void> {\n const configPath = upath.join(repoPath, \"dryconfig.json\");\n const repoExists = await fs.stat(repoPath).then((s) => s.isDirectory()).catch((err: any) => {\n if (err?.code === \"ENOENT\") return false;\n throw err;\n });\n\n if (!repoExists) return;\n\n const exists = await fs.stat(configPath).then(() => true).catch((err: any) => {\n if (err?.code === \"ENOENT\") return false;\n throw err;\n });\n\n if (!exists) {\n await saveDryConfig(repoPath, DEFAULT_CONFIG);\n }\n}\n","import path from \"path\";\nimport fs from \"fs/promises\";\nimport upath from \"upath\";\nimport { glob } from \"glob-gitignore\";\nimport ignore, { Ignore } from \"ignore\";\nimport { DryConfig } from \"./types\";\n\n/**\n * Gitignore helper that builds ignore matchers by combining default rules,\n * repo .gitignore files, and config-driven exclusions.\n */\nexport class Gitignore {\n private readonly defaultIgnores = [\".git/**\", \".dry/**\"];\n\n constructor(private readonly root: string) {}\n\n async buildMatcher(config: DryConfig): Promise<Ignore> {\n const rules = await this.resolveRules(config);\n return ignore({ allowRelativePaths: true }).add(rules);\n }\n\n private async resolveRules(config: DryConfig): Promise<string[]> {\n const gitignoreRules = await this.loadGitignoreRules();\n const configRules = config.excludedPaths || [];\n return [...this.defaultIgnores, ...gitignoreRules, ...configRules];\n }\n\n private async loadGitignoreRules(): Promise<string[]> {\n const gitignoreFiles = await glob(\"**/.gitignore\", {\n cwd: this.root,\n dot: true,\n nodir: true,\n ignore: this.defaultIgnores,\n });\n\n const rules: string[] = [];\n\n for (const file of gitignoreFiles) {\n const absPath = path.join(this.root, file);\n const dir = upath.normalizeTrim(upath.dirname(file));\n const content = await fs.readFile(absPath, \"utf8\").catch(() => \"\");\n const lines = content.split(/\\r?\\n/);\n\n for (const raw of lines) {\n const trimmed = raw.trim();\n if (!trimmed || trimmed.startsWith(\"#\")) continue;\n\n const negated = trimmed.startsWith(\"!\");\n const body = negated ? trimmed.slice(1) : trimmed;\n\n const scoped = this.scopeRule(body, dir);\n if (!scoped) continue;\n\n rules.push(negated ? `!${scoped}` : scoped);\n }\n }\n\n return rules;\n }\n\n private scopeRule(rule: string, gitignoreDir: string): string | null {\n const cleaned = rule.replace(/^\\//, \"\");\n if (!cleaned) return null;\n\n if (!gitignoreDir || gitignoreDir === \".\") {\n return cleaned;\n }\n\n return upath.normalizeTrim(upath.join(gitignoreDir, cleaned));\n }\n}\n","import \"reflect-metadata\";\nimport fs from \"fs/promises\";\nimport upath from \"upath\";\nimport { DataSource, Repository, In } from \"typeorm\";\nimport { FileEntity } from \"./entities/FileEntity\";\nimport { IndexUnit } from \"../types\";\nimport { IndexUnitEntity } from \"./entities/IndexUnitEntity\";\n\nexport class DryScanDatabase {\n private dataSource?: DataSource;\n private unitRepository?: Repository<IndexUnitEntity>;\n private fileRepository?: Repository<FileEntity>;\n\n isInitialized(): boolean {\n return !!this.dataSource?.isInitialized;\n }\n\n async init(dbPath: string): Promise<void> {\n await fs.mkdir(upath.dirname(dbPath), { recursive: true });\n\n this.dataSource = new DataSource({\n type: \"sqlite\",\n database: dbPath,\n entities: [IndexUnitEntity, FileEntity],\n synchronize: true,\n logging: false,\n });\n\n await this.dataSource.initialize();\n this.unitRepository = this.dataSource.getRepository(IndexUnitEntity);\n this.fileRepository = this.dataSource.getRepository(FileEntity);\n }\n\n async saveUnit(unit: IndexUnit): Promise<void> {\n await this.saveUnits(unit);\n }\n\n async saveUnits(units: IndexUnit | IndexUnit[]): Promise<void> {\n if (!this.unitRepository) throw new Error(\"Database not initialized\");\n const payload = Array.isArray(units) ? units : [units];\n const BATCH_SIZE = 500;\n for (let i = 0; i < payload.length; i += BATCH_SIZE) {\n console.debug(`[DryScanDatabase] Saving units ${i + 1}-${Math.min(i + BATCH_SIZE, payload.length)} of ${payload.length}...`);\n const batch = payload.slice(i, i + BATCH_SIZE);\n await this.unitRepository.save(batch);\n }\n }\n\n async getUnit(id: string): Promise<IndexUnit | null> {\n if (!this.unitRepository) throw new Error(\"Database not initialized\");\n return this.unitRepository.findOne({\n where: { id },\n relations: [\"children\", \"parent\"]\n });\n }\n\n async getAllUnits(): Promise<IndexUnit[]> {\n if (!this.unitRepository) throw new Error(\"Database not initialized\");\n return this.unitRepository.find({ relations: [\"children\", \"parent\"] });\n }\n\n async updateUnit(unit: IndexUnit): Promise<void> {\n await this.saveUnits(unit);\n }\n\n async updateUnits(units: IndexUnit | IndexUnit[]): Promise<void> {\n await this.saveUnits(units);\n }\n\n /**\n * Returns total count of indexed units.\n */\n async countUnits(): Promise<number> {\n if (!this.unitRepository) throw new Error(\"Database not initialized\");\n return this.unitRepository.count();\n }\n\n /**\n * Removes index units by their file paths.\n * Used during incremental updates when files change.\n */\n async removeUnitsByFilePaths(filePaths: string[]): Promise<void> {\n if (!this.unitRepository) throw new Error(\"Database not initialized\");\n await this.unitRepository.delete({ filePath: In(filePaths) });\n }\n\n /**\n * Saves file metadata (path, checksum, mtime) to track changes.\n */\n async saveFile(file: FileEntity): Promise<void> {\n if (!this.fileRepository) throw new Error(\"Database not initialized\");\n await this.fileRepository.save(file);\n }\n\n /**\n * Saves multiple file metadata entries.\n */\n async saveFiles(files: FileEntity[]): Promise<void> {\n if (!this.fileRepository) throw new Error(\"Database not initialized\");\n await this.fileRepository.save(files);\n }\n\n /**\n * Gets file metadata by file path.\n */\n async getFile(filePath: string): Promise<FileEntity | null> {\n if (!this.fileRepository) throw new Error(\"Database not initialized\");\n return this.fileRepository.findOne({ where: { filePath } });\n }\n\n /**\n * Gets all tracked files.\n */\n async getAllFiles(): Promise<FileEntity[]> {\n if (!this.fileRepository) throw new Error(\"Database not initialized\");\n return this.fileRepository.find();\n }\n\n /**\n * Removes file metadata entries by file paths.\n * Used when files are deleted from repository.\n */\n async removeFilesByFilePaths(filePaths: string[]): Promise<void> {\n if (!this.fileRepository) throw new Error(\"Database not initialized\");\n await this.fileRepository.delete({ filePath: In(filePaths) });\n }\n\n async close(): Promise<void> {\n if (this.dataSource?.isInitialized) {\n await this.dataSource.destroy();\n }\n }\n}\n","import { Entity, PrimaryColumn, Column } from \"typeorm\";\n\n/**\n * Represents a tracked source file in the repository.\n * Used to detect changes via checksum and mtime for incremental updates.\n */\n@Entity(\"files\")\nexport class FileEntity {\n /**\n * Relative path to the file from repository root.\n * Used as primary key for uniqueness.\n */\n @PrimaryColumn(\"text\")\n filePath!: string;\n\n /**\n * MD5 checksum of file content.\n * Used to detect content changes.\n */\n @Column(\"text\")\n checksum!: string;\n\n /**\n * Last modification time in milliseconds since epoch.\n * Used as fast sanity check before computing checksum.\n */\n @Column(\"integer\")\n mtime!: number;\n}\n","import {\n Column,\n Entity,\n JoinColumn,\n ManyToOne,\n OneToMany,\n PrimaryColumn,\n RelationId,\n} from \"typeorm\";\nimport { IndexUnit, IndexUnitType } from \"../../types\";\n\n@Entity(\"index_units\")\nexport class IndexUnitEntity implements IndexUnit {\n @PrimaryColumn(\"text\")\n id!: string;\n\n @Column(\"text\")\n name!: string;\n\n @Column(\"text\")\n filePath!: string;\n\n @Column(\"integer\")\n startLine!: number;\n\n @Column(\"integer\")\n endLine!: number;\n\n @Column(\"text\")\n code!: string;\n\n @Column(\"text\")\n unitType!: IndexUnitType;\n\n @ManyToOne(() => IndexUnitEntity, (unit) => unit.children, {\n nullable: true,\n onDelete: \"CASCADE\",\n })\n @JoinColumn({ name: \"parent_id\" })\n parent?: IndexUnitEntity | null;\n\n @RelationId((unit: IndexUnitEntity) => unit.parent)\n parentId?: string | null;\n\n @OneToMany(() => IndexUnitEntity, (unit) => unit.parent, { nullable: true })\n children?: IndexUnitEntity[];\n\n @Column(\"simple-array\", { nullable: true })\n embedding?: number[] | null;\n}\n","import path from \"path\";\nimport fs from \"fs/promises\";\nimport { DryScanServiceDeps } from \"./types\";\nimport { ExclusionService } from \"./ExclusionService\";\nimport { IndexUnit } from \"../types\";\nimport { EmbeddingService } from \"./EmbeddingService\";\nimport { FileEntity } from \"../db/entities/FileEntity\";\nimport { IndexUnitExtractor } from \"../IndexUnitExtractor\";\n\nexport interface InitOptions {\n skipEmbeddings?: boolean;\n}\n\nexport class RepositoryInitializer {\n constructor(\n private readonly deps: DryScanServiceDeps,\n private readonly exclusionService: ExclusionService\n ) {}\n\n async init(options?: InitOptions): Promise<void> {\n const extractor = this.deps.extractor;\n\n console.log(\"[DryScan] Phase 1/3: Extracting code units...\");\n await this.initUnits(extractor);\n console.log(\"[DryScan] Phase 2/3: Computing embeddings (may be slow)...\");\n await this.computeEmbeddings(options?.skipEmbeddings === true);\n console.log(\"[DryScan] Phase 3/3: Tracking files...\");\n await this.trackFiles(extractor);\n await this.exclusionService.cleanupExcludedFiles();\n console.log(\"[DryScan] Initialization phases complete.\");\n }\n\n private async initUnits(extractor: IndexUnitExtractor): Promise<void> {\n const units = await extractor.scan(this.deps.repoPath);\n console.log(`[DryScan] Extracted ${units.length} index units.`);\n await this.deps.db.saveUnits(units);\n }\n\n private async computeEmbeddings(skipEmbeddings: boolean): Promise<void> {\n if (skipEmbeddings) {\n console.log(\"[DryScan] Skipping embedding computation by request.\");\n return;\n }\n const allUnits: IndexUnit[] = await this.deps.db.getAllUnits();\n const total = allUnits.length;\n console.log(`[DryScan] Computing embeddings for ${total} units...`);\n\n const updated: IndexUnit[] = [];\n const progressInterval = Math.max(1, Math.ceil(total / 10));\n const embeddingService = new EmbeddingService(this.deps.repoPath);\n\n for (let i = 0; i < total; i++) {\n const unit = allUnits[i];\n try {\n const enriched = await embeddingService.addEmbedding(unit);\n updated.push(enriched);\n } catch (err: any) {\n console.error(\n `[DryScan] Embedding failed for ${unit.filePath} (${unit.name}): ${err?.message || err}`\n );\n throw err;\n }\n\n const completed = i + 1;\n if (completed === total || completed % progressInterval === 0) {\n const pct = Math.floor((completed / total) * 100);\n console.log(`[DryScan] Embeddings ${completed}/${total} (${pct}%)`);\n }\n }\n\n await this.deps.db.updateUnits(updated);\n }\n\n private async trackFiles(extractor: IndexUnitExtractor): Promise<void> {\n const allFunctions = await extractor.listSourceFiles(this.deps.repoPath);\n const fileEntities: FileEntity[] = [];\n\n for (const relPath of allFunctions) {\n const fullPath = path.join(this.deps.repoPath, relPath);\n const stat = await fs.stat(fullPath);\n const checksum = await extractor.computeChecksum(fullPath);\n\n const fileEntity = new FileEntity();\n fileEntity.filePath = relPath;\n fileEntity.checksum = checksum;\n fileEntity.mtime = stat.mtimeMs;\n fileEntities.push(fileEntity);\n }\n\n await this.deps.db.saveFiles(fileEntities);\n console.log(`[DryScan] Tracked ${fileEntities.length} files.`);\n }\n}","import debug from \"debug\";\nimport { OllamaEmbeddings } from \"@langchain/ollama\";\nimport { HuggingFaceInferenceEmbeddings } from \"@langchain/community/embeddings/hf\";\nimport { IndexUnit } from \"../types\";\nimport { configStore } from \"../config/configStore\";\n\nconst log = debug(\"DryScan:EmbeddingService\");\n\n// Model names for each provider\nconst OLLAMA_MODEL = \"qwen3-embedding:0.6b\";\nconst HUGGINGFACE_MODEL = \"Qwen/Qwen3-Embedding-0.6B\";\n\nexport class EmbeddingService {\n constructor(private readonly repoPath: string) { }\n\n /**\n * Generates an embedding for the given index unit using the configured provider.\n * Skips embedding if code exceeds the configured context length.\n */\n async addEmbedding(fn: IndexUnit): Promise<IndexUnit> {\n const config = await configStore.get(this.repoPath);\n const maxContext = config?.contextLength ?? 2048;\n if (fn.code.length > maxContext) {\n log(\n \"Skipping embedding for %s (code length %d exceeds context %d)\",\n fn.id,\n fn.code.length,\n maxContext\n );\n return { ...fn, embedding: null };\n }\n\n const source = config.embeddingSource;\n if (!source) {\n const message = `Embedding source is not configured for repository at ${this.repoPath}`;\n log(message);\n throw new Error(message);\n }\n\n const embeddings = this.buildProvider(source);\n const embedding = await embeddings.embedQuery(fn.code);\n return { ...fn, embedding };\n }\n\n /**\n * Builds the embedding provider based on the source configuration.\n * - URL (http/https): Uses Ollama with \"embeddinggemma\" model\n * - \"huggingface\": Uses HuggingFace Inference API with \"embeddinggemma-300m\" model\n */\n private buildProvider(source: string) {\n // HuggingFace Inference API\n if (source.toLowerCase() === \"huggingface\") {\n log(\"Using HuggingFace Inference with model: %s\", HUGGINGFACE_MODEL);\n return new HuggingFaceInferenceEmbeddings({\n model: HUGGINGFACE_MODEL,\n provider: \"hf-inference\",\n });\n }\n\n // Ollama keyword or direct URL\n const ollamaBaseUrl = this.resolveOllamaBaseUrl(source);\n if (ollamaBaseUrl !== null) {\n log(\"Using Ollama%s with model: %s\", ollamaBaseUrl ? ` at ${ollamaBaseUrl}` : \"\", OLLAMA_MODEL);\n return new OllamaEmbeddings({ model: OLLAMA_MODEL, ...(ollamaBaseUrl && { baseUrl: ollamaBaseUrl }) });\n }\n\n const message = `Unsupported embedding source: ${source || \"(empty)\"}. Use \"huggingface\" or an Ollama URL.`;\n log(message);\n throw new Error(message);\n }\n\n /**\n * Returns the Ollama base URL if source is an HTTP URL, undefined if source is \"ollama\" (use default),\n * or null if source is not an Ollama provider at all.\n */\n private resolveOllamaBaseUrl(source: string): string | undefined | null {\n if (/^https?:\\/\\//i.test(source)) return source;\n if (source.toLowerCase() === \"ollama\") return undefined;\n return null;\n }\n}","import debug from \"debug\";\nimport { DryScanServiceDeps } from \"./types\";\nimport { ExclusionService } from \"./ExclusionService\";\nimport { performIncrementalUpdate } from \"../DryScanUpdater\";\nimport { DuplicationCache } from \"./DuplicationCache\";\n\nconst log = debug(\"DryScan:UpdateService\");\n\nexport class UpdateService {\n constructor(\n private readonly deps: DryScanServiceDeps,\n private readonly exclusionService: ExclusionService\n ) {}\n\n /** Returns the list of file paths that were modified or deleted (dirty). */\n async updateIndex(): Promise<string[]> {\n const extractor = this.deps.extractor;\n const cache = DuplicationCache.getInstance();\n\n try {\n const changeSet = await performIncrementalUpdate(this.deps.repoPath, extractor, this.deps.db);\n await this.exclusionService.cleanupExcludedFiles();\n const dirtyPaths = [...changeSet.changed, ...changeSet.deleted, ...changeSet.added];\n await cache.invalidate(dirtyPaths);\n return dirtyPaths;\n } catch (err) {\n log(\"Error during index update:\", err);\n throw err;\n }\n }\n}","import path from \"path\";\nimport fs from \"fs/promises\";\nimport debug from \"debug\";\nimport { IndexUnit } from \"./types\";\nimport { IndexUnitExtractor } from \"./IndexUnitExtractor\";\nimport { DryScanDatabase } from \"./db/DryScanDatabase\";\nimport { FileEntity } from \"./db/entities/FileEntity\";\nimport { EmbeddingService } from \"./services/EmbeddingService\";\n\nconst log = debug(\"DryScan:Updater\");\n\n/**\n * DryScan Updater Module\n * \n * This module contains all incremental update logic for DryScan.\n * Separated from DryScan.ts to keep that file focused on core operations.\n * \n * Represents the result of change detection.\n * Categorizes files into added, changed, deleted, and unchanged.\n */\nexport interface FileChangeSet {\n added: string[];\n changed: string[];\n deleted: string[];\n unchanged: string[];\n}\n\n/**\n * Detects which files have been added, changed, or deleted since last scan.\n * Uses mtime as fast check, then checksum for verification.\n * \n * @param repoPath - Root path of the repository\n * @param extractor - Index unit extractor instance for file operations\n * @param db - Database instance for retrieving tracked files\n * @returns Change set with categorized file paths\n */\nexport async function detectFileChanges(\n repoPath: string,\n extractor: IndexUnitExtractor,\n db: DryScanDatabase\n): Promise<FileChangeSet> {\n // Get current files in repository\n const currentFiles = await extractor.listSourceFiles(repoPath);\n const currentFileSet = new Set(currentFiles);\n\n // Get tracked files from database\n const trackedFiles = await db.getAllFiles();\n const trackedFileMap = new Map(trackedFiles.map(f => [f.filePath, f]));\n\n const added: string[] = [];\n const changed: string[] = [];\n const unchanged: string[] = [];\n\n // Check each current file\n for (const filePath of currentFiles) {\n const tracked = trackedFileMap.get(filePath);\n \n if (!tracked) {\n // New file\n added.push(filePath);\n continue;\n }\n\n // Check if file changed using mtime first (fast check)\n const fullPath = path.join(repoPath, filePath);\n const stat = await fs.stat(fullPath);\n \n if (stat.mtimeMs !== tracked.mtime) {\n // Mtime changed, verify with checksum\n const currentChecksum = await extractor.computeChecksum(fullPath);\n if (currentChecksum !== tracked.checksum) {\n changed.push(filePath);\n } else {\n // Mtime changed but content same\n unchanged.push(filePath);\n }\n } else {\n unchanged.push(filePath);\n }\n }\n\n // Find deleted files\n const deleted = trackedFiles\n .map(f => f.filePath)\n .filter(fp => !currentFileSet.has(fp));\n\n return { added, changed, deleted, unchanged };\n}\n\n/**\n * Extracts index units from a list of files.\n * Used during incremental updates.\n * \n * @param filePaths - Array of relative file paths to extract from\n * @param extractor - Index unit extractor instance\n * @returns Array of extracted units\n */\nexport async function extractUnitsFromFiles(\n filePaths: string[],\n extractor: IndexUnitExtractor\n): Promise<IndexUnit[]> {\n const allUnits: IndexUnit[] = [];\n \n for (const relPath of filePaths) {\n const functions = await extractor.scan(relPath);\n allUnits.push(...functions);\n }\n \n return allUnits;\n}\n\n/**\n * Updates file tracking metadata after processing changes.\n * Removes deleted files, updates changed files, adds new files.\n * \n * @param changeSet - Set of file changes to apply\n * @param repoPath - Root path of the repository\n * @param extractor - Index unit extractor for checksum computation\n * @param db - Database instance for file tracking\n */\nexport async function updateFileTracking(\n changeSet: FileChangeSet,\n repoPath: string,\n extractor: IndexUnitExtractor,\n db: DryScanDatabase\n): Promise<void> {\n // Remove deleted files\n if (changeSet.deleted.length > 0) {\n if (typeof (db as any).removeFilesByFilePaths === \"function\") {\n await (db as any).removeFilesByFilePaths(changeSet.deleted);\n } else if (typeof (db as any).removeFiles === \"function\") {\n await (db as any).removeFiles(changeSet.deleted);\n }\n }\n\n // Create file entities for new and changed files\n const filesToTrack = [...changeSet.added, ...changeSet.changed];\n if (filesToTrack.length > 0) {\n const fileEntities: FileEntity[] = [];\n \n for (const relPath of filesToTrack) {\n const fullPath = path.join(repoPath, relPath);\n const stat = await fs.stat(fullPath);\n const checksum = await extractor.computeChecksum(fullPath);\n \n const fileEntity = new FileEntity();\n fileEntity.filePath = relPath;\n fileEntity.checksum = checksum;\n fileEntity.mtime = stat.mtimeMs;\n \n fileEntities.push(fileEntity);\n }\n \n await db.saveFiles(fileEntities);\n }\n}\n\n/**\n * Performs incremental update of the DryScan index.\n * Detects file changes and reprocesses only affected files.\n * \n * @param repoPath - Root path of the repository\n * @param extractor - Index unit extractor instance\n * @param db - Database instance (must be initialized)\n */\nexport async function performIncrementalUpdate(\n repoPath: string,\n extractor: IndexUnitExtractor,\n db: DryScanDatabase,\n): Promise<FileChangeSet> {\n log(\"Starting incremental update\");\n const embeddingService = new EmbeddingService(repoPath);\n \n // Step 1: Detect changes\n const changeSet = await detectFileChanges(repoPath, extractor, db);\n \n if (changeSet.changed.length === 0 && \n changeSet.added.length === 0 && \n changeSet.deleted.length === 0) {\n log(\"No changes detected. Index is up to date.\");\n return changeSet;\n }\n\n log(`Changes detected: ${changeSet.added.length} added, ${changeSet.changed.length} changed, ${changeSet.deleted.length} deleted`);\n\n // Step 2: Remove old data for changed/deleted files\n const filesToRemove = [...changeSet.changed, ...changeSet.deleted];\n if (filesToRemove.length > 0) {\n await db.removeUnitsByFilePaths(filesToRemove);\n log(`Removed units from ${filesToRemove.length} files`);\n }\n\n // Step 3: Extract functions from new/changed files\n const filesToProcess = [...changeSet.added, ...changeSet.changed];\n if (filesToProcess.length > 0) {\n const newUnits = await extractUnitsFromFiles(filesToProcess, extractor);\n await db.saveUnits(newUnits);\n log(`Extracted and saved ${newUnits.length} units from ${filesToProcess.length} files`);\n\n // Step 4: Recompute embeddings for affected units only\n const total = newUnits.length;\n if (total > 0) {\n log(`Recomputing embeddings for ${total} units`);\n const progressInterval = Math.max(1, Math.ceil(total / 10));\n const updatedWithEmbeddings = [] as IndexUnit[];\n\n for (let i = 0; i < total; i++) {\n const unit = newUnits[i];\n try {\n const enriched = await embeddingService.addEmbedding(unit);\n updatedWithEmbeddings.push(enriched);\n } catch (err: any) {\n console.error(\n `[DryScan] embedding failed for ${unit.filePath} (${unit.name}): ${err?.message || err}`\n );\n throw err;\n }\n\n const completed = i + 1;\n if (completed === total || completed % progressInterval === 0) {\n const pct = Math.floor((completed / total) * 100);\n console.log(`[DryScan] Incremental embeddings ${completed}/${total} (${pct}%)`);\n }\n }\n\n await db.updateUnits(updatedWithEmbeddings);\n log(`Recomputed embeddings for ${updatedWithEmbeddings.length} units`);\n }\n }\n\n // Step 5: Update file tracking\n await updateFileTracking(changeSet, repoPath, extractor, db);\n log(\"Incremental update complete\");\n\n return changeSet;\n}\n","import debug from \"debug\";\nimport { cosineSimilarity } from \"@langchain/core/utils/math\";\nimport { DuplicateGroup, IndexUnit } from \"../types\";\n\nconst log = debug(\"DryScan:DuplicationCache\");\n\n/**\n * In-memory cache for duplicate comparison scores.\n * Stores a global map of comparison keys and a per-file index for fast invalidation.\n */\nexport class DuplicationCache {\n private static instance: DuplicationCache | null = null;\n\n private readonly comparisons = new Map<string, number>();\n private readonly fileIndex = new Map<string, Set<string>>();\n private initialized = false;\n\n /** Per-run similarity matrix from a single batched library call (reset each run). */\n private embSimMatrix: number[][] = [];\n /** Maps unit ID to its row/column index in embSimMatrix. */\n private embSimIndex = new Map<string, number>();\n /** Per-run memoization of parent unit similarity scores (reset each run). */\n private parentSimCache = new Map<string, number>();\n\n static getInstance(): DuplicationCache {\n if (!DuplicationCache.instance) {\n DuplicationCache.instance = new DuplicationCache();\n }\n return DuplicationCache.instance;\n }\n\n /**\n * Updates the cache with fresh duplicate groups. Not awaited by callers to avoid blocking.\n */\n async update(groups: DuplicateGroup[]): Promise<void> {\n if (!groups) return;\n\n for (const group of groups) {\n const key = this.makeKey(group.left.id, group.right.id);\n this.comparisons.set(key, group.similarity);\n this.addKeyForFile(group.left.filePath, key);\n this.addKeyForFile(group.right.filePath, key);\n }\n\n this.initialized = this.initialized || groups.length > 0;\n }\n\n /**\n * Retrieves a cached similarity if present and valid for both file paths.\n * Returns null when the cache has not been initialized or when the pair is missing.\n */\n get(leftId: string, rightId: string, leftFilePath: string, rightFilePath: string): number | null {\n if (!this.initialized) return null;\n\n const key = this.makeKey(leftId, rightId);\n if (!this.fileHasKey(leftFilePath, key) || !this.fileHasKey(rightFilePath, key)) {\n return null;\n }\n\n const value = this.comparisons.get(key);\n return typeof value === \"number\" ? value : null;\n }\n\n /**\n * Invalidates all cached comparisons involving the provided file paths.\n */\n async invalidate(paths: string[]): Promise<void> {\n if (!this.initialized || !paths || paths.length === 0) return;\n\n const unique = new Set(paths);\n for (const filePath of unique) {\n const keys = this.fileIndex.get(filePath);\n if (!keys) continue;\n\n for (const key of keys) {\n this.comparisons.delete(key);\n for (const [otherPath, otherKeys] of this.fileIndex.entries()) {\n if (otherKeys.delete(key) && otherKeys.size === 0) {\n this.fileIndex.delete(otherPath);\n }\n }\n }\n\n this.fileIndex.delete(filePath);\n }\n\n if (this.comparisons.size === 0) {\n this.initialized = false;\n }\n }\n\n /**\n * Clears all cached data. Intended for test setup.\n */\n clear(): void {\n this.comparisons.clear();\n this.fileIndex.clear();\n this.initialized = false;\n this.embSimMatrix = [];\n this.embSimIndex.clear();\n this.clearRunCaches();\n }\n\n /**\n * Resets per-run memoization (parent similarities).\n * The embedding matrix is intentionally preserved so incremental runs can\n * reuse clean×clean values across calls.\n */\n clearRunCaches(): void {\n this.parentSimCache.clear();\n }\n\n /**\n * Builds or incrementally updates the embedding similarity matrix.\n *\n * Full rebuild (default): replaces the entire matrix — O(n²).\n * Incremental (dirtyPaths provided + prior matrix exists): copies clean×clean\n * cells from the old matrix and recomputes only dirty rows via one batched\n * cosineSimilarity call — O(d·n) where d = number of dirty units.\n */\n buildEmbSimCache(units: IndexUnit[], dirtyPaths?: string[]): void {\n const embedded = units.filter(u => Array.isArray(u.embedding) && u.embedding.length > 0);\n if (embedded.length < 2) {\n this.embSimMatrix = [];\n this.embSimIndex.clear();\n return;\n }\n\n const embeddings = embedded.map(u => u.embedding as number[]);\n const newIndex = new Map(embedded.map((u, i) => [u.id, i] as [string, number]));\n const dirtySet = dirtyPaths ? new Set(dirtyPaths) : null;\n const hasPriorMatrix = this.embSimMatrix.length > 0;\n\n if (!dirtySet || !hasPriorMatrix) {\n // Full rebuild\n this.embSimIndex = newIndex;\n this.embSimMatrix = cosineSimilarity(embeddings, embeddings);\n log(\"Built full embedding similarity matrix: %d units\", embedded.length);\n return;\n }\n\n // Incremental: identify dirty unit IDs\n const dirtyIds = new Set(embedded.filter(u => dirtySet.has(u.filePath)).map(u => u.id));\n\n if (dirtyIds.size === 0) {\n log(\"Matrix reused: no dirty units detected\");\n return;\n }\n\n const n = embedded.length;\n\n // Start with zeroes; copy clean×clean values from prior matrix\n const newMatrix: number[][] = Array.from({ length: n }, () => new Array(n).fill(0));\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n if (dirtyIds.has(embedded[i].id) || dirtyIds.has(embedded[j].id)) continue;\n const oi = this.embSimIndex.get(embedded[i].id);\n const oj = this.embSimIndex.get(embedded[j].id);\n if (oi !== undefined && oj !== undefined) newMatrix[i][j] = this.embSimMatrix[oi][oj];\n }\n }\n\n // Recompute dirty rows in one batched call\n const dirtyIndices = embedded.reduce<number[]>((acc, u, i) => (dirtyIds.has(u.id) ? [...acc, i] : acc), []);\n const dirtyRows = cosineSimilarity(dirtyIndices.map(i => embeddings[i]), embeddings);\n dirtyIndices.forEach((rowIdx, di) => {\n for (let j = 0; j < n; j++) {\n newMatrix[rowIdx][j] = dirtyRows[di][j];\n newMatrix[j][rowIdx] = dirtyRows[di][j];\n }\n });\n\n this.embSimIndex = newIndex;\n this.embSimMatrix = newMatrix;\n log(\"Incremental matrix update: %d dirty unit(s) out of %d total\", dirtyIds.size, n);\n }\n\n /** Returns the pre-computed cosine similarity for a pair of unit IDs, if available. */\n getEmbSim(id1: string, id2: string): number | undefined {\n const i = this.embSimIndex.get(id1);\n const j = this.embSimIndex.get(id2);\n if (i === undefined || j === undefined) return undefined;\n return this.embSimMatrix[i][j];\n }\n\n /** Returns the memoized parent similarity for the given stable key, if available. */\n getParentSim(key: string): number | undefined {\n return this.parentSimCache.get(key);\n }\n\n /** Stores a memoized parent similarity for the given stable key. */\n setParentSim(key: string, sim: number): void {\n this.parentSimCache.set(key, sim);\n }\n\n private addKeyForFile(filePath: string, key: string): void {\n const current = this.fileIndex.get(filePath) ?? new Set<string>();\n current.add(key);\n this.fileIndex.set(filePath, current);\n }\n\n private fileHasKey(filePath: string, key: string): boolean {\n const keys = this.fileIndex.get(filePath);\n return keys ? keys.has(key) : false;\n }\n\n private makeKey(leftId: string, rightId: string): string {\n return [leftId, rightId].sort().join(\"::\");\n }\n}\n","import debug from \"debug\";\nimport shortUuid from \"short-uuid\";\nimport { DryScanServiceDeps } from \"./types\";\nimport { DuplicateAnalysisResult, DuplicateGroup, DuplicationScore, IndexUnit, IndexUnitType } from \"../types\";\nimport { indexConfig } from \"../config/indexConfig\";\nimport { DryConfig } from \"../types\";\nimport { DuplicationCache } from \"./DuplicationCache\";\n\nconst log = debug(\"DryScan:DuplicateService\");\n\nexport class DuplicateService {\n private config?: DryConfig;\n private readonly cache = DuplicationCache.getInstance();\n\n constructor(private readonly deps: DryScanServiceDeps) {}\n\n /**\n * @param dirtyPaths - File paths changed since last run. When provided, only\n * dirty×all similarities are recomputed; clean×clean values are reused from\n * the existing matrix. Pass undefined (or omit) for a full rebuild.\n */\n async findDuplicates(config: DryConfig, dirtyPaths?: string[]): Promise<DuplicateAnalysisResult> {\n this.config = config;\n const t0 = performance.now();\n const allUnits = await this.deps.db.getAllUnits();\n log(\"Starting duplicate analysis on %d units\", allUnits.length);\n\n if (allUnits.length < 2) {\n return { duplicates: [], score: this.computeDuplicationScore([], allUnits) };\n }\n\n const thresholds = this.resolveThresholds(config.threshold);\n const duplicates = this.computeDuplicates(allUnits, thresholds, dirtyPaths);\n const filtered = duplicates.filter((g) => !this.isGroupExcluded(g));\n log(\"Found %d duplicate groups (%d excluded)\", filtered.length, duplicates.length - filtered.length);\n\n this.cache.update(filtered).catch((err) => log(\"Cache update failed: %O\", err));\n\n const score = this.computeDuplicationScore(filtered, allUnits);\n log(\"findDuplicates completed in %dms\", (performance.now() - t0).toFixed(2));\n return { duplicates: filtered, score };\n }\n\n private resolveThresholds(functionThreshold?: number): { function: number; block: number; class: number } {\n const d = indexConfig.thresholds;\n const clamp = (v: number) => Math.min(1, Math.max(0, v));\n const fn = clamp(functionThreshold ?? d.function);\n return {\n function: fn,\n block: clamp(fn + d.block - d.function),\n class: clamp(fn + d.class - d.function),\n };\n }\n\n private computeDuplicates(\n units: IndexUnit[],\n thresholds: { function: number; block: number; class: number },\n dirtyPaths?: string[]\n ): DuplicateGroup[] {\n this.cache.clearRunCaches();\n this.cache.buildEmbSimCache(units, dirtyPaths);\n\n const duplicates: DuplicateGroup[] = [];\n const t0 = performance.now();\n\n for (const [type, typedUnits] of this.groupByType(units)) {\n const threshold = this.getThreshold(type, thresholds);\n log(\"Comparing %d %s units (threshold=%.3f)\", typedUnits.length, type, threshold);\n\n for (let i = 0; i < typedUnits.length; i++) {\n for (let j = i + 1; j < typedUnits.length; j++) {\n const left = typedUnits[i], right = typedUnits[j];\n if (this.shouldSkipComparison(left, right)) continue;\n\n // Always check the cache first — this allows pairs whose embeddings\n // have since been cleared to still be reported using a prior score.\n const cached = this.cache.get(left.id, right.id, left.filePath, right.filePath);\n const hasEmbeddings = left.embedding?.length && right.embedding?.length;\n const similarity = cached ?? (hasEmbeddings ? this.computeWeightedSimilarity(left, right, threshold) : 0);\n if (similarity < threshold) continue;\n\n const exclusionString = this.deps.pairing.pairKeyForUnits(left, right);\n if (!exclusionString) continue;\n\n duplicates.push({\n id: `${left.id}::${right.id}`,\n similarity,\n shortId: shortUuid.generate(),\n exclusionString,\n left: this.toMember(left),\n right: this.toMember(right),\n });\n }\n }\n }\n\n log(\"computeDuplicates: %d duplicates in %dms\", duplicates.length, (performance.now() - t0).toFixed(2));\n return duplicates.sort((a, b) => b.similarity - a.similarity);\n }\n\n private isGroupExcluded(group: DuplicateGroup): boolean {\n const config = this.config;\n if (!config?.excludedPairs?.length) return false;\n const key = this.deps.pairing.pairKeyForUnits(group.left, group.right);\n if (!key) return false;\n const actual = this.deps.pairing.parsePairKey(key);\n if (!actual) return false;\n return config.excludedPairs.some((entry) => {\n const parsed = this.deps.pairing.parsePairKey(entry);\n return parsed ? this.deps.pairing.pairKeyMatches(actual, parsed) : false;\n });\n }\n\n private getThreshold(type: IndexUnitType, thresholds: { function: number; block: number; class: number }): number {\n if (type === IndexUnitType.CLASS) return thresholds.class;\n if (type === IndexUnitType.BLOCK) return thresholds.block;\n return thresholds.function;\n }\n\n private computeWeightedSimilarity(left: IndexUnit, right: IndexUnit, threshold: number): number {\n const selfSim = this.similarity(left, right);\n\n //CLASS\n if (left.unitType === IndexUnitType.CLASS) {\n return selfSim * indexConfig.weights.class.self;\n }\n\n // FUNCTION\n if (left.unitType === IndexUnitType.FUNCTION) {\n const w = indexConfig.weights.function;\n const hasPC = this.bothHaveParent(left, right, IndexUnitType.CLASS);\n const total = w.self + (hasPC ? w.parentClass : 0);\n // Early exit: even with perfect parent similarity, can't reach threshold.\n if ((w.self * selfSim + (hasPC ? w.parentClass : 0)) / total < threshold) return 0;\n return (w.self * selfSim + (hasPC ? w.parentClass * this.parentSimilarity(left, right, IndexUnitType.CLASS) : 0)) / total;\n }\n\n // BLOCK\n const w = indexConfig.weights.block;\n const hasPF = this.bothHaveParent(left, right, IndexUnitType.FUNCTION);\n const hasPC = this.bothHaveParent(left, right, IndexUnitType.CLASS);\n const total = w.self + (hasPF ? w.parentFunction : 0) + (hasPC ? w.parentClass : 0);\n if ((w.self * selfSim + (hasPF ? w.parentFunction : 0) + (hasPC ? w.parentClass : 0)) / total < threshold) return 0;\n return (\n w.self * selfSim +\n (hasPF ? w.parentFunction * this.parentSimilarity(left, right, IndexUnitType.FUNCTION) : 0) +\n (hasPC ? w.parentClass * this.parentSimilarity(left, right, IndexUnitType.CLASS) : 0)\n ) / total;\n }\n\n /** Groups all units by type for the comparison loop. Units without embeddings are included\n * so that cache hits can still be returned for pairs whose embeddings were cleared. */\n private groupByType(units: IndexUnit[]): Map<IndexUnitType, IndexUnit[]> {\n const byType = new Map<IndexUnitType, IndexUnit[]>();\n for (const unit of units) {\n const list = byType.get(unit.unitType) ?? [];\n list.push(unit);\n byType.set(unit.unitType, list);\n }\n return byType;\n }\n\n private toMember(unit: IndexUnit): DuplicateGroup[\"left\"] {\n return {\n id: unit.id,\n name: unit.name,\n filePath: unit.filePath,\n startLine: unit.startLine,\n endLine: unit.endLine,\n code: unit.code,\n unitType: unit.unitType,\n };\n }\n\n private bothHaveParent(left: IndexUnit, right: IndexUnit, type: IndexUnitType): boolean {\n return !!this.findParent(left, type) && !!this.findParent(right, type);\n }\n\n private parentSimilarity(left: IndexUnit, right: IndexUnit, type: IndexUnitType): number {\n const lp = this.findParent(left, type), rp = this.findParent(right, type);\n if (!lp || !rp) return 0;\n\n const key = lp.id < rp.id ? `${lp.id}::${rp.id}` : `${rp.id}::${lp.id}`;\n const cached = this.cache.getParentSim(key);\n if (cached !== undefined) return cached;\n\n const sim = this.similarity(lp, rp);\n this.cache.setParentSim(key, sim);\n return sim;\n }\n\n /** Resolves similarity via the pre-computed embedding matrix, falling back to best child match. */\n private similarity(left: IndexUnit, right: IndexUnit): number {\n return this.cache.getEmbSim(left.id, right.id) ?? this.childSimilarity(left, right);\n }\n\n private childSimilarity(left: IndexUnit, right: IndexUnit): number {\n const lc = left.children ?? [], rc = right.children ?? [];\n if (!lc.length || !rc.length) return 0;\n\n let best = 0;\n for (const l of lc) {\n for (const r of rc) {\n if (l.unitType !== r.unitType) continue;\n const sim = this.similarity(l, r);\n if (sim > best) best = sim;\n }\n }\n return best;\n }\n\n private shouldSkipComparison(left: IndexUnit, right: IndexUnit): boolean {\n if (left.unitType !== IndexUnitType.BLOCK || right.unitType !== IndexUnitType.BLOCK) return false;\n if (left.filePath !== right.filePath) return false;\n return (left.startLine <= right.startLine && left.endLine >= right.endLine)\n || (right.startLine <= left.startLine && right.endLine >= left.endLine);\n }\n\n private findParent(unit: IndexUnit, type: IndexUnitType): IndexUnit | null {\n let p = unit.parent;\n while (p) {\n if (p.unitType === type) return p;\n p = p.parent;\n }\n return null;\n }\n\n private computeDuplicationScore(duplicates: DuplicateGroup[], allUnits: IndexUnit[]): DuplicationScore {\n const totalLines = allUnits.reduce((sum, u) => sum + u.endLine - u.startLine + 1, 0);\n\n if (!totalLines || !duplicates.length) {\n return { score: 0, grade: \"Excellent\", totalLines, duplicateLines: 0, duplicateGroups: 0 };\n }\n\n const duplicateLines = duplicates.reduce((sum, g) => {\n const avg = ((g.left.endLine - g.left.startLine + 1) + (g.right.endLine - g.right.startLine + 1)) / 2;\n return sum + g.similarity * avg;\n }, 0);\n\n const score = (duplicateLines / totalLines) * 100;\n return {\n score,\n grade: this.getScoreGrade(score),\n totalLines,\n duplicateLines: Math.round(duplicateLines),\n duplicateGroups: duplicates.length,\n };\n }\n\n private getScoreGrade(score: number): DuplicationScore[\"grade\"] {\n if (score < 5) return \"Excellent\";\n if (score < 15) return \"Good\";\n if (score < 30) return \"Fair\";\n if (score < 50) return \"Poor\";\n return \"Critical\";\n }\n}","import { DryConfig } from \"../types\";\nimport { configStore } from \"../config/configStore\";\nimport { DryScanServiceDeps } from \"./types\";\nimport { IndexUnitType } from \"../types\";\nimport { minimatch } from \"minimatch\";\nimport { ParsedPairKey } from \"./PairingService\";\n\nexport class ExclusionService {\n private config?: DryConfig;\n\n constructor(private readonly deps: DryScanServiceDeps) {}\n\n async cleanupExcludedFiles(): Promise<void> {\n const config = await this.loadConfig();\n if (!config.excludedPaths || config.excludedPaths.length === 0) return;\n\n const units = await this.deps.db.getAllUnits();\n const files = await this.deps.db.getAllFiles();\n\n const unitPathsToRemove = new Set<string>();\n for (const unit of units) {\n if (this.pathExcluded(unit.filePath)) {\n unitPathsToRemove.add(unit.filePath);\n }\n }\n\n const filePathsToRemove = new Set<string>();\n for (const file of files) {\n if (this.pathExcluded(file.filePath)) {\n filePathsToRemove.add(file.filePath);\n }\n }\n\n const paths = [...new Set([...unitPathsToRemove, ...filePathsToRemove])];\n if (paths.length > 0) {\n await this.deps.db.removeUnitsByFilePaths(paths);\n await this.deps.db.removeFilesByFilePaths(paths);\n }\n }\n\n async cleanExclusions(): Promise<{ removed: number; kept: number }> {\n const config = await this.loadConfig();\n const units = await this.deps.db.getAllUnits();\n\n const actualPairsByType = {\n [IndexUnitType.CLASS]: this.buildPairKeys(units, IndexUnitType.CLASS),\n [IndexUnitType.FUNCTION]: this.buildPairKeys(units, IndexUnitType.FUNCTION),\n [IndexUnitType.BLOCK]: this.buildPairKeys(units, IndexUnitType.BLOCK),\n };\n\n const kept: string[] = [];\n const removed: string[] = [];\n\n for (const entry of config.excludedPairs || []) {\n const parsed = this.deps.pairing.parsePairKey(entry);\n if (!parsed) {\n removed.push(entry);\n continue;\n }\n\n const candidates = actualPairsByType[parsed.type];\n const matched = candidates.some((actual) => this.deps.pairing.pairKeyMatches(actual, parsed));\n if (matched) {\n kept.push(entry);\n } else {\n removed.push(entry);\n }\n }\n\n const nextConfig: DryConfig = { ...config, excludedPairs: kept };\n await configStore.save(this.deps.repoPath, nextConfig);\n this.config = nextConfig;\n\n return { removed: removed.length, kept: kept.length };\n }\n\n private pathExcluded(filePath: string): boolean {\n const config = this.config;\n if (!config || !config.excludedPaths || config.excludedPaths.length === 0) return false;\n return config.excludedPaths.some((pattern) => minimatch(filePath, pattern, { dot: true }));\n }\n\n private buildPairKeys(units: any[], type: IndexUnitType): ParsedPairKey[] {\n const typed = units.filter((u) => u.unitType === type);\n const pairs: ParsedPairKey[] = [];\n for (let i = 0; i < typed.length; i++) {\n for (let j = i + 1; j < typed.length; j++) {\n const key = this.deps.pairing.pairKeyForUnits(typed[i], typed[j]);\n const parsed = key ? this.deps.pairing.parsePairKey(key) : null;\n if (parsed) {\n pairs.push(parsed);\n }\n }\n }\n return pairs;\n }\n\n private async loadConfig(): Promise<DryConfig> {\n this.config = await configStore.get(this.deps.repoPath);\n return this.config;\n }\n}","import crypto from \"node:crypto\";\nimport debug from \"debug\";\nimport { minimatch } from \"minimatch\";\nimport { LanguageExtractor } from \"../extractors/LanguageExtractor\";\nimport { IndexUnitExtractor } from \"../IndexUnitExtractor\";\nimport { IndexUnit, IndexUnitType } from \"../types\";\nimport { BLOCK_HASH_ALGO } from \"../const\";\n\nconst log = debug(\"DryScan:pairs\");\n\ntype UnitLike = Pick<IndexUnit, \"unitType\" | \"filePath\" | \"name\" | \"code\">;\n\nexport interface ParsedPairKey {\n type: IndexUnitType;\n left: string;\n right: string;\n key: string;\n}\n\n/**\n * Service for building and parsing pair keys with extractor-aware labeling.\n */\nexport class PairingService {\n constructor(private readonly indexUnitExtractor: IndexUnitExtractor) {}\n\n /**\n * Creates a stable, order-independent key for two units of the same type.\n * Returns null when units differ in type so callers can skip invalid pairs.\n */\n pairKeyForUnits(left: UnitLike, right: UnitLike): string | null {\n if (left.unitType !== right.unitType) {\n log(\"Skipping pair with mismatched types: %s vs %s\", left.unitType, right.unitType);\n return null;\n }\n const type = left.unitType;\n const leftLabel = this.unitLabel(left);\n const rightLabel = this.unitLabel(right);\n const [a, b] = [leftLabel, rightLabel].sort();\n return `${type}|${a}|${b}`;\n }\n\n /**\n * Parses a raw pair key into its components, returning null for malformed values.\n * Sorting is applied so callers can compare pairs without worrying about order.\n */\n parsePairKey(value: string): ParsedPairKey | null {\n const parts = value.split(\"|\");\n if (parts.length !== 3) {\n log(\"Invalid pair key format: %s\", value);\n return null;\n }\n const [typeRaw, leftRaw, rightRaw] = parts;\n const type = this.stringToUnitType(typeRaw);\n if (!type) {\n log(\"Unknown unit type in pair key: %s\", typeRaw);\n return null;\n }\n const [left, right] = [leftRaw, rightRaw].sort();\n return { type, left, right, key: `${type}|${left}|${right}` };\n }\n\n /**\n * Checks whether an actual pair key satisfies a pattern, with glob matching for class paths.\n */\n pairKeyMatches(actual: ParsedPairKey, pattern: ParsedPairKey): boolean {\n if (actual.type !== pattern.type) return false;\n if (actual.type === IndexUnitType.CLASS) {\n // Allow glob matching for class file paths.\n const forward =\n minimatch(actual.left, pattern.left, { dot: true }) &&\n minimatch(actual.right, pattern.right, { dot: true });\n const swapped =\n minimatch(actual.left, pattern.right, { dot: true }) &&\n minimatch(actual.right, pattern.left, { dot: true });\n return forward || swapped;\n }\n\n // Functions and blocks use exact matching on canonical strings.\n return (\n (actual.left === pattern.left && actual.right === pattern.right) ||\n (actual.left === pattern.right && actual.right === pattern.left)\n );\n }\n\n /**\n * Derives a reversible, extractor-aware label for a unit.\n * Extractors may override; fallback uses a fixed format per unit type.\n */\n unitLabel(unit: UnitLike): string {\n const extractor = this.findExtractor(unit.filePath);\n const customLabel = extractor?.unitLabel?.(unit as IndexUnit);\n if (customLabel) return customLabel;\n\n switch (unit.unitType) {\n case IndexUnitType.CLASS:\n return unit.filePath;\n case IndexUnitType.FUNCTION:\n return this.canonicalFunctionSignature(unit);\n case IndexUnitType.BLOCK:\n return this.normalizedBlockHash(unit);\n default:\n return unit.name;\n }\n }\n\n private findExtractor(filePath: string): LanguageExtractor | undefined {\n return this.indexUnitExtractor.extractors.find((ex) => ex.supports(filePath));\n }\n\n private canonicalFunctionSignature(unit: UnitLike): string {\n const arity = this.extractArity(unit.code);\n return `${unit.name}(arity:${arity})`;\n }\n\n /**\n * Normalizes block code (strips comments/whitespace) and hashes it for pair matching.\n */\n private normalizedBlockHash(unit: UnitLike): string {\n const normalized = this.normalizeCode(unit.code);\n return crypto.createHash(BLOCK_HASH_ALGO).update(normalized).digest(\"hex\");\n }\n\n private stringToUnitType(value: string): IndexUnitType | null {\n if (value === IndexUnitType.CLASS) return IndexUnitType.CLASS;\n if (value === IndexUnitType.FUNCTION) return IndexUnitType.FUNCTION;\n if (value === IndexUnitType.BLOCK) return IndexUnitType.BLOCK;\n return null;\n }\n\n private extractArity(code: string): number {\n const match = code.match(/^[^{]*?\\(([^)]*)\\)/s);\n if (!match) return 0;\n const params = match[1]\n .split(\",\")\n .map((p) => p.trim())\n .filter(Boolean);\n return params.length;\n }\n\n private normalizeCode(code: string): string {\n const withoutBlockComments = code.replace(/\\/\\*[\\s\\S]*?\\*\\//g, \"\");\n const withoutLineComments = withoutBlockComments.replace(/\\/\\/[^\\n\\r]*/g, \"\");\n return withoutLineComments.replace(/\\s+/g, \"\");\n }\n}\n"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,YAAW;AAClB,OAAOC,SAAQ;;;ACDR,IAAM,cAAc;AACpB,IAAM,WAAW;AAEjB,IAAM,qBAAqB;AAC3B,IAAM,kBAAkB;;;ACJ/B,OAAOC,WAAU;AAEjB,OAAOC,SAAQ;AACf,OAAOC,YAAW;AAClB,OAAOC,aAAY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AI;AACjC,YAAQ,IAAI,sCAAsC,WAAW,KAAK;AAElE,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,kBAA8D;AAClE,UAAM,KAAK,YAAY;AACvB,WAAO,KAAK,SAAS,UAAU,gBAAgB;AAAA,EACjD;AAAA,EAEA,MAAc,iBAAgC;AAC5C,QAAI,KAAK,GAAG,cAAc,EAAG;AAC7B,UAAM,SAASA,OAAM,KAAK,KAAK,UAAU,aAAa,QAAQ;AAC9D,UAAMC,IAAG,MAAMD,OAAM,QAAQ,MAAM,GAAG,EAAE,WAAW,KAAK,CAAC;AACzD,UAAM,KAAK,GAAG,KAAK,MAAM;AAAA,EAC3B;AAAA,EAEA,MAAc,aAAiC;AAC7C,WAAO,YAAY,IAAI,KAAK,QAAQ;AAAA,EACtC;AAEF;","names":["upath","fs","path","fs","upath","crypto","glob","upath","upath","fs","upath","path","fs","crypto","upath","glob","fs","upath","Column","Entity","PrimaryColumn","PrimaryColumn","Column","Entity","fs","upath","path","fs","debug","log","debug","path","fs","debug","path","fs","debug","log","debug","path","fs","debug","log","log","debug","debug","log","debug","w","hasPC","total","crypto","debug","minimatch","log","debug","minimatch","crypto","upath","fs"]}
|
|
1
|
+
{"version":3,"sources":["../src/DryScan.ts","../src/const.ts","../src/IndexUnitExtractor.ts","../src/extractors/java.ts","../src/config/indexConfig.ts","../src/config/configStore.ts","../src/config/dryconfig.ts","../src/Gitignore.ts","../src/db/DryScanDatabase.ts","../src/db/entities/FileEntity.ts","../src/db/entities/IndexUnitEntity.ts","../src/services/RepositoryInitializer.ts","../src/services/EmbeddingService.ts","../src/services/UpdateService.ts","../src/DryScanUpdater.ts","../src/services/DuplicationCache.ts","../src/services/DuplicateService.ts","../src/services/ExclusionService.ts","../src/services/PairingService.ts"],"sourcesContent":["import upath from \"upath\";\nimport fs from \"fs/promises\";\nimport { DuplicateAnalysisResult, DuplicateReport } from \"./types\";\nimport { DRYSCAN_DIR, INDEX_DB } from \"./const\";\nimport { defaultExtractors, IndexUnitExtractor } from \"./IndexUnitExtractor\";\nimport { DryScanDatabase } from \"./db/DryScanDatabase\";\nimport { RepositoryInitializer, InitOptions as InitServiceOptions } from \"./services/RepositoryInitializer\";\nimport { UpdateService } from \"./services/UpdateService\";\nimport { DuplicateService } from \"./services/DuplicateService\";\nimport { ExclusionService } from \"./services/ExclusionService\";\nimport { DryScanServiceDeps } from \"./services/types\";\nimport { configStore } from \"./config/configStore\";\nimport { DryConfig } from \"./types\";\nimport { PairingService } from \"./services/PairingService\";\nimport { existsSync } from \"fs\";\n\nexport type InitOptions = InitServiceOptions;\n\n\nexport class DryScan {\n repoPath: string;\n private readonly extractor: IndexUnitExtractor;\n private db: DryScanDatabase;\n private readonly services: {\n initializer: RepositoryInitializer;\n updater: UpdateService;\n duplicate: DuplicateService;\n exclusion: ExclusionService;\n };\n private readonly serviceDeps: DryScanServiceDeps;\n\n constructor(\n repoPath: string,\n extractor?: IndexUnitExtractor,\n db?: DryScanDatabase\n ) {\n this.repoPath = repoPath;\n this.extractor = extractor ?? new IndexUnitExtractor(repoPath, defaultExtractors(repoPath));\n this.db = db ?? new DryScanDatabase();\n\n this.serviceDeps = {\n repoPath: this.repoPath,\n db: this.db,\n extractor: this.extractor,\n pairing: new PairingService(this.extractor),\n };\n\n const exclusion = new ExclusionService(this.serviceDeps);\n this.services = {\n initializer: new RepositoryInitializer(this.serviceDeps, exclusion),\n updater: new UpdateService(this.serviceDeps, exclusion),\n duplicate: new DuplicateService(this.serviceDeps),\n exclusion,\n };\n }\n\n /**\n * Initializes the DryScan repository with a 3-phase analysis:\n * Phase 1: Extract and save all functions\n * Phase 2: Resolve and save internal dependencies\n * Phase 3: Compute and save semantic embeddings\n */\n async init(options?: InitOptions): Promise<void> {\n console.log(`[DryScan] Initializing repository at ${this.repoPath}`);\n\n const dryDir = upath.join(this.repoPath, DRYSCAN_DIR);\n if (existsSync(dryDir)) {\n console.warn(`[DryScan] Warning: a '.dry' folder already exists at ${dryDir}.`);\n }\n console.log(\"[DryScan] Preparing database and cache...\");\n await configStore.init(this.repoPath);\n await this.ensureDatabase();\n console.log(\"[DryScan] Starting initial scan (may take a moment)...\");\n await this.services.initializer.init(options);\n console.log(\"[DryScan] Initial scan complete.\");\n }\n\n /**\n * Updates the index by detecting changed, new, and deleted files.\n * Only reprocesses units in changed files for efficiency.\n * Delegates to DryScanUpdater module for implementation.\n * \n * Update process:\n * 1. List all current source files in repository\n * 2. For each file, check if it's new, changed, or unchanged (via mtime + checksum)\n * 3. Remove old units from changed/deleted files\n * 4. Extract and save units from new/changed files\n * 5. Recompute internal dependencies for affected units\n * 6. Recompute embeddings for affected units\n * 7. Update file tracking metadata\n */\n async updateIndex(): Promise<string[]> {\n console.log(`[DryScan] Updating index at ${this.repoPath}...`);\n console.log(\"[DryScan] Checking for file changes...\");\n const start = Date.now();\n await this.ensureDatabase();\n const dirtyPaths = await this.services.updater.updateIndex();\n const duration = Date.now() - start;\n console.log(`[DryScan] Index update complete. Took ${duration}ms.`);\n return dirtyPaths;\n }\n\n\n /**\n * Runs duplicate detection and returns a normalized report payload ready for persistence or display.\n */\n async buildDuplicateReport(): Promise<DuplicateReport> {\n const config = await this.loadConfig();\n const analysis = await this.findDuplicates(config);\n return {\n version: 1,\n generatedAt: new Date().toISOString(),\n threshold: config.threshold,\n grade: analysis.score.grade,\n score: analysis.score,\n duplicates: analysis.duplicates,\n };\n }\n\n /**\n * Finds duplicate code blocks using cosine similarity on embeddings.\n * Automatically updates the index before searching to ensure results are current.\n * Compares all function pairs and returns groups with similarity above the configured threshold.\n *\n * @returns Analysis result with duplicate groups and duplication score\n */\n private async findDuplicates(config: DryConfig): Promise<DuplicateAnalysisResult> {\n console.log(`[DryScan] Finding duplicates (threshold: ${config.threshold})...`);\n await this.ensureDatabase();\n\n console.log(\"[DryScan] Updating index...\");\n const updateStart = Date.now();\n const dirtyPaths = await this.updateIndex();\n const updateDuration = Date.now() - updateStart;\n console.log(`[DryScan] Index update took ${updateDuration}ms.`);\n\n console.log(\"[DryScan] Detecting duplicates...\");\n const dupStart = Date.now();\n const result = await this.services.duplicate.findDuplicates(config, dirtyPaths);\n const dupDuration = Date.now() - dupStart;\n console.log(`[DryScan] Duplicate detection took ${dupDuration}ms.`);\n\n return result;\n }\n\n /**\n * Cleans excludedPairs entries that no longer match any indexed units.\n * Runs an update first to ensure the index reflects current code.\n */\n async cleanExclusions(): Promise<{ removed: number; kept: number }> {\n await this.updateIndex();\n return this.services.exclusion.cleanExclusions();\n }\n\n private async ensureDatabase(): Promise<void> {\n if (this.db.isInitialized()) return;\n const dbPath = upath.join(this.repoPath, DRYSCAN_DIR, INDEX_DB);\n await fs.mkdir(upath.dirname(dbPath), { recursive: true });\n await this.db.init(dbPath);\n }\n\n private async loadConfig(): Promise<DryConfig> {\n return configStore.get(this.repoPath);\n }\n\n}\n","export const DRYSCAN_DIR = \".dry\";\nexport const INDEX_DB = \"index.db\";\nexport const REPORTS_DIR = \"reports\";\nexport const FILE_CHECKSUM_ALGO = \"md5\";\nexport const BLOCK_HASH_ALGO = \"sha1\";","import path from \"path\";\nimport type { Stats } from \"fs\";\nimport fs from \"fs/promises\";\nimport upath from \"upath\";\nimport crypto from \"node:crypto\";\nimport debug from \"debug\";\nimport { glob } from \"glob-gitignore\";\nimport { IndexUnit } from \"./types\";\nimport { LanguageExtractor } from \"./extractors/LanguageExtractor\";\nimport { JavaExtractor } from \"./extractors/java\";\nimport { FILE_CHECKSUM_ALGO } from \"./const\";\nimport { configStore } from \"./config/configStore\";\nimport { DryConfig } from \"./types\";\nimport { Gitignore } from \"./Gitignore\"\nimport { Ignore } from \"ignore\";\n\nconst log = debug(\"DryScan:Extractor\");\n\nexport type { LanguageExtractor } from \"./extractors/LanguageExtractor\";\n/**\n * Returns the default set of language extractors supported by DryScan.\n * Extend/override by passing custom extractors into the IndexUnitExtractor constructor.\n */\nexport function defaultExtractors(repoPath: string): LanguageExtractor[] {\n return [new JavaExtractor(repoPath)];\n}\n\n/**\n * Extracts and indexes code units (classes, functions, blocks) for a repository.\n * Owns shared file-system helpers and delegates language-specific parsing to LanguageExtractors.\n */\nexport class IndexUnitExtractor {\n private readonly root: string;\n readonly extractors: LanguageExtractor[];\n private readonly gitignore: Gitignore;\n\n constructor(\n rootPath: string,\n extractors?: LanguageExtractor[]\n ) {\n this.root = rootPath;\n this.extractors = extractors ?? defaultExtractors(rootPath);\n this.gitignore = new Gitignore(this.root);\n log(\"Initialized extractor for %s\", this.root);\n }\n\n /**\n * Lists all supported source files from a path. Honors exclusion globs from config.\n */\n async listSourceFiles(dirPath: string): Promise<string[]> {\n const target = await this.resolveTarget(dirPath);\n const config = await this.loadConfig();\n const ignoreMatcher = await this.gitignore.buildMatcher(config);\n\n if (target.stat.isFile()) {\n return this.filterSingleFile(target.baseRel, ignoreMatcher);\n }\n\n const matches = await this.globSourceFiles(target.baseRel);\n return this.filterSupportedFiles(matches, ignoreMatcher);\n }\n\n /**\n * Computes MD5 checksum of file content to track changes.\n */\n async computeChecksum(filePath: string): Promise<string> {\n const fullPath = path.isAbsolute(filePath)\n ? filePath\n : path.join(this.root, filePath);\n\n const content = await fs.readFile(fullPath, \"utf8\");\n return crypto.createHash(FILE_CHECKSUM_ALGO).update(content).digest(\"hex\");\n }\n\n /**\n * Scans a file or directory and extracts indexable units using the matching LanguageExtractor.\n * The returned units have repo-relative file paths and no embedding attached.\n */\n async scan(targetPath: string): Promise<IndexUnit[]> {\n const fullPath = path.isAbsolute(targetPath)\n ? targetPath\n : path.join(this.root, targetPath);\n\n const stat = await fs.stat(fullPath).catch(() => null);\n if (!stat) {\n throw new Error(`Path not found: ${fullPath}`);\n }\n\n if (stat.isDirectory()) {\n log(\"Scanning directory %s\", fullPath);\n return this.scanDirectory(fullPath);\n }\n\n return this.scanFile(fullPath);\n }\n\n\n /**\n * Scans a directory recursively, extracting units from supported files while honoring exclusions.\n */\n private async scanDirectory(dir: string): Promise<IndexUnit[]> {\n const out: IndexUnit[] = [];\n const relDir = this.relPath(dir);\n const files = await this.listSourceFiles(relDir);\n for (const relFile of files) {\n const absFile = path.join(this.root, relFile);\n const extracted = await this.tryScanSupportedFile(absFile);\n out.push(...extracted);\n }\n return out;\n }\n\n /**\n * Scans a single file and extracts supported units.\n */\n private async scanFile(filePath: string): Promise<IndexUnit[]> {\n return this.tryScanSupportedFile(filePath, true);\n }\n\n /**\n * Extracts units from a supported file.\n * Optionally throws when the file type is unsupported (used when scanning an explicit file).\n */\n private async tryScanSupportedFile(filePath: string, throwOnUnsupported = false): Promise<IndexUnit[]> {\n const extractor = this.extractors.find(ex => ex.supports(filePath));\n if (!extractor) {\n if (throwOnUnsupported) {\n throw new Error(`Unsupported file type: ${filePath}`);\n }\n return [];\n }\n const rel = this.relPath(filePath);\n if (await this.shouldExclude(rel)) {\n log(\"Skipping excluded file %s\", rel);\n return [];\n }\n const source = await fs.readFile(filePath, \"utf8\");\n const units = await extractor.extractFromText(rel, source);\n log(\"Extracted %d units from %s\", units.length, rel);\n return units.map(unit => ({\n ...unit,\n filePath: rel,\n embedding: undefined,\n }));\n }\n\n /**\n * Converts an absolute path to a repo-relative, normalized (POSIX-style) path.\n * This keeps paths stable across platforms and consistent in the index/DB.\n */\n private relPath(absPath: string): string {\n return this.normalizeRelPath(upath.relative(this.root, absPath));\n }\n\n /**\n * Returns true if a repo-relative path matches any configured exclusion glob.\n */\n private async shouldExclude(relPath: string): Promise<boolean> {\n const config = await this.loadConfig();\n const ignoreMatcher = await this.gitignore.buildMatcher(config);\n return ignoreMatcher.ignores(this.normalizeRelPath(relPath));\n }\n\n private async loadConfig(): Promise<DryConfig> {\n return await configStore.get(this.root);\n }\n\n /**\n * Normalizes repo-relative paths and strips leading \"./\" to keep matcher inputs consistent.\n */\n private normalizeRelPath(relPath: string): string {\n const normalized = upath.normalizeTrim(relPath);\n return normalized.startsWith(\"./\") ? normalized.slice(2) : normalized;\n }\n\n private async resolveTarget(dirPath: string): Promise<{ fullPath: string; baseRel: string; stat: Stats; }> {\n const fullPath = path.isAbsolute(dirPath) ? dirPath : path.join(this.root, dirPath);\n const stat = await fs.stat(fullPath).catch(() => null);\n if (!stat) {\n throw new Error(`Path not found: ${fullPath}`);\n }\n const baseRel = this.relPath(fullPath);\n log(\"Listing source files under %s\", fullPath);\n return { fullPath, baseRel, stat };\n }\n\n private async filterSingleFile(baseRel: string, ignoreMatcher: Ignore): Promise<string[]> {\n const relFile = this.normalizeRelPath(baseRel);\n if (ignoreMatcher.ignores(relFile)) return [];\n return this.extractors.some((ex) => ex.supports(relFile)) ? [relFile] : [];\n }\n\n private async globSourceFiles(baseRel: string): Promise<string[]> {\n const pattern = baseRel ? `${baseRel.replace(/\\\\/g, \"/\")}/**/*` : \"**/*\";\n const matches = await glob(pattern, {\n cwd: this.root,\n dot: false,\n nodir: true,\n });\n return matches.map((p: string) => this.normalizeRelPath(p));\n }\n\n private filterSupportedFiles(relPaths: string[], ignoreMatcher: Ignore): string[] {\n return relPaths\n .filter((relPath: string) => !ignoreMatcher.ignores(relPath))\n .filter((relPath: string) => this.extractors.some((ex) => ex.supports(relPath)));\n }\n}\n","import crypto from \"node:crypto\";\nimport Parser from \"tree-sitter\";\nimport Java from \"tree-sitter-java\";\nimport { LanguageExtractor } from \"./LanguageExtractor\";\nimport { IndexUnit, IndexUnitType } from \"../types\";\nimport { indexConfig } from \"../config/indexConfig\";\nimport { DryConfig } from \"../types\";\nimport { configStore } from \"../config/configStore\";\nimport { BLOCK_HASH_ALGO } from \"../const\";\n\nexport class JavaExtractor implements LanguageExtractor {\n readonly id = \"java\";\n readonly exts = [\".java\"];\n\n private parser: Parser;\n private readonly repoPath: string;\n private config?: DryConfig;\n\n constructor(repoPath: string) {\n this.repoPath = repoPath;\n this.parser = new Parser();\n this.parser.setLanguage(Java);\n }\n\n supports(filePath: string): boolean {\n const lower = filePath.toLowerCase();\n return this.exts.some((ext) => lower.endsWith(ext));\n }\n\n async extractFromText(fileRelPath: string, source: string): Promise<IndexUnit[]> {\n if (!source.trim()) return [];\n\n this.config = await configStore.get(this.repoPath);\n\n const tree = this.parser.parse(source);\n const units: IndexUnit[] = [];\n\n const visit = (node: Parser.SyntaxNode, currentClass?: IndexUnit) => {\n if (this.isClassNode(node)) {\n const className = this.getClassName(node, source) || \"<anonymous>\";\n if (this.isDtoClass(node, source, className)) {\n return;\n }\n const startLine = node.startPosition.row;\n const endLine = node.endPosition.row;\n const classLength = endLine - startLine;\n const skipClass = this.shouldSkip(IndexUnitType.CLASS, className, classLength);\n const classId = this.buildId(IndexUnitType.CLASS, className, startLine, endLine);\n const code = this.stripComments(this.stripClassBody(node, source));\n const classUnit: IndexUnit = {\n id: classId,\n name: className,\n filePath: fileRelPath,\n startLine,\n endLine,\n code,\n unitType: IndexUnitType.CLASS,\n children: [],\n };\n if (!skipClass) {\n units.push(classUnit);\n }\n\n for (let i = 0; i < node.namedChildCount; i++) {\n const child = node.namedChild(i);\n if (child) visit(child, skipClass ? undefined : classUnit);\n }\n return;\n }\n\n if (this.isFunctionNode(node)) {\n const fnUnit = this.buildFunctionUnit(node, source, fileRelPath, currentClass);\n const fnLength = fnUnit.endLine - fnUnit.startLine;\n const bodyNode = this.getFunctionBody(node);\n const fnArity = this.getNodeArity(node);\n const skipFunction = this.shouldSkip(IndexUnitType.FUNCTION, fnUnit.name, fnLength, fnArity);\n\n if (skipFunction) {\n return;\n }\n\n units.push(fnUnit);\n\n if (bodyNode) {\n const blocks = this.extractBlocks(bodyNode, source, fileRelPath, fnUnit);\n units.push(...blocks);\n }\n }\n\n for (let i = 0; i < node.namedChildCount; i++) {\n const child = node.namedChild(i);\n if (child) visit(child, currentClass);\n }\n };\n\n visit(tree.rootNode);\n\n //remove duplicates if any\n return this.removeDuplicates(units);\n }\n\n unitLabel(unit: IndexUnit): string | null {\n if (unit.unitType === IndexUnitType.CLASS) return unit.filePath;\n if (unit.unitType === IndexUnitType.FUNCTION) return this.canonicalFunctionSignature(unit);\n if (unit.unitType === IndexUnitType.BLOCK) return this.normalizedBlockHash(unit);\n return unit.name;\n }\n\n private isClassNode(node: Parser.SyntaxNode): boolean {\n return node.type === \"class_declaration\";\n }\n\n private getClassName(node: Parser.SyntaxNode, source: string): string | null {\n const nameNode = node.childForFieldName?.(\"name\");\n return nameNode ? source.slice(nameNode.startIndex, nameNode.endIndex) : null;\n }\n\n private isFunctionNode(node: Parser.SyntaxNode): boolean {\n return node.type === \"method_declaration\" || node.type === \"constructor_declaration\";\n }\n\n private getFunctionName(node: Parser.SyntaxNode, source: string, parentClass?: IndexUnit): string | null {\n const nameNode = node.childForFieldName?.(\"name\");\n const nameText = nameNode ? source.slice(nameNode.startIndex, nameNode.endIndex) : \"<anonymous>\";\n return parentClass ? `${parentClass.name}.${nameText}` : nameText;\n }\n\n private getFunctionBody(node: Parser.SyntaxNode): Parser.SyntaxNode | null {\n return node.childForFieldName?.(\"body\") ?? null;\n }\n\n private isBlockNode(node: Parser.SyntaxNode): boolean {\n return node.type === \"block\";\n }\n\n private getMethodBodiesForClass(node: Parser.SyntaxNode): Parser.SyntaxNode[] {\n const bodies: Parser.SyntaxNode[] = [];\n const classBody = node.children.find(child => child.type === \"class_body\");\n if (!classBody) return bodies;\n \n for (let i = 0; i < classBody.namedChildCount; i++) {\n const child = classBody.namedChild(i);\n if (!child) continue;\n if (child.type === \"method_declaration\" || child.type === \"constructor_declaration\") {\n const body = child.childForFieldName?.(\"body\");\n if (body) bodies.push(body);\n }\n }\n return bodies;\n }\n\n private canonicalFunctionSignature(unit: IndexUnit): string {\n const arity = this.extractArity(unit.code);\n return `${unit.name}(arity:${arity})`;\n }\n\n private normalizedBlockHash(unit: IndexUnit): string {\n const normalized = this.normalizeCode(unit.code);\n return crypto.createHash(BLOCK_HASH_ALGO).update(normalized).digest(\"hex\");\n }\n\n private shouldSkip(unitType: IndexUnitType, name: string, lineCount: number, arity?: number): boolean {\n if (!this.config) {\n throw new Error(\"Config not loaded before skip evaluation\");\n }\n const config = this.config;\n const minLines = unitType === IndexUnitType.BLOCK\n ? Math.max(indexConfig.blockMinLines, config.minBlockLines ?? 0)\n : config.minLines;\n const belowMin = minLines > 0 && lineCount < minLines;\n const trivial = unitType === IndexUnitType.FUNCTION && this.isTrivialFunction(name, arity ?? 0);\n return belowMin || trivial;\n }\n\n /**\n * A function is trivial if it follows a simple accessor pattern:\n * - getters/isers: name matches get[A-Z] or is[A-Z] with exactly 0 parameters\n * - setters: name matches set[A-Z] with at most 1 parameter\n * Methods like getUserById(Long id) have arity > 0 and are NOT trivial.\n */\n private isTrivialFunction(fullName: string, arity: number): boolean {\n const simpleName = fullName.split(\".\").pop() || fullName;\n const isGetter = /^(get|is)[A-Z]/.test(simpleName) && arity === 0;\n const isSetter = /^set[A-Z]/.test(simpleName) && arity <= 1;\n return isGetter || isSetter;\n }\n\n /** Counts the formal parameters of a method or constructor node. */\n private getNodeArity(node: Parser.SyntaxNode): number {\n const params = node.childForFieldName?.(\"parameters\");\n if (!params) return 0;\n return params.namedChildren.filter(c => c.type === \"formal_parameter\" || c.type === \"spread_parameter\").length;\n }\n\n private isDtoClass(node: Parser.SyntaxNode, source: string, className: string): boolean {\n const classBody = node.children.find((child) => child.type === \"class_body\");\n if (!classBody) return false;\n\n let hasField = false;\n\n for (let i = 0; i < classBody.namedChildCount; i++) {\n const child = classBody.namedChild(i);\n if (!child) continue;\n\n if (child.type === \"field_declaration\") {\n hasField = true;\n continue;\n }\n\n if (child.type.includes(\"annotation\")) {\n continue;\n }\n\n if (child.type === \"method_declaration\" || child.type === \"constructor_declaration\") {\n const simpleName = this.getSimpleFunctionName(child, source);\n const fullName = `${className}.${simpleName}`;\n const arity = this.getNodeArity(child);\n if (!this.isTrivialFunction(fullName, arity)) {\n return false;\n }\n continue;\n }\n\n return false;\n }\n\n return hasField;\n }\n\n private getSimpleFunctionName(node: Parser.SyntaxNode, source: string): string {\n const nameNode = node.childForFieldName?.(\"name\");\n return nameNode ? source.slice(nameNode.startIndex, nameNode.endIndex) : \"<anonymous>\";\n }\n\n private buildFunctionUnit(\n node: Parser.SyntaxNode,\n source: string,\n file: string,\n parentClass?: IndexUnit\n ): IndexUnit {\n const name = this.getFunctionName(node, source, parentClass) || \"<anonymous>\";\n const startLine = node.startPosition.row;\n const endLine = node.endPosition.row;\n const id = this.buildId(IndexUnitType.FUNCTION, name, startLine, endLine);\n const unit: IndexUnit = {\n id,\n name,\n filePath: file,\n startLine,\n endLine,\n children: [],\n code: this.stripComments(source.slice(node.startIndex, node.endIndex)),\n unitType: IndexUnitType.FUNCTION,\n parentId: parentClass?.id,\n parent: parentClass,\n };\n if (parentClass) {\n parentClass.children = parentClass.children || [];\n parentClass.children.push(unit);\n }\n return unit;\n }\n\n private extractBlocks(\n bodyNode: Parser.SyntaxNode,\n source: string,\n file: string,\n parentFunction: IndexUnit\n ): IndexUnit[] {\n const blocks: IndexUnit[] = [];\n\n const visit = (n: Parser.SyntaxNode) => {\n if (this.isBlockNode(n)) {\n const startLine = n.startPosition.row;\n const endLine = n.endPosition.row;\n const lineCount = endLine - startLine;\n if (this.shouldSkip(IndexUnitType.BLOCK, parentFunction.name, lineCount)) {\n return;\n }\n if (lineCount >= indexConfig.blockMinLines) {\n const id = this.buildId(IndexUnitType.BLOCK, parentFunction.name, startLine, endLine);\n const blockUnit: IndexUnit = {\n id,\n name: parentFunction.name,\n filePath: file,\n startLine,\n endLine,\n code: this.stripComments(source.slice(n.startIndex, n.endIndex)),\n unitType: IndexUnitType.BLOCK,\n parentId: parentFunction.id,\n parent: parentFunction,\n };\n const contextLength = this.config?.contextLength ?? 2048;\n const splitBlocks = this.textSplitBlockIfOverContextLimit(blockUnit, contextLength);\n parentFunction.children = parentFunction.children || [];\n parentFunction.children.push(...splitBlocks);\n blocks.push(...splitBlocks);\n }\n }\n\n for (let i = 0; i < n.namedChildCount; i++) {\n const child = n.namedChild(i);\n if (child) visit(child);\n }\n };\n\n visit(bodyNode);\n return blocks;\n }\n\n private stripClassBody(node: Parser.SyntaxNode, source: string): string {\n const classStart = node.startIndex;\n let code = source.slice(classStart, node.endIndex);\n\n const methodBodies: Array<{ start: number; end: number }> = [];\n const candidates = this.getMethodBodiesForClass(node);\n\n for (const body of candidates) {\n methodBodies.push({ start: body.startIndex - classStart, end: body.endIndex - classStart });\n }\n\n methodBodies.sort((a, b) => b.start - a.start);\n for (const body of methodBodies) {\n code = code.slice(0, body.start) + \" { }\" + code.slice(body.end);\n }\n\n return code;\n }\n\n private buildId(type: IndexUnitType, name: string, startLine: number, endLine: number): string {\n return `${type}:${name}:${startLine}-${endLine}`;\n }\n\n private extractArity(code: string): number {\n const match = code.match(/^[^{]*?\\(([^)]*)\\)/s);\n if (!match) return 0;\n const params = match[1]\n .split(\",\")\n .map((p) => p.trim())\n .filter(Boolean);\n return params.length;\n }\n\n private normalizeCode(code: string): string {\n const withoutBlockComments = code.replace(/\\/\\*[\\s\\S]*?\\*\\//g, \"\");\n const withoutLineComments = withoutBlockComments.replace(/\\/\\/[^\\n\\r]*/g, \"\");\n return withoutLineComments.replace(/\\s+/g, \"\");\n }\n\n private stripComments(code: string): string {\n const withoutBlockComments = code.replace(/\\/\\*[\\s\\S]*?\\*\\//g, (match) => match.replace(/[^\\n\\r]/g, \"\"));\n return withoutBlockComments.replace(/\\/\\/[^\\n\\r]*/g, \"\");\n }\n\n private removeDuplicates(units: IndexUnit[]): IndexUnit[] | PromiseLike<IndexUnit[]> {\n return Array.from(new Map(units.map(u => [u.id, u])).values());\n }\n\n /** Splits a block unit's code into chunks if it exceeds the context length limit. */\n private textSplitBlockIfOverContextLimit(unit: IndexUnit, contextLength: number): IndexUnit[] {\n if (unit.code.length <= contextLength) return [unit];\n\n const chunks: IndexUnit[] = [];\n let chunkIndex = 0;\n for (let i = 0; i < unit.code.length; i += contextLength) {\n chunks.push({\n ...unit,\n id: `${unit.id}:chunk${chunkIndex}`,\n code: unit.code.slice(i, i + contextLength),\n });\n chunkIndex++;\n }\n return chunks;\n }\n}\n\n","export const indexConfig = {\n blockMinLines: 5,\n thresholds: {\n class: 0.88,\n function: 0.88,\n block: 0.88,\n },\n weights: {\n class: { self: 1 },\n function: { self: 0.8, parentClass: 0.2 },\n block: { self: 0.7, parentFunction: 0.2, parentClass: 0.1 },\n },\n};\n","import upath from \"upath\";\nimport { DryConfig } from \"../types\";\nimport { ensureDefaultConfig, resolveDryConfig, saveDryConfig } from \"./dryconfig\";\n\nclass ConfigStore {\n private readonly cache = new Map<string, DryConfig>();\n private readonly loading = new Map<string, Promise<DryConfig>>();\n\n async init(repoPath: string): Promise<DryConfig> {\n const key = this.normalize(repoPath);\n return this.load(key, repoPath);\n }\n\n async get(repoPath: string): Promise<DryConfig> {\n const key = this.normalize(repoPath);\n const cached = this.cache.get(key);\n if (cached) return cached;\n return this.load(key, repoPath);\n }\n\n async refresh(repoPath: string): Promise<DryConfig> {\n const key = this.normalize(repoPath);\n this.cache.delete(key);\n return this.load(key, repoPath);\n }\n\n async save(repoPath: string, config: DryConfig): Promise<void> {\n const key = this.normalize(repoPath);\n await saveDryConfig(repoPath, config);\n this.cache.set(key, config);\n }\n\n private async load(key: string, repoPath: string): Promise<DryConfig> {\n const existing = this.loading.get(key);\n if (existing) return existing;\n\n const promise = ensureDefaultConfig(repoPath).then(() => resolveDryConfig(repoPath)).then((config) => {\n this.cache.set(key, config);\n this.loading.delete(key);\n return config;\n }).catch((err) => {\n this.loading.delete(key);\n throw err;\n });\n\n this.loading.set(key, promise);\n return promise;\n }\n\n private normalize(repoPath: string): string {\n return upath.normalizeTrim(upath.resolve(repoPath));\n }\n}\n\nexport const configStore = new ConfigStore();\n","import fs from \"fs/promises\";\nimport upath from \"upath\";\nimport { Validator, Schema } from \"jsonschema\";\nimport { DryConfig } from \"../types\";\n\n// Baseline config used when no file is present; exported so tests and constructors can seed defaults.\nexport const DEFAULT_CONFIG: DryConfig = {\n excludedPaths: [\n \"**/test/**\",\n ],\n excludedPairs: [],\n minLines: 3,\n minBlockLines: 5,\n threshold: 0.8,\n embeddingSource: \"http://localhost:11434\",\n contextLength: 2048,\n};\n\nconst validator = new Validator();\n\nconst partialConfigSchema: Schema = {\n type: \"object\",\n properties: {\n excludedPaths: { type: \"array\", items: { type: \"string\" } },\n excludedPairs: { type: \"array\", items: { type: \"string\" } },\n minLines: { type: \"number\" },\n minBlockLines: { type: \"number\" },\n threshold: { type: \"number\" },\n embeddingSource: { type: \"string\" },\n contextLength: { type: \"number\" },\n },\n};\n\nconst fullConfigSchema: Schema = {\n ...partialConfigSchema,\n required: [\n \"excludedPaths\",\n \"excludedPairs\",\n \"minLines\",\n \"minBlockLines\",\n \"threshold\",\n \"embeddingSource\",\n \"contextLength\",\n ],\n};\n\nfunction validateConfig(raw: unknown, schema: Schema, source: string): any {\n const result = validator.validate(raw, schema);\n if (!result.valid) {\n const details = result.errors.map((e) => e.stack).join(\"; \");\n throw new Error(`${source} config is invalid: ${details}`);\n }\n return raw;\n}\n\nasync function readConfigFile(repoPath: string): Promise<Partial<DryConfig>> {\n const configPath = upath.join(repoPath, \"dryconfig.json\");\n try {\n const content = await fs.readFile(configPath, \"utf8\");\n let parsed: Partial<DryConfig> = {};\n try {\n parsed = JSON.parse(content) as Partial<DryConfig>;\n } catch (parseErr) {\n throw new Error(`Invalid JSON in ${configPath}: ${(parseErr as Error).message}`);\n }\n return parsed;\n } catch (err: any) {\n if (err?.code === \"ENOENT\") {\n return {};\n }\n throw err;\n }\n}\n\n/**\n * Resolves the effective config for a repo using defaults merged with any file config.\n */\nexport async function resolveDryConfig(repoPath: string): Promise<DryConfig> {\n const fileConfigRaw = await readConfigFile(repoPath);\n validateConfig(fileConfigRaw, partialConfigSchema, \"Config file\");\n\n const merged = { ...DEFAULT_CONFIG, ...fileConfigRaw };\n validateConfig(merged, fullConfigSchema, \"Merged\");\n return merged as DryConfig;\n}\n\n// Backwards-compatible helper used by existing callers (file + defaults).\nexport async function loadDryConfig(repoPath: string): Promise<DryConfig> {\n return resolveDryConfig(repoPath);\n}\n\nexport async function saveDryConfig(repoPath: string, config: DryConfig): Promise<void> {\n const configPath = upath.join(repoPath, \"dryconfig.json\");\n validateConfig(config, fullConfigSchema, \"Config to save\");\n await fs.writeFile(configPath, JSON.stringify(config, null, 2), \"utf8\");\n}\n\nexport async function ensureDefaultConfig(repoPath: string): Promise<void> {\n const configPath = upath.join(repoPath, \"dryconfig.json\");\n const repoExists = await fs.stat(repoPath).then((s) => s.isDirectory()).catch((err: any) => {\n if (err?.code === \"ENOENT\") return false;\n throw err;\n });\n\n if (!repoExists) return;\n\n const exists = await fs.stat(configPath).then(() => true).catch((err: any) => {\n if (err?.code === \"ENOENT\") return false;\n throw err;\n });\n\n if (!exists) {\n await saveDryConfig(repoPath, DEFAULT_CONFIG);\n }\n}\n","import path from \"path\";\nimport fs from \"fs/promises\";\nimport upath from \"upath\";\nimport { glob } from \"glob-gitignore\";\nimport ignore, { Ignore } from \"ignore\";\nimport { DryConfig } from \"./types\";\n\n/**\n * Gitignore helper that builds ignore matchers by combining default rules,\n * repo .gitignore files, and config-driven exclusions.\n */\nexport class Gitignore {\n private readonly defaultIgnores = [\".git/**\", \".dry/**\"];\n\n constructor(private readonly root: string) {}\n\n async buildMatcher(config: DryConfig): Promise<Ignore> {\n const rules = await this.resolveRules(config);\n return ignore({ allowRelativePaths: true }).add(rules);\n }\n\n private async resolveRules(config: DryConfig): Promise<string[]> {\n const gitignoreRules = await this.loadGitignoreRules();\n const configRules = config.excludedPaths || [];\n return [...this.defaultIgnores, ...gitignoreRules, ...configRules];\n }\n\n private async loadGitignoreRules(): Promise<string[]> {\n const gitignoreFiles = await glob(\"**/.gitignore\", {\n cwd: this.root,\n dot: true,\n nodir: true,\n ignore: this.defaultIgnores,\n });\n\n const rules: string[] = [];\n\n for (const file of gitignoreFiles) {\n const absPath = path.join(this.root, file);\n const dir = upath.normalizeTrim(upath.dirname(file));\n const content = await fs.readFile(absPath, \"utf8\").catch(() => \"\");\n const lines = content.split(/\\r?\\n/);\n\n for (const raw of lines) {\n const trimmed = raw.trim();\n if (!trimmed || trimmed.startsWith(\"#\")) continue;\n\n const negated = trimmed.startsWith(\"!\");\n const body = negated ? trimmed.slice(1) : trimmed;\n\n const scoped = this.scopeRule(body, dir);\n if (!scoped) continue;\n\n rules.push(negated ? `!${scoped}` : scoped);\n }\n }\n\n return rules;\n }\n\n private scopeRule(rule: string, gitignoreDir: string): string | null {\n const cleaned = rule.replace(/^\\//, \"\");\n if (!cleaned) return null;\n\n if (!gitignoreDir || gitignoreDir === \".\") {\n return cleaned;\n }\n\n return upath.normalizeTrim(upath.join(gitignoreDir, cleaned));\n }\n}\n","import \"reflect-metadata\";\nimport fs from \"fs/promises\";\nimport upath from \"upath\";\nimport { DataSource, Repository, In } from \"typeorm\";\nimport { FileEntity } from \"./entities/FileEntity\";\nimport { IndexUnit } from \"../types\";\nimport { IndexUnitEntity } from \"./entities/IndexUnitEntity\";\n\nexport class DryScanDatabase {\n private dataSource?: DataSource;\n private unitRepository?: Repository<IndexUnitEntity>;\n private fileRepository?: Repository<FileEntity>;\n\n isInitialized(): boolean {\n return !!this.dataSource?.isInitialized;\n }\n\n async init(dbPath: string): Promise<void> {\n await fs.mkdir(upath.dirname(dbPath), { recursive: true });\n\n this.dataSource = new DataSource({\n type: \"sqlite\",\n database: dbPath,\n entities: [IndexUnitEntity, FileEntity],\n synchronize: true,\n logging: false,\n });\n\n await this.dataSource.initialize();\n this.unitRepository = this.dataSource.getRepository(IndexUnitEntity);\n this.fileRepository = this.dataSource.getRepository(FileEntity);\n }\n\n async saveUnit(unit: IndexUnit): Promise<void> {\n await this.saveUnits(unit);\n }\n\n async saveUnits(units: IndexUnit | IndexUnit[]): Promise<void> {\n if (!this.unitRepository) throw new Error(\"Database not initialized\");\n const payload = Array.isArray(units) ? units : [units];\n const BATCH_SIZE = 500;\n for (let i = 0; i < payload.length; i += BATCH_SIZE) {\n console.debug(`[DryScanDatabase] Saving units ${i + 1}-${Math.min(i + BATCH_SIZE, payload.length)} of ${payload.length}...`);\n const batch = payload.slice(i, i + BATCH_SIZE);\n await this.unitRepository.save(batch);\n }\n }\n\n async getUnit(id: string): Promise<IndexUnit | null> {\n if (!this.unitRepository) throw new Error(\"Database not initialized\");\n return this.unitRepository.findOne({\n where: { id },\n relations: [\"children\", \"parent\"]\n });\n }\n\n async getAllUnits(): Promise<IndexUnit[]> {\n if (!this.unitRepository) throw new Error(\"Database not initialized\");\n return this.unitRepository.find({ relations: [\"children\", \"parent\"] });\n }\n\n async updateUnit(unit: IndexUnit): Promise<void> {\n await this.saveUnits(unit);\n }\n\n async updateUnits(units: IndexUnit | IndexUnit[]): Promise<void> {\n await this.saveUnits(units);\n }\n\n /**\n * Returns total count of indexed units.\n */\n async countUnits(): Promise<number> {\n if (!this.unitRepository) throw new Error(\"Database not initialized\");\n return this.unitRepository.count();\n }\n\n /**\n * Removes index units by their file paths.\n * Used during incremental updates when files change.\n */\n async removeUnitsByFilePaths(filePaths: string[]): Promise<void> {\n if (!this.unitRepository) throw new Error(\"Database not initialized\");\n await this.unitRepository.delete({ filePath: In(filePaths) });\n }\n\n /**\n * Saves file metadata (path, checksum, mtime) to track changes.\n */\n async saveFile(file: FileEntity): Promise<void> {\n if (!this.fileRepository) throw new Error(\"Database not initialized\");\n await this.fileRepository.save(file);\n }\n\n /**\n * Saves multiple file metadata entries.\n */\n async saveFiles(files: FileEntity[]): Promise<void> {\n if (!this.fileRepository) throw new Error(\"Database not initialized\");\n await this.fileRepository.save(files);\n }\n\n /**\n * Gets file metadata by file path.\n */\n async getFile(filePath: string): Promise<FileEntity | null> {\n if (!this.fileRepository) throw new Error(\"Database not initialized\");\n return this.fileRepository.findOne({ where: { filePath } });\n }\n\n /**\n * Gets all tracked files.\n */\n async getAllFiles(): Promise<FileEntity[]> {\n if (!this.fileRepository) throw new Error(\"Database not initialized\");\n return this.fileRepository.find();\n }\n\n /**\n * Removes file metadata entries by file paths.\n * Used when files are deleted from repository.\n */\n async removeFilesByFilePaths(filePaths: string[]): Promise<void> {\n if (!this.fileRepository) throw new Error(\"Database not initialized\");\n await this.fileRepository.delete({ filePath: In(filePaths) });\n }\n\n async close(): Promise<void> {\n if (this.dataSource?.isInitialized) {\n await this.dataSource.destroy();\n }\n }\n}\n","import { Entity, PrimaryColumn, Column } from \"typeorm\";\n\n/**\n * Represents a tracked source file in the repository.\n * Used to detect changes via checksum and mtime for incremental updates.\n */\n@Entity(\"files\")\nexport class FileEntity {\n /**\n * Relative path to the file from repository root.\n * Used as primary key for uniqueness.\n */\n @PrimaryColumn(\"text\")\n filePath!: string;\n\n /**\n * MD5 checksum of file content.\n * Used to detect content changes.\n */\n @Column(\"text\")\n checksum!: string;\n\n /**\n * Last modification time in milliseconds since epoch.\n * Used as fast sanity check before computing checksum.\n */\n @Column(\"integer\")\n mtime!: number;\n}\n","import {\n Column,\n Entity,\n JoinColumn,\n ManyToOne,\n OneToMany,\n PrimaryColumn,\n RelationId,\n} from \"typeorm\";\nimport { IndexUnit, IndexUnitType } from \"../../types\";\n\n@Entity(\"index_units\")\nexport class IndexUnitEntity implements IndexUnit {\n @PrimaryColumn(\"text\")\n id!: string;\n\n @Column(\"text\")\n name!: string;\n\n @Column(\"text\")\n filePath!: string;\n\n @Column(\"integer\")\n startLine!: number;\n\n @Column(\"integer\")\n endLine!: number;\n\n @Column(\"text\")\n code!: string;\n\n @Column(\"text\")\n unitType!: IndexUnitType;\n\n @ManyToOne(() => IndexUnitEntity, (unit) => unit.children, {\n nullable: true,\n onDelete: \"CASCADE\",\n })\n @JoinColumn({ name: \"parent_id\" })\n parent?: IndexUnitEntity | null;\n\n @RelationId((unit: IndexUnitEntity) => unit.parent)\n parentId?: string | null;\n\n @OneToMany(() => IndexUnitEntity, (unit) => unit.parent, { nullable: true })\n children?: IndexUnitEntity[];\n\n @Column(\"simple-array\", { nullable: true })\n embedding?: number[] | null;\n}\n","import path from \"path\";\nimport fs from \"fs/promises\";\nimport { DryScanServiceDeps } from \"./types\";\nimport { ExclusionService } from \"./ExclusionService\";\nimport { IndexUnit } from \"../types\";\nimport { EmbeddingService } from \"./EmbeddingService\";\nimport { FileEntity } from \"../db/entities/FileEntity\";\nimport { IndexUnitExtractor } from \"../IndexUnitExtractor\";\n\nexport interface InitOptions {\n skipEmbeddings?: boolean;\n}\n\nexport class RepositoryInitializer {\n constructor(\n private readonly deps: DryScanServiceDeps,\n private readonly exclusionService: ExclusionService\n ) {}\n\n async init(options?: InitOptions): Promise<void> {\n const extractor = this.deps.extractor;\n\n console.log(\"[DryScan] Phase 1/3: Extracting code units...\");\n await this.initUnits(extractor);\n console.log(\"[DryScan] Phase 2/3: Computing embeddings (may be slow)...\");\n await this.computeEmbeddings(options?.skipEmbeddings === true);\n console.log(\"[DryScan] Phase 3/3: Tracking files...\");\n await this.trackFiles(extractor);\n await this.exclusionService.cleanupExcludedFiles();\n console.log(\"[DryScan] Initialization phases complete.\");\n }\n\n private async initUnits(extractor: IndexUnitExtractor): Promise<void> {\n const units = await extractor.scan(this.deps.repoPath);\n console.log(`[DryScan] Extracted ${units.length} index units.`);\n await this.deps.db.saveUnits(units);\n }\n\n private async computeEmbeddings(skipEmbeddings: boolean): Promise<void> {\n if (skipEmbeddings) {\n console.log(\"[DryScan] Skipping embedding computation by request.\");\n return;\n }\n const allUnits: IndexUnit[] = await this.deps.db.getAllUnits();\n const total = allUnits.length;\n console.log(`[DryScan] Computing embeddings for ${total} units...`);\n\n const updated: IndexUnit[] = [];\n const progressInterval = Math.max(1, Math.ceil(total / 10));\n const embeddingService = new EmbeddingService(this.deps.repoPath);\n\n for (let i = 0; i < total; i++) {\n const unit = allUnits[i];\n try {\n const enriched = await embeddingService.addEmbedding(unit);\n updated.push(enriched);\n } catch (err: any) {\n console.error(\n `[DryScan] Embedding failed for ${unit.filePath} (${unit.name}): ${err?.message || err}`\n );\n throw err;\n }\n\n const completed = i + 1;\n if (completed === total || completed % progressInterval === 0) {\n const pct = Math.floor((completed / total) * 100);\n console.log(`[DryScan] Embeddings ${completed}/${total} (${pct}%)`);\n }\n }\n\n await this.deps.db.updateUnits(updated);\n }\n\n private async trackFiles(extractor: IndexUnitExtractor): Promise<void> {\n const allFunctions = await extractor.listSourceFiles(this.deps.repoPath);\n const fileEntities: FileEntity[] = [];\n\n for (const relPath of allFunctions) {\n const fullPath = path.join(this.deps.repoPath, relPath);\n const stat = await fs.stat(fullPath);\n const checksum = await extractor.computeChecksum(fullPath);\n\n const fileEntity = new FileEntity();\n fileEntity.filePath = relPath;\n fileEntity.checksum = checksum;\n fileEntity.mtime = stat.mtimeMs;\n fileEntities.push(fileEntity);\n }\n\n await this.deps.db.saveFiles(fileEntities);\n console.log(`[DryScan] Tracked ${fileEntities.length} files.`);\n }\n}","import debug from \"debug\";\nimport { OllamaEmbeddings } from \"@langchain/ollama\";\nimport { HuggingFaceInferenceEmbeddings } from \"@langchain/community/embeddings/hf\";\nimport { IndexUnit } from \"../types\";\nimport { configStore } from \"../config/configStore\";\n\nconst log = debug(\"DryScan:EmbeddingService\");\n\n// Model names for each provider\nconst OLLAMA_MODEL = \"qwen3-embedding:0.6b\";\nconst HUGGINGFACE_MODEL = \"Qwen/Qwen3-Embedding-0.6B\";\n\nexport class EmbeddingService {\n constructor(private readonly repoPath: string) { }\n\n /**\n * Generates an embedding for the given index unit using the configured provider.\n * Skips embedding if code exceeds the configured context length.\n */\n async addEmbedding(fn: IndexUnit): Promise<IndexUnit> {\n const config = await configStore.get(this.repoPath);\n const maxContext = config?.contextLength ?? 2048;\n if (fn.code.length > maxContext) {\n log(\n \"Skipping embedding for %s (code length %d exceeds context %d)\",\n fn.id,\n fn.code.length,\n maxContext\n );\n return { ...fn, embedding: null };\n }\n\n const source = config.embeddingSource;\n if (!source) {\n const message = `Embedding source is not configured for repository at ${this.repoPath}`;\n log(message);\n throw new Error(message);\n }\n\n const embeddings = this.buildProvider(source);\n const embedding = await embeddings.embedQuery(fn.code);\n return { ...fn, embedding };\n }\n\n /**\n * Builds the embedding provider based on the source configuration.\n * - URL (http/https): Uses Ollama with \"embeddinggemma\" model\n * - \"huggingface\": Uses HuggingFace Inference API with \"embeddinggemma-300m\" model\n */\n private buildProvider(source: string) {\n // HuggingFace Inference API\n if (source.toLowerCase() === \"huggingface\") {\n log(\"Using HuggingFace Inference with model: %s\", HUGGINGFACE_MODEL);\n return new HuggingFaceInferenceEmbeddings({\n model: HUGGINGFACE_MODEL,\n provider: \"hf-inference\",\n });\n }\n\n // Ollama keyword or direct URL\n const ollamaBaseUrl = this.resolveOllamaBaseUrl(source);\n if (ollamaBaseUrl !== null) {\n log(\"Using Ollama%s with model: %s\", ollamaBaseUrl ? ` at ${ollamaBaseUrl}` : \"\", OLLAMA_MODEL);\n return new OllamaEmbeddings({ model: OLLAMA_MODEL, ...(ollamaBaseUrl && { baseUrl: ollamaBaseUrl }) });\n }\n\n const message = `Unsupported embedding source: ${source || \"(empty)\"}. Use \"huggingface\" or an Ollama URL.`;\n log(message);\n throw new Error(message);\n }\n\n /**\n * Returns the Ollama base URL if source is an HTTP URL, undefined if source is \"ollama\" (use default),\n * or null if source is not an Ollama provider at all.\n */\n private resolveOllamaBaseUrl(source: string): string | undefined | null {\n if (/^https?:\\/\\//i.test(source)) return source;\n if (source.toLowerCase() === \"ollama\") return undefined;\n return null;\n }\n}","import debug from \"debug\";\nimport { DryScanServiceDeps } from \"./types\";\nimport { ExclusionService } from \"./ExclusionService\";\nimport { performIncrementalUpdate } from \"../DryScanUpdater\";\nimport { DuplicationCache } from \"./DuplicationCache\";\n\nconst log = debug(\"DryScan:UpdateService\");\n\nexport class UpdateService {\n constructor(\n private readonly deps: DryScanServiceDeps,\n private readonly exclusionService: ExclusionService\n ) {}\n\n /** Returns the list of file paths that were modified or deleted (dirty). */\n async updateIndex(): Promise<string[]> {\n const extractor = this.deps.extractor;\n const cache = DuplicationCache.getInstance();\n\n try {\n const changeSet = await performIncrementalUpdate(this.deps.repoPath, extractor, this.deps.db);\n await this.exclusionService.cleanupExcludedFiles();\n const dirtyPaths = [...changeSet.changed, ...changeSet.deleted, ...changeSet.added];\n await cache.invalidate(dirtyPaths);\n return dirtyPaths;\n } catch (err) {\n log(\"Error during index update:\", err);\n throw err;\n }\n }\n}","import path from \"path\";\nimport fs from \"fs/promises\";\nimport debug from \"debug\";\nimport { IndexUnit } from \"./types\";\nimport { IndexUnitExtractor } from \"./IndexUnitExtractor\";\nimport { DryScanDatabase } from \"./db/DryScanDatabase\";\nimport { FileEntity } from \"./db/entities/FileEntity\";\nimport { EmbeddingService } from \"./services/EmbeddingService\";\n\nconst log = debug(\"DryScan:Updater\");\n\n/**\n * DryScan Updater Module\n * \n * This module contains all incremental update logic for DryScan.\n * Separated from DryScan.ts to keep that file focused on core operations.\n * \n * Represents the result of change detection.\n * Categorizes files into added, changed, deleted, and unchanged.\n */\nexport interface FileChangeSet {\n added: string[];\n changed: string[];\n deleted: string[];\n unchanged: string[];\n}\n\n/**\n * Detects which files have been added, changed, or deleted since last scan.\n * Uses mtime as fast check, then checksum for verification.\n * \n * @param repoPath - Root path of the repository\n * @param extractor - Index unit extractor instance for file operations\n * @param db - Database instance for retrieving tracked files\n * @returns Change set with categorized file paths\n */\nexport async function detectFileChanges(\n repoPath: string,\n extractor: IndexUnitExtractor,\n db: DryScanDatabase\n): Promise<FileChangeSet> {\n // Get current files in repository\n const currentFiles = await extractor.listSourceFiles(repoPath);\n const currentFileSet = new Set(currentFiles);\n\n // Get tracked files from database\n const trackedFiles = await db.getAllFiles();\n const trackedFileMap = new Map(trackedFiles.map(f => [f.filePath, f]));\n\n const added: string[] = [];\n const changed: string[] = [];\n const unchanged: string[] = [];\n\n // Check each current file\n for (const filePath of currentFiles) {\n const tracked = trackedFileMap.get(filePath);\n \n if (!tracked) {\n // New file\n added.push(filePath);\n continue;\n }\n\n // Check if file changed using mtime first (fast check)\n const fullPath = path.join(repoPath, filePath);\n const stat = await fs.stat(fullPath);\n \n if (stat.mtimeMs !== tracked.mtime) {\n // Mtime changed, verify with checksum\n const currentChecksum = await extractor.computeChecksum(fullPath);\n if (currentChecksum !== tracked.checksum) {\n changed.push(filePath);\n } else {\n // Mtime changed but content same\n unchanged.push(filePath);\n }\n } else {\n unchanged.push(filePath);\n }\n }\n\n // Find deleted files\n const deleted = trackedFiles\n .map(f => f.filePath)\n .filter(fp => !currentFileSet.has(fp));\n\n return { added, changed, deleted, unchanged };\n}\n\n/**\n * Extracts index units from a list of files.\n * Used during incremental updates.\n * \n * @param filePaths - Array of relative file paths to extract from\n * @param extractor - Index unit extractor instance\n * @returns Array of extracted units\n */\nexport async function extractUnitsFromFiles(\n filePaths: string[],\n extractor: IndexUnitExtractor\n): Promise<IndexUnit[]> {\n const allUnits: IndexUnit[] = [];\n \n for (const relPath of filePaths) {\n const functions = await extractor.scan(relPath);\n allUnits.push(...functions);\n }\n \n return allUnits;\n}\n\n/**\n * Updates file tracking metadata after processing changes.\n * Removes deleted files, updates changed files, adds new files.\n * \n * @param changeSet - Set of file changes to apply\n * @param repoPath - Root path of the repository\n * @param extractor - Index unit extractor for checksum computation\n * @param db - Database instance for file tracking\n */\nexport async function updateFileTracking(\n changeSet: FileChangeSet,\n repoPath: string,\n extractor: IndexUnitExtractor,\n db: DryScanDatabase\n): Promise<void> {\n // Remove deleted files\n if (changeSet.deleted.length > 0) {\n if (typeof (db as any).removeFilesByFilePaths === \"function\") {\n await (db as any).removeFilesByFilePaths(changeSet.deleted);\n } else if (typeof (db as any).removeFiles === \"function\") {\n await (db as any).removeFiles(changeSet.deleted);\n }\n }\n\n // Create file entities for new and changed files\n const filesToTrack = [...changeSet.added, ...changeSet.changed];\n if (filesToTrack.length > 0) {\n const fileEntities: FileEntity[] = [];\n \n for (const relPath of filesToTrack) {\n const fullPath = path.join(repoPath, relPath);\n const stat = await fs.stat(fullPath);\n const checksum = await extractor.computeChecksum(fullPath);\n \n const fileEntity = new FileEntity();\n fileEntity.filePath = relPath;\n fileEntity.checksum = checksum;\n fileEntity.mtime = stat.mtimeMs;\n \n fileEntities.push(fileEntity);\n }\n \n await db.saveFiles(fileEntities);\n }\n}\n\n/**\n * Performs incremental update of the DryScan index.\n * Detects file changes and reprocesses only affected files.\n * \n * @param repoPath - Root path of the repository\n * @param extractor - Index unit extractor instance\n * @param db - Database instance (must be initialized)\n */\nexport async function performIncrementalUpdate(\n repoPath: string,\n extractor: IndexUnitExtractor,\n db: DryScanDatabase,\n): Promise<FileChangeSet> {\n log(\"Starting incremental update\");\n const embeddingService = new EmbeddingService(repoPath);\n \n // Step 1: Detect changes\n const changeSet = await detectFileChanges(repoPath, extractor, db);\n \n if (changeSet.changed.length === 0 && \n changeSet.added.length === 0 && \n changeSet.deleted.length === 0) {\n log(\"No changes detected. Index is up to date.\");\n return changeSet;\n }\n\n log(`Changes detected: ${changeSet.added.length} added, ${changeSet.changed.length} changed, ${changeSet.deleted.length} deleted`);\n\n // Step 2: Remove old data for changed/deleted files\n const filesToRemove = [...changeSet.changed, ...changeSet.deleted];\n if (filesToRemove.length > 0) {\n await db.removeUnitsByFilePaths(filesToRemove);\n log(`Removed units from ${filesToRemove.length} files`);\n }\n\n // Step 3: Extract functions from new/changed files\n const filesToProcess = [...changeSet.added, ...changeSet.changed];\n if (filesToProcess.length > 0) {\n const newUnits = await extractUnitsFromFiles(filesToProcess, extractor);\n await db.saveUnits(newUnits);\n log(`Extracted and saved ${newUnits.length} units from ${filesToProcess.length} files`);\n\n // Step 4: Recompute embeddings for affected units only\n const total = newUnits.length;\n if (total > 0) {\n log(`Recomputing embeddings for ${total} units`);\n const progressInterval = Math.max(1, Math.ceil(total / 10));\n const updatedWithEmbeddings = [] as IndexUnit[];\n\n for (let i = 0; i < total; i++) {\n const unit = newUnits[i];\n try {\n const enriched = await embeddingService.addEmbedding(unit);\n updatedWithEmbeddings.push(enriched);\n } catch (err: any) {\n console.error(\n `[DryScan] embedding failed for ${unit.filePath} (${unit.name}): ${err?.message || err}`\n );\n throw err;\n }\n\n const completed = i + 1;\n if (completed === total || completed % progressInterval === 0) {\n const pct = Math.floor((completed / total) * 100);\n console.log(`[DryScan] Incremental embeddings ${completed}/${total} (${pct}%)`);\n }\n }\n\n await db.updateUnits(updatedWithEmbeddings);\n log(`Recomputed embeddings for ${updatedWithEmbeddings.length} units`);\n }\n }\n\n // Step 5: Update file tracking\n await updateFileTracking(changeSet, repoPath, extractor, db);\n log(\"Incremental update complete\");\n\n return changeSet;\n}\n","import debug from \"debug\";\nimport { DuplicateGroup, IndexUnit } from \"../types\";\nimport { parallelCosineSimilarity } from \"./ParallelSimilarity\";\n\nconst log = debug(\"DryScan:DuplicationCache\");\n\n/**\n * In-memory cache for duplicate comparison scores.\n * Stores a global map of comparison keys and a per-file index for fast invalidation.\n */\nexport class DuplicationCache {\n private static instance: DuplicationCache | null = null;\n\n private readonly comparisons = new Map<string, number>();\n private readonly fileIndex = new Map<string, Set<string>>();\n private initialized = false;\n\n /** Per-run similarity matrix from a single batched library call (reset each run). */\n private embSimMatrix: number[][] = [];\n /** Maps unit ID to its row/column index in embSimMatrix. */\n private embSimIndex = new Map<string, number>();\n /** Per-run memoization of parent unit similarity scores (reset each run). */\n private parentSimCache = new Map<string, number>();\n\n static getInstance(): DuplicationCache {\n if (!DuplicationCache.instance) {\n DuplicationCache.instance = new DuplicationCache();\n }\n return DuplicationCache.instance;\n }\n\n /**\n * Updates the cache with fresh duplicate groups. Not awaited by callers to avoid blocking.\n */\n async update(groups: DuplicateGroup[]): Promise<void> {\n if (!groups) return;\n\n for (const group of groups) {\n const key = this.makeKey(group.left.id, group.right.id);\n this.comparisons.set(key, group.similarity);\n this.addKeyForFile(group.left.filePath, key);\n this.addKeyForFile(group.right.filePath, key);\n }\n\n this.initialized = this.initialized || groups.length > 0;\n }\n\n /**\n * Retrieves a cached similarity if present and valid for both file paths.\n * Returns null when the cache has not been initialized or when the pair is missing.\n */\n get(leftId: string, rightId: string, leftFilePath: string, rightFilePath: string): number | null {\n if (!this.initialized) return null;\n\n const key = this.makeKey(leftId, rightId);\n if (!this.fileHasKey(leftFilePath, key) || !this.fileHasKey(rightFilePath, key)) {\n return null;\n }\n\n const value = this.comparisons.get(key);\n return typeof value === \"number\" ? value : null;\n }\n\n /**\n * Invalidates all cached comparisons involving the provided file paths.\n */\n async invalidate(paths: string[]): Promise<void> {\n if (!this.initialized || !paths || paths.length === 0) return;\n\n const unique = new Set(paths);\n for (const filePath of unique) {\n const keys = this.fileIndex.get(filePath);\n if (!keys) continue;\n\n for (const key of keys) {\n this.comparisons.delete(key);\n for (const [otherPath, otherKeys] of this.fileIndex.entries()) {\n if (otherKeys.delete(key) && otherKeys.size === 0) {\n this.fileIndex.delete(otherPath);\n }\n }\n }\n\n this.fileIndex.delete(filePath);\n }\n\n if (this.comparisons.size === 0) {\n this.initialized = false;\n }\n }\n\n /**\n * Clears all cached data. Intended for test setup.\n */\n clear(): void {\n this.comparisons.clear();\n this.fileIndex.clear();\n this.initialized = false;\n this.embSimMatrix = [];\n this.embSimIndex.clear();\n this.clearRunCaches();\n }\n\n /**\n * Resets per-run memoization (parent similarities).\n * The embedding matrix is intentionally preserved so incremental runs can\n * reuse clean×clean values across calls.\n */\n clearRunCaches(): void {\n this.parentSimCache.clear();\n }\n\n /**\n * Builds or incrementally updates the embedding similarity matrix.\n *\n * Full rebuild (default): replaces the entire matrix — O(n²).\n * Incremental (dirtyPaths provided + prior matrix exists): copies clean×clean\n * cells from the old matrix and recomputes only dirty rows via one batched\n * cosineSimilarity call — O(d·n) where d = number of dirty units.\n */\n async buildEmbSimCache(units: IndexUnit[], dirtyPaths?: string[]): Promise<void> {\n const embedded = units.filter(u => Array.isArray(u.embedding) && u.embedding.length > 0);\n if (embedded.length < 2) {\n this.embSimMatrix = [];\n this.embSimIndex.clear();\n return;\n }\n\n const embeddings = embedded.map(u => u.embedding as number[]);\n const newIndex = new Map(embedded.map((u, i) => [u.id, i] as [string, number]));\n const dirtySet = dirtyPaths ? new Set(dirtyPaths) : null;\n const hasPriorMatrix = this.embSimMatrix.length > 0;\n\n if (!dirtySet || !hasPriorMatrix) {\n // Full rebuild\n this.embSimIndex = newIndex;\n this.embSimMatrix = await parallelCosineSimilarity(embeddings, embeddings);\n log(\"Built full embedding similarity matrix: %d units\", embedded.length);\n return;\n }\n\n // Incremental: identify dirty unit IDs\n const dirtyIds = new Set(embedded.filter(u => dirtySet.has(u.filePath)).map(u => u.id));\n\n if (dirtyIds.size === 0) {\n log(\"Matrix reused: no dirty units detected\");\n return;\n }\n\n const n = embedded.length;\n\n // Start with zeroes; copy clean×clean values from prior matrix\n const newMatrix: number[][] = Array.from({ length: n }, () => new Array(n).fill(0));\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n if (dirtyIds.has(embedded[i].id) || dirtyIds.has(embedded[j].id)) continue;\n const oi = this.embSimIndex.get(embedded[i].id);\n const oj = this.embSimIndex.get(embedded[j].id);\n if (oi !== undefined && oj !== undefined) newMatrix[i][j] = this.embSimMatrix[oi][oj];\n }\n }\n\n // Recompute dirty rows in one batched call\n const dirtyIndices = embedded.reduce<number[]>((acc, u, i) => (dirtyIds.has(u.id) ? [...acc, i] : acc), []);\n const dirtyRows = await parallelCosineSimilarity(dirtyIndices.map(i => embeddings[i]), embeddings);\n dirtyIndices.forEach((rowIdx, di) => {\n for (let j = 0; j < n; j++) {\n newMatrix[rowIdx][j] = dirtyRows[di][j];\n newMatrix[j][rowIdx] = dirtyRows[di][j];\n }\n });\n\n this.embSimIndex = newIndex;\n this.embSimMatrix = newMatrix;\n log(\"Incremental matrix update: %d dirty unit(s) out of %d total\", dirtyIds.size, n);\n }\n\n /** Returns the pre-computed cosine similarity for a pair of unit IDs, if available. */\n getEmbSim(id1: string, id2: string): number | undefined {\n const i = this.embSimIndex.get(id1);\n const j = this.embSimIndex.get(id2);\n if (i === undefined || j === undefined) return undefined;\n return this.embSimMatrix[i][j];\n }\n\n /** Returns the memoized parent similarity for the given stable key, if available. */\n getParentSim(key: string): number | undefined {\n return this.parentSimCache.get(key);\n }\n\n /** Stores a memoized parent similarity for the given stable key. */\n setParentSim(key: string, sim: number): void {\n this.parentSimCache.set(key, sim);\n }\n\n private addKeyForFile(filePath: string, key: string): void {\n const current = this.fileIndex.get(filePath) ?? new Set<string>();\n current.add(key);\n this.fileIndex.set(filePath, current);\n }\n\n private fileHasKey(filePath: string, key: string): boolean {\n const keys = this.fileIndex.get(filePath);\n return keys ? keys.has(key) : false;\n }\n\n private makeKey(leftId: string, rightId: string): string {\n return [leftId, rightId].sort().join(\"::\");\n }\n}\n","import debug from \"debug\";\nimport shortUuid from \"short-uuid\";\nimport { DryScanServiceDeps } from \"./types\";\nimport { DuplicateAnalysisResult, DuplicateGroup, DuplicationScore, IndexUnit, IndexUnitType } from \"../types\";\nimport { indexConfig } from \"../config/indexConfig\";\nimport { DryConfig } from \"../types\";\nimport { DuplicationCache } from \"./DuplicationCache\";\n\nconst log = debug(\"DryScan:DuplicateService\");\n\nexport class DuplicateService {\n private config?: DryConfig;\n private readonly cache = DuplicationCache.getInstance();\n\n constructor(private readonly deps: DryScanServiceDeps) {}\n\n /**\n * @param dirtyPaths - File paths changed since last run. When provided, only\n * dirty×all similarities are recomputed; clean×clean values are reused from\n * the existing matrix. Pass undefined (or omit) for a full rebuild.\n */\n async findDuplicates(config: DryConfig, dirtyPaths?: string[]): Promise<DuplicateAnalysisResult> {\n this.config = config;\n const t0 = performance.now();\n const allUnits = await this.deps.db.getAllUnits();\n log(\"Starting duplicate analysis on %d units\", allUnits.length);\n\n if (allUnits.length < 2) {\n return { duplicates: [], score: this.computeDuplicationScore([], allUnits) };\n }\n\n const thresholds = this.resolveThresholds(config.threshold);\n const duplicates = await this.computeDuplicates(allUnits, thresholds, dirtyPaths);\n const filtered = duplicates.filter((g) => !this.isGroupExcluded(g));\n log(\"Found %d duplicate groups (%d excluded)\", filtered.length, duplicates.length - filtered.length);\n\n this.cache.update(filtered).catch((err) => log(\"Cache update failed: %O\", err));\n\n const score = this.computeDuplicationScore(filtered, allUnits);\n log(\"findDuplicates completed in %dms\", (performance.now() - t0).toFixed(2));\n return { duplicates: filtered, score };\n }\n\n private resolveThresholds(functionThreshold?: number): { function: number; block: number; class: number } {\n const d = indexConfig.thresholds;\n const clamp = (v: number) => Math.min(1, Math.max(0, v));\n const fn = clamp(functionThreshold ?? d.function);\n return {\n function: fn,\n block: clamp(fn + d.block - d.function),\n class: clamp(fn + d.class - d.function),\n };\n }\n\n private async computeDuplicates(\n units: IndexUnit[],\n thresholds: { function: number; block: number; class: number },\n dirtyPaths?: string[]\n ): Promise<DuplicateGroup[]> {\n this.cache.clearRunCaches();\n await this.cache.buildEmbSimCache(units, dirtyPaths);\n\n const duplicates: DuplicateGroup[] = [];\n const t0 = performance.now();\n\n for (const [type, typedUnits] of this.groupByType(units)) {\n const threshold = this.getThreshold(type, thresholds);\n log(\"Comparing %d %s units (threshold=%.3f)\", typedUnits.length, type, threshold);\n\n for (let i = 0; i < typedUnits.length; i++) {\n for (let j = i + 1; j < typedUnits.length; j++) {\n const left = typedUnits[i], right = typedUnits[j];\n if (this.shouldSkipComparison(left, right)) continue;\n\n // Always check the cache first — this allows pairs whose embeddings\n // have since been cleared to still be reported using a prior score.\n const cached = this.cache.get(left.id, right.id, left.filePath, right.filePath);\n const hasEmbeddings = left.embedding?.length && right.embedding?.length;\n const similarity = cached ?? (hasEmbeddings ? this.computeWeightedSimilarity(left, right, threshold) : 0);\n if (similarity < threshold) continue;\n\n const exclusionString = this.deps.pairing.pairKeyForUnits(left, right);\n if (!exclusionString) continue;\n\n duplicates.push({\n id: `${left.id}::${right.id}`,\n similarity,\n shortId: shortUuid.generate(),\n exclusionString,\n left: this.toMember(left),\n right: this.toMember(right),\n });\n }\n }\n }\n\n log(\"computeDuplicates: %d duplicates in %dms\", duplicates.length, (performance.now() - t0).toFixed(2));\n return duplicates.sort((a, b) => b.similarity - a.similarity);\n }\n\n private isGroupExcluded(group: DuplicateGroup): boolean {\n const config = this.config;\n if (!config?.excludedPairs?.length) return false;\n const key = this.deps.pairing.pairKeyForUnits(group.left, group.right);\n if (!key) return false;\n const actual = this.deps.pairing.parsePairKey(key);\n if (!actual) return false;\n return config.excludedPairs.some((entry) => {\n const parsed = this.deps.pairing.parsePairKey(entry);\n return parsed ? this.deps.pairing.pairKeyMatches(actual, parsed) : false;\n });\n }\n\n private getThreshold(type: IndexUnitType, thresholds: { function: number; block: number; class: number }): number {\n if (type === IndexUnitType.CLASS) return thresholds.class;\n if (type === IndexUnitType.BLOCK) return thresholds.block;\n return thresholds.function;\n }\n\n private computeWeightedSimilarity(left: IndexUnit, right: IndexUnit, threshold: number): number {\n const selfSim = this.similarity(left, right);\n\n //CLASS\n if (left.unitType === IndexUnitType.CLASS) {\n return selfSim * indexConfig.weights.class.self;\n }\n\n // FUNCTION\n if (left.unitType === IndexUnitType.FUNCTION) {\n const w = indexConfig.weights.function;\n const hasPC = this.bothHaveParent(left, right, IndexUnitType.CLASS);\n const total = w.self + (hasPC ? w.parentClass : 0);\n // Early exit: even with perfect parent similarity, can't reach threshold.\n if ((w.self * selfSim + (hasPC ? w.parentClass : 0)) / total < threshold) return 0;\n return (w.self * selfSim + (hasPC ? w.parentClass * this.parentSimilarity(left, right, IndexUnitType.CLASS) : 0)) / total;\n }\n\n // BLOCK\n const w = indexConfig.weights.block;\n const hasPF = this.bothHaveParent(left, right, IndexUnitType.FUNCTION);\n const hasPC = this.bothHaveParent(left, right, IndexUnitType.CLASS);\n const total = w.self + (hasPF ? w.parentFunction : 0) + (hasPC ? w.parentClass : 0);\n if ((w.self * selfSim + (hasPF ? w.parentFunction : 0) + (hasPC ? w.parentClass : 0)) / total < threshold) return 0;\n return (\n w.self * selfSim +\n (hasPF ? w.parentFunction * this.parentSimilarity(left, right, IndexUnitType.FUNCTION) : 0) +\n (hasPC ? w.parentClass * this.parentSimilarity(left, right, IndexUnitType.CLASS) : 0)\n ) / total;\n }\n\n /** Groups all units by type for the comparison loop. Units without embeddings are included\n * so that cache hits can still be returned for pairs whose embeddings were cleared. */\n private groupByType(units: IndexUnit[]): Map<IndexUnitType, IndexUnit[]> {\n const byType = new Map<IndexUnitType, IndexUnit[]>();\n for (const unit of units) {\n const list = byType.get(unit.unitType) ?? [];\n list.push(unit);\n byType.set(unit.unitType, list);\n }\n return byType;\n }\n\n private toMember(unit: IndexUnit): DuplicateGroup[\"left\"] {\n return {\n id: unit.id,\n name: unit.name,\n filePath: unit.filePath,\n startLine: unit.startLine,\n endLine: unit.endLine,\n code: unit.code,\n unitType: unit.unitType,\n };\n }\n\n private bothHaveParent(left: IndexUnit, right: IndexUnit, type: IndexUnitType): boolean {\n return !!this.findParent(left, type) && !!this.findParent(right, type);\n }\n\n private parentSimilarity(left: IndexUnit, right: IndexUnit, type: IndexUnitType): number {\n const lp = this.findParent(left, type), rp = this.findParent(right, type);\n if (!lp || !rp) return 0;\n\n const key = lp.id < rp.id ? `${lp.id}::${rp.id}` : `${rp.id}::${lp.id}`;\n const cached = this.cache.getParentSim(key);\n if (cached !== undefined) return cached;\n\n const sim = this.similarity(lp, rp);\n this.cache.setParentSim(key, sim);\n return sim;\n }\n\n /** Resolves similarity via the pre-computed embedding matrix, falling back to best child match. */\n private similarity(left: IndexUnit, right: IndexUnit): number {\n return this.cache.getEmbSim(left.id, right.id) ?? this.childSimilarity(left, right);\n }\n\n private childSimilarity(left: IndexUnit, right: IndexUnit): number {\n const lc = left.children ?? [], rc = right.children ?? [];\n if (!lc.length || !rc.length) return 0;\n\n let best = 0;\n for (const l of lc) {\n for (const r of rc) {\n if (l.unitType !== r.unitType) continue;\n const sim = this.similarity(l, r);\n if (sim > best) best = sim;\n }\n }\n return best;\n }\n\n private shouldSkipComparison(left: IndexUnit, right: IndexUnit): boolean {\n if (left.unitType !== IndexUnitType.BLOCK || right.unitType !== IndexUnitType.BLOCK) return false;\n if (left.filePath !== right.filePath) return false;\n return (left.startLine <= right.startLine && left.endLine >= right.endLine)\n || (right.startLine <= left.startLine && right.endLine >= left.endLine);\n }\n\n private findParent(unit: IndexUnit, type: IndexUnitType): IndexUnit | null {\n let p = unit.parent;\n while (p) {\n if (p.unitType === type) return p;\n p = p.parent;\n }\n return null;\n }\n\n private computeDuplicationScore(duplicates: DuplicateGroup[], allUnits: IndexUnit[]): DuplicationScore {\n const totalLines = allUnits.reduce((sum, u) => sum + u.endLine - u.startLine + 1, 0);\n\n if (!totalLines || !duplicates.length) {\n return { score: 0, grade: \"Excellent\", totalLines, duplicateLines: 0, duplicateGroups: 0 };\n }\n\n const duplicateLines = duplicates.reduce((sum, g) => {\n const avg = ((g.left.endLine - g.left.startLine + 1) + (g.right.endLine - g.right.startLine + 1)) / 2;\n return sum + g.similarity * avg;\n }, 0);\n\n const score = (duplicateLines / totalLines) * 100;\n return {\n score,\n grade: this.getScoreGrade(score),\n totalLines,\n duplicateLines: Math.round(duplicateLines),\n duplicateGroups: duplicates.length,\n };\n }\n\n private getScoreGrade(score: number): DuplicationScore[\"grade\"] {\n if (score < 5) return \"Excellent\";\n if (score < 15) return \"Good\";\n if (score < 30) return \"Fair\";\n if (score < 50) return \"Poor\";\n return \"Critical\";\n }\n}","import { DryConfig } from \"../types\";\nimport { configStore } from \"../config/configStore\";\nimport { DryScanServiceDeps } from \"./types\";\nimport { IndexUnitType } from \"../types\";\nimport { minimatch } from \"minimatch\";\nimport { ParsedPairKey } from \"./PairingService\";\n\nexport class ExclusionService {\n private config?: DryConfig;\n\n constructor(private readonly deps: DryScanServiceDeps) {}\n\n async cleanupExcludedFiles(): Promise<void> {\n const config = await this.loadConfig();\n if (!config.excludedPaths || config.excludedPaths.length === 0) return;\n\n const units = await this.deps.db.getAllUnits();\n const files = await this.deps.db.getAllFiles();\n\n const unitPathsToRemove = new Set<string>();\n for (const unit of units) {\n if (this.pathExcluded(unit.filePath)) {\n unitPathsToRemove.add(unit.filePath);\n }\n }\n\n const filePathsToRemove = new Set<string>();\n for (const file of files) {\n if (this.pathExcluded(file.filePath)) {\n filePathsToRemove.add(file.filePath);\n }\n }\n\n const paths = [...new Set([...unitPathsToRemove, ...filePathsToRemove])];\n if (paths.length > 0) {\n await this.deps.db.removeUnitsByFilePaths(paths);\n await this.deps.db.removeFilesByFilePaths(paths);\n }\n }\n\n async cleanExclusions(): Promise<{ removed: number; kept: number }> {\n const config = await this.loadConfig();\n const units = await this.deps.db.getAllUnits();\n\n const actualPairsByType = {\n [IndexUnitType.CLASS]: this.buildPairKeys(units, IndexUnitType.CLASS),\n [IndexUnitType.FUNCTION]: this.buildPairKeys(units, IndexUnitType.FUNCTION),\n [IndexUnitType.BLOCK]: this.buildPairKeys(units, IndexUnitType.BLOCK),\n };\n\n const kept: string[] = [];\n const removed: string[] = [];\n\n for (const entry of config.excludedPairs || []) {\n const parsed = this.deps.pairing.parsePairKey(entry);\n if (!parsed) {\n removed.push(entry);\n continue;\n }\n\n const candidates = actualPairsByType[parsed.type];\n const matched = candidates.some((actual) => this.deps.pairing.pairKeyMatches(actual, parsed));\n if (matched) {\n kept.push(entry);\n } else {\n removed.push(entry);\n }\n }\n\n const nextConfig: DryConfig = { ...config, excludedPairs: kept };\n await configStore.save(this.deps.repoPath, nextConfig);\n this.config = nextConfig;\n\n return { removed: removed.length, kept: kept.length };\n }\n\n private pathExcluded(filePath: string): boolean {\n const config = this.config;\n if (!config || !config.excludedPaths || config.excludedPaths.length === 0) return false;\n return config.excludedPaths.some((pattern) => minimatch(filePath, pattern, { dot: true }));\n }\n\n private buildPairKeys(units: any[], type: IndexUnitType): ParsedPairKey[] {\n const typed = units.filter((u) => u.unitType === type);\n const pairs: ParsedPairKey[] = [];\n for (let i = 0; i < typed.length; i++) {\n for (let j = i + 1; j < typed.length; j++) {\n const key = this.deps.pairing.pairKeyForUnits(typed[i], typed[j]);\n const parsed = key ? this.deps.pairing.parsePairKey(key) : null;\n if (parsed) {\n pairs.push(parsed);\n }\n }\n }\n return pairs;\n }\n\n private async loadConfig(): Promise<DryConfig> {\n this.config = await configStore.get(this.deps.repoPath);\n return this.config;\n }\n}","import crypto from \"node:crypto\";\nimport debug from \"debug\";\nimport { minimatch } from \"minimatch\";\nimport { LanguageExtractor } from \"../extractors/LanguageExtractor\";\nimport { IndexUnitExtractor } from \"../IndexUnitExtractor\";\nimport { IndexUnit, IndexUnitType } from \"../types\";\nimport { BLOCK_HASH_ALGO } from \"../const\";\n\nconst log = debug(\"DryScan:pairs\");\n\ntype UnitLike = Pick<IndexUnit, \"unitType\" | \"filePath\" | \"name\" | \"code\">;\n\nexport interface ParsedPairKey {\n type: IndexUnitType;\n left: string;\n right: string;\n key: string;\n}\n\n/**\n * Service for building and parsing pair keys with extractor-aware labeling.\n */\nexport class PairingService {\n constructor(private readonly indexUnitExtractor: IndexUnitExtractor) {}\n\n /**\n * Creates a stable, order-independent key for two units of the same type.\n * Returns null when units differ in type so callers can skip invalid pairs.\n */\n pairKeyForUnits(left: UnitLike, right: UnitLike): string | null {\n if (left.unitType !== right.unitType) {\n log(\"Skipping pair with mismatched types: %s vs %s\", left.unitType, right.unitType);\n return null;\n }\n const type = left.unitType;\n const leftLabel = this.unitLabel(left);\n const rightLabel = this.unitLabel(right);\n const [a, b] = [leftLabel, rightLabel].sort();\n return `${type}|${a}|${b}`;\n }\n\n /**\n * Parses a raw pair key into its components, returning null for malformed values.\n * Sorting is applied so callers can compare pairs without worrying about order.\n */\n parsePairKey(value: string): ParsedPairKey | null {\n const parts = value.split(\"|\");\n if (parts.length !== 3) {\n log(\"Invalid pair key format: %s\", value);\n return null;\n }\n const [typeRaw, leftRaw, rightRaw] = parts;\n const type = this.stringToUnitType(typeRaw);\n if (!type) {\n log(\"Unknown unit type in pair key: %s\", typeRaw);\n return null;\n }\n const [left, right] = [leftRaw, rightRaw].sort();\n return { type, left, right, key: `${type}|${left}|${right}` };\n }\n\n /**\n * Checks whether an actual pair key satisfies a pattern, with glob matching for class paths.\n */\n pairKeyMatches(actual: ParsedPairKey, pattern: ParsedPairKey): boolean {\n if (actual.type !== pattern.type) return false;\n if (actual.type === IndexUnitType.CLASS) {\n // Allow glob matching for class file paths.\n const forward =\n minimatch(actual.left, pattern.left, { dot: true }) &&\n minimatch(actual.right, pattern.right, { dot: true });\n const swapped =\n minimatch(actual.left, pattern.right, { dot: true }) &&\n minimatch(actual.right, pattern.left, { dot: true });\n return forward || swapped;\n }\n\n // Functions and blocks use exact matching on canonical strings.\n return (\n (actual.left === pattern.left && actual.right === pattern.right) ||\n (actual.left === pattern.right && actual.right === pattern.left)\n );\n }\n\n /**\n * Derives a reversible, extractor-aware label for a unit.\n * Extractors may override; fallback uses a fixed format per unit type.\n */\n unitLabel(unit: UnitLike): string {\n const extractor = this.findExtractor(unit.filePath);\n const customLabel = extractor?.unitLabel?.(unit as IndexUnit);\n if (customLabel) return customLabel;\n\n switch (unit.unitType) {\n case IndexUnitType.CLASS:\n return unit.filePath;\n case IndexUnitType.FUNCTION:\n return this.canonicalFunctionSignature(unit);\n case IndexUnitType.BLOCK:\n return this.normalizedBlockHash(unit);\n default:\n return unit.name;\n }\n }\n\n private findExtractor(filePath: string): LanguageExtractor | undefined {\n return this.indexUnitExtractor.extractors.find((ex) => ex.supports(filePath));\n }\n\n private canonicalFunctionSignature(unit: UnitLike): string {\n const arity = this.extractArity(unit.code);\n return `${unit.name}(arity:${arity})`;\n }\n\n /**\n * Normalizes block code (strips comments/whitespace) and hashes it for pair matching.\n */\n private normalizedBlockHash(unit: UnitLike): string {\n const normalized = this.normalizeCode(unit.code);\n return crypto.createHash(BLOCK_HASH_ALGO).update(normalized).digest(\"hex\");\n }\n\n private stringToUnitType(value: string): IndexUnitType | null {\n if (value === IndexUnitType.CLASS) return IndexUnitType.CLASS;\n if (value === IndexUnitType.FUNCTION) return IndexUnitType.FUNCTION;\n if (value === IndexUnitType.BLOCK) return IndexUnitType.BLOCK;\n return null;\n }\n\n private extractArity(code: string): number {\n const match = code.match(/^[^{]*?\\(([^)]*)\\)/s);\n if (!match) return 0;\n const params = match[1]\n .split(\",\")\n .map((p) => p.trim())\n .filter(Boolean);\n return params.length;\n }\n\n private normalizeCode(code: string): string {\n const withoutBlockComments = code.replace(/\\/\\*[\\s\\S]*?\\*\\//g, \"\");\n const withoutLineComments = withoutBlockComments.replace(/\\/\\/[^\\n\\r]*/g, \"\");\n return withoutLineComments.replace(/\\s+/g, \"\");\n }\n}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;AAC1C,UAAM,iBAAiB,KAAK,IAAI,IAAI;AACpC,YAAQ,IAAI,gCAAgC,cAAc,KAAK;AAE/D,YAAQ,IAAI,mCAAmC;AAC/C,UAAM,WAAW,KAAK,IAAI;AAC1B,UAAM,SAAS,MAAM,KAAK,SAAS,UAAU,eAAe,QAAQ,UAAU;AAC9E,UAAM,cAAc,KAAK,IAAI,IAAI;AACjC,YAAQ,IAAI,sCAAsC,WAAW,KAAK;AAElE,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,kBAA8D;AAClE,UAAM,KAAK,YAAY;AACvB,WAAO,KAAK,SAAS,UAAU,gBAAgB;AAAA,EACjD;AAAA,EAEA,MAAc,iBAAgC;AAC5C,QAAI,KAAK,GAAG,cAAc,EAAG;AAC7B,UAAM,SAASA,OAAM,KAAK,KAAK,UAAU,aAAa,QAAQ;AAC9D,UAAMC,IAAG,MAAMD,OAAM,QAAQ,MAAM,GAAG,EAAE,WAAW,KAAK,CAAC;AACzD,UAAM,KAAK,GAAG,KAAK,MAAM;AAAA,EAC3B;AAAA,EAEA,MAAc,aAAiC;AAC7C,WAAO,YAAY,IAAI,KAAK,QAAQ;AAAA,EACtC;AAEF;","names":["upath","fs","path","fs","upath","crypto","glob","upath","upath","fs","upath","path","fs","crypto","upath","glob","fs","upath","Column","Entity","PrimaryColumn","PrimaryColumn","Column","Entity","fs","upath","path","fs","debug","log","debug","path","fs","debug","path","fs","debug","log","debug","path","fs","debug","log","debug","log","debug","debug","log","debug","w","hasPC","total","crypto","debug","minimatch","log","debug","minimatch","crypto","upath","fs"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes cosineSimilarity(A, B) using worker threads for large inputs,
|
|
3
|
+
* falling back to the synchronous library call for small ones.
|
|
4
|
+
* B is packed into a SharedArrayBuffer shared across all workers — no copies.
|
|
5
|
+
*/
|
|
6
|
+
declare function parallelCosineSimilarity(A: number[][], B: number[][]): Promise<number[][]>;
|
|
7
|
+
|
|
8
|
+
export { parallelCosineSimilarity };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/services/cosineSimilarityWorker.ts
|
|
2
|
+
import { parentPort, workerData } from "worker_threads";
|
|
3
|
+
import { cosineSimilarity } from "@langchain/core/utils/math";
|
|
4
|
+
var { rowsBuffer, rowCount, allBuffer, allCount, dims } = workerData;
|
|
5
|
+
var toMatrix = (buf, count) => Array.from(
|
|
6
|
+
{ length: count },
|
|
7
|
+
(_, i) => Array.from(new Float64Array(buf, i * dims * 8, dims))
|
|
8
|
+
);
|
|
9
|
+
parentPort.postMessage({
|
|
10
|
+
result: cosineSimilarity(toMatrix(rowsBuffer, rowCount), toMatrix(allBuffer, allCount))
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=cosineSimilarityWorker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/cosineSimilarityWorker.ts"],"sourcesContent":["import { parentPort, workerData } from \"node:worker_threads\";\nimport { cosineSimilarity } from \"@langchain/core/utils/math\";\n\nconst { rowsBuffer, rowCount, allBuffer, allCount, dims } = workerData as {\n rowsBuffer: ArrayBuffer;\n rowCount: number;\n /** SharedArrayBuffer so all workers can read B without copying it again. */\n allBuffer: SharedArrayBuffer;\n allCount: number;\n dims: number;\n};\n\nconst toMatrix = (buf: ArrayBuffer | SharedArrayBuffer, count: number): number[][] =>\n Array.from({ length: count }, (_, i) =>\n Array.from(new Float64Array(buf, i * dims * 8, dims))\n );\n\nparentPort!.postMessage({\n result: cosineSimilarity(toMatrix(rowsBuffer, rowCount), toMatrix(allBuffer, allCount)),\n});\n"],"mappings":";AAAA,SAAS,YAAY,kBAAkB;AACvC,SAAS,wBAAwB;AAEjC,IAAM,EAAE,YAAY,UAAU,WAAW,UAAU,KAAK,IAAI;AAS5D,IAAM,WAAW,CAAC,KAAsC,UACtD,MAAM;AAAA,EAAK,EAAE,QAAQ,MAAM;AAAA,EAAG,CAAC,GAAG,MAChC,MAAM,KAAK,IAAI,aAAa,KAAK,IAAI,OAAO,GAAG,IAAI,CAAC;AACtD;AAEF,WAAY,YAAY;AAAA,EACtB,QAAQ,iBAAiB,SAAS,YAAY,QAAQ,GAAG,SAAS,WAAW,QAAQ,CAAC;AACxF,CAAC;","names":[]}
|
package/package.json
CHANGED
|
@@ -30,7 +30,7 @@ export class DuplicateService {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
const thresholds = this.resolveThresholds(config.threshold);
|
|
33
|
-
const duplicates = this.computeDuplicates(allUnits, thresholds, dirtyPaths);
|
|
33
|
+
const duplicates = await this.computeDuplicates(allUnits, thresholds, dirtyPaths);
|
|
34
34
|
const filtered = duplicates.filter((g) => !this.isGroupExcluded(g));
|
|
35
35
|
log("Found %d duplicate groups (%d excluded)", filtered.length, duplicates.length - filtered.length);
|
|
36
36
|
|
|
@@ -52,13 +52,13 @@ export class DuplicateService {
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
private computeDuplicates(
|
|
55
|
+
private async computeDuplicates(
|
|
56
56
|
units: IndexUnit[],
|
|
57
57
|
thresholds: { function: number; block: number; class: number },
|
|
58
58
|
dirtyPaths?: string[]
|
|
59
|
-
): DuplicateGroup[] {
|
|
59
|
+
): Promise<DuplicateGroup[]> {
|
|
60
60
|
this.cache.clearRunCaches();
|
|
61
|
-
this.cache.buildEmbSimCache(units, dirtyPaths);
|
|
61
|
+
await this.cache.buildEmbSimCache(units, dirtyPaths);
|
|
62
62
|
|
|
63
63
|
const duplicates: DuplicateGroup[] = [];
|
|
64
64
|
const t0 = performance.now();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import debug from "debug";
|
|
2
|
-
import { cosineSimilarity } from "@langchain/core/utils/math";
|
|
3
2
|
import { DuplicateGroup, IndexUnit } from "../types";
|
|
3
|
+
import { parallelCosineSimilarity } from "./ParallelSimilarity";
|
|
4
4
|
|
|
5
5
|
const log = debug("DryScan:DuplicationCache");
|
|
6
6
|
|
|
@@ -118,7 +118,7 @@ export class DuplicationCache {
|
|
|
118
118
|
* cells from the old matrix and recomputes only dirty rows via one batched
|
|
119
119
|
* cosineSimilarity call — O(d·n) where d = number of dirty units.
|
|
120
120
|
*/
|
|
121
|
-
buildEmbSimCache(units: IndexUnit[], dirtyPaths?: string[]): void {
|
|
121
|
+
async buildEmbSimCache(units: IndexUnit[], dirtyPaths?: string[]): Promise<void> {
|
|
122
122
|
const embedded = units.filter(u => Array.isArray(u.embedding) && u.embedding.length > 0);
|
|
123
123
|
if (embedded.length < 2) {
|
|
124
124
|
this.embSimMatrix = [];
|
|
@@ -134,7 +134,7 @@ export class DuplicationCache {
|
|
|
134
134
|
if (!dirtySet || !hasPriorMatrix) {
|
|
135
135
|
// Full rebuild
|
|
136
136
|
this.embSimIndex = newIndex;
|
|
137
|
-
this.embSimMatrix =
|
|
137
|
+
this.embSimMatrix = await parallelCosineSimilarity(embeddings, embeddings);
|
|
138
138
|
log("Built full embedding similarity matrix: %d units", embedded.length);
|
|
139
139
|
return;
|
|
140
140
|
}
|
|
@@ -162,7 +162,7 @@ export class DuplicationCache {
|
|
|
162
162
|
|
|
163
163
|
// Recompute dirty rows in one batched call
|
|
164
164
|
const dirtyIndices = embedded.reduce<number[]>((acc, u, i) => (dirtyIds.has(u.id) ? [...acc, i] : acc), []);
|
|
165
|
-
const dirtyRows =
|
|
165
|
+
const dirtyRows = await parallelCosineSimilarity(dirtyIndices.map(i => embeddings[i]), embeddings);
|
|
166
166
|
dirtyIndices.forEach((rowIdx, di) => {
|
|
167
167
|
for (let j = 0; j < n; j++) {
|
|
168
168
|
newMatrix[rowIdx][j] = dirtyRows[di][j];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import { Worker } from "node:worker_threads";
|
|
3
|
+
import { cosineSimilarity } from "@langchain/core/utils/math";
|
|
4
|
+
|
|
5
|
+
/** Minimum row count below which synchronous is faster than worker overhead. */
|
|
6
|
+
const MIN_PARALLEL_ROWS = 50;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Computes cosineSimilarity(A, B) using worker threads for large inputs,
|
|
10
|
+
* falling back to the synchronous library call for small ones.
|
|
11
|
+
* B is packed into a SharedArrayBuffer shared across all workers — no copies.
|
|
12
|
+
*/
|
|
13
|
+
export async function parallelCosineSimilarity(A: number[][], B: number[][]): Promise<number[][]> {
|
|
14
|
+
if (A.length === 0 || B.length === 0) return [];
|
|
15
|
+
if (A.length < MIN_PARALLEL_ROWS) return cosineSimilarity(A, B);
|
|
16
|
+
|
|
17
|
+
const dims = A[0].length;
|
|
18
|
+
const chunkSize = Math.ceil(A.length / os.cpus().length);
|
|
19
|
+
|
|
20
|
+
const sharedB = new SharedArrayBuffer(B.length * dims * 8);
|
|
21
|
+
const bView = new Float64Array(sharedB);
|
|
22
|
+
B.forEach((row, i) => bView.set(row, i * dims));
|
|
23
|
+
|
|
24
|
+
// import.meta.resolve respects the active module loader:
|
|
25
|
+
// under tsx it remaps .js → .ts; in compiled output it stays .js.
|
|
26
|
+
const workerUrl = new URL("./services/cosineSimilarityWorker.js", import.meta.url);
|
|
27
|
+
const execArgv = workerUrl.pathname.endsWith(".ts") ? ["--import", "tsx/esm"] : [];
|
|
28
|
+
|
|
29
|
+
const chunks = Array.from(
|
|
30
|
+
{ length: Math.ceil(A.length / chunkSize) },
|
|
31
|
+
(_, i) => A.slice(i * chunkSize, (i + 1) * chunkSize),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const results = await Promise.all(chunks.map(chunk => runWorker(chunk, sharedB, B.length, dims, workerUrl, execArgv)));
|
|
35
|
+
return results.flat();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function runWorker(
|
|
39
|
+
chunk: number[][],
|
|
40
|
+
sharedB: SharedArrayBuffer,
|
|
41
|
+
bCount: number,
|
|
42
|
+
dims: number,
|
|
43
|
+
workerUrl: URL,
|
|
44
|
+
execArgv: string[],
|
|
45
|
+
): Promise<number[][]> {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
const rowsFlat = new Float64Array(chunk.length * dims);
|
|
48
|
+
chunk.forEach((row, i) => rowsFlat.set(row, i * dims));
|
|
49
|
+
|
|
50
|
+
const worker = new Worker(workerUrl, {
|
|
51
|
+
workerData: { rowsBuffer: rowsFlat.buffer, rowCount: chunk.length, allBuffer: sharedB, allCount: bCount, dims },
|
|
52
|
+
transferList: [rowsFlat.buffer],
|
|
53
|
+
execArgv,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
worker.once("message", ({ result }) => resolve(result));
|
|
57
|
+
worker.once("error", reject);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
2
|
+
import { cosineSimilarity } from "@langchain/core/utils/math";
|
|
3
|
+
|
|
4
|
+
const { rowsBuffer, rowCount, allBuffer, allCount, dims } = workerData as {
|
|
5
|
+
rowsBuffer: ArrayBuffer;
|
|
6
|
+
rowCount: number;
|
|
7
|
+
/** SharedArrayBuffer so all workers can read B without copying it again. */
|
|
8
|
+
allBuffer: SharedArrayBuffer;
|
|
9
|
+
allCount: number;
|
|
10
|
+
dims: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const toMatrix = (buf: ArrayBuffer | SharedArrayBuffer, count: number): number[][] =>
|
|
14
|
+
Array.from({ length: count }, (_, i) =>
|
|
15
|
+
Array.from(new Float64Array(buf, i * dims * 8, dims))
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
parentPort!.postMessage({
|
|
19
|
+
result: cosineSimilarity(toMatrix(rowsBuffer, rowCount), toMatrix(allBuffer, allCount)),
|
|
20
|
+
});
|
package/tsup.config.ts
CHANGED