n8n guide

Clean-room workflow runtime architecture, structural validation, typed LMCode graph execution, neutral connector specifications, and bounded transport.

Overview

The lmctl-ai/n8n repository is a clean-room, MIT-licensed workflow engine that executes n8n-style workflow JSON documents as data without importing any upstream n8n code. It splits workflow execution across three layers: LMScript (src/validate.lms and src/run.lms) for pre-flight JSON Schema and graph-topology validation, LMCode bytecode for typed node traversal and expression resolution, and a compact Go host executable (./build/lmflow-host built on lmcode-go) for credential injection and bounded JSON HTTP transport.

Ten-step workflow execution path

Every invocation of src/run.lms follows a strict ten-step pipeline:

  1. Schema validation: src/validate.lms validates WORKFLOW.json against schema/workflow-v1.schema.json and CONNECTOR.json against schema/connector-v1.schema.json.
  2. Graph and parameter validation: LMScript verifies node IDs and names, confirms that node 0 is n8n-nodes-base.manualTrigger, checks that every subsequent node matches the connector nodeType and has exactly one incoming main connection and at most one outgoing main branch, verifies required operation parameters, and validates expression syntax.
  3. Bytecode compilation: src/run.lms compiles the embedded _lmcode_ block against internal/host/schema.json (lmflow_host_v1).
  4. Graph traversal: the LMCode program loads input("workflow") and input("connector"), seeds a string map of node outputs with the manual trigger parameters, and steps along main connections within a bounded node budget (nodes.len() + 1).
  5. Whole-field expression resolution: parameter strings matching ={{ $json.path.to.value }} are resolved against the immediately preceding node output JSON while preserving exact scalar types (integer, float, string, or boolean).
  6. Parameter mapping: n8n-style nodeField names (such as chatId) are mapped to provider JSON body keys (such as chat_id) using json_put.
  7. External credential lookup: the Go host resolves credential(id, field) from the separate CREDENTIALS.json file and substitutes the placeholder (such as {token}) in the operation path.
  8. Bounded HTTP transport: http_post_json(url, body) sends an application/json POST request and returns an HttpResponse handle exposing status() and json().
  9. Envelope verification: the LMCode program verifies that status() is in [200, 299] and that the provider successField (such as ok) is a boolean true; otherwise it extracts the provider errorField (such as description) and calls workflow_fail(message).
  10. Result contract handoff: the final node JSON response is assigned to $return, verified against the non-nullable Json result contract of lmflow_host_v1, and formatted to stdout.
# Run a validated workflow with an explicit local mock or base URL override
LMFLOW_BASE_URL=http://127.0.0.1:8080 lmscript src/run.lms \
  examples/telegram.workflow.json \
  connectors/telegram.json \
  tests/fixtures/credentials.json

Supported expression subset and type preservation

Unlike upstream n8n, which evaluates arbitrary JavaScript inside expressions, this runtime accepts only deterministic whole-field dot-path selectors of the form ={{ $json.field.subfield }} matching the regular expression ^=\{\{ \$json(\.[A-Za-z_][A-Za-z0-9_]*)+ \}\}$.

Expressions always read the JSON response of the immediately preceding node in the linear chain and must resolve to a non-null scalar JSON value (string, number, or boolean); arrays, objects, and null values are rejected with workflow_fail. In the reference Telegram workflow (Manual Trigger -> Telegram sendMessage -> Telegram getChat), the manual trigger starts with chatId 41, the mocked sendMessage response returns chat.id 42, and getChat receives numeric 42 via ={{ $json.result.chat.id }}, proving both dynamic propagation and numeric type fidelity.

Neutral connector specifications

Connector behavior is driven entirely by declarative JSON files under connectors/ authored from public provider specifications (for example, connectors/telegram.json from the public Telegram Bot API contract). A connector specification declares specVersion (1), name, documentation URL, baseUrl, nodeType, credentialType, credentialField, successField, errorField, and an array of operations. Each operation maps a pair of (resource, nodeOperation) values to an HTTP method (POST), a path containing the credential placeholder (/{credentialField}), and a parameters dictionary mapping provider field names to {nodeField, required} descriptors.

Credential isolation and transport bounds

Workflow files store only symbolic credential references (for example, {"telegramApi": {"id": "telegram-bot"}}). Actual secret values live in a separate file passed as the third CLI argument (use git-ignored credentials.local.json for local development). Because providers like Telegram embed the secret token in the request URL path, the Go HTTP client sanitizes all transport error messages so resolved request URLs are never printed or logged.

The Go transport enforces strict safety bounds on every outbound request: HTTP POST with Content-Type: application/json only, a 10-second client timeout, a 1 MiB maximum request body size, a 1 MiB maximum response body size, HTTP redirects disabled, and strict JSON response decoding with UseNumber().