Codex
将编码任务委派给 OpenAI Codex CLI(功能、PR)。
技能元数据
| 来源 | 捆绑(默认安装) |
| 路径 | skills/autonomous-ai-agents/codex |
| 版本 | 1.0.0 |
| 作者 | Hermes Agent |
| 许可证 | MIT |
| 平台 | linux, macos, windows |
| 标签 | Coding-Agent, Codex, OpenAI, Code-Review, Refactoring |
| 相关技能 | claude-code, hermes-agent |
参考:完整的 SKILL.md
信息
以下是当此技能被触发时,Hermes 加载的完整技能定义。这是技能激活时,智能体看到的指令。
Codex CLI
通过 Hermes 终端将编码任务委派给 Codex。Codex 是 OpenAI 的自主编码智能体 CLI。
何时使用
- 构建功能
- 重构代码
- PR 审查
- 批量修复问题
需要 codex CLI 和一个 git 仓库。
前提条件
- 已安装 Codex:
npm install -g @openai/codex - OpenAI 认证已配置:可以是
OPENAI_API_KEY或来自 Codex CLI 登录流程的 Codex OAuth 凭据 - 必须在 git 仓库内运行 —— Codex 拒绝在 git 仓库外运行
- 在终端调用中使用
pty=true—— Codex 是一个交互式终端应用
对于 Hermes 本身,model.provider: openai-codex 会在执行 hermes auth add openai-codex 后,使用来自 ~/.hermes/auth.json 的、由 Hermes 管理的 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)
后台模式(长任务)
# 使用 PTY 在后台启动
terminal(command="codex exec --full-auto 'Refactor the auth module'", workdir="~/project", background=true, pty=true)
# 返回 session_id
# 监控进度
process(action="poll", session_id="<id>")
process(action="log", session_id="<id>")
# 如果 Codex 提问,发送输入
process(action="submit", session_id="<id>", data="yes")
# 如有需要,终止进程
process(action="kill", session_id="<id>")
关键标志
| 标志 | 效果 |
|---|---|
exec "prompt" | 单次执行,完成后退出 |
--full-auto | 在沙盒中运行,但自动批准工作区内的文件更改 |
--yolo | 无沙盒,无审批(最快,最危险) |
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 并行修复问题
# 创建 worktree
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")
# 在每个 worktree 中启动 Codex
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)
# 监控
process(action="list")
# 完成后,推送并创建 PR
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 '...'")
# 清理
terminal(command="git worktree remove /tmp/issue-78", workdir="~/project")
批量 PR 审查
# 获取所有 PR 引用
terminal(command="git fetch origin '+refs/pull/*/head:refs/remotes/origin/pr/*'", workdir="~/project")
# 并行审查多个 PR
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)
# 发布结果
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 进程