【AI Coding】Spec-Kit

GitHub 官方的规范驱动开发工具

Spec-Kit 是 GitHub 官方出品的 AI 编程工作流工具,由 Den Delimarsky 和 John Lam 等核心开发者维护。

核心定位

Spec-Driven Development flips the script on traditional software development. Specifications become executable, directly generating working implementations rather than just guiding them.

规范不只是"指导文档",而是 可执行的——能直接生成工作代码。

七个阶段(阶段门控式)

constitution → specify → clarify → plan → tasks → analyze → implement
     ↓            ↓         ↓        ↓       ↓        ↓         ↓
   [门控]      [门控]    [门控]   [门控]  [门控]   [门控]    [门控]
阶段 说明
constitution 项目治理 - 定义项目的基本规则和约束
specify 定义需求 - 编写功能规范
clarify 澄清模糊 - 消除规范中的歧义
plan 技术计划 - 制定实现方案
tasks 任务分解 - 将计划拆分为可执行任务
analyze 一致性检查 - 验证任务与规范的一致性
implement 执行实现 - 生成代码

每个阶段都有明确的输入输出,像工厂流水线一样。

技术架构

┌─────────────────────────────────────────────┐
│              Specify CLI (Python)            │
├─────────────────────────────────────────────┤
│  Templates  │  Extensions  │  Presets       │
├─────────────────────────────────────────────┤
│         AI Agent Integration Layer          │
│  Claude │ Copilot │ Cursor │ Gemini │ ...  │
└─────────────────────────────────────────────┘
  • 基础:基于 Python,使用 uv 作为包管理器
  • 核心:模板引擎 + 扩展系统
  • 机制:规范通过模板渲染成代码,扩展系统允许自定义工作流

安装与使用

安装

uv tool install specify-cli --from git+https://github.com/github/spec-kit.git

初始化项目

specify init my-project

定义规范

创建 .specify/specs/features/login.md

# User Login Feature

## User Story
As a user, I want to log in to access my account.

## Acceptance Criteria
- User can enter email and password
- System validates credentials
- User receives error message for invalid credentials
- Successful login redirects to dashboard

## Technical Constraints
- Use JWT for session management
- Password must be hashed with bcrypt

执行规范

# 通过 AI 代理调用
/speckit.implement

Spec-Kit 会自动解析规范,生成计划,分解任务,然后执行实现。

适用场景

场景 推荐度 原因
大型企业项目 ✅ 强烈推荐 GitHub 官方维护、阶段门控确保质量可控、企业级团队功能成熟
需要规范生成代码 ✅ 强烈推荐 规范可执行化是核心定位、模板引擎支持代码生成
快速迭代项目 ⚠️ 不推荐 阶段门较严格,不适合频繁调整方向
个人小项目 ⚠️ 不推荐 相对重量级,学习曲线较陡

局限性

  • 相对重量级:需要 Python 3.11+ 和 uv,环境配置有一定门槛
  • 阶段门较严格:不适合需要频繁调整方向的项目
  • 学习曲线较陡:七个阶段需要时间理解

与其他工具对比

维度 Spec-Kit [[OpenSpec]] [[Superpowers]]
核心范式 规范可执行化 轻量规范层 技能组合
工作流 阶段门控式 流畅迭代式 技能触发式
TDD 强制
Brownfield 支持 ✅ 优先设计

相关资源

  • GitHub: https://github.com/github/spec-kit
  • [[AI 编程工作流对比]] - 三种工具的详细对比
  • [[OpenSpec 规格驱动开发工作流]] - 轻量级替代方案