How xagi-lab/melra works
Purpose and Entry Points
MELRA is an agent-independent, durable execution kernel for bounded external effects. It owns policy, approval, persistence, execution, verification, and auditable receipts; LLMs and harnesses remain responsible for reasoning and planning.
Primary entry points:
• CLI and stdio server: apps/cli/src/bin.ts, apps/cli/src/index.ts
• Runtime composition, MCP, and HTTP transports: packages/server/src/runtime.ts, packages/server/src/mcp-server.ts, packages/server/src/http-server.ts
• TypeScript and Python clients: packages/sdk-ts/src/index.ts, sdk-py/src/melra/client.py
Public Contract and Workflow Model
Strict schemas define bounded operations, tasks, workflows, events, and node kinds. Workflows compose effect nodes with approval, conditions, parallelism, loops, checkpoints, compensation, human input, and delegation.
• packages/protocol/src/index.ts
• packages/protocol/src/workflow.ts
• packages/receipt-schema/src/index.ts
Clients reach one common runtime through MCP, CLI, SDK, or token-protected loopback HTTP. Transport is a boundary only; it must not create alternate execution semantics.
Task Lifecycle and Durable Control Plane
runtime-core implements the effect lifecycle: plan/persist, policy recheck, approval gate, idempotent execution, cancellation/budgets, verification, recovery, event emission, and task/workflow state transitions. Mutations interrupted after dispatch are not silently replayed; they require reconciliation or recovery handling.
• packages/runtime-core/src/task-controller.ts
• packages/runtime-core/src/workflow-controller.ts
• packages/runtime-core/src/workflow-graph.ts
• packages/runtime-core/src/verification-gate.ts
Key control flow: request → schema validation/classification → plan-time policy → durable record → execution-time policy/approval → adapter → evidence verification → event/projection → receipt.
Governance, Identity, and Secrets
Policy distinguishes reads, mutations, and destructive actions; it constrains paths, commands, network destinations, and capabilities. Approval is exact, scoped, and expiring. Server-side OAuth/client identity and the credential broker ensure agents receive scoped capabilities rather than raw credentials.
• packages/policy-core/src/index.ts
• packages/policy-core/src/network-policy.ts
• packages/policy-core/src/credentials.ts
• packages/server/src/oauth.ts
Deployment mode is material: developer mode governs requested effects; enforced mode rejects unsafe-local operation, non-loopback binding, and self-registration assumptions.
Persistence, Encryption, and Audit Evidence
SQLite is the local transactional system of record for tasks, workflows, events, idempotency state, evidence, and projections. Exact executable payloads are protected with an on-host key and encrypted envelopes; receipts are redacted and certificate-oriented.
• packages/storage-sqlite/src/index.ts
• packages/storage-sqlite/src/workflow-store.test.ts
• packages/runtime-core/src/payload-cipher.ts
• packages/server/src/payload-key.ts
Operational memory is separate from agent semantic memory: it stores scoped, redacted, provenance-aware knowledge about prior effects.
• packages/memory/src/index.ts
Verification and Reference Effect Adapters
Verifier predicates determine whether an action’s declared outcome is proven and annotate evidence strength based on source (adapter execution, state reread, independent channel, or semantic observation).
• packages/verifier-core/src/index.ts
• packages/verifier-core/src/probe.ts
Adapters are downstream capability boundaries, not bypasses of the core pipeline:
• Filesystem confinement and atomic operations: packages/file-runtime/src/index.ts
• Shell-free supervised processes: packages/terminal-runtime/src/index.ts
• Isolated Playwright browser sessions, stable DOM, and destination pinning: packages/browser-runtime/src/browser-connection.ts, packages/browser-runtime/src/stable-dom.ts, packages/browser-runtime/src/pinning-proxy.ts
• Local desktop controls: packages/computer-runtime/src/index.ts
• Governed HTTP/API effects: packages/http-runtime/src/index.ts
Runtime and Infrastructure
The primary runtime is strict TypeScript on Node.js, organized as a pnpm workspace. SQLite provides local durable state; Playwright powers browser automation. Supported execution environments include macOS, Linux, and Windows, with Docker packaging via Dockerfile and compose.yaml. Python is used for the SDK and browser-agent benchmark harness.
• Dockerfile
• compose.yaml
• benchmarks/browser-agent/src/melra_browser_bench/runner.py
Main entry points: task-controller.ts Task controller · runtime.ts Runtime composition · workflow-controller.ts Workflow controller · index.ts SQLite system of record
Components 18
Clients & Transports
Multiple interfaces share one runtime.
- CLI / stdio
apps/cli/src/bin.ts - TypeScript SDK
packages/sdk-ts/src/index.ts - Python SDK
sdk-py/src/melra/client.py - Runtime composition · Composes MCP and loopback HTTP over the common control plane.
packages/server/src/runtime.ts
Durable Control Plane
Lifecycle orchestration and workflow execution.
- Task controller · Plans, persists, gates, executes, recovers, and emits task transitions.
packages/runtime-core/src/task-controller.ts - Workflow controller · Runs durable workflow state transitions and control nodes.
packages/runtime-core/src/workflow-controller.ts - Workflow graph
packages/runtime-core/src/workflow-graph.ts
Governance & Security
Policy, approval, identity, and payload protection.
- OAuth & client identity · Issues scoped capabilities instead of exposing raw credentials.
packages/server/src/oauth.ts - Policy engine · Classifies effects and constrains capabilities, paths, commands, and destinations.
packages/policy-core/src/index.ts - Credential broker
packages/policy-core/src/credentials.ts - Payload encryption · Encrypts exact executable payloads with an on-host key.
packages/runtime-core/src/payload-cipher.ts
State & Evidence
Durable records, verification, and receipts.
- Receipt schema
packages/receipt-schema/src/index.ts - SQLite system of record · Stores tasks, workflows, events, idempotency, evidence, and projections.
packages/storage-sqlite/src/index.ts - Verification gate · Proves declared outcomes and grades evidence strength.
packages/runtime-core/src/verification-gate.ts - Operational memory · Stores redacted, provenance-aware knowledge about prior effects.
packages/memory/src/index.ts
Effect Boundaries
Governed downstream capability adapters.
- Governed effect adapters · Filesystem, process, browser, desktop, and HTTP effects remain downstream of the core pipeline.
packages/file-runtime/src/index.ts
Other components
- Protocol schemas · Defines operations, tasks, workflows, events, and node kinds.
packages/protocol/src/index.ts - Workflow model
Connections 20
- CLI / stdio → Runtime composition: invokes
- TypeScript SDK → Runtime composition: requests
- Python SDK → Runtime composition: requests
- Runtime composition → OAuth & client identity: authenticates clients
- Runtime composition → Task controller: dispatches
- Task controller → Protocol schemas: validates request
- Task controller → Policy engine: plan and execution recheck
- Task controller → SQLite system of record: persists lifecycle and idempotency
- Task controller → Payload encryption: protects executable payload
- Task controller → Credential broker: obtains scoped capability
- Task controller → Governed effect adapters: executes approved effect
- Governed effect adapters → Verification gate: supplies execution evidence
- Task controller → Verification gate: requires outcome proof
- Verification gate → SQLite system of record: records evidence
- SQLite system of record → Receipt schema: projects auditable receipt
- Task controller → Operational memory: records redacted operational knowledge
- Workflow controller → Workflow graph: interprets
- Workflow controller → Workflow model: validates workflow
- Workflow controller → Task controller: orchestrates effect nodes
- Workflow controller → SQLite system of record: persists workflow state