feat: aggiungi fallback CLI semplice per terminali incompatibili
- Aggiunto flag --simple per usare input() invece di prompt_toolkit - EnhancedCLI ora ha try/except con fallback automatico - CLI semplice supporta comandi base: /help, /status, /exit
This commit is contained in:
1 parent
3a042355b8
commit
82b70f88d1
1 file changed
+62
-8
+62
-8
@@ -30,10 +30,9 @@ VERSION = "1.0.0"
|
||||
|
||||
|
||||
def cmd_chat(args):
|
||||
"""Avvia l'agent in modalità chat interattiva con EnhancedCLI"""
|
||||
"""Avvia l'agent in modalità chat interattiva"""
|
||||
from main import create_langcode_agent, process_command
|
||||
from langchain_core.messages import HumanMessage
|
||||
from enhanced_cli import create_enhanced_cli
|
||||
|
||||
print("🚀 Inizializzo LangCode Agent...")
|
||||
|
||||
@@ -73,12 +72,66 @@ def cmd_chat(args):
|
||||
except Exception as e:
|
||||
return f"Errore: {str(e)}"
|
||||
|
||||
# Usa EnhancedCLI con history e autocomplete
|
||||
cli = create_enhanced_cli(
|
||||
history_file="./.langcode/.cli_history",
|
||||
theme="default"
|
||||
)
|
||||
cli.run(agent_callback)
|
||||
# Prova EnhancedCLI, altrimenti usa CLI semplice
|
||||
use_enhanced = not args.simple
|
||||
|
||||
if use_enhanced:
|
||||
try:
|
||||
from enhanced_cli import create_enhanced_cli
|
||||
cli = create_enhanced_cli(
|
||||
history_file="./.langcode/.cli_history",
|
||||
theme="default"
|
||||
)
|
||||
cli.run(agent_callback)
|
||||
return
|
||||
except Exception as e:
|
||||
print(f"⚠️ EnhancedCLI non disponibile: {e}")
|
||||
print("📝 Uso CLI semplice...")
|
||||
|
||||
# CLI semplice con input()
|
||||
print("\n" + "=" * 60)
|
||||
print(" CLI SEMPLICE - digita /exit per uscire")
|
||||
print("=" * 60 + "\n")
|
||||
|
||||
while True:
|
||||
try:
|
||||
user_input = input("❯ ").strip()
|
||||
|
||||
if not user_input:
|
||||
continue
|
||||
|
||||
if user_input.lower() in ["/exit", "/quit"]:
|
||||
print("👋 Arrivederci!")
|
||||
break
|
||||
|
||||
if user_input.startswith("/"):
|
||||
if user_input == "/help":
|
||||
print("""
|
||||
Comandi disponibili:
|
||||
/help - Mostra questo messaggio
|
||||
/status - Mostra stato del sistema
|
||||
/exit - Esci
|
||||
""")
|
||||
continue
|
||||
elif user_input == "/status":
|
||||
print("Agent: in esecuzione")
|
||||
continue
|
||||
else:
|
||||
print(f"Comando sconosciuto: {user_input}")
|
||||
continue
|
||||
|
||||
# Mostra input utente
|
||||
print(f"👤 {user_input}\n")
|
||||
|
||||
# Chiamata all'agent
|
||||
response = agent_callback(user_input)
|
||||
print(f"🤖 {response}\n")
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\n👋 Arrivederci!")
|
||||
break
|
||||
except EOFError:
|
||||
break
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Inizializzazione fallita: {str(e)}")
|
||||
@@ -455,6 +508,7 @@ Esempi:
|
||||
|
||||
# === CHAT (default) ===
|
||||
chat_parser = subparsers.add_parser("chat", help="Avvia l'agent in modalità chat")
|
||||
chat_parser.add_argument("--simple", "-s", action="store_true", help="Usa CLI semplice invece di EnhancedCLI")
|
||||
chat_parser.set_defaults(func=cmd_chat)
|
||||
|
||||
# === SERVER ===
|
||||
|
||||
Reference in new issue
Block a user