--- name: project-init description: A0 项目初始化——从插件模板幂等地用 Read/Write 落盘 CLAUDE.md / docs/01-需求清单/index.md / docs/04-技术规范.md / docs/08-模块任务管理.md(已存在则跳过),做跨平台依赖检查(git/mysql/node 缺失则按 OS 给安装指引并停下),并初始化 Git(如未初始化)。plan-start 在 docs/08 缺失时派发本 skill。 user-invocable: false allowed-tools: Read Write Glob Edit Skill Bash(node *) Bash(git init) Bash(git rev-parse *) --- **所有输出必须使用中文。** ## 执行步骤 ### A. 幂等复制模板文件(用 Glob + Read + Write,跨平台无 shell) 对下表每个文件:先用 `Glob` 判断目标路径是否已存在;**已存在则跳过**;不存在则用 `Read` 读模板、用 `Write` **原样**写到目标路径(`Write` 会自动创建缺失的父目录)。 | 模板 | 目标路径 | |---|---| | `${CLAUDE_SKILL_DIR}/templates/CLAUDE-template.md` | `CLAUDE.md` | | `${CLAUDE_SKILL_DIR}/templates/docs-01-index-template.md` | `docs/01-需求清单/index.md` | | `${CLAUDE_SKILL_DIR}/templates/docs-04-stack-template.md` | `docs/04-技术规范.md` | | `${CLAUDE_SKILL_DIR}/templates/docs-08-initial-template.md` | `docs/08-模块任务管理.md` | 完成后,用 `Edit` 在 `docs/08-模块任务管理.md` 中勾选: - ` - [ ] 项目文件骨架已创建(CLAUDE.md + docs/01-需求清单/index.md + docs/04-技术规范.md)` ### B. 依赖检查(跨平台,只检测不自动安装) 检测 git/mysql/node 是否在 PATH; 缺失则打印 OS 对应安装指引并停下. 用 `Bash` 跑下面这段 `node` 脚本: ```bash node -e ' const { spawnSync } = require("node:child_process"); const plat = process.platform; const has = (cmd) => { const r = plat === "win32" ? spawnSync("where", [cmd], { stdio: "ignore" }) : spawnSync("sh", ["-c", "command -v " + cmd], { stdio: "ignore" }); return r.status === 0; }; const guide = { darwin: { git: "xcode-select --install 或 brew install git", mysql: "brew install mysql", node: "brew install node 或见 https://nodejs.org" }, linux: { git: "sudo apt-get install git / sudo yum install git / sudo apk add git", mysql: "sudo apt-get install mysql-client / sudo yum install mysql", node: "sudo apt-get install nodejs 或见 https://nodejs.org" }, win32: { git: "winget install Git.Git 或见 https://git-scm.com/download/win", mysql: "winget install Oracle.MySQL 或见 https://dev.mysql.com/downloads/", node: "winget install OpenJS.NodeJS 或见 https://nodejs.org" }, }[plat] || {}; const tools = ["git", "mysql", "node"]; const missing = tools.filter((t) => !has(t)); const mark = (t) => (missing.includes(t) ? "✗" : "✓"); console.log("[project-init] 依赖检查 (" + plat + "): " + tools.map((t) => t + " " + mark(t)).join(" ")); if (missing.length) { console.error("[project-init] 缺失依赖,请先安装后重跑:"); for (const t of missing) console.error(" - " + t + " : " + (guide[t] || "见对应官网")); process.exit(1); } ' ``` - 退出码 `0`(全部 ✓)→ 进入步骤 C - 退出码 `1`(有缺失)→ 已打印缺失工具 + OS 安装指引,**停下**,提示用户安装后重跑本 skill 完成后,用 `Edit` 在 `docs/08-模块任务管理.md` 中勾选: - ` - [ ] 依赖检查通过` ### C. 初始化 Git(如尚未初始化) 用 `Bash` 执行 `git rev-parse --is-inside-work-tree`。 - 退出码 `0` 且 stdout 为 `true` → 已在 git 仓库中,跳过。 - 非 `0` → 用 `Bash` 执行 `git init`。 不要用 `.git/` 目录是否存在判断:git worktree / 子模块 / 某些托管环境会使用 `.git` 文件,目录探测会误判。 完成后,用 `Edit` 在 `docs/08-模块任务管理.md` 中勾选(A0 子项 + A0 顶层): - ` - [ ] Git 已初始化` - `- [ ] A0 项目初始化 — project-init` ### D. 打印完成横幅并进入 A1 向用户输出: ``` ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ [project-init] 项目初始化完成 已创建: ✓ CLAUDE.md(从插件模板复制) ✓ docs/01-需求清单/index.md(待人工填写模块索引) ✓ docs/04-技术规范.md(默认技术栈,A1 让用户确认) ✓ docs/08-模块任务管理.md(全流程进度跟踪) 已勾选:A0 项目初始化 下一步:A1 scope-lock(填写项目概述 + 技术栈 + 需求索引 + REQ 卡片) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ``` 立即调用 `Skill(scope-lock)` 进入 A1,不等用户手动输入。 ## 参考 - `${CLAUDE_SKILL_DIR}/templates/CLAUDE-template.md` - `${CLAUDE_SKILL_DIR}/templates/docs-01-index-template.md` - `${CLAUDE_SKILL_DIR}/templates/docs-04-stack-template.md` - `${CLAUDE_SKILL_DIR}/templates/docs-08-initial-template.md`