Every session records the directory it was started in (<id>.meta, cwd=). With that, '-c' means the last session that happened *here*: cd ~/src/splinter && splinter -c A session from another tree is never silently loaded; if nothing happened in this directory yet, it says so and exits. Verified in three directories - two report no session, the one with history resumes. folder_history gives the model the folder's memory instead of a guess: sessions started there, newest first, with turn count and the last question. --mcp-server-listen IP --mcp-listen-port N serves the registry over MCP (newline-delimited JSON-RPC on TCP): initialize, tools/list, tools/call. Read tools are served; mutating and destructive ones are refused unless the server was started with --autonomous - a remote agent does not run shell commands here because it asked nicely. Proven with a real client on 127.0.0.1:8097: handshake answers splinter 0.1.0, tools/list reports 14 tools, tools/call list returns the directory, tools/call run is refused with the authorization message.
64 lines
1.7 KiB
C
64 lines
1.7 KiB
C
/*
|
|
* splinter -- the folder's memory.
|
|
*
|
|
* Copyright (c) 2026 Konrad Lother
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*
|
|
* A model that is asked "what happened here" should not guess. Every session
|
|
* records the directory it was started in, so the answer is a lookup:
|
|
* folder_history lists the sessions of a directory, newest first, with the
|
|
* number of turns and the last thing that was asked.
|
|
*/
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
#include "splinter.h"
|
|
#include "mcp.h"
|
|
#include "folder.h"
|
|
|
|
static char sessions_dir[512];
|
|
|
|
static int
|
|
tool_folder_history(const char *args, struct sp_buf *out, void *ctx)
|
|
{
|
|
char path[512];
|
|
const char *want = NULL;
|
|
mcp_json *v;
|
|
|
|
(void)ctx;
|
|
if (args != NULL && args[0] == '{') {
|
|
v = mcp_parse(args);
|
|
if (v != NULL) {
|
|
want = mcp_arg_string(v, "path");
|
|
if (want != NULL)
|
|
snprintf(path, sizeof(path), "%s", want);
|
|
mcp_json_free(v);
|
|
}
|
|
}
|
|
if (want == NULL) {
|
|
if (getcwd(path, sizeof(path)) == NULL)
|
|
return sp_buf_puts(out, "error: cannot read the working "
|
|
"directory");
|
|
}
|
|
return sp_session_folder_history(sessions_dir, path, 10, out) == 0 ? 0 :
|
|
-1;
|
|
}
|
|
|
|
int
|
|
sp_folder_register(struct sp_registry *r, const char *sessions)
|
|
{
|
|
struct sp_tool t;
|
|
|
|
snprintf(sessions_dir, sizeof(sessions_dir), "%s", sessions);
|
|
memset(&t, 0, sizeof(t));
|
|
t.name = "folder_history";
|
|
t.description = "What happened in a directory before: the sessions started "
|
|
"there, how many turns, and the last question. Defaults to the "
|
|
"current directory.";
|
|
t.params = "{\"type\":\"object\",\"properties\":{\"path\":"
|
|
"{\"type\":\"string\",\"description\":\"directory to look at\"}}}";
|
|
t.auth = SP_AUTH_READ;
|
|
t.run = tool_folder_history;
|
|
return sp_registry_add(r, &t);
|
|
}
|