Skip to content

feat(grokbuild): add first-class Grok Build support#5453

Merged
farion1231 merged 8 commits into
farion1231:mainfrom
YUZHEthefool:feat/grokbuild-support
Jul 17, 2026
Merged

feat(grokbuild): add first-class Grok Build support#5453
farion1231 merged 8 commits into
farion1231:mainfrom
YUZHEthefool:feat/grokbuild-support

Conversation

@YUZHEthefool

@YUZHEthefool YUZHEthefool commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary / ??

Add Grok Build CLI as a first-class switchable app backed by its native ~/.grok/config.toml format.

  • manage, import, browse, and switch Grok Build providers with structured [models] / [model.*] configuration
  • expose an independent /grokbuild/v1/responses route with its own provider namespace and failover queue
  • make routed hot switches transactional so failed writes restore the previous provider, backup, and live config
  • integrate Grok Build with MCP, prompts (~/.grok/AGENTS.md), Skills, native sessions, settings, and tray switching
  • add complete Grok CLI lifecycle management in Settings > About: installation status, current/latest versions, refresh, one-click install/upgrade, bulk upgrades, conflict diagnostics, and manual install commands
  • align Grok provider icons with existing apps: custom providers use the name-initial fallback, presets keep their own icons, and legacy auto-assigned Grok icons are normalized without overriding explicit user choices
  • add schema migrations and regression coverage for provider switching, routing rollback, MCP serialization, sessions, and UI flows

Related Issue / ?? Issue

Fixes #5407

Related prior discussion: #4825

Implementation Notes

  • Grok remote MCP keeps Grok-native headers and omits Codex-only type / http_headers fields.
  • Provider switches and proxy teardown preserve [mcp_servers.*] entries in config.toml.
  • Session management reads native ~/.grok/sessions/**/summary.json and chat_history.jsonl, and resumes with grok --resume <session-id>.
  • Prompt auto-import covers both first launch and database migration paths.
  • CLI installation and updates use the official @xai-official/grok package; updates stay anchored to the detected npm/Volta/pnpm/Bun installation, including Grok-specific WSL directory overrides.
  • Grok provider cards now follow the shared icon semantics: blank custom icons render provider initials, preset icons remain provider-specific, and the compatibility path distinguishes old automatic Grok icons from explicitly selected ones.

Screenshots / ??

No static screenshot included. The complete Tauri debug build was manually verified on Windows 11 with real Grok provider, session, and Skills data.

Verification

  • npm run typecheck
  • npm run format:check
  • npm run test:unit -- --testTimeout=15000 (72 files, 462 tests)
  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test with isolated LOCALAPPDATA (1,995 passed, 2 ignored, plus all integration suites)
  • npx tauri build --debug --no-bundle --ignore-version-mismatches with the existing production frontend bundle

Checklist / ????

  • pnpm typecheck equivalent passes via the repository npm run typecheck script
  • pnpm format:check equivalent passes via the repository npm run format:check script
  • cargo clippy passes with warnings denied
  • Updated all four locale files for user-facing text

@YUZHEthefool
YUZHEthefool requested a review from farion1231 as a code owner July 16, 2026 14:54
@github-actions github-actions Bot added frontend Frontend (React/TypeScript) backend Backend (Rust/Tauri) proxy Related to proxy/API forwarding mcp Related to MCP server management skills Related to Skills management labels Jul 16, 2026
@farion1231

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be9847074a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/deeplink/provider.rs
Comment thread src-tauri/src/deeplink/mcp.rs
Comment thread src-tauri/src/prompt_files.rs

@farion1231 farion1231 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this contribution — this is one of the most complete external PRs this repo has received. I reproduced all five verification claims locally (fmt / clippy / 1992 lib tests + integration suites / tsc / 451 vitest, all green) and cross-checked the config schema, MCP layout, AGENTS.md, and --resume against x.ai's docs. The transactional hot-switch is a genuine improvement, and I found no regressions to existing apps: Codex/Claude forwarding stays byte-identical, and failover/circuit-breaker state is fully namespaced per app.

That said, please address the following before merge:

