feat(trae): add Trae client support - #555
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
There was a problem hiding this comment.
3 issues found across 16 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="crates/tokscale-core/src/sessions/trae.rs">
<violation number="1" location="crates/tokscale-core/src/sessions/trae.rs:64">
P2: Missing/invalid `session_id` and `usage_time` are silently defaulted, which can cause dedup collisions and invalid epoch-0 timestamps instead of rejecting bad records.</violation>
</file>
<file name="crates/tokscale-cli/src/trae.rs">
<violation number="1" location="crates/tokscale-cli/src/trae.rs:455">
P1: Manual JWT base64 padding is stripped by trim_end_matches('='), causing decode failures and immediate credential expiry</violation>
<violation number="2" location="crates/tokscale-cli/src/trae.rs:982">
P1: Stale lock file is not cleaned up after abnormal termination, permanently blocking subsequent syncs</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
86d493b to
d4ae3e1
Compare
|
@itling I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
2 issues found across 16 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="crates/tokscale-cli/src/main.rs">
<violation number="1" location="crates/tokscale-cli/src/main.rs:4363">
P1: Invalid --variant values silently expand scope to all variants instead of returning an error</violation>
</file>
<file name="crates/tokscale-cli/src/trae.rs">
<violation number="1" location="crates/tokscale-cli/src/trae.rs:1221">
P2: Sync selection logic does not fail over to another variant when the first credentialed variant fails.</violation>
</file>
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
d4ae3e1 to
ee25a89
Compare
|
@cubic-dev-ai re-review please — the two findings on
|
@itling I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
4 issues found across 16 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="crates/tokscale-cli/src/tui/data/mod.rs">
<violation number="1" location="crates/tokscale-cli/src/tui/data/mod.rs:1147">
P2: `test_client_all` was bumped to expect 24 clients but only asserts indices 0..=22, leaving the new client unverified. Companion mapping tests (`test_client_as_str`, `test_client_key`, `test_client_from_key`) also omit Trae assertions.</violation>
</file>
<file name="README.zh-cn.md">
<violation number="1" location="README.zh-cn.md:541">
P2: `TOKSCALE_CONFIG_DIR` documentation omits `trae-cache/` from the list of relocated directories, inconsistent with the updated cache layout section that groups `trae-cache/` with other client-specific caches under the config root.</violation>
</file>
<file name="crates/tokscale-cli/src/trae.rs">
<violation number="1" location="crates/tokscale-cli/src/trae.rs:263">
P2: Decrypted credentials returned without expiry/refresh check, causing avoidable first-run auth failures when stored access token is stale</violation>
<violation number="2" location="crates/tokscale-cli/src/trae.rs:1080">
P1: pid_is_alive always returns true on non-Unix, making stale lock recovery impossible on Windows</violation>
</file>
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
ee25a89 to
90122a9
Compare
|
@cubic-dev-ai re-review please — the four findings on
|
@itling I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
1 issue found across 16 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="crates/tokscale-core/src/sessions/trae.rs">
<violation number="1" location="crates/tokscale-core/src/sessions/trae.rs:75">
P2: Untrusted `usage_time` from JSON cache can overflow `i64` when multiplied by 1000, causing debug panics or release wraparound timestamps</violation>
</file>
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
90122a9 to
1671a12
Compare
|
@cubic-dev-ai re-review please — the
|
@itling I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
2 issues found across 16 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="crates/tokscale-cli/src/trae.rs">
<violation number="1" location="crates/tokscale-cli/src/trae.rs:476">
P2: `get_token_and_host` uses `.unwrap()` on `load_credentials` despite returning `Result`, risking a panic if the credentials file is deleted, corrupted, or written non-atomically between `resolve_token` and the reload.</violation>
</file>
<file name="crates/tokscale-cli/src/main.rs">
<violation number="1" location="crates/tokscale-cli/src/main.rs:4486">
P2: `trae sync --since` accepts non-positive `i64` values without validation, forwarding invalid lookback windows to the sync layer where negative days produce a future timestamp and zero days produce an empty range.</violation>
</file>
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
1671a12 to
a4e2e48
Compare
|
@cubic-dev-ai re-review please — the two findings on
|
@itling I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
2 issues found across 16 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="crates/tokscale-cli/src/trae.rs">
<violation number="1" location="crates/tokscale-cli/src/trae.rs:1040">
P2: Pagination can silently truncate data when API omits `total` due to `unwrap_or(0)`</violation>
</file>
<file name="README.ko.md">
<violation number="1" location="README.ko.md:945">
P2: Trae cache path documentation hardcodes inconsistent paths rather than using config-root-relative locations</violation>
</file>
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
a4e2e48 to
465c66c
Compare
|
@cubic-dev-ai re-review please |
@itling I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
2 issues found across 16 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="README.md">
<violation number="1" location="README.md:525">
P2: Trae documentation hardcodes `~/.config/tokscale/trae-cache/` as the definitive cache path, but the Rust code resolves it via `get_config_dir().join("trae-cache")` which honors `TOKSCALE_CONFIG_DIR`, `XDG_CONFIG_HOME`, and platform defaults. The Windows path in the Session Data Locations table (`%USERPROFILE%\.config\tokscale\trae-cache\`) is factually incorrect: on Windows `get_config_dir()` uses `dirs::config_dir()` (`%APPDATA%\tokscale`), not `%USERPROFILE%\.config\tokscale`. Docs should describe the default alongside the override behavior.</violation>
</file>
<file name="crates/tokscale-cli/src/trae.rs">
<violation number="1" location="crates/tokscale-cli/src/trae.rs:316">
P2: Error message uses `variant.client_str()` for `--variant` flag instead of `variant.cli_arg()`, producing invalid CLI guidance like `--variant trae-solo` instead of `--variant solo`</violation>
</file>
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
| tokscale trae logout --variant solo | ||
| ``` | ||
|
|
||
| **Cache location**: `~/.config/tokscale/trae-cache/` |
There was a problem hiding this comment.
P2: Trae documentation hardcodes ~/.config/tokscale/trae-cache/ as the definitive cache path, but the Rust code resolves it via get_config_dir().join("trae-cache") which honors TOKSCALE_CONFIG_DIR, XDG_CONFIG_HOME, and platform defaults. The Windows path in the Session Data Locations table (%USERPROFILE%\.config\tokscale\trae-cache\) is factually incorrect: on Windows get_config_dir() uses dirs::config_dir() (%APPDATA%\tokscale), not %USERPROFILE%\.config\tokscale. Docs should describe the default alongside the override behavior.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At README.md, line 525:
<comment>Trae documentation hardcodes `~/.config/tokscale/trae-cache/` as the definitive cache path, but the Rust code resolves it via `get_config_dir().join("trae-cache")` which honors `TOKSCALE_CONFIG_DIR`, `XDG_CONFIG_HOME`, and platform defaults. The Windows path in the Session Data Locations table (`%USERPROFILE%\.config\tokscale\trae-cache\`) is factually incorrect: on Windows `get_config_dir()` uses `dirs::config_dir()` (`%APPDATA%\tokscale`), not `%USERPROFILE%\.config\tokscale`. Docs should describe the default alongside the override behavior.</comment>
<file context>
@@ -489,6 +491,43 @@ tokscale antigravity purge-cache
+tokscale trae logout --variant solo
+```
+
+**Cache location**: `~/.config/tokscale/trae-cache/`
+
+**How it works**: tokscale either decrypts the desktop client's `iCubeAuthInfo://*` blob (`globalStorage/storage.json`) to recover a JWT, or accepts one pasted via `--manual`. It then calls `POST /trae/api/v1/pay/query_user_usage_group_by_session` paginated and stores the raw JSON. Run sync before reports if you want the freshest Trae data.
</file context>
| **Cache location**: `~/.config/tokscale/trae-cache/` | |
| **Cache location**: `<config_dir>/trae-cache/` (default `~/.config/tokscale/trae-cache/` on Linux/macOS and `%APPDATA%\tokscale\trae-cache\` on Windows; overridden by `TOKSCALE_CONFIG_DIR` or `XDG_CONFIG_HOME`). |
| // 4. Everything failed. | ||
| Err(anyhow::anyhow!( | ||
| "Could not obtain a Trae {} access token. Run `tokscale trae login --manual --variant {}` to paste a JWT manually.", | ||
| variant.client_str(), |
There was a problem hiding this comment.
P2: Error message uses variant.client_str() for --variant flag instead of variant.cli_arg(), producing invalid CLI guidance like --variant trae-solo instead of --variant solo
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At crates/tokscale-cli/src/trae.rs, line 316:
<comment>Error message uses `variant.client_str()` for `--variant` flag instead of `variant.cli_arg()`, producing invalid CLI guidance like `--variant trae-solo` instead of `--variant solo`</comment>
<file context>
@@ -0,0 +1,1398 @@
+ // 4. Everything failed.
+ Err(anyhow::anyhow!(
+ "Could not obtain a Trae {} access token. Run `tokscale trae login --manual --variant {}` to paste a JWT manually.",
+ variant.client_str(),
+ variant.client_str()
+ ))
</file context>
Add support for ByteDance's Trae IDE and Trae Solo (international editions). Both desktop clients share the same account-level usage data; tokscale auto-discovers credentials from whichever is installed and reports them as a single `trae` client. - `tokscale trae login/logout/status/sync` CLI subcommand with `--variant solo|ide` - Auth: decrypts `iCubeAuthInfo` from the desktop client's `globalStorage/storage.json` (AES-128-CBC port of `byteCrypto.js`) with a `--manual` JWT fallback for headless environments - Sync: paginated POST against `query_user_usage_group_by_session`, persisted under `~/.config/tokscale/trae-cache/` with a manifest + sync lock for crash-safety - Parser uses Trae's reported `dollar_float`, so pricing lookup is skipped; auto-mode sessions bucket under `trae-auto` - Per `--client/-c`-only convention, only a hidden legacy `--trae` flag is added; the user-facing surface is `--client trae` - README + localized variants document the new client, command set, and Windows path China editions (`trae.com.cn`) are intentionally not supported — the CN backend does not expose a session-level usage query endpoint. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
465c66c to
d8479ac
Compare
|
@cubic-dev-ai re-review please |
@itling I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
No issues found across 16 files
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
junhoyeo
left a comment
There was a problem hiding this comment.
LGTM — auth model is sound and well-tested, opt-in client. Follow-up: README note that Trae cost figures are vendor-reported, not tokscale-priced.
|
@itling this has been merged to v3.0.0: https://github.com/junhoyeo/tokscale/releases/tag/v3.0.0 thanks for the contribution! |
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
traeclient.What's New
tokscale trae login | logout | status | sync(with--variant solo|ideand a--manualJWT fallback for headless environments).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.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.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.y) and is selectable via--client trae.README.mdand the three localized variants document the new client, the Windows path, and the command set.Test Plan
cargo fmt --all --checkcleancargo clippy --workspace --all-features -- -D warningscleancargo test --workspace --all-features— 763 passed (675 core + 88 CLI), 0 failedscripts/check-version-coherence.sh—2.1.1consistent across workspacetokscale trae login(auto),tokscale trae sync,tokscale --client traereports the synced totalsNotes
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.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
traeclient. You can log in, sync account-level session usage from the official API, and see totals in the TUI and reports.New Features
traeclient for Trae IDE and Trae Solo (international; CN not supported).tokscale trae login|logout|status|syncwith--variant solo|ideand--manual; select via--client trae(hidden legacy--traeflag kept).iCubeAuthInfofrom ElectronglobalStorage/storage.json; caches credentials and auto-refreshes.~/.config/tokscale/trae-cache/with a manifest, de-dup bysession_id, and a per-cache sync lock.dollar_floattotals (no pricing lookup); auto-mode bucketed astrae-auto; shown in TUI (hotkeyy).--client trae.Dependencies
aes,cbc, andbase64for credential decryption.Written for commit d8479ac. Summary will update on new commits.