@zuvia-software-solutions/code-mapper 1.4.0 → 2.0.0

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 (137) hide show
  1. package/dist/cli/ai-context.js +1 -1
  2. package/dist/cli/analyze.d.ts +1 -0
  3. package/dist/cli/analyze.js +73 -82
  4. package/dist/cli/augment.js +0 -2
  5. package/dist/cli/eval-server.d.ts +2 -2
  6. package/dist/cli/eval-server.js +6 -6
  7. package/dist/cli/index.js +6 -10
  8. package/dist/cli/mcp.d.ts +1 -3
  9. package/dist/cli/mcp.js +3 -3
  10. package/dist/cli/refresh.d.ts +2 -2
  11. package/dist/cli/refresh.js +24 -29
  12. package/dist/cli/status.js +4 -13
  13. package/dist/cli/tool.d.ts +5 -4
  14. package/dist/cli/tool.js +8 -10
  15. package/dist/config/ignore-service.js +14 -34
  16. package/dist/core/augmentation/engine.js +53 -83
  17. package/dist/core/db/adapter.d.ts +99 -0
  18. package/dist/core/db/adapter.js +402 -0
  19. package/dist/core/db/graph-loader.d.ts +27 -0
  20. package/dist/core/db/graph-loader.js +148 -0
  21. package/dist/core/db/queries.d.ts +160 -0
  22. package/dist/core/db/queries.js +441 -0
  23. package/dist/core/db/schema.d.ts +108 -0
  24. package/dist/core/db/schema.js +136 -0
  25. package/dist/core/embeddings/embedder.d.ts +21 -12
  26. package/dist/core/embeddings/embedder.js +104 -50
  27. package/dist/core/embeddings/embedding-pipeline.d.ts +48 -22
  28. package/dist/core/embeddings/embedding-pipeline.js +220 -262
  29. package/dist/core/embeddings/text-generator.js +4 -19
  30. package/dist/core/embeddings/types.d.ts +1 -1
  31. package/dist/core/graph/graph.d.ts +1 -1
  32. package/dist/core/graph/graph.js +1 -0
  33. package/dist/core/graph/types.d.ts +11 -9
  34. package/dist/core/graph/types.js +4 -1
  35. package/dist/core/incremental/refresh.d.ts +46 -0
  36. package/dist/core/incremental/refresh.js +464 -0
  37. package/dist/core/incremental/types.d.ts +2 -1
  38. package/dist/core/incremental/types.js +42 -44
  39. package/dist/core/ingestion/ast-cache.js +1 -0
  40. package/dist/core/ingestion/call-processor.d.ts +15 -3
  41. package/dist/core/ingestion/call-processor.js +448 -60
  42. package/dist/core/ingestion/cluster-enricher.d.ts +1 -1
  43. package/dist/core/ingestion/cluster-enricher.js +2 -0
  44. package/dist/core/ingestion/community-processor.d.ts +1 -1
  45. package/dist/core/ingestion/community-processor.js +8 -3
  46. package/dist/core/ingestion/export-detection.d.ts +1 -1
  47. package/dist/core/ingestion/export-detection.js +1 -1
  48. package/dist/core/ingestion/filesystem-walker.js +1 -1
  49. package/dist/core/ingestion/heritage-processor.d.ts +2 -2
  50. package/dist/core/ingestion/heritage-processor.js +22 -11
  51. package/dist/core/ingestion/import-processor.d.ts +2 -2
  52. package/dist/core/ingestion/import-processor.js +24 -9
  53. package/dist/core/ingestion/language-config.js +7 -4
  54. package/dist/core/ingestion/mro-processor.d.ts +1 -1
  55. package/dist/core/ingestion/mro-processor.js +23 -11
  56. package/dist/core/ingestion/named-binding-extraction.js +5 -5
  57. package/dist/core/ingestion/parsing-processor.d.ts +4 -4
  58. package/dist/core/ingestion/parsing-processor.js +26 -18
  59. package/dist/core/ingestion/pipeline.d.ts +4 -2
  60. package/dist/core/ingestion/pipeline.js +50 -20
  61. package/dist/core/ingestion/process-processor.d.ts +2 -2
  62. package/dist/core/ingestion/process-processor.js +28 -14
  63. package/dist/core/ingestion/resolution-context.d.ts +1 -1
  64. package/dist/core/ingestion/resolution-context.js +14 -4
  65. package/dist/core/ingestion/resolvers/csharp.js +4 -3
  66. package/dist/core/ingestion/resolvers/go.js +3 -1
  67. package/dist/core/ingestion/resolvers/jvm.js +13 -4
  68. package/dist/core/ingestion/resolvers/standard.js +2 -2
  69. package/dist/core/ingestion/resolvers/utils.js +6 -2
  70. package/dist/core/ingestion/route-stitcher.d.ts +15 -0
  71. package/dist/core/ingestion/route-stitcher.js +92 -0
  72. package/dist/core/ingestion/structure-processor.d.ts +1 -1
  73. package/dist/core/ingestion/structure-processor.js +3 -2
  74. package/dist/core/ingestion/symbol-table.d.ts +2 -0
  75. package/dist/core/ingestion/symbol-table.js +5 -1
  76. package/dist/core/ingestion/tree-sitter-queries.d.ts +2 -2
  77. package/dist/core/ingestion/tree-sitter-queries.js +177 -0
  78. package/dist/core/ingestion/type-env.js +20 -0
  79. package/dist/core/ingestion/type-extractors/csharp.js +4 -3
  80. package/dist/core/ingestion/type-extractors/go.js +23 -12
  81. package/dist/core/ingestion/type-extractors/php.js +18 -10
  82. package/dist/core/ingestion/type-extractors/ruby.js +15 -3
  83. package/dist/core/ingestion/type-extractors/rust.js +3 -2
  84. package/dist/core/ingestion/type-extractors/shared.js +3 -2
  85. package/dist/core/ingestion/type-extractors/typescript.js +11 -5
  86. package/dist/core/ingestion/utils.d.ts +27 -4
  87. package/dist/core/ingestion/utils.js +145 -100
  88. package/dist/core/ingestion/workers/parse-worker.d.ts +1 -0
  89. package/dist/core/ingestion/workers/parse-worker.js +97 -29
  90. package/dist/core/ingestion/workers/worker-pool.js +3 -0
  91. package/dist/core/search/bm25-index.d.ts +15 -8
  92. package/dist/core/search/bm25-index.js +48 -98
  93. package/dist/core/search/hybrid-search.d.ts +9 -3
  94. package/dist/core/search/hybrid-search.js +30 -25
  95. package/dist/core/search/reranker.js +9 -7
  96. package/dist/core/search/types.d.ts +0 -4
  97. package/dist/core/semantic/tsgo-service.d.ts +5 -1
  98. package/dist/core/semantic/tsgo-service.js +161 -66
  99. package/dist/lib/tsgo-test.d.ts +2 -0
  100. package/dist/lib/tsgo-test.js +6 -0
  101. package/dist/lib/type-utils.d.ts +25 -0
  102. package/dist/lib/type-utils.js +22 -0
  103. package/dist/lib/utils.d.ts +3 -2
  104. package/dist/lib/utils.js +3 -2
  105. package/dist/mcp/compatible-stdio-transport.js +1 -1
  106. package/dist/mcp/local/local-backend.d.ts +29 -56
  107. package/dist/mcp/local/local-backend.js +808 -1118
  108. package/dist/mcp/resources.js +35 -25
  109. package/dist/mcp/server.d.ts +1 -1
  110. package/dist/mcp/server.js +5 -5
  111. package/dist/mcp/tools.js +24 -25
  112. package/dist/storage/repo-manager.d.ts +2 -12
  113. package/dist/storage/repo-manager.js +1 -47
  114. package/dist/types/pipeline.d.ts +8 -5
  115. package/dist/types/pipeline.js +5 -0
  116. package/package.json +18 -11
  117. package/dist/cli/serve.d.ts +0 -5
  118. package/dist/cli/serve.js +0 -8
  119. package/dist/core/incremental/child-process.d.ts +0 -8
  120. package/dist/core/incremental/child-process.js +0 -649
  121. package/dist/core/incremental/refresh-coordinator.d.ts +0 -32
  122. package/dist/core/incremental/refresh-coordinator.js +0 -147
  123. package/dist/core/lbug/csv-generator.d.ts +0 -28
  124. package/dist/core/lbug/csv-generator.js +0 -355
  125. package/dist/core/lbug/lbug-adapter.d.ts +0 -96
  126. package/dist/core/lbug/lbug-adapter.js +0 -753
  127. package/dist/core/lbug/schema.d.ts +0 -46
  128. package/dist/core/lbug/schema.js +0 -402
  129. package/dist/mcp/core/embedder.d.ts +0 -24
  130. package/dist/mcp/core/embedder.js +0 -168
  131. package/dist/mcp/core/lbug-adapter.d.ts +0 -29
  132. package/dist/mcp/core/lbug-adapter.js +0 -330
  133. package/dist/server/api.d.ts +0 -5
  134. package/dist/server/api.js +0 -340
  135. package/dist/server/mcp-http.d.ts +0 -7
  136. package/dist/server/mcp-http.js +0 -95
  137. package/models/mlx-embedder.py +0 -185
