@uniswap/ai-toolkit-nx-claude 0.5.17 → 0.5.18-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.
@@ -4,7 +4,7 @@
4
4
 
5
5
  Language-agnostic slash command definitions for Claude Code. Each markdown file defines a command's behavior, parameters, and usage. These are the core commands available in the AI Toolkit.
6
6
 
7
- ## Command Files (26 total)
7
+ ## Command Files (27 total)
8
8
 
9
9
  ### Core Workflow Commands
10
10
 
@@ -35,6 +35,7 @@ Language-agnostic slash command definitions for Claude Code. Each markdown file
35
35
  - `work-through-pr-comments.md` - Methodically work through PR comments
36
36
  - `generate-commit-message.md` - Generate structured commit messages
37
37
  - `split-stack.md` - Split Graphite PR stacks
38
+ - `git-worktree-orchestrator.md` - Create and manage git worktrees with spec-workflow and Linear integration
38
39
 
39
40
  ### Documentation
40
41
 
@@ -0,0 +1,410 @@
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 and Linear task automation.
4
+ argument-hint: <branch-name> [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
+ Optionally accepts a Linear task ID to automatically spawn a new Claude Code instance that will complete the task autonomously.
12
+
13
+ ## Usage
14
+
15
+ ```bash
16
+ # Create worktree for a new branch
17
+ /git-worktree-orchestrator add-new-color
18
+
19
+ # Create worktree and attach a Linear task for autonomous completion
20
+ /git-worktree-orchestrator feature/auth-system DEV-1234
21
+ ```
22
+
23
+ ## Arguments
24
+
25
+ - **branch** (required): Branch name to create/use for the worktree
26
+ - **linear_task_id** (optional): Linear task ID (e.g., DEV-1234) to complete autonomously in the new worktree
27
+
28
+ ## Prerequisites
29
+
30
+ - git (2.5+ for worktree support)
31
+ - claude CLI (for MCP registration and spawning new instances)
32
+ - gh (optional, for PR creation)
33
+
34
+ ## Workflow Steps
35
+
36
+ ### Step 1: Directory Setup
37
+
38
+ The command detects the appropriate worktrees directory:
39
+
40
+ - If already in a worktree (path contains `.worktrees`), extracts the worktrees root
41
+ - Otherwise, creates worktrees as a sibling to the repo root (e.g., `repo.worktrees/`)
42
+
43
+ ### Step 2: Branch Detection and Worktree Creation
44
+
45
+ Handles three scenarios:
46
+
47
+ 1. **Local branch exists**: Uses existing branch
48
+ 2. **Remote branch exists**: Creates local tracking branch from remote
49
+ 3. **New branch**: Creates new branch from current HEAD
50
+
51
+ ### Step 3: Spec-Workflow Setup
52
+
53
+ Creates a symlink to the `.spec-workflow` directory from the root repository, enabling spec-workflow functionality in the new worktree.
54
+
55
+ ### Step 4: Claude Settings Copy
56
+
57
+ Copies `.claude/settings.local.json` to the new worktree to preserve local Claude Code settings.
58
+
59
+ ### Step 5: MCP Registration
60
+
61
+ Registers the spec-workflow MCP with Claude for the new worktree directory:
62
+
63
+ ```bash
64
+ claude mcp add spec-workflow "npx @uniswap/spec-workflow-mcp@latest" "$NEW_DIR"
65
+ ```
66
+
67
+ ### Step 6: Optional Operations
68
+
69
+ Interactive prompts for:
70
+
71
+ - **Linear task ID**: Enter task ID if not provided via arguments
72
+ - **Commit and push**: Stage and push initial changes
73
+ - **Create PR**: Create a pull request via `gh` or provide URL for manual creation
74
+ - **Cleanup**: Remove the worktree after work is complete
75
+
76
+ ### Step 7: Linear Task Automation
77
+
78
+ If a Linear task ID is provided, optionally spawns a new Claude Code instance to:
79
+
80
+ 1. Read the Linear task details using Linear MCP tools
81
+ 2. Understand requirements and acceptance criteria
82
+ 3. Set up the repository (install dependencies, etc.)
83
+ 4. Implement the task autonomously
84
+ 5. Run tests and linting
85
+ 6. Commit changes with descriptive messages
86
+ 7. Provide a summary of completed work
87
+
88
+ ## Execution Script
89
+
90
+ ```bash
91
+ #!/usr/bin/env bash
92
+ set -euo pipefail
93
+
94
+ # Accept arguments from positional or env-provided variables (depending on Claude Code runtime)
95
+ BRANCH="${1:-${branch:-}}"
96
+ LINEAR_TASK_ID="${2:-${linear_task_id:-}}"
97
+
98
+ if [[ -z "${BRANCH:-}" ]]; then
99
+ echo "Error: branch name is required."
100
+ echo "Usage: <command> <branch-name> [linear-task-id]"
101
+ exit 1
102
+ fi
103
+
104
+ # Ensure we are inside a git repo
105
+ if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
106
+ echo "Error: not inside a git repository."
107
+ exit 1
108
+ fi
109
+ REPO_ROOT="$(git rev-parse --show-toplevel)"
110
+ CWD="$(pwd)"
111
+
112
+ # Determine the worktrees directory
113
+ # If we're in a worktree (path contains .worktrees), extract the worktrees root
114
+ # Otherwise, create worktrees as a sibling to the repo root
115
+ if [[ "$CWD" =~ ^(.*\.worktrees) ]]; then
116
+ # We're in a worktree, extract the .worktrees directory path
117
+ WORKTREES_DIR="${BASH_REMATCH[1]}"
118
+ echo "Detected existing worktrees directory: $WORKTREES_DIR"
119
+ else
120
+ # We're in the main repo, use/create a .worktrees sibling directory
121
+ WORKTREES_DIR="${REPO_ROOT}.worktrees"
122
+ echo "Using worktrees directory: $WORKTREES_DIR"
123
+ fi
124
+
125
+ # Create the worktrees directory if it doesn't exist
126
+ mkdir -p "$WORKTREES_DIR"
127
+
128
+ NEW_DIR="${WORKTREES_DIR}/${BRANCH}"
129
+
130
+ if [[ -e "$NEW_DIR" ]]; then
131
+ echo "Target directory already exists: $NEW_DIR"
132
+ read -r -p "Continue and reuse it? (y/N): " RESP || true
133
+ if [[ ! "$RESP" =~ ^[Yy]$ ]]; then
134
+ echo "Aborting."
135
+ exit 1
136
+ fi
137
+ fi
138
+
139
+ # Determine branch existence and create the worktree
140
+ if git show-ref --verify --quiet "refs/heads/$BRANCH"; then
141
+ CREATE_CMD=(git worktree add "$NEW_DIR" "$BRANCH")
142
+ elif git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null 2>&1; then
143
+ # Remote branch exists; create local tracking branch from it
144
+ CREATE_CMD=(git worktree add -b "$BRANCH" "$NEW_DIR" "origin/$BRANCH")
145
+ else
146
+ # Brand-new branch off current HEAD
147
+ CREATE_CMD=(git worktree add -b "$BRANCH" "$NEW_DIR")
148
+ fi
149
+
150
+ echo "Creating worktree: ${CREATE_CMD[*]}"
151
+ "${CREATE_CMD[@]}"
152
+
153
+ echo "Worktree created at: $NEW_DIR"
154
+
155
+ # Symlink .spec-workflow directory
156
+ if [[ -d "$REPO_ROOT/.spec-workflow" ]]; then
157
+ echo "Creating symlink for .spec-workflow in new worktree..."
158
+ if [[ -e "$NEW_DIR/.spec-workflow" ]]; then
159
+ echo "Warning: $NEW_DIR/.spec-workflow already exists"
160
+ read -r -p "Remove existing and create symlink? (y/N): " RESP || true
161
+ if [[ "$RESP" =~ ^[Yy]$ ]]; then
162
+ rm -rf "$NEW_DIR/.spec-workflow"
163
+ else
164
+ echo "Keeping existing .spec-workflow directory"
165
+ fi
166
+ fi
167
+ if [[ ! -e "$NEW_DIR/.spec-workflow" ]]; then
168
+ ln -s "$REPO_ROOT/.spec-workflow" "$NEW_DIR/.spec-workflow"
169
+ echo "Symlinked .spec-workflow: $NEW_DIR/.spec-workflow -> $REPO_ROOT/.spec-workflow"
170
+ fi
171
+ else
172
+ echo "No .spec-workflow directory found in $REPO_ROOT; skipping symlink."
173
+ fi
174
+
175
+ # Copy .claude/settings.local.json file
176
+ if [[ -f "$REPO_ROOT/.claude/settings.local.json" ]]; then
177
+ echo "Copying .claude/settings.local.json to new worktree..."
178
+ mkdir -p "$NEW_DIR/.claude"
179
+ if [[ -e "$NEW_DIR/.claude/settings.local.json" ]]; then
180
+ echo "Warning: $NEW_DIR/.claude/settings.local.json already exists"
181
+ read -r -p "Overwrite existing file? (y/N): " RESP || true
182
+ if [[ "$RESP" =~ ^[Yy]$ ]]; then
183
+ cp "$REPO_ROOT/.claude/settings.local.json" "$NEW_DIR/.claude/settings.local.json"
184
+ echo "Copied .claude/settings.local.json to $NEW_DIR/.claude/"
185
+ else
186
+ echo "Keeping existing .claude/settings.local.json file"
187
+ fi
188
+ else
189
+ cp "$REPO_ROOT/.claude/settings.local.json" "$NEW_DIR/.claude/settings.local.json"
190
+ echo "Copied .claude/settings.local.json to $NEW_DIR/.claude/"
191
+ fi
192
+ else
193
+ echo "No .claude/settings.local.json file found in $REPO_ROOT; skipping copy."
194
+ fi
195
+
196
+ # Add the spec-workflow MCP to the new project directory
197
+ if command -v claude >/dev/null 2>&1; then
198
+ echo "Registering spec-workflow MCP with Claude for: $NEW_DIR"
199
+ if ! claude mcp add spec-workflow "npx @uniswap/spec-workflow-mcp@latest" "$NEW_DIR"; then
200
+ echo "Warning: Failed to add spec-workflow MCP. You can run this manually:"
201
+ echo " claude mcp add spec-workflow npx @uniswap/spec-workflow-mcp@latest \"$NEW_DIR\""
202
+ fi
203
+ else
204
+ echo "Warning: 'claude' CLI not found. Skipping MCP registration. Run manually later:"
205
+ echo " claude mcp add spec-workflow npx @uniswap/spec-workflow-mcp@latest \"$NEW_DIR\""
206
+ fi
207
+
208
+ # Prompt for Linear task ID if not provided
209
+ if [[ -z "${LINEAR_TASK_ID:-}" ]]; then
210
+ echo ""
211
+ read -r -p "Enter Linear task ID (optional, press Enter to skip): " LINEAR_TASK_ID || true
212
+ LINEAR_TASK_ID="${LINEAR_TASK_ID:-}"
213
+ fi
214
+
215
+ # Optionally commit and push changes
216
+ read -r -p "Commit and push changes from $NEW_DIR now? (y/N): " DO_CP || true
217
+ if [[ "$DO_CP" =~ ^[Yy]$ ]]; then
218
+ read -r -p "Commit message [chore: initial setup for $BRANCH]: " COMMIT_MSG || true
219
+ COMMIT_MSG="${COMMIT_MSG:-chore: initial setup for $BRANCH}"
220
+ git -C "$NEW_DIR" add -A
221
+ if git -C "$NEW_DIR" diff --cached --quiet; then
222
+ echo "No changes to commit in $NEW_DIR."
223
+ else
224
+ git -C "$NEW_DIR" commit -m "$COMMIT_MSG"
225
+ fi
226
+ # Push branch (set upstream if needed)
227
+ if git -C "$NEW_DIR" rev-parse --symbolic-full-name --abbrev-ref @{u} >/dev/null 2>&1; then
228
+ git -C "$NEW_DIR" push
229
+ else
230
+ git -C "$NEW_DIR" push -u origin "$BRANCH"
231
+ fi
232
+ fi
233
+
234
+ # Optionally create a PR
235
+ read -r -p "Create a pull request for $BRANCH? (y/N): " DO_PR || true
236
+ if [[ "$DO_PR" =~ ^[Yy]$ ]]; then
237
+ DEFAULT_BASE="$(git -C "$NEW_DIR" remote show origin 2>/dev/null | sed -n 's/.*HEAD branch: //p')" || DEFAULT_BASE=""
238
+ if [[ -z "$DEFAULT_BASE" ]]; then
239
+ echo "Warning: Could not detect default branch from remote. Using 'main'."
240
+ fi
241
+ DEFAULT_BASE="${DEFAULT_BASE:-main}"
242
+ if command -v gh >/dev/null 2>&1; then
243
+ if ! gh -C "$NEW_DIR" pr create --fill --base "$DEFAULT_BASE" --head "$BRANCH"; then
244
+ echo "Warning: PR creation with 'gh' failed."
245
+ fi
246
+ else
247
+ ORIGIN_URL="$(git -C "$NEW_DIR" remote get-url origin)"
248
+ REPO_SLUG=""
249
+ if [[ "$ORIGIN_URL" =~ ^git@github.com:(.*)\\.git$ ]]; then
250
+ REPO_SLUG="${BASH_REMATCH[1]}"
251
+ elif [[ "$ORIGIN_URL" =~ ^https://github.com/(.*)\\.git$ ]]; then
252
+ REPO_SLUG="${BASH_REMATCH[1]}"
253
+ elif [[ "$ORIGIN_URL" =~ ^https://github.com/(.*)$ ]]; then
254
+ REPO_SLUG="${BASH_REMATCH[1]}"
255
+ fi
256
+ if [[ -n "$REPO_SLUG" ]]; then
257
+ PR_URL="https://github.com/${REPO_SLUG}/compare/${DEFAULT_BASE}...${BRANCH}?expand=1"
258
+ echo "Open this URL to create a PR:"
259
+ echo " $PR_URL"
260
+ if command -v open >/dev/null 2>&1; then
261
+ read -r -p "Open PR URL in browser now? (y/N): " DO_OPEN || true
262
+ [[ "$DO_OPEN" =~ ^[Yy]$ ]] && open "$PR_URL" || true
263
+ fi
264
+ else
265
+ echo "Could not parse origin URL; open a PR manually on your hosting provider."
266
+ fi
267
+ fi
268
+ fi
269
+
270
+ # Optionally clean up the worktree
271
+ read -r -p "Remove the worktree $NEW_DIR from the main repo now? (y/N): " DO_CLEAN || true
272
+ if [[ "$DO_CLEAN" =~ ^[Yy]$ ]]; then
273
+ # Ensure we are not in the worktree being removed
274
+ if [[ "$PWD" == "$NEW_DIR" ]]; then
275
+ echo "You are currently in the worktree. Please change directories and run cleanup again."
276
+ else
277
+ if ! git -C "$REPO_ROOT" worktree remove "$NEW_DIR"; then
278
+ read -r -p "Worktree removal failed. Force removal? (y/N): " DO_FORCE || true
279
+ [[ "$DO_FORCE" =~ ^[Yy]$ ]] && git -C "$REPO_ROOT" worktree remove --force "$NEW_DIR" || true
280
+ fi
281
+ fi
282
+ fi
283
+
284
+ # Spawn new Claude Code instance to complete Linear task autonomously
285
+ if [[ -n "${LINEAR_TASK_ID:-}" ]]; then
286
+ echo ""
287
+ echo "============================================"
288
+ echo "Linear Task Integration"
289
+ echo "============================================"
290
+ echo "Linear task ID provided: $LINEAR_TASK_ID"
291
+ echo ""
292
+
293
+ if command -v claude >/dev/null 2>&1; then
294
+ read -r -p "Launch new Claude Code instance to complete this task autonomously? (y/N): " DO_LAUNCH || true
295
+ if [[ "$DO_LAUNCH" =~ ^[Yy]$ ]]; then
296
+ echo "Spawning new Claude Code instance in $NEW_DIR..."
297
+ echo ""
298
+
299
+ # Create a prompt file for the autonomous task completion
300
+ PROMPT="I'm working in a new git worktree to complete Linear task $LINEAR_TASK_ID.
301
+
302
+ Please:
303
+ 1. Read the Linear task details using the Linear MCP tools
304
+ 2. Understand the requirements and acceptance criteria
305
+ 3. Set up the repository if needed (install dependencies, etc.)
306
+ 4. Implement the task autonomously
307
+ 5. Run tests and linting to ensure quality
308
+ 6. Commit the changes with a descriptive commit message
309
+ 7. Provide a summary of what was completed
310
+
311
+ Work autonomously and make reasonable decisions to complete the task efficiently."
312
+
313
+ # Launch Claude Code with the prompt (use absolute path instead of cd)
314
+ echo "Opening Claude Code in $NEW_DIR with task completion prompt..."
315
+ claude "$NEW_DIR" --prompt "$PROMPT" &
316
+
317
+ echo "New Claude Code instance launched in background."
318
+ echo "Check the new window/tab for progress."
319
+ echo ""
320
+ else
321
+ echo "Skipping automatic task completion."
322
+ echo "You can manually work on task $LINEAR_TASK_ID in: $NEW_DIR"
323
+ echo ""
324
+ fi
325
+ else
326
+ echo "Warning: 'claude' CLI not found. Cannot spawn new instance."
327
+ echo "Install it to use automatic task completion: https://claude.ai/download"
328
+ echo "You can manually work on task $LINEAR_TASK_ID in: $NEW_DIR"
329
+ echo ""
330
+ fi
331
+ fi
332
+
333
+ echo ""
334
+ echo "============================================"
335
+ echo "Done! Worktree created at: $NEW_DIR"
336
+ echo "============================================"
337
+ echo ""
338
+ echo "To change to the new worktree directory, run:"
339
+ echo " cd \"$NEW_DIR\""
340
+ echo ""
341
+ if [[ -n "${LINEAR_TASK_ID:-}" ]]; then
342
+ echo "Linear task: $LINEAR_TASK_ID"
343
+ echo ""
344
+ fi
345
+ ```
346
+
347
+ ## Worktree Directory Structure
348
+
349
+ The command creates worktrees in a sibling directory pattern:
350
+
351
+ ```text
352
+ /path/to/repo/ # Main repository
353
+ /path/to/repo.worktrees/ # Worktrees directory
354
+ ├── feature-branch-1/ # Worktree for feature-branch-1
355
+ ├── feature-branch-2/ # Worktree for feature-branch-2
356
+ └── bugfix-123/ # Worktree for bugfix-123
357
+ ```
358
+
359
+ ## Integration Notes
360
+
361
+ - **Spec Workflow**: Symlinks `.spec-workflow` from the main repo to enable spec-workflow MCP functionality
362
+ - **Claude Settings**: Copies local Claude settings to maintain consistent behavior
363
+ - **Linear Integration**: Supports autonomous task completion when provided with a Linear task ID
364
+ - **Graphite Compatible**: Works alongside Graphite for PR stack management
365
+
366
+ ## Merging Work Back
367
+
368
+ After completing work in a worktree:
369
+
370
+ 1. **Commit and push** changes from the worktree
371
+ 2. **Create a PR** using `/create-pr` or `gh pr create`
372
+ 3. **Merge the PR** through your normal review process
373
+ 4. **Clean up** the worktree when done
374
+
375
+ Or use `/split-stack` if you need to break your changes into multiple PRs.
376
+
377
+ ## Related Commands
378
+
379
+ - `/create-pr`: Create pull requests with auto-generated messages
380
+ - `/split-stack`: Split large changes into reviewable PR stacks
381
+ - `/implement-spec`: Implement spec-workflow tasks
382
+ - `/auto-spec`: Autonomous spec-driven development
383
+
384
+ ## Troubleshooting
385
+
386
+ ### "Error: not inside a git repository"
387
+
388
+ **Solution:** Ensure you're running the command from within a git repository.
389
+
390
+ ### "Target directory already exists"
391
+
392
+ **Solution:** Either reuse the existing worktree or remove it first:
393
+
394
+ ```bash
395
+ git worktree remove /path/to/repo.worktrees/branch-name
396
+ ```
397
+
398
+ ### "Failed to add spec-workflow MCP"
399
+
400
+ **Solution:** Run the MCP registration manually:
401
+
402
+ ```bash
403
+ claude mcp add spec-workflow "npx @uniswap/spec-workflow-mcp@latest" "/path/to/worktree"
404
+ ```
405
+
406
+ ### "claude CLI not found"
407
+
408
+ **Solution:** Install Claude Code from <https://claude.ai/download>
409
+
410
+ Arguments: $ARGUMENTS
@@ -1132,6 +1132,10 @@ var commands = {
1132
1132
  description: "Generate a structured git commit message based on current changes and repository patterns",
1133
1133
  filePath: "./generate-commit-message.md"
1134
1134
  },
1135
+ "git-worktree-orchestrator": {
1136
+ description: "Create and manage a git worktree based on the current directory and a branch name, with optional spec-workflow setup and Linear task automation.",
1137
+ filePath: "./git-worktree-orchestrator.md"
1138
+ },
1135
1139
  "implement-spec": {
1136
1140
  description: "Orchestrate implementation of spec-workflow tasks using intelligent agent coordination, parallel execution, and quality gates.",
1137
1141
  filePath: "./implement-spec.md"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniswap/ai-toolkit-nx-claude",
3
- "version": "0.5.17",
3
+ "version": "0.5.18-next.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.cjs",
@@ -38,7 +38,7 @@
38
38
  "{options.outputPath}"
39
39
  ],
40
40
  "dependsOn": [
41
- "types"
41
+ "generate-types"
42
42
  ],
43
43
  "options": {
44
44
  "outputPath": "packages/ai-toolkit-nx-claude/dist",
@@ -93,7 +93,7 @@
93
93
  ]
94
94
  }
95
95
  },
96
- "types": {
96
+ "generate-types": {
97
97
  "executor": "@nx/js:tsc",
98
98
  "outputs": [
99
99
  "{options.outputPath}"