Lightpanda: the headless browser designed for AI and automation
agent: --url opens a start page before the first turn
Adrià Arrufat006af21a6d24
diff --git a/src/Config.zig b/src/Config.zigindex 493cb8c1a..3a564142c 100644--- a/src/Config.zig+++ b/src/Config.zig@@ -472,6 +472,7 @@ const Commands = cli.Builder(.{.{ .name = "verbosity", .type = ?AgentVerbosity },.{ .name = "effort", .type = ?Effort },.{ .name = "search_engine", .type = ?SearchEngine },+ .{ .name = "url", .type = ?[:0]const u8 },.{ .name = "list_models", .type = bool },.{ .name = "no_llm", .type = bool },},diff --git a/src/agent/Agent.zig b/src/agent/Agent.zigindex 9f4f0f219..4e7005110 100644--- a/src/agent/Agent.zig+++ b/src/agent/Agent.zig@@ -159,6 +159,9 @@ model: []u8,/// Per-turn reasoning budget for LLM turns. Mutable at runtime via `/effort`.effort: Config.Effort,script_file: ?[]const u8,+/// `--url`: opened before the first turn, in every mode. A `--task` run that+/// starts on its page does not spend a model turn navigating to it.+start_url: ?[:0]const u8,one_shot_task: ?[]const u8,one_shot_save: ?[]const u8,one_shot_attachments: ?[]const []const u8,@@ -333,6 +336,7 @@ pub fn init(allocator: std.mem.Allocator, app: *App, opts: Config.Agent) !*Agent.effort = effort,.stream_enabled = stream_enabled,.script_file = opts.script_file,+ .start_url = opts.url,.one_shot_task = opts.task,.one_shot_save = opts.save,.one_shot_attachments = if (opts.attach.items.len == 0) null else opts.attach.items,@@ -513,6 +517,12 @@ const TurnInput = struct {/// Returns true on success.pub fn run(self: *Agent) bool {+ if (self.start_url) |url| {+ if (self.gotoStart(url, self.one_shot_save != null)) |err| {+ self.terminal.printError("could not open {s}: {s}", .{ url, browser_tools.errorMessage(err) });+ return false;+ }+ }if (self.one_shot_task) |task| {const saving = self.one_shot_save != null;const ok = self.runTurn(.{@@ -540,6 +550,22 @@ pub fn run(self: *Agent) bool {/// `$usage` prefix. Stable key=value format:/// $usage prompt=N completion=N total=N cached=N cache_creation=N/// Fields emit 0 when the provider didn't report them.+/// Goes through the tool layer so a failed start reads like any other tool+/// failure.+fn gotoStart(self: *Agent, url: [:0]const u8, record: bool) ?browser_tools.ToolError {+ var arena: std.heap.ArenaAllocator = .init(self.allocator);+ defer arena.deinit();+ const a = arena.allocator();++ var object: std.json.ObjectMap = .empty;+ object.put(a, "url", .{ .string = url }) catch return browser_tools.ToolError.OutOfMemory;+ const args: std.json.Value = .{ .object = object };+ _ = browser_tools.call(a, self.ts.session, &self.ts.registry, "goto", args, .{}) catch |err| return err;+ // The opening navigation is the first line of any replayable script.+ if (record) self.recordSaveCommand(Command.fromToolCall(.goto, args));+ return null;+}+fn printUsageSummary(self: *Agent) void {const u = self.total_usage;std.debug.print(diff --git a/src/help.zon b/src/help.zonindex d59303992..32667fd1f 100644--- a/src/help.zon+++ b/src/help.zon@@ -309,6 +309,10 @@\\ One-shot mode: run a single user turn, print the final answer\\ to stdout, and exit. Conflicts with the positional script. With\\ --save, the answer is suppressed and a script is written instead.+ \\ --url <URL>+ \\ Open this page before the first turn. With --task it saves the+ \\ model a turn spent navigating; with --save the opening+ \\ navigation is the first line of the script.\\ --verbosity <LEVEL>\\ Stderr chatter level. Default: high when --task captures stderr\\ to a pipe or file; low otherwise. low/medium also raise