@optave/codegraph 3.1.4 → 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.
Files changed (210) hide show
  1. package/README.md +29 -72
  2. package/package.json +10 -8
  3. package/src/ast-analysis/engine.js +260 -246
  4. package/src/ast-analysis/shared.js +2 -14
  5. package/src/ast-analysis/visitors/cfg-visitor.js +635 -649
  6. package/src/ast-analysis/visitors/complexity-visitor.js +135 -139
  7. package/src/ast-analysis/visitors/dataflow-visitor.js +230 -224
  8. package/src/cli/commands/ast.js +4 -7
  9. package/src/cli/commands/audit.js +11 -11
  10. package/src/cli/commands/batch.js +6 -5
  11. package/src/cli/commands/branch-compare.js +1 -1
  12. package/src/cli/commands/brief.js +12 -0
  13. package/src/cli/commands/build.js +1 -1
  14. package/src/cli/commands/cfg.js +5 -8
  15. package/src/cli/commands/check.js +28 -36
  16. package/src/cli/commands/children.js +9 -7
  17. package/src/cli/commands/co-change.js +5 -3
  18. package/src/cli/commands/communities.js +2 -6
  19. package/src/cli/commands/complexity.js +5 -3
  20. package/src/cli/commands/context.js +9 -8
  21. package/src/cli/commands/cycles.js +12 -8
  22. package/src/cli/commands/dataflow.js +5 -8
  23. package/src/cli/commands/deps.js +9 -8
  24. package/src/cli/commands/diff-impact.js +2 -6
  25. package/src/cli/commands/embed.js +1 -1
  26. package/src/cli/commands/export.js +34 -31
  27. package/src/cli/commands/exports.js +2 -6
  28. package/src/cli/commands/flow.js +5 -8
  29. package/src/cli/commands/fn-impact.js +9 -8
  30. package/src/cli/commands/impact.js +2 -6
  31. package/src/cli/commands/info.js +2 -2
  32. package/src/cli/commands/map.js +1 -1
  33. package/src/cli/commands/mcp.js +1 -1
  34. package/src/cli/commands/models.js +1 -1
  35. package/src/cli/commands/owners.js +5 -3
  36. package/src/cli/commands/path.js +2 -2
  37. package/src/cli/commands/plot.js +40 -31
  38. package/src/cli/commands/query.js +9 -8
  39. package/src/cli/commands/registry.js +2 -2
  40. package/src/cli/commands/roles.js +5 -8
  41. package/src/cli/commands/search.js +9 -3
  42. package/src/cli/commands/sequence.js +5 -8
  43. package/src/cli/commands/snapshot.js +6 -1
  44. package/src/cli/commands/stats.js +1 -1
  45. package/src/cli/commands/structure.js +5 -4
  46. package/src/cli/commands/triage.js +41 -30
  47. package/src/cli/commands/watch.js +1 -1
  48. package/src/cli/commands/where.js +2 -6
  49. package/src/cli/index.js +11 -5
  50. package/src/cli/shared/open-graph.js +13 -0
  51. package/src/cli/shared/options.js +22 -2
  52. package/src/cli.js +1 -1
  53. package/src/db/connection.js +140 -11
  54. package/src/{db.js → db/index.js} +12 -5
  55. package/src/db/migrations.js +42 -65
  56. package/src/db/query-builder.js +72 -9
  57. package/src/db/repository/base.js +1 -1
  58. package/src/db/repository/graph-read.js +3 -3
  59. package/src/db/repository/in-memory-repository.js +30 -28
  60. package/src/db/repository/nodes.js +10 -17
  61. package/src/domain/analysis/brief.js +155 -0
  62. package/src/domain/analysis/context.js +392 -0
  63. package/src/domain/analysis/dependencies.js +395 -0
  64. package/src/{analysis → domain/analysis}/exports.js +11 -6
  65. package/src/domain/analysis/impact.js +581 -0
  66. package/src/domain/analysis/module-map.js +348 -0
  67. package/src/{analysis → domain/analysis}/roles.js +12 -9
  68. package/src/{analysis → domain/analysis}/symbol-lookup.js +19 -11
  69. package/src/{builder → domain/graph/builder}/helpers.js +4 -4
  70. package/src/{builder → domain/graph/builder}/incremental.js +119 -93
  71. package/src/domain/graph/builder/pipeline.js +156 -0
  72. package/src/domain/graph/builder/stages/build-edges.js +376 -0
  73. package/src/{builder → domain/graph/builder}/stages/build-structure.js +4 -4
  74. package/src/{builder → domain/graph/builder}/stages/collect-files.js +2 -2
  75. package/src/{builder → domain/graph/builder}/stages/detect-changes.js +204 -183
  76. package/src/{builder → domain/graph/builder}/stages/finalize.js +4 -4
  77. package/src/domain/graph/builder/stages/insert-nodes.js +203 -0
  78. package/src/{builder → domain/graph/builder}/stages/parse-files.js +2 -2
  79. package/src/{builder → domain/graph/builder}/stages/resolve-imports.js +1 -1
  80. package/src/{builder → domain/graph/builder}/stages/run-analyses.js +2 -2
  81. package/src/{change-journal.js → domain/graph/change-journal.js} +1 -1
  82. package/src/{cycles.js → domain/graph/cycles.js} +4 -4
  83. package/src/{journal.js → domain/graph/journal.js} +1 -1
  84. package/src/{resolve.js → domain/graph/resolve.js} +2 -2
  85. package/src/{watcher.js → domain/graph/watcher.js} +7 -7
  86. package/src/{parser.js → domain/parser.js} +24 -15
  87. package/src/{queries.js → domain/queries.js} +17 -16
  88. package/src/{embeddings → domain/search}/generator.js +3 -3
  89. package/src/{embeddings → domain/search}/models.js +2 -2
  90. package/src/{embeddings → domain/search}/search/cli-formatter.js +1 -1
  91. package/src/{embeddings → domain/search}/search/filters.js +9 -5
  92. package/src/{embeddings → domain/search}/search/hybrid.js +1 -1
  93. package/src/{embeddings → domain/search}/search/keyword.js +13 -6
  94. package/src/{embeddings → domain/search}/search/prepare.js +15 -7
  95. package/src/{embeddings → domain/search}/search/semantic.js +1 -1
  96. package/src/{embeddings → domain/search}/strategies/structured.js +1 -1
  97. package/src/extractors/csharp.js +224 -207
  98. package/src/extractors/go.js +176 -172
  99. package/src/extractors/hcl.js +94 -78
  100. package/src/extractors/java.js +213 -207
  101. package/src/extractors/javascript.js +275 -305
  102. package/src/extractors/php.js +234 -221
  103. package/src/extractors/python.js +252 -250
  104. package/src/extractors/ruby.js +192 -185
  105. package/src/extractors/rust.js +182 -167
  106. package/src/{ast.js → features/ast.js} +13 -11
  107. package/src/{audit.js → features/audit.js} +20 -46
  108. package/src/{batch.js → features/batch.js} +5 -5
  109. package/src/{boundaries.js → features/boundaries.js} +100 -85
  110. package/src/{branch-compare.js → features/branch-compare.js} +3 -3
  111. package/src/{cfg.js → features/cfg.js} +141 -150
  112. package/src/{check.js → features/check.js} +13 -30
  113. package/src/{cochange.js → features/cochange.js} +5 -5
  114. package/src/{communities.js → features/communities.js} +72 -57
  115. package/src/{complexity.js → features/complexity.js} +154 -143
  116. package/src/{dataflow.js → features/dataflow.js} +155 -158
  117. package/src/{export.js → features/export.js} +6 -6
  118. package/src/{flow.js → features/flow.js} +4 -4
  119. package/src/{viewer.js → features/graph-enrichment.js} +8 -8
  120. package/src/{manifesto.js → features/manifesto.js} +15 -12
  121. package/src/{owners.js → features/owners.js} +6 -5
  122. package/src/features/sequence.js +300 -0
  123. package/src/features/shared/find-nodes.js +31 -0
  124. package/src/{snapshot.js → features/snapshot.js} +3 -3
  125. package/src/{structure.js → features/structure.js} +139 -108
  126. package/src/features/triage.js +141 -0
  127. package/src/graph/builders/dependency.js +33 -14
  128. package/src/graph/classifiers/risk.js +3 -2
  129. package/src/graph/classifiers/roles.js +6 -3
  130. package/src/index.cjs +16 -0
  131. package/src/index.js +40 -39
  132. package/src/{native.js → infrastructure/native.js} +1 -1
  133. package/src/mcp/middleware.js +1 -1
  134. package/src/mcp/server.js +68 -59
  135. package/src/mcp/tool-registry.js +15 -2
  136. package/src/mcp/tools/ast-query.js +1 -1
  137. package/src/mcp/tools/audit.js +1 -1
  138. package/src/mcp/tools/batch-query.js +1 -1
  139. package/src/mcp/tools/branch-compare.js +3 -1
  140. package/src/mcp/tools/brief.js +8 -0
  141. package/src/mcp/tools/cfg.js +1 -1
  142. package/src/mcp/tools/check.js +3 -3
  143. package/src/mcp/tools/co-changes.js +1 -1
  144. package/src/mcp/tools/code-owners.js +1 -1
  145. package/src/mcp/tools/communities.js +1 -1
  146. package/src/mcp/tools/complexity.js +1 -1
  147. package/src/mcp/tools/dataflow.js +2 -2
  148. package/src/mcp/tools/execution-flow.js +2 -2
  149. package/src/mcp/tools/export-graph.js +2 -2
  150. package/src/mcp/tools/find-cycles.js +2 -2
  151. package/src/mcp/tools/index.js +2 -0
  152. package/src/mcp/tools/list-repos.js +1 -1
  153. package/src/mcp/tools/sequence.js +1 -1
  154. package/src/mcp/tools/structure.js +1 -1
  155. package/src/mcp/tools/triage.js +2 -2
  156. package/src/{commands → presentation}/audit.js +2 -2
  157. package/src/{commands → presentation}/batch.js +1 -1
  158. package/src/{commands → presentation}/branch-compare.js +2 -2
  159. package/src/presentation/brief.js +51 -0
  160. package/src/{commands → presentation}/cfg.js +1 -1
  161. package/src/{commands → presentation}/check.js +2 -2
  162. package/src/{commands → presentation}/communities.js +1 -1
  163. package/src/{commands → presentation}/complexity.js +1 -1
  164. package/src/{commands → presentation}/dataflow.js +1 -1
  165. package/src/{commands → presentation}/flow.js +2 -2
  166. package/src/{commands → presentation}/manifesto.js +1 -1
  167. package/src/{commands → presentation}/owners.js +1 -1
  168. package/src/presentation/queries-cli/exports.js +53 -0
  169. package/src/presentation/queries-cli/impact.js +214 -0
  170. package/src/presentation/queries-cli/index.js +5 -0
  171. package/src/presentation/queries-cli/inspect.js +329 -0
  172. package/src/presentation/queries-cli/overview.js +196 -0
  173. package/src/presentation/queries-cli/path.js +65 -0
  174. package/src/presentation/queries-cli.js +27 -0
  175. package/src/{commands → presentation}/query.js +1 -1
  176. package/src/presentation/result-formatter.js +126 -3
  177. package/src/{commands → presentation}/sequence.js +2 -2
  178. package/src/{commands → presentation}/structure.js +1 -1
  179. package/src/presentation/table.js +0 -8
  180. package/src/{commands → presentation}/triage.js +1 -1
  181. package/src/{constants.js → shared/constants.js} +1 -1
  182. package/src/shared/file-utils.js +2 -2
  183. package/src/shared/generators.js +9 -5
  184. package/src/shared/hierarchy.js +1 -1
  185. package/src/{kinds.js → shared/kinds.js} +1 -1
  186. package/src/analysis/context.js +0 -408
  187. package/src/analysis/dependencies.js +0 -341
  188. package/src/analysis/impact.js +0 -463
  189. package/src/analysis/module-map.js +0 -322
  190. package/src/builder/pipeline.js +0 -130
  191. package/src/builder/stages/build-edges.js +0 -297
  192. package/src/builder/stages/insert-nodes.js +0 -195
  193. package/src/mcp.js +0 -2
  194. package/src/queries-cli.js +0 -866
  195. package/src/sequence.js +0 -289
  196. package/src/triage.js +0 -126
  197. /package/src/{builder → domain/graph/builder}/context.js +0 -0
  198. /package/src/{builder.js → domain/graph/builder.js} +0 -0
  199. /package/src/{embeddings → domain/search}/index.js +0 -0
  200. /package/src/{embeddings → domain/search}/stores/fts5.js +0 -0
  201. /package/src/{embeddings → domain/search}/stores/sqlite-blob.js +0 -0
  202. /package/src/{embeddings → domain/search}/strategies/source.js +0 -0
  203. /package/src/{embeddings → domain/search}/strategies/text-utils.js +0 -0
  204. /package/src/{config.js → infrastructure/config.js} +0 -0
  205. /package/src/{logger.js → infrastructure/logger.js} +0 -0
  206. /package/src/{registry.js → infrastructure/registry.js} +0 -0
  207. /package/src/{update-check.js → infrastructure/update-check.js} +0 -0
  208. /package/src/{commands → presentation}/cochange.js +0 -0
  209. /package/src/{errors.js → shared/errors.js} +0 -0
  210. /package/src/{paginate.js → shared/paginate.js} +0 -0
@@ -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 definitions = [];
8
- const calls = [];
9
- const imports = [];
10
- const classes = [];
11
- const exports = [];
7
+ const ctx = {
8
+ definitions: [],
9
+ calls: [],
10
+ imports: [],
11
+ classes: [],
12
+ exports: [],
13
+ };
12
14
 
13
- function findRubyParentClass(node) {
14
- let current = node.parent;
15
- while (current) {
16
- if (current.type === 'class') {
17
- const nameNode = current.childForFieldName('name');
18
- return nameNode ? nameNode.text : null;
19
- }
20
- if (current.type === 'module') {
21
- const nameNode = current.childForFieldName('name');
22
- return nameNode ? nameNode.text : null;
23
- }
24
- current = current.parent;
25
- }
26
- return null;
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
- function walkRubyNode(node) {
30
- switch (node.type) {
31
- case 'class': {
32
- const nameNode = node.childForFieldName('name');
33
- if (nameNode) {
34
- const classChildren = extractRubyClassChildren(node);
35
- definitions.push({
36
- name: nameNode.text,
37
- kind: 'class',
38
- line: node.startPosition.row + 1,
39
- endLine: nodeEndLine(node),
40
- children: classChildren.length > 0 ? classChildren : undefined,
41
- });
42
- const superclass = node.childForFieldName('superclass');
43
- if (superclass) {
44
- // superclass wraps the < token and class name
45
- for (let i = 0; i < superclass.childCount; i++) {
46
- const child = superclass.child(i);
47
- if (child && (child.type === 'constant' || child.type === 'scope_resolution')) {
48
- classes.push({
49
- name: nameNode.text,
50
- extends: child.text,
51
- line: node.startPosition.row + 1,
52
- });
53
- break;
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
- case 'module': {
76
- const nameNode = node.childForFieldName('name');
77
- if (nameNode) {
78
- const moduleChildren = extractRubyBodyConstants(node);
79
- definitions.push({
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
- kind: 'module',
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
- case 'method': {
91
- const nameNode = node.childForFieldName('name');
92
- if (nameNode) {
93
- const parentClass = findRubyParentClass(node);
94
- const fullName = parentClass ? `${parentClass}.${nameNode.text}` : nameNode.text;
95
- const params = extractRubyParameters(node);
96
- definitions.push({
97
- name: fullName,
98
- kind: 'method',
99
- line: node.startPosition.row + 1,
100
- endLine: nodeEndLine(node),
101
- children: params.length > 0 ? params : undefined,
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
- case 'singleton_method': {
108
- const nameNode = node.childForFieldName('name');
109
- if (nameNode) {
110
- const parentClass = findRubyParentClass(node);
111
- const fullName = parentClass ? `${parentClass}.${nameNode.text}` : nameNode.text;
112
- const params = extractRubyParameters(node);
113
- definitions.push({
114
- name: fullName,
115
- kind: 'function',
116
- line: node.startPosition.row + 1,
117
- endLine: nodeEndLine(node),
118
- children: params.length > 0 ? params : undefined,
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
- case 'assignment': {
125
- // Top-level constant assignments (parent is program)
126
- if (node.parent && node.parent.type === 'program') {
127
- const left = node.childForFieldName('left');
128
- if (left && left.type === 'constant') {
129
- definitions.push({
130
- name: left.text,
131
- kind: 'constant',
132
- line: node.startPosition.row + 1,
133
- endLine: nodeEndLine(node),
134
- });
135
- }
136
- }
137
- break;
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
- case 'call': {
141
- const methodNode = node.childForFieldName('method');
142
- if (methodNode) {
143
- // Check for require/require_relative
144
- if (methodNode.text === 'require' || methodNode.text === 'require_relative') {
145
- const args = node.childForFieldName('arguments');
146
- if (args) {
147
- for (let i = 0; i < args.childCount; i++) {
148
- const arg = args.child(i);
149
- if (arg && (arg.type === 'string' || arg.type === 'string_content')) {
150
- const strContent = arg.text.replace(/^['"]|['"]$/g, '');
151
- imports.push({
152
- source: strContent,
153
- names: [strContent.split('/').pop()],
154
- line: node.startPosition.row + 1,
155
- rubyRequire: true,
156
- });
157
- break;
158
- }
159
- // Look inside string for string_content
160
- if (arg && arg.type === 'string') {
161
- const content = findChild(arg, 'string_content');
162
- if (content) {
163
- imports.push({
164
- source: content.text,
165
- names: [content.text.split('/').pop()],
166
- line: node.startPosition.row + 1,
167
- rubyRequire: true,
168
- });
169
- break;
170
- }
171
- }
172
- }
173
- }
174
- } else if (
175
- methodNode.text === 'include' ||
176
- methodNode.text === 'extend' ||
177
- methodNode.text === 'prepend'
178
- ) {
179
- // Module inclusion treated like implements
180
- const parentClass = findRubyParentClass(node);
181
- if (parentClass) {
182
- const args = node.childForFieldName('arguments');
183
- if (args) {
184
- for (let i = 0; i < args.childCount; i++) {
185
- const arg = args.child(i);
186
- if (arg && (arg.type === 'constant' || arg.type === 'scope_resolution')) {
187
- classes.push({
188
- name: parentClass,
189
- implements: arg.text,
190
- line: node.startPosition.row + 1,
191
- });
192
- }
193
- }
194
- }
195
- }
196
- } else {
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
- for (let i = 0; i < node.childCount; i++) walkRubyNode(node.child(i));
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
- walkRubyNode(tree.rootNode);
211
- return { definitions, calls, imports, classes, exports };
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 ────────────────────────────────────────────────