實作指南 / 19 分鐘
從 Subagents 擴展到安全 Automation
先平行獨立 evidence,再把穩定 workflow 移入 codex exec 與 CI。
Subagents 把 noisy exploration 移出 main thread,適合平行 independent read-heavy work。codex exec 預設 read-only,progress 到 stderr、final message 到 stdout;JSONL/schema 支援 machine consumer。GitHub Actions 應使用官方 action 與最小權限。
已驗證 Terminal Sequence
- ›
/agent - $
codex exec "summarize the repository structure" - $
codex exec --ephemeral "triage this repository" - $
codex exec --json "summarize the repo structure" | jq - $
codex exec resume --last "continue the task"
工作原則
平行 independent work
先做 exploration、tests、triage、review;parallel writes 需 file ownership/coordination。
Child 繼承 boundary
Subagents 繼承 parent sandbox/live overrides,先設權限再 spawn。
只 automate 穩定 contract
Prompt、inputs、permissions、output、failure handling 可重複後才進 codex exec。
實地程序
- 01
Delegate bounded reads
每個 independent concern 一個 agent,wait all,回 concise evidence。
- 02
檢查 agent threads
用 /agent 讀 status/result,不把 raw logs 塞 main context。
- 03
以 codex exec prototype
先 read-only/ephemeral,piped context 有界。
- 04
加入 machine output
--json 事件流或 --output-schema final object;repo state 相容才 resume。
- 05
Harden CI
使用 openai/codex-action@v1、trusted triggers、minimal permissions、isolated secrets、separate write job。
PASS / FAIL
驗收清單
- Subtasks independent/bounded。
- Parent permission least privilege。
- Automation 處理 non-zero/malformed output。
- Repo write credential 與 Codex job 隔離。
WATCH / REJECT
失敗模式
- 為 tightly coupled writes spawn agents。
- 新 script 使用 deprecated --full-auto。
- Job-wide 暴露 API key 給 repo code。