Add explanation rules for catches, editable over MCP
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4086fa3da3
commit
2437880013
37 files changed
+1867
-37
No files matched your search
@@ -0,0 +1,54 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Flypaper.Core.Models;
|
||||
using Flypaper.Storage.Entities;
|
||||
|
||||
namespace Flypaper.Storage.Explanations;
|
||||
|
||||
public static partial class ExplanationText
|
||||
{
|
||||
[GeneratedRegex("[0-9a-fA-F]{8,}")]
|
||||
private static partial Regex LongHex();
|
||||
|
||||
[GeneratedRegex("[0-9]+")]
|
||||
private static partial Regex Digits();
|
||||
|
||||
public static string? Path(string? target)
|
||||
{
|
||||
if (target is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var space = target.IndexOf(' ');
|
||||
if (space < 0)
|
||||
{
|
||||
return target;
|
||||
}
|
||||
|
||||
var hostAndPath = target[(space + 1)..];
|
||||
if (hostAndPath.StartsWith('/'))
|
||||
{
|
||||
return hostAndPath;
|
||||
}
|
||||
|
||||
var slash = hostAndPath.IndexOf('/');
|
||||
return slash < 0 ? "/" : hostAndPath[slash..];
|
||||
}
|
||||
|
||||
public static string Outcome(TrapOutcome outcome, long durationMs) =>
|
||||
outcome == TrapOutcome.Rejected ? outcome.ToString() : $"{outcome} {durationMs / 1000}s";
|
||||
|
||||
public static string Value(ExplanationKind kind, TrapEventEntity trapEvent) => kind switch
|
||||
{
|
||||
ExplanationKind.Target => Path(trapEvent.Target) ?? "",
|
||||
ExplanationKind.ClientInfo => trapEvent.ClientInfo ?? "",
|
||||
_ => Outcome(trapEvent.Outcome, trapEvent.DurationMs)
|
||||
};
|
||||
|
||||
public static string PathShape(string path)
|
||||
{
|
||||
var query = path.IndexOf('?');
|
||||
var bare = query < 0 ? path : path[..query];
|
||||
return Digits().Replace(LongHex().Replace(bare, "{hex}"), "{n}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user