diff --git a/pkgs/id/src/cli.rs b/pkgs/id/src/cli.rs index 4ac7404035..eb9e616e9f 100644 --- a/pkgs/id/src/cli.rs +++ b/pkgs/id/src/cli.rs @@ -305,6 +305,271 @@ fn parse_result_limit(raw: &str) -> Result { } } +/// The arguments of `id serve`, extracted from the `Command` +/// variant into their own `Args` struct (#4751): clap's derive inlines +/// a struct-style variant's argument construction into the parent +/// enum's `augment_subcommands`, and at this variant's size the +/// generated function's stack frame - summed with the Cli/Command +/// frames above it - overflows the default thread stack on every +/// parse in debug builds, aborting the lib test binary. As a tuple +/// variant over an `Args` struct, the construction lives in its own +/// functions (ServeArgs::augment_args / from_arg_matches) and the +/// parent enum's frame stays small. +#[derive(Args, Debug)] +pub struct ServeArgs { + /// Use in-memory storage instead of persistent disk storage. + /// + /// Content is lost when the server stops. Useful for testing + /// or temporary file sharing sessions. + #[arg(long)] + pub ephemeral: bool, + /// Path to the operator server config TOML (#5119 slice 1). + /// + /// When given, the config is loaded at startup: a malformed + /// file fails startup naming the parse error, and startup + /// provisioning runs from the loaded config. Without the + /// flag no file is read and serve behaves exactly as before. + #[arg(long)] + pub server_config: Option, + /// Disable relay servers and use direct connections only. + /// + /// May prevent connections through NATs or firewalls. + #[arg(long)] + pub no_relay: bool, + /// Disable gossip-based peer discovery entirely. + /// + /// The server still accepts connections but does not join + /// any gossip topic, does not announce itself, and does not + /// discover peers. Useful for isolated servers. + #[arg(long)] + pub no_gossip: bool, + /// Start web interface. + /// + /// Enables an HTTP server with a browser-based UI for + /// file browsing and collaborative editing. + /// Requires the `web` feature to be enabled at build time. + #[arg(long)] + pub web: bool, + /// Port for the web interface. + /// + /// Use port 0 to let the OS assign a random available port. + #[arg(long, default_value = "3000")] + pub port: u16, + /// Comma-separated node IDs for manual peer bootstrapping. + /// + /// Supplementary to automatic DHT discovery. Useful when DHT + /// traffic is blocked or for development/testing. + #[arg(long, value_delimiter = ',')] + pub bootstrap: Vec, + /// Gossip topic name for peer discovery. + /// + /// All servers on the same topic can discover each other. + /// Default: "id-peer-discovery-v1" (public network). + /// Use a custom topic for private networks. + #[arg(long)] + pub topic: Option, + /// Shared secret for topic access control. + /// + /// Used to encrypt DHT bootstrap records. Only nodes with + /// the same secret can discover each other via DHT. + /// Default: "id-public-discovery-v1" (public network). + #[arg(long)] + pub topic_secret: Option, + /// Skip default bootstrap node IDs from `defaults.conf`. + /// + /// Only CLI-provided `--bootstrap` nodes are used. + #[arg(long)] + pub no_default_bootstrap: bool, + /// Skip default topic and secret from `defaults.conf`. + /// + /// Falls back to the hardcoded constant values. CLI-provided + /// `--topic` and `--topic-secret` still take precedence. + #[arg(long)] + pub no_default_topic: bool, + /// Use only `defaults.conf` values, ignoring hardcoded fallbacks. + /// + /// Useful when you want to fully control defaults via the + /// embedded configuration file at build time. + #[arg(long)] + pub replace_defaults: bool, + /// Disable mDNS local peer discovery. + /// + /// By default, the server uses mDNS to discover peers on the + /// local network, and so announces its node ID and addresses to + /// every host there. This flag disables that, which is useful in + /// environments where multicast traffic is blocked or unwanted. + #[arg(long)] + pub no_mdns: bool, + /// Enable mainline DHT address lookup and publishing. + /// + /// By default, the server does not use the mainline BitTorrent DHT + /// for address discovery. This flag enables DHT lookup and publishing + /// for the server's endpoint. + #[arg(long)] + pub dht: bool, + /// Port for the Iroh QUIC endpoint (peer-to-peer protocol). + /// + /// By default, the OS assigns a random available port (0). + /// Set a specific port to allow firewall rules or when running + /// multiple servers that need predictable port assignments. + #[arg(long, default_value = "0")] + pub iroh_port: u16, + /// Address the web interface binds to. + /// + /// Defaults to loopback, so the UI is reachable only from this + /// machine. Use `0.0.0.0` to expose it on the network, and set + /// `--web-token` when you do. + #[arg(long, default_value = "127.0.0.1")] + pub bind: std::net::IpAddr, + /// Web listener to bind, as `IP:PORT` (repeatable; #2145). + /// + /// Each occurrence adds one listener; the set replaces any + /// `[web_bindings]` entries from `defaults.conf` entirely. + /// Combining `--web-listen` with an explicitly-set `--bind` or + /// `--port` is a startup error naming the conflict. IPv6 + /// addresses use the bracket form, e.g. `[::1]:3001`. + #[arg(long = "web-listen", value_name = "IP:PORT")] + pub web_listen: Vec, + /// Require this token to use the web interface. + /// + /// Open `http://host:port/?token=` once; the browser keeps a + /// cookie. Scripts may send `Authorization: Bearer `. + #[arg(long, env = "ID_WEB_TOKEN")] + pub web_token: Option, + /// Mark the web session cookies (`id_token` and the directory explorer's) `Secure`. + /// + /// Set this only when HTTPS is terminated in front of the server. + /// Browsers drop `Secure` cookies over plain HTTP, except on localhost. + #[arg(long, env = "ID_WEB_COOKIE_SECURE")] + pub web_cookie_secure: bool, + /// Host a multiplayer world over Iroh (and `/ws/world` with `--web`). + #[arg(long, requires = "world_admin_token")] + pub world: bool, + /// Admin secret required to mint world guest capabilities. + #[arg(long, env = "ID_WORLD_ADMIN_TOKEN")] + pub world_admin_token: Option, + /// Start with this precompiled Wasm world module (Roc platform ABI). + #[arg(long, requires = "world")] + pub world_module: Option, + /// Write confirmation mail into this directory, one private file per message. + #[arg( + long, + requires = "world", + conflicts_with_all = ["world_mail_command", "world_mail_smtp"] + )] + pub world_mail_outbox: Option, + /// Run this program for each confirmation mail, with `ID_MAIL_TO`, `ID_MAIL_SUBJECT` and `ID_MAIL_BODY` set. + #[arg( + long, + requires = "world", + conflicts_with_all = ["world_mail_outbox", "world_mail_smtp"] + )] + pub world_mail_command: Option, + /// Relay confirmation mail through this SMTP server, which must be on loopback and forward with TLS. + #[arg( + long, + requires_all = ["world", "world_mail_from"], + conflicts_with_all = ["world_mail_outbox", "world_mail_command"] + )] + pub world_mail_smtp: Option, + /// Sender address for mail sent with `--world-mail-smtp`. + #[arg(long, requires = "world_mail_smtp")] + pub world_mail_from: Option, + /// Name of the world this server offers (one world per process). + /// + /// The world's files live in `.id-worlds//`. Names may contain + /// `a-z`, `0-9`, `-` and `_`. + #[arg(long, default_value = "lobby", requires = "world")] + pub world_name: String, + /// Trim the world's journal behind a program snapshot every N events. + /// + /// A journal otherwise grows (and restarts slow down) without bound. + /// Programs that export `plaza_snapshot`/`plaza_restore` are trimmed; + /// others keep their full history. `0` never trims. + #[arg(long, default_value_t = 1000, requires = "world")] + pub world_checkpoint_every: u64, + /// Most worlds open at once; idle durable worlds close to make room. + #[arg(long, default_value_t = 256, requires = "world")] + pub world_max_open: usize, + /// Most world sessions at once, across every world. + #[arg(long, default_value_t = 1024, requires = "world")] + pub world_max_sessions: usize, + /// Close durable worlds that no session used for this many seconds + /// (they reopen from their journal on demand). `0` keeps them open. + #[arg(long, default_value_t = 600, requires = "world")] + pub world_idle_secs: u64, + /// Refuse signed world and directory requests for this many seconds + /// after startup, so a request captured before a restart cannot be + /// replayed into a server with empty replay memory. `0` disables. + #[arg(long, default_value_t = 600, requires = "world")] + pub world_boot_window_secs: u64, + /// Serve the world over SSH on this port, bound to `--bind`. + /// + /// Connect with `ssh -p @`; the password is the + /// guest capability from an invite. + #[arg(long, requires = "world")] + pub world_ssh_port: Option, + /// Accept native (ELF) module installs. Unlike Wasm, the guarantee + /// is the OS sandbox (Landlock, seccomp, rlimits), not an + /// import-free format, so this tier is opt-in. + #[arg(long, requires = "world")] + pub world_native: bool, + /// Accept new world programs only as Roc source compiled by this server. + /// Disables raw Wasm/native module uploads and `--world-module`. + #[arg( + long, + env = "ID_WORLD_SOURCE_ONLY", + requires = "world", + conflicts_with = "world_module" + )] + pub world_source_only: bool, + /// Ed25519 module-signing public key trusted by this server (hex; repeatable). + #[arg( + long = "world-module-trust-key", + value_name = "HEX", + requires = "world" + )] + pub world_module_trust_keys: Vec, + /// Execution bounds for world programs. + #[command(flatten)] + pub world_runtime: WorldRuntimeArgs, + /// Capability the default world's program may use (repeatable; `*` + /// grants the whole catalog). + #[arg(long = "world-cap", value_name = "NAME", requires = "world")] + pub world_caps: Vec, + /// What an unlisted capability costs the program: `deny` (default) or + /// `grant-on-use`, which grants a known capability the first time the + /// program uses it. + #[arg(long, default_value = "deny", requires = "world")] + pub world_cap_policy: String, + /// Capabilities the server allows any world to use, comma-separated + /// (default: the whole catalog). A world may grant less, never more. + /// `*` is refused here. + #[arg(long, value_name = "NAMES", value_delimiter = ',', requires = "world")] + pub world_allowed_caps: Option>, + /// The Roc binary used to compile sources sent to `id world compile` + /// (default: $`ID_ROC_BIN` or `roc` from PATH). + #[arg(long, env = "ID_ROC_BIN")] + pub roc_bin: Option, + /// The world platform directory used for on-the-fly compilation + /// (default: $`ID_ROC_PLATFORM` or ./examples/roc-world). + #[arg(long, env = "ID_ROC_PLATFORM")] + pub roc_platform: Option, + /// Allow this node to modify the store (repeatable, comma-separated). + /// + /// Reading names, hashes and tags is public. Writing (put, delete, + /// rename, copy, tag changes, blob pushes) requires the node's ID to be + /// listed here or in `.iroh-allowed` (one ID per line). This machine's + /// own server and client keys are always allowed. + #[arg(long = "allow-node", value_delimiter = ',')] + pub allow_node: Vec, + /// Let every peer modify the store (insecure). + /// + /// For demos and trusted networks only. + #[arg(long)] + pub open_writes: bool, +} + #[derive(Subcommand, Debug)] pub enum Command { /// Start a server that accepts put/get requests from peers. @@ -356,259 +621,7 @@ pub enum Command { /// # Use only defaults.conf values (ignore hardcoded fallbacks) /// id serve --replace-defaults /// ``` - Serve { - /// Use in-memory storage instead of persistent disk storage. - /// - /// Content is lost when the server stops. Useful for testing - /// or temporary file sharing sessions. - #[arg(long)] - ephemeral: bool, - /// Path to the operator server config TOML (#5119 slice 1). - /// - /// When given, the config is loaded at startup: a malformed - /// file fails startup naming the parse error, and startup - /// provisioning runs from the loaded config. Without the - /// flag no file is read and serve behaves exactly as before. - #[arg(long)] - server_config: Option, - /// Disable relay servers and use direct connections only. - /// - /// May prevent connections through NATs or firewalls. - #[arg(long)] - no_relay: bool, - /// Disable gossip-based peer discovery entirely. - /// - /// The server still accepts connections but does not join - /// any gossip topic, does not announce itself, and does not - /// discover peers. Useful for isolated servers. - #[arg(long)] - no_gossip: bool, - /// Start web interface. - /// - /// Enables an HTTP server with a browser-based UI for - /// file browsing and collaborative editing. - /// Requires the `web` feature to be enabled at build time. - #[arg(long)] - web: bool, - /// Port for the web interface. - /// - /// Use port 0 to let the OS assign a random available port. - #[arg(long, default_value = "3000")] - port: u16, - /// Comma-separated node IDs for manual peer bootstrapping. - /// - /// Supplementary to automatic DHT discovery. Useful when DHT - /// traffic is blocked or for development/testing. - #[arg(long, value_delimiter = ',')] - bootstrap: Vec, - /// Gossip topic name for peer discovery. - /// - /// All servers on the same topic can discover each other. - /// Default: "id-peer-discovery-v1" (public network). - /// Use a custom topic for private networks. - #[arg(long)] - topic: Option, - /// Shared secret for topic access control. - /// - /// Used to encrypt DHT bootstrap records. Only nodes with - /// the same secret can discover each other via DHT. - /// Default: "id-public-discovery-v1" (public network). - #[arg(long)] - topic_secret: Option, - /// Skip default bootstrap node IDs from `defaults.conf`. - /// - /// Only CLI-provided `--bootstrap` nodes are used. - #[arg(long)] - no_default_bootstrap: bool, - /// Skip default topic and secret from `defaults.conf`. - /// - /// Falls back to the hardcoded constant values. CLI-provided - /// `--topic` and `--topic-secret` still take precedence. - #[arg(long)] - no_default_topic: bool, - /// Use only `defaults.conf` values, ignoring hardcoded fallbacks. - /// - /// Useful when you want to fully control defaults via the - /// embedded configuration file at build time. - #[arg(long)] - replace_defaults: bool, - /// Disable mDNS local peer discovery. - /// - /// By default, the server uses mDNS to discover peers on the - /// local network, and so announces its node ID and addresses to - /// every host there. This flag disables that, which is useful in - /// environments where multicast traffic is blocked or unwanted. - #[arg(long)] - no_mdns: bool, - /// Enable mainline DHT address lookup and publishing. - /// - /// By default, the server does not use the mainline BitTorrent DHT - /// for address discovery. This flag enables DHT lookup and publishing - /// for the server's endpoint. - #[arg(long)] - dht: bool, - /// Port for the Iroh QUIC endpoint (peer-to-peer protocol). - /// - /// By default, the OS assigns a random available port (0). - /// Set a specific port to allow firewall rules or when running - /// multiple servers that need predictable port assignments. - #[arg(long, default_value = "0")] - iroh_port: u16, - /// Address the web interface binds to. - /// - /// Defaults to loopback, so the UI is reachable only from this - /// machine. Use `0.0.0.0` to expose it on the network, and set - /// `--web-token` when you do. - #[arg(long, default_value = "127.0.0.1")] - bind: std::net::IpAddr, - /// Web listener to bind, as `IP:PORT` (repeatable; #2145). - /// - /// Each occurrence adds one listener; the set replaces any - /// `[web_bindings]` entries from `defaults.conf` entirely. - /// Combining `--web-listen` with an explicitly-set `--bind` or - /// `--port` is a startup error naming the conflict. IPv6 - /// addresses use the bracket form, e.g. `[::1]:3001`. - #[arg(long = "web-listen", value_name = "IP:PORT")] - web_listen: Vec, - /// Require this token to use the web interface. - /// - /// Open `http://host:port/?token=` once; the browser keeps a - /// cookie. Scripts may send `Authorization: Bearer `. - #[arg(long, env = "ID_WEB_TOKEN")] - web_token: Option, - /// Mark the web session cookies (`id_token` and the directory explorer's) `Secure`. - /// - /// Set this only when HTTPS is terminated in front of the server. - /// Browsers drop `Secure` cookies over plain HTTP, except on localhost. - #[arg(long, env = "ID_WEB_COOKIE_SECURE")] - web_cookie_secure: bool, - /// Host a multiplayer world over Iroh (and `/ws/world` with `--web`). - #[arg(long, requires = "world_admin_token")] - world: bool, - /// Admin secret required to mint world guest capabilities. - #[arg(long, env = "ID_WORLD_ADMIN_TOKEN")] - world_admin_token: Option, - /// Start with this precompiled Wasm world module (Roc platform ABI). - #[arg(long, requires = "world")] - world_module: Option, - /// Write confirmation mail into this directory, one private file per message. - #[arg( - long, - requires = "world", - conflicts_with_all = ["world_mail_command", "world_mail_smtp"] - )] - world_mail_outbox: Option, - /// Run this program for each confirmation mail, with `ID_MAIL_TO`, `ID_MAIL_SUBJECT` and `ID_MAIL_BODY` set. - #[arg( - long, - requires = "world", - conflicts_with_all = ["world_mail_outbox", "world_mail_smtp"] - )] - world_mail_command: Option, - /// Relay confirmation mail through this SMTP server, which must be on loopback and forward with TLS. - #[arg( - long, - requires_all = ["world", "world_mail_from"], - conflicts_with_all = ["world_mail_outbox", "world_mail_command"] - )] - world_mail_smtp: Option, - /// Sender address for mail sent with `--world-mail-smtp`. - #[arg(long, requires = "world_mail_smtp")] - world_mail_from: Option, - /// Name of the world this server offers (one world per process). - /// - /// The world's files live in `.id-worlds//`. Names may contain - /// `a-z`, `0-9`, `-` and `_`. - #[arg(long, default_value = "lobby", requires = "world")] - world_name: String, - /// Trim the world's journal behind a program snapshot every N events. - /// - /// A journal otherwise grows (and restarts slow down) without bound. - /// Programs that export `plaza_snapshot`/`plaza_restore` are trimmed; - /// others keep their full history. `0` never trims. - #[arg(long, default_value_t = 1000, requires = "world")] - world_checkpoint_every: u64, - /// Most worlds open at once; idle durable worlds close to make room. - #[arg(long, default_value_t = 256, requires = "world")] - world_max_open: usize, - /// Most world sessions at once, across every world. - #[arg(long, default_value_t = 1024, requires = "world")] - world_max_sessions: usize, - /// Close durable worlds that no session used for this many seconds - /// (they reopen from their journal on demand). `0` keeps them open. - #[arg(long, default_value_t = 600, requires = "world")] - world_idle_secs: u64, - /// Refuse signed world and directory requests for this many seconds - /// after startup, so a request captured before a restart cannot be - /// replayed into a server with empty replay memory. `0` disables. - #[arg(long, default_value_t = 600, requires = "world")] - world_boot_window_secs: u64, - /// Serve the world over SSH on this port, bound to `--bind`. - /// - /// Connect with `ssh -p @`; the password is the - /// guest capability from an invite. - #[arg(long, requires = "world")] - world_ssh_port: Option, - /// Accept native (ELF) module installs. Unlike Wasm, the guarantee - /// is the OS sandbox (Landlock, seccomp, rlimits), not an - /// import-free format, so this tier is opt-in. - #[arg(long, requires = "world")] - world_native: bool, - /// Accept new world programs only as Roc source compiled by this server. - /// Disables raw Wasm/native module uploads and `--world-module`. - #[arg( - long, - env = "ID_WORLD_SOURCE_ONLY", - requires = "world", - conflicts_with = "world_module" - )] - world_source_only: bool, - /// Ed25519 module-signing public key trusted by this server (hex; repeatable). - #[arg( - long = "world-module-trust-key", - value_name = "HEX", - requires = "world" - )] - world_module_trust_keys: Vec, - /// Execution bounds for world programs. - #[command(flatten)] - world_runtime: WorldRuntimeArgs, - /// Capability the default world's program may use (repeatable; `*` - /// grants the whole catalog). - #[arg(long = "world-cap", value_name = "NAME", requires = "world")] - world_caps: Vec, - /// What an unlisted capability costs the program: `deny` (default) or - /// `grant-on-use`, which grants a known capability the first time the - /// program uses it. - #[arg(long, default_value = "deny", requires = "world")] - world_cap_policy: String, - /// Capabilities the server allows any world to use, comma-separated - /// (default: the whole catalog). A world may grant less, never more. - /// `*` is refused here. - #[arg(long, value_name = "NAMES", value_delimiter = ',', requires = "world")] - world_allowed_caps: Option>, - /// The Roc binary used to compile sources sent to `id world compile` - /// (default: $`ID_ROC_BIN` or `roc` from PATH). - #[arg(long, env = "ID_ROC_BIN")] - roc_bin: Option, - /// The world platform directory used for on-the-fly compilation - /// (default: $`ID_ROC_PLATFORM` or ./examples/roc-world). - #[arg(long, env = "ID_ROC_PLATFORM")] - roc_platform: Option, - /// Allow this node to modify the store (repeatable, comma-separated). - /// - /// Reading names, hashes and tags is public. Writing (put, delete, - /// rename, copy, tag changes, blob pushes) requires the node's ID to be - /// listed here or in `.iroh-allowed` (one ID per line). This machine's - /// own server and client keys are always allowed. - #[arg(long = "allow-node", value_delimiter = ',')] - allow_node: Vec, - /// Let every peer modify the store (insecure). - /// - /// For demos and trusted networks only. - #[arg(long)] - open_writes: bool, - }, + Serve(ServeArgs), /// Start an interactive REPL for issuing commands. /// /// The REPL provides a shell-like interface for executing multiple @@ -1670,303 +1683,752 @@ pub enum MatchAuditCommand { }, } +/// The arguments of `id world invite`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldInviteArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// Admin secret configured with `serve --world-admin-token`. + #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] + pub admin_token: String, + /// Display name for the new participant. + #[arg(long)] + pub name: String, + /// Role preset: spectator sees the world but not the chat, observer + /// also reads chat, player also inputs, guest also chats, delegator + /// may also mint narrower capabilities. Defaults to guest. + #[arg(long, value_parser = ["spectator", "observer", "player", "guest", "delegator", "builder", "moderator"])] + pub role: Option, + /// World on the host to use (default: the host's default world). + #[arg(long, env = "ID_WORLD")] + pub world: Option, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, + /// How long the invite works, such as `12h` or `3d`. + /// + /// Defaults to 7 days; the maximum is 30 days. + #[arg(long, value_name = "DURATION", value_parser = crate::helpers::parse_duration_secs)] + pub expires_in: Option, + /// How many committed actions the invite may take (at least 1). + /// + /// Unlimited when omitted. + #[arg(long, value_name = "N")] + pub uses: Option, +} + +/// The arguments of `id world install`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldInstallArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// Wasm module built for the `id` Roc world ABI. + pub module: PathBuf, + /// Admin secret configured with `serve --world-admin-token`. + #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] + pub admin_token: String, + /// Deterministic seed supplied to the guest initializer. + #[arg(long, default_value_t = 1)] + pub seed: u64, + /// World on the host to use (default: the host's default world). + #[arg(long, env = "ID_WORLD")] + pub world: Option, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + +/// The arguments of `id world records`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldRecordsArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// Guest capability from `id world invite`. + #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] + pub capability: String, + /// Only keys starting with this prefix. + #[arg(long)] + pub prefix: Option, + /// World on the host to use (default: the host's default world). + #[arg(long, env = "ID_WORLD")] + pub world: Option, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + +/// The arguments of `id world mirror`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldMirrorArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// Guest capability from `id world invite`. + #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] + pub capability: String, + /// Keep printing whenever the records change. + #[arg(short, long)] + pub follow: bool, + /// Store the replica on disk so it survives between runs. + #[arg(long, value_name = "PATH")] + pub dir: Option, + /// Give up after this many seconds without a completed sync (maximum 24 hours). + #[arg( + long, + default_value_t = 30, + value_parser = clap::value_parser!(u64).range(0..=86_400) + )] + pub timeout_secs: u64, + /// World on the host to use (default: the host's default world). + #[arg(long, env = "ID_WORLD")] + pub world: Option, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + +/// The arguments of `id world download`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldDownloadArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// Guest capability from `id world invite`. + #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] + pub capability: String, + /// Where to write the verified module bytes. + #[arg(long)] + pub output: PathBuf, + /// World on the host to use (default: the host's default world). + #[arg(long, env = "ID_WORLD")] + pub world: Option, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + +/// The arguments of `id world join`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldJoinArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// Guest capability from `id world invite`. + #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] + pub capability: String, + /// Replay events after this sequence instead of a full snapshot. + #[arg(long)] + pub after: Option, + /// Parse stdin as commands (`/chat`, `/records`, `/stats`, `/caps`, + /// `/quit`, ...) instead of sending every line as chat. + #[arg(long)] + pub command_mode: bool, + /// Emit local command responses as JSONL records on stdout. + #[arg(long, requires = "command_mode")] + pub json: bool, + /// How to reach the host: `iroh` (NODE is a node ID) or `ssh` (NODE + /// is `[user@]host[:port]` of the host's world SSH server, and the + /// frames travel over an SSH exec channel, for networks and jump + /// hosts that only pass SSH). + #[arg(long, value_enum, default_value_t = WorldVia::Iroh)] + pub via: WorldVia, + /// With `--via ssh`: the host key fingerprint `id serve` prints + /// (`SHA256:...`). Without it, the key must be in ~/.ssh/known_hosts. + #[arg(long, value_name = "FINGERPRINT")] + pub ssh_host_key: Option, + /// World on the host to use (default: the host's default world). + #[arg(long, env = "ID_WORLD")] + pub world: Option, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + +/// The arguments of `id world sshtunnel`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldSshTunnelArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// Local address to listen on (loopback only is recommended). + #[arg(long, value_name = "ADDR")] + pub listen: Option, + /// Speak SSH on stdin/stdout (for `ssh -o ProxyCommand`). + #[arg(long, conflicts_with = "listen")] + pub stdio: bool, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + +/// The arguments of `id world compile`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldCompileArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// The app's main.roc. + pub main_file: PathBuf, + /// Additional source files (repeatable; paths become file names). + #[arg(short = 'f', long = "file")] + pub files: Vec, + /// Seed for the compiled program's initializer (default: random). + #[arg(long)] + pub seed: Option, + /// Admin secret configured with `serve --world-admin-token`. + #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] + pub admin_token: String, + /// Build a native worker (x64musl) instead of Wasm; the host must run + /// with `--world-native` and a platform with native targets. + #[arg(long)] + pub native: bool, + /// World on the host to use (default: the host's default world). + #[arg(long, env = "ID_WORLD")] + pub world: Option, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + +/// The arguments of `id world caps`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldCapsArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// Guest capability from `id world invite`. + #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] + pub capability: Option, + /// Admin secret configured with `serve --world-admin-token`. + #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] + pub admin_token: Option, + /// Capability to grant (repeatable; `*` grants the whole catalog). + #[arg(long)] + pub grant: Vec, + /// Capability to revoke (repeatable). + #[arg(long)] + pub revoke: Vec, + /// Capability ceiling to set (comma-separated or repeatable; only known capabilities, no `*`). + #[arg(long, value_delimiter = ',')] + pub ceiling: Option>, + /// World on the host to use (default: the host's default world). + #[arg(long, env = "ID_WORLD")] + pub world: Option, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + +/// The arguments of `id world profile`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldProfileArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// Admin secret configured with `serve --world-admin-token`. + #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] + pub admin_token: Option, + /// Guest capability from `id world invite` (sufficient to inspect the profile). + #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] + pub capability: Option, + /// Requested Wasm fuel limit per transaction/event. + #[arg(long, visible_alias = "fuel")] + pub wasm_fuel: Option, + /// Requested Wasm linear memory in bytes. + #[arg(long, visible_alias = "wasm-memory")] + pub wasm_memory_bytes: Option, + /// Requested Wasm message payload limit in bytes. + #[arg(long, visible_alias = "wasm-message")] + pub wasm_message_bytes: Option, + /// Requested native address-space cap in bytes. + #[arg(long, visible_alias = "native-memory")] + pub native_memory_bytes: Option, + /// Requested native CPU cap in seconds. + #[arg(long, visible_alias = "native-cpu")] + pub native_cpu_seconds: Option, + /// Requested native call deadline in milliseconds. + #[arg(long, visible_alias = "native-deadline")] + pub native_call_deadline_ms: Option, + /// World on the host to use (default: the host's default world). + #[arg(long, env = "ID_WORLD")] + pub world: Option, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + +/// The arguments of `id world doctor`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldDoctorArgs { + /// Roc compiler binary to check (default: $`ID_ROC_BIN`, then the + /// pinned nightly, then `roc` on PATH). + #[arg(long, env = "ID_ROC_BIN")] + pub roc_bin: Option, + /// World platform directory to check (default: $`ID_ROC_PLATFORM` or + /// ./examples/roc-world). + #[arg(long, env = "ID_ROC_PLATFORM")] + pub platform: Option, + /// World journal (`journal.jsonl`) to check for format errors. + #[arg(long, value_name = "FILE")] + pub journal: Option, + /// Capability ceiling to check (comma-separated or repeatable; only + /// known capabilities, no `*`). + #[arg(long, value_delimiter = ',')] + pub ceiling: Option>, + /// Execution profile to check, as a JSON file whose fields are the + /// `WorldExecutionProfile` bounds (e.g. `{"wasm_fuel": 0}`). + #[arg(long, value_name = "FILE")] + pub profile: Option, + /// Print one JSON object instead of text. + #[arg(long)] + pub json: bool, +} + +/// The arguments of `id world diff`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldDiffArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// Path to the `world.toml` to compare against. + #[arg(long, value_name = "FILE")] + pub file: PathBuf, + /// Guest capability from `id world invite` (enough to read the world). + #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] + pub capability: String, + /// World on the host to use (default: the host's default world). + #[arg(long, env = "ID_WORLD")] + pub world: Option, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + +/// The arguments of `id world apply`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldApplyArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// Path to the `world.toml` to apply. + #[arg(long, value_name = "FILE")] + pub file: PathBuf, + /// Admin secret configured with `serve --world-admin-token`. + #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] + pub admin_token: String, + /// Guest capability from `id world invite`, used to read the current + /// state. Required for applying (it reads before it writes). + #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] + pub capability: String, + /// Print the plan without changing the world. + #[arg(long)] + pub dry_run: bool, + /// World on the host to use (default: the host's default world). + #[arg(long, env = "ID_WORLD")] + pub world: Option, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + +/// The arguments of `id world measure`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldMeasureArgs { + /// Wasm module built for the `id` Roc world ABI. + #[arg(long)] + pub module: PathBuf, + /// Deterministic seed supplied to the guest initializer. + #[arg(long, default_value_t = 1)] + pub seed: u64, + /// Event to apply as participant 1, hex-encoded (repeatable, in order). + #[arg(long = "input", value_name = "HEX")] + pub inputs: Vec, + /// Viewport width for the `layout` call (needs `--height`). + #[arg(long, requires = "height")] + pub width: Option, + /// Viewport height for the `layout` call (needs `--width`). + #[arg(long, requires = "width")] + pub height: Option, +} + +/// The arguments of `id world logs`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldLogsArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// Guest capability from `id world invite`. + #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] + pub capability: String, + /// Stop after this many seconds (maximum 24 hours). + #[arg( + long, + default_value_t = 5, + value_parser = clap::value_parser!(u64).range(0..=86_400) + )] + pub seconds: u64, + /// World on the host to use (default: the host's default world). + #[arg(long, env = "ID_WORLD")] + pub world: Option, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + +/// The arguments of `id world stats`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldStatsArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// Guest capability from `id world invite`. + #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] + pub capability: String, + /// World on the host to use (default: the host's default world). + #[arg(long, env = "ID_WORLD")] + pub world: Option, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + +/// The arguments of `id world record`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldRecordArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// Host admin token. + #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] + pub admin_token: String, + /// Write the fixture here instead of standard output. + #[arg(long, value_name = "FILE")] + pub out: Option, + /// World on the host to use (default: the host's default world). + #[arg(long, env = "ID_WORLD")] + pub world: Option, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + +/// The arguments of `id world replay`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldReplayArgs { + /// The Wasm module the fixture was recorded under. + #[arg(long, value_name = "FILE")] + pub module: PathBuf, + /// Fixture written by `id world record`. + #[arg(long, value_name = "FILE")] + pub fixture: PathBuf, + /// Seed the module was installed with. The admin supplied it at install + /// time; the fixture does not carry it. + #[arg(long)] + pub seed: u64, + /// Replay a window that does not start at sequence 1. Its records are + /// not compared. + #[arg(long)] + pub allow_partial: bool, +} + +/// The arguments of `id world verify`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldVerifyArgs { + /// The Wasm module the fixture was recorded under. + #[arg(long, value_name = "FILE")] + pub module: PathBuf, + /// Fixture written by `id world record`. + #[arg(long, value_name = "FILE")] + pub fixture: PathBuf, + /// Seed the module was installed with. The admin supplied it at install + /// time; the fixture does not carry it. + #[arg(long)] + pub seed: u64, + /// Replay a window that does not start at sequence 1. Its records are + /// not compared against the fixture's header, but the two replays are + /// still compared against each other. + #[arg(long)] + pub allow_partial: bool, +} + +/// The arguments of `id world list`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldListArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// Admin secret configured with `serve --world-admin-token`. + /// Optional: omit it to read the public directory. + #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] + pub admin_token: Option, + /// Print one JSON object instead of tab-separated lines. + #[arg(long)] + pub json: bool, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + +/// The arguments of `id world isolation`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldIsolationArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// `isolated` (no cross-world reads) or `unisolated` (readable from + /// other unisolated worlds). + #[arg(value_parser = ["isolated", "unisolated"])] + pub mode: String, + /// Admin secret configured with `serve --world-admin-token`. + #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] + pub admin_token: String, + /// World on the host to change (default: the host's default world). + #[arg(long, env = "ID_WORLD")] + pub world: Option, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + +/// The arguments of `id world crossworldwrite`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldCrossWorldWriteArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// `on` (other unisolated worlds may write here) or `off`. + #[arg(value_parser = ["on", "off"])] + pub mode: String, + /// Admin secret configured with `serve --world-admin-token`. + #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] + pub admin_token: String, + /// World on the host to change (default: the host's default world). + #[arg(long, env = "ID_WORLD")] + pub world: Option, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + +/// The arguments of `id world forcecrossworldwrite`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldForceCrossWorldWriteArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// Admin secret configured with `serve --world-admin-token`. + #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] + pub admin_token: String, + /// World on the host to change (default: the host's default world). + #[arg(long, env = "ID_WORLD")] + pub world: Option, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + +/// The arguments of `id world filescope`, extracted into +/// their own `Args` struct for the same reason as `ServeArgs` +/// (#4751): keeping clap's derive-generated construction in its +/// own function bounds the stack frame of the parent enum's +/// `augment_subcommands`. +#[derive(Args, Debug)] +pub struct WorldFileScopeArgs { + /// The host's node ID (64 hex characters). + pub node: String, + /// `confined` (the world's own sandbox root) or `unrestricted` (any path). + #[arg(value_parser = ["confined", "unrestricted"])] + pub scope: String, + /// Admin file write override for an isolated world: `on` or `off`. + #[arg(long = "write-override", value_parser = ["on", "off"])] + pub write_override: Option, + /// Admin secret configured with `serve --world-admin-token`. + #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] + pub admin_token: String, + /// World on the host to change (default: the host's default world). + #[arg(long, env = "ID_WORLD")] + pub world: Option, + /// Direct socket address of the host (repeatable); skips discovery. + #[arg(long = "addr")] + pub addrs: Vec, + /// Disable relay servers (direct connection only). + #[arg(long)] + pub no_relay: bool, +} + /// Subcommands for `id world`. #[derive(Subcommand, Debug)] pub enum WorldCommand { /// Mint a guest capability on a world host (needs the host's admin token). - Invite { - /// The host's node ID (64 hex characters). - node: String, - /// Admin secret configured with `serve --world-admin-token`. - #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] - admin_token: String, - /// Display name for the new participant. - #[arg(long)] - name: String, - /// Role preset: spectator sees the world but not the chat, observer - /// also reads chat, player also inputs, guest also chats, delegator - /// may also mint narrower capabilities. Defaults to guest. - #[arg(long, value_parser = ["spectator", "observer", "player", "guest", "delegator", "builder", "moderator"])] - role: Option, - /// World on the host to use (default: the host's default world). - #[arg(long, env = "ID_WORLD")] - world: Option, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - /// How long the invite works, such as `12h` or `3d`. - /// - /// Defaults to 7 days; the maximum is 30 days. - #[arg(long, value_name = "DURATION", value_parser = crate::helpers::parse_duration_secs)] - expires_in: Option, - /// How many committed actions the invite may take (at least 1). - /// - /// Unlimited when omitted. - #[arg(long, value_name = "N")] - uses: Option, - }, + Invite(WorldInviteArgs), /// Upload and activate a compiled `.wasm` world program on a host. - Install { - /// The host's node ID (64 hex characters). - node: String, - /// Wasm module built for the `id` Roc world ABI. - module: PathBuf, - /// Admin secret configured with `serve --world-admin-token`. - #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] - admin_token: String, - /// Deterministic seed supplied to the guest initializer. - #[arg(long, default_value_t = 1)] - seed: u64, - /// World on the host to use (default: the host's default world). - #[arg(long, env = "ID_WORLD")] - world: Option, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + Install(WorldInstallArgs), /// Print the world's structured records (a JSON object). - Records { - /// The host's node ID (64 hex characters). - node: String, - /// Guest capability from `id world invite`. - #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] - capability: String, - /// Only keys starting with this prefix. - #[arg(long)] - prefix: Option, - /// World on the host to use (default: the host's default world). - #[arg(long, env = "ID_WORLD")] - world: Option, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + Records(WorldRecordsArgs), /// Replicate the world's records over Iroh with an iroh-docs replica. - Mirror { - /// The host's node ID (64 hex characters). - node: String, - /// Guest capability from `id world invite`. - #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] - capability: String, - /// Keep printing whenever the records change. - #[arg(short, long)] - follow: bool, - /// Store the replica on disk so it survives between runs. - #[arg(long, value_name = "PATH")] - dir: Option, - /// Give up after this many seconds without a completed sync (maximum 24 hours). - #[arg( - long, - default_value_t = 30, - value_parser = clap::value_parser!(u64).range(0..=86_400) - )] - timeout_secs: u64, - /// World on the host to use (default: the host's default world). - #[arg(long, env = "ID_WORLD")] - world: Option, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + Mirror(WorldMirrorArgs), /// Download the module backing the world's current state, verified /// by hash. Prints the module hash; writes the bytes to `--output`. - Download { - /// The host's node ID (64 hex characters). - node: String, - /// Guest capability from `id world invite`. - #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] - capability: String, - /// Where to write the verified module bytes. - #[arg(long)] - output: PathBuf, - /// World on the host to use (default: the host's default world). - #[arg(long, env = "ID_WORLD")] - world: Option, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + Download(WorldDownloadArgs), /// Join a world and chat. Stdin lines are chat; `/input ` sends /// opaque input. Server frames print as JSON lines. - Join { - /// The host's node ID (64 hex characters). - node: String, - /// Guest capability from `id world invite`. - #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] - capability: String, - /// Replay events after this sequence instead of a full snapshot. - #[arg(long)] - after: Option, - /// Parse stdin as commands (`/chat`, `/records`, `/stats`, `/caps`, - /// `/quit`, ...) instead of sending every line as chat. - #[arg(long)] - command_mode: bool, - /// Emit local command responses as JSONL records on stdout. - #[arg(long, requires = "command_mode")] - json: bool, - /// How to reach the host: `iroh` (NODE is a node ID) or `ssh` (NODE - /// is `[user@]host[:port]` of the host's world SSH server, and the - /// frames travel over an SSH exec channel, for networks and jump - /// hosts that only pass SSH). - #[arg(long, value_enum, default_value_t = WorldVia::Iroh)] - via: WorldVia, - /// With `--via ssh`: the host key fingerprint `id serve` prints - /// (`SHA256:...`). Without it, the key must be in ~/.ssh/known_hosts. - #[arg(long, value_name = "FINGERPRINT")] - ssh_host_key: Option, - /// World on the host to use (default: the host's default world). - #[arg(long, env = "ID_WORLD")] - world: Option, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + Join(WorldJoinArgs), /// Reach a host's world SSH server through iroh, so an ordinary `ssh` - /// client can reach a world behind NAT: `ssh -p 2222 @127.0.0.1` - /// (password: the guest capability). With `--stdio`, acts as an SSH - /// ProxyCommand instead of listening. - SshTunnel { - /// The host's node ID (64 hex characters). - node: String, - /// Local address to listen on (loopback only is recommended). - #[arg(long, value_name = "ADDR")] - listen: Option, - /// Speak SSH on stdin/stdout (for `ssh -o ProxyCommand`). - #[arg(long, conflicts_with = "listen")] - stdio: bool, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + /// client can reach a world behind NAT: `ssh -p 2222 @127.0.0.1` + /// (password: the guest capability). With `--stdio`, acts as an SSH + /// ProxyCommand instead of listening. + SshTunnel(WorldSshTunnelArgs), /// Compile Roc sources on the host and install the result. /// /// The host rewrites the app's `pf: platform "..."` path to its staged /// copy of the world platform, so any relative path works. - Compile { - /// The host's node ID (64 hex characters). - node: String, - /// The app's main.roc. - main_file: PathBuf, - /// Additional source files (repeatable; paths become file names). - #[arg(short = 'f', long = "file")] - files: Vec, - /// Seed for the compiled program's initializer (default: random). - #[arg(long)] - seed: Option, - /// Admin secret configured with `serve --world-admin-token`. - #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] - admin_token: String, - /// Build a native worker (x64musl) instead of Wasm; the host must run - /// with `--world-native` and a platform with native targets. - #[arg(long)] - native: bool, - /// World on the host to use (default: the host's default world). - #[arg(long, env = "ID_WORLD")] - world: Option, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + Compile(WorldCompileArgs), /// Show (and, with `--grant`/`--revoke`/`--ceiling`, change) a world's capabilities. /// /// Without `--grant`/`--revoke`/`--ceiling` this needs only a guest capability and /// prints what the world has granted, what its program wants, and what it /// has used. With them it needs the admin token. - Caps { - /// The host's node ID (64 hex characters). - node: String, - /// Guest capability from `id world invite`. - #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] - capability: Option, - /// Admin secret configured with `serve --world-admin-token`. - #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] - admin_token: Option, - /// Capability to grant (repeatable; `*` grants the whole catalog). - #[arg(long)] - grant: Vec, - /// Capability to revoke (repeatable). - #[arg(long)] - revoke: Vec, - /// Capability ceiling to set (comma-separated or repeatable; only known capabilities, no `*`). - #[arg(long, value_delimiter = ',')] - ceiling: Option>, - /// World on the host to use (default: the host's default world). - #[arg(long, env = "ID_WORLD")] - world: Option, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + Caps(WorldCapsArgs), /// View or configure a world's requested execution profile bounds. /// /// When any limit option (`--fuel`, `--wasm-memory`, etc.) is specified, /// `--admin-token` is required to persist the new profile. When no limits /// are specified, prints the current persisted profile (requires either /// `--admin-token` or a guest `--capability`). - Profile { - /// The host's node ID (64 hex characters). - node: String, - /// Admin secret configured with `serve --world-admin-token`. - #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] - admin_token: Option, - /// Guest capability from `id world invite` (sufficient to inspect the profile). - #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] - capability: Option, - /// Requested Wasm fuel limit per transaction/event. - #[arg(long, visible_alias = "fuel")] - wasm_fuel: Option, - /// Requested Wasm linear memory in bytes. - #[arg(long, visible_alias = "wasm-memory")] - wasm_memory_bytes: Option, - /// Requested Wasm message payload limit in bytes. - #[arg(long, visible_alias = "wasm-message")] - wasm_message_bytes: Option, - /// Requested native address-space cap in bytes. - #[arg(long, visible_alias = "native-memory")] - native_memory_bytes: Option, - /// Requested native CPU cap in seconds. - #[arg(long, visible_alias = "native-cpu")] - native_cpu_seconds: Option, - /// Requested native call deadline in milliseconds. - #[arg(long, visible_alias = "native-deadline")] - native_call_deadline_ms: Option, - /// World on the host to use (default: the host's default world). - #[arg(long, env = "ID_WORLD")] - world: Option, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + Profile(WorldProfileArgs), /// Scaffold a new Roc world app directory. /// /// Writes `main.roc`, `build.sh`, and `README.md`. The platform path in the @@ -1987,81 +2449,15 @@ pub enum WorldCommand { /// ceiling and profile checks run against the values given with /// `--ceiling` / `--profile`; without them they report that none is /// configured. `--json` prints one machine-readable report. - Doctor { - /// Roc compiler binary to check (default: $`ID_ROC_BIN`, then the - /// pinned nightly, then `roc` on PATH). - #[arg(long, env = "ID_ROC_BIN")] - roc_bin: Option, - /// World platform directory to check (default: $`ID_ROC_PLATFORM` or - /// ./examples/roc-world). - #[arg(long, env = "ID_ROC_PLATFORM")] - platform: Option, - /// World journal (`journal.jsonl`) to check for format errors. - #[arg(long, value_name = "FILE")] - journal: Option, - /// Capability ceiling to check (comma-separated or repeatable; only - /// known capabilities, no `*`). - #[arg(long, value_delimiter = ',')] - ceiling: Option>, - /// Execution profile to check, as a JSON file whose fields are the - /// `WorldExecutionProfile` bounds (e.g. `{"wasm_fuel": 0}`). - #[arg(long, value_name = "FILE")] - profile: Option, - /// Print one JSON object instead of text. - #[arg(long)] - json: bool, - }, + Doctor(WorldDoctorArgs), /// Show the drift between a `world.toml` and a live world (read-only). - Diff { - /// The host's node ID (64 hex characters). - node: String, - /// Path to the `world.toml` to compare against. - #[arg(long, value_name = "FILE")] - file: PathBuf, - /// Guest capability from `id world invite` (enough to read the world). - #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] - capability: String, - /// World on the host to use (default: the host's default world). - #[arg(long, env = "ID_WORLD")] - world: Option, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + Diff(WorldDiffArgs), /// Reconcile a live world to a `world.toml` (idempotent; journaled). /// /// Prints the plan and applies it. `--dry-run` prints the plan only. /// Every step — module install, grants, ceiling, profile, schedules — /// is applied through the admin operations and journaled by the host. - Apply { - /// The host's node ID (64 hex characters). - node: String, - /// Path to the `world.toml` to apply. - #[arg(long, value_name = "FILE")] - file: PathBuf, - /// Admin secret configured with `serve --world-admin-token`. - #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] - admin_token: String, - /// Guest capability from `id world invite`, used to read the current - /// state. Required for applying (it reads before it writes). - #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] - capability: String, - /// Print the plan without changing the world. - #[arg(long)] - dry_run: bool, - /// World on the host to use (default: the host's default world). - #[arg(long, env = "ID_WORLD")] - world: Option, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + Apply(WorldApplyArgs), /// Print the versioned shell contract (the frame protocol every shell /// speaks), or check a recorded session against it. /// @@ -2082,104 +2478,18 @@ pub enum WorldCommand { /// worst fuel, and the worst call as a percent of the fuel limit. Exits /// nonzero only if the module fails to compile or a call traps. #[cfg(feature = "sandbox")] - Measure { - /// Wasm module built for the `id` Roc world ABI. - #[arg(long)] - module: PathBuf, - /// Deterministic seed supplied to the guest initializer. - #[arg(long, default_value_t = 1)] - seed: u64, - /// Event to apply as participant 1, hex-encoded (repeatable, in order). - #[arg(long = "input", value_name = "HEX")] - inputs: Vec, - /// Viewport width for the `layout` call (needs `--height`). - #[arg(long, requires = "height")] - width: Option, - /// Viewport height for the `layout` call (needs `--width`). - #[arg(long, requires = "width")] - height: Option, - }, + Measure(WorldMeasureArgs), /// Tail a world's recent events (bounded by retention and a deadline). - Logs { - /// The host's node ID (64 hex characters). - node: String, - /// Guest capability from `id world invite`. - #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] - capability: String, - /// Stop after this many seconds (maximum 24 hours). - #[arg( - long, - default_value_t = 5, - value_parser = clap::value_parser!(u64).range(0..=86_400) - )] - seconds: u64, - /// World on the host to use (default: the host's default world). - #[arg(long, env = "ID_WORLD")] - world: Option, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + Logs(WorldLogsArgs), /// Print a world's module, capability, and profile state as one JSON object. - Stats { - /// The host's node ID (64 hex characters). - node: String, - /// Guest capability from `id world invite`. - #[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)] - capability: String, - /// World on the host to use (default: the host's default world). - #[arg(long, env = "ID_WORLD")] - world: Option, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + Stats(WorldStatsArgs), /// Write a world's retained journal history and records to a replayable /// fixture (JSON Lines). Host events require the host's admin token. - Record { - /// The host's node ID (64 hex characters). - node: String, - /// Host admin token. - #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] - admin_token: String, - /// Write the fixture here instead of standard output. - #[arg(long, value_name = "FILE")] - out: Option, - /// World on the host to use (default: the host's default world). - #[arg(long, env = "ID_WORLD")] - world: Option, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + Record(WorldRecordArgs), /// Replay a recorded fixture offline through a module and compare records. /// Prints a verdict line first; exits nonzero when the records differ. #[cfg(feature = "sandbox")] - Replay { - /// The Wasm module the fixture was recorded under. - #[arg(long, value_name = "FILE")] - module: PathBuf, - /// Fixture written by `id world record`. - #[arg(long, value_name = "FILE")] - fixture: PathBuf, - /// Seed the module was installed with. The admin supplied it at install - /// time; the fixture does not carry it. - #[arg(long)] - seed: u64, - /// Replay a window that does not start at sequence 1. Its records are - /// not compared. - #[arg(long)] - allow_partial: bool, - }, + Replay(WorldReplayArgs), /// Verify a recorded fixture's determinism: replay it twice offline /// through a module and compare the records after every event. Prints a /// verdict line first; exits nonzero at the first divergence, or when @@ -2191,127 +2501,22 @@ pub enum WorldCommand { /// including host-originated events in their recorded order. It proves /// determinism for that history, not correctness of host policy. #[cfg(feature = "sandbox")] - Verify { - /// The Wasm module the fixture was recorded under. - #[arg(long, value_name = "FILE")] - module: PathBuf, - /// Fixture written by `id world record`. - #[arg(long, value_name = "FILE")] - fixture: PathBuf, - /// Seed the module was installed with. The admin supplied it at install - /// time; the fixture does not carry it. - #[arg(long)] - seed: u64, - /// Replay a window that does not start at sequence 1. Its records are - /// not compared against the fixture's header, but the two replays are - /// still compared against each other. - #[arg(long)] - allow_partial: bool, - }, + Verify(WorldVerifyArgs), /// List the worlds a host serves. Without `--admin-token` this reads /// the host's public directory (#812: names, loaded state, presence /// counts); with it, the admin listing is used. - List { - /// The host's node ID (64 hex characters). - node: String, - /// Admin secret configured with `serve --world-admin-token`. - /// Optional: omit it to read the public directory. - #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] - admin_token: Option, - /// Print one JSON object instead of tab-separated lines. - #[arg(long)] - json: bool, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + List(WorldListArgs), /// Set whether a world's directory may be read from other unisolated /// worlds (needs the host's admin token). Worlds are isolated by default; /// writes never cross worlds. - Isolation { - /// The host's node ID (64 hex characters). - node: String, - /// `isolated` (no cross-world reads) or `unisolated` (readable from - /// other unisolated worlds). - #[arg(value_parser = ["isolated", "unisolated"])] - mode: String, - /// Admin secret configured with `serve --world-admin-token`. - #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] - admin_token: String, - /// World on the host to change (default: the host's default world). - #[arg(long, env = "ID_WORLD")] - world: Option, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + Isolation(WorldIsolationArgs), /// Let other unisolated worlds write into a world (needs the host's admin token). - CrossWorldWrite { - /// The host's node ID (64 hex characters). - node: String, - /// `on` (other unisolated worlds may write here) or `off`. - #[arg(value_parser = ["on", "off"])] - mode: String, - /// Admin secret configured with `serve --world-admin-token`. - #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] - admin_token: String, - /// World on the host to change (default: the host's default world). - #[arg(long, env = "ID_WORLD")] - world: Option, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + CrossWorldWrite(WorldCrossWorldWriteArgs), /// Force cross-world writes on for an unisolated world, overriding its own /// setting (needs the host's admin token). Moderators cannot undo a force. - ForceCrossWorldWrite { - /// The host's node ID (64 hex characters). - node: String, - /// Admin secret configured with `serve --world-admin-token`. - #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] - admin_token: String, - /// World on the host to change (default: the host's default world). - #[arg(long, env = "ID_WORLD")] - world: Option, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + ForceCrossWorldWrite(WorldForceCrossWorldWriteArgs), /// Set a world's file scope (needs the host's admin token). - FileScope { - /// The host's node ID (64 hex characters). - node: String, - /// `confined` (the world's own sandbox root) or `unrestricted` (any path). - #[arg(value_parser = ["confined", "unrestricted"])] - scope: String, - /// Admin file write override for an isolated world: `on` or `off`. - #[arg(long = "write-override", value_parser = ["on", "off"])] - write_override: Option, - /// Admin secret configured with `serve --world-admin-token`. - #[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)] - admin_token: String, - /// World on the host to change (default: the host's default world). - #[arg(long, env = "ID_WORLD")] - world: Option, - /// Direct socket address of the host (repeatable); skips discovery. - #[arg(long = "addr")] - addrs: Vec, - /// Disable relay servers (direct connection only). - #[arg(long)] - no_relay: bool, - }, + FileScope(WorldFileScopeArgs), /// Create a world on a host (needs the host's admin token). Create { /// The host's node ID (64 hex characters). @@ -2637,7 +2842,7 @@ mod tests { // name, not create an instance literally named "serve". let cli = parse_normalized(&["id", "--new", "serve"]); assert_eq!(cli.new.as_deref(), Some("")); - assert!(matches!(cli.command, Some(Command::Serve { .. }))); + assert!(matches!(cli.command, Some(Command::Serve(..)))); let cli = parse_normalized(&["id", "--new", "id"]); assert_eq!(cli.new.as_deref(), Some("")); @@ -2726,7 +2931,7 @@ mod tests { fn test_cli_parse_debug_with_subcommand() { let cli = Cli::parse_from(["id", "--debug", "serve"]); assert!(cli.debug); - assert!(matches!(cli.command, Some(Command::Serve { .. }))); + assert!(matches!(cli.command, Some(Command::Serve(..)))); } #[test] @@ -2741,48 +2946,49 @@ mod tests { // Global flags should work after subcommand too let cli = Cli::parse_from(["id", "serve", "--debug"]); assert!(cli.debug); - assert!(matches!(cli.command, Some(Command::Serve { .. }))); + assert!(matches!(cli.command, Some(Command::Serve(..)))); } #[test] fn test_cli_parse_serve() { let cli = Cli::parse_from(["id", "serve"]); match cli.command { - Some(Command::Serve { - ephemeral, - no_relay, - no_gossip, - web, - port, - bootstrap, - topic, - topic_secret, - no_default_bootstrap, - no_default_topic, - replace_defaults, - no_mdns, - iroh_port, - bind, - web_token, - world, - world_admin_token, - world_module, - world_name, - world_ssh_port, - world_checkpoint_every, - world_max_open, - world_max_sessions, - world_idle_secs, - world_boot_window_secs, - world_caps, - world_cap_policy, - roc_bin, - roc_platform, - world_native, - allow_node, - open_writes, - .. - }) => { + Some(Command::Serve(args)) => { + let ServeArgs { + ephemeral, + no_relay, + no_gossip, + web, + port, + bootstrap, + topic, + topic_secret, + no_default_bootstrap, + no_default_topic, + replace_defaults, + no_mdns, + iroh_port, + bind, + web_token, + world, + world_admin_token, + world_module, + world_name, + world_ssh_port, + world_checkpoint_every, + world_max_open, + world_max_sessions, + world_idle_secs, + world_boot_window_secs, + world_caps, + world_cap_policy, + roc_bin, + roc_platform, + world_native, + allow_node, + open_writes, + .. + } = args; assert!(!ephemeral); assert!(!no_relay); assert!(!no_gossip); @@ -2825,22 +3031,23 @@ mod tests { fn test_cli_parse_serve_with_flags() { let cli = Cli::parse_from(["id", "serve", "--ephemeral", "--no-relay"]); match cli.command { - Some(Command::Serve { - ephemeral, - no_relay, - no_gossip, - web, - port, - bootstrap, - topic, - topic_secret, - no_default_bootstrap, - no_default_topic, - replace_defaults, - no_mdns, - iroh_port, - .. - }) => { + Some(Command::Serve(args)) => { + let ServeArgs { + ephemeral, + no_relay, + no_gossip, + web, + port, + bootstrap, + topic, + topic_secret, + no_default_bootstrap, + no_default_topic, + replace_defaults, + no_mdns, + iroh_port, + .. + } = args; assert!(ephemeral); assert!(no_relay); assert!(!no_gossip); @@ -2863,7 +3070,8 @@ mod tests { fn test_cli_parse_serve_with_bootstrap() { let cli = Cli::parse_from(["id", "serve", "--bootstrap", "abc123,def456"]); match cli.command { - Some(Command::Serve { bootstrap, .. }) => { + Some(Command::Serve(args)) => { + let ServeArgs { bootstrap, .. } = args; assert_eq!(bootstrap, vec!["abc123", "def456"]); } _ => panic!("Expected Serve command"), @@ -2874,7 +3082,8 @@ mod tests { fn test_cli_parse_serve_with_iroh_port() { let cli = Cli::parse_from(["id", "serve", "--iroh-port", "7777"]); match cli.command { - Some(Command::Serve { iroh_port, .. }) => { + Some(Command::Serve(args)) => { + let ServeArgs { iroh_port, .. } = args; assert_eq!(iroh_port, 7777); } _ => panic!("Expected Serve command"), @@ -2892,11 +3101,12 @@ mod tests { "my-secret", ]); match cli.command { - Some(Command::Serve { - topic, - topic_secret, - .. - }) => { + Some(Command::Serve(args)) => { + let ServeArgs { + topic, + topic_secret, + .. + } = args; assert_eq!(topic, Some("my-private-net".to_owned())); assert_eq!(topic_secret, Some("my-secret".to_owned())); } @@ -3785,7 +3995,8 @@ mod tests { fn test_cli_parse_serve_no_gossip() { let cli = Cli::parse_from(["id", "serve", "--no-gossip"]); match cli.command { - Some(Command::Serve { no_gossip, .. }) => { + Some(Command::Serve(args)) => { + let ServeArgs { no_gossip, .. } = args; assert!(no_gossip); } _ => panic!("Expected Serve command"), @@ -3796,10 +4007,11 @@ mod tests { fn test_cli_parse_serve_no_default_bootstrap() { let cli = Cli::parse_from(["id", "serve", "--no-default-bootstrap"]); match cli.command { - Some(Command::Serve { - no_default_bootstrap, - .. - }) => { + Some(Command::Serve(args)) => { + let ServeArgs { + no_default_bootstrap, + .. + } = args; assert!(no_default_bootstrap); } _ => panic!("Expected Serve command"), @@ -3810,9 +4022,10 @@ mod tests { fn test_cli_parse_serve_no_default_topic() { let cli = Cli::parse_from(["id", "serve", "--no-default-topic"]); match cli.command { - Some(Command::Serve { - no_default_topic, .. - }) => { + Some(Command::Serve(args)) => { + let ServeArgs { + no_default_topic, .. + } = args; assert!(no_default_topic); } _ => panic!("Expected Serve command"), @@ -3823,9 +4036,10 @@ mod tests { fn test_cli_parse_serve_replace_defaults() { let cli = Cli::parse_from(["id", "serve", "--replace-defaults"]); match cli.command { - Some(Command::Serve { - replace_defaults, .. - }) => { + Some(Command::Serve(args)) => { + let ServeArgs { + replace_defaults, .. + } = args; assert!(replace_defaults); } _ => panic!("Expected Serve command"), @@ -3844,14 +4058,15 @@ mod tests { "--no-mdns", ]); match cli.command { - Some(Command::Serve { - no_gossip, - no_default_bootstrap, - no_default_topic, - replace_defaults, - no_mdns, - .. - }) => { + Some(Command::Serve(args)) => { + let ServeArgs { + no_gossip, + no_default_bootstrap, + no_default_topic, + replace_defaults, + no_mdns, + .. + } = args; assert!(no_gossip); assert!(no_default_bootstrap); assert!(no_default_topic); @@ -3906,7 +4121,8 @@ mod tests { fn test_cli_parse_serve_no_mdns() { let cli = Cli::parse_from(["id", "serve", "--no-mdns"]); match cli.command { - Some(Command::Serve { no_mdns, .. }) => { + Some(Command::Serve(args)) => { + let ServeArgs { no_mdns, .. } = args; assert!(no_mdns); } _ => panic!("Expected Serve command"), @@ -3917,7 +4133,8 @@ mod tests { fn test_cli_parse_serve_dht() { let cli = Cli::parse_from(["id", "serve", "--dht"]); match cli.command { - Some(Command::Serve { dht, .. }) => { + Some(Command::Serve(args)) => { + let ServeArgs { dht, .. } = args; assert!(dht); } _ => panic!("Expected Serve command"), @@ -4175,11 +4392,12 @@ mod tests { Err(error) => panic!("smtp mail with a sender should parse: {error}"), }; match cli.command { - Some(Command::Serve { - world_mail_smtp, - world_mail_from, - .. - }) => { + Some(Command::Serve(args)) => { + let ServeArgs { + world_mail_smtp, + world_mail_from, + .. + } = args; assert_eq!(world_mail_smtp, Some("127.0.0.1:25".parse().unwrap())); assert_eq!(world_mail_from.as_deref(), Some("id@example.test")); } @@ -4259,7 +4477,8 @@ mod tests { "[::1]:4002", ]); match cli.command { - Some(Command::Serve { web_listen, .. }) => { + Some(Command::Serve(args)) => { + let ServeArgs { web_listen, .. } = args; assert_eq!( web_listen, vec![ @@ -4294,16 +4513,17 @@ mod tests { "--open-writes", ]); match cli.command { - Some(Command::Serve { - bind, - web_token, - web, - world, - world_admin_token, - allow_node, - open_writes, - .. - }) => { + Some(Command::Serve(args)) => { + let ServeArgs { + bind, + web_token, + web, + world, + world_admin_token, + allow_node, + open_writes, + .. + } = args; assert!(bind.is_unspecified()); assert_eq!(web_token.as_deref(), Some("t0k")); assert!(web); @@ -4339,9 +4559,7 @@ mod tests { ]) .unwrap(); match parsed.command { - Some(Command::Serve { - world_source_only, .. - }) => assert!(world_source_only), + Some(Command::Serve(args)) => assert!(args.world_source_only), _ => panic!("Expected Serve command"), } assert!(Cli::try_parse_from(["id", "serve", "--world-source-only"]).is_err()); @@ -4377,10 +4595,9 @@ mod tests { ]) .unwrap(); match parsed.command { - Some(Command::Serve { - world_module_trust_keys, - .. - }) => assert_eq!(world_module_trust_keys, vec![first.clone(), second]), + Some(Command::Serve(args)) => { + assert_eq!(args.world_module_trust_keys, vec![first.clone(), second]) + } _ => panic!("Expected Serve command"), } assert!(Cli::try_parse_from(["id", "serve", "--world-module-trust-key", &first]).is_err()); @@ -4389,15 +4606,11 @@ mod tests { #[test] fn test_cli_parse_web_cookie_secure() { match Cli::parse_from(["id", "serve", "--web", "--web-cookie-secure"]).command { - Some(Command::Serve { - web_cookie_secure, .. - }) => assert!(web_cookie_secure), + Some(Command::Serve(args)) => assert!(args.web_cookie_secure), _ => panic!("Expected Serve command"), } match Cli::parse_from(["id", "serve", "--web"]).command { - Some(Command::Serve { - web_cookie_secure, .. - }) => assert!(!web_cookie_secure), + Some(Command::Serve(args)) => assert!(!args.web_cookie_secure), _ => panic!("Expected Serve command"), } } @@ -4414,10 +4627,7 @@ mod tests { "0", ]); match cli.command { - Some(Command::Serve { - world_boot_window_secs, - .. - }) => assert_eq!(world_boot_window_secs, 0), + Some(Command::Serve(args)) => assert_eq!(args.world_boot_window_secs, 0), _ => panic!("Expected Serve command"), } } @@ -4492,7 +4702,8 @@ mod tests { ]); match cli.command { Some(Command::World(cmd)) => match *cmd { - WorldCommand::CrossWorldWrite { mode, .. } => { + WorldCommand::CrossWorldWrite(args) => { + let WorldCrossWorldWriteArgs { mode, .. } = args; assert_eq!(mode, "on"); } other => panic!("unexpected: {other:?}"), @@ -4509,7 +4720,7 @@ mod tests { ]); assert!(matches!( cli.command, - Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::ForceCrossWorldWrite { .. }) + Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::ForceCrossWorldWrite(..)) )); let cli = Cli::parse_from([ "id", @@ -4524,11 +4735,12 @@ mod tests { ]); match cli.command { Some(Command::World(cmd)) => match *cmd { - WorldCommand::FileScope { - scope, - write_override, - .. - } => { + WorldCommand::FileScope(args) => { + let WorldFileScopeArgs { + scope, + write_override, + .. + } = args; assert_eq!(scope, "unrestricted"); assert_eq!(write_override.as_deref(), Some("on")); } @@ -4580,13 +4792,14 @@ mod tests { ]); match cli.command { Some(Command::World(cmd)) => match *cmd { - WorldCommand::Invite { - admin_token, - name, - addrs, - no_relay, - .. - } => { + WorldCommand::Invite(args) => { + let WorldInviteArgs { + admin_token, + name, + addrs, + no_relay, + .. + } = args; assert_eq!(admin_token, "t"); assert_eq!(name, "ann"); assert_eq!(addrs.len(), 1); @@ -4612,9 +4825,10 @@ mod tests { ]); match cli.command { Some(Command::World(cmd)) => match *cmd { - WorldCommand::Invite { - expires_in, uses, .. - } => { + WorldCommand::Invite(args) => { + let WorldInviteArgs { + expires_in, uses, .. + } = args; assert_eq!(expires_in, Some(259_200)); assert_eq!(uses, Some(2)); } @@ -4649,7 +4863,7 @@ mod tests { ]); assert!(matches!( cli.command, - Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::Join { after: Some(7), .. }) + Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::Join(ref a) if a.after == Some(7)) )); let cli = Cli::parse_from([ "id", @@ -4663,7 +4877,7 @@ mod tests { ]); assert!(matches!( cli.command, - Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::Join { json: true, .. }) + Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::Join(ref a) if a.json) )); assert!( Cli::try_parse_from(["id", "world", "join", &node, "--capability", "c", "--json",]) @@ -4702,13 +4916,13 @@ mod tests { "client argv {argv:?} must parse as a world client command" ); assert!( - !matches!(cli.command, Some(Command::Serve { .. })), + !matches!(cli.command, Some(Command::Serve(..))), "client argv {argv:?} must never dispatch server startup" ); } // Explicit `id serve` remains the only server entry point. let cli = Cli::parse_from(["id", "serve"]); - assert!(matches!(cli.command, Some(Command::Serve { .. }))); + assert!(matches!(cli.command, Some(Command::Serve(..)))); // There is deliberately no `--client-only` flag (#3846): no // world subcommand has a server mode such a flag could disable. assert!( @@ -4742,7 +4956,8 @@ mod tests { ]); match cli.command { Some(Command::World(cmd)) => match *cmd { - WorldCommand::Invite { role, .. } => { + WorldCommand::Invite(args) => { + let WorldInviteArgs { role, .. } = args; assert_eq!(role, Some("spectator".to_owned())); } other => panic!("unexpected: {other:?}"), @@ -4768,7 +4983,7 @@ mod tests { let cli = Cli::parse_from(["id", "world", "list", &node, "--admin-token", "t", "--json"]); assert!(matches!( cli.command, - Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::List { json: true, .. }) + Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::List(ref a) if a.json) )); } @@ -4793,13 +5008,14 @@ mod tests { ]); match cli.command { Some(Command::World(cmd)) => match *cmd { - WorldCommand::Measure { - inputs, - width, - height, - seed, - .. - } => { + WorldCommand::Measure(args) => { + let WorldMeasureArgs { + inputs, + width, + height, + seed, + .. + } = args; assert_eq!(inputs, ["ff", "00"]); assert_eq!((width, height, seed), (Some(40), Some(20), 1)); } @@ -4817,7 +5033,7 @@ mod tests { let cli = Cli::parse_from(["id", "world", "stats", &node, "--capability", "c"]); assert!(matches!( cli.command, - Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::Stats { .. }) + Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::Stats(..)) )); let cli = Cli::parse_from([ "id", @@ -4831,7 +5047,7 @@ mod tests { ]); assert!(matches!( cli.command, - Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::Logs { seconds: 9, .. }) + Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::Logs(ref a) if a.seconds == 9) )); } @@ -4866,12 +5082,12 @@ mod tests { let logs = Cli::parse_from(["id", "world", "logs", node.as_str(), "--capability", "c"]); assert!(matches!( logs.command, - Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::Logs { seconds: 5, .. }) + Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::Logs(ref a) if a.seconds == 5) )); let mirror = Cli::parse_from(["id", "world", "mirror", node.as_str(), "--capability", "c"]); assert!(matches!( mirror.command, - Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::Mirror { timeout_secs: 30, .. }) + Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::Mirror(ref a) if a.timeout_secs == 30) )); for seconds in ["0", "86400"] { @@ -4880,11 +5096,11 @@ mod tests { let expected = seconds.parse::().unwrap(); assert!(matches!( logs.command, - Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::Logs { seconds, .. } if seconds == expected) + Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::Logs(ref a) if a.seconds == expected) )); assert!(matches!( mirror.command, - Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::Mirror { timeout_secs, .. } if timeout_secs == expected) + Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::Mirror(ref a) if a.timeout_secs == expected) )); } @@ -4912,12 +5128,13 @@ mod tests { ]); match cli.command { Some(Command::World(cmd)) => match *cmd { - WorldCommand::Record { - admin_token, - out, - no_relay, - .. - } => { + WorldCommand::Record(args) => { + let WorldRecordArgs { + admin_token, + out, + no_relay, + .. + } = args; assert_eq!(admin_token, "admin-secret"); assert_eq!(out, Some(PathBuf::from("run.jsonl"))); assert!(no_relay); @@ -4945,12 +5162,14 @@ mod tests { ]); match cli.command { Some(Command::World(cmd)) => match *cmd { - WorldCommand::Replay { - module, - fixture, - seed, - allow_partial, - } => { + WorldCommand::Replay(args) => { + let WorldReplayArgs { + module, + fixture, + seed, + allow_partial, + .. + } = args; assert_eq!(module, PathBuf::from("game.wasm")); assert_eq!(fixture, PathBuf::from("run.jsonl")); assert_eq!(seed, 7); @@ -4991,12 +5210,14 @@ mod tests { ]); match cli.command { Some(Command::World(cmd)) => match *cmd { - WorldCommand::Verify { - module, - fixture, - seed, - allow_partial, - } => { + WorldCommand::Verify(args) => { + let WorldVerifyArgs { + module, + fixture, + seed, + allow_partial, + .. + } = args; assert_eq!(module, PathBuf::from("game.wasm")); assert_eq!(fixture, PathBuf::from("run.jsonl")); assert_eq!(seed, 7); @@ -5036,11 +5257,12 @@ mod tests { ]); match cli.command { Some(Command::World(cmd)) => match *cmd { - WorldCommand::Caps { - admin_token, - ceiling, - .. - } => { + WorldCommand::Caps(args) => { + let WorldCapsArgs { + admin_token, + ceiling, + .. + } = args; assert_eq!(admin_token, Some("adm".to_owned())); assert_eq!( ceiling, @@ -5066,9 +5288,10 @@ mod tests { ]); match cli.command { Some(Command::World(cmd)) => match *cmd { - WorldCommand::Doctor { - ceiling, profile, .. - } => { + WorldCommand::Doctor(args) => { + let WorldDoctorArgs { + ceiling, profile, .. + } = args; assert_eq!( ceiling, Some(vec!["time.now".to_owned(), "chat.say".to_owned()]) @@ -5100,14 +5323,15 @@ mod tests { ]); match cli.command { Some(Command::World(cmd)) => match *cmd { - WorldCommand::Profile { - admin_token, - wasm_fuel, - wasm_memory_bytes, - native_cpu_seconds, - capability, - .. - } => { + WorldCommand::Profile(args) => { + let WorldProfileArgs { + admin_token, + wasm_fuel, + wasm_memory_bytes, + native_cpu_seconds, + capability, + .. + } = args; assert_eq!(admin_token, Some("adm".to_owned())); assert_eq!(wasm_fuel, Some(500000)); assert_eq!(wasm_memory_bytes, Some(16777216)); @@ -5122,12 +5346,13 @@ mod tests { let cli = Cli::parse_from(["id", "world", "profile", &node, "--capability", "cap123"]); match cli.command { Some(Command::World(cmd)) => match *cmd { - WorldCommand::Profile { - admin_token, - capability, - wasm_fuel, - .. - } => { + WorldCommand::Profile(args) => { + let WorldProfileArgs { + admin_token, + capability, + wasm_fuel, + .. + } = args; assert_eq!(admin_token, None); assert_eq!(capability, Some("cap123".to_owned())); assert!(wasm_fuel.is_none()); @@ -5151,7 +5376,7 @@ mod world_limits_args_tests { use anyhow::Result; use clap::Parser; - use super::{Cli, Command}; + use super::{Cli, Command, ServeArgs}; use crate::world_limits::RuntimeLimits; const KIB: u64 = 1024; @@ -5161,9 +5386,10 @@ mod world_limits_args_tests { let mut argv = vec!["id", "serve", "--world", "--world-admin-token", "t"]; argv.extend_from_slice(extra); let cli = Cli::try_parse_from(argv).unwrap(); - let Some(Command::Serve { world_runtime, .. }) = cli.command else { + let Some(Command::Serve(args)) = cli.command else { panic!("expected serve"); }; + let ServeArgs { world_runtime, .. } = args; RuntimeLimits::from_args(&world_runtime) } diff --git a/pkgs/id/src/commands/serve.rs b/pkgs/id/src/commands/serve.rs index b0172db33c..2459adb4cd 100644 --- a/pkgs/id/src/commands/serve.rs +++ b/pkgs/id/src/commands/serve.rs @@ -3212,15 +3212,17 @@ mod tests { fn serve_server_config_flag_defaults_to_none() { use clap::Parser as _; let cli = crate::cli::Cli::try_parse_from(["id", "serve"]).unwrap(); - let Some(crate::cli::Command::Serve { server_config, .. }) = cli.command else { + let Some(crate::cli::Command::Serve(args)) = cli.command else { panic!("expected the serve command"); }; + let crate::cli::ServeArgs { server_config, .. } = args; assert!(server_config.is_none()); let cli = crate::cli::Cli::try_parse_from(["id", "serve", "--server-config", "ops.toml"]) .unwrap(); - let Some(crate::cli::Command::Serve { server_config, .. }) = cli.command else { + let Some(crate::cli::Command::Serve(args)) = cli.command else { panic!("expected the serve command"); }; + let crate::cli::ServeArgs { server_config, .. } = args; assert_eq!(server_config, Some(PathBuf::from("ops.toml"))); } } diff --git a/pkgs/id/src/commands/world.rs b/pkgs/id/src/commands/world.rs index c90c407b2c..8dffabaf43 100644 --- a/pkgs/id/src/commands/world.rs +++ b/pkgs/id/src/commands/world.rs @@ -90,17 +90,19 @@ fn world_list_plain_row(name: &str, default: &str, open: bool) -> String { /// Fails if the host is unreachable, refuses the invite, or the stream breaks. pub async fn cmd_world(command: WorldCommand) -> Result<()> { match command { - WorldCommand::Invite { - node, - admin_token, - name, - role, - world, - addrs, - no_relay, - expires_in, - uses, - } => { + WorldCommand::Invite(args) => { + let crate::cli::WorldInviteArgs { + node, + admin_token, + name, + role, + world, + addrs, + no_relay, + expires_in, + uses, + .. + } = args; crate::world_session::check_invite_bounds(expires_in, uses) .map_err(anyhow::Error::msg)?; let (endpoint, mut client) = connect(&node, &addrs, no_relay, world.as_deref()).await?; @@ -113,15 +115,17 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { println!("{}", result?); Ok(()) } - WorldCommand::Install { - node, - module, - admin_token, - seed, - world, - addrs, - no_relay, - } => { + WorldCommand::Install(args) => { + let crate::cli::WorldInstallArgs { + node, + module, + admin_token, + seed, + world, + addrs, + no_relay, + .. + } = args; let metadata = std::fs::metadata(&module) .with_context(|| format!("read module metadata {}", module.display()))?; anyhow::ensure!( @@ -138,14 +142,16 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { println!("{}", result?); Ok(()) } - WorldCommand::Records { - node, - capability, - prefix, - world, - addrs, - no_relay, - } => { + WorldCommand::Records(args) => { + let crate::cli::WorldRecordsArgs { + node, + capability, + prefix, + world, + addrs, + no_relay, + .. + } = args; let (endpoint, mut client) = connect(&node, &addrs, no_relay, world.as_deref()).await?; let result = client.records(&capability, prefix.as_deref()).await; client.close(); @@ -153,16 +159,18 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { println!("{}", serde_json::to_string_pretty(&result?)?); Ok(()) } - WorldCommand::Mirror { - node, - capability, - follow, - dir, - timeout_secs, - world, - addrs, - no_relay, - } => { + WorldCommand::Mirror(args) => { + let crate::cli::WorldMirrorArgs { + node, + capability, + follow, + dir, + timeout_secs, + world, + addrs, + no_relay, + .. + } = args; let (endpoint, mut client) = connect(&node, &addrs, no_relay, world.as_deref()).await?; let ticket = client.records_ticket(&capability).await?; client.close(); @@ -191,14 +199,16 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { replica.shutdown().await; Ok(()) } - WorldCommand::Download { - node, - capability, - output, - world, - addrs, - no_relay, - } => { + WorldCommand::Download(args) => { + let crate::cli::WorldDownloadArgs { + node, + capability, + output, + world, + addrs, + no_relay, + .. + } = args; let (endpoint, mut client) = connect(&node, &addrs, no_relay, world.as_deref()).await?; let result = async { let (_, active_module_hash, _) = client.info(&capability).await?; @@ -216,17 +226,19 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { endpoint.close().await; result } - WorldCommand::Compile { - node, - main_file, - files, - seed, - admin_token, - native, - world, - addrs, - no_relay, - } => { + WorldCommand::Compile(args) => { + let crate::cli::WorldCompileArgs { + node, + main_file, + files, + seed, + admin_token, + native, + world, + addrs, + no_relay, + .. + } = args; let mut paths = vec![("main.roc".to_owned(), main_file.clone())]; for path in &files { let name = path @@ -267,17 +279,19 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { println!("{hash}"); Ok(()) } - WorldCommand::Caps { - node, - capability, - admin_token, - grant, - revoke, - ceiling, - world, - addrs, - no_relay, - } => { + WorldCommand::Caps(args) => { + let crate::cli::WorldCapsArgs { + node, + capability, + admin_token, + grant, + revoke, + ceiling, + world, + addrs, + no_relay, + .. + } = args; let (endpoint, mut client) = connect(&node, &addrs, no_relay, world.as_deref()).await?; let result = if let Some(ceiling) = ceiling { let admin_token = admin_token @@ -305,20 +319,22 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { println!("{}", serde_json::to_string_pretty(&result)?); Ok(()) } - WorldCommand::Profile { - node, - admin_token, - capability, - wasm_fuel, - wasm_memory_bytes, - wasm_message_bytes, - native_memory_bytes, - native_cpu_seconds, - native_call_deadline_ms, - world, - addrs, - no_relay, - } => { + WorldCommand::Profile(args) => { + let crate::cli::WorldProfileArgs { + node, + admin_token, + capability, + wasm_fuel, + wasm_memory_bytes, + wasm_message_bytes, + native_memory_bytes, + native_cpu_seconds, + native_call_deadline_ms, + world, + addrs, + no_relay, + .. + } = args; let (endpoint, mut client) = connect(&node, &addrs, no_relay, world.as_deref()).await?; let has_updates = wasm_fuel.is_some() || wasm_memory_bytes.is_some() @@ -350,14 +366,16 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { println!("{}", serde_json::to_string_pretty(&result?)?); Ok(()) } - WorldCommand::Isolation { - node, - mode, - admin_token, - world, - addrs, - no_relay, - } => { + WorldCommand::Isolation(args) => { + let crate::cli::WorldIsolationArgs { + node, + mode, + admin_token, + world, + addrs, + no_relay, + .. + } = args; let (endpoint, mut client) = connect(&node, &addrs, no_relay, world.as_deref()).await?; let result = client.set_isolation(&admin_token, &mode).await; client.close(); @@ -365,14 +383,16 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { println!("{}", result?); Ok(()) } - WorldCommand::CrossWorldWrite { - node, - mode, - admin_token, - world, - addrs, - no_relay, - } => { + WorldCommand::CrossWorldWrite(args) => { + let crate::cli::WorldCrossWorldWriteArgs { + node, + mode, + admin_token, + world, + addrs, + no_relay, + .. + } = args; let (endpoint, mut client) = connect(&node, &addrs, no_relay, world.as_deref()).await?; let result = client .set_cross_world_write(&admin_token, mode == "on") @@ -382,13 +402,15 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { println!("{}", serde_json::to_string_pretty(&result?)?); Ok(()) } - WorldCommand::ForceCrossWorldWrite { - node, - admin_token, - world, - addrs, - no_relay, - } => { + WorldCommand::ForceCrossWorldWrite(args) => { + let crate::cli::WorldForceCrossWorldWriteArgs { + node, + admin_token, + world, + addrs, + no_relay, + .. + } = args; let (endpoint, mut client) = connect(&node, &addrs, no_relay, world.as_deref()).await?; let result = client.force_cross_world_write(&admin_token).await; client.close(); @@ -396,15 +418,17 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { println!("{}", serde_json::to_string_pretty(&result?)?); Ok(()) } - WorldCommand::FileScope { - node, - scope, - write_override, - admin_token, - world, - addrs, - no_relay, - } => { + WorldCommand::FileScope(args) => { + let crate::cli::WorldFileScopeArgs { + node, + scope, + write_override, + admin_token, + world, + addrs, + no_relay, + .. + } = args; let (endpoint, mut client) = connect(&node, &addrs, no_relay, world.as_deref()).await?; let result = client .set_file_scope( @@ -419,14 +443,16 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { Ok(()) } WorldCommand::New { dir, name } => scaffold_world(&dir, &name), - WorldCommand::Doctor { - roc_bin, - platform, - journal, - ceiling, - profile, - json, - } => { + WorldCommand::Doctor(args) => { + let crate::cli::WorldDoctorArgs { + roc_bin, + platform, + journal, + ceiling, + profile, + json, + .. + } = args; let platform_dir = platform .or_else(|| std::env::var("ID_ROC_PLATFORM").ok().map(PathBuf::from)) .or_else(|| { @@ -475,14 +501,16 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { // findings exit nonzero, counted by failure_count(). report.exit_result() } - WorldCommand::Diff { - node, - file, - capability, - world, - addrs, - no_relay, - } => { + WorldCommand::Diff(args) => { + let crate::cli::WorldDiffArgs { + node, + file, + capability, + world, + addrs, + no_relay, + .. + } = args; let manifest = parse_manifest_file(&file)?; let (endpoint, client) = connect(&node, &addrs, no_relay, world.as_deref()).await?; let state = current_world_state(&client, &capability, None).await?; @@ -491,16 +519,18 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { print!("{}", crate::world_manifest::diff(&manifest, &state)); Ok(()) } - WorldCommand::Apply { - node, - file, - admin_token, - capability, - dry_run, - world, - addrs, - no_relay, - } => { + WorldCommand::Apply(args) => { + let crate::cli::WorldApplyArgs { + node, + file, + admin_token, + capability, + dry_run, + world, + addrs, + no_relay, + .. + } = args; let manifest = parse_manifest_file(&file)?; let (endpoint, client) = connect(&node, &addrs, no_relay, world.as_deref()).await?; let state = current_world_state(&client, &capability, Some(&admin_token)).await?; @@ -551,27 +581,31 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { Ok(()) } #[cfg(feature = "sandbox")] - WorldCommand::Measure { - module, - seed, - inputs, - width, - height, - } => { + WorldCommand::Measure(args) => { + let crate::cli::WorldMeasureArgs { + module, + seed, + inputs, + width, + height, + .. + } = args; let wasm = std::fs::read(&module) .with_context(|| format!("read Wasm module {}", module.display()))?; let report = measure_module(&wasm, seed, &inputs, width.zip(height))?; println!("{}", serde_json::to_string_pretty(&report)?); Ok(()) } - WorldCommand::Logs { - node, - capability, - seconds, - world, - addrs, - no_relay, - } => { + WorldCommand::Logs(args) => { + let crate::cli::WorldLogsArgs { + node, + capability, + seconds, + world, + addrs, + no_relay, + .. + } = args; let (endpoint, mut client) = connect(&node, &addrs, no_relay, world.as_deref()).await?; client .send_json(&serde_json::json!({ @@ -609,13 +643,15 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { endpoint.close().await; result } - WorldCommand::Stats { - node, - capability, - world, - addrs, - no_relay, - } => { + WorldCommand::Stats(args) => { + let crate::cli::WorldStatsArgs { + node, + capability, + world, + addrs, + no_relay, + .. + } = args; let (endpoint, mut client) = connect(&node, &addrs, no_relay, world.as_deref()).await?; let result = async { let info = client.info_details(&capability).await?; @@ -640,14 +676,16 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { println!("{}", serde_json::to_string_pretty(&result?)?); Ok(()) } - WorldCommand::Record { - node, - admin_token, - out, - world, - addrs, - no_relay, - } => { + WorldCommand::Record(args) => { + let crate::cli::WorldRecordArgs { + node, + admin_token, + out, + world, + addrs, + no_relay, + .. + } = args; // Boxed so that `cmd_world`, already a large state machine, does not // grow by the recording's futures. Box::pin(record_command( @@ -661,26 +699,36 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { .await } #[cfg(feature = "sandbox")] - WorldCommand::Replay { - module, - fixture, - seed, - allow_partial, - } => replay_fixture(&module, &fixture, seed, allow_partial), + WorldCommand::Replay(args) => { + let crate::cli::WorldReplayArgs { + module, + fixture, + seed, + allow_partial, + .. + } = args; + replay_fixture(&module, &fixture, seed, allow_partial) + } #[cfg(feature = "sandbox")] - WorldCommand::Verify { - module, - fixture, - seed, - allow_partial, - } => verify_fixture(&module, &fixture, seed, allow_partial), - WorldCommand::List { - node, - admin_token, - json, - addrs, - no_relay, - } => { + WorldCommand::Verify(args) => { + let crate::cli::WorldVerifyArgs { + module, + fixture, + seed, + allow_partial, + .. + } = args; + verify_fixture(&module, &fixture, seed, allow_partial) + } + WorldCommand::List(args) => { + let crate::cli::WorldListArgs { + node, + admin_token, + json, + addrs, + no_relay, + .. + } = args; let (endpoint, mut client) = connect(&node, &addrs, no_relay, None).await?; // With an admin token this is the admin listing; without one // it is the host's public directory (#812) — same reply shape. @@ -727,18 +775,20 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { println!("{}", if result? { "created" } else { "exists" }); Ok(()) } - WorldCommand::Join { - node, - capability, - after, - command_mode, - json, - world, - addrs, - no_relay, - via, - ssh_host_key, - } => { + WorldCommand::Join(args) => { + let crate::cli::WorldJoinArgs { + node, + capability, + after, + command_mode, + json, + world, + addrs, + no_relay, + via, + ssh_host_key, + .. + } = args; let join = serde_json::json!({ "type": "join", "capability": capability, @@ -768,13 +818,17 @@ pub async fn cmd_world(command: WorldCommand) -> Result<()> { } } } - WorldCommand::SshTunnel { - node, - listen, - stdio, - addrs, - no_relay, - } => ssh_tunnel(&node, listen.as_deref(), stdio, &addrs, no_relay).await, + WorldCommand::SshTunnel(args) => { + let crate::cli::WorldSshTunnelArgs { + node, + listen, + stdio, + addrs, + no_relay, + .. + } = args; + ssh_tunnel(&node, listen.as_deref(), stdio, &addrs, no_relay).await + } WorldCommand::Fork { source, dir, diff --git a/pkgs/id/src/main.rs b/pkgs/id/src/main.rs index 4143439a7a..906fd8406c 100644 --- a/pkgs/id/src/main.rs +++ b/pkgs/id/src/main.rs @@ -274,52 +274,54 @@ async fn main() -> Result<()> { match cli.command { None => run_repl(None).await, Some(Command::Repl { node }) => run_repl(node).await, - Some(Command::Serve { - ephemeral, - server_config, - no_relay, - no_gossip, - web, - port, - bootstrap, - topic, - topic_secret, - no_default_bootstrap, - no_default_topic, - replace_defaults, - no_mdns, - dht, - iroh_port, - bind, - web_listen, - web_token, - web_cookie_secure, - world, - world_admin_token, - world_module, - world_mail_outbox, - world_mail_command, - world_mail_smtp, - world_mail_from, - world_name, - world_ssh_port, - world_checkpoint_every, - world_max_open, - world_max_sessions, - world_idle_secs, - world_boot_window_secs, - world_caps, - world_cap_policy, - world_allowed_caps, - roc_bin, - roc_platform, - world_native, - world_source_only, - world_module_trust_keys, - world_runtime, - allow_node, - open_writes, - }) => { + Some(Command::Serve(args)) => { + let id::cli::ServeArgs { + ephemeral, + server_config, + no_relay, + no_gossip, + web, + port, + bootstrap, + topic, + topic_secret, + no_default_bootstrap, + no_default_topic, + replace_defaults, + no_mdns, + dht, + iroh_port, + bind, + web_listen, + web_token, + web_cookie_secure, + world, + world_admin_token, + world_module, + world_mail_outbox, + world_mail_command, + world_mail_smtp, + world_mail_from, + world_name, + world_ssh_port, + world_checkpoint_every, + world_max_open, + world_max_sessions, + world_idle_secs, + world_boot_window_secs, + world_caps, + world_cap_policy, + world_allowed_caps, + roc_bin, + roc_platform, + world_native, + world_source_only, + world_module_trust_keys, + world_runtime, + allow_node, + open_writes, + .. + } = args; cmd_serve(ServeOptions { ephemeral, server_config,