@@ -66,9 +66,9 @@ function unwrapOutputContent(content: unknown): { roleOverride: NormalizedRole |
6666 return { roleOverride, content : messageContent }
6767}
6868
69- function formatPlainText ( role : NormalizedRole | null , text : string ) : string {
69+ function formatPlainText ( role : NormalizedRole | null , text : string , agentLabel = 'coding agent' ) : string {
7070 if ( role === 'assistant' ) {
71- return `Claude Code : \n<text>${ text } </text>`
71+ return `${ agentLabel } : \n<text>${ text } </text>`
7272 }
7373 return `User sent message: \n<text>${ text } </text>`
7474}
@@ -80,9 +80,10 @@ export function formatPermissionRequest(
8080 sessionId : string ,
8181 requestId : string ,
8282 toolName : string ,
83- toolArgs : unknown
83+ toolArgs : unknown ,
84+ agentLabel = 'coding agent'
8485) : string {
85- return `Claude Code is requesting permission to use ${ toolName } (session ${ sessionId } ):
86+ return `${ agentLabel } is requesting permission to use ${ toolName } (session ${ sessionId } ):
8687<request_id>${ requestId } </request_id>
8788<tool_name>${ toolName } </tool_name>
8889<tool_args>${ JSON . stringify ( toolArgs ) } </tool_args>`
@@ -91,7 +92,7 @@ export function formatPermissionRequest(
9192/**
9293 * Format a single message for voice context
9394 */
94- export function formatMessage ( message : DecryptedMessage ) : string | null {
95+ export function formatMessage ( message : DecryptedMessage , agentLabel = 'coding agent' ) : string | null {
9596 const { role, content : wrappedContent } = unwrapRoleWrappedContent ( message )
9697 const { roleOverride, content } = unwrapOutputContent ( wrappedContent )
9798 const normalizedRole = roleOverride ?? role
@@ -103,7 +104,7 @@ export function formatMessage(message: DecryptedMessage): string | null {
103104 const speakable = ! isContentArray ( content ) ? extractSpeakableFromContent ( content ) : null
104105 if ( speakable ) {
105106 const roleForFormat = normalizedRole === 'user' ? 'user' : 'assistant'
106- return formatPlainText ( roleForFormat , speakable )
107+ return formatPlainText ( roleForFormat , speakable , agentLabel )
107108 }
108109
109110 if ( ! isContentArray ( content ) ) {
@@ -122,13 +123,13 @@ export function formatMessage(message: DecryptedMessage): string | null {
122123
123124 for ( const item of content ) {
124125 if ( item . type === 'text' && item . text ) {
125- lines . push ( formatPlainText ( isAssistant ? 'assistant' : 'user' , item . text ) )
126+ lines . push ( formatPlainText ( isAssistant ? 'assistant' : 'user' , item . text , agentLabel ) )
126127 } else if ( item . type === 'tool_use' && ! VOICE_CONFIG . DISABLE_TOOL_CALLS ) {
127128 const name = item . name || 'unknown'
128129 if ( VOICE_CONFIG . LIMITED_TOOL_CALLS ) {
129- lines . push ( `Claude Code is using ${ name } ` )
130+ lines . push ( `${ agentLabel } is using ${ name } ` )
130131 } else {
131- lines . push ( `Claude Code is using ${ name } with arguments: <arguments>${ JSON . stringify ( item . input ) } </arguments>` )
132+ lines . push ( `${ agentLabel } is using ${ name } with arguments: <arguments>${ JSON . stringify ( item . input ) } </arguments>` )
132133 }
133134 }
134135 }
@@ -214,34 +215,34 @@ export function extractLastAssistantSpeakable(messages: DecryptedMessage[]): str
214215 return null
215216}
216217
217- export function formatNewSingleMessage ( sessionId : string , message : DecryptedMessage ) : string | null {
218- const formatted = formatMessage ( message )
218+ export function formatNewSingleMessage ( sessionId : string , message : DecryptedMessage , agentLabel = 'coding agent' ) : string | null {
219+ const formatted = formatMessage ( message , agentLabel )
219220 if ( ! formatted ) {
220221 return null
221222 }
222223 return 'New message in session: ' + sessionId + '\n\n' + formatted
223224}
224225
225- export function formatNewMessages ( sessionId : string , messages : DecryptedMessage [ ] ) : string | null {
226+ export function formatNewMessages ( sessionId : string , messages : DecryptedMessage [ ] , agentLabel = 'coding agent' ) : string | null {
226227 const formatted = [ ...messages ]
227228 . sort ( ( a , b ) => ( a . seq ?? 0 ) - ( b . seq ?? 0 ) )
228- . map ( formatMessage )
229+ . map ( m => formatMessage ( m , agentLabel ) )
229230 . filter ( Boolean )
230231 if ( formatted . length === 0 ) {
231232 return null
232233 }
233234 return 'New messages in session: ' + sessionId + '\n\n' + formatted . join ( '\n\n' )
234235}
235236
236- export function formatHistory ( sessionId : string , messages : DecryptedMessage [ ] ) : string {
237+ export function formatHistory ( sessionId : string , messages : DecryptedMessage [ ] , agentLabel = 'coding agent' ) : string {
237238 const messagesToFormat = VOICE_CONFIG . MAX_HISTORY_MESSAGES > 0
238239 ? messages . slice ( - VOICE_CONFIG . MAX_HISTORY_MESSAGES )
239240 : messages
240- const formatted = messagesToFormat . map ( formatMessage ) . filter ( Boolean )
241+ const formatted = messagesToFormat . map ( m => formatMessage ( m , agentLabel ) ) . filter ( Boolean )
241242 return 'History of messages in session: ' + sessionId + '\n\n' + formatted . join ( '\n\n' )
242243}
243244
244- export function formatSessionFull ( session : Session | null , messages : DecryptedMessage [ ] ) : string {
245+ export function formatSessionFull ( session : Session | null , messages : DecryptedMessage [ ] , agentLabel = 'coding agent' ) : string {
245246 if ( ! session ) {
246247 return 'Session not available'
247248 }
@@ -262,7 +263,7 @@ export function formatSessionFull(session: Session | null, messages: DecryptedMe
262263
263264 lines . push ( '## Our interaction history so far' )
264265 lines . push ( '' )
265- lines . push ( formatHistory ( session . id , messages ) )
266+ lines . push ( formatHistory ( session . id , messages , agentLabel ) )
266267
267268 return lines . join ( '\n\n' )
268269}
@@ -279,10 +280,10 @@ export function formatSessionFocus(sessionId: string, _metadata?: SessionMetadat
279280 return `Session became focused: ${ sessionId } `
280281}
281282
282- export function formatReadyEvent ( sessionId : string , lastAssistantText ?: string | null ) : string {
283+ export function formatReadyEvent ( sessionId : string , lastAssistantText ?: string | null , agentLabel = 'coding agent' ) : string {
283284 const trimmed = lastAssistantText ?. trim ( )
284285 if ( trimmed ) {
285- return `The coding agent finished working in session: ${ sessionId } . Summarize this for the human immediately:\n<text>${ trimmed } </text>`
286+ return `${ agentLabel } finished working in session: ${ sessionId } . Summarize this for the human immediately:\n<text>${ trimmed } </text>`
286287 }
287- return `The coding agent finished working in session: ${ sessionId } . Use the latest agent message already present in context and summarize it for the human immediately.`
288+ return `${ agentLabel } finished working in session: ${ sessionId } . Use the latest agent message already present in context and summarize it for the human immediately.`
288289}
0 commit comments