Files
splinter/Makefile
T
lotherk fa16bfd0a9 foreign: adopt a claude, hermes or opencode session as a splinter session
Another harness's conversation is not a session until splinter can resume
it. plugins/foreign reads the three stores that already exist on the
machine - ~/.claude/projects/<slug>/<id>.jsonl, <root>/state.db (and
profiles/*/state.db) and opencode.db's session_v2/session_message - and
offers four tools plus /foreign:

  list, search TEXT, read SOURCE ID, import SOURCE ID

The stores are read with sqlite3 -readonly: an import copies, it never
moves. Reasoning blocks are dropped on the way in, because a provider does
not accept another model's thinking as evidence. Tool calls arrive with
their results in place, which is what makes the imported session worth
resuming instead of retyping.

import writes a real splinter session: the conversation as a replayable
jsonl, and a .meta with the source's title, its start time and *its*
working directory. So /open continues it in the chat,
--session-id <id> --resume in a shell, and -c finds it in the directory the
conversation actually ran in. The marker foreign=<source>:<id> survives
every later reopen, which needed the core's .meta sidecar to carry keys it
does not own.

Building this found nine bugs, each one seen red before it was green:

  - four use-after-frees: mcp_arg_string returns a pointer *into* the parse
    tree, read after mcp_json_free. That garbage in `only`/`src` was why a
    list of three stores answered "no sessions" and named AÃ_Â¥U.
  - sql_json took "no rows" for a failure (NULL), so every empty answer
    looked like a broken database.
  - args_split never terminated its buffers: /foreign list became
    "unknown subcommand 'list('".
  - path_join(dir, id, ".meta") built dir/id/.meta, so the sidecar landed
    in a subdirectory.
  - claude_slug_dir had the sign inverted and returned -1 for every
    non-empty cwd, so the project directory was never found.
  - sp_session_open overwrote cwd with getcwd() on *every* open, though the
    comment beside it promised the opposite: imports claimed the directory
    they were imported from and -c then picked the wrong session.
  - hermes_text ran strncmp(p, "\x00json:", 6) on an empty content, a
    one-byte allocation - heap-buffer-overflow, found by ASAN. The marker is
    stripped in SQL anyway.
  - hermes_calls never freed the root node on the object path (5456 bytes
    over 42 allocations).
  - list_any reported strerror(errno) with errno never set: a real file with
    the wrong schema read as "No such file or directory". The SQL reason is
    passed through now.

Checked end to end against the stores on this machine: claude 64 sessions,
opencode 25, hermes 0 (both hermes databases here are empty, count(*) = 0).
A real opencode session of 150 messages reads back with its tool output; one
of 75 imports with the right cwd and title, --resume sends its history, and
-c from the source directory opens it.

tests/sh/port.sh comes along: the shell tests guessed a port with
20000 + $$ % 30000 and on 2026-11-21 landed on one dtsession held. The fake
died, curl got an answer from dtsession, and twenty checks blamed the
gateway. They ask the kernel for a free port now.
2026-11-21 21:26:43 +00:00

416 lines
23 KiB
Makefile

# splinter -- POSIX make for our own code, GNU make only for the vendored curses.
#
# make libsplinter.so, the splinter binary, the example plugin
# make check builds and runs every test binary
# make curses builds the vendored NetBSD curses explicitly
# make clean removes generated files only
#
# The layout is deliberate: the backend lives in libsplinter.so (src/backend,
# the engine and everything it owns). The front ends are src/frontend/curses.c
# (the screen), src/frontend/protocol.c (the engine on a socket) and
# src/frontend/client.c (the reference client); src/main.c launches them.
# Every one of them links that single library, so there is exactly one copy of
# each symbol in the process. Two copies would mean two registries.
CC ?= cc
CFLAGS ?= -std=c99 -O2 -Wall -Wextra -Werror -D_POSIX_C_SOURCE=200809L \
-fPIC -Iinclude -Isrc/backend -Isrc/frontend -Ivendor/libmcp -Ivendor/netbsd-curses/libcurses
LDFLAGS ?=
LIBS ?= -lpthread
PREFIX ?= /usr/local
CURSES_DIR = vendor/netbsd-curses
CURSES_A = $(CURSES_DIR)/libcurses/libcurses.a \
$(CURSES_DIR)/libterminfo/libterminfo.a
LIB = libsplinter.so
LIBOBJ = src/backend/buf.o src/backend/tool.o src/backend/session.o src/backend/conv.o src/backend/compact.o src/backend/transport.o \
src/backend/json.o src/backend/sse.o src/backend/openai.o src/backend/transport_openai.o \
src/backend/anthropic.o src/backend/transport_anthropic.o src/backend/builtin.o \
src/backend/agent.o src/backend/theme.o src/backend/palettes.o src/backend/decomp.o src/backend/i18n.o src/backend/delegate.o src/backend/telegram.o src/backend/log.o src/backend/cmdscript.o src/backend/folder.o src/backend/interview.o src/backend/ack.o src/backend/mcpserver.o src/backend/mcpsession.o src/backend/skills.o src/backend/user.o src/backend/prompt.o src/backend/config.o src/backend/plugin.o src/backend/curl.o src/backend/swarm.o src/backend/provstate.o src/backend/md.o src/backend/tgmd.o src/backend/b64.o src/backend/a2aserver.o src/backend/providers.o src/backend/usage.o src/backend/confblock.o src/backend/embed.o src/backend/agents.o src/backend/engine.o src/backend/http.o src/backend/openai_server.o src/backend/catalogs.o
# buildinfo.o is separate: buildinfo.c is generated from the objects below.
LIBOBJ_ALL = $(LIBOBJ) src/backend/buildinfo.o
BIN = splinter
BINOBJ = src/main.o src/frontend/curses.o src/frontend/protocol.o \
src/frontend/ui_local.o src/frontend/ui_remote.o
CLIENT = splinterctl
CLIENTOBJ = src/frontend/client.o
PLUGIN = plugins/clock/clock.so plugins/lcm/lcm.so plugins/cps/cps.so \
plugins/cli/cli.so plugins/focus/focus.so plugins/mcp/mcp.so \
plugins/ring/ring.so plugins/reminder/reminder.so \
plugins/kids/kids.so plugins/status/status.so plugins/processes/processes.so \
plugins/provider/provider.so \
plugins/scheduler/scheduler.so \
plugins/a2a/a2a.so \
plugins/junction/junction.so \
plugins/self/self.so \
plugins/cache/cache.so \
plugins/session/session.so \
plugins/foreign/foreign.so
TESTS = tests/test_buf tests/test_tool tests/test_session tests/test_conv \
tests/test_transport tests/test_agent tests/test_openai \
tests/test_theme tests/test_plugin tests/test_skills tests/test_telegram tests/test_delegate tests/test_builtin tests/test_ascii tests/test_ack tests/test_i18n tests/test_config tests/test_focus tests/test_sse tests/test_anthropic tests/test_cli tests/test_compactor tests/test_corecompact tests/test_secrets tests/test_mcpclient tests/test_kids tests/test_lifecycle tests/test_md tests/test_tgmd tests/test_providers tests/test_b64 tests/test_pause tests/test_swarm tests/test_provstate tests/test_usage tests/test_agents tests/test_confblock tests/test_jobs tests/test_engine tests/test_self tests/test_fuzz \
tests/test_sessiontools tests/test_embed tests/test_foreign
RPATH = -Wl,-rpath,'$$ORIGIN'
PLUGIN_RPATH = -Wl,-rpath,'$$ORIGIN/../..'
TEST_RPATH = -Wl,-rpath,'$$ORIGIN/..'
all: $(LIB) $(BIN) $(CLIENT) $(PLUGIN)
# The vendored tree ships a GNUmakefile; this is the only place that needs GNU
# make, and it is why the comment above says so out loud.
$(CURSES_A):
cd $(CURSES_DIR) && $(MAKE) -f GNUmakefile libcurses/libcurses.a \
libterminfo/libterminfo.a
curses: $(CURSES_A)
src/backend/catalogs.c: share/locale/de.msg share/locale/en.msg share/locale/pt_BR.msg tools/embed_catalogs.sh
sh tools/embed_catalogs.sh share/locale/*.msg > $@
# The build stamp --version prints. It is regenerated only when one of the
# objects it describes is newer, so a no-op make keeps the old stamp: the
# stamp says when this binary was actually built, not when make last ran.
# The revision is included because 0.1.0 does not tell two builds apart.
src/backend/buildinfo.c: $(LIBOBJ) $(BINOBJ)
@{ \
rev=`git rev-parse --short HEAD 2>/dev/null` || rev=unknown; \
if [ -n "`git status --porcelain --untracked-files=no 2>/dev/null | head -n 1`" ]; then \
rev="$$rev-dirty"; \
fi; \
printf '/* generated by make: the build stamp of this binary */\nconst char *sp_build_time = "%s";\nconst char *sp_build_rev = "%s";\n' \
"`date '+%Y-%m-%d %H:%M:%S %Z'`" "$$rev"; \
} > $@
$(LIB): $(LIBOBJ_ALL) $(CURSES_A)
$(CC) -shared -o $@ $(LIBOBJ_ALL) $(CURSES_A) $(LIBS)
# curses belongs to the front end, not to the library: a plugin that drew into
# a WINDOW would be a plugin holding the UI thread's state.
# The reference client links the library for the JSON it cannot be bothered to
# write twice, but never the curses code and never the engine's internals.
$(CLIENT): $(CLIENTOBJ) $(LIB)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(CLIENTOBJ) -L. -lsplinter $(RPATH) \
$(LIBS)
$(BIN): $(BINOBJ) $(LIB)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(BINOBJ) -L. -lsplinter $(RPATH) \
$(CURSES_A) $(LIBS)
plugins/clock/clock.so: plugins/clock/clock.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/clock/clock.c -L. -lsplinter \
$(PLUGIN_RPATH) $(LIBS)
plugins/lcm/lcm.so: plugins/lcm/lcm.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/lcm/lcm.c -L. -lsplinter \
$(PLUGIN_RPATH) $(LIBS)
plugins/session/session.so: plugins/session/session.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/session/session.c -L. -lsplinter \
$(PLUGIN_RPATH) $(LIBS)
plugins/foreign/foreign.so: plugins/foreign/foreign.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/foreign/foreign.c -L. -lsplinter \
$(PLUGIN_RPATH) $(LIBS)
plugins/cli/cli.so: plugins/cli/cli.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/cli/cli.c -L. -lsplinter \
$(PLUGIN_RPATH) $(LIBS)
plugins/ring/ring.so: plugins/ring/ring.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/ring/ring.c -L. -lsplinter \
$(PLUGIN_RPATH) $(LIBS)
plugins/kids/kids.so: plugins/kids/kids.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/kids/kids.c -L. -lsplinter \
$(PLUGIN_RPATH) $(LIBS)
plugins/processes/processes.so: plugins/processes/processes.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/processes/processes.c -L. -lsplinter \
$(PLUGIN_RPATH) $(LIBS)
plugins/status/status.so: plugins/status/status.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/status/status.c -L. -lsplinter \
$(PLUGIN_RPATH) $(LIBS)
plugins/reminder/reminder.so: plugins/reminder/reminder.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/reminder/reminder.c -L. -lsplinter \
$(PLUGIN_RPATH) $(LIBS)
plugins/mcp/mcp.so: plugins/mcp/mcp.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/mcp/mcp.c -L. -lsplinter \
$(PLUGIN_RPATH) $(LIBS)
plugins/focus/focus.so: plugins/focus/focus.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/focus/focus.c -L. -lsplinter \
$(PLUGIN_RPATH) $(LIBS)
plugins/cps/cps.so: plugins/cps/cps.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/cps/cps.c -L. -lsplinter \
$(PLUGIN_RPATH) $(LIBS)
.c.o:
$(CC) $(CFLAGS) -c -o $@ $<
# A cli delegate's child has to find plugins/cli/cli.so. Beside an installed
# binary there is no such file, so the build directory this binary came from is
# compiled in as the last resort (sp_delegate_cli_plugin in src/backend/delegate.c).
src/backend/delegate.o: src/backend/delegate.c
$(CC) $(CFLAGS) -DSPLINTER_PLUGIN_DIR='"$(CURDIR)"' -c -o $@ $<
# POSIX make has no automatic dependencies. Rather than a list that is wrong
# the day somebody adds an #include, every object depends on the headers that
# make up the interface: a change there rebuilds everything that could see it.
HDRS = include/splinter.h include/splinter_engine.h include/splinter_plugin.h \
src/backend/config.h src/backend/ack.h \
src/backend/curl.h src/backend/log.h src/backend/i18n.h src/backend/md.h src/backend/b64.h src/backend/a2aserver.h
$(LIBOBJ) $(BINOBJ): $(HDRS)
$(PLUGIN): $(HDRS)
src/backend/agent.o: include/splinter.h
src/backend/buf.o: include/splinter.h
src/backend/tool.o: include/splinter.h
src/backend/session.o: include/splinter.h
src/backend/transport.o: include/splinter.h
src/backend/conv.o: include/splinter.h
src/backend/json.o: vendor/libmcp/mcp.h
src/backend/sse.o: include/splinter.h vendor/libmcp/mcp.h
src/backend/openai.o: include/splinter.h vendor/libmcp/mcp.h
src/backend/transport_openai.o: include/splinter.h src/backend/curl.h src/backend/log.h
src/backend/anthropic.o: include/splinter.h vendor/libmcp/mcp.h
src/backend/transport_anthropic.o: include/splinter.h src/backend/curl.h src/backend/log.h vendor/libmcp/mcp.h
src/backend/curl.o: src/backend/curl.h include/splinter.h
src/backend/builtin.o: include/splinter.h
src/backend/theme.o: src/backend/theme.h src/backend/palettes.h include/splinter.h
src/backend/palettes.o: src/backend/palettes.h
src/backend/decomp.o: src/backend/decomp.h
src/backend/i18n.o: src/backend/i18n.h include/splinter.h
src/backend/delegate.o: src/backend/config.h include/splinter.h
src/backend/telegram.o: include/splinter.h src/backend/curl.h src/backend/ack.h
src/backend/log.o: src/backend/log.h
src/backend/cmdscript.o: src/backend/cmdscript.h include/splinter.h
src/backend/folder.o: src/backend/folder.h include/splinter.h
src/backend/ack.o: src/backend/ack.h include/splinter.h
src/backend/interview.o: src/backend/interview.h include/splinter.h
src/backend/mcpserver.o: src/backend/mcpserver.h include/splinter.h
src/backend/skills.o: src/backend/skills.h src/backend/config.h include/splinter.h
src/backend/prompt.o: src/backend/prompt.h include/splinter.h
src/backend/config.o: src/backend/config.h include/splinter.h
src/backend/plugin.o: include/splinter.h include/splinter_plugin.h
src/frontend/curses.o: src/frontend/ui.h src/frontend/ui_backend.h \
include/splinter_engine.h src/backend/theme.h src/backend/decomp.h src/backend/i18n.h include/splinter.h include/splinter_plugin.h src/backend/md.h
src/backend/md.o: src/backend/md.h include/splinter.h
src/backend/b64.o: src/backend/b64.h include/splinter.h
src/backend/a2aserver.o: src/backend/a2aserver.h include/splinter.h vendor/libmcp/mcp.h
src/frontend/ui_local.o: src/frontend/ui_backend.h include/splinter_engine.h src/frontend/ui.h
src/frontend/ui_remote.o: src/frontend/ui_backend.h src/frontend/protocol.h include/splinter_engine.h vendor/libmcp/mcp.h
src/frontend/client.o: src/frontend/protocol.h include/splinter.h
src/frontend/protocol.o: src/frontend/protocol.h include/splinter_engine.h include/splinter.h src/backend/i18n.h
src/backend/http.o: src/backend/http.h include/splinter.h
src/backend/openai_server.o: src/backend/openai_server.h src/backend/http.h src/backend/config.h include/splinter.h vendor/libmcp/mcp.h
src/backend/engine.o: include/splinter_engine.h src/backend/config.h src/backend/providers.h src/backend/agents.h src/backend/swarm.h src/backend/cmdscript.h src/backend/i18n.h include/splinter_plugin.h
src/backend/providers.o: src/backend/providers.h src/backend/config.h include/splinter.h include/splinter_plugin.h
src/main.o: include/splinter.h include/splinter_engine.h \
src/frontend/ui_backend.h src/backend/config.h src/backend/i18n.h include/splinter_plugin.h src/frontend/ui.h src/backend/theme.h src/backend/a2aserver.h
tests/test_buf: tests/test_buf.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_buf.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_tool: tests/test_tool.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_tool.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_session: tests/test_session.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_session.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_transport: tests/test_transport.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_transport.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_agent: tests/test_agent.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_agent.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_conv: tests/test_conv.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_conv.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_openai: tests/test_openai.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_openai.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_theme: tests/test_theme.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_theme.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_focus: tests/test_focus.c $(LIB) $(PLUGIN)
$(CC) $(CFLAGS) -o $@ tests/test_focus.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_skills: tests/test_skills.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_skills.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_telegram: tests/test_telegram.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_telegram.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_delegate: tests/test_delegate.c $(LIB) $(PLUGIN)
$(CC) $(CFLAGS) -o $@ tests/test_delegate.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_builtin: tests/test_builtin.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_builtin.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_ack: tests/test_ack.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_ack.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_i18n: tests/test_i18n.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_i18n.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_ascii: tests/test_ascii.c $(LIB) $(BINOBJ)
$(CC) $(CFLAGS) -o $@ tests/test_ascii.c src/frontend/curses.o -L. -lsplinter \
$(TEST_RPATH) $(CURSES_A) $(LIBS)
tests/test_md: tests/test_md.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_md.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_tgmd: tests/test_tgmd.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_tgmd.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_providers: tests/test_providers.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_providers.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_b64: tests/test_b64.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_b64.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_pause: tests/test_pause.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_pause.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_swarm: tests/test_swarm.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_swarm.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_provstate: tests/test_provstate.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_provstate.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_agents: tests/test_agents.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_agents.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_confblock: tests/test_confblock.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_confblock.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_engine: tests/test_engine.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_engine.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_junction: tests/test_junction.c $(LIB) plugins/junction/junction.so
$(CC) $(CFLAGS) -o $@ tests/test_junction.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_self: tests/test_self.c $(LIB) plugins/self/self.so
$(CC) $(CFLAGS) -o $@ tests/test_self.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_fuzz: tests/test_fuzz.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_fuzz.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_sessiontools: tests/test_sessiontools.c $(LIB) plugins/session/session.so
$(CC) $(CFLAGS) -o $@ tests/test_sessiontools.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_foreign: tests/test_foreign.c $(LIB) plugins/foreign/foreign.so
$(CC) $(CFLAGS) -o $@ tests/test_foreign.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_usage: tests/test_usage.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_usage.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_jobs: tests/test_jobs.c $(LIB) $(PLUGIN)
$(CC) $(CFLAGS) -o $@ tests/test_jobs.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_config: tests/test_config.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_config.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_anthropic: tests/test_anthropic.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_anthropic.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_sse: tests/test_sse.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_sse.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_cli: tests/test_cli.c $(LIB) $(PLUGIN)
$(CC) $(CFLAGS) -o $@ tests/test_cli.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_compactor: tests/test_compactor.c $(LIB) $(PLUGIN)
$(CC) $(CFLAGS) -o $@ tests/test_compactor.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_corecompact: tests/test_corecompact.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_corecompact.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_secrets: tests/test_secrets.c $(LIB) $(PLUGIN)
$(CC) $(CFLAGS) -o $@ tests/test_secrets.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_mcpclient: tests/test_mcpclient.c $(LIB) $(PLUGIN)
$(CC) $(CFLAGS) -o $@ tests/test_mcpclient.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_kids: tests/test_kids.c $(LIB) $(PLUGIN)
$(CC) $(CFLAGS) -o $@ tests/test_kids.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_embed: tests/test_embed.c $(LIB) $(HDRS)
$(CC) $(CFLAGS) -o $@ tests/test_embed.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/plugin_lifecycle.so: tests/plugin_lifecycle.c $(LIB) $(HDRS)
$(CC) $(CFLAGS) -shared -o $@ tests/plugin_lifecycle.c -L. -lsplinter \
$(TEST_RPATH) $(LIBS)
tests/test_lifecycle: tests/test_lifecycle.c $(LIB) tests/plugin_lifecycle.so
$(CC) $(CFLAGS) -o $@ tests/test_lifecycle.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_plugin: tests/test_plugin.c $(LIB) $(PLUGIN)
$(CC) $(CFLAGS) -o $@ tests/test_plugin.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
# Every test runs under a 64 MB address-space limit: splinter is meant to
# be small, and a test that runs away (a retry loop appending to a buffer
# took 17 GB, 2026-11-18) must die at once instead of swapping the host.
TEST_MEM_KB ?= 65536
check: $(LIB) $(BIN) $(CLIENT) $(PLUGIN) $(TESTS) tests/test_junction
@set -e; python3 tools/check_i18n.py; \
ulimit -v $(TEST_MEM_KB); \
export LD_LIBRARY_PATH=.; \
SPLINTER_SESSION_DIR=$$(mktemp -d "$${TMPDIR:-/tmp}/splinter-check-XXXXXX"); \
export SPLINTER_SESSION_DIR; \
trap 'rm -rf "$$SPLINTER_SESSION_DIR"' EXIT; \
for t in $(TESTS); do echo "== $$t"; ./$$t; done; \
echo "== tests/test_delegate_cli.sh"; sh tests/test_delegate_cli.sh; \
echo "== tests/test_interview.sh"; sh tests/test_interview.sh; \
echo "== tests/test_gateway.sh"; sh tests/test_gateway.sh; \
echo "== tests/test_a2a.sh"; sh tests/test_a2a.sh; \
echo "== tests/test_a2a_ui.sh"; sh tests/test_a2a_ui.sh; \
echo "== tests/test_a2a_server.sh"; sh tests/test_a2a_server.sh; \
echo "== tests/test_a2a_context.sh"; sh tests/test_a2a_context.sh; \
echo "== tests/test_limit_wait.sh"; sh tests/test_limit_wait.sh; \
echo "== tests/test_pools.sh"; sh tests/test_pools.sh; \
echo "== tests/test_anthropic.sh"; sh tests/test_anthropic.sh; \
echo "== tests/test_agents_ui.sh"; sh tests/test_agents_ui.sh; \
echo "== tests/test_a2a_input.sh"; sh tests/test_a2a_input.sh; \
echo "== tests/test_ui.sh"; sh tests/test_ui.sh; \
echo "== tests/test_protocol.sh"; sh tests/test_protocol.sh; \
echo "== tests/test_attach.sh"; sh tests/test_attach.sh; \
echo "== tests/test_gateway_openai.sh"; sh tests/test_gateway_openai.sh; \
echo "== tests/test_reconnect.sh"; sh tests/test_reconnect.sh; \
echo "== tests/test_junction.sh"; sh tests/test_junction.sh; \
echo "== tests/test_mcpsession.sh"; sh tests/test_mcpsession.sh; \
echo "all tests passed"
# The unit tests under ASAN/UBSAN with leak detection. Rebuilds the tree with
# sanitizers and back; run it when nothing else builds in this tree.
check-asan:
@sh tests/check_asan.sh
# the test binaries as a list, for check_asan.sh
print-tests:
@echo $(TESTS)
# The installed binary finds its own library through an rpath relative to itself
# ($ORIGIN), so 'make install PREFIX=$HOME/.local' produces a program that runs
# without a wrapper, without LD_LIBRARY_PATH and without an environment file.
# Install by rename, never in place. A running splinter has these files
# mapped: cp truncates the old inode and writes into pages the process is
# executing, which killed a gateway that was up while make install ran
# (SIGSEGV at a nonsense address). A rename swaps the directory entry and
# leaves the mapped inode alone.
install: all
mkdir -p $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(PREFIX)/lib \
$(DESTDIR)$(PREFIX)/lib/splinter/plugins
$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-rpath,'$$ORIGIN/../lib' \
-o $(DESTDIR)$(PREFIX)/bin/.splinter.new $(BINOBJ) -L. -lsplinter \
$(CURSES_A) $(LIBS)
mv -f $(DESTDIR)$(PREFIX)/bin/.splinter.new \
$(DESTDIR)$(PREFIX)/bin/splinter
$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-rpath,'$$ORIGIN/../lib' \
-o $(DESTDIR)$(PREFIX)/bin/.$(CLIENT).new $(CLIENTOBJ) -L. -lsplinter \
$(LIBS)
mv -f $(DESTDIR)$(PREFIX)/bin/.$(CLIENT).new \
$(DESTDIR)$(PREFIX)/bin/$(CLIENT)
cp $(LIB) $(DESTDIR)$(PREFIX)/lib/.$(LIB).new
mv -f $(DESTDIR)$(PREFIX)/lib/.$(LIB).new $(DESTDIR)$(PREFIX)/lib/$(LIB)
for p in $(PLUGIN); do \
cp "$$p" "$(DESTDIR)$(PREFIX)/lib/splinter/plugins/.new.$$$$" && \
mv -f "$(DESTDIR)$(PREFIX)/lib/splinter/plugins/.new.$$$$" \
"$(DESTDIR)$(PREFIX)/lib/splinter/plugins/$${p##*/}" || exit 1; \
done
@echo "installed $(DESTDIR)$(PREFIX)/bin/splinter"
clean:
rm -f src/backend/catalogs.c src/backend/buildinfo.c $(BIN) $(CLIENT) $(LIB) $(LIBOBJ_ALL) $(BINOBJ) \
$(CLIENTOBJ) $(PLUGIN) $(TESTS) tests/plugin_lifecycle.so \
tests/test_junction
.PHONY: all check curses install clean
plugins/provider/provider.so: plugins/provider/provider.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/provider/provider.c -L. -lsplinter \
$(PLUGIN_RPATH) $(LIBS)
plugins/scheduler/scheduler.so: plugins/scheduler/scheduler.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/scheduler/scheduler.c -L. -lsplinter \
$(PLUGIN_RPATH) $(LIBS)
plugins/a2a/a2a.so: plugins/a2a/a2a.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/a2a/a2a.c -L. -lsplinter \
$(PLUGIN_RPATH) $(LIBS)
plugins/junction/junction.so: plugins/junction/junction.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/junction/junction.c -L. -lsplinter \
$(PLUGIN_RPATH) $(LIBS)
plugins/cache/cache.so: plugins/cache/cache.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/cache/cache.c -L. -lsplinter \
$(PLUGIN_LDFLAGS)
plugins/self/self.so: plugins/self/self.c $(LIB)
$(CC) $(CFLAGS) -shared -o $@ plugins/self/self.c -L. -lsplinter \
$(PLUGIN_RPATH) $(LIBS)