Skip to content

Commit 9688ba2

Browse files
nkoji21claude
andauthored
feat(agents): add git-worktree skill and update pr-flow to use it (#79)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 63dd07c commit 9688ba2

2 files changed

Lines changed: 154 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: git-worktree
3+
description: 変更内容をもとにブランチ名を決定し、/tmp 配下に git worktree を作成して変更ファイルをコピーする
4+
user-invocable: true
5+
allowed-tools: Bash
6+
---
7+
8+
Create a git worktree for the current changes so they can be worked on in isolation without affecting the current branch.
9+
10+
1. Run `git status` and `git diff` to understand what has changed
11+
2. Decide the most appropriate branch name based on the changes
12+
13+
Naming convention:
14+
- Prefix: feat/fix/refactor/docs/chore/test
15+
- Format: `{prefix}/{specific-content-in-kebab-case}`
16+
- Examples: feat/user-auth, fix/login-error, refactor/api-client
17+
18+
3. Create a worktree at `/tmp/{branch-name}` on a new branch from `main`:
19+
```
20+
git worktree add /tmp/{branch-name} -b {branch-name} main
21+
```
22+
23+
4. Copy all modified/untracked files from the current working directory into the worktree, preserving directory structure:
24+
```
25+
# For each changed file shown in git status (macOS-compatible):
26+
rsync -R {file} /tmp/{branch-name}/
27+
```
28+
29+
5. Report the worktree path and branch name to the caller.
30+
31+
## Cleanup
32+
33+
The worktree must be removed by the caller after work is complete:
34+
```
35+
git worktree remove /tmp/{branch-name}
36+
```

.agents/skills/pr-flow/SKILL.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
name: pr-flow
3+
description: Full PR workflow - branch, commit, open draft PR, AI review loop, then squash-merge. Use when you want end-to-end automation from staged changes to merged PR.
4+
user-invocable: true
5+
allowed-tools: Bash, Skill, Agent
6+
---
7+
8+
Orchestrate the full pull request workflow from staged changes to squash-merged PR.
9+
10+
## Phase 1: Worktree + Branch
11+
12+
Use the Skill tool to invoke the `git-worktree` skill.
13+
14+
After the skill completes, note the worktree path (`/tmp/{branch-name}`) and branch name it reports.
15+
Perform all subsequent work inside that worktree directory.
16+
17+
After Phase 5 completes (or if the workflow stops early), remove the worktree:
18+
```
19+
git worktree remove /tmp/{branch-name}
20+
```
21+
22+
## Phase 2: Commit
23+
24+
Capture the current HEAD sha before committing:
25+
```
26+
BEFORE_SHA=$(git rev-parse HEAD)
27+
```
28+
29+
Use the Skill tool to invoke the `git-commit` skill.
30+
31+
After the skill completes, check whether a commit was made:
32+
```
33+
AFTER_SHA=$(git rev-parse HEAD)
34+
```
35+
36+
If `BEFORE_SHA == AFTER_SHA`, stop and inform the user that there was nothing to commit.
37+
38+
## Phase 3: Open PR
39+
40+
Use the Skill tool to invoke the `git-pr` skill.
41+
42+
After the skill completes, capture the PR URL:
43+
```
44+
gh pr view --json url --jq '.url'
45+
```
46+
47+
If `gh pr create` failed because a PR already exists, retrieve the existing PR URL with the same command.
48+
49+
Store this URL — you will use it in every subsequent `gh pr comment` and `gh pr merge` call.
50+
51+
## Phase 4: Review Loop
52+
53+
You may run this loop at most **3 times**. Track the iteration count starting at 0.
54+
55+
### 4a. Launch reviewer subagent
56+
57+
Use the Agent tool to launch the `pr-reviewer` subagent with this prompt (substitute the actual PR URL):
58+
59+
```
60+
Review the PR at <PR_URL>. Run `gh pr diff <PR_URL>` to get the diff. Analyze it for bugs, logic errors, security issues, and style/convention violations. Return structured findings exactly as your instructions specify — the REVIEW_RESULT block only, no prose outside it.
61+
```
62+
63+
### 4b. Validate and post the review comment
64+
65+
Before posting, verify that the subagent's response contains a `REVIEW_RESULT` ... `END_REVIEW_RESULT` block. If the block is absent or malformed, post this warning instead and proceed to Phase 5:
66+
```
67+
gh pr comment <PR_URL> --body "[AI-generated review by Claude Code] Warning: reviewer returned malformed output. Skipping auto-fix. Please review manually."
68+
```
69+
70+
Otherwise, post the findings:
71+
```
72+
gh pr comment <PR_URL> --body "[AI-generated review by Claude Code]
73+
74+
<formatted review findings here>"
75+
```
76+
77+
Format findings as a markdown list. Each item: severity label (`must-fix` / `suggestion` / `nitpick`), file/location, description.
78+
79+
### 4c. Evaluate findings
80+
81+
- **No issues** or **only `suggestion`/`nitpick`**: proceed to Phase 5.
82+
- **`must-fix` issues exist AND iteration < 3**:
83+
- Read each flagged file before editing. Fix each `must-fix` issue.
84+
- Capture HEAD sha before invoking git-commit:
85+
```
86+
FIX_BEFORE=$(git rev-parse HEAD)
87+
```
88+
- Use the Skill tool to invoke `git-commit` to commit the fixes.
89+
- Check if the commit actually happened:
90+
```
91+
FIX_AFTER=$(git rev-parse HEAD)
92+
```
93+
- If `FIX_BEFORE == FIX_AFTER` (nothing was committed): post a comment explaining the fix could not be committed, then stop. Do NOT loop.
94+
- Increment iteration count and return to step 4a.
95+
- **`must-fix` issues exist AND iteration == 3**:
96+
- Post comment:
97+
```
98+
gh pr comment <PR_URL> --body "[AI-generated review by Claude Code] Reached maximum auto-fix iterations (3). Remaining must-fix issues require manual attention."
99+
```
100+
- Stop. Do NOT proceed to merge.
101+
102+
## Phase 5: LGTM + Merge
103+
104+
Post the LGTM comment:
105+
```
106+
gh pr comment <PR_URL> --body "[AI-generated LGTM by Claude Code]
107+
108+
No must-fix issues found. Proceeding to auto-merge."
109+
```
110+
111+
Trigger squash merge:
112+
```
113+
gh pr merge <PR_URL> --squash --auto
114+
```
115+
116+
If the merge command fails, report the exact error to the user and stop. Do not retry automatically.
117+
118+
Report the final PR URL and merge status to the user.

0 commit comments

Comments
 (0)