- Rust 86%
- Shell 5.9%
- JavaScript 3.9%
- HTML 2%
- CSS 2%
- Other 0.2%
s121 / hero_proc#102 D-10 sweep T2 — fifth and final wholesale repo before hero_os + hero_osis. Closes the AI-rename + canonical-base migration arc on the Rhai workspace. Service.toml (5 new files): - crates/hero_runner_rhai/service.toml (kind=cli, 3-binary manifest) - crates/hero_runner_rhai_server/service.toml (kind=server, rpc.sock openrpc+sse) - crates/hero_runner_rhai_admin/service.toml (kind=admin, admin.sock http+webui) - crates/hero_do/service.toml (kind=cli, standalone Rhai runner) - crates/gpu_agent/service.toml (kind=server, [[binaries.tcp]] 0.0.0.0:9100) All ship `[[env]] PATH_ROOT default="~/hero"` per s107 lesson #17. service_base!() triad on all 5 main.rs — deleted ~280 LOC of hand-rolled print_info_json / print_startup_info / print_help, replaced by canonical herolib_core::base helpers (validate_service_toml + handle_info_flag + print_startup_banner + prepare_sockets). Lesson #19 (s109+): added `forward_env_if_set` in hero_runner_rhai CLI, threads PATH_ROOT/PATH_VAR/PATH_BUILD/PATH_CODE/HERO_SOCKET_DIR into both spawned ActionSpecs. Verified via /proc/$pid/environ on all CLI-spawned daemons (PATH_ROOT=/home/pctwo/hero across 6 server worker pids + admin). Lesson #21 (cascade-absorb deletion): hero_proc_sdk::HeroLogger removed at hero_proc tip 32af77cd. Resolution is shape 1 trivial collapse (not shape 3 as anticipated in §3 — HeroLogger is fully gone, nothing to thread). proc_log.rs::spawn_forwarder keeps its public signature so SessionManager / OpenRPC / SDK contracts stay intact; body collapses to a single warn-once log + immediate drop of broadcast subscription. forward_logs flag is inert pending re-migration to logs.insert RPC. proc_rhai cascade-absorb (pre-existing latent on origin/development): - job.rs:77+100 — JobLogsInput +attempt; JobLogsOutput.value unwrap_or_default(); LogLine.line is plain String - service.rs:120+301+355 + service_builder.rs:229 — ServiceSpec +probe +require_ready +sockets +tags Test fixture: sse_streaming.rs:103 — session_logs() 4th arg (limit) added. Dep audit (zero-match strips): - hero_runner_rhai: −serde_json - hero_runner_rhai_server: −tower - hero_runner_rhai_admin: −tower −futures −serde −serde_json −chrono −http-body-util −hyper-util - hero_do + gpu_agent: +herolib_core (new — service_base!() requirement) D-10 5/5 acceptance: 1. service.toml at each crate root ✓ (5) 2. service_base!() triad ✓ (5) 3. lab infocheck clean ✓ (5 crates, 0 findings) 4. Smoke 6/6 ✓ (server rpc.sock 4/4 + admin admin.sock 2/2) 5. cargo test --workspace --release ✓ 102/0/5 Effective coverage: 29 → 30/35 ≈ 86%. |
||
|---|---|---|
| .forgejo/workflows | ||
| crates | ||
| docs | ||
| examples | ||
| installers | ||
| scripts | ||
| .gitignore | ||
| apikeys.db | ||
| build_runner.sh | ||
| buildenv.sh | ||
| Cargo.toml | ||
| ci_rhai.sh | ||
| CLAUDE.md | ||
| list_old_issues.rhai | ||
| Makefile | ||
| README.md | ||
| request_logs.db | ||
| RHAI_LIMITS_INVESTIGATION.md | ||
| run_runner.sh | ||
| stop_runner.sh | ||
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/
ai_rhai/ — Rhai bindings for herolib_ai
clients_rhai/ — Rhai bindings for herolib_clients
code_rhai/ — Rhai bindings for herolib_code
core_rhai/ — Rhai bindings for herolib_core
crypt_rhai/ — Rhai bindings for herolib_crypt
gpu_agent/ — daemon binary run inside VastAI containers (see docs/gpu_agent.md)
hero_do/ — CLI binary embedding the Rhai engine
hero_runner_rhai/ — CLI lifecycle binary (--start/--stop, hero_proc registration)
hero_runner_rhai_server/ — Fork-based Rhai script runner with OpenRPC and SSE log streaming
hero_runner_rhai_admin/ — Web dashboard for the runner (Bootstrap 5, /rpc proxy, SSE)
mos_rhai/ — Rhai bindings for herolib_mos
os_rhai/ — Rhai bindings for herolib_os
proc_rhai/ — Rhai bindings for hero_proc (process supervisor)
vault_rhai/ — Rhai bindings for herolib_vault
virt_rhai/ — Rhai bindings for herolib_virt
Examples
See examples/ for runnable scripts covering imports, scheduling, and process supervision.
For the fork-based Rhai runner service (server + UI + lifecycle CLI), see docs/hero_runner_rhai.md.