const std = @import("std"); /// Returns the human-readable body from established tool result envelopes. /// Malformed or unfamiliar output stays literal so presentation never hides /// tool evidence it cannot identify safely. pub fn contentForDisplay(body: []const u8) []const u8 { var rest = body; if (std.mem.startsWith(u8, rest, "")) { const path_close = std.mem.find(u8, rest, "") orelse return body; rest = std.mem.trimStart(u8, rest[path_close + "".len ..], "\r\n"); } if (!std.mem.startsWith(u8, rest, "")) return body; rest = std.mem.trimStart(u8, rest["".len..], "\r\n"); if (!std.mem.endsWith(u8, rest, "")) return body; return std.mem.trimEnd(u8, rest[0 .. rest.len - "".len], "\r\n"); } test "contentForDisplay unwraps path and content result" { try std.testing.expectEqualStrings( "1\talpha\n2\tbeta", contentForDisplay("README.md\n\n1\talpha\n2\tbeta\n"), ); } test "contentForDisplay preserves unknown or malformed output" { const raw = "README.md\nmissing close"; try std.testing.expectEqualStrings(raw, contentForDisplay(raw)); try std.testing.expectEqualStrings("plain output", contentForDisplay("plain output")); }