diff --git a/.husky/pre-commit b/.husky/pre-commit index 3f4f8d6..a0abb46 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,18 @@ #!/bin/sh # Run linting and build to ensure code quality and dist is up to date + +# Get list of staged files before linting +STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM) + +# Run linting (which may modify files) bun run lint bun run build + +# Re-stage any files that were modified by linting +if [ -n "$STAGED_FILES" ]; then + echo "$STAGED_FILES" | while IFS= read -r file; do + if [ -f "$file" ]; then + git add "$file" + fi + done +fi diff --git a/README.md b/README.md index e67f668..aa6e1df 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,9 @@ npm install -D @arittr/commitment # 2. Set up git hooks (automatic) npx commitment init +# Or configure with a specific AI agent +npx commitment init --agent gemini + # 3. Make changes and commit git add . git commit # Message generated automatically! @@ -159,6 +162,12 @@ commitment supports multiple hook managers: | **simple-git-hooks** | `npx commitment init --hook-manager simple-git-hooks` | Lightweight alternative to husky | | **Plain Git Hooks** | `npx commitment init --hook-manager plain` | No dependencies | +**Configure default agent:** +```bash +npx commitment init --agent gemini # Use Gemini by default +npx commitment init --agent codex # Use Codex by default +``` + See [docs/HOOKS.md](./docs/HOOKS.md) for detailed hook integration guide. ## Troubleshooting diff --git a/src/cli.ts b/src/cli.ts index f810e8e..a52d3c8 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -126,7 +126,7 @@ async function main(): Promise { .command('init') .description('Initialize commitment hooks in your project') .option('--hook-manager ', 'Hook manager to use: husky, simple-git-hooks, plain') - .option('--agent ', 'AI agent to use: claude, codex, gemini (default: claude)') + .option('--agent ', 'Default AI agent for hooks: claude, codex, gemini') .option('--cwd ', 'Working directory', process.cwd()) .action( async (options: { @@ -134,8 +134,15 @@ async function main(): Promise { hookManager?: 'husky' | 'simple-git-hooks' | 'plain'; agent?: 'claude' | 'codex' | 'gemini'; }) => { + // Parse --agent manually from process.argv due to Commander.js subcommand option conflict + const agentFlagIndex = process.argv.indexOf('--agent'); + const agentValue = + agentFlagIndex >= 0 && agentFlagIndex < process.argv.length - 1 + ? (process.argv[agentFlagIndex + 1] as 'claude' | 'codex' | 'gemini') + : undefined; + await initCommand({ - agent: options.agent, + agent: agentValue, cwd: options.cwd, hookManager: options.hookManager, }); diff --git a/src/cli/commands/init.ts b/src/cli/commands/init.ts index 054a771..5dd7a08 100644 --- a/src/cli/commands/init.ts +++ b/src/cli/commands/init.ts @@ -277,6 +277,9 @@ export async function initCommand(options: InitOptions): Promise { // Print next steps console.log(''); console.log(chalk.green('🎉 Setup complete!')); + if (options.agent !== undefined) { + console.log(chalk.cyan(` Default agent: ${options.agent}`)); + } console.log(''); console.log(chalk.cyan('Next steps:')); console.log(chalk.white(' 1. Stage your changes: ') + chalk.gray('git add .'));