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,334 @@
|
|
|
1
|
+
"""Show file skeleton: all definitions with signatures."""
|
|
2
|
+
|
|
3
|
+
import subprocess
|
|
4
|
+
from collections import Counter
|
|
5
|
+
|
|
6
|
+
import click
|
|
7
|
+
|
|
8
|
+
from roam.commands.resolve import ensure_index, file_not_found_hint
|
|
9
|
+
from roam.db.connection import find_project_root, open_db
|
|
10
|
+
from roam.db.queries import FILE_BY_PATH, SYMBOLS_IN_FILE
|
|
11
|
+
from roam.output.formatter import abbrev_kind, format_signature, json_envelope, to_json
|
|
12
|
+
|
|
13
|
+
# ---------------------------------------------------------------------------
|
|
14
|
+
# Helpers
|
|
15
|
+
# ---------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _resolve_file(conn, path):
|
|
19
|
+
"""Resolve a file path to its DB row, or None."""
|
|
20
|
+
path = path.replace("\\", "/")
|
|
21
|
+
frow = conn.execute(FILE_BY_PATH, (path,)).fetchone()
|
|
22
|
+
if frow is None:
|
|
23
|
+
frow = conn.execute(
|
|
24
|
+
"SELECT * FROM files WHERE path LIKE ? LIMIT 1",
|
|
25
|
+
(f"%{path}",),
|
|
26
|
+
).fetchone()
|
|
27
|
+
return frow
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _get_changed_files():
|
|
31
|
+
"""Get list of uncommitted changed file paths from git."""
|
|
32
|
+
root = find_project_root()
|
|
33
|
+
paths = set()
|
|
34
|
+
for cmd in (
|
|
35
|
+
["git", "diff", "--name-only"],
|
|
36
|
+
["git", "diff", "--name-only", "--staged"],
|
|
37
|
+
):
|
|
38
|
+
try:
|
|
39
|
+
result = subprocess.run(
|
|
40
|
+
cmd,
|
|
41
|
+
cwd=str(root),
|
|
42
|
+
capture_output=True,
|
|
43
|
+
text=True,
|
|
44
|
+
timeout=10,
|
|
45
|
+
encoding="utf-8",
|
|
46
|
+
errors="replace",
|
|
47
|
+
)
|
|
48
|
+
if result.returncode == 0:
|
|
49
|
+
for p in result.stdout.strip().splitlines():
|
|
50
|
+
p = p.strip()
|
|
51
|
+
if p:
|
|
52
|
+
paths.add(p.replace("\\", "/"))
|
|
53
|
+
except (FileNotFoundError, subprocess.TimeoutExpired):
|
|
54
|
+
pass
|
|
55
|
+
return sorted(paths)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _get_deps_of_file(conn, frow):
|
|
59
|
+
"""Get file paths that the given file imports (outgoing file edges)."""
|
|
60
|
+
rows = conn.execute(
|
|
61
|
+
"SELECT f.path FROM file_edges fe "
|
|
62
|
+
"JOIN files f ON fe.target_file_id = f.id "
|
|
63
|
+
"WHERE fe.source_file_id = ? "
|
|
64
|
+
"ORDER BY f.path",
|
|
65
|
+
(frow["id"],),
|
|
66
|
+
).fetchall()
|
|
67
|
+
return [r["path"] for r in rows]
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _build_file_skeleton(conn, frow):
|
|
71
|
+
"""Build the skeleton data for a single file row.
|
|
72
|
+
|
|
73
|
+
Returns (frow, symbols, kind_counts, parent_ids).
|
|
74
|
+
Enriches frow with file_stats data (cognitive_load, health_score).
|
|
75
|
+
"""
|
|
76
|
+
symbols = conn.execute(SYMBOLS_IN_FILE, (frow["id"],)).fetchall()
|
|
77
|
+
kind_counts = Counter(abbrev_kind(s["kind"]) for s in symbols)
|
|
78
|
+
parent_ids = {s["id"]: s["parent_id"] for s in symbols}
|
|
79
|
+
|
|
80
|
+
# Enrich frow with file_stats
|
|
81
|
+
stats = conn.execute(
|
|
82
|
+
"SELECT cognitive_load, health_score FROM file_stats WHERE file_id = ?",
|
|
83
|
+
(frow["id"],),
|
|
84
|
+
).fetchone()
|
|
85
|
+
# Build a mutable dict from the sqlite3.Row
|
|
86
|
+
enriched = dict(frow)
|
|
87
|
+
if stats:
|
|
88
|
+
enriched["cognitive_load"] = stats["cognitive_load"]
|
|
89
|
+
enriched["health_score"] = stats["health_score"]
|
|
90
|
+
else:
|
|
91
|
+
enriched["cognitive_load"] = None
|
|
92
|
+
enriched["health_score"] = None
|
|
93
|
+
|
|
94
|
+
return enriched, symbols, kind_counts, parent_ids
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _skeleton_to_json(frow, symbols, kind_counts, parent_ids):
|
|
98
|
+
"""Convert a single file skeleton to a JSON-serializable dict."""
|
|
99
|
+
|
|
100
|
+
def _depth(s):
|
|
101
|
+
level = 0
|
|
102
|
+
pid = s["parent_id"]
|
|
103
|
+
while pid is not None and pid in parent_ids:
|
|
104
|
+
level += 1
|
|
105
|
+
pid = parent_ids[pid]
|
|
106
|
+
return level
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
"path": frow["path"],
|
|
110
|
+
"language": frow["language"],
|
|
111
|
+
"line_count": frow["line_count"],
|
|
112
|
+
"symbol_count": len(symbols),
|
|
113
|
+
"kind_summary": dict(kind_counts.most_common()),
|
|
114
|
+
"cognitive_load": frow.get("cognitive_load"),
|
|
115
|
+
"health_score": frow.get("health_score"),
|
|
116
|
+
"symbols": [
|
|
117
|
+
{
|
|
118
|
+
"name": s["name"],
|
|
119
|
+
"kind": s["kind"],
|
|
120
|
+
"signature": s["signature"] or "",
|
|
121
|
+
"line_start": s["line_start"],
|
|
122
|
+
"line_end": s["line_end"],
|
|
123
|
+
"depth": _depth(s),
|
|
124
|
+
}
|
|
125
|
+
for s in symbols
|
|
126
|
+
],
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _render_skeleton_text(frow, symbols, kind_counts, parent_ids, header=None):
|
|
131
|
+
"""Render a single file skeleton as text lines.
|
|
132
|
+
|
|
133
|
+
If *header* is provided, use it instead of the default file header.
|
|
134
|
+
"""
|
|
135
|
+
lines = []
|
|
136
|
+
|
|
137
|
+
if header:
|
|
138
|
+
lines.append(header)
|
|
139
|
+
else:
|
|
140
|
+
meta = f"{frow['language'] or '?'}, {frow['line_count']} lines"
|
|
141
|
+
cl = frow.get("cognitive_load")
|
|
142
|
+
hs = frow.get("health_score")
|
|
143
|
+
if cl is not None:
|
|
144
|
+
meta += f", load={cl:.0f}/100"
|
|
145
|
+
if hs is not None:
|
|
146
|
+
meta += f", health={hs}/10"
|
|
147
|
+
lines.append(f"{frow['path']} ({meta})")
|
|
148
|
+
lines.append("")
|
|
149
|
+
|
|
150
|
+
if not symbols:
|
|
151
|
+
lines.append(" (no symbols)")
|
|
152
|
+
return lines
|
|
153
|
+
|
|
154
|
+
summary_parts = [f"{k}:{v}" for k, v in kind_counts.most_common()]
|
|
155
|
+
lines.append(" ".join(summary_parts))
|
|
156
|
+
lines.append("")
|
|
157
|
+
|
|
158
|
+
for s in symbols:
|
|
159
|
+
level = 0
|
|
160
|
+
if s["parent_id"] is not None:
|
|
161
|
+
level = 1
|
|
162
|
+
pid = s["parent_id"]
|
|
163
|
+
while pid in parent_ids and parent_ids[pid] is not None:
|
|
164
|
+
level += 1
|
|
165
|
+
pid = parent_ids[pid]
|
|
166
|
+
|
|
167
|
+
prefix = " " * level
|
|
168
|
+
kind = abbrev_kind(s["kind"])
|
|
169
|
+
sig = format_signature(s["signature"])
|
|
170
|
+
line_info = f"L{s['line_start']}"
|
|
171
|
+
if s["line_end"] and s["line_end"] != s["line_start"]:
|
|
172
|
+
line_info += f"-{s['line_end']}"
|
|
173
|
+
|
|
174
|
+
parts = [kind, s["name"]]
|
|
175
|
+
if sig:
|
|
176
|
+
parts.append(sig)
|
|
177
|
+
parts.append(line_info)
|
|
178
|
+
lines.append(f"{prefix}{' '.join(parts)}")
|
|
179
|
+
|
|
180
|
+
return lines
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
# ---------------------------------------------------------------------------
|
|
184
|
+
# CLI command
|
|
185
|
+
# ---------------------------------------------------------------------------
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
@click.command("file")
|
|
189
|
+
@click.argument("paths", nargs=-1)
|
|
190
|
+
@click.option("--full", is_flag=True, help="Show all results without truncation")
|
|
191
|
+
@click.option(
|
|
192
|
+
"--changed",
|
|
193
|
+
is_flag=True,
|
|
194
|
+
default=False,
|
|
195
|
+
help="Show skeletons of all uncommitted changed files",
|
|
196
|
+
)
|
|
197
|
+
@click.option(
|
|
198
|
+
"--deps-of",
|
|
199
|
+
"deps_of",
|
|
200
|
+
type=str,
|
|
201
|
+
default=None,
|
|
202
|
+
help="Show skeleton of PATH plus all files it imports",
|
|
203
|
+
)
|
|
204
|
+
@click.pass_context
|
|
205
|
+
def file_cmd(ctx, paths, full, changed, deps_of):
|
|
206
|
+
"""Show file skeleton: all definitions with signatures.
|
|
207
|
+
|
|
208
|
+
Accepts one or more file paths. With --changed, shows skeletons of all
|
|
209
|
+
uncommitted changed files. With --deps-of PATH, shows the skeleton of
|
|
210
|
+
PATH plus every file it imports.
|
|
211
|
+
"""
|
|
212
|
+
json_mode = ctx.obj.get("json") if ctx.obj else False
|
|
213
|
+
ensure_index()
|
|
214
|
+
|
|
215
|
+
# Collect target paths from all sources
|
|
216
|
+
target_paths = list(paths)
|
|
217
|
+
|
|
218
|
+
if changed:
|
|
219
|
+
target_paths.extend(_get_changed_files())
|
|
220
|
+
|
|
221
|
+
if deps_of:
|
|
222
|
+
# Always include the deps-of file itself, plus its imports
|
|
223
|
+
target_paths.append(deps_of)
|
|
224
|
+
|
|
225
|
+
# If nothing to do, print help
|
|
226
|
+
if not target_paths and not deps_of:
|
|
227
|
+
click.echo(ctx.get_help())
|
|
228
|
+
return
|
|
229
|
+
|
|
230
|
+
with open_db(readonly=True) as conn:
|
|
231
|
+
# Resolve --deps-of imports
|
|
232
|
+
if deps_of:
|
|
233
|
+
dep_path = deps_of.replace("\\", "/")
|
|
234
|
+
dep_frow = _resolve_file(conn, dep_path)
|
|
235
|
+
if dep_frow is not None:
|
|
236
|
+
dep_paths = _get_deps_of_file(conn, dep_frow)
|
|
237
|
+
target_paths.extend(dep_paths)
|
|
238
|
+
|
|
239
|
+
# Deduplicate while preserving order
|
|
240
|
+
seen = set()
|
|
241
|
+
unique_paths = []
|
|
242
|
+
for p in target_paths:
|
|
243
|
+
norm = p.replace("\\", "/")
|
|
244
|
+
if norm not in seen:
|
|
245
|
+
seen.add(norm)
|
|
246
|
+
unique_paths.append(p)
|
|
247
|
+
|
|
248
|
+
# --- Single-file mode (backward compat) ---
|
|
249
|
+
if len(unique_paths) == 1:
|
|
250
|
+
frow = _resolve_file(conn, unique_paths[0])
|
|
251
|
+
if frow is None:
|
|
252
|
+
click.echo(file_not_found_hint(unique_paths[0]))
|
|
253
|
+
raise SystemExit(1)
|
|
254
|
+
|
|
255
|
+
frow, symbols, kind_counts, parent_ids = _build_file_skeleton(conn, frow)
|
|
256
|
+
|
|
257
|
+
if json_mode:
|
|
258
|
+
obj = _skeleton_to_json(frow, symbols, kind_counts, parent_ids)
|
|
259
|
+
click.echo(
|
|
260
|
+
to_json(
|
|
261
|
+
json_envelope(
|
|
262
|
+
"file",
|
|
263
|
+
summary={
|
|
264
|
+
"symbols": len(symbols),
|
|
265
|
+
"line_count": frow["line_count"],
|
|
266
|
+
},
|
|
267
|
+
path=obj["path"],
|
|
268
|
+
language=obj["language"],
|
|
269
|
+
line_count=obj["line_count"],
|
|
270
|
+
kind_summary=obj["kind_summary"],
|
|
271
|
+
cognitive_load=obj.get("cognitive_load"),
|
|
272
|
+
health_score=obj.get("health_score"),
|
|
273
|
+
symbols=obj["symbols"],
|
|
274
|
+
)
|
|
275
|
+
)
|
|
276
|
+
)
|
|
277
|
+
return
|
|
278
|
+
|
|
279
|
+
text_lines = _render_skeleton_text(frow, symbols, kind_counts, parent_ids)
|
|
280
|
+
click.echo("\n".join(text_lines))
|
|
281
|
+
return
|
|
282
|
+
|
|
283
|
+
# --- Multi-file mode ---
|
|
284
|
+
file_results = []
|
|
285
|
+
missing = []
|
|
286
|
+
for p in unique_paths:
|
|
287
|
+
frow = _resolve_file(conn, p)
|
|
288
|
+
if frow is None:
|
|
289
|
+
missing.append(p)
|
|
290
|
+
continue
|
|
291
|
+
frow, symbols, kind_counts, parent_ids = _build_file_skeleton(conn, frow)
|
|
292
|
+
file_results.append((frow, symbols, kind_counts, parent_ids))
|
|
293
|
+
|
|
294
|
+
if json_mode:
|
|
295
|
+
files_json = []
|
|
296
|
+
for frow, symbols, kind_counts, parent_ids in file_results:
|
|
297
|
+
files_json.append(_skeleton_to_json(frow, symbols, kind_counts, parent_ids))
|
|
298
|
+
total_symbols = sum(f["symbol_count"] for f in files_json)
|
|
299
|
+
click.echo(
|
|
300
|
+
to_json(
|
|
301
|
+
json_envelope(
|
|
302
|
+
"file",
|
|
303
|
+
summary={
|
|
304
|
+
"files": len(files_json),
|
|
305
|
+
"total_symbols": total_symbols,
|
|
306
|
+
"missing": missing,
|
|
307
|
+
},
|
|
308
|
+
files=files_json,
|
|
309
|
+
)
|
|
310
|
+
)
|
|
311
|
+
)
|
|
312
|
+
return
|
|
313
|
+
|
|
314
|
+
# Text output
|
|
315
|
+
if missing:
|
|
316
|
+
for m in missing:
|
|
317
|
+
click.echo(f"(not indexed: {m})")
|
|
318
|
+
click.echo()
|
|
319
|
+
|
|
320
|
+
first = True
|
|
321
|
+
for frow, symbols, kind_counts, parent_ids in file_results:
|
|
322
|
+
if not first:
|
|
323
|
+
click.echo()
|
|
324
|
+
|
|
325
|
+
header = f"\u2500\u2500\u2500 {frow['path']} ({len(symbols)} symbols) \u2500\u2500\u2500"
|
|
326
|
+
text_lines = _render_skeleton_text(
|
|
327
|
+
frow,
|
|
328
|
+
symbols,
|
|
329
|
+
kind_counts,
|
|
330
|
+
parent_ids,
|
|
331
|
+
header=header,
|
|
332
|
+
)
|
|
333
|
+
click.echo("\n".join(text_lines))
|
|
334
|
+
first = False
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"""Graph-Isomorphism Transfer: topology fingerprint for cross-repo comparison."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json as _json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
import click
|
|
9
|
+
|
|
10
|
+
from roam.commands.resolve import ensure_index
|
|
11
|
+
from roam.db.connection import open_db
|
|
12
|
+
from roam.output.formatter import format_table, json_envelope, to_json
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _format_pct_list(pcts: list[float]) -> str:
|
|
16
|
+
"""Format a list of percentages into a compact distribution string."""
|
|
17
|
+
return " / ".join(f"{p:.0f}%" for p in pcts)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@click.command()
|
|
21
|
+
@click.option("--compact", is_flag=True, help="Single-line summary output")
|
|
22
|
+
@click.option(
|
|
23
|
+
"--export",
|
|
24
|
+
"export_path",
|
|
25
|
+
type=click.Path(),
|
|
26
|
+
default=None,
|
|
27
|
+
help="Write fingerprint JSON to file",
|
|
28
|
+
)
|
|
29
|
+
@click.option(
|
|
30
|
+
"--compare",
|
|
31
|
+
"compare_path",
|
|
32
|
+
type=click.Path(exists=True),
|
|
33
|
+
default=None,
|
|
34
|
+
help="Compare with a saved fingerprint JSON file",
|
|
35
|
+
)
|
|
36
|
+
@click.pass_context
|
|
37
|
+
def fingerprint(ctx, compact, export_path, compare_path):
|
|
38
|
+
"""Topology fingerprint for cross-repo comparison.
|
|
39
|
+
|
|
40
|
+
Extracts a structural signature from the codebase graph: layers,
|
|
41
|
+
modularity, connectivity, clusters, hub/bridge ratio, PageRank
|
|
42
|
+
distribution, and anti-patterns.
|
|
43
|
+
|
|
44
|
+
Use --export to save and --compare to diff against another repo.
|
|
45
|
+
"""
|
|
46
|
+
json_mode = ctx.obj.get("json") if ctx.obj else False
|
|
47
|
+
ensure_index()
|
|
48
|
+
|
|
49
|
+
with open_db(readonly=True) as conn:
|
|
50
|
+
from roam.graph.builder import build_symbol_graph
|
|
51
|
+
from roam.graph.fingerprint import compare_fingerprints, compute_fingerprint
|
|
52
|
+
|
|
53
|
+
G = build_symbol_graph(conn)
|
|
54
|
+
fp = compute_fingerprint(conn, G)
|
|
55
|
+
|
|
56
|
+
topo = fp["topology"]
|
|
57
|
+
n_layers = topo["layers"]
|
|
58
|
+
modularity = topo["modularity"]
|
|
59
|
+
fiedler = topo["fiedler"]
|
|
60
|
+
tangle = topo["tangle_ratio"]
|
|
61
|
+
|
|
62
|
+
verdict = f"{n_layers} layers, modularity {modularity:.2f}, fiedler {fiedler:.3f}, tangle {int(tangle * 100)}%"
|
|
63
|
+
|
|
64
|
+
# -- Export --
|
|
65
|
+
if export_path:
|
|
66
|
+
Path(export_path).write_text(_json.dumps(fp, indent=2, default=str), encoding="utf-8")
|
|
67
|
+
if not json_mode and not compact:
|
|
68
|
+
click.echo(f"Fingerprint written to {export_path}")
|
|
69
|
+
|
|
70
|
+
# -- Compare --
|
|
71
|
+
comparison = None
|
|
72
|
+
if compare_path:
|
|
73
|
+
other_fp = _json.loads(Path(compare_path).read_text(encoding="utf-8"))
|
|
74
|
+
comparison = compare_fingerprints(fp, other_fp)
|
|
75
|
+
|
|
76
|
+
# -- JSON output --
|
|
77
|
+
if json_mode:
|
|
78
|
+
envelope = json_envelope(
|
|
79
|
+
"fingerprint",
|
|
80
|
+
summary={
|
|
81
|
+
"verdict": verdict,
|
|
82
|
+
"layers": n_layers,
|
|
83
|
+
"modularity": modularity,
|
|
84
|
+
"fiedler": fiedler,
|
|
85
|
+
"tangle_ratio": tangle,
|
|
86
|
+
},
|
|
87
|
+
fingerprint=fp,
|
|
88
|
+
)
|
|
89
|
+
if comparison:
|
|
90
|
+
envelope["comparison"] = comparison
|
|
91
|
+
envelope["summary"]["similarity_score"] = comparison["similarity"]
|
|
92
|
+
click.echo(to_json(envelope))
|
|
93
|
+
return
|
|
94
|
+
|
|
95
|
+
# -- Compact output --
|
|
96
|
+
if compact:
|
|
97
|
+
sim_str = ""
|
|
98
|
+
if comparison:
|
|
99
|
+
sim_str = f" similarity={comparison['similarity']:.0%}"
|
|
100
|
+
click.echo(
|
|
101
|
+
f"fingerprint layers={n_layers} mod={modularity:.3f} "
|
|
102
|
+
f"fiedler={fiedler:.4f} tangle={tangle:.2f} "
|
|
103
|
+
f"gini={fp['pagerank_gini']:.2f} "
|
|
104
|
+
f"hubs={fp['hub_bridge_ratio']:.2f}"
|
|
105
|
+
f"{sim_str}"
|
|
106
|
+
)
|
|
107
|
+
return
|
|
108
|
+
|
|
109
|
+
# -- Full text output --
|
|
110
|
+
click.echo(f"VERDICT: {verdict}")
|
|
111
|
+
|
|
112
|
+
# Topology section
|
|
113
|
+
click.echo("\nTOPOLOGY:")
|
|
114
|
+
dist_str = _format_pct_list(topo["layer_distribution"]) if topo["layer_distribution"] else "n/a"
|
|
115
|
+
click.echo(f" Layers: {n_layers} (distribution: {dist_str})")
|
|
116
|
+
click.echo(f" Fiedler: {fiedler:.4f}")
|
|
117
|
+
click.echo(f" Modularity: {modularity:.3f}")
|
|
118
|
+
click.echo(f" Tangle ratio: {tangle:.2f}")
|
|
119
|
+
click.echo(f" Dependency direction: {fp['dependency_direction']}")
|
|
120
|
+
|
|
121
|
+
# Clusters section (top 5)
|
|
122
|
+
clusters = fp.get("clusters", [])
|
|
123
|
+
if clusters:
|
|
124
|
+
click.echo(f"\nCLUSTERS (top {min(5, len(clusters))}):")
|
|
125
|
+
table_rows = []
|
|
126
|
+
for c in clusters[:5]:
|
|
127
|
+
table_rows.append(
|
|
128
|
+
[
|
|
129
|
+
c["label"],
|
|
130
|
+
f"{c['size_pct']:.0f}%",
|
|
131
|
+
f"{c['conductance']:.2f}",
|
|
132
|
+
str(c["layer"]),
|
|
133
|
+
c["pattern"],
|
|
134
|
+
]
|
|
135
|
+
)
|
|
136
|
+
click.echo(
|
|
137
|
+
format_table(
|
|
138
|
+
["Label", "Size", "Conductance", "Layer", "Pattern"],
|
|
139
|
+
table_rows,
|
|
140
|
+
)
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
# Signature section
|
|
144
|
+
click.echo("\nSIGNATURE:")
|
|
145
|
+
click.echo(f" Hub/bridge ratio: {fp['hub_bridge_ratio']:.2f}")
|
|
146
|
+
click.echo(f" PageRank Gini: {fp['pagerank_gini']:.2f}")
|
|
147
|
+
click.echo(f" God objects: {fp['antipatterns']['god_objects']}")
|
|
148
|
+
click.echo(f" Cyclic clusters: {fp['antipatterns']['cyclic_clusters']}")
|
|
149
|
+
|
|
150
|
+
# Comparison section
|
|
151
|
+
if comparison:
|
|
152
|
+
sim = comparison["similarity"]
|
|
153
|
+
dist = comparison["euclidean_distance"]
|
|
154
|
+
click.echo(f"\nVERDICT: {sim:.0%} similar (topology distance: {dist:.2f})")
|
|
155
|
+
click.echo("\nCOMPARISON:")
|
|
156
|
+
cmp_rows = []
|
|
157
|
+
for name, m in comparison["per_metric"].items():
|
|
158
|
+
delta_str = f"{m['delta']:+.4f}" if isinstance(m["delta"], float) else f"{m['delta']:+d}"
|
|
159
|
+
cmp_rows.append(
|
|
160
|
+
[
|
|
161
|
+
name,
|
|
162
|
+
str(round(m["this"], 4)),
|
|
163
|
+
str(round(m["other"], 4)),
|
|
164
|
+
delta_str,
|
|
165
|
+
]
|
|
166
|
+
)
|
|
167
|
+
click.echo(
|
|
168
|
+
format_table(
|
|
169
|
+
["Metric", "This repo", "Other repo", "Delta"],
|
|
170
|
+
cmp_rows,
|
|
171
|
+
)
|
|
172
|
+
)
|