flashbacker
Version:
Claude Code state management with session continuity and AI personas
120 lines • 4.98 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ensureDirectoryExists = ensureDirectoryExists;
exports.fileExists = fileExists;
exports.getRequiredFlashbackDirectories = getRequiredFlashbackDirectories;
exports.getRequiredFlashbackFiles = getRequiredFlashbackFiles;
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
async function ensureDirectoryExists(dirPath) {
await fs_extra_1.default.ensureDir(dirPath);
}
async function fileExists(filePath) {
return await fs_extra_1.default.pathExists(filePath);
}
/**
* Get the bundled templates directory path
*/
function getTemplatesDir() {
// Prefer published package location (node_modules/flashbacker/templates)
const publishedPath = path_1.default.join(__dirname, '..', '..', 'templates', '.claude', 'flashback');
if (fs_extra_1.default.pathExistsSync(publishedPath)) {
return publishedPath;
}
// Fallback to development location (when running from source with different layout)
const devPath = path_1.default.join(__dirname, '..', '..', '..', 'templates', '.claude', 'flashback');
return devPath;
}
/**
* Dynamically scan the bundled templates to determine required directory structure
* This reads the actual template bundle instead of hardcoding paths
*/
async function getRequiredFlashbackDirectories() {
const templatesDir = getTemplatesDir();
if (!await fs_extra_1.default.pathExists(templatesDir)) {
// Fallback for development/testing - return minimal required structure
return ['memory', 'config'];
}
const directories = new Set();
async function scanDirectory(dir, relativePath = '') {
try {
const items = await fs_extra_1.default.readdir(dir);
// Add current directory to set if it's not the root
if (relativePath) {
directories.add(relativePath);
}
for (const item of items) {
const fullPath = path_1.default.join(dir, item);
const itemRelativePath = relativePath ? path_1.default.join(relativePath, item) : item;
const stats = await fs_extra_1.default.stat(fullPath);
if (stats.isDirectory()) {
await scanDirectory(fullPath, itemRelativePath);
}
}
}
catch (error) {
// Ignore errors for individual directories
}
}
await scanDirectory(templatesDir);
// Convert Set to sorted array for consistent output
return Array.from(directories).sort();
}
/**
* Dynamically scan the bundled templates to find core files that should exist
* This reads the actual template bundle instead of hardcoding file paths
*/
async function getRequiredFlashbackFiles() {
const templatesDir = getTemplatesDir();
if (!await fs_extra_1.default.pathExists(templatesDir)) {
// Fallback for development/testing
return ['memory/REMEMBER.md', 'memory/WORKING_PLAN.md', 'config/flashback.json'];
}
const files = [];
async function scanForFiles(dir, relativePath = '') {
try {
const items = await fs_extra_1.default.readdir(dir);
for (const item of items) {
const fullPath = path_1.default.join(dir, item);
const itemRelativePath = relativePath ? path_1.default.join(relativePath, item) : item;
const stats = await fs_extra_1.default.stat(fullPath);
if (stats.isFile()) {
// Include core files that should exist after init
let finalPath = itemRelativePath;
// Handle .template files - they get renamed during init
if (item.endsWith('.template')) {
finalPath = itemRelativePath.replace('.template', '');
}
if (isCoreFile(finalPath)) {
files.push(finalPath);
}
}
else if (stats.isDirectory()) {
await scanForFiles(fullPath, itemRelativePath);
}
}
}
catch (error) {
// Ignore errors for individual items
}
}
await scanForFiles(templatesDir);
return files.sort();
}
/**
* Determine if a file is a core file that should exist after initialization
* Core files are essential for Flashback to function properly
*/
function isCoreFile(filePath) {
const corePatterns = [
'memory/REMEMBER.md',
'memory/WORKING_PLAN.md',
'config/flashback.json',
'scripts/session-start.sh',
];
return corePatterns.some(pattern => filePath === pattern || filePath.endsWith(pattern));
}
//# sourceMappingURL=file-utils.js.map
;