From f8db360d06acdf224dcd21d4bdb4c1a4f843b532 Mon Sep 17 00:00:00 2001 From: Johnathon Selstad Date: Mon, 26 Jan 2026 14:48:26 -0800 Subject: [PATCH] fix: Address Copilot review comments 1. Move sessionTokens Map inside createPresenceManager to avoid cross-account collisions (now scoped per-account) 2. Add NOTE explaining that usage stats aren't available in the message_sent hook currently - this would require threading usage data through the entire reply pipeline (follow-up work) --- src/auto-reply/reply/dispatch-from-config.ts | 6 ++++++ src/discord/monitor/presence-manager.ts | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/auto-reply/reply/dispatch-from-config.ts b/src/auto-reply/reply/dispatch-from-config.ts index acfea5176..428320a68 100644 --- a/src/auto-reply/reply/dispatch-from-config.ts +++ b/src/auto-reply/reply/dispatch-from-config.ts @@ -333,6 +333,12 @@ export async function dispatchReplyFromConfig(params: { counts.final += routedFinalCount; // Trigger message_sent hook for final replies + // NOTE: Usage stats (tokens, model, etc.) are not currently available here. + // They are computed in agent-runner.ts but not returned through the reply pipeline. + // To enable full usage tracking, getReplyFromConfig/replyResolver would need to + // return usage data alongside the reply text. For now, hooks receive the message + // content without usage stats - presence managers can track cumulative tokens + // via other means (e.g., diagnostic events or session metadata). if (hookRunner?.hasHooks("message_sent") && replies.length > 0) { const targetSessionKey = ctx.CommandSource === "native" ? ctx.CommandTargetSessionKey?.trim() : undefined; diff --git a/src/discord/monitor/presence-manager.ts b/src/discord/monitor/presence-manager.ts index 4f9323d71..ce75460b7 100644 --- a/src/discord/monitor/presence-manager.ts +++ b/src/discord/monitor/presence-manager.ts @@ -38,9 +38,6 @@ const ACTIVITY_TYPE_MAP: Record = { Competing: 5, // "Competing in {name}" }; -// Track cumulative tokens per session -const sessionTokens = new Map(); - /** * Create a presence manager for a Discord gateway */ @@ -51,6 +48,9 @@ export function createPresenceManager(params: { }) { const { gateway, config, accountId } = params; + // Track cumulative tokens per session (scoped per-account to avoid cross-account collisions) + const sessionTokens = new Map(); + const defaultFormat = config.showTokenUsage ? "📊 {tokens} tokens" : ""; const format = config.format ?? defaultFormat; // Default to "Watching" as it reads well: "Watching 📊 1,234 tokens"