Hero Script Admin Panel #24

Closed
opened 2026-03-22 09:26:51 +00:00 by despiegk · 4 comments
Owner

Hero Script Admin Panel

1. Overview

Add a new admin tab:

Name: Hero Script

Purpose:

  • Manage and execute Rhai scripts
  • Sync scripts from the filesystem into Hero Proc actions
  • Provide editor, file browser, execution, and logs

2. File System Root

Root directory:

~/hero/cfg/proc/

This directory contains:

  • .rhai files
  • subdirectories
  • one .meta file for ~/hero/cfg/proc/

The filesystem is the source of truth.


3. Naming Rules

All directories and files must use:

  • lowercase only
  • snake_case only

Examples:

  • startup_tasks/
  • build_assets.rhai

Invalid examples:

  • StartupTasks/
  • BuildAssets.rhai
  • my-script.rhai

Scan-time normalization

When scanning a directory:

  • if a file or directory name is not lowercase snake_case, rename it automatically
  • the normalized name becomes the canonical name used by the system

Examples:

  • MyScript.rhaimy_script.rhai
  • Build-Jobsbuild_jobs

This guarantees:

  • stable action naming
  • predictable paths
  • no duplicate logical names caused by casing differences

4. UI Layout

Left panel: file explorer

Tree view of the root directory.

Features:

  • create file
  • create folder
  • upload
  • download
  • rename
  • delete
  • right-click context menu

Main panel: editor + logs

Left side: editor

  • opens selected .rhai file
  • syntax highlighting for Rhai
  • save button
  • run button

Right side: logs

  • live execution output
  • auto-refresh
  • scrollable
  • tied to the current job/run

5. Script Metadata

Metadata is embedded inside .rhai files using comment lines:

// META: interval:5
// META: disabled:false

These lines:

  • can appear anywhere in the file
  • are parsed during scan
  • define scheduling and execution behavior

Supported keys

  • interval: integer, in minutes
  • disabled: boolean

Example:

// META: interval:15
// META: disabled:false

If no interval exists:

  • script is manual only

If disabled:true:

  • not scheduled
  • still visible
  • still manually runnable

6. Execution

Single script run

When user clicks Run:

  • execute through Hero Proc SDK

  • equivalent behavior:

    hero_do <script_path>
    
  • create a Hero Proc job

  • stream logs to UI


Directory run

When user runs a directory:

  • traverse recursively
  • sort alphabetically
  • process folders and files deterministically
  • execute .rhai files one by one

Action / job naming

Each script maps to an action name:

startup.<relative_path_with_dots_without_extension>

Example:

  • file: network/init/setup.rhai
  • action: startup.network.init.setup

This makes it easy to trace script → action → job.


7. .meta File

  • track the known state of that directory
  • detect added, modified, deleted files and subdirectories
  • update Hero Proc actions incrementally

This avoids rebuilding all actions on every scan.


8. What .meta Stores

The .meta file stores a snapshot of the directory contents.

For each direct child entry in that directory, store:

  • name
  • type (file or dir)
  • normalized name
  • hash
  • relative path
  • last known action id or action name if relevant

For files

Hash should be based on:

  • file contents
  • normalized path

For directories

Hash should represent directory state, for example:

  • hash of child names + child hashes
  • or a stable derived hash from the subtree snapshot

This lets the scanner know whether a directory subtree changed.

10. Scan Algorithm

Scanner runs every 5 seconds.

For each directory:

Step 1: normalize names

  • rename invalid file/dir names to lowercase snake_case

Step 2: read current directory state

  • list children
  • calculate hashes
  • read existing .meta

Step 3: compare current state with .meta

Determine:

Added

Entry exists now, but not in .meta

Action:

  • create action(s)
  • for new .rhai file: parse metadata and register action
  • for new directory: recurse into it

Modified

Entry exists in both, but hash changed

Action:

  • for changed .rhai file: update action metadata and script binding
  • for changed directory: recurse and process subtree

Deleted

Entry exists in .meta, but not on disk

Action:

  • remove corresponding action(s)
  • remove related jobs if required
  • if deleted entry was a directory, remove all actions under that subtree

Unchanged

Entry exists in both and hash matches

Action:

  • do nothing

Step 4: write new .meta

After processing, rewrite .meta with the new known state.


11. Why .meta Exists

The .meta file gives each directory memory of its last scanned state.

That allows:

  • cheap diffing
  • incremental updates
  • precise add/change/delete detection
  • subtree-level invalidation
  • no need for full rebuild each scan

Without .meta, the system would need to:

  • rescan everything deeply
  • rebuild all actions more often
  • make deletes harder to detect cleanly

12. Action Update Rules

Added file

  • create new action
  • parse // META: lines
  • register schedule if interval exists

Modified file

  • update stored metadata
  • update schedule if interval changed
  • preserve history only if useful
  • optionally clear obsolete pending jobs tied to old definition

Deleted file

  • remove action
  • remove related jobs if configured

Added directory

  • create subtree actions by scanning recursively

Deleted directory

  • remove all actions and jobs for that subtree

13. Scheduling

Hero Proc uses parsed file metadata.

interval

If present:

  • run every N minutes

disabled

If true:

  • scheduler skips it
  • UI still shows it
  • manual run still allowed

14. Summary

  • /home/hero/cfg/proc/ is the source of truth
  • scripts use .rhai
  • all names are forced to lowercase snake_case
  • every directory has a .meta snapshot file
  • scanner compares disk state with .meta
  • only changed items are updated
  • Hero Proc actions are created, updated, or deleted from those diffs
# Hero Script Admin Panel ## 1. Overview Add a new admin tab: **Name:** `Hero Script` Purpose: * Manage and execute **Rhai scripts** * Sync scripts from the filesystem into **Hero Proc actions** * Provide editor, file browser, execution, and logs --- ## 2. File System Root Root directory: ```text ~/hero/cfg/proc/ ``` This directory contains: * `.rhai` files * subdirectories * one `.meta` file for ~/hero/cfg/proc/ The filesystem is the source of truth. --- ## 3. Naming Rules All directories and files must use: * lowercase only * snake_case only Examples: * `startup_tasks/` * `build_assets.rhai` Invalid examples: * `StartupTasks/` * `BuildAssets.rhai` * `my-script.rhai` ### Scan-time normalization When scanning a directory: * if a file or directory name is not lowercase snake_case, rename it automatically * the normalized name becomes the canonical name used by the system Examples: * `MyScript.rhai` → `my_script.rhai` * `Build-Jobs` → `build_jobs` This guarantees: * stable action naming * predictable paths * no duplicate logical names caused by casing differences --- ## 4. UI Layout ## Left panel: file explorer Tree view of the root directory. Features: * create file * create folder * upload * download * rename * delete * right-click context menu --- ## Main panel: editor + logs ### Left side: editor * opens selected `.rhai` file * syntax highlighting for Rhai * save button * run button ### Right side: logs * live execution output * auto-refresh * scrollable * tied to the current job/run --- ## 5. Script Metadata Metadata is embedded inside `.rhai` files using comment lines: ```rhai // META: interval:5 // META: disabled:false ``` These lines: * can appear anywhere in the file * are parsed during scan * define scheduling and execution behavior ### Supported keys * `interval`: integer, in minutes * `disabled`: boolean Example: ```rhai // META: interval:15 // META: disabled:false ``` If no `interval` exists: * script is manual only If `disabled:true`: * not scheduled * still visible * still manually runnable --- ## 6. Execution ## Single script run When user clicks **Run**: * execute through Hero Proc SDK * equivalent behavior: ```text hero_do <script_path> ``` * create a Hero Proc job * stream logs to UI --- ## Directory run When user runs a directory: * traverse recursively * sort alphabetically * process folders and files deterministically * execute `.rhai` files one by one --- ## Action / job naming Each script maps to an action name: ```text startup.<relative_path_with_dots_without_extension> ``` Example: * file: `network/init/setup.rhai` * action: `startup.network.init.setup` This makes it easy to trace script → action → job. --- ## 7. `.meta` File * track the known state of that directory * detect added, modified, deleted files and subdirectories * update Hero Proc actions incrementally This avoids rebuilding all actions on every scan. --- ## 8. What `.meta` Stores The `.meta` file stores a snapshot of the directory contents. For each direct child entry in that directory, store: * name * type (`file` or `dir`) * normalized name * hash * relative path * last known action id or action name if relevant ### For files Hash should be based on: * file contents * normalized path ### For directories Hash should represent directory state, for example: * hash of child names + child hashes * or a stable derived hash from the subtree snapshot This lets the scanner know whether a directory subtree changed. --- ## 10. Scan Algorithm Scanner runs every **5 seconds**. For each directory: ### Step 1: normalize names * rename invalid file/dir names to lowercase snake_case ### Step 2: read current directory state * list children * calculate hashes * read existing `.meta` ### Step 3: compare current state with `.meta` Determine: #### Added Entry exists now, but not in `.meta` Action: * create action(s) * for new `.rhai` file: parse metadata and register action * for new directory: recurse into it #### Modified Entry exists in both, but hash changed Action: * for changed `.rhai` file: update action metadata and script binding * for changed directory: recurse and process subtree #### Deleted Entry exists in `.meta`, but not on disk Action: * remove corresponding action(s) * remove related jobs if required * if deleted entry was a directory, remove all actions under that subtree #### Unchanged Entry exists in both and hash matches Action: * do nothing ### Step 4: write new `.meta` After processing, rewrite `.meta` with the new known state. --- ## 11. Why `.meta` Exists The `.meta` file gives each directory memory of its last scanned state. That allows: * cheap diffing * incremental updates * precise add/change/delete detection * subtree-level invalidation * no need for full rebuild each scan Without `.meta`, the system would need to: * rescan everything deeply * rebuild all actions more often * make deletes harder to detect cleanly --- ## 12. Action Update Rules ## Added file * create new action * parse `// META:` lines * register schedule if interval exists ## Modified file * update stored metadata * update schedule if interval changed * preserve history only if useful * optionally clear obsolete pending jobs tied to old definition ## Deleted file * remove action * remove related jobs if configured ## Added directory * create subtree actions by scanning recursively ## Deleted directory * remove all actions and jobs for that subtree --- ## 13. Scheduling Hero Proc uses parsed file metadata. ### `interval` If present: * run every N minutes ### `disabled` If true: * scheduler skips it * UI still shows it * manual run still allowed --- ## 14. Summary * `/home/hero/cfg/proc/` is the source of truth * scripts use `.rhai` * all names are forced to lowercase snake_case * every directory has a `.meta` snapshot file * scanner compares disk state with `.meta` * only changed items are updated * Hero Proc actions are created, updated, or deleted from those diffs
Author
Owner

Implementation Spec for Issue #24 — Hero Script Admin Panel

Objective

Add a new "Hero Script" tab to the hero_proc_ui admin dashboard that provides a browser-based IDE for managing and executing Rhai scripts stored at ~/hero/cfg/proc/. The panel consists of a file explorer tree on the left and an editor+log view on the right. A background scanner in hero_proc_server watches the filesystem every 5 seconds, normalizes names to snake_case, and syncs .rhai files into hero_proc actions under the startup context. Scripts embed scheduling metadata as // META: comments. Manual and scheduled execution flows through the existing job.create / action RPC pipeline.


Requirements

  • A new Hero Script tab appears in the tab bar between Admin and Docs
  • Left panel is a file explorer tree rooted at ~/hero/cfg/proc/ with: create file, create folder, upload, download, rename, delete, right-click context menu
  • Main panel has a split view: left = code editor with Rhai syntax highlighting, save button, run button; right = live execution output
  • Execution output auto-refreshes by polling job.logs (same pattern used elsewhere) and is tied to the current job/run for the selected file
  • All new HTTP API routes are added to hero_proc_ui's routes.rs (filesystem CRUD, scan trigger)
  • A new background task in hero_proc_server scans ~/hero/cfg/proc/ every 5 seconds
  • Scanner reads // META: interval:N and // META: disabled:bool from each .rhai file
  • Scanner maintains a .meta JSON file per directory tracking file hash, relative path, and last known action name
  • Action naming convention: startup.<relative_path_with_dots_no_extension> (e.g. startup.tools.deploy)
  • Added file → action.set with interpreter: rhai, schedule_policy.interval_ms if interval META present
  • Modified file → update action script + schedule; disabled: true → remove schedule_policy
  • Deleted file → action.delete + cancel/purge associated jobs
  • Directory run: alphabetically traverse .rhai files recursively
  • Invalid filesystem names (not snake_case) are renamed before scanning
  • The editor's Save button writes content to the filesystem file; Run button executes via job.create
  • A hero_proc_server RPC method script.scan allows triggering a forced re-scan
  • Rhai syntax highlighting provided by reusing highlight.js with rust/javascript mode approximation

Files to Modify / Create

hero_proc_server (scanner + RPC)

File Action Purpose
crates/hero_proc_server/src/script_scanner.rs Create Background scanner task: normalize names, read .meta, diff filesystem vs .meta, call action CRUD
crates/hero_proc_server/src/lib.rs Modify pub mod script_scanner;
crates/hero_proc_server/src/main.rs Modify Spawn scanner task alongside scheduler
crates/hero_proc_server/src/rpc/mod.rs Modify Add script.* method dispatch
crates/hero_proc_server/src/rpc/script.rs Create RPC handlers: script.scan, script.list, script.get, script.set, script.delete, script.run
crates/hero_proc_server/openrpc.json Modify Add script.* method definitions

hero_proc_ui (routes + frontend)

File Action Purpose
crates/hero_proc_ui/src/routes.rs Modify Add filesystem API routes: read file, write file, list directory, create dir, rename, delete, upload, download
crates/hero_proc_ui/templates/index.html Modify Add tab-pane div for tab-heroscript with file tree + editor + log panel HTML
crates/hero_proc_ui/templates/base.html Modify Add tab button for Hero Script; add JS include
crates/hero_proc_ui/static/js/heroscript.js Create All JS for the tab: file tree rendering, editor state, save/run/execute, log polling
crates/hero_proc_ui/static/css/dashboard.css Modify Add .heroscript-* CSS classes for tree + editor split layout

Step-by-Step Implementation Plan

Step 1 — Define .meta format and scanner data types

File: crates/hero_proc_server/src/script_scanner.rs (create)

  • MetaEntry struct with: name, kind, rel_path, hash, action_name
  • normalize_name(s) → lowercase snake_case, rename on disk
  • hash_file(path) → SHA-256 / DefaultHasher hex
  • parse_meta_comments(content) → parse // META: key:value lines into ScriptMeta
  • load_dot_meta(dir) → deserialize .meta JSON
  • save_dot_meta(dir, entries) → serialize .meta JSON
  • Dependencies: none

Step 2 — Implement scan loop and action sync logic

File: crates/hero_proc_server/src/script_scanner.rs (continue)

  • ScriptScanner { db, cfg_root } struct
  • run() → tokio interval loop every 5 seconds
  • scan_dir(dir, rel_prefix) → normalize → compare .meta → Added/Modified/Deleted/Unchanged → upsert_action / delete_action_and_jobs → recurse subdirs → write .meta
  • Dependencies: Step 1

Step 3 — Wire scanner into main.rs

File: crates/hero_proc_server/src/main.rs, src/lib.rs

  • pub mod script_scanner;
  • tokio::spawn(Arc::clone(&scanner).run())
  • Dependencies: Step 2

Step 4 — Add script.* RPC handlers

Files: crates/hero_proc_server/src/rpc/script.rs (create), src/rpc/mod.rs (modify)

  • handle_scan, handle_list, handle_get, handle_set, handle_delete, handle_run
  • Wire into dispatch match
  • Dependencies: Step 2

Step 5 — Add script.* to OpenRPC spec

File: crates/hero_proc_server/openrpc.json

  • Add 6 method definitions + ScriptEntry schema
  • Dependencies: Step 4

Step 6 — Add filesystem API routes to hero_proc_ui

File: crates/hero_proc_ui/src/routes.rs

  • GET/POST/DELETE for file, mkdir, rename, download, upload via RPC proxy
  • Dependencies: Step 4

Step 7 — Add Hero Script tab HTML

Files: crates/hero_proc_ui/templates/index.html, templates/base.html

  • <div class="tab-pane" id="tab-heroscript"> with tree + editor + log split
  • Tab button in #main-tabs
  • JS include for heroscript.js
  • Dependencies: none (can run parallel with Steps 1-6)

Step 8 — Implement Hero Script frontend JavaScript

File: crates/hero_proc_ui/static/js/heroscript.js (create)

  • hsLoadTree, hsRenderTree, hsSelectFile, hsOpenFile
  • hsSave, hsRun, hsStartLogPoll, hsStopLogPoll, hsClearLog
  • hsCreateFile, hsCreateFolder, hsDelete, hsRename, hsDownload, hsUpload
  • hsShowContextMenu, hsInit, hsRefreshTree
  • Dependencies: Step 6, Step 7

Step 9 — Add CSS for Hero Script layout

File: crates/hero_proc_ui/static/css/dashboard.css

  • .heroscript-container, .heroscript-tree-panel, .heroscript-editor-panel, .heroscript-main-split, #hs-editor, .heroscript-log-output, .hs-tree-item etc.
  • Dependencies: Step 7

Step 10 — Wire tab into dashboard.js

File: crates/hero_proc_ui/static/js/dashboard.js

  • Add heroscript case to switchTab()
  • Add heroscript entry to tabLoaders map
  • Dependencies: Step 8

Acceptance Criteria

  • A "Hero Script" tab appears in the tab bar and is navigable
  • File explorer tree loads ~/hero/cfg/proc/ contents on tab open
  • Files and folders can be created, renamed, and deleted via the UI
  • Selecting a .rhai file loads its content into the editor
  • Save button writes editor content back to disk
  • Run button creates a hero_proc job and shows live output in the log panel
  • Log panel auto-scrolls and stops polling when job reaches terminal phase
  • Background scanner runs every 5 seconds and creates/updates/deletes actions in context startup
  • // META: interval:5 results in an action with schedule_policy.interval_ms = 300000
  • // META: disabled:true results in no schedule_policy on the action
  • Invalid names are renamed to snake_case before scanning
  • .meta file is written per directory after each scan
  • action.list with context: "startup" shows all synced Rhai scripts
  • script.scan RPC call triggers an immediate re-scan
  • Right-click context menu on tree items shows relevant actions
  • Upload and download work for .rhai files

Notes

Action naming: startup is a new context string. No schema migration needed — context_name column already exists.

Script execution: ActionSpec.script stores raw Rhai source. When interpreter: Rhai, the executor runs the script via the existing rhai execution path.

Editor MVP: Plain <textarea> for editing; highlight.js with rust mode for approximate Rhai syntax coloring. CodeMirror 6 can be added in a follow-up.

Security: All filesystem paths must be validated to stay within ~/hero/cfg/proc/. UI handlers must canonicalize and prefix-check all rel_path inputs.

Hash: DefaultHasher (non-cryptographic) is sufficient for change detection; avoids adding a dependency.

.meta format (JSON array per directory):

[
  { "name": "deploy", "kind": "file", "rel_path": "tools/deploy.rhai", "hash": "abc123", "action_name": "startup.tools.deploy" },
  { "name": "tools", "kind": "dir", "rel_path": "tools", "hash": "", "action_name": "" }
]
# Implementation Spec for Issue #24 — Hero Script Admin Panel ## Objective Add a new "Hero Script" tab to the hero_proc_ui admin dashboard that provides a browser-based IDE for managing and executing Rhai scripts stored at `~/hero/cfg/proc/`. The panel consists of a file explorer tree on the left and an editor+log view on the right. A background scanner in hero_proc_server watches the filesystem every 5 seconds, normalizes names to snake_case, and syncs `.rhai` files into hero_proc actions under the `startup` context. Scripts embed scheduling metadata as `// META:` comments. Manual and scheduled execution flows through the existing `job.create` / action RPC pipeline. --- ## Requirements - A new `Hero Script` tab appears in the tab bar between `Admin` and `Docs` - Left panel is a file explorer tree rooted at `~/hero/cfg/proc/` with: create file, create folder, upload, download, rename, delete, right-click context menu - Main panel has a split view: left = code editor with Rhai syntax highlighting, save button, run button; right = live execution output - Execution output auto-refreshes by polling `job.logs` (same pattern used elsewhere) and is tied to the current job/run for the selected file - All new HTTP API routes are added to hero_proc_ui's `routes.rs` (filesystem CRUD, scan trigger) - A new background task in hero_proc_server scans `~/hero/cfg/proc/` every 5 seconds - Scanner reads `// META: interval:N` and `// META: disabled:bool` from each `.rhai` file - Scanner maintains a `.meta` JSON file per directory tracking file hash, relative path, and last known action name - Action naming convention: `startup.<relative_path_with_dots_no_extension>` (e.g. `startup.tools.deploy`) - Added file → `action.set` with `interpreter: rhai`, `schedule_policy.interval_ms` if `interval` META present - Modified file → update action script + schedule; `disabled: true` → remove schedule_policy - Deleted file → `action.delete` + cancel/purge associated jobs - Directory run: alphabetically traverse `.rhai` files recursively - Invalid filesystem names (not snake_case) are renamed before scanning - The editor's Save button writes content to the filesystem file; Run button executes via `job.create` - A `hero_proc_server` RPC method `script.scan` allows triggering a forced re-scan - Rhai syntax highlighting provided by reusing highlight.js with rust/javascript mode approximation --- ## Files to Modify / Create ### hero_proc_server (scanner + RPC) | File | Action | Purpose | |------|--------|---------| | `crates/hero_proc_server/src/script_scanner.rs` | **Create** | Background scanner task: normalize names, read `.meta`, diff filesystem vs `.meta`, call action CRUD | | `crates/hero_proc_server/src/lib.rs` | **Modify** | `pub mod script_scanner;` | | `crates/hero_proc_server/src/main.rs` | **Modify** | Spawn scanner task alongside scheduler | | `crates/hero_proc_server/src/rpc/mod.rs` | **Modify** | Add `script.*` method dispatch | | `crates/hero_proc_server/src/rpc/script.rs` | **Create** | RPC handlers: `script.scan`, `script.list`, `script.get`, `script.set`, `script.delete`, `script.run` | | `crates/hero_proc_server/openrpc.json` | **Modify** | Add `script.*` method definitions | ### hero_proc_ui (routes + frontend) | File | Action | Purpose | |------|--------|---------| | `crates/hero_proc_ui/src/routes.rs` | **Modify** | Add filesystem API routes: read file, write file, list directory, create dir, rename, delete, upload, download | | `crates/hero_proc_ui/templates/index.html` | **Modify** | Add `tab-pane` div for `tab-heroscript` with file tree + editor + log panel HTML | | `crates/hero_proc_ui/templates/base.html` | **Modify** | Add tab button for `Hero Script`; add JS include | | `crates/hero_proc_ui/static/js/heroscript.js` | **Create** | All JS for the tab: file tree rendering, editor state, save/run/execute, log polling | | `crates/hero_proc_ui/static/css/dashboard.css` | **Modify** | Add `.heroscript-*` CSS classes for tree + editor split layout | --- ## Step-by-Step Implementation Plan ### Step 1 — Define `.meta` format and scanner data types **File:** `crates/hero_proc_server/src/script_scanner.rs` (create) - `MetaEntry` struct with: name, kind, rel_path, hash, action_name - `normalize_name(s)` → lowercase snake_case, rename on disk - `hash_file(path)` → SHA-256 / DefaultHasher hex - `parse_meta_comments(content)` → parse `// META: key:value` lines into `ScriptMeta` - `load_dot_meta(dir)` → deserialize `.meta` JSON - `save_dot_meta(dir, entries)` → serialize `.meta` JSON - Dependencies: none ### Step 2 — Implement scan loop and action sync logic **File:** `crates/hero_proc_server/src/script_scanner.rs` (continue) - `ScriptScanner { db, cfg_root }` struct - `run()` → tokio interval loop every 5 seconds - `scan_dir(dir, rel_prefix)` → normalize → compare `.meta` → Added/Modified/Deleted/Unchanged → `upsert_action` / `delete_action_and_jobs` → recurse subdirs → write `.meta` - Dependencies: Step 1 ### Step 3 — Wire scanner into main.rs **File:** `crates/hero_proc_server/src/main.rs`, `src/lib.rs` - `pub mod script_scanner;` - `tokio::spawn(Arc::clone(&scanner).run())` - Dependencies: Step 2 ### Step 4 — Add `script.*` RPC handlers **Files:** `crates/hero_proc_server/src/rpc/script.rs` (create), `src/rpc/mod.rs` (modify) - `handle_scan`, `handle_list`, `handle_get`, `handle_set`, `handle_delete`, `handle_run` - Wire into dispatch match - Dependencies: Step 2 ### Step 5 — Add `script.*` to OpenRPC spec **File:** `crates/hero_proc_server/openrpc.json` - Add 6 method definitions + `ScriptEntry` schema - Dependencies: Step 4 ### Step 6 — Add filesystem API routes to hero_proc_ui **File:** `crates/hero_proc_ui/src/routes.rs` - GET/POST/DELETE for file, mkdir, rename, download, upload via RPC proxy - Dependencies: Step 4 ### Step 7 — Add Hero Script tab HTML **Files:** `crates/hero_proc_ui/templates/index.html`, `templates/base.html` - `<div class="tab-pane" id="tab-heroscript">` with tree + editor + log split - Tab button in `#main-tabs` - JS include for `heroscript.js` - Dependencies: none (can run parallel with Steps 1-6) ### Step 8 — Implement Hero Script frontend JavaScript **File:** `crates/hero_proc_ui/static/js/heroscript.js` (create) - `hsLoadTree`, `hsRenderTree`, `hsSelectFile`, `hsOpenFile` - `hsSave`, `hsRun`, `hsStartLogPoll`, `hsStopLogPoll`, `hsClearLog` - `hsCreateFile`, `hsCreateFolder`, `hsDelete`, `hsRename`, `hsDownload`, `hsUpload` - `hsShowContextMenu`, `hsInit`, `hsRefreshTree` - Dependencies: Step 6, Step 7 ### Step 9 — Add CSS for Hero Script layout **File:** `crates/hero_proc_ui/static/css/dashboard.css` - `.heroscript-container`, `.heroscript-tree-panel`, `.heroscript-editor-panel`, `.heroscript-main-split`, `#hs-editor`, `.heroscript-log-output`, `.hs-tree-item` etc. - Dependencies: Step 7 ### Step 10 — Wire tab into dashboard.js **File:** `crates/hero_proc_ui/static/js/dashboard.js` - Add `heroscript` case to `switchTab()` - Add `heroscript` entry to `tabLoaders` map - Dependencies: Step 8 --- ## Acceptance Criteria - [ ] A "Hero Script" tab appears in the tab bar and is navigable - [ ] File explorer tree loads `~/hero/cfg/proc/` contents on tab open - [ ] Files and folders can be created, renamed, and deleted via the UI - [ ] Selecting a `.rhai` file loads its content into the editor - [ ] Save button writes editor content back to disk - [ ] Run button creates a hero_proc job and shows live output in the log panel - [ ] Log panel auto-scrolls and stops polling when job reaches terminal phase - [ ] Background scanner runs every 5 seconds and creates/updates/deletes actions in context `startup` - [ ] `// META: interval:5` results in an action with `schedule_policy.interval_ms = 300000` - [ ] `// META: disabled:true` results in no schedule_policy on the action - [ ] Invalid names are renamed to snake_case before scanning - [ ] `.meta` file is written per directory after each scan - [ ] `action.list` with `context: "startup"` shows all synced Rhai scripts - [ ] `script.scan` RPC call triggers an immediate re-scan - [ ] Right-click context menu on tree items shows relevant actions - [ ] Upload and download work for `.rhai` files --- ## Notes **Action naming:** `startup` is a new context string. No schema migration needed — `context_name` column already exists. **Script execution:** `ActionSpec.script` stores raw Rhai source. When `interpreter: Rhai`, the executor runs the script via the existing rhai execution path. **Editor MVP:** Plain `<textarea>` for editing; `highlight.js` with `rust` mode for approximate Rhai syntax coloring. CodeMirror 6 can be added in a follow-up. **Security:** All filesystem paths must be validated to stay within `~/hero/cfg/proc/`. UI handlers must canonicalize and prefix-check all `rel_path` inputs. **Hash:** `DefaultHasher` (non-cryptographic) is sufficient for change detection; avoids adding a dependency. **`.meta` format** (JSON array per directory): ```json [ { "name": "deploy", "kind": "file", "rel_path": "tools/deploy.rhai", "hash": "abc123", "action_name": "startup.tools.deploy" }, { "name": "tools", "kind": "dir", "rel_path": "tools", "hash": "", "action_name": "" } ] ```
Author
Owner

Build & Test Results

Build Status: SUCCESS

The project compiled successfully with cargo build. No compilation errors. Only minor warnings:

  • Unused import partition_path in db/logs/store.rs
  • Unused function shell_escape in tests/integration/src/fixtures.rs
  • Unused field timestamp in tests/stress.rs

Test Results: ALL PASSED

Test Suite Passed Failed Ignored
hero_proc_lib (unit) 156 0 1
hero_proc_server 55 0 0
hero_proc_sdk 18 0 0
integration tests (db, actions, jobs) 86 0 0
integration tests (scripts, services) 17 0 0
integration tests (logs) 16 0 2
integration tests (process, scheduler) 11 0 1
other suites ~40 0 ~14

Total: All test suites returned test result: ok — 0 failures across all suites.

Summary

Issue #24 (Hero Script Admin Panel) code builds and all tests pass cleanly. No compilation fixes were required.

## Build & Test Results ### Build Status: SUCCESS The project compiled successfully with `cargo build`. No compilation errors. Only minor warnings: - Unused import `partition_path` in `db/logs/store.rs` - Unused function `shell_escape` in `tests/integration/src/fixtures.rs` - Unused field `timestamp` in `tests/stress.rs` ### Test Results: ALL PASSED | Test Suite | Passed | Failed | Ignored | |---|---|---|---| | hero_proc_lib (unit) | 156 | 0 | 1 | | hero_proc_server | 55 | 0 | 0 | | hero_proc_sdk | 18 | 0 | 0 | | integration tests (db, actions, jobs) | 86 | 0 | 0 | | integration tests (scripts, services) | 17 | 0 | 0 | | integration tests (logs) | 16 | 0 | 2 | | integration tests (process, scheduler) | 11 | 0 | 1 | | other suites | ~40 | 0 | ~14 | **Total: All test suites returned `test result: ok` — 0 failures across all suites.** ### Summary Issue #24 (Hero Script Admin Panel) code builds and all tests pass cleanly. No compilation fixes were required.
Author
Owner

Implementation Complete — Hero Script Admin Panel

All 10 implementation steps have been completed. Build succeeds and all 399 tests pass.

Changes Made

hero_proc_server (backend scanner + RPC)

File Change
crates/hero_proc_server/src/script_scanner.rs New — Background scanner task running every 5 seconds: normalizes filenames to snake_case, diffs filesystem vs .meta files, creates/updates/deletes actions in context startup
crates/hero_proc_server/src/rpc/script.rs New — 6 RPC handlers: script.scan, script.list, script.get, script.set, script.delete, script.run
crates/hero_proc_server/src/rpc/mod.rs Modified — Added pub mod script; and 6 dispatch entries
crates/hero_proc_server/src/lib.rs Modified — Added pub mod script_scanner;
crates/hero_proc_server/src/main.rs Modified — Spawns scanner task alongside scheduler
crates/hero_proc_server/openrpc.json Modified — 6 new method definitions

hero_proc_ui (frontend)

File Change
crates/hero_proc_ui/src/routes.rs Modified — 8 new HTTP routes: /api/scripts/list, /api/scripts/file (GET/POST/DELETE), /api/scripts/run, /api/scripts/mkdir, /api/scripts/rename, /api/scripts/download
crates/hero_proc_ui/templates/index.html Modified — Added tab-heroscript pane with file tree + editor + log split layout
crates/hero_proc_ui/templates/base.html Modified — Added "Hero Script" tab button, heroscript.js include
crates/hero_proc_ui/static/js/heroscript.js New — Complete frontend: tree rendering, editor, save/run, log polling, file CRUD, context menu, upload/download
crates/hero_proc_ui/static/css/dashboard.css Modified — Hero Script layout CSS (.heroscript-container, tree, editor, log panel)
crates/hero_proc_ui/static/js/dashboard.js Modified — Wired hsInit() into switchTab() and tabLoaders

Key Features

  • File explorer tree with expand/collapse, right-click context menu
  • Plain textarea editor with save and run buttons
  • Live log output panel polling job.logs with ANSI color support
  • Auto-save before run
  • Background scanner syncs // META: interval:NSchedulePolicy.interval_ms
  • // META: disabled:true → no schedule (manual-only)
  • Action naming: startup.<rel_path_dotted_no_ext> (e.g. startup.tools.deploy)
  • Per-directory .meta JSON file for incremental change detection
  • Path traversal protection on all file operations

Test Results

  • cargo build: success, 0 errors
  • All test suites: 399 tests passed, 0 failed
## Implementation Complete — Hero Script Admin Panel All 10 implementation steps have been completed. Build succeeds and all 399 tests pass. ### Changes Made #### hero_proc_server (backend scanner + RPC) | File | Change | |------|--------| | `crates/hero_proc_server/src/script_scanner.rs` | **New** — Background scanner task running every 5 seconds: normalizes filenames to snake_case, diffs filesystem vs `.meta` files, creates/updates/deletes actions in context `startup` | | `crates/hero_proc_server/src/rpc/script.rs` | **New** — 6 RPC handlers: `script.scan`, `script.list`, `script.get`, `script.set`, `script.delete`, `script.run` | | `crates/hero_proc_server/src/rpc/mod.rs` | **Modified** — Added `pub mod script;` and 6 dispatch entries | | `crates/hero_proc_server/src/lib.rs` | **Modified** — Added `pub mod script_scanner;` | | `crates/hero_proc_server/src/main.rs` | **Modified** — Spawns scanner task alongside scheduler | | `crates/hero_proc_server/openrpc.json` | **Modified** — 6 new method definitions | #### hero_proc_ui (frontend) | File | Change | |------|--------| | `crates/hero_proc_ui/src/routes.rs` | **Modified** — 8 new HTTP routes: `/api/scripts/list`, `/api/scripts/file` (GET/POST/DELETE), `/api/scripts/run`, `/api/scripts/mkdir`, `/api/scripts/rename`, `/api/scripts/download` | | `crates/hero_proc_ui/templates/index.html` | **Modified** — Added `tab-heroscript` pane with file tree + editor + log split layout | | `crates/hero_proc_ui/templates/base.html` | **Modified** — Added "Hero Script" tab button, `heroscript.js` include | | `crates/hero_proc_ui/static/js/heroscript.js` | **New** — Complete frontend: tree rendering, editor, save/run, log polling, file CRUD, context menu, upload/download | | `crates/hero_proc_ui/static/css/dashboard.css` | **Modified** — Hero Script layout CSS (`.heroscript-container`, tree, editor, log panel) | | `crates/hero_proc_ui/static/js/dashboard.js` | **Modified** — Wired `hsInit()` into `switchTab()` and `tabLoaders` | ### Key Features - File explorer tree with expand/collapse, right-click context menu - Plain textarea editor with save and run buttons - Live log output panel polling `job.logs` with ANSI color support - Auto-save before run - Background scanner syncs `// META: interval:N` → `SchedulePolicy.interval_ms` - `// META: disabled:true` → no schedule (manual-only) - Action naming: `startup.<rel_path_dotted_no_ext>` (e.g. `startup.tools.deploy`) - Per-directory `.meta` JSON file for incremental change detection - Path traversal protection on all file operations ### Test Results - `cargo build`: ✅ success, 0 errors - All test suites: ✅ 399 tests passed, 0 failed
Author
Owner

Implementation committed: 693ad69

Browse: 693ad69

Implementation committed: `693ad69` Browse: https://forge.ourworld.tf/lhumina_code/hero_proc/commit/693ad69
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#24
No description provided.