@@ -1,46 +0,0 @@
1
- /**
2
- * @file schema.ts
3
- * @description LadybugDB schema definitions for the hybrid node/relation model
4
- *
5
- * Separate node tables per code element type + single CodeRelation table,
6
- * enabling natural Cypher like: MATCH (f:Function)-[:CodeRelation {type: 'CALLS'}]->(g:Function)
7
- */
8
- export declare const NODE_TABLES: readonly ["File", "Folder", "Function", "Class", "Interface", "Method", "CodeElement", "Community", "Process", "Struct", "Enum", "Macro", "Typedef", "Union", "Namespace", "Trait", "Impl", "TypeAlias", "Const", "Static", "Property", "Record", "Delegate", "Annotation", "Constructor", "Template", "Module"];
9
- export type NodeTableName = typeof NODE_TABLES[number];
10
- export declare const REL_TABLE_NAME = "CodeRelation";
11
- export declare const REL_TYPES: readonly ["CONTAINS", "DEFINES", "IMPORTS", "CALLS", "EXTENDS", "IMPLEMENTS", "HAS_METHOD", "OVERRIDES", "MEMBER_OF", "STEP_IN_PROCESS"];
12
- export type RelType = typeof REL_TYPES[number];
13
- export declare const EMBEDDING_TABLE_NAME = "CodeEmbedding";
14
- export declare const FILE_SCHEMA = "\nCREATE NODE TABLE File (\n id STRING,\n name STRING,\n filePath STRING,\n content STRING,\n PRIMARY KEY (id)\n)";
15
- export declare const FOLDER_SCHEMA = "\nCREATE NODE TABLE Folder (\n id STRING,\n name STRING,\n filePath STRING,\n PRIMARY KEY (id)\n)";
16
- export declare const FUNCTION_SCHEMA = "\nCREATE NODE TABLE Function (\n id STRING,\n name STRING,\n filePath STRING,\n startLine INT64,\n endLine INT64,\n isExported BOOLEAN,\n content STRING,\n description STRING,\n PRIMARY KEY (id)\n)";
17
- export declare const CLASS_SCHEMA = "\nCREATE NODE TABLE Class (\n id STRING,\n name STRING,\n filePath STRING,\n startLine INT64,\n endLine INT64,\n isExported BOOLEAN,\n content STRING,\n description STRING,\n PRIMARY KEY (id)\n)";
18
- export declare const INTERFACE_SCHEMA = "\nCREATE NODE TABLE Interface (\n id STRING,\n name STRING,\n filePath STRING,\n startLine INT64,\n endLine INT64,\n isExported BOOLEAN,\n content STRING,\n description STRING,\n PRIMARY KEY (id)\n)";
19
- export declare const METHOD_SCHEMA = "\nCREATE NODE TABLE Method (\n id STRING,\n name STRING,\n filePath STRING,\n startLine INT64,\n endLine INT64,\n isExported BOOLEAN,\n content STRING,\n description STRING,\n parameterCount INT32,\n returnType STRING,\n PRIMARY KEY (id)\n)";
20
- export declare const CODE_ELEMENT_SCHEMA = "\nCREATE NODE TABLE CodeElement (\n id STRING,\n name STRING,\n filePath STRING,\n startLine INT64,\n endLine INT64,\n isExported BOOLEAN,\n content STRING,\n description STRING,\n PRIMARY KEY (id)\n)";
21
- export declare const COMMUNITY_SCHEMA = "\nCREATE NODE TABLE Community (\n id STRING,\n label STRING,\n heuristicLabel STRING,\n keywords STRING[],\n description STRING,\n enrichedBy STRING,\n cohesion DOUBLE,\n symbolCount INT32,\n PRIMARY KEY (id)\n)";
22
- export declare const PROCESS_SCHEMA = "\nCREATE NODE TABLE Process (\n id STRING,\n label STRING,\n heuristicLabel STRING,\n processType STRING,\n stepCount INT32,\n communities STRING[],\n entryPointId STRING,\n terminalId STRING,\n PRIMARY KEY (id)\n)";
23
- export declare const STRUCT_SCHEMA: string;
24
- export declare const ENUM_SCHEMA: string;
25
- export declare const MACRO_SCHEMA: string;
26
- export declare const TYPEDEF_SCHEMA: string;
27
- export declare const UNION_SCHEMA: string;
28
- export declare const NAMESPACE_SCHEMA: string;
29
- export declare const TRAIT_SCHEMA: string;
30
- export declare const IMPL_SCHEMA: string;
31
- export declare const TYPE_ALIAS_SCHEMA: string;
32
- export declare const CONST_SCHEMA: string;
33
- export declare const STATIC_SCHEMA: string;
34
- export declare const PROPERTY_SCHEMA: string;
35
- export declare const RECORD_SCHEMA: string;
36
- export declare const DELEGATE_SCHEMA: string;
37
- export declare const ANNOTATION_SCHEMA: string;
38
- export declare const CONSTRUCTOR_SCHEMA: string;
39
- export declare const TEMPLATE_SCHEMA: string;
40
- export declare const MODULE_SCHEMA: string;
41
- export declare const RELATION_SCHEMA = "\nCREATE REL TABLE CodeRelation (\n FROM File TO File,\n FROM File TO Folder,\n FROM File TO Function,\n FROM File TO Class,\n FROM File TO Interface,\n FROM File TO Method,\n FROM File TO CodeElement,\n FROM File TO `Struct`,\n FROM File TO `Enum`,\n FROM File TO `Macro`,\n FROM File TO `Typedef`,\n FROM File TO `Union`,\n FROM File TO `Namespace`,\n FROM File TO `Trait`,\n FROM File TO `Impl`,\n FROM File TO `TypeAlias`,\n FROM File TO `Const`,\n FROM File TO `Static`,\n FROM File TO `Property`,\n FROM File TO `Record`,\n FROM File TO `Delegate`,\n FROM File TO `Annotation`,\n FROM File TO `Constructor`,\n FROM File TO `Template`,\n FROM File TO `Module`,\n FROM Folder TO Folder,\n FROM Folder TO File,\n FROM Function TO Function,\n FROM Function TO Method,\n FROM Function TO Class,\n FROM Function TO Community,\n FROM Function TO `Macro`,\n FROM Function TO `Struct`,\n FROM Function TO `Template`,\n FROM Function TO `Enum`,\n FROM Function TO `Namespace`,\n FROM Function TO `TypeAlias`,\n FROM Function TO `Module`,\n FROM Function TO `Impl`,\n FROM Function TO Interface,\n FROM Function TO `Constructor`,\n FROM Function TO `Const`,\n FROM Function TO `Typedef`,\n FROM Function TO `Union`,\n FROM Function TO `Property`,\n FROM Class TO Method,\n FROM Class TO Function,\n FROM Class TO Class,\n FROM Class TO Interface,\n FROM Class TO Community,\n FROM Class TO `Template`,\n FROM Class TO `TypeAlias`,\n FROM Class TO `Struct`,\n FROM Class TO `Enum`,\n FROM Class TO `Annotation`,\n FROM Class TO `Constructor`,\n FROM Class TO `Trait`,\n FROM Class TO `Macro`,\n FROM Class TO `Impl`,\n FROM Class TO `Union`,\n FROM Class TO `Namespace`,\n FROM Class TO `Typedef`,\n FROM Class TO `Property`,\n FROM Method TO Function,\n FROM Method TO Method,\n FROM Method TO Class,\n FROM Method TO Community,\n FROM Method TO `Template`,\n FROM Method TO `Struct`,\n FROM Method TO `TypeAlias`,\n FROM Method TO `Enum`,\n FROM Method TO `Macro`,\n FROM Method TO `Namespace`,\n FROM Method TO `Module`,\n FROM Method TO `Impl`,\n FROM Method TO Interface,\n FROM Method TO `Constructor`,\n FROM Method TO `Property`,\n FROM `Template` TO `Template`,\n FROM `Template` TO Function,\n FROM `Template` TO Method,\n FROM `Template` TO Class,\n FROM `Template` TO `Struct`,\n FROM `Template` TO `TypeAlias`,\n FROM `Template` TO `Enum`,\n FROM `Template` TO `Macro`,\n FROM `Template` TO Interface,\n FROM `Template` TO `Constructor`,\n FROM `Module` TO `Module`,\n FROM CodeElement TO Community,\n FROM Interface TO Community,\n FROM Interface TO Function,\n FROM Interface TO Method,\n FROM Interface TO Class,\n FROM Interface TO Interface,\n FROM Interface TO `TypeAlias`,\n FROM Interface TO `Struct`,\n FROM Interface TO `Constructor`,\n FROM Interface TO `Property`,\n FROM `Struct` TO Community,\n FROM `Struct` TO `Trait`,\n FROM `Struct` TO `Struct`,\n FROM `Struct` TO Class,\n FROM `Struct` TO `Enum`,\n FROM `Struct` TO Function,\n FROM `Struct` TO Method,\n FROM `Struct` TO Interface,\n FROM `Struct` TO `Constructor`,\n FROM `Struct` TO `Property`,\n FROM `Enum` TO `Enum`,\n FROM `Enum` TO Community,\n FROM `Enum` TO Class,\n FROM `Enum` TO Interface,\n FROM `Macro` TO Community,\n FROM `Macro` TO Function,\n FROM `Macro` TO Method,\n FROM `Module` TO Function,\n FROM `Module` TO Method,\n FROM `Typedef` TO Community,\n FROM `Union` TO Community,\n FROM `Namespace` TO Community,\n FROM `Namespace` TO `Struct`,\n FROM `Trait` TO Method,\n FROM `Trait` TO `Constructor`,\n FROM `Trait` TO `Property`,\n FROM `Trait` TO Community,\n FROM `Impl` TO Method,\n FROM `Impl` TO `Constructor`,\n FROM `Impl` TO `Property`,\n FROM `Impl` TO Community,\n FROM `Impl` TO `Trait`,\n FROM `Impl` TO `Struct`,\n FROM `Impl` TO `Impl`,\n FROM `TypeAlias` TO Community,\n FROM `TypeAlias` TO `Trait`,\n FROM `TypeAlias` TO Class,\n FROM `Const` TO Community,\n FROM `Static` TO Community,\n FROM `Property` TO Community,\n FROM `Record` TO Method,\n FROM `Record` TO `Constructor`,\n FROM `Record` TO `Property`,\n FROM `Record` TO Community,\n FROM `Delegate` TO Community,\n FROM `Annotation` TO Community,\n FROM `Constructor` TO Community,\n FROM `Constructor` TO Interface,\n FROM `Constructor` TO Class,\n FROM `Constructor` TO Method,\n FROM `Constructor` TO Function,\n FROM `Constructor` TO `Constructor`,\n FROM `Constructor` TO `Struct`,\n FROM `Constructor` TO `Macro`,\n FROM `Constructor` TO `Template`,\n FROM `Constructor` TO `TypeAlias`,\n FROM `Constructor` TO `Enum`,\n FROM `Constructor` TO `Annotation`,\n FROM `Constructor` TO `Impl`,\n FROM `Constructor` TO `Namespace`,\n FROM `Constructor` TO `Module`,\n FROM `Constructor` TO `Property`,\n FROM `Constructor` TO `Typedef`,\n FROM `Template` TO Community,\n FROM `Module` TO Community,\n FROM Function TO Process,\n FROM Method TO Process,\n FROM Class TO Process,\n FROM Interface TO Process,\n FROM `Struct` TO Process,\n FROM `Constructor` TO Process,\n FROM `Module` TO Process,\n FROM `Macro` TO Process,\n FROM `Impl` TO Process,\n FROM `Typedef` TO Process,\n FROM `TypeAlias` TO Process,\n FROM `Enum` TO Process,\n FROM `Union` TO Process,\n FROM `Namespace` TO Process,\n FROM `Trait` TO Process,\n FROM `Const` TO Process,\n FROM `Static` TO Process,\n FROM `Property` TO Process,\n FROM `Record` TO Process,\n FROM `Delegate` TO Process,\n FROM `Annotation` TO Process,\n FROM `Template` TO Process,\n FROM CodeElement TO Process,\n type STRING,\n confidence DOUBLE,\n reason STRING,\n step INT32,\n callLine INT32\n)";
42
- export declare const EMBEDDING_SCHEMA = "\nCREATE NODE TABLE CodeEmbedding (\n nodeId STRING,\n embedding FLOAT[256],\n PRIMARY KEY (nodeId)\n)";
43
- export declare const CREATE_VECTOR_INDEX_QUERY = "\nCALL CREATE_VECTOR_INDEX('CodeEmbedding', 'code_embedding_idx', 'embedding', metric := 'cosine')\n";
44
- export declare const NODE_SCHEMA_QUERIES: string[];
45
- export declare const REL_SCHEMA_QUERIES: string[];
46
- export declare const SCHEMA_QUERIES: string[];
@@ -1,402 +0,0 @@
1
- // code-mapper/src/core/lbug/schema.ts
2
- /**
3
- * @file schema.ts
4
- * @description LadybugDB schema definitions for the hybrid node/relation model
5
- *
6
- * Separate node tables per code element type + single CodeRelation table,
7
- * enabling natural Cypher like: MATCH (f:Function)-[:CodeRelation {type: 'CALLS'}]->(g:Function)
8
- */
9
- // Node table names
10
- export const NODE_TABLES = [
11
- 'File', 'Folder', 'Function', 'Class', 'Interface', 'Method', 'CodeElement', 'Community', 'Process',
12
- // Multi-language support
13
- 'Struct', 'Enum', 'Macro', 'Typedef', 'Union', 'Namespace', 'Trait', 'Impl',
14
- 'TypeAlias', 'Const', 'Static', 'Property', 'Record', 'Delegate', 'Annotation', 'Constructor', 'Template', 'Module'
15
- ];
16
- // Relation table
17
- export const REL_TABLE_NAME = 'CodeRelation';
18
- // Valid relation types
19
- export const REL_TYPES = ['CONTAINS', 'DEFINES', 'IMPORTS', 'CALLS', 'EXTENDS', 'IMPLEMENTS', 'HAS_METHOD', 'OVERRIDES', 'MEMBER_OF', 'STEP_IN_PROCESS'];
20
- // Embedding table
21
- export const EMBEDDING_TABLE_NAME = 'CodeEmbedding';
22
- // Node table schemas
23
- export const FILE_SCHEMA = `
24
- CREATE NODE TABLE File (
25
- id STRING,
26
- name STRING,
27
- filePath STRING,
28
- content STRING,
29
- PRIMARY KEY (id)
30
- )`;
31
- export const FOLDER_SCHEMA = `
32
- CREATE NODE TABLE Folder (
33
- id STRING,
34
- name STRING,
35
- filePath STRING,
36
- PRIMARY KEY (id)
37
- )`;
38
- export const FUNCTION_SCHEMA = `
39
- CREATE NODE TABLE Function (
40
- id STRING,
41
- name STRING,
42
- filePath STRING,
43
- startLine INT64,
44
- endLine INT64,
45
- isExported BOOLEAN,
46
- content STRING,
47
- description STRING,
48
- PRIMARY KEY (id)
49
- )`;
50
- export const CLASS_SCHEMA = `
51
- CREATE NODE TABLE Class (
52
- id STRING,
53
- name STRING,
54
- filePath STRING,
55
- startLine INT64,
56
- endLine INT64,
57
- isExported BOOLEAN,
58
- content STRING,
59
- description STRING,
60
- PRIMARY KEY (id)
61
- )`;
62
- export const INTERFACE_SCHEMA = `
63
- CREATE NODE TABLE Interface (
64
- id STRING,
65
- name STRING,
66
- filePath STRING,
67
- startLine INT64,
68
- endLine INT64,
69
- isExported BOOLEAN,
70
- content STRING,
71
- description STRING,
72
- PRIMARY KEY (id)
73
- )`;
74
- export const METHOD_SCHEMA = `
75
- CREATE NODE TABLE Method (
76
- id STRING,
77
- name STRING,
78
- filePath STRING,
79
- startLine INT64,
80
- endLine INT64,
81
- isExported BOOLEAN,
82
- content STRING,
83
- description STRING,
84
- parameterCount INT32,
85
- returnType STRING,
86
- PRIMARY KEY (id)
87
- )`;
88
- export const CODE_ELEMENT_SCHEMA = `
89
- CREATE NODE TABLE CodeElement (
90
- id STRING,
91
- name STRING,
92
- filePath STRING,
93
- startLine INT64,
94
- endLine INT64,
95
- isExported BOOLEAN,
96
- content STRING,
97
- description STRING,
98
- PRIMARY KEY (id)
99
- )`;
100
- // Community node table (Leiden algorithm clusters)
101
- export const COMMUNITY_SCHEMA = `
102
- CREATE NODE TABLE Community (
103
- id STRING,
104
- label STRING,
105
- heuristicLabel STRING,
106
- keywords STRING[],
107
- description STRING,
108
- enrichedBy STRING,
109
- cohesion DOUBLE,
110
- symbolCount INT32,
111
- PRIMARY KEY (id)
112
- )`;
113
- // Process node table (execution flow detection)
114
- export const PROCESS_SCHEMA = `
115
- CREATE NODE TABLE Process (
116
- id STRING,
117
- label STRING,
118
- heuristicLabel STRING,
119
- processType STRING,
120
- stepCount INT32,
121
- communities STRING[],
122
- entryPointId STRING,
123
- terminalId STRING,
124
- PRIMARY KEY (id)
125
- )`;
126
- // Multi-language node table schemas
127
- // Generic code element with startLine/endLine for C, C++, Rust, Go, Java, C#, etc
128
- const CODE_ELEMENT_BASE = (name) => `
129
- CREATE NODE TABLE \`${name}\` (
130
- id STRING,
131
- name STRING,
132
- filePath STRING,
133
- startLine INT64,
134
- endLine INT64,
135
- content STRING,
136
- description STRING,
137
- PRIMARY KEY (id)
138
- )`;
139
- export const STRUCT_SCHEMA = CODE_ELEMENT_BASE('Struct');
140
- export const ENUM_SCHEMA = CODE_ELEMENT_BASE('Enum');
141
- export const MACRO_SCHEMA = CODE_ELEMENT_BASE('Macro');
142
- export const TYPEDEF_SCHEMA = CODE_ELEMENT_BASE('Typedef');
143
- export const UNION_SCHEMA = CODE_ELEMENT_BASE('Union');
144
- export const NAMESPACE_SCHEMA = CODE_ELEMENT_BASE('Namespace');
145
- export const TRAIT_SCHEMA = CODE_ELEMENT_BASE('Trait');
146
- export const IMPL_SCHEMA = CODE_ELEMENT_BASE('Impl');
147
- export const TYPE_ALIAS_SCHEMA = CODE_ELEMENT_BASE('TypeAlias');
148
- export const CONST_SCHEMA = CODE_ELEMENT_BASE('Const');
149
- export const STATIC_SCHEMA = CODE_ELEMENT_BASE('Static');
150
- export const PROPERTY_SCHEMA = CODE_ELEMENT_BASE('Property');
151
- export const RECORD_SCHEMA = CODE_ELEMENT_BASE('Record');
152
- export const DELEGATE_SCHEMA = CODE_ELEMENT_BASE('Delegate');
153
- export const ANNOTATION_SCHEMA = CODE_ELEMENT_BASE('Annotation');
154
- export const CONSTRUCTOR_SCHEMA = CODE_ELEMENT_BASE('Constructor');
155
- export const TEMPLATE_SCHEMA = CODE_ELEMENT_BASE('Template');
156
- export const MODULE_SCHEMA = CODE_ELEMENT_BASE('Module');
157
- // Relation table schema — single table with 'type' property connecting all node tables
158
- export const RELATION_SCHEMA = `
159
- CREATE REL TABLE ${REL_TABLE_NAME} (
160
- FROM File TO File,
161
- FROM File TO Folder,
162
- FROM File TO Function,
163
- FROM File TO Class,
164
- FROM File TO Interface,
165
- FROM File TO Method,
166
- FROM File TO CodeElement,
167
- FROM File TO \`Struct\`,
168
- FROM File TO \`Enum\`,
169
- FROM File TO \`Macro\`,
170
- FROM File TO \`Typedef\`,
171
- FROM File TO \`Union\`,
172
- FROM File TO \`Namespace\`,
173
- FROM File TO \`Trait\`,
174
- FROM File TO \`Impl\`,
175
- FROM File TO \`TypeAlias\`,
176
- FROM File TO \`Const\`,
177
- FROM File TO \`Static\`,
178
- FROM File TO \`Property\`,
179
- FROM File TO \`Record\`,
180
- FROM File TO \`Delegate\`,
181
- FROM File TO \`Annotation\`,
182
- FROM File TO \`Constructor\`,
183
- FROM File TO \`Template\`,
184
- FROM File TO \`Module\`,
185
- FROM Folder TO Folder,
186
- FROM Folder TO File,
187
- FROM Function TO Function,
188
- FROM Function TO Method,
189
- FROM Function TO Class,
190
- FROM Function TO Community,
191
- FROM Function TO \`Macro\`,
192
- FROM Function TO \`Struct\`,
193
- FROM Function TO \`Template\`,
194
- FROM Function TO \`Enum\`,
195
- FROM Function TO \`Namespace\`,
196
- FROM Function TO \`TypeAlias\`,
197
- FROM Function TO \`Module\`,
198
- FROM Function TO \`Impl\`,
199
- FROM Function TO Interface,
200
- FROM Function TO \`Constructor\`,
201
- FROM Function TO \`Const\`,
202
- FROM Function TO \`Typedef\`,
203
- FROM Function TO \`Union\`,
204
- FROM Function TO \`Property\`,
205
- FROM Class TO Method,
206
- FROM Class TO Function,
207
- FROM Class TO Class,
208
- FROM Class TO Interface,
209
- FROM Class TO Community,
210
- FROM Class TO \`Template\`,
211
- FROM Class TO \`TypeAlias\`,
212
- FROM Class TO \`Struct\`,
213
- FROM Class TO \`Enum\`,
214
- FROM Class TO \`Annotation\`,
215
- FROM Class TO \`Constructor\`,
216
- FROM Class TO \`Trait\`,
217
- FROM Class TO \`Macro\`,
218
- FROM Class TO \`Impl\`,
219
- FROM Class TO \`Union\`,
220
- FROM Class TO \`Namespace\`,
221
- FROM Class TO \`Typedef\`,
222
- FROM Class TO \`Property\`,
223
- FROM Method TO Function,
224
- FROM Method TO Method,
225
- FROM Method TO Class,
226
- FROM Method TO Community,
227
- FROM Method TO \`Template\`,
228
- FROM Method TO \`Struct\`,
229
- FROM Method TO \`TypeAlias\`,
230
- FROM Method TO \`Enum\`,
231
- FROM Method TO \`Macro\`,
232
- FROM Method TO \`Namespace\`,
233
- FROM Method TO \`Module\`,
234
- FROM Method TO \`Impl\`,
235
- FROM Method TO Interface,
236
- FROM Method TO \`Constructor\`,
237
- FROM Method TO \`Property\`,
238
- FROM \`Template\` TO \`Template\`,
239
- FROM \`Template\` TO Function,
240
- FROM \`Template\` TO Method,
241
- FROM \`Template\` TO Class,
242
- FROM \`Template\` TO \`Struct\`,
243
- FROM \`Template\` TO \`TypeAlias\`,
244
- FROM \`Template\` TO \`Enum\`,
245
- FROM \`Template\` TO \`Macro\`,
246
- FROM \`Template\` TO Interface,
247
- FROM \`Template\` TO \`Constructor\`,
248
- FROM \`Module\` TO \`Module\`,
249
- FROM CodeElement TO Community,
250
- FROM Interface TO Community,
251
- FROM Interface TO Function,
252
- FROM Interface TO Method,
253
- FROM Interface TO Class,
254
- FROM Interface TO Interface,
255
- FROM Interface TO \`TypeAlias\`,
256
- FROM Interface TO \`Struct\`,
257
- FROM Interface TO \`Constructor\`,
258
- FROM Interface TO \`Property\`,
259
- FROM \`Struct\` TO Community,
260
- FROM \`Struct\` TO \`Trait\`,
261
- FROM \`Struct\` TO \`Struct\`,
262
- FROM \`Struct\` TO Class,
263
- FROM \`Struct\` TO \`Enum\`,
264
- FROM \`Struct\` TO Function,
265
- FROM \`Struct\` TO Method,
266
- FROM \`Struct\` TO Interface,
267
- FROM \`Struct\` TO \`Constructor\`,
268
- FROM \`Struct\` TO \`Property\`,
269
- FROM \`Enum\` TO \`Enum\`,
270
- FROM \`Enum\` TO Community,
271
- FROM \`Enum\` TO Class,
272
- FROM \`Enum\` TO Interface,
273
- FROM \`Macro\` TO Community,
274
- FROM \`Macro\` TO Function,
275
- FROM \`Macro\` TO Method,
276
- FROM \`Module\` TO Function,
277
- FROM \`Module\` TO Method,
278
- FROM \`Typedef\` TO Community,
279
- FROM \`Union\` TO Community,
280
- FROM \`Namespace\` TO Community,
281
- FROM \`Namespace\` TO \`Struct\`,
282
- FROM \`Trait\` TO Method,
283
- FROM \`Trait\` TO \`Constructor\`,
284
- FROM \`Trait\` TO \`Property\`,
285
- FROM \`Trait\` TO Community,
286
- FROM \`Impl\` TO Method,
287
- FROM \`Impl\` TO \`Constructor\`,
288
- FROM \`Impl\` TO \`Property\`,
289
- FROM \`Impl\` TO Community,
290
- FROM \`Impl\` TO \`Trait\`,
291
- FROM \`Impl\` TO \`Struct\`,
292
- FROM \`Impl\` TO \`Impl\`,
293
- FROM \`TypeAlias\` TO Community,
294
- FROM \`TypeAlias\` TO \`Trait\`,
295
- FROM \`TypeAlias\` TO Class,
296
- FROM \`Const\` TO Community,
297
- FROM \`Static\` TO Community,
298
- FROM \`Property\` TO Community,
299
- FROM \`Record\` TO Method,
300
- FROM \`Record\` TO \`Constructor\`,
301
- FROM \`Record\` TO \`Property\`,
302
- FROM \`Record\` TO Community,
303
- FROM \`Delegate\` TO Community,
304
- FROM \`Annotation\` TO Community,
305
- FROM \`Constructor\` TO Community,
306
- FROM \`Constructor\` TO Interface,
307
- FROM \`Constructor\` TO Class,
308
- FROM \`Constructor\` TO Method,
309
- FROM \`Constructor\` TO Function,
310
- FROM \`Constructor\` TO \`Constructor\`,
311
- FROM \`Constructor\` TO \`Struct\`,
312
- FROM \`Constructor\` TO \`Macro\`,
313
- FROM \`Constructor\` TO \`Template\`,
314
- FROM \`Constructor\` TO \`TypeAlias\`,
315
- FROM \`Constructor\` TO \`Enum\`,
316
- FROM \`Constructor\` TO \`Annotation\`,
317
- FROM \`Constructor\` TO \`Impl\`,
318
- FROM \`Constructor\` TO \`Namespace\`,
319
- FROM \`Constructor\` TO \`Module\`,
320
- FROM \`Constructor\` TO \`Property\`,
321
- FROM \`Constructor\` TO \`Typedef\`,
322
- FROM \`Template\` TO Community,
323
- FROM \`Module\` TO Community,
324
- FROM Function TO Process,
325
- FROM Method TO Process,
326
- FROM Class TO Process,
327
- FROM Interface TO Process,
328
- FROM \`Struct\` TO Process,
329
- FROM \`Constructor\` TO Process,
330
- FROM \`Module\` TO Process,
331
- FROM \`Macro\` TO Process,
332
- FROM \`Impl\` TO Process,
333
- FROM \`Typedef\` TO Process,
334
- FROM \`TypeAlias\` TO Process,
335
- FROM \`Enum\` TO Process,
336
- FROM \`Union\` TO Process,
337
- FROM \`Namespace\` TO Process,
338
- FROM \`Trait\` TO Process,
339
- FROM \`Const\` TO Process,
340
- FROM \`Static\` TO Process,
341
- FROM \`Property\` TO Process,
342
- FROM \`Record\` TO Process,
343
- FROM \`Delegate\` TO Process,
344
- FROM \`Annotation\` TO Process,
345
- FROM \`Template\` TO Process,
346
- FROM CodeElement TO Process,
347
- type STRING,
348
- confidence DOUBLE,
349
- reason STRING,
350
- step INT32,
351
- callLine INT32
352
- )`;
353
- // Embedding table schema (separate table to avoid COW overhead)
354
- export const EMBEDDING_SCHEMA = `
355
- CREATE NODE TABLE ${EMBEDDING_TABLE_NAME} (
356
- nodeId STRING,
357
- embedding FLOAT[256],
358
- PRIMARY KEY (nodeId)
359
- )`;
360
- // HNSW vector index for semantic search (cosine similarity)
361
- export const CREATE_VECTOR_INDEX_QUERY = `
362
- CALL CREATE_VECTOR_INDEX('${EMBEDDING_TABLE_NAME}', 'code_embedding_idx', 'embedding', metric := 'cosine')
363
- `;
364
- // All schema queries in order (node tables before relationship tables)
365
- export const NODE_SCHEMA_QUERIES = [
366
- FILE_SCHEMA,
367
- FOLDER_SCHEMA,
368
- FUNCTION_SCHEMA,
369
- CLASS_SCHEMA,
370
- INTERFACE_SCHEMA,
371
- METHOD_SCHEMA,
372
- CODE_ELEMENT_SCHEMA,
373
- COMMUNITY_SCHEMA,
374
- PROCESS_SCHEMA,
375
- // Multi-language support
376
- STRUCT_SCHEMA,
377
- ENUM_SCHEMA,
378
- MACRO_SCHEMA,
379
- TYPEDEF_SCHEMA,
380
- UNION_SCHEMA,
381
- NAMESPACE_SCHEMA,
382
- TRAIT_SCHEMA,
383
- IMPL_SCHEMA,
384
- TYPE_ALIAS_SCHEMA,
385
- CONST_SCHEMA,
386
- STATIC_SCHEMA,
387
- PROPERTY_SCHEMA,
388
- RECORD_SCHEMA,
389
- DELEGATE_SCHEMA,
390
- ANNOTATION_SCHEMA,
391
- CONSTRUCTOR_SCHEMA,
392
- TEMPLATE_SCHEMA,
393
- MODULE_SCHEMA,
394
- ];
395
- export const REL_SCHEMA_QUERIES = [
396
- RELATION_SCHEMA,
397
- ];
398
- export const SCHEMA_QUERIES = [
399
- ...NODE_SCHEMA_QUERIES,
400
- ...REL_SCHEMA_QUERIES,
401
- EMBEDDING_SCHEMA,
402
- ];
@@ -1,24 +0,0 @@
1
- /**
2
- * @file embedder.ts
3
- * @description MLX-accelerated query embedder for MCP semantic search
4
- *
5
- * Spawns a persistent Python subprocess running Jina Code 1.5B on Metal.
6
- * Query embeddings use task="nl2code" with prompt_type="query" for optimal
7
- * natural-language-to-code matching. Includes LRU cache.
8
- *
9
- * Fail-fast — requires Python 3 + MLX + the downloaded model.
10
- */
11
- /** Initialize the MLX embedder */
12
- export declare function initEmbedder(): Promise<any>;
13
- /** Check if embedder is ready */
14
- export declare function isEmbedderReady(): boolean;
15
- /** Embed a query text for semantic search (cached, uses "query" prompt type) */
16
- export declare function embedQuery(query: string): Promise<number[]>;
17
- /**
18
- * Embed multiple texts in a single batch (for incremental embedding refresh)
19
- */
20
- export declare function embedBatch(texts: string[]): Promise<number[][]>;
21
- /** Get embedding dimensions */
22
- export declare function getEmbeddingDims(): number;
23
- /** Cleanup embedder subprocess */
24
- export declare function disposeEmbedder(): Promise<void>;
@@ -1,168 +0,0 @@
1
- // code-mapper/src/mcp/core/embedder.ts
2
- /**
3
- * @file embedder.ts
4
- * @description MLX-accelerated query embedder for MCP semantic search
5
- *
6
- * Spawns a persistent Python subprocess running Jina Code 1.5B on Metal.
7
- * Query embeddings use task="nl2code" with prompt_type="query" for optimal
8
- * natural-language-to-code matching. Includes LRU cache.
9
- *
10
- * Fail-fast — requires Python 3 + MLX + the downloaded model.
11
- */
12
- import { spawn, execFileSync } from 'child_process';
13
- import path from 'path';
14
- import { fileURLToPath } from 'url';
15
- import { queryEmbeddingCache } from '../../core/search/query-cache.js';
16
- const __filename = fileURLToPath(import.meta.url);
17
- const __dirname = path.dirname(__filename);
18
- // Path to MLX embedder script
19
- const MLX_SCRIPT = path.resolve(__dirname, '..', '..', '..', 'models', 'mlx-embedder.py');
20
- // Embedding dimensions — must match what was used at index time
21
- const EMBEDDING_DIMS = 256;
22
- // Singleton subprocess
23
- let mlxProcess = null;
24
- let pendingResolve = null;
25
- let pendingReject = null;
26
- let lineBuffer = '';
27
- let ready = false;
28
- function ensureProcess() {
29
- if (mlxProcess && !mlxProcess.killed)
30
- return mlxProcess;
31
- // Check prerequisites
32
- try {
33
- execFileSync('python3', ['-c', 'import mlx; import tokenizers'], {
34
- timeout: 5000,
35
- stdio: ['pipe', 'pipe', 'pipe'],
36
- });
37
- }
38
- catch {
39
- throw new Error('MLX embedder requires Python 3 + MLX on Apple Silicon.\n' +
40
- 'Install: pip3 install mlx tokenizers huggingface_hub\n' +
41
- 'The embedding model will download automatically on first use (~3GB).');
42
- }
43
- mlxProcess = spawn('python3', [MLX_SCRIPT], {
44
- stdio: ['pipe', 'pipe', 'pipe'],
45
- env: { ...process.env, TOKENIZERS_PARALLELISM: 'false' },
46
- });
47
- lineBuffer = '';
48
- mlxProcess.stdout.on('data', (chunk) => {
49
- lineBuffer += chunk.toString();
50
- const lines = lineBuffer.split('\n');
51
- lineBuffer = lines.pop() || '';
52
- for (const line of lines) {
53
- if (!line.trim())
54
- continue;
55
- try {
56
- const msg = JSON.parse(line);
57
- if (msg.status === 'ready' && !ready) {
58
- ready = true;
59
- console.error(`Code Mapper: MLX query embedder ready (${msg.device})`);
60
- }
61
- if (pendingResolve) {
62
- const resolve = pendingResolve;
63
- pendingResolve = null;
64
- pendingReject = null;
65
- resolve(msg);
66
- }
67
- }
68
- catch { }
69
- }
70
- });
71
- mlxProcess.stderr.on('data', (chunk) => {
72
- // Suppress stderr during MCP stdio to avoid corrupting the protocol
73
- // Only log in non-MCP contexts
74
- });
75
- mlxProcess.on('exit', (code) => {
76
- ready = false;
77
- mlxProcess = null;
78
- if (pendingReject) {
79
- const reject = pendingReject;
80
- pendingResolve = null;
81
- pendingReject = null;
82
- reject(new Error(`MLX embedder exited with code ${code}`));
83
- }
84
- });
85
- return mlxProcess;
86
- }
87
- function sendAndReceive(request) {
88
- return new Promise((resolve, reject) => {
89
- const proc = ensureProcess();
90
- pendingResolve = resolve;
91
- pendingReject = reject;
92
- proc.stdin.write(JSON.stringify(request) + '\n');
93
- });
94
- }
95
- /** Initialize the MLX embedder */
96
- export async function initEmbedder() {
97
- if (ready)
98
- return;
99
- ensureProcess();
100
- const msg = await sendAndReceive({ cmd: 'ping' });
101
- if (msg.error)
102
- throw new Error(`MLX embedder failed: ${msg.error}`);
103
- return msg;
104
- }
105
- /** Check if embedder is ready */
106
- export function isEmbedderReady() {
107
- return ready;
108
- }
109
- /** Embed a query text for semantic search (cached, uses "query" prompt type) */
110
- export async function embedQuery(query) {
111
- // Check cache first
112
- const cached = queryEmbeddingCache.get(query);
113
- if (cached)
114
- return cached;
115
- if (!ready)
116
- await initEmbedder();
117
- const result = await sendAndReceive({
118
- texts: [query],
119
- task: 'nl2code',
120
- type: 'query', // query prompt type for natural-language-to-code matching
121
- dims: EMBEDDING_DIMS,
122
- });
123
- if (result.error)
124
- throw new Error(`Query embedding failed: ${result.error}`);
125
- const embedding = result.embeddings[0];
126
- // Cache for future lookups
127
- queryEmbeddingCache.set(query, embedding);
128
- return embedding;
129
- }
130
- /**
131
- * Embed multiple texts in a single batch (for incremental embedding refresh)
132
- */
133
- export async function embedBatch(texts) {
134
- if (texts.length === 0)
135
- return [];
136
- if (!ready)
137
- await initEmbedder();
138
- const result = await sendAndReceive({
139
- texts,
140
- task: 'nl2code',
141
- type: 'passage',
142
- dims: EMBEDDING_DIMS,
143
- });
144
- if (result.error)
145
- throw new Error(`Batch embedding failed: ${result.error}`);
146
- return result.embeddings;
147
- }
148
- /** Get embedding dimensions */
149
- export function getEmbeddingDims() {
150
- return EMBEDDING_DIMS;
151
- }
152
- /** Cleanup embedder subprocess */
153
- export async function disposeEmbedder() {
154
- if (mlxProcess && !mlxProcess.killed) {
155
- try {
156
- mlxProcess.stdin.write(JSON.stringify({ cmd: 'quit' }) + '\n');
157
- await new Promise(resolve => setTimeout(resolve, 500));
158
- }
159
- catch { }
160
- try {
161
- mlxProcess.kill();
162
- }
163
- catch { }
164
- mlxProcess = null;
165
- }
166
- ready = false;
167
- queryEmbeddingCache.clear();
168
- }
@@ -1,29 +0,0 @@
1
- /** @file lbug-adapter.ts
2
- * @description LadybugDB connection pool adapter keyed by repoId
3
- * Provides checkout/return pool so each concurrent query gets its own Connection
4
- * from the same Database (Connections are NOT thread-safe)
5
- * @see https://docs.ladybugdb.com/concurrency */
6
- import lbug from '@ladybugdb/core';
7
- /**
8
- * Initialize (or reuse) a Database + connection pool for a specific repo
9
- * Retries on lock errors (e.g., when `code-mapper analyze` is running)
10
- */
11
- export declare const initLbug: (repoId: string, dbPath: string) => Promise<void>;
12
- export declare const executeQuery: (repoId: string, cypher: string) => Promise<any[]>;
13
- /** Execute a parameterized query using prepare/execute to prevent Cypher injection */
14
- export declare const executeParameterized: (repoId: string, cypher: string, params: Record<string, any>) => Promise<any[]>;
15
- /** Close one or all repo pools (provide repoId for single, omit for all) */
16
- export declare const closeLbug: (repoId?: string) => Promise<void>;
17
- /** Invalidate a repo's pool and shared DB cache, forcing fresh connections on next init.
18
- * Closes the native Database handle to release the file lock so a child process
19
- * can open the DB in read-write mode for incremental refresh.
20
- * Used before AND after the incremental refresh child process writes to the DB. */
21
- export declare const invalidateAndReopen: (repoId: string) => Promise<void>;
22
- /** Check if a specific repo's pool is active */
23
- export declare const isLbugReady: (repoId: string) => boolean;
24
- /**
25
- * Open a short-lived read-write connection, execute the callback, then close.
26
- * The read-only pool must be invalidated BEFORE calling this to avoid lock
27
- * conflicts. Retries on lock errors (e.g., concurrent `code-mapper analyze`).
28
- */
29
- export declare const withWriteConnection: <T>(dbPath: string, fn: (conn: lbug.Connection) => Promise<T>) => Promise<T>;