kiro-impl Skill
Role
You operate in two modes:
- Autonomous mode (no task numbers): Dispatch a fresh subagent per task, with independent review after each
- Manual mode (task numbers provided): Execute selected tasks directly in the main context
Core Mission
- Success Criteria:
- All tests written before implementation code
- Code passes all tests with no regressions
- Tasks marked as completed in tasks.md
- Implementation aligns with design and requirements
- Task completion follows the selected review mode
Review Mode
- Default review mode is
required
- Accept explicit forms:
--review required|inline|off
- Also accept clear natural-language opt-outs such as
skip review or without review as off
- If the request is ambiguous, keep
required
Execution Steps
Step 1: Gather Context
If steering/spec context is already available from conversation, skip redundant file reads.
Otherwise, load all necessary context:
{{KIRO_DIR}}/specs/{feature}/spec.json, requirements.md, design.md, tasks.md
- Core steering context:
product.md, tech.md, structure.md
- Additional steering files only when directly relevant to the selected task's boundary, runtime prerequisites, integrations, domain rules, security/performance constraints, or team conventions that affect implementation or validation
- Relevant local agent skills or playbooks only when they clearly match the task's host environment or use case; read the specific artifact(s) you need, not entire directories
Parallel Research
The following research areas are independent and can be executed in parallel:
- Spec context loading: spec.json, requirements.md, design.md, tasks.md
- Steering, playbooks, & patterns: Core steering, task-relevant extra steering, matching local agent skills/playbooks, and existing code patterns
After all parallel research completes, synthesize implementation brief before starting.
Preflight
Validate approvals:
- Verify tasks are approved in spec.json (stop if not, see Safety & Fallback)
Discover validation commands:
- Inspect repository-local sources of truth in this order: project scripts/manifests (
package.json, pyproject.toml, go.mod, Cargo.toml, app manifests), task runners (Makefile, justfile), CI/workflow files, existing e2e/integration configs, then README*
- Derive a canonical validation set for this repo:
TEST_COMMANDS, BUILD_COMMANDS, and SMOKE_COMMANDS
- Prefer commands already used by repo automation over ad hoc shell pipelines
- For
SMOKE_COMMANDS, choose the lightest trustworthy runtime-liveness check for the app shape (for example: root URL load, Electron launch, CLI --help, service health endpoint, mobile simulator/e2e harness if one already exists)
- Keep the full command set in the parent context, and pass only the task-relevant subset to implementer and reviewer subagents
Establish repo baseline:
- Run
git status --porcelain and note any pre-existing uncommitted changes
Step 2: Select Tasks & Determine Mode
Parse arguments:
- Extract feature name from first argument
- If task numbers provided (e.g., "1.1" or "1,2,3"): manual mode
- If no task numbers: autonomous mode (all pending tasks)
- Determine review mode from the invocation:
--review required or omitted → required
--review inline → inline
--review off, skip review, or without review → off
Build task queue:
- Read tasks.md, identify actionable sub-tasks (X.Y numbering like 1.1, 2.3)
- Major tasks (1., 2.) are grouping headers, not execution units
- Skip tasks with
_Blocked:_ annotation
- For each selected task, check
_Depends:_ annotations -- verify referenced tasks are [x]
- If prerequisites incomplete, execute them first or warn the user
- Use
_Boundary:_ annotations to understand the task's component scope
Step 3: Execute Implementation
Autonomous Mode (subagent dispatch)
Iteration discipline: Process exactly ONE sub-task (e.g., 1.1) per iteration. Do NOT batch multiple sub-tasks into a single subagent dispatch. Each iteration follows the full cycle: dispatch implementer → review → commit → re-read tasks.md → next.
Context management: At the start of each iteration, re-read tasks.md to determine the next actionable sub-task. Do NOT rely on accumulated memory of previous iterations. After completing each iteration, retain only a one-line summary (e.g., "1.1: READY_FOR_REVIEW, 3 files changed") and discard the full status report and reviewer details.
For each task (one at a time):
a) Dispatch implementer:
- Read
templates/implementer-prompt.md from this skill's directory
- Construct a prompt by combining the template with task-specific context:
- Task description and boundary scope
- Paths to spec files: requirements.md, design.md, tasks.md
- Exact requirement and design section numbers this task must satisfy (using source numbering, NOT invented
REQ-* aliases)
- Task-relevant steering context and parent-discovered validation commands (tests/build/smoke as relevant)
- Whether the task is behavioral (Feature Flag Protocol) or non-behavioral
- Previous learnings: Include any
## Implementation Notes entries from tasks.md that are relevant to this task's boundary or dependencies (e.g., "better-sqlite3 requires separate rebuild for Electron"). This prevents the same mistakes from recurring.
- The implementer subagent will read the spec files and build its own Task Brief (acceptance criteria, completion definition, design constraints, verification method) before implementation
- Dispatch via Agent tool as a fresh subagent
b) Handle implementer status:
- Parse implementer status only from the exact
## Status Report block and - STATUS: field.
- If
STATUS is missing, ambiguous, or replaced with prose, re-dispatch the implementer once requesting the exact structured status block only. Do NOT proceed to review without a parseable READY_FOR_REVIEW | BLOCKED | NEEDS_CONTEXT value.
- READY_FOR_REVIEW → proceed to review
- BLOCKED → dispatch debug subagent (see section below); do NOT immediately skip
- NEEDS_CONTEXT → re-dispatch once with the requested additional context; if still unresolved → dispatch debug subagent
c) Review the task:
- If review mode is
required:
- Read
templates/reviewer-prompt.md from this skill's directory
- Construct a review prompt with:
- The task description and relevant spec section numbers
- Paths to spec files (requirements.md, design.md) so the reviewer can read them directly
- The implementer's status report (for reference only — reviewer must verify independently)
- The reviewer must apply the
kiro-review protocol to this task-local review.
- Preserve the existing task-specific context: task text, spec refs,
_Boundary:_ scope, validation commands, implementer report, and the actual git diff as the primary source of truth.
- The reviewer subagent will run
git diff itself to read the actual code changes and verify against the spec
- Dispatch via Agent tool as a fresh subagent
- If review mode is
inline:
- Apply
kiro-review in the parent context using the same task evidence and the actual git diff
- If review mode is
off:
- Skip task-local review
- Record in the parent context that task-local review was skipped for this task
d) Handle reviewer verdict:
- If review mode is
off:
- Do not fabricate a reviewer verdict
- Before marking the task
[x] or making any success claim, apply kiro-verify-completion using fresh evidence from the current code state; then mark task [x] in tasks.md and perform selective git commit
- Otherwise:
- Parse reviewer verdict only from the exact
## Review Verdict block and - VERDICT: field.
- If
VERDICT is missing, ambiguous, or replaced with prose, re-dispatch the reviewer once requesting the exact structured verdict only. Do NOT mark the task complete, commit, or continue to the next task without a parseable APPROVED | REJECTED value.
- APPROVED → before marking the task
[x] or making any success claim, apply kiro-verify-completion using fresh evidence from the current code state; then mark task [x] in tasks.md and perform selective git commit
- REJECTED (round 1-2) → re-dispatch implementer with review feedback
- REJECTED (round 3) → dispatch debug subagent (see section below)
e) Commit (parent-only, selective staging):
- Stage only the files actually changed for this task, plus tasks.md
- NEVER use
git add -A or git add .
- Use
git add <file1> <file2> ... with explicit file paths
- Commit message format:
feat(<feature-name>): <task description>
f) Record learnings:
- If this task revealed cross-cutting insights, append a one-line note to the
## Implementation Notes section at the bottom of tasks.md
g) Debug subagent (triggered by BLOCKED, NEEDS_CONTEXT unresolved, or REJECTED after 2 remediation rounds):
The debug subagent runs in a fresh context — it receives only the error information, not the failed implementation history. This avoids the context pollution that causes infinite retry loops.
- Read
templates/debugger-prompt.md from this skill's directory
- Construct a debug prompt with:
- The error description / blocker reason / reviewer rejection findings
git diff of the current uncommitted changes
- The task description and relevant spec section numbers
- Paths to spec files so the debugger can read them
- The debugger must apply the
kiro-debug protocol to this failure investigation.
- Preserve rich failure context: error output, reviewer findings, current
git diff, task/spec refs, and any relevant Implementation Notes.
- When available, the debugger should inspect runtime/config state and use web or official documentation research to validate root-cause hypotheses before proposing a fix plan.
- Dispatch via Agent tool as a fresh subagent
Handle debug report:
- Parse
NEXT_ACTION from the debug report's exact structured field.
- If
NEXT_ACTION: STOP_FOR_HUMAN → append _Blocked: <ROOT_CAUSE>_ to tasks.md, stop the feature run, and report that human review is required before continuing
- If
NEXT_ACTION: BLOCK_TASK → append _Blocked: <ROOT_CAUSE>_ to tasks.md, skip to next task
- If
NEXT_ACTION: RETRY_TASK → preserve the current worktree; do NOT reset or discard unrelated changes. Spawn a new implementer subagent with the debug report's FIX_PLAN, NOTES, and the current git diff, and require it to repair the task with explicit edits only
- If the new implementer succeeds (READY_FOR_REVIEW → reviewer APPROVED) → normal flow
- If the new implementer also fails → repeat debug cycle (max 2 debug rounds total). After 2 failed debug rounds → append
_Blocked: debug attempted twice, still failing — <ROOT_CAUSE>_ to tasks.md, skip
- Max 2 debug rounds per task. Each round: fresh debug subagent → fresh implementer. If still failing after 2 rounds, the task is blocked.
- Record debug findings in
## Implementation Notes (this helps subsequent tasks avoid the same issue)
(P) markers: Tasks marked (P) in tasks.md indicate they have no inter-dependencies and could theoretically run in parallel. However, kiro-impl processes them sequentially (one at a time) to avoid git conflicts and simplify review. The (P) marker is informational for task planning, not an execution directive.
Completion check: If all remaining tasks are BLOCKED, stop and report blocked tasks with reasons to the user.
Manual Mode (main context)
For each selected task:
1. Build Task Brief:
Before writing any code, read the relevant sections of requirements.md and design.md for this task and clarify:
- What observable behaviors must be true when done (acceptance criteria)
- What files/functions/tests must exist (completion definition)
- What technical decisions to follow from design.md (design constraints)
- How to confirm the task works (verification method)
2. Execute TDD cycle (Kent Beck's RED → GREEN → REFACTOR):
- RED: Write test for the next small piece of functionality based on the acceptance criteria. Test should fail.
- GREEN: Implement simplest solution to make test pass, following the design constraints.
- REFACTOR: Improve code structure, remove duplication. All tests must still pass.
- VERIFY: All tests pass (new and existing), no regressions. Confirm verification method passes.
- REVIEW:
required: Apply kiro-review before marking the task complete. If the host supports fresh subagents in manual mode, use a fresh reviewer; otherwise perform the review in the main context using the kiro-review protocol. Do NOT continue until the verdict is parseably APPROVED.
inline: Apply kiro-review in the main context before marking the task complete.
off: Skip task-local review, but note that kiro-validate-impl becomes the primary quality gate before any feature-level completion claim.
- MARK COMPLETE:
required|inline: Only after review returns APPROVED, apply kiro-verify-completion, then update the checkbox from - [ ] to - [x] in tasks.md.
off: Apply kiro-verify-completion, then update the checkbox from - [ ] to - [x] in tasks.md.
Step 4: Final Validation
Autonomous mode:
- After all tasks complete, run
/kiro-validate-impl {feature} as a GO/NO-GO gate
- If validation returns GO → before reporting feature success, apply
kiro-verify-completion to the feature-level claim using the validation result and fresh supporting evidence
- If validation returns NO-GO:
- Fix only concrete findings from the validation report
- Cap remediation at 3 rounds; if still NO-GO, stop and report remaining findings
- If validation returns MANUAL_VERIFY_REQUIRED → stop and report the missing verification step
Manual mode:
- Suggest running
/kiro-validate-impl {feature} but do not auto-execute
- If review mode is
off, treat /kiro-validate-impl {feature} as mandatory before any feature-level success claim
Feature Flag Protocol
For tasks that add or change behavior, enforce RED → GREEN with a feature flag:
- Add flag (OFF by default): Introduce a toggle appropriate to the codebase (env var, config constant, boolean, conditional -- agent chooses the mechanism)
- RED -- flag OFF: Write tests for the new behavior. Run tests → must FAIL. If tests pass with flag OFF, the tests are not testing the right thing. Rewrite.
- GREEN -- flag ON + implement: Enable the flag, write implementation. Run tests → must PASS.
- Remove flag: Make the code unconditional. Run tests → must still PASS.
Skip this protocol for: refactoring, configuration, documentation, or tasks with no behavioral change.
Critical Constraints
- Strict Handoff Parsing: Never infer implementer
STATUS or reviewer VERDICT from surrounding prose; only the exact structured fields count
- No Destructive Reset: Never use
git checkout ., git reset --hard, or similar destructive rollback inside the implementation loop
- Selective Staging: NEVER use
git add -A or git add .; always stage explicit file paths
- Bounded Review Rounds: Max 2 implementer re-dispatch rounds per reviewer rejection, then debug
- Bounded Debug: Max 2 debug rounds per task (debug + re-implementation per round); if still failing → BLOCKED
- Bounded Remediation: Cap final-validation remediation at 3 rounds
Output Description
Autonomous mode: For each task, report:
- Task ID, implementer status, reviewer verdict
- Files changed, commit hash
- After all tasks: final validation result (GO/NO-GO)
Manual mode:
- Tasks executed: task numbers and test results
- Status: completed tasks marked in tasks.md, remaining tasks count
Format: Concise, in the language specified in spec.json.
Safety & Fallback
Error Scenarios
Tasks Not Approved or Missing Spec Files:
- Stop Execution: All spec files must exist and tasks must be approved
- Suggested Action: "Complete previous phases:
/kiro-spec-requirements, /kiro-spec-design, /kiro-spec-tasks"
Test Failures:
- Stop Implementation: Fix failing tests before continuing
- Action: Debug and fix, then re-run
All Tasks Blocked:
- Stop and report all blocked tasks with reasons
- Human review needed to resolve blockers
Spec Conflicts with Reality:
- If a requirement or design conflicts with reality (API doesn't exist, platform limitation), block the task with
_Blocked: <reason>_ -- do not silently work around it
Upstream Ownership Detected:
- If review, debug, or validation shows that the root cause belongs to an upstream, foundation, shared-platform, or dependency spec, do not patch around it inside the downstream feature
- Route the fix back to the owning upstream spec, keep the downstream task blocked until that contract is repaired, and re-run validation/smoke for dependent specs after the upstream fix lands
Task Plan Invalidated During Implementation:
- If debug returns
NEXT_ACTION: STOP_FOR_HUMAN because of task ordering, boundary, or decomposition problems, stop and return for human review of tasks.md or the approved plan instead of forcing a code workaround
1---2name: kiro-impl3description: Implement approved tasks using TDD with native subagent dispatch. Runs all pending tasks autonomously or selected tasks manually.4---56# kiro-impl Skill78## Role9You operate in two modes:10- **Autonomous mode** (no task numbers): Dispatch a fresh subagent per task, with independent review after each11- **Manual mode** (task numbers provided): Execute selected tasks directly in the main context1213## Core Mission14- **Success Criteria**:15 - All tests written before implementation code16 - Code passes all tests with no regressions17 - Tasks marked as completed in tasks.md18 - Implementation aligns with design and requirements19 - Task completion follows the selected review mode2021## Review Mode22- Default review mode is `required`23- Accept explicit forms: `--review required|inline|off`24- Also accept clear natural-language opt-outs such as `skip review` or `without review` as `off`25- If the request is ambiguous, keep `required`2627## Execution Steps2829### Step 1: Gather Context3031If steering/spec context is already available from conversation, skip redundant file reads.32Otherwise, load all necessary context:33- `{{KIRO_DIR}}/specs/{feature}/spec.json`, `requirements.md`, `design.md`, `tasks.md`34- Core steering context: `product.md`, `tech.md`, `structure.md`35- Additional steering files only when directly relevant to the selected task's boundary, runtime prerequisites, integrations, domain rules, security/performance constraints, or team conventions that affect implementation or validation36- Relevant local agent skills or playbooks only when they clearly match the task's host environment or use case; read the specific artifact(s) you need, not entire directories3738#### Parallel Research3940The following research areas are independent and can be executed in parallel:411. **Spec context loading**: spec.json, requirements.md, design.md, tasks.md422. **Steering, playbooks, & patterns**: Core steering, task-relevant extra steering, matching local agent skills/playbooks, and existing code patterns4344After all parallel research completes, synthesize implementation brief before starting.4546#### Preflight4748**Validate approvals**:49- Verify tasks are approved in spec.json (stop if not, see Safety & Fallback)5051**Discover validation commands**:52- Inspect repository-local sources of truth in this order: project scripts/manifests (`package.json`, `pyproject.toml`, `go.mod`, `Cargo.toml`, app manifests), task runners (`Makefile`, `justfile`), CI/workflow files, existing e2e/integration configs, then `README*`53- Derive a canonical validation set for this repo: `TEST_COMMANDS`, `BUILD_COMMANDS`, and `SMOKE_COMMANDS`54- Prefer commands already used by repo automation over ad hoc shell pipelines55- For `SMOKE_COMMANDS`, choose the lightest trustworthy runtime-liveness check for the app shape (for example: root URL load, Electron launch, CLI `--help`, service health endpoint, mobile simulator/e2e harness if one already exists)56- Keep the full command set in the parent context, and pass only the task-relevant subset to implementer and reviewer subagents5758**Establish repo baseline**:59- Run `git status --porcelain` and note any pre-existing uncommitted changes6061### Step 2: Select Tasks & Determine Mode6263**Parse arguments**:64- Extract feature name from first argument65- If task numbers provided (e.g., "1.1" or "1,2,3"): **manual mode**66- If no task numbers: **autonomous mode** (all pending tasks)67- Determine review mode from the invocation:68 - `--review required` or omitted → `required`69 - `--review inline` → `inline`70 - `--review off`, `skip review`, or `without review` → `off`7172**Build task queue**:73- Read tasks.md, identify actionable sub-tasks (X.Y numbering like 1.1, 2.3)74- Major tasks (1., 2.) are grouping headers, not execution units75- Skip tasks with `_Blocked:_` annotation76- For each selected task, check `_Depends:_` annotations -- verify referenced tasks are `[x]`77- If prerequisites incomplete, execute them first or warn the user78- Use `_Boundary:_` annotations to understand the task's component scope7980### Step 3: Execute Implementation8182#### Autonomous Mode (subagent dispatch)8384**Iteration discipline**: Process exactly ONE sub-task (e.g., 1.1) per iteration. Do NOT batch multiple sub-tasks into a single subagent dispatch. Each iteration follows the full cycle: dispatch implementer → review → commit → re-read tasks.md → next.8586**Context management**: At the start of each iteration, re-read `tasks.md` to determine the next actionable sub-task. Do NOT rely on accumulated memory of previous iterations. After completing each iteration, retain only a one-line summary (e.g., "1.1: READY_FOR_REVIEW, 3 files changed") and discard the full status report and reviewer details.8788For each task (one at a time):8990**a) Dispatch implementer**:91- Read `templates/implementer-prompt.md` from this skill's directory92- Construct a prompt by combining the template with task-specific context:93 - Task description and boundary scope94 - Paths to spec files: requirements.md, design.md, tasks.md95 - Exact requirement and design section numbers this task must satisfy (using source numbering, NOT invented `REQ-*` aliases)96 - Task-relevant steering context and parent-discovered validation commands (tests/build/smoke as relevant)97 - Whether the task is behavioral (Feature Flag Protocol) or non-behavioral98 - **Previous learnings**: Include any `## Implementation Notes` entries from tasks.md that are relevant to this task's boundary or dependencies (e.g., "better-sqlite3 requires separate rebuild for Electron"). This prevents the same mistakes from recurring.99- The implementer subagent will read the spec files and build its own Task Brief (acceptance criteria, completion definition, design constraints, verification method) before implementation100- Dispatch via **Agent tool** as a fresh subagent101102**b) Handle implementer status**:103- Parse implementer status only from the exact `## Status Report` block and `- STATUS:` field.104- If `STATUS` is missing, ambiguous, or replaced with prose, re-dispatch the implementer once requesting the exact structured status block only. Do NOT proceed to review without a parseable `READY_FOR_REVIEW | BLOCKED | NEEDS_CONTEXT` value.105- **READY_FOR_REVIEW** → proceed to review106- **BLOCKED** → dispatch debug subagent (see section below); do NOT immediately skip107- **NEEDS_CONTEXT** → re-dispatch once with the requested additional context; if still unresolved → dispatch debug subagent108109**c) Review the task**:110- If review mode is `required`:111 - Read `templates/reviewer-prompt.md` from this skill's directory112 - Construct a review prompt with:113 - The task description and relevant spec section numbers114 - Paths to spec files (requirements.md, design.md) so the reviewer can read them directly115 - The implementer's status report (for reference only — reviewer must verify independently)116 - The reviewer must apply the `kiro-review` protocol to this task-local review.117 - Preserve the existing task-specific context: task text, spec refs, `_Boundary:_` scope, validation commands, implementer report, and the actual `git diff` as the primary source of truth.118 - The reviewer subagent will run `git diff` itself to read the actual code changes and verify against the spec119 - Dispatch via **Agent tool** as a fresh subagent120- If review mode is `inline`:121 - Apply `kiro-review` in the parent context using the same task evidence and the actual `git diff`122- If review mode is `off`:123 - Skip task-local review124 - Record in the parent context that task-local review was skipped for this task125126**d) Handle reviewer verdict**:127- If review mode is `off`:128 - Do not fabricate a reviewer verdict129 - Before marking the task `[x]` or making any success claim, apply `kiro-verify-completion` using fresh evidence from the current code state; then mark task `[x]` in tasks.md and perform selective git commit130- Otherwise:131 - Parse reviewer verdict only from the exact `## Review Verdict` block and `- VERDICT:` field.132 - If `VERDICT` is missing, ambiguous, or replaced with prose, re-dispatch the reviewer once requesting the exact structured verdict only. Do NOT mark the task complete, commit, or continue to the next task without a parseable `APPROVED | REJECTED` value.133 - **APPROVED** → before marking the task `[x]` or making any success claim, apply `kiro-verify-completion` using fresh evidence from the current code state; then mark task `[x]` in tasks.md and perform selective git commit134 - **REJECTED (round 1-2)** → re-dispatch implementer with review feedback135 - **REJECTED (round 3)** → dispatch debug subagent (see section below)136137**e) Commit** (parent-only, selective staging):138- Stage only the files actually changed for this task, plus tasks.md139- **NEVER** use `git add -A` or `git add .`140- Use `git add <file1> <file2> ...` with explicit file paths141- Commit message format: `feat(<feature-name>): <task description>`142143**f) Record learnings**:144- If this task revealed cross-cutting insights, append a one-line note to the `## Implementation Notes` section at the bottom of tasks.md145146**g) Debug subagent** (triggered by BLOCKED, NEEDS_CONTEXT unresolved, or REJECTED after 2 remediation rounds):147148The debug subagent runs in a **fresh context** — it receives only the error information, not the failed implementation history. This avoids the context pollution that causes infinite retry loops.149150- Read `templates/debugger-prompt.md` from this skill's directory151- Construct a debug prompt with:152 - The error description / blocker reason / reviewer rejection findings153 - `git diff` of the current uncommitted changes154 - The task description and relevant spec section numbers155 - Paths to spec files so the debugger can read them156- The debugger must apply the `kiro-debug` protocol to this failure investigation.157- Preserve rich failure context: error output, reviewer findings, current `git diff`, task/spec refs, and any relevant Implementation Notes.158- When available, the debugger should inspect runtime/config state and use web or official documentation research to validate root-cause hypotheses before proposing a fix plan.159- Dispatch via **Agent tool** as a fresh subagent160161**Handle debug report**:162- Parse `NEXT_ACTION` from the debug report's exact structured field.163- If `NEXT_ACTION: STOP_FOR_HUMAN` → append `_Blocked: <ROOT_CAUSE>_` to tasks.md, stop the feature run, and report that human review is required before continuing164- If `NEXT_ACTION: BLOCK_TASK` → append `_Blocked: <ROOT_CAUSE>_` to tasks.md, skip to next task165- If `NEXT_ACTION: RETRY_TASK` → preserve the current worktree; do NOT reset or discard unrelated changes. Spawn a **new** implementer subagent with the debug report's `FIX_PLAN`, `NOTES`, and the current `git diff`, and require it to repair the task with explicit edits only166 - If the new implementer succeeds (READY_FOR_REVIEW → reviewer APPROVED) → normal flow167 - If the new implementer also fails → repeat debug cycle (max 2 debug rounds total). After 2 failed debug rounds → append `_Blocked: debug attempted twice, still failing — <ROOT_CAUSE>_` to tasks.md, skip168- **Max 2 debug rounds per task**. Each round: fresh debug subagent → fresh implementer. If still failing after 2 rounds, the task is blocked.169- Record debug findings in `## Implementation Notes` (this helps subsequent tasks avoid the same issue)170171**`(P)` markers**: Tasks marked `(P)` in tasks.md indicate they have no inter-dependencies and could theoretically run in parallel. However, kiro-impl processes them sequentially (one at a time) to avoid git conflicts and simplify review. The `(P)` marker is informational for task planning, not an execution directive.172173**Completion check**: If all remaining tasks are BLOCKED, stop and report blocked tasks with reasons to the user.174175#### Manual Mode (main context)176177For each selected task:178179**1. Build Task Brief**:180Before writing any code, read the relevant sections of requirements.md and design.md for this task and clarify:181- What observable behaviors must be true when done (acceptance criteria)182- What files/functions/tests must exist (completion definition)183- What technical decisions to follow from design.md (design constraints)184- How to confirm the task works (verification method)185186**2. Execute TDD cycle** (Kent Beck's RED → GREEN → REFACTOR):187- **RED**: Write test for the next small piece of functionality based on the acceptance criteria. Test should fail.188- **GREEN**: Implement simplest solution to make test pass, following the design constraints.189- **REFACTOR**: Improve code structure, remove duplication. All tests must still pass.190- **VERIFY**: All tests pass (new and existing), no regressions. Confirm verification method passes.191- **REVIEW**:192 - `required`: Apply `kiro-review` before marking the task complete. If the host supports fresh subagents in manual mode, use a fresh reviewer; otherwise perform the review in the main context using the `kiro-review` protocol. Do NOT continue until the verdict is parseably `APPROVED`.193 - `inline`: Apply `kiro-review` in the main context before marking the task complete.194 - `off`: Skip task-local review, but note that `kiro-validate-impl` becomes the primary quality gate before any feature-level completion claim.195- **MARK COMPLETE**:196 - `required|inline`: Only after review returns `APPROVED`, apply `kiro-verify-completion`, then update the checkbox from `- [ ]` to `- [x]` in tasks.md.197 - `off`: Apply `kiro-verify-completion`, then update the checkbox from `- [ ]` to `- [x]` in tasks.md.198199### Step 4: Final Validation200201**Autonomous mode**:202- After all tasks complete, run `/kiro-validate-impl {feature}` as a GO/NO-GO gate203- If validation returns GO → before reporting feature success, apply `kiro-verify-completion` to the feature-level claim using the validation result and fresh supporting evidence204- If validation returns NO-GO:205 - Fix only concrete findings from the validation report206 - Cap remediation at 3 rounds; if still NO-GO, stop and report remaining findings207- If validation returns MANUAL_VERIFY_REQUIRED → stop and report the missing verification step208209**Manual mode**:210- Suggest running `/kiro-validate-impl {feature}` but do not auto-execute211- If review mode is `off`, treat `/kiro-validate-impl {feature}` as mandatory before any feature-level success claim212213## Feature Flag Protocol214215For tasks that add or change behavior, enforce RED → GREEN with a feature flag:2162171. **Add flag** (OFF by default): Introduce a toggle appropriate to the codebase (env var, config constant, boolean, conditional -- agent chooses the mechanism)2182. **RED -- flag OFF**: Write tests for the new behavior. Run tests → must FAIL. If tests pass with flag OFF, the tests are not testing the right thing. Rewrite.2193. **GREEN -- flag ON + implement**: Enable the flag, write implementation. Run tests → must PASS.2204. **Remove flag**: Make the code unconditional. Run tests → must still PASS.221222**Skip this protocol for**: refactoring, configuration, documentation, or tasks with no behavioral change.223224## Critical Constraints225- **Strict Handoff Parsing**: Never infer implementer `STATUS` or reviewer `VERDICT` from surrounding prose; only the exact structured fields count226- **No Destructive Reset**: Never use `git checkout .`, `git reset --hard`, or similar destructive rollback inside the implementation loop227- **Selective Staging**: NEVER use `git add -A` or `git add .`; always stage explicit file paths228- **Bounded Review Rounds**: Max 2 implementer re-dispatch rounds per reviewer rejection, then debug229- **Bounded Debug**: Max 2 debug rounds per task (debug + re-implementation per round); if still failing → BLOCKED230- **Bounded Remediation**: Cap final-validation remediation at 3 rounds231232## Output Description233234**Autonomous mode**: For each task, report:2351. Task ID, implementer status, reviewer verdict2362. Files changed, commit hash2373. After all tasks: final validation result (GO/NO-GO)238239**Manual mode**:2401. Tasks executed: task numbers and test results2412. Status: completed tasks marked in tasks.md, remaining tasks count242243**Format**: Concise, in the language specified in spec.json.244245## Safety & Fallback246247### Error Scenarios248249**Tasks Not Approved or Missing Spec Files**:250- **Stop Execution**: All spec files must exist and tasks must be approved251- **Suggested Action**: "Complete previous phases: `/kiro-spec-requirements`, `/kiro-spec-design`, `/kiro-spec-tasks`"252253**Test Failures**:254- **Stop Implementation**: Fix failing tests before continuing255- **Action**: Debug and fix, then re-run256257**All Tasks Blocked**:258- Stop and report all blocked tasks with reasons259- Human review needed to resolve blockers260261**Spec Conflicts with Reality**:262- If a requirement or design conflicts with reality (API doesn't exist, platform limitation), block the task with `_Blocked: <reason>_` -- do not silently work around it263264**Upstream Ownership Detected**:265- If review, debug, or validation shows that the root cause belongs to an upstream, foundation, shared-platform, or dependency spec, do not patch around it inside the downstream feature266- Route the fix back to the owning upstream spec, keep the downstream task blocked until that contract is repaired, and re-run validation/smoke for dependent specs after the upstream fix lands267268**Task Plan Invalidated During Implementation**:269- If debug returns `NEXT_ACTION: STOP_FOR_HUMAN` because of task ordering, boundary, or decomposition problems, stop and return for human review of `tasks.md` or the approved plan instead of forcing a code workaround