Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions docs/adr/ADR-0022.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# ADR-0022: Antigravity CLI (agy) management and read-only review profile

- Status: Accepted
- Date: 2026-11-23
- Layer: Current practice / tool management, not Constitution
- Related: [#218](https://github.com/rebuildup/dotfiles/issues/218), [#219](https://github.com/rebuildup/dotfiles/issues/219) (harness follow-up), rebuildup/pc-setup#230 / PR #231 (mise baseline)
- Research: [docs/research/antigravity-cli-2026-11-23.md](../research/antigravity-cli-2026-11-23.md)

## Context

The operator runs Google AI Pro and wants a read-only visual review harness on
macOS driven by the Antigravity CLI (`agy`, Google
`google-antigravity/antigravity-cli`, observed 1.5.14). Before this change the
binary was a standalone `~/.local/bin/agy` install outside any package manager,
and nothing in dotfiles described which parts of its state are managed versus
machine-local.

Two properties of `agy` shape the design:

- **Credential store follows the environment.** With `SSH_CONNECTION`,
`SSH_CLIENT` or `SSH_TTY` present, `agy` selects file-based token storage at
`~/.gemini/antigravity-cli/antigravity-oauth-token`; without them it uses the
OS keyring (macOS Keychain). A desktop login therefore does not authenticate
an SSH session, and an SSH login does not authenticate a desktop session
(upstream: google-antigravity/antigravity-cli#1336, #1514).
- **Headless permissions are deny-by-default for prompts but not for allowed
defaults.** In `agy -p` (print) mode a tool call that would prompt is
auto-denied and reported in `denied_actions`, yet `command(*)` still
executes by default policy. Read-only behaviour therefore requires explicit
`permissions.deny` rules, not just the absence of `--dangerously-skip-permissions`.

## Decision

### 1. Binary ownership stays in pc-setup mise; dotfiles owns only the shim

`agy` is added to `rebuildup/pc-setup` `mise.global.toml` (`latest`, aqua
backend `google-antigravity/antigravity-cli`) alongside `claude`/`codex`.
dotfiles does not duplicate version management. `home/.local/bin/agy` (and the
`antigravity` sibling name via symlink) is a thin launcher that resolves the
mise binary and normalizes the SSH credential-store split; it contains no
version pins and no credentials.

### 2. SSH/keyring normalization rule

When any of `SSH_CONNECTION`/`SSH_CLIENT`/`SSH_TTY` is set **and**
`~/.gemini/antigravity-cli/antigravity-oauth-token` does not exist, the shim
removes those three variables for the child (keeping `SSH_AUTH_SOCK`) so `agy`
uses keyring auth. If the token file exists the environment passes through
unchanged, preserving SSH-native logins. This mirrors the proven approach in
the community `hermes-antigravity-subscription` plugin.

### 3. Managed vs machine-local state boundary

Managed by dotfiles (reproducible, shareable):

- `home/.local/bin/agy` + `home/.local/bin/antigravity` — launcher shim
- `home/.config/agy/review.settings.json` — read-only `--settings` payload,
linked to `~/.config/agy/review.settings.json` on every machine

Machine-local, never committed (contains account state, machine paths or
session history):

- `~/.gemini/antigravity-cli/` — `settings.json` (`trustedWorkspaces` is
machine-specific), OAuth token file, conversation DBs, history, logs
- `~/.gemini/antigravity/`, `~/.cache/antigravity`,
`~/Library/Application Support/antigravity` — IDE-side state
- macOS Keychain items (`svce=gemini`, `acct=antigravity`)

`script/link` is non-destructive: adopting `~/.local/bin/agy` requires moving
the pre-mise standalone binary aside once; `~/.config/agy/` has no prior
state. No composer/generator is added — the managed set is two small static
files, below the threshold that justified `script/claude-settings.ts`.

### 4. Read-only enforcement is permission rules plus post-checks

The review profile is `~/.config/agy/review.settings.json`, passed per
invocation with `--settings` (session-only, never persisted by `agy`):

```json
{ "permissions": { "deny": [
"write_file(*)", "command(*)", "read_url(*)",
"execute_url(*)", "mcp(*)", "unsandboxed(*)" ] } }
```

Verified on 1.5.14: `read_file` still works inside the workspace, `write_file`
and `command` fail with explicit deny-rule errors, and no files are created.
`toolPermission: "strict"` was evaluated and rejected — it prompts before
every tool including reads *even when an allow rule matches*, which makes
headless reads unusable.

`--mode plan` and prompt-level instructions are **not** accepted as the
read-only guarantee. The harness (#219) must additionally treat
`denied_actions`, tool permission errors in the response, and any workspace
mutation as review failure — `status: "SUCCESS"` alone is not sufficient
evidence.

### 5. Subscription auth only; quota is observable

Review runs use the Google account sign-in (`oauth-personal`, Google AI Pro
subscription). `gemini-api-key`, `agent-platform` (Vertex/ADC) and any
pay-as-you-go route are out of scope and must not be configured. `agy -p
"/quota"` returns structured quota state (weekly + 5-hour windows per model
group, `remaining_fraction`, `reset_time`) usable by a future scheduler.

## Consequences

- `agy` resolves through mise on machines that applied pc-setup; the shim
fails closed with a clear message where mise has no `agy`.
- SSH-invoked `agy` (including future herdr/Rex workers) authenticates via
keyring as long as no SSH token file exists; a deliberate SSH login keeps
working through the token file.
- The read-only guarantee depends on the deny payload staying in sync with
`agy`'s permission action set (`read_file`, `write_file`, `command`,
`read_url`, `execute_url`, `mcp`, `unsandboxed`); new sensitive actions
upstream must be re-evaluated when bumping `agy`.
- Harness construction, herdr routing and quota scheduling are deferred to
#219.
101 changes: 101 additions & 0 deletions docs/research/antigravity-cli-2026-11-23.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Antigravity CLI (agy) 実機調査メモ — 2026-11-23

Issue #218 の実装根拠。対象マシン: macOS arm64、agy 1.5.14
(`~/.local/bin/agy` スタンドアロンおよび mise aqua 1.5.14、同一バイナリサイズ)。

## 実行ファイル・バージョン・PATH

- `which agy` → `/Users/rebui/.local/bin/agy`(mise 管理前)。mise 側は
`~/.local/share/mise/shims/{agy,antigravity}` と
`~/.local/share/mise/installs/agy/1.5.14/{agy -> antigravity}`。
- PATH では `~/.local/bin` が mise shims より前にあるため、mise 導入後も
スタンドアロンバイナリが残ると shim が隠れる。退避が必須。

## 認証状態(秘密情報を含まない範囲で確認)

- `agy models` / `agy -p` は SSH 環境変数ありだと
`Using file-based token storage because SSH session detected` をログに出し、
`~/.gemini/antigravity-cli/antigravity-oauth-token` を探して未ログイン扱い。
- `env -u SSH_CONNECTION -u SSH_CLIENT -u SSH_TTY agy models` で keyring 認証が
成功しモデル一覧を取得(Google アカウントのサブスクリプション認証)。
- キーチェーンには `svce=gemini` / `acct=antigravity` の項目あり(値は未読)。
- `agy acp` の `initialize` 応答 `authMethods`:
`oauth-personal`(Google アカウント)、`oauth-business`(Gemini Enterprise)、
`gemini-api-key`、`agent-platform`。本件は `oauth-personal` のみ使用。

## 非対話実行・構造化出力・画像入力

- `agy -p "..."` : 応答テキストを stdout へ返す。`--print-timeout` で制限可。
- `--output-format json` : `conversation_id` / `status` / `response` /
`duration_seconds` / `num_turns` / `usage{input,output,thinking,
cache_read,total}_tokens` / `denied_actions` を返す。
- `--json-schema <schema>` : structured output を強制(stream-json では最終結果のみ)。
- 画像入力: プロンプト内 `@/absolute/path.png` メンションで画像を読ませられる
(8x8 赤 PNG で「Red」と正答)。ACP `initialize` の
`promptCapabilities.image: true` とも一致。
- `--input-format stream-json` + `--output-format stream-json` で NDJSON 対話型
print mode あり(複数ターンのバッチ実行向け)。

## ReadOnly 検証(実測)

作業ディレクトリ `/tmp/agy-ro-test` で実施。

| 条件 | write_file | command | 結果 |
| --- | --- | --- | --- |
| `agy -p`(既定) | auto-deny(`denied_actions` に記録) | **実行された**(`touch d.txt` 成功) | command は既定で許可 |
| `agy -p --sandbox` | auto-deny | **実行された**(`touch e.txt` 成功) | sandbox は terminal 制限であり write 禁止ではない |
| `agy -p --settings <deny payload>` | deny rule で拒否 | deny rule で拒否 | `f.txt`/`g.txt` 未作成、read_file は正常 |
| `agy -p --mode plan` | 計画提示のみ | — | ファイル未作成だが plan は保証ではない |
| `toolPermission: "strict"` + allow read_file | read_file も prompt 化 | — | headless では read も auto-deny。**不採用** |

- deny payload(`~/.config/agy/review.settings.json` と同一):
`write_file(*)`, `command(*)`, `read_url(*)`, `execute_url(*)`, `mcp(*)`,
`unsandboxed(*)` を deny。read_file は workspace 内で既定許可のまま。
- deny rule による拒否は tool error として response 本文に現れ、
`denied_actions` は空だった。検証側は `denied_actions`・permission error
本文・workspace 差分の複数シグナルを見る必要がある。
- `status: "SUCCESS"` は禁止操作の失敗を含んでいても返る。レビュー成否の
判定に status のみを使ってはいけない。

## ACP (`agy acp`)

- stdio JSON-RPC。`initialize` に対し `protocolVersion: 1`、
`agentInfo: Antigravity ACP Server 1.5.14`、capabilities
(`loadSession`、`promptCapabilities.image=true`、session resume/close/
load/list、`additionalDirectories`)を返す。
- フラグ: `--app-data-dir`、`--gemini-dir`、`--cli_dir_name`、`--sandbox`、
`--process-per-session`、`--login`(ACP terminal auth)。
- 別 `app-data-dir` / `gemini-dir` を指定すればプロファイル隔離は技術的に可能
だが、認証情報もその配下に分離されるため別途ログインが必要。今回は未採用。

## クォータ / 使用量

- `agy -p "/quota"` が `command.name=usage` の構造化データを返す:
モデルグループ別(Gemini Models / Claude and GPT models / 個別モデル)に
weekly と 5-hour window の `remaining_fraction`・`reset_time`・説明文。
`num_turns: 0` で LLM 呼び出しなしに取得可能。
- 内部 RPC に `GetUserQuotaSummary` / `RetrieveUserQuota` /
`fetchQuotaStatus` が存在(文字列確認のみ、直接呼び出しは未検証)。
- サブスクリプション quota であり API 従量課金ではない。スケジューラは
`remaining_fraction` と `reset_time` を見て投入量を決められる。

## 設定ファイル配置

- `~/.gemini/antigravity-cli/settings.json`: `trustedWorkspaces`
(マシン固有)等。セッション限定上書きは `--settings`(JSON 文字列または
ファイルパス、保存されない)。
- permissions の action: `read_file`, `write_file`, `command`, `read_url`,
`execute_url`, `mcp`, `unsandboxed`。`action(target)` 記法、
deny > ask > allow の優先順。`write_file` allow は `read_file` を内包、
`read_file` deny は `write_file` も阻害。
- `toolPermission` 値: `request-review`(既定)/ `proceed-in-sandbox` /
`always-proceed` / `strict`。

## 未検証・後続

- Windows / Linux での agy 動作(pc-setup lock 上は asset 解決済み)。
- `--json-schema` の実スキーマ強制、stream-json の複数ターン挙動。
- ACP 経由の session/prompt 実装詳細(harness 側 Issue #219)。
- keyring 認証が SSH 越しのヘッドレス実行で常に使えるか(本機では成功)。
- `JETSKI_APP_DATA_DIR` 等の環境変数による app-data-dir 上書きの有無と
安全性。
13 changes: 13 additions & 0 deletions home/.config/agy/review.settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://antigravity.google/schemas/v1/settings.json",
"permissions": {
"deny": [
"write_file(*)",
"command(*)",
"read_url(*)",
"execute_url(*)",
"mcp(*)",
"unsandboxed(*)"
]
}
}
64 changes: 64 additions & 0 deletions home/.local/bin/agy
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
# `agy` / `antigravity` — Antigravity CLI launcher shim.
# Installed into ~/.local/bin by script/link. The real binary is mise-managed
# (pc-setup mise.global.toml, aqua:google-antigravity/antigravity-cli); this
# shim only normalizes one environment split before exec'ing it:
#
# agy picks its credential store from the environment: with SSH session
# markers (SSH_CONNECTION / SSH_CLIENT / SSH_TTY) it uses file-based token
# storage at ~/.gemini/antigravity-cli/antigravity-oauth-token; without them
# it uses the OS keyring. A machine that logged in from the desktop keeps its
# credential in the keyring only, so the same `agy` over SSH (including
# herdr/Rex workers launched from a remote session) demands a fresh OAuth
# login even though the account is signed in.
#
# When an SSH marker is present AND no file-based token exists, the markers
# are removed for the child so agy falls back to keyring auth. SSH_AUTH_SOCK
# is preserved. When the token file exists the environment is passed through
# unchanged, so an SSH-native login keeps working (upstream issue
# google-antigravity/antigravity-cli#1336 documents the two-store split).
set -euo pipefail

tool="$(basename -- "$0")"
case "$tool" in
agy|antigravity) ;;
*) printf 'agy: unexpected invocation name %s\n' "$tool" >&2; exit 2 ;;
esac

# Resolve the real binary: prefer `mise which` (version-correct), else the
# first PATH entry that is not this shim. Never exec ourselves.
self="$(cd -- "$(dirname -- "$0")" && pwd -P)/$(basename -- "$0")"
real=""
if command -v mise >/dev/null 2>&1; then
real="$(mise which "$tool" 2>/dev/null || true)"
fi
if [[ -z "$real" ]]; then
IFS=':' read -ra path_dirs <<< "$PATH"
for dir in "${path_dirs[@]}"; do
candidate="$dir/$tool"
[[ -x "$candidate" ]] || continue
candidate_real="$(cd -- "$(dirname -- "$candidate")" && pwd -P)/$(basename -- "$candidate")"
if [[ "$candidate_real" != "$self" ]]; then
real="$candidate"
break
fi
done
fi

if [[ -z "$real" ]]; then
printf 'agy: %s not found on PATH; install it via mise (pc-setup mise.global.toml)\n' "$tool" >&2
exit 127
fi

ssh_marked=0
for var in SSH_CONNECTION SSH_CLIENT SSH_TTY; do
if [[ -n "${!var:-}" ]]; then ssh_marked=1; fi
done

token_file="${HOME}/.gemini/antigravity-cli/antigravity-oauth-token"

if [[ "$ssh_marked" -eq 1 && ! -e "$token_file" ]]; then
exec env -u SSH_CONNECTION -u SSH_CLIENT -u SSH_TTY "$real" "$@"
fi

exec "$real" "$@"
1 change: 1 addition & 0 deletions home/.local/bin/antigravity
1 change: 1 addition & 0 deletions script/shell-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ evals/agent-router/controls.sh
evals/system-quality/challenge.sh
home/.claude/statusline-command.sh
home/.local/bin/agent
home/.local/bin/agy
home/.local/bin/devices
home/.local/bin/ocr-go-key
script/agent/infisical-key.sh
Expand Down
Loading