引言

Codex Desktop 的 Computer Use 功能允许 AI 直接操控桌面应用,是 Codex 最受关注的能力之一。然而不少用户在升级版本后打开"电脑操控"页面,却看到一行红字:Computer Use 插件不可用。翻遍设置也找不到开关,重新安装也无济于事。

这个问题通常不是 Codex 本身的 bug,而是配置文件没有正确指向插件目录。本文整理了一套完整的排查流程和修复脚本,帮你从根因上解决问题。

问题背景

Codex 的插件体系基于两个关键概念:marketplace(插件市场)和 plugin(插件本身)。Codex Desktop 安装包内置了一个名为 openai-bundled 的 marketplace,里面包含 Computer Use、Browser、Chrome 等官方插件,文件就存放在 Codex 安装目录中。

当插件页面报"不可用"时,原因通常出在三个环节:

  • marketplace 路径错误config.toml 里的 openai-bundled 指向了残缺的缓存目录,而非 Codex 安装包内的真实插件目录
  • 插件未启用computer-use@openai-bundled 没有被显式设为 enabled = true
  • 沙箱模式冲突sandbox = "elevated" 导致 Computer Use 与普通桌面应用权限隔离,无法正常操控

一、排查与修复

常见错误配置

先确认你的 config.toml(位于 <code>C:\Users\<用户名>\.codex\config.toml</code>)是否存在以下问题。

问题一:marketplace 指向残缺的缓存目录

# 错误 —— 指向了临时缓存
source = '\\?\C:\Users\<用户名>\.codex\.tmp\bundled-marketplaces\openai-bundled'

问题二:sandbox 设成了 elevated

# 错误 —— Computer Use 无法操控普通桌面应用
sandbox = "elevated"

问题三:使用不适配当前版本的旧命令

有些教程里的 codex plugin addcodex plugin marketplace add 等命令在较新版本的 Codex CLI 中已经不再支持。如果执行时报 unrecognized subcommand,直接改 config.toml 即可。

修复脚本

以下 PowerShell 脚本会自动完成所有修复步骤。使用前请注意:

  • 完全退出 Codex Desktop,检查任务栏托盘无残留图标
  • 普通用户 PowerShell 执行,不要用管理员模式

$ErrorActionPreference = "Stop"

# 定位 config.toml 并备份
$cfg = "$env:USERPROFILE\.codex\config.toml"
if (!(Test-Path $cfg)) {
    throw "config.toml not found: $cfg"
}

$backup = "$cfg.before-computer-use-direct-$(Get-Date -Format yyyyMMdd-HHmmss)"
Copy-Item -LiteralPath $cfg -Destination $backup

# 获取 Codex Desktop 安装路径
$pkg = Get-AppxPackage *Codex* | Sort-Object Version -Descending | Select-Object -First 1
if (!$pkg) {
    throw "OpenAI Codex package not found"
}

# 验证 Computer Use 插件实体存在
$bundled = Join-Path $pkg.InstallLocation "app\resources\plugins\openai-bundled"
$marketplace = Join-Path $bundled ".agents\plugins\marketplace.json"
$computerUseDir = Join-Path $bundled "plugins\computer-use"

if (!(Test-Path $marketplace)) {
    throw "openai-bundled marketplace.json not found: $marketplace"
}
if (!(Test-Path $computerUseDir)) {
    throw "computer-use plugin directory not found: $computerUseDir"
}

# 读取配置
$text = Get-Content -LiteralPath $cfg -Encoding UTF8 -Raw

# 启用 js_repl
if ($text -match '(?m)^js_repl\s*=') {
    $text = $text -replace '(?m)^js_repl\s*=\s*false\s*$', 'js_repl = true'
} else {
    $text = $text -replace '(?m)^\[features\]\s*$', "[features]`r`njs_repl = true"
}

# 改为 unelevated —— Computer Use 才能控制普通桌面应用
$text = $text -replace '(?m)^sandbox\s*=\s*"elevated"\s*$', 'sandbox = "unelevated"'

# 修复 openai-bundled marketplace 路径
$sourceValue = "\\?\" + $bundled
$text = [regex]::Replace(
    $text,
    '(?ms)(\[marketplaces\.openai-bundled\].*?^source\s*=\s*)''[^'']*''',
    "`$1'$sourceValue'"
)

# 启用 Computer Use 插件
if ($text -notmatch '\[plugins\."computer-use@openai-bundled"\]') {
    $anchor = '[plugins."chrome@openai-bundled"]'
    $insert = "[plugins.""computer-use@openai-bundled""]`r`nenabled = true`r`n`r`n"
    if ($text.Contains($anchor)) {
        $text = $text.Replace($anchor, $insert + $anchor)
    } else {
        $text += "`r`n`r`n" + $insert
    }
}

# 写入 UTF-8 无 BOM(避免 Codex 解析异常)
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($cfg, $text, $utf8NoBom)

Write-Host "Config fixed."
Write-Host "Backup: $backup"
Write-Host "Bundled marketplace: $bundled"

验证修复结果

脚本执行完后,用以下命令验证配置是否生效:

$cfg = "$env:USERPROFILE\.codex\config.toml"
Select-String -LiteralPath $cfg -Pattern `
  '^js_repl\s*=|^sandbox\s*=|\[marketplaces\.openai-bundled\]|^source\s*=|\[plugins\."computer-use@openai-bundled"\]|\[plugins\."browser@openai-bundled"\]|\[plugins\."chrome@openai-bundled"\]'

预期输出类似:

js_repl = true
sandbox = "unelevated"

[marketplaces.openai-bundled]
source = '\\?\C:\Program Files\WindowsApps\OpenAI.Codex_xxx\app\resources\plugins\openai-bundled'

[plugins."computer-use@openai-bundled"]
enabled = true

[plugins."chrome@openai-bundled"]
enabled = true

[plugins."browser@openai-bundled"]
enabled = true

也可以直接验证插件文件是否存在:

$pkg = Get-AppxPackage *Codex* | Sort-Object Version -Descending | Select-Object -First 1
$bundled = Join-Path $pkg.InstallLocation "app\resources\plugins\openai-bundled"
Test-Path (Join-Path $bundled ".agents\plugins\marketplace.json")  # 应返回 True
Test-Path (Join-Path $bundled "plugins\computer-use")              # 应返回 True

两个结果都为 True 说明插件实体完好。

二、重启与验证

操作步骤

配置修改后,按以下步骤操作:

  • 完全退出 Codex Desktop
  • 检查任务栏托盘,确保没有残留的 Codex 进程
  • 重新启动 Codex Desktop
  • 打开"电脑操控"页面,确认不再显示"Computer Use 插件不可用"
  • 新开一个对话,观察 AI 是否能够调用 Computer Use 工具

如果对话中仍不能发现 Computer Use 工具,通常是当前会话未重新加载插件,新开一个 Codex 会话再验证即可。

三、回滚方法

从备份恢复

如果修复后 Codex 启动异常,用脚本执行时生成的备份文件恢复:

$cfg = "$env:USERPROFILE\.codex\config.toml"
# 将备份文件名替换为实际生成的文件名
Copy-Item -LiteralPath "$cfg.before-computer-use-direct-YYYYMMDD-HHMMSS" -Destination $cfg -Force

备份文件就在 config.toml 同级目录下,文件名包含修复操作的时间戳,方便识别。

结语

Codex Computer Use 插件不可用的问题,根因几乎都在配置文件上——marketplace 路径错误、插件未启用、沙箱模式不匹配。这些问题不需要重新安装 Codex,一段 PowerShell 脚本就能解决。

修复完成后,建议保留一份 config.toml 的干净备份。后续 Codex 版本更新如果冲掉了配置,直接用备份恢复即可,不必从头再来一遍。