From 1035066a39e0958991694fafb7c212ebce2c9408 Mon Sep 17 00:00:00 2001 From: Meleki Date: Tue, 7 Apr 2026 07:13:19 +0200 Subject: [PATCH] feat: Python-Befehl auto-detect (python3/python/py) mit Warnung bei fehlendem Python Co-Authored-By: Claude Opus 4.6 --- Services/AnthropicService.Cli.cs | 55 +++++++++++++++++++++++++++++++- wwwroot/js/chat.js | 1 + 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/Services/AnthropicService.Cli.cs b/Services/AnthropicService.Cli.cs index eaa4f7e..281a3c3 100644 --- a/Services/AnthropicService.Cli.cs +++ b/Services/AnthropicService.Cli.cs @@ -14,6 +14,9 @@ namespace Gott.Services; public partial class AnthropicService { + private static string _cachedPythonCmd; + private static bool _pythonCmdChecked; + /// /// Streaming-Chat über die Claude CLI. /// Die CLI verwendet das lokale Token aus ~/.claude/.credentials.json. @@ -64,6 +67,10 @@ public partial class AnthropicService var hasRemote = remoteMgr != null && !string.IsNullOrEmpty(sessionId) && remoteMgr.GetBySessionId(sessionId) != null; mcpConfigPath = GenerateMcpConfig(sessionId, agentId, hasRemote, unityMcpUrl, unityMcpToken); + // Python-Verfügbarkeit prüfen und ggf. warnen + if (FindPythonCommand() == null) + await SseHelper.TryWriteSse(response, "warning", new { message = "⚠ Python wurde nicht gefunden (python3/python/py). MCP-Tools (Remote-Execute, Memory, etc.) sind nicht verfügbar." }, sseCt); + // System-Prompt als Text extrahieren var systemText = new StringBuilder(); if (systemPrompt != null) @@ -515,6 +522,47 @@ public partial class AnthropicService return sb.ToString().Trim(); } + /// + /// Sucht einen verfügbaren Python-Befehl (python3, python, py). + /// Gibt null zurück, wenn keiner gefunden wird. + /// + private static string FindPythonCommand() + { + if (_pythonCmdChecked) return _cachedPythonCmd; + + foreach (var cmd in new[] { "python3", "python", "py" }) + { + try + { + var psi = new System.Diagnostics.ProcessStartInfo + { + FileName = cmd, + Arguments = "--version", + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true + }; + using var proc = System.Diagnostics.Process.Start(psi); + if (proc != null) + { + proc.WaitForExit(3000); + if (proc.ExitCode == 0) + { + _cachedPythonCmd = cmd; + _pythonCmdChecked = true; + Console.WriteLine($"[MCP] Python gefunden: {cmd}"); + return cmd; + } + } + } + catch { /* Command not found – try next */ } + } + _pythonCmdChecked = true; + _cachedPythonCmd = null; + return null; + } + /// /// Generiert eine temporäre MCP-Config-Datei für die Claude CLI. /// Enthält den MCP-Server für remote_execute. @@ -542,16 +590,21 @@ public partial class AnthropicService ["GOTT_HAS_REMOTE"] = hasRemote ? "true" : "false" }; + var pythonCmd = FindPythonCommand(); + var mcpServers = new Dictionary { ["gott-remote"] = new { - command = "python3", + command = pythonCmd ?? "python3", args = new[] { scriptPath }, env } }; + if (pythonCmd == null) + Console.WriteLine("[MCP] ⚠ Python nicht gefunden (python3/python/py) – MCP-Tools werden nicht funktionieren!"); + // Unity MCP Server (pro Session konfigurierbar) // Claude CLI erfordert expliziten "type" – "http" für streamableHttp, "sse" für SSE if (!string.IsNullOrEmpty(unityMcpUrl)) diff --git a/wwwroot/js/chat.js b/wwwroot/js/chat.js index 32893d2..2a6de08 100644 --- a/wwwroot/js/chat.js +++ b/wwwroot/js/chat.js @@ -131,6 +131,7 @@ function handleStreamEvent(eventType, data) { addAutoContextBubble(data.context); break; + case 'warning': case 'info': addWarningBubble(data.message, true); break;