codmap 0.0.37__tar.gz → 0.0.39__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.
Files changed (194) hide show
  1. {codmap-0.0.37/codmap.egg-info → codmap-0.0.39}/PKG-INFO +15 -2
  2. {codmap-0.0.37 → codmap-0.0.39}/README.md +14 -1
  3. codmap-0.0.39/codemap/__main__.py +8 -0
  4. {codmap-0.0.37 → codmap-0.0.39}/codemap/arch.py +91 -3
  5. {codmap-0.0.37 → codmap-0.0.39}/codemap/cli.py +120 -0
  6. codmap-0.0.39/codemap/devkit/__init__.py +57 -0
  7. codmap-0.0.39/codemap/devkit/artifacts.py +269 -0
  8. codmap-0.0.39/codemap/devkit/hooks.py +182 -0
  9. codmap-0.0.39/codemap/devkit/install.py +485 -0
  10. codmap-0.0.39/codemap/devkit/ratchet.py +168 -0
  11. codmap-0.0.39/codemap/devkit/state.py +28 -0
  12. codmap-0.0.39/codemap/devkit/templates/agents_block.md +40 -0
  13. codmap-0.0.39/codemap/devkit/templates/brief.txt +1 -0
  14. codmap-0.0.39/codemap/devkit/templates/claude_hooks.json +10 -0
  15. codmap-0.0.39/codemap/devkit/templates/codex_region.toml +6 -0
  16. codmap-0.0.39/codemap/devkit/templates/contract_head.toml +5 -0
  17. codmap-0.0.39/codemap/devkit/templates/github-workflow.yml +14 -0
  18. codmap-0.0.39/codemap/devkit/templates/gitlab-ci.yml +9 -0
  19. codmap-0.0.39/codemap/devkit/templates/mcp_claude.args +1 -0
  20. codmap-0.0.39/codemap/devkit/templates/post-commit.sh +42 -0
  21. codmap-0.0.39/codemap/devkit/templates/ratchet_region.toml +6 -0
  22. codmap-0.0.39/codemap/devkit/usage.py +103 -0
  23. {codmap-0.0.37 → codmap-0.0.39}/codemap/extract/attrflow.py +2 -2
  24. {codmap-0.0.37 → codmap-0.0.39}/codemap/extract/behavior.py +4 -9
  25. {codmap-0.0.37 → codmap-0.0.39}/codemap/extract/griffe_extractor.py +91 -9
  26. {codmap-0.0.37 → codmap-0.0.39}/codemap/extract/gsource.py +56 -4
  27. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/check.py +24 -2
  28. {codmap-0.0.37 → codmap-0.0.39/codmap.egg-info}/PKG-INFO +15 -2
  29. {codmap-0.0.37 → codmap-0.0.39}/codmap.egg-info/SOURCES.txt +21 -0
  30. {codmap-0.0.37 → codmap-0.0.39}/pyproject.toml +5 -1
  31. codmap-0.0.39/tests/test_r1c108_devkit.py +429 -0
  32. codmap-0.0.39/tests/test_r1c109_namespace_source.py +56 -0
  33. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c37_rule_mutation.py +1 -1
  34. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c49_type_only_cycles.py +3 -1
  35. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c63_answer_format.py +3 -1
  36. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c72_flat_inference_in_packages.py +1 -1
  37. codmap-0.0.39/tests/test_r1c94_root_builds.py +184 -0
  38. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c95_r1c96_foreign_trees.py +19 -0
  39. {codmap-0.0.37 → codmap-0.0.39}/LICENSE +0 -0
  40. {codmap-0.0.37 → codmap-0.0.39}/codemap/__init__.py +0 -0
  41. {codmap-0.0.37 → codmap-0.0.39}/codemap/apidiff.py +0 -0
  42. {codmap-0.0.37 → codmap-0.0.39}/codemap/diagnostics.py +0 -0
  43. {codmap-0.0.37 → codmap-0.0.39}/codemap/extract/__init__.py +0 -0
  44. {codmap-0.0.37 → codmap-0.0.39}/codemap/extract/dataflow.py +0 -0
  45. {codmap-0.0.37 → codmap-0.0.39}/codemap/extract/dispatch.py +0 -0
  46. {codmap-0.0.37 → codmap-0.0.39}/codemap/extract/probe.py +0 -0
  47. {codmap-0.0.37 → codmap-0.0.39}/codemap/extract/roots.py +0 -0
  48. {codmap-0.0.37 → codmap-0.0.39}/codemap/extract/union.py +0 -0
  49. {codmap-0.0.37 → codmap-0.0.39}/codemap/freshness.py +0 -0
  50. {codmap-0.0.37 → codmap-0.0.39}/codemap/incremental.py +0 -0
  51. {codmap-0.0.37 → codmap-0.0.39}/codemap/integrations/__init__.py +0 -0
  52. {codmap-0.0.37 → codmap-0.0.39}/codemap/integrations/base.py +0 -0
  53. {codmap-0.0.37 → codmap-0.0.39}/codemap/integrations/cocoindex.py +0 -0
  54. {codmap-0.0.37 → codmap-0.0.39}/codemap/integrations/gate.py +0 -0
  55. {codmap-0.0.37 → codmap-0.0.39}/codemap/integrations/gitnexus.py +0 -0
  56. {codmap-0.0.37 → codmap-0.0.39}/codemap/integrations/registry.py +0 -0
  57. {codmap-0.0.37 → codmap-0.0.39}/codemap/integrations/transport.py +0 -0
  58. {codmap-0.0.37 → codmap-0.0.39}/codemap/model.py +0 -0
  59. {codmap-0.0.37 → codmap-0.0.39}/codemap/provenance.py +0 -0
  60. {codmap-0.0.37 → codmap-0.0.39}/codemap/query.py +0 -0
  61. {codmap-0.0.37 → codmap-0.0.39}/codemap/scope.py +0 -0
  62. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/__init__.py +0 -0
  63. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/_scip_pb2.py +0 -0
  64. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/api_surface.py +0 -0
  65. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/apidiff.py +0 -0
  66. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/architecture.py +0 -0
  67. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/audit.py +0 -0
  68. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/ctags.py +0 -0
  69. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/currency.py +0 -0
  70. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/impact.py +0 -0
  71. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/limits.py +0 -0
  72. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/livingdocs.py +0 -0
  73. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/mcp_server.py +0 -0
  74. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/mermaid.py +0 -0
  75. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/pack.py +0 -0
  76. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/rag.py +0 -0
  77. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/review.py +0 -0
  78. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/scip.py +0 -0
  79. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/semantic.py +0 -0
  80. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/server.py +0 -0
  81. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/session.py +0 -0
  82. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/subsystems.py +0 -0
  83. {codmap-0.0.37 → codmap-0.0.39}/codemap/serve/vault.py +0 -0
  84. {codmap-0.0.37 → codmap-0.0.39}/codemap/store.py +0 -0
  85. {codmap-0.0.37 → codmap-0.0.39}/codemap/tomlio.py +0 -0
  86. {codmap-0.0.37 → codmap-0.0.39}/codemap/watch.py +0 -0
  87. {codmap-0.0.37 → codmap-0.0.39}/codmap.egg-info/dependency_links.txt +0 -0
  88. {codmap-0.0.37 → codmap-0.0.39}/codmap.egg-info/entry_points.txt +0 -0
  89. {codmap-0.0.37 → codmap-0.0.39}/codmap.egg-info/requires.txt +0 -0
  90. {codmap-0.0.37 → codmap-0.0.39}/codmap.egg-info/top_level.txt +0 -0
  91. {codmap-0.0.37 → codmap-0.0.39}/setup.cfg +0 -0
  92. {codmap-0.0.37 → codmap-0.0.39}/tests/test_epistemic.py +0 -0
  93. {codmap-0.0.37 → codmap-0.0.39}/tests/test_gitnexus_router.py +0 -0
  94. {codmap-0.0.37 → codmap-0.0.39}/tests/test_impact_depth.py +0 -0
  95. {codmap-0.0.37 → codmap-0.0.39}/tests/test_integrations.py +0 -0
  96. {codmap-0.0.37 → codmap-0.0.39}/tests/test_issue3_serve_freshness.py +0 -0
  97. {codmap-0.0.37 → codmap-0.0.39}/tests/test_livingdocs.py +0 -0
  98. {codmap-0.0.37 → codmap-0.0.39}/tests/test_m0_api_surface.py +0 -0
  99. {codmap-0.0.37 → codmap-0.0.39}/tests/test_m11_argcontract.py +0 -0
  100. {codmap-0.0.37 → codmap-0.0.39}/tests/test_m12_dataflow.py +0 -0
  101. {codmap-0.0.37 → codmap-0.0.39}/tests/test_m15_review.py +0 -0
  102. {codmap-0.0.37 → codmap-0.0.39}/tests/test_m16_architecture.py +0 -0
  103. {codmap-0.0.37 → codmap-0.0.39}/tests/test_m17_mcp.py +0 -0
  104. {codmap-0.0.37 → codmap-0.0.39}/tests/test_m18_freshness.py +0 -0
  105. {codmap-0.0.37 → codmap-0.0.39}/tests/test_m1_5_semantics.py +0 -0
  106. {codmap-0.0.37 → codmap-0.0.39}/tests/test_m1_query.py +0 -0
  107. {codmap-0.0.37 → codmap-0.0.39}/tests/test_m2_views.py +0 -0
  108. {codmap-0.0.37 → codmap-0.0.39}/tests/test_m32_watch.py +0 -0
  109. {codmap-0.0.37 → codmap-0.0.39}/tests/test_m3_serve.py +0 -0
  110. {codmap-0.0.37 → codmap-0.0.39}/tests/test_m4_behavior.py +0 -0
  111. {codmap-0.0.37 → codmap-0.0.39}/tests/test_m5_deep.py +0 -0
  112. {codmap-0.0.37 → codmap-0.0.39}/tests/test_m6_repo_scope.py +0 -0
  113. {codmap-0.0.37 → codmap-0.0.39}/tests/test_m7_dispatch.py +0 -0
  114. {codmap-0.0.37 → codmap-0.0.39}/tests/test_m9_family.py +0 -0
  115. {codmap-0.0.37 → codmap-0.0.39}/tests/test_pack_honesty.py +0 -0
  116. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c13_callgraph_accuracy.py +0 -0
  117. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c13_grep_vs_graph.py +0 -0
  118. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c16_semantic.py +0 -0
  119. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c20_attribute_edges.py +0 -0
  120. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c21_flat_layout.py +0 -0
  121. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c22_source_visible_refs.py +0 -0
  122. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c23_hard_python.py +0 -0
  123. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c24_test_mapping.py +0 -0
  124. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c25_provenance.py +0 -0
  125. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c26_deep_union.py +0 -0
  126. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c27_config_honesty.py +0 -0
  127. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c28_limit_envelope.py +0 -0
  128. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c29_lazy_imports.py +0 -0
  129. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c2_ctags.py +0 -0
  130. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c30_local_import_calls.py +0 -0
  131. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c30f1_reexport_calls.py +0 -0
  132. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c30f2_check_scope.py +0 -0
  133. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c31_path_origin.py +0 -0
  134. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c32_report_json.py +0 -0
  135. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c33_query_signature.py +0 -0
  136. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c34_signature_kinds.py +0 -0
  137. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c35_contract_location.py +0 -0
  138. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c36_target_resolution.py +0 -0
  139. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c38_tool_drift.py +0 -0
  140. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c39_edge_resolution.py +0 -0
  141. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c3_arch_contract.py +0 -0
  142. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c3_dogfood.py +0 -0
  143. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c40_flow_reach.py +0 -0
  144. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c41_scope_membership.py +0 -0
  145. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c42_deep_tier_stability.py +0 -0
  146. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c43_incremental_splice.py +0 -0
  147. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c44_absent_answers.py +0 -0
  148. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c45_repeat_union.py +0 -0
  149. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c46_shadowed_definitions.py +0 -0
  150. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c47_incremental_resample.py +0 -0
  151. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c48_type_checking_imports.py +0 -0
  152. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c4_complexity.py +0 -0
  153. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c50_flow_entry_points.py +0 -0
  154. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c53_narrowing_declared.py +0 -0
  155. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c54_deterministic_rendering.py +0 -0
  156. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c55_override_grade.py +0 -0
  157. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c56_stub_files.py +0 -0
  158. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c57_facade_package.py +0 -0
  159. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c58_cycle_tangles.py +0 -0
  160. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c59_completeness_drop.py +0 -0
  161. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c5_apidiff.py +0 -0
  162. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c60_nested_definitions.py +0 -0
  163. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c62_phantom_rules.py +0 -0
  164. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c64_dependency_probe.py +0 -0
  165. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c66_pack_direction.py +0 -0
  166. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c68_dotted_imports.py +0 -0
  167. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c69_contract_validation.py +0 -0
  168. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c6_pack.py +0 -0
  169. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c70_check_graph_currency.py +0 -0
  170. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c71_attribute_chain_calls.py +0 -0
  171. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c73_cli_version.py +0 -0
  172. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c74_call_site_conservation.py +0 -0
  173. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c75_reexported_class_calls.py +0 -0
  174. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c76_contract_table_typo.py +0 -0
  175. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c77_gate_probe_battery.py +0 -0
  176. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c78_forbidden_chains.py +0 -0
  177. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c7_edge_vocab.py +0 -0
  178. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c80_tests_through_helpers.py +0 -0
  179. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c81_protocol_dispatch.py +0 -0
  180. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c82_review_changed_lines.py +0 -0
  181. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c83_foreign_graph_paths.py +0 -0
  182. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c84_missing_roots.py +0 -0
  183. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c85_mcp_graph_currency.py +0 -0
  184. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c86_incremental_repo_scope.py +0 -0
  185. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c87_review_path_base.py +0 -0
  186. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c89_review_docs.py +0 -0
  187. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c8_deadcode.py +0 -0
  188. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c90_currency_without_recipe.py +0 -0
  189. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c91_route_vocabulary.py +0 -0
  190. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c92_sidecar_pair.py +0 -0
  191. {codmap-0.0.37 → codmap-0.0.39}/tests/test_r1c9_incremental.py +0 -0
  192. {codmap-0.0.37 → codmap-0.0.39}/tests/test_scip_export.py +0 -0
  193. {codmap-0.0.37 → codmap-0.0.39}/tests/test_scope.py +0 -0
  194. {codmap-0.0.37 → codmap-0.0.39}/tests/test_subsystems.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codmap
3
- Version: 0.0.37
3
+ Version: 0.0.39
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
  [![CI](https://github.com/kogriv/codemap/actions/workflows/ci.yml/badge.svg)](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
46
46
 
47
- **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1287 tests with no failures on
47
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1324 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 &
@@ -166,6 +166,17 @@ Optional extras: `mcp` (Model Context Protocol server), `scip` (protobuf, for SC
166
166
 
167
167
  ## Quickstart
168
168
 
169
+ **Adopting codemap in a repository?** One command installs the whole discipline — the agent rules in
170
+ `AGENTS.md`, the MCP server for Claude Code (and Codex), a post-commit graph rebuild, an architecture contract
171
+ written from the graph with the `allowed` ratchet, optional Claude Code hooks and a CI gate — and
172
+ `codemap devkit status` says when it has drifted. See **[docs/devkit.md](docs/devkit.md)**.
173
+
174
+ ```bash
175
+ codemap devkit init --package src/yourpkg --consumer tests
176
+ ```
177
+
178
+ By hand:
179
+
169
180
  ```bash
170
181
  # build the canonical graph of a package (its directory name is the package name every id starts with)
171
182
  codemap build ./yourpkg -o graph.json
@@ -318,6 +329,8 @@ the live graph, findings, and the milestone that closed them.
318
329
  - **[docs/export.md](docs/export.md)** — export recipes: RAG, mermaid, Obsidian vault, SCIP + ctags interop.
319
330
  - **[docs/accuracy.md](docs/accuracy.md)** — measured call-graph accuracy, the honest static ceiling, and
320
331
  the grep-vs-graph value proof (both harnesses guarded in CI).
332
+ - **[docs/devkit.md](docs/devkit.md)** — `codemap devkit`: adopt codemap in a repository in one command
333
+ (agent rules, MCP, hooks, the ratchet contract) and keep the adoption current.
321
334
  - **[docs/architecture-contracts.md](docs/architecture-contracts.md)** — declare the intended architecture
322
335
  in `codemap.toml` and enforce it with `codemap check` (CI gate; codemap dogfoods its own).
323
336
  - **[docs/api-diff.md](docs/api-diff.md)** — `codemap diff` two snapshots for added/removed/changed symbols
@@ -8,7 +8,7 @@ and a **SCIP index** for interop with Sourcegraph / Glean and other precise-code
8
8
 
9
9
  [![CI](https://github.com/kogriv/codemap/actions/workflows/ci.yml/badge.svg)](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
10
10
 
11
- **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1287 tests with no failures on
11
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1324 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 &
@@ -130,6 +130,17 @@ Optional extras: `mcp` (Model Context Protocol server), `scip` (protobuf, for SC
130
130
 
131
131
  ## Quickstart
132
132
 
133
+ **Adopting codemap in a repository?** One command installs the whole discipline — the agent rules in
134
+ `AGENTS.md`, the MCP server for Claude Code (and Codex), a post-commit graph rebuild, an architecture contract
135
+ written from the graph with the `allowed` ratchet, optional Claude Code hooks and a CI gate — and
136
+ `codemap devkit status` says when it has drifted. See **[docs/devkit.md](docs/devkit.md)**.
137
+
138
+ ```bash
139
+ codemap devkit init --package src/yourpkg --consumer tests
140
+ ```
141
+
142
+ By hand:
143
+
133
144
  ```bash
134
145
  # build the canonical graph of a package (its directory name is the package name every id starts with)
135
146
  codemap build ./yourpkg -o graph.json
@@ -282,6 +293,8 @@ the live graph, findings, and the milestone that closed them.
282
293
  - **[docs/export.md](docs/export.md)** — export recipes: RAG, mermaid, Obsidian vault, SCIP + ctags interop.
283
294
  - **[docs/accuracy.md](docs/accuracy.md)** — measured call-graph accuracy, the honest static ceiling, and
284
295
  the grep-vs-graph value proof (both harnesses guarded in CI).
296
+ - **[docs/devkit.md](docs/devkit.md)** — `codemap devkit`: adopt codemap in a repository in one command
297
+ (agent rules, MCP, hooks, the ratchet contract) and keep the adoption current.
285
298
  - **[docs/architecture-contracts.md](docs/architecture-contracts.md)** — declare the intended architecture
286
299
  in `codemap.toml` and enforce it with `codemap check` (CI gate; codemap dogfoods its own).
287
300
  - **[docs/api-diff.md](docs/api-diff.md)** — `codemap diff` two snapshots for added/removed/changed symbols
@@ -0,0 +1,8 @@
1
+ """``python -m codemap`` — the same entry point as the ``codemap`` script.
2
+
3
+ The devkit pins this form when codemap runs without its console script (R1-C108 D2).
4
+ """
5
+
6
+ from codemap.cli import main
7
+
8
+ raise SystemExit(main())
@@ -18,6 +18,9 @@ integration gate reads). All rules operate on the **core** module import graph
18
18
  forbidden = [{ from = "core", to = "analysis" }]
19
19
  # ...or no chain of imports at all, through any module (R1-C78):
20
20
  # forbidden = [{ from = "data", to = "analysis", indirect = true }]
21
+ # the ratchet (R1-C108): when present, every import between two layers must be a
22
+ # listed pair — any other is a violation; `codemap devkit ratchet` writes it from a graph.
23
+ # allowed = [{ from = "analysis", to = "core" }]
21
24
  # the import graph must be acyclic *at import time* (the eager graph).
22
25
  no_cycles = true
23
26
  # also gate the coupling a lazy import hides: cycles closed only by an import
@@ -67,6 +70,9 @@ class ArchitectureContract:
67
70
  # written ahead of the code is a documented, legitimate use (see the module docstring)
68
71
  # and failing on it by default would turn that practice red on somebody else's tree.
69
72
  no_phantom_rules: bool = False
73
+ # R1-C108 (design ``devkit.md`` D3): the ratchet. ``None`` = not declared; ``()`` = declared
74
+ # empty, which allows no cross-layer import at all. The two must stay apart.
75
+ allowed: tuple[tuple[str, str], ...] | None = None
70
76
  error: str | None = None
71
77
  # R1-C35: the file this contract was looked for in. "No contract found" is only
72
78
  # actionable next to *where* we looked — a reader in the wrong directory cannot tell
@@ -77,7 +83,7 @@ class ArchitectureContract:
77
83
  return not (self.layers or self.independent or self.forbidden
78
84
  or self.no_cycles or self.no_lazy_cycles
79
85
  or self.no_type_only_cycles or self.exhaustive
80
- or self.no_phantom_rules)
86
+ or self.no_phantom_rules or self.allowed is not None)
81
87
 
82
88
 
83
89
  @dataclass(frozen=True)
@@ -85,7 +91,7 @@ class Violation:
85
91
  """One broken rule, with the concrete import edges (or cycle) that break it."""
86
92
 
87
93
  rule: str # layered | independent | forbidden | no_cycles | no_lazy_cycles
88
- # | no_type_only_cycles | exhaustive
94
+ # | no_type_only_cycles | exhaustive | no_phantom_rules | allowed
89
95
  summary: str # human one-liner
90
96
  edges: tuple[tuple[str, str], ...] = field(default=()) # offending (importer, imported)
91
97
  modules: tuple[str, ...] = field(default=()) # for exhaustive / cycles
@@ -133,7 +139,7 @@ def _near_miss_tables(data: dict) -> str | None:
133
139
 
134
140
  #: R1-C69: the closed schema of ``[architecture]``. A key outside it is an error, not a skip.
135
141
  _FLAGS = ("no_cycles", "no_lazy_cycles", "no_type_only_cycles", "exhaustive", "no_phantom_rules")
136
- _KNOWN_KEYS = ("layers", "independent", "forbidden") + _FLAGS
142
+ _KNOWN_KEYS = ("layers", "independent", "forbidden", "allowed") + _FLAGS
137
143
 
138
144
 
139
145
  def _is_str_list(v) -> bool:
@@ -214,6 +220,8 @@ def contract_problems(section) -> list[str]:
214
220
  elif not missing and item["from"] == item["to"]:
215
221
  # R1-C79: rules read cross-layer edges, so this can never fire.
216
222
  problems.append(f"`forbidden[{i}]`: `from` and `to` are both `{item['from']}`")
223
+ if "allowed" in section:
224
+ problems.extend(_allowed_problems(section["allowed"]))
217
225
  for flag in _FLAGS:
218
226
  if flag in section and not isinstance(section[flag], bool):
219
227
  problems.append(f"`{flag}` must be true or false, got {type(section[flag]).__name__} "
@@ -221,6 +229,39 @@ def contract_problems(section) -> list[str]:
221
229
  return problems
222
230
 
223
231
 
232
+ def _allowed_problems(items) -> list[str]:
233
+ """Schema of ``allowed`` (R1-C108 D3): ``{ from, to }`` tables, ``from ≠ to``, no repeats."""
234
+ if not isinstance(items, list):
235
+ return ["`allowed` must be a list of `{ from = \"…\", to = \"…\" }` tables"]
236
+ problems: list[str] = []
237
+ seen: set[tuple[str, str]] = set()
238
+ for i, item in enumerate(items):
239
+ if not isinstance(item, dict):
240
+ problems.append(f"`allowed[{i}]` must be a table `{{ from = \"…\", to = \"…\" }}`")
241
+ continue
242
+ extra = sorted(set(item) - {"from", "to"})
243
+ missing = [k for k in ("from", "to") if k not in item]
244
+ wrong = [k for k in ("from", "to") if k in item and not isinstance(item[k], str)]
245
+ if extra:
246
+ problems.append(f"`allowed[{i}]` has unknown key(s) " + ", ".join(f"`{k}`" for k in extra))
247
+ if missing:
248
+ problems.append(f"`allowed[{i}]` is missing " + ", ".join(f"`{k}`" for k in missing))
249
+ if wrong:
250
+ problems.append(f"`allowed[{i}]`: " + ", ".join(f"`{k}`" for k in wrong)
251
+ + " must be a string")
252
+ continue
253
+ if missing:
254
+ continue
255
+ pair = (item["from"], item["to"])
256
+ if pair[0] == pair[1]:
257
+ # Rules read cross-layer edges only, so a pair of one layer can never be used.
258
+ problems.append(f"`allowed[{i}]`: `from` and `to` are both `{pair[0]}`")
259
+ elif pair in seen:
260
+ problems.append(f"`allowed[{i}]` repeats `{pair[0]}` → `{pair[1]}`")
261
+ seen.add(pair)
262
+ return problems
263
+
264
+
224
265
  def parse_contract(section: dict) -> ArchitectureContract:
225
266
  """Build a contract from the parsed ``[architecture]`` table.
226
267
 
@@ -254,6 +295,8 @@ def parse_contract(section: dict) -> ArchitectureContract:
254
295
  no_type_only_cycles=bool(section.get("no_type_only_cycles", False)),
255
296
  exhaustive=bool(section.get("exhaustive", False)),
256
297
  no_phantom_rules=bool(section.get("no_phantom_rules", False)),
298
+ allowed=(None if "allowed" not in section
299
+ else tuple((str(i["from"]), str(i["to"])) for i in section["allowed"])),
257
300
  )
258
301
 
259
302
 
@@ -280,6 +323,8 @@ def applicability(query, contract: ArchitectureContract) -> dict:
280
323
  present = _graph_layers(query)
281
324
  named = set(contract.layers) | {m for grp in contract.independent for m in grp}
282
325
  named |= {n for pair in contract.forbidden for n in pair}
326
+ allowed = contract.allowed or ()
327
+ named |= {n for pair in allowed for n in pair}
283
328
  return {
284
329
  "layers": {"declared": len(contract.layers),
285
330
  "applicable": sum(1 for x in contract.layers if x in present)},
@@ -289,6 +334,9 @@ def applicability(query, contract: ArchitectureContract) -> dict:
289
334
  "forbidden": {"declared": len(contract.forbidden),
290
335
  "applicable": sum(1 for (a, b) in contract.forbidden
291
336
  if a in present and b in present)},
337
+ # R1-C108: always present (R1-C28); zero when the contract declares no `allowed`.
338
+ "allowed": {"declared": len(allowed),
339
+ "applicable": sum(1 for (a, b) in allowed if a in present and b in present)},
292
340
  "absent_names": tuple(sorted(n for n in named if n not in present)),
293
341
  }
294
342
 
@@ -307,6 +355,30 @@ def _core_layer_edges(query) -> list[tuple[str, str, str, str]]:
307
355
 
308
356
 
309
357
 
358
+ def layer_pairs(query) -> dict[tuple[str, str], list[tuple[str, str]]]:
359
+ """Every cross-layer core import, grouped by ``(from_layer, to_layer)`` (R1-C108).
360
+
361
+ All import scopes count — module level, function-local, ``TYPE_CHECKING``, stub: each is a
362
+ dependency of one layer on the other, which is what the ratchet holds still. The same
363
+ reading feeds the rule and ``codemap devkit ratchet``, so a generated list is green.
364
+ """
365
+ pairs: dict[tuple[str, str], list[tuple[str, str]]] = {}
366
+ for u, v, lu, lv in _core_layer_edges(query):
367
+ pairs.setdefault((lu, lv), []).append((u, v))
368
+ return pairs
369
+
370
+
371
+ def allowed_unused(query, contract: ArchitectureContract) -> list[tuple[str, str]]:
372
+ """Pairs ``allowed`` lists that no import uses today — a ratchet that can tighten (D3).
373
+
374
+ Reported, never a violation: removing a dependency must not turn the gate red.
375
+ """
376
+ if contract.allowed is None:
377
+ return []
378
+ used = set(layer_pairs(query))
379
+ return [p for p in contract.allowed if p not in used]
380
+
381
+
310
382
  def _tangle_line(tangle: dict) -> str:
311
383
  """One gate line per tangle: the example cycle, then the members (R1-C58).
312
384
 
@@ -437,6 +509,22 @@ def check_contract(query, contract: ArchitectureContract) -> list[Violation]:
437
509
  edges=tuple(sorted(bad)),
438
510
  ))
