aboutsummaryrefslogtreecommitdiff
path: root/crates/dinggerd/src/watcher.rs
diff options
context:
space:
mode:
authorIgor Soarez <igor@soarez.org>2026-10-23 15:08:53 +0300
committerIgor Soarez <igor@soarez.org>2026-10-23 15:08:53 +0300
commit7520141a55e8876824dcb4e2cf5e8e3027efa59d (patch)
tree02022949d5b9bd41c5421ae7134ca8816f4b045b /crates/dinggerd/src/watcher.rs
parenta7d34521c7f874beb44e0314017ab28979550495 (diff)
restore Claude Code agents in their own sessions
`dingger install claude` adds a SessionStart hook to Claude's settings (every other key and hook kept, in order; the original backed up; written through a symlink; installing again changes nothing). The hook is `dingger hook claude`: it reports the session's transcript for its tmux pane, prints nothing (Claude adds SessionStart output to the conversation) and always exits 0. Claude's state still comes from its screen. restore types `claude --resume <id>` in the directory the session ran in (elsewhere, Claude moves the conversation there). it resumes an agent only when its session file exists: a Claude session that never got a message has no transcript, and `--resume` fails ("No conversation found"). the snapshot now keeps an agent's command line too, so such a pane gets it retyped instead of nothing. - the hook receiver takes a report without a state: only the session. - a report that arrives after the watcher listed the panes is not dropped as "agent gone": Claude reports once, as it starts. - serde_json preserve_order (indexmap is already a dependency, via toml). e2e step 18: install against a settings file like a real one, a fake claude running the exact installed hook command, resume by id, retype without a transcript, the resumed agent reporting again. a server that restore starts now gets the test's plain shells: it got the user's login shell, whose profile put the real claude first, which started (stuck at its trust dialog) during development. every test restore now checks that no real pi or claude runs in a test pane.
Diffstat (limited to 'crates/dinggerd/src/watcher.rs')
-rw-r--r--crates/dinggerd/src/watcher.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/crates/dinggerd/src/watcher.rs b/crates/dinggerd/src/watcher.rs
index 91fa332..346bfa8 100644
--- a/crates/dinggerd/src/watcher.rs
+++ b/crates/dinggerd/src/watcher.rs
@@ -235,6 +235,7 @@ impl Watcher {
}
fn tick(&mut self) -> Result<(), String> {
+ let listed = std::time::Instant::now();
let panes = tmux::list_panes()?;
let now = unix_now();
@@ -244,7 +245,7 @@ impl Watcher {
hooks::forget(&panes.iter().map(|pane| pane.pane_id.clone()).collect::<Vec<_>>());
for pane in &panes {
- let Some(observations) = observe(pane) else {
+ let Some(observations) = observe(pane, listed) else {
debug!(target = %pane.display_target, "observation skipped (viewer screen)");
continue;
};
@@ -393,13 +394,13 @@ impl Watcher {
/// The pane's raw agent states this tick, in order, or `None` when the
/// screen is a viewer (transcript, picker) that says nothing about state.
-fn observe(pane: &tmux::Pane) -> Option<Vec<AgentState>> {
+fn observe(pane: &tmux::Pane, listed: std::time::Instant) -> Option<Vec<AgentState>> {
if pane.dead {
return Some(vec![AgentState::Idle]);
}
let Some(agent) = pane.agent else {
// The agent is gone; its last hook report must not outlive it.
- hooks::drop_reports(&pane.pane_id);
+ hooks::drop_reports(&pane.pane_id, listed);
return Some(vec![AgentState::Unknown]);
};
// Agent-reported state is authoritative; it survives restarts through