1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
mod actions;
mod browser;
mod bundler;
mod commands;
mod config;
mod error;
pub mod output;
use std::path::PathBuf;
use clap::{Parser, Subcommand};
use crate::error::CliError;
#[derive(Parser)]
#[command(
name = "stepshots",
about = "Record, bundle, and upload interactive product demos",
version
)]
struct Cli {
/// Path to config file (default: auto-detect stepshots.config.json)
#[arg(long, global = true)]
config: Option<PathBuf>,
/// Enable verbose logging
#[arg(long, short, global = true)]
verbose: bool,
/// Output results as JSON to stdout (for AI agents and automation)
#[arg(long, global = true)]
json: bool,
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
/// Generate a sample stepshots.config.json
Init {
/// Overwrite existing config file
#[arg(long)]
force: bool,
},
/// Record tutorials into .stepshot bundles
Record {
/// Record only specific tutorials (by key). Records all if omitted.
#[arg(long, short)]
tutorial: Vec<String>,
/// Output directory for .stepshot files
#[arg(long, short, default_value = "output")]
output: PathBuf,
/// Show what would be recorded without launching a browser
#[arg(long)]
dry_run: bool,
},
/// Preview a tutorial in a visible browser
Preview {
/// Tutorial key to preview
tutorial: String,
},
/// Upload .stepshot bundles to the Stepshots API
Upload {
/// .stepshot files to upload
files: Vec<String>,
/// Override the demo title
#[arg(long)]
title: Option<String>,
/// Replace an existing demo instead of creating a new one
#[arg(long)]
demo_id: Option<String>,
/// Server URL
#[arg(
long,
env = "STEPSHOTS_SERVER",
default_value = "https://stepshots.com"
)]
server: String,
/// API token
#[arg(long, env = "STEPSHOTS_TOKEN")]
token: Option<String>,
},
/// Inspect a page to discover interactive elements and CSS selectors
Inspect {
/// URL to inspect (defaults to config baseUrl if omitted)
url: Option<String>,
/// Viewport width
#[arg(long, default_value = "1280")]
width: u32,
/// Viewport height
#[arg(long, default_value = "800")]
height: u32,
},
/// Upgrade stepshots to the latest version
Upgrade {
/// Force reinstall even if already on the latest version
#[arg(long)]
force: bool,
/// Only check for updates without installing
#[arg(long)]
check: bool,
},
/// Start a local HTTP server for browser extension integration
Serve {
/// Port to listen on
#[arg(long, short, default_value = "8124")]
port: u16,
/// Output directory for recorded bundles
#[arg(long, short, default_value = "output")]
output: PathBuf,
},
}
#[tokio::main]
async fn main() {
dotenvy::dotenv().ok();
let cli = Cli::parse();
if cli.verbose {
tracing_subscriber::fmt()
.with_env_filter("stepshots=debug")
.init();
} else {
tracing_subscriber::fmt()
.with_env_filter("stepshots=info")
.init();
}
let json = cli.json;
if let Err(e) = run(cli).await {
if json {
let output = serde_json::json!({
"success": false,
"error": {
"category": e.error_category(),
"message": e.to_string()
}
});
println!("{}", serde_json::to_string_pretty(&output).unwrap());
} else {
eprintln!("Error: {e}");
}
std::process::exit(e.exit_code());
}
}
async fn run(cli: Cli) -> Result<(), CliError> {
let json = cli.json;
match cli.command {
Commands::Init { force } => {
commands::init::run(force)?;
}
Commands::Record {
tutorial,
output,
dry_run,
} => {
let config_path = config::find_config(cli.config.as_deref())?;
let config = config::load_config(&config_path)?;
if !json {
println!("Using config: {}", config_path.display());
}
commands::record::run(&config, &tutorial, &output, dry_run, json).await?;
}
Commands::Preview { tutorial } => {
let config_path = config::find_config(cli.config.as_deref())?;
let config = config::load_config(&config_path)?;
if !json {
println!("Using config: {}", config_path.display());
}
let effective_viewport =
manifest::resolve_viewport(config.format.as_ref(), &config.viewport);
commands::preview::run(&config, &tutorial, &effective_viewport).await?;
}
Commands::Upload {
files,
title,
demo_id,
server,
token,
} => {
let token = token.ok_or_else(|| {
CliError::Auth("No API token provided. Set STEPSHOTS_TOKEN or use --token.".into())
})?;
commands::upload::run(
&files,
title.as_deref(),
demo_id.as_deref(),
&server,
&token,
)
.await?;
}
Commands::Inspect { url, width, height } => {
let url = match url {
Some(u) => u,
None => {
let config_path = config::find_config(cli.config.as_deref())?;
let config = config::load_config(&config_path)?;
if !json {
println!("Using config: {}", config_path.display());
}
config.base_url.clone()
}
};
commands::inspect::run(&url, width, height, json).await?;
}
Commands::Upgrade { force, check } => {
commands::upgrade::run(force, check).await?;
}
Commands::Serve { port, output } => {
commands::serve::run(port, output).await?;
}
}
Ok(())
}