schema_version: "1.0" workflow: id: "ado-lifecycle" name: "ADO story lifecycle" version: "0.4.0" author: "praveenlavu" description: "Azure DevOps story to an open PR: spec, plan, tasks, push, implement, gate, review, PR. Every board or PR change is preview, human gate, apply. The story closes after merge." requires: speckit_version: ">=1.2.1" integrations: # Advisory, non-exhaustive hint (same list as upstream's speckit workflow); the workflow # runs on any integration the project was initialized with. any: - "alquimia" - "claude" - "copilot" - "gemini" - "opencode" inputs: story_id: type: number required: true prompt: "Azure DevOps story ID" integration: type: string default: "auto" prompt: "Integration to use (e.g. claude, copilot, gemini; 'auto' uses the project's initialized integration)" review_model: type: string default: "" prompt: "Model for the review step (empty = the integration's default). Recommended: a different model from the one that implemented, e.g. a stronger one; it feeds only the review step" verdict_review_spec: type: string enum: ["", "approve", "reject"] default: "" prompt: "Verdict for gate review-spec supplied by `ado approvals sync --resume` (leave empty: the gate asks at a terminal or pauses)" verdict_approve_questions: type: string enum: ["", "approve", "reject"] default: "" prompt: "Verdict for gate approve-questions supplied by `ado approvals sync --resume` (leave empty: the gate asks at a terminal or pauses)" verdict_approve_plan_questions: type: string enum: ["", "approve", "reject"] default: "" prompt: "Verdict for gate approve-plan-questions supplied by `ado approvals sync --resume` (leave empty: the gate asks at a terminal or pauses)" verdict_wait_po_answers: type: string enum: ["", "approve", "reject"] default: "" prompt: "Verdict for gate wait-po-answers supplied by `ado approvals sync --resume` (leave empty: the gate asks at a terminal or pauses)" verdict_approve_answers_questions: type: string enum: ["", "approve", "reject"] default: "" prompt: "Verdict for gate approve-answers-questions supplied by `ado approvals sync --resume` (leave empty: the gate asks at a terminal or pauses)" verdict_review_plan: type: string enum: ["", "approve", "reject"] default: "" prompt: "Verdict for gate review-plan supplied by `ado approvals sync --resume` (leave empty: the gate asks at a terminal or pauses)" verdict_approve_push: type: string enum: ["", "approve", "reject"] default: "" prompt: "Verdict for gate approve-push supplied by `ado approvals sync --resume` (leave empty: the gate asks at a terminal or pauses)" verdict_approve_decisions: type: string enum: ["", "approve", "reject"] default: "" prompt: "Verdict for gate approve-decisions supplied by `ado approvals sync --resume` (leave empty: the gate asks at a terminal or pauses)" verdict_approve_sync: type: string enum: ["", "approve", "reject"] default: "" prompt: "Verdict for gate approve-sync supplied by `ado approvals sync --resume` (leave empty: the gate asks at a terminal or pauses)" verdict_review_review: type: string enum: ["", "approve", "reject"] default: "" prompt: "Verdict for gate review-review supplied by `ado approvals sync --resume` (leave empty: the gate asks at a terminal or pauses)" verdict_approve_pr: type: string enum: ["", "approve", "reject"] default: "" prompt: "Verdict for gate approve-pr supplied by `ado approvals sync --resume` (leave empty: the gate asks at a terminal or pauses)" verdict_wait_po_validation: type: string enum: ["", "approve", "reject"] default: "" prompt: "Verdict for gate wait-po-validation supplied by `ado approvals sync --resume` (leave empty: the gate asks at a terminal or pauses)" # Each command step runs the agent once with no chance to reply, so every ADO-changing # step is a triplet: shell preview (--plan-out) -> gate (show_file) -> shell --apply. # The apply passes --expect-plan with the preview's file and the same flags, so it re-renders the # plan and refuses (exit 2, fresh plan in .new) unless it is exactly what the gate showed. # Each triplet sits in a do-while loop capped at ONE pass (max_iterations: 1): a refused apply (exit 2 with a # fresh .new) ends its step cleanly, the loop does not repeat, and the *-applied step after it stops the # run (exit 1: start a new run). The loop must not repeat because a verdict supplied with `--input` (or left in # the inputs by an earlier resume) stays set and would pass the second gate with no prompt, applying a plan no # human saw (found by an automated review on the Spec Kit catalog PR; tests/test_speckit_contract.py). A plain # `specify workflow resume` re-runs only the failed step, so it can never apply the new plan. Any other # failure stops the run as before. # Command steps that could write ADO get `--workflow`, which makes them skip every ADO write; # pull, plan, gate and review also get it so they never stop to ask: open decisions go to # ledger section 2 (`Q` lines with owner: PO for the product owner; the questions triplets post those). # Every command step sets `integration: "{{ inputs.integration }}"` (default "auto" = the project's # initialized integration); without it the engine fails with "integration None". # Only inputs.story_id (a number) is interpolated into any run; gate messages are constant. # The strict-mode steps (strict-check-implement, decisions-loop, strict-verify, wait-po-validation) need no shell conditionals: # in an advisory project `ado strict check` and `ado strict verify` exit 0 with "mode is advisory", and decisions-loop is # a no-op when there is no decisions file; when there is one the post happens in every mode, behind the gate # (`ado decisions --post --if-any` exits 0 with nothing to post, so the gate says so and you approve it). # Comment approval (approval: "comment" on the target branch; docs/unattended.md). Every gate has its own `verdict_` input (underscores), # empty by default: an empty input leaves the gate exactly as it was (it asks at a terminal, and without one it pauses). `ado approvals sync # --resume` sets the paused gate's input to approve or reject and resets the other eleven, so it only un-pauses: anyone who can run `specify` # can set an input, so the authority is the CLI. The five review and wait gates are followed by `ado approvals check --gate ` (a no-op in # terminal mode, exit 2 in comment mode unless an approver's comment for the current artifacts exists); the seven write gates are checked by the apply # right after them. `ado questions --sync` (after the wait-po-answers check, before plan-with-answers) and `ado decisions --sync` (after the # wait-po-validation gate, before its check) write the approvers' `/answer` and `/approve|/reject` comments into the local ledger and decisions file. # `--if-comment-mode` makes each a no-op (exit 0, a fixed note, before any token or request) unless `approval` is "comment" on the target branch, so a # terminal-mode run is unchanged even when approvers are configured; the decisions step is also a no-op when the decisions file does not exist at all. # Every other refusal (a link, an oversized or non-UTF-8 file, no approvers, a token that can bypass rules, cut-off comments) stops the run. # Only inputs.story_id is interpolated into a shell command (never a verdict or review_model). `review_model` is the review step's model. # The run ends at the open PR: closing happens after merge (CI close-story, or speckit.ado.done). steps: - id: pull command: speckit.ado.pull integration: "{{ inputs.integration }}" input: args: "{{ inputs.story_id }} --workflow" # Strict mode: stop here (before anything is reviewed or posted) unless the stack profile is approved, matches # strict.test_command and covers every detected root. Advisory: exit 0 with notes. The fix is `speckit.ado.stack` by hand. - id: stack-check type: shell run: "ado stack show --check" - id: review-spec type: gate verdict_input: verdict_review_spec message: "Review the spec, the open questions in ledger section 2 and the ledger's 'Needs human decision' list before approving." options: [approve, reject] on_reject: abort - id: check-review-spec type: shell run: "ado approvals check {{ inputs.story_id }} --gate review-spec" # Questions raised by pull (spec ambiguities). The apply is a no-op when none are open or the comment is current. - id: questions-loop type: do-while max_iterations: 1 condition: "{{ steps.questions-apply.output.stderr | contains('plan changed since approval') }}" steps: - id: questions-preview type: shell run: "ado questions {{ inputs.story_id }} --post --plan-out .ado/plan-questions.md" - id: approve-questions type: gate verdict_input: verdict_approve_questions message: "Approve posting these open questions to the story in Azure Boards (or updating the existing questions comment). The plan file is shown below (the gate shows at most 200 lines). If the preview starts with ⚠, open the file and read it in full before approving. If it says nothing to post, approve to continue." show_file: .ado/plan-questions.md options: [approve, reject] on_reject: abort - id: questions-apply type: shell run: "ado questions {{ inputs.story_id }} --post --apply --expect-plan .ado/plan-questions.md || { [ $? -eq 2 ] && [ -e .ado/plan-questions.md.new ]; }" - id: questions-applied type: shell run: "if [ -e .ado/plan-questions.md.new ]; then echo 'spec-kit-ado: the questions plan changed after approval; start a new run' >&2; exit 1; fi" - id: plan command: speckit.ado.plan integration: "{{ inputs.integration }}" input: args: "{{ inputs.story_id }} --workflow" # Questions the plan phase raised (ledger section 2 `Q` lines, owner: PO). The same marked comment is edited, # so this adds only what pull's did not post. Its own plan file: the first loop's `.new` guard stays independent. - id: plan-questions-loop type: do-while max_iterations: 1 condition: "{{ steps.plan-questions-apply.output.stderr | contains('plan changed since approval') }}" steps: - id: plan-questions-preview type: shell run: "ado questions {{ inputs.story_id }} --post --plan-out .ado/plan-questions-after-plan.md" - id: approve-plan-questions type: gate verdict_input: verdict_approve_plan_questions message: "Approve posting the questions the plan raised to the story in Azure Boards (or updating the existing questions comment). The plan file is shown below (the gate shows at most 200 lines). If the preview starts with ⚠, open the file and read it in full before approving. If it says nothing to post, approve to continue." show_file: .ado/plan-questions-after-plan.md options: [approve, reject] on_reject: abort - id: plan-questions-apply type: shell run: "ado questions {{ inputs.story_id }} --post --apply --expect-plan .ado/plan-questions-after-plan.md || { [ $? -eq 2 ] && [ -e .ado/plan-questions-after-plan.md.new ]; }" - id: plan-questions-applied type: shell run: "if [ -e .ado/plan-questions-after-plan.md.new ]; then echo 'spec-kit-ado: the plan questions plan changed after approval; start a new run' >&2; exit 1; fi" # The engine cannot loop back, so the wait is a gate and the answers are read by a second plan run. # The run does not wait by itself: the operator waits at this gate until the product owner replies. # `--close-assumed` makes the second plan run record each still-unanswered question as `assumed:` (an open one would halt gate-check). - id: wait-po-answers type: gate verdict_input: verdict_wait_po_answers message: "The questions the plan raised are posted on the story. Approve once the product owner has answered them. Approving without their answers accepts the plan's stated assumptions: the next step reads the replies into the ledger, records each question still unanswered as `assumed: ` (ticked, and kept in ledger section 2 for review) and revises the plan. Reject to stop." options: [approve, reject] on_reject: abort - id: check-wait-po-answers type: shell run: "ado approvals check {{ inputs.story_id }} --gate wait-po-answers" - id: sync-po-answers type: shell run: "ado questions {{ inputs.story_id }} --sync --if-comment-mode" - id: plan-with-answers command: speckit.ado.plan integration: "{{ inputs.integration }}" input: args: "{{ inputs.story_id }} --workflow --close-assumed" # Questions the second plan run raised (R3 B1): never shown at wait-po-answers, so they stay open; post them so the # product owner sees them. They stay open until answered: the ledger's "no open questions" box cannot be ticked, so `ado done` reports the story not ready. - id: answers-questions-loop type: do-while max_iterations: 1 condition: "{{ steps.answers-questions-apply.output.stderr | contains('plan changed since approval') }}" steps: - id: answers-questions-preview type: shell run: "ado questions {{ inputs.story_id }} --post --plan-out .ado/plan-questions-after-answers.md" - id: approve-answers-questions type: gate verdict_input: verdict_approve_answers_questions message: "Approve posting the questions the revised plan raised to the story in Azure Boards (or updating the existing questions comment). They stay open in ledger section 2 until the product owner answers, and the story cannot be closed before then. The comment is rewritten from section 2, so a question the operator accepted as assumed is listed under 'The team assumed these' with its assumption: read the plan file for what the product owner will see. The plan file is shown below (the gate shows at most 200 lines). If the preview starts with ⚠, open the file and read it in full before approving. If it says nothing to post, approve to continue." show_file: .ado/plan-questions-after-answers.md options: [approve, reject] on_reject: abort - id: answers-questions-apply type: shell run: "ado questions {{ inputs.story_id }} --post --apply --expect-plan .ado/plan-questions-after-answers.md || { [ $? -eq 2 ] && [ -e .ado/plan-questions-after-answers.md.new ]; }" - id: answers-questions-applied type: shell run: "if [ -e .ado/plan-questions-after-answers.md.new ]; then echo 'spec-kit-ado: the answers questions plan changed after approval; start a new run' >&2; exit 1; fi" - id: review-plan type: gate verdict_input: verdict_review_plan message: "Review the plan, the spec, the open questions in ledger section 2 and the ledger's 'Needs human decision' list before approving." options: [approve, reject] on_reject: abort - id: check-review-plan type: shell run: "ado approvals check {{ inputs.story_id }} --gate review-plan" - id: tasks command: speckit.ado.tasks integration: "{{ inputs.integration }}" input: args: "{{ inputs.story_id }}" - id: push-loop type: do-while max_iterations: 1 condition: "{{ steps.push-apply.output.stderr | contains('plan changed since approval') }}" steps: - id: push-preview type: shell run: "ado push {{ inputs.story_id }} --plan-out .ado/plan-push.md" - id: approve-push type: gate verdict_input: verdict_approve_push message: "Approve creating or updating these child Tasks in Azure Boards. The plan file is shown below (the gate shows at most 200 lines). If the preview starts with ⚠, open the file and read it in full before approving." show_file: .ado/plan-push.md options: [approve, reject] on_reject: abort - id: push-apply type: shell run: "ado push {{ inputs.story_id }} --apply --expect-plan .ado/plan-push.md || { [ $? -eq 2 ] && [ -e .ado/plan-push.md.new ]; }" - id: push-applied type: shell run: "if [ -e .ado/plan-push.md.new ]; then echo 'spec-kit-ado: the push plan changed after approval; start a new run' >&2; exit 1; fi" # Strict mode: refuses (exit 2, findings on stdout) before implement starts unless spec, plan, tasks, the board Tasks and the # answered questions are in order. Advisory mode: a no-op (exit 0, "mode is advisory"). - id: strict-check-implement type: shell run: "ado strict check {{ inputs.story_id }} --phase implement" - id: implement command: speckit.ado.implement integration: "{{ inputs.integration }}" input: args: "{{ inputs.story_id }} --workflow" # The decisions implement (and plan) recorded in /Decisions_.md, posted as ONE new comment so the product owner sees them. # `--if-any`: no decisions file is a no-op (the preview says nothing to post), so it is the same triplet in every mode. - id: decisions-loop type: do-while max_iterations: 1 condition: "{{ steps.decisions-apply.output.stderr | contains('plan changed since approval') }}" steps: - id: decisions-preview type: shell run: "ado decisions {{ inputs.story_id }} --post --if-any --plan-out .ado/plan-decisions.md" - id: approve-decisions type: gate verdict_input: verdict_approve_decisions message: "Approve posting these development decisions and assumptions to the story in Azure Boards as one new comment. The plan file is shown below (the gate shows at most 200 lines). If the preview starts with ⚠, open the file and read it in full before approving. If it says nothing to post, approve to continue." show_file: .ado/plan-decisions.md options: [approve, reject] on_reject: abort - id: decisions-apply type: shell run: "ado decisions {{ inputs.story_id }} --post --if-any --apply --expect-plan .ado/plan-decisions.md || { [ $? -eq 2 ] && [ -e .ado/plan-decisions.md.new ]; }" - id: decisions-applied type: shell run: "if [ -e .ado/plan-decisions.md.new ]; then echo 'spec-kit-ado: the decisions plan changed after approval; start a new run' >&2; exit 1; fi" # Strict mode: runs the tests at every red and green commit and records the result in ledger section 4 (a local write); exit 2 stops # the run before any Task state is synced. Advisory mode: a no-op (exit 0, "mode is advisory"). # `timeout: 7200`: the engine's shell default is 300 s, which would kill the test runs (one per red and green commit and HEAD) mid-way # and skip the cleanup of the throwaway clone. Each run still has its own strict.test_timeout. - id: strict-verify type: shell timeout: 7200 run: "ado strict verify {{ inputs.story_id }}" - id: sync-loop type: do-while max_iterations: 1 condition: "{{ steps.sync-apply.output.stderr | contains('plan changed since approval') }}" steps: - id: sync-preview type: shell run: "ado push {{ inputs.story_id }} --plan-out .ado/plan-sync.md" - id: approve-sync type: gate verdict_input: verdict_approve_sync message: "Approve syncing the Task states ticked during implement to Azure Boards. The plan file is shown below (the gate shows at most 200 lines). If the preview starts with ⚠, open the file and read it in full before approving." show_file: .ado/plan-sync.md options: [approve, reject] on_reject: abort - id: sync-apply type: shell run: "ado push {{ inputs.story_id }} --apply --expect-plan .ado/plan-sync.md || { [ $? -eq 2 ] && [ -e .ado/plan-sync.md.new ]; }" - id: sync-applied type: shell run: "if [ -e .ado/plan-sync.md.new ]; then echo 'spec-kit-ado: the sync plan changed after approval; start a new run' >&2; exit 1; fi" # The gate command runs `ado gate` and appends the result to ledger section 4 (a shell step could not). - id: gate command: speckit.ado.gate integration: "{{ inputs.integration }}" input: args: "{{ inputs.story_id }} --workflow" # Exit 1 (gate.block failed) and exit 3 (invalid ado.config.json) halt the run; missing info exits 0, other errors (2, e.g. no config) do not halt. - id: gate-check type: shell # bash, not the engine's sh (arrays are bash-only); a read loop, not mapfile, so macOS bash 3.2 works. # File names go through a NUL-delimited file, never into the script text. A failed diff runs the # gate without --changed (missing info never blocks). run: | bash <<'EOF' base=$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null || echo origin/main) args=() tmp=$(mktemp) && git diff -z --name-only "$base...HEAD" > "$tmp" 2>/dev/null && ok=1 || ok= if [ -n "$ok" ]; then while IFS= read -r -d '' f; do args+=("./$f"); done < "$tmp" # ./ prefix: a name like -x must not parse as an option [ "${#args[@]}" -eq 0 ] || args=(--changed "${args[@]}") else echo "spec-kit-ado: changed files unavailable - assertion check skipped" >&2 fi rm -f "$tmp" code=0 ado gate {{ inputs.story_id }} --src . --base "$base" "${args[@]}" > /dev/null < /dev/null || code=$? [ "$code" -ne 1 ] && [ "$code" -ne 3 ] EOF # R3 B5: the review reads .ado/context/.md; refresh it so a PO comment posted after pull is not missed. # Read-only, stdout dropped (the file is the product); a failure only warns, the review then says it was not refreshed. - id: refresh-context type: shell run: "ado comments {{ inputs.story_id }} > /dev/null || echo 'spec-kit-ado: could not refresh the story discussion; the review will use the file on disk' >&2" - id: review command: speckit.ado.review integration: "{{ inputs.integration }}" model: "{{ inputs.review_model }}" input: args: "{{ inputs.story_id }} --workflow" - id: review-review type: gate verdict_input: verdict_review_review message: "Review the findings logged in the ledger before opening the PR. Reject if implement reported INCOMPLETE tasks: the run aborts and cannot be resumed; finish by hand as the README's recovery section says." options: [approve, reject] on_reject: abort - id: check-review-review type: shell run: "ado approvals check {{ inputs.story_id }} --gate review-review" # Clears files an earlier run left: a refused pr-prepare writes nothing, so pr-preview would send them. - id: pr-clear type: shell run: "rm -f .ado/pr-args.json .ado/pr-body.md" - id: pr-prepare command: speckit.ado.pr integration: "{{ inputs.integration }}" input: args: "{{ inputs.story_id }} --prepare-only" - id: pr-loop type: do-while max_iterations: 1 condition: "{{ steps.pr-apply.output.stderr | contains('plan changed since approval') }}" steps: # The CLI, not the agent, writes the preview the gate shows, with pr-apply's own flags # (--push too, so both skip the remote-diverged review check). - id: pr-preview type: shell run: "ado pr create {{ inputs.story_id }} --from-prepared --push --plan-out .ado/plan-pr.md" - id: approve-pr type: gate verdict_input: verdict_approve_pr message: "Approve pushing the head branch and opening this pull request. The plan file is shown below (the gate shows at most 200 lines). If the preview starts with ⚠, open the file and read it in full before approving." show_file: .ado/plan-pr.md options: [approve, reject] on_reject: abort - id: pr-apply type: shell run: "ado pr create {{ inputs.story_id }} --from-prepared --push --apply --expect-plan .ado/plan-pr.md || { [ $? -eq 2 ] && [ -e .ado/plan-pr.md.new ]; }" - id: pr-applied type: shell run: "if [ -e .ado/plan-pr.md.new ]; then echo 'spec-kit-ado: the PR plan changed after approval; start a new run' >&2; exit 1; fi" # The product owner answers the posted decisions in the story's comment thread; a human records each verdict in their own terminal. # The run does not wait by itself: this gate is where you wait. It ends the run; `ado done` happens after merge. - id: wait-po-validation type: gate verdict_input: verdict_wait_po_validation message: "Approve once the product owner has validated or rejected the posted decisions. Terminal mode: record each verdict first with `ado decisions --resolve` in your own terminal. Comment mode (approvers configured; `--resolve` is refused): the approvers' `/approve D` and `/reject D` comments are recorded by `ado decisions --sync` in the next step. Either way, commit and push the recorded lines to the PR branch before the merge. In strict mode `ado done` refuses while any is open; if nothing was posted just approve." options: [approve, reject] on_reject: abort - id: sync-po-validation type: shell run: "ado decisions {{ inputs.story_id }} --sync --if-comment-mode" - id: check-wait-po-validation type: shell run: "ado approvals check {{ inputs.story_id }} --gate wait-po-validation"