From 6cab10baddabca2466fbd1a947c7fa23cf4a8ed1 Mon Sep 17 00:00:00 2001 From: Smokey <150986568+jacisjake@users.noreply.github.com> Date: Wed, 28 Oct 2026 08:46:02 -0600 Subject: [PATCH] =?UTF-8?q?feat(quill):=20status=20answers=20read=20the=20?= =?UTF-8?q?nest=20=E2=80=94=20capped=20recent-message=20block=20(#39)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- quill.go | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/quill.go b/quill.go index eb2c403..8292c9e 100644 --- a/quill.go +++ b/quill.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "strings" "time" ) @@ -8,13 +9,43 @@ import ( const quillSystem = `You are Quill crow, the owner's assistant and point of contact in a nest of AI crows. Answer the owner in one or two plain sentences. You are text-only: no web, no files, no tools.` +const quillHistoryCap = 20 + +// quillHistory builds a block of the most recent nest messages (excluding the +// requesting message), formatted as "[author|kind] text" with text truncated +// to 200 runes. Returns a single line when no earlier messages exist. +func quillHistory(all []Message, excludeID int) string { + var filtered []Message + for _, m := range all { + if m.ID != excludeID { + filtered = append(filtered, m) + } + } + if len(filtered) == 0 { + return "The nest has no earlier messages." + } + if len(filtered) > quillHistoryCap { + filtered = filtered[len(filtered)-quillHistoryCap:] + } + var sb strings.Builder + for _, m := range filtered { + text := []rune(m.Text) + if len(text) > 200 { + text = text[:200] + } + sb.WriteString(fmt.Sprintf("[%s|%s] %s\n", m.Author, m.Kind, string(text))) + } + return strings.TrimRight(sb.String(), "\n") +} + // respondQuill answers a message addressed to Quill, the assistant service -// role (CHATROOM_SPEC section 6). D1: one in-character reply through the -// flock. Reading the nest for status (D2) and relaying (D3) extend this file. +// role (CHATROOM_SPEC section 6). D2: reads the nest for status before +// composing its reply. func (s *Server) respondQuill(nest Nest, req Message) { budget := &Budget{name: "quill-reply", limit: s.p.G.TokenBudgetPerItem} system := systemFor("Quill", quillSystem, false) - prompt := "FROM: " + req.Author + "\nMESSAGE: " + req.Text + history := quillHistory(s.msgs.All(nest.ID), req.ID) + prompt := history + "\n---\nFROM: " + req.Author + "\nMESSAGE: " + req.Text answer, err := s.p.Flock.ask(s.ctx, nil, "Quill", system, prompt, budget) if err != nil { return