<cursorcommands> --- Cursor Command: implement-issue --- /implement-issue コマンド…
- User
<cursor_commands>
--- Cursor Command: implement-issue ---
/implement-issue コマンド
ユーザーが指定した番号の GitHub Issue の内容を読み取り、その機能を実際にコードベースに実装する。
手順
gh issue view N -R tominaga-h/jarvis-shellを実行し、Issue の内容を取得する- 該当する Issue が見つからない場合、ユーザーに「指定された番号の Issue が見つかりません」と伝え、処理を停止する
- 既にクローズ済みの場合、ユーザーに「既にクローズ済みです。再実装しますか?」と確認する
- Issue の内容を理解し、
docs/OVERVIEW.mdを読み込んでプロジェクト全体の構成を把握する - 必要に応じてコードベースを調査し、関連するファイルを特定する
- プランモードに切り替え、実装計画をユーザーに提示し、確認を得る
- 実装を行う
make checkを実行し、異常終了しないことを確認する
制約
- 実装前に必ずプランモードで計画を提示し、ユーザーの承認を得ること
- 既存のコードスタイル・パターンに従うこと
- 変更範囲が大きい場合は段階的に実装すること
- 実装を完了しても Issue をクローズしないこと
例
ユーザー入力:
/implement-issue 13→
gh issue view 13 -R tominaga-h/jarvis-shellで Issue 内容を取得し、プランモードで実装計画を提示、承認後に実装、完了後に Issue をクローズする。76 --- End Command --- </cursor_commands>
/implement-issue 76
Assistant
The user wants me to implement GitHub Issue #76. Let me first fetch the issue content, then read the project overview.
Assistant
Issue #76 の内容を確認しました。
git push時にカレントブランチを初期補完(Tab補完の最初の候補)にしたいという機能リクエストですね。コードベースの補完システムを調査します。
Issue #76 is about auto-completing the current branch name first when doing
git push. Let me understand the codebase better, particularly how tab completion works for commands likegit push.Let me explore the completion system and understand how git-related completions work.
Assistant
実装の全体像が見えてきました。具体的なコードを確認します。
Now I have a good understanding of the codebase. Let me read the key file that needs to be modified -
src/cli/completer/git.rs- to understand the exact current implementation.Assistant
- User
Assistant
まず
current_branch()ヘルパー関数を追加し、次にcomplete_git_branchメソッドを修正します。Now I'll implement the changes. First, I'll add the
current_branch()helper function and modifycomplete_git_branchto prioritize the current branch.The key challenge is that
branchesisVec<&str>with lifetimes tied tostdout. When I remove the current branch and re-insert it, I need to be careful with lifetimes. Since the current branch name comes fromgit2(an ownedString), I can't insert a reference to it into aVec<&str>that borrows fromstdout.The cleanest approach: convert the branches to owned
Strings, or handle it differently. Let me think...Actually, I can keep the
Vec<&str>approach but use a different strategy. Since the current branch is already in the branches list as a&strfrom stdout, I can just find its position and move it to the front without needing to insert a new reference.Reordering the vec...
Assistant
次に
complete_git_branchメソッドにカレントブランチを先頭に移動するロジックを追加します。Assistant
テストを追加します。テスト用リポジトリでは
main(またはmaster) がカレントブランチになるので、それが先頭に来ることを検証します。Assistant
変更後のファイルを確認してから
make checkを実行します。Assistant
repoのライフタイム問題を修正します。headの参照を中間変数に束縛する必要があります。There's a lifetime issue with the
current_branchfunction. Therepo.head()returns aReferencethat borrows fromrepo, and using the?operator creates a temporary that outlivesrepo. I need to split the expression into separate bindings. The prompt module (src/cli/prompt/git.rs) does the same thing but with separateletbindings. Let me fix this.Assistant
全チェック通過しました。新しいテスト
complete_git_branch_current_branch_comes_firstも含めて 392 テスト全て成功です。Assistant
全タスク完了です。変更内容をまとめます。
変更サマリ
src/cli/completer/git.rsに以下の変更を加えました。1.
current_branch()ヘルパー関数の追加 (L8-12)git2クレートを使ってカレントブランチ名を取得する関数を追加しました。プロンプト側 (src/cli/prompt/git.rs) と同じパターンです。2.
complete_git_branchメソッドの修正 (L76-81)ブランチ一覧をソート・重複除去した後、カレントブランチが候補に含まれていれば先頭に移動するロジックを追加しました。
76:81:src/cli/completer/git.rsif let Some(ref current) = current_branch() { if let Some(pos) = branches.iter().position(|b| *b == current.as_str()) { let branch = branches.remove(pos); branches.insert(0, branch); } }3. テストの追加
complete_git_branch_current_branch_comes_firstテストを追加し、カレントブランチ(mainormaster)が補完候補の先頭に来ることを検証しています。この変更は
git pushだけでなく、GIT_BRANCH_SUBCOMMANDSに含まれる全サブコマンド(checkout,switch,merge,rebase,branch, , , , , )のブランチ補完に適用されます。