auto_commit_changes
Automatically commit AI-generated changes to your repository with a clear commit message. Optionally specify files or amend the latest session commit for streamlined version control.
Instructions
Automatically commit AI-made changes with tracking
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| message | Yes | Commit message | |
| files | No | Specific files to commit | |
| amendSession | No | Amend to current session commit |
Implementation Reference
- src/services/GitService.ts:632-720 (handler)Main handler for auto_commit_changes tool. Checks git repo, checks for changes, stages files, creates commit with [AI] prefix, and returns success/failure.
async autoCommitChanges(options: AutoCommitOptions): Promise<ToolResult> { try { const { message, files, amendSession = true, skipIfNoChanges = true } = options; const cwd = this.workspaceService.getCurrentWorkspace(); // Check if we're in a git repository first const gitCheckResult = await this.gitCommand(['rev-parse', '--git-dir'], cwd); if (gitCheckResult.isError || gitCheckResult.content[0]?.text?.includes('not a git repository')) { return { isError: true, content: [{ type: 'text', text: 'Auto-commit failed: Not a git repository' }] }; } // Check if there are any changes to commit if (skipIfNoChanges) { const statusResult = await this.gitStatus({ cwd }); if (!statusResult.isError) { const statusText = statusResult.content[0]?.text; // Check if status is empty (no changes) or explicitly mentions no changes if (!statusText || statusText.trim() === '' || statusText === 'Command completed successfully' || statusText.includes('nothing to commit') || statusText.includes('working tree clean') || statusText.includes('working directory clean')) { return { content: [{ type: 'text', text: 'No changes to commit' }] }; } } } // Stage the files const addArgs: GitAddArgs = { cwd }; if (files && files.length > 0) { addArgs.files = files; } else { addArgs.all = true; } const addResult = await this.gitAdd(addArgs); if (addResult.isError) { return addResult; } // Prepare commit message with AI prefix const commitMessage = `[AI] ${message}`; const commitArgs: GitCommitArgs = { message: commitMessage, cwd }; const commitResult = await this.gitCommit(commitArgs); if (commitResult.isError) { return { isError: true, content: [{ type: 'text', text: `Auto-commit failed: ${commitResult.content[0]?.text || 'Failed to commit changes'}` }] }; } // Return success with commit message return { content: [{ type: 'text', text: `Successfully committed changes: ${commitMessage}` }] }; } catch (error) { return { isError: true, content: [{ type: 'text', text: `Auto-commit failed: ${error instanceof Error ? error.message : String(error)}` }] }; } } - src/services/GitService.ts:144-149 (schema)Input options interface for autoCommitChanges: message (required), files, amendSession, skipIfNoChanges.
export interface AutoCommitOptions { message: string; files?: string[]; amendSession?: boolean; skipIfNoChanges?: boolean; } - src/toolDefinitions.ts:747-757 (schema)Tool definition with inputSchema: requires message, optional files (array of strings) and amendSession (boolean).
name: 'auto_commit_changes', description: 'Automatically commit AI-made changes with tracking', inputSchema: { type: 'object', properties: { message: { type: 'string', description: 'Commit message' }, files: { type: 'array', items: { type: 'string' }, description: 'Specific files to commit' }, amendSession: { type: 'boolean', description: 'Amend to current session commit' } }, required: ['message'] } - src/index.ts:355-360 (registration)Case statement in the tool dispatcher routing 'auto_commit_changes' to gitService.autoCommitChanges() with args.
case 'auto_commit_changes': return await this.gitService.autoCommitChanges({ message: args.message, files: args.files, amendSession: args.amendSession }); - Helper call to autoCommitChanges after running a command, used when gitAutoCommit config is enabled.
if (commitResult) { const config = await this.configService.loadProjectConfig(); if (config.gitAutoCommit) { const message = commitMessage || `Executed command: ${command}`; await this.gitService.autoCommitChanges({ message, skipIfNoChanges: true });