Required

  1. Deleted MCP servers resurrect on switch-back. services/provider/live.rs:836restore_live_settings_for_provider_backfill early-returns for non-Codex apps, so the projected [mcp_servers.*] gets baked verbatim into the outgoing Grok provider snapshot. Since project_servers_to_app only reconciles servers still in the DB, a server deleted in cc-switch resurrects in ~/.grok/config.toml (possibly with stale credentials) on the next switch back. Grok needs the same strip Codex has (strip_codex_mcp_servers_from_settings; see the regression test codex_switch_backfill_strips_synced_mcp_servers as a template). The live-import path (live.rs:1450) needs the same strip.

  2. Inline api_key is hard-required, rejecting documented config styles. grok_config.rs:104 — per x.ai's settings reference, api_key is discouraged; env_key / session token / XAI_API_KEY are canonical (resolution order api_key > env_key > session token > XAI_API_KEY). A valid env_key-style config fails "import from live" with an error, and the startup auto-import silently no-ops. Suggest accepting api_key OR env_key on import/validation.

  3. Grok route doesn't survive an app restart. lib.rs:1746restore_proxy_state_on_startup iterates the hardcoded ["claude", "codex", "gemini"]. With only the Grok route enabled, the proxy never starts after a restart and the route silently drops to direct upstream while proxy_config.enabled stays true in the UI. (The live config itself is fine — restore_live_configs and detect_takeover_in_live_configs both cover Grok — only the re-takeover loop is missing.) Please add "grokbuild" plus a restart regression test.

  4. Preset apiFormat isn't mapped into TOML api_backend. GrokBuildProviderForm.tsxhandlePresetChange sets meta.apiFormat but never updates apiBackend, so the generated TOML always says api_backend = "responses". Under proxy takeover this happens to work (the conversion gate reads meta.api_format), but in direct mode Grok CLI will speak Responses to a Chat-only gateway. x.ai documents api_backend = chat_completions | responses | messages, so please map openai_chat → chat_completions / anthropic → messages when generating the TOML.

  5. First-launch MCP import misses Grok. The empty-table import block at lib.rs:761 calls the per-app importers for claude/codex/gemini/opencode/hermes but not the already-implemented import_from_grokbuild (the adjacent prompts loop does include GrokBuild). Existing ~/.grok/config.toml MCP servers won't be picked up on first launch.

Recommended (fine as a follow-up)

  1. Cached tokens double-counted for GrokBuild. GrokBuild flows through Responses semantics where input_tokens includes cache, but grokbuild is missing from all four cache-inclusive lists: proxy/usage/calculator.rs:62, proxy/usage/logger.rs:74 (rows should be TOTAL, not FRESH), services/sql_helpers.rs:19, and the frontend mirror types/usage.ts:198. Result: cache portion billed at both input and cache rates, and cache-hit rate badly understated.
  2. Deeplink coverage is partial. The prompt whitelist (deeplink/parser.rs:193) and MCP apps whitelist (parser.rs:265) still reject grokbuild; the existing-server apps merge (deeplink/mcp.rs:104) only merges claude/codex/gemini — this also predates the PR for opencode/hermes, so consider looping over the flags instead of per-field merging; and the provider inline-config dispatch (deeplink/provider.rs:642) has no Grok branch, so config/configUrl deeplinks fail with "Invalid app type".
  3. No GrokBuild entry in usage UI. types/usage.ts:175 KNOWN_APP_TYPES (dashboard filter) and PricingConfigPanel.tsx PRICING_APPS omit grokbuild even though it records real proxy usage.
  4. custom_endpoints conflation in the form. GrokBuildProviderForm.tsx:186-197, 329-356 persists the union of baseUrl + preset endpoints + prior custom_endpoints back into meta.custom_endpoints, so an endpoint removed in the speed-test modal resurrects on save. The Codex form persists only user-added endpoints.
  5. Rollback gap for the Codex direct-write branch. rollback_hot_switch_preparation (services/proxy.rs:433) never restores the has_backup && !live_taken_over Codex direct write (proxy.rs:~2465) on commit failure — the PR moved that write ahead of the commit, so a commit failure now leaves ~/.codex on the new provider until the next proxy stop self-heals it.

Nits

README app lists (4 locales) still say 7 apps; the inline rawConfigError renders hardcoded English (should go through t()); five grokBuild.* i18n keys are unused; test gaps worth closing: delete_session (destructive remove_dir_all guards untested), validateGrokBuildConfig error branches / profile-rename, and the form's validation-error + edit-mode paths.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jul 17, 2026
@YUZHEthefool

Copy link
Copy Markdown
Contributor Author

Addressed all maintainer and inline review feedback in a9608bc6 and 381040fb.

