Skip to content

feat(config): add polylogue.toml loading with four-layer precedence (#829) - #889

Merged
Sinity merged 1 commit into
masterfrom
feature/feat/config-root-829
May 7, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/feat/config-root-829

Conversation

@Sinity

@Sinity Sinity commented May 7, 2026

Copy link
Copy Markdown
Owner

TOML config loading, 4-layer precedence, config show command. 8 files +222/-12. All gates passed.

…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]>
Copilot AI review requested due to automatic review settings May 7, 2026 08:21
@Sinity
Sinity merged commit 2ea09fe into master May 7, 2026
@Sinity
Sinity deleted the feature/feat/config-root-829 branch May 7, 2026 08:21
@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 29 minutes and 38 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 01d10291-a41e-41cf-8f92-93a0886e6005

📥 Commits

Reviewing files that changed from the base of the PR and between 0cd125f and e47e3be.

📒 Files selected for processing (8)
  • docs/cli-reference.md
  • docs/plans/topology-target.yaml
  • docs/test-quality-workflows.md
  • docs/topology-status.md
  • docs/verification-catalog.md
  • polylogue/cli/click_command_registration.py
  • polylogue/cli/commands/config.py
  • polylogue/config.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/config-root-829

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread polylogue/config.py Resolved
Comment thread polylogue/config.py Resolved
Comment thread polylogue/config.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 config CLI 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.

Comment thread polylogue/config.py
Comment on lines +199 to +216
"""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,
}
Comment thread polylogue/config.py
Comment on lines +169 to +190
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

Comment thread polylogue/config.py
Comment on lines +225 to +226
except (OSError, tomllib.TOMLDecodeError):
pass
Comment thread polylogue/config.py
Comment on lines +242 to +248
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"),
}
Comment thread polylogue/config.py
Comment on lines +257 to +276
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
Comment thread polylogue/config.py
Comment on lines +308 to +315
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}")
Comment on lines +24 to +31
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))
Comment thread polylogue/config.py
Comment on lines +194 to +237
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 61.F148 / P2: fixed-already at the checked revision: polylogue/config.py:1559 normalizes POLYLOGUE_CONFIG through _expand_bootstrap_path before testing existence. The helper expands a leading ~/ against the captured home at lines 1496-1497, so that spelling no longer disables an existing config file.
  • 61.F149 / P2: stale at the checked revision: The flat daemon host/port merge described in the review is retired and those keys are now rejected at polylogue/config.py:1871. The replacement inventory explicitly separates daemon.url, the client endpoint, from daemon.api host/port, the server listen address, rather than promising to derive one from the other.
  • 61.F150 / P2: fixed-already at the checked revision: polylogue/config.py:1893 restricts boolean parsing to keys in _BOOL_CONFIG_KEYS. Integer and floating-point keys take separate conversions at lines 1907 and 1912, so a numeric value of 1 is no longer generically converted to True.

Only the rows listed above are dispositioned. Held findings remain open.

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.

2 participants