Skip to main content

ringlet_scripting/
lib.rs

1//! Rhai scripting engine for ringlet configuration generation.
2//!
3//! This crate provides:
4//! - A sandboxed Rhai engine for running configuration scripts
5//! - Built-in functions for JSON and TOML encoding
6//! - Built-in scripts for each supported agent
7//!
8//! ## Script Context
9//!
10//! Scripts receive a context object with:
11//! - `profile`: Profile information (alias, agent, provider, model, etc.)
12//! - `provider`: Provider information (type, endpoints, auth)
13//! - `agent`: Agent information (binary, profile strategy)
14//! - `prefs`: User preferences (from config.toml)
15//!
16//! ## Script Output
17//!
18//! Scripts should return an object with:
19//! - `files`: Map of relative paths to file contents
20//! - `env`: Map of environment variables to set
21//! - `hooks`: Optional hooks configuration
22//! - `mcp_servers`: Optional MCP servers configuration
23
24mod engine;
25mod functions;
26
27pub use engine::{
28    AgentContext, PrefsContext, ProfileContext, ProviderContext,
29    ScriptContext, ScriptEngine, ScriptOutput,
30};
31
32/// Built-in scripts for each agent.
33pub mod scripts {
34    pub const CLAUDE: &str = include_str!("scripts/claude.rhai");
35    pub const GROK: &str = include_str!("scripts/grok.rhai");
36    pub const CODEX: &str = include_str!("scripts/codex.rhai");
37    pub const DROID: &str = include_str!("scripts/droid.rhai");
38    pub const OPENCODE: &str = include_str!("scripts/opencode.rhai");
39
40    /// Get built-in script by name.
41    pub fn get(name: &str) -> Option<&'static str> {
42        match name {
43            "claude.rhai" => Some(CLAUDE),
44            "grok.rhai" => Some(GROK),
45            "codex.rhai" => Some(CODEX),
46            "droid.rhai" => Some(DROID),
47            "opencode.rhai" => Some(OPENCODE),
48            _ => None,
49        }
50    }
51}