Commit Graph
35 Commits
Author SHA1 Message Date
Karl Seguin 2e6999f20b chore: make declarations private if they don't need to be public
This change is 99%  s/pub//   + a handful of dead code removal.
2026-09-10 14:42:09 +08:00
Adrià Arrufat cff32f6c04 agent: let the model see a REPL /screenshot; fold the tool-result adapters
The slash path's result has two consumers: the terminal, which can't
show an image, and the conversation, which can. Opt in when a model is
attached and forward the image through the same adapter the model-driven
path uses, and stop mapping a failed adapter to a text-only success.
MCP's ImageContent and CallToolResult take their payload type like
TextContent does; resolveScope reuses resolveTarget; needsLocator folds
into replayRequires.
2026-08-27 15:03:19 +02:00
Adrià Arrufat 193f15558c tools: declare image support at the call site, not in each consumer
Callers pass CallOpts.inline_image; execScreenshot rejects a path-less
call before navigating or rendering, which removes the per-consumer
guards and covers the model-driven tool path that had none. MCP image
content is a protocol type, the screenshot recording rule joins the
recorder's replayRequires predicate, and the viewport-to-Opts mapping,
node-scope ladder and save-path helpers are shared instead of copied.
2026-08-27 15:03:19 +02:00
Adrià Arrufat 5f8eb43867 Merge pull request #3276 from lightpanda-io/mcp-tool-annotations
mcp: add title and annotations to tools/list
2026-08-26 09:46:48 +02:00
Adrià Arrufat ade731cb0b mcp: add title and annotations to tools/list
Every tool already had a short summary and a natural read-only /
destructive classification, but tools/list exposed neither, so clients
had to prompt for every call, including pure reads like getUrl.
2026-08-25 15:46:30 +02:00
Adrià Arrufat 3e8b836680 mcp: negotiate the protocol version on initialize
initialize always answered 2024-11-05 regardless of what the client asked
for. Per the spec, echo the requested version when we support it and
otherwise reply with the newest we do (2025-11-25).
2026-08-25 15:30:26 +02:00
Karl Seguin c726b022e8 tests: improve test output and test log handling
1 - TEST_VERBOSE is now off by default
2 - There's a afterEach callback that is automatically run after each tests, it:
     a - clears the log filters
     b - resets the test arena
3 - LogFilter replace with
     a - testing.silenceLog(&.{...scopes...}); to silence all logs for the given
         scopes.
     b - testing.expectLog(&.{...scopes}); to set log expectations, 1 per log.
         The goal here isn't so much to expect logs (though, you can do that),
         but rather to silence an expected # of logs, without silencing more.
2026-07-31 07:30:25 +08:00
Adrià Arrufat fb7dfc1410 refactor: clean up comments and remove redundant ping test 2026-05-30 19:53:43 +02:00
Adrià Arrufat f51bda4d5a refactor: deduplicate comment writing and remove unused code 2026-05-30 19:32:59 +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 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 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 58308cfdca Merge branch 'main' into agent 2026-04-22 07:13:04 +02:00
Karl Seguin 2275416505 Page -> Frame
This is to pave the way for introducing a new "Page" container, which will take
over the page lifecycle currently burdening Session. The ultimate goal of that
is to allow the Session to have multiple pages (mostly for better transitions
between pages), which is hard to do now since the Session has so much state.

This rename was aggressive, e.g. currentPage() -> currentFrame() so that, when
the new Page container is added, you won't see "currentPage()" and wonder:

  "Does 'currentPage' mean the new Page container, or the Frame (which
  used to be called Page)".
2026-04-22 08:42:18 +08:00
Adrià Arrufat a5fd70f5dd refactor: improve tool execution and terminal formatting
- Standardize `fill` tool to use `value` instead of `text`.
- Add formatted output methods (`printInfoFmt`, `printErrorFmt`) to `Terminal`.
- Improve error handling in `ToolExecutor` and `browser/tools` by using error unions.
- Deduplicate `minify` utility and remove redundant code comments.
- Refactor tool dispatch to use `Action` enum tags instead of hardcoded strings.
2026-04-10 14:54:51 +02:00
Adrià Arrufat 81d4bdb157 mcp: change default protocol version to 2024-11-05 2026-03-29 08:34:24 +02:00
Adrià Arrufat cf5e4d7d1e mcp: allow configuring protocol version
Closes #2023
2026-03-29 08:29:04 +02:00
Karl Seguin c9bc370d6a Extract Session.wait into a Runner
This is done for a couple reasons. The first is just to have things a little
more self-contained for eventually supporting more advanced "wait" logic, e.g.
waiting for a selector.

