diff --git a/Cargo.lock b/Cargo.lock index 12af32c87..0f4b53458 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1591,6 +1591,17 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" +[[package]] +name = "clear-state" +version = "0.1.0" +dependencies = [ + "anyhow", + "hyperware_process_lib 2.1.0", + "serde", + "serde_json", + "wit-bindgen 0.42.1", +] + [[package]] name = "cmake" version = "0.1.54" @@ -3291,7 +3302,7 @@ dependencies = [ [[package]] name = "hyperdrive" -version = "1.6.0" +version = "1.6.1" dependencies = [ "aes-gcm", "alloy", @@ -3346,7 +3357,7 @@ dependencies = [ [[package]] name = "hyperdrive_lib" -version = "1.6.0" +version = "1.6.1" dependencies = [ "lib", ] @@ -3972,7 +3983,7 @@ checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" [[package]] name = "lib" -version = "1.6.0" +version = "1.6.1" dependencies = [ "alloy", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 798d6772a..7a714c422 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,8 +26,8 @@ members = [ "hyperdrive/packages/hypermap-cacher/start-providing", "hyperdrive/packages/hypermap-cacher/stop-providing", "hyperdrive/packages/sign/sign", "hyperdrive/packages/terminal/terminal", "hyperdrive/packages/terminal/add-node-provider", "hyperdrive/packages/terminal/add-rpcurl-provider", - "hyperdrive/packages/terminal/alias", "hyperdrive/packages/terminal/cat", "hyperdrive/packages/terminal/echo", "hyperdrive/packages/terminal/get-providers", - "hyperdrive/packages/terminal/help", "hyperdrive/packages/terminal/hfetch", "hyperdrive/packages/terminal/hi", + "hyperdrive/packages/terminal/alias", "hyperdrive/packages/terminal/cat", "hyperdrive/packages/terminal/clear-state", "hyperdrive/packages/terminal/echo", + "hyperdrive/packages/terminal/get-providers", "hyperdrive/packages/terminal/help", "hyperdrive/packages/terminal/hfetch", "hyperdrive/packages/terminal/hi", "hyperdrive/packages/terminal/kill", "hyperdrive/packages/terminal/m", "hyperdrive/packages/terminal/top", "hyperdrive/packages/terminal/net-diagnostics", "hyperdrive/packages/terminal/peer", "hyperdrive/packages/terminal/peers", "hyperdrive/packages/terminal/remove-provider", "hyperdrive/packages/tester/tester", diff --git a/README.md b/README.md index a606e377c..845b43c1b 100644 --- a/README.md +++ b/README.md @@ -251,34 +251,40 @@ Subsequent use of the shorthand will then be interpolated as the process ID. A list of the terminal scripts included in this distro: -- `alias `: create an alias for a script. - - Example: `alias get_block get-block:hns-indexer:sys` +- `add-node-provider [--trusted ]`: add a node provider to the providers configuration. + - Examples: + - `add-node-provider 8453 other-node.hypr abc123pubkey 192.168.1.1 9000` (defaults to trusted=false) + - `add-node-provider 1 other-node.hypr abc123pubkey 192.168.1.1 9000 --trusted true` +- `add-rpcurl-provider [--chain-id ] [--trusted ] [--auth-type --auth-value ]`: add an RPC URL provider to the providers configuration. + - Examples: + - `add-rpcurl-provider wss://base-mainnet.infura.io/v3/your-key` (defaults to chain-id=8453, trusted=true) + - `add-rpcurl-provider wss://mainnet.infura.io/v3/your-key --chain-id 1` + - `add-rpcurl-provider wss://base-mainnet.infura.io/ws/v3/your-key --trusted false` + - `add-rpcurl-provider wss://rpc.example.com --auth-type bearer --auth-value your-token` +- `alias `: create an alias for a script. + - Example: `alias get-block get-block:hns-indexer:sys` - note: all of these listed commands are just default aliases for terminal scripts. - `cat `: print the contents of a file in the terminal. - Example: `cat /terminal:sys/pkg/scripts.json` -- `echo `: print text to the terminal. +- `clear-state `: clear the state of the given process. +- `echo : print text to the terminal. - Example: `echo foo` -- `help `: print the help message for a command. - Leave the command blank to print the help message for all commands. +- `get-providers`: display the providers configuration. - `hi `: send a text message to another node's command line. - Example: `hi mothu.hypr hello world` -- `hfetch`: print system information a la neofetch. - No arguments. -- `kill `: terminate a running process. - This will bypass any restart behavior–use judiciously. - - Example: `kill chess:chess:template.os` -- `m
''`: send an inter-process message. -
is formatted as @. - is formatted as ::. - JSON containing spaces must be wrapped in single-quotes (`''`). +- `kfetch`: print system information a la neofetch. No arguments. +- `kill `: terminate a running process. This will bypass any restart behavior; use judiciously. + - Example: `kill chess:chess:sys` +- `m
''`: send an inter-process message. `
` is formatted as `@`. `` is formatted as `::`. JSON containing spaces must be wrapped in single-quotes (''). - Example: `m our@eth:distro:sys "SetPublic" -a 5` - - the '-a' flag is used to expect a response with a given timeout + - the `-a` flag is used to expect a response with a given timeout - `our` will always be interpolated by the system as your node's name - `net-diagnostics`: print some useful networking diagnostic data. - `peer `: print the peer's PKI info, if it exists. - `peers`: print the peers the node currently hold connections with. -- `top `: display kernel debugging info about a process. - Leave the process ID blank to display info about all processes and get the total number of running processes. +- `remove-provider `: remove a provider from the providers configuration. + - Example: `remove-provider 8453 wss://base-mainnet.infura.io/ws/v3/your-key` +- `top `: display kernel debugging info about a process. Leave the process ID blank to display info about all processes and get the total number of running processes. - Example: `top net:distro:sys` - Example: `top` diff --git a/hyperdrive/packages/terminal/Cargo.lock b/hyperdrive/packages/terminal/Cargo.lock index 2860ebbc2..19afe4693 100644 --- a/hyperdrive/packages/terminal/Cargo.lock +++ b/hyperdrive/packages/terminal/Cargo.lock @@ -1033,6 +1033,17 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" +[[package]] +name = "clear-state" +version = "0.1.0" +dependencies = [ + "anyhow", + "hyperware_process_lib", + "serde", + "serde_json", + "wit-bindgen", +] + [[package]] name = "colorchoice" version = "1.0.3" diff --git a/hyperdrive/packages/terminal/Cargo.toml b/hyperdrive/packages/terminal/Cargo.toml index 7a6d7f5c5..3a57261ec 100644 --- a/hyperdrive/packages/terminal/Cargo.toml +++ b/hyperdrive/packages/terminal/Cargo.toml @@ -5,6 +5,7 @@ members = [ "add-rpcurl-provider", "alias", "cat", + "clear-state", "echo", "get-providers", "help", diff --git a/hyperdrive/packages/terminal/clear-state/Cargo.toml b/hyperdrive/packages/terminal/clear-state/Cargo.toml new file mode 100644 index 000000000..580f64180 --- /dev/null +++ b/hyperdrive/packages/terminal/clear-state/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "clear-state" +version = "0.1.0" +edition = "2021" + +[features] +simulation-mode = [] + +[dependencies] +anyhow = "1.0" +hyperware_process_lib = "2.1.0" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +wit-bindgen = "0.42.1" + +[lib] +crate-type = ["cdylib"] + +[package.metadata.component] +package = "hyperware:process" diff --git a/hyperdrive/packages/terminal/clear-state/src/lib.rs b/hyperdrive/packages/terminal/clear-state/src/lib.rs new file mode 100644 index 000000000..5f0a63ccc --- /dev/null +++ b/hyperdrive/packages/terminal/clear-state/src/lib.rs @@ -0,0 +1,33 @@ +use hyperware_process_lib::{ + kernel_types::StateAction, println, script, Address, ProcessId, Request, +}; + +wit_bindgen::generate!({ + path: "../target/wit", + world: "process-v1", +}); + +const USAGE: &str = "\x1b[1mUsage:\x1b[0m clear-state "; +const STATE_PROCESS_ID: (&str, &str, &str) = ("state", "distro", "sys"); + +script!(init); +fn init(_our: Address, args: String) -> String { + if args.is_empty() { + return format!("Clear the state of the given process.\n{USAGE}"); + } + + let Ok(ref process_id) = args.parse::() else { + return format!( + "'{args}' is not a process-id (e.g. `process-name:package-name:publisher.os`)\n{USAGE}" + ); + }; + + let Ok(Ok(_)) = Request::to(("our", STATE_PROCESS_ID)) + .body(serde_json::to_vec(&StateAction::DeleteState(process_id.clone())).unwrap()) + .send_and_await_response(5) + else { + return format!("Failed to delete state for process {process_id}"); + }; + + format!("Deleted state of process {process_id}") +} diff --git a/hyperdrive/packages/terminal/help/src/lib.rs b/hyperdrive/packages/terminal/help/src/lib.rs index 999e32d93..3b26ff75e 100644 --- a/hyperdrive/packages/terminal/help/src/lib.rs +++ b/hyperdrive/packages/terminal/help/src/lib.rs @@ -5,11 +5,12 @@ wit_bindgen::generate!({ world: "process-v1", }); -const HELP_MESSAGES: [[&str; 2]; 15] = [ +const HELP_MESSAGES: [[&str; 2]; 16] = [ ["add-node-provider", "\n\x1b[1madd-node-provider\x1b[0m [--trusted ]: add a node provider to the providers configuration.\n - Examples:\n \x1b[1madd-node-provider 8453 other-node.hypr abc123pubkey 192.168.1.1 9000\x1b[0m (defaults to trusted=false)\n \x1b[1madd-node-provider 1 other-node.hypr abc123pubkey 192.168.1.1 9000 --trusted true\x1b[0m"], ["add-rpcurl-provider", "\n\x1b[1madd-rpcurl-provider\x1b[0m [--chain-id ] [--trusted ] [--auth-type --auth-value ]: add an RPC URL provider to the providers configuration.\n - Examples:\n \x1b[1madd-rpcurl-provider wss://base-mainnet.infura.io/v3/your-key\x1b[0m (defaults to chain-id=8453, trusted=true)\n \x1b[1madd-rpcurl-provider wss://mainnet.infura.io/v3/your-key --chain-id 1\x1b[0m\n \x1b[1madd-rpcurl-provider wss://base-mainnet.infura.io/ws/v3/your-key --trusted false\x1b[0m\n \x1b[1madd-rpcurl-provider wss://rpc.example.com --auth-type bearer --auth-value your-token\x1b[0m"], ["alias", "\n\x1b[1malias\x1b[0m : create an alias for a script.\n - Example: \x1b[1malias get-block get-block:hns-indexer:sys\x1b[0m\n - note: all of these listed commands are just default aliases for terminal scripts."], ["cat", "\n\x1b[1mcat\x1b[0m : print the contents of a file in the terminal.\n - Example: \x1b[1mcat /terminal:sys/pkg/scripts.json\x1b[0m"], + ["clear-state", "\n\x1b[1mclear-state\x1b[0m : clear the state of the given process."], ["echo", "\n\x1b[1mecho\x1b[0m : print text to the terminal.\n - Example: \x1b[1mecho foo\x1b[0m"], ["get-providers", "\n\x1b[1mget-providers\x1b[0m: display the providers configuration."], ["hi", "\n\x1b[1mhi\x1b[0m : send a text message to another node's command line.\n - Example: \x1b[1mhi mothu.hypr hello world\x1b[0m"], diff --git a/hyperdrive/packages/terminal/pkg/manifest.json b/hyperdrive/packages/terminal/pkg/manifest.json index 8238109e0..4b98add19 100644 --- a/hyperdrive/packages/terminal/pkg/manifest.json +++ b/hyperdrive/packages/terminal/pkg/manifest.json @@ -30,6 +30,7 @@ "net:distro:sys", "sign:sign:sys", "sqlite:distro:sys", + "state:distro:sys", "timer:distro:sys", "vfs:distro:sys", { diff --git a/hyperdrive/packages/terminal/pkg/scripts.json b/hyperdrive/packages/terminal/pkg/scripts.json index 1b2c17825..6d12decba 100644 --- a/hyperdrive/packages/terminal/pkg/scripts.json +++ b/hyperdrive/packages/terminal/pkg/scripts.json @@ -61,6 +61,18 @@ "grant_capabilities": [], "wit_version": 1 }, + "clear-state.wasm": { + "root": false, + "public": false, + "request_networking": false, + "request_capabilities": [ + "state:distro:sys" + ], + "grant_capabilities": [ + "state:distro:sys" + ], + "wit_version": 1 + }, "echo.wasm": { "root": false, "public": false, diff --git a/hyperdrive/packages/terminal/terminal/src/lib.rs b/hyperdrive/packages/terminal/terminal/src/lib.rs index babd24ceb..c1831f6ae 100644 --- a/hyperdrive/packages/terminal/terminal/src/lib.rs +++ b/hyperdrive/packages/terminal/terminal/src/lib.rs @@ -76,6 +76,10 @@ impl VersionedState { "cat".to_string(), ProcessId::new(Some("cat"), "terminal", "sys"), ), + ( + "clear-state".to_string(), + ProcessId::new(Some("clear-state"), "terminal", "sys"), + ), ( "echo".to_string(), ProcessId::new(Some("echo"), "terminal", "sys"),