refactor: P3 low priority improvements

P3-1: Magic numbers to named constants
- SMS_CONTENT_MAX_LENGTH = 500 (bank-sms-parser.ts)
- DEFAULT_HISTORY_LIMIT = 10 (deposit-agent.ts)
- LOG_RESULT_MAX_LENGTH = 200 (deposit-tool.ts)

P3-2: Debug command admin-only access
- Add DEPOSIT_ADMIN_ID check for /debug command
- Return "관리자만 사용 가능" for non-admins

P3-3: Stats query null handling
- Replace || with ?? for COUNT results
- Prevents 0 being overwritten incorrectly

P3-4: Memory save error logging
- Add logger.debug for saveMemorySilently failures
- Non-critical but helps debug memory issues

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
kappa
2026-01-28 20:43:00 +09:00
parent 69e4dcc338
commit 79b8555893
5 changed files with 31 additions and 18 deletions

View File

@@ -43,9 +43,9 @@ export async function handleCommand(
return `📊 <b>현재 컨텍스트</b>
분석된 메시지: ${ctx.previousSummary?.message_count || 0}
분석된 메시지: ${ctx.previousSummary?.message_count ?? 0}
버퍼 메시지: ${ctx.recentMessages.length}
프로필 버전: ${ctx.previousSummary?.generation || 0}
프로필 버전: ${ctx.previousSummary?.generation ?? 0}
총 메시지: ${ctx.totalMessages}
💡 ${remaining > 0 ? `${remaining}개 메시지 후 프로필 업데이트` : '업데이트 대기 중'}`;
@@ -78,12 +78,18 @@ ${summary.summary}
return `📈 <b>대화 통계</b>
총 메시지: ${ctx.totalMessages}
프로필 버전: ${ctx.previousSummary?.generation || 0}
저장된 프로필: ${profileCount?.cnt || 0}
프로필 버전: ${ctx.previousSummary?.generation ?? 0}
저장된 프로필: ${profileCount?.cnt ?? 0}
버퍼 대기: ${ctx.recentMessages.length}`;
}
case '/debug': {
// Admin only - exposes internal debug info
const adminId = env.DEPOSIT_ADMIN_ID ? parseInt(env.DEPOSIT_ADMIN_ID, 10) : null;
if (!adminId || userId !== adminId) {
return '🔒 이 명령어는 관리자만 사용할 수 있습니다.';
}
// 디버그용 명령어 (개발 시 유용)
const ctx = await getConversationContext(env.DB, userId, chatId);
const recentMsgs = ctx.recentMessages.slice(-5).map((m, i) =>
@@ -95,7 +101,7 @@ ${summary.summary}
User ID: ${userId}
Chat ID: ${chatId}
Buffer Count: ${ctx.recentMessages.length}
Summary Gen: ${ctx.previousSummary?.generation || 0}
Summary Gen: ${ctx.previousSummary?.generation ?? 0}
<b>최근 버퍼 (5개):</b>
${recentMsgs || '(비어있음)'}`;