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,198 @@
1
+ """Salesforce cross-language bridge: Apex <-> Aura/LWC/Visualforce.
2
+
3
+ Resolves cross-references between:
4
+ - Apex controllers (.cls) and Aura components (.cmp, .app)
5
+ - Apex controllers (.cls) and Visualforce pages (.page, .component)
6
+ - @AuraEnabled methods in Apex and Lightning component calls
7
+ - Apex classes referenced via controller="" attributes in markup
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import os
13
+ import re
14
+
15
+ from roam.bridges.base import LanguageBridge
16
+ from roam.bridges.registry import register_bridge
17
+
18
+ # Pattern to detect @AuraEnabled annotation on symbols
19
+ _AURA_ENABLED_RE = re.compile(r"@AuraEnabled", re.IGNORECASE)
20
+
21
+ # Apex source extensions
22
+ _APEX_EXTS = frozenset({".cls", ".trigger"})
23
+
24
+ # Aura/LWC/Visualforce target extensions
25
+ _SF_MARKUP_EXTS = frozenset({".cmp", ".app", ".evt", ".intf", ".page", ".component"})
26
+
27
+
28
+ class SalesforceBridge(LanguageBridge):
29
+ """Bridge between Apex controllers and Aura/LWC/Visualforce templates."""
30
+
31
+ @property
32
+ def name(self) -> str:
33
+ return "salesforce"
34
+
35
+ @property
36
+ def source_extensions(self) -> frozenset[str]:
37
+ return _APEX_EXTS
38
+
39
+ @property
40
+ def target_extensions(self) -> frozenset[str]:
41
+ return _SF_MARKUP_EXTS
42
+
43
+ def detect(self, file_paths: list[str]) -> bool:
44
+ """Detect if project has both Apex and markup files."""
45
+ has_apex = False
46
+ has_markup = False
47
+ for fp in file_paths:
48
+ ext = os.path.splitext(fp)[1].lower()
49
+ if ext in _APEX_EXTS:
50
+ has_apex = True
51
+ if ext in _SF_MARKUP_EXTS:
52
+ has_markup = True
53
+ if has_apex and has_markup:
54
+ return True
55
+ return False
56
+
57
+ def resolve(self, source_path: str, source_symbols: list[dict], target_files: dict[str, list[dict]]) -> list[dict]:
58
+ """Resolve Apex-to-markup cross-language links.
59
+
60
+ Resolution strategies:
61
+ 1. Naming convention: MyController.cls -> MyController.cmp
62
+ 2. Controller attribute: <aura:component controller="MyController">
63
+ 3. @AuraEnabled methods: match to components referencing that controller
64
+ """
65
+ edges: list[dict] = []
66
+ source_ext = os.path.splitext(source_path)[1].lower()
67
+
68
+ if source_ext not in _APEX_EXTS:
69
+ return edges
70
+
71
+ # Get the Apex class name from the file path
72
+ apex_class_name = os.path.basename(source_path).rsplit(".", 1)[0]
73
+
74
+ # Build a lookup of target symbols by qualified name for fast matching
75
+ target_symbol_index: dict[str, str] = {} # symbol_name -> qualified_name
76
+ # Track which target files reference this Apex class as a controller
77
+ controller_targets: list[tuple[str, list[dict]]] = []
78
+
79
+ for tpath, tsymbols in target_files.items():
80
+ text_ext = os.path.splitext(tpath)[1].lower()
81
+ if text_ext not in _SF_MARKUP_EXTS:
82
+ continue
83
+
84
+ for sym in tsymbols:
85
+ target_symbol_index[sym.get("name", "")] = sym.get("qualified_name", "")
86
+
87
+ # Check if any target symbol references this Apex class
88
+ # Aura components reference controllers via naming convention or
89
+ # controller attribute (already extracted as references by AuraExtractor)
90
+ target_basename = os.path.basename(tpath).rsplit(".", 1)[0]
91
+
92
+ # Strategy 1: Naming convention match
93
+ # MyController.cls -> MyController.cmp (same name)
94
+ # MyController.cls -> MyControllerCmp.cmp (with suffix)
95
+ if self._names_match(apex_class_name, target_basename):
96
+ controller_targets.append((tpath, tsymbols))
97
+ # Create edge from Apex class to the component
98
+ edges.append(
99
+ {
100
+ "source": apex_class_name,
101
+ "target": target_basename,
102
+ "kind": "x-lang",
103
+ "bridge": self.name,
104
+ "mechanism": "naming-convention",
105
+ }
106
+ )
107
+
108
+ # Strategy 2: Match @AuraEnabled methods to components that reference
109
+ # this controller. Any component whose controller is this Apex class
110
+ # can call its @AuraEnabled methods.
111
+ aura_enabled_methods = self._find_aura_enabled_methods(source_symbols)
112
+
113
+ for method_name, method_qname in aura_enabled_methods:
114
+ for tpath, tsymbols in controller_targets:
115
+ target_basename = os.path.basename(tpath).rsplit(".", 1)[0]
116
+ edges.append(
117
+ {
118
+ "source": method_qname,
119
+ "target": target_basename,
120
+ "kind": "x-lang",
121
+ "bridge": self.name,
122
+ "mechanism": "aura-enabled",
123
+ }
124
+ )
125
+
126
+ # Strategy 3: Check for Visualforce controller references
127
+ # Visualforce pages specify controller="ClassName" in <apex:page>
128
+ # The VF extractor already extracts these as "controller" references,
129
+ # but we create x-lang edges for them here
130
+ for tpath, tsymbols in target_files.items():
131
+ text_ext = os.path.splitext(tpath)[1].lower()
132
+ if text_ext not in (".page", ".component"):
133
+ continue
134
+ target_basename = os.path.basename(tpath).rsplit(".", 1)[0]
135
+ # Check if any symbol in the target references this Apex class
136
+ # We look for the component-level symbol whose name matches
137
+ for sym in tsymbols:
138
+ # Visualforce pages are top-level symbols of kind "page"/"component"
139
+ if sym.get("kind") in ("page", "component"):
140
+ # The VF extractor creates controller references; check if
141
+ # this Apex class is referenced by name in the target path
142
+ # (We rely on naming convention or explicit controller attr)
143
+ if self._names_match(apex_class_name, target_basename):
144
+ # Already handled by strategy 1 above; skip duplicate
145
+ pass
146
+
147
+ return edges
148
+
149
+ def _names_match(self, apex_name: str, target_name: str) -> bool:
150
+ """Check if an Apex class name matches a component name.
151
+
152
+ Supports common Salesforce naming conventions:
153
+ - Exact match: MyController -> MyController
154
+ - Controller suffix: MyController -> My (component uses class as controller)
155
+ - Component suffix: MyClass -> MyClassController (Apex has Controller suffix)
156
+ """
157
+ apex_lower = apex_name.lower()
158
+ target_lower = target_name.lower()
159
+
160
+ # Exact match
161
+ if apex_lower == target_lower:
162
+ return True
163
+
164
+ # Apex name is target + "Controller" suffix
165
+ # e.g., MyComponentController.cls -> MyComponent.cmp
166
+ if apex_lower == target_lower + "controller":
167
+ return True
168
+
169
+ # Target name is apex + "Controller" suffix (less common but possible)
170
+ if target_lower == apex_lower + "controller":
171
+ return True
172
+
173
+ return False
174
+
175
+ def _find_aura_enabled_methods(self, symbols: list[dict]) -> list[tuple[str, str]]:
176
+ """Find methods with @AuraEnabled annotation.
177
+
178
+ Returns list of (method_name, qualified_name) tuples.
179
+ """
180
+ results = []
181
+ for sym in symbols:
182
+ kind = sym.get("kind", "")
183
+ if kind not in ("method", "function"):
184
+ continue
185
+ sig = sym.get("signature", "") or ""
186
+ # Check if the signature or annotations contain @AuraEnabled
187
+ if _AURA_ENABLED_RE.search(sig):
188
+ results.append((sym.get("name", ""), sym.get("qualified_name", "")))
189
+ continue
190
+ # Also check docstring/annotations if stored there
191
+ doc = sym.get("docstring", "") or ""
192
+ if _AURA_ENABLED_RE.search(doc):
193
+ results.append((sym.get("name", ""), sym.get("qualified_name", "")))
194
+ return results
195
+
196
+
197
+ # Auto-register on import
198
+ register_bridge(SalesforceBridge())
@@ -0,0 +1,247 @@
1
+ """Template engine cross-language bridge: templates <-> host language symbols.
2
+
3
+ Resolves cross-references between:
4
+ - Jinja2/Django templates and Python view functions
5
+ - ERB templates and Ruby controllers
6
+ - Handlebars templates and JavaScript/TypeScript code
7
+ - Template variable references ({{ var }}) to context dict keys
8
+ - Template includes/extends to other template files
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import os
14
+ import re
15
+
16
+ from roam.bridges.base import LanguageBridge
17
+ from roam.bridges.registry import register_bridge
18
+
19
+ # Template file extensions
20
+ _TEMPLATE_EXTS = frozenset({".html", ".jinja2", ".jinja", ".j2", ".erb", ".hbs", ".mustache"})
21
+
22
+ # Host language extensions that render templates
23
+ _HOST_EXTS = frozenset({".py", ".rb", ".js", ".ts", ".jsx", ".tsx"})
24
+
25
+ # --- Template variable extraction patterns ---
26
+
27
+ # Jinja2/Django: {{ user.name }}, {{ items }}, {% extends "base.html" %}, {% include "header.html" %}
28
+ _JINJA_VAR_RE = re.compile(r"\{\{\s*(\w+)(?:\.\w+)*\s*\}\}")
29
+ _JINJA_EXTENDS_RE = re.compile(r'\{%\s*extends\s+["\']([^"\']+)["\']\s*%\}')
30
+ _JINJA_INCLUDE_RE = re.compile(r'\{%\s*include\s+["\']([^"\']+)["\']\s*%\}')
31
+
32
+ # ERB: <%= @user.name %>, <%= render partial: "header" %>
33
+ _ERB_VAR_RE = re.compile(r"<%=?\s*@?(\w+)(?:\.\w+)*\s*%>")
34
+ _ERB_RENDER_RE = re.compile(r'render\s+(?:partial:\s*)?["\']([^"\']+)["\']')
35
+
36
+ # Handlebars: {{user.name}}, {{> header}}, {{#each items}}
37
+ _HBS_VAR_RE = re.compile(r"\{\{(?!>|#|/)(\w+)(?:\.\w+)*\}\}")
38
+ _HBS_PARTIAL_RE = re.compile(r"\{\{>\s*(\w+)\s*\}\}")
39
+
40
+ # --- Host language template rendering patterns ---
41
+
42
+ # Python: render_template('x.html', user=user), render('x.html', context)
43
+ _PY_RENDER_RE = re.compile(
44
+ r"""render(?:_template)?\s*\(\s*['"]([\w./]+\.(?:html|jinja2?|j2))['"]\s*(?:,\s*(.+?))?(?:\)|$)""",
45
+ )
46
+
47
+ # Python keyword args in render_template calls: user=user, items=items
48
+ _PY_KWARG_RE = re.compile(r"(\w+)\s*=")
49
+
50
+ # Express/Handlebars: res.render('template', {user: user})
51
+ _JS_RENDER_RE = re.compile(
52
+ r"""(?:res|response)\s*\.\s*render\s*\(\s*['"]([\w./]+)['"]\s*(?:,\s*(\{[^}]*\}))?""",
53
+ )
54
+
55
+
56
+ class TemplateBridge(LanguageBridge):
57
+ """Bridge between template files and host language code."""
58
+
59
+ @property
60
+ def name(self) -> str:
61
+ return "template"
62
+
63
+ @property
64
+ def source_extensions(self) -> frozenset[str]:
65
+ return _TEMPLATE_EXTS
66
+
67
+ @property
68
+ def target_extensions(self) -> frozenset[str]:
69
+ return _HOST_EXTS
70
+
71
+ def detect(self, file_paths: list[str]) -> bool:
72
+ """Detect if project has template files."""
73
+ for fp in file_paths:
74
+ ext = os.path.splitext(fp)[1].lower()
75
+ if ext in _TEMPLATE_EXTS:
76
+ return True
77
+ return False
78
+
79
+ def resolve(self, source_path: str, source_symbols: list[dict], target_files: dict[str, list[dict]]) -> list[dict]:
80
+ """Resolve template references to host language symbols.
81
+
82
+ Strategies:
83
+ 1. Template filename matching: render_template('users.html') -> users.html
84
+ 2. Variable matching: {{ user }} in template -> user= kwarg in render call
85
+ 3. Template includes: {% include "header.html" %} -> header.html file
86
+ """
87
+ edges: list[dict] = []
88
+ source_ext = os.path.splitext(source_path)[1].lower()
89
+
90
+ if source_ext not in _TEMPLATE_EXTS:
91
+ return edges
92
+
93
+ template_basename = os.path.basename(source_path)
94
+
95
+ # Extract template variables from source symbols
96
+ template_vars = self._extract_template_vars(source_symbols, source_ext)
97
+ template_includes = self._extract_template_includes(source_symbols, source_ext)
98
+
99
+ # Scan host language files for render calls referencing this template
100
+ for tpath, tsymbols in target_files.items():
101
+ text_ext = os.path.splitext(tpath)[1].lower()
102
+ if text_ext not in _HOST_EXTS:
103
+ continue
104
+
105
+ render_info = self._extract_render_calls(tsymbols, text_ext)
106
+
107
+ for render_template_name, context_vars, render_sym_name in render_info:
108
+ # Strategy 1: Template filename match
109
+ if self._template_names_match(template_basename, render_template_name):
110
+ edges.append(
111
+ {
112
+ "source": template_basename,
113
+ "target": render_sym_name,
114
+ "kind": "x-lang",
115
+ "bridge": self.name,
116
+ "mechanism": "template-render",
117
+ "confidence": 0.9,
118
+ }
119
+ )
120
+
121
+ # Strategy 2: Variable matching
122
+ for tvar in template_vars:
123
+ if tvar in context_vars:
124
+ edges.append(
125
+ {
126
+ "source": f"{template_basename}:{tvar}",
127
+ "target": render_sym_name,
128
+ "kind": "x-lang",
129
+ "bridge": self.name,
130
+ "mechanism": "template-var",
131
+ "confidence": 0.7,
132
+ }
133
+ )
134
+
135
+ # Strategy 3: Template includes -> other template files
136
+ for include_name in template_includes:
137
+ for tpath, tsymbols in target_files.items():
138
+ tbasename = os.path.basename(tpath)
139
+ if self._template_names_match(tbasename, include_name):
140
+ edges.append(
141
+ {
142
+ "source": template_basename,
143
+ "target": tbasename,
144
+ "kind": "x-lang",
145
+ "bridge": self.name,
146
+ "mechanism": "template-include",
147
+ "confidence": 0.9,
148
+ }
149
+ )
150
+
151
+ return edges
152
+
153
+ def _extract_template_vars(self, symbols: list[dict], ext: str) -> set[str]:
154
+ """Extract variable names referenced in template symbols."""
155
+ variables: set[str] = set()
156
+ for sym in symbols:
157
+ name = sym.get("name", "")
158
+ sig = sym.get("signature", "") or ""
159
+ doc = sym.get("docstring", "") or ""
160
+ text = f"{name} {sig} {doc}"
161
+
162
+ if ext in (".html", ".jinja2", ".jinja", ".j2"):
163
+ variables.update(m.group(1) for m in _JINJA_VAR_RE.finditer(text))
164
+ elif ext == ".erb":
165
+ variables.update(m.group(1) for m in _ERB_VAR_RE.finditer(text))
166
+ elif ext in (".hbs", ".mustache"):
167
+ variables.update(m.group(1) for m in _HBS_VAR_RE.finditer(text))
168
+
169
+ return variables
170
+
171
+ def _extract_template_includes(self, symbols: list[dict], ext: str) -> set[str]:
172
+ """Extract included/extended template names."""
173
+ includes: set[str] = set()
174
+ for sym in symbols:
175
+ sig = sym.get("signature", "") or ""
176
+ doc = sym.get("docstring", "") or ""
177
+ text = f"{sig} {doc}"
178
+
179
+ if ext in (".html", ".jinja2", ".jinja", ".j2"):
180
+ includes.update(m.group(1) for m in _JINJA_EXTENDS_RE.finditer(text))
181
+ includes.update(m.group(1) for m in _JINJA_INCLUDE_RE.finditer(text))
182
+ elif ext == ".erb":
183
+ includes.update(m.group(1) for m in _ERB_RENDER_RE.finditer(text))
184
+ elif ext in (".hbs", ".mustache"):
185
+ includes.update(m.group(1) for m in _HBS_PARTIAL_RE.finditer(text))
186
+
187
+ return includes
188
+
189
+ def _extract_render_calls(self, symbols: list[dict], ext: str) -> list[tuple[str, set[str], str]]:
190
+ """Extract render_template calls from host language symbols.
191
+
192
+ Returns list of (template_name, context_var_names, symbol_qualified_name).
193
+ """
194
+ results: list[tuple[str, set[str], str]] = []
195
+ for sym in symbols:
196
+ qname = sym.get("qualified_name", sym.get("name", ""))
197
+ sig = sym.get("signature", "") or ""
198
+ doc = sym.get("docstring", "") or ""
199
+ text = f"{sig} {doc}"
200
+
201
+ if ext in (".py",):
202
+ for m in _PY_RENDER_RE.finditer(text):
203
+ tpl_name = m.group(1)
204
+ kwargs_str = m.group(2) or ""
205
+ ctx_vars = set(km.group(1) for km in _PY_KWARG_RE.finditer(kwargs_str))
206
+ results.append((tpl_name, ctx_vars, qname))
207
+ elif ext in (".js", ".ts", ".jsx", ".tsx"):
208
+ for m in _JS_RENDER_RE.finditer(text):
209
+ tpl_name = m.group(1)
210
+ obj_str = m.group(2) or ""
211
+ # Extract keys from {key: val, ...}
212
+ ctx_vars = set(re.findall(r"(\w+)\s*:", obj_str))
213
+ results.append((tpl_name, ctx_vars, qname))
214
+
215
+ return results
216
+
217
+ def _template_names_match(self, template_basename: str, render_name: str) -> bool:
218
+ """Check if a template file matches a render call reference.
219
+
220
+ Handles path variations:
221
+ - Exact: users.html == users.html
222
+ - Path prefix: templates/users.html matches users.html
223
+ - Without extension: users matches users.html
224
+ """
225
+ if template_basename == render_name:
226
+ return True
227
+
228
+ # render_name might include path prefix
229
+ if render_name.endswith(template_basename):
230
+ return True
231
+
232
+ # Match without extension
233
+ t_stem = os.path.splitext(template_basename)[0]
234
+ r_stem = os.path.splitext(render_name)[0]
235
+ if t_stem == r_stem:
236
+ return True
237
+
238
+ # render_name path might end with the template stem
239
+ r_basename = os.path.basename(render_name)
240
+ if r_basename == template_basename:
241
+ return True
242
+
243
+ return False
244
+
245
+
246
+ # Auto-register on import
247
+ register_bridge(TemplateBridge())
@@ -0,0 +1,51 @@
1
+ """Bridge registry -- discovers and manages cross-language bridges."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from roam.bridges.base import LanguageBridge
6
+
7
+ _BRIDGES: list[LanguageBridge] = []
8
+
9
+
10
+ def register_bridge(bridge: LanguageBridge) -> None:
11
+ """Register a bridge instance."""
12
+ _BRIDGES.append(bridge)
13
+
14
+
15
+ def get_bridges() -> list[LanguageBridge]:
16
+ """Return all registered bridges."""
17
+ return list(_BRIDGES)
18
+
19
+
20
+ def detect_bridges(file_paths: list[str]) -> list[LanguageBridge]:
21
+ """Return bridges relevant for the given file set."""
22
+ _auto_discover()
23
+ return [b for b in _BRIDGES if b.detect(file_paths)]
24
+
25
+
26
+ def _auto_discover():
27
+ """Auto-discover built-in bridges on first call."""
28
+ if _BRIDGES:
29
+ return
30
+
31
+ # Import built-in bridges -- each registers itself on import
32
+ try:
33
+ from roam.bridges import bridge_salesforce # noqa: F401
34
+ except ImportError:
35
+ pass
36
+ try:
37
+ from roam.bridges import bridge_protobuf # noqa: F401
38
+ except ImportError:
39
+ pass
40
+ try:
41
+ from roam.bridges import bridge_rest_api # noqa: F401
42
+ except ImportError:
43
+ pass
44
+ try:
45
+ from roam.bridges import bridge_template # noqa: F401
46
+ except ImportError:
47
+ pass
48
+ try:
49
+ from roam.bridges import bridge_config # noqa: F401
50
+ except ImportError:
51
+ pass
File without changes