Skip to content

feat: add CodeFuse CLI usage parsing support - #42

Merged
juliantanx merged 4 commits into
juliantanx:mainfrom
Ed-Bg:feat/codefuse-support
Jul 10, 2026
Merged

feat: add CodeFuse CLI usage parsing support#42
juliantanx merged 4 commits into
juliantanx:mainfrom
Ed-Bg:feat/codefuse-support

Conversation

@Ed-Bg

@Ed-Bg Ed-Bg commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

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:

  • native CodeFuse project JSONL logs
  • embedded Claude Code style JSONL logs under engine/cc/projects
  • embedded Codex session JSONL logs under engine/codex/sessions
  • ant_cc_*.json snapshot fallback files when no matching JSONL record exists

Changes

  • Add codefuse to the core tool list, aggregator, parser exports, CLI watermark defaults, sync mapper, and web tool constants.
  • Add CodeFuseParser for:
    • CodeFuse CC assistant usage rows
    • CodeFuse native assistant usage rows
    • embedded Codex token_count rows
    • tool call names without storing tool arguments
  • Add CodeFuse discovery via CODEFUSE_HOME, AIUSAGE_CODEFUSE_PATH, legacy config, and default ~/.codefuse.
  • Add snapshot fallback parsing for ant_cc_*.json, with JSONL de-duplication to avoid double-counting.
  • Normalize routed model names such as glink/claude-opus-4-6 and antchat/claude-sonnet-4-6.
  • Ignore non-assistant usage-looking rows and <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.ts
  • CI=true PNPM_CONFIG_CONFIRM_MODULES_PURGE=false pnpm --filter @aiusage/core exec tsc --noEmit -p tsconfig.json
  • CI=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.ts
  • CI=true PNPM_CONFIG_CONFIRM_MODULES_PURGE=false pnpm --filter @aiusage/core build
  • CI=true PNPM_CONFIG_CONFIRM_MODULES_PURGE=false pnpm --filter @aiusage/web build
  • CI=true PNPM_CONFIG_CONFIRM_MODULES_PURGE=false pnpm --filter @juliantanx/aiusage build

Copilot AI review requested due to automatic review settings July 7, 2026 03:31
@Ed-Bg

Ed-Bg commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

佬友你好,我很喜欢你做的这个工具,很有用,很漂亮,很感谢佬友的开发和分享!使用途中,我发现其中缺少了对code fuse的消耗统计支持,于是斗胆添加了一下,这是我第一次尝试参与开源项目和提PR,如果有任何不妥之处,恳请多多海涵和指正,谢谢!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 CodeFuseParser in @aiusage/core to parse multiple CodeFuse/embedded formats (CC-like rows, native rows, embedded Codex token_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_*.json snapshot 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.

Comment thread packages/cli/src/commands/parse.ts Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Ed-Bg Ed-Bg changed the title feat: add CodeFuse usage parsing support feat: add CodeFuse CLI usage parsing support Jul 7, 2026
- 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
@juliantanx

juliantanx commented Jul 7, 2026

Copy link
Copy Markdown
Owner

感谢 PR,@Ed-Bg。解析思路扎实,沿用了现有 Codex/Kiro 范式,快照与 JSONL 去重在增量和全量重解析下都没问题,测试也都通过。

我推了两个小 commit 到这个分支:

  1. refactor:把重复的 normalizeCodeFuseModel / 时间戳解析抽到 core 复用;快照的 costSource 改为与解析器一致(基于 resolvePrice())。
  2. docs:README 和站点文档补上 CodeFuse。

构建和测试均已通过。没问题的话我就合并了。

@Ed-Bg

Ed-Bg commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

没问题嘞,谢谢,辛苦维护啦!

@juliantanx
juliantanx merged commit 22d39c5 into juliantanx:main Jul 10, 2026
7 checks passed
juliantanx added a commit that referenced this pull request Jul 10, 2026
Add CodeFuse support (#42 by @Ed-Bg) and credit contributor.
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.

3 participants