@optave/codegraph 3.1.5 → 3.2.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 +3 -2
- package/package.json +7 -7
- package/src/ast-analysis/engine.js +252 -258
- package/src/ast-analysis/shared.js +0 -12
- package/src/ast-analysis/visitors/cfg-visitor.js +635 -649
- package/src/ast-analysis/visitors/complexity-visitor.js +135 -139
- package/src/ast-analysis/visitors/dataflow-visitor.js +230 -224
- package/src/cli/commands/ast.js +2 -1
- package/src/cli/commands/audit.js +2 -1
- package/src/cli/commands/batch.js +2 -1
- package/src/cli/commands/brief.js +12 -0
- package/src/cli/commands/cfg.js +2 -1
- package/src/cli/commands/check.js +20 -23
- package/src/cli/commands/children.js +6 -1
- package/src/cli/commands/complexity.js +2 -1
- package/src/cli/commands/context.js +6 -1
- package/src/cli/commands/dataflow.js +2 -1
- package/src/cli/commands/deps.js +8 -3
- package/src/cli/commands/flow.js +2 -1
- package/src/cli/commands/fn-impact.js +6 -1
- package/src/cli/commands/owners.js +4 -2
- package/src/cli/commands/query.js +6 -1
- package/src/cli/commands/roles.js +2 -1
- package/src/cli/commands/search.js +8 -2
- package/src/cli/commands/sequence.js +2 -1
- package/src/cli/commands/triage.js +38 -27
- package/src/db/connection.js +18 -12
- package/src/db/migrations.js +41 -64
- package/src/db/query-builder.js +60 -4
- package/src/db/repository/in-memory-repository.js +27 -16
- package/src/db/repository/nodes.js +8 -10
- package/src/domain/analysis/brief.js +155 -0
- package/src/domain/analysis/context.js +174 -190
- package/src/domain/analysis/dependencies.js +200 -146
- package/src/domain/analysis/exports.js +3 -2
- package/src/domain/analysis/impact.js +267 -152
- package/src/domain/analysis/module-map.js +247 -221
- package/src/domain/analysis/roles.js +8 -5
- package/src/domain/analysis/symbol-lookup.js +7 -5
- package/src/domain/graph/builder/helpers.js +1 -1
- package/src/domain/graph/builder/incremental.js +116 -90
- package/src/domain/graph/builder/pipeline.js +106 -80
- package/src/domain/graph/builder/stages/build-edges.js +318 -239
- package/src/domain/graph/builder/stages/detect-changes.js +198 -177
- package/src/domain/graph/builder/stages/insert-nodes.js +147 -139
- package/src/domain/graph/watcher.js +2 -2
- package/src/domain/parser.js +20 -11
- package/src/domain/queries.js +1 -0
- package/src/domain/search/search/filters.js +9 -5
- package/src/domain/search/search/keyword.js +12 -5
- package/src/domain/search/search/prepare.js +13 -5
- package/src/extractors/csharp.js +224 -207
- package/src/extractors/go.js +176 -172
- package/src/extractors/hcl.js +94 -78
- package/src/extractors/java.js +213 -207
- package/src/extractors/javascript.js +274 -304
- package/src/extractors/php.js +234 -221
- package/src/extractors/python.js +252 -250
- package/src/extractors/ruby.js +192 -185
- package/src/extractors/rust.js +182 -167
- package/src/features/ast.js +5 -3
- package/src/features/audit.js +4 -2
- package/src/features/boundaries.js +98 -83
- package/src/features/cfg.js +134 -143
- package/src/features/communities.js +68 -53
- package/src/features/complexity.js +143 -132
- package/src/features/dataflow.js +146 -149
- package/src/features/export.js +3 -3
- package/src/features/graph-enrichment.js +2 -2
- package/src/features/manifesto.js +9 -6
- package/src/features/owners.js +4 -3
- package/src/features/sequence.js +152 -141
- package/src/features/shared/find-nodes.js +31 -0
- package/src/features/structure.js +130 -99
- package/src/features/triage.js +83 -68
- package/src/graph/classifiers/risk.js +3 -2
- package/src/graph/classifiers/roles.js +6 -3
- package/src/index.js +1 -0
- package/src/mcp/server.js +65 -56
- package/src/mcp/tool-registry.js +13 -0
- package/src/mcp/tools/brief.js +8 -0
- package/src/mcp/tools/index.js +2 -0
- package/src/presentation/brief.js +51 -0
- package/src/presentation/queries-cli/exports.js +21 -14
- package/src/presentation/queries-cli/impact.js +55 -39
- package/src/presentation/queries-cli/inspect.js +184 -189
- package/src/presentation/queries-cli/overview.js +57 -58
- package/src/presentation/queries-cli/path.js +36 -29
- package/src/presentation/table.js +0 -8
- package/src/shared/generators.js +7 -3
- package/src/shared/kinds.js +1 -1
package/src/extractors/ruby.js
CHANGED
|
@@ -4,211 +4,218 @@ import { findChild, nodeEndLine } from './helpers.js';
|
|
|
4
4
|
* Extract symbols from Ruby files.
|
|
5
5
|
*/
|
|
6
6
|
export function extractRubySymbols(tree, _filePath) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const ctx = {
|
|
8
|
+
definitions: [],
|
|
9
|
+
calls: [],
|
|
10
|
+
imports: [],
|
|
11
|
+
classes: [],
|
|
12
|
+
exports: [],
|
|
13
|
+
};
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
walkRubyNode(tree.rootNode, ctx);
|
|
16
|
+
return ctx;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function walkRubyNode(node, ctx) {
|
|
20
|
+
switch (node.type) {
|
|
21
|
+
case 'class':
|
|
22
|
+
handleRubyClass(node, ctx);
|
|
23
|
+
break;
|
|
24
|
+
case 'module':
|
|
25
|
+
handleRubyModule(node, ctx);
|
|
26
|
+
break;
|
|
27
|
+
case 'method':
|
|
28
|
+
handleRubyMethod(node, ctx);
|
|
29
|
+
break;
|
|
30
|
+
case 'singleton_method':
|
|
31
|
+
handleRubySingletonMethod(node, ctx);
|
|
32
|
+
break;
|
|
33
|
+
case 'assignment':
|
|
34
|
+
handleRubyAssignment(node, ctx);
|
|
35
|
+
break;
|
|
36
|
+
case 'call':
|
|
37
|
+
handleRubyCall(node, ctx);
|
|
38
|
+
break;
|
|
27
39
|
}
|
|
28
40
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
// Direct superclass node may be a constant
|
|
57
|
-
if (superclass.type === 'superclass') {
|
|
58
|
-
for (let i = 0; i < superclass.childCount; i++) {
|
|
59
|
-
const child = superclass.child(i);
|
|
60
|
-
if (child && (child.type === 'constant' || child.type === 'scope_resolution')) {
|
|
61
|
-
classes.push({
|
|
62
|
-
name: nameNode.text,
|
|
63
|
-
extends: child.text,
|
|
64
|
-
line: node.startPosition.row + 1,
|
|
65
|
-
});
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
41
|
+
for (let i = 0; i < node.childCount; i++) walkRubyNode(node.child(i), ctx);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ── Walk-path per-node-type handlers ────────────────────────────────────────
|
|
45
|
+
|
|
46
|
+
function handleRubyClass(node, ctx) {
|
|
47
|
+
const nameNode = node.childForFieldName('name');
|
|
48
|
+
if (!nameNode) return;
|
|
49
|
+
const classChildren = extractRubyClassChildren(node);
|
|
50
|
+
ctx.definitions.push({
|
|
51
|
+
name: nameNode.text,
|
|
52
|
+
kind: 'class',
|
|
53
|
+
line: node.startPosition.row + 1,
|
|
54
|
+
endLine: nodeEndLine(node),
|
|
55
|
+
children: classChildren.length > 0 ? classChildren : undefined,
|
|
56
|
+
});
|
|
57
|
+
const superclass = node.childForFieldName('superclass');
|
|
58
|
+
if (superclass) {
|
|
59
|
+
for (let i = 0; i < superclass.childCount; i++) {
|
|
60
|
+
const child = superclass.child(i);
|
|
61
|
+
if (child && (child.type === 'constant' || child.type === 'scope_resolution')) {
|
|
62
|
+
ctx.classes.push({
|
|
63
|
+
name: nameNode.text,
|
|
64
|
+
extends: child.text,
|
|
65
|
+
line: node.startPosition.row + 1,
|
|
66
|
+
});
|
|
72
67
|
break;
|
|
73
68
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
69
|
+
}
|
|
70
|
+
if (superclass.type === 'superclass') {
|
|
71
|
+
for (let i = 0; i < superclass.childCount; i++) {
|
|
72
|
+
const child = superclass.child(i);
|
|
73
|
+
if (child && (child.type === 'constant' || child.type === 'scope_resolution')) {
|
|
74
|
+
ctx.classes.push({
|
|
80
75
|
name: nameNode.text,
|
|
81
|
-
|
|
76
|
+
extends: child.text,
|
|
82
77
|
line: node.startPosition.row + 1,
|
|
83
|
-
endLine: nodeEndLine(node),
|
|
84
|
-
children: moduleChildren.length > 0 ? moduleChildren : undefined,
|
|
85
78
|
});
|
|
79
|
+
break;
|
|
86
80
|
}
|
|
87
|
-
break;
|
|
88
81
|
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
89
85
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
86
|
+
function handleRubyModule(node, ctx) {
|
|
87
|
+
const nameNode = node.childForFieldName('name');
|
|
88
|
+
if (!nameNode) return;
|
|
89
|
+
const moduleChildren = extractRubyBodyConstants(node);
|
|
90
|
+
ctx.definitions.push({
|
|
91
|
+
name: nameNode.text,
|
|
92
|
+
kind: 'module',
|
|
93
|
+
line: node.startPosition.row + 1,
|
|
94
|
+
endLine: nodeEndLine(node),
|
|
95
|
+
children: moduleChildren.length > 0 ? moduleChildren : undefined,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
106
98
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
99
|
+
function handleRubyMethod(node, ctx) {
|
|
100
|
+
const nameNode = node.childForFieldName('name');
|
|
101
|
+
if (!nameNode) return;
|
|
102
|
+
const parentClass = findRubyParentClass(node);
|
|
103
|
+
const fullName = parentClass ? `${parentClass}.${nameNode.text}` : nameNode.text;
|
|
104
|
+
const params = extractRubyParameters(node);
|
|
105
|
+
ctx.definitions.push({
|
|
106
|
+
name: fullName,
|
|
107
|
+
kind: 'method',
|
|
108
|
+
line: node.startPosition.row + 1,
|
|
109
|
+
endLine: nodeEndLine(node),
|
|
110
|
+
children: params.length > 0 ? params : undefined,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
123
113
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
114
|
+
function handleRubySingletonMethod(node, ctx) {
|
|
115
|
+
const nameNode = node.childForFieldName('name');
|
|
116
|
+
if (!nameNode) return;
|
|
117
|
+
const parentClass = findRubyParentClass(node);
|
|
118
|
+
const fullName = parentClass ? `${parentClass}.${nameNode.text}` : nameNode.text;
|
|
119
|
+
const params = extractRubyParameters(node);
|
|
120
|
+
ctx.definitions.push({
|
|
121
|
+
name: fullName,
|
|
122
|
+
kind: 'function',
|
|
123
|
+
line: node.startPosition.row + 1,
|
|
124
|
+
endLine: nodeEndLine(node),
|
|
125
|
+
children: params.length > 0 ? params : undefined,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
139
128
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const recv = node.childForFieldName('receiver');
|
|
198
|
-
const call = { name: methodNode.text, line: node.startPosition.row + 1 };
|
|
199
|
-
if (recv) call.receiver = recv.text;
|
|
200
|
-
calls.push(call);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
129
|
+
function handleRubyAssignment(node, ctx) {
|
|
130
|
+
if (node.parent && node.parent.type === 'program') {
|
|
131
|
+
const left = node.childForFieldName('left');
|
|
132
|
+
if (left && left.type === 'constant') {
|
|
133
|
+
ctx.definitions.push({
|
|
134
|
+
name: left.text,
|
|
135
|
+
kind: 'constant',
|
|
136
|
+
line: node.startPosition.row + 1,
|
|
137
|
+
endLine: nodeEndLine(node),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function handleRubyCall(node, ctx) {
|
|
144
|
+
const methodNode = node.childForFieldName('method');
|
|
145
|
+
if (!methodNode) return;
|
|
146
|
+
if (methodNode.text === 'require' || methodNode.text === 'require_relative') {
|
|
147
|
+
handleRubyRequire(node, ctx);
|
|
148
|
+
} else if (
|
|
149
|
+
methodNode.text === 'include' ||
|
|
150
|
+
methodNode.text === 'extend' ||
|
|
151
|
+
methodNode.text === 'prepend'
|
|
152
|
+
) {
|
|
153
|
+
handleRubyModuleInclusion(node, methodNode, ctx);
|
|
154
|
+
} else {
|
|
155
|
+
const recv = node.childForFieldName('receiver');
|
|
156
|
+
const call = { name: methodNode.text, line: node.startPosition.row + 1 };
|
|
157
|
+
if (recv) call.receiver = recv.text;
|
|
158
|
+
ctx.calls.push(call);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function handleRubyRequire(node, ctx) {
|
|
163
|
+
const args = node.childForFieldName('arguments');
|
|
164
|
+
if (!args) return;
|
|
165
|
+
for (let i = 0; i < args.childCount; i++) {
|
|
166
|
+
const arg = args.child(i);
|
|
167
|
+
if (arg && (arg.type === 'string' || arg.type === 'string_content')) {
|
|
168
|
+
const strContent = arg.text.replace(/^['"]|['"]$/g, '');
|
|
169
|
+
ctx.imports.push({
|
|
170
|
+
source: strContent,
|
|
171
|
+
names: [strContent.split('/').pop()],
|
|
172
|
+
line: node.startPosition.row + 1,
|
|
173
|
+
rubyRequire: true,
|
|
174
|
+
});
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
if (arg && arg.type === 'string') {
|
|
178
|
+
const content = findChild(arg, 'string_content');
|
|
179
|
+
if (content) {
|
|
180
|
+
ctx.imports.push({
|
|
181
|
+
source: content.text,
|
|
182
|
+
names: [content.text.split('/').pop()],
|
|
183
|
+
line: node.startPosition.row + 1,
|
|
184
|
+
rubyRequire: true,
|
|
185
|
+
});
|
|
203
186
|
break;
|
|
204
187
|
}
|
|
205
188
|
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
206
191
|
|
|
207
|
-
|
|
192
|
+
function handleRubyModuleInclusion(node, _methodNode, ctx) {
|
|
193
|
+
const parentClass = findRubyParentClass(node);
|
|
194
|
+
if (!parentClass) return;
|
|
195
|
+
const args = node.childForFieldName('arguments');
|
|
196
|
+
if (!args) return;
|
|
197
|
+
for (let i = 0; i < args.childCount; i++) {
|
|
198
|
+
const arg = args.child(i);
|
|
199
|
+
if (arg && (arg.type === 'constant' || arg.type === 'scope_resolution')) {
|
|
200
|
+
ctx.classes.push({
|
|
201
|
+
name: parentClass,
|
|
202
|
+
implements: arg.text,
|
|
203
|
+
line: node.startPosition.row + 1,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
208
206
|
}
|
|
207
|
+
}
|
|
209
208
|
|
|
210
|
-
|
|
211
|
-
|
|
209
|
+
function findRubyParentClass(node) {
|
|
210
|
+
let current = node.parent;
|
|
211
|
+
while (current) {
|
|
212
|
+
if (current.type === 'class' || current.type === 'module') {
|
|
213
|
+
const nameNode = current.childForFieldName('name');
|
|
214
|
+
return nameNode ? nameNode.text : null;
|
|
215
|
+
}
|
|
216
|
+
current = current.parent;
|
|
217
|
+
}
|
|
218
|
+
return null;
|
|
212
219
|
}
|
|
213
220
|
|
|
214
221
|
// ── Child extraction helpers ────────────────────────────────────────────────
|