1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//! # Ryo Plugin API
//!
//! WebAssembly Interface Types for ryo mutation plugins.
//!
//! ## Overview
//!
//! This crate provides the WIT-generated Rust types that define the contract
//! between the ryo host and WASM mutation plugins. Plugins act as
//! "Definition Providers" - they supply mutation metadata and transformation logic.
//!
//! ## Architecture
//!
//! ```text
//! WASM Plugin (Guest) ryo (Host)
//! ┌─────────────────────┐ ┌─────────────────────────┐
//! │ get-manifest() │───WIT───>│ Load mutation metadata │
//! │ get-pattern-source()│───WIT───>│ Compile pattern matcher │
//! │ execute-transform() │───WIT───>│ Apply text edits │
//! └─────────────────────┘ └─────────────────────────┘
//! ```
//!
//! ## Usage
//!
//! ### For Plugin Authors (Guest)
//!
//! ```rust,ignore
//! use ryo_plugin_api::*;
//!
//! wit_bindgen::generate!({
//! world: "mutation-plugin",
//! path: "wit",
//! exports: {
//! "ryo:transform/mutation": MyMutation,
//! }
//! });
//!
//! struct MyMutation;
//!
//! impl exports::ryo::transform::mutation::Guest for MyMutation {
//! fn get_manifest() -> MutationManifest {
//! MutationManifest {
//! api_version: CURRENT_API_VERSION,
//! name: "bool-simplify".into(),
//! description: "Simplify boolean comparisons".into(),
//! category: MutationCategory::Idiom,
//! tier: 1,
//! pattern: "...".into(),
//! transform: TransformDef::Template("{{var}}".into()),
//! }
//! }
//!
//! fn get_pattern_source() -> String {
//! String::new()
//! }
//!
//! fn execute_transform(
//! _matches: Vec<MatchResult>,
//! _context: TransformContext,
//! ) -> Result<Vec<TextEdit>, TransformError> {
//! // Only called if transform = WasmExecute
//! unreachable!()
//! }
//! }
//! ```
//!
//! ### For Host Implementation
//!
//! ```rust,ignore
//! use ryo_plugin_loader::PluginLoader;
//!
//! let loader = PluginLoader::new()?;
//! let plugin = loader.load(&wasm_bytes)?;
//!
//! // Use manifest
//! println!("Loaded mutation: {}", plugin.manifest.name);
//! ```
//!
//! ## API Versioning
//!
//! The `api_version` field in `MutationManifest` ensures compatibility:
//!
//! - Current version: **1**
//! - Host rejects plugins with mismatched versions
//! - Breaking changes increment the version number
// Generate WIT bindings
generate!;
// Re-export types from WIT interfaces
pub use ;
pub use ;
/// Current API version
///
/// This constant should match the version used by the host.
/// Plugins should use this in their manifest:
///
/// ```rust,ignore
/// MutationManifest {
/// api_version: ryo_plugin_api::CURRENT_API_VERSION,
/// // ...
/// }
/// ```
pub const CURRENT_API_VERSION: u32 = 1;
// =============================================================================
// Helper Functions
// =============================================================================
/// Create a template-based transform definition
///
/// Template supports `{{capture_name}}` interpolation.
///
/// # Example
/// ```rust,ignore
/// let transform = template("{{var}}");
/// // For match: `x == true` with capture @var="x"
/// // Result: `x`
/// ```
/// Create a WASM-execute transform definition
///
/// Use this when the transform requires complex logic that can't be
/// expressed as a simple template.
/// Create a text edit