@mars167/git-ai 2.3.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 +22 -0
- package/README.md +364 -0
- package/README.zh-CN.md +361 -0
- package/assets/hooks/post-checkout +28 -0
- package/assets/hooks/post-merge +28 -0
- package/assets/hooks/pre-commit +17 -0
- package/assets/hooks/pre-push +29 -0
- package/dist/bin/git-ai.js +62 -0
- package/dist/src/commands/ai.js +30 -0
- package/dist/src/commands/checkIndex.js +19 -0
- package/dist/src/commands/dsr.js +156 -0
- package/dist/src/commands/graph.js +203 -0
- package/dist/src/commands/hooks.js +125 -0
- package/dist/src/commands/index.js +92 -0
- package/dist/src/commands/pack.js +31 -0
- package/dist/src/commands/query.js +139 -0
- package/dist/src/commands/semantic.js +134 -0
- package/dist/src/commands/serve.js +14 -0
- package/dist/src/commands/status.js +78 -0
- package/dist/src/commands/trae.js +75 -0
- package/dist/src/commands/unpack.js +28 -0
- package/dist/src/core/archive.js +91 -0
- package/dist/src/core/astGraph.js +127 -0
- package/dist/src/core/astGraphQuery.js +142 -0
- package/dist/src/core/cozo.js +266 -0
- package/dist/src/core/cpg/astLayer.js +56 -0
- package/dist/src/core/cpg/callGraph.js +483 -0
- package/dist/src/core/cpg/cfgLayer.js +490 -0
- package/dist/src/core/cpg/dfgLayer.js +237 -0
- package/dist/src/core/cpg/index.js +80 -0
- package/dist/src/core/cpg/types.js +108 -0
- package/dist/src/core/crypto.js +10 -0
- package/dist/src/core/dsr/generate.js +308 -0
- package/dist/src/core/dsr/gitContext.js +74 -0
- package/dist/src/core/dsr/indexMaterialize.js +106 -0
- package/dist/src/core/dsr/paths.js +26 -0
- package/dist/src/core/dsr/query.js +73 -0
- package/dist/src/core/dsr/snapshotParser.js +73 -0
- package/dist/src/core/dsr/state.js +27 -0
- package/dist/src/core/dsr/types.js +2 -0
- package/dist/src/core/embedding/fusion.js +52 -0
- package/dist/src/core/embedding/index.js +43 -0
- package/dist/src/core/embedding/parser.js +14 -0
- package/dist/src/core/embedding/semantic.js +254 -0
- package/dist/src/core/embedding/structural.js +97 -0
- package/dist/src/core/embedding/symbolic.js +117 -0
- package/dist/src/core/embedding/tokenizer.js +91 -0
- package/dist/src/core/embedding/types.js +2 -0
- package/dist/src/core/embedding.js +36 -0
- package/dist/src/core/git.js +49 -0
- package/dist/src/core/gitDiff.js +73 -0
- package/dist/src/core/indexCheck.js +131 -0
- package/dist/src/core/indexer.js +185 -0
- package/dist/src/core/indexerIncremental.js +303 -0
- package/dist/src/core/indexing/config.js +51 -0
- package/dist/src/core/indexing/hnsw.js +568 -0
- package/dist/src/core/indexing/index.js +17 -0
- package/dist/src/core/indexing/monitor.js +82 -0
- package/dist/src/core/indexing/parallel.js +252 -0
- package/dist/src/core/lancedb.js +111 -0
- package/dist/src/core/lfs.js +27 -0
- package/dist/src/core/log.js +62 -0
- package/dist/src/core/manifest.js +88 -0
- package/dist/src/core/parser/adapter.js +2 -0
- package/dist/src/core/parser/c.js +93 -0
- package/dist/src/core/parser/chunkRelations.js +178 -0
- package/dist/src/core/parser/chunker.js +274 -0
- package/dist/src/core/parser/go.js +98 -0
- package/dist/src/core/parser/java.js +80 -0
- package/dist/src/core/parser/markdown.js +76 -0
- package/dist/src/core/parser/python.js +81 -0
- package/dist/src/core/parser/rust.js +103 -0
- package/dist/src/core/parser/typescript.js +98 -0
- package/dist/src/core/parser/utils.js +62 -0
- package/dist/src/core/parser/yaml.js +53 -0
- package/dist/src/core/parser.js +75 -0
- package/dist/src/core/paths.js +10 -0
- package/dist/src/core/repoMap.js +164 -0
- package/dist/src/core/retrieval/cache.js +31 -0
- package/dist/src/core/retrieval/classifier.js +74 -0
- package/dist/src/core/retrieval/expander.js +80 -0
- package/dist/src/core/retrieval/fuser.js +40 -0
- package/dist/src/core/retrieval/index.js +32 -0
- package/dist/src/core/retrieval/reranker.js +304 -0
- package/dist/src/core/retrieval/types.js +2 -0
- package/dist/src/core/retrieval/weights.js +42 -0
- package/dist/src/core/search.js +41 -0
- package/dist/src/core/sq8.js +65 -0
- package/dist/src/core/symbolSearch.js +143 -0
- package/dist/src/core/types.js +2 -0
- package/dist/src/core/workspace.js +116 -0
- package/dist/src/mcp/server.js +794 -0
- package/docs/README.md +44 -0
- package/docs/cross-encoder.md +157 -0
- package/docs/embedding.md +158 -0
- package/docs/logo.png +0 -0
- package/docs/windows-setup.md +67 -0
- package/docs/zh-CN/DESIGN.md +102 -0
- package/docs/zh-CN/README.md +46 -0
- package/docs/zh-CN/advanced.md +26 -0
- package/docs/zh-CN/architecture_explained.md +116 -0
- package/docs/zh-CN/cli.md +109 -0
- package/docs/zh-CN/dsr.md +91 -0
- package/docs/zh-CN/graph_scenarios.md +173 -0
- package/docs/zh-CN/hooks.md +14 -0
- package/docs/zh-CN/manifests.md +136 -0
- package/docs/zh-CN/mcp.md +205 -0
- package/docs/zh-CN/quickstart.md +35 -0
- package/docs/zh-CN/rules.md +7 -0
- package/docs/zh-CN/technical-details.md +454 -0
- package/docs/zh-CN/troubleshooting.md +19 -0
- package/docs/zh-CN/windows-setup.md +67 -0
- package/install.sh +183 -0
- package/package.json +97 -0
- package/skills/git-ai-mcp/SKILL.md +86 -0
- package/skills/git-ai-mcp/references/constraints.md +143 -0
- package/skills/git-ai-mcp/references/tools.md +263 -0
- package/templates/agents/common/documents/Fix EISDIR error and enable multi-language indexing.md +14 -0
- package/templates/agents/common/documents/Fix git-ai index error in CodaGraph directory.md +13 -0
- package/templates/agents/common/skills/git-ai-mcp/SKILL.md +86 -0
- package/templates/agents/common/skills/git-ai-mcp/references/constraints.md +143 -0
- package/templates/agents/common/skills/git-ai-mcp/references/tools.md +263 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.buildDfgLayer = buildDfgLayer;
|
|
7
|
+
exports.buildDFG = buildDFG;
|
|
8
|
+
const tree_sitter_1 = __importDefault(require("tree-sitter"));
|
|
9
|
+
const tree_sitter_typescript_1 = __importDefault(require("tree-sitter-typescript"));
|
|
10
|
+
const types_1 = require("./types");
|
|
11
|
+
const IDENTIFIER_TYPES = new Set(['identifier', 'property_identifier']);
|
|
12
|
+
const ASSIGNMENT_TYPES = new Set([
|
|
13
|
+
'assignment_expression',
|
|
14
|
+
'augmented_assignment_expression',
|
|
15
|
+
'variable_declarator',
|
|
16
|
+
]);
|
|
17
|
+
const ASSIGNMENT_OPERATORS = new Set([
|
|
18
|
+
'=',
|
|
19
|
+
'+=',
|
|
20
|
+
'-=',
|
|
21
|
+
'*=',
|
|
22
|
+
'/=',
|
|
23
|
+
'%=',
|
|
24
|
+
'||=',
|
|
25
|
+
'&&=',
|
|
26
|
+
'??=',
|
|
27
|
+
'|=',
|
|
28
|
+
'&=',
|
|
29
|
+
'^=',
|
|
30
|
+
'<<=',
|
|
31
|
+
'>>=',
|
|
32
|
+
'>>>=',
|
|
33
|
+
]);
|
|
34
|
+
function isIdentifier(node) {
|
|
35
|
+
return IDENTIFIER_TYPES.has(node.type) || node.type === 'shorthand_property_identifier';
|
|
36
|
+
}
|
|
37
|
+
function collectIdentifiers(node, out) {
|
|
38
|
+
if (isIdentifier(node))
|
|
39
|
+
out.push(node);
|
|
40
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
41
|
+
const child = node.child(i);
|
|
42
|
+
if (child)
|
|
43
|
+
collectIdentifiers(child, out);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function collectPatternIdentifiers(node, out) {
|
|
47
|
+
if (isIdentifier(node)) {
|
|
48
|
+
out.push(node);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (node.type === 'shorthand_property_identifier') {
|
|
52
|
+
out.push(node);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
56
|
+
const child = node.child(i);
|
|
57
|
+
if (!child)
|
|
58
|
+
continue;
|
|
59
|
+
collectPatternIdentifiers(child, out);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function collectAssignments(root) {
|
|
63
|
+
const nodes = [];
|
|
64
|
+
const visit = (node) => {
|
|
65
|
+
if (ASSIGNMENT_TYPES.has(node.type))
|
|
66
|
+
nodes.push(node);
|
|
67
|
+
if (node.type === 'formal_parameters')
|
|
68
|
+
nodes.push(node);
|
|
69
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
70
|
+
const child = node.child(i);
|
|
71
|
+
if (child)
|
|
72
|
+
visit(child);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
visit(root);
|
|
76
|
+
return nodes;
|
|
77
|
+
}
|
|
78
|
+
function getAssignmentOperator(node) {
|
|
79
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
80
|
+
const child = node.child(i);
|
|
81
|
+
if (!child)
|
|
82
|
+
continue;
|
|
83
|
+
if (ASSIGNMENT_OPERATORS.has(child.type))
|
|
84
|
+
return child.type;
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
function isCompoundAssignment(node) {
|
|
89
|
+
if (node.type === 'augmented_assignment_expression')
|
|
90
|
+
return true;
|
|
91
|
+
if (node.type !== 'assignment_expression')
|
|
92
|
+
return false;
|
|
93
|
+
const op = getAssignmentOperator(node);
|
|
94
|
+
return op !== null && op !== '=';
|
|
95
|
+
}
|
|
96
|
+
function extractDefinitions(node, filePath) {
|
|
97
|
+
const defs = [];
|
|
98
|
+
if (node.type === 'formal_parameters') {
|
|
99
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
100
|
+
const param = node.namedChild(i);
|
|
101
|
+
if (!param)
|
|
102
|
+
continue;
|
|
103
|
+
const ids = [];
|
|
104
|
+
const paramNode = param.childForFieldName('name') ?? param;
|
|
105
|
+
collectPatternIdentifiers(paramNode, ids);
|
|
106
|
+
for (const id of ids) {
|
|
107
|
+
defs.push({ id: (0, types_1.astNodeId)(filePath, id), name: id.text, node: id });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return defs;
|
|
111
|
+
}
|
|
112
|
+
const left = node.childForFieldName('left') ?? node.childForFieldName('name');
|
|
113
|
+
if (!left)
|
|
114
|
+
return defs;
|
|
115
|
+
const ids = [];
|
|
116
|
+
collectPatternIdentifiers(left, ids);
|
|
117
|
+
for (const id of ids) {
|
|
118
|
+
defs.push({ id: (0, types_1.astNodeId)(filePath, id), name: id.text, node: id });
|
|
119
|
+
}
|
|
120
|
+
return defs;
|
|
121
|
+
}
|
|
122
|
+
function extractUses(node, filePath) {
|
|
123
|
+
const uses = [];
|
|
124
|
+
if (node.type === 'formal_parameters')
|
|
125
|
+
return uses;
|
|
126
|
+
const assignmentLeft = node.childForFieldName('left') ?? node.childForFieldName('name');
|
|
127
|
+
const right = node.childForFieldName('right') ?? node.childForFieldName('value');
|
|
128
|
+
if (!right) {
|
|
129
|
+
if (isCompoundAssignment(node) && assignmentLeft) {
|
|
130
|
+
const leftIds = [];
|
|
131
|
+
collectIdentifiers(assignmentLeft, leftIds);
|
|
132
|
+
for (const id of leftIds) {
|
|
133
|
+
uses.push({ id: (0, types_1.astNodeId)(filePath, id), name: id.text, node: id });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return uses;
|
|
137
|
+
}
|
|
138
|
+
const ids = [];
|
|
139
|
+
collectIdentifiers(right, ids);
|
|
140
|
+
for (const id of ids) {
|
|
141
|
+
if (assignmentLeft && id.startIndex >= assignmentLeft.startIndex && id.endIndex <= assignmentLeft.endIndex) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
uses.push({ id: (0, types_1.astNodeId)(filePath, id), name: id.text, node: id });
|
|
145
|
+
}
|
|
146
|
+
if (isCompoundAssignment(node) && assignmentLeft) {
|
|
147
|
+
const leftIds = [];
|
|
148
|
+
collectIdentifiers(assignmentLeft, leftIds);
|
|
149
|
+
for (const id of leftIds) {
|
|
150
|
+
uses.push({ id: (0, types_1.astNodeId)(filePath, id), name: id.text, node: id });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return uses;
|
|
154
|
+
}
|
|
155
|
+
function addDefinedByEdges(edges, filePath, defs, assignmentNode) {
|
|
156
|
+
const assignmentId = (0, types_1.astNodeId)(filePath, assignmentNode);
|
|
157
|
+
for (const def of defs) {
|
|
158
|
+
edges.push({ from: def.id, to: assignmentId, type: types_1.EdgeType.DEFINED_BY });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function buildDfgInternal(filePath, root) {
|
|
162
|
+
const edges = [];
|
|
163
|
+
const nodes = [];
|
|
164
|
+
const seenNodes = new Set();
|
|
165
|
+
const assignments = collectAssignments(root);
|
|
166
|
+
for (const assignment of assignments) {
|
|
167
|
+
const defs = extractDefinitions(assignment, filePath);
|
|
168
|
+
const uses = extractUses(assignment, filePath);
|
|
169
|
+
for (const def of defs) {
|
|
170
|
+
if (!seenNodes.has(def.id)) {
|
|
171
|
+
nodes.push({
|
|
172
|
+
id: def.id,
|
|
173
|
+
kind: 'dfg',
|
|
174
|
+
label: def.name,
|
|
175
|
+
startLine: def.node.startPosition.row + 1,
|
|
176
|
+
endLine: def.node.endPosition.row + 1,
|
|
177
|
+
});
|
|
178
|
+
seenNodes.add(def.id);
|
|
179
|
+
}
|
|
180
|
+
for (const use of uses) {
|
|
181
|
+
if (!seenNodes.has(use.id)) {
|
|
182
|
+
nodes.push({
|
|
183
|
+
id: use.id,
|
|
184
|
+
kind: 'dfg',
|
|
185
|
+
label: use.name,
|
|
186
|
+
startLine: use.node.startPosition.row + 1,
|
|
187
|
+
endLine: use.node.endPosition.row + 1,
|
|
188
|
+
});
|
|
189
|
+
seenNodes.add(use.id);
|
|
190
|
+
}
|
|
191
|
+
edges.push({ from: use.id, to: def.id, type: types_1.EdgeType.COMPUTED_FROM });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (defs.length > 0) {
|
|
195
|
+
addDefinedByEdges(edges, filePath, defs, assignment);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return { nodes, edges };
|
|
199
|
+
}
|
|
200
|
+
function buildDfgLayer(filePath, root) {
|
|
201
|
+
const edgeTypes = [types_1.EdgeType.COMPUTED_FROM, types_1.EdgeType.DEFINED_BY];
|
|
202
|
+
const internal = buildDfgInternal(filePath, root);
|
|
203
|
+
return { nodes: internal.nodes, edges: internal.edges, edgeTypes };
|
|
204
|
+
}
|
|
205
|
+
function buildDFG(filePath, content) {
|
|
206
|
+
const parser = new tree_sitter_1.default();
|
|
207
|
+
parser.setLanguage(tree_sitter_typescript_1.default.typescript);
|
|
208
|
+
const tree = parser.parse(content);
|
|
209
|
+
const root = tree.rootNode;
|
|
210
|
+
const nodeMap = new Map();
|
|
211
|
+
const edges = [];
|
|
212
|
+
const assignments = collectAssignments(root);
|
|
213
|
+
for (const assignment of assignments) {
|
|
214
|
+
const defs = extractDefinitions(assignment, filePath);
|
|
215
|
+
const uses = extractUses(assignment, filePath);
|
|
216
|
+
for (const def of defs) {
|
|
217
|
+
let defNode = nodeMap.get(def.id);
|
|
218
|
+
if (!defNode) {
|
|
219
|
+
defNode = {
|
|
220
|
+
id: def.id,
|
|
221
|
+
varName: def.name,
|
|
222
|
+
defLine: def.node.startPosition.row + 1,
|
|
223
|
+
useLines: [],
|
|
224
|
+
};
|
|
225
|
+
nodeMap.set(def.id, defNode);
|
|
226
|
+
}
|
|
227
|
+
for (const use of uses) {
|
|
228
|
+
edges.push({ from: def.id, to: use.id, varName: def.name });
|
|
229
|
+
const useLine = use.node.startPosition.row + 1;
|
|
230
|
+
if (!defNode.useLines.includes(useLine)) {
|
|
231
|
+
defNode.useLines.push(useLine);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return { nodes: Array.from(nodeMap.values()), edges };
|
|
237
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildCpgForFile = buildCpgForFile;
|
|
4
|
+
exports.buildCpgForFiles = buildCpgForFiles;
|
|
5
|
+
const parser_1 = require("../parser");
|
|
6
|
+
const paths_1 = require("../paths");
|
|
7
|
+
const astLayer_1 = require("./astLayer");
|
|
8
|
+
const cfgLayer_1 = require("./cfgLayer");
|
|
9
|
+
const dfgLayer_1 = require("./dfgLayer");
|
|
10
|
+
const callGraph_1 = require("./callGraph");
|
|
11
|
+
function mergeLayers(layers) {
|
|
12
|
+
const nodesMap = new Map();
|
|
13
|
+
const edges = [];
|
|
14
|
+
const edgeTypes = new Set();
|
|
15
|
+
for (const layer of layers) {
|
|
16
|
+
for (const node of layer.nodes)
|
|
17
|
+
nodesMap.set(node.id, node);
|
|
18
|
+
for (const edge of layer.edges)
|
|
19
|
+
edges.push(edge);
|
|
20
|
+
for (const type of layer.edgeTypes)
|
|
21
|
+
edgeTypes.add(type);
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
nodes: Array.from(nodesMap.values()),
|
|
25
|
+
edges,
|
|
26
|
+
edgeTypes: Array.from(edgeTypes),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function buildCpgForFile(filePath, lang, root) {
|
|
30
|
+
const ast = (0, astLayer_1.buildAstLayer)(filePath, lang, root);
|
|
31
|
+
const cfg = (0, cfgLayer_1.buildCfgLayer)(filePath, root);
|
|
32
|
+
const dfg = (0, dfgLayer_1.buildDfgLayer)(filePath, root);
|
|
33
|
+
return {
|
|
34
|
+
ast,
|
|
35
|
+
cfg,
|
|
36
|
+
dfg,
|
|
37
|
+
callGraph: { nodes: [], edges: [], edgeTypes: [] },
|
|
38
|
+
importGraph: { nodes: [], edges: [], edgeTypes: [] },
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function buildCpgForFiles(files) {
|
|
42
|
+
const parser = new parser_1.CodeParser();
|
|
43
|
+
const contexts = [];
|
|
44
|
+
const astLayers = [];
|
|
45
|
+
const cfgLayers = [];
|
|
46
|
+
const dfgLayers = [];
|
|
47
|
+
for (const file of files) {
|
|
48
|
+
const filePath = (0, paths_1.toPosixPath)(file.filePath);
|
|
49
|
+
let tree = null;
|
|
50
|
+
try {
|
|
51
|
+
const adapter = parser.pickAdapter?.(filePath);
|
|
52
|
+
if (adapter) {
|
|
53
|
+
parser.parser.setLanguage(adapter.getTreeSitterLanguage());
|
|
54
|
+
tree = parser.parser.parse(file.content);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
tree = null;
|
|
59
|
+
}
|
|
60
|
+
if (!tree)
|
|
61
|
+
continue;
|
|
62
|
+
const root = tree.rootNode;
|
|
63
|
+
const ast = (0, astLayer_1.buildAstLayer)(filePath, file.lang, root);
|
|
64
|
+
const cfg = (0, cfgLayer_1.buildCfgLayer)(filePath, root);
|
|
65
|
+
const dfg = (0, dfgLayer_1.buildDfgLayer)(filePath, root);
|
|
66
|
+
astLayers.push(ast);
|
|
67
|
+
cfgLayers.push(cfg);
|
|
68
|
+
dfgLayers.push(dfg);
|
|
69
|
+
contexts.push({ filePath, lang: file.lang, root });
|
|
70
|
+
}
|
|
71
|
+
const callGraph = (0, callGraph_1.buildCallGraph)(contexts);
|
|
72
|
+
const importGraph = (0, callGraph_1.buildImportGraph)(contexts);
|
|
73
|
+
return {
|
|
74
|
+
ast: mergeLayers(astLayers),
|
|
75
|
+
cfg: mergeLayers(cfgLayers),
|
|
76
|
+
dfg: mergeLayers(dfgLayers),
|
|
77
|
+
callGraph,
|
|
78
|
+
importGraph,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EdgeType = void 0;
|
|
4
|
+
exports.fileNodeId = fileNodeId;
|
|
5
|
+
exports.moduleNodeId = moduleNodeId;
|
|
6
|
+
exports.astNodeId = astNodeId;
|
|
7
|
+
exports.buildSymbolChunkText = buildSymbolChunkText;
|
|
8
|
+
exports.symbolNodeId = symbolNodeId;
|
|
9
|
+
exports.createFileNode = createFileNode;
|
|
10
|
+
exports.createModuleNode = createModuleNode;
|
|
11
|
+
exports.createAstNode = createAstNode;
|
|
12
|
+
exports.createSymbolNode = createSymbolNode;
|
|
13
|
+
const crypto_1 = require("../crypto");
|
|
14
|
+
const paths_1 = require("../paths");
|
|
15
|
+
var EdgeType;
|
|
16
|
+
(function (EdgeType) {
|
|
17
|
+
EdgeType["CHILD"] = "CHILD";
|
|
18
|
+
EdgeType["NEXT_TOKEN"] = "NEXT_TOKEN";
|
|
19
|
+
EdgeType["NEXT_STATEMENT"] = "NEXT_STATEMENT";
|
|
20
|
+
EdgeType["TRUE_BRANCH"] = "TRUE_BRANCH";
|
|
21
|
+
EdgeType["FALSE_BRANCH"] = "FALSE_BRANCH";
|
|
22
|
+
EdgeType["FALLTHROUGH"] = "FALLTHROUGH";
|
|
23
|
+
EdgeType["COMPUTED_FROM"] = "COMPUTED_FROM";
|
|
24
|
+
EdgeType["DEFINED_BY"] = "DEFINED_BY";
|
|
25
|
+
EdgeType["CALLS"] = "CALLS";
|
|
26
|
+
EdgeType["DEFINES"] = "DEFINES";
|
|
27
|
+
EdgeType["IMPORTS"] = "IMPORTS";
|
|
28
|
+
EdgeType["INHERITS"] = "INHERITS";
|
|
29
|
+
EdgeType["IMPLEMENTS"] = "IMPLEMENTS";
|
|
30
|
+
})(EdgeType || (exports.EdgeType = EdgeType = {}));
|
|
31
|
+
function fileNodeId(filePath) {
|
|
32
|
+
const filePosix = (0, paths_1.toPosixPath)(filePath);
|
|
33
|
+
return (0, crypto_1.sha256Hex)(`file:${filePosix}`);
|
|
34
|
+
}
|
|
35
|
+
function moduleNodeId(name) {
|
|
36
|
+
return (0, crypto_1.sha256Hex)(`module:${name}`);
|
|
37
|
+
}
|
|
38
|
+
function astNodeId(filePath, node) {
|
|
39
|
+
const filePosix = (0, paths_1.toPosixPath)(filePath);
|
|
40
|
+
const start = `${node.startPosition.row + 1}:${node.startPosition.column + 1}`;
|
|
41
|
+
const end = `${node.endPosition.row + 1}:${node.endPosition.column + 1}`;
|
|
42
|
+
return (0, crypto_1.sha256Hex)(`cpg:${filePosix}:${node.type}:${start}:${end}`);
|
|
43
|
+
}
|
|
44
|
+
function buildSymbolChunkText(filePath, symbol) {
|
|
45
|
+
const filePosix = (0, paths_1.toPosixPath)(filePath);
|
|
46
|
+
return `file:${filePosix}\nkind:${symbol.kind}\nname:${symbol.name}\nsignature:${symbol.signature}`;
|
|
47
|
+
}
|
|
48
|
+
function symbolNodeId(filePath, symbol) {
|
|
49
|
+
const filePosix = (0, paths_1.toPosixPath)(filePath);
|
|
50
|
+
const chunk = buildSymbolChunkText(filePosix, symbol);
|
|
51
|
+
const contentHash = (0, crypto_1.sha256Hex)(chunk);
|
|
52
|
+
return (0, crypto_1.sha256Hex)(`${filePosix}:${symbol.name}:${symbol.kind}:${symbol.startLine}:${symbol.endLine}:${contentHash}`);
|
|
53
|
+
}
|
|
54
|
+
function createFileNode(filePath, lang) {
|
|
55
|
+
const filePosix = (0, paths_1.toPosixPath)(filePath);
|
|
56
|
+
return {
|
|
57
|
+
id: fileNodeId(filePosix),
|
|
58
|
+
kind: 'file',
|
|
59
|
+
label: filePosix,
|
|
60
|
+
file: filePosix,
|
|
61
|
+
lang,
|
|
62
|
+
startLine: 0,
|
|
63
|
+
endLine: 0,
|
|
64
|
+
startCol: 0,
|
|
65
|
+
endCol: 0,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function createModuleNode(name) {
|
|
69
|
+
return {
|
|
70
|
+
id: moduleNodeId(name),
|
|
71
|
+
kind: 'module',
|
|
72
|
+
label: name,
|
|
73
|
+
file: '',
|
|
74
|
+
lang: '',
|
|
75
|
+
startLine: 0,
|
|
76
|
+
endLine: 0,
|
|
77
|
+
startCol: 0,
|
|
78
|
+
endCol: 0,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function createAstNode(filePath, lang, node) {
|
|
82
|
+
const filePosix = (0, paths_1.toPosixPath)(filePath);
|
|
83
|
+
return {
|
|
84
|
+
id: astNodeId(filePosix, node),
|
|
85
|
+
kind: 'ast',
|
|
86
|
+
label: node.type,
|
|
87
|
+
file: filePosix,
|
|
88
|
+
lang,
|
|
89
|
+
startLine: node.startPosition.row + 1,
|
|
90
|
+
endLine: node.endPosition.row + 1,
|
|
91
|
+
startCol: node.startPosition.column + 1,
|
|
92
|
+
endCol: node.endPosition.column + 1,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function createSymbolNode(filePath, lang, symbol) {
|
|
96
|
+
const filePosix = (0, paths_1.toPosixPath)(filePath);
|
|
97
|
+
return {
|
|
98
|
+
id: symbolNodeId(filePosix, symbol),
|
|
99
|
+
kind: 'symbol',
|
|
100
|
+
label: symbol.name,
|
|
101
|
+
file: filePosix,
|
|
102
|
+
lang,
|
|
103
|
+
startLine: symbol.startLine,
|
|
104
|
+
endLine: symbol.endLine,
|
|
105
|
+
startCol: 0,
|
|
106
|
+
endCol: 0,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.sha256Hex = sha256Hex;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
function sha256Hex(input) {
|
|
9
|
+
return crypto_1.default.createHash('sha256').update(input).digest('hex');
|
|
10
|
+
}
|