Commit Graph
62 Commits
Author SHA1 Message Date
Adrià Arrufat df5fbf4bc3 command: require locator for null args in isRecorded
Tool calls like click or hover with null arguments are unreplayable
and should not be considered recorded, even if they have zero
required fields.
2026-05-25 17:33:08 +02:00
Adrià Arrufat adc76d2cc1 agent: fix tool output capping and tokenizer escape handling
- Limit UTF-8 walkback in `capToolOutput` to 3 bytes to prevent
  excessive scanning on malformed input.
- Track consecutive backslashes in `tokenize` to correctly handle
  even-count backslashes before a closing quote.
2026-05-24 12:18:05 +02:00
Adrià Arrufat aed5bbf1b6 schema: reject backslash escapes in quoted values
Explicitly reject backslash-escaped quotes with a clear error
message, suggesting alternative quote styles or triple quotes.
Bare backslashes (e.g. in Windows paths) remain supported.
2026-05-24 11:35:07 +02:00
Adrià Arrufat d469fdc88c tools: normalize PascalCase argument keys from LLMs 2026-05-24 11:22:42 +02:00
Adrià Arrufat bd861f5ac0 mcp: rename tools to camelCase 2026-05-24 11:13:56 +02:00
Adrià Arrufat 0670823905 script: rename mcp_driver_guidance to driver_guidance
Rename the system prompt constant to reflect its broader usage.
Also add instructions to guide the agent on handling follow-up
questions after navigation.
2026-05-23 11:24:36 +02:00
Adrià Arrufat f8d12cf4b5 schema: test parseValue with embedded single quotes 2026-05-22 22:38:48 +02:00
Adrià Arrufat 5454f2b2c2 terminal: disable completions inside triple quotes 2026-05-22 21:15:14 +02:00
Adrià Arrufat 005e489870 schema: make argument keys case-insensitive
Normalizes parsed keys to their canonical casing defined in the schema
for both KV and JSON inputs.
2026-05-22 20:29:45 +02:00
Adrià Arrufat 91916b7aae repl: sort slash commands alphabetically in help 2026-05-22 20:09:56 +02:00
Adrià Arrufat f7a4d1f6e2 terminal: unify tool and action result printing
Replaces `printActionResult` and `printToolResult` with a single
`printToolOutcome` function. This unifies the output path and adds
red/green color coding for tool failures and successes.
2026-05-22 19:05:46 +02:00
Adrià Arrufat 96c16defdd refactor: apply minor cleanups and improvements
- Add `/.lp-history` to `.gitignore`.
- Make `SlashCommand.MetaCommand.Tag` private.
- Simplify loop in `tools.zig` using `while ... else`.
- Use `trimStart` instead of `trim` in `Schema.splitNameRest`.
2026-05-22 16:38:46 +02:00
Adrià Arrufat 1309407e01 script: unify heal formatting and move TTY helpers
- Merge `formatHealReplacement` and `formatHealReplacementLines` using
  a new `HealBody` union.
- Move `interactiveTty` and `promptNumberedChoice` to `Terminal.zig`.
- Relocate and consolidate tests for `canHeal` and `isRecorded`.
- Make internal `Schema` functions private.
2026-05-22 16:19:46 +02:00
Adrià Arrufat 486d0d53a9 agent: inline CommandRunner and simplify Command union 2026-05-22 15:50:36 +02:00
Adrià Arrufat 3a792c7c1c command: centralize slash command parsing and retry logic 2026-05-22 15:17:59 +02:00
Adrià Arrufat 8fb3c7baed tools: restructure browser tools and script schemas
- Replace `Action` enum with `Tool` enum using exhaustive switches
- Extract `ScriptIterator` to `Iterator.zig`
- Refactor `schema.zig` into `Schema.zig`
- Move string substitution logic into `tools.zig`
- Clean up `SlashCommand.zig` to only handle REPL meta-commands
2026-05-22 13:41:04 +02:00
Adrià Arrufat 6cd75c454e script: optimize hint allocation and inline helper
Calculate the exact size needed for hint slots in schema.zig to avoid
overallocating. Also inline the single-use helper isDefaultTrueBool in
command.zig.
2026-05-22 09:23:52 +02:00
Adrià Arrufat fec1909aa1 script: strip backendNodeId and fix error line reporting
- Allow recording commands with backendNodeId if they also have a
  selector, stripping backendNodeId during formatting.
- Point UnterminatedQuote errors to the opening line instead of EOF.
- Fix buildHints allocation when fields is empty but required is not.
- Update docs to clarify positional argument rules.
2026-05-22 09:18:32 +02:00
Adrià Arrufat df42d18d6d command: check required fields for null-arg tool calls
Tool calls with null arguments are now only considered recorded if the
tool schema has no required fields. This prevents generating invalid,
unreplayable commands for tools like `goto` or `fill`.
2026-05-22 09:09:19 +02:00
Adrià Arrufat a3eeec0b26 agent: use global tools and simplify meta commands
- Initialize tools once globally instead of allocating per-agent.
- Refactor meta commands to use an enum for cleaner dispatch.
- Remove unused `findSchemaCanonical` and simplify command parsing.
2026-05-21 23:24:21 +02:00
Adrià Arrufat 6177d51c4e agent: use action enum for tool calls and trim REPL input
- Update `buildToolCall` to use `browser_tools.Action` enum.
- Trim whitespace from REPL input in `Agent.zig`.
- Replace `expectEqualStrings` with `expectString` in tests.
2026-05-21 23:06:34 +02:00
Adrià Arrufat e9943a3976 command: use Action enum for ToolCall name
Replaces the string `name` in `ToolCall` with `action: browser_tools.Action`.
This avoids repeated string-to-enum parsing and simplifies schema lookups.
Also updates `zenai` dependency to use its JSON duplication helper.
2026-05-21 22:51:52 +02:00
Adrià Arrufat 13ebb9e802 agent: simplify command, schema, and repl logic
- Remove `input_schema_raw` from `SchemaInfo` and use `parameters` directly
- Simplify JSON field extraction in `Verifier` to avoid `parseArgs`
- Refactor REPL command splitting and environment substitution
- Clean up and condense comments across the codebase
2026-05-21 22:39:58 +02:00
Adrià Arrufat e89fb9b485 agent: simplify tool allocation and schema info
Remove `tool_schema_arena` from `Agent` and allocate the tools slice
directly using the general allocator.

Remove the pre-calculated `is_multiline_capable` field from
`SchemaInfo` and compute it dynamically in `isMultiLineCapable()`.
2026-05-21 22:24:27 +02:00
Adrià Arrufat 3b2956c400 schema: simplify initialization and parsing
- Use global schemas built once at startup instead of parsing on init.
- Simplify argument verification using `browser_tools.parseArgs`.
- Optimize `parseValue` with `std.ArrayList`.
- Panic on global schema parse failure since schemas are static.
2026-05-21 22:17:21 +02:00
Adrià Arrufat 8cf431b771 agent: remove ToolExecutor abstraction
Inlines the browser, session, and node registry management directly
into Agent. Updates CommandRunner to use Session and Registry directly,
and calls browser_tools.call without the ToolExecutor wrapper.
2026-05-21 22:02:27 +02:00
Adrià Arrufat 349b4ea798 agent: clean up dead code and optimize schema parsing
- Remove unused `callEval` and `extract` from `ToolExecutor`.
- Optimize `parseValue` in `schema.zig` to allocate directly instead of
  using `std.ArrayList` when filling missing defaults.