Required:

  • Strip projected Grok MCP servers during switch-back backfill and live import, with regressions.
  • Accept api_key or env_key, preserve env-based profiles through takeover, and resolve configured environment credentials.
  • Restore Grok proxy takeover on startup, with a startup regression.
  • Map preset/API formats to responses, chat_completions, or messages in generated TOML.
  • Include Grok in first-launch MCP import.

Recommended:

  • Treat Grok Responses input tokens as cache-inclusive in calculation, logging, SQL aggregation, and the frontend.
  • Complete provider/MCP/prompt deeplink support and merge all MCP app flags, including OpenCode and Hermes.
  • Add Grok to usage filters and pricing configuration.
  • Persist only actual user-added custom endpoints so deleted endpoints do not reappear.
  • Restore the exact pre-write Codex Live snapshot when the logical provider commit fails.

Nits/tests:

  • Update all four READMEs to eight tools and include Grok Build.
  • Localize raw TOML errors and remove five unused grokBuild.* keys.
  • Add Grok session deletion/root-guard, config validation/profile rename, form validation/edit-mode, deeplink, cache accounting, MCP stripping, startup restore, and commit-failure tests.

Validation completed locally: TypeScript, Prettier, 457 Vitest tests, rustfmt, strict Clippy, 1993 Cargo tests (2 ignored), renderer production build, and Tauri debug build.

@YUZHEthefool

Copy link
Copy Markdown
Contributor Author

Follow-up: Grok Build lifecycle and provider icon alignment

This PR now includes two additional consistency improvements:

1. Grok CLI lifecycle management (16301ef6)

  • Added Grok Build to Settings > About > Local environment check.
  • Supports installation status, current/latest version checks, manual refresh, one-click install/upgrade, and bulk upgrades.
  • Added multi-install conflict diagnostics and manual installation commands.
  • Uses the official @xai-official/grok package.
  • Upgrade commands stay anchored to the detected npm/Volta/pnpm/Bun installation instead of updating a different CLI copy.
  • Grok-specific WSL directory overrides are included in environment detection.

2. Provider icon behavior alignment (cb36d93f, 43100883)

  • Custom Grok Build providers no longer receive the Grok application icon automatically; they now use the same provider-name initials fallback as the other apps.
  • Preset providers continue to use their own preset-specific icons.
  • Previously auto-assigned Grok icons are normalized immediately for compatibility.
  • An explicitly selected Grok icon is preserved by distinguishing the icon picker's currentColor metadata from the old automatic empty-color value.
  • Added coverage for both form defaults and the final AddProviderDialog persistence payload, verifying that custom providers are saved without icon or iconColor.

Verification

  • npm run typecheck
  • npm run format:check
  • npm run test:unit -- --testTimeout=15000 — 72 files, 462 tests
  • Renderer production build
  • Tauri debug build on Windows

@farion1231 farion1231 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

@farion1231
farion1231 merged commit 1c0ee0c into farion1231:main Jul 17, 2026
6 checks passed
dashu33 pushed a commit to dashu33/cc-switch-linuxdo that referenced this pull request Jul 17, 2026
* feat(grokbuild): add backend integration

* feat(grokbuild): add provider and management UI

* test(grokbuild): cover configuration and integrations

* fix(grokbuild): address backend review feedback

* fix(grokbuild): complete UI review feedback

* feat(grokbuild): add CLI lifecycle management

* fix(grokbuild): align provider icon fallback

* test(grokbuild): cover provider icon persistence
@makoMakoGo makoMakoGo mentioned this pull request Jul 18, 2026
3 tasks
jarvislee90s-dot pushed a commit to jarvislee90s-dot/cc-switch-enhance that referenced this pull request Jul 22, 2026
* feat(grokbuild): add backend integration

* feat(grokbuild): add provider and management UI

* test(grokbuild): cover configuration and integrations

* fix(grokbuild): address backend review feedback

* fix(grokbuild): complete UI review feedback

* feat(grokbuild): add CLI lifecycle management

* fix(grokbuild): align provider icon fallback

* test(grokbuild): cover provider icon persistence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend (Rust/Tauri) documentation Improvements or additions to documentation frontend Frontend (React/TypeScript) mcp Related to MCP server management proxy Related to proxy/API forwarding skills Related to Skills management

Projects

None yet

Development

Successfully merging this pull request may close these issues.

能否加grok呢

2 participants