Skip to content

feat(cli): gate and apply low-risk project config keys at startup (#208, part 3a) - #345

Merged
ajianaz merged 1 commit into
developfrom
feat/config-apply-gate
Oct 9, 2026
Merged

ajianaz merged 1 commit into
developfrom
feat/config-apply-gate

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

What

Part 3a of 4 of #208: wire the project-config trust gate into startup, add --config / --no-config as global flags, add a pure flag > env > config > default precedence framework, and apply ONLY the low-risk keys: model, base_url, system_prompt, memory, sessions_dir, workspace, [mission] max_steps/max_minutes/max_tokens. Security-sensitive keys (trust, allow, mcp_server, hooks, skill, plan_mode, no_auto_mcp, no_skills, mission.verify, mission.verify_timeout) are still only parsed/validated (3b).

Why

Parts 1-2 built the loader and the trust store but nothing ran at startup. This makes a trusted .tole/config.toml take effect safely, with unchanged behavior for projects that have no config.

Changes

Size: 14 files, +1895/-98. Tests ~1000 lines (tests/config_apply.rs 477, config_apply_tests.rs ~430, main_gate_tests.rs ~80); new code config_apply.rs ~430; docs ~60. Kept as one PR because a framework with nothing wired would be dead code.

  • Gate / interactivity per command: config, upgrade, approvals skip the gate. run/chat/resume/mission may prompt only when stdin AND stderr are terminals and not --prompt-file -. sessions, status, serve, acp, mcp never prompt and fail closed with the exact tole config trust instruction; the command does not run. --no-config skips discovery/gate/output; --config p is trusted without the store (store path is not even resolved). The gate runs before the update banner. One stderr line tole: using config <path> on success. The gate's vetted bytes are parsed; the file is never re-read.
  • Precedence API (tole_cli::config_apply): Source {Flag, Env, Config, Default} (+Display), resolve, resolve_or, resolve_string, resolve_string_or (blank env/config = unset), Eff<T>, Flags, Settings::resolve(&Flags, &Config, env) shared by startup and config check. 3b adds resolve_list and the boolean rule alongside.
  • model/base_url to tole-core: no tole-core change. A set-once OnceLock<ProviderFill> in tole-cli is installed only after a config passed the gate and parsed (empty otherwise, so every reader behaves as today). provider_config() replaces every OpenAiConfig::from_env() call: pass 1 is exactly from_env (complete env triple wins), and only if none is complete may the config fill base_url/model for a prefix that already has an env API key. API keys are never read from config. Acceptable because the cell is write-once, read-only afterwards and a no-op without a loaded config; it avoids threading a parameter through serve/acp/mcp.
  • Sites: sessions_dir/workspace/memory/system_prompt/mission budgets in main.rs dispatch; provider config in run/resume/chat, mission.rs, session_host.rs, ACP probe and advertised model.
  • config check prints key = v [config] effective: ... (source) for applied keys and (parsed, not applied yet — 3b) for the rest, using the same resolution as startup.
  • --help differences: per-action --config on config check|trust|untrust replaced by the global one (both config check --config p and --config p config check work); two new global flags on every command; updated config subcommand text. No clap-default flags needed changes. Existing option order unchanged.
  • Docs: README Configuration section, threat-model subsection (startup gating, fail closed, vetted bytes, residual unlocked read-modify-write on the trust store), CHANGELOG bullet. Status/epics do not claim completion.

Testing

  • No config => identical: e2e runs sessions with HOME/CODECORA_HOME removed, asserts empty stderr and stdout byte-identical to --no-config; status error unchanged; unit test panics if the store is resolved with no config.
  • 25 unit tests (precedence matrix per key, provider resolution, startup with fake IO, 3b keys leave settings unchanged), 5 gate-policy tests, 17 e2e tests with the real binary (untrusted/non-TTY, trust then apply, --no-config, explicit --config, modified file, serve/acp/mcp fail fast, flag/env beat config, mock provider sees config model and env override).
  • Mutation proofs (restored by copy-back): bypassing the gate fails 3 tests; inverting precedence fails 7 unit + 5 e2e; applying plan_mode fails the e2e 3b test.
  • fmt, clippy --workspace --all-targets -D warnings, cargo test --workspace, bare-profile and shell-tools checks, tole-core --no-default-features --tests all pass.

Part of #208

🤖 Generated with Claude Code

…, part 3a)

Wire the config trust gate into startup (every command except config,
upgrade, approvals), add --config/--no-config as global flags, a pure
flag > env > config > default precedence framework, and apply only the
low-risk keys (model, base_url, system_prompt, memory, sessions_dir,
workspace, [mission] budgets). Security-sensitive keys stay parsed but
unapplied. tole config check shows effective values and sources.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@github-actions

github-actions Bot commented Oct 9, 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 d6cd8cd into develop Oct 9, 2026
17 checks passed
@ajianaz
ajianaz deleted the feat/config-apply-gate branch October 9, 2026 06:42
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