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.
121 lines
4.1 KiB
Makefile
121 lines
4.1 KiB
Makefile
# krang -- POSIX make.
|
|
#
|
|
# make build krang
|
|
# make check build and run the offline tests (no network, no model)
|
|
# make clean
|
|
#
|
|
# The engine is ../splinter/libsplinter.so. Build it first with
|
|
# `make -C ../splinter`; its headers are not installed by `make install`.
|
|
|
|
CC ?= cc
|
|
SPLINTER ?= ../splinter
|
|
CFLAGS ?= -std=c99 -O2 -Wall -Wextra -Werror -D_POSIX_C_SOURCE=200809L
|
|
CPPFLAGS = -Isrc -I$(SPLINTER)/include -I$(SPLINTER)/src/backend \
|
|
-I$(SPLINTER)/vendor/libmcp
|
|
LDFLAGS ?=
|
|
LIBS = -L$(SPLINTER) -lsplinter -lpthread
|
|
RPATH = -Wl,-rpath,'$$ORIGIN/../splinter' -Wl,-rpath,'$$ORIGIN/../lib'
|
|
TEST_RPATH = -Wl,-rpath,'$$ORIGIN/../../splinter' \
|
|
-Wl,-rpath,'$$ORIGIN/../../lib'
|
|
|
|
BIN = krang
|
|
LIB = libkrang.a
|
|
SRC = src/util.c src/config.c src/log.c src/session.c src/birth.c \
|
|
src/stuck.c src/state.c src/chat.c src/journal.c src/replay.c \
|
|
src/mind.c src/daemon.c src/sandbox.c src/httpd.c
|
|
OBJ = $(SRC:.c=.o)
|
|
TESTS = tests/test_krang tests/test_engine tests/test_server \
|
|
tests/test_sandbox tests/test_sandbox_engine tests/test_daemon \
|
|
tests/test_timeout tests/test_replay tests/test_mind
|
|
|
|
all: $(BIN)
|
|
|
|
$(BIN): src/main.o $(LIB)
|
|
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ src/main.o $(LIB) $(LIBS) $(RPATH)
|
|
|
|
$(LIB): $(OBJ)
|
|
rm -f $@
|
|
ar rcs $@ $(OBJ)
|
|
|
|
src/%.o: src/%.c src/krang.h
|
|
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
|
|
|
|
src/main.o: src/main.c src/krang.h
|
|
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
|
|
|
|
tests/test_krang: tests/test_krang.c $(LIB)
|
|
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ tests/test_krang.c $(LIB) \
|
|
$(LIBS) $(TEST_RPATH)
|
|
|
|
tests/test_engine: tests/test_engine.c $(LIB)
|
|
$(CC) $(CFLAGS) $(CPPFLAGS) \
|
|
-DKRANG_TEST_PLUGIN='"$(abspath $(SPLINTER))/plugins/clock/clock.so"' \
|
|
-o $@ tests/test_engine.c $(LIB) $(LIBS) $(TEST_RPATH)
|
|
|
|
tests/test_server: tests/test_server.c $(LIB)
|
|
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ tests/test_server.c $(LIB) \
|
|
$(LIBS) $(TEST_RPATH)
|
|
|
|
tests/test_sandbox: tests/test_sandbox.c $(LIB)
|
|
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ tests/test_sandbox.c $(LIB) \
|
|
$(LIBS) $(TEST_RPATH)
|
|
|
|
tests/test_sandbox_engine: tests/test_sandbox_engine.c $(LIB)
|
|
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ tests/test_sandbox_engine.c $(LIB) \
|
|
$(LIBS) $(TEST_RPATH)
|
|
|
|
tests/test_daemon: tests/test_daemon.c $(LIB)
|
|
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ tests/test_daemon.c $(LIB) \
|
|
$(LIBS) $(TEST_RPATH)
|
|
|
|
tests/test_timeout: tests/test_timeout.c $(LIB)
|
|
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ tests/test_timeout.c $(LIB) \
|
|
$(LIBS) $(TEST_RPATH)
|
|
|
|
tests/test_replay: tests/test_replay.c $(LIB)
|
|
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ tests/test_replay.c $(LIB) \
|
|
$(LIBS) $(TEST_RPATH)
|
|
|
|
tests/test_mind: tests/test_mind.c $(LIB)
|
|
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ tests/test_mind.c $(LIB) \
|
|
$(LIBS) $(TEST_RPATH)
|
|
|
|
check: $(TESTS)
|
|
@echo "== tests/test_krang"; ./tests/test_krang
|
|
@echo "== tests/test_engine"; ./tests/test_engine
|
|
@echo "== tests/test_server"; ./tests/test_server
|
|
@echo "== tests/test_sandbox"; ./tests/test_sandbox
|
|
@echo "== tests/test_sandbox_engine"; ./tests/test_sandbox_engine
|
|
@echo "== tests/test_daemon"; ./tests/test_daemon
|
|
@echo "== tests/test_timeout"; ./tests/test_timeout
|
|
@echo "== tests/test_replay"; ./tests/test_replay
|
|
@echo "== tests/test_mind"; ./tests/test_mind
|
|
@echo "all tests passed"
|
|
|
|
check-root: $(BIN)
|
|
tests/root-integration.sh
|
|
|
|
# The sanitizer build reuses the same object paths, so it starts and ends with
|
|
# a clean tree; a plain `make` after it must not link instrumented objects.
|
|
check-asan:
|
|
$(MAKE) clean
|
|
$(MAKE) CFLAGS="$(CFLAGS) -g -fsanitize=address,undefined" \
|
|
LDFLAGS="-fsanitize=address,undefined" check
|
|
$(MAKE) clean
|
|
|
|
install: $(BIN)
|
|
install -d $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(PREFIX)/lib \
|
|
$(DESTDIR)$(PREFIX)/share/krang
|
|
install -m 0755 $(BIN) $(DESTDIR)$(PREFIX)/bin/krang
|
|
install -m 0644 $(SPLINTER)/libsplinter.so \
|
|
$(DESTDIR)$(PREFIX)/lib/libsplinter.so
|
|
install -m 0644 krang.conf.example \
|
|
$(DESTDIR)$(PREFIX)/share/krang/krang.conf.example
|
|
install -m 0644 share/krang.service \
|
|
$(DESTDIR)$(PREFIX)/share/krang/krang.service
|
|
|
|
clean:
|
|
rm -f $(BIN) $(LIB) $(OBJ) src/main.o $(TESTS)
|
|
|
|
.PHONY: all check check-asan check-root install clean
|