vibesurfer 0.1.12

A real browser for your local AI agent.
Documentation
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
//! `clap`-derived command tree and dispatch.
//!
//! Each primitive is one subcommand. [`run`] builds a [`Request`] from
//! the subcommand, calls [`Client::call`](crate::client::Client::call),
//! and returns the response; [`render`] formats it for stdout.

use std::path::PathBuf;

use anyhow::{Context as _, Result};
use clap::{Parser, Subcommand};
use vs_protocol::Request;

/// Top-level CLI.
#[derive(Debug, Parser)]
#[command(
    name = "vs",
    version,
    about = "vibesurfer — agent-native browser CLI",
    long_about = "vibesurfer client and daemon. `vs serve` runs the daemon; everything else sends a request to it over a Unix socket."
)]
pub struct Cli {
    /// Override the active session id (otherwise read from
    /// `$VIBESURFER_HOME/active-session`).
    #[arg(long, short = 'S', global = true)]
    pub session: Option<String>,

    /// Override the daemon socket path. Tests pass an explicit path;
    /// in production this defaults to `$HOME/.vibesurfer/daemon.sock`.
    #[arg(long, global = true)]
    pub socket: Option<PathBuf>,

    /// Override the vibesurfer home directory. Useful for tests.
    #[arg(long, global = true)]
    pub home: Option<PathBuf>,

    /// Skip the daemon auto-spawn step. Tests start the daemon
    /// themselves and connect via `--socket`.
    #[arg(long, global = true)]
    pub no_spawn: bool,

    /// Emit the response as JSON for human inspection. The default is
    /// the line-oriented wire form that agents consume.
    #[arg(long, short = 'j', global = true)]
    pub json: bool,

    #[command(subcommand)]
    pub command: Command,
}

/// The subcommand vocabulary. One variant per primitive.
///
/// Each variant has a `visible_alias` short form for token economy in
/// agent contexts (mirrors agented's `s` / `i` / `d` / `w` / `br`
/// pattern). Long forms remain for human readers.
#[derive(Debug, Subcommand)]
pub enum Command {
    /// 1. Open a new session.
    #[command(visible_alias = "so")]
    SessionOpen {
        #[arg(long)]
        policy: Option<String>,
    },
    /// 2. Close the active session.
    #[command(visible_alias = "sc")]
    SessionClose,
    /// 3. Open a page navigated to URL.
    #[command(visible_alias = "o")]
    Open { url: String },
    /// 4. Close a page.
    #[command(visible_alias = "c")]
    Close { page: String },
    /// 5. View a page (delta by default; `--full` re-baselines).
    #[command(visible_alias = "v")]
    View {
        page: String,
        #[arg(long, short = 'F')]
        full: bool,
    },
    /// 6. Read the full text of a ref.
    #[command(visible_alias = "r")]
    Read {
        page: String,
        #[arg(value_name = "REF")]
        r: u32,
    },
    /// 7. Perform an action on a ref.
    #[command(visible_alias = "a")]
    Act {
        page: String,
        #[arg(value_name = "REF")]
        r: u32,
        op: String,
        value: Option<String>,
        #[arg(long)]
        token: String,
        #[arg(long)]
        group: Option<String>,
    },
    /// 8. Search across pages in the session.
    #[command(visible_alias = "f")]
    Find { query: String },
    /// 9. Wait for a condition on a page.
    #[command(visible_alias = "w")]
    Wait {
        page: String,
        cond: String,
        value: Option<String>,
        #[arg(long, default_value_t = 5000)]
        timeout: u64,
    },
    /// 13. Status summary for the active session (or all sessions).
    #[command(visible_alias = "st")]
    Status,
    /// 10. Extract structured data using a known schema.
    #[command(visible_alias = "x")]
    Extract {
        page: String,
        schema: String,
        #[arg(long)]
        token: String,
    },
    /// 11. Persist a ref as a named anchor.
    #[command(visible_alias = "m")]
    Mark {
        page: String,
        #[arg(value_name = "REF")]
        r: u32,
        name: String,
        #[arg(long)]
        token: String,
    },
    /// 12. Attach a (key, value) annotation to a target (one of
    ///     `ref:N`, `mark:NAME`, or `page`).
    #[command(visible_alias = "an")]
    Annotate {
        target: String,
        key: String,
        value: Option<String>,
    },
    /// 14. Slice the audit log.
    #[command(visible_alias = "l")]
    Log {
        #[arg(long, short = 'P')]
        page: Option<String>,
        #[arg(long)]
        group: Option<String>,
        #[arg(long, short = 's')]
        since: Option<i64>,
        #[arg(long, short = 'n')]
        limit: Option<i64>,
    },
    /// 15. Skill management. Subcommand: `list` or `show <name>`.
    ///     (M6 adds `<name> [args]` execution.)
    #[command(visible_alias = "sk")]
    Skill {
        sub: Option<String>,
        name: Option<String>,
    },
    /// 16. Capture a screenshot. Defaults to viewport scope; pass a
    ///     ref to capture an element, or `--full-page`.
    #[command(visible_alias = "cap")]
    Capture {
        page: String,
        #[arg(value_name = "REF")]
        r: Option<u32>,
        #[arg(long)]
        full_page: bool,
        /// Emit the PNG bytes as base64 on the response body (instead
        /// of just a path on disk). Lets MCP-driven agents see the
        /// screenshot inline; the on-disk PNG is still written.
        #[arg(long, alias = "b64")]
        base64: bool,
    },
    /// 17. Set the viewport. `spec` is a preset (e.g. `mobile`,
    ///     `desktop`) or `WxH` (e.g. `1280x720`).
    #[command(visible_alias = "vp")]
    Viewport {
        page: String,
        spec: String,
        #[arg(long, default_value_t = 2)]
        dpr: u32,
    },
    /// 18. Compute layout boxes for one or more refs.
    #[command(visible_alias = "lay")]
    Layout {
        page: String,
        #[arg(value_name = "REF", required = true)]
        refs: Vec<u32>,
    },
    /// 19. Auth blob management. Subcommand: `save <page> <name>`,
    ///     `load <page> <name>`, `list`, or `clear <name>`.
    #[command(visible_alias = "au")]
    Auth {
        sub: String,
        #[arg(num_args = 0..=2)]
        rest: Vec<String>,
    },
    /// 20. Inspect engine state — console, network, request detail,
    ///     storage, scripts, dom, performance. The first positional is
    ///     the page id; the second is the kind. Trailing positionals
    ///     are kind-specific (e.g. `request <seq>`, `eval <expr>`,
    ///     `storage <scope>`, `script <seq>`).
    #[command(visible_alias = "i")]
    Inspect {
        page: String,
        kind: String,
        #[arg(num_args = 0..=3)]
        rest: Vec<String>,
        #[arg(long, short = 's')]
        since: Option<String>,
        #[arg(long)]
        level: Option<String>,
        #[arg(long)]
        status: Option<String>,
        #[arg(long)]
        max: Option<String>,
        #[arg(long, short = 'F')]
        full: bool,
        #[arg(long = "unsafe-log")]
        unsafe_log: bool,
    },
    /// Move the cursor to `(x, y)` along a humanized Bezier path.
    /// Native trusted-event dispatch on macOS; ENGINE_UNSUPPORTED
    /// elsewhere until M7 wires GDK / CDP input.
    #[command(visible_alias = "mt")]
    MoveTo {
        page: String,
        x: f64,
        y: f64,
        #[arg(long, short = 'M', default_value = "human")]
        mode: String,
    },
    /// Click at `(x, y)`. Trusted on macOS (`isTrusted = true`).
    #[command(visible_alias = "ca")]
    ClickAt {
        page: String,
        x: f64,
        y: f64,
        #[arg(long)]
        token: String,
        #[arg(long, short = 'M', default_value = "human")]
        mode: String,
    },
    /// Hover at `(x, y)`.
    #[command(visible_alias = "ha")]
    HoverAt {
        page: String,
        x: f64,
        y: f64,
        #[arg(long, short = 'M', default_value = "human")]
        mode: String,
    },
    /// Drag from `(x1, y1)` to `(x2, y2)`.
    #[command(visible_alias = "dr")]
    Drag {
        page: String,
        x1: f64,
        y1: f64,
        x2: f64,
        y2: f64,
        #[arg(long)]
        token: String,
        #[arg(long, short = 'M', default_value = "human")]
        mode: String,
    },
    /// Prompt the user (in the terminal that ran vs) for a value, then
    /// fill it into a ref. The value is read from tty by the CLI and
    /// shipped to the daemon over the local socket; the agent that
    /// invoked vs prompt-input never sees the bytes. Use `--secret`
    /// for passwords, TANs, and other credentials (terminal echo off).
    #[command(visible_alias = "pi")]
    PromptInput {
        page: String,
        #[arg(value_name = "REF")]
        r: u32,
        #[arg(long)]
        message: String,
        #[arg(long)]
        secret: bool,
        #[arg(long)]
        token: String,
        #[arg(long)]
        group: Option<String>,
    },
    /// Block until the user presses Enter in the terminal. Returns
    /// `ok` on confirm or `! ABORTED` if the user sends EOF / Ctrl-C.
    /// Use as a human-in-loop gate before a sensitive `vs act click`.
    #[command(visible_alias = "pc")]
    PromptConfirm {
        page: String,
        #[arg(long)]
        message: String,
    },
    /// Wire-only `vs_prompt_input` variant — does NOT read from the
    /// local tty. Used by `vs mcp` so an MCP-driven agent can enqueue
    /// a prompt the local user fulfills via `vs pending fulfill`.
    /// Hidden from `--help`: only the MCP server wires it.
    #[command(hide = true)]
    PromptInputQueue {
        page: String,
        r: u32,
        #[arg(long)]
        message: String,
        #[arg(long, default_value_t = false)]
        secret: bool,
        #[arg(long)]
        token: String,
        #[arg(long)]
        group: Option<String>,
        /// Timeout in milliseconds before the daemon gives up waiting
        /// for `vs pending fulfill <id>` (default 5 min).
        #[arg(long = "timeout-ms", default_value_t = 300_000)]
        timeout_ms: u64,
    },
    /// List / fulfill / cancel pending `vs_prompt_input` entries
    /// queued by an MCP-driven agent. Use `vs pending list` to see
    /// what's waiting, `vs pending fulfill <id>` to type the value at
    /// the local tty (`--secret` hides echo), `vs pending cancel <id>`
    /// to abort.
    #[command(visible_alias = "pe")]
    Pending {
        #[command(subcommand)]
        sub: PendingSub,
    },
    /// Run the daemon in this process. The `vs` binary doubles as the
    /// daemon — `vs serve` is what auto-spawn re-execs when the socket
    /// is missing. SIGINT shuts down cleanly.
    Serve {
        /// Send SIGTERM to the running daemon (PID file at
        /// `~/.vibesurfer/daemon.pid`) and wait for the socket to
        /// disappear. Returns immediately if no daemon is running.
        #[arg(long)]
        stop: bool,
    },
    /// Run the MCP (Model Context Protocol) server over stdio.
    /// Speaks JSON-RPC 2.0; each of the 19 vibesurfer primitives is
    /// exposed as one MCP tool. Wire to Claude Desktop / Claude Code
    /// by configuring `vs mcp` as the server command.
    Mcp,
}

#[derive(Debug, Subcommand)]
pub enum PendingSub {
    /// Show all pending `vs_prompt_input` entries the daemon is
    /// holding for fulfillment.
    #[command(visible_alias = "ls")]
    List,
    /// Read the value the daemon is waiting for from the local tty
    /// (rpassword for `--secret`) and send it to the pending entry.
    /// On success the parked `vs_prompt_input` call returns and the
    /// agent observes the filled field.
    #[command(visible_alias = "f")]
    Fulfill {
        /// Pending entry id (from `vs pending list`). If omitted and
        /// there is exactly one pending entry, that one is used.
        id: Option<String>,
    },
    /// Cancel a pending entry. The parked `vs_prompt_input` call
    /// returns `BadRequest "cancelled"`.
    #[command(visible_alias = "c")]
    Cancel {
        id: String,
    },
}

impl Command {
    /// Build the wire [`Request`] for this subcommand. Returns `None`
    /// for commands that the CLI handles locally (none yet).
    #[allow(clippy::too_many_lines)]
    pub fn to_request(&self, session_id: Option<&str>) -> Result<Request> {
        Ok(match self {
            Self::SessionOpen { policy } => {
                let mut r = Request::new("vs_session_open");
                if let Some(p) = policy {
                    r = r.flag_value("policy", p.clone());
                }
                r
            }
            Self::SessionClose => {
                let s = require_session(session_id)?;
                Request::new("vs_session_close").arg(s)
            }
            Self::Open { url } => {
                let s = require_session(session_id)?;
                Request::new("vs_open")
                    .arg(url.clone())
                    .flag_value("session", s)
            }
            Self::Close { page } => {
                let s = require_session(session_id)?;
                Request::new("vs_close")
                    .arg(page.clone())
                    .flag_value("session", s)
            }
            Self::View { page, full } => {
                let s = require_session(session_id)?;
                let mut r = Request::new("vs_view")
                    .arg(page.clone())
                    .flag_value("session", s);
                if *full {
                    r = r.flag("full");
                }
                r
            }
            Self::Read { page, r } => {
                let s = require_session(session_id)?;
                Request::new("vs_read")
                    .arg(page.clone())
                    .arg(r.to_string())
                    .flag_value("session", s)
            }
            Self::Act {
                page,
                r,
                op,
                value,
                token,
                group,
            } => {
                let s = require_session(session_id)?;
                let mut req = Request::new("vs_act")
                    .arg(page.clone())
                    .arg(r.to_string())
                    .arg(op.clone());
                if let Some(v) = value {
                    req = req.arg(v.clone());
                }
                req = req
                    .flag_value("session", s)
                    .flag_value("token", token.clone());
                if let Some(g) = group {
                    req = req.flag_value("group", g.clone());
                }
                req
            }
            Self::Find { query } => {
                let s = require_session(session_id)?;
                Request::new("vs_find")
                    .arg(query.clone())
                    .flag_value("session", s)
            }
            Self::Wait {
                page,
                cond,
                value,
                timeout,
            } => {
                let s = require_session(session_id)?;
                let mut req = Request::new("vs_wait").arg(page.clone()).arg(cond.clone());
                if let Some(v) = value {
                    req = req.arg(v.clone());
                }
                req.flag_value("session", s)
                    .flag_value("timeout", format!("{timeout}ms"))
            }
            Self::Status => {
                let mut r = Request::new("vs_status");
                if let Some(s) = session_id {
                    r = r.flag_value("session", s.to_string());
                }
                r
            }
            Self::Extract {
                page,
                schema,
                token,
            } => {
                let s = require_session(session_id)?;
                Request::new("vs_extract")
                    .arg(page.clone())
                    .arg(schema.clone())
                    .flag_value("session", s)
                    .flag_value("token", token.clone())
            }
            Self::Mark {
                page,
                r,
                name,
                token,
            } => {
                let s = require_session(session_id)?;
                Request::new("vs_mark")
                    .arg(page.clone())
                    .arg(r.to_string())
                    .arg(name.clone())
                    .flag_value("session", s)
                    .flag_value("token", token.clone())
            }
            Self::Annotate { target, key, value } => {
                let s = require_session(session_id)?;
                let mut req = Request::new("vs_annotate")
                    .arg(target.clone())
                    .arg(key.clone());
                if let Some(v) = value {
                    req = req.arg(v.clone());
                }
                req.flag_value("session", s)
            }
            Self::Log {
                page,
                group,
                since,
                limit,
            } => {
                let s = require_session(session_id)?;
                let mut req = Request::new("vs_log").flag_value("session", s);
                if let Some(p) = page {
                    req = req.flag_value("page", p.clone());
                }
                if let Some(g) = group {
                    req = req.flag_value("group", g.clone());
                }
                if let Some(t) = since {
                    req = req.flag_value("since", t.to_string());
                }
                if let Some(l) = limit {
                    req = req.flag_value("limit", l.to_string());
                }
                req
            }
            Self::Skill { sub, name } => {
                let s = require_session(session_id)?;
                let mut req = Request::new("vs_skill").flag_value("session", s);
                let sub = sub.as_deref().unwrap_or("list");
                req = req.arg(sub.to_string());
                if let Some(n) = name {
                    req = req.arg(n.clone());
                }
                req
            }
            Self::Capture { page, r, full_page, base64: _ } => {
                // `base64` is a CLI-side post-process — the daemon
                // still returns the on-disk path; dispatch.rs reads
                // the PNG and base64-encodes it before printing.
                let s = require_session(session_id)?;
                let mut req = Request::new("vs_capture")
                    .arg(page.clone())
                    .flag_value("session", s);
                if let Some(rr) = r {
                    req = req.arg(rr.to_string());
                }
                if *full_page {
                    req = req.flag("full-page");
                }
                req
            }
            Self::Viewport { page, spec, dpr } => {
                let s = require_session(session_id)?;
                Request::new("vs_viewport")
                    .arg(page.clone())
                    .arg(spec.clone())
                    .flag_value("session", s)
                    .flag_value("dpr", dpr.to_string())
            }
            Self::Layout { page, refs } => {
                let s = require_session(session_id)?;
                let mut req = Request::new("vs_layout").arg(page.clone());
                for r in refs {
                    req = req.arg(r.to_string());
                }
                req.flag_value("session", s)
            }
            Self::Auth { sub, rest } => {
                let s = require_session(session_id)?;
                let mut req = Request::new("vs_auth")
                    .arg(sub.clone())
                    .flag_value("session", s);
                for r in rest {
                    req = req.arg(r.clone());
                }
                req
            }
            Self::Inspect {
                page,
                kind,
                rest,
                since,
                level,
                status,
                max,
                full,
                unsafe_log,
            } => {
                let s = require_session(session_id)?;
                let kind_long = normalize_inspect_kind(kind);
                let mut req = Request::new("vs_inspect")
                    .arg(kind_long.to_string())
                    .arg(page.clone());
                for r in rest {
                    req = req.arg(r.clone());
                }
                req = req.flag_value("session", s);
                if let Some(v) = since {
                    req = req.flag_value("since", v.clone());
                }
                if let Some(v) = level {
                    req = req.flag_value("level", v.clone());
                }
                if let Some(v) = status {
                    req = req.flag_value("status", v.clone());
                }
                if let Some(v) = max {
                    req = req.flag_value("max", v.clone());
                }
                if *full {
                    req = req.flag("full");
                }
                if *unsafe_log {
                    req = req.flag("unsafe-log");
                }
                req
            }
            Self::MoveTo { page, x, y, mode } => {
                let s = require_session(session_id)?;
                Request::new("vs_move_to")
                    .arg(page.clone())
                    .arg(x.to_string())
                    .arg(y.to_string())
                    .flag_value("session", s)
                    .flag_value("mode", mode.clone())
            }
            Self::ClickAt {
                page,
                x,
                y,
                token,
                mode,
            } => {
                let s = require_session(session_id)?;
                Request::new("vs_click_at")
                    .arg(page.clone())
                    .arg(x.to_string())
                    .arg(y.to_string())
                    .flag_value("session", s)
                    .flag_value("token", token.clone())
                    .flag_value("mode", mode.clone())
            }
            Self::HoverAt { page, x, y, mode } => {
                let s = require_session(session_id)?;
                Request::new("vs_hover_at")
                    .arg(page.clone())
                    .arg(x.to_string())
                    .arg(y.to_string())
                    .flag_value("session", s)
                    .flag_value("mode", mode.clone())
            }
            Self::Drag {
                page,
                x1,
                y1,
                x2,
                y2,
                token,
                mode,
            } => {
                let s = require_session(session_id)?;
                Request::new("vs_drag")
                    .arg(page.clone())
                    .arg(x1.to_string())
                    .arg(y1.to_string())
                    .arg(x2.to_string())
                    .arg(y2.to_string())
                    .flag_value("session", s)
                    .flag_value("token", token.clone())
                    .flag_value("mode", mode.clone())
            }
            Self::PromptInput { .. } | Self::PromptConfirm { .. } => {
                anyhow::bail!("vs_prompt_* is local; route via main, not the wire dispatcher");
            }
            Self::PromptInputQueue {
                page, r, message, secret, token, group, timeout_ms,
            } => {
                let s = require_session(session_id)?;
                let mut req = Request::new("vs_prompt_input_queue")
                    .arg(page.clone())
                    .arg(r.to_string())
                    .arg(message.clone())
                    .flag_value("session", s)
                    .flag_value("token", token.clone())
                    .flag_value("timeout-ms", timeout_ms.to_string());
                if *secret { req = req.flag("secret"); }
                if let Some(g) = group { req = req.flag_value("group", g.clone()); }
                req
            }
            Self::Pending { sub } => match sub {
                PendingSub::List => Request::new("vs_pending_list"),
                PendingSub::Fulfill { id } => {
                    // CLI side reads value from tty before sending the
                    // wire request — handled in dispatch.rs. Here we
                    // just stub a placeholder; dispatch overrides the
                    // value arg with what the user typed.
                    let id_v = id.clone().unwrap_or_default();
                    Request::new("vs_pending_fulfill").arg(id_v).arg(String::new())
                }
                PendingSub::Cancel { id } => Request::new("vs_pending_cancel").arg(id.clone()),
            },
            Self::Serve { .. } => {
                anyhow::bail!("vs_serve is local; route via main, not the wire dispatcher");
            }
            Self::Mcp => {
                anyhow::bail!("vs_mcp is local; route via main, not the wire dispatcher");
            }
        })
    }

    /// True if this subcommand requires an active session.
    #[must_use]
    pub fn needs_session(&self) -> bool {
        !matches!(
            self,
            Self::SessionOpen { .. } | Self::Status | Self::Serve { .. } | Self::Mcp | Self::Pending { .. }
        )
    }
}

fn require_session(session: Option<&str>) -> Result<String> {
    session
        .map(str::to_string)
        .context("no active session — run `vs session-open` or pass `--session=<id>`")
}

/// Map short-form inspect kind aliases to their long form. Unknown
/// inputs pass through unchanged so the wire-side parser can reject
/// or accept them — the CLI does not gatekeep here. The two-letter
/// short forms are unambiguous within the inspect subcommand set.
fn normalize_inspect_kind(kind: &str) -> &str {
    match kind {
        "co" => "console",
        "n" => "network",
        "req" => "request",
        "e" => "eval",
        "s" => "storage",
        "scr" => "scripts",
        "src" => "script",
        "d" => "dom",
        "p" => "performance",
        "ce" => "cookie-events",
        other => other,
    }
}

mod dispatch;
mod render;

pub use dispatch::{connect, resolve_paths, resolve_session, run};
pub use render::render;