# Herodo - Rhai Script Executor for HeroLib
Herodo is a command-line utility that executes Rhai scripts with full access to the HeroLib ecosystem. It provides a powerful scripting environment for automation, AI, system management, and infrastructure tasks.
## Features
- **Single Script Execution**: Execute individual `.rhai` script files
- **Directory Execution**: Execute all `.rhai` scripts in a directory (recursively)
- **Sorted Execution**: Scripts are executed in alphabetical order for predictable behavior
- **HeroLib Integration**: Full access to all HeroLib modules and functions
- **Error Handling**: Clear error messages and proper exit codes
- **Logging Support**: Built-in logging with `env_logger`
## Installation
### Build and Install
```bash
git clone https://github.com/herolib/herolib_rust
cd herolib_rust
./build.sh
```
This script will:
- Build herodo in debug mode
- Install it to `~/hero/bin/herodo` (non-root) or `/usr/local/bin/herodo` (root)
- Make it available in your PATH
**Note**: If using the non-root installation, make sure `~/hero/bin` is in your PATH:
```bash
export PATH="$HOME/hero/bin:$PATH"
```
## Usage
### Execute a Single Script
```bash
herodo path/to/script.rhai
```
### Execute All Scripts in a Directory
```bash
herodo path/to/scripts/
```
When given a directory, herodo will:
1. Recursively find all `.rhai` files
2. Sort them alphabetically
3. Execute them in order
4. Stop on the first error
## Example Scripts
### Basic Script
```rhai
// hello.rhai
print("Hello from Herodo!");
let result = 42 * 2;
print(`Result: ${result}`);
```
### AI Chat
```rhai
// ai_chat.rhai
// Requires GROQ_API_KEY, OPENROUTER_API_KEY, or SAMBANOVA_API_KEY
// List available models
let models = ai_models();
print("Available models:");
for model in models {
print(` - ${model}`);
}
// Simple chat
let response = ai_chat("What is the capital of France?");
print(response);
// Chat with specific model
let response = ai_chat_with_model("gpt_oss_120b", "Hello!");
print(response);
// Chat with system message
let response = ai_chat_with_system(
"llama3_3_70b",
"You are a helpful coding assistant.",
"Write a hello world in Rust"
);
print(response);
```
### System Operations
```rhai
// system_info.rhai
// Check if a file exists
let config_exists = exist("/etc/hosts");
print(`Config file exists: ${config_exists}`);
// Download a file
download("https://example.com/data.txt", "/tmp/data.txt");
print("File downloaded successfully");
// Execute a system command
let output = run("ls -la /tmp");
print("Directory listing:");
print(output.stdout);
```
### Redis Operations
```rhai
// redis_example.rhai
// Set a value
redis_set("app_status", "running");
print("Status set in Redis");
// Get the value
let status = redis_get("app_status");
print(`Current status: ${status}`);
```
## Available Modules
Herodo provides access to all HeroLib modules through Rhai:
### AI (`herolib-ai`)
- `ai_chat(prompt)` - Chat with default model
- `ai_chat_with_model(model, prompt)` - Chat with specific model
- `ai_chat_with_system(model, system, prompt)` - Chat with system message
- `ai_models()` - List available chat models
- `ai_embed(text)` - Generate text embedding
- `ai_embed_batch(texts)` - Batch embeddings
- `ai_transcribe(file_path)` - Transcribe audio file
### Core (`herolib-core`)
- Text processing and manipulation
- HeroScript parsing and execution
- Network utilities
### Cryptography (`herolib-crypt`)
- `keypair_new()` - Generate Ed25519 keypair
- `keypair_sign(keypair, message)` - Sign messages
- `keypair_verify(pubkey, message, signature)` - Verify signatures
- Symmetric encryption with ChaCha20-Poly1305
### OS (`herolib-os`)
- `exist(path)` - Check file existence
- `mkdir(path)` - Create directories
- `delete(path)` - Delete files/directories
- `download(url, dest)` - Download files
- `run(cmd)` - Execute system commands
- Git operations, SSH, process management
### Clients (`herolib-clients`)
- `redis_set(key, value)` - Redis operations
- `redis_get(key)` - Get Redis values
- PostgreSQL, MQTT, Mycelium clients
### Virtualization (`herolib-virt`)
- Buildah container building
- Nerdctl container management
- QEMU/KVM operations
### MOS (`herolib-mos`)
- Network namespace management
- Bridge and veth pair operations
- System profiling
## Environment Variables
Set API keys for AI providers:
```bash
export GROQ_API_KEY="your-groq-key"
export OPENROUTER_API_KEY="your-openrouter-key"
export SAMBANOVA_API_KEY="your-sambanova-key"
```
Enable detailed logging:
```bash
RUST_LOG=debug herodo script.rhai
```
## Error Handling
Herodo provides clear error messages and appropriate exit codes:
- **Exit Code 0**: All scripts executed successfully
- **Exit Code 1**: Error occurred (file not found, script error, etc.)
## Testing
Run the test suite:
```bash
cd packages/herodo
cargo test
```
## License
Apache-2.0