AGENT SKILL

tdd

TDD-orchestrator що проганяє повний Red-Green-Refactor цикл через 3 ізольовані agents. Використовуй коли користувач каже `/tdd <story-id>` (наприклад `/tdd story-24-sm2`), або «прогон TDD циклу на story X», «запусти TDD pipeline», «зроби RGR на цій story». Послідовно викликає tdd-test-writer → tdd-implementer → tdd-refactorer через Agent tool, з automatic bash-gates між фазами. Підтримує опційний flag `--review-tests` для зупинки після RED і human review.

License 许可
MIT
最近更新
2026-11-12
Stars
★ 15
Forks
13

01 前言 Front Matter

name
tdd
description
TDD-orchestrator що проганяє повний Red-Green-Refactor цикл через 3 ізольовані agents. Використовуй коли користувач каже `/tdd <story-id>` (наприклад `/tdd story-24-sm2`), або «прогон TDD циклу на story X», «запусти TDD pipeline», «зроби RGR на цій story». Послідовно викликає tdd-test-writer → tdd-implementer → tdd-refactorer через Agent tool, з automatic bash-gates між фазами. Підтримує опційний flag `--review-tests` для зупинки після RED і human review.
allowed-tools
Bash, Read, Agent

03 SKILL.md 正文

tdd — orchestrator повного RGR циклу

Цей skill — диригент. Сам НЕ пише ні тестів, ні коду. Викликає 3 справжніх Claude Code agents (з .claude/agents/) через Agent tool, кожен у своєму isolated context. Між фазами виконує bash-гейти автоматично. На failure будь-якого гейту — STOP з actionable error.

Чому 3 окремі agents, а не 3 skill-виклики у одному контексті: skill виконується inline у тому самому context window головного агента. Agent tool створює окреме context window зі своїм system prompt. Тільки другий варіант дає реальний isolation, який лікує context pollution — головний аргумент Section 4 лекції 7.7.

Inputs

З користувацького промпта витягни:

  • <story-id> — обов'язково. Наприклад story-24-sm2. Має існувати файл tasks/<story-id>.md.
  • --review-tests — опційний flag. Якщо є, після Phase 1 зупинитись і чекати на user input («continue» / «abort») перед запуском Phase 2. Це augmented coding варіант з Section 9 лекції.

Pre-flight checks (виконати ПЕРЕД будь-якою фазою)

Виконай у Bash:

  1. git status --porcelain — output має бути порожній.
    • Якщо ні: STOP з Working tree not clean. Commit or stash changes before /tdd <story-id>.
  2. test -f tasks/<story-id>.md && echo OK — story-файл має існувати.
    • Якщо ні: STOP з Story file tasks/<story-id>.md not found.
  3. git rev-parse HEAD — запам'ятай baseline SHA для фінального звіту.

Phase 1 — RED (tdd-test-writer)

Виклич Agent tool:

Agent(
  subagent_type="tdd-test-writer",
  description="RED phase: write failing tests for <story-id>",
  prompt="Story: <story-id>. Read tasks/<story-id>.md and CLAUDE.md, then follow your standard RED-phase workflow: write failing tests in tests/, confirm pytest red, commit with `test(<scope>): add failing tests per AC` (scope = domain prefix from story), output `RED phase commit: <SHA>`. STOP after commit. Do not write implementation."
)

Дочекайся завершення. Витягни з output рядок RED phase commit: <SHA> — запиши як RED_SHA.

Gate 1 — verify RED state

Виконай у Bash послідовно:

  • git log -1 --pretty=%s — output має починатись з test(.
    • Якщо ні: STOP з Phase 1 gate failed: last commit subject doesn't start with test(. Got: <subject>. SHA: <RED_SHA>.
  • pytest -q; echo "EXIT:$?" — exit code MUST be != 0 (тести мають падати).
    • Якщо EXIT:0: STOP з Phase 1 gate failed: pytest passes after RED phase. Tests don't actually verify new behavior — they pass on empty implementation. SHA: <RED_SHA>.

Якщо --review-tests flag присутній: STOP з:

Phase 1 complete (RED). Review tests via `git show <RED_SHA>`.
To continue: run `/tdd <story-id>` again (will re-detect RED state and skip to Phase 2).
To abort: `git reset --hard <baseline-SHA>`.

(Зауваж: для auto-continue після review треба, щоб Pre-flight #1 не зашкодив. Один з варіантів — користувач каже «continue» одним рядком, і skill стартує безпосередньо з Phase 2 без re-run pre-flight. Альтернатива — повний re-run, який детектить останній commit як RED і пропускає Phase 1.)

Phase 2 — GREEN (tdd-implementer)

Виклич Agent tool:

Agent(
  subagent_type="tdd-implementer",
  description="GREEN phase: implement <story-id> to make tests pass",
  prompt="Story: <story-id>. Read tests/ (read-only) and interface stub in src/. Follow your standard GREEN-phase workflow: write minimal monolithic implementation in src/, drive pytest to green, commit with `feat(<scope>): implement to make tests pass`, output `GREEN phase commit: <SHA>`. STOP after commit. Do NOT modify any file under tests/."
)

Витягни GREEN_SHA з output.

Gate 2 — verify GREEN state

Виконай у Bash:

  • git log -1 --pretty=%s — output має починатись з feat(.
    • Якщо ні: STOP з Phase 2 gate failed: last commit subject doesn't start with feat(. Got: <subject>. SHA: <GREEN_SHA>.
  • pytest -q; echo "EXIT:$?" — exit code MUST be 0.
    • Якщо ні: STOP з Phase 2 gate failed: pytest still red after implementer. SHA: <GREEN_SHA>.
  • git diff --name-only HEAD~1 HEAD -- tests/ — output MUST be порожній (тести не торкалися).
    • Якщо непорожній: STOP з Phase 2 gate failed: implementer modified tests/. Hard rule violated. Files changed: <files>. SHA: <GREEN_SHA>.

Phase 3 — REFACTOR (tdd-refactorer)

Виклич Agent tool:

Agent(
  subagent_type="tdd-refactorer",
  description="REFACTOR phase: extract helpers for <story-id>",
  prompt="Story: <story-id>. Refactor src/ implementation: extract at least 2 private helpers based on natural branches per story rules, run pytest after each change. Commit with `refactor(<scope>): extract helpers`, output `REFACTOR phase commit: <SHA>`. STOP after commit. Tests are STRICTLY read-only."
)

Витягни REFACTOR_SHA з output.

Gate 3 — verify REFACTOR state

Виконай у Bash:

  • git log -1 --pretty=%s — output має починатись з refactor(.
    • Якщо ні: STOP з Phase 3 gate failed: last commit subject doesn't start with refactor(. Got: <subject>. SHA: <REFACTOR_SHA>.
  • pytest -q; echo "EXIT:$?" — exit code MUST be 0.
    • Якщо ні: STOP з Phase 3 gate failed: refactor broke tests. SHA: <REFACTOR_SHA>.
  • git diff --name-only HEAD~1 HEAD -- tests/ — output MUST be порожній.
    • Якщо непорожній: STOP з Phase 3 gate failed: refactorer modified tests/. SHA: <REFACTOR_SHA>. Files: <files>.
  • grep -E '^\s*def _' src/<feature>.py | wc -l (де <feature> витягається з commit-diff) — output MUST be ≥ 2 (мінімум 2 приватні helpers).
    • Якщо < 2: STOP з Phase 3 gate failed: refactorer extracted only <n> helpers, expected ≥ 2. SHA: <REFACTOR_SHA>.

Final report

Виведи користувачу:

TDD pipeline complete for <story-id>.

Commits:
  RED      <RED_SHA>      test(<scope>): add failing tests per AC
  GREEN    <GREEN_SHA>    feat(<scope>): implement to make tests pass
  REFACTOR <REFACTOR_SHA> refactor(<scope>): extract helpers

Gates passed:
  ✓ Phase 1: pytest red after test-writer, commit subject = test(
  ✓ Phase 2: pytest green after implementer, tests/ untouched
  ✓ Phase 3: pytest green after refactorer, tests/ untouched, ≥ 2 helpers extracted

Inspect: git log --oneline -3
Verify isolation: git diff HEAD~3 HEAD -- tests/ (must be non-empty for RED phase only)

Anti-patterns

  • Не виконуй фази inline. Кожна фаза = окремий Agent tool call. Якщо пишеш тести сам у головному контексті — context pollution повернувся, semantic argument лекції зламано.
  • Не пропускай gates. Gate 2 (git diff -- tests/) — критичний; без нього втрачаєш гарантію, що implementer не "виправив" тест.
  • Не намагайся "fix" failing agent. Якщо agent не зміг закрити phase — це сигнал про story або стек. STOP, дай користувачу побачити helpful error. Pipeline не повинен "майже працювати".
  • Не амальгамуй commits. 3 окремих commits — це observability layer. Squash-у не місце у цьому pipeline.

Example invocations

User: /tdd story-24-sm2
You:  (run pre-flight → Phase 1 via Agent → Gate 1 via Bash → Phase 2 → Gate 2 → Phase 3 → Gate 3 → final report)

User: /tdd story-24-sm2 --review-tests
You:  (same as above, але STOP після Gate 1 з review prompt)

User: /tdd story-99-broken-tests  (де тести виявились зеленими після test-writer)
You:  STOP з "Phase 1 gate failed: pytest passes after RED phase..."

04 同仓库更多 Skills

genkovich
genkovich/agentic-engineering-course-public

release

Run the whole local release pipeline in order, stopping at each human gate. Triggers on "run the release", "prepare a release", "/release", "зроби реліз", "підготуй реліз". Drives the four stages back to back — bump-version → curate-changelog → release-notes → check-docs-drift — pausing after each so the human reviews the diff before the next stage. Prepares everything in the working tree; never tags, commits, or pushes. The tag push (which fires CI) stays the human's action.

★ 15
genkovich
genkovich/agentic-engineering-course-public

release-notes

Draft partner-facing release notes from the same commits as the changelog. Triggers on "draft release notes", "release notes for the next version", "/release-notes", "нотатки релізу", "release notes партнеру". Same input as curate-changelog, different audience and tone: a short, benefit-first narrative for a user or partner — "what's new for you" — not a categorized engineer's list. Keeps only changes a user actually notices; drops internal refactors and tooling. Prints the notes to the chat to seed a GitHub Release description or a partner announcement. Writes no file.

★ 15
genkovich
genkovich/agentic-engineering-course-public

curate-changelog

Curate the [Unreleased] section of docs/CHANGELOG.md from git history. Triggers on "curate the changelog", "update the changelog", "/curate-changelog", "онови changelog", "курування журналу". Reads git log since the last tag, FILTERS out what a reader never feels (test/ci/chore/merge), GROUPS commits about one feature into one bullet, and REWRITES technical subjects into plain language under the six Keep a Changelog categories (Added/Changed/Deprecated/ Removed/Fixed/Security). The result must have FEWER lines than the raw log — that is the proof of curation, not a dump. Leaves the edit in the working tree; never commits or pushes.

★ 15
genkovich
genkovich/agentic-engineering-course-public

codify-rule

Turn a repeated mistake into a durable, path-scoped rule in .claude/rules/. Triggers on "codify this rule", "make a rule so this doesn't happen again", "/codify-rule", "закодифікуй правило", "петля помилка-правило". Use only when the same mistake showed up TWICE (twice = a pattern, once = noise). Names the wrong shape and the right shape with one short example of each, scopes the rule to the paths that matter, and leaves the edit in the working tree so the next agent on this repo inherits the fix. Edits only .claude/rules/; never commits or pushes.

★ 15
genkovich
genkovich/agentic-engineering-course-public

check-docs-drift

Find and fix where docs/api.md fell behind the code. Triggers on "check for doc drift", "is the API doc up to date", "/check-docs-drift", "перевір дрейф документації", "docs drift". Runs the deterministic scripts/check-docs-drift.py (parses the public NoteBook methods with ast, compares to what docs/api.md documents — NO LLM finds the gap), reports the drift, and PROPOSES the doc edit that closes it. The gap is found by parsing; the agent writes the missing documentation in the doc's existing style. Edits only docs/; never commits or pushes.

★ 15
genkovich
genkovich/agentic-engineering-course-public

bump-version

Decide and apply the next semver for a release. Triggers on "bump the version", "what version is next", "/bump-version", "простав версію", "яка наступна версія". Reads the next number from the deterministic scripts/next-version.sh (NEVER guesses it), explains in plain language WHICH part moved and why (e.g. "MINOR, because a feat landed: filter notes by tag"), edits the version line in pyproject.toml, and proposes the matching `git tag vX.Y.Z`. The number is decided by a rule; the agent explains and applies — the human confirms the tag. Never pushes a tag itself.

★ 15