flashbacker
Version:
Claude Code state management with session continuity and AI personas
84 lines • 3.7 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleHook = handleHook;
const path_1 = __importDefault(require("path"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const chalk_1 = __importDefault(require("chalk"));
const child_process_1 = require("child_process");
async function handleHook(type, projectDir) {
// Add hook execution logging
const timestamp = new Date().toISOString();
const logEntry = `[${timestamp}] Hook triggered: ${type} in ${projectDir}`;
// Log to file for debugging
const logPath = path_1.default.join(projectDir, '.claude', 'flashback', 'hook-execution.log');
await fs_extra_1.default.ensureDir(path_1.default.dirname(logPath));
await fs_extra_1.default.appendFile(logPath, logEntry + '\n');
console.log(chalk_1.default.green(`🪝 ${logEntry}`));
try {
switch (type) {
case 'session-start':
await handleSessionStartHook(projectDir);
break;
default:
console.error(`Unknown hook type: ${type}`);
process.exit(1);
}
// Log successful completion
const successEntry = `[${new Date().toISOString()}] Hook completed: ${type}`;
await fs_extra_1.default.appendFile(logPath, successEntry + '\n');
console.log(chalk_1.default.green(`✅ ${successEntry}`));
}
catch (error) {
const errorEntry = `[${new Date().toISOString()}] Hook failed: ${type} - ${error instanceof Error ? error.message : String(error)}`;
await fs_extra_1.default.appendFile(logPath, errorEntry + '\n');
console.error(`Hook handler failed: ${error instanceof Error ? error.message : String(error)}`);
process.exit(1);
}
}
/**
* Simple session-start hook following hybrid AI+Computer pattern
* Gathers context and lets Claude do the intelligent analysis
*/
async function handleSessionStartHook(projectDir) {
console.log(chalk_1.default.blue('🔄 Flashback: Loading session context...'));
try {
// Find flashback binary
const flashbackBin = await findFlashbackBinary();
// Call session-start --context to gather project context
const result = (0, child_process_1.execFileSync)(flashbackBin, ['session-start', '--context'], {
cwd: projectDir,
encoding: 'utf8',
timeout: 30000, // 30 second timeout
});
console.log(chalk_1.default.green('🧠 Project context loaded successfully'));
console.log(result); // Output the context for Claude Code to inject
}
catch (error) {
console.log(chalk_1.default.yellow('⚠️ Failed to load project context:'), error instanceof Error ? error.message : String(error));
console.log(chalk_1.default.gray(' Starting session without context restoration...'));
}
}
/**
* Find flashback binary in common locations
*/
async function findFlashbackBinary() {
const possiblePaths = [
'flashback', // Assume it's in PATH
path_1.default.join(process.cwd(), 'node_modules', '.bin', 'flashback'),
path_1.default.join(process.env.HOME || '', '.npm-global', 'bin', 'flashback'),
];
for (const testPath of possiblePaths) {
try {
(0, child_process_1.execFileSync)(testPath, ['--version'], { stdio: 'pipe' });
return testPath;
}
catch {
// Try next path
}
}
return 'flashback'; // Default to PATH lookup
}
//# sourceMappingURL=hook-handler.js.map
;