Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: none
goal_ref: "issue-refinement-loop の scope guard が人間レビュー由来の明示的な契約更新要求を scope_delta_authority で分類し、不要な human_escalation を避けつつ実装続行と契約更新を分離できるようにする。加えて #1008 / #1011 を supersede し、trusted anchor 判定に基づく provenance 分離と scope amendment routing を単一の拡張ポイントへ統合する"
change_kind: workflowParent Issue
なし(単独改善。ただし #1008 / #1011 を supersede する統合 Issue)
Parent Goal Ref
- Goal: issue-refinement-loop の scope guard が「誰が・どの権限で・何を変更しようとしているか」を区別できるようにし、人間レビュー由来の明示的な契約更新要求を過剰に human_escalation しないようにする
- Desired Destination: N/A(単独改善 Issue のため)
Current Validated Scope
- .claude/skills/issue-refinement-loop/scripts/scope_signal_delta.py に scope_delta_authority 分類ロジックを追加する
- .claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py が scope_delta_authority を scope_signal_guard_decision_v2 の additive フィールドとして出力できるようにする(既存 schemas/refinement_loop_plan_v1.json のトップレベル契約は変更しない)
- .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py に anchor comment / issue comment metadata から scope_delta_authority_evidence_v1 を生成するロジックを追加する
- .claude/skills/issue-refinement-loop/scripts/decide_next_loop_action.py に scope_signal_guard_decision_v2.route == contract_update_required を消費する非破壊的 next_action 分岐を追加する(既存 termination_reason enum は変更しない)
- .claude/skills/issue-refinement-loop/references/scope-signal-guard.md に scope_delta_authority 契約、scope_delta_authority_evidence_v1、contract_patch_plan_v1 を明文化する
- .claude/skills/issue-refinement-loop/schemas/ に scope_delta_authority / scope_delta_authority_evidence_v1 / contract_patch_plan_v1 の JSON Schema を追加する
- .claude/skills/issue-refinement-loop/tests/ に AC 対応の回帰テストを追加する
Remaining Parent Gaps
なし(単独改善 Issue のため)
Background
現行 issue-refinement-loop の scope guard(.claude/skills/issue-refinement-loop/references/scope-signal-guard.md)は、Issue 本文の In Scope / Acceptance Criteria / Allowed Paths / Stop Conditions を超える変更要求を検出すると scope_signal_guard_triggered / reason_code:new_in_scope_area で無条件に human_escalation する。
この安全設計自体は妥当だが、人間レビューコメントが明示的に Issue 契約の更新を要求している場合まで、AI が独自に推定した未承認スコープ拡張と同一の扱いで停止してしまう。
実例(Issue #1270): 人間レビューコメントが provider_auto_policy_v1、retry budget schema、AGY failure classifier、idempotency guard、#1274 前提条件、Revised Acceptance Criteria を具体的に提示していたにもかかわらず、Refinement Loop は new_in_scope_area として iteration 0 で human_escalation した(コメント: https://github.com/squne121/loop-protocol/issues/1270#issuecomment-4881521790)。安全側ではあるが運用上は過剰停止であり、人間からの明示的な指摘は「未承認のスコープ拡張」ではなく「契約更新の入力」として扱うべきである。
Supersede 宣言(OWNER 判断、2026-07-04)
本 Issue は以下 2 件を supersede する。本 Issue マージ後、両 Issue は「Closed as superseded by #1323」として close する。
- 実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008(run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする): 実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008 が目的とした「trusted anchor comment(author_association: OWNER/MEMBER/COLLABORATOR)による REQUEST_CHANGES を AI scope creep と分離し、known_context 経由で planner に渡す」という Outcome は、本 Issue の
scope_delta_authority_evidence_v1(後述)とrun_refinement_preflight.pyへの provenance 検証追加によって包含される。実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008 の AC1〜AC5 が要求する trusted anchor 判定・AI 推定との区別・untrusted author fail-closed・raw snapshot 非流入・fix(agent-ops): Issue VC grammar を vc_contract_syntax に単一化し、C4/C5 と LP010/LP011 の矛盾を解消する #993 相当 fixture は、本 Issue の AC(後述)に統合する。 - 実装: CONTEXT_PROVENANCE_V1 を導入し human-requested / agent-inferred / repo-evidence を分離する #1011(CONTEXT_PROVENANCE_V1 を導入し human-requested / agent-inferred / repo-evidence を分離する): 実装: CONTEXT_PROVENANCE_V1 を導入し human-requested / agent-inferred / repo-evidence を分離する #1011 が目的とした「origin: trusted_anchor_comment / agent_inferred の provenance 分離」は、本 Issue の
scope_delta_authority.provenance(source_kind/source_ref/author_association)フィールドに統合する。実装: CONTEXT_PROVENANCE_V1 を導入し human-requested / agent-inferred / repo-evidence を分離する #1011 の AC1〜AC5(artifact への provenance 格納、trusted/agent_inferred 分類、scope_signal_guard が trusted 由来をスルーする、raw body 非出力)は、本 Issue の AC に統合する。
ただし、#1090(PR #1294, マージ済み)が既に実装した ANCHOR_SCOPE_REFRAME_V1(構造化テンプレートによる trusted anchor scope 拡張承認)と SCOPE_SIGNAL_GUARD_DECISION_V2(raw_signal / scope_context / scope_delta_approval / security_sensitive / route の分解 shape、additive-only 拡張ポイント)は再実装しない。本 Issue はこれらの上に築く Phase 2 的拡張であり、scope_signal_guard_decision_v2 の下に scope_delta_authority を additive フィールドとして追加することで、#1008 / #1011 が残していた「自由記述の人間レビュー指摘の扱い」というギャップを埋める。
Problem
現在の scope guard は scope delta の発生源と権限レベルを区別していない。以下が同一扱いになっている。
- AI が独自判断で新しい AC / path / dependency を提案した
- 人間レビューコメントが明示的に AC / path / dependency の追加を要求した
- 親 Issue / 関連 Issue の既存コメントが既に revised AC を提示していた
- 実装中に初めて別スコープが必要だと判明した
この結果、人間がすでに承認・要求している契約更新であっても、Refinement Loop が実行せずに停止する。
加えて、この問題を解決しようとする既存 OPEN Issue(#1008 の trusted anchor 判定、#1011 の provenance 分離)が並行して存在し、#1090 で既に merged された SCOPE_SIGNAL_GUARD_DECISION_V2 / ANCHOR_SCOPE_REFRAME_V1 とは異なる別の権限モデル(ANCHOR_SCOPE_AMENDMENT_V1、CONTEXT_PROVENANCE_V1)を導入しようとしていたため、正本が分散し agent が誤読するリスクがあった。本 Issue はこれを一本化する。
Goal
Refinement Loop / scope guard に、scope delta の発生源と処理方針を分類する scope_delta_authority を、既存 scope_signal_guard_decision_v2 の additive 拡張として導入する。人間レビュー由来の明示的な契約変更要求は、危険・矛盾・権限昇格・別 Issue 分割の懸念がない限り、Issue 本文への契約更新案として処理できるようにする(ただし契約更新と実装続行は分離し、契約更新のみでは実装フェーズへ進まない)。同時に #1008 / #1011 が残した trusted anchor 判定と provenance 分離のギャップを本 Issue の中で完結させる。
Non-Goal
- Issue 契約を更新せずに拡張スコープの実装へ直接進むこと
- AI が独自提案した新スコープを無条件で採用すること
- 危険な権限昇格、外部サービス利用、Allowed Paths 大幅拡張を自動承認すること
- 人間コメントが曖昧または矛盾している場合の自動判断
- 既存の scope guard 自体を撤廃すること
REFINEMENT_LOOP_PLAN_V1トップレベル schema やLOOP_STATE_V1.termination_reasonenum の破壊的変更(additionalProperties:falseを緩和したり新しい top-level V2 schema を導入したりしない)- Issue 本文への実際の書き込み(direct_github_write)を本 Issue のスコープに含めること(
contract_patch_plan_v1は生成のみ)
Outcome
.claude/skills/issue-refinement-loop/scripts/scope_signal_delta.py、plan_refinement_loop.py、run_refinement_preflight.py、decide_next_loop_action.py に scope_delta_authority / scope_delta_authority_evidence_v1 / contract_patch_plan_v1 のロジックが追加され、references/scope-signal-guard.md に判定契約が明文化され、schemas/ に対応する JSON Schema が追加され、AC1からAC20(#1008/#1011 統合分含む)に対応する pytest 回帰テストが全て PASS している状態。#1008 / #1011 は本 Issue のマージ後に superseded として close されている状態。
Proposed Behavior
1. scope delta の authority を分解された shape で分類する
単一 enum ではなく、#1090 の scope_signal_guard_decision_v2 と同じ分解パターンを踏襲する。
scope_delta_authority:
schema_version: SCOPE_DELTA_AUTHORITY_V1
authority_category: ai_inferred | human_review_directive | existing_parent_contract | related_issue_dependency
provenance:
source_kind: issue_comment | pr_review | parent_issue | related_issue | generated_by_agent
source_ref: "<url or artifact ref>"
body_sha256: "<sha256|null>"
author_association: OWNER | MEMBER | COLLABORATOR | CONTRIBUTOR | NONE | null
directive:
confidence: explicit | ambiguous | conflicting | inferred
extracted_markers: []
boundary_flags:
expands_allowed_paths: false
changes_permission_boundary: false
changes_external_service_boundary: false
destructive_or_non_idempotent_operation: false
requires_issue_split: false
route:
action: contract_update_required | human_escalation | not_triggered
reason_code: explicit_human_contract_directive | ambiguous_human_directive | conflicting_human_directives | safety_or_permission_boundary
implementation_allowed: false
next_step: rerun_refinement_after_contract_updateこのフィールドは scope_signal_guard_decision_v2 の下に additive に格納する(新しい top-level schema V2 は導入しない)。known_context.scope_signal_delta_input が与えられた場合にのみ生成される opt-in ガードは #1090 の既存方針を踏襲する。
2. run_refinement_preflight.py が normalized evidence を生成する(#1008 統合)
raw anchor comment body / raw issue comment body を planner に直接渡さず、run_refinement_preflight.py が GitHub comment metadata(author、author_association、comment_url、issue_url、created_at)を構造検証した上で以下の evidence を生成する。
scope_delta_authority_evidence_v1:
source_kind: issue_comment | pull_request_review | parent_issue | related_issue | agent_inferred
source_ref: "<stable url or artifact ref>"
source_issue_number: <int>
comment_id: <int|null>
comment_url: "<url|null>"
issue_url: "<url|null>"
body_sha256: "<sha256>"
author_login: "<login>"
author_type: User | Bot | Organization | unknown
author_association: OWNER | MEMBER | COLLABORATOR | CONTRIBUTOR | NONE | null
captured_at: "<ISO-8601>"
directive_markers: []
extracted_directives: []
ambiguity_flags: []
boundary_flags: []author_association が OWNER / MEMBER / COLLABORATOR 以外(CONTRIBUTOR / NONE / bot user / 欠落)の場合は fail-closed とし、authority_category: ai_inferred 相当(human_review_directive への昇格なし)として扱う。
3. 人間レビュー由来なら Issue 契約更新へ進む
以下をすべて満たす場合、human_escalation せず contract_update_required として処理する。
scope_delta_authority_evidence_v1.author_associationがOWNER/MEMBER/COLLABORATOR- コメントが明示的な修正要求(Revised Acceptance Criteria / 前提条件 / Stop Condition 等)を含む(
directive.confidence: explicit) - 変更が対象 Issue の goal_ref と矛盾しない
- 実装ではなく Issue 契約の更新に留まる
- 外部サービス利用、権限昇格、破壊的変更を要求していない(
boundary_flagsが全て false)
4. contract_update_required の消費点(Blocker 3 の解決)
contract_update_required は scope_signal_guard_decision_v2.route の新しい enum 値としてのみ追加する。REFINEMENT_LOOP_PLAN_V1 トップレベル schema と LOOP_STATE_V1.termination_reason(approved / human_escalation / superseded_by_decision / null)の enum は変更しない。
decide_next_loop_action.py はこの route 値を見て、既存の human_escalation 分岐とは別に NEXT_ACTION: proceed_with_contract_update を返す(termination_reason は設定せず、loop を継続させたまま Step 4 相当の契約更新へ進める非破壊的分岐)。
5. 契約更新と実装続行を分離する
human_review_directive と分類された場合も、Issue 本文(In Scope / Out of Scope / Acceptance Criteria / Stop Conditions / Verification Commands)を更新し、Refinement Loop を再実行するまで実装フェーズへ進まない(implementation_allowed: false を維持)。
6. contract_patch_plan_v1(Blocker 7 の解決)
Issue 本文への実際の書き込みは行わず、patch plan の生成のみを本 Issue のスコープとする。
contract_patch_plan_v1:
target_issue_number: <int>
base_issue_body_sha256: "<sha256>"
source_evidence:
- source_ref: "<comment url>"
source_body_sha256: "<sha256>"
author_association: OWNER
start_line: <int>
end_line: <int>
operations:
- section: Acceptance Criteria
op: append
text: "- [ ] ACx: ..."
rationale: "Revised AC from trusted review comment"
source_evidence_index: 0
forbidden:
- direct_github_write
- implementation_phase_transition
required_next_step: rerun_refinement_after_contract_updateforbidden に列挙された操作(Issue 本文への直接書き込み、実装フェーズへの遷移)は本 Issue のコードパスから実行できない設計にする。実際の適用は既存の issue-author / edit-issue skill 経由でのみ行う。
7. escalation を維持する条件(reason_code を具体化する)
以下に該当する場合は従来どおり human_escalation するが、reason_code を new_in_scope_area のような汎用値ではなく以下のいずれかに具体化する。
- ambiguous_human_directive(指摘が曖昧)
- conflicting_human_directives(reviewer 間で要求が衝突)
- requires_issue_split(Issue 分割が必要な規模)
- expands_allowed_paths(Allowed Paths を大幅に拡張する)
- changes_permission_boundary(権限昇格を要求する)
- changes_external_service_boundary(外部サービス利用を要求する)
- destructive_or_non_idempotent_operation(破壊的操作を要求する)
In Scope
- .claude/skills/issue-refinement-loop/scripts/scope_signal_delta.py の判定ロジックへ scope_delta_authority の 4 分類(ai_inferred / human_review_directive / existing_parent_contract / related_issue_dependency)と
provenance/directive/boundary_flags/routeの分解 shape を追加する - .claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py が scope_delta_authority を scope_signal_guard_decision_v2 の additive フィールドとして出力できるようにする(既存 schemas/refinement_loop_plan_v1.json は変更しない)
- .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py に scope_delta_authority_evidence_v1 生成ロジックを追加する(GitHub comment metadata の構造検証、author_association fail-closed 判定を含む)
- .claude/skills/issue-refinement-loop/scripts/decide_next_loop_action.py に
scope_signal_guard_decision_v2.route == contract_update_requiredを消費しNEXT_ACTION: proceed_with_contract_updateを返す分岐を追加する - human_review_directive と分類された場合に contract_update_required / implementation_allowed:false / next_step:rerun_refinement_after_contract_update を出力する分岐を追加する
- contract_patch_plan_v1 の生成ロジックを追加する(Issue 本文への direct_github_write は実行しない)
- termination reason / cause / blocker の reason_code をより具体的な値(ambiguous_human_directive 等)に改善する
- .claude/skills/issue-refinement-loop/schemas/ に scope_delta_authority / scope_delta_authority_evidence_v1 / contract_patch_plan_v1 の JSON Schema を追加する
- .claude/skills/issue-refinement-loop/references/scope-signal-guard.md / anchor-comment-handling.md に本 Issue の契約を明文化する
- .claude/skills/issue-refinement-loop/tests/ に AC 対応の回帰テストを追加する(実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008 / 実装: CONTEXT_PROVENANCE_V1 を導入し human-requested / agent-inferred / repo-evidence を分離する #1011 の AC 相当を含む)
- 本 Issue マージ後、実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008 / 実装: CONTEXT_PROVENANCE_V1 を導入し human-requested / agent-inferred / repo-evidence を分離する #1011 を「Closed as superseded by 実装: Refinement Loop の scope guard を人間レビュー由来の契約更新として自動反映できるようにする #1323」として close する
Out of Scope
- scope guard の撤廃
- 人間コメントを無条件で実装承認とみなすこと
- 実装フェーズの Allowed Paths 自動拡張
- GitHub への destructive write operation の自動実行(Issue 本文への direct_github_write を含む)
- reviewer 権限モデルの大規模実装
- 複数 Issue への自動分割・自動起票(Issue 案生成は可、実起票は human decision 経由)
REFINEMENT_LOOP_PLAN_V1トップレベル schema の破壊的変更・新規 top-level V2 schema の導入LOOP_STATE_V1.termination_reasonenum への値追加
Acceptance Criteria
- AC1: scope delta 検出時に scope_delta_authority.authority_category が ai_inferred / human_review_directive / existing_parent_contract / related_issue_dependency のいずれかに分類される
- AC2: 人間レビューコメントが明示的な Revised Acceptance Criteria または修正要求を含む場合、new_in_scope_area だけで即時 human_escalation せず、contract_update_required として処理される
- AC3: human_review_directive の場合、Issue 本文の In Scope / Out of Scope / Acceptance Criteria / Stop Conditions / Verification Commands への反映案(contract_patch_plan_v1)が生成される
- AC4: human_review_directive であっても、Issue 本文更新前に実装フェーズへ進まない(implementation_allowed:false が出力される)
- AC5: AI が独自に推定した scope delta は従来どおり human_escalation される(regression)
- AC6: 人間コメントが曖昧・矛盾・権限昇格・外部サービス利用・Allowed Paths 大幅拡張・destructive operation を含む場合は human_escalation される(regression)
- AC7: new_in_scope_area のような汎用 reason_code だけでなく、ambiguous_human_directive 等の具体的な reason_code が出力される
- AC8: Issue 実装: クォータ管理と provider fallback policy を明文化・実装する #1270 相当のケース(人間レビューコメントが Revised AC を明示している)で、human_escalation ではなく contract_update_required への分岐を検証する回帰テストが追加されている
- AC9: human_review_directive による契約更新後の次アクションとして next_step:rerun_refinement_after_contract_update が出力される
- AC10: 既存の scope_signal_guard 回帰テスト(scope_signal_guard_termination)が regression しない
- AC11: trusted anchor comment(author_association: OWNER/MEMBER/COLLABORATOR)が REQUEST_CHANGES で AC / Allowed Paths / VC 追加を明示している fixture では authority_category: human_review_directive に分類される(実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008 AC1 相当)
- AC12: 同じ Allowed Paths 拡張でも、anchor comment 由来ではなく AI が自発的に作った変更では authority_category: ai_inferred のまま human_escalation する(実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008 AC2 相当、regression)
- AC13: untrusted author(CONTRIBUTOR / NONE / bot user / author_association 欠落)は fail-closed で human_escalation する(実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008 AC3 / Blocker 4 追加テスト相当)
- AC14: issue-author へ raw comment body を直接渡さず、正規化済み scope_delta_authority_evidence_v1 のみを渡す(実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008 AC4 / 実装: CONTEXT_PROVENANCE_V1 を導入し human-requested / agent-inferred / repo-evidence を分離する #1011 AC5 相当)
- AC15: scope_delta_authority.provenance に origin 相当の分類(source_kind: issue_comment 等、author_association)が含まれ、trusted_anchor_comment 由来と agent_inferred 由来が区別される(実装: CONTEXT_PROVENANCE_V1 を導入し human-requested / agent-inferred / repo-evidence を分離する #1011 AC1/AC2/AC3 相当)
- AC16: PR review comment URL と issue comment URL を混同せず、issue comment URL と issue_url が対象 Issue と不一致な場合は invalid として fail-closed になる
- AC17: 複数 reviewer の要求が衝突する場合は conflicting_human_directives に分類される
- AC18: changes_permission_boundary / changes_external_service_boundary / destructive_or_non_idempotent_operation のいずれかが true の場合、trusted anchor による承認があっても contract_update_required に進まず human_escalation する
- AC19: 実装: クォータ管理と provider fallback policy を明文化・実装する #1270 の実コメント fixture から contract_patch_plan_v1 が生成され、forbidden に direct_github_write と implementation_phase_transition が含まれる
- AC20: decide_next_loop_action.py が scope_signal_guard_decision_v2.route == contract_update_required を受け取ると NEXT_ACTION: proceed_with_contract_update を返し、termination_reason enum には新しい値を追加しないことを end-to-end で検証する(回帰テストは新規ファイル test_decide_next_loop_action_contract_update.py に追加する)
Verification Commands
# AC1
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_scope_delta_authority_classifies_into_four_categories"# AC2
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_human_review_directive_yields_contract_update_required"# AC3
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_human_review_directive_generates_contract_patch_plan"# AC4
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_contract_update_required_sets_implementation_allowed_false"# AC5
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_ai_inferred_scope_delta_still_escalates"# AC6
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_ambiguous_conflicting_or_permission_boundary_still_escalates"# AC7
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_reason_code_is_specific_not_generic_new_in_scope_area"# AC8
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_issue_1270_human_review_decision_fixture_yields_contract_update_required"# AC9
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_contract_update_required_next_step_is_rerun_refinement"# AC10
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_signal_guard_termination.py# AC11
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_trusted_anchor_request_changes_classified_as_human_review_directive"# AC12
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_agent_inferred_allowed_path_expansion_still_escalates"# AC13
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_untrusted_or_missing_author_association_fails_closed"# AC14
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_raw_comment_body_not_forwarded_to_issue_author"# AC15
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_provenance_distinguishes_trusted_anchor_from_agent_inferred"# AC16
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_issue_comment_url_mismatch_or_pr_review_url_confusion_is_invalid"# AC17
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_conflicting_reviewer_directives_classified_as_conflicting_human_directives"# AC18
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_boundary_flags_block_contract_update_even_with_trusted_approval"# AC19
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_issue_1270_fixture_generates_contract_patch_plan_with_forbidden_operations"# AC20
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_decide_next_loop_action_contract_update.pyAllowed Paths
- .claude/skills/issue-refinement-loop/scripts/scope_signal_delta.py
- .claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py
- .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py
- .claude/skills/issue-refinement-loop/scripts/decide_next_loop_action.py
- .claude/skills/issue-refinement-loop/references/scope-signal-guard.md
- .claude/skills/issue-refinement-loop/references/anchor-comment-handling.md
- .claude/skills/issue-refinement-loop/schemas/
- .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py
- .claude/skills/issue-refinement-loop/tests/test_decide_next_loop_action.py
- .claude/skills/issue-refinement-loop/tests/test_decide_next_loop_action_contract_update.py
- .claude/skills/issue-refinement-loop/tests/fixtures/
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
REFINEMENT_LOOP_PLAN_V1トップレベル schema やLOOP_STATE_V1.termination_reasonenum の変更が必要と判明した場合- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
- Python / pytest
- YAML / JSON Schema 設計
- GitHub REST API(author_association / comment metadata 取得)
Scope Delta(任意)
N/A
Delivery Rule
- 1 Issue = 1 PR
- worktree で実装する
- Draft PR として作成し、AC 全件 VC 通過後に Ready for Review にする
- マージ後、実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008 / 実装: CONTEXT_PROVENANCE_V1 を導入し human-requested / agent-inferred / repo-evidence を分離する #1011 を「Closed as superseded by 実装: Refinement Loop の scope guard を人間レビュー由来の契約更新として自動反映できるようにする #1323」として close する
Runtime Verification Applicability
- decision: not_applicable
- reason: 本 Issue は issue-refinement-loop skill 内の静的なロジック変更(Python)であり、pytest による決定論的検証で完結する。ゲームランタイム/ブラウザ実行を伴わない。
Notes for Reviewer
今回の改善目的は scope guard を弱めることではなく、「誰が、どの権限で、何を変更しようとしているか」を区別できるようにすることである。参考実例: Issue #1270(コメント #1270 (comment) の Human Review Decision)。
OWNER 判断(2026-07-04): #1323 は #1008 / #1011 を supersede する(anchor comment #1323 (comment) への回答)。既存 #1090(PR #1294, マージ済み)の SCOPE_SIGNAL_GUARD_DECISION_V2 / ANCHOR_SCOPE_REFRAME_V1 は再実装せず、その additive 拡張ポイント(scope_signal_guard_decision_v2 配下)に scope_delta_authority を追加する形で統合する。contract_update_required は route の新しい enum 値としてのみ追加し、REFINEMENT_LOOP_PLAN_V1 トップレベル schema と LOOP_STATE_V1.termination_reason enum は変更しない。scope_delta_authority_evidence_v1 は raw comment body を含まない正規化済み evidence とし、contract_patch_plan_v1 は Issue 本文への実際の書き込み(direct_github_write)を実行しない生成専用の shape とする。
本改訂で #1008 / #1011 の Outcome / AC を吸収したため、両 Issue は本 Issue マージ後に superseded として close する。
Activity
squne121 commentedon Jul 4, 2026
判定: REQUEST_CHANGES
#1323 の問題意識は妥当です。#1270 のように、人間レビューが Revised AC や前提条件を明示しているのに
new_in_scope_areaで即human_escalationするのは過剰停止です。ただし、現契約のまま実装すると 既存のANCHOR_SCOPE_REFRAME_V1/SCOPE_SIGNAL_GUARD_DECISION_V2と並行する別権限モデルを増やすだけになり、schema-invalid、router 未接続、または自由記述コメントによる権限注入のいずれかに落ちます。#1323 自体にはコメントはありません。本文は #1008 / #1011 との概念重複を認識しつつ、#1090 で実装済みの構造化 anchor approval とは別に「自由記述の人間レビュー指摘」を扱う Issue と位置づけています。
Blocker 1: #1008 / #1011 / #1090 との統合方針が未決定
#1008 は trusted human anchor comment を AI scope creep と分離し、
run_refinement_preflight.pyから planner のknown_contextへ渡すことを目的にしています。#1011 はCONTEXT_PROVENANCE_V1でhuman-requested / agent-inferred / repo-evidenceを分離する設計です。#1323 のscope_delta_authorityはこの2件の中核と重複します。さらに #1090 / PR #1294 では、
SCOPE_SIGNAL_GUARD_DECISION_V2、trusted anchor approval、proceed_with_notes、security-sensitive fail-closed が既に merged されています。PR #1294 は既存decisions.scope_signal_guardを変えず、known_context.scope_signal_delta_inputがある場合だけ additive に v2 artifact を出す設計です。修正要求: #1323 は単独実装ではなく、次のどちらかに寄せるべきです。
SCOPE_SIGNAL_GUARD_DECISION_V2の authority/provenance 拡張に限定する。この整理なしに実装すると、
ANCHOR_SCOPE_REFRAME_V1、ANCHOR_SCOPE_AMENDMENT_V1、CONTEXT_PROVENANCE_V1、scope_delta_authorityが併存し、エージェントが正本を誤読します。Blocker 2:
scope_signal_delta.pyだけでは authority 分類に必要な入力がない#1323 は
scope_signal_delta.pyにscope_delta_authority分類を追加するとしていますが、現行scope_signal_delta_inputはbefore_body / current_body / after_body / source_refsだけです。compute_scope_signal_delta()も本文差分から Allowed Paths / In Scope / AC の delta を出すだけで、author、author_association、comment_url、issue_url、PR review metadata、parent/related issue snapshot を受け取りません。さらに
_validate_input()は未知フィールドを拒否します。つまり、現在の入力契約のままではhuman_review_directive、existing_parent_contract、related_issue_dependencyを deterministic に分類できません。修正要求: Allowed Paths に少なくとも以下を入れるか、#1323 を planner-only の diagnostic 拡張に縮退してください。
.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py.claude/skills/issue-refinement-loop/schemas/.claude/skills/issue-refinement-loop/scripts/decide_next_loop_action.py.claude/skills/issue-refinement-loop/schemas/loop_state.schema.jsonBlocker 3:
contract_update_requiredが schema / router / loop_state に存在しない#1323 は
status: contract_update_required、implementation_allowed:false、next_step:rerun_refinement_after_contract_updateを出す設計ですが、現行refinement_loop_plan_v1.jsonは top-leveladditionalProperties:falseで、decisionsもadditionalProperties:falseです。また、現行
decisions.scope_delta_decision.statusの enum はapproved_by_trusted_anchor / fail_closed / not_applicableのみで、contract_update_requiredはありません。LOOP_STATE_V1.termination_reasonもapproved / human_escalation / superseded_by_decision / nullだけです。router はscope_signal_guard.triggeredを見るとSTATUS: human_escalation/NEXT_ACTION: human_escalation/TERMINATION_CAUSE: human_judgment_requiredを返す実装です。修正要求:
contract_update_requiredの置き場を明確にしてください。実際の停止挙動を変えるなら schema/router/loop_state まで変更対象です。変えないなら AC2/AC4/AC9 は「出力するだけ」で運用効果がありません。
Blocker 4: 「自由記述の人間レビュー指摘」は安全境界を下げる
既存 docs は、raw anchor comment body を planner や delta helper に直接流してはならず、normalized decision / hash / provenance のみを渡す、と明記しています。
現行の anchor approval は、top-level fenced YAML の
ANCHOR_SCOPE_REFRAME_V1を要求し、GitHubauthor_associationがOWNER / MEMBER / COLLABORATORであること、target repo/issue 一致、schema validity などを fail-closed で確認します。GitHub の Issue Comments REST response には
issue_urlとauthor_associationが含まれるため、同一 Issue コメントか、信頼できる関係者か、という構造検証は可能です。ただし GitHub Docs も issue comments と pull request review comments を別エンドポイントとして扱っており、自由記述コメントの意味解釈はリポジトリ側の独自ロジックです。([GitHub Docs]1) (GitHub Docs)修正要求: 「テンプレート形式を問わない」は残してもよいですが、planner に渡すのは raw body ではなく、preflight が生成する normalized evidence に限定してください。
最低限の normalized shape:
Blocker 5:
additionalProperties:falseと additive-only 方針の相性が悪いPR #1294 では、v2 field を schema 外に置き、テストも
plan_refinement_loop()直呼びで schema validation を避けています。テストファイル自身が「新フィールドは intentionally kept out of schemas/refinement_loop_plan_v1.json」と説明しています。これは #1090 では暫定的に成立しても、#1323 のように router/status/contract patch plan に影響するフィールドでは危険です。JSON Schema でも、
additionalPropertiesは同じ subschema 内で宣言された property だけを認識するため、closed schema を後からallOf等で拡張しようとすると失敗しやすいです。新しい draft ではunevaluatedPropertiesでこの問題を緩和できます。([JSON Schema]2)修正要求: 次のいずれかにしてください。
REFINEMENT_LOOP_PLAN_V2を導入する。REFINEMENT_LOOP_PLAN_V1に明示的なextensions/artifactsslot を追加する。scope_signal_guard_decision_v2を拡張し、scope_delta_authorityをその配下に入れる。Blocker 6: authority / safety / route / reason_code が混ざっている
#1323 の分類は
ai_inferred / human_review_directive / existing_parent_contract / related_issue_dependency / ambiguous_or_conflicting / safety_or_permission_boundaryですが、これは同じ軸ではありません。これを1つの enum に押し込むと、後続 consumer が分岐条件を誤ります。#1090 の v2 は既に
raw_signal / scope_context / scope_delta_approval / security_sensitive / routeに分けています。#1323 も同じ分解に寄せるべきです。推奨 shape:
Blocker 7: patch plan が未定義で、Issue 本文の危険な半自動編集になり得る
#1323 は In Scope / Out of Scope / AC / Stop Conditions / Verification Commands への patch plan 生成を求めていますが、patch の形式、source evidence、staleness check、競合時の扱い、適用主体が未定義です。
修正要求:
contract_patch_plan_v1を明文化してください。Python artifact 出力では
json.dumps(..., allow_nan=False)を維持してください。Python の JSON encoder は既定だとNaN/Infinityを出力し得るため、strict JSON にするならallow_nan=Falseが必要です。([Python documentation]3)追加すべきテスト
現 AC1〜AC10 だけでは不足です。最低限、以下を追加してください。
scope_signal_delta_inputだけではhuman_review_directiveを分類できず、normalized evidence 不在なら fail-closed。author_association欠落、CONTRIBUTOR、NONE、bot user は fail-closed。issue_urlが対象 Issue と一致しない場合は invalid。ambiguous_human_directive。conflicting_human_directives。changes_permission_boundary/changes_external_service_boundary/destructive_or_non_idempotent_operationは approval があっても contract update に進まない。contract_patch_plan_v1が生成される。contract_update_requiredが schema validation / preflight / router / loop_state のどこで消費されるかを end-to-end で検証する。結論
#1323 は 実装着手前に契約修正必須です。特に直すべきは次の3点です。
scope_signal_delta.py単体ではなく、preflight provenance → planner artifact → router/loop_state までの責務境界を再定義する。貼り付け用のレビューコメント案です。
判定
REQUEST_CHANGES。
#1323 の方向性は妥当です。#1270 のように、人間レビューが Revised Acceptance Criteria / 前提条件 / Stop Condition を明示しているにもかかわらず、Refinement Loop が
new_in_scope_areaとして即human_escalationする挙動は過剰停止です。ただし、現契約のまま実装すると、既存の
ANCHOR_SCOPE_REFRAME_V1/SCOPE_SIGNAL_GUARD_DECISION_V2/ #1008 / #1011 と衝突します。Blockers
実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008 / 実装: CONTEXT_PROVENANCE_V1 を導入し human-requested / agent-inferred / repo-evidence を分離する #1011 / 実装: scope_signal_guard の escalation lane を分割し scope delta approval を契約化する #1090 との統合方針が未定義
known_contextに渡す Issue。CONTEXT_PROVENANCE_V1でhuman-requested / agent-inferred / repo-evidenceを分離する Issue。SCOPE_SIGNAL_GUARD_DECISION_V2と trusted anchor approval が既に merged 済み。scope_signal_delta.py単体ではhuman_review_directiveを分類できないscope_signal_delta_inputはbefore_body / current_body / after_body / source_refsだけで、author、author_association、comment_url、issue_url、parent/related issue snapshot を持ちません。_validate_input()は unknown field を拒否するため、現在の入力契約のまま authority 分類を足すのは無理があります。run_refinement_preflight.pyで GitHub comment metadata を検証し、normalized evidence を planner に渡す設計にしてください。contract_update_requiredが schema / router / loop_state に存在しないREFINEMENT_LOOP_PLAN_V1は top-level / decisions ともに closed schema です。scope_delta_decision.statusenum にcontract_update_requiredはありません。LOOP_STATE_V1.termination_reasonとdecide_next_loop_action.pyもcontract_update_requiredを消費しません。自由記述コメントを authority として扱う設計は危険
scope_delta_authority_evidence_v1のような構造化 evidence に変換し、planner はそれだけを読むべきです。authority / provenance / boundary / route / reason_code が混ざっている
human_review_directiveとsafety_or_permission_boundaryは同じ分類軸ではありません。authority_category、provenance、directive.confidence、boundary_flags、route.action、reason_codeに分解してください。Required Contract Changes
scope_delta_authority_evidence_v1を定義し、GitHub comment metadata 検証済みの normalized evidence のみ planner に渡す。contract_update_requiredの消費点を明確化する。planner-only artifact なのか、preflight status なのか、router next_action なのか、loop_state termination_reason なのかを固定する。contract_patch_plan_v1を定義し、Issue 本文への direct write は禁止する。この修正なしで実装すると、過剰停止の解消ではなく、既存 guard の外側に未検証の authority bypass を追加するリスクが高いです。
squne121 commentedon Jul 4, 2026
Refinement Loop: Human Escalation Required
The loop has terminated and requires human review. Cause: human judgment required
human_escalationhuman_judgment_requiredBlockers
squne121 commentedon Jul 4, 2026
Refinement Loop: Human Escalation Required
The loop has terminated and requires human review. Cause: human judgment required
human_escalationhuman_judgment_requiredBlockers
squne121 commentedon Jul 4, 2026
Contract Review Result
squne121 commentedon Jul 4, 2026
implement-issue: 実装完了 (2026-07-04)
4e59578c).claude/worktrees/issue-1323-refinement-loop-scope-guardworktree-issue-1323-refinement-loop-scope-guard.claude/skills/issue-refinement-loop/tests/全体で既存回帰含め 1176 passed(新規 26 tests 含む)not_applicable(静的 Python ロジック変更、pytest で完結)fix: check_issue_contract.py の body_sha256 が canonical raw-body hash …