@pimzino/claude-code-spec-workflow
Version:
Automated workflows for Claude Code. Includes spec-driven development (Requirements → Design → Tasks → Implementation) with intelligent task execution, optional steering documents and streamlined bug fix workflow (Report → Analyze → Fix → Verify). We have
137 lines • 4.53 kB
JavaScript
;
/**
* Shared file caching utility for all context and content scripts
* Provides longer caching duration for better performance
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCachedFileContent = getCachedFileContent;
exports.cachedFileExists = cachedFileExists;
exports.clearCache = clearCache;
exports.getCacheStats = getCacheStats;
exports.cleanExpiredCache = cleanExpiredCache;
const fs_1 = require("fs");
const path = __importStar(require("path"));
// Global cache shared across all scripts
const globalFileCache = new Map();
// Extended cache TTL to 1 hour (3600 seconds) for optimal performance
const CACHE_TTL = 3600000; // 1 hour
/**
* Get file content with caching
* @param filePath - Path to the file
* @returns File content or null if file doesn't exist
*/
function getCachedFileContent(filePath) {
try {
// Normalize the path for cross-platform compatibility
const normalizedPath = path.resolve(filePath);
// Check if file exists
if (!(0, fs_1.existsSync)(normalizedPath)) {
return null;
}
// Check cache first
const now = Date.now();
const cached = globalFileCache.get(normalizedPath);
if (cached) {
// Check if cache is still valid (TTL and file modification time)
const stats = (0, fs_1.statSync)(normalizedPath);
const fileModTime = stats.mtime.getTime();
if (now - cached.timestamp < CACHE_TTL && cached.mtime === fileModTime) {
return cached.content;
}
}
// Read file and update cache
const content = (0, fs_1.readFileSync)(normalizedPath, 'utf-8');
const stats = (0, fs_1.statSync)(normalizedPath);
globalFileCache.set(normalizedPath, {
content,
mtime: stats.mtime.getTime(),
timestamp: now
});
return content;
}
catch (error) {
return null;
}
}
/**
* Check if a file exists (with caching for stat calls)
* @param filePath - Path to check
* @returns True if file exists
*/
function cachedFileExists(filePath) {
try {
const normalizedPath = path.resolve(filePath);
return (0, fs_1.existsSync)(normalizedPath);
}
catch {
return false;
}
}
/**
* Clear cache for a specific file or all files
* @param filePath - Optional specific file path to clear, if not provided clears all
*/
function clearCache(filePath) {
if (filePath) {
const normalizedPath = path.resolve(filePath);
globalFileCache.delete(normalizedPath);
}
else {
globalFileCache.clear();
}
}
/**
* Get cache statistics
* @returns Object with cache size and TTL info
*/
function getCacheStats() {
return {
size: globalFileCache.size,
ttl: CACHE_TTL
};
}
/**
* Clean expired cache entries
*/
function cleanExpiredCache() {
const now = Date.now();
for (const [key, entry] of globalFileCache.entries()) {
if (now - entry.timestamp >= CACHE_TTL) {
globalFileCache.delete(key);
}
}
}
//# sourceMappingURL=file-cache.js.map