Skip to content

Self-Improving Specs

Specs are living documents. As your project evolves — new features implemented, constitution updated, lessons learned — the refinement system detects gaps and suggests improvements.

How It Works

The Refinement Command

Command: /speckit.refine

Reviews specs and presents auto-generated improvement suggestions.

bash
/speckit.refine

What It Detects

Gap Detection

Compares spec complexity against implementation complexity. Flags specs that are thin relative to what was actually built.

Example: Spec says "handle errors" but the implementation has 15 distinct error paths. The refinement engine suggests expanding the error handling section with the actual paths.

Staleness Detection

Flags specs whose linked code has changed significantly since the last spec update.

Example: The data model spec describes 5 tables, but the implementation now has 8. The engine flags the 3 new tables as missing from the spec.

Consistency Propagation

When the constitution is updated, checks all existing specs for potential violations of the new or changed principles.

Example: A new constitution principle requires all API endpoints to have rate limiting. The engine scans specs for API definitions that don't mention rate limits.

Interactive Review

The refine command presents suggestions grouped by spec. For each suggestion, you can:

  • Accept — Apply the improvement to the spec
  • Reject — Skip this suggestion
  • Modify — Edit the suggestion before applying

Suggestions are never applied automatically.

Quality Scoring

Each spec is scored on a 100-point rubric:

CategoryMax PointsWhat It Measures
Completeness30All template sections filled, requirements have scenarios, no TODO placeholders
Consistency25Aligns with constitution, no conflicting artifacts, consistent terminology
Testability25All requirements have GIVEN/WHEN/THEN scenarios, measurable acceptance criteria
Clarity20No vague adjectives without metrics, no ambiguous terms, clear language
Total100

Ratings: Excellent (90+) | Good (80+) | Fair (70+) | Poor (<70)

Spec Maturity Tracking

Every spec has a maturity level that evolves over time:

LevelMeaningHow to Reach
draftInitial creationRun /speckit.specify
refinedGaps filled, clarifiedRun /speckit.clarify + /speckit.refine
validatedQuality score 80+Run /speckit.analyze with passing score
implementedCode generated and testedRun /speckit.implement
evolvedUpdated from implementation learningsRun /speckit.refine after implementation

Tracked in spec frontmatter:

markdown
<!-- maturity: refined -->
<!-- last_refined: 2026-02-24 -->
<!-- refinement_count: 3 -->
<!-- knowledge_coverage: 78% -->

knowledge_coverage tracks what percentage of spec sections are backed by implementation artifacts.

Constitution Learning Loop

The constitution also evolves. After implementation cycles, the /speckit.constitution command can:

  1. Analyze patterns — Scan the last 3 implemented features for recurring decisions
  2. Detect overrides — Find patterns where constitution principles were frequently worked around
  3. Suggest new principles — Based on patterns that should be codified
  4. Propagate changes — Flag specs that may violate updated principles

Example Learning Flow

text
1. Team implements 3 features
2. All 3 implementations add retry logic to API calls
3. Constitution command detects pattern
4. Suggests new principle: "All external API calls MUST implement retry with exponential backoff"
5. User approves → constitution updated
6. Refinement engine flags existing specs missing retry requirements

Refinement Suggestions File

Auto-generated suggestions are stored in .specify/memory/refinement-suggestions.md. This file is read by /speckit.refine and cleared as suggestions are processed.

Format:

markdown
## Suggestions for 001-user-auth

### S1: Expand error handling section
- **Type:** Gap
- **Severity:** Medium
- **Current:** "Handle authentication errors"
- **Suggested:** Add specific error paths: expired token, invalid credentials, account locked, rate limited, MFA required
- **Reason:** Implementation has 6 error paths, spec only mentions 1

### S2: Add rate limiting requirement
- **Type:** Constitution alignment
- **Severity:** High
- **Principle:** Article X — API Rate Limiting
- **Suggested:** Add non-functional requirement for rate limiting on login endpoint

Integration with Other Commands

CommandRelationship
/speckit.analyzePre-implementation quality check — identifies issues before building
/speckit.refinePost-implementation improvement — learns from what was actually built
/speckit.constitutionPrinciple evolution — detects patterns and suggests new rules
/speckit.levelupTeam learning — captures conventions that feed back into refinements

Released under the MIT License.