hooks_setup_git
Configure Git hooks to automate documentation updates and code validation processes within your development workflow.
Instructions
Setup Git hooks for automated documentation and validation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/hooks/index.ts:80-83 (handler)MCP tool handler for 'hooks_setup_git' that invokes HooksService.setupGitHooks() and returns success status.tools.set('hooks_setup_git', async () => { const gitSetup = await hooksService.setupGitHooks(); return { success: gitSetup, message: gitSetup ? 'Git hooks setup successfully' : 'Failed to setup Git hooks' }; });
- src/tools/hooks/index.ts:34-42 (schema)Tool schema definition specifying no input parameters required.{ name: 'hooks_setup_git', description: 'Setup Git hooks for automated documentation and validation', inputSchema: { type: 'object', properties: {}, required: [] } },
- src/services/HooksService.ts:346-378 (helper)Main logic for setting up Git hooks: creates and writes pre-commit and post-commit hook scripts to .git/hooks directory, makes them executable on Unix.async setupGitHooks(): Promise<boolean> { if (!this.config.gitIntegration) { return false; } const hooksDir = this.pathAdapter.join(this.projectRoot, '.git', 'hooks'); if (!this.fileSystem.existsSync(hooksDir)) { return false; } try { // Create pre-commit hook const preCommitHook = this.generatePreCommitHook(); this.fileSystem.writeFileSync(this.pathAdapter.join(hooksDir, 'pre-commit'), preCommitHook); // Create post-commit hook const postCommitHook = this.generatePostCommitHook(); this.fileSystem.writeFileSync(this.pathAdapter.join(hooksDir, 'post-commit'), postCommitHook); // Make hooks executable (Unix systems) if (process.platform !== 'win32') { this.fileSystem.chmodSync(this.pathAdapter.join(hooksDir, 'pre-commit'), 0o755); this.fileSystem.chmodSync(this.pathAdapter.join(hooksDir, 'post-commit'), 0o755); } await this.notify('system', 'Git hooks setup completed'); return true; } catch (error: any) { console.error('Failed to setup git hooks:', error); return false; } }
- src/services/HooksService.ts:380-395 (helper)Generates the content for the pre-commit Git hook script.private generatePreCommitHook(): string { return `#!/bin/sh # CastPlan Automation Pre-commit Hook # Get staged files changed_files=$(git diff --cached --name-only) if [ ! -z "$changed_files" ]; then echo "🔍 Running pre-commit hooks..." # Trigger pre-work event via MCP # This would typically call the MCP server echo "Files to be committed: $changed_files" fi `; }
- src/services/HooksService.ts:397-414 (helper)Generates the content for the post-commit Git hook script.private generatePostCommitHook(): string { return `#!/bin/sh # CastPlan Automation Post-commit Hook # Get committed files changed_files=$(git diff-tree --no-commit-id --name-only -r HEAD) commit_message=$(git log -1 --pretty=%B) if [ ! -z "$changed_files" ]; then echo "📝 Running post-commit hooks..." # Trigger post-work event via MCP # This would typically call the MCP server echo "Files committed: $changed_files" echo "Commit message: $commit_message" fi `; }