From 2b6e8527a5e89bb62d428c5224569eec2a829da5 Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Mon, 15 Jan 2024 14:22:59 -0600 Subject: [PATCH 01/21] initial --- modules/script_runner/pkg/manifest.json | 21 + modules/script_runner/pkg/metadata.json | 9 + .../script_runner/script_runner/Cargo.lock | 555 ++++++++++++++++++ .../script_runner/script_runner/Cargo.toml | 23 + .../script_runner/script_runner/src/lib.rs | 67 +++ 5 files changed, 675 insertions(+) create mode 100644 modules/script_runner/pkg/manifest.json create mode 100644 modules/script_runner/pkg/metadata.json create mode 100644 modules/script_runner/script_runner/Cargo.lock create mode 100644 modules/script_runner/script_runner/Cargo.toml create mode 100644 modules/script_runner/script_runner/src/lib.rs diff --git a/modules/script_runner/pkg/manifest.json b/modules/script_runner/pkg/manifest.json new file mode 100644 index 00000000..4011c479 --- /dev/null +++ b/modules/script_runner/pkg/manifest.json @@ -0,0 +1,21 @@ +[ + { + "process_name": "script_runner", + "process_wasm_path": "/script_runner.wasm", + "on_exit": "Restart", + "request_networking": false, + "request_capabilities": [ + "filesystem:sys:nectar", + "vfs:sys:nectar", + "kernel:sys:nectar", + { + "process": "vfs:sys:nectar", + "params": { + "root": true + } + } + ], + "grant_capabilities": [], + "public": true + } +] \ No newline at end of file diff --git a/modules/script_runner/pkg/metadata.json b/modules/script_runner/pkg/metadata.json new file mode 100644 index 00000000..d5f37684 --- /dev/null +++ b/modules/script_runner/pkg/metadata.json @@ -0,0 +1,9 @@ +{ + "package": "script_runner", + "publisher": "nectar", + "version": [ + 0, + 1, + 0 + ] +} \ No newline at end of file diff --git a/modules/script_runner/script_runner/Cargo.lock b/modules/script_runner/script_runner/Cargo.lock new file mode 100644 index 00000000..938691df --- /dev/null +++ b/modules/script_runner/script_runner/Cargo.lock @@ -0,0 +1,555 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + +[[package]] +name = "bytes" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "getrandom" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "http" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +dependencies = [ + "equivalent", + "hashbrown", + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + +[[package]] +name = "libc" +version = "0.2.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "nectar_process_lib" +version = "0.5.0" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?tag=v0.5.1-alpha#64d2856412c11c93b5f4e2f6d61b5111fa4bf84c" +dependencies = [ + "anyhow", + "bincode", + "http", + "mime_guess", + "rand", + "serde", + "serde_json", + "thiserror", + "url", + "wit-bindgen", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "ryu" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" + +[[package]] +name = "script_runner" +version = "0.1.0" +dependencies = [ + "anyhow", + "bincode", + "nectar_process_lib", + "serde", + "serde_json", + "wit-bindgen", +] + +[[package]] +name = "semver" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" + +[[package]] +name = "serde" +version = "1.0.195" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.195" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "smallvec" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2593d31f82ead8df961d8bd23a64c2ccf2eb5dd34b0a34bfb4dd54011c72009e" + +[[package]] +name = "spdx" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bde1398b09b9f93fc2fc9b9da86e362693e999d3a54a8ac47a99a5a73f638b" +dependencies = [ + "smallvec", +] + +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-encoder" +version = "0.38.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ad2b51884de9c7f4fe2fd1043fccb8dcad4b1e29558146ee57a144d15779f3f" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-encoder" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "111495d6204760238512f57a9af162f45086504da332af210f2f75dd80b34f1d" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-metadata" +version = "0.10.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "818931c85b1d197909699d36c509fa89550ccfa0d66932ba3c1726faddb4d0c7" +dependencies = [ + "anyhow", + "indexmap", + "serde", + "serde_derive", + "serde_json", + "spdx", + "wasm-encoder 0.39.0", + "wasmparser 0.119.0", +] + +[[package]] +name = "wasmparser" +version = "0.118.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95ee9723b928e735d53000dec9eae7b07a60e490c85ab54abb66659fc61bfcd9" +dependencies = [ + "indexmap", + "semver", +] + +[[package]] +name = "wasmparser" +version = "0.119.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c35daf77afb4f9b14016625144a391085ec2ca99ca9cc53ed291bb53ab5278d" +dependencies = [ + "bitflags", + "indexmap", + "semver", +] + +[[package]] +name = "wit-bindgen" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "bitflags", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "anyhow", + "wit-component", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "anyhow", + "heck", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", + "wit-component", +] + +[[package]] +name = "wit-component" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a35a2a9992898c9d27f1664001860595a4bc99d32dd3599d547412e17d7e2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder 0.38.1", + "wasm-metadata", + "wasmparser 0.118.1", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df4913a2219096373fd6512adead1fb77ecdaa59d7fc517972a7d30b12f625be" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", +] diff --git a/modules/script_runner/script_runner/Cargo.toml b/modules/script_runner/script_runner/Cargo.toml new file mode 100644 index 00000000..539ca1fa --- /dev/null +++ b/modules/script_runner/script_runner/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "script_runner" +version = "0.1.0" +edition = "2021" + +[profile.release] +panic = "abort" +opt-level = "s" +lto = true + +[dependencies] +anyhow = "1.0" +bincode = "1.3.3" +nectar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", tag = "v0.5.1-alpha" } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } + +[lib] +crate-type = ["cdylib"] + +[package.metadata.component] +package = "nectar:process" diff --git a/modules/script_runner/script_runner/src/lib.rs b/modules/script_runner/script_runner/src/lib.rs new file mode 100644 index 00000000..7f4ca59c --- /dev/null +++ b/modules/script_runner/script_runner/src/lib.rs @@ -0,0 +1,67 @@ +use serde::{Deserialize, Serialize}; +use std::str::FromStr; + +use nectar_process_lib::{ + await_message, call_init, println, Address, Message, ProcessId, Request, Response, +}; + +wit_bindgen::generate!({ + path: "wit", + world: "process", + exports: { + world: Component, + }, +}); + +#[derive(Debug, Serialize, Deserialize)] +pub enum ScriptRequest { + Run { + path: String, // vfs path + args: String, // first message, in json + }, + Inject { + process: String, // ProcessId + args: String, // next message, in json + }, + Terminate(String), // ProcessId string encoded +} + +call_init!(init); +fn init(our: Address) { + println!("script_runner: begin"); + + loop { + match handle_message(&our) { + Ok(()) => {} + Err(e) => { + println!("script_runner: error: {:?}", e); + } + }; + } +} + +fn handle_message(our: &Address) -> anyhow::Result<()> { + let message = await_message()?; + + match message { + Message::Response { .. } => { + return Err(anyhow::anyhow!("unexpected Response: {:?}", message)); + } + Message::Request { + ref source, + ref body, + .. + } => match serde_json::from_slice::(body)? { + ScriptRequest::Run { path, args } => { + println!("script_runner: got run request"); + } + ScriptRequest::Inject { process, args } => { + println!("script_runner: got inject request"); + } + ScriptRequest::Terminate(process) => { + println!("script_runner: got terminate request"); + } + }, + } + Ok(()) +} From a3d1e37241324596f2cdb4bdac225221eb30bb15 Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Mon, 15 Jan 2024 16:07:59 -0600 Subject: [PATCH 02/21] dummy script starting working --- .../script_runner/script_runner/Cargo.lock | 1 + .../script_runner/script_runner/Cargo.toml | 1 + .../script_runner/script_runner/src/lib.rs | 225 ++++++- modules/script_runner/test_script/Cargo.lock | 554 ++++++++++++++++++ modules/script_runner/test_script/Cargo.toml | 22 + modules/script_runner/test_script/src/lib.rs | 15 + 6 files changed, 813 insertions(+), 5 deletions(-) create mode 100644 modules/script_runner/test_script/Cargo.lock create mode 100644 modules/script_runner/test_script/Cargo.toml create mode 100644 modules/script_runner/test_script/src/lib.rs diff --git a/modules/script_runner/script_runner/Cargo.lock b/modules/script_runner/script_runner/Cargo.lock index 938691df..bd2b79c2 100644 --- a/modules/script_runner/script_runner/Cargo.lock +++ b/modules/script_runner/script_runner/Cargo.lock @@ -250,6 +250,7 @@ dependencies = [ "anyhow", "bincode", "nectar_process_lib", + "rand", "serde", "serde_json", "wit-bindgen", diff --git a/modules/script_runner/script_runner/Cargo.toml b/modules/script_runner/script_runner/Cargo.toml index 539ca1fa..a71b7dfa 100644 --- a/modules/script_runner/script_runner/Cargo.toml +++ b/modules/script_runner/script_runner/Cargo.toml @@ -12,6 +12,7 @@ lto = true anyhow = "1.0" bincode = "1.3.3" nectar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", tag = "v0.5.1-alpha" } +rand = "0.8" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } diff --git a/modules/script_runner/script_runner/src/lib.rs b/modules/script_runner/script_runner/src/lib.rs index 7f4ca59c..593a3a10 100644 --- a/modules/script_runner/script_runner/src/lib.rs +++ b/modules/script_runner/script_runner/src/lib.rs @@ -1,4 +1,7 @@ +use nectar_process_lib::kernel_types as kt; +use nectar_process_lib::*; use serde::{Deserialize, Serialize}; +use std::collections::{HashMap, HashSet}; use std::str::FromStr; use nectar_process_lib::{ @@ -16,8 +19,9 @@ wit_bindgen::generate!({ #[derive(Debug, Serialize, Deserialize)] pub enum ScriptRequest { Run { - path: String, // vfs path - args: String, // first message, in json + package: PackageId, + wasm_path: String, // vfs path + args: String, // first message, in json }, Inject { process: String, // ProcessId @@ -52,9 +56,14 @@ fn handle_message(our: &Address) -> anyhow::Result<()> { ref body, .. } => match serde_json::from_slice::(body)? { - ScriptRequest::Run { path, args } => { - println!("script_runner: got run request"); - } + ScriptRequest::Run { + package, + wasm_path, + args, + } => match handle_run(our, &package, wasm_path, args) { + Ok(()) => {} // LocalResponse::InstallResponse(InstallResponse::Success), + Err(_) => {} // LocalResponse::InstallResponse(InstallResponse::Failure), + }, ScriptRequest::Inject { process, args } => { println!("script_runner: got inject request"); } @@ -65,3 +74,209 @@ fn handle_message(our: &Address) -> anyhow::Result<()> { } Ok(()) } + +fn handle_run( + our: &Address, + package: &PackageId, + wasm_path: String, + args: String, +) -> anyhow::Result<()> { + let drive_path = format!("/{}/pkg", package); + // Request::new() + // .target(("our", "vfs", "sys", "nectar")) + // .body(serde_json::to_vec(&vfs::VfsRequest { + // path: format!("{}/manifest.json", drive_path), + // action: vfs::VfsAction::Read, + // })?) + // .send_and_await_response(5)??; + // let Some(blob) = get_blob() else { + // return Err(anyhow::anyhow!("no blob")); + // }; + // let manifest = String::from_utf8(blob.bytes)?; + // let manifest = serde_json::from_str::>(&manifest)?; + // // always grant read/write to their drive, which we created for them + // let Some(read_cap) = get_capability( + // &Address::new(&our.node, ("vfs", "sys", "nectar")), + // &serde_json::to_string(&serde_json::json!({ + // "kind": "read", + // "drive": drive_path, + // }))?, + // ) else { + // return Err(anyhow::anyhow!("app store: no read cap")); + // }; + // let Some(write_cap) = get_capability( + // &Address::new(&our.node, ("vfs", "sys", "nectar")), + // &serde_json::to_string(&serde_json::json!({ + // "kind": "write", + // "drive": drive_path, + // }))?, + // ) else { + // return Err(anyhow::anyhow!("app store: no write cap")); + // }; + // let Some(networking_cap) = get_capability( + // &Address::new(&our.node, ("kernel", "sys", "nectar")), + // &"\"network\"".to_string(), + // ) else { + // return Err(anyhow::anyhow!("app store: no net cap")); + // }; + // first, for each process in manifest, initialize it + // then, once all have been initialized, grant them requested caps + // and finally start them. + let wasm_path = if wasm_path.starts_with("/") { + wasm_path.clone() + } else { + format!("/{}", wasm_path) + }; + let wasm_path = format!("{}{}", drive_path, wasm_path); + println!("wasm path: {:?}", wasm_path); + // build initial caps + // let mut initial_capabilities: HashSet = HashSet::new(); + // if entry.request_networking { + // initial_capabilities.insert(kt::de_wit_capability(networking_cap.clone())); + // } + // initial_capabilities.insert(kt::de_wit_capability(read_cap.clone())); + // initial_capabilities.insert(kt::de_wit_capability(write_cap.clone())); + let process_id = format!("{}:{}", rand::random::(), package); // all scripts are given random process IDs + let Ok(parsed_new_process_id) = process_id.parse::() else { + return Err(anyhow::anyhow!("app store: invalid process id!")); + }; + + // TODO why is this here? Just to make sure that the file exists? I don't think we need it?? + let _bytes_response = Request::new() + .target(("our", "vfs", "sys", "nectar")) + .body(serde_json::to_vec(&vfs::VfsRequest { + path: wasm_path.clone(), + action: vfs::VfsAction::Read, + })?) + .send_and_await_response(5)??; + // if let Some(to_request) = &entry.request_capabilities { + // for value in to_request { + // let mut capability = None; + // match value { + // serde_json::Value::String(process_name) => { + // if let Ok(parsed_process_id) = process_name.parse::() { + // capability = get_capability( + // &Address { + // node: our.node.clone(), + // process: parsed_process_id.clone(), + // }, + // "\"messaging\"".into(), + // ); + // } + // } + // serde_json::Value::Object(map) => { + // if let Some(process_name) = map.get("process") { + // if let Ok(parsed_process_id) = process_name + // .as_str() + // .unwrap_or_default() + // .parse::() + // { + // if let Some(params) = map.get("params") { + // if params.to_string() == "\"root\"" { + // println!("app-store: app requested root capability, ignoring"); + // continue; + // } + + // capability = get_capability( + // &Address { + // node: our.node.clone(), + // process: parsed_process_id.clone(), + // }, + // ¶ms.to_string(), + // ); + // } + // } + // } + // } + // _ => { + // continue; + // } + // } + // if let Some(cap) = capability { + // initial_capabilities.insert(kt::de_wit_capability(cap)); + // } else { + // println!( + // "app-store: no cap: {}, for {} to request!", + // value.to_string(), + // package + // ); + // } + // } + // } + Request::new() + .target(("our", "kernel", "sys", "nectar")) + .body(serde_json::to_vec(&kt::KernelCommand::InitializeProcess { + id: parsed_new_process_id.clone(), + wasm_bytes_handle: wasm_path, + wit_version: None, + on_exit: kt::OnExit::None, + initial_capabilities: HashSet::new(), // TODO + public: true, // TODO unclear if this should be public or not...definitley gets around grant_caps issues + })?) + .inherit(true) + .send_and_await_response(5)??; + // if let Some(to_grant) = &entry.grant_capabilities { + // for value in to_grant { + // match value { + // serde_json::Value::String(process_name) => { + // if let Ok(parsed_process_id) = process_name.parse::() { + // let _ = Request::new() + // .target(("our", "kernel", "sys", "nectar")) + // .body( + // serde_json::to_vec(&kt::KernelCommand::GrantCapabilities { + // target: parsed_process_id, + // capabilities: vec![kt::Capability { + // issuer: Address { + // node: our.node.clone(), + // process: parsed_new_process_id.clone(), + // }, + // params: "\"messaging\"".into(), + // }], + // }) + // .unwrap(), + // ) + // .send()?; + // } + // } + // serde_json::Value::Object(map) => { + // if let Some(process_name) = map.get("process") { + // if let Ok(parsed_process_id) = process_name + // .as_str() + // .unwrap_or_default() + // .parse::() + // { + // if let Some(params) = map.get("params") { + // let _ = Request::new() + // .target(("our", "kernel", "sys", "nectar")) + // .body( + // serde_json::to_vec(&kt::KernelCommand::GrantCapabilities { + // target: parsed_process_id, + // capabilities: vec![kt::Capability { + // issuer: Address { + // node: our.node.clone(), + // process: parsed_new_process_id.clone(), + // }, + // params: params.to_string(), + // }], + // }) + // .unwrap(), + // ) + // .send()?; + // } + // } + // } + // } + // _ => { + // continue; + // } + // } + // } + // } + Request::new() + .target(("our", "kernel", "sys", "nectar")) + .body(serde_json::to_vec(&kt::KernelCommand::RunProcess( + parsed_new_process_id, + ))?) + .send_and_await_response(5)??; + Ok(()) +} diff --git a/modules/script_runner/test_script/Cargo.lock b/modules/script_runner/test_script/Cargo.lock new file mode 100644 index 00000000..4c5752d9 --- /dev/null +++ b/modules/script_runner/test_script/Cargo.lock @@ -0,0 +1,554 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + +[[package]] +name = "bytes" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "getrandom" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "http" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +dependencies = [ + "equivalent", + "hashbrown", + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + +[[package]] +name = "libc" +version = "0.2.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "nectar_process_lib" +version = "0.5.0" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?tag=v0.5.1-alpha#64d2856412c11c93b5f4e2f6d61b5111fa4bf84c" +dependencies = [ + "anyhow", + "bincode", + "http", + "mime_guess", + "rand", + "serde", + "serde_json", + "thiserror", + "url", + "wit-bindgen", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "ryu" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" + +[[package]] +name = "semver" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" + +[[package]] +name = "serde" +version = "1.0.195" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.195" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "smallvec" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2593d31f82ead8df961d8bd23a64c2ccf2eb5dd34b0a34bfb4dd54011c72009e" + +[[package]] +name = "spdx" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bde1398b09b9f93fc2fc9b9da86e362693e999d3a54a8ac47a99a5a73f638b" +dependencies = [ + "smallvec", +] + +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "test_script" +version = "0.1.0" +dependencies = [ + "anyhow", + "nectar_process_lib", + "serde", + "serde_json", + "wit-bindgen", +] + +[[package]] +name = "thiserror" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-encoder" +version = "0.38.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ad2b51884de9c7f4fe2fd1043fccb8dcad4b1e29558146ee57a144d15779f3f" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-encoder" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "111495d6204760238512f57a9af162f45086504da332af210f2f75dd80b34f1d" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-metadata" +version = "0.10.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "818931c85b1d197909699d36c509fa89550ccfa0d66932ba3c1726faddb4d0c7" +dependencies = [ + "anyhow", + "indexmap", + "serde", + "serde_derive", + "serde_json", + "spdx", + "wasm-encoder 0.39.0", + "wasmparser 0.119.0", +] + +[[package]] +name = "wasmparser" +version = "0.118.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95ee9723b928e735d53000dec9eae7b07a60e490c85ab54abb66659fc61bfcd9" +dependencies = [ + "indexmap", + "semver", +] + +[[package]] +name = "wasmparser" +version = "0.119.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c35daf77afb4f9b14016625144a391085ec2ca99ca9cc53ed291bb53ab5278d" +dependencies = [ + "bitflags", + "indexmap", + "semver", +] + +[[package]] +name = "wit-bindgen" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "bitflags", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "anyhow", + "wit-component", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "anyhow", + "heck", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", + "wit-component", +] + +[[package]] +name = "wit-component" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a35a2a9992898c9d27f1664001860595a4bc99d32dd3599d547412e17d7e2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder 0.38.1", + "wasm-metadata", + "wasmparser 0.118.1", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df4913a2219096373fd6512adead1fb77ecdaa59d7fc517972a7d30b12f625be" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", +] diff --git a/modules/script_runner/test_script/Cargo.toml b/modules/script_runner/test_script/Cargo.toml new file mode 100644 index 00000000..7f8bca0b --- /dev/null +++ b/modules/script_runner/test_script/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "test_script" +version = "0.1.0" +edition = "2021" + +[profile.release] +panic = "abort" +opt-level = "s" +lto = true + +[dependencies] +anyhow = "1.0" +nectar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", tag = "v0.5.1-alpha" } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } + +[lib] +crate-type = ["cdylib"] + +[package.metadata.component] +package = "nectar:process" diff --git a/modules/script_runner/test_script/src/lib.rs b/modules/script_runner/test_script/src/lib.rs new file mode 100644 index 00000000..86cc7e00 --- /dev/null +++ b/modules/script_runner/test_script/src/lib.rs @@ -0,0 +1,15 @@ +use nectar_process_lib::{await_message, call_init, println, Address, Request}; + +wit_bindgen::generate!({ + path: "wit", + world: "process", + exports: { + world: Component, + }, +}); + +call_init!(init); + +fn init(our: Address) { + println!("{}: this is a dummy script!", our); +} From 27ff968fc1dec13b39d28bf7645d6641e1ef65e5 Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Tue, 16 Jan 2024 16:24:35 -0600 Subject: [PATCH 03/21] renaming --- .../{script_runner => script}/pkg/manifest.json | 4 ++-- .../{script_runner => script}/pkg/metadata.json | 2 +- .../script_runner => script/runner}/Cargo.lock | 14 +++++++------- .../script_runner => script/runner}/Cargo.toml | 2 +- .../script_runner => script/runner}/src/lib.rs | 0 .../test_script/Cargo.lock | 0 .../test_script/Cargo.toml | 0 .../test_script/src/lib.rs | 0 8 files changed, 11 insertions(+), 11 deletions(-) rename modules/{script_runner => script}/pkg/manifest.json (82%) rename modules/{script_runner => script}/pkg/metadata.json (72%) rename modules/{script_runner/script_runner => script/runner}/Cargo.lock (99%) rename modules/{script_runner/script_runner => script/runner}/Cargo.toml (95%) rename modules/{script_runner/script_runner => script/runner}/src/lib.rs (100%) rename modules/{script_runner => script}/test_script/Cargo.lock (100%) rename modules/{script_runner => script}/test_script/Cargo.toml (100%) rename modules/{script_runner => script}/test_script/src/lib.rs (100%) diff --git a/modules/script_runner/pkg/manifest.json b/modules/script/pkg/manifest.json similarity index 82% rename from modules/script_runner/pkg/manifest.json rename to modules/script/pkg/manifest.json index 4011c479..412ca946 100644 --- a/modules/script_runner/pkg/manifest.json +++ b/modules/script/pkg/manifest.json @@ -1,7 +1,7 @@ [ { - "process_name": "script_runner", - "process_wasm_path": "/script_runner.wasm", + "process_name": "runner", + "process_wasm_path": "/runner.wasm", "on_exit": "Restart", "request_networking": false, "request_capabilities": [ diff --git a/modules/script_runner/pkg/metadata.json b/modules/script/pkg/metadata.json similarity index 72% rename from modules/script_runner/pkg/metadata.json rename to modules/script/pkg/metadata.json index d5f37684..c972802e 100644 --- a/modules/script_runner/pkg/metadata.json +++ b/modules/script/pkg/metadata.json @@ -1,5 +1,5 @@ { - "package": "script_runner", + "package": "script", "publisher": "nectar", "version": [ 0, diff --git a/modules/script_runner/script_runner/Cargo.lock b/modules/script/runner/Cargo.lock similarity index 99% rename from modules/script_runner/script_runner/Cargo.lock rename to modules/script/runner/Cargo.lock index bd2b79c2..241ea8bc 100644 --- a/modules/script_runner/script_runner/Cargo.lock +++ b/modules/script/runner/Cargo.lock @@ -238,13 +238,7 @@ dependencies = [ ] [[package]] -name = "ryu" -version = "1.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" - -[[package]] -name = "script_runner" +name = "runner" version = "0.1.0" dependencies = [ "anyhow", @@ -256,6 +250,12 @@ dependencies = [ "wit-bindgen", ] +[[package]] +name = "ryu" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" + [[package]] name = "semver" version = "1.0.21" diff --git a/modules/script_runner/script_runner/Cargo.toml b/modules/script/runner/Cargo.toml similarity index 95% rename from modules/script_runner/script_runner/Cargo.toml rename to modules/script/runner/Cargo.toml index a71b7dfa..de948b7e 100644 --- a/modules/script_runner/script_runner/Cargo.toml +++ b/modules/script/runner/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "script_runner" +name = "runner" version = "0.1.0" edition = "2021" diff --git a/modules/script_runner/script_runner/src/lib.rs b/modules/script/runner/src/lib.rs similarity index 100% rename from modules/script_runner/script_runner/src/lib.rs rename to modules/script/runner/src/lib.rs diff --git a/modules/script_runner/test_script/Cargo.lock b/modules/script/test_script/Cargo.lock similarity index 100% rename from modules/script_runner/test_script/Cargo.lock rename to modules/script/test_script/Cargo.lock diff --git a/modules/script_runner/test_script/Cargo.toml b/modules/script/test_script/Cargo.toml similarity index 100% rename from modules/script_runner/test_script/Cargo.toml rename to modules/script/test_script/Cargo.toml diff --git a/modules/script_runner/test_script/src/lib.rs b/modules/script/test_script/src/lib.rs similarity index 100% rename from modules/script_runner/test_script/src/lib.rs rename to modules/script/test_script/src/lib.rs From 5d74293678f19264b372e7d4c47c529d02b4464c Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Tue, 16 Jan 2024 16:37:49 -0600 Subject: [PATCH 04/21] args working --- modules/script/runner/src/lib.rs | 8 ++++++-- modules/script/test_script/src/lib.rs | 10 +++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/modules/script/runner/src/lib.rs b/modules/script/runner/src/lib.rs index 593a3a10..a2c54517 100644 --- a/modules/script/runner/src/lib.rs +++ b/modules/script/runner/src/lib.rs @@ -272,11 +272,15 @@ fn handle_run( // } // } // } - Request::new() + let _ = Request::new() .target(("our", "kernel", "sys", "nectar")) .body(serde_json::to_vec(&kt::KernelCommand::RunProcess( - parsed_new_process_id, + parsed_new_process_id.clone(), ))?) .send_and_await_response(5)??; + let _ = Request::new() + .target(("our", parsed_new_process_id)) + .body(args.into_bytes()) + .send(); Ok(()) } diff --git a/modules/script/test_script/src/lib.rs b/modules/script/test_script/src/lib.rs index 86cc7e00..da4ea456 100644 --- a/modules/script/test_script/src/lib.rs +++ b/modules/script/test_script/src/lib.rs @@ -1,4 +1,4 @@ -use nectar_process_lib::{await_message, call_init, println, Address, Request}; +use nectar_process_lib::{await_message, call_init, println, Address, Message, Request}; wit_bindgen::generate!({ path: "wit", @@ -12,4 +12,12 @@ call_init!(init); fn init(our: Address) { println!("{}: this is a dummy script!", our); + + // TODO will need to package this up into a process lib function that makes it easy + let Ok(Message::Request { body, .. }) = await_message() else { + println!("got send error, failing out"); + return; + }; + + println!("here are the args: {:?}", String::from_utf8(body)); } From e2132073f1ce3292f4104e1b7b739d385ffe0bf1 Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Tue, 16 Jan 2024 16:56:20 -0600 Subject: [PATCH 05/21] /run command added --- modules/terminal/terminal/src/lib.rs | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/modules/terminal/terminal/src/lib.rs b/modules/terminal/terminal/src/lib.rs index 72290e8b..4f0462d7 100644 --- a/modules/terminal/terminal/src/lib.rs +++ b/modules/terminal/terminal/src/lib.rs @@ -2,6 +2,7 @@ use anyhow::anyhow; use nectar_process_lib::kernel_types::{KernelCommand, KernelPrint}; use nectar_process_lib::nectar::process::standard as wit; use nectar_process_lib::{println, Address, ProcessId, Request}; +use serde_json::json; wit_bindgen::generate!({ path: "../../../wit", @@ -91,6 +92,36 @@ fn parse_command(state: &mut TerminalState, line: &str) -> anyhow::Result<()> { .send(), } } + "/run" => { + let (process, args) = match tail.split_once(" ") { + Some((p, a)) => ( + match p.parse::() { + Ok(p) => p, + Err(_) => return Err(anyhow!("invalid process id: \"{tail}\"")), + }, + a, + ), + None => return Err(anyhow!("invalid command: \"{line}\"")), + }; + Request::new() + .target(Address::new("our", ("runner", "script", "nectar"))) + .body( + json!({ + "Run": { + // TODO we should add a package_id() method to ProcessId that will get this for you + "package": { + "package_name": process.package(), + "publisher_node": process.publisher(), + }, + "wasm_path": format!("{}.wasm", process.process()), + "args": args + } + }) + .to_string() + .into_bytes(), + ) + .send() + } _ => return Err(anyhow!("invalid command: \"{line}\"")), } } From 8e683a4992acf09a3a5ffad12578e0f97d53edd7 Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Tue, 16 Jan 2024 17:28:34 -0600 Subject: [PATCH 06/21] echo and cat added --- .../script/{test_script => cat}/Cargo.lock | 22 +- .../script/{test_script => cat}/Cargo.toml | 2 +- modules/script/cat/src/lib.rs | 47 ++ modules/script/echo/Cargo.lock | 554 ++++++++++++++++++ modules/script/echo/Cargo.toml | 22 + .../script/{test_script => echo}/src/lib.rs | 0 modules/terminal/terminal/src/lib.rs | 2 +- 7 files changed, 636 insertions(+), 13 deletions(-) rename modules/script/{test_script => cat}/Cargo.lock (99%) rename modules/script/{test_script => cat}/Cargo.toml (95%) create mode 100644 modules/script/cat/src/lib.rs create mode 100644 modules/script/echo/Cargo.lock create mode 100644 modules/script/echo/Cargo.toml rename modules/script/{test_script => echo}/src/lib.rs (100%) diff --git a/modules/script/test_script/Cargo.lock b/modules/script/cat/Cargo.lock similarity index 99% rename from modules/script/test_script/Cargo.lock rename to modules/script/cat/Cargo.lock index 4c5752d9..84da7026 100644 --- a/modules/script/test_script/Cargo.lock +++ b/modules/script/cat/Cargo.lock @@ -29,6 +29,17 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +[[package]] +name = "cat" +version = "0.1.0" +dependencies = [ + "anyhow", + "nectar_process_lib", + "serde", + "serde_json", + "wit-bindgen", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -306,17 +317,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "test_script" -version = "0.1.0" -dependencies = [ - "anyhow", - "nectar_process_lib", - "serde", - "serde_json", - "wit-bindgen", -] - [[package]] name = "thiserror" version = "1.0.56" diff --git a/modules/script/test_script/Cargo.toml b/modules/script/cat/Cargo.toml similarity index 95% rename from modules/script/test_script/Cargo.toml rename to modules/script/cat/Cargo.toml index 7f8bca0b..51b28a1a 100644 --- a/modules/script/test_script/Cargo.toml +++ b/modules/script/cat/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "test_script" +name = "cat" version = "0.1.0" edition = "2021" diff --git a/modules/script/cat/src/lib.rs b/modules/script/cat/src/lib.rs new file mode 100644 index 00000000..09991625 --- /dev/null +++ b/modules/script/cat/src/lib.rs @@ -0,0 +1,47 @@ +use nectar_process_lib::{ + await_message, call_init, get_blob, println, vfs, Address, Message, Request, +}; + +wit_bindgen::generate!({ + path: "wit", + world: "process", + exports: { + world: Component, + }, +}); + +call_init!(init); + +fn init(_our: Address) { + // TODO will need to package this up into a process lib function that makes it easy + let Ok(Message::Request { body, .. }) = await_message() else { + println!("got send error, failing out"); + return; + }; + + let Ok(file_path) = String::from_utf8(body) else { + println!("bad file path"); + return; + }; + + Request::new() + .target(("our", "vfs", "sys", "nectar")) + .body( + serde_json::to_vec(&vfs::VfsRequest { + path: file_path.clone(), + action: vfs::VfsAction::Read, + }) + .unwrap(), + ) + .send_and_await_response(5) + .unwrap() + .unwrap(); + let Some(blob) = get_blob() else { + println!("no file found at {}", file_path); + return; + }; + println!( + "{}", + String::from_utf8(blob.bytes).unwrap_or("could not stringify file".to_string()) + ); +} diff --git a/modules/script/echo/Cargo.lock b/modules/script/echo/Cargo.lock new file mode 100644 index 00000000..c6de04c8 --- /dev/null +++ b/modules/script/echo/Cargo.lock @@ -0,0 +1,554 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + +[[package]] +name = "bytes" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "echo" +version = "0.1.0" +dependencies = [ + "anyhow", + "nectar_process_lib", + "serde", + "serde_json", + "wit-bindgen", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "getrandom" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "http" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +dependencies = [ + "equivalent", + "hashbrown", + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + +[[package]] +name = "libc" +version = "0.2.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "nectar_process_lib" +version = "0.5.0" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?tag=v0.5.1-alpha#64d2856412c11c93b5f4e2f6d61b5111fa4bf84c" +dependencies = [ + "anyhow", + "bincode", + "http", + "mime_guess", + "rand", + "serde", + "serde_json", + "thiserror", + "url", + "wit-bindgen", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "ryu" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" + +[[package]] +name = "semver" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" + +[[package]] +name = "serde" +version = "1.0.195" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.195" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "smallvec" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2593d31f82ead8df961d8bd23a64c2ccf2eb5dd34b0a34bfb4dd54011c72009e" + +[[package]] +name = "spdx" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bde1398b09b9f93fc2fc9b9da86e362693e999d3a54a8ac47a99a5a73f638b" +dependencies = [ + "smallvec", +] + +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-encoder" +version = "0.38.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ad2b51884de9c7f4fe2fd1043fccb8dcad4b1e29558146ee57a144d15779f3f" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-encoder" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "111495d6204760238512f57a9af162f45086504da332af210f2f75dd80b34f1d" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-metadata" +version = "0.10.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "818931c85b1d197909699d36c509fa89550ccfa0d66932ba3c1726faddb4d0c7" +dependencies = [ + "anyhow", + "indexmap", + "serde", + "serde_derive", + "serde_json", + "spdx", + "wasm-encoder 0.39.0", + "wasmparser 0.119.0", +] + +[[package]] +name = "wasmparser" +version = "0.118.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95ee9723b928e735d53000dec9eae7b07a60e490c85ab54abb66659fc61bfcd9" +dependencies = [ + "indexmap", + "semver", +] + +[[package]] +name = "wasmparser" +version = "0.119.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c35daf77afb4f9b14016625144a391085ec2ca99ca9cc53ed291bb53ab5278d" +dependencies = [ + "bitflags", + "indexmap", + "semver", +] + +[[package]] +name = "wit-bindgen" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "bitflags", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "anyhow", + "wit-component", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "anyhow", + "heck", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", + "wit-component", +] + +[[package]] +name = "wit-component" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a35a2a9992898c9d27f1664001860595a4bc99d32dd3599d547412e17d7e2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder 0.38.1", + "wasm-metadata", + "wasmparser 0.118.1", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df4913a2219096373fd6512adead1fb77ecdaa59d7fc517972a7d30b12f625be" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", +] diff --git a/modules/script/echo/Cargo.toml b/modules/script/echo/Cargo.toml new file mode 100644 index 00000000..44a61485 --- /dev/null +++ b/modules/script/echo/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "echo" +version = "0.1.0" +edition = "2021" + +[profile.release] +panic = "abort" +opt-level = "s" +lto = true + +[dependencies] +anyhow = "1.0" +nectar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", tag = "v0.5.1-alpha" } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } + +[lib] +crate-type = ["cdylib"] + +[package.metadata.component] +package = "nectar:process" diff --git a/modules/script/test_script/src/lib.rs b/modules/script/echo/src/lib.rs similarity index 100% rename from modules/script/test_script/src/lib.rs rename to modules/script/echo/src/lib.rs diff --git a/modules/terminal/terminal/src/lib.rs b/modules/terminal/terminal/src/lib.rs index 4f0462d7..bab30f12 100644 --- a/modules/terminal/terminal/src/lib.rs +++ b/modules/terminal/terminal/src/lib.rs @@ -92,7 +92,7 @@ fn parse_command(state: &mut TerminalState, line: &str) -> anyhow::Result<()> { .send(), } } - "/run" => { + "/script" | "/s" => { let (process, args) = match tail.split_once(" ") { Some((p, a)) => ( match p.parse::() { From a5fe97f0a9ea594141ee01fd8617e7d4eab90141 Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Wed, 17 Jan 2024 22:21:34 -0600 Subject: [PATCH 07/21] capabilities for scripts worked out --- modules/app_store/app_store/src/lib.rs | 29 +-- modules/script/cat/Cargo.lock | 36 +-- modules/script/cat/Cargo.toml | 4 +- modules/script/cat/src/lib.rs | 6 +- modules/script/echo/Cargo.lock | 36 +-- modules/script/echo/Cargo.toml | 4 +- modules/script/echo/src/lib.rs | 2 +- modules/script/pkg/manifest.json | 8 +- modules/script/pkg/metadata.json | 2 +- modules/script/pkg/scripts.json | 14 ++ modules/script/runner/Cargo.lock | 36 +-- modules/script/runner/Cargo.toml | 4 +- modules/script/runner/src/lib.rs | 318 ++++++++++++------------- modules/terminal/terminal/src/lib.rs | 2 +- 14 files changed, 242 insertions(+), 259 deletions(-) create mode 100644 modules/script/pkg/scripts.json diff --git a/modules/app_store/app_store/src/lib.rs b/modules/app_store/app_store/src/lib.rs index e720c2c7..bf194aa6 100644 --- a/modules/app_store/app_store/src/lib.rs +++ b/modules/app_store/app_store/src/lib.rs @@ -521,13 +521,6 @@ fn handle_install(our: &Address, package: &PackageId) -> anyhow::Result<()> { .parse::() { if let Some(params) = map.get("params") { - if params.to_string() == "\"root\"" { - println!( - "app-store: app requested root capability, ignoring" - ); - continue; - } - capability = get_capability( &Address { node: our.node.clone(), @@ -598,18 +591,16 @@ fn handle_install(our: &Address, package: &PackageId) -> anyhow::Result<()> { let _ = Request::new() .target(("our", "kernel", "distro", "sys")) .body( - serde_json::to_vec( - &kt::KernelCommand::GrantCapabilities { - target: parsed_process_id, - capabilities: vec![kt::Capability { - issuer: Address { - node: our.node.clone(), - process: parsed_new_process_id.clone(), - }, - params: params.to_string(), - }], - }, - ) + serde_json::to_vec(&kt::KernelCommand::GrantCapabilities { + target: parsed_process_id, + capabilities: vec![kt::Capability { + issuer: Address { + node: our.node.clone(), + process: parsed_new_process_id.clone(), + }, + params: params.to_string(), + }], + }) .unwrap(), ) .send()?; diff --git a/modules/script/cat/Cargo.lock b/modules/script/cat/Cargo.lock index 84da7026..15ab7395 100644 --- a/modules/script/cat/Cargo.lock +++ b/modules/script/cat/Cargo.lock @@ -34,7 +34,7 @@ name = "cat" version = "0.1.0" dependencies = [ "anyhow", - "nectar_process_lib", + "kinode_process_lib", "serde", "serde_json", "wit-bindgen", @@ -137,6 +137,23 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +[[package]] +name = "kinode_process_lib" +version = "0.5.0" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=9790c0f#9790c0fecc64572d1fbeecdf3724eb37b3d6d3fa" +dependencies = [ + "anyhow", + "bincode", + "http", + "mime_guess", + "rand", + "serde", + "serde_json", + "thiserror", + "url", + "wit-bindgen", +] + [[package]] name = "leb128" version = "0.2.5" @@ -171,23 +188,6 @@ dependencies = [ "unicase", ] -[[package]] -name = "nectar_process_lib" -version = "0.5.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?tag=v0.5.1-alpha#64d2856412c11c93b5f4e2f6d61b5111fa4bf84c" -dependencies = [ - "anyhow", - "bincode", - "http", - "mime_guess", - "rand", - "serde", - "serde_json", - "thiserror", - "url", - "wit-bindgen", -] - [[package]] name = "percent-encoding" version = "2.3.1" diff --git a/modules/script/cat/Cargo.toml b/modules/script/cat/Cargo.toml index 51b28a1a..7586ced2 100644 --- a/modules/script/cat/Cargo.toml +++ b/modules/script/cat/Cargo.toml @@ -10,7 +10,7 @@ lto = true [dependencies] anyhow = "1.0" -nectar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", tag = "v0.5.1-alpha" } +kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "9790c0f" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } @@ -19,4 +19,4 @@ wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = " crate-type = ["cdylib"] [package.metadata.component] -package = "nectar:process" +package = "kinode:process" diff --git a/modules/script/cat/src/lib.rs b/modules/script/cat/src/lib.rs index 09991625..d189c074 100644 --- a/modules/script/cat/src/lib.rs +++ b/modules/script/cat/src/lib.rs @@ -1,5 +1,5 @@ -use nectar_process_lib::{ - await_message, call_init, get_blob, println, vfs, Address, Message, Request, +use kinode_process_lib::{ + await_message, call_init, get_blob, println, vfs, Address, Capability, Message, Request, }; wit_bindgen::generate!({ @@ -25,7 +25,7 @@ fn init(_our: Address) { }; Request::new() - .target(("our", "vfs", "sys", "nectar")) + .target(("our", "vfs", "sys", "kinode")) .body( serde_json::to_vec(&vfs::VfsRequest { path: file_path.clone(), diff --git a/modules/script/echo/Cargo.lock b/modules/script/echo/Cargo.lock index c6de04c8..03cabc96 100644 --- a/modules/script/echo/Cargo.lock +++ b/modules/script/echo/Cargo.lock @@ -40,7 +40,7 @@ name = "echo" version = "0.1.0" dependencies = [ "anyhow", - "nectar_process_lib", + "kinode_process_lib", "serde", "serde_json", "wit-bindgen", @@ -137,6 +137,23 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +[[package]] +name = "kinode_process_lib" +version = "0.5.0" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=9790c0f#9790c0fecc64572d1fbeecdf3724eb37b3d6d3fa" +dependencies = [ + "anyhow", + "bincode", + "http", + "mime_guess", + "rand", + "serde", + "serde_json", + "thiserror", + "url", + "wit-bindgen", +] + [[package]] name = "leb128" version = "0.2.5" @@ -171,23 +188,6 @@ dependencies = [ "unicase", ] -[[package]] -name = "nectar_process_lib" -version = "0.5.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?tag=v0.5.1-alpha#64d2856412c11c93b5f4e2f6d61b5111fa4bf84c" -dependencies = [ - "anyhow", - "bincode", - "http", - "mime_guess", - "rand", - "serde", - "serde_json", - "thiserror", - "url", - "wit-bindgen", -] - [[package]] name = "percent-encoding" version = "2.3.1" diff --git a/modules/script/echo/Cargo.toml b/modules/script/echo/Cargo.toml index 44a61485..ca8a4c0c 100644 --- a/modules/script/echo/Cargo.toml +++ b/modules/script/echo/Cargo.toml @@ -10,7 +10,7 @@ lto = true [dependencies] anyhow = "1.0" -nectar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", tag = "v0.5.1-alpha" } +kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "9790c0f" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } @@ -19,4 +19,4 @@ wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = " crate-type = ["cdylib"] [package.metadata.component] -package = "nectar:process" +package = "kinode:process" diff --git a/modules/script/echo/src/lib.rs b/modules/script/echo/src/lib.rs index da4ea456..ee5d5b62 100644 --- a/modules/script/echo/src/lib.rs +++ b/modules/script/echo/src/lib.rs @@ -1,4 +1,4 @@ -use nectar_process_lib::{await_message, call_init, println, Address, Message, Request}; +use kinode_process_lib::{await_message, call_init, println, Address, Message, Request}; wit_bindgen::generate!({ path: "wit", diff --git a/modules/script/pkg/manifest.json b/modules/script/pkg/manifest.json index 412ca946..b0b98cb5 100644 --- a/modules/script/pkg/manifest.json +++ b/modules/script/pkg/manifest.json @@ -5,11 +5,11 @@ "on_exit": "Restart", "request_networking": false, "request_capabilities": [ - "filesystem:sys:nectar", - "vfs:sys:nectar", - "kernel:sys:nectar", + "filesystem:distro:sys", + "vfs:distro:sys", + "kernel:distro:sys", { - "process": "vfs:sys:nectar", + "process": "vfs:distro:sys", "params": { "root": true } diff --git a/modules/script/pkg/metadata.json b/modules/script/pkg/metadata.json index c972802e..b22ce780 100644 --- a/modules/script/pkg/metadata.json +++ b/modules/script/pkg/metadata.json @@ -1,6 +1,6 @@ { "package": "script", - "publisher": "nectar", + "publisher": "sys", "version": [ 0, 1, diff --git a/modules/script/pkg/scripts.json b/modules/script/pkg/scripts.json new file mode 100644 index 00000000..89684954 --- /dev/null +++ b/modules/script/pkg/scripts.json @@ -0,0 +1,14 @@ +{ + "echo": { + "public": false, + "requestNetworking": false, + "requestCapabilities": [], + "grantCapabilities": [] + }, + "cat": { + "public": false, + "requestNetworking": false, + "requestCapabilities": [], + "grantCapabilities": [] + } +} \ No newline at end of file diff --git a/modules/script/runner/Cargo.lock b/modules/script/runner/Cargo.lock index 241ea8bc..715d2408 100644 --- a/modules/script/runner/Cargo.lock +++ b/modules/script/runner/Cargo.lock @@ -126,6 +126,23 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +[[package]] +name = "kinode_process_lib" +version = "0.5.0" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=9790c0f#9790c0fecc64572d1fbeecdf3724eb37b3d6d3fa" +dependencies = [ + "anyhow", + "bincode", + "http", + "mime_guess", + "rand", + "serde", + "serde_json", + "thiserror", + "url", + "wit-bindgen", +] + [[package]] name = "leb128" version = "0.2.5" @@ -160,23 +177,6 @@ dependencies = [ "unicase", ] -[[package]] -name = "nectar_process_lib" -version = "0.5.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?tag=v0.5.1-alpha#64d2856412c11c93b5f4e2f6d61b5111fa4bf84c" -dependencies = [ - "anyhow", - "bincode", - "http", - "mime_guess", - "rand", - "serde", - "serde_json", - "thiserror", - "url", - "wit-bindgen", -] - [[package]] name = "percent-encoding" version = "2.3.1" @@ -243,7 +243,7 @@ version = "0.1.0" dependencies = [ "anyhow", "bincode", - "nectar_process_lib", + "kinode_process_lib", "rand", "serde", "serde_json", diff --git a/modules/script/runner/Cargo.toml b/modules/script/runner/Cargo.toml index de948b7e..8118b268 100644 --- a/modules/script/runner/Cargo.toml +++ b/modules/script/runner/Cargo.toml @@ -11,7 +11,7 @@ lto = true [dependencies] anyhow = "1.0" bincode = "1.3.3" -nectar_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", tag = "v0.5.1-alpha" } +kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "9790c0f" } rand = "0.8" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" @@ -21,4 +21,4 @@ wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = " crate-type = ["cdylib"] [package.metadata.component] -package = "nectar:process" +package = "kinode:process" diff --git a/modules/script/runner/src/lib.rs b/modules/script/runner/src/lib.rs index a2c54517..1cee52df 100644 --- a/modules/script/runner/src/lib.rs +++ b/modules/script/runner/src/lib.rs @@ -1,13 +1,22 @@ -use nectar_process_lib::kernel_types as kt; -use nectar_process_lib::*; +use kinode_process_lib::kernel_types as kt; +use kinode_process_lib::*; use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; -use std::str::FromStr; -use nectar_process_lib::{ - await_message, call_init, println, Address, Message, ProcessId, Request, Response, +use kinode_process_lib::{ + await_message, call_init, println, Address, Capability, Message, ProcessId, Request, Response, }; +// TODO move this into kt:: +#[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct DotScriptsEntry { + pub public: bool, + pub request_networking: bool, + pub request_capabilities: Option>, + pub grant_capabilities: Option>, +} + wit_bindgen::generate!({ path: "wit", world: "process", @@ -82,198 +91,167 @@ fn handle_run( args: String, ) -> anyhow::Result<()> { let drive_path = format!("/{}/pkg", package); - // Request::new() - // .target(("our", "vfs", "sys", "nectar")) - // .body(serde_json::to_vec(&vfs::VfsRequest { - // path: format!("{}/manifest.json", drive_path), - // action: vfs::VfsAction::Read, - // })?) - // .send_and_await_response(5)??; - // let Some(blob) = get_blob() else { - // return Err(anyhow::anyhow!("no blob")); - // }; - // let manifest = String::from_utf8(blob.bytes)?; - // let manifest = serde_json::from_str::>(&manifest)?; - // // always grant read/write to their drive, which we created for them - // let Some(read_cap) = get_capability( - // &Address::new(&our.node, ("vfs", "sys", "nectar")), - // &serde_json::to_string(&serde_json::json!({ - // "kind": "read", - // "drive": drive_path, - // }))?, - // ) else { - // return Err(anyhow::anyhow!("app store: no read cap")); - // }; - // let Some(write_cap) = get_capability( - // &Address::new(&our.node, ("vfs", "sys", "nectar")), - // &serde_json::to_string(&serde_json::json!({ - // "kind": "write", - // "drive": drive_path, - // }))?, - // ) else { - // return Err(anyhow::anyhow!("app store: no write cap")); - // }; - // let Some(networking_cap) = get_capability( - // &Address::new(&our.node, ("kernel", "sys", "nectar")), - // &"\"network\"".to_string(), - // ) else { - // return Err(anyhow::anyhow!("app store: no net cap")); - // }; - // first, for each process in manifest, initialize it - // then, once all have been initialized, grant them requested caps - // and finally start them. + Request::new() + .target(("our", "vfs", "sys", "kinode")) + .body(serde_json::to_vec(&vfs::VfsRequest { + path: format!("{}/scripts.json", drive_path), + action: vfs::VfsAction::Read, + })?) + .send_and_await_response(5)??; + let Some(blob) = get_blob() else { + return Err(anyhow::anyhow!("no blob")); + }; + let dot_scripts = String::from_utf8(blob.bytes)?; + let dot_scripts = serde_json::from_str::>(&dot_scripts)?; + let Some(entry) = dot_scripts.get(&wasm_path) else { + return Err(anyhow::anyhow!("script not in scripts.json file")); + }; let wasm_path = if wasm_path.starts_with("/") { wasm_path.clone() } else { format!("/{}", wasm_path) }; let wasm_path = format!("{}{}", drive_path, wasm_path); - println!("wasm path: {:?}", wasm_path); // build initial caps - // let mut initial_capabilities: HashSet = HashSet::new(); - // if entry.request_networking { - // initial_capabilities.insert(kt::de_wit_capability(networking_cap.clone())); - // } - // initial_capabilities.insert(kt::de_wit_capability(read_cap.clone())); - // initial_capabilities.insert(kt::de_wit_capability(write_cap.clone())); + let mut initial_capabilities: HashSet = HashSet::new(); + if entry.request_networking { + initial_capabilities.insert(kt::de_wit_capability(Capability { + issuer: Address::new(&our.node, ("kernel", "sys", "kinode")), + params: "\"network\"".to_string(), + })); + } let process_id = format!("{}:{}", rand::random::(), package); // all scripts are given random process IDs let Ok(parsed_new_process_id) = process_id.parse::() else { return Err(anyhow::anyhow!("app store: invalid process id!")); }; - // TODO why is this here? Just to make sure that the file exists? I don't think we need it?? let _bytes_response = Request::new() - .target(("our", "vfs", "sys", "nectar")) + .target(("our", "vfs", "sys", "kinode")) .body(serde_json::to_vec(&vfs::VfsRequest { path: wasm_path.clone(), action: vfs::VfsAction::Read, })?) .send_and_await_response(5)??; - // if let Some(to_request) = &entry.request_capabilities { - // for value in to_request { - // let mut capability = None; - // match value { - // serde_json::Value::String(process_name) => { - // if let Ok(parsed_process_id) = process_name.parse::() { - // capability = get_capability( - // &Address { - // node: our.node.clone(), - // process: parsed_process_id.clone(), - // }, - // "\"messaging\"".into(), - // ); - // } - // } - // serde_json::Value::Object(map) => { - // if let Some(process_name) = map.get("process") { - // if let Ok(parsed_process_id) = process_name - // .as_str() - // .unwrap_or_default() - // .parse::() - // { - // if let Some(params) = map.get("params") { - // if params.to_string() == "\"root\"" { - // println!("app-store: app requested root capability, ignoring"); - // continue; - // } - - // capability = get_capability( - // &Address { - // node: our.node.clone(), - // process: parsed_process_id.clone(), - // }, - // ¶ms.to_string(), - // ); - // } - // } - // } - // } - // _ => { - // continue; - // } - // } - // if let Some(cap) = capability { - // initial_capabilities.insert(kt::de_wit_capability(cap)); - // } else { - // println!( - // "app-store: no cap: {}, for {} to request!", - // value.to_string(), - // package - // ); - // } - // } - // } + if let Some(to_request) = &entry.request_capabilities { + for value in to_request { + let mut capability = None; + match value { + serde_json::Value::String(process_name) => { + if let Ok(parsed_process_id) = process_name.parse::() { + capability = get_capability( + &Address { + node: our.node.clone(), + process: parsed_process_id.clone(), + }, + "\"messaging\"".into(), + ); + } + } + serde_json::Value::Object(map) => { + if let Some(process_name) = map.get("process") { + if let Ok(parsed_process_id) = process_name + .as_str() + .unwrap_or_default() + .parse::() + { + if let Some(params) = map.get("params") { + capability = get_capability( + &Address { + node: our.node.clone(), + process: parsed_process_id.clone(), + }, + ¶ms.to_string(), + ); + } + } + } + } + _ => { + continue; + } + } + if let Some(cap) = capability { + initial_capabilities.insert(kt::de_wit_capability(cap)); + } else { + println!( + "runner: no cap: {}, for {} to request!", + value.to_string(), + package + ); + } + } + } Request::new() - .target(("our", "kernel", "sys", "nectar")) + .target(("our", "kernel", "sys", "kinode")) .body(serde_json::to_vec(&kt::KernelCommand::InitializeProcess { id: parsed_new_process_id.clone(), wasm_bytes_handle: wasm_path, wit_version: None, - on_exit: kt::OnExit::None, - initial_capabilities: HashSet::new(), // TODO - public: true, // TODO unclear if this should be public or not...definitley gets around grant_caps issues + on_exit: kt::OnExit::None, // TODO this should send a message back to runner:script:sys so that it can Drop capabilities + initial_capabilities, + public: entry.public, })?) .inherit(true) .send_and_await_response(5)??; - // if let Some(to_grant) = &entry.grant_capabilities { - // for value in to_grant { - // match value { - // serde_json::Value::String(process_name) => { - // if let Ok(parsed_process_id) = process_name.parse::() { - // let _ = Request::new() - // .target(("our", "kernel", "sys", "nectar")) - // .body( - // serde_json::to_vec(&kt::KernelCommand::GrantCapabilities { - // target: parsed_process_id, - // capabilities: vec![kt::Capability { - // issuer: Address { - // node: our.node.clone(), - // process: parsed_new_process_id.clone(), - // }, - // params: "\"messaging\"".into(), - // }], - // }) - // .unwrap(), - // ) - // .send()?; - // } - // } - // serde_json::Value::Object(map) => { - // if let Some(process_name) = map.get("process") { - // if let Ok(parsed_process_id) = process_name - // .as_str() - // .unwrap_or_default() - // .parse::() - // { - // if let Some(params) = map.get("params") { - // let _ = Request::new() - // .target(("our", "kernel", "sys", "nectar")) - // .body( - // serde_json::to_vec(&kt::KernelCommand::GrantCapabilities { - // target: parsed_process_id, - // capabilities: vec![kt::Capability { - // issuer: Address { - // node: our.node.clone(), - // process: parsed_new_process_id.clone(), - // }, - // params: params.to_string(), - // }], - // }) - // .unwrap(), - // ) - // .send()?; - // } - // } - // } - // } - // _ => { - // continue; - // } - // } - // } - // } + if let Some(to_grant) = &entry.grant_capabilities { + for value in to_grant { + match value { + serde_json::Value::String(process_name) => { + if let Ok(parsed_process_id) = process_name.parse::() { + let _ = Request::new() + .target(("our", "kernel", "sys", "kinode")) + .body( + serde_json::to_vec(&kt::KernelCommand::GrantCapabilities { + target: parsed_process_id, + capabilities: vec![kt::Capability { + issuer: Address { + node: our.node.clone(), + process: parsed_new_process_id.clone(), + }, + params: "\"messaging\"".into(), + }], + }) + .unwrap(), + ) + .send()?; + } + } + serde_json::Value::Object(map) => { + if let Some(process_name) = map.get("process") { + if let Ok(parsed_process_id) = process_name + .as_str() + .unwrap_or_default() + .parse::() + { + if let Some(params) = map.get("params") { + let _ = Request::new() + .target(("our", "kernel", "sys", "kinode")) + .body( + serde_json::to_vec(&kt::KernelCommand::GrantCapabilities { + target: parsed_process_id, + capabilities: vec![kt::Capability { + issuer: Address { + node: our.node.clone(), + process: parsed_new_process_id.clone(), + }, + params: params.to_string(), + }], + }) + .unwrap(), + ) + .send()?; + } + } + } + } + _ => { + continue; + } + } + } + } let _ = Request::new() - .target(("our", "kernel", "sys", "nectar")) + .target(("our", "kernel", "sys", "kinode")) .body(serde_json::to_vec(&kt::KernelCommand::RunProcess( parsed_new_process_id.clone(), ))?) diff --git a/modules/terminal/terminal/src/lib.rs b/modules/terminal/terminal/src/lib.rs index 6204c05c..5f682209 100644 --- a/modules/terminal/terminal/src/lib.rs +++ b/modules/terminal/terminal/src/lib.rs @@ -104,7 +104,7 @@ fn parse_command(state: &mut TerminalState, line: &str) -> anyhow::Result<()> { None => return Err(anyhow!("invalid command: \"{line}\"")), }; Request::new() - .target(Address::new("our", ("runner", "script", "nectar"))) + .target(Address::new("our", ("runner", "script", "sys"))) .body( json!({ "Run": { From ed41ea942d6fa7ae0b7d7e75a52a37e6ac9dccbb Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Thu, 18 Jan 2024 12:51:36 -0600 Subject: [PATCH 08/21] caps working, cat working --- modules/script/cat/src/lib.rs | 2 +- modules/script/echo/src/lib.rs | 4 +--- modules/script/pkg/scripts.json | 14 +++++++++++--- modules/script/runner/src/lib.rs | 17 ++++++++--------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/modules/script/cat/src/lib.rs b/modules/script/cat/src/lib.rs index d189c074..831e0310 100644 --- a/modules/script/cat/src/lib.rs +++ b/modules/script/cat/src/lib.rs @@ -25,7 +25,7 @@ fn init(_our: Address) { }; Request::new() - .target(("our", "vfs", "sys", "kinode")) + .target(("our", "vfs", "distro", "sys")) .body( serde_json::to_vec(&vfs::VfsRequest { path: file_path.clone(), diff --git a/modules/script/echo/src/lib.rs b/modules/script/echo/src/lib.rs index ee5d5b62..c7a7714a 100644 --- a/modules/script/echo/src/lib.rs +++ b/modules/script/echo/src/lib.rs @@ -11,13 +11,11 @@ wit_bindgen::generate!({ call_init!(init); fn init(our: Address) { - println!("{}: this is a dummy script!", our); - // TODO will need to package this up into a process lib function that makes it easy let Ok(Message::Request { body, .. }) = await_message() else { println!("got send error, failing out"); return; }; - println!("here are the args: {:?}", String::from_utf8(body)); + println!("{}", String::from_utf8(body).unwrap()); } diff --git a/modules/script/pkg/scripts.json b/modules/script/pkg/scripts.json index 89684954..86b990a6 100644 --- a/modules/script/pkg/scripts.json +++ b/modules/script/pkg/scripts.json @@ -1,14 +1,22 @@ { - "echo": { + "echo.wasm": { "public": false, "requestNetworking": false, "requestCapabilities": [], "grantCapabilities": [] }, - "cat": { + "cat.wasm": { "public": false, "requestNetworking": false, - "requestCapabilities": [], + "requestCapabilities": [ + "vfs:distro:sys", + { + "process": "vfs:distro:sys", + "params": { + "root": true + } + } + ], "grantCapabilities": [] } } \ No newline at end of file diff --git a/modules/script/runner/src/lib.rs b/modules/script/runner/src/lib.rs index 1cee52df..3f7c38d7 100644 --- a/modules/script/runner/src/lib.rs +++ b/modules/script/runner/src/lib.rs @@ -41,7 +41,7 @@ pub enum ScriptRequest { call_init!(init); fn init(our: Address) { - println!("script_runner: begin"); + println!("runner:script : begin"); loop { match handle_message(&our) { @@ -55,7 +55,6 @@ fn init(our: Address) { fn handle_message(our: &Address) -> anyhow::Result<()> { let message = await_message()?; - match message { Message::Response { .. } => { return Err(anyhow::anyhow!("unexpected Response: {:?}", message)); @@ -92,7 +91,7 @@ fn handle_run( ) -> anyhow::Result<()> { let drive_path = format!("/{}/pkg", package); Request::new() - .target(("our", "vfs", "sys", "kinode")) + .target(("our", "vfs", "distro", "sys")) .body(serde_json::to_vec(&vfs::VfsRequest { path: format!("{}/scripts.json", drive_path), action: vfs::VfsAction::Read, @@ -116,7 +115,7 @@ fn handle_run( let mut initial_capabilities: HashSet = HashSet::new(); if entry.request_networking { initial_capabilities.insert(kt::de_wit_capability(Capability { - issuer: Address::new(&our.node, ("kernel", "sys", "kinode")), + issuer: Address::new(&our.node, ("kernel", "distro", "sys")), params: "\"network\"".to_string(), })); } @@ -126,7 +125,7 @@ fn handle_run( }; let _bytes_response = Request::new() - .target(("our", "vfs", "sys", "kinode")) + .target(("our", "vfs", "distro", "sys")) .body(serde_json::to_vec(&vfs::VfsRequest { path: wasm_path.clone(), action: vfs::VfsAction::Read, @@ -182,7 +181,7 @@ fn handle_run( } } Request::new() - .target(("our", "kernel", "sys", "kinode")) + .target(("our", "kernel", "distro", "sys")) .body(serde_json::to_vec(&kt::KernelCommand::InitializeProcess { id: parsed_new_process_id.clone(), wasm_bytes_handle: wasm_path, @@ -199,7 +198,7 @@ fn handle_run( serde_json::Value::String(process_name) => { if let Ok(parsed_process_id) = process_name.parse::() { let _ = Request::new() - .target(("our", "kernel", "sys", "kinode")) + .target(("our", "kernel", "distro", "sys")) .body( serde_json::to_vec(&kt::KernelCommand::GrantCapabilities { target: parsed_process_id, @@ -225,7 +224,7 @@ fn handle_run( { if let Some(params) = map.get("params") { let _ = Request::new() - .target(("our", "kernel", "sys", "kinode")) + .target(("our", "kernel", "distro", "sys")) .body( serde_json::to_vec(&kt::KernelCommand::GrantCapabilities { target: parsed_process_id, @@ -251,7 +250,7 @@ fn handle_run( } } let _ = Request::new() - .target(("our", "kernel", "sys", "kinode")) + .target(("our", "kernel", "distro", "sys")) .body(serde_json::to_vec(&kt::KernelCommand::RunProcess( parsed_new_process_id.clone(), ))?) From 6082ffde81ed8e0a1af73f550e4525910fc63943 Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Thu, 18 Jan 2024 14:15:11 -0600 Subject: [PATCH 09/21] hi working --- modules/script/cat/src/lib.rs | 2 +- modules/script/echo/src/lib.rs | 4 +- modules/script/hi/Cargo.lock | 553 +++++++++++++++++++++++++++++++ modules/script/hi/Cargo.toml | 21 ++ modules/script/hi/src/lib.rs | 48 +++ modules/script/pkg/manifest.json | 11 +- modules/script/pkg/scripts.json | 10 + 7 files changed, 645 insertions(+), 4 deletions(-) create mode 100644 modules/script/hi/Cargo.lock create mode 100644 modules/script/hi/Cargo.toml create mode 100644 modules/script/hi/src/lib.rs diff --git a/modules/script/cat/src/lib.rs b/modules/script/cat/src/lib.rs index 831e0310..2a8f8ec0 100644 --- a/modules/script/cat/src/lib.rs +++ b/modules/script/cat/src/lib.rs @@ -1,5 +1,5 @@ use kinode_process_lib::{ - await_message, call_init, get_blob, println, vfs, Address, Capability, Message, Request, + await_message, call_init, get_blob, println, vfs, Address, Message, Request, }; wit_bindgen::generate!({ diff --git a/modules/script/echo/src/lib.rs b/modules/script/echo/src/lib.rs index c7a7714a..b42c8633 100644 --- a/modules/script/echo/src/lib.rs +++ b/modules/script/echo/src/lib.rs @@ -1,4 +1,4 @@ -use kinode_process_lib::{await_message, call_init, println, Address, Message, Request}; +use kinode_process_lib::{await_message, call_init, println, Address, Message}; wit_bindgen::generate!({ path: "wit", @@ -10,7 +10,7 @@ wit_bindgen::generate!({ call_init!(init); -fn init(our: Address) { +fn init(_our: Address) { // TODO will need to package this up into a process lib function that makes it easy let Ok(Message::Request { body, .. }) = await_message() else { println!("got send error, failing out"); diff --git a/modules/script/hi/Cargo.lock b/modules/script/hi/Cargo.lock new file mode 100644 index 00000000..75b28183 --- /dev/null +++ b/modules/script/hi/Cargo.lock @@ -0,0 +1,553 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" + +[[package]] +name = "bytes" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "getrandom" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hi" +version = "0.1.0" +dependencies = [ + "kinode_process_lib", + "serde", + "serde_json", + "wit-bindgen", +] + +[[package]] +name = "http" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +dependencies = [ + "equivalent", + "hashbrown", + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "kinode_process_lib" +version = "0.5.0" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=9790c0f#9790c0fecc64572d1fbeecdf3724eb37b3d6d3fa" +dependencies = [ + "anyhow", + "bincode", + "http", + "mime_guess", + "rand", + "serde", + "serde_json", + "thiserror", + "url", + "wit-bindgen", +] + +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + +[[package]] +name = "libc" +version = "0.2.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "ryu" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" + +[[package]] +name = "semver" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" + +[[package]] +name = "serde" +version = "1.0.195" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.195" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "smallvec" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2593d31f82ead8df961d8bd23a64c2ccf2eb5dd34b0a34bfb4dd54011c72009e" + +[[package]] +name = "spdx" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bde1398b09b9f93fc2fc9b9da86e362693e999d3a54a8ac47a99a5a73f638b" +dependencies = [ + "smallvec", +] + +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-encoder" +version = "0.38.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ad2b51884de9c7f4fe2fd1043fccb8dcad4b1e29558146ee57a144d15779f3f" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-encoder" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "111495d6204760238512f57a9af162f45086504da332af210f2f75dd80b34f1d" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-metadata" +version = "0.10.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "818931c85b1d197909699d36c509fa89550ccfa0d66932ba3c1726faddb4d0c7" +dependencies = [ + "anyhow", + "indexmap", + "serde", + "serde_derive", + "serde_json", + "spdx", + "wasm-encoder 0.39.0", + "wasmparser 0.119.0", +] + +[[package]] +name = "wasmparser" +version = "0.118.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95ee9723b928e735d53000dec9eae7b07a60e490c85ab54abb66659fc61bfcd9" +dependencies = [ + "indexmap", + "semver", +] + +[[package]] +name = "wasmparser" +version = "0.119.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c35daf77afb4f9b14016625144a391085ec2ca99ca9cc53ed291bb53ab5278d" +dependencies = [ + "bitflags", + "indexmap", + "semver", +] + +[[package]] +name = "wit-bindgen" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "bitflags", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "anyhow", + "wit-component", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "anyhow", + "heck", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", + "wit-component", +] + +[[package]] +name = "wit-component" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a35a2a9992898c9d27f1664001860595a4bc99d32dd3599d547412e17d7e2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder 0.38.1", + "wasm-metadata", + "wasmparser 0.118.1", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df4913a2219096373fd6512adead1fb77ecdaa59d7fc517972a7d30b12f625be" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", +] diff --git a/modules/script/hi/Cargo.toml b/modules/script/hi/Cargo.toml new file mode 100644 index 00000000..65dda4a9 --- /dev/null +++ b/modules/script/hi/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "hi" +version = "0.1.0" +edition = "2021" + +[profile.release] +panic = "abort" +opt-level = "s" +lto = true + +[dependencies] +kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "9790c0f" } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } + +[lib] +crate-type = ["cdylib"] + +[package.metadata.component] +package = "kinode:process" diff --git a/modules/script/hi/src/lib.rs b/modules/script/hi/src/lib.rs new file mode 100644 index 00000000..4a5b3c90 --- /dev/null +++ b/modules/script/hi/src/lib.rs @@ -0,0 +1,48 @@ +use kinode_process_lib::{await_message, call_init, println, Address, Message, Request, SendError}; + +wit_bindgen::generate!({ + path: "wit", + world: "process", + exports: { + world: Component, + }, +}); + +call_init!(init); + +fn init(our: Address) { + // TODO will need to package this up into a process lib function that makes it easy + let Ok(Message::Request { body, .. }) = await_message() else { + println!("got send error, failing out"); + return; + }; + + let tail = String::from_utf8(body).unwrap(); + + let (node_id, message) = match tail.split_once(" ") { + Some((s, t)) => (s, t), + None => { + println!("invalid command: \"{tail}\""); + return; + } + }; + let node_id = if node_id == "our" { &our.node } else { node_id }; + match Request::new() + .target((node_id, "net", "distro", "sys")) + .body(message) + .send_and_await_response(5) + .unwrap() + { + Ok(msg) => { + if let Ok(txt) = std::str::from_utf8(&msg.body()) { + println!("response from {node_id}: {txt}"); + } else { + println!("response from {node_id}: {:?}", msg.body()); + } + } + Err(SendError { kind, .. }) => { + println!("hi: net error: {:?}", kind); + return; + } + } +} diff --git a/modules/script/pkg/manifest.json b/modules/script/pkg/manifest.json index b0b98cb5..3c931f42 100644 --- a/modules/script/pkg/manifest.json +++ b/modules/script/pkg/manifest.json @@ -3,11 +3,20 @@ "process_name": "runner", "process_wasm_path": "/runner.wasm", "on_exit": "Restart", - "request_networking": false, + "request_networking": true, "request_capabilities": [ + "terminal:terminal:sys", "filesystem:distro:sys", + "http_server:distro:sys", + "http_client:distro:sys", + "net:distro:sys", "vfs:distro:sys", "kernel:distro:sys", + "eth:distro:sys", + "sqlite:distro:sys", + "kv:distro:sys", + "chess:chess:sys", + "kns_indexer:kns_indexer:sys", { "process": "vfs:distro:sys", "params": { diff --git a/modules/script/pkg/scripts.json b/modules/script/pkg/scripts.json index 86b990a6..168f895b 100644 --- a/modules/script/pkg/scripts.json +++ b/modules/script/pkg/scripts.json @@ -18,5 +18,15 @@ } ], "grantCapabilities": [] + }, + "hi.wasm": { + "public": false, + "requestNetworking": true, + "requestCapabilities": [ + "net:distro:sys" + ], + "grantCapabilities": [ + "net:distro:sys" + ] } } \ No newline at end of file From 3746f404e62ab9b102292d30de33e4f63fd8bf88 Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Thu, 18 Jan 2024 14:46:54 -0600 Subject: [PATCH 10/21] top working --- modules/script/pkg/scripts.json | 8 + modules/script/top/Cargo.lock | 554 +++++++++++++++++++++++++++ modules/script/top/Cargo.toml | 22 ++ modules/script/top/src/lib.rs | 34 ++ modules/terminal/terminal/src/lib.rs | 5 +- 5 files changed, 622 insertions(+), 1 deletion(-) create mode 100644 modules/script/top/Cargo.lock create mode 100644 modules/script/top/Cargo.toml create mode 100644 modules/script/top/src/lib.rs diff --git a/modules/script/pkg/scripts.json b/modules/script/pkg/scripts.json index 168f895b..fe434a61 100644 --- a/modules/script/pkg/scripts.json +++ b/modules/script/pkg/scripts.json @@ -28,5 +28,13 @@ "grantCapabilities": [ "net:distro:sys" ] + }, + "top.wasm": { + "public": false, + "requestNetworking": false, + "requestCapabilities": [ + "kernel:distro:sys" + ], + "grantCapabilities": [] } } \ No newline at end of file diff --git a/modules/script/top/Cargo.lock b/modules/script/top/Cargo.lock new file mode 100644 index 00000000..46692fbb --- /dev/null +++ b/modules/script/top/Cargo.lock @@ -0,0 +1,554 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + +[[package]] +name = "bytes" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "getrandom" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "http" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +dependencies = [ + "equivalent", + "hashbrown", + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "kinode_process_lib" +version = "0.5.0" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=9790c0f#9790c0fecc64572d1fbeecdf3724eb37b3d6d3fa" +dependencies = [ + "anyhow", + "bincode", + "http", + "mime_guess", + "rand", + "serde", + "serde_json", + "thiserror", + "url", + "wit-bindgen", +] + +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + +[[package]] +name = "libc" +version = "0.2.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "ryu" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" + +[[package]] +name = "semver" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" + +[[package]] +name = "serde" +version = "1.0.195" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.195" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "smallvec" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2593d31f82ead8df961d8bd23a64c2ccf2eb5dd34b0a34bfb4dd54011c72009e" + +[[package]] +name = "spdx" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bde1398b09b9f93fc2fc9b9da86e362693e999d3a54a8ac47a99a5a73f638b" +dependencies = [ + "smallvec", +] + +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "top" +version = "0.1.0" +dependencies = [ + "anyhow", + "kinode_process_lib", + "serde", + "serde_json", + "wit-bindgen", +] + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-encoder" +version = "0.38.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ad2b51884de9c7f4fe2fd1043fccb8dcad4b1e29558146ee57a144d15779f3f" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-encoder" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "111495d6204760238512f57a9af162f45086504da332af210f2f75dd80b34f1d" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-metadata" +version = "0.10.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "818931c85b1d197909699d36c509fa89550ccfa0d66932ba3c1726faddb4d0c7" +dependencies = [ + "anyhow", + "indexmap", + "serde", + "serde_derive", + "serde_json", + "spdx", + "wasm-encoder 0.39.0", + "wasmparser 0.119.0", +] + +[[package]] +name = "wasmparser" +version = "0.118.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95ee9723b928e735d53000dec9eae7b07a60e490c85ab54abb66659fc61bfcd9" +dependencies = [ + "indexmap", + "semver", +] + +[[package]] +name = "wasmparser" +version = "0.119.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c35daf77afb4f9b14016625144a391085ec2ca99ca9cc53ed291bb53ab5278d" +dependencies = [ + "bitflags", + "indexmap", + "semver", +] + +[[package]] +name = "wit-bindgen" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "bitflags", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "anyhow", + "wit-component", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "anyhow", + "heck", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", + "wit-component", +] + +[[package]] +name = "wit-component" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a35a2a9992898c9d27f1664001860595a4bc99d32dd3599d547412e17d7e2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder 0.38.1", + "wasm-metadata", + "wasmparser 0.118.1", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df4913a2219096373fd6512adead1fb77ecdaa59d7fc517972a7d30b12f625be" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", +] diff --git a/modules/script/top/Cargo.toml b/modules/script/top/Cargo.toml new file mode 100644 index 00000000..9369c45c --- /dev/null +++ b/modules/script/top/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "top" +version = "0.1.0" +edition = "2021" + +[profile.release] +panic = "abort" +opt-level = "s" +lto = true + +[dependencies] +anyhow = "1.0" +kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "9790c0f" } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } + +[lib] +crate-type = ["cdylib"] + +[package.metadata.component] +package = "kinode:process" diff --git a/modules/script/top/src/lib.rs b/modules/script/top/src/lib.rs new file mode 100644 index 00000000..f994c8ed --- /dev/null +++ b/modules/script/top/src/lib.rs @@ -0,0 +1,34 @@ +use kinode_process_lib::kernel_types::{KernelCommand, KernelPrint}; +use kinode_process_lib::{await_message, call_init, println, Address, Message, ProcessId, Request}; + +wit_bindgen::generate!({ + path: "wit", + world: "process", + exports: { + world: Component, + }, +}); + +call_init!(init); + +fn init(_our: Address) { + // TODO will need to package this up into a process lib function that makes it easy + let Ok(Message::Request { body, .. }) = await_message() else { + println!("got send error, failing out"); + return; + }; + + let proc_id = String::from_utf8(body).unwrap(); + + let kernel_addr = Address::new("our", ("kernel", "distro", "sys")); + let _ = Request::new() + .target(kernel_addr) + .body( + serde_json::to_vec(&match proc_id.parse::() { + Ok(proc_id) => KernelCommand::Debug(KernelPrint::Process(proc_id)), + Err(_) => KernelCommand::Debug(KernelPrint::ProcessMap), + }) + .unwrap(), + ) + .send(); +} diff --git a/modules/terminal/terminal/src/lib.rs b/modules/terminal/terminal/src/lib.rs index 5f682209..c20dfe48 100644 --- a/modules/terminal/terminal/src/lib.rs +++ b/modules/terminal/terminal/src/lib.rs @@ -101,7 +101,10 @@ fn parse_command(state: &mut TerminalState, line: &str) -> anyhow::Result<()> { }, a, ), - None => return Err(anyhow!("invalid command: \"{line}\"")), + None => match tail.parse::() { + Ok(p) => (p, ""), + Err(_) => return Err(anyhow!("invalid process id: \"{tail}\"")), + }, }; Request::new() .target(Address::new("our", ("runner", "script", "sys"))) From 2db9f2d9711e33b8eb1a0313f29bae6d10a0b03d Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Thu, 18 Jan 2024 16:27:38 -0600 Subject: [PATCH 11/21] top and hi removed from terminalk --- modules/terminal/terminal/src/lib.rs | 38 +--------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/modules/terminal/terminal/src/lib.rs b/modules/terminal/terminal/src/lib.rs index c20dfe48..3d0d3368 100644 --- a/modules/terminal/terminal/src/lib.rs +++ b/modules/terminal/terminal/src/lib.rs @@ -25,24 +25,6 @@ fn parse_command(state: &mut TerminalState, line: &str) -> anyhow::Result<()> { let (head, tail) = line.split_once(" ").unwrap_or((&line, "")); match head { "" | " " => return Ok(()), - // send a raw text message over the network to a node - "/hi" => { - let (node_id, message) = match tail.split_once(" ") { - Some((s, t)) => (s, t), - None => return Err(anyhow!("invalid command: \"{line}\"")), - }; - let node_id = if node_id == "our" { - &state.our.node - } else { - node_id - }; - Request::new() - .target((node_id, "net", "distro", "sys")) - .body(message) - .expects_response(5) - .send()?; - Ok(()) - } // set the current target, so you can message it without specifying "/a" | "/app" => { if tail == "" || tail == "clear" { @@ -74,25 +56,7 @@ fn parse_command(state: &mut TerminalState, line: &str) -> anyhow::Result<()> { Request::new().target(target).body(body).send() } } - // send a message to kernel asking it to print debugging information - "/top" | "/kernel_debug" => { - let kernel_addr = Address::new("our", ("kernel", "distro", "sys")); - match tail { - "" => Request::new() - .target(kernel_addr) - .body(serde_json::to_vec(&KernelCommand::Debug( - KernelPrint::ProcessMap, - ))?) - .send(), - proc_id => Request::new() - .target(kernel_addr) - .body(serde_json::to_vec(&KernelCommand::Debug( - KernelPrint::Process(proc_id.parse()?), - ))?) - .send(), - } - } - "/script" | "/s" => { + "/s" | "/script" => { let (process, args) = match tail.split_once(" ") { Some((p, a)) => ( match p.parse::() { From 566b255099250ef4d2840c30cb1a227ec1df2d5c Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Thu, 18 Jan 2024 16:54:30 -0600 Subject: [PATCH 12/21] runner moved into terminal --- modules/script/pkg/manifest.json | 30 -- modules/script/runner/Cargo.lock | 556 --------------------------- modules/script/runner/Cargo.toml | 24 -- modules/script/runner/src/lib.rs | 263 ------------- modules/terminal/pkg/manifest.json | 18 +- modules/terminal/terminal/Cargo.lock | 1 + modules/terminal/terminal/Cargo.toml | 1 + modules/terminal/terminal/src/lib.rs | 226 +++++++++-- 8 files changed, 219 insertions(+), 900 deletions(-) delete mode 100644 modules/script/pkg/manifest.json delete mode 100644 modules/script/runner/Cargo.lock delete mode 100644 modules/script/runner/Cargo.toml delete mode 100644 modules/script/runner/src/lib.rs diff --git a/modules/script/pkg/manifest.json b/modules/script/pkg/manifest.json deleted file mode 100644 index 3c931f42..00000000 --- a/modules/script/pkg/manifest.json +++ /dev/null @@ -1,30 +0,0 @@ -[ - { - "process_name": "runner", - "process_wasm_path": "/runner.wasm", - "on_exit": "Restart", - "request_networking": true, - "request_capabilities": [ - "terminal:terminal:sys", - "filesystem:distro:sys", - "http_server:distro:sys", - "http_client:distro:sys", - "net:distro:sys", - "vfs:distro:sys", - "kernel:distro:sys", - "eth:distro:sys", - "sqlite:distro:sys", - "kv:distro:sys", - "chess:chess:sys", - "kns_indexer:kns_indexer:sys", - { - "process": "vfs:distro:sys", - "params": { - "root": true - } - } - ], - "grant_capabilities": [], - "public": true - } -] \ No newline at end of file diff --git a/modules/script/runner/Cargo.lock b/modules/script/runner/Cargo.lock deleted file mode 100644 index 715d2408..00000000 --- a/modules/script/runner/Cargo.lock +++ /dev/null @@ -1,556 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.79" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" - -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "getrandom" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "hashbrown" -version = "0.14.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "http" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "idna" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "indexmap" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" - -[[package]] -name = "kinode_process_lib" -version = "0.5.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=9790c0f#9790c0fecc64572d1fbeecdf3724eb37b3d6d3fa" -dependencies = [ - "anyhow", - "bincode", - "http", - "mime_guess", - "rand", - "serde", - "serde_json", - "thiserror", - "url", - "wit-bindgen", -] - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "libc" -version = "0.2.152" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "mime" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" - -[[package]] -name = "mime_guess" -version = "2.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" -dependencies = [ - "mime", - "unicase", -] - -[[package]] -name = "percent-encoding" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" - -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - -[[package]] -name = "proc-macro2" -version = "1.0.76" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "runner" -version = "0.1.0" -dependencies = [ - "anyhow", - "bincode", - "kinode_process_lib", - "rand", - "serde", - "serde_json", - "wit-bindgen", -] - -[[package]] -name = "ryu" -version = "1.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" - -[[package]] -name = "semver" -version = "1.0.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" - -[[package]] -name = "serde" -version = "1.0.195" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.195" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.111" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "smallvec" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2593d31f82ead8df961d8bd23a64c2ccf2eb5dd34b0a34bfb4dd54011c72009e" - -[[package]] -name = "spdx" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bde1398b09b9f93fc2fc9b9da86e362693e999d3a54a8ac47a99a5a73f638b" -dependencies = [ - "smallvec", -] - -[[package]] -name = "syn" -version = "2.0.48" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - -[[package]] -name = "unicase" -version = "2.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" -dependencies = [ - "version_check", -] - -[[package]] -name = "unicode-bidi" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-normalization" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "url" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wasm-encoder" -version = "0.38.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ad2b51884de9c7f4fe2fd1043fccb8dcad4b1e29558146ee57a144d15779f3f" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-encoder" -version = "0.39.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "111495d6204760238512f57a9af162f45086504da332af210f2f75dd80b34f1d" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "818931c85b1d197909699d36c509fa89550ccfa0d66932ba3c1726faddb4d0c7" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_derive", - "serde_json", - "spdx", - "wasm-encoder 0.39.0", - "wasmparser 0.119.0", -] - -[[package]] -name = "wasmparser" -version = "0.118.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ee9723b928e735d53000dec9eae7b07a60e490c85ab54abb66659fc61bfcd9" -dependencies = [ - "indexmap", - "semver", -] - -[[package]] -name = "wasmparser" -version = "0.119.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c35daf77afb4f9b14016625144a391085ec2ca99ca9cc53ed291bb53ab5278d" -dependencies = [ - "bitflags", - "indexmap", - "semver", -] - -[[package]] -name = "wit-bindgen" -version = "0.16.0" -source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" -dependencies = [ - "bitflags", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.16.0" -source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.16.0" -source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.16.0" -source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.18.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a35a2a9992898c9d27f1664001860595a4bc99d32dd3599d547412e17d7e2" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder 0.38.1", - "wasm-metadata", - "wasmparser 0.118.1", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df4913a2219096373fd6512adead1fb77ecdaa59d7fc517972a7d30b12f625be" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", -] diff --git a/modules/script/runner/Cargo.toml b/modules/script/runner/Cargo.toml deleted file mode 100644 index 8118b268..00000000 --- a/modules/script/runner/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "runner" -version = "0.1.0" -edition = "2021" - -[profile.release] -panic = "abort" -opt-level = "s" -lto = true - -[dependencies] -anyhow = "1.0" -bincode = "1.3.3" -kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "9790c0f" } -rand = "0.8" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } - -[lib] -crate-type = ["cdylib"] - -[package.metadata.component] -package = "kinode:process" diff --git a/modules/script/runner/src/lib.rs b/modules/script/runner/src/lib.rs deleted file mode 100644 index 3f7c38d7..00000000 --- a/modules/script/runner/src/lib.rs +++ /dev/null @@ -1,263 +0,0 @@ -use kinode_process_lib::kernel_types as kt; -use kinode_process_lib::*; -use serde::{Deserialize, Serialize}; -use std::collections::{HashMap, HashSet}; - -use kinode_process_lib::{ - await_message, call_init, println, Address, Capability, Message, ProcessId, Request, Response, -}; - -// TODO move this into kt:: -#[derive(Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct DotScriptsEntry { - pub public: bool, - pub request_networking: bool, - pub request_capabilities: Option>, - pub grant_capabilities: Option>, -} - -wit_bindgen::generate!({ - path: "wit", - world: "process", - exports: { - world: Component, - }, -}); - -#[derive(Debug, Serialize, Deserialize)] -pub enum ScriptRequest { - Run { - package: PackageId, - wasm_path: String, // vfs path - args: String, // first message, in json - }, - Inject { - process: String, // ProcessId - args: String, // next message, in json - }, - Terminate(String), // ProcessId string encoded -} - -call_init!(init); -fn init(our: Address) { - println!("runner:script : begin"); - - loop { - match handle_message(&our) { - Ok(()) => {} - Err(e) => { - println!("script_runner: error: {:?}", e); - } - }; - } -} - -fn handle_message(our: &Address) -> anyhow::Result<()> { - let message = await_message()?; - match message { - Message::Response { .. } => { - return Err(anyhow::anyhow!("unexpected Response: {:?}", message)); - } - Message::Request { - ref source, - ref body, - .. - } => match serde_json::from_slice::(body)? { - ScriptRequest::Run { - package, - wasm_path, - args, - } => match handle_run(our, &package, wasm_path, args) { - Ok(()) => {} // LocalResponse::InstallResponse(InstallResponse::Success), - Err(_) => {} // LocalResponse::InstallResponse(InstallResponse::Failure), - }, - ScriptRequest::Inject { process, args } => { - println!("script_runner: got inject request"); - } - ScriptRequest::Terminate(process) => { - println!("script_runner: got terminate request"); - } - }, - } - Ok(()) -} - -fn handle_run( - our: &Address, - package: &PackageId, - wasm_path: String, - args: String, -) -> anyhow::Result<()> { - let drive_path = format!("/{}/pkg", package); - Request::new() - .target(("our", "vfs", "distro", "sys")) - .body(serde_json::to_vec(&vfs::VfsRequest { - path: format!("{}/scripts.json", drive_path), - action: vfs::VfsAction::Read, - })?) - .send_and_await_response(5)??; - let Some(blob) = get_blob() else { - return Err(anyhow::anyhow!("no blob")); - }; - let dot_scripts = String::from_utf8(blob.bytes)?; - let dot_scripts = serde_json::from_str::>(&dot_scripts)?; - let Some(entry) = dot_scripts.get(&wasm_path) else { - return Err(anyhow::anyhow!("script not in scripts.json file")); - }; - let wasm_path = if wasm_path.starts_with("/") { - wasm_path.clone() - } else { - format!("/{}", wasm_path) - }; - let wasm_path = format!("{}{}", drive_path, wasm_path); - // build initial caps - let mut initial_capabilities: HashSet = HashSet::new(); - if entry.request_networking { - initial_capabilities.insert(kt::de_wit_capability(Capability { - issuer: Address::new(&our.node, ("kernel", "distro", "sys")), - params: "\"network\"".to_string(), - })); - } - let process_id = format!("{}:{}", rand::random::(), package); // all scripts are given random process IDs - let Ok(parsed_new_process_id) = process_id.parse::() else { - return Err(anyhow::anyhow!("app store: invalid process id!")); - }; - - let _bytes_response = Request::new() - .target(("our", "vfs", "distro", "sys")) - .body(serde_json::to_vec(&vfs::VfsRequest { - path: wasm_path.clone(), - action: vfs::VfsAction::Read, - })?) - .send_and_await_response(5)??; - if let Some(to_request) = &entry.request_capabilities { - for value in to_request { - let mut capability = None; - match value { - serde_json::Value::String(process_name) => { - if let Ok(parsed_process_id) = process_name.parse::() { - capability = get_capability( - &Address { - node: our.node.clone(), - process: parsed_process_id.clone(), - }, - "\"messaging\"".into(), - ); - } - } - serde_json::Value::Object(map) => { - if let Some(process_name) = map.get("process") { - if let Ok(parsed_process_id) = process_name - .as_str() - .unwrap_or_default() - .parse::() - { - if let Some(params) = map.get("params") { - capability = get_capability( - &Address { - node: our.node.clone(), - process: parsed_process_id.clone(), - }, - ¶ms.to_string(), - ); - } - } - } - } - _ => { - continue; - } - } - if let Some(cap) = capability { - initial_capabilities.insert(kt::de_wit_capability(cap)); - } else { - println!( - "runner: no cap: {}, for {} to request!", - value.to_string(), - package - ); - } - } - } - Request::new() - .target(("our", "kernel", "distro", "sys")) - .body(serde_json::to_vec(&kt::KernelCommand::InitializeProcess { - id: parsed_new_process_id.clone(), - wasm_bytes_handle: wasm_path, - wit_version: None, - on_exit: kt::OnExit::None, // TODO this should send a message back to runner:script:sys so that it can Drop capabilities - initial_capabilities, - public: entry.public, - })?) - .inherit(true) - .send_and_await_response(5)??; - if let Some(to_grant) = &entry.grant_capabilities { - for value in to_grant { - match value { - serde_json::Value::String(process_name) => { - if let Ok(parsed_process_id) = process_name.parse::() { - let _ = Request::new() - .target(("our", "kernel", "distro", "sys")) - .body( - serde_json::to_vec(&kt::KernelCommand::GrantCapabilities { - target: parsed_process_id, - capabilities: vec![kt::Capability { - issuer: Address { - node: our.node.clone(), - process: parsed_new_process_id.clone(), - }, - params: "\"messaging\"".into(), - }], - }) - .unwrap(), - ) - .send()?; - } - } - serde_json::Value::Object(map) => { - if let Some(process_name) = map.get("process") { - if let Ok(parsed_process_id) = process_name - .as_str() - .unwrap_or_default() - .parse::() - { - if let Some(params) = map.get("params") { - let _ = Request::new() - .target(("our", "kernel", "distro", "sys")) - .body( - serde_json::to_vec(&kt::KernelCommand::GrantCapabilities { - target: parsed_process_id, - capabilities: vec![kt::Capability { - issuer: Address { - node: our.node.clone(), - process: parsed_new_process_id.clone(), - }, - params: params.to_string(), - }], - }) - .unwrap(), - ) - .send()?; - } - } - } - } - _ => { - continue; - } - } - } - } - let _ = Request::new() - .target(("our", "kernel", "distro", "sys")) - .body(serde_json::to_vec(&kt::KernelCommand::RunProcess( - parsed_new_process_id.clone(), - ))?) - .send_and_await_response(5)??; - let _ = Request::new() - .target(("our", parsed_new_process_id)) - .body(args.into_bytes()) - .send(); - Ok(()) -} diff --git a/modules/terminal/pkg/manifest.json b/modules/terminal/pkg/manifest.json index 412357ef..7c787eb0 100644 --- a/modules/terminal/pkg/manifest.json +++ b/modules/terminal/pkg/manifest.json @@ -6,10 +6,24 @@ "request_networking": true, "request_capabilities": [ "net:distro:sys", + "filesystem:distro:sys", + "http_server:distro:sys", "http_client:distro:sys", - "kernel:distro:sys" + "kernel:distro:sys", + "vfs:distro:sys", + "eth:distro:sys", + "sqlite:distro:sys", + "kv:distro:sys", + "chess:chess:sys", + "kns_indexer:kns_indexer:sys", + { + "process": "vfs:distro:sys", + "params": { + "root": true + } + } ], "grant_capabilities": [], "public": true } -] +] \ No newline at end of file diff --git a/modules/terminal/terminal/Cargo.lock b/modules/terminal/terminal/Cargo.lock index 3f84f5a5..6d0344fb 100644 --- a/modules/terminal/terminal/Cargo.lock +++ b/modules/terminal/terminal/Cargo.lock @@ -313,6 +313,7 @@ dependencies = [ "anyhow", "bincode", "kinode_process_lib", + "rand", "serde", "serde_json", "wit-bindgen", diff --git a/modules/terminal/terminal/Cargo.toml b/modules/terminal/terminal/Cargo.toml index 7504cb90..d6c19221 100644 --- a/modules/terminal/terminal/Cargo.toml +++ b/modules/terminal/terminal/Cargo.toml @@ -13,6 +13,7 @@ lto = true [dependencies] anyhow = "1.0" bincode = "1.3.3" +rand = "0.8" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", tag = "v0.5.3-alpha" } diff --git a/modules/terminal/terminal/src/lib.rs b/modules/terminal/terminal/src/lib.rs index 3d0d3368..fd9f6ec8 100644 --- a/modules/terminal/terminal/src/lib.rs +++ b/modules/terminal/terminal/src/lib.rs @@ -1,8 +1,11 @@ use anyhow::anyhow; -use kinode_process_lib::kernel_types::{KernelCommand, KernelPrint}; +use kinode_process_lib::kernel_types as kt; use kinode_process_lib::kinode::process::standard as wit; -use kinode_process_lib::{println, Address, ProcessId, Request}; -use serde_json::json; +use kinode_process_lib::{ + get_blob, get_capability, println, vfs, Address, Capability, PackageId, ProcessId, Request, +}; +use serde::{Deserialize, Serialize}; +use std::collections::{HashMap, HashSet}; wit_bindgen::generate!({ path: "../../../wit", @@ -12,15 +15,21 @@ wit_bindgen::generate!({ }, }); +// TODO move this into kt:: +#[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct DotScriptsEntry { + pub public: bool, + pub request_networking: bool, + pub request_capabilities: Option>, + pub grant_capabilities: Option>, +} + struct TerminalState { our: Address, current_target: Option
, } -fn serialize_message(message: &str) -> anyhow::Result> { - Ok(message.as_bytes().to_vec()) -} - fn parse_command(state: &mut TerminalState, line: &str) -> anyhow::Result<()> { let (head, tail) = line.split_once(" ").unwrap_or((&line, "")); match head { @@ -70,24 +79,12 @@ fn parse_command(state: &mut TerminalState, line: &str) -> anyhow::Result<()> { Err(_) => return Err(anyhow!("invalid process id: \"{tail}\"")), }, }; - Request::new() - .target(Address::new("our", ("runner", "script", "sys"))) - .body( - json!({ - "Run": { - // TODO we should add a package_id() method to ProcessId that will get this for you - "package": { - "package_name": process.package(), - "publisher_node": process.publisher(), - }, - "wasm_path": format!("{}.wasm", process.process()), - "args": args - } - }) - .to_string() - .into_bytes(), - ) - .send() + let wasm_path = format!("{}.wasm", process.process()); + let package = PackageId::new(process.package(), process.publisher()); + match handle_run(&state.our, &package, wasm_path, args.to_string()) { + Ok(_) => Ok(()), // TODO clean up process + Err(e) => Err(anyhow!("terminal: failed to instantiate script: {}", e)), + } } _ => return Err(anyhow!("invalid command: \"{line}\"")), } @@ -130,3 +127,182 @@ impl Guest for Component { } } } + +fn handle_run( + our: &Address, + package: &PackageId, + wasm_path: String, + args: String, +) -> anyhow::Result<()> { + let drive_path = format!("/{}/pkg", package); + Request::new() + .target(("our", "vfs", "distro", "sys")) + .body(serde_json::to_vec(&vfs::VfsRequest { + path: format!("{}/scripts.json", drive_path), + action: vfs::VfsAction::Read, + })?) + .send_and_await_response(5)??; + let Some(blob) = get_blob() else { + return Err(anyhow::anyhow!("no blob")); + }; + let dot_scripts = String::from_utf8(blob.bytes)?; + let dot_scripts = serde_json::from_str::>(&dot_scripts)?; + let Some(entry) = dot_scripts.get(&wasm_path) else { + return Err(anyhow::anyhow!("script not in scripts.json file")); + }; + let wasm_path = if wasm_path.starts_with("/") { + wasm_path.clone() + } else { + format!("/{}", wasm_path) + }; + let wasm_path = format!("{}{}", drive_path, wasm_path); + // build initial caps + let mut initial_capabilities: HashSet = HashSet::new(); + if entry.request_networking { + initial_capabilities.insert(kt::de_wit_capability(Capability { + issuer: Address::new(&our.node, ("kernel", "distro", "sys")), + params: "\"network\"".to_string(), + })); + } + let process_id = format!("{}:{}", rand::random::(), package); // all scripts are given random process IDs + let Ok(parsed_new_process_id) = process_id.parse::() else { + return Err(anyhow::anyhow!("app store: invalid process id!")); + }; + + let _bytes_response = Request::new() + .target(("our", "vfs", "distro", "sys")) + .body(serde_json::to_vec(&vfs::VfsRequest { + path: wasm_path.clone(), + action: vfs::VfsAction::Read, + })?) + .send_and_await_response(5)??; + if let Some(to_request) = &entry.request_capabilities { + for value in to_request { + let mut capability = None; + match value { + serde_json::Value::String(process_name) => { + if let Ok(parsed_process_id) = process_name.parse::() { + capability = get_capability( + &Address { + node: our.node.clone(), + process: parsed_process_id.clone(), + }, + "\"messaging\"".into(), + ); + } + } + serde_json::Value::Object(map) => { + if let Some(process_name) = map.get("process") { + if let Ok(parsed_process_id) = process_name + .as_str() + .unwrap_or_default() + .parse::() + { + if let Some(params) = map.get("params") { + capability = get_capability( + &Address { + node: our.node.clone(), + process: parsed_process_id.clone(), + }, + ¶ms.to_string(), + ); + } + } + } + } + _ => { + continue; + } + } + if let Some(cap) = capability { + initial_capabilities.insert(kt::de_wit_capability(cap)); + } else { + println!( + "runner: no cap: {}, for {} to request!", + value.to_string(), + package + ); + } + } + } + Request::new() + .target(("our", "kernel", "distro", "sys")) + .body(serde_json::to_vec(&kt::KernelCommand::InitializeProcess { + id: parsed_new_process_id.clone(), + wasm_bytes_handle: wasm_path, + wit_version: None, + on_exit: kt::OnExit::None, // TODO this should send a message back to runner:script:sys so that it can Drop capabilities + initial_capabilities, + public: entry.public, + })?) + .inherit(true) + .send_and_await_response(5)??; + if let Some(to_grant) = &entry.grant_capabilities { + for value in to_grant { + match value { + serde_json::Value::String(process_name) => { + if let Ok(parsed_process_id) = process_name.parse::() { + let _ = Request::new() + .target(("our", "kernel", "distro", "sys")) + .body( + serde_json::to_vec(&kt::KernelCommand::GrantCapabilities { + target: parsed_process_id, + capabilities: vec![kt::Capability { + issuer: Address { + node: our.node.clone(), + process: parsed_new_process_id.clone(), + }, + params: "\"messaging\"".into(), + }], + }) + .unwrap(), + ) + .send()?; + } + } + serde_json::Value::Object(map) => { + if let Some(process_name) = map.get("process") { + if let Ok(parsed_process_id) = process_name + .as_str() + .unwrap_or_default() + .parse::() + { + if let Some(params) = map.get("params") { + let _ = Request::new() + .target(("our", "kernel", "distro", "sys")) + .body( + serde_json::to_vec(&kt::KernelCommand::GrantCapabilities { + target: parsed_process_id, + capabilities: vec![kt::Capability { + issuer: Address { + node: our.node.clone(), + process: parsed_new_process_id.clone(), + }, + params: params.to_string(), + }], + }) + .unwrap(), + ) + .send()?; + } + } + } + } + _ => { + continue; + } + } + } + } + let _ = Request::new() + .target(("our", "kernel", "distro", "sys")) + .body(serde_json::to_vec(&kt::KernelCommand::RunProcess( + parsed_new_process_id.clone(), + ))?) + .send_and_await_response(5)??; + let _ = Request::new() + .target(("our", parsed_new_process_id)) + .body(args.into_bytes()) + .send(); + Ok(()) +} From 42e88f6c5988f14335b8f3101c5676936a30d757 Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Thu, 18 Jan 2024 16:58:30 -0600 Subject: [PATCH 13/21] scripts moved into terminal --- modules/script/pkg/metadata.json | 9 --------- modules/{script => terminal}/cat/Cargo.lock | 0 modules/{script => terminal}/cat/Cargo.toml | 0 modules/{script => terminal}/cat/src/lib.rs | 0 modules/{script => terminal}/echo/Cargo.lock | 0 modules/{script => terminal}/echo/Cargo.toml | 0 modules/{script => terminal}/echo/src/lib.rs | 0 modules/{script => terminal}/hi/Cargo.lock | 0 modules/{script => terminal}/hi/Cargo.toml | 0 modules/{script => terminal}/hi/src/lib.rs | 0 modules/{script => terminal}/pkg/scripts.json | 0 modules/{script => terminal}/top/Cargo.lock | 0 modules/{script => terminal}/top/Cargo.toml | 0 modules/{script => terminal}/top/src/lib.rs | 0 14 files changed, 9 deletions(-) delete mode 100644 modules/script/pkg/metadata.json rename modules/{script => terminal}/cat/Cargo.lock (100%) rename modules/{script => terminal}/cat/Cargo.toml (100%) rename modules/{script => terminal}/cat/src/lib.rs (100%) rename modules/{script => terminal}/echo/Cargo.lock (100%) rename modules/{script => terminal}/echo/Cargo.toml (100%) rename modules/{script => terminal}/echo/src/lib.rs (100%) rename modules/{script => terminal}/hi/Cargo.lock (100%) rename modules/{script => terminal}/hi/Cargo.toml (100%) rename modules/{script => terminal}/hi/src/lib.rs (100%) rename modules/{script => terminal}/pkg/scripts.json (100%) rename modules/{script => terminal}/top/Cargo.lock (100%) rename modules/{script => terminal}/top/Cargo.toml (100%) rename modules/{script => terminal}/top/src/lib.rs (100%) diff --git a/modules/script/pkg/metadata.json b/modules/script/pkg/metadata.json deleted file mode 100644 index b22ce780..00000000 --- a/modules/script/pkg/metadata.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "package": "script", - "publisher": "sys", - "version": [ - 0, - 1, - 0 - ] -} \ No newline at end of file diff --git a/modules/script/cat/Cargo.lock b/modules/terminal/cat/Cargo.lock similarity index 100% rename from modules/script/cat/Cargo.lock rename to modules/terminal/cat/Cargo.lock diff --git a/modules/script/cat/Cargo.toml b/modules/terminal/cat/Cargo.toml similarity index 100% rename from modules/script/cat/Cargo.toml rename to modules/terminal/cat/Cargo.toml diff --git a/modules/script/cat/src/lib.rs b/modules/terminal/cat/src/lib.rs similarity index 100% rename from modules/script/cat/src/lib.rs rename to modules/terminal/cat/src/lib.rs diff --git a/modules/script/echo/Cargo.lock b/modules/terminal/echo/Cargo.lock similarity index 100% rename from modules/script/echo/Cargo.lock rename to modules/terminal/echo/Cargo.lock diff --git a/modules/script/echo/Cargo.toml b/modules/terminal/echo/Cargo.toml similarity index 100% rename from modules/script/echo/Cargo.toml rename to modules/terminal/echo/Cargo.toml diff --git a/modules/script/echo/src/lib.rs b/modules/terminal/echo/src/lib.rs similarity index 100% rename from modules/script/echo/src/lib.rs rename to modules/terminal/echo/src/lib.rs diff --git a/modules/script/hi/Cargo.lock b/modules/terminal/hi/Cargo.lock similarity index 100% rename from modules/script/hi/Cargo.lock rename to modules/terminal/hi/Cargo.lock diff --git a/modules/script/hi/Cargo.toml b/modules/terminal/hi/Cargo.toml similarity index 100% rename from modules/script/hi/Cargo.toml rename to modules/terminal/hi/Cargo.toml diff --git a/modules/script/hi/src/lib.rs b/modules/terminal/hi/src/lib.rs similarity index 100% rename from modules/script/hi/src/lib.rs rename to modules/terminal/hi/src/lib.rs diff --git a/modules/script/pkg/scripts.json b/modules/terminal/pkg/scripts.json similarity index 100% rename from modules/script/pkg/scripts.json rename to modules/terminal/pkg/scripts.json diff --git a/modules/script/top/Cargo.lock b/modules/terminal/top/Cargo.lock similarity index 100% rename from modules/script/top/Cargo.lock rename to modules/terminal/top/Cargo.lock diff --git a/modules/script/top/Cargo.toml b/modules/terminal/top/Cargo.toml similarity index 100% rename from modules/script/top/Cargo.toml rename to modules/terminal/top/Cargo.toml diff --git a/modules/script/top/src/lib.rs b/modules/terminal/top/src/lib.rs similarity index 100% rename from modules/script/top/src/lib.rs rename to modules/terminal/top/src/lib.rs From ed0d17ecd04e52386bf2c17b7cc2a57b4623986a Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Fri, 19 Jan 2024 09:41:11 -0600 Subject: [PATCH 14/21] terminal commands changed --- modules/terminal/terminal/src/lib.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/terminal/terminal/src/lib.rs b/modules/terminal/terminal/src/lib.rs index fd9f6ec8..c6966444 100644 --- a/modules/terminal/terminal/src/lib.rs +++ b/modules/terminal/terminal/src/lib.rs @@ -31,11 +31,12 @@ struct TerminalState { } fn parse_command(state: &mut TerminalState, line: &str) -> anyhow::Result<()> { - let (head, tail) = line.split_once(" ").unwrap_or((&line, "")); + let head = line.chars().next().unwrap_or(' '); + let (_, tail) = line.split_at(head.len_utf8()); match head { - "" | " " => return Ok(()), + ' ' => return Ok(()), // set the current target, so you can message it without specifying - "/a" | "/app" => { + '+' => { if tail == "" || tail == "clear" { state.current_target = None; println!("current target cleared"); @@ -51,7 +52,7 @@ fn parse_command(state: &mut TerminalState, line: &str) -> anyhow::Result<()> { // send a message to a specified app // if no current_target is set, require it, // otherwise use the current_target - "/m" | "/message" => { + '/' => { if let Some(target) = &state.current_target { Request::new().target(target.clone()).body(tail).send() } else { @@ -65,7 +66,7 @@ fn parse_command(state: &mut TerminalState, line: &str) -> anyhow::Result<()> { Request::new().target(target).body(body).send() } } - "/s" | "/script" => { + '-' => { let (process, args) = match tail.split_once(" ") { Some((p, a)) => ( match p.parse::() { @@ -83,7 +84,7 @@ fn parse_command(state: &mut TerminalState, line: &str) -> anyhow::Result<()> { let package = PackageId::new(process.package(), process.publisher()); match handle_run(&state.our, &package, wasm_path, args.to_string()) { Ok(_) => Ok(()), // TODO clean up process - Err(e) => Err(anyhow!("terminal: failed to instantiate script: {}", e)), + Err(e) => Err(anyhow!("failed to instantiate script: {}", e)), } } _ => return Err(anyhow!("invalid command: \"{line}\"")), @@ -143,7 +144,10 @@ fn handle_run( })?) .send_and_await_response(5)??; let Some(blob) = get_blob() else { - return Err(anyhow::anyhow!("no blob")); + return Err(anyhow::anyhow!( + "couldn't find /{}/pkg/scripts.json", + package + )); }; let dot_scripts = String::from_utf8(blob.bytes)?; let dot_scripts = serde_json::from_str::>(&dot_scripts)?; From b08f6bb4307584bcb6cad02d6d14db23495b5d90 Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Fri, 19 Jan 2024 10:23:09 -0600 Subject: [PATCH 15/21] aliases working --- modules/terminal/terminal/src/lib.rs | 39 ++++++++++++++++++---------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/modules/terminal/terminal/src/lib.rs b/modules/terminal/terminal/src/lib.rs index c6966444..e8a2c03a 100644 --- a/modules/terminal/terminal/src/lib.rs +++ b/modules/terminal/terminal/src/lib.rs @@ -28,6 +28,7 @@ pub struct DotScriptsEntry { struct TerminalState { our: Address, current_target: Option
, + aliases: HashMap, // TODO maybe address... } fn parse_command(state: &mut TerminalState, line: &str) -> anyhow::Result<()> { @@ -35,6 +36,7 @@ fn parse_command(state: &mut TerminalState, line: &str) -> anyhow::Result<()> { let (_, tail) = line.split_at(head.len_utf8()); match head { ' ' => return Ok(()), + // TODO actually I think this can be done as a script... // set the current target, so you can message it without specifying '+' => { if tail == "" || tail == "clear" { @@ -60,24 +62,27 @@ fn parse_command(state: &mut TerminalState, line: &str) -> anyhow::Result<()> { Some((a, p)) => (a, p), None => return Err(anyhow!("invalid command: \"{line}\"")), }; - let Ok(target) = target.parse::
() else { - return Err(anyhow!("invalid address: \"{target}\"")); + let target = match target.parse::
() { + Ok(t) => t, + Err(e) => match state.aliases.get(target) { + Some(pid) => Address::new("our", pid.clone()), + None => { + return Err(anyhow!("invalid address: \"{target}\"")); + } + }, }; Request::new().target(target).body(body).send() } } '-' => { - let (process, args) = match tail.split_once(" ") { - Some((p, a)) => ( - match p.parse::() { - Ok(p) => p, - Err(_) => return Err(anyhow!("invalid process id: \"{tail}\"")), - }, - a, - ), - None => match tail.parse::() { - Ok(p) => (p, ""), - Err(_) => return Err(anyhow!("invalid process id: \"{tail}\"")), + let (process, args) = tail.split_once(" ").unwrap_or((tail, "")); + let process = match process.parse::() { + Ok(p) => p, + Err(e) => match state.aliases.get(process) { + Some(pid) => pid.clone(), + None => { + return Err(anyhow!("invalid process: \"{process}\"")); + } }, }; let wasm_path = format!("{}.wasm", process.process()); @@ -97,6 +102,14 @@ impl Guest for Component { let mut state = TerminalState { our: our.parse::
().unwrap(), current_target: None, + aliases: { + let mut a = HashMap::new(); + a.insert( + "echo".to_string(), + "echo:terminal:sys".parse::().unwrap(), + ); + a + }, }; loop { let (source, message) = match wit::receive() { From fa02c604dfdfbd32f198a293f316a7cde240472c Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Fri, 19 Jan 2024 11:55:30 -0600 Subject: [PATCH 16/21] m script added; script maximalism --- modules/terminal/m/Cargo.lock | 554 +++++++++++++++++++++++++++ modules/terminal/m/Cargo.toml | 22 ++ modules/terminal/m/src/lib.rs | 43 +++ modules/terminal/pkg/scripts.json | 9 + modules/terminal/terminal/src/lib.rs | 104 ++--- 5 files changed, 670 insertions(+), 62 deletions(-) create mode 100644 modules/terminal/m/Cargo.lock create mode 100644 modules/terminal/m/Cargo.toml create mode 100644 modules/terminal/m/src/lib.rs diff --git a/modules/terminal/m/Cargo.lock b/modules/terminal/m/Cargo.lock new file mode 100644 index 00000000..518b682c --- /dev/null +++ b/modules/terminal/m/Cargo.lock @@ -0,0 +1,554 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + +[[package]] +name = "bytes" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "getrandom" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "http" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +dependencies = [ + "equivalent", + "hashbrown", + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "kinode_process_lib" +version = "0.5.0" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=9790c0f#9790c0fecc64572d1fbeecdf3724eb37b3d6d3fa" +dependencies = [ + "anyhow", + "bincode", + "http", + "mime_guess", + "rand", + "serde", + "serde_json", + "thiserror", + "url", + "wit-bindgen", +] + +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + +[[package]] +name = "libc" +version = "0.2.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "m" +version = "0.1.0" +dependencies = [ + "anyhow", + "kinode_process_lib", + "serde", + "serde_json", + "wit-bindgen", +] + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "ryu" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" + +[[package]] +name = "semver" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" + +[[package]] +name = "serde" +version = "1.0.195" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.195" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "smallvec" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2593d31f82ead8df961d8bd23a64c2ccf2eb5dd34b0a34bfb4dd54011c72009e" + +[[package]] +name = "spdx" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bde1398b09b9f93fc2fc9b9da86e362693e999d3a54a8ac47a99a5a73f638b" +dependencies = [ + "smallvec", +] + +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-encoder" +version = "0.38.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ad2b51884de9c7f4fe2fd1043fccb8dcad4b1e29558146ee57a144d15779f3f" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-encoder" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "111495d6204760238512f57a9af162f45086504da332af210f2f75dd80b34f1d" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-metadata" +version = "0.10.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "818931c85b1d197909699d36c509fa89550ccfa0d66932ba3c1726faddb4d0c7" +dependencies = [ + "anyhow", + "indexmap", + "serde", + "serde_derive", + "serde_json", + "spdx", + "wasm-encoder 0.39.0", + "wasmparser 0.119.0", +] + +[[package]] +name = "wasmparser" +version = "0.118.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95ee9723b928e735d53000dec9eae7b07a60e490c85ab54abb66659fc61bfcd9" +dependencies = [ + "indexmap", + "semver", +] + +[[package]] +name = "wasmparser" +version = "0.119.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c35daf77afb4f9b14016625144a391085ec2ca99ca9cc53ed291bb53ab5278d" +dependencies = [ + "bitflags", + "indexmap", + "semver", +] + +[[package]] +name = "wit-bindgen" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "bitflags", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "anyhow", + "wit-component", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "anyhow", + "heck", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.16.0" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=efcc759#efcc7592cf3277bcb9be1034e48569c6d822b322" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", + "wit-component", +] + +[[package]] +name = "wit-component" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a35a2a9992898c9d27f1664001860595a4bc99d32dd3599d547412e17d7e2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder 0.38.1", + "wasm-metadata", + "wasmparser 0.118.1", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df4913a2219096373fd6512adead1fb77ecdaa59d7fc517972a7d30b12f625be" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", +] diff --git a/modules/terminal/m/Cargo.toml b/modules/terminal/m/Cargo.toml new file mode 100644 index 00000000..72ee9261 --- /dev/null +++ b/modules/terminal/m/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "m" +version = "0.1.0" +edition = "2021" + +[profile.release] +panic = "abort" +opt-level = "s" +lto = true + +[dependencies] +anyhow = "1.0" +kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "9790c0f" } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } + +[lib] +crate-type = ["cdylib"] + +[package.metadata.component] +package = "kinode:process" diff --git a/modules/terminal/m/src/lib.rs b/modules/terminal/m/src/lib.rs new file mode 100644 index 00000000..c4929ddb --- /dev/null +++ b/modules/terminal/m/src/lib.rs @@ -0,0 +1,43 @@ +use kinode_process_lib::{await_message, call_init, println, Address, Message, Request}; + +wit_bindgen::generate!({ + path: "wit", + world: "process", + exports: { + world: Component, + }, +}); + +call_init!(init); + +fn init(_our: Address) { + // TODO will need to package this up into a process lib function that makes it easy + let Ok(Message::Request { body, .. }) = await_message() else { + println!("got send error, failing out"); + return; + }; + + let tail = String::from_utf8(body).unwrap(); + + let (target, body) = match tail.split_once(" ") { + Some((a, p)) => (a, p), + None => { + println!("invalid command: \"{tail}\""); + return; + } + }; + // TODO aliasing logic...maybe we can read from terminal state since we have root? + let target = match target.parse::
() { + Ok(t) => t, + Err(e) => { + println!("invalid address: \"{target}\""); + return; + } // match state.aliases.get(target) { + // Some(pid) => Address::new("our", pid.clone()), + // None => { + // return Err(anyhow!("invalid address: \"{target}\"")); + // } + // }, + }; + let _ = Request::new().target(target).body(body).send(); +} diff --git a/modules/terminal/pkg/scripts.json b/modules/terminal/pkg/scripts.json index fe434a61..d2277504 100644 --- a/modules/terminal/pkg/scripts.json +++ b/modules/terminal/pkg/scripts.json @@ -1,11 +1,13 @@ { "echo.wasm": { + "root": false, "public": false, "requestNetworking": false, "requestCapabilities": [], "grantCapabilities": [] }, "cat.wasm": { + "root": false, "public": false, "requestNetworking": false, "requestCapabilities": [ @@ -20,6 +22,7 @@ "grantCapabilities": [] }, "hi.wasm": { + "root": false, "public": false, "requestNetworking": true, "requestCapabilities": [ @@ -30,11 +33,17 @@ ] }, "top.wasm": { + "root": false, "public": false, "requestNetworking": false, "requestCapabilities": [ "kernel:distro:sys" ], "grantCapabilities": [] + }, + "m.wasm": { + "root": true, + "public": false, + "requestNetworking": true } } \ No newline at end of file diff --git a/modules/terminal/terminal/src/lib.rs b/modules/terminal/terminal/src/lib.rs index e8a2c03a..b5d0ed63 100644 --- a/modules/terminal/terminal/src/lib.rs +++ b/modules/terminal/terminal/src/lib.rs @@ -2,7 +2,8 @@ use anyhow::anyhow; use kinode_process_lib::kernel_types as kt; use kinode_process_lib::kinode::process::standard as wit; use kinode_process_lib::{ - get_blob, get_capability, println, vfs, Address, Capability, PackageId, ProcessId, Request, + get_blob, get_capability, our_capabilities, println, vfs, Address, Capability, PackageId, + ProcessId, Request, }; use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; @@ -19,6 +20,7 @@ wit_bindgen::generate!({ #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct DotScriptsEntry { + pub root: bool, pub public: bool, pub request_networking: bool, pub request_capabilities: Option>, @@ -32,67 +34,22 @@ struct TerminalState { } fn parse_command(state: &mut TerminalState, line: &str) -> anyhow::Result<()> { - let head = line.chars().next().unwrap_or(' '); - let (_, tail) = line.split_at(head.len_utf8()); - match head { - ' ' => return Ok(()), - // TODO actually I think this can be done as a script... - // set the current target, so you can message it without specifying - '+' => { - if tail == "" || tail == "clear" { - state.current_target = None; - println!("current target cleared"); - return Ok(()); + let (head, args) = line.split_once(" ").unwrap_or((line, "")); + let process = match state.aliases.get(head) { + Some(pid) => pid.clone(), + None => match head.parse::() { + Ok(pid) => pid, + Err(_) => { + return Err(anyhow!("invalid script name")); } - let Ok(target) = tail.parse::
() else { - return Err(anyhow!("invalid address: \"{tail}\"")); - }; - println!("current target set to {target}"); - state.current_target = Some(target); - Ok(()) - } - // send a message to a specified app - // if no current_target is set, require it, - // otherwise use the current_target - '/' => { - if let Some(target) = &state.current_target { - Request::new().target(target.clone()).body(tail).send() - } else { - let (target, body) = match tail.split_once(" ") { - Some((a, p)) => (a, p), - None => return Err(anyhow!("invalid command: \"{line}\"")), - }; - let target = match target.parse::
() { - Ok(t) => t, - Err(e) => match state.aliases.get(target) { - Some(pid) => Address::new("our", pid.clone()), - None => { - return Err(anyhow!("invalid address: \"{target}\"")); - } - }, - }; - Request::new().target(target).body(body).send() - } - } - '-' => { - let (process, args) = tail.split_once(" ").unwrap_or((tail, "")); - let process = match process.parse::() { - Ok(p) => p, - Err(e) => match state.aliases.get(process) { - Some(pid) => pid.clone(), - None => { - return Err(anyhow!("invalid process: \"{process}\"")); - } - }, - }; - let wasm_path = format!("{}.wasm", process.process()); - let package = PackageId::new(process.package(), process.publisher()); - match handle_run(&state.our, &package, wasm_path, args.to_string()) { - Ok(_) => Ok(()), // TODO clean up process - Err(e) => Err(anyhow!("failed to instantiate script: {}", e)), - } - } - _ => return Err(anyhow!("invalid command: \"{line}\"")), + }, + }; + + let wasm_path = format!("{}.wasm", process.process()); + let package = PackageId::new(process.package(), process.publisher()); + match handle_run(&state.our, &package, wasm_path, args.to_string()) { + Ok(_) => Ok(()), // TODO clean up process + Err(e) => Err(anyhow!("failed to instantiate script: {}", e)), } } @@ -104,10 +61,26 @@ impl Guest for Component { current_target: None, aliases: { let mut a = HashMap::new(); + a.insert( + "cat".to_string(), + "cat:terminal:sys".parse::().unwrap(), + ); a.insert( "echo".to_string(), "echo:terminal:sys".parse::().unwrap(), ); + a.insert( + "hi".to_string(), + "hi:terminal:sys".parse::().unwrap(), + ); + a.insert( + "m".to_string(), + "m:terminal:sys".parse::().unwrap(), + ); + a.insert( + "top".to_string(), + "top:terminal:sys".parse::().unwrap(), + ); a }, }; @@ -249,7 +222,14 @@ fn handle_run( wasm_bytes_handle: wasm_path, wit_version: None, on_exit: kt::OnExit::None, // TODO this should send a message back to runner:script:sys so that it can Drop capabilities - initial_capabilities, + initial_capabilities: if entry.root { + our_capabilities() + .iter() + .map(|wit: &kinode_process_lib::Capability| kt::de_wit_capability(wit.clone())) + .collect() + } else { + initial_capabilities + }, public: entry.public, })?) .inherit(true) From 41d130e5e4b18448d0eb7f71d8e89a06e6635728 Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Mon, 22 Jan 2024 11:35:38 -0600 Subject: [PATCH 17/21] scripts updated to latest process_lib --- modules/terminal/cat/Cargo.lock | 4 ++-- modules/terminal/cat/Cargo.toml | 2 +- modules/terminal/cat/src/lib.rs | 9 ++++----- modules/terminal/echo/Cargo.lock | 4 ++-- modules/terminal/echo/Cargo.toml | 2 +- modules/terminal/echo/src/lib.rs | 9 ++++----- modules/terminal/hi/Cargo.lock | 4 ++-- modules/terminal/hi/Cargo.toml | 2 +- modules/terminal/hi/src/lib.rs | 11 ++++++----- modules/terminal/m/Cargo.lock | 4 ++-- modules/terminal/m/Cargo.toml | 2 +- modules/terminal/m/src/lib.rs | 11 +++++------ modules/terminal/terminal/Cargo.lock | 4 ++-- modules/terminal/terminal/Cargo.toml | 2 +- modules/terminal/terminal/src/lib.rs | 16 +--------------- modules/terminal/top/Cargo.lock | 4 ++-- modules/terminal/top/Cargo.toml | 2 +- modules/terminal/top/src/lib.rs | 11 ++++++----- 18 files changed, 44 insertions(+), 59 deletions(-) diff --git a/modules/terminal/cat/Cargo.lock b/modules/terminal/cat/Cargo.lock index 15ab7395..ed8f770f 100644 --- a/modules/terminal/cat/Cargo.lock +++ b/modules/terminal/cat/Cargo.lock @@ -139,8 +139,8 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "kinode_process_lib" -version = "0.5.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=9790c0f#9790c0fecc64572d1fbeecdf3724eb37b3d6d3fa" +version = "0.5.5" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=329c7a8#329c7a8314973c857db38c7b712318de9349eb6e" dependencies = [ "anyhow", "bincode", diff --git a/modules/terminal/cat/Cargo.toml b/modules/terminal/cat/Cargo.toml index 7586ced2..39a82b32 100644 --- a/modules/terminal/cat/Cargo.toml +++ b/modules/terminal/cat/Cargo.toml @@ -10,7 +10,7 @@ lto = true [dependencies] anyhow = "1.0" -kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "9790c0f" } +kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "329c7a8" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } diff --git a/modules/terminal/cat/src/lib.rs b/modules/terminal/cat/src/lib.rs index 2a8f8ec0..40387525 100644 --- a/modules/terminal/cat/src/lib.rs +++ b/modules/terminal/cat/src/lib.rs @@ -1,5 +1,5 @@ use kinode_process_lib::{ - await_message, call_init, get_blob, println, vfs, Address, Message, Request, + await_next_request_body, call_init, get_blob, println, vfs, Address, Request, }; wit_bindgen::generate!({ @@ -13,13 +13,12 @@ wit_bindgen::generate!({ call_init!(init); fn init(_our: Address) { - // TODO will need to package this up into a process lib function that makes it easy - let Ok(Message::Request { body, .. }) = await_message() else { - println!("got send error, failing out"); + let Ok(args) = await_next_request_body() else { + println!("cat: failed to get args, aborting"); return; }; - let Ok(file_path) = String::from_utf8(body) else { + let Ok(file_path) = String::from_utf8(args) else { println!("bad file path"); return; }; diff --git a/modules/terminal/echo/Cargo.lock b/modules/terminal/echo/Cargo.lock index 03cabc96..3c6814bf 100644 --- a/modules/terminal/echo/Cargo.lock +++ b/modules/terminal/echo/Cargo.lock @@ -139,8 +139,8 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "kinode_process_lib" -version = "0.5.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=9790c0f#9790c0fecc64572d1fbeecdf3724eb37b3d6d3fa" +version = "0.5.5" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=329c7a8#329c7a8314973c857db38c7b712318de9349eb6e" dependencies = [ "anyhow", "bincode", diff --git a/modules/terminal/echo/Cargo.toml b/modules/terminal/echo/Cargo.toml index ca8a4c0c..259b24ce 100644 --- a/modules/terminal/echo/Cargo.toml +++ b/modules/terminal/echo/Cargo.toml @@ -10,7 +10,7 @@ lto = true [dependencies] anyhow = "1.0" -kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "9790c0f" } +kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "329c7a8" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } diff --git a/modules/terminal/echo/src/lib.rs b/modules/terminal/echo/src/lib.rs index b42c8633..12eae687 100644 --- a/modules/terminal/echo/src/lib.rs +++ b/modules/terminal/echo/src/lib.rs @@ -1,4 +1,4 @@ -use kinode_process_lib::{await_message, call_init, println, Address, Message}; +use kinode_process_lib::{await_next_request_body, call_init, println, Address}; wit_bindgen::generate!({ path: "wit", @@ -11,11 +11,10 @@ wit_bindgen::generate!({ call_init!(init); fn init(_our: Address) { - // TODO will need to package this up into a process lib function that makes it easy - let Ok(Message::Request { body, .. }) = await_message() else { - println!("got send error, failing out"); + let Ok(args) = await_next_request_body() else { + println!("echo: failed to get args, aborting"); return; }; - println!("{}", String::from_utf8(body).unwrap()); + println!("{}", String::from_utf8(args).unwrap()); } diff --git a/modules/terminal/hi/Cargo.lock b/modules/terminal/hi/Cargo.lock index 75b28183..50b34b89 100644 --- a/modules/terminal/hi/Cargo.lock +++ b/modules/terminal/hi/Cargo.lock @@ -138,8 +138,8 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "kinode_process_lib" -version = "0.5.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=9790c0f#9790c0fecc64572d1fbeecdf3724eb37b3d6d3fa" +version = "0.5.5" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=329c7a8#329c7a8314973c857db38c7b712318de9349eb6e" dependencies = [ "anyhow", "bincode", diff --git a/modules/terminal/hi/Cargo.toml b/modules/terminal/hi/Cargo.toml index 65dda4a9..54c9ea63 100644 --- a/modules/terminal/hi/Cargo.toml +++ b/modules/terminal/hi/Cargo.toml @@ -9,7 +9,7 @@ opt-level = "s" lto = true [dependencies] -kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "9790c0f" } +kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "329c7a8" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } diff --git a/modules/terminal/hi/src/lib.rs b/modules/terminal/hi/src/lib.rs index 4a5b3c90..f46c0253 100644 --- a/modules/terminal/hi/src/lib.rs +++ b/modules/terminal/hi/src/lib.rs @@ -1,4 +1,6 @@ -use kinode_process_lib::{await_message, call_init, println, Address, Message, Request, SendError}; +use kinode_process_lib::{ + await_next_request_body, call_init, println, Address, Request, SendError, +}; wit_bindgen::generate!({ path: "wit", @@ -11,13 +13,12 @@ wit_bindgen::generate!({ call_init!(init); fn init(our: Address) { - // TODO will need to package this up into a process lib function that makes it easy - let Ok(Message::Request { body, .. }) = await_message() else { - println!("got send error, failing out"); + let Ok(args) = await_next_request_body() else { + println!("hi: failed to get args, aborting"); return; }; - let tail = String::from_utf8(body).unwrap(); + let tail = String::from_utf8(args).unwrap(); let (node_id, message) = match tail.split_once(" ") { Some((s, t)) => (s, t), diff --git a/modules/terminal/m/Cargo.lock b/modules/terminal/m/Cargo.lock index 518b682c..a2ed6b61 100644 --- a/modules/terminal/m/Cargo.lock +++ b/modules/terminal/m/Cargo.lock @@ -128,8 +128,8 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "kinode_process_lib" -version = "0.5.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=9790c0f#9790c0fecc64572d1fbeecdf3724eb37b3d6d3fa" +version = "0.5.5" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=329c7a8#329c7a8314973c857db38c7b712318de9349eb6e" dependencies = [ "anyhow", "bincode", diff --git a/modules/terminal/m/Cargo.toml b/modules/terminal/m/Cargo.toml index 72ee9261..a7a64421 100644 --- a/modules/terminal/m/Cargo.toml +++ b/modules/terminal/m/Cargo.toml @@ -10,7 +10,7 @@ lto = true [dependencies] anyhow = "1.0" -kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "9790c0f" } +kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "329c7a8" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } diff --git a/modules/terminal/m/src/lib.rs b/modules/terminal/m/src/lib.rs index c4929ddb..ce59104b 100644 --- a/modules/terminal/m/src/lib.rs +++ b/modules/terminal/m/src/lib.rs @@ -1,4 +1,4 @@ -use kinode_process_lib::{await_message, call_init, println, Address, Message, Request}; +use kinode_process_lib::{await_next_request_body, call_init, println, Address, Request}; wit_bindgen::generate!({ path: "wit", @@ -11,13 +11,12 @@ wit_bindgen::generate!({ call_init!(init); fn init(_our: Address) { - // TODO will need to package this up into a process lib function that makes it easy - let Ok(Message::Request { body, .. }) = await_message() else { - println!("got send error, failing out"); + let Ok(args) = await_next_request_body() else { + println!("m: failed to get args, aborting"); return; }; - let tail = String::from_utf8(body).unwrap(); + let tail = String::from_utf8(args).unwrap(); let (target, body) = match tail.split_once(" ") { Some((a, p)) => (a, p), @@ -29,7 +28,7 @@ fn init(_our: Address) { // TODO aliasing logic...maybe we can read from terminal state since we have root? let target = match target.parse::
() { Ok(t) => t, - Err(e) => { + Err(_) => { println!("invalid address: \"{target}\""); return; } // match state.aliases.get(target) { diff --git a/modules/terminal/terminal/Cargo.lock b/modules/terminal/terminal/Cargo.lock index 6d0344fb..783b1852 100644 --- a/modules/terminal/terminal/Cargo.lock +++ b/modules/terminal/terminal/Cargo.lock @@ -128,8 +128,8 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "kinode_process_lib" -version = "0.5.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?tag=v0.5.3-alpha#8de14aa7132e6b7992c720c6aae24a64e108779d" +version = "0.5.5" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=329c7a8#329c7a8314973c857db38c7b712318de9349eb6e" dependencies = [ "anyhow", "bincode", diff --git a/modules/terminal/terminal/Cargo.toml b/modules/terminal/terminal/Cargo.toml index d6c19221..d8723eca 100644 --- a/modules/terminal/terminal/Cargo.toml +++ b/modules/terminal/terminal/Cargo.toml @@ -16,7 +16,7 @@ bincode = "1.3.3" rand = "0.8" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", tag = "v0.5.3-alpha" } +kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "329c7a8" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } [lib] diff --git a/modules/terminal/terminal/src/lib.rs b/modules/terminal/terminal/src/lib.rs index b5d0ed63..f6b5a6fe 100644 --- a/modules/terminal/terminal/src/lib.rs +++ b/modules/terminal/terminal/src/lib.rs @@ -5,7 +5,6 @@ use kinode_process_lib::{ get_blob, get_capability, our_capabilities, println, vfs, Address, Capability, PackageId, ProcessId, Request, }; -use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; wit_bindgen::generate!({ @@ -16,20 +15,8 @@ wit_bindgen::generate!({ }, }); -// TODO move this into kt:: -#[derive(Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct DotScriptsEntry { - pub root: bool, - pub public: bool, - pub request_networking: bool, - pub request_capabilities: Option>, - pub grant_capabilities: Option>, -} - struct TerminalState { our: Address, - current_target: Option
, aliases: HashMap, // TODO maybe address... } @@ -58,7 +45,6 @@ impl Guest for Component { fn init(our: String) { let mut state = TerminalState { our: our.parse::
().unwrap(), - current_target: None, aliases: { let mut a = HashMap::new(); a.insert( @@ -136,7 +122,7 @@ fn handle_run( )); }; let dot_scripts = String::from_utf8(blob.bytes)?; - let dot_scripts = serde_json::from_str::>(&dot_scripts)?; + let dot_scripts = serde_json::from_str::>(&dot_scripts)?; let Some(entry) = dot_scripts.get(&wasm_path) else { return Err(anyhow::anyhow!("script not in scripts.json file")); }; diff --git a/modules/terminal/top/Cargo.lock b/modules/terminal/top/Cargo.lock index 46692fbb..cc8708b9 100644 --- a/modules/terminal/top/Cargo.lock +++ b/modules/terminal/top/Cargo.lock @@ -128,8 +128,8 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "kinode_process_lib" -version = "0.5.0" -source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=9790c0f#9790c0fecc64572d1fbeecdf3724eb37b3d6d3fa" +version = "0.5.5" +source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=329c7a8#329c7a8314973c857db38c7b712318de9349eb6e" dependencies = [ "anyhow", "bincode", diff --git a/modules/terminal/top/Cargo.toml b/modules/terminal/top/Cargo.toml index 9369c45c..edf86c21 100644 --- a/modules/terminal/top/Cargo.toml +++ b/modules/terminal/top/Cargo.toml @@ -10,7 +10,7 @@ lto = true [dependencies] anyhow = "1.0" -kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "9790c0f" } +kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "329c7a8" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } diff --git a/modules/terminal/top/src/lib.rs b/modules/terminal/top/src/lib.rs index f994c8ed..7bf1d31c 100644 --- a/modules/terminal/top/src/lib.rs +++ b/modules/terminal/top/src/lib.rs @@ -1,5 +1,7 @@ use kinode_process_lib::kernel_types::{KernelCommand, KernelPrint}; -use kinode_process_lib::{await_message, call_init, println, Address, Message, ProcessId, Request}; +use kinode_process_lib::{ + await_next_request_body, call_init, println, Address, ProcessId, Request, +}; wit_bindgen::generate!({ path: "wit", @@ -12,13 +14,12 @@ wit_bindgen::generate!({ call_init!(init); fn init(_our: Address) { - // TODO will need to package this up into a process lib function that makes it easy - let Ok(Message::Request { body, .. }) = await_message() else { - println!("got send error, failing out"); + let Ok(args) = await_next_request_body() else { + println!("top: failed to get args, aborting"); return; }; - let proc_id = String::from_utf8(body).unwrap(); + let proc_id = String::from_utf8(args).unwrap(); let kernel_addr = Address::new("our", ("kernel", "distro", "sys")); let _ = Request::new() From 5c47cebf07b835ca41e2ff91873cb2e1e23a53fe Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Mon, 22 Jan 2024 11:53:32 -0600 Subject: [PATCH 18/21] updated README.md --- README.md | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 664e6171..4234e02c 100644 --- a/README.md +++ b/README.md @@ -84,28 +84,32 @@ The `sys` publisher is not a real node ID, but it's also not a special case valu - UpArrow/DownArrow or CTRL+P/CTRL+N to move up and down through command history - CTRL+R to search history, CTRL+R again to toggle through search results, CTRL+G to cancel search -- `/message
`: send an inter-process message.
is formatted as @. is formatted as ::. - - Example: `/message our@net:distro:sys diagnostics` +- `m
`: send an inter-process message.
is formatted as @. is formatted as ::. + - Example: `m our@net:distro:sys diagnostics` - `our` will always be interpolated by the system as your node's name - - Can also use `/m` for same command: `/m our@net:distro:sys diagnostics` -- `/app
`: set the terminal to a mode where all messages go to a specific app. To clear this selection, use `/app clear` or simply `/app`. This is useful for apps that have a command line interface. + - Can also use `m` for same command: `m our@net:distro:sys diagnostics` + +- `hi `: send a text message to another node's command line. + - Example: `hi ben.os hello world` +- `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` +- `cat `: print the contents of a file in the terminal + - Example: `cat /terminal:sys/pkg/scripts.json` +- `echo `: print `text` to the terminal + - Example: `echo foo` ### Terminal example usage Download and install an app: ``` -/m our@main:app_store:sys {"Download": {"package": {"package_name": "", "publisher_node": ""}, "install_from": ""}} -/m our@main:app_store:sys {"Install": {"package_name": "", "publisher_node": ""}} +m our@main:app_store:sys {"Download": {"package": {"package_name": "", "publisher_node": ""}, "install_from": ""}} +m our@main:app_store:sys {"Install": {"package_name": "", "publisher_node": ""}} ``` From 0711c32a746b51cf480f6e2542fcf6293917e6a0 Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Mon, 22 Jan 2024 12:46:56 -0600 Subject: [PATCH 19/21] requested changes --- modules/terminal/echo/src/lib.rs | 5 +++- modules/terminal/hi/src/lib.rs | 2 +- modules/terminal/m/src/lib.rs | 4 +-- modules/terminal/terminal/src/lib.rs | 26 +++++++++---------- modules/terminal/top/src/lib.rs | 38 +++++++++++++++++++--------- 5 files changed, 45 insertions(+), 30 deletions(-) diff --git a/modules/terminal/echo/src/lib.rs b/modules/terminal/echo/src/lib.rs index 12eae687..b287a971 100644 --- a/modules/terminal/echo/src/lib.rs +++ b/modules/terminal/echo/src/lib.rs @@ -16,5 +16,8 @@ fn init(_our: Address) { return; }; - println!("{}", String::from_utf8(args).unwrap()); + println!( + "{}", + String::from_utf8(args).unwrap_or("echo: error".into()) + ); } diff --git a/modules/terminal/hi/src/lib.rs b/modules/terminal/hi/src/lib.rs index f46c0253..71d09035 100644 --- a/modules/terminal/hi/src/lib.rs +++ b/modules/terminal/hi/src/lib.rs @@ -23,7 +23,7 @@ fn init(our: Address) { let (node_id, message) = match tail.split_once(" ") { Some((s, t)) => (s, t), None => { - println!("invalid command: \"{tail}\""); + println!("hi: invalid command, please provide a message"); return; } }; diff --git a/modules/terminal/m/src/lib.rs b/modules/terminal/m/src/lib.rs index ce59104b..fd6dcae6 100644 --- a/modules/terminal/m/src/lib.rs +++ b/modules/terminal/m/src/lib.rs @@ -21,7 +21,7 @@ fn init(_our: Address) { let (target, body) = match tail.split_once(" ") { Some((a, p)) => (a, p), None => { - println!("invalid command: \"{tail}\""); + println!("m: invalid command, please provide an address and json message"); return; } }; @@ -38,5 +38,5 @@ fn init(_our: Address) { // } // }, }; - let _ = Request::new().target(target).body(body).send(); + let _ = Request::new().target(target).body(body).send().unwrap(); } diff --git a/modules/terminal/terminal/src/lib.rs b/modules/terminal/terminal/src/lib.rs index f6b5a6fe..b7699531 100644 --- a/modules/terminal/terminal/src/lib.rs +++ b/modules/terminal/terminal/src/lib.rs @@ -45,30 +45,28 @@ impl Guest for Component { fn init(our: String) { let mut state = TerminalState { our: our.parse::
().unwrap(), - aliases: { - let mut a = HashMap::new(); - a.insert( + aliases: HashMap::from([ + ( "cat".to_string(), "cat:terminal:sys".parse::().unwrap(), - ); - a.insert( + ), + ( "echo".to_string(), "echo:terminal:sys".parse::().unwrap(), - ); - a.insert( + ), + ( "hi".to_string(), "hi:terminal:sys".parse::().unwrap(), - ); - a.insert( + ), + ( "m".to_string(), "m:terminal:sys".parse::().unwrap(), - ); - a.insert( + ), + ( "top".to_string(), "top:terminal:sys".parse::().unwrap(), - ); - a - }, + ), + ]), }; loop { let (source, message) = match wit::receive() { diff --git a/modules/terminal/top/src/lib.rs b/modules/terminal/top/src/lib.rs index 7bf1d31c..2bcbe25a 100644 --- a/modules/terminal/top/src/lib.rs +++ b/modules/terminal/top/src/lib.rs @@ -19,17 +19,31 @@ fn init(_our: Address) { return; }; - let proc_id = String::from_utf8(args).unwrap(); + let Ok(proc_id) = String::from_utf8(args) else { + println!("top: failed to stringify arguments"); + return; + }; - let kernel_addr = Address::new("our", ("kernel", "distro", "sys")); - let _ = Request::new() - .target(kernel_addr) - .body( - serde_json::to_vec(&match proc_id.parse::() { - Ok(proc_id) => KernelCommand::Debug(KernelPrint::Process(proc_id)), - Err(_) => KernelCommand::Debug(KernelPrint::ProcessMap), - }) - .unwrap(), - ) - .send(); + if proc_id.is_empty() { + let _ = Request::new() + .target(("our", "kernel", "distro", "sys")) + .body(serde_json::to_vec(&KernelCommand::Debug(KernelPrint::ProcessMap)).unwrap()) + .send(); + } else { + match proc_id.parse::() { + Ok(proc_id) => { + let _ = Request::new() + .target(("our", "kernel", "distro", "sys")) + .body( + serde_json::to_vec(&KernelCommand::Debug(KernelPrint::Process(proc_id))) + .unwrap(), + ) + .send(); + } + Err(_) => { + println!("top: invalid process id"); + return; + } + } + } } From a6462d4d64d1f4b75df29e3cd95040a563e9a9e0 Mon Sep 17 00:00:00 2001 From: Drew Tada Date: Mon, 22 Jan 2024 12:48:35 -0600 Subject: [PATCH 20/21] updated README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 4234e02c..f737c7d0 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,6 @@ The `sys` publisher is not a real node ID, but it's also not a special case valu - `m
`: send an inter-process message.
is formatted as @. is formatted as ::. - Example: `m our@net:distro:sys diagnostics` - `our` will always be interpolated by the system as your node's name - - Can also use `m` for same command: `m our@net:distro:sys diagnostics` - `hi `: send a text message to another node's command line. - Example: `hi ben.os hello world` - `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.