Codex
将编码工作委托给 OpenAI Codex CLI(功能开发、PR)。
Skill 元数据
| 来源 | Bundled(默认已安装) |
| 路径 | skills/autonomous-ai-agents/codex |
| 版本 | 1.0.0 |
| 作者 | KOPI AI AGENT |
| 许可证 | MIT |
| 平台 | linux, macos, windows |
| 标签 | Coding-Agent, Codex, OpenAI, Code-Review, Refactoring |
| 相关 skill | claude-code, kopi-ai-agent |
参考:完整的 SKILL.md
以下是触发此 skill 时 Kopi Agent 加载的完整 skill 定义。这就是 skill 处于激活状态时 agent 看到的指令。
Codex CLI
通过 Kopi Agent 终端将编码任务委托给 Codex。Codex 是 OpenAI 的自主编码 agent CLI。
何时使用
- 构建功能
- 重构
- PR 审查
- 批量修复 issue
需要 codex CLI 和一个 git 仓库。
前提条件
- 已安装 Codex:
npm install -g @openai/codex - 已配置 OpenAI 认证:
OPENAI_API_KEY或来自 Codex CLI 登录流程的 Codex OAuth 凭据 - 必须在 git 仓库内运行 —— Codex 会拒绝在仓库外运行
- 在终端调用中使用
pty=true—— Codex 是一个交互式终端应用
对于 Kopi Agent 本身,model.provider: openai-codex 使用 kopi auth add openai-codex 之后来自 ~/.kopi/auth.json 的
由 Kopi Agent 管理的 Codex OAuth。对于独立的 Codex CLI,有效的 CLI OAuth 会话
可能位于 ~/.codex/auth.json;不要仅凭缺少 OPENAI_API_KEY 就认定 Codex 认证缺失。
单次任务
terminal(command="codex exec 'Add dark mode toggle to settings'", workdir="~/project", pty=true)
用于临时性工作(Codex 需要一个 git 仓库):
terminal(command="cd $(mktemp -d) && git init && codex exec 'Build a snake game in Python'", pty=true)
后台模式(长时间任务)
# Start in background with PTY
terminal(command="codex exec --full-auto 'Refactor the auth module'", workdir="~/project", background=true, pty=true)
# Returns session_id
# Monitor progress
process(action="poll", session_id="<id>")
process(action="log", session_id="<id>")
# Send input if Codex asks a question
process(action="submit", session_id="<id>", data="yes")
# Kill if needed
process(action="kill", session_id="<id>")
关键 Flag
| Flag | 效果 |
|---|---|
exec "prompt" | 单次执行,完成后退出 |
--full-auto | 在沙箱中运行,但自动批准工作区内的文件更改 |
--yolo | 无沙箱、无审批(最快,也最危险) |
--sandbox danger-full-access | 不使用 Codex 沙箱;当宿主服务上下文导致 bubblewrap 出问题时很有用 |
Kopi Agent 网关注意事项
当从 Kopi Agent 网关/服务上下文(例如由 Telegram 驱动的 agent 会话)调用 Codex CLI 时,
即使同一命令在用户的交互式 shell 中可以正常运行,Codex 的 workspace-write 沙箱化
也可能失败。典型症状是 bubblewrap/用户命名空间错误,例如 setting up uid map: Permission denied
或 loopback: Failed RTM_NEWADDR: Operation not permitted。
在这种上下文中,优先使用:
codex exec --sandbox danger-full-access "<task>"
改用进程边界作为安全层:显式 workdir、启动前保持干净的 git 状态、
精确的任务提示、git diff 审查、有针对性的测试,以及在提交大范围更改前
进行人工/agent 确认。
PR 审查
克隆到临时目录以便安全审查:
terminal(command="REVIEW=$(mktemp -d) && git clone https://github.com/user/repo.git $REVIEW && cd $REVIEW && gh pr checkout 42 && codex review --base origin/main", pty=true)
使用 Worktree 并行修复 Issue
# Create worktrees
terminal(command="git worktree add -b fix/issue-78 /tmp/issue-78 main", workdir="~/project")
terminal(command="git worktree add -b fix/issue-99 /tmp/issue-99 main", workdir="~/project")
# Launch Codex in each
terminal(command="codex --yolo exec 'Fix issue #78: <description>. Commit when done.'", workdir="/tmp/issue-78", background=true, pty=true)
terminal(command="codex --yolo exec 'Fix issue #99: <description>. Commit when done.'", workdir="/tmp/issue-99", background=true, pty=true)
# Monitor
process(action="list")
# After completion, push and create PRs
terminal(command="cd /tmp/issue-78 && git push -u origin fix/issue-78")
terminal(command="gh pr create --repo user/repo --head fix/issue-78 --title 'fix: ...' --body '...'")
# Cleanup
terminal(command="git worktree remove /tmp/issue-78", workdir="~/project")
批量 PR 审查
# Fetch all PR refs
terminal(command="git fetch origin '+refs/pull/*/head:refs/remotes/origin/pr/*'", workdir="~/project")
# Review multiple PRs in parallel
terminal(command="codex exec 'Review PR #86. git diff origin/main...origin/pr/86'", workdir="~/project", background=true, pty=true)
terminal(command="codex exec 'Review PR #87. git diff origin/main...origin/pr/87'", workdir="~/project", background=true, pty=true)
# Post results
terminal(command="gh pr comment 86 --body '<review>'", workdir="~/project")
规则
- 始终使用
pty=true—— Codex 是交互式终端应用,没有 PTY 时会挂起 - 必须有 git 仓库 —— Codex 不会在 git 目录之外运行。临时性工作请使用
mktemp -d && git init - 单次任务使用
exec——codex exec "prompt"会运行后正常退出 - 构建时使用
--full-auto—— 自动批准沙箱内的更改 - 长时间任务用后台运行 —— 使用
background=true并通过process工具监控 - 不要进行干扰 —— 用
poll/log监控,对长时间运行的任务保持耐心 - 并行没问题 —— 可同时运行多个 Codex 进程来批量处理工作