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,405 @@
1
+ """Show how a set of symbols relate: shared deps, call chains, conflicts."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import click
6
+
7
+ from roam.commands.resolve import ensure_index, find_symbol, symbol_not_found_hint
8
+ from roam.db.connection import open_db
9
+ from roam.output.formatter import json_envelope, to_json
10
+
11
+
12
+ def _resolve_symbols_from_files(conn, file_paths):
13
+ """Resolve all symbol IDs from file paths or directory prefixes."""
14
+ symbol_ids = []
15
+ for fp in file_paths:
16
+ # Normalize path separators
17
+ fp_norm = fp.replace("\\", "/")
18
+ rows = conn.execute(
19
+ "SELECT s.id FROM symbols s JOIN files f ON s.file_id = f.id WHERE f.path LIKE ?",
20
+ (f"%{fp_norm}%",),
21
+ ).fetchall()
22
+ for r in rows:
23
+ symbol_ids.append(r[0])
24
+ return symbol_ids
25
+
26
+
27
+ def _get_symbol_info(conn, node_id):
28
+ """Get name, kind, file_path for a symbol node ID."""
29
+ row = conn.execute(
30
+ "SELECT s.name, s.kind, f.path AS file_path FROM symbols s JOIN files f ON s.file_id = f.id WHERE s.id = ?",
31
+ (node_id,),
32
+ ).fetchone()
33
+ if row:
34
+ return {"name": row["name"], "kind": row["kind"], "file_path": row["file_path"]}
35
+ return None
36
+
37
+
38
+ def _find_shared_dependencies(G, input_ids):
39
+ """Find symbols that multiple input symbols depend on (common targets)."""
40
+ # For each input symbol, find its successors (what it calls/depends on)
41
+ dep_map = {} # target_id -> set of input_ids that depend on it
42
+ for nid in input_ids:
43
+ if nid not in G:
44
+ continue
45
+ for succ in G.successors(nid):
46
+ if succ in input_ids:
47
+ continue # Skip input symbols themselves
48
+ dep_map.setdefault(succ, set()).add(nid)
49
+
50
+ # Keep only those depended on by 2+ input symbols
51
+ shared = {tid: callers for tid, callers in dep_map.items() if len(callers) >= 2}
52
+ return shared
53
+
54
+
55
+ def _find_shared_callers(G, input_ids):
56
+ """Find symbols that call multiple input symbols (common predecessors)."""
57
+ caller_map = {} # caller_id -> set of input_ids it calls
58
+ for nid in input_ids:
59
+ if nid not in G:
60
+ continue
61
+ for pred in G.predecessors(nid):
62
+ if pred in input_ids:
63
+ continue
64
+ caller_map.setdefault(pred, set()).add(nid)
65
+
66
+ shared = {cid: callees for cid, callees in caller_map.items() if len(callees) >= 2}
67
+ return shared
68
+
69
+
70
+ def _compute_distance_matrix(G, input_ids, depth):
71
+ """Compute shortest-path distances between all pairs of input symbols."""
72
+ import networkx as nx
73
+
74
+ undirected = G.to_undirected()
75
+ matrix = {}
76
+ for i, src in enumerate(input_ids):
77
+ for j, tgt in enumerate(input_ids):
78
+ if i >= j:
79
+ continue
80
+ if src not in G or tgt not in G:
81
+ matrix[(src, tgt)] = None
82
+ continue
83
+ try:
84
+ dist = nx.shortest_path_length(undirected, src, tgt)
85
+ if dist > depth:
86
+ matrix[(src, tgt)] = None
87
+ else:
88
+ matrix[(src, tgt)] = dist
89
+ except (nx.NetworkXNoPath, nx.NodeNotFound):
90
+ matrix[(src, tgt)] = None
91
+ return matrix
92
+
93
+
94
+ def _find_direct_edges(G, input_ids):
95
+ """Find direct edges between input symbols."""
96
+ edges = []
97
+ input_set = set(input_ids)
98
+ for src in input_ids:
99
+ if src not in G:
100
+ continue
101
+ for tgt in G.successors(src):
102
+ if tgt in input_set and tgt != src:
103
+ kind = G.edges[src, tgt].get("kind", "unknown")
104
+ edges.append((src, tgt, kind))
105
+ return edges
106
+
107
+
108
+ def _find_connecting_path(G, src, tgt, depth):
109
+ """Find shortest path between two nodes, respecting depth limit."""
110
+ import networkx as nx
111
+
112
+ if src not in G or tgt not in G:
113
+ return None
114
+ # Try directed first
115
+ try:
116
+ path = nx.shortest_path(G, src, tgt)
117
+ if len(path) - 1 <= depth:
118
+ return path
119
+ except (nx.NetworkXNoPath, nx.NodeNotFound):
120
+ pass
121
+ # Try undirected
122
+ try:
123
+ undirected = G.to_undirected()
124
+ path = nx.shortest_path(undirected, src, tgt)
125
+ if len(path) - 1 <= depth:
126
+ return path
127
+ except (nx.NetworkXNoPath, nx.NodeNotFound):
128
+ pass
129
+ return None
130
+
131
+
132
+ def _detect_conflicts(G, input_ids, shared_deps, conn):
133
+ """Detect conflict risks: input symbols that both have outgoing edges to the same dependency."""
134
+ conflicts = []
135
+ for dep_id, callers in shared_deps.items():
136
+ # Check if multiple inputs have edges that indicate modification
137
+ # (calls, uses — things that could conflict)
138
+ modifiers = set()
139
+ for caller_id in callers:
140
+ if G.has_edge(caller_id, dep_id):
141
+ edge_kind = G.edges[caller_id, dep_id].get("kind", "")
142
+ if edge_kind in ("call", "uses", "uses_trait"):
143
+ modifiers.add(caller_id)
144
+ if len(modifiers) >= 2:
145
+ dep_info = _get_symbol_info(conn, dep_id)
146
+ if dep_info:
147
+ conflicts.append(
148
+ {
149
+ "symbol": dep_info["name"],
150
+ "symbol_id": dep_id,
151
+ "modified_by": list(modifiers),
152
+ "recommendation": "coordinate changes to avoid race conditions",
153
+ }
154
+ )
155
+ return conflicts
156
+
157
+
158
+ def _compute_cohesion(distance_matrix, input_count):
159
+ """Compute cohesion score: average inverse distance, normalized 0-1."""
160
+ if input_count < 2:
161
+ return 1.0
162
+ distances = [d for d in distance_matrix.values() if d is not None]
163
+ if not distances:
164
+ return 0.0
165
+ # Inverse distance: 1/d, averaged
166
+ inv_sum = sum(1.0 / d for d in distances if d > 0)
167
+ # Number of pairs
168
+ n_pairs = input_count * (input_count - 1) // 2
169
+ if n_pairs == 0:
170
+ return 0.0
171
+ cohesion = inv_sum / n_pairs
172
+ # Clamp to 0-1
173
+ return min(1.0, max(0.0, cohesion))
174
+
175
+
176
+ @click.command()
177
+ @click.argument("symbols", nargs=-1)
178
+ @click.option("--file", "files", multiple=True, help="Include symbols from file/dir path")
179
+ @click.option("--depth", default=3, help="Max hops for connecting paths (default 3)")
180
+ @click.pass_context
181
+ def relate(ctx, symbols, files, depth):
182
+ """Show how a set of symbols relate to each other."""
183
+ json_mode = ctx.obj.get("json") if ctx.obj else False
184
+ ensure_index()
185
+
186
+ from roam.graph.builder import build_symbol_graph
187
+
188
+ with open_db(readonly=True) as conn:
189
+ G = build_symbol_graph(conn)
190
+
191
+ # Resolve input symbols to node IDs
192
+ input_ids = []
193
+ input_names = {} # id -> name
194
+
195
+ for name in symbols:
196
+ sym = find_symbol(conn, name)
197
+ if sym:
198
+ sid = sym["id"]
199
+ if sid not in input_names:
200
+ input_ids.append(sid)
201
+ input_names[sid] = sym["name"]
202
+ else:
203
+ click.echo(symbol_not_found_hint(name))
204
+ if not json_mode:
205
+ raise SystemExit(1)
206
+
207
+ # Resolve symbols from --file paths
208
+ if files:
209
+ file_ids = _resolve_symbols_from_files(conn, files)
210
+ for sid in file_ids:
211
+ if sid not in input_names:
212
+ info = _get_symbol_info(conn, sid)
213
+ if info:
214
+ input_ids.append(sid)
215
+ input_names[sid] = info["name"]
216
+
217
+ if not input_ids:
218
+ click.echo(
219
+ "No symbols to analyze.\n"
220
+ " Tip: Provide at least one valid symbol name or --file path.\n"
221
+ " Use `roam search <partial-name>` to find symbol names."
222
+ )
223
+ raise SystemExit(1)
224
+
225
+ # Analysis
226
+ direct_edges = _find_direct_edges(G, input_ids)
227
+ shared_deps = _find_shared_dependencies(G, input_ids)
228
+ shared_callers = _find_shared_callers(G, input_ids)
229
+ distance_matrix = _compute_distance_matrix(G, input_ids, depth)
230
+ conflicts = _detect_conflicts(G, input_ids, shared_deps, conn)
231
+ cohesion = _compute_cohesion(distance_matrix, len(input_ids))
232
+
233
+ # Build relationship list for each pair
234
+ relationships = []
235
+ for i, src in enumerate(input_ids):
236
+ for j, tgt in enumerate(input_ids):
237
+ if i >= j:
238
+ continue
239
+ src_name = input_names[src]
240
+ tgt_name = input_names[tgt]
241
+ dist = distance_matrix.get((src, tgt))
242
+ if dist is None:
243
+ dist = distance_matrix.get((tgt, src))
244
+
245
+ # Check for direct edge
246
+ has_direct = False
247
+ edge_kind = None
248
+ for s, t, k in direct_edges:
249
+ if (s == src and t == tgt) or (s == tgt and t == src):
250
+ has_direct = True
251
+ edge_kind = k
252
+ break
253
+
254
+ # Find intermediate node if distance is 2
255
+ via = None
256
+ if dist is not None and dist == 2 and not has_direct:
257
+ path = _find_connecting_path(G, src, tgt, depth)
258
+ if path and len(path) == 3:
259
+ mid_info = _get_symbol_info(conn, path[1])
260
+ if mid_info:
261
+ via = mid_info["name"]
262
+
263
+ if has_direct:
264
+ kind = f"DIRECT {edge_kind.upper()}" if edge_kind else "DIRECT"
265
+ elif dist is not None:
266
+ kind = "INDIRECT"
267
+ else:
268
+ kind = "NO PATH"
269
+
270
+ relationships.append(
271
+ {
272
+ "source": src_name,
273
+ "target": tgt_name,
274
+ "kind": kind,
275
+ "distance": dist,
276
+ "via": via,
277
+ }
278
+ )
279
+
280
+ # Build shared_deps output
281
+ shared_deps_out = []
282
+ for dep_id, callers in shared_deps.items():
283
+ dep_info = _get_symbol_info(conn, dep_id)
284
+ if dep_info:
285
+ shared_deps_out.append(
286
+ {
287
+ "name": dep_info["name"],
288
+ "used_by": [input_names[c] for c in callers if c in input_names],
289
+ }
290
+ )
291
+
292
+ # Build shared_callers output
293
+ shared_callers_out = []
294
+ for caller_id, callees in shared_callers.items():
295
+ caller_info = _get_symbol_info(conn, caller_id)
296
+ if caller_info:
297
+ shared_callers_out.append(
298
+ {
299
+ "name": caller_info["name"],
300
+ "calls": [input_names[c] for c in callees if c in input_names],
301
+ }
302
+ )
303
+
304
+ # Build conflicts output
305
+ conflicts_out = []
306
+ for c in conflicts:
307
+ conflicts_out.append(
308
+ {
309
+ "symbol": c["symbol"],
310
+ "modified_by": [input_names[m] for m in c["modified_by"] if m in input_names],
311
+ "recommendation": c["recommendation"],
312
+ }
313
+ )
314
+
315
+ # Build distance matrix output
316
+ dist_matrix_out = {}
317
+ for sid in input_ids:
318
+ name = input_names[sid]
319
+ dist_matrix_out[name] = {}
320
+ for sid2 in input_ids:
321
+ name2 = input_names[sid2]
322
+ if sid == sid2:
323
+ dist_matrix_out[name][name2] = 0
324
+ else:
325
+ key = (min(sid, sid2), max(sid, sid2))
326
+ d = distance_matrix.get(key)
327
+ dist_matrix_out[name][name2] = d
328
+
329
+ verdict = (
330
+ f"{len(input_ids)} symbols analyzed, "
331
+ f"cohesion {cohesion:.2f}, "
332
+ f"{len(direct_edges)} direct edges, "
333
+ f"{len(conflicts_out)} conflict risks"
334
+ )
335
+
336
+ if json_mode:
337
+ click.echo(
338
+ to_json(
339
+ json_envelope(
340
+ "relate",
341
+ summary={
342
+ "verdict": verdict,
343
+ "symbol_count": len(input_ids),
344
+ "cohesion": round(cohesion, 2),
345
+ "direct_edges": len(direct_edges),
346
+ "conflict_risks": len(conflicts_out),
347
+ },
348
+ relationships=relationships,
349
+ shared_deps=shared_deps_out,
350
+ shared_callers=shared_callers_out,
351
+ conflicts=conflicts_out,
352
+ distance_matrix=dist_matrix_out,
353
+ )
354
+ )
355
+ )
356
+ return
357
+
358
+ # Text output
359
+ click.echo(f"VERDICT: {verdict}")
360
+
361
+ if relationships:
362
+ click.echo("\nRELATIONSHIPS:")
363
+ for rel in relationships:
364
+ dist_str = f"distance {rel['distance']}" if rel["distance"] is not None else "no path"
365
+ via_str = f" via {rel['via']}" if rel.get("via") else ""
366
+ click.echo(f" {rel['source']} -> {rel['target']} {rel['kind']} ({dist_str}){via_str}")
367
+
368
+ if shared_deps_out:
369
+ click.echo("\nSHARED DEPENDENCIES:")
370
+ for dep in shared_deps_out:
371
+ click.echo(f" {dep['name']} used by: {', '.join(dep['used_by'])}")
372
+
373
+ if shared_callers_out:
374
+ click.echo("\nSHARED CALLERS:")
375
+ for caller in shared_callers_out:
376
+ click.echo(f" {caller['name']} calls: {', '.join(caller['calls'])}")
377
+
378
+ if conflicts_out:
379
+ click.echo("\nCONFLICT RISKS:")
380
+ for c in conflicts_out:
381
+ click.echo(f" {c['symbol']} -- modified by {' AND '.join(c['modified_by'])}")
382
+ click.echo(f" Recommendation: {c['recommendation']}")
383
+
384
+ # Distance matrix
385
+ if len(input_ids) >= 2:
386
+ click.echo("\nDISTANCE MATRIX:")
387
+ names = [input_names[sid] for sid in input_ids]
388
+ # Header
389
+ max_name_len = max(len(n) for n in names)
390
+ header = " " * (max_name_len + 2)
391
+ for n in names:
392
+ header += f"{n:>{max_name_len + 2}}"
393
+ click.echo(header)
394
+ for sid in input_ids:
395
+ name = input_names[sid]
396
+ row = f" {name:<{max_name_len}}"
397
+ for sid2 in input_ids:
398
+ name2 = input_names[sid2]
399
+ if sid == sid2:
400
+ row += f"{'-':>{max_name_len + 2}}"
401
+ else:
402
+ d = dist_matrix_out[name][name2]
403
+ val = str(d) if d is not None else "-"
404
+ row += f"{val:>{max_name_len + 2}}"
405
+ click.echo(row)