Skip to content

feat: 适配 Reasonix 本地用量统计 - #452

Merged
xiufengsun merged 3 commits into
xiufengsun:mainfrom
wp-x:codex/reasonix-support
Aug 13, 2026
Merged

feat: 适配 Reasonix 本地用量统计#452
xiufengsun merged 3 commits into
xiufengsun:mainfrom
wp-x:codex/reasonix-support

Conversation

@wp-x

@wp-x wp-x commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

背景

Reasonix 是面向 DeepSeek 深度适配的 Harness Agent。当前 TokenTracker 无法识别 Reasonix 产生的本地用量,因此其模型和 Token 消耗不会出现在 Dashboard 中。

改动内容

  • 被动扫描 ~/.reasonix/projects/**/sessions/*.jsonl.telemetry.json~/.reasonix/sessions/**/*.jsonl.telemetry.json
  • 仅读取不含会话正文的 telemetry sidecar 和 .jsonl.meta,不读取提示词、回复或工具输出
  • 将累计 telemetry 快照转换为增量,避免重复同步造成重复计数
  • 正确拆分非缓存输入、缓存读取、普通输出和推理输出
  • 规范化第三方路由前缀,例如将 基元律动-雷/deepseek-v4-flash-0731 识别为 deepseek-v4-flash-0731
  • 将 Reasonix 纳入桌面端后台本地同步、init 检测和 status 状态输出
  • 增加 Reasonix 来源图标,并同步更新支持工具清单和相关元数据

隐私边界

Reasonix 适配只读取 Token 计数、模型标识和时间戳。不会读取或上传会话 JSONL 正文、提示词、模型回复、工具调用内容或源代码。

验证

  • Reasonix 解析、增量同步、后台同步及支持工具元数据回归测试:26 项通过
  • ProviderIcon 组件测试:9 项通过
  • validate:guardrailsvalidate:copyvalidate:ui-hardcode 通过
  • Dashboard production build 通过
  • 使用本机 24 个 Reasonix telemetry 文件验证:首次同步正常回填,第二次同步新增 0 条,Token 列恒等式成立
  • macOS DMG 本地构建、镜像校验及 App 深层签名校验通过

说明

Reasonix 来源金额沿用 TokenTracker 现有模型定价引擎估算;第三方 API 站点的实际账单可能因路由商加价、折扣或套餐而不同。

Summary by CodeRabbit

  • New Features
    • Added Reasonix as a supported passive telemetry integration.
    • Sync and status commands now discover, process, and report Reasonix usage data.
    • Added branding for Reasonix, Kilo CLI, Kilo Code, and Roo Code.
  • Documentation
    • Updated localized documentation, dashboard content, and package metadata to reflect support for 30 AI tools.
    • Documented Reasonix integration and telemetry support.
  • Tests
    • Added coverage for Reasonix discovery, parsing, incremental sync, and background processing.

@wp-x
wp-x requested a review from xiufengsun as a code owner August 12, 2026 08:14
@github-actions github-actions Bot added documentation Improvements or additions to documentation dashboard cli tests labels Aug 12, 2026
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: aa2584f0-c167-4f9a-b62f-1bd3de5e9138

📥 Commits

Reviewing files that changed from the base of the PR and between fff56c1 and c59dc9e.

📒 Files selected for processing (2)
  • package.json
  • test/sync-background.test.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json

📝 Walkthrough

Walkthrough

The change adds Reasonix as a passive telemetry provider. It discovers and parses Reasonix telemetry, integrates the data with CLI synchronization and status reporting, updates provider branding and supported-tool metadata, and adds parser and synchronization tests.

Changes

Reasonix integration

Layer / File(s) Summary
Reasonix telemetry parser
src/lib/rollout.js, test/reasonix-parser.test.js
The parser resolves Reasonix state directories, discovers telemetry sidecars, normalizes models and token fields, computes incremental deltas, creates half-hour buckets, and persists cursors. Tests cover discovery, normalization, cumulative growth, cache handling, and duplicate suppression.
CLI discovery and synchronization
src/commands/init.js, src/commands/status.js, src/commands/sync.js, test/sync-background.test.js
CLI initialization and status reporting detect Reasonix telemetry. Automatic synchronization parses Reasonix files, queues records, reports progress, isolates parser errors, and includes Reasonix totals.
Supported-tool metadata and documentation
README*.md, dashboard/index.html, dashboard/public/llms.txt, dashboard/src/ui/marketing/agent-logos.js, dashboard/src/ui/dashboard/components/ProviderIcon.jsx, dashboard/src/ui/dashboard/components/ProviderIcon.test.jsx, package.json, test/discovery-metadata.test.js
Documentation and metadata update supported-tool counts from 29 to 30. Reasonix is added to supported-tool and passive-reader lists, branding mappings, marketing entries, and metadata assertions. Claude Science is added to the German and Japanese lists.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Mergeability Score: ⚪ Minimal · up to c59dc

This change adds Reasonix local usage tracking and synchronization support; no actionable merge-blocking risk remains after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant Reasonix
  participant SyncCommand
  participant RolloutParser
  participant SyncQueue
  Reasonix->>SyncCommand: expose telemetry sidecars
  SyncCommand->>RolloutParser: parse telemetry incrementally
  RolloutParser->>SyncQueue: enqueue reasonix buckets
  SyncCommand->>SyncQueue: report parsed files and queued buckets
Loading

Possibly related PRs

Suggested reviewers: xiufengsun

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了为 Reasonix 增加本地用量统计支持这一主要变更。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@wp-x

wp-x commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author
image

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🧹 Nitpick comments (1)
test/sync-background.test.js (1)

366-376: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Extend the regression to cover the Reasonix parser contract.

This test runs one sync only. It cannot detect duplicate imports from cumulative snapshots. Run the same sync twice and assert that the second run adds no Reasonix tokens. Also assert the normalized token columns and the normalized routed model.

As per coding guidelines: “Verify provider-specific token semantics from raw usage and billing data before mapping fields; cached tokens may be included in a provider's input value.”

Based on learnings: “After changing sync logic or cursor schema, run sync twice consecutively to detect state pollution and migration errors.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/sync-background.test.js` around lines 366 - 376, Extend the test around
the all-local background sync to run the command twice, then verify the second
run does not increase Reasonix token totals. Assert the queue uses the
normalized token fields and normalized routed model, while preserving the
existing Reasonix source assertion and raw usage semantics.

Sources: Coding guidelines, Learnings

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@dashboard/index.html`:
- Line 370: Synchronize the supported-tool metadata with the 30-tool count: in
dashboard/index.html at lines 370-370, add Reasonix to the explicit FAQ list; in
README.de.md at lines 217-217, update the German comparison prose from 28 tools
to 30 tools.

In `@dashboard/src/ui/dashboard/components/ProviderIcon.jsx`:
- Line 334: Add REASONIX to the canonical PROVIDER_ICON_MAP using the uppercase
REASONIX key, in addition to its existing PROVIDER_LOGO_MAP entry.

In `@dashboard/src/ui/marketing/agent-logos.js`:
- Line 23: Move the user-facing “Reasonix” label out of the agent metadata in
the logos configuration. Add the corresponding localization entry to copy.csv
and update the rendering path for the Reasonix metadata to resolve its name from
the existing copy source, preserving the provider identifier.

In `@src/commands/init.js`:
- Around line 721-729: Update the Reasonix detection block to import and use the
shared resolveReasonixHome(process.env) resolver instead of manually reading
TOKENTRACKER_REASONIX_HOME, REASONIX_STATE_HOME, and the fallback path. Pass the
resolved home to existsSync so tilde-based overrides match the sync and status
behavior.

In `@src/commands/sync.js`:
- Line 285: Add "reasonix" to the BACKGROUND_AUTO_SYNC_SOURCES collection so
default --auto --background synchronization includes Reasonix telemetry. Extend
the relevant sync test to verify Reasonix is selected for default background
mode, while preserving the existing --all-local-sources coverage.

In `@src/lib/rollout.js`:
- Around line 12828-12830: Update the enqueue condition in the aggregation flow
around addReasonixDelta to also accept delta.requests > 0, so request-only
changes queue a conversation_count before sessionTotals[filePath] advances. Add
a regression test covering an increased requestCount with unchanged token
fields.

---

Nitpick comments:
In `@test/sync-background.test.js`:
- Around line 366-376: Extend the test around the all-local background sync to
run the command twice, then verify the second run does not increase Reasonix
token totals. Assert the queue uses the normalized token fields and normalized
routed model, while preserving the existing Reasonix source assertion and raw
usage semantics.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ae2d3374-5fbd-42a3-8317-5a3d630f232b

📥 Commits

Reviewing files that changed from the base of the PR and between 2300e14 and 3df1946.

⛔ Files ignored due to path filters (1)
  • dashboard/public/brand-logos/reasonix.png is excluded by !**/*.png
📒 Files selected for processing (18)
  • README.de.md
  • README.ja.md
  • README.ko.md
  • README.md
  • README.zh-CN.md
  • dashboard/index.html
  • dashboard/public/llms.txt
  • dashboard/src/ui/dashboard/components/ProviderIcon.jsx
  • dashboard/src/ui/dashboard/components/ProviderIcon.test.jsx
  • dashboard/src/ui/marketing/agent-logos.js
  • package.json
  • src/commands/init.js
  • src/commands/status.js
  • src/commands/sync.js
  • src/lib/rollout.js
  • test/discovery-metadata.test.js
  • test/reasonix-parser.test.js
  • test/sync-background.test.js

Comment thread dashboard/index.html Outdated
"PI-COPILOT": "/brand-logos/pi.svg",
"PI-OPENAI-CODEX": "/brand-logos/pi.svg",
QODER: "/brand-logos/qoder.svg",
REASONIX: "/brand-logos/reasonix.png",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Register REASONIX in PROVIDER_ICON_MAP.

Line 334 adds the provider only to PROVIDER_LOGO_MAP. Register the icon through the required canonical map with the uppercase REASONIX key.

As per coding guidelines, “Provider icons must be registered in PROVIDER_ICON_MAP using an uppercase source key.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dashboard/src/ui/dashboard/components/ProviderIcon.jsx` at line 334, Add
REASONIX to the canonical PROVIDER_ICON_MAP using the uppercase REASONIX key, in
addition to its existing PROVIDER_LOGO_MAP entry.

Sources: Coding guidelines, Learnings

{ id: 27, name: "Qoder", provider: "qoder" },
{ id: 28, name: "AnythingLLM", provider: "anythingllm" },
{ id: 29, name: "Claude Science", provider: "claude-science" },
{ id: 19, name: "Reasonix", provider: "reasonix" },

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Move the Reasonix label to copy.csv.

name is tooltip and accessibility text. The new hardcoded "Reasonix" value bypasses the dashboard localization source.

Add the label to dashboard/src/content/copy.csv and resolve it when rendering the logo metadata.

As per coding guidelines, “Never hardcode user-facing text; add it to dashboard/src/content/copy.csv.” As per path instructions, “User-facing strings must come from dashboard/src/content/copy.csv.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dashboard/src/ui/marketing/agent-logos.js` at line 23, Move the user-facing
“Reasonix” label out of the agent metadata in the logos configuration. Add the
corresponding localization entry to copy.csv and update the rendering path for
the Reasonix metadata to resolve its name from the existing copy source,
preserving the provider identifier.

Sources: Coding guidelines, Path instructions

Comment thread src/commands/init.js
Comment thread src/commands/sync.js
Comment thread src/lib/rollout.js Outdated

@xiufengsun xiufengsun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

NO-MERGE — reviewed exact head 3df1946d4c3b2b9e9a599834a2356f6d030ea738 against current origin/main.

There are two reproducible accounting blockers:

  1. normalizeReasonixTotals() ignores Reasonix cacheWriteTokens. In current Reasonix telemetry, cache writes are a subset of cacheMissTokens; this head assigns the entire miss count to input_tokens and always emits cache_creation_input_tokens: 0. That misclassifies cache writes and produces the wrong cost for providers with cache-write pricing. Please split cacheMissTokens into non-cached input plus cache creation, carry that field through cumulative state/diff, include it in total_tokens, and add a regression fixture with non-zero cacheWriteTokens.

  2. parseReasonixIncremental() only calls addReasonixDelta() when tokenDelta > 0, but advances sessionTotals[filePath] unconditionally. If requestCount grows while token fields do not, that conversation increment is skipped and then permanently absorbed into the cursor. Queue when either token delta or request delta is positive, and add a repeat-sync regression test.

The branch also conflicts with current main at package.json because it is still based on v0.88.4. Please rebase and keep the current release version while preserving the 30-tool description update. Request re-review after pushing a new head.

@wp-x
wp-x force-pushed the codex/reasonix-support branch from 3df1946 to fff56c1 Compare August 13, 2026 01:25
@wp-x

wp-x commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

已按 review 修复并更新分支:

  1. cacheWriteTokens 现在从 cacheMissTokens 中拆分,分别进入非缓存输入与缓存写入;缓存写入已贯穿累计 cursor、增量 diff、cache_creation_input_tokenstotal_tokens 及成本计算。
  2. 请求数单独增长时现在也会写入 bucket,不再被 cursor 吸收;已增加连续三次同步的回归测试,验证增量计入且重复同步不重复统计。
  3. 分支已 rebase 到当前 origin/main28c7c887),保留最新版本 0.88.6,同时保留 30-tool description。
  4. 补充了默认后台同步、二次同步幂等、模型归一化及 token 列拆分测试。
  5. 同步修正共享 Reasonix home resolver、FAQ 工具列表及德文工具数量。

本地验证:

  • Reasonix 相关 Node 测试:24 项通过
  • ProviderIcon 测试:9 项通过
  • guardrails / copy / ui-hardcode / versions:通过
  • Dashboard production build:通过

另外两条建议未做扩大范围的改动:

  • Reasonix 使用多彩图标,现有 PROVIDER_LOGO_MAP 已是实际渲染路径;重复加入 PROVIDER_ICON_MAP 不会参与该路径。
  • AGENT_LOGOS 当前所有品牌名均为静态 metadata,单独为 Reasonix 引入 copy 路径会形成不一致的局部重构。

新 head:fff56c166415599bf2162802ce3b67b6469137b9。当前 GitHub 已显示可合并,CI 正在运行。

@xiufengsun 烦请基于新 head 复审,谢谢。

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/sync-background.test.js`:
- Around line 77-97: Update withTempSyncEnv to save the current values of
TOKENTRACKER_REASONIX_HOME and REASONIX_STATE_HOME, clear both variables while
the test environment is active, and restore their original values during
cleanup, including preserving whether each was previously unset.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 8ca03dab-e9a9-4b3a-9f13-190c45acd69d

📥 Commits

Reviewing files that changed from the base of the PR and between 3df1946 and fff56c1.

📒 Files selected for processing (8)
  • README.de.md
  • dashboard/index.html
  • package.json
  • src/commands/init.js
  • src/commands/sync.js
  • src/lib/rollout.js
  • test/reasonix-parser.test.js
  • test/sync-background.test.js
🚧 Files skipped from review as they are similar to previous changes (4)
  • package.json
  • src/commands/sync.js
  • README.de.md
  • src/commands/init.js

Comment thread test/sync-background.test.js

@xiufengsun xiufengsun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

MERGE — 已基于 exact head c59dc9e 完成复审。此前 cacheWriteTokens、仅请求数增长、版本基线与测试隔离问题均已修复;与 #459 的组合集成验证通过,GitHub 全平台 CI/CodeQL 也均为绿色。

@xiufengsun
xiufengsun merged commit 8b8fbff into xiufengsun:main Aug 13, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli dashboard documentation Improvements or additions to documentation tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants