Skip to content

調査: agent-neutral worktree mutation guard input schema の要否を判断する #1663

Closed
2 of 2 issues completed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: research
parent_issue: none
change_kind: research-only
goal_ref: validated runtime adapter と agent-neutral policy-domain contract の実測境界を固定する
evidence_main_sha: 2bbbe239ffcdc5fa129817fda4b51d9dbc23dfb9
implementation_main_sha: bb917a8ef637b8a73921acdf714392c044edda97

Source と実装結果

Outcome

対応済み runtime・version・hook channel に限り、runtime-specific adapter が vendor raw payload を閉じ込め、WORKTREE_MUTATION_INTENT_V1、WORKTREE_SCOPE_BINDING_V1、WORKTREE_POLICY_DECISION_V1 の順で共有 policy-domain に渡す設計を採用します。未測定 runtime、未対応 grammar、trust/load 未確定状態は supported と主張せず、limitation または fail-closed classification とします。

本 Issue は research-only です。追跡コードを変更せず、証跡は .claude/artifacts/issue-refinement-loop/1663/runtime-evidence/ と tmp/issue_1663_* に限定しました。

Parent Issue

なし(単独調査)。#1657 / PR #1662 の post-merge research として開始し、後続 delivery は #1670 / PR #1672 と #1678 / PR #1681 へ分割しました。

In Scope

Out of Scope

Evidence Classification

区分 証跡 意味
official_runtime_wire Claude Write/Edit/Bash、Codex apply_patch/Bash secret-free synthetic Git repository で実 CLI が発火した sanitized wire。raw payload は保存しない。
runtime_generated_sanitized lifecycle matrix 実 runtime 実験の時刻・handler・digest だけを記録する。
synthetic_negative_fixture missing/malformed、legacy alias、Move の回帰 fail-closed の fixture coverage。official wire の代替ではない。
source_code_readback current code / merged PR readback policy と実装の境界確認。

すべての official wire は raw digest、sanitized digest、sanitization version、raw_payload_persisted: false、secret detector pass を持ちます。秘密、credential、実利用者 prompt、環境変数、transcript 本文は artifact に保存していません。

Runtime / Version Matrix

  • Capture base: 2bbbe239ffcdc5fa129817fda4b51d9dbc23dfb9。これは capture 時点の default branch です。実装後 default branch は bb917a8ef637b8a73921acdf714392c044edda97 です。
  • Claude Code: 2.1.218、versioned local launcher、WSL2 Ubuntu 24.04、POSIX path flavor。
  • Codex CLI: 0.145.0、model gpt-5.3-codex-spark、standalone local package、WSL2 Ubuntu 24.04、POSIX path flavor。
  • Python: 3.12.3、Git: 2.43.0、shell: bash、architecture: x86_64。
  • exact executable path は個人ディレクトリを正規化し、hook config SHA-256 とともに runtime-matrix.json に記録します。

ADR Decision

採用するのは version-validated runtime adapter と agent-neutral policy-domain contract の分離です。

  1. Adapter は raw payload の closed validation、canonical tool identity、version check、unsupported/malformed classification を担います。
  2. Adapter は immutable な WORKTREE_MUTATION_INTENT_V1 を出力し、raw vendor DTO を shared policy へ渡しません。
  3. Resolver は bound、verified_unbound、unknown、ambiguous、resolution_failed を区別した WORKTREE_SCOPE_BINDING_V1 を出力します。
  4. Shared policy は intent + binding だけから stable reason code を含む WORKTREE_POLICY_DECISION_V1 を返し、emitter が各 runtime transport へ変換します。

却下した案は、shared core が vendor DTO を直接読む、adapter ごとに authorization policy を持つ、universal raw payload schema、独自 regex を upstream Codex grammar と同値と主張する、binding failure を null に畳み込む、hook を security boundary と扱う、の6件です。完全な ADR は adr-policy-domain.md を正本とします。

No-Issue Semantics

historical claim は「no-Issue 時は Write/Edit deny、Bash allow」でした。capture base の code readback では、Write/Edit は issue_context_required deny、Bash mutation/unknown は no_issue_no_scope allow、Codex canonical apply_patch は verified_unbound の場合に no_issue_no_scope allow でした。これは全状態を一つの None に潰す意味ではありません。

verified_unbound は Git/worktree evidence により scope 適用外と確認済みの状態です。unknown、ambiguous、resolution_failed は別状態であり、同じ allow 根拠にはしません。merged #1672 はこの binding 分離を policy-domain に実装し、#1681 は Claude 2.1.218 の validated identity を追加しました。

Hook Lifecycle Matrix

Claude lifecycle の実験は 2.1.216 capture であり、wire corpus の Claude 2.1.218 と区別します。matching PreToolUse handlers は逐次で、single exit-2 handler 後に unique Write target が存在しないことを確認しました。外側 session exit code は tool decision を直接表しません。

Codex 0.145.0 は official wire capture を得ましたが、変更した二-handler config では lifecycle event が観測されませんでした。trust/load を bypass していないため、これは trust_or_load_state_not_proven と分類します。handler ordering、aggregation、timeout、spawn failure、invalid JSON、competing decisions は未測定です。hook は runtime integration control であり、security boundary、CI、branch protection、repository permission の代替ではありません。

Parser / Path Boundary

  • 実装: launcher command 共有 parser(argv boundary 保持・cwd/project_root 対応)を抽出し全 consumer の invocation contract を移行する #1595: raw Bash command、wrapper、source-word、cwd/project_root の parsing ownership。後続 consumer は公開 API を利用します。
  • Codex: supported version の upstream grammar に依存し、Move は source と destination の両方を評価します。unsupported/malformed grammar を supported と主張しません。
  • Environment ID、effective cwd、path flavor は contract field として保持します。Windows/WSL translation、Move の real runtime wire は未測定であり limitation です。
  • Codex Edit/Write prompt probe は matcher alias ではなく canonical apply_patch wire identity を観測しました。alias 互換と canonical identity を混同しません。

Acceptance Criteria

Runtime Verification Applicability

decision: immediate_and_bounded
applicable_acs: [AC1, AC2, AC5]
execution_environment: "Claude Code 2.1.218 / Codex CLI 0.145.0、WSL2 Ubuntu 24.04、secret-free synthetic Git repository"
skip_conditions: "未測定 runtime/channel/lifecycle は limitation として記録し、supported と主張しない"
artifact_requirements: "schema/version、raw/sanitized digest、secret detector、evidence class、capture timestamp、raw payload non-persistence"
official_runtime_wire:
  claude_code: "2.1.218: Write, Edit, Bash"
  codex_cli: "0.145.0: apply_patch, Bash"
synthetic_negative_fixture:
  coverage: "missing, malformed, legacy alias, Move, binding failures"
not_supported_claims:
  - Claude MultiEdit was not observed
  - Codex lifecycle aggregation/trust-load is unresolved
  - Windows/WSL translation and Move real wire are not measured
fallback_policy: synthetic evidence never substitutes for official runtime wire

Verification Commands

# AC1
# baseline-expect: pass
$ uv run --locked python3 .claude/artifacts/issue-refinement-loop/1663/runtime-evidence/verify_evidence.py

# AC2
# baseline-expect: pass
$ uv run --locked python3 .claude/artifacts/issue-refinement-loop/1663/runtime-evidence/verify_evidence.py

# AC3
# baseline-expect: pass
$ uv run --locked pytest tests/agent_guards/test_worktree_policy_domain.py tests/agent_guards/test_worktree_scope_guard.py tests/agent_guards/test_codex_apply_patch_adapter.py -q

# AC4
# baseline-expect: pass
$ uv run --locked pytest tests/agent_guards/test_worktree_policy_domain.py tests/agent_guards/test_worktree_scope_guard.py tests/agent_guards/test_codex_apply_patch_adapter.py -q

# AC5
# baseline-expect: pass
$ uv run --locked python3 .claude/artifacts/issue-refinement-loop/1663/runtime-evidence/verify_evidence.py

# AC6
# baseline-expect: pass
$ uv run --locked python3 .claude/artifacts/issue-refinement-loop/1663/runtime-evidence/verify_evidence.py

# AC7
# baseline-expect: pass
$ gh issue view 1670 --repo squne121/loop-protocol --json state,url
$ gh issue view 1678 --repo squne121/loop-protocol --json state,url
$ gh issue view 1663 --repo squne121/loop-protocol --json body,updatedAt

Evidence References

  • .claude/artifacts/issue-refinement-loop/1663/runtime-evidence/runtime-matrix.json
  • .claude/artifacts/issue-refinement-loop/1663/runtime-evidence/official-claude-{write,edit,bash}-wire-v2.json
  • .claude/artifacts/issue-refinement-loop/1663/runtime-evidence/official-codex-{apply-patch,bash}-wire-v2.json
  • .claude/artifacts/issue-refinement-loop/1663/runtime-evidence/codex-alias-identity-matrix-v1.json
  • .claude/artifacts/issue-refinement-loop/1663/runtime-evidence/synthetic-negative-coverage-v1.json
  • .claude/artifacts/issue-refinement-loop/1663/runtime-evidence/lifecycle-matrix-v2.json
  • .claude/artifacts/issue-refinement-loop/1663/runtime-evidence/adr-policy-domain.md

