feat(maestro): durable per-host spawn history + recent-dirs query (#24)

Add a `spawn_history` daemon module backing the spawn form's "recent dirs"
picker. Sidecars are deleted on kill, so they can't be the source — use an
append-only JSONL log at `<state_dir>/spawn-history.jsonl`, one record per
successful spawn (cwd, command, name, worktree_branch, at).

- Write: `SessionManager::create` appends after a successful spawn,
  best-effort — a log-write failure only warns, never fails the spawn.
- Read: `recent_dirs()` folds newest-first, dedups by cwd, drops entries past
  the recency cap, caps the result count.
- Prune: opportunistic `compact()` from `append` once the file passes a size
  threshold; atomic tmp+rename rewrite.
- Config: `[daemon].spawn_history_days` (default 30, `0` disables). History is
  wired into the manager at daemon startup.

Time-dependent logic is factored into `*_as_of(now)` helpers for
deterministic unit tests. Adds module unit tests (append/dedup/recency
prune/compaction/disabled/malformed/cap), a config resolution test, and
real-tmux integration tests proving create→append→read end to end.

Closes #24

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-20 20:54:21 +00:00
co-authored by Claude Opus 4.8
parent 7f3ac21402
commit b5fabff8e4
9 changed files with 544 additions and 2 deletions
+5 -1
View File
@@ -106,7 +106,11 @@ async fn run(config_override: Option<PathBuf>) -> Result<(), Box<dyn Error>> {
worktree_mgr,
config.fifo_dir(),
config.pty_replay_bytes,
);
)
.with_spawn_history(crate::spawn_history::SpawnHistory::new(
config.spawn_history_path(),
config.spawn_history_days,
));
let recovered = manager.recover().await?;
tracing::info!(recovered, "adopted existing tmux sessions");