安装

前提条件

  • 需要具备uv

安装方式

  • 方式一:
brew install uv
  • 方式二:
curl -LsSf https://astral.sh/uv/install.sh | sh

使用

缺点:太耗token了

安装

使用下面命令进行安装spec-kit

uv tool install specify-cli --from git+https://github.com/github/spec-kit.git
  • 可能会出现执行的bin目录找不到:
warning: `/Users/panape/.local/bin` is not on your PATH. To use installed tools, run `export PATH="/Users/panapechen/.local/bin:$PATH"` or `uv tool update-shell`.
  • 在bash_profile进行进行添加:
# path 添加上specify相关的目录
export PATH="/Users/panape/.local/bin:$PATH"
# 然后执行source命令,是的配置生效
source .bash_profile

相关命令

流程命令

阶段 主要文件 目的
宪法(Constitution) .specify/memory/constitution.md 项目全局指导原则
规范(Specification) specs/<feature>/spec.md 功能需求和用户故事
澄清(Clarifications) specs/<feature>/spec.md (澄清部分) 解决规范歧义
计划(Plan) specs/<feature>/plan.md 技术栈、架构和数据模型
研究(Research) specs/<feature>/research.md 技术栈特定调查
任务(Tasks) specs/<feature>/tasks.md 有序实施步骤、并行标记和文件路径
实施(Implementation) 生成的代码文件 生产就绪代码

核心命令

命令 描述 用法示例
init 初始化项目,创建 .specifytemplatesscripts 等目录结构。 specify init
check 检查所需 AI 代理工具是否就位。 specify check
/speckit.constitution 生成项目治理原则文件(constitution.md),用于指导后续决策。 在 AI 代理中输入 /speckit.constitution
/speckit.specify 编写功能规范文件(specs/<feature>/spec.md),捕获需求和用户故事。 在 AI 代理中输入 /speckit.specify
/speckit.clarify (可选)添加澄清部分到规范,解决歧义。 在 AI 代理中输入 /speckit.clarify
/speckit.plan 生成技术计划文件(plan.md),包括架构、数据模型和研究文件。 在 AI 代理中输入 /speckit.plan
/speckit.tasks 生成有序任务列表(tasks.md),包含依赖、并行标记、文件路径和 TDD 检查点。 在 AI 代理中输入 /speckit.tasks
/speckit.implement 执行任务,运行本地 CLI 命令(如 dotnet、npm),生成代码并提交 PR。 在 AI 代理中输入 /speckit.implement
/speckit.analyze 分析规范的一致性和覆盖率。 在 AI 代理中输入 /speckit.analyze
/speckit.checklist 生成自定义质量检查清单。 在 AI 代理中输入 /speckit.checklist

详细使用

项目初始化

使用工具

# 创建一个项目
specify init project_name

# 在一个已经存在的项目中进行初始化
specify init . --ai claude
# 或者如下执行也可以
specify init --here --ai claude

# 检查并安装相关工具
specify check

# 相关的目录结构
├── memory/
│   ├── constitution.md          ← 项目宪法(AI 决策依据)
│   └── constitution_update_checklist.md
├── scripts/
│   ├── check-prerequisites.sh   ← 环境检查
│   ├── create-new-feature.sh    ← 创建新特性分支
│   └── setup-plan.sh            ← 初始化 plan 目录
├── specs/
│   └── 001-photo-albums/        ← 特性编号+名称
│       ├── spec.md              ← 功能规范
│       ├── plan.md              ← 技术方案
│       ├── tasks.md             ← 任务清单
│       ├── data-model.md        ← 数据模型
│       └── contracts/           ← API/协议定义
├── templates/
│   ├── spec-template.md
│   ├── plan-template.md
│   └── tasks-template.md
└── CLAUDE.md                    ← AI 会话上下文记录

请添加图片描述

创建项目规则

  • 注意使用spec相关命令,需要在claude下执行
    使用spec命令创建项目规则
