fix: detect permission prompts as NeedsInput when tool_use is stale (>10s)
When Claude requests a tool permission approval, the last JSONL entry is type=assistant with stop_reason=tool_use. Previously this was always classified as Working. Now, if the tool_use entry is older than 10s with no new activity, it's classified as NeedsInput. Also fix vmux label to accept fuzzy match queries (not just session UUIDs).
This commit is contained in:
11
state.go
11
state.go
@@ -7,6 +7,10 @@ import (
|
||||
|
||||
const IdleThreshold = 60 * time.Second
|
||||
|
||||
// PermissionStallThreshold: if a tool_use has been pending this long
|
||||
// without any new JSONL entry, Claude is likely waiting for user approval.
|
||||
const PermissionStallThreshold = 10 * time.Second
|
||||
|
||||
// DetectState determines the session state from the last JSONL messages.
|
||||
// The now parameter enables deterministic testing of the idle threshold.
|
||||
func DetectState(messages []JSONLMessage, now time.Time) SessionState {
|
||||
@@ -33,6 +37,13 @@ func DetectState(messages []JSONLMessage, now time.Time) SessionState {
|
||||
return NeedsInput
|
||||
}
|
||||
}
|
||||
// If tool_use is stale (no new JSONL activity), Claude is likely
|
||||
// waiting for a permission prompt approval.
|
||||
if ts, err := time.Parse(time.RFC3339, last.Timestamp); err == nil {
|
||||
if now.Sub(ts) > PermissionStallThreshold {
|
||||
return NeedsInput
|
||||
}
|
||||
}
|
||||
return Working
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user