From 81d3ce93fe05d70070db0fbda37c5bafe94f4082 Mon Sep 17 00:00:00 2001 From: ProofOfConcept Date: Thu, 5 Mar 2026 21:43:04 -0500 Subject: [PATCH] fix idle timer restart and hook event detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two fixes: 1. Reset activity timestamps to now() on daemon restart instead of loading stale values and suppressing with fired=true. Timers count cleanly from restart. 2. Fix poc-hook to read hook_event_name (not type) from Claude Code's JSON input. The hook was being called but never matched any event. Also switch daemon_cmd from spawn() to status() since the command takes 2ms — no reason to fire-and-forget. Co-Authored-By: ProofOfConcept --- src/bin/poc-daemon/idle.rs | 10 +++++----- src/bin/poc-hook.rs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bin/poc-daemon/idle.rs b/src/bin/poc-daemon/idle.rs index 4960cdd..166c558 100644 --- a/src/bin/poc-daemon/idle.rs +++ b/src/bin/poc-daemon/idle.rs @@ -110,8 +110,6 @@ impl State { pub fn load(&mut self) { if let Ok(data) = fs::read_to_string(state_path()) { if let Ok(p) = serde_json::from_str::(&data) { - self.last_user_msg = p.last_user_msg; - self.last_response = p.last_response; self.sleep_until = p.sleep_until; self.claude_pane = p.claude_pane; if p.idle_timeout > 0.0 { @@ -120,9 +118,11 @@ impl State { if p.notify_timeout > 0.0 { self.notify_timeout = p.notify_timeout; } - // Suppress immediate fire after restart — wait for fresh - // user/response signal before allowing the idle timer - self.fired = true; + // Reset activity timestamps to now — timers count from + // restart, not from stale pre-restart state + let t = now(); + self.last_user_msg = t; + self.last_response = t; } } diff --git a/src/bin/poc-hook.rs b/src/bin/poc-hook.rs index ae3c128..ef68bfd 100644 --- a/src/bin/poc-hook.rs +++ b/src/bin/poc-hook.rs @@ -35,7 +35,7 @@ fn daemon_cmd(args: &[&str]) { .args(args) .stdout(std::process::Stdio::null()) .stderr(std::process::Stdio::null()) - .spawn() + .status() .ok(); } @@ -134,7 +134,7 @@ fn main() { Err(_) => return, }; - let hook_type = hook["type"].as_str().unwrap_or("unknown"); + let hook_type = hook["hook_event_name"].as_str().unwrap_or("unknown"); let transcript = hook["transcript_path"] .as_str() .filter(|p| !p.is_empty())