feat(trae): add Trae client support
Merged
IT
6mo ago+2254+2254+0123456789012345678901234567890123456789-25-25-01234567890123456789
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|ideand a--manualJWT fallback for headless environments). - Auth — decrypts the desktop client's
iCubeAuthInfoblob fromglobalStorage/storage.json(faithful Rust port ofbyteCrypto.js: AES-128-CBC + SHA-512 integrity prefix). Cached credentials live at~/.config/tokscale/trae-cache/credentials-{solo,ide}.json(0600on Unix). Automatic refresh viaExchangeTokenbefore 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 bysession_id) and a per-cache sync lock for crash-safety. Mirrors the Antigravity pattern. - Parser —
crates/tokscale-core/src/sessions/trae.rsconsumes the API dump directly; Trae reportsdollar_float, so we don't go through the pricing lookup. Auto-mode sessions (model_name: "") are bucketed undertrae-auto. - TUI / filters — Trae appears in the client list (hotkey
y) and is selectable via--client trae. - Docs —
README.mdand the three localized variants document the new client, the Windows path, and the command set.
Test Plan
-
cargo fmt --all --checkclean -
cargo clippy --workspace --all-features -- -D warningsclean -
cargo test --workspace --all-features— 763 passed (675 core + 88 CLI), 0 failed -
scripts/check-version-coherence.sh—2.1.1consistent 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 traereports 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
synconly 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
traeclient for Trae IDE and Trae Solo (international; CN not supported). - CLI:
tokscale trae login|logout|status|syncwith--variant solo|ideand--manual; select via--client trae(hidden legacy--traeflag kept). - Auth: decrypts desktop
iCubeAuthInfofrom ElectronglobalStorage/storage.json; caches credentials and auto-refreshes. - Sync: paginated session-usage API; stores under
~/.config/tokscale/trae-cache/with a manifest, de-dup bysession_id, and a per-cache sync lock. - Parser/UI: uses API
dollar_floattotals (no pricing lookup); auto-mode bucketed astrae-auto; shown in TUI (hotkeyy). - Submission: excluded from default submit; opt in via
--client trae.
- New
-
Dependencies
- Added
aes,cbc, andbase64for credential decryption.
- Added