Lightpanda: the headless browser designed for AI and automation
agent: let REPL tool commands take a prompt
Adrià Arrufatd0c1d3fc2a45
diff --git a/src/agent/Agent.zig b/src/agent/Agent.zigindex 34e4a6973..2c2066776 100644--- a/src/agent/Agent.zig+++ b/src/agent/Agent.zig@@ -193,6 +193,8 @@ synthetic_tool_call_id: u32 = 0,/// and the navigation a read tool's `url` made.save_calls: std.ArrayList(SavedCall) = .empty,capturing_for_save: bool = false,+/// Set while a prompt command (`/click the sign in button`) runs its turn.+prompt_target: ?PromptTarget = null,/// Aggregate Anthropic/OpenAI/Gemini token usage across every model call./// Printed as a structured `$usage ...` line on stderr at the end of `--task`/// (one-shot) mode so wrappers can capture per-task cost.@@ -671,6 +673,10 @@ fn runTurn(self: *Agent, input: TurnInput) bool {elseself.terminal.printInfo("(no response from model)", .{});}+ if (self.prompt_target) |target| {+ // The model only summarizes; the data is what `/extract` would print.+ if (target.result) |r| if (target.tool.producesData()) self.printData(target.tool, r);+ }self.conversation.prune();return true;}@@ -770,6 +776,18 @@ fn runRepl(self: *Agent) void {if (!self.requireLlm(label)) continue :repl;_ = self.runTurn(.{ .prompt = lc.prompt(), .record_comment = line, .capture_for_save = true, .label = label });},+ .prompt => |p| {+ var label_buf: [32]u8 = undefined;+ const label = std.mem.print(&label_buf, "/{s}", .{@tagName(p.tool)}) catch "/?";+ if (self.credential == null) {+ self.terminal.printError("{s}: text without key=value is a prompt and needs an LLM. Pass the fields as key=value (/help {s}), or " ++ llm_setup_hint ++ ".", .{ label, @tagName(p.tool) });+ continue :repl;+ }+ const prompt = promptCommandText(aa, p) catch continue :repl;+ self.prompt_target = .{ .tool = p.tool, .pinned = p.args };+ defer self.prompt_target = null;+ _ = self.runTurn(.{ .prompt = prompt, .record_comment = line, .capture_for_save = true, .label = label });+ },.tool_call => |tc| {self.terminal.beginTool(tc.name(), slash_split.?.rest);const result = self.runCommand(aa, tc);@@ -1173,6 +1191,63 @@ const SavedCall = struct {navigated: bool = false,};+const PromptTarget = struct {+ tool: BrowserTool,+ /// Fields typed beside the prompt; they override whatever the model passes.+ pinned: ?std.json.Value,+ /// The target call's output, in the conversation arena, once one succeeded.+ /// Later tool calls are refused, so the turn records exactly one.+ result: ?[]const u8 = null,+};++// What the model may inspect the page with before its one target call.+const prompt_read_tools = [_]BrowserTool{ .tree, .findElement, .nodeDetails, .interactiveElements, .detectForms, .markdown, .html };++fn isPromptReadTool(tool: BrowserTool) bool {+ return std.mem.findScalar(BrowserTool, &prompt_read_tools, tool) != null;+}++fn promptTools(arena: std.mem.Allocator, target: BrowserTool) ![]const ProviderTool {+ const all = globalTools();+ const out = try arena.alloc(ProviderTool, prompt_read_tools.len + 1);+ for (prompt_read_tools, out[0..prompt_read_tools.len]) |t, *o| o.* = all[@backingInt(t)];+ out[prompt_read_tools.len] = all[@backingInt(target)];+ return out;+}++fn hasUrl(args: ?std.json.Value) bool {+ const a = args orelse return false;+ if (a != .object) return false;+ const url = a.object.get("url") orelse return false;+ return url != .string or url.string.len > 0;+}++/// `args` with every `pinned` field set over it.+fn pinArgs(arena: std.mem.Allocator, args: ?std.json.Value, pinned: ?std.json.Value) error{OutOfMemory}!?std.json.Value {+ const p = pinned orelse return args;+ var obj: std.json.ObjectMap = if (args) |a| (if (a == .object) try a.object.clone(arena) else .empty) else .empty;+ var it = p.object.iterator();+ while (it.next()) |entry| try obj.put(arena, entry.key_ptr.*, entry.value_ptr.*);+ return .{ .object = obj };+}++/// The user turn for a prompt command. Pinned fields are named but their values+/// stay out of the conversation: a `fill` value may be a literal secret.+fn promptCommandText(arena: std.mem.Allocator, p: Command.Prompt) ![]const u8 {+ var aw: std.Io.Writer.Allocating = .init(arena);+ const w = &aw.writer;+ const name = @tagName(p.tool);+ try w.print("Make exactly one successful `{s}` call for this request:\n\n{s}\n\n", .{ name, p.text });+ if (p.args) |args| {+ try w.writeAll("These fields are fixed and filled in for you, so leave them out:");+ var it = args.object.iterator();+ while (it.next()) |entry| try w.print(" `{s}`", .{entry.key_ptr.*});+ try w.writeAll(".\n");+ }+ try w.print("Inspect the current page with the read-only tools if you need to; do not navigate. Once `{s}` succeeds, reply in one short sentence.", .{name});+ return aw.written();+}+fn resolveSavePathAndMode(self: *Agent, arena: std.mem.Allocator, filename: ?[]const u8) ?PathAndMode {if (self.save_path) |saved| {if (filename) |name| {@@ -1823,7 +1898,7 @@ fn processUserMessage(self: *Agent, input: TurnInput) !?[]const u8 {ma,.{ .context = @ptrCast(self), .callFn = handleToolCall },.{- .tools = globalTools(),+ .tools = if (self.prompt_target) |t| try promptTools(ma, t.tool) else globalTools(),.before_request = .{ .context = @ptrCast(self), .callFn = beforeTurnRequest },.after_response = .{ .context = @ptrCast(self), .callFn = afterResponse },.max_turns = 100,@@ -1874,7 +1949,12 @@ fn processUserMessage(self: *Agent, input: TurnInput) !?[]const u8 {if (tool == .extract and idx != i) continue;}const ca = self.conversation.arena.allocator();- const args = browser_tools.normalizeArgs(ca, tool, tc.arguments) catch tc.arguments;+ var call_args = tc.arguments;+ if (self.prompt_target) |t| {+ if (tool != t.tool) continue;+ call_args = try pinArgs(ca, call_args, t.pinned);+ }+ const args = browser_tools.normalizeArgs(ca, tool, call_args) catch call_args;// Fall back to the navigation a read tool performed, so a// markdown/tree-driven turn isn't lost from `/save`.const saved: SavedCall = if (i < self.save_calls.items.len) self.save_calls.items[i] else .{};@@ -2066,13 +2146,31 @@ fn handleToolCall(ctx: *anyopaque, allocator: std.mem.Allocator, tool_name: []co/// The text plus the rendered PNG, for backends that can show the model an image.fn toolOutcome(self: *Agent, allocator: std.mem.Allocator, tool_name: []const u8, arguments: ?std.json.Value, saved: *SavedCall) browser_tools.ToolError!zenai.provider.Client.ToolHandler.Result {- const result = try browser_tools.call(allocator, self.ts.session, &self.ts.registry, tool_name, arguments, .{+ var args = arguments;+ var is_target = false;+ if (self.prompt_target) |t| {+ if (t.result != null) return .{ .content = "Error: the request is already done. Reply without calling more tools.", .is_error = true };+ const tool = std.meta.stringToEnum(BrowserTool, tool_name);+ is_target = if (tool) |tl| tl == t.tool else false;+ if (is_target) {+ args = try pinArgs(allocator, args, t.pinned);+ } else if (tool == null or !isPromptReadTool(tool.?)) {+ return .{ .content = allocator.print("Error: only {s} and the read-only tools are available for this request.", .{@tagName(t.tool)}) catch "Error: tool not available", .is_error = true };+ } else if (hasUrl(args)) {+ return .{ .content = "Error: read the current page; this request must not navigate.", .is_error = true };+ }+ }++ const result = try browser_tools.call(allocator, self.ts.session, &self.ts.registry, tool_name, args, .{.inline_image = true,.record = self.capturing_for_save,.nav_note = true,.source = .llm,});saved.* = .{ .selector = result.selector, .navigated = result.navigated };+ if (is_target and !result.is_error) {+ self.prompt_target.?.result = try self.conversation.arena.allocator().dupe(u8, result.text);+ }const content = capToolOutput(allocator, tool_name, result.text);return .{.content = content,diff --git a/src/script/Recorder.zig b/src/script/Recorder.zigindex 74fe8e5a0..a2eacdef7 100644--- a/src/script/Recorder.zig+++ b/src/script/Recorder.zig@@ -243,7 +243,7 @@ test "record emits multi-line extract as JavaScript" {var recorder: Recorder = .init(std.testing.allocator);defer recorder.deinit();- const cmd_str = "/extract '{\n \"title\": \"span.title\",\n \"desc\": \"p.description\"\n}'";+ const cmd_str = "/extract schema='{\n \"title\": \"span.title\",\n \"desc\": \"p.description\"\n}'";try recorder.record(parseLine(aa, cmd_str));try std.testing.expectEqualStrings(@@ -292,7 +292,7 @@ test "record downgrades goto before waitForSelector to domcontentloaded" {defer recorder.deinit();try recorder.record(parseLine(aa, "/goto https://example.com"));- try recorder.record(parseLine(aa, "/waitForSelector .story"));+ try recorder.record(parseLine(aa, "/waitForSelector selector=.story"));try std.testing.expectEqualStrings("const page = new Page();\nawait page.goto({ url: \"https://example.com\", waitUntil: \"domcontentloaded\" });\npage.waitForSelector(\".story\");\n",@@ -309,7 +309,7 @@ test "record keeps the load wait when goto is followed by extract" {defer recorder.deinit();try recorder.record(parseLine(aa, "/goto https://example.com"));- try recorder.record(parseLine(aa, "/extract '{\"title\": \"h1\"}'"));+ try recorder.record(parseLine(aa, "/extract schema='{\"title\": \"h1\"}'"));try std.testing.expectEqualStrings("const page = new Page();\nawait page.goto(\"https://example.com\");\npage.extract({ title: \"h1\" });\n",@@ -326,7 +326,7 @@ test "record preserves an explicit waitUntil on goto" {defer recorder.deinit();try recorder.record(parseLine(aa, "/goto https://example.com waitUntil=networkidle"));- try recorder.record(parseLine(aa, "/waitForSelector .story"));+ try recorder.record(parseLine(aa, "/waitForSelector selector=.story"));try std.testing.expectEqualStrings("const page = new Page();\nawait page.goto({ url: \"https://example.com\", waitUntil: \"networkidle\" });\npage.waitForSelector(\".story\");\n",diff --git a/src/script/Schema.zig b/src/script/Schema.zigindex 49a53878c..57240e68f 100644--- a/src/script/Schema.zig+++ b/src/script/Schema.zig@@ -117,6 +117,17 @@ pub fn positionalFor(tool: BrowserTool) []const []const u8 {};}+/// Tools whose slash form reads leading text as a prompt: the model locates the+/// element or writes the script/schema, and the call it makes is what gets+/// recorded. Their slash fields are keyword-only, so a prompt can't be+/// mistaken for a selector.+pub fn takesPrompt(tool: BrowserTool) bool {+ return switch (tool) {+ .click, .fill, .hover, .selectOption, .setChecked, .waitForSelector, .extract, .evaluate, .waitForScript => true,+ .goto, .search, .markdown, .html, .screenshot, .links, .tree, .nodeDetails, .interactiveElements, .structuredData, .detectForms, .scroll, .waitForState, .press, .findElement, .consoleLogs, .getUrl, .getCookies, .getEnv => false,+ };+}+pub fn findField(self: Schema, key: []const u8) ?FieldEntry {for (self.fields) |f| {if (std.ascii.eqlIgnoreCase(f.name, key)) return f;@@ -190,6 +201,7 @@ pub fn isBarePositional(self: Schema, args: std.json.ObjectMap) bool {/// `name`). Null when there's no required field and more than one optional/// field, since the target would be ambiguous (click's selector/backendNodeId).pub fn leadingPositionalField(self: Schema) ?[]const u8 {+ if (takesPrompt(self.tool)) return null;if (self.required.len == 1) return self.required[0];if (self.required.len == 0 and self.fields.len == 1) return self.fields[0].name;return null;@@ -211,9 +223,47 @@ pub fn parseValue(self: Schema, arena: std.mem.Allocator, rest: []const u8) Pars/// callers can render a user-facing message like/// "y: expected integer, got 'fast'".pub fn parseValueDiag(self: Schema, arena: std.mem.Allocator, rest_raw: []const u8, diag: ?*Diag) ParseError!?std.json.Value {+ return self.parseArgs(arena, rest_raw, diag, true);+}++/// A slash command's leading prompt and the `key=value` tail pinned beside it.+pub const PromptSplit = struct {+ prompt: []const u8,+ args: ?std.json.Value,+};++/// Splits `rest` for a `takesPrompt` tool. Null when there is no leading text,+/// so the caller parses `rest` as ordinary arguments. Required fields may be+/// missing from `args`: the model supplies them.+pub fn parsePrompt(self: Schema, arena: std.mem.Allocator, rest_raw: []const u8, diag: ?*Diag) ParseError!?PromptSplit {+ std.debug.assert(takesPrompt(self.tool));+ const rest = std.mem.trim(u8, rest_raw, &std.ascii.whitespace);+ if (rest.len == 0 or rest[0] == '{') return null;++ // Split on bare words, not `tokenize`: a prompt is prose, and the+ // apostrophe in "the user's menu" is not an opening quote.+ var tail_start = rest.len;+ var it = std.mem.tokenizeAny(u8, rest, &std.ascii.whitespace);+ while (it.next()) |word| {+ if (looksLikeKv(word)) {+ tail_start = it.index - word.len;+ break;+ }+ }++ const text = std.mem.trimEnd(u8, rest[0..tail_start], &std.ascii.whitespace);+ if (text.len == 0) return null;+ const whole_quoted = (text[0] == '\'' or text[0] == '"') and quotedSpanEnd(text, 0) == text.len;+ return .{+ .prompt = if (whole_quoted) stripQuotes(text) else text,+ .args = try self.parseArgs(arena, rest[tail_start..], diag, false),+ };+}++fn parseArgs(self: Schema, arena: std.mem.Allocator, rest_raw: []const u8, diag: ?*Diag, require: bool) ParseError!?std.json.Value {const rest = std.mem.trim(u8, rest_raw, &std.ascii.whitespace);if (rest.len == 0) {- if (self.required.len > 0) return error.MissingRequired;+ if (require and self.required.len > 0) return error.MissingRequired;return null;}@@ -257,6 +307,9 @@ pub fn parseValueDiag(self: Schema, arena: std.mem.Allocator, rest_raw: []const// selector='#a'` works without `checked=true`.required: for (self.required) |req| {for (list.items) |p| if (std.mem.eql(u8, p.key, req)) continue :required;+ // Beside a prompt, a missing field is the model's to fill: defaulting+ // `checked=true` would pin it and rule out "uncheck the newsletter box".+ if (!require) continue;if (!self.isFieldDefaultTrue(req)) return error.MissingRequired;list.appendAssumeCapacity(.{ .key = req, .value = "true" });}@@ -417,13 +470,15 @@ fn buildOne(arena: std.mem.Allocator, tool: BrowserTool, td: BrowserTool.Definit}}- info.hints = try buildHints(arena, info.required, info.fields);+ info.hints = try buildHints(arena, info.required, info.fields, takesPrompt(tool));std.debug.assert(info.hints.len <= max_hint_slots);return info;}-fn buildHints(arena: std.mem.Allocator, required: []const []const u8, fields: []const FieldEntry) ![]const HintSlot {+/// `keyword_only`: a required field renders as `name=…`, since bare text is a+/// prompt rather than its value.+fn buildHints(arena: std.mem.Allocator, required: []const []const u8, fields: []const FieldEntry, keyword_only: bool) ![]const HintSlot {if (fields.len == 0 and required.len == 0) return &.{};var optional_count: usize = 0;for (fields) |f| {@@ -436,7 +491,7 @@ fn buildHints(arena: std.mem.Allocator, required: []const []const u8, fields: []out[idx] = .{.name = name,.required = true,- .fragment = try arena.print("<{s}>", .{name}),+ .fragment = if (keyword_only) try arena.print("{s}=…", .{name}) else try arena.print("<{s}>", .{name}),};idx += 1;}@@ -813,7 +868,7 @@ test "parseValue: double-quoted script with embedded single-quoted argument" {var arena: std.heap.ArenaAllocator = .init(testing.allocator);defer arena.deinit();const evaluate = Schema.find(Schema.all(), "evaluate").?;- const v = (try evaluate.parseValue(arena.allocator(), "\"setTimeout(() => document.querySelector('a'), 1000)\"")).?;+ const v = (try evaluate.parseValue(arena.allocator(), "script=\"setTimeout(() => document.querySelector('a'), 1000)\"")).?;try testing.expectString("setTimeout(() => document.querySelector('a'), 1000)", v.object.get("script").?.string);}@@ -879,3 +934,36 @@ test "parseValue: rejects non-object JSON payloads" {const v = (try goto.parseValue(arena.allocator(), "\"hello\"")).?;try testing.expectString("hello", v.object.get("url").?.string);}++test "parsePrompt: splits the prompt from the key=value tail" {+ var arena: std.heap.ArenaAllocator = .init(testing.allocator);+ defer arena.deinit();+ const aa = arena.allocator();+ const fill = Schema.find(Schema.all(), "fill").?;++ const p = (try fill.parsePrompt(aa, " the email field value='a b' ", null)).?;+ try testing.expectString("the email field", p.prompt);+ try testing.expectString("a b", p.args.?.object.get("value").?.string);++ // A wholly quoted prompt loses its quotes; one that only starts quoted keeps them.+ try testing.expectString("the email field", (try fill.parsePrompt(aa, "\"the email field\"", null)).?.prompt);+ try testing.expectString("'a' then b", (try fill.parsePrompt(aa, "'a' then b", null)).?.prompt);++ // No leading text, or a JSON payload: ordinary arguments.+ try testing.expect((try fill.parsePrompt(aa, "selector=#e value=x", null)) == null);+ try testing.expect((try fill.parsePrompt(aa, "{\"selector\":\"#e\",\"value\":\"x\"}", null)) == null);+ try testing.expect((try fill.parsePrompt(aa, "", null)) == null);++ try testing.expectError(error.UnknownField, fill.parsePrompt(aa, "the email field valu=x", null));+}++test "takesPrompt: prompt tools have keyword-only hints and no positional" {+ const click = Schema.find(Schema.all(), "click").?;+ try testing.expect(click.leadingPositionalField() == null);+ const extract = Schema.find(Schema.all(), "extract").?;+ try testing.expect(extract.leadingPositionalField() == null);+ try testing.expectString("schema=…", extract.hints[0].fragment);+ const goto = Schema.find(Schema.all(), "goto").?;+ try testing.expectString("url", goto.leadingPositionalField().?);+ try testing.expectString("<url>", goto.hints[0].fragment);+}diff --git a/src/script/command.zig b/src/script/command.zigindex 83acc3dcc..700c0fe74 100644--- a/src/script/command.zig+++ b/src/script/command.zig@@ -16,8 +16,9 @@// You should have received a copy of the GNU Affero General Public License// along with this program. If not, see <https://www.gnu.org/licenses/>.-//! A parsed slash command: a tool slash command, a `#`-comment, or an-//! `LlmCommand` trigger (`/login`, `/logout`, `/acceptCookies`). Multi-line+//! A parsed slash command: a tool slash command, a tool command given a+//! prompt instead of its fields, a `#`-comment, or an `LlmCommand` trigger+//! (`/login`, `/logout`, `/acceptCookies`). Multi-line//! `'''…'''` blocks are assembled by the REPL before parse.const std = @import("std");@@ -64,8 +65,19 @@ const accept_cookies_prompt =pub const Command = union(enum) {tool_call: ToolCall,llm: LlmCommand,+ prompt: Prompt,comment: void,+ /// A `takesPrompt` tool given leading text (`/click the sign in button`):+ /// the model fills in the arguments `args` leaves out, and its call is+ /// what gets recorded.+ pub const Prompt = struct {+ tool: BrowserTool,+ text: []const u8,+ /// Fields typed as `key=value` beside the prompt; the model can't change them.+ args: ?std.json.Value,+ };+/// An LLM-driven command: `@tagName` is the wire-format slash name, and/// each value owns its `prompt()` (sent to the model) and `description()`/// (shown in `/help`) — mirroring how `tool_call` wraps `BrowserTool`.@@ -134,8 +146,7 @@ pub const Command = union(enum) {pub fn isRecorded(self: Command) bool {return switch (self) {- .comment => false,- .llm => false,+ .comment, .llm, .prompt => false,.tool_call => |tc| tc.isRecorded(),};}@@ -168,6 +179,11 @@ pub const Command = union(enum) {}const s = Schema.findByName(split.name) orelse return error.UnknownTool;+ if (Schema.takesPrompt(s.tool)) {+ if (try s.parsePrompt(arena, split.rest, diag)) |p| {+ return .{ .prompt = .{ .tool = s.tool, .text = p.prompt, .args = p.args } };+ }+ }const args = try s.parseValueDiag(arena, split.rest, diag);return .{ .tool_call = .{ .tool = s.tool, .args = args } };}@@ -178,7 +194,7 @@ pub const Command = union(enum) {/// runtime.pub fn formatJs(self: Command, arena: std.mem.Allocator, writer: *std.Io.Writer) (std.Io.Writer.Error || error{OutOfMemory})!void {switch (self) {- .comment, .llm => return,+ .comment, .llm, .prompt => return,.tool_call => |tc| try formatJsToolCall(tc, arena, writer),}}@@ -380,12 +396,41 @@ test "parse: /goto positional" {try testing.expectString("https://example.com", cmd.tool_call.args.?.object.get("url").?.string);}-test "parse: /click rejects positional (zero required fields)" {+test "parse: leading text on a prompt tool is a prompt, key=value stays literal" {var arena: std.heap.ArenaAllocator = .init(testing.allocator);defer arena.deinit();- try testing.expectError(error.PositionalNotAllowed, Command.parse(arena.allocator(), "/click 'Login'"));- const cmd = try Command.parse(arena.allocator(), "/click selector='Login'");- try testing.expectString("Login", cmd.tool_call.args.?.object.get("selector").?.string);+ const aa = arena.allocator();++ const quoted = (try Command.parse(aa, "/click 'Login'")).prompt;+ try testing.expectEqual(BrowserTool.click, quoted.tool);+ try testing.expectString("Login", quoted.text);+ try testing.expect(quoted.args == null);++ // An apostrophe in prose is not an opening quote.+ try testing.expectString("the user's menu", (try Command.parse(aa, "/click the user's menu")).prompt.text);++ const fill = (try Command.parse(aa, "/fill the email field value=$LP_EMAIL")).prompt;+ try testing.expectString("the email field", fill.text);+ try testing.expectString("$LP_EMAIL", fill.args.?.object.get("value").?.string);+ try testing.expect(fill.args.?.object.get("selector") == null);++ // `checked` is left to the model rather than defaulted to true.+ try testing.expect((try Command.parse(aa, "/setChecked uncheck the newsletter box")).prompt.args == null);++ const extract = (try Command.parse(aa, "/extract all products with prices save=products")).prompt;+ try testing.expectString("all products with prices", extract.text);+ try testing.expectString("products", extract.args.?.object.get("save").?.string);++ const literal = try Command.parse(aa, "/click selector='Login'");+ try testing.expectString("Login", literal.tool_call.args.?.object.get("selector").?.string);+}++test "parse: tools without a prompt form keep their positional" {+ var arena: std.heap.ArenaAllocator = .init(testing.allocator);+ defer arena.deinit();+ const aa = arena.allocator();+ try testing.expectString("Enter", (try Command.parse(aa, "/press Enter")).tool_call.args.?.object.get("key").?.string);+ try testing.expectString("networkidle", (try Command.parse(aa, "/waitForState networkidle")).tool_call.args.?.object.get("state").?.string);}test "parse: /getEnv positional binds to optional name" {@@ -399,11 +444,13 @@ test "parse: /getEnv positional binds to optional name" {try testing.expect(list.tool_call.args == null);}-test "parse: /extract rejects positional after key=value" {+test "parse: positional must come before key=value" {var arena: std.heap.ArenaAllocator = .init(testing.allocator);defer arena.deinit();- try testing.expectError(error.PositionalMustComeFirst, Command.parse(arena.allocator(), "/extract save=front '{\"karma\":\"#karma\"}'"));- const cmd = try Command.parse(arena.allocator(), "/extract '{\"karma\":\"#karma\"}' save=front");+ try testing.expectError(error.PositionalMustComeFirst, Command.parse(arena.allocator(), "/goto timeout=5000 https://example.com"));+ // A prompt tool has no positional, so a bare value after key=value is malformed.+ try testing.expectError(error.MalformedKv, Command.parse(arena.allocator(), "/extract save=front '{\"karma\":\"#karma\"}'"));+ const cmd = try Command.parse(arena.allocator(), "/extract schema='{\"karma\":\"#karma\"}' save=front");try testing.expectString("front", cmd.tool_call.args.?.object.get("save").?.string);}@@ -456,28 +503,28 @@ test "formatJs: evaluate and extract strings" {const aa = arena.allocator();{- const cmd = try Command.parse(aa, "/evaluate '''\nconst x = 1;\nreturn x;\n'''");+ const cmd = try Command.parse(aa, "/evaluate script='''\nconst x = 1;\nreturn x;\n'''");var aw: std.Io.Writer.Allocating = .init(testing.allocator);defer aw.deinit();try cmd.formatJs(aa, &aw.writer);try testing.expectString("evaluate(`\nconst x = 1;\nreturn x;\n`);", aw.written());}{- const cmd = try Command.parse(aa, "/evaluate 'return `tick` + ${x};'");+ const cmd = try Command.parse(aa, "/evaluate script='return `tick` + ${x};'");var aw: std.Io.Writer.Allocating = .init(testing.allocator);defer aw.deinit();try cmd.formatJs(aa, &aw.writer);try testing.expectString("evaluate(\"return `tick` + ${x};\");", aw.written());}{- const cmd = try Command.parse(aa, "/extract '{\"title\":\"h1\",\"bad-key\":\".x\"}'");+ const cmd = try Command.parse(aa, "/extract schema='{\"title\":\"h1\",\"bad-key\":\".x\"}'");var aw: std.Io.Writer.Allocating = .init(testing.allocator);defer aw.deinit();try cmd.formatJs(aa, &aw.writer);try testing.expectString("extract({ title: \"h1\", \"bad-key\": \".x\" });", aw.written());}{- const cmd = try Command.parse(aa, "/extract '{\"title\":\"h1\"}' save=snap");+ const cmd = try Command.parse(aa, "/extract schema='{\"title\":\"h1\"}' save=snap");var aw: std.Io.Writer.Allocating = .init(testing.allocator);defer aw.deinit();try cmd.formatJs(aa, &aw.writer);@@ -499,6 +546,10 @@ test "isRecorded / producesData via tool flags" {const login: Command = .{ .llm = .login };try testing.expect(!login.isRecorded());++ // Only the call the model makes is recorded, never the prompt itself.+ const prompt = try Command.parse(arena.allocator(), "/click the sign in button");+ try testing.expect(!prompt.isRecorded());}test "isRecorded: screenshot needs a path to replay" {