Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#1265"
goal_ref: "AGY/Gemini provider の認証状態・実行環境診断を機械可読化し、既知の WSL2/OAuth 再認証課題と non-TTY silent failure を扱えるようにする"
change_kind: codeParent Issue
Parent Goal Ref
- Goal: GeminiCLI 依存を段階的に縮小しつつ、AGY provider が Gemini 版と同等の delegation platform として機能し、可観測性・テスト密度・認証堅牢性・クォータ制御を備えた状態にする。
- Desired Destination: 9 件の child issue が起票され close されることで、GeminiCLI 依存縮小と AGY provider 機能同等性拡張が段階的に達成される。
Current Validated Scope
- setup_check.py(.claude/skills/gemini-cli-headless-delegation/scripts/)の auth mode / keyring availability / TTY condition の machine-readable 化
- preflight_agy.py(同 scripts/)への認証診断 sub-check 追加(agy_auth_diagnostics_v1 schema での failure class 拡張)
- preflight_gemini_headless.py(同 scripts/)の既存 OAuth sunset 検出との整合確認・必要な差分反映(SSOT は setup_check.py の check_auth 関数)
- WSL2/OAuth 再認証問題・agy -p の non-TTY 実行時 silent stdout drop の known issue 明記と recovery action 定義(skill 内 docs/references への反映を含む)
Remaining Parent Gaps
- クォータ管理と provider fallback policy(別 child issue、実装: クォータ管理と provider fallback policy を明文化・実装する #1270)
- agent delegation テスト密度の AGY provider 固有分岐までの引き上げ(別 child issue)
- AGY 実機の non-TTY silent stdout drop の根本修正(Antigravity CLI 側の挙動修正は本 Issue の non-goal であり、diagnostics/recovery のみを扱う)
Outcome
setup_check.py と preflight_agy.py が auth mode・keyring availability・TTY condition を、本文で固定する agy_auth_diagnostics_v1 schema に準拠した machine-readable failure class として返し、WSL2/OAuth 再認証問題と agy -p の non-TTY silent stdout drop の recovery action が skill docs に明記されている状態。
Auth Diagnostics Schema(agy_auth_diagnostics_v1)
preflight_agy.py は success / CLI missing / smoke failure / timeout / grounded・local-asset sub-check failure を含む、すべての agy_preflight_result/v1 応答に、以下の固定スキーマに準拠する auth オブジェクトを含める。この schema の追加・値そのものの拡張は本 Issue で許可済み。
agy_auth_diagnostics_v1:
checked: true
auth_mode:
enum:
- unknown
- system_keyring_cached
- google_sign_in_required
- api_key_env_present
- unauthenticated
- auth_probe_failed
auth_mode_confidence:
enum: [observed, inferred, unknown]
keyring:
available: boolean | null
backend_hint: string | null
failure_class:
enum:
- null
- system_keyring_unavailable
- system_keyring_locked
- system_keyring_backend_missing
- system_keyring_access_denied
- system_keyring_probe_unsupported
tty:
stdin_isatty: boolean
stdout_isatty: boolean
stderr_isatty: boolean
noninteractive_mode: boolean
platform:
os: linux | windows | macos | unknown
is_wsl: boolean
wsl_hint: string | null
recovery_action: string | nullsetup_check.py --provider agy --json は同じ構造をそのまま agy_preflight.auth に surfacing し、setup_check.py 側で別 schema へ再構成しない(schema drift を防ぐ)。
Required Result Contract
preflight_agy.py MUST include auth: agy_auth_diagnostics_v1 in every agy_preflight_result/v1, including success, CLI missing, smoke failure, timeout, and grounded/local-asset sub-check failures.
setup_check.py --provider agy --json MUST surface the same object at agy_preflight.auth without schema drift.
setup_check.py --provider auto --json MUST preserve the AGY attempt's auth/keyring/TTY failure class inside provider_attempts or an equivalent machine-readable attempt detail. It MUST NOT implement runtime provider fallback; that remains #1270.
Empty stdout MUST remain an output-surface failure (agy_empty_stdout / agy_output_missing) and MUST NOT be reclassified as auth failure unless stderr/stdout contains explicit auth/keyring evidence.
In Scope
- setup_check.py の出力に agy_auth_diagnostics_v1 準拠の auth mode / keyring availability / TTY condition フィールドを追加する
- preflight_agy.py に認証診断 sub-check を追加し、failure class を system_keyring_unavailable, system_keyring_locked, system_keyring_backend_missing, system_keyring_access_denied, noninteractive_auth_prompt_required, google_sign_in_required, agy_auth_unknown へ拡張する(agy_empty_stdout / agy_output_missing は output-surface failure として別分類のまま維持する)
- 診断用 env snapshot(DBUS_SESSION_BUS_ADDRESS_present, DISPLAY_present, WAYLAND_DISPLAY_present, WSL_INTEROP_present, WSL_DISTRO_NAME_present の boolean のみ)と、AGY subprocess 実行用 minimal env を分離する。診断結果に環境変数の値そのものは出さない
- preflight_gemini_headless.py の既存 OAuth sunset 検出との整合確認について、setup_check.py の check_auth 関数を SSOT とすることを明記し、参照のズレを解消する
- setup_check.py --provider auto --json において、AGY attempt の auth/keyring/TTY failure class を provider_attempts 相当の machine-readable attempt detail に残す(runtime fallback policy 自体は実装しない)
- WSL2/OAuth 再認証問題、agy -p の non-TTY 実行時 silent stdout drop の既知事象を skill 内 docs(references/ または SKILL.md)に明記し、recovery action を定義する
- 上記診断ロジックに対応する pytest ケース(non-TTY, WSL2 検出, keyring unavailable, D-Bus missing hint, Google Sign-In required, empty stdout は auth failure ではない, redaction)を追加する
Out of Scope
- Google OAuth / Antigravity CLI 側の認証プロバイダ実装自体の変更
- クォータ管理(別 child issue)
- モデル選択・並列実行 orchestrator(別 child issue)
- provider=auto の runtime fallback policy 実装(実装: クォータ管理と provider fallback policy を明文化・実装する #1270 の範囲。本 Issue は failure class を attempt detail に残すところまで)
- _normalize_agy_result 関数の empty stdout warning 文字列と failure_class の既存不整合の是正(実装: agent delegation の AGY provider 固有分岐に対するテスト密度を引き上げる #1274 の範囲。本 Issue はこの不整合を悪化させない・auth failure と混同しないことのみを要求する)
Acceptance Criteria
- AC1: setup_check.py --provider agy --json の出力の agy_preflight.auth に、agy_auth_diagnostics_v1 schema 準拠の auth mode・keyring availability・TTY condition のフィールドが含まれる。
- AC2: preflight_agy.py が返す agy_preflight_result/v1 は、success / CLI missing / smoke failure / timeout / grounded・local-asset sub-check failure のいずれの場合にも auth: agy_auth_diagnostics_v1 を含む。
- AC3: keyring / auth failure class に system_keyring_unavailable, system_keyring_locked, system_keyring_backend_missing, system_keyring_access_denied, noninteractive_auth_prompt_required, google_sign_in_required, agy_auth_unknown が定義されており、agy_empty_stdout / agy_output_missing は auth failure ではなく output-surface failure として区別される。
- AC4: 診断用 env snapshot(DBUS_SESSION_BUS_ADDRESS_present 等の boolean のみ)と AGY subprocess 実行用 minimal env が分離されており、診断結果に環境変数の値そのものが含まれない。
- AC5: preflight_gemini_headless.py の OAuth sunset 検出に関する参照が setup_check.py の check_auth 関数を SSOT として明記されている(実装コメントまたは docs レベルの整合)。
- AC6: setup_check.py --provider auto --json は AGY attempt の auth/keyring/TTY failure class を provider_attempts 相当の machine-readable attempt detail に保持し、runtime provider fallback policy は実装されていない。
- AC7: WSL2/OAuth 再認証問題と non-TTY silent stdout drop の既知事象・recovery action が skill 内ドキュメントに記載されている。
- AC8: 既存テストが壊れていない。
- AC9: test_preflight_agy.py / test_setup_check.py に non-TTY, WSL2 検出, keyring unavailable, D-Bus missing hint, Google Sign-In required, empty stdout は auth failure ではないこと, redaction(env 値・HOME・絶対パス・auth URL/token を出さないこと), setup_check --provider agy の auth 欠落なし surfacing, setup_check --provider auto の AGY auth/keyring failure class 保持、をカバーするテストケースが追加されている。
Verification Commands
# AC1
$ rg -n "keyring" .claude/skills/gemini-cli-headless-delegation/scripts/setup_check.py
# AC2
$ rg -n "agy_auth_diagnostics_v1" .claude/skills/gemini-cli-headless-delegation/scripts/preflight_agy.py
# AC3
$ rg -n "noninteractive_auth_prompt_required" .claude/skills/gemini-cli-headless-delegation/scripts/preflight_agy.py
# AC4
$ rg -n "DBUS_SESSION_BUS_ADDRESS_present" .claude/skills/gemini-cli-headless-delegation/scripts/preflight_agy.py
# AC5
$ rg -n "check_auth" .claude/skills/gemini-cli-headless-delegation/scripts/preflight_gemini_headless.py
# AC6
$ rg -n "auth_failure_class" .claude/skills/gemini-cli-headless-delegation/scripts/setup_check.py
# AC7
$ rg -n "WSL2" .claude/skills/gemini-cli-headless-delegation/SKILL.md
# AC8
$ uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py
# AC9
$ uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_preflight_agy.py -k "auth or keyring or tty or wsl or recovery" -q
$ rg -n "def test_agy_provider_auth_diagnostics_surfaced" .claude/skills/gemini-cli-headless-delegation/tests/test_setup_check.py
$ rg -n "def test_auto_provider_preserves_agy_auth_failure_class" .claude/skills/gemini-cli-headless-delegation/tests/test_setup_check.pyAllowed Paths
- .claude/skills/gemini-cli-headless-delegation/scripts/setup_check.py
- .claude/skills/gemini-cli-headless-delegation/scripts/preflight_agy.py
- .claude/skills/gemini-cli-headless-delegation/scripts/preflight_gemini_headless.py
- .claude/skills/gemini-cli-headless-delegation/SKILL.md
- .claude/skills/gemini-cli-headless-delegation/references/
- .claude/skills/gemini-cli-headless-delegation/tests/
Runtime Verification Applicability
- decision: not_applicable
- reason: 本 Issue が要求する auth mode / keyring availability / TTY condition / WSL2 検出の各判定は、subprocess 呼び出し結果・環境変数・sys.stdin/stdout/stderr の isatty() を mock した pytest ユニットテスト(AC9 の VC 参照)で静的に検証できる。実サービスへの通信・実 keyring backend への接続・実 Google Sign-In フローの起動は要求しておらず、uv run pytest ユニットテストで完結するため not_applicable とする。実 AGY CLI・実 keyring・実 WSL2 環境での end-to-end 疎通検証は本 Issue の範囲外とし、実施する場合は別途 deferred として後続 Issue で扱う。
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合(ただし本 Issue の Auth Diagnostics Schema セクションで固定する agy_auth_diagnostics_v1 の追加自体は本 Issue で許可済みであり、この Stop Condition の対象外とする)
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合(provider=auto の runtime fallback policy 実装、_normalize_agy_result の empty stdout 不整合是正など、実装: クォータ管理と provider fallback policy を明文化・実装する #1270 / 実装: agent delegation の AGY provider 固有分岐に対するテスト密度を引き上げる #1274 のスコープに踏み込む変更が必要になった場合を含む)
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
- Python(fail-closed diagnostics 実装)
- CLI / subprocess 診断設計
Scope Delta(任意)
N/A
Notes for Reviewer
- 本 Issue は 導入: Gemini CLI → Antigravity CLI (agy) provider migration: 機能同等性評価と改善計画 #1265 の child issue(認証フロー堅牢化)である。
- OWNER レビュー(https://github.com/squne121/loop-protocol/issues/1267#issuecomment-4879955833)の Blocker 1〜7 を反映済み: agy_auth_diagnostics_v1 schema 固定、env snapshot/実行 env 分離方針、OAuth sunset SSOT の明記、failure class 拡張、provider=auto fallback 実装除外、test density 拡張、Stop Conditions の自己矛盾解消。
- WSL2/OAuth 再認証問題、agy -p の non-TTY silent stdout drop の具体的な再現条件・recovery コマンドは実装時に repo 実体(既存 preflight_agy.py の TTY/subprocess 処理)を確認しながら確定する。
- _normalize_agy_result 関数の empty stdout warning/failure_class 不整合是正は 実装: agent delegation の AGY provider 固有分岐に対するテスト密度を引き上げる #1274 の範囲であり、本 Issue はこれを悪化させない(auth failure に誤分類しない)ことのみを要求する。
- VC hygiene fix(2026-07-04): contract-review preflight で AC6 の VC (
rg "provider_attempts") が既存コードの汎用キーに unexpected pass し、AC9 の VC (pytest -k "agy_provider_auth_diagnostics or auto_provider_auth_failure_surface") が未実装テスト名のため pytest exit 5(no tests collected)で blocked と判定されたため、VC 文字列のみを修正した(意味論変更なし)。AC6 は実装が追加する想定のauth_failure_classフィールドへの参照に絞り込んだ。AC9 は pytest node-id 直接指定(exit 4 だが preflight classifier が既存ファイル内の未知ノードをunknowncategory として human_judgment 扱いにするため不採用)ではなく、AC1〜5 と同型のrg -n "def <test_name>" test_setup_check.py静的存在チェックへ変更した(baseline では exit 1 = expected_baseline_fail、実装後は当該テスト関数定義で exit 0 になる)。実装者はこれらのテスト関数名(test_agy_provider_auth_diagnostics_surfaced/test_auto_provider_preserves_agy_auth_failure_class)を採用するか、同等の検証意図を保つ別名を使う場合は本 Issue の VC も追随して更新すること。
Activity
squne121 commentedon Jul 4, 2026
判定: REQUEST_CHANGES
#1267 の方向性は正しいです。ただし、現状のIssue本文のままだと「認証フロー堅牢化」ではなく、
agy -psmoke failure に説明文を足しただけで close される危険があります。#1267 はsetup_check.py/preflight_agy.pyに auth mode・keyring availability・TTY condition を machine-readable に出すことを要求していますが、現行コード上は AGY provider checks がtoolsとagy_preflightを返すだけで、auth/keyring/TTY 専用の結果面がありません。#1267 自体にはコメントがなく、判断材料は親 #1265、関連 child issue、既存 PR、リポジトリ内実装に寄っています。親 #1265 は、単に child issue を close するだけでなく、provider/profile matrix、failure surface、setup/runtime auto の分離、docs/code 矛盾解消まで要求しています。
外部仕様から見た前提
Google は Gemini CLI から Antigravity CLI への移行を案内しつつ、「最初から 1:1 feature parity はない」と明記しています。したがって、AGY 移行の受け入れ条件は smoke 成功では足りず、認証・keyring・TTY・非対話実行の失敗面を分類可能にする必要があります。([Google Developers Blog][1])
Antigravity CLI の公式 README は、CLI が system keyring で認証し、active session がなければ Google Sign-In にフォールバックし、local ではブラウザを開き、remote/SSH では認可URLを出す、と説明しています。同じ README は、Antigravity CLI がコード編集・コマンド実行能力を持つ agentic CLI であり、自律実行、データ流出、prompt injection、supply chain のリスクも明記しています。([GitHub]2)
さらに公式 changelog では、1.0.15 で「Windows の print mode / non-TUI command output が non-TTY 環境で silently discarded される問題」を修正したとあります。#1267 の
non-TTY silent stdout dropは、auth failure と混同してはいけない既知の runtime/platform bug class です。([GitHub]3)Blocker 1:
agy_auth_diagnosticsのスキーマが定義されていない#1267 は
auth mode / keyring availability / TTY conditionを要求していますが、どこに、どのキーで、どの enum で出すかが未定義です。現行preflight_agy.pyの result shape はschema,ok,failure_reason,failure_class,agy,help,smoke,grounded_research,warningsで、auth/keyring/TTY 専用セクションはありません。最低限、以下のような固定スキーマを #1267 本文に追加すべきです。
この schema を
preflight_agy.pyの top-level またはagy_preflight["auth"]に載せ、setup_check.py --provider agy --jsonは同じ構造をそのまま surfacing する形にするのが妥当です。setup_check.py側で別 schema を再構成すると drift します。Blocker 2: 現行の AGY preflight は auth/keyring を見ていない
現行
preflight_agy.pyはagy --version、agy --help、agy -p <sentinel>を実行し、stdout が空なら CI ではagy_output_missing、非CIではagy_empty_stdoutに分類します。これは useful ですが、system keyring availability や OAuth 再認証 requirement の診断ではありません。_minimal_agy_env()はPATH,HOME,LANG,LC_ALL,TERM,XDG_*だけを subprocess に渡します。Linux/headless の SecretService 型 keyring では D-Bus session が重要で、Python keyring のドキュメントも headless Linux では D-Bus session と同一 session 内実行が必要、DBUS_SESSION_BUS_ADDRESSや場合によりDISPLAY/WAYLAND_DISPLAYが問題になると説明しています。 ([Keyring]4)したがって、#1267 は「AGY subprocess に環境変数を増やす」だけでなく、診断用 env snapshot と 実行用 minimal env を分けるべきです。実行用 env は今の安全境界を維持し、診断結果には
DBUS_SESSION_BUS_ADDRESS_present,DISPLAY_present,WAYLAND_DISPLAY_present,WSL_INTEROP_present,WSL_DISTRO_NAME_presentのような boolean だけを載せる。値そのものは出さない。Blocker 3: Gemini OAuth sunset の参照先がIssue本文と実装でズレている
#1267 は
preflight_gemini_headless.pyの既存 OAuth sunset 検出との整合確認を scope に入れています。しかし現行の OAuth sunset / ineligible tier / unauthenticated 判定はsetup_check.py::check_auth()側にあります。preflight_gemini_headless.pyは主に version/help/smoke/trusted directory/gh CLI を見ており、OAuth sunset classifier の SSOT ではありません。修正方針は二択です。
setup_check.py::check_auth()と整合させる」と明記する。setup_check.pyとpreflight_gemini_headless.pyの両方から使う。Allowed Paths には両ファイルが含まれるため、2 も可能ですが、Issue のサイズを抑えるなら 1 で十分です。
Blocker 4:
system_keyring_unavailableだけでは分類が粗すぎるAntigravity CLI は system keyring を使う仕様なので、keyring failure は
unavailableだけでは足りません。最低限、以下を分けるべきです。system_keyring_unavailable: backend/service が見えないsystem_keyring_locked: keyring はあるが unlock が必要system_keyring_backend_missing: Linux SecretService / DBus / platform backend が欠けているsystem_keyring_access_denied: permission/ACL で読めないnoninteractive_auth_prompt_required:agy -pではログインフローを完了できないagy_auth_unknown: stdout/stderr から認証原因と断定できないagy_empty_stdout/agy_output_missing: output surface 問題で、auth とは別分類特に最後が重要です。現行 runtime の
_normalize_agy_result()は、非CI empty stdout でfailure_class="agy_empty_stdout"にしながら、warning 文字列は固定でagy_output_missing: exit 0 but stdout was emptyを返します。これは #1274 の対象でもありますが、#1267 が auth surface を増やすなら、この不整合を「別Issue任せで未解決」と明示しない限り、failure classifier の信頼性を偽装します。Blocker 5:
provider=autoと混ぜると責務が壊れるsetup_check.pyはprovider=autoで AGY を先に試し、失敗時に Gemini checks へ進みます。一方、runtime のrun_gemini_headless.pyはSUPPORTED_PROVIDERS={"gemini","agy"}で、runtimeprovider=autoは #1270 のスコープです。#1267 は auth diagnostics だけを実装し、fallback policy は実装しない方がよいです。
provider=autoではprovider_attempts[].failure_classに auth/keyring/TTY failure を残すだけにし、「AGY auth failure 時に Gemini へ fallback するか」は #1270 の policy に任せるべきです。Blocker 6: test density がACに足りない
現行
test_preflight_agy.pyは shell=False、help flag、timeout、empty stdout、CI empty stdout、grounded quota などを見ていますが、keyring/auth/TTY/WSL2 の専用テストはありません。#1267 のAC4「既存テストが壊れない」だけでは不足です。追加ACとして最低限これを要求してください。
追加すべきテストケースは以下です。
stdin/stdout/stderr isatty=Falseが JSON に出る/proc/versionまたは env mock からis_wsl=Truesystem_keyring_unavailablesystem_keyring_backend_missinggoogle_sign_in_requiredまたはnoninteractive_auth_prompt_requiredagy_empty_stdoutsetup_check --provider agy --json:agy_preflight.authを欠落なく surfacingsetup_check --provider auto --json: failed AGY attempt に auth/keyring failure class が残るBlocker 7: Stop Conditions がIssueの目的と衝突している
#1267 の Stop Conditions には「固定契約のキー集合・スキーマ・型定義の変更が必要なら停止」とあります。しかし #1267 の目的そのものが auth mode / keyring availability / TTY condition の machine-readable schema 追加です。
これは実装エージェントを止める罠になります。Issue本文に
agy_auth_diagnostics_v1を先に定義し、「この schema の追加は本Issueで許可済み」と明記してください。推奨する実装方針
preflight_agy.pyに以下の read-only helper を追加するのが最小変更です。run_preflight()は常に以下を返す。{ "schema": "agy_preflight_result/v1", "auth": { "schema": "agy_auth_diagnostics_v1", "checked": true, "auth_mode": "unknown", "auth_mode_confidence": "unknown", "keyring": { "available": null, "backend_hint": null, "failure_class": null }, "tty": { "stdin_isatty": false, "stdout_isatty": false, "stderr_isatty": false, "noninteractive_mode": true }, "platform": { "os": "linux", "is_wsl": true, "wsl_hint": "wsl2" }, "recovery_action": null } }setup_check.pyはcheck_agy_preflight()の返却を加工しすぎず、agy_preflight["auth"]をそのまま保持する。human-readable output にはauth_mode,keyring.failure_class,tty.noninteractive_mode,platform.is_wslだけを短く出せば十分です。Issue本文に入れるべき差分
#1267 に以下を追加するのが妥当です。
AIエージェント向け実装プロンプト
最終的には、#1267 は「認証が通るか」ではなく「なぜ通らないかを安全に分類できるか」を完了条件にするべきです。現行Issueのままだと、keyring/TTY/WSL2 の本質的な失敗を
agy smoke failedに潰してしまうため、親 #1265 の migration gate には使えません。[1]: https://developers.googleblog.com/en/an-important-update-transitioning-gemini-cli-to-antigravity-cli/ "
squne121 commentedon Jul 4, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jul 4, 2026
Contract Review Result
squne121 commentedon Jul 4, 2026
implement-issue: 実装完了 (2026-07-04)
.claude/worktrees/issue-1267-agy-auth-diagnosticsworktree-issue-1267-agy-auth-diagnosticspnpm typecheck/pnpm lint/pnpm test1350件 /pnpm build)+uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/608件 PASSfix(#1267): iteration-1 CI blockers を解消する
fix(#1267): iteration-2 PR review blockers を解消する
feat: AGY provider の認証フローを堅牢化する (#1316)
fix: PR #1823 レビュー指摘 5 Blocker + 1 Major を反映する
実装: gemini-cli-headless-delegation の profile x provider contract matr…