Skip to content

feat: auto-index on first tool call when project is not yet indexed#156

Open
maplenk wants to merge 2 commits intoDeusData:mainfrom
maplenk:feat/auto-index
Open

feat: auto-index on first tool call when project is not yet indexed#156
maplenk wants to merge 2 commits intoDeusData:mainfrom
maplenk:feat/auto-index

Conversation

@maplenk
Copy link
Copy Markdown

@maplenk maplenk commented Mar 27, 2026

Summary

When any query tool is called and the project isn't indexed yet, the server now auto-indexes it inline instead of returning "not indexed". This eliminates the manual index_repository step for first-time use — users can just start asking questions.

The existing background auto-index at startup is preserved; this adds synchronous fallback when a tool call arrives before background indexing completes (or when it wasn't triggered).

Changes

  • try_auto_index() — consolidates resolve_store + verify_project_indexed into a single function that auto-indexes on cache miss. Respects auto_index config flag and auto_index_limit file count guard. Uses pipeline lock to avoid concurrent indexing. Waits for any in-progress background auto-index thread before falling back to inline indexing.
  • session_project_alt — handles macOS /tmp/private/tmp symlink variants so tool calls with either project name resolve correctly
  • cbm_mcp_server_set_session_root() — public API for external session injection (derives both primary and alt project names)
  • 6 handlers modified to use try_auto_index(): get_graph_schema, search_graph, query_graph, get_architecture, trace_call_path, get_code_snippet

Guards

  • Config-gated: requires auto_index = true (default: false)
  • File limit: rejects repos exceeding auto_index_limit (default: 50,000 files)
  • Shell-safe path validation before git ls-files
  • Pipeline lock prevents concurrent indexing

Blocking behavior

On a cache miss, the first query can block while inline indexing runs; this path is gated by auto_index=true and auto_index_limit.

Test plan

  • Integration test: creates temp project, does NOT pre-index, calls search_graph → verifies auto-index triggers and returns results
  • All 2587 tests pass (existing + new)
  • Build clean on macOS arm64

@maplenk
Copy link
Copy Markdown
Author

maplenk commented Mar 27, 2026

These changes are based on other open PRs. Majorly #151

maplenk and others added 2 commits March 27, 2026 17:55
When any query tool is called and the project isn't indexed yet, the
server now auto-indexes it inline instead of returning "not indexed".
This eliminates the manual index_repository step for first-time use.

Key changes:
- try_auto_index() consolidates resolve_store + verify_project_indexed
  across query handlers, with config/file-limit guards and pipeline lock
- session_project_alt handles macOS /tmp → /private/tmp symlink variants
- char **project_ptr pattern ensures callers get the canonical name
- cbm_mcp_server_set_session_root() public API for external session injection
- Integration test covers the full auto-index-on-search_graph path
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@DeusData DeusData added enhancement New feature or request ux/behavior Display bugs, docs, adoption UX labels Mar 27, 2026
@DeusData
Copy link
Copy Markdown
Owner

@maplenk — auto-indexing on first tool call is an interesting idea, but this is a UX/behavior change that needs discussion first. Please open an issue. See CONTRIBUTING.md.

The current explicit index_repository call is intentional — it gives the user control over when indexing happens and avoids surprise latency on the first query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request ux/behavior Display bugs, docs, adoption UX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants