Hero Script tab: show bundled example scripts from examples/rhai/ #31

Closed
opened 2026-03-31 07:30:54 +00:00 by timur · 1 comment
Owner

Problem

The hero_proc repo ships example Rhai scripts in examples/rhai/ — these are ready-to-use install_and_run.rhai scripts for each Hero service (hero_runner, hero_proxy, hero_aibroker, hero_os, etc.). However, the Hero Script tab in the UI only shows scripts from ~/hero/cfg/proc/ (user scripts). There is no way for users to discover or browse the bundled examples from the UI.

Currently the only workaround is to manually symlink the example scripts into ~/hero/cfg/proc/, which only works for the local machine and doesn't scale.

Proposed Solution

Make the Hero Script tab aware of two script sources:

  1. User scripts~/hero/cfg/proc/ (current behavior, read-write)
  2. Example scriptsexamples/rhai/ from the hero_proc repo (read-only, bundled)

UI Requirements

  • Show example scripts in the file tree, visually distinct from user scripts (e.g., different icon, dimmed style, or a separate tree section labeled "Examples")
  • Example scripts should be read-only in the editor (no save/delete)
  • Example scripts should still be runnable (the Run button should work)
  • Optionally: a "Copy to My Scripts" action that copies an example into ~/hero/cfg/proc/ so the user can customize it

Backend Requirements

  • The script.list RPC method needs to return both sources, with a flag indicating which source each script comes from (e.g., "source": "examples" vs "source": "user")
  • The script.get RPC method needs to resolve paths from both roots
  • The script.set and script.delete methods must reject writes to the examples tree
  • The script.run method should work for both sources
  • The examples path could be:
    • Relative to the binary: ../examples/rhai/ (works for dev builds)
    • Configurable via env var or config (e.g., HERO_PROC_EXAMPLES_DIR)
    • Or embedded at compile time

Current Example Scripts

examples/rhai/
  hero_runner/install_and_run.rhai
  hero_proxy/install_and_run.rhai
  hero_aibroker/install_and_run.rhai
  hero_os/install_and_run.rhai

More will be added as services are migrated (issue #29).

Context

This is part of the broader effort to make Rhai scripts the standard way to manage Hero service lifecycle (issue #29). Having the examples discoverable in the UI makes it much easier for users to get started.

## Problem The `hero_proc` repo ships example Rhai scripts in `examples/rhai/` — these are ready-to-use `install_and_run.rhai` scripts for each Hero service (hero_runner, hero_proxy, hero_aibroker, hero_os, etc.). However, the Hero Script tab in the UI only shows scripts from `~/hero/cfg/proc/` (user scripts). There is no way for users to discover or browse the bundled examples from the UI. Currently the only workaround is to manually symlink the example scripts into `~/hero/cfg/proc/`, which only works for the local machine and doesn't scale. ## Proposed Solution Make the Hero Script tab aware of two script sources: 1. **User scripts** — `~/hero/cfg/proc/` (current behavior, read-write) 2. **Example scripts** — `examples/rhai/` from the hero_proc repo (read-only, bundled) ### UI Requirements - Show example scripts in the file tree, visually distinct from user scripts (e.g., different icon, dimmed style, or a separate tree section labeled "Examples") - Example scripts should be **read-only** in the editor (no save/delete) - Example scripts should still be **runnable** (the Run button should work) - Optionally: a "Copy to My Scripts" action that copies an example into `~/hero/cfg/proc/` so the user can customize it ### Backend Requirements - The `script.list` RPC method needs to return both sources, with a flag indicating which source each script comes from (e.g., `"source": "examples"` vs `"source": "user"`) - The `script.get` RPC method needs to resolve paths from both roots - The `script.set` and `script.delete` methods must reject writes to the examples tree - The `script.run` method should work for both sources - The examples path could be: - Relative to the binary: `../examples/rhai/` (works for dev builds) - Configurable via env var or config (e.g., `HERO_PROC_EXAMPLES_DIR`) - Or embedded at compile time ### Current Example Scripts ``` examples/rhai/ hero_runner/install_and_run.rhai hero_proxy/install_and_run.rhai hero_aibroker/install_and_run.rhai hero_os/install_and_run.rhai ``` More will be added as services are migrated (issue #29). ## Context This is part of the broader effort to make Rhai scripts the standard way to manage Hero service lifecycle (issue #29). Having the examples discoverable in the UI makes it much easier for users to get started.
Author
Owner

Implemented in commit d807672 on development.

Changes

Backend (hero_proc_server)

  • Added examples_root() — locates bundled examples/rhai/ via HERO_PROC_EXAMPLES_DIR env var or by walking ancestors of the executable
  • script.list now returns scripts from both user and examples directories, each tagged with "source": "user" or "source": "example"
  • script.get / script.run accept optional source param to resolve from either root
  • script.set / script.delete reject writes to example scripts ("read-only")

OpenRPC spec

  • Added source field to list items and optional source param to get/set/delete/run methods

UI

  • Two-section tree: "My Scripts" (read-write) and "Examples" (read-only, dimmed)
  • Example files open in read-only mode with a READ-ONLY badge
  • Examples are still runnable via Run button or context menu
  • "Copy to My Scripts" action in example context menu
  • Context menu for examples: Run, Download, Copy to My Scripts (no Rename/Delete)
  • Graceful fallback: if no examples directory found, only "My Scripts" section shown
Implemented in commit d807672 on `development`. ## Changes ### Backend (`hero_proc_server`) - Added `examples_root()` — locates bundled `examples/rhai/` via `HERO_PROC_EXAMPLES_DIR` env var or by walking ancestors of the executable - `script.list` now returns scripts from both user and examples directories, each tagged with `"source": "user"` or `"source": "example"` - `script.get` / `script.run` accept optional `source` param to resolve from either root - `script.set` / `script.delete` reject writes to example scripts ("read-only") ### OpenRPC spec - Added `source` field to list items and optional `source` param to get/set/delete/run methods ### UI - **Two-section tree**: "My Scripts" (read-write) and "Examples" (read-only, dimmed) - Example files open in **read-only** mode with a READ-ONLY badge - Examples are still **runnable** via Run button or context menu - **"Copy to My Scripts"** action in example context menu - Context menu for examples: Run, Download, Copy to My Scripts (no Rename/Delete) - Graceful fallback: if no examples directory found, only "My Scripts" section shown
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_proc#31
No description provided.