diff --git a/Cargo.lock b/Cargo.lock index 0598ca0a..4a4dbdf2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -613,6 +613,12 @@ dependencies = [ "piper", ] +[[package]] +name = "borrow-or-share" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc0b364ead1874514c8c2855ab558056ebfeb775653e7ae45ff72f28f8f3166c" + [[package]] name = "branches" version = "0.4.6" @@ -1708,6 +1714,17 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "fluent-uri" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc74ac4d8359ae70623506d512209619e5cf8f347124910440dbc221714b328e" +dependencies = [ + "borrow-or-share", + "ref-cast", + "serde", +] + [[package]] name = "fnv" version = "1.0.7" @@ -4071,6 +4088,15 @@ dependencies = [ "serde_json", ] +[[package]] +name = "plugin-urls" +version = "0.1.0" +source = "git+https://github.com/cppalliance/runvil-plugin-urls?rev=5133069dc11ee99fdc10b4568388d8252d43dab4#5133069dc11ee99fdc10b4568388d8252d43dab4" +dependencies = [ + "fluent-uri", + "runvil-plugin-sdk", +] + [[package]] name = "plugin-web" version = "0.1.0" @@ -8025,6 +8051,14 @@ dependencies = [ "runvil-plugin-sdk", ] +[[package]] +name = "workshop-plugin-urls" +version = "0.3.1" +dependencies = [ + "plugin-urls", + "runvil-plugin-sdk", +] + [[package]] name = "workshop-plugin-web" version = "0.3.1" @@ -8090,6 +8124,7 @@ dependencies = [ "workshop-menu", "workshop-plugin-bashkit", "workshop-plugin-std", + "workshop-plugin-urls", "workshop-plugin-web", "workshop-protocol", "workshop-registry", diff --git a/Cargo.toml b/Cargo.toml index ab2cd95c..7494ebd6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "3" -members = ["crates/*", "crates/workshop/desktop", "crates/workshop/server", "crates/workshop/server-api", "crates/workshop/gateway", "crates/workshop/gateway-discovery", "crates/workshop/menu", "crates/workshop/protocol", "crates/workshop/registry", "crates/workshop/status", "crates/workshop/support", "crates/workshop/user-state", "crates/workshop/workspace", "crates/workshop/run-log", "crates/workshop/agents", "crates/workshop/plugin-std", "crates/workshop/plugin-bashkit", "crates/workshop/plugin-web"] +members = ["crates/*", "crates/workshop/desktop", "crates/workshop/server", "crates/workshop/server-api", "crates/workshop/gateway", "crates/workshop/gateway-discovery", "crates/workshop/menu", "crates/workshop/protocol", "crates/workshop/registry", "crates/workshop/status", "crates/workshop/support", "crates/workshop/user-state", "crates/workshop/workspace", "crates/workshop/run-log", "crates/workshop/agents", "crates/workshop/plugin-std", "crates/workshop/plugin-bashkit", "crates/workshop/plugin-web", "crates/workshop/plugin-urls"] # crates/workshop is a manifestless container holding Workshop's crates. # Cargo prunes excluded subtrees from member globs, so a "crates/workshop/*" # glob beside the exclude below would match nothing; the container crates @@ -10,7 +10,7 @@ exclude = ["crates/workshop"] # the server it embeds, and the server's facade: the rest compile on a # fresh macOS or Linux clone with no Node install and no Tauri system # packages. The desktop app is an explicit choice: `cargo build -p workshop`. -default-members = ["crates/build-ui", "crates/build-workshop", "crates/build-xtask", "crates/workshop/gateway", "crates/workshop/gateway-discovery", "crates/workshop/menu", "crates/workshop/protocol", "crates/workshop/registry", "crates/workshop/status", "crates/workshop/support", "crates/workshop/user-state", "crates/workshop/workspace", "crates/workshop/run-log", "crates/workshop/agents", "crates/workshop/plugin-std", "crates/workshop/plugin-bashkit", "crates/workshop/plugin-web"] +default-members = ["crates/build-ui", "crates/build-workshop", "crates/build-xtask", "crates/workshop/gateway", "crates/workshop/gateway-discovery", "crates/workshop/menu", "crates/workshop/protocol", "crates/workshop/registry", "crates/workshop/status", "crates/workshop/support", "crates/workshop/user-state", "crates/workshop/workspace", "crates/workshop/run-log", "crates/workshop/agents", "crates/workshop/plugin-std", "crates/workshop/plugin-bashkit", "crates/workshop/plugin-web", "crates/workshop/plugin-urls"] [workspace.package] version = "0.3.1" @@ -54,6 +54,13 @@ bashkit-plugin = { package = "plugin-bashkit", version = "0.1.0", git = "https:/ # crate's own library has the name of the file Workshop ships, # `plugin_web`. web-plugin = { package = "plugin-web", version = "0.1.0", git = "https://github.com/cppalliance/runvil-plugin-web", rev = "9409b2c8070fc43883c8b286a56015eb4747fa20", default-features = false } +# The urls Plugin, from its own repository, pinned by commit and built +# against the same contract commit. default-features off drops its own +# export of `runvil_plugin`, which `workshop-plugin-urls` makes instead. +# The key is `urls-plugin` for the reason std's is `std-plugin`: the +# crate's own library has the name of the file Workshop ships, +# `plugin_urls`. +urls-plugin = { package = "plugin-urls", version = "0.1.0", git = "https://github.com/cppalliance/runvil-plugin-urls", rev = "5133069dc11ee99fdc10b4568388d8252d43dab4", default-features = false } workshop-gateway-discovery = { path = "crates/workshop/gateway-discovery" } workshop-server = { path = "crates/workshop/server" } workshop-server-api = { path = "crates/workshop/server-api" } @@ -70,6 +77,7 @@ workshop-user-state = { path = "crates/workshop/user-state" } workshop-plugin-std = { path = "crates/workshop/plugin-std" } workshop-plugin-bashkit = { path = "crates/workshop/plugin-bashkit" } workshop-plugin-web = { path = "crates/workshop/plugin-web" } +workshop-plugin-urls = { path = "crates/workshop/plugin-urls" } # default-features off: build-xtask's doctest scan reads only the core # event stream, never the `html` renderer or the `getopts` binary. pulldown-cmark = { version = "0.12", default-features = false } diff --git a/crates/build-workshop/README.md b/crates/build-workshop/README.md index 2ba711c5..e57ea8c1 100644 --- a/crates/build-workshop/README.md +++ b/crates/build-workshop/README.md @@ -26,6 +26,7 @@ Three library Plugins ship with Workshop, each a dynamic library whose code is i - The std Plugin, from [cppalliance/runvil-plugin-std](https://github.com/cppalliance/runvil-plugin-std), holds the file tools. Its library is `plugin_std.dll`, `libplugin_std.so`, or `libplugin_std.dylib`. - The bashkit Plugin, from [cppalliance/runvil-plugin-bashkit](https://github.com/cppalliance/runvil-plugin-bashkit), holds the shell. Its library is `plugin_bashkit.dll`, `libplugin_bashkit.so`, or `libplugin_bashkit.dylib`. - The web Plugin, from [cppalliance/runvil-plugin-web](https://github.com/cppalliance/runvil-plugin-web), holds the web tools. Its library is `plugin_web.dll`, `libplugin_web.so`, or `libplugin_web.dylib`. +- The urls Plugin, from [cppalliance/runvil-plugin-urls](https://github.com/cppalliance/runvil-plugin-urls), holds the `urls` native prelude. Its library is `plugin_urls.dll`, `libplugin_urls.so`, or `libplugin_urls.dylib`. Nothing here builds them by name: the Workshop server depends on `workshop-plugin-std`, `workshop-plugin-bashkit`, and `workshop-plugin-web`, so Cargo writes each library to `deps` in the profile's directory whenever it builds Workshop. Each mode takes the libraries from there. A build copies them into `plugins` beside Workshop in the target directory. A macOS or Linux bundle build has Tauri copy them into Workshop's bundle, at `Runvil.app/Contents/Resources/plugins` or at `usr/lib/runvil/plugins` in the AppImage, so the updater, which replaces only that bundle, replaces the libraries with it. The bundle build fails when the bundle Tauri built does not hold each library. A Workshop run with plain `cargo run -p workshop` has no Plugin directory, so its agents have no file tools, no shell, and no web tools; run `cargo workshop` once to place the libraries. Plain Cargo builds do not refresh the placed copies, so run `cargo workshop` again after a pin or the contract version changes. diff --git a/crates/build-workshop/src/main/plugin.rs b/crates/build-workshop/src/main/plugin.rs index 1b487eac..35f140d3 100644 --- a/crates/build-workshop/src/main/plugin.rs +++ b/crates/build-workshop/src/main/plugin.rs @@ -31,10 +31,12 @@ pub(crate) const APPIMAGE_PLUGIN_PARENT: &str = "usr/lib/runvil"; /// The library of each Plugin Workshop ships, as its `workshop-plugin-*` /// crate names it: the std Plugin's, which holds the file tools, the -/// bashkit Plugin's, which holds the shell, and the web Plugin's, which -/// holds the web tools. `installer.nsi` and the install tests in -/// `cppalliance/runvil` name the same three. -pub(crate) const LIBRARIES: [&str; 3] = ["plugin_std", "plugin_bashkit", "plugin_web"]; +/// bashkit Plugin's, which holds the shell, the web Plugin's, which holds +/// the web tools, and the urls Plugin's, which holds the `urls` native +/// prelude. `installer.nsi` and the install tests in `cppalliance/runvil` +/// name the same four. +pub(crate) const LIBRARIES: [&str; 4] = + ["plugin_std", "plugin_bashkit", "plugin_web", "plugin_urls"]; /// The file name Cargo gives each shipped library for `target`, in the /// order of [`LIBRARIES`]. diff --git a/crates/build-workshop/src/main/tests/bundle.rs b/crates/build-workshop/src/main/tests/bundle.rs index 734ff3d2..258e1cec 100644 --- a/crates/build-workshop/src/main/tests/bundle.rs +++ b/crates/build-workshop/src/main/tests/bundle.rs @@ -73,6 +73,7 @@ pub(super) fn bundled_plugins(environment: &BuildEnvironment, target: &str) -> V "libplugin_std.dylib", "libplugin_bashkit.dylib", "libplugin_web.dylib", + "libplugin_urls.dylib", ], ) } else { @@ -87,6 +88,7 @@ pub(super) fn bundled_plugins(environment: &BuildEnvironment, target: &str) -> V "libplugin_std.so", "libplugin_bashkit.so", "libplugin_web.so", + "libplugin_urls.so", ], ) }; @@ -104,6 +106,7 @@ fn plugin_config(environment: &BuildEnvironment, target: &str) -> Option "Resources/plugins/libplugin_bashkit.dylib": deps.join("libplugin_bashkit.dylib"), "Resources/plugins/libplugin_web.dylib": deps.join("libplugin_web.dylib"), + "Resources/plugins/libplugin_urls.dylib": deps.join("libplugin_urls.dylib"), } } } }) } else if target.contains("linux") { @@ -113,6 +116,7 @@ fn plugin_config(environment: &BuildEnvironment, target: &str) -> Option "/usr/lib/runvil/plugins/libplugin_bashkit.so": deps.join("libplugin_bashkit.so"), "/usr/lib/runvil/plugins/libplugin_web.so": deps.join("libplugin_web.so"), + "/usr/lib/runvil/plugins/libplugin_urls.so": deps.join("libplugin_urls.so"), } } } } }) } else { diff --git a/crates/build-workshop/src/main/tests/plugin.rs b/crates/build-workshop/src/main/tests/plugin.rs index 0765413c..e6c0d4af 100644 --- a/crates/build-workshop/src/main/tests/plugin.rs +++ b/crates/build-workshop/src/main/tests/plugin.rs @@ -12,11 +12,21 @@ fn each_library_is_named_as_cargo_names_it_for_each_target() { for (target, names) in [ ( "x86_64-pc-windows-msvc", - ["plugin_std.dll", "plugin_bashkit.dll", "plugin_web.dll"], + [ + "plugin_std.dll", + "plugin_bashkit.dll", + "plugin_web.dll", + "plugin_urls.dll", + ], ), ( "aarch64-pc-windows-msvc", - ["plugin_std.dll", "plugin_bashkit.dll", "plugin_web.dll"], + [ + "plugin_std.dll", + "plugin_bashkit.dll", + "plugin_web.dll", + "plugin_urls.dll", + ], ), ( "x86_64-apple-darwin", @@ -24,6 +34,7 @@ fn each_library_is_named_as_cargo_names_it_for_each_target() { "libplugin_std.dylib", "libplugin_bashkit.dylib", "libplugin_web.dylib", + "libplugin_urls.dylib", ], ), ( @@ -32,6 +43,7 @@ fn each_library_is_named_as_cargo_names_it_for_each_target() { "libplugin_std.dylib", "libplugin_bashkit.dylib", "libplugin_web.dylib", + "libplugin_urls.dylib", ], ), ( @@ -40,6 +52,7 @@ fn each_library_is_named_as_cargo_names_it_for_each_target() { "libplugin_std.so", "libplugin_bashkit.so", "libplugin_web.so", + "libplugin_urls.so", ], ), ( @@ -48,6 +61,7 @@ fn each_library_is_named_as_cargo_names_it_for_each_target() { "libplugin_std.so", "libplugin_bashkit.so", "libplugin_web.so", + "libplugin_urls.so", ], ), ] { @@ -83,7 +97,7 @@ fn a_host_build_places_each_library_in_the_plugin_directory_beside_workshop() { .expect("Workshop build"); let plugins = environment.target_root.join("debug").join("plugins"); - for library in ["plugin_std", "plugin_bashkit", "plugin_web"] { + for library in ["plugin_std", "plugin_bashkit", "plugin_web", "plugin_urls"] { assert_eq!( std::fs::read(plugins.join(format!("{library}.dll"))).expect("the placed library"), plugin_bytes(library, None, "debug"), @@ -92,7 +106,7 @@ fn a_host_build_places_each_library_in_the_plugin_directory_beside_workshop() { } assert_eq!( std::fs::read_dir(&plugins).expect("plugins").count(), - 3, + 4, "the copies leave no other file behind" ); } @@ -123,7 +137,7 @@ fn a_build_for_a_named_target_places_each_library_under_that_target_and_replaces ) .expect("Workshop build"); - for library in ["plugin_std", "plugin_bashkit", "plugin_web"] { + for library in ["plugin_std", "plugin_bashkit", "plugin_web", "plugin_urls"] { assert_eq!( std::fs::read(plugins.join(format!("lib{library}.so"))).expect("the placed library"), plugin_bytes(library, Some(triple), "release"), @@ -146,6 +160,7 @@ fn a_build_that_left_a_library_out_fails_naming_the_file_and_places_nothing() { ("plugin_std", "libplugin_std.so"), ("plugin_bashkit", "libplugin_bashkit.so"), ("plugin_web", "libplugin_web.so"), + ("plugin_urls", "libplugin_urls.so"), ] { let test_environment = environment(); let environment = &test_environment.environment; @@ -195,6 +210,7 @@ fn the_bundle_configuration_copies_each_library_into_each_platform_s_bundle() { deps.join("libplugin_std.dylib"), deps.join("libplugin_bashkit.dylib"), deps.join("libplugin_web.dylib"), + deps.join("libplugin_urls.dylib"), ]; assert_eq!( plugin::bundle_config(System::MacOs, &dylibs), @@ -204,6 +220,7 @@ fn the_bundle_configuration_copies_each_library_into_each_platform_s_bundle() { "Resources/plugins/libplugin_std.dylib": dylibs[0], "Resources/plugins/libplugin_bashkit.dylib": dylibs[1], "Resources/plugins/libplugin_web.dylib": dylibs[2], + "Resources/plugins/libplugin_urls.dylib": dylibs[3], } } } }) .to_string() @@ -214,6 +231,7 @@ fn the_bundle_configuration_copies_each_library_into_each_platform_s_bundle() { deps.join("libplugin_std.so"), deps.join("libplugin_bashkit.so"), deps.join("libplugin_web.so"), + deps.join("libplugin_urls.so"), ]; assert_eq!( plugin::bundle_config(System::Linux, &sos), @@ -223,6 +241,7 @@ fn the_bundle_configuration_copies_each_library_into_each_platform_s_bundle() { "/usr/lib/runvil/plugins/libplugin_std.so": sos[0], "/usr/lib/runvil/plugins/libplugin_bashkit.so": sos[1], "/usr/lib/runvil/plugins/libplugin_web.so": sos[2], + "/usr/lib/runvil/plugins/libplugin_urls.so": sos[3], } } } } }) .to_string() @@ -233,6 +252,7 @@ fn the_bundle_configuration_copies_each_library_into_each_platform_s_bundle() { deps.join("plugin_std.dll"), deps.join("plugin_bashkit.dll"), deps.join("plugin_web.dll"), + deps.join("plugin_urls.dll"), ]; assert_eq!( plugin::bundle_config(System::Windows, &dlls), @@ -254,6 +274,7 @@ fn a_bundle_tauri_left_without_a_library_fails_the_bundle_build() { (0, "libplugin_std."), (1, "libplugin_bashkit."), (2, "libplugin_web."), + (3, "libplugin_urls."), ] { let test_environment = environment(); let environment = &test_environment.environment; diff --git a/crates/build-xtask/src/tidy-tests.rs b/crates/build-xtask/src/tidy-tests.rs index 972c3eaa..fc8f135c 100644 --- a/crates/build-xtask/src/tidy-tests.rs +++ b/crates/build-xtask/src/tidy-tests.rs @@ -267,6 +267,7 @@ fn tier_table_grants_each_tier_only_lower_tiers() { "workshop-plugin-std", "workshop-plugin-bashkit", "workshop-plugin-web", + "workshop-plugin-urls", ] { assert_eq!( allowed_dependencies(plugin), diff --git a/crates/build-xtask/src/tidy.rs b/crates/build-xtask/src/tidy.rs index e95130c7..7558f267 100644 --- a/crates/build-xtask/src/tidy.rs +++ b/crates/build-xtask/src/tidy.rs @@ -33,6 +33,7 @@ const PLUGINS: &[Tiered] = &[ ("workshop-plugin-std", "plugin-std"), ("workshop-plugin-bashkit", "plugin-bashkit"), ("workshop-plugin-web", "plugin-web"), + ("workshop-plugin-urls", "plugin-urls"), ]; /// Tier 1: domain services. Depend on vocabulary crates only. const SERVICES: &[Tiered] = &[ diff --git a/crates/workshop/desktop/README.md b/crates/workshop/desktop/README.md index c8824cf3..be1a60ec 100644 --- a/crates/workshop/desktop/README.md +++ b/crates/workshop/desktop/README.md @@ -27,6 +27,7 @@ Each installer puts three libraries there, each from a repository of its own, pi - The std Plugin, which holds the file tools: `plugin_std.dll`, `libplugin_std.dylib`, or `libplugin_std.so`, from [cppalliance/runvil-plugin-std](https://github.com/cppalliance/runvil-plugin-std). - The bashkit Plugin, which holds the shell: `plugin_bashkit.dll`, `libplugin_bashkit.dylib`, or `libplugin_bashkit.so`, from [cppalliance/runvil-plugin-bashkit](https://github.com/cppalliance/runvil-plugin-bashkit). - The web Plugin, which holds the web tools: `plugin_web.dll`, `libplugin_web.dylib`, or `libplugin_web.so`, from [cppalliance/runvil-plugin-web](https://github.com/cppalliance/runvil-plugin-web). +- The urls Plugin, which holds the `urls` native prelude: `plugin_urls.dll`, `libplugin_urls.dylib`, or `libplugin_urls.so`, from [cppalliance/runvil-plugin-urls](https://github.com/cppalliance/runvil-plugin-urls). A Workshop with no Plugin directory, or one whose std library does not load, refuses an agent that requires `std` and says that `runvil/std` is not installed. It does the same for `bash` and the bashkit library, and for `web` and the web library. diff --git a/crates/workshop/desktop/installer.nsi b/crates/workshop/desktop/installer.nsi index 26a4fd5a..f7faa9dc 100644 --- a/crates/workshop/desktop/installer.nsi +++ b/crates/workshop/desktop/installer.nsi @@ -65,6 +65,7 @@ ${StrLoc} !searchreplace STDPLUGINSRCPATH "${MAINBINARYSRCPATH}" "${MAINBINARYNAME}.exe" "deps\plugin_std.dll" !searchreplace BASHKITPLUGINSRCPATH "${MAINBINARYSRCPATH}" "${MAINBINARYNAME}.exe" "deps\plugin_bashkit.dll" !searchreplace WEBPLUGINSRCPATH "${MAINBINARYSRCPATH}" "${MAINBINARYNAME}.exe" "deps\plugin_web.dll" +!searchreplace URLSPLUGINSRCPATH "${MAINBINARYSRCPATH}" "${MAINBINARYNAME}.exe" "deps\plugin_urls.dll" ; A main executable under another name would leave the path unchanged, and ; the setup would install the executable as each Plugin. !if "${STDPLUGINSRCPATH}" == "${MAINBINARYSRCPATH}" @@ -753,6 +754,7 @@ Section "Runvil Workshop" SecWorkshop File "/oname=plugins\plugin_std.dll" "${STDPLUGINSRCPATH}" File "/oname=plugins\plugin_bashkit.dll" "${BASHKITPLUGINSRCPATH}" File "/oname=plugins\plugin_web.dll" "${WEBPLUGINSRCPATH}" + File "/oname=plugins\plugin_urls.dll" "${URLSPLUGINSRCPATH}" ; Copy resources {{#each resources_dirs}} @@ -907,6 +909,7 @@ Section "-Finalize" !insertmacro DeleteComponentPayloadIfDeclined ${SecWorkshop} $INSTDIR\plugins\plugin_std.dll !insertmacro DeleteComponentPayloadIfDeclined ${SecWorkshop} $INSTDIR\plugins\plugin_bashkit.dll !insertmacro DeleteComponentPayloadIfDeclined ${SecWorkshop} $INSTDIR\plugins\plugin_web.dll + !insertmacro DeleteComponentPayloadIfDeclined ${SecWorkshop} $INSTDIR\plugins\plugin_urls.dll ; Without /r, RMDir removes the Plugin directory only when it is empty, ; which it is only after the lines above deleted the three libraries in it. RMDir "$INSTDIR\plugins" @@ -993,6 +996,7 @@ Section "un.Workshop" Delete "$INSTDIR\plugins\plugin_std.dll" Delete "$INSTDIR\plugins\plugin_bashkit.dll" Delete "$INSTDIR\plugins\plugin_web.dll" + Delete "$INSTDIR\plugins\plugin_urls.dll" RMDir "$INSTDIR\plugins" ; Delete resources diff --git a/crates/workshop/plugin-urls/Cargo.toml b/crates/workshop/plugin-urls/Cargo.toml new file mode 100644 index 00000000..6a2a30a1 --- /dev/null +++ b/crates/workshop/plugin-urls/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "workshop-plugin-urls" +version.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +publish = false + +# A dynamic library, which is the file Workshop's Plugin directory holds, +# and an rlib, so the server can depend on this crate and have Cargo +# build the library with every build of Workshop. The library is named +# for the Plugin, so the file is `plugin_urls.dll`, `libplugin_urls.so`, or +# `libplugin_urls.dylib`. +[lib] +name = "plugin_urls" +crate-type = ["cdylib", "rlib"] + +[dependencies] +# The urls Plugin, linked in with its own export off. +urls-plugin.workspace = true +# `export_plugin!`, which exports the Plugin's entry point from this +# library. +runvil-plugin-sdk.workspace = true + +[lints] +workspace = true diff --git a/crates/workshop/plugin-urls/src/lib.rs b/crates/workshop/plugin-urls/src/lib.rs new file mode 100644 index 00000000..ab0970ea --- /dev/null +++ b/crates/workshop/plugin-urls/src/lib.rs @@ -0,0 +1,30 @@ +//! `workshop-plugin-urls` - the urls Plugin as the dynamic library Workshop +//! ships in its Plugin directory: `plugin_urls.dll` on Windows, +//! `libplugin_urls.so` on Linux, and `libplugin_urls.dylib` on macOS. The +//! Plugin inserts the Pack `runvil/urls`, whose native Lua prelude installs +//! the `urls` table for RFC 3986 URL parsing, serialization, validation, +//! normalization, and relative-reference resolution. +//! +//! The Plugin's code lives in its own repository, +//! `cppalliance/runvil-plugin-urls`, which the root `Cargo.toml` pins by +//! commit. Cargo gives a git dependency's own library a file name with a +//! hash in it, which no test and no installer could find, so this crate +//! links the Plugin in and exports its entry point under a file name the +//! workspace fixes. Cargo writes that file to `deps` in the profile's +//! directory whenever it builds the server, and `cargo workshop` copies +//! it from there into the Plugin directory. +//! +//! ## Invariants +//! +//! - Tier: library Plugin; may depend on no `workshop-*` crate, and only +//! the server may name it. `cargo test -p build-xtask` enforces the +//! tiers. +//! - Holds no code of its own beyond the export of `runvil_plugin`. +//! - The server depends on this crate only so that Cargo builds the +//! library. No Workshop crate links it in or calls it: Workshop reaches +//! the Plugin through the library alone. +//! - Names the Plugin SDK at the commit the pinned urls Plugin was built +//! against. Cargo links one copy of the contract into a build, so a pin +//! that disagrees fails to resolve. + +runvil_plugin_sdk::export_plugin!(urls_plugin::Urls); diff --git a/crates/workshop/server/Cargo.toml b/crates/workshop/server/Cargo.toml index eed7232e..58370583 100644 --- a/crates/workshop/server/Cargo.toml +++ b/crates/workshop/server/Cargo.toml @@ -35,6 +35,9 @@ workshop-plugin-bashkit.workspace = true # The web Plugin's dynamic library, which holds the web Pack # `runvil/web`. Like std's, it is here only so that Cargo builds it. workshop-plugin-web.workspace = true +# The urls Plugin's dynamic library, which holds the urls Pack +# `runvil/urls`. Like std's, it is here only so that Cargo builds it. +workshop-plugin-urls.workspace = true reqwest.workspace = true rust-embed.workspace = true serde.workspace = true diff --git a/crates/workshop/server/src/agents.rs b/crates/workshop/server/src/agents.rs index 78772907..470b3f0e 100644 --- a/crates/workshop/server/src/agents.rs +++ b/crates/workshop/server/src/agents.rs @@ -476,9 +476,10 @@ fn with_plugins( } /// The Packs that only a library Plugin Workshop ships inserts: the file -/// tools, from the std Plugin, the shell, from the bashkit Plugin, and the -/// web tools, from the web Plugin. -const SHIPPED_PACKS: [&str; 3] = ["runvil/std", "runvil/bash", "runvil/web"]; +/// tools, from the std Plugin, the shell, from the bashkit Plugin, the web +/// tools, from the web Plugin, and the `urls` native prelude, from the urls +/// Plugin. +const SHIPPED_PACKS: [&str; 4] = ["runvil/std", "runvil/bash", "runvil/web", "runvil/urls"]; /// Whether `host` has the Pack named `pack`, a vendor and a Pack id. fn holds(host: &Host, pack: &str) -> bool { diff --git a/crates/workshop/server/src/agents/tests.rs b/crates/workshop/server/src/agents/tests.rs index 9055143f..0ffb71c8 100644 --- a/crates/workshop/server/src/agents/tests.rs +++ b/crates/workshop/server/src/agents/tests.rs @@ -36,6 +36,7 @@ static PLUGIN_DIRS: AtomicUsize = AtomicUsize::new(0); pub(super) const STD_LIBRARY: &str = "plugin_std"; pub(super) const BASHKIT_LIBRARY: &str = "plugin_bashkit"; const WEB_LIBRARY: &str = "plugin_web"; +const URLS_LIBRARY: &str = "plugin_urls"; fn requiring(pack: &str) -> String { format!( @@ -171,6 +172,7 @@ async fn every_run_holds_the_packs_the_three_plugins_add_and_the_builtins() { async fn prompts_declaring_available_packs_prepare_and_run() { const CASES: &[(&str, &str, Option<&str>, Option<&str>)] = &[ ("library-web", "web", Some(WEB_LIBRARY), Some("web")), + ("library-urls", "urls", Some(URLS_LIBRARY), Some("urls")), ("library-std", "std", Some(STD_LIBRARY), Some("std")), ( "library-bash", @@ -422,6 +424,7 @@ fn only_a_plugin_directory_with_a_shipped_library_gives_the_host_its_pack() { (STD_LIBRARY, "runvil/std"), (BASHKIT_LIBRARY, "runvil/bash"), (WEB_LIBRARY, "runvil/web"), + (URLS_LIBRARY, "runvil/urls"), ] { assert!(SHIPPED_PACKS.contains(&pack), "{pack}"); let (dir, _library) = plugin_dir_of("holds-a-shipped-pack", library); @@ -612,3 +615,35 @@ fn the_streaming_callback_publishes_each_piece_into_its_conversation_under_the_r ); assert!(deltas.try_recv().is_err()); } + +#[tokio::test] +async fn the_urls_plugin_native_prelude_runs_in_a_section_vm() { + let source = "---\nname: browses\ndescription: exercises urls native prelude\nrunvil: 0\n\ + uses:\n - urls\n---\n\n\ + ## Only\n\n```lua\n\ + local u = urls.parse('https://alice%3A1:p:ss@example.com:8443/a/b%2Fc?k+1=v%2B1&flag#sec%201')\n\ + assert(u.scheme == 'https' and u.username == 'alice:1' and u.password == 'p:ss')\n\ + assert(u.host == 'example.com' and u.port == 8443 and u.path_absolute == true)\n\ + assert(#u.segments == 2 and u.segments[1] == 'a' and u.segments[2] == 'b/c')\n\ + assert(#u.params == 2 and u.params[1].key == 'k 1' and u.params[1].value == 'v+1')\n\ + assert(u.params[2].key == 'flag' and u.params[2].value == nil)\n\ + assert(u.fragment == 'sec 1')\n\ + local rt = urls.serialize(u)\n\ + local bad, err = urls.parse('http://[::1')\n\ + assert(bad == nil and type(err) == 'string')\n\ + assert(urls.validate('/a/b?c=1') == true)\n\ + local norm = urls.normalize('HTTP://ExAmPlE.com:80/a/../b')\n\ + local res = urls.resolve('http://a/b/c/d?q#f', '../g')\n\ + return rt .. '|' .. norm .. '|' .. res\n\ + ```\n"; + let (dir, _library) = plugin_dir_of("urls-prelude", URLS_LIBRARY); + let host = server_host(serving(source), &Registry::new(), None, Some(dir.path())); + assert_no_failures(&host); + assert_eq!( + run_prompt(host).await, + Ok(Ok( + "https://alice%3A1:p:ss@example.com:8443/a/b%2Fc?k+1=v%2B1&flag#sec%201|http://example.com:80/b|http://a/b/g" + .to_owned() + )) + ); +} diff --git a/crates/workshop/server/src/lib.rs b/crates/workshop/server/src/lib.rs index 4b9d5606..f6a66f77 100644 --- a/crates/workshop/server/src/lib.rs +++ b/crates/workshop/server/src/lib.rs @@ -33,8 +33,9 @@ //! `workshop-run-log`, `workshop-user-state`, `workshop-workspace`), //! the Harness's public crates `runvil` and `harness-gateway-client`, //! the Plugin crate `plugin-mcp`, and `workshop-plugin-std`, -//! `workshop-plugin-bashkit`, and `workshop-plugin-web`, the libraries -//! of the std Plugin, the bashkit Plugin, and the web Plugin, which +//! `workshop-plugin-bashkit`, `workshop-plugin-web`, and +//! `workshop-plugin-urls`, the libraries of the std Plugin, the +//! bashkit Plugin, the web Plugin, and the urls Plugin, which //! the server loads from its Plugin directory and never links. //! It reaches the Engine and the Plugin contract through `runvil` //! alone, never through an Engine crate. diff --git a/crates/workshop/server/tests/common/mod.rs b/crates/workshop/server/tests/common/mod.rs index 41ad18d8..f4b3b429 100644 --- a/crates/workshop/server/tests/common/mod.rs +++ b/crates/workshop/server/tests/common/mod.rs @@ -36,8 +36,9 @@ use workshop_server::{ pub(crate) const RECV_TIMEOUT: Duration = Duration::from_secs(10); /// The name of each library Plugin Workshop ships, as Cargo names its -/// library: the std Plugin's, the bashkit Plugin's, and the web Plugin's. -const PLUGIN_LIBRARIES: [&str; 3] = ["plugin_std", "plugin_bashkit", "plugin_web"]; +/// library: the std Plugin's, the bashkit Plugin's, the web Plugin's, and +/// the urls Plugin's. +const PLUGIN_LIBRARIES: [&str; 4] = ["plugin_std", "plugin_bashkit", "plugin_web", "plugin_urls"]; /// A Plugin directory that holds the library of each Plugin Workshop /// ships and nothing else, for a server whose agents declare `std`, diff --git a/crates/workshop/ui/test/docs-claims.mjs b/crates/workshop/ui/test/docs-claims.mjs index 11064eff..601607c4 100644 --- a/crates/workshop/ui/test/docs-claims.mjs +++ b/crates/workshop/ui/test/docs-claims.mjs @@ -115,6 +115,7 @@ const PLUGIN_DOC_DIRS = [ "crates/workshop/plugin-std", "crates/workshop/plugin-bashkit", "crates/workshop/plugin-web", + "crates/workshop/plugin-urls", ]; test("the root AGENTS.md and the Pack-facing crates' comments never describe Pack activation", async () => { diff --git a/deny.toml b/deny.toml index c5a928cc..551da45d 100644 --- a/deny.toml +++ b/deny.toml @@ -86,4 +86,5 @@ allow-git = [ "https://github.com/cppalliance/runvil-plugin-std", "https://github.com/cppalliance/runvil-plugin-bashkit", "https://github.com/cppalliance/runvil-plugin-web", + "https://github.com/cppalliance/runvil-plugin-urls", ]