fix: add snapshot diagnostics + lower content filter for Discord messages

This commit is contained in:
2026-03-10 08:18:36 +09:00
parent 628b5ae2fa
commit 8c6d25c6d4
3 changed files with 67 additions and 47 deletions

View File

@@ -132,6 +132,8 @@ function writeChatSnapshot(text) {
const filePath = path.join(snapshotDir, `${id}.json`); const filePath = path.join(snapshotDir, `${id}.json`);
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf-8'); fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf-8');
console.log(`Gravity Bridge: chat snapshot written (${text.length} chars) → ${id}.json`); console.log(`Gravity Bridge: chat snapshot written (${text.length} chars) → ${id}.json`);
logToFile(`[SNAPSHOT] written ${id}.json (${text.length} chars)`);
logToFile(`[SNAPSHOT] content: ${text.substring(0, 200)}`);
// Lazily register session → project mapping (correct because projectName is per-window) // Lazily register session → project mapping (correct because projectName is per-window)
if (activeSessionId) { if (activeSessionId) {
writeRegistration(activeSessionId); writeRegistration(activeSessionId);
@@ -1740,38 +1742,47 @@ function setupMonitor() {
} }
// ── Process latestNotifyUserStep ── // ── Process latestNotifyUserStep ──
const notifyStep = bestSession.latestNotifyUserStep; const notifyStep = bestSession.latestNotifyUserStep;
if (notifyStep && notifyStep.stepIndex > lastNotifyStepIndex) { if (notifyStep) {
if (notifyStep.stepIndex > lastNotifyStepIndex) {
lastNotifyStepIndex = notifyStep.stepIndex; lastNotifyStepIndex = notifyStep.stepIndex;
const content = notifyStep.step?.notifyUser?.notificationContent || ''; const content = notifyStep.step?.notifyUser?.notificationContent || '';
// Filter: only relay meaningful notifications (skip trivial ones) logToFile(`[NOTIFY-STEP] NEW step=${notifyStep.stepIndex} content=${content.length} chars`);
if (content.length > 50) { // Filter: relay all non-empty notifications
if (content.length > 10) {
writeChatSnapshot(`📣 **알림** (step ${notifyStep.stepIndex})\n\n${content}`); writeChatSnapshot(`📣 **알림** (step ${notifyStep.stepIndex})\n\n${content}`);
console.log(`Gravity Bridge: [POLL#${pollCount}] NOTIFY step=${notifyStep.stepIndex} ${content.length} chars`);
} }
else if (content.length > 0) { else if (content.length > 0) {
logToFile(`[POLL] NOTIFY skipped (too short: ${content.length} chars): ${content.substring(0, 80)}`); logToFile(`[NOTIFY-STEP] skipped (too short: ${content.length} chars): ${content}`);
} }
} }
}
else if (pollCount <= 5) {
logToFile(`[NOTIFY-STEP] null (no notify step in session)`);
}
// ── Process latestTaskBoundaryStep ── // ── Process latestTaskBoundaryStep ──
const taskStep = bestSession.latestTaskBoundaryStep; const taskStep = bestSession.latestTaskBoundaryStep;
if (taskStep && taskStep.stepIndex > lastTaskStepIndex) { if (taskStep) {
if (taskStep.stepIndex > lastTaskStepIndex) {
lastTaskStepIndex = taskStep.stepIndex; lastTaskStepIndex = taskStep.stepIndex;
const tb = taskStep.step?.taskBoundary; const tb = taskStep.step?.taskBoundary;
if (tb?.taskName) { if (tb?.taskName) {
const mode = tb.mode ? tb.mode.replace('AGENT_MODE_', '') : ''; const mode = tb.mode ? tb.mode.replace('AGENT_MODE_', '') : '';
// Filter: skip status-only updates with same task name (noise)
const taskText = `${tb.taskName}|${tb.taskStatus || ''}`; const taskText = `${tb.taskName}|${tb.taskStatus || ''}`;
logToFile(`[TASK-STEP] NEW step=${taskStep.stepIndex} name="${tb.taskName}" mode=${mode}`);
if (taskText !== lastRelayedTaskText) { if (taskText !== lastRelayedTaskText) {
lastRelayedTaskText = taskText; lastRelayedTaskText = taskText;
writeChatSnapshot(`📋 **[${mode}] ${tb.taskName}**\n${tb.taskStatus || ''}\n\n${tb.taskSummary || ''}`); writeChatSnapshot(`📋 **[${mode}] ${tb.taskName}**\n${tb.taskStatus || ''}\n\n${tb.taskSummary || ''}`);
console.log(`Gravity Bridge: [POLL#${pollCount}] TASK step=${taskStep.stepIndex} "${tb.taskName}"`);
} }
else { else {
logToFile(`[POLL] TASK skipped (duplicate): "${tb.taskName}"`); logToFile(`[TASK-STEP] skipped (duplicate): "${tb.taskName}"`);
} }
} }
} }
} }
else if (pollCount <= 5) {
logToFile(`[TASK-STEP] null (no task step in session)`);
}
}
catch (e) { catch (e) {
if (pollCount <= 5 || pollCount % 20 === 0) { if (pollCount <= 5 || pollCount % 20 === 0) {
console.log(`Gravity Bridge: [POLL#${pollCount}] error: ${e.message}`); console.log(`Gravity Bridge: [POLL#${pollCount}] error: ${e.message}`);

File diff suppressed because one or more lines are too long

View File

@@ -98,6 +98,8 @@ function writeChatSnapshot(text: string) {
const filePath = path.join(snapshotDir, `${id}.json`); const filePath = path.join(snapshotDir, `${id}.json`);
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf-8'); fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf-8');
console.log(`Gravity Bridge: chat snapshot written (${text.length} chars) → ${id}.json`); console.log(`Gravity Bridge: chat snapshot written (${text.length} chars) → ${id}.json`);
logToFile(`[SNAPSHOT] written ${id}.json (${text.length} chars)`);
logToFile(`[SNAPSHOT] content: ${text.substring(0, 200)}`);
// Lazily register session → project mapping (correct because projectName is per-window) // Lazily register session → project mapping (correct because projectName is per-window)
if (activeSessionId) { writeRegistration(activeSessionId); } if (activeSessionId) { writeRegistration(activeSessionId); }
} catch (e: any) { } catch (e: any) {
@@ -1709,36 +1711,43 @@ function setupMonitor() {
// ── Process latestNotifyUserStep ── // ── Process latestNotifyUserStep ──
const notifyStep = bestSession.latestNotifyUserStep; const notifyStep = bestSession.latestNotifyUserStep;
if (notifyStep && notifyStep.stepIndex > lastNotifyStepIndex) { if (notifyStep) {
if (notifyStep.stepIndex > lastNotifyStepIndex) {
lastNotifyStepIndex = notifyStep.stepIndex; lastNotifyStepIndex = notifyStep.stepIndex;
const content = notifyStep.step?.notifyUser?.notificationContent || ''; const content = notifyStep.step?.notifyUser?.notificationContent || '';
// Filter: only relay meaningful notifications (skip trivial ones) logToFile(`[NOTIFY-STEP] NEW step=${notifyStep.stepIndex} content=${content.length} chars`);
if (content.length > 50) { // Filter: relay all non-empty notifications
if (content.length > 10) {
writeChatSnapshot(`📣 **알림** (step ${notifyStep.stepIndex})\n\n${content}`); writeChatSnapshot(`📣 **알림** (step ${notifyStep.stepIndex})\n\n${content}`);
console.log(`Gravity Bridge: [POLL#${pollCount}] NOTIFY step=${notifyStep.stepIndex} ${content.length} chars`);
} else if (content.length > 0) { } else if (content.length > 0) {
logToFile(`[POLL] NOTIFY skipped (too short: ${content.length} chars): ${content.substring(0, 80)}`); logToFile(`[NOTIFY-STEP] skipped (too short: ${content.length} chars): ${content}`);
} }
} }
} else if (pollCount <= 5) {
logToFile(`[NOTIFY-STEP] null (no notify step in session)`);
}
// ── Process latestTaskBoundaryStep ── // ── Process latestTaskBoundaryStep ──
const taskStep = bestSession.latestTaskBoundaryStep; const taskStep = bestSession.latestTaskBoundaryStep;
if (taskStep && taskStep.stepIndex > lastTaskStepIndex) { if (taskStep) {
if (taskStep.stepIndex > lastTaskStepIndex) {
lastTaskStepIndex = taskStep.stepIndex; lastTaskStepIndex = taskStep.stepIndex;
const tb = taskStep.step?.taskBoundary; const tb = taskStep.step?.taskBoundary;
if (tb?.taskName) { if (tb?.taskName) {
const mode = tb.mode ? tb.mode.replace('AGENT_MODE_', '') : ''; const mode = tb.mode ? tb.mode.replace('AGENT_MODE_', '') : '';
// Filter: skip status-only updates with same task name (noise)
const taskText = `${tb.taskName}|${tb.taskStatus || ''}`; const taskText = `${tb.taskName}|${tb.taskStatus || ''}`;
logToFile(`[TASK-STEP] NEW step=${taskStep.stepIndex} name="${tb.taskName}" mode=${mode}`);
if (taskText !== lastRelayedTaskText) { if (taskText !== lastRelayedTaskText) {
lastRelayedTaskText = taskText; lastRelayedTaskText = taskText;
writeChatSnapshot(`📋 **[${mode}] ${tb.taskName}**\n${tb.taskStatus || ''}\n\n${tb.taskSummary || ''}`); writeChatSnapshot(`📋 **[${mode}] ${tb.taskName}**\n${tb.taskStatus || ''}\n\n${tb.taskSummary || ''}`);
console.log(`Gravity Bridge: [POLL#${pollCount}] TASK step=${taskStep.stepIndex} "${tb.taskName}"`);
} else { } else {
logToFile(`[POLL] TASK skipped (duplicate): "${tb.taskName}"`); logToFile(`[TASK-STEP] skipped (duplicate): "${tb.taskName}"`);
} }
} }
} }
} else if (pollCount <= 5) {
logToFile(`[TASK-STEP] null (no task step in session)`);
}
} catch (e: any) { } catch (e: any) {
if (pollCount <= 5 || pollCount % 20 === 0) { if (pollCount <= 5 || pollCount % 20 === 0) {
console.log(`Gravity Bridge: [POLL#${pollCount}] error: ${e.message}`); console.log(`Gravity Bridge: [POLL#${pollCount}] error: ${e.message}`);