From 5a155697fa4364deea8a23568c930ec5c4a5d525 Mon Sep 17 00:00:00 2001 From: jaydenfyi <213395523+jaydenfyi@users.noreply.github.com> Date: Sun, 25 Jan 2026 19:15:42 +0800 Subject: [PATCH] remove duplicate log tags + log received messages --- .../twitch/src/client-manager-registry.ts | 4 +- extensions/twitch/src/monitor.ts | 34 +++++------ extensions/twitch/src/plugin.ts | 8 +-- extensions/twitch/src/resolver.ts | 8 +-- extensions/twitch/src/send.ts | 2 +- extensions/twitch/src/twitch-client.ts | 60 ++++++++++--------- 6 files changed, 58 insertions(+), 58 deletions(-) diff --git a/extensions/twitch/src/client-manager-registry.ts b/extensions/twitch/src/client-manager-registry.ts index 2d1eaf006..1b7ae23f2 100644 --- a/extensions/twitch/src/client-manager-registry.ts +++ b/extensions/twitch/src/client-manager-registry.ts @@ -52,7 +52,7 @@ export function getOrCreateClientManager( createdAt: Date.now(), }); - logger.info(`[twitch] Registered client manager for account: ${accountId}`); + logger.info(`Registered client manager for account: ${accountId}`); return manager; } @@ -83,7 +83,7 @@ export async function removeClientManager(accountId: string): Promise { // Remove from registry registry.delete(accountId); - entry.logger.info(`[twitch] Unregistered client manager for account: ${accountId}`); + entry.logger.info(`Unregistered client manager for account: ${accountId}`); } /** diff --git a/extensions/twitch/src/monitor.ts b/extensions/twitch/src/monitor.ts index 081503bc5..22100780a 100644 --- a/extensions/twitch/src/monitor.ts +++ b/extensions/twitch/src/monitor.ts @@ -95,7 +95,7 @@ async function processTwitchMessage(params: { sessionKey: ctxPayload.SessionKey ?? route.sessionKey, ctx: ctxPayload, onRecordError: (err) => { - runtime.error?.(`[twitch] Failed updating session meta: ${String(err)}`); + runtime.error?.(`Failed updating session meta: ${String(err)}`); }, }); @@ -144,10 +144,10 @@ async function deliverTwitchReply(params: { try { const clientManager = getOrCreateClientManager(accountId, { - info: (msg) => runtime.log?.(`[twitch] ${msg}`), - warn: (msg) => runtime.log?.(`[twitch] ${msg}`), - error: (msg) => runtime.error?.(`[twitch] ${msg}`), - debug: (msg) => runtime.log?.(`[twitch] ${msg}`), + info: (msg) => runtime.log?.(msg), + warn: (msg) => runtime.log?.(msg), + error: (msg) => runtime.error?.(msg), + debug: (msg) => runtime.log?.(msg), }); const client = await clientManager.getClient( @@ -156,19 +156,19 @@ async function deliverTwitchReply(params: { accountId, ); if (!client) { - runtime.error?.(`[twitch] No client available for sending reply`); + runtime.error?.(`No client available for sending reply`); return; } // Send the reply if (!payload.text) { - runtime.error?.(`[twitch] No text to send in reply payload`); + runtime.error?.(`No text to send in reply payload`); return; } await client.say(channel, payload.text); statusSink?.({ lastOutboundAt: Date.now() }); } catch (err) { - runtime.error?.(`[twitch] Failed to send reply: ${String(err)}`); + runtime.error?.(`Failed to send reply: ${String(err)}`); } } @@ -186,10 +186,10 @@ export async function monitorTwitchProvider( let stopped = false; const logger = { - info: (msg: string) => runtime.log?.(`[twitch] ${msg}`), - warn: (msg: string) => runtime.log?.(`[twitch] ${msg}`), - error: (msg: string) => runtime.error?.(`[twitch] ${msg}`), - debug: (msg: string) => runtime.log?.(`[twitch] ${msg}`), + info: (msg: string) => runtime.log?.(msg), + warn: (msg: string) => runtime.log?.(msg), + error: (msg: string) => runtime.error?.(msg), + debug: (msg: string) => runtime.log?.(msg), }; const clientManager = getOrCreateClientManager(accountId, logger); @@ -200,10 +200,10 @@ export async function monitorTwitchProvider( config as Parameters[1], accountId, ); - runtime.log?.(`[twitch] Connected to Twitch as ${account.username}`); + runtime.log?.(`Connected to Twitch as ${account.username}`); } catch (error) { const errorMsg = error instanceof Error ? error.message : String(error); - runtime.error?.(`[twitch] Failed to connect: ${errorMsg}`); + runtime.error?.(`Failed to connect: ${errorMsg}`); throw error; } @@ -223,9 +223,7 @@ export async function monitorTwitchProvider( }); if (!access.allowed) { - runtime.log?.( - `[twitch] Ignored message from ${message.username}: ${access.reason ?? "blocked"}`, - ); + runtime.log?.(`Ignored message from ${message.username}: ${access.reason ?? "blocked"}`); return; } @@ -242,7 +240,7 @@ export async function monitorTwitchProvider( statusSink, }); } catch (err) { - runtime.error?.(`[twitch] Message processing failed: ${String(err)}`); + runtime.error?.(`Message processing failed: ${String(err)}`); } }); diff --git a/extensions/twitch/src/plugin.ts b/extensions/twitch/src/plugin.ts index 6a43ac3a2..1330c05cb 100644 --- a/extensions/twitch/src/plugin.ts +++ b/extensions/twitch/src/plugin.ts @@ -60,9 +60,7 @@ export const twitchPlugin: ChannelPlugin = { notifyApproval: async ({ id }) => { // Note: Twitch doesn't support DMs from bots, so pairing approval is limited // We'll log the approval instead - console.warn( - `[twitch] Pairing approved for user ${id} (notification sent via chat if possible)`, - ); + console.warn(`Pairing approved for user ${id} (notification sent via chat if possible)`); }, }, @@ -243,7 +241,7 @@ export const twitchPlugin: ChannelPlugin = { lastError: null, }); - ctx.log?.info(`[twitch] Starting Twitch connection for ${account.username}`); + ctx.log?.info(`Starting Twitch connection for ${account.username}`); // Lazy import: the monitor pulls the reply pipeline; avoid ESM init cycles. const { monitorTwitchProvider } = await import("./monitor.js"); @@ -270,7 +268,7 @@ export const twitchPlugin: ChannelPlugin = { lastStopAt: Date.now(), }); - ctx.log?.info(`[twitch] Stopped Twitch connection for ${account.username}`); + ctx.log?.info(`Stopped Twitch connection for ${account.username}`); }, }, }; diff --git a/extensions/twitch/src/resolver.ts b/extensions/twitch/src/resolver.ts index 5e3a66e95..acc578f4b 100644 --- a/extensions/twitch/src/resolver.ts +++ b/extensions/twitch/src/resolver.ts @@ -27,10 +27,10 @@ function normalizeUsername(input: string): string { */ function createLogger(logger?: ChannelLogSink): ChannelLogSink { return { - info: (msg: string) => logger?.info(`[twitch] ${msg}`), - warn: (msg: string) => logger?.warn(`[twitch] ${msg}`), - error: (msg: string) => logger?.error(`[twitch] ${msg}`), - debug: (msg: string) => logger?.debug?.(`[twitch] ${msg}`) ?? (() => {}), + info: (msg: string) => logger?.info(msg), + warn: (msg: string) => logger?.warn(msg), + error: (msg: string) => logger?.error(msg), + debug: (msg: string) => logger?.debug?.(msg) ?? (() => {}), }; } diff --git a/extensions/twitch/src/send.ts b/extensions/twitch/src/send.ts index 25b720150..cc9ff678e 100644 --- a/extensions/twitch/src/send.ts +++ b/extensions/twitch/src/send.ts @@ -126,7 +126,7 @@ export async function sendMessageTwitchInternal( }; } catch (error) { const errorMsg = error instanceof Error ? error.message : String(error); - logger.error(`[twitch] Failed to send message: ${errorMsg}`); + logger.error(`Failed to send message: ${errorMsg}`); return { ok: false, messageId: generateMessageId(), diff --git a/extensions/twitch/src/twitch-client.ts b/extensions/twitch/src/twitch-client.ts index f1d695151..0e2815121 100644 --- a/extensions/twitch/src/twitch-client.ts +++ b/extensions/twitch/src/twitch-client.ts @@ -40,40 +40,34 @@ export class TwitchClientManager { }) .then((userId) => { this.logger.info( - `[twitch] Added user ${userId} to RefreshingAuthProvider for ${account.username}`, + `Added user ${userId} to RefreshingAuthProvider for ${account.username}`, ); }) .catch((err) => { this.logger.error( - `[twitch] Failed to add user to RefreshingAuthProvider: ${err instanceof Error ? err.message : String(err)}`, + `Failed to add user to RefreshingAuthProvider: ${err instanceof Error ? err.message : String(err)}`, ); }); authProvider.onRefresh((userId, token) => { this.logger.info( - `[twitch] Access token refreshed for user ${userId} (expires in ${token.expiresIn ? `${token.expiresIn}s` : "unknown"})`, + `Access token refreshed for user ${userId} (expires in ${token.expiresIn ? `${token.expiresIn}s` : "unknown"})`, ); }); authProvider.onRefreshFailure((userId, error) => { - this.logger.error( - `[twitch] Failed to refresh access token for user ${userId}: ${error.message}`, - ); + this.logger.error(`Failed to refresh access token for user ${userId}: ${error.message}`); }); const refreshStatus = account.refreshToken ? "automatic token refresh enabled" : "token refresh disabled (no refresh token)"; - this.logger.info( - `[twitch] Using RefreshingAuthProvider for ${account.username} (${refreshStatus})`, - ); + this.logger.info(`Using RefreshingAuthProvider for ${account.username} (${refreshStatus})`); return authProvider; } - this.logger.info( - `[twitch] Using StaticAuthProvider for ${account.username} (no clientSecret provided)`, - ); + this.logger.info(`Using StaticAuthProvider for ${account.username} (no clientSecret provided)`); return new StaticAuthProvider(account.clientId, normalizedToken); } @@ -98,17 +92,15 @@ export class TwitchClientManager { if (!tokenResolution.token) { this.logger.error( - `[twitch] Missing Twitch token for account ${account.username} (set channels.twitch.accounts.${account.username}.token or CLAWDBOT_TWITCH_ACCESS_TOKEN for default)`, + `Missing Twitch token for account ${account.username} (set channels.twitch.accounts.${account.username}.token or CLAWDBOT_TWITCH_ACCESS_TOKEN for default)`, ); throw new Error("Missing Twitch token"); } - this.logger.debug?.( - `[twitch] Using ${tokenResolution.source} token source for ${account.username}`, - ); + this.logger.debug?.(`Using ${tokenResolution.source} token source for ${account.username}`); if (!account.clientId) { - this.logger.error(`[twitch] Missing Twitch client ID for account ${account.username}`); + this.logger.error(`Missing Twitch client ID for account ${account.username}`); throw new Error("Missing Twitch client ID"); } @@ -127,22 +119,22 @@ export class TwitchClientManager { log: (level, message) => { switch (level) { case LogLevel.CRITICAL: - this.logger.error(`[twitch] ${message}`); + this.logger.error(`${message}`); break; case LogLevel.ERROR: - this.logger.error(`[twitch] ${message}`); + this.logger.error(`${message}`); break; case LogLevel.WARNING: - this.logger.warn(`[twitch] ${message}`); + this.logger.warn(`${message}`); break; case LogLevel.INFO: - this.logger.info(`[twitch] ${message}`); + this.logger.info(`${message}`); break; case LogLevel.DEBUG: - this.logger.debug?.(`[twitch] ${message}`); + this.logger.debug?.(`${message}`); break; case LogLevel.TRACE: - this.logger.debug?.(`[twitch] ${message}`); + this.logger.debug?.(`${message}`); break; } }, @@ -155,7 +147,7 @@ export class TwitchClientManager { client.connect(); this.clients.set(key, client); - this.logger.info(`[twitch] Connected to Twitch as ${account.username}`); + this.logger.info(`Connected to Twitch as ${account.username}`); return client; } @@ -171,6 +163,12 @@ export class TwitchClientManager { const handler = this.messageHandlers.get(key); if (handler) { const normalizedChannel = channelName.startsWith("#") ? channelName.slice(1) : channelName; + const from = `twitch:${msg.userInfo.userName}`; + const preview = messageText.slice(0, 100).replace(/\n/g, "\\n"); + this.logger.debug?.( + `twitch inbound: channel=${normalizedChannel} from=${from} len=${messageText.length} preview="${preview}"`, + ); + handler({ username: msg.userInfo.userName, displayName: msg.userInfo.displayName, @@ -192,6 +190,12 @@ export class TwitchClientManager { client.onWhisper((_user, messageText, msg) => { const handler = this.messageHandlers.get(key); if (handler) { + const from = `twitch:${msg.userInfo.userName}`; + const preview = messageText.slice(0, 100).replace(/\n/g, "\\n"); + this.logger.debug?.( + `twitch inbound: whisper from=${from} len=${messageText.length} preview="${preview}"`, + ); + handler({ username: msg.userInfo.userName, displayName: msg.userInfo.displayName, @@ -209,7 +213,7 @@ export class TwitchClientManager { } }); - this.logger.info(`[twitch] Set up handlers for ${key}`); + this.logger.info(`Set up handlers for ${key}`); } /** @@ -238,7 +242,7 @@ export class TwitchClientManager { client.quit(); this.clients.delete(key); this.messageHandlers.delete(key); - this.logger.info(`[twitch] Disconnected ${key}`); + this.logger.info(`Disconnected ${key}`); } } @@ -249,7 +253,7 @@ export class TwitchClientManager { this.clients.forEach((client) => client.quit()); this.clients.clear(); this.messageHandlers.clear(); - this.logger.info("[twitch] Disconnected all clients"); + this.logger.info(" Disconnected all clients"); } /** @@ -274,7 +278,7 @@ export class TwitchClientManager { return { ok: true, messageId }; } catch (error) { this.logger.error( - `[twitch] Failed to send message: ${error instanceof Error ? error.message : String(error)}`, + `Failed to send message: ${error instanceof Error ? error.message : String(error)}`, ); return { ok: false,