No description
  • Rust 92.7%
  • Shell 7%
  • Makefile 0.3%
Find a file
Timur Gordon fdb8a22734
Some checks failed
Lint / lint-linux (push) Failing after 3s
Tests / test-linux (push) Failing after 36s
Fix Rhai engine operation limits causing script failures (#8)
Root cause: os_rhai profiling module registration was calling
configure_engine_security() which set max_operations to 10,000 on the
shared hero_do engine, causing scripts to fail at ~158 repo iterations.

- Remove security config overrides from profiling module registration
  (module registration should only register types/functions, not modify
  global engine settings)
- Add centralized configure_engine_limits() to hero_do (both main.rs
  and lib.rs), called AFTER all module registrations to prevent any
  module from overriding limits
- Set all limits to 0 (unlimited) for general-purpose scripting
- Make security functions public for opt-in sandboxed execution
- Remove leftover debug eprintln statements from lib.rs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 13:04:36 +02:00
.forgejo/workflows feat: add Forgejo CI/CD workflows with hero_do build support 2026-03-20 19:03:40 +01:00
crates Fix Rhai engine operation limits causing script failures (#8) 2026-04-06 13:04:36 +02:00
docs/rhai feat: initial Rhai scripting workspace migrated from hero_lib 2026-03-20 18:38:57 +01:00
examples add built-in scheduler, fix run() relative path resolution, expand README 2026-03-23 20:54:42 +01:00
installers feat: initial Rhai scripting workspace migrated from hero_lib 2026-03-20 18:38:57 +01:00
scripts feat: add Forgejo CI/CD workflows with hero_do build support 2026-03-20 19:03:40 +01:00
.gitignore cleanup rhai 2026-03-20 19:00:21 +01:00
build_herodo.sh cleanup rhai 2026-03-20 19:00:21 +01:00
Cargo.lock feat: add tools_rhai crate with Rhai bindings for herolib_tools 2026-03-26 07:33:50 +01:00
Cargo.toml feat: add tools_rhai crate with Rhai bindings for herolib_tools 2026-03-26 07:33:50 +01:00
ci_rhai.sh feat: initial Rhai scripting workspace migrated from hero_lib 2026-03-20 18:38:57 +01:00
CLAUDE.md feat: initial Rhai scripting workspace migrated from hero_lib 2026-03-20 18:38:57 +01:00
Makefile cleanup rhai 2026-03-20 19:00:21 +01:00
README.md add built-in scheduler, fix run() relative path resolution, expand README 2026-03-23 20:54:42 +01:00

hero_lib_rhai

Rhai scripting bindings for the herolib libraries. Each crate in crates/*_rhai exposes a corresponding herolib module as a Rhai namespace. The hero_do binary embeds the Rhai engine and loads all modules, giving you a scriptable CLI for the entire herolib ecosystem.


hero_do

Build

Always use the provided script — do not use cargo build directly:

./build_herodo.sh

Run a script

hero_do my_script.rhai
hero_do examples/scheduler/01_basic.rhai

Shebang support

Make any .rhai file directly executable:

#!/usr/bin/env hero_do

print("Hello from hero_do!");
chmod +x my_script.rhai
./my_script.rhai

Available modules

Module Description
herolib-core Text processing, networking, HeroScript
herolib-os OS operations, process management, git, virtualisation
herolib-crypt Encryption and key management
herolib-clients Redis, PostgreSQL, MQTT, Mycelium, Hetzner
herolib-ai AI client (Groq, OpenRouter, SambaNova)
herolib-vault Secret vault management
herolib-code Rust builder utilities
herolib-mos MOS module
herolib-virt Virtualisation
herolib-proc Process supervisor (hero_proc): services, jobs, logs

Import system

hero_do extends Rhai's import statement to support local files, directories, HTTP URLs, and a GitHub shorthand.

import "lib/math"                           as m;  // local file (no extension needed)
import "lib"                                as l;  // whole directory — all .rhai files merged
import "https://example.com/utils"          as u;  // HTTPS URL
import "github:user/repo/scripts/helpers"   as h;  // GitHub raw shorthand

Relative paths resolve relative to the calling script's location. HTTP and GitHub results are cached for the engine session.

Directory imports

When you import a directory, all .rhai files inside are sorted alphabetically, merged, and exposed as a single namespace.


run()

run() executes another script in full (with its own scope), unlike import which loads a namespace.

run("other.rhai");                       // relative to calling script
run("https://example.com/setup.rhai");   // from HTTP
run("github:myorg/repo/scripts/setup");  // from GitHub

Built-in scheduler

Register tasks at any interval; the scheduler checks every 50 ms.

every(30, "sec",  || { print("every 30 seconds"); });
every(5,  "min",  || { print("every 5 minutes");  });
every(1,  "hour", || { print("every hour");        });
every(500,"ms",   || { print("every 500 ms");      });

scheduler_run();           // block forever (Ctrl+C to stop)
scheduler_run_for(60);     // block for 60 seconds then return
scheduler_stop();          // stop from inside a task

Time units accepted: ms / millisecond / milliseconds, s / sec / second / seconds, m / min / minute / minutes, h / hour / hours.

Tasks run immediately on the first tick, then repeat at the given interval. Closures capture variables by reference, so state persists across ticks.


Workspace crate layout

crates/
  core_rhai/      — Rhai bindings for herolib_core
  os_rhai/        — Rhai bindings for herolib_os
  crypt_rhai/     — Rhai bindings for herolib_crypt
  vault_rhai/     — Rhai bindings for herolib_vault
  ai_rhai/        — Rhai bindings for herolib_ai
  clients_rhai/   — Rhai bindings for herolib_clients
  code_rhai/      — Rhai bindings for herolib_code
  mos_rhai/       — Rhai bindings for herolib_mos
  virt_rhai/      — Rhai bindings for herolib_virt
  proc_rhai/      — Rhai bindings for hero_proc (process supervisor)
  hero_do/        — CLI binary embedding the Rhai engine

Examples

See examples/ for runnable scripts covering imports, scheduling, and process supervision.