From 12d29e42da9b2fd2095a8074fb6ca02060b48369 Mon Sep 17 00:00:00 2001 From: Franco Conturso Date: Fri, 13 Nov 2026 17:01:25 -0300 Subject: [PATCH] Prompt hook: print nothing for a prompt with only task notifications or hc notes (#759) --- cmd/contr/hooksession.go | 12 +++++++++++- cmd/contr/hooksession_test.go | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cmd/contr/hooksession.go b/cmd/contr/hooksession.go index 67e6df9c..55ecfc82 100644 --- a/cmd/contr/hooksession.go +++ b/cmd/contr/hooksession.go @@ -10,6 +10,7 @@ import ( "fmt" "io" "os" + "regexp" "runtime" "strings" "time" @@ -95,7 +96,7 @@ func promptHook(stdin io.Reader, stdout, stderr io.Writer, stateDir, id string, return nil } text := youContext - if strings.HasPrefix(strings.TrimSpace(in.Prompt), ".*?||.*?`) + +// ownerWords reports whether the prompt holds text other than notes. +func ownerWords(prompt string) bool { + return strings.TrimSpace(notePattern.ReplaceAllString(prompt, "")) != "" +} + func postToolHook(stdin io.Reader, stateDir, id string, now uint64) error { var in toolInput if err := json.NewDecoder(stdin).Decode(&in); err != nil { diff --git a/cmd/contr/hooksession_test.go b/cmd/contr/hooksession_test.go index f5ff3215..30bc6956 100644 --- a/cmd/contr/hooksession_test.go +++ b/cmd/contr/hooksession_test.go @@ -124,6 +124,24 @@ func TestPromptHook(t *testing.T) { if out, _ := runSession(t, dir, "prompt", `{"prompt":"done"}`); out != "" { t.Fatalf("hc report got %q", out) } + for _, p := range []string{ + `\nb1\n`, + `\ndone\n`, + `a\nb`, + ` `, + } { + if out, _ := runSession(t, dir, "prompt", `{"prompt":"`+p+`"}`); out != "" { + t.Fatalf("note %q got %q", p, out) + } + } + for _, p := range []string{ + `done\nnow fix the bug`, + `done merge it`, + } { + if out, _ := runSession(t, dir, "prompt", `{"prompt":"`+p+`"}`); !strings.Contains(out, `[you]`) { + t.Fatalf("owner words %q got %q", p, out) + } + } if _, e := runSession(t, dir, "prompt", `nope`); !strings.Contains(e, "bad hook input") { t.Fatalf("stderr %q", e) }