@@ -11,7 +11,12 @@ import {
1111 injectExtendedSubAgentResults ,
1212 stripStaleMetadata ,
1313} from "./messages"
14- import { buildToolIdList , isIgnoredUserMessage , stripHallucinations } from "./messages/utils"
14+ import {
15+ buildToolIdList ,
16+ isIgnoredUserMessage ,
17+ sanitizeVisibleOutput ,
18+ stripHallucinations ,
19+ } from "./messages/utils"
1520import { checkSession } from "./state"
1621import { renderSystemPrompt } from "./prompts"
1722import { handleStatsCommand } from "./commands/stats"
@@ -33,9 +38,6 @@ const INTERNAL_AGENT_SIGNATURES = [
3338 "Summarize what was done in this conversation" ,
3439]
3540
36- const DCP_MESSAGE_ID_TAG_REGEX = / < d c p - m e s s a g e - i d > (?: m \d + | b \d + ) < \/ d c p - m e s s a g e - i d > / g
37- const DCP_SYSTEM_REMINDER_REGEX = / < d c p - s y s t e m - r e m i n d e r \b [ ^ > ] * > [ \s \S ] * ?< \/ d c p - s y s t e m - r e m i n d e r > / g
38-
3941function applyManualPrompt ( state : SessionState , messages : WithParts [ ] , logger : Logger ) : void {
4042 const pending = state . pendingManualTrigger
4143 if ( ! pending ) {
@@ -125,7 +127,7 @@ export function createChatMessageTransformHandler(
125127 prompts : PromptStore ,
126128 hostPermissions : HostPermissionSnapshot ,
127129) {
128- return async ( input : { } , output : { messages : WithParts [ ] } ) => {
130+ return async ( _input : { } , output : { messages : WithParts [ ] } ) => {
129131 await checkSession ( client , state , logger , output . messages , config . manualMode . enabled )
130132
131133 syncCompressPermissionState ( state , config , hostPermissions , output . messages )
@@ -280,8 +282,16 @@ export function createTextCompleteHandler() {
280282 _input : { sessionID : string ; messageID : string ; partID : string } ,
281283 output : { text : string } ,
282284 ) => {
283- output . text = output . text
284- . replace ( DCP_SYSTEM_REMINDER_REGEX , "" )
285- . replace ( DCP_MESSAGE_ID_TAG_REGEX , "" )
285+ output . text = sanitizeVisibleOutput ( output . text )
286+ }
287+ }
288+
289+ export function createToolExecuteAfterHandler ( ) {
290+ return async (
291+ _input : { tool : string ; sessionID : string ; callID : string } ,
292+ output : { title : string ; output : string ; metadata : unknown } ,
293+ ) => {
294+ output . title = sanitizeVisibleOutput ( output . title )
295+ output . output = sanitizeVisibleOutput ( output . output )
286296 }
287297}
0 commit comments