log_module
Record a module modification with change description, files, and decisions. Use after modifying code to log the update for the module.
Instructions
【模块记录】按模块记录一次修改(目录式)。修改功能前先 read_module,修改后调用此工具。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| moduleName | Yes | 模块名称(如 auth、rag-upload、frontend) | |
| change | Yes | 变更内容描述 | |
| files | No | 涉及的文件列表 | |
| decisions | No | 本次决策 |
Implementation Reference
- src/index.ts:433-466 (handler)The handleLogModule method is the tool handler for 'log_module'. It extracts moduleName, change, files, and decisions from args, validates required params (moduleName, change), then calls appendModuleLog from module-logger.ts to write the module modification record to disk.
private async handleLogModule(args: any) { const moduleName = typeof args?.moduleName === 'string' ? args.moduleName : ''; const change = typeof args?.change === 'string' ? args.change : ''; const files: string[] = Array.isArray(args?.files) ? args.files : []; const decisions: string[] = Array.isArray(args?.decisions) ? args.decisions : []; if (!moduleName || !change) { return { content: [{ type: 'text', text: '❌ "moduleName" 和 "change" 是必填参数。' }], isError: true, }; } const projectRoot = getProjectRoot(); const today = new Date().toISOString().slice(0, 10); const result = appendModuleLog(projectRoot, moduleName, { date: today, change, files, decisions, }); if (result.success) { return { content: [{ type: 'text', text: `✅ 模块记录已更新: ${moduleName}\n\n变更: ${change}\n日期: ${today}` }], }; } else { return { content: [{ type: 'text', text: `❌ 更新模块记录失败: ${result.error}` }], isError: true, }; } } - src/index.ts:171-196 (schema)Registration/input schema for the 'log_module' tool. Defines the tool name, description, and input parameters: moduleName (string, required), change (string, required), files (array of strings), decisions (array of strings).
name: 'log_module', description: '【模块记录】按模块记录一次修改(目录式)。修改功能前先 read_module,修改后调用此工具。', inputSchema: { type: 'object', properties: { moduleName: { type: 'string', description: '模块名称(如 auth、rag-upload、frontend)', }, change: { type: 'string', description: '变更内容描述', }, files: { type: 'array', items: { type: 'string' }, description: '涉及的文件列表', }, decisions: { type: 'array', items: { type: 'string' }, description: '本次决策', }, }, required: ['moduleName', 'change'], }, - src/index.ts:248-249 (registration)Registration of 'log_module' in the CallToolRequestSchema handler. Maps the tool name 'log_module' to handleLogModule method via a switch-case statement.
case 'log_module': return this.handleLogModule(args); - src/module-logger.ts:69-135 (helper)The appendModuleLog function is the core helper that writes the module modification entry to disk. It appends a new row to the markdown table in the module's record file under .github/prompts/modules/<moduleName>.md. If the file doesn't exist, it creates a new one with a header table.
// ─── 写入模块记录 ──────────────────────────────────────────────────── /** * 追加一条模块修改记录 */ export function appendModuleLog( projectRoot: string, moduleName: string, entry: ModuleEntry ): { success: boolean; error?: string } { try { const modulesDir = getModulesDir(projectRoot); if (!fs.existsSync(modulesDir)) { fs.mkdirSync(modulesDir, { recursive: true }); } const filePath = getModulePath(projectRoot, moduleName); let existing = ''; if (fs.existsSync(filePath)) { existing = fs.readFileSync(filePath, 'utf-8'); } // 构建新条目行 const filesStr = entry.files.join(', ') || '-'; const decisionsStr = entry.decisions.join('; ') || '-'; const newRow = `| ${entry.date} | ${entry.change} | ${filesStr} | ${decisionsStr} |\n`; if (!existing) { // 新文件 const content = `# 模块记录: ${moduleName} > 按模块记录每一项修改,修改前先读取此文件了解历史。 ## 修改历史 | 日期 | 变更内容 | 涉及文件 | 决策 | |------|---------|---------|------| ${newRow} ## 当前状态 - 待补充 ## 待办 - [ ] 补充模块说明 `; fs.writeFileSync(filePath, content, 'utf-8'); } else { // 追加到表格中(在表头之后插入) const tableMarker = '|------|---------|---------|------|'; const idx = existing.indexOf(tableMarker); if (idx !== -1) { const insertPos = idx + tableMarker.length; const updated = existing.slice(0, insertPos) + '\n' + newRow + existing.slice(insertPos); fs.writeFileSync(filePath, updated, 'utf-8'); } else { // 没有表格,追加到末尾 const updated = existing + `\n| ${entry.date} | ${entry.change} | ${filesStr} | ${decisionsStr} |\n`; fs.writeFileSync(filePath, updated, 'utf-8'); } } return { success: true }; } catch (e: any) { return { success: false, error: e.message }; } } - src/module-logger.ts:13-25 (helper)Type definitions for the module logger: ModuleEntry interface (date, change, files, decisions) and ModuleLog interface (moduleName, entries, currentState, todos).
export interface ModuleEntry { date: string; change: string; files: string[]; decisions: string[]; } export interface ModuleLog { moduleName: string; entries: ModuleEntry[]; currentState: string; todos: string[]; }