439
511
 
512
+ # -- allowed: the ratchet — every cross-layer import must be a listed pair (R1-C108) --
513
+ if contract.allowed is not None:
514
+ listed = set(contract.allowed)
515
+ bad = tuple(sorted(
516
+ (u, v) for (u, v, lu, lv) in edges if (lu, lv) not in listed))
517
+ if bad:
518
+ new_pairs = sorted({(lu, lv) for (u, v, lu, lv) in edges if (lu, lv) not in listed})
519
+ names = ", ".join(f"`{a}` → `{b}`" for a, b in new_pairs[:10])
520
+ more = f" and {len(new_pairs) - 10} more" if len(new_pairs) > 10 else ""
521
+ violations.append(Violation(
522
+ "allowed",
523
+ f"{len(bad)} import(s) between layers not listed in `allowed` "
524
+ f"({len(new_pairs)} pair(s): {names}{more})",
525
+ edges=bad,
526
+ ))
527
+
440
528
  # -- no_cycles: no cycle among imports that run at import time ---------------
441
529
  # R1-C29: deliberately the eager graph. `no_cycles` is a gate against the import-order
442
530
  # failure, and a function-local import is the accepted fix for it — failing a build
@@ -1020,6 +1020,74 @@ def _cmd_check(args) -> int:
1020
1020
  return _check_exit(violations, currency, allow_stale)
