Expand description
ScriptEngine — the cheap tier of extension backend.
A hook point today can be answered three ways: a Rust implementation compiled in, a command hook that pays for a subprocess, or a prompt hook that pays for a model call. There is nothing between “recompile the engine” and “spawn a process”, so doing something small at a hook point — rewrite one line of a prompt, tag a tool result, decide whether to retry — costs either a release or several milliseconds and a PID.
This is the missing tier: run a piece of the operator’s own code, in this process, in microseconds.
§The engine is a separate crate, behind a feature
This module is the contract and the governance around it, never an
interpreter: base has no internal dependencies and linking a JavaScript
runtime into it would put one in every build of everything. script-host
is the carrier crate — the ScriptCarrier that enforces the budget, the
adapters for the bindable points and QuickJS behind this trait — and it is
an optional dependency of daemon under the scripts feature.
RefusingEngine is what runs when a host wired nothing, and
FnScriptEngine gives a host the governance around logic written in
Rust.
§Governance is outside the engine
The timeout and the call quota are enforced by script_host::carrier::ScriptCarrier,
on this side of the trait, because an engine that enforced its own limits would be
an engine that could choose not to. What the carrier cannot do from here
is stop a script that never yields: tokio::time::timeout abandons a
future, it does not interrupt a busy loop. An engine implementation must
provide its own interruption — every serious one has a fuel or watchdog
mechanism — and the carrier’s timeout is the second line, not the first.
Structs§
- FnScript
Engine - An “engine” that is a Rust closure.
- Refusing
Engine - The engine when there is none.
- Script
Binding - One script, bound to one extension point.
- Script
Ledger - Every script call, in the order the points made them.
- Script
Limits - What a script may spend.
- Script
Record - One line of the ledger.
- Script
Source - A piece of code to run, and whose it is.
Enums§
- Script
Error - Script
Outcome - What one script call did, once the point it was bound to had its say.
Traits§
- Script
Engine - Runs a script.
Functions§
- check_
global_ name - Why
namecannot be a global the engine adds to every script — the base library’s, or a host library’s: it is[a-z][a-z0-9]*, no reserved word, and no name a script already has from its carrier or the language.