codecortex 0.27.0__tar.gz → 0.28.0__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 (181) hide show
  1. {codecortex-0.27.0/src/codecortex.egg-info → codecortex-0.28.0}/PKG-INFO +2 -2
  2. {codecortex-0.27.0 → codecortex-0.28.0}/README.md +1 -1
  3. {codecortex-0.27.0 → codecortex-0.28.0/src/codecortex.egg-info}/PKG-INFO +2 -2
  4. {codecortex-0.27.0 → codecortex-0.28.0}/src/codecortex.egg-info/SOURCES.txt +1 -0
  5. codecortex-0.28.0/src/codeintel/__init__.py +1 -0
  6. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/graph_changed.py +8 -2
  7. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/server.py +81 -18
  8. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/symbol_diff.py +182 -10
  9. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_changed_range.py +100 -0
  10. codecortex-0.28.0/tests/test_mcp_answer_size.py +94 -0
  11. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_summary_integrity.py +56 -2
  12. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_symbol_diff.py +108 -0
  13. codecortex-0.27.0/src/codeintel/__init__.py +0 -1
  14. {codecortex-0.27.0 → codecortex-0.28.0}/LICENSE +0 -0
  15. {codecortex-0.27.0 → codecortex-0.28.0}/pyproject.toml +0 -0
  16. {codecortex-0.27.0 → codecortex-0.28.0}/setup.cfg +0 -0
  17. {codecortex-0.27.0 → codecortex-0.28.0}/src/codecortex.egg-info/dependency_links.txt +0 -0
  18. {codecortex-0.27.0 → codecortex-0.28.0}/src/codecortex.egg-info/entry_points.txt +0 -0
  19. {codecortex-0.27.0 → codecortex-0.28.0}/src/codecortex.egg-info/requires.txt +0 -0
  20. {codecortex-0.27.0 → codecortex-0.28.0}/src/codecortex.egg-info/top_level.txt +0 -0
  21. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/__main__.py +0 -0
  22. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/agent_prompt.py +0 -0
  23. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/auth.py +0 -0
  24. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/c4.py +0 -0
  25. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/c4_check.py +0 -0
  26. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/c4_layers.py +0 -0
  27. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/cache.py +0 -0
  28. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/changed_range.py +0 -0
  29. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/commands/__init__.py +0 -0
  30. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/commands/_common.py +0 -0
  31. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/commands/c4.py +0 -0
  32. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/commands/doctor.py +0 -0
  33. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/commands/gen_token.py +0 -0
  34. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/commands/graph.py +0 -0
  35. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/commands/index.py +0 -0
  36. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/commands/install.py +0 -0
  37. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/commands/map.py +0 -0
  38. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/commands/prompt.py +0 -0
  39. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/commands/query.py +0 -0
  40. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/commands/reset.py +0 -0
  41. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/commands/serve.py +0 -0
  42. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/commands/serve_http.py +0 -0
  43. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/commands/setup.py +0 -0
  44. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/commands/status.py +0 -0
  45. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/commands/uninstall.py +0 -0
  46. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/config.py +0 -0
  47. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/containment.py +0 -0
  48. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/doctor.py +0 -0
  49. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/filelock.py +0 -0
  50. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/gateway.py +0 -0
  51. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/graph_answer.py +0 -0
  52. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/graph_backend.py +0 -0
  53. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/graph_confidence.py +0 -0
  54. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/graph_dispatch.py +0 -0
  55. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/graph_edges.py +0 -0
  56. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/graph_ops.py +0 -0
  57. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/graph_render.py +0 -0
  58. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/graph_resolution.py +0 -0
  59. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/graph_targets.py +0 -0
  60. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/grapher.py +0 -0
  61. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/http_server.py +0 -0
  62. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/indexer.py +0 -0
  63. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/injector.py +0 -0
  64. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/installer.py +0 -0
  65. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/lang_config.py +0 -0
  66. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/loc.py +0 -0
  67. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/logconfig.py +0 -0
  68. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/mapper.py +0 -0
  69. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/metrics.py +0 -0
  70. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/onboarding.py +0 -0
  71. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/outcome.py +0 -0
  72. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/paths.py +0 -0
  73. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/per_thread.py +0 -0
  74. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/policy.py +0 -0
  75. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/progress.py +0 -0
  76. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/provider.py +0 -0
  77. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/providers/__init__.py +0 -0
  78. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/providers/graph.py +0 -0
  79. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/providers/lsp.py +0 -0
  80. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/providers/none.py +0 -0
  81. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/providers/semantic.py +0 -0
  82. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/py.typed +0 -0
  83. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/qualifier_scan.py +0 -0
  84. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/query_ops.py +0 -0
  85. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/redact.py +0 -0
  86. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/reindexer.py +0 -0
  87. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/reset.py +0 -0
  88. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/searcher.py +0 -0
  89. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/semantic_db.py +0 -0
  90. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/source_kind.py +0 -0
  91. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/term.py +0 -0
  92. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/verify.py +0 -0
  93. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/viewer/__init__.py +0 -0
  94. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/viewer/graph_template.html +0 -0
  95. {codecortex-0.27.0 → codecortex-0.28.0}/src/codeintel/wire_text.py +0 -0
  96. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_agent_prompt.py +0 -0
  97. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_backend_failure_detail.py +0 -0
  98. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_backend_reaper.py +0 -0
  99. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_background_index_failure.py +0 -0
  100. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_bench_corpus_typed.py +0 -0
  101. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_bench_gate.py +0 -0
  102. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_bench_graphify.py +0 -0
  103. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_bench_oracle.py +0 -0
  104. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_bench_oracle_ts.py +0 -0
  105. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_bench_qualified.py +0 -0
  106. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_c4.py +0 -0
  107. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_c4_check.py +0 -0
  108. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_c4_layers.py +0 -0
  109. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_c4_model.py +0 -0
  110. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_c4_output.py +0 -0
  111. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_cache.py +0 -0
  112. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_chunking.py +0 -0
  113. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_cli_commands.py +0 -0
  114. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_cli_help.py +0 -0
  115. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_cli_install_dry_run.py +0 -0
  116. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_cli_install_offer_injection.py +0 -0
  117. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_cold_process.py +0 -0
  118. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_config.py +0 -0
  119. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_corpus.py +0 -0
  120. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_could_not_ask_semantic.py +0 -0
  121. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_dispatch_callers.py +0 -0
  122. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_docs_ci_claims.py +0 -0
  123. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_docs_deadcode_withdrawal.py +0 -0
  124. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_docs_trust_claims.py +0 -0
  125. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_doctor.py +0 -0
  126. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_e2e.py +0 -0
  127. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_edge_confidence.py +0 -0
  128. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_edge_endpoint_cap.py +0 -0
  129. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_engine_adoption.py +0 -0
  130. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_enterprise.py +0 -0
  131. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_gateway.py +0 -0
  132. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_graph_failure_population.py +0 -0
  133. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_graph_provider.py +0 -0
  134. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_graph_real.py +0 -0
  135. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_graph_stdin.py +0 -0
  136. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_grapher.py +0 -0
  137. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_hard_exit.py +0 -0
  138. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_hardening.py +0 -0
  139. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_http_auth.py +0 -0
  140. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_http_server.py +0 -0
  141. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_incompleteness.py +0 -0
  142. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_index_failure_reason.py +0 -0
  143. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_index_incompleteness.py +0 -0
  144. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_index_progress.py +0 -0
  145. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_indexer_binary.py +0 -0
  146. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_installer.py +0 -0
  147. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_integration.py +0 -0
  148. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_lang_config.py +0 -0
  149. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_loc_census.py +0 -0
  150. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_lsp_language_coverage.py +0 -0
  151. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_lsp_provider.py +0 -0
  152. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_lsp_real.py +0 -0
  153. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_mapper.py +0 -0
  154. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_mcp_handshake.py +0 -0
  155. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_mcp_server.py +0 -0
  156. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_missing_target.py +0 -0
  157. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_model_dimension.py +0 -0
  158. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_never_raise.py +0 -0
  159. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_null_reason_and_ripple.py +0 -0
  160. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_onboarding.py +0 -0
  161. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_per_thread.py +0 -0
  162. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_qualifier_scan.py +0 -0
  163. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_query_budget.py +0 -0
  164. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_rbac.py +0 -0
  165. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_redaction_boundary.py +0 -0
  166. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_reindex_lock.py +0 -0
  167. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_reindexer.py +0 -0
  168. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_rerank.py +0 -0
  169. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_reset.py +0 -0
  170. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_semantic_provider.py +0 -0
  171. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_source_kind.py +0 -0
  172. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_staleness.py +0 -0
  173. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_symbol_context.py +0 -0
  174. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_term.py +0 -0
  175. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_treesitter.py +0 -0
  176. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_uninstall.py +0 -0
  177. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_upgrade_path.py +0 -0
  178. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_verify.py +0 -0
  179. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_verify_call.py +0 -0
  180. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_version_skew.py +0 -0
  181. {codecortex-0.27.0 → codecortex-0.28.0}/tests/test_wire_text.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codecortex
3
- Version: 0.27.0
3
+ Version: 0.28.0
4
4
  Summary: Local-first, MCP-native code-intelligence server — graph, LSP, and semantic search behind one safe code.query tool for coding agents.
5
5
  Author: Shammai Hamilton
6
6
  License-Expression: MIT
@@ -540,7 +540,7 @@ Register codeintel as an MCP server (`codeintel install`) and the agent gets fou
540
540
  | MCP tool | HTTP equivalent | Purpose |
541
541
  |---|---|---|
542
542
  | `code.query` | `POST /code/query` | The main call — search, trace, understand (the `op` table above) |
543
- | `code.status` | `GET /code/status` | Per-engine `installed` / `runnable` / `repo_indexed` (plus `model_cached` for semantic), probed against the live engines a query actually hits, plus `degraded`: engines that are installed but not working — see [docs/doctor.md](docs/doctor.md) |
543
+ | `code.status` | `GET /code/status` | Per-engine `installed` / `runnable` / `repo_indexed` (plus `model_cached` for semantic), probed against the live engines a query actually hits, plus `indexed` (true when graph or semantic has indexed this repo; `indexed_by` names which) and `degraded`: engines that are installed but not working — see [docs/doctor.md](docs/doctor.md) |
544
544
  | `code.doctor` | `POST /code/doctor` | Per-engine health + repo index status, with a fix for each gap |
545
545
  | `code.map` | — | Generate/refresh `CODE_INTEL.md`, a static orientation file for hosts without MCP |
546
546
 
@@ -499,7 +499,7 @@ Register codeintel as an MCP server (`codeintel install`) and the agent gets fou
499
499
  | MCP tool | HTTP equivalent | Purpose |
500
500
  |---|---|---|
501
501
  | `code.query` | `POST /code/query` | The main call — search, trace, understand (the `op` table above) |
502
- | `code.status` | `GET /code/status` | Per-engine `installed` / `runnable` / `repo_indexed` (plus `model_cached` for semantic), probed against the live engines a query actually hits, plus `degraded`: engines that are installed but not working — see [docs/doctor.md](docs/doctor.md) |
502
+ | `code.status` | `GET /code/status` | Per-engine `installed` / `runnable` / `repo_indexed` (plus `model_cached` for semantic), probed against the live engines a query actually hits, plus `indexed` (true when graph or semantic has indexed this repo; `indexed_by` names which) and `degraded`: engines that are installed but not working — see [docs/doctor.md](docs/doctor.md) |
503
503
  | `code.doctor` | `POST /code/doctor` | Per-engine health + repo index status, with a fix for each gap |
