From e7ff151c045c277b60d574be9548518450695a99 Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Sun, 12 Oct 2025 15:30:53 +0000 Subject: [PATCH] Disable ANSI colors and browser prefix in AI agent mode This ensures that grep '^error:' works reliably in all scenarios: - ANSI escape codes are disabled to prevent them from appearing before 'error:' - The 'frontend' prefix is suppressed so browser errors also start with 'error:' These changes guarantee that the error prefix is always at column 0 for easy grepping by AI agents. --- src/bun.js/VirtualMachine.zig | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/bun.js/VirtualMachine.zig b/src/bun.js/VirtualMachine.zig index 1124a737f2..da7b121b4f 100644 --- a/src/bun.js/VirtualMachine.zig +++ b/src/bun.js/VirtualMachine.zig @@ -1958,7 +1958,8 @@ pub fn printException( .stack_check = bun.StackCheck.init(), }; defer formatter.deinit(); - if (Output.enable_ansi_colors) { + // Disable ANSI colors in AI agent mode to ensure grep '^error:' works reliably + if (Output.enable_ansi_colors and !Output.isAIAgent()) { this.printErrorlikeObject(exception.value(), exception, exception_list, &formatter, Writer, writer, true, allow_side_effects); } else { this.printErrorlikeObject(exception.value(), exception, exception_list, &formatter, Writer, writer, false, allow_side_effects); @@ -1997,7 +1998,8 @@ pub noinline fn runErrorHandler(this: *VirtualMachine, result: JSValue, exceptio .error_display_level = .full, }; defer formatter.deinit(); - switch (Output.enable_ansi_colors) { + // Disable ANSI colors in AI agent mode to ensure grep '^error:' works reliably + switch (Output.enable_ansi_colors and !Output.isAIAgent()) { inline else => |enable_colors| this.printErrorlikeObject(result, null, exception_list, &formatter, @TypeOf(writer), writer, enable_colors, true), } } @@ -3306,7 +3308,7 @@ fn printErrorNameAndMessage( comptime allow_ansi_color: bool, error_display_level: ConsoleObject.FormatOptions.ErrorDisplayLevel, ) !void { - if (is_browser_error) { + if (is_browser_error and !Output.isAIAgent()) { try writer.writeAll(Output.prettyFmt("frontend ", true)); } if (!name.isEmpty() and !message.isEmpty()) {