Commit Graph
5 Commits
Author SHA1 Message Date
lotherk 30e202eca0 foreign: /foreign search keeps a quote in the text
The command built its JSON request with the operator's words as a plain
%s inside a string, so /foreign search he said "hi" there ended the
value early and was answered with "'query' is required" - the whole
phrase lost. The text (and the source/id pair) goes through
sp_json_escape now.

  before: /foreign search he said "hi" there -> error: 'query' is required
  after:  the same command reaches the stores and answers
  tests/test_foreign: red with the old line (2 failures), green with the fix
  make check: all tests passed, rc=0
2026-11-22 23:57:00 +00:00
lotherk f5d63f6199 sessions: the foreign picker counts and dates what it lists
Three bugs in the /sessions picker, all of them found by review and all of
them visible on the screen:

- sp_engine_sources() hard-set every foreign source's count to 0, so the
  picker offered "claude (0)" while 82 rows were behind it. The count now
  comes from the same listing the picker shows.
- sp_foreign_sessions() hard-set each row's date to 0, so every foreign
  session drew as 1970-01-01. The plugin prints "%Y-%m-%d %H:%M" and the
  row's first column is parsed into epoch seconds.
- The foreign plugin's list tool queried with its configured default
  (limit = 25) no matter what the caller asked for, so asking for 100 rows
  returned 25 and a store with 290 sessions looked like one with 25. The
  caller's limit now reaches the SQL.

Proof: tests/test_foreignopen.c asserts count == 1 and mtime > 1600000000
against a fixture store; reverting either fix makes both checks fail. Live
over the socket, before: [('splinter', 100), ('claude', 0), ('opencode', 0)]
with mtime 0 on every row; after: [('splinter', 100), ('claude', 82),
('opencode', 100)] with mtime 1795387200. sqlite3 counts 290 opencode
sessions and 82 claude files, so the numbers agree with the stores.

make check: 21 suites, 0 failures. check_i18n: 229 keys in 3 catalogues.
2026-11-22 22:52:51 +00:00
lotherk 1781cdd478 session: session_search and session_list also read claude, opencode and hermes
The session plugin scanned only splinter's own sessions, so "what did we say
about X in this folder" was answered as if no other tool had ever run here.
Both tools now delegate to the foreign plugin's tools through the registry
instead of reading the three stores a second time, and stay usable without it
(fallback to splinter's own sessions).

foreign_search also promises a cwd in its schema and then threw it away
((void)only), so a search always ran over every folder. The filter is applied
for all three sources now.

Two silent losses in the opencode search: substr(data,1,20000) cut the JSON
mid-object, so 2973 messages (up to 15 MB) never parsed and were dropped, and
assistant messages carry their text in data.content[], not data.text, so
73706 of them were skipped even when short. The text is extracted in SQL now
and the whole row is read. Hermes cut its match at 400 bytes in the same way.

Test: tests/test_sessiontools.c writes a claude session into its own working
directory and expects the hit through session_search and session_list; both
fall without the delegation. tests/test_foreign.c covers a long opencode
message, an assistant message via content[], the hermes cut and the cwd
filter; every check was counter-checked against the old code. make check exit
0, check_asan.sh 45/45 clean.
2026-11-22 13:20:45 +00:00
lotherk a48a2deec5 foreign: an imported tool call is a JSON array, not a run of objects
The importer collected tool calls by concatenating the objects it found, so a
source that recorded two calls handed the model "{} {}" where the API expects
"[{}, {}]". One call per assistant message is the common case and hid it.

The calls are now kept as the array they were read as, and their results are
kept with the same call ids, so the call/result pairing a provider insists on
survives the import.
2026-11-22 10:26:06 +00:00
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