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)
This commit is contained in:
Johnathon Selstad 2026-01-26 14:48:26 -08:00
parent 13c3b3844d
commit f8db360d06
2 changed files with 9 additions and 3 deletions

View File

@ -333,6 +333,12 @@ export async function dispatchReplyFromConfig(params: {
counts.final += routedFinalCount; counts.final += routedFinalCount;
// Trigger message_sent hook for final replies // 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) { if (hookRunner?.hasHooks("message_sent") && replies.length > 0) {
const targetSessionKey = const targetSessionKey =
ctx.CommandSource === "native" ? ctx.CommandTargetSessionKey?.trim() : undefined; ctx.CommandSource === "native" ? ctx.CommandTargetSessionKey?.trim() : undefined;

View File

@ -38,9 +38,6 @@ const ACTIVITY_TYPE_MAP: Record<string, number> = {
Competing: 5, // "Competing in {name}" Competing: 5, // "Competing in {name}"
}; };
// Track cumulative tokens per session
const sessionTokens = new Map<string, number>();
/** /**
* Create a presence manager for a Discord gateway * Create a presence manager for a Discord gateway
*/ */
@ -51,6 +48,9 @@ export function createPresenceManager(params: {
}) { }) {
const { gateway, config, accountId } = params; const { gateway, config, accountId } = params;
// Track cumulative tokens per session (scoped per-account to avoid cross-account collisions)
const sessionTokens = new Map<string, number>();
const defaultFormat = config.showTokenUsage ? "📊 {tokens} tokens" : ""; const defaultFormat = config.showTokenUsage ? "📊 {tokens} tokens" : "";
const format = config.format ?? defaultFormat; const format = config.format ?? defaultFormat;
// Default to "Watching" as it reads well: "Watching 📊 1,234 tokens" // Default to "Watching" as it reads well: "Watching 📊 1,234 tokens"