The problem
Coding agents fail in two well-documented ways.
- They fill gaps with guesses. A four-sentence requirement leaves dozens of boundaries open. The agent picks an answer for each one and you discover the wrong picks at acceptance.
- They edit the test instead of the code. When a test and the implementation disagree, the cheapest path to green is to change the test. The report still says "all tests pass".
Specification-driven tools such as GitHub Spec Kit and Kiro address the first problem by writing a specification before coding. The agent then derives the tests from that specification largely on its own, and nothing locks the specification or the tests while the code is written.
The approach: stepwise refinement
SpecEngine does not translate a natural-language specification into tests in one move. It refines the requirement through six levels, from the stakeholder's words down to test code. Each level is a file you can read, each answers one question, and each is checked before the next one is written.
| Level | Artifact | Question it answers | Checked by |
|---|
| 1 | Natural-language requirement | What does the stakeholder want? | Human |
| 2 | Rule matrix | Under which precondition, on which trigger, must the system do what? | Human answers every open question; feature-lint.js checks the structure |
| 3 | Flow diagrams | Do the rules together cover every branch? | Human confirms; any gap goes back to level 2 |
| 4 | Gherkin scenarios and example tables | What are the concrete cases for each rule? | feature-lint.js: one-to-one rule coverage; every example row must follow from the matrix |
| 5 | Step sentences and driver interface | Which system operation does each sentence drive? | In driver mode every @binds must point to a real driver method; sentences are frozen |
| 6 | Step implementations and product code | How is it done? | Tests go from red to green while levels 2 to 5 stay byte-for-byte unchanged |
Refining in levels gives two things a one-step translation cannot:
- Each error is caught at the level where it is made. An unclear requirement becomes a question at level 2. A missing branch shows up in the diagrams at level 3. A miscopied example fails the lint at level 4. In a one-step translation all three surface later as the same symptom, a failing test, with nothing to say which level went wrong.
- Every test line is traceable to a decision. A step implementation leads to its sentence, its scenario and its rule, and from there to the question it came from and the person who answered it.
Established theory, put into practice
None of the ideas underneath SpecEngine is new on its own. Its contribution is turning them into one working toolchain for AI coding agents.
| Idea | Source | Where it lives in SpecEngine |
|---|
| Stepwise refinement | Wirth, Program Development by Stepwise Refinement, 1971 | The six levels above |
| Preconditions and postconditions | Hoare, An Axiomatic Basis for Computer Programming, 1969 | Each rule in the matrix is a precondition, a trigger and a postcondition |
| Behaviour-driven development and specification by example | North, 2006; Adzic, 2011 | Gherkin scenarios with example tables as the executable level |
| Test-driven development | Beck, 2002 | Every test starts red; code is written until it turns green |
On top of that foundation SpecEngine adds two rules that classic refinement never needed, because its refiner was a human:
- Gaps between levels are filled only by humans. Whenever a level cannot be derived from the one above, the agent must stop and ask. Every answer is filed with the rule it produced.
- A lower level cannot rewrite a higher one. While the agent writes levels 5 and 6, a script holds levels 2 to 5 frozen. Once the module is done it is locked, and any later change must go through the change workflow.
What holds it together