- Simplify redundant checks and clean up comments.
2026-05-21 21:41:28 +02:00
Adrià Arrufat d16f8a032e script: support triple-quoted strings and optimize lookups
- Add support for triple-quoted strings (''' and """) in the tokenizer
  and quote stripper.
- Avoid allocations in `stripQuotes` by returning slices.
- Optimize schema lookups using O(1) enum-based canonical resolution.
- Skip env var substitution if "$LP_" is not present in the string.
2026-05-21 21:33:05 +02:00
Adrià Arrufat 7f60d73338 use global schemas and enum-based tool matching
- Use `SlashCommand.globalSchemas()` instead of passing schemas around.
- Use `browser_tools.Action` enums for tool matching in Agent and Verifier.
- Optimize string substitution and quote stripping with early exits.
2026-05-21 21:08:02 +02:00
Adrià Arrufat 0ce0d264a4 agent: prevent use-after-free in self-heal path 2026-05-21 20:45:03 +02:00
Adrià Arrufat 459893f414 script: unify PandaScript to slash commands
Unifies PandaScript syntax by replacing uppercase keywords with slash
commands (e.g., `/goto`, `/click`, `/fill`). Refactors the `Command`
representation to use a generic tool call structure backed by schemas.

BREAKING CHANGE: Uppercase PandaScript keywords (GOTO, CLICK, TYPE, etc.)
are no longer supported. All scripts must use slash commands.
2026-05-21 20:38:21 +02:00
Adrià Arrufat ceb5f368f0 script: rename raw_line to opener_line 2026-05-21 18:01:46 +02:00
Adrià Arrufat 31e20ae261 Recorder: pass directory to init and reuse arena
Update `Recorder.init` to accept a `std.fs.Dir` and relative path,
decoupling it from the current working directory.

Also add a persistent arena allocator to `Recorder` to reuse
allocations when scrubbing environment variables on each write.
2026-05-21 17:45:54 +02:00
Adrià Arrufat 88d56c63d0 script: optimize formatting and avoid redundant writes
- Skip atomic writes if the content is unchanged.
- Use allocating writer to reduce allocations during formatting.
2026-05-21 17:37:13 +02:00
Adrià Arrufat 55a50746fa script: move helper functions into Command union
Renames `Command.zig` to `command.zig` and moves associated functions
like `parse`, `toToolCall`, and `canHeal` directly into the `Command`
union. This simplifies usage from `Command.Command` to just `Command`.
2026-05-21 17:13:19 +02:00
Adrià Arrufat e0af9c4168 refactor: unify tool results and rename CommandExecutor
Unifies tool outcomes into a `ToolResult` struct, replacing `EvalResult`.
Renames `CommandExecutor` to `CommandRunner` and simplifies error handling.
2026-05-19 13:01:39 +02:00
Adrià Arrufat 92733763d8 refactor: use explicit type names and encapsulate spinner state
- Replace `Self` with `Recorder` and `Verifier` for improved clarity.
- Add `Spinner.isEnabled()` to encapsulate atomic state access.
- Shorten and refine various comments across the codebase.
2026-05-19 11:13:15 +02:00
Adrià Arrufat 66e7b1aafd script: improve verifier and recorder robustness
- Make `VerifyResult.failed` reason non-optional with an OOM fallback.
- Use `ElementProperty` enum for safer JS property injection.
- Ensure `Recorder` disables on all errors to prevent silent data loss.
- Add `CHECK` command round-trip test.
2026-05-19 10:51:13 +02:00
Adrià Arrufat 061a740dbb script: improve reliability, CRLF support, and formatting
- Prevent UB in `applyReplacements` with pointer assertions.
- Reorder `writeAtomic` to build content before writing backup.
- Strip trailing `\r` in `ScriptIterator` for CRLF compatibility.
- Use shorter representation for `SCROLL` commands.
2026-05-19 10:43:20 +02:00
Adrià Arrufat 61b6003818 refactor: simplify tool execution and recording logic 2026-05-14 13:45:35 +02:00
Adrià Arrufat 2862feb7c4 agent: improve recording quality and tool guidance
- Filter redundant `extract` calls in recordings to reduce noise.
- Scrub literal `LP_*` secrets from recorded commands for portability.
- Throw a descriptive error in `extract` when no selectors match.
- Update tool descriptions and guidance to favor a `tree` ->
  `nodeDetails` -> `extract` workflow for more robust selectors.
2026-05-14 13:36:36 +02:00
Adrià Arrufat 3d8621561a tools: add extract tool for structured data
Adds the `extract` tool for lifting structured data via JSON schemas.
Updates the command system to support recording and replaying
extraction steps in PandaScript.
2026-05-14 10:32:59 +02:00
Adrià Arrufat 819d2f9884 verifier: change VerifyResult to a tagged union
Replaces the struct-based result with a tagged union to represent
verification outcomes more idiomatically. Updates callers in Agent
and MCP tools to handle the new union type.
2026-05-14 09:39:12 +02:00
Adrià Arrufat eb863e0b16 script: unify tool call conversion to use json values 2026-05-14 09:23:54 +02:00
Adrià Arrufat 001fbb97d0 Recorder: make init fallible and Agent.recorder optional 2026-05-14 08:59:47 +02:00
Adrià Arrufat ad862862c2 test: consolidate Command parsing and round-trip tests 2026-05-14 07:48:45 +02:00
Adrià Arrufat 6538a34f56 browser: separate operational and JS errors in eval
Changes `EvalResult` to a union and uses Zig errors for operational
failures, distinguishing them from JavaScript execution errors.
Also removes redundant `stringifyJson` in favor of standard library.
2026-05-13 14:27:28 +02:00
Adrià Arrufat 635546bf85 Recorder: simplify initialization and file opening 2026-05-13 14:03:18 +02:00
Adrià Arrufat b2454a9190 chore: add license headers to source files 2026-05-13 13:20:36 +02:00
Adrià Arrufat b4b533d2be agent: derive Action enum from tool_defs and clean up Verifier
- Derives the `Action` enum in `src/browser/tools.zig` from `tool_defs` to prevent manual maintenance and potential drift.
- Refactors `verifyElementValue` in `src/script/Verifier.zig` to use a `Check` struct for its parameters.
- Reorganizes and cleans up imports in `src/agent/Agent.zig`.
2026-05-13 13:18:30 +02:00