Recursive AI
oneecmaCookbook

oneecma cookbook

Short recipes for common OneEcma tasks, each with complete code you can copy.

Recipes

Run untrusted JavaScript with limitsRun JavaScript you don’t trust from C# with OneEcma: a fresh engine per script, a step budget, an allocation budget, a wall-clock deadline, a call-depth limit and cancellation, each ending in a report that says what stopped the run.Call C# from JavaScriptGive scripts C# functions with OneEcma’s host API: plain functions, .NET exceptions that scripts can catch, tasks that become promises, and script values read back in C#. No generator needed.Expose .NET objects with [JsExport]Mark C# classes, records and enums with [JsExport] and OneEcma’s source generator writes the bindings at build time: methods, properties, async methods and callbacks work in script, with no reflection at run time, and a wrong argument names the .NET member, the path and both…Give scripts tools from a JSON SchemaRegister host functions whose argument is checked against a JSON Schema before your C# handler runs, the way an agent host exposes its tools to model-written JavaScript. A bad call fails with a report that names the path, the rule and the value.Error reports: text, compact and JSONGet OneEcma’s report for a failed script in each of its forms: the full text report, the same with each frame’s local variables, a compact rendering sized for an LLM’s context, and versioned JSON for tools. All of them come from one Diagnostic.Run code a model wroteRun JavaScript that an LLM wrote as a tool call: check it and apply safe syntax repairs, run it as an async function body under limits, and hand the model back either the result or a compact report it can act on. Four attempts show the loop.Point reports at the original source with source mapsRun minified or bundled JavaScript with OneEcma and turn its error report back into one about the TypeScript you wrote: the location, the source line and the whole stack move to the original files through the bundle’s ECMA-426 source map.The oneecma commandRun, check and repair JavaScript from a terminal or a CI job with the oneecma command: the same reports as the library on stderr, JSON on stdout, exit status 1 on an error, and a REPL.Record a failed run and replay itSave the record log of a JavaScript run that failed in production and replay it anywhere with OneEcma: the same clock readings, random numbers and host-call results come back from the log, so the replay fails the same way and gives the same report, with each frame’s locals added.Move from Jint or ClearScriptMove a .NET host from Jint or ClearScript to OneEcma: how engine creation, limits, exposing functions and objects, running code and catching errors map, with one program run on all three engines and what each prints for the same mistake.