Skip to content

fix(codex): add multi-platform CLI discovery and static gpt-5.5 template fallback#3382

Merged
farion1231 merged 2 commits into
farion1231:mainfrom
chofuhoyu:fix/codex-model-catalog-template-fallback
May 31, 2026
Merged

fix(codex): add multi-platform CLI discovery and static gpt-5.5 template fallback#3382
farion1231 merged 2 commits into
farion1231:mainfrom
chofuhoyu:fix/codex-model-catalog-template-fallback

Conversation

@chofuhoyu

Copy link
Copy Markdown
Contributor

问题

当用户从未直连过 OpenAI(比如只用 DeepSeek 等第三方供应商)时,~/.codex/models_cache.json 永远不会被创建。cc-switch 在生成第三方供应商的模型目录时需要 gpt-5.5 模型定义作为模板,当前有两条获取路径:

  1. models_cache.json → 不存在 ❌
  2. codex debug models --bundled → 在 macOS GUI 环境下 codex 不在 Tauri 的 PATH 中,也找不到 ❌

两条路都断了就会报:

Codex model catalog template gpt-5.5 not found. Please start Codex once so models_cache.json is available, or ensure the codex CLI is on PATH.

相关 issue:#3325 #3337 #3343 #3378

修复

三层递进兜底,每层都是跨平台的:

① ~/.codex/models_cache.json        ← 已有,不变
② codex CLI(PATH + 常见安装路径)   ← 新增多路径尝试
③ 编译时嵌入的静态模板               ← 新增,最终兜底

第 2 层load_codex_model_template_from_bundled 原来只试 Command::new("codex"),现在遍历候选列表:

"codex"                                    # PATH(所有平台)
"/opt/homebrew/bin/codex"                  # macOS Apple Silicon Homebrew
"/usr/local/bin/codex"                     # macOS Intel Homebrew / Linux
"/home/linuxbrew/.linuxbrew/bin/codex"     # Linux Homebrew

第 3 层:新增 src-tauri/src/resources/gpt5_5_template.json,内容是 codex debug models --bundled 输出中 gpt-5.5 的完整条目(从当前 codex 0.135.0 提取),通过 include_str! 在编译时嵌入。无论用户环境如何,只要 cc-switch 能成功编译启动,就能拿到模板。

测试

running 29 tests
test codex_config::tests::codex_cli_candidates_are_non_empty ... ok
test codex_config::tests::static_template_is_valid_json_with_slug ... ok
test codex_config::tests::static_template_has_required_keys ... ok
... (原有 26 个全部通过)
test result: ok. 29 passed; 0 failed

注意事项

静态模板需要在 Codex 更新其 agent 系统提示词(model_messages / base_instructions)时同步更新。频率很低,过去一年未变。可以考虑在 CI 中加一个检查项或文档提示,提醒在升级 codex 依赖版本时检查模板是否过时。

…ate fallback for model catalog generation

When cc-switch generates a Codex model catalog for third-party providers,
it needs the gpt-5.5 model definition as a template. Previously it relied
on either ~/.codex/models_cache.json (only exists when Codex has connected
to OpenAI) or running 'codex debug models --bundled' (fails when codex
is not on the Tauri app's PATH, common in macOS GUI environments).

This commit adds a three-tier fallback:
1. Try 'codex' from PATH, then platform-specific common paths
   (/opt/homebrew/bin/codex, /usr/local/bin/codex, etc.)
2. If all CLI attempts fail, use a compile-time embedded gpt-5.5
   template (extracted from codex 0.135.0 bundled models)

Also adds tests for the static template validity and CLI candidates.
@chofuhoyu

chofuhoyu commented May 30, 2026

Copy link
Copy Markdown
Contributor Author

我已对该修改进行审查,应该能解决像我这种从未直连过OpenAI的人的问题。

其实我就是因为看到ccswitch现在支持转发deepseek才第一次愿意尝试codex。相信有更多的人也是怀着同样的心情打开cc-switch,然后被这个问题卡了一下午。

希望cc-switch越来越好~

@farion1231

Copy link
Copy Markdown
Owner

@codex review

@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.

非常感谢您的贡献!

@farion1231
farion1231 merged commit 5ef72a2 into farion1231:main May 31, 2026
3 checks passed
@dadahhhh

Copy link
Copy Markdown

thanks,感谢 终于找到了

AnXiYiZhi pushed a commit to AnXiYiZhi/DevCLaw-old that referenced this pull request Jun 9, 2026
…ate fallback (farion1231#3382)

* fix(codex): add multi-platform CLI discovery and static gpt-5.5 template fallback for model catalog generation

When cc-switch generates a Codex model catalog for third-party providers,
it needs the gpt-5.5 model definition as a template. Previously it relied
on either ~/.codex/models_cache.json (only exists when Codex has connected
to OpenAI) or running 'codex debug models --bundled' (fails when codex
is not on the Tauri app's PATH, common in macOS GUI environments).

This commit adds a three-tier fallback:
1. Try 'codex' from PATH, then platform-specific common paths
   (/opt/homebrew/bin/codex, /usr/local/bin/codex, etc.)
2. If all CLI attempts fail, use a compile-time embedded gpt-5.5
   template (extracted from codex 0.135.0 bundled models)

Also adds tests for the static template validity and CLI candidates.

* fix(codex): discover user node codex installs

---------

Co-authored-by: Jason <[email protected]>
gfunc pushed a commit to gfunc/cc-switch that referenced this pull request Jun 19, 2026
…ate fallback (farion1231#3382)

* fix(codex): add multi-platform CLI discovery and static gpt-5.5 template fallback for model catalog generation

When cc-switch generates a Codex model catalog for third-party providers,
it needs the gpt-5.5 model definition as a template. Previously it relied
on either ~/.codex/models_cache.json (only exists when Codex has connected
to OpenAI) or running 'codex debug models --bundled' (fails when codex
is not on the Tauri app's PATH, common in macOS GUI environments).

This commit adds a three-tier fallback:
1. Try 'codex' from PATH, then platform-specific common paths
   (/opt/homebrew/bin/codex, /usr/local/bin/codex, etc.)
2. If all CLI attempts fail, use a compile-time embedded gpt-5.5
   template (extracted from codex 0.135.0 bundled models)

Also adds tests for the static template validity and CLI candidates.

* fix(codex): discover user node codex installs

---------

Co-authored-by: Jason <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants