sparrow-cli 0.5.1

A local-first Rust agent cockpit โ€” route, run, replay, rewind
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
use clap::{Parser, Subcommand};
use std::path::PathBuf;

#[derive(Parser)]
#[command(name = "sparrow", about = "one cli ยท grows with you", version)]
pub struct Cli {
    #[command(subcommand)]
    pub command: Option<Commands>,

    /// Launch terminal TUI (native)
    #[arg(long)]
    pub tui: bool,

    /// Launch webview console (HTTP + WebSocket)
    #[arg(long)]
    pub web: bool,

    /// JSON output (NDJSON event stream)
    #[arg(long)]
    pub json: bool,

    /// Override autonomy level
    #[arg(long)]
    pub autonomy: Option<String>,

    /// Force a specific model
    #[arg(long)]
    pub model: Option<String>,

    /// Prefer local/offline models
    #[arg(long)]
    pub local: bool,

    /// Session budget cap (USD)
    #[arg(long)]
    pub budget: Option<f64>,

    /// Sandbox backend
    #[arg(long)]
    pub sandbox: Option<String>,

    /// Profile name
    #[arg(long)]
    pub profile: Option<String>,

    /// Disable checkpointing
    #[arg(long)]
    pub no_checkpoint: bool,

    /// Run as a named agent
    #[arg(long)]
    pub agent: Option<String>,
}

#[derive(Subcommand)]
pub enum Commands {
    /// Run a single agentic task
    Run {
        /// Task description
        task: String,

        /// Emit NDJSON event stream (same as the global --json flag, but may
        /// follow the task: `sparrow run "..." --json`)
        #[arg(long)]
        json: bool,
    },

    /// Create a read-only execution plan for a task
    Plan {
        /// Task description
        task: String,

        /// Emit JSON instead of Markdown
        #[arg(long)]
        json: bool,
    },

    /// Interactive multi-turn chat
    Chat,

    /// Launch TUI
    Tui,

    /// Launch first-run setup, then the WebView cockpit
    Launch {
        /// TCP port for the WebView HTTP/WS server
        #[arg(long, default_value = "9339")]
        port: u16,

        /// Launch the terminal TUI instead of the WebView cockpit
        #[arg(long)]
        tui: bool,
    },

    /// Launch webview console (HTTP + WebSocket)
    Console {
        /// TCP port for the webview HTTP/WS server
        #[arg(long, default_value = "9339")]
        port: u16,
    },

    /// Run headless Sparrow runtime daemon
    Daemon,

    /// Manage persistent agents
    Agent {
        #[command(subcommand)]
        action: AgentAction,
    },

    /// Run swarm: planner โ†’ coder โ†’ verifier
    Swarm {
        /// Task or plan file
        task: String,
    },

    /// Schedule periodic jobs
    Schedule {
        /// Task description
        task: String,

        /// Cron expression
        #[arg(long)]
        cron: String,

        /// Autonomy level for scheduled jobs
        #[arg(long)]
        autonomy: Option<String>,

        /// Report to surfaces
        #[arg(long)]
        report: Vec<String>,
    },

    /// Manage model routing
    Model {
        /// Set active route
        #[arg(long)]
        set: Option<String>,

        /// List available models
        #[arg(long)]
        list: bool,
    },

    /// Configure intelligent auto-routing provider
    Route {
        #[command(subcommand)]
        action: RouteAction,
    },

    /// Manage provider credentials
    Auth {
        #[command(subcommand)]
        action: AuthAction,
    },

    /// Manage skill library
    Skills {
        #[command(subcommand)]
        action: SkillsAction,
    },

    /// Manage local Sparrow plugins
    Plugins {
        #[command(subcommand)]
        action: PluginsAction,
    },

    /// Inspect and gate toolsets
    Tools {
        #[command(subcommand)]
        action: ToolsAction,
    },

    /// Security audit of config, permissions, plugins, hooks, secrets
    Security {
        #[command(subcommand)]
        action: SecurityAction,
    },

    /// GitHub Action / remote PR workflow
    Github {
        #[command(subcommand)]
        action: GithubAction,
    },

    /// Compact context and write a durable handoff doc
    Compact {
        /// Task description (recorded in the handoff)
        #[arg(long)]
        task: Option<String>,
        /// Output path (default: .sparrow/handoff/<timestamp>.md)
        #[arg(long)]
        out: Option<PathBuf>,
        /// Emit JSON instead of Markdown to stdout (the file is always Markdown)
        #[arg(long)]
        json: bool,
    },

    /// Manage MCP connectors
    Mcp {
        #[command(subcommand)]
        action: McpAction,
    },

