Overview
Runs a continuous loop: sync (index + extract) then maintain (refine), repeating at configurable intervals. Use--once for a single cycle.
Sessions are processed sequentially in chronological order (oldest first) so that later sessions can update memories from earlier ones.
Syntax
Parameters
Run exactly one sync+maintain cycle and exit (instead of looping forever).
Max sessions to extract per cycle. Defaults to
sync_max_sessions from config (currently 50).Override both sync and maintain intervals uniformly (seconds). Minimum 30s.Note: This replaces the separate
sync_interval_minutes and maintain_interval_minutes config values.Examples
Run forever with default intervals
Start the daemon with config defaults (sync every 10 min, maintain every 60 min):Ctrl+C to stop gracefully.
One-shot execution
Run a single sync+maintain cycle and exit:- CI/CD pipelines
- Scheduled cron jobs
- Testing daemon behavior
Custom poll interval
Run sync and maintain every 2 minutes:Limit sessions per cycle
Process at most 10 sessions per sync:- Controlling API costs
- Limiting extraction latency
- Testing with small batches
How it works
Continuous mode (default)
- Start sync and maintain loops with independent intervals
- Sync loop:
- Wait for
sync_interval_minutes(orpoll_seconds) - Discover new sessions within
sync_window_days - Enqueue up to
max_sessionsfor extraction - Extract memories using DSPy
- Write to
.lerim/memory/
- Wait for
- Maintain loop:
- Wait for
maintain_interval_minutes(orpoll_seconds) - Scan existing memories
- Merge duplicates, archive low-value items, consolidate related memories
- Wait for
- Repeat until interrupted
One-shot mode (--once)
- Run one sync cycle
- Run one maintain cycle
- Print summary JSON
- Exit
Configuration
Default intervals from~/.lerim/config.toml:
<repo>/.lerim/config.toml) or via CLI flags.
Daemon vs. serve
| Command | HTTP API | Dashboard | Daemon loop |
|---|---|---|---|
lerim daemon | No | No | Yes |
lerim serve | Yes | Yes | Yes |
lerim daemon:
- You only need background sync/maintain (no web UI or API)
- You’re running a separate HTTP server
- You want minimal resource usage
lerim serve:
- You want the full stack (API + dashboard + daemon)
- You’re running in Docker
- You need to query status or run one-shot commands
Use cases
Background service
Run the daemon as a systemd service:Scheduled job
Run once per hour via cron:Development testing
Quick test with high frequency and limited sessions:Monitoring
The daemon logs to stderr (or stdout in--once mode). You can redirect output to a log file:
supervisor, pm2, or systemd for automatic restarts and log rotation.
Exit codes
- 0: Success (one-shot mode only)
- 1: Error - startup failure or unrecoverable error
Related commands
lerim serve
Run full server (API + dashboard + daemon)
lerim sync
One-shot sync (no daemon loop)
Notes
- The daemon uses monotonic time to avoid clock drift
- Errors in sync or maintain are logged but don’t crash the daemon
- In continuous mode, the daemon sleeps until the next scheduled run (no busy polling)
- Sessions are always processed in chronological order (oldest first)