- HookEvent struct parses Claude Code hook JSON payload - processHookEvent maps Notification/Stop/PostToolUse/PreToolUse to State+WaitType - UpdateFromHook creates new entries and manages WaitingSince transitions - SessionInfo.WaitType serialized in JSON with omitempty - 12 tests cover all event mappings, edge cases, and JSON serialization Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
// Request is the JSON message sent by a client to the daemon over the Unix socket.
|
|
type Request struct {
|
|
Action string `json:"action"` // "list", "switch", "label", "stop"
|
|
Args json.RawMessage `json:"args,omitempty"`
|
|
}
|
|
|
|
// Response is the JSON message sent back by the daemon.
|
|
type Response struct {
|
|
OK bool `json:"ok"`
|
|
Error string `json:"error,omitempty"`
|
|
Sessions []SessionInfo `json:"sessions,omitempty"`
|
|
}
|
|
|
|
// SessionInfo is the wire format for a session in IPC responses.
|
|
type SessionInfo struct {
|
|
PID int `json:"pid"`
|
|
SessionID string `json:"session_id"`
|
|
Cwd string `json:"cwd"`
|
|
GitBranch string `json:"git_branch"`
|
|
State string `json:"state"`
|
|
Preview string `json:"preview"`
|
|
Workspace string `json:"workspace"`
|
|
Label string `json:"label,omitempty"`
|
|
WaitType string `json:"wait_type,omitempty"`
|
|
WaitingSince *time.Time `json:"waiting_since,omitempty"`
|
|
}
|
|
|
|
// SwitchArgs carries the query for workspace switching.
|
|
type SwitchArgs struct {
|
|
Query string `json:"query"`
|
|
}
|
|
|
|
// LabelArgs carries the session ID and label for the label action.
|
|
type LabelArgs struct {
|
|
SessionID string `json:"session_id"`
|
|
Label string `json:"label"`
|
|
}
|