Files
agent-dashboard/internal/hook/debounce.go
laily 021fc3a828 feat: fix Cursor hook delivery and improve notify workflow
Route hook notifications through /dev/tty and client_tty so OSC reaches
Ghostty when Cursor captures stdout. Add afterAgentResponse hook, hook
logging, debounce, split test modes, and use directory name for titles.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-26 12:46:50 +08:00

41 lines
815 B
Go

package hook
import (
"os"
"path/filepath"
"strconv"
"time"
)
func debouncePath() string {
return filepath.Join(os.Getenv("HOME"), ".local", "state", "agent-notify", "debounce")
}
func shouldDebounce(title string) bool {
path := debouncePath()
data, err := os.ReadFile(path)
now := time.Now().UnixNano()
window := int64(2 * time.Second)
var lastTitle string
var lastAt int64
if err == nil {
// format: timestamp\ttitle
for i := 0; i < len(data); i++ {
if data[i] == '\t' {
lastAt, _ = strconv.ParseInt(string(data[:i]), 10, 64)
lastTitle = string(data[i+1:])
break
}
}
}
if lastTitle == title && now-lastAt < window {
return true
}
_ = os.MkdirAll(filepath.Dir(path), 0755)
_ = os.WriteFile(path, []byte(strconv.FormatInt(now, 10)+"\t"+title), 0644)
return false
}