1021
1021
 
1022
1022
 
1023
+ def _cmd_devkit(args) -> int:
1024
+ """R1-C108: `codemap devkit …` — design ``docs/design/devkit.md``."""
1025
+ from pathlib import Path as _P
1026
+ root = _P(args.root)
1027
+ cmd = args.devkit_cmd
1028
+ if cmd == "init":
1029
+ from codemap.devkit.install import init
1030
+ return init(root, package=args.package, consumers=args.consumer, docs=args.docs,
1031
+ agents_file=args.agents_file, claude_hooks=args.claude_hooks, codex=args.codex,
1032
+ ci=args.ci, hook=args.hook, build=args.build, ratchet=args.ratchet,
1033
+ dry_run=args.dry_run, force=args.force)
1034
+ if cmd == "update":
1035
+ from codemap.devkit.install import update
1036
+ return update(root, force=args.force, repin=args.repin, dry_run=args.dry_run)
1037
+ if cmd == "status":
1038
+ from codemap.devkit.install import status
1039
+ return status(root, args.format)
1040
+ if cmd == "ratchet":
1041
+ return _devkit_ratchet(root, args)
1042
+ if cmd == "brief":
1043
+ from codemap.devkit.hooks import brief
1044
+ return brief(root.resolve())
1045
+ if cmd == "touched":
1046
+ from codemap.devkit.hooks import touched
1047
+ return touched(root.resolve())
1048
+ if cmd == "index":
1049
+ from codemap.devkit.hooks import index
1050
+ return index(root.resolve(), args.graph)
1051
+ if cmd == "usage":
1052
+ import json as _json
1053
+
1054
+ from codemap.devkit.usage import count, render, transcripts_dir
1055
+ d = _P(args.transcripts) if args.transcripts else transcripts_dir(root)
1056
+ r = count(d, args.days)
1057
+ print(_json.dumps(r, indent=2, sort_keys=True) if args.format == "json" else render(r), end="")
1058
+ return 0
1059
+ raise SystemExit(f"error: unknown devkit command {cmd}")
1060
+
1061
+
1062
+ def _devkit_ratchet(root, args) -> int:
1063
+ from codemap.arch import layer_pairs
1064
+ from codemap.devkit.ratchet import RatchetError, edit_region
1065
+ from codemap.devkit.state import load_state
1066
+ st = load_state(root) or {}
1067
+ graph = args.graph or str(root / st.get("graph", ".codemap/graph.json"))
1068
+ q = Query(store.load(graph))
1069
+ used = sorted(layer_pairs(q))
1070
+ try:
1071
+ res = edit_region(root, used, tighten=args.tighten, dry_run=args.dry_run)
1072
+ except RatchetError as exc:
1073
+ print(f"error: {exc}", file=sys.stderr)
1074
+ return 2
1075
+ verb = "would change" if args.dry_run else "changed"
1076
+ if not res.added and not res.removed:
1077
+ print(f"codemap.toml: the `allowed` region already matches the graph ({len(used)} pair(s) used).")
1078
+ return 0
1079
+ print(f"codemap.toml {verb}: {len(res.added)} pair(s) added, {len(res.removed)} removed "
1080
+ f"({len(used)} pair(s) used by the graph).")
1081
+ for a, b in res.removed:
1082
+ print(f" - {a} → {b} (no import uses it any more)")
1083
+ for a, b in res.added:
1084
+ print(f" + {a} → {b}")
1085
+ if res.added and not res.created_region:
1086
+ print(" Adding pairs weakens the gate: each one is a dependency the gate will no longer flag. "
1087
+ "Give each a reason comment, or remove the import instead.")
1088
+ return 0
1089
+
1090
+
1023
1091
  def _cmd_diff(args) -> int:
1024
1092
  """Two-graph API diff → added/removed/changed + breaking-change (R1-C5).
1025
1093
 
@@ -1406,6 +1474,58 @@ def build_parser() -> argparse.ArgumentParser:
1406
1474
  "(R1-C70); the 'behind' line is still printed.")
1407
1475
  ck.set_defaults(func=_cmd_check)
1408
1476
 
1477
+ # R1-C108: the devkit — adopt codemap in a repository and keep the adoption current.
1478
+ dk = sub.add_parser("devkit", help="Install, update and check codemap's adoption in a repository "
1479
+ "(agent rules, MCP, hooks, the ratchet contract).")
1480
+ dks = dk.add_subparsers(dest="devkit_cmd", required=True)
1481
+ di = dks.add_parser("init", help="First install into a repository (or `update` if already installed).")
1482
+ di.add_argument("--root", default=".", help="Repository root (default: cwd).")
1483
+ di.add_argument("--package", required=True, help="The package directory, relative to the root.")
1484
+ di.add_argument("--consumer", action="append", default=[],
1485
+ help="Repo-scope root that uses the package (tests/, scripts/). Repeatable.")
1486
+ di.add_argument("--docs", action="append", default=[], help="Docs root (*.md). Repeatable.")
1487
+ di.add_argument("--agents-file", default=None,
1488
+ help="File for the agent rules block (default: AGENTS.md, or CLAUDE.md when only it exists).")
1489
+ di.add_argument("--claude-hooks", action="store_true",
1490
+ help="Also install Claude Code hooks (SessionStart brief, PostToolUse touched).")
1491
+ di.add_argument("--codex", action="store_true", help="Also write the MCP entry in .codex/config.toml.")
1492
+ di.add_argument("--ci", choices=["github", "gitlab"], default=None, help="Also write a CI gate.")
1493
+ di.add_argument("--no-hook", dest="hook", action="store_false", help="Do not install the post-commit hook.")
1494
+ di.add_argument("--no-build", dest="build", action="store_false",
1495
+ help="Do not build the graph now (the contract is then not written).")
1496
+ di.add_argument("--ratchet", action="store_true",
1497
+ help="Add the `allowed` region to an existing `[architecture]` contract.")
1498
+ di.add_argument("--dry-run", action="store_true", help="Report what would change; write nothing.")
1499
+ di.add_argument("--force", action="store_true",
1500
+ help="Overwrite hand-edited regions and foreign artifacts in the devkit's place.")
1501
+ du = dks.add_parser("update", help="Bring every managed artifact to the installed devkit version.")
1502
+ du.add_argument("--root", default=".")
1503
+ du.add_argument("--force", action="store_true")
1504
+ du.add_argument("--repin", action="store_true", help="Move the pin to the codemap running this command.")
1505
+ du.add_argument("--dry-run", action="store_true")
1506
+ dst = dks.add_parser("status", help="What is current, outdated, edited by hand or missing (exit 1 if any).")
1507
+ dst.add_argument("--root", default=".")
1508
+ dst.add_argument("--format", choices=["text", "json"], default="text")
1509
+ dr_ = dks.add_parser("ratchet", help="Write the contract's `allowed` region from the graph, "
1510
+ "or remove pairs nothing uses (--tighten).")
1511
+ dr_.add_argument("--root", default=".")
1512
+ dr_.add_argument("--graph", default=None, help="Graph to read (default: the devkit's, .codemap/graph.json).")
1513
+ dr_.add_argument("--tighten", action="store_true", help="Remove allowed pairs no import uses any more.")
1514
+ dr_.add_argument("--dry-run", action="store_true")
1515
+ db = dks.add_parser("brief", help="SessionStart hook: graph currency and the rule, as plain text.")
1516
+ db.add_argument("--root", default=".")
1517
+ dt = dks.add_parser("touched", help="PostToolUse hook: what depends on the edited module (stdin: hook JSON).")
1518
+ dt.add_argument("--root", default=".")
1519
+ dx = dks.add_parser("index", help="Write the per-module digest the hooks read.")
1520
+ dx.add_argument("--root", default=".")
1521
+ dx.add_argument("--graph", default=None)
1522
+ dus = dks.add_parser("usage", help="codemap tool calls against grep in local Claude Code transcripts.")
1523
+ dus.add_argument("--root", default=".")
1524
+ dus.add_argument("--days", type=int, default=7)
1525
+ dus.add_argument("--transcripts", default=None, help="Transcripts directory (default: Claude Code's for --root).")
1526
+ dus.add_argument("--format", choices=["markdown", "json"], default="markdown")
1527
+ dk.set_defaults(func=_cmd_devkit)
1528
+
1409
1529
  return p
1410
1530
 
1411
1531
 
@@ -0,0 +1,57 @@
1
+ """The devkit: codemap adopted by a project in one command, kept current by codemap's suite (R1-C108).
2
+
3
+ Design ``docs/design/devkit.md``. Templates live in ``templates/`` (package data) and are rendered into a
4
+ project's repository by ``codemap devkit init | update``; ``status`` says what is behind. The devkit writes
5
+ only regions it owns, records the hash of what it wrote in ``.codemap-devkit.json``, and never overwrites a
6
+ region edited by hand or an artifact it did not write without ``--force`` (D2).
7
+
8
+ What keeps the templates current is ``tests/test_r1c108_devkit.py``, not memory (D7): every command in every
9
+ template parses with the CLI's own parser, every MCP tool a template names exists, and a template cannot
10
+ change without ``DEVKIT_VERSION`` and ``TEMPLATES_SHA256`` changing with it.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import hashlib
16
+ from pathlib import Path
17
+
18
+ #: Raised whenever a template changes; adopting projects see "outdated" in `codemap devkit status`.
19
+ DEVKIT_VERSION = 2
20
+
21
+ #: sha256 over the templates (name + content, sorted). The suite recomputes it: a template edited without
22
+ #: bumping DEVKIT_VERSION and updating this value fails there, in the same commit (D7).
23
+ TEMPLATES_SHA256 = "175879a3f5457a24517f6bb00556fa7bc493d0776944835e4e7615e159f44d7d"
24
+
25
+ TEMPLATES_DIR = Path(__file__).parent / "templates"
26
+
27
+
28
+ def template(name: str) -> str:
29
+ return (TEMPLATES_DIR / name).read_text(encoding="utf-8")
30
+
31
+
32
+ def templates_sha256() -> str:
33
+ h = hashlib.sha256()
34
+ for p in sorted(TEMPLATES_DIR.iterdir()):
35
+ if p.is_file():
36
+ h.update(p.name.encode())
37
+ h.update(b"\0")
38
+ h.update(p.read_bytes())
39
+ h.update(b"\0")
40
+ return h.hexdigest()
41
+
42
+
43
+ def render(text: str, ctx: dict[str, object]) -> str:
44
+ """Replace ``{{name}}`` placeholders. An unknown placeholder is an error, not left in the output."""
45
+ import re
46
+
47
+ def sub(m: re.Match) -> str:
48
+ key = m.group(1)
49
+ if key not in ctx:
50
+ raise KeyError(f"template placeholder `{{{{{key}}}}}` has no value")
51
+ return str(ctx[key])
52
+
53
+ return re.sub(r"\{\{(\w+)\}\}", sub, text)
54
+
55
+
56
+ def sha(text: str) -> str:
57
+ return hashlib.sha256(text.encode("utf-8")).hexdigest()