ag-cortex 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/.agent/commands/test-browser.md +339 -0
  2. package/.agent/rules/00-constitution.md +46 -0
  3. package/.agent/rules/project-rules.md +49 -0
  4. package/.agent/skills/agent-browser/SKILL.md +223 -0
  5. package/.agent/skills/agent-native-architecture/SKILL.md +435 -0
  6. package/.agent/skills/agent-native-architecture/references/action-parity-discipline.md +409 -0
  7. package/.agent/skills/agent-native-architecture/references/agent-execution-patterns.md +467 -0
  8. package/.agent/skills/agent-native-architecture/references/agent-native-testing.md +582 -0
  9. package/.agent/skills/agent-native-architecture/references/architecture-patterns.md +478 -0
  10. package/.agent/skills/agent-native-architecture/references/dynamic-context-injection.md +338 -0
  11. package/.agent/skills/agent-native-architecture/references/files-universal-interface.md +301 -0
  12. package/.agent/skills/agent-native-architecture/references/from-primitives-to-domain-tools.md +359 -0
  13. package/.agent/skills/agent-native-architecture/references/mcp-tool-design.md +506 -0
  14. package/.agent/skills/agent-native-architecture/references/mobile-patterns.md +871 -0
  15. package/.agent/skills/agent-native-architecture/references/product-implications.md +443 -0
  16. package/.agent/skills/agent-native-architecture/references/refactoring-to-prompt-native.md +317 -0
  17. package/.agent/skills/agent-native-architecture/references/self-modification.md +269 -0
  18. package/.agent/skills/agent-native-architecture/references/shared-workspace-architecture.md +680 -0
  19. package/.agent/skills/agent-native-architecture/references/system-prompt-design.md +250 -0
  20. package/.agent/skills/agent-native-reviewer/SKILL.md +246 -0
  21. package/.agent/skills/andrew-kane-gem-writer/SKILL.md +184 -0
  22. package/.agent/skills/andrew-kane-gem-writer/references/database-adapters.md +231 -0
  23. package/.agent/skills/andrew-kane-gem-writer/references/module-organization.md +121 -0
  24. package/.agent/skills/andrew-kane-gem-writer/references/rails-integration.md +183 -0
  25. package/.agent/skills/andrew-kane-gem-writer/references/resources.md +119 -0
  26. package/.agent/skills/andrew-kane-gem-writer/references/testing-patterns.md +261 -0
  27. package/.agent/skills/ankane-readme-writer/SKILL.md +50 -0
  28. package/.agent/skills/architecture-strategist/SKILL.md +52 -0
  29. package/.agent/skills/best-practices-researcher/SKILL.md +100 -0
  30. package/.agent/skills/bug-reproduction-validator/SKILL.md +67 -0
  31. package/.agent/skills/code-simplicity-reviewer/SKILL.md +85 -0
  32. package/.agent/skills/coding-tutor/.claude-plugin/plugin.json +9 -0
  33. package/.agent/skills/coding-tutor/README.md +37 -0
  34. package/.agent/skills/coding-tutor/commands/quiz-me.md +1 -0
  35. package/.agent/skills/coding-tutor/commands/sync-tutorials.md +25 -0
  36. package/.agent/skills/coding-tutor/commands/teach-me.md +1 -0
  37. package/.agent/skills/coding-tutor/skills/coding-tutor/SKILL.md +214 -0
  38. package/.agent/skills/coding-tutor/skills/coding-tutor/scripts/create_tutorial.py +202 -0
  39. package/.agent/skills/coding-tutor/skills/coding-tutor/scripts/index_tutorials.py +203 -0
  40. package/.agent/skills/coding-tutor/skills/coding-tutor/scripts/quiz_priority.py +190 -0
  41. package/.agent/skills/coding-tutor/skills/coding-tutor/scripts/setup_tutorials.py +132 -0
  42. package/.agent/skills/compound-docs/SKILL.md +510 -0
  43. package/.agent/skills/compound-docs/assets/critical-pattern-template.md +34 -0
  44. package/.agent/skills/compound-docs/assets/resolution-template.md +93 -0
  45. package/.agent/skills/compound-docs/references/yaml-schema.md +65 -0
  46. package/.agent/skills/compound-docs/schema.yaml +176 -0
  47. package/.agent/skills/create-agent-skills/SKILL.md +299 -0
  48. package/.agent/skills/create-agent-skills/references/api-security.md +226 -0
  49. package/.agent/skills/create-agent-skills/references/be-clear-and-direct.md +531 -0
  50. package/.agent/skills/create-agent-skills/references/best-practices.md +404 -0
  51. package/.agent/skills/create-agent-skills/references/common-patterns.md +595 -0
  52. package/.agent/skills/create-agent-skills/references/core-principles.md +437 -0
  53. package/.agent/skills/create-agent-skills/references/executable-code.md +175 -0
  54. package/.agent/skills/create-agent-skills/references/iteration-and-testing.md +474 -0
  55. package/.agent/skills/create-agent-skills/references/official-spec.md +185 -0
  56. package/.agent/skills/create-agent-skills/references/recommended-structure.md +168 -0
  57. package/.agent/skills/create-agent-skills/references/skill-structure.md +372 -0
  58. package/.agent/skills/create-agent-skills/references/using-scripts.md +113 -0
  59. package/.agent/skills/create-agent-skills/references/using-templates.md +112 -0
  60. package/.agent/skills/create-agent-skills/references/workflows-and-validation.md +510 -0
  61. package/.agent/skills/create-agent-skills/templates/router-skill.md +73 -0
  62. package/.agent/skills/create-agent-skills/templates/simple-skill.md +33 -0
  63. package/.agent/skills/create-agent-skills/workflows/add-reference.md +96 -0
  64. package/.agent/skills/create-agent-skills/workflows/add-script.md +93 -0
  65. package/.agent/skills/create-agent-skills/workflows/add-template.md +74 -0
  66. package/.agent/skills/create-agent-skills/workflows/add-workflow.md +120 -0
  67. package/.agent/skills/create-agent-skills/workflows/audit-skill.md +138 -0
  68. package/.agent/skills/create-agent-skills/workflows/create-domain-expertise-skill.md +605 -0
  69. package/.agent/skills/create-agent-skills/workflows/create-new-skill.md +191 -0
  70. package/.agent/skills/create-agent-skills/workflows/get-guidance.md +121 -0
  71. package/.agent/skills/create-agent-skills/workflows/upgrade-to-router.md +161 -0
  72. package/.agent/skills/create-agent-skills/workflows/verify-skill.md +204 -0
  73. package/.agent/skills/data-integrity-guardian/SKILL.md +70 -0
  74. package/.agent/skills/data-migration-expert/SKILL.md +97 -0
  75. package/.agent/skills/deployment-verification-agent/SKILL.md +159 -0
  76. package/.agent/skills/design-implementation-reviewer/SKILL.md +85 -0
  77. package/.agent/skills/design-iterator/SKILL.md +197 -0
  78. package/.agent/skills/dhh-rails-reviewer/SKILL.md +45 -0
  79. package/.agent/skills/dhh-rails-style/SKILL.md +184 -0
  80. package/.agent/skills/dhh-rails-style/references/architecture.md +653 -0
  81. package/.agent/skills/dhh-rails-style/references/controllers.md +303 -0
  82. package/.agent/skills/dhh-rails-style/references/frontend.md +510 -0
  83. package/.agent/skills/dhh-rails-style/references/gems.md +266 -0
  84. package/.agent/skills/dhh-rails-style/references/models.md +359 -0
  85. package/.agent/skills/dhh-rails-style/references/testing.md +338 -0
  86. package/.agent/skills/dspy-ruby/SKILL.md +594 -0
  87. package/.agent/skills/dspy-ruby/assets/config-template.rb +359 -0
  88. package/.agent/skills/dspy-ruby/assets/module-template.rb +326 -0
  89. package/.agent/skills/dspy-ruby/assets/signature-template.rb +143 -0
  90. package/.agent/skills/dspy-ruby/references/core-concepts.md +265 -0
  91. package/.agent/skills/dspy-ruby/references/optimization.md +623 -0
  92. package/.agent/skills/dspy-ruby/references/providers.md +305 -0
  93. package/.agent/skills/every-style-editor/SKILL.md +134 -0
  94. package/.agent/skills/every-style-editor/references/EVERY_WRITE_STYLE.md +529 -0
  95. package/.agent/skills/figma-design-sync/SKILL.md +166 -0
  96. package/.agent/skills/file-todos/SKILL.md +251 -0
  97. package/.agent/skills/file-todos/assets/todo-template.md +155 -0
  98. package/.agent/skills/framework-docs-researcher/SKILL.md +83 -0
  99. package/.agent/skills/frontend-design/SKILL.md +42 -0
  100. package/.agent/skills/gemini-imagegen/SKILL.md +237 -0
  101. package/.agent/skills/gemini-imagegen/requirements.txt +2 -0
  102. package/.agent/skills/gemini-imagegen/scripts/compose_images.py +168 -0
  103. package/.agent/skills/gemini-imagegen/scripts/edit_image.py +157 -0
  104. package/.agent/skills/gemini-imagegen/scripts/gemini_images.py +265 -0
  105. package/.agent/skills/gemini-imagegen/scripts/generate_image.py +147 -0
  106. package/.agent/skills/gemini-imagegen/scripts/multi_turn_chat.py +215 -0
  107. package/.agent/skills/git-history-analyzer/SKILL.md +42 -0
  108. package/.agent/skills/git-worktree/SKILL.md +302 -0
  109. package/.agent/skills/git-worktree/scripts/worktree-manager.sh +345 -0
  110. package/.agent/skills/julik-frontend-races-reviewer/SKILL.md +222 -0
  111. package/.agent/skills/kieran-python-reviewer/SKILL.md +104 -0
  112. package/.agent/skills/kieran-rails-reviewer/SKILL.md +86 -0
  113. package/.agent/skills/kieran-typescript-reviewer/SKILL.md +95 -0
  114. package/.agent/skills/lint/SKILL.md +16 -0
  115. package/.agent/skills/pattern-recognition-specialist/SKILL.md +57 -0
  116. package/.agent/skills/performance-oracle/SKILL.md +110 -0
  117. package/.agent/skills/pr-comment-resolver/SKILL.md +69 -0
  118. package/.agent/skills/rclone/SKILL.md +150 -0
  119. package/.agent/skills/rclone/scripts/check_setup.sh +60 -0
  120. package/.agent/skills/repo-research-analyst/SKILL.md +113 -0
  121. package/.agent/skills/security-sentinel/SKILL.md +93 -0
  122. package/.agent/skills/skill-creator/SKILL.md +209 -0
  123. package/.agent/skills/skill-creator/scripts/init_skill.py +304 -0
  124. package/.agent/skills/skill-creator/scripts/package_skill.py +112 -0
  125. package/.agent/skills/skill-creator/scripts/quick_validate.py +72 -0
  126. package/.agent/skills/spec-flow-analyzer/SKILL.md +113 -0
  127. package/.agent/skills/test-agent/SKILL.md +4 -0
  128. package/.agent/workflows/agent-native-audit.md +277 -0
  129. package/.agent/workflows/ask-user-question.md +21 -0
  130. package/.agent/workflows/changelog.md +137 -0
  131. package/.agent/workflows/compound.md +202 -0
  132. package/.agent/workflows/create-agent-skill.md +8 -0
  133. package/.agent/workflows/deepen-plan-research.md +334 -0
  134. package/.agent/workflows/deepen-plan-synthesis.md +182 -0
  135. package/.agent/workflows/deepen-plan.md +79 -0
  136. package/.agent/workflows/feature-video.md +342 -0
  137. package/.agent/workflows/generate-command.md +162 -0
  138. package/.agent/workflows/heal-skill.md +142 -0
  139. package/.agent/workflows/lfg.md +20 -0
  140. package/.agent/workflows/plan-analysis.md +67 -0
  141. package/.agent/workflows/plan-next-steps.md +63 -0
  142. package/.agent/workflows/plan-review.md +33 -0
  143. package/.agent/workflows/plan-synthesis.md +106 -0
  144. package/.agent/workflows/plan.md +49 -0
  145. package/.agent/workflows/report-bug.md +150 -0
  146. package/.agent/workflows/reproduce-bug.md +99 -0
  147. package/.agent/workflows/resolve-parallel.md +34 -0
  148. package/.agent/workflows/resolve-pr-parallel.md +49 -0
  149. package/.agent/workflows/resolve-todo-parallel.md +35 -0
  150. package/.agent/workflows/review-analysis.md +145 -0
  151. package/.agent/workflows/review-synthesis.md +262 -0
  152. package/.agent/workflows/review.md +64 -0
  153. package/.agent/workflows/ship.md +90 -0
  154. package/.agent/workflows/test-command.md +3 -0
  155. package/.agent/workflows/triage.md +310 -0
  156. package/.agent/workflows/work.md +157 -0
  157. package/.agent/workflows/xcode-test.md +332 -0
  158. package/LICENSE +22 -0
  159. package/README.md +49 -0
  160. package/bin/ag-cortex.js +54 -0
  161. package/lib/core.js +165 -0
  162. package/package.json +31 -0
@@ -0,0 +1,302 @@
1
+ ---
2
+ name: git-worktree
3
+ description: This skill manages Git worktrees for isolated parallel development. It handles creating, listing, switching, and cleaning up worktrees with a simple interactive interface, following KISS principles.
4
+ ---
5
+
6
+ # Git Worktree Manager
7
+
8
+ This skill provides a unified interface for managing Git worktrees across your development workflow. Whether you're reviewing PRs in isolation or working on features in parallel, this skill handles all the complexity.
9
+
10
+ ## What This Skill Does
11
+
12
+ - **Create worktrees** from main branch with clear branch names
13
+ - **List worktrees** with current status
14
+ - **Switch between worktrees** for parallel work
15
+ - **Clean up completed worktrees** automatically
16
+ - **Interactive confirmations** at each step
17
+ - **Automatic .gitignore management** for worktree directory
18
+ - **Automatic .env file copying** from main repo to new worktrees
19
+
20
+ ## CRITICAL: Always Use the Manager Script
21
+
22
+ **NEVER call `git worktree add` directly.** Always use the `worktree-manager.sh` script.
23
+
24
+ The script handles critical setup that raw git commands don't:
25
+ 1. Copies `.env`, `.env.local`, `.env.test`, etc. from main repo
26
+ 2. Ensures `.worktrees` is in `.gitignore`
27
+ 3. Creates consistent directory structure
28
+
29
+ ```bash
30
+ # ✅ CORRECT - Always use the script
31
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh create feature-name
32
+
33
+ # ❌ WRONG - Never do this directly
34
+ git worktree add .worktrees/feature-name -b feature-name main
35
+ ```
36
+
37
+ ## When to Use This Skill
38
+
39
+ Use this skill in these scenarios:
40
+
41
+ 1. **Code Review (`/review`)**: If NOT already on the PR branch, offer worktree for isolated review
42
+ 2. **Feature Work (`/work`)**: Always ask if user wants parallel worktree or live branch work
43
+ 3. **Parallel Development**: When working on multiple features simultaneously
44
+ 4. **Cleanup**: After completing work in a worktree
45
+
46
+ ## How to Use
47
+
48
+ ### In Antigravity Workflows
49
+
50
+ The skill is automatically called from `/review` and `/work` commands:
51
+
52
+ ```
53
+ # For review: offers worktree if not on PR branch
54
+ # For work: always asks - new branch or worktree?
55
+ ```
56
+
57
+ ### Manual Usage
58
+
59
+ You can also invoke the skill directly from bash:
60
+
61
+ ```bash
62
+ # Create a new worktree (copies .env files automatically)
63
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh create feature-login
64
+
65
+ # List all worktrees
66
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh list
67
+
68
+ # Switch to a worktree
69
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh switch feature-login
70
+
71
+ # Copy .env files to an existing worktree (if they weren't copied)
72
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh copy-env feature-login
73
+
74
+ # Clean up completed worktrees
75
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh cleanup
76
+ ```
77
+
78
+ ## Commands
79
+
80
+ ### `create <branch-name> [from-branch]`
81
+
82
+ Creates a new worktree with the given branch name.
83
+
84
+ **Options:**
85
+ - `branch-name` (required): The name for the new branch and worktree
86
+ - `from-branch` (optional): Base branch to create from (defaults to `main`)
87
+
88
+ **Example:**
89
+ ```bash
90
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh create feature-login
91
+ ```
92
+
93
+ **What happens:**
94
+ 1. Checks if worktree already exists
95
+ 2. Updates the base branch from remote
96
+ 3. Creates new worktree and branch
97
+ 4. **Copies all .env files from main repo** (.env, .env.local, .env.test, etc.)
98
+ 5. Shows path for cd-ing to the worktree
99
+
100
+ ### `list` or `ls`
101
+
102
+ Lists all available worktrees with their branches and current status.
103
+
104
+ **Example:**
105
+ ```bash
106
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh list
107
+ ```
108
+
109
+ **Output shows:**
110
+ - Worktree name
111
+ - Branch name
112
+ - Which is current (marked with ✓)
113
+ - Main repo status
114
+
115
+ ### `switch <name>` or `go <name>`
116
+
117
+ Switches to an existing worktree and cd's into it.
118
+
119
+ **Example:**
120
+ ```bash
121
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh switch feature-login
122
+ ```
123
+
124
+ **Optional:**
125
+ - If name not provided, lists available worktrees and prompts for selection
126
+
127
+ ### `cleanup` or `clean`
128
+
129
+ Interactively cleans up inactive worktrees with confirmation.
130
+
131
+ **Example:**
132
+ ```bash
133
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh cleanup
134
+ ```
135
+
136
+ **What happens:**
137
+ 1. Lists all inactive worktrees
138
+ 2. Asks for confirmation
139
+ 3. Removes selected worktrees
140
+ 4. Cleans up empty directories
141
+
142
+ ## Workflow Examples
143
+
144
+ ### Code Review with Worktree
145
+
146
+ ```bash
147
+ # Antigravity recognizes you're not on the PR branch
148
+ # Offers: "Use worktree for isolated review? (y/n)"
149
+
150
+ # You respond: yes
151
+ # Script runs (copies .env files automatically):
152
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh create pr-123-feature-name
153
+
154
+ # You're now in isolated worktree for review with all env vars
155
+ cd .worktrees/pr-123-feature-name
156
+
157
+ # After review, return to main:
158
+ cd ../..
159
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh cleanup
160
+ ```
161
+
162
+ ### Parallel Feature Development
163
+
164
+ ```bash
165
+ # For first feature (copies .env files):
166
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh create feature-login
167
+
168
+ # Later, start second feature (also copies .env files):
169
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh create feature-notifications
170
+
171
+ # List what you have:
172
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh list
173
+
174
+ # Switch between them as needed:
175
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh switch feature-login
176
+
177
+ # Return to main and cleanup when done:
178
+ cd .
179
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh cleanup
180
+ ```
181
+
182
+ ## Key Design Principles
183
+
184
+ ### KISS (Keep It Simple, Stupid)
185
+
186
+ - **One manager script** handles all worktree operations
187
+ - **Simple commands** with sensible defaults
188
+ - **Interactive prompts** prevent accidental operations
189
+ - **Clear naming** using branch names directly
190
+
191
+ ### Opinionated Defaults
192
+
193
+ - Worktrees always created from **main** (unless specified)
194
+ - Worktrees stored in **.worktrees/** directory
195
+ - Branch name becomes worktree name
196
+ - **.gitignore** automatically managed
197
+
198
+ ### Safety First
199
+
200
+ - **Confirms before creating** worktrees
201
+ - **Confirms before cleanup** to prevent accidental removal
202
+ - **Won't remove current worktree**
203
+ - **Clear error messages** for issues
204
+
205
+ ## Integration with Workflows
206
+
207
+ ### `/review`
208
+
209
+ Instead of always creating a worktree:
210
+
211
+ ```
212
+ 1. Check current branch
213
+ 2. If ALREADY on PR branch → stay there, no worktree needed
214
+ 3. If DIFFERENT branch → offer worktree:
215
+ "Use worktree for isolated review? (y/n)"
216
+ - yes → call git-worktree skill
217
+ - no → proceed with PR diff on current branch
218
+ ```
219
+
220
+ ### `/work`
221
+
222
+ Always offer choice:
223
+
224
+ ```
225
+ 1. Ask: "How do you want to work?
226
+ 1. New branch on current worktree (live work)
227
+ 2. Worktree (parallel work)"
228
+
229
+ 2. If choice 1 → create new branch normally
230
+ 3. If choice 2 → call git-worktree skill to create from main
231
+ ```
232
+
233
+ ## Troubleshooting
234
+
235
+ ### "Worktree already exists"
236
+
237
+ If you see this, the script will ask if you want to switch to it instead.
238
+
239
+ ### "Cannot remove worktree: it is the current worktree"
240
+
241
+ Switch out of the worktree first (to main repo), then cleanup:
242
+
243
+ ```bash
244
+ cd $(git rev-parse --show-toplevel)
245
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh cleanup
246
+ ```
247
+
248
+ ### Lost in a worktree?
249
+
250
+ See where you are:
251
+
252
+ ```bash
253
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh list
254
+ ```
255
+
256
+ ### .env files missing in worktree?
257
+
258
+ If a worktree was created without .env files (e.g., via raw `git worktree add`), copy them:
259
+
260
+ ```bash
261
+ bash ${ANTIGRAVITY_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh copy-env feature-name
262
+ ```
263
+
264
+ Navigate back to main:
265
+
266
+ ```bash
267
+ cd $(git rev-parse --show-toplevel)
268
+ ```
269
+
270
+ ## Technical Details
271
+
272
+ ### Directory Structure
273
+
274
+ ```
275
+ .worktrees/
276
+ ├── feature-login/ # Worktree 1
277
+ │ ├── .git
278
+ │ ├── app/
279
+ │ └── ...
280
+ ├── feature-notifications/ # Worktree 2
281
+ │ ├── .git
282
+ │ ├── app/
283
+ │ └── ...
284
+ └── ...
285
+
286
+ .gitignore (updated to include .worktrees)
287
+ ```
288
+
289
+ ### How It Works
290
+
291
+ - Uses `git worktree add` for isolated environments
292
+ - Each worktree has its own branch
293
+ - Changes in one worktree don't affect others
294
+ - Share git history with main repo
295
+ - Can push from any worktree
296
+
297
+ ### Performance
298
+
299
+ - Worktrees are lightweight (just file system links)
300
+ - No repository duplication
301
+ - Shared git objects for efficiency
302
+ - Much faster than cloning or stashing/switching
@@ -0,0 +1,345 @@
1
+ #!/bin/bash
2
+
3
+ # Git Worktree Manager
4
+ # Handles creating, listing, switching, and cleaning up Git worktrees
5
+ # KISS principle: Simple, interactive, opinionated
6
+
7
+ set -e
8
+
9
+ # Colors for output
10
+ RED='\033[0;31m'
11
+ GREEN='\033[0;32m'
12
+ YELLOW='\033[1;33m'
13
+ BLUE='\033[0;34m'
14
+ NC='\033[0m' # No Color
15
+
16
+ # Get repo root
17
+ GIT_ROOT=$(git rev-parse --show-toplevel)
18
+ WORKTREE_DIR="$GIT_ROOT/.worktrees"
19
+
20
+ # Ensure .worktrees is in .gitignore
21
+ ensure_gitignore() {
22
+ if ! grep -q "^\.worktrees$" "$GIT_ROOT/.gitignore" 2>/dev/null; then
23
+ echo ".worktrees" >> "$GIT_ROOT/.gitignore"
24
+ fi
25
+ }
26
+
27
+ # Copy .env files from main repo to worktree
28
+ copy_env_files() {
29
+ local worktree_path="$1"
30
+
31
+ echo -e "${BLUE}Copying environment files...${NC}"
32
+
33
+ # Find all .env* files in root (excluding .env.example which should be in git)
34
+ local env_files=()
35
+ for f in "$GIT_ROOT"/.env*; do
36
+ if [[ -f "$f" ]]; then
37
+ local basename=$(basename "$f")
38
+ # Skip .env.example (that's typically committed to git)
39
+ if [[ "$basename" != ".env.example" ]]; then
40
+ env_files+=("$basename")
41
+ fi
42
+ fi
43
+ done
44
+
45
+ if [[ ${#env_files[@]} -eq 0 ]]; then
46
+ echo -e " ${YELLOW}ℹ️ No .env files found in main repository${NC}"
47
+ return
48
+ fi
49
+
50
+ local copied=0
51
+ for env_file in "${env_files[@]}"; do
52
+ local source="$GIT_ROOT/$env_file"
53
+ local dest="$worktree_path/$env_file"
54
+
55
+ if [[ -f "$dest" ]]; then
56
+ echo -e " ${YELLOW}⚠️ $env_file already exists, backing up to ${env_file}.backup${NC}"
57
+ cp "$dest" "${dest}.backup"
58
+ fi
59
+
60
+ cp "$source" "$dest"
61
+ echo -e " ${GREEN}✓ Copied $env_file${NC}"
62
+ copied=$((copied + 1))
63
+ done
64
+
65
+ echo -e " ${GREEN}✓ Copied $copied environment file(s)${NC}"
66
+ }
67
+
68
+ # Create a new worktree
69
+ create_worktree() {
70
+ local branch_name="$1"
71
+ local from_branch="${2:-main}"
72
+
73
+ if [[ -z "$branch_name" ]]; then
74
+ echo -e "${RED}Error: Branch name required${NC}"
75
+ exit 1
76
+ fi
77
+
78
+ local worktree_path="$WORKTREE_DIR/$branch_name"
79
+
80
+ # Check if worktree already exists
81
+ if [[ -d "$worktree_path" ]]; then
82
+ echo -e "${YELLOW}Worktree already exists at: $worktree_path${NC}"
83
+ echo -e "Switch to it instead? (y/n)"
84
+ read -r response
85
+ if [[ "$response" == "y" ]]; then
86
+ switch_worktree "$branch_name"
87
+ fi
88
+ return
89
+ fi
90
+
91
+ echo -e "${BLUE}Creating worktree: $branch_name${NC}"
92
+ echo " From: $from_branch"
93
+ echo " Path: $worktree_path"
94
+ echo ""
95
+ echo "Proceed? (y/n)"
96
+ read -r response
97
+
98
+ if [[ "$response" != "y" ]]; then
99
+ echo -e "${YELLOW}Cancelled${NC}"
100
+ return
101
+ fi
102
+
103
+ # Update main branch
104
+ echo -e "${BLUE}Updating $from_branch...${NC}"
105
+ git checkout "$from_branch"
106
+ git pull origin "$from_branch" || true
107
+
108
+ # Create worktree
109
+ mkdir -p "$WORKTREE_DIR"
110
+ ensure_gitignore
111
+
112
+ echo -e "${BLUE}Creating worktree...${NC}"
113
+ git worktree add -b "$branch_name" "$worktree_path" "$from_branch"
114
+
115
+ # Copy environment files
116
+ copy_env_files "$worktree_path"
117
+
118
+ echo -e "${GREEN}✓ Worktree created successfully!${NC}"
119
+ echo ""
120
+ echo "To switch to this worktree:"
121
+ echo -e "${BLUE}cd $worktree_path${NC}"
122
+ echo ""
123
+ }
124
+
125
+ # List all worktrees
126
+ list_worktrees() {
127
+ echo -e "${BLUE}Available worktrees:${NC}"
128
+ echo ""
129
+
130
+ if [[ ! -d "$WORKTREE_DIR" ]]; then
131
+ echo -e "${YELLOW}No worktrees found${NC}"
132
+ return
133
+ fi
134
+
135
+ local count=0
136
+ for worktree_path in "$WORKTREE_DIR"/*; do
137
+ if [[ -d "$worktree_path" && -d "$worktree_path/.git" ]]; then
138
+ count=$((count + 1))
139
+ local worktree_name=$(basename "$worktree_path")
140
+ local branch=$(git -C "$worktree_path" rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
141
+
142
+ if [[ "$PWD" == "$worktree_path" ]]; then
143
+ echo -e "${GREEN}✓ $worktree_name${NC} (current) → branch: $branch"
144
+ else
145
+ echo -e " $worktree_name → branch: $branch"
146
+ fi
147
+ fi
148
+ done
149
+
150
+ if [[ $count -eq 0 ]]; then
151
+ echo -e "${YELLOW}No worktrees found${NC}"
152
+ else
153
+ echo ""
154
+ echo -e "${BLUE}Total: $count worktree(s)${NC}"
155
+ fi
156
+
157
+ echo ""
158
+ echo -e "${BLUE}Main repository:${NC}"
159
+ local main_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
160
+ echo " Branch: $main_branch"
161
+ echo " Path: $GIT_ROOT"
162
+ }
163
+
164
+ # Switch to a worktree
165
+ switch_worktree() {
166
+ local worktree_name="$1"
167
+
168
+ if [[ -z "$worktree_name" ]]; then
169
+ list_worktrees
170
+ echo -e "${BLUE}Switch to which worktree? (enter name)${NC}"
171
+ read -r worktree_name
172
+ fi
173
+
174
+ local worktree_path="$WORKTREE_DIR/$worktree_name"
175
+
176
+ if [[ ! -d "$worktree_path" ]]; then
177
+ echo -e "${RED}Error: Worktree not found: $worktree_name${NC}"
178
+ echo ""
179
+ list_worktrees
180
+ exit 1
181
+ fi
182
+
183
+ echo -e "${GREEN}Switching to worktree: $worktree_name${NC}"
184
+ cd "$worktree_path"
185
+ echo -e "${BLUE}Now in: $(pwd)${NC}"
186
+ }
187
+
188
+ # Copy env files to an existing worktree (or current directory if in a worktree)
189
+ copy_env_to_worktree() {
190
+ local worktree_name="$1"
191
+ local worktree_path
192
+
193
+ if [[ -z "$worktree_name" ]]; then
194
+ # Check if we're currently in a worktree
195
+ local current_dir=$(pwd)
196
+ if [[ "$current_dir" == "$WORKTREE_DIR"/* ]]; then
197
+ worktree_path="$current_dir"
198
+ worktree_name=$(basename "$worktree_path")
199
+ echo -e "${BLUE}Detected current worktree: $worktree_name${NC}"
200
+ else
201
+ echo -e "${YELLOW}Usage: worktree-manager.sh copy-env [worktree-name]${NC}"
202
+ echo "Or run from within a worktree to copy to current directory"
203
+ list_worktrees
204
+ return 1
205
+ fi
206
+ else
207
+ worktree_path="$WORKTREE_DIR/$worktree_name"
208
+
209
+ if [[ ! -d "$worktree_path" ]]; then
210
+ echo -e "${RED}Error: Worktree not found: $worktree_name${NC}"
211
+ list_worktrees
212
+ return 1
213
+ fi
214
+ fi
215
+
216
+ copy_env_files "$worktree_path"
217
+ echo ""
218
+ }
219
+
220
+ # Clean up completed worktrees
221
+ cleanup_worktrees() {
222
+ if [[ ! -d "$WORKTREE_DIR" ]]; then
223
+ echo -e "${YELLOW}No worktrees to clean up${NC}"
224
+ return
225
+ fi
226
+
227
+ echo -e "${BLUE}Checking for completed worktrees...${NC}"
228
+ echo ""
229
+
230
+ local found=0
231
+ local to_remove=()
232
+
233
+ for worktree_path in "$WORKTREE_DIR"/*; do
234
+ if [[ -d "$worktree_path" && -d "$worktree_path/.git" ]]; then
235
+ local worktree_name=$(basename "$worktree_path")
236
+
237
+ # Skip if current worktree
238
+ if [[ "$PWD" == "$worktree_path" ]]; then
239
+ echo -e "${YELLOW}(skip) $worktree_name - currently active${NC}"
240
+ continue
241
+ fi
242
+
243
+ found=$((found + 1))
244
+ to_remove+=("$worktree_path")
245
+ echo -e "${YELLOW}• $worktree_name${NC}"
246
+ fi
247
+ done
248
+
249
+ if [[ $found -eq 0 ]]; then
250
+ echo -e "${GREEN}No inactive worktrees to clean up${NC}"
251
+ return
252
+ fi
253
+
254
+ echo ""
255
+ echo -e "Remove $found worktree(s)? (y/n)"
256
+ read -r response
257
+
258
+ if [[ "$response" != "y" ]]; then
259
+ echo -e "${YELLOW}Cleanup cancelled${NC}"
260
+ return
261
+ fi
262
+
263
+ echo -e "${BLUE}Cleaning up worktrees...${NC}"
264
+ for worktree_path in "${to_remove[@]}"; do
265
+ local worktree_name=$(basename "$worktree_path")
266
+ git worktree remove "$worktree_path" --force 2>/dev/null || true
267
+ echo -e "${GREEN}✓ Removed: $worktree_name${NC}"
268
+ done
269
+
270
+ # Clean up empty directory if nothing left
271
+ if [[ -z "$(ls -A "$WORKTREE_DIR" 2>/dev/null)" ]]; then
272
+ rmdir "$WORKTREE_DIR" 2>/dev/null || true
273
+ fi
274
+
275
+ echo -e "${GREEN}Cleanup complete!${NC}"
276
+ }
277
+
278
+ # Main command handler
279
+ main() {
280
+ local command="${1:-list}"
281
+
282
+ case "$command" in
283
+ create)
284
+ create_worktree "$2" "$3"
285
+ ;;
286
+ list|ls)
287
+ list_worktrees
288
+ ;;
289
+ switch|go)
290
+ switch_worktree "$2"
291
+ ;;
292
+ copy-env|env)
293
+ copy_env_to_worktree "$2"
294
+ ;;
295
+ cleanup|clean)
296
+ cleanup_worktrees
297
+ ;;
298
+ help)
299
+ show_help
300
+ ;;
301
+ *)
302
+ echo -e "${RED}Unknown command: $command${NC}"
303
+ echo ""
304
+ show_help
305
+ exit 1
306
+ ;;
307
+ esac
308
+ }
309
+
310
+ show_help() {
311
+ cat << EOF
312
+ Git Worktree Manager
313
+
314
+ Usage: worktree-manager.sh <command> [options]
315
+
316
+ Commands:
317
+ create <branch-name> [from-branch] Create new worktree (copies .env files automatically)
318
+ (from-branch defaults to main)
319
+ list | ls List all worktrees
320
+ switch | go [name] Switch to worktree
321
+ copy-env | env [name] Copy .env files from main repo to worktree
322
+ (if name omitted, uses current worktree)
323
+ cleanup | clean Clean up inactive worktrees
324
+ help Show this help message
325
+
326
+ Environment Files:
327
+ - Automatically copies .env, .env.local, .env.test, etc. on create
328
+ - Skips .env.example (should be in git)
329
+ - Creates .backup files if destination already exists
330
+ - Use 'copy-env' to refresh env files after main repo changes
331
+
332
+ Examples:
333
+ worktree-manager.sh create feature-login
334
+ worktree-manager.sh create feature-auth develop
335
+ worktree-manager.sh switch feature-login
336
+ worktree-manager.sh copy-env feature-login
337
+ worktree-manager.sh copy-env # copies to current worktree
338
+ worktree-manager.sh cleanup
339
+ worktree-manager.sh list
340
+
341
+ EOF
342
+ }
343
+
344
+ # Run
345
+ main "$@"