refactor(hooks): post-pr-monitor を PostToolUse hook からスタンドアロン CLI に移行 - #13
Conversation
- hooks-post-pr-monitor.exe: stdin JSON パース → CLI 引数方式に全面書き換え - デフォルトモード: gh pr create 実行後に claude -p で CronCreate 監視開始 - --monitor-only モード: PR 存在確認のみ、あれば監視開始 - hooks-pre-tool-validate.exe: gh-pr-create-guard プリセット追加 (テスト6件) - hooks-config.toml: blocked_patterns に gh-pr-create-guard 追加 - package.json: pnpm pr-create / pnpm push に --monitor-only チェイン追加 - settings.local.json.template: PostToolUse Bash matcher 削除、pnpm pr-create 許可追加 - ADR-009: アーキテクチャ図・変更履歴を更新 Why: 元の PostToolUse hook + additionalContext 方式は Claude が CronCreate を 実行しないケースがあり信頼性が低かった。push-pipeline と同じ 「ガード + 専用コマンド + claude -p」パターンに統一。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughこのPRは、 Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as 開発者
participant Shell as ローカルシェル
participant PreGuard as PreToolValidate (gh-pr-create-guard)
participant CLI as hooks-post-pr-monitor.exe
participant GH as GitHub CLI (gh)
participant Claude as Claude (claude -p)
Shell->>PreGuard: コマンド入力 (例: gh pr create ...)
alt マッチする場合
PreGuard-->>Shell: ブロック指示(pnpm pr-create推奨)
Shell->>CLI: `pnpm pr-create` 実行
CLI->>GH: `gh pr create` 実行
GH-->>CLI: PR作成結果
CLI->>Claude: `claude -p` による CronCreate 開始(監視プロンプト送信)
Claude-->>CLI: 監視応答/アクション
else マッチしない場合
PreGuard-->>Shell: 通常実行許可
end
推定レビュー工数🎯 4 (Complex) | ⏱️ ~50 分 関連する可能性のあるPR
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.claude/hooks-post-pr-monitor/src/main.rs:
- Around line 125-128: The code in run_cmd_direct is directly concatenating
stdout and stderr into combined (using stdout_handle.join/ stderr_handle.join
and format!("{}{}", ...)), which misses the newline behavior used elsewhere;
replace that manual concatenation with a call to the existing combine_output
helper (the function defined around lines 187-195) so you produce the same
newline-separated output consistently—fetch stdout_text and stderr_text as you
already do, then pass them into combine_output (using the exact parameter
names/signature from combine_output) and assign its return to combined.
In @.claude/hooks-pre-tool-validate/src/main.rs:
- Around line 267-285: In the preset_gh_pr_create_guard() function update the
user-facing message inside the BlockedPattern so it refers to the actual script
name `pnpm pr-create` instead of `pnpm pr`; specifically replace the occurrences
in the message text (the "PR 作成は ..." line and the "代わりに以下を実行してください:" code
example) so the guidance and the code block use `pnpm pr-create -- --title
"タイトル" --body "本文"`; keep the rest of the BlockedPattern (Regex, structure)
unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 423daabd-8cfa-44a7-bde8-3fde5819cd60
⛔ Files ignored due to path filters (1)
.claude/hooks-post-pr-monitor/Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (7)
.claude/hooks-config.toml.claude/hooks-post-pr-monitor/Cargo.toml.claude/hooks-post-pr-monitor/src/main.rs.claude/hooks-pre-tool-validate/src/main.rs.claude/settings.local.json.templatedocs/adr/adr-009-post-pr-monitor.mdpackage.json
💤 Files with no reviewable changes (1)
- .claude/hooks-post-pr-monitor/Cargo.toml
| let stdout_text = stdout_handle.join().unwrap_or_default(); | ||
| let stderr_text = stderr_handle.join().unwrap_or_default(); | ||
| let combined = format!("{}{}", stdout_text, stderr_text).trim().to_string(); | ||
|
|
There was a problem hiding this comment.
stdout と stderr の結合に改行が欠けています。
run_cmd_direct では stdout と stderr を直接結合していますが、combine_output 関数(Line 187-195)では改行を挿入しています。一貫性のため combine_output を使用してください。
📝 修正案
let stdout_text = stdout_handle.join().unwrap_or_default();
let stderr_text = stderr_handle.join().unwrap_or_default();
- let combined = format!("{}{}", stdout_text, stderr_text).trim().to_string();
+ let combined = combine_output(&stdout_text, &stderr_text);
if timed_out {
return (false, format!("{}\n(timeout after {}s)", combined, timeout_secs));
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.claude/hooks-post-pr-monitor/src/main.rs around lines 125 - 128, The code
in run_cmd_direct is directly concatenating stdout and stderr into combined
(using stdout_handle.join/ stderr_handle.join and format!("{}{}", ...)), which
misses the newline behavior used elsewhere; replace that manual concatenation
with a call to the existing combine_output helper (the function defined around
lines 187-195) so you produce the same newline-separated output
consistently—fetch stdout_text and stderr_text as you already do, then pass them
into combine_output (using the exact parameter names/signature from
combine_output) and assign its return to combined.
CodeRabbit レビュー指摘対応。ガードメッセージ内の誘導先コマンド名が 実際の package.json スクリプト名と不一致だった。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
hooks-post-pr-monitor.exeを PostToolUse hook からスタンドアロン CLI に全面書き換えpnpm pr-createでgh pr create+claude -pで CronCreate 監視開始--monitor-only:pnpm push完了後に PR 存在確認 → あれば監視開始hooks-pre-tool-validate.exeにgh-pr-create-guardプリセット追加(直接のgh pr createをブロック)settings.local.json.templateから PostToolUse Bash matcher 削除Why
元の PostToolUse hook + additionalContext 方式は Claude が CronCreate を実行しないケースがあり信頼性が低かった。push-pipeline と同じ「ガード + 専用コマンド + claude -p」パターンに統一。
Test plan
cargo test— hooks-pre-tool-validate 99テスト全通過(gh-pr-create-guard 6件含む)pnpm build:hooks— 全 exe ビルド成功pnpm push— pipeline +--monitor-onlyチェイン動作確認(PR なし時は正常スキップ)pnpm pr-create— PR 作成成功Known Issues (次 PR で対応)
pnpm pr-create経由で改行を含む--bodyが切り詰められる(pnpm のシェル引数分割)gh pr create出力の URL から取得できていない(pr=None)claude -pの監視ジョブ起動がタイムアウト🤖 Generated with Claude Code
Summary by CodeRabbit
リリースノート
新機能
pnpm pr-createスクリプトでPR作成と監視を実行できるようになりました。改善