/* * 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 #include #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); }