Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "anchor_comment の schema 正規化と preflight 正規化を一致させ、docs が要求する metadata を deterministic に enforcement できる状態にする"
change_kind: codeParent Issue
none(単独改善)
Parent Goal Ref
- Goal:
anchor-comment-handling.mdが要求するLOOP_STATE.anchor_commentの required metadata と preflight 入力境界を repo reality に一致させる - Desired Destination:
loop_state.schema.jsonとrun_refinement_preflight.pyが normalizedanchor_commentstate を共有し、schema-invalid anchor state を preflight で blocked にできる
Current Validated Scope
.claude/skills/issue-refinement-loop/schemas/loop_state.schema.jsonでanchor_commentの正本 shape をdefinitions.anchor_commentに固定し、properties.anchor_commentから$ref参照する.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.pyで GitHub issue comment API response から required metadata を正規化し、schema-invalid anchor state を blocked にする.claude/skills/issue-refinement-loop/references/anchor-comment-handling.mdを現行実装 shape と一致させる.claude/skills/issue-refinement-loop/tests/にanchor_comment.required/scope_impactnull / 複数--anchor-comment-url/anchor_comment_feedbackboundary の regression を追加する
Remaining Parent Gaps
- trusted anchor scope amendment を planner
known_contextに渡す routing 変更は#1008 CONTEXT_PROVENANCE_V1による origin/actionability 分離は#1011- preflight 直後の phase gate は
#1013 - anchor reframe comment schema / template の運用面は
#920
Background
現行の anchor-comment-handling.md は、LOOP_STATE.anchor_comment に url / id / issue_number / html_url / api_url / user_login / author_association / snapshot / timestamps / classification / scope_impact / requires_fact_check を保持することを要求している。
一方で live repo の loop_state.schema.json は anchor_comment を inline properties だけで持ち、definitions.anchor_comment も required もない。run_refinement_preflight.py も anchor URL の構造検証と issue_url 一致確認までは行うが、docs が要求する full metadata を schema-valid な normalized state として組み立てていない。
この不一致のため、schema enforcement を期待する Issue なのに AC / VC が現行 repo reality と食い違い、実装者が classification / fact_check_status のような別名 field を追加したり、scope_impact の null を文字列として実装したり、raw snapshot と normalized feedback の境界を曖昧にしたりする余地が残っている。
Outcome
loop_state.schema.json が definitions.anchor_comment を正本として docs required fields を schema enforcement し、run_refinement_preflight.py が GitHub issue comment API response から同 shape の normalized anchor_comment state を生成する。required field 欠落・enum 外値・複数 anchor URL・raw snapshot 境界違反は preflight / pytest で fail-closed に検出でき、routing 変更は #1008 / #1011 / #1013 に波及しない。
In Scope
definitions.anchor_commentを追加し、properties.anchor_commentは$refで参照するanchor_comment.requiredをanchor-comment-handling.mdの Required LOOP_STATE fields と一致させるauthor_associationをOWNER | MEMBER | COLLABORATOR | CONTRIBUTOR | NONEの enum として定義するscope_impactをtype: [\"string\", \"null\"]かつenum: [\"none\", \"amend\", \"replace\", \"ambiguous\", null]で定義し、文字列\"null\"は許容しないclassification/fact_check_statusは追加せず、既存のpreliminary_classification/final_classification/requires_fact_checkを使うrun_refinement_preflight.pyでid/html_url/api_url/user.login/author_association/created_at/updated_at/issue_url/bodyを取得し、schema-valid な normalizedanchor_commentstate を生成する- raw comment body は artifact にのみ保存し、planner input / Step 4 writer request には normalized
anchor_comment_feedbackのみを渡す - 複数
--anchor-comment-urlはこの Issue では unsupported とし、ANCHOR_COMMENT_MULTIPLE_UNSUPPORTED相当の blocked routing を追加する .claude/skills/issue-refinement-loop/tests/に schema-invalid fixture、複数 anchor URL fixture、artifact boundary fixture を追加する
Out of Scope
decide_next_loop_action.pyの routing ロジック変更- trusted anchor scope amendment を planner
known_contextに渡す処理 CONTEXT_PROVENANCE_V1導入- phase gate /
hard_stop_eligiblerouting anchor-comment-handling.mdへの新規フロー追加(既存 required flow との整合のみ)loop_state.schema.jsonのanchor_comment以外のフィールド変更
Acceptance Criteria
- AC1:
loop_state.schema.jsonにdefinitions.anchor_commentが追加され、properties.anchor_commentがその$refを参照している - AC2:
definitions.anchor_comment.requiredがanchor-comment-handling.mdの Required LOOP_STATE fields と一致し、author_association/comment_created_at/comment_updated_at/fetched_at/scope_impact/requires_fact_checkを必須化している - AC3:
scope_impactは JSONnullを許容し、文字列\"null\"を許容しない - AC4:
classification/fact_check_statusは追加されず、classification 系はpreliminary_classification/final_classification/classification_reason/requires_fact_checkに統一されている - AC5:
run_refinement_preflight.pyが GitHub issue comment API response から normalizedanchor_commentstate を生成し、required field 欠落・enum 外値・issue_url不一致を preflight 段階で blocked にする - AC6: 複数
--anchor-comment-urlはこの Issue のスコープでは blocked になり、単数 anchor 契約を fail-closed で守る - AC7: raw comment body は
raw_issue_snapshot.json/ raw anchor artifact にのみ保存され、planner_input.jsonと Step 4 writer request には normalizedanchor_comment_feedbackのみが含まれることを pytest で検証できる
Verification Commands
# AC1
# baseline-expect: fail
$ uv run pytest .claude/skills/issue-refinement-loop/tests -q -x -k "anchor_comment_ref or anchor_comment_schema_shape"
# AC2
# baseline-expect: fail
$ rg -n '"comment_created_at"' .claude/skills/issue-refinement-loop/schemas/loop_state.schema.json
# AC3
# baseline-expect: fail
$ rg -n '"enum": \["none", "amend", "replace", "ambiguous", null\]' .claude/skills/issue-refinement-loop/schemas/loop_state.schema.json
# AC4
# baseline-expect: fail
$ test -f .claude/skills/issue-refinement-loop/tests/fixtures/anchor_comment/classification_alias_rejected.json
# AC5
# baseline-expect: fail
$ rg -n 'author_association' .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py
# AC6
# baseline-expect: fail
$ rg -n 'ANCHOR_COMMENT_MULTIPLE_UNSUPPORTED' .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py
# AC7
# baseline-expect: fail
$ test -f .claude/skills/issue-refinement-loop/tests/fixtures/anchor_comment_feedback/planner_input_boundary.jsonAllowed Paths
.claude/skills/issue-refinement-loop/schemas/loop_state.schema.json.claude/skills/issue-refinement-loop/references/anchor-comment-handling.md.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py.claude/skills/issue-refinement-loop/tests/**
Runtime Verification Applicability
decision: not_applicable
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
- JSON Schema(draft-07 / jsonschema validation)
- Python / pytest
- GitHub issue comment API response の正規化
Scope Delta(任意)
N/A
Activity
squne121 commentedon Jun 20, 2026
結論
#1010 は方向性は正しいですが、このまま実装 Issue として渡すと失敗する可能性が高いです。理由は、docs と schema の不一致を直す Issue なのに、Issue 自体の AC / VC が現行 schema・既存 preflight 実装・関連 Issue の責務分割と矛盾しているためです。
#1010 自体のコメントは空で、Closes #1010 検索でも明示的な関連作業は #1010 自身しか確認できませんでした。したがって、関連 Issue と現行ファイルを主証跡にしています。
敵対的レビュー
#1010 の Scope / Outcome は、loop_state.schema.json の anchor_comment を docs の Required flow と一致させ、preflight で schema-invalid anchor state を block することです。 しかし現行 schema の anchor_comment は properties 直下に inline 定義されており、definitions.anchor_comment は存在しません。現在あるのは url、preliminary_classification、final_classification、classification_reason、verified_claims、unresolved_claims、scope_impact、requires_fact_check 程度です。
問題は、#1010 の検証コマンドが s['definitions']['anchor_comment'] を参照している点です。現行構造のまま実装すると VC は KeyError で落ちます。逆に VC に合わせて definitions.anchor_comment を追加するなら、properties.anchor_comment を $ref へ置き換える設計変更を AC に明記すべきです。
修正案:
definitions.anchor_comment を正本にし、properties.anchor_comment は $ref 参照にする。もしくは VC を s['properties']['anchor_comment'] 参照に直す。個人的には再利用性とテスト容易性のため、definitions.anchor_comment 化を推奨します。
現行 schema の top-level required に anchor_comment は含まれていません。 さらに anchor_comment 内にも required がありません。JSON Schema draft-07 では、required は配列で指定された property の存在を要求し、省略時は空配列と同等です。つまり、properties に field を追加するだけでは必須化されません。
#1010 は「必須フィールドを追加」と書いていますが、実装者が properties だけ足して終えるリスクが高いです。これはレビューで必ず落とすべきです。
修正案:
anchor_comment が存在する場合は以下を required に入れるべきです。
[
"url",
"id",
"issue_number",
"html_url",
"api_url",
"user_login",
"author_association",
"snapshot",
"captured_at",
"fetched_at",
"comment_created_at",
"comment_updated_at",
"preliminary_classification",
"final_classification",
"classification_reason",
"verified_claims",
"unresolved_claims",
"scope_impact",
"requires_fact_check"
]
これは anchor-comment-handling.md の Required LOOP_STATE fields と一致します。
#1010 の AC3 / VC は scope_impact enum を none | amend | replace | ambiguous | null としつつ、検証コマンドでは文字列 'null' を期待しています。これは危険です。
JSON Schema の type における "null" は型名ですが、enum の要素として null を許可する場合は JSON の null 値そのものを入れます。draft-07 でも enum の要素は任意の値を取れ、null も含められると定義されています。
NG:
"enum": ["none", "amend", "replace", "ambiguous", "null"]
推奨:
"type": ["string", "null"],
"enum": ["none", "amend", "replace", "ambiguous", null]
VC も Python 側では None を期待する形に直すべきです。
#1010 の AC1 は classification / fact_check_status を追加対象にしています。しかし現行 docs は preliminary_classification、final_classification、requires_fact_check、verified_claims、unresolved_claims を要求しています。 現行 schema も preliminary_classification / final_classification / requires_fact_check を持っています。
ここで classification や fact_check_status を新規追加すると、同じ意味の状態が二重化します。additionalProperties: false の schema では、曖昧な別名追加は将来の migration と test fixture を壊します。
修正案:
#1010 の AC1 から classification / fact_check_status を削除し、既存 docs に合わせて以下に統一する。
preliminary_classification
final_classification
requires_fact_check
verified_claims
unresolved_claims
GitHub REST の issue comment API は id、API url、html_url、body、user.login、created_at、updated_at、issue_url、author_association を返します。つまり #1010 が必要とするデータは API から取れます。
しかし現行 run_refinement_preflight.py の anchor validation は、URL 構造・repo/issue 一致・comment existence・issue_url 一致を見るだけです。 実際の実装でも issue_url を検証した後、author_association、created_at、updated_at、body、html_url、user.login を正規化して LOOP_STATE.anchor_comment に落としていません。
そのため、schema だけ増やしても #1008 の問題、つまり trusted anchor scope amendment を known_context.anchor_reframe: true として planner に渡せない問題は解消しません。#1008 はまさに、author_association / scope_impact が実装されず、scope_signal_guard が trusted human request と AI scope creep を区別できないことを問題にしています。
修正案:
#1010 の実装には最低限 _build_anchor_comment_state() を追加する必要があります。
処理順は以下。
URL parse
gh api repos/{repo}/issues/comments/{comment_id} で comment fetch
issue_url が対象 issue と一致することを検証
API response から anchor_comment 正規化
loop_state.schema.json の definitions.anchor_comment で validate
invalid なら ANCHOR_COMMENT_SCHEMA_INVALID で blocked
raw body は artifact のみに保存し、planner / writer には normalized feedback のみ渡す
現行 CLI は --anchor-comment-url を複数受け取れます。_validate_anchor_comments_batch() も複数 URL を stable sort / dedupe します。 しかし schema/docs は LOOP_STATE.anchor_comment 単数です。
このまま実装すると、複数 anchor が指定されたときに以下が未定義です。
最初の 1 件だけ採用するのか
複数を block するのか
anchor_comments[] に schema を変えるのか
trusted と untrusted が混ざった場合の判定はどうするのか
修正案:
#1010 は単数契約に閉じるべきです。active_anchor_urls が 2 件以上なら ANCHOR_COMMENT_MULTIPLE_UNSUPPORTED で blocked にする。複数 anchor を正式サポートするなら別 Issue です。
#920 は、人間が anchor comment で scope 拡張を許可できる schema / template を追加する Issue です。背景には、OWNER が anchor comment を書いても excluded_by_anchor_reframe=false になり、loop が停止した問題があります。
#1008 は、その trusted anchor comment を known_context.anchor_reframe: true として planner に渡す Issue です。
#1011 は、anchor comment 由来の REQUEST_CHANGES を origin: trusted_anchor_comment / actionability: requirement、AI が自発的に追加した scope を origin: agent_inferred / actionability: hypothesis として分離する Issue です。
#1013 は、scope_signal_guard.triggered を phase-sensitive に扱い、preflight 直後の誤った human_escalation を防ぐための phase gate Issue です。
#1010 はこの中で schema / preflight 正規化の下位基盤 に限定すべきです。routing ロジックや phase gate まで触ると #1008 / #1011 / #1013 と衝突します。
修正案:
#1010 の Outcome を次のように狭めるべきです。
#1010 の AC6 は「Step 4 writer へは正規化済み feedback のみを渡す」ですが、VC は normalized_feedback / anchor_comment_feedback / raw_snapshot という文字列がソースに存在するかを見るだけです。これは実質的に無検証です。
現行 preflight は raw issue snapshot、planner input、preflight result を artifact として書き出します。 また compact stdout は raw issue body / raw comments を出さない設計です。 この境界は良いので、AC6 は grep ではなく artifact / planner input の負例テストにするべきです。
修正案:
pytest で以下を検証する。
raw_issue_snapshot.json には raw comment body がある
planner_input.json には raw snapshot がない
planner_input.json には anchor_comment_feedback だけがある
Step 4 writer request fixture に anchor_comment.snapshot / raw body が混入しない
実装を高品質化する具体案
Schema 形状
loop_state.schema.json は draft-07 なので、以下の方向が堅いです。
{
"definitions": {
"anchor_comment": {
"type": "object",
"additionalProperties": false,
"required": [
"url",
"id",
"issue_number",
"html_url",
"api_url",
"user_login",
"author_association",
"snapshot",
"captured_at",
"fetched_at",
"comment_created_at",
"comment_updated_at",
"preliminary_classification",
"final_classification",
"classification_reason",
"verified_claims",
"unresolved_claims",
"scope_impact",
"requires_fact_check"
],
"properties": {
"url": { "type": "string", "minLength": 1 },
"id": { "type": ["integer", "string"] },
"issue_number": { "type": "integer", "minimum": 1 },
"html_url": { "type": "string", "minLength": 1 },
"api_url": { "type": "string", "minLength": 1 },
"user_login": { "type": "string", "minLength": 1 },
"author_association": {
"type": "string",
"enum": ["OWNER", "MEMBER", "COLLABORATOR", "CONTRIBUTOR", "NONE"]
},
"snapshot": { "type": "string" },
"captured_at": { "type": "string", "format": "date-time" },
"fetched_at": { "type": "string", "format": "date-time" },
"comment_created_at": { "type": "string", "format": "date-time" },
"comment_updated_at": { "type": "string", "format": "date-time" },
"preliminary_classification": {
"type": "string",
"enum": [
"superseded_by_decision",
"reframe_in_place",
"feedback_update_required",
"human_escalation"
]
},
"final_classification": {
"type": ["string", "null"],
"enum": [
"superseded_by_decision",
"reframe_in_place",
"feedback_update_required",
"human_escalation",
null
]
},
"classification_reason": { "type": ["string", "null"] },
"verified_claims": { "type": "array", "items": { "type": "string" } },
"unresolved_claims": { "type": "array", "items": { "type": "string" } },
"scope_impact": {
"type": ["string", "null"],
"enum": ["none", "amend", "replace", "ambiguous", null]
},
"requires_fact_check": { "type": "boolean" }
}
}
}
}
注意点は、format: date-time は draft-07 では実装依存です。JSON Schema 仕様上、format を validation assertion として実装するかは実装依存なので、厳密に日付検証したいなら Python 側で datetime.fromisoformat 相当の検証も追加すべきです。
preflight artifact 境界
配布物としては、次の 4 層に分けるのが安全です。
raw_issue_snapshot.json: raw issue / comments
anchor_comment_snapshot_v1.json: GitHub comment API response の raw subset
planner_input.json: raw snapshot を含めず、normalized anchor_comment_feedback / known_context のみ
refinement_preflight_result_v1.json: status / blockers / artifact paths のみ
GitHub comment API は raw markdown body を body として返せるため、raw body は artifact に閉じ込め、planner / writer には要約済み feedback だけを渡す設計にできます。
#1010 に入れるべき追加 AC
この Issue は、最低限以下を追加しないとレビューで落とすべきです。
definitions.anchor_commentを追加し、properties.anchor_commentは$refで参照する。VC は実 schema 形状と一致する。anchor_comment.requiredに docs Required LOOP_STATE fields の全 field が含まれる。scope_impactの enum は JSON null を許容し、文字列"null"を許容しない。classification/fact_check_statusという別名 field は追加せず、preliminary_classification/final_classification/requires_fact_checkに統一する。--anchor-comment-urlが指定された場合の挙動を定義する。この Issue では単数のみ許可し、複数は blocked にする。author_association欠落、enum 外値、comment_updated_at欠落、scope_impact: "null"を schema-invalid として block する。anchor_comment_feedbackのみが渡る。実装プロンプトに落とすなら
以下の方針で指示するのが安全です。
Issue #1010 はそのまま実装せず、まず Issue body の AC/VC を現行 schema と docs に整合させる修正 PR を作ること。
必須修正:
停止条件:
現時点の判定は 修正条件付き GO です。schema の field 追加だけで閉じる実装なら reject でよいです。
squne121 commentedon Jun 20, 2026
issue-refinement-loop を指定 comment 起点で実施し、Issue 本文を live rewrite しました。
今回の更新点:
anchor_commentの責務をschema enforcement + preflight 正規化 + artifact boundaryに狭め、routing 変更は#1008/#1011/#1013/#920へ明示的に分離definitions.anchor_comment正本化、required必須化、scope_impactの JSONnull、classification 語彙の既存 docs への統一を AC/Outcome/In Scope に反映Verification Commandsを$ ...形式へ修正し、## Runtime Verification Applicabilityをdecision: not_applicableで追加--anchor-comment-urlはこの Issue では unsupported / blocked として fail-closed 方針を明記planner_input/ Step 4 writer には normalizedanchor_comment_feedbackのみを渡す境界を AC7 に格上げローカル検証:
check_issue_contract.py --file /tmp/issue1010_rewrite.md→verdict: approvecontract_readiness_check.py --mode preflight-static --body-file /tmp/issue1010_rewrite.md→status: gosqune121 commentedon Jun 20, 2026
Contract Review Result
fix(#1010): anchor_comment schema を docs required flow に一致させる (#1043)