Engine reference — generated from the canonical engineering source. Do not edit this page by hand.
Contributing to ZERG
Development Setup
Prerequisites
| Dependency | Version | Purpose |
|---|---|---|
| Erlang/OTP | 29.1+ | Sol server runtime |
| rebar3 | 3.20+ | Erlang build tool |
| LuaJIT | 2.1 | Luna agent runtime |
| Python | 3.11+ | Mango framework only |
| gcc | C11+ | FFI bindings, single-binary build |
| upx | optional | Secure release binaries only — local builds pass --plain --no-upx |
| ncurses / ncursesw | 6.0+ | Luna TUI |
| libcurl | 7.68+ | Luna HTTP/SSE |
| libzmq | 4.3+ | ZMQ worker mode (optional) |
The OTP floor is Erlang/OTP 29.1+ (OTP 30+ is the forward aim; OTP 28 is not a support target).
Build and Run
Sol server:
cd server && rebar3 compile
rebar3 shell # Dev shell, Cowboy HTTP on port 21434
zerg status # Verify server is running
Luna agent:
luajit client/main.lua --configure # interactive setup wizard
luajit client/main.lua --connect tcp://127.0.0.1:5555 # Sol-fed worker (lane grants)
Mango auth service:
cd mango && pip install -e .
python server.py # Starts on port 5800
Infrastructure stack:
Production deployment is handled by wild (Crow CI + podman + runit); the
legacy deployment/infra/scripts/setup.sh was archived with the old on-host
model. Local development does not need the infra stack — Sol, Luna,
and Mango all run directly on the host. See wild/AGENTS.md §“CD Build
Execution” for the provisioning path.
Code Style
Erlang (Sol Server)
Use OTP behaviours for all stateful processes (gen_server, gen_statem, gen_event)
process_flag(trap_exit, true) in all gen_servers that own resources (OS processes, ETS, sockets)
ETS {heir, Pid} for all critical tables
logger module for all logging – never io:format
-vsn attribute on every module
binary_to_existing_atom for all external input – never list_to_atom on untrusted data
warnings_as_errors enabled in rebar3 config – all warnings are build failures
Prefix unused variables with _ (_Unused, _Ignored)
simple_one_for_one for dynamic child factories
rest_for_one for top-level supervisor
sol_config:get_env/2 for reading application environment – no direct application:get_env in modules
Module structure:
-module(sol_my_module).
-behaviour(gen_server).
-vsn("1.0").
%% API
-export([start_link/0, my_function/1]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
Lua (Luna Client)
Use cel.class (middleclass) for all new classes – see docs/cel-vision.md
Use cel.json for all JSON access – never import dkjson or JSON_luerl directly
Use cel.deep_merge / cel.deep_copy for table operations
Use FFI (ffi/process.lua, ffi/dir.lua) for filesystem and process operations – never os.execute
Module pattern: local M = {}; M.__index = M; return M (pre-middleclass modules)
Instance pattern: setmetatable({}, M)
pcall for all fallible operations
Atomic writes: write to .tmp, then os.rename
Coroutine-based async via Turbo.lua IOLoop – never blocking io.read or usleep polling
Return nil, err on failure (two-value convention)
Python (Mango)
Tornado async handlers for HTTP endpoints
BaseSystem for business logic, BaseHandler for HTTP endpoints
pytest with @pytest.mark.asyncio for async tests
ZERG CLI uses LuaJIT (zero Python dependency) – no third-party dependencies
Testing
All tests must pass with 0 new failures before merging. The env baseline has been empty since then: a new failing test is a regression to fix, never a tracked exception.
Server Tests
From the repository root (the canonical gate is the filtered runner, not
bare rebar3 eunit):
(cd server && make test-unit) # canonical filtered gate
(cd server && ERL_AFLAGS='-eunit_timeout 10s' rebar3 eunit --module=sol_integration_tests)
Test files follow test/sol_<feature>_tests.erl or test/sol_s<phase>_tests.erl naming. Use eunit ?_test and ?_assert patterns. Test pure functions directly; use meck for mocking gen_servers.
Client Tests
From the repository root:
(cd client && luajit tests/test_core.lua) # Core + agent + regression
(cd client && luajit tests/test_ffi.lua) # FFI + security
(cd client && luajit tests/test_provider.lua) # Provider + retry + OpenAI
# Run all:
(cd client && for f in tests/test_*.lua; do luajit "$f"; done)
Test files under client/tests/ (count grows as tests land —
ls client/tests/test_*.lua | wc -l) carry luna_test_functions=691 test
functions / luna_test_assertions=22038 assertions (machine-derived; see
AGENTS.counts — luna_test_functions / luna_test_assertions). The runtime pass/skip
totals shift as tests are added: run
cd client &&./run_tests.sh for the authoritative aggregate (it prints
passed/failed/skipped; the empty corpus fails loudly). Use assert
and return passed/failed counts. Mock provider available at
core/mock_provider.lua. Mock MCP server at tests/mcp_mock_server.lua.
Mango Tests
From the repository root:
(cd mango && python3 -m pytest test/ -v) # re-measure; see AGENTS.md Tests row
(cd mango && python3 -m pytest test/test_auth.py -v) # Auth tests only
Integration Tests
(cd server && ERL_AFLAGS='-eunit_timeout 10s' rebar3 eunit --module=sol_integration_tests)
(cd server && ERL_AFLAGS='-eunit_timeout 10s' rebar3 eunit --module=sol_http_e2e_zmq_roundtrip_tests)
Contract Single-Source (events & wire)
Event types, payload-key validators, wire frame field lists and MAC domain
metadata live in ONE machine-readable source: contract/events.yaml and
contract/wire.yaml (,; format decision + measured
inventory in contract/INVENTORY.md).
Adding an event:
- Add the type (aggregate + group, optional doc) to
contract/events.yaml; add a payload validator only if the type needs required keys. - Regenerate the consumers and commit them together:
python3 ci/contract_gen.py
python3 ci/contract_gen.py --check
Generated artifacts: server/src/sol_event_contract.erl (definitions +
validators), server/test/fixtures/event_contract.json,
server/test/fixtures/wire_contract.json (: the unconsumed Luna
event_types.lua seed was deleted; Luna emission literals remain the only
Luna-side truth until the emitter migration lands). CI’s contract_drift_lint fails on
a stale artifact or an emission literal outside the declared set;
event_drift_lint fails on a declared type nothing emits. The wire slice is a
verification artifact only (migration state: contract/MIGRATION.md).
PR Process
- All changes require tests. New modules, bug fixes, and refactors all need test coverage.
- Run the full test suite for the affected component before opening a PR.
- Update AGENTS.md when adding new modules, phases, or capabilities. This is the canonical project reference.
- Follow naming conventions:
Server phases:
S##(e.g., S102, S103) Client phases:L##(e.g., L75, L76) Server test files:test/sol_s<phase>_tests.erlClient test files:tests/test_<feature>.lua - Create a plan in
plan/for non-trivial changes. Include scope, focus, and test expectations. - Create a review in
review/after implementation. Document what was done, test results, and any deviations from plan.
Project Structure
server/ Sol -- Erlang/OTP orchestration platform
src/ sol_modules=489 Erlang source modules (see AGENTS.counts)
test/ unit + CT suites (see AGENTS.counts)
cli/ ZERG CLI (LuaJIT binary, cli_commands=92 commands + cli_subcommands=37 subcommands)
config/ sys.config, vm.args, production configs
priv/lua_libs/ cel.lua, fun.lua, lume.lua, JSON_luerl.lua
priv/plugins/ Bundled Lua plugins (telegram, discord)
client/ Luna -- LuaJIT agent (worker runtime)
core/ core modules (agent loop, tools, session, provider)
ui/ ~17 TUI modules (app, chatpane, inputbar, theme, markdown)
ffi/ 17 FFI bindings (curl, process, dir, zmq, md4c, sqlite3)
tests/ luna_test_functions=691 test functions / luna_test_assertions=22038 assertions
build/ Single-binary build (994KB stripped)
vendor/ Vendored libraries (turbo, ltui, fun, lume, JSON_luerl, middleclass)
mango/ Mango -- Python/Tornado auth framework
mango/ Core: systems, handlers, schemas, events, storage, plugins
test/ pytest suites (re-measure; see AGENTS.md Tests row)
docs/ User-facing documentation (docs_artifacts=70 artifacts)
plan/archive/ plan_files=1414 archived phase plans
review/archive/ historical reviews (categorized)
reference/ Reference systems and documentation (read-only)
deployment/infra/ Docker Compose stack (11 services)
ci/ CI support files (LuaJIT image, smoke test)
Key Decisions
These are settled architectural choices. Do not introduce alternatives without discussion:
Erlang/OTP for orchestration – concurrency, fault tolerance, supervision trees
LuaJIT for worker runtime – sub-10MB RAM, 994KB binary, FFI speed
Llama.cpp local-first inference – remote providers are fallback only
ZMQ for polyglot worker boundary – language-agnostic IPC at Erlang/non-Erlang boundary
Cel.lua as unified standard library – all JSON via cel.json, all OOP via cel.class
Mango as identity provider – Sol delegates auth to Mango HTTP service
No cloud API dependencies – all external calls must be explicitly configured