11import { AIAgent , AIAgentResult } from '../services/MockAIAgent' ;
2+ import { universalConfigService } from '../config/UniversalConfigService' ;
23
34/**
45 * Electron Shell AI Agent that uses IPC to execute shell commands in main process
56 * This avoids Node.js module compatibility issues with Vite build
67 */
78export class ElectronShellAIAgent implements AIAgent {
89 name = 'Electron IPC Shell AI Agent' ;
10+ private outputConfig : { useCodeBlock : boolean ; codeBlockSyntax : string } = {
11+ useCodeBlock : true ,
12+ codeBlockSyntax : 'shell'
13+ } ;
914
1015 async executeCommand ( _command : string ) : Promise < AIAgentResult > {
1116 return {
@@ -36,6 +41,16 @@ export class ElectronShellAIAgent implements AIAgent {
3641 async generateResponse ( messages : any [ ] ) : Promise < string > {
3742 console . log ( '🎯 ElectronShellAIAgent.generateResponse called with messages:' , messages ) ;
3843
44+ // Load output format config
45+ const shellConfig = universalConfigService . get < any > ( 'ai:shell' ) ;
46+ if ( shellConfig ?. outputFormat ) {
47+ this . outputConfig = {
48+ useCodeBlock : shellConfig . outputFormat . useCodeBlock ?? true ,
49+ codeBlockSyntax : shellConfig . outputFormat . codeBlockSyntax || 'shell'
50+ } ;
51+ }
52+ console . log ( 'Using output config:' , this . outputConfig ) ;
53+
3954 // Convert message history to a single prompt
4055 const lastMessage = messages [ messages . length - 1 ] ;
4156 const prompt = lastMessage ?. content || '' ;
@@ -45,26 +60,36 @@ export class ElectronShellAIAgent implements AIAgent {
4560 const result = await this . query ( prompt ) ;
4661 console . log ( 'ElectronShellAIAgent query result:' , result ) ;
4762
48- // Format output for markdown rendering (with code blocks)
63+ // Format output based on config
4964 let output = '' ;
65+ const wrapInCodeBlock = ( text : string ) => {
66+ if ( this . outputConfig . useCodeBlock ) {
67+ return `\`\`\`${ this . outputConfig . codeBlockSyntax } \n${ text } \n\`\`\`` ;
68+ }
69+ return text ;
70+ } ;
71+
5072 if ( result . success ) {
5173 const stdout = result . metadata ?. stdout || result . content || 'Command completed successfully' ;
52- output = `\`\`\`\n ${ stdout } \n\`\`\`` ;
74+ output = wrapInCodeBlock ( stdout ) ;
5375
5476 // Include stderr if present
5577 if ( result . metadata ?. stderr && result . metadata . stderr . trim ( ) ) {
56- output += `\n\n**stderr:**\n\`\`\`\n${ result . metadata . stderr . trim ( ) } \n\`\`\`` ;
78+ const stderrFormatted = wrapInCodeBlock ( result . metadata . stderr . trim ( ) ) ;
79+ output += `\n\n**stderr:**\n${ stderrFormatted } ` ;
5780 }
5881 } else {
5982 // For failures, show comprehensive error info in markdown format
6083 output = '**Command failed**\n\n' ;
6184
6285 if ( result . metadata ?. stderr && result . metadata . stderr . trim ( ) ) {
63- output += `**stderr:**\n\`\`\`\n${ result . metadata . stderr . trim ( ) } \n\`\`\`\n\n` ;
86+ const stderrFormatted = wrapInCodeBlock ( result . metadata . stderr . trim ( ) ) ;
87+ output += `**stderr:**\n${ stderrFormatted } \n\n` ;
6488 }
6589
6690 if ( result . metadata ?. stdout && result . metadata . stdout . trim ( ) ) {
67- output += `**stdout:**\n\`\`\`\n${ result . metadata . stdout . trim ( ) } \n\`\`\`\n\n` ;
91+ const stdoutFormatted = wrapInCodeBlock ( result . metadata . stdout . trim ( ) ) ;
92+ output += `**stdout:**\n${ stdoutFormatted } \n\n` ;
6893 }
6994
7095 if ( result . metadata ?. exitCode !== undefined ) {
0 commit comments