Codex Orchestrator
This skill provides a workflow for supervising the Codex coding agent running in background processes.
Workflow
1. Start (Launch)
Always launch Codex in a background PTY session to maintain interactivity without blocking the main agent.
CODEBLOCK0
- * Store the returned
sessionId. - If
sessionId is lost, find it via process action:list.
2. Monitor (Watch)
Check progress regularly (e.g., via cron or manual check).
CODEBLOCK1
Signs of life:
- * Spinner animations or progress bars updating.
- "Working...", "Thinking...", "Running...".
- File edits (
Edit ...).
Signs of blockage:
- * Interactive prompts (e.g., "Select directory", "Approve change [y/n]").
- No log output for >5 minutes (process might be hung or waiting for hidden input).
3. Intervene (Control)
If Codex is stuck at a prompt:
CODEBLOCK2
If Codex is looping or hallucinating:
CODEBLOCK3
4. Report (Notify)
When a significant milestone is reached or the task is done:
- 1. Summarize the work done (files changed, tests passed).
- Notify the user.
Standard Operating Procedures (SOPs)
"The Stuck Agent" Protocol
- 1. Diagnose: Run
process action:log sessionId:<id> limit:500. - Analyze: Is it asking a question? Is it downloading?
- Action:
* If asking: Provide answer via
submit.
* If downloading (slow): Wait.
* If silent >10m: Send a "poke" (e.g.
submit data:"\n" to refresh prompt) or kill/resume.
"The Resume" Protocol
If a session died or was killed:
- 1. Run
codex resume --last or codex resume <session_id> in a new background process. - Verify it picked up the context.
Logs & Artifacts
- * Codex logs are ephemeral in the PTY buffer.
- For persistent logs, instruct Codex to write to a file:
codex exec "task..." > codex.log 2>&1 (Note: buffering may delay output). - Better: Use
process action:log to snapshot the buffer periodically.
Codex Orchestrator
该技能提供了一种工作流程,用于监督在后台进程中运行的Codex编码代理。
工作流程
1. 启动(Launch)
始终在后台PTY会话中启动Codex,以保持交互性,同时不阻塞主代理。
bash
bash pty:true workdir:<目标目录> background:true command:codex exec --full-auto <提示词>
- * 保存返回的sessionId。
- 如果sessionId丢失,可通过process action:list查找。
2. 监控(Watch)
定期检查进度(例如,通过cron或手动检查)。
bash
获取最后2KB日志以查看当前状态
process action:log sessionId:
limit:2000
活跃迹象:
- * 旋转动画或进度条更新。
- 工作中...、思考中...、运行中...。
- 文件编辑(Edit ...)。
阻塞迹象:
- * 交互式提示(例如,选择目录、批准更改 [y/n])。
- 超过5分钟无日志输出(进程可能挂起或等待隐藏输入)。
3. 干预(Control)
如果Codex卡在提示处:
bash
发送y和回车
process action:submit sessionId: data:y
仅发送回车(默认选项)
process action:submit sessionId: data:
如果Codex陷入循环或产生幻觉:
bash
终止会话
process action:kill sessionId:
4. 报告(Notify)
当达到重要里程碑或任务完成时:
- 1. 总结已完成的工作(更改的文件、通过的测试)。
- 通知用户。
标准操作程序(SOPs)
卡住代理协议
- 1. 诊断:运行process action:log sessionId: limit:500。
- 分析:它是在提问?还是在下载?
- 操作:
* 如果在提问:通过submit提供答案。
* 如果在下载(缓慢):等待。
* 如果静默超过10分钟:发送唤醒(例如submit data:\n刷新提示)或终止/恢复。
恢复协议
如果会话终止或被杀死:
- 1. 在新的后台进程中运行codex resume --last或codex resume 。
- 验证它已恢复上下文。
日志与工件
- * Codex日志在PTY缓冲区中是临时的。
- 如需持久化日志,指示Codex写入文件:codex exec 任务... > codex.log 2>&1(注意:缓冲可能导致输出延迟)。
- 更好的做法:使用process action:log定期快照缓冲区。