generate_commit_message
Generate Git commit messages from code diffs. Choose from conventional, simple, or detailed styles to match your project's needs.
Instructions
根据代码变更生成 Git commit message
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| diff | Yes | 代码变更内容(git diff 输出) | |
| style | No | 提交信息风格:conventional(约定式)、simple(简洁)、detailed(详细) |
Implementation Reference
- src/server.ts:325-343 (registration)Registers the 'generate_commit_message' tool with name, description, and input schema (diff string required, optional style enum with values conventional/simple/detailed).
{ name: 'generate_commit_message', description: '根据代码变更生成 Git commit message', inputSchema: { type: 'object', properties: { diff: { type: 'string', description: '代码变更内容(git diff 输出)', }, style: { type: 'string', enum: ['conventional', 'simple', 'detailed'], description: '提交信息风格:conventional(约定式)、simple(简洁)、detailed(详细)', }, }, required: ['diff'], }, }, - src/server.ts:328-342 (schema)Input schema for the tool: requires 'diff' (string) and optionally accepts 'style' (enum: conventional/simple/detailed).
inputSchema: { type: 'object', properties: { diff: { type: 'string', description: '代码变更内容(git diff 输出)', }, style: { type: 'string', enum: ['conventional', 'simple', 'detailed'], description: '提交信息风格:conventional(约定式)、simple(简洁)、detailed(详细)', }, }, required: ['diff'], }, - src/server.ts:770-795 (handler)Handler for generate_commit_message: extracts diff and optional style, builds a prompt with style-specific instructions, truncates diff to 8000 chars, calls orchestrator.askDynamicExpert with a 'fast' tier expert role 'Git commit规范专家', and returns formatted commit message.
case 'generate_commit_message': { const { diff, style = 'conventional' } = args as { diff: string; style?: string }; const stylePrompts: Record<string, string> = { conventional: '使用约定式提交格式:type(scope): description。type 可以是 feat/fix/docs/style/refactor/test/chore。', simple: '使用简洁风格:一行描述主要变更。', detailed: '使用详细风格:标题 + 空行 + 详细说明(列出所有变更点)。', }; const prompt = `请根据以下代码变更生成 Git commit message。 ${stylePrompts[style] || stylePrompts.conventional} 代码变更: \`\`\`diff ${diff.slice(0, 8000)} \`\`\` 请只输出 commit message,不要其他内容。`; const response = await orchestrator.askDynamicExpert('fast', '你是一位 Git 提交规范专家。', prompt); return { content: [{ type: 'text', text: `# 📝 推荐的 Commit Message\n\n\`\`\`\n${response}\n\`\`\`` }], }; } - Helper method askDynamicExpert that creates a dynamic Expert instance with the given tier and role, sends the prompt (question), and returns the response. Used by the generate_commit_message handler to call an LLM with the commit message prompt.
async askDynamicExpert(tier: ModelTier, role: string, question: string): Promise<string> { const expert = new Expert( { id: 'dynamic', name: '专家', role, capabilities: [], }, this.getAdapterByTier(tier) ); const response = await expert.respond(question); this.space.send('user', 'dynamic', question, 'question'); this.space.send('dynamic', 'user', response, 'output'); return response; }