Adds a visual spinner to the REPL to indicate agent activity (thinking
or tool execution). Refactors terminal output to prevent interleaving
with spinner frames.
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).
`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).
- 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.
- Extract `modeNeedsHttp` helper in `Config.zig`.
- Move `CallParams` to `protocol.zig` to deduplicate MCP code.
- Extract `lookupLpEnv` in `browser/tools.zig` for environment lookups.
Removes pre-state tracking and click verification from the agent.
Consolidates provider requirement validation logic and optimizes
`applyReplacements` by pre-calculating memory capacity.
- 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.
- 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.
- 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.
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.
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.
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.
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.
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.