stepwise
After explicit selection of $stepwise, execute the chosen ordered process.
Each independent step
runs in a new clean child using transport selected for that step. Same-host
work normally uses an active-host native child; the existing Claude, Codex,
Grok, and Kimi subprocess harness is the explicit external adapter. A new clean critic
judges whether each attempt honored its declared contract. When a critic fails
or abstains with inspectable evidence, Stepwise diagnoses the failure before
repair: it reads the evidence, talks directly to the exact relevant child,
walks upstream when inputs are suspect, and authors the repair prompt itself.
Stepwise maintains a truthful chain from user intent to manifest, from manifest
to owner skill, from owner skill to worker action, from worker action to
evidence, and from evidence to critic judgment. When the chain breaks,
Stepwise locates the break and restores truth. It does not paper over the
break.
When to use
- "ramp up on and implement strictly according to order"
- "run in ../ and make sure no steps are skipped"
- "orchestrate with a critic checking each step"
- "just get it done but don't make stuff up" where the request still needs
ordered child roles and auditable evidence
When not to use
- Free-form requirement loops with no step manifest -> native
/goal.
- Plan-doc-backed implementation of a fixed architecture plan ->
$arch-step.
- Bet-and-learn optimization, one bet per iteration with worklog ->
native goal mode.
- One-shot review of a diff or branch -> the host agent's normal review
response. Use
$codex-review-yolo only when the exact external yolo
profile and its receipts are the requested benefit.
- Work that fits in a single orchestrator turn with no child roles.
Non-negotiables
- Truthful propagation is the single invariant. Every pass corresponds to
honest evidence. Every fail is diagnosed to root cause before repair. No step
passes with fabricated evidence; no repair prompt contains invented
constraints.
- Pin
raw_instructions verbatim with sha256. Any rewrite clears run state.
- Produce a Step Manifest and confirm it with the user before any step
executes. Strictness tunes the gate's behavior; it never removes it.
- Apply
../_shared/agent-orchestration-policy.md at every dispatch.
Apply $prompt-authoring to every actual populated first brief or materially
reframed follow-up. Prefer clean native children for ordinary same-host
workers and critics. Use an external session when a concrete provider, exact
model/profile, durable lifecycle, worktree/process isolation, automation
surface, structured receipt, or another real benefit is worth the extra
process and integration cost. These examples are recognition aids, not an
allowlist.
- Every worker step starts as a new clean child. Diagnostic and repair messages
resume that exact child so the worker keeps its own role history.
- Every critic is a new clean, independent child. The critic observes and
returns structured JSON conforming to
StepVerdict; it never prescribes
future worker actions and is never resumed.
- The critic observes; the orchestrator reasons; the worker executes. The
critic never writes agent commands. The orchestrator never edits target-repo
files or invents constraints. The worker never sees orchestrator-internal
vocabulary.
- Native starting context is explicit. Codex dispatch always sets
fork_turns to "none" for normal workers and critics, to a positive count
only for deliberately bounded chat context, or to "all" only when the full
conversation is genuinely load-bearing. Claude uses a clean named subagent
by default; an explicit conversation fork means full inherited conversation,
while a skill with context: fork is an isolated clean subagent context.
Context is separate from permissions, capabilities, and worktree isolation.
- The orchestrator owns external topology and integration. Worker and critic
prompts allow each role its own native sub-agents on its own host and forbid
starting external agents.
- Every critic fail and every inspectable abstain enters the same diagnostic
protocol. Stepwise holds read-only diagnostic conversation with the agents
involved, walking upstream when evidence points there, until root cause is
located or the diagnostic turn cap is exhausted.
- If diagnosis shows a step received bad input from an earlier step, repair the
upstream worker that owns the bad input. Downstream steps start new clean
replacements after upstream repair; resuming downstream children would
compound broken context.
- Every hard boundary and operational instruction in a repair prompt carries
an authority tag: user, manifest, or owner runbook. Critic evidence and a
parent-confirmed diagnosis may travel only as non-binding, falsifiable
context; they cannot create a worker command. Unsourced boundaries or
instructions are invented and must be removed.
- Learnings are consulted with applicability tests and surfaced in Stepwise's
reasoning. They never appear as worker-facing doctrine. Workers act on owner
doctrine, not on Stepwise process memory.
- Permissions and worktree behavior are resolved independently from context.
Use enforced read-only capability for critics when the host exposes it,
retain the no-edit prompt contract, and compare target-repo state before and
after critic work. External worker and critic subprocesses keep the existing
dangerous / skip-permissions / no-sandbox convention; that convention does
not describe native children.
- Native same-host roles need no invented runtime/model promise. For an
external lane, base runtime and normally effort are supplied by the user or target
doctrine for worker and critic independently. Models are also supplied
except that an external Codex lane with no named model defaults to
gpt-6-astra, and that Astra lane defaults an omitted effort to xhigh; Kimi
defaults to kimi-code/k3 and an omitted effort to max. Natural Grok
wording resolves to grok-4.6, while explicit legacy Grok ids stay exact.
Ask once only for missing load-bearing external values.
- Optional execution preferences are interpreted after the Step Manifest is
drafted. A phrase like "copywriting steps use Claude Fable 5.1" is a routing
preference to resolve against real steps, not a built-in category.
- Orchestrator does not persistently load the target repo's contents into its
own context. It points clean children at paths; children read source truth.
- Resolve profile, execution routing, and repair limits from the complete user
prompt, then quote the source phrase in the announcement when a specific
phrase drives the decision.
- Default broken-step repair limit is 5 operational repair bounces. A clear
user bound such as "up to three times" can override it; otherwise keep 5.
Strict/balanced/lenient never changes this number.
- Diagnostic read-only turns do not consume repair bounces. Operational repair
prompts do.
- In the external lane, do not use stateless-only worker flags because workers
must be resumable. External critics use the runtime's fresh/stateless command
shape where supported. Kimi always persists a session, so a Kimi critic is a
new clean session that is never resumed, not a stateless/no-persist process.
- Silent worker repair past the resolved repair limit, silent skipping, and
silent advance on fail are forbidden. Apply
stop_discipline when repair
capacity is exhausted.
- Fabricated step completion, claim without artifact or transcript evidence,
fails the step regardless of profile.
- Do not use
/loop or ScheduleWakeup to bridge child work. Native roles use
host wait/status primitives. The external lane uses foreground
run_stepwise.py calls; if a subprocess genuinely outlasts the shell
timeout, use supported background execution and its harness receipt.
- Long children commonly take 5+ minutes. For native roles, use host child
state; for external
xhigh or max turns, inspect live stream.log and
process liveness every few minutes rather than polling every few seconds or
treating a missing final file as a hang before exit.
First move
- Capture the user's prompt verbatim. Compute
sha256.
- Read
../_shared/agent-orchestration-policy.md.
- Read
references/strictness-profiles.md. Interpret profile, forced
checks, stop discipline, and broken-step repair limit.
- Read
references/model-and-effort.md and
references/execution-routing.md. Resolve transport, clean starting
context, and any external execution preferences. Ask one consolidated
question only when a selected external lane lacks load-bearing values.
- Resolve
target_repo_path as an absolute path. Fail loud if unresolvable.
- Read
references/workflow-contract.md for the five-phase workflow.
- Read
references/diagnose-and-repair.md before executing any child
loop.
- Read
references/unblocking.md before deciding a child failure is a
user-facing blocker.
- Announce the interpretation before Phase 2.
Workflow
Five phases. Detail lives in references/workflow-contract.md.
- Intake & interpretation. Parse the prompt; set profile, forced checks,
stop discipline, repair limit, execution defaults, and unresolved execution
preferences. Announce.
- Process grounding. Read the target repo's
CLAUDE.md / AGENTS.md
and the named process's SKILL.md. Draft steps, resolve execution
preferences against those steps, and write manifest.json per
references/manifest-schema.md.
- Plan confirmation. Print manifest + interpretation. Gate per profile:
strict always pauses, balanced pauses once, lenient prints and proceeds.
Always include the resolved dispatch table.
- Step execution loop. For each step: start a clean worker, start a clean
observational critic, advance on pass, and on fail or inspectable abstain
run the single diagnose-and-repair protocol. Repair at the root-cause
worker, start downstream replacements clean after upstream repair, and halt
when repair capacity or diagnostic clarity is exhausted.
- Report. Per-step status table, run directory path, instructive critic
observations, diagnostic records, learnings considered/written, and pending
work if halted. No certification language.
Output expectations
- Run directory at
.arch_skill/stepwise/runs/<run-id>/ in the orchestrator
repo root.
- Per-step artifacts under
steps/<n>/try-<k>/.
- Attempt origin metadata at
steps/<n>/try-<k>/origin.json.
- Diagnostic records under
steps/<n>/try-<k>/diagnostic/.
- Learnings under
.arch_skill/stepwise/learnings/.
report.md summarizing the run in plain English.
- Console summary with run path, status table, and any halted root cause.
Reference map
references/workflow-contract.md - five phases with inputs, outputs,
failure modes, and where judgment lives.
references/diagnose-and-repair.md - single failure-handling protocol,
diagnostic conversation, upstream traversal, repair authorship, budgets, and
halt conditions.
references/strictness-profiles.md - profile, forced checks, stop
discipline, and repair-bounce policy.
references/model-and-effort.md - how to elicit base worker/critic runtime,
model, and effort from the user.
references/execution-routing.md - how to resolve optional execution
preferences against drafted steps without hardcoded task taxonomies.
references/unblocking.md - how roles handle known blockers before asking or
halting.
references/manifest-schema.md - Step Manifest and StepDescriptor shape.
references/critic-contract.md - observational StepVerdict schema and check
definitions.
references/step-verdict.schema.json - canonical StepVerdict JSON schema.
references/critic-prompt.md - verbatim observation-only critic prompt.
references/session-prompt-contracts.md - initial, diagnostic, and repair
prompt contracts for worker sessions.
references/session-resume.md - native context/continuation mapping plus the
external Claude, Codex, Grok, and Kimi session adapter.
references/run-directory-layout.md - on-disk artifact layout.
references/learnings.md - persistent process-learning ledger.
references/examples.md - worked examples of local diagnosis and upstream
traversal.
The orchestration script
scripts/run_stepwise.py is deterministic run-state plumbing plus the explicit
external-session adapter. Its transport-neutral subcommands create and inspect
run artifacts; its launch subcommands spawn external processes, capture session
ids, and validate critic verdicts. It does not choose transport, interpret the
user's prompt, draft the manifest, decide root cause, or author repairs.
Subcommands:
init-run - create the run directory and initial state.json.
step-spawn - spawn a new clean external worker session; capture session id.
step-resume - resume an existing worker session with an operational repair
prompt.
step-diagnose - resume an existing worker session read-only and write the
diagnostic turn into diagnostic/ without consuming a repair bounce.
critic-spawn - spawn a new clean external critic with a structured schema;
parse and validate the observational verdict.
latest-session - print latest try/session metadata for a step.
upstream-for - print manifest-declared upstream artifacts and latest
sessions for a step.
report-scaffold - print or write a deterministic report.md scaffold.
Run python3 scripts/run_stepwise.py <subcommand> --help for flags.
1---2name: stepwise3description: Explicitly selected ordered process with a clean worker and critic per step and exact-worker repair. Use when the user chooses $stepwise or binding task instructions require it. A numbered task list or ordinary multi-step work does not select worker orchestration.4---56# stepwise78After explicit selection of `$stepwise`, execute the chosen ordered process.9Each independent step10runs in a new clean child using transport selected for that step. Same-host11work normally uses an active-host native child; the existing Claude, Codex,12Grok, and Kimi subprocess harness is the explicit external adapter. A new clean critic13judges whether each attempt honored its declared contract. When a critic fails14or abstains with inspectable evidence, Stepwise diagnoses the failure before15repair: it reads the evidence, talks directly to the exact relevant child,16walks upstream when inputs are suspect, and authors the repair prompt itself.1718Stepwise maintains a truthful chain from user intent to manifest, from manifest19to owner skill, from owner skill to worker action, from worker action to20evidence, and from evidence to critic judgment. When the chain breaks,21Stepwise locates the break and restores truth. It does not paper over the22break.2324## When to use2526- "ramp up on <topic> and implement <lesson> strictly according to <skill> order"27- "run <named process> in ../<repo> and make sure no steps are skipped"28- "orchestrate <multi-step flow> with a critic checking each step"29- "just get it done but don't make stuff up" where the request still needs30 ordered child roles and auditable evidence3132## When not to use3334- Free-form requirement loops with no step manifest -> native `/goal`.35- Plan-doc-backed implementation of a fixed architecture plan -> `$arch-step`.36- Bet-and-learn optimization, one bet per iteration with worklog ->37 native goal mode.38- One-shot review of a diff or branch -> the host agent's normal review39 response. Use `$codex-review-yolo` only when the exact external `yolo`40 profile and its receipts are the requested benefit.41- Work that fits in a single orchestrator turn with no child roles.4243## Non-negotiables4445- Truthful propagation is the single invariant. Every pass corresponds to46 honest evidence. Every fail is diagnosed to root cause before repair. No step47 passes with fabricated evidence; no repair prompt contains invented48 constraints.49- Pin `raw_instructions` verbatim with `sha256`. Any rewrite clears run state.50- Produce a Step Manifest and confirm it with the user before any step51 executes. Strictness tunes the gate's behavior; it never removes it.52- Apply `../_shared/agent-orchestration-policy.md` at every dispatch.53 Apply `$prompt-authoring` to every actual populated first brief or materially54 reframed follow-up. Prefer clean native children for ordinary same-host55 workers and critics. Use an external session when a concrete provider, exact56 model/profile, durable lifecycle, worktree/process isolation, automation57 surface, structured receipt, or another real benefit is worth the extra58 process and integration cost. These examples are recognition aids, not an59 allowlist.60- Every worker step starts as a new clean child. Diagnostic and repair messages61 resume that exact child so the worker keeps its own role history.62- Every critic is a new clean, independent child. The critic observes and63 returns structured JSON conforming to `StepVerdict`; it never prescribes64 future worker actions and is never resumed.65- The critic observes; the orchestrator reasons; the worker executes. The66 critic never writes agent commands. The orchestrator never edits target-repo67 files or invents constraints. The worker never sees orchestrator-internal68 vocabulary.69- Native starting context is explicit. Codex dispatch always sets70 `fork_turns` to `"none"` for normal workers and critics, to a positive count71 only for deliberately bounded chat context, or to `"all"` only when the full72 conversation is genuinely load-bearing. Claude uses a clean named subagent73 by default; an explicit conversation fork means full inherited conversation,74 while a skill with `context: fork` is an isolated clean subagent context.75 Context is separate from permissions, capabilities, and worktree isolation.76- The orchestrator owns external topology and integration. Worker and critic77 prompts allow each role its own native sub-agents on its own host and forbid78 starting external agents.79- Every critic fail and every inspectable abstain enters the same diagnostic80 protocol. Stepwise holds read-only diagnostic conversation with the agents81 involved, walking upstream when evidence points there, until root cause is82 located or the diagnostic turn cap is exhausted.83- If diagnosis shows a step received bad input from an earlier step, repair the84 upstream worker that owns the bad input. Downstream steps start new clean85 replacements after upstream repair; resuming downstream children would86 compound broken context.87- Every hard boundary and operational instruction in a repair prompt carries88 an authority tag: user, manifest, or owner runbook. Critic evidence and a89 parent-confirmed diagnosis may travel only as non-binding, falsifiable90 context; they cannot create a worker command. Unsourced boundaries or91 instructions are invented and must be removed.92- Learnings are consulted with applicability tests and surfaced in Stepwise's93 reasoning. They never appear as worker-facing doctrine. Workers act on owner94 doctrine, not on Stepwise process memory.95- Permissions and worktree behavior are resolved independently from context.96 Use enforced read-only capability for critics when the host exposes it,97 retain the no-edit prompt contract, and compare target-repo state before and98 after critic work. External worker and critic subprocesses keep the existing99 dangerous / skip-permissions / no-sandbox convention; that convention does100 not describe native children.101- Native same-host roles need no invented runtime/model promise. For an102 external lane, base runtime and normally effort are supplied by the user or target103 doctrine for worker and critic independently. Models are also supplied104 except that an external Codex lane with no named model defaults to105 `gpt-6-astra`, and that Astra lane defaults an omitted effort to `xhigh`; Kimi106 defaults to `kimi-code/k3` and an omitted effort to `max`. Natural Grok107 wording resolves to `grok-4.6`, while explicit legacy Grok ids stay exact.108 Ask once only for missing load-bearing external values.109- Optional execution preferences are interpreted after the Step Manifest is110 drafted. A phrase like "copywriting steps use Claude Fable 5.1" is a routing111 preference to resolve against real steps, not a built-in category.112- Orchestrator does not persistently load the target repo's contents into its113 own context. It points clean children at paths; children read source truth.114- Resolve profile, execution routing, and repair limits from the complete user115 prompt, then quote the source phrase in the announcement when a specific116 phrase drives the decision.117- Default broken-step repair limit is 5 operational repair bounces. A clear118 user bound such as "up to three times" can override it; otherwise keep 5.119 Strict/balanced/lenient never changes this number.120- Diagnostic read-only turns do not consume repair bounces. Operational repair121 prompts do.122- In the external lane, do not use stateless-only worker flags because workers123 must be resumable. External critics use the runtime's fresh/stateless command124 shape where supported. Kimi always persists a session, so a Kimi critic is a125 new clean session that is never resumed, not a stateless/no-persist process.126- Silent worker repair past the resolved repair limit, silent skipping, and127 silent advance on fail are forbidden. Apply `stop_discipline` when repair128 capacity is exhausted.129- Fabricated step completion, claim without artifact or transcript evidence,130 fails the step regardless of profile.131- Do not use `/loop` or `ScheduleWakeup` to bridge child work. Native roles use132 host wait/status primitives. The external lane uses foreground133 `run_stepwise.py` calls; if a subprocess genuinely outlasts the shell134 timeout, use supported background execution and its harness receipt.135- Long children commonly take 5+ minutes. For native roles, use host child136 state; for external `xhigh` or `max` turns, inspect live `stream.log` and137 process liveness every few minutes rather than polling every few seconds or138 treating a missing final file as a hang before exit.139140## First move1411421. Capture the user's prompt verbatim. Compute `sha256`.1432. Read `../_shared/agent-orchestration-policy.md`.1443. Read `references/strictness-profiles.md`. Interpret profile, forced145 checks, stop discipline, and broken-step repair limit.1464. Read `references/model-and-effort.md` and147 `references/execution-routing.md`. Resolve transport, clean starting148 context, and any external execution preferences. Ask one consolidated149 question only when a selected external lane lacks load-bearing values.1505. Resolve `target_repo_path` as an absolute path. Fail loud if unresolvable.1516. Read `references/workflow-contract.md` for the five-phase workflow.1527. Read `references/diagnose-and-repair.md` before executing any child153 loop.1548. Read `references/unblocking.md` before deciding a child failure is a155 user-facing blocker.1569. Announce the interpretation before Phase 2.157158## Workflow159160Five phases. Detail lives in `references/workflow-contract.md`.1611621. **Intake & interpretation.** Parse the prompt; set profile, forced checks,163 stop discipline, repair limit, execution defaults, and unresolved execution164 preferences. Announce.1652. **Process grounding.** Read the target repo's `CLAUDE.md` / `AGENTS.md`166 and the named process's `SKILL.md`. Draft steps, resolve execution167 preferences against those steps, and write `manifest.json` per168 `references/manifest-schema.md`.1693. **Plan confirmation.** Print manifest + interpretation. Gate per profile:170 strict always pauses, balanced pauses once, lenient prints and proceeds.171 Always include the resolved dispatch table.1724. **Step execution loop.** For each step: start a clean worker, start a clean173 observational critic, advance on pass, and on fail or inspectable abstain174 run the single diagnose-and-repair protocol. Repair at the root-cause175 worker, start downstream replacements clean after upstream repair, and halt176 when repair capacity or diagnostic clarity is exhausted.1775. **Report.** Per-step status table, run directory path, instructive critic178 observations, diagnostic records, learnings considered/written, and pending179 work if halted. No certification language.180181## Output expectations182183- Run directory at `.arch_skill/stepwise/runs/<run-id>/` in the orchestrator184 repo root.185- Per-step artifacts under `steps/<n>/try-<k>/`.186- Attempt origin metadata at `steps/<n>/try-<k>/origin.json`.187- Diagnostic records under `steps/<n>/try-<k>/diagnostic/`.188- Learnings under `.arch_skill/stepwise/learnings/`.189- `report.md` summarizing the run in plain English.190- Console summary with run path, status table, and any halted root cause.191192## Reference map193194- `references/workflow-contract.md` - five phases with inputs, outputs,195 failure modes, and where judgment lives.196- `references/diagnose-and-repair.md` - single failure-handling protocol,197 diagnostic conversation, upstream traversal, repair authorship, budgets, and198 halt conditions.199- `references/strictness-profiles.md` - profile, forced checks, stop200 discipline, and repair-bounce policy.201- `references/model-and-effort.md` - how to elicit base worker/critic runtime,202 model, and effort from the user.203- `references/execution-routing.md` - how to resolve optional execution204 preferences against drafted steps without hardcoded task taxonomies.205- `references/unblocking.md` - how roles handle known blockers before asking or206 halting.207- `references/manifest-schema.md` - Step Manifest and StepDescriptor shape.208- `references/critic-contract.md` - observational StepVerdict schema and check209 definitions.210- `references/step-verdict.schema.json` - canonical StepVerdict JSON schema.211- `references/critic-prompt.md` - verbatim observation-only critic prompt.212- `references/session-prompt-contracts.md` - initial, diagnostic, and repair213 prompt contracts for worker sessions.214- `references/session-resume.md` - native context/continuation mapping plus the215 external Claude, Codex, Grok, and Kimi session adapter.216- `references/run-directory-layout.md` - on-disk artifact layout.217- `references/learnings.md` - persistent process-learning ledger.218- `references/examples.md` - worked examples of local diagnosis and upstream219 traversal.220221## The orchestration script222223`scripts/run_stepwise.py` is deterministic run-state plumbing plus the explicit224external-session adapter. Its transport-neutral subcommands create and inspect225run artifacts; its launch subcommands spawn external processes, capture session226ids, and validate critic verdicts. It does not choose transport, interpret the227user's prompt, draft the manifest, decide root cause, or author repairs.228229Subcommands:230231- `init-run` - create the run directory and initial `state.json`.232- `step-spawn` - spawn a new clean external worker session; capture session id.233- `step-resume` - resume an existing worker session with an operational repair234 prompt.235- `step-diagnose` - resume an existing worker session read-only and write the236 diagnostic turn into `diagnostic/` without consuming a repair bounce.237- `critic-spawn` - spawn a new clean external critic with a structured schema;238 parse and validate the observational verdict.239- `latest-session` - print latest try/session metadata for a step.240- `upstream-for` - print manifest-declared upstream artifacts and latest241 sessions for a step.242- `report-scaffold` - print or write a deterministic `report.md` scaffold.243244Run `python3 scripts/run_stepwise.py <subcommand> --help` for flags.