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,193 @@
|
|
|
1
|
+
"""Documentation coverage and staleness analysis for exported symbols."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections import defaultdict
|
|
6
|
+
|
|
7
|
+
import click
|
|
8
|
+
|
|
9
|
+
from roam.commands.cmd_doc_staleness import _analyze_staleness
|
|
10
|
+
from roam.commands.resolve import ensure_index
|
|
11
|
+
from roam.db.connection import find_project_root, open_db
|
|
12
|
+
from roam.output.formatter import abbrev_kind, json_envelope, loc, to_json
|
|
13
|
+
|
|
14
|
+
_PUBLIC_SYMBOLS_SQL = """
|
|
15
|
+
SELECT s.id, s.name, s.kind, s.signature,
|
|
16
|
+
s.line_start, s.line_end, s.docstring,
|
|
17
|
+
s.visibility, s.is_exported,
|
|
18
|
+
f.path AS file_path,
|
|
19
|
+
COALESCE(gm.pagerank, 0.0) AS pagerank
|
|
20
|
+
FROM symbols s
|
|
21
|
+
JOIN files f ON s.file_id = f.id
|
|
22
|
+
LEFT JOIN graph_metrics gm ON gm.symbol_id = s.id
|
|
23
|
+
WHERE s.kind IN ('function', 'class', 'method', 'interface', 'struct', 'enum')
|
|
24
|
+
AND s.is_exported = 1
|
|
25
|
+
AND s.line_start IS NOT NULL
|
|
26
|
+
AND s.line_end IS NOT NULL
|
|
27
|
+
AND s.line_end >= s.line_start
|
|
28
|
+
AND f.path NOT LIKE '%/tests/%'
|
|
29
|
+
AND f.path NOT LIKE '%/test/%'
|
|
30
|
+
AND f.path NOT LIKE '%test\\_%' ESCAPE '\\'
|
|
31
|
+
AND f.path NOT LIKE '%\\_test.%' ESCAPE '\\'
|
|
32
|
+
ORDER BY pagerank DESC, f.path, s.line_start
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _to_symbol_dict(row) -> dict:
|
|
37
|
+
return {
|
|
38
|
+
"id": row["id"],
|
|
39
|
+
"name": row["name"],
|
|
40
|
+
"kind": row["kind"],
|
|
41
|
+
"signature": row["signature"],
|
|
42
|
+
"line_start": row["line_start"],
|
|
43
|
+
"line_end": row["line_end"],
|
|
44
|
+
"docstring": row["docstring"] or "",
|
|
45
|
+
"visibility": row["visibility"] or "public",
|
|
46
|
+
"is_exported": bool(row["is_exported"]),
|
|
47
|
+
"file_path": row["file_path"],
|
|
48
|
+
"pagerank": float(row["pagerank"] or 0.0),
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _has_docs(symbol: dict) -> bool:
|
|
53
|
+
return bool((symbol.get("docstring") or "").strip())
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _compute_coverage(symbols: list[dict]) -> tuple[int, int, float]:
|
|
57
|
+
total = len(symbols)
|
|
58
|
+
documented = sum(1 for s in symbols if _has_docs(s))
|
|
59
|
+
if total <= 0:
|
|
60
|
+
return 0, 0, 100.0
|
|
61
|
+
pct = (documented / total) * 100.0
|
|
62
|
+
return total, documented, round(pct, 1)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _missing_docs(symbols: list[dict]) -> list[dict]:
|
|
66
|
+
missing = [s for s in symbols if not _has_docs(s)]
|
|
67
|
+
missing.sort(
|
|
68
|
+
key=lambda s: (-float(s.get("pagerank", 0.0)), s["file_path"], s["line_start"]),
|
|
69
|
+
)
|
|
70
|
+
return [
|
|
71
|
+
{
|
|
72
|
+
"name": s["name"],
|
|
73
|
+
"kind": s["kind"],
|
|
74
|
+
"file": s["file_path"],
|
|
75
|
+
"line": s["line_start"],
|
|
76
|
+
"pagerank": round(float(s.get("pagerank", 0.0)), 6),
|
|
77
|
+
}
|
|
78
|
+
for s in missing
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _stale_docs(symbols: list[dict], threshold_days: int) -> list[dict]:
|
|
83
|
+
documented = [s for s in symbols if _has_docs(s)]
|
|
84
|
+
if not documented:
|
|
85
|
+
return []
|
|
86
|
+
|
|
87
|
+
by_file: dict[str, list[dict]] = defaultdict(list)
|
|
88
|
+
for s in documented:
|
|
89
|
+
by_file[s["file_path"]].append(
|
|
90
|
+
{
|
|
91
|
+
"name": s["name"],
|
|
92
|
+
"kind": s["kind"],
|
|
93
|
+
"file_path": s["file_path"],
|
|
94
|
+
"line_start": s["line_start"],
|
|
95
|
+
"line_end": s["line_end"],
|
|
96
|
+
"docstring": s["docstring"],
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
return _analyze_staleness(by_file, find_project_root(), threshold_days)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@click.command("docs-coverage")
|
|
104
|
+
@click.option(
|
|
105
|
+
"--limit",
|
|
106
|
+
default=20,
|
|
107
|
+
show_default=True,
|
|
108
|
+
help="Maximum number of missing/stale symbols to display.",
|
|
109
|
+
)
|
|
110
|
+
@click.option(
|
|
111
|
+
"--days",
|
|
112
|
+
default=90,
|
|
113
|
+
show_default=True,
|
|
114
|
+
help="Staleness threshold in days (body changed N+ days after docs).",
|
|
115
|
+
)
|
|
116
|
+
@click.option(
|
|
117
|
+
"--threshold",
|
|
118
|
+
type=int,
|
|
119
|
+
default=0,
|
|
120
|
+
show_default=True,
|
|
121
|
+
help="Fail with exit code 5 if coverage %% is below threshold (0 = no gate).",
|
|
122
|
+
)
|
|
123
|
+
@click.pass_context
|
|
124
|
+
def docs_coverage(ctx, limit, days, threshold):
|
|
125
|
+
"""Analyze exported-symbol doc coverage and stale docs in one report."""
|
|
126
|
+
json_mode = ctx.obj.get("json") if ctx.obj else False
|
|
127
|
+
ensure_index()
|
|
128
|
+
|
|
129
|
+
with open_db(readonly=True) as conn:
|
|
130
|
+
rows = conn.execute(_PUBLIC_SYMBOLS_SQL).fetchall()
|
|
131
|
+
|
|
132
|
+
symbols = [_to_symbol_dict(r) for r in rows]
|
|
133
|
+
total_public, documented_public, coverage_pct = _compute_coverage(symbols)
|
|
134
|
+
missing = _missing_docs(symbols)
|
|
135
|
+
stale = _stale_docs(symbols, days)
|
|
136
|
+
|
|
137
|
+
display_missing = missing[:limit]
|
|
138
|
+
display_stale = stale[:limit]
|
|
139
|
+
|
|
140
|
+
gate_passed = True
|
|
141
|
+
if threshold > 0 and coverage_pct < float(threshold):
|
|
142
|
+
gate_passed = False
|
|
143
|
+
|
|
144
|
+
if json_mode:
|
|
145
|
+
payload = json_envelope(
|
|
146
|
+
"docs-coverage",
|
|
147
|
+
summary={
|
|
148
|
+
"public_symbols": total_public,
|
|
149
|
+
"documented_symbols": documented_public,
|
|
150
|
+
"coverage_pct": coverage_pct,
|
|
151
|
+
"missing_docs": len(missing),
|
|
152
|
+
"stale_docs": len(stale),
|
|
153
|
+
"threshold": threshold,
|
|
154
|
+
"gate_passed": gate_passed,
|
|
155
|
+
"verdict": (f"{coverage_pct:.1f}% doc coverage ({documented_public}/{total_public} public symbols)"),
|
|
156
|
+
},
|
|
157
|
+
missing_docs=display_missing,
|
|
158
|
+
stale_docs=display_stale,
|
|
159
|
+
threshold_days=days,
|
|
160
|
+
)
|
|
161
|
+
click.echo(to_json(payload))
|
|
162
|
+
|
|
163
|
+
if not gate_passed:
|
|
164
|
+
from roam.exit_codes import EXIT_GATE_FAILURE
|
|
165
|
+
|
|
166
|
+
ctx.exit(EXIT_GATE_FAILURE)
|
|
167
|
+
return
|
|
168
|
+
|
|
169
|
+
click.echo("Documentation coverage\n")
|
|
170
|
+
click.echo(f" Public symbols: {total_public}\n Documented: {documented_public}\n Coverage: {coverage_pct:.1f}%")
|
|
171
|
+
click.echo(f" Missing docs: {len(missing)}\n Stale docs (>{days}d): {len(stale)}")
|
|
172
|
+
|
|
173
|
+
if display_missing:
|
|
174
|
+
click.echo("\nTop undocumented symbols (PageRank-ranked):")
|
|
175
|
+
for item in display_missing:
|
|
176
|
+
click.echo(
|
|
177
|
+
f" {item['name']:<25s} {abbrev_kind(item['kind']):<5s} "
|
|
178
|
+
f"{loc(item['file'], item['line'])} PR={item['pagerank']:.6f}"
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
if display_stale:
|
|
182
|
+
click.echo(f"\nStale docs (>{days} days drift):")
|
|
183
|
+
for item in display_stale:
|
|
184
|
+
click.echo(
|
|
185
|
+
f" {item['name']:<25s} {abbrev_kind(item['kind']):<5s} "
|
|
186
|
+
f"{loc(item['file'], item['line'])} drift={item['drift_days']}d"
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
if not gate_passed:
|
|
190
|
+
click.echo(f"\n GATE FAILED: coverage {coverage_pct:.1f}% below threshold {threshold}%")
|
|
191
|
+
from roam.exit_codes import EXIT_GATE_FAILURE
|
|
192
|
+
|
|
193
|
+
ctx.exit(EXIT_GATE_FAILURE)
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
"""Setup diagnostics command — checks environment, dependencies, and index state.
|
|
2
|
+
|
|
3
|
+
Exit codes:
|
|
4
|
+
0 All checks passed.
|
|
5
|
+
1 One or more checks failed.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import shutil
|
|
11
|
+
import sys
|
|
12
|
+
import time
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
import click
|
|
16
|
+
|
|
17
|
+
from roam.output.formatter import json_envelope, to_json
|
|
18
|
+
|
|
19
|
+
# ---------------------------------------------------------------------------
|
|
20
|
+
# Individual check functions
|
|
21
|
+
# ---------------------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _check_python_version() -> dict:
|
|
25
|
+
"""Python >= 3.9 required."""
|
|
26
|
+
vi = sys.version_info
|
|
27
|
+
version_str = f"{vi.major}.{vi.minor}.{vi.micro}"
|
|
28
|
+
passed = (vi.major, vi.minor) >= (3, 9)
|
|
29
|
+
return {
|
|
30
|
+
"name": "Python version",
|
|
31
|
+
"passed": passed,
|
|
32
|
+
"detail": f"Python {version_str} (>= 3.9 required)",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _check_tree_sitter() -> dict:
|
|
37
|
+
"""tree-sitter package importable."""
|
|
38
|
+
try:
|
|
39
|
+
import tree_sitter
|
|
40
|
+
|
|
41
|
+
version = getattr(tree_sitter, "__version__", "unknown")
|
|
42
|
+
return {
|
|
43
|
+
"name": "tree-sitter",
|
|
44
|
+
"passed": True,
|
|
45
|
+
"detail": f"tree-sitter {version}",
|
|
46
|
+
}
|
|
47
|
+
except ImportError as exc:
|
|
48
|
+
return {
|
|
49
|
+
"name": "tree-sitter",
|
|
50
|
+
"passed": False,
|
|
51
|
+
"detail": f"not installed: {exc}",
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _check_tree_sitter_language_pack() -> dict:
|
|
56
|
+
"""tree-sitter-language-pack importable."""
|
|
57
|
+
try:
|
|
58
|
+
import tree_sitter_language_pack
|
|
59
|
+
|
|
60
|
+
version = getattr(tree_sitter_language_pack, "__version__", "unknown")
|
|
61
|
+
return {
|
|
62
|
+
"name": "tree-sitter-language-pack",
|
|
63
|
+
"passed": True,
|
|
64
|
+
"detail": f"tree-sitter-language-pack {version}",
|
|
65
|
+
}
|
|
66
|
+
except ImportError as exc:
|
|
67
|
+
return {
|
|
68
|
+
"name": "tree-sitter-language-pack",
|
|
69
|
+
"passed": False,
|
|
70
|
+
"detail": f"not installed: {exc}",
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _check_git() -> dict:
|
|
75
|
+
"""git executable available on PATH."""
|
|
76
|
+
git_path = shutil.which("git")
|
|
77
|
+
if git_path is None:
|
|
78
|
+
return {
|
|
79
|
+
"name": "git executable",
|
|
80
|
+
"passed": False,
|
|
81
|
+
"detail": "git not found on PATH",
|
|
82
|
+
}
|
|
83
|
+
# Get version string
|
|
84
|
+
try:
|
|
85
|
+
import subprocess
|
|
86
|
+
|
|
87
|
+
result = subprocess.run(
|
|
88
|
+
["git", "--version"],
|
|
89
|
+
capture_output=True,
|
|
90
|
+
text=True,
|
|
91
|
+
timeout=5,
|
|
92
|
+
)
|
|
93
|
+
version_line = result.stdout.strip() if result.returncode == 0 else ""
|
|
94
|
+
# "git version 2.43.0" -> "2.43.0"
|
|
95
|
+
version = version_line.replace("git version", "").strip() or "unknown"
|
|
96
|
+
except Exception:
|
|
97
|
+
version = "unknown"
|
|
98
|
+
return {
|
|
99
|
+
"name": "git executable",
|
|
100
|
+
"passed": True,
|
|
101
|
+
"detail": f"git {version}",
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _check_networkx() -> dict:
|
|
106
|
+
"""networkx importable."""
|
|
107
|
+
try:
|
|
108
|
+
import networkx
|
|
109
|
+
|
|
110
|
+
version = getattr(networkx, "__version__", "unknown")
|
|
111
|
+
return {
|
|
112
|
+
"name": "networkx",
|
|
113
|
+
"passed": True,
|
|
114
|
+
"detail": f"networkx {version}",
|
|
115
|
+
}
|
|
116
|
+
except ImportError as exc:
|
|
117
|
+
return {
|
|
118
|
+
"name": "networkx",
|
|
119
|
+
"passed": False,
|
|
120
|
+
"detail": f"not installed: {exc}",
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _check_index_exists() -> dict:
|
|
125
|
+
"""Index DB file exists at the expected path."""
|
|
126
|
+
try:
|
|
127
|
+
from roam.db.connection import get_db_path
|
|
128
|
+
|
|
129
|
+
db_path = get_db_path()
|
|
130
|
+
except Exception as exc:
|
|
131
|
+
return {
|
|
132
|
+
"name": "Index exists",
|
|
133
|
+
"passed": False,
|
|
134
|
+
"detail": f"could not determine DB path: {exc}",
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
exists = db_path.exists()
|
|
138
|
+
return {
|
|
139
|
+
"name": "Index exists",
|
|
140
|
+
"passed": exists,
|
|
141
|
+
"detail": str(db_path) if exists else f"not found: {db_path} (run `roam init`)",
|
|
142
|
+
"_db_path": str(db_path) if exists else None,
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def _check_index_freshness(db_path_str: str | None) -> dict:
|
|
147
|
+
"""Index mtime <= 24 hours old."""
|
|
148
|
+
if db_path_str is None:
|
|
149
|
+
return {
|
|
150
|
+
"name": "Index freshness",
|
|
151
|
+
"passed": False,
|
|
152
|
+
"detail": "index does not exist (run `roam init`)",
|
|
153
|
+
}
|
|
154
|
+
db_path = Path(db_path_str)
|
|
155
|
+
if not db_path.exists():
|
|
156
|
+
return {
|
|
157
|
+
"name": "Index freshness",
|
|
158
|
+
"passed": False,
|
|
159
|
+
"detail": "index does not exist (run `roam init`)",
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
age_s = time.time() - db_path.stat().st_mtime
|
|
163
|
+
age_h = age_s / 3600.0
|
|
164
|
+
stale = age_h > 24.0
|
|
165
|
+
|
|
166
|
+
if age_s < 60:
|
|
167
|
+
age_str = f"{int(age_s)} second{'s' if int(age_s) != 1 else ''} ago"
|
|
168
|
+
elif age_s < 3600:
|
|
169
|
+
age_m = int(age_s / 60)
|
|
170
|
+
age_str = f"{age_m} minute{'s' if age_m != 1 else ''} ago"
|
|
171
|
+
elif age_s < 86400:
|
|
172
|
+
age_h_int = int(age_h)
|
|
173
|
+
age_str = f"{age_h_int} hour{'s' if age_h_int != 1 else ''} ago"
|
|
174
|
+
else:
|
|
175
|
+
age_d = int(age_h / 24)
|
|
176
|
+
age_str = f"{age_d} day{'s' if age_d != 1 else ''} ago"
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
"name": "Index freshness",
|
|
180
|
+
"passed": not stale,
|
|
181
|
+
"detail": (f"fresh ({age_str})" if not stale else f"stale ({age_str}, run `roam index` to refresh)"),
|
|
182
|
+
"_age_s": round(age_s, 1),
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def _check_sqlite(db_path_str: str | None) -> dict:
|
|
187
|
+
"""SQLite can open and query the index DB."""
|
|
188
|
+
if db_path_str is None:
|
|
189
|
+
return {
|
|
190
|
+
"name": "SQLite operational",
|
|
191
|
+
"passed": False,
|
|
192
|
+
"detail": "index does not exist (run `roam init`)",
|
|
193
|
+
}
|
|
194
|
+
db_path = Path(db_path_str)
|
|
195
|
+
if not db_path.exists():
|
|
196
|
+
return {
|
|
197
|
+
"name": "SQLite operational",
|
|
198
|
+
"passed": False,
|
|
199
|
+
"detail": "index does not exist (run `roam init`)",
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
try:
|
|
203
|
+
import sqlite3
|
|
204
|
+
|
|
205
|
+
conn = sqlite3.connect(str(db_path), timeout=5)
|
|
206
|
+
# PRAGMA integrity_check verifies the file is a real, non-corrupted DB
|
|
207
|
+
rows = conn.execute("PRAGMA integrity_check").fetchall()
|
|
208
|
+
conn.close()
|
|
209
|
+
if rows and rows[0][0] == "ok":
|
|
210
|
+
return {
|
|
211
|
+
"name": "SQLite operational",
|
|
212
|
+
"passed": True,
|
|
213
|
+
"detail": "SQLite operational",
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
"name": "SQLite operational",
|
|
217
|
+
"passed": False,
|
|
218
|
+
"detail": "SQLite integrity check failed",
|
|
219
|
+
}
|
|
220
|
+
except Exception as exc:
|
|
221
|
+
return {
|
|
222
|
+
"name": "SQLite operational",
|
|
223
|
+
"passed": False,
|
|
224
|
+
"detail": f"SQLite error: {exc}",
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
# ---------------------------------------------------------------------------
|
|
229
|
+
# CLI command
|
|
230
|
+
# ---------------------------------------------------------------------------
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
@click.command("doctor")
|
|
234
|
+
@click.pass_context
|
|
235
|
+
def doctor(ctx):
|
|
236
|
+
"""Diagnose environment setup: Python, dependencies, index state, disk space.
|
|
237
|
+
|
|
238
|
+
Checks each requirement and reports PASS or FAIL. Useful for onboarding
|
|
239
|
+
new developers or troubleshooting agent setup issues.
|
|
240
|
+
|
|
241
|
+
\b
|
|
242
|
+
Exit codes:
|
|
243
|
+
0 All checks passed.
|
|
244
|
+
1 One or more checks failed.
|
|
245
|
+
|
|
246
|
+
\b
|
|
247
|
+
Examples:
|
|
248
|
+
roam doctor
|
|
249
|
+
roam --json doctor
|
|
250
|
+
"""
|
|
251
|
+
json_mode = ctx.obj.get("json") if ctx.obj else False
|
|
252
|
+
|
|
253
|
+
# --- Run all checks ---
|
|
254
|
+
checks: list[dict] = []
|
|
255
|
+
|
|
256
|
+
checks.append(_check_python_version())
|
|
257
|
+
checks.append(_check_tree_sitter())
|
|
258
|
+
checks.append(_check_tree_sitter_language_pack())
|
|
259
|
+
checks.append(_check_git())
|
|
260
|
+
checks.append(_check_networkx())
|
|
261
|
+
|
|
262
|
+
# Index checks: existence feeds into freshness and SQLite checks
|
|
263
|
+
index_check = _check_index_exists()
|
|
264
|
+
checks.append(index_check)
|
|
265
|
+
|
|
266
|
+
db_path_str = index_check.get("_db_path")
|
|
267
|
+
checks.append(_check_index_freshness(db_path_str))
|
|
268
|
+
checks.append(_check_sqlite(db_path_str))
|
|
269
|
+
|
|
270
|
+
# --- Compute summary ---
|
|
271
|
+
total = len(checks)
|
|
272
|
+
failed = [c for c in checks if not c["passed"]]
|
|
273
|
+
passed_count = total - len(failed)
|
|
274
|
+
|
|
275
|
+
if not failed:
|
|
276
|
+
verdict = f"all {total} checks passed"
|
|
277
|
+
elif len(failed) == 1:
|
|
278
|
+
verdict = f"1 check failed ({failed[0]['name']})"
|
|
279
|
+
else:
|
|
280
|
+
verdict = f"{len(failed)} checks failed"
|
|
281
|
+
|
|
282
|
+
# Strip private keys (prefixed with _) before output
|
|
283
|
+
clean_checks = [{k: v for k, v in c.items() if not k.startswith("_")} for c in checks]
|
|
284
|
+
|
|
285
|
+
if json_mode:
|
|
286
|
+
click.echo(
|
|
287
|
+
to_json(
|
|
288
|
+
json_envelope(
|
|
289
|
+
"doctor",
|
|
290
|
+
summary={
|
|
291
|
+
"verdict": verdict,
|
|
292
|
+
"total": total,
|
|
293
|
+
"passed": passed_count,
|
|
294
|
+
"failed": len(failed),
|
|
295
|
+
"all_passed": len(failed) == 0,
|
|
296
|
+
},
|
|
297
|
+
checks=clean_checks,
|
|
298
|
+
failed_checks=[c for c in clean_checks if not c["passed"]],
|
|
299
|
+
)
|
|
300
|
+
)
|
|
301
|
+
)
|
|
302
|
+
if failed:
|
|
303
|
+
from roam.exit_codes import EXIT_ERROR
|
|
304
|
+
|
|
305
|
+
ctx.exit(EXIT_ERROR)
|
|
306
|
+
return
|
|
307
|
+
|
|
308
|
+
# --- Text output ---
|
|
309
|
+
click.echo(f"VERDICT: {verdict}\n")
|
|
310
|
+
for c in clean_checks:
|
|
311
|
+
label = "PASS" if c["passed"] else "FAIL"
|
|
312
|
+
click.echo(f" [{label}] {c['detail']}")
|
|
313
|
+
|
|
314
|
+
if failed:
|
|
315
|
+
click.echo()
|
|
316
|
+
click.echo(f" {len(failed)} check{'s' if len(failed) != 1 else ''} failed.")
|
|
317
|
+
from roam.exit_codes import EXIT_ERROR
|
|
318
|
+
|
|
319
|
+
ctx.exit(EXIT_ERROR)
|