Coverage for src/alprina_cli/chat_ui_enhanced.py: 0%

80 statements  

« prev     ^ index     » next       coverage.py v7.11.3, created at 2025-11-14 11:27 +0100

1""" 

2Beautiful Kimi-style chat UI enhancements for Alprina. 

3""" 

4 

5from datetime import datetime 

6from rich.console import Console 

7from rich.panel import Panel 

8from rich.text import Text 

9from rich.box import ROUNDED 

10from rich.table import Table 

11 

12console = Console() 

13 

14# Alprina brand color 

15ALPRINA_RED = "#FF0420" 

16 

17 

18def show_beautiful_welcome(): 

19 """Show beautiful ASCII art welcome with Alprina branding.""" 

20 console.clear() 

21 

22 # Beautiful ASCII art header 

23 header = Text() 

24 header.append("\n") 

25 header.append(" █████╗ ██╗ ██████╗ ██████╗ ██╗███╗ ██╗ █████╗ \n", style=f"bold {ALPRINA_RED}") 

26 header.append(" ██╔══██╗██║ ██╔══██╗██╔══██╗██║████╗ ██║██╔══██╗\n", style=f"bold {ALPRINA_RED}") 

27 header.append(" ███████║██║ ██████╔╝██████╔╝██║██╔██╗ ██║███████║\n", style=f"bold {ALPRINA_RED}") 

28 header.append(" ██╔══██║██║ ██╔═══╝ ██╔══██╗██║██║╚██╗██║██╔══██║\n", style=f"bold {ALPRINA_RED}") 

29 header.append(" ██║ ██║███████╗██║ ██║ ██║██║██║ ╚████║██║ ██║\n", style=f"bold {ALPRINA_RED}") 

30 header.append(" ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚═╝ ╚═╝\n", style=f"bold {ALPRINA_RED}") 

31 header.append("\n") 

32 header.append(" AI Security Assistant", style="dim") 

33 header.append(" • ", style="dim") 

34 header.append("Chat Mode", style=ALPRINA_RED) 

35 header.append("\n\n") 

36 

37 console.print(header) 

38 

39 # Capabilities in a beautiful box 

40 capabilities_panel = Panel( 

41 f"[white]I can help you with:[/white]\n\n" 

42 f" [{ALPRINA_RED}]•[/{ALPRINA_RED}] Running security scans on code, APIs, and infrastructure\n" 

43 f" [{ALPRINA_RED}]•[/{ALPRINA_RED}] Explaining vulnerabilities and security findings\n" 

44 f" [{ALPRINA_RED}]•[/{ALPRINA_RED}] Providing remediation steps and code fixes\n" 

45 f" [{ALPRINA_RED}]•[/{ALPRINA_RED}] Answering security questions and best practices\n\n" 

46 f"[dim]Type [bold]/help[/bold] for commands or just ask me anything!\n" 

47 f"Type [bold]exit[/bold] or press [bold]Ctrl+D[/bold] to quit[/dim]", 

48 border_style=ALPRINA_RED, 

49 box=ROUNDED, 

50 padding=(1, 2) 

51 ) 

52 console.print(capabilities_panel) 

53 console.print() 

54 

55 

56def display_user_message(message: str): 

57 """Display user message in Kimi-style beautiful format.""" 

58 timestamp = datetime.now().strftime("%H:%M") 

59 

60 console.print() 

61 console.print(f"[dim]{timestamp}[/dim] [bold white]You[/bold white]") 

62 

63 # Create a subtle message bubble effect 

64 message_panel = Panel( 

65 f"[white]{message}[/white]", 

66 border_style="dim white", 

67 box=ROUNDED, 

68 padding=(0, 1), 

69 expand=False 

70 ) 

71 console.print(message_panel) 

72 

73 

74def display_assistant_header(): 

75 """Display assistant message header in Kimi style.""" 

76 timestamp = datetime.now().strftime("%H:%M") 

77 console.print() 

78 console.print(f"[dim]{timestamp}[/dim] [bold {ALPRINA_RED}]Alprina[/bold {ALPRINA_RED}]") 

79 

80 

81def display_thinking_indicator(): 

82 """Show thinking indicator.""" 

83 console.print(f"[dim {ALPRINA_RED}]● Thinking...[/dim {ALPRINA_RED}]") 

84 

85 

86def display_error(error_message: str): 

87 """Display error in beautiful format.""" 

88 console.print() 

89 console.print(Panel( 

90 f"[red]✗ {error_message}[/red]", 

91 border_style="red", 

92 box=ROUNDED, 

93 padding=(0, 1) 

94 )) 

95 console.print() 

96 

97 

98def display_success(success_message: str): 

99 """Display success message.""" 

100 console.print() 

101 console.print(Panel( 

102 f"[green]✓ {success_message}[/green]", 

103 border_style="green", 

104 box=ROUNDED, 

105 padding=(0, 1) 

106 )) 

107 console.print() 

108 

109 

110def display_info(info_message: str): 

111 """Display info message.""" 

112 console.print() 

113 console.print(Panel( 

114 f"[{ALPRINA_RED}]→[/{ALPRINA_RED}] {info_message}", 

115 border_style=ALPRINA_RED, 

116 box=ROUNDED, 

117 padding=(0, 1) 

118 )) 

119 console.print() 

120 

121 

122def create_help_table(): 

123 """Create beautiful help table.""" 

124 help_table = Table( 

125 title=f"[bold {ALPRINA_RED}]Available Commands[/bold {ALPRINA_RED}]", 

126 show_header=True, 

127 header_style="bold white", 

128 border_style=ALPRINA_RED, 

129 box=ROUNDED, 

130 padding=(0, 1) 

131 ) 

132 help_table.add_column("Command", style=ALPRINA_RED, no_wrap=True) 

133 help_table.add_column("Description", style="white") 

134 

135 commands = [ 

136 ("/help", "Show this help message"), 

137 ("/scan <target>", "Run security scan on target"), 

138 ("/explain [id]", "Explain finding (or list all)"), 

139 ("/fix <id>", "Get fix for specific finding"), 

140 ("/report", "Show current scan summary"), 

141 ("/clear", "Clear conversation history"), 

142 ("/stats", "Show conversation statistics"), 

143 ("/save", "Save conversation to file"), 

144 ("exit", "Exit chat session"), 

145 ] 

146 

147 for cmd, desc in commands: 

148 help_table.add_row(cmd, desc) 

149 

150 console.print() 

151 console.print(help_table) 

152 console.print() 

153 

154 

155def create_stats_table(stats: dict): 

156 """Create beautiful stats table.""" 

157 stats_table = Table( 

158 title=f"[bold {ALPRINA_RED}]Session Statistics[/bold {ALPRINA_RED}]", 

159 show_header=False, 

160 border_style=ALPRINA_RED, 

161 box=ROUNDED, 

162 padding=(0, 1) 

163 ) 

164 stats_table.add_column("Metric", style="white") 

165 stats_table.add_column("Value", style=f"bold {ALPRINA_RED}", justify="right") 

166 

167 stats_table.add_row("Messages", str(stats.get('total_messages', 0))) 

168 stats_table.add_row(" └─ User", str(stats.get('user_messages', 0))) 

169 stats_table.add_row(" └─ Assistant", str(stats.get('assistant_messages', 0))) 

170 stats_table.add_row("Findings", str(stats.get('total_findings', 0))) 

171 stats_table.add_row(" └─ HIGH", str(stats.get('high_severity', 0))) 

172 stats_table.add_row(" └─ MEDIUM", str(stats.get('medium_severity', 0))) 

173 stats_table.add_row(" └─ LOW", str(stats.get('low_severity', 0))) 

174 stats_table.add_row("Duration", f"{stats.get('session_duration', 0):.0f}s") 

175 

176 console.print() 

177 console.print(stats_table) 

178 console.print() 

179 

180 

181def display_goodbye(stats: dict): 

182 """Display beautiful goodbye message.""" 

183 console.print() 

184 console.print(Panel( 

185 f"[bold {ALPRINA_RED}]Thanks for using Alprina![/bold {ALPRINA_RED}]\n\n" 

186 f"[white]Session Statistics:[/white]\n" 

187 f"{stats.get('total_messages', 0)} messages\n" 

188 f"{stats.get('session_duration', 0):.0f}s duration\n\n" 

189 f"[dim]💾 Use /save before exit to save your conversation[/dim]", 

190 border_style=ALPRINA_RED, 

191 box=ROUNDED, 

192 padding=(1, 2) 

193 )) 

194 console.print()