Skip to main content

Module config

Module config 

Source
Expand description

Config & persistence — user preferences plus durable storage for preferences, lifetime stats and the diagnostic cache.

Everything lives under <home>/.limitless/:

FileContents
config.jsonLimitlessConfig user preferences (auto-created)
stats.jsonArcadeStats lifetime usage counters
cache.jsonLast 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§

CacheEntry
A cached EnvironmentState with the Unix timestamp when it was saved.
LimitlessConfig
User preferences, persisted as config.json.
PersistenceManager
Owns the ~/.limitless/ data directory and its three JSON files.

Constants§

CACHE_TTL
How long a cached EnvironmentState snapshot is considered fresh.
CACHE_TTL_SECS
CACHE_TTL expressed 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.