commit 0d21da1040677c816d3a0259022bb2f80bc6ba19 Author: Zhongwei Li Date: Sat Nov 29 18:45:43 2025 +0800 Initial commit diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..0fb2f4b --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,15 @@ +{ + "name": "wf", + "description": "PR management commands and code review agents", + "version": "0.0.0-2025.11.28", + "author": { + "name": "Hikaru Egashira", + "email": "zhongweili@tubi.tv" + }, + "agents": [ + "./agents" + ], + "commands": [ + "./commands" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4b7fbe2 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# wf + +PR management commands and code review agents diff --git a/agents/code-reviewer.md b/agents/code-reviewer.md new file mode 100644 index 0000000..d47621a --- /dev/null +++ b/agents/code-reviewer.md @@ -0,0 +1,30 @@ +--- +name: code-reviewer +description: Expert code review specialist. Proactively reviews code for quality, security, and maintainability. Use immediately after writing or modifying code. +tools: Read, Grep, Glob, Bash +model: sonnet +--- + +You are a senior code reviewer ensuring high standards of code quality and security. + +When invoked: +1. Run git diff to see recent changes +2. Focus on modified files +3. Begin review immediately + +Review checklist: +- Code is simple and readable +- Functions and variables are well-named +- No duplicated code +- Proper error handling +- No exposed secrets or API keys +- Input validation implemented +- Good test coverage +- Performance considerations addressed + +Provide feedback organized by priority: +- Critical issues (must fix) +- Warnings (should fix) +- Suggestions (consider improving) + +Include specific examples of how to fix issues. diff --git a/agents/comment-cleaner.md b/agents/comment-cleaner.md new file mode 100644 index 0000000..25a69e4 --- /dev/null +++ b/agents/comment-cleaner.md @@ -0,0 +1,46 @@ +--- +name: comment-cleaner +description: diffを見て不要なコードコメントを削除する +model: haiku +--- + +diffのscope内で、不要なコードコメントを削除してください +You believe in self-documenting code where the code itself clearly expresses its intent through +- Descriptive variable and function names +- Clear structure and organization +- Appropriate use of language idioms +- Well-designed interfaces and abstractions + +However, you recognize that certain comments provide irreplaceable value +- Context and background that cannot be expressed in code +- Rationale for non-obvious design decisions +- High-level explanations of code blocks or modules +- Business logic explanations that connect code to requirements +- Warnings about edge cases or gotchas +- TODO/FIXME with specific context +- Focus only on files changed in the diff and do not address code outside the scope of those changes + +## Review Process + +1. Identify Unnecessary Comments + - Comments that merely restate what the code does (e.g., `// increment counter` above `counter++`) + - Obvious comments on self-explanatory code + - Commented-out code (suggest removal unless there's a specific reason to keep) + - Outdated comments that no longer match the code + - Redundant documentation that duplicates function/variable names + +2. Preserve Valuable Comments + - Block-level comments that explain the purpose of a code section + - Comments explaining "why" rather than "what" + - Context about business requirements or constraints + - Non-obvious algorithmic choices or optimizations + - Warnings about potential issues or edge cases + - References to external documentation or tickets + +3. Provide Specific Recommendations + - For each comment you suggest removing, explain why it's unnecessary + - For comments you suggest keeping, explain what value they provide + - Suggest improvements to comments that are valuable but poorly written + - Recommend refactoring if code needs comments to be understood + +4. Remove identified unnecessary comments diff --git a/commands/commit.md b/commands/commit.md new file mode 100644 index 0000000..2740fec --- /dev/null +++ b/commands/commit.md @@ -0,0 +1,209 @@ +--- +description: 分割commit +model: haiku +--- + +大きな変更を論理的な単位に分割してコミットします。LLMがgit diffを分析して意味のある最小単位を提案し、`git-sequential-stage`ツールによる自動化された逐次ステージングでコミットします。 + +#### git-sequential-stage + +`git-sequential-stage`は、hunk単位の部分的なステージングを自動化するためのGoで実装された専用ツールです。 + +```bash +# hunk番号を指定して部分的にステージング +git-sequential-stage -patch="path/to/changes.patch" -hunk="src/main.go:1,3,5" + +# ファイル全体をステージング(ワイルドカード使用) +git-sequential-stage -patch="path/to/changes.patch" -hunk="src/logger.go:*" + +# 複数ファイルの場合(ワイルドカードと番号指定の混在も可能) +git-sequential-stage -patch="path/to/changes.patch" \ + -hunk="src/main.go:1,3" \ + -hunk="src/utils.go:*" \ + -hunk="docs/README.md:*" +``` + +#### ワイルドカード使用の判断基準 + +ワイルドカード(`*`)を使用すべきケース +- ファイル内のすべての変更が意味的に一体である場合 +- 新規ファイルの追加 +- ファイル全体のリファクタリング(すべての変更が同じ目的) +- ドキュメントファイルの更新 + +hunk番号で分割すべきケース +- 異なる目的の変更が混在している場合 +- バグ修正とリファクタリングが同じファイルに混在 +- 機能追加と既存コードの改善が混在 + +⚠️ 注意点 +- 「hunkを数えるのが面倒」という理由で使用するものではない。 +- 意味のある最小単位でのコミットという本来の目的を必ず守ること。 + +## 実行手順 + +### Step 0: リポジトリルートに移動 + +```bash +# リポジトリルートを確認 +REPO_ROOT=$(git rev-parse --show-toplevel) +echo "リポジトリルート: $REPO_ROOT" + +# リポジトリルートに移動 +cd "$REPO_ROOT" +``` + +### Step 1: 差分を取得 + +```bash +# .claude/tmpディレクトリは既に存在するため、直接ファイルを作成可能 + +# 新規ファイル(untracked files)をintent-to-addで追加 +git ls-files --others --exclude-standard | xargs git add -N + +# コンテキスト付きの差分を取得(より安定した位置特定のため) +# 新規ファイルも含めて取得される +git diff HEAD > .claude/tmp/current_changes.patch +``` + +### Step 2: LLM分析 + +LLMがhunk単位で変更を分析し、最初のコミットに含めるhunkを決定: + +- hunkの内容を読み取る: 各hunkが何を変更しているか理解 +- 意味的グループ化: 同じ目的の変更(バグ修正、リファクタリング等)をグループ化 +- コミット計画: どのhunkをどのコミットに含めるか決定 + +必要に応じて、hunk数を確認: +```bash +# 全体のhunk数 +grep -c "^@@" .claude/tmp/current_changes.patch + +# 各ファイルのhunk数 +git diff HEAD --name-only | xargs -I {} sh -c 'printf "%s: " "{}"; git diff HEAD {} | grep -c "^@@"' +``` + +例: +```bash +# LLMの分析結果 +# - コミット1(fix): +# - src/calculator.py: hunk 1, 3, 5(ゼロ除算エラーの修正) +# - src/utils.py: hunk 2(関連するユーティリティ関数の修正) +# - コミット2(refactor): +# - src/calculator.py: hunk 2, 4(計算ロジックの最適化) + +# 最初のコミット用の設定 +COMMIT_MSG="fix: ゼロ除算エラーを修正 + +計算処理で分母が0の場合の適切なエラーハンドリングを追加" +``` + +### Step 3: 自動ステージング + +選択したhunkを`git-sequential-stage`で自動的にステージング: + +```bash +# git-sequential-stageを実行(内部で逐次ステージングを安全に処理) +# 部分的な変更をステージング(hunk番号指定) +git-sequential-stage -patch=".claude/tmp/current_changes.patch" -hunk="src/calculator.py:1,3,5" + +# ファイル全体をステージング(意味的に一体の変更の場合) +git-sequential-stage -patch=".claude/tmp/current_changes.patch" -hunk="tests/test_calculator.py:*" + +# 複数ファイルの場合(混在使用) +git-sequential-stage -patch=".claude/tmp/current_changes.patch" \ + -hunk="src/calculator.py:1,3,5" \ + -hunk="src/utils.py:2" \ + -hunk="docs/CHANGELOG.md:*" + +# コミット実行 +git commit -m "$COMMIT_MSG" +``` + +### Step 4: 繰り返し + +残りの変更に対して同じプロセスを繰り返し: + +```bash +# 残りの差分を確認 +if [ $(git diff HEAD | wc -l) -gt 0 ]; then + echo "残りの変更を処理します..." + # Step 1(差分取得)から再開 +fi +``` + +### Step 5: 最終確認 + +```bash +# すべての変更がコミットされたか確認 +if [ $(git diff HEAD | wc -l) -eq 0 ]; then + echo "すべての変更がコミットされました" +else + echo "警告: まだコミットされていない変更があります" + git status +fi +``` + +## 例 + +### ファイル内の意味的分割 + +``` +変更内容: src/calculator.py +- hunk 1: 10行目のゼロ除算チェック追加 +- hunk 2: 25-30行目の計算アルゴリズム最適化 +- hunk 3: 45行目の別のゼロ除算エラー修正 +- hunk 4: 60-80行目の内部構造リファクタリング +- hunk 5: 95行目のゼロ除算時のログ出力追加 + +↓ 分割結果 + +コミット1: fix: ゼロ除算エラーを修正 +# バグ修正のhunkのみを選択(他の変更と混在しているため番号指定) +git-sequential-stage -patch=".claude/tmp/current_changes.patch" -hunk="src/calculator.py:1,3,5" + +コミット2: refactor: 計算ロジックの最適化 +# リファクタリングのhunkのみを選択 +git-sequential-stage -patch=".claude/tmp/current_changes.patch" -hunk="src/calculator.py:2,4" +``` + +### 複雑な変更パターン + +``` +変更内容: +- src/auth.py: 認証ロジックの修正(hunk 1,3,5)とリファクタリング(hunk 2,4) +- src/models.py: ユーザーモデルの拡張(hunk 1,2) +- tests/test_auth.py: 新規テスト(hunk 1,2,3) + +↓ 分割結果 + +コミット1: fix: 既存認証のセキュリティ脆弱性修正 +# セキュリティ修正のhunkのみを選択(他の変更と混在) +git-sequential-stage -patch=".claude/tmp/current_changes.patch" -hunk="src/auth.py:1,3,5" + +コミット2: feat: JWT認証機能の実装 +# 新機能実装に関連する変更を選択 +git-sequential-stage -patch=".claude/tmp/current_changes.patch" \ + -hunk="src/auth.py:2,4" \ + -hunk="src/models.py:*" # モデルの変更はすべてJWT関連のため*を使用 + +コミット3: test: 認証機能のテスト追加 +# 新規テストファイルは意味的に一体のため*を使用 +git-sequential-stage -patch=".claude/tmp/current_changes.patch" -hunk="tests/test_auth.py:*" +``` + +# ベストプラクティス + +1. 事前確認: `git status`で現在の状態を確認 +2. 適切な指定方法の選択: + - 部分的な変更: `file.go:1,3,5` (hunk番号を指定) + - ファイル全体: `file.go:*` (意味的に一体の場合のみ) +3. 意味的一貫性: 同じ目的の変更は同じコミットに +4. Conventional Commits: 適切なプレフィックスを使用, 1行にまとめる + - `feat:` 新機能 + - `fix:` バグ修正 + - `refactor:` リファクタリング + - `docs:` ドキュメント + - `test:` テスト + - `style:` フォーマット + - `chore:` その他 diff --git a/commands/current-pr.md b/commands/current-pr.md new file mode 100644 index 0000000..dce64b1 --- /dev/null +++ b/commands/current-pr.md @@ -0,0 +1 @@ +現在のPRを引き継いでください。 diff --git a/commands/pr-simple.md b/commands/pr-simple.md new file mode 100644 index 0000000..205f45f --- /dev/null +++ b/commands/pr-simple.md @@ -0,0 +1,10 @@ +--- +description: create pr +model: haiku +--- + +- create branch(if current branch in default) and pr +- following pr template +- description in japanese +- create create pr subtask +- 提出後は gh pr view --web で差分を共有して完了してください diff --git a/commands/pr.md b/commands/pr.md new file mode 100644 index 0000000..685efb8 --- /dev/null +++ b/commands/pr.md @@ -0,0 +1,13 @@ +--- +description: create pr +model: haiku +--- + +parallelで以下を進めます。 +- create create pr subtask + - create branch and pr + - following pr template + - description in japanese + 提出後は gh pr checks --watch で CI 成功を確認し、必要に応じて gh pr view --web で差分を共有します。 +- comment-cleaner subagent diffに含まれる不要なコメントを削除します +- code-reviewer subagent を使用してレビューを進めてその結果を出力します diff --git a/commands/review-pr.md b/commands/review-pr.md new file mode 100644 index 0000000..d1908df --- /dev/null +++ b/commands/review-pr.md @@ -0,0 +1,30 @@ +--- +description: review pr +argument-hint: [url] +model: haiku +--- + +PR $1 について理解しPR authorの身になってペアプロセッションを開始します。 +レビュワーにわかりやすいように解説をしてください。 + +gh pr checkoutを実行して現在のブランチに切り替えるもしも異なるリポジトリにいる場合は ~/ghq/githtub.com/{owner}/{repo} に移動してください。 + +parallelに以下のsubagentsを実行します +- code-reviewer subagent を使用して初期レビューを実行します。 +- explorer subagent を使用してPRの変更点を整理します。 + - 追加した処理 + - 変更した処理 + - 削除した処理 + - 影響のある他コンポネント +- dynamic-test subagent を使用してPRの対象となる機能を実際にBash Toolを用いて動作確認します。 + - 動作確認手順 + - 期待される結果 + - 実際の結果 + - もしも問題があればその詳細 + +以下の項目を報告してください +- コードの解説 +- code-reviewerのフィードバック内容/動作確認結果を元にした代理質問を提案してください + そこからペアプロセッションを開始します。 + - 〇〇のような入力があった場合、どのような挙動になりますか? + - この処理のパフォーマンスが気になりますが、どの程度の負荷がかかりますか? diff --git a/commands/watch-pr.md b/commands/watch-pr.md new file mode 100644 index 0000000..15e39c4 --- /dev/null +++ b/commands/watch-pr.md @@ -0,0 +1,23 @@ +--- +description: watch pr +argument-hint: [url] +model: haiku +--- + +PR $1 がマージ可能になるまで監視し続けます。 + +gh pr checkoutを実行して現在のブランチに切り替えるもしも異なるリポジトリにいる場合は ~/ghq/githtub.com/{owner}/{repo} に移動してください。 + +code-reviewer subagent を使用して1次レビューを実行します。 +CIが通過しているかどうか確認します。 + +以下の場合はマージ可能ではないため1分後に再度確認します +- CIが失敗している +- まだバグが残っている +- 変更がPR Descriptionで達成したいこと満たしていない +- Bash(sleep 60)で1分待機し、再度PRの状態を確認します +- マージ可能になるまでこの操作を繰り返します + +マージ可能な場合以下を報告してください。 +- コードの解説 +- code-reviewerのフィードバック概要 diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..3332717 --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,73 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:HikaruEgashira/hikae-claude-code-marketplace:plugins/wf", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "ddb4eb8038fa63fc78572fed759b8668c0a390ef", + "treeHash": "219750d1a825792106f94f0074d652469d0c9a12593f2c2dd4319d5dd2148ca9", + "generatedAt": "2025-11-28T10:11:40.366437Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "wf", + "description": "PR management commands and code review agents", + "version": null + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "f50d3114c6c3a39e15a50896fe97ef6d78c8c7e5c9f2ea6d05fdaedc62067c6e" + }, + { + "path": "agents/comment-cleaner.md", + "sha256": "06aa487b49a2bfb7479bb56e51b36f8fb56ea7d7accd2707668f5071f6c27299" + }, + { + "path": "agents/code-reviewer.md", + "sha256": "384b132fa13a9e98f5e292ffde36b8b0ff11070de0667e029c4298029ce14e4c" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "1c8dac7323d189ee10a525de7a9056629d3660325da4a56c235c3ab297c04772" + }, + { + "path": "commands/pr.md", + "sha256": "ec4946c1fb4f823c2f3a60873e605e0281b7f660f206618167f88e109f85d27c" + }, + { + "path": "commands/review-pr.md", + "sha256": "6e41153c90be13050a11a44646d9c959d661dec21be259534259306f652555ab" + }, + { + "path": "commands/pr-simple.md", + "sha256": "ef15a04df37fb81b41d3b088ba1feceecb3008ff015bfdef32abbcdf4f337549" + }, + { + "path": "commands/watch-pr.md", + "sha256": "f857b1a01649b2bbb05843564427d9127d33287b738074b8fb6f723244b99681" + }, + { + "path": "commands/current-pr.md", + "sha256": "ab031a3c106ff3c13f8fcfddb9dcf99b84415bae7dabfc5cb7b3cbf2c87e3f87" + }, + { + "path": "commands/commit.md", + "sha256": "a61da37f2f1e466b32eff27d9dc94f88dce5263087b5dba5b4d09b502410bbee" + } + ], + "dirSha256": "219750d1a825792106f94f0074d652469d0c9a12593f2c2dd4319d5dd2148ca9" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file