The other is to provide callers with more fine-grained controlled. Specifically
the ability to manually "tick", so that they can [presumably] do something
after every tick. This is needed by the test runner to support more advanced
cases (cases that need to test beyond 'load') and it also improves (and fixes
potential use-after-free, the lp.waitForSelector)
2026-03-23 12:30:41 +08:00
evalstate 93ea95af24 feat(mcp): add ping request handling 2026-03-14 17:48:29 +00:00
Adrià Arrufat 60699229ca Merge branch 'main' into semantic-tree 2026-03-11 20:52:39 +09:00
Karl Seguin ae4ad713ec Fix page re-navigate
It isn't safe/correct to call `navigate` on the same page multiple times. A page
is meant to have 1 navigate call. The caller should either remove the page
and create a new one, or call Session.replacePage.

This commit removes the *Page from the MCP Server and instead interacts with
the session to create or remove+create the page as needed, and lets the Session
own the *Page.

It also adds a bit of defensiveness around parameter parsing, e.g. calling
{"method": "tools/call"} (without an id) now errors instead of crashing.
2026-03-07 10:19:37 +08:00
Adrià Arrufat 48df38cbfe mcp: improve evaluate error reporting and refactor tool result types 2026-03-03 15:17:59 +09:00
Adrià Arrufat c8d5665653 mcp: use testing allocator in tests 2026-03-03 14:32:29 +09:00
Adrià Arrufat 6b80cd6109 mcp: namespace tests 2026-03-03 14:19:36 +09:00
Adrià Arrufat 4f99df694b mcp: simplify minify and remove eval quota 2026-03-02 22:46:20 +09:00
Adrià Arrufat 3c858f522b mcp: simplify minify function 2026-03-02 22:04:55 +09:00
Adrià Arrufat 73565c4493 mcp: optimize dispatching and simplify test harness
- Use StaticStringMap and enums for method, tool, and resource lookups.
- Implement comptime JSON minification for tool schemas.
- Refactor router and harness to use more efficient buffered polling.
- Consolidate integration tests and add synchronous unit tests.
2026-03-02 20:53:14 +09:00
Adrià Arrufat 64107f5957 mcp: refactor for testability and add comprehensive test suite
- Refactor mcp.Server and router to accept injected I/O streams.
- Implement McpHarness for high-fidelity MCP integration testing.
- Add unit tests for protocol, tools, and resources modules.
- Add integration tests covering initialization, tool/resource execution, and error handling.
- Improve error reporting for malformed JSON requests.
2026-03-02 15:52:05 +09:00
Adrià Arrufat b63d4cf675 mcp: improve RawJson stringification and schema formatting
- Update `RawJson.jsonStringify` to parse and re-write JSON content, ensuring valid output.
- Reformat tool input schemas in `tools.zig` using multi-line string literals for better readability.
2026-03-02 11:47:02 +09:00
Adrià Arrufat e9c36fd6f8 mcp: use declarative static definitions for tools and resources 2026-03-01 21:56:48 +09:00
Adrià Arrufat 8cbc58d257 mcp: unify error reporting and use named error codes 2026-03-01 21:29:59 +09:00
Adrià Arrufat 947e672d18 mcp: stream resource and tool content to JSON output 2026-02-28 23:04:22 +09:00
Adrià Arrufat 8c8a05b8c1 mcp: consolidate tests and cleanup imports 2026-02-26 00:02:49 +09:00
Adrià Arrufat 34d2fc1503 mcp: support notifications and improve error handling
Make Request id optional for JSON-RPC notifications and handle the
initialized event. Improve thread safety, logging, and error paths.
2026-02-25 23:14:06 +09:00
Adrià Arrufat a27339b954 mcp: add Model Context Protocol server support
Adds a new `mcp` run mode to start an MCP server over stdio.
Implements tools for navigation and JS evaluation, along with
resources for HTML and Markdown page content.
2026-02-22 22:32:14 +09:00