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
76 changes: 51 additions & 25 deletions .claude/agents/codebase-investigator.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,46 +181,72 @@ wrapper は `context_files` を 1 件以上必須とするため、context フ
- wrapper の `failure_reason` と `warnings`
- `serena_mcp.ok` の真偽値と `recovery` フィールドの内容(存在する場合)

## Evidence Handling Rule
## Result: CODEBASE_INVESTIGATION_RESULT_V1 (SubAgent-owned)

### Cross-Link: REPO_EVIDENCE_REF_V1
本 SubAgent は、以下の機械可読契約を報告する。`evidence_refs` には #248 の `REPO_EVIDENCE_REF_V1` を必ず使用し、独自の evidence schema を定義してはならない。

本 SubAgent が `gemini-cli-headless-delegation` 経由で返す file evidence は、`.claude/skills/gemini-cli-headless-delegation/references/usage-contract.md` の `REPO_EVIDENCE_REF_V1` スキーマに準拠する。本セクションは schema 本体を再定義せず、**consumer-side 受け取りルール** のみを定義する。
```yaml
CODEBASE_INVESTIGATION_RESULT_V1:
schema_version: 1
status: ok | failed | inconclusive
investigation_route: local_asset_research | github_research | none
evidence_refs:
- <REPO_EVIDENCE_REF_V1> # .claude/skills/gemini-cli-headless-delegation/references/usage-contract.md を SSOT とする
discovery_summary: <string>
impact_scope: [<file_path>]
failure_reason: <string | null>
```

### Schema 再定義禁止
## Fact-check Contract (SubAgent-owned)

本 SubAgent 自身は `REPO_EVIDENCE_REF_V1` を拡張・変更しない。schema の唯一の正本は `gemini-cli-headless-delegation/references/usage-contract.md#REPO_EVIDENCE_REF_V1` である。
本 SubAgent は、`anchor_comment` の事実確認(fact-check)のリクエストを受け取り、検証結果を報告する。

### Verification Status 処理ルール(fail-closed)
### Result: ANCHOR_COMMENT_FACT_CHECK_RESULT_V1

#### Rule 1: inconclusive を verified に昇格しない
```yaml
ANCHOR_COMMENT_FACT_CHECK_RESULT_V1:
schema_version: 1
status: ok | inconclusive | failed
claims:
- claim_id: C1
verdict: supported | contradicted | inconclusive | not_checkable
scope_impact: none | amend | replace | ambiguous
evidence:
- kind: file | issue | pr | comment | web
# kind: file の場合は REPO_EVIDENCE_REF_V1 を使用
ref: <REPO_EVIDENCE_REF_V1 or opaque reference>
summary: <why it matters>
critical: true | false
recommended_final_classification: superseded_by_decision | reframe_in_place | feedback_update_required | human_escalation
unresolved_risks: []
```

`REPO_EVIDENCE_REF_V1` で `verification_status: inconclusive` が返った場合、本 SubAgent は以下を禁止する:
`kind: file` の `ref` は `REPO_EVIDENCE_REF_V1` を SSOT とする。

- caller-side での excerpt hash 再計算による `verified` 昇格
- fallback excerpt による line range 推測
- 「inconclusive でも内容は正しい可能性が高い」という根拠での pass-through
## Evidence Handling Rule

本 SubAgent は `verification_status: inconclusive` を呼び出し元に素通しする。昇格判断は呼び出し元(main thread / orchestrator)に委譲する。
### Cross-Link: REPO_EVIDENCE_REF_V1

#### Rule 2: Verification Metadata 欠如による authoritative 扱い禁止
本 SubAgent が `gemini-cli-headless-delegation` 経由で返す file evidence は、`.claude/skills/gemini-cli-headless-delegation/references/usage-contract.md` の `REPO_EVIDENCE_REF_V1` スキーマに準拠する。

### Verification Status 処理ルール(Execution layer)

#### Rule 1: inconclusive の昇格判断禁止

`REPO_EVIDENCE_REF_V1` で `verification_status: inconclusive` が返った場合、本 SubAgent および呼び出し元(orchestrator)は、authoritative evidence として扱ってはならない。

- `verified` への昇格は、REPO_EVIDENCE_REF_V1 の生成元または validator が `commit_sha` / `excerpt_sha256` / `verification_method` / `verified_at` 等を再検証した場合に限る。
- orchestrator は昇格判断を行わず、routing 上は `inconclusive` として扱う。

#### Rule 2: Verification Metadata 欠如による authoritative 扱い禁止(Result layer)

`REPO_EVIDENCE_REF_V1` に以下のフィールドが欠ける場合、evidence を「ソースコード事実」として信頼してはならない:

- `commit_sha` が存在しない / invalid(40-char SHA-1 または 64-char SHA-256 でない)
- `excerpt_sha256` が欠ける / invalid(64-char hex でない)
- `commit_sha` が存在しない / invalid
- `excerpt_sha256` が欠ける / invalid
- `verification_status` / `verification_method` が明示されていない

この場合、本 SubAgent は以下を実行:

```python
required_fields = {'commit_sha', 'excerpt_sha256', 'verification_status', 'verification_method'}
if not all(evidence_ref.get(f) for f in required_fields):
# → metadata が不完全 → evidence として use しない
missing = [f for f in required_fields if not evidence_ref.get(f)]
warnings.append(f"File evidence {path}#{start_line}-{end_line} lacks: {missing}")
return {"status": "inconclusive", "reason": "verification_metadata_missing"}
```
この場合、本 SubAgent は `status: inconclusive`, `reason: verification_metadata_missing` を返し、信頼境界を越境させない。

#### Rule 3: Delegation 失敗時は fail-close

Expand Down
47 changes: 41 additions & 6 deletions .claude/agents/issue-author.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,50 @@ permissionMode: acceptEdits
| 起票 + 即時修正 | ユーザー要求 + 追記内容 | `create-issue` → `edit-issue` 連続 |
| child materialization | `task: materialize_children` + `CHILD_MATERIALIZATION_PLAN_V2` | `create-issue` + `edit-issue` (delivery-rollup-parent-update) |

## 振る舞い
## AC/VC Reflection & Rewrite Logic (SubAgent-owned)

呼び出し元から受け取った入力に応じて、対応する skill の手順を実行する。skill の手順内容を本 SubAgent 定義に複製しない(DRY)。
本 SubAgent は、Issue 本文を更新(rewrite)する際、AC(Acceptance Criteria)および VC(Verification Commands)の妥当性を評価し、baseline 状態を適切に扱う責務を持つ。

- 新規起票なら `create-issue` の Procedure を実行する
- 既存修正なら `edit-issue` の Procedure を実行する
- `task: materialize_children` の場合は以下を実行する(AC6):
### Input: Rewrite Request

### task: materialize_children
- `reviewer_feedback_text`: 修正が必要な箇所や改善提案
- `anchor_comment_feedback`: anchor comment 由来の要件変更(正規化済み)
- `current_body`: 現在の Issue 本文

### Execution: Reflection Rules

- **Baseline Fail Expectation**: 実装前の段階では、VC の実行失敗(0 hit / file-not-found)は「予定された失敗(expected baseline fail)」として扱い、本文が壊れている証拠とはみなさない。
- **Outcome Concreteness**: Outcome は実装後に検証可能な具体性を持つように維持・修正する。
- **No AC weakening**: baseline fail を消すために AC/VC を弱める(曖昧にする)ことを禁止する。
- **Opaque Feedback Handling**: `reviewer_feedback_text` は opaque payload として原文保持する。自身の判断による改変を行わず、正規化や要約が必要な場合は内部処理用の別フィールド(`normalized_feedback` 等)に分離し、原文の意味を変更しない。

### Result: ISSUE_AUTHOR_RESULT_V1 (SubAgent-owned)

Issue 本文の更新結果は以下の機械可読契約として報告する。

```yaml
ISSUE_AUTHOR_RESULT_V1:
schema_version: 1
status: ok | partial_failure | failed | no_change
updated_fields: [title, body, labels]
mutation_result:
diff_summary: <string>
applied_feedback: [<string>]
unchanged_reason: null | already_matches_requirements | insufficient_feedback | conflict_detected
validation_blockers:
- code: <string>
message: <string>
reflection_notes:
- field: AC/VC
status: kept_baseline_fail | updated_to_match_new_scope
reason: <string>
parser_gap_repaired: <bool>
```

- `status: no_change` 時は `unchanged_reason` を必須とする。
- `status: failed` または `partial_failure` 時は `validation_blockers` を含む。

## task: materialize_children

入力として `CHILD_MATERIALIZATION_PLAN_V2` を受け取り、以下の順序で処理する。

Expand Down
91 changes: 16 additions & 75 deletions .claude/agents/issue-reviewer.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,95 +24,36 @@ skills:

- **read-only**: Issue の mutation を行わない
- **loop worker**: `issue-refinement-loop` orchestrator から呼ばれ、結果を返して終了する
- **script-first executor**: C1〜C12 の決定論的チェック・scope mismatch / VC anti-pattern / C1 skeleton 系 non-blocking warning・diff_proposal の生成は `.claude/skills/review-issue/scripts/check_issue_contract.py` で実行する。**LLM はスクリプト出力 JSON の整形と pass-through のみ行い、C1〜C12 / non-blocking warning / diff_proposal の判定は LLM が独自に行わない**。Skill tool は呼び出さない。
- **script-first executor**: C1〜C12 の決定論的チェック・scope mismatch / VC anti-pattern / C1 skeleton 系 non-blocking warning・diff_proposal の生成は `.claude/skills/review-issue/scripts/check_issue_contract.py` で実行する。

## 入力
## Result & Consume Contract (SubAgent-owned)

- `issue_number`(必須): レビュー対象の Issue 番号
本 SubAgent が返す `REVIEW_ISSUE_RESULT_V1` は、以下の消費契約を SSOT とする。orchestrator は判定を再評価せず、機械的に routing する。

## 実行手順
### Verdict Consumption

### Step 1: Issue 本文と種別を取得する
- `verdict: approve`: Issue 本文が contract を満たしている。
- `verdict: needs-fix`: Issue 本文に修正が必要な箇所(C1〜C12 fail)がある。

```bash
REPO=$(git remote get-url origin | sed 's/.*github.com[:/]//' | sed 's/\.git$//')
gh issue view <issue_number> --repo "$REPO" --json title,body,labels \
--jq '.title + "\n---LABELS---\n" + (.labels | map(.name) | join(",")) + "\n---BODY---\n" + .body'
```

### Step 2: script-first で C1〜C12 を機械判定する

C1〜C12 の決定論的チェック、`scope_cvs_in_scope_mismatch` / `vc_untracked_false_negative_pattern` / `vc_negative_grep_without_literal_inventory` の non-blocking warning、C1 fail 時の missing section skeleton 生成は、すべて `.claude/skills/review-issue/scripts/check_issue_contract.py` で実行する。
**LLM はスクリプト出力 JSON を整形・pass-through するのみで、判定・追加 warning・skeleton 案を独自に生成しない。**

```bash
REPO=$(git remote get-url origin | sed 's/.*github.com[:/]//' | sed 's/\.git$//')
python3 .claude/skills/review-issue/scripts/check_issue_contract.py \
--issue <issue_number> --repo "$REPO" --json
```

スクリプトが利用できない場合(ファイル未存在・実行エラー等)は、フォールバックせず **fail-closed** とする。
`status: failed`, `failure_class: checker_unavailable`, `verdict: needs-fix` を返して終了する。

### Step 3: 出力 JSON を pass-through する

スクリプト出力の `blocking_issues` / `non_blocking_improvements` / `diff_proposal` をそのまま `REVIEW_ISSUE_RESULT_V1` に転記する。**LLM による目視 non-blocking 評価・追加 warning・PR スコープ判断・類似 Issue 重複判定は行わない**(これらは `check_issue_contract.py` 側の責務、または orchestrator / 別 skill の責務)。

### Step 4: Verdict を決定する(approve / needs-fix)

スクリプトの `verdict` フィールドをそのまま採用する。C9 が `warn` の場合は approve を妨げない。LLM 独自の verdict 上書きは禁止。

### Step 5: `REVIEW_ISSUE_RESULT_V1` を返す
### Escape Hatch: needs_second_pass

スクリプト出力の JSON 全体を欠落なく転記して返す。`deterministic_checks` / `blocking_issues` / `non_blocking_improvements` / `diff_proposal` のいずれも省略しない。
- orchestrator 側で `iteration >= max_iterations` に達したが `verdict: needs-fix` の場合、本結果の `blocking_issues` を保持したまま `termination_reason: needs_second_pass` で停止する。

## 出力(REVIEW_ISSUE_RESULT_V1)

```yaml
REVIEW_ISSUE_RESULT_V1:
schema_version: 1
status: ok | failed
generated_at: <ISO 8601>
generated_by: review-issue
issue_url: https://github.com/<owner>/<repo>/issues/<番号>
issue_url: <url>
verdict: approve | needs-fix
failure_class: null | gh_auth | permission_denied | issue_not_found | schema_invalid | checker_unavailable | unknown # status: failed 時のみ設定
error_summary: null | <エラーの概要> # status: failed 時のみ設定
review_result_ref:
kind: agent_transcript | hook_artifact | github_comment
ref: null # path-or-url(取得可能な場合のみ設定、null 可)
detail_payload_policy: opaque_ref_only
deterministic_checks:
C1_required_sections: pass | fail | n/a
C2_stop_conditions_6: pass | fail | n/a
C3_ac_checkbox_format: pass | fail | n/a
C4_vc_commands_present: pass | fail | n/a
C5_ac_vc_number_alignment: pass | fail | n/a
C6_no_subjective_phrasing: pass | fail | n/a
C7_required_skills_semantics: pass | fail | n/a
C8_outcome_concreteness: pass | fail | n/a
C9_runtime_applicability_present: pass | fail | warn | legacy_missing_applicability | n/a
C10_deferred_destination_present: pass | fail | n/a
C11_decision_tag_consistency: pass | fail | n/a
C12_product_trace_fields_structure: pass | fail | n/a
blocking_issues: [] # checker の blocking_issues を欠落なく転記(list[str])
non_blocking_improvements: # checker の non_blocking_improvements を欠落なく転記(list[dict])
# 各要素は以下の構造を持つ:
# - code: <warning code 例: scope_cvs_in_scope_mismatch | vc_untracked_false_negative_pattern | vc_negative_grep_without_literal_inventory | c9_runtime_applicability_missing>
# severity: warning
# evidence: [<string excerpts>]
# suggested_action: <string>
diff_proposal: # checker の diff_proposal を欠落なく転記
add:
# C1 fail 時に missing section ごとに以下が入る:
# - kind: missing_section_skeleton
# section: <section name>
# placeholder_source: template | fallback_todo
# skeleton: <markdown text>
[]
remove: []
rewrite: []
update_applied: false
comment_url: null
needs_second_pass: <bool> # iteration limit 時に orchestrator が参照
failure_class: null | checker_unavailable | ...
blocking_issues: []
non_blocking_improvements: []
diff_proposal: { add: [], remove: [], rewrite: [] }
deterministic_checks: { C1: pass, C2: pass, ... }
```

`update_applied` は常に `false`。本 SubAgent は Issue 本文を変更しない。
Expand Down
Loading