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
roam/commands/cmd_map.py
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"""Show project skeleton with entry points and key symbols."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from collections import Counter
|
|
5
|
+
|
|
6
|
+
import click
|
|
7
|
+
|
|
8
|
+
from roam.commands.resolve import ensure_index
|
|
9
|
+
from roam.db.connection import open_db
|
|
10
|
+
from roam.db.queries import (
|
|
11
|
+
ALL_FILES,
|
|
12
|
+
TOP_SYMBOLS_BY_PAGERANK,
|
|
13
|
+
)
|
|
14
|
+
from roam.output.formatter import (
|
|
15
|
+
abbrev_kind,
|
|
16
|
+
format_signature,
|
|
17
|
+
format_table,
|
|
18
|
+
json_envelope,
|
|
19
|
+
loc,
|
|
20
|
+
section,
|
|
21
|
+
to_json,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _estimate_tokens(text: str) -> int:
|
|
26
|
+
"""Rough token estimate: 4 characters = 1 token."""
|
|
27
|
+
return max(1, len(text) // 4)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _build_symbol_entry_text(s, *, for_budget: bool = False) -> str:
|
|
31
|
+
"""Build a single symbol's display line for token-budget accounting."""
|
|
32
|
+
sig = format_signature(s["signature"], max_len=50)
|
|
33
|
+
kind = abbrev_kind(s["kind"])
|
|
34
|
+
location = loc(s["file_path"], s["line_start"])
|
|
35
|
+
pr = f"{(s['pagerank'] or 0):.4f}"
|
|
36
|
+
# Approximate the formatted table row as a single string
|
|
37
|
+
return f"{kind} {s['name']} {sig} {location} {pr}"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@click.command("map")
|
|
41
|
+
@click.option("-n", "count", default=20, help="Number of top symbols to show")
|
|
42
|
+
@click.option("--full", is_flag=True, help="Show all results without truncation")
|
|
43
|
+
@click.option("--budget", type=int, default=None, help="Approximate token limit for output")
|
|
44
|
+
@click.pass_context
|
|
45
|
+
def map_cmd(ctx, count, full, budget):
|
|
46
|
+
"""Show project skeleton with entry points and key symbols."""
|
|
47
|
+
json_mode = ctx.obj.get("json") if ctx.obj else False
|
|
48
|
+
ensure_index()
|
|
49
|
+
|
|
50
|
+
with open_db(readonly=True) as conn:
|
|
51
|
+
# --- Project stats ---
|
|
52
|
+
files = conn.execute(ALL_FILES).fetchall()
|
|
53
|
+
total_files = len(files)
|
|
54
|
+
sym_count = conn.execute("SELECT COUNT(*) FROM symbols").fetchone()[0]
|
|
55
|
+
edge_count = conn.execute("SELECT COUNT(*) FROM edges").fetchone()[0]
|
|
56
|
+
|
|
57
|
+
lang_counts = Counter(f["language"] for f in files if f["language"])
|
|
58
|
+
|
|
59
|
+
# Edge kind distribution
|
|
60
|
+
edge_kinds = conn.execute("SELECT kind, COUNT(*) as cnt FROM edges GROUP BY kind ORDER BY cnt DESC").fetchall()
|
|
61
|
+
|
|
62
|
+
# --- Top directories ---
|
|
63
|
+
dir_rows_raw = conn.execute("""
|
|
64
|
+
SELECT CASE WHEN INSTR(REPLACE(path, '\\', '/'), '/') > 0
|
|
65
|
+
THEN SUBSTR(REPLACE(path, '\\', '/'), 1, INSTR(REPLACE(path, '\\', '/'), '/') - 1)
|
|
66
|
+
ELSE '.' END as dir,
|
|
67
|
+
COUNT(*) as cnt
|
|
68
|
+
FROM files GROUP BY dir ORDER BY cnt DESC
|
|
69
|
+
""").fetchall()
|
|
70
|
+
dir_counts = {r["dir"]: r["cnt"] for r in dir_rows_raw}
|
|
71
|
+
dir_items = sorted(dir_counts.items(), key=lambda x: x[1], reverse=True)
|
|
72
|
+
|
|
73
|
+
# --- Entry points ---
|
|
74
|
+
entry_names = {
|
|
75
|
+
"main.py",
|
|
76
|
+
"__main__.py",
|
|
77
|
+
"__init__.py",
|
|
78
|
+
"index.js",
|
|
79
|
+
"index.ts",
|
|
80
|
+
"main.go",
|
|
81
|
+
"main.rs",
|
|
82
|
+
"app.py",
|
|
83
|
+
"app.js",
|
|
84
|
+
"app.ts",
|
|
85
|
+
"mod.rs",
|
|
86
|
+
"lib.rs",
|
|
87
|
+
"setup.py",
|
|
88
|
+
"manage.py",
|
|
89
|
+
}
|
|
90
|
+
entries = [f["path"] for f in files if os.path.basename(f["path"]) in entry_names]
|
|
91
|
+
|
|
92
|
+
# Filter barrel files: index files with few own definitions (re-export only)
|
|
93
|
+
barrel_paths = set()
|
|
94
|
+
for f in files:
|
|
95
|
+
bn = os.path.basename(f["path"])
|
|
96
|
+
if bn.startswith("index.") and f["path"] in entries:
|
|
97
|
+
own_defs = conn.execute(
|
|
98
|
+
"SELECT COUNT(*) FROM symbols WHERE file_id = ? AND kind IN ('function', 'class', 'method')",
|
|
99
|
+
(f["id"],),
|
|
100
|
+
).fetchone()[0]
|
|
101
|
+
if own_defs <= 2:
|
|
102
|
+
barrel_paths.add(f["path"])
|
|
103
|
+
entries = [e for e in entries if e not in barrel_paths]
|
|
104
|
+
|
|
105
|
+
main_files = conn.execute(
|
|
106
|
+
"SELECT DISTINCT f.path FROM symbols s JOIN files f ON s.file_id = f.id "
|
|
107
|
+
"WHERE s.name = 'main' AND s.kind = 'function'",
|
|
108
|
+
).fetchall()
|
|
109
|
+
for r in main_files:
|
|
110
|
+
if r["path"] not in entries:
|
|
111
|
+
entries.append(r["path"])
|
|
112
|
+
|
|
113
|
+
decorated_files = conn.execute(
|
|
114
|
+
"SELECT DISTINCT f.path FROM symbols s JOIN files f ON s.file_id = f.id "
|
|
115
|
+
"WHERE s.kind = 'decorator' AND (s.name LIKE '%route%' OR s.name LIKE '%command%')",
|
|
116
|
+
).fetchall()
|
|
117
|
+
for r in decorated_files:
|
|
118
|
+
if r["path"] not in entries:
|
|
119
|
+
entries.append(r["path"])
|
|
120
|
+
|
|
121
|
+
# --- Top symbols by PageRank ---
|
|
122
|
+
# When budget is active, fetch all ranked symbols to allow greedy
|
|
123
|
+
# filling up to the token limit. Otherwise honour the -n count.
|
|
124
|
+
fetch_limit = count if budget is None else 10_000
|
|
125
|
+
all_ranked = conn.execute(TOP_SYMBOLS_BY_PAGERANK, (fetch_limit,)).fetchall()
|
|
126
|
+
|
|
127
|
+
# ---- Budget-aware symbol selection ----
|
|
128
|
+
if budget is not None:
|
|
129
|
+
# Pre-compute the preamble (stats, dirs, entries) to account
|
|
130
|
+
# for its token cost when filling the budget.
|
|
131
|
+
lang_str = ", ".join(f"{lang}={n}" for lang, n in lang_counts.most_common(8))
|
|
132
|
+
edge_str = ", ".join(f"{r['kind']}={r['cnt']}" for r in edge_kinds) if edge_kinds else "none"
|
|
133
|
+
|
|
134
|
+
preamble_lines = [
|
|
135
|
+
f"Files: {total_files} Symbols: {sym_count} Edges: {edge_count}",
|
|
136
|
+
f"Languages: {lang_str}",
|
|
137
|
+
f"Edge kinds: {edge_str}",
|
|
138
|
+
"",
|
|
139
|
+
]
|
|
140
|
+
# Directories section
|
|
141
|
+
dir_rows_budget = [[d, str(c)] for d, c in (dir_items if full else dir_items[:15])]
|
|
142
|
+
preamble_lines.append("Directories:")
|
|
143
|
+
preamble_lines.append(
|
|
144
|
+
format_table(
|
|
145
|
+
["dir", "files"],
|
|
146
|
+
dir_rows_budget,
|
|
147
|
+
budget=0 if full else 15,
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
preamble_lines.append("")
|
|
151
|
+
|
|
152
|
+
# Entry points section
|
|
153
|
+
if entries:
|
|
154
|
+
preamble_lines.append("Entry points:")
|
|
155
|
+
for e in entries if full else entries[:20]:
|
|
156
|
+
preamble_lines.append(f" {e}")
|
|
157
|
+
if not full and len(entries) > 20:
|
|
158
|
+
preamble_lines.append(f" (+{len(entries) - 20} more)")
|
|
159
|
+
preamble_lines.append("")
|
|
160
|
+
|
|
161
|
+
preamble_text = "\n".join(preamble_lines)
|
|
162
|
+
tokens_used = _estimate_tokens(preamble_text)
|
|
163
|
+
|
|
164
|
+
# Greedily add symbols until budget is exhausted
|
|
165
|
+
top = []
|
|
166
|
+
for s in all_ranked:
|
|
167
|
+
entry_text = _build_symbol_entry_text(s)
|
|
168
|
+
entry_tokens = _estimate_tokens(entry_text)
|
|
169
|
+
if tokens_used + entry_tokens > budget:
|
|
170
|
+
break
|
|
171
|
+
tokens_used += entry_tokens
|
|
172
|
+
top.append(s)
|
|
173
|
+
else:
|
|
174
|
+
top = all_ranked
|
|
175
|
+
tokens_used = 0 # not tracked when budget is off
|
|
176
|
+
|
|
177
|
+
if json_mode:
|
|
178
|
+
data = {
|
|
179
|
+
"files": total_files,
|
|
180
|
+
"symbols": sym_count,
|
|
181
|
+
"edges": edge_count,
|
|
182
|
+
"languages": dict(lang_counts.most_common(8)),
|
|
183
|
+
"edge_kinds": {r["kind"]: r["cnt"] for r in edge_kinds},
|
|
184
|
+
"directories": [{"name": d, "files": c} for d, c in dir_items],
|
|
185
|
+
"entry_points": entries,
|
|
186
|
+
"top_symbols": [
|
|
187
|
+
{
|
|
188
|
+
"name": s["name"],
|
|
189
|
+
"kind": s["kind"],
|
|
190
|
+
"signature": s["signature"] or "",
|
|
191
|
+
"location": loc(s["file_path"], s["line_start"]),
|
|
192
|
+
"pagerank": round(s["pagerank"] or 0, 4),
|
|
193
|
+
}
|
|
194
|
+
for s in top
|
|
195
|
+
],
|
|
196
|
+
}
|
|
197
|
+
summary = {
|
|
198
|
+
"files": total_files,
|
|
199
|
+
"symbols": sym_count,
|
|
200
|
+
"edges": edge_count,
|
|
201
|
+
}
|
|
202
|
+
if budget is not None:
|
|
203
|
+
summary["token_budget"] = budget
|
|
204
|
+
summary["tokens_used"] = tokens_used
|
|
205
|
+
data["token_budget"] = budget
|
|
206
|
+
data["tokens_used"] = tokens_used
|
|
207
|
+
click.echo(
|
|
208
|
+
to_json(
|
|
209
|
+
json_envelope(
|
|
210
|
+
"map",
|
|
211
|
+
summary=summary,
|
|
212
|
+
**data,
|
|
213
|
+
)
|
|
214
|
+
)
|
|
215
|
+
)
|
|
216
|
+
return
|
|
217
|
+
|
|
218
|
+
# --- Text output ---
|
|
219
|
+
if budget is not None:
|
|
220
|
+
# Preamble already built above; emit it directly
|
|
221
|
+
click.echo(preamble_text, nl=False)
|
|
222
|
+
else:
|
|
223
|
+
lang_str = ", ".join(f"{lang}={n}" for lang, n in lang_counts.most_common(8))
|
|
224
|
+
edge_str = ", ".join(f"{r['kind']}={r['cnt']}" for r in edge_kinds) if edge_kinds else "none"
|
|
225
|
+
|
|
226
|
+
click.echo(f"Files: {total_files} Symbols: {sym_count} Edges: {edge_count}")
|
|
227
|
+
click.echo(f"Languages: {lang_str}")
|
|
228
|
+
click.echo(f"Edge kinds: {edge_str}")
|
|
229
|
+
click.echo()
|
|
230
|
+
|
|
231
|
+
dir_rows = [[d, str(c)] for d, c in (dir_items if full else dir_items[:15])]
|
|
232
|
+
click.echo(section("Directories:", []))
|
|
233
|
+
click.echo(
|
|
234
|
+
format_table(
|
|
235
|
+
["dir", "files"],
|
|
236
|
+
dir_rows,
|
|
237
|
+
budget=0 if full else 15,
|
|
238
|
+
)
|
|
239
|
+
)
|
|
240
|
+
click.echo()
|
|
241
|
+
|
|
242
|
+
if entries:
|
|
243
|
+
click.echo("Entry points:")
|
|
244
|
+
for e in entries if full else entries[:20]:
|
|
245
|
+
click.echo(f" {e}")
|
|
246
|
+
if not full and len(entries) > 20:
|
|
247
|
+
click.echo(f" (+{len(entries) - 20} more)")
|
|
248
|
+
click.echo()
|
|
249
|
+
|
|
250
|
+
if top:
|
|
251
|
+
rows = []
|
|
252
|
+
for s in top:
|
|
253
|
+
sig = format_signature(s["signature"], max_len=50)
|
|
254
|
+
rows.append(
|
|
255
|
+
[
|
|
256
|
+
abbrev_kind(s["kind"]),
|
|
257
|
+
s["name"],
|
|
258
|
+
sig,
|
|
259
|
+
loc(s["file_path"], s["line_start"]),
|
|
260
|
+
f"{(s['pagerank'] or 0):.4f}",
|
|
261
|
+
]
|
|
262
|
+
)
|
|
263
|
+
click.echo("Top symbols (PageRank):")
|
|
264
|
+
click.echo(
|
|
265
|
+
format_table(
|
|
266
|
+
["kind", "name", "signature", "location", "PR"],
|
|
267
|
+
rows,
|
|
268
|
+
)
|
|
269
|
+
)
|
|
270
|
+
else:
|
|
271
|
+
click.echo("No graph metrics available. Run `roam index` first.")
|
|
272
|
+
|
|
273
|
+
if budget is not None:
|
|
274
|
+
click.echo()
|
|
275
|
+
click.echo(f"Token budget: {tokens_used}/{budget} used")
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"""Detect suboptimal algorithms and suggest better approaches (algo command)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections import defaultdict
|
|
6
|
+
|
|
7
|
+
import click
|
|
8
|
+
|
|
9
|
+
from roam.catalog.fixes import get_fix
|
|
10
|
+
from roam.catalog.tasks import get_task, get_tip
|
|
11
|
+
from roam.commands.resolve import ensure_index
|
|
12
|
+
from roam.db.connection import open_db
|
|
13
|
+
from roam.output.formatter import abbrev_kind, json_envelope, to_json
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@click.command()
|
|
17
|
+
@click.option("--task", "task_filter", default=None, help="Filter by task ID (e.g. sorting, membership)")
|
|
18
|
+
@click.option(
|
|
19
|
+
"--confidence",
|
|
20
|
+
"confidence_filter",
|
|
21
|
+
default=None,
|
|
22
|
+
type=click.Choice(["high", "medium", "low"], case_sensitive=False),
|
|
23
|
+
help="Filter by confidence level",
|
|
24
|
+
)
|
|
25
|
+
@click.option(
|
|
26
|
+
"--profile",
|
|
27
|
+
"profile",
|
|
28
|
+
default="balanced",
|
|
29
|
+
type=click.Choice(["balanced", "strict", "aggressive"], case_sensitive=False),
|
|
30
|
+
help="Precision profile (strict reduces false positives; aggressive surfaces more candidates)",
|
|
31
|
+
)
|
|
32
|
+
@click.option("--limit", "-n", default=30, help="Max findings to show")
|
|
33
|
+
@click.pass_context
|
|
34
|
+
def math_cmd(ctx, task_filter, confidence_filter, profile, limit):
|
|
35
|
+
"""Detect suboptimal algorithms and suggest better approaches.
|
|
36
|
+
|
|
37
|
+
Scans indexed symbols for common algorithmic anti-patterns
|
|
38
|
+
(manual sort, linear search, nested-loop lookup, busy wait, etc.)
|
|
39
|
+
and recommends better alternatives from a universal catalog.
|
|
40
|
+
|
|
41
|
+
Primary name: algo. Alias: math (backward compat).
|
|
42
|
+
"""
|
|
43
|
+
json_mode = ctx.obj.get("json") if ctx.obj else False
|
|
44
|
+
sarif_mode = ctx.obj.get("sarif") if ctx.obj else False
|
|
45
|
+
ensure_index()
|
|
46
|
+
|
|
47
|
+
from roam.catalog.detectors import run_detectors
|
|
48
|
+
|
|
49
|
+
with open_db(readonly=True) as conn:
|
|
50
|
+
findings, detector_meta = run_detectors(
|
|
51
|
+
conn,
|
|
52
|
+
task_filter,
|
|
53
|
+
confidence_filter,
|
|
54
|
+
profile=profile,
|
|
55
|
+
return_meta=True,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# Build symbol_id -> language mapping for language-aware tips
|
|
59
|
+
sym_ids = [f["symbol_id"] for f in findings if f.get("symbol_id")]
|
|
60
|
+
lang_map: dict[int, str] = {}
|
|
61
|
+
if sym_ids:
|
|
62
|
+
from roam.db.connection import batched_in
|
|
63
|
+
|
|
64
|
+
rows = batched_in(
|
|
65
|
+
conn,
|
|
66
|
+
"SELECT s.id, f.language FROM symbols s JOIN files f ON s.file_id = f.id WHERE s.id IN ({ph})",
|
|
67
|
+
sym_ids,
|
|
68
|
+
)
|
|
69
|
+
for r in rows:
|
|
70
|
+
if r["language"]:
|
|
71
|
+
lang_map[r["id"]] = r["language"]
|
|
72
|
+
|
|
73
|
+
# Enrich findings with language-aware tips
|
|
74
|
+
for f in findings:
|
|
75
|
+
lang = lang_map.get(f.get("symbol_id"), "")
|
|
76
|
+
f["language"] = lang
|
|
77
|
+
f["tip"] = get_tip(f["task_id"], f["suggested_way"], lang)
|
|
78
|
+
if not f.get("fix"):
|
|
79
|
+
f["fix"] = get_fix(f["task_id"], lang)
|
|
80
|
+
|
|
81
|
+
# Sort by impact score first, then confidence.
|
|
82
|
+
_conf_order = {"high": 0, "medium": 1, "low": 2}
|
|
83
|
+
findings.sort(
|
|
84
|
+
key=lambda f: (
|
|
85
|
+
-float(f.get("impact_score", 0.0) or 0.0),
|
|
86
|
+
_conf_order.get(f["confidence"], 9),
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
# Apply limit
|
|
91
|
+
truncated = len(findings) > limit
|
|
92
|
+
findings = findings[:limit]
|
|
93
|
+
|
|
94
|
+
# Group by task category
|
|
95
|
+
by_category = defaultdict(list)
|
|
96
|
+
for f in findings:
|
|
97
|
+
task = get_task(f["task_id"])
|
|
98
|
+
cat = task["category"] if task else "other"
|
|
99
|
+
by_category[cat].append(f)
|
|
100
|
+
|
|
101
|
+
by_confidence = defaultdict(int)
|
|
102
|
+
for f in findings:
|
|
103
|
+
by_confidence[f["confidence"]] += 1
|
|
104
|
+
|
|
105
|
+
total = len(findings)
|
|
106
|
+
conf_parts = []
|
|
107
|
+
for c in ("high", "medium", "low"):
|
|
108
|
+
if by_confidence.get(c):
|
|
109
|
+
conf_parts.append(f"{by_confidence[c]} {c}")
|
|
110
|
+
conf_str = ", ".join(conf_parts) if conf_parts else "none"
|
|
111
|
+
|
|
112
|
+
verdict = (
|
|
113
|
+
f"{total} algorithmic improvement{'s' if total != 1 else ''} found ({conf_str})"
|
|
114
|
+
if total
|
|
115
|
+
else "No algorithmic issues detected"
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
if sarif_mode:
|
|
119
|
+
from roam.output.sarif import algo_to_sarif, write_sarif
|
|
120
|
+
|
|
121
|
+
sarif = algo_to_sarif(
|
|
122
|
+
findings,
|
|
123
|
+
detector_meta.get("detector_metadata", {}),
|
|
124
|
+
)
|
|
125
|
+
click.echo(write_sarif(sarif))
|
|
126
|
+
return
|
|
127
|
+
|
|
128
|
+
# --- JSON output ---
|
|
129
|
+
if json_mode:
|
|
130
|
+
click.echo(
|
|
131
|
+
to_json(
|
|
132
|
+
json_envelope(
|
|
133
|
+
"algo",
|
|
134
|
+
summary={
|
|
135
|
+
"verdict": verdict,
|
|
136
|
+
"total": total,
|
|
137
|
+
"by_category": dict((k, len(v)) for k, v in by_category.items()),
|
|
138
|
+
"by_confidence": dict(by_confidence),
|
|
139
|
+
"truncated": truncated,
|
|
140
|
+
"detectors_executed": detector_meta.get("detectors_executed", 0),
|
|
141
|
+
"detectors_failed": detector_meta.get("detectors_failed", 0),
|
|
142
|
+
"failed_detectors": detector_meta.get("failed_detectors", []),
|
|
143
|
+
"detector_metadata": detector_meta.get("detector_metadata", {}),
|
|
144
|
+
"profile": detector_meta.get("profile", profile),
|
|
145
|
+
"profile_filtered": detector_meta.get("profile_filtered", 0),
|
|
146
|
+
"max_impact_score": max(
|
|
147
|
+
[float(f.get("impact_score", 0.0) or 0.0) for f in findings],
|
|
148
|
+
default=0.0,
|
|
149
|
+
),
|
|
150
|
+
},
|
|
151
|
+
findings=findings,
|
|
152
|
+
)
|
|
153
|
+
)
|
|
154
|
+
)
|
|
155
|
+
return
|
|
156
|
+
|
|
157
|
+
# --- Text output ---
|
|
158
|
+
click.echo(f"VERDICT: {verdict}")
|
|
159
|
+
click.echo("Ordering: highest impact first")
|
|
160
|
+
click.echo(
|
|
161
|
+
f"Profile: {detector_meta.get('profile', profile)} "
|
|
162
|
+
f"(filtered {detector_meta.get('profile_filtered', 0)} low-signal findings)"
|
|
163
|
+
)
|
|
164
|
+
if detector_meta.get("detectors_failed"):
|
|
165
|
+
click.echo(f"NOTE: {detector_meta['detectors_failed']} detector(s) failed (use --json for details).")
|
|
166
|
+
if not findings:
|
|
167
|
+
return
|
|
168
|
+
|
|
169
|
+
click.echo()
|
|
170
|
+
|
|
171
|
+
# Group by task_id for display
|
|
172
|
+
by_task = defaultdict(list)
|
|
173
|
+
for f in findings:
|
|
174
|
+
by_task[f["task_id"]].append(f)
|
|
175
|
+
|
|
176
|
+
for task_id, task_findings in by_task.items():
|
|
177
|
+
task = get_task(task_id)
|
|
178
|
+
task_name = task["name"] if task else task_id
|
|
179
|
+
click.echo(f"{task_name} ({len(task_findings)}):")
|
|
180
|
+
|
|
181
|
+
for f in task_findings:
|
|
182
|
+
kind_abbr = abbrev_kind(f["kind"])
|
|
183
|
+
name = f["symbol_name"]
|
|
184
|
+
location = f["location"]
|
|
185
|
+
conf = f["confidence"]
|
|
186
|
+
impact_score = float(f.get("impact_score", 0.0) or 0.0)
|
|
187
|
+
|
|
188
|
+
# Get catalog info for display
|
|
189
|
+
detected = None
|
|
190
|
+
suggested = None
|
|
191
|
+
if task:
|
|
192
|
+
for w in task["ways"]:
|
|
193
|
+
if w["id"] == f["detected_way"]:
|
|
194
|
+
detected = w
|
|
195
|
+
if w["id"] == f["suggested_way"]:
|
|
196
|
+
suggested = w
|
|
197
|
+
|
|
198
|
+
click.echo(f" {kind_abbr:<5s} {name:<40s} {location} [{conf}, impact={impact_score:.1f}]")
|
|
199
|
+
if detected:
|
|
200
|
+
click.echo(f" Current: {detected['name']} -- {detected['time']}")
|
|
201
|
+
if suggested:
|
|
202
|
+
click.echo(f" Better: {suggested['name']} -- {suggested['time']}")
|
|
203
|
+
tip_text = f.get("tip", "")
|
|
204
|
+
if tip_text:
|
|
205
|
+
click.echo(f" Tip: {tip_text}")
|
|
206
|
+
fix_text = f.get("fix", "")
|
|
207
|
+
if fix_text:
|
|
208
|
+
click.echo(f" Fix: {fix_text.splitlines()[0]}")
|
|
209
|
+
|
|
210
|
+
click.echo()
|
|
211
|
+
|
|
212
|
+
if truncated:
|
|
213
|
+
click.echo(f" (showing {limit} of more findings, use --limit to see more)")
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""Generate MCP server configuration for AI coding platforms."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
import click
|
|
8
|
+
|
|
9
|
+
from roam.output.formatter import json_envelope, to_json
|
|
10
|
+
|
|
11
|
+
# Platform config templates
|
|
12
|
+
_CONFIGS = {
|
|
13
|
+
"claude-code": {
|
|
14
|
+
"description": "Claude Code CLI",
|
|
15
|
+
"setup_command": "claude mcp add roam-code -- roam mcp",
|
|
16
|
+
"instructions": [
|
|
17
|
+
"Run: claude mcp add roam-code -- roam mcp",
|
|
18
|
+
"Or add to .mcp.json in your project root:",
|
|
19
|
+
],
|
|
20
|
+
"json_config": {"mcpServers": {"roam-code": {"command": "roam", "args": ["mcp"]}}},
|
|
21
|
+
},
|
|
22
|
+
"cursor": {
|
|
23
|
+
"description": "Cursor IDE",
|
|
24
|
+
"instructions": [
|
|
25
|
+
"Add to .cursor/mcp.json in your project root:",
|
|
26
|
+
],
|
|
27
|
+
"json_config": {"mcpServers": {"roam-code": {"command": "roam", "args": ["mcp"]}}},
|
|
28
|
+
},
|
|
29
|
+
"windsurf": {
|
|
30
|
+
"description": "Windsurf IDE",
|
|
31
|
+
"instructions": [
|
|
32
|
+
"Add to ~/.codeium/windsurf/mcp_config.json:",
|
|
33
|
+
],
|
|
34
|
+
"json_config": {"mcpServers": {"roam-code": {"command": "roam", "args": ["mcp"]}}},
|
|
35
|
+
},
|
|
36
|
+
"vscode": {
|
|
37
|
+
"description": "VS Code (Copilot Agent Mode)",
|
|
38
|
+
"instructions": [
|
|
39
|
+
"Add to .vscode/mcp.json in your project root:",
|
|
40
|
+
],
|
|
41
|
+
"json_config": {"servers": {"roam-code": {"type": "stdio", "command": "roam", "args": ["mcp"]}}},
|
|
42
|
+
},
|
|
43
|
+
"gemini-cli": {
|
|
44
|
+
"description": "Gemini CLI",
|
|
45
|
+
"instructions": [
|
|
46
|
+
"Add to ~/.gemini/settings.json:",
|
|
47
|
+
],
|
|
48
|
+
"json_config": {"mcpServers": {"roam-code": {"command": "roam", "args": ["mcp"]}}},
|
|
49
|
+
},
|
|
50
|
+
"codex-cli": {
|
|
51
|
+
"description": "OpenAI Codex CLI",
|
|
52
|
+
"instructions": [
|
|
53
|
+
"Add to ~/.codex/config.json or use:",
|
|
54
|
+
"codex --mcp roam-code='roam mcp'",
|
|
55
|
+
],
|
|
56
|
+
"json_config": {"mcpServers": {"roam-code": {"command": "roam", "args": ["mcp"]}}},
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@click.command("mcp-setup")
|
|
62
|
+
@click.argument("platform", type=click.Choice(sorted(_CONFIGS.keys())), required=False)
|
|
63
|
+
@click.pass_context
|
|
64
|
+
def mcp_setup(ctx, platform):
|
|
65
|
+
"""Generate MCP server config for AI coding platforms.
|
|
66
|
+
|
|
67
|
+
\b
|
|
68
|
+
Supported platforms:
|
|
69
|
+
claude-code Claude Code CLI
|
|
70
|
+
cursor Cursor IDE
|
|
71
|
+
windsurf Windsurf IDE
|
|
72
|
+
vscode VS Code (Copilot Agent Mode)
|
|
73
|
+
gemini-cli Gemini CLI
|
|
74
|
+
codex-cli OpenAI Codex CLI
|
|
75
|
+
|
|
76
|
+
\b
|
|
77
|
+
Examples:
|
|
78
|
+
roam mcp-setup claude-code
|
|
79
|
+
roam mcp-setup cursor
|
|
80
|
+
roam --json mcp-setup vscode
|
|
81
|
+
"""
|
|
82
|
+
json_mode = ctx.obj.get("json") if ctx.obj else False
|
|
83
|
+
|
|
84
|
+
if not platform:
|
|
85
|
+
# List all platforms
|
|
86
|
+
if json_mode:
|
|
87
|
+
click.echo(
|
|
88
|
+
to_json(
|
|
89
|
+
json_envelope(
|
|
90
|
+
"mcp-setup",
|
|
91
|
+
summary={"verdict": f"{len(_CONFIGS)} platforms supported"},
|
|
92
|
+
platforms=list(_CONFIGS.keys()),
|
|
93
|
+
)
|
|
94
|
+
)
|
|
95
|
+
)
|
|
96
|
+
return
|
|
97
|
+
click.echo("Supported platforms:\n")
|
|
98
|
+
for name, cfg in sorted(_CONFIGS.items()):
|
|
99
|
+
click.echo(f" {name:16s} {cfg['description']}")
|
|
100
|
+
click.echo("\nUsage: roam mcp-setup <platform>")
|
|
101
|
+
return
|
|
102
|
+
|
|
103
|
+
cfg = _CONFIGS[platform]
|
|
104
|
+
|
|
105
|
+
if json_mode:
|
|
106
|
+
click.echo(
|
|
107
|
+
to_json(
|
|
108
|
+
json_envelope(
|
|
109
|
+
"mcp-setup",
|
|
110
|
+
summary={
|
|
111
|
+
"verdict": f"Config for {cfg['description']}",
|
|
112
|
+
"platform": platform,
|
|
113
|
+
},
|
|
114
|
+
platform=platform,
|
|
115
|
+
description=cfg["description"],
|
|
116
|
+
instructions=cfg.get("instructions", []),
|
|
117
|
+
config=cfg.get("json_config", {}),
|
|
118
|
+
setup_command=cfg.get("setup_command"),
|
|
119
|
+
)
|
|
120
|
+
)
|
|
121
|
+
)
|
|
122
|
+
return
|
|
123
|
+
|
|
124
|
+
# Text output
|
|
125
|
+
click.echo(f"=== {cfg['description']} ===\n")
|
|
126
|
+
for instruction in cfg.get("instructions", []):
|
|
127
|
+
click.echo(f" {instruction}")
|
|
128
|
+
|
|
129
|
+
if cfg.get("setup_command"):
|
|
130
|
+
click.echo(f"\n Quick setup:\n {cfg['setup_command']}\n")
|
|
131
|
+
|
|
132
|
+
json_config = cfg.get("json_config")
|
|
133
|
+
if json_config:
|
|
134
|
+
click.echo("\n Configuration JSON:")
|
|
135
|
+
click.echo(json.dumps(json_config, indent=2))
|