Skip to content

調査: preflight.run command registry に anchor-comment-url の受け口がない #1492

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: research
parent_issue: "none"
goal_ref: "root canonical preflight.run 経路(決定論的 skill runtime executor 経由)で anchor comment を指定した issue-refinement-loop 実行を、command registry の正規 placeholder を通じて行えるようにする"
change_kind: research-only

Parent Issue

none(単独改善)

Outcome

.claude/skills/issue-refinement-loop/scripts/command_registry.py の ISSUE_REFINEMENT_COMMAND_REGISTRY_V1["preflight.run"] に anchor_comment_url(複数指定可能)を安全に受け渡す方式の調査結果が本 Issue 本文に記載され、採用方針(registry 側 placeholder スキーマの拡張方法、repeatable 引数の表現方法、既存 render_command() / validate_shell_string() 契約との整合性)を確定した implementation Issue が起票され、本 Issue がそれを link している状態。

In Scope

  • command_registry.py の preflight.run エントリの placeholders に anchor_comment_url(0 個以上・複数指定可能)を追加する場合の設計選択肢の調査(例: argv テンプレートでの repeatable placeholder 表現方法、positional/variadic 型を _validate_placeholder_value にどう追加するか)
  • render_command() が現在 1 placeholder = 1 argv token 前提で書かれている実装(for token in entry["argv"] の単純トークン置換)が、--anchor-comment-url URL1 --anchor-comment-url URL2 ... のような repeatable フラグをどう扱えるかの技術調査
  • run_refinement_preflight.py 側の --anchor-comment-url(action="append", dest="anchor_comment_urls")の既存契約を変更せずに registry 側だけで解決できるか、両方の変更が必要かの判定
  • 既存の preflight.run 呼び出し元(root 経路 / 決定論的 skill runtime executor 経由)が --anchor-comment-url を渡せないことによる実害範囲の特定(他の privileged command でも同様の repeatable-placeholder gap があるかの横断確認を含む)

Out of Scope

  • command_registry.py / run_refinement_preflight.py の実コード変更(実装は本調査結果をもとに起票する implementation Issue で行う)
  • 決定論的 skill runtime executor(scripts/agent-guards/ 配下)の unauthorized-write 誤検知(bytecode cache 問題)。これは既存 Issue 実装: root preflight の bytecode cache 誤検知を防止する #1439(実装: root preflight の bytecode cache 誤検知を防止する)が扱う別 concern であり、本 Issue では扱わない
  • preflight.run 以外の command の new placeholder 追加(横断確認は行うが、変更は行わない)

Acceptance Criteria

  • AC1: command_registry.py の preflight.run placeholders に repeatable な anchor_comment_url を追加する場合の実装方式(案A/案B等)が比較され、採用案が本 Issue 本文に記載されている
  • AC2: 採用案を実装する implementation Issue が起票され、本 Issue がそれを link している
  • AC3: 本 Issue は close 可能、もしくは追加調査要件が明示されている

Verification Commands

# AC1
$ gh issue view THIS_ISSUE_NUMBER --json body
# AC2
$ gh issue view NEW_IMPLEMENTATION_ISSUE_NUMBER
# AC3
$ gh issue view THIS_ISSUE_NUMBER --json state,body

Allowed Paths

  • 読み取り専用。リポジトリ変更なし(既定)

Stop Conditions

  • Outcome / Scope / AC が検索可能な形で記載されていない場合は即停止
  • Allowed Paths 外への書き込みを試みた場合は即停止
  • 権限不足(permission denied)により操作が完了できない場合は即停止
  • 成果物の書き込みに失敗した場合(I/O エラー等)は即停止

Handoff Contract

  • Current Objective
  • Bounded Current Context
  • Open Questions
  • Next Action
  • Artifact Refs

Background

Issue #1386 に対して issue-refinement-loop を実行しようとした際、以下の再現手順で判明した:

uv run python3 scripts/agent-guards/skill_runtime_exec.py --command-id preflight.run --issue-number 1386 --repo squne121/loop-protocol

上記コマンドに anchor comment(人間の Decision コメント等)を指定したい場合、.claude/skills/issue-refinement-loop/scripts/command_registry.py の REGISTRY["preflight.run"]["placeholders"] は issue_number と repo のみを許可しており、--anchor-comment-url を追加パラメータとして渡すと render_command() の Extra params not defined for command 「preflight.run」 で拒否される。

一方、run_refinement_preflight.py 自体は --anchor-comment-url(dest="anchor_comment_urls", action="append")を既にサポートしている(.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py:2524-2529)。つまり実行対象スクリプトは anchor comment 指定に対応済みだが、skill_runtime_exec.py が要求する正規の command registry 経由の呼び出し経路には、その受け口が存在しない。

