Hero Script Admin Panel #24
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#24
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?
Hero Script Admin Panel
1. Overview
Add a new admin tab:
Name:
Hero ScriptPurpose:
2. File System Root
Root directory:
This directory contains:
.rhaifiles.metafile for ~/hero/cfg/proc/The filesystem is the source of truth.
3. Naming Rules
All directories and files must use:
Examples:
startup_tasks/build_assets.rhaiInvalid examples:
StartupTasks/BuildAssets.rhaimy-script.rhaiScan-time normalization
When scanning a directory:
Examples:
MyScript.rhai→my_script.rhaiBuild-Jobs→build_jobsThis guarantees:
4. UI Layout
Left panel: file explorer
Tree view of the root directory.
Features:
Main panel: editor + logs
Left side: editor
.rhaifileRight side: logs
5. Script Metadata
Metadata is embedded inside
.rhaifiles using comment lines:These lines:
Supported keys
interval: integer, in minutesdisabled: booleanExample:
If no
intervalexists:If
disabled:true:6. Execution
Single script run
When user clicks Run:
execute through Hero Proc SDK
equivalent behavior:
create a Hero Proc job
stream logs to UI
Directory run
When user runs a directory:
.rhaifiles one by oneAction / job naming
Each script maps to an action name:
Example:
network/init/setup.rhaistartup.network.init.setupThis makes it easy to trace script → action → job.
7.
.metaFileThis avoids rebuilding all actions on every scan.
8. What
.metaStoresThe
.metafile stores a snapshot of the directory contents.For each direct child entry in that directory, store:
fileordir)For files
Hash should be based on:
For directories
Hash should represent directory state, for example:
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
Step 2: read current directory state
.metaStep 3: compare current state with
.metaDetermine:
Added
Entry exists now, but not in
.metaAction:
.rhaifile: parse metadata and register actionModified
Entry exists in both, but hash changed
Action:
.rhaifile: update action metadata and script bindingDeleted
Entry exists in
.meta, but not on diskAction:
Unchanged
Entry exists in both and hash matches
Action:
Step 4: write new
.metaAfter processing, rewrite
.metawith the new known state.11. Why
.metaExistsThe
.metafile gives each directory memory of its last scanned state.That allows:
Without
.meta, the system would need to:12. Action Update Rules
Added file
// META:linesModified file
Deleted file
Added directory
Deleted directory
13. Scheduling
Hero Proc uses parsed file metadata.
intervalIf present:
disabledIf true:
14. Summary
/home/hero/cfg/proc/is the source of truth.rhai.metasnapshot file.metaImplementation 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.rhaifiles into hero_proc actions under thestartupcontext. Scripts embed scheduling metadata as// META:comments. Manual and scheduled execution flows through the existingjob.create/ action RPC pipeline.Requirements
Hero Scripttab appears in the tab bar betweenAdminandDocs~/hero/cfg/proc/with: create file, create folder, upload, download, rename, delete, right-click context menujob.logs(same pattern used elsewhere) and is tied to the current job/run for the selected fileroutes.rs(filesystem CRUD, scan trigger)~/hero/cfg/proc/every 5 seconds// META: interval:Nand// META: disabled:boolfrom each.rhaifile.metaJSON file per directory tracking file hash, relative path, and last known action namestartup.<relative_path_with_dots_no_extension>(e.g.startup.tools.deploy)action.setwithinterpreter: rhai,schedule_policy.interval_msifintervalMETA presentdisabled: true→ remove schedule_policyaction.delete+ cancel/purge associated jobs.rhaifiles recursivelyjob.createhero_proc_serverRPC methodscript.scanallows triggering a forced re-scanFiles to Modify / Create
hero_proc_server (scanner + RPC)
crates/hero_proc_server/src/script_scanner.rs.meta, diff filesystem vs.meta, call action CRUDcrates/hero_proc_server/src/lib.rspub mod script_scanner;crates/hero_proc_server/src/main.rscrates/hero_proc_server/src/rpc/mod.rsscript.*method dispatchcrates/hero_proc_server/src/rpc/script.rsscript.scan,script.list,script.get,script.set,script.delete,script.runcrates/hero_proc_server/openrpc.jsonscript.*method definitionshero_proc_ui (routes + frontend)
crates/hero_proc_ui/src/routes.rscrates/hero_proc_ui/templates/index.htmltab-panediv fortab-heroscriptwith file tree + editor + log panel HTMLcrates/hero_proc_ui/templates/base.htmlHero Script; add JS includecrates/hero_proc_ui/static/js/heroscript.jscrates/hero_proc_ui/static/css/dashboard.css.heroscript-*CSS classes for tree + editor split layoutStep-by-Step Implementation Plan
Step 1 — Define
.metaformat and scanner data typesFile:
crates/hero_proc_server/src/script_scanner.rs(create)MetaEntrystruct with: name, kind, rel_path, hash, action_namenormalize_name(s)→ lowercase snake_case, rename on diskhash_file(path)→ SHA-256 / DefaultHasher hexparse_meta_comments(content)→ parse// META: key:valuelines intoScriptMetaload_dot_meta(dir)→ deserialize.metaJSONsave_dot_meta(dir, entries)→ serialize.metaJSONStep 2 — Implement scan loop and action sync logic
File:
crates/hero_proc_server/src/script_scanner.rs(continue)ScriptScanner { db, cfg_root }structrun()→ tokio interval loop every 5 secondsscan_dir(dir, rel_prefix)→ normalize → compare.meta→ Added/Modified/Deleted/Unchanged →upsert_action/delete_action_and_jobs→ recurse subdirs → write.metaStep 3 — Wire scanner into main.rs
File:
crates/hero_proc_server/src/main.rs,src/lib.rspub mod script_scanner;tokio::spawn(Arc::clone(&scanner).run())Step 4 — Add
script.*RPC handlersFiles:
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_runStep 5 — Add
script.*to OpenRPC specFile:
crates/hero_proc_server/openrpc.jsonScriptEntryschemaStep 6 — Add filesystem API routes to hero_proc_ui
File:
crates/hero_proc_ui/src/routes.rsStep 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#main-tabsheroscript.jsStep 8 — Implement Hero Script frontend JavaScript
File:
crates/hero_proc_ui/static/js/heroscript.js(create)hsLoadTree,hsRenderTree,hsSelectFile,hsOpenFilehsSave,hsRun,hsStartLogPoll,hsStopLogPoll,hsClearLoghsCreateFile,hsCreateFolder,hsDelete,hsRename,hsDownload,hsUploadhsShowContextMenu,hsInit,hsRefreshTreeStep 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-itemetc.Step 10 — Wire tab into dashboard.js
File:
crates/hero_proc_ui/static/js/dashboard.jsheroscriptcase toswitchTab()heroscriptentry totabLoadersmapAcceptance Criteria
~/hero/cfg/proc/contents on tab open.rhaifile loads its content into the editorstartup// META: interval:5results in an action withschedule_policy.interval_ms = 300000// META: disabled:trueresults in no schedule_policy on the action.metafile is written per directory after each scanaction.listwithcontext: "startup"shows all synced Rhai scriptsscript.scanRPC call triggers an immediate re-scan.rhaifilesNotes
Action naming:
startupis a new context string. No schema migration needed —context_namecolumn already exists.Script execution:
ActionSpec.scriptstores raw Rhai source. Wheninterpreter: Rhai, the executor runs the script via the existing rhai execution path.Editor MVP: Plain
<textarea>for editing;highlight.jswithrustmode 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 allrel_pathinputs.Hash:
DefaultHasher(non-cryptographic) is sufficient for change detection; avoids adding a dependency..metaformat (JSON array per directory):Build & Test Results
Build Status: SUCCESS
The project compiled successfully with
cargo build. No compilation errors. Only minor warnings:partition_pathindb/logs/store.rsshell_escapeintests/integration/src/fixtures.rstimestampintests/stress.rsTest Results: ALL PASSED
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.
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)
crates/hero_proc_server/src/script_scanner.rs.metafiles, creates/updates/deletes actions in contextstartupcrates/hero_proc_server/src/rpc/script.rsscript.scan,script.list,script.get,script.set,script.delete,script.runcrates/hero_proc_server/src/rpc/mod.rspub mod script;and 6 dispatch entriescrates/hero_proc_server/src/lib.rspub mod script_scanner;crates/hero_proc_server/src/main.rscrates/hero_proc_server/openrpc.jsonhero_proc_ui (frontend)
crates/hero_proc_ui/src/routes.rs/api/scripts/list,/api/scripts/file(GET/POST/DELETE),/api/scripts/run,/api/scripts/mkdir,/api/scripts/rename,/api/scripts/downloadcrates/hero_proc_ui/templates/index.htmltab-heroscriptpane with file tree + editor + log split layoutcrates/hero_proc_ui/templates/base.htmlheroscript.jsincludecrates/hero_proc_ui/static/js/heroscript.jscrates/hero_proc_ui/static/css/dashboard.css.heroscript-container, tree, editor, log panel)crates/hero_proc_ui/static/js/dashboard.jshsInit()intoswitchTab()andtabLoadersKey Features
job.logswith ANSI color support// META: interval:N→SchedulePolicy.interval_ms// META: disabled:true→ no schedule (manual-only)startup.<rel_path_dotted_no_ext>(e.g.startup.tools.deploy).metaJSON file for incremental change detectionTest Results
cargo build: ✅ success, 0 errorsImplementation committed:
693ad69Browse:
693ad69