11import type { Logger } from "../logger"
22import type { SessionState } from "../state"
3- import { formatPrunedItemsList , formatTokenCount } from "./utils"
3+ import {
4+ formatExtracted ,
5+ formatPrunedItemsList ,
6+ formatStatsHeader ,
7+ formatTokenCount ,
8+ } from "./utils"
49import { ToolParameterEntry } from "../state"
510import { PluginConfig } from "../config"
611
7- export type PruneReason = "completion" | "noise" | "consolidation "
12+ export type PruneReason = "completion" | "noise" | "extraction "
813export const PRUNE_REASON_LABELS : Record < PruneReason , string > = {
914 completion : "Task Complete" ,
1015 noise : "Noise Removal" ,
11- consolidation : "Consolidation " ,
16+ extraction : "Extraction " ,
1217}
1318
14- function formatStatsHeader ( totalTokensSaved : number , pruneTokenCounter : number ) : string {
15- const totalTokensSavedStr = `~${ formatTokenCount ( totalTokensSaved + pruneTokenCounter ) } `
16- return [ `▣ DCP | ${ totalTokensSavedStr } saved total` ] . join ( "\n" )
17- }
18-
19- function buildMinimalMessage ( state : SessionState , reason : PruneReason | undefined ) : string {
20- const reasonSuffix = reason ? ` [${ PRUNE_REASON_LABELS [ reason ] } ]` : ""
21- return (
19+ function buildMinimalMessage (
20+ state : SessionState ,
21+ reason : PruneReason | undefined ,
22+ distillation ?: string [ ] ,
23+ ) : string {
24+ const reasonSuffix = reason ? ` — ${ PRUNE_REASON_LABELS [ reason ] } ` : ""
25+ let message =
2226 formatStatsHeader ( state . stats . totalPruneTokens , state . stats . pruneTokenCounter ) +
2327 reasonSuffix
24- )
28+
29+ return message + formatExtracted ( distillation )
2530}
2631
2732function buildDetailedMessage (
@@ -30,6 +35,7 @@ function buildDetailedMessage(
3035 pruneToolIds : string [ ] ,
3136 toolMetadata : Map < string , ToolParameterEntry > ,
3237 workingDirectory ?: string ,
38+ distillation ?: string [ ] ,
3339) : string {
3440 let message = formatStatsHeader ( state . stats . totalPruneTokens , state . stats . pruneTokenCounter )
3541
@@ -42,7 +48,7 @@ function buildDetailedMessage(
4248 message += "\n" + itemLines . join ( "\n" )
4349 }
4450
45- return message . trim ( )
51+ return ( message + formatExtracted ( distillation ) ) . trim ( )
4652}
4753
4854export async function sendUnifiedNotification (
@@ -56,6 +62,7 @@ export async function sendUnifiedNotification(
5662 reason : PruneReason | undefined ,
5763 params : any ,
5864 workingDirectory : string ,
65+ distillation ?: string [ ] ,
5966) : Promise < boolean > {
6067 const hasPruned = pruneToolIds . length > 0
6168 if ( ! hasPruned ) {
@@ -66,42 +73,20 @@ export async function sendUnifiedNotification(
6673 return false
6774 }
6875
76+ const showExtraction = config . tools . extract . showDistillation ? distillation : undefined
77+
6978 const message =
7079 config . pruneNotification === "minimal"
71- ? buildMinimalMessage ( state , reason )
72- : buildDetailedMessage ( state , reason , pruneToolIds , toolMetadata , workingDirectory )
73-
74- await sendIgnoredMessage ( client , sessionId , message , params , logger )
75- return true
76- }
77-
78- function formatDistillationMessage ( distillation : Record < string , any > ) : string {
79- const lines : string [ ] = [ "▣ DCP | Extracted Distillation" ]
80-
81- for ( const findings of Object . values ( distillation ) ) {
82- lines . push ( `\n───` )
83- if ( typeof findings === "object" && findings !== null ) {
84- lines . push ( JSON . stringify ( findings , null , 2 ) )
85- } else {
86- lines . push ( String ( findings ) )
87- }
88- }
89-
90- return lines . join ( "\n" )
91- }
92-
93- export async function sendDistillationNotification (
94- client : any ,
95- logger : Logger ,
96- sessionId : string ,
97- distillation : Record < string , any > ,
98- params : any ,
99- ) : Promise < boolean > {
100- if ( ! distillation || Object . keys ( distillation ) . length === 0 ) {
101- return false
102- }
80+ ? buildMinimalMessage ( state , reason , showExtraction )
81+ : buildDetailedMessage (
82+ state ,
83+ reason ,
84+ pruneToolIds ,
85+ toolMetadata ,
86+ workingDirectory ,
87+ showExtraction ,
88+ )
10389
104- const message = formatDistillationMessage ( distillation )
10590 await sendIgnoredMessage ( client , sessionId , message , params , logger )
10691 return true
10792}
0 commit comments