跳到主要内容

Codex

将编码任务委托给 OpenAI Codex CLI 代理。用于构建功能、重构代码、PR(拉取请求)审查以及批量修复问题。需要 codex CLI 和一个 git 仓库。

技能元数据

来源捆绑(默认安装)
路径skills/autonomous-ai-agents/codex
版本1.0.0
作者Hermes Agent
许可证MIT
标签Coding-Agent, Codex, OpenAI, Code-Review, Refactoring
相关技能claude-code, hermes-agent

参考:完整 SKILL.md

信息

以下是 Hermes 在触发此技能时加载的完整技能定义。这是技能激活时代理看到的指令。

Codex CLI

通过 Hermes 终端将编码任务委托给 Codex。Codex 是 OpenAI 的自主编码代理 CLI。

前提条件

  • 已安装 Codex:npm install -g @openai/codex
  • 已配置 OpenAI API 密钥
  • 必须在 git 仓库内运行 — Codex 拒绝在非 git 目录下运行
  • 在终端调用中使用 pty=true — Codex 是一个交互式终端应用

一次性任务 (One-Shot Tasks)

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>")

关键标志 (Key Flags)

标志效果
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)

使用 Worktrees 并行修复问题

# 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")

规则

  1. 始终使用 pty=true — Codex 是一个交互式终端应用,如果没有 PTY 将会挂起
  2. 需要 Git 仓库 — Codex 不会在 git 目录之外运行。对于临时性工作,使用 mktemp -d && git init
  3. 对一次性任务使用 execcodex exec "prompt" 运行并干净地退出
  4. 构建时使用 --full-auto — 自动批准沙箱内的更改
  5. 长时间任务使用后台模式 — 使用 background=true 并通过 process 工具监控
  6. 不要干扰 — 使用 poll/log 监控,对长时间运行的任务保持耐心
  7. 并行处理是可行的 — 同时运行多个 Codex 进程以进行批量工作