Add Rhai script for installing, building, and running hero_runner_v2 #29
Labels
No labels
prio_critical
prio_low
type_bug
type_contact
type_issue
type_lead
type_question
type_story
type_task
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lhumina_code/hero_proc#29
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Create a Rhai script that automates the full lifecycle of
hero_runner_v2— cloning the repository, building it, installing the binaries, and running the service viahero_proc.Context
hero_prochas a Hero Script tab in the web UI that allows writing, managing, and executing.rhaiscripts from~/hero/cfg/proc/.hero_lib_rhaiprovides comprehensive Rhai bindings for git operations (git_tree_new,get_path,clone_repo_pull), process execution (run/execute), file system operations, and Rust project building (rust_builder_from).hero_runner_v2(athttps://forge.ourworld.tf/lhumina_code/hero_runner_v2) is a Rhai+Python script execution engine with server, UI, and SDK crates. It integrates withhero_procfor service lifecycle management.Requirements
hero_runner_v2repository using existing Rhai git functions (e.g.,git_tree_new+get_pathorclone_repo_pull).rust_builder_from()or by invokingmake build/cargo build --release.hero_runner,hero_runner_server,hero_runner_ui) to~/hero/bin/.hero_proc(the server and UI daemons).~/hero/cfg/proc/(or in the repo'sexamples/rhai/for reference) so it can be run from the Hero Script tab in the hero_proc dashboard.Acceptance Criteria
hero_runner_v2from forge (development branch)~/hero/bin/hero_runner_serverandhero_runner_uias hero_proc services with health checkshero_lib_rhai(git, process, os, optionally rust_builder)Research Findings & Implementation Notes
I've explored
hero_proc,hero_lib_rhai, andhero_runner_v2in depth. Here's my understanding and open questions.What I understand
hero_runner_v2 architecture:
hero_runner(CLI),hero_runner_server(daemon),hero_runner_ui(web dashboard),hero_runner_sdk,hero_runner_lib,hero_runner_integration_testhero_proc_sdkto register server + UI as hero_proc services, then--start/--stopmanages them~/hero/var/sockets/hero_runner_server.sock~/hero/var/sockets/hero_runner_ui.sockhero_runner,hero_runner_server,hero_runner_uiAvailable Rhai API for this task:
git_tree_new(path)→.get_path(url)or.clone_repo_pull(url)rust_builder_from(path).release().all_bins().copy_to_hero_bin().build()code_rhaicrate. Or fallback torun("make build").execute()copy_bin(src)or file copy to~/hero/bin/rust_builderhas.copy_to_hero_bin()hero_procRhai module:z.service_new().name(...).exec(...).register()hero_runner --startwhich does registration internallytcp_check()or service status via hero_proc SDKProposed script flow:
Open Questions
Build approach —
rust_buildervsmake build?rust_builder_from()gives us native Rhai integration with.copy_to_hero_bin(). Buthero_runner_v2has aMakefilewithmake installthat handles the full flow (build + copy to~/hero/bin). Which is preferred?rust_builderhandle workspace builds correctly (building all 3 binaries)?Service registration —
hero_runner --startvs manual?hero_runner --startalready useshero_proc_sdkto register both server and UI with proper health checks, restart policies, and dependency ordering. Running this seems simpler and more maintainable than duplicating the registration logic in Rhai.hero_runner --startafter building, or should we manually register services for more visibility/control?Git clone location — where should the repo live?
git_tree_new("~/hero/code")would put it at~/hero/code/forge.ourworld.tf/lhumina_code/hero_runner_v2/~/code/forge.ourworld.tf/lhumina_code/hero_runner_v2)?CODEROOTconvention?Script location —
examples/rhai/or~/hero/cfg/proc/?examples/rhai/hero_runner/install.rhai?~/hero/cfg/proc/for the Hero Script tab?Branch — should the script clone
developmentormain?hero_runner_v2usesdevelopmentas the default/active branch. Should we hardcode this or make it configurable?Dependencies — does hero_runner_v2 need hero_proc running first?
hero_runner --starttalks to hero_proc to register services, hero_proc_server must already be running. Is it safe to assume this when the script runs from the Hero Script tab (which implies hero_proc is already up)?Waiting for guidance on these questions before creating the implementation plan.
Keep in mind the actual purpose of this issue is to have a POC for running services via heroscripts. Once this works we will add more.
Q&A:
what would also be cool, and necessary for the future, since this is a paradigm shift from using the make file and binary to manage server and ui lifecycle to using rhai scripts on hero_proc, is if we had a scripts dir in hero_runner_v2 with rhai scripts for installing, building running etc, and if the make commands actually used hero_proc client to simply post these to hero_proc to manage the lifecycle and installation and building of services
Implementation Complete
Created
examples/rhai/hero_runner/install_and_run.rhaiwith the following flow:git_tree_new(~/hero/code)+clone_repo_full()withdevelopmentbranch, reset + pull (idempotent)rust_builder_from().release().all_bins().copy_to_hero_bin().build()(native Rhai, no Makefile)hero_procRhai API with restart policies, env vars, and ordering (hero_runner_uistarts afterhero_runner_server)The script is idempotent: re-running stops existing services, pulls latest code, rebuilds, and restarts.
Decisions made per Q&A:
rust_buildernative Rhai (no make/cargo shell commands)hero_runner --start)~/hero/code/(hero code root)examples/rhai/hero_runner/in hero_proc repodevelopmentbranch hardcodedReady for review and testing.
Testing Complete — Script Works End-to-End ✅
Commit
66b1e4b— script fully tested and working.Issues Found & Fixed
run()is overridden by hero_do — hero_do'smain.rsregisters a customrun(path)that treats the argument as a script file path (callsfetch_content()→fs::read_to_string). This shadows the process module'srun()builder. Fix: useexecute()instead, which is an alias that isn't overridden.rust_builder_from().all_bins().copy_to_hero_bin().build()— the build itself succeeds (exit code 0) but artifact discovery throws an error. Fix: useexecute("cargo build --release").execute()+ manualcopy()+chmod_exec().hero_proc.log_level(2).connect()— this API doesn't exist. The real API fromherolib_proc_rhaiisproc_client().log_level(2).connect(). Fix: updated to correct API.hero_runner_v2 has no
developmentbranch — onlymain. Fix: hardcodedBRANCH = "main".quick_service_deletethrows on first run — when services don't exist yet. Fix: wrapped stop/delete intry {} catch {}for idempotency.Status shows
inactiveimmediately after start — services need time to initialize. Fix: addedsleep(2000)before status check.Test Output (second run — proves idempotency)
Key Learnings for the Paradigm
execute()notrun()— this is a gotcha in hero_do; should be documentedproc_client()nothero_proc— the Rhai entry point for hero_proc SDKquick_service_*methods are the simplest path for exec-based servicesokay, can we now experiment with using the same paradigm for running rhai scripts in repo via hero_proc as make cmds
Rhai Scripts as Make Command Replacements — Done
Commit
3afbaccin hero_runner_v2 — 8 Rhai scripts inscripts/rhai/that mirror Makefile targets.Scripts
build.rhaimake buildinstall.rhaimake installrun.rhaimake runstop.rhaimake stoprestart.rhaimake restartstatus.rhaimake statustest.rhaimake testclean.rhaimake cleanUsage
Key Pattern
Each script is self-contained and uses:
execute(cmd).execute()for cargo commandsproc_client().log_level(2).connect()for hero_procquick_service_set_full()/start()/stop()for service lifecyclecopy()+chmod_exec()for binary installationAll scripts are idempotent and work from the repo root directory.
and could the lifecycle management be replace with this, and the make cmds run these, so we have a unified way of performing these operations? Also, dont we have rhai functionality to install build etc that we can use? i see everything is manual cmd executions
Updated: Native Rhai Functions + Makefile Integration
Changes
hero_runner_v2 (
8e1b621):rust_builder_from(path).release().bin(name).copy_to_hero_bin().build()instead ofexecute("cargo build ...")build,install,run,stop,restart,status,test,clean) now callhero_do scripts/rhai/*.rhaihero_proc (
745e980):install_and_run.rhaialso updated to userust_builderWhat's Native vs Shell
rust_builder_from().release().bin().build()rust_builder...copy_to_hero_bin().build()proc_client().quick_service_start/stop()proc_client().quick_service_set_full()proc_client().quick_service_status()git_tree_new().clone_repo_full()copy(),chmod_exec(),exist(),ensure_dir()execute("cargo test")execute("cargo clean")Unified Flow
Same scripts work from:
make run)hero_do scripts/rhai/run.rhai)Note on rust_builder workspace bug
rust_builder_from(workspace).all_bins()fails because workspace root Cargo.toml has no[[bin]]entries — artifact discovery looks at workspace metadata only, not member crates. Workaround: use.bin("name")per binary. This should be fixed in hero_lib.Service Lifecycle Audit — All lhumina_code Repos
Analyzed all 25 repos under
lhumina_code/. Here's how each service currently manages its lifecycle and what needs to change.Current State
make run--starthero_aibroker --start--starthero_auth --startscripts/run-services.sh--starthero_browser --startcargo run &--starthero_embedder --start--starthero_foundry --start--starthero_inspector --start./heroledger--starthero_os --start--starthero_osis --start--starthero_proxy --start--starthero_redis --starthero_do scripts/rhai/run.rhai--starthero_shrimp --start--starthero_voice --startdx serveTarget State
All Rust services should follow the hero_runner_v2 pattern:
scripts/rhai/in each repo — build.rhai, install.rhai, run.rhai, stop.rhai, restart.rhai, status.rhai, test.rhai, clean.rhaimake run→hero_do scripts/rhai/run.rhaiexamples/rhai/<service>/install_and_run.rhai— external install script (clone + build + register + start)--start/--stopbinary flags — Rhai scripts handle registration directly viaproc_client()Priority Order for Migration
Phase 1 — Core services (used by other services):
Phase 2 — Active development services:
4. hero_inspector
5. hero_embedder
6. hero_fossil
7. hero_books
Phase 3 — Remaining services:
8. hero_aibroker
9. hero_auth
10. hero_cloud
11. hero_compute_manager
12. hero_proxy
13. hero_redis
14. hero_voice
15. hero_services
16. hero_browser_mcp
Phase 4 — Special cases:
17. hero_os (platform-specific)
18. hero_ledger (has extensive Rhai already)
19. hero_shrimp (Node/TS, not Rust)
20. hero_archipelagos (WASM/Dioxus)
Related Issues
Cleanup: Removed accidentally re-introduced files
Commit
20e4e74fixes the issue Jan raised.What happened
Commit
aa3fe74("Add Rhai script to install, build, and run hero_runner_v2") accidentally re-introduced 61 files that had been deliberately removed by previous commits. These were staged in the working tree from a prior Claude Code session and got bundled into the commit.Files removed
crates/hero_proc_pid1/(entire crate + sysvol)a8b7692tests/integration/tests/pid1_behavior.rsa8b7692INSTRUCTIONS.md(TTY integration)49a6ff0.forgejo/workflows/build-macos.yaml0766bfeexamples/rhai/git,hero_proc,net,os,process,rsync,ssh/)bfc7994examples/rust/multiple_process_filters.rse042636examples/scripts/01-list.rhai,02-status.rhaibfc7994What remains
Only the legitimate work from this issue:
examples/rhai/hero_runner/install_and_run.rhai— hero_runner_v2 lifecycle scriptexamples/rhai/hero_proxy/install_and_run.rhai— hero_proxy lifecycle scriptPrevention
Will be more careful with
git addin future — staging specific files only, not relying on what's already staged from previous sessions.hero_aibroker — Rhai Lifecycle Scripts Done ✅
hero_proc (
30f7c02)examples/rhai/hero_aibroker/install_and_run.rhai— clone, build, install, start from scratchhero_aibroker (
7ff9053)scripts/rhai/(build, install, run, stop, restart, status, test, clean)hero_do scripts/rhai/*.rhairust_builderfor all builds,proc_client()for service managementmodelsconfig.ymlto~/hero/var/hero_aibroker/Services (3)
Migration Progress
hero_os — Rhai Lifecycle Scripts Done ✅
This was the complex one — hero_os has a Dioxus WASM frontend in addition to server binaries.
hero_proc (
acc234e)examples/rhai/hero_os/install_and_run.rhairust_builderdx build(285 crates compiled to WASM)~/hero/share/hero_os/public/via rsynchero_os (
d64147c)scripts/rhai/(one extra:build-wasm.rhaifor standalone WASM builds)status.rhaialso shows WASM asset statusclean.rhaialso removestarget/dxdirectoryServices
Migration Progress
Reopening: Rhai scripts need refactoring to use proper service model
The existing install_and_run scripts (hero_runner, hero_proxy, hero_aibroker, hero_os) all use the same pattern:
This creates individual quick_services — each with 1 action and 1 run with 1 job. No dependencies between server and UI.
What needs to change
Each service group (e.g., hero_runner) should be registered as one service with multiple actions and inter-action dependencies:
Benefits
Scripts to update
examples/rhai/hero_runner/install_and_run.rhaiexamples/rhai/hero_proxy/install_and_run.rhaiexamples/rhai/hero_aibroker/install_and_run.rhaiexamples/rhai/hero_os/install_and_run.rhaiPrerequisite
Need to verify that
proc_process_action().depends_on()andproc.service_register()work correctly in Rhai before migrating. May also depend on the Workflow object discussion in a separate issue.Architecture note: Rhai scripts are the workflow layer
Per discussion on #33, we decided no Workflow object is needed in hero_proc. Rhai scripts already serve as the workflow/orchestration layer.
The separation:
depends_onfor intra-service orderingWhat the script refactoring should do
Replace
quick_service_set_full()per-binary with proper action+service registration:The Rhai script handles the build/install workflow. The service handles ongoing supervision.
depends_onhandles startup ordering within the service.Rhai scripts refactored to use hero_lib_rhai tools
All Rhai scripts (both in
hero_proc/examples/rhai/and in each service repo'sscripts/rhai/) have been updated to use the proper hero_lib_rhai functions instead of manual patterns:Changes
env_get("HOME") + "/hero/code"hero_init()→env.rootdir,env.coderootgit_tree_new() + clone_repo_full()forge_client()+forge.pull("org/repo")execute("which dx")checkensure_installed("dx")quick_service_set_full(svc, cmd, "exec", "")per binaryproc_process_action()+action_set()+service_register()Service model change
All scripts now use the proper service model: multiple actions grouped under one service.
hero_proxy_serverandhero_proxy_uias separate quick_serviceshero_proxyservice containinghero_proxy_server+hero_proxy_uiactionsThis applies to all 4 products (hero_runner, hero_proxy, hero_aibroker, hero_os).
Commits
6c59561— example scripts inexamples/rhai/73792b7—scripts/rhai/(run, stop, restart, status)383d733—scripts/rhai/(run, stop, restart, status, install)44286fe—scripts/rhai/(run, stop, restart, status, install)Remaining for this issue
scripts/rhai/folder (8 scripts) — not yet createddepends_on()method is not yet exposed in the Rhai SDK (only in Rust SDK), so action-level dependencies aren't set from RhaiThe consolidated
install_and_run_all.rhai(b6e8961) usesforge_client()+forge.pull()for all repo operations and serves as the reference example for the correct pattern.