Restart persistence. A daemon that forgets its own history on every restart is not one experiment. kreplay_events() reads the append-only event log once at startup and rebuilds the impulse ledger (with ids), token/cost/step totals, the last outcome, the stuck ladder, the blocked clock and the recent-start count. The engine's counters start at zero on each open; the surfaces add them to the restored base, so the dashboard does not reset. A restored blocked goal keeps its hour of quiet, three starts within five minutes back off, and an empty session with a non-empty event log is recorded as session_reset instead of silently looking new. The conductor. Before an impulse the daemon measures its own vitals (context against the window and the compaction threshold, cost, stuck level, turn failures, impulses since the last goal, the age of THREADS.md, session size) and lets five drives compete: survive, reflect, maintain, explore, goal. The winning drive, its reason and the vitals are injected into the prompt and shown on the dashboard. The model still chooses the action; the conductor chooses what the turn is about. This is the control architecture from the body/drives/conductor argument, borrowed without the consciousness claim. Session counting is now incremental: only bytes appended since the last look are scanned, the offset stops at the last newline so a torn tail is recounted, and a truncated file resets the count. Tests: test_replay (synthetic log + two kdaemon_run lifetimes, same birth, ledger ids 1 and 2, cumulative totals), test_mind (goal/maintain/explore/ survive/reflect, prompt and snapshot), test_krang's session counter (append, torn tail, truncation). make check is nine suites; ASAN is green; the root integration still passes on a fresh debootstrap. Docs: AGENTS.md, README.md and docs/DESIGN.md; the latter maps the video's blueprint (body, drives, self-model, conductor, continuous feedback) to krang.
7.9 KiB
krang
An autonomous agent daemon built on the splinter engine. The design notes and the prior art are in docs/DESIGN.md.
krang exists to test one hypothesis: what an assistant lacks is not intelligence but a regular impulse to continue. It is born once, keeps one session forever, wakes on its own cadence, works on a goal, notices when it is stuck, changes approach, and records what happened. There is no user to ask.
It lives in a chroot. The process starts as root only to build that world, then drops to an unprivileged uid and applies two one-way restrictions: Landlock for paths and seccomp-bpf for syscalls on Linux (the design is pledge/unveil; the OpenBSD backend is not implemented yet).
Build
make -C ../splinter # libsplinter.so and the headers
make
make check # no network, no key, no model
libsplinter.so has no SONAME; the binary carries an rpath to ../splinter.
Rebuild krang whenever splinter changes.
Configure
sudo install -d /etc/krang
sudo install -m 0600 krang.conf.example /etc/krang/krang.conf
$EDITOR /etc/krang/krang.conf
The goal is used only when the session is empty: that is the newborn. After
that the goal in the session's .meta is the life's goal.
Prepare and start
sudo krang --prepare-rootfs --config /etc/krang/krang.conf
krang --plan --config /etc/krang/krang.conf # read the plan, do not start
sudo krang --config /etc/krang/krang.conf # start
Do not start it casually: once it has a provider it will act on its own. The
service unit in share/krang.service restarts it after an unexpected exit; a
deliberate stop is systemctl stop krang (or SIGTERM).
What it offers
- Dashboard
http://127.0.0.1:8096/— state, goal, the conductor's drive and reason, impulses, turns, tool calls, failures, tokens, cost, context, session, compactions, stuck level, last outcome and error, working notes, and a chat box. - HTTP API —
/healthz,/api/state,/api/impulses,/api/log,/api/history,/api/threads,/api/tools,/api/sandbox,/api/config,/api/events,POST /api/say,GET /api/say/<id>,POST /mcp. - MCP — newline-delimited JSON-RPC on
127.0.0.1:8098. Tools:krang_state,krang_impulses,krang_events,krang_session,krang_history,krang_tools,krang_sandbox,krang_config,krang_say,krang_say_status,krang_steer,krang_cancel. Nokrang_approve: krang never asks. - Chat from either surface goes into the same session as the daemon's own impulses. One turn at a time; a message that arrives mid-turn is queued.
The model also gets journal_search (read-only): it searches the full session
log, including the history compaction dropped.
The conductor
A timer alone is not a reason. Before every impulse the daemon measures its own
state - context against the window and the compaction threshold, cost against
the cap, stuck level, turn failures, impulse count, the age of THREADS.md,
session size - and lets five drives compete:
| drive | when it wins | what the impulse is for |
|---|---|---|
survive |
context or cost is near its limit | the smallest step; write down what compaction must not lose |
reflect |
the stuck ladder fired | find the mistake, change the approach |
maintain |
notes are missing or stale | bring THREADS.md and skills/ up to date |
explore |
twenty impulses without a completed goal, then every eighth | try one new capability, bounded |
goal |
nothing more urgent | the smallest useful step on the goal |
The chosen drive, its reason and the vitals go into the impulse and onto the dashboard. The model still chooses the action; the conductor only chooses what the turn is about. This is the engineering version of the body/drives/ conductor loop: constraints produce drives, drives compete for attention, and the consequences feed the next decision.
Restart
The event log is the life, not a copy of it. At startup kreplay_events()
reads it once and rebuilds the impulse ledger (with ids), the token/cost/step
totals, the last outcome, the stuck ladder, the blocked clock and the
recent-start count. The engine's own counters are added on top, so the
dashboard never starts again at zero. A restored blocked goal keeps its hour
of quiet; three starts within five minutes back off instead of spinning. The
session is opened with resume, so there is no second birth.
Splinter plugins are opt-in: plugin = /absolute/plugin.so (max 8). The root
phase bind-mounts each plugin and libsplinter.so read-only into /opt/krang
and sets LD_LIBRARY_PATH; only the path is wired, not the plugin's own
plugin NAME { } config block yet. The root integration loads the clock plugin
inside the chroot as a proof.
If a token is set in the config, loopback is not required and every request
needs it (Authorization: Bearer, ?token=, or the MCP AUTH <token> line).
Without a token krang refuses to bind to a non-loopback address.
A loopback dashboard without a token is still a local service, so the HTTP
surface checks the names a browser sends: a request whose Host is not a
loopback name is refused (DNS rebinding), and an Origin that does not match
the Host is refused (cross-site requests). There is no CORS grant; the
dashboard is same-origin.
The experiment log
state/sessions/krang.jsonlis the conversation and the model's memory.state/events.jsonlis the append-only experiment log. It is opened by the root phase, owned by root, mode 0600, and written through the inherited descriptor; the sandbox user can neither open nor truncate it. The fd isFD_CLOEXEC, so theruntool's children do not inherit it.- The dashboard, HTTP API and MCP all read the same snapshot and the same ring of recent events. There is no second counter.
Tests
make check
make check-asan
./krang --check --config krang.conf.example # config + plan + scripted turn
./krang --self-test # one scripted turn, no network
sudo tests/root-integration.sh # debootstrap + chroot + drop
make check covers config parsing and path guards, the birth prompt, stuck
detection, the snapshot/HTTP/MCP surfaces (including the Host/Origin refusal
and token check), a real scripted engine turn, the engine under Landlock +
seccomp, kdaemon_run itself (one birth impulse on the script transport, then
a clean stop), a turn cancelled by max_turn_seconds, restart replay (ledger,
totals, stuck and blocked) with a second daemon run that continues the first,
incremental session counting across appends, a torn tail and truncation, and
the conductor's goal/maintain/explore/survive decisions. The sandbox tests
prove Landlock denies a write outside the allowed set and seccomp denies
mount(2) while fork/execve/network still work.
tests/root-integration.sh is the root-only proof: it prepares a real rootfs
with debootstrap, enters it with --sandbox-test, loads the clock plugin from
the splinter tree, and checks uid 65534, mount denial, plugin execution,
event-log ownership/mode, session ownership, and that the sandbox uid cannot
read the event log. It never starts the autonomous daemon or calls a provider.
Safety notes
- chroot is isolation, not a jail against root. krang runs as an unprivileged uid after setup and has no path back.
- The provider key is readable by the daemon; assume the model can eventually
see anything in its environment. Use a throwaway, budget-capped key. The
runtool's environment is filtered withsp_secret_env_add(), and the event log redacts the configured key. - The network namespace is shared.
runcan reach the network; the chroot does not change that. - The session log is the model's memory. It is writable by the sandbox uid; the experiment log is not.
- User namespaces and kernel bugs remain outside the model. The layers raise the cost of an escape; they are not a proof.