const { Notification } = require('electron'); /** * 데스크톱 네이티브 알림 발송 헬퍼 * @param {string} title 알림 제목 * @param {string} body 알림 내용 * @param {'normal'|'critical'} urgency 긴급성 레벨 (critical 시 무음 아님, 알림창 상시 대기) */ function sendNotification(title, body, urgency = 'normal') { if (!Notification?.isSupported?.()) { console.warn('[Notifier] Native notifications are not supported on this platform.'); return { status: 'unsupported' }; } try { const notification = new Notification({ title: title, body: body, silent: urgency === 'normal', // macOS의 경우 urgency 가 critical 이면 배너가 닫히지 않고 머물도록 설정 timeoutType: urgency === 'critical' ? 'never' : 'default' }); // 알림 클릭 시 메인 윈도우 포커싱 이벤트 핸들러 추가 가능 notification.on('click', () => { const ctx = require('./context'); if (ctx.mainWindow) { ctx.mainWindow.show(); ctx.mainWindow.focus(); } }); notification.show(); return { status: 'submitted' }; } catch (err) { console.error('[Notifier] Failed to show native notification:', err); return { status: 'uncertain' }; } } module.exports = { /** * 루프 최종 완료 시 알림 */ notifyLoopComplete(runId, success, reason, cost) { const title = success ? '✅ Closed-Loop 최종 성공' : '❌ Closed-Loop 종료 (실패)'; const body = success ? `태스크 ${runId}가 성공적으로 최종 목표(Goal)를 완수했습니다! (비용: $${cost.toFixed(2)})` : `태스크 ${runId}가 목표 달성에 실패하거나 중단되었습니다: ${reason}`; return sendNotification(title, body, success ? 'normal' : 'critical'); }, /** * 예산 80% 경고 등 루프 경고 알림 */ notifyLoopWarning(runId, message) { const title = '⚠️ Closed-Loop 가드레일 경고'; const body = `태스크 ${runId}: ${message}`; return sendNotification(title, body, 'normal'); }, /** * HITL (사람의 판단) 대기 알림 */ notifyHitlWait(runId, message) { const title = '🙋 Closed-Loop 사람의 개입 대기'; const body = `태스크 ${runId}가 사용자의 분석 및 승인 피드백을 기다립니다: ${message}`; return sendNotification(title, body, 'critical'); } };