From f19fbf6ac1d94241eb20d32756c75417c6bf9131 Mon Sep 17 00:00:00 2001 From: lotherk Date: Sun, 22 Nov 2026 13:20:17 +0000 Subject: [PATCH] cli: splinter -c --claude continues the newest claude session of this folder The operator's claude ran into its limit mid-work; the session was too full to continue there. The foreign plugin could already read and import it, but only through a tool call inside a turn - there was no way in from the command line. --claude, --opencode, --hermes and --from=NAME make the newest session that tool ran in this directory the session of the run: it is imported before the history is loaded, so the first turn already carries it. -c no longer fails in a folder that has no splinter session yet; it falls back to "no session" and lets the import decide. An empty placeholder session is removed again, whether the import worked or not. Repeating the call continues the same session instead of importing a second time: sp_session_foreign() reads the foreign= marker back, so the work done in splinter is kept. A second foreign_import into the same session replaces the history rather than appending it twice (path_join built "id/.jsonl", so the replace branch never fired). Test: tests/test_foreignopen.c builds a claude fixture under its own HOME and covers import, idempotency, replace-not-append, the empty placeholder and a folder with no foreign session. make check exit 0, check_asan.sh clean. --- Makefile | 9 +- README.md | 27 ++++ docs/splinter.1 | 20 +++ include/splinter.h | 15 ++ include/splinter_engine.h | 5 + src/backend/engine.c | 84 ++++++++-- src/backend/foreignopen.c | 302 ++++++++++++++++++++++++++++++++++ src/backend/foreignopen.h | 41 +++++ src/backend/session.c | 52 ++++++ src/main.c | 16 ++ tests/fake_openai_echo.py | 35 ++++ tests/test_foreignopen.c | 331 ++++++++++++++++++++++++++++++++++++++ 12 files changed, 924 insertions(+), 13 deletions(-) create mode 100644 src/backend/foreignopen.c create mode 100644 src/backend/foreignopen.h create mode 100644 tests/fake_openai_echo.py create mode 100644 tests/test_foreignopen.c diff --git a/Makefile b/Makefile index 4fc875d..740f337 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ 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 + 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/foreignopen.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 @@ -50,7 +50,8 @@ PLUGIN = plugins/clock/clock.so plugins/lcm/lcm.so plugins/cps/cps.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 + tests/test_sessiontools tests/test_embed tests/test_foreign \ + tests/test_foreignopen RPATH = -Wl,-rpath,'$$ORIGIN' PLUGIN_RPATH = -Wl,-rpath,'$$ORIGIN/../..' @@ -272,10 +273,12 @@ tests/test_self: tests/test_self.c $(LIB) plugins/self/self.so 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 +tests/test_sessiontools: tests/test_sessiontools.c $(LIB) plugins/session/session.so plugins/foreign/foreign.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_foreignopen: tests/test_foreignopen.c $(LIB) plugins/foreign/foreign.so + $(CC) $(CFLAGS) -o $@ tests/test_foreignopen.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) diff --git a/README.md b/README.md index 3887179..7905400 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ splinter refuses to start rather than pretend it can talk to a model. | `--serve`, `--attach`, `--socket PATH` | serve the line protocol on a Unix socket, or be a client of it (default `~/.splinter/splinter.sock`) | | `--theme NAME`, `--list-themes` | UI theme (`Xresources` or a CDE palette such as `Default`, `Delphinium`, `MakroSlate`), and the names | | `--resume`, `-c, --continue` | load the session's history; continue the last session started in this directory | +| `--claude`, `--opencode`, `--hermes`, `--from=NAME` | continue the newest session that tool ran in this directory (imports it on the first start) | | `--session DIR`, `--session-id ID` | session directory (default `~/.splinter`) and id (default `sess-