rhai bindngs for tools #2

Open
opened 2026-03-26 05:06:09 +00:00 by despiegk · 4 comments
Owner

implement /Volumes/T7/code0/hero_lib_rhai/crates/tools_rhai
from /Volumes/T7/code0/hero_lib/crates/tools

see how we did it for the others

use skill /rhai_bindings_reference

make good tests

implement /Volumes/T7/code0/hero_lib_rhai/crates/tools_rhai from /Volumes/T7/code0/hero_lib/crates/tools see how we did it for the others use skill /rhai_bindings_reference make good tests
Author
Owner

Implementation Spec for Issue #2 — Rhai Bindings for Tools

Objective

Create a new crate herolib_tools_rhai at crates/tools_rhai/ that exposes the public API of herolib_tools (forge, agent, hero_utils, init, installers, legacy, secrets, services, skills) to the Rhai scripting engine, following the established patterns from os_rhai, ai_rhai, and code_rhai.

Requirements

  • Follow the same directory/module structure as existing *_rhai crates
  • Register all types, constructors, methods, and getters with the Rhai engine
  • Convert error types into Box<EvalAltResult> consistently
  • Handle ForgeClient (not Clone) via Arc wrapper
  • Provide a top-level register_tools_module(&mut Engine) convenience function
  • Add crate to workspace and integrate into hero_do
  • Write unit tests for registration and pure function evaluation

Files to Create

  • crates/tools_rhai/Cargo.toml — Crate manifest
  • crates/tools_rhai/src/lib.rs — Top-level module + register_tools_module()
  • crates/tools_rhai/src/forge.rs — ForgeClient, ForgeEnv, repo types
  • crates/tools_rhai/src/agent.rs — ModelConfig, ModelProvider
  • crates/tools_rhai/src/hero_utils.rs — detect_external_disks, string_stats, etc.
  • crates/tools_rhai/src/init.rs — HeroEnv, derive_rootdir, detect_editor
  • crates/tools_rhai/src/installers.rs — package manager detection, install functions
  • crates/tools_rhai/src/legacy.rs — set_paths
  • crates/tools_rhai/src/secrets.rs — secrets source, sync, toml_to_sh
  • crates/tools_rhai/src/services.rs — HeroService, service status
  • crates/tools_rhai/src/skills.rs — skills_sync, skills_edit

Files to Modify

  • Cargo.toml — Add tools_rhai to workspace members and dependencies
  • crates/hero_do/Cargo.toml — Add herolib_tools_rhai dependency
  • crates/hero_do/src/lib.rs — Register tools module in engine setup

Implementation Plan (13 Steps)

  1. Create crate skeleton (Cargo.toml + lib.rs)
  2. Update workspace configuration
  3. Implement hero_utils.rs bindings
  4. Implement agent.rs bindings
  5. Implement init.rs bindings
  6. Implement installers.rs bindings
  7. Implement legacy.rs bindings
  8. Implement secrets.rs bindings
  9. Implement forge.rs bindings (largest module)
  10. Implement services.rs bindings
  11. Implement skills.rs bindings
  12. Integrate into hero_do
  13. Write tests for all modules

Acceptance Criteria

  • cargo build -p herolib_tools_rhai succeeds
  • cargo test -p herolib_tools_rhai passes
  • cargo build -p herolib_do succeeds with new module
  • All 9 submodules have Rhai bindings
  • hero_do registers the tools module
  • Tests cover registration and pure function evaluation

Notes

  • ForgeClient wrapped in Arc for Rhai Clone requirement
  • All herolib_tools functions are synchronous — no async bridge needed
  • Function names use snake_case with module prefix to avoid collisions
