Skip to content

実装: Claude/Codex agent parity linter を拡張し出力 schema 名・permission・delegation 制約の drift を検出する #799

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#791"
goal_ref: "agent ops の token/context 浪費を決定論的 preflight / compact contract / hook 規律で削減する"
change_kind: workflow

Parent Issue

#791

Parent Goal Ref

Current Validated Scope

  • 既存 scripts/check_claude_codex_agent_parity.py を拡張する(責務 / 出力 schema 名 / mutation permission / nested delegation 禁止の drift 検出)
  • tests/test_agent_parity.py を新規追加する

Remaining Parent Gaps

Background

.claude/agents/issue-author.md(245 行)と .codex/agents/issue-author.toml(35 行)のように、同名 agent の launcher 別定義は情報量が大きく異なり、出力契約・permission・delegation 制約の drift が発生しやすい。既存の check_claude_codex_agent_parity.py は基本 parity を検証済みのため、これを拡張して compact schema 名参照・mutation permission・nested delegation 禁止の比較を追加する。

  • model / reasoning effort は config declaration として比較・報告するのみとし、runtime proof とは扱わない(runtime 検証は transcript / ledger の責務)
  • drift は STATUS: warn|fail で報告し、launcher 固有で正当な差分は allowlist で明示する

Outcome

check_claude_codex_agent_parity.py が issue-reviewer / issue-author の Claude / Codex 定義間で出力 schema 名・mutation permission・nested delegation 禁止の drift を検出できるよう拡張され、tests/test_agent_parity.py が追加されて全 PASS した状態のコミットが作成され、pnpm 品質ゲートが全 PASS している。

In Scope

  • check_claude_codex_agent_parity.py の拡張
    • 同名 agent(issue-reviewer / issue-author)が同じ compact result schema 名(ISSUE_REVIEW_RESULT_COMPACT_V1 / ISSUE_AUTHOR_RESULT_COMPACT_V1)を参照しているかの比較
    • mutation permission(readonly / write 境界)の差分の明示出力
    • nested delegation prohibition 記述の有無比較
    • model / reasoning effort を「config declaration」として report に含める(一致は要求しない)
    • drift 時の STATUS: warn|fail と evidence(file:line)出力
  • tests/test_agent_parity.py(drift fixture / allowlist / 正常系)

Out of Scope

Acceptance Criteria

  • AC1: issue-reviewer / issue-author の Claude / Codex 定義が同一 compact schema 名を参照しない場合に drift が報告されることが pytest で検証されている
  • AC2: mutation permission の差分が出力に明示されることが pytest で検証されている
  • AC3: model / reasoning effort が config declaration として report に含まれ、runtime proof と扱われない旨が出力に明示されている
  • AC4: nested delegation prohibition の有無比較が行われることが pytest で検証されている
  • AC5: drift 検出時に STATUS: warn または STATUS: fail が返ることが pytest で検証されている
  • AC6: pnpm typecheck / lint / test / build が全 PASS する
  • AC7: final output schema(ISSUE_*_COMPACT_V1)と artifact-only schema(旧 REVIEW_ISSUE_RESULT_V1 / ISSUE_AUTHOR_RESULT_V1)を区別して抽出し、artifact-only schema が残っていても compact schema parity fail にならないことが pytest で検証されている
  • AC8: permission comparison は DECLARED_PERMISSION(claude.permissionMode / claude.disallowedTools / codex.default_permissions)/ MUTATION_BOUNDARY(readonly / issue-mutation / repo-write)/ RUNTIME_PROOF_NOTE(宣言は runtime proof ではない)の 3 層に分離して report されることが pytest で検証されている
  • AC9: Claude nested delegation 禁止は tools / disallowedTools の構造から判定し、Codex nested delegation 禁止は .codex/config.toml の [agents].max_depth == 1 と agent instruction から判定することが pytest で検証されている(check_codex_agent_config.py との責務重複を避け、max_depth 事実の参照は read-only dependency として扱う)
  • AC10: drift evidence は必ず rule_id、file:line、launcher、agent、expected、actual を含み、line number が fixture で安定検証されている
  • AC11: STATUS: warn の exit code は default 0、--strict フラグ指定時は 1 になることが pytest で検証されている

Verification Commands

# AC1
$ uv run pytest tests/test_agent_parity.py -v  # baseline-expect: fail

# AC2
$ rg -n "permission" scripts/check_claude_codex_agent_parity.py  # baseline-expect: pass

# AC3
$ rg -n "declaration" scripts/check_claude_codex_agent_parity.py  # baseline-expect: fail

# AC4
$ rg -n "nested" scripts/check_claude_codex_agent_parity.py  # baseline-expect: fail

# AC5
$ rg -n "STATUS" scripts/check_claude_codex_agent_parity.py  # baseline-expect: pass

# AC6
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm build

# AC7
$ uv run pytest tests/test_agent_parity.py -v -k artifact_only  # baseline-expect: fail

# AC8
$ rg -n "DECLARED_PERMISSION|MUTATION_BOUNDARY|RUNTIME_PROOF" scripts/check_claude_codex_agent_parity.py  # baseline-expect: fail

# AC9
$ rg -n "max_depth|disallowedTools" scripts/check_claude_codex_agent_parity.py  # baseline-expect: fail

# AC10
$ rg -n "rule_id" scripts/check_claude_codex_agent_parity.py  # baseline-expect: fail

# AC11
$ rg -n "strict" scripts/check_claude_codex_agent_parity.py  # baseline-expect: fail

Allowed Paths

  • scripts/check_claude_codex_agent_parity.py
  • tests/test_agent_parity.py(新規)
  • tests/fixtures/agent-parity/(新規。fixture が必要な場合)
  • tests/fixtures/agent-parity/expected-agent-parity.json(新規。parity 検証専用 fixture)

Runtime Verification Applicability

decision: deferred
reason: "Verification Commands は pytest と pnpm ゲートで構成されており、実行環境依存の runtime probe なし。実装完了後に CI で検証する。"
deferred_destination: "CI (pnpm test / uv run pytest tests/test_agent_parity.py)"
deferred_verification_condition: "PR CI が全 PASS した時点で verification 完了とみなす"

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • 既存 parity check の利用箇所(CI / 他 script)との互換が壊れる場合

Required Skills

なし

Scope Delta(任意)

N/A

Delivery Rule

Notes for Reviewer

Activity

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

    @squne121
    OwnerAuthor

    判定

    REQUEST_CHANGES。#799 は必要だが、現Issue契約のままだと “文字列 grep parity linter” になりやすく、#794 で整備した compact output contract の drift を十分に止められません。

    #799 は、既存 scripts/check_claude_codex_agent_parity.py を拡張し、issue-reviewer / issue-author の compact schema 名、mutation permission、nested delegation 禁止、model / reasoning effort declaration を比較するIssueです。#799 自体にコメントはありません。

    #799 の親 #791 は、agent ops の token/context 浪費を preflight / compact contract / hook 規律 / parity linter で減らす delivery-rollup です。特に #799 は、#794 の compact subagent result contract が入った後の drift 検出が役割です。

    関連実装では、#794 / PR #805 が ISSUE_REVIEW_RESULT_COMPACT_V1 / ISSUE_AUTHOR_RESULT_COMPACT_V1、compact script、stdout 2048 UTF-8 bytes 制限、raw diff/log 禁止、Claude/Codex agent 定義更新、SKILL.md consumer 更新を入れています。したがって #799 は「schema名があるか」ではなく「final output contract として同じ compact schema が維持されているか」を検出しないと価値が薄いです。

    ブロッカー

    1. 現行 parity linter は #799 の検出対象に届いていない

    現行 check_claude_codex_agent_parity.py は、期待値JSONを読み、Claude frontmatter / Codex TOML の name、model、permissionMode、runtime route などを軽く比較するだけです。schema 名、final stdout contract、artifact-only schema、permission boundary、nested delegation prohibition は構造化抽出されていません。

    修正: AgentParityFacts のような正規化モデルを作り、Claude/Codex それぞれから次を抽出してください。

    final_output_schema
    artifact_only_schema_names
    permission_declaration
    mutation_boundary  # readonly | issue-mutation | repo-write | unknown
    nested_delegation_blocked
    model_declaration
    reasoning_effort_declaration
    evidence[path,line,snippet]

    2. schema drift 検出が naive grep だと false positive になる

    現行 Claude issue-reviewer.md には final output として ISSUE_REVIEW_RESULT_COMPACT_V1 がありつつ、内部 artifact 用に旧 REVIEW_ISSUE_RESULT_V1 も残っています。これは #794 の設計上正しい状態です。

    同様に Claude issue-author.md には旧 ISSUE_AUTHOR_RESULT_V1 の説明と、後段に final output の ISSUE_AUTHOR_RESULT_COMPACT_V1 が共存しています。単純に schema 名集合を比較すると、旧 schema が混じって drift と誤判定します。

    修正: 抽出対象を以下に限定してください。

    • Claude: ## 出力契約(ISSUE_*_COMPACT_V1) セクション配下
    • Codex: OUTPUT_CONTRACT セクション配下
    • 旧 REVIEW_ISSUE_RESULT_V1 / ISSUE_AUTHOR_RESULT_V1 は artifact_only_schema_names として扱い、final parity の比較対象から除外

    3. permission parity は “宣言一致” と “実効保証” を分けないと危険

    Codex custom agent は TOML で model / model_reasoning_effort / default_permissions などを定義できますが、Codex の subagent は親セッションの sandbox policy を継承し、親ターンの runtime override、たとえば /permissions や --yolo も子 agent 起動時に再適用されます。つまり TOML の default_permissions は runtime proof ではありません。([OpenAI Developers]1)

    Codex permission profile には :read-only、:workspace、:danger-full-access があり、default_permissions は profile 名または built-in を指します。read-only と write-capable の境界は linter が明示すべきですが、「Claude permissionMode と Codex default_permissions が同じ意味」と扱うのは不正確です。([OpenAI Developers]2)

    現行の期待値では issue-author は Codex loop-protocol-rtk / Claude acceptEdits、issue-reviewer は Codex loop-protocol-readonly / Claude dontAsk です。

    修正: permission は単一比較ではなく、最低限この3層で report してください。

    DECLARED_PERMISSION:
      claude.permissionMode
      claude.tools/disallowedTools
      codex.default_permissions
      codex.sandbox_mode if present
    
    MUTATION_BOUNDARY:
      issue-reviewer: readonly required
      issue-author: issue-mutation allowed, repo file write forbidden
    
    RUNTIME_PROOF:
      model/reasoning/permission declarations are config declarations only;
      not runtime proof because parent runtime overrides may apply.
    

    4. nested delegation 禁止は prose 検出だけでは不十分

    Claude Code docs では、特定 subagent がさらに subagent を spawn しないようにするには Agent を tools list から除外するか disallowedTools に追加するとされています。現在の Claude issue-reviewer / issue-author は disallowedTools: Agent を持っており、この点は実装上の evidence として使えます。([Claude API Docs]3)

    Codex 側は [agents].max_depth が重要です。OpenAI docs では agents.max_depth の default は 1 で、直接 child は許すが deeper nesting を防ぐ設計です。上げると fan-out、token、latency、予測可能性リスクが増えます。([OpenAI Developers]1)

    既存 check_codex_agent_config.py はすでに [agents].max_depth == 1 を検査しています。#799 はこれと責務重複しやすいので、同じ事実を別ロジックで再実装するのではなく、共通 helper 化または明示的な read-only dependency として扱うべきです。

    修正: nested delegation rule は以下を fail 条件にしてください。

    • Claude: Agent が tools に許可され、かつ disallowedTools にない
    • Codex: .codex/config.toml の [agents].max_depth が 1 でない
    • Codex agent instructions に spawn_agents_on_csv / recursive delegation / child agent spawn 指示がある

    5. STATUS: warn|fail の exit code が未定義

    #799 は drift 時に STATUS: warn|fail を返すことを求めていますが、現行 linter は failure を [FAIL] で出して exit 1、成功時は OK で exit 0 です。warn を CI で失敗にするのか、report-only にするのかが未定義です。

    修正: 次のように固定してください。

    STATUS: ok    -> exit 0
    STATUS: warn  -> exit 0 by default, exit 1 with --strict
    STATUS: fail  -> exit 1
    

    加えて --format text|json を追加し、pytest は JSON を検証、PR body / human 用は text を使う構成がよいです。

    6. Allowed Paths が expectation fixture 更新を許していない

    現行 linter は tests/fixtures/codex-agent-config/expected-runtime-contract.json を参照しています。#799 の Allowed Paths は scripts/check_claude_codex_agent_parity.py、tests/test_agent_parity.py、tests/fixtures/agent-parity/ だけなので、既存 expectation JSON に parity 用フィールドを足すとスコープ違反になります。

    修正案: 既存 expected-runtime-contract.json は runtime contract 用として維持し、#799 では tests/fixtures/agent-parity/expected-agent-parity.json を新設するのが安全です。既存 JSON を拡張したいなら、Allowed Paths に明示追加してください。

    追加すべき Acceptance Criteria

    - [ ] AC7: final output schema と artifact-only schema を区別して抽出し、
          `REVIEW_ISSUE_RESULT_V1` / `ISSUE_AUTHOR_RESULT_V1` が artifact-only として残っても
          compact schema parity fail にならないことを pytest で検証する
    
    - [ ] AC8: permission comparison は declaration / mutation_boundary / runtime_proof_note を分離し、
          model / reasoning effort / permission profile を runtime proof と扱わないことを pytest で検証する
    
    - [ ] AC9: Claude nested delegation は tools/disallowedTools の構造から判定し、
          Codex nested delegation は `.codex/config.toml [agents].max_depth` と agent instruction から判定する
    
    - [ ] AC10: drift evidence は必ず `file:line` と rule id を含み、
          line number が fixture で安定検証されている
    
    - [ ] AC11: `STATUS: warn` の exit code は default 0、`--strict` では 1 になる

    実装方針

    最小実装はこの形です。

    scripts/check_claude_codex_agent_parity.py
      - --repo-root
      - --format text|json
      - --strict
      - extract_claude_agent_facts(path)
      - extract_codex_agent_facts(path)
      - compare_agent_pair(expected, claude, codex)
      - emit STATUS / rule_id / severity / evidence
    
    tests/test_agent_parity.py
      - normal fixture
      - final schema mismatch
      - artifact-only old schema coexistence
      - reviewer accidentally write-capable
      - author accidentally readonly / missing pre-mutation checker
      - Claude Agent not blocked
      - Codex max_depth=2
      - model/reasoning mismatch report-only
      - allowlist suppresses known launcher-specific drift
      - file:line evidence stability
    

    Codex Skills は progressive disclosure で SKILL.md 全文を必要時だけ読む設計なので、長大な schema を agent 定義に直書きして検査するより、script/constants/tests 側を正本にする #794 の方針は妥当です。#799 も同じ方向で、agent prose ではなく正規化された抽出結果を比較するべきです。([OpenAI Developers]4)

    そのまま Issue コメントに貼る文案

    REQUEST_CHANGES.
    
    #799 の方向性は妥当ですが、現Issue契約のままだと `check_claude_codex_agent_parity.py` に文字列 grep を足すだけになり、#794 で導入した compact output contract の drift を十分に防げません。
    
    Blocker:
    
    1. final output schema と artifact-only schema の区別が必要です。
       現行 Claude agent には `ISSUE_*_COMPACT_V1` と旧 `REVIEW_ISSUE_RESULT_V1` / `ISSUE_AUTHOR_RESULT_V1` が共存します。旧 schema は artifact-only として正しいため、schema 名集合の単純比較は禁止してください。
    
    2. permission parity は declaration / mutation_boundary / runtime proof を分離してください。
       Codex custom agent の `default_permissions` は宣言であり、親 runtime override の影響を受け得ます。Claude `permissionMode` と Codex `default_permissions` を同一意味として扱うのは危険です。
    
    3. nested delegation 禁止は prose ではなく構造で判定してください。
       Claude は `Agent` が tools から除外されている、または `disallowedTools` にあること。
       Codex は `[agents].max_depth == 1` と agent instruction に recursive spawn 指示がないことを確認してください。
    
    4. `STATUS: warn|fail` の exit code を固定してください。
       推奨は `ok -> 0`, `warn -> 0`, `warn --strict -> 1`, `fail -> 1` です。
    
    5. drift evidence は必ず `rule_id`, `file:line`, `launcher`, `agent`, `expected`, `actual` を含めてください。
    
    6. 既存 `tests/fixtures/codex-agent-config/expected-runtime-contract.json` を拡張するなら Allowed Paths に追加してください。
       そうでなければ `tests/fixtures/agent-parity/expected-agent-parity.json` を新設してください。
    
    追加ACとして、artifact-only schema coexistence、permission boundary mismatch、nested delegation mismatch、model/reasoning report-only、allowlist、file:line evidence、warn exit semantics を pytest fixture で固定することを要求します。
  3. squne121 commented on Jun 15, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Human Escalation Required

    The loop has terminated and requires human review. Cause: max iterations exceeded

    Blockers

    "Iteration 3/3 到達: max_iterations=3 で自動停止"
    
    "reviewer が 3 回連続 VERDICT: needs-fix を返した"
    
    "contract_readiness_check.py は最終本文で status: go を返しており reviewer VCP エラーは false positive の可能性"
    
    "anchor comment の 6 blockers は AC7-AC11 追加等で全て対処済み"
    
  4. squne121 commented on Jun 15, 2026

    @squne121
    OwnerAuthor

    CONTRACT_REVIEW_RESULT_V1

    schema: CONTRACT_REVIEW_RESULT_V1
    issue_number: 799
    repo: squne121/loop-protocol
    status: go
    generated_at: 2026-06-15T10:45:00Z
    body_sha256: sha256:b566d997a696e19853091ea60f00aa79c76ff3dcb4af3c0b371f8e8a0157a5bc

    checks

    template_compliance: pass
    state_label: pass  # state/needs-human なし
    allowed_paths_present: pass
    vc_present: pass
    stop_conditions_complete: pass
    worktree_branch_collision: pass  # issue-799 worktree/branch なし
    dependency_blockers: pass  # check_blockers.sh: 全 blocker closed(#794 PR #805 merged)
    product_spec_check:
      applicability: not_applicable
      decision: pass
      reason: "workflow/script 変更。docs/product / tasks.md / feature spec 非対象"
    vc_preflight:
      status: go_with_notes
      summary:
        expected_fail: 2   # AC1, AC7
        expected_pass: 4   # AC6 ×4 (pnpm typecheck/lint/test/build)
        blocked_false_positive: 8  # AC2-AC5, AC8-AC11(broad_search_path_unbounded 偽陽性)
      false_positive_basis: >
        AC2-AC5/AC8-AC11 の rg コマンドは `scripts/check_claude_codex_agent_parity.py` という
        特定ファイルを対象としており、Allowed Paths 内の具体的パス指定。
        broad_search_path_unbounded は誤分類。
        手動検証: AC2(permission)現在 PASS / AC3-AC5,AC8-AC11 現在 FAIL(baseline-expect:fail と一致)。
        AC5 の baseline-expect:pass 記載は annotation 誤りだが実装後に STATUS 追加で AC 有効。
    ac_verifiability: pass  # AC1-AC11 全チェックボックス形式、VC と番号一致
    runtime_verification_applicability:
      decision: deferred
      destination: "CI (pnpm test / uv run pytest tests/test_agent_parity.py)"
    blocked_reasons: []
    next_action: implement-issue

    Worktree / Branch

    worktree: .claude/worktrees/issue-799-agent-parity-linter-extend
    branch: worktree-issue-799-agent-parity-linter-extend

    contract_snapshot

    outcome: >
      check_claude_codex_agent_parity.py が issue-reviewer / issue-author の Claude/Codex 定義間で
      出力 schema 名・mutation permission・nested delegation 禁止の drift を検出できるよう拡張され、
      tests/test_agent_parity.py が追加されて全 PASS した状態のコミットが作成され、
      pnpm 品質ゲートが全 PASS している。
    
    acceptance_criteria:
      - AC1: compact schema drift が pytest で検証されている
      - AC2: mutation permission 差分が出力に明示されることが pytest で検証されている
      - AC3: model/reasoning effort が config declaration として report に含まれている
      - AC4: nested delegation 比較が pytest で検証されている
      - AC5: drift 時に STATUS: warn/fail が返ることが pytest で検証されている
      - AC6: pnpm typecheck/lint/test/build 全 PASS
      - AC7: final output schema と artifact-only schema を区別して抽出できている
      - AC8: permission comparison が 3 層(DECLARED_PERMISSION/MUTATION_BOUNDARY/RUNTIME_PROOF_NOTE)で報告
      - AC9: Claude は tools/disallowedTools から、Codex は max_depth+instruction から nested delegation を判定
      - AC10: drift evidence に rule_id/file:line/launcher/agent/expected/actual を含む
      - AC11: STATUS:warn は exit 0 / --strict 時は exit 1
    
    verification_commands:
      - "uv run pytest tests/test_agent_parity.py -v  # AC1 baseline: fail"
      - "rg -n 'permission' scripts/check_claude_codex_agent_parity.py  # AC2"
      - "rg -n 'declaration' scripts/check_claude_codex_agent_parity.py  # AC3 baseline: fail"
      - "rg -n 'nested' scripts/check_claude_codex_agent_parity.py  # AC4 baseline: fail"
      - "rg -n 'STATUS' scripts/check_claude_codex_agent_parity.py  # AC5"
      - "pnpm typecheck && pnpm lint && pnpm test && pnpm build  # AC6"
      - "uv run pytest tests/test_agent_parity.py -v -k artifact_only  # AC7 baseline: fail"
      - "rg -n 'DECLARED_PERMISSION|MUTATION_BOUNDARY|RUNTIME_PROOF' scripts/check_claude_codex_agent_parity.py  # AC8 baseline: fail"
      - "rg -n 'max_depth|disallowedTools' scripts/check_claude_codex_agent_parity.py  # AC9 baseline: fail"
      - "rg -n 'rule_id' scripts/check_claude_codex_agent_parity.py  # AC10 baseline: fail"
      - "rg -n 'strict' scripts/check_claude_codex_agent_parity.py  # AC11 baseline: fail"
    
    allowed_paths:
      - scripts/check_claude_codex_agent_parity.py
      - tests/test_agent_parity.py(新規)
      - tests/fixtures/agent-parity/(新規)
      - tests/fixtures/agent-parity/expected-agent-parity.json(新規)
    
    vc_preflight_digest: sha256:1d811c7134c836f61287ecee9671bfca5de9d1d4202ab4fc7eda61dc92bebb10
  5. added 4 commits that reference this issue on Jun 15, 2026
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