Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 23 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <shorthand> <process_id>`: create an alias for a script.
- Example: `alias get_block get-block:hns-indexer:sys`
- `add-node-provider <chain-id> <node-name> <public-key> <ip-address> <ws-port> [--trusted <true|false>]`: 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 <rpc-url> [--chain-id <id>] [--trusted <true|false>] [--auth-type <basic|bearer|raw> --auth-value <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 <shorthand> <process-id>`: 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 <vfs-file-path>`: print the contents of a file in the terminal.
- Example: `cat /terminal:sys/pkg/scripts.json`
- `echo <text>`: print text to the terminal.
- `clear-state <process-id>`: clear the state of the given process.
- `echo <text>: print text to the terminal.
- Example: `echo foo`
- `help <command>`: 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 <name> <string>`: 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 <process-id>`: terminate a running process.
This will bypass any restart behavior–use judiciously.
- Example: `kill chess:chess:template.os`
- `m <address> '<json>'`: send an inter-process message.
<address> is formatted as <node>@<process-id>.
<process-id> is formatted as <process-name>:<package-name>:<publisher-node>.
JSON containing spaces must be wrapped in single-quotes (`''`).
- `kfetch`: print system information a la neofetch. No arguments.
- `kill <process-id>`: terminate a running process. This will bypass any restart behavior; use judiciously.
- Example: `kill chess:chess:sys`
- `m <address> '<json>'`: send an inter-process message. `<address>` is formatted as `<node>@<process-id>`. `<process-id>` is formatted as `<process-name>:<package-name>:<publisher-node>`. 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 <name>`: print the peer's PKI info, if it exists.
- `peers`: print the peers the node currently hold connections with.
- `top <process_id>`: 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 <chain-id> <nodename or rpc-url>`: remove a provider from the providers configuration.
- Example: `remove-provider 8453 wss://base-mainnet.infura.io/ws/v3/your-key`
- `top <process-id>`: 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`

Expand Down
11 changes: 11 additions & 0 deletions hyperdrive/packages/terminal/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions hyperdrive/packages/terminal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"add-rpcurl-provider",
"alias",
"cat",
"clear-state",
"echo",
"get-providers",
"help",
Expand Down
20 changes: 20 additions & 0 deletions hyperdrive/packages/terminal/clear-state/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
33 changes: 33 additions & 0 deletions hyperdrive/packages/terminal/clear-state/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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 <process-id>";
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::<ProcessId>() 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}")
}
3 changes: 2 additions & 1 deletion hyperdrive/packages/terminal/help/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <chain-id> <node-name> <public-key> <ip-address> <ws-port> [--trusted <true|false>]: 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 <rpc-url> [--chain-id <id>] [--trusted <true|false>] [--auth-type <basic|bearer|raw> --auth-value <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 <shorthand> <process-id>: 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 <vfs-file-path>: 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 <process-id>: clear the state of the given process."],
["echo", "\n\x1b[1mecho\x1b[0m <text>: 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 <name> <string>: send a text message to another node's command line.\n - Example: \x1b[1mhi mothu.hypr hello world\x1b[0m"],
Expand Down
1 change: 1 addition & 0 deletions hyperdrive/packages/terminal/pkg/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"net:distro:sys",
"sign:sign:sys",
"sqlite:distro:sys",
"state:distro:sys",
"timer:distro:sys",
"vfs:distro:sys",
{
Expand Down
12 changes: 12 additions & 0 deletions hyperdrive/packages/terminal/pkg/scripts.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions hyperdrive/packages/terminal/terminal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down