Skip to content

harness/codebuddy-cn: add CodeBuddy CN, reading the desktop app's request logs - #10

Merged
zzstar101 merged 1 commit into
nerv-base:mainfrom
dtapps:feat/codebuddy-cn
Nov 16, 2026
Merged

zzstar101 merged 1 commit into
nerv-base:mainfrom
dtapps:feat/codebuddy-cn

Conversation

@dtapps

@dtapps dtapps commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Adds a codebuddy-cn harness for CodeBuddy CN (国内版, codebuddy.cn). No such
harness existed: codebuddy reads only the international build under
~/.codebuddy, while the mainland build keeps its own home and, crucially, no
token or credit counters in any local database.

Where the numbers are

The mainland desktop build and its tencent-cloud.coding-copilot extension
journal every finished request as a plain-text line:

2026-11-06 22:38:36.930 [info] [CraftInvokableAgent] [90c56f83fae2e804...] Model prepared: Hy4 (hy4free)
2026-11-06 22:38:36.930 [info] [AgentReporter] [90c56f83fae2e804...] Agent execution successful with usage:
  {"inputTokens":253109,"outputTokens":1694,"cacheTokens":250368,"cachedMissTokens":2741,
   "cachedWriteTokens":0,"credit":0.41,"thinkingTokens":190}

This harness reads those lines. It does not install a hook: that would mean
writing into the tool's own settings, and MyToken's readers stay read-only.

What it does

  • Splits the five token classes without double counting: Input is the uncached
    prompt (cachedMissTokens, else inputTokens - cacheTokens) and Output is
    outputTokens - thinkingTokens. The model comes from the preceding
    [CraftInvokableAgent] line, cached in the cursor so incremental reads keep it.
  • Preserves the tool's own charge as Bill{unit: "credit"}. Nothing is converted
    to USD or CNY.
  • Deduplicates the same request journalled by both the app log and the extension
    log (they differ by one millisecond). DedupKey is the agent id plus the five
    token classes — never the path or the millisecond. Trade-off: two turns from
    the same agent with identical token counts collapse into one.
  • Fingerprints only the already-read prefix. These logs start small and grow a
    line at a time; hashing a fixed first 4 KB would change on every append and
    re-read the whole file.
  • Also reads CLI transcripts from $CODEBUDDYCN_HOME/projects (~/.codebuddycn/projects)
    through the existing WorkBuddy reader, since that half shares the schema.

Platform coverage

Verified against real installs:

  • macOS: ~/Library/Application Support/CodeBuddy CN/logs,
    ~/Library/Application Support/CodeBuddyExtension/Logs/{CodeBuddyIDE,VSCode}
  • Windows: %APPDATA%\CodeBuddy CN\logs, %APPDATA%\Code\logs,
    %LOCALAPPDATA%\CodeBuddyExtension\Logs\CodeBuddyIDE

Not verified:

  • Linux paths are inferred from the same Electron/VS Code conventions and have
    not been observed on a real machine. The walk therefore searches both the XDG
    variables and ~/.config / ~/.local/share, so a build that ignores XDG is
    still found.
  • The CLI transcript half is inferred from the international build; no CodeBuddy
    CN CLI transcript has been observed yet.

CRLF line endings, a UTF-8 BOM, local-time stamps without a zone, and
case-insensitive .LOG / path matching are covered by tests.

Results on real data

149 events across hy4free, deepseek-v4.1-flash and hy3; 47 of them carry a
credit charge. hy4free and hy3 show as unpriced because they are not in the
models.dev / LiteLLM catalog, which is the intended behaviour — an unknown price
is unpriced, never zero.

Checklist

  • harness package, model.CodeBuddyCN, Register, blank import in internal/app/app.go
  • conformance fixture + golden, root-provenance and rooted contracts
  • README rows (both languages), brand icon (reuses codebuddy-color.svg), install hint (site only, no command)
  • only numbers and an agent id are stored, never message text
  • gofmt clean, go vet on darwin/windows/linux, full test suite green
  • no cgo

CodeBuddy CN keeps no usage in any local database: the mainland desktop build journals every finished request to a plain-text log, so the previous harness (a WorkBuddy alias over ~/.codebuddycn/projects) could never see it.

- parse [AgentReporter] 'Agent execution successful with usage: {...}' lines and the preceding [CraftInvokableAgent] 'Model prepared:' line; keep the five token classes disjoint and preserve the tool's own credit charge as Bill

- dedup the same request journalled by both the app log and the extension log: the key is the agent id plus the token classes, never the path or the millisecond

- fingerprint only the already-read prefix, so a small log that grows a line at a time is not re-read in full on every scan

- roots: macOS and Windows verified against real installs; Linux walks the XDG variables and the plain defaults because it is unverified

- CRLF, UTF-8 BOM, local-time stamps and case-insensitive log matching covered by tests

Verified on real data: 149 events across hy4free, deepseek-v4.1-flash and hy3.

@zzstar101 zzstar101 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zzstar101
zzstar101 merged commit d82e079 into nerv-base:main Nov 16, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants