Skip to content

Walk-up config discovery, configurable source root, and microservice auto-scope#277

Merged
HumanBean17 merged 6 commits into
masterfrom
feat/dirs-hierarchy
Jun 7, 2026
Merged

Walk-up config discovery, configurable source root, and microservice auto-scope#277
HumanBean17 merged 6 commits into
masterfrom
feat/dirs-hierarchy

Conversation

@HumanBean17

Copy link
Copy Markdown
Owner

Summary

  • Walk-up config discovery: Tool walks up directory tree to find .java-codebase-rag.yml, similar to git's behavior with .git. Users can run CLI and MCP commands from any subdirectory within their project.
  • Configurable source root: YAML config gains optional source_root field so the config can live separately from Java source code. Index dir auto-derives from resolved source root.
  • Microservice auto-scope: When working from a microservice subdirectory, queries automatically scope to that microservice. Agents see correct codebase boundaries without manual filters.
  • Zero-env-var configuration: MCP hosts can now use minimal configuration without JAVA_CODEBASE_RAG_SOURCE_ROOT env var.

Test Plan

  • All 21 new tests pass (config discovery, precedence, microservice scope)
  • ruff check passes with no errors
  • Existing test suite passes (no regressions)
  • CLI commands work from subdirectories (walk-up finds config)
  • MCP server auto-detects microservice scope at startup
  • Tool wrappers apply auto-scope when no explicit microservice filter provided

HumanBean17 and others added 4 commits June 7, 2026 11:50
- 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 HumanBean17 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_pathmicroservice_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.

HumanBean17 and others added 2 commits June 7, 2026 13:08
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>
@HumanBean17 HumanBean17 merged commit 84cef79 into master Jun 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant