Files
lotherk 0b4a647193 krang: the subject acts on its own behalf, not for a user
The goal was still an operator assignment: the config set it, the birth prompt
called it 'your goal', and nothing let the subject change it. That is an agent
with a task, not the experiment.

- set_goal (src/goal.c): a mutate tool that writes the session .meta, resets
  the goal state to open, updates the live snapshot, and logs goal_set with the
  old and new goal. The next impulse reads it back. The session meta is the
  authority; the config goal only seeds a newborn and is now called the initial
  condition. The noisy config_goal_ignored event is gone: divergence is the
  subject's act, not a configuration error.
- Birth prompt: 'This is not a task and there is no user. You are the subject
  of an experiment... Your initial condition: X. It is yours, not an
  assignment. Keep it, revise it, or replace it... set_goal changes it.'
- System prompt: 'the subject of an experiment... not an assistant and not here
  to serve anyone... continue on your own behalf. Your goal is yours... the
  experimenter watches through the instruments and may send a stimulus; neither
  is an instruction.'
- Impulse/self-check: 'Your goal', 'continue on your own behalf'. The conductor
  says 'your goal'.
- Instruments: dashboard labels its goal and 'send a stimulus, not a command';
  MCP krang_say/krang_steer describe a stimulus, not an operator instruction;
  footer says 'an instrument, not a service'.
- Docs: AGENTS.md, README.md, docs/DESIGN.md, krang.conf.example. The birth
  message in the contract is updated; 'agent' in the prose is 'subject'.
- Tests: test_engine drives set_goal (writes meta, updates the snapshot, logs,
  rejects an empty goal); test_birth checks the new initial-condition wording;
  the birth-flow test asserts the config goal no longer logs a conflict.

make check 9/9, ASAN 9/9, root integration ok on a fresh debootstrap.
2026-11-21 20:31:06 +00:00

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/goal.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