Expand description
Config & persistence — user preferences plus durable storage for preferences, lifetime stats and the diagnostic cache.
Everything lives under <home>/.limitless/:
| File | Contents |
|---|---|
config.json | LimitlessConfig user preferences (auto-created) |
stats.json | ArcadeStats lifetime usage counters |
cache.json | Last EnvironmentState snapshot (5-minute TTL) |
The PersistenceManager owns those paths. Its default instance targets
the user’s home directory, but from_home / at_dir let callers (and
tests) point persistence at any directory. Writes go through a temp-file
then rename so a crash mid-write never corrupts the real file.
use limitless_cli::modules::config::{LimitlessConfig, PersistenceManager};
let dir = std::env::temp_dir().join(format!(
"limitless_config_doc_{}_{}",
std::process::id(),
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_nanos())
.unwrap_or(0)
));
let manager = PersistenceManager::from_home(&dir);
// First init creates ~/.limitless/config.json with defaults.
let config = manager.init_config().unwrap();
assert!(config.color_enabled);
assert!(config.animation_enabled);
// Stats default to an empty counter set when the file is absent.
let stats = manager.load_stats().unwrap();
assert_eq!(stats.diagnostics_run, 0);
let _ = std::fs::remove_dir_all(&dir);Structs§
- Cache
Entry - A cached
EnvironmentStatewith the Unix timestamp when it was saved. - Limitless
Config - User preferences, persisted as
config.json. - Persistence
Manager - Owns the
~/.limitless/data directory and its three JSON files.
Constants§
- CACHE_
TTL - How long a cached
EnvironmentStatesnapshot is considered fresh. - CACHE_
TTL_ SECS CACHE_TTLexpressed in seconds (handy for tests).
Functions§
- cache_
diagnostics - Snapshots the given state to the cache file.
- default_
config - Default colors/animations and empty preferred stack.
- get_
cached_ diagnostics - Returns the cached diagnostics snapshot when it is fresh.
- init_
config - Initializes the default config, creating
~/.limitless/on first run. - load_
stats - Loads lifetime stats from
~/.limitless/stats.json(empty when missing). - save_
config - Saves the configuration to
~/.limitless/config.json. - save_
stats - Saves lifetime stats to
~/.limitless/stats.json. - unix_
secs_ now - Current time as Unix seconds.