spec-init
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesespec-init
spec-init
概览
Overview
spec-init{num}-{short-name}.aisdlc/specs/{num}-{short-name}/requirements/raw.mdspec-init{num}-{short-name}.aisdlc/specs/{num}-{short-name}/requirements/raw.md何时使用 / 不使用
When to Use / Not to Use
- 使用时机
- 用户要开始一个“新需求”的 Spec(还没有 分支与
{num}-{short-name}目录)。.aisdlc/specs/... - 用户只给了中文需求文本(不方便先手动建文件),担心参数编码导致乱码。
- 需要确保分支命名、编号来源、目录结构与后续命令(如 )一致。
spec-product-clarify
- 用户要开始一个“新需求”的 Spec(还没有
- 不要用在
- 已经在一个合法的 spec 分支上,且
{num}-{short-name}已存在并结构完整(这时直接进入后续命令)。.aisdlc/specs/{num}-{short-name}/
- 已经在一个合法的
- Use Cases
- You are starting a Spec for a "new requirement" (no branch or
{num}-{short-name}directory exists yet)..aisdlc/specs/... - You only have Chinese requirement text (it's inconvenient to manually create files first) and are worried about garbled characters caused by parameter encoding.
- You need to ensure consistency between branch naming, numbering source, directory structure, and subsequent commands (such as ).
spec-product-clarify
- You are starting a Spec for a "new requirement" (no
- Do Not Use When
- You are already on a valid spec branch, and the
{num}-{short-name}directory already exists with a complete structure (proceed directly to subsequent commands in this case)..aisdlc/specs/{num}-{short-name}/
- You are already on a valid
快速参考
Quick Reference
- 分支命名:(
{num}-{short-name}为三位数字;num为 kebab-case,小写字母/数字/连字符)short-name - 统一输出位置:
.aisdlc/specs/{num}-{short-name}/ - 必备子目录:、
requirements/、design/、implementation/、verification/release/ - 初始文件:(内容=原始需求;编码=UTF-8 with BOM)
requirements/raw.md - 脚本入口:的
spec-create-branch.ps1Main - 脚本参数
- (必需)
-ShortName - (必需,必须是文件路径)
-SourceFilePath - (可选)
-Title
- 关键副作用:脚本执行成功后会删除 指向的源文件(无论是原始文件还是临时文件)。
SourceFilePath
- Branch Naming: (
{num}-{short-name}is a three-digit number;numis in kebab-case, using lowercase letters/numbers/hyphens)short-name - Unified Output Location:
.aisdlc/specs/{num}-{short-name}/ - Required Subdirectories: ,
requirements/,design/,implementation/,verification/release/ - Initial File: (content = original requirements; encoding = UTF-8 with BOM)
requirements/raw.md - Script Entry Point: in
Mainspec-create-branch.ps1 - Script Parameters
- (required)
-ShortName - (required, must be a file path)
-SourceFilePath - (optional)
-Title
- Key Side Effect: The source file pointed to by will be deleted after the script executes successfully (whether it's an original file or a temporary file).
SourceFilePath
实施步骤(Agent 行为规范)
Implementation Steps (Agent Behavior Specifications)
0) 预检(不要跳过)
0) Pre-Check (Do Not Skip)
- 确认当前工作目录在目标 Git 仓库内(能成功)。
git rev-parse --show-toplevel - 确认 PowerShell 版本满足脚本要求(脚本声明 )。
#Requires -Version 7.0 - 如果用户提供的是“文件路径”,提醒:该文件会被脚本删除;如需保留,先复制一份再传入。
- Confirm that the current working directory is within the target Git repository (executes successfully).
git rev-parse --show-toplevel - Confirm that the PowerShell version meets the script requirements (the script declares ).
#Requires -Version 7.0 - If the user provides a "file path", remind them: this file will be deleted by the script; if you need to keep it, make a copy before passing it in.
1) 解析用户输入 → 一律落到文件路径
1) Parse User Input → Always Use File Path
强制规则:始终以文件路径方式传入需求内容(避免中文内容在参数传递/编码上出问题)。
- 输入是文件路径:直接用该路径作为 (但要提示“会被删除”)。
$sourceFilePath - 输入是文本:创建临时文件并用 UTF-8 with BOM 写入,然后把临时文件路径作为 。
$sourceFilePath
PowerShell 模板(文本 → BOM 临时文件):
powershell
$raw = @"
为现有后台系统新增‘批量导出订单’功能:支持按时间范围/状态筛选、CSV 与 XLSX 两种格式、导出任务异步执行并在导出中心可下载,权限仅管理员可见。
"@
$utf8Bom = [System.Text.UTF8Encoding]::new($true)
$tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("sdlc-raw-{0}.md" -f ([guid]::NewGuid().ToString("N")))
[System.IO.File]::WriteAllText($tmp, $raw, $utf8Bom)
$sourceFilePath = $tmpMandatory Rule: Always pass requirement content via a file path (to avoid issues with Chinese content in parameter passing/encoding).
- Input is a file path: Directly use this path as (but prompt "will be deleted").
$sourceFilePath - Input is text: Create a temporary file and write to it using UTF-8 with BOM, then use the temporary file path as .
$sourceFilePath
PowerShell Template (Text → BOM Temporary File):
powershell
$raw = @"
为现有后台系统新增‘批量导出订单’功能:支持按时间范围/状态筛选、CSV 与 XLSX 两种格式、导出任务异步执行并在导出中心可下载,权限仅管理员可见。
"@
$utf8Bom = [System.Text.UTF8Encoding]::new($true)
$tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("sdlc-raw-{0}.md" -f ([guid]::NewGuid().ToString("N")))
[System.IO.File]::WriteAllText($tmp, $raw, $utf8Bom)
$sourceFilePath = $tmp2) 生成 short-name
(2-4 词,kebab-case)
short-name2) Generate short-name
(2-4 Words, Kebab-Case)
short-name从原始需求提炼 2-4 个词的短名称,优先“动词-名词”,保留常见技术缩写(如 、、):
oauth2jwtapi- 示例:批量导出订单 + 异步任务 → 或
export-orders-batchadd-order-export - 若不确定,宁可更通用、更短:
export-orders
Extract a 2-4 word short name from the original requirements, prioritize "verb-noun" structure, and retain common technical abbreviations (e.g., , , ):
oauth2jwtapi- Example: Batch export orders + asynchronous task → or
export-orders-batchadd-order-export - If unsure, use a more general, shorter name:
export-orders
3) 调用脚本创建分支与 Spec Pack
3) Call Script to Create Branch and Spec Pack
必须用 dot sourcing 加载脚本并调用 ,不要直接运行脚本文件。
Mainpowershell
$repoRoot = (git rev-parse --show-toplevel)
. (Join-Path $repoRoot "skills\spec-init\spec-create-branch.ps1")
$shortName = "export-orders"
$title = ""
$result = Main -ShortName $shortName -SourceFilePath $sourceFilePath -Title $title
$resultYou must load the script using dot sourcing and call ; do not run the script file directly.
Mainpowershell
$repoRoot = (git rev-parse --show-toplevel)
. (Join-Path $repoRoot "skills\spec-init\spec-create-branch.ps1")
$shortName = "export-orders"
$title = ""
$result = Main -ShortName $shortName -SourceFilePath $sourceFilePath -Title $title
$result4) 验收(DoD)
4) Acceptance Criteria (DoD)
检查以下事实是否同时成立(缺一不可):
- 当前分支名等于 ,且符合
$result.branchName。{num}-{short-name} - 存在,且包含 5 个必需子目录。
.aisdlc/specs/$($result.branchName)/ - 存在,内容等于原始需求,且为 UTF-8 with BOM。
.aisdlc/specs/$($result.branchName)/requirements/raw.md - 指向的源文件已被删除(这不是 bug;若用户需要保留,应在步骤 1 之前自行备份)。
$sourceFilePath
如需对 的 BOM 做显式校验,可用下面片段检查前三个字节是否为 :
raw.mdEF BB BFpowershell
$repoRoot = (git rev-parse --show-toplevel)
$rawPath = (Join-Path $repoRoot ".aisdlc\specs\$($result.branchName)\requirements\raw.md")
$bytes = [System.IO.File]::ReadAllBytes((Resolve-Path $rawPath))
($bytes.Length -ge 3) -and ($bytes[0] -eq 0xEF) -and ($bytes[1] -eq 0xBB) -and ($bytes[2] -eq 0xBF)Verify that all of the following are true (none can be missing):
- The current branch name equals and conforms to
$result.branchName.{num}-{short-name} - exists and contains the 5 required subdirectories.
.aisdlc/specs/$($result.branchName)/ - exists, its content matches the original requirements, and it is encoded in UTF-8 with BOM.
.aisdlc/specs/$($result.branchName)/requirements/raw.md - The source file pointed to by has been deleted (this is not a bug; if the user needs to keep it, they should back it up before step 1).
$sourceFilePath
If you need to explicitly verify the BOM of , use the following snippet to check if the first three bytes are :
raw.mdEF BB BFpowershell
$repoRoot = (git rev-parse --show-toplevel)
$rawPath = (Join-Path $repoRoot ".aisdlc\specs\$($result.branchName)\requirements\raw.md")
$bytes = [System.IO.File]::ReadAllBytes((Resolve-Path $rawPath))
($bytes.Length -ge 3) -and ($bytes[0] -eq 0xEF) -and ($bytes[1] -eq 0xBB) -and ($bytes[2] -eq 0xBF)5) 完成后:自动进入 spec-product-clarify
(R1)
spec-product-clarify5) After Completion: Automatically Proceed to spec-product-clarify
(R1)
spec-product-clarify强制衔接规则: 的 DoD 通过后,不要停在“提示下一步”,而是立刻进入 R1(澄清 + 方案对比 + 推荐决策),直到产出 或用户明确停止。
spec-initrequirements/solution.mdMandatory Transition Rule: After the DoD of is met, do not stop at "prompt for next steps"; instead, immediately proceed to R1 (clarification + solution comparison + recommended decision) until is produced or the user explicitly stops.
spec-initrequirements/solution.md5.1 先过门禁:定位 FEATURE_DIR
(必须)
FEATURE_DIR5.1 First, Pass the Gate: Locate FEATURE_DIR
(Mandatory)
FEATURE_DIR禁止手写/猜路径;必须以.aisdlc/specs/...的输出为准。spec-context
powershell
$repoRoot = (git rev-parse --show-toplevel)
. (Join-Path $repoRoot "skills\spec-context\spec-common.ps1")
$context = Get-SpecContext
$FEATURE_DIR = $context.FEATURE_DIR
Write-Host "FEATURE_DIR=$FEATURE_DIR"若上面报错 → 立刻停止(不要继续生成/写任何 内容)。
requirements/*.mdDo not manually write/guess thepath; must use the output of.aisdlc/specs/....spec-context
powershell
$repoRoot = (git rev-parse --show-toplevel)
. (Join-Path $repoRoot "skills\spec-context\spec-common.ps1")
$context = Get-SpecContext
$FEATURE_DIR = $context.FEATURE_DIR
Write-Host "FEATURE_DIR=$FEATURE_DIR"If the above code throws an error → Stop immediately (do not continue generating/writing any content).
requirements/*.md5.2 进入 R1:按 spec-product-clarify
的“一次一问 + 增量回写”推进
spec-product-clarify5.2 Proceed to R1: Follow spec-product-clarify
's "One Question at a Time + Incremental Rewrite" Approach
spec-product-clarify从这里开始,严格按 执行(无需重复发明流程),最小闭环如下:
spec-product-clarify- 读取:
$FEATURE_DIR/requirements/raw.md - 立刻发起第 1 个澄清问题:只问 1 个最高杠杆未知,优先做成 2–4 选项的选择题(带“其他/不确定”兜底 + 你的推荐项与理由)
- 用户回答后必须增量回写:追加到 的
$FEATURE_DIR/requirements/raw.md## 澄清记录 - 停止条件满足后生成:(结论摘要 / 推荐方案 / 2–3 备选 / 决策依据 / 验证清单 / 迭代记录)
$FEATURE_DIR/requirements/solution.md
关键禁令:不写“待确认问题清单”;所有不确定性统一进入的“验证清单”(Owner/截止/信号/动作)。solution.md
From this point, strictly follow (no need to reinvent the process); the minimum closed loop is as follows:
spec-product-clarify- Read:
$FEATURE_DIR/requirements/raw.md - Immediately Initiate the 1st Clarification Question: Only ask 1 highest-leverage unknown, preferably as a multiple-choice question with 2–4 options (with "Other/Unsure" fallback + your recommended option and rationale)
- After User Answers, Must Incrementally Rewrite: Append to the section in
## Clarification Records$FEATURE_DIR/requirements/raw.md - Generate When Stop Conditions Are Met: (conclusion summary / recommended solution / 2–3 alternatives / decision basis / verification checklist / iteration records)
$FEATURE_DIR/requirements/solution.md
Key Prohibition: Do not write "pending confirmation question list"; all uncertainties should be unified into the "verification checklist" in(Owner/Deadline/Signal/Action).solution.md
常见错误(以及怎么避免)
Common Mistakes (and How to Avoid Them)
- 自创分支/目录结构:不要用 、
spec/<slug>、feature/<slug>;本仓库规范是features/<slug>+{num}-{short-name}。.aisdlc/specs/... - 把中文需求当作命令行参数直接传递:一律写入 UTF-8 BOM 文件,再传路径。
- 误以为脚本不会删源文件:它会删除 指向的文件;对用户的原始文件务必先确认是否需要备份。
SourceFilePath - 短名称不规范:避免大写、下划线、中文;避免前后连字符与连续 ;尽量 2-4 词。
--
- Creating Custom Branch/Directory Structures: Do not use ,
spec/<slug>,feature/<slug>; the repository specification isfeatures/<slug>+{num}-{short-name}..aisdlc/specs/... - Directly Passing Chinese Requirements as Command Line Parameters: Always write to a UTF-8 BOM file first, then pass the path.
- Mistakenly Believing the Script Won't Delete the Source File: It will delete the file pointed to by ; always confirm with the user whether they need to back up their original file first.
SourceFilePath - Non-Standard Short Names: Avoid uppercase letters, underscores, Chinese characters; avoid leading/trailing hyphens and consecutive ; aim for 2-4 words.
--