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
.rhaiscript files - Directory Execution: Execute all
.rhaiscripts 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
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:
Usage
Execute a Single Script
Execute All Scripts in a Directory
When given a directory, herodo will:
- Recursively find all
.rhaifiles - Sort them alphabetically
- Execute them in order
- Stop on the first error
Example Scripts
Basic Script
// hello.rhai
print("Hello from Herodo!");
let result = 42 * 2;
print(`Result: ${result}`);
AI Chat
// 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
// 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
// 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 modelai_chat_with_model(model, prompt)- Chat with specific modelai_chat_with_system(model, system, prompt)- Chat with system messageai_models()- List available chat modelsai_embed(text)- Generate text embeddingai_embed_batch(texts)- Batch embeddingsai_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 keypairkeypair_sign(keypair, message)- Sign messageskeypair_verify(pubkey, message, signature)- Verify signatures- Symmetric encryption with ChaCha20-Poly1305
OS (herolib-os)
exist(path)- Check file existencemkdir(path)- Create directoriesdelete(path)- Delete files/directoriesdownload(url, dest)- Download filesrun(cmd)- Execute system commands- Git operations, SSH, process management
Clients (herolib-clients)
redis_set(key, value)- Redis operationsredis_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:
Enable detailed logging:
RUST_LOG=debug
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:
License
Apache-2.0