workflow-state
workflow-state.json 是運行執行的唯一真相來源。架構:
templates/workflow-state.template.json。它由每次工件寫入時的 post-write-state 鉤子以及 scripts/approve_event.py / scripts/reject_event.py 腳本更新。代理不得手動編輯它。
鍵值
| 鍵 | 含義 |
|---|---|
run_id | 必須等於運行資料夾名稱 (runs/<run-id>) |
requirements_hash | artifacts/01-requirements.md 的 SHA-256(寫入時設定) |
execution_plan | 有序步驟:step、name、agents、depends_on、status(pending/running/done/failed)、attempts |
artifacts | 運行相對路徑到 {owner, status, sha256, updated_at} 的映射 |
gate_results | 映射 G1..G8 → {status: PASS/FAIL/PASS-N/A, attempts, findings, responsible_agent} |
retry_counters | 映射 G1..G8 → 已耗費的重試輪數 |
approval | {status: pending/approved/rejected, approved_at, plan_sha256, rejected_count, feedback[]} |
notes | 僅追加的自由格式日誌(決策、跳過的代理及原因) |
更新規則
- 雜湊是檔案字節的 SHA-256(十六進位,小寫)。當步驟因工件狀態為
done且磁碟上的雜湊匹配而被跳過時,不記錄任何新內容。 - 狀態轉換:
pending → running → done|failed。針對性重試僅重新執行負責代理的步驟及其下游依賴項;將該步驟的attempts和retry_counters[gate]增加。 - 跳過的代理記錄在
notes中(例如"entertainment-planner skipped: no entertainment required"),且其工件仍寫入為Not applicable — <reason>。 - 閘門結果按閘門記錄,包含發現和
responsible_agent;狀態為status: FAIL且attempts: 3的閘門會停止依賴項執行 — 將下游步驟標記為failed並以清晰報告結束運行。 - 批准:只有
scripts/approve_event.py可以設定approval.status = "approved"和approval.plan_sha256。scripts/reject_event.py將內容附加到approval.feedback並增加rejected_count。對06-event-plan.md的修訂會使plan_sha256無效,即使該字段已過期。 - 寫入是原子性的(臨時檔 + 重新命名)。保持
updated_at為 UTC ISO-8601 格式(...Z)。
恢復合約 (/plan-event --resume <run-id>)
- 載入狀態;如果
workflow-state.json遺失或無效 → 停止並報錯。 - 重新計算
artifacts中每個路徑的磁碟雜湊;不匹配則將該工件標記為stale。 - 僅執行
status為pending/running/failed的步驟,以及工件為stale的步驟(及其下游依賴項)。 - 絕不重複執行工件為
done且雜湊匹配的步驟。 - 每個工件完成後,鉤子會自動更新狀態 — 協調器僅更新
execution_plan、gate_results、retry_counters和notes。