Skip to content
This repository was archived by the owner on Jul 30, 2026. It is now read-only.

feat(cline): ingest shared SDK v1 sessions - #175

Merged
makoMakoGo merged 2 commits into
personal/local-clientsfrom
codex/cline-sdk-v1
Jul 20, 2026
Merged

feat(cline): ingest shared SDK v1 sessions#175
makoMakoGo merged 2 commits into
personal/local-clientsfrom
codex/cline-sdk-v1

Conversation

@makoMakoGo

@makoMakoGo makoMakoGo commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Root cause

Cline VS Code 4.0+ and Cline CLI 3.x now persist the same SDK v1 *.messages.json artifacts under the Cline data directory. Tokscale still searched the retired VS Code globalStorage ui_messages.json layout and therefore missed current CLI usage, including a real Laguna M.1 free-model session whose metrics omitted vendor cost.

Current-format boundary

  • add a dedicated cache-backed Cline adapter for SDK v1 artifacts;
  • resolve the default root as CLINE_SESSION_DATA_DIR, CLINE_DATA_DIR/sessions, CLINE_DIR/data/sessions, then ~/.cline/data/sessions;
  • preserve configured Cline extra scan roots and canonical-path deduplication;
  • stop discovering retired Cline globalStorage task logs while leaving Roo Code and KiloCode unchanged;
  • use the optional root manifest only for workspace metadata and cache invalidation, and ignore sessions.db for usage authority;
  • reject unsupported envelopes at source scope and reject malformed usage at message scope.

Usage mapping

Each assistant message with valid metrics becomes one turn. Tokscale keeps the message timestamp, model, and provider, then maps tokens as follows:

input       = max(inputTokens - cacheReadTokens - cacheWriteTokens, 0)
output      = outputTokens
cache_read  = cacheReadTokens
cache_write = cacheWriteTokens
reasoning   = 0
cost        = 0.0

Vendor metrics.cost is neither read nor validated. Existing model canonicalization and Tokscale pricing remain authoritative. Lead, subagent, and teammate artifacts receive stable session and agent identities, so the TUI cache schema advances from 39 to 40.

User impact

Current Cline VS Code and CLI sessions now appear through the existing report pipeline. Legacy Cline VS Code task logs are intentionally unsupported. No public CLI arguments, aggregation structures, pricing rules, or client IDs change.

Validation

  • cargo fmt --all -- --check
  • cargo test -p tokscale-core cline — 14 passed
  • cargo test -p tokscale-core — 1,541 passed, 4 ignored
  • cargo test — 2,362 passed, 5 ignored
  • cargo clippy -p tokscale-core --all-targets -- -D warnings
  • cargo build -p tokscale-cli
  • cargo build --release -p tokscale-cli
  • bun run cli -- models --client cline --no-spinner — found laguna-m.1, 12 turns, and 293,305 tokens in the current local corpus

Summary by CodeRabbit

  • 新功能

    • 支持扫描和解析 Cline SDK v1 会话数据(*.messages.json)。
    • 支持通过环境变量配置 Cline 会话目录,并按优先级自动选择。
    • 支持识别主会话、子代理及队友会话,并统计助手消息用量。
  • 改进

    • 无效消息或清单不会影响其他有效记录的处理。
    • 缓存格式升级,提升缓存兼容性与可靠性。
  • 文档

    • 更新 Cline 数据来源、目录规则及格式支持说明。

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@makoMakoGo, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 51 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 12368d38-886b-497c-ae20-db1c040c9aad

📥 Commits

Reviewing files that changed from the base of the PR and between 3b25fc5 and aa31816.

📒 Files selected for processing (2)
  • crates/tokscale-core/src/local_clients.rs
  • crates/tokscale-core/src/scanner.rs

Walkthrough

Cline 本地数据源迁移至 SDK v1 *.messages.json 会话工件,新增路径解析、消息解析和本地适配器,并移除旧版 VS Code task-log 支持;TUI 缓存 schema 同步升级至 40。

Changes

Cline SDK v1 本地会话

Layer / File(s) Summary
会话根目录与扫描规则
crates/tokscale-core/src/local_clients.rs, crates/tokscale-core/src/scanner.rs, crates/tokscale-cli/src/commands/clients.rs, docs/...
Cline 按环境变量优先级或默认目录定位 session 根,扫描 *.messages.json,并更新相关文档与测试。
Messages v1 解析与校验
crates/tokscale-core/src/sessions/cline.rs
解析 version-1 envelope、assistant metrics、模型/provider、会话身份及 manifest workspace;无效记录被拒绝,manifest 错误标记源为 partial。
本地适配器接入
crates/tokscale-core/src/adapters/cline.rs, crates/tokscale-core/src/adapters/mod.rs, crates/tokscale-core/src/adapters/vscode_tasks.rs
新增 Cline 本地适配器并注册到本地源适配器集合,移除旧 VS Code tasks Cline 适配器及其专用路径逻辑。

TUI 缓存 schema

Layer / File(s) Summary
缓存 schema 升级
crates/tokscale-cli/src/tui/cache.rs
缓存 schema 版本从 39 更新为 40,相关加载提示、注释和 round-trip 测试同步更新。

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant Scanner
  participant ClineAdapter
  participant parse_cline_file
  participant TUI Cache
  CLI->>Scanner: resolve Cline session root
  Scanner->>ClineAdapter: discover *.messages.json
  ClineAdapter->>parse_cline_file: parse session unit
  parse_cline_file-->>ClineAdapter: ParsedUnit and rejections
  ClineAdapter-->>CLI: folded usage data
  CLI->>TUI Cache: read or write schema-40 bundle
Loading

Possibly related PRs

Poem

小兔蹦过 messages.json,
采来 token 满月光。
新适配器排好队,
旧 task-log 悄悄藏。
缓存四十戴新冠,
Cline 的会话闪闪亮。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 68.09% 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 标题准确概括了本次 PR 的核心变化:为 Cline 接入共享的 SDK v1 会话数据。
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
  • Commit unit tests in branch codex/cline-sdk-v1

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.

@codspeed-hq

codspeed-hq Bot commented Jul 20, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 41 untouched benchmarks


Comparing codex/cline-sdk-v1 (aa31816) with personal/local-clients (77f306e)

Open in CodSpeed

@makoMakoGo
makoMakoGo marked this pull request as ready for review July 20, 2026 08:34
@makoMakoGo
makoMakoGo merged commit 1e38ad3 into personal/local-clients Jul 20, 2026
9 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant