feat: add CodeFuse CLI usage parsing support - #42
Merged
Conversation
Contributor
Author
|
佬友你好,我很喜欢你做的这个工具,很有用,很漂亮,很感谢佬友的开发和分享!使用途中,我发现其中缺少了对code fuse的消耗统计支持,于是斗胆添加了一下,这是我第一次尝试参与开源项目和提PR,如果有任何不妥之处,恳请多多海涵和指正,谢谢! |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds first-class CodeFuse support to aiusage by wiring CodeFuse into discovery (CLI), parsing (core + CLI snapshot fallback), pricing/provider normalization, sync mapping behavior, and web UI tool filters.
Changes:
- Introduces
CodeFuseParserin@aiusage/coreto parse multiple CodeFuse/embedded formats (CC-like rows, native rows, embedded Codextoken_count, and tool call names without arguments). - Extends CLI discovery + parsing to find CodeFuse logs via env/config/default locations and to parse
ant_cc_*.jsonsnapshot fallbacks with JSONL de-duplication. - Updates tool registries/constants, pricing prefix normalization, sync mapping rules, and adds comprehensive tests across core + CLI.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/web/src/lib/constants.js | Adds codefuse to the web UI tool filter list. |
| packages/core/tests/codefuse.test.ts | Adds unit tests for CodeFuseParser behaviors (usage parsing, normalization, tool calls, finalize/orphans). |
| packages/core/src/types.ts | Registers codefuse in the core tool list/type surface. |
| packages/core/src/pricing.ts | Adds routed-model prefixes (glink/, antchat/) for price resolution normalization. |
| packages/core/src/parsers/index.ts | Exports CodeFuseParser from the parser index. |
| packages/core/src/parsers/codefuse.ts | Implements the CodeFuse parser (CC/native/Codex embedded + tool-call extraction). |
| packages/core/src/aggregator.ts | Registers CodeFuseParser in the core aggregator. |
| packages/cli/tests/sync/mapper.test.ts | Ensures sync mapping behavior includes codefuse where record.id should be used. |
| packages/cli/tests/discovery.test.ts | Tests CodeFuse discovery for native/CC/embedded Codex/snapshot fallback and custom roots. |
| packages/cli/tests/commands/parse-codefuse.test.ts | End-to-end CLI parse tests for CodeFuse sources + de-duplication and privacy constraints (no args stored). |
| packages/cli/src/watermark.ts | Adds codefuse watermark defaults. |
| packages/cli/src/sync/mapper.ts | Adds codefuse to tools that sync using record.id semantics. |
| packages/cli/src/discovery.ts | Adds CodeFuse probe + log enumeration logic and exposes multiple visible paths. |
| packages/cli/src/commands/parse.ts | Adds snapshot fallback parsing + CodeFuse-specific session ID extraction and snapshot de-duping. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- Extract normalizeCodeFuseModel to core (shared by parser and CLI snapshot path) - Extract parseTimestamp to core, replacing duplicated CLI/parser copies - Snapshot fallback now derives costSource from resolvePrice() like the parser, so a priced model computing zero cost is no longer mislabeled 'unknown'
- Add CodeFuse to README supported-tools tables (en + zh) - Add CodeFuse to site landing tool list and intro copy - Document CodeFuse data source, AIUSAGE_CODEFUSE_PATH / CODEFUSE_HOME, and the --tool codefuse flag in the docs page
Owner
|
感谢 PR,@Ed-Bg。解析思路扎实,沿用了现有 Codex/Kiro 范式,快照与 JSONL 去重在增量和全量重解析下都没问题,测试也都通过。 我推了两个小 commit 到这个分支:
构建和测试均已通过。没问题的话我就合并了。 |
Contributor
Author
|
没问题嘞,谢谢,辛苦维护啦! |
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.
Summary
Adds CodeFuse CLI usage support across discovery, parsing, sync mapping, pricing/provider normalization, and web tool filters.
CodeFuse CLI can store usage in multiple local formats, so this PR imports:
engine/cc/projectsengine/codex/sessionsant_cc_*.jsonsnapshot fallback files when no matching JSONL record existsChanges
codefuseto the core tool list, aggregator, parser exports, CLI watermark defaults, sync mapper, and web tool constants.CodeFuseParserfor:token_countrowsCODEFUSE_HOME,AIUSAGE_CODEFUSE_PATH, legacy config, and default~/.codefuse.ant_cc_*.json, with JSONL de-duplication to avoid double-counting.glink/claude-opus-4-6andantchat/claude-sonnet-4-6.<synthetic>models.Notes
The parser stores usage metrics, model/provider metadata, source file/cwd fields already used by aiusage, and tool call names. It does not store prompt text, completion text, or tool call arguments.
Test plan
CI=true PNPM_CONFIG_CONFIRM_MODULES_PURGE=false pnpm --filter @aiusage/core exec vitest run tests/codefuse.test.tsCI=true PNPM_CONFIG_CONFIRM_MODULES_PURGE=false pnpm --filter @aiusage/core exec tsc --noEmit -p tsconfig.jsonCI=true PNPM_CONFIG_CONFIRM_MODULES_PURGE=false pnpm --filter @juliantanx/aiusage exec vitest run tests/commands/parse-codefuse.test.ts tests/discovery.test.ts tests/sync/mapper.test.tsCI=true PNPM_CONFIG_CONFIRM_MODULES_PURGE=false pnpm --filter @aiusage/core buildCI=true PNPM_CONFIG_CONFIRM_MODULES_PURGE=false pnpm --filter @aiusage/web buildCI=true PNPM_CONFIG_CONFIRM_MODULES_PURGE=false pnpm --filter @juliantanx/aiusage build