@getmikk/core 2.0.14 → 2.0.15

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.
Files changed (64) hide show
  1. package/README.md +4 -4
  2. package/package.json +2 -1
  3. package/src/analysis/type-flow.ts +1 -1
  4. package/src/cache/incremental-cache.ts +86 -80
  5. package/src/contract/contract-reader.ts +1 -0
  6. package/src/contract/lock-compiler.ts +95 -13
  7. package/src/contract/schema.ts +2 -0
  8. package/src/error-handler.ts +2 -1
  9. package/src/graph/cluster-detector.ts +2 -4
  10. package/src/graph/dead-code-detector.ts +303 -117
  11. package/src/graph/graph-builder.ts +21 -161
  12. package/src/graph/impact-analyzer.ts +1 -0
  13. package/src/graph/index.ts +2 -0
  14. package/src/graph/rich-function-index.ts +1080 -0
  15. package/src/graph/symbol-table.ts +252 -0
  16. package/src/hash/hash-store.ts +1 -0
  17. package/src/index.ts +2 -0
  18. package/src/parser/base-extractor.ts +19 -0
  19. package/src/parser/boundary-checker.ts +31 -12
  20. package/src/parser/error-recovery.ts +5 -4
  21. package/src/parser/function-body-extractor.ts +248 -0
  22. package/src/parser/go/go-extractor.ts +249 -676
  23. package/src/parser/index.ts +132 -318
  24. package/src/parser/language-registry.ts +57 -0
  25. package/src/parser/oxc-parser.ts +166 -28
  26. package/src/parser/oxc-resolver.ts +179 -11
  27. package/src/parser/parser-constants.ts +1 -0
  28. package/src/parser/rust/rust-extractor.ts +109 -0
  29. package/src/parser/tree-sitter/parser.ts +369 -62
  30. package/src/parser/tree-sitter/queries.ts +106 -10
  31. package/src/parser/types.ts +20 -1
  32. package/src/search/bm25.ts +21 -8
  33. package/src/search/direct-search.ts +472 -0
  34. package/src/search/embedding-provider.ts +249 -0
  35. package/src/search/index.ts +12 -0
  36. package/src/search/semantic-search.ts +435 -0
  37. package/src/utils/artifact-transaction.ts +1 -0
  38. package/src/utils/atomic-write.ts +1 -0
  39. package/src/utils/errors.ts +89 -4
  40. package/src/utils/fs.ts +104 -50
  41. package/src/utils/json.ts +1 -0
  42. package/src/utils/language-registry.ts +84 -6
  43. package/src/utils/path.ts +26 -0
  44. package/tests/dead-code.test.ts +3 -2
  45. package/tests/direct-search.test.ts +435 -0
  46. package/tests/error-recovery.test.ts +143 -0
  47. package/tests/fixtures/simple-api/src/index.ts +1 -1
  48. package/tests/go-parser.test.ts +19 -335
  49. package/tests/js-parser.test.ts +18 -1089
  50. package/tests/language-registry-all.test.ts +276 -0
  51. package/tests/language-registry.test.ts +6 -4
  52. package/tests/parse-diagnostics.test.ts +9 -96
  53. package/tests/parser.test.ts +42 -771
  54. package/tests/polyglot-parser.test.ts +117 -0
  55. package/tests/rich-function-index.test.ts +703 -0
  56. package/tests/tree-sitter-parser.test.ts +108 -80
  57. package/tests/ts-parser.test.ts +8 -8
  58. package/tests/verification.test.ts +175 -0
  59. package/src/parser/base-parser.ts +0 -16
  60. package/src/parser/go/go-parser.ts +0 -43
  61. package/src/parser/javascript/js-extractor.ts +0 -278
  62. package/src/parser/javascript/js-parser.ts +0 -101
  63. package/src/parser/typescript/ts-extractor.ts +0 -447
  64. package/src/parser/typescript/ts-parser.ts +0 -36
@@ -66,9 +66,10 @@ export const JAVA_QUERIES = `
66
66
  `;
67
67
 
68
68
  export const KOTLIN_QUERIES = `
69
- (class_declaration name: (type_identifier) @name) @definition.class
70
- (object_declaration name: (type_identifier) @name) @definition.class
71
- (function_declaration name: (simple_identifier) @name) @definition.function
69
+ ; Kotlin uses type_identifier as child node, not as a named field
70
+ (class_declaration (type_identifier) @name) @definition.class
71
+ (object_declaration (type_identifier) @name) @definition.class
72
+ (function_declaration (simple_identifier) @name) @definition.function
72
73
  (property_declaration (variable_declaration (simple_identifier) @name)) @definition.property
73
74
  (type_alias (type_identifier) @name) @definition.type
74
75
  (import_header (identifier) @import.source) @import
@@ -175,13 +176,11 @@ export const RUST_QUERIES = `
175
176
 
176
177
  export const PHP_QUERIES = `
177
178
  (namespace_definition name: (namespace_name) @name) @definition.namespace
178
- (class_declaration name: (name) @name) @definition.class
179
- (interface_declaration name: (name) @name) @definition.interface
180
- (trait_declaration name: (name) @name) @definition.trait
181
- (enum_declaration name: (name) @name) @definition.enum
182
- (function_definition name: (name) @name) @definition.function
183
- (method_declaration name: (name) @name) @definition.method
184
- (property_declaration (property_element (variable_name (name) @name))) @definition.property
179
+ (class_declaration (name) @name) @definition.class
180
+ (interface_declaration (name) @name) @definition.interface
181
+ (trait_declaration (name) @name) @definition.trait
182
+ (enum_declaration (name) @name) @definition.enum
183
+ (method_declaration (name) @name) @definition.method
185
184
  (namespace_use_declaration (namespace_use_clause (qualified_name) @import.source)) @import
186
185
  (function_call_expression function: (name) @call.name) @call
187
186
  (member_call_expression name: (name) @call.name) @call
@@ -292,3 +291,100 @@ export const RAILS_ROUTE_QUERIES = `
292
291
  arguments: (argument_list (string (string_content) @route.path)))
293
292
  ) @route.def
