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:
Pierre Martin
2026-03-23 18:29:32 +01:00
parent 170790fcda
commit 8594c48f84
5 changed files with 162 additions and 5 deletions

View File

@@ -45,9 +45,10 @@ func TestDetectState_ToolUseAskUser(t *testing.T) {
}
func TestDetectState_ToolUseOther(t *testing.T) {
// Recent tool_use (< PermissionStallThreshold) → Working
msgs := []JSONLMessage{{
Type: "assistant",
Timestamp: "2026-03-23T12:00:00Z",
Timestamp: "2026-03-23T12:00:25Z", // 5s before testNow
Message: &MessagePayload{
Role: "assistant",
Content: []ContentBlock{
@@ -63,6 +64,26 @@ func TestDetectState_ToolUseOther(t *testing.T) {
}
}
func TestDetectState_ToolUseStale(t *testing.T) {
// tool_use older than PermissionStallThreshold → permission prompt
msgs := []JSONLMessage{{
Type: "assistant",
Timestamp: "2026-03-23T12:00:10Z", // 20s before testNow
Message: &MessagePayload{
Role: "assistant",
Content: []ContentBlock{
{Type: "tool_use", Name: "Bash"},
},
StopReason: "tool_use",
},
}}
state := DetectState(msgs, testNow)
if state != NeedsInput {
t.Errorf("expected NeedsInput for stale tool_use, got %v", state)
}
}
func TestDetectState_Progress(t *testing.T) {
msgs := []JSONLMessage{{
Type: "progress",