Orchestrate one specification ticket in the current working copy. Coding
children own source edits; coding:commit owns local history shaping,
coding:push-pr owns publication and remote restacking, and
specification:mdc is the only writer for .code-spec/*.md.
-
Normalize the Notion URL or 32-hex id. Pull the ticket once with
notion-sync pull <id> --follow-children --follow-links --out <tmp> and
classify its stage by status group plus label keywords — never by exact
option names, which drift per database:
to_do + idea/draft/skeleton/review → not-ready
to_do + pending/ready/approved/queued → ready-to-code
in_progress + implementing/in-progress/wip/coding → implementing
in_progress + audit/verify/qa → auditing
complete + implemented/done/shipped/merged → done
- external/archive/wontfix →
out-of-scope; unmatched → unknown
-
Materialize the authoritative bundle through specification:sync-spec.
--use-cache is valid only when the bundle contains Markdown and the
non-empty root filename ends with the ticket id; otherwise record a cache
miss and refresh. Refuse if the same root-file gate fails after refresh or
immediately before coding.
-
Read local DRAFT.md, PLAN.md, existing code, and the ticket stage.
Select exactly one mode; for unknown, ask the user to map the stage
before proceeding. Load only the selected child chain from
references/modes.md.
| Condition | Mode |
|---|
| ready-to-code + approved PLAN | COMMIT_PLAN |
| implementing + partial work | PI_ITERATE |
| ready-to-code + no approved PLAN | DRAFT_THEN_ASK |
| auditing | AUDIT_AND_COMPLETE |
| done | VERIFY_ONLY |
| stage and supplied flags contradict | FLAG_MISMATCH |
| not-ready, out-of-scope, or rejected | REFUSE |
-
Produce one evidence map covering Spec, DRAFT, PLAN, code, and every
acceptance feature. Cite bundle headings and code symbols; distinguish
absent, partial, implemented, and contradictory behavior.
-
Review the proposed contract against current architecture. Fan out only
when independent reviewer or workflow capability is actually available;
otherwise perform one soundness pass. For every blocking ambiguity, stop
and ask. Record the decision through specification:mdc, then re-read the
changed spec. Never guess an architectural decision.
-
Require approval of the resolved mode, scope, feature map, and soundness
decisions unless --skip-approval. --dry-run stops after reporting this
plan.
-
Resolve repo_path, verify the working tree, and capture immutable
base_rev before any child runs. Scaffold DEVIATIONS.md only for
code-producing modes. Material deviations are appended using the policy in
references/modes.md; trivial formatter, inferred-type, or documentation
differences are not logged. After every material deviation, revalidate the
remaining PLAN dependencies and acceptance map before dispatching dependent
work. A low-impact reversible departure may continue and be logged; a
deviation affecting architecture, public API, data model, security/privacy,
destructive migration, user-visible semantics, or acceptance criteria must
return pending_decision and stop the stale branch.
-
Select the execution mechanism by capability, not preference:
- When
Workflow is available and the mode is COMMIT_PLAN,
PI_ITERATE, or AUDIT_AND_COMPLETE, load
references/execute-workflow.md and use
its fan-out, adversarial-verify, retry loop.
- Otherwise load the selected sequential chain in
references/modes.md.
Pass the absolute repo path, root spec pointer, acceptance map, mode, and
deviation policy to every child; both references carry the dispatch and
report bounds. Capture child_dispatch_log and commits_landed. When
execution returns pending_decision, stop, ask the user, persist the
answer through specification:mdc, and resume the same workflow run — do
not start over or continue past it. Surface any iteration or token guard
as unresolved and return partial with coding:handover.
-
When commits landed, load
references/stack-aware-sizing.md.
Measure the aggregate diff from base_rev; route oversized splitting
through the coding:commit --create-pr compatibility entrypoint and
semantic restacking to coding:push-pr. Never mutate history or publish
directly.
-
Run specification:review-implementation against the bundle. On P0/P1
alignment findings, dispatch coding:fix and retry alignment — at most
three passes, after which remaining findings are reported instead of
looped on. General and security review still run on every pass.
-
For landed code-producing modes, load
references/thought-experiment.md.
Run its read-only usage trace at the required capability; if that
capability is unavailable, report partial rather than silently
downgrade.
-
Detect a linked Git worktree by comparing common-dir and git-dir. A jj
workspace is allowed. If a linked Git worktree contains the landed
commits, ask whether to keep or relocate them; delegate relocation to
coding:commit.
-
Run the verification below; when a check fails, fix the cause and re-run
that check. Repeat until every check passes or a concrete blocker
remains, then report the blocker instead of looping.