@@ -544,10 +544,21 @@ export function createHudPluginHooks(
544544 runtimeConfig : HudRuntimeConfig = resolveRuntimeConfig ( ) ,
545545 runtimeOptions : HudPluginRuntimeOptions = { }
546546) : HudPluginHooks {
547+ const MAX_SESSION_ENTRIES = 50
547548 const sessionRuntimes = new Map < string , SessionRuntime > ( )
548549 const sessionAgentMap = new Map < string , string > ( )
549550 let latestSessionKey : string | null = null
550551
552+ function pruneMap < V > ( map : Map < string , V > ) : void {
553+ if ( map . size <= MAX_SESSION_ENTRIES ) return
554+ const excess = map . size - MAX_SESSION_ENTRIES
555+ const iter = map . keys ( )
556+ for ( let i = 0 ; i < excess ; i ++ ) {
557+ const key = iter . next ( ) . value
558+ if ( key !== undefined ) map . delete ( key )
559+ }
560+ }
561+
551562 const registry = createModelRegistry ( )
552563 const aggregator = createUsageAggregator ( )
553564 const diskCache = createDiskCache ( )
@@ -801,6 +812,7 @@ export function createHudPluginHooks(
801812 lastCompletedUsage : null
802813 }
803814 sessionRuntimes . set ( sessionKey , created )
815+ pruneMap ( sessionRuntimes )
804816 return created
805817 }
806818
@@ -971,6 +983,7 @@ export function createHudPluginHooks(
971983 : undefined
972984 if ( name ) {
973985 sessionAgentMap . set ( toSessionKey ( input . sessionID ) , name )
986+ pruneMap ( sessionAgentMap )
974987 }
975988 }
976989 if ( input . model && input . provider ) {
0 commit comments