Skip to content

xdfnet/iCodex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

iCodex

Build macOS Swift License

纯原生 macOS 菜单栏 App — Codex ↔ DeepSeek 本机中转服务。

纯 Swift 实现,零外部依赖。服务随 App 启停,无需手动管理。

功能

功能 说明
模型切换 从 DeepSeek API 实时获取模型列表,选中即写入 Codex 配置
思考模式 DeepSeek 推理模式开关,即时生效
API Key 窗口配置,明文显示,存 UserDefaults
自动启动 随 App 自动运行中转服务
模型元数据 自动为 Codex 提供完整模型信息(context_window、shell_type 等),消除 fallback 警告
Codex App 适配 自动修补 Codex 桌面 App 的模型白名单过滤,让 DeepSeek 显示在模型菜单中

要求

  • macOS 14+
  • Xcode 15+ 或 Swift 5.9+

安装

从 GitHub Releases 下载(推荐)

curl -sL https://github.com/xdfnet/iCodex/releases/latest/download/iCodex.zip -o /tmp/iCodex.zip
unzip -qo /tmp/iCodex.zip -d /Applications
open /Applications/iCodex.app

或一条命令:

bash <(curl -sL https://raw.githubusercontent.com/xdfnet/iCodex/main/install.sh)

⚠️ 首次运行需右键 iCodex.app打开(未签名应用 Gatekeeper 拦截)

从源码构建

# 需要 Xcode 15+ 或 Swift 5.9+
git clone https://github.com/xdfnet/iCodex.git
cd iCodex
swift run                    # 开发调试
./build.sh                   # 构建正式包
open iCodex.app               # 启动

使用

  1. 启动 iCodex,点击菜单栏图标 → 配置 → 输入 DeepSeek API Key
  2. API Key 生效后自动拉取模型列表
  3. 在菜单栏选择模型 → 自动写入 Codex 配置并启用中转
  4. 可在菜单栏切换模型、开关思考模式、关闭 iCodex 模型提供

首次使用后重启 Codex,它会自动从 iCodex 获取模型列表。

架构

MenuBarExtra (SwiftUI)
  ├─ 模型 / 模式 / 配置 / 退出
  ├─ CodexConfigManager — ~/.codex/config.toml
  │   ├─ 写入 model_catalog_json,让 Codex 正确识别 DeepSeek 模型
  │   └─ CodexAppPatcher — 修补桌面 App 模型白名单过滤
  └─ HTTPServer         — 内嵌 HTTP 服务器
      └─ RelayHandler   — 路由 + 协议转换
          └─ DeepSeekClient — DeepSeek API 调用
  • HTTPServer: 基于 Network.framework (NWListener),零外部依赖
  • RelayHandler: 路由 /health /v1/models /v1/responses,协议转换
  • DeepSeekClient: URLSession + async/await,支持流式 SSE
  • CodexConfigManager: 配 Key/切模型时写入 model_provider = "iCodex"、当前模型、model_catalog_json;关模型时清理
  • CodexAppPatcher: 配 Key/切模型时备份并修补 /Applications/Codex.app/Contents/Resources/app.asar;关模型时恢复并删备份

目录结构

Sources/iCodex/
├── iCodexApp.swift              # @main 入口,MenuBarExtra + 配置窗口
├── MenuBarView.swift            # 菜单栏下拉 UI
├── Models/
│   ├── RelayConfig.swift        # ModelInfo 数据模型
│   └── RelayState.swift         # @Observable 全局状态
├── Services/
│   ├── CodexConfigManager.swift # ~/.codex/config.toml 和模型 catalog 管理
│   └── CodexAppPatcher.swift    # Codex 桌面 App 模型菜单补丁
└── Core/
    ├── HTTPServer.swift         # 内嵌 HTTP 服务器 (NWListener)
    ├── RelayHandler.swift       # 路由分发 + 协议转换
    └── DeepSeekClient.swift     # DeepSeek API 客户端

Codex 桌面 App 适配

Codex 桌面 App 前端会读取远端 Statsig 模型白名单。某些版本中白名单只包含 gpt-* 模型,并启用了 use_hidden_models,导致 iCodex 提供的 deepseek-v4-pro / deepseek-v4-flash 被过滤,模型菜单显示为空。

iCodex 配 Key 或切换模型时会自动检测并修补:

/Applications/Codex.app/Contents/Resources/app.asar

补丁方式是等长替换前端过滤表达式,避免依赖 npx asar 或其他外部工具。每次修补前会重新备份(删旧→建新),保证备份始终对应当前 Codex 版本。

关闭 iCodex 模型提供时从备份恢复,并删除备份文件。Codex App 自动更新后,下次启用 iCodex 时会重建最新备份再打补丁。

许可证

MIT

About

Codex ↔ DeepSeek 本机中转服务。

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors