Skip to content

実装: agent-ops: scope_signal_guard を差分ベース診断にして In Scope 語彙追加停止ループを防ぐ #1027

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "scope_signal_guard の差分判定仕様を安全化し、既存 layer 再掲や並び替えで false positive を出さない deterministic な delta facts を追加する"
change_kind: workflow

Parent Issue

なし(standalone issue)

Parent Goal Ref

  • Goal: issue-refinement-loop の scope_signal 判定を再現可能な差分事実に基づいて評価できるようにする
  • Desired Destination: new_allowed_path_layer の false positive を減らし、後続 issue が consume 可能な差分 artifact と planner projection を固定する

Background

Current Validated Scope

  • .claude/skills/issue-refinement-loop/scripts/scope_signal_delta.py を追加し、SCOPE_SIGNAL_DELTA_INPUT_V1 を read-only / stdin JSON / stdout canonical JSON の deterministic CLI と library API として固定する
  • .claude/skills/issue-refinement-loop/schemas/scope_signal_delta_v1.schema.json を追加し、before/current/after の body hash・source_refs・normalized delta facts・legacy scope_signal_guard projection を固定する
  • .claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py で top-level prefix 数え上げベースの new_allowed_path_layer 判定を廃止し、scope_signal_delta projection を consume する
  • .claude/skills/issue-refinement-loop/tests/test_scope_signal_delta.py / tests/test_plan_refinement_loop.py / tests/test_scope_signal_guard_termination.py / tests/test_anchor_scope_reframe_preflight.py / tests/test_anchor_comment_artifact_boundary.py と tests/fixtures/scope_signal_delta/** を追加・更新し、既存 layer 再掲・並び替え・空白差分・trusted anchor projection・raw anchor 非注入・非自動修正 policy の回帰を固定する
  • .claude/skills/issue-refinement-loop/references/scope-signal-guard.md を更新し、trusted anchor は raw comment body ではなく既存の normalized known_context.scope_delta_decision のみを参照し、approved_by_trusted_anchor かつ implementation_go=false の境界を維持することを明記する
  • 実装: scope_signal_guard の escalation lane を分割し scope delta approval を契約化する #1090 が consume できる最小 artifact/schema/test だけを追加し、lane split 自体は out of scope に残す

Remaining Parent Gaps

なし(standalone issue)

Outcome

scope_signal_delta が before/current/after の section delta を deterministic に算出し、plan_refinement_loop.py はその projection に基づいて new_allowed_path_layer を判定する。既存 layer の再掲、並び替え、空白差分、fenced code 内の path mention では false positive を出さず、trusted anchor がある場合も raw comment body を再 parse しない。

Source Of Truth

SCOPE_SIGNAL_DELTA_INPUT_V1

before_body: string
current_body: string
after_body: string
source_refs:
  before: string | null
  current: string | null
  after: string | null
  • before_body: rewrite 前の canonical issue body
  • current_body: planner / checker が評価対象として読む current snapshot body
  • after_body: proposed rewrite body または fixture が与える candidate body
  • source_refs.*: issue URL / artifact path / fixture path / comment id のいずれかを表す provenance

production path で raw anchor comment body を before/current/after に流してはならない。anchor 由来の抑止条件は、既存 preflight が生成する normalized known_context.scope_delta_decision のみを consume する。

In Scope

  • .claude/skills/issue-refinement-loop/scripts/scope_signal_delta.py の追加
  • .claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py の scope_signal_guard 判定を scope_signal_delta projection 経由へ置換
  • .claude/skills/issue-refinement-loop/schemas/scope_signal_delta_v1.schema.json の追加
  • .claude/skills/issue-refinement-loop/tests/test_scope_signal_delta.py の追加・更新
  • .claude/skills/issue-refinement-loop/tests/test_plan_refinement_loop.py の差分判定 / anchor projection 回帰追加
  • .claude/skills/issue-refinement-loop/tests/test_scope_signal_guard_termination.py の回帰追加
  • .claude/skills/issue-refinement-loop/tests/test_anchor_scope_reframe_preflight.py の trusted anchor projection 回帰追加
  • .claude/skills/issue-refinement-loop/tests/test_anchor_comment_artifact_boundary.py の raw anchor 非注入回帰追加
  • .claude/skills/issue-refinement-loop/tests/fixtures/scope_signal_delta/** の追加
  • .claude/skills/issue-refinement-loop/references/scope-signal-guard.md の契約更新

Out of Scope

Acceptance Criteria

  • AC1: SCOPE_SIGNAL_DELTA_INPUT_V1 と SCOPE_SIGNAL_DELTA_V1 が追加され、before/current/after の body hash・source_refs・normalized delta facts・legacy scope_signal_guard projection を含む
  • AC2: 既存 layer の再掲、並び替え、空白差分、fenced code 内の path mention では legacy_scope_signal_guard.triggered == false になる fixture が追加される
  • AC3: new_allowed_path_layer は after.allowed_path_layers - before.allowed_path_layers が非空の場合にのみ発火する
  • AC4: excluded_by_anchor_reframe=true は known_context.scope_delta_decision.status == "approved_by_trusted_anchor" かつ implementation_go == false かつ required_rerun 保持時だけ出る
  • AC5: plan_refinement_loop.py / scope_signal_delta.py は raw anchor comment body を読まず、normalized scope_delta_decision だけを consume する
  • AC6: scope_signal_delta は lane split を行わず、実装: scope_signal_guard の escalation lane を分割し scope delta approval を契約化する #1090 が consume 可能な normalized delta facts(added / removed / repeated_existing / triggering_lines)だけを出力する
  • AC7: scope_signal_guard が発火しても orchestrator が In Scope / Allowed Paths を自動修正しない既存 policy を回帰テストで維持する

Verification Commands

# AC1
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_scope_signal_delta.py -q -k "schema or artifact"

# AC2
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_scope_signal_delta.py -q -k "repeated or reordered or whitespace or fenced_code"

# AC3
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_scope_signal_delta.py -q -k "new_allowed_path_layer"

# AC4
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_anchor_scope_reframe_preflight.py -q -k "approved_trusted_anchor_scope_delta_decision"

# AC5
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_anchor_comment_artifact_boundary.py -q

# AC6
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_scope_signal_delta.py -q -k "projection or repeated_existing"

# AC7
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_scope_signal_guard_termination.py -q

Allowed 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/schemas/scope_signal_delta_v1.schema.json
  • .claude/skills/issue-refinement-loop/tests/test_scope_signal_delta.py
  • .claude/skills/issue-refinement-loop/tests/test_plan_refinement_loop.py
  • .claude/skills/issue-refinement-loop/tests/test_scope_signal_guard_termination.py
  • .claude/skills/issue-refinement-loop/tests/test_anchor_scope_reframe_preflight.py
  • .claude/skills/issue-refinement-loop/tests/test_anchor_comment_artifact_boundary.py
  • .claude/skills/issue-refinement-loop/tests/fixtures/scope_signal_delta/**
  • .claude/skills/issue-refinement-loop/references/scope-signal-guard.md

Stop Conditions

Runtime Verification Applicability

decision: not_applicable
reason: "workflow script / schema / fixture / reference の変更のみを対象とし、runtime gameplay や CI workflow lane split 自体は変更しない"
deferred_destination: n/a

Related Issues

Required Skills

  • Python(JSON / delta 計算 / pytest)
  • issue-refinement-loop architecture
  • JSON Schema

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    on Jun 20, 2026
  2. squne121 commented on Jul 1, 2026

    @squne121
    OwnerAuthor

    判定: REQUEST_CHANGES

    #1027 の問題意識は妥当です。現行 plan_refinement_loop.py の scope_signal_guard は、Allowed Paths の top-level prefix が 2 種以上あるだけで new_allowed_path_layer を出す構造で、before/current/after 差分を見ていません。つまり「既存 layer の再掲」や「順序変更」でも停止し得るため、差分ベース化は必要です。

    ただし、#1027 はこのまま実装に入るべきではありません。Issue 契約が曖昧なままだと、#920 の trusted anchor 境界、#1090 の scope lane split 前提、既存 preflight/planner の raw comment 分離境界を壊す可能性が高いです。


    致命的指摘

    1. Parent contract が破綻している

    #1027 の Machine-Readable Contract は parent_issue: "none" なのに、本文の ## Parent Issue は #964 です。さらに #964 は PR body hygiene 更新は update_pr.py wrapper 経由に限定する Issue で、direct gh pr edit body mutation の hook/wrapper 制御が主題です。scope_signal_delta / issue-refinement-loop の親としては意味が合いません。

    同じ agent-ops 系の #1024 は LOOP_STATE builder、#1026 は command registry で、#1027 はそれらと並ぶ「scope_signal 差分ベース化」slot に見えます。#1024 も Remaining Parent Gaps で scope_signal 差分分類を別 Issue として扱っており、#1026 も scope_signal guard 変更を Out of Scope にしています。

    修正要求: parent_issue を実際の agent-ops rollup に直すか、standalone として related_issues: [1024, 1026, 1028, 920, 1090] を明示してください。現状のままだと、contract lineage / Remaining Parent Gaps / stop condition の解釈が壊れます。


    2. before/current/after の SoT が未定義

    #1027 は「before/current/after のハッシュと差分行」を要求していますが、3 つの本文がどこから来るのかを定義していません。現行 run_refinement_preflight.py は repair dry-run を実行しても、planner には original Issue body を渡す設計です。

    このままでは実装者が次のどれを after とみなすべきか判断できません。

    • issue-author が提案した rewrite 後 body

    • repair_issue_contract.py の dry-run result

    • GitHub 上の current issue body

    • preflight fixture 内の proposed body

    • planner 実行時に main thread が保持しているローカル draft

    修正要求: scope_signal_delta.py の入力契約を固定してください。最低限、以下のように明示すべきです。

    SCOPE_SIGNAL_DELTA_INPUT_V1:
      before_body: string        # rewrite 前の canonical issue body
      current_body: string       # GitHub/current snapshot body
      after_body: string         # proposed rewrite body
      source_refs:
        before: artifact path or issue comment id
        current: issue url/hash
        after: artifact path or rewrite result id
    

    after_body を production preflight から生成するなら、#1027 の Allowed Paths には run_refinement_preflight.py か rewrite producer 側が必要です。Allowed Paths を増やせないなら、#1027 は scope_signal_delta.py の純粋 CLI + planner integration に限定し、after は fixture/stdin から受ける契約にしてください。


    3. Artifact schema がないため #1090 が消費できない

    #1090 は #1027 を blocked_by にしており、new_allowed_path_layer を runtime / docs / skill / hook / agent / test などへ lane split する前提として、#1027 の差分ベース診断を要求しています。

    しかし #1027 は scope_signal_delta artifact を追加するとだけ書いており、schema_version、必須 field、互換性、legacy reason_code との関係を固定していません。これでは #1090 側が安定して consume できません。

    修正要求: Allowed Paths に schema を追加してください。

    + .claude/skills/issue-refinement-loop/schemas/scope_signal_delta_v1.schema.json
    

    推奨する最小 schema は次です。

    schema_version: scope_signal_delta/v1
    inputs:
      before_body_sha256: string
      current_body_sha256: string
      after_body_sha256: string
      source_refs:
        before: string | null
        current: string | null
        after: string | null
    sections:
      allowed_paths:
        before: []
        current: []
        after: []
        added: []
        removed: []
        repeated_existing: []
      in_scope:
        before_layers: []
        after_layers: []
        added_layers: []
        repeated_existing_layers: []
      acceptance_criteria:
        added_low_verifiability_items: []
    signals:
      - reason_code: new_allowed_path_layer | new_in_scope_area | new_unverifiable_ac
        triggered: boolean
        normalized_value: string
        triggering_lines:
          - body_version: before | current | after
            start_line: integer
            end_line: integer
            text_sha256: string
    legacy_scope_signal_guard:
      triggered: boolean
      reason_code: string
      excluded_by_anchor_reframe: boolean
    suppressions:
      anchor_reframe:
        status: approved_by_trusted_anchor | not_applicable | fail_closed
        implementation_go: false
    

    JSON Schema で allOf などの composition を使う場合、additionalProperties: false は subschema をまたぐ拡張と衝突しやすいため、Draft 2019-09 以降の unevaluatedProperties: false を検討すべきです。(JSON Schema)


    4. 現行 guard の置換単位が曖昧

    現行 plan_refinement_loop.py は _detect_scope_signals(issue_body, known_context) を直接呼び、scope_signal_guard.triggered/reason_code/excluded_by_anchor_reframe を組み立てています。

    #1027 は「scope 判定を差分ベース API 経由へ移行」と書いていますが、次が未定義です。

    • _detect_scope_signals を削除するのか

    • _detect_scope_signals が scope_signal_delta.py の library API を呼ぶのか

    • scope_signal_delta.py は CLI 専用なのか、import 可能 module なのか

    • legacy scope_signal_guard 出力を誰が生成するのか

    • diff artifact は planner output に埋め込むのか、artifact path 参照にするのか

    修正要求: production path は次のように固定してください。

    plan_refinement_loop.py
      -> import scope_signal_delta
      -> compute SCOPE_SIGNAL_DELTA_V1 from before/current/after
      -> derive legacy scope_signal_guard projection
      -> expose full delta as artifact path or decisions.scope_signal_delta
    

    CLI は --help と stdin/stdout の deterministic interface を持つべきですが、planner が shell out する設計は避けるべきです。planner 内部で subprocess を挟むと、失敗分類と artifact hash が複雑になります。


    5. Anchor reframe の境界を壊す危険がある

    #920 / PR #1119 後の current repo では、trusted anchor は run_refinement_preflight.py が GitHub issue comment を取得し、author_association、target repo/issue、schema validation を見たうえで known_context.scope_delta_decision に正規化する構造になっています。

    scope-signal-guard.md も、trusted anchor は implementation_go=false で、contract review / refinement preflight / allowed_paths_gate の再実行が必要だと明記しています。

    #1027 の AC4 は「anchor が明示的に再フレーム許可している場合のみ excluded_by_anchor_reframe=true」とだけ書いています。これだと実装者が plan_refinement_loop.py で raw comment body を再 parse し、#920 の raw-body 境界を破る危険があります。

    修正要求: AC4 を次のように狭めてください。

    AC4: `excluded_by_anchor_reframe=true` は、
    `known_context.scope_delta_decision.status == "approved_by_trusted_anchor"` かつ
    `implementation_go == false` かつ `required_rerun` を保持している場合だけ出る。
    `plan_refinement_loop.py` / `scope_signal_delta.py` は raw anchor comment body を読まない。
    

    GitHub issue comments API は body だけでなく issue_url と author_association を返します。trusted 判定はこの API metadata を SoT にすべきで、コメント本文の自己申告を信じる設計に戻してはいけません。(GitHub Docs)


    6. #1090 との責務境界が危ない

    #1090 は #1027 完了後に new_runtime_path_layer / new_skill_or_docs_layer / new_hook_or_agent_layer / missing_scope_delta_approval へ lane split する Issue です。#1090 のレビューコメントでも、path prefix だけで lane 分類すると false positive を再発させると指摘されています。

    #1027 がやるべきことは lane split ではなく、lane split 可能な normalized delta facts を出すことです。

    #1027 側で出すべきもの:

    added_allowed_paths:
      - ".claude/skills/issue-refinement-loop/scripts/scope_signal_delta.py"
    added_top_level_prefixes:
      - ".claude"
    repeated_existing_allowed_paths:
      - ".claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py"
    has_new_layer: true
    

    #1090 側に残すべきもの:

    path_layer: runtime | docs | skill | hook | agent | test_fixture | unknown
    route: proceed_with_notes | human_judgment_required | block
    security_risk_gate_required: boolean
    

    この分離を #1027 本文に入れないと、#1027 が #1090 の lane split まで先取りして scope creep します。


    実装品質に関する外部調査ベースの改善点

    差分判定は unified diff 文字列ではなく、正規化 set/opcode で行う

    Python difflib は human-friendly な差分生成に向いていますが、SequenceMatcher は最小 edit script を保証しないうえ、繰り返し要素に対する heuristic があります。unified_diff は人間向け evidence としては有用ですが、判定ロジックの唯一の SoT にすべきではありません。(Python documentation)

    推奨:

    before_paths = normalize_allowed_paths(before_body)
    after_paths = normalize_allowed_paths(after_body)
    

    added = sorted(after_paths - before_paths)
    repeated = sorted(after_paths & before_paths)
    removed = sorted(before_paths - after_paths)

    triggered = bool(added_layer_set)

    difflib.unified_diff(..., n=0 or 3, lineterm="") は artifact の human_diff として残す程度に留めるべきです。

    Git-like artifact を出すなら patch 適用可能性を主張しない

    Git の diff --git a/file b/file 形式は traditional unified diff と細部が異なり、rename/copy/path quoting などもあります。#1027 の artifact が Git patch ではなく issue body section diff なら、git diff compatible と主張しない方が安全です。(Git)

    推奨 field:

    human_unified_diff:
    format: difflib_unified_diff
    patch_apply_semantics: false

    JSON は load/dump の両方で strict にする

    Python json.dumps(..., allow_nan=False, sort_keys=True) は regression artifact に適しています。読み込み側では parse_constant を使って NaN / Infinity / -Infinity を reject できます。(Python documentation)

    現行 plan_refinement_loop.py は decode 後に NaN/Infinity を再帰検査していますが、parse_constant を使えば decode 時点で fail-closed にできます。


    追加すべき fixture

    最低限、次の fixture が必要です。

    fixture 期待
    existing_allowed_path_repeated.json 既存 path 再掲は triggered=false
    allowed_paths_reordered.json 並び替えのみは triggered=false
    allowed_paths_whitespace_only.json 空白・bullet 形式変更のみは triggered=false
    new_allowed_path_same_layer.json 同一 layer 内の追加をどう扱うか明示
    new_allowed_path_new_layer.json new_allowed_path_layer
    mixed_existing_and_new_layers.json repeated と added を両方 artifact に出す
    fenced_code_mentions_path.json fenced code 内の path は section path として扱わない
    markdown_table_allowed_paths.json table/list の path 抽出を固定
    anchor_trusted_suppresses_signal.json trusted anchor ありで excluded_by_anchor_reframe=true
    anchor_fail_closed_does_not_suppress.json untrusted/wrong issue は suppress しない
    json_nan_rejected.json NaN/Infinity は input validation error
    orchestrator_no_auto_scope_rewrite.json scope_signal 時に In Scope/Allowed Paths を自動修正しない

    特に最後の AC5 は plan_refinement_loop.py 単体では証明しにくいです。scope-signal-guard.md は orchestrator が planner output を consume するだけで判定を再実装しない、scope 拡張を自動承認しない、と明記しています。

    Allowed Paths を増やせないなら、AC5 は「既存 policy に対する regression assertion」に弱めるか、別 Issue に分割してください。


    Verification Commands の問題

    #1027 の現行 Verification Commands は AC と対応していません。

    • AC2 の command が scope_signal_delta.py --help になっており、「before 既存 layer を new 扱いしない fixture」の検証になっていません。

    • AC3 は plan_refinement_loop.py < input_existing_layers.json だけで、stdout の reason_code / triggered assertion がありません。

    • AC5 の pnpm typecheck/lint/test/build は repo-wide gate であり、「orchestrator が In Scope を自動修正しない」証明にはなりません。

    推奨:

    uv run pytest .claude/skills/issue-refinement-loop/tests/test_scope_signal_delta.py -q
    

    uv run python3 .claude/skills/issue-refinement-loop/scripts/scope_signal_delta.py
    < .claude/skills/issue-refinement-loop/tests/fixtures/scope_signal_delta/input_existing_layers.json
    | jq -e '.legacy_scope_signal_guard.triggered == false'

    uv run python3 .claude/skills/issue-refinement-loop/scripts/scope_signal_delta.py
    < .claude/skills/issue-refinement-loop/tests/fixtures/scope_signal_delta/input_new_layer.json
    | jq -e '.legacy_scope_signal_guard.reason_code == "new_allowed_path_layer"'

    uv run pytest .claude/skills/issue-refinement-loop/tests/test_plan_refinement_loop.py
    -q -k "scope_signal_delta or anchor_reframe"

    uv run pytest .claude/skills/issue-refinement-loop/tests/test_scope_signal_guard_termination.py -q

    repo-wide gates は最後に残してよいですが、AC の primary evidence にしてはいけません。


    そのまま貼れる修正版レビューコメント案

    ## 判定

    REQUEST_CHANGES。

    #1027 の方向性は正しいです。現行 plan_refinement_loop.py の scope_signal_guard は before/current/after 差分を見ず、Allowed Paths / In Scope の prefix 数や語彙だけで new_allowed_path_layer / new_in_scope_area を出すため、既存 layer 再掲で false positive を起こし得ます。

    ただし、現契約のまま実装すると別の不整合を作ります。

    Blockers

    1. Parent contract が破綻しています。

      • Machine-Readable Contract は parent_issue: "none"。
      • 本文の Parent Issue は #964。
      • #964 は PR body hygiene / update_pr wrapper の Issue で、scope_signal_delta の親として不適切です。
      • 実 parent / rollup を明示するか、standalone + related_issues に直してください。
    2. before/current/after の SoT が未定義です。

      • before/current/after body が GitHub snapshot、rewrite draft、repair dry-run、fixture のどれなのか不明です。
      • SCOPE_SIGNAL_DELTA_INPUT_V1 を定義し、各 body hash と source_ref を必須にしてください。
    3. scope_signal_delta artifact schema がありません。

      • schema_version
      • before/current/after hashes
      • normalized section deltas
      • added / removed / repeated_existing
      • triggering_lines
      • legacy scope_signal_guard projection
      • anchor suppression status
        を固定してください。
      • Allowed Paths に schemas/scope_signal_delta_v1.schema.json を追加すべきです。
    4. #920 の trusted anchor 境界を壊さないでください。

      • plan_refinement_loop.py / scope_signal_delta.py は raw anchor comment body を parse してはいけません。
      • known_context.scope_delta_decision.status == approved_by_trusted_anchor のみを consume してください。
      • trusted anchor でも implementation_go=false と required_rerun は維持してください。
    5. #1090 との責務を分けてください。

      • #1027 は normalized delta facts を出す。
      • runtime/docs/skill/hook/agent lane split と route decision は #1090 に残す。
      • #1027 で lane split まで実装すると scope creep です。
    6. AC5 は現在の Allowed Paths では証明困難です。

      • orchestrator が In Scope を自動修正しないことを本当に保護するなら、rewrite/orchestrator 側の test path が必要です。
      • Allowed Paths を増やせないなら、AC5 を policy/reference regression に弱めるか、別 Issue に分割してください。

    Required contract changes

    • SCOPE_SIGNAL_DELTA_INPUT_V1 と SCOPE_SIGNAL_DELTA_V1 を追加する。
    • scope_signal_delta.py は read-only、stdin JSON、stdout canonical JSON、no GitHub mutation とする。
    • plan_refinement_loop.py は旧 prefix-count 判定ではなく scope_signal_delta の library API を consume する。
    • new_allowed_path_layer は after.allowed_path_layers - before.allowed_path_layers が非空の場合のみ出す。
    • 既存 layer の再掲、並び替え、空白差分、fenced code 内の path mention は signal にしない。
    • trusted anchor は normalized known_context.scope_delta_decision のみで判定し、raw comment body を planner/delta に渡さない。

    この修正なしで実装すると、false positive 解消ではなく、scope_signal_guard / anchor reframe / #1090 lane split の境界破壊になります。


    結論

    #1027 は 必要だが、契約修正が先 です。特に修正すべきは、親子関係、before/current/after の入力契約、SCOPE_SIGNAL_DELTA_V1 schema、#920 trusted anchor 境界、#1090 との責務分離です。

    現行のまま実装すると、new_allowed_path_layer の false positive を減らす目的に対して、artifact 非互換・anchor bypass・scope creep のリスクが高いです。

    ## 判定: REQUEST_CHANGES

    #1027 の問題意識は妥当です。現行 plan_refinement_loop.py の scope_signal_guard は、Allowed Paths の top-level prefix が 2 種以上あるだけで new_allowed_path_layer を出す構造で、before/current/after 差分を見ていません。つまり「既存 layer の再掲」や「順序変更」でも停止し得るため、差分ベース化は必要です。

    ただし、#1027 はこのまま実装に入るべきではありません。Issue 契約が曖昧なままだと、#920 の trusted anchor 境界、#1090 の scope lane split 前提、既存 preflight/planner の raw comment 分離境界を壊す可能性が高いです。


    致命的指摘

    1. Parent contract が破綻している

    #1027 の Machine-Readable Contract は parent_issue: "none" なのに、本文の ## Parent Issue は #964 です。さらに #964 は PR body hygiene 更新は update_pr.py wrapper 経由に限定する Issue で、direct gh pr edit body mutation の hook/wrapper 制御が主題です。scope_signal_delta / issue-refinement-loop の親としては意味が合いません。

    同じ agent-ops 系の #1024 は LOOP_STATE builder、#1026 は command registry で、#1027 はそれらと並ぶ「scope_signal 差分ベース化」slot に見えます。#1024 も Remaining Parent Gaps で scope_signal 差分分類を別 Issue として扱っており、#1026 も scope_signal guard 変更を Out of Scope にしています。

    修正要求: parent_issue を実際の agent-ops rollup に直すか、standalone として related_issues: [1024, 1026, 1028, 920, 1090] を明示してください。現状のままだと、contract lineage / Remaining Parent Gaps / stop condition の解釈が壊れます。


    2. before/current/after の SoT が未定義

    #1027 は「before/current/after のハッシュと差分行」を要求していますが、3 つの本文がどこから来るのかを定義していません。現行 run_refinement_preflight.py は repair dry-run を実行しても、planner には original Issue body を渡す設計です。

    このままでは実装者が次のどれを after とみなすべきか判断できません。

    • issue-author が提案した rewrite 後 body
    • repair_issue_contract.py の dry-run result
    • GitHub 上の current issue body
    • preflight fixture 内の proposed body
    • planner 実行時に main thread が保持しているローカル draft

    修正要求: scope_signal_delta.py の入力契約を固定してください。最低限、以下のように明示すべきです。

    SCOPE_SIGNAL_DELTA_INPUT_V1:
      before_body: string        # rewrite 前の canonical issue body
      current_body: string       # GitHub/current snapshot body
      after_body: string         # proposed rewrite body
      source_refs:
        before: artifact path or issue comment id
        current: issue url/hash
        after: artifact path or rewrite result id

    after_body を production preflight から生成するなら、#1027 の Allowed Paths には run_refinement_preflight.py か rewrite producer 側が必要です。Allowed Paths を増やせないなら、#1027 は scope_signal_delta.py の純粋 CLI + planner integration に限定し、after は fixture/stdin から受ける契約にしてください。


    3. Artifact schema がないため #1090 が消費できない

    #1090 は #1027 を blocked_by にしており、new_allowed_path_layer を runtime / docs / skill / hook / agent / test などへ lane split する前提として、#1027 の差分ベース診断を要求しています。

    しかし #1027 は scope_signal_delta artifact を追加するとだけ書いており、schema_version、必須 field、互換性、legacy reason_code との関係を固定していません。これでは #1090 側が安定して consume できません。

    修正要求: Allowed Paths に schema を追加してください。

    + .claude/skills/issue-refinement-loop/schemas/scope_signal_delta_v1.schema.json

    推奨する最小 schema は次です。

    schema_version: scope_signal_delta/v1
    inputs:
      before_body_sha256: string
      current_body_sha256: string
      after_body_sha256: string
      source_refs:
        before: string | null
        current: string | null
        after: string | null
    sections:
      allowed_paths:
        before: []
        current: []
        after: []
        added: []
        removed: []
        repeated_existing: []
      in_scope:
        before_layers: []
        after_layers: []
        added_layers: []
        repeated_existing_layers: []
      acceptance_criteria:
        added_low_verifiability_items: []
    signals:
      - reason_code: new_allowed_path_layer | new_in_scope_area | new_unverifiable_ac
        triggered: boolean
        normalized_value: string
        triggering_lines:
          - body_version: before | current | after
            start_line: integer
            end_line: integer
            text_sha256: string
    legacy_scope_signal_guard:
      triggered: boolean
      reason_code: string
      excluded_by_anchor_reframe: boolean
    suppressions:
      anchor_reframe:
        status: approved_by_trusted_anchor | not_applicable | fail_closed
        implementation_go: false

    JSON Schema で allOf などの composition を使う場合、additionalProperties: false は subschema をまたぐ拡張と衝突しやすいため、Draft 2019-09 以降の unevaluatedProperties: false を検討すべきです。(JSON Schema)


    4. 現行 guard の置換単位が曖昧

    現行 plan_refinement_loop.py は _detect_scope_signals(issue_body, known_context) を直接呼び、scope_signal_guard.triggered/reason_code/excluded_by_anchor_reframe を組み立てています。

    #1027 は「scope 判定を差分ベース API 経由へ移行」と書いていますが、次が未定義です。

    • _detect_scope_signals を削除するのか
    • _detect_scope_signals が scope_signal_delta.py の library API を呼ぶのか
    • scope_signal_delta.py は CLI 専用なのか、import 可能 module なのか
    • legacy scope_signal_guard 出力を誰が生成するのか
    • diff artifact は planner output に埋め込むのか、artifact path 参照にするのか

    修正要求: production path は次のように固定してください。

    plan_refinement_loop.py
      -> import scope_signal_delta
      -> compute SCOPE_SIGNAL_DELTA_V1 from before/current/after
      -> derive legacy scope_signal_guard projection
      -> expose full delta as artifact path or decisions.scope_signal_delta
    

    CLI は --help と stdin/stdout の deterministic interface を持つべきですが、planner が shell out する設計は避けるべきです。planner 内部で subprocess を挟むと、失敗分類と artifact hash が複雑になります。


    5. Anchor reframe の境界を壊す危険がある

    #920 / PR #1119 後の current repo では、trusted anchor は run_refinement_preflight.py が GitHub issue comment を取得し、author_association、target repo/issue、schema validation を見たうえで known_context.scope_delta_decision に正規化する構造になっています。

    scope-signal-guard.md も、trusted anchor は implementation_go=false で、contract review / refinement preflight / allowed_paths_gate の再実行が必要だと明記しています。

    #1027 の AC4 は「anchor が明示的に再フレーム許可している場合のみ excluded_by_anchor_reframe=true」とだけ書いています。これだと実装者が plan_refinement_loop.py で raw comment body を再 parse し、#920 の raw-body 境界を破る危険があります。

    修正要求: AC4 を次のように狭めてください。

    AC4: `excluded_by_anchor_reframe=true` は、
    `known_context.scope_delta_decision.status == "approved_by_trusted_anchor"` かつ
    `implementation_go == false` かつ `required_rerun` を保持している場合だけ出る。
    `plan_refinement_loop.py` / `scope_signal_delta.py` は raw anchor comment body を読まない。

    GitHub issue comments API は body だけでなく issue_url と author_association を返します。trusted 判定はこの API metadata を SoT にすべきで、コメント本文の自己申告を信じる設計に戻してはいけません。([GitHub Docs]2)


    6. #1090 との責務境界が危ない

    #1090 は #1027 完了後に new_runtime_path_layer / new_skill_or_docs_layer / new_hook_or_agent_layer / missing_scope_delta_approval へ lane split する Issue です。#1090 のレビューコメントでも、path prefix だけで lane 分類すると false positive を再発させると指摘されています。

    #1027 がやるべきことは lane split ではなく、lane split 可能な normalized delta facts を出すことです。

    #1027 側で出すべきもの:

    added_allowed_paths:
      - ".claude/skills/issue-refinement-loop/scripts/scope_signal_delta.py"
    added_top_level_prefixes:
      - ".claude"
    repeated_existing_allowed_paths:
      - ".claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py"
    has_new_layer: true

    #1090 側に残すべきもの:

    path_layer: runtime | docs | skill | hook | agent | test_fixture | unknown
    route: proceed_with_notes | human_judgment_required | block
    security_risk_gate_required: boolean

    この分離を #1027 本文に入れないと、#1027 が #1090 の lane split まで先取りして scope creep します。


    実装品質に関する外部調査ベースの改善点

    差分判定は unified diff 文字列ではなく、正規化 set/opcode で行う

    Python difflib は human-friendly な差分生成に向いていますが、SequenceMatcher は最小 edit script を保証しないうえ、繰り返し要素に対する heuristic があります。unified_diff は人間向け evidence としては有用ですが、判定ロジックの唯一の SoT にすべきではありません。([Python documentation]3)

    推奨:

    before_paths = normalize_allowed_paths(before_body)
    after_paths = normalize_allowed_paths(after_body)
    
    added = sorted(after_paths - before_paths)
    repeated = sorted(after_paths & before_paths)
    removed = sorted(before_paths - after_paths)
    
    triggered = bool(added_layer_set)

    difflib.unified_diff(..., n=0 or 3, lineterm="") は artifact の human_diff として残す程度に留めるべきです。

    Git-like artifact を出すなら patch 適用可能性を主張しない

    Git の diff --git a/file b/file 形式は traditional unified diff と細部が異なり、rename/copy/path quoting などもあります。#1027 の artifact が Git patch ではなく issue body section diff なら、git diff compatible と主張しない方が安全です。([Git]4)

    推奨 field:

    human_unified_diff:
      format: difflib_unified_diff
      patch_apply_semantics: false

    JSON は load/dump の両方で strict にする

    Python json.dumps(..., allow_nan=False, sort_keys=True) は regression artifact に適しています。読み込み側では parse_constant を使って NaN / Infinity / -Infinity を reject できます。([Python documentation]5)

    現行 plan_refinement_loop.py は decode 後に NaN/Infinity を再帰検査していますが、parse_constant を使えば decode 時点で fail-closed にできます。


    追加すべき fixture

    最低限、次の fixture が必要です。

    fixture 期待
    existing_allowed_path_repeated.json 既存 path 再掲は triggered=false
    allowed_paths_reordered.json 並び替えのみは triggered=false
    allowed_paths_whitespace_only.json 空白・bullet 形式変更のみは triggered=false
    new_allowed_path_same_layer.json 同一 layer 内の追加をどう扱うか明示
    new_allowed_path_new_layer.json new_allowed_path_layer
    mixed_existing_and_new_layers.json repeated と added を両方 artifact に出す
    fenced_code_mentions_path.json fenced code 内の path は section path として扱わない
    markdown_table_allowed_paths.json table/list の path 抽出を固定
    anchor_trusted_suppresses_signal.json trusted anchor ありで excluded_by_anchor_reframe=true
    anchor_fail_closed_does_not_suppress.json untrusted/wrong issue は suppress しない
    json_nan_rejected.json NaN/Infinity は input validation error
    orchestrator_no_auto_scope_rewrite.json scope_signal 時に In Scope/Allowed Paths を自動修正しない

    特に最後の AC5 は plan_refinement_loop.py 単体では証明しにくいです。scope-signal-guard.md は orchestrator が planner output を consume するだけで判定を再実装しない、scope 拡張を自動承認しない、と明記しています。

    Allowed Paths を増やせないなら、AC5 は「既存 policy に対する regression assertion」に弱めるか、別 Issue に分割してください。


    Verification Commands の問題

    #1027 の現行 Verification Commands は AC と対応していません。

    • AC2 の command が scope_signal_delta.py --help になっており、「before 既存 layer を new 扱いしない fixture」の検証になっていません。
    • AC3 は plan_refinement_loop.py < input_existing_layers.json だけで、stdout の reason_code / triggered assertion がありません。
    • AC5 の pnpm typecheck/lint/test/build は repo-wide gate であり、「orchestrator が In Scope を自動修正しない」証明にはなりません。

    推奨:

    uv run pytest .claude/skills/issue-refinement-loop/tests/test_scope_signal_delta.py -q
    
    uv run python3 .claude/skills/issue-refinement-loop/scripts/scope_signal_delta.py \
      < .claude/skills/issue-refinement-loop/tests/fixtures/scope_signal_delta/input_existing_layers.json \
      | jq -e '.legacy_scope_signal_guard.triggered == false'
    
    uv run python3 .claude/skills/issue-refinement-loop/scripts/scope_signal_delta.py \
      < .claude/skills/issue-refinement-loop/tests/fixtures/scope_signal_delta/input_new_layer.json \
      | jq -e '.legacy_scope_signal_guard.reason_code == "new_allowed_path_layer"'
    
    uv run pytest .claude/skills/issue-refinement-loop/tests/test_plan_refinement_loop.py \
      -q -k "scope_signal_delta or anchor_reframe"
    
    uv run pytest .claude/skills/issue-refinement-loop/tests/test_scope_signal_guard_termination.py -q

    repo-wide gates は最後に残してよいですが、AC の primary evidence にしてはいけません。


    そのまま貼れる修正版レビューコメント案

    ## 判定
    
    REQUEST_CHANGES。
    
    #1027 の方向性は正しいです。現行 `plan_refinement_loop.py` の scope_signal_guard は before/current/after 差分を見ず、Allowed Paths / In Scope の prefix 数や語彙だけで `new_allowed_path_layer` / `new_in_scope_area` を出すため、既存 layer 再掲で false positive を起こし得ます。
    
    ただし、現契約のまま実装すると別の不整合を作ります。
    
    ### Blockers
    
    1. Parent contract が破綻しています。
       - Machine-Readable Contract は `parent_issue: "none"`。
       - 本文の Parent Issue は `#964`。
       - #964 は PR body hygiene / update_pr wrapper の Issue で、scope_signal_delta の親として不適切です。
       - 実 parent / rollup を明示するか、standalone + related_issues に直してください。
    
    2. `before/current/after` の SoT が未定義です。
       - before/current/after body が GitHub snapshot、rewrite draft、repair dry-run、fixture のどれなのか不明です。
       - `SCOPE_SIGNAL_DELTA_INPUT_V1` を定義し、各 body hash と source_ref を必須にしてください。
    
    3. `scope_signal_delta` artifact schema がありません。
       - `schema_version`
       - before/current/after hashes
       - normalized section deltas
       - added / removed / repeated_existing
       - triggering_lines
       - legacy `scope_signal_guard` projection
       - anchor suppression status
       を固定してください。
       - Allowed Paths に `schemas/scope_signal_delta_v1.schema.json` を追加すべきです。
    
    4. #920 の trusted anchor 境界を壊さないでください。
       - `plan_refinement_loop.py` / `scope_signal_delta.py` は raw anchor comment body を parse してはいけません。
       - `known_context.scope_delta_decision.status == approved_by_trusted_anchor` のみを consume してください。
       - trusted anchor でも `implementation_go=false` と `required_rerun` は維持してください。
    
    5. #1090 との責務を分けてください。
       - #1027 は normalized delta facts を出す。
       - runtime/docs/skill/hook/agent lane split と route decision は #1090 に残す。
       - #1027 で lane split まで実装すると scope creep です。
    
    6. AC5 は現在の Allowed Paths では証明困難です。
       - orchestrator が In Scope を自動修正しないことを本当に保護するなら、rewrite/orchestrator 側の test path が必要です。
       - Allowed Paths を増やせないなら、AC5 を policy/reference regression に弱めるか、別 Issue に分割してください。
    
    ### Required contract changes
    
    - `SCOPE_SIGNAL_DELTA_INPUT_V1` と `SCOPE_SIGNAL_DELTA_V1` を追加する。
    - `scope_signal_delta.py` は read-only、stdin JSON、stdout canonical JSON、no GitHub mutation とする。
    - `plan_refinement_loop.py` は旧 prefix-count 判定ではなく `scope_signal_delta` の library API を consume する。
    - `new_allowed_path_layer` は `after.allowed_path_layers - before.allowed_path_layers` が非空の場合のみ出す。
    - 既存 layer の再掲、並び替え、空白差分、fenced code 内の path mention は signal にしない。
    - trusted anchor は normalized `known_context.scope_delta_decision` のみで判定し、raw comment body を planner/delta に渡さない。
    
    この修正なしで実装すると、false positive 解消ではなく、scope_signal_guard / anchor reframe / #1090 lane split の境界破壊になります。

    結論

    #1027 は 必要だが、契約修正が先 です。特に修正すべきは、親子関係、before/current/after の入力契約、SCOPE_SIGNAL_DELTA_V1 schema、#920 trusted anchor 境界、#1090 との責務分離です。

    現行のまま実装すると、new_allowed_path_layer の false positive を減らす目的に対して、artifact 非互換・anchor bypass・scope creep のリスクが高いです。

  3. squne121 commented on Jul 1, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  4. squne121 commented on Jul 1, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-07-01T21:45:57Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1027
      body_sha256: "sha256:185ac3054e8f5b1ed9477e8ccaedbc92cf3e63e57898f8c4540bba5794050f59"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: ensure_contract_snapshot_auto
  5. squne121 commented on Jul 2, 2026

    @squne121
    OwnerAuthor

    PR #1276 のマージに伴う post-merge cleanup を完了したためクローズします。dedicated worktree は既に消えており、残っていた local branch も canonical cleanup 経路で削除済みです。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions