From 29dfe891375f74465ef82d5bce2e3f978114d2c7 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 5 Dec 2025 19:21:23 +0000 Subject: [PATCH] chore: redact long texts in web logs --- src/config/sessions.ts | 3 ++- src/web/auto-reply.ts | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/config/sessions.ts b/src/config/sessions.ts index 3be3621b1..3fb506b87 100644 --- a/src/config/sessions.ts +++ b/src/config/sessions.ts @@ -27,7 +27,8 @@ export const DEFAULT_IDLE_MINUTES = 60; export function resolveStorePath(store?: string) { if (!store) return SESSION_STORE_DEFAULT; - if (store.startsWith("~")) return path.resolve(store.replace("~", os.homedir())); + if (store.startsWith("~")) + return path.resolve(store.replace("~", os.homedir())); return path.resolve(store); } diff --git a/src/web/auto-reply.ts b/src/web/auto-reply.ts index c2bfba319..14ca131e6 100644 --- a/src/web/auto-reply.ts +++ b/src/web/auto-reply.ts @@ -75,6 +75,12 @@ const DEFAULT_REPLY_HEARTBEAT_MINUTES = 30; export const HEARTBEAT_TOKEN = "HEARTBEAT_OK"; export const HEARTBEAT_PROMPT = "HEARTBEAT /think:high"; +function elide(text?: string, limit = 400) { + if (!text) return text; + if (text.length <= limit) return text; + return `${text.slice(0, limit)}… (truncated ${text.length - limit} chars)`; +} + type MentionConfig = { requireMention: boolean; mentionRegexes: RegExp[]; @@ -337,7 +343,12 @@ export async function runWebHeartbeatOnce(opts: { const sendResult = await sender(to, finalText, { verbose }); heartbeatLogger.info( - { to, messageId: sendResult.messageId, chars: finalText.length }, + { + to, + messageId: sendResult.messageId, + chars: finalText.length, + preview: elide(finalText, 140), + }, "heartbeat sent", ); console.log(success(`heartbeat: alert sent to ${to}`)); @@ -479,7 +490,7 @@ async function deliverWebReply(params: { connectionId: connectionId ?? null, to: msg.from, from: msg.to, - text: replyResult.text, + text: elide(replyResult.text, 240), mediaUrl: null, mediaSizeBytes: null, mediaKind: null, @@ -748,7 +759,7 @@ export async function monitorWebProvider( correlationId, from: latest.chatType === "group" ? conversationId : latest.from, to: latest.to, - body: combinedBody, + body: elide(combinedBody, 240), mediaType: latest.mediaType ?? null, mediaPath: latest.mediaPath ?? null, batchSize: messages.length,