diff --git a/README.md b/README.md index 161bef66..8abf877f 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,10 @@ reads this file to locate the right asset for the host. See [`AGENTS-NEW-WORKER.md`](AGENTS-NEW-WORKER.md) for the full checklist covering folder layout, `iii.worker.yaml`, lint, tests, deploy type (`binary` vs. `image`), and the release flow. +[`binary-worker.md`](binary-worker.md) goes deeper for the Rust binary +scaffold; [`worker-readme.md`](worker-readme.md) covers the README +contract every worker shares (install via `iii worker add`, run via +`iii start`, how-to over reference). ## CI diff --git a/skills/Cargo.lock b/skills/Cargo.lock new file mode 100644 index 00000000..6c77166e --- /dev/null +++ b/skills/Cargo.lock @@ -0,0 +1,3242 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anstyle-parse" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.61.2", +] + +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "async-trait" +version = "0.1.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bstr" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63044e1ae8e69f3b5a92c736ca6269b8d12fa7efe39bf34ddb06d102cf0e2cab" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "bumpalo" +version = "3.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" + +[[package]] +name = "bytecount" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "175812e0be2bccb6abe50bb8d566126198344f707e304f45c648fd8f2cc0365e" + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + +[[package]] +name = "cc" +version = "1.2.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d16d90359e986641506914ba71350897565610e87ce0ad9e6f28569db3dd5c6d" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "chrono" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "clap" +version = "4.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ddb117e43bbf7dacf0a4190fef4d345b9bad68dfc649cb349e7d17d28428e51" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", + "terminal_size", +] + +[[package]] +name = "clap_derive" +version = "4.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2ce8604710f6733aa641a2b3731eaa1e8b3d9973d5e3565da11800813f997a9" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" + +[[package]] +name = "colorchoice" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" + +[[package]] +name = "console" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d64e8af5551369d19cf50138de61f1c42074ab970f74e99be916646777f8fc87" +dependencies = [ + "encode_unicode", + "libc", + "unicode-width", + "windows-sys 0.61.2", +] + +[[package]] +name = "const-hex" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20d9a563d167a9cce0f94153382b33cb6eded6dfabff03c69ad65a28ea1514e0" +dependencies = [ + "cfg-if", + "cpufeatures", + "proptest", + "serde_core", +] + +[[package]] +name = "convert_case" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "633458d4ef8c78b72454de2d54fd6ab2e60f9e02be22f3c6104cdc8a4e0fceb9" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "cucumber" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16cbb27bc2064274afa3a3d8bc9a0e71333589850573aa632ec4520e4af14d94" +dependencies = [ + "anyhow", + "clap", + "console", + "cucumber-codegen", + "cucumber-expressions", + "derive_more", + "either", + "futures", + "gherkin", + "globwalk", + "humantime", + "inventory", + "itertools", + "linked-hash-map", + "pin-project", + "ref-cast", + "regex", + "sealed", + "smart-default", +] + +[[package]] +name = "cucumber-codegen" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a1afaf9c422380861111c6be56f39b324e351fd9efc07a1486268798bf79cfd" +dependencies = [ + "cucumber-expressions", + "inflections", + "itertools", + "proc-macro2", + "quote", + "regex", + "syn", + "synthez", +] + +[[package]] +name = "cucumber-expressions" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6401038de3af44fe74e6fccdb8a5b7db7ba418f480c8e9ad584c6f65c05a27a6" +dependencies = [ + "derive_more", + "either", + "nom", + "nom_locate", + "regex", + "regex-syntax", +] + +[[package]] +name = "data-encoding" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4ae5f15dda3c708c0ade84bfee31ccab44a3da4f88015ed22f63732abe300c8" + +[[package]] +name = "derive_more" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d751e9e49156b02b44f9c1815bcb94b984cdcc4396ecc32521c739452808b134" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn", + "unicode-xid", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dyn-clone" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + +[[package]] +name = "encode_unicode" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "fastrand" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-executor" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf29c38818342a3b26b5b923639e7b1f4a61fc5e76102d4b1981c6dc7a7579d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718" + +[[package]] +name = "futures-macro" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi 5.3.0", + "wasip2", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +dependencies = [ + "cfg-if", + "libc", + "r-efi 6.0.0", + "wasip2", + "wasip3", +] + +[[package]] +name = "gherkin" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70197ce7751bfe8bc828e3a855502d3a869a1e9416b58b10c4bde5cf8a0a3cb3" +dependencies = [ + "heck", + "peg", + "quote", + "serde", + "serde_json", + "syn", + "textwrap", + "thiserror", + "typed-builder", +] + +[[package]] +name = "globset" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52dfc19153a48bde0cbd630453615c8151bce3a5adfac7a0aebfbf0a1e1f57e3" +dependencies = [ + "aho-corasick", + "bstr", + "log", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "globwalk" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf760ebf69878d9fd8f110c89703d90ce35095324d1f1edcb595c63945ee757" +dependencies = [ + "bitflags", + "ignore", + "walkdir", +] + +[[package]] +name = "h2" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f44da3a8150a6703ed5d34e164b875fd14c2cdab9af1252a9a1020bde2bdc54" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hostname" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "617aaa3557aef3810a6369d0a99fac8a080891b68bd9f9812a1eeda0c0730cbd" +dependencies = [ + "cfg-if", + "libc", + "windows-link", +] + +[[package]] +name = "http" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "humantime" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "135b12329e5e3ce057a9f972339ea52bc954fe1e9358ef27f95e89716fbc5424" + +[[package]] +name = "hyper" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6299f016b246a94207e63da54dbe807655bf9e00044f73ded42c3ac5305fbcca" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-timeout" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0" +dependencies = [ + "hyper", + "hyper-util", + "pin-project-lite", + "tokio", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2984d1cd16c883d7935b9e07e44071dca8d917fd52ecc02c04d5fa0b5a3f191c" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c56e5ee99d6e3d33bd91c5d85458b6005a22140021cc324cea84dd0e72cff3b4" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da3be0ae77ea334f4da67c12f149704f19f81d1adf7c51cf482943e84a2bad38" + +[[package]] +name = "icu_properties" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bee3b67d0ea5c2cca5003417989af8996f8604e34fb9ddf96208a033901e70de" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14" + +[[package]] +name = "icu_provider" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "ignore" +version = "0.4.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3d782a365a015e0f5c04902246139249abf769125006fbe7649e2ee88169b4a" +dependencies = [ + "crossbeam-deque", + "globset", + "log", + "memchr", + "regex-automata", + "same-file", + "walkdir", + "winapi-util", +] + +[[package]] +name = "iii-sdk" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0226f7ce0d9071f9cb75ea7b7ac1241b15282915ccd41d9bbd2ee0db94f90c6" +dependencies = [ + "async-trait", + "futures-util", + "hostname", + "opentelemetry", + "opentelemetry-http", + "opentelemetry-proto", + "opentelemetry_sdk", + "prost", + "reqwest", + "schemars", + "serde", + "serde_json", + "sysinfo", + "thiserror", + "tokio", + "tokio-tungstenite", + "tracing", + "uuid", +] + +[[package]] +name = "skills" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "chrono", + "clap", + "cucumber", + "futures", + "iii-sdk", + "schemars", + "serde", + "serde_json", + "serde_yaml", + "tempfile", + "thiserror", + "tokio", + "tracing", + "tracing-subscriber", + "uuid", +] + +[[package]] +name = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown 0.17.0", + "serde", + "serde_core", +] + +[[package]] +name = "inflections" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a257582fdcde896fd96463bf2d40eefea0580021c0712a0e2b028b60b47a837a" + +[[package]] +name = "inventory" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4f0c30c76f2f4ccee3fe55a2435f691ca00c0e4bd87abe4f4a851b1d4dac39b" +dependencies = [ + "rustversion", +] + +[[package]] +name = "ipnet" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" + +[[package]] +name = "iri-string" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25e659a4bb38e810ebc252e53b5814ff908a8c58c2a9ce2fae1bbec24cbf4e20" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "js-sys" +version = "0.3.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1840c94c045fbcf8ba2812c95db44499f7c64910a912551aaaa541decebcacf" +dependencies = [ + "cfg-if", + "futures-util", + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "libc" +version = "0.2.186" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" + +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "litemap" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "mio" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "nom" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405" +dependencies = [ + "memchr", +] + +[[package]] +name = "nom_locate" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b577e2d69827c4740cba2b52efaad1c4cc7c73042860b199710b3575c68438d" +dependencies = [ + "bytecount", + "memchr", + "nom", +] + +[[package]] +name = "ntapi" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3b335231dfd352ffb0f8017f3b6027a4917f7df785ea2143d8af2adc66980ae" +dependencies = [ + "winapi", +] + +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "objc2-core-foundation" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536" +dependencies = [ + "bitflags", +] + +[[package]] +name = "objc2-io-kit" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33fafba39597d6dc1fb709123dfa8289d39406734be322956a69f0931c73bb15" +dependencies = [ + "libc", + "objc2-core-foundation", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] +name = "openssl-probe" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + +[[package]] +name = "opentelemetry" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b84bcd6ae87133e903af7ef497404dda70c60d0ea14895fc8a5e6722754fc2a0" +dependencies = [ + "futures-core", + "futures-sink", + "js-sys", + "pin-project-lite", + "thiserror", + "tracing", +] + +[[package]] +name = "opentelemetry-http" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7a6d09a73194e6b66df7c8f1b680f156d916a1a942abf2de06823dd02b7855d" +dependencies = [ + "async-trait", + "bytes", + "http", + "opentelemetry", + "reqwest", +] + +[[package]] +name = "opentelemetry-proto" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7175df06de5eaee9909d4805a3d07e28bb752c34cab57fa9cff549da596b30f" +dependencies = [ + "base64", + "const-hex", + "opentelemetry", + "opentelemetry_sdk", + "prost", + "serde", + "serde_json", + "tonic", + "tonic-prost", +] + +[[package]] +name = "opentelemetry_sdk" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14ae4f5991976fd48df6d843de219ca6d31b01daaab2dad5af2badeded372bd" +dependencies = [ + "futures-channel", + "futures-executor", + "futures-util", + "opentelemetry", + "percent-encoding", + "rand", + "thiserror", + "tokio", + "tokio-stream", +] + +[[package]] +name = "peg" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f76678828272f177ac33b7e2ac2e3e73cc6c1cd1e3e387928aa69562fa51367" +dependencies = [ + "peg-macros", + "peg-runtime", +] + +[[package]] +name = "peg-macros" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "636d60acf97633e48d266d7415a9355d4389cea327a193f87df395d88cd2b14d" +dependencies = [ + "peg-runtime", + "proc-macro2", + "quote", +] + +[[package]] +name = "peg-runtime" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9555b1514d2d99d78150d3c799d4c357a3e2c2a8062cd108e93a06d9057629c5" + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project" +version = "1.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1749c7ed4bcaf4c3d0a3efc28538844fb29bcdd7d2b67b2be7e20ba861ff517" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b20ed30f105399776b9c883e68e536ef602a16ae6f596d2c473591d6ad64c6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "potential_utf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564" +dependencies = [ + "zerovec", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "proptest" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b45fcc2344c680f5025fe57779faef368840d0bd1f42f216291f0dc4ace4744" +dependencies = [ + "bitflags", + "num-traits", + "rand", + "rand_chacha", + "rand_xorshift", + "regex-syntax", + "unarray", +] + +[[package]] +name = "prost" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ea70524a2f82d518bce41317d0fae74151505651af45faf1ffbd6fd33f0568" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27c6023962132f4b30eb4c172c91ce92d933da334c59c23cddee82358ddafb0b" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "quinn" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "434b42fec591c96ef50e21e886936e66d3cc3f737104fdb9b737c40ffb94c098" +dependencies = [ + "bytes", + "getrandom 0.3.4", + "lru-slab", + "rand", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.60.2", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rand" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c5af06bb1b7d3216d91932aed5265164bf384dc89cd6ba05cf59a35f5f76ea" +dependencies = [ + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", +] + +[[package]] +name = "rand_xorshift" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a" +dependencies = [ + "rand_core", +] + +[[package]] +name = "ref-cast" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f354300ae66f76f1c85c5f84693f0ce81d747e2c3f21a45fef496d89c960bf7d" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7186006dcb21920990093f30e3dea63b7d6e977bf1256be20c3563a5db070da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "regex" +version = "1.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" + +[[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64", + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-hash" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls" +version = "0.23.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef86cd5876211988985292b91c96a8f2d298df24e75989a43a3c73f2d4d8168b" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-native-certs" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "612460d5f7bea540c490b2b6395d8e34a953e52b491accd6c86c8164c5932a63" +dependencies = [ + "openssl-probe", + "rustls-pki-types", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pki-types" +version = "1.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30a7197ae7eb376e574fe940d068c30fe0462554a3ddbe4eca7838e049c937a9" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schannel" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91c1b7e4904c873ef0710c1f407dde2e6287de2bebc1bbbf7d430bb7cbffd939" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "schemars" +version = "0.8.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fbf2ae1b8bc8e02df939598064d22402220cd5bbcca1c76f7d6a310974d5615" +dependencies = [ + "chrono", + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", + "uuid", +] + +[[package]] +name = "schemars_derive" +version = "0.8.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32e265784ad618884abaea0600a9adf15393368d840e0222d101a072f3f7534d" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn", +] + +[[package]] +name = "sealed" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22f968c5ea23d555e670b449c1c5e7b2fc399fdaec1d304a17cd48e288abc107" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "security-framework" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_derive_internals" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_yaml" +version = "0.9.34+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "smart-default" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eb01866308440fc64d6c44d9e86c5cc17adfe33c4d6eed55da9145044d0ffc1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "smawk" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c" + +[[package]] +name = "socket2" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "synthez" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d8a928f38f1bc873f28e0d2ba8298ad65374a6ac2241dabd297271531a736cd" +dependencies = [ + "syn", + "synthez-codegen", + "synthez-core", +] + +[[package]] +name = "synthez-codegen" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fb83b8df4238e11746984dfb3819b155cd270de0e25847f45abad56b3671047" +dependencies = [ + "syn", + "synthez-core", +] + +[[package]] +name = "synthez-core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "906fba967105d822e7c7ed60477b5e76116724d33de68a585681fb253fc30d5c" +dependencies = [ + "proc-macro2", + "quote", + "sealed", + "syn", +] + +[[package]] +name = "sysinfo" +version = "0.38.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ab6a2f8bfe508deb3c6406578252e491d299cbbf3bc0529ecc3313aee4a52f" +dependencies = [ + "libc", + "memchr", + "ntapi", + "objc2-core-foundation", + "objc2-io-kit", + "windows", +] + +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom 0.4.2", + "once_cell", + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "terminal_size" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "230a1b821ccbd75b185820a1f1ff7b14d21da1e442e22c0863ea5f08771a8874" +dependencies = [ + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "textwrap" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c13547615a44dc9c452a8a534638acdf07120d4b6847c8178705da06306a3057" +dependencies = [ + "smawk", + "unicode-linebreak", + "unicode-width", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "tinystr" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e61e67053d25a4e82c844e8424039d9745781b3fc4f32b8d55ed50f5f667ef3" +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 = "tokio" +version = "1.52.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67dee974fe86fd92cc45b7a95fdd2f99a36a6d7b0d431a231178d3d670bbcc6" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32da49809aab5c3bc678af03902d4ccddea2a87d028d86392a4b1560c6906c70" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-tungstenite" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d25a406cddcc431a75d3d9afc6a7c0f7428d4891dd973e4d54c56b46127bf857" +dependencies = [ + "futures-util", + "log", + "rustls", + "rustls-native-certs", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tungstenite", +] + +[[package]] +name = "tokio-util" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tonic" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fec7c61a0695dc1887c1b53952990f3ad2e3a31453e1f49f10e75424943a93ec" +dependencies = [ + "async-trait", + "base64", + "bytes", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-timeout", + "hyper-util", + "percent-encoding", + "pin-project", + "sync_wrapper", + "tokio", + "tokio-stream", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tonic-prost" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a55376a0bbaa4975a3f10d009ad763d8f4108f067c7c2e74f3001fb49778d309" +dependencies = [ + "bytes", + "prost", + "tonic", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "indexmap", + "pin-project-lite", + "slab", + "sync_wrapper", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "iri-string", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex-automata", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "tungstenite" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8628dcc84e5a09eb3d8423d6cb682965dea9133204e8fb3efee74c2a0c259442" +dependencies = [ + "bytes", + "data-encoding", + "http", + "httparse", + "log", + "rand", + "rustls", + "rustls-pki-types", + "sha1", + "thiserror", + "utf-8", +] + +[[package]] +name = "typed-builder" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31aa81521b70f94402501d848ccc0ecaa8f93c8eb6999eb9747e72287757ffda" +dependencies = [ + "typed-builder-macro", +] + +[[package]] +name = "typed-builder-macro" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "076a02dc54dd46795c2e9c8282ed40bcfb1e22747e955de9389a1de28190fb26" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "typenum" +version = "1.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de" + +[[package]] +name = "unarray" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unicode-linebreak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" + +[[package]] +name = "unicode-segmentation" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9629274872b2bfaf8d66f5f15725007f635594914870f65218920345aa11aa8c" + +[[package]] +name = "unicode-width" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "unsafe-libyaml" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "uuid" +version = "1.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd74a9687298c6858e9b88ec8935ec45d22e8fd5e6394fa1bd4e99a87789c76" +dependencies = [ + "getrandom 0.4.2", + "js-sys", + "serde_core", + "wasm-bindgen", +] + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.3+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" +dependencies = [ + "wit-bindgen 0.57.1", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen 0.51.0", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.120" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df52b6d9b87e0c74c9edfa1eb2d9bf85e5d63515474513aa50fa181b3c4f5db1" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af934872acec734c2d80e6617bbb5ff4f12b052dd8e6332b0817bce889516084" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.120" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b1041f495fb322e64aca85f5756b2172e35cd459376e67f2a6c9dffcedb103" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.120" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dcd0ff20416988a18ac686d4d4d0f6aae9ebf08a389ff5d29012b05af2a1b41" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.120" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49757b3c82ebf16c57d69365a142940b384176c24df52a087fb748e2085359ea" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + +[[package]] +name = "web-sys" +version = "0.3.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eadbac71025cd7b0834f20d1fe8472e8495821b4e9801eb0a60bd1f19827602" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52f5ee44c96cf55f1b349600768e3ece3a8f26010c05265ab73f945bb1a2eb9d" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580" +dependencies = [ + "windows-collections", + "windows-core", + "windows-future", + "windows-numerics", +] + +[[package]] +name = "windows-collections" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b2d95af1a8a14a3c7367e1ed4fc9c20e0a26e79551b1454d72583c97cc6610" +dependencies = [ + "windows-core", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-future" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb" +dependencies = [ + "windows-core", + "windows-link", + "windows-threading", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-numerics" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26" +dependencies = [ + "windows-core", + "windows-link", +] + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + +[[package]] +name = "windows-threading" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "writeable" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" + +[[package]] +name = "yoke" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eed437bf9d6692032087e337407a86f04cd8d6a16a37199ed57949d415bd68e9" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerofrom" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69faa1f2a1ea75661980b013019ed6687ed0e83d069bc1114e2cc74c6c04c4df" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/skills/Cargo.toml b/skills/Cargo.toml new file mode 100644 index 00000000..749f3d22 --- /dev/null +++ b/skills/Cargo.toml @@ -0,0 +1,53 @@ +[workspace] + +[package] +name = "skills" +version = "0.1.0" +edition = "2021" +publish = false + +[[bin]] +name = "skills" +path = "src/main.rs" + +[lib] +name = "iii_skills" +path = "src/lib.rs" + +[dependencies] +iii-sdk = "=0.11.3" +tokio = { version = "1", features = ["rt-multi-thread", "macros", "sync", "signal", "time", "fs"] } +serde = { version = "1", features = ["derive"] } +serde_json = "1" +serde_yaml = "0.9" +anyhow = "1" +thiserror = "2" +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter"] } +clap = { version = "4", features = ["derive"] } +async-trait = "0.1" +schemars = { version = "0.8", features = ["chrono", "uuid1"] } +chrono = { version = "0.4", features = ["serde"] } +uuid = { version = "1", features = ["v4"] } + +[dev-dependencies] +serde_json = "1" +tempfile = "3" +# BDD test runner. Drives Gherkin .feature files under tests/features/. +cucumber = "0.22" +# Used by step defs that need to drive multiple awaits in fixed order. +futures = "0.3" +uuid = { version = "1", features = ["v4"] } +tokio = { version = "1", features = ["rt-multi-thread", "macros", "sync", "signal", "time"] } + +# Single BDD entry point. cucumber needs full control of the runner, so +# `harness = false` is required. All .feature files under +# `tests/features/**` are discovered at runtime; tags (`@pure`, `@engine`, +# `@skills_register`, ...) let you filter to a subset: +# +# cargo test --test bdd # everything +# cargo test --test bdd -- --tags @pure # no engine required +# cargo test --test bdd -- --tags @skills_register +[[test]] +name = "bdd" +harness = false diff --git a/skills/README.md b/skills/README.md new file mode 100644 index 00000000..03fc6f3b --- /dev/null +++ b/skills/README.md @@ -0,0 +1,583 @@ +# skills + +Agentic content registry worker for the [iii engine](https://github.com/iii-hq/iii). +Persists two kinds of content for AI clients: **skills** (markdown +orientation docs about a worker's tools, served at `iii://{id}` plus +an auto-rendered `iii://skills` index) and **prompts** (parametric +slash-command templates, dispatched on demand to a registered handler +function). Workers register their content at boot via `iii.trigger`; +skills persists everything to iii-state and emits change +notifications on `skills::on-change` / `prompts::on-change` for any +other worker that wants to react. + +| Surface | What clients see | When to use it | +|---|---|---| +| **Skills** | Markdown documents under `iii://{id}` plus an `iii://skills` index | Orientation: "when and why to use my worker's tools" | +| **Prompts** | Slash-commands (e.g. `/send-email`) with declared arguments | Parametric command templates the *user* invokes | + +The rest of this README walks you through installing the worker and +writing a worker that publishes skills and slash-command prompts. + +--- + +## Table of contents + +1. [Install](#install) +2. [Quickstart: publish a skill and a slash-command](#quickstart-publish-a-skill-and-a-slash-command) +3. [Configuration](#configuration) +4. [Functions](#functions) +5. [Custom trigger types](#custom-trigger-types) +6. [Local development & testing](#local-development--testing) + +--- + +## Install + +```bash +iii worker add skills +``` + +`iii worker add` fetches the binary, writes a config block into +`~/.iii/config.yaml`, and the engine starts the worker on the next +`iii start`. + +--- + +## Quickstart: publish a skill and a slash-command + +A worker can plug into this registry three ways. They compose: most +workers ship one top-level skill, optional sub-skill markdown sections, +and zero or more slash-commands. + +The interface is two `iii.trigger` calls, plus optional in-process +handler functions for sub-skills and prompt rendering: + +| Step | Function id | What it stores | +|---|---|---| +| Register a skill | `skills::register` | Markdown body keyed by id | +| Register a prompt | `prompts::register` | Slash-command name + args + handler function id | +| Subscribe to changes | `skills::on-change` / `prompts::on-change` | Custom trigger types fired on every mutation | + +### Skills (markdown orientation docs) + +A **skill** is a markdown document explaining when and why to use your +worker's tools. Skills don't replicate the JSON schemas of your +functions โ€” clients get those from the engine's tool listing. Skills +tell the LLM *which tool for which job*. + +Register one with `skills::register`: + +```rust +use iii_sdk::{register_worker, InitOptions, TriggerRequest}; +use serde_json::json; + +let iii = register_worker("ws://localhost:49134", InitOptions::default()); + +iii.trigger(TriggerRequest { + function_id: "skills::register".into(), + payload: json!({ + "id": "myworker", + "skill": include_str!("../docs/skill.md"), + }), + action: None, + timeout_ms: Some(5_000), +}).await?; +``` + +Validation rules (rejected at registration time): + +- `id`: lowercase ASCII letters, digits, `-` and `_` only; max 64 chars +- `skill`: non-empty; max 256 KiB + +Re-registering with the same id overwrites the body and refreshes the +`registered_at` timestamp. **Workers MUST re-register on every boot** +so any updated content shipped with the worker lands in the registry. +Doing this unconditionally also keeps you robust to state being wiped +during local development. + +#### URI scheme + +| URI | Returns | +|---|---| +| `iii://skills` | Auto-rendered markdown index of every registered skill (entry point) | +| `iii://{your_id}` | The body you registered | +| `iii://{your_id}/{your_function_id}` | Triggers `your_function_id` with `{}` and returns its output as content | + +The third shape lets you split a skill across multiple files. Register +your top-level skill at `iii://{your_id}`, then reference sub-content +inside it as markdown links to functions you also registered. Any +function the engine knows about is reachable this way; there's no +opt-in flag. A short reserved-prefix list (engine internals, state +plumbing, this worker's own admin functions) is rejected at read time +to keep the resolver from tunneling back into infra. + +A function backing `iii://{id}/{fn}` should return one of: + +- a string โ†’ served as `text/markdown` +- `{ "content": "..." }` โ†’ the `content` field is served as `text/markdown` +- anything else โ†’ pretty-printed JSON, served as `application/json` + +The auto-rendered `iii://skills` index uses the first H1 of each skill +as the link title and the first non-heading paragraph as the +description (truncated at 140 chars). Lead with a `# {title}` and a +short summary paragraph and the index reads cleanly without further +work. + +#### Worked example: skill with sub-skills + +```rust +use iii_sdk::{RegisterFunction, TriggerRequest}; +use schemars::JsonSchema; +use serde::Serialize; +use serde_json::{json, Value}; + +#[derive(Serialize, JsonSchema)] +struct SkillContent { + content: String, +} + +iii.trigger(TriggerRequest { + function_id: "skills::register".into(), + payload: json!({ + "id": "brain", + "skill": "# brain\n\nHelps build UIs with Tailwind.\n\n\ + See [`summarize`](iii://brain/brain::summarize) \ + for the catalogue.\n", + }), + action: None, + timeout_ms: Some(5_000), +}).await?; + +iii.register_function( + RegisterFunction::new("brain::summarize", |_input: Value| { + Ok::<_, String>(SkillContent { + content: include_str!("../docs/summarize.md").to_string(), + }) + }) + .description("Index of UI design guidelines."), +); +``` + +Now any consumer can read `iii://brain` for the orientation and click +through to `iii://brain/brain::summarize` for the catalogue. The +resource resolver invokes the sub-skill function directly through +`iii.trigger`, so it doesn't need any extra opt-in flag. + +### Prompts (slash commands) + +A **prompt** is a parametric template the *user* invokes from the +client (e.g. typing `/send-email`). The template is rendered by your +handler function with the user-supplied arguments. + +Registration is two steps: + +1. Register a normal handler function. No special opt-in flag is + needed โ€” `skills` dispatches the handler directly through + `iii.trigger` when the prompt is invoked. +2. Register the prompt itself, pointing at that function. + +```rust +use iii_sdk::{RegisterFunction, TriggerRequest}; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; +use serde_json::json; + +#[derive(Deserialize, JsonSchema)] +struct SendEmailArgs { + to: String, + subject: String, +} + +#[derive(Serialize, JsonSchema)] +struct PromptOutput { + content: String, +} + +// Step 1: handler renders the prompt +iii.register_function( + RegisterFunction::new("myworker::send_email_prompt", |args: SendEmailArgs| { + Ok::<_, String>(PromptOutput { + content: format!( + "Compose an email to {} with the subject \"{}\". Be concise and friendly.", + args.to, args.subject + ), + }) + }) + .description("Render the send-email slash-command body."), +); + +// Step 2: register the slash-command +iii.trigger(TriggerRequest { + function_id: "prompts::register".into(), + payload: json!({ + "name": "send-email", + "description": "Compose and send an email", + "arguments": [ + { "name": "to", "description": "Recipient address", "required": true }, + { "name": "subject", "description": "Subject line", "required": true } + ], + "function_id": "myworker::send_email_prompt" + }), + action: None, + timeout_ms: Some(5_000), +}).await?; +``` + +Validation rules (rejected at registration time): + +- `name`: lowercase ASCII letters, digits, `-` and `_` only; max 64 + chars (no `::`, no `/`, no whitespace) +- `description`: non-empty after trim +- `function_id`: non-empty after trim +- `arguments[].name`: non-empty, no duplicates within the list + +#### Argument schema gotcha + +The `arguments` field is what the *client* sees in its argument-picker +UI. **It does not auto-validate at runtime.** The handler is +responsible for validating its own input โ€” treat the schema as a +contract you uphold inside the function. + +#### Output normalization + +The handler can return any of: + +- `String` โ†’ wrapped as a single user-text message +- `{ "content": "..." }` โ†’ wrapped as a single user-text message +- `{ "messages": [ ... ] }` โ†’ passed through unchanged (full control; + use this for multi-turn templates or assistant-prefilled responses) +- anything else โ†’ an error returned to the client + +### Lifecycle & boot-time handshake + +Skills and prompts are stored in iii-state under scopes `skills` and +`prompts` (configurable). Both registries are durable and survive +restarts of either `skills` or your worker. + +Workers MUST re-register on every boot. `skills` itself can be +absent or come up *after* your worker, so treat the registration as +best-effort with capped exponential backoff: + +```rust +use std::sync::Arc; +use std::time::{Duration, Instant}; +use iii_sdk::{TriggerRequest, III}; +use serde_json::json; + +fn register_with_iii_skills(iii: Arc) { + tokio::spawn(async move { + let mut backoff = Duration::from_secs(5); + let started = Instant::now(); + loop { + let result = iii.trigger(TriggerRequest { + function_id: "skills::register".into(), + payload: json!({ + "id": "myworker", + "skill": include_str!("../docs/skill.md"), + }), + action: None, + timeout_ms: Some(5_000), + }).await; + if result.is_ok() { + tracing::info!("registered myworker skill"); + return; + } + if started.elapsed() > Duration::from_secs(180) { + tracing::warn!("skills handshake gave up; install / start it and restart this worker"); + return; + } + tokio::time::sleep(backoff).await; + backoff = (backoff * 2).min(Duration::from_secs(60)); + } + }); +} +``` + +On graceful shutdown, optionally call `skills::unregister` and +`prompts::unregister` to clean up. Crashes leave entries in state +indefinitely; an operator can list them with `skills::list` / +`prompts::list` (which expose `registered_at`) and remove dead ones +manually. + +Mutations of either scope fire the `skills::on-change` / +`prompts::on-change` custom trigger types automatically. Any worker +can subscribe and react to registrations without polling. + +### Subscribing to registry changes + +Workers that need to react to registrations (a dashboard, a metrics +sink, a sibling protocol bridge) subscribe to the custom trigger +types: + +```rust +use iii_sdk::RegisterTriggerInput; +use serde_json::json; + +iii.register_trigger(RegisterTriggerInput { + trigger_type: "skills::on-change".into(), + function_id: "myworker::on_skill_change".into(), + config: json!({}), + metadata: None, +})?; +``` + +Payload sent to each subscriber: + +| Trigger type | Payload | +|---|---| +| `skills::on-change` | `{ "op": "register" \| "unregister", "id": "" }` | +| `prompts::on-change` | `{ "op": "register" \| "unregister", "name": "" }` | + +Dispatches are fire-and-forget (Void), so the write path on +`skills::register` / `prompts::register` doesn't block on downstream +latency. Idempotent unregisters that found nothing to delete don't +fire. + +### Full multi-language example + +Self-contained worker that registers one skill, one sub-skill function, +and one slash-command prompt. Boots, registers everything, then sleeps +until SIGINT. + +#### Rust + +```rust +use iii_sdk::{register_worker, InitOptions, RegisterFunction, TriggerRequest}; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; +use serde_json::{json, Value}; + +#[derive(Default, Deserialize, JsonSchema)] +struct GreetArgs { + name: String, +} + +#[derive(Serialize, JsonSchema)] +struct SkillContent { + content: String, +} + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let iii = register_worker("ws://localhost:49134", InitOptions::default()); + + // 1. Sub-skill function: returns extended docs as markdown. + iii.register_function( + RegisterFunction::new("demo::guide", |_input: Value| { + Ok::<_, String>(SkillContent { + content: "# Demo guide\n\nThe long-form docs for the demo worker." + .into(), + }) + }) + .description("Detailed guide for the demo worker."), + ); + + // 2. Prompt handler: turns slash-command args into a templated message. + iii.register_function( + RegisterFunction::new("demo::greet_prompt", |input: GreetArgs| { + Ok::<_, String>(SkillContent { + content: format!("Greet {} warmly.", input.name), + }) + }) + .description("Render the greet prompt."), + ); + + // Wire the registries. Always skills::register / prompts::register + // at startup so the entries refresh after any worker upgrade. + iii.trigger(TriggerRequest { + function_id: "skills::register".into(), + payload: json!({ + "id": "demo", + "skill": "# demo\n\n\ + A demo worker.\n\n\ + See [`guide`](iii://demo/demo::guide) for the long version.\n" + }), + action: None, + timeout_ms: Some(5_000), + }).await?; + + iii.trigger(TriggerRequest { + function_id: "prompts::register".into(), + payload: json!({ + "name": "greet", + "description": "Compose a greeting.", + "arguments": [ + { "name": "name", "description": "Who to greet", "required": true } + ], + "function_id": "demo::greet_prompt" + }), + action: None, + timeout_ms: Some(5_000), + }).await?; + + tokio::signal::ctrl_c().await?; + Ok(()) +} +``` + +#### Node + +```js +import { registerWorker } from 'iii-sdk' + +const iii = registerWorker('ws://localhost:49134') + +iii.registerFunction({ id: 'demo::guide' }, async () => ({ + content: '# Demo guide\n\nThe long-form docs for the demo worker.', +})) + +iii.registerFunction({ id: 'demo::greet_prompt' }, async ({ name = 'world' }) => ({ + content: `Greet ${name} warmly.`, +})) + +await iii.trigger({ + function_id: 'skills::register', + payload: { + id: 'demo', + skill: '# demo\n\nA demo worker.\n\nSee [`guide`](iii://demo/demo::guide) for the long version.\n', + }, +}) + +await iii.trigger({ + function_id: 'prompts::register', + payload: { + name: 'greet', + description: 'Compose a greeting.', + arguments: [{ name: 'name', description: 'Who to greet', required: true }], + function_id: 'demo::greet_prompt', + }, +}) +``` + +#### Python + +```python +from iii_sdk import register_worker + +iii = register_worker('ws://localhost:49134') + +@iii.register_function('demo::guide') +async def guide(_input): + return {'content': '# Demo guide\n\nThe long-form docs for the demo worker.'} + +@iii.register_function('demo::greet_prompt') +async def greet_prompt(input): + name = input.get('name', 'world') + return {'content': f'Greet {name} warmly.'} + +await iii.trigger( + function_id='skills::register', + payload={ + 'id': 'demo', + 'skill': '# demo\n\nA demo worker.\n\nSee [`guide`](iii://demo/demo::guide) for the long version.\n', + }, +) + +await iii.trigger( + function_id='prompts::register', + payload={ + 'name': 'greet', + 'description': 'Compose a greeting.', + 'arguments': [{'name': 'name', 'description': 'Who to greet', 'required': True}], + 'function_id': 'demo::greet_prompt', + }, +) +``` + +--- + +## Configuration + +```yaml +# skills runtime config. + +# State scopes used to persist the two registries. Changing these at +# runtime is supported but orphans prior entries; treat them as +# deployment-time constants in practice. +scopes: + skills: skills + prompts: prompts + +# Default timeout for state::* and sub-skill function triggers (ms). +state_timeout_ms: 10000 +``` + +CLI flags: + +```text +--config Path to config.yaml [default: ./config.yaml] +--url WebSocket URL of the iii engine [default: ws://127.0.0.1:49134] +--manifest Output the module manifest as JSON and exit +-h, --help Print help +``` + +If the config file is missing or malformed the worker logs a warning +and falls back to the defaults โ€” boot is never blocked by a bad +config path. + +--- + +## Functions + +Eleven functions across the two registries. The six public CRUD +entries are callable by any worker over `iii.trigger`. The five +internal-RPC entries are reserved for protocol-bridge workers that +serve the registries to external clients; they never surface as agent +tools. + +| Function ID | Description | +|---|---| +| `skills::register` | Store a markdown skill body keyed by id. | +| `skills::unregister` | Delete a skill by id. Idempotent. | +| `skills::list` | Metadata-only listing, sorted by id. | +| `skills::resources-list` | Internal: enumerate registered skills as resource entries. | +| `skills::resources-read` | Internal: resolve an `iii://` URI to its content. | +| `skills::resources-templates` | Internal: declare the `iii://{id}` URI templates. | +| `prompts::register` | Store a slash-command prompt definition. | +| `prompts::unregister` | Delete a prompt by name. Idempotent. | +| `prompts::list` | Metadata-only listing, sorted by name. | +| `prompts::mcp-list` | Internal: enumerate registered prompts with argument schemas. | +| `prompts::mcp-get` | Internal: dispatch a registered prompt handler with caller-supplied arguments. | + +--- + +## Custom trigger types + +| Trigger type | Fires when | Payload to subscribers | +|---|---|---| +| `skills::on-change` | After every mutation of the skills registry | `{ "op": "register" \| "unregister", "id": "" }` | +| `prompts::on-change` | After every mutation of the prompts registry | `{ "op": "register" \| "unregister", "name": "" }` | + +--- + +## Local development & testing + +### Run from source + +```bash +cargo run --release -- --url ws://127.0.0.1:49134 --config ./config.yaml +``` + +### Tests + +```bash +# Fast, offline โ€” exercises the pure helpers (markdown / URI / validators) +# without needing an iii engine. +cargo test --test bdd -- --tags @pure + +# Full suite โ€” requires an iii engine on ws://127.0.0.1:49134 +# (or III_ENGINE_WS_URL). Runs the full BDD scenario set covering +# every function and every validation rule. +cargo test + +# One feature group at a time. Available tags: +# @pure @markdown +# @engine @skills_register @skills_resources +# @prompts_register @prompts_get @notifications +cargo test --test bdd -- --tags @skills_resources +``` + +The BDD harness lives under [tests/](tests/). Feature files mirror the +modules in [src/functions/](src/functions/). Step definitions under +[tests/steps/](tests/steps/) drive each feature through the same +`iii.trigger` path the production binary uses. diff --git a/skills/build.rs b/skills/build.rs new file mode 100644 index 00000000..81caa36d --- /dev/null +++ b/skills/build.rs @@ -0,0 +1,6 @@ +fn main() { + println!( + "cargo:rustc-env=TARGET={}", + std::env::var("TARGET").unwrap() + ); +} diff --git a/skills/config.yaml b/skills/config.yaml new file mode 100644 index 00000000..2ba783c4 --- /dev/null +++ b/skills/config.yaml @@ -0,0 +1,11 @@ +# skills runtime config. + +# State scopes used to persist the two registries. Changing these at +# runtime is supported but orphans prior entries; treat them as +# deployment-time constants in practice. +scopes: + skills: skills + prompts: prompts + +# Default timeout for `state::*` and sub-skill function triggers (ms). +state_timeout_ms: 10000 diff --git a/skills/iii.worker.yaml b/skills/iii.worker.yaml new file mode 100644 index 00000000..f1552c99 --- /dev/null +++ b/skills/iii.worker.yaml @@ -0,0 +1,7 @@ +iii: v1 +name: skills +language: rust +deploy: binary +manifest: Cargo.toml +bin: skills +description: Agentic content registry worker. Hosts skills + prompts + the iii:// resource resolver that the mcp worker serves to harnesses. diff --git a/skills/src/config.rs b/skills/src/config.rs new file mode 100644 index 00000000..f8aff68b --- /dev/null +++ b/skills/src/config.rs @@ -0,0 +1,98 @@ +//! Worker runtime config. Mirrors iii-graph / iii-fts. + +use anyhow::Result; +use serde::{Deserialize, Serialize}; + +#[derive(Deserialize, Serialize, Debug, Clone)] +pub struct SkillsConfig { + #[serde(default)] + pub scopes: ScopesConfig, + #[serde(default = "default_state_timeout_ms")] + pub state_timeout_ms: u64, +} + +#[derive(Deserialize, Serialize, Debug, Clone)] +pub struct ScopesConfig { + #[serde(default = "default_skills_scope")] + pub skills: String, + #[serde(default = "default_prompts_scope")] + pub prompts: String, +} + +fn default_skills_scope() -> String { + "skills".to_string() +} + +fn default_prompts_scope() -> String { + "prompts".to_string() +} + +fn default_state_timeout_ms() -> u64 { + 10_000 +} + +impl Default for ScopesConfig { + fn default() -> Self { + Self { + skills: default_skills_scope(), + prompts: default_prompts_scope(), + } + } +} + +impl Default for SkillsConfig { + fn default() -> Self { + Self { + scopes: ScopesConfig::default(), + state_timeout_ms: default_state_timeout_ms(), + } + } +} + +pub fn load_config(path: &str) -> Result { + let contents = std::fs::read_to_string(path)?; + let cfg: SkillsConfig = serde_yaml::from_str(&contents)?; + Ok(cfg) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn defaults_from_empty_yaml() { + let cfg: SkillsConfig = serde_yaml::from_str("{}").unwrap(); + assert_eq!(cfg.scopes.skills, "skills"); + assert_eq!(cfg.scopes.prompts, "prompts"); + assert_eq!(cfg.state_timeout_ms, 10_000); + } + + #[test] + fn impl_default_matches_yaml_defaults() { + let from_empty: SkillsConfig = serde_yaml::from_str("{}").unwrap(); + let from_default = SkillsConfig::default(); + assert_eq!(from_empty.scopes.skills, from_default.scopes.skills); + assert_eq!(from_empty.scopes.prompts, from_default.scopes.prompts); + assert_eq!(from_empty.state_timeout_ms, from_default.state_timeout_ms); + } + + #[test] + fn custom_yaml_overrides_each_field() { + let yaml = "\ +scopes: + skills: my-skills + prompts: my-prompts +state_timeout_ms: 7500 +"; + let cfg: SkillsConfig = serde_yaml::from_str(yaml).unwrap(); + assert_eq!(cfg.scopes.skills, "my-skills"); + assert_eq!(cfg.scopes.prompts, "my-prompts"); + assert_eq!(cfg.state_timeout_ms, 7_500); + } + + #[test] + fn malformed_yaml_errors() { + let err = load_config("/no/such/path/for/skills.yaml"); + assert!(err.is_err()); + } +} diff --git a/skills/src/functions/mod.rs b/skills/src/functions/mod.rs new file mode 100644 index 00000000..96d43d03 --- /dev/null +++ b/skills/src/functions/mod.rs @@ -0,0 +1,26 @@ +//! Function registrations for `skills`. Each submodule registers +//! the public CRUD API plus the internal RPC that the `mcp` worker +//! calls when serving MCP `resources/*` / `prompts/*` methods. + +pub mod prompts; +pub mod skills; + +use std::sync::Arc; + +use iii_sdk::III; + +use crate::config::SkillsConfig; +use crate::trigger_types::RegisteredTriggerTypes; + +/// Register every `skills::*` and `prompts::*` function handler +/// against `iii`. Wires the skills fan-out channel to `trigger_types.skills` +/// and the prompts fan-out channel to `trigger_types.prompts`. +pub fn register_all( + iii: &Arc, + cfg: &Arc, + trigger_types: &RegisteredTriggerTypes, +) { + skills::register(iii, cfg, &trigger_types.skills); + prompts::register(iii, cfg, &trigger_types.prompts); + tracing::info!("skills registered 5 skills::* and 5 prompts::* functions"); +} diff --git a/skills/src/functions/prompts.rs b/skills/src/functions/prompts.rs new file mode 100644 index 00000000..b2e55795 --- /dev/null +++ b/skills/src/functions/prompts.rs @@ -0,0 +1,523 @@ +//! State-backed prompts registry, ported from the `mcp` worker. +//! +//! Public API (reachable by any worker over `iii.trigger`): +//! +//! * `prompts::register` โ€” store a slash-command prompt definition. +//! * `prompts::unregister` โ€” delete one by name (idempotent). +//! * `prompts::list` โ€” metadata-only listing, sorted by name. +//! +//! Internal RPC called only by the `mcp` worker (hard-floored under +//! `prompts::*` so never an MCP tool): +//! +//! * `prompts::mcp-list` โ€” `{ prompts: [...] }` for MCP `prompts/list`. +//! * `prompts::mcp-get` โ€” `{ description, messages: [...] }` for MCP `prompts/get`. +//! +//! Each mutation fans out through the `prompts::on-change` trigger type +//! (see [`crate::trigger_types`]) so interested workers (`mcp` today) +//! can forward MCP notifications. + +use std::collections::HashSet; +use std::sync::Arc; + +use iii_sdk::{IIIError, RegisterFunction, TriggerRequest, III}; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; +use serde_json::{json, Value}; + +use crate::config::SkillsConfig; +use crate::functions::skills::is_always_hidden; +use crate::state; +use crate::trigger_types::{self, SubscriberSet}; + +const NAME_MAX_LEN: usize = 64; + +#[derive(Debug, Deserialize, JsonSchema)] +struct RegisterPromptInput { + /// Unique prompt name (lowercase ASCII, kebab/underscore, max 64 chars). + name: String, + /// Free-text description shown in the client's prompt picker. + description: String, + #[serde(default)] + arguments: Vec, + /// Handler function called on prompts/get with the supplied arguments. + function_id: String, +} + +#[derive(Debug, Serialize, JsonSchema)] +struct RegisterPromptOutput { + name: String, + registered_at: String, +} + +#[derive(Debug, Deserialize, JsonSchema)] +struct UnregisterPromptInput { + name: String, +} + +#[derive(Debug, Serialize, JsonSchema)] +struct UnregisterPromptOutput { + name: String, + removed: bool, +} + +#[derive(Debug, Default, Deserialize, JsonSchema)] +struct ListPromptsInput {} + +#[derive(Debug, Serialize, JsonSchema)] +struct PromptEntry { + name: String, + function_id: String, + arguments: usize, + registered_at: String, +} + +#[derive(Debug, Serialize, JsonSchema)] +struct ListPromptsOutput { + prompts: Vec, +} + +#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)] +pub struct PromptArgument { + pub name: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub description: Option, + #[serde(default)] + pub required: bool, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct StoredPrompt { + pub name: String, + pub description: String, + #[serde(default)] + pub arguments: Vec, + pub function_id: String, + pub registered_at: String, +} + +#[derive(Debug, Default, Deserialize, JsonSchema)] +struct EmptyInput {} + +#[derive(Debug, Deserialize, JsonSchema)] +struct PromptGetInput { + name: String, + #[serde(default)] + arguments: Option, +} + +pub fn register(iii: &Arc, cfg: &Arc, subscribers: &SubscriberSet) { + register_register_prompt(iii, cfg, subscribers); + register_unregister_prompt(iii, cfg, subscribers); + register_list_prompts(iii, cfg); + register_mcp_list(iii, cfg); + register_mcp_get(iii, cfg); +} + +fn register_register_prompt(iii: &Arc, cfg: &Arc, subscribers: &SubscriberSet) { + let iii_inner = iii.clone(); + let cfg_inner = cfg.clone(); + let subs_inner = subscribers.clone(); + iii.register_function( + RegisterFunction::new_async("prompts::register", move |req: RegisterPromptInput| { + let iii = iii_inner.clone(); + let cfg = cfg_inner.clone(); + let subs = subs_inner.clone(); + async move { + validate_name(&req.name).map_err(IIIError::Handler)?; + if req.description.trim().is_empty() { + return Err(IIIError::Handler("description must be non-empty".into())); + } + if req.function_id.trim().is_empty() { + return Err(IIIError::Handler("function_id must be non-empty".into())); + } + validate_arguments(&req.arguments).map_err(IIIError::Handler)?; + + let stored = StoredPrompt { + name: req.name.clone(), + description: req.description, + arguments: req.arguments, + function_id: req.function_id, + registered_at: chrono::Utc::now().to_rfc3339(), + }; + + let value = serde_json::to_value(&stored) + .map_err(|e| IIIError::Handler(format!("encode prompt: {e}")))?; + state::state_set( + &iii, + &cfg.scopes.prompts, + &req.name, + value, + cfg.state_timeout_ms, + ) + .await?; + + tracing::info!(prompt = %req.name, "prompt registered"); + + trigger_types::dispatch(&iii, &subs, json!({ "op": "register", "name": req.name })) + .await; + + Ok::<_, IIIError>(RegisterPromptOutput { + name: req.name, + registered_at: stored.registered_at, + }) + } + }) + .description("Register a slash-command prompt; clients call prompts/get to render it."), + ); +} + +fn register_unregister_prompt( + iii: &Arc, + cfg: &Arc, + subscribers: &SubscriberSet, +) { + let iii_inner = iii.clone(); + let cfg_inner = cfg.clone(); + let subs_inner = subscribers.clone(); + iii.register_function( + RegisterFunction::new_async("prompts::unregister", move |req: UnregisterPromptInput| { + let iii = iii_inner.clone(); + let cfg = cfg_inner.clone(); + let subs = subs_inner.clone(); + async move { + validate_name(&req.name).map_err(IIIError::Handler)?; + let prior = + state::state_delete(&iii, &cfg.scopes.prompts, &req.name, cfg.state_timeout_ms) + .await?; + let removed = !prior.is_null(); + tracing::info!(prompt = %req.name, removed, "prompt unregister"); + + if removed { + trigger_types::dispatch( + &iii, + &subs, + json!({ "op": "unregister", "name": req.name }), + ) + .await; + } + + Ok::<_, IIIError>(UnregisterPromptOutput { + name: req.name, + removed, + }) + } + }) + .description("Remove a registered prompt by name."), + ); +} + +fn register_list_prompts(iii: &Arc, cfg: &Arc) { + let iii_inner = iii.clone(); + let cfg_inner = cfg.clone(); + iii.register_function( + RegisterFunction::new_async("prompts::list", move |_input: ListPromptsInput| { + let iii = iii_inner.clone(); + let cfg = cfg_inner.clone(); + async move { + let entries = list_stored(&iii, &cfg).await?; + let mut out: Vec = entries + .into_iter() + .map(|p| PromptEntry { + arguments: p.arguments.len(), + name: p.name, + function_id: p.function_id, + registered_at: p.registered_at, + }) + .collect(); + out.sort_by(|a, b| a.name.cmp(&b.name)); + Ok::<_, IIIError>(ListPromptsOutput { prompts: out }) + } + }) + .description("List registered prompts (name, function_id, arg count, registered_at)."), + ); +} + +fn register_mcp_list(iii: &Arc, cfg: &Arc) { + let iii_inner = iii.clone(); + let cfg_inner = cfg.clone(); + iii.register_function( + RegisterFunction::new_async("prompts::mcp-list", move |_input: EmptyInput| { + let iii = iii_inner.clone(); + let cfg = cfg_inner.clone(); + async move { Ok::<_, IIIError>(mcp_list(&iii, &cfg).await) } + }) + .description( + "Internal: returns the MCP prompts/list envelope (full arguments schema for each registered prompt).", + ), + ); +} + +fn register_mcp_get(iii: &Arc, cfg: &Arc) { + let iii_inner = iii.clone(); + let cfg_inner = cfg.clone(); + iii.register_function( + RegisterFunction::new_async("prompts::mcp-get", move |req: PromptGetInput| { + let iii = iii_inner.clone(); + let cfg = cfg_inner.clone(); + async move { + mcp_get(&iii, &cfg, req.name, req.arguments) + .await + .map_err(IIIError::Handler) + } + }) + .description( + "Internal: dispatches a registered prompt handler and normalizes the result for MCP prompts/get.", + ), + ); +} + +// ---------- core helpers (reusable in tests) ---------- + +pub async fn mcp_list(iii: &III, cfg: &SkillsConfig) -> Value { + let entries = list_stored(iii, cfg).await.unwrap_or_default(); + let mut prompts: Vec = entries + .into_iter() + .map(|p| { + let arguments: Vec = p + .arguments + .iter() + .map(|a| { + let mut obj = json!({ "name": a.name, "required": a.required }); + if let Some(d) = &a.description { + obj["description"] = Value::String(d.clone()); + } + obj + }) + .collect(); + json!({ + "name": p.name, + "description": p.description, + "arguments": arguments, + }) + }) + .collect(); + prompts.sort_by(|a, b| a["name"].as_str().cmp(&b["name"].as_str())); + json!({ "prompts": prompts }) +} + +pub async fn mcp_get( + iii: &III, + cfg: &SkillsConfig, + name: String, + arguments: Option, +) -> Result { + validate_name(&name)?; + let arguments = arguments.unwrap_or_else(|| json!({})); + + let stored = read_prompt(iii, cfg, &name) + .await? + .ok_or_else(|| format!("Prompt not found: {name}"))?; + + if is_always_hidden(&stored.function_id) { + return Err(format!( + "Prompt handler '{}' is in an internal namespace and cannot back a prompt", + stored.function_id + )); + } + + let raw = iii + .trigger(TriggerRequest { + function_id: stored.function_id.clone(), + payload: arguments, + action: None, + timeout_ms: Some(cfg.state_timeout_ms), + }) + .await + .map_err(|e| format!("trigger {}: {e}", stored.function_id))?; + + let messages = normalize_prompt_output(raw)?; + Ok(json!({ "description": stored.description, "messages": messages })) +} + +// ---------- validation ---------- + +pub fn validate_name(name: &str) -> Result<(), String> { + if name.is_empty() { + return Err("name must be non-empty".into()); + } + if name.len() > NAME_MAX_LEN { + return Err(format!( + "name too long ({} chars; max {NAME_MAX_LEN})", + name.len() + )); + } + for c in name.chars() { + let ok = c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-' || c == '_'; + if !ok { + return Err(format!( + "name may only contain lowercase ASCII letters, digits, '-' and '_': {name:?}" + )); + } + } + Ok(()) +} + +pub fn validate_arguments(args: &[PromptArgument]) -> Result<(), String> { + let mut seen = HashSet::new(); + for a in args { + if a.name.trim().is_empty() { + return Err("argument name must be non-empty".into()); + } + if !seen.insert(a.name.clone()) { + return Err(format!("duplicate argument name: {}", a.name)); + } + } + Ok(()) +} + +// ---------- output normalization ---------- + +pub fn normalize_prompt_output(raw: Value) -> Result { + if let Value::String(s) = &raw { + return Ok(json!([single_user_message(s)])); + } + if let Some(messages) = raw.get("messages").and_then(|v| v.as_array()) { + return Ok(Value::Array(messages.clone())); + } + if let Some(content) = raw.get("content").and_then(|v| v.as_str()) { + return Ok(json!([single_user_message(content)])); + } + Err("prompt handler returned unsupported shape; expected string, { content }, or { messages: [...] }".into()) +} + +fn single_user_message(text: &str) -> Value { + json!({ + "role": "user", + "content": { "type": "text", "text": text } + }) +} + +// ---------- state wrappers ---------- + +async fn read_prompt( + iii: &III, + cfg: &SkillsConfig, + name: &str, +) -> Result, String> { + let raw = state::state_get(iii, &cfg.scopes.prompts, name, cfg.state_timeout_ms) + .await + .map_err(|e| format!("state::get: {e}"))?; + if raw.is_null() { + return Ok(None); + } + serde_json::from_value::(raw) + .map(Some) + .map_err(|e| format!("decode stored prompt {name}: {e}")) +} + +async fn list_stored(iii: &III, cfg: &SkillsConfig) -> Result, IIIError> { + let raw = state::state_list(iii, &cfg.scopes.prompts, cfg.state_timeout_ms).await?; + let entries = state::extract_state_entries(raw); + let mut out: Vec = entries + .into_iter() + .filter_map(|v| serde_json::from_value(v).ok()) + .collect(); + out.sort_by(|a, b| a.name.cmp(&b.name)); + Ok(out) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn name_validation_accepts_kebab_and_underscore() { + assert!(validate_name("send-email").is_ok()); + assert!(validate_name("triage_ticket").is_ok()); + assert!(validate_name("a").is_ok()); + assert!(validate_name("v2").is_ok()); + } + + #[test] + fn name_validation_rejects_bad_chars() { + assert!(validate_name("").is_err()); + assert!(validate_name("Send-Email").is_err()); + assert!(validate_name("send email").is_err()); + assert!(validate_name("send/email").is_err()); + assert!(validate_name("mcp::send").is_err()); + assert!(validate_name(&"x".repeat(NAME_MAX_LEN + 1)).is_err()); + } + + #[test] + fn argument_validation_rejects_duplicates() { + let args = vec![ + PromptArgument { + name: "to".into(), + description: None, + required: true, + }, + PromptArgument { + name: "to".into(), + description: None, + required: false, + }, + ]; + assert!(validate_arguments(&args).is_err()); + } + + #[test] + fn argument_validation_rejects_empty_names() { + let args = vec![PromptArgument { + name: "".into(), + description: None, + required: true, + }]; + assert!(validate_arguments(&args).is_err()); + } + + #[test] + fn argument_validation_accepts_unique_names() { + let args = vec![ + PromptArgument { + name: "to".into(), + description: None, + required: true, + }, + PromptArgument { + name: "subject".into(), + description: None, + required: false, + }, + ]; + assert!(validate_arguments(&args).is_ok()); + } + + #[test] + fn normalize_string_wraps_as_user_message() { + let out = normalize_prompt_output(Value::String("hello".into())).unwrap(); + let msgs = out.as_array().unwrap(); + assert_eq!(msgs.len(), 1); + assert_eq!(msgs[0]["role"], "user"); + assert_eq!(msgs[0]["content"]["type"], "text"); + assert_eq!(msgs[0]["content"]["text"], "hello"); + } + + #[test] + fn normalize_content_wraps_as_user_message() { + let out = normalize_prompt_output(json!({ "content": "hi" })).unwrap(); + let msgs = out.as_array().unwrap(); + assert_eq!(msgs.len(), 1); + assert_eq!(msgs[0]["content"]["text"], "hi"); + } + + #[test] + fn normalize_messages_passes_through() { + let raw = json!({ + "messages": [ + { "role": "user", "content": { "type": "text", "text": "a" } }, + { "role": "assistant", "content": { "type": "text", "text": "b" } } + ] + }); + let out = normalize_prompt_output(raw).unwrap(); + let msgs = out.as_array().unwrap(); + assert_eq!(msgs.len(), 2); + assert_eq!(msgs[0]["role"], "user"); + assert_eq!(msgs[1]["role"], "assistant"); + } + + #[test] + fn normalize_other_returns_error() { + let err = normalize_prompt_output(json!({ "x": 1 })).unwrap_err(); + assert!(err.contains("unsupported shape")); + } +} diff --git a/skills/src/functions/skills.rs b/skills/src/functions/skills.rs new file mode 100644 index 00000000..e1526166 --- /dev/null +++ b/skills/src/functions/skills.rs @@ -0,0 +1,715 @@ +//! State-backed skills registry, ported from the `mcp` worker. +//! +//! Public API (reachable by any worker over `iii.trigger`): +//! +//! * `skills::register` โ€” store a markdown skill body keyed by id. +//! * `skills::unregister` โ€” delete one by id (idempotent). +//! * `skills::list` โ€” metadata-only listing, sorted by id. +//! +//! Internal RPC called only by the `mcp` worker (hard-floored under +//! `skills::*` so never an MCP tool): +//! +//! * `skills::resources-list` โ€” `{ resources: [...] }` for MCP `resources/list`. +//! * `skills::resources-read` โ€” `{ contents: [...] }` for MCP `resources/read`. +//! * `skills::resources-templates` โ€” `{ resourceTemplates: [...] }` for MCP `resources/templates/list`. +//! +//! Each mutation fans out through [`trigger_types::dispatch`] on the +//! `skills::on-change` trigger type so interested workers (the `mcp` +//! worker today) can forward MCP notifications. + +use std::sync::Arc; + +use iii_sdk::{IIIError, RegisterFunction, TriggerRequest, III}; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; +use serde_json::{json, Value}; + +use crate::config::SkillsConfig; +use crate::state; +use crate::trigger_types::{self, SubscriberSet}; + +const SKILL_BODY_MAX_BYTES: usize = 256 * 1024; +const ID_MAX_LEN: usize = 64; +const INDEX_URI: &str = "iii://skills"; +const URI_PREFIX: &str = "iii://"; + +/// Prefixes that are NEVER allowed as the `function_id` half of an +/// `iii://{skill}/{fn}` resource URI. Mirrors the hard-floor list in +/// [mcp/src/handler.rs](../../mcp/src/handler.rs); duplicated here so +/// `skills` can enforce the recursion guard without importing from +/// the mcp crate (each worker is its own cargo workspace). Keep the +/// two lists in sync when adding an infra namespace. +pub const ALWAYS_HIDDEN_PREFIXES: &[&str] = &[ + "engine::", + "state::", + "stream::", + "iii.", + "iii::", + "mcp::", + "a2a::", + "skills::", + "prompts::", +]; + +pub fn is_always_hidden(function_id: &str) -> bool { + ALWAYS_HIDDEN_PREFIXES + .iter() + .any(|p| function_id.starts_with(p)) +} + +#[derive(Debug, Deserialize, JsonSchema)] +struct RegisterSkillInput { + /// Unique skill id (lowercase ASCII, kebab/underscore, max 64 chars). + id: String, + /// Markdown body served at iii://{id}. + skill: String, +} + +#[derive(Debug, Serialize, JsonSchema)] +struct RegisterSkillOutput { + id: String, + registered_at: String, +} + +#[derive(Debug, Deserialize, JsonSchema)] +struct UnregisterSkillInput { + id: String, +} + +#[derive(Debug, Serialize, JsonSchema)] +struct UnregisterSkillOutput { + id: String, + removed: bool, +} + +#[derive(Debug, Default, Deserialize, JsonSchema)] +struct ListSkillsInput {} + +#[derive(Debug, Serialize, JsonSchema)] +struct SkillEntry { + id: String, + bytes: usize, + registered_at: String, +} + +#[derive(Debug, Serialize, JsonSchema)] +struct ListSkillsOutput { + skills: Vec, +} + +#[derive(Debug, Default, Deserialize, JsonSchema)] +struct EmptyInput {} + +#[derive(Debug, Deserialize, JsonSchema)] +struct ReadResourceInput { + uri: String, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +struct StoredSkill { + id: String, + skill: String, + registered_at: String, +} + +pub fn register(iii: &Arc, cfg: &Arc, subscribers: &SubscriberSet) { + register_register_skill(iii, cfg, subscribers); + register_unregister_skill(iii, cfg, subscribers); + register_list_skills(iii, cfg); + register_resources_list(iii, cfg); + register_resources_read(iii, cfg); + register_resources_templates(iii); +} + +fn register_register_skill(iii: &Arc, cfg: &Arc, subscribers: &SubscriberSet) { + let iii_inner = iii.clone(); + let cfg_inner = cfg.clone(); + let subs_inner = subscribers.clone(); + iii.register_function( + RegisterFunction::new_async("skills::register", move |req: RegisterSkillInput| { + let iii = iii_inner.clone(); + let cfg = cfg_inner.clone(); + let subs = subs_inner.clone(); + async move { + validate_id(&req.id).map_err(IIIError::Handler)?; + if req.skill.is_empty() { + return Err(IIIError::Handler("skill must be non-empty".into())); + } + if req.skill.len() > SKILL_BODY_MAX_BYTES { + return Err(IIIError::Handler(format!( + "skill body too large ({} bytes; max {SKILL_BODY_MAX_BYTES})", + req.skill.len() + ))); + } + + let stored = StoredSkill { + id: req.id.clone(), + skill: req.skill, + registered_at: chrono::Utc::now().to_rfc3339(), + }; + let value = serde_json::to_value(&stored) + .map_err(|e| IIIError::Handler(format!("encode skill: {e}")))?; + state::state_set( + &iii, + &cfg.scopes.skills, + &req.id, + value, + cfg.state_timeout_ms, + ) + .await?; + tracing::info!(skill_id = %req.id, "skill registered"); + + // Fan out to any `skills::on-change` subscribers with a + // Void dispatch so the write path doesn't block on + // downstream latency. + trigger_types::dispatch(&iii, &subs, json!({ "op": "register", "id": req.id })) + .await; + + Ok::<_, IIIError>(RegisterSkillOutput { + id: req.id, + registered_at: stored.registered_at, + }) + } + }) + .description("Register a markdown skill so it appears as iii://{id} in resources/list."), + ); +} + +fn register_unregister_skill(iii: &Arc, cfg: &Arc, subscribers: &SubscriberSet) { + let iii_inner = iii.clone(); + let cfg_inner = cfg.clone(); + let subs_inner = subscribers.clone(); + iii.register_function( + RegisterFunction::new_async("skills::unregister", move |req: UnregisterSkillInput| { + let iii = iii_inner.clone(); + let cfg = cfg_inner.clone(); + let subs = subs_inner.clone(); + async move { + validate_id(&req.id).map_err(IIIError::Handler)?; + let prior = + state::state_delete(&iii, &cfg.scopes.skills, &req.id, cfg.state_timeout_ms) + .await?; + let removed = !prior.is_null(); + tracing::info!(skill_id = %req.id, removed, "skill unregister"); + + // Only fan out when the state actually changed so + // idempotent deletes stay quiet. + if removed { + trigger_types::dispatch( + &iii, + &subs, + json!({ "op": "unregister", "id": req.id }), + ) + .await; + } + + Ok::<_, IIIError>(UnregisterSkillOutput { + id: req.id, + removed, + }) + } + }) + .description("Remove a registered skill by id."), + ); +} + +fn register_list_skills(iii: &Arc, cfg: &Arc) { + let iii_inner = iii.clone(); + let cfg_inner = cfg.clone(); + iii.register_function( + RegisterFunction::new_async("skills::list", move |_input: ListSkillsInput| { + let iii = iii_inner.clone(); + let cfg = cfg_inner.clone(); + async move { + let entries = list_stored(&iii, &cfg).await?; + let mut out: Vec = entries + .into_iter() + .map(|s| SkillEntry { + bytes: s.skill.len(), + id: s.id, + registered_at: s.registered_at, + }) + .collect(); + out.sort_by(|a, b| a.id.cmp(&b.id)); + Ok::<_, IIIError>(ListSkillsOutput { skills: out }) + } + }) + .description("List registered skills (id, body length, registered_at) without bodies."), + ); +} + +fn register_resources_list(iii: &Arc, cfg: &Arc) { + let iii_inner = iii.clone(); + let cfg_inner = cfg.clone(); + iii.register_function( + RegisterFunction::new_async( + "skills::resources-list", + move |_input: EmptyInput| { + let iii = iii_inner.clone(); + let cfg = cfg_inner.clone(); + async move { Ok::<_, IIIError>(list_resources(&iii, &cfg).await) } + }, + ) + .description( + "Internal: returns the MCP resources/list envelope with the iii://skills index + one iii://{id} entry per registered skill.", + ), + ); +} + +fn register_resources_read(iii: &Arc, cfg: &Arc) { + let iii_inner = iii.clone(); + let cfg_inner = cfg.clone(); + iii.register_function( + RegisterFunction::new_async("skills::resources-read", move |req: ReadResourceInput| { + let iii = iii_inner.clone(); + let cfg = cfg_inner.clone(); + async move { read(&iii, &cfg, &req.uri).await.map_err(IIIError::Handler) } + }) + .description( + "Internal: resolves an iii:// URI and returns the MCP resources/read contents envelope.", + ), + ); +} + +fn register_resources_templates(iii: &Arc) { + iii.register_function( + RegisterFunction::new_async( + "skills::resources-templates", + move |_input: EmptyInput| async move { Ok::<_, IIIError>(list_templates()) }, + ) + .description("Internal: returns the MCP resources/templates/list envelope."), + ); +} + +// ---------- core resource helpers (also usable by in-process tests) ---------- + +pub async fn list_resources(iii: &III, cfg: &SkillsConfig) -> Value { + let mut resources: Vec = vec![json!({ + "uri": INDEX_URI, + "name": "skills", + "description": "Index of every registered skill", + "mimeType": "text/markdown", + })]; + if let Ok(skills) = list_stored(iii, cfg).await { + for s in skills { + let title = extract_title(&s.skill).unwrap_or(&s.id); + resources.push(json!({ + "uri": format!("{URI_PREFIX}{}", s.id), + "name": title, + "mimeType": "text/markdown", + })); + } + } + json!({ "resources": resources }) +} + +pub fn list_templates() -> Value { + json!({ + "resourceTemplates": [ + { + "uriTemplate": "iii://{skill_id}", + "name": "Skill", + "description": "Markdown body of a registered skill", + "mimeType": "text/markdown" + }, + { + "uriTemplate": "iii://{skill_id}/{function_id}", + "name": "Skill section", + "description": "Markdown returned by triggering function_id with empty input", + "mimeType": "text/markdown" + } + ] + }) +} + +pub async fn read(iii: &III, cfg: &SkillsConfig, uri: &str) -> Result { + let parsed = parse_uri(uri)?; + match parsed { + ParsedUri::Index => { + let body = render_index(iii, cfg).await; + Ok(wrap_contents(uri, "text/markdown", &body)) + } + ParsedUri::Skill(id) => { + validate_id(&id)?; + let stored = read_skill(iii, cfg, &id) + .await? + .ok_or_else(|| format!("Skill not found: {id}"))?; + Ok(wrap_contents(uri, "text/markdown", &stored.skill)) + } + ParsedUri::Section { function_id, .. } => { + // Recursion guard โ€” a client that crafts iii://x/state::set would + // otherwise tunnel into infra. We also block skills::* / prompts::* + // so the resource resolver can't drive the admin API. + if is_always_hidden(&function_id) { + return Err(format!( + "Function '{function_id}' is in an internal namespace and cannot back a skill resource" + )); + } + let value = iii + .trigger(TriggerRequest { + function_id: function_id.clone(), + payload: json!({}), + action: None, + timeout_ms: Some(cfg.state_timeout_ms), + }) + .await + .map_err(|e| format!("trigger {function_id}: {e}"))?; + let (text, mime) = normalize_function_output(value); + Ok(wrap_contents(uri, mime, &text)) + } + } +} + +// ---------- URI parsing ---------- + +#[derive(Debug, PartialEq, Eq)] +pub enum ParsedUri { + Index, + Skill(String), + Section { + skill_id: String, + function_id: String, + }, +} + +pub fn parse_uri(uri: &str) -> Result { + let rest = uri + .strip_prefix(URI_PREFIX) + .ok_or_else(|| format!("Resource URI must start with iii://: {uri}"))?; + if rest.is_empty() { + return Err(format!("Empty resource id: {uri}")); + } + if rest == "skills" { + return Ok(ParsedUri::Index); + } + match rest.split_once('/') { + None => Ok(ParsedUri::Skill(rest.to_string())), + Some((skill_id, function_id)) => { + if skill_id.is_empty() { + return Err(format!("Empty skill id in URI: {uri}")); + } + if function_id.is_empty() { + return Err(format!("Empty function id in URI: {uri}")); + } + // Function ids contain `::` but not `/`; reject extra path + // segments rather than silently joining them. + if function_id.contains('/') { + return Err(format!( + "Resource URI may not have more than one path segment after the skill id: {uri}" + )); + } + Ok(ParsedUri::Section { + skill_id: skill_id.to_string(), + function_id: function_id.to_string(), + }) + } + } +} + +pub fn validate_id(id: &str) -> Result<(), String> { + if id.is_empty() { + return Err("id must be non-empty".into()); + } + if id.len() > ID_MAX_LEN { + return Err(format!( + "id too long ({} chars; max {ID_MAX_LEN})", + id.len() + )); + } + for c in id.chars() { + let ok = c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-' || c == '_'; + if !ok { + return Err(format!( + "id may only contain lowercase ASCII letters, digits, '-' and '_': {id:?}" + )); + } + } + Ok(()) +} + +// ---------- markdown helpers ---------- + +async fn render_index(iii: &III, cfg: &SkillsConfig) -> String { + let skills = match list_stored(iii, cfg).await { + Ok(s) => s, + Err(e) => { + return format!("# Skills\n\n_Error reading skills index: {e}_\n"); + } + }; + let mut out = String::from( + "# Skills\n\nRead each skill's resource for orientation on when and why to call its functions.\n\n", + ); + if skills.is_empty() { + out.push_str("_No skills are currently registered._\n"); + return out; + } + for s in skills { + let title = extract_title(&s.skill).unwrap_or(&s.id); + let desc = extract_description(&s.skill).unwrap_or_default(); + let suffix = if desc.is_empty() { + String::new() + } else { + format!(" โ€” {desc}") + }; + out.push_str(&format!( + "- [`{}`](iii://{}) โ€” {}{}\n", + s.id, s.id, title, suffix + )); + } + out +} + +pub fn extract_title(markdown: &str) -> Option<&str> { + markdown.lines().find_map(|line| { + let trimmed = line.trim_start(); + trimmed.strip_prefix("# ").map(|s| s.trim()) + }) +} + +pub fn extract_description(markdown: &str) -> Option { + let mut buf = String::new(); + for line in markdown.lines() { + let trimmed = line.trim(); + if trimmed.is_empty() { + if !buf.is_empty() { + break; + } + continue; + } + if trimmed.starts_with('#') { + if !buf.is_empty() { + break; + } + continue; + } + if !buf.is_empty() { + buf.push(' '); + } + buf.push_str(trimmed); + } + if buf.is_empty() { + return None; + } + Some(truncate_chars(&buf, 140)) +} + +pub fn truncate_chars(s: &str, max_chars: usize) -> String { + match s.char_indices().nth(max_chars) { + Some((byte_end, _)) => format!("{}...", &s[..byte_end]), + None => s.to_string(), + } +} + +// ---------- output normalization for iii://{skill}/{function} ---------- + +pub fn normalize_function_output(v: Value) -> (String, &'static str) { + if let Value::String(s) = &v { + return (s.clone(), "text/markdown"); + } + if let Some(content) = v.get("content").and_then(|c| c.as_str()) { + return (content.to_string(), "text/markdown"); + } + let pretty = serde_json::to_string_pretty(&v).unwrap_or_else(|_| v.to_string()); + (pretty, "application/json") +} + +fn wrap_contents(uri: &str, mime: &str, text: &str) -> Value { + json!({ + "contents": [ + { "uri": uri, "mimeType": mime, "text": text } + ] + }) +} + +// ---------- state wrappers ---------- + +async fn read_skill( + iii: &III, + cfg: &SkillsConfig, + id: &str, +) -> Result, String> { + let raw = state::state_get(iii, &cfg.scopes.skills, id, cfg.state_timeout_ms) + .await + .map_err(|e| format!("state::get: {e}"))?; + if raw.is_null() { + return Ok(None); + } + serde_json::from_value::(raw) + .map(Some) + .map_err(|e| format!("decode stored skill {id}: {e}")) +} + +async fn list_stored(iii: &III, cfg: &SkillsConfig) -> Result, IIIError> { + let raw = state::state_list(iii, &cfg.scopes.skills, cfg.state_timeout_ms).await?; + let entries = state::extract_state_entries(raw); + let mut out: Vec = entries + .into_iter() + .filter_map(|v| serde_json::from_value(v).ok()) + .collect(); + out.sort_by(|a, b| a.id.cmp(&b.id)); + Ok(out) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parse_index_uri() { + assert_eq!(parse_uri("iii://skills").unwrap(), ParsedUri::Index); + } + + #[test] + fn parse_single_skill_uri() { + assert_eq!( + parse_uri("iii://brain").unwrap(), + ParsedUri::Skill("brain".into()) + ); + } + + #[test] + fn parse_section_uri() { + assert_eq!( + parse_uri("iii://brain/brain::summarize").unwrap(), + ParsedUri::Section { + skill_id: "brain".into(), + function_id: "brain::summarize".into(), + } + ); + } + + #[test] + fn rejects_missing_prefix() { + assert!(parse_uri("brain").is_err()); + assert!(parse_uri("https://example.com").is_err()); + } + + #[test] + fn rejects_empty_id() { + assert!(parse_uri("iii://").is_err()); + assert!(parse_uri("iii:///fn").is_err()); + assert!(parse_uri("iii://skill/").is_err()); + } + + #[test] + fn rejects_extra_path_segments() { + assert!(parse_uri("iii://x/y/z").is_err()); + } + + #[test] + fn id_validation_accepts_kebab_and_underscore() { + assert!(validate_id("brain").is_ok()); + assert!(validate_id("agent_memory").is_ok()); + assert!(validate_id("my-skill-1").is_ok()); + assert!(validate_id("a").is_ok()); + } + + #[test] + fn id_validation_rejects_bad_chars() { + assert!(validate_id("").is_err()); + assert!(validate_id("UpperCase").is_err()); + assert!(validate_id("with space").is_err()); + assert!(validate_id("with/slash").is_err()); + assert!(validate_id("with::colon").is_err()); + assert!(validate_id(&"x".repeat(ID_MAX_LEN + 1)).is_err()); + } + + #[test] + fn extract_title_finds_h1() { + let md = "# my skill\n\nbody\n"; + assert_eq!(extract_title(md), Some("my skill")); + } + + #[test] + fn extract_title_ignores_h2() { + let md = "## sub\n\nbody\n"; + assert_eq!(extract_title(md), None); + } + + #[test] + fn extract_description_grabs_first_paragraph() { + let md = "# title\n\nfirst paragraph here.\n\nsecond paragraph.\n"; + assert_eq!( + extract_description(md).as_deref(), + Some("first paragraph here.") + ); + } + + #[test] + fn extract_description_skips_subheadings() { + let md = "# title\n\n## sub\n\n### deeper\n\nfinally text.\n"; + assert_eq!(extract_description(md).as_deref(), Some("finally text.")); + } + + #[test] + fn extract_description_handles_missing_paragraph() { + let md = "# only a title\n"; + assert_eq!(extract_description(md), None); + } + + #[test] + fn extract_description_truncates_long_lines() { + let body = "x".repeat(200); + let md = format!("# t\n\n{body}\n"); + let desc = extract_description(&md).unwrap(); + assert!(desc.ends_with("...")); + assert!(desc.chars().count() <= 144); + } + + #[test] + fn normalize_string_returns_markdown() { + let (text, mime) = normalize_function_output(Value::String("hello".into())); + assert_eq!(text, "hello"); + assert_eq!(mime, "text/markdown"); + } + + #[test] + fn normalize_content_object_returns_markdown() { + let (text, mime) = normalize_function_output(json!({ "content": "hi" })); + assert_eq!(text, "hi"); + assert_eq!(mime, "text/markdown"); + } + + #[test] + fn normalize_other_falls_back_to_json() { + let (text, mime) = normalize_function_output(json!({ "x": 1 })); + assert_eq!(mime, "application/json"); + assert!(text.contains("\"x\"")); + } + + #[test] + fn truncate_chars_handles_multibyte() { + let s = "รกรฉรญรณรบ".repeat(50); + let out = truncate_chars(&s, 5); + assert!(out.starts_with("รกรฉรญรณรบ")); + assert!(out.ends_with("...")); + assert_eq!(out.chars().count(), 5 + 3); + } + + #[test] + fn hard_floor_rejects_infra_namespaces() { + assert!(is_always_hidden("engine::foo")); + assert!(is_always_hidden("state::get")); + assert!(is_always_hidden("stream::publish")); + assert!(is_always_hidden("iii.on_foo")); + assert!(is_always_hidden("iii::internal")); + assert!(is_always_hidden("mcp::handler")); + assert!(is_always_hidden("a2a::send")); + assert!(is_always_hidden("skills::register")); + assert!(is_always_hidden("prompts::register")); + } + + #[test] + fn hard_floor_allows_ordinary_namespaces() { + assert!(!is_always_hidden("mem::observe")); + assert!(!is_always_hidden("brain::summarize")); + assert!(!is_always_hidden("my-worker::my-fn")); + } + + #[test] + fn list_templates_has_two_entries() { + let v = list_templates(); + let templates = v["resourceTemplates"].as_array().unwrap(); + assert_eq!(templates.len(), 2); + } +} diff --git a/skills/src/lib.rs b/skills/src/lib.rs new file mode 100644 index 00000000..da8a87de --- /dev/null +++ b/skills/src/lib.rs @@ -0,0 +1,26 @@ +//! `skills` โ€” agentic content registry worker. The binary in +//! `src/main.rs` is a thin wrapper that wires the modules below to the iii +//! engine. +//! +//! This worker owns two surfaces that were previously bundled inside +//! `iii-mcp`: +//! +//! * **Skills** (`skills::*`): a state-backed markdown registry keyed +//! by short skill ids. Skills are surfaced through the `iii://` +//! resource URI scheme and read by the `mcp` worker when it serves +//! `resources/list` / `resources/read`. +//! * **Prompts** (`prompts::*`): a state-backed registry of +//! slash-command templates. The `mcp` worker reads them via +//! `prompts::mcp-list` / `prompts::mcp-get` when answering +//! `prompts/list` and `prompts/get`. +//! +//! Mutations of either scope fan out through custom trigger types +//! `skills::on-change` and `prompts::on-change` so that the `mcp` worker +//! (or any other interested subscriber) can forward MCP +//! `notifications/*_list_changed` to its clients. + +pub mod config; +pub mod functions; +pub mod manifest; +pub mod state; +pub mod trigger_types; diff --git a/skills/src/main.rs b/skills/src/main.rs new file mode 100644 index 00000000..cf6ab03c --- /dev/null +++ b/skills/src/main.rs @@ -0,0 +1,92 @@ +//! `skills` binary entry. +//! +//! Boot sequence: +//! 1. Parse CLI / load YAML config (with fallback to defaults). +//! 2. Connect to the iii engine over WebSocket. +//! 3. Register the custom trigger types `skills::on-change` / `prompts::on-change`. +//! 4. Register every `skills::*` and `prompts::*` function against the engine. +//! 5. Sleep on Ctrl+C, then `shutdown_async` cleanly. +//! +//! All public CRUD functions are reachable over `iii.trigger` from any +//! sibling worker. Internal `skills::resources-*` / `prompts::mcp-*` +//! are called by the mcp worker over the iii bus only. + +use std::sync::Arc; + +use anyhow::Result; +use clap::Parser; +use iii_sdk::{register_worker, InitOptions, OtelConfig}; + +use iii_skills::{config, functions, manifest, trigger_types}; + +#[derive(Parser, Debug)] +#[command( + name = "skills", + about = "Agentic content registry worker. Hosts skills + prompts + the iii:// resource resolver." +)] +struct Cli { + #[arg(long, default_value = "./config.yaml")] + config: String, + + #[arg(long, default_value = "ws://127.0.0.1:49134")] + url: String, + + #[arg(long)] + manifest: bool, +} + +#[tokio::main] +async fn main() -> Result<()> { + tracing_subscriber::fmt() + .with_env_filter( + tracing_subscriber::EnvFilter::try_from_default_env() + .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")), + ) + .init(); + + let cli = Cli::parse(); + + if cli.manifest { + let m = manifest::build_manifest(); + println!("{}", serde_json::to_string_pretty(&m).unwrap()); + return Ok(()); + } + + let cfg = match config::load_config(&cli.config) { + Ok(c) => { + tracing::info!( + skills_scope = %c.scopes.skills, + prompts_scope = %c.scopes.prompts, + "loaded config from {}", + cli.config + ); + c + } + Err(e) => { + tracing::warn!(error = %e, path = %cli.config, "failed to load config, using defaults"); + config::SkillsConfig::default() + } + }; + let cfg = Arc::new(cfg); + + let iii = register_worker( + &cli.url, + InitOptions { + otel: Some(OtelConfig::default()), + ..Default::default() + }, + ); + let iii = Arc::new(iii); + + // Custom trigger types come first because the function handlers + // capture the subscriber sets they'll fan out to. + let registered = trigger_types::register_all(&iii); + functions::register_all(&iii, &cfg, ®istered); + + tracing::info!("skills ready: 10 functions + 2 custom trigger types"); + + tokio::signal::ctrl_c().await?; + tracing::info!("skills shutting down"); + iii.shutdown_async().await; + Ok(()) +} diff --git a/skills/src/manifest.rs b/skills/src/manifest.rs new file mode 100644 index 00000000..b78cff52 --- /dev/null +++ b/skills/src/manifest.rs @@ -0,0 +1,52 @@ +//! `--manifest` subcommand output. Same contract as every binary worker. + +use serde::Serialize; + +#[derive(Serialize)] +pub struct ModuleManifest { + pub name: String, + pub version: String, + pub description: String, + pub default_config: serde_json::Value, + pub supported_targets: Vec, +} + +pub fn build_manifest() -> ModuleManifest { + ModuleManifest { + name: env!("CARGO_PKG_NAME").to_string(), + version: env!("CARGO_PKG_VERSION").to_string(), + description: + "Agentic content registry worker. Hosts skills + prompts + the iii:// resource resolver that the mcp worker serves to harnesses." + .to_string(), + default_config: serde_json::json!({ + "scopes": { + "skills": "skills", + "prompts": "prompts" + }, + "state_timeout_ms": 10_000 + }), + supported_targets: vec![env!("TARGET").to_string()], + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn json_roundtrip_has_required_fields() { + let m = build_manifest(); + let json = serde_json::to_string_pretty(&m).unwrap(); + let parsed: serde_json::Value = serde_json::from_str(&json).unwrap(); + + assert_eq!(parsed["name"], "skills"); + assert_eq!(parsed["version"], env!("CARGO_PKG_VERSION")); + assert!(parsed["description"] + .as_str() + .is_some_and(|s| !s.is_empty())); + assert_eq!(parsed["default_config"]["scopes"]["skills"], "skills"); + assert_eq!(parsed["default_config"]["scopes"]["prompts"], "prompts"); + assert_eq!(parsed["default_config"]["state_timeout_ms"], 10_000); + assert!(!parsed["supported_targets"].as_array().unwrap().is_empty()); + } +} diff --git a/skills/src/state.rs b/skills/src/state.rs new file mode 100644 index 00000000..5a3608a8 --- /dev/null +++ b/skills/src/state.rs @@ -0,0 +1,114 @@ +//! Thin StateKV wrappers around `iii.trigger()`. Kept in one place so +//! every function module uses the same scope + timeout conventions. + +use iii_sdk::{IIIError, TriggerRequest, III}; +use serde_json::{json, Value}; + +pub async fn state_set( + iii: &III, + scope: &str, + key: &str, + value: Value, + timeout_ms: u64, +) -> Result { + iii.trigger(TriggerRequest { + function_id: "state::set".to_string(), + payload: json!({ "scope": scope, "key": key, "value": value }), + action: None, + timeout_ms: Some(timeout_ms), + }) + .await +} + +pub async fn state_get( + iii: &III, + scope: &str, + key: &str, + timeout_ms: u64, +) -> Result { + iii.trigger(TriggerRequest { + function_id: "state::get".to_string(), + payload: json!({ "scope": scope, "key": key }), + action: None, + timeout_ms: Some(timeout_ms), + }) + .await +} + +pub async fn state_delete( + iii: &III, + scope: &str, + key: &str, + timeout_ms: u64, +) -> Result { + iii.trigger(TriggerRequest { + function_id: "state::delete".to_string(), + payload: json!({ "scope": scope, "key": key }), + action: None, + timeout_ms: Some(timeout_ms), + }) + .await +} + +pub async fn state_list(iii: &III, scope: &str, timeout_ms: u64) -> Result { + iii.trigger(TriggerRequest { + function_id: "state::list".to_string(), + payload: json!({ "scope": scope }), + action: None, + timeout_ms: Some(timeout_ms), + }) + .await +} + +/// Normalize the several shapes `state::list` can return (a flat array, +/// a `{items: [{value: ...}, ...]}` envelope, or `{value: [...]}`) +/// into a plain Vec of the stored values. +pub fn extract_state_entries(raw: Value) -> Vec { + if let Value::Array(arr) = raw { + return arr; + } + if let Some(items) = raw.get("items").and_then(|v| v.as_array()) { + return items + .iter() + .filter_map(|item| item.get("value").cloned()) + .collect(); + } + if let Some(arr) = raw.get("value").and_then(|v| v.as_array()) { + return arr.clone(); + } + Vec::new() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn extract_state_entries_handles_flat_array() { + let raw = json!([{"id": "a"}, {"id": "b"}]); + let entries = extract_state_entries(raw); + assert_eq!(entries.len(), 2); + } + + #[test] + fn extract_state_entries_handles_items_envelope() { + let raw = json!({ "items": [{"value": {"id": "a"}}] }); + let entries = extract_state_entries(raw); + assert_eq!(entries.len(), 1); + assert_eq!(entries[0]["id"], "a"); + } + + #[test] + fn extract_state_entries_handles_value_array() { + let raw = json!({ "value": [{"id": "a"}] }); + let entries = extract_state_entries(raw); + assert_eq!(entries.len(), 1); + } + + #[test] + fn extract_state_entries_handles_unknown_shape() { + let raw = json!({ "random": "not-a-list" }); + let entries = extract_state_entries(raw); + assert_eq!(entries.len(), 0); + } +} diff --git a/skills/src/trigger_types.rs b/skills/src/trigger_types.rs new file mode 100644 index 00000000..56bb6420 --- /dev/null +++ b/skills/src/trigger_types.rs @@ -0,0 +1,210 @@ +//! Custom trigger types this worker publishes. +//! +//! Two trigger types exist: +//! +//! - `skills::on-change` โ€” fires once per mutation of the skills scope. +//! - `prompts::on-change` โ€” fires once per mutation of the prompts scope. +//! +//! The `mcp` worker (and any other interested subscriber) registers a +//! trigger instance of these types via +//! `iii.register_trigger(RegisterTriggerInput { trigger_type: "skills::on-change", ... })`. +//! The engine routes that registration through our [`SkillsTriggerHandler`] +//! which stashes the subscriber in [`SubscriberSet`]. When a state +//! mutation lands, the owning function module (`functions::skills` / +//! `functions::prompts`) reads the active subscribers and invokes each +//! one via `iii.trigger` โ€” a simple in-process fanout. +//! +//! We intentionally don't rely on the engine's built-in `state` trigger +//! to dispatch directly to mcp because that would hard-code the +//! `mcp::*` function ids inside skills. Using a named custom trigger +//! keeps the coupling one-way: mcp knows skills publishes +//! `skills::on-change`; skills never has to know mcp exists. + +use std::collections::HashMap; +use std::sync::{Arc, Mutex}; + +use async_trait::async_trait; +use iii_sdk::{ + IIIError, RegisterTriggerType, TriggerAction, TriggerConfig, TriggerHandler, TriggerRequest, + III, +}; +use serde_json::Value; + +pub const SKILLS_ON_CHANGE: &str = "skills::on-change"; +pub const PROMPTS_ON_CHANGE: &str = "prompts::on-change"; + +/// Thread-safe subscriber registry keyed by trigger-instance id. Cloned +/// into both the `TriggerHandler` (which mutates on register / +/// unregister) and the fan-out path in the function modules (which +/// iterates read-only). Entries are `TriggerConfig` so the fan-out can +/// see the subscriber's `function_id`. +#[derive(Clone, Default)] +pub struct SubscriberSet { + inner: Arc>>, +} + +impl SubscriberSet { + pub fn new() -> Self { + Self::default() + } + + fn insert(&self, config: TriggerConfig) { + let mut map = self + .inner + .lock() + .unwrap_or_else(|poison| poison.into_inner()); + map.insert(config.id.clone(), config); + } + + fn remove(&self, id: &str) { + let mut map = self + .inner + .lock() + .unwrap_or_else(|poison| poison.into_inner()); + map.remove(id); + } + + /// Snapshot of the current subscribers as a Vec of `function_id`s. + /// Returns a snapshot so the mutex isn't held across awaits. + pub fn function_ids(&self) -> Vec { + let map = self + .inner + .lock() + .unwrap_or_else(|poison| poison.into_inner()); + map.values().map(|c| c.function_id.clone()).collect() + } +} + +/// Fire `payload` to every subscriber using `TriggerAction::Void` +/// (fire-and-forget so the mutation that produced the change isn't +/// blocked on downstream latency). Failures are logged and swallowed +/// because a slow / misbehaving subscriber must not break the write +/// path. +pub async fn dispatch(iii: &III, subscribers: &SubscriberSet, payload: Value) { + let targets = subscribers.function_ids(); + for function_id in targets { + let fid = function_id.clone(); + let payload_copy = payload.clone(); + let res = iii + .trigger(TriggerRequest { + function_id: fid, + payload: payload_copy, + action: Some(TriggerAction::Void), + timeout_ms: None, + }) + .await; + if let Err(e) = res { + tracing::warn!( + function_id = %function_id, + error = %e, + "on-change fan-out failed" + ); + } + } +} + +pub struct RegisteredTriggerTypes { + pub skills: SubscriberSet, + pub prompts: SubscriberSet, +} + +pub fn register_all(iii: &Arc) -> RegisteredTriggerTypes { + let skills = SubscriberSet::new(); + let prompts = SubscriberSet::new(); + + let _ = iii.register_trigger_type(RegisterTriggerType::new( + SKILLS_ON_CHANGE.to_string(), + "Fires after any mutation of the skills registry (register / unregister).".to_string(), + SkillsTriggerHandler::new(SKILLS_ON_CHANGE, skills.clone()), + )); + tracing::info!(trigger_type = SKILLS_ON_CHANGE, "registered trigger type"); + + let _ = iii.register_trigger_type(RegisterTriggerType::new( + PROMPTS_ON_CHANGE.to_string(), + "Fires after any mutation of the prompts registry (register / unregister).".to_string(), + SkillsTriggerHandler::new(PROMPTS_ON_CHANGE, prompts.clone()), + )); + tracing::info!(trigger_type = PROMPTS_ON_CHANGE, "registered trigger type"); + + RegisteredTriggerTypes { skills, prompts } +} + +struct SkillsTriggerHandler { + name: String, + subscribers: SubscriberSet, +} + +impl SkillsTriggerHandler { + fn new(name: &str, subscribers: SubscriberSet) -> Self { + Self { + name: name.into(), + subscribers, + } + } +} + +#[async_trait] +impl TriggerHandler for SkillsTriggerHandler { + async fn register_trigger(&self, config: TriggerConfig) -> Result<(), IIIError> { + tracing::info!( + trigger_type = %self.name, + id = %config.id, + function_id = %config.function_id, + "trigger subscription registered" + ); + self.subscribers.insert(config); + Ok(()) + } + + async fn unregister_trigger(&self, config: TriggerConfig) -> Result<(), IIIError> { + tracing::info!( + trigger_type = %self.name, + id = %config.id, + "trigger subscription unregistered" + ); + self.subscribers.remove(&config.id); + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use serde_json::json; + + fn make_config(id: &str, function_id: &str) -> TriggerConfig { + TriggerConfig { + id: id.to_string(), + function_id: function_id.to_string(), + config: json!({}), + metadata: None, + } + } + + #[test] + fn subscriber_set_insert_and_remove() { + let set = SubscriberSet::new(); + assert!(set.function_ids().is_empty()); + set.insert(make_config("sub-1", "mcp::__on_skills_changed")); + set.insert(make_config("sub-2", "other::receiver")); + let mut fns = set.function_ids(); + fns.sort(); + assert_eq!( + fns, + vec![ + "mcp::__on_skills_changed".to_string(), + "other::receiver".to_string() + ] + ); + set.remove("sub-1"); + assert_eq!(set.function_ids(), vec!["other::receiver".to_string()]); + } + + #[test] + fn subscriber_set_duplicate_id_overwrites() { + let set = SubscriberSet::new(); + set.insert(make_config("sub-1", "a")); + set.insert(make_config("sub-1", "b")); + assert_eq!(set.function_ids(), vec!["b".to_string()]); + } +} diff --git a/skills/tests/bdd.rs b/skills/tests/bdd.rs new file mode 100644 index 00000000..d23a9597 --- /dev/null +++ b/skills/tests/bdd.rs @@ -0,0 +1,48 @@ +//! BDD entry point. Runs every `.feature` file under `tests/features/`. +//! +//! Filter by tag to isolate slices: +//! +//! ```text +//! cargo test --test bdd # everything +//! cargo test --test bdd -- --tags @pure # no engine required +//! cargo test --test bdd -- --tags @skills_register # one feature group +//! cargo test --test bdd -- --tags "@engine and not @notifications" +//! ``` + +mod common; +mod steps; + +use cucumber::World; + +use crate::common::world::IiiSkillsWorld; + +#[tokio::main] +async fn main() { + // Bring up the shared engine connection + in-process registrations + // exactly once. On a host without an engine this returns None and + // every `@engine` scenario short-circuits into a soft skip. + let _ = common::engine::get_or_init().await; + + IiiSkillsWorld::cucumber() + // Scenarios share a single engine connection + a single set of + // registered functions; running them concurrently means two + // scenarios trampling each other's state writes. + .max_concurrent_scenarios(1) + .before(|_feature, _rule, _scenario, world| { + Box::pin(async move { + if let Some(iii) = common::engine::get_or_init().await { + world.iii = Some(iii.clone()); + if let Some(shared) = common::workers::shared() { + world.cfg = shared.cfg.clone(); + } + // Start every scenario with both registries empty + // so per-test assertions aren't polluted by earlier + // writes. + common::workers::reset_state(&iii).await; + } + world.stash.clear(); + }) + }) + .run_and_exit("tests/features") + .await; +} diff --git a/skills/tests/common/engine.rs b/skills/tests/common/engine.rs new file mode 100644 index 00000000..1e2eb901 --- /dev/null +++ b/skills/tests/common/engine.rs @@ -0,0 +1,63 @@ +//! Connect-or-skip wrapper around the iii SDK. +//! +//! Lifted from agentmemory/tests/common/engine.rs. One engine connection +//! per test binary process via OnceCell โ€” the cost of each WebSocket +//! handshake dwarfs cucumber's per-scenario overhead. + +use std::sync::Arc; +use std::time::Duration; + +use iii_sdk::{register_worker, IIIError, InitOptions, TriggerRequest, III}; +use serde_json::json; +use tokio::sync::OnceCell; + +const DEFAULT_WS_URL: &str = "ws://127.0.0.1:49134"; + +static ENGINE: OnceCell>> = OnceCell::const_new(); + +pub fn ws_url() -> String { + std::env::var("III_ENGINE_WS_URL").unwrap_or_else(|_| DEFAULT_WS_URL.to_string()) +} + +pub async fn try_connect_raw() -> Option> { + let url = ws_url(); + let iii = Arc::new(register_worker(&url, InitOptions::default())); + + for _ in 0..20 { + tokio::time::sleep(Duration::from_millis(250)).await; + let probe = iii + .trigger(TriggerRequest { + function_id: "engine::workers::list".to_string(), + payload: json!({}), + action: None, + timeout_ms: Some(800), + }) + .await; + match probe { + Ok(_) => return Some(iii), + Err(IIIError::NotConnected) => continue, + Err(_) => continue, + } + } + + eprintln!( + "[skip] iii engine not reachable at {url}; \ + set III_ENGINE_WS_URL or start `iii` to enable engine-bound BDD scenarios" + ); + iii.shutdown_async().await; + None +} + +/// Get-or-init the shared engine handle. Registers skills's own +/// function surface in-process so the BDD scenarios drive the same +/// code the production binary would. +pub async fn get_or_init() -> Option> { + ENGINE + .get_or_init(|| async { + let iii = try_connect_raw().await?; + crate::common::workers::register_all(&iii).await.ok()?; + Some(iii) + }) + .await + .clone() +} diff --git a/skills/tests/common/mod.rs b/skills/tests/common/mod.rs new file mode 100644 index 00000000..b40e01be --- /dev/null +++ b/skills/tests/common/mod.rs @@ -0,0 +1,5 @@ +//! Shared BDD harness. Same shape as agentmemory/tests/common/. + +pub mod engine; +pub mod workers; +pub mod world; diff --git a/skills/tests/common/workers.rs b/skills/tests/common/workers.rs new file mode 100644 index 00000000..6b91bc73 --- /dev/null +++ b/skills/tests/common/workers.rs @@ -0,0 +1,114 @@ +//! In-process registration of the `skills` surface against the +//! shared SDK handle. Re-uses the same entry point the production +//! binary does (`iii_skills::functions::register_all`), so the BDD +//! scenarios exercise identical code paths. +//! +//! The registered state is kept once-per-binary in `OnceCell`. The +//! cucumber `before` hook in `tests/bdd.rs` wipes the two state scopes +//! between scenarios so each scenario starts from a clean slate. + +use std::sync::Arc; + +use anyhow::Result; +use iii_sdk::{TriggerRequest, III}; +use serde_json::{json, Value}; +use tokio::sync::OnceCell; + +use iii_skills::{ + config::SkillsConfig, + functions, + trigger_types::{self, RegisteredTriggerTypes}, +}; + +pub struct Shared { + pub cfg: Arc, + /// Kept so step defs needing to assert on subscriber-set state can + /// probe it directly (the registered trigger types live here). + #[allow(dead_code)] + pub triggers: Arc, +} + +static SHARED: OnceCell> = OnceCell::const_new(); + +/// Idempotent: the first caller registers; subsequent callers reuse. +pub async fn register_all(iii: &Arc) -> Result> { + if let Some(s) = SHARED.get() { + return Ok(s.clone()); + } + + let cfg = Arc::new(SkillsConfig::default()); + let registered = trigger_types::register_all(iii); + functions::register_all(iii, &cfg, ®istered); + + // Give the SDK a beat to publish the function registrations before + // scenarios start triggering them. + tokio::time::sleep(std::time::Duration::from_millis(150)).await; + + let shared = Arc::new(Shared { + cfg, + triggers: Arc::new(registered), + }); + let _ = SHARED.set(shared.clone()); + Ok(shared) +} + +pub fn shared() -> Option> { + SHARED.get().cloned() +} + +/// Wipe both state scopes between scenarios. Called from the cucumber +/// `before` hook. Iterates the current contents of each scope and +/// deletes each entry; `state::delete` is idempotent so a race with +/// another scenario's teardown is harmless. +pub async fn reset_state(iii: &III) { + for scope in ["skills", "prompts"] { + let listed = iii + .trigger(TriggerRequest { + function_id: "state::list".to_string(), + payload: json!({ "scope": scope }), + action: None, + timeout_ms: Some(5_000), + }) + .await + .ok(); + let Some(raw) = listed else { + continue; + }; + for value in extract_ids(raw, scope) { + let _ = iii + .trigger(TriggerRequest { + function_id: "state::delete".to_string(), + payload: json!({ "scope": scope, "key": value }), + action: None, + timeout_ms: Some(2_000), + }) + .await; + } + } +} + +/// `state::list` returns different shapes depending on the backend. +/// Extract the entries whose `.id` / `.name` looks like a key for our +/// scope and return those keys. +fn extract_ids(raw: Value, scope: &str) -> Vec { + let values: Vec = if let Value::Array(arr) = raw { + arr + } else if let Some(items) = raw.get("items").and_then(|v| v.as_array()) { + items + .iter() + .filter_map(|item| item.get("value").cloned()) + .collect() + } else if let Some(arr) = raw.get("value").and_then(|v| v.as_array()) { + arr.clone() + } else { + return Vec::new(); + }; + values + .into_iter() + .filter_map(|v| match scope { + "skills" => v.get("id").and_then(|x| x.as_str()).map(String::from), + "prompts" => v.get("name").and_then(|x| x.as_str()).map(String::from), + _ => None, + }) + .collect() +} diff --git a/skills/tests/common/world.rs b/skills/tests/common/world.rs new file mode 100644 index 00000000..0ca90b18 --- /dev/null +++ b/skills/tests/common/world.rs @@ -0,0 +1,61 @@ +//! Per-scenario World. +//! +//! Holds: +//! +//! - `iii` โ€” `None` when the engine is unreachable so `@engine` steps +//! can soft-skip without failing the run. +//! - `cfg` โ€” the SkillsConfig the in-process registration used. +//! - `unique_id` โ€” UUID-prefixed id used to namespace state writes +//! per scenario (the `skills` / `prompts` state scopes are +//! process-wide on the engine side). +//! - `stash` โ€” typed outcome slots a `Then` step can read after the +//! matching `When` step wrote. + +use std::collections::HashMap; +use std::sync::Arc; + +use cucumber::World; +use iii_sdk::III; +use serde_json::Value; +use uuid::Uuid; + +use iii_skills::config::SkillsConfig; + +#[derive(World)] +#[world(init = Self::new)] +pub struct IiiSkillsWorld { + pub iii: Option>, + pub cfg: Arc, + pub unique_id: String, + pub stash: HashMap, +} + +impl std::fmt::Debug for IiiSkillsWorld { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("IiiSkillsWorld") + .field("engine_connected", &self.iii.is_some()) + .field("unique_id", &self.unique_id) + .finish() + } +} + +impl IiiSkillsWorld { + pub fn new() -> Self { + let unique_id = format!("bdd-{}", &Uuid::new_v4().simple().to_string()[..12]); + Self { + iii: None, + cfg: Arc::new(SkillsConfig::default()), + unique_id, + stash: HashMap::new(), + } + } + + /// Scenario-scoped id prefix for state-scope isolation. Call this + /// whenever a scenario needs an id / name that won't collide with a + /// concurrent scenario or a leftover from a previous binary run. + pub fn scoped_id(&self, base: &str) -> String { + let id = format!("{}-{}", base, self.unique_id); + // skills::validate_id caps at 64 chars; keep a comfortable margin. + id.chars().take(64).collect() + } +} diff --git a/skills/tests/features/markdown.feature b/skills/tests/features/markdown.feature new file mode 100644 index 00000000..b37a2367 --- /dev/null +++ b/skills/tests/features/markdown.feature @@ -0,0 +1,179 @@ +@pure @markdown +Feature: pure markdown, URI, and validation helpers + Runs without the iii engine. Covers the helpers that back the + `skills::resources-*` and prompts-normalize paths so the hot loop + doesn't need an engine round-trip just to assert on them. + + # โ”€โ”€ extract_title โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: extract_title picks up the first H1 + When I extract the title from: + """ + # my skill + + body + """ + Then the extracted title is "my skill" + + Scenario: extract_title ignores H2 headings + When I extract the title from: + """ + ## sub + + body + """ + Then there is no extracted title + + # โ”€โ”€ extract_description โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: extract_description grabs the first paragraph + When I extract the description from: + """ + # title + + first paragraph here. + + second paragraph. + """ + Then the extracted description is "first paragraph here." + + Scenario: extract_description skips subheadings before finding text + When I extract the description from: + """ + # title + + ## sub + + ### deeper + + finally text. + """ + Then the extracted description is "finally text." + + Scenario: extract_description returns nothing for heading-only docs + When I extract the description from: + """ + # only a title + """ + Then there is no extracted description + + # โ”€โ”€ truncate_chars โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: truncate_chars keeps multibyte characters intact + Given the string "รกรฉรญรณรบ" repeated 50 times + When I truncate it to 5 chars + Then the truncated string has 8 chars + And the truncated string ends with ... + + # โ”€โ”€ parse_uri โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: parse_uri returns Index for iii://skills + When I parse the URI "iii://skills" + Then parse_uri returns the index shape + + Scenario: parse_uri returns Skill for iii://brain + When I parse the URI "iii://brain" + Then parse_uri returns a skill with id "brain" + + Scenario: parse_uri returns Section for iii://skill/fn + When I parse the URI "iii://brain/brain::summarize" + Then parse_uri returns a section with skill "brain" and function "brain::summarize" + + Scenario: parse_uri rejects a missing scheme + When I parse the URI "brain" + Then parse_uri fails + + Scenario: parse_uri rejects extra path segments + When I parse the URI "iii://x/y/z" + Then parse_uri fails + + # โ”€โ”€ validate_id โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: validate_id accepts kebab / underscore lowercase + When I validate the skill id "my-skill-1" + Then the skill id validation succeeds + + Scenario: validate_id rejects uppercase + When I validate the skill id "UpperCase" + Then the skill id validation fails + + Scenario: validate_id rejects 65-char ids + When I validate a skill id of 65 lowercase letters + Then the skill id validation fails + + # โ”€โ”€ validate_name (prompts) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: validate_name accepts kebab / underscore + When I validate the prompt name "send-email" + Then the prompt name validation succeeds + + Scenario: validate_name rejects :: in the name + When I validate the prompt name "mcp::send" + Then the prompt name validation fails + + Scenario: validate_arguments rejects duplicates + When I validate a duplicate argument pair + Then argument validation fails + + Scenario: validate_arguments rejects empty names + When I validate an empty argument name + Then argument validation fails + + # โ”€โ”€ normalize_function_output (iii://skill/fn) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: normalize_function_output string -> markdown + When I normalize a markdown string output + Then the normalized mime is "text/markdown" + And the normalized text is "hello" + + Scenario: normalize_function_output {content} -> markdown + When I normalize a {content} output + Then the normalized mime is "text/markdown" + And the normalized text is "hi" + + Scenario: normalize_function_output other -> JSON + When I normalize an arbitrary JSON output + Then the normalized mime is "application/json" + And the normalized text is JSON containing "x" + + # โ”€โ”€ normalize_prompt_output โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: normalize_prompt_output string -> single user message + When I normalize a prompt output string + Then the normalized messages length is 1 + + Scenario: normalize_prompt_output messages -> pass-through + When I normalize a prompt output with a messages array + Then the normalized messages length is 2 + + Scenario: normalize_prompt_output unsupported shape fails + When I normalize a prompt output of unsupported shape + Then prompt normalization fails + + # โ”€โ”€ is_always_hidden โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario Outline: infra namespaces are hard-floored + When I check the hard floor for "" + Then the function id is hard-floored + + Examples: + | function_id | + | state::get | + | engine::workers | + | stream::publish | + | iii.on_foo | + | iii::internal | + | mcp::handler | + | a2a::send | + | skills::register | + | prompts::register | + + Scenario Outline: ordinary namespaces are not hard-floored + When I check the hard floor for "" + Then the function id is not hard-floored + + Examples: + | function_id | + | mem::observe | + | brain::summarize | + | my-worker::my-fn | diff --git a/skills/tests/features/mcp_bridge.feature b/skills/tests/features/mcp_bridge.feature new file mode 100644 index 00000000..dd8c842d --- /dev/null +++ b/skills/tests/features/mcp_bridge.feature @@ -0,0 +1,28 @@ +@engine @mcp_bridge +Feature: skills::resources-* and prompts::mcp-* bridge to the mcp worker + The `mcp` worker serves MCP `resources/*` and `prompts/*` by calling + the internal RPC this worker exposes. These scenarios lock in the + exact envelope shape the `mcp` dispatcher expects so a renamed + field or missing key is caught immediately. + + Background: + Given the iii engine is reachable + And a skill and a prompt are registered for the bridge test + + Scenario: skills::resources-list returns the MCP resources/list envelope + When I call skills::resources-list through the bridge + Then the bridged resources envelope has the iii://skills index + And the bridged resources envelope includes the seeded skill uri + + Scenario: skills::resources-read round-trips a registered skill body + When I call skills::resources-read on the seeded skill uri + Then the bridged read contents mime is text/markdown + And the bridged read contents text includes the skill body + + Scenario: prompts::mcp-list returns the MCP-shaped arguments array + When I call prompts::mcp-list through the bridge + Then the bridged prompts listing includes the seeded prompt with a required argument + + Scenario: prompts::mcp-get dispatches the handler and returns the MCP messages shape + When I call prompts::mcp-get through the bridge with arguments to=alice@example.com + Then the bridged prompts::mcp-get returns a single user message diff --git a/skills/tests/features/notifications.feature b/skills/tests/features/notifications.feature new file mode 100644 index 00000000..b71b5eb5 --- /dev/null +++ b/skills/tests/features/notifications.feature @@ -0,0 +1,37 @@ +@engine @notifications +Feature: skills::on-change and prompts::on-change fan-out + Each mutation of the skills / prompts registries fans out through + the custom trigger types `skills::on-change` and `prompts::on-change`. + These scenarios register an in-process subscriber, mutate the + registry, and assert the subscriber observed the expected number of + events within a bounded window. + + Background: + Given the iii engine is reachable + + Scenario: skills::register fires skills::on-change + Given a subscriber to skills::on-change is registered + When I register a scoped skill with a short body + Then the subscriber observed at least 1 event within 3000 ms + + Scenario: skills::unregister fires skills::on-change + Given a subscriber to skills::on-change is registered + When I register a scoped skill with a short body + And I unregister that skill + Then the subscriber observed at least 2 events within 4000 ms + + Scenario: 3 rapid skill mutations each produce a notification + Given a subscriber to skills::on-change is registered + When I register 3 scoped skills in quick succession + Then the subscriber observed at least 3 events within 5000 ms + + Scenario: prompts::register fires prompts::on-change + Given a subscriber to prompts::on-change is registered + When I register a scoped prompt + Then the subscriber observed at least 1 event within 3000 ms + + Scenario: prompts::unregister fires prompts::on-change + Given a subscriber to prompts::on-change is registered + When I register a scoped prompt + And I unregister that prompt + Then the subscriber observed at least 2 events within 4000 ms diff --git a/skills/tests/features/prompts_get.feature b/skills/tests/features/prompts_get.feature new file mode 100644 index 00000000..9955b45b --- /dev/null +++ b/skills/tests/features/prompts_get.feature @@ -0,0 +1,50 @@ +@engine @prompts_get +Feature: prompts::mcp-get (the internal RPC behind MCP prompts/get) + `prompts::mcp-get` looks a prompt up by name, invokes its handler + via `iii.trigger`, and normalizes the handler output into the + `{ description, messages: [...] }` shape the MCP worker passes to + clients. Unknown prompts error; infra-namespace handlers are + rejected by the hard floor. + + Background: + Given the iii engine is reachable + + Scenario: a string handler is wrapped as a single user message + Given a prompt handler that returns a string + When I call prompts::mcp-get on the scoped prompt + Then the mcp-get call succeeds + And the messages array has length 1 + And message 0 has role "user" and text "str body" + And the result description is "bdd prompt" + + Scenario: a {content} handler is wrapped as a single user message + Given a prompt handler that returns a {content} object + When I call prompts::mcp-get on the scoped prompt + Then the mcp-get call succeeds + And the messages array has length 1 + And message 0 has role "user" and text "obj body" + + Scenario: a {messages: [...]} handler is passed through unchanged + Given a prompt handler that returns a {messages: [...]} object + When I call prompts::mcp-get on the scoped prompt + Then the mcp-get call succeeds + And the messages array has length 2 + And message 0 has role "user" and text "m1" + And message 1 has role "assistant" and text "m2" + + Scenario: a handler returning an unsupported shape fails the call + Given a prompt handler that returns an unsupported shape + When I call prompts::mcp-get on the scoped prompt + Then the mcp-get call fails + And the mcp-get error mentions "unsupported shape" + + Scenario: calling mcp-get on an unknown prompt returns a not-found error + When I call prompts::mcp-get with an unknown name "no-such-prompt" + Then the mcp-get call fails + And the mcp-get error mentions "not found" + + Scenario: a prompt pointing at an infra-namespace handler is rejected by the hard floor + Given a prompt pointing at the infra function "state::set" + When I call prompts::mcp-get on the scoped prompt + Then the mcp-get call fails + And the mcp-get error mentions "internal namespace" diff --git a/skills/tests/features/prompts_register.feature b/skills/tests/features/prompts_register.feature new file mode 100644 index 00000000..4e36835d --- /dev/null +++ b/skills/tests/features/prompts_register.feature @@ -0,0 +1,79 @@ +@engine @prompts_register +Feature: prompts::register / unregister / list + The prompts registry validates name, description, function_id, and + arguments (no duplicate / empty names) before writing to the + `prompts` scope. Re-registration overwrites; unregister is idempotent; + list returns metadata sorted by name without dispatching handlers. + + Background: + Given the iii engine is reachable + + # โ”€โ”€ name validation โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: register rejects an empty name + When I register a prompt with name "", description "x", function_id "test::handler" + Then the prompts::register call fails + And the prompts::register error mentions "name must be non-empty" + + Scenario: register rejects an uppercase name + When I register a prompt with name "BadName", description "x", function_id "test::handler" + Then the prompts::register call fails + And the prompts::register error mentions "lowercase" + + Scenario: register rejects a name with a space + When I register a prompt with name "bad name", description "x", function_id "test::handler" + Then the prompts::register call fails + + Scenario: register rejects a name with :: like a function id + When I register a prompt with name "mcp::register", description "x", function_id "test::handler" + Then the prompts::register call fails + + # โ”€โ”€ description / function_id validation โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: register rejects a blank description + When I register a prompt with name "ok", description " ", function_id "test::handler" + Then the prompts::register call fails + And the prompts::register error mentions "description must be non-empty" + + Scenario: register rejects a missing function_id + When I register a prompt with name "ok", description "x", function_id "" + Then the prompts::register call fails + And the prompts::register error mentions "function_id must be non-empty" + + # โ”€โ”€ arguments validation โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: register rejects duplicate argument names + When I register a prompt with duplicate argument names + Then the prompts::register call fails + And the prompts::register error mentions "duplicate argument name" + + Scenario: register rejects an empty argument name + When I register a prompt with an empty argument name + Then the prompts::register call fails + And the prompts::register error mentions "argument name must be non-empty" + + # โ”€โ”€ round-trip โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: register then list surfaces the scoped prompt + When I register a scoped prompt "simple" pointing at "test::handler" + Then the prompts::register call succeeds + When I list prompts + Then the scoped prompt appears in the listing + And each prompt listing entry carries arguments count, function_id, and registered_at + And the prompt listing is sorted by name + + Scenario: re-register overwrites and refreshes the timestamp + When I register a scoped prompt "twice" pointing at "test::handler" + And I record the registered_at timestamp for the prompt + And I re-register the scoped prompt with description "refreshed" + Then the prompts::register call succeeds + And the re-registered prompt timestamp is different from the first + + Scenario: unregister is idempotent + When I register a scoped prompt "gone" pointing at "test::handler" + And I unregister the scoped prompt + Then the last prompt unregister returned removed=true + When I unregister the scoped prompt again + Then the last prompt unregister returned removed=false + When I list prompts + Then the scoped prompt does not appear in the listing diff --git a/skills/tests/features/skills_register.feature b/skills/tests/features/skills_register.feature new file mode 100644 index 00000000..69498297 --- /dev/null +++ b/skills/tests/features/skills_register.feature @@ -0,0 +1,79 @@ +@engine @skills_register +Feature: skills::register / unregister / list + The state-backed skills registry validates ids + bodies up front, + writes to the `skills` scope, fans out through the + `skills::on-change` trigger type, and supports idempotent removal. + + Background: + Given the iii engine is reachable + + # โ”€โ”€ id validation โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: register rejects an empty id + When I register a skill with id "" and body "# hi" + Then the skills::register call fails + And the skills::register error mentions "id must be non-empty" + + Scenario: register rejects an uppercase id + When I register a skill with id "Bad-Id" and body "# hi" + Then the skills::register call fails + And the skills::register error mentions "lowercase" + + Scenario: register rejects an id with a space + When I register a skill with id "with space" and body "# hi" + Then the skills::register call fails + + Scenario: register rejects an id with a slash + When I register a skill with id "with/slash" and body "# hi" + Then the skills::register call fails + + Scenario: register rejects an id with a colon + When I register a skill with id "with::colon" and body "# hi" + Then the skills::register call fails + + Scenario: register rejects a 65-char id + When I register a skill with id "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" and body "# ok" + Then the skills::register call fails + And the skills::register error mentions "too long" + + # โ”€โ”€ body validation โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: register rejects an empty body + When I register a skill with id "emptyid" and an empty body + Then the skills::register call fails + And the skills::register error mentions "non-empty" + + Scenario: register rejects a body bigger than 256 KiB + When I register a skill with id "bigid" and a body of 262145 bytes + Then the skills::register call fails + And the skills::register error mentions "too large" + + Scenario: register accepts a body right at 256 KiB + When I register a skill with id "maxid" and a body of 262144 bytes + Then the skills::register call succeeds + + # โ”€โ”€ round-trip โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: register then list shows the scoped skill + When I register a scoped skill "smoke" with body "# smoke\n\nsmoke body" + Then the skills::register call succeeds + When I list skills + Then the scoped skill appears in the listing + And the listing entries carry bytes and registered_at but no skill body + And the listing is sorted by id + + Scenario: re-register overwrites the body and refreshes the timestamp + When I register a scoped skill "twice" with body "# one\nfirst" + And I record the registered_at timestamp + And I re-register the scoped skill with body "# one\nsecond" + Then the skills::register call succeeds + And the re-registered timestamp is different from the first + + Scenario: unregister is idempotent + When I register a scoped skill "gone" with body "# gone\nbody" + And I unregister the scoped skill + Then the last unregister returned removed=true + When I unregister the scoped skill again + Then the last unregister returned removed=false + When I list skills + Then the scoped skill does not appear in the listing diff --git a/skills/tests/features/skills_resources.feature b/skills/tests/features/skills_resources.feature new file mode 100644 index 00000000..ef092045 --- /dev/null +++ b/skills/tests/features/skills_resources.feature @@ -0,0 +1,119 @@ +@engine @skills_resources +Feature: iii:// resource resolver (skills::resources-list / read / templates) + The `skills::resources-*` internal RPC serves the `iii://skills` + index, registered `iii://{id}` bodies, and `iii://{id}/{fn}` sections + that delegate to a sub-skill function. Normalization turns strings, + `{content}` objects, and JSON into the contents envelope shape the + `mcp` worker forwards to MCP `resources/read`. + + Background: + Given the iii engine is reachable + + # โ”€โ”€ resources-list โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: resources-list exposes the iii://skills index and every registered skill + Given a skill with id "listed" and body: + """ + # Listed + + This skill shows up in the index. + """ + When I call skills::resources-list + Then the resource list includes iii://skills + And the resource list includes the seeded skill URI + + Scenario: resources-templates returns the two URI templates + When I call skills::resources-templates + Then the templates listing contains the skill and skill-section templates + + # โ”€โ”€ reading iii:// URIs โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: iii://skills renders a markdown index with title and description + Given a skill with id "indexed" and body: + """ + # Indexed skill + + First paragraph summary. + + Ignored second paragraph. + """ + When I read iii://skills + Then the contents mime type is "text/markdown" + And the contents text contains "# Skills" + And the contents text contains "Indexed skill" + And the contents text contains "First paragraph summary." + + Scenario: iii://{id} returns the registered body as text/markdown + Given a skill with id "body" and body: + """ + # Body skill + + The full body goes here. + """ + When I read the seeded skill URI + Then the contents mime type is "text/markdown" + And the contents text contains "The full body goes here." + + # โ”€โ”€ section shapes โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: iii://{skill}/{fn} returning a markdown string is served as text/markdown + Given a skill with id "sec-str" and body: + """ + # sec-str + """ + And a sub-skill function that returns a markdown string + When I read the section URI with skill id "sec-str" + Then the contents mime type is "text/markdown" + And the contents text contains "str-section" + + Scenario: iii://{skill}/{fn} returning {content} is served as text/markdown + Given a skill with id "sec-obj" and body: + """ + # sec-obj + """ + And a sub-skill function that returns a {content} object + When I read the section URI with skill id "sec-obj" + Then the contents mime type is "text/markdown" + And the contents text contains "wrapped" + + Scenario: iii://{skill}/{fn} returning arbitrary JSON falls back to application/json + Given a skill with id "sec-json" and body: + """ + # sec-json + """ + And a sub-skill function that returns an arbitrary JSON object + When I read the section URI with skill id "sec-json" + Then the contents mime type is "application/json" + And the contents text contains "count" + + # โ”€โ”€ recursion guard โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: the section resolver refuses state:: as a function id + When I read the URI "iii://anything/state::set" + Then the read fails with a message mentioning "internal namespace" + + Scenario: the section resolver refuses mcp:: as a function id + When I read the URI "iii://x/mcp::handler" + Then the read fails with a message mentioning "internal namespace" + + Scenario: the section resolver refuses skills:: to block tunnelling into the admin API + When I read the URI "iii://x/skills::register" + Then the read fails with a message mentioning "internal namespace" + + Scenario: the section resolver refuses prompts:: as a function id + When I read the URI "iii://x/prompts::register" + Then the read fails with a message mentioning "internal namespace" + + # โ”€โ”€ URI validation โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + + Scenario: a URI without the iii:// prefix is rejected + When I read the URI "https://example.com" + Then the read fails with a message mentioning "iii://" + + Scenario: a URI with more than two path segments is rejected + When I read the URI "iii://a/b/c" + Then the read fails with a message mentioning "more than one path segment" + + Scenario: reading an unknown skill returns a not-found error + When I read the URI "iii://no-such-skill-does-not-exist" + Then the read fails with a message mentioning "not found" diff --git a/skills/tests/steps/markdown.rs b/skills/tests/steps/markdown.rs new file mode 100644 index 00000000..0a328b31 --- /dev/null +++ b/skills/tests/steps/markdown.rs @@ -0,0 +1,426 @@ +//! Step defs for tests/features/markdown.feature. +//! +//! Pure, engine-free unit tests of the markdown / URI / validation +//! helpers that the skills module exposes. Runs under `--tags @pure` +//! on CI hosts without `iii`. + +use cucumber::{given, then, when}; +use serde_json::{json, Value}; + +use crate::common::world::IiiSkillsWorld; +use iii_skills::functions::prompts; +use iii_skills::functions::skills::{ + self, extract_description, extract_title, is_always_hidden, normalize_function_output, + parse_uri, truncate_chars, validate_id, ParsedUri, +}; + +const BUF_INPUT: &str = "md_input"; +const BUF_OUTPUT: &str = "md_output"; +const BUF_ERR: &str = "md_error"; +const BUF_MIME: &str = "md_mime"; + +// โ”€โ”€ title / description โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when(regex = r#"^I extract the title from:$"#)] +fn when_extract_title(world: &mut IiiSkillsWorld, step: &cucumber::gherkin::Step) { + let md = step.docstring.clone().unwrap_or_default(); + let got = extract_title(&md) + .map(|s| Value::String(s.to_string())) + .unwrap_or(Value::Null); + world.stash.insert(BUF_OUTPUT.into(), got); +} + +#[then(regex = r#"^the extracted title is "([^"]+)"$"#)] +fn then_title_is(world: &mut IiiSkillsWorld, want: String) { + let got = world.stash.get(BUF_OUTPUT).unwrap(); + assert_eq!(got.as_str(), Some(want.as_str())); +} + +#[then("there is no extracted title")] +fn then_no_title(world: &mut IiiSkillsWorld) { + let got = world.stash.get(BUF_OUTPUT).unwrap(); + assert!(got.is_null(), "expected Null; got {got}"); +} + +#[when(regex = r#"^I extract the description from:$"#)] +fn when_extract_desc(world: &mut IiiSkillsWorld, step: &cucumber::gherkin::Step) { + let md = step.docstring.clone().unwrap_or_default(); + let got = extract_description(&md) + .map(Value::String) + .unwrap_or(Value::Null); + world.stash.insert(BUF_OUTPUT.into(), got); +} + +#[then(regex = r#"^the extracted description is "([^"]+)"$"#)] +fn then_desc_is(world: &mut IiiSkillsWorld, want: String) { + let got = world.stash.get(BUF_OUTPUT).unwrap(); + assert_eq!(got.as_str(), Some(want.as_str())); +} + +#[then("there is no extracted description")] +fn then_no_desc(world: &mut IiiSkillsWorld) { + let got = world.stash.get(BUF_OUTPUT).unwrap(); + assert!(got.is_null(), "expected Null; got {got}"); +} + +// โ”€โ”€ truncate_chars โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[given(regex = r#"^the string "([^"]*)" repeated (\d+) times$"#)] +fn given_repeated(world: &mut IiiSkillsWorld, s: String, n: usize) { + world + .stash + .insert(BUF_INPUT.into(), Value::String(s.repeat(n))); +} + +#[when(regex = r#"^I truncate it to (\d+) chars$"#)] +fn when_truncate(world: &mut IiiSkillsWorld, n: usize) { + let input = world.stash.get(BUF_INPUT).and_then(|v| v.as_str()).unwrap(); + let got = truncate_chars(input, n); + world.stash.insert(BUF_OUTPUT.into(), Value::String(got)); +} + +#[then(regex = r#"^the truncated string has (\d+) chars$"#)] +fn then_truncated_len(world: &mut IiiSkillsWorld, want: usize) { + let got = world + .stash + .get(BUF_OUTPUT) + .and_then(|v| v.as_str()) + .unwrap(); + assert_eq!(got.chars().count(), want, "{got:?}"); +} + +#[then("the truncated string ends with ...")] +fn then_truncated_ends_ellipsis(world: &mut IiiSkillsWorld) { + let got = world + .stash + .get(BUF_OUTPUT) + .and_then(|v| v.as_str()) + .unwrap(); + assert!(got.ends_with("..."), "{got:?}"); +} + +// โ”€โ”€ parse_uri โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when(regex = r#"^I parse the URI "([^"]*)"$"#)] +fn when_parse_uri(world: &mut IiiSkillsWorld, uri: String) { + world.stash.remove(BUF_OUTPUT); + world.stash.remove(BUF_ERR); + match parse_uri(&uri) { + Ok(ParsedUri::Index) => { + world + .stash + .insert(BUF_OUTPUT.into(), json!({ "kind": "index" })); + } + Ok(ParsedUri::Skill(id)) => { + world + .stash + .insert(BUF_OUTPUT.into(), json!({ "kind": "skill", "id": id })); + } + Ok(ParsedUri::Section { + skill_id, + function_id, + }) => { + world.stash.insert( + BUF_OUTPUT.into(), + json!({ "kind": "section", "skill_id": skill_id, "function_id": function_id }), + ); + } + Err(e) => { + world.stash.insert(BUF_ERR.into(), Value::String(e)); + } + } +} + +#[then(regex = r#"^parse_uri returns the index shape$"#)] +fn then_parse_index(world: &mut IiiSkillsWorld) { + let v = world.stash.get(BUF_OUTPUT).unwrap(); + assert_eq!(v["kind"].as_str(), Some("index"), "{v}"); +} + +#[then(regex = r#"^parse_uri returns a skill with id "([^"]+)"$"#)] +fn then_parse_skill(world: &mut IiiSkillsWorld, id: String) { + let v = world.stash.get(BUF_OUTPUT).unwrap(); + assert_eq!(v["kind"].as_str(), Some("skill")); + assert_eq!(v["id"].as_str(), Some(id.as_str())); +} + +#[then(regex = r#"^parse_uri returns a section with skill "([^"]+)" and function "([^"]+)"$"#)] +fn then_parse_section(world: &mut IiiSkillsWorld, skill: String, function: String) { + let v = world.stash.get(BUF_OUTPUT).unwrap(); + assert_eq!(v["kind"].as_str(), Some("section")); + assert_eq!(v["skill_id"].as_str(), Some(skill.as_str())); + assert_eq!(v["function_id"].as_str(), Some(function.as_str())); +} + +#[then("parse_uri fails")] +fn then_parse_fails(world: &mut IiiSkillsWorld) { + assert!( + world.stash.contains_key(BUF_ERR), + "expected error; got success" + ); +} + +// โ”€โ”€ validate_id / validate_name โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when(regex = r#"^I validate the skill id "([^"]*)"$"#)] +fn when_validate_id(world: &mut IiiSkillsWorld, id: String) { + world.stash.remove(BUF_ERR); + match validate_id(&id) { + Ok(()) => { + world.stash.insert(BUF_OUTPUT.into(), Value::Bool(true)); + } + Err(e) => { + world.stash.insert(BUF_ERR.into(), Value::String(e)); + } + } +} + +#[when(regex = r#"^I validate a skill id of (\d+) lowercase letters$"#)] +fn when_validate_id_sized(world: &mut IiiSkillsWorld, n: usize) { + let id = "a".repeat(n); + when_validate_id(world, id) +} + +#[then("the skill id validation succeeds")] +fn then_validate_id_ok(world: &mut IiiSkillsWorld) { + assert!( + world.stash.contains_key(BUF_OUTPUT), + "error: {:?}", + world.stash.get(BUF_ERR) + ); +} + +#[then("the skill id validation fails")] +fn then_validate_id_err(world: &mut IiiSkillsWorld) { + assert!( + world.stash.contains_key(BUF_ERR), + "expected error; got {:?}", + world.stash.get(BUF_OUTPUT) + ); +} + +#[when(regex = r#"^I validate the prompt name "([^"]*)"$"#)] +fn when_validate_prompt(world: &mut IiiSkillsWorld, name: String) { + world.stash.remove(BUF_ERR); + match prompts::validate_name(&name) { + Ok(()) => { + world.stash.insert(BUF_OUTPUT.into(), Value::Bool(true)); + } + Err(e) => { + world.stash.insert(BUF_ERR.into(), Value::String(e)); + } + } +} + +#[then("the prompt name validation succeeds")] +fn then_validate_prompt_ok(world: &mut IiiSkillsWorld) { + assert!( + world.stash.contains_key(BUF_OUTPUT), + "error: {:?}", + world.stash.get(BUF_ERR) + ); +} + +#[then("the prompt name validation fails")] +fn then_validate_prompt_err(world: &mut IiiSkillsWorld) { + assert!( + world.stash.contains_key(BUF_ERR), + "expected error; got success" + ); +} + +#[when("I validate a duplicate argument pair")] +fn when_validate_arg_dup(world: &mut IiiSkillsWorld) { + let args = vec![ + prompts::PromptArgument { + name: "to".into(), + description: None, + required: true, + }, + prompts::PromptArgument { + name: "to".into(), + description: None, + required: false, + }, + ]; + match prompts::validate_arguments(&args) { + Ok(()) => { + world.stash.insert(BUF_OUTPUT.into(), Value::Bool(true)); + } + Err(e) => { + world.stash.insert(BUF_ERR.into(), Value::String(e)); + } + } +} + +#[when("I validate an empty argument name")] +fn when_validate_arg_empty(world: &mut IiiSkillsWorld) { + let args = vec![prompts::PromptArgument { + name: "".into(), + description: None, + required: true, + }]; + match prompts::validate_arguments(&args) { + Ok(()) => { + world.stash.insert(BUF_OUTPUT.into(), Value::Bool(true)); + } + Err(e) => { + world.stash.insert(BUF_ERR.into(), Value::String(e)); + } + } +} + +#[then("argument validation fails")] +fn then_arg_validation_fails(world: &mut IiiSkillsWorld) { + assert!( + world.stash.contains_key(BUF_ERR), + "expected error; got success" + ); +} + +// โ”€โ”€ normalize_function_output โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when("I normalize a markdown string output")] +fn when_norm_string(world: &mut IiiSkillsWorld) { + let (text, mime) = normalize_function_output(Value::String("hello".into())); + world.stash.insert(BUF_OUTPUT.into(), Value::String(text)); + world + .stash + .insert(BUF_MIME.into(), Value::String(mime.into())); +} + +#[when("I normalize a {content} output")] +fn when_norm_content(world: &mut IiiSkillsWorld) { + let (text, mime) = normalize_function_output(json!({ "content": "hi" })); + world.stash.insert(BUF_OUTPUT.into(), Value::String(text)); + world + .stash + .insert(BUF_MIME.into(), Value::String(mime.into())); +} + +#[when("I normalize an arbitrary JSON output")] +fn when_norm_json(world: &mut IiiSkillsWorld) { + let (text, mime) = normalize_function_output(json!({ "x": 1 })); + world.stash.insert(BUF_OUTPUT.into(), Value::String(text)); + world + .stash + .insert(BUF_MIME.into(), Value::String(mime.into())); +} + +#[then(regex = r#"^the normalized mime is "([^"]+)"$"#)] +fn then_norm_mime(world: &mut IiiSkillsWorld, want: String) { + let got = world.stash.get(BUF_MIME).and_then(|v| v.as_str()).unwrap(); + assert_eq!(got, want); +} + +#[then(regex = r#"^the normalized text is "([^"]+)"$"#)] +fn then_norm_text(world: &mut IiiSkillsWorld, want: String) { + let got = world + .stash + .get(BUF_OUTPUT) + .and_then(|v| v.as_str()) + .unwrap(); + assert_eq!(got, want); +} + +#[then("the normalized text is JSON containing \"x\"")] +fn then_norm_text_has_x(world: &mut IiiSkillsWorld) { + let got = world + .stash + .get(BUF_OUTPUT) + .and_then(|v| v.as_str()) + .unwrap(); + assert!(got.contains("\"x\""), "{got}"); +} + +// โ”€โ”€ normalize_prompt_output โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when("I normalize a prompt output string")] +fn when_prompt_norm_string(world: &mut IiiSkillsWorld) { + match prompts::normalize_prompt_output(Value::String("hello".into())) { + Ok(v) => { + world.stash.insert(BUF_OUTPUT.into(), v); + } + Err(e) => { + world.stash.insert(BUF_ERR.into(), Value::String(e)); + } + } +} + +#[when("I normalize a prompt output with a messages array")] +fn when_prompt_norm_messages(world: &mut IiiSkillsWorld) { + match prompts::normalize_prompt_output(json!({ + "messages": [ + { "role": "user", "content": { "type": "text", "text": "a" } }, + { "role": "assistant", "content": { "type": "text", "text": "b" } } + ] + })) { + Ok(v) => { + world.stash.insert(BUF_OUTPUT.into(), v); + } + Err(e) => { + world.stash.insert(BUF_ERR.into(), Value::String(e)); + } + } +} + +#[when("I normalize a prompt output of unsupported shape")] +fn when_prompt_norm_bad(world: &mut IiiSkillsWorld) { + match prompts::normalize_prompt_output(json!({ "x": 1 })) { + Ok(v) => { + world.stash.insert(BUF_OUTPUT.into(), v); + } + Err(e) => { + world.stash.insert(BUF_ERR.into(), Value::String(e)); + } + } +} + +#[then(regex = r#"^the normalized messages length is (\d+)$"#)] +fn then_norm_messages_len(world: &mut IiiSkillsWorld, want: usize) { + let v = world.stash.get(BUF_OUTPUT).unwrap(); + assert_eq!(v.as_array().map(|a| a.len()).unwrap_or(0), want, "{v}"); +} + +#[then("prompt normalization fails")] +fn then_norm_fails(world: &mut IiiSkillsWorld) { + assert!( + world.stash.contains_key(BUF_ERR), + "expected error; got success" + ); +} + +// โ”€โ”€ is_always_hidden โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when(regex = r#"^I check the hard floor for "([^"]*)"$"#)] +fn when_check_floor(world: &mut IiiSkillsWorld, fid: String) { + world + .stash + .insert(BUF_OUTPUT.into(), Value::Bool(is_always_hidden(&fid))); +} + +#[then("the function id is hard-floored")] +fn then_floored(world: &mut IiiSkillsWorld) { + let got = world + .stash + .get(BUF_OUTPUT) + .and_then(|v| v.as_bool()) + .unwrap(); + assert!(got, "expected hard-floored"); +} + +#[then("the function id is not hard-floored")] +fn then_not_floored(world: &mut IiiSkillsWorld) { + let got = world + .stash + .get(BUF_OUTPUT) + .and_then(|v| v.as_bool()) + .unwrap(); + assert!(!got, "expected NOT hard-floored"); +} + +// Used by a handful of scenarios that just need the module loaded. +#[allow(dead_code)] +fn _force_imports() { + let _ = skills::list_templates(); +} diff --git a/skills/tests/steps/mcp_bridge.rs b/skills/tests/steps/mcp_bridge.rs new file mode 100644 index 00000000..743cbc54 --- /dev/null +++ b/skills/tests/steps/mcp_bridge.rs @@ -0,0 +1,232 @@ +//! Step defs for tests/features/mcp_bridge.feature. +//! +//! End-to-end shape checks that prove the internal RPC the `mcp` worker +//! will call returns exactly the JSON envelope MCP expects. + +use cucumber::{given, then, when}; +use iii_sdk::{IIIError, RegisterFunction, TriggerRequest}; +use serde_json::{json, Value}; + +use crate::common::world::IiiSkillsWorld; + +const LAST: &str = "mcp_bridge_last"; + +async fn call(world: &mut IiiSkillsWorld, function_id: &str, payload: Value) { + world.stash.remove(LAST); + let Some(iii) = world.iii.clone() else { + return; + }; + if let Ok(v) = iii + .trigger(TriggerRequest { + function_id: function_id.into(), + payload, + action: None, + timeout_ms: Some(5_000), + }) + .await + { + world.stash.insert(LAST.into(), v); + } +} + +#[given("a skill and a prompt are registered for the bridge test")] +async fn seed_bridge(world: &mut IiiSkillsWorld) { + let Some(iii) = world.iii.clone() else { + return; + }; + let skill_id = world.scoped_id("bridge"); + world + .stash + .insert("bridge_skill_id".into(), Value::String(skill_id.clone())); + let _ = iii + .trigger(TriggerRequest { + function_id: "skills::register".to_string(), + payload: json!({ + "id": skill_id, + "skill": "# bridge\n\nbody content\n", + }), + action: None, + timeout_ms: Some(5_000), + }) + .await; + + // Handler backing the prompt. + let handler_id = format!("bdd::bridge-handler-{}", world.unique_id); + world.stash.insert( + "bridge_handler_id".into(), + Value::String(handler_id.clone()), + ); + iii.register_function( + RegisterFunction::new_async(handler_id.clone(), |_input: Value| async move { + Ok::<_, IIIError>(json!({ "content": "bridge body" })) + }) + .description("bdd bridge prompt handler"), + ); + tokio::time::sleep(std::time::Duration::from_millis(80)).await; + + let prompt_name = world.scoped_id("bridge-prompt"); + world.stash.insert( + "bridge_prompt_name".into(), + Value::String(prompt_name.clone()), + ); + let _ = iii + .trigger(TriggerRequest { + function_id: "prompts::register".to_string(), + payload: json!({ + "name": prompt_name, + "description": "bdd bridge", + "function_id": handler_id, + "arguments": [ + { "name": "to", "description": "Recipient", "required": true } + ] + }), + action: None, + timeout_ms: Some(5_000), + }) + .await; +} + +// โ”€โ”€ resources-list โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when("I call skills::resources-list through the bridge")] +async fn bridge_resources_list(world: &mut IiiSkillsWorld) { + call(world, "skills::resources-list", json!({})).await; +} + +#[then("the bridged resources envelope has the iii://skills index")] +fn bridge_has_index(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let v = world.stash.get(LAST).expect("no response recorded"); + let arr = v["resources"].as_array().expect("missing .resources"); + assert!( + arr.iter() + .any(|r| r["uri"].as_str() == Some("iii://skills")), + "missing iii://skills: {arr:?}" + ); +} + +#[then("the bridged resources envelope includes the seeded skill uri")] +fn bridge_has_seeded(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let id = world + .stash + .get("bridge_skill_id") + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + let want = format!("iii://{id}"); + let v = world.stash.get(LAST).expect("no response recorded"); + let arr = v["resources"].as_array().expect("missing .resources"); + assert!( + arr.iter().any(|r| r["uri"].as_str() == Some(want.as_str())), + "missing {want:?}: {arr:?}" + ); +} + +// โ”€โ”€ resources-read โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when("I call skills::resources-read on the seeded skill uri")] +async fn bridge_resources_read(world: &mut IiiSkillsWorld) { + let id = world + .stash + .get("bridge_skill_id") + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + call( + world, + "skills::resources-read", + json!({ "uri": format!("iii://{id}") }), + ) + .await; +} + +#[then("the bridged read contents mime is text/markdown")] +fn bridge_read_mime_md(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let v = world.stash.get(LAST).expect("no response recorded"); + let mime = v["contents"][0]["mimeType"].as_str().unwrap_or(""); + assert_eq!(mime, "text/markdown", "{v}"); +} + +#[then("the bridged read contents text includes the skill body")] +fn bridge_read_text_has_body(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let v = world.stash.get(LAST).expect("no response recorded"); + let text = v["contents"][0]["text"].as_str().unwrap_or(""); + assert!(text.contains("body content"), "{text}"); +} + +// โ”€โ”€ prompts mcp-list โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when("I call prompts::mcp-list through the bridge")] +async fn bridge_mcp_list(world: &mut IiiSkillsWorld) { + call(world, "prompts::mcp-list", json!({})).await; +} + +#[then("the bridged prompts listing includes the seeded prompt with a required argument")] +fn bridge_prompts_listing(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let name = world + .stash + .get("bridge_prompt_name") + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + let v = world.stash.get(LAST).expect("no response recorded"); + let arr = v["prompts"].as_array().expect("missing .prompts"); + let entry = arr + .iter() + .find(|p| p["name"].as_str() == Some(name.as_str())) + .unwrap_or_else(|| panic!("missing prompt {name:?}: {arr:?}")); + let args = entry["arguments"].as_array().expect("missing arguments"); + assert_eq!(args.len(), 1, "args len: {entry}"); + assert_eq!(args[0]["name"].as_str(), Some("to")); + assert_eq!(args[0]["required"].as_bool(), Some(true)); +} + +// โ”€โ”€ prompts mcp-get โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when("I call prompts::mcp-get through the bridge with arguments to=alice@example.com")] +async fn bridge_mcp_get(world: &mut IiiSkillsWorld) { + let name = world + .stash + .get("bridge_prompt_name") + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + call( + world, + "prompts::mcp-get", + json!({ + "name": name, + "arguments": { "to": "alice@example.com" } + }), + ) + .await; +} + +#[then("the bridged prompts::mcp-get returns a single user message")] +fn bridge_mcp_get_shape(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let v = world.stash.get(LAST).expect("no response recorded"); + assert!( + v["description"].as_str().is_some(), + "missing description: {v}" + ); + let messages = v["messages"].as_array().expect("missing messages"); + assert_eq!(messages.len(), 1, "{v}"); + assert_eq!(messages[0]["role"].as_str(), Some("user")); +} diff --git a/skills/tests/steps/mod.rs b/skills/tests/steps/mod.rs new file mode 100644 index 00000000..f14e1698 --- /dev/null +++ b/skills/tests/steps/mod.rs @@ -0,0 +1,9 @@ +//! Step-definition modules. One per `.feature` under `tests/features/`. + +pub mod markdown; +pub mod mcp_bridge; +pub mod notifications; +pub mod prompts_get; +pub mod prompts_register; +pub mod skills_register; +pub mod skills_resources; diff --git a/skills/tests/steps/notifications.rs b/skills/tests/steps/notifications.rs new file mode 100644 index 00000000..5b27c820 --- /dev/null +++ b/skills/tests/steps/notifications.rs @@ -0,0 +1,234 @@ +//! Step defs for tests/features/notifications.feature. +//! +//! Each scenario registers a private "observer" function, subscribes it +//! to either `skills::on-change` or `prompts::on-change` via a trigger +//! instance, mutates the registry, and asserts the observer saw the +//! expected number of events within a bounded window. + +use std::sync::{Arc, Mutex, OnceLock}; + +use cucumber::{given, then, when}; +use iii_sdk::{IIIError, RegisterFunction, RegisterTriggerInput, TriggerRequest}; +use serde_json::{json, Value}; + +use crate::common::world::IiiSkillsWorld; + +const OBS_COUNT_SLOT: &str = "notifications_observed"; + +/// Shared counter that both the observer function (closure-captured) and +/// the assertion step read. We keep Arcs in a process-wide Vec +/// so the observer function's closure can increment the counter while +/// the Then step pulls the snapshot out by index. +struct Observer { + counter: Arc>, +} + +static OBSERVERS: OnceLock>>> = OnceLock::new(); + +fn observers() -> &'static Mutex>> { + OBSERVERS.get_or_init(|| Mutex::new(Vec::new())) +} + +fn new_observer(_world: &IiiSkillsWorld) -> Arc { + let o = Arc::new(Observer { + counter: Arc::new(Mutex::new(0)), + }); + observers().lock().unwrap().push(o.clone()); + o +} + +async fn register_observer( + world: &mut IiiSkillsWorld, + trigger_type: &str, + label: &str, +) -> Arc { + let obs = new_observer(world); + let Some(iii) = world.iii.clone() else { + return obs; + }; + let fn_id = format!("bdd::obs-{label}-{}", world.unique_id); + let counter = obs.counter.clone(); + iii.register_function( + RegisterFunction::new_async(fn_id.clone(), move |_input: Value| { + let counter = counter.clone(); + async move { + *counter.lock().unwrap() += 1; + Ok::<_, IIIError>(json!({})) + } + }) + .description("bdd: notifications observer"), + ); + // Give the engine a beat to publish the function registration so + // the trigger-type subscription has a valid target. + tokio::time::sleep(std::time::Duration::from_millis(80)).await; + + match iii.register_trigger(RegisterTriggerInput { + trigger_type: trigger_type.to_string(), + function_id: fn_id.clone(), + config: json!({}), + metadata: None, + }) { + Ok(_trigger) => { + // Leak the Trigger guard intentionally: we want the + // subscription to live until the binary exits. The + // `observer` handle on the world holds the counter. + } + Err(e) => { + eprintln!("failed to register {trigger_type} observer: {e}"); + } + } + // Let the trigger-type handler stash the subscription before we + // start mutating state. + tokio::time::sleep(std::time::Duration::from_millis(100)).await; + obs +} + +async fn wait_for_count(obs: &Observer, want: u64, timeout_ms: u64) -> u64 { + let deadline = std::time::Instant::now() + std::time::Duration::from_millis(timeout_ms); + loop { + let now = *obs.counter.lock().unwrap(); + if now >= want { + return now; + } + if std::time::Instant::now() >= deadline { + return now; + } + tokio::time::sleep(std::time::Duration::from_millis(50)).await; + } +} + +// โ”€โ”€ setup โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[given("a subscriber to skills::on-change is registered")] +async fn subscribe_skills(world: &mut IiiSkillsWorld) { + let obs = register_observer(world, "skills::on-change", "skills").await; + world + .stash + .insert(OBS_COUNT_SLOT.into(), Value::Number(0.into())); + let idx = observers().lock().unwrap().len() - 1; + world + .stash + .insert("notifications_obs_idx".into(), json!(idx)); + drop(obs); +} + +#[given("a subscriber to prompts::on-change is registered")] +async fn subscribe_prompts(world: &mut IiiSkillsWorld) { + let obs = register_observer(world, "prompts::on-change", "prompts").await; + world + .stash + .insert(OBS_COUNT_SLOT.into(), Value::Number(0.into())); + let idx = observers().lock().unwrap().len() - 1; + world + .stash + .insert("notifications_obs_idx".into(), json!(idx)); + drop(obs); +} + +// โ”€โ”€ mutation triggers โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +async fn trigger(world: &IiiSkillsWorld, function_id: &str, payload: Value) { + let Some(iii) = world.iii.clone() else { + return; + }; + let _ = iii + .trigger(TriggerRequest { + function_id: function_id.into(), + payload, + action: None, + timeout_ms: Some(5_000), + }) + .await; +} + +#[when("I register a scoped skill with a short body")] +async fn mut_register_skill(world: &mut IiiSkillsWorld) { + let id = world.scoped_id("nskill"); + world + .stash + .insert("notif_mut_id".into(), Value::String(id.clone())); + trigger( + world, + "skills::register", + json!({ "id": id, "skill": "# n\nok\n" }), + ) + .await; +} + +#[when("I unregister that skill")] +async fn mut_unregister_skill(world: &mut IiiSkillsWorld) { + let id = world + .stash + .get("notif_mut_id") + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + trigger(world, "skills::unregister", json!({ "id": id })).await; +} + +#[when(regex = r#"^I register (\d+) scoped skills in quick succession$"#)] +async fn mut_register_many(world: &mut IiiSkillsWorld, n: usize) { + for i in 0..n { + let id = world.scoped_id(&format!("burst-{i}")); + trigger( + world, + "skills::register", + json!({ "id": id, "skill": format!("# burst-{i}\n") }), + ) + .await; + } +} + +#[when("I register a scoped prompt")] +async fn mut_register_prompt(world: &mut IiiSkillsWorld) { + let name = world.scoped_id("nprompt"); + world + .stash + .insert("notif_mut_name".into(), Value::String(name.clone())); + trigger( + world, + "prompts::register", + json!({ + "name": name, + "description": "notifications probe", + "function_id": "bdd::dummy-handler", + }), + ) + .await; +} + +#[when("I unregister that prompt")] +async fn mut_unregister_prompt(world: &mut IiiSkillsWorld) { + let name = world + .stash + .get("notif_mut_name") + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + trigger(world, "prompts::unregister", json!({ "name": name })).await; +} + +// โ”€โ”€ assertions โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[then(regex = r#"^the subscriber observed at least (\d+) event within (\d+) ms$"#)] +async fn observed_at_least_single(world: &mut IiiSkillsWorld, want: u64, timeout_ms: u64) { + observed_at_least(world, want, timeout_ms).await; +} + +#[then(regex = r#"^the subscriber observed at least (\d+) events within (\d+) ms$"#)] +async fn observed_at_least(world: &mut IiiSkillsWorld, want: u64, timeout_ms: u64) { + if world.iii.is_none() { + return; + } + let idx = world + .stash + .get("notifications_obs_idx") + .and_then(|v| v.as_u64()) + .expect("no observer index recorded") as usize; + let obs = observers().lock().unwrap()[idx].clone(); + let got = wait_for_count(&obs, want, timeout_ms).await; + assert!( + got >= want, + "observed {got} events, wanted >= {want} within {timeout_ms}ms" + ); +} diff --git a/skills/tests/steps/prompts_get.rs b/skills/tests/steps/prompts_get.rs new file mode 100644 index 00000000..46ccaf49 --- /dev/null +++ b/skills/tests/steps/prompts_get.rs @@ -0,0 +1,227 @@ +//! Step defs for tests/features/prompts_get.feature. +//! +//! Drives `prompts::mcp-get` (the internal RPC mcp uses to answer MCP +//! `prompts/get`). Validates the three normalization shapes, not-found +//! errors, and the hard-floor guard against infra-namespace handlers. + +use cucumber::{given, then, when}; +use iii_sdk::{IIIError, RegisterFunction, TriggerRequest}; +use serde_json::{json, Value}; + +use crate::common::world::IiiSkillsWorld; + +const LAST_OK: &str = "prompts_get_last_ok"; +const LAST_ERR: &str = "prompts_get_last_err"; +const REGISTERED_NAME: &str = "prompts_get_registered_name"; + +async fn register_handler_returning>(world: &mut IiiSkillsWorld, kind: S) -> String { + let Some(iii) = world.iii.clone() else { + return String::new(); + }; + let kind = kind.as_ref().to_string(); + let fn_id = format!("bdd::prompt-handler-{kind}-{}", world.unique_id); + iii.register_function( + RegisterFunction::new_async(fn_id.clone(), move |_input: Value| { + let k = kind.clone(); + async move { + match k.as_str() { + "string" => Ok::<_, IIIError>(Value::String("str body".to_string())), + "content" => Ok::<_, IIIError>(json!({ "content": "obj body" })), + "messages" => Ok::<_, IIIError>(json!({ + "messages": [ + { "role": "user", "content": { "type": "text", "text": "m1" } }, + { "role": "assistant", "content": { "type": "text", "text": "m2" } } + ] + })), + "bogus" => Ok::<_, IIIError>(json!({ "x": 1 })), + _ => Err(IIIError::Handler(format!("unknown kind {k}"))), + } + } + }) + .description("bdd: prompt handler variant"), + ); + tokio::time::sleep(std::time::Duration::from_millis(60)).await; + fn_id +} + +async fn register_prompt_pointing_at(world: &mut IiiSkillsWorld, function_id: &str) -> String { + let Some(iii) = world.iii.clone() else { + return String::new(); + }; + let name = world.scoped_id("pget"); + let _ = iii + .trigger(TriggerRequest { + function_id: "prompts::register".to_string(), + payload: json!({ + "name": name, + "description": "bdd prompt", + "function_id": function_id, + }), + action: None, + timeout_ms: Some(5_000), + }) + .await; + world + .stash + .insert(REGISTERED_NAME.into(), Value::String(name.clone())); + name +} + +async fn call_mcp_get(world: &mut IiiSkillsWorld, payload: Value) { + world.stash.remove(LAST_OK); + world.stash.remove(LAST_ERR); + let Some(iii) = world.iii.clone() else { + return; + }; + match iii + .trigger(TriggerRequest { + function_id: "prompts::mcp-get".to_string(), + payload, + action: None, + timeout_ms: Some(5_000), + }) + .await + { + Ok(v) => { + world.stash.insert(LAST_OK.into(), v); + } + Err(e) => { + world + .stash + .insert(LAST_ERR.into(), Value::String(e.to_string())); + } + } +} + +// โ”€โ”€ seed handlers โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[given("a prompt handler that returns a string")] +async fn seed_string(world: &mut IiiSkillsWorld) { + let fn_id = register_handler_returning(world, "string").await; + let _ = register_prompt_pointing_at(world, &fn_id).await; +} + +#[given("a prompt handler that returns a {content} object")] +async fn seed_content(world: &mut IiiSkillsWorld) { + let fn_id = register_handler_returning(world, "content").await; + let _ = register_prompt_pointing_at(world, &fn_id).await; +} + +#[given("a prompt handler that returns a {messages: [...]} object")] +async fn seed_messages(world: &mut IiiSkillsWorld) { + let fn_id = register_handler_returning(world, "messages").await; + let _ = register_prompt_pointing_at(world, &fn_id).await; +} + +#[given("a prompt handler that returns an unsupported shape")] +async fn seed_bogus(world: &mut IiiSkillsWorld) { + let fn_id = register_handler_returning(world, "bogus").await; + let _ = register_prompt_pointing_at(world, &fn_id).await; +} + +#[given(regex = r#"^a prompt pointing at the infra function "([^"]+)"$"#)] +async fn seed_prompt_infra(world: &mut IiiSkillsWorld, function_id: String) { + let _ = register_prompt_pointing_at(world, &function_id).await; +} + +// โ”€โ”€ actions โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when("I call prompts::mcp-get on the scoped prompt")] +async fn get_scoped(world: &mut IiiSkillsWorld) { + let Some(name_value) = world.stash.get(REGISTERED_NAME).cloned() else { + return; + }; + let name = name_value.as_str().unwrap_or("").to_string(); + call_mcp_get(world, json!({ "name": name, "arguments": {} })).await; +} + +#[when(regex = r#"^I call prompts::mcp-get with an unknown name "([^"]*)"$"#)] +async fn get_unknown(world: &mut IiiSkillsWorld, name: String) { + call_mcp_get(world, json!({ "name": name })).await; +} + +// โ”€โ”€ assertions โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[then("the mcp-get call succeeds")] +fn get_ok(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + assert!( + world.stash.contains_key(LAST_OK), + "expected success; got error: {:?}", + world.stash.get(LAST_ERR) + ); +} + +#[then("the mcp-get call fails")] +fn get_fails(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + assert!( + world.stash.contains_key(LAST_ERR), + "expected failure; got success: {:?}", + world.stash.get(LAST_OK) + ); +} + +#[then(regex = r#"^the mcp-get error mentions "([^"]+)"$"#)] +fn get_error_mentions(world: &mut IiiSkillsWorld, needle: String) { + if world.iii.is_none() { + return; + } + let err = world + .stash + .get(LAST_ERR) + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + assert!(err.contains(&needle), "error missing {needle:?}: {err:?}"); +} + +#[then(regex = r#"^the messages array has length (\d+)$"#)] +fn messages_len(world: &mut IiiSkillsWorld, want: usize) { + if world.iii.is_none() { + return; + } + let v = world.stash.get(LAST_OK).expect("no success recorded"); + let arr = v["messages"].as_array().expect("missing .messages"); + assert_eq!(arr.len(), want, "messages len mismatch: {v}"); +} + +#[then(regex = r#"^message (\d+) has role "([^"]+)" and text "([^"]+)"$"#)] +fn message_shape(world: &mut IiiSkillsWorld, idx: usize, role: String, text: String) { + if world.iii.is_none() { + return; + } + let v = world.stash.get(LAST_OK).expect("no success recorded"); + let arr = v["messages"].as_array().expect("missing .messages"); + let msg = arr + .get(idx) + .unwrap_or_else(|| panic!("no message {idx}: {arr:?}")); + assert_eq!( + msg["role"].as_str().unwrap_or(""), + role, + "role at {idx}: {msg}" + ); + assert_eq!( + msg["content"]["type"].as_str().unwrap_or(""), + "text", + "content.type at {idx}: {msg}" + ); + assert_eq!( + msg["content"]["text"].as_str().unwrap_or(""), + text, + "content.text at {idx}: {msg}" + ); +} + +#[then(regex = r#"^the result description is "([^"]+)"$"#)] +fn result_description(world: &mut IiiSkillsWorld, want: String) { + if world.iii.is_none() { + return; + } + let v = world.stash.get(LAST_OK).expect("no success recorded"); + assert_eq!(v["description"].as_str().unwrap_or(""), want, "{v}"); +} diff --git a/skills/tests/steps/prompts_register.rs b/skills/tests/steps/prompts_register.rs new file mode 100644 index 00000000..7f7a2410 --- /dev/null +++ b/skills/tests/steps/prompts_register.rs @@ -0,0 +1,370 @@ +//! Step defs for tests/features/prompts_register.feature. +//! +//! Drives `prompts::register`, `prompts::unregister`, and `prompts::list` +//! through the iii bus, covering validation (name, description, +//! function_id, duplicate/empty arguments), round-trip, idempotency. + +use cucumber::{given, then, when}; +use iii_sdk::TriggerRequest; +use serde_json::{json, Value}; + +use crate::common::world::IiiSkillsWorld; + +const LAST_OK: &str = "prompts_register_last_ok"; +const LAST_ERR: &str = "prompts_register_last_err"; +const LAST_LIST: &str = "prompts_register_last_list"; +const REGISTERED_NAME: &str = "prompts_register_registered_name"; +const REGISTERED_AT_FIRST: &str = "prompts_register_registered_at_first"; +const UNREG_LAST: &str = "prompts_register_unreg_last"; + +async fn call_register(world: &mut IiiSkillsWorld, payload: Value) { + world.stash.remove(LAST_OK); + world.stash.remove(LAST_ERR); + let Some(iii) = world.iii.clone() else { + return; + }; + match iii + .trigger(TriggerRequest { + function_id: "prompts::register".to_string(), + payload, + action: None, + timeout_ms: Some(5_000), + }) + .await + { + Ok(v) => { + world.stash.insert(LAST_OK.into(), v); + } + Err(e) => { + world + .stash + .insert(LAST_ERR.into(), Value::String(e.to_string())); + } + } +} + +async fn call_list(world: &mut IiiSkillsWorld) { + world.stash.remove(LAST_LIST); + let Some(iii) = world.iii.clone() else { + return; + }; + if let Ok(v) = iii + .trigger(TriggerRequest { + function_id: "prompts::list".to_string(), + payload: json!({}), + action: None, + timeout_ms: Some(5_000), + }) + .await + { + world.stash.insert(LAST_LIST.into(), v); + } +} + +// โ”€โ”€ validation โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when( + regex = r#"^I register a prompt with name "([^"]*)", description "([^"]*)", function_id "([^"]*)"$"# +)] +async fn register_simple( + world: &mut IiiSkillsWorld, + name: String, + description: String, + function_id: String, +) { + call_register( + world, + json!({ + "name": name, + "description": description, + "function_id": function_id, + }), + ) + .await; +} + +#[when("I register a prompt with duplicate argument names")] +async fn register_dup_args(world: &mut IiiSkillsWorld) { + call_register( + world, + json!({ + "name": "dup", + "description": "dup args", + "function_id": "test::handler", + "arguments": [ + { "name": "to", "required": true }, + { "name": "to", "required": false } + ] + }), + ) + .await; +} + +#[when("I register a prompt with an empty argument name")] +async fn register_empty_arg(world: &mut IiiSkillsWorld) { + call_register( + world, + json!({ + "name": "dup", + "description": "empty arg", + "function_id": "test::handler", + "arguments": [ + { "name": "", "required": true } + ] + }), + ) + .await; +} + +#[then("the prompts::register call fails")] +fn register_fails(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + assert!( + world.stash.contains_key(LAST_ERR), + "expected prompts::register to fail; got success: {:?}", + world.stash.get(LAST_OK) + ); +} + +#[then(regex = r#"^the prompts::register error mentions "([^"]+)"$"#)] +fn register_error_mentions(world: &mut IiiSkillsWorld, needle: String) { + if world.iii.is_none() { + return; + } + let err = world + .stash + .get(LAST_ERR) + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + assert!( + err.contains(&needle), + "expected error to mention {needle:?}; got {err:?}" + ); +} + +#[then("the prompts::register call succeeds")] +fn register_succeeds(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + assert!( + world.stash.contains_key(LAST_OK), + "expected prompts::register to succeed; got error: {:?}", + world.stash.get(LAST_ERR) + ); +} + +// โ”€โ”€ round-trip scenarios โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when(regex = r#"^I register a scoped prompt "([^"]*)" pointing at "([^"]*)"$"#)] +async fn register_scoped(world: &mut IiiSkillsWorld, base: String, function_id: String) { + let name = world.scoped_id(&base); + world + .stash + .insert(REGISTERED_NAME.into(), Value::String(name.clone())); + call_register( + world, + json!({ + "name": name, + "description": format!("scoped prompt {base}"), + "function_id": function_id, + "arguments": [ + { "name": "to", "description": "Recipient", "required": true } + ] + }), + ) + .await; +} + +#[when("I record the registered_at timestamp for the prompt")] +fn record_registered_at(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let v = world.stash.get(LAST_OK).cloned().expect("LAST_OK not set"); + let ts = v["registered_at"].as_str().unwrap_or("").to_string(); + world + .stash + .insert(REGISTERED_AT_FIRST.into(), Value::String(ts)); +} + +#[when(regex = r#"^I re-register the scoped prompt with description "([^"]*)"$"#)] +async fn reregister_scoped(world: &mut IiiSkillsWorld, description: String) { + let Some(name_value) = world.stash.get(REGISTERED_NAME).cloned() else { + return; + }; + let name = name_value.as_str().unwrap_or("").to_string(); + tokio::time::sleep(std::time::Duration::from_millis(20)).await; + call_register( + world, + json!({ + "name": name, + "description": description, + "function_id": "test::handler", + }), + ) + .await; +} + +#[then("the re-registered prompt timestamp is different from the first")] +fn prompt_timestamps_differ(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let first = world + .stash + .get(REGISTERED_AT_FIRST) + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + let latest = world + .stash + .get(LAST_OK) + .and_then(|v| v["registered_at"].as_str().map(String::from)) + .unwrap_or_default(); + assert!(!first.is_empty() && !latest.is_empty()); + assert_ne!(first, latest); +} + +// โ”€โ”€ unregister โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when("I unregister the scoped prompt")] +async fn unregister_scoped(world: &mut IiiSkillsWorld) { + let Some(iii) = world.iii.clone() else { + return; + }; + let Some(name_value) = world.stash.get(REGISTERED_NAME).cloned() else { + return; + }; + let name = name_value.as_str().unwrap_or("").to_string(); + if let Ok(v) = iii + .trigger(TriggerRequest { + function_id: "prompts::unregister".to_string(), + payload: json!({ "name": name }), + action: None, + timeout_ms: Some(5_000), + }) + .await + { + world.stash.insert(UNREG_LAST.into(), v); + } +} + +#[when("I unregister the scoped prompt again")] +async fn unregister_scoped_twice(world: &mut IiiSkillsWorld) { + unregister_scoped(world).await +} + +#[then(regex = r#"^the last prompt unregister returned removed=(true|false)$"#)] +fn prompt_unregister_removed(world: &mut IiiSkillsWorld, expected: String) { + if world.iii.is_none() { + return; + } + let v = world + .stash + .get(UNREG_LAST) + .expect("no prompt unregister result recorded"); + let got = v["removed"].as_bool().unwrap_or(false); + let want = expected == "true"; + assert_eq!(got, want, "removed flag mismatch: {v:?}"); +} + +// โ”€โ”€ list โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when("I list prompts")] +async fn list_prompts(world: &mut IiiSkillsWorld) { + call_list(world).await; +} + +#[then("the scoped prompt appears in the listing")] +fn scoped_prompt_in_listing(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let name = world + .stash + .get(REGISTERED_NAME) + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + let list = world.stash.get(LAST_LIST).expect("no list recorded"); + let arr = list["prompts"].as_array().expect("missing .prompts array"); + let found = arr + .iter() + .any(|e| e["name"].as_str() == Some(name.as_str())); + assert!(found, "scoped prompt {name:?} not in listing: {arr:?}"); +} + +#[then("the scoped prompt does not appear in the listing")] +fn scoped_prompt_not_in_listing(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let name = world + .stash + .get(REGISTERED_NAME) + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + let list = world.stash.get(LAST_LIST).expect("no list recorded"); + let arr = list["prompts"].as_array().expect("missing .prompts array"); + let found = arr + .iter() + .any(|e| e["name"].as_str() == Some(name.as_str())); + assert!(!found, "scoped prompt {name:?} still in listing: {arr:?}"); +} + +#[then("the prompt listing is sorted by name")] +fn prompt_listing_sorted(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let list = world.stash.get(LAST_LIST).expect("no list recorded"); + let arr = list["prompts"].as_array().expect("missing .prompts array"); + let names: Vec<&str> = arr.iter().filter_map(|e| e["name"].as_str()).collect(); + let mut sorted = names.clone(); + sorted.sort(); + assert_eq!(names, sorted, "prompts not sorted by name: {names:?}"); +} + +#[then("each prompt listing entry carries arguments count, function_id, and registered_at")] +fn prompt_list_metadata_shape(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let list = world.stash.get(LAST_LIST).expect("no list recorded"); + let arr = list["prompts"].as_array().expect("missing .prompts array"); + for entry in arr { + assert!( + entry["arguments"].as_u64().is_some(), + "missing arguments count: {entry}" + ); + assert!( + entry["function_id"].as_str().is_some(), + "missing function_id: {entry}" + ); + assert!( + entry["registered_at"].as_str().is_some(), + "missing registered_at: {entry}" + ); + } +} + +// โ”€โ”€ seed helper โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[given(regex = r#"^a prompt "([^"]+)" is already registered pointing at "([^"]+)"$"#)] +async fn seed_prompt(world: &mut IiiSkillsWorld, name_base: String, function_id: String) { + let name = world.scoped_id(&name_base); + call_register( + world, + json!({ + "name": name, + "description": format!("seeded {name_base}"), + "function_id": function_id, + }), + ) + .await; +} diff --git a/skills/tests/steps/skills_register.rs b/skills/tests/steps/skills_register.rs new file mode 100644 index 00000000..51ed29da --- /dev/null +++ b/skills/tests/steps/skills_register.rs @@ -0,0 +1,310 @@ +//! Step defs for tests/features/skills_register.feature. +//! +//! Drives the `skills::register`, `skills::unregister`, and `skills::list` +//! surface through `iii.trigger(...)` so the BDD scenarios exercise the +//! full in-process handler path โ€” including validation, state writes, +//! and the `skills::on-change` fan-out. + +use cucumber::{given, then, when}; +use iii_sdk::TriggerRequest; +use serde_json::{json, Value}; + +use crate::common::world::IiiSkillsWorld; + +const LAST_ERR: &str = "skills_register_last_err"; +const LAST_OK: &str = "skills_register_last_ok"; +const LAST_LIST: &str = "skills_register_last_list"; +const REGISTERED_ID: &str = "skills_register_registered_id"; +const REGISTERED_AT_FIRST: &str = "skills_register_registered_at_first"; + +#[given("the iii engine is reachable")] +async fn engine_reachable(_world: &mut IiiSkillsWorld) {} + +async fn call_register(world: &mut IiiSkillsWorld, payload: Value) { + world.stash.remove(LAST_OK); + world.stash.remove(LAST_ERR); + let Some(iii) = world.iii.clone() else { + return; + }; + match iii + .trigger(TriggerRequest { + function_id: "skills::register".to_string(), + payload, + action: None, + timeout_ms: Some(5_000), + }) + .await + { + Ok(v) => { + world.stash.insert(LAST_OK.into(), v); + } + Err(e) => { + world + .stash + .insert(LAST_ERR.into(), Value::String(e.to_string())); + } + } +} + +async fn call_unregister(world: &mut IiiSkillsWorld, id: &str) -> Option { + let iii = world.iii.clone()?; + iii.trigger(TriggerRequest { + function_id: "skills::unregister".to_string(), + payload: json!({ "id": id }), + action: None, + timeout_ms: Some(5_000), + }) + .await + .ok() +} + +async fn call_list(world: &mut IiiSkillsWorld) { + world.stash.remove(LAST_LIST); + let Some(iii) = world.iii.clone() else { + return; + }; + if let Ok(v) = iii + .trigger(TriggerRequest { + function_id: "skills::list".to_string(), + payload: json!({}), + action: None, + timeout_ms: Some(5_000), + }) + .await + { + world.stash.insert(LAST_LIST.into(), v); + } +} + +// โ”€โ”€ register validation โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when(regex = r#"^I register a skill with id "([^"]*)" and body "([^"]*)"$"#)] +async fn register_simple(world: &mut IiiSkillsWorld, id: String, body: String) { + call_register(world, json!({ "id": id, "skill": body })).await; +} + +#[when(regex = r#"^I register a skill with id "([^"]*)" and a body of (\d+) bytes$"#)] +async fn register_sized(world: &mut IiiSkillsWorld, id: String, bytes: usize) { + let body = "x".repeat(bytes); + call_register(world, json!({ "id": id, "skill": body })).await; +} + +#[when(regex = r#"^I register a skill with id "([^"]*)" and an empty body$"#)] +async fn register_empty_body(world: &mut IiiSkillsWorld, id: String) { + call_register(world, json!({ "id": id, "skill": "" })).await; +} + +#[then("the skills::register call fails")] +fn register_fails(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + assert!( + world.stash.contains_key(LAST_ERR), + "expected skills::register to fail; got success: {:?}", + world.stash.get(LAST_OK) + ); +} + +#[then(regex = r#"^the skills::register error mentions "([^"]+)"$"#)] +fn register_error_mentions(world: &mut IiiSkillsWorld, needle: String) { + if world.iii.is_none() { + return; + } + let err = world + .stash + .get(LAST_ERR) + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + assert!( + err.contains(&needle), + "expected skills::register error to mention {needle:?}; got {err:?}" + ); +} + +#[then("the skills::register call succeeds")] +fn register_succeeds(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + assert!( + world.stash.contains_key(LAST_OK), + "expected skills::register to succeed; got error: {:?}", + world.stash.get(LAST_ERR) + ); +} + +// โ”€โ”€ round-trip scenarios โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when(regex = r#"^I register a scoped skill "([^"]*)" with body "([^"]*)"$"#)] +async fn register_scoped(world: &mut IiiSkillsWorld, base: String, body: String) { + let id = world.scoped_id(&base); + world + .stash + .insert(REGISTERED_ID.into(), Value::String(id.clone())); + call_register(world, json!({ "id": id, "skill": body })).await; +} + +#[when("I record the registered_at timestamp")] +fn record_registered_at(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let v = world + .stash + .get(LAST_OK) + .cloned() + .expect("a previous When step should have set LAST_OK"); + let ts = v["registered_at"].as_str().unwrap_or("").to_string(); + world + .stash + .insert(REGISTERED_AT_FIRST.into(), Value::String(ts)); +} + +#[when(regex = r#"^I re-register the scoped skill with body "([^"]*)"$"#)] +async fn reregister_scoped(world: &mut IiiSkillsWorld, body: String) { + let Some(id_value) = world.stash.get(REGISTERED_ID).cloned() else { + return; + }; + let id = id_value.as_str().unwrap_or("").to_string(); + // Ensure the `registered_at` timestamp actually differs on re-register. + tokio::time::sleep(std::time::Duration::from_millis(20)).await; + call_register(world, json!({ "id": id, "skill": body })).await; +} + +#[then("the re-registered timestamp is different from the first")] +fn timestamps_differ(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let first = world + .stash + .get(REGISTERED_AT_FIRST) + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + let latest = world + .stash + .get(LAST_OK) + .and_then(|v| v["registered_at"].as_str().map(String::from)) + .unwrap_or_default(); + assert!(!first.is_empty(), "no recorded first timestamp"); + assert!(!latest.is_empty(), "no latest timestamp"); + assert_ne!(first, latest, "timestamps should differ on re-register"); +} + +// โ”€โ”€ unregister โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when("I unregister the scoped skill")] +async fn unregister_scoped(world: &mut IiiSkillsWorld) { + let Some(id_value) = world.stash.get(REGISTERED_ID).cloned() else { + return; + }; + let id = id_value.as_str().unwrap_or("").to_string(); + if let Some(v) = call_unregister(world, &id).await { + world.stash.insert("skills_unreg_last".into(), v); + } +} + +#[when("I unregister the scoped skill again")] +async fn unregister_scoped_twice(world: &mut IiiSkillsWorld) { + unregister_scoped(world).await +} + +#[then(regex = r#"^the last unregister returned removed=(true|false)$"#)] +fn unregister_removed_flag(world: &mut IiiSkillsWorld, expected: String) { + if world.iii.is_none() { + return; + } + let v = world + .stash + .get("skills_unreg_last") + .expect("no unregister result recorded"); + let got = v["removed"].as_bool().unwrap_or(false); + let want = expected == "true"; + assert_eq!(got, want, "removed flag mismatch: {:?}", v); +} + +// โ”€โ”€ list โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when("I list skills")] +async fn list_skills(world: &mut IiiSkillsWorld) { + call_list(world).await; +} + +#[then("the scoped skill appears in the listing")] +fn scoped_in_listing(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let id = world + .stash + .get(REGISTERED_ID) + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + let list = world.stash.get(LAST_LIST).expect("no list recorded"); + let arr = list["skills"].as_array().expect("missing .skills array"); + let found = arr.iter().any(|e| e["id"].as_str() == Some(id.as_str())); + assert!(found, "scoped skill {id:?} not in listing: {arr:?}"); +} + +#[then("the scoped skill does not appear in the listing")] +fn scoped_not_in_listing(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let id = world + .stash + .get(REGISTERED_ID) + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + let list = world.stash.get(LAST_LIST).expect("no list recorded"); + let arr = list["skills"].as_array().expect("missing .skills array"); + let found = arr.iter().any(|e| e["id"].as_str() == Some(id.as_str())); + assert!(!found, "scoped skill {id:?} still in listing: {arr:?}"); +} + +#[then("the listing entries carry bytes and registered_at but no skill body")] +fn list_metadata_shape(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let list = world.stash.get(LAST_LIST).expect("no list recorded"); + let arr = list["skills"].as_array().expect("missing .skills array"); + for entry in arr { + assert!(entry["bytes"].as_u64().is_some(), "missing bytes: {entry}"); + assert!( + entry["registered_at"].as_str().is_some(), + "missing registered_at: {entry}" + ); + assert!( + entry.get("skill").is_none(), + "list must not echo bodies: {entry}" + ); + } +} + +#[then("the listing is sorted by id")] +fn listing_sorted(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let list = world.stash.get(LAST_LIST).expect("no list recorded"); + let arr = list["skills"].as_array().expect("missing .skills array"); + let ids: Vec<&str> = arr.iter().filter_map(|e| e["id"].as_str()).collect(); + let mut sorted = ids.clone(); + sorted.sort(); + assert_eq!(ids, sorted, "listing not sorted by id: {ids:?}"); +} + +// โ”€โ”€ seed helpers used by ordering tests โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[given(regex = r#"^a skill "([^"]+)" is already registered$"#)] +async fn seed_skill(world: &mut IiiSkillsWorld, id_base: String) { + let id = world.scoped_id(&id_base); + let body = format!("# {id}\nbody\n"); + call_register(world, json!({ "id": id, "skill": body })).await; +} diff --git a/skills/tests/steps/skills_resources.rs b/skills/tests/steps/skills_resources.rs new file mode 100644 index 00000000..51407a5e --- /dev/null +++ b/skills/tests/steps/skills_resources.rs @@ -0,0 +1,314 @@ +//! Step defs for tests/features/skills_resources.feature. +//! +//! Exercises the `iii://` resource resolver via `skills::resources-*`: +//! the three URI shapes, output normalization, recursion guard. + +use cucumber::{given, then, when}; +use iii_sdk::{IIIError, RegisterFunction, TriggerRequest}; +use serde_json::{json, Value}; + +use crate::common::world::IiiSkillsWorld; + +const LAST_READ: &str = "skills_resources_last_read"; +const LAST_ERR: &str = "skills_resources_last_err"; +const LAST_LIST: &str = "skills_resources_last_list"; +const LAST_TEMPLATES: &str = "skills_resources_last_templates"; +const SECTION_FN: &str = "skills_resources_section_fn"; + +async fn trigger_json(world: &mut IiiSkillsWorld, function_id: &str, payload: Value, slot: &str) { + world.stash.remove(slot); + world.stash.remove(LAST_ERR); + let Some(iii) = world.iii.clone() else { + return; + }; + match iii + .trigger(TriggerRequest { + function_id: function_id.to_string(), + payload, + action: None, + timeout_ms: Some(5_000), + }) + .await + { + Ok(v) => { + world.stash.insert(slot.into(), v); + } + Err(e) => { + world + .stash + .insert(LAST_ERR.into(), Value::String(e.to_string())); + } + } +} + +// โ”€โ”€ seeding โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[given(regex = r#"^a skill with id "([^"]+)" and body:$"#)] +async fn seed_skill_block( + world: &mut IiiSkillsWorld, + id_base: String, + step: &cucumber::gherkin::Step, +) { + let id = world.scoped_id(&id_base); + let body = step + .docstring + .clone() + .expect("skill body requires a docstring"); + world + .stash + .insert("resources_seed_id".into(), Value::String(id.clone())); + trigger_json( + world, + "skills::register", + json!({ "id": id, "skill": body }), + "resources_seed_ok", + ) + .await; +} + +#[given("a sub-skill function that returns a markdown string")] +async fn seed_section_string(world: &mut IiiSkillsWorld) { + let Some(iii) = world.iii.clone() else { + return; + }; + let fn_id = format!("bdd::section-str-{}", world.unique_id); + world + .stash + .insert(SECTION_FN.into(), Value::String(fn_id.clone())); + iii.register_function( + RegisterFunction::new_async(fn_id.clone(), |_input: Value| async move { + Ok::<_, IIIError>(Value::String("# str-section\nplain text".into())) + }) + .description("bdd: returns a markdown string directly"), + ); + tokio::time::sleep(std::time::Duration::from_millis(60)).await; +} + +#[given("a sub-skill function that returns a {content} object")] +async fn seed_section_content(world: &mut IiiSkillsWorld) { + let Some(iii) = world.iii.clone() else { + return; + }; + let fn_id = format!("bdd::section-content-{}", world.unique_id); + world + .stash + .insert(SECTION_FN.into(), Value::String(fn_id.clone())); + iii.register_function( + RegisterFunction::new_async(fn_id.clone(), |_input: Value| async move { + Ok::<_, IIIError>(json!({ "content": "# object-section\nwrapped" })) + }) + .description("bdd: returns a {content} object"), + ); + tokio::time::sleep(std::time::Duration::from_millis(60)).await; +} + +#[given("a sub-skill function that returns an arbitrary JSON object")] +async fn seed_section_json(world: &mut IiiSkillsWorld) { + let Some(iii) = world.iii.clone() else { + return; + }; + let fn_id = format!("bdd::section-json-{}", world.unique_id); + world + .stash + .insert(SECTION_FN.into(), Value::String(fn_id.clone())); + iii.register_function( + RegisterFunction::new_async(fn_id.clone(), |_input: Value| async move { + Ok::<_, IIIError>(json!({ "count": 42, "label": "json" })) + }) + .description("bdd: returns arbitrary JSON"), + ); + tokio::time::sleep(std::time::Duration::from_millis(60)).await; +} + +// โ”€โ”€ resources-list / templates โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when("I call skills::resources-list")] +async fn call_resources_list(world: &mut IiiSkillsWorld) { + trigger_json(world, "skills::resources-list", json!({}), LAST_LIST).await; +} + +#[then("the resource list includes iii://skills")] +fn list_includes_index(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let v = world.stash.get(LAST_LIST).expect("no list recorded"); + let arr = v["resources"].as_array().expect("missing .resources"); + assert!( + arr.iter() + .any(|r| r["uri"].as_str() == Some("iii://skills")), + "missing iii://skills index: {arr:?}" + ); +} + +#[then("the resource list includes the seeded skill URI")] +fn list_includes_seeded(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let id = world + .stash + .get("resources_seed_id") + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + let want = format!("iii://{id}"); + let v = world.stash.get(LAST_LIST).expect("no list recorded"); + let arr = v["resources"].as_array().expect("missing .resources"); + assert!( + arr.iter().any(|r| r["uri"].as_str() == Some(want.as_str())), + "missing {want:?}: {arr:?}" + ); +} + +#[when("I call skills::resources-templates")] +async fn call_resources_templates(world: &mut IiiSkillsWorld) { + trigger_json( + world, + "skills::resources-templates", + json!({}), + LAST_TEMPLATES, + ) + .await; +} + +#[then("the templates listing contains the skill and skill-section templates")] +fn templates_two_entries(world: &mut IiiSkillsWorld) { + if world.iii.is_none() { + return; + } + let v = world + .stash + .get(LAST_TEMPLATES) + .expect("no templates recorded"); + let arr = v["resourceTemplates"] + .as_array() + .expect("missing .resourceTemplates"); + assert_eq!(arr.len(), 2, "expected 2 templates, got {arr:?}"); + let patterns: Vec<&str> = arr + .iter() + .filter_map(|t| t["uriTemplate"].as_str()) + .collect(); + assert!( + patterns.contains(&"iii://{skill_id}"), + "patterns: {patterns:?}" + ); + assert!( + patterns.contains(&"iii://{skill_id}/{function_id}"), + "patterns: {patterns:?}" + ); +} + +// โ”€โ”€ resources-read โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[when("I read iii://skills")] +async fn read_index(world: &mut IiiSkillsWorld) { + trigger_json( + world, + "skills::resources-read", + json!({ "uri": "iii://skills" }), + LAST_READ, + ) + .await; +} + +#[when("I read the seeded skill URI")] +async fn read_seeded(world: &mut IiiSkillsWorld) { + let id = world + .stash + .get("resources_seed_id") + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + let uri = format!("iii://{id}"); + trigger_json( + world, + "skills::resources-read", + json!({ "uri": uri }), + LAST_READ, + ) + .await; +} + +#[when(regex = r#"^I read the section URI with skill id "([^"]*)"$"#)] +async fn read_section(world: &mut IiiSkillsWorld, skill_id_base: String) { + let skill_id = if skill_id_base.is_empty() { + "anything".to_string() + } else { + world.scoped_id(&skill_id_base) + }; + let fn_id = world + .stash + .get(SECTION_FN) + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + let uri = format!("iii://{skill_id}/{fn_id}"); + trigger_json( + world, + "skills::resources-read", + json!({ "uri": uri }), + LAST_READ, + ) + .await; +} + +#[when(regex = r#"^I read the URI "([^"]+)"$"#)] +async fn read_raw(world: &mut IiiSkillsWorld, uri: String) { + trigger_json( + world, + "skills::resources-read", + json!({ "uri": uri }), + LAST_READ, + ) + .await; +} + +// โ”€โ”€ assertions on the last read โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + +#[then(regex = r#"^the contents mime type is "([^"]+)"$"#)] +fn read_mime(world: &mut IiiSkillsWorld, want: String) { + if world.iii.is_none() { + return; + } + let v = world.stash.get(LAST_READ).expect("no read recorded"); + let mime = v["contents"][0]["mimeType"].as_str().unwrap_or(""); + assert_eq!(mime, want, "mime mismatch in: {v}"); +} + +#[then(regex = r#"^the contents text contains "([^"]+)"$"#)] +fn read_contains(world: &mut IiiSkillsWorld, needle: String) { + if world.iii.is_none() { + return; + } + let v = world.stash.get(LAST_READ).expect("no read recorded"); + let text = v["contents"][0]["text"].as_str().unwrap_or(""); + assert!(text.contains(&needle), "missing {needle:?}: {text}"); +} + +#[then(regex = r#"^the contents text does not contain "([^"]+)"$"#)] +fn read_not_contains(world: &mut IiiSkillsWorld, needle: String) { + if world.iii.is_none() { + return; + } + let v = world.stash.get(LAST_READ).expect("no read recorded"); + let text = v["contents"][0]["text"].as_str().unwrap_or(""); + assert!(!text.contains(&needle), "unexpected {needle:?} in: {text}"); +} + +#[then(regex = r#"^the read fails with a message mentioning "([^"]+)"$"#)] +fn read_error_mentions(world: &mut IiiSkillsWorld, needle: String) { + if world.iii.is_none() { + return; + } + let err = world + .stash + .get(LAST_ERR) + .and_then(|v| v.as_str()) + .unwrap_or("") + .to_string(); + assert!( + err.contains(&needle), + "expected error to mention {needle:?}; got {err:?}" + ); +} diff --git a/worker-readme.md b/worker-readme.md new file mode 100644 index 00000000..4a0090fa --- /dev/null +++ b/worker-readme.md @@ -0,0 +1,307 @@ +# Worker README guide + +How to write the `README.md` for a worker in this repo. + +A worker's README is consumer-facing: it lands as the `readme` field on +`POST /publish`, it is what someone reads after `iii worker info `, +and it is the page on the registry. Treat it as a **how-to**, not a +reference. The reference lives in the code โ€” rustdoc, source links, +`iii worker info`, IDE autocomplete on function ids. + +## What the README answers + +In order, four questions: + +1. **What does this worker do?** One paragraph. +2. **How do I install it?** One command. +3. **How do I run it?** One command. +4. **How do I make my first useful call?** A short, runnable example. + +Anything else is a follow-up section. The README is **not**: + +- A function reference. Use rustdoc / `iii worker info` / source links. +- A request/response schema dump. Same. +- A deep architecture document. That belongs in a sibling design doc + (`/project-*.md` or similar). +- A build-from-source recipe for end users. Source builds belong in the + optional `## Local development & testing` section. + +## Required structure + +Every worker README has these sections, in this order: + +1. Title + one-paragraph summary +2. `## Install` +3. `## Run` +4. `## Quickstart` (or a more specific name like `## Build a worker that โ€ฆ`) +5. `## Configuration` + +Optional, only when relevant: + +- `## Custom trigger types` โ€” if your worker emits subscribable trigger + types for sibling workers. +- `## Migration notes` โ€” for renamed function ids or breaking payload + changes in a recent release. +- `## Local development & testing` โ€” `cargo run`, `cargo test`, BDD + tags, end-to-end smoke instructions for contributors. + +For longer READMEs (>~200 lines), add a `## Table of contents` after +the summary. Short ones don't need one. + +## Section: title + summary + +```markdown +# + +One paragraph. What this worker does in plain English, who calls it, +and the single most important thing it gives you. +``` + +Lead with the user-facing value, not the implementation. If your worker +ships with a sibling that most users will install too (e.g. +[`skills`](skills) โ†’ [`mcp`](mcp)), name and link to the +sibling in the same paragraph. + +## Section: Install + +Always exactly one command: + +````markdown +```bash +iii worker add +``` +```` + +Where `` is the value of `iii.worker.yaml.name` (which equals the +folder name; see [`AGENTS-NEW-WORKER.md`](AGENTS-NEW-WORKER.md) ยง1). +That is the whole user-facing install โ€” no source build, no +`sudo install`, no `--manifest | jq` verification step. `iii worker add` +fetches the binary, writes a config block into `~/.iii/config.yaml`, +and the engine starts the worker on the next `iii start`. + +### Companion workers + +If your worker is most useful next to a sibling โ€” e.g. `mcp` surfaces +`skills`-registered content to MCP clients โ€” include the companion as +a second `iii worker add` block with one sentence explaining what it +unlocks: + +````markdown +```bash +iii worker add skills +``` + +To surface every registered skill (and slash-command prompt) to MCP +clients (Cursor, Claude Code, Codex, Claude Desktop, โ€ฆ), add the +[mcp](../mcp) worker as well: + +```bash +iii worker add mcp +``` +```` + +### What does NOT go here + +Do not show `cargo build` / `cargo install` / `From source` blocks in +the user-facing flow. Source builds are for contributors; gate them +behind `## Local development & testing`. + +Do not show binary-verification steps (` --help`, +` --manifest | jq`). The registry already verifies the manifest +on publish; the user does not need to. + +## Section: Quickstart + +This is the meat of the README. Get the reader from "the worker is +running" to "I made a first useful call" as fast as possible. Aim for +โ‰ค30 lines of code in the primary example. + +Pick the audience-appropriate language (Rust, Node, or Python) and show +three things: + +- The function id to call. +- A realistic payload. +- The expected output shape. + +Example skeleton (Rust): + +````markdown +## Quickstart + +```rust +use iii_sdk::{register_worker, InitOptions, TriggerRequest}; +use serde_json::json; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let iii = register_worker("ws://localhost:49134", InitOptions::default()); + + let result = iii.trigger(TriggerRequest { + function_id: "::".into(), + payload: json!({ /* โ€ฆ */ }), + action: None, + timeout_ms: Some(5_000), + }).await?; + + println!("{result:#?}"); + Ok(()) +} +``` +```` + +Keep it to **1โ€“3 functions**, picked for their introductory value, not +their breadth. If your worker has 20 functions, show the 2 most users +will hit first; the rest live in code with rustdoc. + +If your worker participates in a larger flow (skills + mcp, fts + +agentmemory, โ€ฆ), the Quickstart can be a walkthrough of the +cross-worker handshake. [`skills/README.md`](skills/README.md) +is the canonical example: skill registration, sub-skill markdown +links, and prompt registration told as a single end-to-end story. + +## Section: Configuration + +Show the `config.yaml` block annotated with one-line comments. Keep it +to the fields a user is likely to tune. + +````markdown +## Configuration + +```yaml +data_dir: ${WORKER_DATA:~/.iii/data/} # where to persist state +timeout_ms: 5000 # per-call upper bound +``` +```` + +If your worker has many internal/advanced config keys, point at the +defaults in code rather than paginating every field: + +```markdown +Other keys (and their defaults) live in [`src/config.rs`](src/config.rs). +``` + +## Optional: Custom trigger types + +Include this section only if your worker publishes custom trigger +types other workers can subscribe to. Show a table: + +```markdown +## Custom trigger types + +| Trigger type | Fires when | Payload to subscribers | +|---|---|---| +| `::on-change` | After every mutation | `{ "op": "register" \| "unregister", "id": "..." }` | +``` + +This is one of the few cases the README **should** carry a reference +table โ€” sibling-worker authors need the trigger names + payload shapes +to write `iii.register_trigger(...)` calls. + +## Optional: Migration notes + +If you renamed function ids, removed config keys, or changed payload +shapes between versions, document the upgrade path. Keep it terse. + +```markdown +## Migration: pre-split function ids + +Function ids you used to call as `mcp::register-skill` / +`mcp::register-prompt` are now `skills::register` / +`prompts::register`. Payloads are unchanged. +``` + +## Optional: Local development & testing + +The escape hatch for contributors. Anything that uses `cargo` directly +goes here, never in `## Install` or `## Run`. + +````markdown +## Local development & testing + +### Run from source + +```bash +cargo run --release -- --url ws://127.0.0.1:49134 --config ./config.yaml +``` + +### Tests + +```bash +cargo test +``` +```` + +If your test suite has tags or scenarios worth surfacing (BDD harness, +optional engine-required suites), document them here. See +[`skills/README.md`](skills/README.md) for a worked example. + +## Skeleton + +Drop this in as `/README.md` and fill in the placeholders. Use +a four-backtick outer fence (or copy the body unfenced) when pasting, +since the README itself contains triple-backtick code blocks. + +````markdown +# + +One paragraph: what the worker does, who calls it, and the single +most important thing it gives you. + +## Install + +```bash +iii worker add +``` + +`iii worker add` fetches the binary, writes a config block into +`~/.iii/config.yaml`, and the engine starts the worker on the next +`iii start`. + +## Run + +```bash +iii start +``` + +## Quickstart + +```rust +use iii_sdk::{register_worker, InitOptions, TriggerRequest}; +use serde_json::json; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let iii = register_worker("ws://localhost:49134", InitOptions::default()); + + let result = iii.trigger(TriggerRequest { + function_id: "::".into(), + payload: json!({ "key": "value" }), + action: None, + timeout_ms: Some(5_000), + }).await?; + + println!("{result:#?}"); + Ok(()) +} +``` + +## Configuration + +```yaml +key: value # one line of intent per field +``` + +## Local development & testing + +```bash +cargo run --release -- --url ws://127.0.0.1:49134 --config ./config.yaml +cargo test +``` +```` + +## Worked examples + +- [`skills/README.md`](skills/README.md) โ€” install (with + companion `mcp`), end-to-end how-to, minimal configuration, dev + section. Canonical reference for this guide. +