terminal: add help script, cargo update

This commit is contained in:
dr-frmr 2024-08-14 14:57:50 +03:00
parent 2d71ec529a
commit 91aef91317
No known key found for this signature in database
9 changed files with 150 additions and 51 deletions

79
Cargo.lock generated
View File

@ -1294,12 +1294,13 @@ dependencies = [
[[package]]
name = "cc"
version = "1.1.10"
version = "1.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9e8aabfac534be767c909e0690571677d49f41bd8465ae876fe043d52ba5292"
checksum = "5fb8dd288a69fc53a1996d7ecfbf4a20d59065bff137ce7e56bbd620de191189"
dependencies = [
"jobserver",
"libc",
"shlex",
]
[[package]]
@ -1545,9 +1546,9 @@ dependencies = [
[[package]]
name = "cpufeatures"
version = "0.2.12"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504"
checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad"
dependencies = [
"libc",
]
@ -2098,10 +2099,7 @@ dependencies = [
name = "echo"
version = "0.1.0"
dependencies = [
"anyhow",
"kinode_process_lib 0.9.0",
"serde",
"serde_json",
"wit-bindgen",
]
@ -2667,6 +2665,14 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "help"
version = "0.1.0"
dependencies = [
"kinode_process_lib 0.9.0",
"wit-bindgen",
]
[[package]]
name = "hermit-abi"
version = "0.3.9"
@ -3018,9 +3024,9 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
[[package]]
name = "indexmap"
version = "2.3.0"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0"
checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c"
dependencies = [
"equivalent",
"hashbrown 0.14.5",
@ -3158,9 +3164,9 @@ dependencies = [
[[package]]
name = "js-sys"
version = "0.3.69"
version = "0.3.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d"
checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a"
dependencies = [
"wasm-bindgen",
]
@ -3325,7 +3331,7 @@ dependencies = [
[[package]]
name = "kinode_process_lib"
version = "0.9.0"
source = "git+https://github.com/kinode-dao/process_lib?branch=develop#22d08dd395eff61435370575f2966ac6cfbcfdce"
source = "git+https://github.com/kinode-dao/process_lib?branch=develop#5c1d8ed36cf10688808c09357ef0e43225396097"
dependencies = [
"alloy",
"alloy-primitives",
@ -3559,9 +3565,9 @@ dependencies = [
[[package]]
name = "libz-sys"
version = "1.1.18"
version = "1.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c15da26e5af7e25c90b37a2d75cdbf940cf4a55316de9d84c679c9b8bfabf82e"
checksum = "fdc53a7799a7496ebc9fd29f31f7df80e83c9bda5299768af5f9e59eeea74647"
dependencies = [
"cc",
"libc",
@ -5073,18 +5079,18 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73"
[[package]]
name = "serde"
version = "1.0.206"
version = "1.0.207"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b3e4cd94123dd520a128bcd11e34d9e9e423e7e3e50425cb1b4b1e3549d0284"
checksum = "5665e14a49a4ea1b91029ba7d3bca9f299e1f7cfa194388ccc20f14743e784f2"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.206"
version = "1.0.207"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fabfb6138d2383ea8208cf98ccf69cdfb1aff4088460681d84189aa259762f97"
checksum = "6aea2634c86b0e8ef2cfdc0c340baede54ec27b1e46febd7f80dffb2aa44a00e"
dependencies = [
"proc-macro2",
"quote",
@ -5838,15 +5844,15 @@ dependencies = [
[[package]]
name = "tower-layer"
version = "0.3.2"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0"
checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e"
[[package]]
name = "tower-service"
version = "0.3.2"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52"
checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
[[package]]
name = "tracing"
@ -6303,19 +6309,20 @@ dependencies = [
[[package]]
name = "wasm-bindgen"
version = "0.2.92"
version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8"
checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5"
dependencies = [
"cfg-if",
"once_cell",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.92"
version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da"
checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b"
dependencies = [
"bumpalo",
"log",
@ -6328,9 +6335,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.42"
version = "0.4.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0"
checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed"
dependencies = [
"cfg-if",
"js-sys",
@ -6340,9 +6347,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.92"
version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726"
checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -6350,9 +6357,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.92"
version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836"
dependencies = [
"proc-macro2",
"quote",
@ -6363,9 +6370,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.92"
version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484"
[[package]]
name = "wasm-encoder"
@ -6802,9 +6809,9 @@ dependencies = [
[[package]]
name = "web-sys"
version = "0.3.69"
version = "0.3.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef"
checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0"
dependencies = [
"js-sys",
"wasm-bindgen",

View File

@ -22,7 +22,9 @@ members = [
"kinode/packages/kns_indexer/kns_indexer", "kinode/packages/kns_indexer/get_block", "kinode/packages/kns_indexer/state",
"kinode/packages/settings/settings",
"kinode/packages/terminal/terminal",
"kinode/packages/terminal/alias", "kinode/packages/terminal/cat", "kinode/packages/terminal/echo", "kinode/packages/terminal/hi", "kinode/packages/terminal/kfetch", "kinode/packages/terminal/kill", "kinode/packages/terminal/m", "kinode/packages/terminal/top",
"kinode/packages/terminal/alias", "kinode/packages/terminal/cat", "kinode/packages/terminal/echo",
"kinode/packages/terminal/help", "kinode/packages/terminal/hi", "kinode/packages/terminal/kfetch",
"kinode/packages/terminal/kill", "kinode/packages/terminal/m", "kinode/packages/terminal/top",
"kinode/packages/terminal/net_diagnostics", "kinode/packages/terminal/peer", "kinode/packages/terminal/peers",
"kinode/packages/tester/tester",
]

View File

@ -139,8 +139,9 @@ A list of the terminal scripts included in this distro:
- Example: `cat /terminal:sys/pkg/scripts.json`
- `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.
- `hi <name> <string>`: send a text message to another node's command line.
- Example: `hi ben.os hello world`
- Example: `hi mothu.kino hello world`
- `kfetch`: print system information a la neofetch. No arguments.
- `kill <process-id>`: terminate a running process. This will bypass any restart behavioruse judiciously.
- Example: `kill chess:chess:sys`

View File

@ -306,8 +306,8 @@ fn handle_log(our: &Address, state: &mut State, log: &eth::Log) -> anyhow::Resul
let child_hash = decoded.childhash.to_string();
let name = String::from_utf8(decoded.label.to_vec())?;
if !kimap::valid_name(&name, false) {
return Err(anyhow::anyhow!("skipping invalid entry"));
if !kimap::valid_name(&name) {
return Err(anyhow::anyhow!("skipping invalid name: {name}"));
}
let full_name = match get_parent_name(&state.names, &parent_hash) {
@ -334,6 +334,10 @@ fn handle_log(our: &Address, state: &mut State, log: &eth::Log) -> anyhow::Resul
let note = String::from_utf8(decoded.label.to_vec())?;
let node_hash = decoded.parenthash.to_string();
if !kimap::valid_note(&note) {
return Err(anyhow::anyhow!("skipping invalid note: {note}"));
}
let Some(node_name) = get_parent_name(&state.names, &node_hash) else {
return Err(anyhow::anyhow!("parent node for note not found"));
};

View File

@ -7,10 +7,7 @@ edition = "2021"
simulation-mode = []
[dependencies]
anyhow = "1.0"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", branch = "develop" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = "0.24.0"
[lib]

View File

@ -0,0 +1,17 @@
[package]
name = "help"
version = "0.1.0"
edition = "2021"
[features]
simulation-mode = []
[dependencies]
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", branch = "develop" }
wit-bindgen = "0.24.0"
[lib]
crate-type = ["cdylib"]
[package.metadata.component]
package = "kinode:process"

View File

@ -0,0 +1,50 @@
use kinode_process_lib::{script, Address};
wit_bindgen::generate!({
path: "target/wit",
world: "process-v0",
});
const HELP_MESSAGES: [[&str; 2]; 11] = [
["alias", "\n\x1b[1malias\x1b[0m <shorthand> <process_id>: create an alias for a script.\n - Example: \x1b[1malias get_block get_block:kns_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"],
["echo", "\n\x1b[1mecho\x1b[0m <text>: print text to the terminal.\n - Example: \x1b[1mecho foo\x1b[0m"],
["hi", "\n\x1b[1mhi\x1b[0m <name> <string>: send a text message to another node's command line.\n - Example: \x1b[1mhi mothu.kino hello world\x1b[0m"],
["kfetch", "\n\x1b[1mkfetch\x1b[0m: print system information a la neofetch. No arguments."],
["kill", "\n\x1b[1mkill\x1b[0m <process-id>: terminate a running process. This will bypass any restart behavioruse judiciously.\n - Example: \x1b[1mkill chess:chess:sys\x1b[0m"],
["m", "\n\x1b[1mm\x1b[0m <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 (\x1b[1m''\x1b[0m).\n - Example: \x1b[1mm our@eth:distro:sys \"SetPublic\" -a 5\x1b[0m\n - the '-a' flag is used to expect a response with a given timeout\n - \x1b[1mour\x1b[0m will always be interpolated by the system as your node's name"],
["net_diagnostics", "\n\x1b[1mnet_diagnostics\x1b[0m: print some useful networking diagnostic data."],
["peer", "\n\x1b[1mpeer\x1b[0m <name>: print the peer's PKI info, if it exists."],
["peers", "\n\x1b[1mpeers\x1b[0m: print the peers the node currently hold connections with."],
["top", "\n\x1b[1mtop\x1b[0m <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.\n - Example: \x1b[1mtop net:distro:sys\x1b[0m\n - Example: \x1b[1mtop\x1b[0m"],
];
script!(init);
fn init(_our: Address, args: String) -> String {
// if args is empty, print the entire help message.
// if args contains the name of a command, print the help message for that command.
// otherwise, print an error message.
if args.is_empty() {
let mut help_message = String::from(
"\n====================\n\
Kinode Terminal Help\n\
====================\n",
);
for [_, message] in HELP_MESSAGES.iter() {
help_message.push_str(message);
help_message.push_str("\n");
}
help_message.push_str(
"For more help, look to the documentation at book.kinode.org.\n\
============================================================\n",
);
return help_message;
} else if let Some(message) = HELP_MESSAGES.iter().find(|[cmd, _]| cmd == &args) {
return message[1].to_string();
} else {
return format!("No help found for command \x1b[1m{args}\x1b[0m");
}
}

View File

@ -33,6 +33,14 @@
"grant_capabilities": [],
"wit_version": 0
},
"help.wasm": {
"root": false,
"public": false,
"request_networking": false,
"request_capabilities": [],
"grant_capabilities": [],
"wit_version": 0
},
"hi.wasm": {
"root": false,
"public": false,

View File

@ -71,6 +71,10 @@ impl TerminalState {
"echo".to_string(),
ProcessId::new(Some("echo"), "terminal", "sys"),
),
(
"help".to_string(),
ProcessId::new(Some("help"), "terminal", "sys"),
),
(
"hi".to_string(),
ProcessId::new(Some("hi"), "terminal", "sys"),
@ -110,14 +114,23 @@ impl TerminalState {
call_init!(init);
fn init(our: Address) {
let mut state: TerminalState = match get_typed_state(|bytes| bincode::deserialize(bytes)) {
Some(s) => s,
None => {
let state = TerminalState::new(our);
set_state(&bincode::serialize(&state).unwrap());
state
}
};
let mut state: TerminalState =
match get_typed_state(|bytes| bincode::deserialize::<TerminalState>(bytes)) {
Some(mut s) => {
// **add** the pre-installed scripts to the terminal state
// in case new ones have been added or if user has deleted aliases
let default_state = TerminalState::new(our);
for (alias, process) in default_state.aliases {
s.aliases.insert(alias, process);
}
s
}
None => {
let state = TerminalState::new(our);
set_state(&bincode::serialize(&state).unwrap());
state
}
};
loop {
let message = match await_message() {