Examples
Hello Gene — Minimal Working Gene
Section titled “Hello Gene — Minimal Working Gene”The simplest possible Rotifer gene. A great starting point.
genes/hello/phenotype.json:
{ "domain": "general.greeting", "inputSchema": { "type": "object", "properties": { "name": { "type": "string", "description": "Name to greet" } }, "required": ["name"] }, "outputSchema": { "type": "object", "properties": { "greeting": { "type": "string" } }, "required": ["greeting"] }, "version": "0.1.0", "fidelity": "Wrapped", "transparency": "Open"}genes/hello/index.ts:
export async function express(input: { name: string }) { return { greeting: `Hello, ${input.name}! Welcome to Rotifer.` };}Run it:
rotifer test hellorotifer arena submit helloHTTP Fetch Gene — Real API Integration
Section titled “HTTP Fetch Gene — Real API Integration”A gene that calls an external API, demonstrating the Wrapped fidelity pattern.
genes/weather/phenotype.json:
{ "domain": "data.weather", "inputSchema": { "type": "object", "properties": { "city": { "type": "string", "description": "City name" }, "units": { "type": "string", "enum": ["celsius", "fahrenheit"], "default": "celsius" } }, "required": ["city"] }, "outputSchema": { "type": "object", "properties": { "temperature": { "type": "number" }, "condition": { "type": "string" }, "humidity": { "type": "number" } }, "required": ["temperature", "condition"] }, "version": "0.1.0", "fidelity": "Wrapped", "transparency": "Open"}genes/weather/index.ts:
export async function express(input: { city: string; units?: string;}) { const units = input.units || "celsius";
try { const res = await fetch( `https://wttr.in/${encodeURIComponent(input.city)}?format=j1` ); const data = await res.json(); const current = data.current_condition[0];
const tempC = parseFloat(current.temp_C); const temperature = units === "fahrenheit" ? tempC * 9 / 5 + 32 : tempC;
return { temperature, condition: current.weatherDesc[0].value, humidity: parseFloat(current.humidity), }; } catch (err) { throw new Error(`EXECUTION_FAILURE: Weather API error: ${err.message}`); }}Search + Summarize Pipeline — Gene Composition
Section titled “Search + Summarize Pipeline — Gene Composition”Compose two genes sequentially to search the web and summarize results.
Step 1: Use the built-in genesis-web-search gene for searching.
Step 2: Create a summarizer gene.
genes/summarizer/phenotype.json:
{ "domain": "text.summarize", "inputSchema": { "type": "object", "properties": { "text": { "type": "string", "description": "Text to summarize" }, "maxLength": { "type": "integer", "default": 200 } }, "required": ["text"] }, "outputSchema": { "type": "object", "properties": { "summary": { "type": "string" }, "wordCount": { "type": "integer" } }, "required": ["summary"] }, "version": "0.1.0", "fidelity": "Wrapped", "transparency": "Open"}genes/summarizer/index.ts:
export async function express(input: { text: string; maxLength?: number;}) { const maxLen = input.maxLength || 200; const sentences = input.text.split(/[.!?]+/).filter(Boolean);
let summary = ""; for (const sentence of sentences) { if ((summary + sentence).length > maxLen) break; summary += sentence.trim() + ". "; }
return { summary: summary.trim(), wordCount: summary.split(/\s+/).length, };}Compose them:
import { Seq, Transform } from "@rotifer/algebra";
const searchAndSummarize = Seq( "genesis-web-search", Transform((searchResult) => ({ text: searchResult.results.map(r => r.snippet).join(" "), maxLength: 200, })), "summarizer");MCP Tool Migration — Scan → Wrap → Compile
Section titled “MCP Tool Migration — Scan → Wrap → Compile”Migrate an existing MCP tool to a Rotifer gene in three steps.
Starting point: An MCP Tool
export function calculate(expression: string): number { return eval(expression); // Simplified for demo}Step 1: Scan
$ rotifer scan tools/ Found 1 candidate function: #1 calculate tools/calculator.ts:2Step 2: Wrap
$ rotifer wrap calculator --domain math.calculate --file tools/calculator.ts ✓ Gene 'calculator' wrappedThis generates:
genes/calculator/phenotype.json— auto-detected schemasgenes/calculator/index.ts— express() wrapper
Step 3: Compile to WASM
$ rotifer compile calculator ✓ Compiled to gene.ir.wasm (42KB)Now the MCP tool is a fully sandboxed Rotifer gene, ready for Arena competition.
Code Formatter Gene — Tool-Type Gene
Section titled “Code Formatter Gene — Tool-Type Gene”A pure logic gene that runs entirely within the WASM sandbox (Native fidelity).
genes/json-formatter/phenotype.json:
{ "domain": "code.format", "inputSchema": { "type": "object", "properties": { "code": { "type": "string" }, "indent": { "type": "integer", "default": 2 } }, "required": ["code"] }, "outputSchema": { "type": "object", "properties": { "formatted": { "type": "string" }, "valid": { "type": "boolean" } }, "required": ["formatted", "valid"] }, "version": "0.1.0", "fidelity": "Native", "transparency": "Open"}genes/json-formatter/index.ts:
export async function express(input: { code: string; indent?: number;}) { const indent = input.indent ?? 2; try { const parsed = JSON.parse(input.code); return { formatted: JSON.stringify(parsed, null, indent), valid: true, }; } catch { return { formatted: input.code, valid: false, }; }}Since this gene has no external dependencies (no API calls, no file I/O), it compiles to a fully self-contained WASM module with Native fidelity — the highest trust level in the Arena.