From 994c7900972d8b8154d1c3977b1b297b2f7e8737 Mon Sep 17 00:00:00 2001 From: junhsss Date: Mon, 16 Nov 2026 19:07:24 +0900 Subject: [PATCH 1/2] fix(browser): print a note, not a warning, when the default session starts --- src/commands/browser/action.rs | 12 +++++------- src/commands/browser/start.rs | 34 +++++++++++++++++++++++++++------- tests/browser_commands.rs | 13 +++++++++++-- tests/cli_blackbox.rs | 6 +++--- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/src/commands/browser/action.rs b/src/commands/browser/action.rs index 8d71693..c535be3 100644 --- a/src/commands/browser/action.rs +++ b/src/commands/browser/action.rs @@ -1235,10 +1235,7 @@ impl Browser { let signs_in = match &target { Some(Target::Saved(found)) => found.mode == ApiMode::Cloud, Some(Target::Id(_)) => true, - None if name.is_none() && start_default => { - eprintln!("warning: session \"default\" is not running; starting a new one"); - true - } + None if name.is_none() && start_default => true, None => return Err(super::not_running(name)), }; if signs_in { @@ -1249,9 +1246,10 @@ impl Browser { Some(Target::Saved(found)) => *found, Some(Target::Id(id)) => attach(&client, &id).await?, None => { - start::create(&client, DEFAULT_SESSION, &start::default_options()) - .await? - .0 + let (created, _) = + start::create(&client, DEFAULT_SESSION, &start::default_options()).await?; + eprintln!("note: {}", start::started_note(&created)); + created } }; let client = client.at(&state.api_url, state.mode); diff --git a/src/commands/browser/start.rs b/src/commands/browser/start.rs index 49ea55b..a6b38c1 100644 --- a/src/commands/browser/start.rs +++ b/src/commands/browser/start.rs @@ -168,6 +168,24 @@ pub async fn create( Ok((created, session.connect_url(mode, client.auth()))) } +pub fn started_note(info: &BrowserSession) -> String { + let span = |ms: u64| humanize_secs(ms / 1000); + let ends = match (info.timeout_ms, info.inactivity_timeout_ms) { + (Some(total), Some(idle)) => format!( + " It ends after {}, or after {} without commands.", + span(total), + span(idle) + ), + (Some(total), None) => format!(" It ends after {}.", span(total)), + (None, Some(idle)) => format!(" It ends after {} without commands.", span(idle)), + (None, None) => String::new(), + }; + format!( + "started session \"{}\".{ends} Stop it with `steel browser stop`.", + info.name + ) +} + pub async fn run(args: Args, session: Option<&str>) -> anyhow::Result<()> { let session_name = session.unwrap_or("default").to_string(); if state::looks_like_session_id(&session_name) { @@ -381,12 +399,12 @@ fn remaining_time_str(info: &BrowserSession) -> Option<(u64, String)> { } fn humanize_secs(secs: u64) -> String { - if secs >= 3600 { - format!("{}h {}m", secs / 3600, (secs % 3600) / 60) - } else if secs >= 60 { - format!("{}m {}s", secs / 60, secs % 60) - } else { - format!("{secs}s") + match (secs / 3600, (secs % 3600) / 60, secs % 60) { + (0, 0, s) => format!("{s}s"), + (0, m, 0) => format!("{m}m"), + (0, m, s) => format!("{m}m {s}s"), + (h, 0, _) => format!("{h}h"), + (h, m, _) => format!("{h}h {m}m"), } } @@ -493,7 +511,9 @@ mod tests { #[test] fn humanize_secs_formats() { assert_eq!(humanize_secs(45), "45s"); - assert_eq!(humanize_secs(120), "2m 0s"); + assert_eq!(humanize_secs(120), "2m"); + assert_eq!(humanize_secs(125), "2m 5s"); + assert_eq!(humanize_secs(3600), "1h"); assert_eq!(humanize_secs(3661), "1h 1m"); } } diff --git a/tests/browser_commands.rs b/tests/browser_commands.rs index 83e0835..c05e956 100644 --- a/tests/browser_commands.rs +++ b/tests/browser_commands.rs @@ -742,12 +742,14 @@ async fn screenshots_are_written_to_the_output_path() { #[tokio::test] async fn the_default_session_starts_on_first_use() { let server = MockServer::start().await; + let mut created = session_json(); + created["timeout"] = json!(900_000); Mock::given(method("POST")) .and(path("/v1/sessions")) .and(body_partial_json( json!({"timeout": 900_000, "inactivityTimeout": 600_000}), )) - .respond_with(ResponseTemplate::new(200).set_body_json(session_json())) + .respond_with(ResponseTemplate::new(200).set_body_json(created)) .expect(1) .mount(&server) .await; @@ -766,7 +768,14 @@ async fn the_default_session_starts_on_first_use() { .run(&["browser", "navigate", "https://example.com"]) .await; assert!(out.status.success(), "{out:?}"); - assert!(String::from_utf8_lossy(&out.stderr).contains("starting a new one")); + let err = String::from_utf8_lossy(&out.stderr); + assert!( + err.contains( + "note: started session \"default\". It ends after 15m, or after 10m without commands. Stop it with `steel browser stop`." + ), + "{err}" + ); + assert!(!err.contains("warning:"), "{err}"); assert_eq!(cli.state("default").unwrap()["next"], "op_1"); } diff --git a/tests/cli_blackbox.rs b/tests/cli_blackbox.rs index 98faf94..ac1fb26 100644 --- a/tests/cli_blackbox.rs +++ b/tests/cli_blackbox.rs @@ -615,14 +615,14 @@ fn browser_action_with_missing_named_session_fails_without_starting_one() { } #[test] -fn browser_action_without_session_warns_before_starting_default() { +fn browser_action_without_session_notes_only_a_session_that_started() { let output = run(&["--json", "browser", "navigate", "https://example.com"]); assert!(!output.status.success()); let err = stderr(&output); assert!( - err.contains("warning: session \"default\" is not running"), - "stderr should warn that a default session is being started, got: {err}" + !err.contains("started session") && !err.contains("warning:"), + "a failed start should not report a started session, got: {err}" ); } From 5441885b16109241e5180354e89e1dcc0159a235 Mon Sep 17 00:00:00 2001 From: junhsss Date: Mon, 16 Nov 2026 19:07:24 +0900 Subject: [PATCH 2/2] fix(describe): type numeric options as integer or number --- docs/cli-reference.md | 52 ++++++++++++++++++++-------------------- src/commands/describe.rs | 47 +++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 27 deletions(-) diff --git a/docs/cli-reference.md b/docs/cli-reference.md index cc5472e..1e03b55 100644 --- a/docs/cli-reference.md +++ b/docs/cli-reference.md @@ -130,7 +130,7 @@ steel scrape - `url` (string, optional): Target URL to scrape - `--format` (string, optional): Comma-separated output formats: html, readability, cleaned_html, markdown -- `-d, --delay` (string, optional): Delay before scraping in milliseconds +- `-d, --delay` (integer, optional): Delay before scraping in milliseconds - `--pdf` (boolean, optional): Include a generated PDF in the response - `--screenshot` (boolean, optional): Include a generated screenshot in the response - `--use-proxy` (boolean, optional): Use a Steel-managed residential proxy @@ -149,7 +149,7 @@ steel screenshot ### Parameters - `url` (string, optional): Target URL to capture -- `-d, --delay` (string, optional): Delay before capturing in milliseconds +- `-d, --delay` (integer, optional): Delay before capturing in milliseconds - `-f, --full-page` (boolean, optional): Capture a full-page screenshot - `--use-proxy` (boolean, optional): Use a Steel-managed residential proxy - `-r, --region` (string, optional): Region identifier for request execution @@ -167,7 +167,7 @@ steel pdf ### Parameters - `url` (string, optional): Target URL to generate PDF from -- `-d, --delay` (string, optional): Delay before generating in milliseconds +- `-d, --delay` (integer, optional): Delay before generating in milliseconds - `--use-proxy` (boolean, optional): Use a Steel-managed residential proxy - `-r, --region` (string, optional): Region identifier for request execution @@ -240,8 +240,8 @@ steel browser start - `-p, --proxy` (string, optional): Route the session through your own proxy (http://user:pass@host:port) - `--use-proxy` (boolean, optional): Use a Steel-managed residential proxy - `--project` (string, optional): Project to create the session in, needed with an organization-wide API key. Defaults to STEEL_PROJECT_ID -- `--timeout` (string, optional): Session timeout in milliseconds. Defaults to 900000 (15 minutes), which every plan allows (create-time only) -- `--inactivity-timeout` (string, optional): Inactivity timeout in milliseconds: release the session when no command, CDP message, or remote input arrives for this long. Defaults to 600000 (10 minutes); pass 0 to disable (create-time only) +- `--timeout` (integer, optional): Session timeout in milliseconds. Defaults to 900000 (15 minutes), which every plan allows (create-time only) +- `--inactivity-timeout` (integer, optional): Inactivity timeout in milliseconds: release the session when no command, CDP message, or remote input arrives for this long. Defaults to 600000 (10 minutes); pass 0 to disable (create-time only) - `--solve-captcha` (boolean, optional): Enable manual CAPTCHA solving on new sessions (create-time only) - `--profile` (string, optional): Named profile to load (see `steel profile list`) - `--update-profile` (boolean, optional): Save session state back to the profile when the session ends; creates the profile if it does not exist @@ -330,8 +330,8 @@ steel browser captcha status - `--page-id` (string, optional): Check only this page - `-w, --wait` (boolean, optional): Wait for terminal status -- `--timeout` (string, optional): Timeout in milliseconds for --wait mode -- `--interval` (string, optional): Poll interval in milliseconds for --wait mode +- `--timeout` (integer, optional): Timeout in milliseconds for --wait mode +- `--interval` (integer, optional): Poll interval in milliseconds for --wait mode ## steel browser batch @@ -407,7 +407,7 @@ steel browser click ### Parameters - `selector` (string, required): Element ref (e.g. e5) or CSS selector -- `--count` (string, optional): Number of clicks (2 for double-click) +- `--count` (integer, optional): Number of clicks (2 for double-click) ## steel browser dblclick @@ -453,7 +453,7 @@ steel browser type - `selector` (string, required): Element ref or CSS selector - `text` (string[], optional): Text to type - `--clear` (boolean, optional): Clear the field before typing -- `--delay` (string, optional): Delay between keystrokes in milliseconds (at most 1000) +- `--delay` (integer, optional): Delay between keystrokes in milliseconds (at most 1000) ## steel browser press @@ -611,7 +611,7 @@ steel browser scroll ### Parameters - `direction` (enum, optional): Direction: up, down, left, right (default: down) -- `amount` (string, optional): Scroll amount in pixels (default: 300) +- `amount` (number, optional): Scroll amount in pixels (default: 300) - `-s, --selector` (string, optional): Element to scroll instead of the page ## steel browser drag @@ -657,12 +657,12 @@ steel browser mouse ### Parameters - `action` (enum, required): move, down, up, click, or wheel -- `x` (string, optional): X in CSS pixels of the visible page (needed for move, click, and wheel) -- `y` (string, optional): Y in CSS pixels of the visible page (needed for move, click, and wheel) +- `x` (number, optional): X in CSS pixels of the visible page (needed for move, click, and wheel) +- `y` (number, optional): Y in CSS pixels of the visible page (needed for move, click, and wheel) - `--button` (enum, optional): Mouse button: left, right, middle -- `--clicks` (string, optional): Click count for click (1 to 3) -- `--dx` (string, optional): Horizontal wheel delta -- `--dy` (string, optional): Vertical wheel delta +- `--clicks` (integer, optional): Click count for click (1 to 3) +- `--dx` (number, optional): Horizontal wheel delta +- `--dy` (number, optional): Vertical wheel delta ## steel browser snapshot @@ -678,7 +678,7 @@ steel browser snapshot - `-i, --interactive` (boolean, optional): Show only interactive elements - `-c, --compact` (boolean, optional): Keep only lines with refs or values, and their ancestors -- `-d, --max-depth` (string, optional): Maximum nesting depth +- `-d, --max-depth` (integer, optional): Maximum nesting depth ## steel browser screenshot @@ -696,7 +696,7 @@ steel browser screenshot - `-o, --output` (string, optional): Output file path - `--selector` (string, optional): Capture one element (ref or CSS selector) - `--format` (enum, optional): Image format: png, jpeg, webp (default: from the output extension) -- `--quality` (string, optional): JPEG/WebP quality (0-100) +- `--quality` (integer, optional): JPEG/WebP quality (0-100) ## steel browser pdf @@ -727,7 +727,7 @@ steel browser eval ### Parameters - `script` (string, required): JavaScript expression or function body; its value is printed -- `--timeout` (string, optional): Time limit in milliseconds (default 10000, at most 50000) +- `--timeout` (integer, optional): Time limit in milliseconds (default 10000, at most 50000) ## steel browser find @@ -967,8 +967,8 @@ steel browser wait ### Parameters -- `ms` (string, optional): Fixed time to wait in milliseconds (at most 30000) -- `--timeout` (string, optional): Timeout in milliseconds (at most 50000) +- `ms` (integer, optional): Fixed time to wait in milliseconds (at most 30000) +- `--timeout` (integer, optional): Timeout in milliseconds (at most 50000) - `-t, --text` (string, optional): Wait for text to appear on the page - `--selector` (string, optional): Wait for an element (ref or CSS selector) - `--state` (enum, optional): Element state: visible, hidden, attached, detached @@ -1106,7 +1106,7 @@ steel sessions list ### Parameters -- `--limit` (string, optional): Number of sessions to return +- `--limit` (integer, optional): Number of sessions to return - `--cursor-id` (string, optional): Cursor ID for pagination - `--status` (string, optional): Filter by status: live, released, or failed - `--metadata` (string[], optional): Filter by metadata KEY=VALUE, repeatable; all must match @@ -1209,8 +1209,8 @@ steel sessions logs - `--since` (string, optional): Alias for --start-time - `--end-time` (string, optional): ISO timestamp upper bound - `--event-type` (string[], optional): Event type filter, repeatable or comma-separated -- `--limit` (string, optional): Number of events to return -- `--offset` (string, optional): Pagination offset +- `--limit` (integer, optional): Number of events to return +- `--offset` (integer, optional): Pagination offset ### API Operations @@ -1237,8 +1237,8 @@ steel sessions agent-logs - `--since` (string, optional): Alias for --start-time - `--end-time` (string, optional): ISO timestamp upper bound - `--event-type` (string[], optional): Event type filter, repeatable or comma-separated -- `--limit` (string, optional): Number of events to return -- `--offset` (string, optional): Pagination offset +- `--limit` (integer, optional): Number of events to return +- `--offset` (integer, optional): Pagination offset ### API Operations @@ -1449,7 +1449,7 @@ steel dev start ### Parameters -- `-p, --port` (string, optional): API port for local Steel Browser runtime +- `-p, --port` (integer, optional): API port for local Steel Browser runtime - `-V, --verbose` (boolean, optional): Enable verbose Docker command output - `-d, --docker-check` (boolean, optional): Only verify Docker availability and exit diff --git a/src/commands/describe.rs b/src/commands/describe.rs index 7621124..82bf55c 100644 --- a/src/commands/describe.rs +++ b/src/commands/describe.rs @@ -1,3 +1,5 @@ +use std::any::TypeId; + use crate::util::output; use anyhow::{Result, bail}; use clap::{ArgAction, CommandFactory, Parser}; @@ -377,13 +379,33 @@ fn infer_type(arg: &clap::Arg) -> String { if !possible.is_empty() { "enum".into() } else { - "string".into() + scalar_type(arg).into() } } _ => "string".into(), } } +fn scalar_type(arg: &clap::Arg) -> &'static str { + let id = arg.get_value_parser().type_id(); + let is_any = |types: &[TypeId]| types.iter().any(|t| id == *t); + if is_any(&[ + TypeId::of::(), + TypeId::of::(), + TypeId::of::(), + TypeId::of::(), + TypeId::of::(), + TypeId::of::(), + TypeId::of::(), + ]) { + "integer" + } else if is_any(&[TypeId::of::(), TypeId::of::()]) { + "number" + } else { + "string" + } +} + // ── Helpers ───────────────────────────────────────────────────────── fn get_aliases(cmd: &clap::Command) -> Vec { @@ -635,6 +657,29 @@ mod tests { assert_eq!(timeout["default"], "30000"); } + #[test] + fn numeric_args_typed_as_numbers() { + let param_type = |path: &[&str], name: &str| { + let v = describe_path(path); + v["parameters"] + .as_array() + .unwrap() + .iter() + .find(|p| p["name"] == name) + .unwrap()["type"] + .clone() + }; + assert_eq!(param_type(&["browser", "start"], "timeout"), "integer"); + assert_eq!( + param_type(&["browser", "start"], "inactivity-timeout"), + "integer" + ); + assert_eq!(param_type(&["browser", "wait"], "timeout"), "integer"); + assert_eq!(param_type(&["browser", "click"], "count"), "integer"); + assert_eq!(param_type(&["browser", "scroll"], "amount"), "number"); + assert_eq!(param_type(&["browser", "wait"], "text"), "string"); + } + #[test] fn vec_args_typed_as_array() { let v = describe_path(&["browser", "fill"]);