504
504
  | `code.map` | — | Generate/refresh `CODE_INTEL.md`, a static orientation file for hosts without MCP |
505
505
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codecortex
3
- Version: 0.27.0
3
+ Version: 0.28.0
4
4
  Summary: Local-first, MCP-native code-intelligence server — graph, LSP, and semantic search behind one safe code.query tool for coding agents.
5
5
  Author: Shammai Hamilton
6
6
  License-Expression: MIT
@@ -540,7 +540,7 @@ Register codeintel as an MCP server (`codeintel install`) and the agent gets fou
540
540
  | MCP tool | HTTP equivalent | Purpose |
541
541
  |---|---|---|
542
542
  | `code.query` | `POST /code/query` | The main call — search, trace, understand (the `op` table above) |
543
- | `code.status` | `GET /code/status` | Per-engine `installed` / `runnable` / `repo_indexed` (plus `model_cached` for semantic), probed against the live engines a query actually hits, plus `degraded`: engines that are installed but not working — see [docs/doctor.md](docs/doctor.md) |
543
+ | `code.status` | `GET /code/status` | Per-engine `installed` / `runnable` / `repo_indexed` (plus `model_cached` for semantic), probed against the live engines a query actually hits, plus `indexed` (true when graph or semantic has indexed this repo; `indexed_by` names which) and `degraded`: engines that are installed but not working — see [docs/doctor.md](docs/doctor.md) |
544
544
  | `code.doctor` | `POST /code/doctor` | Per-engine health + repo index status, with a fix for each gap |
545
545
  | `code.map` | — | Generate/refresh `CODE_INTEL.md`, a static orientation file for hosts without MCP |
546
546
 
@@ -145,6 +145,7 @@ tests/test_lsp_language_coverage.py
145
145
  tests/test_lsp_provider.py
146
146
  tests/test_lsp_real.py
147
147
  tests/test_mapper.py
148
+ tests/test_mcp_answer_size.py
148
149
  tests/test_mcp_handshake.py
149
150
  tests/test_mcp_server.py
150
151
  tests/test_missing_target.py
@@ -0,0 +1 @@
1
+ __version__ = "0.28.0"
@@ -292,7 +292,11 @@ class ChangedSince(AnswerRendering):
292
292
  touched: dict[str, set[str]] = {}
293
293
  for e in entries:
294
294
  if e.change.change != REMOVED:
295
- touched.setdefault(e.path, set()).add(e.qn)
295
+ # A closure the diff rewrote is a caller the diff touched: the graph files it as a
296
+ # caller of its own, under its enclosing function's name or directly under its
297
+ # module, and only its parent is a key of the diff.
298
+ touched.setdefault(e.path, set()).update(
299
+ (e.qn, *e.change.nested_changed, *e.change.nested_bare))
296
300
  files_in_diff = {c.path for c, _ in diffs}
297
301
  added_at: dict[str, list[str]] = {}
298
302
  for e in entries:
@@ -468,7 +472,9 @@ class ChangedSince(AnswerRendering):
468
472
 
469
473
  @staticmethod
470
474
  def _caller_is_changed(row: dict, touched: dict[str, set[str]]) -> bool:
471
- """Whether a caller is itself a definition this diff added, rewrote or re-signed.
475
+ """Whether a caller is itself a definition this diff added, rewrote or re-signed — or a
476
+ function nested in one whose OWN text the diff changed (`SymbolChange.nested_changed`); a
477
+ sibling closure the diff left alone stays untouched.
472
478
 
473
479
  A MODULE-SCOPE caller is never counted: the diff is compared definition by definition, so
474
480
  whether a file's top-level statements changed is not something it knows. It is left on the
@@ -1,6 +1,8 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import json
3
4
  import os
5
+ import shlex
4
6
  import threading
5
7
  import time
6
8
  from typing import Annotated, Literal
@@ -12,7 +14,7 @@ from pydantic import Field
12
14
 
13
15
  from codeintel.gateway import Gateway
14
16
  from codeintel.policy import TieringPolicy
15
- from codeintel.provider import Result, safe_null_result
17
+ from codeintel.provider import Result, log_swallowed, safe_null_result
16
18
  from codeintel.providers.graph import GraphProvider
17
19
  from codeintel.providers.lsp import LspProvider
18
20
  from codeintel.providers.semantic import SemanticProvider
@@ -124,6 +126,59 @@ def _refresh_missing_engines(gw: Gateway) -> None:
124
126
  pass
125
127
 
126
128
 
129
+ # The most an MCP `code.query` envelope may serialize to. Claude Code's client refuses a tool result
130
+ # over its token limit (25,000 by default) and spills it to a file the agent never reads, and a
131
+ # branch-wide `changed` came back at 113,352 bytes — its `rows` repeating, as structured data, every
132
+ # finding the `result` text already states. 40,000 bytes is about 10,000 tokens: under the limit with
133
+ # room for the agent's own context. The CLI (`codeintel query --json`) is not bound by it.
134
+ MCP_ENVELOPE_BUDGET_BYTES = 40_000
135
+
136
+
137
+ def _size(obj: object) -> int:
138
+ return len(json.dumps(obj, default=str).encode("utf-8"))
139
+
140
+
141
+ def compact_for_mcp(env: dict, op: str, target: str) -> dict:
142
+ """*env* as an MCP client can take it: unchanged when it fits the byte budget; otherwise with
143
+ `rows` cut to the leading rows that fit, and the cut counted (`rows_total`, `rows_omitted`)
144
+ and explained (`rows_note`, with the command that prints them all).
145
+
146
+ Only `rows` is cut. `result` is the answer — every finding is stated there — and the rest of the
147
+ envelope (`gaps`, `evidence`, `confidence`) is what says how far to trust it, so neither is
148
+ trimmed: an answer cut mid-text, or stripped of its caveats, is worse than one that is long."""
149
+ try:
150
+ rows = env.get("rows")
151
+ if not isinstance(rows, list) or not rows or _size(env) <= MCP_ENVELOPE_BUDGET_BYTES:
152
+ return env
153
+ cmd = (f"codeintel query --op {shlex.quote(op)}"
154
+ + (f" --target {shlex.quote(target)}" if target else "") + " --json")
155
+ out = dict(env)
156
+ out["rows"] = []
157
+ out["rows_total"] = len(rows)
158
+ out["rows_omitted"] = len(rows)
159
+ out["rows_note"] = (
160
+ f"{len(rows)} of {len(rows)} rows left out to keep this answer under the MCP client's "
161
+ f"size limit. The answer text in `result` is not cut; for all rows as data run "
162
+ f"`{cmd}` in the project root.")
163
+ room = MCP_ENVELOPE_BUDGET_BYTES - _size(out) - 16 # the note's count can grow a digit
164
+ kept = 0
165
+ for row in rows:
166
+ cost = _size(row) + 2 # ", " between rows
167
+ if cost > room:
168
+ break
169
+ room -= cost
170
+ kept += 1
171
+ omitted = len(rows) - kept
172
+ out["rows"] = rows[:kept]
173
+ out["rows_omitted"] = omitted
174
+ out["rows_note"] = out["rows_note"].replace(
175
+ f"{len(rows)} of {len(rows)} rows", f"{omitted} of {len(rows)} rows", 1)
176
+ return out
177
+ except Exception as exc:
178
+ log_swallowed("server.compact_for_mcp", exc)
179
+ return env
180
+
181
+
127
182
  def code_query_handler(args: dict) -> Result:
128
183
  try:
129
184
  op = args.get("op", "")
@@ -176,6 +231,7 @@ _STATUS_FALLBACK: dict = {
176
231
  "lsp": False,
177
232
  "semantic": False,
178
233
  "indexed": False,
234
+ "indexed_by": [],
179
235
  "model": None,
180
236
  "healthy": False,
181
237
  # `None`, not `[]`: this fallback means the status could not be produced, and `[]` is the report's
@@ -196,8 +252,10 @@ def _code_status_handler_inner(args: dict) -> dict:
196
252
  boolean per engine, so `lsp: true` could mean "uvx is on PATH" for an engine that in fact
197
253
  never boots — an agent reading that would reason from a readiness claim nothing verified.
198
254
 
199
- The flat `graph`/`lsp`/`semantic`/`indexed`/`model` keys keep their original meaning for
200
- existing callers; `readiness` and `healthy` carry the full picture. That meaning is
255
+ The flat `graph`/`lsp`/`semantic`/`model` keys keep their original meaning for existing
256
+ callers; `readiness` and `healthy` carry the full picture. `indexed` changed meaning in 0.28.0:
257
+ it is "some indexing engine has indexed this repo" (`indexed_by` names which), no longer the
258
+ semantic engine's word alone. That meaning is
201
259
  INSTALLED, not usable: `graph: true` is a binary on PATH, and was reported next to a backend
202
260
  that refused to start. `degraded` names the engines that are installed and failing — including
203
261
  the optional graph engine, which `healthy` deliberately ignores — so a caller reads that
@@ -253,12 +311,17 @@ def _code_status_handler_inner(args: dict) -> dict:
253
311
  if not engines:
254
312
  engines = ["none"]
255
313
 
256
- # `indexed` stays semantic-scoped and back-compatible: for a given repo it means "this
257
- # repo has chunks"; with no project_root it falls back to "any index exists on this box".
258
- indexed = False
314
+ # `indexed`: SOME engine that indexes (graph, semantic) has indexed THIS repo, and
315
+ # `indexed_by` names which. It used to be the semantic engine's word alone, so a repo the
316
+ # graph had indexed read `indexed: false` — "this repo is not indexed" — and with no
317
+ # project_root it was "any semantic*.db exists in the per-machine cache", which made every
318
+ # repo on the machine indexed once one was. Both now come from the probes of the root
319
+ # doctor resolved (the server's cwd when none is given), like every other field here.
320
+ indexed_by = [n for n in ("graph", "semantic") if readiness[n]["repo_indexed"] is True]
321
+ indexed = bool(indexed_by)
259
322
  model = None
260
323
  try:
261
- from codeintel.semantic_db import DEFAULT_MODEL, default_db_path
324
+ from codeintel.semantic_db import DEFAULT_MODEL
262
325
  if semantic_available:
263
326
  model = DEFAULT_MODEL
264
327
  if project_root:
@@ -267,13 +330,6 @@ def _code_status_handler_inner(args: dict) -> dict:
267
330
  model = str(load_config(project_root).get("model") or DEFAULT_MODEL)
268
331
  except Exception:
269
332
  pass
270
- indexed = readiness["semantic"]["repo_indexed"] is True
271
- else:
272
- import glob
273
- import os
274
- # any per-model cache file (semantic.db / semantic-<hash>.db) counts as "indexed"
275
- base = os.path.dirname(default_db_path())
276
- indexed = bool(glob.glob(os.path.join(base, "semantic*.db")))
277
333
  except Exception:
278
334
  pass
279
335
 
@@ -285,6 +341,7 @@ def _code_status_handler_inner(args: dict) -> dict:
285
341
  "lsp": lsp_available,
286
342
  "semantic": semantic_available,
287
343
  "indexed": indexed,
344
+ "indexed_by": indexed_by,
288
345
  "model": model,
289
346
  "healthy": bool(summary.get("healthy")),
290
347
  # Derived from the probes read above rather than copied from `report`, so a report that
@@ -429,7 +486,10 @@ _MCP_INSTRUCTIONS = (
429
486
  "argument, a factory call, an alias) reaches the method without ever writing the class's name, "
430
487
  "as does an interface-typed field, a subclass or a renaming re-export — so false is not proof, "
431
488
  "and you should not filter on it before a delete or a rename. No class-qualified Python target "
432
- "has been measured."
489
+ "has been measured.\n\n"
490
+ "An answer too large for this client keeps its whole `result` text but cuts `rows[]` to the "
491
+ "leading rows that fit: `rows_total` and `rows_omitted` count the cut, and `rows_note` gives the "
492
+ "`codeintel query ... --json` command that prints every row."
433
493
  )
434
494
 
435
495
 
@@ -513,9 +573,10 @@ def run() -> None:
513
573
  # annotation, and it validates a TypedDict's NotRequired keys (`reason`, `hint`) as
514
574
  # REQUIRED — so every successful query, which carries neither, comes back to the agent as
515
575
  # `isError: true`. Guarded by test_mcp_server.py::test_no_tool_advertises_the_optional_*.
516
- return dict(code_query_handler(
576
+ # Bounded for the MCP client (`compact_for_mcp`); the CLI's `--json` keeps every row.
577
+ return compact_for_mcp(dict(code_query_handler(
517
578
  {"op": op, "target": target, "project_root": project_root, "engine": engine, "role": role}
518
- ))
579
+ )), op, target)
519
580
 
520
581
  async def _code_status(
521
582
  project_root: Annotated[str, Field(description=_PROJECT_ROOT_FIELD_DESCRIPTION)] = "",
@@ -574,7 +635,9 @@ def run() -> None:
574
635
  annotations=ToolAnnotations(read_only_hint=True),
575
636
  description=(
576
637
  "Read-only. Which engines (graph/LSP/semantic) are available and whether this repo is "
577
- "indexed. Check this first if code.query keeps returning nothing. The top-level "
638
+ "indexed. Check this first if code.query keeps returning nothing. `indexed` is true "
639
+ "when ANY indexing engine (graph or semantic) has indexed this repo, and `indexed_by` "
640
+ "names which — per-engine detail is `readiness.<engine>.repo_indexed`. The top-level "
578
641
  "`graph`/`lsp`/`semantic` flags mean INSTALLED, not usable — read `readiness` for "
579
642
  "that, and `degraded` for engines that are installed but failing (`healthy` ignores "
580
643
  "the optional graph engine)."
@@ -44,10 +44,13 @@ THREE THINGS IT DECLINES TO DO, because the alternative is a classification nobo
44
44
  from __future__ import annotations
45
45
 
46
46
  import ast
47
+ import io
47
48
  import os
48
49
  import re
50
+ import sys
51
+ import tokenize
49
52
  from collections.abc import Iterable
50
- from dataclasses import dataclass
53
+ from dataclasses import dataclass, replace
51
54
  from typing import Any
52
55
 
53
56
  REMOVED = "removed"
@@ -73,6 +76,10 @@ _TS_SUPPORTED = frozenset({"typescript", "tsx", "javascript", "go", "rust", "jav
73
76
 
74
77
  _PYTHON_EXTS = (".py", ".pyi")
75
78
 
79
+ # The tree-sitter definition types that, found inside a function's body, are a nested function.
80
+ _TS_NESTED_FUNC_TYPES = frozenset({
81
+ "function_declaration", "generator_function_declaration", "function_item"})
82
+
76
83
 
77
84
  @dataclass(frozen=True)
78
85
  class SymbolChange:
@@ -86,6 +93,15 @@ class SymbolChange:
86
93
  # What part moved: for `signature`, which header facet(s) (`parameters (+x, -y)`, `return
87
94
  # annotation`, `decorators`, `async`); for `body`, `docstring only` when nothing else did.
88
95
  facets: tuple[str, ...] = ()
96
+ # The functions nested inside this one that the diff added or rewrote (`App.downloadPlan`). A
97
+ # closure is not a symbol of its own here — no other module can name it — but the graph records
98
+ # it as a CALLER in its own right, and without this a closure edited together with a callee's
99
+ # signature was reported as a caller the diff did not touch.
100
+ nested_changed: tuple[str, ...] = ()
101
+ # The same closures by their bare name (`downloadPlan`), for a graph that files a closure
102
+ # directly under its module. Only names no definition of the file's own also uses: a bare name
103
+ # shared with a top-level function would mark THAT function touched when it was not.
104
+ nested_bare: tuple[str, ...] = ()
89
105
 
90
106
 
91
107
  @dataclass(frozen=True)
@@ -113,6 +129,9 @@ class _One:
113
129
  plain_body: tuple # the body without a leading docstring
114
130
  line: int
115
131
  params: tuple[str, ...] = ()
132
+ # Every function nested in this one, at any depth, by its name relative to this one
133
+ # (`inner`, `inner.helper`) with a fingerprint of its whole text.
134
+ nested: tuple[tuple[str, tuple], ...] = ()
116
135
 
117
136
 
118
137
  class _Unparsable(Exception):
@@ -165,6 +184,11 @@ def diff_file(path: str, old_source: str | None, new_source: str | None) -> File
165
184
  (old_defs if side == "old" else new_defs).update(table)
166
185
  changes = [c for qn in sorted(set(old_defs) | set(new_defs))
167
186
  if (c := _classify(qn, old_defs.get(qn), new_defs.get(qn))) is not None]
187
+ own_bare = {qn.rsplit(".", 1)[-1] for qn in (*old_defs, *new_defs)}
188
+ changes = [replace(c, nested_bare=tuple(dict.fromkeys(
189
+ b for n in c.nested_changed
190
+ if (b := n.rsplit(".", 1)[-1]) not in own_bare)))
191
+ if c.nested_changed else c for c in changes]
168
192
  changes.sort(key=lambda c: (SEVERITY[c.change], c.new_line or c.old_line or 0))
169
193
  return FileSymbolDiff(path, STATUS_OK, language, tuple(changes), unnamed=unnamed)
170
194
  except _Unsupported as exc:
@@ -176,8 +200,29 @@ def diff_file(path: str, old_source: str | None, new_source: str | None) -> File
176
200
 
177
201
  # ------------------------------------------------------------------------------------ comparing
178
202
 
203
+ def _nested_changed(qn: str, old: list[_One] | None, new: list[_One] | None) -> tuple[str, ...]:
204
+ """The nested functions present in *new* whose text is not the same as in *old*."""
205
+ before = {name: print_ for o in old or () for name, print_ in o.nested}
206
+ out: dict[str, None] = {}
207
+ for n in new or ():
208
+ for name, print_ in n.nested:
209
+ if before.get(name) != print_:
210
+ out[f"{qn}.{name}"] = None
211
+ return tuple(out)
212
+
213
+
179
214
  def _classify(
180
215
  qn: str, old: list[_One] | None, new: list[_One] | None
216
+ ) -> SymbolChange | None:
217
+ change = _classify_one(qn, old, new)
218
+ if change is None or change.change == REMOVED:
219
+ return change
220
+ nested = _nested_changed(qn, old, new)
221
+ return replace(change, nested_changed=nested) if nested else change
222
+
223
+
224
+ def _classify_one(
225
+ qn: str, old: list[_One] | None, new: list[_One] | None
181
226
  ) -> SymbolChange | None:
182
227
  if old and not new:
183
228
  return SymbolChange(qn, REMOVED, old[0].kind, old[0].line, None)
@@ -239,6 +284,20 @@ def _dump_all(nodes: Iterable[ast.AST]) -> tuple[str, ...]:
239
284
  return tuple(ast.dump(n) for n in nodes)
240
285
 
241
286
 
287
+ def _py_nested(stmts: list[ast.stmt], prefix: str = "") -> list[tuple[str, tuple]]:
288
+ """Every function defined inside *stmts*, at any depth, named relative to the enclosing one."""
289
+ out: list[tuple[str, tuple]] = []
290
+ for node in stmts:
291
+ if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
292
+ name = prefix + node.name
293
+ out.append((name, (ast.dump(node),)))
294
+ out.extend(_py_nested(node.body, name + "."))
295
+ elif not isinstance(node, ast.ClassDef):
296
+ for block in _child_blocks(node):
297
+ out.extend(_py_nested(block, prefix))
298
+ return out
299
+
300
+
242
301
  def _py_function(node: ast.FunctionDef | ast.AsyncFunctionDef, in_class: bool) -> _One:
243
302
  args = node.args
244
303
  every = [*args.posonlyargs, *args.args, *([args.vararg] if args.vararg else []),
@@ -257,6 +316,7 @@ def _py_function(node: ast.FunctionDef | ast.AsyncFunctionDef, in_class: bool) -
257
316
  plain_body=body[1:] if node.body and _is_docstring(node.body[0]) else body,
258
317
  line=node.lineno,
259
318
  params=tuple(a.arg for a in every),
319
+ nested=tuple(_py_nested(node.body)),
260
320
  )
261
321
 
262
322
 
@@ -294,13 +354,95 @@ def _child_blocks(node: ast.AST) -> Iterable[list[ast.stmt]]:
294
354
  yield v.body
295
355
 
296
356
 
357
+ _PARSE_ERRORS = (SyntaxError, ValueError, RecursionError, MemoryError)
358
+
359
+
360
+ def _parenthesize_except_lists(source: str) -> str | None:
361
+ """*source* with every PEP 758 `except A, B:` written as `except (A, B):`, or None if it has none.
362
+
363
+ Python 3.14 dropped the parentheses (PEP 758); an older interpreter's `ast.parse` rejects the
364
+ whole file for it, and every definition in it then went unseen. The two spellings are the same
365
+ tree on 3.14 — an `ExceptHandler` whose `type` is a `Tuple` — so rewriting them is a reading of
366
+ the file, not a guess at it. A list followed by `as` is left alone: that still needs the
367
+ parentheses on 3.14, and accepting it would read a file no interpreter runs. Only the clause's
368
+ own line(s) change, and only by inserting two characters, so line numbers survive."""
369
+ try:
370
+ toks = list(tokenize.generate_tokens(io.StringIO(source).readline))
371
+ except (tokenize.TokenError, SyntaxError, ValueError, RecursionError, MemoryError):
372
+ return None
373
+ inserts: list[tuple[tuple[int, int], str]] = []
374
+ i = 0
375
+ while i < len(toks):
376
+ tok = toks[i]
377
+ if not (tok.type == tokenize.NAME and tok.string == "except"):
378
+ i += 1
379
+ continue
380
+ j = i + 1
381
+ if j < len(toks) and toks[j].type == tokenize.OP and toks[j].string == "*":
382
+ j += 1
383
+ start, depth, comma, end, has_as = j, 0, False, None, False
384
+ while j < len(toks):
385
+ t = toks[j]
386
+ if t.type == tokenize.OP and t.string in "([{":
387
+ depth += 1
388
+ elif t.type == tokenize.OP and t.string in ")]}":
389
+ depth -= 1
390
+ elif depth == 0 and t.type == tokenize.OP and t.string == ",":
391
+ comma = True
392
+ elif depth == 0 and t.type == tokenize.NAME and t.string == "as":
393
+ has_as = True
394
+ elif depth == 0 and t.type == tokenize.OP and t.string == ":":
395
+ end = j
396
+ break
397
+ elif t.type in (tokenize.NEWLINE, tokenize.ENDMARKER):
398
+ break
399
+ j += 1
400
+ if comma and not has_as and end is not None and start < end:
401
+ inserts.append((toks[start].start, "("))
402
+ inserts.append((toks[end].start, ")"))
403
+ i = j + 1
404
+ if not inserts:
405
+ return None
406
+ lines = source.splitlines(keepends=True)
407
+ # Back to front, so an insertion never moves a position still to be used.
408
+ for (row, col), text in sorted(inserts, reverse=True):
409
+ line = lines[row - 1]
410
+ lines[row - 1] = line[:col] + text + line[col:]
411
+ return "".join(lines)
412
+
413
+
414
+ def _parse_python(source: str) -> ast.Module:
415
+ """`ast.parse`, but a file is not unreadable merely for being newer than this interpreter.
416
+
417
+ The one newer spelling that is known to stop a whole real file — PEP 758's unparenthesized
418
+ `except` list — is read as what it means. Anything else this interpreter cannot parse raises
419
+ as before, and the caller says WHICH Python failed to read it (`_unparsable_reason`)."""
420
+ try:
421
+ return ast.parse(source)
422
+ except SyntaxError as exc:
423
+ rewritten = _parenthesize_except_lists(source) if sys.version_info < (3, 14) else None
424
+ if rewritten is None:
425
+ raise
426
+ try:
427
+ return ast.parse(rewritten)
428
+ except _PARSE_ERRORS:
429
+ raise exc from None
430
+
431
+
432
+ def _unparsable_reason(exc: BaseException) -> str:
433
+ reason = f"line {exc.lineno}: {exc.msg}" if isinstance(exc, SyntaxError) else (
434
+ f"{type(exc).__name__}: {exc}")
435
+ # The interpreter is named because "does not parse" is otherwise read as "this file is broken",
436
+ # and a file written for a newer Python than the tool runs on is not.
437
+ here = f"Python {sys.version_info.major}.{sys.version_info.minor}"
438
+ return f"does not parse as Python ({reason}; parsed with {here}, so newer syntax also fails)"
439
+
440
+
297
441
  def _python_definitions(source: str) -> tuple[dict[str, list[_One]], int]:
298
442
  try:
299
- tree = ast.parse(source)
300
- except (SyntaxError, ValueError, RecursionError, MemoryError) as exc:
301
- reason = f"line {exc.lineno}: {exc.msg}" if isinstance(exc, SyntaxError) else (
302
- f"{type(exc).__name__}: {exc}")
303
- raise _Unparsable(f"does not parse as Python ({reason})"[:200]) from exc
443
+ tree = _parse_python(source)
444
+ except _PARSE_ERRORS as exc:
445
+ raise _Unparsable(_unparsable_reason(exc)[:240]) from exc
304
446
  out: dict[str, list[_One]] = {}
305
447
 
306
448
  def visit(stmts: list[ast.stmt], prefix: str, in_class: bool) -> None:
@@ -353,7 +495,26 @@ def _ts_function_value(node):
353
495
  return node
354
496
 
355
497
 
356
- def _ts_one(node, is_method: bool) -> _One:
498
+ def _ts_nested(body, is_nested, name_of, prefix: str = "") -> list[tuple[str, tuple]]:
499
+ """Every named function declared inside *body*, at any depth, named relative to the enclosing
500
+ one: `function f() {}` and `const f = () => {}` alike, the second being how React components
501
+ write their handlers."""
502
+ out: list[tuple[str, tuple]] = []
503
+ stack = list(reversed(body.children))
504
+ while stack:
505
+ n = stack.pop()
506
+ if is_nested(n) and (name := name_of(n)):
507
+ qn = prefix + name
508
+ out.append((qn, _tokens(n)))
509
+ inner = _ts_function_value(n).child_by_field_name("body")
510
+ if inner is not None:
511
+ out.extend(_ts_nested(inner, is_nested, name_of, qn + "."))
512
+ continue
513
+ stack.extend(reversed(n.children))
514
+ return out
515
+
516
+
517
+ def _ts_one(node, is_method: bool, is_nested=None, name_of=None) -> _One:
357
518
  target = _ts_function_value(node)
358
519
  body = target.child_by_field_name("body")
359
520
  tail: tuple[str, ...] = ()
@@ -367,6 +528,8 @@ def _ts_one(node, is_method: bool) -> _One:
367
528
  body=tail,
368
529
  plain_body=tail,
369
530
  line=node.start_point[0] + 1,
531
+ nested=tuple(_ts_nested(body, is_nested, name_of))
532
+ if body is not None and is_nested is not None else (),
370
533
  )
371
534
 
372
535
 
@@ -427,6 +590,14 @@ def _treesitter_definitions(source: str, lang: str) -> tuple[dict[str, list[_One
427
590
  cont_types = _TS_CONTAINER_TYPES.get(lang, set())
428
591
  arrow_ok = lang in _TS_ARROW_LANGS
429
592
  name_of = Indexer._ts_node_name
593
+ # What counts as a function NESTED in another: a declaration of one, never a method (an object
594
+ # literal's method is not a closure the graph files as a caller of its own).
595
+ nested_types = {t for t in func_types if t in _TS_NESTED_FUNC_TYPES}
596
+
597
+ def is_nested(n) -> bool:
598
+ return n.type in nested_types or (
599
+ arrow_ok and n.type in _TS_DECL_TYPES and _ts_decl_is_function(n))
600
+
430
601
  out: dict[str, list[_One]] = {}
431
602
  unnamed = 0
432
603
  stack: list[tuple[Any, str]] = [(root, "")]
@@ -456,7 +627,8 @@ def _treesitter_definitions(source: str, lang: str) -> tuple[dict[str, list[_One
456
627
  is_go_method = lang == "go" and child.type == "method_declaration"
457
628
  recv = _go_receiver(child) if is_go_method else None
458
629
  qn = f"{recv}.{name}" if recv else prefix + name
459
- out.setdefault(qn, []).append(_ts_one(child, bool(prefix) or is_go_method))
630
+ out.setdefault(qn, []).append(
631
+ _ts_one(child, bool(prefix) or is_go_method, is_nested, name_of))
460
632
  else:
461
633
  stack.append((child, prefix))
462
634
  return out, unnamed
@@ -478,8 +650,8 @@ def classify_mentions(source: str, name: str, lines: Iterable[int]) -> dict[int,
478
650
  the line is code."""
479
651
  wanted = list(lines)
480
652
  try:
481
- tree = ast.parse(source)
482
- except (SyntaxError, ValueError, RecursionError, MemoryError):
653
+ tree = _parse_python(source)
654
+ except _PARSE_ERRORS:
483
655
  return {}
484
656
  word = re.compile(rf"(?<![A-Za-z0-9_]){re.escape(name)}(?![A-Za-z0-9_])")
485
657
  code: set[int] = set()
@@ -1525,3 +1525,103 @@ def test_a_fifo_at_a_tracked_path_is_not_read_and_cannot_hang_the_reader(tmp_pat
1525
1525
  pass
1526
1526
  assert not thread.is_alive(), "read_new blocked on a FIFO"
1527
1527
  assert out == {"pipe": None, "plain": "x = 1\n"}, out
1528
+
1529
+
1530
+ # ========================== D2: a closure the diff rewrote is a caller the diff touched, not one it left
1531
+
1532
+ def _status_of(env: dict, symbol: str) -> dict[str, str]:
1533
+ return {r["qualified_name"].removeprefix(f"{PROJECT}."): r["caller_status"]
1534
+ for r in env["rows"] if r["changed_symbol"] == symbol}
1535
+
1536
+
1537
+ _PY_USE = '''\
1538
+ from m.core import f
1539
+
1540
+
1541
+ def outer():
1542
+ def edited():
1543
+ return f(1)
1544
+
1545
+ def left():
1546
+ return f(3)
1547
+
1548
+ return edited() + left()
1549
+
1550
+
1551
+ VALUE = f(4)
1552
+ '''
1553
+
1554
+
1555
+ def test_a_python_closure_rewritten_with_the_callee_lands_under_also_changed(monkeypatch, tmp_path):
1556
+ """`f` gains a parameter and `outer.edited` is rewritten to pass it. The graph names the
1557
+ closure as the caller, the diff's key is `outer`, and the two never matched — so the one caller
1558
+ that was fixed was reported as one that may break. Its sibling `left`, which the diff did not
1559
+ touch, and the module-scope call, which the diff cannot see, stay on the untouched side."""
1560
+ repo = _branch(tmp_path, "py-closure",
1561
+ {"m/__init__.py": "", "m/core.py": "def f(a):\n return a\n",
1562
+ "m/use.py": _PY_USE},
1563
+ {"m/core.py": "def f(a, b):\n return a\n",
1564
+ "m/use.py": _PY_USE.replace("f(1)", "f(1, 2)")})
1565
+ graph = _Graph()
1566
+ graph.edges["f"] = [
1567
+ _edge("f", "m/core.py", "m.use.outer.edited", "m/use.py"),
1568
+ _edge("f", "m/core.py", "m.use.outer.left", "m/use.py"),
1569
+ ]
1570
+ env = _ask(_provider(monkeypatch, tmp_path, repo, graph), repo)
1571
+ assert _status_of(env, "f") == {
1572
+ "m.use.outer.edited": "also-changed", "m.use.outer.left": "untouched"}, env["result"]
1573
+
1574
+
1575
+ _APP_BASE = '''\
1576
+ import { runnerFile } from "./runner"
1577
+
1578
+ export function App() {
1579
+ function downloadPlan() {
1580
+ return runnerFile(plan)
1581
+ }
1582
+ const exportPlan = () => {
1583
+ return runnerFile(plan)
1584
+ }
1585
+ const printPlan = () => runnerFile(plan)
1586
+ return null
1587
+ }
1588
+ '''
1589
+
1590
+ _APP_WORK = '''\
1591
+ import { runnerFile } from "./runner"
1592
+
1593
+ export function App() {
1594
+ async function downloadPlan() {
1595
+ return await runnerFile(plan, "zip")
1596
+ }
1597
+ const exportPlan = async () => {
1598
+ return await runnerFile(plan, "json")
1599
+ }
1600
+ const printPlan = () => runnerFile(plan)
1601
+ return null
1602
+ }
1603
+ '''
1604
+
1605
+
1606
+ @pytest.mark.parametrize("nesting", ["flattened", "qualified"])
1607
+ def test_a_react_components_inner_functions_rewritten_with_the_callee_land_under_also_changed(
1608
+ monkeypatch, tmp_path, nesting):
1609
+ """The defect as found: `runnerFile` re-signed, and `App`'s `downloadPlan` and `exportPlan`
1610
+ rewritten to match, were listed under "Callers this diff did NOT touch". The graph has been
1611
+ seen filing a closure directly under its module (`web.src.App.downloadPlan`); a graph that
1612
+ keeps the enclosing function (`web.src.App.App.downloadPlan`) must match too. `printPlan` was
1613
+ not edited and stays untouched."""
1614
+ repo = _branch(tmp_path, f"tsx-{nesting}",
1615
+ {"web/src/runner.ts": "export function runnerFile(p) { return p }\n",
1616
+ "web/src/App.tsx": _APP_BASE},
1617
+ {"web/src/runner.ts": "export function runnerFile(p, fmt) { return p }\n",
1618
+ "web/src/App.tsx": _APP_WORK})
1619
+ scope = "web.src.App." if nesting == "flattened" else "web.src.App.App."
1620
+ graph = _Graph()
1621
+ graph.edges["runnerFile"] = [
1622
+ _edge("runnerFile", "web/src/runner.ts", scope + name, "web/src/App.tsx")
1623
+ for name in ("downloadPlan", "exportPlan", "printPlan")]
1624
+ env = _ask(_provider(monkeypatch, tmp_path, repo, graph), repo)
1625
+ assert _status_of(env, "runnerFile") == {
1626
+ scope + "downloadPlan": "also-changed", scope + "exportPlan": "also-changed",
1627
+ scope + "printPlan": "untouched"}, env["result"]