feat(trae): add Trae client support

Merged
IT
6mo ago
+2254-25

Summary

Adds support for ByteDance's Trae IDE and Trae Solo (international editions). Both desktop clients share the same account-level usage data, so tokscale auto-discovers credentials from whichever is installed and reports them as a single trae client.

What's New

  • CLI — tokscale trae login | logout | status | sync (with --variant solo|ide and a --manual JWT fallback for headless environments).
  • Auth — decrypts the desktop client's iCubeAuthInfo blob from globalStorage/storage.json (faithful Rust port of byteCrypto.js: AES-128-CBC + SHA-512 integrity prefix). Cached credentials live at ~/.config/tokscale/trae-cache/credentials-{solo,ide}.json (0600 on Unix). Automatic refresh via ExchangeToken before expiry.
  • Sync — paginated POST /trae/api/v1/pay/query_user_usage_group_by_session, persisted under ~/.config/tokscale/trae-cache/sessions/*.json, with a manifest (de-dup by session_id) and a per-cache sync lock for crash-safety. Mirrors the Antigravity pattern.
  • Parser — crates/tokscale-core/src/sessions/trae.rs consumes the API dump directly; Trae reports dollar_float, so we don't go through the pricing lookup. Auto-mode sessions (model_name: "") are bucketed under trae-auto.
  • TUI / filters — Trae appears in the client list (hotkey y) and is selectable via --client trae.
  • Docs — README.md and the three localized variants document the new client, the Windows path, and the command set.

Test Plan

  • cargo fmt --all --check clean
  • cargo clippy --workspace --all-features -- -D warnings clean
  • cargo test --workspace --all-features — 763 passed (675 core + 88 CLI), 0 failed
  • scripts/check-version-coherence.sh — 2.1.1 consistent across workspace
  • Parser unit tests cover: empty file, single session, zero-token skip, model normalization, auto-mode fallback, missing metadata fallback
  • Decryption tests cover: hardcoded password invariant, round-trip, Unicode, base64 round-trip, magic-mismatch, too-short blob, tampered ciphertext, misaligned ciphertext
  • Manual smoke test: tokscale trae login (auto), tokscale trae sync, tokscale --client trae reports the synced totals

Notes

  • China editions (trae.com.cn) are intentionally not included — the CN backend does not expose a session-level usage query endpoint. Will be added if/when an official endpoint appears upstream.
  • Trae IDE and Trae Solo share account-level usage data, so sync only runs once per invocation regardless of which variants have credentials.

Summary by cubic

Adds support for Trae IDE and Trae Solo as a new trae client. You can log in, sync account-level session usage from the official API, and see totals in the TUI and reports.

  • New Features

    • New trae client for Trae IDE and Trae Solo (international; CN not supported).
    • CLI: tokscale trae login|logout|status|sync with --variant solo|ide and --manual; select via --client trae (hidden legacy --trae flag kept).
    • Auth: decrypts desktop iCubeAuthInfo from Electron globalStorage/storage.json; caches credentials and auto-refreshes.
    • Sync: paginated session-usage API; stores under ~/.config/tokscale/trae-cache/ with a manifest, de-dup by session_id, and a per-cache sync lock.
    • Parser/UI: uses API dollar_float totals (no pricing lookup); auto-mode bucketed as trae-auto; shown in TUI (hotkey y).
    • Submission: excluded from default submit; opt in via --client trae.
  • Dependencies

    • Added aes, cbc, and base64 for credential decryption.