Commit Graph

8347 Commits

Author SHA1 Message Date
Adrià Arrufat
598a3b984b agent: add status spinner for AI turns
Adds a visual spinner to the REPL to indicate agent activity (thinking
or tool execution). Refactors terminal output to prevent interleaving
with spinner frames.
2026-05-07 15:25:26 +02:00
Adrià Arrufat
b716bfe1bc browser: improve getUrl tool description 2026-05-07 14:38:44 +02:00
Karl Seguin
61497ffe3a Merge pull request #2383 from lightpanda-io/css_static_binding
Fix binding for static (in general) and specifically for CSS.escape
2026-05-07 20:30:40 +08:00
Adrià Arrufat
8e9e82b478 cli: support short flags and hide tool results in REPL 2026-05-07 14:22:26 +02:00
Karl Seguin
a4cf214040 Merge pull request #2382 from lightpanda-io/xhr_fix_teardown_order
Fix the XHR teardown order
2026-05-07 20:05:55 +08:00
Karl Seguin
87b0c33344 Merge pull request #2384 from lightpanda-io/silence_test_warns
Silence test warnings
2026-05-07 19:50:57 +08:00
Karl Seguin
a74c5cc54c On error, don't free headers
There's ambiguity in the http_client.request() call on whether or not the caller
is responsible for freeing the header. It depends how request() fails, and it's
impossible for the caller to know. This needs a fundamental fix, but, in the
meantime, we get to pick between: a possible leak or a double free.

This commit opts for a possible leak. Why? Because overwhelmingly, if request
fails, it'll fail at a point where it will handle the free. In those cases
where it doesn't then the system is probably in trouble anyways (OOM).

(Also, as I was debugging, I noticed that the function.src() debug helper
wasn't working, so I fixed it).
2026-05-07 19:47:29 +08:00
Karl Seguin
459c7a532a Silence test warnings
https://github.com/lightpanda-io/browser/pull/2368  added more warnings on JS
callback failure. The test for these naturally trigger the logging. Silence them
during testing.
2026-05-07 18:59:46 +08:00
Karl Seguin
dd49e51f7a Fix binding for static (in general) and specifically for CSS.escape
Fixes rendering issue on:
https://jobs.gem.com/inception/am9icG9zdDpZ-UzWsyEeC6ZVEZ8l0t4s
2026-05-07 18:49:28 +08:00
Karl Seguin
783bfd3813 Fix the XHR teardown order
`releaseRef` can free the XHR instance, so anything we want to set, has to
happen before then. (It might seem like the set is meaningful if we're just
going to destroy the instance, but `releaseRef` might also _not_ destroy the
instance, and the guard is for those cases).
2026-05-07 17:48:34 +08:00
Adrià Arrufat
0de602695f refactor: rename buildJson to stringifyJson and clean up logic
- Rename `Command.buildJson` to `stringifyJson` for clarity.
- Flatten tool call recording loop in `Agent.zig` to reduce nesting.
- Extract `parseValue` helper in `tools.zig` to reduce duplication.
- Optimize `substituteEnvVars` by skipping redundant string scans.
2026-05-07 11:00:33 +02:00
Adrià Arrufat
02ae92d619 agent: remove unused code and add recorder guard 2026-05-07 10:34:14 +02:00
Adrià Arrufat
25f8dfcab3 refactor: consolidate common logic and structs
- Extract `modeNeedsHttp` helper in `Config.zig`.
- Move `CallParams` to `protocol.zig` to deduplicate MCP code.
- Extract `lookupLpEnv` in `browser/tools.zig` for environment lookups.
2026-05-07 10:11:25 +02:00
Adrià Arrufat
7fb0251fff agent: simplify verification and provider checks
Removes pre-state tracking and click verification from the agent.
Consolidates provider requirement validation logic and optimizes
`applyReplacements` by pre-calculating memory capacity.
2026-05-07 10:04:35 +02:00
Adrià Arrufat
bf172bd811 refactor: consolidate browser tool helpers and optimize logic
- Extract `awaitQueuedNavigation` and `mapActionError` in `tools.zig`.
- Optimize `substituteEnvVars` using `indexOfScalarPos` to reduce copies.
- Switch to `parseFromSliceLeaky` for tool arguments parsing.
- Improve error handling in `Agent.zig` self-healing and `Recorder.zig`.
- Simplify `callEval` by adding `evalScript` helper.
2026-05-07 09:52:43 +02:00
Adrià Arrufat
5bcf90a8f9 perf: optimize terminal json parsing and env var substitution
- Skip JSON parsing in Terminal for non-JSON tool results to avoid unnecessary allocations.
- Simplify `$LP_` environment variable detection in tools.
- Update documentation comments in Agent for clarity.
2026-05-07 09:41:47 +02:00
Adrià Arrufat
87d0bc95dc agent: modularize script runner and simplify terminal state 2026-05-07 09:35:08 +02:00
Adrià Arrufat
92a0f0e290 refactor: reorder tool arguments and optimize env substitution
- Reorder `arena` and `session` arguments in tool functions.
- Optimize `substituteEnvVars` to only process `$LP_` prefixes.
- Use stack buffer for backup paths in `Agent.zig`.
- Clean up `formatActionResult` implementation.
2026-05-07 09:25:36 +02:00
Adrià Arrufat
7beb4691dd Merge branch 'main' into agent 2026-05-07 08:54:28 +02:00
Adrià Arrufat
1dc4262478 terminal: pretty-print tool results in REPL 2026-05-07 08:46:49 +02:00
Adrià Arrufat
93d08a486b agent: add --verbosity flag to control stderr output 2026-05-07 08:15:51 +02:00
Karl Seguin
3143b6e519 On Illegal Constructor, try to capture name (for logs)
Just improves the log a little to try and capture the name of what was
constructed. We see this often in WPT tests, which is probably WPT testing the
illegal constructor behavior, but it's hard to be sure. Having the name logged
gives us enough detail to see if the behavior is correct or not.

Also, downgraded the log level from warn -> info.
2026-05-07 10:29:53 +08:00
Karl Seguin
5615ba762d Give setters an arity of 1
Static functions don't take a 'self' so their arity isn't + 1.

Fixes a handful of IDL test cases.
2026-05-07 10:11:56 +08:00
Karl Seguin
5a0c7eff66 Protect assertion when reload from about:blank
(and hopefully all other cases) where a commit happens on a previously blank
slate.
2026-05-07 09:14:07 +08:00
Karl Seguin
03ee1f61d0 Merge pull request #2376 from webcoyote/fix-ws-port
Fix /json/version advertising ws://host:0/ when --port 0
2026-05-07 08:19:18 +08:00
Karl Seguin
4f7db8e974 Merge pull request #2375 from lightpanda-io/worker_location
add WorkerLocation
2026-05-07 08:18:51 +08:00
Karl Seguin
2de56622d5 Track DOM version on the page
This is a follow up to https://github.com/lightpanda-io/browser/pull/2365 which
implements a different fix with different performance tradeoffs.

To recap, #2365 fixed an issue where the frame used to track the dom version
was the frame here the JS was being executed, not necessarily where the node
existed. This would cause the caching to break. #2365 fixed this by always
using the node's frame. But this is relatively expensive, requiring that we
find the owning document of a node in order to get its frame. This traversal
has to happen on every dom manipulation (to update the version) and every cached
read (to verify the dom version hasn't changed). We _could_ store the owning
frame on every Node, but that's relatively memory expensive to do.

This commit moves the dom version from the Frame to the Page. This allows us
to use the executing Frame to get the page (`frame._page`) which is much faster
than traversing the parent nodes to find the document. The downside is that a
mutation in Frame1 will invalidate the cache in Frame2. Given that many sites
have a single frame, this seems like a clear win.
2026-05-07 08:14:03 +08:00
Karl Seguin
f13ca0f44a Merge pull request #2371 from lightpanda-io/cdp_navigate_fast_path
On an unloaded-page, fast-path navigation
2026-05-07 06:47:43 +08:00
Karl Seguin
608650533a Merge pull request #2374 from lightpanda-io/frame_deinit_order
Abort http_client _before_ destroying context
2026-05-07 06:47:26 +08:00
Karl Seguin
740f95e142 Merge pull request #2372 from lightpanda-io/worker_subtle_crypto
Make SubtleCrypto work on Worker
2026-05-07 06:47:12 +08:00
Patrick Wyatt
f352c49a3a Fix /json/version advertising ws://host:0/ when --port 0
buildJSONVersionResponse read the port from app.config.port(), which
is the configured value (still 0 with --port 0). Pass the OS-assigned
port from the bound address instead, so webSocketDebuggerUrl matches
the actual listener.

The integration test previously asserted a literal ws://127.0.0.1:9222/
that happened to match the test config's default port but not the
harness's hardcoded bind address (9583) — drop the URL assertion; the
buildJSONVersionResponse unit test already covers URL formatting.
2026-05-06 12:44:38 -07:00
Adrià Arrufat
1be0efece6 agent: update /help syntax to show optional argument 2026-05-06 19:26:38 +02:00
Adrià Arrufat
c7c6d08f18 terminal: improve slash command hint logic 2026-05-06 19:22:20 +02:00
Pierre Tachoire
7df0f8d5d5 cdp: use a specific enum for console message 2026-05-06 19:15:44 +02:00
Adrià Arrufat
845ef6ac3b terminal: use bitmask to track used slash command fields 2026-05-06 19:11:23 +02:00
Pierre Tachoire
d6c9a5fb83 cdp: add runtime.consoleAPICalled 2026-05-06 18:34:30 +02:00
Pierre Tachoire
2c28023168 implement jsonStringify for js.Value 2026-05-06 18:34:29 +02:00
Pierre Tachoire
595b774f1d cdp: implement Console.messageAdded event 2026-05-06 18:34:29 +02:00
Adrià Arrufat
bdd1256c8b terminal: simplify slash command hinting and completion 2026-05-06 18:25:56 +02:00
Adrià Arrufat
425f5d4e96 terminal: use bufPrintZ for prefixed completion 2026-05-06 18:03:06 +02:00
Adrià Arrufat
b8ebe6fa11 terminal: improve slash command completion and hinting 2026-05-06 17:59:47 +02:00
Adrià Arrufat
9690164514 terminal: add tab-completion for slash command keys 2026-05-06 16:39:21 +02:00
Adrià Arrufat
248c04239d agent: dynamic slash command hints and improved parsing 2026-05-06 15:52:31 +02:00
Adrià Arrufat
71616046fb terminal: add slash command hints and help completions
Adds argument syntax hints (e.g. <req> [opt]) for slash commands in the
REPL and implements tab completion for /help command arguments.
2026-05-06 15:28:57 +02:00
Karl Seguin
15021b7302 add WorkerLocation
This is a distinct type from Location, a read-only subset.
2026-05-06 18:57:31 +08:00
Karl Seguin
042df590a2 Abort http_client _before_ destroying context
XHR, for example, needs the context to properly shutdown. It get the page via
exec.context.page. Now, we could store the page on the XHR instance, sure. But
the point is the js.Context should never need the HttpClient, so it should
always be safe to abort inflight requests before canceling the context.

Fixes some flaky WPT crashes.
2026-05-06 18:42:06 +08:00
Karl Seguin
95f647d4ae Make SubtleCrypto work on Worker
This is a source of many WPT crashes right now. worker.crypto is exposed, and
therefore worker.crypto.subtle also is.
2026-05-06 16:12:41 +08:00
Adrià Arrufat
36d40be2cf Merge branch 'main' into agent 2026-05-06 07:56:28 +02:00
Karl Seguin
0c87fd6771 Merge pull request #2370 from lightpanda-io/fix-a34-fetch-xhr-formdata-multipart
Fix a34 fetch xhr formdata multipart
2026-05-06 12:50:34 +08:00
Karl Seguin
47792378ee On an unloaded-page, fast-path navigation
This re-implements the CDP navigate action fast-path when a page is in a
waiting state. It was removed for https://github.com/lightpanda-io/browser/pull/2297.

I believe this fast-path is still safe to do given that a page in _waiting has
had no navigation event yet and thus has nothing to preserve. The upside is
being able to re-use the existing [bare] v8::Context.
2026-05-06 12:38:12 +08:00