@duytransipher/gitnexus 1.4.6-sipher.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/LICENSE +73 -0
- package/README.md +261 -0
- package/dist/cli/ai-context.d.ts +23 -0
- package/dist/cli/ai-context.js +265 -0
- package/dist/cli/analyze.d.ts +12 -0
- package/dist/cli/analyze.js +345 -0
- package/dist/cli/augment.d.ts +13 -0
- package/dist/cli/augment.js +33 -0
- package/dist/cli/clean.d.ts +10 -0
- package/dist/cli/clean.js +60 -0
- package/dist/cli/eval-server.d.ts +37 -0
- package/dist/cli/eval-server.js +389 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +137 -0
- package/dist/cli/lazy-action.d.ts +6 -0
- package/dist/cli/lazy-action.js +18 -0
- package/dist/cli/list.d.ts +6 -0
- package/dist/cli/list.js +30 -0
- package/dist/cli/mcp.d.ts +8 -0
- package/dist/cli/mcp.js +36 -0
- package/dist/cli/serve.d.ts +4 -0
- package/dist/cli/serve.js +6 -0
- package/dist/cli/setup.d.ts +8 -0
- package/dist/cli/setup.js +367 -0
- package/dist/cli/sipher-patched.d.ts +2 -0
- package/dist/cli/sipher-patched.js +77 -0
- package/dist/cli/skill-gen.d.ts +26 -0
- package/dist/cli/skill-gen.js +549 -0
- package/dist/cli/status.d.ts +6 -0
- package/dist/cli/status.js +36 -0
- package/dist/cli/tool.d.ts +60 -0
- package/dist/cli/tool.js +180 -0
- package/dist/cli/wiki.d.ts +15 -0
- package/dist/cli/wiki.js +365 -0
- package/dist/config/ignore-service.d.ts +26 -0
- package/dist/config/ignore-service.js +284 -0
- package/dist/config/supported-languages.d.ts +15 -0
- package/dist/config/supported-languages.js +16 -0
- package/dist/core/augmentation/engine.d.ts +26 -0
- package/dist/core/augmentation/engine.js +240 -0
- package/dist/core/embeddings/embedder.d.ts +60 -0
- package/dist/core/embeddings/embedder.js +251 -0
- package/dist/core/embeddings/embedding-pipeline.d.ts +51 -0
- package/dist/core/embeddings/embedding-pipeline.js +356 -0
- package/dist/core/embeddings/index.d.ts +9 -0
- package/dist/core/embeddings/index.js +9 -0
- package/dist/core/embeddings/text-generator.d.ts +24 -0
- package/dist/core/embeddings/text-generator.js +182 -0
- package/dist/core/embeddings/types.d.ts +87 -0
- package/dist/core/embeddings/types.js +32 -0
- package/dist/core/graph/graph.d.ts +2 -0
- package/dist/core/graph/graph.js +66 -0
- package/dist/core/graph/types.d.ts +66 -0
- package/dist/core/graph/types.js +1 -0
- package/dist/core/ingestion/ast-cache.d.ts +11 -0
- package/dist/core/ingestion/ast-cache.js +35 -0
- package/dist/core/ingestion/call-processor.d.ts +23 -0
- package/dist/core/ingestion/call-processor.js +793 -0
- package/dist/core/ingestion/call-routing.d.ts +68 -0
- package/dist/core/ingestion/call-routing.js +129 -0
- package/dist/core/ingestion/cluster-enricher.d.ts +38 -0
- package/dist/core/ingestion/cluster-enricher.js +170 -0
- package/dist/core/ingestion/community-processor.d.ts +39 -0
- package/dist/core/ingestion/community-processor.js +312 -0
- package/dist/core/ingestion/constants.d.ts +16 -0
- package/dist/core/ingestion/constants.js +16 -0
- package/dist/core/ingestion/entry-point-scoring.d.ts +40 -0
- package/dist/core/ingestion/entry-point-scoring.js +353 -0
- package/dist/core/ingestion/export-detection.d.ts +18 -0
- package/dist/core/ingestion/export-detection.js +231 -0
- package/dist/core/ingestion/filesystem-walker.d.ts +28 -0
- package/dist/core/ingestion/filesystem-walker.js +81 -0
- package/dist/core/ingestion/framework-detection.d.ts +54 -0
- package/dist/core/ingestion/framework-detection.js +411 -0
- package/dist/core/ingestion/heritage-processor.d.ts +28 -0
- package/dist/core/ingestion/heritage-processor.js +251 -0
- package/dist/core/ingestion/import-processor.d.ts +34 -0
- package/dist/core/ingestion/import-processor.js +398 -0
- package/dist/core/ingestion/language-config.d.ts +46 -0
- package/dist/core/ingestion/language-config.js +167 -0
- package/dist/core/ingestion/mro-processor.d.ts +45 -0
- package/dist/core/ingestion/mro-processor.js +369 -0
- package/dist/core/ingestion/named-binding-extraction.d.ts +61 -0
- package/dist/core/ingestion/named-binding-extraction.js +363 -0
- package/dist/core/ingestion/parsing-processor.d.ts +19 -0
- package/dist/core/ingestion/parsing-processor.js +315 -0
- package/dist/core/ingestion/pipeline.d.ts +6 -0
- package/dist/core/ingestion/pipeline.js +401 -0
- package/dist/core/ingestion/process-processor.d.ts +51 -0
- package/dist/core/ingestion/process-processor.js +315 -0
- package/dist/core/ingestion/resolution-context.d.ts +53 -0
- package/dist/core/ingestion/resolution-context.js +132 -0
- package/dist/core/ingestion/resolvers/csharp.d.ts +22 -0
- package/dist/core/ingestion/resolvers/csharp.js +109 -0
- package/dist/core/ingestion/resolvers/go.d.ts +19 -0
- package/dist/core/ingestion/resolvers/go.js +42 -0
- package/dist/core/ingestion/resolvers/index.d.ts +18 -0
- package/dist/core/ingestion/resolvers/index.js +13 -0
- package/dist/core/ingestion/resolvers/jvm.d.ts +23 -0
- package/dist/core/ingestion/resolvers/jvm.js +87 -0
- package/dist/core/ingestion/resolvers/php.d.ts +15 -0
- package/dist/core/ingestion/resolvers/php.js +35 -0
- package/dist/core/ingestion/resolvers/python.d.ts +19 -0
- package/dist/core/ingestion/resolvers/python.js +52 -0
- package/dist/core/ingestion/resolvers/ruby.d.ts +12 -0
- package/dist/core/ingestion/resolvers/ruby.js +15 -0
- package/dist/core/ingestion/resolvers/rust.d.ts +15 -0
- package/dist/core/ingestion/resolvers/rust.js +73 -0
- package/dist/core/ingestion/resolvers/standard.d.ts +28 -0
- package/dist/core/ingestion/resolvers/standard.js +123 -0
- package/dist/core/ingestion/resolvers/utils.d.ts +33 -0
- package/dist/core/ingestion/resolvers/utils.js +122 -0
- package/dist/core/ingestion/structure-processor.d.ts +2 -0
- package/dist/core/ingestion/structure-processor.js +36 -0
- package/dist/core/ingestion/symbol-table.d.ts +63 -0
- package/dist/core/ingestion/symbol-table.js +85 -0
- package/dist/core/ingestion/tree-sitter-queries.d.ts +15 -0
- package/dist/core/ingestion/tree-sitter-queries.js +888 -0
- package/dist/core/ingestion/type-env.d.ts +49 -0
- package/dist/core/ingestion/type-env.js +613 -0
- package/dist/core/ingestion/type-extractors/c-cpp.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/c-cpp.js +385 -0
- package/dist/core/ingestion/type-extractors/csharp.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/csharp.js +383 -0
- package/dist/core/ingestion/type-extractors/go.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/go.js +467 -0
- package/dist/core/ingestion/type-extractors/index.d.ts +22 -0
- package/dist/core/ingestion/type-extractors/index.js +31 -0
- package/dist/core/ingestion/type-extractors/jvm.d.ts +3 -0
- package/dist/core/ingestion/type-extractors/jvm.js +681 -0
- package/dist/core/ingestion/type-extractors/php.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/php.js +549 -0
- package/dist/core/ingestion/type-extractors/python.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/python.js +455 -0
- package/dist/core/ingestion/type-extractors/ruby.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/ruby.js +389 -0
- package/dist/core/ingestion/type-extractors/rust.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/rust.js +456 -0
- package/dist/core/ingestion/type-extractors/shared.d.ts +145 -0
- package/dist/core/ingestion/type-extractors/shared.js +810 -0
- package/dist/core/ingestion/type-extractors/swift.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/swift.js +137 -0
- package/dist/core/ingestion/type-extractors/types.d.ts +127 -0
- package/dist/core/ingestion/type-extractors/types.js +1 -0
- package/dist/core/ingestion/type-extractors/typescript.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/typescript.js +494 -0
- package/dist/core/ingestion/utils.d.ts +138 -0
- package/dist/core/ingestion/utils.js +1290 -0
- package/dist/core/ingestion/workers/parse-worker.d.ts +122 -0
- package/dist/core/ingestion/workers/parse-worker.js +1126 -0
- package/dist/core/ingestion/workers/worker-pool.d.ts +16 -0
- package/dist/core/ingestion/workers/worker-pool.js +128 -0
- package/dist/core/lbug/csv-generator.d.ts +33 -0
- package/dist/core/lbug/csv-generator.js +366 -0
- package/dist/core/lbug/lbug-adapter.d.ts +103 -0
- package/dist/core/lbug/lbug-adapter.js +769 -0
- package/dist/core/lbug/schema.d.ts +53 -0
- package/dist/core/lbug/schema.js +430 -0
- package/dist/core/search/bm25-index.d.ts +23 -0
- package/dist/core/search/bm25-index.js +96 -0
- package/dist/core/search/hybrid-search.d.ts +49 -0
- package/dist/core/search/hybrid-search.js +118 -0
- package/dist/core/tree-sitter/parser-loader.d.ts +5 -0
- package/dist/core/tree-sitter/parser-loader.js +63 -0
- package/dist/core/wiki/generator.d.ts +120 -0
- package/dist/core/wiki/generator.js +939 -0
- package/dist/core/wiki/graph-queries.d.ts +80 -0
- package/dist/core/wiki/graph-queries.js +238 -0
- package/dist/core/wiki/html-viewer.d.ts +10 -0
- package/dist/core/wiki/html-viewer.js +297 -0
- package/dist/core/wiki/llm-client.d.ts +43 -0
- package/dist/core/wiki/llm-client.js +186 -0
- package/dist/core/wiki/prompts.d.ts +53 -0
- package/dist/core/wiki/prompts.js +174 -0
- package/dist/lib/utils.d.ts +1 -0
- package/dist/lib/utils.js +3 -0
- package/dist/mcp/compatible-stdio-transport.d.ts +25 -0
- package/dist/mcp/compatible-stdio-transport.js +200 -0
- package/dist/mcp/core/embedder.d.ts +27 -0
- package/dist/mcp/core/embedder.js +108 -0
- package/dist/mcp/core/lbug-adapter.d.ts +57 -0
- package/dist/mcp/core/lbug-adapter.js +455 -0
- package/dist/mcp/local/local-backend.d.ts +181 -0
- package/dist/mcp/local/local-backend.js +1722 -0
- package/dist/mcp/resources.d.ts +31 -0
- package/dist/mcp/resources.js +411 -0
- package/dist/mcp/server.d.ts +23 -0
- package/dist/mcp/server.js +296 -0
- package/dist/mcp/staleness.d.ts +15 -0
- package/dist/mcp/staleness.js +29 -0
- package/dist/mcp/tools.d.ts +24 -0
- package/dist/mcp/tools.js +292 -0
- package/dist/server/api.d.ts +10 -0
- package/dist/server/api.js +344 -0
- package/dist/server/mcp-http.d.ts +13 -0
- package/dist/server/mcp-http.js +100 -0
- package/dist/storage/git.d.ts +6 -0
- package/dist/storage/git.js +35 -0
- package/dist/storage/repo-manager.d.ts +138 -0
- package/dist/storage/repo-manager.js +299 -0
- package/dist/types/pipeline.d.ts +32 -0
- package/dist/types/pipeline.js +18 -0
- package/dist/unreal/bridge.d.ts +4 -0
- package/dist/unreal/bridge.js +113 -0
- package/dist/unreal/config.d.ts +6 -0
- package/dist/unreal/config.js +55 -0
- package/dist/unreal/types.d.ts +105 -0
- package/dist/unreal/types.js +1 -0
- package/hooks/claude/gitnexus-hook.cjs +238 -0
- package/hooks/claude/pre-tool-use.sh +79 -0
- package/hooks/claude/session-start.sh +42 -0
- package/package.json +100 -0
- package/scripts/ensure-cli-executable.cjs +21 -0
- package/scripts/patch-tree-sitter-swift.cjs +74 -0
- package/scripts/setup-unreal-gitnexus.ps1 +191 -0
- package/skills/gitnexus-cli.md +82 -0
- package/skills/gitnexus-debugging.md +89 -0
- package/skills/gitnexus-exploring.md +78 -0
- package/skills/gitnexus-guide.md +64 -0
- package/skills/gitnexus-impact-analysis.md +97 -0
- package/skills/gitnexus-pr-review.md +163 -0
- package/skills/gitnexus-refactoring.md +121 -0
- package/vendor/leiden/index.cjs +355 -0
- package/vendor/leiden/utils.cjs +392 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Heritage Processor
|
|
3
|
+
*
|
|
4
|
+
* Extracts class inheritance relationships:
|
|
5
|
+
* - EXTENDS: Class extends another Class (TS, JS, Python, C#, C++)
|
|
6
|
+
* - IMPLEMENTS: Class implements an Interface (TS, C#, Java, Kotlin, PHP)
|
|
7
|
+
*
|
|
8
|
+
* Languages like C# use a single `base_list` for both class and interface parents.
|
|
9
|
+
* We resolve the correct edge type by checking the symbol table: if the parent is
|
|
10
|
+
* registered as an Interface, we emit IMPLEMENTS; otherwise EXTENDS. For unresolved
|
|
11
|
+
* external symbols, the fallback heuristic is language-gated:
|
|
12
|
+
* - C# / Java: apply the `I[A-Z]` naming convention (e.g. IDisposable → IMPLEMENTS)
|
|
13
|
+
* - Swift: default to IMPLEMENTS (protocol conformance is more common than class inheritance)
|
|
14
|
+
* - All other languages: default to EXTENDS
|
|
15
|
+
*/
|
|
16
|
+
import Parser from 'tree-sitter';
|
|
17
|
+
import { isLanguageAvailable, loadParser, loadLanguage } from '../tree-sitter/parser-loader.js';
|
|
18
|
+
import { LANGUAGE_QUERIES } from './tree-sitter-queries.js';
|
|
19
|
+
import { generateId } from '../../lib/utils.js';
|
|
20
|
+
import { getLanguageFromFilename, isVerboseIngestionEnabled, yieldToEventLoop } from './utils.js';
|
|
21
|
+
import { SupportedLanguages } from '../../config/supported-languages.js';
|
|
22
|
+
import { getTreeSitterBufferSize } from './constants.js';
|
|
23
|
+
/** C#/Java convention: interfaces start with I followed by an uppercase letter */
|
|
24
|
+
const INTERFACE_NAME_RE = /^I[A-Z]/;
|
|
25
|
+
/**
|
|
26
|
+
* Determine whether a heritage.extends capture is actually an IMPLEMENTS relationship.
|
|
27
|
+
* Uses the symbol table first (authoritative — Tier 1); falls back to a language-gated
|
|
28
|
+
* heuristic for external symbols not present in the graph:
|
|
29
|
+
* - C# / Java: `I[A-Z]` naming convention
|
|
30
|
+
* - Swift: default IMPLEMENTS (protocol conformance is the norm)
|
|
31
|
+
* - All others: default EXTENDS
|
|
32
|
+
*/
|
|
33
|
+
const resolveExtendsType = (parentName, currentFilePath, ctx, language) => {
|
|
34
|
+
const resolved = ctx.resolve(parentName, currentFilePath);
|
|
35
|
+
if (resolved && resolved.candidates.length > 0) {
|
|
36
|
+
const isInterface = resolved.candidates[0].type === 'Interface';
|
|
37
|
+
return isInterface
|
|
38
|
+
? { type: 'IMPLEMENTS', idPrefix: 'Interface' }
|
|
39
|
+
: { type: 'EXTENDS', idPrefix: 'Class' };
|
|
40
|
+
}
|
|
41
|
+
// Unresolved symbol — fall back to language-specific heuristic
|
|
42
|
+
if (language === SupportedLanguages.CSharp || language === SupportedLanguages.Java) {
|
|
43
|
+
if (INTERFACE_NAME_RE.test(parentName)) {
|
|
44
|
+
return { type: 'IMPLEMENTS', idPrefix: 'Interface' };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else if (language === SupportedLanguages.Swift) {
|
|
48
|
+
// Protocol conformance is far more common than class inheritance in Swift
|
|
49
|
+
return { type: 'IMPLEMENTS', idPrefix: 'Interface' };
|
|
50
|
+
}
|
|
51
|
+
return { type: 'EXTENDS', idPrefix: 'Class' };
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Resolve a symbol ID for heritage, with fallback to generated ID.
|
|
55
|
+
* Uses ctx.resolve() → pick first candidate's nodeId → generate synthetic ID.
|
|
56
|
+
*/
|
|
57
|
+
const resolveHeritageId = (name, filePath, ctx, fallbackLabel, fallbackKey) => {
|
|
58
|
+
const resolved = ctx.resolve(name, filePath);
|
|
59
|
+
if (resolved && resolved.candidates.length > 0) {
|
|
60
|
+
// For global with multiple candidates, refuse (a wrong edge is worse than no edge)
|
|
61
|
+
if (resolved.tier === 'global' && resolved.candidates.length > 1) {
|
|
62
|
+
return generateId(fallbackLabel, fallbackKey ?? name);
|
|
63
|
+
}
|
|
64
|
+
return resolved.candidates[0].nodeId;
|
|
65
|
+
}
|
|
66
|
+
return generateId(fallbackLabel, fallbackKey ?? name);
|
|
67
|
+
};
|
|
68
|
+
export const processHeritage = async (graph, files, astCache, ctx, onProgress) => {
|
|
69
|
+
const parser = await loadParser();
|
|
70
|
+
const logSkipped = isVerboseIngestionEnabled();
|
|
71
|
+
const skippedByLang = logSkipped ? new Map() : null;
|
|
72
|
+
for (let i = 0; i < files.length; i++) {
|
|
73
|
+
const file = files[i];
|
|
74
|
+
onProgress?.(i + 1, files.length);
|
|
75
|
+
if (i % 20 === 0)
|
|
76
|
+
await yieldToEventLoop();
|
|
77
|
+
// 1. Check language support
|
|
78
|
+
const language = getLanguageFromFilename(file.path);
|
|
79
|
+
if (!language)
|
|
80
|
+
continue;
|
|
81
|
+
if (!isLanguageAvailable(language)) {
|
|
82
|
+
if (skippedByLang) {
|
|
83
|
+
skippedByLang.set(language, (skippedByLang.get(language) ?? 0) + 1);
|
|
84
|
+
}
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const queryStr = LANGUAGE_QUERIES[language];
|
|
88
|
+
if (!queryStr)
|
|
89
|
+
continue;
|
|
90
|
+
// 2. Load the language
|
|
91
|
+
await loadLanguage(language, file.path);
|
|
92
|
+
// 3. Get AST
|
|
93
|
+
let tree = astCache.get(file.path);
|
|
94
|
+
if (!tree) {
|
|
95
|
+
// Use larger bufferSize for files > 32KB
|
|
96
|
+
try {
|
|
97
|
+
tree = parser.parse(file.content, undefined, { bufferSize: getTreeSitterBufferSize(file.content.length) });
|
|
98
|
+
}
|
|
99
|
+
catch (parseError) {
|
|
100
|
+
// Skip files that can't be parsed
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
// Cache re-parsed tree for potential future use
|
|
104
|
+
astCache.set(file.path, tree);
|
|
105
|
+
}
|
|
106
|
+
let query;
|
|
107
|
+
let matches;
|
|
108
|
+
try {
|
|
109
|
+
const language = parser.getLanguage();
|
|
110
|
+
query = new Parser.Query(language, queryStr);
|
|
111
|
+
matches = query.matches(tree.rootNode);
|
|
112
|
+
}
|
|
113
|
+
catch (queryError) {
|
|
114
|
+
console.warn(`Heritage query error for ${file.path}:`, queryError);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
// 4. Process heritage matches
|
|
118
|
+
matches.forEach(match => {
|
|
119
|
+
const captureMap = {};
|
|
120
|
+
match.captures.forEach(c => {
|
|
121
|
+
captureMap[c.name] = c.node;
|
|
122
|
+
});
|
|
123
|
+
// EXTENDS or IMPLEMENTS: resolve via symbol table for languages where
|
|
124
|
+
// the tree-sitter query can't distinguish classes from interfaces (C#, Java)
|
|
125
|
+
if (captureMap['heritage.class'] && captureMap['heritage.extends']) {
|
|
126
|
+
// Go struct embedding: skip named fields (only anonymous fields are embedded)
|
|
127
|
+
const extendsNode = captureMap['heritage.extends'];
|
|
128
|
+
const fieldDecl = extendsNode.parent;
|
|
129
|
+
if (fieldDecl?.type === 'field_declaration' && fieldDecl.childForFieldName('name')) {
|
|
130
|
+
return; // Named field, not struct embedding
|
|
131
|
+
}
|
|
132
|
+
const className = captureMap['heritage.class'].text;
|
|
133
|
+
const parentClassName = captureMap['heritage.extends'].text;
|
|
134
|
+
const { type: relType, idPrefix } = resolveExtendsType(parentClassName, file.path, ctx, language);
|
|
135
|
+
const childId = resolveHeritageId(className, file.path, ctx, 'Class', `${file.path}:${className}`);
|
|
136
|
+
const parentId = resolveHeritageId(parentClassName, file.path, ctx, idPrefix);
|
|
137
|
+
if (childId && parentId && childId !== parentId) {
|
|
138
|
+
graph.addRelationship({
|
|
139
|
+
id: generateId(relType, `${childId}->${parentId}`),
|
|
140
|
+
sourceId: childId,
|
|
141
|
+
targetId: parentId,
|
|
142
|
+
type: relType,
|
|
143
|
+
confidence: 1.0,
|
|
144
|
+
reason: '',
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// IMPLEMENTS: Class implements Interface (TypeScript only)
|
|
149
|
+
if (captureMap['heritage.class'] && captureMap['heritage.implements']) {
|
|
150
|
+
const className = captureMap['heritage.class'].text;
|
|
151
|
+
const interfaceName = captureMap['heritage.implements'].text;
|
|
152
|
+
const classId = resolveHeritageId(className, file.path, ctx, 'Class', `${file.path}:${className}`);
|
|
153
|
+
const interfaceId = resolveHeritageId(interfaceName, file.path, ctx, 'Interface');
|
|
154
|
+
if (classId && interfaceId) {
|
|
155
|
+
graph.addRelationship({
|
|
156
|
+
id: generateId('IMPLEMENTS', `${classId}->${interfaceId}`),
|
|
157
|
+
sourceId: classId,
|
|
158
|
+
targetId: interfaceId,
|
|
159
|
+
type: 'IMPLEMENTS',
|
|
160
|
+
confidence: 1.0,
|
|
161
|
+
reason: '',
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// IMPLEMENTS (Rust): impl Trait for Struct
|
|
166
|
+
if (captureMap['heritage.trait'] && captureMap['heritage.class']) {
|
|
167
|
+
const structName = captureMap['heritage.class'].text;
|
|
168
|
+
const traitName = captureMap['heritage.trait'].text;
|
|
169
|
+
const structId = resolveHeritageId(structName, file.path, ctx, 'Struct', `${file.path}:${structName}`);
|
|
170
|
+
const traitId = resolveHeritageId(traitName, file.path, ctx, 'Trait');
|
|
171
|
+
if (structId && traitId) {
|
|
172
|
+
graph.addRelationship({
|
|
173
|
+
id: generateId('IMPLEMENTS', `${structId}->${traitId}`),
|
|
174
|
+
sourceId: structId,
|
|
175
|
+
targetId: traitId,
|
|
176
|
+
type: 'IMPLEMENTS',
|
|
177
|
+
confidence: 1.0,
|
|
178
|
+
reason: 'trait-impl',
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
// Tree is now owned by the LRU cache — no manual delete needed
|
|
184
|
+
}
|
|
185
|
+
if (skippedByLang && skippedByLang.size > 0) {
|
|
186
|
+
for (const [lang, count] of skippedByLang.entries()) {
|
|
187
|
+
console.warn(`[ingestion] Skipped ${count} ${lang} file(s) in heritage processing — ${lang} parser not available.`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Fast path: resolve pre-extracted heritage from workers.
|
|
193
|
+
* No AST parsing — workers already extracted className + parentName + kind.
|
|
194
|
+
*/
|
|
195
|
+
export const processHeritageFromExtracted = async (graph, extractedHeritage, ctx, onProgress) => {
|
|
196
|
+
const total = extractedHeritage.length;
|
|
197
|
+
for (let i = 0; i < extractedHeritage.length; i++) {
|
|
198
|
+
if (i % 500 === 0) {
|
|
199
|
+
onProgress?.(i, total);
|
|
200
|
+
await yieldToEventLoop();
|
|
201
|
+
}
|
|
202
|
+
const h = extractedHeritage[i];
|
|
203
|
+
if (h.kind === 'extends') {
|
|
204
|
+
const fileLanguage = getLanguageFromFilename(h.filePath);
|
|
205
|
+
if (!fileLanguage)
|
|
206
|
+
continue;
|
|
207
|
+
const { type: relType, idPrefix } = resolveExtendsType(h.parentName, h.filePath, ctx, fileLanguage);
|
|
208
|
+
const childId = resolveHeritageId(h.className, h.filePath, ctx, 'Class', `${h.filePath}:${h.className}`);
|
|
209
|
+
const parentId = resolveHeritageId(h.parentName, h.filePath, ctx, idPrefix);
|
|
210
|
+
if (childId && parentId && childId !== parentId) {
|
|
211
|
+
graph.addRelationship({
|
|
212
|
+
id: generateId(relType, `${childId}->${parentId}`),
|
|
213
|
+
sourceId: childId,
|
|
214
|
+
targetId: parentId,
|
|
215
|
+
type: relType,
|
|
216
|
+
confidence: 1.0,
|
|
217
|
+
reason: '',
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
else if (h.kind === 'implements') {
|
|
222
|
+
const classId = resolveHeritageId(h.className, h.filePath, ctx, 'Class', `${h.filePath}:${h.className}`);
|
|
223
|
+
const interfaceId = resolveHeritageId(h.parentName, h.filePath, ctx, 'Interface');
|
|
224
|
+
if (classId && interfaceId) {
|
|
225
|
+
graph.addRelationship({
|
|
226
|
+
id: generateId('IMPLEMENTS', `${classId}->${interfaceId}`),
|
|
227
|
+
sourceId: classId,
|
|
228
|
+
targetId: interfaceId,
|
|
229
|
+
type: 'IMPLEMENTS',
|
|
230
|
+
confidence: 1.0,
|
|
231
|
+
reason: '',
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
else if (h.kind === 'trait-impl' || h.kind === 'include' || h.kind === 'extend' || h.kind === 'prepend') {
|
|
236
|
+
const structId = resolveHeritageId(h.className, h.filePath, ctx, 'Struct', `${h.filePath}:${h.className}`);
|
|
237
|
+
const traitId = resolveHeritageId(h.parentName, h.filePath, ctx, 'Trait');
|
|
238
|
+
if (structId && traitId) {
|
|
239
|
+
graph.addRelationship({
|
|
240
|
+
id: generateId('IMPLEMENTS', `${structId}->${traitId}:${h.kind}`),
|
|
241
|
+
sourceId: structId,
|
|
242
|
+
targetId: traitId,
|
|
243
|
+
type: 'IMPLEMENTS',
|
|
244
|
+
confidence: 1.0,
|
|
245
|
+
reason: h.kind,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
onProgress?.(total, total);
|
|
251
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { KnowledgeGraph } from '../graph/types.js';
|
|
2
|
+
import { ASTCache } from './ast-cache.js';
|
|
3
|
+
import type { ExtractedImport } from './workers/parse-worker.js';
|
|
4
|
+
import type { ResolutionContext } from './resolution-context.js';
|
|
5
|
+
import type { SuffixIndex } from './resolvers/index.js';
|
|
6
|
+
export type { SuffixIndex, TsconfigPaths, GoModuleConfig, CSharpProjectConfig, ComposerConfig } from './resolvers/index.js';
|
|
7
|
+
export type ImportMap = Map<string, Set<string>>;
|
|
8
|
+
export type PackageMap = Map<string, Set<string>>;
|
|
9
|
+
export interface NamedImportBinding {
|
|
10
|
+
sourcePath: string;
|
|
11
|
+
exportedName: string;
|
|
12
|
+
}
|
|
13
|
+
export type NamedImportMap = Map<string, Map<string, NamedImportBinding>>;
|
|
14
|
+
/**
|
|
15
|
+
* Check if a file path is directly inside a package directory identified by its suffix.
|
|
16
|
+
* Used by the symbol resolver for Go and C# directory-level import matching.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isFileInPackageDir(filePath: string, dirSuffix: string): boolean;
|
|
19
|
+
/** Pre-built lookup structures for import resolution. Build once, reuse across chunks. */
|
|
20
|
+
export interface ImportResolutionContext {
|
|
21
|
+
allFilePaths: Set<string>;
|
|
22
|
+
allFileList: string[];
|
|
23
|
+
normalizedFileList: string[];
|
|
24
|
+
suffixIndex: SuffixIndex;
|
|
25
|
+
resolveCache: Map<string, string | null>;
|
|
26
|
+
}
|
|
27
|
+
export declare function buildImportResolutionContext(allPaths: string[]): ImportResolutionContext;
|
|
28
|
+
export declare const processImports: (graph: KnowledgeGraph, files: {
|
|
29
|
+
path: string;
|
|
30
|
+
content: string;
|
|
31
|
+
}[], astCache: ASTCache, ctx: ResolutionContext, onProgress?: (current: number, total: number) => void, repoRoot?: string, allPaths?: string[]) => Promise<void>;
|
|
32
|
+
export declare const processImportsFromExtracted: (graph: KnowledgeGraph, files: {
|
|
33
|
+
path: string;
|
|
34
|
+
}[], extractedImports: ExtractedImport[], ctx: ResolutionContext, onProgress?: (current: number, total: number) => void, repoRoot?: string, prebuiltCtx?: ImportResolutionContext) => Promise<void>;
|