@@ -5,7 +5,7 @@ import type { StateManager } from "./state"
55import { buildAnalysisPrompt } from "./prompt"
66import { selectModel , extractModelFromSession } from "./model-selector"
77import { estimateTokensBatch , formatTokenCount } from "./tokenizer"
8- import { detectDuplicates } from "./deduplicator"
8+ import { detectDuplicates , extractParameterKey } from "./deduplicator"
99
1010export class Janitor {
1111 constructor (
@@ -505,10 +505,17 @@ export class Janitor {
505505
506506 /**
507507 * Build a summary of tools by grouping them
508+ * Uses shared extractParameterKey logic for consistent parameter extraction
508509 */
509510 private buildToolsSummary ( prunedIds : string [ ] , toolMetadata : Map < string , { tool : string , parameters ?: any } > ) : Map < string , string [ ] > {
510511 const toolsSummary = new Map < string , string [ ] > ( )
511512
513+ // Helper function to truncate long strings
514+ const truncate = ( str : string , maxLen : number = 60 ) : string => {
515+ if ( str . length <= maxLen ) return str
516+ return str . slice ( 0 , maxLen - 3 ) + '...'
517+ }
518+
512519 for ( const prunedId of prunedIds ) {
513520 const metadata = toolMetadata . get ( prunedId )
514521 if ( metadata ) {
@@ -517,45 +524,12 @@ export class Janitor {
517524 toolsSummary . set ( toolName , [ ] )
518525 }
519526
520- // Helper function to truncate long strings
521- const truncate = ( str : string , maxLen : number = 60 ) : string => {
522- if ( str . length <= maxLen ) return str
523- return str . slice ( 0 , maxLen - 3 ) + '...'
524- }
525-
526- // Extract meaningful parameter info based on tool type
527- let paramInfo = ""
528- if ( metadata . parameters ) {
529- // For read tool, show filePath
530- if ( toolName === "read" && metadata . parameters . filePath ) {
531- paramInfo = truncate ( this . shortenPath ( metadata . parameters . filePath ) , 80 )
532- }
533- // For list tool, show path
534- else if ( toolName === "list" && metadata . parameters . path ) {
535- paramInfo = truncate ( this . shortenPath ( metadata . parameters . path ) , 80 )
536- }
537- // For bash/command tools, prefer description over command
538- else if ( toolName === "bash" ) {
539- if ( metadata . parameters . description ) {
540- paramInfo = truncate ( metadata . parameters . description , 80 )
541- } else if ( metadata . parameters . command ) {
542- paramInfo = truncate ( metadata . parameters . command , 80 )
543- }
544- }
545- // For other tools, show the first relevant parameter
546- else if ( metadata . parameters . path ) {
547- paramInfo = truncate ( this . shortenPath ( metadata . parameters . path ) , 80 )
548- }
549- else if ( metadata . parameters . pattern ) {
550- paramInfo = truncate ( metadata . parameters . pattern , 80 )
551- }
552- else if ( metadata . parameters . command ) {
553- paramInfo = truncate ( metadata . parameters . command , 80 )
554- }
555- }
556-
557- if ( paramInfo ) {
558- toolsSummary . get ( toolName ) ! . push ( paramInfo )
527+ // Use shared parameter extraction logic
528+ const paramKey = extractParameterKey ( metadata )
529+ if ( paramKey ) {
530+ // Apply path shortening and truncation for display
531+ const displayKey = truncate ( this . shortenPath ( paramKey ) , 80 )
532+ toolsSummary . get ( toolName ) ! . push ( displayKey )
559533 }
560534 }
561535 }
0 commit comments