Principle:ARCANGEL0 EVA Configuration Persistence
| Knowledge Sources | |
|---|---|
| Domains | Configuration, Security, Onboarding |
| Last Updated | 2026-10-29 14:00 GMT |
Overview
Pattern for securely persisting application configuration — credentials, provider profiles, search engine settings, and user preferences — using XDG-compliant paths, atomic file writes, and restrictive permissions.
Description
An agentic security tool stores sensitive configuration: API keys, provider base URLs, model selections, search engine API keys, and user preferences (theme, companion). Configuration persistence ensures:
- XDG compliance: Credentials go in `~/.config/mitsu/credentials.json`; preferences in `~/.config/mitsu/settings.json`; sessions in `~/.local/share/mitsu/sessions/`.
- Atomic writes: Configuration is written to a temp file, fsync'd, then atomically renamed over the target — preventing corruption from crashes mid-write.
- Restrictive permissions: Credential files use 0o600; directories use 0o700 — no other user can read them.
- Secret preservation: When updating a profile without an API key, the previous key is retained rather than cleared.
- Default bootstrapping: Preferences load with sensible defaults (theme="ember", companion="mitsu", onboarding_complete=False).
The first-run onboarding wizard uses these stores to guide the operator through provider selection, API key entry, model loading, search engine configuration, and companion/theme selection.
Usage
Apply this principle when:
- Storing API keys or other secrets on disk.
- Implementing a first-run setup wizard with multi-step configuration.
- Needing crash-safe configuration writes.
- Managing multiple provider profiles with credential isolation.
Theoretical Basis
Atomic write uses temp file + rename for crash safety:
# Abstract algorithm (NOT real implementation)
def atomic_json(path, data, private=True):
temp = NamedTemporaryFile(dir=path.parent, delete=False)
json.dump(data, temp, indent=2)
temp.flush()
os.fsync(temp.fileno())
os.replace(temp.name, path)
if private:
path.chmod(0o600)
Credential retention on profile update:
# Abstract algorithm (NOT real implementation)
def save_profile(profile):
previous = load().get(profile["provider_id"])
if not profile.get("api_key") and previous:
profile["api_key"] = previous["api_key"] # retain existing key
Practical Guide
- Never write directly to the target file — always use temp + rename for atomicity.
- Set 0o600 on credential files and 0o700 on config directories.
- Retain API keys when updating other profile fields — the operator may not re-enter the key when changing the model.
- Follow XDG spec for file locations so backups and cleanup are predictable.
- Provide sensible defaults so the app boots even before onboarding is complete.
- Validate provider configuration before marking it as ready (requires base_url, model, and api_key if the provider requires one).