-
Notifications
You must be signed in to change notification settings - Fork 188
Open
Description
Problem
scripting_engine.rs contains large JavaScript/TypeScript wrapper scripts embedded as Rust strings using format!() blocks (lines ~970-1030, ~1690-1770, etc.). This makes the code:
- Hard to maintain (no syntax highlighting, no linting)
- Error-prone (escaping issues with
{{and}}) - Difficult to read and review
Proposed Solution
Extract wrapper scripts to external template files using include_str!:
// Include at compile time
const JS_WRAPPER: &str = include_str!("templates/wrapper.js");
// Use string replacement for dynamic parts
let script = JS_WRAPPER
.replace("{{USER_SCRIPT}}", &script)
.replace("{{MODULE_SETUP}}", &module_resolution_setup);File structure
crates/terminator-mcp-agent/src/
├── scripting_engine.rs
└── templates/
├── js_wrapper.js
├── ts_wrapper.ts
└── py_wrapper.py
Benefits
- IDE support: Syntax highlighting, linting, formatting for JS/TS/Python
- Easier maintenance: Edit JS as JS, not escaped Rust strings
- Better reviews: Cleaner diffs when modifying wrapper logic
- No runtime cost:
include_str!embeds at compile time
Alternatives Considered
indoc!macro: Cleaner inline formatting but still strings- Template engine (tera/handlebars): Overkill, adds runtime dep
- Build-time codegen: More complex than needed
Affected Code
execute_javascript_with_nodejs(~line 970)execute_typescript_with_nodejs(~line 1690)execute_python_with_bindings(~line 2100)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels