feat(config): implement three-scope config resolution with local config file support #1195

Merged
freemo merged 1 commits from feature/config-three-scope-resolution into master 2026-03-30 22:09:29 +00:00
Owner

Summary

Implements three-scope configuration resolution (local > project > global) with config.local.toml file support for developer-specific overrides.

Changes

  • src/cleveragents/application/services/config_service.py: Added ConfigScope.LOCAL, ConfigLevel.LOCAL, project-root discovery (walk up from CWD), config.local.toml loading, three-scope deep merge, scoped writes
  • src/cleveragents/cli/commands/config.py: Added --scope local to config set
  • src/cleveragents/application/services/context_service.py: Added config.local.toml to DEFAULT_IGNORE_PATTERNS
  • .gitignore: Added config.local.toml
  • features/config_three_scope.feature: 18 BDD scenarios
  • features/steps/config_three_scope_steps.py: Step definitions

Approach

Resolution follows local > project > global precedence with deep merge. Project root discovery walks up from CWD looking for cleveragents.toml or .cleveragents/. Local config files are .gitignored by default.

Closes #937

## Summary Implements three-scope configuration resolution (`local > project > global`) with `config.local.toml` file support for developer-specific overrides. ## Changes - `src/cleveragents/application/services/config_service.py`: Added `ConfigScope.LOCAL`, `ConfigLevel.LOCAL`, project-root discovery (walk up from CWD), `config.local.toml` loading, three-scope deep merge, scoped writes - `src/cleveragents/cli/commands/config.py`: Added `--scope local` to `config set` - `src/cleveragents/application/services/context_service.py`: Added `config.local.toml` to `DEFAULT_IGNORE_PATTERNS` - `.gitignore`: Added `config.local.toml` - `features/config_three_scope.feature`: 18 BDD scenarios - `features/steps/config_three_scope_steps.py`: Step definitions ## Approach Resolution follows `local > project > global` precedence with deep merge. Project root discovery walks up from CWD looking for `cleveragents.toml` or `.cleveragents/`. Local config files are `.gitignore`d by default. Closes #937
freemo added this to the v3.5.0 milestone 2026-03-29 08:17:55 +00:00
freemo added the
Type
Feature
label 2026-03-29 08:18:00 +00:00
freemo force-pushed feature/config-three-scope-resolution from 036b9b0e7e to 479935686d 2026-03-29 22:37:49 +00:00 Compare
freemo reviewed 2026-03-30 04:21:05 +00:00
freemo left a comment
Author
Owner

Review: Looks Good (self-authored — posted as comment)

Solid config infrastructure enhancement adding local scope resolution.

Notes

  1. ... (Ellipsis) sentinel: Consider a named sentinel (e.g., _AUTO_DISCOVER = object()) for clarity.
  2. Module-level markers mutation in tests: Consider making markers a constructor parameter to avoid monkey-patching.
  3. Good: Backward compatibility maintained. Deep merge utility is well-implemented. config.local.toml properly added to .gitignore.
## Review: Looks Good (self-authored — posted as comment) Solid config infrastructure enhancement adding local scope resolution. ### Notes 1. **`...` (Ellipsis) sentinel**: Consider a named sentinel (e.g., `_AUTO_DISCOVER = object()`) for clarity. 2. **Module-level markers mutation in tests**: Consider making markers a constructor parameter to avoid monkey-patching. 3. **Good**: Backward compatibility maintained. Deep merge utility is well-implemented. `config.local.toml` properly added to `.gitignore`.
freemo reviewed 2026-03-30 04:50:02 +00:00
freemo left a comment
Author
Owner

Updated Review (Deep Pass): Change Required

New Finding: # type: ignore[assignment] violates CONTRIBUTING.md

config_service.py line 1162: project_root: Path | None = ..., # type: ignore[assignment] — This is a direct CONTRIBUTING.md violation (§Type Safety: "never use inline comments to suppress type checking errors").

Fix: Replace with a named sentinel: _AUTO_DISCOVER = object() and annotate as Path | None | object, or use a separate boolean parameter auto_discover: bool = True.

New Finding: config.py at 557 lines — slightly over 500-line limit

The CLI config module now slightly exceeds the limit.

Confirmed: Module-level markers monkey-patched in tests

_PROJECT_ROOT_MARKERS is monkey-patched in step functions. Consider making markers a constructor parameter to avoid this fragile pattern.

Previous findings still apply: Clean three-scope architecture, proper deep merge, config.local.toml in .gitignore.

## Updated Review (Deep Pass): Change Required ### New Finding: `# type: ignore[assignment]` violates CONTRIBUTING.md `config_service.py` line 1162: `project_root: Path | None = ..., # type: ignore[assignment]` — This is a direct CONTRIBUTING.md violation (§Type Safety: "never use inline comments to suppress type checking errors"). **Fix:** Replace with a named sentinel: `_AUTO_DISCOVER = object()` and annotate as `Path | None | object`, or use a separate boolean parameter `auto_discover: bool = True`. ### New Finding: `config.py` at 557 lines — slightly over 500-line limit The CLI config module now slightly exceeds the limit. ### Confirmed: Module-level markers monkey-patched in tests `_PROJECT_ROOT_MARKERS` is monkey-patched in step functions. Consider making markers a constructor parameter to avoid this fragile pattern. ### Previous findings still apply: Clean three-scope architecture, proper deep merge, `config.local.toml` in `.gitignore`.
freemo requested review from CoreRasurae 2026-03-30 05:14:10 +00:00
freemo requested review from hamza.khyari 2026-03-30 05:14:10 +00:00
freemo scheduled this pull request to auto merge when all checks succeed 2026-03-30 21:47:55 +00:00
freemo force-pushed feature/config-three-scope-resolution from 479935686d to 7b3fcaf466 2026-03-30 21:48:02 +00:00 Compare
freemo merged commit 7b3fcaf466 into master 2026-03-30 22:09:29 +00:00
freemo deleted branch feature/config-three-scope-resolution 2026-03-30 22:09:30 +00:00
Sign in to join this conversation.
No Label
Type
Feature
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: cleveragents/cleveragents-core#1195