From 68ebaf501480f941555320ec662bf2be3a8deddc Mon Sep 17 00:00:00 2001 From: Claudia Date: Sun, 1 Feb 2026 19:44:52 +0100 Subject: [PATCH] debug: add file-based logging to track message handling Writes to /home/keller/clawd/agents/mondo-assistant/matrix-debug.log --- src/matrix/monitor/debug-log.ts | 14 ++++++++++++++ src/matrix/monitor/handler.ts | 13 +++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/matrix/monitor/debug-log.ts diff --git a/src/matrix/monitor/debug-log.ts b/src/matrix/monitor/debug-log.ts new file mode 100644 index 000000000..2b47ff5eb --- /dev/null +++ b/src/matrix/monitor/debug-log.ts @@ -0,0 +1,14 @@ +import fs from "node:fs"; +import path from "node:path"; + +const DEBUG_LOG_PATH = "/home/keller/clawd/agents/mondo-assistant/debug-matrix.log"; + +export function debugLog(message: string): void { + const timestamp = new Date().toISOString(); + const line = `[${timestamp}] ${message}\n`; + try { + fs.appendFileSync(DEBUG_LOG_PATH, line); + } catch { + // Ignore errors + } +} diff --git a/src/matrix/monitor/handler.ts b/src/matrix/monitor/handler.ts index acaff70bf..410635fe1 100644 --- a/src/matrix/monitor/handler.ts +++ b/src/matrix/monitor/handler.ts @@ -1,4 +1,13 @@ import type { LocationMessageEventContent, MatrixClient } from "@vector-im/matrix-bot-sdk"; +import fs from "node:fs"; + +// File-based debug logging +const DEBUG_LOG = "/home/keller/clawd/agents/mondo-assistant/matrix-debug.log"; +function debugWrite(msg: string) { + try { + fs.appendFileSync(DEBUG_LOG, `[${new Date().toISOString()}] ${msg}\n`); + } catch { /* ignore */ } +} import { createReplyPrefixContext, @@ -110,9 +119,11 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam } = params; return async (roomId: string, event: MatrixRawEvent) => { + debugWrite(`HANDLER-START: room=${roomId} eventId=${event.event_id ?? "unknown"} type=${event.type} sender=${event.sender} accountId=${accountId ?? "default"}`); try { const eventType = event.type; if (eventType === EventType.RoomMessageEncrypted) { + debugWrite(`HANDLER: SKIP encrypted event (should be auto-decrypted)`); // Encrypted messages are decrypted automatically by @vector-im/matrix-bot-sdk with crypto enabled return; } @@ -331,9 +342,11 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam // DEBUG: Log media detection const msgtype = "msgtype" in content ? content.msgtype : undefined; + debugWrite(`HANDLER: room=${roomId} sender=${senderId} msgtype=${msgtype} contentUrl=${contentUrl ?? "none"} mediaUrl=${mediaUrl ?? "none"} accountId=${accountId ?? "default"}`); logVerboseMessage(`matrix: content check msgtype=${msgtype} contentUrl=${contentUrl ?? "none"} mediaUrl=${mediaUrl ?? "none"} rawBody="${rawBody.slice(0,50)}"`); if (!rawBody && !mediaUrl) { + debugWrite(`HANDLER: SKIP - no rawBody and no mediaUrl`); return; }