sessions: CodeBuddy Code's own sessions are listed on the Sessions page, resumed with codebuddy --resume and deletable (#2657, caozeal)
CodeBuddy Code keeps its sessions as WorkBuddy does, ~/.codebuddy/projects/<cwd>/<id>.jsonl. magpie read them for the calls ledger (#1779) but never listed them: allFiles() and Dirs() left them out, parserFor sent them to the Claude parser, and Deletable didn't name the agent. caozeal's branch (85cc186a2) adds them to allFiles, Dirs, parserFor (workbuddyLine) and Deletable, with the meta cwd fallback WorkBuddy has, and the ledger reads through the same list. On top of it: the resume command is `codebuddy --resume <id>` (its CLI's `-r, --resume [sessionId]`, read from @tencent-ai/codebuddy-code 2.168.2's dist/codebuddy.js; codebuddy is one of the package's three bins). The Sessions page's and Usage > Sessions' agent label come from the agent registry (CodeBuddy Code, codebuddy-color) and needed no change; a test now holds them. Fixtures are the real `codebuddy -p` runs already in internal/sessions/testdata/codebuddy (#1779). Tests: - TestCodeBuddy (caozeal's, extended): two sessions with their cwd, title and model tokens; the resume command on each OS's form; Deletable. - TestCodeBuddySessionsListedUnderTheirName (new, internal/gui): /api/sessions, /api/sessions/manage and /api/sessions/stats name them CodeBuddy Code with its icon, resume command and trash. - Broken by hand, each red: allFiles reverted and parserFor reverted ("want 2 CodeBuddy Code sessions, got 0" in both tests), resume reverted (resume ""), Deletable reverted ("not deletable", "offers no trash"). Run ate085d6e92plus this change: - gofmt -l internal/: clean. go vet ./... (darwin): exit 0. GOOS=linux and GOOS=windows go vet -tags nogui ./...: exit 0. - go test -tags nogui -timeout 45m ./... under set -o pipefail: 64 packages ok, 2 red at load average ~110, neither ours: - internal/agent timed out at 45m (TestWSLMoreAgentsPick running; 2702.7s), recorded on #2544. - internal/gui TestRestartWhenIdle "restarted in a tool chain's gap" (30ms sleep vs 80ms idleSettle); passes -count=10 alone; filed #2673. - After rebasing onto origin/main7660399a1(#2576, #2578: gateway model list, gui Claude Desktop chip): internal/sessions ok (169.6s) and internal/gui ok (303.7s) at the rebased head on7660399a1. Co-authored-by: caozeal <21231607+caozeal@users.noreply.github.com>
This commit is contained in:
@@ -287,7 +287,10 @@ Code's, Claude Desktop's and Cowork's, Codex's (and both in WSL), and,
|
||||
read a file at a time (`wholeCallReaders` in
|
||||
[`call_cache.go`](../../internal/sessions/call_cache.go)), OpenCode's
|
||||
(#680), ZCode's, DeepSeek Harness's (`dsh`), WorkBuddy's, CodeBuddy
|
||||
Code's (#1779), MiniMax Code's (#1605), Kimi Code's (#1607,
|
||||
Code's (#1779; its sessions are on the Sessions page too, from the same
|
||||
`projects/<cwd>/<id>.jsonl` files read as WorkBuddy's, resumed with
|
||||
`codebuddy --resume <id>` and deletable, #2657: `TestCodeBuddy`,
|
||||
`TestCodeBuddySessionsListedUnderTheirName`), MiniMax Code's (#1605), Kimi Code's (#1607,
|
||||
[`calls_kimi.go`](../../internal/sessions/calls_kimi.go)) and Pi's and
|
||||
omp's, here and in WSL (#1951,
|
||||
[`calls_pi.go`](../../internal/sessions/calls_pi.go)). Each skips the
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/sessions"
|
||||
)
|
||||
|
||||
// CodeBuddy Code's own sessions (~/.codebuddy/projects, the real `codebuddy
|
||||
// -p` runs in the sessions package's testdata) reach the Sessions page and
|
||||
// Usage > Sessions under CodeBuddy Code's name and icon, with the command that
|
||||
// resumes them, and the page offers them to the trash (#2657).
|
||||
func TestCodeBuddySessionsListedUnderTheirName(t *testing.T) {
|
||||
h := sandboxHome(t)
|
||||
src := filepath.Join("..", "sessions", "testdata", "codebuddy")
|
||||
dst := filepath.Join(h, ".codebuddy")
|
||||
if err := filepath.WalkDir(src, func(p string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rel, _ := filepath.Rel(src, p)
|
||||
if d.IsDir() {
|
||||
return os.MkdirAll(filepath.Join(dst, rel), 0o755)
|
||||
}
|
||||
b, err := os.ReadFile(p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(filepath.Join(dst, rel), b, 0o644)
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sessions.Reset()
|
||||
t.Cleanup(sessions.Reset)
|
||||
|
||||
mux := http.NewServeMux()
|
||||
sessionRoutes(mux, folderOnly{})
|
||||
sessionManageRoutes(mux, folderOnly{})
|
||||
get := func(path string, v any) {
|
||||
t.Helper()
|
||||
w := httptest.NewRecorder()
|
||||
mux.ServeHTTP(w, httptest.NewRequest("GET", path, nil))
|
||||
if w.Code != 200 {
|
||||
t.Fatalf("%s: %d %s", path, w.Code, w.Body)
|
||||
}
|
||||
if err := json.Unmarshal(w.Body.Bytes(), v); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
type named struct {
|
||||
Agent string `json:"agent"`
|
||||
Name string `json:"name"`
|
||||
Icon string `json:"icon"`
|
||||
Resume string `json:"resume"`
|
||||
}
|
||||
var list struct{ Sessions []named }
|
||||
get("/api/sessions", &list)
|
||||
n := 0
|
||||
for _, s := range list.Sessions {
|
||||
if s.Agent != "codebuddy" {
|
||||
continue
|
||||
}
|
||||
n++
|
||||
if s.Name != "CodeBuddy Code" || s.Icon != "codebuddy-color" {
|
||||
t.Errorf("listed as %q (%s), want CodeBuddy Code (codebuddy-color)", s.Name, s.Icon)
|
||||
}
|
||||
if !strings.Contains(s.Resume, "codebuddy --resume ") {
|
||||
t.Errorf("resume %q", s.Resume)
|
||||
}
|
||||
}
|
||||
if n != 2 {
|
||||
t.Fatalf("want 2 CodeBuddy Code sessions, got %d: %+v", n, list.Sessions)
|
||||
}
|
||||
var manage struct {
|
||||
Agents []struct {
|
||||
named
|
||||
Deletable bool `json:"deletable"`
|
||||
}
|
||||
}
|
||||
get("/api/sessions/manage", &manage)
|
||||
found := false
|
||||
for _, a := range manage.Agents {
|
||||
if a.Agent == "codebuddy" {
|
||||
found = true
|
||||
if a.Name != "CodeBuddy Code" {
|
||||
t.Errorf("the Sessions page's agent is %q, want CodeBuddy Code", a.Name)
|
||||
}
|
||||
if !a.Deletable {
|
||||
t.Error("the Sessions page offers no trash for CodeBuddy Code's sessions")
|
||||
}
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("no codebuddy among the Sessions page's agents: %+v", manage.Agents)
|
||||
}
|
||||
var stats struct {
|
||||
Agents map[string]string `json:"agents"`
|
||||
}
|
||||
get("/api/sessions/stats?days=0", &stats)
|
||||
if stats.Agents["codebuddy"] != "CodeBuddy Code" {
|
||||
t.Errorf("Usage > Sessions' agent strip names it %q: %v", stats.Agents["codebuddy"], stats.Agents)
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,8 @@ const (
|
||||
)
|
||||
|
||||
// setupAgents is setup with ZCode's database made and dsh's, Cline's,
|
||||
// Qoder's, Grok Build's and WorkBuddy's sessions put in the home folder,
|
||||
// where each keeps them.
|
||||
// Qoder's, Grok Build's, WorkBuddy's and CodeBuddy Code's sessions put in the
|
||||
// home folder, where each keeps them.
|
||||
func setupAgents(t *testing.T) (home string) {
|
||||
claude, _ := setup(t)
|
||||
home = filepath.Join(filepath.Dir(claude), "home")
|
||||
@@ -82,6 +82,49 @@ func count(ss []Session, agent string) int {
|
||||
return n
|
||||
}
|
||||
|
||||
// CodeBuddy Code's own sessions are listed as its own agent's, read from
|
||||
// ~/.codebuddy/projects as WorkBuddy's are from ~/.workbuddy/projects
|
||||
// (#1779): the two `codebuddy -p` runs in testdata/codebuddy, one on a model
|
||||
// of the user's own, one on a model magpie wired.
|
||||
func TestCodeBuddy(t *testing.T) {
|
||||
inZone(t, 0)
|
||||
setupAgents(t)
|
||||
ss := List(0)
|
||||
if n := count(ss, "codebuddy"); n != 2 {
|
||||
t.Fatalf("want 2 CodeBuddy Code sessions, got %d", n)
|
||||
}
|
||||
for _, w := range []struct {
|
||||
id string
|
||||
cwd string
|
||||
}{{"01a12fea-4cae-78ac-8b2b-a1c0f9da9b1c", "/Users/me/work"}, {"01a12fed-6117-7b70-934b-2d2c05250180", "/Users/me/wired"}} {
|
||||
s := find(t, ss, "codebuddy", w.id)
|
||||
// the only line that names a folder is the session's own
|
||||
if s.Cwd != w.cwd || s.Title != "Read /etc/hosts and tell me what it names" {
|
||||
t.Fatalf("%s: %+v", w.id, s)
|
||||
}
|
||||
// a run's two lines — the tool call's and the text after it — carry
|
||||
// the same cumulative usage: 27017 in, of them 26496 read from the cache,
|
||||
// and 115 out. Each is counted once, as WorkBuddy's summary does
|
||||
want := Tokens{Input: 2 * (27017 - 26496), Output: 2 * 115, CacheRead: 2 * 26496}
|
||||
if m := model(s, "fake-m1"); m.Tokens != want {
|
||||
t.Fatalf("%s, fake-m1: %+v", w.id, m)
|
||||
}
|
||||
// picked up again by its CLI in its folder, as Claude Code's are
|
||||
run := "codebuddy --resume " + w.id
|
||||
wantResume := "cd '" + w.cwd + "' && " + run
|
||||
if runtime.GOOS == "windows" {
|
||||
wantResume = "Set-Location -LiteralPath '" + w.cwd + "'; " + run
|
||||
}
|
||||
if s.Resume != wantResume {
|
||||
t.Fatalf("%s: resume %q, want %q", w.id, s.Resume, wantResume)
|
||||
}
|
||||
}
|
||||
// its files are its own, so the Sessions page can move them to the trash
|
||||
if !Deletable("codebuddy") {
|
||||
t.Fatal("CodeBuddy Code's sessions are not deletable")
|
||||
}
|
||||
}
|
||||
|
||||
func TestZCode(t *testing.T) {
|
||||
inZone(t, 0)
|
||||
setupAgents(t)
|
||||
@@ -278,7 +321,7 @@ func TestDirsMore(t *testing.T) {
|
||||
home := setupAgents(t)
|
||||
d := Dirs()
|
||||
want := []string{filepath.Join(home, ".zcode"), filepath.Join(home, ".dsh"), filepath.Join(home, ".cline", "data", "sessions"), filepath.Join(home, ".qoder"), filepath.Join(home, ".qoder-cn"),
|
||||
filepath.Join(home, ".grok"), filepath.Join(home, ".workbuddy"), filepath.Join(home, ".omp", "agent")}
|
||||
filepath.Join(home, ".grok"), filepath.Join(home, ".workbuddy"), filepath.Join(home, ".codebuddy"), filepath.Join(home, ".omp", "agent")}
|
||||
if len(d) != 2+len(want) {
|
||||
t.Fatalf("dirs %v", d)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func workbuddyCallFiles() []file {
|
||||
// message lines, and the same models.json, so its calls are read as
|
||||
// WorkBuddy's are, from its own folder.
|
||||
func codebuddyCallFiles() []file {
|
||||
return buddyFiles("codebuddy", CodeBuddyDir())
|
||||
return codebuddyFiles()
|
||||
}
|
||||
|
||||
// CodeBuddyDir is CodeBuddy Code's folder: $CODEBUDDY_CONFIG_DIR, else
|
||||
|
||||
@@ -58,7 +58,7 @@ type AgentCount struct {
|
||||
// those kept as files of their own, in a layout magpie knows whole.
|
||||
func Deletable(agent string) bool {
|
||||
switch agent {
|
||||
case "claude", "qoder", "qoder-cn", "workbuddy", "codex", "pi", "omp", "cursor", "dsh":
|
||||
case "claude", "qoder", "qoder-cn", "workbuddy", "codebuddy", "codex", "pi", "omp", "cursor", "dsh":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// files — Claude Code's projects/*/<id>.jsonl (and Qoder's, the same kind),
|
||||
// Codex's rollout files, OpenCode's database (or its older JSON files) and
|
||||
// ZCode's, Pi's session files and omp's, DeepSeek Harness's, Cline's, Grok
|
||||
// Build's, WorkBuddy's, Droid's, Cursor CLI's and Alma's chat stores — with the tokens each spent, what that cost at the
|
||||
// Build's, WorkBuddy's and CodeBuddy Code's, Droid's, Cursor CLI's and Alma's chat stores — with the tokens each spent, what that cost at the
|
||||
// effective price, and the command that resumes it. It only ever reads the
|
||||
// agents' folders.
|
||||
//
|
||||
@@ -118,7 +118,7 @@ type Session struct {
|
||||
// Gateway: seen only through magpie's gateway, with no file of the
|
||||
// agent's on this computer (external.go)
|
||||
Gateway bool `json:"gateway,omitempty"`
|
||||
Agent string `json:"agent"` // magpie agent id: claude, codex, opencode, pi, omp, zcode, dsh, cline, qoder, qoder-cn, grok, workbuddy, droid, cursor, hermes, alma, kimi
|
||||
Agent string `json:"agent"` // magpie agent id: claude, codex, opencode, pi, omp, zcode, dsh, cline, qoder, qoder-cn, grok, workbuddy, codebuddy, droid, cursor, hermes, alma, kimi
|
||||
ID string `json:"id"`
|
||||
Cwd string `json:"cwd"`
|
||||
Title string `json:"title"` // the name it was given, else the agent's own title, else the first prompt
|
||||
@@ -473,7 +473,7 @@ func allFiles() []file {
|
||||
var out []file
|
||||
for _, fs := range [][]file{callFiles(), openCodeFiles(), piFiles(),
|
||||
wslFiles("pi", "omp", "kimi"), zcodeFiles(), dshFiles(), clineFiles(), ccFiles("qoder", QoderDir("qoder")), ccFiles("qoder-cn", QoderDir("qoder-cn")),
|
||||
grokFiles(), workbuddyFiles(), droidFiles(), ompFiles(), cursorFiles(), hermesFiles(), almaFiles(), kimiFiles()} {
|
||||
grokFiles(), workbuddyFiles(), codebuddyFiles(), droidFiles(), ompFiles(), cursorFiles(), hermesFiles(), almaFiles(), kimiFiles()} {
|
||||
out = append(out, fs...)
|
||||
}
|
||||
return out
|
||||
@@ -493,6 +493,7 @@ func Dirs() []string {
|
||||
{QoderDir("qoder-cn"), filepath.Join(QoderDir("qoder-cn"), "projects")},
|
||||
{GrokDir(), filepath.Join(GrokDir(), "sessions")},
|
||||
{WorkBuddyDir(), filepath.Join(WorkBuddyDir(), "projects")},
|
||||
{CodeBuddyDir(), filepath.Join(CodeBuddyDir(), "projects")},
|
||||
{OmpDir(), filepath.Join(OmpDir(), "sessions")},
|
||||
{FactoryDir(), filepath.Join(FactoryDir(), "sessions")},
|
||||
{CursorDir(), filepath.Join(CursorDir(), "chats")},
|
||||
@@ -1175,7 +1176,7 @@ func parserFor(agent string) sessionParser {
|
||||
return sessionParser{line: codexBody}
|
||||
case "pi", "omp":
|
||||
return sessionParser{line: piParse}
|
||||
case "workbuddy":
|
||||
case "workbuddy", "codebuddy":
|
||||
return sessionParser{line: workbuddyLine}
|
||||
default:
|
||||
return sessionParser{line: claudeLine, claude: true}
|
||||
@@ -1219,7 +1220,7 @@ func parse(f file, old *state) *state {
|
||||
if err == nil {
|
||||
s.Off = off
|
||||
}
|
||||
if f.agent == "workbuddy" && s.Cwd == "" {
|
||||
if isBuddy(f.agent) && s.Cwd == "" {
|
||||
workbuddyMeta(s, f.path)
|
||||
}
|
||||
return s
|
||||
@@ -1477,6 +1478,10 @@ func resumeCommand(distro, agent, id, cwd, path string) string {
|
||||
run = "qoderclicn --resume " + id
|
||||
case "grok":
|
||||
run = "grok --resume " + id
|
||||
case "codebuddy":
|
||||
// its CLI's -r, --resume [sessionId], one bin of the package's
|
||||
// three (codebuddy, cbc, codebuddy-code)
|
||||
run = "codebuddy --resume " + id
|
||||
case "omp":
|
||||
run = "omp --resume " + id
|
||||
if profile := ompProfile(path); profile != "" {
|
||||
|
||||
@@ -40,6 +40,14 @@ func WorkBuddyDir() string {
|
||||
// a session's own <id>.jsonl, and a subagent's under <id>/subagents/.
|
||||
func workbuddyFiles() []file { return buddyFiles("workbuddy", WorkBuddyDir()) }
|
||||
|
||||
// codebuddyFiles are the same under CodeBuddy Code's projects/: the CLI keeps
|
||||
// them as its desktop sibling does, one agent's folder apart (#1779).
|
||||
func codebuddyFiles() []file { return buddyFiles("codebuddy", CodeBuddyDir()) }
|
||||
|
||||
// isBuddy is whether agent keeps its sessions the way WorkBuddy does: its
|
||||
// own, or CodeBuddy Code's.
|
||||
func isBuddy(agent string) bool { return agent == "workbuddy" || agent == "codebuddy" }
|
||||
|
||||
// buddyFiles are the sessions under projects/ in dir, as agent's: WorkBuddy's,
|
||||
// or CodeBuddy Code's, which keeps them the same way.
|
||||
func buddyFiles(agent, dir string) []file {
|
||||
|
||||
Reference in New Issue
Block a user