diff --git a/.takt/facets/instructions/refute-finding.md b/.takt/facets/instructions/refute-finding.md index a181a338..eac8da26 100644 --- a/.takt/facets/instructions/refute-finding.md +++ b/.takt/facets/instructions/refute-finding.md @@ -39,7 +39,7 @@ Therefore **the tie goes to reject**: only let a finding survive when you have p Write `refutation-report.md` following its output contract: -- **Survived Findings** -- carry over the original `finding_id`, source, severity, location, issue, **and the reviewer's original fix suggestion**, and add the code-level **evidence it reproduces**. These are the only findings `fix` acts on, and `fix` reads this table as its work list, so make each row **self-contained**: a reader must be able to fix from the row alone (the `finding_id` lets them pull extra context from the reviewer report if needed). +- **Survived Findings** -- carry over the original `finding_id`, `family_tag`, source, severity, location, issue, **and the reviewer's original fix suggestion**, and add the code-level **evidence it reproduces**. These are the only findings `fix` acts on, and `fix` reads this table as its work list, so make each row **self-contained**: a reader must be able to fix from the row alone (the `finding_id` lets them pull extra context from the reviewer report if needed). - **Rejected Findings** -- carry over `finding_id`, source, location, and original issue, plus a concrete **rejection reason** (what you read that disproves it). This table is the audit log for dogfood measurement (reject rate / reject-error rate vs. later CodeRabbit re-findings), so make each reason specific and checkable. - **Verdict**: `ALL_REFUTED` when the Survived table is empty, otherwise `SOME_SURVIVE`. diff --git a/.takt/facets/output-contracts/refutation-report.md b/.takt/facets/output-contracts/refutation-report.md index a5843440..1f61c93e 100644 --- a/.takt/facets/output-contracts/refutation-report.md +++ b/.takt/facets/output-contracts/refutation-report.md @@ -4,9 +4,9 @@ ## Verdict: ALL_REFUTED / SOME_SURVIVE ## Survived Findings (passed to fix) -| # | finding_id | Source | Severity | Location | Issue | Fix Suggestion | Evidence it reproduces | -|---|------------|--------|----------|----------|-------|----------------|------------------------| -| 1 | SEC-NEW-src-db-L42 | security | High | `src/db.ts:42` | Raw query string | Use a parameterized query | Confirmed by reading line 42: user input is interpolated into the SQL string | +| # | finding_id | family_tag | Source | Severity | Location | Issue | Fix Suggestion | Evidence it reproduces | +|---|------------|------------|--------|----------|----------|-------|----------------|------------------------| +| 1 | SEC-NEW-src-db-L42 | injection-risk | security | High | `src/db.ts:42` | Raw query string | Use a parameterized query | Confirmed by reading line 42: user input is interpolated into the SQL string | ## Rejected Findings (refuted -- audit log) | # | finding_id | Source | Location | Original Issue | Rejection reason | diff --git a/.takt/facets/output-contracts/simplicity-review.md b/.takt/facets/output-contracts/simplicity-review.md new file mode 100644 index 00000000..8e01788f --- /dev/null +++ b/.takt/facets/output-contracts/simplicity-review.md @@ -0,0 +1,52 @@ +```markdown +# Simplicity Review + +## Result: APPROVE / REJECT + +## Summary +{1-2 sentence anomaly-scan result} + +## Anomaly Scan +| Category | Result | Notes | +|----------|--------|-------| +| Unexplained complexity | ✅ | - | +| Inconsistent style | ✅ | - | +| Dead-on-arrival code | ✅ | - | +| Hidden coupling | ✅ | - | +| Missing failure paths | ✅ | - | +| DRY / YAGNI (code logic) | ✅ | - | + +## Current Iteration Findings (new) +| # | finding_id | family_tag | Severity | Type | Location | Issue | Fix Suggestion | +|---|------------|------------|----------|------|----------|-------|----------------| +| 1 | SIM-NEW-src-x-L10 | dead-code | Medium | dead-on-arrival | `src/x.ts:10` | Helper with no caller | Remove or wire up | + +## Carry-over Findings (persists) +| # | finding_id | family_tag | Previous Evidence | Current Evidence | Issue | Fix Suggestion | +|---|------------|------------|-------------------|------------------|-------|----------------| +| 1 | SIM-PERSIST-src-y-L30 | deep-nesting | `src/y.ts:30` | `src/y.ts:30` | Nesting persists | Flatten with guard clause | + +## Resolved Findings (resolved) +| finding_id | Resolution Evidence | +|------------|---------------------| +| SIM-RESOLVED-src-x-L10 | `src/x.ts:10` helper removed | + +## Reopened Findings (reopened) +| # | finding_id | family_tag | Prior Resolution Evidence | Recurrence Evidence | Issue | Fix Suggestion | +|---|------------|------------|--------------------------|---------------------|-------|----------------| +| 1 | SIM-REOPENED-src-y-L55 | deep-nesting | `Previously flattened at src/y.ts:30` | `Recurred at src/y.ts:55` | Nesting reintroduced | Flatten again | + +## Warnings (non-blocking) +- {Non-blocking simplicity notes} + +## Rejection Gate +- REJECT is valid only when at least one finding exists in `new`, `persists`, or `reopened` +- Findings without `finding_id` are invalid +- `finding_id` is immutable: a finding keeps the same id as it moves across the `new` / `persists` / `resolved` / `reopened` tables (the table conveys status, not the id — the `SIM-NEW-` / `SIM-PERSIST-` prefixes in the examples above are illustrative only) +- `Type` is the anomaly category (e.g. dead-on-arrival, hidden-coupling, unexplained-complexity, inconsistent-style, missing-failure-path) +``` + +**Cognitive load reduction rules:** +- No anomalies → Anomaly Scan table only (10 lines or fewer) +- Warnings only → + Warnings in 1-2 lines (15 lines or fewer) +- Anomalies found → + finding tables (30 lines or fewer) diff --git a/CLAUDE.md b/CLAUDE.md index c2c2105e..22385c8d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -48,6 +48,7 @@ - [ADR-045: jj workspace による並列セッション運用 — メイン作業と細粒度改善の分離](docs/adr/adr-045-jj-workspace-parallel-sessions.md) *(試験運用)* - [ADR-046: ローカル LLM pre-push レビュアー — 選定スパイクと不採用判断](docs/adr/adr-046-local-llm-review-spike.md) *(却下)* - [ADR-047: pre-push review の反証(refute)facet](docs/adr/adr-047-prepush-refute-facet.md) *(試験運用)* +- [ADR-048: reviewers→fix findings handoff の output-contract 標準化(markdown 統一・JSON 却下)](docs/adr/adr-048-facet-findings-handoff-markdown-contract.md) *(試験運用)* ## Build diff --git a/docs/adr/adr-048-facet-findings-handoff-markdown-contract.md b/docs/adr/adr-048-facet-findings-handoff-markdown-contract.md new file mode 100644 index 00000000..8a3f7be2 --- /dev/null +++ b/docs/adr/adr-048-facet-findings-handoff-markdown-contract.md @@ -0,0 +1,128 @@ +# ADR-048: reviewers→fix findings handoff の output-contract 標準化 (markdown 統一・JSON 却下) + +## ステータス + +試験運用 (2026-07-06) + +> WP-07 (`docs/harness-improvement-plan.md`) の実装 ADR。計画の当初案 (findings の JSON 化) を +> takt 公式仕様の調査結果に基づき却下し、takt idiomatic な markdown output-contract の標準化に方針転換した記録。 + +## コンテキスト + +WP-07 の目的は、pre-push review の **reviewers → fix 間の findings 受け渡し**で発生しうる +「parse 事故・読み落とし」を防ぐことである。当初計画 (`docs/harness-improvement-plan.md` の WP-07) は +次の 2 ステップを想定していた: + +1. findings スキーマ定義 (file / line / severity / rationale / suggested_fix) を **JSON 化**。 +2. Rust 側 (cli-push-runner) に schema 検証 pre-step を追加、parse 失敗時は markdown fallback。 + +この当初案は計画策定セッション (Claude Fable 5) が「未検証」と明記した部分であり、実装着手前に +takt の公式仕様・ベストプラクティスを調査した。 + +### 調査結果 (takt 0.35.3 公式仕様、ADR-017 で pin) + +takt に同梱の公式スタイルガイド・スキーマ・builtins を精査した結果、以下が判明した: + +- **takt の idiomatic な facet 間 handoff は markdown レポートファイル**である。step は + `output_contracts.report[].format` で markdown レポートを出力し、実行ごとの `reports/` ディレクトリに + 保存され、後続 step が `{report:filename}` で参照する (`builtins/skill/references/engine.md`)。 +- 公式 **`OUTPUT_CONTRACT_STYLE_GUIDE.md`** は output-contract を「必ず ` ```markdown ` コードブロックで + 囲む」ことを要求し、DO/DON'T 表で **「プレーンテキストで出力契約を書く」を DON'T** と明記している。 +- output-contract のスキーマ (`schema-base.js` の `OutputContractItemSchema`) に `type` / `schema` / + `json` フィールドは存在せず、`format` は**検証されない markdown テンプレート文字列**にすぎない + (Phase 2 プロンプト末尾に verbatim 展開されるのみ、`ReportInstructionBuilder.js`)。 +- **29 の builtin output-contract・36 の builtin workflow・251 の report 宣言はすべて markdown (`.md`)**。 + スキーマ・builtins・docs のいずれにも JSON producer/consumer は存在しない。JSON handoff は takt の + 流儀に反する。 +- 構造化 findings の blessed な形は既に markdown テーブルで存在する: builtin `security-review` の + finding テーブル (`finding_id / family_tag / Severity / Type / Location / Issue / Fix Suggestion`)。 + +### parse 事故の真因 (JSON でないことではない) + +調査で判明した「読み落とし」の実体は「markdown だから」ではなく、**片方のレビュアーに output-contract が +存在せず、reviewer 間で finding テーブルの列が不統一**なことだった: + +- `format: security-review` → takt builtin の finding テーブル契約に解決される (構造あり)。 +- `format: simplicity-review` → **対応する contract ファイルが存在せず** (`.takt/facets/output-contracts/` + にも builtin にも無い)、takt はリテラル文字列 `"simplicity-review"` に degrade する + (`faceted-prompting/dist/resolve.js` の literal fallback)。結果、simplicity reviewer は + **構造の強制がゼロ**で free-form 出力していた (実 run の `simplicity-review.md` が裏付け)。 +- WP-06 で追加した `refutation-report` (project) は finding テーブルを持つが、列が上記と微妙に不統一。 + +### アーキテクチャ制約 (当初案の実現不能性) + +当初案の「Rust 側 (cli-push-runner) に検証 pre-step」は**構造的に実現不可能**である: + +- takt の step はすべて **LLM persona 呼び出し**であり、command/exec/script step 種別は存在しない + (`workflow-schemas.js` の zod schema で確認)。純粋な Rust 検証ノードを workflow 内に置けない。 +- cli-push-runner は takt workflow **全体を 1 つの不透明なサブプロセス** (`pnpm exec takt -w `) + として呼ぶ (`src/cli-push-runner/src/stages/takt.rs`)。`reviewers → fix` の handoff は takt 内部で + 起き、runner からは見えないため、その境界に pre-step を挟めない。 + +## 決定 + +当初の JSON 化を**却下**し、takt idiomatic な **markdown output-contract の標準化**で WP-07 の目的 +(parse 事故・読み落とし防止) を達成する。 + +1. **`.takt/facets/output-contracts/simplicity-review.md` を新設**し、builtin `security-review` の + finding テーブル構造を踏襲する。これにより simplicity reviewer にも構造が強制され、真因 + (片方に契約が無い) を直接解消する。`format: simplicity-review` は既存 workflow の記述のまま + 新規 project ファイルに解決されるため、**workflow YAML の変更は不要**。 +2. **reviewer 間で finding テーブルの列を統一**する。canonical 列: + `finding_id | family_tag | Severity | Type | Location (file:line) | Issue | Fix Suggestion`。 + security は builtin 契約 (同一列) をそのまま使用し、simplicity が同構造を mirror する。 +3. **`refutation-report.md` の Survived Findings テーブルに `family_tag` 列を追加**し、reviewer 契約と + 整合させる (fix の family_tag ベース同時修正に資する)。`refute-finding.md` の carry-over 指示も更新。 +4. 契約は公式スタイルガイド準拠 (` ```markdown ` ブロック + 認知負荷軽減ルール + `finding_id` 必須の + Rejection Gate)。 + +適用範囲は **pre-push review の reviewers** (通常 `pre-push-review.yaml` と refute variant +`pre-push-review-refute.yaml` の両方が同じ `format:` 名を共有するため自動的に裨益)。post-pr-review は +simplicity/security reviewer を持たず (CodeRabbit findings 駆動の analyze/fix 構成) 対象外。 + +## 却下した代替案 + +- **JSON handoff (当初計画案)**: takt 公式スタイルガイドの明示的 DON'T に反し、builtin (全 markdown) や + 将来の takt アップグレードと不整合を生む。機械可読性の利得は、後述の理由で markdown テーブルでも + 十分得られる。→ 却下。 +- **Rust 検証 pre-step を cli-push-runner に追加 (当初計画 step 2)**: takt が LLM step 専用かつ runner が + workflow 全体を不透明に呼ぶため、reviewers→fix 境界に介入できない。→ 実現不能。 +- **reviewers と fix の間に検証専用 takt movement を新設**: takt に非 LLM step が無いため LLM step を + 1 つ増やすことになり、コスト/レイテンシ増 + refute variant の verify step と干渉する。→ 却下。 +- **markdown finding テーブルを parse する Rust validator を Bash 経由で fix から呼ぶ**: takt 自体は + contract を検証しないため machine 検証層を自前で足す選択肢 (cli-finding-classifier の Bash 呼び出し + 前例あり)。有効だが、まず契約標準化で構造を揃える効果を観測し、必要なら follow-up とする。 + → 今回は見送り (順位化候補)。 + +## 帰結 + +### 利点 + +- simplicity reviewer に構造が強制され、reviewer 間で finding 列が統一される (真因の解消)。 +- takt 公式の idiomatic な機構 (`output_contracts` + `{report:}`) の上に乗るため、builtin・将来の + アップグレード・他 workflow と整合する。 +- `finding_id` 必須の Rejection Gate により「finding_id 無しの finding」を契約レベルで無効化 (読み落とし + 防止)。 +- ADR-020 (`fix.md` は入力形式非依存) の不変条件を維持 — fix は引き続き markdown レポートを読むだけ。 + +### 欠点 / 留意点 + +- takt は contract を機械検証しないため、reviewer が契約に**従わない**リスクは残る (LLM 出力の性質)。 + 完全な machine 検証が必要なら Bash 経由 Rust validator を後日追加する (却下案参照)。 +- security 契約は takt builtin に依存する。takt アップグレード時に builtin の列が変われば simplicity 側の + mirror も追随が必要 (ADR-017 の pin により当面は安定)。 + +### ADR-039 との関係 + +本 ADR は prompt-contract の改善であり**ランタイム機能ではない**ため、ADR-039 の config opt-in / +kill-switch はそのままは適用されない。可逆性は「contract ファイルの revert (simplicity は free-form に +戻る)」で担保する。bounded lifetime として、dogfood 期間で reviewer findings が一貫した構造で出力され +parse 事故が減ることを確認したら `試験運用` を解除する。未達 (契約無視が頻発) なら Bash 経由 Rust +validator の追加を再検討する。 + +### 関連 ADR + +- [ADR-020](adr-020-takt-facets-sharing.md) — facet 共有 (`fix.md` の入力形式非依存原則を維持) +- [ADR-036](adr-036-bundle-z-three-layer-review.md) — Bundle Z 3 層 review (reviewer 出力の構造化) +- [ADR-047](adr-047-prepush-refute-facet.md) — refute facet (`refutation-report` の列を本 ADR で整合) +- [ADR-017](adr-017-takt-version-pinning.md) — takt バージョン固定 (builtin 契約の安定性の前提) diff --git a/docs/harness-improvement-plan.md b/docs/harness-improvement-plan.md index 0c8fc19a..f1b1fe4b 100644 --- a/docs/harness-improvement-plan.md +++ b/docs/harness-improvement-plan.md @@ -66,7 +66,7 @@ Anthropic 公式のハーネスエンジニアリング指針(決定論的基 | WP-04 | 1-A | classifier モデル格上げ(7b → 27b 級) | XS-S | WP-01 | 見送り (ADR-038 amendment: FP 検出改善なし + qwen3-coder は安全後退、mistral:7b 維持。FP-tune 再評価 → 順位 256) | | WP-05 | 1-A | Stop hook 高速化(nextest + 変更 crate 限定) | M | なし | 実装済(ADR-004 amendment: 逐次→並列で ~8s→~2s 約75%削減。nextest/変更crate は実測無効 → push pipeline 向け nextest を順位257へ) | | WP-06 | 1-B | 反証(refute)facet 追加 | S-M | なし | 実装済(ADR-047、導入は default OFF、dogfood 有効化はマージ後の別 PR) | -| WP-07 | 1-B | facet 間受け渡しの JSON 化 | M | なし | 未着手 | +| WP-07 | 1-B | facet 間受け渡しの JSON 化 | M | なし | 実装済(ADR-048: 公式調査で JSON 却下→markdown 契約標準化。simplicity-review 契約新設・reviewer 間で列統一) | | WP-08 | 1-B | incident→eval 回帰スイート | S | なし | 未着手 | | WP-09 | 1-C | PR 監視の GitHub Actions 化 Phase A(読み取り専用) | M | なし | 未着手 | | WP-10 | 1-C | 自律境界ポリシー ADR(ADR-028 の 2 段化) | S | なし | 未着手 | @@ -160,6 +160,8 @@ Anthropic 公式のハーネスエンジニアリング指針(決定論的基 ### WP-07: facet 間受け渡しの JSON 化 +> **実装済 (2026-07-06、[ADR-048](adr/adr-048-facet-findings-handoff-markdown-contract.md))**: 当初案 (findings の JSON 化) を takt 公式仕様の調査で却下。takt の idiomatic な handoff は markdown output-contract (`{report:}` 参照) で、公式スタイルガイドが JSON/プレーンテキスト契約を DON'T と明記。parse 事故の真因は「simplicity-review に output-contract が無く列が不統一」だったため、`.takt/facets/output-contracts/simplicity-review.md` を新設 (builtin security-review の finding テーブルを踏襲)、reviewer 間で列統一 (finding_id / family_tag / severity / type / location / issue / fix suggestion)、refutation-report に family_tag 追加。既存 workflow の `format:` 名にそのまま解決されるため YAML 変更不要。当初案の「Rust pre-step (cli-push-runner)」は takt が LLM step 専用 + cli-push-runner が takt workflow 全体を不透明に呼ぶため実現不能と判明。machine 検証 (Bash 経由 Rust validator) は見送り (順位化候補)。以下は当初ステップ (記録用)。 + - **目的**: reviewers → fix 間の findings 受け渡し(現状 markdown)の parse 事故・読み落とし防止。 - **ステップ**: 1. findings スキーマ定義(file / line / severity / rationale / suggested_fix)。