Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions .claude/hooks-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
# SessionStart hook がセッション ID を以下に書き出す:
# 1. $CLAUDE_ENV_FILE → Bash ツールの環境変数 (CLAUDE_CODE_SESSION_ID)
# 2. .claude/.session-id → 子プロセス exe から読み取り可能
# hooks-post-pr-monitor は .session-id から ID を読み、
# claude -p --resume <id> でメインセッションに CronCreate を注入する。
# 同一 ID ならスキップ、異なる ID なら上書きする方式。
# ※ hooks-post-pr-monitor は daemon + state file 方式に移行済みのため
# .session-id の直接参照は不要になったが、将来の拡張用に維持。

# [session_start]
# 現在設定項目なし(将来の拡張用)
Expand Down Expand Up @@ -113,12 +114,14 @@ name = "commit_refactor"
type = "ai"
prompt = "optimize_commit_structure"

# ─── PostToolUse: PR モニター ───
# ─── Post-PR Monitor: daemon + state file ───
#
# gh pr create / git push / jj git push / pnpm push 検出後に
# CI + CodeRabbit の自動モニタリングを CronCreate で開始する。
# check-ci-coderabbit.exe によるポーリングで監視し、
# 結果の action フィールドに従って Claude が行動する。
# pnpm pr-create / pnpm push 実行時に daemon がバックグラウンドで起動し、
# check-ci-coderabbit.exe を定期ポーリングして結果を
# .claude/pr-monitor-state.json に書き出す。
# Claude は CronCreate で state file を cat し、action に従って行動する。
# CronCreate は UX 最適化レイヤーであり、コア機能ではない。
# フォールバック: cat .claude/pr-monitor-state.json で手動確認可能。

[post_pr_monitor]
enabled = true
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ src/hooks-session-start/target/

# Runtime generated files
.claude/.session-id
.claude/pr-monitor-state.json
.claude/pr-monitor-state.json.tmp
.claude/scheduled_tasks.lock
44 changes: 27 additions & 17 deletions docs/adr/adr-009-post-pr-monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ Claude が "pnpm pr-create -- --title ..." を実行
hooks-post-pr-monitor.exe (スタンドアロン)
├─ gh pr create を実行(引数を転送)
├─ PR番号・リポジトリ情報を gh CLI で取得
├─ PUSH_TIME を記録 (UTC ISO 8601)
└─ claude -p で CronCreate 指示を送信
├─ .claude/pr-monitor-state.json に初期 state 書き出し
├─ daemon をスポーン (自身を --daemon で起動)
└─ stdout に CronCreate セットアップ指示を出力
Claude が CronCreate で定期ジョブ作成 (120秒間隔)
Claude が stdout を読み、CronCreate で定期ジョブ作成 (任意)
└─ command: cat .claude/pr-monitor-state.json

【既存 PR への push 時】
pnpm push → hooks-push-pipeline.exe (テスト + レビュー + push)
Expand All @@ -68,26 +70,26 @@ pnpm push → hooks-push-pipeline.exe (テスト + レビュー + push)
hooks-post-pr-monitor.exe --monitor-only
├─ gh pr view で PR 存在確認
├─ PR なし → exit 0 (何もしない)
└─ PR あり → claude -p で CronCreate 指示を送信

定期実行
check-ci-coderabbit.exe --push-time <T> --repo <R> --pr <N>
├─ CI 状態チェック (gh run list)
├─ CodeRabbit 状態チェック (gh api .../statuses)
├─ 新規コメント取得 (gh api .../comments, created_at > push_time)
├─ レビュー本文クロスチェック (Actionable comments posted: N)
├─ 未解決スレッド (gh api graphql)
└─ 判定 JSON を stdout 出力
Claude が action フィールドに従い行動
└─ PR あり → state file 初期化 + daemon スポーン + stdout 指示

daemon (バックグラウンド)
hooks-post-pr-monitor.exe --daemon --state-file <path>
├─ check-ci-coderabbit.exe を poll_interval_secs 間隔で実行
├─ 結果を pr-monitor-state.json に毎回書き出し
├─ 意味的終了: action != "continue_monitoring"
└─ 安全タイムアウト: max_duration_secs で停止

【CronCreate (任意, UX 最適化レイヤー)】
cat .claude/pr-monitor-state.json
├─ Claude が action フィールドに従い行動
└─ フォールバック: 手動 cat で確認可能
```

### コンポーネント

| コンポーネント | 種別 | 役割 |
|---|---|---|
| `hooks-post-pr-monitor.exe` | スタンドアロン CLI (Rust) | PR 作成 + CronCreate 監視開始 |
| `hooks-post-pr-monitor.exe` | スタンドアロン CLI (Rust) | PR 作成 + daemon 起動 + state file 管理 |
| `hooks-pre-tool-validate.exe` | PreToolUse hook (Rust) | `gh-pr-create-guard` で直接の `gh pr create` をブロック |
| `check-ci-coderabbit.exe` | スタンドアロン CLI (Rust) | CI・CodeRabbit 状態チェック → JSON 出力 |
| `post-pr-create-review-check` SKILL.md | Claude Skill | 監視結果の解釈・報告手順 |
Expand Down Expand Up @@ -144,6 +146,14 @@ check_coderabbit = true
信頼性が低かった。push-pipeline と同じ「ガード + 専用コマンド + claude -p」パターンに
統一することで、CronCreate の実行を確実にした。

- **2026-04-05**: `claude -p --resume` → daemon + state file アーキテクチャに変更。
VSCode 拡張では `~/.claude/sessions/` に CLI セッションのみ登録されるため、
`claude -p --resume <session_id>` で VSCode セッションにアクセスできないことが判明。
外部プロセスから Claude セッションに状態を注入する設計自体がアンチパターンであると認識。
新設計: daemon が外部で監視を完結させ、結果を `.claude/pr-monitor-state.json` に書き出す。
Claude は state file を読むだけ。CronCreate は UX 最適化レイヤーとして維持(state file の
cat のみ実行)し、コア機能ではない。フォールバック: 手動 `cat` で確認可能。

## 参考

- ADR-001 — hooks の実装言語として Rust を採用
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"push": ".\\.claude\\hooks-push-pipeline.exe && .\\.claude\\hooks-post-pr-monitor.exe --monitor-only",
"pr-create": ".\\.claude\\hooks-post-pr-monitor.exe",
"check-ci": ".\\.claude\\check-ci-coderabbit.exe",
"mark-notified": ".\\.claude\\hooks-post-pr-monitor.exe --mark-notified",
"check-monitor": "type .\\.claude\\pr-monitor-state.json 2>NUL || echo No active monitor",
"deploy:hooks": "npx tsx scripts/deploy-hooks.ts",
"py-lint": "ruff check src/",
"py-test": "python -m pytest tests/",
Expand Down
26 changes: 26 additions & 0 deletions src/hooks-post-pr-monitor/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/hooks-post-pr-monitor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
toml = "0.8"

[profile.release]
Expand Down
Loading