## Implementation Spec for Issue #2 — Rhai Bindings for Tools ### Objective Create a new crate `herolib_tools_rhai` at `crates/tools_rhai/` that exposes the public API of `herolib_tools` (forge, agent, hero_utils, init, installers, legacy, secrets, services, skills) to the Rhai scripting engine, following the established patterns from `os_rhai`, `ai_rhai`, and `code_rhai`. ### Requirements - Follow the same directory/module structure as existing `*_rhai` crates - Register all types, constructors, methods, and getters with the Rhai engine - Convert error types into `Box<EvalAltResult>` consistently - Handle `ForgeClient` (not `Clone`) via `Arc` wrapper - Provide a top-level `register_tools_module(&mut Engine)` convenience function - Add crate to workspace and integrate into `hero_do` - Write unit tests for registration and pure function evaluation ### Files to Create - `crates/tools_rhai/Cargo.toml` — Crate manifest - `crates/tools_rhai/src/lib.rs` — Top-level module + `register_tools_module()` - `crates/tools_rhai/src/forge.rs` — ForgeClient, ForgeEnv, repo types - `crates/tools_rhai/src/agent.rs` — ModelConfig, ModelProvider - `crates/tools_rhai/src/hero_utils.rs` — detect_external_disks, string_stats, etc. - `crates/tools_rhai/src/init.rs` — HeroEnv, derive_rootdir, detect_editor - `crates/tools_rhai/src/installers.rs` — package manager detection, install functions - `crates/tools_rhai/src/legacy.rs` — set_paths - `crates/tools_rhai/src/secrets.rs` — secrets source, sync, toml_to_sh - `crates/tools_rhai/src/services.rs` — HeroService, service status - `crates/tools_rhai/src/skills.rs` — skills_sync, skills_edit ### Files to Modify - `Cargo.toml` — Add tools_rhai to workspace members and dependencies - `crates/hero_do/Cargo.toml` — Add herolib_tools_rhai dependency - `crates/hero_do/src/lib.rs` — Register tools module in engine setup ### Implementation Plan (13 Steps) 1. Create crate skeleton (Cargo.toml + lib.rs) 2. Update workspace configuration 3. Implement hero_utils.rs bindings 4. Implement agent.rs bindings 5. Implement init.rs bindings 6. Implement installers.rs bindings 7. Implement legacy.rs bindings 8. Implement secrets.rs bindings 9. Implement forge.rs bindings (largest module) 10. Implement services.rs bindings 11. Implement skills.rs bindings 12. Integrate into hero_do 13. Write tests for all modules ### Acceptance Criteria - [ ] `cargo build -p herolib_tools_rhai` succeeds - [ ] `cargo test -p herolib_tools_rhai` passes - [ ] `cargo build -p herolib_do` succeeds with new module - [ ] All 9 submodules have Rhai bindings - [ ] hero_do registers the tools module - [ ] Tests cover registration and pure function evaluation ### Notes - ForgeClient wrapped in `Arc` for Rhai Clone requirement - All herolib_tools functions are synchronous — no async bridge needed - Function names use snake_case with module prefix to avoid collisions
Author
Owner

Test Results

  • Total: 12
  • Passed: 12
  • Failed: 0

All tests pass cleanly with no warnings from herolib_tools_rhai.

Tests by module:

  • tests::test_register_tools_module
  • agent::tests::test_claude_flags
  • agent::tests::test_claude_model_config
  • forge::tests::test_parse_repo_input
  • forge::tests::test_forge_env_optional
  • hero_utils::tests::test_string_stats
  • hero_utils::tests::test_detect_external_disks
  • init::tests::test_derive_rootdir
  • installers::tests::test_detect_package_manager
  • secrets::tests::test_secrets_path
  • services::tests::test_service_repo
  • skills::tests::test_skills_repo_path

Build verification:

  • cargo build -p herolib_tools_rhai
  • cargo build -p herolib_do (with tools_rhai integrated)
## Test Results - **Total**: 12 - **Passed**: 12 - **Failed**: 0 All tests pass cleanly with no warnings from `herolib_tools_rhai`. ### Tests by module: - `tests::test_register_tools_module` ✅ - `agent::tests::test_claude_flags` ✅ - `agent::tests::test_claude_model_config` ✅ - `forge::tests::test_parse_repo_input` ✅ - `forge::tests::test_forge_env_optional` ✅ - `hero_utils::tests::test_string_stats` ✅ - `hero_utils::tests::test_detect_external_disks` ✅ - `init::tests::test_derive_rootdir` ✅ - `installers::tests::test_detect_package_manager` ✅ - `secrets::tests::test_secrets_path` ✅ - `services::tests::test_service_repo` ✅ - `skills::tests::test_skills_repo_path` ✅ ### Build verification: - `cargo build -p herolib_tools_rhai` ✅ - `cargo build -p herolib_do` (with tools_rhai integrated) ✅
Author
Owner

Implementation Summary

New crate: herolib_tools_rhai (crates/tools_rhai/)

Created complete Rhai scripting bindings for all 9 submodules of herolib_tools:

Module Rhai Functions Types Registered
hero_utils string_stats, detect_external_disks, load_init_sh, to_markdown_table, ls_big StringStats, FileEntry
agent agent_model_config, agent_claude_flags ModelConfig
init hero_init, hero_derive_rootdir, hero_detect_editor HeroEnv
installers detect_package_manager, ensure_installed, ensure_installed_pkg, install_base, install_ai, install_py
legacy legacy_set_paths
secrets secrets_source, secrets_path, secrets_toml_to_sh, secrets_sync_builder SecretsSyncResult, SecretsSync
forge forge_client, forge_env_from_env, forge_env_from_env_optional, is_online, user, list, list_all, find, info, resolve, create_repo, delete_repo, rename_repo, ensure_local, pull, push, clone_repo_to, forge_parse_repo_input, forge_resolve_local ForgeClient, ForgeEnv, RepoSummary, RepoDetail, UserInfo, RepoInfo
services is_service_running, service_repo, ensure_service, start_service ServiceResult
skills skills_repo_path, skills_edit, skills_sync SkillsSyncResult

Files created (11):

  • crates/tools_rhai/Cargo.toml
  • crates/tools_rhai/src/lib.rs
  • crates/tools_rhai/src/agent.rs
  • crates/tools_rhai/src/forge.rs
  • crates/tools_rhai/src/hero_utils.rs
  • crates/tools_rhai/src/init.rs
  • crates/tools_rhai/src/installers.rs
  • crates/tools_rhai/src/legacy.rs
  • crates/tools_rhai/src/secrets.rs
  • crates/tools_rhai/src/services.rs
  • crates/tools_rhai/src/skills.rs

Files modified (3):

  • Cargo.toml — Added tools_rhai to workspace members and dependencies
  • crates/hero_do/Cargo.toml — Added herolib_tools_rhai dependency
  • crates/hero_do/src/lib.rs — Registered tools module in engine setup

Key design decisions:

  • ForgeClient wrapped in Arc for Rhai Clone requirement
  • All error types converted to Box<EvalAltResult> consistently
  • PathBuf fields converted to String in Rhai wrapper types
  • Service/skill functions that need ForgeClient use it as the first (&mut) parameter for Rhai compatibility
## Implementation Summary ### New crate: `herolib_tools_rhai` (`crates/tools_rhai/`) Created complete Rhai scripting bindings for all 9 submodules of `herolib_tools`: | Module | Rhai Functions | Types Registered | | --- | --- | --- | | `hero_utils` | `string_stats`, `detect_external_disks`, `load_init_sh`, `to_markdown_table`, `ls_big` | `StringStats`, `FileEntry` | | `agent` | `agent_model_config`, `agent_claude_flags` | `ModelConfig` | | `init` | `hero_init`, `hero_derive_rootdir`, `hero_detect_editor` | `HeroEnv` | | `installers` | `detect_package_manager`, `ensure_installed`, `ensure_installed_pkg`, `install_base`, `install_ai`, `install_py` | — | | `legacy` | `legacy_set_paths` | — | | `secrets` | `secrets_source`, `secrets_path`, `secrets_toml_to_sh`, `secrets_sync_builder` | `SecretsSyncResult`, `SecretsSync` | | `forge` | `forge_client`, `forge_env_from_env`, `forge_env_from_env_optional`, `is_online`, `user`, `list`, `list_all`, `find`, `info`, `resolve`, `create_repo`, `delete_repo`, `rename_repo`, `ensure_local`, `pull`, `push`, `clone_repo_to`, `forge_parse_repo_input`, `forge_resolve_local` | `ForgeClient`, `ForgeEnv`, `RepoSummary`, `RepoDetail`, `UserInfo`, `RepoInfo` | | `services` | `is_service_running`, `service_repo`, `ensure_service`, `start_service` | `ServiceResult` | | `skills` | `skills_repo_path`, `skills_edit`, `skills_sync` | `SkillsSyncResult` | ### Files created (11): - `crates/tools_rhai/Cargo.toml` - `crates/tools_rhai/src/lib.rs` - `crates/tools_rhai/src/agent.rs` - `crates/tools_rhai/src/forge.rs` - `crates/tools_rhai/src/hero_utils.rs` - `crates/tools_rhai/src/init.rs` - `crates/tools_rhai/src/installers.rs` - `crates/tools_rhai/src/legacy.rs` - `crates/tools_rhai/src/secrets.rs` - `crates/tools_rhai/src/services.rs` - `crates/tools_rhai/src/skills.rs` ### Files modified (3): - `Cargo.toml` — Added `tools_rhai` to workspace members and dependencies - `crates/hero_do/Cargo.toml` — Added `herolib_tools_rhai` dependency - `crates/hero_do/src/lib.rs` — Registered tools module in engine setup ### Key design decisions: - `ForgeClient` wrapped in `Arc` for Rhai `Clone` requirement - All error types converted to `Box<EvalAltResult>` consistently - `PathBuf` fields converted to `String` in Rhai wrapper types - Service/skill functions that need `ForgeClient` use it as the first (`&mut`) parameter for Rhai compatibility
Author
Owner

Implementation committed: c3f6375

Browse: c3f6375

Implementation committed: `c3f6375` Browse: https://forge.ourworld.tf/lhumina_code/hero_lib_rhai/commit/c3f6375
Sign in to join this conversation.
No labels
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_lib_rhai#2
No description provided.