    /// List checkpoints
    Checkpoint {
        #[command(subcommand)]
        action: CheckpointAction,
    },

    /// Rewind to a checkpoint
    Rewind {
        /// Checkpoint ID or number
        id: String,
    },

    /// Replay a transcript
    Replay {
        /// Run ID to replay
        run_id: String,
        /// Open an interactive TUI scrubber (โ†/โ†’ to step through events)
        #[arg(long)]
        scrub: bool,
    },

    /// Start/stop gateway daemon
    Gateway {
        #[command(subcommand)]
        action: GatewayAction,
    },

    /// Manage saved sessions
    Sessions {
        #[command(subcommand)]
        action: SessionAction,
    },

    /// Interactive tutorial
    Learn,

    /// Initialize a project with .sparrow/ config
    Init,

    /// Show live status (active runs, budget, session)
    Status,

    /// Manage persistent memory
    Memory {
        #[command(subcommand)]
        action: MemoryAction,
    },

    /// Inspect and update permission policy
    Permissions {
        #[command(subcommand)]
        action: PermissionAction,
    },

    /// Profile management
    Profile {
        #[command(subcommand)]
        action: ProfileAction,
    },

    /// Migrate from OpenClaw
    Import {
        #[command(subcommand)]
        source: ImportSource,
    },

    /// Edit configuration
    Config {
        /// Open config.toml in editor
        #[arg(short)]
        edit: bool,
    },

    /// Self-update
    Update,

    /// Run diagnostics
    Doctor,

    /// (Re)run conversational setup
    Setup,

    /// Run a self-contained demo (snake game)
    Demo,

    /// Share latest session as GitHub Gist
    Share,

    /// Install or scan security pre-commit hooks
    Hook {
        #[command(subcommand)]
        action: HookAction,
    },

    /// Voice commands (speak, transcribe, providers)
    Voice {
        #[command(subcommand)]
        action: VoiceAction,
    },
}

#[derive(Subcommand)]
pub enum AgentAction {
    Create { name: String },
    List,
    Edit { name: String },
    Rm { name: String },
    Run { name: String, task: String },
    Mention { name: String, message: String },
}

#[derive(Subcommand)]
pub enum AuthAction {
    Add {
        provider: String,
    },
    List,
    Rm {
        provider: String,
    },
    /// Authenticate a provider via OAuth device flow (github/google/microsoft).
    Login {
        provider: String,
        /// OAuth client id (or set <PROVIDER>_CLIENT_ID env var)
        #[arg(long)]
        client_id: Option<String>,
    },
}

#[derive(Subcommand)]
pub enum SkillsAction {
    List,
    View {
        name: String,
    },
    Create {
        name: String,
    },
    Install {
        source: String,
    },
    Update {
        name: String,
    },
    Prune,
    /// Remove a skill by name (e.g. to delete junk auto-learned skills)
    Rm {
        name: String,
    },
}

#[derive(Subcommand)]
pub enum PluginsAction {
    List,
    Install {
        source: String,
        #[arg(long)]
        allow: bool,
    },
    Rm {
        name: String,
    },
}

#[derive(Subcommand)]
pub enum GithubAction {
    /// Review a pull request: fetch diff via `gh`, run a read-only review prompt
    Review {
        /// PR number
        pr: u64,
        /// Print the review plan without invoking the model or posting comments
        #[arg(long)]
        dry_run: bool,
        /// Override the model id
        #[arg(long)]
        model: Option<String>,
        /// Restrict tool allow-list (comma-separated). Empty = inherit config.
        #[arg(long)]
        allowed_tools: Option<String>,
    },
    /// Show CI status for the current branch (via `gh run list`)
    Status,
    /// Fetch CI logs for a workflow run id (via `gh run view --log`)
    Logs { run_id: String },
}

#[derive(Subcommand)]
pub enum SecurityAction {
    /// Run a full security audit
    Audit {
        /// Emit JSON instead of human-readable summary
        #[arg(long)]
        json: bool,
    },
}

#[derive(Subcommand)]
pub enum ToolsAction {
    List {
        #[arg(long)]
        surface: Option<String>,
    },
    Enable {
        tool: String,
    },
    Disable {
        tool: String,
    },
}

#[derive(Subcommand)]
pub enum McpAction {
    Add {
        server: String,

        /// Command to launch the MCP server
        #[arg(long)]
        command: Option<String>,

        /// Command arguments, either repeated or space-delimited
        #[arg(long, value_delimiter = ' ', allow_hyphen_values = true)]
        args: Vec<String>,

        /// Transport backend: stdio, sse, or url
        #[arg(long)]
        transport: Option<String>,
    },
    List,
    Rm {
        server: String,
    },
}

