Index `files`, plus `pad` trivial Python files (enough of them moves the * index onto the parallel resolver, MIN_FILES_FOR_PARALLEL). */
| 180 | /* Index `files`, plus `pad` trivial Python files (enough of them moves the |
| 181 | * index onto the parallel resolver, MIN_FILES_FOR_PARALLEL). */ |
| 182 | static bool sp_index(sp_proj_t *p, const sp_file_t *files, int count, int pad) { |
| 183 | memset(p, 0, sizeof(*p)); |
| 184 | snprintf(p->tmpdir, sizeof(p->tmpdir), "%s", th_mktempdir("cbm-sp")); |
| 185 | if (!p->tmpdir[0]) { |
| 186 | return false; |
| 187 | } |
| 188 | for (int i = 0; i < count; i++) { |
| 189 | if (!sp_write(p->tmpdir, files[i].name, files[i].content)) { |
| 190 | return false; |
| 191 | } |
| 192 | } |
| 193 | for (int i = 0; i < pad; i++) { |
| 194 | char name[64]; |
| 195 | char body[96]; |
| 196 | snprintf(name, sizeof(name), "pad/p%d.py", i); |
| 197 | snprintf(body, sizeof(body), "def pad_%d():\n return %d\n", i, i); |
| 198 | if (!sp_write(p->tmpdir, name, body)) { |
| 199 | return false; |
| 200 | } |
| 201 | } |
| 202 | p->project = cbm_project_name_from_path(p->tmpdir); |
| 203 | if (!p->project) { |
| 204 | return false; |
| 205 | } |
| 206 | char cache[700]; |
| 207 | const char *configured = getenv("CBM_CACHE_DIR"); |
| 208 | const char *home = getenv("HOME"); |
| 209 | if (configured && configured[0]) { |
| 210 | snprintf(cache, sizeof(cache), "%s", configured); |
| 211 | } else { |
| 212 | snprintf(cache, sizeof(cache), "%s/.cache/codebase-memory-mcp", home ? home : "/tmp"); |
| 213 | } |
| 214 | cbm_mkdir_p(cache, 0755); |
| 215 | snprintf(p->dbpath, sizeof(p->dbpath), "%s/%s.db", cache, p->project); |
| 216 | unlink(p->dbpath); |
| 217 | p->srv = cbm_mcp_server_new(NULL); |
| 218 | if (!p->srv) { |
| 219 | return false; |
| 220 | } |
| 221 | char args[800]; |
| 222 | snprintf(args, sizeof(args), "{\"repo_path\":\"%s\"}", p->tmpdir); |
| 223 | free(cbm_mcp_handle_tool(p->srv, "index_repository", args)); |
| 224 | p->store = cbm_store_open_path(p->dbpath); |
| 225 | return p->store != NULL; |
| 226 | } |
| 227 | |
| 228 | static void sp_cleanup(sp_proj_t *p) { |
| 229 | if (p->store) { |
no test coverage detected