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.
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
# fake OpenAI endpoint: the first request of a turn asks for the `session_search`
|
|
# tool with the query given on the command line, the next one echoes what it
|
|
# returned. Used to prove that session_search sees the foreign stores.
|
|
# argv: port, tool name, arguments JSON
|
|
import http.server, json, sys
|
|
|
|
|
|
def ev(d):
|
|
return ("data: " + json.dumps(d) + "\n\n").encode()
|
|
|
|
|
|
class H(http.server.BaseHTTPRequestHandler):
|
|
def log_message(self, *a):
|
|
pass
|
|
|
|
def do_POST(self):
|
|
n = int(self.headers.get("Content-Length", 0))
|
|
req = json.loads(self.rfile.read(n))
|
|
last = req["messages"][-1]
|
|
self.send_response(200)
|
|
self.send_header("Content-Type", "text/event-stream")
|
|
self.end_headers()
|
|
w = self.wfile.write
|
|
if last["role"] == "tool":
|
|
w(ev({"choices": [{"delta": {"content":
|
|
"OBS-BEGIN\n" + str(last.get("content", "")) + "\nOBS-END"}}]}))
|
|
else:
|
|
w(ev({"choices": [{"delta": {"tool_calls": [{"index": 0,
|
|
"id": "c1", "type": "function", "function": {
|
|
"name": sys.argv[2], "arguments": sys.argv[3]}}]}}]}))
|
|
w(b"data: [DONE]\n\n")
|
|
|
|
|
|
http.server.ThreadingHTTPServer(("127.0.0.1", int(sys.argv[1])), H).serve_forever()
|