CodeVetter · Repo Unpack · System map
farion1231/cc-switch
The process entry is src-tauri/src/main.rs, which only adjusts Linux WebKit environment variables and calls cc_switch_lib::run(). lib.rs owns the Tauri builder: single-instance, deep-link, dialog, updater, window-state, and a very large invoke_handler. Shared state is AppState { db, proxy_service, usage_cache, codex_oauth_manager }. Durable app data is rusqlite at ~/.cc-switch/cc-switch.db (SCHEMA_VERSION 19); device settings are a separate JSON file. The renderer is Vite rooted at src/, dev server port 3000, production output ../dist. CI splits frontend (pnpm) and backend (cargo on three OSes plus a Windows+WSL2 job). Tagged v* pushes build Windows, macOS, and Linux artifacts, including arm64, with a signed updater.
- package.json name cc-switch version 3.20.3 describes the app as an assistant for Claude Code, Codex, and Gemini CLI; scripts are dev (pnpm tauri dev), build (pnpm tauri build), dev:renderer (vite), build:renderer (vite build), typecheck (tsc --noEmit), format/format:check (Prettier on src), and test:unit (vitest run). There is no lint script.
- The Rust package cc-switch 3.20.3 (edition 2021, rust-version 1.85, rust-toolchain channel 1.95) builds library cc_switch_lib as staticlib, cdylib, and rlib. Default features are empty; feature test-hooks exists only to expose test hooks. Release profile uses thin LTO, opt-level s, panic=unwind, and strip=symbols.
- Tauri productName is CC Switch, identifier com.ccswitch.desktop, window label main starts hidden at 1000x650 with Overlay title bar. frontendDist is ../dist, devUrl is http://localhost:3000, beforeDevCommand is pnpm run dev:renderer. Deep-link scheme is ccswitch. Updater pubkey is embedded and endpoints are https://dl.ccswitch.io/latest.json and the GitHub latest.json asset. CSP script-src is 'self' plus one sha256; connect-src allows ipc, https, and http.
- main() on Linux sets WEBKIT_DISABLE_DMABUF_RENDERER=1 and WEBKIT_DISABLE_COMPOSITING_MODE=1 when unset, and if CC_SWITCH_GDK_BACKEND is non-empty copies it onto GDK_BACKEND, then calls cc_switch_lib::run().
- run() installs a panic hook writing ~/.cc-switch/crash.log, registers tauri_plugin_single_instance (which can exit lightweight mode, parse ccswitch:// args, and focus the main window), deep-link, process, dialog, opener, store, window-state, and updater. CloseRequested hides to tray when minimize_to_tray_on_close is set, otherwise exits; db_version_too_new recovery always exits.
- The invoke_handler beginning at lib.rs registers commands for providers, Claude Desktop, settings, MCP, prompts, Pi, profiles, skills, proxy start/stop/takeover, failover, usage, stream check, sessions, WebDAV, S3, deep link, env conflicts, and universal providers. Frontend wrappers in src/lib/api/index.ts re-export providersApi, proxyApi, mcpApi, skillsApi, usageApi, and others that call invoke().
- AppState holds Arc<Database>, ProxyService (constructed with the same CodexOAuthManager), Arc<UsageCache>, and Arc<CodexOAuthManager> rooted at get_app_config_dir().
- Database::init opens ~/.cc-switch/cc-switch.db via get_app_config_dir(), enables foreign_keys, registers an update hook that notifies WebDAV and S3 auto-sync, creates tables, and migrates when user_version is between 1 and SCHEMA_VERSION (19). A newer on-disk user_version is detected by stored_user_version_exceeds_supported and treated as db_version_too_new.
- AppType has ten variants: Claude, ClaudeDesktop, Codex, Gemini, GrokBuild, OpenCode, OpenClaw, Hermes, Pi, Mcode. is_additive_mode is true for OpenCode, OpenClaw, Hermes, Pi, and Mcode. supports_local_proxy is true only for Claude, Codex, Gemini, and GrokBuild.
- Live config path helpers: Claude ~/.claude/settings.json (legacy claude.json if present), Codex ~/.codex/config.toml and auth.json, Gemini ~/.gemini/settings.json plus .env, Grok ~/.grok/config.toml, OpenCode ~/.config/opencode/opencode.json, OpenClaw ~/.openclaw/openclaw.json, Hermes ~/.hermes/config.yaml, Pi ~/.pi/agent/models.json (override via settings or PI_CODING_AGENT_DIR), MiniMax ~/.minimax/config.yaml or MINIMAX_DATA_DIR/MAVIS_DATA_DIR. Directory overrides exist on AppSettings.src-tauri/src/config.rs#L243-256src-tauri/src/codex_config.rs#L462-473src-tauri/src/codex_config.rs#L987-990src-tauri/src/gemini_config.rs#L340-345src-tauri/src/grok_config.rs#L25-33src-tauri/src/opencode_config.rs#L48-59src-tauri/src/openclaw_config.rs#L31-48src-tauri/src/hermes_config.rs#L98-103src-tauri/src/pi_config/mod.rs#L34-77src-tauri/src/mcode_config.rs#L12-60
- CI on pull_request and push to main path-filters frontend versus src-tauri. Frontend job runs pnpm install --frozen-lockfile, pnpm typecheck, pnpm format:check, pnpm test:unit on Node 20. Backend matrix is ubuntu-22.04, windows-latest, macos-latest and runs cargo fmt --check, cargo clippy -D warnings, and cargo test. A separate windows-2025 job runs tests against a WSL2 home. Release workflow triggers on tags v* and builds windows-2022, windows-11-arm, ubuntu-22.04, ubuntu-22.04-arm, and macos-14.
- The default Tauri capability grants the main window core, opener, updater, log, a short list of window controls, process exit/restart, and dialog. It does not grant shell or fs plugins; filesystem and process work goes through Rust commands.