Repository navigation
feat(config): add polylogue.toml loading with four-layer precedence (#829) - #889
Conversation
…829) Add load_polylogue_config() with TOML file loading, environment variable overrides, and CLI override support. Four-layer precedence: defaults → polylogue.toml → POLYLOGUE_* env vars → CLI flags. Add `polylogue config show` command with --format toml|json. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Warning Rate limit exceeded
To continue reviewing without waiting, purchase usage credits in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (8)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e47e3becdf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
Adds initial support for loading a polylogue.toml config file with layered precedence and exposes a new polylogue config CLI command to display the resolved configuration.
Changes:
- Introduce TOML config discovery/loading and env/CLI override merging helpers in
polylogue/config.py. - Add
polylogue configCLI subcommand (TOML/JSON output) and register it in the root command set. - Update generated docs/catalogs to account for the new CLI command and file topology.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
polylogue/config.py |
Implements polylogue.toml discovery + merge/override logic and config rendering helpers. |
polylogue/cli/commands/config.py |
Adds polylogue config command to print resolved config as TOML or JSON. |
polylogue/cli/click_command_registration.py |
Registers the new config command in root CLI commands. |
docs/verification-catalog.md |
Updates generated verification catalog counts and adds polylogue config entry. |
docs/topology-status.md |
Updates generated topology status counts. |
docs/test-quality-workflows.md |
Updates generated workflow counts and adds config help exercise entry. |
docs/plans/topology-target.yaml |
Declares the new CLI command file in topology targets. |
docs/cli-reference.md |
Adds config to CLI command reference list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| """Load resolved Polylogue config with four-layer precedence. | ||
|
|
||
| Returns a dict suitable for constructing typed config models. | ||
| The dict always has all known keys with defaults applied. | ||
| """ | ||
| cfg: dict[str, object] = { | ||
| "archive_root": str(archive_root()), | ||
| "daemon_url": "http://127.0.0.1:8766", | ||
| "daemon_host": "127.0.0.1", | ||
| "daemon_port": 8766, | ||
| "embedding_enabled": False, | ||
| "embedding_model": "voyage-4", | ||
| "embedding_dimension": 1024, | ||
| "embedding_max_cost_usd": 0.0, | ||
| "hooks_enabled": False, | ||
| "log_level": "INFO", | ||
| "force_plain": False, | ||
| } |
| def _config_file_path() -> Path | None: | ||
| """Resolve the polylogue.toml path. | ||
|
|
||
| Returns the first existing path from: | ||
| 1. ``POLYLOGUE_CONFIG`` env var | ||
| 2. ``{XDG_CONFIG_HOME}/polylogue/polylogue.toml`` | ||
| 3. ``{project_root}/polylogue.toml`` | ||
| Returns None if no file exists. | ||
| """ | ||
| override = os.environ.get("POLYLOGUE_CONFIG") | ||
| if override: | ||
| p = Path(override) | ||
| return p if p.is_file() else None | ||
|
|
||
| xdg_path = config_home() / "polylogue.toml" | ||
| if xdg_path.is_file(): | ||
| return xdg_path | ||
|
|
||
| project_path = Path("polylogue.toml") | ||
| if project_path.is_file(): | ||
| return project_path | ||
|
|
| except (OSError, tomllib.TOMLDecodeError): | ||
| pass |
| section_keys = { | ||
| "archive": ("archive_root",), | ||
| "daemon": ("daemon_host", "daemon_port"), | ||
| "embedding": ("embedding_enabled", "embedding_model", "embedding_dimension", "embedding_max_cost_usd"), | ||
| "hooks": ("hooks_enabled",), | ||
| "logging": ("log_level", "force_plain"), | ||
| } |
| def _apply_env_overrides(cfg: dict[str, object]) -> None: | ||
| """Apply POLYLOGUE_* environment variable overrides.""" | ||
| env_map = { | ||
| "POLYLOGUE_ARCHIVE_ROOT": "archive_root", | ||
| "POLYLOGUE_DAEMON_ENABLE_EMBEDDINGS": "embedding_enabled", | ||
| "VOYAGE_API_KEY": "voyage_api_key", | ||
| "POLYLOGUE_FORCE_PLAIN": "force_plain", | ||
| "POLYLOGUE_SLOW_QUERY_NOTICE_SECONDS": "slow_query_notice_seconds", | ||
| "POLYLOGUE_SCHEMA_VALIDATION": "schema_validation", | ||
| } | ||
| for env_var, cfg_key in env_map.items(): | ||
| value = os.environ.get(env_var) | ||
| if value is not None: | ||
| # Coerce booleans | ||
| if value.lower() in ("1", "true", "yes"): | ||
| cfg[cfg_key] = True | ||
| elif value.lower() in ("0", "false", "no"): | ||
| cfg[cfg_key] = False | ||
| else: | ||
| cfg[cfg_key] = value |
| lines.append(f"[{section}]") | ||
| for key, value in data.items(): | ||
| if isinstance(value, str): | ||
| lines.append(f'{key} = "{value}"') | ||
| elif isinstance(value, bool): | ||
| lines.append(f"{key} = {str(value).lower()}") | ||
| else: | ||
| lines.append(f"{key} = {value}") |
| cfg = load_polylogue_config() | ||
|
|
||
| if output_format == "json": | ||
| import json | ||
|
|
||
| env.ui.console.print(json.dumps(cfg, indent=2, default=str)) | ||
| else: | ||
| env.ui.console.print(format_config_toml(cfg)) |
| def load_polylogue_config( | ||
| *, | ||
| config_path: Path | None = None, | ||
| cli_overrides: dict[str, object] | None = None, | ||
| ) -> dict[str, object]: | ||
| """Load resolved Polylogue config with four-layer precedence. | ||
|
|
||
| Returns a dict suitable for constructing typed config models. | ||
| The dict always has all known keys with defaults applied. | ||
| """ | ||
| cfg: dict[str, object] = { | ||
| "archive_root": str(archive_root()), | ||
| "daemon_url": "http://127.0.0.1:8766", | ||
| "daemon_host": "127.0.0.1", | ||
| "daemon_port": 8766, | ||
| "embedding_enabled": False, | ||
| "embedding_model": "voyage-4", | ||
| "embedding_dimension": 1024, | ||
| "embedding_max_cost_usd": 0.0, | ||
| "hooks_enabled": False, | ||
| "log_level": "INFO", | ||
| "force_plain": False, | ||
| } | ||
|
|
||
| # Layer 2: TOML file | ||
| path = config_path or _config_file_path() | ||
| if path is not None: | ||
| try: | ||
| with open(path, "rb") as fh: | ||
| toml_data = tomllib.load(fh) | ||
| _merge_toml(cfg, toml_data) | ||
| except (OSError, tomllib.TOMLDecodeError): | ||
| pass | ||
|
|
||
| # Layer 3: Environment variables | ||
| _apply_env_overrides(cfg) | ||
|
|
||
| # Layer 4: CLI overrides | ||
| if cli_overrides: | ||
| for key, value in cli_overrides.items(): | ||
| if value is not None: | ||
| cfg[key] = value | ||
|
|
||
| return cfg |
Foundation slice for #829. Polylogue mixed hardcoded defaults, scattered env reads, CLI flags, and partial dataclasses; after #847 daemon convergence, embeddings, hook install, auth, and health policies all needed one config contract. - `polylogue/config.py`: introduces `polylogue.toml` loading with the four-layer precedence (defaults → user TOML at `$XDG_CONFIG_HOME/polylogue/polylogue.toml` → environment variables → CLI flags / programmatic overrides). Defines the schema sections `[archive]`, `[daemon]`, `[daemon.api]`, `[notifications]`, `[health]`. - `polylogue/cli/commands/config.py` and registration: `polylogue config show` lets operators see the resolved config and the layer that supplied each value. - `docs/cli-reference.md`, `docs/topology-status.md`, etc.: generated surfaces refreshed. Refs #829
Foundation slice for #829. Polylogue mixed hardcoded defaults, scattered `os.environ.get()` calls, CLI flags, and partial dataclasses; after #847 daemon convergence, embeddings, hook install, auth, and health all need one config contract. - `polylogue/config.py`: introduces `PolylogueConfig` dataclass with typed fields covering archive root, daemon settings, watch sources, embedding settings, and notification backend. `load_polylogue_config()` returns the typed instance and applies the four-layer precedence (defaults → TOML → env → flags) introduced in PR #889. - Six previously direct `os.environ.get()` reads under `cli/query_progress.py`, `cli/shared/formatting.py`, `daemon/status.py`, `logging.py`, `paths/_roots.py`, `pipeline/services/{ingest_worker,validation_flow}.py` now go through the config object so future env additions land in one place. Refs #829
Foundation slice for #829. Polylogue mixed hardcoded defaults, scattered env reads, CLI flags, and partial dataclasses; after #847 daemon convergence, embeddings, hook install, auth, and health policies all needed one config contract. - `polylogue/config.py`: introduces `polylogue.toml` loading with the four-layer precedence (defaults → user TOML at `$XDG_CONFIG_HOME/polylogue/polylogue.toml` → environment variables → CLI flags / programmatic overrides). Defines the schema sections `[archive]`, `[daemon]`, `[daemon.api]`, `[notifications]`, `[health]`. - `polylogue/cli/commands/config.py` and registration: `polylogue config show` lets operators see the resolved config and the layer that supplied each value. - `docs/cli-reference.md`, `docs/topology-status.md`, etc.: generated surfaces refreshed. Refs #829
Foundation slice for #829. Polylogue mixed hardcoded defaults, scattered `os.environ.get()` calls, CLI flags, and partial dataclasses; after #847 daemon convergence, embeddings, hook install, auth, and health all need one config contract. - `polylogue/config.py`: introduces `PolylogueConfig` dataclass with typed fields covering archive root, daemon settings, watch sources, embedding settings, and notification backend. `load_polylogue_config()` returns the typed instance and applies the four-layer precedence (defaults → TOML → env → flags) introduced in PR #889. - Six previously direct `os.environ.get()` reads under `cli/query_progress.py`, `cli/shared/formatting.py`, `daemon/status.py`, `logging.py`, `paths/_roots.py`, `pipeline/services/{ingest_worker,validation_flow}.py` now go through the config object so future env additions land in one place. Refs #829
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
TOML config loading, 4-layer precedence, config show command. 8 files +222/-12. All gates passed.