From draft
Implements one task at a time from track plan using TDD workflow (red-green-refactor), commits each task, runs reviews at phase boundaries, updates plan.md. Use to start coding, implement next task, or run TDD.
npx claudepluginhub mayurpise/draft --plugin draftThis skill uses the workspace's default tool permissions.
You are implementing tasks from the active track's plan following the TDD workflow.
Executes tasks from a Conductor track's implementation plan using TDD workflow. Loads project context, updates track status, and follows checklists for implementation.
Executes tasks from Conductor track implementation plans via TDD workflow. Handles track selection, context loading, status updates, and guided task progression.
Starts collaborative intake for new feature or bug tracks: verifies draft init, loads project context (product.md, tech-stack.md), checks overlaps, refines scope, generates spec.md and plan.md.
Share bugs, ideas, or general feedback.
You are implementing tasks from the active track's plan following the TDD workflow.
[x] without fresh verification evidenceVerify before you mark complete. One task, one commit.
Draft skills are designed for single-agent, single-track execution. Do not run multiple Draft commands concurrently on the same track.
draft/tracks.md (look for [~] In Progress or first [ ] track)spec.md for requirementsplan.md for task listdraft/workflow.md for TDD and commit preferencesdraft/tech-stack.md for technical contextdraft/guardrails.md (if exists) for hard guardrails and learned conventionsdraft/tracks/<id>/architecture.mddraft/.ai-context.md (or legacy draft/architecture.md)draft/.ai-context.md exists):
## INVARIANTS section (and ## CONCURRENCY if present)draft/graph/schema.yaml exists):
draft/graph/hotspots.jsonl — check if any files this task will modify appear as hotspotsdraft/graph/modules/<module>.jsonl for the module(s) being modified — gives file-level dependency contextcore/shared/graph-query.md for on-demand query subroutines (callers, impact)draft/tracks.md from [ ] to [~] In ProgressIf no active track found:
/draft:new-track to create one."Architecture Mode Activation:
.ai-context.md or architecture.md exists (file-based, no flag needed)/draft:decompose.ai-context.md created by /draft:initSkip if: Any task in plan.md is already [x] — the track is in progress, this check has already passed.
Run once, before the first task of a new track:
For each acceptance criterion in spec.md:
plan.md references or addresses it.ai-context.md exists)Compare the synced_to_commit values in the YAML frontmatter of spec.md and plan.md.
synced_to_commit field (quick-mode tracks omit it).Issues found: List them, then ask:
Readiness issues found (see above). Proceed anyway or update first? [proceed/update]
proceed → add a ## Notes entry in plan.md listing the issues, then continue to Step 2update → stop here and let the user refine spec or plan before re-runningNo issues: Print Readiness check passed. and continue to Step 2.
Before starting TDD cycle for the first task:
draft/tracks/<id>/testing-strategy.mddraft/testing-strategy.md or draft/testing-strategy-latest.md/draft:testing-strategy to define test approach"If track type is bugfix (from metadata.json):
BEFORE writing any test file:
ASK: "This is a bug fix track. Want me to write tests as part of the fix? [Y/n]"
If declined: skip TDD cycle, note in plan.md: "Tests: developer-handled"
Scan plan.md for the first uncompleted task:
[ ] = Pending (pick this one)[~] = In Progress (resume this one)[x] = Completed (skip)[!] = Blocked (skip - requires manual intervention)IMPORTANT: If blocked task found, notify user:
[!] Blocked"If resuming [~] task, check for partial work.
Activation: Only runs when .ai-context.md or architecture.md exists (track-level or project-level).
When the next task involves creating or substantially modifying a code file:
// Story: [Module/File Name]
//
// Input: [what this module/function receives]
// Process:
// 1. [first algorithmic step]
// 2. [second algorithmic step]
// 3. [third algorithmic step]
// Output: [what this module/function produces]
//
// Dependencies: [what this module relies on]
// Side effects: [any mutations, I/O, or external calls]
Adapt comment syntax to the language (# for Python, /* */ for CSS, etc.).
STOP. Present the Story to the developer for review.
See core/agents/architect.md for story writing guidelines.
Activation: Only runs when .ai-context.md or architecture.md exists (track-level or project-level).
Skip for trivial tasks - Config updates, type-only changes, single-function tasks where the design is obvious.
Study the control flow for the task and propose intermediate state variables:
.ai-context.md Data Lifecycle — Align execution state with documented state machines (valid states/transitions), storage topology (which tier data targets), and data transformation chain (shape changes at boundaries).ai-context.md Critical Paths — Identify where this task sits in documented write/read/async paths. Note consistency boundaries and failure recovery expectations.Present in this format:
EXECUTION STATE: [Task/Module Name]
─────────────────────────────────────────────────────────
Input State:
- variableName: Type — purpose
Intermediate State:
- variableName: Type — purpose
Output State:
- variableName: Type — purpose
Error State:
- variableName: Type — purpose
CHECKPOINT (MANDATORY): Present execution state to developer. Wait for approval. Developer may add, remove, or modify state variables. Developer can say "skip" to bypass.
Generate function/method stubs based on the approved execution state:
// TODO, pass, unimplemented!(), etc.tech-stack.mdCHECKPOINT (MANDATORY): Present skeletons to developer. Wait for approval. Developer may rename functions, change signatures, add/remove methods. Developer can say "skip" to bypass.
See core/agents/architect.md for execution state and skeleton guidelines.
Applies to all code generation — architecture mode or not. These patterns are generation directives, not a post-hoc checklist. Apply them while writing code, not after.
When your implementation hits any of these triggers, use the corresponding pattern. Do not write code that violates these and plan to "fix it later."
| Trigger | Required Pattern |
|---|---|
| Multi-step state mutation (DB + memory, multiple records) | Wrap in transaction or try/finally with rollback on failure |
| File write | Write to temp file + atomic rename to target path. Never write directly to the target. |
| DB write paired with in-memory state update | DB-first: persist to DB, update memory only on DB success. Never update memory optimistically. |
| Resource acquisition (locks, file handles, connections, capital) | Release in finally / defer / RAII — never rely on happy-path-only cleanup |
| Trigger | Required Pattern |
|---|---|
| Method mutates shared/instance state | Acquire the class's or module's existing lock before mutation |
| Lifecycle operations (start/stop/reset/reconnect) | Use a dedicated lifecycle lock, separate from data locks |
| Returning internal state to callers | Return a deep copy or frozen snapshot — never a mutable reference to internal state |
| Acquiring a second lock while holding one | Follow documented lock ordering. If no ordering exists, do not nest locks — restructure to acquire sequentially. |
| DB I/O while holding a state lock | Move DB I/O outside the lock scope. Lock only the in-memory mutation, not the I/O. |
| Trigger | Required Pattern |
|---|---|
| Critical state that must survive crashes | Ensure state is recoverable from DB/disk alone — no reliance on in-memory-only state for recovery |
| Async DB write (fire-and-forget) | Await the write. Check return value or propagate exceptions. No fire-and-forget on data persistence. |
| Event log / audit trail / fill history | Use append-only pattern where specified by architecture |
| Trigger | Required Pattern |
|---|---|
| External numeric data used in arithmetic | Guard with isFinite() / isnan() / equivalent before any calculation |
| External API/webhook response consumed | Validate expected fields exist and have correct types before accessing nested properties |
| SQL query with dynamic values | Parameterized queries only — zero string interpolation for values |
| Dynamic column names, table names, or identifiers in SQL | Validate against an explicit allowlist — never pass user-controlled strings as identifiers |
| Trigger | Required Pattern |
|---|---|
| Operation that may be retried (network calls, queue consumers, webhook handlers) | Use a dedup key (UUID, request ID, fill ID) — check-before-write or upsert |
| State transition (status changes, lifecycle events) | Validate the transition is legal from the current state. Reject terminal→terminal transitions. |
| Alert / notification emission | Dedup on (alert_type, entity_id, time_window) to prevent re-firing on retries |
| Trigger | Required Pattern |
|---|---|
| Error path or exception handler that determines access/action | Default to the safe/restrictive/deny state — never default to permissive on error |
| Missing data, null, or undefined where a decision depends on it | Treat as deny/reject/skip — not as allow/proceed |
| Config or feature flag missing/unparseable | Use the restrictive default — system runs in safe mode, not open mode |
| Trigger | Required Pattern |
|---|---|
| Any retry logic | Exponential backoff with jitter — never fixed-interval or immediate retries. Prevents retry storms. |
| Cache population under high concurrency | Cache stampede prevention: use probabilistic early expiration or request coalescing to prevent thundering herd |
| External dependency call (HTTP, RPC, DB to external service) | Circuit breaker pattern: track failure rate, open circuit on threshold, allow periodic probes to recover |
| Non-critical dependency failure | Graceful degradation: return cached/default/partial result rather than failing the entire request |
Enforcement: These patterns override convenience. If following a pattern makes the code more verbose, that's correct — the verbosity is the safety. If a pattern is genuinely N/A for the current task (e.g., no DB in a pure utility function), skip it — only apply relevant patterns.
If project invariants were loaded in Step 1: Cross-reference them here. Project-specific invariants (lock ordering, concurrency model, consistency boundaries) take precedence over these general patterns when they conflict.
For each task, follow this workflow based on workflow.md. If skeletons were generated in Step 3.0b, fill them in using the TDD cycle below.
When refactoring code that lacks tests, write characterization tests first to capture current behavior as a baseline. Identify seams (interfaces for test doubles, swappable imports), record actual outputs for representative inputs, then proceed with the TDD cycle for new behavior.
Iron Law: No production code without a failing test first.
3a. RED - Write Failing Test
1. Create/update test file as specified in task
2. Write test that captures the requirement
3. RUN test - VERIFY it FAILS (not syntax error, actual assertion failure)
4. Show test output with failure
5. Announce: "Test failing as expected: [failure message]"
Test Quality Checklist (REQUIRED for every test):
assertTrue(true))Property-Based Testing Checkpoint: After writing example-based tests, consider property-based tests for pure functions (algebraic properties, round-trip serialization, sort invariants). Not mandatory — skip if properties are not obvious.
3b. GREEN - Implement Minimum Code
1. Write MINIMUM code to make test pass (no extras)
2. RUN test - VERIFY it PASSES
3. Show test output with pass
4. Announce: "Test passing: [evidence]"
Observability Prompts (consider during implementation): Structured logging at decision points, metrics for latency-sensitive ops, tracing at service boundaries, error classification (transient vs permanent). Use engineering judgment — not mandatory for every task.
Contract Testing Checkpoint (Service Boundaries Only): For new API endpoints or service-to-service interfaces, suggest consumer-driven contract tests. Skip for purely internal modules.
3c. REFACTOR - Clean with Tests Green
1. Review code for improvements
2. Refactor while keeping tests green
3. RUN all related tests after each change
4. Show final test output
5. Announce: "Refactoring complete, all tests passing: [evidence]"
Red Flags - STOP and restart the cycle if:
3a. Implement
1. Implement the task as specified
2. Test manually or run existing tests
3. Announce: "Implementation complete"
Activation: Only when .ai-context.md or architecture.md exists (track-level or project-level).
If the implementation diff for a task exceeds ~200 lines:
feat(<track_id>): <task description> (chunk N)This prevents large, unreviewable code drops. Each chunk should be a coherent, reviewable unit.
Iron Law: Every completed task gets its own commit. No batching. No skipping.
After completing each task:
Quick robustness scan (30-second check before committing):
Commit FIRST (REQUIRED - non-negotiable):
git add .)git add <specific files>git diff --cached --quiet. If nothing staged, skip the commit step.git commit -m "type(<track_id>): task description" (Conventional Commits — see core/shared/vcs-commands.md)spec.md, reference it in the commit body: Refs: <JIRA_ID>.git rev-parse --short HEADUpdate plan.md:
[ ] to [x] for the completed task[x] Task description (abc1234)Update metadata.json:
tasks.completedupdated timestampVerify state updates (CRITICAL):
plan.md - confirm task marked [x] with SHAmetadata.json - confirm tasks.completed incremented[!] Blocked in plan.md[x], update metadata.json tasks.completed to Y"If .ai-context.md or architecture.md exists for the track:
[ ] → [~] when first task in module starts, [~] → [x] when all tasks complete)draft/.ai-context.md: also update YAML frontmatter git.commit and git.commit_message to current HEAD. Update draft/architecture.md with structural changes, then run the Condensation Subroutine (defined in core/shared/condensation.md) to regenerate draft/.ai-context.md.Iron Law: No completion claims without fresh verification evidence.
Before marking ANY task/phase/track complete:
[~], state actual status[x]Red Flags - STOP if you're thinking:
[x] without fresh evidence from this sessionWhen all tasks in a phase are [x]:
Stage 1: Automated Validation
npm audit for JS, bandit for Python, cargo audit for Rust).Stage 2: Spec Compliance (only if Stage 1 passes)
spec.mdStage 3: Code Quality (only if Stage 2 passes)
See core/agents/reviewer.md for detailed review process.
At phase boundaries, offer the lightweight alternative:
"Phase {N} complete. Review options:
1. Full three-stage review (recommended) — spec compliance + security + quality
2. /draft:quick-review — lightweight 4-dimension check (faster)
Choose [1/2, default: 1]:"
If quick-review chosen, invoke /draft:quick-review with the phase's changed files.
metadata.json phases.completedAfter a phase passes review, refresh metadata.json.impact so future tracks can detect overlap with this work.
Compute touched files: From plan.md, find the first commit SHA recorded for this track (earliest [x] line with (<sha>)). Run:
git diff --name-only <first_sha>^..HEAD
That is the files_touched list. Derive modules_touched as the unique top-level path segments (e.g. auth/login.go → auth).
Compute downstream blast radius (graph-aware, optional): If draft/graph/schema.yaml exists, for each file in files_touched query:
graph --repo . --out draft/graph --query --file <path> --mode impact
Aggregate across all files: downstream_files = total unique downstream files (deduped), downstream_modules = union of affected_modules, max_depth = max across queries, by_category = sum of each query's by_category. If the graph is absent, leave these fields as zeros / empty arrays — the snapshot still records the directly-touched files.
Write metadata.json with the populated impact block and computed_at set to the current timestamp.
This snapshot is consumed by /draft:new-track to surface overlap warnings when a new track touches the same modules as a recently completed track.
When all phases complete:
Run review (if enabled):
draft/workflow.md review configuration## Review Settings
- [x] Auto-review at track completion
/draft:review track <track_id>Update plan.md status to [x] Completed
Update metadata.json status to "completed"
Update draft/tracks.md:
Verify completion state consistency (CRITICAL):
plan.md - confirm status [x] Completedmetadata.json - confirm status "completed"draft/tracks.md - confirm track in Completed section with completion dateAnnounce: "Track <track_id> completed!
Summary:
[If review ran:] Review: PASS | PASS WITH NOTES | FAIL Report: draft/tracks/<track_id>/review-report-latest.md
All acceptance criteria from spec.md should be verified.
Next: Run /draft:status to see project overview."
If blocked:
[!] Blockedcore/agents/debugger.md)
Recommended: Instead of inline debugging, invoke /draft:debug skill for a structured session:
"Task blocked: {description}. Run /draft:debug for structured investigation? [Y/n]"
The debug skill provides: Reproduce → Isolate → Diagnose → Fix methodology with debug report output.
If test fails unexpectedly:
If unsure about implementation:
During implementation, track technical debt decisions in the track's plan.md:
When you encounter a shortcut, workaround, or known-imperfect solution during implementation:
## Tech Debt section at the bottom of plan.md## Tech Debt
| ID | Location | Description | Severity | Payback Trigger |
|----|----------|-------------|----------|-----------------|
| TD-1 | `src/api/handler.ts:45` | Hardcoded timeout instead of config | Low | When adding config system |
| TD-2 | `src/auth/session.ts:12` | In-memory session store | Medium | Before horizontal scaling |
Severity levels:
Payback Trigger — The condition or event that should trigger debt repayment (e.g., "before launch", "when adding feature X", "before scaling past N users").
Only log genuine debt — intentional shortcuts with known consequences. Not everything imperfect is debt.
After each task, report:
Task: [description]
Status: Complete
Phase Progress: N/M tasks
Overall: X% complete
After announcing track completion, suggest relevant follow-ups based on context:
If track modifies production code:
"Track complete! Consider:
→ /draft:deploy-checklist — Pre-deployment verification"
If track added new APIs/services/components:
→ /draft:documentation — Update documentation for new components"
If implementation contains TODO/FIXME/HACK comments:
→ /draft:tech-debt — Catalog any new technical debt introduced"
If new patterns or dependencies not in tech-stack.md:
→ /draft:adr — Document this design decision"
If Jira ticket linked, sync via core/shared/jira-sync.md:
If implementing a bug track and draft/tracks/<id>/rca.md exists: