Skip to main content

Crate ssh_cli

Crate ssh_cli 

Source
Expand description

§ssh-cli

Full-stack Rust CLI that gives an LLM (Claude Code, Cursor, Windsurf) the ability to operate remote servers over SSH in a subprocess flow via stdin/stdout.

§Modules

ModuleResponsibility
cliClap derive argument definitions (contract)
commandsSubcommand dispatch layer (CAMADA 2)
concurrencyBounded multi-host / tunnel fan-out (Semaphore + JoinSet)
constantsNamed domain constants (XDG names, env keys, network/timing)
netAsync DNS + Happy Eyeballs TCP dial for SSH connect
error/errorsStructured error types via thiserror + retry classification
retryNamed RetryConfig + full-jitter backoff (agent contract)
vpsCRUD and persistence of VPS records (XDG + TOML + 0o600)
secretsPrimary key and default at-rest encryption (ChaCha20-Poly1305)
sshReal one-shot SSH client via russh (password/key, TOFU)
tlsrustls (aws_lc_rs): SSH-over-TLS, mTLS, ACME (feature tls)
i18nBilingual UI (Message enum + exhaustive EN/pt-BR match)
json_wireTyped agent JSON DTOs + compact emit (RFC 8259, not NDJSON)
localeBCP47 detect/negotiate (sys-locale + unic-langid + langneg)
platformWindows UTF-8/VT, runtime env (WSL/container/CI), TTY
maskingUnicode-safe masking of sensitive values
outputSole module authorized for stdout/stderr data emission
pathsPath validation and normalization (anti-traversal, NFC)
signalsOne-shot SIGINT/SIGTERM flags + cooperative should_stop
telemetryProcess-local tracing install (stderr; no OTEL / no files)
validationParse→serde→validator pipeline for config/import (no OTEL)
domainNewtypes: VpsName, Rfc3339Utc, BatchRunId, HttpsUrl, Money…
terminalTTY detection and color choice via termcolor

§Features

FeatureDefaultEffect
ssh-realyesReal SSH via russh + aws-lc-rs (compression none only; G-TLS)
tlsyesrustls ≥0.23.18 + aws_lc_rs: SSH-over-TLS, mTLS, ACME
musl-allocatornoUses mimalloc as #[global_allocator] (binary only; musl/Alpine)
i18n-fullnoReserved: top-20 economic locales (no extra strings yet)
i18n-cjknoReserved: zh-Hans / zh-Hant / ja / ko
i18n-rtlnoReserved: ar / he (RTL isolation)
i18n-europenoReserved: additional European locales

Disable real SSH only for dependency diagnosis: --no-default-features. Documented feature gates use #[doc(cfg(...))] under the docsrs cfg. Default binary always embeds en + pt-BR only (Rules: no full top-20).

§Entry point

The public run function is the entry point called by main.rs.

§Safety

  • docs.rs / rustdoc: when built with --cfg docsrs, this crate enables #![feature(doc_cfg)] so #[doc(cfg(...))] labels render on feature-gated items (migration doc_auto_cfgdoc_cfg). Consumers of this crate do not need nightly; only the docs.rs build uses the feature gate.
  • unsafe: product code avoids unsafe on the happy path; remaining blocks (platform console / Unix permissions) are documented at the call site.

Modules§

cli
CLI argument definitions via clap derive and dispatcher.
commands
Per-subcommand command layer (rules clap CAMADA 2).
concurrency
Bounded multi-host / tunnel fan-out (Semaphore + JoinSet). Bounded concurrency for multi-host SSH fan-out (Rules Rust — paralelismo).
constants
Named domain constants (XDG file names, env keys, network/timing defaults). Named domain constants (Rules Rust — proibição de hardcode).
domain
Domain newtypes (parse, don’t validate — G-TYPE / G-DOM 4-crates). Domain newtypes — parse, don’t validate (G-TYPE / G-DOM).
error
Canonical error module name per clap layout rules (error.rs). Canonical error module path (error.rs) required by clap project layout rules.
errors
Structured error types (thiserror) and sysexits-style exit codes. Structured error types for ssh-cli.
fs_perm
Unix secret file/dir permission helpers (G-AUD-24). Unix secret file/dir modes — single source (G-AUD-24 / no hardcode drift).
i18n
ssh-cli internationalization system (Rules Rust multi-idioma).
json_wire
Typed JSON wire DTOs for agent-facing stdout/stderr contracts.
locale
Cross-platform language detection and resolution (Rules Rust i18n).
masking
Masking of sensitive values (passwords, tokens) — agent-safe.
net
TCP dial (async DNS + Happy Eyeballs multi-address connect). TCP dial helpers (Rules Rust — rede).
output
Only module allowed to emit stdout for VPS CRUD.
paths
File path validation and normalization.
platform
Operating-system conditional abstractions.
retry
Explicit retry policy + full-jitter backoff (agent re-invoke; opt-in in-process). Explicit retry policy for ssh-cli (Rules Rust — retry / backoff).
scp
File transfer via SCP over SSH (one-shot).
secrets
At-rest encryption of secrets in config.toml (GAP-009 / R-SECRETS-DEFAULT).
sftp
SFTP subsystem operations over SSH (upload/download/ls/mkdir/rm/stat/rename).
signals
Operating system signal handling for one-shot graceful shutdown.
ssh
SSH engine via russh 0.62.x.
telemetry
Process-local tracing subscriber (binary path only; libraries only emit). Process-local tracing setup for the ssh-cli binary path.
terminal
Colored output configuration and interactive terminal detection.
tls
rustls TLS stack (SSH-over-TLS, mTLS, ACME) — feature tls (default). Product TLS via rustls (aws_lc_rs only): SSH-over-TLS, mTLS, ACME.
tunnel
SSH tunnel (local port-forward) with mandatory deadline (bounded one-shot).
validation
Shared parse→validate pipeline for external config/import (G-SERDE-07). Shared validation pipeline for external input (G-SERDE-07).
vps
VPS record CRUD and persistence (XDG + atomic TOML + flock).

Functions§

resolve_exit_code
Maps a run / run_with_args result to a sysexits-aligned exit code.
run
Runs ssh-cli from the command-line arguments.
run_with_args
Executes phases 4–5 with pre-parsed arguments (G-IO-11 library entry).