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,
|
mkdirSync,
|
||||||
renameSync,
|
renameSync,
|
||||||
} from "fs";
|
} from "fs";
|
||||||
import { join } from "path";
|
import { dirname, join } from "path";
|
||||||
|
|
||||||
const DEFAULT_CACHE_SUBDIR = ".cache/pi-project-map";
|
const CACHE_FILE = "llm-cache.json";
|
||||||
const DEFAULT_CACHE_FILE = "llm-cache.json";
|
|
||||||
|
|
||||||
interface CacheEntry {
|
interface CacheEntry {
|
||||||
result: string;
|
result: string;
|
||||||
@@ -16,15 +15,12 @@ interface CacheEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getCachePath(cacheDir?: string): string {
|
function getCachePath(cacheDir?: string): string {
|
||||||
if (cacheDir) {
|
const base = cacheDir || process.cwd();
|
||||||
return join(cacheDir, DEFAULT_CACHE_FILE);
|
return join(base, ".cache", CACHE_FILE);
|
||||||
}
|
|
||||||
// Fallback to cwd when no project root provided
|
|
||||||
return join(process.cwd(), DEFAULT_CACHE_SUBDIR, DEFAULT_CACHE_FILE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureCacheDir(cachePath: string): void {
|
function ensureCacheDir(cachePath: string): void {
|
||||||
const dir = cachePath.substring(0, cachePath.lastIndexOf("/"));
|
const dir = dirname(cachePath);
|
||||||
if (!existsSync(dir)) {
|
if (!existsSync(dir)) {
|
||||||
mkdirSync(dir, { recursive: true });
|
mkdirSync(dir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user