@uniswap/ai-toolkit-nx-claude 0.5.28 → 0.5.30-next.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 (87) hide show
  1. package/dist/cli-generator.cjs +28 -59
  2. package/dist/packages/ai-toolkit-nx-claude/src/cli-generator.d.ts +8 -10
  3. package/dist/packages/ai-toolkit-nx-claude/src/cli-generator.d.ts.map +1 -1
  4. package/dist/packages/ai-toolkit-nx-claude/src/index.d.ts +0 -1
  5. package/dist/packages/ai-toolkit-nx-claude/src/index.d.ts.map +1 -1
  6. package/generators.json +0 -15
  7. package/package.json +4 -35
  8. package/dist/content/agents/agnostic/CLAUDE.md +0 -282
  9. package/dist/content/agents/agnostic/agent-capability-analyst.md +0 -575
  10. package/dist/content/agents/agnostic/agent-optimizer.md +0 -396
  11. package/dist/content/agents/agnostic/agent-orchestrator.md +0 -475
  12. package/dist/content/agents/agnostic/cicd-agent.md +0 -301
  13. package/dist/content/agents/agnostic/claude-agent-discovery.md +0 -304
  14. package/dist/content/agents/agnostic/claude-docs-fact-checker.md +0 -435
  15. package/dist/content/agents/agnostic/claude-docs-initializer.md +0 -782
  16. package/dist/content/agents/agnostic/claude-docs-manager.md +0 -595
  17. package/dist/content/agents/agnostic/code-explainer.md +0 -269
  18. package/dist/content/agents/agnostic/code-generator.md +0 -785
  19. package/dist/content/agents/agnostic/commit-message-generator.md +0 -101
  20. package/dist/content/agents/agnostic/context-loader.md +0 -432
  21. package/dist/content/agents/agnostic/debug-assistant.md +0 -321
  22. package/dist/content/agents/agnostic/doc-writer.md +0 -536
  23. package/dist/content/agents/agnostic/feedback-collector.md +0 -165
  24. package/dist/content/agents/agnostic/infrastructure-agent.md +0 -406
  25. package/dist/content/agents/agnostic/migration-assistant.md +0 -489
  26. package/dist/content/agents/agnostic/pattern-learner.md +0 -481
  27. package/dist/content/agents/agnostic/performance-analyzer.md +0 -528
  28. package/dist/content/agents/agnostic/plan-reviewer.md +0 -173
  29. package/dist/content/agents/agnostic/planner.md +0 -235
  30. package/dist/content/agents/agnostic/pr-creator.md +0 -498
  31. package/dist/content/agents/agnostic/pr-reviewer.md +0 -142
  32. package/dist/content/agents/agnostic/prompt-engineer.md +0 -541
  33. package/dist/content/agents/agnostic/refactorer.md +0 -311
  34. package/dist/content/agents/agnostic/researcher.md +0 -349
  35. package/dist/content/agents/agnostic/security-analyzer.md +0 -1087
  36. package/dist/content/agents/agnostic/stack-splitter.md +0 -642
  37. package/dist/content/agents/agnostic/style-enforcer.md +0 -568
  38. package/dist/content/agents/agnostic/test-runner.md +0 -481
  39. package/dist/content/agents/agnostic/test-writer.md +0 -292
  40. package/dist/content/commands/agnostic/CLAUDE.md +0 -207
  41. package/dist/content/commands/agnostic/address-pr-issues.md +0 -205
  42. package/dist/content/commands/agnostic/auto-spec.md +0 -386
  43. package/dist/content/commands/agnostic/claude-docs.md +0 -409
  44. package/dist/content/commands/agnostic/claude-init-plus.md +0 -439
  45. package/dist/content/commands/agnostic/create-pr.md +0 -79
  46. package/dist/content/commands/agnostic/daily-standup.md +0 -185
  47. package/dist/content/commands/agnostic/deploy.md +0 -441
  48. package/dist/content/commands/agnostic/execute-plan.md +0 -167
  49. package/dist/content/commands/agnostic/explain-file.md +0 -303
  50. package/dist/content/commands/agnostic/explore.md +0 -82
  51. package/dist/content/commands/agnostic/fix-bug.md +0 -273
  52. package/dist/content/commands/agnostic/gen-tests.md +0 -185
  53. package/dist/content/commands/agnostic/generate-commit-message.md +0 -92
  54. package/dist/content/commands/agnostic/git-worktree-orchestrator.md +0 -647
  55. package/dist/content/commands/agnostic/implement-spec.md +0 -270
  56. package/dist/content/commands/agnostic/monitor.md +0 -581
  57. package/dist/content/commands/agnostic/perf-analyze.md +0 -214
  58. package/dist/content/commands/agnostic/plan.md +0 -453
  59. package/dist/content/commands/agnostic/refactor.md +0 -315
  60. package/dist/content/commands/agnostic/refine-linear-task.md +0 -575
  61. package/dist/content/commands/agnostic/research.md +0 -49
  62. package/dist/content/commands/agnostic/review-code.md +0 -321
  63. package/dist/content/commands/agnostic/review-plan.md +0 -109
  64. package/dist/content/commands/agnostic/review-pr.md +0 -393
  65. package/dist/content/commands/agnostic/split-stack.md +0 -705
  66. package/dist/content/commands/agnostic/update-claude-md.md +0 -401
  67. package/dist/content/commands/agnostic/work-through-pr-comments.md +0 -873
  68. package/dist/generators/add-agent/CLAUDE.md +0 -130
  69. package/dist/generators/add-agent/files/__name__.md.template +0 -37
  70. package/dist/generators/add-agent/generator.cjs +0 -640
  71. package/dist/generators/add-agent/schema.json +0 -59
  72. package/dist/generators/add-command/CLAUDE.md +0 -131
  73. package/dist/generators/add-command/files/__name__.md.template +0 -46
  74. package/dist/generators/add-command/generator.cjs +0 -643
  75. package/dist/generators/add-command/schema.json +0 -50
  76. package/dist/generators/files/src/index.ts.template +0 -1
  77. package/dist/generators/init/CLAUDE.md +0 -520
  78. package/dist/generators/init/generator.cjs +0 -3304
  79. package/dist/generators/init/schema.json +0 -180
  80. package/dist/packages/ai-toolkit-nx-claude/src/generators/add-agent/generator.d.ts +0 -5
  81. package/dist/packages/ai-toolkit-nx-claude/src/generators/add-agent/generator.d.ts.map +0 -1
  82. package/dist/packages/ai-toolkit-nx-claude/src/generators/add-command/generator.d.ts +0 -5
  83. package/dist/packages/ai-toolkit-nx-claude/src/generators/add-command/generator.d.ts.map +0 -1
  84. package/dist/packages/ai-toolkit-nx-claude/src/generators/init/generator.d.ts +0 -5
  85. package/dist/packages/ai-toolkit-nx-claude/src/generators/init/generator.d.ts.map +0 -1
  86. package/dist/packages/ai-toolkit-nx-claude/src/utils/auto-update-utils.d.ts +0 -30
  87. package/dist/packages/ai-toolkit-nx-claude/src/utils/auto-update-utils.d.ts.map +0 -1
