UNPKG

automagik-genie

Version:

Self-evolving AI agent orchestration framework with Model Context Protocol support

102 lines (101 loc) • 3.38 kB
"use strict"; /** * Stats Integration - Hook stats tracker into Genie execution * * Automatically tracks sessions, tokens, and tasks without manual intervention. * Call these functions from the appropriate places in the CLI. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getStatsTracker = getStatsTracker; exports.hookSessionStart = hookSessionStart; exports.hookSessionEnd = hookSessionEnd; exports.hookTokenUpdate = hookTokenUpdate; exports.hookTaskCompletion = hookTaskCompletion; exports.hookWishFulfillment = hookWishFulfillment; exports.hookAgentInvocation = hookAgentInvocation; exports.getCurrentSessionId = getCurrentSessionId; exports.ensureSession = ensureSession; const stats_tracker_1 = require("./stats-tracker"); // Singleton tracker instance let tracker = null; function getStatsTracker() { if (!tracker) { tracker = new stats_tracker_1.StatsTracker(process.cwd()); } return tracker; } /** * Hook 1: Start Session (call from 'genie run' command start) */ function hookSessionStart(projectId, projectName) { const tracker = getStatsTracker(); const task = tracker.startSession(projectId, projectName); console.error(`šŸ“Š Session started: ${task.id}`); } /** * Hook 2: End Session (call from execution completion or SIGINT) */ function hookSessionEnd(taskId) { const tracker = getStatsTracker(); tracker.endSession(taskId); console.error(`šŸ“Š Session ended: ${taskId}`); } /** * Hook 3: Record Tokens (call from execution process token updates) */ function hookTokenUpdate(taskId, inputTokens, outputTokens) { const tracker = getStatsTracker(); tracker.recordTokens(taskId, inputTokens, outputTokens); // Check for milestones const task = tracker.getCurrentSession(); if (task) { const milestones = tracker.getRecentMilestones(1); if (milestones.length > 0) { const latest = milestones[0]; // Flash milestone notification console.error(`\nšŸŽ‰ ${latest.title}\n`); } } } /** * Hook 4: Record Task Completion (call when Forge task status changes to 'done') */ function hookTaskCompletion(sessionTaskId, forgeTaskId, taskTitle) { const tracker = getStatsTracker(); tracker.recordTaskCompletion(sessionTaskId, forgeTaskId, taskTitle); console.error(`āœ… Task completed: ${taskTitle}`); } /** * Hook 5: Record Wish Fulfillment (call when wish is marked complete) */ function hookWishFulfillment(taskId) { const tracker = getStatsTracker(); tracker.recordWishFulfillment(taskId); console.error(`šŸŽÆ Wish fulfilled!`); } /** * Hook 6: Record Agent Invocation (call when agent starts) */ function hookAgentInvocation(taskId, agentId) { const tracker = getStatsTracker(); tracker.recordAgentInvocation(taskId, agentId); } /** * Get current session ID (for passing to other hooks) */ function getCurrentSessionId() { const tracker = getStatsTracker(); const task = tracker.getCurrentSession(); return task ? task.id : null; } /** * Auto-start session if none exists (convenience) */ function ensureSession(projectId = 'default', projectName = 'Genie Workspace') { const tracker = getStatsTracker(); let task = tracker.getCurrentSession(); if (!task) { task = tracker.startSession(projectId, projectName); } return task.id; }