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
62 changes: 62 additions & 0 deletions .takt/facets/instructions/analyze-coderabbit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# CodeRabbit Review Analysis

## Input

Read `.takt/review-comments.json`. This file contains the output from `check-ci-coderabbit.exe`, including:
- `ci`: GitHub Actions CI status (overall + per-run results)
- `coderabbit`: CodeRabbit review state (review_state, new_comments, actionable_comments, unresolved_threads)
- `findings`: Array of structured findings (severity, file, line, issue, suggestion, source)
- `action`: Terminal action from the monitor ("action_required", "stop_monitoring_success", etc.)
- `summary`: Human-readable summary

## Task

1. Read the JSON file with the Read tool
2. Parse the `findings` array and `coderabbit` state
3. Classify each finding by severity: Critical > High > Major > Medium > Minor > Low > Info
4. Group findings by file path
5. For each Critical/High/Major finding, provide:
- Root cause analysis (why this is a problem)
- Recommended fix approach
- Impact if not addressed

## Output Format

Produce a structured Markdown report:

```markdown
## CodeRabbit Analysis Report

### Summary
- CI: [status]
- CodeRabbit: [N] findings ([X] critical/high, [Y] medium, [Z] low)
- Verdict: PASS / FAIL

### Findings by Severity

#### Critical / High
| # | File (Line) | Issue | Recommended Action |
|---|-------------|-------|--------------------|
| 1 | path:line | ... | ... |

#### Medium
...

#### Low / Info
...

### Recommended Actions
1. [Prioritized action items for critical/high findings]
```

## Verdict Rules

- **FAIL**: Any Critical or High or Major severity finding exists
- **PASS**: Only Medium or lower severity findings (or no findings)

## Important

- Do NOT modify any code. This is analysis only.
- Do NOT fabricate findings. Report only what is in the JSON.
- If the findings array is empty, report "No actionable findings" with verdict PASS.
- If the JSON file is missing or empty, report the error and exit.
42 changes: 42 additions & 0 deletions .takt/workflows/post-pr-review.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: post-pr-review
description: >
CodeRabbit レビューコメントを分析し、深刻度別レポートを出力する。
入力: .takt/review-comments.json (Rust exe が書き出し)
Phase 1: 分析のみ。Phase 2 で fix loop を追加予定。

workflow_config:
provider_options:
codex:
network_access: true
opencode:
network_access: true

max_steps: 5
initial_step: analyze

steps:
# ---------------------------------------------------------------------------
# Step 1: analyze
# CodeRabbit の指摘を深刻度別に分類し、構造化レポートを出力する。
# Phase 2 で fix / re-review ステップを追加予定。
# ---------------------------------------------------------------------------
- name: analyze
edit: false
persona: code-reviewer
policy: review
knowledge: architecture
provider_options:
claude:
allowed_tools:
- Read
- Glob
- Grep
- Bash
instruction: analyze-coderabbit
output_contracts:
report:
- name: coderabbit-analysis.md
format: coderabbit-analysis
rules:
- condition: Analysis complete
next: COMPLETE
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- [ADR-015: Push Pipeline を takt ベースの push-runner に移行](docs/adr/adr-015-push-runner-takt-migration.md) *(Supersedes ADR-008 の push 前パイプライン部分)*
- [ADR-016: Claude Code Bash ツールでの長時間コマンド実行戦略](docs/adr/adr-016-long-running-command-strategy.md)
- [ADR-017: takt バージョン固定と検証環境の維持](docs/adr/adr-017-takt-version-pinning.md)
- [ADR-018: cli-pr-monitor の takt ベース移行と CronCreate 廃止](docs/adr/adr-018-pr-monitor-takt-migration.md) *(Supersedes ADR-009 の daemon + CronCreate 部分)*

## Build

Expand Down
104 changes: 104 additions & 0 deletions docs/adr/adr-018-pr-monitor-takt-migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# ADR-018: cli-pr-monitor の takt ベース移行と CronCreate 廃止

## ステータス

承認済み (2026-04-15)

Supersedes: ADR-009 (Post-PR Monitor) の daemon + CronCreate アーキテクチャ部分

## コンテキスト

### 問題

ADR-009 で導入した cli-pr-monitor は daemon spawn + CronCreate による「お願いベース」の通知フローを採用していた:

1. **4 段階の間接連携**: daemon → state file → CronCreate → Claude 読み取り → スキル発動。各段階で失敗しうる
2. **CronCreate の信頼性**: Claude Code がセッション状態によっては CronCreate を正しく実行しない場合がある
3. **AI 分析の欠如**: CodeRabbit 指摘は state file に生の findings として保存されるが、深刻度分析や対応方針の提示は Claude の「お願いベース」
4. **ADR-015 との不整合**: push-runner は takt ベースに移行済みだが、pr-monitor は旧アーキテクチャのまま

### ADR-015 の成功パターン

