11import type { Logger } from "../logger"
22import type { SessionState } from "../state"
33import {
4+ countDistillationTokens ,
45 formatExtracted ,
56 formatPrunedItemsList ,
67 formatStatsHeader ,
@@ -19,36 +20,46 @@ export const PRUNE_REASON_LABELS: Record<PruneReason, string> = {
1920function buildMinimalMessage (
2021 state : SessionState ,
2122 reason : PruneReason | undefined ,
22- distillation ?: string [ ] ,
23+ distillation : string [ ] | undefined ,
24+ showDistillation : boolean ,
2325) : string {
24- const reasonSuffix = reason ? ` — ${ PRUNE_REASON_LABELS [ reason ] } ` : ""
26+ const extractedTokens = countDistillationTokens ( distillation )
27+ const extractedSuffix =
28+ extractedTokens > 0 ? ` (extracted ${ formatTokenCount ( extractedTokens ) } )` : ""
29+ const reasonSuffix = reason && extractedTokens === 0 ? ` — ${ PRUNE_REASON_LABELS [ reason ] } ` : ""
2530 let message =
2631 formatStatsHeader ( state . stats . totalPruneTokens , state . stats . pruneTokenCounter ) +
27- reasonSuffix
32+ reasonSuffix +
33+ extractedSuffix
2834
29- return message + formatExtracted ( distillation )
35+ return message + formatExtracted ( showDistillation ? distillation : undefined )
3036}
3137
3238function buildDetailedMessage (
3339 state : SessionState ,
3440 reason : PruneReason | undefined ,
3541 pruneToolIds : string [ ] ,
3642 toolMetadata : Map < string , ToolParameterEntry > ,
37- workingDirectory ?: string ,
38- distillation ?: string [ ] ,
43+ workingDirectory : string ,
44+ distillation : string [ ] | undefined ,
45+ showDistillation : boolean ,
3946) : string {
4047 let message = formatStatsHeader ( state . stats . totalPruneTokens , state . stats . pruneTokenCounter )
4148
4249 if ( pruneToolIds . length > 0 ) {
4350 const pruneTokenCounterStr = `~${ formatTokenCount ( state . stats . pruneTokenCounter ) } `
44- const reasonLabel = reason ? ` — ${ PRUNE_REASON_LABELS [ reason ] } ` : ""
45- message += `\n\n▣ Pruning (${ pruneTokenCounterStr } )${ reasonLabel } `
51+ const extractedTokens = countDistillationTokens ( distillation )
52+ const extractedSuffix =
53+ extractedTokens > 0 ? `, extracted ${ formatTokenCount ( extractedTokens ) } ` : ""
54+ const reasonLabel =
55+ reason && extractedTokens === 0 ? ` — ${ PRUNE_REASON_LABELS [ reason ] } ` : ""
56+ message += `\n\n▣ Pruning (${ pruneTokenCounterStr } ${ extractedSuffix } )${ reasonLabel } `
4657
4758 const itemLines = formatPrunedItemsList ( pruneToolIds , toolMetadata , workingDirectory )
4859 message += "\n" + itemLines . join ( "\n" )
4960 }
5061
51- return ( message + formatExtracted ( distillation ) ) . trim ( )
62+ return ( message + formatExtracted ( showDistillation ? distillation : undefined ) ) . trim ( )
5263}
5364
5465export async function sendUnifiedNotification (
@@ -73,18 +84,19 @@ export async function sendUnifiedNotification(
7384 return false
7485 }
7586
76- const showExtraction = config . tools . extract . showDistillation ? distillation : undefined
87+ const showDistillation = config . tools . extract . showDistillation
7788
7889 const message =
7990 config . pruneNotification === "minimal"
80- ? buildMinimalMessage ( state , reason , showExtraction )
91+ ? buildMinimalMessage ( state , reason , distillation , showDistillation )
8192 : buildDetailedMessage (
8293 state ,
8394 reason ,
8495 pruneToolIds ,
8596 toolMetadata ,
8697 workingDirectory ,
87- showExtraction ,
98+ distillation ,
99+ showDistillation ,
88100 )
89101
90102 await sendIgnoredMessage ( client , sessionId , message , params , logger )
0 commit comments