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
9 changes: 7 additions & 2 deletions .claude/skills/impl-review-loop/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ implementation child issue を **実装 → 検証 → PR レビュー** の 3

- `issue_number`(必須): implementation child issue 番号
- `contract_snapshot_url`(任意、省略時は preparation ステップで自動取得): `issue-contract-review` で `status: go` を返したコメントの URL。未提供の場合は preparation ステップが Issue コメントから `CONTRACT_REVIEW_RESULT_V1 status: go` コメントを自動検出する(存在すれば採用、なければ `issue-contract-review` を自動呼び出し)
- `max_iterations`(任意、デフォルト 5): 上限回数。超過時は fail-close で人間判断を仰ぐ
- `max_iterations`(任意、デフォルト 3): 上限回数。超過時は fail-close で人間判断を仰ぐ

## Loop Structure

Expand Down Expand Up @@ -59,7 +59,7 @@ LOOP_STATE:
contract_snapshot_url: <URL>
contract_snapshot_source: provided | detected_existing | materialized_by_issue_contract_review
iteration: <int, 0-indexed>
max_iterations: 5
max_iterations: 3
worktree: .claude/worktrees/issue-<番号>-<slug>
branch: worktree-issue-<番号>-<slug>
last_step: implementation | verification | pr_review | judgment
Expand Down Expand Up @@ -114,6 +114,7 @@ preparation step で取得した contract snapshot 内の以下の情報を Step

## Guardrails

- loop policy(何回まで自動で回すか)と Claude Code permission mode(ツール呼び出しの承認方式)は直交する概念であり、loop policy の継続判断に `--permission-mode` / `permissions.defaultMode` / `--dangerously-skip-permissions` を参照しない
- control-plane だけを担い、data-plane 操作(push / `gh pr edit` / マージ等)は SubAgent に委譲する
- LOOP_STATE をイテレーションごとに更新し、人間がループの全履歴を読めるようにする
- `max_iterations` 超過時は必ず fail-close(無限ループ防止)
Expand All @@ -130,6 +131,10 @@ preparation step で取得した contract snapshot 内の以下の情報を Step
- `docs/dev/agent-skill-boundaries.md` — オーケストレーター設計原則(control-plane / LOOP_STATE / 人間承認原則)
- `docs/dev/github-ops.md` — GitHub 運用ルール(body-file guard / コメントテンプレ)

## Loop Policy 参照

impl-review-loop は `.claude/skills/issue-refinement-loop/references/termination-policy.md` の `LOOP_POLICY_V1` と同一の routing policy を採用する。`max_iterations` 既定値 3、loop iteration approval gate は repo_loop_iteration_only スコープ、Claude Code permission mode は変更しない。

## 出力制約 (OUTPUT_BUDGET_V1)

`docs/dev/agent-skill-boundaries.md#OUTPUT_BUDGET_V1` の制約に従う。routing-critical な機械可読フィールドは削らず、人間向け説明・証跡・diff 再掲のみを削減する。
4 changes: 2 additions & 2 deletions .claude/skills/impl-review-loop/steps/preparation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
```yaml
issue_number: <int, 必須>
contract_snapshot_url: <URL, 任意> # 省略時は以下の自動検出フローで取得
max_iterations: 5 # 任意
max_iterations: 3 # 任意
```

### 1-a. `contract_snapshot_url` が提供された場合
Expand Down Expand Up @@ -244,7 +244,7 @@ LOOP_STATE:
contract_snapshot_url: <URL>
contract_snapshot_source: provided | detected_existing | materialized_by_issue_contract_review
iteration: 0
max_iterations: 5
max_iterations: 3
worktree: .claude/worktrees/issue-<番号>-<slug>
branch: worktree-issue-<番号>-<slug>
last_step: null
Expand Down
52 changes: 34 additions & 18 deletions .claude/skills/issue-refinement-loop/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,36 @@ subagent_contract_mode: link_only
## Inputs

- `issue_number`(必須): 改善対象の Issue 番号
- `max_iterations`(任意、既定 1): review cycle の上限
- `max_iterations`(任意、既定 3): review cycle の上限
- `anchor_comment_url`(任意): 人間 Decision や差し戻しコメントを snapshot 固定して扱う対象コメント URL

## Loop Policy

```yaml
loop_policy:
default_max_iterations: 3
loop_iteration_approval_gate:
default_required: false
scope: repo_loop_iteration_only
does_not_control:
- Claude Code permissions.defaultMode
- bypassPermissions
- --dangerously-skip-permissions
- --allow-dangerously-skip-permissions
- --permission-mode
- hooks PermissionRequest auto-approval
```

### loop_iteration_approval_gate

`loop_iteration_approval_gate.default_required: false`

ループの自動継続は「このリポジトリの loop policy 上の承認確認(過去に `--no-approval` と呼んでいた運用フラグ/指示)」であり、Claude Code の `--permission-mode`、`--dangerously-skip-permissions`、`permissions.defaultMode` は変更しない。loop policy は「何回まで自動で回すか」を制御し、Claude Code の permission mode は「ツール呼び出しの承認方式」を制御する。両者は直交する概念であり、loop policy の継続判断に permission mode を参照しない。

needs-fix を受け取ったとき:
- `iteration + 1 < max_iterations` → 自動継続(条件なし)
- `iteration + 1 >= max_iterations` → `human_escalation` で停止し、全 iteration 分の blocker summary を添付

## Loop Structure

```text
Expand All @@ -37,21 +64,11 @@ subagent_contract_mode: link_only
↓
approve → Step 4.5 → Step 5
needs-fix
├─ [blocker_class 確定]
│ review_blockers = REVIEW_ISSUE_RESULT_V1.blocking_issues
│ auto_fixable_ids = REFINEMENT_LOOP_PLAN_V1.decisions.auto_fixable_structural_blocker_list
│ if (review_blockers - auto_fixable_ids) is empty:
│ blocker_class = auto_fixable_structural
│ else:
│ blocker_class = requires_human
│
├─ no_approval == true
│ AND blocker_class == auto_fixable_structural
│ AND requires_human blockers == 0:
├─ iteration + 1 < max_iterations:
│ iteration += 1 → Step 4 (自動継続)
│
├─ iteration + 1 >= max_iterations → Step 5 (needs_second_pass)
└─ else Step 4 → issue-author → next iteration
└─ iteration + 1 >= max_iterations:
→ Step 5 (human_escalation) + 全 iteration 分 blocker summary
```

Step 3(adversarial review)と Step 1.5(spec document review)は採用しない。Step 番号は履歴互換のため維持する。
Expand All @@ -62,13 +79,12 @@ Step 3(adversarial review)と Step 1.5(spec document review)は採用し
LOOP_STATE:
issue_number: <int>
iteration: <int, 0-indexed>
max_iterations: 1
max_iterations: 3
last_verdict: approve | needs-fix | null
blockers_history: []
blocker_class: null | auto_fixable_structural | requires_human
improvements_applied: []
removed_state_labels: []
termination_reason: null | approved | needs_second_pass | human_escalation | superseded_by_decision
termination_reason: null | approved | human_escalation | superseded_by_decision
scope_rollup_decision: null
anchor_comment:
url: null
Expand Down Expand Up @@ -164,7 +180,7 @@ delivery-rollup parent の child materialization gate と、approve 後の follo

### Step 5: Termination

終了条件、`needs_second_pass` escape hatch、scope change signal 停止、loop termination table は `references/termination-policy.md` を参照する。
終了条件、`human_escalation` 経路、scope change signal 停止、loop termination table は `references/termination-policy.md` を参照する。

## Reference Map

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,14 @@
| condition | termination_reason |
|---|---|
| Step 2 returns `approve` | `approved` |
| Step 2 returns `needs-fix` and `iteration + 1 >= max_iterations` and `--no-approval` not set | `needs_second_pass` |
| Step 2 returns `needs-fix` and `iteration + 1 >= max_iterations` and `--no-approval` set and `blocker_class: requires_human` | `needs_second_pass` |
| Step 2 returns `needs-fix` and `iteration + 1 >= max_iterations` and `--no-approval` set and `blocker_class: auto_fixable_structural` | auto-continue to second iteration |
| Step 2 returns `needs-fix` and `iteration + 1 < max_iterations` | continue to next iteration |
| Step 2 returns `needs-fix` and `iteration + 1 >= max_iterations` | `human_escalation` (with full blocker summary) |
| Any step requires human review | `human_escalation` |
| `final_classification == superseded_by_decision` and close / replacement flow completed | `superseded_by_decision` |

## NEEDS_SECOND_PASS escape hatch
## Human Escalation on max_iterations

`iteration` は完了した review cycle 数を表す。`max_iterations=1` 既定では、最初の `needs-fix` で Step 4 を自動実行せず停止する。次パスを回すには明示的な iteration 追加または人間判断が必要。

## --no-approval auto-continuation(blocker_class: auto_fixable_structural)

`--no-approval` フラグが設定されており、かつ `blocker_class` が `auto_fixable_structural` のみの場合は、`max_iterations` を超えていても第2イテレーションへ自動継続する。

### auto_fixable_structural とみなす blocker の種類

| blocker_id | 説明 |
|---|---|
| `missing_machine_readable_contract` | `## Machine-Readable Contract` セクション欠落(YAML フロントマター生成可能) |
| `missing_stop_conditions` | `## Stop Conditions` セクション欠落(issue_kind / change_kind から定型生成可能) |
| `vc_missing_prefix` | `## Verification Commands` の `$` / `- ` プレフィックス欠落(形式変換のみ) |

### requires_human とみなす blocker の種類

以下のいずれかが含まれる場合は `blocker_class: requires_human` とし、`needs_second_pass` で停止する。

| blocker_id | 説明 |
|---|---|
| `new_scope_area` | AC の追加・削除・変更が必要 |
| `ac_removed_or_weakened` | Acceptance Criteria の弱体化や削除 |
| `allowed_paths_expanded` | Allowed Paths の縮小・拡大 |
| `outcome_rewrite_needed` | Outcome のリライトが必要 |

### 分類ルール

1. `blocker_class` の分類は `REFINEMENT_LOOP_PLAN_V1.decisions.auto_fixable_structural_blocker_list` を参照する。
2. `auto_fixable_structural_blocker_list` が空でなく、かつ `requires_human` blocker が0件の場合は `blocker_class: auto_fixable_structural`。
3. `requires_human` blocker が1件でも含まれる場合は `blocker_class: requires_human`。
4. `--no-approval` 未指定の場合は `blocker_class` に関わらず `needs_second_pass` で停止する。
`iteration + 1 >= max_iterations` かつ approve なしの場合は `human_escalation` で停止し、全 iteration 分の blocker summary を終了コメントに添付する。`max_iterations=3` 既定では、3 回目の `needs-fix` で停止する。

## Additional stop rules

Expand All @@ -54,13 +23,29 @@
## Must not

- `approve` 以外を success 扱いして silently finish しない
- `max_iterations` を超えて自動ループしない(ただし `--no-approval` + `blocker_class: auto_fixable_structural` のみの場合は例外)
- `requires_human` blocker を自動処理しない
- `blocker_class: auto_fixable_structural` で auto-continue する際も `--no-approval` フラグの確認を省略しない
- `max_iterations` を超えて自動ループしない
- hard stop 条件(`state/needs-human`、scope change 等)をスキップしない

## Termination Result Schema(LOOP_TERMINATION_RESULT_V1)

`human_escalation` 終了時は以下の構造で終了コメントを出力する:

```yaml
LOOP_TERMINATION_RESULT_V1:
termination_reason: human_escalation
max_iterations: 3
blockers_history:
- iteration: 0
blockers: []
- iteration: 1
blockers: []
- iteration: 2
blockers: []
```

## Termination Comment(全 termination reason 共通)

すべての termination reason(`approved` / `needs_second_pass` / `human_escalation` / `superseded_by_decision`)で、終了コメントに `FOLLOW_UP_MATERIALIZATION_RESULT_V1` を含める。follow-up が存在しない場合も空配列で出力する(`follow_up_issues: []` / `note_only_observations: []`)。
すべての termination reason(`approved` / `human_escalation` / `superseded_by_decision`)で、終了コメントに `FOLLOW_UP_MATERIALIZATION_RESULT_V1` を含める。follow-up が存在しない場合も空配列で出力する(`follow_up_issues: []` / `note_only_observations: []`)。

```yaml
FOLLOW_UP_MATERIALIZATION_RESULT_V1:
Expand All @@ -71,3 +56,36 @@ FOLLOW_UP_MATERIALIZATION_RESULT_V1:
```

詳細 schema は `docs/dev/agent-skill-boundaries.md` の `FOLLOW_UP_MATERIALIZATION_RESULT_V1` を参照。`issue-refinement-loop` は thin orchestrator として raw context を保持せず、materialization 結果のみを報告する(`docs/dev/agent-skill-boundaries.md` の `ORCHESTRATOR_IO_BOUNDARY_V1` 参照)。

## Loop Policy(LOOP_POLICY_V1)

```yaml
LOOP_POLICY_V1:
max_iterations_default: 3
loop_iteration_approval_gate:
default_required: false
scope: repo_loop_iteration_only
does_not_control:
- Claude Code permissions.defaultMode
- bypassPermissions
- --dangerously-skip-permissions
- --allow-dangerously-skip-permissions
- --permission-mode
- hooks PermissionRequest auto-approval
routes:
- when: hard_stop_triggered
action: human_escalation
- when: verdict == "approve"
action: done
- when: "verdict == 'needs-fix' and iteration_plus_one < max_iterations"
action: continue
- when: "verdict == 'needs-fix' and iteration_plus_one >= max_iterations"
action: human_escalation
hard_stops:
- state/needs-human
- state/done
- scope_change_signal
- contract_malformation
- required_external_research_unresolved
- unsafe_mutation
```
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,6 @@
}
}
}
},
"auto_fixable_structural_blocker_list": {
"type": "array",
"description": "List of auto-fixable structural blocker IDs detected in the issue body. Empty list means no auto-fixable blockers detected.",
"items": {
"type": "string",
"enum": [
"missing_machine_readable_contract",
"missing_stop_conditions",
"vc_missing_prefix"
]
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@
FAIL_CLOSED_REASON_UNKNOWN_SCHEMA = "unknown_input_schema"
FAIL_CLOSED_REASON_INTERNAL_ERROR = "planner_internal_error"

# Auto-fixable structural blocker IDs
BLOCKER_MISSING_MACHINE_READABLE_CONTRACT = "missing_machine_readable_contract"
BLOCKER_MISSING_STOP_CONDITIONS = "missing_stop_conditions"
BLOCKER_VC_MISSING_PREFIX = "vc_missing_prefix"


# ---------------------------------------------------------------------------
# Regex patterns
Expand Down Expand Up @@ -500,54 +495,6 @@ def _check_missing_vc(issue_body: str) -> bool:
return "## Verification Commands" not in issue_body


def _detect_auto_fixable_structural_blockers(issue_body: str) -> list[str]:
"""
Detect auto-fixable structural blockers in the issue body.

Returns a list of blocker IDs that are present and auto-fixable
(i.e., can be fixed without human judgment).

Blocker IDs:
- missing_machine_readable_contract: ## Machine-Readable Contract section missing
- missing_stop_conditions: ## Stop Conditions section missing
- vc_missing_prefix: Verification Commands lines missing $ or - prefix
"""
blockers = []

# Check for missing ## Machine-Readable Contract section
if "## Machine-Readable Contract" not in issue_body:
blockers.append(BLOCKER_MISSING_MACHINE_READABLE_CONTRACT)

# Check for missing ## Stop Conditions section
if "## Stop Conditions" not in issue_body:
blockers.append(BLOCKER_MISSING_STOP_CONDITIONS)

# Check for Verification Commands lines missing $ or - prefix
sections = _extract_sections(issue_body)
vc_content = sections.get("Verification Commands", "")
if vc_content:
vc_lines = vc_content.splitlines()
has_unprefixed = False
for line in vc_lines:
stripped = line.strip()
# Skip empty lines, fenced code block markers, comments (#)
if not stripped:
continue
if stripped.startswith("```") or stripped.startswith("~~~"):
continue
if stripped.startswith("#"):
continue
# Any non-empty command line that lacks $ or - prefix is a blocker.
# Commands like pnpm, uv, rg, git, gh etc. without a $ or - prefix
# are exactly what should be flagged.
if not stripped.startswith("$") and not stripped.startswith("- "):
has_unprefixed = True
break
if has_unprefixed:
blockers.append(BLOCKER_VC_MISSING_PREFIX)

return blockers


def _validate_input_schema(data: Any) -> bool:
"""Validate input matches REFINEMENT_LOOP_PLANNER_INPUT_V1 schema."""
Expand Down Expand Up @@ -701,7 +648,6 @@ def plan_refinement_loop(input_data: dict[str, Any]) -> tuple[dict[str, Any], in
"follow_up_materialization": {
"candidates": [],
},
"auto_fixable_structural_blocker_list": [],
},
"fail_closed": {
"required": True,
Expand Down Expand Up @@ -769,9 +715,6 @@ def plan_refinement_loop(input_data: dict[str, Any]) -> tuple[dict[str, Any], in
issue_body, known_context
)

# Detect auto-fixable structural blockers
auto_fixable_structural_blocker_list = _detect_auto_fixable_structural_blockers(issue_body)

# Build output
plan = {
"schema_version": SCHEMA_VERSION,
Expand Down Expand Up @@ -812,7 +755,6 @@ def plan_refinement_loop(input_data: dict[str, Any]) -> tuple[dict[str, Any], in
"follow_up_materialization": {
"candidates": follow_up_candidates,
},
"auto_fixable_structural_blocker_list": auto_fixable_structural_blocker_list,
},
"fail_closed": {
"required": False,
Expand Down Expand Up @@ -864,7 +806,6 @@ def plan_refinement_loop(input_data: dict[str, Any]) -> tuple[dict[str, Any], in
"follow_up_materialization": {
"candidates": [],
},
"auto_fixable_structural_blocker_list": [],
},
"fail_closed": {
"required": True,
Expand Down Expand Up @@ -926,7 +867,6 @@ def main(argv: list[str] | None = None) -> None:
"follow_up_materialization": {
"candidates": [],
},
"auto_fixable_structural_blocker_list": [],
},
"fail_closed": {
"required": True,
Expand Down
Loading
Loading