init_prompts
Scans a project root directory and generates initial prompts files (context.md, workflow-log.md, recent-5.md, summary-10.md, todos.md, dev-rules.md, modules/) for AI coding assistants, without overwriting existing files.
Instructions
【初始化】扫描目标项目,自动生成原始 prompts 体系(context.md / workflow-log.md / recent-5.md / summary-10.md / todos.md / dev-rules.md / modules/)。已有文件不会覆盖。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectRoot | No | 目标项目根目录路径。不传则使用 PROJECT_ROOT 环境变量或当前目录。 |
Implementation Reference
- src/index.ts:268-317 (handler)MCP tool handler for init_prompts. Calls the core initPrompts() function from prompts-generator.ts and formats the result as a markdown response.
private async handleInitPrompts(args: any) { const projectRoot = typeof args?.projectRoot === 'string' ? args.projectRoot : getProjectRoot(); const result = initPrompts(projectRoot); const lines: string[] = []; lines.push('# 🚀 Prompts 体系初始化完成'); lines.push(''); lines.push(`**项目**: ${result.projectInfo.name}`); lines.push(`**路径**: ${result.promptsDir}`); lines.push(''); lines.push('## ✅ 已创建文件'); lines.push(''); for (const f of result.filesCreated) { lines.push(`- \`${f}\``); } lines.push(''); lines.push('## 📋 检测到的项目信息'); lines.push(''); lines.push(`- 语言: ${result.projectInfo.languages.join(', ') || '未检测到'}`); lines.push(`- 框架: ${result.projectInfo.frameworks.join(', ') || '未检测到'}`); lines.push(`- 构建工具: ${result.projectInfo.buildTools.join(', ') || '未检测到'}`); lines.push(`- 数据库: ${result.projectInfo.databases.join(', ') || '未检测到'}`); lines.push(`- 前端: ${result.projectInfo.hasFrontend ? result.projectInfo.frontendFramework : '无'}`); lines.push(`- 后端: ${result.projectInfo.hasBackend ? result.projectInfo.backendFramework : '无'}`); lines.push(''); if (result.errors.length > 0) { lines.push('## ⚠️ 错误'); lines.push(''); for (const e of result.errors) { lines.push(`- ❌ ${e}`); } lines.push(''); } lines.push('## 📖 下一步'); lines.push(''); lines.push('1. 检查生成的 prompts 文件,根据项目实际情况补充修改'); lines.push('2. 运行 `bootstrap` 验证加载正常'); lines.push('3. 开始开发时,先运行 `check_requirements` 澄清需求'); return { content: [{ type: 'text', text: lines.join('\n') }], }; } - src/index.ts:89-100 (registration)Registers the 'init_prompts' tool with name, description, and inputSchema (projectRoot optional string).
name: 'init_prompts', description: '【初始化】扫描目标项目,自动生成原始 prompts 体系(context.md / workflow-log.md / recent-5.md / summary-10.md / todos.md / dev-rules.md / modules/)。已有文件不会覆盖。', inputSchema: { type: 'object', properties: { projectRoot: { type: 'string', description: '目标项目根目录路径。不传则使用 PROJECT_ROOT 环境变量或当前目录。', }, }, }, }, - src/index.ts:237-239 (registration)Routes the 'init_prompts' tool call to handleInitPrompts() in the CallToolRequestSchema handler.
switch (name) { case 'init_prompts': return this.handleInitPrompts(args); - src/prompts-generator.ts:647-653 (schema)InitResult interface defining the return type of initPrompts(): success, promptsDir, filesCreated, projectInfo, errors.
export interface InitResult { success: boolean; promptsDir: string; filesCreated: string[]; projectInfo: ProjectInfo; errors: string[]; } - src/prompts-generator.ts:658-716 (helper)Core initPrompts() function: scans the project, creates .github/prompts/ directories, and generates prompt files (context.md, workflow-log.md, recent-5.md, summary-10.md, log-state.json, todos.md, dev-rules.md) without overwriting existing files.
export function initPrompts(projectRoot: string): InitResult { const errors: string[] = []; const filesCreated: string[] = []; // 扫描项目 const info = scanProject(projectRoot); // 创建 .github/prompts 目录 const promptsDir = path.join(projectRoot, '.github', 'prompts'); const dirsToCreate = [ promptsDir, path.join(promptsDir, 'daily'), path.join(promptsDir, 'modules'), ]; for (const dir of dirsToCreate) { try { if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); } } catch (e: any) { errors.push(`创建目录失败: ${dir} - ${e.message}`); } } // 生成文件 const files: { name: string; content: string }[] = [ { name: 'context.md', content: generateContextMd(info) }, { name: 'workflow-log.md', content: generateWorkflowLogMd() }, { name: 'recent-5.md', content: generateRecent5Md() }, { name: 'summary-10.md', content: generateSummary10Md() }, { name: 'log-state.json', content: generateLogStateJson() }, { name: 'todos.md', content: generateTodosMd() }, { name: 'dev-rules.md', content: generateDevRulesPrompt(info) }, ]; for (const file of files) { const filePath = path.join(promptsDir, file.name); try { // 不覆盖已存在的文件 if (!fs.existsSync(filePath)) { fs.writeFileSync(filePath, file.content, 'utf-8'); filesCreated.push(file.name); } else { filesCreated.push(`${file.name} (已存在,跳过覆盖)`); } } catch (e: any) { errors.push(`写入文件失败: ${file.name} - ${e.message}`); } } return { success: errors.length === 0, promptsDir, filesCreated, projectInfo: info, errors, }; }