push-runner で確立された「機械的ステップは Rust、AI ステップは takt」の分離原則が有効であることが実証されている。同じパターンを pr-monitor にも適用する。

## 決定

### daemon + CronCreate を廃止し、in-process sequential chain + takt に移行する

**パイプライン構成:**

```text
cli-pr-monitor.exe --monitor-only
|
+-- Stage 1: poll_loop (Rust, in-process, blocking)
| check-ci-coderabbit.exe を 2分間隔で実行
| 最大 10分タイムアウト
| state file を毎回更新 (debug/observability 用)
|
+-- Stage 2: collect_findings (Rust)
| action_required or findings ありの場合:
| .takt/review-comments.json に書き出し
|
+-- Stage 3: run_takt (takt, optional)
| pnpm exec takt -w post-pr-review -t "analyze PR review"
| review-comments.json を読み、深刻度別レポートを stdout 出力
|
+-- Stage 4: print_report (stdout)
```

### 設計原則

1. **機械的ステップは Rust**: ポーリング、state 管理、JSON 書き出しは Rust exe 内で直接実行
2. **AI ステップは takt**: CodeRabbit 指摘の分析・深刻度分類は takt ワークフローで実行
3. **takt はオプショナル**: `pr-monitor-config.toml` に `[takt]` セクションがなければポーリング結果のみ報告
4. **CronCreate 不要**: in-process blocking で完了まで待ち、Bash tool の `run_in_background` で完了通知

### 設定ファイルの分離

`hooks-config.toml` の `[post_pr_monitor]` セクションから `pr-monitor-config.toml` に移行:

```toml
[monitor]
enabled = true
poll_interval_secs = 120
max_duration_secs = 600
check_ci = true
check_coderabbit = true

[takt]
workflow = "post-pr-review"
task = "analyze PR review comments"
extra_args = ["--pipeline", "--skip-git"]
```

## 影響

### 廃止

- `--daemon` フラグ: バックグラウンド daemon モードを削除
- `stages/daemon.rs`: spawn_daemon + run_daemon を削除
- CronCreate 指示の stdout 出力: print_cron_instruction を削除
- `pnpm mark-notified` / `pnpm check-monitor` スクリプト: 不要に
- `hooks-config.toml` の `[post_pr_monitor]` セクション: `pr-monitor-config.toml` に移行

### 維持

- `--monitor-only` フラグ: `pnpm push` チェーンからの呼び出し
- `--mark-notified` フラグ: 後方互換性のため残す(state file は debug 用に残る)
- `check-ci-coderabbit.exe`: ポーリングで使用
- `lib-report-formatter`: Finding 構造体を継続使用
- state file (`pr-monitor-state.json`): debug/observability 用に維持

### 新規追加

- `stages/poll.rs`: in-process 同期ポーリングループ
- `stages/collect.rs`: .takt/review-comments.json 書き出し
- `stages/takt.rs`: takt ワークフロー呼び出し
- `pr-monitor-config.toml`: 専用設定ファイル
- `.takt/workflows/post-pr-review.yaml`: takt ワークフロー (Phase 1: 分析のみ)
- `.takt/facets/instructions/analyze-coderabbit.md`: 分析用 instruction

## 次ステップ (スコープ外)

- **Phase 2: fix loop + re-push**: takt ワークフローに fix ステップを追加し、CodeRabbit 指摘の自動修正 + re-push まで一気通貫で処理
- **push-runner との共通化**: fix loop / report ロジックの共通 takt instruction 化
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
"create-pr": ".\\.claude\\cli-pr-monitor.exe",
"merge-pr": ".\\.claude\\cli-merge-pipeline.exe",
"check-ci": ".\\.claude\\check-ci-coderabbit.exe",
"mark-notified": ".\\.claude\\cli-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
17 changes: 17 additions & 0 deletions pr-monitor-config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# pr-monitor-config.toml -- cli-pr-monitor (takt ベース) の設定
#
# pnpm create-pr / pnpm push (--monitor-only) で起動される
# cli-pr-monitor.exe がこのファイルを読み込む。
# カレントディレクトリ (リポジトリルート) を優先的に検索する。

[monitor]
enabled = true
poll_interval_secs = 120
max_duration_secs = 600
check_ci = true
check_coderabbit = true

[takt]
workflow = "post-pr-review"
task = "analyze PR review comments"
extra_args = ["--pipeline", "--skip-git"]
6 changes: 6 additions & 0 deletions scripts/deploy-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ function deployTo(targetDir: string): boolean {
"See templates/push-runner-config.toml for a starting point"
);

notifyIfMissing(
join(targetDir, "pr-monitor-config.toml"),
"pr-monitor-config.toml not found — takt pr-monitor requires this at repo root",
"See templates/pr-monitor-config.toml for a starting point"
);

const templateSrc = join(CLAUDE_DIR, SETTINGS_TEMPLATE);
if (existsSync(templateSrc)) {
const template = readFileSync(templateSrc, "utf8");
Expand Down
Loading