Rund 2.600 Kommentarblöcke in 310 C#-Dateien übersetzt, Begründungen vollständig erhalten: blockweise gleiche Anzahl wie vorher, kein Block unter 60 % seiner Länge, der Code außerhalb der Kommentare per Tokenizer byte-identisch geprüft. Zitate deutscher Oberflächentexte und Testdaten bleiben deutsch. WebUI: Kommentare in JS/CSS/HTML übersetzt, JSDoc-@param an die in 4b umbenannten Parameter angeglichen. Dabei behoben: - 4b hatte "tag" (HTML-Tag) als deutsches "Tag" gelesen und zu "dayValue" gemacht (makeElement, svg, Tagesübersicht) - zurück auf tag/day. - Aufgaben "InProgress" bekamen die Plakettenart "laufend", für die es nie eine CSS-Klasse gab - jetzt "success" wie laufende Instanzen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
40 lines
1.4 KiB
C#
40 lines
1.4 KiB
C#
using ClawdDotNet.Core.Config;
|
|
|
|
namespace ClawdDotNet.Core.Engine;
|
|
|
|
public sealed class LoopGuard
|
|
{
|
|
private readonly LoopGuardConfig _cfg;
|
|
private int _steps;
|
|
private int _tokens;
|
|
|
|
public LoopGuard(LoopGuardConfig cfg) => _cfg = cfg;
|
|
|
|
public int Steps => _steps;
|
|
public int Tokens => _tokens;
|
|
|
|
public void RecordStep()
|
|
{
|
|
if (Interlocked.Increment(ref _steps) > _cfg.MaxSteps)
|
|
throw new LoopLimitExceededException(
|
|
$"Schritt-Limit erreicht: {_cfg.MaxSteps} Schritte pro Run.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Books the billed tokens of a step onto the run's cost budget.
|
|
/// This is purely a cost brake — the context size is controlled separately via
|
|
/// <see cref="LoopGuardConfig.MaxContextTokens"/> and compaction.
|
|
/// </summary>
|
|
public void RecordTokens(int count)
|
|
{
|
|
var total = Interlocked.Add(ref _tokens, count);
|
|
if (total > _cfg.MaxCumulativeTokens)
|
|
throw new LoopLimitExceededException(
|
|
$"Kostenbudget erschöpft: {total:N0} von maximal {_cfg.MaxCumulativeTokens:N0} " +
|
|
"abgerechneten Tokens in diesem Run. Hinweis: Jeder Schritt sendet den " +
|
|
"kompletten Kontext erneut, die Summe wächst daher überproportional.");
|
|
}
|
|
}
|
|
|
|
public sealed class LoopLimitExceededException(string message) : Exception(message);
|