debug: add file-based logging to track message handling

Writes to /home/keller/clawd/agents/mondo-assistant/matrix-debug.log
This commit is contained in:
Claudia 2026-02-01 19:44:52 +01:00
parent fc96f0e967
commit 68ebaf5014
2 changed files with 27 additions and 0 deletions

View file

@ -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
}
}

View file

@ -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;
}