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")
規則
- 始終使用
pty=true— Codex 是一個交互式終端應用,如果沒有 PTY 將會掛起 - 需要 Git 倉庫 — Codex 不會在 git 目錄之外運行。對於臨時性工作,使用
mktemp -d && git init - 對一次性任務使用
exec—codex exec "prompt"運行並乾淨地退出 - 構建時使用
--full-auto— 自動批准沙箱內的更改 - 長時間任務使用後臺模式 — 使用
background=true並通過process工具監控 - 不要干擾 — 使用
poll/log監控,對長時間運行的任務保持耐心 - 並行處理是可行的 — 同時運行多個 Codex 進程以進行批量工作