Lightpanda: the headless browser designed for AI and automation
mcp, agent: load external stylesheets by default
Adrià Arrufatd29308337c11
diff --git a/src/Config.zig b/src/Config.zigindex 966100946..f8e173ff2 100644--- a/src/Config.zig+++ b/src/Config.zig@@ -231,11 +231,14 @@ pub const HttpVersion = enum {@"1.1",};-pub const LoadResources = packed struct(u4) {+pub const LoadResources = packed struct(u5) {image: bool = false,iframe: bool = false,worker: bool = false,stylesheet: bool = false,+ // Only marks the option as given, so `--load-resources none` turns off a+ // mode's default.+ none: bool = false,};pub const ExperimentalFeatures = packed struct(u2) {@@ -532,6 +535,15 @@ pub fn init(allocator: Allocator, exec_name: []const u8, mode: Mode) !Config {m.load_resources.stylesheet = true;}}+ // The agent-facing modes read visibility, which is wrong without+ // external stylesheets: a menu hidden by an author class looks+ // open. An explicit --load-resources replaces this default.+ if (@hasField(@TypeOf(m.*), "load_resources")) {+ const given = m.load_resources != LoadResources{};+ if (!given and (config.command == .mcp or config.command == .agent)) {+ m.load_resources.stylesheet = true;+ }+ }},}@@ -1773,3 +1785,22 @@ pub fn tagJsonArray(comptime E: type) []const u8 {}return s ++ "]";}++test "Config: parseArgs --load-resources defaults stylesheets on for mcp and agent" {+ var arena = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer arena.deinit();++ const cases = [_]struct { argv: []const [*:0]const u8, stylesheet: bool, image: bool }{+ .{ .argv = &.{ "lightpanda", "mcp" }, .stylesheet = true, .image = false },+ .{ .argv = &.{ "lightpanda", "agent", "--no-llm" }, .stylesheet = true, .image = false },+ .{ .argv = &.{ "lightpanda", "fetch", "https://example.com" }, .stylesheet = false, .image = false },+ .{ .argv = &.{ "lightpanda", "mcp", "--load-resources", "none" }, .stylesheet = false, .image = false },+ .{ .argv = &.{ "lightpanda", "mcp", "--load-resources", "image" }, .stylesheet = false, .image = true },+ };+ for (cases) |case| {+ const config = try parseArgs(arena.allocator(), .{ .vector = case.argv });+ const resources = config.loadResources();+ try std.testing.expectEqual(case.stylesheet, resources.stylesheet);+ try std.testing.expectEqual(case.image, resources.image);+ }+}diff --git a/src/help.zon b/src/help.zonindex 2a71f4026..31b8c8993 100644--- a/src/help.zon+++ b/src/help.zon@@ -433,7 +433,8 @@\\ Defaults to none enabled.\\ --load-resources <RESOURCE>\\ Sub-resource to actually request. Can be passed multiple times.- \\ Defaults to requesting none of them.+ \\ Defaults to stylesheet for mcp and agent, and to none of them+ \\ otherwise. Passing it replaces the default.\\ Allowed values:\\ iframe When enabled, <iframe> elements are fully loaded.\\@@ -451,6 +452,8 @@\\ disabled, the Worker constructor still returns a\\ Worker, but no script fetch is initiated and the\\ Worker never runs.+ \\+ \\ none Request none of them, overriding the default.\\ --http-cache-dir <PATH>\\ Directory used as a filesystem cache for network resources. Omitting\\ this disables caching.