Expand description
Write a Moonlit plugin: one Middleware impl per step, and one
moonlit_plugin! block naming them.
Targets plugin ABI moonlit:plugin@0.3.0. Each middleware publishes a JSON
Schema for its Input and Output, which is what moonlit plugin inspect
reads. See Middleware for a worked example and testing for driving
one in a unit test.
Modules§
- bindings
- Generated WIT bindings. Public because the
moonlit_plugin!macro output (expanded in the author crate) references this exact path viaexport!(Component with_types_in moonlit_pdk::bindings). - clock
- Monotonic clock access.
ctx.clock().start()yields aTimerwhoseelapsed_ms()re-reads the live clock — an honest stopwatch across an arbitrarily long operation, with the plugin never touching raw nanos. - config
- Config binding with §5.4 string coercion. The engine sends config JSON in
which every scalar is a string (see engine
value_to_json); typed fields parse those strings in the fixed order bool -> i64 -> f64 -> datetime -> String.deserialize_any(dynamic targets) applies the same order, with datetime collapsing to a string (serde has no datetime type). - env
- Environment access. Reads route through the host, which serves
wasi:cli/environment— already permission-filtered by the engine (filter_env). Funnelling throughHostkeeps env mockable in native tests. - http
- Tiny blocking HTTP client over the host
http_sendcapability. Verbs, bearer auth, custom headers, JSON in/out, per-request timeout, and gzip response inflate. Sized for GitHub/GitLab/Slack/OpenAI/npm/NuGet-style REST calls. - prelude
- process
- Safe, native-testable wrappers over the host
processcapability.Commandbuilds a subprocess;.run()captures,.stream()live-logs via aLineHandler,.spawn()yields aChildfor line-by-line control. Non-zero exit is data (Ok), not an error;Errmeans the spawn itself failed. - random
- Randomness, routed through the host so tests can seed it deterministically.
- state
- Interior-mutable state shared between a plugin’s middlewares.
- testing
- Drive a middleware against a recording mock host, with no wasm build.
Macros§
- export
- Generates
#[unsafe(no_mangle)]functions to export the specified type as the root implementation of all generated traits. - moonlit_
plugin
Structs§
- Context
- Execution context handed to every middleware.
- Middleware
Result - What a
Middlewarereturns. - NoInput
- Marker for a middleware that reads no configuration. Deserializes from
{}(or an absent config block) and yields an empty-object input schema (“no declared inputs”). Input-only: it has noSerializeimpl. - NoOutput
- Marker for a middleware that publishes no outputs. Serializes to
{}and yields an empty-object output schema (“no declared outputs”).
Enums§
- LogLevel
- Log severity surfaced to the CLI renderer.
Traits§
- Host
- The capabilities
Contextneeds from the environment. - Middleware
- One step a pipeline can
run:. Implement it on aDefaultunit struct. - Plugin
Config - Semantic validation for a plugin’s
config:, beyond what decoding checks.