"Learn from conversations" (memdistill) reads a session only when the
Sessions list marks it Transcript, which is HasTranscript(agent). The
WorkBuddy family had a summary reader (workbuddyLine) for the Sessions
page and the usage ledger but no transcript reader, so its sessions were
listed and never learned from.
Add wbTranscript (transcript_workbuddy.go), over the same
projects/<cwd>/<id>.jsonl lines: a message's input_text/output_text
blocks (WorkBuddy's own <system-reminder> blocks stay context and its
@scene: blocks are dropped, so the typed words still count as said), a
function_call with its arguments, and its function_call_result by callId.
workbuddy, workbuddy-ai and codebuddy join HasTranscript.
Guard: TestEveryListedAgentHasATranscriptOrIsNamed reads the agent ids
Session.Agent lists and fails for any with no transcript that is not in
noTranscriptYet, and for any in that list that now has one. Siblings still
without a transcript, named there: zcode, dsh, cline, grok, droid, hermes,
alma (issues filed).
Run (mote): go vet ./internal/sessions ./internal/memdistill; go test
./internal/sessions ./internal/memdistill ./internal/memory ./internal/gui.
The new tests fail on the old transcript.go (workbuddy, workbuddy-ai and
codebuddy named, codebuddy not marked readable). internal/gui has one red
that is also red on origin/main 99cc8fa5d, TestSettingsSaveKeepsWhatItDoesNotSend
(RedactModelDir), filed. No GUI file changed. Fixtures are the existing
testdata/workbuddy and testdata/codebuddy session files. Not tried: a real
WorkBuddy account's session through the model.
107 lines
3.5 KiB
Go
107 lines
3.5 KiB
Go
package sessions
|
|
|
|
import (
|
|
"os"
|
|
"regexp"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// listedAgents are the agent ids a Session's Agent names, from its doc
|
|
// comment: the agents whose sessions the Sessions page can list.
|
|
func listedAgents(t *testing.T) []string {
|
|
t.Helper()
|
|
src, err := os.ReadFile("sessions.go")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
m := regexp.MustCompile("json:\"agent\"`[^\\n]*magpie agent id: ([^\\n]+)").FindSubmatch(src)
|
|
if m == nil {
|
|
t.Fatal("Session.Agent's list of agent ids is gone")
|
|
}
|
|
var out []string
|
|
for _, a := range strings.Split(string(m[1]), ",") {
|
|
out = append(out, strings.TrimSpace(a))
|
|
}
|
|
return out
|
|
}
|
|
|
|
// noTranscriptYet are agents the Sessions page lists whose conversations
|
|
// are not read as a transcript, so "Learn from conversations"
|
|
// (memdistill, which reads sessions.TranscriptOf) skips them. An agent
|
|
// leaves this list when its reader is written, and may not be added to it
|
|
// without one being filed.
|
|
var noTranscriptYet = map[string]string{
|
|
"zcode": "database rows",
|
|
"dsh": "session.v3.jsonl not read as a transcript",
|
|
"cline": "messages.json not read as a transcript",
|
|
"grok": "updates.jsonl not read as a transcript",
|
|
"droid": "not read as a transcript",
|
|
"hermes": "database rows",
|
|
"alma": "database rows",
|
|
}
|
|
|
|
// Every agent the Sessions page lists is read by memory learning, or is
|
|
// named in noTranscriptYet: a new session reader can't be left out of it
|
|
// unseen (WorkBuddy's sessions showed on Sessions for weeks and were
|
|
// never learned from, #feedback bxgz233).
|
|
func TestEveryListedAgentHasATranscriptOrIsNamed(t *testing.T) {
|
|
for _, a := range listedAgents(t) {
|
|
_, parked := noTranscriptYet[a]
|
|
switch {
|
|
case HasTranscript(a) && parked:
|
|
t.Errorf("%s reads as a transcript: take it off noTranscriptYet", a)
|
|
case !HasTranscript(a) && !parked:
|
|
t.Errorf("%s has a session reader and no transcript: memory learning never reads it", a)
|
|
}
|
|
}
|
|
for a := range noTranscriptYet {
|
|
found := false
|
|
for _, l := range listedAgents(t) {
|
|
found = found || l == a
|
|
}
|
|
if !found {
|
|
t.Errorf("noTranscriptYet names %s, which is not a listed agent", a)
|
|
}
|
|
}
|
|
}
|
|
|
|
// WorkBuddy's, WorkBuddy AI's and CodeBuddy Code's sessions are read as a
|
|
// conversation: what was typed (beside WorkBuddy's own reminder and
|
|
// @scene blocks), the replies, and each tool call with its result.
|
|
func TestTranscriptWorkBuddyFamily(t *testing.T) {
|
|
setupAgents(t)
|
|
n := 0
|
|
for _, s := range List(100) {
|
|
if s.Agent != "workbuddy" && s.Agent != "codebuddy" || s.ParentSession != "" {
|
|
continue
|
|
}
|
|
n++
|
|
if !s.Transcript {
|
|
t.Fatalf("%s session %s is not marked readable", s.Agent, s.ID)
|
|
}
|
|
tr, err := TranscriptOf(s)
|
|
if err != nil || len(tr.Parts) == 0 {
|
|
t.Fatalf("%s %s: %v, %d parts", s.Agent, s.ID, err, len(tr.Parts))
|
|
}
|
|
if strings.HasPrefix(s.ID, "22222222") {
|
|
var typed, reply, call, result bool
|
|
for _, p := range tr.Parts {
|
|
typed = typed || p.Kind == "text" && p.Role == "user" && p.Text == "Draft the launch notes"
|
|
reply = reply || p.Kind == "text" && p.Role == "assistant" && p.Text == "Reading the notes."
|
|
call = call || p.Kind == "tool_use" && p.Name == "Read"
|
|
result = result || p.Kind == "tool_result" && p.Name == "Read" && p.Text == "notes"
|
|
if strings.HasPrefix(p.Text, "@scene") {
|
|
t.Errorf("WorkBuddy's @scene block read as said: %+v", p)
|
|
}
|
|
}
|
|
if !typed || !reply || !call || !result {
|
|
t.Fatalf("typed %v reply %v call %v result %v: %+v", typed, reply, call, result, tr.Parts)
|
|
}
|
|
}
|
|
}
|
|
if n < 3 {
|
|
t.Fatalf("only %d WorkBuddy-family sessions listed", n)
|
|
}
|
|
}
|