From 68b4bccad2223ff3b8dc2d08fcd79f173e318352 Mon Sep 17 00:00:00 2001 From: makoMakoGo <48956204+makoMakoGo@users.noreply.github.com> Date: Sun, 7 Jun 2026 05:06:28 +0800 Subject: [PATCH 1/3] refactor: remove synthetic source --- README.ja.md | 19 +- README.ko.md | 19 +- README.md | 21 +- README.zh-cn.md | 19 +- crates/tokscale-cli/src/commands/wrapped.rs | 2 - crates/tokscale-cli/src/main.rs | 156 ++------ crates/tokscale-cli/src/tui/app.rs | 27 +- crates/tokscale-cli/src/tui/cache.rs | 139 ++----- crates/tokscale-cli/src/tui/data/mod.rs | 28 +- crates/tokscale-cli/src/tui/mod.rs | 14 +- crates/tokscale-cli/src/tui/settings.rs | 8 +- .../src/tui/ui/dialog/source_picker.rs | 41 +- crates/tokscale-core/src/lib.rs | 200 ++-------- crates/tokscale-core/src/pricing/aliases.rs | 2 +- crates/tokscale-core/src/pricing/custom.rs | 22 +- crates/tokscale-core/src/scanner.rs | 39 +- crates/tokscale-core/src/sessions/mod.rs | 1 - .../tokscale-core/src/sessions/synthetic.rs | 365 ------------------ .../frontend/src/components/SourceLogo.tsx | 2 - packages/frontend/src/lib/constants.ts | 3 - packages/frontend/src/lib/types.ts | 1 - 21 files changed, 180 insertions(+), 948 deletions(-) delete mode 100644 crates/tokscale-core/src/sessions/synthetic.rs diff --git a/README.ja.md b/README.ja.md index bbcd84e2e..19c4f72ca 100644 --- a/README.ja.md +++ b/README.ja.md @@ -79,7 +79,6 @@ | Trae | [Trae IDE](https://www.trae.ai/) / [Trae Solo](https://www.trae.ai/solo)(国際版) | `tokscale trae sync` で `~/.config/tokscale/trae-cache/sessions/*.json` にキャッシュ(公式 API のアカウント単位使用量) | ✅ 対応 | | Zed Agent | [Zed Agent](https://zed.dev/docs/ai/agent-panel) | `~/.local/share/zed/threads/threads.db`(macOS: `~/Library/Application Support/Zed/threads/threads.db`; Windows: `%LOCALAPPDATA%/Zed/threads/threads.db`; ホスティング済み Zed モデル専用、外部 ACP エージェントは対象外) | ✅ 対応 | | Kiro | Kiro | `~/.kiro/sessions/cli/*.json`(+ `*.jsonl`)と `~/.local/share/kiro-cli/data.sqlite3`(macOS: `~/Library/Application Support/kiro-cli/data.sqlite3`) | ✅ 対応 | -| Synthetic | [Synthetic](https://synthetic.new/) | `hf:`モデルや`synthetic`プロバイダを検出して他ソースから再帰属(+ [Octofriend](https://github.com/synthetic-lab/octofriend): `~/.local/share/octofriend/sqlite.db`) | ✅ 対応 | [🚅 LiteLLMの価格データ](https://github.com/BerriAI/litellm)を使用してリアルタイム価格計算を提供し、階層型価格モデルとキャッシュトークン割引をサポートしています。 @@ -146,7 +145,7 @@ AI支援開発の時代において、**トークンは新しいエネルギー* - 9色テーマのGitHubスタイル貢献グラフ - リアルタイムフィルタリングとソート - ゼロフリッカーレンダリング -- **マルチプラットフォームサポート** - OpenCode、Claude Code、Codex CLI、Copilot CLI、Cursor IDE、Gemini CLI、Amp、Codebuff、Droid、OpenClaw、Hermes Agent、Pi、OMP、Kimi CLI、Qwen CLI、Roo Code、Kilo、Mux、Kilo CLI、Crush、Goose、Antigravity、Zed、Kiro、Trae、Synthetic全体の使用量追跡 +- **マルチプラットフォームサポート** - OpenCode、Claude Code、Codex CLI、Copilot CLI、Cursor IDE、Gemini CLI、Amp、Codebuff、Droid、OpenClaw、Hermes Agent、Pi、OMP、Kimi CLI、Qwen CLI、Roo Code、Kilo、Mux、Kilo CLI、Crush、Goose、Antigravity、Zed、Kiro、Trae 全体の使用量追跡 - **リアルタイム価格** - 1時間ディスクキャッシュ付きでLiteLLMから現在の価格を取得;OpenRouter自動フォールバックと新規モデル向けCursor価格サポート - **詳細な内訳** - 入力、出力、キャッシュ読み書き、推論トークン追跡 - **ネイティブRustコア** - 10倍高速な処理のため、すべての解析と集計をRustで実行 @@ -318,14 +317,11 @@ tokscale -c opencode -c claude # Cursor IDE は事前に `tokscale cursor login` が必要 tokscale --client cursor -# Synthetic(synthetic.new)は他のエージェントセッションから検出されます -tokscale --client synthetic - # 他のフィルターと組み合わせ tokscale --client opencode,claude --week --json ``` -利用可能な値: `opencode`, `claude`, `codex`, `copilot`, `gemini`, `cursor`, `amp`, `codebuff`, `droid`, `openclaw`, `hermes`, `pi`, `omp`, `kimi`, `qwen`, `roocode`, `kilocode`, `kilo`, `mux`, `crush`, `goose`, `antigravity`, `zed`, `kiro`, `trae`, `synthetic`。 +利用可能な値: `opencode`, `claude`, `codex`, `copilot`, `gemini`, `cursor`, `amp`, `codebuff`, `droid`, `openclaw`, `hermes`, `pi`, `omp`, `kimi`, `qwen`, `roocode`, `kilocode`, `kilo`, `mux`, `crush`, `goose`, `antigravity`, `zed`, `kiro`, `trae`。 > **非推奨のお知らせ**: 既存の単一クライアントフラグ(`--opencode`、`--claude`、`--codex` など)は後方互換性のため引き続き動作しますが、`--help` から非表示となり、次のメジャーリリースで削除予定です。可能な限り `--client` への移行を推奨します。インタラクティブな端末で旧フラグを使用すると 1 行の警告が表示されます。 @@ -537,7 +533,7 @@ Tokscaleは設定を`~/.config/tokscale/settings.json`に保存します: | `autoRefreshEnabled` | boolean | `false` | TUIの自動更新を有効化 | | `autoRefreshMs` | number | `60000` | 自動更新間隔(30000-3600000ms) | | `nativeTimeoutMs` | number | `300000` | ネイティブサブプロセス処理の最大時間(5000-3600000ms) | -| `defaultClients` | string[] | `[]` | `--client/-c` フラグを渡さない場合に適用されるクライアントフィルター。`--client` と同じ ID を受け付けます(例: `["opencode", "claude", "synthetic"]`)。未知の ID は無視されます。CLI フラグが指定されるとこのリストは完全に無視されます — マージはしません。 | +| `defaultClients` | string[] | `[]` | `--client/-c` フラグを渡さない場合に適用されるクライアントフィルター。`--client` と同じ ID を受け付けます(例: `["opencode", "claude", "zed"]`)。未知の ID は無視されます。CLI フラグが指定されるとこのリストは完全に無視されます — マージはしません。 | | `light.writeCache` | boolean | `false` | `true` のとき、`tokscale --light` はレンダリング直後に TUI キャッシュを原子的に上書きします。CLI フラグ `--write-cache` / `--no-write-cache` が実行ごとに優先されます。 | | `minutelyTabEnabled` | boolean | `false` | TUI に分単位の Minutely タブを表示し、データ読み込み時に分単位の集計を実行します。分単位の粒度はほとんどのユーザーにとってニッチな診断ビューであり、大規模データセットでは分単位のバケット処理に無視できないコストがかかるため、既定では無効になっています。 | @@ -657,7 +653,7 @@ tokscale sources --json - **インタラクティブツールチップ**: ホバーで詳細な日別内訳を表示 - **日別内訳パネル**: クリックでソース別、モデル別の詳細を確認 - **年別フィルタリング**: 年間を移動 -- **ソースフィルタリング**: プラットフォーム別フィルター(OpenCode、Claude、Codex、Copilot、Cursor、Gemini、Amp、Codebuff、Droid、OpenClaw、Hermes Agent、Pi、OMP、Kimi、Qwen、Roo Code、Kilo、Mux、Kilo CLI、Crush、Goose、Antigravity、Zed、Kiro、Trae、Synthetic) +- **ソースフィルタリング**: プラットフォーム別フィルター(OpenCode、Claude、Codex、Copilot、Cursor、Gemini、Amp、Codebuff、Droid、OpenClaw、Hermes Agent、Pi、OMP、Kimi、Qwen、Roo Code、Kilo、Mux、Kilo CLI、Crush、Goose、Antigravity、Zed、Kiro、Trae) - **統計パネル**: 総コスト、トークン、活動日数、連続記録 - **FOUC防止**: Reactハイドレーション前にテーマを適用(フラッシュなし) @@ -969,7 +965,6 @@ AIコーディングツールはクロスプラットフォームの場所にセ | Goose | `~/.local/share/goose/sessions/` (+ macOS Application Support、レガシー Block パス) | `%USERPROFILE%\.local\share\goose\sessions\` | `GOOSE_PATH_ROOT` 環境変数で設定可能 | | Antigravity | `~/.config/tokscale/antigravity-cache/sessions/` | — | `tokscale antigravity sync` は現在 macOS / Linux でのみサポート | | Trae | `~/.config/tokscale/trae-cache/sessions/` | `%APPDATA%\tokscale\trae-cache\sessions\` | `tokscale trae sync` で 1 回だけ同期。インストール済みの Trae IDE または Trae Solo デスクトップアプリから資格情報を自動検出 | -| Synthetic | 他ソースから再帰属 | 他ソースから再帰属 | `hf:`モデル + `synthetic`プロバイダを検出 | > **注**: Windowsでは`~`は`%USERPROFILE%`に展開されます(例:`C:\Users\ユーザー名`)。これらのツールは`%APPDATA%`のようなWindowsネイティブパスではなく、クロスプラットフォームの一貫性のためにUnixスタイルのパス(`.local/share`など)を意図的に使用しています。 @@ -1293,12 +1288,6 @@ Goose はセッションごとの使用量を SQLite の `sessions.db` に保存 Codebuff(旧 Manicode)はチャットごとに JSON ファイルを書き出します。Tokscale は `metadata.usage`、`metadata.codebuff.usage`、および run-state の `messageHistory[*].providerOptions` フォールバックからトークン使用量を解析し、部分的に新しいエントリが実トークン数を持つ古いエントリを覆い隠さないように履歴を逆順に走査します。メッセージごとのタイムスタンプが欠けている場合は chat-id ディレクトリ名、最後にファイルの mtime にフォールバックします。 -### Synthetic (synthetic.new) - -Synthetic は他ソースのメッセージを後処理で再帰属します。`hf:`プレフィックスのモデル ID または `synthetic` / `glhf` / `octofriend` プロバイダを検出した場合、ソースを `synthetic` として扱います。 - -また `~/.local/share/octofriend/sqlite.db` を検出し、トークン情報を持つレコードを取り込みます。 - ## 価格 Tokscaleは[LiteLLMの価格データベース](https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json)からリアルタイム価格を取得します。 diff --git a/README.ko.md b/README.ko.md index 203b6cb4e..a834cf77e 100644 --- a/README.ko.md +++ b/README.ko.md @@ -79,7 +79,6 @@ | Trae | [Trae IDE](https://www.trae.ai/) / [Trae Solo](https://www.trae.ai/solo) (국제판) | `tokscale trae sync`로 `~/.config/tokscale/trae-cache/sessions/*.json`에 캐싱 (공식 API의 계정 단위 사용량) | ✅ 지원 | | Zed Agent | [Zed Agent](https://zed.dev/docs/ai/agent-panel) | `~/.local/share/zed/threads/threads.db` (macOS: `~/Library/Application Support/Zed/threads/threads.db`; Windows: `%LOCALAPPDATA%/Zed/threads/threads.db`; 호스팅된 Zed 모델 전용, 외부 ACP 에이전트 제외) | ✅ 지원 | | Kiro | Kiro | `~/.kiro/sessions/cli/*.json` (+ `*.jsonl`) 및 `~/.local/share/kiro-cli/data.sqlite3` (macOS: `~/Library/Application Support/kiro-cli/data.sqlite3`) | ✅ 지원 | -| Synthetic | [Synthetic](https://synthetic.new/) | `hf:` 모델/`synthetic` provider 감지로 다른 소스에서 재귀속 (+ [Octofriend](https://github.com/synthetic-lab/octofriend): `~/.local/share/octofriend/sqlite.db`) | ✅ 지원 | [🚅 LiteLLM의 가격 데이터](https://github.com/BerriAI/litellm)를 사용해 **실시간 비용 계산**을 제공합니다. 구간별 가격 모델(대용량 컨텍스트 등)과 **캐시 토큰 할인**도 지원합니다. @@ -146,7 +145,7 @@ AI 지원 개발 시대에 **토큰은 새로운 에너지**입니다. 토큰은 - 9가지 테마의 GitHub 스타일 기여 그래프 - 실시간 필터링 및 정렬 - 깜빡임 없는 렌더링 -- **멀티 플랫폼 지원** - OpenCode, Claude Code, Codex CLI, Copilot CLI, Cursor IDE, Gemini CLI, Amp, Codebuff, Droid, OpenClaw, Hermes Agent, Pi, OMP, Kimi CLI, Qwen CLI, Roo Code, Kilo, Mux, Kilo CLI, Crush, Goose, Antigravity, Zed, Kiro, Trae, Synthetic 사용량 통합 추적 +- **멀티 플랫폼 지원** - OpenCode, Claude Code, Codex CLI, Copilot CLI, Cursor IDE, Gemini CLI, Amp, Codebuff, Droid, OpenClaw, Hermes Agent, Pi, OMP, Kimi CLI, Qwen CLI, Roo Code, Kilo, Mux, Kilo CLI, Crush, Goose, Antigravity, Zed, Kiro, Trae 사용량 통합 추적 - **실시간 가격 반영** - LiteLLM에서 최신 가격을 가져와(디스크 캐시 1시간) 비용 계산; OpenRouter 자동 폴백 및 신규 모델용 Cursor 가격 지원 - **상세 분석** - 입력, 출력, 캐시 읽기/쓰기, 추론 토큰까지 추적 - **네이티브 Rust 코어** - 모든 파싱과 집계를 Rust로 처리해 최대 10배 빠른 성능 @@ -317,14 +316,11 @@ tokscale -c opencode -c claude # Cursor IDE는 사전에 `tokscale cursor login` 필요 tokscale --client cursor -# Synthetic (synthetic.new) 은 다른 에이전트 세션에서 검출됨 -tokscale --client synthetic - # 다른 필터와 조합 tokscale --client opencode,claude --week --json ``` -가능한 값: `opencode`, `claude`, `codex`, `copilot`, `gemini`, `cursor`, `amp`, `codebuff`, `droid`, `openclaw`, `hermes`, `pi`, `omp`, `kimi`, `qwen`, `roocode`, `kilocode`, `kilo`, `mux`, `crush`, `goose`, `antigravity`, `zed`, `kiro`, `trae`, `synthetic`. +가능한 값: `opencode`, `claude`, `codex`, `copilot`, `gemini`, `cursor`, `amp`, `codebuff`, `droid`, `openclaw`, `hermes`, `pi`, `omp`, `kimi`, `qwen`, `roocode`, `kilocode`, `kilo`, `mux`, `crush`, `goose`, `antigravity`, `zed`, `kiro`, `trae`. > **Deprecation 안내**: 기존 단일 클라이언트 플래그 (`--opencode`, `--claude`, `--codex` 등)는 하위 호환성을 위해 여전히 동작하지만 `--help`에서 숨겨졌으며 다음 메이저 릴리스에서 제거됩니다. 가능한 한 `--client`로 마이그레이션하세요. 인터랙티브 터미널에서 레거시 플래그를 사용하면 한 줄 경고가 출력됩니다. @@ -536,7 +532,7 @@ Tokscale은 설정을 `~/.config/tokscale/settings.json`에 저장합니다: | `autoRefreshEnabled` | boolean | `false` | TUI 자동 새로고침 활성화 | | `autoRefreshMs` | number | `60000` | 자동 새로고침 간격 (30000-3600000ms) | | `nativeTimeoutMs` | number | `300000` | 네이티브 서브프로세스 처리 최대 시간 (5000-3600000ms) | -| `defaultClients` | string[] | `[]` | `--client/-c` 플래그를 전달하지 않을 때 적용되는 기본 클라이언트 필터. `--client`와 동일한 ID를 받습니다 (예: `["opencode", "claude", "synthetic"]`). 알 수 없는 ID는 자동으로 무시됩니다. CLI 플래그가 있으면 이 목록은 완전히 무시됩니다 — 병합되지 않습니다. | +| `defaultClients` | string[] | `[]` | `--client/-c` 플래그를 전달하지 않을 때 적용되는 기본 클라이언트 필터. `--client`와 동일한 ID를 받습니다 (예: `["opencode", "claude", "zed"]`). 알 수 없는 ID는 자동으로 무시됩니다. CLI 플래그가 있으면 이 목록은 완전히 무시됩니다 — 병합되지 않습니다. | | `light.writeCache` | boolean | `false` | `true`이면 `tokscale --light`가 렌더링 직후 TUI 캐시를 원자적으로 덮어씁니다. CLI 플래그 `--write-cache` / `--no-write-cache`가 실행별로 우선합니다. | | `minutelyTabEnabled` | boolean | `false` | TUI에 분 단위 Minutely 탭을 표시하고 데이터 로딩 중에 분 단위 집계를 수행합니다. 대부분의 사용자에게 분 단위 세분화는 틈새/진단 뷰이며, 대규모 데이터셋에서는 분 단위 버케팅에 무시할 수 없는 비용이 들기 때문에 기본적으로 비활성화되어 있습니다. | @@ -656,7 +652,7 @@ tokscale sources --json - **인터랙티브 툴팁**: 호버 시 상세 일별 분석 표시 - **일별 분석 패널**: 클릭하여 소스별, 모델별 세부사항 확인 - **연도 필터링**: 연도 간 탐색 -- **소스 필터링**: 플랫폼별 필터 (OpenCode, Claude, Codex, Copilot, Cursor, Gemini, Amp, Codebuff, Droid, OpenClaw, Hermes Agent, Pi, OMP, Kimi, Qwen, Roo Code, Kilo, Mux, Kilo CLI, Crush, Goose, Antigravity, Zed, Kiro, Trae, Synthetic) +- **소스 필터링**: 플랫폼별 필터 (OpenCode, Claude, Codex, Copilot, Cursor, Gemini, Amp, Codebuff, Droid, OpenClaw, Hermes Agent, Pi, OMP, Kimi, Qwen, Roo Code, Kilo, Mux, Kilo CLI, Crush, Goose, Antigravity, Zed, Kiro, Trae) - **통계 패널**: 총 비용, 토큰, 활동 일수, 연속 기록 - **FOUC 방지**: React 하이드레이션 전 테마 적용 (깜빡임 없음) @@ -968,7 +964,6 @@ AI 코딩 도구들은 크로스 플랫폼 위치에 세션 데이터를 저장 | Goose | `~/.local/share/goose/sessions/` (+ macOS Application Support, 레거시 Block 경로) | `%USERPROFILE%\.local\share\goose\sessions\` | `GOOSE_PATH_ROOT` 환경변수로 설정 가능 | | Antigravity | `~/.config/tokscale/antigravity-cache/sessions/` | — | `tokscale antigravity sync`는 현재 macOS/Linux에서만 지원 | | Trae | `~/.config/tokscale/trae-cache/sessions/` | `%APPDATA%\tokscale\trae-cache\sessions\` | `tokscale trae sync`로 한 번 동기화; 설치된 Trae IDE 또는 Trae Solo 데스크톱 앱에서 자격 증명 자동 발견 | -| Synthetic | 다른 소스에서 재귀속 | 다른 소스에서 재귀속 | `hf:` 모델 접두사 + `synthetic` provider 감지 | > **참고**: Windows에서 `~`는 `%USERPROFILE%`로 확장됩니다 (예: `C:\Users\사용자이름`). 이러한 도구들은 `%APPDATA%`와 같은 Windows 기본 경로 대신 크로스 플랫폼 일관성을 위해 의도적으로 Unix 스타일 경로(`.local/share` 등)를 사용합니다. @@ -1292,12 +1287,6 @@ Goose는 세션별 사용량을 SQLite `sessions.db`에 저장합니다. Tokscal Codebuff(이전 Manicode)는 채팅별 JSON 파일을 저장합니다. Tokscale은 `metadata.usage`, `metadata.codebuff.usage` 및 run-state의 `messageHistory[*].providerOptions` 폴백에서 토큰 사용량을 파싱하며, 부분적으로 갱신된 최신 항목이 실제 토큰 카운트를 가진 이전 항목을 가리지 않도록 히스토리를 역순으로 순회합니다. 메시지별 타임스탬프가 없을 때는 chat-id 디렉토리 이름, 마지막으로 파일 mtime으로 폴백합니다. -### Synthetic (synthetic.new) - -Synthetic은 기존 에이전트 세션을 후처리하여 재귀속합니다. `hf:` 접두사 모델 ID 또는 `synthetic` / `glhf` / `octofriend` provider를 감지하면 해당 메시지를 `synthetic` 소스로 처리합니다. - -또한 `~/.local/share/octofriend/sqlite.db`를 감지해 토큰 정보가 있는 레코드를 파싱합니다. - ## 가격 Tokscale은 [LiteLLM의 가격 데이터베이스](https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json)에서 실시간 가격을 가져옵니다. diff --git a/README.md b/README.md index c0be23316..b4e93e54f 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,6 @@ | Warp/Oz | [Warp](https://www.warp.dev/) / Oz | Cached via `tokscale warp sync` to `~/.config/tokscale/warp-cache/usage.json` (aggregate requests and spend only; no token transcripts) | ✅ Yes | | Zed Agent | [Zed Agent](https://zed.dev/docs/ai/agent-panel) | `~/.local/share/zed/threads/threads.db` (macOS: `~/Library/Application Support/Zed/threads/threads.db`; Windows: `%LOCALAPPDATA%/Zed/threads/threads.db`; hosted Zed models only, not external ACP agents) | ✅ Yes | | Kiro | Kiro | `~/.kiro/sessions/cli/*.json` (+ `*.jsonl`) and `~/.local/share/kiro-cli/data.sqlite3` (macOS: `~/Library/Application Support/kiro-cli/data.sqlite3`) | ✅ Yes | -| Synthetic | [Synthetic](https://synthetic.new/) | Re-attributed from other sources via `hf:` model prefix or `synthetic` provider (+ [Octofriend](https://github.com/synthetic-lab/octofriend): `~/.local/share/octofriend/sqlite.db`) | ✅ Yes | Get real-time pricing calculations using [🚅 LiteLLM's pricing data](https://github.com/BerriAI/litellm), with support for tiered pricing models and cache token discounts. @@ -150,7 +149,7 @@ In the age of AI-assisted development, **tokens are the new energy**. They power - GitHub-style contribution graph with 9 color themes - Real-time filtering and sorting - Zero flicker rendering -- **Multi-platform support** - Track usage across OpenCode, Claude Code, Codex CLI, Copilot CLI, Cursor IDE, Gemini CLI, Amp, Codebuff, Droid, OpenClaw, Hermes Agent, Pi, OMP, Kimi CLI, Qwen CLI, Roo Code, Kilo, Mux, Kilo CLI, Crush, Goose, Antigravity, Zed, Kiro, Trae, and Synthetic +- **Multi-platform support** - Track usage across OpenCode, Claude Code, Codex CLI, Copilot CLI, Cursor IDE, Gemini CLI, Amp, Codebuff, Droid, OpenClaw, Hermes Agent, Pi, OMP, Kimi CLI, Qwen CLI, Roo Code, Kilo, Mux, Kilo CLI, Crush, Goose, Antigravity, Zed, Kiro, and Trae - **Real-time pricing** - Fetches current pricing from LiteLLM with 1-hour disk cache; automatic OpenRouter fallback and Cursor model pricing for newly released models - **Detailed breakdowns** - Input, output, cache read/write, and reasoning token tracking - **Native Rust core** - All parsing and aggregation done in Rust for 10x faster processing @@ -353,14 +352,11 @@ tokscale -c opencode -c claude # Cursor IDE uses Tokscale's API cache; run login + sync --json first tokscale --client cursor -# Synthetic (synthetic.new) is detected from other agent sessions -tokscale --client synthetic - # Combine with other filters tokscale --client opencode,claude --week --json ``` -Possible values: `opencode`, `claude`, `codex`, `copilot`, `gemini`, `cursor`, `amp`, `codebuff`, `droid`, `openclaw`, `hermes`, `pi`, `omp`, `kimi`, `qwen`, `roocode`, `kilocode`, `kilo`, `mux`, `crush`, `goose`, `antigravity`, `zed`, `kiro`, `trae`, `synthetic`. +Possible values: `opencode`, `claude`, `codex`, `copilot`, `gemini`, `cursor`, `amp`, `codebuff`, `droid`, `openclaw`, `hermes`, `pi`, `omp`, `kimi`, `qwen`, `roocode`, `kilocode`, `kilo`, `mux`, `crush`, `goose`, `antigravity`, `zed`, `kiro`, `trae`. > **Deprecation notice**: The legacy single-client flags (`--opencode`, `--claude`, `--codex`, etc.) still work for backward compatibility but are hidden from `--help` and will be removed in the next major release. Migrate to `--client` whenever possible. Running tokscale in an interactive terminal will print a one-line warning when a legacy flag is used. @@ -449,7 +445,7 @@ Create `custom-pricing.json` in Tokscale's config directory (`~/.config/tokscale Override prices are entered in dollars per million tokens, matching how most API providers publish pricing; Tokscale converts them to per-token rates internally. At least one of `input_cost_per_million_tokens` or `output_cost_per_million_tokens` must be present and positive, and cache-read/cache-creation fields are optional. LiteLLM-style per-token field names such as `input_cost_per_token`, `output_cost_per_token`, and `cache_read_input_token_cost` are also accepted for copy/paste compatibility, but the per-million names are the recommended user-facing form. To omit a tier or cache price, leave the field out; negative or non-finite values are treated as invalid and the whole model entry is skipped so typos do not silently alter accounting. Optional `source` and `notes` fields are ignored by Tokscale and can be used for your own bookkeeping. -Overrides are exact-only and case-insensitive. Tokscale checks the raw model ID first, then the existing synthetic `/models/` normalization, then falls through to LiteLLM, OpenRouter, Cursor pricing, and fuzzy matching if no override matches. Raw exact matches beat normalized exact matches, so `accounts/fireworks/routers/kimi-k2p6-turbo` can override one gateway-specific model while `kimi-k2p6-turbo` can cover normalized `/models/` paths. Overrides are loaded once at startup; restart the command after editing the file. This is the recommended local fix for wrong-model pricing bugs while waiting on upstream LiteLLM pricing updates. +Overrides are exact-only and case-insensitive. Tokscale checks the raw model ID first, then gateway `/models/` path normalization, then falls through to LiteLLM, OpenRouter, Cursor pricing, and fuzzy matching if no override matches. Raw exact matches beat normalized exact matches, so `accounts/fireworks/routers/kimi-k2p6-turbo` can override one gateway-specific model while `kimi-k2p6-turbo` can cover normalized `/models/` paths. Overrides are loaded once at startup; restart the command after editing the file. This is the recommended local fix for wrong-model pricing bugs while waiting on upstream LiteLLM pricing updates. **Provider Preference:** @@ -723,7 +719,7 @@ Tokscale stores settings in `~/.config/tokscale/settings.json`: | `autoRefreshEnabled` | boolean | `false` | Enable auto-refresh in TUI | | `autoRefreshMs` | number | `60000` | Auto-refresh interval (30000-3600000ms) | | `nativeTimeoutMs` | number | `300000` | Maximum time for native subprocess processing (5000-3600000ms) | -| `defaultClients` | string[] | `[]` | Client filter applied when no `--client/-c` flag is passed. Accepts the same ids as `--client` (e.g. `["opencode", "claude", "synthetic"]`). Unknown ids are silently dropped. CLI flags always override this list completely — no merging. | +| `defaultClients` | string[] | `[]` | Client filter applied when no `--client/-c` flag is passed. Accepts the same ids as `--client` (e.g. `["opencode", "claude", "zed"]`). Unknown ids are silently dropped. CLI flags always override this list completely — no merging. | | `light.writeCache` | boolean | `false` | When true, `tokscale --light` overwrites the TUI cache atomically after rendering. CLI flags `--write-cache` / `--no-write-cache` override per-invocation. | | `usageTabEnabled` | boolean | `false` | Show the subscription quota Usage tab in the TUI. Default-off because local token usage is the primary TUI workflow and subscription lookups are optional. | | `minutelyTabEnabled` | boolean | `false` | Show the per-minute Minutely tab in the TUI and aggregate per-minute usage during data loading. Default-off because minute-granularity is a niche/diagnostic view for most users and the per-minute bucketing has a non-trivial cost on large datasets. | @@ -857,7 +853,7 @@ The frontend provides a GitHub-style contribution graph visualization: - **Interactive tooltips**: Hover for detailed daily breakdowns - **Day breakdown panel**: Click to see per-source and per-model details - **Year filtering**: Navigate between years -- **Source filtering**: Filter by platform (OpenCode, Claude, Codex, Copilot, Cursor, Gemini, Amp, Codebuff, Droid, OpenClaw, Hermes Agent, Pi, OMP, Kimi, Qwen, Roo Code, Kilo, Mux, Kilo CLI, Crush, Goose, Antigravity, Zed, Kiro, Trae, Synthetic) +- **Source filtering**: Filter by platform (OpenCode, Claude, Codex, Copilot, Cursor, Gemini, Amp, Codebuff, Droid, OpenClaw, Hermes Agent, Pi, OMP, Kimi, Qwen, Roo Code, Kilo, Mux, Kilo CLI, Crush, Goose, Antigravity, Zed, Kiro, Trae) - **Stats panel**: Total cost, tokens, active days, streaks - **FOUC prevention**: Theme applied before React hydrates (no flash) @@ -1188,7 +1184,6 @@ AI coding tools store their session data in cross-platform locations. Most tools | Kiro | `~/.kiro/sessions/cli/` and `~/.local/share/kiro-cli/data.sqlite3` | `%USERPROFILE%\.kiro\sessions\cli\` and `%USERPROFILE%\.local\share\kiro-cli\data.sqlite3` | Parses Kiro session files plus the Kiro CLI SQLite database when present | | Trae | `~/.config/tokscale/trae-cache/sessions/` | `%APPDATA%\tokscale\trae-cache\sessions\` | Synced once via `tokscale trae sync`; credentials are auto-discovered from any installed Trae IDE or Trae Solo desktop app | | Warp/Oz | `~/.config/tokscale/warp-cache/usage.json` | `%APPDATA%\tokscale\warp-cache\usage.json` | Synced via `tokscale warp sync`; aggregate requests and spend only, no token transcripts | -| Synthetic | Re-attributed from other sources | Re-attributed from other sources | Detects `hf:` model prefix + `synthetic` provider | > **Note**: On Windows, `~` expands to `%USERPROFILE%` (e.g., `C:\Users\YourName`). These tools intentionally use Unix-style paths (like `.local/share`) even on Windows for cross-platform consistency, rather than Windows-native paths like `%APPDATA%`. @@ -1561,12 +1556,6 @@ Location: `~/.config/manicode/projects//chats//chat-messages.js Codebuff (formerly Manicode) writes per-chat JSON files. Tokscale parses token usage from `metadata.usage`, `metadata.codebuff.usage`, and the run-state `messageHistory[*].providerOptions` fallback, walking the history in reverse so partial newer entries don't shadow earlier entries that carry the actual token counts. Per-message timestamps fall back to the chat-id directory name and finally to file mtime when missing. -### Synthetic (synthetic.new) - -Synthetic usage is detected via post-processing of existing agent session files. Messages are re-attributed to `synthetic` when they use `hf:` model IDs or synthetic providers (`synthetic`, `glhf`, `octofriend`). - -Tokscale also checks Octofriend SQLite at `~/.local/share/octofriend/sqlite.db` and parses token-bearing records when available. - ## Pricing Tokscale fetches real-time pricing from [LiteLLM's pricing database](https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json). diff --git a/README.zh-cn.md b/README.zh-cn.md index 6348eba3a..8de94a5fd 100644 --- a/README.zh-cn.md +++ b/README.zh-cn.md @@ -79,7 +79,6 @@ | Trae | [Trae IDE](https://www.trae.ai/) / [Trae Solo](https://www.trae.ai/solo)(国际版) | 通过 `tokscale trae sync` 缓存到 `~/.config/tokscale/trae-cache/sessions/*.json`(来自官方 API 的账号级使用量) | ✅ 支持 | | Zed Agent | [Zed Agent](https://zed.dev/docs/ai/agent-panel) | `~/.local/share/zed/threads/threads.db`(macOS: `~/Library/Application Support/Zed/threads/threads.db`;Windows: `%LOCALAPPDATA%/Zed/threads/threads.db`;仅限托管 Zed 模型,不含外部 ACP 代理) | ✅ 支持 | | Kiro | Kiro | `~/.kiro/sessions/cli/*.json`(+ `*.jsonl`)和 `~/.local/share/kiro-cli/data.sqlite3`(macOS: `~/Library/Application Support/kiro-cli/data.sqlite3`) | ✅ 支持 | -| Synthetic | [Synthetic](https://synthetic.new/) | 通过 `hf:` 模型前缀或 `synthetic` provider 从其他来源重归属(+ [Octofriend](https://github.com/synthetic-lab/octofriend): `~/.local/share/octofriend/sqlite.db`) | ✅ 支持 | 使用 [🚅 LiteLLM 的价格数据](https://github.com/BerriAI/litellm)提供实时价格计算,支持分层定价模型和缓存 Token 折扣。 @@ -147,7 +146,7 @@ - 9 种颜色主题的 GitHub 风格贡献图 - 实时筛选和排序 - 零闪烁渲染 -- **多平台支持** - 跟踪 OpenCode、Claude Code、Codex CLI、Copilot CLI、Cursor IDE、Gemini CLI、Amp、Codebuff、Droid、OpenClaw、Hermes Agent、Pi、OMP、Kimi CLI、Qwen CLI、Roo Code、Kilo、Mux、Kilo CLI、Crush、Goose、Antigravity、Zed、Kiro、Trae 和 Synthetic 的使用情况 +- **多平台支持** - 跟踪 OpenCode、Claude Code、Codex CLI、Copilot CLI、Cursor IDE、Gemini CLI、Amp、Codebuff、Droid、OpenClaw、Hermes Agent、Pi、OMP、Kimi CLI、Qwen CLI、Roo Code、Kilo、Mux、Kilo CLI、Crush、Goose、Antigravity、Zed、Kiro 和 Trae 的使用情况 - **实时定价** - 从 LiteLLM 获取当前价格,带 1 小时磁盘缓存;OpenRouter 自动回退和新模型的 Cursor 定价支持 - **详细分解** - 输入、输出、缓存读写和推理 Token 跟踪 - **原生 Rust 核心** - 所有解析和聚合在 Rust 中完成,处理速度提升 10 倍 @@ -324,14 +323,11 @@ tokscale -c opencode -c claude # Cursor IDE 需要先运行 `tokscale cursor login` tokscale --client cursor -# Synthetic(synthetic.new)从其他 agent 会话中检测 -tokscale --client synthetic - # 与其他筛选条件组合 tokscale --client opencode,claude --week --json ``` -可用值:`opencode`、`claude`、`codex`、`copilot`、`gemini`、`cursor`、`amp`、`codebuff`、`droid`、`openclaw`、`hermes`、`pi`、`omp`、`kimi`、`qwen`、`roocode`、`kilocode`、`kilo`、`mux`、`crush`、`goose`、`antigravity`、`zed`、`kiro`、`trae`、`synthetic`。 +可用值:`opencode`、`claude`、`codex`、`copilot`、`gemini`、`cursor`、`amp`、`codebuff`、`droid`、`openclaw`、`hermes`、`pi`、`omp`、`kimi`、`qwen`、`roocode`、`kilocode`、`kilo`、`mux`、`crush`、`goose`、`antigravity`、`zed`、`kiro`、`trae`。 > **弃用通知**:旧的单客户端选项(`--opencode`、`--claude`、`--codex` 等)出于向后兼容仍然可用,但已从 `--help` 中隐藏,将在下一个主要版本中移除。请尽量迁移到 `--client`。在交互式终端中使用旧选项时会输出一行警告。 @@ -567,7 +563,7 @@ Tokscale 将设置存储在 `~/.config/tokscale/settings.json`: | `autoRefreshEnabled` | boolean | `false` | 在 TUI 中启用自动刷新 | | `autoRefreshMs` | number | `60000` | 自动刷新间隔(30000-3600000ms) | | `nativeTimeoutMs` | number | `300000` | 原生子进程处理最大时间(5000-3600000ms) | -| `defaultClients` | string[] | `[]` | 未传递 `--client/-c` 选项时应用的客户端筛选。接受与 `--client` 相同的 ID(例如 `["opencode", "claude", "synthetic"]`)。未知 ID 会被静默丢弃。命令行选项会完全覆盖此列表 — 不会合并。 | +| `defaultClients` | string[] | `[]` | 未传递 `--client/-c` 选项时应用的客户端筛选。接受与 `--client` 相同的 ID(例如 `["opencode", "claude", "zed"]`)。未知 ID 会被静默丢弃。命令行选项会完全覆盖此列表 — 不会合并。 | | `light.writeCache` | boolean | `false` | 为 `true` 时,`tokscale --light` 会在渲染完成后以原子方式覆盖 TUI 缓存。CLI 标志 `--write-cache` / `--no-write-cache` 会按次运行覆盖该设置。 | | `usageTabEnabled` | boolean | `false` | 在 TUI 中显示订阅额度 Usage 标签。默认关闭,因为本地 Token 使用统计是主要 TUI 工作流,订阅额度查询是可选功能。 | | `minutelyTabEnabled` | boolean | `false` | 在 TUI 中显示按分钟的 Minutely 标签,并在数据加载期间执行分钟级聚合。对大多数用户而言,分钟级粒度是较为小众的诊断视图,而在大数据集上分钟分桶有非平凡的代价,因此默认关闭。 | @@ -702,7 +698,7 @@ tokscale sources --json - **交互式提示**:悬停查看详细的每日分解 - **每日分解面板**:点击查看每个来源和模型的详情 - **年份筛选**:在年份之间导航 -- **来源筛选**:按平台筛选(OpenCode、Claude、Codex、Copilot、Cursor、Gemini、Amp、Codebuff、Droid、OpenClaw、Hermes Agent、Pi、OMP、Kimi、Qwen、Roo Code、Kilo、Mux、Kilo CLI、Crush、Goose、Antigravity、Zed、Kiro、Trae、Synthetic) +- **来源筛选**:按平台筛选(OpenCode、Claude、Codex、Copilot、Cursor、Gemini、Amp、Codebuff、Droid、OpenClaw、Hermes Agent、Pi、OMP、Kimi、Qwen、Roo Code、Kilo、Mux、Kilo CLI、Crush、Goose、Antigravity、Zed、Kiro、Trae) - **统计面板**:总成本、Token、活跃天数、连续记录 - **FOUC 防护**:在 React 水合前应用主题(无闪烁) @@ -1014,7 +1010,6 @@ AI 编程工具将会话数据存储在跨平台位置。大多数工具在所 | Goose | `~/.local/share/goose/sessions/`(+ macOS Application Support、旧版 Block 路径) | `%USERPROFILE%\.local\share\goose\sessions\` | 可通过 `GOOSE_PATH_ROOT` 环境变量配置 | | Antigravity | `~/.config/tokscale/antigravity-cache/sessions/` | — | `tokscale antigravity sync` 目前仅支持 macOS / Linux | | Trae | `~/.config/tokscale/trae-cache/sessions/` | `%APPDATA%\tokscale\trae-cache\sessions\` | 通过 `tokscale trae sync` 同步一次;凭据会从已安装的任意 Trae IDE 或 Trae Solo 桌面端自动发现 | -| Synthetic | 从其他来源重归属 | 从其他来源重归属 | 检测 `hf:` 模型前缀 + `synthetic` provider | > **注意**:在 Windows 上,`~` 扩展为 `%USERPROFILE%`(例如 `C:\Users\用户名`)。这些工具故意使用 Unix 风格的路径(如 `.local/share`)而不是 Windows 原生路径(如 `%APPDATA%`),以实现跨平台一致性。 @@ -1338,12 +1333,6 @@ Goose 在 SQLite 的 `sessions.db` 中按会话保存使用量。Tokscale 从 `m Codebuff(前身 Manicode)按聊天写入 JSON 文件。Tokscale 从 `metadata.usage`、`metadata.codebuff.usage` 以及 run-state 中的 `messageHistory[*].providerOptions` 回退路径解析 Token 使用量,并以反向顺序遍历历史,避免部分更新的较新条目遮蔽实际承载 Token 数的较早条目。当消息时间戳缺失时,会回退到 chat-id 目录名,最后回退到文件 mtime。 -### Synthetic (synthetic.new) - -Synthetic 通过后处理重归属其他来源的消息。当检测到 `hf:` 前缀模型 ID 或 `synthetic` / `glhf` / `octofriend` provider 时,消息会被归类为 `synthetic` 来源。 - -Tokscale 还会检测 `~/.local/share/octofriend/sqlite.db`,并在可用时解析包含 token 数据的记录。 - ## 定价 Tokscale 从 [LiteLLM 的价格数据库](https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json)获取实时价格。 diff --git a/crates/tokscale-cli/src/commands/wrapped.rs b/crates/tokscale-cli/src/commands/wrapped.rs index 80dbdd1eb..a75dda20e 100644 --- a/crates/tokscale-cli/src/commands/wrapped.rs +++ b/crates/tokscale-cli/src/commands/wrapped.rs @@ -1454,7 +1454,6 @@ fn client_display_name(client: &str) -> Option<&'static str> { "antigravity" => Some("Antigravity"), "zed" => Some("Zed Agent"), "warp" => Some("Warp"), - "synthetic" => Some("Synthetic"), _ => None, } } @@ -1497,7 +1496,6 @@ fn client_logo_url(client_name: &str) -> Option<&'static str> { "Zed Agent" => Some( "https://raw.githubusercontent.com/junhoyeo/tokscale/main/.github/assets/client-zed.webp", ), - "Synthetic" => Some("https://tokscale.ai/assets/logos/synthetic.png"), _ => None, } } diff --git a/crates/tokscale-cli/src/main.rs b/crates/tokscale-cli/src/main.rs index 3636fbd8b..0a396d0a8 100644 --- a/crates/tokscale-cli/src/main.rs +++ b/crates/tokscale-cli/src/main.rs @@ -807,17 +807,13 @@ fn main() -> Result<()> { /// Client identifiers exposed via `--client`. /// -/// Mirrors `tokscale_core::ClientId` plus the `Synthetic` meta-client. We -/// duplicate the variant set on the CLI side so `tokscale-core` stays free of -/// CLI-parsing dependencies and so `Synthetic` (which has no scan path of its -/// own) can be treated as a first-class filter value without changing core -/// invariants. +/// Mirrors `tokscale_core::ClientId`. We duplicate the variant set on the CLI +/// side so `tokscale-core` stays free of CLI-parsing dependencies. /// /// Variant order intentionally mirrors `ClientId::ALL` declaration order so /// the TUI source picker, `--help`'s `[possible values: ...]` listing, and /// any future iteration over `ClientFilter::value_variants()` agree on a -/// single chronological ordering. `Synthetic` is appended at the end since -/// it has no `ClientId` counterpart. +/// single chronological ordering. #[derive(ValueEnum, Clone, Copy, Debug, PartialEq, Eq, Hash)] #[value(rename_all = "lowercase")] pub enum ClientFilter { @@ -848,7 +844,6 @@ pub enum ClientFilter { #[value(name = "trae")] Trae, Warp, - Synthetic, } impl ClientFilter { @@ -883,12 +878,10 @@ impl ClientFilter { Self::Kiro => "kiro", Self::Trae => "trae", Self::Warp => "warp", - Self::Synthetic => "synthetic", } } - /// Convert to the corresponding `ClientId`, or `None` for the - /// `Synthetic` meta-client which has no scan path of its own. + /// Convert to the corresponding `ClientId`. /// /// Used at boundaries where TUI state (`HashSet`) needs /// to feed core APIs that still consume `Vec`. @@ -921,12 +914,11 @@ impl ClientFilter { Self::Kiro => Some(ClientId::Kiro), Self::Trae => Some(ClientId::Trae), Self::Warp => Some(ClientId::Warp), - Self::Synthetic => None, } } /// Lift a `ClientId` back into a `ClientFilter`. Total inverse of - /// `to_client_id` for non-`Synthetic` variants. + /// `to_client_id`. pub fn from_client_id(client: tokscale_core::ClientId) -> Self { use tokscale_core::ClientId; match client { @@ -970,23 +962,13 @@ impl ClientFilter { .find(|f| f.as_filter_str() == s) } - /// The "no filter" default set: every real client, with `Synthetic` - /// **excluded**. Matches the pre-refactor behavior where a missing - /// filter scanned every `ClientId` but did NOT post-process synthetic - /// (synthetic detection has always been opt-in because it - /// re-attributes messages from other clients to a different bucket). - /// /// Single source of truth: every code path that needs a default /// filter (TUI launch, `submit` warm cache, etc.) must consult this /// so the cache key, the in-app state, and the loader filter all /// agree. Drift between them produces stale-cache misses on every /// launch. pub fn default_set() -> std::collections::HashSet { - Self::value_variants() - .iter() - .copied() - .filter(|f| !matches!(f, Self::Synthetic)) - .collect() + Self::value_variants().iter().copied().collect() } } @@ -1058,8 +1040,6 @@ pub struct ClientFlags { pub trae: bool, #[arg(long, hide = true)] pub warp: bool, - #[arg(long, hide = true)] - pub synthetic: bool, } #[derive(Args, Clone, Debug, Default)] @@ -1112,7 +1092,7 @@ fn build_client_filter_with_defaults( } } - let legacy: [(bool, ClientFilter); 26] = [ + let legacy: [(bool, ClientFilter); 25] = [ (flags.opencode, ClientFilter::Opencode), (flags.claude, ClientFilter::Claude), (flags.codex, ClientFilter::Codex), @@ -1138,7 +1118,6 @@ fn build_client_filter_with_defaults( (flags.kiro, ClientFilter::Kiro), (flags.trae, ClientFilter::Trae), (flags.warp, ClientFilter::Warp), - (flags.synthetic, ClientFilter::Synthetic), ]; let mut legacy_used: Vec<&'static str> = Vec::new(); @@ -1443,12 +1422,10 @@ fn emit_cursor_sync_warning( } fn default_submit_clients() -> Vec { - let mut clients: Vec = tokscale_core::ClientId::iter() + tokscale_core::ClientId::iter() .filter(|client| client.submit_default()) .map(|client| client.as_str().to_string()) - .collect(); - clients.push("synthetic".to_string()); - clients + .collect() } fn reject_unsupported_home_override(home_dir: &Option, command: &str) -> Result<()> { @@ -5119,7 +5096,7 @@ fn spawn_warm_tui_cache_detached() { /// 1. If `defaultClients` from `~/.config/tokscale/settings.json` is /// set, use that (after dropping unknown ids). /// 2. Otherwise fall back to `ClientFilter::default_set()` (every real -/// client, Synthetic excluded). +/// client). /// /// This **must** stay in lockstep with the resolution that /// `tui::run(.., clients = None, ..)` would compute. If it drifts, the @@ -5200,14 +5177,13 @@ fn write_light_cache( .iter() .filter_map(|filter| filter.to_client_id()) .collect(); - let include_synthetic = enabled_set.contains(&ClientFilter::Synthetic); // The report has already been flushed to stdout by the time we reach // here. Keep the report exit code stable, but expose cache scan/write // failures instead of swallowing them. let loader = DataLoader::with_filters(None, since.clone(), until.clone(), year.clone()); let report_scope = CacheReportScope::new(since.clone(), until.clone(), year.clone()); - match loader.load(&scan_clients, group_by, include_synthetic) { + match loader.load(&scan_clients, group_by) { Ok(data) => { if let Err(err) = save_cached_data(&data, &enabled_set, group_by, &report_scope) { eprintln!("tokscale: --write-cache failed to save TUI cache: {err}"); @@ -5247,9 +5223,8 @@ fn run_warm_tui_cache() -> Result<()> { .iter() .filter_map(|f| f.to_client_id()) .collect(); - let include_synthetic = enabled_set.contains(&ClientFilter::Synthetic); let loader = DataLoader::with_filters(None, None, None, None); - let data = loader.load(&scan_clients, &TUI_DEFAULT_GROUP_BY, include_synthetic)?; + let data = loader.load(&scan_clients, &TUI_DEFAULT_GROUP_BY)?; save_cached_data( &data, &enabled_set, @@ -5801,18 +5776,6 @@ mod tests { ); } - #[test] - fn test_build_client_filter_synthetic_only_legacy() { - let flags = ClientFlags { - synthetic: true, - ..ClientFlags::default() - }; - assert_eq!( - build_client_filter_with_defaults(flags, &[]), - Some(vec!["synthetic".to_string()]) - ); - } - #[test] fn test_build_client_filter_all_legacy_flags() { let flags = ClientFlags { @@ -5841,7 +5804,6 @@ mod tests { kiro: true, trae: true, warp: true, - synthetic: true, ..ClientFlags::default() }; let result = build_client_filter_with_defaults(flags, &[]); @@ -5873,11 +5835,10 @@ mod tests { "kiro", "trae", "warp", - "synthetic", ]; // New clients do not need deprecated boolean flags; only the - // pre-existing legacy flags plus synthetic are represented here. + // pre-existing legacy flags are represented here. let expected_len = required.len(); assert_eq!(sources.len(), expected_len); for required in required { @@ -5945,12 +5906,9 @@ mod tests { #[test] fn test_client_filter_as_filter_str_matches_client_id_for_overlap() { - // Every ClientFilter variant except Synthetic must agree with - // ClientId::as_str() so the core filter list stays consistent. + // Every ClientFilter variant must agree with ClientId::as_str() + // so the core filter list stays consistent. for filter in ClientFilter::value_variants() { - if matches!(filter, ClientFilter::Synthetic) { - continue; - } let id = filter.as_filter_str(); assert!( tokscale_core::ClientId::from_str(id).is_some(), @@ -5963,30 +5921,25 @@ mod tests { #[test] fn test_client_filter_to_client_id_round_trip() { - // For every non-Synthetic filter: - // from_client_id(to_client_id(filter).unwrap()) == filter - // and the canonical id strings agree. + // For every filter: + // from_client_id(to_client_id(filter).unwrap()) == filter + // and canonical id strings agree. for filter in ClientFilter::value_variants() { - match filter.to_client_id() { - Some(id) => { - assert_eq!( - ClientFilter::from_client_id(id), - *filter, - "round-trip mismatch for {:?}", - filter - ); - assert_eq!( - id.as_str(), - filter.as_filter_str(), - "id string drift between ClientId and ClientFilter for {:?}", - filter - ); - } - None => { - // Synthetic is the only meta-client without a ClientId. - assert!(matches!(filter, ClientFilter::Synthetic)); - } - } + let id = filter + .to_client_id() + .expect("client filter must map to ClientId"); + assert_eq!( + ClientFilter::from_client_id(id), + *filter, + "round-trip mismatch for {:?}", + filter + ); + assert_eq!( + id.as_str(), + filter.as_filter_str(), + "id string drift between ClientId and ClientFilter for {:?}", + filter + ); } } @@ -5994,13 +5947,9 @@ mod tests { fn test_client_filter_order_matches_client_id_all() { // Picker rendering, --help possible-values listing, and any // future iteration over `ClientFilter::value_variants()` all - // assume the variant order mirrors `ClientId::ALL` (with - // Synthetic appended). Guard that invariant explicitly. - let filters: Vec = ClientFilter::value_variants() - .iter() - .copied() - .filter(|f| !matches!(f, ClientFilter::Synthetic)) - .collect(); + // assume the variant order mirrors `ClientId::ALL`. Guard that + // invariant explicitly. + let filters: Vec = ClientFilter::value_variants().iter().copied().collect(); let ids: Vec = tokscale_core::ClientId::ALL.to_vec(); assert_eq!(filters.len(), ids.len()); for (filter, id) in filters.iter().zip(ids.iter()) { @@ -6011,11 +5960,6 @@ mod tests { filter ); } - // Synthetic is the very last variant. - assert_eq!( - ClientFilter::value_variants().last().copied(), - Some(ClientFilter::Synthetic) - ); } #[test] @@ -6028,29 +5972,17 @@ mod tests { } #[test] - fn test_client_filter_default_set_excludes_synthetic() { - // Synthetic detection is opt-in: it post-processes other clients' - // sessions to re-attribute messages to a different bucket. The - // pre-refactor default was "every ClientId, include_synthetic = - // false"; default_set() must preserve that contract. + fn test_client_filter_default_set_includes_all_clients() { let default = ClientFilter::default_set(); - assert!( - !default.contains(&ClientFilter::Synthetic), - "default_set() must NOT include Synthetic — it is opt-in only" - ); - // Every real client must be present so first-launch reports cover + // Every client must be present so first-launch reports cover // every integration the binary knows about. for filter in ClientFilter::value_variants() { - if matches!(filter, ClientFilter::Synthetic) { - continue; - } assert!(default.contains(filter), "default_set() missing {filter:?}"); } - // Size sanity: every variant minus Synthetic. assert_eq!( default.len(), - ClientFilter::value_variants().len() - 1, - "default_set() size drifted from value_variants() - 1" + ClientFilter::value_variants().len(), + "default_set() size drifted from value_variants()" ); } @@ -6098,14 +6030,11 @@ mod tests { } #[test] - fn test_resolve_default_tui_filter_set_supports_synthetic() { - // Power users who explicitly want synthetic detection on every - // launch can put it in defaultClients. - let configured = vec!["claude".to_string(), "synthetic".to_string()]; + fn test_resolve_default_tui_filter_set_drops_removed_client_id() { + let configured = vec!["claude".to_string(), "removed-client".to_string()]; let set = resolve_default_tui_filter_set_with(&configured); let mut expected = std::collections::HashSet::new(); expected.insert(ClientFilter::Claude); - expected.insert(ClientFilter::Synthetic); assert_eq!(set, expected); } @@ -6306,7 +6235,6 @@ mod tests { #[test] fn test_default_submit_clients_excludes_crush() { let clients = default_submit_clients(); - assert!(clients.contains(&"synthetic".to_string())); assert!(clients.contains(&"zed".to_string())); assert!(!clients.contains(&"crush".to_string())); } diff --git a/crates/tokscale-cli/src/tui/app.rs b/crates/tokscale-cli/src/tui/app.rs index cfc94a106..ceebd31a9 100644 --- a/crates/tokscale-cli/src/tui/app.rs +++ b/crates/tokscale-cli/src/tui/app.rs @@ -179,12 +179,7 @@ pub struct App { pub data: UsageData, pub data_loader: DataLoader, - /// Set of clients currently selected in the source picker. The - /// `Synthetic` variant is part of the same set so dialog code can - /// uniformly toggle/inspect every option without a separate boolean. - /// Code that talks to `tokscale_core` (which still expects a - /// `Vec` plus a `bool include_synthetic`) projects this set - /// at the boundary via `App::scan_clients` and `App::include_synthetic`. + /// Set of clients currently selected in the source picker. pub enabled_clients: Rc>>, pub group_by: Rc>, pub sort_field: SortField, @@ -260,7 +255,7 @@ impl App { let enabled_clients: HashSet = if let Some(ref cli_clients) = config.clients { // CLI-provided filter list. Each entry is the canonical - // lowercase id (`opencode`, `claude`, ..., `synthetic`). + // lowercase client id. // Unknown ids are dropped silently; the CLI parser already // validated against `ClientFilter` so this lookup should be // total in practice. @@ -269,8 +264,7 @@ impl App { .filter_map(|s| ClientFilter::from_filter_str(&s.to_lowercase())) .collect() } else { - // No filter → use the canonical default set (every real - // client, Synthetic opt-in only). MUST stay in sync with + // No filter → use the canonical default set. MUST stay in sync with // `run_warm_tui_cache()` so a fresh cache warm produces a // fresh hit on the next no-filter launch. ClientFilter::default_set() @@ -1090,9 +1084,6 @@ impl App { /// Project the unified `HashSet` into the /// `Vec` shape that `tokscale_core` scanners still consume. - /// `ClientFilter::Synthetic` does not have a `ClientId` and is - /// excluded from this projection — use [`Self::include_synthetic`] - /// for that signal. pub fn scan_clients(&self) -> Vec { let mut out: Vec = self .enabled_clients @@ -1107,14 +1098,6 @@ impl App { out } - /// Whether the user has Synthetic enabled. Boundary helper for code - /// paths that still take a separate `bool include_synthetic` argument. - pub fn include_synthetic(&self) -> bool { - self.enabled_clients - .borrow() - .contains(&ClientFilter::Synthetic) - } - fn open_group_by_picker(&mut self) { use super::ui::dialog::GroupByPickerDialog; let dialog = @@ -1937,10 +1920,6 @@ mod tests { "no-filter App default drifted from ClientFilter::default_set() — \ warm cache and TUI launch will mismatch" ); - assert!( - !actual.contains(&ClientFilter::Synthetic), - "no-filter default must not include Synthetic (opt-in only)" - ); } fn make_app_with_models(n: usize) -> App { diff --git a/crates/tokscale-cli/src/tui/cache.rs b/crates/tokscale-cli/src/tui/cache.rs index 718764a8f..2bc7cca10 100644 --- a/crates/tokscale-cli/src/tui/cache.rs +++ b/crates/tokscale-cli/src/tui/cache.rs @@ -75,7 +75,6 @@ struct CachedTUIData { schema_version: u32, timestamp: u64, enabled_clients: Vec, - include_synthetic: bool, group_by: String, report_scope: CacheReportScope, data: CachedUsageData, @@ -612,9 +611,9 @@ pub enum CacheResult { /// Returns Fresh/Stale/Miss so the caller can decide whether to /// display cached data immediately and/or trigger a background refresh. /// -/// `enabled_clients` is the unified `HashSet` (Synthetic -/// included as a set member). The cache key must match exactly; partial -/// cache hits would show incomplete data before the background refresh. +/// `enabled_clients` is the unified `HashSet`. The cache key must +/// match exactly; partial cache hits would show incomplete data before the +/// background refresh. pub fn load_cache( enabled_clients: &HashSet, group_by: &GroupBy, @@ -665,11 +664,7 @@ pub fn load_cache( return CacheResult::Miss; } - if !cache_clients_match_exact( - enabled_clients, - &cached.enabled_clients, - cached.include_synthetic, - ) { + if !cache_clients_match_exact(enabled_clients, &cached.enabled_clients) { return CacheResult::Miss; } @@ -710,28 +705,19 @@ pub fn load_cache( fn cache_clients_match_exact( enabled_clients: &HashSet, cached_clients: &[String], - cached_include_synthetic: bool, ) -> bool { - let include_synthetic = enabled_clients.contains(&ClientFilter::Synthetic); - if include_synthetic != cached_include_synthetic { - return false; - } - - let enabled_non_synthetic: HashSet<&str> = enabled_clients + let enabled: HashSet<&str> = enabled_clients .iter() - .filter(|filter| !matches!(filter, ClientFilter::Synthetic)) .map(ClientFilter::as_filter_str) .collect(); - let cached_non_synthetic: HashSet<&str> = cached_clients.iter().map(String::as_str).collect(); + let cached: HashSet<&str> = cached_clients.iter().map(String::as_str).collect(); - cached_non_synthetic.len() == cached_clients.len() - && enabled_non_synthetic == cached_non_synthetic + cached.len() == cached_clients.len() && enabled == cached } /// Save TUI data to disk cache. /// -/// The on-disk cache key stores `(Vec enabled_clients, bool -/// include_synthetic)`. We project the unified `HashSet` here. +/// The on-disk cache key stores the enabled client ids. pub fn save_cached_data( data: &UsageData, enabled_clients: &HashSet, @@ -746,10 +732,8 @@ pub fn save_cached_data( let timestamp = SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis() as u64; - let include_synthetic = enabled_clients.contains(&ClientFilter::Synthetic); let mut clients_vec: Vec = enabled_clients .iter() - .filter(|f| !matches!(f, ClientFilter::Synthetic)) .map(|f| f.as_filter_str().to_string()) .collect(); // Sort so the cache key is deterministic across runs / HashSet @@ -761,7 +745,6 @@ pub fn save_cached_data( schema_version: CACHE_SCHEMA_VERSION, timestamp, enabled_clients: clients_vec, - include_synthetic, group_by: group_by.to_string(), report_scope: report_scope.clone(), data: data.into(), @@ -814,15 +797,8 @@ mod tests { use std::{env, fs}; use tempfile::TempDir; - /// Build a unified filter set. Pass `synthetic=true` to include - /// `ClientFilter::Synthetic` as a set member (the new way to express - /// "user has synthetic enabled"). - fn make_filters(filters: &[ClientFilter], synthetic: bool) -> HashSet { - let mut set: HashSet = filters.iter().copied().collect(); - if synthetic { - set.insert(ClientFilter::Synthetic); - } - set + fn make_filters(filters: &[ClientFilter]) -> HashSet { + filters.iter().copied().collect() } fn cached_agent(agent: &str, clients: &str, total_seed: u64) -> CachedAgentUsage { @@ -881,74 +857,49 @@ mod tests { #[test] fn test_exact_match() { - let enabled = make_filters(&[ClientFilter::Claude, ClientFilter::Opencode], false); + let enabled = make_filters(&[ClientFilter::Claude, ClientFilter::Opencode]); let cached = vec!["claude".to_string(), "opencode".to_string()]; - assert!(cache_clients_match_exact(&enabled, &cached, false)); + assert!(cache_clients_match_exact(&enabled, &cached)); } #[test] fn test_new_client_added_is_not_exact_match() { - let enabled = make_filters( - &[ - ClientFilter::Claude, - ClientFilter::Opencode, - ClientFilter::Qwen, - ], - false, - ); + let enabled = make_filters(&[ + ClientFilter::Claude, + ClientFilter::Opencode, + ClientFilter::Qwen, + ]); let cached = vec!["claude".to_string(), "opencode".to_string()]; - assert!(!cache_clients_match_exact(&enabled, &cached, false)); - } - - #[test] - fn test_synthetic_added_is_not_exact_match() { - let enabled = make_filters(&[ClientFilter::Claude], true); - let cached = vec!["claude".to_string()]; - assert!(!cache_clients_match_exact(&enabled, &cached, false)); + assert!(!cache_clients_match_exact(&enabled, &cached)); } #[test] fn test_mismatch_superset() { // Cache has more clients than enabled (user narrowed filter) - let enabled = make_filters(&[ClientFilter::Claude], false); + let enabled = make_filters(&[ClientFilter::Claude]); let cached = vec!["claude".to_string(), "opencode".to_string()]; - assert!(!cache_clients_match_exact(&enabled, &cached, false)); + assert!(!cache_clients_match_exact(&enabled, &cached)); } #[test] fn test_mismatch_disjoint() { - let enabled = make_filters(&[ClientFilter::Claude], false); + let enabled = make_filters(&[ClientFilter::Claude]); let cached = vec!["opencode".to_string()]; - assert!(!cache_clients_match_exact(&enabled, &cached, false)); - } - - #[test] - fn test_mismatch_unwanted_synthetic() { - // Cache has synthetic data but user doesn't want it - let enabled = make_filters(&[ClientFilter::Claude], false); - let cached = vec!["claude".to_string()]; - assert!(!cache_clients_match_exact(&enabled, &cached, true)); - } - - #[test] - fn test_exact_with_synthetic() { - let enabled = make_filters(&[ClientFilter::Claude], true); - let cached = vec!["claude".to_string()]; - assert!(cache_clients_match_exact(&enabled, &cached, true)); + assert!(!cache_clients_match_exact(&enabled, &cached)); } #[test] - fn test_new_client_and_synthetic_is_not_exact_match() { - let enabled = make_filters(&[ClientFilter::Claude, ClientFilter::Qwen], true); + fn test_new_client_is_not_exact_match() { + let enabled = make_filters(&[ClientFilter::Claude, ClientFilter::Qwen]); let cached = vec!["claude".to_string()]; - assert!(!cache_clients_match_exact(&enabled, &cached, false)); + assert!(!cache_clients_match_exact(&enabled, &cached)); } #[test] fn test_empty_cache_is_not_exact_match() { - let enabled = make_filters(&[ClientFilter::Claude], false); + let enabled = make_filters(&[ClientFilter::Claude]); let cached: Vec = vec![]; - assert!(!cache_clients_match_exact(&enabled, &cached, false)); + assert!(!cache_clients_match_exact(&enabled, &cached)); } #[test] @@ -967,7 +918,6 @@ mod tests { r#"{ "timestamp": 9999999999999, "enabledClients": ["claude"], - "includeSynthetic": false, "data": { "models": [], "daily": [], @@ -981,7 +931,7 @@ mod tests { ) .unwrap(); - let clients = make_filters(&[ClientFilter::Claude], false); + let clients = make_filters(&[ClientFilter::Claude]); assert!(matches!( load_cache( &clients, @@ -1015,7 +965,6 @@ mod tests { "schemaVersion": 13, "timestamp": 9999999999999, "enabledClients": ["claude"], - "includeSynthetic": false, "groupBy": "model", "reportScope": { "since": null, @@ -1037,7 +986,7 @@ mod tests { ) .unwrap(); - let clients = make_filters(&[ClientFilter::Claude], false); + let clients = make_filters(&[ClientFilter::Claude]); assert!(matches!( load_cache( &clients, @@ -1063,7 +1012,7 @@ mod tests { env::set_var("HOME", temp_dir.path()); } - let clients = make_filters(&[ClientFilter::Claude], false); + let clients = make_filters(&[ClientFilter::Claude]); let filtered_scope = CacheReportScope::new( Some("2026-05-01".to_string()), Some("2026-05-07".to_string()), @@ -1107,7 +1056,7 @@ mod tests { env::set_var("HOME", temp_dir.path()); } - let clients = make_filters(&[ClientFilter::Claude], false); + let clients = make_filters(&[ClientFilter::Claude]); let scope = CacheReportScope::default(); save_cached_data(&UsageData::default(), &clients, &GroupBy::Model, &scope).unwrap(); @@ -1147,7 +1096,6 @@ mod tests { "schemaVersion": 8, "timestamp": 9999999999999, "enabledClients": ["claude"], - "includeSynthetic": false, "groupBy": "model", "data": { "models": [{ @@ -1177,7 +1125,7 @@ mod tests { ) .unwrap(); - let clients = make_filters(&[ClientFilter::Claude], false); + let clients = make_filters(&[ClientFilter::Claude]); assert!(matches!( load_cache( &clients, @@ -1211,7 +1159,6 @@ mod tests { "schemaVersion": 3, "timestamp": 9999999999999, "enabledClients": ["claude"], - "includeSynthetic": false, "groupBy": "model", "data": { "models": [], @@ -1251,7 +1198,7 @@ mod tests { ) .unwrap(); - let clients = make_filters(&[ClientFilter::Claude], false); + let clients = make_filters(&[ClientFilter::Claude]); assert!(matches!( load_cache( &clients, @@ -1284,7 +1231,6 @@ mod tests { "schemaVersion": 13, "timestamp": 0, "enabledClients": ["claude", "cursor"], - "includeSynthetic": false, "groupBy": "model", "reportScope": { "since": null, @@ -1379,7 +1325,7 @@ mod tests { cached["timestamp"] = serde_json::Value::from(fresh_timestamp_ms()); fs::write(&cache_path, serde_json::to_vec(&cached).unwrap()).unwrap(); - let clients = make_filters(&[ClientFilter::Claude, ClientFilter::Cursor], false); + let clients = make_filters(&[ClientFilter::Claude, ClientFilter::Cursor]); match load_cache( &clients, &GroupBy::Model, @@ -1414,7 +1360,7 @@ mod tests { env::set_var("HOME", temp_dir.path()); } - let clients = make_filters(&[ClientFilter::Claude], false); + let clients = make_filters(&[ClientFilter::Claude]); save_cached_data( &UsageData::default(), &clients, @@ -1461,7 +1407,6 @@ mod tests { "schemaVersion": 5, "timestamp": 9999999999999, "enabledClients": ["claude"], - "includeSynthetic": false, "groupBy": "model", "data": { "models": [], @@ -1504,7 +1449,7 @@ mod tests { ) .unwrap(); - let clients = make_filters(&[ClientFilter::Claude], false); + let clients = make_filters(&[ClientFilter::Claude]); assert!(matches!( load_cache( &clients, @@ -1538,7 +1483,6 @@ mod tests { "schemaVersion": 3, "timestamp": 9999999999999, "enabledClients": ["claude"], - "includeSynthetic": false, "groupBy": "model", "data": { "models": [], @@ -1578,7 +1522,7 @@ mod tests { ) .unwrap(); - let clients = make_filters(&[ClientFilter::Claude], false); + let clients = make_filters(&[ClientFilter::Claude]); assert!(matches!( load_cache( &clients, @@ -1616,7 +1560,6 @@ mod tests { "schemaVersion": 10, "timestamp": 9999999999999, "enabledClients": ["claude"], - "includeSynthetic": false, "groupBy": "model", "data": { "models": [], @@ -1633,7 +1576,7 @@ mod tests { ) .unwrap(); - let clients = make_filters(&[ClientFilter::Claude], false); + let clients = make_filters(&[ClientFilter::Claude]); assert!(matches!( load_cache( &clients, @@ -1678,7 +1621,6 @@ mod tests { "schemaVersion": 6, "timestamp": 9999999999999, "enabledClients": ["claude"], - "includeSynthetic": false, "groupBy": "model", "data": { "models": [], @@ -1695,7 +1637,7 @@ mod tests { ) .unwrap(); - let clients = make_filters(&[ClientFilter::Claude], false); + let clients = make_filters(&[ClientFilter::Claude]); assert!(matches!( load_cache( &clients, @@ -1740,7 +1682,6 @@ mod tests { "schemaVersion": 6, "timestamp": {old_timestamp}, "enabledClients": ["claude"], - "includeSynthetic": false, "groupBy": "model", "data": {{ "models": [], @@ -1759,7 +1700,7 @@ mod tests { .unwrap(); assert!(fs::metadata(&cache_path).is_ok()); - let clients = make_filters(&[ClientFilter::Claude], false); + let clients = make_filters(&[ClientFilter::Claude]); save_cached_data( &UsageData::default(), &clients, diff --git a/crates/tokscale-cli/src/tui/data/mod.rs b/crates/tokscale-cli/src/tui/data/mod.rs index 96bafe5f8..f703b4c94 100644 --- a/crates/tokscale-cli/src/tui/data/mod.rs +++ b/crates/tokscale-cli/src/tui/data/mod.rs @@ -306,24 +306,16 @@ impl DataLoader { self } - pub fn load( - &self, - enabled_clients: &[ClientId], - group_by: &GroupBy, - include_synthetic: bool, - ) -> Result { + pub fn load(&self, enabled_clients: &[ClientId], group_by: &GroupBy) -> Result { let home = dirs::home_dir() .ok_or_else(|| anyhow::anyhow!("Could not find home directory"))? .to_string_lossy() .to_string(); - let mut sources: Vec = enabled_clients + let sources: Vec = enabled_clients .iter() .map(|client| client.as_str().to_string()) .collect(); - if include_synthetic { - sources.push("synthetic".to_string()); - } let opts = LocalParseOptions { home_dir: Some(home), @@ -358,7 +350,6 @@ impl DataLoader { &self, enabled_clients: &[ClientId], group_by: &GroupBy, - include_synthetic: bool, pricing: &tokscale_core::pricing::PricingService, ) -> Result { let home = dirs::home_dir() @@ -366,13 +357,10 @@ impl DataLoader { .to_string_lossy() .to_string(); - let mut sources: Vec = enabled_clients + let sources: Vec = enabled_clients .iter() .map(|client| client.as_str().to_string()) .collect(); - if include_synthetic { - sources.push("synthetic".to_string()); - } let opts = LocalParseOptions { home_dir: Some(home), @@ -1249,7 +1237,6 @@ mod tests { loader: &DataLoader, enabled_clients: &[ClientId], group_by: &GroupBy, - include_synthetic: bool, pricing: Option<&PricingService>, ) -> Result { let home = dirs::home_dir() @@ -1257,13 +1244,10 @@ mod tests { .to_string_lossy() .to_string(); - let mut sources: Vec = enabled_clients + let sources: Vec = enabled_clients .iter() .map(|client| client.as_str().to_string()) .collect(); - if include_synthetic { - sources.push("synthetic".to_string()); - } let opts = LocalParseOptions { home_dir: Some(home), @@ -2539,7 +2523,6 @@ after"#, &loader, &[ClientId::RooCode], &GroupBy::Model, - false, Some(&pricing), ) .unwrap(); @@ -2611,7 +2594,7 @@ after"#, #[test] #[serial] - fn test_data_loader_keeps_synthetic_gateway_messages_under_original_client() { + fn test_data_loader_keeps_gateway_model_path_under_original_client() { let temp_dir = TempDir::new().unwrap(); let previous_home = env::var_os("HOME"); let message_dir = temp_dir @@ -2634,7 +2617,6 @@ after"#, &loader, &[ClientId::OpenCode], &GroupBy::ClientProviderModel, - true, Some(&pricing), ) .unwrap(); diff --git a/crates/tokscale-cli/src/tui/mod.rs b/crates/tokscale-cli/src/tui/mod.rs index 756f9a730..0cce4a204 100644 --- a/crates/tokscale-cli/src/tui/mod.rs +++ b/crates/tokscale-cli/src/tui/mod.rs @@ -173,15 +173,11 @@ pub fn run( app.set_background_loading(true); let tx = bg_tx.clone(); - // Project the filter set into the (clients, include_synthetic) - // pair the loader still consumes. Keeping the projection here - // (instead of inside DataLoader) avoids touching tokscale-core's - // public API in this PR. + // Project the filter set into the client list the loader consumes. let bg_clients: Vec = enabled_clients .iter() .filter_map(|f| f.to_client_id()) .collect(); - let bg_include_synthetic = enabled_clients.contains(&ClientFilter::Synthetic); let bg_since = since.clone(); let bg_until = until.clone(); let bg_year = year.clone(); @@ -192,7 +188,7 @@ pub fn run( thread::spawn(move || { let loader = background_data_loader(bg_since, bg_until, bg_year, bg_minutely_enabled); - let result = loader.load(&bg_clients, &bg_group_by, bg_include_synthetic); + let result = loader.load(&bg_clients, &bg_group_by); if let Ok(ref data) = result { if let Err(err) = @@ -306,9 +302,7 @@ fn run_loop_with_background( app.set_background_loading(true); let tx = bg_tx.clone(); - // Boundary projection: see [`run`] above for the shape rationale. let clients = app.scan_clients(); - let include_synthetic = app.include_synthetic(); let since = app.data_loader.since.clone(); let until = app.data_loader.until.clone(); let year = app.data_loader.year.clone(); @@ -319,7 +313,7 @@ fn run_loop_with_background( thread::spawn(move || { let loader = background_data_loader(since, until, year, minutely_enabled); - let result = loader.load(&clients, &group_by, include_synthetic); + let result = loader.load(&clients, &group_by); if let Ok(ref data) = result { if let Err(err) = save_cached_data(data, &enabled_clients, &group_by, &report_scope) @@ -381,7 +375,7 @@ pub fn test_data_loading() -> Result<()> { ClientId::Codebuff, ]; - let data = loader.load(&all_clients, &tokscale_core::GroupBy::default(), false)?; + let data = loader.load(&all_clients, &tokscale_core::GroupBy::default())?; println!("Loaded {} models", data.models.len()); println!("Total cost: ${:.2}", data.total_cost); diff --git a/crates/tokscale-cli/src/tui/settings.rs b/crates/tokscale-cli/src/tui/settings.rs index 98ccbcf3e..796440d9b 100644 --- a/crates/tokscale-cli/src/tui/settings.rs +++ b/crates/tokscale-cli/src/tui/settings.rs @@ -70,7 +70,7 @@ pub struct Settings { /// invocation. /// /// Stored as canonical lowercase ids matching `ClientFilter::as_filter_str` - /// (e.g. `["opencode", "claude", "synthetic"]`). Unknown ids are dropped + /// (e.g. `["opencode", "claude", "zed"]`). Unknown ids are dropped /// silently at load time so a typo or stale entry never breaks tokscale. /// CLI flags always override this list completely — no merging. #[serde(default, deserialize_with = "deserialize_string_array_lossy")] @@ -647,7 +647,7 @@ mod tests { "autoRefreshMs": 60000, "includeUnusedModels": false, "nativeTimeoutMs": 300000, - "defaultClients": ["opencode", "claude", "synthetic"] + "defaultClients": ["opencode", "claude", "zed"] }"#; let parsed: Settings = serde_json::from_str(json).unwrap(); assert_eq!( @@ -655,7 +655,7 @@ mod tests { vec![ "opencode".to_string(), "claude".to_string(), - "synthetic".to_string() + "zed".to_string() ] ); @@ -663,7 +663,7 @@ mod tests { let round_trip: serde_json::Value = serde_json::from_str(&serialized).unwrap(); assert_eq!( round_trip["defaultClients"], - serde_json::json!(["opencode", "claude", "synthetic"]) + serde_json::json!(["opencode", "claude", "zed"]) ); } diff --git a/crates/tokscale-cli/src/tui/ui/dialog/source_picker.rs b/crates/tokscale-cli/src/tui/ui/dialog/source_picker.rs index ee8c4d906..780c622f1 100644 --- a/crates/tokscale-cli/src/tui/ui/dialog/source_picker.rs +++ b/crates/tokscale-cli/src/tui/ui/dialog/source_picker.rs @@ -18,17 +18,8 @@ use crate::ClientFilter; use super::{DialogContent, DialogResult}; -/// Hotkey assigned to the Synthetic option in the dialog. -/// -/// `'n'` is reserved here for Synthetic so it does not collide with any -/// real client hotkey in [`crate::tui::client_ui::CLIENT_UI`]. The toggle -/// path checks `client_ui::from_hotkey` first, so any future client that -/// also wants `'n'` would silently shadow Synthetic — keep this value in -/// sync with the client hotkey table. -const SYNTHETIC_HOTKEY: char = 'n'; - -/// TUI dialog that lets the user toggle which clients (and Synthetic) are -/// included in reports. Backed by the same unified +/// TUI dialog that lets the user toggle which clients are included in reports. +/// Backed by the same unified /// `Rc>>` the rest of the app sees, so /// toggles propagate without a separate sync step. pub struct ClientPickerDialog { @@ -246,12 +237,9 @@ impl DialogContent for ClientPickerDialog { KeyCode::Char(c) => { // Hotkey toggle: route through the centralized // `ClientFilter` mapping so adding a new hotkey only - // requires editing `client_ui.rs` + (if it's a non-client - // meta source) updating SYNTHETIC_HOTKEY here. + // requires editing `client_ui.rs`. if let Some(client_id) = client_ui::from_hotkey(c) { self.toggle(ClientFilter::from_client_id(client_id)); - } else if c == SYNTHETIC_HOTKEY { - self.toggle(ClientFilter::Synthetic); } else { self.filter.push(c); self.rebuild_filter(); @@ -264,19 +252,20 @@ impl DialogContent for ClientPickerDialog { } /// Display name for a `ClientFilter` row in the picker. Delegates to the -/// existing `client_ui` registry for `ClientId`-backed variants and adds -/// the meta-client label for `Synthetic`. +/// existing `client_ui` registry. fn display_name(client: ClientFilter) -> &'static str { - match client.to_client_id() { - Some(id) => client_ui::display_name(id), - None => "Synthetic", - } + client_ui::display_name( + client + .to_client_id() + .expect("client filter must map to ClientId"), + ) } -/// Hotkey for a `ClientFilter` row. Mirrors `display_name`'s split. +/// Hotkey for a `ClientFilter` row. fn hotkey(client: ClientFilter) -> char { - match client.to_client_id() { - Some(id) => client_ui::hotkey(id), - None => SYNTHETIC_HOTKEY, - } + client_ui::hotkey( + client + .to_client_id() + .expect("client filter must map to ClientId"), + ) } diff --git a/crates/tokscale-core/src/lib.rs b/crates/tokscale-core/src/lib.rs index f5db6859c..ed6477e0e 100644 --- a/crates/tokscale-core/src/lib.rs +++ b/crates/tokscale-core/src/lib.rs @@ -372,14 +372,11 @@ fn strip_claude_grouping_noise_tail(mut tail: &str) -> &str { fn retain_for_requested_clients( client: &str, - model_id: &str, - provider_id: &str, + _model_id: &str, + _provider_id: &str, requested: &HashSet<&str>, ) -> bool { - requested.contains(client) - || (requested.contains("claude") && client.starts_with("cc-mirror/")) - || (requested.contains("synthetic") - && sessions::synthetic::matches_synthetic_filter(client, model_id, provider_id)) + requested.contains(client) || (requested.contains("claude") && client.starts_with("cc-mirror/")) } #[derive(Debug, Clone, Default, PartialEq, serde::Serialize)] @@ -1124,7 +1121,6 @@ fn parse_all_messages_with_pricing_with_env_strategy( source_cache.prune_missing_files(); let mut all_messages: Vec = Vec::new(); let include_all = clients.is_empty(); - let include_synthetic = include_all || clients.iter().any(|c| c == "synthetic"); // Parse OpenCode: prefer SQLite, collapse forked SQLite history there, then // suppress legacy JSON overlap by message identity. @@ -1599,21 +1595,6 @@ fn parse_all_messages_with_pricing_with_env_strategy( let deduped_trae_messages = dedupe_latest_trae_messages(trae_messages); all_messages.extend(deduped_trae_messages); - if include_synthetic { - if let Some(db_path) = &scan_result.synthetic_db { - let outcome = load_or_parse_sqlite_source(db_path, &source_cache, pricing, |path| { - sessions::synthetic::parse_octofriend_sqlite(path) - }); - all_messages.extend(outcome.messages); - if let Some(entry) = outcome.cache_entry { - source_cache.insert(entry); - } - } - } - - // Filter BEFORE normalization so retain_for_requested_clients can see - // original model/provider prefixes (e.g. "accounts/fireworks/models/…") - // that is_synthetic_gateway relies on for gateway detection. if !include_all { let requested: HashSet<&str> = clients.iter().map(String::as_str).collect(); all_messages.retain(|msg| { @@ -1621,15 +1602,6 @@ fn parse_all_messages_with_pricing_with_env_strategy( }); } - if include_synthetic { - for msg in &mut all_messages { - sessions::synthetic::normalize_synthetic_gateway_fields( - &mut msg.model_id, - &mut msg.provider_id, - ); - } - } - source_cache.save_if_dirty(); Ok(all_messages) @@ -1851,12 +1823,10 @@ pub async fn get_model_report(options: ReportOptions) -> Result = options.clients.clone().unwrap_or_else(|| { - let mut clients: Vec = ClientId::ALL + ClientId::ALL .iter() .map(|c| c.as_str().to_string()) - .collect(); - clients.push("synthetic".to_string()); - clients + .collect() }); let pricing = load_pricing_for_local_parse().await; @@ -1907,12 +1877,10 @@ pub async fn get_monthly_report(options: ReportOptions) -> Result = options.clients.clone().unwrap_or_else(|| { - let mut clients: Vec = ClientId::ALL + ClientId::ALL .iter() .map(|c| c.as_str().to_string()) - .collect(); - clients.push("synthetic".to_string()); - clients + .collect() }); let pricing = load_pricing_for_local_parse().await; @@ -2006,12 +1974,10 @@ pub async fn get_hourly_report(options: ReportOptions) -> Result = options.clients.clone().unwrap_or_else(|| { - let mut clients: Vec = ClientId::ALL + ClientId::ALL .iter() .map(|c| c.as_str().to_string()) - .collect(); - clients.push("synthetic".to_string()); - clients + .collect() }); let pricing = load_pricing_for_local_parse().await; @@ -2103,12 +2069,10 @@ async fn generate_graph_with_loaded_pricing( let home_dir = get_home_dir_string(&options.home_dir)?; let clients: Vec = options.clients.clone().unwrap_or_else(|| { - let mut clients: Vec = ClientId::ALL + ClientId::ALL .iter() .map(|c| c.as_str().to_string()) - .collect(); - clients.push("synthetic".to_string()); - clients + .collect() }); let all_messages = parse_all_messages_with_pricing_with_env_strategy( @@ -2153,12 +2117,10 @@ pub async fn get_time_metrics_report(options: ReportOptions) -> Result = options.clients.clone().unwrap_or_else(|| { - let mut clients: Vec = ClientId::ALL + ClientId::ALL .iter() .map(|c| c.as_str().to_string()) - .collect(); - clients.push("synthetic".to_string()); - clients + .collect() }); let all_messages = parse_all_messages_with_pricing_with_env_strategy( @@ -2307,12 +2269,10 @@ fn resolve_local_parse_request( ) -> Result<(String, Vec), String> { let home_dir = get_home_dir_string(&options.home_dir)?; let clients = options.clients.clone().unwrap_or_else(|| { - let mut clients: Vec = ClientId::iter() + ClientId::iter() .filter(|c| c.parse_local()) .map(|c| c.as_str().to_string()) - .collect(); - clients.push("synthetic".to_string()); - clients + .collect() }); Ok((home_dir, clients)) } @@ -2338,15 +2298,12 @@ pub fn parse_local_clients(options: LocalParseOptions) -> Result = options.clients.clone().unwrap_or_else(|| { - let mut clients: Vec = ClientId::iter() + ClientId::iter() .filter(|c| c.parse_local()) .map(|c| c.as_str().to_string()) - .collect(); - clients.push("synthetic".to_string()); - clients + .collect() }); let include_all = clients.is_empty(); - let include_synthetic = include_all || clients.iter().any(|c| c == "synthetic"); let scan_result = scanner::scan_all_clients_with_scanner_settings( &home_dir, @@ -2784,18 +2741,6 @@ pub fn parse_local_clients(options: LocalParseOptions) -> Result = - sessions::synthetic::parse_octofriend_sqlite(db_path) - .into_iter() - .map(|msg| unified_to_parsed(&msg)) - .collect(); - messages.extend(synthetic_msgs); - } - } - - // Filter BEFORE normalization (see parse_all_messages_with_pricing). if !include_all { let requested: HashSet<&str> = clients.iter().map(String::as_str).collect(); messages.retain(|msg| { @@ -2803,15 +2748,6 @@ pub fn parse_local_clients(options: LocalParseOptions) -> Result = HashSet::from(["synthetic"]); - assert!(retain_for_requested_clients( - "opencode", - "hf:deepseek-ai/DeepSeek-V3-0324", - "unknown", - &requested - )); - assert!(retain_for_requested_clients( - "synthetic", - "deepseek-v3-0324", - "synthetic", - &requested - )); - assert!(!retain_for_requested_clients( - "opencode", - "gpt-4o", - "anthropic", - &requested - )); - } - #[test] fn test_retain_for_requested_clients_preserves_kilo_split() { let kilocode_only: HashSet<&str> = HashSet::from(["kilocode"]); @@ -6459,7 +6372,7 @@ mod tests { } #[test] - fn test_parse_all_messages_with_pricing_keeps_gateway_message_under_synthetic_filter() { + fn test_parse_all_messages_with_pricing_keeps_gateway_message_under_real_client_filter() { let temp_dir = tempfile::TempDir::new().unwrap(); let message_dir = temp_dir .path() @@ -6474,15 +6387,15 @@ mod tests { let pricing = pricing::PricingService::new(HashMap::new(), HashMap::new()); let messages = parse_all_messages_with_pricing( temp_dir.path().to_str().unwrap(), - &["synthetic".to_string()], + &["opencode".to_string()], Some(&pricing), ) .unwrap(); assert_eq!(messages.len(), 1); assert_eq!(messages[0].client, "opencode"); - assert_eq!(messages[0].model_id, "deepseek-v3-0324"); - assert_eq!(messages[0].provider_id, "synthetic"); + assert_eq!(messages[0].model_id, "hf:deepseek-ai/DeepSeek-V3-0324"); + assert_eq!(messages[0].provider_id, "unknown"); } #[test] @@ -6501,7 +6414,7 @@ mod tests { let parsed = parse_local_clients(LocalParseOptions { home_dir: Some(temp_dir.path().to_str().unwrap().to_string()), use_env_roots: false, - clients: Some(vec!["opencode".to_string(), "synthetic".to_string()]), + clients: Some(vec!["opencode".to_string()]), since: None, until: None, year: None, @@ -6512,72 +6425,10 @@ mod tests { assert_eq!(parsed.counts.get(ClientId::OpenCode), 1); assert_eq!(parsed.messages.len(), 1); assert_eq!(parsed.messages[0].client, "opencode"); - assert_eq!(parsed.messages[0].model_id, "deepseek-v3-0324"); - assert_eq!(parsed.messages[0].provider_id, "fireworks"); - } - - #[test] - fn test_parse_all_messages_fireworks_provider_kept_under_synthetic_only_filter() { - let temp_dir = tempfile::TempDir::new().unwrap(); - let message_dir = temp_dir - .path() - .join(".local/share/opencode/storage/message/project-1"); - std::fs::create_dir_all(&message_dir).unwrap(); - std::fs::write( - message_dir.join("msg_001.json"), - r#"{"id":"msg-1","sessionID":"session-1","role":"assistant","modelID":"accounts/fireworks/models/deepseek-v3-0324","providerID":"fireworks","cost":0.1,"tokens":{"input":10,"output":5,"reasoning":0,"cache":{"read":0,"write":0}},"time":{"created":1733011200000}}"#, - ) - .unwrap(); - - let pricing = pricing::PricingService::new(HashMap::new(), HashMap::new()); - let messages = parse_all_messages_with_pricing( - temp_dir.path().to_str().unwrap(), - &["synthetic".to_string()], - Some(&pricing), - ) - .unwrap(); - assert_eq!( - messages.len(), - 1, - "fireworks gateway message must not be dropped when filtering for synthetic" + parsed.messages[0].model_id, + "accounts/fireworks/models/deepseek-v3-0324" ); - assert_eq!(messages[0].client, "opencode"); - assert_eq!(messages[0].model_id, "deepseek-v3-0324"); - assert_eq!(messages[0].provider_id, "fireworks"); - } - - #[test] - fn test_parse_local_clients_fireworks_provider_kept_under_synthetic_only_filter() { - let temp_dir = tempfile::TempDir::new().unwrap(); - let message_dir = temp_dir - .path() - .join(".local/share/opencode/storage/message/project-1"); - std::fs::create_dir_all(&message_dir).unwrap(); - std::fs::write( - message_dir.join("msg_001.json"), - r#"{"id":"msg-1","sessionID":"session-1","role":"assistant","modelID":"accounts/fireworks/models/deepseek-v3-0324","providerID":"fireworks","cost":0.1,"tokens":{"input":10,"output":5,"reasoning":0,"cache":{"read":0,"write":0}},"time":{"created":1733011200000}}"#, - ) - .unwrap(); - - let parsed = parse_local_clients(LocalParseOptions { - home_dir: Some(temp_dir.path().to_str().unwrap().to_string()), - use_env_roots: false, - clients: Some(vec!["synthetic".to_string()]), - since: None, - until: None, - year: None, - scanner_settings: scanner::ScannerSettings::default(), - }) - .unwrap(); - - assert_eq!( - parsed.messages.len(), - 1, - "fireworks gateway message must not be dropped when filtering for synthetic only" - ); - assert_eq!(parsed.messages[0].client, "opencode"); - assert_eq!(parsed.messages[0].model_id, "deepseek-v3-0324"); assert_eq!(parsed.messages[0].provider_id, "fireworks"); } @@ -6795,11 +6646,10 @@ mod tests { ) .unwrap(); - let mut clients: Vec = ClientId::iter() + let clients: Vec = ClientId::iter() .filter(|client| client.submit_default()) .map(|client| client.as_str().to_string()) .collect(); - clients.push("synthetic".to_string()); let rt = tokio::runtime::Runtime::new().unwrap(); let graph = rt diff --git a/crates/tokscale-core/src/pricing/aliases.rs b/crates/tokscale-core/src/pricing/aliases.rs index bdf105774..a58d3cce3 100644 --- a/crates/tokscale-core/src/pricing/aliases.rs +++ b/crates/tokscale-core/src/pricing/aliases.rs @@ -47,7 +47,7 @@ static MODEL_ALIASES: Lazy> = Lazy::new(|| { m.insert("gemini-3-flash", "gemini-3-flash-preview"); m.insert("gemini-3-flash-c", "gemini-3-flash-preview"); - // Synthetic model variants (only where resolver needs help) + // Gateway model variants (only where resolver needs help) m.insert("kimi-k2.5-nvfp4", "kimi-k2.5"); // Quantization variant → base model pricing m.insert("kimi-k2-instruct-0905", "kimi-k2.5"); // Specific version → base (avoids reseller) m diff --git a/crates/tokscale-core/src/pricing/custom.rs b/crates/tokscale-core/src/pricing/custom.rs index ac6822d7a..7807a36fe 100644 --- a/crates/tokscale-core/src/pricing/custom.rs +++ b/crates/tokscale-core/src/pricing/custom.rs @@ -1,5 +1,4 @@ use super::litellm::ModelPricing; -use crate::sessions::synthetic::normalize_synthetic_model; use serde::de::{MapAccess, Visitor}; use serde::Deserialize; use serde_json::Value; @@ -250,7 +249,7 @@ impl CustomPricing { }); } - let normalized_key = normalize_synthetic_model(model_id).to_lowercase(); + let normalized_key = normalize_gateway_model_path(model_id).to_lowercase(); if normalized_key != raw_key { if let Some(pricing) = self.models.get_key_value(&normalized_key) { return Some(CustomLookupResult { @@ -308,6 +307,25 @@ impl CustomPricing { } } +fn normalize_gateway_model_path(model_id: &str) -> String { + let lower = model_id.to_lowercase(); + + if let Some(rest) = lower.strip_prefix("hf:") { + return rest + .split_once('/') + .map_or(rest, |(_, model)| model) + .to_string(); + } + + if let Some(rest) = lower.strip_prefix("accounts/") { + if let Some((_, model)) = rest.split_once("/models/") { + return model.to_string(); + } + } + + lower +} + fn base_price( per_million: Option, per_token: Option, diff --git a/crates/tokscale-core/src/scanner.rs b/crates/tokscale-core/src/scanner.rs index 2a4cbe729..5fd25375f 100644 --- a/crates/tokscale-core/src/scanner.rs +++ b/crates/tokscale-core/src/scanner.rs @@ -81,7 +81,6 @@ pub struct ScanResult { /// `opencode-nightly.db`, etc. See upstream logic in opencode's /// `packages/opencode/src/storage/db.ts` (`getChannelPath`). pub opencode_dbs: Vec, - pub synthetic_db: Option, pub kilo_db: Option, pub hermes_db: Option, pub goose_db: Option, @@ -97,7 +96,6 @@ impl Default for ScanResult { Self { files: std::array::from_fn(|_| Vec::new()), opencode_dbs: Vec::new(), - synthetic_db: None, kilo_db: None, hermes_db: None, goose_db: None, @@ -662,9 +660,7 @@ fn scan_all_clients_with_env_strategy_inner( let mut result = ScanResult::default(); let include_all = clients.is_empty(); - let include_synthetic = include_all || clients.iter().any(|s| s == "synthetic"); - - let enabled: HashSet = if include_all || include_synthetic { + let enabled: HashSet = if include_all { ClientId::iter().collect() } else { clients @@ -841,18 +837,6 @@ fn scan_all_clients_with_env_strategy_inner( ); } - if include_synthetic { - let xdg_data = if use_env_roots { - std::env::var("XDG_DATA_HOME").unwrap_or_else(|_| format!("{}/.local/share", home_dir)) - } else { - format!("{}/.local/share", home_dir) - }; - let octofriend_db_path = PathBuf::from(format!("{}/octofriend/sqlite.db", xdg_data)); - if octofriend_db_path.exists() { - result.synthetic_db = Some(octofriend_db_path); - } - } - if enabled.contains(&ClientId::RooCode) { let local_path = ClientId::RooCode .data() @@ -1994,11 +1978,10 @@ mod tests { // counts plus waste SQLite parsing work. // // The fix moves the merge inside the OpenCode-enabled block, so - // this test exercises the four canonical filter shapes: + // this test exercises the three canonical filter shapes: // 1. ["claude"] → opencode_dbs must be empty // 2. ["opencode"] → both auto + user-configured dbs present - // 3. ["synthetic"] → both present (synthetic enables all) - // 4. [] → both present (empty filter = all clients) + // 3. [] → both present (empty filter = all clients) let previous_xdg = std::env::var("XDG_DATA_HOME").ok(); let dir = TempDir::new().unwrap(); @@ -2053,21 +2036,7 @@ mod tests { opencode_only.opencode_dbs ); - // 3. clients=["synthetic"] — synthetic enables all clients, so - // both dbs must be present. - let synthetic_only = scan(&["synthetic"]); - assert!( - synthetic_only.opencode_dbs.iter().any(|p| p == &auto_db), - "synthetic-only filter must enable OpenCode auto-discovery, got {:?}", - synthetic_only.opencode_dbs - ); - assert!( - synthetic_only.opencode_dbs.iter().any(|p| p == &outside_db), - "synthetic-only filter must merge user-configured paths, got {:?}", - synthetic_only.opencode_dbs - ); - - // 4. clients=[] — empty filter = all clients = both dbs present. + // 3. clients=[] — empty filter = all clients = both dbs present. let all_clients = scan(&[]); assert!( all_clients.opencode_dbs.iter().any(|p| p == &auto_db), diff --git a/crates/tokscale-core/src/sessions/mod.rs b/crates/tokscale-core/src/sessions/mod.rs index 1db46a243..540a2d0fe 100644 --- a/crates/tokscale-core/src/sessions/mod.rs +++ b/crates/tokscale-core/src/sessions/mod.rs @@ -24,7 +24,6 @@ pub mod opencode; pub mod pi; pub mod qwen; pub mod roocode; -pub mod synthetic; pub mod trae; pub(crate) mod utils; pub mod warp; diff --git a/crates/tokscale-core/src/sessions/synthetic.rs b/crates/tokscale-core/src/sessions/synthetic.rs deleted file mode 100644 index f02e838a0..000000000 --- a/crates/tokscale-core/src/sessions/synthetic.rs +++ /dev/null @@ -1,365 +0,0 @@ -//! Synthetic.new detection and Octofriend session parser -//! -//! Detects synthetic.new API usage across existing agent sessions by model/provider patterns, -//! and parses Octofriend's SQLite database when token data is available. - -use super::utils::open_readonly_sqlite; -use super::UnifiedMessage; -use crate::TokenBreakdown; -use std::path::Path; - -// ============================================================================= -// Detection Functions (Strategy 1: detect synthetic.new usage in other sources) -// ============================================================================= - -/// Check if a model ID indicates synthetic.new API usage. -/// -/// synthetic.new uses `hf:` prefixed model IDs in requests and may return -/// provider-prefixed model IDs like `accounts/fireworks/models/...` in responses. -pub fn is_synthetic_model(model_id: &str) -> bool { - let lower = model_id.to_lowercase(); - - // HuggingFace-style model IDs used by synthetic.new - if lower.starts_with("hf:") { - return true; - } - - // Fireworks provider-prefixed responses - if lower.starts_with("accounts/fireworks/") { - return true; - } - - // Together AI provider-prefixed responses - if lower.starts_with("accounts/together/") { - return true; - } - - false -} - -/// Check if a provider ID indicates synthetic.new API usage. -pub fn is_synthetic_provider(provider_id: &str) -> bool { - let lower = provider_id.to_lowercase(); - matches!( - lower.as_str(), - "synthetic" | "glhf" | "synthetic.new" | "octofriend" - ) -} - -/// Check if a message appears to have been routed through Synthetic's gateway. -pub fn is_synthetic_gateway(model_id: &str, provider_id: &str) -> bool { - is_synthetic_model(model_id) || is_synthetic_provider(provider_id) -} - -// ============================================================================= -// Model name normalization (strip synthetic.new prefixes for pricing lookup) -// ============================================================================= - -/// Normalize a synthetic.new model ID to a standard form for pricing lookup. -/// e.g. "hf:deepseek-ai/DeepSeek-V3-0324" -> "deepseek-v3-0324" -/// e.g. "accounts/fireworks/models/deepseek-v3-0324" -> "deepseek-v3-0324" -pub fn normalize_synthetic_model(model_id: &str) -> String { - let lower = model_id.to_lowercase(); - - // Strip "hf:" prefix and org name - if let Some(rest) = lower.strip_prefix("hf:") { - // "hf:deepseek-ai/DeepSeek-V3-0324" -> "deepseek-v3-0324" - if let Some((_org, model)) = rest.split_once('/') { - return model.to_string(); - } - return rest.to_string(); - } - - // Strip "accounts//models/" prefix - if let Some(rest) = lower.strip_prefix("accounts/") { - // "accounts/fireworks/models/deepseek-v3-0324" -> "deepseek-v3-0324" - if let Some(models_rest) = rest.split_once("/models/") { - return models_rest.1.to_string(); - } - } - - lower -} - -/// Normalize synthetic gateway fields without changing the originating client. -pub fn normalize_synthetic_gateway_fields(model_id: &mut String, provider_id: &mut String) -> bool { - if !is_synthetic_gateway(model_id, provider_id) { - return false; - } - - *model_id = normalize_synthetic_model(model_id); - if provider_id.is_empty() || provider_id.eq_ignore_ascii_case("unknown") { - *provider_id = "synthetic".to_string(); - } - - true -} - -/// Compatibility matcher for `--synthetic` / synthetic source selection. -pub fn matches_synthetic_filter(client: &str, model_id: &str, provider_id: &str) -> bool { - client.eq_ignore_ascii_case("synthetic") || is_synthetic_gateway(model_id, provider_id) -} - -// ============================================================================= -// Octofriend SQLite Parser (Strategy 2: parse Octofriend sessions) -// ============================================================================= - -/// Parse Octofriend's SQLite database for token usage data. -/// -/// Currently Octofriend only stores input_history (no token data). -/// This function checks for token-related tables and parses them when available, -/// making it future-proof for when Octofriend adds token persistence. -pub fn parse_octofriend_sqlite(db_path: &Path) -> Vec { - let Some(conn) = open_readonly_sqlite(db_path) else { - return Vec::new(); - }; - - // Check if a token-tracking table exists (future-proofing) - // Octofriend may add tables like 'messages', 'sessions', or 'token_usage' - let has_messages_table: bool = conn - .query_row( - "SELECT count(*) FROM sqlite_master WHERE type='table' AND name IN ('messages', 'sessions', 'token_usage')", - [], - |row| row.get::<_, i64>(0), - ) - .map(|count| count > 0) - .unwrap_or(false); - - if !has_messages_table { - return Vec::new(); - } - - // If messages table exists, attempt to parse it - // This follows the OpenCode SQLite pattern: - // SELECT id, session_id, data FROM messages WHERE role = 'assistant' AND tokens IS NOT NULL - let mut messages = Vec::new(); - - // Try 'messages' table first (most likely schema) - if let Ok(mut stmt) = conn.prepare( - "SELECT id, model, input_tokens, output_tokens, cache_read_tokens, cache_write_tokens, reasoning_tokens, cost, timestamp, session_id, provider FROM messages WHERE input_tokens IS NOT NULL OR output_tokens IS NOT NULL", - ) { - if let Ok(rows) = stmt.query_map([], |row| { - let id: String = row.get(0)?; - let model_id: String = row.get::<_, String>(1).unwrap_or_default(); - let input: i64 = row.get::<_, i64>(2).unwrap_or(0); - let output: i64 = row.get::<_, i64>(3).unwrap_or(0); - let cache_read: i64 = row.get::<_, i64>(4).unwrap_or(0); - let cache_write: i64 = row.get::<_, i64>(5).unwrap_or(0); - let reasoning: i64 = row.get::<_, i64>(6).unwrap_or(0); - let cost: f64 = row.get::<_, f64>(7).unwrap_or(0.0); - let timestamp: f64 = row.get::<_, f64>(8).unwrap_or(0.0); - let session_id: String = row.get::<_, String>(9).unwrap_or_else(|_| "unknown".to_string()); - let provider: String = row.get::<_, String>(10).unwrap_or_else(|_| "synthetic".to_string()); - - Ok((id, model_id, input, output, cache_read, cache_write, reasoning, cost, timestamp, session_id, provider)) - }) { - for row_result in rows.flatten() { - let (id, model_id, input, output, cache_read, cache_write, reasoning, cost, timestamp, session_id, provider) = row_result; - - let total = input + output + cache_read + cache_write + reasoning; - if total == 0 { - continue; - } - - let ts_ms = if timestamp > 1e12 { - timestamp as i64 - } else { - (timestamp * 1000.0) as i64 - }; - - let mut msg = UnifiedMessage::new( - "synthetic", - normalize_synthetic_model(&model_id), - provider, - session_id, - ts_ms, - TokenBreakdown { - input: input.max(0), - output: output.max(0), - cache_read: cache_read.max(0), - cache_write: cache_write.max(0), - reasoning: reasoning.max(0), - }, - cost.max(0.0), - ); - msg.dedup_key = Some(id); - messages.push(msg); - } - } - } - - // Try 'token_usage' table as alternative schema - if messages.is_empty() { - if let Ok(mut stmt) = conn.prepare( - "SELECT id, model, input_tokens, output_tokens, timestamp, session_id FROM token_usage WHERE input_tokens > 0 OR output_tokens > 0", - ) { - if let Ok(rows) = stmt.query_map([], |row| { - let id: String = row.get(0)?; - let model_id: String = row.get::<_, String>(1).unwrap_or_default(); - let input: i64 = row.get::<_, i64>(2).unwrap_or(0); - let output: i64 = row.get::<_, i64>(3).unwrap_or(0); - let timestamp: f64 = row.get::<_, f64>(4).unwrap_or(0.0); - let session_id: String = row.get::<_, String>(5).unwrap_or_else(|_| "unknown".to_string()); - - Ok((id, model_id, input, output, timestamp, session_id)) - }) { - for row_result in rows.flatten() { - let (id, model_id, input, output, timestamp, session_id) = row_result; - - let ts_ms = if timestamp > 1e12 { - timestamp as i64 - } else { - (timestamp * 1000.0) as i64 - }; - - let mut msg = UnifiedMessage::new( - "synthetic", - normalize_synthetic_model(&model_id), - "synthetic", - session_id, - ts_ms, - TokenBreakdown { - input: input.max(0), - output: output.max(0), - cache_read: 0, - cache_write: 0, - reasoning: 0, - }, - 0.0, - ); - msg.dedup_key = Some(id); - messages.push(msg); - } - } - } - } - - messages -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_is_synthetic_model_hf_prefix() { - assert!(is_synthetic_model("hf:deepseek-ai/DeepSeek-V3-0324")); - assert!(is_synthetic_model("hf:zai-org/GLM-4.7")); - assert!(is_synthetic_model("hf:moonshotai/Kimi-K2.5")); - assert!(is_synthetic_model("hf:MiniMaxAI/MiniMax-M2.1")); - } - - #[test] - fn test_is_synthetic_model_fireworks_prefix() { - assert!(is_synthetic_model( - "accounts/fireworks/models/deepseek-v3-0324" - )); - assert!(is_synthetic_model("accounts/fireworks/models/glm-4.7")); - } - - #[test] - fn test_is_synthetic_model_together_prefix() { - assert!(is_synthetic_model("accounts/together/models/qwen3-235b")); - } - - #[test] - fn test_is_synthetic_model_negative() { - assert!(!is_synthetic_model("claude-sonnet-4-5")); - assert!(!is_synthetic_model("gpt-5.2-codex")); - assert!(!is_synthetic_model("deepseek-v3")); - assert!(!is_synthetic_model("gemini-2.5-pro")); - } - - #[test] - fn test_is_synthetic_provider() { - assert!(is_synthetic_provider("synthetic")); - assert!(is_synthetic_provider("glhf")); - assert!(is_synthetic_provider("Synthetic")); - assert!(is_synthetic_provider("GLHF")); - assert!(is_synthetic_provider("synthetic.new")); - assert!(is_synthetic_provider("octofriend")); - } - - #[test] - fn test_is_synthetic_provider_negative() { - assert!(!is_synthetic_provider("anthropic")); - assert!(!is_synthetic_provider("openai")); - assert!(!is_synthetic_provider("moonshot")); - assert!(!is_synthetic_provider("fireworks")); - } - - #[test] - fn test_normalize_synthetic_model_hf() { - assert_eq!( - normalize_synthetic_model("hf:deepseek-ai/DeepSeek-V3-0324"), - "deepseek-v3-0324" - ); - assert_eq!(normalize_synthetic_model("hf:zai-org/GLM-4.7"), "glm-4.7"); - assert_eq!( - normalize_synthetic_model("hf:moonshotai/Kimi-K2.5"), - "kimi-k2.5" - ); - } - - #[test] - fn test_normalize_synthetic_model_fireworks() { - assert_eq!( - normalize_synthetic_model("accounts/fireworks/models/deepseek-v3-0324"), - "deepseek-v3-0324" - ); - } - - #[test] - fn test_normalize_synthetic_model_passthrough() { - assert_eq!( - normalize_synthetic_model("claude-sonnet-4-5"), - "claude-sonnet-4-5" - ); - assert_eq!(normalize_synthetic_model("gpt-4o"), "gpt-4o"); - } - - #[test] - fn test_normalize_synthetic_gateway_fields_sets_provider_when_unknown() { - let mut model_id = "hf:deepseek-ai/DeepSeek-V3-0324".to_string(); - let mut provider_id = "unknown".to_string(); - - let matched = normalize_synthetic_gateway_fields(&mut model_id, &mut provider_id); - - assert!(matched); - assert_eq!(model_id, "deepseek-v3-0324"); - assert_eq!(provider_id, "synthetic"); - } - - #[test] - fn test_normalize_synthetic_gateway_fields_preserves_existing_provider() { - let mut model_id = "accounts/fireworks/models/deepseek-v3-0324".to_string(); - let mut provider_id = "fireworks".to_string(); - - let matched = normalize_synthetic_gateway_fields(&mut model_id, &mut provider_id); - - assert!(matched); - assert_eq!(model_id, "deepseek-v3-0324"); - assert_eq!(provider_id, "fireworks"); - } - - #[test] - fn test_matches_synthetic_filter_accepts_gateway_traffic_without_rewriting_client() { - assert!(matches_synthetic_filter( - "opencode", - "hf:deepseek-ai/DeepSeek-V3-0324", - "unknown" - )); - assert!(matches_synthetic_filter( - "claude", - "claude-sonnet-4-5", - "glhf" - )); - assert!(!matches_synthetic_filter("opencode", "gpt-4o", "anthropic")); - } - - #[test] - fn test_parse_octofriend_sqlite_nonexistent() { - let result = parse_octofriend_sqlite(Path::new("/nonexistent/path/sqlite.db")); - assert!(result.is_empty()); - } -} diff --git a/packages/frontend/src/components/SourceLogo.tsx b/packages/frontend/src/components/SourceLogo.tsx index 2f95ebe0e..2fe4f3298 100644 --- a/packages/frontend/src/components/SourceLogo.tsx +++ b/packages/frontend/src/components/SourceLogo.tsx @@ -65,8 +65,6 @@ export function SourceLogo({ sourceId, height = 14, className = "" }: SourceLogo return "/assets/logos/kiro.ico"; case "zed": return "https://raw.githubusercontent.com/junhoyeo/tokscale/main/.github/assets/client-zed.webp"; - case "synthetic": - return "/assets/logos/synthetic.png"; default: return null; } diff --git a/packages/frontend/src/lib/constants.ts b/packages/frontend/src/lib/constants.ts index 810761c0b..802ae79fc 100644 --- a/packages/frontend/src/lib/constants.ts +++ b/packages/frontend/src/lib/constants.ts @@ -53,7 +53,6 @@ export const SOURCE_DISPLAY_NAMES: Record = { zed: "Zed Agent", trae: "Trae", warp: "Warp", - synthetic: "Synthetic", }; // Client logos from GitHub CDN (public repo) @@ -86,7 +85,6 @@ export const SOURCE_LOGOS: Record = { zed: `${GITHUB_CDN_BASE}/client-zed.webp`, trae: `${GITHUB_CDN_BASE}/client-trae.png`, warp: `${GITHUB_CDN_BASE}/client-warp.png`, - synthetic: `${GITHUB_CDN_BASE}/client-synthetic.png`, }; export const SOURCE_COLORS: Record = { @@ -117,7 +115,6 @@ export const SOURCE_COLORS: Record = { zed: "#084CCF", trae: "#00BFA5", warp: "#01A4A4", - synthetic: "#4ADE80", }; export const SOURCE_TEXT_COLORS: Partial> = { diff --git a/packages/frontend/src/lib/types.ts b/packages/frontend/src/lib/types.ts index a1e482c54..eec0973a3 100644 --- a/packages/frontend/src/lib/types.ts +++ b/packages/frontend/src/lib/types.ts @@ -25,7 +25,6 @@ export const SUPPORTED_CLIENT_TYPES = [ "zed", "trae", "warp", - "synthetic", ] as const; export type CcMirrorClientType = `cc-mirror/${string}`; From eb6d072b3d3a040a9729f7fea06f44d761300181 Mon Sep 17 00:00:00 2001 From: makoMakoGo <48956204+makoMakoGo@users.noreply.github.com> Date: Sun, 7 Jun 2026 05:08:35 +0800 Subject: [PATCH 2/3] refactor: avoid duplicate gateway normalization --- crates/tokscale-core/src/pricing/custom.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tokscale-core/src/pricing/custom.rs b/crates/tokscale-core/src/pricing/custom.rs index 7807a36fe..6e841d674 100644 --- a/crates/tokscale-core/src/pricing/custom.rs +++ b/crates/tokscale-core/src/pricing/custom.rs @@ -249,7 +249,7 @@ impl CustomPricing { }); } - let normalized_key = normalize_gateway_model_path(model_id).to_lowercase(); + let normalized_key = normalize_gateway_model_path(model_id); if normalized_key != raw_key { if let Some(pricing) = self.models.get_key_value(&normalized_key) { return Some(CustomLookupResult { From ed7b1d22be0373dd41baaa40812821c54b491920 Mon Sep 17 00:00:00 2001 From: makoMakoGo <48956204+makoMakoGo@users.noreply.github.com> Date: Sun, 7 Jun 2026 14:18:44 +0800 Subject: [PATCH 3/3] fix(cli): reject stale client defaults --- crates/tokscale-cli/src/main.rs | 185 ++++++++++++--------- crates/tokscale-cli/src/tui/cache.rs | 62 ++++++- crates/tokscale-cli/src/tui/mod.rs | 3 +- crates/tokscale-core/src/pricing/custom.rs | 19 ++- 4 files changed, 183 insertions(+), 86 deletions(-) diff --git a/crates/tokscale-cli/src/main.rs b/crates/tokscale-cli/src/main.rs index 0a396d0a8..49f033cad 100644 --- a/crates/tokscale-cli/src/main.rs +++ b/crates/tokscale-cli/src/main.rs @@ -453,7 +453,7 @@ fn main() -> Result<()> { let month = date.month; let (since, until) = build_date_filter(today, week, month, date.since, date.until); let year = normalize_year_filter(today, week, month, date.year); - let clients = build_client_filter(clients, &cli.home); + let clients = build_client_filter(clients, &cli.home)?; if json || light || !can_use_tui { run_models_report( json, @@ -499,7 +499,7 @@ fn main() -> Result<()> { let month = date.month; let (since, until) = build_date_filter(today, week, month, date.since, date.until); let year = normalize_year_filter(today, week, month, date.year); - let clients = build_client_filter(clients, &cli.home); + let clients = build_client_filter(clients, &cli.home)?; if json || light || !can_use_tui { run_monthly_report( json, @@ -542,7 +542,7 @@ fn main() -> Result<()> { let month = date.month; let (since, until) = build_date_filter(today, week, month, date.since, date.until); let year = normalize_year_filter(today, week, month, date.year); - let clients = build_client_filter(clients, &cli.home); + let clients = build_client_filter(clients, &cli.home)?; if json || light || !can_use_tui { run_hourly_report( json, @@ -610,7 +610,7 @@ fn main() -> Result<()> { let month = date.month; let (since, until) = build_date_filter(today, week, month, date.since, date.until); let year = normalize_year_filter(today, week, month, date.year); - let clients = build_client_filter(clients, &cli.home); + let clients = build_client_filter(clients, &cli.home)?; run_graph_command( output, cli.home.clone(), @@ -629,7 +629,7 @@ fn main() -> Result<()> { let month = date.month; let (since, until) = build_date_filter(today, week, month, date.since, date.until); let year = normalize_year_filter(today, week, month, date.year); - let clients = build_client_filter(clients, &cli.home); + let clients = build_client_filter(clients, &cli.home)?; auto_sync_cursor_before_tui(&cli.home, &clients)?; tui::run( &cli.theme, @@ -658,7 +658,7 @@ fn main() -> Result<()> { // to fire when the user passes no client flags, not the user's general // defaultClients view filter (which may exclude clients they still want // to upload). Pass an explicit empty defaults slice. - let clients = build_client_filter_with_defaults(clients, &[]); + let clients = build_client_filter_with_defaults(clients, &[])?; run_submit_command(clients, since, until, year, dry_run) } Some(Commands::Headless { @@ -682,7 +682,7 @@ fn main() -> Result<()> { no_spinner: _, }) => { reject_unsupported_home_override(&cli.home, "wrapped")?; - let client_filter = build_client_filter(client_flags, &cli.home); + let client_filter = build_client_filter(client_flags, &cli.home)?; run_wrapped_command( output, year, @@ -728,7 +728,7 @@ fn main() -> Result<()> { let month = date.month; let (since, until) = build_date_filter(today, week, month, date.since, date.until); let year = normalize_year_filter(today, week, month, date.year); - let clients = build_client_filter(clients, &cli.home); + let clients = build_client_filter(clients, &cli.home)?; run_time_metrics_report( json, cli.home.clone(), @@ -744,7 +744,7 @@ fn main() -> Result<()> { let today = cli.date.today; let week = cli.date.week; let month = cli.date.month; - let clients = build_client_filter(cli.clients, &cli.home); + let clients = build_client_filter(cli.clients, &cli.home)?; let (since, until) = build_date_filter(today, week, month, cli.date.since, cli.date.until); let year = normalize_year_filter(today, week, month, cli.date.year); @@ -953,8 +953,8 @@ impl ClientFilter { /// Parse a canonical lowercase identifier (the same form /// `as_filter_str` returns) into a `ClientFilter`. Returns `None` for - /// any unknown id so callers can drop unrecognized settings entries - /// without erroring. + /// any unknown id; callers decide whether unknown input is a user-facing + /// configuration error or already-validated CLI data. pub fn from_filter_str(s: &str) -> Option { Self::value_variants() .iter() @@ -1070,18 +1070,21 @@ pub struct DateRangeFlags { /// /// Returns `None` when no filters are active *and* no defaults configured /// so the caller can scan all clients. -fn build_client_filter(flags: ClientFlags, home_dir: &Option) -> Option> { +fn build_client_filter( + flags: ClientFlags, + home_dir: &Option, +) -> Result>> { let defaults = tui::settings::load_default_clients_for_home(home_dir); build_client_filter_with_defaults(flags, &defaults) } /// Pure variant of [`build_client_filter`] for unit-testable resolution. -/// `defaults` is the (already-validated) list of canonical filter ids that +/// `defaults` is the raw list of configured filter ids that /// should apply when no CLI flag is present. fn build_client_filter_with_defaults( flags: ClientFlags, defaults: &[String], -) -> Option> { +) -> Result>> { let mut ordered: Vec = Vec::new(); let mut seen: std::collections::HashSet = std::collections::HashSet::new(); @@ -1136,28 +1139,48 @@ fn build_client_filter_with_defaults( emit_legacy_client_flag_warning(&legacy_used); } - // Defaults only apply when the user passed neither canonical nor legacy - // flags. CLI flags always win — predictable semantics over "merge". - // Unknown / typo'd ids are dropped silently so a stale settings.json - // entry never breaks tokscale. if ordered.is_empty() { - for raw in defaults { - if let Some(client) = ClientFilter::from_filter_str(raw) { - let id = client.as_filter_str().to_string(); - if seen.insert(id.clone()) { - ordered.push(id); - } + for client in parse_default_client_filters(defaults)? { + let id = client.as_filter_str().to_string(); + if seen.insert(id.clone()) { + ordered.push(id); } } } if ordered.is_empty() { - None + Ok(None) } else { - Some(ordered) + Ok(Some(ordered)) } } +fn parse_default_client_filters(defaults: &[String]) -> Result> { + let mut parsed = Vec::new(); + let mut invalid = Vec::new(); + + for raw in defaults { + match ClientFilter::from_filter_str(raw) { + Some(client) => parsed.push(client), + None => invalid.push(raw.as_str()), + } + } + + if invalid.is_empty() { + return Ok(parsed); + } + + let valid = ClientFilter::value_variants() + .iter() + .map(ClientFilter::as_filter_str) + .collect::>() + .join(", "); + anyhow::bail!( + "invalid client id(s) in settings.json defaultClients: {}. Remove stale entries such as `synthetic` or use one of: {valid}", + invalid.join(", ") + ); +} + /// Emits a single stderr deprecation warning when legacy `--` flags /// are used. Suppressed entirely when stderr is not a TTY (e.g. when piping /// JSON output through scripts) so machine-parseable output stays clean. @@ -5094,7 +5117,7 @@ fn spawn_warm_tui_cache_detached() { /// when the user passes no CLI client flag: /// /// 1. If `defaultClients` from `~/.config/tokscale/settings.json` is -/// set, use that (after dropping unknown ids). +/// set, use it after validating every id. /// 2. Otherwise fall back to `ClientFilter::default_set()` (every real /// client). /// @@ -5103,7 +5126,7 @@ fn spawn_warm_tui_cache_detached() { /// `submit` warm cache uses one filter set while the next no-flag TUI /// launch wants another, the cache key mismatches, and the warming /// becomes a wasted background scan. -fn resolve_default_tui_filter_set() -> std::collections::HashSet { +fn resolve_default_tui_filter_set() -> Result> { resolve_default_tui_filter_set_with(&tui::settings::load_default_clients()) } @@ -5112,15 +5135,12 @@ fn resolve_default_tui_filter_set() -> std::collections::HashSet { /// from settings.json. fn resolve_default_tui_filter_set_with( configured: &[String], -) -> std::collections::HashSet { - let parsed: Vec = configured - .iter() - .filter_map(|s| ClientFilter::from_filter_str(s)) - .collect(); +) -> Result> { + let parsed = parse_default_client_filters(configured)?; if parsed.is_empty() { - ClientFilter::default_set() + Ok(ClientFilter::default_set()) } else { - parsed.into_iter().collect() + Ok(parsed.into_iter().collect()) } } @@ -5147,7 +5167,7 @@ fn resolve_light_cache_filter_set( .filter_map(|client| ClientFilter::from_filter_str(client)) .collect() } else { - resolve_default_tui_filter_set() + ClientFilter::default_set() } } @@ -5173,10 +5193,11 @@ fn write_light_cache( } let enabled_set = resolve_light_cache_filter_set(clients); - let scan_clients: Vec = enabled_set + let mut scan_clients: Vec = enabled_set .iter() .filter_map(|filter| filter.to_client_id()) .collect(); + scan_clients.sort_by_key(|client| *client as usize); // The report has already been flushed to stdout by the time we reach // here. Keep the report exit code stable, but expose cache scan/write @@ -5218,11 +5239,12 @@ fn run_warm_tui_cache() -> Result<()> { // `GroupBy::default()` is `GroupBy::ClientModel`, so the warm cache // was written under a key the TUI never queried. Every submit // silently invalidated the next TUI launch. - let enabled_set = resolve_default_tui_filter_set(); - let scan_clients: Vec = enabled_set + let enabled_set = resolve_default_tui_filter_set()?; + let mut scan_clients: Vec = enabled_set .iter() .filter_map(|f| f.to_client_id()) .collect(); + scan_clients.sort_by_key(|client| *client as usize); let loader = DataLoader::with_filters(None, None, None, None); let data = loader.load(&scan_clients, &TUI_DEFAULT_GROUP_BY)?; save_cached_data( @@ -5739,7 +5761,7 @@ mod tests { #[test] fn test_build_client_filter_all_false() { let flags = ClientFlags::default(); - assert_eq!(build_client_filter_with_defaults(flags, &[]), None); + assert_eq!(build_client_filter_with_defaults(flags, &[]).unwrap(), None); } #[test] @@ -5749,7 +5771,7 @@ mod tests { ..ClientFlags::default() }; assert_eq!( - build_client_filter_with_defaults(flags, &[]), + build_client_filter_with_defaults(flags, &[]).unwrap(), Some(vec!["opencode".to_string()]) ); } @@ -5767,7 +5789,7 @@ mod tests { // a deliberate trade-off: legacy flags are deprecated, and the // canonical `--client a,b,c` form preserves user order. assert_eq!( - build_client_filter_with_defaults(flags, &[]), + build_client_filter_with_defaults(flags, &[]).unwrap(), Some(vec![ "opencode".to_string(), "claude".to_string(), @@ -5806,7 +5828,7 @@ mod tests { warp: true, ..ClientFlags::default() }; - let result = build_client_filter_with_defaults(flags, &[]); + let result = build_client_filter_with_defaults(flags, &[]).unwrap(); assert!(result.is_some()); let sources = result.unwrap(); let required = [ @@ -5862,7 +5884,7 @@ mod tests { ..ClientFlags::default() }; assert_eq!( - build_client_filter_with_defaults(flags, &[]), + build_client_filter_with_defaults(flags, &[]).unwrap(), Some(vec![ "claude".to_string(), "opencode".to_string(), @@ -5882,7 +5904,7 @@ mod tests { ..ClientFlags::default() }; assert_eq!( - build_client_filter_with_defaults(flags, &[]), + build_client_filter_with_defaults(flags, &[]).unwrap(), Some(vec!["claude".to_string(), "opencode".to_string()]) ); } @@ -5899,7 +5921,7 @@ mod tests { ..ClientFlags::default() }; assert_eq!( - build_client_filter_with_defaults(flags, &[]), + build_client_filter_with_defaults(flags, &[]).unwrap(), Some(vec!["claude".to_string(), "opencode".to_string()]) ); } @@ -5993,7 +6015,7 @@ mod tests { // client while the next no-flag TUI launch wants only the configured // ones, producing a guaranteed cache miss. let configured = vec!["opencode".to_string(), "claude".to_string()]; - let set = resolve_default_tui_filter_set_with(&configured); + let set = resolve_default_tui_filter_set_with(&configured).unwrap(); let mut expected = std::collections::HashSet::new(); expected.insert(ClientFilter::Opencode); expected.insert(ClientFilter::Claude); @@ -6003,39 +6025,38 @@ mod tests { #[test] fn test_resolve_default_tui_filter_set_falls_back_when_empty() { // No defaultClients configured → use the canonical default set. - let set = resolve_default_tui_filter_set_with(&[]); + let set = resolve_default_tui_filter_set_with(&[]).unwrap(); assert_eq!(set, ClientFilter::default_set()); } #[test] - fn test_resolve_default_tui_filter_set_drops_unknown_ids() { - // A stale settings.json entry (renamed/removed client) must not - // crash; unknown ids are dropped and the resolver still produces - // a usable filter set. + fn test_resolve_default_tui_filter_set_rejects_unknown_ids() { let configured = vec!["opencode".to_string(), "not-a-real-client".to_string()]; - let set = resolve_default_tui_filter_set_with(&configured); - let mut expected = std::collections::HashSet::new(); - expected.insert(ClientFilter::Opencode); - assert_eq!(set, expected); + let err = resolve_default_tui_filter_set_with(&configured).unwrap_err(); + assert!( + err.to_string().contains("not-a-real-client"), + "unexpected error: {err}" + ); } #[test] - fn test_resolve_default_tui_filter_set_all_unknown_falls_back() { - // If every configured id is invalid, treat as if nothing is - // configured rather than producing an empty filter set (which - // would mean "scan nothing", definitely not the intent). + fn test_resolve_default_tui_filter_set_rejects_all_unknown_ids() { let configured = vec!["not-real".to_string(), "also-fake".to_string()]; - let set = resolve_default_tui_filter_set_with(&configured); - assert_eq!(set, ClientFilter::default_set()); + let err = resolve_default_tui_filter_set_with(&configured).unwrap_err(); + assert!( + err.to_string().contains("not-real, also-fake"), + "unexpected error: {err}" + ); } #[test] - fn test_resolve_default_tui_filter_set_drops_removed_client_id() { - let configured = vec!["claude".to_string(), "removed-client".to_string()]; - let set = resolve_default_tui_filter_set_with(&configured); - let mut expected = std::collections::HashSet::new(); - expected.insert(ClientFilter::Claude); - assert_eq!(set, expected); + fn test_resolve_default_tui_filter_set_rejects_removed_synthetic_id() { + let configured = vec!["claude".to_string(), "synthetic".to_string()]; + let err = resolve_default_tui_filter_set_with(&configured).unwrap_err(); + assert!( + err.to_string().contains("synthetic"), + "unexpected error: {err}" + ); } #[test] @@ -6044,7 +6065,7 @@ mod tests { let flags = ClientFlags::default(); let defaults = vec!["opencode".to_string(), "claude".to_string()]; assert_eq!( - build_client_filter_with_defaults(flags, &defaults), + build_client_filter_with_defaults(flags, &defaults).unwrap(), Some(vec!["opencode".to_string(), "claude".to_string()]) ); } @@ -6060,7 +6081,7 @@ mod tests { }; let defaults = vec!["opencode".to_string(), "claude".to_string()]; assert_eq!( - build_client_filter_with_defaults(flags, &defaults), + build_client_filter_with_defaults(flags, &defaults).unwrap(), Some(vec!["codex".to_string()]) ); } @@ -6076,20 +6097,19 @@ mod tests { }; let defaults = vec!["claude".to_string()]; assert_eq!( - build_client_filter_with_defaults(flags, &defaults), + build_client_filter_with_defaults(flags, &defaults).unwrap(), Some(vec!["opencode".to_string()]) ); } #[test] - fn test_build_client_filter_defaults_dropped_for_unknown_ids() { - // Stale settings entry (e.g. removed/renamed client) → silently - // dropped, never errors. Ensures a typo never breaks tokscale. + fn test_build_client_filter_defaults_reject_unknown_ids() { let flags = ClientFlags::default(); let defaults = vec!["opencode".to_string(), "not-a-client".to_string()]; - assert_eq!( - build_client_filter_with_defaults(flags, &defaults), - Some(vec!["opencode".to_string()]) + let err = build_client_filter_with_defaults(flags, &defaults).unwrap_err(); + assert!( + err.to_string().contains("not-a-client"), + "unexpected error: {err}" ); } @@ -6102,7 +6122,7 @@ mod tests { "claude".to_string(), ]; assert_eq!( - build_client_filter_with_defaults(flags, &defaults), + build_client_filter_with_defaults(flags, &defaults).unwrap(), Some(vec!["claude".to_string(), "opencode".to_string()]) ); } @@ -6111,7 +6131,10 @@ mod tests { fn test_build_client_filter_no_flags_no_defaults_returns_none() { let flags = ClientFlags::default(); let defaults: Vec = vec![]; - assert_eq!(build_client_filter_with_defaults(flags, &defaults), None); + assert_eq!( + build_client_filter_with_defaults(flags, &defaults).unwrap(), + None + ); } #[test] @@ -6244,7 +6267,7 @@ mod tests { let flags = ClientFlags::default(); let defaults = vec!["opencode".to_string(), "claude".to_string()]; assert_eq!( - build_client_filter_with_defaults(flags, &defaults), + build_client_filter_with_defaults(flags, &defaults).unwrap(), Some(vec!["opencode".to_string(), "claude".to_string()]) ); } @@ -6252,7 +6275,7 @@ mod tests { #[test] fn test_build_client_filter_with_defaults_empty_defaults_returns_none() { let flags = ClientFlags::default(); - assert_eq!(build_client_filter_with_defaults(flags, &[]), None); + assert_eq!(build_client_filter_with_defaults(flags, &[]).unwrap(), None); } #[test] diff --git a/crates/tokscale-cli/src/tui/cache.rs b/crates/tokscale-cli/src/tui/cache.rs index 2bc7cca10..b0dd285ff 100644 --- a/crates/tokscale-cli/src/tui/cache.rs +++ b/crates/tokscale-cli/src/tui/cache.rs @@ -22,7 +22,7 @@ use super::data::{ /// Cache staleness threshold: 5 minutes (matches TS implementation) const CACHE_STALE_THRESHOLD_MS: u64 = 5 * 60 * 1000; -const CACHE_SCHEMA_VERSION: u32 = 13; +const CACHE_SCHEMA_VERSION: u32 = 14; #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] @@ -962,7 +962,7 @@ mod tests { fs::write( &cache_path, r#"{ - "schemaVersion": 13, + "schemaVersion": 14, "timestamp": 9999999999999, "enabledClients": ["claude"], "groupBy": "model", @@ -1003,6 +1003,62 @@ mod tests { } } + #[test] + #[serial] + fn test_load_cache_misses_old_include_synthetic_schema() { + let temp_dir = TempDir::new().unwrap(); + let previous_home = env::var_os("HOME"); + unsafe { + env::set_var("HOME", temp_dir.path()); + } + + let cache_path = cache_file().unwrap(); + fs::create_dir_all(cache_path.parent().unwrap()).unwrap(); + fs::write( + &cache_path, + r#"{ + "schemaVersion": 13, + "timestamp": 9999999999999, + "enabledClients": ["claude"], + "includeSynthetic": true, + "groupBy": "model", + "reportScope": { + "since": null, + "until": null, + "year": null + }, + "data": { + "models": [], + "agents": [], + "daily": [], + "hourly": [], + "graph": null, + "totalTokens": 0, + "totalCost": 0.0, + "currentStreak": 0, + "longestStreak": 0 + } +}"#, + ) + .unwrap(); + + let clients = make_filters(&[ClientFilter::Claude]); + assert!(matches!( + load_cache( + &clients, + &GroupBy::Model, + &CacheReportScope::default(), + false + ), + CacheResult::Miss + )); + + match previous_home { + Some(home) => unsafe { env::set_var("HOME", home) }, + None => unsafe { env::remove_var("HOME") }, + } + } + #[test] #[serial] fn test_load_cache_misses_when_report_scope_differs() { @@ -1228,7 +1284,7 @@ mod tests { fs::create_dir_all(cache_path.parent().unwrap()).unwrap(); let mut cached: serde_json::Value = serde_json::from_str( r#"{ - "schemaVersion": 13, + "schemaVersion": 14, "timestamp": 0, "enabledClients": ["claude", "cursor"], "groupBy": "model", diff --git a/crates/tokscale-cli/src/tui/mod.rs b/crates/tokscale-cli/src/tui/mod.rs index 0cce4a204..dae5f8a02 100644 --- a/crates/tokscale-cli/src/tui/mod.rs +++ b/crates/tokscale-cli/src/tui/mod.rs @@ -174,10 +174,11 @@ pub fn run( let tx = bg_tx.clone(); // Project the filter set into the client list the loader consumes. - let bg_clients: Vec = enabled_clients + let mut bg_clients: Vec = enabled_clients .iter() .filter_map(|f| f.to_client_id()) .collect(); + bg_clients.sort_by_key(|client| *client as usize); let bg_since = since.clone(); let bg_until = until.clone(); let bg_year = year.clone(); diff --git a/crates/tokscale-core/src/pricing/custom.rs b/crates/tokscale-core/src/pricing/custom.rs index 6e841d674..09d36e62d 100644 --- a/crates/tokscale-core/src/pricing/custom.rs +++ b/crates/tokscale-core/src/pricing/custom.rs @@ -318,7 +318,10 @@ fn normalize_gateway_model_path(model_id: &str) -> String { } if let Some(rest) = lower.strip_prefix("accounts/") { - if let Some((_, model)) = rest.split_once("/models/") { + if let Some((_, model)) = rest + .split_once("/models/") + .or_else(|| rest.split_once("/routers/")) + { return model.to_string(); } } @@ -457,6 +460,20 @@ mod tests { assert_eq!(pricing.cache_read_input_token_cost, Some(0.0000003)); } + #[test] + fn gateway_router_path_matches_base_model_key() { + let mut models = HashMap::new(); + models.insert("kimi-k2p6-turbo".to_string(), pricing(2.0, 8.0)); + let loaded = CustomPricing::from_models(models); + + let result = loaded + .lookup_with_key("accounts/fireworks/routers/kimi-k2p6-turbo") + .unwrap(); + + assert_eq!(result.matched_key, "kimi-k2p6-turbo"); + assert_eq!(result.pricing.input_cost_per_token, Some(2.0)); + } + #[test] fn loads_litellm_per_token_fields() { let temp = TempDir::new().unwrap();