なお、同じ調査セッションで scripts/agent-guards/skill_runtime_exec.py の bytecode cache 誤検知(unauthorized_write_path, target=.claude/skills/issue-refinement-loop/scripts/__pycache__/plan_refinement_loop.cpython-312.pyc)も観測されたが、これは既存 OPEN Issue #1439 が同一 concern を扱っているため本 Issue のスコープには含めない。

Notes for Reviewer

  • render_command() は現状 1 placeholder = 1 argv token の単純置換実装であり、repeatable な --anchor-comment-url URL を複数回追加する機能は registry スキーマに存在しない。調査時に variadic placeholder 表現の要否を判断すること。
  • 横断確認の結果、他の command にも同様の repeatable-placeholder gap があった場合は、本 Issue の Out of Scope 通り実装はせず、調査結果として記載するに留める。

調査結果・採用判断

現行契約の再確認

  • render_command("preflight.run", {"issue_number": ..., "repo": ..., "anchor_comment_url": ...}) は command_registry.py の render_command() の extra_params チェックにより ValueError: Extra params not defined for command 'preflight.run': ['anchor_comment_url'] で拒否される(.claude/skills/issue-refinement-loop/scripts/command_registry.py の render_command() 実装、placeholders に anchor_comment_url が存在しないため)。
  • scripts/agent-guards/skill_runtime_exec.py の argparse.ArgumentParser は --command-id / --issue-number / --repo / --fixture のみを定義しており、--anchor-comment-url は未定義引数のため argparse レベルで即座に拒否される。加えて skill_runtime_command_policy.py の parse_exact_skill_runtime_command() はトークン数10個への厳密一致(uv run python3 <exec> --command-id <id> --issue-number <n> --repo <repo>)であり、--anchor-comment-url を追加すると即座にトークン数不一致で None を返し拒否される。
  • run_refinement_preflight.py に異なる anchor URL を2件(--anchor-comment-url URL1 --anchor-comment-url URL2)渡すと、_validate_anchor_comments_batch() が dedupe 後 len(sorted_urls) > 1 で BLOCKER_ANCHOR_COMMENT_MULTIPLE_UNSUPPORTED を返し blocked になる(.claude/skills/issue-refinement-loop/tests/test_anchor_comment_multiple_urls.py::test_multiple_anchor_comment_urls_are_blocked_fail_closed で固定済み)。同一URLの重複投入はこの dedupe ロジックにより単一URL扱いへ収束する(duplicate と distinct-multiple は別区分)。
  • command_registry.py の preflight.run エントリの argv / placeholders(issue_number, repo の2つのみ)は PR fix: preflight provenance の pyc 生成を防止する #1444(Issue 実装: root preflight の bytecode cache 誤検知を防止する #1439 Scope Delta 2)マージ後も一切変更されていない。同 PR で追加された preflight.run.fixture は preflight.run を汎用化・拡張したものではなく、独立した sibling exact profile(別 execution_class: exact_skill_runtime_fixture、別 argv テンプレート、skill_runtime_command_policy.py に別関数 parse_exact_skill_runtime_fixture_command / is_exact_skill_runtime_fixture_executor_command)として実装されている。この設計を今回の anchor_comment_url 対応の前例として採用する。

cardinality と duplicate policy

  • 現行 run_refinement_preflight.py の --anchor-comment-url(action="append")は複数回指定を argparse レベルでは許容するが、業務契約としては 0..1 件のみが有効であり、2件以上の異なる URL は fail-closed で拒否される(ANCHOR_COMMENT_MULTIPLE_UNSUPPORTED)。action="append" は実装上の受け口が repeatable であることを意味するだけで、業務カーディナリティが複数を意味するものではない。
  • 同一 URL の重複指定は _validate_anchor_comments_batch() の seen_urls dedupe により単一 URL として扱われる(後方互換のため既存動作を維持)。
  • 本 Issue が新規追加する command_registry.py / skill_runtime_command_policy.py の preflight.run.with_anchor exact profile は、--anchor-comment-url を required scalar(1個のみ、repeatable でない)として固定 argv に埋め込む。これにより新しい実行経路ではそもそも複数指定という入力形状自体が構文的に成立しない(cardinality 0..1 を argv shape レベルで強制する)。

実装方式の比較

方式 概要 判定
A. dedicated exact profile(preflight.run.with_anchor) preflight.run は無変更のまま、anchor_comment_url を扱う新しい sibling exact command-id を registry / policy / executor に追加する。PR #1444 の preflight.run.fixture と同型の設計。 採用
B. registry V2 optional-segment / variadic placeholder 汎用化 render_command() の argv テンプレートに optional token 除去や repeatable placeholder 展開を一般化する。 不採用。render_command() は他の多数の command(plan.run 等)と契約を共有する共通関数であり、汎用化は攻撃面と回帰リスクを全 command に波及させる。Issue #1439 の Stop Conditions でも production preflight.run の固定契約変更・registry の汎用化は明示的に禁止されており、同じ理由でこの Issue でも production 契約を変更しない dedicated profile 方式を踏襲する。

採用案は A. dedicated exact profile。registry のみの修正では、skill_runtime_exec.py の exact-match executor 層(parse_exact_skill_runtime_command() のトークン数固定チェック)を通過できないため、registry・policy・executor の3層すべてに sibling entry を追加する必要がある。

validate_shell_string() について

validate_shell_string() は untrusted shell 文字列を検査する関数であり、registry-generated argv(render_command() の戻り値である list[str])の production path では使用されていない(skill_runtime_exec.py は subprocess.run(child_argv, shell=False, ...) で list[str] を直接実行する)。今回の変更の主要な対象ではなく、変更しない。

URL 検証の責務分担

層 責務
registry(command_registry.py) canonical GitHub issue comment URL の構文検証(新設する github_issue_comment_url placeholder type)。https://github.com/{owner}/{repo}/issues/{number}#issuecomment-{id} の厳密な shape のみを許可し、query / extra fragment / trailing slash / userinfo / port / 非 https / 非 github.com host / pull request review comment URL / discussion_r 形式を拒否する。
executor(skill_runtime_command_policy.py の新設パーサ) URL 内の owner/repo と issue 番号を、CLI 引数の --repo / --issue-number に束縛(一致検証)する。不一致は fail-closed で拒否する。
wrapper(run_refinement_preflight.py、既存) GitHub API(または --fixture 経由のオフライン fixture)で実際にそのコメントが対象 issue に存在し、issue に属していることを再検証する(既存の _validate_anchor_comment_url / ANCHOR_NOT_IN_ISSUE 相当のロジックを維持)。

既存前例

Issue #1439 / PR #1444(マージ済み)は、production preflight.run の固定契約を一切変更せず、test-only sibling exact profile preflight.run.fixture を command_registry.py / skill_runtime_command_policy.py / skill_runtime_exec.py の3層に追加することで、real executor → real preflight → real planner の subprocess chain を deterministic に検証した。本 Issue が採用する preflight.run.with_anchor(production)の設計は、この前例の構造(sibling profile、production 契約不変、専用 parser/validator 関数)を踏襲する。

consumer inventory

  • .claude/skills/issue-refinement-loop/scripts/command_registry.py(producer: REGISTRY, render_command())
  • scripts/agent-guards/skill_runtime_command_policy.py(SKILL_RUNTIME_COMMAND_POLICY_V2["eligible_command_ids"], parse_exact_skill_runtime_command(), _EXPECTED_ARGV_BY_COMMAND, _EXPECTED_PLACEHOLDERS_BY_COMMAND, validate_registry_entry())
  • scripts/agent-guards/skill_runtime_exec.py(main() の command-id 分岐、_validate_runtime_context())
  • .claude/hooks/worktree_scope_guard.py(_is_skill_runtime_executor_command()。現状 is_exact_skill_runtime_executor_command のみを呼び、is_exact_skill_runtime_fixture_executor_command は呼んでいない=test-only profile はそもそも hook allow 対象外。production の anchor profile はこの hook にも新規許可を追加する必要がある)
  • scripts/agent-guards/local_main_branch_guard.py(_is_skill_runtime_executor_command()。同様に production executor command のみを consume。anchor profile 用の許可を同様に追加する必要がある)
  • tests/codex/test_local_main_branch_guard.py(Claude/Codex parity test)
  • .claude/settings.json(permissions.allow の exact Bash allowlist。現在 preflight.run のみ許可されており、preflight.run.fixture は許可されていない=test-only なので agent の直接呼び出し経路には現れない。anchor profile は agent が直接呼ぶ想定のため新規 allow entry が必要)
  • .claude/skills/issue-refinement-loop/SKILL.md(呼び出し例のドキュメント)
  • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py(既存の --anchor-comment-url CLI 引数・単数契約は維持するが、help text の「複数指定可能」という誤解を招く表現を修正する)

Implementation Issue

採用設計を実装する implementation Issue として Issue #1498(実装: preflight.run に anchor comment 対応の sibling exact profile (preflight.run.with_anchor) を追加する, #1498 )を起票し、本 Issue にリンクした。

Acceptance Criteria の状態

AC1(実装方式比較・採用案記載)、AC2(implementation Issue 起票・リンク)は本更新で満たす。AC3(close 可能)は implementation Issue 起票・リンク後に満たされる。

