roswire 0.1.1

JSON-first RouterOS CLI bridge for AI agents and automation.
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
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
use crate::args::Cli;
use crate::error::{RosWireError, RosWireResult};
use serde::Serialize;

pub mod cache;
pub mod discovery;
pub mod doctor;

#[derive(Debug, Clone, Serialize)]
pub struct ArgumentSpec {
    pub name: String,
    pub style: String,
    pub required: bool,
    #[serde(rename = "type")]
    pub arg_type: String,
    pub description: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub example: Option<String>,
}

#[derive(Debug, Clone, Serialize)]
pub struct CommandDefinition {
    pub name: String,
    pub summary: String,
    pub kind: String,
    pub syntax: String,
    pub arguments: Vec<ArgumentSpec>,
    pub examples: Vec<String>,
    pub errors: Vec<String>,
}

#[derive(Debug, Serialize)]
struct CommandsPayload {
    schema_version: &'static str,
    commands: Vec<CommandSummary>,
}

#[derive(Debug, Serialize)]
struct CommandSummary {
    name: String,
    summary: String,
    kind: String,
}

#[derive(Debug, Serialize)]
struct HelpPayload {
    schema_version: &'static str,
    command: CommandDefinition,
}

#[derive(Debug, Serialize)]
struct HelpIndexPayload {
    schema_version: &'static str,
    global_options: Vec<String>,
    commands: Vec<CommandSummary>,
}

#[derive(Debug, Serialize)]
struct SchemaPayload {
    schema_version: &'static str,
    command: String,
    arguments: Vec<ArgumentSpec>,
}

#[derive(Debug, Serialize)]
struct ExplainErrorPayload {
    schema_version: &'static str,
    error_code: String,
    summary: String,
    common_causes: Vec<String>,
    suggested_next_steps: Vec<String>,
}

pub fn handle(tokens: &[String], cli: &Cli) -> Option<RosWireResult<String>> {
    if tokens.is_empty() {
        return None;
    }

    let command = tokens[0].as_str();

    if cli.remote && command == "commands" {
        return Some(Err(Box::new(RosWireError::remote_schema_unavailable())));
    }

    match command {
        "commands" => Some(render_json(&commands_payload())),
        "doctor" => Some(doctor::doctor_payload(cli)),
        "help" => Some(help_payload(tokens)),
        "schema" if cli.remote => Some(remote_schema_payload(tokens, cli)),
        "schema" => Some(schema_payload(tokens)),
        "explain-error" => Some(explain_error_payload(tokens)),
        _ => None,
    }
}

fn commands_payload() -> CommandsPayload {
    let commands = catalog()
        .into_iter()
        .map(|entry| CommandSummary {
            name: entry.name,
            summary: entry.summary,
            kind: entry.kind,
        })
        .collect();

    CommandsPayload {
        schema_version: "roswire.commands.v1",
        commands,
    }
}

fn help_payload(tokens: &[String]) -> RosWireResult<String> {
    if tokens.len() == 1 {
        let payload = HelpIndexPayload {
            schema_version: "roswire.help.index.v1",
            global_options: vec![
                "--profile".to_owned(),
                "--host".to_owned(),
                "--user".to_owned(),
                "--password".to_owned(),
                "--protocol".to_owned(),
                "--routeros-version".to_owned(),
                "--transfer".to_owned(),
                "--port".to_owned(),
                "--json".to_owned(),
                "--debug".to_owned(),
                "--include-remote".to_owned(),
                "--refresh".to_owned(),
                "--source".to_owned(),
                "--allow-write".to_owned(),
            ],
            commands: commands_payload().commands,
        };
        return render_json(&payload);
    }

    let topic = normalize_topic(&tokens[1..]);
    let command = lookup_command(&topic)
        .ok_or_else(|| Box::new(RosWireError::help_topic_not_found(topic.clone())))?;

    render_json(&HelpPayload {
        schema_version: "roswire.command.help.v1",
        command,
    })
}

fn schema_payload(tokens: &[String]) -> RosWireResult<String> {
    if tokens.get(1).map(String::as_str) == Some("discover") {
        return Err(Box::new(RosWireError::usage(
            "schema discover requires --remote: roswire schema discover --remote --json",
        )));
    }

    if tokens.len() < 3 || tokens[1].as_str() != "command" {
        return Err(Box::new(RosWireError::usage(
            "schema command requires: roswire schema command <command...>",
        )));
    }

    let topic = normalize_topic(&tokens[2..]);
    let command = lookup_command(&topic)
        .ok_or_else(|| Box::new(RosWireError::schema_unavailable(topic.clone())))?;

    render_json(&SchemaPayload {
        schema_version: "roswire.command.schema.v1",
        command: command.name,
        arguments: command.arguments,
    })
}

fn remote_schema_payload(tokens: &[String], cli: &Cli) -> RosWireResult<String> {
    let commands = catalog();
    let policies = match tokens.get(1).map(String::as_str) {
        Some("discover") => discovery::policies_from_catalog(&commands),
        Some("command") if tokens.len() >= 3 => {
            let topic = normalize_topic(&tokens[2..]);
            let command = lookup_command(&topic)
                .ok_or_else(|| Box::new(RosWireError::schema_unavailable(topic.clone())))?;
            discovery::policy_from_command(&command)
                .map(|policy| vec![policy])
                .ok_or_else(|| Box::new(RosWireError::schema_unavailable(topic)))?
        }
        _ => {
            return Err(Box::new(RosWireError::usage(
                "remote schema requires: roswire schema discover --remote --json or roswire schema command <command...> --remote --json",
            )));
        }
    };

    let (profile, fingerprint, warning) = match crate::resolve_execution_target(cli) {
        Ok(target) => (
            cli.profile.clone().unwrap_or_else(|| "default".to_owned()),
            discovery::unknown_fingerprint(&target.host, &target.requested_protocol),
            "CAPABILITY_PROBE_FAILED".to_owned(),
        ),
        Err(error) => (
            cli.profile.clone().unwrap_or_else(|| "default".to_owned()),
            discovery::unknown_fingerprint("unknown", "unknown"),
            discovery::warning_name(error.error_code),
        ),
    };

    let cache_status = if cli.refresh {
        cache::CacheLookupStatus::Refresh
    } else {
        cache::CacheLookupStatus::Miss
    };
    let snapshot = discovery::degraded_remote_schema_snapshot_with_cache_status(
        &profile,
        &fingerprint,
        policies,
        warning,
        cache_status,
    );
    render_json(&snapshot)
}

fn explain_error_payload(tokens: &[String]) -> RosWireResult<String> {
    if tokens.len() < 2 {
        return Err(Box::new(RosWireError::usage(
            "missing error code: roswire explain-error <CODE>",
        )));
    }

    let code = tokens[1].to_ascii_uppercase();
    let payload = match code.as_str() {
        "ROS_API_FAILURE" => ExplainErrorPayload {
            schema_version: "roswire.error.explain.v1",
            error_code: code,
            summary: "RouterOS returned a trap or command failure.".to_owned(),
            common_causes: vec![
                "target interface/item does not exist".to_owned(),
                "argument value does not match menu expectations".to_owned(),
            ],
            suggested_next_steps: vec![
                "run `roswire interface print --json` to discover valid interfaces".to_owned(),
                "verify key=value arguments and .id references".to_owned(),
            ],
        },
        "USAGE_ERROR" => ExplainErrorPayload {
            schema_version: "roswire.error.explain.v1",
            error_code: code,
            summary: "CLI arguments are missing or invalid.".to_owned(),
            common_causes: vec![
                "missing action token".to_owned(),
                "malformed key=value argument".to_owned(),
            ],
            suggested_next_steps: vec![
                "run `roswire help --json` to inspect command contracts".to_owned(),
                "run `roswire commands --json` for command discovery".to_owned(),
            ],
        },
        "SSH_RESTORE_FAILED" => ExplainErrorPayload {
            schema_version: "roswire.error.explain.v1",
            error_code: code,
            summary:
                "RosWire could not restore the RouterOS SSH service state captured before transfer."
                    .to_owned(),
            common_causes: vec![
                "RouterOS rejected /ip service ssh restore fields".to_owned(),
                "control protocol connection failed during cleanup".to_owned(),
            ],
            suggested_next_steps: vec![
                "inspect `/ip service print where name=ssh` on the router".to_owned(),
                "restore the intended disabled/address values manually before retrying".to_owned(),
            ],
        },
        _ => {
            return Err(Box::new(RosWireError::help_topic_not_found(format!(
                "error code {code}",
            ))));
        }
    };

    render_json(&payload)
}

fn render_json<T: Serialize>(value: &T) -> RosWireResult<String> {
    serde_json::to_string_pretty(value).map_err(|error| {
        Box::new(RosWireError::internal(format!(
            "failed to serialize introspection payload: {error}",
        )))
    })
}

fn normalize_topic(tokens: &[String]) -> String {
    tokens
        .iter()
        .flat_map(|token| token.split_whitespace())
        .collect::<Vec<_>>()
        .join(" ")
        .to_ascii_lowercase()
}

fn lookup_command(topic: &str) -> Option<CommandDefinition> {
    catalog()
        .into_iter()
        .find(|command| command.name.eq_ignore_ascii_case(topic))
}

fn catalog() -> Vec<CommandDefinition> {
    vec![
        CommandDefinition {
            name: "ip address print".to_owned(),
            summary: "Print IP address records.".to_owned(),
            kind: "routeros-command".to_owned(),
            syntax: "roswire ip address print --json".to_owned(),
            arguments: vec![],
            examples: vec!["roswire ip address print --json".to_owned()],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "AUTH_FAILED".to_owned(),
                "NETWORK_ERROR".to_owned(),
                "ROS_API_FAILURE".to_owned(),
            ],
        },
        CommandDefinition {
            name: "ip address add".to_owned(),
            summary: "Add an IP address entry.".to_owned(),
            kind: "routeros-command".to_owned(),
            syntax: "roswire ip address add address=<cidr> interface=<name> --json".to_owned(),
            arguments: vec![
                ArgumentSpec {
                    name: "address".to_owned(),
                    style: "key-value".to_owned(),
                    required: true,
                    arg_type: "cidr".to_owned(),
                    description: "Address with prefix length.".to_owned(),
                    example: Some("192.168.88.2/24".to_owned()),
                },
                ArgumentSpec {
                    name: "interface".to_owned(),
                    style: "key-value".to_owned(),
                    required: true,
                    arg_type: "string".to_owned(),
                    description: "RouterOS interface name.".to_owned(),
                    example: Some("bridge".to_owned()),
                },
            ],
            examples: vec![
                "roswire ip address add address=192.168.88.2/24 interface=bridge --json".to_owned(),
            ],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "AUTH_FAILED".to_owned(),
                "NETWORK_ERROR".to_owned(),
                "ROS_API_FAILURE".to_owned(),
            ],
        },
        CommandDefinition {
            name: "ip address set".to_owned(),
            summary: "Update an existing IP address entry.".to_owned(),
            kind: "routeros-command".to_owned(),
            syntax: "roswire ip address set .id=<id> disabled=<bool> --json".to_owned(),
            arguments: vec![
                ArgumentSpec {
                    name: ".id".to_owned(),
                    style: "key-value".to_owned(),
                    required: true,
                    arg_type: "string".to_owned(),
                    description: "RouterOS internal item ID.".to_owned(),
                    example: Some("*1".to_owned()),
                },
                ArgumentSpec {
                    name: "disabled".to_owned(),
                    style: "key-value".to_owned(),
                    required: false,
                    arg_type: "bool".to_owned(),
                    description: "Disable or enable the address entry.".to_owned(),
                    example: Some("true".to_owned()),
                },
            ],
            examples: vec!["roswire ip address set .id=*1 disabled=true --json".to_owned()],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "AUTH_FAILED".to_owned(),
                "NETWORK_ERROR".to_owned(),
                "ROS_API_FAILURE".to_owned(),
            ],
        },
        CommandDefinition {
            name: "ip address remove".to_owned(),
            summary: "Remove an IP address entry.".to_owned(),
            kind: "routeros-command".to_owned(),
            syntax: "roswire ip address remove .id=<id> --json".to_owned(),
            arguments: vec![ArgumentSpec {
                name: ".id".to_owned(),
                style: "key-value".to_owned(),
                required: true,
                arg_type: "string".to_owned(),
                description: "RouterOS internal item ID.".to_owned(),
                example: Some("*1".to_owned()),
            }],
            examples: vec!["roswire ip address remove .id=*1 --json".to_owned()],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "AUTH_FAILED".to_owned(),
                "NETWORK_ERROR".to_owned(),
                "ROS_API_FAILURE".to_owned(),
            ],
        },
        CommandDefinition {
            name: "ip firewall address-list print".to_owned(),
            summary: "Print firewall address-list entries.".to_owned(),
            kind: "routeros-command".to_owned(),
            syntax: "roswire ip firewall address-list print --json".to_owned(),
            arguments: vec![],
            examples: vec!["roswire ip firewall address-list print --json".to_owned()],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "AUTH_FAILED".to_owned(),
                "NETWORK_ERROR".to_owned(),
                "ROS_API_FAILURE".to_owned(),
            ],
        },
        CommandDefinition {
            name: "ip firewall filter print".to_owned(),
            summary: "Print firewall filter rules without changing packet handling.".to_owned(),
            kind: "routeros-command".to_owned(),
            syntax: "roswire ip firewall filter print --json".to_owned(),
            arguments: vec![],
            examples: vec!["roswire ip firewall filter print --json".to_owned()],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "AUTH_FAILED".to_owned(),
                "NETWORK_ERROR".to_owned(),
                "ROS_API_FAILURE".to_owned(),
            ],
        },
        CommandDefinition {
            name: "ip firewall nat print".to_owned(),
            summary: "Print firewall NAT rules without changing packet handling.".to_owned(),
            kind: "routeros-command".to_owned(),
            syntax: "roswire ip firewall nat print --json".to_owned(),
            arguments: vec![],
            examples: vec!["roswire ip firewall nat print --json".to_owned()],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "AUTH_FAILED".to_owned(),
                "NETWORK_ERROR".to_owned(),
                "ROS_API_FAILURE".to_owned(),
            ],
        },
        CommandDefinition {
            name: "ip route print".to_owned(),
            summary: "Print RouterOS IP routes, including v6/v7 route table fields when present."
                .to_owned(),
            kind: "routeros-command".to_owned(),
            syntax: "roswire ip route print --json".to_owned(),
            arguments: vec![],
            examples: vec!["roswire ip route print --json".to_owned()],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "AUTH_FAILED".to_owned(),
                "NETWORK_ERROR".to_owned(),
                "ROS_API_FAILURE".to_owned(),
            ],
        },
        CommandDefinition {
            name: "interface print".to_owned(),
            summary: "Print interface list.".to_owned(),
            kind: "routeros-command".to_owned(),
            syntax: "roswire interface print --json".to_owned(),
            arguments: vec![],
            examples: vec!["roswire interface print --json".to_owned()],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "AUTH_FAILED".to_owned(),
                "NETWORK_ERROR".to_owned(),
                "ROS_API_FAILURE".to_owned(),
            ],
        },
        CommandDefinition {
            name: "interface wireguard print".to_owned(),
            summary: "Print RouterOS v7 WireGuard interfaces without exposing private keys."
                .to_owned(),
            kind: "routeros-command".to_owned(),
            syntax: "roswire interface wireguard print --json".to_owned(),
            arguments: vec![],
            examples: vec!["roswire interface wireguard print --json".to_owned()],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "AUTH_FAILED".to_owned(),
                "NETWORK_ERROR".to_owned(),
                "ROS_API_FAILURE".to_owned(),
            ],
        },
        CommandDefinition {
            name: "interface wireguard peers print".to_owned(),
            summary: "Print RouterOS v7 WireGuard peers without exposing preshared keys."
                .to_owned(),
            kind: "routeros-command".to_owned(),
            syntax: "roswire interface wireguard peers print --json".to_owned(),
            arguments: vec![],
            examples: vec!["roswire interface wireguard peers print --json".to_owned()],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "AUTH_FAILED".to_owned(),
                "NETWORK_ERROR".to_owned(),
                "ROS_API_FAILURE".to_owned(),
            ],
        },
        CommandDefinition {
            name: "system package print".to_owned(),
            summary: "Print installed RouterOS packages.".to_owned(),
            kind: "routeros-command".to_owned(),
            syntax: "roswire system package print --json".to_owned(),
            arguments: vec![],
            examples: vec!["roswire system package print --json".to_owned()],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "AUTH_FAILED".to_owned(),
                "NETWORK_ERROR".to_owned(),
                "ROS_API_FAILURE".to_owned(),
            ],
        },
        CommandDefinition {
            name: "script put".to_owned(),
            summary: "Read local .rsc text and store it as a RouterOS system script without creating a RouterOS file.".to_owned(),
            kind: "workflow".to_owned(),
            syntax: "roswire script put <name> --source @<local.rsc> --json".to_owned(),
            arguments: vec![
                ArgumentSpec {
                    name: "name".to_owned(),
                    style: "positional".to_owned(),
                    required: true,
                    arg_type: "string".to_owned(),
                    description: "RouterOS system script name to create.".to_owned(),
                    example: Some("bootstrap".to_owned()),
                },
                ArgumentSpec {
                    name: "--source".to_owned(),
                    style: "option".to_owned(),
                    required: true,
                    arg_type: "@path".to_owned(),
                    description: "Local UTF-8 .rsc file to read as script source. The content is never printed in errors or dry-run output.".to_owned(),
                    example: Some("@setup.rsc".to_owned()),
                },
            ],
            examples: vec![
                "roswire script put bootstrap --source @setup.rsc --dry-run --json".to_owned(),
                "roswire --profile lab script put bootstrap --source @setup.rsc --json".to_owned(),
            ],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "FILE_TOO_LARGE".to_owned(),
                "CONFIG_ERROR".to_owned(),
                "AUTH_FAILED".to_owned(),
                "NETWORK_ERROR".to_owned(),
                "ROS_API_FAILURE".to_owned(),
            ],
        },
        CommandDefinition {
            name: "raw".to_owned(),
            summary: "Explicitly pass a RouterOS classic API path and key=value words for advanced unsupported commands.".to_owned(),
            kind: "raw-routeros-command".to_owned(),
            syntax: "roswire raw /system/resource/print [key=value ...] --json".to_owned(),
            arguments: vec![
                ArgumentSpec {
                    name: "routeros-path".to_owned(),
                    style: "positional".to_owned(),
                    required: true,
                    arg_type: "classic-api-path".to_owned(),
                    description: "RouterOS classic API path beginning with `/`, e.g. /system/resource/print.".to_owned(),
                    example: Some("/system/resource/print".to_owned()),
                },
                ArgumentSpec {
                    name: "key=value".to_owned(),
                    style: "key-value".to_owned(),
                    required: false,
                    arg_type: "string".to_owned(),
                    description: "Additional RouterOS API word arguments. Sensitive keys and local paths are redacted in errors/logs.".to_owned(),
                    example: Some("detail=yes".to_owned()),
                },
                ArgumentSpec {
                    name: "--allow-write".to_owned(),
                    style: "flag".to_owned(),
                    required: false,
                    arg_type: "bool".to_owned(),
                    description: "Required for raw commands that are not `/.../print`; REST generic raw passthrough is intentionally unavailable.".to_owned(),
                    example: Some("--allow-write".to_owned()),
                },
            ],
            examples: vec![
                "roswire raw /system/resource/print --json".to_owned(),
                "roswire raw /tool/fetch url=https://example.invalid/a.rsc --allow-write --json".to_owned(),
            ],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "CONFIG_ERROR".to_owned(),
                "AUTH_FAILED".to_owned(),
                "NETWORK_ERROR".to_owned(),
                "ROS_API_FAILURE".to_owned(),
                "UNSUPPORTED_ACTION".to_owned(),
            ],
        },
        CommandDefinition {
            name: "tool mac-server print".to_owned(),
            summary: "Print RouterOS MAC server settings without changing service state."
                .to_owned(),
            kind: "routeros-command".to_owned(),
            syntax: "roswire tool mac-server print --json".to_owned(),
            arguments: vec![],
            examples: vec!["roswire tool mac-server print --json".to_owned()],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "AUTH_FAILED".to_owned(),
                "NETWORK_ERROR".to_owned(),
                "ROS_API_FAILURE".to_owned(),
            ],
        },
        CommandDefinition {
            name: "tool netwatch print".to_owned(),
            summary: "Print RouterOS Netwatch entries; does not run ad-hoc probes.".to_owned(),
            kind: "routeros-command".to_owned(),
            syntax: "roswire tool netwatch print --json".to_owned(),
            arguments: vec![],
            examples: vec!["roswire tool netwatch print --json".to_owned()],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "AUTH_FAILED".to_owned(),
                "NETWORK_ERROR".to_owned(),
                "ROS_API_FAILURE".to_owned(),
            ],
        },
        CommandDefinition {
            name: "user print".to_owned(),
            summary: "Print RouterOS users without exposing password material.".to_owned(),
            kind: "routeros-command".to_owned(),
            syntax: "roswire user print --json".to_owned(),
            arguments: vec![],
            examples: vec!["roswire user print --json".to_owned()],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "AUTH_FAILED".to_owned(),
                "NETWORK_ERROR".to_owned(),
                "ROS_API_FAILURE".to_owned(),
            ],
        },
        CommandDefinition {
            name: "config inspect".to_owned(),
            summary: "Inspect resolved local configuration and source precedence.".to_owned(),
            kind: "config".to_owned(),
            syntax: "roswire config inspect --json".to_owned(),
            arguments: vec![],
            examples: vec!["roswire config inspect --json".to_owned()],
            errors: vec![
                "CONFIG_ERROR".to_owned(),
                "PROFILE_NOT_FOUND".to_owned(),
                "CONFIG_INSECURE_PERMISSIONS".to_owned(),
            ],
        },
        CommandDefinition {
            name: "config init".to_owned(),
            summary: "Initialize ~/.roswire home, logs, and config.toml".to_owned(),
            kind: "config".to_owned(),
            syntax: "roswire config init --json".to_owned(),
            arguments: vec![],
            examples: vec!["roswire config init --json".to_owned()],
            errors: vec!["CONFIG_ERROR".to_owned(), "INTERNAL_ERROR".to_owned()],
        },
        CommandDefinition {
            name: "config profiles".to_owned(),
            summary: "List configured profiles and default profile.".to_owned(),
            kind: "config".to_owned(),
            syntax: "roswire config profiles --json".to_owned(),
            arguments: vec![],
            examples: vec!["roswire config profiles --json".to_owned()],
            errors: vec!["CONFIG_ERROR".to_owned()],
        },
        CommandDefinition {
            name: "config device add".to_owned(),
            summary: "Create a profile/device entry in config.toml.".to_owned(),
            kind: "config".to_owned(),
            syntax: "roswire config device add <profile> host=<host> user=<user> [protocol=<mode>] [transfer=<mode>] [port=<n>] [ssh_host_key=<fingerprint>] [allow_from=<cidr>[,<cidr>...]] --json".to_owned(),
            arguments: vec![
                ArgumentSpec {
                    name: "profile".to_owned(),
                    style: "positional".to_owned(),
                    required: true,
                    arg_type: "string".to_owned(),
                    description: "Profile name to create.".to_owned(),
                    example: Some("studio-router".to_owned()),
                },
                ArgumentSpec {
                    name: "host".to_owned(),
                    style: "key-value".to_owned(),
                    required: true,
                    arg_type: "string".to_owned(),
                    description: "Router host/IP".to_owned(),
                    example: Some("10.189.189.1".to_owned()),
                },
                ArgumentSpec {
                    name: "user".to_owned(),
                    style: "key-value".to_owned(),
                    required: true,
                    arg_type: "string".to_owned(),
                    description: "Router username".to_owned(),
                    example: Some("master".to_owned()),
                },
            ],
            examples: vec![
                "roswire config device add studio-router host=10.189.189.1 user=master ssh_host_key=SHA256:abc allow_from=203.0.113.10/32 --json".to_owned(),
            ],
            errors: vec!["USAGE_ERROR".to_owned(), "CONFIG_ERROR".to_owned()],
        },
        CommandDefinition {
            name: "config device set".to_owned(),
            summary: "Update an existing profile/device entry in config.toml.".to_owned(),
            kind: "config".to_owned(),
            syntax: "roswire config device set <profile> [host=<host>] [user=<user>] [protocol=<mode>] [transfer=<mode>] [port=<n>] [ssh_host_key=<fingerprint>] [allow_from=<cidr>[,<cidr>...]] --json".to_owned(),
            arguments: vec![ArgumentSpec {
                name: "profile".to_owned(),
                style: "positional".to_owned(),
                required: true,
                arg_type: "string".to_owned(),
                description: "Profile name to update.".to_owned(),
                example: Some("studio-router".to_owned()),
            }],
            examples: vec![
                "roswire config device set studio-router protocol=rest --json".to_owned(),
            ],
            errors: vec!["USAGE_ERROR".to_owned(), "CONFIG_ERROR".to_owned()],
        },
        CommandDefinition {
            name: "config secret set".to_owned(),
            summary: "Set profile secret using plain/encrypted/keychain/same-as types.".to_owned(),
            kind: "config".to_owned(),
            syntax: "roswire config secret set <profile> <name> type=<plain|encrypted|keychain|same-as> ... --json".to_owned(),
            arguments: vec![
                ArgumentSpec {
                    name: "profile".to_owned(),
                    style: "positional".to_owned(),
                    required: true,
                    arg_type: "string".to_owned(),
                    description: "Profile name.".to_owned(),
                    example: Some("studio-router".to_owned()),
                },
                ArgumentSpec {
                    name: "name".to_owned(),
                    style: "positional".to_owned(),
                    required: true,
                    arg_type: "string".to_owned(),
                    description: "Secret key name, e.g. password.".to_owned(),
                    example: Some("password".to_owned()),
                },
                ArgumentSpec {
                    name: "type".to_owned(),
                    style: "key-value".to_owned(),
                    required: true,
                    arg_type: "string".to_owned(),
                    description: "Secret backend type.".to_owned(),
                    example: Some("keychain".to_owned()),
                },
            ],
            examples: vec![
                "roswire config secret set studio-router password type=plain value=All.007! --json".to_owned(),
                "roswire config secret set studio-router password type=keychain service=roswire account=profiles/studio-router/password --json".to_owned(),
                "roswire config secret set studio-router ssh_password type=same-as target=password --json".to_owned(),
                "roswire config secret set studio-router ssh_key_passphrase type=env var=ROSWIRE_STUDIO_SSH_KEY_PASSPHRASE --json".to_owned(),
            ],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "PROFILE_NOT_FOUND".to_owned(),
                "CONFIG_ERROR".to_owned(),
            ],
        },
        CommandDefinition {
            name: "doctor".to_owned(),
            summary: "Run local diagnostics and optionally include read-only remote checks."
                .to_owned(),
            kind: "introspection".to_owned(),
            syntax: "roswire doctor [--include-remote] --json".to_owned(),
            arguments: vec![ArgumentSpec {
                name: "--include-remote".to_owned(),
                style: "flag".to_owned(),
                required: false,
                arg_type: "bool".to_owned(),
                description: "Include read-only RouterOS port/login/resource diagnostics."
                    .to_owned(),
                example: Some("--include-remote".to_owned()),
            }],
            examples: vec![
                "roswire doctor --json".to_owned(),
                "roswire --profile studio-router doctor --include-remote --json".to_owned(),
            ],
            errors: vec![
                "CONFIG_ERROR".to_owned(),
                "AUTH_FAILED".to_owned(),
                "NETWORK_ERROR".to_owned(),
                "ROS_API_FAILURE".to_owned(),
            ],
        },
        CommandDefinition {
            name: "commands".to_owned(),
            summary: "List command index for agent discovery.".to_owned(),
            kind: "introspection".to_owned(),
            syntax: "roswire commands --json".to_owned(),
            arguments: vec![],
            examples: vec!["roswire commands --json".to_owned()],
            errors: vec!["USAGE_ERROR".to_owned()],
        },
        CommandDefinition {
            name: "schema command".to_owned(),
            summary: "Show argument schema for a command topic.".to_owned(),
            kind: "introspection".to_owned(),
            syntax: "roswire schema command ip address add --json".to_owned(),
            arguments: vec![ArgumentSpec {
                name: "command".to_owned(),
                style: "positional".to_owned(),
                required: true,
                arg_type: "string".to_owned(),
                description: "Command topic, e.g. `ip address add`.".to_owned(),
                example: Some("ip address add".to_owned()),
            }],
            examples: vec!["roswire schema command ip address add --json".to_owned()],
            errors: vec!["SCHEMA_UNAVAILABLE".to_owned(), "USAGE_ERROR".to_owned()],
        },
        CommandDefinition {
            name: "schema discover".to_owned(),
            summary: "Discover remote schema overlay with cache TTL metadata.".to_owned(),
            kind: "introspection".to_owned(),
            syntax: "roswire schema discover --remote [--refresh] --json".to_owned(),
            arguments: vec![
                ArgumentSpec {
                    name: "--remote".to_owned(),
                    style: "flag".to_owned(),
                    required: true,
                    arg_type: "bool".to_owned(),
                    description: "Enable remote schema discovery.".to_owned(),
                    example: Some("--remote".to_owned()),
                },
                ArgumentSpec {
                    name: "--refresh".to_owned(),
                    style: "flag".to_owned(),
                    required: false,
                    arg_type: "bool".to_owned(),
                    description: "Bypass cached remote schema metadata and mark the cache status as refresh.".to_owned(),
                    example: Some("--refresh".to_owned()),
                },
            ],
            examples: vec![
                "roswire schema discover --remote --json".to_owned(),
                "roswire schema discover --remote --refresh --json".to_owned(),
            ],
            errors: vec![
                "USAGE_ERROR".to_owned(),
                "CONFIG_ERROR".to_owned(),
                "REMOTE_SCHEMA_UNAVAILABLE".to_owned(),
            ],
        },
    ]
}