diff --git a/crates/axe-core/src/form.rs b/crates/axe-core/src/form.rs index fca3643..02343f0 100644 --- a/crates/axe-core/src/form.rs +++ b/crates/axe-core/src/form.rs @@ -335,6 +335,42 @@ impl Forms { open_prompts_in(&forms, at) } + /// Closes the open forms other than `keep` that ask for the same + /// runtime login (runtime and provider) as `keep`: a new login attempt + /// replaces the form an earlier one left open, so the owner never holds + /// two. A replaced form prompted by `bot` is closed without a message + /// (the new prompt's keyboard, sent there next, drops its button); + /// elsewhere the server closes its prompt as for any finished form. + /// Returns the replaced forms' ids. + pub fn supersede(&self, keep: &str, bot: &str, now: i64) -> Vec { + let mut forms = self.lock(); + let Some(sealed::Target::Runtime { + runtime, provider, .. + }) = forms.get(keep).map(|f| f.spec.target.clone()) + else { + return vec![]; + }; + let mut out = vec![]; + for f in forms.values_mut() { + let same = matches!(&f.spec.target, sealed::Target::Runtime { + runtime: r, provider: p, .. + } if *r == runtime && *p == provider); + if f.spec.form == keep || f.state != OPEN || !same { + continue; + } + f.state = EXPIRED; + f.error = Some("replaced by a newer login form".into()); + f.finished = Some(now); + f.closed = f.prompt.as_ref().is_none_or(|p| p.bot == bot); + out.push(f.spec.form.clone()); + } + if !out.is_empty() { + self.save(&forms); + self.cv.notify_all(); + } + out + } + /// Forgets a prompt that could not be sent. pub fn clear_prompt(&self, form: &str) { let mut forms = self.lock(); @@ -846,4 +882,68 @@ mod tests { assert!(t.contains("\nFor willy · closes in 1h\n"), "{t}"); assert!(!t.contains("Sealed form"), "{t}"); } + + #[test] + fn a_new_login_form_replaces_the_open_one_for_that_runtime() { + let forms = Forms::default(); + let key = crate::sealed::Key::random(); + let login = |runtime: &str, login: &str, provider: Option<&str>| Request { + purpose: "Log in".into(), + target: Target::Runtime { + runtime: runtime.into(), + login: login.into(), + provider: provider.map(String::from), + }, + fields: vec![Field::parse("secret:secret:required").unwrap()], + ttl: Some(900), + from: "/runtimes".into(), + }; + let add = |r: &Request| { + let (_, s) = key.sign("d", r, 0).unwrap(); + forms.add(r, s, 0).unwrap().spec.form + }; + let at = |bot: &str| Prompt { + bot: bot.into(), + chat: 7, + }; + let first = add(&login("agy-1", "code", None)); + forms.prompt_at(&first, &at("aux")); + let elsewhere = add(&login("agy-1", "token", None)); + forms.prompt_at(&elsewhere, &at("grp")); + let other_runtime = add(&login("agy-2", "code", None)); + let other_provider = add(&login("agy-1", "api_key", Some("deepseek"))); + let task = add(&req()); + let second = add(&login("agy-1", "code", None)); + + let mut replaced = forms.supersede(&second, "aux", 5); + replaced.sort(); + let mut want = vec![first.clone(), elsewhere.clone()]; + want.sort(); + assert_eq!(replaced, want); + for f in [&first, &elsewhere] { + let f = forms.get(f, 5).unwrap(); + assert_eq!(f.state, EXPIRED); + assert_eq!(f.error.as_deref(), Some("replaced by a newer login form")); + } + for f in [&second, &other_runtime, &other_provider, &task] { + assert_eq!(forms.get(f, 5).unwrap().state, OPEN, "{f}"); + } + // The new prompt in aux's chat holds only the new form's button. + let open: Vec = forms + .prompt_at(&second, &at("aux")) + .into_iter() + .map(|f| f.spec.form) + .collect(); + assert_eq!(open, std::slice::from_ref(&second)); + // The one prompted by another bot is closed there by the server; + // the one in aux's chat needs no message. + let closing: Vec = forms + .take_closing(10) + .into_iter() + .map(|(f, _)| f.spec.form) + .collect(); + assert_eq!(closing, [elsewhere]); + // A replaced form takes no reply; nothing to replace twice. + assert!(forms.supersede(&second, "aux", 11).is_empty()); + } } diff --git a/crates/axe-core/src/harness.rs b/crates/axe-core/src/harness.rs index 4ddaef5..e6859fd 100644 --- a/crates/axe-core/src/harness.rs +++ b/crates/axe-core/src/harness.rs @@ -476,6 +476,85 @@ pub const HARNESSES: &[Harness] = &[ 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"), + }, // OpenCode 2.x (`@opencode/cli`), verified on 2.4.3 in a scratch home // against a local provider mock (store doc // harvis/research/20261201-open-harness-runtimes.md, sections 3 and 6): @@ -623,85 +702,6 @@ pub const HARNESSES: &[Harness] = &[ 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"), - }, ]; impl Harness { diff --git a/crates/axe-core/src/runtime_views.rs b/crates/axe-core/src/runtime_views.rs index 954e843..3630c2b 100644 --- a/crates/axe-core/src/runtime_views.rs +++ b/crates/axe-core/src/runtime_views.rs @@ -973,7 +973,7 @@ mod tests { fn nouns_come_from_the_rows() { // The empty state and A3 name tools from the harness rows; runtime // is the noun, never "account". - assert_eq!(tools(), "Claude, Codex, OpenCode, Pi or Antigravity"); + assert_eq!(tools(), "Claude, Codex, Antigravity, OpenCode or Pi"); assert_eq!(add_text(), "Add a runtime\nWhich one?"); // Claude takes the Anthropic-shaped provider rows: one step for them. assert_eq!(other_provider("claude-code"), Some("Other provider…")); diff --git a/crates/axe-server/src/server.rs b/crates/axe-server/src/server.rs index fce5fbe..a6bf4d1 100644 --- a/crates/axe-server/src/server.rs +++ b/crates/axe-server/src/server.rs @@ -180,7 +180,8 @@ impl crate::core::Axe for State { method: &str, provider: Option<&str>, ) -> Result { - runtime_login(self, bot, runtime, method, provider) + // Telegram shows the returned text on the owner's own screen. + runtime_login(self, bot, runtime, method, provider, false) } fn runtime_add(&self, actor: &db::Actor, harness: &str, bot: Option<&str>) -> Result { let v = runtime_add(self, actor, harness, bot)?; @@ -2899,7 +2900,8 @@ fn route(st: &State, req: &Request) -> Result { } ("POST", ["api", "runtimes", name, "login"]) => { let b: RuntimeLoginBody = req.json()?; - let text = runtime_login(st, &b.bot, name, &b.method, b.provider.as_deref())?; + // From the CLI: the owner gets the sign-in link from the bot. + let text = runtime_login(st, &b.bot, name, &b.method, b.provider.as_deref(), true)?; ok(200, &json!({"runtime": name, "text": text})) } // Checks a runtime's login now (Check on an out-of-credit card). @@ -4467,15 +4469,19 @@ fn sign_form(st: &State, req: &crate::sealed::Request, now: i64) -> Result, + tell_owner: bool, ) -> Result { let view = crate::runtime::view(&st.admission()); let harness = view["runtimes"] @@ -4531,26 +4537,42 @@ fn runtime_login( } eprintln!("axe server: runtime {runtime}: device login started"); let output = v["output"].as_str().unwrap_or(""); - if v["code"] != true { - return Ok(format!( + let text = if v["code"] != true { + format!( "Log in runtime {runtime} ({harness}) with a device code: open the link below \ and enter the code. The runtime is ok again at its next login check.\n\n{output}" - )); - } - // The CLI waits for the code the page shows: a sealed form takes it. - let sent = login_form( - st, - bot, - runtime, - &harness, - "code", - None, - "code from the sign-in page", - )?; - return Ok(format!( - "Log in runtime {runtime} ({harness}): open the link below and sign in, then paste \ - the code the page shows into the sealed form ({sent}).\n\n{output}" - )); + ) + } else { + // The CLI waits for the code the page shows: a sealed form takes it. + let sent = login_form( + st, + bot, + runtime, + &harness, + "code", + None, + "code from the sign-in page", + )?; + format!( + "Log in runtime {runtime} ({harness}): open the link below and sign in, then \ + paste the code the page shows into the sealed form ({sent}).\n\n{output}" + ) + }; + if !tell_owner { + return Ok(text); + } + let told = owner_alert(st, bot, &text); + return Ok(match told["sent"].as_bool() { + Some(true) => format!( + "Sent the owner the sign-in link from {}.\n\n{text}", + told["bot"].as_str().unwrap_or(bot) + ), + _ => format!( + "The sign-in link could not be sent to the owner ({}): pass it on yourself.\n\n\ + {text}", + told["reason"].as_str().unwrap_or("unknown") + ), + }); } login_form(st, bot, runtime, &harness, method, None, label)?; Ok(format!( @@ -4614,7 +4636,12 @@ fn login_form( ttl: None, from: "/runtimes".into(), }; - let f = sign_form(st, &req, remote::epoch())?; + let now = remote::epoch(); + let f = sign_form(st, &req, now)?; + // One open form per runtime login: this one replaces an earlier one. + for old in st.forms.supersede(&f.spec.form, bot, now) { + eprintln!("axe server: form {old}: replaced by form {}", f.spec.form); + } let sent = form_prompt(st, &f, bot); eprintln!( "axe server: form {}: asked for {}", diff --git a/crates/axe-telegram/src/telegram.rs b/crates/axe-telegram/src/telegram.rs index f7f349c..3f7c08d 100644 --- a/crates/axe-telegram/src/telegram.rs +++ b/crates/axe-telegram/src/telegram.rs @@ -4131,14 +4131,14 @@ mod tests { let s = runtimes_screen(&none, &c); assert_eq!( check(&s), - "Runtimes\nNo runtime yet. Set up Claude, Codex, OpenCode, Pi or Antigravity to start \ + "Runtimes\nNo runtime yet. Set up Claude, Codex, Antigravity, OpenCode or Pi to start \ your bots." ); assert_eq!( labels(&s.1), [ - vec!["Log in Claude", "Log in Codex", "Set up OpenCode"], - vec!["Set up Pi", "Antigravity"] + vec!["Log in Claude", "Log in Codex", "Antigravity"], + vec!["Set up OpenCode", "Set up Pi"] ] ); assert_eq!( @@ -4146,9 +4146,9 @@ mod tests { [ "rtadd:claude-code", "rtadd:codex", + "rtadd:antigravity", "rtadd:opencode", - "rtadd:pi", - "rtadd:antigravity" + "rtadd:pi" ] ); // A pilot with one runtime. @@ -4223,8 +4223,8 @@ mod tests { assert_eq!( labels(&s.1), [ - vec!["Claude", "Codex", "OpenCode"], - vec!["Pi", "Antigravity"], + vec!["Claude", "Codex", "Antigravity"], + vec!["OpenCode", "Pi"], vec!["Cancel"] ] ); @@ -4233,9 +4233,9 @@ mod tests { [ "rtadd:claude-code", "rtadd:codex", + "rtadd:antigravity", "rtadd:opencode", "rtadd:pi", - "rtadd:antigravity", "runtimes" ] ); diff --git a/crates/axe/src/cli.rs b/crates/axe/src/cli.rs index 49e887d..3842d88 100644 --- a/crates/axe/src/cli.rs +++ b/crates/axe/src/cli.rs @@ -2684,7 +2684,8 @@ enum RuntimesCmd { json: bool, }, /// Log a runtime in: the owner gets a sealed form (token, API key) or - /// the device code from --bot on Telegram + /// the device login's link (and one form for its code) from --bot on + /// Telegram; a new form replaces one an earlier attempt left open Login { runtime: String, /// A login method of its harness (device, token, api_key) diff --git a/crates/axe/tests/telegram.rs b/crates/axe/tests/telegram.rs index c6c550e..b907842 100644 --- a/crates/axe/tests/telegram.rs +++ b/crates/axe/tests/telegram.rs @@ -4890,10 +4890,10 @@ fn opencode_sets_up_from_telegram_with_a_provider_key() { let list = rig.sent_to(OWNER).pop().unwrap(); assert_eq!( list["text"], - "Runtimes\nNo runtime yet. Set up Claude, Codex, OpenCode, Pi or Antigravity to start your bots." + "Runtimes\nNo runtime yet. Set up Claude, Codex, Antigravity, OpenCode or Pi to start your bots." ); assert_eq!( - keyboard_of(&list)[0][2], + keyboard_of(&list)[1][0], ("Set up OpenCode".to_string(), "rtadd:opencode".to_string()) ); wait_for("the list recorded", 20, || rig.messages().len() == 1); @@ -6404,7 +6404,7 @@ fn runtimes_log_in_first_and_routing_is_view_only() { let list = next("the /runtimes reply", 0); assert_eq!( list["text"], - "Runtimes\nNo runtime yet. Set up Claude, Codex, OpenCode, Pi or Antigravity to start your bots." + "Runtimes\nNo runtime yet. Set up Claude, Codex, Antigravity, OpenCode or Pi to start your bots." ); assert_eq!( keyboard_of(&list), @@ -6412,11 +6412,11 @@ fn runtimes_log_in_first_and_routing_is_view_only() { &[ ("Log in Claude", "rtadd:claude-code"), ("Log in Codex", "rtadd:codex"), - ("Set up OpenCode", "rtadd:opencode") + ("Antigravity", "rtadd:antigravity") ], &[ - ("Set up Pi", "rtadd:pi"), - ("Antigravity", "rtadd:antigravity") + ("Set up OpenCode", "rtadd:opencode"), + ("Set up Pi", "rtadd:pi") ] ]) ); @@ -6440,7 +6440,7 @@ fn runtimes_log_in_first_and_routing_is_view_only() { .push_to(AUX_TOKEN, text_msg(102, 201, OWNER, OWNER, "/runtimes")); assert_eq!( next("the list while logging in", n)["text"], - "Runtimes\nNo runtime yet. Set up Claude, Codex, OpenCode, Pi or Antigravity to start your bots." + "Runtimes\nNo runtime yet. Set up Claude, Codex, Antigravity, OpenCode or Pi to start your bots." ); // Web sign-in: the claude.ai link on the screen, a sealed form for the code. @@ -7020,3 +7020,142 @@ fn a_board_press_is_checked_against_the_owner() { assert_eq!(board_events(), before, "a press changes nothing"); assert!(board_ok(&rig, &["show"]).contains("Log retention cap")); } + +/// A fake `claude` whose web sign-in prints the claude.ai URL, waits for a +/// code a moment and gives up, so a second attempt can follow; never logged in. +const FAKE_GIVE_UP_LOGIN: &str = r#"#!/bin/sh +case "$(basename "$0") $1 $2" in +"claude auth login") + echo "If the browser didn't open, visit: https://claude.ai/oauth/authorize?code=true&state=t" + printf 'Paste code here if prompted > ' + sleep 1 + exit 1 ;; +"claude auth status") echo "Not logged in"; exit 1 ;; +*) exit 2 ;; +esac +"#; + +/// `axe runtimes login --method device --bot X` (task 2526): the owner, not +/// only the CLI caller, gets the sign-in link from X together with one form +/// for the code; a second attempt replaces the form the first left open. +#[test] +fn a_cli_device_login_sends_the_owner_the_link_and_one_form() { + use std::os::unix::fs::PermissionsExt as _; + let dir = tempfile::tempdir().unwrap(); + let bin = dir.path().join("bin"); + std::fs::create_dir_all(&bin).unwrap(); + let p = bin.join("claude"); + std::fs::write(&p, FAKE_GIVE_UP_LOGIN).unwrap(); + std::fs::set_permissions(&p, std::fs::Permissions::from_mode(0o755)).unwrap(); + let reg = dir.path().join("runtimes"); + std::fs::create_dir_all(®).unwrap(); + let rig = Rig::with(&format!( + "{}[runtimes]\ndir = \"{}\"\n[agents.claude]\ncmd = [\"claude\"]\nharness = \"claude-code\"\nbot_args = []\n", + extra_bots(dir.path()), + reg.display() + )); + rig.srv().ok(&["bot", "pause", "cos"]); + rig.add_bot("aux"); + let path = format!("{}:{}", bin.display(), std::env::var("PATH").unwrap()); + let _disp = rig.srv().dispatcher(&[], &[("PATH", &path)]); + wait_for("the empty report", 30, || { + rig.srv() + .ok(&["runtimes", "list"]) + .contains("none reported") + }); + rig.srv().ok(&["runtimes", "add", "claude-code"]); + wait_for("claude-1 reported", 30, || { + rig.srv().ok(&["runtimes", "list"]).contains("claude-1") + }); + const URL: &str = "https://claude.ai/oauth/authorize?code=true&state=t"; + let prompts = |from: usize| -> Vec { + rig.sent_to(OWNER)[from..] + .iter() + .filter(|p| p["reply_markup"]["keyboard"].is_array()) + .cloned() + .collect() + }; + let links = |from: usize| -> Vec { + rig.sent_to(OWNER)[from..] + .iter() + .filter(|p| p["text"].as_str().is_some_and(|t| t.contains(URL))) + .cloned() + .collect() + }; + let login = || { + rig.srv().run(&[ + "runtimes", "login", "claude-1", "--method", "device", "--bot", "aux", + ]) + }; + + // First attempt: the caller and the owner both get the link; the + // owner gets one form for the code. + let n = rig.sent_to(OWNER).len(); + let out = login(); + assert!(out.status.success(), "{out:?}"); + let said = String::from_utf8(out.stdout).unwrap(); + assert!( + said.starts_with("Sent the owner the sign-in link from aux.") && said.contains(URL), + "{said}" + ); + wait_for("the link to the owner", 20, || !links(n).is_empty()); + let link = links(n).remove(0); + let text = link["text"].as_str().unwrap(); + assert!( + text.contains("open the link below and sign in, then paste the code the page shows") + && !text.starts_with("Sent the owner"), + "{text}" + ); + let first = prompts(n); + assert_eq!(first.len(), 1, "{first:?}"); + let first_link = first[0]["reply_markup"]["keyboard"][0][0]["web_app"]["url"].clone(); + assert_eq!( + form_spec(&json!({ "link": first_link })).target, + axe::sealed::Target::Runtime { + runtime: "claude-1".into(), + login: "code".into(), + provider: None, + } + ); + + // The CLI gave up with the first form still open. A second attempt + // (once the node has let the first go) replaces that form: the new + // prompt's keyboard holds only its own button. + let n = rig.sent_to(OWNER).len(); + let mut out = login(); + let end = Instant::now() + Duration::from_secs(30); + while !out.status.success() && Instant::now() < end { + assert!( + String::from_utf8_lossy(&out.stderr).contains("already in progress"), + "{out:?}" + ); + std::thread::sleep(Duration::from_millis(300)); + out = login(); + } + assert!(out.status.success(), "{out:?}"); + wait_for("the second link", 20, || !links(n).is_empty()); + let second = prompts(n); + assert_eq!(second.len(), 1, "{second:?}"); + let keyboard = second[0]["reply_markup"]["keyboard"].as_array().unwrap(); + assert_eq!(keyboard.len(), 1, "{keyboard:?}"); + assert_ne!(keyboard[0][0]["web_app"]["url"], first_link); + let open: Vec = rig + .srv() + .get("/api/forms") + .as_array() + .unwrap() + .iter() + .filter(|f| f["state"] == "open") + .cloned() + .collect(); + assert_eq!(open.len(), 1, "{open:?}"); + // Replaced in aux's own chat: no extra "not delivered" message there. + std::thread::sleep(Duration::from_secs(3)); + assert!( + !rig.sent_to(OWNER).iter().any(|p| p["text"] + .as_str() + .is_some_and(|t| t.contains("replaced by a newer login form"))), + "{:?}", + rig.sent_to(OWNER) + ); +} diff --git a/docs/user/concepts/runtimes.md b/docs/user/concepts/runtimes.md index 0cc913c..084cc4e 100644 --- a/docs/user/concepts/runtimes.md +++ b/docs/user/concepts/runtimes.md @@ -1,6 +1,6 @@ --- title: "Runtimes" -description: "A runtime is a harness plus its logins on the node: one per provider. Claude, Codex, OpenCode, Pi and Antigravity." +description: "A runtime is a harness plus its logins on the node: one per provider. Claude, Codex, Antigravity, OpenCode and Pi." --- Paths in `crates/axe-core/src/`, `crates/axe-telegram/src/`, `crates/axe-node/src/`, `crates/axe-server/src/` or `crates/axe/src/` (a file is in one) unless noted. diff --git a/docs/user/guides/runtimes-from-telegram.md b/docs/user/guides/runtimes-from-telegram.md index 167a456..d419cff 100644 --- a/docs/user/guides/runtimes-from-telegram.md +++ b/docs/user/guides/runtimes-from-telegram.md @@ -19,9 +19,9 @@ key or a provider key is billed per use and shows the last 7 days' spend from axe's own cost records (`$1.84 this week`, `usage::runtime_spend`); Codex shows none. One button per runtime (marked `!` when it needs you), *Add runtime* and *Routing →*; with no runtime yet, -"No runtime yet. Set up Claude, Codex, OpenCode, Pi or Antigravity to start your bots." and -one button per tool, three a row (*Log in Claude*, *Log in Codex*, *Set up OpenCode*, *Set up Pi*, -*Antigravity*: a label that would pass 16 characters is the tool's name alone), both from the harness rows +"No runtime yet. Set up Claude, Codex, Antigravity, OpenCode or Pi to start your bots." and +one button per tool, three a row (*Log in Claude*, *Log in Codex*, *Antigravity*, *Set up OpenCode*, +*Set up Pi*: a label that would pass 16 characters is the tool's name alone), both from the harness rows (`runtime_views::tools`, `telegram::runtimes_screen`). Every button edits the same message in place (`Gateway::runtimes_press`); runtime screens never change what a bot or task runs on. @@ -157,6 +157,14 @@ on the others. Google account serves one person's runtimes: Google's terms forbid sharing an Antigravity entitlement between users. +One login attempt sends one sealed form: a new form for a runtime's login +closes the one an earlier attempt left open (`Forms::supersede`), so the +chat keyboard keeps only the new button. `axe runtimes login +--method device --bot ` from the CLI works like the buttons: the bot +sends the owner the sign-in link and instructions (and the form, when the +page shows a code), and the CLI prints the same text, starting with who +sent it. + **Models.** A runtime stores no model of its own: routing rules choose models. A provider login runs its row's default model (`provider.rs` `default_model`) when a rule names none, and the ready card says which, diff --git a/docs/user/reference/config.md b/docs/user/reference/config.md index ba24833..7f5e3f4 100644 --- a/docs/user/reference/config.md +++ b/docs/user/reference/config.md @@ -18,8 +18,8 @@ agents. Each harness row (`crates/axe-core/src/harness.rs`) owns its launch and resume commands and session mode and gives a built-in agent: `claude` -(Claude Code), `codex` (Codex), `opencode` (OpenCode), `pi` (Pi) and -`antigravity` (Antigravity), so a node needs no +(Claude Code), `codex` (Codex), `antigravity` (Antigravity), `opencode` +(OpenCode) and `pi` (Pi), so a node needs no `[agents.*]` table to run any of them. An `[agents.]` table of the same name replaces a built-in agent whole; another table driving the same harness keeps the built-in `codex` out (`claude` always stays: bots and unpinned tasks name it). On a