mulle-roam-code 0.0.1__py3-none-any.whl

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 (257) hide show
  1. mulle_roam_code-0.0.1.dist-info/METADATA +1590 -0
  2. mulle_roam_code-0.0.1.dist-info/RECORD +257 -0
  3. mulle_roam_code-0.0.1.dist-info/WHEEL +5 -0
  4. mulle_roam_code-0.0.1.dist-info/entry_points.txt +3 -0
  5. mulle_roam_code-0.0.1.dist-info/licenses/LICENSE +21 -0
  6. mulle_roam_code-0.0.1.dist-info/top_level.txt +1 -0
  7. roam/__init__.py +8 -0
  8. roam/__main__.py +5 -0
  9. roam/analysis/__init__.py +1 -0
  10. roam/analysis/effects.py +639 -0
  11. roam/analysis/taint.py +689 -0
  12. roam/api.py +238 -0
  13. roam/bridges/__init__.py +3 -0
  14. roam/bridges/base.py +49 -0
  15. roam/bridges/bridge_config.py +218 -0
  16. roam/bridges/bridge_protobuf.py +352 -0
  17. roam/bridges/bridge_rest_api.py +242 -0
  18. roam/bridges/bridge_salesforce.py +198 -0
  19. roam/bridges/bridge_template.py +247 -0
  20. roam/bridges/registry.py +51 -0
  21. roam/catalog/__init__.py +0 -0
  22. roam/catalog/detectors.py +2242 -0
  23. roam/catalog/fixes.py +86 -0
  24. roam/catalog/smells.py +599 -0
  25. roam/catalog/tasks.py +1260 -0
  26. roam/cli.py +548 -0
  27. roam/commands/__init__.py +0 -0
  28. roam/commands/changed_files.py +139 -0
  29. roam/commands/cmd_adversarial.py +699 -0
  30. roam/commands/cmd_affected.py +432 -0
  31. roam/commands/cmd_affected_tests.py +375 -0
  32. roam/commands/cmd_agent_context.py +168 -0
  33. roam/commands/cmd_agent_export.py +890 -0
  34. roam/commands/cmd_agent_plan.py +315 -0
  35. roam/commands/cmd_ai_ratio.py +765 -0
  36. roam/commands/cmd_ai_readiness.py +775 -0
  37. roam/commands/cmd_alerts.py +409 -0
  38. roam/commands/cmd_annotate.py +210 -0
  39. roam/commands/cmd_api_changes.py +796 -0
  40. roam/commands/cmd_api_drift.py +781 -0
  41. roam/commands/cmd_attest.py +913 -0
  42. roam/commands/cmd_auth_gaps.py +799 -0
  43. roam/commands/cmd_bisect.py +216 -0
  44. roam/commands/cmd_breaking.py +464 -0
  45. roam/commands/cmd_budget.py +413 -0
  46. roam/commands/cmd_bus_factor.py +403 -0
  47. roam/commands/cmd_capsule.py +275 -0
  48. roam/commands/cmd_check_rules.py +574 -0
  49. roam/commands/cmd_clean.py +147 -0
  50. roam/commands/cmd_closure.py +294 -0
  51. roam/commands/cmd_clusters.py +457 -0
  52. roam/commands/cmd_codeowners.py +600 -0
  53. roam/commands/cmd_complexity.py +364 -0
  54. roam/commands/cmd_config.py +310 -0
  55. roam/commands/cmd_context.py +1151 -0
  56. roam/commands/cmd_conventions.py +697 -0
  57. roam/commands/cmd_coupling.py +462 -0
  58. roam/commands/cmd_coverage_gaps.py +638 -0
  59. roam/commands/cmd_cut.py +235 -0
  60. roam/commands/cmd_dark_matter.py +127 -0
  61. roam/commands/cmd_dashboard.py +365 -0
  62. roam/commands/cmd_dead.py +1585 -0
  63. roam/commands/cmd_debt.py +731 -0
  64. roam/commands/cmd_deps.py +121 -0
  65. roam/commands/cmd_describe.py +959 -0
  66. roam/commands/cmd_dev_profile.py +580 -0
  67. roam/commands/cmd_diagnose.py +377 -0
  68. roam/commands/cmd_diff.py +633 -0
  69. roam/commands/cmd_digest.py +214 -0
  70. roam/commands/cmd_doc_staleness.py +334 -0
  71. roam/commands/cmd_docs_coverage.py +193 -0
  72. roam/commands/cmd_doctor.py +319 -0
  73. roam/commands/cmd_drift.py +377 -0
  74. roam/commands/cmd_duplicates.py +559 -0
  75. roam/commands/cmd_effects.py +362 -0
  76. roam/commands/cmd_endpoints.py +768 -0
  77. roam/commands/cmd_entry_points.py +358 -0
  78. roam/commands/cmd_fan.py +311 -0
  79. roam/commands/cmd_file.py +334 -0
  80. roam/commands/cmd_fingerprint.py +172 -0
  81. roam/commands/cmd_fitness.py +723 -0
  82. roam/commands/cmd_fn_coupling.py +295 -0
  83. roam/commands/cmd_forecast.py +366 -0
  84. roam/commands/cmd_grep.py +282 -0
  85. roam/commands/cmd_guard.py +434 -0
  86. roam/commands/cmd_health.py +922 -0
  87. roam/commands/cmd_hooks.py +458 -0
  88. roam/commands/cmd_hotspots.py +606 -0
  89. roam/commands/cmd_impact.py +228 -0
  90. roam/commands/cmd_index.py +102 -0
  91. roam/commands/cmd_ingest_trace.py +143 -0
  92. roam/commands/cmd_init.py +166 -0
  93. roam/commands/cmd_intent.py +459 -0
  94. roam/commands/cmd_invariants.py +301 -0
  95. roam/commands/cmd_layers.py +387 -0
  96. roam/commands/cmd_map.py +275 -0
  97. roam/commands/cmd_math.py +213 -0
  98. roam/commands/cmd_mcp_setup.py +135 -0
  99. roam/commands/cmd_metrics.py +663 -0
  100. roam/commands/cmd_migration_safety.py +712 -0
  101. roam/commands/cmd_minimap.py +519 -0
  102. roam/commands/cmd_missing_index.py +885 -0
  103. roam/commands/cmd_module.py +204 -0
  104. roam/commands/cmd_mutate.py +400 -0
  105. roam/commands/cmd_n1.py +967 -0
  106. roam/commands/cmd_onboard.py +740 -0
  107. roam/commands/cmd_orchestrate.py +180 -0
  108. roam/commands/cmd_orphan_routes.py +754 -0
  109. roam/commands/cmd_over_fetch.py +633 -0
  110. roam/commands/cmd_owner.py +299 -0
  111. roam/commands/cmd_partition.py +714 -0
  112. roam/commands/cmd_path_coverage.py +564 -0
  113. roam/commands/cmd_patterns.py +689 -0
  114. roam/commands/cmd_plan.py +616 -0
  115. roam/commands/cmd_plan_refactor.py +432 -0
  116. roam/commands/cmd_pr_diff.py +292 -0
  117. roam/commands/cmd_pr_risk.py +677 -0
  118. roam/commands/cmd_preflight.py +706 -0
  119. roam/commands/cmd_relate.py +405 -0
  120. roam/commands/cmd_report.py +304 -0
  121. roam/commands/cmd_reset.py +117 -0
  122. roam/commands/cmd_risk.py +533 -0
  123. roam/commands/cmd_rules.py +319 -0
  124. roam/commands/cmd_safe_delete.py +224 -0
  125. roam/commands/cmd_safe_zones.py +295 -0
  126. roam/commands/cmd_schema.py +166 -0
  127. roam/commands/cmd_search.py +295 -0
  128. roam/commands/cmd_search_semantic.py +101 -0
  129. roam/commands/cmd_secrets.py +636 -0
  130. roam/commands/cmd_semantic_diff.py +538 -0
  131. roam/commands/cmd_simulate.py +296 -0
  132. roam/commands/cmd_simulate_departure.py +632 -0
  133. roam/commands/cmd_sketch.py +160 -0
  134. roam/commands/cmd_smells.py +179 -0
  135. roam/commands/cmd_snapshot.py +50 -0
  136. roam/commands/cmd_spectral.py +183 -0
  137. roam/commands/cmd_split.py +432 -0
  138. roam/commands/cmd_suggest_refactoring.py +486 -0
  139. roam/commands/cmd_suggest_reviewers.py +491 -0
  140. roam/commands/cmd_supply_chain.py +831 -0
  141. roam/commands/cmd_symbol.py +135 -0
  142. roam/commands/cmd_syntax_check.py +301 -0
  143. roam/commands/cmd_test_gaps.py +574 -0
  144. roam/commands/cmd_testmap.py +308 -0
  145. roam/commands/cmd_tour.py +377 -0
  146. roam/commands/cmd_trace.py +304 -0
  147. roam/commands/cmd_trend.py +461 -0
  148. roam/commands/cmd_trends.py +929 -0
  149. roam/commands/cmd_understand.py +763 -0
  150. roam/commands/cmd_uses.py +170 -0
  151. roam/commands/cmd_verify.py +812 -0
  152. roam/commands/cmd_verify_imports.py +435 -0
  153. roam/commands/cmd_vibe_check.py +932 -0
  154. roam/commands/cmd_visualize.py +361 -0
  155. roam/commands/cmd_vuln_map.py +139 -0
  156. roam/commands/cmd_vuln_reach.py +289 -0
  157. roam/commands/cmd_vulns.py +414 -0
  158. roam/commands/cmd_watch.py +759 -0
  159. roam/commands/cmd_weather.py +118 -0
  160. roam/commands/cmd_why.py +325 -0
  161. roam/commands/cmd_ws.py +755 -0
  162. roam/commands/cmd_xlang.py +170 -0
  163. roam/commands/context_helpers.py +1137 -0
  164. roam/commands/gate_presets.py +222 -0
  165. roam/commands/graph_helpers.py +93 -0
  166. roam/commands/metrics_history.py +298 -0
  167. roam/commands/next_steps.py +107 -0
  168. roam/commands/resolve.py +302 -0
  169. roam/competitor_site_data.py +2229 -0
  170. roam/coverage_reports.py +462 -0
  171. roam/db/__init__.py +0 -0
  172. roam/db/connection.py +359 -0
  173. roam/db/queries.py +151 -0
  174. roam/db/schema.py +335 -0
  175. roam/exit_codes.py +100 -0
  176. roam/graph/__init__.py +43 -0
  177. roam/graph/anomaly.py +493 -0
  178. roam/graph/builder.py +61 -0
  179. roam/graph/clusters.py +286 -0
  180. roam/graph/cycles.py +210 -0
  181. roam/graph/dark_matter.py +207 -0
  182. roam/graph/diff.py +467 -0
  183. roam/graph/fingerprint.py +297 -0
  184. roam/graph/layers.py +134 -0
  185. roam/graph/pagerank.py +171 -0
  186. roam/graph/partition.py +437 -0
  187. roam/graph/pathfinding.py +119 -0
  188. roam/graph/propagation.py +208 -0
  189. roam/graph/simulate.py +286 -0
  190. roam/graph/spectral.py +260 -0
  191. roam/index/__init__.py +5 -0
  192. roam/index/complexity.py +1108 -0
  193. roam/index/discovery.py +338 -0
  194. roam/index/file_roles.py +586 -0
  195. roam/index/git_stats.py +577 -0
  196. roam/index/incremental.py +75 -0
  197. roam/index/indexer.py +1191 -0
  198. roam/index/parser.py +461 -0
  199. roam/index/relations.py +537 -0
  200. roam/index/symbols.py +71 -0
  201. roam/index/test_conventions.py +508 -0
  202. roam/languages/__init__.py +21 -0
  203. roam/languages/apex_lang.py +241 -0
  204. roam/languages/aura_lang.py +228 -0
  205. roam/languages/base.py +111 -0
  206. roam/languages/c_lang.py +458 -0
  207. roam/languages/csharp_lang.py +1215 -0
  208. roam/languages/foxpro_lang.py +1554 -0
  209. roam/languages/generic_lang.py +702 -0
  210. roam/languages/go_lang.py +392 -0
  211. roam/languages/hcl_lang.py +398 -0
  212. roam/languages/java_lang.py +418 -0
  213. roam/languages/javascript_lang.py +799 -0
  214. roam/languages/kotlin_lang.py +147 -0
  215. roam/languages/objc_lang.py +401 -0
  216. roam/languages/php_lang.py +696 -0
  217. roam/languages/python_lang.py +850 -0
  218. roam/languages/registry.py +283 -0
  219. roam/languages/ruby_lang.py +429 -0
  220. roam/languages/rust_lang.py +545 -0
  221. roam/languages/sfxml_lang.py +276 -0
  222. roam/languages/swift_lang.py +173 -0
  223. roam/languages/typescript_lang.py +323 -0
  224. roam/languages/visualforce_lang.py +151 -0
  225. roam/languages/yaml_lang.py +566 -0
  226. roam/mcp_server.py +4794 -0
  227. roam/output/__init__.py +0 -0
  228. roam/output/formatter.py +557 -0
  229. roam/output/mermaid.py +62 -0
  230. roam/output/sarif.py +897 -0
  231. roam/output/schema_registry.py +57 -0
  232. roam/plugins.py +208 -0
  233. roam/refactor/__init__.py +0 -0
  234. roam/refactor/codegen.py +106 -0
  235. roam/refactor/transforms.py +711 -0
  236. roam/rules/__init__.py +0 -0
  237. roam/rules/ast_match.py +238 -0
  238. roam/rules/builtin.py +617 -0
  239. roam/rules/dataflow.py +515 -0
  240. roam/rules/engine.py +943 -0
  241. roam/runtime/__init__.py +3 -0
  242. roam/runtime/hotspots.py +138 -0
  243. roam/runtime/trace_ingest.py +535 -0
  244. roam/search/__init__.py +1 -0
  245. roam/search/framework_packs.py +673 -0
  246. roam/search/index_embeddings.py +732 -0
  247. roam/search/onnx_embeddings.py +233 -0
  248. roam/search/tfidf.py +355 -0
  249. roam/security/__init__.py +1 -0
  250. roam/security/vuln_reach.py +246 -0
  251. roam/security/vuln_store.py +334 -0
  252. roam/surface_counts.py +158 -0
  253. roam/workspace/__init__.py +3 -0
  254. roam/workspace/aggregator.py +426 -0
  255. roam/workspace/api_scanner.py +538 -0
  256. roam/workspace/config.py +95 -0
  257. roam/workspace/db.py +136 -0
@@ -0,0 +1,352 @@
1
+ """Protobuf cross-language bridge: .proto -> generated stubs.
2
+
3
+ Resolves cross-references between Protocol Buffer definitions and their
4
+ generated code in various languages:
5
+ - Python: *_pb2.py modules with classes matching message/service names
6
+ - Go: *.pb.go files with CamelCase struct names
7
+ - Java: OuterClass.MessageName pattern in *OuterClass.java
8
+ - C++: *.pb.h / *.pb.cc with namespace::MessageName
9
+ - TypeScript/JavaScript: *_pb.ts / *_pb.js
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import os
15
+ import re
16
+
17
+ from roam.bridges.base import LanguageBridge
18
+ from roam.bridges.registry import register_bridge
19
+
20
+ # Proto source extension
21
+ _PROTO_EXT = frozenset({".proto"})
22
+
23
+ # Generated stub file patterns by language
24
+ _GENERATED_PATTERNS: dict[str, re.Pattern] = {
25
+ "python": re.compile(r"_pb2\.pyi?$"),
26
+ "go": re.compile(r"\.pb\.go$"),
27
+ "java": re.compile(r"(?:OuterClass|Grpc|Proto)\.java$"),
28
+ "cpp_header": re.compile(r"\.pb\.h$"),
29
+ "cpp_source": re.compile(r"\.pb\.cc$"),
30
+ "typescript": re.compile(r"_pb\.(ts|d\.ts)$"),
31
+ "javascript": re.compile(r"_pb\.js$"),
32
+ "csharp": re.compile(r"\.g\.cs$"),
33
+ "ruby": re.compile(r"_pb\.rb$"),
34
+ }
35
+
36
+ # All target extensions that could be generated from .proto
37
+ _TARGET_EXTS = frozenset(
38
+ {
39
+ ".py",
40
+ ".pyi",
41
+ ".go",
42
+ ".java",
43
+ ".h",
44
+ ".cc",
45
+ ".cpp",
46
+ ".ts",
47
+ ".js",
48
+ ".cs",
49
+ ".rb",
50
+ }
51
+ )
52
+
53
+ # Pattern to extract package from proto file symbols
54
+ _PROTO_PACKAGE_RE = re.compile(r"package\s+([\w.]+)")
55
+
56
+
57
+ class ProtobufBridge(LanguageBridge):
58
+ """Bridge between .proto definitions and generated language stubs."""
59
+
60
+ @property
61
+ def name(self) -> str:
62
+ return "protobuf"
63
+
64
+ @property
65
+ def source_extensions(self) -> frozenset[str]:
66
+ return _PROTO_EXT
67
+
68
+ @property
69
+ def target_extensions(self) -> frozenset[str]:
70
+ return _TARGET_EXTS
71
+
72
+ def detect(self, file_paths: list[str]) -> bool:
73
+ """Detect if project has .proto files and potential generated stubs."""
74
+ has_proto = False
75
+ has_generated = False
76
+ for fp in file_paths:
77
+ ext = os.path.splitext(fp)[1].lower()
78
+ if ext == ".proto":
79
+ has_proto = True
80
+ # Check for generated stub patterns
81
+ basename = os.path.basename(fp)
82
+ for pattern in _GENERATED_PATTERNS.values():
83
+ if pattern.search(basename):
84
+ has_generated = True
85
+ break
86
+ if has_proto and has_generated:
87
+ return True
88
+ return False
89
+
90
+ def resolve(self, source_path: str, source_symbols: list[dict], target_files: dict[str, list[dict]]) -> list[dict]:
91
+ """Resolve .proto symbols to their generated stubs.
92
+
93
+ Resolution strategies:
94
+ 1. File naming: foo.proto -> foo_pb2.py, foo.pb.go, etc.
95
+ 2. Symbol naming: message MyMessage -> class MyMessage (Python),
96
+ struct MyMessage (Go), MyMessage (Java inner class)
97
+ 3. Service naming: service MyService -> MyServiceClient, MyServiceServer
98
+ """
99
+ edges: list[dict] = []
100
+ source_ext = os.path.splitext(source_path)[1].lower()
101
+
102
+ if source_ext != ".proto":
103
+ return edges
104
+
105
+ # Get the proto file stem (e.g., "foo" from "foo.proto")
106
+ proto_stem = os.path.basename(source_path).rsplit(".", 1)[0]
107
+
108
+ # Classify source symbols into messages, services, enums
109
+ messages = []
110
+ services = []
111
+ enums = []
112
+ for sym in source_symbols:
113
+ kind = sym.get("kind", "")
114
+ if kind in ("message", "class", "struct"):
115
+ messages.append(sym)
116
+ elif kind in ("service", "interface"):
117
+ services.append(sym)
118
+ elif kind == "enum":
119
+ enums.append(sym)
120
+
121
+ # Find generated target files that correspond to this proto
122
+ generated_targets = self._find_generated_files(proto_stem, target_files)
123
+
124
+ # For each generated file, try to match symbols
125
+ for tpath, tsymbols, lang in generated_targets:
126
+ target_symbol_names = {sym.get("name", ""): sym.get("qualified_name", "") for sym in tsymbols}
127
+
128
+ # Match message symbols
129
+ for msg in messages:
130
+ msg_name = msg.get("name", "")
131
+ msg_qname = msg.get("qualified_name", msg_name)
132
+ matched = self._match_message(msg_name, target_symbol_names, lang)
133
+ for target_qname in matched:
134
+ edges.append(
135
+ {
136
+ "source": msg_qname,
137
+ "target": target_qname,
138
+ "kind": "x-lang",
139
+ "bridge": self.name,
140
+ "mechanism": "proto-message",
141
+ "target_lang": lang,
142
+ }
143
+ )
144
+
145
+ # Match service symbols
146
+ for svc in services:
147
+ svc_name = svc.get("name", "")
148
+ svc_qname = svc.get("qualified_name", svc_name)
149
+ matched = self._match_service(svc_name, target_symbol_names, lang)
150
+ for target_qname in matched:
151
+ edges.append(
152
+ {
153
+ "source": svc_qname,
154
+ "target": target_qname,
155
+ "kind": "x-lang",
156
+ "bridge": self.name,
157
+ "mechanism": "proto-service",
158
+ "target_lang": lang,
159
+ }
160
+ )
161
+
162
+ # Match enum symbols
163
+ for enum in enums:
164
+ enum_name = enum.get("name", "")
165
+ enum_qname = enum.get("qualified_name", enum_name)
166
+ matched = self._match_enum(enum_name, target_symbol_names, lang)
167
+ for target_qname in matched:
168
+ edges.append(
169
+ {
170
+ "source": enum_qname,
171
+ "target": target_qname,
172
+ "kind": "x-lang",
173
+ "bridge": self.name,
174
+ "mechanism": "proto-enum",
175
+ "target_lang": lang,
176
+ }
177
+ )
178
+
179
+ return edges
180
+
181
+ def _find_generated_files(
182
+ self, proto_stem: str, target_files: dict[str, list[dict]]
183
+ ) -> list[tuple[str, list[dict], str]]:
184
+ """Find target files that were likely generated from this proto.
185
+
186
+ Returns list of (path, symbols, language) tuples.
187
+ """
188
+ results = []
189
+ proto_lower = proto_stem.lower()
190
+
191
+ for tpath, tsymbols in target_files.items():
192
+ basename = os.path.basename(tpath).lower()
193
+
194
+ # Check each language pattern
195
+ for lang, pattern in _GENERATED_PATTERNS.items():
196
+ if pattern.search(basename):
197
+ # Verify the stem matches the proto file
198
+ # e.g., "foo_pb2.py" stem is "foo", "foo.pb.go" stem is "foo"
199
+ generated_stem = self._extract_stem(basename, lang)
200
+ if generated_stem and generated_stem == proto_lower:
201
+ results.append((tpath, tsymbols, lang))
202
+ break # Only match one language per file
203
+
204
+ return results
205
+
206
+ def _extract_stem(self, basename: str, lang: str) -> str | None:
207
+ """Extract the original proto stem from a generated filename.
208
+
209
+ E.g., "foo_pb2.py" -> "foo", "foo.pb.go" -> "foo"
210
+ """
211
+ lower = basename.lower()
212
+ if lang == "python":
213
+ # foo_pb2.py or foo_pb2.pyi
214
+ m = re.match(r"^(.+)_pb2\.pyi?$", lower)
215
+ return m.group(1) if m else None
216
+ elif lang == "go":
217
+ # foo.pb.go
218
+ m = re.match(r"^(.+)\.pb\.go$", lower)
219
+ return m.group(1) if m else None
220
+ elif lang == "java":
221
+ # FooOuterClass.java or FooGrpc.java or FooProto.java
222
+ m = re.match(r"^(.+?)(?:outerclass|grpc|proto)\.java$", lower)
223
+ return m.group(1) if m else None
224
+ elif lang in ("cpp_header", "cpp_source"):
225
+ # foo.pb.h or foo.pb.cc
226
+ m = re.match(r"^(.+)\.pb\.(?:h|cc)$", lower)
227
+ return m.group(1) if m else None
228
+ elif lang == "typescript":
229
+ # foo_pb.ts or foo_pb.d.ts
230
+ m = re.match(r"^(.+)_pb\.(?:d\.)?ts$", lower)
231
+ return m.group(1) if m else None
232
+ elif lang == "javascript":
233
+ # foo_pb.js
234
+ m = re.match(r"^(.+)_pb\.js$", lower)
235
+ return m.group(1) if m else None
236
+ elif lang == "csharp":
237
+ # Foo.g.cs
238
+ m = re.match(r"^(.+)\.g\.cs$", lower)
239
+ return m.group(1) if m else None
240
+ elif lang == "ruby":
241
+ # foo_pb.rb
242
+ m = re.match(r"^(.+)_pb\.rb$", lower)
243
+ return m.group(1) if m else None
244
+ return None
245
+
246
+ def _match_message(self, msg_name: str, target_names: dict[str, str], lang: str) -> list[str]:
247
+ """Match a proto message name to generated symbols.
248
+
249
+ Naming conventions vary by language:
250
+ - Python: class MyMessage in *_pb2.py (exact name)
251
+ - Go: struct MyMessage in *.pb.go (CamelCase preserved)
252
+ - Java: inner class MyMessage inside OuterClass
253
+ - C++: class MyMessage in namespace
254
+ """
255
+ matched = []
256
+ msg_lower = msg_name.lower()
257
+
258
+ for sym_name, sym_qname in target_names.items():
259
+ sym_lower = sym_name.lower()
260
+
261
+ # Exact match (most common for Python, Go, C++)
262
+ if sym_lower == msg_lower:
263
+ matched.append(sym_qname)
264
+ continue
265
+
266
+ # Go: proto snake_case -> CamelCase
267
+ # e.g., my_message -> MyMessage
268
+ if lang == "go" and self._snake_to_camel(msg_name).lower() == sym_lower:
269
+ matched.append(sym_qname)
270
+ continue
271
+
272
+ # Java: OuterClass.MessageName pattern
273
+ if lang == "java" and sym_lower.endswith("." + msg_lower):
274
+ matched.append(sym_qname)
275
+ continue
276
+
277
+ return matched
278
+
279
+ def _match_service(self, svc_name: str, target_names: dict[str, str], lang: str) -> list[str]:
280
+ """Match a proto service name to generated symbols.
281
+
282
+ Generated service stubs commonly use suffixes:
283
+ - Python: MyServiceStub, MyServiceServicer
284
+ - Go: MyServiceClient, MyServiceServer
285
+ - Java: MyServiceGrpc, MyServiceBlockingStub
286
+ """
287
+ matched = []
288
+ svc_lower = svc_name.lower()
289
+
290
+ # Common generated suffixes for service stubs
291
+ suffixes = [
292
+ "", # exact match
293
+ "client",
294
+ "server",
295
+ "stub",
296
+ "servicer",
297
+ "grpc",
298
+ "blockingstub",
299
+ "futurestub",
300
+ "implbase",
301
+ ]
302
+
303
+ for sym_name, sym_qname in target_names.items():
304
+ sym_lower = sym_name.lower()
305
+ for suffix in suffixes:
306
+ if sym_lower == svc_lower + suffix:
307
+ matched.append(sym_qname)
308
+ break
309
+ # Also check with underscore separator (Python style)
310
+ if suffix and sym_lower == svc_lower + "_" + suffix:
311
+ matched.append(sym_qname)
312
+ break
313
+
314
+ return matched
315
+
316
+ def _match_enum(self, enum_name: str, target_names: dict[str, str], lang: str) -> list[str]:
317
+ """Match a proto enum name to generated symbols.
318
+
319
+ Enums generally keep their name across languages.
320
+ """
321
+ matched = []
322
+ enum_lower = enum_name.lower()
323
+
324
+ for sym_name, sym_qname in target_names.items():
325
+ sym_lower = sym_name.lower()
326
+
327
+ # Exact match
328
+ if sym_lower == enum_lower:
329
+ matched.append(sym_qname)
330
+ continue
331
+
332
+ # Go CamelCase conversion
333
+ if lang == "go" and self._snake_to_camel(enum_name).lower() == sym_lower:
334
+ matched.append(sym_qname)
335
+ continue
336
+
337
+ return matched
338
+
339
+ def _snake_to_camel(self, name: str) -> str:
340
+ """Convert snake_case to CamelCase.
341
+
342
+ E.g., my_message -> MyMessage, already_camel -> AlreadyCamel
343
+ """
344
+ if "_" not in name:
345
+ # Already CamelCase or single word; just capitalize first letter
346
+ return name[0].upper() + name[1:] if name else name
347
+ parts = name.split("_")
348
+ return "".join(p.capitalize() for p in parts if p)
349
+
350
+
351
+ # Auto-register on import
352
+ register_bridge(ProtobufBridge())
@@ -0,0 +1,242 @@
1
+ """REST API cross-language bridge: frontend HTTP calls <-> backend route definitions.
2
+
3
+ Resolves cross-references between:
4
+ - Frontend fetch/axios/jQuery calls to API endpoints
5
+ - Backend route definitions in Flask, Express, Go net/http, Spring Boot, etc.
6
+ - Python HTTP client calls (requests, httpx) to backend routes
7
+
8
+ Spring Boot support: class-level @RequestMapping prefix is concatenated with
9
+ method-level @GetMapping/@PostMapping/@PutMapping/@PatchMapping/@DeleteMapping
10
+ routes (e.g. @RequestMapping("/api/v1") + @GetMapping("/users") -> /api/v1/users).
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import os
16
+ import re
17
+
18
+ from roam.bridges.base import LanguageBridge
19
+ from roam.bridges.registry import register_bridge
20
+
21
+ # Frontend extensions that may contain HTTP calls
22
+ _FRONTEND_EXTS = frozenset({".js", ".ts", ".jsx", ".tsx"})
23
+
24
+ # Backend extensions that may contain route definitions
25
+ _BACKEND_EXTS = frozenset({".py", ".go", ".java", ".rb", ".js", ".ts"})
26
+
27
+ # All extensions this bridge cares about (union)
28
+ _ALL_SOURCE_EXTS = _FRONTEND_EXTS
29
+ _ALL_TARGET_EXTS = _BACKEND_EXTS
30
+
31
+ # --- Frontend URL extraction patterns ---
32
+
33
+ # fetch('/api/users') or fetch("/api/users")
34
+ _FETCH_RE = re.compile(
35
+ r"""fetch\s*\(\s*['"](/[^'"]+)['"]""",
36
+ )
37
+
38
+ # axios.get('/api/users'), axios.post('/api/orders'), etc.
39
+ _AXIOS_RE = re.compile(
40
+ r"""axios\s*\.\s*(?:get|post|put|patch|delete|head|options)\s*\(\s*['"](/[^'"]+)['"]""",
41
+ re.IGNORECASE,
42
+ )
43
+
44
+ # $.ajax({url: '/api/...'}) or $.get('/api/...') or $.post('/api/...')
45
+ _JQUERY_RE = re.compile(
46
+ r"""\$\s*\.\s*(?:ajax|get|post|put|delete)\s*\(\s*(?:\{\s*url\s*:\s*)?['"](/[^'"]+)['"]""",
47
+ re.IGNORECASE,
48
+ )
49
+
50
+ # Python: requests.get('/api/users'), httpx.get(...)
51
+ _PY_HTTP_RE = re.compile(
52
+ r"""(?:requests|httpx|urllib\.request)\s*\.\s*(?:get|post|put|patch|delete|head|options|urlopen)\s*\(\s*['"](/[^'"]+)['"]""",
53
+ re.IGNORECASE,
54
+ )
55
+
56
+ # --- Backend route definition patterns ---
57
+
58
+ # Python/Flask/FastAPI: @app.route('/api/users'), @router.get('/api/users')
59
+ _PY_ROUTE_RE = re.compile(
60
+ r"""@\s*(?:\w+)\s*\.\s*(?:route|get|post|put|patch|delete|head|options|api_view)\s*\(\s*['"](/[^'"]+)['"]""",
61
+ )
62
+
63
+ # Express: app.get('/api/users', ...), router.post('/api/orders', ...)
64
+ _EXPRESS_RE = re.compile(
65
+ r"""(?:app|router|server)\s*\.\s*(?:get|post|put|patch|delete|head|options|all|use)\s*\(\s*['"](/[^'"]+)['"]""",
66
+ )
67
+
68
+ # Go: http.HandleFunc("/api/users", ...), r.GET("/api/users", ...)
69
+ _GO_ROUTE_RE = re.compile(
70
+ r"""(?:HandleFunc|Handle|GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|Group|Any)\s*\(\s*["'](/[^"']+)["']""",
71
+ )
72
+
73
+ # Java Spring: @GetMapping("/api/users"), @RequestMapping("/api/users"),
74
+ # @RequestMapping(value = "/api"), @GetMapping("users") (no leading /)
75
+ _JAVA_ROUTE_RE = re.compile(
76
+ r"""@\s*(?:GetMapping|PostMapping|PutMapping|PatchMapping|DeleteMapping|RequestMapping)\s*\(\s*(?:value\s*=\s*|path\s*=\s*)?["'](/?\w[^"']*)["']""",
77
+ )
78
+
79
+ # Ruby/Rails: get '/api/users', post '/api/orders'
80
+ _RUBY_ROUTE_RE = re.compile(
81
+ r"""(?:get|post|put|patch|delete|match)\s+['"](/[^'"]+)['"]""",
82
+ )
83
+
84
+
85
+ class RestApiBridge(LanguageBridge):
86
+ """Bridge between frontend HTTP calls and backend route definitions."""
87
+
88
+ @property
89
+ def name(self) -> str:
90
+ return "rest-api"
91
+
92
+ @property
93
+ def source_extensions(self) -> frozenset[str]:
94
+ return _ALL_SOURCE_EXTS
95
+
96
+ @property
97
+ def target_extensions(self) -> frozenset[str]:
98
+ return _ALL_TARGET_EXTS
99
+
100
+ def detect(self, file_paths: list[str]) -> bool:
101
+ """Detect if project has both frontend and backend files."""
102
+ has_frontend = False
103
+ has_backend = False
104
+ for fp in file_paths:
105
+ ext = os.path.splitext(fp)[1].lower()
106
+ if ext in _FRONTEND_EXTS:
107
+ has_frontend = True
108
+ if ext in {".py", ".go", ".java", ".rb"}:
109
+ has_backend = True
110
+ if has_frontend and has_backend:
111
+ return True
112
+ return False
113
+
114
+ def resolve(self, source_path: str, source_symbols: list[dict], target_files: dict[str, list[dict]]) -> list[dict]:
115
+ """Resolve frontend HTTP calls to backend route definitions.
116
+
117
+ This bridge works differently from symbol-based bridges:
118
+ it scans file contents (via symbol signatures/docstrings or raw names)
119
+ to find URL patterns, then matches them across languages.
120
+
121
+ For simplicity with the existing bridge interface (which provides symbols,
122
+ not raw file content), we extract URL-like strings from symbol names,
123
+ signatures, and qualified names.
124
+ """
125
+ edges: list[dict] = []
126
+
127
+ # Extract URLs from source symbols (frontend calls)
128
+ source_urls = self._extract_urls_from_symbols(source_symbols, mode="client")
129
+
130
+ if not source_urls:
131
+ return edges
132
+
133
+ # Extract route definitions from target files
134
+ for tpath, tsymbols in target_files.items():
135
+ target_urls = self._extract_urls_from_symbols(tsymbols, mode="server")
136
+ if not target_urls:
137
+ continue
138
+
139
+ # Match URLs
140
+ for src_url, src_sym_name in source_urls:
141
+ for tgt_url, tgt_sym_name in target_urls:
142
+ if self._urls_match(src_url, tgt_url):
143
+ edges.append(
144
+ {
145
+ "source": src_sym_name,
146
+ "target": tgt_sym_name,
147
+ "kind": "x-lang",
148
+ "bridge": self.name,
149
+ "mechanism": "url-match",
150
+ "url": src_url,
151
+ "confidence": 0.8,
152
+ }
153
+ )
154
+
155
+ return edges
156
+
157
+ def _extract_urls_from_symbols(self, symbols: list[dict], mode: str) -> list[tuple[str, str]]:
158
+ """Extract URL strings from symbol metadata.
159
+
160
+ Returns list of (url, symbol_qualified_name) tuples.
161
+
162
+ For Spring Boot, handles class-level @RequestMapping prefix
163
+ concatenation with method-level @GetMapping/@PostMapping etc.
164
+ """
165
+ results: list[tuple[str, str]] = []
166
+
167
+ # First pass: collect class-level route prefixes (Spring Boot pattern)
168
+ class_prefixes: dict[str, str] = {}
169
+ if mode == "server":
170
+ for sym in symbols:
171
+ kind = sym.get("kind", "")
172
+ if kind != "class":
173
+ continue
174
+ sig = sym.get("signature", "") or ""
175
+ qname = sym.get("qualified_name", sym.get("name", ""))
176
+ for m in _JAVA_ROUTE_RE.finditer(sig):
177
+ class_prefixes[qname] = m.group(1).rstrip("/")
178
+ break
179
+
180
+ for sym in symbols:
181
+ name = sym.get("name", "")
182
+ qname = sym.get("qualified_name", name)
183
+ sig = sym.get("signature", "") or ""
184
+ doc = sym.get("docstring", "") or ""
185
+
186
+ # Combine all text fields for scanning
187
+ text = f"{name} {sig} {doc}"
188
+
189
+ urls: list[str] = []
190
+ if mode == "client":
191
+ urls.extend(m.group(1) for m in _FETCH_RE.finditer(text))
192
+ urls.extend(m.group(1) for m in _AXIOS_RE.finditer(text))
193
+ urls.extend(m.group(1) for m in _JQUERY_RE.finditer(text))
194
+ urls.extend(m.group(1) for m in _PY_HTTP_RE.finditer(text))
195
+ else:
196
+ urls.extend(m.group(1) for m in _PY_ROUTE_RE.finditer(text))
197
+ urls.extend(m.group(1) for m in _EXPRESS_RE.finditer(text))
198
+ urls.extend(m.group(1) for m in _GO_ROUTE_RE.finditer(text))
199
+ urls.extend(m.group(1) for m in _JAVA_ROUTE_RE.finditer(text))
200
+ urls.extend(m.group(1) for m in _RUBY_ROUTE_RE.finditer(text))
201
+
202
+ # Spring Boot: prepend class-level prefix to method routes
203
+ kind = sym.get("kind", "")
204
+ if kind == "method" and class_prefixes:
205
+ parent = sym.get("parent", "")
206
+ prefix = class_prefixes.get(parent, "")
207
+ if prefix:
208
+ urls = [prefix + u if not u.startswith(prefix) else u for u in urls]
209
+
210
+ for url in urls:
211
+ results.append((url, qname))
212
+
213
+ return results
214
+
215
+ def _urls_match(self, client_url: str, server_url: str) -> bool:
216
+ """Check if a client URL matches a server route.
217
+
218
+ Supports exact match and parameterized routes:
219
+ - /api/users matches /api/users
220
+ - /api/users/123 matches /api/users/<id> or /api/users/:id or /api/users/{id}
221
+ """
222
+ if client_url == server_url:
223
+ return True
224
+
225
+ # Normalize: strip trailing slashes
226
+ c = client_url.rstrip("/")
227
+ s = server_url.rstrip("/")
228
+ if c == s:
229
+ return True
230
+
231
+ # Check prefix match for parameterized routes
232
+ # Convert server route params to regex
233
+ # :param, <param>, {param} -> wildcard
234
+ param_re = re.sub(r"[:<{]\w+[>}]?", r"[^/]+", s)
235
+ if re.fullmatch(param_re, c):
236
+ return True
237
+
238
+ return False
239
+
240
+
241
+ # Auto-register on import
242
+ register_bridge(RestApiBridge())