Activity

  1. added
    phase/research
    state/queued
    agent/research
    on Jul 13, 2026
  2. squne121 commented on Jul 13, 2026

    @squne121
    OwnerAuthor

    判定: REQUEST_CHANGES

    Issue #1492 が発見した「canonical preflight.run 経路から anchor comment を渡せない」という不具合自体は正しいです。ただし、現在の Issue は次の二点を誤認しています。

    1. run_refinement_preflight.py は複数 anchor を実質的にはサポートしていない

    2. 修正対象は command registry だけではなく、privileged exact executor の認可境界全体

    このまま implementation Issue を起票すると、既存の単数-anchor契約を意図せず破壊するか、registryだけ更新しても実際には呼び出せない実装になります。なお、Issue #1492 自体にコメントはありません。

    P0-1: action="append" を「複数anchor対応」と解釈している

    確かにCLI parserは action="append" で、同じオプションを複数回受け取ってリストへ格納します。Python公式でも、append は各出現値をリストへ追加する構文上の収集機能です。アプリケーションが複数値を受理することまでは保証しません。 (Python documentation)

    現行実装は、重複排除・ソート後に異なるURLが2件以上あれば、即座に ANCHOR_COMMENT_MULTIPLE_UNSUPPORTED でblockします。専用回帰テストも、2件のanchor URLを必ず拒否する契約を固定しています。

    さらに、下流契約もすべて単数です。

    • SKILL.md の入力は単数 anchor_comment_url

    • LOOP_STATE は anchor_comment オブジェクト1件

    • anchor handling文書も単数snapshot、単数classificationを前提

    これは偶発的な制限ではありません。PR #1043で「複数URLはfail-closed」という契約が意図的に導入されています。

    修正要求: Issue #1492は最初にcardinalityを確定してください。

    • 推奨: 0..1件を維持

    • 0..N件を本当に実装する場合: registry改善ではなく、wrapper、LOOP_STATE、schema、planner input、artifact、分類処理を変更するbreaking contract Issueへ分離

    「複数指定可能」という記述は、現行契約を維持するなら削除が必要です。


    P0-2: registryだけを変更してもexact executorから値が到達しない

    現在の preflight.run registry entryは、issue_number と repo の2placeholderしか持ちません。

    しかし、より重大なのはregistryの外側です。

    skill_runtime_exec.py は以下の3オプションしか受け付けません。

    --command-id
    --issue-number
    --repo
    

    さらに render_command() へ渡すparamsも issue_number と repo だけです。

    認可ポリシー側も、

    • token数を厳密に10個へ固定

    • flag位置を固定

    • dataclassにanchor fieldがない

    • registry argv templateを完全一致で固定

    • placeholder集合を完全一致で固定

    しています。

    Claude Codeのpermission ruleも、--repo squne121/loop-protocol で終了する現在の形だけをallowしています。

    したがって、正しい判定は次です。

    run_refinement_preflight.py の単数anchor処理は既に存在する。
    必須変更は registry + executor + exact-command policy + permission/hook/test parity である。

    最低限のconsumer inventoryは以下です。

    .claude/skills/issue-refinement-loop/scripts/command_registry.py
    scripts/agent-guards/skill_runtime_exec.py
    scripts/agent-guards/skill_runtime_command_policy.py
    .claude/settings.json
    .claude/skills/issue-refinement-loop/tests/test_command_registry.py
    scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py
    .claude/hooks/tests/test_worktree_scope_guard.py
    .claude/hooks/tests/test_local_main_branch_guard.py
    tests/codex/test_local_main_branch_guard.py
    .claude/skills/issue-refinement-loop/SKILL.md
    docs/dev/agent-skill-boundaries.md
    docs/dev/hook-boundaries.md
    

    実際にexecutor参照はこれらのsettings、docs、Claude/Codex guard testsへ広がっています。


    P0-3: required: false を足すだけではoptional flagにならない

    現在のrendererは、registryの各template tokenを必ず1個の出力tokenへ変換します。値が与えられていないoptional placeholderを削除する処理はありません。

    そのため、例えば次のように追加しても、

    "argv": [
        ...,
        "--anchor-comment-url",
        "{anchor_comment_url}",
    ],
    "placeholders": {
        "anchor_comment_url": {
            "type": "url",
            "required": False,
        },
    },
    

    anchor未指定時には、次のliteral tokenが残ります。

    --anchor-comment-url
    {anchor_comment_url}
    

    未解決placeholderの検出も required: true のwhole-tokenしかerrorにしないため、optional placeholderはそのまま返ります。

    既存の decide.run にも、optionalと宣言されながらargv内に常駐する max_iterations、phase_state_file があり、同じ潜在問題を抱えています。

    つまり必要なのは単なる variadic 型追加ではありません。

    • optionalな flag + valueグループ

    • 反復する flag + valueグループ

    • 未指定時のグループ全体削除

    • cardinality

    • duplicate policy

    • canonical ordering

    • placeholder 1件から複数argv tokenを生成する規則

    を表現するschemaが必要です。

    この一般化を行うなら、ISSUE_REFINEMENT_COMMAND_REGISTRY_V1 の意味変更として扱い、V2 schemaへ更新すべきです。現在のテストはregistry templateを list[str] として固定しています。


    P0-4: validate_shell_string() は主要な設計対象ではない

    Issue #1492は validate_shell_string() との整合性を調査対象に含めていますが、registry-generated argvはproductionでこの関数を通りません。

    現行テストにも、registry argvは subprocess(..., shell=False) へ直接渡され、validate_shell_string() はstring入力用であると明記されています。

    Python公式も、外部コマンドには文字列ではなくargument sequenceを渡す方式を推奨しており、shell の既定値は False です。(Python documentation)

    したがって重点はshell文字列検査ではなく、以下です。

    • argvの固定形

    • exact command class

    • context binding

    • URLの意味検証

    • unknown・duplicate・省略flagのfail-closed

    validate_shell_string() をvariadic placeholder対応へ拡張する必要はありません。


    P0-5: 既存のurl placeholder型は認可境界として弱すぎる

    registryの現在の url validatorは、非空文字列かつ https:// で始まることしか確認しません。

    一方、wrapperはより厳格です。

    • GitHub issue comment URLの完全なshape

    • owner/repo一致

    • issue番号一致

    • comment ID

    • PR review commentとの区別

    • REST APIでcommentを取得

    • responseの issue_url が対象Issueと一致

    GitHub REST APIも、comment取得を owner、repo、comment_id に束縛し、responseに html_url、issue_url、author_association 等を返します。(GitHub Docs)

    実装Issueでは、汎用 url ではなく次のようなdomain typeが必要です。

    github_issue_comment_url
    

    責務分離は次が妥当です。

    • registry: URLのcanonical shapeを検証

    • executor: URL内のrepo/issueを現在の repo / issue_number へ束縛

    • wrapper: GitHub REST responseで存在と所属を再検証


    推奨設計

    採用推奨: 単数anchorを維持し、exact command profileを分ける

    既存V1 rendererを一般化せず、固定argvの別command IDを追加する案が最も安全です。

    "preflight.run.with_anchor": {
        "argv": [
            "uv", "run", "python3",
            ".claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py",
            "--issue-number", "{issue_number}",
            "--repo", "{repo}",
            "--anchor-comment-url", "{anchor_comment_url}",
        ],
        "placeholders": {
            "issue_number": {
                "type": "positive_int",
                "required": True,
            },
            "repo": {
                "type": "owner_repo",
                "required": True,
            },
            "anchor_comment_url": {
                "type": "github_issue_comment_url",
                "required": True,
            },
        },
    }
    

    これにより、

    • anchorなし: preflight.run

    • anchorあり: preflight.run.with_anchor

    という2つの完全固定command classになります。

    利点は以下です。

    • registry V1の「固定 list[str]」を維持

    • optional token削除処理が不要

    • generic variadic rendererを増やさない

    • exact policyで10-token profileと12-token profileを別々に検証可能

    • 既存の単数 LOOP_STATE.anchor_comment と整合

    • 既存のmultiple-anchor fail-closed契約を維持

    Issue #1492の「同一 preflight.run entryへ追加」というgoalは変更になりますが、#1154で確立されたdeny-by-defaultのexact executor設計にはこちらの方が適合します。

    同じcommand IDを必須とするなら、registry V2でoptional argument groupを正式に設計してください。required:false のscalar placeholder追加だけでは不可です。


    P1: exact CLIではoption abbreviationも禁止すべき

    skill_runtime_exec.py とwrapperは通常の ArgumentParser() を使っています。Pythonの argparse は既定で、曖昧でないlong optionの省略形を許可します。 (Python documentation)

    privileged exact commandでは次を明示すべきです。

    argparse.ArgumentParser(
        ...,
        allow_abbrev=False,
    )
    

    これにより、例えば以下を拒否できます。

    --anchor-comment-u
    --issue-n
    

    公式ドキュメントでも allow_abbrev=False によってlong option prefix matchingを無効化できます。(Python documentation)


    P1: ACとVerification Commandsが調査品質を証明していない

    現在のACは、

    • 比較結果が本文にある

    • implementation Issueを作る

    • close可能である

    だけです。

    Verification Commandsも gh issue view で本文やstateを見るだけなので、調査内容が正しいことを一切証明しません。

    少なくとも次のACへ置き換えるべきです。

    - [ ] AC1: 現行契約が anchor 0..1 であり、異なる2 URLが
          ANCHOR_COMMENT_MULTIPLE_UNSUPPORTED になる証跡を記載する
    - [ ] AC2: registryへ未知paramを渡した場合と、exact executorへ追加flagを
          渡した場合の両方のbaseline rejectionを記録する
    - [ ] AC3: registry、executor、command policy、settings、Claude/Codex hook tests、
          docsを含むconsumer inventoryを記載する
    - [ ] AC4: dedicated command ID案とregistry V2 optional-segment案を比較し、
          compatibility decisionを確定する
    - [ ] AC5: URL shape validation、repo/issue context binding、REST再検証の
          責務分離を確定する
    - [ ] AC6: implementation Issueにexact argv、Allowed Paths、negative matrix、
          schema version decisionを記載する
    - [ ] AC7: Issue #1439との変更ファイル競合とmerge順序を明記する
    

    必須negative matrix

    ケース | 期待結果 -- | -- anchorなし | 既存 preflight.run を許可 正しいanchor 1件 | 許可 異なるanchor 2件 | 現行契約では拒否 同一URLの重複 | 重複を拒否、またはcanonical dedupeを明文化 他repoのURL | 拒否 他IssueのURL | 拒否 PR #discussion_r... | 拒否 query・余分なfragment・末尾文字列付きURL | 拒否 --anchor-comment-url=URL | exact形でないなら拒否 option省略形 | 拒否 flagのみで値なし | 拒否 unknown extra flag | 拒否 flag順序変更 | exact policyに従い拒否 guardとexecutorの判定不一致 | テスト失敗 Claude/Codex側の認可差異 | テスト失敗

    配列契約を導入する場合は、cardinalityとduplicate policyを文章だけでなく maxItems と uniqueItems 相当で機械的に固定すべきです。JSON Schemaではこれらが配列長と一意性の標準的な制約です。(JSON Schema)


    #1439との関係

    bytecode cache誤検知を別concernとしてOut of Scopeにした判断は正しいです。

    ただし #1439と今回のimplementationは、ともに以下へ触れる可能性があります。

    scripts/agent-guards/skill_runtime_exec.py
    .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py
    

    #1439自身も、canonical argv、command registry、exact-command policyの変更が必要なら停止する契約です。したがって、#1492から起票するimplementation Issueには、#1439との依存関係、merge順序、rebase後の回帰コマンドを明記する必要があります。

    最終結論

    Issue #1492は、問題発見は正しいが、研究契約は修正必須です。

    最も安全な着地点は次です。

    現行の単数anchor契約を維持する。
    generic variadic placeholderは導入しない。
    anchorなし/anchorありを別のexact command profileとして登録する。
    registryだけでなくexecutor、command policy、permission、Claude/Codex parity testsを同一implementation Issueで更新する。

    現行本文の「0個以上・複数指定可能」と「registry側だけで解決可能か」という表現は、そのまま採用すべきではありません。

    # 判定: **REQUEST_CHANGES**

    Issue #1492 が発見した「canonical preflight.run 経路から anchor comment を渡せない」という不具合自体は正しいです。ただし、現在の Issue は次の二点を誤認しています。

    1. run_refinement_preflight.py は複数 anchor を実質的にはサポートしていない
    2. 修正対象は command registry だけではなく、privileged exact executor の認可境界全体

    このまま implementation Issue を起票すると、既存の単数-anchor契約を意図せず破壊するか、registryだけ更新しても実際には呼び出せない実装になります。なお、Issue #1492 自体にコメントはありません。

    P0-1: action="append" を「複数anchor対応」と解釈している

    確かにCLI parserは action="append" で、同じオプションを複数回受け取ってリストへ格納します。Python公式でも、append は各出現値をリストへ追加する構文上の収集機能です。アプリケーションが複数値を受理することまでは保証しません。 ([Python documentation]1)

    現行実装は、重複排除・ソート後に異なるURLが2件以上あれば、即座に ANCHOR_COMMENT_MULTIPLE_UNSUPPORTED でblockします。専用回帰テストも、2件のanchor URLを必ず拒否する契約を固定しています。

    さらに、下流契約もすべて単数です。

    • SKILL.md の入力は単数 anchor_comment_url

    • LOOP_STATE は anchor_comment オブジェクト1件

    • anchor handling文書も単数snapshot、単数classificationを前提

    これは偶発的な制限ではありません。PR #1043で「複数URLはfail-closed」という契約が意図的に導入されています。

    修正要求: Issue #1492は最初にcardinalityを確定してください。

    • 推奨: 0..1件を維持
    • 0..N件を本当に実装する場合: registry改善ではなく、wrapper、LOOP_STATE、schema、planner input、artifact、分類処理を変更するbreaking contract Issueへ分離

    「複数指定可能」という記述は、現行契約を維持するなら削除が必要です。


    P0-2: registryだけを変更してもexact executorから値が到達しない

    現在の preflight.run registry entryは、issue_number と repo の2placeholderしか持ちません。

    しかし、より重大なのはregistryの外側です。

    skill_runtime_exec.py は以下の3オプションしか受け付けません。

    --command-id
    --issue-number
    --repo
    

    さらに render_command() へ渡すparamsも issue_number と repo だけです。

    認可ポリシー側も、

    • token数を厳密に10個へ固定
    • flag位置を固定
    • dataclassにanchor fieldがない
    • registry argv templateを完全一致で固定
    • placeholder集合を完全一致で固定

    しています。

    Claude Codeのpermission ruleも、--repo squne121/loop-protocol で終了する現在の形だけをallowしています。

    したがって、正しい判定は次です。

    run_refinement_preflight.py の単数anchor処理は既に存在する。
    必須変更は registry + executor + exact-command policy + permission/hook/test parity である。

    最低限のconsumer inventoryは以下です。

    .claude/skills/issue-refinement-loop/scripts/command_registry.py
    scripts/agent-guards/skill_runtime_exec.py
    scripts/agent-guards/skill_runtime_command_policy.py
    .claude/settings.json
    .claude/skills/issue-refinement-loop/tests/test_command_registry.py
    scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py
    .claude/hooks/tests/test_worktree_scope_guard.py
    .claude/hooks/tests/test_local_main_branch_guard.py
    tests/codex/test_local_main_branch_guard.py
    .claude/skills/issue-refinement-loop/SKILL.md
    docs/dev/agent-skill-boundaries.md
    docs/dev/hook-boundaries.md
    

    実際にexecutor参照はこれらのsettings、docs、Claude/Codex guard testsへ広がっています。


    P0-3: required: false を足すだけではoptional flagにならない

    現在のrendererは、registryの各template tokenを必ず1個の出力tokenへ変換します。値が与えられていないoptional placeholderを削除する処理はありません。

    そのため、例えば次のように追加しても、

    "argv": [
        ...,
        "--anchor-comment-url",
        "{anchor_comment_url}",
    ],
    "placeholders": {
        "anchor_comment_url": {
            "type": "url",
            "required": False,
        },
    },

    anchor未指定時には、次のliteral tokenが残ります。

    --anchor-comment-url
    {anchor_comment_url}
    

    未解決placeholderの検出も required: true のwhole-tokenしかerrorにしないため、optional placeholderはそのまま返ります。

    既存の decide.run にも、optionalと宣言されながらargv内に常駐する max_iterations、phase_state_file があり、同じ潜在問題を抱えています。

    つまり必要なのは単なる variadic 型追加ではありません。

    • optionalな flag + valueグループ
    • 反復する flag + valueグループ
    • 未指定時のグループ全体削除
    • cardinality
    • duplicate policy
    • canonical ordering
    • placeholder 1件から複数argv tokenを生成する規則

    を表現するschemaが必要です。

    この一般化を行うなら、ISSUE_REFINEMENT_COMMAND_REGISTRY_V1 の意味変更として扱い、V2 schemaへ更新すべきです。現在のテストはregistry templateを list[str] として固定しています。


    P0-4: validate_shell_string() は主要な設計対象ではない

    Issue #1492は validate_shell_string() との整合性を調査対象に含めていますが、registry-generated argvはproductionでこの関数を通りません。

    現行テストにも、registry argvは subprocess(..., shell=False) へ直接渡され、validate_shell_string() はstring入力用であると明記されています。

    Python公式も、外部コマンドには文字列ではなくargument sequenceを渡す方式を推奨しており、shell の既定値は False です。([Python documentation]2)

    したがって重点はshell文字列検査ではなく、以下です。

    • argvの固定形
    • exact command class
    • context binding
    • URLの意味検証
    • unknown・duplicate・省略flagのfail-closed

    validate_shell_string() をvariadic placeholder対応へ拡張する必要はありません。


    P0-5: 既存のurl placeholder型は認可境界として弱すぎる

    registryの現在の url validatorは、非空文字列かつ https:// で始まることしか確認しません。

    一方、wrapperはより厳格です。

    • GitHub issue comment URLの完全なshape

    • owner/repo一致

    • issue番号一致

    • comment ID

    • PR review commentとの区別

    • REST APIでcommentを取得

    • responseの issue_url が対象Issueと一致

    GitHub REST APIも、comment取得を owner、repo、comment_id に束縛し、responseに html_url、issue_url、author_association 等を返します。([GitHub Docs]3)

    実装Issueでは、汎用 url ではなく次のようなdomain typeが必要です。

    github_issue_comment_url
    

    責務分離は次が妥当です。

    • registry: URLのcanonical shapeを検証
    • executor: URL内のrepo/issueを現在の repo / issue_number へ束縛
    • wrapper: GitHub REST responseで存在と所属を再検証

    推奨設計

    採用推奨: 単数anchorを維持し、exact command profileを分ける

    既存V1 rendererを一般化せず、固定argvの別command IDを追加する案が最も安全です。

    "preflight.run.with_anchor": {
        "argv": [
            "uv", "run", "python3",
            ".claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py",
            "--issue-number", "{issue_number}",
            "--repo", "{repo}",
            "--anchor-comment-url", "{anchor_comment_url}",
        ],
        "placeholders": {
            "issue_number": {
                "type": "positive_int",
                "required": True,
            },
            "repo": {
                "type": "owner_repo",
                "required": True,
            },
            "anchor_comment_url": {
                "type": "github_issue_comment_url",
                "required": True,
            },
        },
    }

    これにより、

    • anchorなし: preflight.run
    • anchorあり: preflight.run.with_anchor

    という2つの完全固定command classになります。

    利点は以下です。

    • registry V1の「固定 list[str]」を維持
    • optional token削除処理が不要
    • generic variadic rendererを増やさない
    • exact policyで10-token profileと12-token profileを別々に検証可能
    • 既存の単数 LOOP_STATE.anchor_comment と整合
    • 既存のmultiple-anchor fail-closed契約を維持

    Issue #1492の「同一 preflight.run entryへ追加」というgoalは変更になりますが、#1154で確立されたdeny-by-defaultのexact executor設計にはこちらの方が適合します。

    同じcommand IDを必須とするなら、registry V2でoptional argument groupを正式に設計してください。required:false のscalar placeholder追加だけでは不可です。


    P1: exact CLIではoption abbreviationも禁止すべき

    skill_runtime_exec.py とwrapperは通常の ArgumentParser() を使っています。Pythonの argparse は既定で、曖昧でないlong optionの省略形を許可します。 ([Python documentation]1)

    privileged exact commandでは次を明示すべきです。

    argparse.ArgumentParser(
        ...,
        allow_abbrev=False,
    )

    これにより、例えば以下を拒否できます。

    --anchor-comment-u
    --issue-n
    

    公式ドキュメントでも allow_abbrev=False によってlong option prefix matchingを無効化できます。([Python documentation]1)


    P1: ACとVerification Commandsが調査品質を証明していない

    現在のACは、

    • 比較結果が本文にある
    • implementation Issueを作る
    • close可能である

    だけです。

    Verification Commandsも gh issue view で本文やstateを見るだけなので、調査内容が正しいことを一切証明しません。

    少なくとも次のACへ置き換えるべきです。

    - [ ] AC1: 現行契約が anchor 0..1 であり、異なる2 URLが
          ANCHOR_COMMENT_MULTIPLE_UNSUPPORTED になる証跡を記載する
    - [ ] AC2: registryへ未知paramを渡した場合と、exact executorへ追加flagを
          渡した場合の両方のbaseline rejectionを記録する
    - [ ] AC3: registry、executor、command policy、settings、Claude/Codex hook tests、
          docsを含むconsumer inventoryを記載する
    - [ ] AC4: dedicated command ID案とregistry V2 optional-segment案を比較し、
          compatibility decisionを確定する
    - [ ] AC5: URL shape validation、repo/issue context binding、REST再検証の
          責務分離を確定する
    - [ ] AC6: implementation Issueにexact argv、Allowed Paths、negative matrix、
          schema version decisionを記載する
    - [ ] AC7: Issue #1439との変更ファイル競合とmerge順序を明記する

    必須negative matrix

    ケース 期待結果
    anchorなし 既存 preflight.run を許可
    正しいanchor 1件 許可
    異なるanchor 2件 現行契約では拒否
    同一URLの重複 重複を拒否、またはcanonical dedupeを明文化
    他repoのURL 拒否
    他IssueのURL 拒否
    PR #discussion_r... 拒否
    query・余分なfragment・末尾文字列付きURL 拒否
    --anchor-comment-url=URL exact形でないなら拒否
    option省略形 拒否
    flagのみで値なし 拒否
    unknown extra flag 拒否
    flag順序変更 exact policyに従い拒否
    guardとexecutorの判定不一致 テスト失敗
    Claude/Codex側の認可差異 テスト失敗

    配列契約を導入する場合は、cardinalityとduplicate policyを文章だけでなく maxItems と uniqueItems 相当で機械的に固定すべきです。JSON Schemaではこれらが配列長と一意性の標準的な制約です。(JSON Schema)


    #1439との関係

    bytecode cache誤検知を別concernとしてOut of Scopeにした判断は正しいです。

    ただし #1439と今回のimplementationは、ともに以下へ触れる可能性があります。

    scripts/agent-guards/skill_runtime_exec.py
    .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py
    

    #1439自身も、canonical argv、command registry、exact-command policyの変更が必要なら停止する契約です。したがって、#1492から起票するimplementation Issueには、#1439との依存関係、merge順序、rebase後の回帰コマンドを明記する必要があります。

    最終結論

    Issue #1492は、問題発見は正しいが、研究契約は修正必須です。

    最も安全な着地点は次です。

    現行の単数anchor契約を維持する。
    generic variadic placeholderは導入しない。
    anchorなし/anchorありを別のexact command profileとして登録する。
    registryだけでなくexecutor、command policy、permission、Claude/Codex parity testsを同一implementation Issueで更新する。

    現行本文の「0個以上・複数指定可能」と「registry側だけで解決可能か」という表現は、そのまま採用すべきではありません。

  3. squne121 commented on Jul 13, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  4. squne121 commented on Jul 13, 2026

    @squne121
    OwnerAuthor

    調査完了・クローズ

    本 Issue の調査に基づき、採用設計(dedicated exact profile preflight.run.with_anchor、production preflight.run 契約不変)を実装する implementation Issue #1498 を起票し、本 Issue へリンクしました。

    Acceptance Criteria (AC1-AC3) をすべて満たしたため、本 Issue を completed としてクローズします。

    (internal marker: ISSUE_1492_CLOSE_COMMENT_MARKER_V1)

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/researchphase/researchstate/queued

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions