fix: hooks の stderr flush 追加、パス環境非依存化、インストールヒント追加 - #458
Conversation
- pre_git_quality_gates.py: すべての print() に flush=True を追加 - 出力がバッファリングされて途中で切れる問題を修正 - block_git_no_verify.py: sys.stderr.flush() を追加 - settings.json: hooks パスを git rev-parse --show-toplevel で動的に取得 - ローカル環境と DevContainer の両方で動作するように - ツールが見つからない場合(exit 127)はスキップしてインストール方法を表示 - 出力が実質的に空の場合もツール/環境の問題としてスキップ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe PR enhances git hook scripts with improved output handling and robustness. Changes include adding output flushing for immediate feedback, introducing tool install hints, gracefully skipping checks when tools are missing, and updating hook invocations to use relative paths via a bash wrapper that cd's to the repository root. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🔍 AI Code Review (Local Hook)Models: Codex (default) / Gemini (default) 🤖 Codex Review
patch is incorrect — Quality Gates を失敗で止めるべきケースがスキップされ、検査が機能しなくなるため。信頼度 0.57 ✨ Gemini Reviewコードレビューこの変更に対して、いくつか改善点と評価を指摘します。 発見した問題リスト
全体的な評価patch is correct 理由: このパッチは、主に2つの点でコードベースを大幅に改善しています。
上記で指摘した保守性の問題は軽微であり、このパッチがもたらす正確性と開発者体験の向上という大きなメリットを損なうものではありません。 信頼度スコア: 0.95
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @.claude/hooks/pre_git_quality_gates.py:
- Around line 124-125: Rename the lambda variable `l` to `line` in the stdout
parsing to fix E741 and replace the brittle "━" check with a regex-based
decorative-line filter: strip result.stdout, split into lines and keep lines
that are non-empty and do not match a pattern for purely decorative/non-word
characters (e.g. re.match(r'^[^\w]+$', line) to detect box-drawing or repeated
punctuation), then set is_empty_output based on that filtered list and
result.stderr; update references to `stdout_lines` and `is_empty_output`
accordingly (use `result`, `stdout_lines`, `is_empty_output`, and `line` as
identifiers).
🧹 Nitpick comments (1)
.claude/hooks/pre_git_quality_gates.py (1)
143-143: Remove extraneousfprefix on strings without placeholders.Lines 143, 150, and 154 use f-strings with no interpolation. Use plain strings instead (flagged by Ruff F541).
Proposed fix
- print(f" ✅ 成功", file=sys.stderr, flush=True) + print(" ✅ 成功", file=sys.stderr, flush=True)- print(f" ❌ タイムアウト", file=sys.stderr, flush=True) + print(" ❌ タイムアウト", file=sys.stderr, flush=True)- print(f" ⚠️ スキップ (コマンドが見つかりません)", file=sys.stderr, flush=True) + print(" ⚠️ スキップ (コマンドが見つかりません)", file=sys.stderr, flush=True)Also applies to: 150-150, 154-154
| stdout_lines = [l for l in result.stdout.strip().split('\n') if l.strip() and not l.startswith('━')] | ||
| is_empty_output = len(stdout_lines) <= 1 and not result.stderr.strip() |
There was a problem hiding this comment.
Ambiguous variable name l and fragile output-parsing heuristic.
The lambda variable l triggers E741. More importantly, filtering lines by the ━ character couples this to a specific tool's output format — other tools won't match this pattern and may be incorrectly classified.
Proposed fix
- stdout_lines = [l for l in result.stdout.strip().split('\n') if l.strip() and not l.startswith('━')]
+ stdout_lines = [line for line in result.stdout.strip().split('\n') if line.strip() and not line.startswith('━')]📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| stdout_lines = [l for l in result.stdout.strip().split('\n') if l.strip() and not l.startswith('━')] | |
| is_empty_output = len(stdout_lines) <= 1 and not result.stderr.strip() | |
| stdout_lines = [line for line in result.stdout.strip().split('\n') if line.strip() and not line.startswith('━')] | |
| is_empty_output = len(stdout_lines) <= 1 and not result.stderr.strip() |
🧰 Tools
🪛 Ruff (0.15.0)
[error] 124-124: Ambiguous variable name: l
(E741)
🤖 Prompt for AI Agents
In @.claude/hooks/pre_git_quality_gates.py around lines 124 - 125, Rename the
lambda variable `l` to `line` in the stdout parsing to fix E741 and replace the
brittle "━" check with a regex-based decorative-line filter: strip
result.stdout, split into lines and keep lines that are non-empty and do not
match a pattern for purely decorative/non-word characters (e.g.
re.match(r'^[^\w]+$', line) to detect box-drawing or repeated punctuation), then
set is_empty_output based on that filtered list and result.stderr; update
references to `stdout_lines` and `is_empty_output` accordingly (use `result`,
`stdout_lines`, `is_empty_output`, and `line` as identifiers).
PR Review: hooks の stderr flush 追加、パス環境非依存化、インストールヒント追加✅ 全体評価このPRは開発体験を大きく向上させる重要な改善です。3つの主要な変更点はすべて明確な目的を持ち、適切に実装されています。 📋 コード品質👍 良い点
🔍 潜在的な問題・改善提案
|
| 項目 | 状態 | 備考 |
|---|---|---|
| Diff ≤ 400行 | ✅ | 115行(70追加 + 45削除) |
| ファイル数 ≤ 25 | ✅ | 3ファイル |
| Conventional Commits | ✅ | fix: タイプで適切 |
| Linked Issue | Issue リンクなし(Minor) |
🚀 マージ推奨度
推奨: マージ可(Minor な改善提案あり)
理由:
- コア機能の動作に影響する critical な問題なし
- 開発体験を大きく向上させる重要な改善
- 提案した改善点はすべて optional(後続PRで対応可)
マージ前の必須アクション:
- ✅ Test plan の手動実行と確認
⚠️ CI の claude-review が完了するのを待つ(現在 pending)
推奨される後続改善(別PRで可):
- 空出力判定ロジックの堅牢化
- エラーパターンマッチングの国際化対応
- Magic number の定数化
- DRY原則違反の解消
🤖 Review Summary
このPRは品質基準を満たしており、開発体験向上に直結する価値ある変更です。提案した改善点は品質をさらに高めるものですが、現状のコードでもプロダクション投入可能です。
Next Action: Test plan 完了後、マージを推奨します。
🤖 Generated by Claude Code
|
🎉 This PR is included in version 1.69.3 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Summary
flush=Trueを追加して途中で切れる問題を修正git rev-parse --show-toplevelで動的に取得し、環境非依存にChanges
.claude/hooks/pre_git_quality_gates.py: すべてのprint()にflush=True追加.claude/hooks/block_git_no_verify.py:sys.stderr.flush()追加.claude/settings.json: hooks パスを環境非依存に変更Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit