UNPKG

crevr

Version:

A web-based UI for reviewing and reverting Claude Code changes

53 lines 2.11 kB
import * as fs from 'fs'; import * as path from 'path'; import * as os from 'os'; export class RevertTracker { constructor() { this.revertFile = path.join(os.homedir(), '.crevr', 'reverted-changes.json'); } async init() { await fs.promises.mkdir(path.dirname(this.revertFile), { recursive: true }); } async getRevertedChanges() { try { const data = await fs.promises.readFile(this.revertFile, 'utf-8'); return JSON.parse(data); } catch (error) { if (error.code === 'ENOENT') { return {}; } throw error; } } async markAsReverted(changeId, sessionKey = 'default') { const revertedChanges = await this.getRevertedChanges(); if (!revertedChanges[sessionKey]) { revertedChanges[sessionKey] = []; } if (!revertedChanges[sessionKey].includes(changeId)) { revertedChanges[sessionKey].push(changeId); await fs.promises.writeFile(this.revertFile, JSON.stringify(revertedChanges, null, 2)); } } async isReverted(changeId, sessionKey = 'default') { const revertedChanges = await this.getRevertedChanges(); return revertedChanges[sessionKey]?.includes(changeId) || false; } async filterRevertedChanges(changes, sessionKey = 'default') { const revertedChanges = await this.getRevertedChanges(); const revertedIds = revertedChanges[sessionKey] || []; return changes.filter(change => !revertedIds.includes(change.id)); } async unmarkAsReverted(changeId, sessionKey = 'default') { const revertedChanges = await this.getRevertedChanges(); if (revertedChanges[sessionKey]) { const index = revertedChanges[sessionKey].indexOf(changeId); if (index > -1) { revertedChanges[sessionKey].splice(index, 1); await fs.promises.writeFile(this.revertFile, JSON.stringify(revertedChanges, null, 2)); } } } } //# sourceMappingURL=revert-tracker.js.map