Code Generation Skill
Core Principle: Story-Driven, Not Vibe-Driven
Every line of code traces back to a user story. No speculative features.
Story → Read Architecture → Write Code → Write Tests → Code Review → Done
The Six Quality Principles
Reference: "AI is forcing us to write good code" (Steve Krenzel)
For decades, we've known what good code looks like: thorough tests, clear documentation, small well-scoped modules, static typing, and reproducible dev environments. AI agents need these — they aren't great at making a mess and cleaning it up later. The only guardrails are the ones you set and enforce.
- Small, Well-Scoped Modules — one file = one responsibility. No
utils/helpers.py.
- Static Typing Everywhere — type-annotate all functions. Zero
any in TypeScript.
- Functions Under 50 Lines — decompose long functions into named subfunctions.
- Explicit Error Handling — typed error classes, no bare exceptions.
- No Dead Code — every line traces to a story. Delete, don't comment out.
- Self-Documenting — good names > comments. Types as primary documentation.
For detailed patterns and examples, see references/quality-principles.md.
Implementation Workflow
For each story:
- Read the story's acceptance criteria and layer assignment.
- Read architecture:
api-contracts.md, data-models.md, folder-structure.md.
- Write implementation code first, following patterns in references/patterns.md.
- Write unit tests for 100% meaningful coverage — see references/testing-rules.md.
- Run verification:
uv run pytest -x -q, uv run ruff check ., uv run mypy src/.
- Submit for code review.
Parallel Execution via Agent Teams
For independent stories (same parallel group):
- Read
dependency-graph.md to identify the parallel group.
- Create an agent team with one teammate per story.
- Each teammate owns distinct files — no overlapping edits.
- Require plan approval before teammates write code.
- Teammates communicate via agent team messaging about shared interfaces.
- After all teammates complete, run the full test suite.
For examples, see examples/agent-team-setup.md.
Code Review Gate
After implementation, the code-reviewer agent reviews all changes. See the review skill. All BLOCK findings must be resolved before the story is done.
Gotchas
These are common failure modes — check for them before marking code as done:
- Importing upward in layers. Service importing from API, or Repository importing from Service. Always check:
grep -rn "from src.api" src/service/ src/repository/.
- Functions creeping past 50 lines. It happens gradually. Count lines after writing — if over 50, split immediately.
any types sneaking into TypeScript. Especially in API response handling. Use unknown + type guards instead.
- Bare
except Exception: in Python. Always catch specific typed errors. If you're unsure which, that means the error types aren't defined yet — define them first.
- Mocking business logic in tests. Only mock external boundaries (DB, APIs, file I/O). If you're mocking a function in
src/service/, something is wrong.
- Test data like "test123" or "foo@bar.com". Use realistic data: "Sarah Chen", "sarah.chen@horizonequity.com", "$2,500,000".
- Writing code before reading the story. Every time. Read acceptance criteria first.
- Commented-out code blocks. Git remembers. Delete the code, don't comment it.
- Missing error path tests. If a function can throw, there must be a test that triggers that throw.
- Agent teammates editing the same file. Always verify file ownership in the plan before approving.
Additional Resources
- references/quality-principles.md — detailed rules and examples for each quality principle
- references/patterns.md — Python and TypeScript implementation patterns
- references/testing-rules.md — testing rules, coverage targets, mock boundaries
- examples/agent-team-setup.md — agent team configuration examples
Verification
After every story:
uv run pytest -x -q --cov=src --cov-report=term-missing
uv run ruff check .
uv run mypy src/
npm test -- --coverage
npm run lint
npm run typecheck
1---2name: code-gen-33description: Story-driven code generation with strict quality principles. Use when implementing user stories, writing production code, creating unit tests, or generating code from specs. Enforces small modules, static typing, 50-line function limit, and 100% meaningful test coverage.4---56# Code Generation Skill78## Core Principle: Story-Driven, Not Vibe-Driven910Every line of code traces back to a user story. No speculative features.1112```13Story → Read Architecture → Write Code → Write Tests → Code Review → Done14```1516## The Six Quality Principles1718Reference: "AI is forcing us to write good code" (Steve Krenzel)1920For decades, we've known what good code looks like: thorough tests, clear documentation, small well-scoped modules, static typing, and reproducible dev environments. AI agents need these — they aren't great at making a mess and cleaning it up later. The only guardrails are the ones you set and enforce.21221. **Small, Well-Scoped Modules** — one file = one responsibility. No `utils/helpers.py`.232. **Static Typing Everywhere** — type-annotate all functions. Zero `any` in TypeScript.243. **Functions Under 50 Lines** — decompose long functions into named subfunctions.254. **Explicit Error Handling** — typed error classes, no bare exceptions.265. **No Dead Code** — every line traces to a story. Delete, don't comment out.276. **Self-Documenting** — good names > comments. Types as primary documentation.2829For detailed patterns and examples, see [references/quality-principles.md](references/quality-principles.md).3031## Implementation Workflow3233For each story:341. Read the story's acceptance criteria and layer assignment.352. Read architecture: `api-contracts.md`, `data-models.md`, `folder-structure.md`.363. Write implementation code first, following patterns in [references/patterns.md](references/patterns.md).374. Write unit tests for 100% meaningful coverage — see [references/testing-rules.md](references/testing-rules.md).385. Run verification: `uv run pytest -x -q`, `uv run ruff check .`, `uv run mypy src/`.396. Submit for code review.4041## Parallel Execution via Agent Teams4243For independent stories (same parallel group):441. Read `dependency-graph.md` to identify the parallel group.452. Create an agent team with one teammate per story.463. Each teammate owns distinct files — no overlapping edits.474. Require plan approval before teammates write code.485. Teammates communicate via agent team messaging about shared interfaces.496. After all teammates complete, run the full test suite.5051For examples, see [examples/agent-team-setup.md](examples/agent-team-setup.md).5253## Code Review Gate5455After implementation, the `code-reviewer` agent reviews all changes. See the `review` skill. All BLOCK findings must be resolved before the story is done.5657## Gotchas5859These are common failure modes — check for them before marking code as done:6061- **Importing upward in layers.** Service importing from API, or Repository importing from Service. Always check: `grep -rn "from src.api" src/service/ src/repository/`.62- **Functions creeping past 50 lines.** It happens gradually. Count lines after writing — if over 50, split immediately.63- **`any` types sneaking into TypeScript.** Especially in API response handling. Use `unknown` + type guards instead.64- **Bare `except Exception:` in Python.** Always catch specific typed errors. If you're unsure which, that means the error types aren't defined yet — define them first.65- **Mocking business logic in tests.** Only mock external boundaries (DB, APIs, file I/O). If you're mocking a function in `src/service/`, something is wrong.66- **Test data like "test123" or "foo@bar.com".** Use realistic data: "Sarah Chen", "sarah.chen@horizonequity.com", "$2,500,000".67- **Writing code before reading the story.** Every time. Read acceptance criteria first.68- **Commented-out code blocks.** Git remembers. Delete the code, don't comment it.69- **Missing error path tests.** If a function can throw, there must be a test that triggers that throw.70- **Agent teammates editing the same file.** Always verify file ownership in the plan before approving.7172## Additional Resources7374- [references/quality-principles.md](references/quality-principles.md) — detailed rules and examples for each quality principle75- [references/patterns.md](references/patterns.md) — Python and TypeScript implementation patterns76- [references/testing-rules.md](references/testing-rules.md) — testing rules, coverage targets, mock boundaries77- [examples/agent-team-setup.md](examples/agent-team-setup.md) — agent team configuration examples7879## Verification8081After every story:82```bash83uv run pytest -x -q --cov=src --cov-report=term-missing84uv run ruff check .85uv run mypy src/86npm test -- --coverage87npm run lint88npm run typecheck89```