Query library and layering: extract tool logic from the 38k-line bin-only server.rs, move registry.rs out of core, split IndexAccess into an access crate #517

Open
opened 2026-11-09 08:03:46 +01:00 by buildagent · 0 comments
Member

Consolidated scope (triage 2026-11-09)

Priority: Medium: one query path instead of three, and the remaining module cycles.

This issue is now the canonical tracker for:

  • The layering half: core/src/registry.rs makes core depend on the signing crate; split IndexAccess and the wire rows into an access crate (edges moved to #543) (from #526, closed and merged here; its full report stays readable there)
  • 2 of 4 cycles gone; access↔local_index is resolved by the access crate; cli link↔main is harmless crate-root coupling (from #32, closed and merged here; its full report stays readable there)
  • SCC/layering analysis: as a cargo-metadata CI test (for example, plugin-host must not depend on daemon), not a new tool (from #28, closed and merged here; its full report stays readable there)

Original report

Summary

The logic behind every MCP tool lives in crates/mcp-server/src/server.rs, which is 38,497 lines with 558 top-level items and 41 interleaved #[cfg(test)] blocks, inside a crate with no lib.rs. That one fact produces three query paths and several workarounds:

  • The CLI starts a server process for every query. crates/cli/src/query.rs:20-48 explains it directly: "crates/mcp-server is a BIN-ONLY crate … the same move here means publishing a 28k-line server as a library". So code-index query spawns code-index-mcp and speaks stdio to it. That doc comment is itself stale: the file has grown about 10k lines since.
  • The daemon side has its own query semantics behind IndexAccess: daemon/src/local_index.rs (12.8k lines), graph.rs (4.3k) and refactor.rs (5.0k).
  • server.rs also opens SQLite directly, bypassing IndexAccess (around :2308, :4330, :4348, :4384, :8929), and makes about 198 code_index_indexer:: references.
  • single_process (crates/mcp-server/src/main.rs:995-1387) is a fourth wiring of the same tools for --no-daemon.

Related size problems: indexer/src/index.rs is 22k lines, daemon/src/local_index.rs 12.8k, and daemon/src/main.rs run is one async fn spanning lines 653-1750 (1,098 lines), followed by rearm_for_activation (244 lines). Parallel lanes concentrate their merge conflicts in these files, and every edit to them recompiles and re-reviews a very large unit.

Proposal (mechanical, no redesign)

  1. Extract a code-index-query library crate holding the tool handlers, argument checking and the disclosure envelope (annotate_evidence_gaps), written only against IndexAccess. Move the direct SQLite health probes behind IndexAccess methods.
  2. code-index-mcp, code-index query and --no-daemon all become thin transports over that library. The CLI calls it in-process against an RPC IndexAccess, with no process spawn, and still returns the same answers and the same envelope, which keeps #282's requirement.
  3. Use one module per tool (tools/<tool>.rs) with its unit tests beside it.
  4. Split daemon run into startup, the event-loop body and shutdown functions.

Acceptance

  • The daemon⇄snapshot parity runner and the MCP e2e suites stay green, including COSI_E2E_LEG=daemon.
  • code-index query returns byte-identical JSON before and after, except that the spawn disappears. Measure its latency.

Related: #32 (dependency cycles). Found by automated architecture and bloat reviews (2026-11-09). The bin-only crate and the query.rs rationale were verified by hand.


Filed from a five-agent review of master @ e3ec6ead (bloat, robustness, agent usefulness, docs, architecture). Every finding was spot-checked in the main session before filing.

## Consolidated scope (triage 2026-11-09) **Priority: Medium**: one query path instead of three, and the remaining module cycles. This issue is now the canonical tracker for: - [ ] The layering half: `core/src/registry.rs` makes `core` depend on the signing crate; split `IndexAccess` and the wire rows into an `access` crate (edges moved to #543) (from #526, closed and merged here; its full report stays readable there) - [ ] 2 of 4 cycles gone; `access`↔`local_index` is resolved by the access crate; `cli` `link`↔`main` is harmless crate-root coupling (from #32, closed and merged here; its full report stays readable there) - [ ] SCC/layering analysis: as a cargo-metadata CI test (for example, plugin-host must not depend on daemon), not a new tool (from #28, closed and merged here; its full report stays readable there) --- ## Original report ## Summary The logic behind every MCP tool lives in `crates/mcp-server/src/server.rs`, which is **38,497 lines with 558 top-level items and 41 interleaved `#[cfg(test)]` blocks**, inside a crate with **no `lib.rs`**. That one fact produces three query paths and several workarounds: - **The CLI starts a server process for every query.** `crates/cli/src/query.rs:20-48` explains it directly: "`crates/mcp-server` is a BIN-ONLY crate … the same move here means publishing a 28k-line server as a library". So `code-index query` spawns `code-index-mcp` and speaks stdio to it. That doc comment is itself stale: the file has grown about 10k lines since. - **The daemon side has its own query semantics** behind `IndexAccess`: `daemon/src/local_index.rs` (12.8k lines), `graph.rs` (4.3k) and `refactor.rs` (5.0k). - **`server.rs` also opens SQLite directly**, bypassing `IndexAccess` (around `:2308, :4330, :4348, :4384, :8929`), and makes about 198 `code_index_indexer::` references. - `single_process` (`crates/mcp-server/src/main.rs:995-1387`) is a fourth wiring of the same tools for `--no-daemon`. Related size problems: `indexer/src/index.rs` is 22k lines, `daemon/src/local_index.rs` 12.8k, and `daemon/src/main.rs` `run` is one async fn spanning lines 653-1750 (1,098 lines), followed by `rearm_for_activation` (244 lines). Parallel lanes concentrate their merge conflicts in these files, and every edit to them recompiles and re-reviews a very large unit. ## Proposal (mechanical, no redesign) 1. Extract a `code-index-query` library crate holding the tool handlers, argument checking and the disclosure envelope (`annotate_evidence_gaps`), written **only** against `IndexAccess`. Move the direct SQLite health probes behind `IndexAccess` methods. 2. `code-index-mcp`, `code-index query` and `--no-daemon` all become thin transports over that library. The CLI calls it in-process against an RPC `IndexAccess`, with no process spawn, and still returns the same answers and the same envelope, which keeps #282's requirement. 3. Use one module per tool (`tools/<tool>.rs`) with its unit tests beside it. 4. Split daemon `run` into startup, the event-loop body and shutdown functions. ## Acceptance - The daemon⇄snapshot parity runner and the MCP e2e suites stay green, including `COSI_E2E_LEG=daemon`. - `code-index query` returns byte-identical JSON before and after, except that the spawn disappears. Measure its latency. Related: #32 (dependency cycles). Found by automated architecture and bloat reviews (2026-11-09). The bin-only crate and the query.rs rationale were verified by hand. --- _Filed from a five-agent review of master @ e3ec6ead (bloat, robustness, agent usefulness, docs, architecture). Every finding was spot-checked in the main session before filing._
buildagent changed title from Extract tool logic from the 38k-line bin-only server.rs into a query library; the CLI spawns a server process per query to Query library and layering: extract tool logic from the 38k-line bin-only server.rs, move registry.rs out of core, split IndexAccess into an access crate 2026-11-09 09:21:01 +01:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
h-dv/code-index#517
No description provided.