Commit Graph

6284 Commits

Author SHA1 Message Date
Adrià Arrufat
c6ccd83ac4 mcp: add pandascript recording and self-healing tools
Adds tools to record sessions and heal scripts over MCP. Refactors
shared logic to `script.zig` and adds a TTY spinner for the agent.
2026-05-07 20:11:40 +02:00
Adrià Arrufat
7bf69a9a34 agent: remove integrated mcp server
Removes the `--mcp` flag and the internal `task` tool from the agent.
Users should use `lightpanda mcp` for external agent integrations.
2026-05-07 17:12:46 +02:00
Adrià Arrufat
16e61e342e terminal: simplify spinner access and organize ansi codes 2026-05-07 16:38:11 +02:00
Adrià Arrufat
855ab768fa terminal: show tool execution trace in spinner mode 2026-05-07 16:28:16 +02:00
Adrià Arrufat
a254e4041a agent: refine verbosity levels and tool output UI 2026-05-07 16:11:28 +02:00
Adrià Arrufat
54d873e007 agent: add proactive login and silence tool errors 2026-05-07 15:51:18 +02:00
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
Adrià Arrufat
8e9e82b478 cli: support short flags and hide tool results in REPL 2026-05-07 14:22:26 +02: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
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
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
Adrià Arrufat
845ef6ac3b terminal: use bitmask to track used slash command fields 2026-05-06 19:11:23 +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
Karl Seguin
7e0dc678c4 Improve BodyInit
Replace boundary allocation with a fixed-size buffer. Follow file naming for
non-struct-as-file file.
2026-05-06 12:06:54 +08:00
Karl Seguin
6136443764 Merge pull request #2369 from lightpanda-io/fix-a33-dispatch-listener-throw
Tweak: events: report listener exceptions instead of halting dispatch
2026-05-06 10:17:09 +08:00
Karl Seguin
bf7cac2b68 Extract repeated listener switch/execution into helper 2026-05-06 09:07:38 +08:00
Karl Seguin
00d0a9f3b0 Merge pull request #2366 from lightpanda-io/custom_element_callbacks_again
Protect DOM mutations against custom element callbacks.
2026-05-06 08:02:16 +08:00
Karl Seguin
ca4444e389 Merge pull request #2362 from lightpanda-io/slience_test_log
silence an unecessary test log
2026-05-06 07:53:40 +08:00
Karl Seguin
a3891c4f68 Merge pull request #2364 from lightpanda-io/response_double_free
Protect against response double-free
2026-05-06 07:53:26 +08:00
Karl Seguin
0ca3f2d8ec Merge pull request #2365 from lightpanda-io/dom_version_node_frame
Track DOM version based on the node's owning frame
2026-05-06 07:53:13 +08:00
Navid EMAD
b573e44fe1 events: report listener exceptions instead of halting dispatch
Per DOM §2.9 step 4 substep 8 ("Inner invoke"), an exception thrown by a
listener callback must be reported to the realm's global, not propagated
out of `dispatchEvent`. Subsequent listeners on the same target and the
rest of the capture/bubble walk must still run.

Both `EventManager.dispatchPhase` (DOM targets) and
`EventManagerBase.dispatchDirect` (Window/XHR/AbortSignal/etc.) wrapped
the V8 callback invocation in raw `try`, so a listener throw aborted the
whole dispatch and surfaced as an uncaught exception at the
`Runtime.evaluate` boundary. The inline-handler invocation a few lines
above already used `catch |err| log.warn(...)`; this just extends the
same shape to the listener switch.

Closes #2367
2026-05-05 18:16:52 +02:00
Karl Seguin
5112adc69f Protect DOM mutations against custom element callbacks.
Same issue as https://github.com/lightpanda-io/browser/pull/2313

DOM mutations have certain expectations that custom element callbacks can
violate.
2026-05-05 19:22:34 +08:00