Skip to content

feat(config): unified polylogue.toml with explicit layer precedence (#829) - #1143

Merged
Sinity merged 1 commit into
masterfrom
feature/feat/unified-config-layers
May 17, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/feat/unified-config-layers

Conversation

@Sinity

@Sinity Sinity commented May 17, 2026

Copy link
Copy Markdown
Owner

Summary

Establishes the five-layer config precedence chain described in #829
(defaults → site → user → env → CLI) and surfaces layer provenance
through polylogue config --show-layers.

Problem

polylogue/config.py already had a PolylogueConfig loader that read a
single TOML and POLYLOGUE_* env vars, but it did not match the
contract in #829 in three ways:

  1. No site-wide config layer. Issue specifies
    /etc/polylogue/polylogue.toml so packaging can ship defaults that
    are themselves overridable per user.
  2. No provenance. Operators could read the resolved values but had no
    way to ask "which layer did this come from?" — the very question
    feat(config): unified config system — polylogue.toml, four-layer precedence, shared daemon/CLI config #829 calls out for polylogue config --show-layers.
  3. The config CLI command did not expose layer information at all.

Solution

polylogue/config.py:

  • Adds DEFAULT_SITE_CONFIG_PATH = /etc/polylogue/polylogue.toml and
    _site_config_path() with a POLYLOGUE_SITE_CONFIG override (empty
    string disables, e.g. for tests and ephemeral environments).
  • Splits the loader into a pure _default_config_values() and an
    _apply_toml_layer() helper that records which keys each layer
    actually changed.
  • load_polylogue_config(site_config_path=..., config_path=..., cli_overrides=...)
    now walks defaults → site TOML → user TOML → env → CLI in order and
    builds a layers map alongside the resolved values.
  • PolylogueConfig gains layers (dict) and layer_of(key) accessors;
    malformed TOML is swallowed silently so a broken site config cannot
    brick the CLI.
  • describe_config_layers() returns a JSON-friendly view of the
    resolved site and user config paths plus existence flags, used by
    polylogue config --show-layers.

polylogue/cli/commands/config.py:

  • Adds --show-layers to the existing polylogue config command.
  • Emits the layer descriptor + per-key {value, layer} map in either
    TOML or JSON (both via console.print(..., markup=False) so JSON and
    TOML headers survive Rich markup parsing).

tests/unit/core/test_config.py:

  • TestPolylogueConfigLayerPrecedence covers every transition
    (default → site → user → env → CLI), the missing-file fallthrough,
    and the malformed-TOML graceful fallback.
  • TestDescribeConfigLayers covers the structured report including
    the POLYLOGUE_SITE_CONFIG="" disable case.

The inherited init-command snapshot drift on master (#1116 landed
without refreshing tests/unit/cli/__snapshots__/test_terminal_snapshots.ambr)
is included so pytest tests/unit/cli/test_terminal_snapshots.py is
green again on this branch.

Verification

nix develop -c devtools verify --quick
# total_duration_s 20.29, exit_code 0

nix develop -c pytest tests/unit/core/test_config.py -q
# 81 passed in 7.88s

nix develop -c pytest tests/unit/cli/test_terminal_snapshots.py -q
# 9 passed in 8.48s

POLYLOGUE_SITE_CONFIG='' POLYLOGUE_API_PORT=9999 \
  POLYLOGUE_FORCE_PLAIN=1 nix develop -c polylogue config --show-layers
# api_port = 9999  # layer = env

Ref #829

Establishes the five-layer precedence chain described in #829 with
provenance tracking surfaced through `polylogue config --show-layers`.

Layers (low → high):
  1. built-in defaults
  2. site TOML  — /etc/polylogue/polylogue.toml (env: POLYLOGUE_SITE_CONFIG)
  3. user TOML  — $XDG_CONFIG_HOME/polylogue/polylogue.toml or ./polylogue.toml
                  (env: POLYLOGUE_CONFIG)
  4. POLYLOGUE_* env vars
  5. CLI overrides (per-invocation)

`PolylogueConfig` now exposes `layers` and `layer_of(key)` so callers
(and the CLI) can report which physical layer supplied each value.
`describe_config_layers()` complements that by reporting the resolved
file paths and existence for the site and user layers.

The CLI `polylogue config` command gains `--show-layers` and emits
the layer descriptor + per-key provenance in either TOML or JSON.

Inherited snapshot drift from the master `init` command (#1116) is
refreshed in the same change so the syrupy gate is green again.

Ref #829

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented May 17, 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 52 minutes and 50 seconds before requesting another review.

You’ve run out of usage credits. Purchase more 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: 7d6d9356-d529-43c2-996e-ecd63d93b2d0

📥 Commits

Reviewing files that changed from the base of the PR and between e7bf42f and 43db757.

📒 Files selected for processing (4)
  • polylogue/cli/commands/config.py
  • polylogue/config.py
  • tests/unit/cli/__snapshots__/test_terminal_snapshots.ambr
  • tests/unit/core/test_config.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/unified-config-layers

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.

@Sinity
Sinity merged commit 3617391 into master May 17, 2026
3 checks passed
@Sinity
Sinity deleted the feature/feat/unified-config-layers branch May 17, 2026 00:40

@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

return p if p.is_file() else None

P2 Badge Preserve explicit override paths in layer report

Do not drop POLYLOGUE_CONFIG/POLYLOGUE_SITE_CONFIG paths when the file is missing, because polylogue config --show-layers is supposed to explain where each layer points and whether it exists. With the current is_file() gate, an explicit but mistyped path is reported as path: null, which hides the operator error and makes the new diagnostics far less useful.

ℹ️ 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
Comment on lines +492 to +493
if before_env.get(key, _MISSING) != value:
layers[key] = "env"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Record provenance by key presence, not value delta

Update the layer map even when a higher-precedence layer sets the same value, otherwise --show-layers reports misleading provenance. For example, setting POLYLOGUE_API_PORT=8766 currently leaves api_port marked as default because the value did not change, even though the env layer explicitly supplied it; the same issue applies to TOML layers that restate default values.

Useful? React with 👍 / 👎.

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