# 英文版本
/speckit.constitution Create principles focused on code quality, testing standards, user experience consistency, and performance requirements. Include governance for how these principles should guide technical decisions and implementation choices.
# 中文版本
/speckit.constitution 创建专注于代码质量、测试标准、用户体验一致性和性能要求的原则。包括对这些原则应如何指导技术决策和实施选择的治理。
  • /speckit.constitution 创建专注于代码质量、测试标准、用户体验一致性和性能要求的原则。包括对这些原则应如何指导技术决策和实施选择的治理。
    ![请添加图片描述](https://i-blog.csdnimg.cn/direct/0b433e39986d4525b060d0624c07be56.png

描述需求

/speckit.specify @相关接口文档说明.md 请解析相关接口文档,然后实现一个桩程序:相关技术springboot3.5最新版本;jdk21;日志使用logback;需要支持高并发

  ⎿  Read 相关接口文档说明.md (361 lines)

⏺ I'll help you create a specification for implementing a stub program based on the AI interface documentation. Let me start by analyzing the requirements and creating the feature.

⏺ Bash(git fetch --all --prune)
  ⎿  (No content)

⏺ Bash(git ls-remote --heads origin 2>/dev/null | grep -oE '[0-9]+-[a-z0-9-]+$' || echo "No remote branches found")
  ⎿  No remote branches found

⏺ Bash(git branch 2>/dev/null | grep -oE '[0-9]+-[a-z0-9-]+$' || echo "No local branches found")
  ⎿  No local branches found

⏺ Bash(ls -d specs/*/ 2>/dev/null | grep -oE '[0-9]+-[a-z0-9-]+' || echo "No spec directories found")
  ⎿  No spec directories found
     (eval):1: no matches found: specs/*/

⏺ Now let me create the feature branch with the appropriate short name. Based on the requirements, I'll use "h5-liveness-stub" as the short name:

⏺ Bash(.specify/scripts/bash/create-new-feature.sh --json --number 1 --short-name "h5-liveness-stub" "实现H5实时活体检测桩程序:SpringBoot 3.5, JDK 21, Logback日志, 支持高并发")
  ⎿  Running…

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 Bash command

   .specify/scripts/bash/create-new-feature.sh --json --number 1 --short-name "h5-liveness-stub" "实现H5实时活体检测桩程序:SpringBoot 3.5, JDK 21, Logback日志, 支持高并发"
   Create new feature branch and spec

 Do you want to proceed?
   1. Yes
 ❯ 2. Yes, and don't ask again for .specify/scripts/bash/create-new-feature.sh commands in /Users/panapechen/Workspace/ai/java/qvp-stub

调整校对需求(重要!)

ai生成的文档并不是一蹴而就,需要不断地调整修复,所以需要使用到 speckit.clarify 命令

/speckit.clarify 请调整 @specs/001-h5-liveness-stub 文件,用中文
  ⎿  Listed directory specs/001-h5-liveness-stub/

⏺ I'll help you translate the specification file to Chinese and run the clarification process. Let me start by loading the current spec and understanding what needs to be clarified.

⏺ Bash(.specify/scripts/bash/check-prerequisites.sh --json --paths-only){
       "REPO_ROOT": "/Users/panapechen/Workspace/ai/java/qvp-stub",
       "BRANCH": "001-h5-liveness-stub"
  ---
  澄清问题

  基于对规格说明的分析,我发现几个可以进一步明确的领域。让我逐一提问:

  问题 1: 配置热重载机制

  推荐选项: 选项 B - 基于配置文件监听,实时生效(推荐用于开发和测试环境,提供最佳的灵活性,无需手动操作)

  当前规格说明SC-005提到"配置更改在30秒内生效,无需重启服务",但未明确配置重载的触发机制。

  | 选项  | 描述                                                              |
  |-------|-------------------------------------------------------------------|
  | A     | 手动API触发 - 提供 /admin/reload-config 端点,管理员调用以重载配置 |
  | B     | 基于配置文件监听 - 自动检测配置文件修改并重载(推荐)               |
  | C     | 定时轮询 - 每30秒检查一次配置文件是否变化                         |
  | Short | 提供不同的简短答案(≤5个词)                                        |

  您可以回复选项字母(例如"A"),通过说"yes""recommended"接受推荐,或提供您自己的简短答案。

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
> 使用配置文件appcalition.yaml 文件获取;更新重启服务即可

完美!已记录第一个澄清。现在让我继续下一个重要问题:

  问题 2: HTML和资源文件模板存储

  推荐选项: 选项 A - resources/templates目录(推荐用于SpringBoot项目,符合标准实践,便于打包和部署)

  当前规格说明SC-012提到"HTML响应模板外部化且可自定义",但未明确HTML页面及其引用的静态资源(CSS/JS)的存储位置。

  | 选项  | 描述                                                                         |
  |-------|------------------------------------------------------------------------------|
  | A     | resources/templates目录 - HTML模板和静态资源存储在src/main/resources下(推荐) |
  | B     | 外部文件目录 - 通过application.yaml配置外部路径,如/opt/qvp-stub/templates    |
  | C     | 类路径资源 - 打包在JAR内,不支持运行时修改                                    |
  | Short | 提供不同的简短答案(≤5个词)                                                   |

  您可以回复选项字母(例如"A"),通过说"yes""recommended"接受推荐,或提供您自己的简短答案。

生成技术方案(多次迭代)

当通过clarify进行不断澄清只会,便可生成相关的技术方案;

  • 注意:需要多次迭代审查,防止后续开发返工,出现问题
> /speckit.plan

⏺ I'll execute the /speckit.plan workflow to generate the implementation plan for the H5 liveness detection stub service.

⏺ Bash(.specify/scripts/bash/setup-plan.sh --json)
  ⎿  Copied plan template to /Users/panapechen/Workspace/ai/java/qvp-stub/specs/001-h5-liveness-stub/plan.md
     {
       "FEATURE_SPEC": "/Users/panapechen/Workspace/ai/java/qvp-stub/specs/001-h5-liveness-stub/spec.md",
     … +5 lines (ctrl+o to expand)

⏺ Now I'll read the plan template and constitution to begin filling it out:

创建任务

当计划和技术方案实现之后,便可执行相关的任务生成

> /speckit.tasks

⏺ I'll execute the task generation workflow for the H5实时活体检测桩服务 feature.

⏺ Bash(.specify/scripts/bash/check-prerequisites.sh --json)
  ⎿  Running…

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 Bash command

   .specify/scripts/bash/check-prerequisites.sh --json
   Check prerequisites and get feature paths

 Do you want to proceed?

开始执行任务

当任务计划创建成功,并修改满足之后,便可开始执行任务

> /speckit.implement

⏺ I'll execute the implementation workflow for the H5实时活体检测桩服务 feature.

⏺ Bash(.specify/scripts/bash/check-prerequisites.sh --json --require-tasks --include-tasks){
       "FEATURE_DIR": "/Users/panapechen/Workspace/ai/java/qvp-stub/specs/001-h5-liveness-stub",
       "AVAILABLE_DOCS": [

最终目录请添加图片描述

交互时序

本地 Shell(npm/dotnet 等) Git 仓库(分支与提交) 文件系统(.specify/specs/) AI 编码代理(Claude/Gemini/Qoder) Specify CLI(项目初始化) 用户(人类决策者) 本地 Shell(npm/dotnet 等) Git 仓库(分支与提交) 文件系统(.specify/specs/) AI 编码代理(Claude/Gemini/Qoder) Specify CLI(项目初始化) 用户(人类决策者) opt [可选:澄清歧义] 🔥 **关键关注点** 🔥 **用户必须手动审计计划** (建议多次迭代,直至完全满意) alt [执行出错(需人工干预)] loop [逐个执行任务(重点关注执行过程)] 🔥 **最终关注点** 🔥 **人工审查 PR** 确保代码与规范完全一致 specify init <项目名> --ai <agent> 创建 .specify/ 目录结构 (memory、specs、templates、scripts) 初始化 Git(可选 --no-git) 项目初始化完成 /speckit.constitution 写入 constitution.md(项目原则) /speckit.specify(描述功能需求) 创建 spec.md(功能规范、用户故事) 创建新分支 <feature-id>(隔离开发) /speckit.clarify 在 spec.md 添加 Clarifications 部分 /speckit.plan 生成 plan.md、data-model.md、research.md(技术方案) /speckit.tasks 生成 tasks.md(有序任务、[P] 并行标记) /speckit.implement 运行本地命令(构建、安装、测试) 生成/修改代码文件 提交变更(自动 commit) 流式输出错误日志 提供反馈或错误信息 自我修复并重试 (可选)创建 Pull Request 到 main(待审查)

推荐链接

  1. github spec-kit
  2. spec使用手册
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