@goshenkata/dryscan-core 1.0.15 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,263 @@
1
+ declare enum IndexUnitType {
2
+ CLASS = "class",
3
+ FUNCTION = "function",
4
+ BLOCK = "block"
5
+ }
6
+ interface DuplicateGroup {
7
+ id: string;
8
+ similarity: number;
9
+ left: DuplicateSide;
10
+ right: DuplicateSide;
11
+ shortId: string;
12
+ exclusionString: string;
13
+ }
14
+ interface DuplicationScore {
15
+ score: number;
16
+ grade: 'Excellent' | 'Good' | 'Fair' | 'Poor' | 'Critical';
17
+ totalLines: number;
18
+ duplicateLines: number;
19
+ duplicateGroups: number;
20
+ }
21
+ interface DuplicateReport {
22
+ version: number;
23
+ generatedAt: string;
24
+ threshold: number;
25
+ grade: DuplicationScore["grade"];
26
+ score: DuplicationScore;
27
+ duplicates: DuplicateGroup[];
28
+ }
29
+ interface DuplicateSide {
30
+ id: string;
31
+ name: string;
32
+ filePath: string;
33
+ startLine: number;
34
+ endLine: number;
35
+ code: string;
36
+ unitType: IndexUnitType;
37
+ }
38
+ interface DryConfig {
39
+ excludedPaths: string[];
40
+ excludedPairs: string[];
41
+ minLines: number;
42
+ minBlockLines: number;
43
+ threshold: number;
44
+ embeddingModel: string;
45
+ embeddingSource?: string;
46
+ contextLength: number;
47
+ }
48
+ interface IndexUnit {
49
+ id: string;
50
+ name: string;
51
+ filePath: string;
52
+ startLine: number;
53
+ endLine: number;
54
+ code: string;
55
+ unitType: IndexUnitType;
56
+ parentId?: string | null;
57
+ parent?: IndexUnit | null;
58
+ children?: IndexUnit[];
59
+ embedding?: number[] | null;
60
+ }
61
+
62
+ interface LanguageExtractor {
63
+ readonly id: string;
64
+ readonly exts: string[];
65
+ supports(filePath: string): boolean;
66
+ extractFromText(filePath: string, source: string): Promise<IndexUnit[]>;
67
+ unitLabel(unit: IndexUnit): string | null;
68
+ }
69
+
70
+ /**
71
+ * Extracts and indexes code units (classes, functions, blocks) for a repository.
72
+ * Owns shared file-system helpers and delegates language-specific parsing to LanguageExtractors.
73
+ */
74
+ declare class IndexUnitExtractor {
75
+ private readonly root;
76
+ readonly extractors: LanguageExtractor[];
77
+ private readonly gitignore;
78
+ constructor(rootPath: string, extractors?: LanguageExtractor[]);
79
+ /**
80
+ * Lists all supported source files from a path. Honors exclusion globs from config.
81
+ */
82
+ listSourceFiles(dirPath: string): Promise<string[]>;
83
+ /**
84
+ * Computes MD5 checksum of file content to track changes.
85
+ */
86
+ computeChecksum(filePath: string): Promise<string>;
87
+ /**
88
+ * Scans a file or directory and extracts indexable units using the matching LanguageExtractor.
89
+ * The returned units have repo-relative file paths and no embedding attached.
90
+ */
91
+ scan(targetPath: string): Promise<IndexUnit[]>;
92
+ /**
93
+ * Scans a directory recursively, extracting units from supported files while honoring exclusions.
94
+ */
95
+ private scanDirectory;
96
+ /**
97
+ * Scans a single file and extracts supported units.
98
+ */
99
+ private scanFile;
100
+ /**
101
+ * Extracts units from a supported file.
102
+ * Optionally throws when the file type is unsupported (used when scanning an explicit file).
103
+ */
104
+ private tryScanSupportedFile;
105
+ /**
106
+ * Converts an absolute path to a repo-relative, normalized (POSIX-style) path.
107
+ * This keeps paths stable across platforms and consistent in the index/DB.
108
+ */
109
+ private relPath;
110
+ /**
111
+ * Returns true if a repo-relative path matches any configured exclusion glob.
112
+ */
113
+ private shouldExclude;
114
+ private loadConfig;
115
+ /**
116
+ * Normalizes repo-relative paths and strips leading "./" to keep matcher inputs consistent.
117
+ */
118
+ private normalizeRelPath;
119
+ private resolveTarget;
120
+ private filterSingleFile;
121
+ private globSourceFiles;
122
+ private filterSupportedFiles;
123
+ }
124
+
125
+ /**
126
+ * Represents a tracked source file in the repository.
127
+ * Used to detect changes via checksum and mtime for incremental updates.
128
+ */
129
+ declare class FileEntity {
130
+ /**
131
+ * Relative path to the file from repository root.
132
+ * Used as primary key for uniqueness.
133
+ */
134
+ filePath: string;
135
+ /**
136
+ * MD5 checksum of file content.
137
+ * Used to detect content changes.
138
+ */
139
+ checksum: string;
140
+ /**
141
+ * Last modification time in milliseconds since epoch.
142
+ * Used as fast sanity check before computing checksum.
143
+ */
144
+ mtime: number;
145
+ }
146
+
147
+ declare class DryScanDatabase {
148
+ private dataSource?;
149
+ private unitRepository?;
150
+ private fileRepository?;
151
+ isInitialized(): boolean;
152
+ init(dbPath: string): Promise<void>;
153
+ saveUnit(unit: IndexUnit): Promise<void>;
154
+ saveUnits(units: IndexUnit | IndexUnit[]): Promise<void>;
155
+ getUnit(id: string): Promise<IndexUnit | null>;
156
+ getAllUnits(): Promise<IndexUnit[]>;
157
+ updateUnit(unit: IndexUnit): Promise<void>;
158
+ updateUnits(units: IndexUnit | IndexUnit[]): Promise<void>;
159
+ /**
160
+ * Returns total count of indexed units.
161
+ */
162
+ countUnits(): Promise<number>;
163
+ /**
164
+ * Removes index units by their file paths.
165
+ * Used during incremental updates when files change.
166
+ */
167
+ removeUnitsByFilePaths(filePaths: string[]): Promise<void>;
168
+ /**
169
+ * Saves file metadata (path, checksum, mtime) to track changes.
170
+ */
171
+ saveFile(file: FileEntity): Promise<void>;
172
+ /**
173
+ * Saves multiple file metadata entries.
174
+ */
175
+ saveFiles(files: FileEntity[]): Promise<void>;
176
+ /**
177
+ * Gets file metadata by file path.
178
+ */
179
+ getFile(filePath: string): Promise<FileEntity | null>;
180
+ /**
181
+ * Gets all tracked files.
182
+ */
183
+ getAllFiles(): Promise<FileEntity[]>;
184
+ /**
185
+ * Removes file metadata entries by file paths.
186
+ * Used when files are deleted from repository.
187
+ */
188
+ removeFilesByFilePaths(filePaths: string[]): Promise<void>;
189
+ close(): Promise<void>;
190
+ }
191
+
192
+ interface InitOptions$1 {
193
+ skipEmbeddings?: boolean;
194
+ }
195
+
196
+ type InitOptions = InitOptions$1;
197
+ declare class DryScan {
198
+ repoPath: string;
199
+ private readonly extractor;
200
+ private db;
201
+ private readonly services;
202
+ private readonly serviceDeps;
203
+ constructor(repoPath: string, extractor?: IndexUnitExtractor, db?: DryScanDatabase);
204
+ /**
205
+ * Initializes the DryScan repository with a 3-phase analysis:
206
+ * Phase 1: Extract and save all functions
207
+ * Phase 2: Resolve and save internal dependencies
208
+ * Phase 3: Compute and save semantic embeddings
209
+ */
210
+ init(options?: InitOptions): Promise<void>;
211
+ /**
212
+ * Updates the index by detecting changed, new, and deleted files.
213
+ * Only reprocesses units in changed files for efficiency.
214
+ * Delegates to DryScanUpdater module for implementation.
215
+ *
216
+ * Update process:
217
+ * 1. List all current source files in repository
218
+ * 2. For each file, check if it's new, changed, or unchanged (via mtime + checksum)
219
+ * 3. Remove old units from changed/deleted files
220
+ * 4. Extract and save units from new/changed files
221
+ * 5. Recompute internal dependencies for affected units
222
+ * 6. Recompute embeddings for affected units
223
+ * 7. Update file tracking metadata
224
+ */
225
+ updateIndex(): Promise<void>;
226
+ /**
227
+ * Runs duplicate detection and returns a normalized report payload ready for persistence or display.
228
+ */
229
+ buildDuplicateReport(): Promise<DuplicateReport>;
230
+ /**
231
+ * Finds duplicate code blocks using cosine similarity on embeddings.
232
+ * Automatically updates the index before searching to ensure results are current.
233
+ * Compares all function pairs and returns groups with similarity above the configured threshold.
234
+ *
235
+ * @returns Analysis result with duplicate groups and duplication score
236
+ */
237
+ private findDuplicates;
238
+ /**
239
+ * Cleans excludedPairs entries that no longer match any indexed units.
240
+ * Runs an update first to ensure the index reflects current code.
241
+ */
242
+ cleanExclusions(): Promise<{
243
+ removed: number;
244
+ kept: number;
245
+ }>;
246
+ private ensureDatabase;
247
+ private loadConfig;
248
+ private isInitialized;
249
+ }
250
+
251
+ declare class ConfigStore {
252
+ private readonly cache;
253
+ private readonly loading;
254
+ init(repoPath: string): Promise<DryConfig>;
255
+ get(repoPath: string): Promise<DryConfig>;
256
+ refresh(repoPath: string): Promise<DryConfig>;
257
+ save(repoPath: string, config: DryConfig): Promise<void>;
258
+ private load;
259
+ private normalize;
260
+ }
261
+ declare const configStore: ConfigStore;
262
+
263
+ export { type DryConfig, DryScan, type DuplicateGroup, type DuplicateReport, type DuplicationScore, configStore };