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.
- mulle_roam_code-0.0.1.dist-info/METADATA +1590 -0
- mulle_roam_code-0.0.1.dist-info/RECORD +257 -0
- mulle_roam_code-0.0.1.dist-info/WHEEL +5 -0
- mulle_roam_code-0.0.1.dist-info/entry_points.txt +3 -0
- mulle_roam_code-0.0.1.dist-info/licenses/LICENSE +21 -0
- mulle_roam_code-0.0.1.dist-info/top_level.txt +1 -0
- roam/__init__.py +8 -0
- roam/__main__.py +5 -0
- roam/analysis/__init__.py +1 -0
- roam/analysis/effects.py +639 -0
- roam/analysis/taint.py +689 -0
- roam/api.py +238 -0
- roam/bridges/__init__.py +3 -0
- roam/bridges/base.py +49 -0
- roam/bridges/bridge_config.py +218 -0
- roam/bridges/bridge_protobuf.py +352 -0
- roam/bridges/bridge_rest_api.py +242 -0
- roam/bridges/bridge_salesforce.py +198 -0
- roam/bridges/bridge_template.py +247 -0
- roam/bridges/registry.py +51 -0
- roam/catalog/__init__.py +0 -0
- roam/catalog/detectors.py +2242 -0
- roam/catalog/fixes.py +86 -0
- roam/catalog/smells.py +599 -0
- roam/catalog/tasks.py +1260 -0
- roam/cli.py +548 -0
- roam/commands/__init__.py +0 -0
- roam/commands/changed_files.py +139 -0
- roam/commands/cmd_adversarial.py +699 -0
- roam/commands/cmd_affected.py +432 -0
- roam/commands/cmd_affected_tests.py +375 -0
- roam/commands/cmd_agent_context.py +168 -0
- roam/commands/cmd_agent_export.py +890 -0
- roam/commands/cmd_agent_plan.py +315 -0
- roam/commands/cmd_ai_ratio.py +765 -0
- roam/commands/cmd_ai_readiness.py +775 -0
- roam/commands/cmd_alerts.py +409 -0
- roam/commands/cmd_annotate.py +210 -0
- roam/commands/cmd_api_changes.py +796 -0
- roam/commands/cmd_api_drift.py +781 -0
- roam/commands/cmd_attest.py +913 -0
- roam/commands/cmd_auth_gaps.py +799 -0
- roam/commands/cmd_bisect.py +216 -0
- roam/commands/cmd_breaking.py +464 -0
- roam/commands/cmd_budget.py +413 -0
- roam/commands/cmd_bus_factor.py +403 -0
- roam/commands/cmd_capsule.py +275 -0
- roam/commands/cmd_check_rules.py +574 -0
- roam/commands/cmd_clean.py +147 -0
- roam/commands/cmd_closure.py +294 -0
- roam/commands/cmd_clusters.py +457 -0
- roam/commands/cmd_codeowners.py +600 -0
- roam/commands/cmd_complexity.py +364 -0
- roam/commands/cmd_config.py +310 -0
- roam/commands/cmd_context.py +1151 -0
- roam/commands/cmd_conventions.py +697 -0
- roam/commands/cmd_coupling.py +462 -0
- roam/commands/cmd_coverage_gaps.py +638 -0
- roam/commands/cmd_cut.py +235 -0
- roam/commands/cmd_dark_matter.py +127 -0
- roam/commands/cmd_dashboard.py +365 -0
- roam/commands/cmd_dead.py +1585 -0
- roam/commands/cmd_debt.py +731 -0
- roam/commands/cmd_deps.py +121 -0
- roam/commands/cmd_describe.py +959 -0
- roam/commands/cmd_dev_profile.py +580 -0
- roam/commands/cmd_diagnose.py +377 -0
- roam/commands/cmd_diff.py +633 -0
- roam/commands/cmd_digest.py +214 -0
- roam/commands/cmd_doc_staleness.py +334 -0
- roam/commands/cmd_docs_coverage.py +193 -0
- roam/commands/cmd_doctor.py +319 -0
- roam/commands/cmd_drift.py +377 -0
- roam/commands/cmd_duplicates.py +559 -0
- roam/commands/cmd_effects.py +362 -0
- roam/commands/cmd_endpoints.py +768 -0
- roam/commands/cmd_entry_points.py +358 -0
- roam/commands/cmd_fan.py +311 -0
- roam/commands/cmd_file.py +334 -0
- roam/commands/cmd_fingerprint.py +172 -0
- roam/commands/cmd_fitness.py +723 -0
- roam/commands/cmd_fn_coupling.py +295 -0
- roam/commands/cmd_forecast.py +366 -0
- roam/commands/cmd_grep.py +282 -0
- roam/commands/cmd_guard.py +434 -0
- roam/commands/cmd_health.py +922 -0
- roam/commands/cmd_hooks.py +458 -0
- roam/commands/cmd_hotspots.py +606 -0
- roam/commands/cmd_impact.py +228 -0
- roam/commands/cmd_index.py +102 -0
- roam/commands/cmd_ingest_trace.py +143 -0
- roam/commands/cmd_init.py +166 -0
- roam/commands/cmd_intent.py +459 -0
- roam/commands/cmd_invariants.py +301 -0
- roam/commands/cmd_layers.py +387 -0
- roam/commands/cmd_map.py +275 -0
- roam/commands/cmd_math.py +213 -0
- roam/commands/cmd_mcp_setup.py +135 -0
- roam/commands/cmd_metrics.py +663 -0
- roam/commands/cmd_migration_safety.py +712 -0
- roam/commands/cmd_minimap.py +519 -0
- roam/commands/cmd_missing_index.py +885 -0
- roam/commands/cmd_module.py +204 -0
- roam/commands/cmd_mutate.py +400 -0
- roam/commands/cmd_n1.py +967 -0
- roam/commands/cmd_onboard.py +740 -0
- roam/commands/cmd_orchestrate.py +180 -0
- roam/commands/cmd_orphan_routes.py +754 -0
- roam/commands/cmd_over_fetch.py +633 -0
- roam/commands/cmd_owner.py +299 -0
- roam/commands/cmd_partition.py +714 -0
- roam/commands/cmd_path_coverage.py +564 -0
- roam/commands/cmd_patterns.py +689 -0
- roam/commands/cmd_plan.py +616 -0
- roam/commands/cmd_plan_refactor.py +432 -0
- roam/commands/cmd_pr_diff.py +292 -0
- roam/commands/cmd_pr_risk.py +677 -0
- roam/commands/cmd_preflight.py +706 -0
- roam/commands/cmd_relate.py +405 -0
- roam/commands/cmd_report.py +304 -0
- roam/commands/cmd_reset.py +117 -0
- roam/commands/cmd_risk.py +533 -0
- roam/commands/cmd_rules.py +319 -0
- roam/commands/cmd_safe_delete.py +224 -0
- roam/commands/cmd_safe_zones.py +295 -0
- roam/commands/cmd_schema.py +166 -0
- roam/commands/cmd_search.py +295 -0
- roam/commands/cmd_search_semantic.py +101 -0
- roam/commands/cmd_secrets.py +636 -0
- roam/commands/cmd_semantic_diff.py +538 -0
- roam/commands/cmd_simulate.py +296 -0
- roam/commands/cmd_simulate_departure.py +632 -0
- roam/commands/cmd_sketch.py +160 -0
- roam/commands/cmd_smells.py +179 -0
- roam/commands/cmd_snapshot.py +50 -0
- roam/commands/cmd_spectral.py +183 -0
- roam/commands/cmd_split.py +432 -0
- roam/commands/cmd_suggest_refactoring.py +486 -0
- roam/commands/cmd_suggest_reviewers.py +491 -0
- roam/commands/cmd_supply_chain.py +831 -0
- roam/commands/cmd_symbol.py +135 -0
- roam/commands/cmd_syntax_check.py +301 -0
- roam/commands/cmd_test_gaps.py +574 -0
- roam/commands/cmd_testmap.py +308 -0
- roam/commands/cmd_tour.py +377 -0
- roam/commands/cmd_trace.py +304 -0
- roam/commands/cmd_trend.py +461 -0
- roam/commands/cmd_trends.py +929 -0
- roam/commands/cmd_understand.py +763 -0
- roam/commands/cmd_uses.py +170 -0
- roam/commands/cmd_verify.py +812 -0
- roam/commands/cmd_verify_imports.py +435 -0
- roam/commands/cmd_vibe_check.py +932 -0
- roam/commands/cmd_visualize.py +361 -0
- roam/commands/cmd_vuln_map.py +139 -0
- roam/commands/cmd_vuln_reach.py +289 -0
- roam/commands/cmd_vulns.py +414 -0
- roam/commands/cmd_watch.py +759 -0
- roam/commands/cmd_weather.py +118 -0
- roam/commands/cmd_why.py +325 -0
- roam/commands/cmd_ws.py +755 -0
- roam/commands/cmd_xlang.py +170 -0
- roam/commands/context_helpers.py +1137 -0
- roam/commands/gate_presets.py +222 -0
- roam/commands/graph_helpers.py +93 -0
- roam/commands/metrics_history.py +298 -0
- roam/commands/next_steps.py +107 -0
- roam/commands/resolve.py +302 -0
- roam/competitor_site_data.py +2229 -0
- roam/coverage_reports.py +462 -0
- roam/db/__init__.py +0 -0
- roam/db/connection.py +359 -0
- roam/db/queries.py +151 -0
- roam/db/schema.py +335 -0
- roam/exit_codes.py +100 -0
- roam/graph/__init__.py +43 -0
- roam/graph/anomaly.py +493 -0
- roam/graph/builder.py +61 -0
- roam/graph/clusters.py +286 -0
- roam/graph/cycles.py +210 -0
- roam/graph/dark_matter.py +207 -0
- roam/graph/diff.py +467 -0
- roam/graph/fingerprint.py +297 -0
- roam/graph/layers.py +134 -0
- roam/graph/pagerank.py +171 -0
- roam/graph/partition.py +437 -0
- roam/graph/pathfinding.py +119 -0
- roam/graph/propagation.py +208 -0
- roam/graph/simulate.py +286 -0
- roam/graph/spectral.py +260 -0
- roam/index/__init__.py +5 -0
- roam/index/complexity.py +1108 -0
- roam/index/discovery.py +338 -0
- roam/index/file_roles.py +586 -0
- roam/index/git_stats.py +577 -0
- roam/index/incremental.py +75 -0
- roam/index/indexer.py +1191 -0
- roam/index/parser.py +461 -0
- roam/index/relations.py +537 -0
- roam/index/symbols.py +71 -0
- roam/index/test_conventions.py +508 -0
- roam/languages/__init__.py +21 -0
- roam/languages/apex_lang.py +241 -0
- roam/languages/aura_lang.py +228 -0
- roam/languages/base.py +111 -0
- roam/languages/c_lang.py +458 -0
- roam/languages/csharp_lang.py +1215 -0
- roam/languages/foxpro_lang.py +1554 -0
- roam/languages/generic_lang.py +702 -0
- roam/languages/go_lang.py +392 -0
- roam/languages/hcl_lang.py +398 -0
- roam/languages/java_lang.py +418 -0
- roam/languages/javascript_lang.py +799 -0
- roam/languages/kotlin_lang.py +147 -0
- roam/languages/objc_lang.py +401 -0
- roam/languages/php_lang.py +696 -0
- roam/languages/python_lang.py +850 -0
- roam/languages/registry.py +283 -0
- roam/languages/ruby_lang.py +429 -0
- roam/languages/rust_lang.py +545 -0
- roam/languages/sfxml_lang.py +276 -0
- roam/languages/swift_lang.py +173 -0
- roam/languages/typescript_lang.py +323 -0
- roam/languages/visualforce_lang.py +151 -0
- roam/languages/yaml_lang.py +566 -0
- roam/mcp_server.py +4794 -0
- roam/output/__init__.py +0 -0
- roam/output/formatter.py +557 -0
- roam/output/mermaid.py +62 -0
- roam/output/sarif.py +897 -0
- roam/output/schema_registry.py +57 -0
- roam/plugins.py +208 -0
- roam/refactor/__init__.py +0 -0
- roam/refactor/codegen.py +106 -0
- roam/refactor/transforms.py +711 -0
- roam/rules/__init__.py +0 -0
- roam/rules/ast_match.py +238 -0
- roam/rules/builtin.py +617 -0
- roam/rules/dataflow.py +515 -0
- roam/rules/engine.py +943 -0
- roam/runtime/__init__.py +3 -0
- roam/runtime/hotspots.py +138 -0
- roam/runtime/trace_ingest.py +535 -0
- roam/search/__init__.py +1 -0
- roam/search/framework_packs.py +673 -0
- roam/search/index_embeddings.py +732 -0
- roam/search/onnx_embeddings.py +233 -0
- roam/search/tfidf.py +355 -0
- roam/security/__init__.py +1 -0
- roam/security/vuln_reach.py +246 -0
- roam/security/vuln_store.py +334 -0
- roam/surface_counts.py +158 -0
- roam/workspace/__init__.py +3 -0
- roam/workspace/aggregator.py +426 -0
- roam/workspace/api_scanner.py +538 -0
- roam/workspace/config.py +95 -0
- 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)
|