Sub topic 3
The spec-driven workflow: requirements, design, tasks, implementation
This chapter assumes you can write code in at least one language, use Git, have prompted an AI coding assistant before, and know basic automated testing. It walks through the four phases of the workflow. Later chapters cover each phase in more detail.
The working model
Spec-driven development splits a change into phases. Each phase produces a file that you review before the next phase starts. The agent reads those files as its context, so its work is anchored to something you have approved.
| Phase | Question it answers | Artifact | Who decides |
|---|---|---|---|
| Requirements | What should the system do? | `requirements.md` | You |
| Design | How will it do that? | `design.md` | You, with the agent's proposal |
| Tasks | In what order do we build it? | `tasks.md` | You approve, the agent drafts |
| Implementation | Is it built and does it pass? | Code and tests | The agent, checked by you |
The agent can draft any of these files. The human approves each one. An error that survives into a later phase costs more to fix, so each approval is a gate.
Phase by phase
Requirements
Requirements describe observable behavior, not code. Each one has a user story and acceptance criteria that you can test. Here is a short example for a password reset feature.
### Requirement 1: Password reset
**User story:** As a registered user, I want to reset my password by email, so that I can regain access to my account.
#### Acceptance criteria
1. WHEN a user submits a registered email address THEN the system SHALL send a reset link that expires after 30 minutes.
2. WHEN a user submits an unregistered email address THEN the system SHALL return the same response as for a registered address.
3. IF a reset link has already been used THEN the system SHALL reject any further use of that link.Criterion 2 is a decision the agent would otherwise make silently. It prevents the endpoint from revealing which emails have accounts. Writing it down is the point of this phase.
Design
The design document records how the requirements will be met: components, data, interfaces, error handling, and the trade-offs you chose. For this feature it might say that tokens are stored with an issue time and a used flag, and that the endpoint always returns the same message. The agent should propose the design from the approved requirements. You then correct it before any code exists.
Tasks
Tasks turn the design into small steps. Each task is ordered, can be verified on its own, and names the requirement it covers.
## Tasks
- [ ] 1. Add a reset token store
- Store the token, its issue time, and a used flag.
- Covers: Requirement 1.1, 1.3
- [ ] 2. Implement token redemption
- Reject expired tokens and tokens that were already used.
- Write tests first. Covers: Requirement 1.1, 1.3
- [ ] 3. Add the reset-request endpoint
- Return the same response for registered and unregistered emails.
- Covers: Requirement 1.2The Covers: lines make review simple. Any requirement that no task covers is a gap. Any task that covers no requirement is probably scope creep.
Implementation
You ask the agent to execute one task, then stop. You review the diff, run the tests, and tick the box. Then you start the next task. Running the whole list in one go removes the gates that make the workflow useful.
Common errors
- Skipping to tasks. Without approved requirements, the agent invents behavior and the task list inherits it.
- Approving without reading. A generated spec can look complete and still contain wrong assumptions. Read the acceptance criteria as if you were writing the tests.
- Letting the agent edit requirements. If implementation reveals a flaw, the agent should report it. You change the requirement, then update the design and tasks that depend on it.
- Tasks that are too large. A task you cannot review in one sitting is too big to verify.
Exercise
A reviewer finds that no task in tasks.md mentions Requirement 1.2. What does this tell you, and what should you do before implementation starts?
Show answer
It shows a gap: nothing in the plan will build or check that behavior (same response for unregistered emails). Add a task that covers Requirement 1.2, such as the reset-request endpoint, and get the task list approved again before the agent begins implementation.
Exercise
During task 2 the agent suggests that tokens should expire after 15 minutes instead of 30. Which file do you change first, and why?
Show answer
Change requirements.md, because the 30-minute limit is stated in acceptance criterion 1.1. Then update the design and any task that mentions the expiry. Changing only the code would leave the spec and the code in conflict.