What
Third-party usage trackers (e.g. xiufengsun/TokenTracker#499) cannot measure Freebuff token usage from local files today. Two small persistence additions would unblock passive tracking without changing any runtime behavior.
Why it is blocked today (verified on current main)
ChatMessageMetadata (cli/src/types/chat.ts) has no usage field. chat-messages.json carries credits + metadata.runState only.
- Token counts (
inputTokens, outputTokens, cachedInputTokens) flow only in-memory via onUsageReceived (sdk/src/impl/llm.ts, packages/agent-runtime/src/run-agent-step.ts) and are never written to chat-messages.json or run-state.json. providerOptions.codebuff.usage in persisted history carries only { cost, costDetails } (sdk/src/impl/model-provider.ts).
IS_FREEBUFF (cli/src/utils/constants.ts) is never stamped to disk, so Freebuff and paid Codebuff chats sharing ~/.config/manicode/ are indistinguishable after the fact.
Request (2 additions, both gated on existing constants)
- Per-turn usage receipt: on run completion, write the final
ModelUsageData ({ inputTokens, outputTokens, cachedInputTokens, totalTokens, reasoningOutputTokens? }, type in common/src/types/contracts/llm.ts) into the persisted chat state — e.g. ChatMessage.metadata.usage in chat-messages.json and/or a usage summary in run-state.json. Raw provider values only, no estimation. Note inputTokens is inclusive of cache reads (common/src/util/tokens.ts), so consumers need both fields to avoid double-counting.
- Product marker: stamp e.g.
{ product: "freebuff" } (exact key your call) into run-state.json / chat-meta, gated on the existing IS_FREEBUFF flag. Natural home: saveChatState in cli/src/utils/run-state-storage.ts or writeChatMeta in cli/src/utils/chat-meta.ts. This fixes the Codebuff-vs-Freebuff attribution problem permanently; model-ID heuristics rot on every catalog change.
Scope notes
- No behavior change, no estimation fallback, no limits/quota surface (
rateLimitsByModel stays out of scope — it is pool quota, not tokens).
- Env nit: third-party docs currently say
FREEBUFF_DATA_DIR; actual override is FREEBUFF_CONFIG_DIR (cli/src/utils/config-dir.ts). Worth one line in README when this ships.
Happy to test the build on macOS once a snapshot exists.
What
Third-party usage trackers (e.g.
xiufengsun/TokenTracker#499) cannot measure Freebuff token usage from local files today. Two small persistence additions would unblock passive tracking without changing any runtime behavior.Why it is blocked today (verified on current
main)ChatMessageMetadata(cli/src/types/chat.ts) has nousagefield.chat-messages.jsoncarriescredits+metadata.runStateonly.inputTokens,outputTokens,cachedInputTokens) flow only in-memory viaonUsageReceived(sdk/src/impl/llm.ts,packages/agent-runtime/src/run-agent-step.ts) and are never written tochat-messages.jsonorrun-state.json.providerOptions.codebuff.usagein persisted history carries only{ cost, costDetails }(sdk/src/impl/model-provider.ts).IS_FREEBUFF(cli/src/utils/constants.ts) is never stamped to disk, so Freebuff and paid Codebuff chats sharing~/.config/manicode/are indistinguishable after the fact.Request (2 additions, both gated on existing constants)
ModelUsageData({ inputTokens, outputTokens, cachedInputTokens, totalTokens, reasoningOutputTokens? }, type incommon/src/types/contracts/llm.ts) into the persisted chat state — e.g.ChatMessage.metadata.usageinchat-messages.jsonand/or ausagesummary inrun-state.json. Raw provider values only, no estimation. NoteinputTokensis inclusive of cache reads (common/src/util/tokens.ts), so consumers need both fields to avoid double-counting.{ product: "freebuff" }(exact key your call) intorun-state.json/ chat-meta, gated on the existingIS_FREEBUFFflag. Natural home:saveChatStateincli/src/utils/run-state-storage.tsorwriteChatMetaincli/src/utils/chat-meta.ts. This fixes the Codebuff-vs-Freebuff attribution problem permanently; model-ID heuristics rot on every catalog change.Scope notes
rateLimitsByModelstays out of scope — it is pool quota, not tokens).FREEBUFF_DATA_DIR; actual override isFREEBUFF_CONFIG_DIR(cli/src/utils/config-dir.ts). Worth one line in README when this ships.Happy to test the build on macOS once a snapshot exists.