refactor: simplify cache location to .cache/llm-cache.json
- Cache now lives at <project>/.cache/llm-cache.json (single hidden dir) - Remove extra pi-project-map subdirectory level - Use dirname() instead of string slicing for robustness
This commit is contained in:
@@ -5,10 +5,9 @@ import {
|
||||
mkdirSync,
|
||||
renameSync,
|
||||
} from "fs";
|
||||
import { join } from "path";
|
||||
import { dirname, join } from "path";
|
||||
|
||||
const DEFAULT_CACHE_SUBDIR = ".cache/pi-project-map";
|
||||
const DEFAULT_CACHE_FILE = "llm-cache.json";
|
||||
const CACHE_FILE = "llm-cache.json";
|
||||
|
||||
interface CacheEntry {
|
||||
result: string;
|
||||
@@ -16,15 +15,12 @@ interface CacheEntry {
|
||||
}
|
||||
|
||||
function getCachePath(cacheDir?: string): string {
|
||||
if (cacheDir) {
|
||||
return join(cacheDir, DEFAULT_CACHE_FILE);
|
||||
}
|
||||
// Fallback to cwd when no project root provided
|
||||
return join(process.cwd(), DEFAULT_CACHE_SUBDIR, DEFAULT_CACHE_FILE);
|
||||
const base = cacheDir || process.cwd();
|
||||
return join(base, ".cache", CACHE_FILE);
|
||||
}
|
||||
|
||||
function ensureCacheDir(cachePath: string): void {
|
||||
const dir = cachePath.substring(0, cachePath.lastIndexOf("/"));
|
||||
const dir = dirname(cachePath);
|
||||
if (!existsSync(dir)) {
|
||||
mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user