UNPKG

refakts

Version:

TypeScript refactoring tool built for AI coding agents to perform precise refactoring operations via command line instead of requiring complete code regeneration.

146 lines 5.12 kB
"use strict"; 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.isCheckSnoozed = isCheckSnoozed; exports.snoozeCheck = snoozeCheck; exports.clearExpiredSnoozes = clearExpiredSnoozes; const fs = __importStar(require("fs")); const path = __importStar(require("path")); const SNOOZE_FILE_PATH = path.join(__dirname, '..', '..', '.quality-snooze.json'); const SNOOZE_DURATION_HOURS = 24; function isCheckSnoozed(checkType, identifier) { const snoozeData = loadSnoozeData(); const checkSnoozes = snoozeData[checkType]; return validateSnoozeStatus(checkSnoozes, identifier); } function validateSnoozeStatus(checkSnoozes, identifier) { if (!hasActiveSnooze(checkSnoozes, identifier)) { return false; } return validateActiveSnooze(checkSnoozes, identifier); } function validateActiveSnooze(checkSnoozes, identifier) { if (!checkSnoozes) { return false; } const snoozeTimestamp = checkSnoozes[identifier]; return isSnoozeStillValid(snoozeTimestamp); } function hasActiveSnooze(checkSnoozes, identifier) { return Boolean(checkSnoozes && checkSnoozes[identifier]); } function isSnoozeStillValid(snoozeTimestamp) { const currentTime = Date.now(); const hoursElapsed = (currentTime - snoozeTimestamp) / (1000 * 60 * 60); return hoursElapsed < SNOOZE_DURATION_HOURS; } function snoozeCheck(checkType, identifier) { const snoozeData = loadSnoozeData(); if (!snoozeData[checkType]) { snoozeData[checkType] = {}; } snoozeData[checkType][identifier] = Date.now(); saveSnoozeData(snoozeData); } function clearExpiredSnoozes() { const snoozeData = loadSnoozeData(); const hasChanges = removeExpiredSnoozes(snoozeData); if (hasChanges) { saveSnoozeData(snoozeData); } } function removeExpiredSnoozes(snoozeData) { let hasChanges = false; for (const checkType in snoozeData) { hasChanges = cleanupCheckType(snoozeData, checkType) || hasChanges; } return hasChanges; } function cleanupCheckType(snoozeData, checkType) { const hasChanges = removeExpiredIdentifiers(snoozeData, checkType); return cleanupEmptyCheckType(snoozeData, checkType) || hasChanges; } function removeExpiredIdentifiers(snoozeData, checkType) { let hasChanges = false; hasChanges = processIdentifiersForExpiration(snoozeData, checkType, hasChanges); return hasChanges; } function processIdentifiersForExpiration(snoozeData, checkType, hasChanges) { for (const identifier in snoozeData[checkType]) { if (isSnoozeExpired(snoozeData[checkType][identifier])) { delete snoozeData[checkType][identifier]; hasChanges = true; } } return hasChanges; } function isSnoozeExpired(snoozeTimestamp) { return !isSnoozeStillValid(snoozeTimestamp); } function cleanupEmptyCheckType(snoozeData, checkType) { if (Object.keys(snoozeData[checkType]).length === 0) { delete snoozeData[checkType]; return true; } return false; } function loadSnoozeData() { return readSnoozeFile(); } function readSnoozeFile() { try { return attemptFileRead(); } catch (error) { process.stderr.write(`Warning: Failed to load snooze data: ${error}\n`); return {}; } } function attemptFileRead() { if (fs.existsSync(SNOOZE_FILE_PATH)) { const data = fs.readFileSync(SNOOZE_FILE_PATH, 'utf8'); return JSON.parse(data); } return {}; } function saveSnoozeData(data) { try { fs.writeFileSync(SNOOZE_FILE_PATH, JSON.stringify(data, null, 2)); } catch (error) { process.stderr.write(`Warning: Failed to save snooze data: ${error}\n`); } } //# sourceMappingURL=snooze-tracker.js.map