Walk-up config discovery, configurable source root, and microservice auto-scope#277
Conversation
- Add Hard Gate: prevent writing proposals without discovery - Add systematic 8-step process with task tracking - Agent determines clarifying questions (not scripted) - Present 2-3 solution approaches with trade-offs - Draft sections incrementally with approval - Self-review after writing - User review gate before completion Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit adds the complete design specification for two related features that address workspace flexibility and codebase boundary awareness: Walk-up config discovery: - Tool finds .java-codebase-rag.yml by walking up from cwd (like git) - YAML gains optional source_root field for config/code separation - Index dir auto-derives from resolved source root - Precedence: CLI > env > YAML > walk-up > cwd Microservice auto-scope: - Automatically detects microservice from current working directory - Applies microservice filter to queries when inside a microservice - Prevents agents from seeing code outside their context - Explicit filters always override auto-detected scope Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit addresses all issues found in code review: Critical Issues Fixed: 1. Directory traversal logic - Added detailed algorithm specification with error handling for permissions, inaccessible home, and boundary conditions 2. Microservice detection at source_root - Clarified that cwd=source_root returns None with semantic rationale different from indexing behavior 3. ScopeManager lifecycle - Specified that scope is cached at startup and requires restart for directory changes Important Issues Fixed: 4. Permissions error handling - Added comprehensive error handling table 5. Path resolution documentation - Clarified how precedence interacts with different resolution bases 6. Multiple config files - Specified .yml takes precedence over .yaml 7. _resolve_lancedb_uri integration - Specified behavior when JAVA_CODEBASE_RAG_INDEX_DIR is set but JAVA_CODEBASE_RAG_SOURCE_ROOT is not Minor Issues Fixed: 8. Documentation update timing - Added timing specification to plan 9. Advisory message phrasing - Defined exact log and advisory message text 10. Test file organization - Added justification for separate test files Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…ice auto-scope Implement walk-up config discovery, configurable source root via YAML, and microservice auto-scope for MCP queries. Changes: - Add discover_project_root() to walk up directory tree finding config - Add source_root YAML field for config-source separation - Implement precedence chain: CLI > env > YAML > discovery > cwd - Update _project_root() in server.py to use walk-up discovery - Add detect_microservice_from_path() for microservice detection - Add ScopeManager class for automatic microservice scoping - Wire ScopeManager into all MCP tool wrappers - Add init command warning when parent config detected - Update documentation for walk-up, source_root, and auto-scope - Add mcp.json.example with zero-env-var configuration Tests: 21 new tests covering config discovery, precedence, and microservice scope. All tests pass, ruff check clean. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
HumanBean17
left a comment
There was a problem hiding this comment.
Code Review: Walk-up config discovery, configurable source root, and microservice auto-scope
Overall this is a well-structured PR. The precedence chain is clean, backward compatibility is preserved, test coverage is solid (21/21 passing), and documentation is thorough. Below are specific items worth addressing.
Should fix
1. Duplicate "Key Principles" section in SKILL.md
The old "Final checklist" heading was replaced with "Key Principles", but the file already has a "Key Principles" section immediately below. This creates a duplicate heading — the second one should be renamed or the sections merged.
2. apply_auto_scope shadows built-in filter (server.py:1060)
The parameter name filter shadows Python's built-in. Suggest renaming to node_filter or query_filter.
3. ScopeManager tests bypass actual detection (tests/test_microservice_scope.py:1411-1456)
All TestScopeManager tests manually set mgr.default_scope instead of testing the actual _detect_scope() flow. This means the integration between ScopeManager.__init__ → detect_microservice_from_path → microservice_for_path is untested. At least one test should let __init__ run naturally to exercise the real detection path.
4. detect_microservice_from_path doesn't pass overrides (graph_enrich.py:1589)
The function calls microservice_for_path(str(cwd_resolved), source_resolved) without passing overrides, so YAML microservice_roots config is not respected during scope detection. This could cause auto-scope to disagree with indexing boundaries when custom microservice_roots are configured.
Minor / deferred
5. Advisory messages in MCP responses — The plan specifies advisory messages in MCP responses when queries span multiple microservices at project root, but I only see stderr logging at startup. Worth clarifying whether this is deferred or omitted by design.
6. discover_project_root doesn't handle Path.home() failure (config.py:130-151) — The proposal mentions graceful handling for inaccessible home dirs, but the implementation calls Path.home().resolve() directly. Low risk but worth a try/except if robustness is a goal.
Verdict
The core walk-up discovery and precedence chain are solid. Items 1–3 are quick fixes, item 4 is a potential correctness issue worth confirming.
Add monkeypatch.delenv() calls to tests that need clean environment. The conftest.py mcp_env fixture sets JAVA_CODEBASE_RAG_INDEX_DIR and JAVA_CODEBASE_RAG_SOURCE_ROOT at session level, which was causing test failures when resolve_operator_config(source_root=None) picked up these env vars instead of using walk-up discovery. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Fixes: 1. Remove duplicate "Key Principles" section in SKILL.md 2. Rename apply_auto_scope parameter from 'filter' to 'node_filter' to avoid shadowing built-in 3. Add test_detect_scope_integration to exercise real detection flow 4. Fix detect_microservice_from_path to check cwd against YAML overrides 5. Add test_detect_scope_with_yaml_overrides to verify override behavior Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Summary
.java-codebase-rag.yml, similar to git's behavior with.git. Users can run CLI and MCP commands from any subdirectory within their project.source_rootfield so the config can live separately from Java source code. Index dir auto-derives from resolved source root.JAVA_CODEBASE_RAG_SOURCE_ROOTenv var.Test Plan
ruff checkpasses with no errors