diff --git a/README.md b/README.md index f09ef3f..d363d4f 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ Supported shells: `bash`, `zsh`, `fish`, `powershell`, `elvish`. | API tools | `scrape`, `screenshot`, `pdf` | | Local runtime | `dev install`, `dev start`, `dev stop` | | Credentials | `credentials list`, `credentials create`, `credentials update`, `credentials delete` | -| Account and utility | `login`, `logout`, `config`, `doctor`, `cache`, `update`, `completion` | +| Account and utility | `login`, `logout`, `config`, `doctor`, `feedback`, `cache`, `update`, `completion` | Full flags and schemas: [CLI reference](docs/cli-reference.md). diff --git a/docs/cli-reference.md b/docs/cli-reference.md index 1e03b55..b368f5e 100644 --- a/docs/cli-reference.md +++ b/docs/cli-reference.md @@ -97,6 +97,7 @@ Steel CLI - browser automation for AI agents. This file is generated from `steel - [steel profile delete](#steel-profile-delete) - [steel describe](#steel-describe) - [steel doctor](#steel-doctor) +- [steel feedback](#steel-feedback) - [steel skills](#steel-skills) - [steel skills list](#steel-skills-list) - [steel skills install](#steel-skills-install) @@ -1626,6 +1627,25 @@ steel doctor - `--preflight` (boolean, optional): Only check auth and API connectivity +## steel feedback + +Send feedback to the Steel team: a bug, a docs problem, or a request + +### Usage + +```bash +steel feedback +``` + +### Parameters + +- `category` (enum, required): What kind of feedback this is +- `message` (string, required): What happened or what you need, in a few sentences +- `--goal` (string, optional): What you were trying to do +- `--command` (string, optional): The Steel command that failed, with its arguments +- `--error` (string, optional): The error or output you got +- `--page` (string, optional): For docs feedback, the docs page it is about + ## steel skills Manage Steel agent skills diff --git a/docs/references/agent-troubleshooting.md b/docs/references/agent-troubleshooting.md index 63b88ad..117c3a1 100644 --- a/docs/references/agent-troubleshooting.md +++ b/docs/references/agent-troubleshooting.md @@ -99,6 +99,21 @@ steel browser start --local --session "$SESSION_NAME" - Stale state: `steel browser stop --all`, then start a new named session. +## Report Problems to Steel + +If a command keeps failing in a way you cannot fix, tell the Steel team: + +```bash +steel feedback bug "browser start fails every time" \ + --goal "open example.com" \ + --command "steel browser start --session $SESSION_NAME" \ + --error "internal_error" +``` + +Use `docs` when the docs are wrong, `product` when Steel lacks something you +need, and `other` for anything else. Send only what you observed about Steel. +Never include page content, user data or keys. + ## PR/CI Hygiene for Agent Logs - never print `STEEL_API_KEY` directly. diff --git a/docs/references/steel-cli.md b/docs/references/steel-cli.md index 7f1e564..635b684 100644 --- a/docs/references/steel-cli.md +++ b/docs/references/steel-cli.md @@ -50,6 +50,7 @@ For generated flags and argument schemas, use [../cli-reference.md](../cli-refer - `steel login`: device login; approve the shown code in any browser. `--resume` continues a saved request, `--no-wait` returns while approval is pending, `--no-browser` skips opening a browser. Reports an existing API key instead of starting device login. - `steel logout`: revoke the device login's refresh grant, then forget local auth (state is kept if revocation fails). `--local-only` forgets local state without contacting the server; revoke the device in your account too. Issued access tokens stay valid until they expire. - `steel config`: print current auth/session context. +- `steel feedback `: send feedback to the Steel team. Categories are `bug`, `docs`, `product` and `other`. `--goal`, `--command`, `--error` and `--page` add context. Needs a login or API key. - `steel settings`: switch persisted local/cloud preference. - `steel cache`: clean cache. - `steel update`: update CLI. diff --git a/src/api/feedback.rs b/src/api/feedback.rs new file mode 100644 index 0000000..317e351 --- /dev/null +++ b/src/api/feedback.rs @@ -0,0 +1,65 @@ +use serde_json::Value; + +use crate::api::client::{ApiError, SteelClient}; + +impl SteelClient { + pub async fn send_feedback(&self, body: &Value) -> Result { + self.request(reqwest::Method::POST, "/feedback/agent", Some(body.clone())) + .await + } +} + +#[cfg(test)] +mod tests { + use serde_json::json; + use wiremock::matchers::{body_json, header, method, path}; + use wiremock::{Mock, MockServer, ResponseTemplate}; + + use super::*; + use crate::config::auth::{Auth, AuthSource}; + use crate::config::settings::ApiMode; + + fn client(server: &MockServer, api_key: Option<&str>) -> SteelClient { + let auth = Auth { + api_key: api_key.map(Into::into), + access_token: None, + source: AuthSource::Env, + }; + SteelClient::with(server.uri(), ApiMode::Cloud, auth).unwrap() + } + + #[tokio::test] + async fn sends_feedback_with_the_api_key() { + let server = MockServer::start().await; + let body = json!({"category": "bug", "message": "browser start fails"}); + + Mock::given(method("POST")) + .and(path("/feedback/agent")) + .and(header("Steel-Api-Key", "test-key")) + .and(body_json(&body)) + .respond_with(ResponseTemplate::new(200).set_body_json(json!({"id": "f-1"}))) + .expect(1) + .mount(&server) + .await; + + let data = client(&server, Some("test-key")) + .send_feedback(&body) + .await + .unwrap(); + + assert_eq!(data["id"], "f-1"); + } + + #[tokio::test] + async fn refuses_to_send_without_signing_in() { + let server = MockServer::start().await; + + let err = client(&server, None) + .send_feedback(&json!({"category": "bug", "message": "x"})) + .await + .unwrap_err(); + + assert!(matches!(err, ApiError::MissingAuth)); + assert!(server.received_requests().await.unwrap().is_empty()); + } +} diff --git a/src/api/mod.rs b/src/api/mod.rs index b33a698..1b315f2 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,5 +1,6 @@ pub mod client; pub mod commands; +pub mod feedback; pub mod generated; pub mod profiles; pub mod projects; diff --git a/src/commands/feedback.rs b/src/commands/feedback.rs new file mode 100644 index 0000000..b239e18 --- /dev/null +++ b/src/commands/feedback.rs @@ -0,0 +1,135 @@ +use clap::{Parser, ValueEnum}; +use serde_json::{Value, json}; + +use crate::api::client::SteelClient; +use crate::util::output; + +#[derive(Clone, Copy, Debug, PartialEq, Eq, ValueEnum)] +pub enum Category { + /// Steel failed or did the wrong thing + Bug, + /// Steel's docs are wrong, missing something or unclear + Docs, + /// Steel lacks something you need + Product, + /// Anything else + Other, +} + +impl Category { + const fn as_str(self) -> &'static str { + match self { + Self::Bug => "bug", + Self::Docs => "docs", + Self::Product => "product", + Self::Other => "other", + } + } +} + +#[derive(Parser)] +#[command(after_help = "Examples: + steel feedback bug \"browser start fails every time\" --command \"steel browser start\" --error \"internal_error\" + steel feedback docs \"The timeout default is wrong\" --page sessions/timeouts + steel feedback product \"I need to download files from a session\"")] +pub struct Args { + /// What kind of feedback this is + #[arg(value_enum)] + pub category: Category, + + /// What happened or what you need, in a few sentences + pub message: String, + + /// What you were trying to do + #[arg(long)] + pub goal: Option, + + /// The Steel command that failed, with its arguments + #[arg(long)] + pub command: Option, + + /// The error or output you got + #[arg(long)] + pub error: Option, + + /// For docs feedback, the docs page it is about + #[arg(long)] + pub page: Option, +} + +impl Args { + fn body(&self) -> Value { + let mut body = json!({ + "category": self.category.as_str(), + "message": self.message, + }); + for (key, value) in [ + ("goal", &self.goal), + ("command", &self.command), + ("error", &self.error), + ("page", &self.page), + ] { + if let Some(value) = value { + body[key] = json!(value); + } + } + body + } +} + +pub async fn run(args: Args) -> anyhow::Result<()> { + output::suppress_feedback_hint(); + let response = SteelClient::new()?.send_feedback(&args.body()).await?; + let id = response + .get("id") + .and_then(Value::as_str) + .unwrap_or_default(); + + output::success( + json!({ "id": id }), + &format!("Sent to the Steel team. Reference: {id}\n"), + ); + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + + fn args(category: Category) -> Args { + Args { + category, + message: "browser start fails".into(), + goal: None, + command: None, + error: None, + page: None, + } + } + + #[test] + fn body_carries_only_the_fields_given() { + assert_eq!( + args(Category::Product).body(), + json!({"category": "product", "message": "browser start fails"}) + ); + let full = Args { + goal: Some("open a page".into()), + command: Some("steel browser start".into()), + error: Some("internal_error".into()), + page: Some("sessions/timeouts".into()), + ..args(Category::Bug) + }; + assert_eq!( + full.body(), + json!({ + "category": "bug", + "message": "browser start fails", + "goal": "open a page", + "command": "steel browser start", + "error": "internal_error", + "page": "sessions/timeouts", + }) + ); + } +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 07c9130..56afe2c 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -6,6 +6,7 @@ pub mod credentials; pub mod describe; pub mod dev; pub mod doctor; +pub mod feedback; pub mod forge; pub mod init; pub mod login; @@ -59,6 +60,7 @@ const EXAMPLES: &[&str] = &[ "steel browser tab new https://example.com", "steel browser stop --session my-session", "steel sessions list --metadata env=prod --signal captcha_encountered", + "steel feedback bug \"browser start keeps failing\" --command \"steel browser start\"", ]; fn long_help(root: &clap::Command) -> String { @@ -177,6 +179,9 @@ pub enum Command { /// Check environment, auth, and connectivity Doctor(doctor::Args), + /// Send feedback to the Steel team: a bug, a docs problem, or a request + Feedback(feedback::Args), + /// Manage Steel agent skills Skills(skills::Args), @@ -205,6 +210,7 @@ fn telemetry_command_path(command: &Command) -> Option { Command::Profile { command } => Some(format!("profile.{}", command.telemetry_name())), Command::Describe(_) => Some("describe".to_string()), Command::Doctor(_) => Some("doctor".to_string()), + Command::Feedback(_) => Some("feedback".to_string()), Command::Skills(args) => Some(format!("skills.{}", skills::telemetry_name(&args.command))), Command::Completion(_) => Some("completion".to_string()), } @@ -250,6 +256,7 @@ pub async fn run(cli: Cli) -> anyhow::Result<()> { Command::Profile { command } => profile::run(command).await, Command::Describe(args) => describe::run(args).await, Command::Doctor(args) => doctor::run(args).await, + Command::Feedback(args) => feedback::run(args).await, Command::Skills(args) => skills::run(args.command).await, Command::Completion(args) => completion::run(args).await, }; diff --git a/src/util/output.rs b/src/util/output.rs index 7716d4f..f32ee47 100644 --- a/src/util/output.rs +++ b/src/util/output.rs @@ -6,6 +6,7 @@ use serde_json::{Value, json}; static JSON_MODE: AtomicBool = AtomicBool::new(false); static NO_COLOR: AtomicBool = AtomicBool::new(false); +static FEEDBACK_HINT: AtomicBool = AtomicBool::new(true); /// Initialize output settings. Called once at startup. pub fn init(json: bool) { @@ -18,6 +19,10 @@ pub fn is_json() -> bool { JSON_MODE.load(Ordering::Relaxed) } +pub fn suppress_feedback_hint() { + FEEDBACK_HINT.store(false, Ordering::Relaxed); +} + /// Check if `NO_COLOR` environment variable is set. pub fn no_color() -> bool { NO_COLOR.load(Ordering::Relaxed) @@ -172,6 +177,7 @@ pub fn handle_error(err: &anyhow::Error) -> ! { } let class = classify(err); + let hint = hint_for(&class, FEEDBACK_HINT.load(Ordering::Relaxed)); let msg = format!("{err:#}"); let data = err .downcast_ref::() @@ -183,7 +189,7 @@ pub fn handle_error(err: &anyhow::Error) -> ! { "error": msg, "error_code": class.code, }); - if let Some(h) = class.hint { + if let Some(h) = hint { obj["hint"] = json!(h); } if let Some(data) = data { @@ -192,7 +198,7 @@ pub fn handle_error(err: &anyhow::Error) -> ! { println!("{obj}"); } else { eprintln!("Error: {msg}"); - if let Some(h) = class.hint { + if let Some(h) = hint { eprintln!("Hint: {h}"); } } @@ -222,6 +228,21 @@ const fn class( } } +const FEEDBACK_HINT_TEXT: &str = "If this keeps failing, tell the Steel team: steel feedback bug \"\" --command \"\" --error \"\"."; + +fn hint_for(class: &ErrorClass, feedback: bool) -> Option { + let feedback = (feedback + && matches!( + class.code, + "internal_error" | "server_error" | "api_bad_response" | "request_failed" + )) + .then_some(FEEDBACK_HINT_TEXT); + match (class.hint, feedback) { + (Some(hint), Some(feedback)) => Some(format!("{hint} {feedback}")), + (hint, feedback) => hint.or(feedback).map(str::to_string), + } +} + const NETWORK_HINT: Option<&str> = Some("Check your network connection."); const LOCAL_STATE_HINT: Option<&str> = Some("Delete the file and retry."); const PROJECT_HINT: Option<&str> = Some( @@ -640,6 +661,34 @@ mod tests { assert_eq!(classify(&device).code, "device_auth_failed"); } + #[test] + fn hint_points_at_feedback_only_for_failures_the_agent_cannot_fix() { + let internal = classify(&anyhow::anyhow!("something unexpected")); + assert_eq!( + hint_for(&internal, true).as_deref(), + Some(FEEDBACK_HINT_TEXT) + ); + assert_eq!(hint_for(&internal, false), None); + + let server: anyhow::Error = crate::api::client::ApiError::RequestFailed { + status: 500, + message: std::borrow::Cow::Borrowed("Internal Server Error"), + body: None, + } + .into(); + let hint = hint_for(&classify(&server), true).unwrap(); + assert!(hint.starts_with("Steel API server error. Try again later. ")); + assert!(hint.ends_with(FEEDBACK_HINT_TEXT)); + + let auth: anyhow::Error = crate::api::client::ApiError::MissingAuth.into(); + assert_eq!( + hint_for(&classify(&auth), true).as_deref(), + Some("Run `steel login` or set STEEL_API_KEY.") + ); + let usage = crate::util::error::invalid_input("bad flag"); + assert_eq!(hint_for(&classify(&usage), true), None); + } + #[test] fn classify_gone_as_not_found() { let err: anyhow::Error = crate::api::client::ApiError::RequestFailed {