@@ -1,647 +0,0 @@
1
- ---
2
- name: git-worktree-orchestrator
3
- description: Create and manage a git worktree based on the current directory and a branch name, with optional spec-workflow setup, Graphite integration, and Linear task automation.
4
- argument-hint: <branch-name> [--graphite [--trunk <branch>]] [--setup <script-or-command>] [linear-task-id]
5
- ---
6
-
7
- # Git Worktree Orchestrator
8
-
9
- Create and manage a git worktree based on the current directory and a branch name. After creating the worktree, it copies the .spec-workflow directory, adds the spec-workflow MCP, and can optionally commit/push, open a PR, and clean up the worktree. It also copies other files from the root git worktree into the newly created worktree.
10
-
11
- Supports Graphite integration to track the new branch on top of a trunk branch, and can run a setup script immediately after creating the worktree.
12
-
13
- Optionally accepts a Linear task ID to automatically spawn a new Claude Code instance that will complete the task autonomously.
14
-
15
- ## Usage
16
-
17
- ```bash
18
- # Create worktree for a new branch
19
- /git-worktree-orchestrator add-new-color
20
-
21
- # Create worktree with Graphite tracking (will prompt for trunk branch)
22
- /git-worktree-orchestrator feature/new-ui --graphite
23
-
24
- # Create worktree with Graphite tracking on specific trunk
25
- /git-worktree-orchestrator feature/new-ui --graphite --trunk main
26
-
27
- # Create worktree and run a setup script
28
- /git-worktree-orchestrator feature/setup-test --setup "./scripts/setup-dev.sh"
29
-
30
- # Create worktree and run an inline setup command
31
- /git-worktree-orchestrator feature/npm-setup --setup "npm install && npm run build"
32
-
33
- # Full example with all options
34
- /git-worktree-orchestrator feature/auth-system --graphite --trunk main --setup "npm ci" DEV-1234
35
- ```
36
-
37
- ## Arguments
38
-
39
- - **branch** (required): Branch name to create/use for the worktree
40
- - **--graphite, -g** (optional): Enable Graphite integration to track the branch
41
- - **--trunk <branch>** (optional): Trunk branch name for Graphite tracking (defaults to prompting user, or 'main' if not specified)
42
- - **--setup <script-or-command>** (optional): Setup script file path or inline command to run after creating the worktree
43
- - **linear_task_id** (optional): Linear task ID (e.g., DEV-1234) to complete autonomously in the new worktree
44
-
45
- ## Prerequisites
46
-
47
- - git (2.5+ for worktree support)
48
- - claude CLI (for MCP registration and spawning new instances)
49
- - gh (optional, for PR creation)
50
- - gt (optional, for Graphite integration)
51
-
52
- ## Workflow Steps
53
-
54
- ### Step 1: Directory Setup
55
-
56
- The command detects the appropriate worktrees directory:
57
-
58
- - If already in a worktree (path contains `.worktrees`), extracts the worktrees root
59
- - Otherwise, creates worktrees as a sibling to the repo root (e.g., `repo.worktrees/`)
60
-
61
- ### Step 2: Branch Detection and Worktree Creation
62
-
63
- Handles three scenarios:
64
-
65
- 1. **Local branch exists**: Uses existing branch
66
- 2. **Remote branch exists**: Creates local tracking branch from remote
67
- 3. **New branch**: Creates new branch from current HEAD
68
-
69
- ### Step 3: Spec-Workflow Setup
70
-
71
- Creates a symlink to the `.spec-workflow` directory from the root repository, enabling spec-workflow functionality in the new worktree.
72
-
73
- ### Step 4: Claude Settings Copy
74
-
75
- Copies `.claude/settings.local.json` to the new worktree to preserve local Claude Code settings.
76
-
77
- ### Step 5: MCP Registration
78
-
79
- Registers the spec-workflow MCP with Claude for the new worktree directory:
80
-
81
- ```bash
82
- claude mcp add spec-workflow "npx @uniswap/spec-workflow-mcp@latest" "$NEW_DIR"
83
- ```
84
-
85
- ### Step 6: Graphite Integration (Optional)
86
-
87
- If Graphite is enabled (via `--graphite` flag or user prompt):
88
-
89
- 1. Prompts for trunk branch if not provided via `--trunk`
90
- 2. Runs `gt track` in the new worktree to track the branch on top of the trunk branch
91
-
92
- ```bash
93
- gt track --trunk "$TRUNK_BRANCH"
94
- ```
95
-
96
- ### Step 7: Setup Script Execution (Optional)
97
-
98
- If a setup script is provided (via `--setup` flag or user prompt):
99
-
100
- 1. Detects whether the input is a file path or inline command
101
- 2. If file: validates existence and executes it
102
- 3. If inline command: executes directly in the worktree directory
103
-
104
- ```bash
105
- # File execution
106
- if [[ -f "$SETUP_SCRIPT" ]]; then
107
- bash "$SETUP_SCRIPT"
108
- else
109
- # Inline command execution
110
- eval "$SETUP_SCRIPT"
111
- fi
112
- ```
113
-
114
- ### Step 8: Optional Operations
115
-
116
- Interactive prompts for:
117
-
118
- - **Linear task ID**: Enter task ID if not provided via arguments
119
- - **Commit and push**: Stage and push initial changes
120
- - **Create PR**: Create a pull request via `gh` or provide URL for manual creation
121
- - **Cleanup**: Remove the worktree after work is complete
122
-
123
- ### Step 9: Linear Task Automation
124
-
125
- If a Linear task ID is provided, optionally spawns a new Claude Code instance to:
126
-
127
- 1. Read the Linear task details using Linear MCP tools
128
- 2. Understand requirements and acceptance criteria
129
- 3. Set up the repository (install dependencies, etc.)
130
- 4. Implement the task autonomously
131
- 5. Run tests and linting
132
- 6. Commit changes with descriptive messages
133
- 7. Provide a summary of completed work
134
-
135
- ## Execution Script
136
-
137
- ```bash
138
- #!/usr/bin/env bash
139
- set -euo pipefail
140
-
141
- # Initialize variables
142
- BRANCH=""
143
- LINEAR_TASK_ID=""
144
- USE_GRAPHITE=""
145
- TRUNK_BRANCH=""
146
- SETUP_SCRIPT=""
147
-
148
- # Parse arguments
149
- while [[ $# -gt 0 ]]; do
150
- case "$1" in
151
- --graphite|-g)
152
- USE_GRAPHITE="true"
153
- shift
154
- ;;
155
- --trunk)
156
- if [[ -n "${2:-}" && ! "$2" =~ ^- ]]; then
157
- TRUNK_BRANCH="$2"
158
- shift 2
159
- else
160
- echo "Error: --trunk requires a branch name argument"
161
- exit 1
162
- fi
163
- ;;
164
- --setup)
165
- if [[ -n "${2:-}" && ! "$2" =~ ^- ]]; then
166
- SETUP_SCRIPT="$2"
167
- shift 2
168
- else
169
- echo "Error: --setup requires a script path or command argument"
170
- exit 1
171
- fi
172
- ;;
173
- -*)
174
- echo "Error: Unknown option: $1"
175
- echo "Usage: <command> <branch-name> [--graphite| -g] [--trunk <branch>] [--setup <script-or-command>] [linear-task-id]"
176
- exit 1
177
- ;;
178
- *)
179
- # Positional arguments: first is branch, second is linear_task_id
180
- if [[ -z "$BRANCH" ]]; then
181
- BRANCH="$1"
182
- elif [[ -z "$LINEAR_TASK_ID" ]]; then
183
- LINEAR_TASK_ID="$1"
184
- else
185
- echo "Error: Unexpected argument: $1"
186
- exit 1
187
- fi
188
- shift
189
- ;;
190
- esac
191
- done
192
-
193
- # Also check for env-provided variables as fallback
194
- BRANCH="${BRANCH:-${branch:-}}"
195
- LINEAR_TASK_ID="${LINEAR_TASK_ID:-${linear_task_id:-}}"
196
- USE_GRAPHITE="${USE_GRAPHITE:-${use_graphite:-}}"
197
- TRUNK_BRANCH="${TRUNK_BRANCH:-${trunk_branch:-}}"
198
- SETUP_SCRIPT="${SETUP_SCRIPT:-${setup_script:-}}"
199
-
200
- if [[ -z "${BRANCH:-}" ]]; then
201
- echo "Error: branch name is required."
202
- echo "Usage: <command> <branch-name> [--graphite | -g] [--trunk <branch>] [--setup <script-or-command>] [linear-task-id]"
203
- exit 1
204
- fi
205
-
206
- # Ensure we are inside a git repo
207
- if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
208
- echo "Error: not inside a git repository."
209
- exit 1
210
- fi
211
- REPO_ROOT="$(git rev-parse --show-toplevel)"
212
- CWD="$(pwd)"
213
-
214
- # Determine the worktrees directory
215
- # If we're in a worktree (path contains .worktrees), extract the worktrees root
216
- # Otherwise, create worktrees as a sibling to the repo root
217
- if [[ "$CWD" =~ ^(.*\.worktrees) ]]; then
218
- # We're in a worktree, extract the .worktrees directory path
219
- WORKTREES_DIR="${BASH_REMATCH[1]}"
220
- echo "Detected existing worktrees directory: $WORKTREES_DIR"
221
- else
222
- # We're in the main repo, use/create a .worktrees sibling directory
223
- WORKTREES_DIR="${REPO_ROOT}.worktrees"
224
- echo "Using worktrees directory: $WORKTREES_DIR"
225
- fi
226
-
227
- # Create the worktrees directory if it doesn't exist
228
- mkdir -p "$WORKTREES_DIR"
229
-
230
- NEW_DIR="${WORKTREES_DIR}/${BRANCH}"
231
-
232
- if [[ -e "$NEW_DIR" ]]; then
233
- echo "Target directory already exists: $NEW_DIR"
234
- read -r -p "Continue and reuse it? (y/N): " RESP || true
235
- if [[ ! "$RESP" =~ ^[Yy]$ ]]; then
236
- echo "Aborting."
237
- exit 1
238
- fi
239
- fi
240
-
241
- # Determine branch existence and create the worktree
242
- if git show-ref --verify --quiet "refs/heads/$BRANCH"; then
243
- CREATE_CMD=(git worktree add "$NEW_DIR" "$BRANCH")
244
- elif git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null 2>&1; then
245
- # Remote branch exists; create local tracking branch from it
246
- CREATE_CMD=(git worktree add -b "$BRANCH" "$NEW_DIR" "origin/$BRANCH")
247
- else
248
- # Brand-new branch off current HEAD
249
- CREATE_CMD=(git worktree add -b "$BRANCH" "$NEW_DIR")
250
- fi
251
-
252
- echo "Creating worktree: ${CREATE_CMD[*]}"
253
- "${CREATE_CMD[@]}"
254
-
255
- echo "Worktree created at: $NEW_DIR"
256
-
257
- # Symlink .spec-workflow directory
258
- if [[ -d "$REPO_ROOT/.spec-workflow" ]]; then
259
- echo "Creating symlink for .spec-workflow in new worktree..."
260
- if [[ -e "$NEW_DIR/.spec-workflow" ]]; then
261
- echo "Warning: $NEW_DIR/.spec-workflow already exists"
262
- read -r -p "Remove existing and create symlink? (y/N): " RESP || true
263
- if [[ "$RESP" =~ ^[Yy]$ ]]; then
264
- rm -rf "$NEW_DIR/.spec-workflow"
265
- else
266
- echo "Keeping existing .spec-workflow directory"
267
- fi
268
- fi
269
- if [[ ! -e "$NEW_DIR/.spec-workflow" ]]; then
270
- ln -s "$REPO_ROOT/.spec-workflow" "$NEW_DIR/.spec-workflow"
271
- echo "Symlinked .spec-workflow: $NEW_DIR/.spec-workflow -> $REPO_ROOT/.spec-workflow"
272
- fi
273
- else
274
- echo "No .spec-workflow directory found in $REPO_ROOT; skipping symlink."
275
- fi
276
-
277
- # Copy .claude/settings.local.json file
278
- if [[ -f "$REPO_ROOT/.claude/settings.local.json" ]]; then
279
- echo "Copying .claude/settings.local.json to new worktree..."
280
- mkdir -p "$NEW_DIR/.claude"
281
- if [[ -e "$NEW_DIR/.claude/settings.local.json" ]]; then
282
- echo "Warning: $NEW_DIR/.claude/settings.local.json already exists"
283
- read -r -p "Overwrite existing file? (y/N): " RESP || true
284
- if [[ "$RESP" =~ ^[Yy]$ ]]; then
285
- cp "$REPO_ROOT/.claude/settings.local.json" "$NEW_DIR/.claude/settings.local.json"
286
- echo "Copied .claude/settings.local.json to $NEW_DIR/.claude/"
287
- else
288
- echo "Keeping existing .claude/settings.local.json file"
289
- fi
290
- else
291
- cp "$REPO_ROOT/.claude/settings.local.json" "$NEW_DIR/.claude/settings.local.json"
292
- echo "Copied .claude/settings.local.json to $NEW_DIR/.claude/"
293
- fi
294
- else
295
- echo "No .claude/settings.local.json file found in $REPO_ROOT; skipping copy."
296
- fi
297
-
298
- # Add the spec-workflow MCP to the new project directory
299
- if command -v claude >/dev/null 2>&1; then
300
- echo "Registering spec-workflow MCP with Claude for: $NEW_DIR"
301
- if ! claude mcp add spec-workflow "npx @uniswap/spec-workflow-mcp@latest" "$NEW_DIR"; then
302
- echo "Warning: Failed to add spec-workflow MCP. You can run this manually:"
303
- echo " claude mcp add spec-workflow npx @uniswap/spec-workflow-mcp@latest \"$NEW_DIR\""
304
- fi
305
- else
306
- echo "Warning: 'claude' CLI not found. Skipping MCP registration. Run manually later:"
307
- echo " claude mcp add spec-workflow npx @uniswap/spec-workflow-mcp@latest \"$NEW_DIR\""
308
- fi
309
-
310
- # Prompt for Graphite usage if not specified
311
- if [[ -z "${USE_GRAPHITE:-}" ]]; then
312
- echo ""
313
- read -r -p "Use Graphite to track this branch? (y/N): " GRAPHITE_RESP || true
314
- if [[ "$GRAPHITE_RESP" =~ ^[Yy]$ ]]; then
315
- USE_GRAPHITE="true"
316
- fi
317
- fi
318
-
319
- # Graphite integration
320
- if [[ "${USE_GRAPHITE:-}" == "true" ]]; then
321
- echo ""
322
- echo "============================================"
323
- echo "Graphite Integration"
324
- echo "============================================"
325
-
326
- if ! command -v gt >/dev/null 2>&1; then
327
- echo "Warning: 'gt' (Graphite CLI) not found. Skipping Graphite setup."
328
- echo "Install it from: https://graphite.dev/docs/installing-the-cli"
329
- else
330
- # Prompt for trunk branch if not provided
331
- if [[ -z "${TRUNK_BRANCH:-}" ]]; then
332
- DEFAULT_TRUNK="$(git -C "$NEW_DIR" remote show origin 2>/dev/null | sed -n 's/.*HEAD branch: //p')" || DEFAULT_TRUNK=""
333
- DEFAULT_TRUNK="${DEFAULT_TRUNK:-main}"
334
- read -r -p "Enter trunk branch name [$DEFAULT_TRUNK]: " TRUNK_INPUT || true
335
- TRUNK_BRANCH="${TRUNK_INPUT:-$DEFAULT_TRUNK}"
336
- fi
337
-
338
- echo "Tracking branch '$BRANCH' on top of trunk '$TRUNK_BRANCH'..."
339
- if ! gt -C "$NEW_DIR" track --trunk "$TRUNK_BRANCH"; then
340
- echo "Warning: Failed to track branch with Graphite. You can run this manually:"
341
- echo " cd \"$NEW_DIR\" && gt track --trunk \"$TRUNK_BRANCH\""
342
- else
343
- echo "Successfully tracked branch with Graphite."
344
- fi
345
- fi
346
- fi
347
-
348
- # Prompt for setup script if not provided
349
- if [[ -z "${SETUP_SCRIPT:-}" ]]; then
350
- echo ""
351
- read -r -p "Run a setup script/command in the new worktree? (y/N): " SETUP_RESP || true
352
- if [[ "$SETUP_RESP" =~ ^[Yy]$ ]]; then
353
- read -r -p "Enter script path or inline command: " SETUP_SCRIPT || true
354
- fi
355
- fi
356
-
357
- # Execute setup script if provided
358
- if [[ -n "${SETUP_SCRIPT:-}" ]]; then
359
- echo ""
360
- echo "============================================"
361
- echo "Running Setup Script"
362
- echo "============================================"
363
- echo "Executing: $SETUP_SCRIPT"
364
- echo ""
365
-
366
- # Change to the new worktree directory for script execution
367
- pushd "$NEW_DIR" >/dev/null
368
-
369
- # Check if it's a file path (absolute or relative to original directory)
370
- SCRIPT_PATH=""
371
- if [[ -f "$SETUP_SCRIPT" ]]; then
372
- SCRIPT_PATH="$SETUP_SCRIPT"
373
- elif [[ -f "$CWD/$SETUP_SCRIPT" ]]; then
374
- SCRIPT_PATH="$CWD/$SETUP_SCRIPT"
375
- elif [[ -f "$REPO_ROOT/$SETUP_SCRIPT" ]]; then
376
- SCRIPT_PATH="$REPO_ROOT/$SETUP_SCRIPT"
377
- fi
378
-
379
- if [[ -n "$SCRIPT_PATH" ]]; then
380
- echo "Running script file: $SCRIPT_PATH"
381
- if [[ -x "$SCRIPT_PATH" ]]; then
382
- "$SCRIPT_PATH"
383
- else
384
- bash "$SCRIPT_PATH"
385
- fi
386
- else
387
- # Treat as inline command
388
- echo "Running inline command..."
389
- eval "$SETUP_SCRIPT"
390
- fi
391
-
392
- SETUP_EXIT_CODE=$?
393
- popd >/dev/null
394
-
395
- if [[ $SETUP_EXIT_CODE -eq 0 ]]; then
396
- echo "Setup script completed successfully."
397
- else
398
- echo "Warning: Setup script exited with code $SETUP_EXIT_CODE"
399
- fi
400
- fi
401
-
402
- # Prompt for Linear task ID if not provided
403
- if [[ -z "${LINEAR_TASK_ID:-}" ]]; then
404
- echo ""
405
- read -r -p "Enter Linear task ID (optional, press Enter to skip): " LINEAR_TASK_ID || true
406
- LINEAR_TASK_ID="${LINEAR_TASK_ID:-}"
407
- fi
408
-
409
- # Optionally commit and push changes
410
- read -r -p "Commit and push changes from $NEW_DIR now? (y/N): " DO_CP || true
411
- if [[ "$DO_CP" =~ ^[Yy]$ ]]; then
412
- read -r -p "Commit message [chore: initial setup for $BRANCH]: " COMMIT_MSG || true
413
- COMMIT_MSG="${COMMIT_MSG:-chore: initial setup for $BRANCH}"
414
- git -C "$NEW_DIR" add -A
415
- if git -C "$NEW_DIR" diff --cached --quiet; then
416
- echo "No changes to commit in $NEW_DIR."
417
- else
418
- git -C "$NEW_DIR" commit -m "$COMMIT_MSG"
419
- fi
420
- # Push branch (set upstream if needed)
421
- if git -C "$NEW_DIR" rev-parse --symbolic-full-name --abbrev-ref @{u} >/dev/null 2>&1; then
422
- git -C "$NEW_DIR" push
423
- else
424
- git -C "$NEW_DIR" push -u origin "$BRANCH"
425
- fi
426
- fi
427
-
428
- # Optionally create a PR
429
- read -r -p "Create a pull request for $BRANCH? (y/N): " DO_PR || true
430
- if [[ "$DO_PR" =~ ^[Yy]$ ]]; then
431
- DEFAULT_BASE="$(git -C "$NEW_DIR" remote show origin 2>/dev/null | sed -n 's/.*HEAD branch: //p')" || DEFAULT_BASE=""
432
- if [[ -z "$DEFAULT_BASE" ]]; then
433
- echo "Warning: Could not detect default branch from remote. Using 'main'."
434
- fi
435
- DEFAULT_BASE="${DEFAULT_BASE:-main}"
436
- if command -v gh >/dev/null 2>&1; then
437
- if ! gh -C "$NEW_DIR" pr create --fill --base "$DEFAULT_BASE" --head "$BRANCH"; then
438
- echo "Warning: PR creation with 'gh' failed."
439
- fi
440
- else
441
- ORIGIN_URL="$(git -C "$NEW_DIR" remote get-url origin)"
442
- REPO_SLUG=""
443
- if [[ "$ORIGIN_URL" =~ ^git@github.com:(.*)\\.git$ ]]; then
444
- REPO_SLUG="${BASH_REMATCH[1]}"
445
- elif [[ "$ORIGIN_URL" =~ ^https://github.com/(.*)\\.git$ ]]; then
446
- REPO_SLUG="${BASH_REMATCH[1]}"
447
- elif [[ "$ORIGIN_URL" =~ ^https://github.com/(.*)$ ]]; then
448
- REPO_SLUG="${BASH_REMATCH[1]}"
449
- fi
450
- if [[ -n "$REPO_SLUG" ]]; then
451
- PR_URL="https://github.com/${REPO_SLUG}/compare/${DEFAULT_BASE}...${BRANCH}?expand=1"
452
- echo "Open this URL to create a PR:"
453
- echo " $PR_URL"
454
- if command -v open >/dev/null 2>&1; then
455
- read -r -p "Open PR URL in browser now? (y/N): " DO_OPEN || true
456
- [[ "$DO_OPEN" =~ ^[Yy]$ ]] && open "$PR_URL" || true
457
- fi
458
- else
459
- echo "Could not parse origin URL; open a PR manually on your hosting provider."
460
- fi
461
- fi
462
- fi
463
-
464
- # Optionally clean up the worktree
465
- read -r -p "Remove the worktree $NEW_DIR from the main repo now? (y/N): " DO_CLEAN || true
466
- if [[ "$DO_CLEAN" =~ ^[Yy]$ ]]; then
467
- # Ensure we are not in the worktree being removed
468
- if [[ "$PWD" == "$NEW_DIR" ]]; then
469
- echo "You are currently in the worktree. Please change directories and run cleanup again."
470
- else
471
- if ! git -C "$REPO_ROOT" worktree remove "$NEW_DIR"; then
472
- read -r -p "Worktree removal failed. Force removal? (y/N): " DO_FORCE || true
473
- [[ "$DO_FORCE" =~ ^[Yy]$ ]] && git -C "$REPO_ROOT" worktree remove --force "$NEW_DIR" || true
474
- fi
475
- fi
476
- fi
477
-
478
- # Spawn new Claude Code instance to complete Linear task autonomously
479
- if [[ -n "${LINEAR_TASK_ID:-}" ]]; then
480
- echo ""
481
- echo "============================================"
482
- echo "Linear Task Integration"
483
- echo "============================================"
484
- echo "Linear task ID provided: $LINEAR_TASK_ID"
485
- echo ""
486
-
487
- if command -v claude >/dev/null 2>&1; then
488
- read -r -p "Launch new Claude Code instance to complete this task autonomously? (y/N): " DO_LAUNCH || true
489
- if [[ "$DO_LAUNCH" =~ ^[Yy]$ ]]; then
490
- echo "Spawning new Claude Code instance in $NEW_DIR..."
491
- echo ""
492
-
493
- # Create a prompt file for the autonomous task completion
494
- PROMPT="I'm working in a new git worktree to complete Linear task $LINEAR_TASK_ID.
495
-
496
- Please:
497
- 1. Read the Linear task details using the Linear MCP tools
498
- 2. Understand the requirements and acceptance criteria
499
- 3. Set up the repository if needed (install dependencies, etc.)
500
- 4. Implement the task autonomously
501
- 5. Run tests and linting to ensure quality
502
- 6. Commit the changes with a descriptive commit message
503
- 7. Provide a summary of what was completed
504
-
505
- Work autonomously and make reasonable decisions to complete the task efficiently."
506
-
507
- # Launch Claude Code with the prompt (use absolute path instead of cd)
508
- echo "Opening Claude Code in $NEW_DIR with task completion prompt..."
509
- claude "$NEW_DIR" --prompt "$PROMPT" &
510
-
511
- echo "New Claude Code instance launched in background."
512
- echo "Check the new window/tab for progress."
513
- echo ""
514
- else
515
- echo "Skipping automatic task completion."
516
- echo "You can manually work on task $LINEAR_TASK_ID in: $NEW_DIR"
517
- echo ""
518
- fi
519
- else
520
- echo "Warning: 'claude' CLI not found. Cannot spawn new instance."
521
- echo "Install it to use automatic task completion: https://claude.ai/download"
522
- echo "You can manually work on task $LINEAR_TASK_ID in: $NEW_DIR"
523
- echo ""
524
- fi
525
- fi
526
-
527
- echo ""
528
- echo "============================================"
529
- echo "Done! Worktree created at: $NEW_DIR"
530
- echo "============================================"
531
- echo ""
532
- echo "To change to the new worktree directory, run:"
533
- echo " cd \"$NEW_DIR\""
534
- echo ""
535
- if [[ -n "${LINEAR_TASK_ID:-}" ]]; then
536
- echo "Linear task: $LINEAR_TASK_ID"
537
- echo ""
538
- fi
539
- ```
540
-
541
- ## Worktree Directory Structure
542
-
543
- The command creates worktrees in a sibling directory pattern:
544
-
545
- ```text
546
- /path/to/repo/ # Main repository
547
- /path/to/repo.worktrees/ # Worktrees directory
548
- ├── feature-branch-1/ # Worktree for feature-branch-1
549
- ├── feature-branch-2/ # Worktree for feature-branch-2
550
- └── bugfix-123/ # Worktree for bugfix-123
551
- ```
552
-
553
- ## Integration Notes
554
-
555
- - **Spec Workflow**: Symlinks `.spec-workflow` from the main repo to enable spec-workflow MCP functionality
556
- - **Claude Settings**: Copies local Claude settings to maintain consistent behavior
557
- - **Linear Integration**: Supports autonomous task completion when provided with a Linear task ID
558
- - **Graphite Integration**: Built-in support for `gt track` to manage branch stacks; tracks new branches on specified trunk
559
- - **Setup Scripts**: Runs custom setup scripts or commands (e.g., `npm install`, `./scripts/setup.sh`) after worktree creation
560
-
561
- ## Merging Work Back
562
-
563
- After completing work in a worktree:
564
-
565
- 1. **Commit and push** changes from the worktree
566
- 2. **Create a PR** using `/create-pr` or `gh pr create`
567
- 3. **Merge the PR** through your normal review process
568
- 4. **Clean up** the worktree when done
569
-
570
- Or use `/split-stack` if you need to break your changes into multiple PRs.
571
-
572
- ## Related Commands
573
-
574
- - `/create-pr`: Create pull requests with auto-generated messages
575
- - `/split-stack`: Split large changes into reviewable PR stacks
576
- - `/implement-spec`: Implement spec-workflow tasks
577
- - `/auto-spec`: Autonomous spec-driven development
578
-
579
- ## Troubleshooting
580
-
581
- ### "Error: not inside a git repository"
582
-
583
- **Solution:** Ensure you're running the command from within a git repository.
584
-
585
- ### "Target directory already exists"
586
-
587
- **Solution:** Either reuse the existing worktree or remove it first:
588
-
589
- ```bash
590
- git worktree remove /path/to/repo.worktrees/branch-name
591
- ```
592
-
593
- ### "Failed to add spec-workflow MCP"
594
-
595
- **Solution:** Run the MCP registration manually:
596
-
597
- ```bash
598
- claude mcp add spec-workflow "npx @uniswap/spec-workflow-mcp@latest" "/path/to/worktree"
599
- ```
600
-
601
- ### "claude CLI not found"
602
-
603
- **Solution:** Install Claude Code from <https://claude.ai/download>
604
-
605
- ### "gt (Graphite CLI) not found"
606
-
607
- **Solution:** Install the Graphite CLI:
608
-
609
- ```bash
610
- npm install -g @withgraphite/graphite-cli
611
- ```
612
-
613
- Or follow the installation guide at <https://graphite.dev/docs/installing-the-cli>
614
-
615
- ### "Failed to track branch with Graphite"
616
-
617
- **Solution:** Ensure you're in a Graphite-enabled repository and the trunk branch exists:
618
-
619
- ```bash
620
- cd /path/to/worktree
621
- gt init # If not already initialized
622
- gt track --trunk main
623
- ```
624
-
625
- ### "Setup script failed"
626
-
627
- **Solution:** Check that your script:
628
-
629
- 1. Exists at the specified path (relative to CWD or repo root)
630
- 2. Has proper execute permissions (`chmod +x script.sh`)
631
- 3. Returns exit code 0 on success
632
-
633
- You can test the script manually:
634
-
635
- ```bash
636
- cd /path/to/worktree
637
- ./your-script.sh # or: bash your-script.sh
638
- ```
639
-
640
- ### "Setup command not found"
641
-
642
- **Solution:** Inline commands are executed with `eval` in the worktree directory. Ensure:
643
-
644
- 1. The command is available in your PATH
645
- 2. You're using proper shell syntax for chained commands (`&&` for sequential, `;` for independent)
646
-
647
- Arguments: $ARGUMENTS