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
29 changes: 28 additions & 1 deletion crates/axe-core/src/activity.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -120,6 +121,32 @@ pub(crate) fn pi(v: &Value) -> Option<String> {
})
}

/// 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<String> {
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<String> {
msg["content"]
Expand Down
7 changes: 5 additions & 2 deletions crates/axe-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
61 changes: 59 additions & 2 deletions crates/axe-core/src/failure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -312,6 +313,62 @@ pub fn pi(path: &Path) -> Option<Failure> {
})
}

/// 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<Failure> {
let mut agy_error: Option<Value> = None;
let mut result: Option<Value> = 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<Failure> {
Expand Down
177 changes: 175 additions & 2 deletions crates/axe-core/src/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ pub struct Harness {
/// for installs (`npm install -g <package>@<version>`); `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-<bot>`, 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`]).
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"),
},
];

Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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,
Expand All @@ -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::<String>();
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();
}
Expand Down Expand Up @@ -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");
}
}
Loading
Loading