Skip to content

refactor: shared config layer resolution in uteke-core - #1354

Merged
ajianaz merged 1 commit into
developfrom
refactor/config-layer-resolution
Oct 7, 2026
Merged

ajianaz merged 1 commit into
developfrom
refactor/config-layer-resolution

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

What

Step 1 of the Config module (#1342, tracked in #1345): a shared layer resolution module in core, used by both adapters.

  • New uteke_core::config_layers (resolve::<T>(&Layers), deep_merge, strip_untrusted, UNTRUSTED_PROJECT_KEYS): global file then project-local file; tables merge per key, other values (arrays included) from the higher layer replace; untrusted project keys (embedding.{backend,api_key,base_url,endpoint_path}, embed_fallback.*/extraction.* credentials+endpoints, the whole [server] section) are stripped from the project file before merging unless UTEKE_TRUST_PROJECT_CONFIG=1; each layer must validate against the schema on its own, otherwise it is skipped with a warning.
  • CLI: Config::load → Config::from_layers (+ env overrides as before). Deleted merge_from_file (~290 lines, 56 hand-listed contains_key) and restore_sensitive_from. config.rs 2256 → 1936 lines.
  • Server: load_uteke_toml calls the same resolver; deleted overlay_project_config / read_server_toml.
  • Docs: docs/configuration.md per-project section now states what a project file may not set (the old example set [server], which has been ignored since security: untrusted project config, CORS off by default, list limit caps #1321).

Why

The same uteke.toml was merged by two different hand-written implementations and the untrusted-project rule existed twice. That caused real bugs: whole sections silently ignored by the CLI (#1334), a project file wiping the global [server] auth in the server (#1321). Adding a key needed a struct field and a merge line and a trust entry. Now a key needs a struct field only.

Behaviour changes

  • Server: a project [recall] / [lifecycle] / [maintenance] / [dream] now merges per key instead of replacing the global section (the CLI already did). Project [extraction] model/mode now apply; only its api_key/base_url/endpoint_path are stripped (before, the whole section was ignored). Config parse errors are logged instead of silently dropped. UTEKE_TRUST_PROJECT_CONFIG=1 is honoured by the server too.
  • CLI: none intended — all 87 pre-existing tests (merge precedence, trust, lifecycle/aging/top-level keys, invalid TOML) pass unchanged in count; the trust check is now "strip before merge" instead of "restore after merge" with the same key set.
  • New dependency: toml in uteke-core (already used by CLI and server).

Testing

  • 8 new tests on the pure resolver (deep merge, per-key precedence, untrusted stripping, global may set sensitive keys, explicit trust, project without [server] keeps global, invalid TOML / wrong-type layers skipped without leaking, missing files).
  • Server: 3 tests through load-style resolution incl. the new per-key [recall] merge (fixed a flaky temp-file name along the way).
  • cargo fmt --check, cargo clippy --workspace --all-targets clean; cargo test --workspace green (core 615, cli 87, server 52); vecq-only core build green (613).
  • Not covered: the unified-schema step (CLI Config vs server ServerFileConfig still mirror each other) — optional step 2 in refactor: one Config module in core; CLI and server as adapters #1342; env override tests unchanged.

Refs #1342

🤖 Generated with Claude Code

Add uteke_core::config_layers: per-key deep merge of the global and project
uteke.toml, one untrusted-project-key policy (stripped before merging) and
per-layer validation, generic over the schema type. The CLI (Config::load) and
the server (load_uteke_toml) both use it, replacing ~290 lines of hand-listed
merge_from_file, restore_sensitive_from and the server's overlay_project_config.
A new config key now needs only a struct field.

Server behaviour: project [recall]/[lifecycle]/... now merge per key instead of
replacing the whole section; parse errors are logged instead of silent;
UTEKE_TRUST_PROJECT_CONFIG=1 works for the server too.

Refs #1342

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@ajianaz ajianaz added enhancement New feature or request scope:core Core engine work scope:cli CLI and UX labels Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 9af3f07 into develop Oct 7, 2026
15 checks passed
@ajianaz
ajianaz deleted the refactor/config-layer-resolution branch October 13, 2026 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request scope:cli CLI and UX scope:core Core engine work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant