codmap 0.0.28__tar.gz → 0.0.30__tar.gz
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.
- {codmap-0.0.28/codmap.egg-info → codmap-0.0.30}/PKG-INFO +6 -4
- {codmap-0.0.28 → codmap-0.0.30}/README.md +5 -3
- {codmap-0.0.28 → codmap-0.0.30}/codemap/cli.py +67 -15
- {codmap-0.0.28 → codmap-0.0.30}/codemap/extract/attrflow.py +121 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/extract/roots.py +29 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/model.py +7 -1
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/review.py +112 -15
- {codmap-0.0.28 → codmap-0.0.30/codmap.egg-info}/PKG-INFO +6 -4
- {codmap-0.0.28 → codmap-0.0.30}/codmap.egg-info/SOURCES.txt +3 -0
- {codmap-0.0.28 → codmap-0.0.30}/pyproject.toml +1 -1
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_m15_review.py +4 -2
- codmap-0.0.30/tests/test_r1c82_review_changed_lines.py +163 -0
- codmap-0.0.30/tests/test_r1c83_foreign_graph_paths.py +125 -0
- codmap-0.0.30/tests/test_r1c84_missing_roots.py +126 -0
- {codmap-0.0.28 → codmap-0.0.30}/LICENSE +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/__init__.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/apidiff.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/arch.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/diagnostics.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/extract/__init__.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/extract/behavior.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/extract/dataflow.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/extract/dispatch.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/extract/griffe_extractor.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/extract/gsource.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/extract/probe.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/extract/union.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/freshness.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/incremental.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/integrations/__init__.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/integrations/base.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/integrations/cocoindex.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/integrations/gate.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/integrations/gitnexus.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/integrations/registry.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/integrations/transport.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/provenance.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/query.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/scope.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/__init__.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/_scip_pb2.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/api_surface.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/apidiff.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/architecture.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/audit.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/check.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/ctags.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/currency.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/impact.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/limits.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/livingdocs.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/mcp_server.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/mermaid.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/pack.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/rag.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/scip.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/semantic.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/server.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/session.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/subsystems.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/serve/vault.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/store.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/tomlio.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codemap/watch.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codmap.egg-info/dependency_links.txt +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codmap.egg-info/entry_points.txt +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codmap.egg-info/requires.txt +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/codmap.egg-info/top_level.txt +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/setup.cfg +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_epistemic.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_gitnexus_router.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_impact_depth.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_integrations.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_issue3_serve_freshness.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_livingdocs.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_m0_api_surface.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_m11_argcontract.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_m12_dataflow.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_m16_architecture.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_m17_mcp.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_m18_freshness.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_m1_5_semantics.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_m1_query.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_m2_views.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_m32_watch.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_m3_serve.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_m4_behavior.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_m5_deep.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_m6_repo_scope.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_m7_dispatch.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_m9_family.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_pack_honesty.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c13_callgraph_accuracy.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c13_grep_vs_graph.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c16_semantic.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c20_attribute_edges.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c21_flat_layout.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c22_source_visible_refs.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c23_hard_python.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c24_test_mapping.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c25_provenance.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c26_deep_union.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c27_config_honesty.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c28_limit_envelope.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c29_lazy_imports.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c2_ctags.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c30_local_import_calls.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c30f1_reexport_calls.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c30f2_check_scope.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c31_path_origin.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c32_report_json.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c33_query_signature.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c34_signature_kinds.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c35_contract_location.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c36_target_resolution.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c37_rule_mutation.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c38_tool_drift.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c39_edge_resolution.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c3_arch_contract.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c3_dogfood.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c40_flow_reach.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c41_scope_membership.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c42_deep_tier_stability.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c43_incremental_splice.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c44_absent_answers.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c45_repeat_union.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c46_shadowed_definitions.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c47_incremental_resample.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c48_type_checking_imports.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c49_type_only_cycles.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c4_complexity.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c50_flow_entry_points.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c53_narrowing_declared.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c54_deterministic_rendering.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c55_override_grade.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c56_stub_files.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c57_facade_package.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c58_cycle_tangles.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c59_completeness_drop.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c5_apidiff.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c60_nested_definitions.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c62_phantom_rules.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c63_answer_format.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c64_dependency_probe.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c66_pack_direction.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c68_dotted_imports.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c69_contract_validation.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c6_pack.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c70_check_graph_currency.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c71_attribute_chain_calls.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c72_flat_inference_in_packages.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c73_cli_version.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c74_call_site_conservation.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c75_reexported_class_calls.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c76_contract_table_typo.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c77_gate_probe_battery.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c78_forbidden_chains.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c7_edge_vocab.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c80_tests_through_helpers.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c8_deadcode.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_r1c9_incremental.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_scip_export.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_scope.py +0 -0
- {codmap-0.0.28 → codmap-0.0.30}/tests/test_subsystems.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codmap
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.30
|
|
4
4
|
Summary: Static analyzer that turns a package's source into a queryable code graph.
|
|
5
5
|
Author-email: kogriv <kogriv@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -44,7 +44,7 @@ and a **SCIP index** for interop with Sourcegraph / Glean and other precise-code
|
|
|
44
44
|
|
|
45
45
|
[](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
|
|
46
46
|
|
|
47
|
-
**Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **
|
|
47
|
+
**Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1220 tests with no failures on
|
|
48
48
|
Python 3.11–3.14** ([in CI](docs/ci.md): the full suite including the dogfood pass, a determinism check, a
|
|
49
49
|
wheel smoke test, and ctags/SCIP interop against the real CLIs), warm serve surface with 31 ops (28 exposed
|
|
50
50
|
as MCP tools), and SCIP export. See **[DESIGN.md](DESIGN.md)** (product design &
|
|
@@ -170,7 +170,8 @@ Optional extras: `mcp` (Model Context Protocol server), `scip` (protobuf, for SC
|
|
|
170
170
|
# build the canonical graph of a package (its directory name is the package name every id starts with)
|
|
171
171
|
codemap build ./yourpkg -o graph.json
|
|
172
172
|
|
|
173
|
-
# repo-scoped: add consumers (tests/examples) + docs for blast-radius/impact
|
|
173
|
+
# repo-scoped: add consumers (tests/examples) + docs for blast-radius/impact;
|
|
174
|
+
# one flag per root — a root that is not a directory is refused, exit 2
|
|
174
175
|
codemap build ./yourpkg --deep --mode full --consumer ./tests --docs ./docs -o graph.json
|
|
175
176
|
|
|
176
177
|
# deep tier: union N independent samples (one build misses a real edge ~1 time in 4)
|
|
@@ -221,7 +222,8 @@ codemap serve --graph graph.json --watch
|
|
|
221
222
|
(Ca/Ce/instability), god-objects & call-hubs, per-function complexity (cyclomatic / MI)
|
|
222
223
|
blended with structural coupling.
|
|
223
224
|
- **Impact / blast radius** — who uses X, across the whole repo (core + tests + docs).
|
|
224
|
-
- **Change review** — a diff → the symbols
|
|
225
|
+
- **Change review** — a diff → the symbols its changed lines touch (context lines and comments
|
|
226
|
+
between definitions are not changes), their callers or readers, signature-change surface,
|
|
225
227
|
touched columns, cross-root consumers, risk rank.
|
|
226
228
|
- **Dispatch seams** — registry/factory families and the Protocol each impl satisfies.
|
|
227
229
|
- **Dataflow** — producers/consumers of a string-keyed DataFrame column.
|
|
@@ -8,7 +8,7 @@ and a **SCIP index** for interop with Sourcegraph / Glean and other precise-code
|
|
|
8
8
|
|
|
9
9
|
[](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
|
|
10
10
|
|
|
11
|
-
**Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **
|
|
11
|
+
**Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1220 tests with no failures on
|
|
12
12
|
Python 3.11–3.14** ([in CI](docs/ci.md): the full suite including the dogfood pass, a determinism check, a
|
|
13
13
|
wheel smoke test, and ctags/SCIP interop against the real CLIs), warm serve surface with 31 ops (28 exposed
|
|
14
14
|
as MCP tools), and SCIP export. See **[DESIGN.md](DESIGN.md)** (product design &
|
|
@@ -134,7 +134,8 @@ Optional extras: `mcp` (Model Context Protocol server), `scip` (protobuf, for SC
|
|
|
134
134
|
# build the canonical graph of a package (its directory name is the package name every id starts with)
|
|
135
135
|
codemap build ./yourpkg -o graph.json
|
|
136
136
|
|
|
137
|
-
# repo-scoped: add consumers (tests/examples) + docs for blast-radius/impact
|
|
137
|
+
# repo-scoped: add consumers (tests/examples) + docs for blast-radius/impact;
|
|
138
|
+
# one flag per root — a root that is not a directory is refused, exit 2
|
|
138
139
|
codemap build ./yourpkg --deep --mode full --consumer ./tests --docs ./docs -o graph.json
|
|
139
140
|
|
|
140
141
|
# deep tier: union N independent samples (one build misses a real edge ~1 time in 4)
|
|
@@ -185,7 +186,8 @@ codemap serve --graph graph.json --watch
|
|
|
185
186
|
(Ca/Ce/instability), god-objects & call-hubs, per-function complexity (cyclomatic / MI)
|
|
186
187
|
blended with structural coupling.
|
|
187
188
|
- **Impact / blast radius** — who uses X, across the whole repo (core + tests + docs).
|
|
188
|
-
- **Change review** — a diff → the symbols
|
|
189
|
+
- **Change review** — a diff → the symbols its changed lines touch (context lines and comments
|
|
190
|
+
between definitions are not changes), their callers or readers, signature-change surface,
|
|
189
191
|
touched columns, cross-root consumers, risk rank.
|
|
190
192
|
- **Dispatch seams** — registry/factory families and the Protocol each impl satisfies.
|
|
191
193
|
- **Dataflow** — producers/consumers of a string-keyed DataFrame column.
|
|
@@ -49,7 +49,7 @@ from pathlib import Path
|
|
|
49
49
|
from codemap import store
|
|
50
50
|
from codemap.diagnostics import diagnostics
|
|
51
51
|
from codemap.extract import extract, extract_repo
|
|
52
|
-
from codemap.extract.roots import roots_base
|
|
52
|
+
from codemap.extract.roots import root_problems, roots_base
|
|
53
53
|
from codemap.provenance import build_provenance
|
|
54
54
|
from codemap.query import Query
|
|
55
55
|
from codemap.serve import (
|
|
@@ -100,6 +100,19 @@ def _graph_from(args):
|
|
|
100
100
|
raise SystemExit("error: need --graph <file> or --build <path>")
|
|
101
101
|
|
|
102
102
|
|
|
103
|
+
def _refuse_bad_roots(args) -> bool:
|
|
104
|
+
"""R1-C84: print every unreadable ``--consumer``/``--docs`` root; True means refuse (exit 2).
|
|
105
|
+
|
|
106
|
+
Checked before anything is built — a `--deep` core pass must not spend minutes on a
|
|
107
|
+
graph that will lack a root — and before ``-o`` is touched.
|
|
108
|
+
"""
|
|
109
|
+
problems = root_problems(tuple(getattr(args, "consumer", None) or ()),
|
|
110
|
+
tuple(getattr(args, "docs", None) or ()))
|
|
111
|
+
for p in problems:
|
|
112
|
+
print(f"error: {p}", file=sys.stderr)
|
|
113
|
+
return bool(problems)
|
|
114
|
+
|
|
115
|
+
|
|
103
116
|
def _cmd_build(args) -> int:
|
|
104
117
|
incr_info = None
|
|
105
118
|
repeat = getattr(args, "repeat", None)
|
|
@@ -114,6 +127,8 @@ def _cmd_build(args) -> int:
|
|
|
114
127
|
print(f"error: --repeat {repeat} needs --deep — the fast tier is byte-stable, so "
|
|
115
128
|
"repeating it unions identical samples", file=sys.stderr)
|
|
116
129
|
return 2
|
|
130
|
+
if _refuse_bad_roots(args):
|
|
131
|
+
return 2
|
|
117
132
|
if args.consumer or args.docs:
|
|
118
133
|
if getattr(args, "incremental", False):
|
|
119
134
|
# R1-C44 / D6: the flag used to be swallowed here without a word. Not an
|
|
@@ -311,6 +326,8 @@ def _cmd_watch(args) -> int:
|
|
|
311
326
|
import argparse as _argparse
|
|
312
327
|
from codemap.watch import DebouncedPoller, scope_probe
|
|
313
328
|
|
|
329
|
+
if _refuse_bad_roots(args):
|
|
330
|
+
return 2
|
|
314
331
|
consumers = tuple(args.consumer or ())
|
|
315
332
|
docs = tuple(args.docs or ())
|
|
316
333
|
build_args = _argparse.Namespace(
|
|
@@ -328,7 +345,11 @@ def _cmd_watch(args) -> int:
|
|
|
328
345
|
# and it would pollute a pipeline this watcher is composed into. Everything
|
|
329
346
|
# this command says goes to stderr — stdout stays empty on purpose.
|
|
330
347
|
with contextlib.redirect_stdout(sys.stderr):
|
|
331
|
-
_cmd_build(build_args)
|
|
348
|
+
rc = _cmd_build(build_args)
|
|
349
|
+
if rc != 0:
|
|
350
|
+
# R1-C84: a refusal returns 2 rather than raising (a root deleted while
|
|
351
|
+
# watching); it is a failed rebuild, never "rebuilt".
|
|
352
|
+
raise RuntimeError(f"build exited {rc}")
|
|
332
353
|
except Exception as exc:
|
|
333
354
|
# A failed rebuild leaves the previous graph in place, and says so. Silence
|
|
334
355
|
# here would be the same defect this project keeps fixing: a stale answer
|
|
@@ -402,6 +423,8 @@ def _cmd_scope(args) -> int:
|
|
|
402
423
|
return 0 if not (d["added"] or d["removed"] or d["changed"]) else 1
|
|
403
424
|
if not args.path:
|
|
404
425
|
raise SystemExit("error: scope needs <path> (or --diff A B)")
|
|
426
|
+
if _refuse_bad_roots(args):
|
|
427
|
+
return 2
|
|
405
428
|
scope = resolve_scope(args.path, consumers=tuple(args.consumer or ()),
|
|
406
429
|
docs=tuple(args.docs or ()), use_git=not args.no_git)
|
|
407
430
|
if args.json:
|
|
@@ -545,26 +568,50 @@ def _local_nodeids(ids: list[str], args) -> tuple[list[str], str | None]:
|
|
|
545
568
|
there**: a rewrite that cannot be verified is not printed, and the caveat says which
|
|
546
569
|
directory the untouched path belongs to instead of leaving the reader to find out from
|
|
547
570
|
pytest. The op's own payload keeps the graph-relative id, which is the portable one.
|
|
571
|
+
|
|
572
|
+
R1-C83: a graph built on another machine (or another checkout) records a directory
|
|
573
|
+
that is not here. One base was tried, so a line that ran fine from the repo root still
|
|
574
|
+
drew "could not be located", and from anywhere else there was no way to name the root.
|
|
575
|
+
Now ``--source-root`` is the only base when given; otherwise the sidecar's directory if
|
|
576
|
+
it exists here, then the current one — each path against the first base where that
|
|
577
|
+
file is, so nothing unverified is printed.
|
|
548
578
|
"""
|
|
549
579
|
from codemap.freshness import read_meta
|
|
550
580
|
meta = read_meta(getattr(args, "graph", None) or "") or {}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
581
|
+
recorded = meta.get("roots_base")
|
|
582
|
+
explicit = getattr(args, "source_root", None)
|
|
583
|
+
if explicit:
|
|
584
|
+
bases = [explicit]
|
|
585
|
+
else:
|
|
586
|
+
bases = [b for b in (recorded,) if b and os.path.isdir(b)] + [os.getcwd()]
|
|
587
|
+
out, missing = [], 0
|
|
556
588
|
for nid in ids:
|
|
557
589
|
path, sep, tail = nid.partition("::")
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
590
|
+
for b in bases:
|
|
591
|
+
full = os.path.join(b, path)
|
|
592
|
+
if os.path.exists(full):
|
|
593
|
+
out.append(os.path.relpath(full, os.getcwd()) + sep + tail)
|
|
594
|
+
break
|
|
562
595
|
else:
|
|
563
596
|
out.append(nid)
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
597
|
+
missing += 1
|
|
598
|
+
if missing:
|
|
599
|
+
if explicit:
|
|
600
|
+
return out, (f"{missing} of {len(ids)} path(s) not found under `--source-root "
|
|
601
|
+
f"{explicit}` and are printed as the graph stores them")
|
|
602
|
+
if not recorded:
|
|
603
|
+
return out, ("paths are relative to the build roots' common directory — run from "
|
|
604
|
+
"there, pass `--source-root`, or rebuild with this codemap so the "
|
|
605
|
+
"sidecar records it")
|
|
606
|
+
tried = " and ".join(f"`{b}`" for b in bases)
|
|
607
|
+
away = ("" if os.path.isdir(recorded) else
|
|
608
|
+
f" (the graph was built in `{recorded}`, which is not on this machine)")
|
|
609
|
+
return out, (f"{missing} of {len(ids)} path(s) could not be located under {tried}{away} "
|
|
610
|
+
f"and are printed as the graph stores them — pass `--source-root` with "
|
|
611
|
+
f"the directory the graph's paths are relative to")
|
|
612
|
+
if recorded and not explicit and not os.path.isdir(recorded):
|
|
613
|
+
return out, (f"the graph was built in `{recorded}`, which is not on this machine; "
|
|
614
|
+
f"paths located from the current directory")
|
|
568
615
|
return out, None
|
|
569
616
|
|
|
570
617
|
|
|
@@ -1091,6 +1138,9 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
1091
1138
|
t.add_argument("--all-bands", action="store_true",
|
|
1092
1139
|
help="List every band within --depth, not only the nearest (R1-C80).")
|
|
1093
1140
|
t.add_argument("--format", choices=["text", "json"], default="text")
|
|
1141
|
+
t.add_argument("--source-root", metavar="DIR",
|
|
1142
|
+
help="Directory the graph's paths are relative to on this machine, for the "
|
|
1143
|
+
"printed pytest line (default: the build's own, else the current one).")
|
|
1094
1144
|
t.set_defaults(func=_cmd_tests)
|
|
1095
1145
|
|
|
1096
1146
|
r = sub.add_parser("report", help="Render a report over the graph.")
|
|
@@ -1105,6 +1155,8 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
1105
1155
|
r.add_argument("--min-confidence", choices=["low", "medium", "high"], default=None,
|
|
1106
1156
|
help="report dead-code: only show candidates at/above this confidence.")
|
|
1107
1157
|
r.add_argument("--format", choices=["markdown", "json"], default="markdown")
|
|
1158
|
+
r.add_argument("--source-root", metavar="DIR",
|
|
1159
|
+
help="Where codemap.toml is read for `dead-code` (default: current dir).")
|
|
1108
1160
|
r.set_defaults(func=_cmd_report)
|
|
1109
1161
|
|
|
1110
1162
|
e = sub.add_parser("export", help="Export a view: rag (JSONL) | vault | mermaid | scip | ctags | docs.")
|
|
@@ -106,6 +106,16 @@ def add_attrflow(graph, griffe_root, target_pkg: str, *, deep: bool = False,
|
|
|
106
106
|
edges.add((node_id, attr_id, access, resolution))
|
|
107
107
|
if counts["out"]:
|
|
108
108
|
graph.nodes[node_id].extras["attr_access"] = counts
|
|
109
|
+
# R1-C82 D3b: module-level code and class bodies read constants too — the
|
|
110
|
+
# import-time check `if set(SURFACES) != set(SURFACE_NAMES): raise` is exactly
|
|
111
|
+
# the reader a review of SURFACE_NAMES must name. Source: the module / class.
|
|
112
|
+
for src_id, scope, cls_bound in _non_function_scopes(tree, modpath):
|
|
113
|
+
if src_id not in graph.nodes:
|
|
114
|
+
continue
|
|
115
|
+
for attr_id, access in _scope_name_reads(scope, cls_bound, graph, modpath,
|
|
116
|
+
imports, modmembers, pkg):
|
|
117
|
+
if attr_id != src_id:
|
|
118
|
+
edges.add((src_id, attr_id, access, "name"))
|
|
109
119
|
|
|
110
120
|
for src, attr_id, access, resolution in sorted(edges):
|
|
111
121
|
graph.add_edge(Edge("accesses", src, attr_id,
|
|
@@ -149,6 +159,7 @@ def _own_attr_uses(fnode, graph, modpath, members, imports, modmembers, pkg, scr
|
|
|
149
159
|
# Attributes that are the callee of a call (``self.foo()``) are *method calls*,
|
|
150
160
|
# handled by the behavioral layer — not field access. Skip exactly those.
|
|
151
161
|
call_funcs = {id(n.func) for n in nodes if isinstance(n, ast.Call)}
|
|
162
|
+
yield from _module_name_uses(fnode, nodes, graph, modpath, imports, modmembers, pkg)
|
|
152
163
|
|
|
153
164
|
for node in nodes:
|
|
154
165
|
if isinstance(node, ast.Call) and isinstance(node.func, ast.Name):
|
|
@@ -195,6 +206,116 @@ def _own_attr_uses(fnode, graph, modpath, members, imports, modmembers, pkg, scr
|
|
|
195
206
|
yield from _deep_attr(node, graph, pkg, script)
|
|
196
207
|
|
|
197
208
|
|
|
209
|
+
def _bound_names(fnode, nodes) -> tuple[set[str], set[str]]:
|
|
210
|
+
"""(names bound locally in the function, names declared ``global``)."""
|
|
211
|
+
bound: set[str] = set()
|
|
212
|
+
a = fnode.args
|
|
213
|
+
for arg in (*a.posonlyargs, *a.args, *a.kwonlyargs, a.vararg, a.kwarg):
|
|
214
|
+
if arg is not None:
|
|
215
|
+
bound.add(arg.arg)
|
|
216
|
+
glob: set[str] = set()
|
|
217
|
+
for n in nodes:
|
|
218
|
+
if isinstance(n, ast.Name) and isinstance(n.ctx, (ast.Store, ast.Del)):
|
|
219
|
+
bound.add(n.id)
|
|
220
|
+
elif isinstance(n, (ast.Import, ast.ImportFrom)):
|
|
221
|
+
bound.update((al.asname or al.name).split(".")[0] for al in n.names)
|
|
222
|
+
elif isinstance(n, ast.ExceptHandler) and n.name:
|
|
223
|
+
bound.add(n.name)
|
|
224
|
+
elif isinstance(n, ast.Global):
|
|
225
|
+
glob.update(n.names)
|
|
226
|
+
elif isinstance(n, ast.arg):
|
|
227
|
+
bound.add(n.arg) # lambda parameters
|
|
228
|
+
return bound - glob, glob
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def _module_name_uses(fnode, nodes, graph, modpath, imports, modmembers, pkg):
|
|
232
|
+
"""Bare-name reads of a module attribute: ``x in NAMES`` (R1-C82 D3).
|
|
233
|
+
|
|
234
|
+
``from pkg.contracts import NAMES`` gave only an ``export`` edge and a read of the
|
|
235
|
+
name inside a function gave none, so a module constant had "no consumers" in
|
|
236
|
+
``review``/``impact`` while being read everywhere. Resolved through the module's
|
|
237
|
+
imports or its own members; emitted only onto a real ``attribute`` node. A local
|
|
238
|
+
binding of the same name shadows it. Unresolved bare names are not counted —
|
|
239
|
+
nearly all of them are locals and builtins. Fast tier.
|
|
240
|
+
"""
|
|
241
|
+
bound, glob = _bound_names(fnode, nodes)
|
|
242
|
+
for n in nodes:
|
|
243
|
+
if not isinstance(n, ast.Name):
|
|
244
|
+
continue
|
|
245
|
+
if isinstance(n.ctx, ast.Load):
|
|
246
|
+
if n.id in bound:
|
|
247
|
+
continue
|
|
248
|
+
access = "read"
|
|
249
|
+
elif isinstance(n.ctx, ast.Store) and n.id in glob:
|
|
250
|
+
access = "write" # global NAME; NAME = …
|
|
251
|
+
else:
|
|
252
|
+
continue
|
|
253
|
+
if n.id in imports:
|
|
254
|
+
tgt = imports[n.id]
|
|
255
|
+
if not tgt.startswith(pkg):
|
|
256
|
+
continue
|
|
257
|
+
elif n.id in modmembers:
|
|
258
|
+
tgt = f"{modpath}.{n.id}"
|
|
259
|
+
else:
|
|
260
|
+
continue
|
|
261
|
+
if _is_attribute_node(graph, tgt):
|
|
262
|
+
yield tgt, access, "name"
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
_SCOPE_BARRIERS = (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef, ast.Lambda)
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def _scope_walk(stmts):
|
|
269
|
+
"""Every node of ``stmts`` that belongs to this scope — not into defs, classes, lambdas."""
|
|
270
|
+
todo = list(stmts)
|
|
271
|
+
while todo:
|
|
272
|
+
n = todo.pop()
|
|
273
|
+
yield n
|
|
274
|
+
if isinstance(n, _SCOPE_BARRIERS):
|
|
275
|
+
# decorators, defaults and bases are evaluated in the enclosing scope
|
|
276
|
+
if isinstance(n, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
|
277
|
+
todo.extend(n.decorator_list)
|
|
278
|
+
todo.extend(d for d in (*n.args.defaults, *n.args.kw_defaults) if d is not None)
|
|
279
|
+
elif isinstance(n, ast.ClassDef):
|
|
280
|
+
todo.extend((*n.decorator_list, *n.bases, *(k.value for k in n.keywords)))
|
|
281
|
+
continue
|
|
282
|
+
todo.extend(ast.iter_child_nodes(n))
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def _non_function_scopes(tree, modpath):
|
|
286
|
+
"""(source id, nodes, names bound in that scope or None) for the module and each class body."""
|
|
287
|
+
yield modpath, list(_scope_walk(tree.body)), None
|
|
288
|
+
|
|
289
|
+
def classes(stmts, prefix):
|
|
290
|
+
for st in stmts:
|
|
291
|
+
if isinstance(st, ast.ClassDef):
|
|
292
|
+
cid = f"{prefix}.{st.name}"
|
|
293
|
+
nodes = list(_scope_walk(st.body))
|
|
294
|
+
bound = {n.id for n in nodes if isinstance(n, ast.Name)
|
|
295
|
+
and isinstance(n.ctx, (ast.Store, ast.Del))}
|
|
296
|
+
yield cid, nodes, bound
|
|
297
|
+
yield from classes(st.body, cid)
|
|
298
|
+
yield from classes(tree.body, modpath)
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def _scope_name_reads(nodes, cls_bound, graph, modpath, imports, modmembers, pkg):
|
|
302
|
+
for n in nodes:
|
|
303
|
+
if not (isinstance(n, ast.Name) and isinstance(n.ctx, ast.Load)):
|
|
304
|
+
continue
|
|
305
|
+
if cls_bound is not None and n.id in cls_bound:
|
|
306
|
+
continue
|
|
307
|
+
if n.id in imports:
|
|
308
|
+
tgt = imports[n.id]
|
|
309
|
+
if not tgt.startswith(pkg):
|
|
310
|
+
continue
|
|
311
|
+
elif n.id in modmembers:
|
|
312
|
+
tgt = f"{modpath}.{n.id}"
|
|
313
|
+
else:
|
|
314
|
+
continue
|
|
315
|
+
if _is_attribute_node(graph, tgt):
|
|
316
|
+
yield tgt, "read"
|
|
317
|
+
|
|
318
|
+
|
|
198
319
|
def _deep_attr(node, graph, pkg, script):
|
|
199
320
|
"""Resolve ``obj.field`` via jedi (deep tier); yield (attr_id | None, access, 'deep').
|
|
200
321
|
|
|
@@ -61,6 +61,32 @@ def roots_base(core: str | Path, consumers=(), docs=()) -> Path:
|
|
|
61
61
|
return Path(os.path.commonpath([str(p) for p in parents]))
|
|
62
62
|
|
|
63
63
|
|
|
64
|
+
def root_problems(consumers=(), docs=()) -> list[str]:
|
|
65
|
+
"""Every ``--consumer`` / ``--docs`` root that cannot be read, in words (R1-C84).
|
|
66
|
+
|
|
67
|
+
The scanners skip a root that is not a directory, so a typo or two roots passed in
|
|
68
|
+
one string (`--consumer tests,examples`) built a graph without them, exit 0, and the
|
|
69
|
+
provenance still listed the root as read. Callers refuse on any problem instead.
|
|
70
|
+
An existing empty directory is not a problem: the graph simply has nothing from it.
|
|
71
|
+
"""
|
|
72
|
+
problems = []
|
|
73
|
+
for flag, paths in (("--consumer", consumers), ("--docs", docs)):
|
|
74
|
+
for raw in paths:
|
|
75
|
+
p = Path(raw)
|
|
76
|
+
if p.is_dir():
|
|
77
|
+
continue
|
|
78
|
+
if p.exists():
|
|
79
|
+
problems.append(f"`{flag} {raw}`: not a directory")
|
|
80
|
+
continue
|
|
81
|
+
msg = f"`{flag} {raw}`: no such directory"
|
|
82
|
+
parts = [s for s in str(raw).split(",") if s]
|
|
83
|
+
if len(parts) > 1 and all(Path(s).is_dir() for s in parts):
|
|
84
|
+
msg += (" — looks like a list; pass the flag once per root: `"
|
|
85
|
+
+ " ".join(f"{flag} {s}" for s in parts) + "`")
|
|
86
|
+
problems.append(msg)
|
|
87
|
+
return problems
|
|
88
|
+
|
|
89
|
+
|
|
64
90
|
def _reroot_files(graph, offset: str) -> None:
|
|
65
91
|
"""Prefix every node's ``file`` with ``offset`` (the core pass wrote them relative to
|
|
66
92
|
the core's own parent, which may be below the common origin)."""
|
|
@@ -90,6 +116,9 @@ def extract_repo(
|
|
|
90
116
|
"""
|
|
91
117
|
if mode not in ("thin", "full"):
|
|
92
118
|
raise ValueError(f"mode must be 'thin' or 'full', got {mode!r}")
|
|
119
|
+
problems = root_problems(consumers, docs)
|
|
120
|
+
if problems:
|
|
121
|
+
raise ValueError("; ".join(problems))
|
|
93
122
|
|
|
94
123
|
graph = extract(core, deep=deep, repeat=repeat)
|
|
95
124
|
core_pkg = graph.target
|
|
@@ -118,7 +118,10 @@ SCHEMA_VERSION = "0.13"
|
|
|
118
118
|
# `--all-bands` lists every band, each row carrying its distance and confidence; a helper
|
|
119
119
|
# function inside a collected test module costs no hop in `tests` and `covers`, so
|
|
120
120
|
# distances move where one sits on the path (R1-C80, docs/design/tests_through_helpers.md).
|
|
121
|
-
|
|
121
|
+
# 6 — `review` reads changed lines, not whole hunks; a module's dossier counts direct references
|
|
122
|
+
# to the module (its importers), not every reference into every member, and has no call-site
|
|
123
|
+
# contract; module constants gain `accesses` readers (R1-C82, docs/design/review_changed_lines.md).
|
|
124
|
+
ANSWER_FORMAT = 6
|
|
122
125
|
|
|
123
126
|
# Closed vocabulary of edge types (R1-C7). Node ``kind`` is deliberately an OPEN set
|
|
124
127
|
# (DESIGN §2 — new entity kinds may appear), but edges are TYPED: every relationship
|
|
@@ -181,6 +184,9 @@ RESOLUTIONS: dict[tuple[str, str], dict[str, str]] = {
|
|
|
181
184
|
"how": "`Class(...).attr` — the constructor names the owner"},
|
|
182
185
|
("accesses", "deep"): {"means": "route", "confidence": "inferred",
|
|
183
186
|
"how": "owner type inferred by jedi (deep tier only)"},
|
|
187
|
+
("accesses", "name"): {"means": "route", "confidence": "exact",
|
|
188
|
+
"how": "a module attribute read by bare name — through an import "
|
|
189
|
+
"or in its own module; a local binding shadows it (R1-C82)"},
|
|
184
190
|
("references", "annotation"): {"means": "site", "confidence": "exact",
|
|
185
191
|
"how": "the symbol appears in a type annotation"},
|
|
186
192
|
("references", "name"): {"means": "site", "confidence": "exact",
|
|
@@ -51,16 +51,43 @@ def _risk(caller_n: int, consumers: dict[str, int], contract_sites: int,
|
|
|
51
51
|
return "low", score
|
|
52
52
|
|
|
53
53
|
|
|
54
|
+
def _module_dossier(query: Query, sid: str, node) -> dict:
|
|
55
|
+
"""A changed line of module-level code (R1-C82 D2): about the module, not its members.
|
|
56
|
+
|
|
57
|
+
The generic dossier sums callers and call sites over every member, which turned a
|
|
58
|
+
one-line constant edit into "[high] … 123 site(s) — check on signature change". A
|
|
59
|
+
module has no signature; what module-level code reaches is whoever imports it.
|
|
60
|
+
"""
|
|
61
|
+
consumers: dict[str, int] = {}
|
|
62
|
+
for ref in query.references_to(sid, include_members=False):
|
|
63
|
+
consumers[ref["root"]] = consumers.get(ref["root"], 0) + 1
|
|
64
|
+
importers = sum(consumers.values())
|
|
65
|
+
risk, score = _risk(importers, {r: v for r, v in consumers.items() if r != "core"}, 0, False)
|
|
66
|
+
return {
|
|
67
|
+
"symbol": sid, "kind": "module", "file": node.file if node else None, "lines": None,
|
|
68
|
+
"callers": [], "callees": [], "call_contract": [],
|
|
69
|
+
"columns": {"reads": [], "writes": []},
|
|
70
|
+
"consumers_by_root": consumers,
|
|
71
|
+
"module_level": True,
|
|
72
|
+
"risk": risk, "risk_score": score,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
54
76
|
def build_symbol_dossier(query: Query, sid: str) -> dict:
|
|
55
77
|
"""Everything a reviewer needs about one changed symbol (F17)."""
|
|
56
78
|
node = query.graph.nodes.get(sid)
|
|
57
79
|
kind = node.kind if node else None
|
|
80
|
+
if kind == "module":
|
|
81
|
+
return _module_dossier(query, sid, node)
|
|
58
82
|
callers = query.callers(sid)
|
|
59
83
|
contract = query.call_contract(sid)
|
|
60
84
|
cols = query.columns_of(sid) if kind == "function" else {"reads": [], "writes": []}
|
|
61
85
|
consumers = _consumers_by_root(query, sid)
|
|
62
86
|
touches = bool(cols["reads"] or cols["writes"])
|
|
63
|
-
|
|
87
|
+
# R1-C82: an attribute has no callers; its reach is who reads or writes it (the
|
|
88
|
+
# `accesses` edges D3 added), or a widely read constant would rank "low".
|
|
89
|
+
reach = sum(consumers.values()) if kind == "attribute" else len(callers)
|
|
90
|
+
risk, score = _risk(reach, consumers, len(contract), touches)
|
|
64
91
|
return {
|
|
65
92
|
"symbol": sid,
|
|
66
93
|
"kind": kind,
|
|
@@ -102,6 +129,11 @@ def build_review(query: Query, *, hunks: list[dict] | None = None,
|
|
|
102
129
|
ids.update(got)
|
|
103
130
|
else:
|
|
104
131
|
unresolved.append({"file": file, "range": [start, end]})
|
|
132
|
+
for rng in h.get("soft", []):
|
|
133
|
+
# D1b: a blank/comment line names its definition, never the module
|
|
134
|
+
start, end = int(rng[0]), int(rng[-1])
|
|
135
|
+
_defs, module = query._defs_in_file(file)
|
|
136
|
+
ids.update(s for s in query.symbols_in_range(file, start, end) if s != module)
|
|
105
137
|
ids = {query.canonical(i) or i for i in ids}
|
|
106
138
|
dossiers = [build_symbol_dossier(query, sid) for sid in sorted(ids)]
|
|
107
139
|
dossiers.sort(key=lambda d: (-d["risk_score"], d["symbol"]))
|
|
@@ -154,7 +186,11 @@ def render_review(query: Query, *, hunks: list[dict] | None = None,
|
|
|
154
186
|
for d in rv["changed"]:
|
|
155
187
|
loc = f" ({d['file']}:{d['lines'][0]})" if d["file"] and d["lines"] else ""
|
|
156
188
|
out.append(f"## [{d['risk']}] {d['symbol']}{loc}")
|
|
157
|
-
if d
|
|
189
|
+
if d.get("module_level"):
|
|
190
|
+
n = sum(d["consumers_by_root"].values())
|
|
191
|
+
out.append(f"- Module-level code changed (outside any definition) — runs on import; "
|
|
192
|
+
f"referenced directly by {n} site(s): {d['consumers_by_root'] or '—'}")
|
|
193
|
+
elif d["consumers_by_root"]:
|
|
158
194
|
out.append(f"- Consumers by root: {d['consumers_by_root']}")
|
|
159
195
|
if d["callers"]:
|
|
160
196
|
out.append(f"- Callers ({len(d['callers'])}): "
|
|
@@ -171,27 +207,88 @@ def render_review(query: Query, *, hunks: list[dict] | None = None,
|
|
|
171
207
|
|
|
172
208
|
# -- unified-diff hunk parsing (for CLI `codemap review <diff>`) --------------
|
|
173
209
|
|
|
210
|
+
def _soft(text: str) -> bool:
|
|
211
|
+
"""A blank or comment-only line: no code changed on it (R1-C82 D1b)."""
|
|
212
|
+
t = text.strip()
|
|
213
|
+
return not t or t.startswith("#")
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _runs(lines: list[int]) -> list[list[int]]:
|
|
217
|
+
"""Sorted line numbers → [[start, end], …] of consecutive runs."""
|
|
218
|
+
out: list[list[int]] = []
|
|
219
|
+
for n in sorted(set(lines)):
|
|
220
|
+
if out and n == out[-1][1] + 1:
|
|
221
|
+
out[-1][1] = n
|
|
222
|
+
else:
|
|
223
|
+
out.append([n, n])
|
|
224
|
+
return out
|
|
225
|
+
|
|
226
|
+
|
|
174
227
|
def parse_unified_diff(text: str) -> list[dict]:
|
|
175
|
-
"""Parse a unified diff → [{file, ranges
|
|
228
|
+
"""Parse a unified diff → [{file, ranges, soft}] in new-file line numbers.
|
|
176
229
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
230
|
+
R1-C82 D1: only **changed** lines count. The ``@@ +c,d @@`` header spans the hunk's
|
|
231
|
+
context too (three lines each side by default), and reading it whole put untouched
|
|
232
|
+
neighbours — and, through module-level comments, the whole module — into a review of
|
|
233
|
+
a one-line change. Now ``+`` lines give their own numbers; a run of ``-`` lines with no
|
|
234
|
+
``+`` (a pure deletion) anchors a zero-width range at the new-file line where it stood.
|
|
235
|
+
|
|
236
|
+
D1b: a changed line that is blank or a comment goes to ``soft`` instead of ``ranges``.
|
|
237
|
+
Inside a definition it still names that definition; outside every definition it
|
|
238
|
+
names nothing — a comment between two functions is not a change to the module.
|
|
180
239
|
"""
|
|
181
240
|
import re
|
|
182
|
-
hdr = re.compile(r"^@@ -\d+(
|
|
183
|
-
|
|
241
|
+
hdr = re.compile(r"^@@ -\d+(?:,(\d+))? \+(\d+)(?:,(\d+))? @@")
|
|
242
|
+
hard: dict[str, list[int]] = {}
|
|
243
|
+
soft: dict[str, list[int]] = {}
|
|
184
244
|
current = None
|
|
245
|
+
cur = old_left = new_left = 0 # the header's counts tell body lines from headers
|
|
246
|
+
pending: list[str] = [] # texts of a run of '-' lines not yet followed by '+'
|
|
247
|
+
|
|
248
|
+
def flush():
|
|
249
|
+
if current and pending:
|
|
250
|
+
(soft if all(_soft(t) for t in pending) else hard)[current].append(cur)
|
|
251
|
+
pending.clear()
|
|
252
|
+
|
|
185
253
|
for ln in text.splitlines():
|
|
254
|
+
if old_left > 0 or new_left > 0: # inside a hunk body
|
|
255
|
+
if ln.startswith("\\"):
|
|
256
|
+
continue # ""
|
|
257
|
+
tag, body = (ln[:1], ln[1:]) if ln else (" ", "")
|
|
258
|
+
if tag == "+":
|
|
259
|
+
pending.clear() # a replacement: '+' lines carry it
|
|
260
|
+
if current:
|
|
261
|
+
(soft if _soft(body) else hard)[current].append(cur)
|
|
262
|
+
cur += 1
|
|
263
|
+
new_left -= 1
|
|
264
|
+
elif tag == "-":
|
|
265
|
+
pending.append(body)
|
|
266
|
+
old_left -= 1
|
|
267
|
+
else: # context
|
|
268
|
+
flush()
|
|
269
|
+
cur += 1
|
|
270
|
+
old_left -= 1
|
|
271
|
+
new_left -= 1
|
|
272
|
+
if old_left <= 0 and new_left <= 0:
|
|
273
|
+
flush()
|
|
274
|
+
continue
|
|
186
275
|
if ln.startswith("+++ "):
|
|
187
276
|
path = ln[4:].strip().split("\t")[0]
|
|
188
277
|
if path.startswith("b/"):
|
|
189
278
|
path = path[2:]
|
|
190
279
|
current = None if path == "/dev/null" else path
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
280
|
+
if current:
|
|
281
|
+
hard.setdefault(current, [])
|
|
282
|
+
soft.setdefault(current, [])
|
|
283
|
+
elif m := hdr.match(ln):
|
|
284
|
+
old_left = int(m.group(1)) if m.group(1) is not None else 1
|
|
285
|
+
cur = int(m.group(2))
|
|
286
|
+
new_left = int(m.group(3)) if m.group(3) is not None else 1
|
|
287
|
+
if new_left == 0:
|
|
288
|
+
cur += 1 # "+c,0": the deletion sits after new line c
|
|
289
|
+
out = []
|
|
290
|
+
for f in hard:
|
|
291
|
+
h, so = _runs(hard[f]), _runs(soft.get(f, []))
|
|
292
|
+
if h or so:
|
|
293
|
+
out.append({"file": f, "ranges": h, "soft": so})
|
|
294
|
+
return out
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codmap
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.30
|
|
4
4
|
Summary: Static analyzer that turns a package's source into a queryable code graph.
|
|
5
5
|
Author-email: kogriv <kogriv@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -44,7 +44,7 @@ and a **SCIP index** for interop with Sourcegraph / Glean and other precise-code
|
|
|
44
44
|
|
|
45
45
|
[](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
|
|
46
46
|
|
|
47
|
-
**Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **
|
|
47
|
+
**Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1220 tests with no failures on
|
|
48
48
|
Python 3.11–3.14** ([in CI](docs/ci.md): the full suite including the dogfood pass, a determinism check, a
|
|
49
49
|
wheel smoke test, and ctags/SCIP interop against the real CLIs), warm serve surface with 31 ops (28 exposed
|
|
50
50
|
as MCP tools), and SCIP export. See **[DESIGN.md](DESIGN.md)** (product design &
|
|
@@ -170,7 +170,8 @@ Optional extras: `mcp` (Model Context Protocol server), `scip` (protobuf, for SC
|
|
|
170
170
|
# build the canonical graph of a package (its directory name is the package name every id starts with)
|
|
171
171
|
codemap build ./yourpkg -o graph.json
|
|
172
172
|
|
|
173
|
-
# repo-scoped: add consumers (tests/examples) + docs for blast-radius/impact
|
|
173
|
+
# repo-scoped: add consumers (tests/examples) + docs for blast-radius/impact;
|
|
174
|
+
# one flag per root — a root that is not a directory is refused, exit 2
|
|
174
175
|
codemap build ./yourpkg --deep --mode full --consumer ./tests --docs ./docs -o graph.json
|
|
175
176
|
|
|
176
177
|
# deep tier: union N independent samples (one build misses a real edge ~1 time in 4)
|
|
@@ -221,7 +222,8 @@ codemap serve --graph graph.json --watch
|
|
|
221
222
|
(Ca/Ce/instability), god-objects & call-hubs, per-function complexity (cyclomatic / MI)
|
|
222
223
|
blended with structural coupling.
|
|
223
224
|
- **Impact / blast radius** — who uses X, across the whole repo (core + tests + docs).
|
|
224
|
-
- **Change review** — a diff → the symbols
|
|
225
|
+
- **Change review** — a diff → the symbols its changed lines touch (context lines and comments
|
|
226
|
+
between definitions are not changes), their callers or readers, signature-change surface,
|
|
225
227
|
touched columns, cross-root consumers, risk rank.
|
|
226
228
|
- **Dispatch seams** — registry/factory families and the Protocol each impl satisfies.
|
|
227
229
|
- **Dataflow** — producers/consumers of a string-keyed DataFrame column.
|
|
@@ -152,6 +152,9 @@ tests/test_r1c77_gate_probe_battery.py
|
|
|
152
152
|
tests/test_r1c78_forbidden_chains.py
|
|
153
153
|
tests/test_r1c7_edge_vocab.py
|
|
154
154
|
tests/test_r1c80_tests_through_helpers.py
|
|
155
|
+
tests/test_r1c82_review_changed_lines.py
|
|
156
|
+
tests/test_r1c83_foreign_graph_paths.py
|
|
157
|
+
tests/test_r1c84_missing_roots.py
|
|
155
158
|
tests/test_r1c8_deadcode.py
|
|
156
159
|
tests/test_r1c9_incremental.py
|
|
157
160
|
tests/test_scip_export.py
|