#[derive(Subcommand)]
pub enum CheckpointAction {
    /// List all checkpoints
    List,
    /// Show diff between HEAD and a checkpoint
    Diff {
        /// Checkpoint ID
        id: String,
    },
    /// Delete checkpoints older than N days (default: 30)
    Prune {
        /// Remove checkpoints older than this many days
        #[arg(long, default_value = "30")]
        older_than_days: u64,
    },
}

#[derive(Subcommand)]
pub enum GatewayAction {
    Start,
    Status,
    Health,
    Abort { run: String },
    Stop,
}

#[derive(Subcommand)]
pub enum SessionAction {
    List,
    Export {
        id: String,
        path: Option<PathBuf>,
    },
    Cleanup {
        #[arg(long, default_value_t = 30)]
        older_than_days: u64,
    },
}

#[derive(Subcommand)]
pub enum ProfileAction {
    Create { name: String },
    List,
    Use { name: String },
}

#[derive(Subcommand)]
pub enum ImportSource {
    Openclaw { path: Option<PathBuf> },
}

#[derive(Subcommand)]
pub enum MemoryAction {
    List,
    Forget {
        id: String,
    },
    Add {
        key: String,
        value: String,
    },
    Replace {
        id: String,
        key: String,
        value: String,
    },
    Recall {
        query: String,
        #[arg(long, default_value_t = 10)]
        limit: usize,
    },
    Consolidate,
    Docs,
    Search {
        query: String,
        #[arg(long, default_value_t = 10)]
        limit: usize,
    },
    Scroll {
        session: String,
        #[arg(long, default_value_t = 0)]
        around: usize,
        #[arg(long, default_value_t = 3)]
        before: usize,
        #[arg(long, default_value_t = 3)]
        after: usize,
    },
    Graph {
        #[command(subcommand)]
        action: GraphAction,
    },
}

#[derive(Subcommand)]
pub enum GraphAction {
    UpsertNode {
        id: String,
        label: String,
        #[arg(long, default_value = "entity")]
        kind: String,
        #[arg(long, default_value = "{}")]
        properties: String,
    },
    UpsertEdge {
        from_id: String,
        relation: String,
        to_id: String,
        #[arg(long)]
        id: Option<String>,
        #[arg(long, default_value_t = 1.0)]
        weight: f64,
        #[arg(long, default_value = "{}")]
        properties: String,
    },
    Get {
        id: String,
    },
    Neighbors {
        id: String,
        #[arg(long, default_value = "both")]
        direction: String,
        #[arg(long, default_value_t = 20)]
        limit: usize,
    },
    Search {
        query: String,
        #[arg(long, default_value_t = 20)]
        limit: usize,
    },
    Export,
    DeleteNode {
        id: String,
    },
    DeleteEdge {
        id: String,
    },
    SyncNeo4j,
}

#[derive(Subcommand)]
pub enum PermissionAction {
    /// Show current permission mode and rules
    List,
    /// Set permission mode (read-only|plan|supervised|trusted|autonomous|emergency-stop)
    Set { mode: String },
    /// Add an explicitly allowed tool pattern
    AllowTool { tool: String },
    /// Add a tool pattern that always asks for approval
    AskTool { tool: String },
    /// Add an explicitly denied tool pattern
    DenyTool { tool: String },
    /// Add an allowed path boundary
    AllowPath { path: PathBuf },
    /// Add a denied path boundary
    DenyPath { path: PathBuf },
}

#[derive(Subcommand)]
pub enum RouteAction {
    /// Pin the intelligent auto-router to a specific provider for all tiers.
    /// Example: sparrow route set opencode-go
    Set {
        /// Provider ID to use for all task tiers (e.g. opencode-go, anthropic, nvidia)
        provider: String,
    },
    /// Clear the pinned provider โ€” let the multi-tier policy decide per task.
    Clear,
    /// Show the current routing config (preferred provider + per-tier policy).
    Show,
}

#[derive(Subcommand)]
pub enum HookAction {
    /// Install pre-commit security hook
    Install,
    /// Scan staged files (or all files with --all) for secrets
    Scan {
        /// Scan entire working tree instead of just staged files
        #[arg(long)]
        all: bool,
    },
}

#[derive(Subcommand)]
pub enum VoiceAction {
    /// Convert text to speech
    Speak { text: String },
    /// Transcribe audio file
    Transcribe { file: String },
    /// List available voice providers
    Providers,
}