Skip to content

feat: add compound query tools (explore, understand, prepare_change)#149

Open
maplenk wants to merge 10 commits intoDeusData:mainfrom
maplenk:feat/compound-queries
Open

feat: add compound query tools (explore, understand, prepare_change)#149
maplenk wants to merge 10 commits intoDeusData:mainfrom
maplenk:feat/compound-queries

Conversation

@maplenk
Copy link

@maplenk maplenk commented Mar 26, 2026

Summary

Three new tools that bundle multiple graph queries into single-call responses, reducing agent round-trips from 4–5 tool calls to 1.

Stacked PR: This builds on #148 (Blast Radius) which builds on #147 (PageRank). Please merge those first — this PR's unique changes are the 1 commit after PR 2's HEAD.

New tools

  • explore — Area exploration. Takes a keyword, runs 3 searches (name/QN/path), merges and dedupes, adds dependency summaries for top matches, hotspots from PageRank, entry points from architecture. Token-budgeted.

  • understand — Symbol deep-dive. 3-tier resolution: exact QN → short name (auto-pick by PageRank) → suffix match (returns suggestions if ambiguous). Returns source code, 1-hop callers/callees sorted by PageRank, connected symbols with relation labels, key symbol status.

  • prepare_change — Pre-change analysis. Wraps impact analysis with review_scope: must_review (target + direct callers), should_review (indirect), tests. Token budget priority: root → direct → review scope → tests.

Bug fixes included

12 fixes across all phases — highlights:

  • OOM infinite loop in markdown_builder_reserve
  • SQLite bind parameter limit in impact_fetch_nodes_with_scores
  • POSIX regex invalid PCRE prefix ((?:...)(...))
  • Memory leaks in 5 MCP handlers (REQUIRE_STORE early-return paths)
  • qsort(NULL, 0) undefined behavior
  • cbm_mcp_text_result(NULL) crash guard
  • summary_count_nodes returning -1 on SQL error
  • Search degree filter min/max_degree = -1 handling
  • explore total_results overcounting

Tests

15 new tests + 3 integration tests. Total: 2639 passing.


Part 3 of a 4-PR series. Depends on #148#147.


Built with OpenAI Codex and Claude Code.

@DeusData
Copy link
Owner

Thanks @maplenk — compound query tools that combine multiple graph operations into higher-level actions is a nice abstraction. Will review.

Naman Khator and others added 10 commits March 27, 2026 18:10
Account for optional signatures in the search_graph and trace_call_path size estimators, and improve compact trace chains to report omitted-node counts.

This also documents the normal-path output enrichment introduced with Task 4: search_graph results now include file_path, start_line, end_line, and signature, and trace_call_path hop items now include file_path, start_line, and signature.
- Guard cbm_mcp_text_result() against NULL text
- Fix memory leak in handle_get_key_symbols() REQUIRE_STORE path (focus not freed)
- Wire qn_pattern through handle_search_graph()
- Fix OOM infinite loop in markdown_builder_reserve()
- Return 0 instead of CBM_STORE_ERR from summary_count_nodes() on prepare fail

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Prefer non-test symbol matches before pagerank for ambiguous short names. Batch-load visited node metadata and pagerank scores to remove per-node query loops during impact analysis. Hide test counts from the public summary when include_tests=false, and add max_tokens truncation support to get_impact_analysis with MCP coverage.
Add the impact-analysis store API declaration, expose get_impact_analysis in CLI help text, and cover the tool with the existing integration fixture.
- Chunk impact_fetch_nodes_with_scores() into batches of 900 to stay
  under SQLite's SQLITE_MAX_VARIABLE_NUMBER bind limit
- Replace REQUIRE_STORE in handle_get_impact_analysis() with explicit
  cleanup that frees symbol on early return
- Fix pre-existing test_integration assertion that used escaped JSON
  field matching (was already failing on origin/feat/blast-radius)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Phase 5: Three new compound MCP tools (explore, understand, prepare_change)
that bundle multiple graph queries into single-call responses:
- explore: area search with matches, dependencies, hotspots, entry points
- understand: symbol deep-dive with 3-tier resolution (exact QN, exact name
  with auto-pick, QN suffix with suggestions), callers, callees, source,
  connected symbols, is_key_symbol flag
- prepare_change: wraps impact analysis with review_scope (must_review,
  should_review, tests) and include_tests=false support
- All three support max_tokens budget with progressive truncation
- Wire qn_pattern in store search (completing pre-existing API contract)

Bug fixes across all committed phases:
- Fix REQUIRE_STORE leaking heap args in 5 handlers (get_key_symbols,
  get_impact_analysis, explore, understand, prepare_change)
- Fix markdown_builder_reserve infinite loop on OOM (NULL check after
  safe_realloc)
- Fix SQLite bind parameter limit in impact_fetch_nodes_with_scores
  (chunk into batches of 900)
- Fix cbm_mcp_text_result(NULL) crash on OOM (guard with empty string)
- Fix POSIX regex: remove invalid PCRE (?i) prefix from contains pattern
- Fix search degree filter: set min_degree/max_degree to -1 (disabled)
  in compound search helpers
- Fix summary_count_nodes returning -1 on SQL error (return 0 instead)
- Fix explore total_results overcounting unfiltered hotspots
- Fix qsort(NULL, 0) undefined behavior in explore
- Fix handle_understand early return leaking search outputs (use goto)
- Refactor handle_prepare_change to use goto cleanup pattern

Output enrichment (non-breaking):
- search_graph results now include start_line, end_line, signature
- trace_call_path hops now include file_path, start_line, signature

Tests: 2639 passed (+44 new), 0 failures

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@maplenk maplenk force-pushed the feat/compound-queries branch from 83f8e8b to 0e55891 Compare March 27, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants