feat: move LLM cache to project-local directory
- Cache now lives in <project>/.pi-project-map/cache/llm-cache.json - Removed global ~/.cache/pi-project-map/ usage - Cache travels with the project, no cross-project collisions - Easy to invalidate: rm -rf .pi-project-map/cache/ Files changed: - llm-cache.ts: accept cacheDir parameter, default to project-local - llm-extract.ts: pass cacheDir through to cache functions - init.ts: pass rootPath as cacheDir - patch.ts: accept and pass cacheDir - cli.ts: pass targetPath as cacheDir - pi-extension.ts: pass ctx.cwd as cacheDir - Tests updated to use temp dirs for cache isolation
This commit is contained in:
@@ -19,13 +19,23 @@ vi.mock("typebox", () => ({
|
||||
vi.mock("@mariozechner/pi-ai", () => ({
|
||||
complete: vi.fn(async (_model: any, _context: any) => ({
|
||||
role: "assistant" as const,
|
||||
content: [{ type: "text", text: "PURPOSE: Test file\nDEPS: none\nCONCEPTS: testing" }],
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "PURPOSE: Test file\nDEPS: none\nCONCEPTS: testing",
|
||||
},
|
||||
],
|
||||
})),
|
||||
}));
|
||||
|
||||
import extension from "../pi-extension.js";
|
||||
|
||||
const CACHE_FILE = join(homedir(), ".cache", "pi-project-map", "llm-cache.json");
|
||||
const CACHE_FILE = join(
|
||||
homedir(),
|
||||
".cache",
|
||||
"pi-project-map",
|
||||
"llm-cache.json",
|
||||
);
|
||||
function clearCache() {
|
||||
if (existsSync(CACHE_FILE)) unlinkSync(CACHE_FILE);
|
||||
}
|
||||
@@ -43,9 +53,16 @@ describe("pi-extension", () => {
|
||||
mockNotify = vi.fn();
|
||||
mockCtx = {
|
||||
cwd: "/home/project",
|
||||
model: { provider: "openai", id: "gpt-4o-mini", api: "openai-completions" },
|
||||
model: {
|
||||
provider: "openai",
|
||||
id: "gpt-4o-mini",
|
||||
api: "openai-completions",
|
||||
},
|
||||
modelRegistry: {
|
||||
getApiKeyAndHeaders: vi.fn(async () => ({ apiKey: "test-key", headers: {} })),
|
||||
getApiKeyAndHeaders: vi.fn(async () => ({
|
||||
apiKey: "test-key",
|
||||
headers: {},
|
||||
})),
|
||||
},
|
||||
ui: { notify: mockNotify },
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user