From b229c7ef29adef54ab8220176751e26384a9c899 Mon Sep 17 00:00:00 2001 From: haojr Date: Wed, 2 Dec 2026 09:48:29 +0000 Subject: [PATCH] feat: Antigravity harness row with Google sign-in login - antigravity row (agy, verified on 1.5.22): agy --output-format stream-json --dangerously-skip-permissions --print={prompt}, resume with --conversation {session_id} (jsonl:conversation_id; an empty id is no session), --model and --effort, bots via --agent axe- with the system prompt as a custom agent file in the runtime home - Google sign-in is its only login (owner msg #6704): agy acp --login relays the accounts.google.com link and takes the code or landing URL on stdin from the sealed form, like Claude's web sign-in; probe agy usage --json (exits 1 when signed out) - agy keeps its login under $HOME, so a runtime's login directory is its HOME; runtime::link_home links every other entry of the node user's home into it before each launch (git, gh, axe keep working), and Harness::cli_env sets AGY_CLI_DISABLE_AUTO_UPDATE and AGY_CLI_FORCE_FILE_TOKEN_STORAGE on every launch - LogFormat::Antigravity: per-run usage from agent_response steps, failures from the result and its AGY_ERROR line (401 and signed out as auth_invalid, 429/5xx as provider_unavailable), activity, and conversation retention under .gemini/antigravity-cli - Telegram: Antigravity under Add runtime, "Google sign-in" button - Fixtures from agy 1.5.22 against a local Gemini API mock - docs/user: runtimes, runtimes from Telegram, config, cost Task 2452. Co-Authored-By: Claude Opus 5.5 --- crates/axe-core/src/activity.rs | 29 +- crates/axe-core/src/config.rs | 7 +- crates/axe-core/src/failure.rs | 61 ++++- crates/axe-core/src/harness.rs | 177 ++++++++++++- crates/axe-core/src/log_format.rs | 21 +- crates/axe-core/src/retention.rs | 67 ++++- crates/axe-core/src/runtime.rs | 220 +++++++++++++++- crates/axe-core/src/runtime_views.rs | 3 +- crates/axe-core/src/usage.rs | 92 ++++++- crates/axe-node/src/agent_proc.rs | 53 +++- crates/axe-node/src/dispatch.rs | 2 +- crates/axe-node/src/dispatch/bots.rs | 28 +- crates/axe-telegram/src/telegram.rs | 39 ++- crates/axe/tests/config.rs | 8 +- crates/axe/tests/dispatch.rs | 42 +++ .../antigravity/antigravity-401.jsonl | 6 + .../antigravity/antigravity-429.jsonl | 14 + .../antigravity/antigravity-503.jsonl | 14 + .../antigravity/antigravity-bad-model.jsonl | 28 ++ .../antigravity/antigravity-resume.jsonl | 5 + .../antigravity/antigravity-run.jsonl | 4 + .../antigravity/antigravity-signed-out.jsonl | 8 + .../antigravity/antigravity-tool.jsonl | 7 + .../axe/tests/fixtures/log-format/golden.json | 248 ++++++++++++++++++ crates/axe/tests/log_format.rs | 10 +- crates/axe/tests/telegram.rs | 11 +- docs/user/concepts/routines-bots-goals.md | 7 + docs/user/concepts/runtimes.md | 36 ++- docs/user/guides/runtimes-from-telegram.md | 14 +- docs/user/reference/config.md | 3 +- 30 files changed, 1218 insertions(+), 46 deletions(-) create mode 100644 crates/axe/tests/fixtures/antigravity/antigravity-401.jsonl create mode 100644 crates/axe/tests/fixtures/antigravity/antigravity-429.jsonl create mode 100644 crates/axe/tests/fixtures/antigravity/antigravity-503.jsonl create mode 100644 crates/axe/tests/fixtures/antigravity/antigravity-bad-model.jsonl create mode 100644 crates/axe/tests/fixtures/antigravity/antigravity-resume.jsonl create mode 100644 crates/axe/tests/fixtures/antigravity/antigravity-run.jsonl create mode 100644 crates/axe/tests/fixtures/antigravity/antigravity-signed-out.jsonl create mode 100644 crates/axe/tests/fixtures/antigravity/antigravity-tool.jsonl diff --git a/crates/axe-core/src/activity.rs b/crates/axe-core/src/activity.rs index e5ab50f..ffb7b3d 100644 --- a/crates/axe-core/src/activity.rs +++ b/crates/axe-core/src/activity.rs @@ -1,7 +1,8 @@ //! Short "what is the agent doing" text from agent JSONL output, read by the //! run's harness's parser (`LogFormat::activity`): claude //! `--output-format stream-json`, codex `exec --json`, opencode -//! `run --format json` or pi `--mode json`. +//! `run --format json`, pi `--mode json` or agy `-p --output-format +//! stream-json`. use std::io::{Read, Seek, SeekFrom}; use std::path::Path; @@ -120,6 +121,32 @@ pub(crate) fn pi(v: &Value) -> Option { }) } +/// agy -p --output-format stream-json (Antigravity): a tool step as it +/// starts, a model reply's text, a failed result. +pub(crate) fn antigravity(v: &Value) -> Option { + Some(match v.get("event")?.as_str()? { + "step_update" => { + let step = &v["step_update"]; + match step["step_type"].as_str()? { + "tool" if step["state"] == "ACTIVE" => { + let info = &step["tool_info"]; + let name = info["name"].as_str().or(step["tool_name"].as_str())?; + match tool_arg(&info["parameters"]) { + Some(arg) => format!("{name}: {arg}"), + None => name.to_string(), + } + } + "agent_response" => format!("says: {}", nonempty(&step["text_delta"])?), + _ => return None, + } + } + "result" if v["result"]["status"] == "ERROR" => { + format!("error: {}", v["result"]["error"].as_str().unwrap_or("")) + } + _ => return None, + }) +} + /// The last tool call or non-empty text block of a claude assistant message. fn claude_message(msg: &Value) -> Option { msg["content"] diff --git a/crates/axe-core/src/config.rs b/crates/axe-core/src/config.rs index 45312a3..2b38457 100644 --- a/crates/axe-core/src/config.rs +++ b/crates/axe-core/src/config.rs @@ -1572,12 +1572,15 @@ session = "none" /// Extra placeholders only `bot_args` may use. `system_prompt_toml` and /// `hooks_toml` are the system prompt and the inbox /// hooks as TOML values, for CLIs that take them as config overrides (Codex -/// `-c key=value`). -pub const BOT_VARS: [&str; 4] = [ +/// `-c key=value`); `bot_agent` is the name of the agent file a bot run +/// writes its system prompt to, for CLIs that read it from one +/// (`harness::Harness::bot_agent_file`, Antigravity `--agent`). +pub const BOT_VARS: [&str; 5] = [ "system_prompt_file", "settings_file", "system_prompt_toml", "hooks_toml", + "bot_agent", ]; /// Rejects `{name}` placeholders that are not in [`TEMPLATE_VARS`] or `extra`. diff --git a/crates/axe-core/src/failure.rs b/crates/axe-core/src/failure.rs index f39b902..a98d5e1 100644 --- a/crates/axe-core/src/failure.rs +++ b/crates/axe-core/src/failure.rs @@ -2,8 +2,9 @@ //! (`log_format::LogFormat::failure`): Claude Code stream-json //! (`claude -p --output-format stream-json`, [`claude`]), Codex JSONL //! (`codex exec --json`, [`codex`]), OpenCode JSON lines -//! (`opencode run --format json`, [`opencode`]) or Pi JSON lines -//! (`pi --mode json`, [`pi`]). +//! (`opencode run --format json`, [`opencode`]), Pi JSON lines +//! (`pi --mode json`, [`pi`]) or Antigravity stream-json +//! (`agy -p --output-format stream-json`, [`antigravity`]). //! //! Four classes are not the task's fault, so the node retries them later //! instead of escalating: an exhausted usage quota, an exhausted prepaid @@ -312,6 +313,62 @@ pub fn pi(path: &Path) -> Option { }) } +/// Antigravity `agy -p --output-format stream-json`: the failure of the +/// run's `result` (`status: "ERROR"`). A failed model call also writes +/// `AGY_ERROR: {json}` to stderr, with the HTTP `error_code` and the API's +/// `status` (`UNAUTHENTICATED`, `RESOURCE_EXHAUSTED`); the CLI retries a +/// `retryable` one itself (about two minutes for a 429) before it writes +/// it. A run that is not signed in waits 60 s for a sign-in nobody gives, +/// then fails "authentication failed or timed out". As seen from 1.5.22 +/// against a Gemini API mock answering 401, 429 and 503, and signed out +/// (`tests/fixtures/antigravity/`). +pub fn antigravity(path: &Path) -> Option { + let mut agy_error: Option = None; + let mut result: Option = None; + scan( + path, + &["\"event\":\"result\""], + |t| t.starts_with("AGY_ERROR: "), + |text, v| { + if let Some(json) = text.trim().strip_prefix("AGY_ERROR: ") { + agy_error = serde_json::from_str(json).ok(); + return; + } + let Some(v) = v else { return }; + if v["event"] == "result" { + result = Some(v["result"].clone()); + } + }, + )?; + let r = result?; + if r["status"] != "ERROR" { + return None; + } + let message = r["error"].as_str().unwrap_or("").to_string(); + let lower = message.to_lowercase(); + if lower.starts_with("authentication failed") || lower.contains("authentication required") { + return Some(Failure { + class: AUTH_INVALID, + status: None, + message, + retry_at: None, + }); + } + let e = agy_error?; + let status = e["error_code"].as_i64(); + let class = match (e["status"].as_str().unwrap_or(""), status) { + ("UNAUTHENTICATED", _) | (_, Some(401)) => AUTH_INVALID, + (_, Some(s)) if transient_status(s) => PROVIDER_UNAVAILABLE, + _ => return None, + }; + Some(Failure { + class, + status, + message, + retry_at: None, + }) +} + /// Codex reports failures as text only; the phrases are its `CodexErr` /// messages (openai/codex `codex-rs/protocol/src/error.rs`). fn codex_message(message: &str) -> Option { diff --git a/crates/axe-core/src/harness.rs b/crates/axe-core/src/harness.rs index bfbcbbb..4ddaef5 100644 --- a/crates/axe-core/src/harness.rs +++ b/crates/axe-core/src/harness.rs @@ -160,6 +160,20 @@ pub struct Harness { /// for installs (`npm install -g @`); `None`: the /// CLI is installed by hand. pub package: Option<(&'static str, &'static str)>, + /// Variables every launch of the CLI gets (runs, logins, probes), on + /// any login: Antigravity's self-update off, as axe pins the version. + pub cli_env: &'static [(&'static str, &'static str)], + /// For a CLI that keeps its login under `$HOME` (its [`Harness::login_env`] + /// is `HOME`): the paths under a home that are the CLI's own. A + /// runtime's own home links every other entry of the node user's home + /// ([`crate::runtime::link_home`]), so the tools a run uses (git, gh, + /// axe, caches) find their usual files; these stay the runtime's. + pub home_own: &'static [&'static str], + /// Where a bot run's system prompt goes for a CLI that reads it from an + /// agent file instead of an argument: that file under the runtime's + /// login directory, with `{bot_agent}` (`axe-`, which + /// [`Harness::bot_args`] names). Written before each bot run. + pub bot_agent_file: Option<&'static str>, } /// A config file axe writes for a runtime ([`Harness::config`]). @@ -383,6 +397,9 @@ pub const HARNESSES: &[Harness] = &[ inbox_hook: true, config: ConfigFile::None, package: None, + cli_env: &[], + home_own: &[], + bot_agent_file: None, }, Harness { name: "codex", @@ -455,6 +472,9 @@ pub const HARNESSES: &[Harness] = &[ inbox_hook: false, config: ConfigFile::None, package: None, + cli_env: &[], + home_own: &[], + bot_agent_file: None, }, // OpenCode 2.x (`@opencode/cli`), verified on 2.4.3 in a scratch home // against a local provider mock (store doc @@ -531,6 +551,9 @@ pub const HARNESSES: &[Harness] = &[ inbox_hook: false, config: ConfigFile::OpenCode, package: Some(("@opencode/cli", "2.4.3")), + cli_env: &[], + home_own: &[], + bot_agent_file: None, }, // Pi (`@earendil-works/pi-coding-agent`), verified on 1.7.0 in a scratch // home against a local provider mock (store doc @@ -596,6 +619,88 @@ pub const HARNESSES: &[Harness] = &[ inbox_hook: false, config: ConfigFile::Pi, package: Some(("@earendil-works/pi-coding-agent", "1.7.0")), + cli_env: &[], + home_own: &[], + bot_agent_file: None, + }, + // Antigravity CLI (`agy`), verified on 1.5.22 (installed from Google's + // manifest, https://antigravity.google/docs/getting-started?tab=cli; not + // on npm) in a scratch home against a local Gemini API mock (store doc + // harvis/research/20261202-antigravity-harness.md, section 8). Flags: + // https://antigravity.google/docs/cli/reference/ and + // https://antigravity.google/docs/cli/headless/ (`-p`/`--print` takes the + // prompt as its value; `--conversation` resumes; without + // `--dangerously-skip-permissions` a blocked tool is soft-denied and the + // run still exits 0). The CLI picks the conversation id (`init`), and + // keeps everything under `$HOME/.gemini` and `$HOME/.config/antigravity`: + // no variable moves it, so a runtime's login directory is its HOME. + Harness { + name: "antigravity", + display: "Antigravity", + bin: "agy", + name_prefix: "antigravity", + agent: "antigravity", + launch: &[ + "agy", + "--output-format", + "stream-json", + "--dangerously-skip-permissions", + "--print={prompt}", + ], + resume: &[ + "agy", + "--output-format", + "stream-json", + "--dangerously-skip-permissions", + "--conversation", + "{session_id}", + "--print={prompt}", + ], + session: "jsonl:conversation_id", + login_env: &[("HOME", "")], + default_login: "~", + // Google by the owner's own Google account (AI Pro / Ultra quota); + // no API key login (owner msg #6704). + providers: Providers::Fixed("google", None), + quota: QuotaSource::None, + meter: Meter::None, + // `agy usage` ("Show account quota usage", `agy help usage` on + // 1.5.22) exits 1 at once when signed out ("Please sign in to view + // account usage"). + probe: &["agy", "usage", "--json"], + // `agy acp --login`: "Log in with Google interactively, then exit + // (ACP terminal auth)" (`agy help acp`; https://antigravity.google/docs/cli/acp/). + // It prints an accounts.google.com URL and reads the code, or the + // URL the page lands on, from stdin. + logins: &[("device", None, "Google sign-in")], + login_checks: &[], + stdin_login: &[], + device_login: (&["acp", "--login"], true), + shared: &[], + // The bot's system prompt as a custom agent + // (https://antigravity.google/docs/cli/commands/agents/: "Global: + // ~/.gemini/config/agents/{agent_name}/agent.md", YAML `name` and + // `description`, then the prompt), selected with `--agent`. + bot_args: &["--agent", "{bot_agent}"], + bot_env: &[], + model_args: &["--model", "{model}"], + effort_args: &["--effort", "{effort}"], + model_effort_args: &[], + log: LogFormat::Antigravity, + inbox_hook: false, + config: ConfigFile::None, + package: None, + // `AGY_CLI_DISABLE_AUTO_UPDATE`: https://antigravity.google/docs/cli/troubleshooting/. + // `AGY_CLI_FORCE_FILE_TOKEN_STORAGE` is undocumented (seen in 1.5.21 + // and 1.5.22 logs: "Using file-based token storage because + // AGY_CLI_FORCE_FILE_TOKEN_STORAGE is set"): the login stays a file + // in the runtime's home, never the user's shared desktop keyring. + cli_env: &[ + ("AGY_CLI_DISABLE_AUTO_UPDATE", "true"), + ("AGY_CLI_FORCE_FILE_TOKEN_STORAGE", "true"), + ], + home_own: &[".gemini", ".config/antigravity"], + bot_agent_file: Some(".gemini/config/agents/{bot_agent}/agent.md"), }, ]; @@ -672,6 +777,9 @@ const TEST_HARNESSES: &[Harness] = &[Harness { inbox_hook: false, config: ConfigFile::None, package: None, + cli_env: &[], + home_own: &[], + bot_agent_file: None, }]; /// The harness whose CLI binary is `bin` (a file name). @@ -744,7 +852,12 @@ mod tests { if !table { assert_eq!(h.probe.first(), Some(&h.bin), "{n}: probe runs the CLI"); assert!(h.probe.len() > 1, "{n}: probe"); - assert!(!h.shared.is_empty(), "{n}: shared"); + // A CLI whose login is a home links the node user's home + // whole ([`Harness::home_own`]) instead of a few entries. + assert!( + !h.shared.is_empty() || !h.home_own.is_empty(), + "{n}: shared" + ); } else { assert!( crate::provider::of_harness(n).count() >= 2, @@ -769,7 +882,23 @@ mod tests { } // A bot's system prompt reaches the CLI one way or the other. let bot = h.bot_args.join(" ") + &h.bot_env.iter().map(|(_, v)| *v).collect::(); - assert!(bot.contains("{system_prompt"), "{n}: bot_args or bot_env"); + match h.bot_agent_file { + Some(f) => { + assert!(bot.contains("{bot_agent}"), "{n}: bot_args name the agent"); + assert!(f.contains("{bot_agent}") && !f.starts_with('/'), "{n}: {f}"); + } + None => assert!(bot.contains("{system_prompt"), "{n}: bot_args or bot_env"), + } + for (var, value) in h.cli_env { + crate::sealed::check_env_name(var).unwrap(); + assert!(!value.is_empty(), "{n}: {var}"); + } + if !h.home_own.is_empty() { + assert_eq!(h.login_env, &[("HOME", "")], "{n}: home_own needs HOME"); + for p in h.home_own { + assert!(!p.starts_with('/') && !p.contains(".."), "{n}: {p}"); + } + } for (var, _) in h.bot_env { crate::sealed::check_env_name(var).unwrap(); } @@ -909,4 +1038,48 @@ mod tests { ["--model", "deepseek/deepseek-flash", "--thinking", "high"] ); } + /// Antigravity (`agy` 1.5.22): the prompt as `--print`'s value, so model, + /// effort and bot arguments go in ahead of it; resume by the + /// conversation id the CLI printed; tools never ask (a soft-denied tool + /// still exits 0); its home is its login; Google sign-in only. + #[test] + fn antigravity_runs_agy_headless_with_its_own_home() { + let h = get("antigravity").unwrap(); + assert_eq!(by_bin("agy").map(|h| h.name), Some("antigravity")); + assert_eq!( + h.launch, + [ + "agy", + "--output-format", + "stream-json", + "--dangerously-skip-permissions", + "--print={prompt}" + ] + ); + assert_eq!( + &h.resume[4..], + ["--conversation", "{session_id}", "--print={prompt}"] + ); + assert_eq!(h.session, "jsonl:conversation_id"); + assert_eq!(h.login_env, &[("HOME", "")]); + assert_eq!(h.home_own, &[".gemini", ".config/antigravity"]); + assert_eq!(h.logins, &[("device", None, "Google sign-in")]); + assert_eq!(h.device_login, (&["acp", "--login"][..], true)); + assert_eq!(crate::provider::of_harness("antigravity").count(), 0); + assert_eq!( + crate::rule::Use { + harness: "antigravity".into(), + model: Some("gemini-4-neon-high".into()), + effort: Some("high".into()), + } + .args(), + ["--model", "gemini-4-neon-high", "--effort", "high"] + ); + assert_eq!(h.bot_args, ["--agent", "{bot_agent}"]); + assert_eq!( + fill(&[h.bot_agent_file.unwrap()], "bot_agent", "axe-os-bot"), + [".gemini/config/agents/axe-os-bot/agent.md"] + ); + assert!(crate::sealed::check_env_name("HOME").is_err(), "reserved"); + } } diff --git a/crates/axe-core/src/log_format.rs b/crates/axe-core/src/log_format.rs index 05e596c..7dbdd68 100644 --- a/crates/axe-core/src/log_format.rs +++ b/crates/axe-core/src/log_format.rs @@ -32,6 +32,13 @@ pub enum LogFormat { /// `tool_execution_*`, `auto_retry_*`, and `agent_settled` last. /// Transcripts `/sessions//