Files
magpie/internal/sessions/testdata/codebuddy/projects/Users-me-wired
yetone a3f2097ede 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/<cwd>/<id>.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:<id>, where models.json names <id> 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.
2026-10-12 22:55:23 +08:00
..