pub const NAME: &str = "lua_repl";
pub const DESCRIPTION: &str = r#"Execute Lua code in a long-lived sandboxed REPL environment.
**IMPORTANT:** Provide ONLY valid Lua code as input. Do NOT wrap code in markdown blocks.
**Environment:**
- Sandboxed Lua 5.4 with persistent state between calls
- Global variables (assigned without `local`) persist across calls
- Local variables (`local x = ...`) are lost between calls
- Custom global variables may be injected by the application (check what's available!)
**Available Operations:**
- Full string library (string.sub, string.find, string.match, string.gsub, string.gmatch, etc.)
- Full table library (table.insert, table.concat, table.remove, table.sort, etc.)
- Full math library (math.min, math.max, math.floor, math.ceil, math.abs, math.sqrt, etc.)
- UTF-8 support (utf8.*)
- Core functions: type(), tonumber(), tostring(), pairs(), ipairs(), select(), assert(), error(), pcall(), xpcall()
- Output: print() (captured in tool response)
- Time: os.time(), os.date()
- Docs: `docs` global contains documentation for custom functions
**Restrictions:**
- No file I/O, network access, or OS commands
- No require(), load(), loadfile(), or dofile()
- No metatable manipulation (rawset, setmetatable, etc.)
**Pattern Matching:**
Lua patterns (NOT regex): `.` (any char), `%d` (digit), `%a` (letter), `%s` (space), `+` (1 or more), `*` (0 or more)
Example: string.match(text, "number is (%d+)") -- captures digits after "number is "
**Usage:**
- Use print() to output intermediate values for debugging
- Use return to provide final results
- Access any global variables that have been set by the application
- Leverage Lua for data processing - it's fast and efficient even on large strings
**Example:**
x = 10
y = 20
print("Computing sum...")
return x + y
**Output Truncation:**
- Output and result are automatically truncated to 50,000 characters by default
- Truncated values end with "...\n(output truncated)"
- This prevents extremely large outputs from overwhelming the conversation context
"#;
pub const PARAM_SOURCE_CODE: &str = "source_code";
pub const PARAM_SOURCE_CODE_DESC: &str =
"Lua source code to execute in the sandboxed REPL environment";
#[cfg(feature = "json_schema")]
pub fn json_schema() -> serde_json::Value {
serde_json::json!({
"type": "object",
"properties": {
PARAM_SOURCE_CODE: {
"type": "string",
"description": PARAM_SOURCE_CODE_DESC
}
},
"required": [PARAM_SOURCE_CODE]
})
}