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>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user