@zuvia-software-solutions/code-mapper 1.4.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.
- package/README.md +215 -0
- package/dist/cli/ai-context.d.ts +19 -0
- package/dist/cli/ai-context.js +168 -0
- package/dist/cli/analyze.d.ts +7 -0
- package/dist/cli/analyze.js +325 -0
- package/dist/cli/augment.d.ts +7 -0
- package/dist/cli/augment.js +27 -0
- package/dist/cli/clean.d.ts +5 -0
- package/dist/cli/clean.js +56 -0
- package/dist/cli/eval-server.d.ts +25 -0
- package/dist/cli/eval-server.js +365 -0
- package/dist/cli/index.d.ts +6 -0
- package/dist/cli/index.js +102 -0
- package/dist/cli/lazy-action.d.ts +6 -0
- package/dist/cli/lazy-action.js +19 -0
- package/dist/cli/list.d.ts +2 -0
- package/dist/cli/list.js +27 -0
- package/dist/cli/mcp.d.ts +8 -0
- package/dist/cli/mcp.js +35 -0
- package/dist/cli/refresh.d.ts +12 -0
- package/dist/cli/refresh.js +165 -0
- package/dist/cli/serve.d.ts +5 -0
- package/dist/cli/serve.js +8 -0
- package/dist/cli/setup.d.ts +6 -0
- package/dist/cli/setup.js +218 -0
- package/dist/cli/status.d.ts +2 -0
- package/dist/cli/status.js +33 -0
- package/dist/cli/tool.d.ts +28 -0
- package/dist/cli/tool.js +87 -0
- package/dist/config/ignore-service.d.ts +32 -0
- package/dist/config/ignore-service.js +282 -0
- package/dist/config/supported-languages.d.ts +23 -0
- package/dist/config/supported-languages.js +52 -0
- package/dist/core/augmentation/engine.d.ts +22 -0
- package/dist/core/augmentation/engine.js +232 -0
- package/dist/core/embeddings/embedder.d.ts +35 -0
- package/dist/core/embeddings/embedder.js +171 -0
- package/dist/core/embeddings/embedding-pipeline.d.ts +41 -0
- package/dist/core/embeddings/embedding-pipeline.js +402 -0
- package/dist/core/embeddings/index.d.ts +5 -0
- package/dist/core/embeddings/index.js +6 -0
- package/dist/core/embeddings/text-generator.d.ts +20 -0
- package/dist/core/embeddings/text-generator.js +159 -0
- package/dist/core/embeddings/types.d.ts +60 -0
- package/dist/core/embeddings/types.js +23 -0
- package/dist/core/graph/graph.d.ts +4 -0
- package/dist/core/graph/graph.js +65 -0
- package/dist/core/graph/types.d.ts +69 -0
- package/dist/core/graph/types.js +3 -0
- package/dist/core/incremental/child-process.d.ts +8 -0
- package/dist/core/incremental/child-process.js +649 -0
- package/dist/core/incremental/refresh-coordinator.d.ts +32 -0
- package/dist/core/incremental/refresh-coordinator.js +147 -0
- package/dist/core/incremental/types.d.ts +78 -0
- package/dist/core/incremental/types.js +153 -0
- package/dist/core/incremental/watcher.d.ts +63 -0
- package/dist/core/incremental/watcher.js +338 -0
- package/dist/core/ingestion/ast-cache.d.ts +12 -0
- package/dist/core/ingestion/ast-cache.js +34 -0
- package/dist/core/ingestion/call-processor.d.ts +34 -0
- package/dist/core/ingestion/call-processor.js +937 -0
- package/dist/core/ingestion/call-routing.d.ts +40 -0
- package/dist/core/ingestion/call-routing.js +97 -0
- package/dist/core/ingestion/cluster-enricher.d.ts +30 -0
- package/dist/core/ingestion/cluster-enricher.js +151 -0
- package/dist/core/ingestion/community-processor.d.ts +26 -0
- package/dist/core/ingestion/community-processor.js +272 -0
- package/dist/core/ingestion/constants.d.ts +5 -0
- package/dist/core/ingestion/constants.js +8 -0
- package/dist/core/ingestion/entry-point-scoring.d.ts +23 -0
- package/dist/core/ingestion/entry-point-scoring.js +317 -0
- package/dist/core/ingestion/export-detection.d.ts +11 -0
- package/dist/core/ingestion/export-detection.js +203 -0
- package/dist/core/ingestion/filesystem-walker.d.ts +18 -0
- package/dist/core/ingestion/filesystem-walker.js +64 -0
- package/dist/core/ingestion/framework-detection.d.ts +42 -0
- package/dist/core/ingestion/framework-detection.js +405 -0
- package/dist/core/ingestion/heritage-processor.d.ts +15 -0
- package/dist/core/ingestion/heritage-processor.js +237 -0
- package/dist/core/ingestion/import-processor.d.ts +31 -0
- package/dist/core/ingestion/import-processor.js +416 -0
- package/dist/core/ingestion/language-config.d.ts +32 -0
- package/dist/core/ingestion/language-config.js +161 -0
- package/dist/core/ingestion/mro-processor.d.ts +32 -0
- package/dist/core/ingestion/mro-processor.js +343 -0
- package/dist/core/ingestion/named-binding-extraction.d.ts +51 -0
- package/dist/core/ingestion/named-binding-extraction.js +343 -0
- package/dist/core/ingestion/parsing-processor.d.ts +20 -0
- package/dist/core/ingestion/parsing-processor.js +282 -0
- package/dist/core/ingestion/pipeline.d.ts +3 -0
- package/dist/core/ingestion/pipeline.js +416 -0
- package/dist/core/ingestion/process-processor.d.ts +42 -0
- package/dist/core/ingestion/process-processor.js +357 -0
- package/dist/core/ingestion/resolution-context.d.ts +40 -0
- package/dist/core/ingestion/resolution-context.js +171 -0
- package/dist/core/ingestion/resolvers/csharp.d.ts +10 -0
- package/dist/core/ingestion/resolvers/csharp.js +101 -0
- package/dist/core/ingestion/resolvers/go.d.ts +8 -0
- package/dist/core/ingestion/resolvers/go.js +33 -0
- package/dist/core/ingestion/resolvers/index.d.ts +14 -0
- package/dist/core/ingestion/resolvers/index.js +10 -0
- package/dist/core/ingestion/resolvers/jvm.d.ts +9 -0
- package/dist/core/ingestion/resolvers/jvm.js +74 -0
- package/dist/core/ingestion/resolvers/php.d.ts +7 -0
- package/dist/core/ingestion/resolvers/php.js +30 -0
- package/dist/core/ingestion/resolvers/ruby.d.ts +9 -0
- package/dist/core/ingestion/resolvers/ruby.js +13 -0
- package/dist/core/ingestion/resolvers/rust.d.ts +5 -0
- package/dist/core/ingestion/resolvers/rust.js +62 -0
- package/dist/core/ingestion/resolvers/standard.d.ts +16 -0
- package/dist/core/ingestion/resolvers/standard.js +144 -0
- package/dist/core/ingestion/resolvers/utils.d.ts +18 -0
- package/dist/core/ingestion/resolvers/utils.js +113 -0
- package/dist/core/ingestion/structure-processor.d.ts +4 -0
- package/dist/core/ingestion/structure-processor.js +39 -0
- package/dist/core/ingestion/symbol-table.d.ts +34 -0
- package/dist/core/ingestion/symbol-table.js +48 -0
- package/dist/core/ingestion/tree-sitter-queries.d.ts +20 -0
- package/dist/core/ingestion/tree-sitter-queries.js +691 -0
- package/dist/core/ingestion/type-env.d.ts +52 -0
- package/dist/core/ingestion/type-env.js +349 -0
- package/dist/core/ingestion/type-extractors/c-cpp.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/c-cpp.js +214 -0
- package/dist/core/ingestion/type-extractors/csharp.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/csharp.js +224 -0
- package/dist/core/ingestion/type-extractors/go.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/go.js +261 -0
- package/dist/core/ingestion/type-extractors/index.d.ts +20 -0
- package/dist/core/ingestion/type-extractors/index.js +30 -0
- package/dist/core/ingestion/type-extractors/jvm.d.ts +5 -0
- package/dist/core/ingestion/type-extractors/jvm.js +386 -0
- package/dist/core/ingestion/type-extractors/php.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/php.js +280 -0
- package/dist/core/ingestion/type-extractors/python.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/python.js +175 -0
- package/dist/core/ingestion/type-extractors/ruby.d.ts +12 -0
- package/dist/core/ingestion/type-extractors/ruby.js +218 -0
- package/dist/core/ingestion/type-extractors/rust.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/rust.js +290 -0
- package/dist/core/ingestion/type-extractors/shared.d.ts +81 -0
- package/dist/core/ingestion/type-extractors/shared.js +322 -0
- package/dist/core/ingestion/type-extractors/swift.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/swift.js +140 -0
- package/dist/core/ingestion/type-extractors/types.d.ts +111 -0
- package/dist/core/ingestion/type-extractors/types.js +4 -0
- package/dist/core/ingestion/type-extractors/typescript.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/typescript.js +227 -0
- package/dist/core/ingestion/utils.d.ts +73 -0
- package/dist/core/ingestion/utils.js +992 -0
- package/dist/core/ingestion/workers/parse-worker.d.ts +99 -0
- package/dist/core/ingestion/workers/parse-worker.js +1055 -0
- package/dist/core/ingestion/workers/worker-pool.d.ts +15 -0
- package/dist/core/ingestion/workers/worker-pool.js +123 -0
- package/dist/core/lbug/csv-generator.d.ts +28 -0
- package/dist/core/lbug/csv-generator.js +355 -0
- package/dist/core/lbug/lbug-adapter.d.ts +96 -0
- package/dist/core/lbug/lbug-adapter.js +753 -0
- package/dist/core/lbug/schema.d.ts +46 -0
- package/dist/core/lbug/schema.js +402 -0
- package/dist/core/search/bm25-index.d.ts +20 -0
- package/dist/core/search/bm25-index.js +123 -0
- package/dist/core/search/hybrid-search.d.ts +32 -0
- package/dist/core/search/hybrid-search.js +131 -0
- package/dist/core/search/query-cache.d.ts +18 -0
- package/dist/core/search/query-cache.js +47 -0
- package/dist/core/search/query-expansion.d.ts +19 -0
- package/dist/core/search/query-expansion.js +75 -0
- package/dist/core/search/reranker.d.ts +29 -0
- package/dist/core/search/reranker.js +122 -0
- package/dist/core/search/types.d.ts +154 -0
- package/dist/core/search/types.js +51 -0
- package/dist/core/semantic/tsgo-service.d.ts +67 -0
- package/dist/core/semantic/tsgo-service.js +355 -0
- package/dist/core/tree-sitter/parser-loader.d.ts +12 -0
- package/dist/core/tree-sitter/parser-loader.js +71 -0
- package/dist/lib/memory-guard.d.ts +35 -0
- package/dist/lib/memory-guard.js +70 -0
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.js +6 -0
- package/dist/mcp/compatible-stdio-transport.d.ts +32 -0
- package/dist/mcp/compatible-stdio-transport.js +209 -0
- package/dist/mcp/core/embedder.d.ts +24 -0
- package/dist/mcp/core/embedder.js +168 -0
- package/dist/mcp/core/lbug-adapter.d.ts +29 -0
- package/dist/mcp/core/lbug-adapter.js +330 -0
- package/dist/mcp/local/local-backend.d.ts +188 -0
- package/dist/mcp/local/local-backend.js +2759 -0
- package/dist/mcp/resources.d.ts +22 -0
- package/dist/mcp/resources.js +379 -0
- package/dist/mcp/server.d.ts +10 -0
- package/dist/mcp/server.js +217 -0
- package/dist/mcp/staleness.d.ts +10 -0
- package/dist/mcp/staleness.js +25 -0
- package/dist/mcp/tools.d.ts +21 -0
- package/dist/mcp/tools.js +202 -0
- package/dist/server/api.d.ts +5 -0
- package/dist/server/api.js +340 -0
- package/dist/server/mcp-http.d.ts +7 -0
- package/dist/server/mcp-http.js +95 -0
- package/dist/storage/git.d.ts +6 -0
- package/dist/storage/git.js +35 -0
- package/dist/storage/repo-manager.d.ts +87 -0
- package/dist/storage/repo-manager.js +249 -0
- package/dist/types/pipeline.d.ts +35 -0
- package/dist/types/pipeline.js +20 -0
- package/hooks/claude/code-mapper-hook.cjs +238 -0
- package/hooks/claude/pre-tool-use.sh +79 -0
- package/hooks/claude/session-start.sh +42 -0
- package/models/mlx-embedder.py +185 -0
- package/package.json +100 -0
- package/scripts/patch-tree-sitter-swift.cjs +74 -0
- package/vendor/leiden/index.cjs +355 -0
- package/vendor/leiden/utils.cjs +392 -0
|
@@ -0,0 +1,46 @@
|
|
|
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[];
|
|
@@ -0,0 +1,402 @@
|
|
|
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
|
+
];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file bm25-index.ts
|
|
3
|
+
* @description Symbol-level full-text search via LadybugDB FTS indexes.
|
|
4
|
+
*
|
|
5
|
+
* Returns individual symbols (functions, classes, methods, interfaces, files)
|
|
6
|
+
* with their nodeId, name, type — NOT just filePaths.
|
|
7
|
+
* This gives the RRF merge symbol-level granularity for accurate ranking.
|
|
8
|
+
*
|
|
9
|
+
* All FTS tables are driven from FTS_TABLES in types.ts — single source of truth.
|
|
10
|
+
*/
|
|
11
|
+
import { type BM25SearchResult } from './types.js';
|
|
12
|
+
export type { BM25SearchResult } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* Symbol-level BM25 search via LadybugDB FTS.
|
|
15
|
+
*
|
|
16
|
+
* Queries all FTS_TABLES in parallel. Returns individual symbols (not filePaths).
|
|
17
|
+
* Deduplicates by nodeId — if the same symbol matches in multiple indexes,
|
|
18
|
+
* take the highest score.
|
|
19
|
+
*/
|
|
20
|
+
export declare function searchFTSFromLbug(query: string, limit?: number, repoId?: string): Promise<BM25SearchResult[]>;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// code-mapper/src/core/search/bm25-index.ts
|
|
2
|
+
/**
|
|
3
|
+
* @file bm25-index.ts
|
|
4
|
+
* @description Symbol-level full-text search via LadybugDB FTS indexes.
|
|
5
|
+
*
|
|
6
|
+
* Returns individual symbols (functions, classes, methods, interfaces, files)
|
|
7
|
+
* with their nodeId, name, type — NOT just filePaths.
|
|
8
|
+
* This gives the RRF merge symbol-level granularity for accurate ranking.
|
|
9
|
+
*
|
|
10
|
+
* All FTS tables are driven from FTS_TABLES in types.ts — single source of truth.
|
|
11
|
+
*/
|
|
12
|
+
import { queryFTS } from '../lbug/lbug-adapter.js';
|
|
13
|
+
import { FTS_TABLES } from './types.js';
|
|
14
|
+
/**
|
|
15
|
+
* Execute a single FTS query returning symbol-level results.
|
|
16
|
+
* Each result has nodeId + name + type, not just filePath.
|
|
17
|
+
*/
|
|
18
|
+
async function queryFTSSymbols(executor, tableName, indexName, query, limit) {
|
|
19
|
+
const escapedQuery = query.replace(/\\/g, '\\\\').replace(/'/g, "''");
|
|
20
|
+
// Return node.id and node.name alongside filePath so we get symbol-level results
|
|
21
|
+
const isFile = tableName === 'File';
|
|
22
|
+
const returnFields = isFile
|
|
23
|
+
? `node.id AS nodeId, node.name AS name, '${tableName}' AS type, node.filePath AS filePath, score`
|
|
24
|
+
: `node.id AS nodeId, node.name AS name, '${tableName}' AS type, node.filePath AS filePath, node.startLine AS startLine, node.endLine AS endLine, score`;
|
|
25
|
+
const cypher = `
|
|
26
|
+
CALL QUERY_FTS_INDEX('${tableName}', '${indexName}', '${escapedQuery}', conjunctive := false)
|
|
27
|
+
RETURN ${returnFields}
|
|
28
|
+
ORDER BY score DESC
|
|
29
|
+
LIMIT ${limit}
|
|
30
|
+
`;
|
|
31
|
+
try {
|
|
32
|
+
const rows = await executor(cypher);
|
|
33
|
+
return rows.map((row) => {
|
|
34
|
+
const r = row;
|
|
35
|
+
const rawScore = r.score ?? 0;
|
|
36
|
+
const score = typeof rawScore === 'number' ? rawScore : parseFloat(String(rawScore)) || 0;
|
|
37
|
+
return {
|
|
38
|
+
nodeId: String(r.nodeId ?? ''),
|
|
39
|
+
name: String(r.name ?? ''),
|
|
40
|
+
type: String(r.type ?? tableName),
|
|
41
|
+
filePath: String(r.filePath ?? ''),
|
|
42
|
+
score,
|
|
43
|
+
...(!isFile && r.startLine != null ? { startLine: Number(r.startLine) } : {}),
|
|
44
|
+
...(!isFile && r.endLine != null ? { endLine: Number(r.endLine) } : {}),
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// ============================================================================
|
|
53
|
+
// MAIN SEARCH FUNCTION
|
|
54
|
+
// ============================================================================
|
|
55
|
+
/**
|
|
56
|
+
* Symbol-level BM25 search via LadybugDB FTS.
|
|
57
|
+
*
|
|
58
|
+
* Queries all FTS_TABLES in parallel. Returns individual symbols (not filePaths).
|
|
59
|
+
* Deduplicates by nodeId — if the same symbol matches in multiple indexes,
|
|
60
|
+
* take the highest score.
|
|
61
|
+
*/
|
|
62
|
+
export async function searchFTSFromLbug(query, limit = 20, repoId) {
|
|
63
|
+
const queryAll = [];
|
|
64
|
+
if (repoId) {
|
|
65
|
+
const { executeQuery } = await import('../../mcp/core/lbug-adapter.js');
|
|
66
|
+
const executor = (cypher) => executeQuery(repoId, cypher);
|
|
67
|
+
for (const { table, index } of FTS_TABLES) {
|
|
68
|
+
queryAll.push(queryFTSSymbols(executor, table, index, query, limit));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
for (const { table, index } of FTS_TABLES) {
|
|
73
|
+
queryAll.push(queryFTS(table, index, query, limit, false)
|
|
74
|
+
.then((rows) => rows.map(r => ({
|
|
75
|
+
nodeId: String(r.nodeId ?? r.id ?? ''),
|
|
76
|
+
name: String(r.name ?? ''),
|
|
77
|
+
type: table,
|
|
78
|
+
filePath: String(r.filePath ?? ''),
|
|
79
|
+
score: typeof r.score === 'number' ? r.score : 0,
|
|
80
|
+
...(r.startLine != null ? { startLine: Number(r.startLine) } : {}),
|
|
81
|
+
...(r.endLine != null ? { endLine: Number(r.endLine) } : {}),
|
|
82
|
+
})))
|
|
83
|
+
.catch(() => []));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const allResults = await Promise.all(queryAll);
|
|
87
|
+
// Symbol-type weight multipliers: functions/methods are more actionable than files
|
|
88
|
+
const TYPE_WEIGHTS = {
|
|
89
|
+
Function: 1.5,
|
|
90
|
+
Method: 1.5,
|
|
91
|
+
Class: 1.3,
|
|
92
|
+
Interface: 1.3,
|
|
93
|
+
File: 1.0,
|
|
94
|
+
};
|
|
95
|
+
// Deduplicate by nodeId — keep highest score per symbol, apply type weighting
|
|
96
|
+
const byNodeId = new Map();
|
|
97
|
+
for (const tableResults of allResults) {
|
|
98
|
+
for (const r of tableResults) {
|
|
99
|
+
if (!r.nodeId)
|
|
100
|
+
continue;
|
|
101
|
+
const weight = TYPE_WEIGHTS[r.type] ?? 1.0;
|
|
102
|
+
const weighted = { ...r, score: r.score * weight };
|
|
103
|
+
const existing = byNodeId.get(r.nodeId);
|
|
104
|
+
if (!existing || weighted.score > existing.score) {
|
|
105
|
+
byNodeId.set(r.nodeId, weighted);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Sort by score descending, assign rank
|
|
110
|
+
const sorted = Array.from(byNodeId.values())
|
|
111
|
+
.sort((a, b) => b.score - a.score)
|
|
112
|
+
.slice(0, limit);
|
|
113
|
+
return sorted.map((r, index) => ({
|
|
114
|
+
nodeId: r.nodeId,
|
|
115
|
+
name: r.name,
|
|
116
|
+
type: r.type,
|
|
117
|
+
filePath: r.filePath,
|
|
118
|
+
score: r.score,
|
|
119
|
+
rank: index + 1,
|
|
120
|
+
...(r.startLine != null ? { startLine: r.startLine } : {}),
|
|
121
|
+
...(r.endLine != null ? { endLine: r.endLine } : {}),
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file hybrid-search.ts
|
|
3
|
+
* @description Combines BM25 (keyword) and semantic (embedding) search using
|
|
4
|
+
* weighted Reciprocal Rank Fusion (RRF) to merge rankings without score normalization
|
|
5
|
+
*
|
|
6
|
+
* All constants come from types.ts (single source of truth)
|
|
7
|
+
* This is the ONLY RRF implementation — local-backend.ts must import this, never reimplement
|
|
8
|
+
*/
|
|
9
|
+
import { type BM25SearchResult, type SemanticSearchResult, type HybridSearchResult, type RRFConfig } from './types.js';
|
|
10
|
+
export type { HybridSearchResult, RRFConfig } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Merge BM25 and semantic results using weighted Reciprocal Rank Fusion
|
|
13
|
+
*
|
|
14
|
+
* Formula: rrfScore = weight * (1 / (k + rank))
|
|
15
|
+
* Results found by both methods get both scores summed (consensus boost)
|
|
16
|
+
*
|
|
17
|
+
* @param bm25Results - BM25 keyword search results (pre-sorted by score desc)
|
|
18
|
+
* @param semanticResults - Semantic embedding search results (pre-sorted by distance asc)
|
|
19
|
+
* @param config - RRF configuration (weights, k, limit)
|
|
20
|
+
*/
|
|
21
|
+
export declare function mergeWithRRF(bm25Results: readonly BM25SearchResult[], semanticResults: readonly SemanticSearchResult[], config?: Partial<RRFConfig>): HybridSearchResult[];
|
|
22
|
+
/** Check if hybrid search is available (FTS always available when DB is open) */
|
|
23
|
+
export declare function isHybridSearchReady(): boolean;
|
|
24
|
+
/** Format hybrid results for LLM consumption */
|
|
25
|
+
export declare function formatHybridResults(results: readonly HybridSearchResult[]): string;
|
|
26
|
+
/**
|
|
27
|
+
* Execute BM25 + semantic search and merge with weighted RRF
|
|
28
|
+
*
|
|
29
|
+
* Uses LadybugDB FTS for always-fresh BM25 results
|
|
30
|
+
* The semanticSearch function is injected to keep this module environment-agnostic
|
|
31
|
+
*/
|
|
32
|
+
export declare function hybridSearch(query: string, limit: number, executeQuery: (cypher: string) => Promise<unknown[]>, semanticSearchFn: (executeQuery: (cypher: string) => Promise<unknown[]>, query: string, k?: number) => Promise<SemanticSearchResult[]>): Promise<HybridSearchResult[]>;
|