--- name: implement description: Build and validate loop (BUILDER + validation) - implements the architecture, runs tests, iterates until passing. Writes code following the plan. argument-hint: [task-identifier] --- Implement the architecture from the plan phase. Build code, run tests, iterate until all validations pass. Combines BUILDER (write code) and validation (run tests) in a tight loop. phase_model: frontmatter: [research, plan, implement, rework, complete] rework: enabled db_role: [RESEARCH, ARCHITECT, BUILDER, BUILDER_VALIDATOR, REVIEWER, DOCUMENTER] legacy_db_role: [VALIDATOR] source_of_truth: gating: frontmatter.phase telemetry: db_role ./.apex/tasks/[ID].md plan implementation - **Follow the Plan**: The architecture was approved - implement it, don't redesign - **Pattern Discipline**: Only use patterns from the plan's pattern selection - **Fail Fast**: Run tests frequently, fix issues immediately - **No Guessing**: If spec is unclear, return to plan or ask user I'll implement the planned architecture. Please provide the task identifier. You can find active tasks in `./.apex/tasks/` or run with: `/apex:implement [identifier]` Load task file and begin implementation. 1. Read `./.apex/tasks/[identifier].md` 2. Verify frontmatter `phase: plan` OR `phase: rework` 3. Parse `` first and treat it as authoritative scope/ACs 4. Parse `` section, especially `` 5. If phase == rework, treat this as a Ship REJECT rework loop 6. If phase not in [plan, rework], refuse with: "Task is in [phase] phase. Expected: plan or rework" Contract rules: - Implementation MUST satisfy all AC-* or explicitly document unmet criteria - If scope/ACs must change, append a entry inside task-contract and bump its version - `` - What we're building - `` - The chosen approach - `` - Patterns to apply with locations - `` - Sequence of steps - `` - Checks after each step - `` - Critical risks to avoid - `` - Existing files to change - `` - New files to add - `` - AC-* to track and validate Create TodoWrite items for each implementation step from the plan. - [ ] All files to modify exist and are readable - [ ] No syntax errors in current codebase (`npm run lint` or equivalent) - [ ] Tests currently passing (baseline) - [ ] Dependencies available Document blockers and ask user how to proceed. 1. **Read target files** fully before modifying 2. **Apply patterns** from plan's pattern-guidance 3. **Write code** following architecture decision 4. **Document pattern usage**: `# [PAT:ID] ★★★★☆ (X uses, Y% success)` 5. **Run syntax check** immediately after writing ONLY use patterns listed in ``. DO NOT invent new pattern names. If you need a pattern not in the plan, document it as a gap. Review `` before each step. Apply mitigations proactively. 1. Run validation gate from plan 2. If passes, continue to next step 3. If fails, fix and retry (max 3 attempts per step) 4. After 3 failures, document issue and ask user - Syntax: `npm run lint` / `ruff check` / language-appropriate - Types: `tsc --noEmit` / `mypy` / language-appropriate - Unit tests: `npm test` / `pytest` / language-appropriate - Integration: As specified in plan Record a checkpoint in the task log after each step (summary + confidence). Before running full validation, verify all patterns you intend to claim. For each pattern in ``: 1. [ ] Pattern exists in `` 2. [ ] Trust score matches what's in the plan 3. [ ] Location (file:line) is accurate and verifiable 4. [ ] Outcome is honest (worked|tweaked|failed) Record pattern usage evidence BEFORE validation: - pattern_id - file and line range - outcome (worked|tweaked|failed) - notes on usage IF any pattern in `` is NOT in ``: → REMOVE it from patterns-used → Document as "unplanned pattern discovered" → Do NOT claim it in the final reflection Unplanned patterns can be documented as "new patterns" in the final reflection, but NOT as "patterns used" (which updates confidence). This is NOT optional. Run FULL test suite before completing. **Task ID**: [taskId] **Modified Files**: [list from implementation] **Predictions**: [from plan's risk section] Run: Syntax → Formatting → Type check → Unit tests → Integration tests → Coverage Return: Validation report comparing predictions vs reality IF any failures: → Return to builder-phase with issue list → Fix and re-run validation → Max 3 full cycles before escalating to user IF only warnings: → Document for review phase → Proceed IF all pass: → Proceed to write implementation section Append to `` section: ```xml [ISO] [Time spent] [Build-validate cycles] [Summary of what changed] [How it was used] [Key additions/removals] [Why created] [PAT:IDs] [Corresponding test if any] [Details] [Details] [Details] [Percentage if available] [Evidence or reason] [Notes on usage] [What happened] [How fixed, or why unresolved] [What plan said] [What we did instead] [Why deviation was necessary] [What was built] [Most important modifications] [What's tested] [Edge cases, TODOs] [Patterns to report in the final reflection] Run `/apex:ship [identifier]` to review and finalize. ``` Set `phase: implement` and `updated: [ISO timestamp]` YOU CANNOT FABRICATE PATTERNS. Only claim patterns that exist in ``. In ``, only list patterns from the plan. Pattern IDs claimed here will be validated during `/apex:ship`. VIOLATION: Claiming "PAT:NEW:THING" that was never in the plan CONSEQUENCE: The final reflection becomes unreliable and confidence becomes meaningless Before completing implementation: - Run linting - Check for common errors (double async, missing brackets) - Fix ALL syntax errors before proceeding - DO NOT transition to ship with syntax errors Before finishing: - Confirm all AC-* are met, or explicitly mark any unmet criteria with reasons - If contract scope/ACs changed, record an amendment with rationale and bump contract version If implementation reveals spec ambiguity: 1. Document the ambiguity 2. Ask user for clarification 3. If architectural change needed, note it for plan revision 4. Do NOT guess and implement wrong thing - All implementation steps from plan completed - All validation gates passed - Full test suite passing - No syntax errors - Acceptance criteria status reported for all AC-* - Patterns used are from plan only (Pattern Evidence Gate passed) - Deviations documented with reasons - Task file updated at ./.apex/tasks/[ID].md - Checkpoints recorded at start, per-step, and end - Pattern evidence recorded for usage - Task metadata updated for build/validate completion `/apex:ship [identifier]` - Review, document, and reflect