Skip to content

fix(agent-ops): capability 判定を claude --help ではなく実 runtime 挙動で行う - #1976

Merged
squne121 merged 4 commits into
mainfrom
worktree-issue-1960-runtime-capability-classification
Aug 2, 2026
Merged

squne121 merged 4 commits into
mainfrom
worktree-issue-1960-runtime-capability-classification

Conversation

@squne121

@squne121 squne121 commented Aug 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • run_worktree_agent_runtime_smoke.py の Claude capability preflight を、claude --help の文字列検索から実際の fixed-argv invocation 結果に基づく判定へ置き換えた(Issue 実装: run_worktree_agent_runtime_smoke.py の Claude capability 判定を --help 非掲載フラグでなく実 runtime 挙動に基づく判定へ修正する #1960)
  • preflight_claude_flags(help 文字列検索)を撤去し、preflight_claude_available(claude 実行ファイルの存在確認のみ)に置き換えた
  • classify_claude_structured_outcome を追加し、structured lane の実行結果を capability_skip(unknown/unrecognized option 診断のみ)・turn_limit_reached(--max-turns 到達=flag 受理の証拠、FAIL 1)・runtime_outcome(既存の exit code / terminal event 判定)の 3 種へ narrow に分類する
  • interactive lane(herdr 経由)から --max-turns の forward を撤去し、structured-only flags に依存しないことを明示した
  • --max-turns に _positive_int を追加し、1 以上の整数のみを受理するようにした(0・負数は argument error)
  • .claude/skills/worktree-agent-runtime-smoke/SKILL.md と references/claude-code.md の capability 判定説明を、実 runtime 挙動ベースへ更新した(AC8)
  • 新規テストファイル test_run_worktree_agent_runtime_smoke_help_capability.py(AC1-AC6 回帰)と test_run_worktree_agent_runtime_smoke_runtime_evidence.py(AC9 回帰、fake claude binary で実 invocation 到達を独立証明)を追加した
  • test_run_worktree_agent_runtime_smoke.py に 実装: issue-author を issue-creator/issue-editor に分割し実行時に真である Skill 権限境界を実装する #1734 の runtime AC 再実行可能性についての記述を追加した(AC10)
  • fix-delta(owner REQUEST_CHANGES, comment)反映:
    • preflight_herdr / preflight_claude_available / preflight_codex_flags の SKIP 経路が schema_summary 構築前に早期 return EXIT_SKIP していたため summary.md が全く書かれていなかった欠陥を修正し、これら 3 経路も含む全ての controlled exit を単一の write_evidence finalizer 経由にした(AC7)
    • preflight_claude_available / preflight_codex_flags を shutil.which() で resolved executable を一度だけ返す設計に変更し、version capture(capture_runtime_version)と structured lane invocation(run_structured_claude / run_structured_codex)へ同一の絶対パスを共有させ、evidence に resolved_executable を追加した(Design Decision 5)。interactive lane は herdr 側で --kind から再解決されるため、同一バイナリの保証がないことを resolved_executable_binding_note として正直に記録した
    • classify_claude_structured_outcome のテキストベース分類を stderr のみへ限定し、fixed-argv flag 名(--max-turns 等)を明示的に含む「error: 行頭付近のパーサーエラー行」のみを capability_skip と判定するよう narrow 化した。加えて stdout から有効な JSON stream-json event が既に観測されている場合は parser-rejection と判定しない(= runtime が既に起動した証拠を優先する)ガードを追加した

Checks

  • uv run --locked pytest scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_help_capability.py -q — 11 passed(fix-delta iteration: capability 判定の stdout/stderr 混同を防ぐ adversarial regression 2件を追加)
  • uv run --locked pytest scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py -q — 61 passed(fix-delta iteration: preflight SKIP 経路の summary.md 生成回帰 3件を追加)
  • uv run --locked pytest scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_runtime_evidence.py -q — 2 passed(fix-delta iteration: resolved_executable 単一 resolve 回帰 1件を追加)
  • rg -n "help への非掲載は capability 不足を意味しない" .claude/skills/worktree-agent-runtime-smoke/references/claude-code.md .claude/skills/worktree-agent-runtime-smoke/SKILL.md — 両ファイルで一致
  • rg -n "1734" scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py — 一致
  • uv run --locked ruff check scripts/agent-ops/run_worktree_agent_runtime_smoke.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_help_capability.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_runtime_evidence.py — All checks passed
  • N/A: pnpm typecheck / pnpm lint / pnpm test / pnpm build(本 PR は Python runner / pytest / skill markdown のみを変更し、TypeScript ソースを変更しない)

Schema Change Applicability

  • decision: not_schema_change
  • reason: summary.md(WORKTREE_AGENT_RUNTIME_SMOKE_RESULT_V1)のフィールド集合は変更する(本 PR で capability_decision / capability_error_classification を新規追加し、fix-delta iteration で resolved_executable / resolved_executable_binding_note をさらに追加した)が、この artifact は他 Skill / SubAgent が読み取る versioned producer-consumer contract ではなく、worktree-local untracked な人間可読 evidence であるため、フィールド追加は not_schema_change と判断する(Schema Consumer Inventory 節参照。旧文言は「フィールド集合・型は変更していない」と事実誤認していたため、レビュー指摘(PR fix(agent-ops): capability 判定を claude --help ではなく実 runtime 挙動で行う #1976 owner REQUEST_CHANGES)を受けて訂正)。

Schema Consumer Inventory

  • decision: not_schema_change(上記 Schema Change Applicability)のため N/A
  • 理由: summary.md は worktree-local untracked artifact であり、他 Skill / SubAgent が読み取る producer-consumer 境界の machine-readable contract ではない

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
Claude capability 判定は claude --help の文字列出現ではなく、実際に実行する fixed-argv invocation の結果(unknown/unrecognized option の狭い診断のみ)で SKIP を判定する yes - classify_claude_structured_outcome / test_help_omits_max_turns_but_runtime_accepts_flag_then_structured_smoke_runs / test_runtime_rejects_max_turns_as_unknown_option_then_skip77_with_summary -
認証失敗・network failure・model failure・汎用 runtime エラー等の非ゼロ終了を、unknown-option capability SKIP へ誤分類しない yes - test_non_capability_runtime_failure_is_not_misclassified_as_skip -
--max-turns の bound 到達(flag 受理の証拠)を capability 不足へ誤分類せず、runtime failure の exit 1 として扱う yes - test_max_turn_limit_reached_is_fail_not_capability_skip -
interactive lane は structured-only flags(--output-format/--include-hook-events/--no-session-persistence/--max-turns)の help preflight に依存せず、--max-turns を対話型起動へ転送しない yes interactive mode での --max-turns 対応自体が実 runtime で別途確認されるまでは非対応のまま(Issue #1960 Outcome の明記通り) test_interactive_claude_does_not_require_or_forward_structured_only_flags #1887
--max-turns は 1 以上の整数のみを受理し、0・負数は argument error として拒否する yes - test_max_turns_must_be_positive -
preflight_herdr / preflight_claude_available / preflight_codex_flags の SKIP 77 経路でも allowlist-only summary.md が必ず生成される(AC7) yes - test_given_no_claude_binary_when_preflight_runs_then_skip77 / test_given_codex_help_introspection_fails_when_preflight_runs_then_skip77_with_summary / test_given_herdr_preflight_fails_when_interactive_mode_runs_then_skip77_with_summary -
runtime executable は shutil.which() で一度だけ resolve し、version capture と structured invocation が同一の絶対パスを共有する(Design Decision 5) yes interactive lane は herdr 側の --kind 経由再解決のため同一バイナリ保証は無く、evidence にその制約を明記するのみ test_resolved_executable_is_single_path_shared_by_version_capture_and_invocation -
capability_skip 判定は stdout(未信頼な model/tool-output stream)ではなく stderr のみを参照し、fixed-argv flag 名を明示する parser-level 診断行のみを狭く一致させる yes - test_stdout_prose_saying_unknown_option_with_unrelated_stderr_failure_is_not_misclassified_as_skip / test_stdout_quoted_max_turns_text_does_not_override_genuine_stderr_parser_rejection -

動作検証証跡(Runtime Verification Evidence)

## Runtime Verification Applicability は decision: immediate(applicable_acs: AC9)。

AC9: 実 Claude Code 2.1.220 による structured smoke が help 非掲載を理由に SKIP しないことの確認

linked worktree(.claude/worktrees/issue-1960-runtime-capability-classification)内で、実 Claude Code CLI(claude --version → 2.1.220 (Claude Code))に対して実際に runner を実行した。

$ uv run --locked python3 scripts/agent-ops/run_worktree_agent_runtime_smoke.py \
    --runtime claude --mode structured --worktree "$WORKTREE" \
    --prompt-file tmp/runtime-smoke/claude-structured.md \
    --output-dir artifacts/runtime-smoke/claude-structured \
    --timeout-seconds 180 --max-turns 5
OK: runtime smoke evidence written to .../artifacts/runtime-smoke/claude-structured
exit=0

summary.md(抜粋、redacted):

capability_decision: runtime_outcome
capability_error_classification: None
exit_code: 0
native_event_count: 16
process_exit_code: 0
runtime: claude
runtime_version: 2.1.220 (Claude Code)
timed_out: False

claude --help は本環境の 2.1.220 でも --max-turns を表示しないが(Issue #1960 背景の通り)、runner は help 出力の非掲載を理由に SKIP せず、実際の fixed-argv invocation まで到達し capability_decision: runtime_outcome・exit_code: 0 の evidence を残した。fake-binary ベースの回帰テスト(test_structured_smoke_reaches_real_invocation_via_subprocess_despite_help_omission)が同じ挙動を継続的に検証する。

Notes

`run_worktree_agent_runtime_smoke.py` の Claude capability preflight を
`claude --help` の文字列検索から実際の fixed-argv invocation 結果に基づく
判定へ置き換える。help への非掲載は capability 不足を意味せず、
`--max-turns` は Claude Code 2.1.220 の `--help` から欠落していても
実際には受理される documented print-mode flag であるため、false SKIP を
引き起こしていた。

- unknown/unrecognized option 診断のみを capability SKIP(exit 77)へ
  分類し、任意の non-zero exit を capability 不足として扱わない
- `--max-turns` の bound 到達は flag 受理の証拠として bounded turn
  failure(FAIL 1)とし capability SKIP に昇格させない
- interactive lane は structured-only flag(`--output-format` /
  `--include-hook-events` / `--no-session-persistence` /
  `--max-turns`)を forward しない
- `--max-turns` を 1 以上の整数のみ受理するよう argparse type を追加
- SKILL.md / references/claude-code.md の capability 判定説明を
  実 runtime 挙動ベースへ更新(AC8)
- 実 Claude Code 2.1.220 による structured smoke で false SKIP せず
  実 invocation まで到達する evidence を確認(AC9)
- #1734 の runtime AC 再実行可能性を回帰テストへ反映(AC10)

Closes #1960
@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Preview URL

✅ verified live assets: https://squne121.github.io/loop-protocol/pr-1976/

The preview will be removed when this PR is closed.

@squne121

squne121 commented Aug 2, 2026

Copy link
Copy Markdown
Owner Author

判定

REQUEST_CHANGES

  • P0: 0件
  • P1: 3件
  • P2: 2件

claude --help を capability authority から外す方向自体は正しいです。Claude Code 公式資料も、--help は全フラグを列挙せず、非掲載は利用不能を意味しないと明記しています。また、--max-turns は print mode 専用で、上限到達時はエラー終了する仕様です。([Claude]1)

ただし、現在の実装は Issue #1960 の契約を複数箇所で満たしていません。

ブロッカー

P1-1. command-not-found 等の exit 77 では、依然として summary.md が生成されない

main() は schema_summary を構築する前に preflight_herdr()、preflight_claude_available()、preflight_codex_flags() を実行し、失敗時はその場で return EXIT_SKIP します。したがって次の controlled SKIP では証跡が残りません。

  • claude が PATH に存在しない
  • codex が存在しない、または help introspection が失敗
  • interactive lane で Herdr が利用不能

Issue #1960 の AC7 は「exit 77 を含む controlled exit path で allowlist-only summary.md を生成」と明示しています。実装は runtime invocation 後の unknown-option SKIP だけを修正しており、AC7 全体を満たしていません。

さらに、既存の no-claude テストは return code 77 しか検査しておらず、summary.md の欠落を固定化しています。

必要な修正

すべての controlled exit を単一の evidence finalizer に通してください。少なくとも以下を追加検証すべきです。

  • missing Claude → exit 77 + summary.md
  • Herdr preflight failure → exit 77 + summary.md
  • Codex capability preflight failure → exit 77 + summary.md

P1-2. 「同一の解決済み実行ファイルを使う」という Design Decision 5 が未実装

preflight_claude_available() は shutil.which("claude") の結果を取得しますが、その絶対パスを破棄しています。その後は別々に、

  • capture_runtime_version("claude")
  • run_structured_claude(..., claude_bin="claude")

を実行しており、それぞれで PATH 解決が再発生します。

Issue #1960 は、shutil.which() で一度だけ解決した同一の絶対パスを version 取得と runtime execution の双方に使い、途中で別バイナリへ切り替わることを防ぐと明記しています。また Evidence 要件には resolved executable も含まれています。現行 summary にはそのフィールドもありません。

PATH の変更、shim の差し替え、symlink 更新が発生すると、version evidence と実際に実行したバイナリが異なる可能性があります。

必要な修正

resolved_runtime = os.path.realpath(shutil.which(runtime))

を一度だけ行い、次の全経路に渡してください。

  • version capture
  • structured invocation
  • evidence の resolved_executable

interactive Herdr 経由では実バイナリを明示的に束縛できないなら、その制約を evidence に正直に記録すべきです。


P1-3. unknown-option 判定が「parser-level」ではなく、モデル出力を含む全文検索になっている

classify_claude_structured_outcome() は stdout + stderr 全体に対して次の一般的な文字列を検索します。

  • unknown option
  • unknown argument
  • turn limit reached
  • max turns reached

しかし stdout は Claude の stream JSON であり、assistant message や tool output を含みます。実際、同じ runner は stdout 内の assistant event と tool-use content を解析しています。つまり、モデルが説明文として「unknown option」と出力しただけでも、プロセスが非ゼロなら capability SKIP へ誤分類できます。

逆に、実際の parser rejection と無関係な stdout 内の Reached max turns が先に一致すると、unknown-option より turn_limit_reached が優先されます。

これは Issue の「既知の parser-level diagnostic のみを狭く分類する」という条件を満たしていません。

必要な修正

最低限、以下まで絞るべきです。

  • 原則として stderr のみを判定対象にする
  • fixed argv に実在するフラグ名が診断行に含まれることを要求する
  • 行頭付近の error: 等を含む anchored pattern にする
  • valid JSON event が既に出ている場合は、単純な parser rejection として扱わない

追加すべき敵対的テスト例:

stdout: assistant message に "unknown option" を含む
stderr: authentication failure
exit: 1
期待: FAIL 1、SKIP 77 ではない
stdout: tool output に "Reached max turns" を含む
stderr: error: unknown option '--max-turns'
exit: 1
期待: parser rejection の扱いを明確に固定

P2 指摘

P2-1. PR 本文の Schema Change Applicability が事実と異なる

PR 本文は、capability_decision と capability_error_classification は既存フィールドで、フィールド集合を変更していないと説明しています。

しかし差分では、この2フィールドを schema_summary に新規追加しています。

「非契約的な untracked artifact なので schema governance 対象外」という結論はあり得ますが、フィールド集合が変わっていないという理由は誤りです。PR 本文を次のように訂正すべきです。

summary のフィールド集合は変更するが、この artifact は versioned producer-consumer contract ではないため not_schema_change と判断する。

P2-2. AC10 の検証が実質的に無意味

AC10 の確認は、一般テストファイルに 1734 という文字列が存在することを rg で確認しているだけです。PR 本文も「#1734 の runtime AC 再実行可能性についての記述を追加」と説明しています。

これは consumer の runtime smoke が実行可能になった証拠ではありません。特に #1734 は、その後 issue-author を issue-creator/issue-editor に分割する設計へ変更されており、実 Agent persona を指定した smoke が必要になっています。

AC10 は少なくとも、現在の #1734 用 runtime test を実行し、旧 false-SKIP ではなく実 invocation へ到達することを確認すべきです。

良い変更

以下は妥当です。

  • 非網羅的な --help grep を capability gate から撤去した
  • interactive lane へ --max-turns を転送しなくした
  • --max-turns を正整数に制限した
  • max-turn 到達を capability 不足ではなく runtime failure とした
  • 実 Claude Code 2.1.220 で invocation 到達と exit 0 の証跡を取得した

取得できた PR 会話上のコメントは preview bot の1件のみで、既存の人間レビュー指摘はまだ反映されていません。

結論: 方向性は正しいものの、AC7、Design Decision 5、狭い parser-level classification の3点が未達です。この状態では merge 非推奨です。GitHub へのレビュー投稿は行っていません。

…dence 欠落・resolved executable 未共有・capability 判定の stdout 誤混入を修正)

- preflight_herdr / preflight_claude_available / preflight_codex_flags の
  SKIP 77 経路が schema_summary 構築前に早期 return しており summary.md が
  一切書かれていなかった欠陥を修正し、全 controlled exit を単一の
  write_evidence finalizer 経由にした(Issue #1960 AC7)
- preflight_claude_available / preflight_codex_flags を shutil.which() で
  resolved executable を一度だけ返す設計に変更し、version capture と
  structured invocation へ同一の絶対パスを共有させ、evidence に
  resolved_executable を追加した(Design Decision 5)。interactive lane は
  herdr 側で再解決されるため同一バイナリを保証できない旨を
  resolved_executable_binding_note として正直に記録する
- classify_claude_structured_outcome のテキストベース分類を stderr のみへ
  限定し、fixed-argv flag 名を明示するパーサーエラー行のみを狭く一致させ、
  stdout に有効な JSON stream-json event が既に観測されている場合は
  parser-rejection と判定しないガードを追加した(Issue #1960 P1-3)
- 上記の regression test を追加し、既存 AC1-AC10 の pass を維持したまま
  74 tests green を確認した
- PR body の Schema Change Applicability を、フィールド集合は変更するが
  versioned producer-consumer contract ではないため not_schema_change、と
  正しい理由に訂正した

Ref: #1976 (comment)
Closes #1960
…fication

# Conflicts:
#	scripts/agent-ops/run_worktree_agent_runtime_smoke.py
@squne121
squne121 marked this pull request as ready for review August 2, 2026 13:22
@squne121
squne121 merged commit b958cdc into main Aug 2, 2026
21 checks passed
@squne121
squne121 deleted the worktree-issue-1960-runtime-capability-classification branch August 2, 2026 13:22
squne121 added a commit that referenced this pull request Aug 3, 2026
* feat(agy): add capability gate for AGY headless capabilities (#1941)

`preflight_agy.py` becomes the single implementation SSOT for AGY capability
detection. Adds a version parser (parse_agy_version_string), a fixed-argv
parser-acceptance classifier for `--disable-slash-commands`, a runtime probe
for leading-slash literal treatment, binary identity fingerprinting +
drift detection, an in-process-only memoization cache, and a single
finalizer that always persists a sanitized JSON artifact under `.claude/tmp/`.

The capability matrix decomposes headless_permission_policy / hooks /
disable_slash_commands into predicate-level supported / unsupported /
unavailable / inconclusive / evidence_invalid results — evidence-source
prioritized runtime_semantic_observation > parser_acceptance > changelog >
help > version, so help/version alone never confirm `supported`.
`pre_invocation_injected_tool_call` is pinned `unsupported` while upstream
google-antigravity/antigravity-cli#728 is open. Predicates whose live
enforcement verification is Issue #1979's responsibility are classified
`inconclusive`, never fabricated as `supported`.

Also fixes the existing early cli_incompatible exit on missing --help flags
so it defers to the runtime smoke check (help absence is supporting evidence
only, per PR #1976 design) — this was explicitly the bug #1941 asked to fix,
and the pre-existing test asserting the old behavior is updated accordingly.

`--require-capability` adds an additive 0/1/77 exit-code mode without
touching the default invocation's existing ok-boolean exit 0/1. setup_check.py
surfaces the additive `agy_capabilities` field without adding its own
version/help parser or changing its existing single-boolean ok derivation.

docs/dev/schema-governance.md records the additive `agy_capability_matrix/v1`
extension to `agy_preflight_result/v1` (no v2 bump).

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix(agy): resolve OWNER fix_delta blockers in AGY capability gate (#1941)

OWNER REQUEST_CHANGES on PR #1982 found the previous automated APPROVE
inadequate: binary-identity binding was not actually applied to executed
probes, the leading_slash_is_literal runtime probe tested the wrong argv
and misclassified combined evidence, the same probe leaked the real
HOME/XDG_* environment and had no cost gate, sanitization missed
version_evidence.raw/agy.version and the in-memory return value, parser-
rejection classification was too broad, setup_check.py never actually
requested the capability matrix on the real invocation path, and
memoization could bypass binary-identity drift detection.

- preflight_agy.py: resolve the agy binary exactly once via
  os.path.realpath(shutil.which()) and bind every version/help/smoke/
  capability probe to that single path; rewrite the leading-slash-literal
  probe to use the exact production argv with an isolated HOME/XDG_* env
  and a cost-confirmation gate (skips by default, exit taxonomy
  unaffected); route every external-facing output (return value,
  --json, --output-file, artifact) through the same sanitizer, including
  version_evidence.raw and a normalized agy.version + redacted sample;
  narrow classify_parser_acceptance() to require the specific
  --disable-slash-commands flag name and prioritize auth evidence;
  bind the capability memoization cache key to both pre-run and
  pre-runtime-probe binary identity plus an expanded config digest
  (.agents/hooks.json + global hooks path); populate a full-shaped
  capability matrix with per-predicate reasons on controlled early
  exits; and anchor version parsing to an explicit `agy` context line
  when multiple version-shaped tokens are present.
- setup_check.py: check_agy_preflight() now requests
  compute_capabilities=True so the real invocation path actually
  populates the capability matrix.
- Adds unit/integration tests for every P1/P2 finding, including a real
  subprocess round-trip against a swappable fake binary proving
  binary-identity drift is caught.
- docs/dev/schema-governance.md: documents the agy.version /
  version_evidence.raw sanitization semantics change.

All 9 original Issue #1941 AC verification commands, the full
gemini-cli-headless-delegation test suite (1278 tests), and the
repo-wide pytest suite (7633 passed) are green.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant