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,295 @@
|
|
|
1
|
+
"""Identify safe refactoring boundaries for a symbol or file."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import click
|
|
6
|
+
|
|
7
|
+
from roam.commands.graph_helpers import bfs_nx
|
|
8
|
+
from roam.commands.resolve import ensure_index, find_symbol
|
|
9
|
+
from roam.db.connection import batched_in, open_db
|
|
10
|
+
from roam.output.formatter import abbrev_kind, format_table, json_envelope, loc, to_json
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _resolve_file_symbols(conn, target):
|
|
14
|
+
"""If *target* looks like a file path, return all symbol IDs in that file."""
|
|
15
|
+
# Normalize separators for matching
|
|
16
|
+
normalized = target.replace("\\", "/")
|
|
17
|
+
|
|
18
|
+
row = conn.execute(
|
|
19
|
+
"SELECT id FROM files WHERE path = ? OR path LIKE ?",
|
|
20
|
+
(normalized, f"%{normalized}"),
|
|
21
|
+
).fetchone()
|
|
22
|
+
if row is None:
|
|
23
|
+
return None, None
|
|
24
|
+
|
|
25
|
+
file_id = row["id"]
|
|
26
|
+
syms = conn.execute("SELECT id FROM symbols WHERE file_id = ?", (file_id,)).fetchall()
|
|
27
|
+
return file_id, {s["id"] for s in syms}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _classify_zone(boundary_count):
|
|
31
|
+
"""Return (zone_label, zone_description)."""
|
|
32
|
+
if boundary_count == 0:
|
|
33
|
+
return "ISOLATED", "no external connections -- safe to refactor freely"
|
|
34
|
+
if boundary_count <= 5:
|
|
35
|
+
return (
|
|
36
|
+
"CONTAINED",
|
|
37
|
+
f"{boundary_count} boundary symbols -- refactor with minor API contract awareness",
|
|
38
|
+
)
|
|
39
|
+
return "EXPOSED", f"{boundary_count} boundary symbols -- refactor carefully, many consumers"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@click.command("safe-zones")
|
|
43
|
+
@click.argument("target")
|
|
44
|
+
@click.option(
|
|
45
|
+
"--depth",
|
|
46
|
+
default=5,
|
|
47
|
+
type=int,
|
|
48
|
+
show_default=True,
|
|
49
|
+
help="Max BFS depth for propagation analysis.",
|
|
50
|
+
)
|
|
51
|
+
@click.pass_context
|
|
52
|
+
def safe_zones(ctx, target, depth):
|
|
53
|
+
"""Identify safe refactoring boundaries for a symbol or file.
|
|
54
|
+
|
|
55
|
+
Answers: if I refactor TARGET, what is the containment boundary?
|
|
56
|
+
How far can changes propagate?
|
|
57
|
+
|
|
58
|
+
TARGET is a symbol name (or file:symbol) or a file path.
|
|
59
|
+
"""
|
|
60
|
+
json_mode = ctx.obj.get("json") if ctx.obj else False
|
|
61
|
+
ensure_index()
|
|
62
|
+
|
|
63
|
+
with open_db(readonly=True) as conn:
|
|
64
|
+
# --- Resolve target to seed symbol IDs ---
|
|
65
|
+
seed_ids: set[int] = set()
|
|
66
|
+
target_label = target
|
|
67
|
+
|
|
68
|
+
# Try as file first
|
|
69
|
+
file_id, file_syms = _resolve_file_symbols(conn, target)
|
|
70
|
+
if file_syms:
|
|
71
|
+
seed_ids = file_syms
|
|
72
|
+
# Fetch the canonical path for display
|
|
73
|
+
frow = conn.execute("SELECT path FROM files WHERE id = ?", (file_id,)).fetchone()
|
|
74
|
+
if frow:
|
|
75
|
+
target_label = frow["path"]
|
|
76
|
+
else:
|
|
77
|
+
# Try as symbol
|
|
78
|
+
sym = find_symbol(conn, target)
|
|
79
|
+
if sym is None:
|
|
80
|
+
click.echo(f"Symbol or file not found: {target}")
|
|
81
|
+
raise SystemExit(1)
|
|
82
|
+
seed_ids = {sym["id"]}
|
|
83
|
+
target_label = sym["qualified_name"] or sym["name"]
|
|
84
|
+
|
|
85
|
+
# --- Build graph ---
|
|
86
|
+
try:
|
|
87
|
+
from roam.graph.builder import build_symbol_graph
|
|
88
|
+
except ImportError:
|
|
89
|
+
click.echo("Graph module not available. Run `roam index` first.")
|
|
90
|
+
return
|
|
91
|
+
|
|
92
|
+
G = build_symbol_graph(conn)
|
|
93
|
+
|
|
94
|
+
# Filter seed_ids to nodes present in the graph
|
|
95
|
+
seed_ids = {s for s in seed_ids if s in G}
|
|
96
|
+
if not seed_ids:
|
|
97
|
+
click.echo("Target symbol(s) not found in the dependency graph.")
|
|
98
|
+
return
|
|
99
|
+
|
|
100
|
+
# --- BFS forward (callees / downstream) and backward (callers / upstream) ---
|
|
101
|
+
forward = bfs_nx(G, seed_ids, depth, direction="forward")
|
|
102
|
+
backward = bfs_nx(G, seed_ids, depth, direction="backward")
|
|
103
|
+
|
|
104
|
+
# Internal zone = union of forward and backward, including seeds
|
|
105
|
+
internal_ids = set(forward.keys()) | set(backward.keys())
|
|
106
|
+
|
|
107
|
+
# --- Identify boundary symbols ---
|
|
108
|
+
# A boundary symbol is an internal node that has at least one
|
|
109
|
+
# neighbor outside the internal zone.
|
|
110
|
+
boundary_ids: set[int] = set()
|
|
111
|
+
external_caller_count: dict[int, int] = {} # boundary_id -> count of external callers
|
|
112
|
+
external_callee_count: dict[int, int] = {} # boundary_id -> count of external callees
|
|
113
|
+
|
|
114
|
+
for nid in internal_ids:
|
|
115
|
+
if nid not in G:
|
|
116
|
+
continue
|
|
117
|
+
# Check outgoing edges to external nodes
|
|
118
|
+
for succ in G.successors(nid):
|
|
119
|
+
if succ not in internal_ids:
|
|
120
|
+
boundary_ids.add(nid)
|
|
121
|
+
external_callee_count[nid] = external_callee_count.get(nid, 0) + 1
|
|
122
|
+
# Check incoming edges from external nodes
|
|
123
|
+
for pred in G.predecessors(nid):
|
|
124
|
+
if pred not in internal_ids:
|
|
125
|
+
boundary_ids.add(nid)
|
|
126
|
+
external_caller_count[nid] = external_caller_count.get(nid, 0) + 1
|
|
127
|
+
|
|
128
|
+
# Strictly internal = internal minus boundary
|
|
129
|
+
strictly_internal_ids = internal_ids - boundary_ids
|
|
130
|
+
|
|
131
|
+
# --- Classify ---
|
|
132
|
+
zone_label, zone_desc = _classify_zone(len(boundary_ids))
|
|
133
|
+
|
|
134
|
+
# --- Gather node details from DB for display ---
|
|
135
|
+
all_display_ids = internal_ids | boundary_ids
|
|
136
|
+
if not all_display_ids:
|
|
137
|
+
click.echo("No reachable symbols found.")
|
|
138
|
+
return
|
|
139
|
+
|
|
140
|
+
detail_rows = batched_in(
|
|
141
|
+
conn,
|
|
142
|
+
"SELECT s.id, s.name, s.kind, s.qualified_name, s.line_start, "
|
|
143
|
+
"f.path as file_path "
|
|
144
|
+
"FROM symbols s JOIN files f ON s.file_id = f.id "
|
|
145
|
+
"WHERE s.id IN ({ph})",
|
|
146
|
+
list(all_display_ids),
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
detail_map: dict[int, dict] = {}
|
|
150
|
+
for r in detail_rows:
|
|
151
|
+
detail_map[r["id"]] = {
|
|
152
|
+
"id": r["id"],
|
|
153
|
+
"name": r["name"],
|
|
154
|
+
"kind": r["kind"],
|
|
155
|
+
"qualified_name": r["qualified_name"],
|
|
156
|
+
"line_start": r["line_start"],
|
|
157
|
+
"file_path": r["file_path"],
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
# --- Collect affected files ---
|
|
161
|
+
affected_files: set[str] = set()
|
|
162
|
+
for nid in internal_ids:
|
|
163
|
+
info = detail_map.get(nid)
|
|
164
|
+
if info:
|
|
165
|
+
affected_files.add(info["file_path"])
|
|
166
|
+
|
|
167
|
+
# --- External ref counts for boundary symbols ---
|
|
168
|
+
# Total external references (callers from outside the zone)
|
|
169
|
+
boundary_external_refs: dict[int, int] = {}
|
|
170
|
+
for bid in boundary_ids:
|
|
171
|
+
ext_callers = external_caller_count.get(bid, 0)
|
|
172
|
+
ext_callees = external_callee_count.get(bid, 0)
|
|
173
|
+
boundary_external_refs[bid] = ext_callers + ext_callees
|
|
174
|
+
|
|
175
|
+
# --- JSON output ---
|
|
176
|
+
if json_mode:
|
|
177
|
+
internal_list = []
|
|
178
|
+
for nid in sorted(strictly_internal_ids):
|
|
179
|
+
info = detail_map.get(nid)
|
|
180
|
+
if not info:
|
|
181
|
+
continue
|
|
182
|
+
internal_list.append(
|
|
183
|
+
{
|
|
184
|
+
"name": info["name"],
|
|
185
|
+
"kind": abbrev_kind(info["kind"]),
|
|
186
|
+
"file": info["file_path"],
|
|
187
|
+
"line": info["line_start"],
|
|
188
|
+
}
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
boundary_list = []
|
|
192
|
+
for nid in sorted(boundary_ids, key=lambda b: boundary_external_refs.get(b, 0), reverse=True):
|
|
193
|
+
info = detail_map.get(nid)
|
|
194
|
+
if not info:
|
|
195
|
+
continue
|
|
196
|
+
boundary_list.append(
|
|
197
|
+
{
|
|
198
|
+
"name": info["name"],
|
|
199
|
+
"kind": abbrev_kind(info["kind"]),
|
|
200
|
+
"file": info["file_path"],
|
|
201
|
+
"line": info["line_start"],
|
|
202
|
+
"external_callers": external_caller_count.get(nid, 0),
|
|
203
|
+
"external_callees": external_callee_count.get(nid, 0),
|
|
204
|
+
"external_refs": boundary_external_refs.get(nid, 0),
|
|
205
|
+
}
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
click.echo(
|
|
209
|
+
to_json(
|
|
210
|
+
json_envelope(
|
|
211
|
+
"safe-zones",
|
|
212
|
+
summary={
|
|
213
|
+
"zone": zone_label,
|
|
214
|
+
"internal_symbols": len(strictly_internal_ids),
|
|
215
|
+
"boundary_symbols": len(boundary_ids),
|
|
216
|
+
"total_symbols": len(internal_ids),
|
|
217
|
+
"affected_files": len(affected_files),
|
|
218
|
+
},
|
|
219
|
+
target=target_label,
|
|
220
|
+
depth=depth,
|
|
221
|
+
zone=zone_label,
|
|
222
|
+
zone_description=zone_desc,
|
|
223
|
+
internal_symbols=len(strictly_internal_ids),
|
|
224
|
+
boundary_symbols=len(boundary_ids),
|
|
225
|
+
total_symbols=len(internal_ids),
|
|
226
|
+
affected_files=sorted(affected_files),
|
|
227
|
+
internal=internal_list,
|
|
228
|
+
boundary=boundary_list,
|
|
229
|
+
)
|
|
230
|
+
)
|
|
231
|
+
)
|
|
232
|
+
return
|
|
233
|
+
|
|
234
|
+
# --- Text output ---
|
|
235
|
+
click.echo(f"Safe zone analysis for `{target_label}`:\n")
|
|
236
|
+
click.echo(f"Zone: {zone_label} ({zone_desc})\n")
|
|
237
|
+
|
|
238
|
+
# Internal symbols
|
|
239
|
+
if strictly_internal_ids:
|
|
240
|
+
click.echo("Internal (safe to change freely):")
|
|
241
|
+
int_rows = []
|
|
242
|
+
for nid in sorted(strictly_internal_ids):
|
|
243
|
+
info = detail_map.get(nid)
|
|
244
|
+
if not info:
|
|
245
|
+
continue
|
|
246
|
+
int_rows.append(
|
|
247
|
+
[
|
|
248
|
+
info["name"],
|
|
249
|
+
abbrev_kind(info["kind"]),
|
|
250
|
+
loc(info["file_path"], info["line_start"]),
|
|
251
|
+
]
|
|
252
|
+
)
|
|
253
|
+
click.echo(format_table(["name", "kind", "location"], int_rows, budget=20))
|
|
254
|
+
click.echo()
|
|
255
|
+
|
|
256
|
+
# Boundary symbols
|
|
257
|
+
if boundary_ids:
|
|
258
|
+
click.echo("Boundary (maintain contracts):")
|
|
259
|
+
bnd_rows = []
|
|
260
|
+
for nid in sorted(boundary_ids, key=lambda b: boundary_external_refs.get(b, 0), reverse=True):
|
|
261
|
+
info = detail_map.get(nid)
|
|
262
|
+
if not info:
|
|
263
|
+
continue
|
|
264
|
+
ext_c = external_caller_count.get(nid, 0)
|
|
265
|
+
ext_e = external_callee_count.get(nid, 0)
|
|
266
|
+
refs_parts = []
|
|
267
|
+
if ext_c:
|
|
268
|
+
refs_parts.append(f"{ext_c} caller{'s' if ext_c != 1 else ''}")
|
|
269
|
+
if ext_e:
|
|
270
|
+
refs_parts.append(f"{ext_e} callee{'s' if ext_e != 1 else ''}")
|
|
271
|
+
refs_label = ", ".join(refs_parts) if refs_parts else "0 external refs"
|
|
272
|
+
bnd_rows.append(
|
|
273
|
+
[
|
|
274
|
+
info["name"],
|
|
275
|
+
abbrev_kind(info["kind"]),
|
|
276
|
+
loc(info["file_path"], info["line_start"]),
|
|
277
|
+
f"({refs_label})",
|
|
278
|
+
]
|
|
279
|
+
)
|
|
280
|
+
click.echo(
|
|
281
|
+
format_table(
|
|
282
|
+
["name", "kind", "location", "external refs"],
|
|
283
|
+
bnd_rows,
|
|
284
|
+
budget=20,
|
|
285
|
+
)
|
|
286
|
+
)
|
|
287
|
+
click.echo()
|
|
288
|
+
|
|
289
|
+
# Blast radius summary
|
|
290
|
+
click.echo(
|
|
291
|
+
f"Blast radius: {len(internal_ids)} symbols in "
|
|
292
|
+
f"{len(affected_files)} file{'s' if len(affected_files) != 1 else ''}"
|
|
293
|
+
f" (contained to {', '.join(sorted(affected_files)[:5])}"
|
|
294
|
+
f"{'...' if len(affected_files) > 5 else ''})"
|
|
295
|
+
)
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"""Show and validate the roam JSON envelope schema."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json as _json
|
|
6
|
+
|
|
7
|
+
import click
|
|
8
|
+
|
|
9
|
+
from roam.output.formatter import json_envelope, to_json
|
|
10
|
+
from roam.output.schema_registry import get_schema_info, validate_envelope
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@click.command("schema")
|
|
14
|
+
@click.option(
|
|
15
|
+
"--validate",
|
|
16
|
+
"validate_file",
|
|
17
|
+
type=click.Path(exists=True),
|
|
18
|
+
default=None,
|
|
19
|
+
help="Validate a JSON file against the envelope schema.",
|
|
20
|
+
)
|
|
21
|
+
@click.option("--changelog", "show_changelog", is_flag=True, help="Show the schema changelog.")
|
|
22
|
+
@click.pass_context
|
|
23
|
+
def schema_cmd(ctx, validate_file, show_changelog):
|
|
24
|
+
"""Show the roam JSON envelope schema and validate output files."""
|
|
25
|
+
json_mode = ctx.obj.get("json") if ctx.obj else False
|
|
26
|
+
schema = get_schema_info()
|
|
27
|
+
|
|
28
|
+
# --validate FILE mode
|
|
29
|
+
if validate_file:
|
|
30
|
+
_handle_validate(validate_file, schema, json_mode)
|
|
31
|
+
return
|
|
32
|
+
|
|
33
|
+
# --changelog mode
|
|
34
|
+
if show_changelog:
|
|
35
|
+
_handle_changelog(schema, json_mode)
|
|
36
|
+
return
|
|
37
|
+
|
|
38
|
+
# Default: show schema info
|
|
39
|
+
_handle_info(schema, json_mode)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _handle_info(schema: dict, json_mode: bool) -> None:
|
|
43
|
+
"""Display schema information."""
|
|
44
|
+
if json_mode:
|
|
45
|
+
click.echo(
|
|
46
|
+
to_json(
|
|
47
|
+
json_envelope(
|
|
48
|
+
"schema",
|
|
49
|
+
summary={
|
|
50
|
+
"verdict": f"{schema['name']} (version {schema['version']})",
|
|
51
|
+
"schema_name": schema["name"],
|
|
52
|
+
"schema_version": schema["version"],
|
|
53
|
+
},
|
|
54
|
+
schema=schema,
|
|
55
|
+
)
|
|
56
|
+
)
|
|
57
|
+
)
|
|
58
|
+
return
|
|
59
|
+
|
|
60
|
+
click.echo(f"VERDICT: {schema['name']} (version {schema['version']})")
|
|
61
|
+
click.echo()
|
|
62
|
+
click.echo("REQUIRED FIELDS:")
|
|
63
|
+
for field, desc in schema["required_fields"].items():
|
|
64
|
+
click.echo(f" {field:20s} {desc}")
|
|
65
|
+
click.echo()
|
|
66
|
+
click.echo("CHANGELOG:")
|
|
67
|
+
for entry in schema["changelog"]:
|
|
68
|
+
changes = "; ".join(entry["changes"])
|
|
69
|
+
click.echo(f" {entry['version']} ({entry['date']}): {changes}")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _handle_changelog(schema: dict, json_mode: bool) -> None:
|
|
73
|
+
"""Display schema changelog."""
|
|
74
|
+
if json_mode:
|
|
75
|
+
click.echo(
|
|
76
|
+
to_json(
|
|
77
|
+
json_envelope(
|
|
78
|
+
"schema",
|
|
79
|
+
summary={
|
|
80
|
+
"verdict": f"{schema['name']} changelog ({len(schema['changelog'])} entries)",
|
|
81
|
+
"schema_name": schema["name"],
|
|
82
|
+
"schema_version": schema["version"],
|
|
83
|
+
},
|
|
84
|
+
changelog=schema["changelog"],
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
|
+
)
|
|
88
|
+
return
|
|
89
|
+
|
|
90
|
+
click.echo(f"VERDICT: {schema['name']} changelog ({len(schema['changelog'])} entries)")
|
|
91
|
+
click.echo()
|
|
92
|
+
click.echo("CHANGELOG:")
|
|
93
|
+
for entry in schema["changelog"]:
|
|
94
|
+
changes = "; ".join(entry["changes"])
|
|
95
|
+
click.echo(f" {entry['version']} ({entry['date']}): {changes}")
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _handle_validate(filepath: str, schema: dict, json_mode: bool) -> None:
|
|
99
|
+
"""Validate a JSON file against the envelope schema."""
|
|
100
|
+
try:
|
|
101
|
+
with open(filepath, "r", encoding="utf-8") as f:
|
|
102
|
+
data = _json.load(f)
|
|
103
|
+
except _json.JSONDecodeError as e:
|
|
104
|
+
if json_mode:
|
|
105
|
+
click.echo(
|
|
106
|
+
to_json(
|
|
107
|
+
json_envelope(
|
|
108
|
+
"schema",
|
|
109
|
+
summary={
|
|
110
|
+
"verdict": "invalid JSON file",
|
|
111
|
+
"schema_name": schema["name"],
|
|
112
|
+
"schema_version": schema["version"],
|
|
113
|
+
"is_valid": False,
|
|
114
|
+
},
|
|
115
|
+
validation={"errors": [f"JSON parse error: {e}"]},
|
|
116
|
+
)
|
|
117
|
+
)
|
|
118
|
+
)
|
|
119
|
+
else:
|
|
120
|
+
click.echo("VERDICT: invalid JSON file")
|
|
121
|
+
click.echo(f" Error: {e}")
|
|
122
|
+
return
|
|
123
|
+
|
|
124
|
+
is_valid, errors = validate_envelope(data)
|
|
125
|
+
|
|
126
|
+
if json_mode:
|
|
127
|
+
validation_info = {
|
|
128
|
+
"is_valid": is_valid,
|
|
129
|
+
"errors": errors,
|
|
130
|
+
"fields_present": [f for f in schema["required_fields"] if f in data],
|
|
131
|
+
"fields_missing": [f for f in schema["required_fields"] if f not in data],
|
|
132
|
+
}
|
|
133
|
+
if "schema_version" in data:
|
|
134
|
+
validation_info["detected_version"] = data["schema_version"]
|
|
135
|
+
if "command" in data:
|
|
136
|
+
validation_info["detected_command"] = data["command"]
|
|
137
|
+
click.echo(
|
|
138
|
+
to_json(
|
|
139
|
+
json_envelope(
|
|
140
|
+
"schema",
|
|
141
|
+
summary={
|
|
142
|
+
"verdict": "valid roam-envelope-v1 output" if is_valid else "invalid roam-envelope-v1 output",
|
|
143
|
+
"schema_name": schema["name"],
|
|
144
|
+
"schema_version": schema["version"],
|
|
145
|
+
"is_valid": is_valid,
|
|
146
|
+
},
|
|
147
|
+
validation=validation_info,
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
)
|
|
151
|
+
return
|
|
152
|
+
|
|
153
|
+
if is_valid:
|
|
154
|
+
click.echo("VERDICT: valid roam-envelope-v1 output")
|
|
155
|
+
click.echo()
|
|
156
|
+
if "schema_version" in data:
|
|
157
|
+
click.echo(f" schema_version: {data['schema_version']}")
|
|
158
|
+
if "command" in data:
|
|
159
|
+
click.echo(f" command: {data['command']}")
|
|
160
|
+
field_count = sum(1 for f in schema["required_fields"] if f in data)
|
|
161
|
+
click.echo(f" All {field_count} required fields present")
|
|
162
|
+
else:
|
|
163
|
+
click.echo("VERDICT: invalid roam-envelope-v1 output")
|
|
164
|
+
click.echo()
|
|
165
|
+
for err in errors:
|
|
166
|
+
click.echo(f" ERROR: {err}")
|