Repository navigation
harness/codebuddy-cn: add CodeBuddy CN, reading the desktop app's request logs - #10
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
codebuddy-cnharness for CodeBuddy CN (国内版, codebuddy.cn). No suchharness existed:
codebuddyreads only the international build under~/.codebuddy, while the mainland build keeps its own home and, crucially, notoken or credit counters in any local database.
Where the numbers are
The mainland desktop build and its
tencent-cloud.coding-copilotextensionjournal every finished request as a plain-text line:
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
Inputis the uncachedprompt (
cachedMissTokens, elseinputTokens - cacheTokens) andOutputisoutputTokens - thinkingTokens. The model comes from the preceding[CraftInvokableAgent]line, cached in the cursor so incremental reads keep it.Bill{unit: "credit"}. Nothing is convertedto USD or CNY.
log (they differ by one millisecond).
DedupKeyis the agent id plus the fivetoken classes — never the path or the millisecond. Trade-off: two turns from
the same agent with identical token counts collapse into one.
line at a time; hashing a fixed first 4 KB would change on every append and
re-read the whole file.
$CODEBUDDYCN_HOME/projects(~/.codebuddycn/projects)through the existing WorkBuddy reader, since that half shares the schema.
Platform coverage
Verified against real installs:
~/Library/Application Support/CodeBuddy CN/logs,~/Library/Application Support/CodeBuddyExtension/Logs/{CodeBuddyIDE,VSCode}%APPDATA%\CodeBuddy CN\logs,%APPDATA%\Code\logs,%LOCALAPPDATA%\CodeBuddyExtension\Logs\CodeBuddyIDENot verified:
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 isstill found.
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-flashandhy3; 47 of them carry acredit charge.
hy4freeandhy3show as unpriced because they are not in themodels.dev / LiteLLM catalog, which is the intended behaviour — an unknown price
is unpriced, never zero.
Checklist
model.CodeBuddyCN,Register, blank import ininternal/app/app.gocodebuddy-color.svg), install hint (site only, no command)gofmtclean,go veton darwin/windows/linux, full test suite green