Bugtracker-Durchgang: 13 Bugs behoben, Build ohne Warnungen
Alle Behebungen auf der Linux-Test-VM gegengeprueft (Ubuntu, .NET 10.0.111): Build 0 Warnungen / 0 Fehler, 637 Tests gruen, 1 uebersprungen (WindowsFact). Sicherheit und Zielplattform #373 PathBoundary.Canonicalize fiel offen aus. File.ResolveLinkTarget wirft fuer einen fehlenden Abschnitt FileNotFoundException; der catch(IOException) verliess daraufhin die GANZE Aufloesung mit dem unaufgeloesten Pfad - und der besteht jede Praefixpruefung. Der Symlink-Schutz war damit bei jedem Schreibvorgang wirkungslos. Jetzt ueber FileSystemInfo.LinkTarget, und TryCanonicalize meldet "nicht bestimmbar", statt fail-open durchzureichen. #374 WorkspacePath weist den Backslash rundheraus ab, wie den Doppelpunkt. Eine Schreibweise statt einer Sonderregel je Windows-Form. #375 Log-Verzeichnis: leer heisst "Anwendungseinstellung"; ein relativer Wert zaehlt gegen das Instanzverzeichnis, nicht gegen das Arbeitsverzeichnis des Prozesses. Ein systemd-Dienst landet nicht mehr auf /Logs. Agentenkommunikation #206 Delegationskette gegen A->B->A (Test A13). Zyklusfrei per Bauart, dazu MaxDelegationDepth gegen die Staffel, die niemand beauftragt hat. #461 Zwei unabhaengige Ketten ueber Kreuz - beim Beheben von #206 gefunden und reproduziert. Ein delegierter Lauf wartet nur noch begrenzt auf ein fremdes Gate; ein Chat vom Menschen reiht sich weiter unbegrenzt ein. #234 Instanz-Id wird durchgereicht statt aus einem nur beilaeufig gesetzten Feld gelesen. Betrieb und Oberflaeche #376 Log-Ansicht chronologisch statt gruppiert je Moduldatei, mit Stacktraces an ihrer Meldung - auch ueber Taktgrenzen hinweg. #377 Info-Tabelle: feste Spaltenbreiten, damit ein langer Aenderungstext den anderen Spalten nicht den Platz nimmt. #378 Sicherung: Mindestabstand zwischen Ueberschrift und Schaltflaechenleiste. #379 Hellmodus: drei von vier gedaempften Textpinseln lagen unter 4,5:1. Die helle Palette ist als Ganzes verschoben, damit die Staffelung sichtbar bleibt statt auf einen Wert zusammenzufallen. Hygiene #233 stock_add: der Indexstand wird innerhalb der Sperre festgehalten. #235 Zeitumstellung: eine nicht existierende Ortszeit wird auf den ersten Zeitpunkt nach der Luecke verschoben statt uebersprungen (R4, R5). #236 45 Nullable-Warnungen und eine CA1416 - nicht unterdrueckt, sondern die Stellen so umgebaut, dass die Zusage nachvollziehbar wird. Mail meldet jetzt, WELCHER Zugangsschluessel fehlt, statt an einer KeyNotFoundException zu scheitern. #203 Kompaktiert wird vor dem API-Aufruf statt danach; die gemessenen Prompt-Groessen kalibrieren die Schaetzung je Modell. Neu: tests/ClawdDotNet.App.Tests - fuer #375 und #376 gab es keinen Ort fuer Tests. Dazu Regressionstests fuer jede Behebung; jeder wurde gegen den alten Stand geprueft, damit belegt ist, dass er den Fehler faengt. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -80,8 +80,8 @@ public sealed class MailTool : IAgentTool, IToolJobProvider
|
||||
private async Task<ToolResult> HandleSendAsync(JsonElement input, AgentToolContext context, CancellationToken ct)
|
||||
{
|
||||
var to = input.TryGetProperty("to", out var t) ? t.GetString() : null;
|
||||
var subject = input.TryGetProperty("subject", out var s) ? s.GetString() : "(Kein Betreff)";
|
||||
var body = input.TryGetProperty("body", out var b) ? b.GetString() : "";
|
||||
var subject = (input.TryGetProperty("subject", out var s) ? s.GetString() : null) ?? "(Kein Betreff)";
|
||||
var body = (input.TryGetProperty("body", out var b) ? b.GetString() : null) ?? "";
|
||||
|
||||
if (string.IsNullOrWhiteSpace(to)) return ToolResult.Fail("'to' ist erforderlich.");
|
||||
|
||||
@@ -91,16 +91,18 @@ public sealed class MailTool : IAgentTool, IToolJobProvider
|
||||
return ToolResult.Fail($"Sicherheitsfehler: Senden an '{to}' ist nicht erlaubt.");
|
||||
}
|
||||
|
||||
var config = context.ToolConfig;
|
||||
if (!TryReadAccess(context, "smtpHost", "smtpPort", 587, out var access, out var fehlt))
|
||||
return ToolResult.Fail(fehlt);
|
||||
|
||||
var message = new MimeMessage();
|
||||
message.From.Add(new MailboxAddress("ClawdDotNet", config["username"]?.ToString()));
|
||||
message.From.Add(new MailboxAddress("ClawdDotNet", access.UserName));
|
||||
message.To.Add(MailboxAddress.Parse(to));
|
||||
message.Subject = subject;
|
||||
message.Body = new TextPart("plain") { Text = body };
|
||||
|
||||
using var client = new SmtpClient();
|
||||
await client.ConnectAsync(config["smtpHost"]?.ToString(), (config["smtpPort"] is JsonElement sp ? sp.GetInt32() : 587), true, ct);
|
||||
await client.AuthenticateAsync(config["username"]?.ToString(), config["password"]?.ToString(), ct);
|
||||
await client.ConnectAsync(access.Host, access.Port, true, ct);
|
||||
await client.AuthenticateAsync(access.UserName, access.Password, ct);
|
||||
await client.SendAsync(message, ct);
|
||||
await client.DisconnectAsync(true, ct);
|
||||
|
||||
@@ -110,11 +112,13 @@ public sealed class MailTool : IAgentTool, IToolJobProvider
|
||||
private async Task<ToolResult> HandleReadInboxAsync(JsonElement input, AgentToolContext context, CancellationToken ct)
|
||||
{
|
||||
var limit = input.TryGetProperty("limit", out var l) ? l.GetInt32() : 10;
|
||||
var config = context.ToolConfig;
|
||||
|
||||
if (!TryReadAccess(context, "imapHost", "imapPort", 993, out var access, out var fehlt))
|
||||
return ToolResult.Fail(fehlt);
|
||||
|
||||
using var client = new ImapClient();
|
||||
await client.ConnectAsync(config["imapHost"]?.ToString(), (config["imapPort"] is JsonElement ip ? ip.GetInt32() : 993), true, ct);
|
||||
await client.AuthenticateAsync(config["username"]?.ToString(), config["password"]?.ToString(), ct);
|
||||
await client.ConnectAsync(access.Host, access.Port, true, ct);
|
||||
await client.AuthenticateAsync(access.UserName, access.Password, ct);
|
||||
|
||||
await client.Inbox!.OpenAsync(FolderAccess.ReadOnly, ct);
|
||||
var messages = new List<object>();
|
||||
@@ -142,10 +146,12 @@ public sealed class MailTool : IAgentTool, IToolJobProvider
|
||||
return ToolResult.Fail("'messageId' (Index) ist erforderlich.");
|
||||
}
|
||||
|
||||
var config = context.ToolConfig;
|
||||
if (!TryReadAccess(context, "imapHost", "imapPort", 993, out var access, out var fehlt))
|
||||
return ToolResult.Fail(fehlt);
|
||||
|
||||
using var client = new ImapClient();
|
||||
await client.ConnectAsync(config["imapHost"]?.ToString(), (config["imapPort"] is JsonElement ip ? ip.GetInt32() : 993), true, ct);
|
||||
await client.AuthenticateAsync(config["username"]?.ToString(), config["password"]?.ToString(), ct);
|
||||
await client.ConnectAsync(access.Host, access.Port, true, ct);
|
||||
await client.AuthenticateAsync(access.UserName, access.Password, ct);
|
||||
|
||||
await client.Inbox!.OpenAsync(FolderAccess.ReadOnly, ct);
|
||||
var msg = await client.Inbox!.GetMessageAsync(index, ct);
|
||||
@@ -170,10 +176,12 @@ public sealed class MailTool : IAgentTool, IToolJobProvider
|
||||
return ToolResult.Fail("'messageId' (Index) ist erforderlich.");
|
||||
}
|
||||
|
||||
var config = context.ToolConfig;
|
||||
if (!TryReadAccess(context, "imapHost", "imapPort", 993, out var access, out var fehlt))
|
||||
return ToolResult.Fail(fehlt);
|
||||
|
||||
using var client = new ImapClient();
|
||||
await client.ConnectAsync(config["imapHost"]?.ToString(), (config["imapPort"] is JsonElement ip ? ip.GetInt32() : 993), true, ct);
|
||||
await client.AuthenticateAsync(config["username"]?.ToString(), config["password"]?.ToString(), ct);
|
||||
await client.ConnectAsync(access.Host, access.Port, true, ct);
|
||||
await client.AuthenticateAsync(access.UserName, access.Password, ct);
|
||||
|
||||
await client.Inbox!.OpenAsync(FolderAccess.ReadWrite, ct);
|
||||
await client.Inbox!.AddFlagsAsync(index, MessageFlags.Seen, true, ct);
|
||||
@@ -182,6 +190,60 @@ public sealed class MailTool : IAgentTool, IToolJobProvider
|
||||
return ToolResult.Ok($"Nachricht {index} als gelesen markiert.");
|
||||
}
|
||||
|
||||
/// <summary>Ein Zugang: Server, Port und Anmeldedaten — vollständig oder gar nicht.</summary>
|
||||
private readonly record struct MailAccess(string Host, int Port, string UserName, string Password);
|
||||
|
||||
/// <summary>
|
||||
/// Liest Server und Anmeldedaten aus der Werkzeug-Konfiguration.
|
||||
///
|
||||
/// <para>Vorher standen die Werte an vier Stellen einzeln im Aufruf:
|
||||
/// <c>config["smtpHost"]?.ToString()</c>. Das ging auf zwei Arten schief. Fehlte der
|
||||
/// Schlüssel ganz, warf der Indexer eine <c>KeyNotFoundException</c>; war er leer,
|
||||
/// ging <c>null</c> an MailKit — worauf der Compiler mit fünfzehn
|
||||
/// Nullable-Warnungen hinwies. Beim Agenten kam beides als dieselbe unbrauchbare
|
||||
/// Zeile an: „Fehler: …".</para>
|
||||
///
|
||||
/// <para>Hier fällt stattdessen die Antwort aus, die weiterhilft: welcher Schlüssel
|
||||
/// fehlt. Der Port bleibt weich — dafür gibt es sinnvolle Vorgaben; Server und
|
||||
/// Anmeldedaten kann niemand raten.</para>
|
||||
/// </summary>
|
||||
private static bool TryReadAccess(
|
||||
AgentToolContext context, string hostKey, string portKey, int defaultPort,
|
||||
out MailAccess access, out string error)
|
||||
{
|
||||
access = default;
|
||||
|
||||
var host = ReadSetting(context, hostKey);
|
||||
var user = ReadSetting(context, "username");
|
||||
var password = ReadSetting(context, "password");
|
||||
|
||||
var missing = new List<string>();
|
||||
if (string.IsNullOrWhiteSpace(host)) missing.Add(hostKey);
|
||||
if (string.IsNullOrWhiteSpace(user)) missing.Add("username");
|
||||
if (string.IsNullOrWhiteSpace(password)) missing.Add("password");
|
||||
|
||||
if (missing.Count > 0)
|
||||
{
|
||||
error = "Das Mail-Werkzeug ist nicht vollständig eingerichtet. " +
|
||||
$"Es fehlt in der Werkzeug-Konfiguration: {string.Join(", ", missing)}.";
|
||||
return false;
|
||||
}
|
||||
|
||||
access = new MailAccess(host!, ReadPort(context, portKey, defaultPort), user!, password!);
|
||||
error = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
private static string? ReadSetting(AgentToolContext context, string key)
|
||||
=> context.ToolConfig.TryGetValue(key, out var value) ? value?.ToString() : null;
|
||||
|
||||
private static int ReadPort(AgentToolContext context, string key, int fallback)
|
||||
=> context.ToolConfig.TryGetValue(key, out var value)
|
||||
&& value is JsonElement { ValueKind: JsonValueKind.Number } je
|
||||
&& je.TryGetInt32(out var port)
|
||||
? port
|
||||
: fallback;
|
||||
|
||||
private bool IsRecipientAllowed(string email, AgentToolContext context)
|
||||
{
|
||||
if (!context.ToolConfig.TryGetValue("allowedRecipients", out var val) || val is not JsonElement je)
|
||||
|
||||
Reference in New Issue
Block a user