/
sasha.martian
/
DevAgent
Обзор
Документация
Войти
/
sasha.martian
/
DevAgent
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/cli.py
57 строк
2 KB
Galushkin Alexander
Step
06 авг 2026, 13:02
06 авг 2026, 13:02
90d584c
Код
Авторство
О чём код?
"""Interactive CLI loop for DevAgent.""" from __future__ import annotations from src.agent import DEFAULT_THREAD_ID, create_agent, run_agent_turn from src.config import load_settings from src.logger import setup_logging TOOL_NAMES = "read_file, list_directory, run_command" def _confirm_command(command: str) -> bool: print(f"\n⚠ Запрос на выполнение команды:\n {command}") answer = input("Выполнить? [y/N]: ").strip().lower() return answer in {"y", "yes", "д", "да"} def run_cli() -> int: """Start the interactive agent session. Returns process exit code.""" logger = setup_logging() try: settings = load_settings() agent = create_agent(settings, confirm=_confirm_command) except Exception as exc: # noqa: BLE001 logger.exception("Не удалось запустить CLI: %s", exc) print(f"Ошибка запуска: {exc}") return 1 print("🤖 DevAgent на GigaChat запущен!") print(f"Доступные инструменты: {TOOL_NAMES}") print("Введите 'exit' или 'quit' для выхода.\n") while True: try: user_input = input("💬 Вы: ").strip() except (EOFError, KeyboardInterrupt): print("\nВыход.") return 0 if not user_input: continue if user_input.lower() in {"exit", "quit"}: print("До свидания.") return 0 print("🧠 Агент думает...") try: reply = run_agent_turn( agent, user_input, thread_id=DEFAULT_THREAD_ID, on_event=lambda line: print(line), ) print(f"🤖 Агент: {reply}\n") except Exception as exc: # noqa: BLE001 — keep session alive logger.exception("Сбой хода: %s", exc) print(f"Ошибка: {exc}\n")