Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
72 changes: 48 additions & 24 deletions .takt/facets/instructions/analyze-coderabbit.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CodeRabbit Review Analysis
# CodeRabbit Review Analysis (with Project Fitness Filter)

## Input

Expand All @@ -11,52 +11,76 @@ Read `.takt/review-comments.json`. This file contains the output from `check-ci-

## Task

1. Read the JSON file with the Read tool
### Step 1: Read and parse
1. Read `.takt/review-comments.json` 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
### Step 2: Project fitness filter
CodeRabbit sometimes raises findings that are not applicable to this project. Before classifying severity, evaluate each finding against the project context:

1. Read `CLAUDE.md` to understand the project's architecture decisions and constraints
2. For each finding, check:
- **Platform scope**: This project targets Windows only. Findings about cross-platform compatibility (e.g., `.exe` hardcoding) are NOT applicable -- downgrade to `Info`
- **Intentional design**: Check if the finding contradicts an ADR decision. If so, mark as `not_applicable`
- **Scope mismatch**: If the finding targets a read-only zone (`.takt/`, `docs/adr/`, `templates/`), mark as `not_applicable`
- **False positive**: If the finding misunderstands the code logic, mark as `not_applicable`

Mark each finding as:
- `applicable` -- genuine issue that should be addressed
- `not_applicable` -- does not apply to this project (with reason)

### Step 3: Severity classification
For `applicable` findings only, classify by severity:
- Critical > High > Major > Medium > Minor > Low > Info

### Step 4: Produce report and verdict

Produce a structured Markdown report:
## Output Format

```markdown
## CodeRabbit Analysis Report

### Summary
- CI: [status]
- CodeRabbit: [N] findings ([X] critical/high, [Y] medium, [Z] low)
- Verdict: PASS / FAIL
- CodeRabbit: [N] findings total, [M] applicable after filter
- Verdict: PASS / NEEDS_FIX / USER_DECISION

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
### Filtered Findings (not applicable)
| # | File (Line) | Issue | Filter Reason |
|---|-------------|-------|---------------|
| 1 | path:line | ... | Platform scope: Windows only |

### Findings by Severity
### Applicable Findings by Severity

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

#### Medium
...

#### Low / Info
...
#### Medium / Minor
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
| # | File (Line) | Issue | Recommended Action |
|---|-------------|-------|--------------------|

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

## Verdict Rules
## Verdict Rules (3-way)

- **FAIL**: Any Critical or High or Major severity finding exists
- **PASS**: Only Medium or lower severity findings (or no findings)
- **approved**: No applicable findings, OR all applicable findings are Info/Low severity
- Output: `approved` condition
- **needs_fix**: Any applicable Critical or Major finding exists
- Output: `needs_fix` condition
- These will be automatically fixed in the next step
- **user_decision**: Only Medium or lower applicable findings exist (no Critical/Major)
- Output: `user_decision` condition
- These are reported but NOT auto-fixed; the user decides

## 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.
- Do NOT skip the fitness filter. Every finding must be evaluated for project applicability.
- If the findings array is empty, report "No actionable findings" with verdict `approved`.
- If the JSON file is missing or empty, report the error and exit.
- When this is a re-analysis after a fix iteration, compare with previous reports to check for regression or persistence.
129 changes: 123 additions & 6 deletions .takt/workflows/post-pr-review.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: post-pr-review
description: >
CodeRabbit レビューコメントを分析し、深刻度別レポートを出力する。
CodeRabbit レビューコメントを分析・フィルタし、Critical/Major を自動修正する。
入力: .takt/review-comments.json (Rust exe が書き出し)
Phase 1: 分析のみ。Phase 2 で fix loop を追加予定。
フロー: analyze (適合性フィルタ + 深刻度分類) -> fix (Critical/Major) -> supervise

workflow_config:
provider_options:
Expand All @@ -11,14 +11,30 @@ workflow_config:
opencode:
network_access: true

max_steps: 5
max_steps: 30
initial_step: analyze

loop_monitors:
- cycle:
- analyze
- fix
threshold: 2
judge:
persona: supervisor
instruction: loop-monitor-reviewers-fix
rules:
- condition: Healthy (progress being made)
next: analyze
- condition: Unproductive (repeated findings, fixes not applied)
next: supervise

steps:
# ---------------------------------------------------------------------------
# Step 1: analyze
# CodeRabbit の指摘を深刻度別に分類し、構造化レポートを出力する。
# Phase 2 で fix / re-review ステップを追加予定。
# CodeRabbit 指摘をプロジェクト適合性でフィルタし、深刻度を再分類する。
# approved: 指摘なし or 全て不適合 -> COMPLETE
# needs_fix: Critical/Major あり -> fix
# user_decision: Medium 以下のみ -> COMPLETE (レポート出力のみ)
# ---------------------------------------------------------------------------
- name: analyze
edit: false
Expand All @@ -38,5 +54,106 @@ steps:
- name: coderabbit-analysis.md
format: coderabbit-analysis
rules:
- condition: Analysis complete
- condition: approved
next: COMPLETE
- condition: needs_fix
next: fix
- condition: user_decision
next: COMPLETE

# ---------------------------------------------------------------------------
# Step 2: fix
# Critical/Major の自動修正。fix.md (pre-push-review と共有) をベースに、
# CodeRabbit 指摘に特化した入力ソース指示を追加。
# loop_monitor で最大 2 回の fix -> analyze ループを許可。
# ---------------------------------------------------------------------------
- name: fix
edit: true
persona: coder
model: sonnet
policy:
- coding
- testing
knowledge:
- architecture
- security
provider_options:
claude:
allowed_tools:
- Read
- Glob
- Grep
- Edit
- Write
- Bash
- WebSearch
- WebFetch
required_permission_mode: edit
pass_previous_response: false
instruction: fix
rules:
- condition: Fixes complete
next: analyze
- condition: Unable to proceed with fixes
next: supervise

# ---------------------------------------------------------------------------
# Step 3: supervise
# エスカレーション。fix.md / supervise.md は pre-push-review と共有。
# ---------------------------------------------------------------------------
- name: supervise
edit: false
persona: supervisor
policy: review
provider_options:
claude:
allowed_tools:
- Read
- Glob
- Grep
- WebSearch
- WebFetch
instruction: supervise
pass_previous_response: false
output_contracts:
report:
- name: supervisor-validation.md
format: supervisor-validation
- name: summary.md
format: summary
use_judge: false
rules:
- condition: All validations complete, ready to push
next: COMPLETE
- condition: Issues detected
next: fix_supervisor

- name: fix_supervisor
edit: true
persona: coder
model: sonnet
policy:
- coding
- testing
knowledge:
- architecture
- security
provider_options:
claude:
allowed_tools:
- Read
- Glob
- Grep
- Edit
- Write
- Bash
- WebSearch
- WebFetch
required_permission_mode: edit
instruction: fix-supervisor
pass_previous_response: false
rules:
- condition: Fixes for supervisor findings complete
next: supervise
- condition: Unable to proceed with fixes
next: supervise
5 changes: 3 additions & 2 deletions docs/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
- [x] **templates/ に push-runner-config.toml 追加**: 派生プロジェクトへの deploy:hooks で push-runner-config.toml が配布されない問題。テンプレート追加 + deploy-hooks.ts 更新
- [x] **pre-push-review スキルの役割整理**: takt 導入済みプロジェクトでは不要に。takt 未導入の派生プロジェクト向けにフォールバックとして維持

## 次ステップ: cli-pr-monitor の takt 化
## cli-pr-monitor の takt 化

- [ ] **cli-pr-monitor を takt ベースに段階的移行**: daemon ポーリング完了後に takt ワークフローで CodeRabbit 指摘の自動分析を実行。Phase 2 では fix loop による自動修正 + re-push まで一気通貫で処理する構想。push-runner と同様に「機械的ポーリングは Rust、AI 分析は takt」の分離原則を適用する (ADR-015 次ステップ参照)
- [x] **Phase 1: in-process ポーリング + takt 分析** (PR #38, #39, #40): daemon spawn + CronCreate を廃止し、in-process sequential chain (poll -> collect -> takt analyze -> report) に移行。ADR-018 で決定を記録
- [x] **Phase 2: fix loop + ハイブリッド re-push** (PR #41): takt ワークフローに fix + supervise ステップを追加。CodeRabbit 指摘のプロジェクト適合性フィルタ、Critical/Major の自動修正、深刻度別の re-push 制御 (Critical=自動, Major以下=ユーザー確認) を実装。fix.md / supervise.md は pre-push-review と共有

## プロセス改善

Expand Down
6 changes: 6 additions & 0 deletions pr-monitor-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ check_coderabbit = true
workflow = "post-pr-review"
task = "analyze PR review comments"
extra_args = ["--pipeline", "--skip-git"]

[fix]
# Critical 修正は自動 re-push。Major 以下はユーザー確認後 push。
# "critical" = Critical のみ自動, "major" = Critical+Major 自動, "none" = 全て手動
auto_push_severity = "critical"
push_command = "jj git push"
50 changes: 50 additions & 0 deletions src/cli-pr-monitor/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub(crate) struct Config {
#[serde(default)]
pub(crate) monitor: MonitorConfig,
pub(crate) takt: Option<TaktConfig>,
#[serde(default)]
pub(crate) fix: FixConfig,
}

#[derive(Deserialize, Clone)]
Expand Down Expand Up @@ -64,6 +66,32 @@ pub(crate) struct TaktConfig {
pub(crate) extra_args: Option<Vec<String>>,
}

#[derive(Deserialize, Clone)]
pub(crate) struct FixConfig {
/// Critical 修正は自動 re-push する。Major 以下はユーザー確認。
#[serde(default = "default_auto_push_severity")]
pub(crate) auto_push_severity: String,
/// push コマンド (jj git push / git push)
#[serde(default = "default_push_command")]
pub(crate) push_command: String,
}

fn default_auto_push_severity() -> String {
"critical".into()
}
fn default_push_command() -> String {
"jj git push".into()
}

impl Default for FixConfig {
fn default() -> Self {
Self {
auto_push_severity: default_auto_push_severity(),
push_command: default_push_command(),
}
}
}

fn config_path() -> PathBuf {
let filename = "pr-monitor-config.toml";

Expand Down Expand Up @@ -193,4 +221,26 @@ task = "t"
let takt = config.takt.unwrap();
assert!(takt.extra_args.is_none());
}

#[test]
fn config_fix_defaults() {
let toml_str = "[monitor]\n";
let config: Config = toml::from_str(toml_str).unwrap();
assert_eq!(config.fix.auto_push_severity, "critical");
assert_eq!(config.fix.push_command, "jj git push");
}

#[test]
fn config_fix_custom() {
let toml_str = r#"
[monitor]

[fix]
auto_push_severity = "major"
push_command = "git push"
"#;
let config: Config = toml::from_str(toml_str).unwrap();
assert_eq!(config.fix.auto_push_severity, "major");
assert_eq!(config.fix.push_command, "git push");
}
}
1 change: 1 addition & 0 deletions src/cli-pr-monitor/src/stages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod create_pr;
mod mark_notified;
mod monitor;
pub(crate) mod poll;
pub(crate) mod push;
pub(crate) mod takt;

pub(crate) use create_pr::run_create_pr;
Expand Down
Loading