关于 sdd-init
sdd-init 是用于在项目中启动规范驱动开发(SDD)的技能,面向需要梳理项目上下文并初始化规范文档的开发者。它检测技术栈、约定和架构,并处理 Constitution 与知识图谱的初始化。
主要功能
- 01检测语言、框架与工具
- 02识别项目约定和架构
- 03初始化 Constitution 文档
- 04创建或更新知识图谱
- 05保留现有内容并验证 JSON
适用场景
- 01为现有项目建立 SDD 上下文
- 02检查项目技术栈与架构
- 03初始化规范文档和知识图谱
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ giuseppe-trisciuoglio/ developer-kit --skill sdd-init安装后在 Claude Code 中输入/sdd-init确认已加载。
详细介绍
SDD 初始化技能
在当前项目中初始化规范驱动开发(SDD)。检测技术栈、约定和架构模式,并引导所有持久化后端(Constitution + Knowledge Graph)。
适用场景
触发短语:
- “sdd-init”“init sdd”“setup sdd”
- “initialize sdd”“setup project”“initialize project context”
- “bootstrap sdd”“start sdd”
- “detect project stack”“detect tech stack”
工作流
1. Detect Project Context
├── Scan tech stack (languages, frameworks, tools)
├── Identify conventions (folder structure, patterns, configs)
└── Detect architecture (monolith, microservices, serverless)
2. Bootstrap Constitution
├── Check if docs/specs/architecture.md exists
├── If missing → ask user to create with constitution skill
└── If exists → show current state
3. Bootstrap Knowledge Graph
├── Check if docs/specs/knowledge-graph.json exists
├── Create with initial discoveries (stack, patterns, conventions)
└── Link to Constitution
4. Return Structured Result
└── status, executive_summary, artifacts, next_recommended
阶段 1:检测项目上下文
1.1 扫描技术栈
检测主要语言和框架:
# Detect language (priority order)
ls *.go *.rs *.ts *.js *.py *.java *.cs *.rb *.php *.cpp *.c 2>/dev/null | head -1
# Detect framework/type
ls package.json pyproject.toml Cargo.toml go.mod pom.xml *.csproj Gemfile composer.json 2>/dev/null
# Detect project type
ls -la src/ lib/ app/ cmd/ internal/ pkg/ services/ 2>/dev/null
1.2 识别约定
扫描现有模式:
# Folder structure
find . -maxdepth 2 -type d -name "src" -o -name "lib" -o -name "app" -o -name "cmd" | head -10
# Config files
ls -la *.yaml *.yml *.toml *.json *.env* Makefile 2>/dev/null
# Testing patterns
find . -name "*_test.*" -o -name "test_*.py" -o -name "*_test.go" -o -name "*.spec.ts" 2>/dev/null | head -10
# Build system
ls Makefile Dockerfile docker-compose*.yml *.mk 2>/dev/null
# CI/CD
ls .github/workflows/ .gitlab-ci.yml .circleci/ 2>/dev/null
1.3 检测架构风格
分析项目结构,查找架构模式:
# Microservices vs Monolith
ls services/ microservices/ cmd/ api/ internal/ 2>/dev/null
# Serverless
ls functions/ lambda/ handlers/ 2>/dev/null
# Layered architecture
ls controllers/ services/ repositories/ models/ 2>/dev/null
# Hexagonal/Ports & Adapters
ls ports/ adapters/ domain/ infrastructure/ 2>/dev/null
阶段 2:引导 Constitution
2.1 检查是否存在
# Check if Constitution files exist
[ -f docs/specs/architecture.md ] && echo "architecture:exists" || echo "architecture:missing"
[ -f docs/specs/ontology.md ] && echo "ontology:exists" || echo "ontology:missing"
2.2 如果不存在 → 询问用户
使用 AskUserQuestion 提示:
Constitution 文件(architecture.md、ontology.md)尚不存在。
**选项 1:**创建两者(推荐)——建立架构 DNA 和领域语言 **选项 2:**仅创建 architecture.md **选项 3:**仅创建 ontology.md
**选项 4:**暂时跳过——我会检测上下文,但跳过 Constitution
如果用户选择选项 1–3,将检测到的上下文委派给 /developer-kit-specs:constitution create。
2.3 如果存在 → 显示当前状态
读取并显示当前 Constitution 文件,并将检测到的上下文作为对照。
阶段 3:引导 Knowledge Graph
3.1 检查是否存在
# Check if KG exists
ls docs/specs/knowledge-graph.json 2>/dev/null
3.2 创建/更新 KG
使用初步发现创建或更新 docs/specs/knowledge-graph.json:
{
"metadata": {
"spec_id": "project-init",
"version": "1.0.0",
"created": "{{ISO_DATE}}",
"project": "{{PROJECT_NAME}}",
"type": "initial-discovery"
},
"context": {
"workingDirectory": "{{PWD}}",
"projectName": "{{PROJECT_NAME}}"
},
"stack": {
"primaryLanguage": "{{DETECTED_LANGUAGE}}",
"framework": "{{DETECTED_FRAMEWORK}}",
"buildSystem": "{{DETECTED_BUILD_SYSTEM}}"
},
"conventions": {
"folderStructure": ["{{FOLDERS}}"],
"namingPatterns": ["{{PATTERNS}}"],
"configFiles": ["{{CONFIGS}}"],
"testingPattern": "{{TESTING_PATTERN}}"
},
"architecture": {
"style": "{{MONOLITH|MICROSERVICE|SERVERLESS|LAYERED|HEXAGONAL}}",
"layers": ["{{LAYERS}}"],
"patterns": ["{{ARCHITECTURAL_PATTERNS}}"]
},
"references": {
"constitution": "docs/specs/architecture.md",
"ontology": "docs/specs/ontology.md"
},
"source": "sdd-init"
}
3.3 验证
创建 KG 后,验证其存在且包含有效 JSON:
# Validate KG
cat docs/specs/knowledge-graph.json | python3 -m json.tool > /dev/null && echo "KG:valid" || echo "KG:invalid"
阶段 4:返回结构化结果
返回一个 JSON 对象,其中包含:
{
"status": "success|partial|skipped",
"executive_summary": "Brief description of what was detected and initialized",
"artifacts": [
{
"path": "docs/specs/architecture.md",
"action": "created|existing|skipped",
"summary": "What this file contains"
},
{
"path": "docs/specs/ontology.md",
"action": "created|existing|skipped",
"summary": "What this file contains"
},
{
"path": "docs/specs/knowledge-graph.json",
"action": "created|updated",
"summary": "What was discovered and stored"
}
],
"next_recommended": [
"Review Constitution if just created",
"Run brainstorm to start first spec",
"Check knowledge-graph.json for detected patterns"
]
}
输出格式
以结构化格式显示结果:
══════════════════════════════════════════════════
SDD Init — {{PROJECT_NAME}}
══════════════════════════════════════════════════
STATUS: {{status}}
TECH STACK DETECTED:
Language: {{language}}
Framework: {{framework}}
Build: {{build_system}}
ARCHITECTURE:
Style: {{architecture_style}}
Patterns: {{patterns}}
ARTIFACTS:
✓ Constitution (architecture.md) — {{status}}
✓ Constitution (ontology.md) — {{status}}
✓ Knowledge Graph — {{status}}
NEXT STEPS:
{{next_recommended}}
══════════════════════════════════════════════════
与其他技能集成
| 技能 | 集成点 |
|---|---|
constitution | 如果 Constitution 不存在,则由 sdd-init 创建/更新 |
knowledge-graph | 由 sdd-init 填入初步发现 |
brainstorm | 开始前应先读取 Constitution |
spec-to-tasks | 应根据 KG 和 Constitution 进行验证 |
task-implementation | 应检查 KG 中是否存在现有模式 |
约束和警告
- 只读检测——不会修改源代码
- 非破坏性——只创建新文件,不覆盖现有内容
- 权限检查——如果无法创建 docs/specs/,请发出警告
- 备份 KG——更新现有 KG 时,保留已有数据
错误处理
| 错误 | 恢复方式 |
|---|---|
| 无法创建 docs/specs/ | 请用户手动创建目录 |
| KG JSON 无效 | 显示错误,保留原始文件,并建议进行验证 |
| Constitution 委派失败 | 使用模板回退到内联创建 |
评论
支持 Markdown