codmap 0.0.42__tar.gz → 0.0.43__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 (208) hide show
  1. {codmap-0.0.42 → codmap-0.0.43}/PKG-INFO +2 -2
  2. {codmap-0.0.42 → codmap-0.0.43}/README.md +1 -1
  3. {codmap-0.0.42 → codmap-0.0.43}/codemap/arch.py +80 -9
  4. {codmap-0.0.42 → codmap-0.0.43}/codemap/cli.py +62 -8
  5. {codmap-0.0.42 → codmap-0.0.43}/codemap/devkit/__init__.py +15 -2
  6. {codmap-0.0.42 → codmap-0.0.43}/codemap/devkit/artifacts.py +10 -0
  7. {codmap-0.0.42 → codmap-0.0.43}/codemap/devkit/hooks.py +5 -1
  8. {codmap-0.0.42 → codmap-0.0.43}/codemap/devkit/install.py +111 -23
  9. {codmap-0.0.42 → codmap-0.0.43}/codemap/devkit/ratchet.py +117 -1
  10. codmap-0.0.43/codemap/devkit/templates/agents_block.ru.md +47 -0
  11. codmap-0.0.43/codemap/devkit/templates/cycles_region.toml +8 -0
  12. {codmap-0.0.42 → codmap-0.0.43}/codemap/extract/behavior.py +27 -0
  13. {codmap-0.0.42 → codmap-0.0.43}/codemap/extract/roots.py +5 -0
  14. {codmap-0.0.42 → codmap-0.0.43}/codemap/model.py +7 -1
  15. {codmap-0.0.42 → codmap-0.0.43}/codemap/query.py +54 -0
  16. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/audit.py +48 -2
  17. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/check.py +24 -4
  18. {codmap-0.0.42 → codmap-0.0.43}/codmap.egg-info/PKG-INFO +2 -2
  19. {codmap-0.0.42 → codmap-0.0.43}/codmap.egg-info/SOURCES.txt +7 -0
  20. {codmap-0.0.42 → codmap-0.0.43}/pyproject.toml +1 -1
  21. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c108_devkit.py +4 -2
  22. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c110_advise.py +1 -1
  23. codmap-0.0.43/tests/test_r1c114_devkit_graph.py +160 -0
  24. codmap-0.0.43/tests/test_r1c115_agents_block.py +92 -0
  25. codmap-0.0.43/tests/test_r1c116_known_cycles.py +158 -0
  26. codmap-0.0.43/tests/test_r1c118_dead_code.py +119 -0
  27. codmap-0.0.43/tests/test_r1c119_first_build.py +47 -0
  28. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c13_grep_vs_graph.py +8 -6
  29. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c39_edge_resolution.py +11 -0
  30. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c49_type_only_cycles.py +3 -1
  31. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c60_nested_definitions.py +3 -2
  32. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c63_answer_format.py +1 -1
  33. {codmap-0.0.42 → codmap-0.0.43}/LICENSE +0 -0
  34. {codmap-0.0.42 → codmap-0.0.43}/codemap/__init__.py +0 -0
  35. {codmap-0.0.42 → codmap-0.0.43}/codemap/__main__.py +0 -0
  36. {codmap-0.0.42 → codmap-0.0.43}/codemap/advise/__init__.py +0 -0
  37. {codmap-0.0.42 → codmap-0.0.43}/codemap/advise/data/feed.json +0 -0
  38. {codmap-0.0.42 → codmap-0.0.43}/codemap/advise/data/matrix.toml +0 -0
  39. {codmap-0.0.42 → codmap-0.0.43}/codemap/advise/refresh.py +0 -0
  40. {codmap-0.0.42 → codmap-0.0.43}/codemap/advise/render.py +0 -0
  41. {codmap-0.0.42 → codmap-0.0.43}/codemap/apidiff.py +0 -0
  42. {codmap-0.0.42 → codmap-0.0.43}/codemap/devkit/state.py +0 -0
  43. {codmap-0.0.42 → codmap-0.0.43}/codemap/devkit/templates/agents_block.md +0 -0
  44. {codmap-0.0.42 → codmap-0.0.43}/codemap/devkit/templates/brief.txt +0 -0
  45. {codmap-0.0.42 → codmap-0.0.43}/codemap/devkit/templates/claude_hooks.json +0 -0
  46. {codmap-0.0.42 → codmap-0.0.43}/codemap/devkit/templates/codex_region.toml +0 -0
  47. {codmap-0.0.42 → codmap-0.0.43}/codemap/devkit/templates/contract_head.toml +0 -0
  48. {codmap-0.0.42 → codmap-0.0.43}/codemap/devkit/templates/github-workflow.yml +0 -0
  49. {codmap-0.0.42 → codmap-0.0.43}/codemap/devkit/templates/gitlab-ci.yml +0 -0
  50. {codmap-0.0.42 → codmap-0.0.43}/codemap/devkit/templates/mcp_claude.args +0 -0
  51. {codmap-0.0.42 → codmap-0.0.43}/codemap/devkit/templates/post-commit.sh +0 -0
  52. {codmap-0.0.42 → codmap-0.0.43}/codemap/devkit/templates/ratchet_region.toml +0 -0
  53. {codmap-0.0.42 → codmap-0.0.43}/codemap/devkit/usage.py +0 -0
  54. {codmap-0.0.42 → codmap-0.0.43}/codemap/diagnostics.py +0 -0
  55. {codmap-0.0.42 → codmap-0.0.43}/codemap/extract/__init__.py +0 -0
  56. {codmap-0.0.42 → codmap-0.0.43}/codemap/extract/attrflow.py +0 -0
  57. {codmap-0.0.42 → codmap-0.0.43}/codemap/extract/dataflow.py +0 -0
  58. {codmap-0.0.42 → codmap-0.0.43}/codemap/extract/dispatch.py +0 -0
  59. {codmap-0.0.42 → codmap-0.0.43}/codemap/extract/griffe_extractor.py +0 -0
  60. {codmap-0.0.42 → codmap-0.0.43}/codemap/extract/gsource.py +0 -0
  61. {codmap-0.0.42 → codmap-0.0.43}/codemap/extract/probe.py +0 -0
  62. {codmap-0.0.42 → codmap-0.0.43}/codemap/extract/union.py +0 -0
  63. {codmap-0.0.42 → codmap-0.0.43}/codemap/freshness.py +0 -0
  64. {codmap-0.0.42 → codmap-0.0.43}/codemap/incremental.py +0 -0
  65. {codmap-0.0.42 → codmap-0.0.43}/codemap/integrations/__init__.py +0 -0
  66. {codmap-0.0.42 → codmap-0.0.43}/codemap/integrations/base.py +0 -0
  67. {codmap-0.0.42 → codmap-0.0.43}/codemap/integrations/cocoindex.py +0 -0
  68. {codmap-0.0.42 → codmap-0.0.43}/codemap/integrations/gate.py +0 -0
  69. {codmap-0.0.42 → codmap-0.0.43}/codemap/integrations/gitnexus.py +0 -0
  70. {codmap-0.0.42 → codmap-0.0.43}/codemap/integrations/registry.py +0 -0
  71. {codmap-0.0.42 → codmap-0.0.43}/codemap/integrations/transport.py +0 -0
  72. {codmap-0.0.42 → codmap-0.0.43}/codemap/provenance.py +0 -0
  73. {codmap-0.0.42 → codmap-0.0.43}/codemap/scope.py +0 -0
  74. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/__init__.py +0 -0
  75. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/_scip_pb2.py +0 -0
  76. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/api_surface.py +0 -0
  77. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/apidiff.py +0 -0
  78. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/architecture.py +0 -0
  79. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/ctags.py +0 -0
  80. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/currency.py +0 -0
  81. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/impact.py +0 -0
  82. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/limits.py +0 -0
  83. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/livingdocs.py +0 -0
  84. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/mcp_server.py +0 -0
  85. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/mermaid.py +0 -0
  86. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/pack.py +0 -0
  87. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/rag.py +0 -0
  88. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/review.py +0 -0
  89. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/scip.py +0 -0
  90. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/semantic.py +0 -0
  91. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/server.py +0 -0
  92. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/session.py +0 -0
  93. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/subsystems.py +0 -0
  94. {codmap-0.0.42 → codmap-0.0.43}/codemap/serve/vault.py +0 -0
  95. {codmap-0.0.42 → codmap-0.0.43}/codemap/store.py +0 -0
  96. {codmap-0.0.42 → codmap-0.0.43}/codemap/tomlio.py +0 -0
  97. {codmap-0.0.42 → codmap-0.0.43}/codemap/watch.py +0 -0
  98. {codmap-0.0.42 → codmap-0.0.43}/codmap.egg-info/dependency_links.txt +0 -0
  99. {codmap-0.0.42 → codmap-0.0.43}/codmap.egg-info/entry_points.txt +0 -0
  100. {codmap-0.0.42 → codmap-0.0.43}/codmap.egg-info/requires.txt +0 -0
  101. {codmap-0.0.42 → codmap-0.0.43}/codmap.egg-info/top_level.txt +0 -0
  102. {codmap-0.0.42 → codmap-0.0.43}/setup.cfg +0 -0
  103. {codmap-0.0.42 → codmap-0.0.43}/tests/test_epistemic.py +0 -0
  104. {codmap-0.0.42 → codmap-0.0.43}/tests/test_gitnexus_router.py +0 -0
  105. {codmap-0.0.42 → codmap-0.0.43}/tests/test_impact_depth.py +0 -0
  106. {codmap-0.0.42 → codmap-0.0.43}/tests/test_integrations.py +0 -0
  107. {codmap-0.0.42 → codmap-0.0.43}/tests/test_issue3_serve_freshness.py +0 -0
  108. {codmap-0.0.42 → codmap-0.0.43}/tests/test_livingdocs.py +0 -0
  109. {codmap-0.0.42 → codmap-0.0.43}/tests/test_m0_api_surface.py +0 -0
  110. {codmap-0.0.42 → codmap-0.0.43}/tests/test_m11_argcontract.py +0 -0
  111. {codmap-0.0.42 → codmap-0.0.43}/tests/test_m12_dataflow.py +0 -0
  112. {codmap-0.0.42 → codmap-0.0.43}/tests/test_m15_review.py +0 -0
  113. {codmap-0.0.42 → codmap-0.0.43}/tests/test_m16_architecture.py +0 -0
  114. {codmap-0.0.42 → codmap-0.0.43}/tests/test_m17_mcp.py +0 -0
  115. {codmap-0.0.42 → codmap-0.0.43}/tests/test_m18_freshness.py +0 -0
  116. {codmap-0.0.42 → codmap-0.0.43}/tests/test_m1_5_semantics.py +0 -0
  117. {codmap-0.0.42 → codmap-0.0.43}/tests/test_m1_query.py +0 -0
  118. {codmap-0.0.42 → codmap-0.0.43}/tests/test_m2_views.py +0 -0
  119. {codmap-0.0.42 → codmap-0.0.43}/tests/test_m32_watch.py +0 -0
  120. {codmap-0.0.42 → codmap-0.0.43}/tests/test_m3_serve.py +0 -0
  121. {codmap-0.0.42 → codmap-0.0.43}/tests/test_m4_behavior.py +0 -0
  122. {codmap-0.0.42 → codmap-0.0.43}/tests/test_m5_deep.py +0 -0
  123. {codmap-0.0.42 → codmap-0.0.43}/tests/test_m6_repo_scope.py +0 -0
  124. {codmap-0.0.42 → codmap-0.0.43}/tests/test_m7_dispatch.py +0 -0
  125. {codmap-0.0.42 → codmap-0.0.43}/tests/test_m9_family.py +0 -0
  126. {codmap-0.0.42 → codmap-0.0.43}/tests/test_pack_honesty.py +0 -0
  127. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c109_namespace_source.py +0 -0
  128. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c111_recipe.py +0 -0
  129. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c13_callgraph_accuracy.py +0 -0
  130. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c16_semantic.py +0 -0
  131. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c20_attribute_edges.py +0 -0
  132. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c21_flat_layout.py +0 -0
  133. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c22_source_visible_refs.py +0 -0
  134. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c23_hard_python.py +0 -0
  135. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c24_test_mapping.py +0 -0
  136. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c25_provenance.py +0 -0
  137. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c26_deep_union.py +0 -0
  138. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c27_config_honesty.py +0 -0
  139. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c28_limit_envelope.py +0 -0
  140. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c29_lazy_imports.py +0 -0
  141. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c2_ctags.py +0 -0
  142. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c30_local_import_calls.py +0 -0
  143. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c30f1_reexport_calls.py +0 -0
  144. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c30f2_check_scope.py +0 -0
  145. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c31_path_origin.py +0 -0
  146. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c32_report_json.py +0 -0
  147. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c33_query_signature.py +0 -0
  148. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c34_signature_kinds.py +0 -0
  149. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c35_contract_location.py +0 -0
  150. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c36_target_resolution.py +0 -0
  151. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c37_rule_mutation.py +0 -0
  152. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c38_tool_drift.py +0 -0
  153. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c3_arch_contract.py +0 -0
  154. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c3_dogfood.py +0 -0
  155. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c40_flow_reach.py +0 -0
  156. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c41_scope_membership.py +0 -0
  157. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c42_deep_tier_stability.py +0 -0
  158. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c43_incremental_splice.py +0 -0
  159. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c44_absent_answers.py +0 -0
  160. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c45_repeat_union.py +0 -0
  161. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c46_shadowed_definitions.py +0 -0
  162. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c47_incremental_resample.py +0 -0
  163. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c48_type_checking_imports.py +0 -0
  164. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c4_complexity.py +0 -0
  165. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c50_flow_entry_points.py +0 -0
  166. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c53_narrowing_declared.py +0 -0
  167. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c54_deterministic_rendering.py +0 -0
  168. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c55_override_grade.py +0 -0
  169. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c56_stub_files.py +0 -0
  170. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c57_facade_package.py +0 -0
  171. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c58_cycle_tangles.py +0 -0
  172. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c59_completeness_drop.py +0 -0
  173. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c5_apidiff.py +0 -0
  174. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c62_phantom_rules.py +0 -0
  175. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c64_dependency_probe.py +0 -0
  176. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c66_pack_direction.py +0 -0
  177. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c68_dotted_imports.py +0 -0
  178. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c69_contract_validation.py +0 -0
  179. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c6_pack.py +0 -0
  180. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c70_check_graph_currency.py +0 -0
  181. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c71_attribute_chain_calls.py +0 -0
  182. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c72_flat_inference_in_packages.py +0 -0
  183. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c73_cli_version.py +0 -0
  184. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c74_call_site_conservation.py +0 -0
  185. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c75_reexported_class_calls.py +0 -0
  186. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c76_contract_table_typo.py +0 -0
  187. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c77_gate_probe_battery.py +0 -0
  188. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c78_forbidden_chains.py +0 -0
  189. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c7_edge_vocab.py +0 -0
  190. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c80_tests_through_helpers.py +0 -0
  191. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c81_protocol_dispatch.py +0 -0
  192. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c82_review_changed_lines.py +0 -0
  193. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c83_foreign_graph_paths.py +0 -0
  194. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c84_missing_roots.py +0 -0
  195. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c85_mcp_graph_currency.py +0 -0
  196. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c86_incremental_repo_scope.py +0 -0
  197. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c87_review_path_base.py +0 -0
  198. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c89_review_docs.py +0 -0
  199. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c8_deadcode.py +0 -0
  200. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c90_currency_without_recipe.py +0 -0
  201. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c91_route_vocabulary.py +0 -0
  202. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c92_sidecar_pair.py +0 -0
  203. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c94_root_builds.py +0 -0
  204. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c95_r1c96_foreign_trees.py +0 -0
  205. {codmap-0.0.42 → codmap-0.0.43}/tests/test_r1c9_incremental.py +0 -0
  206. {codmap-0.0.42 → codmap-0.0.43}/tests/test_scip_export.py +0 -0
  207. {codmap-0.0.42 → codmap-0.0.43}/tests/test_scope.py +0 -0
  208. {codmap-0.0.42 → codmap-0.0.43}/tests/test_subsystems.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codmap
3
- Version: 0.0.42
3
+ Version: 0.0.43
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
@@ -54,7 +54,7 @@ without a release.
54
54
 
55
55
  [![CI](https://github.com/kogriv/codemap/actions/workflows/ci.yml/badge.svg)](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
56
56
 
57
- **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1383 tests with no failures on
57
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1416 tests with no failures on
58
58
  Python 3.11–3.14** ([in CI](docs/ci.md): the full suite including the dogfood pass, a determinism check, a
59
59
  wheel smoke test, and ctags/SCIP interop against the real CLIs), warm serve surface with 32 ops (29 exposed
60
60
  as MCP tools), and SCIP export. See **[DESIGN.md](DESIGN.md)** (product design &
@@ -18,7 +18,7 @@ without a release.
18
18
 
19
19
  [![CI](https://github.com/kogriv/codemap/actions/workflows/ci.yml/badge.svg)](https://github.com/kogriv/codemap/actions/workflows/ci.yml)
20
20
 
21
- **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1383 tests with no failures on
21
+ **Status:** 🟢 M0–M20 implemented + research track (R1/R2) — schema 0.13, **1416 tests with no failures on
22
22
  Python 3.11–3.14** ([in CI](docs/ci.md): the full suite including the dogfood pass, a determinism check, a
23
23
  wheel smoke test, and ctags/SCIP interop against the real CLIs), warm serve surface with 32 ops (29 exposed
24
24
  as MCP tools), and SCIP export. See **[DESIGN.md](DESIGN.md)** (product design &
@@ -73,6 +73,10 @@ class ArchitectureContract:
73
73
  # R1-C108 (design ``devkit.md`` D3): the ratchet. ``None`` = not declared; ``()`` = declared
74
74
  # empty, which allows no cross-layer import at all. The two must stay apart.
75
75
  allowed: tuple[tuple[str, str], ...] | None = None
76
+ # R1-C116: the cycle ratchet. ``None`` = not declared. A declared list turns its gate on; a tangle whose
77
+ # modules all sit inside one listed group is known and passes, any other tangle breaks the rule.
78
+ known_lazy_cycles: tuple[frozenset[str], ...] | None = None
79
+ known_type_only_cycles: tuple[frozenset[str], ...] | None = None
76
80
  error: str | None = None
77
81
  # R1-C35: the file this contract was looked for in. "No contract found" is only
78
82
  # actionable next to *where* we looked — a reader in the wrong directory cannot tell
@@ -139,7 +143,8 @@ def _near_miss_tables(data: dict) -> str | None:
139
143
 
140
144
  #: R1-C69: the closed schema of ``[architecture]``. A key outside it is an error, not a skip.
141
145
  _FLAGS = ("no_cycles", "no_lazy_cycles", "no_type_only_cycles", "exhaustive", "no_phantom_rules")
142
- _KNOWN_KEYS = ("layers", "independent", "forbidden", "allowed") + _FLAGS
146
+ _KNOWN_CYCLES = ("known_lazy_cycles", "known_type_only_cycles")
147
+ _KNOWN_KEYS = ("layers", "independent", "forbidden", "allowed") + _FLAGS + _KNOWN_CYCLES
143
148
 
144
149
 
145
150
  def _is_str_list(v) -> bool:
@@ -222,6 +227,9 @@ def contract_problems(section) -> list[str]:
222
227
  problems.append(f"`forbidden[{i}]`: `from` and `to` are both `{item['from']}`")
223
228
  if "allowed" in section:
224
229
  problems.extend(_allowed_problems(section["allowed"]))
230
+ for key in _KNOWN_CYCLES:
231
+ if key in section:
232
+ problems.extend(_known_cycles_problems(key, section[key]))
225
233
  for flag in _FLAGS:
226
234
  if flag in section and not isinstance(section[flag], bool):
227
235
  problems.append(f"`{flag}` must be true or false, got {type(section[flag]).__name__} "
@@ -262,6 +270,28 @@ def _allowed_problems(items) -> list[str]:
262
270
  return problems
263
271
 
264
272
 
273
+ def _known_cycles_problems(key: str, groups) -> list[str]:
274
+ """Schema of a known-cycles list (R1-C116): groups of at least two distinct module names, no group twice."""
275
+ if not isinstance(groups, list):
276
+ return [f"`{key}` must be a list of lists of module names"]
277
+ problems: list[str] = []
278
+ seen: set[frozenset[str]] = set()
279
+ for i, grp in enumerate(groups):
280
+ if not _is_str_list(grp) or len(set(grp)) < 2:
281
+ problems.append(f"`{key}[{i}]` must be a list of at least 2 different module names")
282
+ continue
283
+ for name in _repeated(grp):
284
+ problems.append(f"`{key}[{i}]` repeats `{name}`")
285
+ if frozenset(grp) in seen:
286
+ problems.append(f"`{key}[{i}]` repeats an earlier group")
287
+ seen.add(frozenset(grp))
288
+ return problems
289
+
290
+
291
+ def _known(section: dict, key: str) -> tuple[frozenset[str], ...] | None:
292
+ return None if key not in section else tuple(frozenset(g) for g in section[key])
293
+
294
+
265
295
  def parse_contract(section: dict) -> ArchitectureContract:
266
296
  """Build a contract from the parsed ``[architecture]`` table.
267
297
 
@@ -291,12 +321,15 @@ def parse_contract(section: dict) -> ArchitectureContract:
291
321
  forbidden=tuple(forbidden),
292
322
  forbidden_indirect=tuple(indirect),
293
323
  no_cycles=bool(section.get("no_cycles", False)),
294
- no_lazy_cycles=bool(section.get("no_lazy_cycles", False)),
295
- no_type_only_cycles=bool(section.get("no_type_only_cycles", False)),
324
+ no_lazy_cycles=bool(section.get("no_lazy_cycles", False)) or "known_lazy_cycles" in section,
325
+ no_type_only_cycles=(bool(section.get("no_type_only_cycles", False))
326
+ or "known_type_only_cycles" in section),
296
327
  exhaustive=bool(section.get("exhaustive", False)),
297
328
  no_phantom_rules=bool(section.get("no_phantom_rules", False)),
298
329
  allowed=(None if "allowed" not in section
299
330
  else tuple((str(i["from"]), str(i["to"])) for i in section["allowed"])),
331
+ known_lazy_cycles=_known(section, "known_lazy_cycles"),
332
+ known_type_only_cycles=_known(section, "known_type_only_cycles"),
300
333
  )
301
334
 
302
335
 
@@ -379,6 +412,41 @@ def allowed_unused(query, contract: ArchitectureContract) -> list[tuple[str, str
379
412
  return [p for p in contract.allowed if p not in used]
380
413
 
381
414
 
415
+ def split_known(tangles: list[dict], known: tuple[frozenset[str], ...] | None) -> tuple[list[dict], list[dict]]:
416
+ """``(new, known)`` tangles (R1-C116): a tangle inside one listed group is known — it may have split or
417
+ shrunk, never grown. With no list declared every tangle is new, as before."""
418
+ if not known:
419
+ return list(tangles), []
420
+ new, old = [], []
421
+ for t in tangles:
422
+ (old if any(set(t["modules"]) <= k for k in known) else new).append(t)
423
+ return new, old
424
+
425
+
426
+ def known_stale(query, contract: ArchitectureContract) -> dict[str, list[frozenset[str]]]:
427
+ """Listed groups that hold no tangle any more, per key — a cycle ratchet that can tighten (R1-C116).
428
+
429
+ Reported, never a violation, like `allowed_unused`: breaking a cycle must not turn the gate red.
430
+ """
431
+ out: dict[str, list[frozenset[str]]] = {}
432
+ for key, known, tangles in (("known_lazy_cycles", contract.known_lazy_cycles, query.lazy_import_tangles),
433
+ ("known_type_only_cycles", contract.known_type_only_cycles,
434
+ query.type_only_import_tangles)):
435
+ if known:
436
+ now = [set(t["modules"]) for t in tangles()]
437
+ stale = [k for k in known if not any(m <= k for m in now)]
438
+ if stale:
439
+ out[key] = stale
440
+ return out
441
+
442
+
443
+ def _grew(tangle: dict, known: tuple[frozenset[str], ...] | None) -> str:
444
+ overlap = [k for k in known or () if k & set(tangle["modules"])]
445
+ if not overlap:
446
+ return ""
447
+ return " — grew from the known " + "; ".join("(" + ", ".join(sorted(k)) + ")" for k in overlap)
448
+
449
+
382
450
  def _tangle_line(tangle: dict) -> str:
383
451
  """One gate line per tangle: the example cycle, then the members (R1-C58).
384
452
 
@@ -555,13 +623,14 @@ def check_contract(query, contract: ArchitectureContract) -> list[Violation]:
555
623
  # not a gate, and a lazy import is the accepted way to break an import cycle — so this
556
624
  # is the contract owner's call to state, not a default to pick on their behalf.
557
625
  if contract.no_lazy_cycles:
558
- lazy = query.lazy_import_tangles()
626
+ lazy, _ = split_known(query.lazy_import_tangles(), contract.known_lazy_cycles)
559
627
  if lazy:
560
628
  violations.append(Violation(
561
629
  "no_lazy_cycles",
562
- f"{len(lazy)} tangle(s) closed only by a function-local import, "
630
+ f"{len(lazy)} {'new ' if contract.known_lazy_cycles is not None else ''}"
631
+ f"tangle(s) closed only by a function-local import, "
563
632
  f"{sum(t['size'] for t in lazy)} module(s)",
564
- modules=tuple(_tangle_line(t) for t in lazy),
633
+ modules=tuple(_tangle_line(t) + _grew(t, contract.known_lazy_cycles) for t in lazy),
565
634
  ))
566
635
 
567
636
  # -- no_type_only_cycles: the third kind, and the one with no runtime dependency ----
@@ -572,14 +641,16 @@ def check_contract(query, contract: ArchitectureContract) -> list[Violation]:
572
641
  # against lazy imports used as a way around `no_cycles`, and the standard typing
573
642
  # idiom is not that.
574
643
  if contract.no_type_only_cycles:
575
- type_only = query.type_only_import_tangles()
644
+ type_only, _ = split_known(query.type_only_import_tangles(), contract.known_type_only_cycles)
576
645
  if type_only:
577
646
  violations.append(Violation(
578
647
  "no_type_only_cycles",
579
- f"{len(type_only)} tangle(s) closed only by an import that never runs "
648
+ f"{len(type_only)} {'new ' if contract.known_type_only_cycles is not None else ''}"
649
+ f"tangle(s) closed only by an import that never runs "
580
650
  f"(`if TYPE_CHECKING:` or a `.pyi`), "
581
651
  f"{sum(t['size'] for t in type_only)} module(s)",
582
- modules=tuple(_tangle_line(t) for t in type_only),
652
+ modules=tuple(_tangle_line(t) + _grew(t, contract.known_type_only_cycles)
653
+ for t in type_only),
583
654
  ))
584
655
 
585
656
  # -- exhaustive: every core module's layer must be declared -----------------
@@ -96,6 +96,10 @@ def _graph_from(args):
96
96
  if getattr(args, "build", None):
97
97
  return extract(args.build, deep=getattr(args, "deep", False))
98
98
  if getattr(args, "graph", None):
99
+ if not os.path.exists(args.graph):
100
+ # R1-C119: said before any work, with the command that makes one.
101
+ raise SystemExit(f"error: no graph at {args.graph} — build it first: "
102
+ f"`codemap build <package> -o {args.graph}`")
99
103
  graph = store.load(args.graph)
100
104
  if getattr(args, "func", None) not in (_cmd_check, _cmd_serve):
101
105
  _warn_if_behind(args.graph, graph, args)
@@ -163,6 +167,14 @@ def _cmd_build(args) -> int:
163
167
  return 2
164
168
  if _refuse_bad_roots(args):
165
169
  return 2
170
+ if args.out:
171
+ # R1-C119: the parent directory exists before the parse, not after it — a fresh clone has no
172
+ # `.codemap/`, and the whole extraction used to run and then fail on writing.
173
+ try:
174
+ Path(args.out).resolve().parent.mkdir(parents=True, exist_ok=True)
175
+ except OSError as exc:
176
+ print(f"error: cannot create the directory for {args.out}: {exc.strerror}", file=sys.stderr)
177
+ return 2
166
178
  if args.consumer or args.docs:
167
179
  core_graph = None
168
180
  if getattr(args, "incremental", False) and args.out:
@@ -751,7 +763,7 @@ def _cmd_report(args) -> int:
751
763
  _emit_answer(render_dead_code(Query(graph),
752
764
  whitelist=whitelist,
753
765
  min_confidence=args.min_confidence,
754
- whitelist_error=wl_error))
766
+ whitelist_error=wl_error, public=args.public))
755
767
  return 0
756
768
  renderer = _REPORTS[args.kind]
757
769
  payload = renderer(graph) if args.kind == "api-surface" else renderer(Query(graph))
@@ -796,7 +808,7 @@ def _report_json(graph, args) -> dict:
796
808
  whitelist, wl_error = load_dead_code_whitelist(root)
797
809
  return build_dead_code(Query(graph), whitelist=whitelist,
798
810
  min_confidence=args.min_confidence,
799
- whitelist_error=wl_error)
811
+ whitelist_error=wl_error, public=args.public)
800
812
  if args.kind == "api-surface":
801
813
  from codemap.serve.api_surface import build_api_surface
802
814
  return build_api_surface(graph)
@@ -881,9 +893,10 @@ def _cmd_refresh(args) -> int:
881
893
  from codemap.freshness import read_meta
882
894
  meta = read_meta(args.graph)
883
895
  if not meta or not meta.get("argv"):
896
+ what = "no graph" if not os.path.exists(args.graph) else "no rebuild recipe"
884
897
  raise SystemExit(
885
- f"error: no rebuild recipe for {args.graph!r} "
886
- "(build it with `codemap build … -o {graph}` first)")
898
+ f"error: {what} at {args.graph} — `refresh` repeats a recorded build; make the first one with "
899
+ f"`codemap build <package> -o {args.graph}`")
887
900
  cwd = meta.get("cwd")
888
901
  if cwd and os.path.isdir(cwd):
889
902
  os.chdir(cwd) # recorded argv may use paths relative to the build cwd
@@ -1077,10 +1090,11 @@ def _cmd_devkit(args) -> int:
1077
1090
  return init(root, package=args.package, consumers=args.consumer, docs=args.docs,
1078
1091
  agents_file=args.agents_file, claude_hooks=args.claude_hooks, codex=args.codex,
1079
1092
  ci=args.ci, hook=args.hook, build=args.build, ratchet=args.ratchet,
1080
- dry_run=args.dry_run, force=args.force)
1093
+ dry_run=args.dry_run, force=args.force, agents_lang=args.agents_lang)
1081
1094
  if cmd == "update":
1082
1095
  from codemap.devkit.install import update
1083
- return update(root, force=args.force, repin=args.repin, dry_run=args.dry_run)
1096
+ return update(root, force=args.force, repin=args.repin, dry_run=args.dry_run,
1097
+ agents_file=args.agents_file, agents_lang=args.agents_lang)
1084
1098
  if cmd == "status":
1085
1099
  from codemap.devkit.install import status
1086
1100
  return status(root, args.format)
@@ -1112,6 +1126,11 @@ def _devkit_ratchet(root, args) -> int:
1112
1126
  from codemap.devkit.state import load_state
1113
1127
  st = load_state(root) or {}
1114
1128
  graph = args.graph or str(root / st.get("graph", ".codemap/graph.json"))
1129
+ from codemap.devkit.install import graph_unfit
1130
+ unfit = graph_unfit(root, Path(graph))
1131
+ if unfit:
1132
+ print(f"error: {unfit}; rebuild it with the pinned codemap, then run this again", file=sys.stderr)
1133
+ return 2
1115
1134
  q = Query(store.load(graph))
1116
1135
  used = sorted(layer_pairs(q))
1117
1136
  try:
@@ -1119,6 +1138,26 @@ def _devkit_ratchet(root, args) -> int:
1119
1138
  except RatchetError as exc:
1120
1139
  print(f"error: {exc}", file=sys.stderr)
1121
1140
  return 2
1141
+ from codemap.devkit.ratchet import edit_cycles_region, has_cycles_region, tangles_now
1142
+ if getattr(args, "cycles", False) or has_cycles_region(root):
1143
+ try:
1144
+ cres = edit_cycles_region(root, tangles_now(q), tighten=args.tighten, dry_run=args.dry_run)
1145
+ except RatchetError as exc:
1146
+ print(f"error: {exc}", file=sys.stderr)
1147
+ return 2
1148
+ verb_c = "would change" if args.dry_run else "changed"
1149
+ if cres.created_region:
1150
+ n = sum(len(v) for v in cres.added.values())
1151
+ print(f"codemap.toml {verb_c}: known-cycles region written — {n} cycle group(s) known as of this graph.")
1152
+ for key, groups in cres.removed.items():
1153
+ for g in groups:
1154
+ print(f" - {key}: ({', '.join(sorted(g))}) (no cycle inside it any more)")
1155
+ if not cres.created_region:
1156
+ for key, groups in cres.added.items():
1157
+ for g in groups:
1158
+ print(f" + {key}: ({', '.join(sorted(g))})")
1159
+ if cres.added:
1160
+ print(" Adding a cycle group accepts that coupling: say why in a comment, or break the cycle.")
1122
1161
  verb = "would change" if args.dry_run else "changed"
1123
1162
  if not res.added and not res.removed:
1124
1163
  print(f"codemap.toml: the `allowed` region already matches the graph ({len(used)} pair(s) used).")
@@ -1387,6 +1426,9 @@ def build_parser() -> argparse.ArgumentParser:
1387
1426
  "the symbol (default 5, same as `report flows`).")
1388
1427
  r.add_argument("--min-confidence", choices=["low", "medium", "high"], default=None,
1389
1428
  help="report dead-code: only show candidates at/above this confidence.")
1429
+ r.add_argument("--public", action="store_true",
1430
+ help="report dead-code: also list public module-level functions with no inbound edge "
1431
+ "(dead in an application; in a library they may be external API).")
1390
1432
  r.add_argument("--format", choices=["markdown", "json"], default="markdown")
1391
1433
  r.add_argument("--source-root", metavar="DIR",
1392
1434
  help="Where codemap.toml is read for `dead-code` (default: current dir).")
@@ -1533,13 +1575,16 @@ def build_parser() -> argparse.ArgumentParser:
1533
1575
  di.add_argument("--docs", action="append", default=[], help="Docs root (*.md). Repeatable.")
1534
1576
  di.add_argument("--agents-file", default=None,
1535
1577
  help="File for the agent rules block (default: AGENTS.md, or CLAUDE.md when only it exists).")
1578
+ di.add_argument("--agents-lang", choices=["en", "ru"], default=None,
1579
+ help="Language of the agent rules block (default: en).")
1536
1580
  di.add_argument("--claude-hooks", action="store_true",
1537
1581
  help="Also install Claude Code hooks (SessionStart brief, PostToolUse touched).")
1538
1582
  di.add_argument("--codex", action="store_true", help="Also write the MCP entry in .codex/config.toml.")
1539
1583
  di.add_argument("--ci", choices=["github", "gitlab"], default=None, help="Also write a CI gate.")
1540
1584
  di.add_argument("--no-hook", dest="hook", action="store_false", help="Do not install the post-commit hook.")
1541
1585
  di.add_argument("--no-build", dest="build", action="store_false",
1542
- help="Do not build the graph now (the contract is then not written).")
1586
+ help="Do not build a graph now. The contract is written from an existing graph, if it was "
1587
+ "built by this codemap and is not behind its tree; otherwise it is not written.")
1543
1588
  di.add_argument("--ratchet", action="store_true",
1544
1589
  help="Add the `allowed` region to an existing `[architecture]` contract.")
1545
1590
  di.add_argument("--dry-run", action="store_true", help="Report what would change; write nothing.")
@@ -1549,6 +1594,10 @@ def build_parser() -> argparse.ArgumentParser:
1549
1594
  du.add_argument("--root", default=".")
1550
1595
  du.add_argument("--force", action="store_true")
1551
1596
  du.add_argument("--repin", action="store_true", help="Move the pin to the codemap running this command.")
1597
+ du.add_argument("--agents-file", default=None,
1598
+ help="Move the agent rules block to this file (an untouched old block is removed).")
1599
+ du.add_argument("--agents-lang", choices=["en", "ru"], default=None,
1600
+ help="Language of the agent rules block.")
1552
1601
  du.add_argument("--dry-run", action="store_true")
1553
1602
  dst = dks.add_parser("status", help="What is current, outdated, edited by hand or missing (exit 1 if any).")
1554
1603
  dst.add_argument("--root", default=".")
@@ -1557,7 +1606,12 @@ def build_parser() -> argparse.ArgumentParser:
1557
1606
  "or remove pairs nothing uses (--tighten).")
1558
1607
  dr_.add_argument("--root", default=".")
1559
1608
  dr_.add_argument("--graph", default=None, help="Graph to read (default: the devkit's, .codemap/graph.json).")
1560
- dr_.add_argument("--tighten", action="store_true", help="Remove allowed pairs no import uses any more.")
1609
+ dr_.add_argument("--tighten", action="store_true",
1610
+ help="Remove allowed pairs no import uses any more, and known cycle groups with no cycle.")
1611
+ dr_.add_argument("--cycles", action="store_true",
1612
+ help="Also write the known-cycles region (known_lazy_cycles, known_type_only_cycles): "
1613
+ "the cycles of today pass, a new or grown one fails check. Once written, every "
1614
+ "ratchet run updates it.")
1561
1615
  dr_.add_argument("--dry-run", action="store_true")
1562
1616
  db = dks.add_parser("brief", help="SessionStart hook: graph currency and the rule, as plain text.")
1563
1617
  db.add_argument("--root", default=".")
@@ -16,11 +16,11 @@ import hashlib
16
16
  from pathlib import Path
17
17
 
18
18
  #: Raised whenever a template changes; adopting projects see "outdated" in `codemap devkit status`.
19
- DEVKIT_VERSION = 3
19
+ DEVKIT_VERSION = 5
20
20
 
21
21
  #: sha256 over the templates (name + content, sorted). The suite recomputes it: a template edited without
22
22
  #: bumping DEVKIT_VERSION and updating this value fails there, in the same commit (D7).
23
- TEMPLATES_SHA256 = "131c38386ac4558ddc701a00a2dcaa4e18efcb8848ad90bc2b168295d6479cb6"
23
+ TEMPLATES_SHA256 = "22364b9f3ba0d4a2ffb81d888184481817dcf131f31accfbbbd7881dd247c72a"
24
24
 
25
25
  TEMPLATES_DIR = Path(__file__).parent / "templates"
26
26
 
@@ -55,3 +55,16 @@ def render(text: str, ctx: dict[str, object]) -> str:
55
55
 
56
56
  def sha(text: str) -> str:
57
57
  return hashlib.sha256(text.encode("utf-8")).hexdigest()
58
+
59
+
60
+ def build_args(st: dict) -> str:
61
+ """The roots part of the devkit's build command (`--consumer`, `--docs`, `--mode full`)."""
62
+ import shlex
63
+ parts: list[str] = []
64
+ for c in st.get("consumers", []):
65
+ parts += ["--consumer", c]
66
+ for d in st.get("docs", []):
67
+ parts += ["--docs", d]
68
+ if st.get("consumers"):
69
+ parts += ["--mode", "full"]
70
+ return shlex.join(parts)
@@ -101,6 +101,16 @@ class MarkdownRegion(Artifact):
101
101
  _write(self.path, text + sep + block + "\n")
102
102
 
103
103
 
104
+ def remove_region(art: "MarkdownRegion") -> None:
105
+ """Take the block out of its file (R1-C115), folding the blank lines it leaves; the file stays."""
106
+ text = _read(art.path)
107
+ span = art._span(text) if text is not None else None
108
+ if not span:
109
+ return
110
+ head, tail = text[:span[0]].rstrip("\n"), text[span[1]:].lstrip("\n")
111
+ _write(art.path, (head + "\n\n" + tail if head and tail else head + "\n" if head else tail))
112
+
113
+
104
114
  class TomlRegion(Artifact):
105
115
  """The Codex MCP entry in .codex/config.toml: between `# >>> codemap-devkit` and `# <<<`."""
106
116
 
@@ -48,7 +48,11 @@ def currency_line(root: Path, st: dict) -> str:
48
48
  gp = _graph_path(root, st)
49
49
  rel = os.path.relpath(gp, root)
50
50
  if not gp.is_file():
51
- return f"absent ({rel} does not exist — `codemap devkit init` builds it, the post-commit hook keeps it)"
51
+ # R1-C119: a fresh clone has no graph and `refresh` has no recipe to repeat — give the first build.
52
+ from codemap.devkit import build_args
53
+ cmd = " ".join(x for x in ("codemap build", st.get("package", "<package>"), build_args(st), "-o", rel) if x)
54
+ return (f"absent ({rel} does not exist; build it once: `{cmd}` — after that the post-commit hook "
55
+ "keeps it)")
52
56
  meta = read_meta(str(gp)) or {}
53
57
  built = meta.get("built_at")
54
58
  when = f", built {_ago(built)}" if isinstance(built, (int, float)) else ""
@@ -20,7 +20,7 @@ import sys
20
20
  from dataclasses import dataclass, field
21
21
  from pathlib import Path
22
22
 
23
- from codemap.devkit import DEVKIT_VERSION, render, sha, template
23
+ from codemap.devkit import DEVKIT_VERSION, build_args, render, sha, template
24
24
  from codemap.devkit.artifacts import (CI_MARK, HOOK_MARK, Artifact, ClaudeHooks, JsonKey,
25
25
  MarkdownRegion, TomlRegion, WholeFile, canon_json)
26
26
  from codemap.devkit.state import STATE, load_state, save_state
@@ -96,15 +96,7 @@ def pin_has_mcp(pin: list[str]) -> bool | None:
96
96
 
97
97
  # --------------------------------------------------------------------------- rendering
98
98
 
99
- def build_args(st: dict) -> str:
100
- parts: list[str] = []
101
- for c in st.get("consumers", []):
102
- parts += ["--consumer", c]
103
- for d in st.get("docs", []):
104
- parts += ["--docs", d]
105
- if st.get("consumers"):
106
- parts += ["--mode", "full"]
107
- return shlex.join(parts)
99
+
108
100
 
109
101
 
110
102
  def context(st: dict, pin: list[str], codemap_version: str, root: Path | None = None) -> dict:
@@ -174,8 +166,9 @@ def items(root: Path, st: dict, pin: list[str], codemap_version: str) -> tuple[l
174
166
  opts = st.get("options", {})
175
167
  out: list[Item] = []
176
168
  notes: list[str] = []
169
+ block = "agents_block.ru.md" if st.get("agents_lang") == "ru" else "agents_block.md"
177
170
  out.append(Item("agents", MarkdownRegion("agents", root / ctx["agents_file"]),
178
- render(template("agents_block.md"), ctx)))
171
+ render(template(block), ctx)))
179
172
  mcp = JsonKey("mcp", root / ".mcp.json")
180
173
  mcp.recorded = (st.get("artifacts", {}).get("mcp") or {}).get("sha256")
181
174
  out.append(Item("mcp", mcp, mcp_entry(ctx, pin), canonical=True))
@@ -321,6 +314,29 @@ def _query(root: Path, st: dict):
321
314
  return Query(store.load(str(root / st.get("graph", GRAPH))))
322
315
 
323
316
 
317
+ def graph_unfit(root: Path, graph: Path) -> str | None:
318
+ """Why ``graph`` must not be the base of a contract, or None (R1-C114).
319
+
320
+ A contract written from a graph built by another codemap, or from one behind its source tree,
321
+ allows pairs the gate (run with the pinned codemap on the current tree) will not see, or misses
322
+ pairs it will: the ratchet would be wrong on its first run.
323
+ """
324
+ from codemap import store
325
+ from codemap.serve.currency import graph_currency
326
+ g = store.load(str(graph))
327
+ prov = g.provenance or {}
328
+ built_by = (prov.get("tool") or {}).get("version")
329
+ running = _version()
330
+ if built_by and running != "unknown" and built_by != running:
331
+ return f"the graph was built by codemap {built_by}, this is codemap {running}"
332
+ cur = graph_currency(str(graph), prov.get("scope_id"), roots=prov.get("roots"), target=g.target,
333
+ base=str(root))
334
+ if cur.get("status") == "behind":
335
+ parts = [f"{cur[k]} {k}" for k in ("changed", "added", "removed") if cur.get(k)]
336
+ return f"the graph is behind its source tree ({', '.join(parts) or 'the scope differs'})"
337
+ return None
338
+
339
+
324
340
  def _contract(root: Path, st: dict, *, ratchet: bool, dry_run: bool, notes: list[str]) -> None:
325
341
  from codemap.arch import layer_pairs
326
342
  from codemap.devkit.ratchet import RatchetError, edit_region, starter_flags
@@ -335,6 +351,11 @@ def _contract(root: Path, st: dict, *, ratchet: bool, dry_run: bool, notes: list
335
351
  if not graph.is_file():
336
352
  notes.append("contract not written: no graph (`--no-build`); run `codemap devkit ratchet` after a build")
337
353
  return
354
+ unfit = graph_unfit(root, graph)
355
+ if unfit:
356
+ notes.append(f"contract not written: {unfit}; rebuild it with the pinned codemap, then run "
357
+ "`codemap devkit ratchet`")
358
+ return
338
359
  q = _query(root, st)
339
360
  used = sorted(layer_pairs(q))
340
361
  try:
@@ -360,7 +381,7 @@ def _choose_agents_file(root: Path, given: str | None) -> str:
360
381
 
361
382
  def init(root: Path, *, package: str, consumers: list[str], docs: list[str], agents_file: str | None,
362
383
  claude_hooks: bool, codex: bool, ci: str | None, hook: bool, build: bool, ratchet: bool,
363
- dry_run: bool, force: bool) -> int:
384
+ dry_run: bool, force: bool, agents_lang: str | None = None) -> int:
364
385
  root = root.resolve()
365
386
  st = load_state(root)
366
387
  if st is not None:
@@ -370,7 +391,9 @@ def init(root: Path, *, package: str, consumers: list[str], docs: list[str], age
370
391
  opts["claude_hooks"] = opts.get("claude_hooks") or claude_hooks
371
392
  opts["codex"] = opts.get("codex") or codex
372
393
  opts["ci"] = ci or opts.get("ci")
373
- return update(root, force=force, repin=False, dry_run=dry_run, _state=st)
394
+ # R1-C115: the rules file and its language move too, as `update` with them would.
395
+ return update(root, force=force, repin=False, dry_run=dry_run, _state=st,
396
+ agents_file=agents_file, agents_lang=agents_lang)
374
397
  for p, what in [(package, "--package"), *((c, "--consumer") for c in consumers),
375
398
  *((d, "--docs") for d in docs)]:
376
399
  if not (root / p).is_dir():
@@ -385,23 +408,33 @@ def init(root: Path, *, package: str, consumers: list[str], docs: list[str], age
385
408
  st = {"devkit_version": DEVKIT_VERSION, "written_by": version, "package": package.rstrip("/"),
386
409
  "consumers": consumers, "docs": docs, "graph": GRAPH,
387
410
  "agents_file": _choose_agents_file(root, agents_file),
411
+ **({"agents_lang": agents_lang} if agents_lang and agents_lang != "en" else {}),
388
412
  "options": {"hook": hook, "claude_hooks": claude_hooks, "codex": codex, "ci": ci},
389
413
  "artifacts": {}}
390
414
  notes: list[str] = []
391
415
  graph = root / GRAPH
392
- if build and not graph.is_file() and not dry_run:
393
- ok, err = _build_graph(root, st, pin)
394
- notes.append("graph built (fast tier; the post-commit hook builds --deep)" if ok else
395
- f"graph build FAILED — {err.splitlines()[-1] if err else 'no message'}")
396
- _contract(root, st, ratchet=ratchet, dry_run=dry_run, notes=notes)
416
+ # Artifacts first, graph second (R1-C117): the rules file may sit inside a `--docs` root, and a graph
417
+ # built before it is written is behind its tree on the first `check`.
397
418
  if _ensure_gitignore(root, write=not dry_run):
398
419
  notes.append(".gitignore: `.codemap/` added (graphs and the hooks' digest are local)")
399
420
  its, skip = items(root, st, pin, version)
400
421
  notes += skip
401
422
  outcomes = [process(root, st, it, write=not dry_run, force=force) for it in its]
423
+ if build and not dry_run:
424
+ unfit = graph_unfit(root, graph) if graph.is_file() else "there is no graph"
425
+ if unfit:
426
+ ok, err = _build_graph(root, st, pin)
427
+ if not ok:
428
+ notes.append(f"graph build FAILED — {err.splitlines()[-1] if err else 'no message'}")
429
+ elif graph.is_file() and unfit != "there is no graph":
430
+ notes.append(f"graph rebuilt ({unfit}; fast tier — the post-commit hook builds --deep)")
431
+ else:
432
+ notes.append("graph built (fast tier; the post-commit hook builds --deep)")
433
+ _contract(root, st, ratchet=ratchet, dry_run=dry_run, notes=notes)
402
434
  if any(o.key == "mcp" and o.status == "created" for o in outcomes):
403
435
  notes.append(".mcp.json names the codemap executable by its absolute path on this machine "
404
436
  f"({pin[0]}); whether to commit it is this project's decision")
437
+ mcp_missing = _mcp_notes(root, st, pin, outcomes, notes)
405
438
  if graph.is_file() and not dry_run:
406
439
  from codemap.devkit.hooks import index
407
440
  import contextlib, io
@@ -411,10 +444,36 @@ def init(root: Path, *, package: str, consumers: list[str], docs: list[str], age
411
444
  save_state(root, st)
412
445
  notes.append(f"{STATE} written — commit it: it records the devkit version and what the devkit wrote")
413
446
  _report(f"codemap devkit v{DEVKIT_VERSION} — init{' (dry run)' if dry_run else ''}", outcomes, notes)
414
- return 1 if any(o.attention for o in outcomes) else 0
415
-
416
-
417
- def update(root: Path, *, force: bool, repin: bool, dry_run: bool, _state: dict | None = None) -> int:
447
+ return 1 if mcp_missing or any(o.attention for o in outcomes) else 0
448
+
449
+
450
+ def _linked_worktree(root: Path) -> bool:
451
+ """True in a `git worktree add` checkout: its path is usually temporary, the main checkout's is not."""
452
+ def rev(arg):
453
+ r = subprocess.run(["git", "rev-parse", arg], cwd=root, capture_output=True, text=True)
454
+ return (root / r.stdout.strip()).resolve() if r.returncode == 0 and r.stdout.strip() else None
455
+ common, own = rev("--git-common-dir"), rev("--git-dir")
456
+ return common is not None and own is not None and common != own
457
+
458
+
459
+ def _mcp_notes(root: Path, st: dict, pin: list[str], outcomes, notes: list[str]) -> bool:
460
+ """What `status` says about the MCP entry, said when it is written (R1-C117). True: needs attention."""
461
+ keys = {o.key for o in outcomes if o.status in ("created", "updated", "overwritten", "current")}
462
+ missing = False
463
+ if "mcp" in keys or "codex" in keys:
464
+ if pin_has_mcp(pin) is False:
465
+ missing = True
466
+ notes.append("MCP: the pinned interpreter cannot import `mcp` — `serve --mcp` will not start, the MCP "
467
+ "entries written here are dead until the extra is installed: `pip install 'codmap[mcp]'` "
468
+ "(or `uv tool install --force 'codmap[mcp]'`)")
469
+ if "codex" in keys and _linked_worktree(root):
470
+ notes.append(f".codex/config.toml: `cwd` is this linked worktree ({root}); once it is merged and removed, "
471
+ "run `codemap devkit update` in the main checkout to point it there")
472
+ return missing
473
+
474
+
475
+ def update(root: Path, *, force: bool, repin: bool, dry_run: bool, _state: dict | None = None,
476
+ agents_file: str | None = None, agents_lang: str | None = None) -> int:
418
477
  root = root.resolve()
419
478
  st = _state if _state is not None else load_state(root)
420
479
  if st is None:
@@ -423,6 +482,13 @@ def update(root: Path, *, force: bool, repin: bool, dry_run: bool, _state: dict
423
482
  return 2
424
483
  pin, version = _pin_and_version(root, st, repin)
425
484
  notes: list[str] = []
485
+ if agents_lang:
486
+ if agents_lang == "en":
487
+ st.pop("agents_lang", None)
488
+ else:
489
+ st["agents_lang"] = agents_lang
490
+ if agents_file and agents_file != st.get("agents_file"):
491
+ _move_agents_block(root, st, agents_file, write=not dry_run, notes=notes)
426
492
  its, skip = items(root, st, pin, version)
427
493
  notes += skip
428
494
  outcomes = [process(root, st, it, write=not dry_run, force=force) for it in its]
@@ -432,8 +498,30 @@ def update(root: Path, *, force: bool, repin: bool, dry_run: bool, _state: dict
432
498
  save_state(root, st)
433
499
  if repin:
434
500
  notes.append(f"re-pinned to {shlex.join(pin)} (codemap {version})")
501
+ written = [o for o in outcomes if o.status in ("created", "updated", "overwritten")]
502
+ mcp_missing = _mcp_notes(root, st, pin, written, notes)
435
503
  _report(f"codemap devkit v{DEVKIT_VERSION} — update{' (dry run)' if dry_run else ''}", outcomes, notes)
436
- return 1 if any(o.attention for o in outcomes) else 0
504
+ return 1 if mcp_missing or any(o.attention for o in outcomes) else 0
505
+
506
+
507
+ def _move_agents_block(root: Path, st: dict, new_file: str, *, write: bool, notes: list[str]) -> None:
508
+ """R1-C115: the rules block goes to ``new_file``; the old one leaves its file only if it is untouched."""
509
+ from codemap.devkit.artifacts import remove_region
510
+ old_file = st.get("agents_file", "AGENTS.md")
511
+ old = MarkdownRegion("agents", root / old_file)
512
+ cur = old.current()
513
+ recorded = (st.get("artifacts", {}).get("agents") or {}).get("sha256")
514
+ if cur is None:
515
+ notes.append(f"rules block: none in {old_file}; writing it to {new_file}")
516
+ elif recorded is not None and sha(cur) == recorded:
517
+ if write:
518
+ remove_region(old)
519
+ notes.append(f"rules block moved: {old_file} → {new_file} (link to it from {old_file} in your own words)")
520
+ else:
521
+ notes.append(f"rules block: the one in {old_file} was edited by hand — kept there; the devkit now "
522
+ f"manages the copy in {new_file}. Remove the old one yourself once you have looked")
523
+ st["agents_file"] = new_file
524
+ st.get("artifacts", {}).pop("agents", None)
437
525
 
438
526
 
439
527
  def _pin_and_version(root: Path, st: dict, repin: bool) -> tuple[list[str], str]: