Commit Graph

5406 Commits

Author SHA1 Message Date
Adrià Arrufat
fbec560292 Ref: #123
fix: address various stability and reliability issues

- Cache stderr TTY check in Config to optimize log hot path.
- Cap signal handler attempts during no-hard-exit.
- Always duplicate URL segments to prevent invalid frees.
- Write live file before backup in atomic writes.
- Settle microtasks before verifying DOM elements.
2026-05-25 18:05:11 +02:00
Adrià Arrufat
4bc5baf7ee agent: improve command diagnostics and fix various bugs
- Add diagnostics to command parsing to report invalid field values.
- Fix UTF-8 truncation in spinner to avoid splitting codepoints.
- Fix swapped arguments in log error formatting.
- Distinguish "null" values from missing elements in verifier.
- Handle MCP tool cancellation and timeouts with specific error codes.
2026-05-25 17:51:46 +02:00
Adrià Arrufat
4ad59b07b3 console: use warn severity for console.warn 2026-05-25 17:40:06 +02:00
Adrià Arrufat
7532cd1df4 session: cap console message size to remaining budget 2026-05-25 17:39:49 +02:00
Adrià Arrufat
8ca2975b1d browser: catch implicit form submit error on Enter
Prevents form submission failures from blocking the subsequent keyup
event, which could cause UIs waiting on keyup to hang.
2026-05-25 17:37:15 +02:00
Adrià Arrufat
e519d84318 tools: default checked to true in execSetChecked 2026-05-25 17:36:06 +02:00
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
634566f4b8 agent: truncate tool output at UTF-8 boundary 2026-05-24 11:48:22 +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
4a58a9043e tools: reject invalid backendNodeId in tree tool 2026-05-24 11:25:41 +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
1151e03181 mcp: index multi-line blocks as single spans
Detects multi-line block openers (e.g., `/eval '''`) and indexes the
entire block up to its closing fence as a single span. This prevents
body lines from being indexed individually and orphaned during splicing.
Falls back to single-line indexing if the block is unterminated.
2026-05-24 10:31:08 +02:00
Adrià Arrufat
3381f64ad9 mcp: handle CRLF line endings in indexLines
Strip carriage returns from CRLF line endings before indexing so that
LLM-supplied keys (using plain LF) match files saved with Windows
line endings. The span still covers the full CRLF sequence.
2026-05-24 09:00:31 +02:00
Adrià Arrufat
09698045c6 tools: refuse getCookies without active page
Return an error message instead of dumping all cookies when no page
is loaded and no filter is provided.
2026-05-24 09:00:19 +02:00
Adrià Arrufat
0c58184137 Cookie: make host matching case-insensitive 2026-05-24 08:46:55 +02:00
Adrià Arrufat
525c3e467c input: centralize password value redaction
Introduces `Input.getRedactedValue` to mask password values in
LLM-facing dumps (semantic tree, forms, AXNode) instead of
exposing raw values or using ad-hoc checks.
2026-05-24 08:36:23 +02:00
Adrià Arrufat
ddd9c84195 agent: update zenai and tune agent settings 2026-05-23 23:36:07 +02:00
Adrià Arrufat
8721bfb69e Spinner: prevent line wrapping and multi-line breaks
Strips control characters from tool arguments to avoid breaking the
carriage-return redraw. Queries the terminal width and truncates
arguments to fit on a single row, appending an ellipsis if needed.
2026-05-23 17:22:47 +02:00
Adrià Arrufat
6a0801a6f6 agent: add user turn before slash tool call
Gemini requires that a function call follow a user or function-response
turn. Record the user input before the synthetic assistant tool call.
2026-05-23 14:46:32 +02:00
Adrià Arrufat
4c06fe482f agent: record slash commands as tool calls
Mirrors user-typed slash commands into the message history as synthetic
tool calls. This ensures the LLM conversation remains in sync and the
next prompt can see the action's result.
2026-05-23 11:54:48 +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
424f315f27 browser: fix premature timeouts and handle eval navigation
- In Runner, sleep and poll on idle tick instead of failing early.
- In tools, await queued navigations after eval and report the new page.
2026-05-23 10:52:24 +02:00
Adrià Arrufat
70b9b6f958 Merge branch 'main' into agent 2026-05-22 23:34:36 +02:00
Adrià Arrufat
f8d12cf4b5 schema: test parseValue with embedded single quotes 2026-05-22 22:38:48 +02:00
Adrià Arrufat
1bb506761c tools: support selector and backendNodeId in html tool
Allows dumping a specific element's outerHTML instead of the full
document when a selector or backendNodeId is provided.
2026-05-22 22:35:54 +02:00
Adrià Arrufat
2defc0e829 tools: add html tool to dump raw page HTML
Adds a new `html` tool to dump the full raw HTML of the current page.
This is useful for debugging and capturing fixtures.
2026-05-22 22:31:34 +02:00
Adrià Arrufat
056912bbee browser: add waitForScript tool
Adds a new `waitForScript` tool to wait for a JS expression to
evaluate to truthy. This allows synchronization beyond what CSS
selectors can express.
2026-05-22 22:23:50 +02:00
Adrià Arrufat
312276f968 browser: normalize keys and support form submit in press
- Map common key shorthand aliases to canonical KeyboardEvent keys.
- Trigger implicit form submission when pressing Enter on inputs.
- Add CSS selector support to the press tool.
2026-05-22 22:16:56 +02:00
Adrià Arrufat
4e69be8543 tools: add filtering options to getCookies
Allows filtering cookies by URL or dumping all cookies. Defaults to
cookies matching the current page's host.
2026-05-22 22:05:36 +02:00
Adrià Arrufat
f917a7adfc terminal: simplify print API and add printDimmed
Unifies printInfo/printInfoFmt and printError/printErrorFmt into
single functions accepting format arguments. Adds printDimmed for
dimmed output and supports highlighting quoted slash arguments.
2026-05-22 21:49:41 +02:00
Adrià Arrufat
5454f2b2c2 terminal: disable completions inside triple quotes 2026-05-22 21:15:14 +02:00
Adrià Arrufat
4d283ae21c terminal: improve colors and help formatting
- Remove automatic dimming from `printInfoFmt`
- Add explicit ANSI formatting to slash command help
- Adjust syntax highlighting colors for terminal output
2026-05-22 20:56:35 +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
d4f4be704d repl: categorize help and centralize LLM checks
- Group `/help` output into Browser, LLM, and Meta commands.
- Only show LLM commands in help if an LLM client is configured.
- Centralize the check for commands requiring an LLM in the REPL loop.
- Add descriptions to meta and LLM commands.
2026-05-22 20:24:24 +02:00
Adrià Arrufat
0049480f04 Merge pull request #2528 from lightpanda-io/parseargs-error-detail
terminal: better error diagnostics
2026-05-22 20:10:07 +02:00
Adrià Arrufat
91916b7aae repl: sort slash commands alphabetically in help 2026-05-22 20:09:56 +02:00
Adrià Arrufat
c30ccae5fb terminal: improve log routing and navigation error reporting
- Route logs through a terminal sink to avoid trampling the spinner.
- Track and format the last navigation error in browser tools.
2026-05-22 19:58:02 +02:00
Adrià Arrufat
0219ee66b7 tools: add argument diagnostics
Validate tool arguments like `waitUntil` before parsing to provide
clearer error messages with expected enum values.
2026-05-22 19:33:53 +02:00
Adrià Arrufat
2669e3223f browser: add cooperative cancellation support
Allows SIGINT to abort in-flight browser operations and V8 execution.
2026-05-22 19:22:46 +02:00
Adrià Arrufat
aef2c1326d Merge pull request #2527 from lightpanda-io/waitforselector-notfound
tools: map waitForSelector timeout to NodeNotFound
2026-05-22 19:13:17 +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
db14d0be1b tools: map waitForSelector timeout to NodeNotFound
When a selector times out without matching, the outcome is the same as
/hover or /click against a missing node. Returning InternalError instead
gave inconsistent feedback to the agent.

Map error.Timeout to NodeNotFound and leave the catch-all log +
InternalError for genuinely unexpected errors. Tighten the existing
MCP - waitForSelector: timeout test to pin the specific error name.
2026-05-22 18:47:46 +02:00
Adrià Arrufat
3b285df432 browser: reset node registry on navigation
When an action triggers a navigation that swaps the root frame, the
previous page is torn down, leaving dangling DOMNode pointers in the
registry.

Reset the registry in `finalizeAction` if the frame changes to prevent
subsequent actions from dereferencing freed memory.
2026-05-22 17:32:17 +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
Karl Seguin
9d6dcb71ab Merge pull request #2521 from lightpanda-io/multi_remove_assert_attributes
Add more attributes to multi_remove assertion failure
2026-05-22 20:12:53 +08:00