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:
2026-06-10 15:13:10 +02:00
parent 5c6719817f
commit ed9f843d65
10 changed files with 88 additions and 49 deletions
+5 -2
View File
@@ -14,6 +14,7 @@ import type { LLMClient } from "./llm-client.js";
export interface InitOptions {
verbose?: boolean;
llmClient?: LLMClient;
cacheDir?: string;
}
export async function initProject(
@@ -23,7 +24,7 @@ export async function initProject(
const entries = discoverProject(rootPath);
for (const entry of entries) {
await generateDirectoryMap(entry, options.llmClient);
await generateDirectoryMap(entry, options.llmClient, options.cacheDir);
}
if (options.verbose !== false) {
@@ -34,11 +35,12 @@ export async function initProject(
export async function generateDirectoryMap(
entry: DirectoryEntry,
llmClient?: LLMClient,
cacheDir?: string,
): Promise<FileEntry[]> {
const fileData: FileEntry[] = [];
for (const file of entry.files) {
const filePath = join(entry.dirPath, file);
const llmData = await extractFileLLM(filePath, llmClient);
const llmData = await extractFileLLM(filePath, llmClient, cacheDir);
const astData = await extractFileAST(filePath);
fileData.push(mergeFileData(file, llmData, astData));
}
@@ -47,6 +49,7 @@ export async function generateDirectoryMap(
entry.relativePath,
fileData,
llmClient,
cacheDir,
);
const mapData: PackageMapData = {