@moikapy/origen-zero
v0.1.1
Published
Bridge package connecting Origen agents to ZeroLang compiler and runtime
Readme
@moikapy/origen-zero
Bridge package connecting Origen agents to the ZeroLang compiler and runtime.
Why?
Origen agents write tool logic in TypeScript. ZeroLang is a systems language designed for agents — structured compiler output, explicit effects, repair metadata, and JSON diagnostics are first-class. This package bridges the two:
- Define tools in Zero — Write
.0files, compile them, get structured diagnostics before registration - Register as OrigenTools — Zero functions become first-class Origen tools
- Interactive compiler tools —
zero_check,zero_graph,zero_size,zero_fixas Origen tools - Self-modify — Write, check, fix, and register tools during a single conversation session
Install
npm install @moikapy/origen-zeroPrerequisites:
@moikapy/origen^0.6.0 (peer dependency)- Zero CLI installed and available on
$PATH— install guide
Usage
Register a Compiled Zero Binary as OrigenTool
import { createZeroTool } from "@moikapy/origen-zero/tools";
import { streamOrigen } from "@moikapy/origen";
const lookupTool = createZeroTool({
functionName: "lookup",
description: "Look up a record by ID",
executablePath: "./bin/lookup",
});
const config = {
appName: "MyAgent",
tools: [lookupTool],
getD1: async () => myD1,
};Interactive Compiler Tools (LLM Calls Zero CLI)
import { createZeroCompilerTools } from "@moikapy/origen-zero/tools";
const compilerTools = createZeroCompilerTools();
// Returns: [zero_check, zero_graph, zero_size, zero_fix]Write, Check, Fix, Register — Full Loop
import { compileAndRegister } from "@moikapy/origen-zero/tools";
const result = await compileAndRegister({
path: "math.0",
content: sourceCode,
});
if ("tools" in result) {
// ✅ Compiled — result.tools are ready
} else {
// ❌ Errors — return to LLM for self-repair
console.log(result.errors);
}Direct Compiler Access
import { ZeroCompiler } from "@moikapy/origen-zero/compiler";
const compiler = new ZeroCompiler({ binaryPath: "zero", timeout: 10000 });
// Check for errors
const result = await compiler.check("fun main() {}" /* ... */);
if (result.ok) { /* clean */ }
// Get dependency graph
const graph = await compiler.graph("./src/math.0");
// Get size estimates
const sizes = await compiler.size("./src/math.0");
// Build WASM for Workers
const build = await compiler.build("./src/math.0", { emit: "wasm", target: "wasm32-web", out: "./dist/math" });API
ZeroCompiler
| Method | Description | Zero CLI |
|---|---|---|
| check(source) | Check for errors, return diagnostics | zero check --json |
| graph(source) | Get dependency graph | zero graph --json |
| size(source) | Get function size estimates | zero size --json |
| fix(source) | Get repair suggestions | zero fix --plan --json |
| build(source, opts?) | Compile to native executable | zero build |
| explain(code) | Human-readable diagnostic explanation | zero explain |
Tool Registration
| Function | Description |
|---|---|
| createZeroTool(config) | Register a compiled Zero function as an OrigenTool |
| createZeroToolsFromProgram(path, opts?) | Discover and register all public functions |
| compileAndRegister(source, opts?) | Write → compile → verify → register in one call |
Interactive Compiler Tools
| Tool Name | Description |
|---|---|
| zero_check | Check Zero source for errors |
| zero_graph | Show dependency graph |
| zero_size | Show function size estimates |
| zero_fix | Suggest repairs for errors |
Error Types
| Error | When |
|---|---|
| ZeroCompilerNotFoundError | zero binary not on PATH |
| ZeroCheckFailedError | Source has diagnostics |
| ZeroBuildFailedError | Build produces no output |
| ZeroTimeoutError | CLI invocation exceeds timeout |
| ZeroExecutionError | Compiled binary exits non-zero |
WASM Execution (Workers-ready)
import { createZeroWASMTool } from "@moikapy/origen-zero/wasm-tool";
import { readFileSync } from "node:fs";
// Load pre-compiled WASM module
const wasmBytes = readFileSync("./dist/my-tool.wasm");
// In Workers — WASM runs in-process, no subprocess or HTTP needed
const tool = createZeroWASMTool({
functionName: "main",
description: "My Zero tool",
wasmBytes,
});
// Execute: Zero program writes to stdout, tool captures the output
const result = await tool.execute({ input: "hello" });Build the WASM module from Zero source:
zero build --emit wasm --target wasm32-web src/my-tool.0 --out dist/my-toolExecution Modes
| Mode | Transport | Works In | When |
|---|---|---|---|
| subprocess | execFile() | Node.js, Bun | Native binaries |
| http | fetch() | Workers, Node, browser | Remote Zero service |
| wasm | WebAssembly.instantiate() | Workers, Node, browser | Pre-compiled .wasm |
License
MIT
