# ai_client.py import tomllib import json import datetime from pathlib import Path import file_cache import mcp_client _provider: str = "gemini" _model: str = "gemini-2.0-flash" _gemini_client = None _gemini_chat = None _anthropic_client = None _anthropic_history: list[dict] = [] # Injected by gui.py - called when AI wants to run a command. # Signature: (script: str, base_dir: str) -> str | None confirm_and_run_callback = None # Injected by gui.py - called whenever a comms entry is appended. # Signature: (entry: dict) -> None comms_log_callback = None # Injected by gui.py - called whenever a tool call completes. # Signature: (script: str, result: str) -> None tool_log_callback = None MAX_TOOL_ROUNDS = 5 # Maximum characters per text chunk sent to Anthropic. # Kept well under the ~200k token API limit. _ANTHROPIC_CHUNK_SIZE = 180_000 _ANTHROPIC_SYSTEM = ( "You are a helpful coding assistant with access to a PowerShell tool and MCP file tools (read_file, list_directory, search_files, get_file_summary). " "When asked to create or edit files, prefer targeted edits over full rewrites. " "Always explain what you are doing before invoking the tool.\n\n" "When writing or rewriting large files (especially those containing quotes, backticks, or special characters), " "avoid python -c with inline strings. Instead: (1) write a .py helper script to disk using a PS here-string " "(@'...'@ for literal content), (2) run it with `python