22"""Terminal CLI for Meeseeks."""
33
44import argparse
5+ import json
56import os
67import sys
78from collections .abc import Callable , Iterable
89
910from prompt_toolkit import PromptSession
1011from prompt_toolkit .history import FileHistory
12+ from rich import box
1113from rich .columns import Columns
1214from rich .console import Console , Group
1315from rich .markdown import Markdown
1416from rich .panel import Panel
17+ from rich .syntax import Syntax
1518from rich .text import Text
1619
1720
@@ -252,6 +255,7 @@ def _run_query(
252255 task_queue ,
253256 tool_registry ,
254257 highlight_latest = not bool (task_queue .task_result ),
258+ verbose = args .verbose > 0 ,
255259 )
256260 if task_queue .task_result :
257261 console .print (
@@ -353,6 +357,7 @@ def _render_results_with_registry(
353357 task_queue : TaskQueue ,
354358 tool_registry : ToolRegistry ,
355359 highlight_latest : bool = True ,
360+ verbose : bool = False ,
356361) -> None :
357362 specs = _tool_specs_by_id (tool_registry )
358363 panels : list [Panel ] = []
@@ -370,16 +375,21 @@ def _render_results_with_registry(
370375 is_latest = highlight_latest and index == last_index
371376 content_style = None if is_latest else "dim"
372377 border_style = "magenta" if is_latest else "dim magenta"
373- content = Text (
374- str (result ) if result is not None else "(no result)" ,
375- style = content_style ,
376- )
378+ renderable : Text | Syntax
379+ if result is None :
380+ renderable = Text ("(no result)" , style = "dim" )
381+ elif not verbose :
382+ renderable = Text ("(output hidden; use -v/--verbose)" , style = "dim" )
383+ else :
384+ renderable = _format_tool_output (result , content_style )
377385 panels .append (
378386 Panel (
379- content ,
387+ renderable ,
380388 title = label ,
381389 border_style = border_style ,
382- padding = (0 , 1 ),
390+ padding = (0 , 0 ),
391+ box = box .MINIMAL ,
392+ style = None if is_latest else "dim" ,
383393 )
384394 )
385395 if not panels :
@@ -391,6 +401,32 @@ def _render_results_with_registry(
391401 console .print (Columns (panels , expand = True ))
392402
393403
404+ def _format_tool_output (result : object , content_style : str | None ) -> Text | Syntax :
405+ if isinstance (result , dict | list ):
406+ return Syntax (
407+ json .dumps (result , indent = 2 , ensure_ascii = True ),
408+ "json" ,
409+ theme = "ansi_dark" ,
410+ word_wrap = True ,
411+ )
412+ if isinstance (result , str ):
413+ stripped = result .strip ()
414+ if stripped :
415+ try :
416+ parsed = json .loads (stripped )
417+ except json .JSONDecodeError :
418+ parsed = None
419+ if isinstance (parsed , dict | list ):
420+ return Syntax (
421+ json .dumps (parsed , indent = 2 , ensure_ascii = True ),
422+ "json" ,
423+ theme = "ansi_dark" ,
424+ word_wrap = True ,
425+ )
426+ return Text (result , style = content_style )
427+ return Text (str (result ), style = content_style )
428+
429+
394430def _build_cli_hook_manager (
395431 console : Console ,
396432 tool_registry : ToolRegistry ,
0 commit comments