294
293
  `;
294
+
295
+ // Scala queries - uses class_definition and function_definition
296
+ export const SCALA_QUERIES = `
297
+ (class_definition (identifier) @name) @definition.class
298
+ (object_definition (identifier) @name) @definition.class
299
+ (function_definition (identifier) @name) @definition.function
300
+ (function_definition (identifier) @call.name) @call
301
+ `;
302
+
303
+ // Dart queries - reuse Swift queries
304
+ export const DART_QUERIES = SWIFT_QUERIES;
305
+
306
+ // Zig queries - uses function_declaration
307
+ export const ZIG_QUERIES = `
308
+ (function_declaration (identifier) @name) @definition.function
309
+ (variable_declaration (identifier) @name) @definition.const
310
+ `;
311
+
312
+ // Haskell queries
313
+ export const HASKELL_QUERIES = `
314
+ (class_declaration name: (type) @name) @definition.class
315
+ (function_declaration name: (variable) @name) @definition.function
316
+ (type_signature (variable) @name) @definition.function
317
+ (import_statement (qualified_module) @import.source) @import
318
+ (import_statement (module) @import.source) @import
319
+ (call_expression (variable) @call.name) @call
320
+ (call_expression (qualified_method) @call.name) @call
321
+ `;
322
+
323
+ // Elixir queries - uses call nodes for everything
324
+ export const ELIXIR_QUERIES = `
325
+ (call (identifier) @name) @definition.function
326
+ (call (identifier) @call.name) @call
327
+ `;
328
+
329
+ // Clojure queries
330
+ export const CLOJURE_QUERIES = `
331
+ (namespaceDeclaration name: (symbol) @name) @definition.namespace
332
+ (defn name: (symbol) @name) @definition.function
333
+ (def name: (symbol) @name) @definition.var
334
+ (require :refer (symbol) @import.source) @import
335
+ `;
336
+
337
+ // F# queries
338
+ export const FSHARP_QUERIES = `
339
+ (type_definition name: (type) @name) @definition.type
340
+ (function_definition name: (identifier) @name) @definition.function
341
+ (binding name: (identifier) @name) @definition.var
342
+ (openStatement (identifier) @import.source) @import
343
+ `;
344
+
345
+ // OCaml queries - uses value_definition and value_name
346
+ export const OCAML_QUERIES = `
347
+ (value_definition (let_binding (value_name) @name)) @definition.function
348
+ `;
349
+
350
+ // Perl queries
351
+ export const PERL_QUERIES = `
352
+ (package_declaration name: (package) @name) @definition.package
353
+ (subroutine_definition name: (identifier) @name) @definition.function
354
+ `;
355
+
356
+ // R queries
357
+ export const R_QUERIES = `
358
+ (function_definition name: (identifier) @name) @definition.function
359
+ (assignment_left name: (identifier) @name) @definition.var
360
+ `;
361
+
362
+ // Julia queries
363
+ export const JULIA_QUERIES = `
364
+ (function_definition name: (identifier) @name) @definition.function
365
+ (struct_definition name: (identifier) @name) @definition.struct
366
+ (import_statement (identifier) @import.source) @import
367
+ `;
368
+
369
+ // Lua queries - uses function_definition_statement
370
+ export const LUA_QUERIES = `
371
+ (function_definition_statement (identifier) @name) @definition.function
372
+ (variable_assignment (variable_list (identifier) @name)) @definition.var
373
+ (local_variable_declaration (variable_list (identifier) @name)) @definition.local
374
+ `;
375
+
376
+ // SQL queries
377
+ export const SQL_QUERIES = `
378
+ (create_table (identifier) @name) @definition.table
379
+ (create_index (identifier) @name) @definition.index
380
+ `;
381
+
382
+ // HCL (Terraform) queries - reuse generic
383
+ export const HCL_QUERIES = `
384
+ (block (identifier) @name) @definition.block
385
+ `;
386
+
387
+ // Bash/Shell queries
388
+ export const BASH_QUERIES = `
389
+ (function_definition name: (word) @name) @definition.function
390
+ `;
@@ -2,6 +2,8 @@
2
2
  * Parser types — data shapes that flow through the entire Mikk system.
3
3
  */
4
4
 
5
+ import type { ParsedFileLanguage } from '../utils/language-registry.js';
6
+
5
7
  /** A single parameter in a function signature */
6
8
  export interface ParsedParam {
7
9
  name: string;
@@ -38,6 +40,20 @@ export interface ParsedFunction {
38
40
  edgeCasesHandled: string[];
39
41
  errorHandling: { line: number; type: 'try-catch' | 'throw'; detail: string }[];
40
42
  detailedLines: { startLine: number; endLine: number; blockType: string }[];
43
+ decorators?: string[];
44
+ }
45
+
46
+ /** A single import specifier with alias support */
47
+ export interface ImportSpecifier {
48
+ imported: string;
49
+ local: string;
50
+ }
51
+
52
+ /** A re-export statement (export { X } from './source') */
53
+ export interface ReExport {
54
+ name: string;
55
+ source: string;
56
+ sourceResolved?: string;
41
57
  }
42
58
 
43
59
  /** A single import statement */
@@ -45,6 +61,7 @@ export interface ParsedImport {
45
61
  source: string;
46
62
  resolvedPath: string;
47
63
  names: string[];
64
+ specifiers?: ImportSpecifier[];
48
65
  isDefault: boolean;
49
66
  isDynamic: boolean;
50
67
  }
@@ -66,6 +83,7 @@ export interface ParsedVariable {
66
83
  isExported: boolean;
67
84
  isStatic?: boolean;
68
85
  purpose?: string;
86
+ decorators?: string[];
69
87
  }
70
88
 
71
89
  /** A parsed class */
@@ -116,13 +134,14 @@ export interface ParsedRoute {
116
134
  /** Everything extracted from a single file */
117
135
  export interface ParsedFile {
118
136
  path: string; // normalized absolute path
119
- language: 'python' | 'go' | 'typescript' | 'javascript' | 'java' | 'kotlin' | 'swift' | 'c' | 'cpp' | 'csharp' | 'rust' | 'php' | 'ruby' | 'unknown';
137
+ language: ParsedFileLanguage;
120
138
  functions: ParsedFunction[];
121
139
  classes: ParsedClass[];
122
140
  variables: ParsedVariable[];
123
141
  generics: ParsedGeneric[];
124
142
  imports: ParsedImport[];
125
143
  exports: ParsedExport[];
144
+ reexports?: ReExport[];
126
145
  routes: ParsedRoute[];
127
146
  calls: CallExpression[]; // module-level calls
128
147
  hash: string;
@@ -188,7 +188,7 @@ export function tokenize(text: string): string[] {
188
188
  }
189
189
 
190
190
  /**
191
- * Build search tokens for a function — combines name, purpose, params, file path.
191
+ * Build search tokens for a function — combines name, purpose, params, file path, and body.
192
192
  * This gives BM25 rich content to index beyond just the function name.
193
193
  */
194
194
  export function buildFunctionTokens(fn: {
@@ -197,25 +197,22 @@ export function buildFunctionTokens(fn: {
197
197
  purpose?: string
198
198
  params?: { name: string; type: string }[]
199
199
  returnType?: string
200
+ body?: string
200
201
  }): string[] {
201
202
  const parts: string[] = []
202
203
 
203
- // Function name tokens (highest signal)
204
204
  parts.push(...tokenize(fn.name))
205
205
  parts.push(...tokenize(fn.name))
206
- parts.push(...tokenize(fn.name)) // Triple-weight the name
206
+ parts.push(...tokenize(fn.name))
207
207
  parts.push(`name_exact:${fn.name.toLowerCase()}`)
208
208
 
209
- // File path tokens
210
209
  const filename = fn.file.split('/').pop() ?? fn.file
211
- parts.push(...tokenize(filename.replace(/\.[^.]+$/, ''))) // Strip extension
210
+ parts.push(...tokenize(filename.replace(/\.[^.]+$/, '')))
212
211
 
213
- // Purpose tokens
214
212
  if (fn.purpose) {
215
213
  parts.push(...tokenize(fn.purpose))
216
214
  }
217
215
 
218
- // Parameter name tokens
219
216
  if (fn.params) {
220
217
  for (const p of fn.params) {
221
218
  parts.push(...tokenize(p.name))
@@ -223,10 +220,26 @@ export function buildFunctionTokens(fn: {
223
220
  }
224
221
  }
225
222
 
226
- // Return type tokens
227
223
  if (fn.returnType) {
228
224
  parts.push(...tokenize(fn.returnType))
229
225
  }
230
226
 
227
+ if (fn.body) {
228
+ const cleanedBody = cleanCodeForTokens(fn.body)
229
+ const bodyTokens = tokenize(cleanedBody).slice(0, 50)
230
+ parts.push(...bodyTokens)
231
+ }
232
+
231
233
  return parts
232
234
  }
235
+
236
+ function cleanCodeForTokens(code: string): string {
237
+ return code
238
+ .replace(/\/\*\*[\s\S]*?\*\//g, ' ')
239
+ .replace(/\/\/[^\n]*/g, ' ')
240
+ .replace(/#.*$/gm, ' ')
241
+ .replace(/['"`][^'"`]*['"`]/g, ' ')
242
+ .replace(/\d+/g, ' ')
243
+ .replace(/\s+/g, ' ')
244
+ .trim()
245
+ }