From a3f2097ede889da66be3accc573ff72c18e515fd Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 12 Oct 2026 19:49:49 +0800 Subject: [PATCH] sessions: CodeBuddy Code's own calls reach Usage, read from its session files as WorkBuddy's are, and its calls through magpie's gateway are left to the gateway (#1779) CodeBuddy Code was wired on the Agents page, but nothing read its session files, so a call it made straight to its vendor never reached the usage ledger. Only the calls it made through magpie's gateway showed, logged by the gateway. CodeBuddy Code writes its sessions the way WorkBuddy does: projects//.jsonl under $CODEBUDDY_CONFIG_DIR, else ~/.codebuddy. A reply's usage sits in providerData.usage on its function_call or assistant message line, keyed by providerData.messageId, and models.json has the same format. So WorkBuddy's reader is now parameterized by agent: - buddyFiles(agent, dir) lists the files. - buddyGateway(dir, id) reads that agent's own models.json. Its stamp cache is kept per path. - readWorkBuddyCalls takes the agent from the file. "codebuddy" is registered in callSources and wholeCallReaders. A model CodeBuddy asks for as custom-local:, where models.json names with vendor "magpie", went to the gateway, and is skipped as WorkBuddy's are. The fixtures in testdata/codebuddy are CodeBuddy Code 2.164.0's own files (npm @tencent-ai/codebuddy-code), with only the cwd path shortened. They come from two `codebuddy -p` runs in a sandbox HOME against a local OpenAI fake: one on a model the user added for another vendor (counted: two replies, 521 in + 26496 cache read, 115 out), and one on a vendor "magpie" entry (skipped). Run: - TestCodeBuddyCalls goes red (0 calls) with codebuddyCallFiles taken out of callSources, and green with it in. - TestCodeBuddyGatewayIsItsOwn checks that each agent's models.json is its own. - go test ./internal/sessions passes. - gofmt, go vet, Linux nogui vet and Windows vet are clean. - Sandboxed go test ./... at the rebased head. Not done: - The Sessions page still doesn't list CodeBuddy Code's sessions. This commit is the Usage side only. - Reasoning tokens (outputTokensDetails) aren't recorded, as for WorkBuddy. - Not run against the reporter's China-edition session (47 calls). The line shapes match those in the issue. --- internal/sessions/agents_test.go | 1 + internal/sessions/call_cache.go | 3 +- internal/sessions/calls.go | 5 +- internal/sessions/calls_codebuddy_test.go | 55 ++++++++++++++ internal/sessions/calls_workbuddy.go | 76 ++++++++++++++----- .../sessions/testdata/codebuddy/models.json | 1 + ...01a12fed-6117-7b70-934b-2d2c05250180.jsonl | 5 ++ ...01a12fea-4cae-78ac-8b2b-a1c0f9da9b1c.jsonl | 5 ++ internal/sessions/workbuddy.go | 12 ++- 9 files changed, 139 insertions(+), 24 deletions(-) create mode 100644 internal/sessions/calls_codebuddy_test.go create mode 100644 internal/sessions/testdata/codebuddy/models.json create mode 100644 internal/sessions/testdata/codebuddy/projects/Users-me-wired/01a12fed-6117-7b70-934b-2d2c05250180.jsonl create mode 100644 internal/sessions/testdata/codebuddy/projects/Users-me-work/01a12fea-4cae-78ac-8b2b-a1c0f9da9b1c.jsonl diff --git a/internal/sessions/agents_test.go b/internal/sessions/agents_test.go index 820390e45..fb1ac942d 100644 --- a/internal/sessions/agents_test.go +++ b/internal/sessions/agents_test.go @@ -29,6 +29,7 @@ func setupAgents(t *testing.T) (home string) { copyTree(t, "testdata/qoder-cn", filepath.Join(home, ".qoder-cn")) copyTree(t, "testdata/grok", filepath.Join(home, ".grok")) copyTree(t, "testdata/workbuddy", filepath.Join(home, ".workbuddy")) + copyTree(t, "testdata/codebuddy", filepath.Join(home, ".codebuddy")) copyTree(t, "testdata/omp", filepath.Join(home, ".omp")) zcMakeDB(t, filepath.Join(home, ".zcode", "cli", "db", "db.sqlite")) return diff --git a/internal/sessions/call_cache.go b/internal/sessions/call_cache.go index 7e69e0af6..1f0434aed 100644 --- a/internal/sessions/call_cache.go +++ b/internal/sessions/call_cache.go @@ -66,7 +66,7 @@ func resetCalls() { zcCallList.stamp, zcCallList.files = "", nil zcCallList.Unlock() wbGateway.Lock() - wbGateway.stamp, wbGateway.ids = "", nil + wbGateway.byPath = nil wbGateway.Unlock() } @@ -175,6 +175,7 @@ var wholeCallReaders = map[string]func(file) (*callFile, bool){ "zcode": readZCodeCalls, "dsh": readDshCalls, "workbuddy": readWorkBuddyCalls, + "codebuddy": readWorkBuddyCalls, // #1779 // #1605 "minimax-code": readMiniMaxCalls, } diff --git a/internal/sessions/calls.go b/internal/sessions/calls.go index 3fa49513f..453e4eb61 100644 --- a/internal/sessions/calls.go +++ b/internal/sessions/calls.go @@ -221,8 +221,8 @@ func callFiles() []file { // rows of their database or their JSON files; DeepSeek Harness's, whose // session file is packed in frames and so cannot be read on from the middle // of one; and WorkBuddy's, whose usage lines repeat a reply's id as it goes -// on; and MiniMax Code's, whose messages file a later generation of its -// history may replace (#1605). Every agent here needs an entry in +// on, as CodeBuddy Code's do (#1779); and MiniMax Code's, whose messages +// file a later generation of its history may replace (#1605). Every agent here needs an entry in // wholeCallReaders. func callSources() []file { out := callFiles() @@ -230,6 +230,7 @@ func callSources() []file { out = append(out, zcodeCallFiles()...) out = append(out, dshCallFiles()...) out = append(out, minimaxCallFiles()...) + out = append(out, codebuddyCallFiles()...) return append(out, workbuddyCallFiles()...) } diff --git a/internal/sessions/calls_codebuddy_test.go b/internal/sessions/calls_codebuddy_test.go new file mode 100644 index 000000000..182249ae2 --- /dev/null +++ b/internal/sessions/calls_codebuddy_test.go @@ -0,0 +1,55 @@ +package sessions + +import ( + "testing" + "time" +) + +// CodeBuddy Code's direct calls reach the usage ledger (#1779). The two +// sessions in testdata/codebuddy are CodeBuddy Code 2.164.0's own files, from +// two `codebuddy -p` runs against a local OpenAI fake: one on a model the user +// added for another vendor (fake-m1), whose two replies (a Read tool call, +// then text) are calls of the agent's own; one on a model magpie wired +// (deepseek/pro, vendor "magpie" in models.json), whose replies the gateway +// logs itself and are not read here as well. +func TestCodeBuddyCalls(t *testing.T) { + setupAgents(t) + var got []Call + for _, c := range Calls(time.Time{}) { + if c.Agent == "codebuddy" { + got = append(got, c) + } + } + if len(got) != 2 { + t.Fatalf("want CodeBuddy Code's 2 direct calls, got %d: %+v", len(got), got) + } + // each reply: 27017 in, of them 26496 read from the cache; 115 out + want := Tokens{Input: 27017 - 26496, Output: 115, CacheRead: 26496} + // newest first: the text reply, then the tool call before it + for i, w := range []struct { + msg string + at int64 + }{{"01a12fea4ecc74979fe1b9832df42ddb", 1791805247199}, {"01a12fea4e6378c680e219148e8547be", 1791805247141}} { + c := got[i] + if c.Msg != w.msg || !c.Time.Equal(ms(w.at)) || c.Model != "fake-m1" || c.Tokens != want || c.Session != "01a12fea-4cae-78ac-8b2b-a1c0f9da9b1c" { + t.Fatalf("call %d: %+v", i, c) + } + } +} + +// WorkBuddy's calls are still WorkBuddy's: the two agents share a reader, +// and each is read against its own models.json. deepseek/pro is magpie's in +// CodeBuddy's models.json and not in WorkBuddy's, so the same id there +// would be the user's own. +func TestCodeBuddyGatewayIsItsOwn(t *testing.T) { + setupAgents(t) + if !buddyGateway(CodeBuddyDir(), "custom-local:deepseek/pro") { + t.Fatal("magpie's model in CodeBuddy's models.json is not read as the gateway's") + } + if buddyGateway(CodeBuddyDir(), "custom-local:fake-m1") { + t.Fatal("the user's own model in CodeBuddy's models.json is read as the gateway's") + } + if workbuddyGateway("custom-local:deepseek/pro") { + t.Fatal("CodeBuddy's models.json was read for WorkBuddy") + } +} diff --git a/internal/sessions/calls_workbuddy.go b/internal/sessions/calls_workbuddy.go index a3335afb0..e1b238f22 100644 --- a/internal/sessions/calls_workbuddy.go +++ b/internal/sessions/calls_workbuddy.go @@ -12,6 +12,7 @@ import ( "strings" "sync" + "github.com/yetone/magpie/internal/appdir" "github.com/yetone/magpie/internal/provider" ) @@ -37,10 +38,42 @@ func workbuddyCallFiles() []file { return workbuddyFiles() } -// wbGateway are the ids WorkBuddy has of magpie's gateway, kept while -// models.json is as it was, as zcodeCallFiles keeps its listing. +// codebuddyCallFiles are CodeBuddy Code's sessions as call sources (#1779). +// CodeBuddy Code is WorkBuddy's CLI sibling: the same projects//.jsonl +// files, the same providerData.usage on a reply's function_call and assistant +// 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()) +} + +// CodeBuddyDir is CodeBuddy Code's folder: $CODEBUDDY_CONFIG_DIR, else +// ~/.codebuddy, as internal/agent's codebuddy.go finds it. +func CodeBuddyDir() string { + if d := strings.TrimSpace(appdir.Getenv("CODEBUDDY_CONFIG_DIR")); d != "" { + return expandHome(d) + } + home, _ := os.UserHomeDir() + return filepath.Join(home, ".codebuddy") +} + +// buddyDir is the folder an agent read here keeps its models.json in. +func buddyDir(agent string) string { + if agent == "codebuddy" { + return CodeBuddyDir() + } + return WorkBuddyDir() +} + +// wbGateway are the ids each agent's models.json names as magpie's gateway, +// by the file's path, kept while it is as it was, as zcodeCallFiles keeps +// its listing. var wbGateway struct { sync.Mutex + byPath map[string]wbIDs +} + +type wbIDs struct { stamp string ids map[string]bool } @@ -61,13 +94,17 @@ var wbGateway struct { // gateway's rows for the same calls. It is the one shape this cannot tell // from the file alone — WorkBuddy names no provider of its own, as dsh, ZCode // and OpenCode do — so it is said here and pinned by a test. -func workbuddyGateway(id string) bool { +func workbuddyGateway(id string) bool { return buddyGateway(WorkBuddyDir(), id) } + +// buddyGateway is workbuddyGateway for the models.json in dir: WorkBuddy's, +// or CodeBuddy Code's, which names magpie's models the same way. +func buddyGateway(dir, id string) bool { const local = "custom-local:" if !strings.HasPrefix(id, local) { return false } id = id[len(local):] - return strings.HasPrefix(id, provider.GroupPrefix) || workbuddyGatewayIDs()[id] + return strings.HasPrefix(id, provider.GroupPrefix) || buddyGatewayIDs(dir)[id] } // wbEntry is what is read of a models.json entry: its id and whose it is. @@ -76,15 +113,15 @@ type wbEntry struct { Vendor string `json:"vendor"` } -// workbuddyGatewayIDs are the ids of the models WorkBuddy's models.json names +// buddyGatewayIDs are the ids of the models the models.json in dir names // as magpie's, an empty set when it names none (or cannot be read). -func workbuddyGatewayIDs() map[string]bool { - path := filepath.Join(WorkBuddyDir(), "models.json") +func buddyGatewayIDs(dir string) map[string]bool { + path := filepath.Join(dir, "models.json") stamp := ocStamp(path) wbGateway.Lock() defer wbGateway.Unlock() - if stamp == wbGateway.stamp { - return wbGateway.ids + if old, ok := wbGateway.byPath[path]; ok && stamp == old.stamp { + return old.ids } ids := map[string]bool{} // a bare list of entries, or an object with a "models" list, as @@ -108,11 +145,15 @@ func workbuddyGatewayIDs() map[string]bool { } } } - wbGateway.stamp, wbGateway.ids = stamp, ids + if wbGateway.byPath == nil { + wbGateway.byPath = map[string]wbIDs{} + } + wbGateway.byPath[path] = wbIDs{stamp, ids} return ids } -// readWorkBuddyCalls reads a session's calls whole: its usage lines repeat +// readWorkBuddyCalls reads a session's calls whole (WorkBuddy's, or CodeBuddy +// Code's, as f.agent says): its usage lines repeat // the same messageId as a reply goes on, so the last line for a reply is the // one that counts. A reply WorkBuddy brought over from its older history // names no messageId at all, and each of those is a call of its own, as the @@ -121,10 +162,11 @@ func workbuddyGatewayIDs() map[string]bool { func readWorkBuddyCalls(f file) (*callFile, bool) { r, err := openLines(f.path) if err != nil { - return &callFile{Path: f.path, Agent: "workbuddy"}, false + return &callFile{Path: f.path, Agent: f.agent}, false } defer r.Close() - st := &callFile{Agent: "workbuddy", Path: f.path, Session: strings.TrimPrefix(f.key, "workbuddy:")} + st := &callFile{Agent: f.agent, Path: f.path, Session: strings.TrimPrefix(f.key, f.agent+":")} + dir := buddyDir(f.agent) br := bufio.NewReaderSize(r, 1<<20) last := "" // the messageId the call before this line carried for { @@ -142,7 +184,7 @@ func readWorkBuddyCalls(f file) (*callFile, bool) { // a zero-token line is a call the same, and the reply after // it is a new one, so both readers end on the same call id := st.str(l.ProviderData.MessageID) - if c, ok := workbuddyCall(st, l, b); ok { + if c, ok := workbuddyCall(st, dir, l, b); ok { if c.Msg != "" && c.Msg == last { st.Calls[len(st.Calls)-1] = c // another line of the reply before it } else { @@ -162,10 +204,10 @@ func readWorkBuddyCalls(f file) (*callFile, bool) { // workbuddyCall is a line's providerData.usage as a call: the reply's model, // its tokens (input with the cache read and written taken out of it, as its // summary counts them) and the time it was written. -func workbuddyCall(st *callFile, l wbLine, b []byte) (Call, bool) { +func workbuddyCall(st *callFile, dir string, l wbLine, b []byte) (Call, bool) { // a call made to magpie's gateway is the gateway's record to keep, not // this one's: see workbuddyGateway - if workbuddyGateway(l.ProviderData.RequestModel) { + if buddyGateway(dir, l.ProviderData.RequestModel) { return Call{}, false } u := l.ProviderData.Usage @@ -180,7 +222,7 @@ func workbuddyCall(st *callFile, l wbLine, b []byte) (Call, bool) { read := u.InputDetails.sum("cached_tokens") + u.OldDetails.sum("cached_tokens") write := cmp.Or(u.CacheWrite, u.OldCacheWrite) c := Call{ - Agent: "workbuddy", + Agent: st.Agent, Time: t, Session: st.Session, Model: st.str(cmp.Or(l.ProviderData.Model, l.ProviderData.RequestModel)), diff --git a/internal/sessions/testdata/codebuddy/models.json b/internal/sessions/testdata/codebuddy/models.json new file mode 100644 index 000000000..6791f11ca --- /dev/null +++ b/internal/sessions/testdata/codebuddy/models.json @@ -0,0 +1 @@ +{"models":[{"id":"fake-m1","name":"Fake M1","vendor":"fakevendor","apiKey":"k-fake","url":"http://127.0.0.1:3971/v1/chat/completions","maxInputTokens":128000,"maxOutputTokens":8192,"supportsToolCall":true,"supportsImages":false},{"id":"deepseek/pro","name":"DeepSeek Pro","vendor":"magpie","apiKey":"magpie-codebuddy","url":"http://127.0.0.1:3425/v1/chat/completions","maxInputTokens":128000,"maxOutputTokens":8192,"supportsToolCall":true,"supportsImages":false}],"availableModels":["fake-m1","deepseek/pro"]} diff --git a/internal/sessions/testdata/codebuddy/projects/Users-me-wired/01a12fed-6117-7b70-934b-2d2c05250180.jsonl b/internal/sessions/testdata/codebuddy/projects/Users-me-wired/01a12fed-6117-7b70-934b-2d2c05250180.jsonl new file mode 100644 index 000000000..8f7ed2cbc --- /dev/null +++ b/internal/sessions/testdata/codebuddy/projects/Users-me-wired/01a12fed-6117-7b70-934b-2d2c05250180.jsonl @@ -0,0 +1,5 @@ +{"id":"01a12fed-6197-7302-8a5f-90a2d8ca6ce7","timestamp":1791805448638,"type":"message","role":"user","content":[{"type":"input_text","text":"Read /etc/hosts and tell me what it names"}],"providerData":{"agent":"cli","conversationRequestId":"01a12fed61bd7f6bb92f350f72673f87"},"__codebuddyLocal":{"sensitiveUserInputReviewed":true},"sessionId":"01a12fed-6117-7b70-934b-2d2c05250180","cwd":"/Users/me/wired","_meta":{"baggage":"codebuddy.session_id=01a12fed-6117-7b70-934b-2d2c05250180,codebuddy.conversation_request_id=01a12fed61bd7f6bb92f350f72673f87"}} +{"timestamp":1791805448651,"type":"file-history-snapshot","messageId":"01a12fed-6197-7302-8a5f-90a2d8ca6ce7","isSnapshotUpdate":false,"snapshot":{"messageId":"01a12fed-6197-7302-8a5f-90a2d8ca6ce7","trackedFileBackups":{}},"cwd":"/Users/me/wired","_meta":{"baggage":"codebuddy.session_id=01a12fed-6117-7b70-934b-2d2c05250180,codebuddy.conversation_request_id=01a12fed61bd7f6bb92f350f72673f87"}} +{"id":"01a12fed-63f5-7101-b386-13110ed3b9ae","parentId":"01a12fed-6197-7302-8a5f-90a2d8ca6ce7","timestamp":1791805449205,"type":"function_call","providerData":{"conversationRequestId":"01a12fed61bd7f6bb92f350f72673f87","messageId":"01a12fed63b177fa9f668fec808e9215","stepSeq":1,"model":"fake-m1","requestModelId":"custom-local:deepseek/pro","requestModelName":"DeepSeek Pro","traceId":"96551cb44f4dc5dd52ad317efc4634a0","rawUsage":{"prompt_tokens":27017,"completion_tokens":115,"total_tokens":27132,"prompt_tokens_details":{"cached_tokens":26496},"completion_tokens_details":{"reasoning_tokens":48}},"agent":"cli","argumentsDisplayText":"../../../../../../../../etc/hosts","usage":{"requests":1,"inputTokens":27017,"outputTokens":115,"totalTokens":27132,"inputTokensDetails":[{"cached_tokens":26496}],"outputTokensDetails":[{"reasoning_tokens":48}]}},"callId":"call_fake1","name":"Read","arguments":"{\"file_path\": \"/etc/hosts\"}","sessionId":"01a12fed-6117-7b70-934b-2d2c05250180","message":{"usage":{"input_tokens":27017,"output_tokens":115,"total_tokens":27132,"cache_read_input_tokens":26496}},"cwd":"/Users/me/wired","_meta":{"baggage":"codebuddy.session_id=01a12fed-6117-7b70-934b-2d2c05250180,codebuddy.conversation_request_id=01a12fed61bd7f6bb92f350f72673f87"}} +{"id":"01a12fed-6430-70a5-ba48-50d0a7c61761","parentId":"01a12fed-63f5-7101-b386-13110ed3b9ae","timestamp":1791805449248,"type":"function_call_result","name":"Read","callId":"call_fake1","status":"completed","output":{"type":"text","text":" 1→##\n 2→# Host Database\n 3→#\n 4→# localhost is used to configure the loopback interface\n 5→# when the system is booting. Do not change this entry.\n 6→##\n 7→127.0.0.1\tlocalhost\n 8→255.255.255.255\tbroadcasthost\n 9→::1 localhost\n 10→"},"providerData":{"conversationRequestId":"01a12fed61bd7f6bb92f350f72673f87","messageId":"01a12fed63b177fa9f668fec808e9215","stepSeq":1,"agent":"cli","toolResult":{"title":"Read \u001b[38;2;0;0;0m10\u001b[39m lines","content":" 1→##\n 2→# Host Database\n 3→#\n 4→# localhost is used to configure the loopback interface\n 5→# when the system is booting. Do not change this entry.\n 6→##\n 7→127.0.0.1\tlocalhost\n 8→255.255.255.255\tbroadcasthost\n 9→::1 localhost\n 10→","renderer":{"type":"code","context":{"language":"text"}}},"model":"fake-m1","requestModelId":"custom-local:deepseek/pro","requestModelName":"DeepSeek Pro","traceId":"96551cb44f4dc5dd52ad317efc4634a0"},"sessionId":"01a12fed-6117-7b70-934b-2d2c05250180","cwd":"/Users/me/wired","_meta":{"baggage":"codebuddy.session_id=01a12fed-6117-7b70-934b-2d2c05250180,codebuddy.conversation_request_id=01a12fed61bd7f6bb92f350f72673f87"}} +{"id":"01a12fed-6432-75fc-80a0-171aa793aaad","parentId":"01a12fed-6430-70a5-ba48-50d0a7c61761","timestamp":1791805449290,"type":"message","role":"assistant","providerData":{"conversationRequestId":"01a12fed61bd7f6bb92f350f72673f87","messageId":"01a12fed643275fc80a017198c80d8f9","stepSeq":2,"model":"fake-m1","requestModelId":"custom-local:deepseek/pro","requestModelName":"DeepSeek Pro","traceId":"96551cb44f4dc5dd52ad317efc4634a0","rawUsage":{"prompt_tokens":27017,"completion_tokens":115,"total_tokens":27132,"prompt_tokens_details":{"cached_tokens":26496},"completion_tokens_details":{"reasoning_tokens":48}},"agent":"cli","usage":{"requests":1,"inputTokens":27017,"outputTokens":115,"totalTokens":27132,"inputTokensDetails":[{"cached_tokens":26496}],"outputTokensDetails":[{"reasoning_tokens":48}]}},"status":"completed","content":[{"providerData":{"annotations":[]},"type":"output_text","text":"Done: the file names localhost."}],"sessionId":"01a12fed-6117-7b70-934b-2d2c05250180","message":{"usage":{"input_tokens":27017,"output_tokens":115,"total_tokens":27132,"cache_read_input_tokens":26496}},"cwd":"/Users/me/wired","_meta":{"baggage":"codebuddy.session_id=01a12fed-6117-7b70-934b-2d2c05250180,codebuddy.conversation_request_id=01a12fed61bd7f6bb92f350f72673f87"}} diff --git a/internal/sessions/testdata/codebuddy/projects/Users-me-work/01a12fea-4cae-78ac-8b2b-a1c0f9da9b1c.jsonl b/internal/sessions/testdata/codebuddy/projects/Users-me-work/01a12fea-4cae-78ac-8b2b-a1c0f9da9b1c.jsonl new file mode 100644 index 000000000..0d7c43f82 --- /dev/null +++ b/internal/sessions/testdata/codebuddy/projects/Users-me-work/01a12fea-4cae-78ac-8b2b-a1c0f9da9b1c.jsonl @@ -0,0 +1,5 @@ +{"id":"01a12fea-4d54-7897-a7e2-dd56aec59483","timestamp":1791805246844,"type":"message","role":"user","content":[{"type":"input_text","text":"Read /etc/hosts and tell me what it names"}],"providerData":{"agent":"cli","conversationRequestId":"01a12fea4d7b7b68b06bc54ed751c2e5"},"__codebuddyLocal":{"sensitiveUserInputReviewed":true},"sessionId":"01a12fea-4cae-78ac-8b2b-a1c0f9da9b1c","cwd":"/Users/me/work","_meta":{"baggage":"codebuddy.session_id=01a12fea-4cae-78ac-8b2b-a1c0f9da9b1c,codebuddy.conversation_request_id=01a12fea4d7b7b68b06bc54ed751c2e5"}} +{"timestamp":1791805246854,"type":"file-history-snapshot","messageId":"01a12fea-4d54-7897-a7e2-dd56aec59483","isSnapshotUpdate":false,"snapshot":{"messageId":"01a12fea-4d54-7897-a7e2-dd56aec59483","trackedFileBackups":{}},"cwd":"/Users/me/work","_meta":{"baggage":"codebuddy.session_id=01a12fea-4cae-78ac-8b2b-a1c0f9da9b1c,codebuddy.conversation_request_id=01a12fea4d7b7b68b06bc54ed751c2e5"}} +{"id":"01a12fea-4ea5-7002-9e15-6fb1a341ec7b","parentId":"01a12fea-4d54-7897-a7e2-dd56aec59483","timestamp":1791805247141,"type":"function_call","providerData":{"conversationRequestId":"01a12fea4d7b7b68b06bc54ed751c2e5","messageId":"01a12fea4e6378c680e219148e8547be","stepSeq":1,"model":"fake-m1","requestModelId":"custom-local:fake-m1","requestModelName":"Fake M1","traceId":"5ecbd1ca27e3d63f78f8d8bd367e9173","rawUsage":{"prompt_tokens":27017,"completion_tokens":115,"total_tokens":27132,"prompt_tokens_details":{"cached_tokens":26496},"completion_tokens_details":{"reasoning_tokens":48}},"agent":"cli","argumentsDisplayText":"../../../../../../../../etc/hosts","usage":{"requests":1,"inputTokens":27017,"outputTokens":115,"totalTokens":27132,"inputTokensDetails":[{"cached_tokens":26496}],"outputTokensDetails":[{"reasoning_tokens":48}]}},"callId":"call_fake1","name":"Read","arguments":"{\"file_path\": \"/etc/hosts\"}","sessionId":"01a12fea-4cae-78ac-8b2b-a1c0f9da9b1c","message":{"usage":{"input_tokens":27017,"output_tokens":115,"total_tokens":27132,"cache_read_input_tokens":26496}},"cwd":"/Users/me/work","_meta":{"baggage":"codebuddy.session_id=01a12fea-4cae-78ac-8b2b-a1c0f9da9b1c,codebuddy.conversation_request_id=01a12fea4d7b7b68b06bc54ed751c2e5"}} +{"id":"01a12fea-4eca-7707-a154-62d4724c67eb","parentId":"01a12fea-4ea5-7002-9e15-6fb1a341ec7b","timestamp":1791805247176,"type":"function_call_result","name":"Read","callId":"call_fake1","status":"completed","output":{"type":"text","text":" 1→##\n 2→# Host Database\n 3→#\n 4→# localhost is used to configure the loopback interface\n 5→# when the system is booting. Do not change this entry.\n 6→##\n 7→127.0.0.1\tlocalhost\n 8→255.255.255.255\tbroadcasthost\n 9→::1 localhost\n 10→"},"providerData":{"conversationRequestId":"01a12fea4d7b7b68b06bc54ed751c2e5","messageId":"01a12fea4e6378c680e219148e8547be","stepSeq":1,"agent":"cli","toolResult":{"title":"Read \u001b[38;2;0;0;0m10\u001b[39m lines","content":" 1→##\n 2→# Host Database\n 3→#\n 4→# localhost is used to configure the loopback interface\n 5→# when the system is booting. Do not change this entry.\n 6→##\n 7→127.0.0.1\tlocalhost\n 8→255.255.255.255\tbroadcasthost\n 9→::1 localhost\n 10→","renderer":{"type":"code","context":{"language":"text"}}},"model":"fake-m1","requestModelId":"custom-local:fake-m1","requestModelName":"Fake M1","traceId":"5ecbd1ca27e3d63f78f8d8bd367e9173"},"sessionId":"01a12fea-4cae-78ac-8b2b-a1c0f9da9b1c","cwd":"/Users/me/work","_meta":{"baggage":"codebuddy.session_id=01a12fea-4cae-78ac-8b2b-a1c0f9da9b1c,codebuddy.conversation_request_id=01a12fea4d7b7b68b06bc54ed751c2e5"}} +{"id":"01a12fea-4ecc-7497-9fe1-b9841b286f77","parentId":"01a12fea-4eca-7707-a154-62d4724c67eb","timestamp":1791805247199,"type":"message","role":"assistant","providerData":{"conversationRequestId":"01a12fea4d7b7b68b06bc54ed751c2e5","messageId":"01a12fea4ecc74979fe1b9832df42ddb","stepSeq":2,"model":"fake-m1","requestModelId":"custom-local:fake-m1","requestModelName":"Fake M1","traceId":"5ecbd1ca27e3d63f78f8d8bd367e9173","rawUsage":{"prompt_tokens":27017,"completion_tokens":115,"total_tokens":27132,"prompt_tokens_details":{"cached_tokens":26496},"completion_tokens_details":{"reasoning_tokens":48}},"agent":"cli","usage":{"requests":1,"inputTokens":27017,"outputTokens":115,"totalTokens":27132,"inputTokensDetails":[{"cached_tokens":26496}],"outputTokensDetails":[{"reasoning_tokens":48}]}},"status":"completed","content":[{"providerData":{"annotations":[]},"type":"output_text","text":"Done: the file names localhost."}],"sessionId":"01a12fea-4cae-78ac-8b2b-a1c0f9da9b1c","message":{"usage":{"input_tokens":27017,"output_tokens":115,"total_tokens":27132,"cache_read_input_tokens":26496}},"cwd":"/Users/me/work","_meta":{"baggage":"codebuddy.session_id=01a12fea-4cae-78ac-8b2b-a1c0f9da9b1c,codebuddy.conversation_request_id=01a12fea4d7b7b68b06bc54ed751c2e5"}} diff --git a/internal/sessions/workbuddy.go b/internal/sessions/workbuddy.go index 76ecd7ad2..9422e0073 100644 --- a/internal/sessions/workbuddy.go +++ b/internal/sessions/workbuddy.go @@ -38,15 +38,19 @@ func WorkBuddyDir() string { // workbuddyFiles are the sessions under WorkBuddy's projects/, however deep: // a session's own .jsonl, and a subagent's under /subagents/. -func workbuddyFiles() []file { +func workbuddyFiles() []file { return buddyFiles("workbuddy", WorkBuddyDir()) } + +// 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 { var out []file - filepath.WalkDir(filepath.Join(WorkBuddyDir(), "projects"), func(p string, d os.DirEntry, err error) error { + filepath.WalkDir(filepath.Join(dir, "projects"), func(p string, d os.DirEntry, err error) error { if err != nil || d.IsDir() || !strings.HasSuffix(d.Name(), ".jsonl") { return nil } - f := file{agent: "workbuddy", key: "workbuddy:" + strings.TrimSuffix(d.Name(), ".jsonl"), path: p, main: true} + f := file{agent: agent, key: agent + ":" + strings.TrimSuffix(d.Name(), ".jsonl"), path: p, main: true} if dir := filepath.Dir(p); filepath.Base(dir) == "subagents" { - f.key, f.main = "workbuddy:"+filepath.Base(filepath.Dir(dir)), false + f.key, f.main = agent+":"+filepath.Base(filepath.Dir(dir)), false } if stat(&f) { out = append(out, f)