feat(ai): run postCd hooks before launching AI process#145
Conversation
When users configure postCd hooks (e.g., source ./vars.sh), gtr cd runs them but gtr ai did not. This meant AI tools launched via gtr ai didn't get the worktree's environment setup. Add run_hooks_export to lib/hooks.sh — a variant of run_hooks that evals hooks without subshell isolation so exported env vars persist. Call sites wrap it in an explicit subshell for safety with set -e. Closes #144
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (5)
WalkthroughThe changes implement Changes
Sequence DiagramsequenceDiagram
participant User as User/Create Command
participant AICmd as AI Command
participant Subshell as Subshell
participant Hooks as Hook System
participant AITool as AI Process
User->>AICmd: gtr ai [branch]<br/>(with repo_root, branch)
AICmd->>Subshell: spawn with worktree_path
Subshell->>Hooks: run_hooks_export(postCd)<br/>export REPO_ROOT, WORKTREE_PATH, BRANCH
Hooks->>Hooks: source hook script
Hooks-->>Subshell: variables exported
Subshell->>AITool: ai_start
AITool->>AITool: inherits exported vars
AITool-->>User: AI process launched<br/>with hook env
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
Summary
gtr aiandgtr new --ainow runpostCdhooks before launching the AI process, so env vars set by hooks (e.g.,source ./vars.sh) propagate to the AI toolrun_hooks_exporttolib/hooks.sh— a hook runner thatevals without subshell isolation, soexportcalls persist. Call sites wrap it in an explicit( ... )subshell forset -esafetyCloses #144
Test plan
run_hooks_export)gtr aiwith postCd hook → env var propagates to AI process🤖 Generated with Claude Code
Summary by CodeRabbit
Enhancements
Tests