Workflow Todo State
Use this skill to make long-running agent workflows recoverable from named workflow state files. The pattern combines human-readable Markdown checklists with machine-readable YAML frontmatter and a deterministic state script.
Quick Start
Install into another project:
skills/workflow-todo-state/scripts/install.sh /path/to/target-project --agent-dir .agent --with-skill --init-layout --update-agents
Use --profile <name> for any built-in layout in profiles/*.yaml, or --agent-dir, --skills-dir, and --entry-file for a custom layout. The Codex profile correctly separates .agents/skills from .codex; omitting profile options keeps the historical .claude + CODEBUDDY.md default.
Then:
- Create workflow definitions under
<agent-dir>/workflows/{workflow-id}/. - Add
routing.yamlto every workflow directory as the source of truth for its trigger conditions and state file pattern. - Generate the routing registry with
<agent-dir>/scripts/sync-workflow-routing.sh. - Create run state files under
workspace/workflow-runs/{task-or-feature}.workflow.md. - Create or update the state file from
references/basic-state-template.md. - Ensure every phase has exactly one status line:
> [P0] ⬜ 未开始 - Make every workflow skill or agent route the task, then read the relevant workflow state file before starting work.
- Update state only through the script:
<agent-dir>/scripts/todo-state.sh "${WORKFLOW_STATE_FILE}" start P1 <agent-dir>/scripts/todo-state.sh "${WORKFLOW_STATE_FILE}" complete P1 <agent-dir>/scripts/todo-state.sh "${WORKFLOW_STATE_FILE}" skip P2 "not needed" <agent-dir>/scripts/todo-state.sh "${WORKFLOW_STATE_FILE}" block P3 "waiting for user input"
Recommended Layout
Use separate files for workflow definitions and workflow runs:
.agent/
workflows/
feature-development/
workflow.md
state-template.md
routing.yaml
release-check/
workflow.md
state-template.md
routing.yaml
rules/
workflow-routing.md
scripts/
sync-workflow-routing.sh
workspace/
workflow-runs/
payment-refactor.workflow.md
release-v1-2.workflow.md
Do not name every run todo.md when a project can have multiple workflows. Prefer descriptive state files:
{feature-name}.workflow.md{task-name}.workflow.md{workflow-id}-{run-id}.workflow.md
Use todo.md only for a single-purpose project where one workflow will ever exist.
Required State File Shape
Each reusable workflow state file should contain:
- YAML frontmatter with
workflow_id,workflow_name,workflow_version,state_file_type,run_id,task,created_from,current_phase,current_status,mode, andblocked_reason. - A visible line beginning with
> 当前阶段:. - One unique phase status line per phase, using
> [PN] .... - An
## 异常记录table ifskiporblockshould append history.
See references/basic-state-template.md for a minimal portable state template, references/workflow-routing-template.md for routing rules, and references/integration.md for retrofit instructions.
Routing Metadata and Synchronization
Each workflow directory must contain a minimal scalar routing.yaml:
workflow_id: feature-development
required: true
when_to_use: "Implementing or changing a product feature"
triggers: "new feature; bug fix; refactor"
excludes: "read-only question; inspect-only request"
state_file_pattern: "workspace/workflow-runs/feature-{task}.workflow.md"
workflow_id must match its directory name. Keep values on one line and do not use |, because they are rendered into a Markdown table.
After every workflow create, change, rename, or deletion, run:
<agent-dir>/scripts/sync-workflow-routing.sh
<agent-dir>/scripts/sync-workflow-routing.sh --check
The first command regenerates only the marked block in <agent-dir>/rules/workflow-routing.md; the second is suitable for pre-commit or CI and fails when the registry is stale.
State Rules
start PNrequires all previous phases to be✅ 已完成or⏭️ 跳过.complete PNrequires the phase to be🔲 进行中.skip PNrefuses completed phases and records a reason.block PNmarks an open phase in progress, writescurrent_status: blocked, and records a reason; completed and skipped phases are terminal.- After
completeorskip, the script advancescurrent_phaseto the next⬜ 未开始phase, or todonewhen no pending phase remains.
When Retrofitting A Project
Keep the change small:
- Add the script.
- Add
<agent-dir>/workflows/,workspace/workflow-runs/, and<agent-dir>/rules/workflow-routing.md. - Add
routing.yamlto every existing workflow, then runsync-workflow-routing.sh. - Add frontmatter and unique phase lines to existing state files.
- Replace ad hoc
sedor manual status edits in skills/agents withtodo-state.sh. - Add a project entry rule: before any mutating action, route the task; if a required workflow matches, create or resume its run and start the current phase.
- Run
sync-workflow-routing.sh --checkin pre-commit or CI. - Test one happy path, one blocked/invalid transition, and one stale-routing failure.
Do not force a project to adopt this exact workflow structure. Preserve local phase names, output files, and user confirmation gates.