Allowed Paths

  • .claude/artifacts/issue-refinement-loop/1663/**
  • tmp/issue_1663_*

Stop Conditions

  • Outcome / Scope / AC が検索可能な形で記載されていない場合は即停止。
  • Allowed Paths 外への書き込みを試みた場合は即停止。
  • 権限不足(permission denied)により操作が完了できない場合は即停止。
  • 成果物の書き込みに失敗した場合(I/O エラー等)は即停止。
  • secret、credential、raw user/runtime payload を表示・保存する必要がある場合。
  • runtime capture を安全に sanitize できない場合。
  • 実装: launcher command 共有 parser(argv boundary 保持・cwd/project_root 対応)を抽出し全 consumer の invocation contract を移行する #1595 の parser responsibility を再実装する必要がある場合。
  • controlled Issue mutation または repository permission が利用不能な場合。

Close Decision

この research scope の AC は上記 evidence set と limitation の明示により完了です。これは全 runtime/channel/lifecycle の parity や security boundary を主張する close ではありません。未対応 runtime/channel は unsupported として残し、hook trust/load の未確定は成功扱いにしません。

Handoff Contract

  • Current Objective: bounded research evidence を close し、実装 delivery の merged readback を残す。
  • Remaining limitations: Claude MultiEdit、Codex lifecycle aggregation/trust-load、Windows/WSL translation、Move real wire は supported と主張しない。
  • Follow-up route: 追加 runtime/version support が必要な場合は 実装: Claude Code 2.1.218 の validated adapter support を追加する #1678 と同じ 1 Issue = 1 PR contract で別 implementation Issue を作成する。

Sub-issues

Sub-issues

2 of 2 Issues completed
Loading 2 sub-issues

Activity

  1. squne121 commented on Jul 20, 2026

    @squne121
    OwnerAuthor

    create-issue transaction partial-failure

    Issue: #1663
    Failure stage: label-apply
    Message: label-apply failed

    Requested:

    • labels: design, worktree-guard, codex-claude-parity
    • parent: (none)
    • dependencies: (none)
      Completed steps: create

    Failure context: command=gh issue edit --repo squne121/loop-protocol 1663 --add-label design,worktree-guard,codex-claude-parity
    output=failed to update #1663: 'design' not found
    failed to update 1 issue
    matching_issue_numbers=[1663]
    issue_number=1663

    Recovery hint: stage 'label-apply' encountered an unexpected failure.
    Generic guidance: verify the issue state manually and re-run the transaction if safe.
    gh issue view 1663 --repo squne121/loop-protocol --json number,title,labels,state
    idempotent re-run: depends on the specific failure

    Please recover deterministically before re-running the create issue transaction.

  2. added
    phase/research
    state/queued
    agent/research
    on Jul 20, 2026
  3. squne121 commented on Jul 22, 2026

    @squne121
    OwnerAuthor

    判定

    REQUEST_CHANGES / NEEDS_MAJOR_REVISION

    Issue #1663 が問い直している方向性自体は妥当です。しかし、現行スコープとAcceptance Criteriaのままでは、「agent-neutral schemaを新設する」か「共有配置+薄いadapterを維持する」かを安全に決定できません。現在の二択は誤っており、実装・配布物・上流仕様を突き合わせると、必要なのは バージョン管理されたruntime別adapterと、agent-neutralなpolicy-domain contractの併用 です。Issue本文はAC1〜AC3で棚卸し、判断、次アクションだけを要求し、検証も実質的にIssue本文の再表示に留まっています。これは設計判断の証拠要件として不足しています。


    主要指摘

    1. Blocker: 「schemaかadapterか」という二択が成立していない

    現行のworktree_scope_guard.pyは、共有ディレクトリへ移動しただけで、依然としてtool_name、tool_input、cwdというhook transportの生DTOを直接読み、Write、Edit、MultiEdit、Bashというruntime由来の名称で分岐しています。つまり、配置は共有化されていますが、policy coreはagent-neutralではありません。

    一方、codex_apply_patch_adapter.pyは単なる薄い変換層ではありません。Codexのpatch文法を独自正規表現で部分的に再実装し、Issue解決、worktree解決、path containment、allow/blockまで実行しています。さらに共有モジュールの公開APIではなく、_allow、_block、_relといったprivate関数にも依存しています。これはtransport adapterではなく、parserとauthorization policyを含む第二のpolicy implementationです。

    したがって設計上の正しい問いは、次です。

    「vendor固有の生payloadをどこで検証・正規化し、どの地点から先を共有policy-domain objectとして扱うか」

    「schemaを作るならadapterは不要」「adapterを維持するならschemaは不要」という関係ではありません。adapterは必要であり、その出力として中立contractも必要です。


    2. Blocker: 現在すでにtool経路ごとの認可split-brainがある

    同じ「ファイルを変更する操作」でも、Issue文脈を解決できなかった場合の判断が統一されていません。

    • Codex apply_patch adapterは、Issueを解決できなければ無条件でallowします。

    • 共有コアのWrite/Edit経路は、Issueがなければissue_context_requiredでdenyします。

    • Bashのmutation/unknown経路は、Issueがなければno_issue_no_scopeでallowします。

    この差は偶発的な未テスト状態ではなく、test_apply_patch_with_no_active_issue_is_allowedとして明示的に契約化されています。

    これはschema形式の問題ではありません。先に次のpolicy invariantを決める必要があります。

    • Issueなしは、検証済みの「scope適用対象外」なのか

    • 単にIssue解決情報が欠落した「不明状態」なのか

    • worktree catalogやGitが利用できない「解決失敗」なのか

    • 複数候補がある「曖昧状態」なのか

    現在はこれらをNoneに潰しているため、context resolution failureがauthorization allowに化け得ます。最低でもbinding状態を次のように分離すべきです。

    bound
    verified_unbound
    unknown
    ambiguous
    resolution_failed
    

    verified_unboundをallowする設計はあり得ます。しかしunknownやresolution_failedを同じallow経路に流してはいけません。


    3. Blocker: Acceptance Criteriaが実runtimeを一切検証しない

    Issue #1663のACは、依存箇所の記載、方針の記載、後続Issueのリンクだけです。Verification Commandsもgh issue view Nであり、実装上の前提が正しいかを検証しません。

    PR #1662で追加されたテストも、実Codex CLIから得たpayloadではありません。テストヘルパーがCLAUDE_PROJECT_DIRとLOOP_ISSUE_NUMBERを人工的に注入し、tool_name、tool_input、cwdを手作業で組み立てています。これは関数単体の回帰テストとしては有効ですが、配布物のwire contract、hook trust、matcher alias、cwd、version driftを証明しません。

    研究Issueでコード変更を行わないこと自体は問題ありません。しかし少なくとも、以下の実測証拠が必要です。

    • 対象Claude Codeバージョンから取得したsanitized PreToolUse stdin

    • 対象Codex CLI/Codex Appバージョンから取得したsanitized PreToolUse stdin

    • tool call、matcher、hook stdin上のtool_nameの対応表

    • exit 0/exit 2/timeout/spawn failure/invalid JSON output時の実挙動

    • linked worktree、main checkout、別worktreeでのcwdとproject root

    • runtimeがproject hookを実際にtrust・loadしていることの証跡

    単なるfixture成功を「runtime parity verified」と扱うべきではありません。


    4. Blocker: CodexのEdit/Write理解が現在の実装契約と異なる

    現在のCodex本体では、hook stdinへ直列化されるcanonical tool nameはapply_patchです。WriteとEditはhook matcher選択用のcompatibility aliasにすぎず、hook processへ渡されるtool_nameを変更しません。上流実装も「aliasをstable payload nameとして直列化してはならない」と明示しています。

    したがって、.codex/hooks.jsonの^(apply_patch|Edit|Write)$ matcher自体は互換性のために妥当ですが、adapter内のtool_name == "Edit"/"Write"経路は、少なくとも現行Codexの正式wire contractでは通りません。

    にもかかわらず、repository testは人工的なEdit/Write payloadを生成し、そのdelegationを検証しています。これは実runtimeとのconformance testではありません。

    さらに現行Claude Code公式tool一覧にはEditとWriteはありますが、MultiEditは掲載されていません。過去または特定distributionで存在した可能性はありますが、Issue #1663はruntime versionを固定せずにMultiEditを恒久的な比較軸として扱っています。バージョン証跡なしにこの前提を採用すべきではありません。 (Claude)

    必要なのは、次の区別です。

    canonical tool identity
    matcher compatibility aliases
    legacy tool names
    repository-defined synthetic names
    

    これらを同じtool_name集合として扱うと、実際には到達不能な分岐を保守し続けることになります。


    5. Blocker: 入力schemaだけではhookのfail-closed性を保証できない

    repositoryの境界文書は、Claude側hookについて「secret → local_main → worktree」という順序を記述しています。

    しかしClaude Code公式仕様では、同一eventでmatchingしたhookは並列実行され、あるhookのdenyが他のhookの開始を防ぐわけではありません。Codex本体もFuturesUnorderedでmatching handlersを同時実行し、完了後に表示順へ並べ直しているだけです。 (code.claude.com)

    つまり、現在の「順序」は表示上・設定上の並びであり、authorization pipelineの逐次順序ではありません。worktree guardがdenyしても、session recordingやadvisoryなどのsibling hookはすでに開始しています。これは必ずしも脆弱性ではありませんが、「前段guardが後段hookの実行を防ぐ」という設計前提にはできません。

    さらにCodex hook engineでは、次の場合にhook runはFailedになりますが、tool callをblockしません。

    • hook processの起動・実行エラー

    • exit code 2以外の非ゼロ終了

    • invalid JSON output

    • unsupported output fields

    • hook inputのserialization failure

    実際にblockになるのは、正常なdeny JSON、または非空stderrを伴うexit 2など、限定された場合です。serialization failureのoutcomeもshould_block: falseです。

    またCodexのproject-local hookはtrust状態に依存し、内容変更後のhashが未承認であれば実行されないことがあります。 (OpenAI Developers)

    したがって、「adapter内部でmalformed inputをexit 2にする」ことと、「配布物全体がfail-closedである」ことは別です。repository文書自身も、hookをセキュリティ境界ではなくlocal guardrailと位置付けています。

    Issue #1663はinput schemaだけでなく、次のlifecycle contractを対象に含める必要があります。

    • matcher selection

    • concurrent execution

    • project trust

    • command resolution

    • stdin serialization

    • timeout

    • process spawn failure

    • exit-code mapping

    • stdout JSON validation

    • duplicate/competing decisions

    • runtime version compatibility


    6. High: Codex patch parserを正規表現で再実装しており、上流grammarとの同値性がない

    現adapterは次の4種類のheaderだけを正規表現で拾います。

    Add File
    Update File
    Delete File
    Move to
    

    patch全体の境界、hunk構造、headerの位置、Environment ID、path conventionなどは検証しません。

    一方、現行Codex本体は専用parserを使用し、正式grammarとして以下を扱います。

    • *** Begin Patch/*** End Patch

    • optional *** Environment ID

    • Add/Delete/Update/Move

    • lenient marker whitespace

    • parsed hunks

    • environment ID

    • effective cwdを基準にしたpath resolution

    Codex実行系はparserが生成した構造化変更からsource pathとmove destinationの双方を取得します。

    現adapterと上流parserが同じtarget集合を生成するという証明も、差分テストもありません。この状態では上流grammar変更時に、以下のどちらかが発生します。

    • 実行可能なpatchをadapterが誤って拒否する

    • adapterが抽出したpath集合と、実行系が解釈するpath集合が食い違う

    安全側の過剰拒否だけで済む保証はありません。特にremote/cross-platform environmentでは、adapter hostのos.pathと、実行先environmentのpath semanticsが異なり得ます。

    対応は次のいずれかが必要です。

    1. 対応Codex version/commitを固定し、そのgrammarに対するdifferential corpus testを持つ

    2. 上流parser相当のversioned parserを依存物として利用する

    3. Codex側が将来structured target listをhook payloadへ提供するなら、それを正式入力とする

    現状の独自regexを「薄いadapter」と呼ぶべきではありません。


    7. High: Codexのmulti-environmentとeffective cwdがモデル化されていない

    現行Codex sourceは、multi-environment modeではpatch grammarにEnvironment IDを含められる設計です。

    実際のpatch処理ではEnvironment IDから対象environmentを選択し、そのenvironmentのfilesystemとcwdに対してpathを解決・適用します。

    一方、PreToolUse hookへ渡されるcwdはturn_context.cwdであり、hook payloadのcanonical tool nameとraw patch textを使ってhandlerが起動されます。

    現adapterはpatch中のEnvironment IDを無視し、hook envelopeの単一cwdだけで全pathを解決します。この差が現在の対象distributionで実際に有効化されているかは別途version確認が必要ですが、少なくとも上流sourceが対応している実行モードをIssue #1663は扱っていません。

    結論を出す前に、次のどちらかを明記すべきです。

    • 対象を「single local environmentの特定Codex CLI version」に限定する

    • schemaへenvironment_id、effective_cwd、filesystem_identity、path_flavorを含める

    前者を選ぶ場合も、非対応モードをfail-closedに拒否する必要があります。


    8. High: Issue #1595との責務境界・依存関係が不十分

    Issue #1595は、raw commandを一度だけlexし、cwdとproject_rootを明示入力に取り、複数consumerで同じimmutable invocationを共有するlauncher parserを所有しています。Issue #1657自身も、#1595がこの責務を持つことを明記していました。

    Issue #1663はまさに、hook入力を中立化し、cwd/project root/mutation targetをどの層で正規化するかを判断するIssueです。したがって#1595は単なる「関連Issue」ではなく、少なくとも設計上のdependencyまたはhard boundaryです。

    特にBash経路について、新しいschema側で再度shell command解析を定義すると、#1595と直接競合します。推奨される分担は次です。

    #1595
      raw shell command
        -> parsed launcher / command classification / target evidence
    

    #1663 follow-up
    runtime-specific hook payload
    -> normalized mutation intent
    -> shared worktree policy

    #1663のコメントでは親・依存ともなしとして作成されており、現在ある唯一のコメントもlabel付与失敗のtransaction reportだけです。設計依存の記録はまだありません。


    9. High: CLAUDE_PROJECT_DIR、.claude/worktrees/、tool nameを同列の「Claude依存」として扱っている

    CLAUDE_PROJECT_DIRは現行実装では必須入力ではなく、存在しなければ共有script自身のfileからrootを求めます。

    また、通常のexpected worktree選択は.claude/worktrees/の固定パスを直接探索するのではなく、git worktree list --porcelain -zのcatalogとbranch/path naming ruleを使っています。

    .claude/worktrees/は少なくともlocal-main scratch例外の除外条件やcleanup policyにも現れます。したがって、これは単純なvendor input fieldではなく、repository layout/policy conventionです。

    Issue #1663では、依存を少なくとも次のカテゴリーへ分けるべきです。

    カテゴリー 例
    Hook transport tool_name, tool_input, cwd, event名
    Runtime identity Claude Code、Codex、version、distribution
    Repository policy Issue branch命名、worktree basename規則
    Git topology linked worktree、primary worktree、common dir
    Repository layout .claude/worktrees/、scratch prefixes
    Authorization context Issue番号、expected worktree、binding evidence

    したがってIssue #1663は、現在のAC2にある二択で結論を出してcloseすべきではありません。本文を改稿し、**「adapterかschemaか」ではなく「adapterと共有policy contractの境界をどこに置くか」**をOutcomeに変更する必要があります。

    # 判定

    REQUEST_CHANGES / NEEDS_MAJOR_REVISION

    Issue #1663 が問い直している方向性自体は妥当です。しかし、現行スコープとAcceptance Criteriaのままでは、「agent-neutral schemaを新設する」か「共有配置+薄いadapterを維持する」かを安全に決定できません。現在の二択は誤っており、実装・配布物・上流仕様を突き合わせると、必要なのは バージョン管理されたruntime別adapterと、agent-neutralなpolicy-domain contractの併用 です。Issue本文はAC1〜AC3で棚卸し、判断、次アクションだけを要求し、検証も実質的にIssue本文の再表示に留まっています。これは設計判断の証拠要件として不足しています。


    主要指摘

    1. Blocker: 「schemaかadapterか」という二択が成立していない

    現行のworktree_scope_guard.pyは、共有ディレクトリへ移動しただけで、依然としてtool_name、tool_input、cwdというhook transportの生DTOを直接読み、Write、Edit、MultiEdit、Bashというruntime由来の名称で分岐しています。つまり、配置は共有化されていますが、policy coreはagent-neutralではありません。

    一方、codex_apply_patch_adapter.pyは単なる薄い変換層ではありません。Codexのpatch文法を独自正規表現で部分的に再実装し、Issue解決、worktree解決、path containment、allow/blockまで実行しています。さらに共有モジュールの公開APIではなく、_allow、_block、_relといったprivate関数にも依存しています。これはtransport adapterではなく、parserとauthorization policyを含む第二のpolicy implementationです。

    したがって設計上の正しい問いは、次です。

    「vendor固有の生payloadをどこで検証・正規化し、どの地点から先を共有policy-domain objectとして扱うか」

    「schemaを作るならadapterは不要」「adapterを維持するならschemaは不要」という関係ではありません。adapterは必要であり、その出力として中立contractも必要です。


    2. Blocker: 現在すでにtool経路ごとの認可split-brainがある

    同じ「ファイルを変更する操作」でも、Issue文脈を解決できなかった場合の判断が統一されていません。

    • Codex apply_patch adapterは、Issueを解決できなければ無条件でallowします。
    • 共有コアのWrite/Edit経路は、Issueがなければissue_context_requiredでdenyします。
    • Bashのmutation/unknown経路は、Issueがなければno_issue_no_scopeでallowします。

    この差は偶発的な未テスト状態ではなく、test_apply_patch_with_no_active_issue_is_allowedとして明示的に契約化されています。

    これはschema形式の問題ではありません。先に次のpolicy invariantを決める必要があります。

    • Issueなしは、検証済みの「scope適用対象外」なのか
    • 単にIssue解決情報が欠落した「不明状態」なのか
    • worktree catalogやGitが利用できない「解決失敗」なのか
    • 複数候補がある「曖昧状態」なのか

    現在はこれらをNoneに潰しているため、context resolution failureがauthorization allowに化け得ます。最低でもbinding状態を次のように分離すべきです。

    bound
    verified_unbound
    unknown
    ambiguous
    resolution_failed
    

    verified_unboundをallowする設計はあり得ます。しかしunknownやresolution_failedを同じallow経路に流してはいけません。


    3. Blocker: Acceptance Criteriaが実runtimeを一切検証しない

    Issue #1663のACは、依存箇所の記載、方針の記載、後続Issueのリンクだけです。Verification Commandsもgh issue view Nであり、実装上の前提が正しいかを検証しません。

    PR #1662で追加されたテストも、実Codex CLIから得たpayloadではありません。テストヘルパーがCLAUDE_PROJECT_DIRとLOOP_ISSUE_NUMBERを人工的に注入し、tool_name、tool_input、cwdを手作業で組み立てています。これは関数単体の回帰テストとしては有効ですが、配布物のwire contract、hook trust、matcher alias、cwd、version driftを証明しません。

    研究Issueでコード変更を行わないこと自体は問題ありません。しかし少なくとも、以下の実測証拠が必要です。

    • 対象Claude Codeバージョンから取得したsanitized PreToolUse stdin
    • 対象Codex CLI/Codex Appバージョンから取得したsanitized PreToolUse stdin
    • tool call、matcher、hook stdin上のtool_nameの対応表
    • exit 0/exit 2/timeout/spawn failure/invalid JSON output時の実挙動
    • linked worktree、main checkout、別worktreeでのcwdとproject root
    • runtimeがproject hookを実際にtrust・loadしていることの証跡

    単なるfixture成功を「runtime parity verified」と扱うべきではありません。


    4. Blocker: CodexのEdit/Write理解が現在の実装契約と異なる

    現在のCodex本体では、hook stdinへ直列化されるcanonical tool nameはapply_patchです。WriteとEditはhook matcher選択用のcompatibility aliasにすぎず、hook processへ渡されるtool_nameを変更しません。上流実装も「aliasをstable payload nameとして直列化してはならない」と明示しています。

    したがって、.codex/hooks.jsonの^(apply_patch|Edit|Write)$ matcher自体は互換性のために妥当ですが、adapter内のtool_name == "Edit"/"Write"経路は、少なくとも現行Codexの正式wire contractでは通りません。

    にもかかわらず、repository testは人工的なEdit/Write payloadを生成し、そのdelegationを検証しています。これは実runtimeとのconformance testではありません。

    さらに現行Claude Code公式tool一覧にはEditとWriteはありますが、MultiEditは掲載されていません。過去または特定distributionで存在した可能性はありますが、Issue #1663はruntime versionを固定せずにMultiEditを恒久的な比較軸として扱っています。バージョン証跡なしにこの前提を採用すべきではありません。 (Claude)

    必要なのは、次の区別です。

    canonical tool identity
    matcher compatibility aliases
    legacy tool names
    repository-defined synthetic names
    

    これらを同じtool_name集合として扱うと、実際には到達不能な分岐を保守し続けることになります。


    5. Blocker: 入力schemaだけではhookのfail-closed性を保証できない

    repositoryの境界文書は、Claude側hookについて「secret → local_main → worktree」という順序を記述しています。

    しかしClaude Code公式仕様では、同一eventでmatchingしたhookは並列実行され、あるhookのdenyが他のhookの開始を防ぐわけではありません。Codex本体もFuturesUnorderedでmatching handlersを同時実行し、完了後に表示順へ並べ直しているだけです。 ([code.claude.com]2)

    つまり、現在の「順序」は表示上・設定上の並びであり、authorization pipelineの逐次順序ではありません。worktree guardがdenyしても、session recordingやadvisoryなどのsibling hookはすでに開始しています。これは必ずしも脆弱性ではありませんが、「前段guardが後段hookの実行を防ぐ」という設計前提にはできません。

    さらにCodex hook engineでは、次の場合にhook runはFailedになりますが、tool callをblockしません。

    • hook processの起動・実行エラー
    • exit code 2以外の非ゼロ終了
    • invalid JSON output
    • unsupported output fields
    • hook inputのserialization failure

    実際にblockになるのは、正常なdeny JSON、または非空stderrを伴うexit 2など、限定された場合です。serialization failureのoutcomeもshould_block: falseです。

    またCodexのproject-local hookはtrust状態に依存し、内容変更後のhashが未承認であれば実行されないことがあります。 ([OpenAI Developers]3)

    したがって、「adapter内部でmalformed inputをexit 2にする」ことと、「配布物全体がfail-closedである」ことは別です。repository文書自身も、hookをセキュリティ境界ではなくlocal guardrailと位置付けています。

    Issue #1663はinput schemaだけでなく、次のlifecycle contractを対象に含める必要があります。

    • matcher selection
    • concurrent execution
    • project trust
    • command resolution
    • stdin serialization
    • timeout
    • process spawn failure
    • exit-code mapping
    • stdout JSON validation
    • duplicate/competing decisions
    • runtime version compatibility

    6. High: Codex patch parserを正規表現で再実装しており、上流grammarとの同値性がない

    現adapterは次の4種類のheaderだけを正規表現で拾います。

    Add File
    Update File
    Delete File
    Move to
    

    patch全体の境界、hunk構造、headerの位置、Environment ID、path conventionなどは検証しません。

    一方、現行Codex本体は専用parserを使用し、正式grammarとして以下を扱います。

    • *** Begin Patch/*** End Patch
    • optional *** Environment ID
    • Add/Delete/Update/Move
    • lenient marker whitespace
    • parsed hunks
    • environment ID
    • effective cwdを基準にしたpath resolution

    Codex実行系はparserが生成した構造化変更からsource pathとmove destinationの双方を取得します。

    現adapterと上流parserが同じtarget集合を生成するという証明も、差分テストもありません。この状態では上流grammar変更時に、以下のどちらかが発生します。

    • 実行可能なpatchをadapterが誤って拒否する
    • adapterが抽出したpath集合と、実行系が解釈するpath集合が食い違う

    安全側の過剰拒否だけで済む保証はありません。特にremote/cross-platform environmentでは、adapter hostのos.pathと、実行先environmentのpath semanticsが異なり得ます。

    対応は次のいずれかが必要です。

    1. 対応Codex version/commitを固定し、そのgrammarに対するdifferential corpus testを持つ
    2. 上流parser相当のversioned parserを依存物として利用する
    3. Codex側が将来structured target listをhook payloadへ提供するなら、それを正式入力とする

    現状の独自regexを「薄いadapter」と呼ぶべきではありません。


    7. High: Codexのmulti-environmentとeffective cwdがモデル化されていない

    現行Codex sourceは、multi-environment modeではpatch grammarにEnvironment IDを含められる設計です。

    実際のpatch処理ではEnvironment IDから対象environmentを選択し、そのenvironmentのfilesystemとcwdに対してpathを解決・適用します。

    一方、PreToolUse hookへ渡されるcwdはturn_context.cwdであり、hook payloadのcanonical tool nameとraw patch textを使ってhandlerが起動されます。

    現adapterはpatch中のEnvironment IDを無視し、hook envelopeの単一cwdだけで全pathを解決します。この差が現在の対象distributionで実際に有効化されているかは別途version確認が必要ですが、少なくとも上流sourceが対応している実行モードをIssue #1663は扱っていません。

    結論を出す前に、次のどちらかを明記すべきです。

    • 対象を「single local environmentの特定Codex CLI version」に限定する
    • schemaへenvironment_id、effective_cwd、filesystem_identity、path_flavorを含める

    前者を選ぶ場合も、非対応モードをfail-closedに拒否する必要があります。


    8. High: Issue #1595との責務境界・依存関係が不十分

    Issue #1595は、raw commandを一度だけlexし、cwdとproject_rootを明示入力に取り、複数consumerで同じimmutable invocationを共有するlauncher parserを所有しています。Issue #1657自身も、#1595がこの責務を持つことを明記していました。

    Issue #1663はまさに、hook入力を中立化し、cwd/project root/mutation targetをどの層で正規化するかを判断するIssueです。したがって#1595は単なる「関連Issue」ではなく、少なくとも設計上のdependencyまたはhard boundaryです。

    特にBash経路について、新しいschema側で再度shell command解析を定義すると、#1595と直接競合します。推奨される分担は次です。

    #1595
      raw shell command
        -> parsed launcher / command classification / target evidence
    
    #1663 follow-up
      runtime-specific hook payload
        -> normalized mutation intent
        -> shared worktree policy
    

    #1663のコメントでは親・依存ともなしとして作成されており、現在ある唯一のコメントもlabel付与失敗のtransaction reportだけです。設計依存の記録はまだありません。


    9. High: CLAUDE_PROJECT_DIR、.claude/worktrees/、tool nameを同列の「Claude依存」として扱っている

    CLAUDE_PROJECT_DIRは現行実装では必須入力ではなく、存在しなければ共有script自身の__file__からrootを求めます。

    また、通常のexpected worktree選択は.claude/worktrees/の固定パスを直接探索するのではなく、git worktree list --porcelain -zのcatalogとbranch/path naming ruleを使っています。

    .claude/worktrees/は少なくともlocal-main scratch例外の除外条件やcleanup policyにも現れます。したがって、これは単純なvendor input fieldではなく、repository layout/policy conventionです。

    Issue #1663では、依存を少なくとも次のカテゴリーへ分けるべきです。

    カテゴリー 例
    Hook transport tool_name, tool_input, cwd, event名
    Runtime identity Claude Code、Codex、version、distribution
    Repository policy Issue branch命名、worktree basename規則
    Git topology linked worktree、primary worktree、common dir
    Repository layout .claude/worktrees/、scratch prefixes
    Authorization context Issue番号、expected worktree、binding evidence

    単にrg CLAUDE_PROJECT_DIRやrg Writeを実行するだけでは、この区別を得られません。


    10. High: project_rootの意味が曖昧で、Git worktreeのroot概念が混在している

    共有コアの冒頭コメントには、linked worktree内のgit rev-parse --show-toplevelがmain repository rootを返すため使わない、という説明が残っています。

    しかしrepositoryのtestkitはこの説明が事実と逆であり、linked worktree自身のtoplevelを返すと訂正しています。

    Gitの仕様上も、--show-toplevelは現在のworking treeのtop-levelを返します。 (Git)

    さらに現行.codex/hooks.jsonは、実際にgit rev-parse --show-toplevelを使ってhook scriptの位置を決めています。linked worktreeから呼ばれれば、linked worktree内のscriptを実行します。

    この不整合は単なるdocstring typoではありません。project_rootという名称が、次のどれを指すのか曖昧であることを示しています。

    • 現在のworking tree root
    • primary worktree root
    • shared Git repository identity
    • policy artifactのroot
    • hook scriptが配置されたcheckout root

    中立contractでは、少なくとも次を分けるべきです。

    checkout_root
    repository_common_dir
    primary_worktree_root
    cwd
    expected_worktree_root
    

    同一文字列project_rootへ押し込めるべきではありません。


    11. Medium: 「agent-neutral」の主張範囲が定義されていない

    現在guardが登録されているmutation channelは、Claude側ではBash|Write|Edit|MultiEdit、Codex側ではBashとapply_patch系matcherです。

    したがって、達成可能なのは「対応済みbuilt-in mutation channels間のpolicy parity」です。あらゆるagent、MCP tool、extension tool、外部process、直接filesystem accessを含む普遍的なworktree security boundaryではありません。

    IssueのOutcomeは次のように限定すべきです。

    対応runtime・対応version・対応hook event・対応mutation channelについて、同一mutation intentと同一scope bindingが同一policy decisionになる。

    repository文書が既に明記しているとおり、hookはセキュリティ境界ではありません。branch protection、CI、repository permissionなどの別層を代替しないこともOutcomeへ残す必要があります。


    推奨設計

    採用すべき第三案

    「validated runtime adapters + agent-neutral policy-domain contract」

    WORKTREE_GUARD_INPUT_V1をClaude/Codexのraw hook payloadの最大公約数として作る案は推奨しません。vendor envelopeをそのまま共通schemaにすると、runtime固有の曖昧さや将来のpayload変更を共有コアへ持ち込みます。

    代わりに、以下の4層に分けるべきです。

    1. Runtime adapter

    runtime/version固有の責務だけを持たせます。

    • raw payload schema validation
    • canonical tool identityの決定
    • matcher aliasの正規化
    • path syntaxの検証
    • mutation targetの抽出
    • unsupported version/modeの拒否
    • sanitized diagnostics

    この層はClaude用、Codex用に別々で構いません。

    2. Mutation intent

    agent-neutralな操作表現です。

    schema: WORKTREE_MUTATION_INTENT_V1
    source:
      runtime: codex
      runtime_version: "..."
      distribution: cli
      hook_event: PreToolUse
      canonical_tool: apply_patch
    
    execution:
      cwd: "/..."
      checkout_root: "/..."
      repository_common_dir: "/..."
      environment_id: null
      path_flavor: posix
    
    mutation:
      kind: patch
      parse_status: parsed
      targets:
        - role: source
          resolved_path: "/.../old.py"
        - role: destination
          resolved_path: "/.../new.py"

    raw patch本文やraw shell commandを共有policy objectへ常時保持する必要はありません。parser/adapterで検証後、policyに必要な最小限のevidenceだけを渡します。

    3. Scope binding

    Issueとworktreeの対応を独立したobjectにします。

    schema: WORKTREE_SCOPE_BINDING_V1
    state: bound
    issue_number: 1663
    expected_worktree_root: "/..."
    evidence:
      issue_source: explicit_env
      worktree_source: git_worktree_catalog
      branch_match: true
      basename_match: true

    stateは少なくとも次を区別します。

    bound
    verified_unbound
    unknown
    ambiguous
    resolution_failed
    

    4. Policy decision

    policy coreはvendor payloadを一切見ず、MutationIntent + ScopeBindingだけを評価します。

    schema: WORKTREE_POLICY_DECISION_V1
    decision: deny
    reason_code: mutation_outside_expected_worktree
    policy_version: WORKTREE_POLICY_V1

    runtime adapterはこのdecisionを各hook runtimeのexit code/JSON outputへ変換します。policy core自身がsys.exit()を呼ぶ設計は避けるべきです。


    Issue #1663に追加すべきAcceptance Criteria

    AC1: Runtime version matrix

    対象とする以下の正確なversion/commit/distribution/OSを本文に固定する。

    • Claude Code
    • Codex CLIまたはCodex App
    • Python
    • Git
    • POSIX/Windows path semantics

    「latest」は不可です。

    AC2: Official-wire evidence

    各runtimeから実際に取得したsanitized hook payloadをartifact化する。

    • Claude Bash
    • Claude Edit
    • Claude Write
    • Claude MultiEditは対象versionが実際に生成する場合のみ
    • Codex Bash
    • Codex apply_patch
    • Codex matcher alias経由
    • malformed payload
    • missing field

    fixtureはこのcaptureから生成し、手書きpayloadだけで完結させない。

    AC3: Mutation equivalence matrix

    同一mutation intentに対し、runtimeに依存せず同じdecision/reason codeになることを検証する。

    • expected worktree内
    • main checkout
    • 別Issue worktree
    • verified no-Issue context
    • Issue context unknown
    • Git unavailable
    • worktreeなし
    • worktree複数
    • relative path
    • absolute path
    • .. traversal
    • symlink escape
    • move source/destination
    • parser unsupported/malformed

    AC4: No-Issue semantics

    verified_unboundとunknownを分離し、各状態のallow/deny方針を本文に固定する。現在のapply_patch/Write/Bashの不一致を解消する。

    AC5: Hook lifecycle matrix

    以下についてClaudeとCodexの挙動を記録する。

    • hooksの並列実行
    • exit 0
    • exit 2
    • その他のexit code
    • empty stderr
    • invalid JSON stdout
    • timeout
    • process spawn failure
    • input serialization failure
    • untrusted/changed project hook
    • competing updatedInput/deny

    AC6: Parser ownership

    Bash command parsingは#1595のcontractを再利用し、#1663 follow-upで別parserを実装しない。

    Codex patch parsingは、対象versionの上流grammarとのdifferential testを要求する。Environment ID、path convention、Moveの両側を含める。

    AC7: Scope limitation

    「対応runtime・version・tool channelのlocal guardrail」であり、セキュリティ境界ではないことを明記する。未対応mutation channelを列挙する。

    AC8: Architecture decision record

    結論をIssue本文の一文だけで終わらせず、次を含むADR相当の設計結果を残す。

    • considered options
    • rejected options
    • normalization boundary
    • policy boundary
    • failure semantics
    • migration plan
    • compatibility policy
    • versioning policy

    AC9: Follow-up issue split

    少なくとも次の責務は分離する。

    1. neutral domain contractとpolicy core抽出
    2. Claude adapter移行
    3. Codex adapter移行とpatch parser conformance
    4. live runtime/trust/failure conformance tests

    AC10: Verification evidence

    gh issue viewだけをverificationにしない。実payload capture、differential test、decision matrix、live smokeのartifact pathとdigestを記録する。


    最終的な採用判断

    現時点で採るべき判断は次です。

    選択肢 判断
    Claude/Codexのraw hook envelopeをそのまま共通化するWORKTREE_GUARD_INPUT_V1 却下
    現行の「共有配置+薄いadapter」を変更せず維持 却下。adapterは既に薄くなく、policy split-brainがある
    runtime別validated adapterの後段にagent-neutral policy-domain contractを置く 採用
    hookを完全なセキュリティ境界として扱う 却下
    対応version/tool channelを限定したlocal guardrail parityとして扱う 採用

    したがってIssue #1663は、現在のAC2にある二択で結論を出してcloseすべきではありません。本文を改稿し、**「adapterかschemaか」ではなく「adapterと共有policy contractの境界をどこに置くか」**をOutcomeに変更する必要があります。

  4. squne121 commented on Jul 22, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Human Escalation Required

    The loop has terminated and requires human review. Cause: human judgment required

    Blockers

    "reviewer_false_positive_suspected"
    
    "VCP_UNEXPECTED_PASS は execute readiness で検出されたが、parent replay taxonomy では unknown_blocker_type / checker_gap と判定された"
    
    "同一本文・同一 blocker の再レビューでも同じ checker_gap が連続したため、本文を自動編集せず停止した"
    
    "判断依頼: baseline-expect: pass 注記を本文へ追加するか、VCP_UNEXPECTED_PASS を parent replay の決定論的 taxonomy に接続するかを決定する"
    
  5. squne121 commented on Jul 22, 2026

    @squne121
    OwnerAuthor

    Refinement Blocker Resolved

    前回の human-escalation で報告した VCP_UNEXPECTED_PASS は、AC1 の read-only Verification Command に baseline expectation が未指定だったことが原因でした。

    対応済み:

    • AC1 の直前へ # baseline-expect: pass を追加
    • controlled transaction による本文更新と live readback を確認
    • 更新後 body hash: sha256:37ef25950b7939868492aae6faddd20bd9cc6decf5d76b03c9d5247df3ab029e
    • independent issue review: approve
    • contract review (execute): go、VC preflight: 7 件すべて expected_pass

    前回の escalation は解消済みです。本 Issue は research-only として OPEN を維持し、本文記載の evidence/ADR と後続 implementation Issue の作業を続行できます。

  6. removed
    state/queued
    on Jul 23, 2026
  7. squne121 commented on Jul 23, 2026

    @squne121
    OwnerAuthor

    Research Close Evidence

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/research

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions