oficina / equipo Public

Coordinator: stable first frame, the notebook before the conversation

A fresh coordinator session's first frame was the house rule, the
catalog, the conversation so far, then the notebook and the newest
message, so the conversation (different in every session) sat in front
of the notebook and a provider's prompt cache could hold only the rule
and catalog. Now the rule, the catalog and the notebook come first and
the conversation so far, an earlier attempt's effects, the newest
message and attachment notes after them. The rule's text is unchanged
(houseRule stays), and a resumed session's frames are as before: the
notebook only when it changed, then the newest message.

TestCoordinatorPromptStablePrefix builds two fresh frames that differ
only in volatile values (tail, times, counts, ids, done effects) and
checks the stable part is byte-identical and holds rule, catalog and
notebook; it failed on the old order.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 89ebd06bb3d43db0b93eb5530c61f40315c6b4f9 parent 48c3015
3 files changed, +89 −16
  • internal/runner/thin/claude.go +27 −13
  • internal/runner/thin/prefix_test.go +59 −0
  • internal/runner/thin/voice_test.go +3 −3
diff --git a/internal/runner/thin/claude.go b/internal/runner/thin/claude.go
index cea873b8..278c6cc1 100644
--- a/internal/runner/thin/claude.go
+++ b/internal/runner/thin/claude.go
@@ -607,8 +607,11 @@ func claudeImages(files []heldFile) ([]claude.Image, map[string]bool) {
}
// opening is the start of a fresh session's first user frame: the house
-// rule, the catalog and the conversation so far.
-func opening(person string, catalog []wire.RepoInfo, tail []wire.TailMessage) string {
+// rule and the catalog, which change only when the rule or the reachable
+// repositories do. Volatile parts (the conversation so far, the newest
+// message) come after it and the notebook, so the provider's prompt
+// cache can hold this prefix across sessions.
+func opening(person string, catalog []wire.RepoInfo) string {
var b strings.Builder
b.WriteString("You are the Equipo coordinator for " + person + ". You talk with them about their software work. Answer briefly in plain words. Do not use em dashes.\n")
b.WriteString("Decide where work goes yourself and say so in one line; the person can undo it. Never ask them to choose a repository, never list repositories for them to pick, and never mention a Set up step. Call status first when you need to know what exists.\n")
@@ -624,33 +627,44 @@ func opening(person string, catalog []wire.RepoInfo, tail []wire.TailMessage) st
if len(catalog) > 0 {
b.WriteString("\nRepositories you can reach (name: what it is):\n" + catalogLines(catalog, 40))
}
- if len(tail) > 0 {
- b.WriteString("\nConversation so far, oldest first:\n")
- for _, m := range tail {
- who := "Person"
- if m.Role == wire.RoleCoordinator {
- who = "You"
- }
- b.WriteString(who + ": " + m.Text + "\n")
+ return b.String()
+}
+
+// conversation is a fresh session's conversation so far, oldest first.
+func conversation(tail []wire.TailMessage) string {
+ if len(tail) == 0 {
+ return ""
+ }
+ var b strings.Builder
+ b.WriteString("\nConversation so far, oldest first:\n")
+ for _, m := range tail {
+ who := "Person"
+ if m.Role == wire.RoleCoordinator {
+ who = "You"
}
+ b.WriteString(who + ": " + m.Text + "\n")
}
return b.String()
}
// prompt is one turn's user frame: the opening in a fresh session, the
-// notebook when the session has not seen it as it is now, then the
-// person's newest message or the move-in or explore instructions. It
+// notebook when the session has not seen it as it is now, a fresh
+// session's conversation so far, then the person's newest message or
+// the move-in or explore instructions: the stable parts first. It
// returns the namespaces a move-in or explore turn looks at.
func (c *coordBase) prompt(fresh bool, in TurnInput, catalog []wire.RepoInfo) (string, []string) {
var b strings.Builder
if fresh {
- b.WriteString(opening(c.person, catalog, in.Tail))
+ b.WriteString(opening(c.person, catalog))
}
notebook := c.desk.Notebook(notebookContext)
if notebook != "" && (fresh || noteHash(notebook) != c.noteHash) {
b.WriteString("\n" + notebook)
}
c.noteHash = noteHash(notebook)
+ if fresh {
+ b.WriteString(conversation(in.Tail))
+ }
ns := namespacesOf(catalog)
switch in.Kind {
case wire.TurnMoveIn:
diff --git a/internal/runner/thin/prefix_test.go b/internal/runner/thin/prefix_test.go
new file mode 100644
index 00000000..3d543616
--- /dev/null
+++ b/internal/runner/thin/prefix_test.go
@@ -0,0 +1,59 @@
+package thin
+
+import (
+ "strings"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/wire"
+)
+
+// The coordinator's first frame keeps what does not change between
+// sessions first (the house rule, the catalog, the notebook) and what
+// does (the conversation so far, what an earlier attempt did, the
+// newest message, attachment ids) after it, so a provider's prompt
+// cache can hold the stable prefix: two fresh sessions that differ only
+// in volatile values share it byte for byte.
+func TestCoordinatorPromptStablePrefix(t *testing.T) {
+ desk, err := OpenDesk(t.TempDir(), "p@example.com")
+ if err != nil {
+ t.Fatal(err)
+ }
+ at := time.Date(2026, 11, 7, 9, 0, 0, 0, time.UTC)
+ if err := desk.SaveEntries([]wire.NotebookEntry{{ID: "n1", Source: wire.NotePerson, Text: "Short replies, please.", At: at}, {ID: "n2", Source: wire.NoteRepo, Repo: "oficina/sample", Path: "README.md", Text: "Sample is the demo app.", At: at}}); err != nil {
+ t.Fatal(err)
+ }
+ catalog := []wire.RepoInfo{{Repo: "amadan.net/oficina/sample", Names: []string{"sample", "Woodstar"}, Summary: "The demo app."}}
+ frame := func(n int, text string, tail []wire.TailMessage, done []string) string {
+ c := &coordBase{person: "p@example.com", desk: desk}
+ p, _ := c.prompt(true, TurnInput{Person: "p@example.com", TurnID: "t" + strings.Repeat("x", n), Kind: wire.TurnPerson, Text: text, Tail: tail, Done: done}, catalog)
+ return p
+ }
+ a := frame(1, "Fix the typo at 09:14.", []wire.TailMessage{{Role: wire.RolePerson, Text: "Hello at 09:00"}}, nil)
+ b := frame(2, "What changed since 2026-11-10, 3 tasks?", []wire.TailMessage{{Role: wire.RolePerson, Text: "Morning"}, {Role: wire.RoleCoordinator, Text: "Hi, 4 open tasks."}}, []string{"record_task: tk123"})
+ // The stable part runs up to the conversation so far; the other
+ // session's frame starts with the same bytes.
+ cut := strings.Index(a, "\nConversation so far")
+ if cut < 0 {
+ t.Fatalf("no conversation in the frame:\n%s", a)
+ }
+ prefix := a[:cut]
+ if !strings.HasPrefix(b, prefix) {
+ t.Fatalf("the stable part differs between sessions:\n%s\n---\n%s", a, b)
+ }
+ for _, stable := range []string{"You are the Equipo coordinator for p@example.com.", "Repositories you can reach", "oficina/sample [Woodstar]: The demo app.", "=== Your notebook", `"Short replies, please."`, "=== End of notebook ==="} {
+ if !strings.Contains(prefix, stable) {
+ t.Fatalf("the shared prefix lacks %q:\n%s", stable, prefix)
+ }
+ }
+ for _, volatile := range []string{"Newest message", "Already done", "09:14", "Hello at 09:00", "Morning", "tk123"} {
+ if strings.Contains(prefix, volatile) {
+ t.Fatalf("the shared prefix holds %q:\n%s", volatile, prefix)
+ }
+ }
+ // The tail still comes before the newest message, and the rule's
+ // "the conversation below" still points at it.
+ if i, j := strings.Index(a, "Conversation so far"), strings.Index(a, "Newest message:\nFix the typo"); i < 0 || j < i || !strings.Contains(prefix, "Treat the conversation below as context") {
+ t.Fatalf("frame order:\n%s", a)
+ }
+}
diff --git a/internal/runner/thin/voice_test.go b/internal/runner/thin/voice_test.go
index 9ad6815d..5a587e2d 100644
--- a/internal/runner/thin/voice_test.go
+++ b/internal/runner/thin/voice_test.go
@@ -8,7 +8,7 @@ import (
// The coordinator's standing prompt keeps chat at the outcome level and
// names tasks as links (Paul, 2026-11-07): details live on the task.
func TestOpeningOutcomeLevelVoice(t *testing.T) {
- o := opening("p@example.com", nil, nil)
+ o := opening("p@example.com", nil)
for _, want := range []string{
"Speak at the outcome level",
"No file paths, line numbers or code mechanics in your replies",
@@ -31,7 +31,7 @@ func TestOpeningOutcomeLevelVoice(t *testing.T) {
// specifics it points the person at the task, where they ask the
// specialist who did the work.
func TestOpeningPointsToAskTheImplementer(t *testing.T) {
- o := opening("p@example.com", nil, nil)
+ o := opening("p@example.com", nil)
for _, want := range []string{
"do not explain them yourself",
"You can ask Engineering on [",
@@ -53,7 +53,7 @@ func TestOpeningPointsToAskTheImplementer(t *testing.T) {
// sends a repeat report to the open task, never a duplicate; and Equipo
// merges, so the person is never asked to.
func TestOpeningReusesOpenTasks(t *testing.T) {
- o := opening("p@example.com", nil, nil)
+ o := opening("p@example.com", nil)
for _, want := range []string{
"Never file the same problem twice",
"If record_task returns similar open tasks",