@jjdenhertog/ai-driven-development
Version:
AI-driven development workflow with learning capabilities for Claude
66 lines • 3.42 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkUsageLimitInSession = checkUsageLimitInSession;
exports.waitForUsageLimitReset = waitForUsageLimitReset;
const parseUsageLimitMessage_1 = require("./parseUsageLimitMessage");
const logger_1 = require("../logger");
const sleep_1 = require("../sleep");
/**
* Checks if a session report indicates AI usage limit has been reached
* @param sessionReport - The session report to check
* @returns Usage limit info or null if no usage limit reached
*/
function checkUsageLimitInSession(sessionReport) {
if (sessionReport.success) {
return null;
}
// Check timeline for usage limit messages
for (const entry of sessionReport.timeline) {
if (entry.type === 'status' && entry.message) {
// Remove the ⏺ prefix if present
const cleanMessage = entry.message.replace(/^⏺\s*/, '');
const usageLimitInfo = (0, parseUsageLimitMessage_1.parseUsageLimitMessage)(cleanMessage);
if (usageLimitInfo) {
return usageLimitInfo;
}
}
}
return null;
}
/**
* Waits for AI usage limit to be reset and logs progress
* @param waitTimeSeconds - Number of seconds to wait
* @param resetTimestamp - Unix timestamp when limit will be reset
* @param logPath - Optional path to log file
*/
function waitForUsageLimitReset(waitTimeSeconds, resetTimestamp, logPath) {
return __awaiter(this, void 0, void 0, function* () {
// resetTimestamp is Unix timestamp in UTC, but we show it in user's local timezone
const resetTime = new Date(resetTimestamp * 1000);
const formattedWaitTime = (0, parseUsageLimitMessage_1.formatWaitTime)(waitTimeSeconds);
(0, logger_1.log)(`AI usage limit reached. Waiting ${formattedWaitTime} until ${resetTime.toLocaleString()}...`, 'warn', undefined, logPath);
// Wait with periodic progress updates
const updateInterval = 300; // 5 minutes
let remainingSeconds = waitTimeSeconds;
while (remainingSeconds > 0) {
const sleepTime = Math.min(remainingSeconds, updateInterval);
yield (0, sleep_1.sleep)(sleepTime * 1000);
remainingSeconds -= sleepTime;
if (remainingSeconds > 0) {
const remaining = (0, parseUsageLimitMessage_1.formatWaitTime)(remainingSeconds);
(0, logger_1.log)(`Still waiting for usage limit reset. Time remaining: ${remaining}`, 'info', undefined, logPath);
}
}
(0, logger_1.log)('AI usage limit should now be reset. Continuing...', 'success', undefined, logPath);
});
}
//# sourceMappingURL=checkUsageLimitInSession.js.map