feat: Python-Befehl auto-detect (python3/python/py) mit Warnung bei fehlendem Python

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
MelekiandClaude Opus 4.6 committed 2026-04-07 07:13:19 +02:00
1 parent f180dbc842
commit 1035066a39
2 files changed
+55 -1

No files matched your search

+54 -1
View File
@@ -14,6 +14,9 @@ namespace Gott.Services;
public partial class AnthropicService
{
private static string _cachedPythonCmd;
private static bool _pythonCmdChecked;
/// <summary>
/// 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();
}
/// <summary>
/// Sucht einen verfügbaren Python-Befehl (python3, python, py).
/// Gibt null zurück, wenn keiner gefunden wird.
/// </summary>
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;
}
/// <summary>
/// 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<string, object>
{
["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))
+1
View File
@@ -131,6 +131,7 @@ function handleStreamEvent(eventType, data) {
addAutoContextBubble(data.context);
break;
case 'warning':
case 'info':
addWarningBubble(data.message, true);
break;