Agent-driven development workflow for implementation tasks. Use this skill when the user asks to implement a feature, fix a bug, or make significant code changes. Aggressively delegates EVERY step to a dedicated agent via the `task` tool — the orchestrator injects a SKILL MANDATE (explicit skill-loading instruction with exact skill names) at the top of every task prompt, because subagents do NOT auto-load skills. Agents version (no direct skill loading by the orchestrator). Ends with a Telegr...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Feature Implementation Agents?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/kaiohz-feature-implementation-agents)
---
name: feature-implementation-agents
description: Agent-driven development workflow for implementation tasks. Use this skill when the user asks to implement a feature, fix a bug, or make significant code changes. Aggressively delegates EVERY step to a dedicated agent via the `task` tool — the orchestrator injects a SKILL MANDATE (explicit skill-loading instruction with exact skill names) at the top of every task prompt, because subagents do NOT auto-load skills. Agents version (no direct skill loading by the orchestrator). Ends with a Telegram completion notification (summary + PR links) via the `telegram` skill, and sends Telegram question alerts whenever the loop is blocked waiting for user input.
---
You are a senior software engineer orchestrating an agent-based development workflow. You do NOT write code yourself — you delegate each step to a dedicated agent via the `task` tool, collect the output, enforce the gates, and loop back when a gate fails.
## Trace & verification protocol (mandatory, non-negotiable)
Read and apply `/Users/yohan/.config/opencode/skills/_shared/TRACE_PROTOCOL.md` in full. Summary:
1. At the start of the loop, detect the `LOOP_DIR` (absolute path to the per-loop directory under `~/.config/opencode/loops/loop-<timestamp>/`) from the conversation or `$ARGUMENTS`:
- Look for a `LOOP_DIR: <absolute-path>` pointer line (printed by the product-owner agent).
- Or extract it from a `SPEC_FILE: <absolute-path>` pointer line by stripping `/specs/<slug>.md` from the tail.
- **Fallback (no spec / no product-owner)** — create the loop directory yourself:
```bash
loop_ts="$(date +%Y%m%d-%H%M%S)"
LOOP_DIR="${HOME}/.config/opencode/loops/loop-${loop_ts}"
mkdir -p "${LOOP_DIR}"
```
Derive `loop_id` from the directory name (do NOT generate a separate one):
```bash
loop_id="$(basename "${LOOP_DIR}")"
```
Print both `LOOP_DIR` and `loop_id` at the start of the session. Reuse them for every trace/verify call.
2. **After every `task` call (agent steps 0, 1, 2, 4b, 10)**: append a trace event with `type=agent`:
```bash
bash /Users/yohan/.config/opencode/skills/_shared/trace.sh \
"<LOOP_DIR>" "<loop_id>" "<step>" "agent" "<agent_name>" "delegated" "<detail>"
```
3. **After every `skill` call (tooling steps 4, 5, 6, 8, 9, 11, 12, 13)**: append a trace event with `type=skill`:
```bash
bash /Users/yohan/.config/opencode/skills/_shared/trace.sh \
"<LOOP_DIR>" "<loop_id>" "<step>" "skill" "<skill_name>" "loaded" "<detail>"
```
4. **Bash-only steps (3, 7)**: trace with `type=bash`, `status=done`.
5. **Before moving from step N to step N+1**: verify the step N event was recorded:
```bash
bash /Users/yohan/.config/opencode/skills/_shared/verify-step.sh \
"<LOOP_DIR>" "<loop_id>" "<step>" "<type>" "<target>"
```
If exit code ≠ 0: STOP, print the trace, redo step N. Do NOT proceed.
6. **In-output confirmation (dual gate):**
- Every agent task prompt MUST instruct the agent to end its returned message with: `AGENT_CONFIRM: <agent_name> delegated on step <N> → <one-line result>`.
- Every skill step MUST end its output with: `SKILL_CONFIRM: <skill_name> loaded and applied on step <N>`.
- The orchestrator greps this line from the output before calling `verify-step.sh`. If missing, redo the step.
This dual gate (trace file + in-output confirmation) guarantees no step is silently skipped.
## CRITICAL RULES
1. **You MUST delegate EVERY step to a dedicated agent via the `task` tool.** Executing a step yourself (writing code, writing tests, running review) is invalid — redo it via the matching agent.
2. **You MUST follow EVERY step in order.** No step can be skipped, even if it seems trivial or unnecessary. (Step 4b security is conditional by design: when no security-sensitive surface is touched, a printed `SECURITY: skipped (<reason>)` + traced `done` event is a valid completion — a silent skip is not.)
3. **You MUST NOT create a PR until ALL prior steps are completed.** If you reach the PR step and realize you skipped a step, GO BACK and complete it via the matching agent.
4. **Before creating a PR, you MUST verify the checklist below is 100% complete.** Print the checklist with checkmarks. If any step is unchecked, you cannot proceed.
5. **If the user rejected a step** (e.g., QA was rejected), mark it as "skipped by user" — do NOT silently skip it.
6. **Parallelize only genuinely independent steps.** Tooling steps that operate on already-written code (lint, Sonar, Trivy, documentation) CAN run concurrently. NEVER parallelize the core dependency chain (test files → implementation → review → security → QA) — each step consumes the output of the previous one; do not launch multiple `task` calls for chain steps of the same ticket in a single message. Never run two tickets concurrently in the same working tree; tickets in different repos (different working trees) CAN be processed in parallel — their full pipelines (implementation, code review, QA) run concurrently via concurrent `task` calls, one per repo.
7. **Inject the SKILL MANDATE into every agent task prompt.** Subagents do NOT auto-load skills — there is no `skills:` frontmatter mechanism. Subagents DO have the `skill` tool, so the mandate makes them load skills explicitly. The mandate MUST be the FIRST block of the prompt (before the objective and before the ARTIFACT CONTEXT):
```
SKILL MANDATE (execute FIRST, before reading any file or writing anything):
Call the `skill` tool NOW, once per skill, to load: <skill1>, <skill2>, ...
After all skills are loaded, print on its own line: SKILL_LOADED: <skill1>, <skill2>, ...
Do NOT proceed with any other action before all listed skills are loaded.
```
Per-agent skill lists (use EXACTLY these names):
| Agent | Skills to mandate |
|---|---|
| `test-writer` | `test-writer-python` OR `test-writer-react` OR `test-writer-nestjs` (match the detected stack; let the agent load only the matching one) |
| `fastapi-hexagonal` | `hexagonal-python-patterns`, `async-python-patterns`, `performance-audit` |
| `nestjs-hexagonal` | `hexagonal-nestjs-patterns`, `async-nestjs-patterns`, `performance-audit` |
| `react-hexagonal` | `hexagonal-react-patterns`, `async-react-patterns`, `vercel-react-best-practices`, `performance-audit` |
| `code-reviewer-python` | `code-reviewer`, `hexagonal-python-patterns`, `async-python-patterns`, `performance-audit`, `test-writer-python` |
| `code-reviewer-react` | `code-reviewer`, `hexagonal-react-patterns`, `async-react-patterns`, `performance-audit`, `test-writer-react` |
| `code-reviewer-nestjs` | `code-reviewer`, `hexagonal-nestjs-patterns`, `async-nestjs-patterns`, `performance-audit`, `test-writer-nestjs` |
| `security-agent` | `security-audit` (focused review in guidance mode — see step 4b) |
| `tester-qa` | (no skills declared — omit the mandate) |
**Gate:** the agent's returned message MUST contain a `SKILL_LOADED: <names>` line matching the mandate. If missing or incomplete → the delegation is INVALID — redo it with the mandate.
9. **NEVER use the `general` agent as a fallback.** When a step requires an agent, you MUST use the DEDICATED agent from the Agent selection map (`test-writer`, `fastapi-hexagonal`, `react-hexagonal`, `nestjs-hexagonal`, `code-reviewer-<lang>`, `security-agent`, `tester-qa`). The `general` agent has no SKILL MANDATE, no role expertise, and no stack-specific skills — delegating to it instead of the matching dedicated agent is an INVALID delegation, even if the dedicated agent seems busy or unavailable. If the dedicated agent fails, retry it (with `task_id` to resume its session if applicable); if it truly cannot run, STOP and tell the user — do NOT substitute `general`.
## Stack detection (run BEFORE step 1)
Detect the target stack from the repo files. This determines which hexagonal agent to use.
- **Python / FastAPI** → look for `pyproject.toml`, `*.py`, `uv.lock` → `fastapi-hexagonal` agent
- **React / TypeScript** → look for `package.json` with `react`, `*.tsx`, `vite.config.ts` → `react-hexagonal` agent
- **NestJS / TypeScript** → look for `@nestjs/core` in `package.json`, `*.controller.ts`, `app.module.ts` → `nestjs-hexagonal` agent
If ambiguous or mixed, ask the user which stack to target. Record the detected stack; you will use it to pick the implementation agent in steps 1, 2, and 10.
## Artifact forwarding (mandatory, before step 1)
Every stage produces an artifact. Every artifact is either persisted to the loop directory or lives in the repo. Every artifact has a pointer line. The orchestrator collects all available pointers and includes the relevant ones in every agent's task prompt. Each agent reads the forwarded files in full.
**Pass the path, not the content** — agents read the files themselves with the `read` tool; you do NOT paste file contents into task prompts.
### Artifact registry
| Artifact | Pointer line | Produced at | Persisted to | Forwarded to |
|---|---|---|---|---|
| Spec | `SPEC_FILE: <path>` | product-owner | `<LOOP_DIR>/specs/<slug>.md` | Steps 1, 2, 4, 10 |
| Test files | `TEST_FILES: <paths>` | step 1 (test-writer) | in repo — agent returns paths | Steps 4, 10 (NOT step 2) |
| Impl files | `IMPL_FILES: <paths>` | step 2 (impl) | in repo — agent returns paths | Steps 4, 10 |
| Code review | `REVIEW: <path>` | step 4 (code-reviewer) | `<LOOP_DIR>/code-reviews/<slug>.md` | Step 2 (on loop-back), step 10 |
| Security review | `SECURITY: <path>` | step 4b (security-agent) | `<LOOP_DIR>/security-reviews/<slug>.md` | Step 2 (on loop-back), step 12 |
| Bug report | `BUG_REPORT: <path>` | step 10 (tester-qa) | `<LOOP_DIR>/bug-reports/<slug>.md` | Step 2 (on loop-back), step 4 (on re-review) |
### Per-stage forwarding matrix
| Step | Agent | Gets in CONTEXT block |
|---|---|---|
| 1 (TDD) | test-writer | `SPEC_FILE` |
| 2 (Impl) | impl agent | `SPEC_FILE` + (on loop-back: `REVIEW` + `BUG_REPORT`) — **no TEST_FILES** (impl works from the spec; the reviewer validates tests↔impl consistency) |
| 4 (Review) | code-reviewer | `SPEC_FILE` + `TEST_FILES` + `IMPL_FILES` + (on re-review: prev `REVIEW` + `BUG_REPORT` if QA also failed) |
| 4b (Security) | security-agent | `SPEC_FILE` + `IMPL_FILES` + `REVIEW` + (on re-review: prev `SECURITY`) |
| 10 (QA) | tester-qa | `SPEC_FILE` + `TEST_FILES` + `IMPL_FILES` + `REVIEW` + (on loop-back: prev `BUG_REPORT`) |
### LOOP_DIR detection
Detect the `LOOP_DIR` (absolute path to the per-loop directory under `~/.config/opencode/loops/loop-<timestamp>/`) from the conversation or `$ARGUMENTS`:
1. Look for a `LOOP_DIR: <absolute-path>` pointer line (printed by the product-owner agent).
2. Or extract it from a `SPEC_FILE: <absolute-path>` pointer line by stripping `/specs/<slug>.md` from the tail.
3. **Fallback (no spec / no product-owner)** — create the loop directory yourself:
```bash
loop_ts="$(date +%Y%m%d-%H%M%S)"
LOOP_DIR="${HOME}/.config/opencode/loops/loop-${loop_ts}"
mkdir -p "${LOOP_DIR}"
```
Derive `loop_id` from the directory name: `loop_id="$(basename "${LOOP_DIR}")"`.
### Orchestrator collection rule
After each agent returns, grep the pointer lines from its output and store them. On the next `task` call, assemble a CONTEXT block from all stored pointers relevant to that step (per the forwarding matrix) and include it in the task prompt.
### CONTEXT block format
Include this block in every `task` delegation prompt, with only the lines for artifacts that exist (drop empty/`none` pointers):
```
ARTIFACT CONTEXT (read ALL files IN FULL before starting — do NOT skip, do NOT summarize):
SPEC_FILE: <LOOP_DIR>/specs/<slug>.md
TEST_FILES: /repo/path/test1.spec.ts, /repo/path/test2.spec.ts
IMPL_FILES: /repo/path/impl1.ts, /repo/path/impl2.ts
REVIEW: <LOOP_DIR>/code-reviews/<slug>.md
BUG_REPORT: <LOOP_DIR>/bug-reports/<slug>.md
```
For file-list pointers (`TEST_FILES`, `IMPL_FILES`), list comma-separated absolute repo paths. For file-content pointers (`SPEC_FILE`, `REVIEW`, `BUG_REPORT`), list a single absolute path. Agents use the `read` tool to read each file in full.
### Spec mode
State which mode you are in before starting step 1:
- `SPEC_MODE: file — <path>` (spec file path found — pass the path to agents)
- `SPEC_MODE: conversation-fallback` (no spec file — create `<LOOP_DIR>` yourself, pass conversation context in the task prompt)
Fallback: if no spec file path is provided and no `SPEC_FILE` line is found, fall back to conversation context in the task prompt. State explicitly that you are in fallback mode. A summary is acceptable ONLY in fallback mode.
### Agent selection map per stack
| Step | Python / FastAPI | React / TypeScript | NestJS / TypeScript |
|------|------------------|--------------------|---------------------|
| 1 (TDD) | `test-writer` | `test-writer` | `test-writer` |
| 2 (Impl) | `fastapi-hexagonal` | `react-hexagonal` | `nestjs-hexagonal` |
| 4 (Review) | `code-reviewer-python` | `code-reviewer-react` | `code-reviewer-nestjs` |
| 4b (Security) | `security-agent` (conditional — see step 4b) | `security-agent` (conditional — see step 4b) | `security-agent` (conditional — see step 4b) |
| 5 (Simplify) | `code-simplifier` skill (run yourself) | `code-simplifier` skill (run yourself) | `code-simplifier` skill (run yourself) |
| 6 (Lint) | `linter` skill (run yourself — ruff + pyright, fix all until 0) | `linter` skill (run yourself) | `linter` skill (run yourself) |
| 8 (Sonar) | `sonarfix` skill (run yourself) | `sonarfix` skill (run yourself) | `sonarfix` skill (run yourself) |
| 9 (Trivy) | `trivyfix` skill (run yourself) | `trivyfix` skill (run yourself) | `trivyfix` skill (run yourself) |
| 10 (QA) | `tester-qa` | `tester-qa` | `tester-qa` |
| 11 (Docs) | `documentation-writer` skill (run yourself) | `documentation-writer` skill (run yourself) | `documentation-writer` skill (run yourself) |
| 12 (PR) | `githubpr` skill (run yourself) | `githubpr` skill (run yourself) | `githubpr` skill (run yourself) |
| 13 (Notify) | `telegram` skill (run yourself) | `telegram` skill (run yourself) | `telegram` skill (run yourself) |
**Note:** Steps that are pure skills (code-simplifier, linter, sonarfix, trivyfix, documentation-writer, githubpr, telegram) are loaded via the `skill` tool directly by you (the orchestrator) — they are not agents and cannot be delegated via `task`. Steps that are roles (TDD, implementation, code review, security focused review, QA) ARE delegated to agents. The `code-reviewer-<lang>` and `tester-qa` agents are vision-capable — they can read screenshots and UI state. The `product-owner` agent is NOT part of the loop — the user provides the spec/requirements directly as input to the loop.
## How to delegate to an agent
For each agent-delegated step, call the `task` tool with:
- `subagent_type`: the agent identifier from the map above.
- `description`: 3-5 words summarizing the step.
- `prompt`: a **highly detailed** prompt containing:
0. The **SKILL MANDATE block** as the FIRST lines (see CRITICAL RULES #8 — exact skill names per agent, `SKILL_LOADED:` confirmation required).
1. The objective of this step in the overall workflow.
2. The concrete task to perform (files to read, code to write, tests to run).
3. The ARTIFACT CONTEXT block (per the forwarding matrix).
4. The expected output to return to the orchestrator (e.g. list of test files written, test run output, review score, bug report).
5. Context from previous steps (e.g. test files from step 1, file paths from step 2).
- `task_id` (optional): to resume a previous agent session for iteration loops (e.g. when step 4 code review fails and you loop back to step 2).
You MUST forward relevant artifacts between agents: test files → implementation agent → reviewer, etc. Agents do not share context unless you forward it. The user provides the spec/requirements directly as input to the loop — there is no requirements-discovery step inside the loop.
## Mandatory Checklist
You MUST maintain this checklist throughout the implementation. Print it before creating the PR to verify completeness:
```
- [ ] 1. TDD — test-writer agent → failing tests written (Red), extending existing specs first + `TEST_FILES: <paths>` pointer returned
- [ ] 2. IMPLEMENTATION — hexagonal agent (backend or frontend) → feature implemented (Green) + `IMPL_FILES: <paths>` pointer returned
- [ ] 3. TESTED — targeted test run (feature specs + affected specs), all green
- [ ] 4. CODE REVIEW — code-reviewer-<lang> agent → 0 critical + score ≥ 8/10 + `REVIEW: <path>` pointer returned
- [ ] 4b. SECURITY — security-agent focused review (conditional: `SECURITY: skipped (<reason>)` is valid when no security-sensitive surface is touched) → 0 confirmed findings + `SECURITY: <path|none|skipped>` pointer returned
- [ ] 5. CODE SIMPLIFIER — code-simplifier skill → complexity reduced
- [ ] 6. LINTER — linter skill → 0 lint AND type issues (ruff + pyright)
- [ ] 7. TARGETED RE-RUN — feature + affected specs green again after simplification/lint (NO full suite — CI runs it)
- [ ] 8. SONARQUBE — sonarfix skill → 0 new issues
- [ ] 9. TRIVY — trivyfix skill → 0 new vulns
- [ ] 10. TESTER-QA — tester-qa agent + new e2e in soludev-compose-apps/<app>/e2e + `BUG_REPORT: <path|none>` pointer returned
- [ ] 11. DOCUMENTATION — documentation-writer skill → docs updated + `<LOOP_DIR>/loop-report.html` generated
- [ ] 12. PR — githubpr skill → one draft PR per modified repo
- [ ] 13. TELEGRAM — telegram skill → completion notification sent (summary + PR links)
```
**Before step 12 (PR), verify ALL boxes 1-11 are checked.** If any is missing:
- STOP
- Print the checklist showing which steps are incomplete
- Complete the missing step (via the matching agent or skill)
- Only then proceed to PR
## Development Workflow Details
### 1. Test-First Development — `test-writer` agent
**ACTIONS (in order):**
1. call the `task` tool NOW with `subagent_type: test-writer`. The task prompt MUST:
- Include the CONTEXT block (per the forwarding matrix, step 1 gets `SPEC_FILE` only):
```
ARTIFACT CONTEXT (read ALL files IN FULL before starting — do NOT skip, do NOT summarize):
SPEC_FILE: <path>
```
If in `SPEC_MODE: conversation-fallback`, include the available requirements context directly in the task prompt instead.
- Instruct the agent to search the existing test suite FIRST — grep/glob for spec files already covering the same entry point or feature (route path, endpoint/use case name, component/hook name) and EXTEND those files with the new failing test cases instead of creating new ones; create a new test file ONLY when no existing spec covers the entry point. Never duplicate coverage that already exists.
- Instruct the agent to end its returned message with `TEST_FILES: <comma-separated absolute paths to every test file written or modified>` followed by `AGENT_CONFIRM: test-writer delegated on step 1 → <N> failing test files written or modified`.
2. the agent loads `test-writer-<lang>` (per detected stack) via the SKILL MANDATE injected at the top of its task prompt — verify `SKILL_LOADED:` in its output.
3. **Collect the `TEST_FILES:` pointer** from the agent's returned message — grep the line and store it for forwarding to steps 4 and 10.
4. `bash .../trace.sh "<LOOP_DIR>" "<loop_id>" "1" "agent" "test-writer" "delegated" "<N> test files written or modified"`.
5. before step 2: `verify-step.sh ... "1" "agent" "test-writer"` — if fail, redo step 1.
### 2. Implementation — hexagonal agent
**ACTIONS (in order):**
1. call the `task` tool NOW with `subagent_type: <fastapi-hexagonal | react-hexagonal | nestjs-hexagonal>` per the detected stack. The task prompt MUST:
- Include the CONTEXT block (per the forwarding matrix, step 2 gets `SPEC_FILE` only on first pass — **no TEST_FILES**; on loop-back add `REVIEW` + `BUG_REPORT`):
```
ARTIFACT CONTEXT (read ALL files IN FULL before starting — do NOT skip, do NOT summarize):
SPEC_FILE: <path>
```
On loop-back (code review or QA failed), add the review and/or bug report pointers:
```
ARTIFACT CONTEXT (read ALL files IN FULL before starting — do NOT skip, do NOT summarize):
SPEC_FILE: <path>
REVIEW: <LOOP_DIR>/code-reviews/<slug>.md
BUG_REPORT: <LOOP_DIR>/bug-reports/<slug>.md
```
If in `SPEC_MODE: conversation-fallback`, include the available requirements context directly in the task prompt instead.
- Instruct the agent to end its returned message with `IMPL_FILES: <comma-separated absolute paths>` followed by `AGENT_CONFIRM: <agent> delegated on step 2 → <N> files implemented`.
2. the agent loads the architecture/async/performance skills via the SKILL MANDATE injected at the top of its task prompt — verify `SKILL_LOADED:` in its output.
3. **Collect the `IMPL_FILES:` pointer** from the agent's returned message — grep the line and store it for forwarding to steps 4 and 10.
4. `bash .../trace.sh "<LOOP_DIR>" "<loop_id>" "2" "agent" "<agent_name>" "delegated" "<N> files modified"`.
5. before step 3: `verify-step.sh ... "2" "agent" "<agent_name>"` — if fail, redo step 2.
### 3. Targeted Test Run
1. Run the targeted tests yourself via Bash — the feature's new spec files plus directly related behavioral specs: `uv run pytest tests/behavioral/<feature>/ -q` (Python), `npx vitest run <spec-files>` (TypeScript). All must pass with 0 failures. Do NOT re-run the entire suite — the CI runs the full suite on the PR. If a failure appears, loop back to step 2 via the implementation agent (use `task_id` to resume the session).
2. `bash .../trace.sh "<LOOP_DIR>" "<loop_id>" "3" "bash" "test-suite" "done" "exit=<code>, pass=<N>"`.
3. before step 4: `verify-step.sh ... "3" "bash" "test-suite"` — if fail, redo step 3.
### 4. Code Review
**ACTIONS (in order):**
1. call the `task` tool NOW with `subagent_type: code-reviewer-<lang>` per the detected stack (Python → `code-reviewer-python`, React → `code-reviewer-react`, NestJS → `code-reviewer-nestjs`). The task prompt MUST:
- Include the CONTEXT block (per the forwarding matrix, step 4 gets `SPEC_FILE` + `TEST_FILES` + `IMPL_FILES`; on re-review add prev `REVIEW` + `BUG_REPORT`):
```
ARTIFACT CONTEXT (read ALL files IN FULL before starting — do NOT skip, do NOT summarize):
SPEC_FILE: <path>
TEST_FILES: <comma-separated absolute paths from step 1>
IMPL_FILES: <comma-separated absolute paths from step 2>
```
On re-review (loop-back after fixes), add the previous review and bug report if QA also failed:
```
REVIEW: <LOOP_DIR>/code-reviews/<slug>.md
BUG_REPORT: <LOOP_DIR>/bug-reports/<slug>.md
```
If in `SPEC_MODE: conversation-fallback`, include the available requirements context directly in the task prompt instead.
- Include the review-persistence block (mandatory — the agent MUST persist the review to a file):
```
REVIEW PERSISTENCE (mandatory):
- LOOP_DIR: <LOOP_DIR absolute path>
- Persist the FULL review to <LOOP_DIR>/code-reviews/<slug>.md (reuse the <slug> from the SPEC_FILE path). Run `mkdir -p <LOOP_DIR>/code-reviews/` first, then `write` the complete review — score table + summary + critical issues + improvements + minor suggestions + positive highlights — not a summary.
- Print `REVIEW: <LOOP_DIR>/code-reviews/<slug>.md` (absolute path) before the AGENT_CONFIRM line.
```
- Instruct the agent to end its returned message with `REVIEW: <path>` followed by `AGENT_CONFIRM: code-reviewer-<lang> delegated on step 4 → score=<S>, critical=<N>, REVIEW: <path|none>`.
2. the agent loads `code-reviewer` + `hexagonal-<lang>-patterns` + `async-<lang>-patterns` + `performance-audit` + `test-writer-<lang>` via the SKILL MANDATE injected at the top of its task prompt (verify `SKILL_LOADED:` in its output). The review uses the 6-dimension scoring rubric. Minimum required: **8/10**. If below 8, loop back to step 2 (delegate to the implementation agent with `task_id` to resume the session, include `SPEC_FILE` + `REVIEW` + `BUG_REPORT` in the CONTEXT block) and fix, then re-run. If any critical issues remain, loop back regardless of score. Commit fixes.
3. **Collect the `REVIEW:` pointer** from the agent's returned message — grep the line and store it for forwarding to step 10 and step 2 on loop-back.
4. `bash .../trace.sh "<LOOP_DIR>" "<loop_id>" "4" "agent" "code-reviewer-<lang>" "delegated" "score=<S>, critical=<N>, REVIEW: <path|none>"`.
5. before step 5: `verify-step.sh ... "4" "agent" "code-reviewer-<lang>"` — if fail, redo step 4.
### 4b. Security Focused Review — `security-agent` (conditional)
**ACTIONS (in order):**
1. Decide whether the change touches a security-sensitive surface (grep the diff / `IMPL_FILES` + the spec for: auth/sessions/JWT/guards/permissions, new or modified HTTP endpoints or input parsing, secrets/credentials/env handling, data isolation (multi-tenant, ownership checks), file uploads, webhooks/payments/external API calls, LLM/AI prompt construction, crypto/hashing).
- **Triggered** → call the `task` tool NOW with `subagent_type: security-agent`. The task prompt MUST:
- Include the SKILL MANDATE block: `security-audit`, plus the explicit instruction that this is a FOCUSED review in guidance mode — scope limited to the listed files, NOT an audit: do NOT run the six-phase workflow, do NOT create an output directory, do NOT write audit artifacts.
- Include the CONTEXT block (per the forwarding matrix, step 4b gets `SPEC_FILE` + `IMPL_FILES` + `REVIEW`; on re-review add prev `SECURITY`).
- Include the persistence block: persist findings to `<LOOP_DIR>/security-reviews/<slug>.md` (`mkdir -p` first, reuse the `<slug>` from the SPEC_FILE path) and print `SECURITY: <path|none>` before the AGENT_CONFIRM line.
- **Not triggered** → print `SECURITY: skipped (no security-sensitive surface: <one-line reason>)` and trace step 4b as `type=agent`, target `security-agent`, `status=done` (the verify gate passes — no delegation needed).
2. **Gate:** `SECURITY: <path>` with ≥1 confirmed finding → loop back to step 2 (delegate to the implementation agent with `task_id` to resume the session, include `SPEC_FILE` + `REVIEW` + `SECURITY` in the CONTEXT block), fix, then re-run steps 3-4b. `SECURITY: none` or `skipped` passes. needs_validation findings do NOT block the loop, but MUST be embedded in the PR comment (step 12).
3. **Collect the `SECURITY:` pointer** from the agent's returned message — grep the line and store it for step 12 and step 2 on loop-back.
4. `bash .../trace.sh "<LOOP_DIR>" "<loop_id>" "4b" "agent" "security-agent" "delegated" "findings=<N>, SECURITY: <path|none>"` (or `"done" "skipped: <reason>"` when skipped).
5. before step 5: `verify-step.sh ... "4b" "agent" "security-agent"` — if fail, redo step 4b.
### 5. Code Simplifier
**ACTIONS (in order):**
1. call the `skill` tool NOW with `code-simplifier`.
2. refactor to reduce complexity while maintaining functionality. Run tests again after simplification (step 3).
3. print `SKILL_CONFIRM: code-simplifier loaded and applied on step 5`.
4. `bash .../trace.sh "<LOOP_DIR>" "<loop_id>" "5" "skill" "code-simplifier" "loaded" "<detail>"`.
5. before step 6: `verify-step.sh ... "5" "skill" "code-simplifier"` — if fail, redo step 5.
### 6. Linter
**ACTIONS (in order):**
1. call the `skill` tool NOW with `linter`.
2. run ruff + pyright (Python) and/or eslint+prettier (TypeScript) per the loaded skill. **Fix ALL issues (lint AND type errors, including pre-existing pyright errors) until 0 issues** — iterating run → fix → run — before proceeding. Delegate fixes back to the implementation agent if non-trivial.
3. print `SKILL_CONFIRM: linter loaded and applied on step 6`.
4. `bash .../trace.sh "<LOOP_DIR>" "<loop_id>" "6" "skill" "linter" "loaded" "<N> issues fixed"`.
5. before step 7: `verify-step.sh ... "6" "skill" "linter"` — if fail, redo step 6.
### 7. Targeted Re-Run (post-simplification)
1. Re-run the TARGETED tests via Bash — the same scope as step 3 (the feature's new spec files plus directly related behavioral specs), plus the specs covering any file the simplifier (step 5) or linter (step 6) modified: `uv run pytest tests/behavioral/<feature>/ -q` (Python), `npx vitest run <spec-files>` (TypeScript). All must pass with 0 failures. Do NOT run the full suite — the CI runs the full suite on the PR. If a failure appears, loop back to step 2 via the implementation agent (use `task_id` to resume the session).
2. `bash .../trace.sh "<LOOP_DIR>" "<loop_id>" "7" "bash" "targeted-rerun" "done" "exit=<code>, pass=<N>"`.
3. before step 8: `verify-step.sh ... "7" "bash" "targeted-rerun"` — if fail, redo step 7.
### 8. SonarQube
**ACTIONS (in order):**
1. call the `skill` tool NOW with `sonarfix`.
2. run SonarQube analysis. Verify 0 new issues on the branch. If issues, loop back to step 2 (delegate to implementation agent) to fix, then re-run.
3. print `SKILL_CONFIRM: sonarfix loaded and applied on step 8`.
4. `bash .../trace.sh "<LOOP_DIR>" "<loop_id>" "8" "skill" "sonarfix" "loaded" "<N> new issues"`.
5. before step 9: `verify-step.sh ... "8" "skill" "sonarfix"` — if fail, redo step 8.
### 9. Trivy
**ACTIONS (in order):**
1. call the `skill` tool NOW with `trivyfix`.
2. run Trivy vulnerability scan. Verify 0 new vulnerabilities. If issues, loop back to step 2 to fix, then re-run.
3. print `SKILL_CONFIRM: trivyfix loaded and applied on step 9`.
4. `bash .../trace.sh "<LOOP_DIR>" "<loop_id>" "9" "skill" "trivyfix" "loaded" "<N> vulns"`.
5. before step 10: `verify-step.sh ... "9" "skill" "trivyfix"` — if fail, redo step 9.
### 10. Tester-QA — `tester-qa` agent
**ACTIONS (in order):**
1. call the `task` tool NOW with `subagent_type: tester-qa`. The task prompt MUST:
- Include the CONTEXT block (per the forwarding matrix, step 10 gets `SPEC_FILE` + `TEST_FILES` + `IMPL_FILES` + `REVIEW`; on loop-back add prev `BUG_REPORT`):
```
ARTIFACT CONTEXT (read ALL files IN FULL before starting — do NOT skip, do NOT summarize):
SPEC_FILE: <path>
TEST_FILES: <comma-separated absolute paths from step 1>
IMPL_FILES: <comma-separated absolute paths from step 2>
REVIEW: <LOOP_DIR>/code-reviews/<slug>.md
```
On loop-back (previous QA found bugs), add:
```
BUG_REPORT: <LOOP_DIR>/bug-reports/<slug>.md
```
If in `SPEC_MODE: conversation-fallback`, include the available requirements context directly in the task prompt instead.
- Include the bug-report persistence block (mandatory — the agent MUST persist bugs to a file, not just print them):
```
BUG REPORT OUTPUT (mandatory):
- LOOP_DIR: <LOOP_DIR absolute path>
- If you find confirmed bugs, persist the FULL bug report to <LOOP_DIR>/bug-reports/<slug>.md (reuse the <slug> from the SPEC_FILE path; if no spec, derive a short kebab-case slug, max 30 chars). Run `mkdir -p <LOOP_DIR>/bug-reports/` first, then `write` the complete tickets to that file — not a summary.
- Print one line per confirmed bug right before the pointer line: `BUG-XXX | Severity | Layer | <one-line root cause>`.
- End your returned message with EXACTLY one pointer line: `BUG_REPORT: <LOOP_DIR>/bug-reports/<slug>.md` (absolute path, bugs found) or `BUG_REPORT: none` (no bugs).
- This mirrors the SPEC_FILE pointer convention so the orchestrator can forward the path to the implementation agent on a loop-back.
```
- Instruct the agent to end its returned message with `AGENT_CONFIRM: tester-qa delegated on step 10 → <N> e2e specs written, <N> bugs found, BUG_REPORT: <path|none>`.
- Include the QA EVIDENCE OUTPUT block (mandatory — step 10 is NOT done without the matching evidence pointer lines):
```
QA EVIDENCE OUTPUT (mandatory):
- The e2e specs you write MUST test the feature under test — map each acceptance criterion of the spec to at least one spec test (print the coverage matrix). Generic "app loads" specs do not count.
- FRONT/FULLSTACK → generate the video report: `node /Users/yohan/.config/opencode/skills/tester-qa/build-qa-video-report.js <e2e_dir>` and print `QA_VIDEO_REPORT: <path> (N videos, X KB)`. No pointer line = invalid QA.
- BACKEND-ONLY → record every curl command + HTTP status + actual response in <LOOP_DIR>/qa/curl-logs.json (valid JSON, mkdir -p first) and print `QA_CURL_LOGS: <LOOP_DIR>/qa/curl-logs.json (N entries)`. Chat-only output does not count.
- End your returned message with BOTH matching pointer lines (QA_VIDEO_REPORT for front, QA_CURL_LOGS for backend) in addition to BUG_REPORT.
```
2. the agent relaunches the app's full docker stack FIRST (`docker compose up -d --build --force-recreate` in `soludev-compose-apps/<app_name>/`, verified with `docker compose ps` + smoke test), performs the QA itself (curl for backend-only, Chrome DevTools MCP browser for fullstack), transcribes the QA tests performed into NEW e2e Playwright specs in `soludev-compose-apps/<app_name>/e2e`, then replays ONLY the feature specs (NO full suite — QA scope is the feature under test). Re-running existing tests is not enough. If bugs found, loop back to step 2 with the bug report and re-run steps 3-10.
3. **Collect the `BUG_REPORT:` pointer AND the evidence pointers** (`QA_VIDEO_REPORT:` for front features, `QA_CURL_LOGS:` for backend) from the agent's returned message — grep the lines, store them for step 12 (PR comment), and REJECT the QA if the matching evidence line is missing: re-delegate to the tester-qa agent until the evidence pointers are present.
4. `bash .../trace.sh "<LOOP_DIR>" "<loop_id>" "10" "agent" "tester-qa" "delegated" "<N> e2e specs, <N> bugs, BUG_REPORT: <path|none>"`.
4. before step 11: `verify-step.sh ... "10" "agent" "tester-qa"` — if fail, redo step 10.
#### Bug report consumption (orchestrator side, after step 10)
Grep the `BUG_REPORT: <path|none>` line from the tester-qa agent's returned message:
- `BUG_REPORT: none` → QA gate passed, proceed to step 11.
- `BUG_REPORT: <LOOP_DIR>/bug-reports/<slug>.md` → QA gate failed. Loop back to step 2 (implementation agent). When you delegate to the implementation agent, include a **bug-report pointer block** in the task prompt (non-negotiable, path-only — never paste the content):
```
BUG_REPORT: <path>
Use the `read` tool to read this bug report IN FULL before doing anything else. Do NOT skip this step. Do NOT work from a summary — read the full file. Fix every confirmed bug listed in the report, ordered by descending severity (Critical first). Each ticket has Steps to reproduce, Expected behavior, Observed behavior, Evidence, and a Root cause hypothesis — use them to locate and fix the defect.
```
Re-include the `SPEC_FILE: <path>` block alongside it (agents do not retain context across sessions). Then re-run steps 3-10. Loop until the tester-qa agent returns `BUG_REPORT: none`.
### 11. Documentation
**ACTIONS (in order):**
1. call the `skill` tool NOW with `documentation-writer`.
2. update or create documentation when public APIs or significant behavior changes. Skip only if internal refactors with no user-facing impact (trace as `status=skipped-by-user`).
3. the documentation-writer skill ALSO generates the mandatory `<LOOP_DIR>/loop-report.html` (big-picture loop schema + per-step timeline) — verify the file exists before tracing (`test -f "<LOOP_DIR>/loop-report.html"`); if missing, redo the report part.
4. print `SKILL_CONFIRM: documentation-writer loaded and applied on step 11 (loop-report.html generated)` then, as the LAST line of the output, print the clickable link: `LOOP_REPORT: file://<LOOP_DIR>/loop-report.html`.
5. `bash .../trace.sh "<LOOP_DIR>" "<loop_id>" "11" "skill" "documentation-writer" "loaded" "<detail>; loop-report.html generated"`.
6. before step 12: `verify-step.sh ... "11" "skill" "documentation-writer"` — if fail, redo step 11.
### 12. PR
**ACTIONS (in order):**
1. call the `skill` tool NOW with `githubpr`.
2. if no Jira ticket, create a conventional descriptive branch name. Open one detailed draft PR per modified repo. Commits are conventional. Post the full loop results comment per the githubpr skill — **QA evidence is a hard gate**: front/fullstack → the QA replay videos MUST be attached inline and verified (every `![]()` rewritten to a `github.com/user-attachments/...` URL in the posted body; use the `QA_VIDEO_REPORT` videos from step 10); backend-only → the curl evidence from `<LOOP_DIR>/qa/curl-logs.json` MUST be embedded. A PR comment without the matching evidence = PR step NOT done. If step 4b produced a security review, embed its findings (especially needs_validation ones) in the PR comment. Do NOT merge — the user must be able to test on the local stack. Wait for CI green. If PR reviewer feedback arrives, address only critical items in a single pass — do NOT loop on PR reviews (the in-loop code review gate is authoritative).
3. print `SKILL_CONFIRM: githubpr loaded and applied on step 12`.
4. `bash .../trace.sh "<LOOP_DIR>" "<loop_id>" "12" "skill" "githubpr" "loaded" "<PR URLs>"`.
5. before step 13: `verify-step.sh ... "12" "skill" "githubpr"` — if fail, redo step 12.
### 13. Telegram Notification
**ACTIONS (in order):**
1. call the `skill` tool NOW with `telegram`.
2. compose the completion notification (plain text, per the telegram skill): loop_id, one-paragraph summary of the work done (feature, stack, repo), gates results (tests green, review score, QA bugs), the PR URLs from step 12 — ONLY if PRs were created in this loop (PR step skipped → summary only), and the `<LOOP_DIR>/loop-report.html` path if it exists. Send it with `bash /Users/yohan/.config/opencode/skills/telegram/send.sh "<message>"`. On failure, retry ONCE.
3. **Non-blocking (best-effort):** if Telegram is not configured or the send fails after the retry, do NOT invalidate the completed work — trace with `status=skipped-by-user` (not configured) or `status=failed` (send failed), print a warning, and declare the loop done anyway.
4. print `SKILL_CONFIRM: telegram loaded and applied on step 13`.
5. `bash .../trace.sh "<LOOP_DIR>" "<loop_id>" "13" "skill" "telegram" "loaded" "notified"` (or the matching skip/fail status, see above).
6. final: `verify-step.sh ... "13" "skill" "telegram"` — if fail, print a warning but do NOT redo the prior steps (the work is complete; the notification is best-effort). Then declare the loop done.
## Guidelines
- The user provides the spec/requirements as input to the loop — no discovery phase inside the loop. Prefer a spec file path (`<LOOP_DIR>/specs/<slug>.md`) produced by the product-owner agent. Fall back to conversation context only if no spec file is available.
- **Artifact forwarding is systematic.** Every agent gets the CONTEXT block with all relevant artifact pointers (per the forwarding matrix). Never paste file contents — always pass paths and instruct agents to `read` in full. A summarized or pasted-but-truncated file is an invalid delegation.
- **If code review reveals issues** (critical > 0 or score < 8), iterate back to implementation (delegate to the implementation agent with `task_id` to resume the session). Include `SPEC_FILE` + `REVIEW` in the CONTEXT block so the impl agent reads the review and knows exactly what to fix.
- **If the security focused review confirms findings** (`SECURITY: <path>` with ≥1 confirmed), iterate back to implementation with `SPEC_FILE` + `REVIEW` + `SECURITY` in the CONTEXT block (path-only — agents read the files themselves). needs_validation findings do NOT block — embed them in the PR comment (step 12). Loop until the security-agent returns `SECURITY: none`.
- **If QA reveals bugs**, iterate back to implementation with `SPEC_FILE` + `REVIEW` + `BUG_REPORT` in the CONTEXT block (path-only — agents read the files themselves). Loop until the tester-qa agent returns `BUG_REPORT: none`.
- When chaining multiple tickets, be EXTRA vigilant about completing all steps — this is when steps get skipped.
- **Delegating is cheap.** When in doubt, delegate again to the matching agent with the CONTEXT block + previous step artifacts. The `task` tool is the canonical way to guarantee the agent's skills are loaded and the work is done by the right role.
- **When the loop is blocked waiting for the user** (ambiguous stack, rejected step, unavailable agent, any question or decision needed), load the `telegram` skill FIRST and send a question notification BEFORE waiting — the user is often away from the terminal. A failed/blocked Telegram send never blocks: still ask the question in the session.
- **On EVERY loop-back iteration** (QA bugs, review < 8/10 or criticals, security findings, failing tests, CI red, rejected step), load the `telegram` skill FIRST and send a loop-back notification (iteration number + one-line reason + what is being redone) BEFORE re-delegating. The send attempt is mandatory on every iteration; delivery remains best-effort.