Commit Graph
201 Commits
Author SHA1 Message Date
Adrià Arrufat c3afc75ce8 tools: ask Gemini Decisions only with LIGHTPANDA_DECISION_PROVIDER=gemini
#4590 sent decision asks (page content, a login's username) to Gemini
whenever GOOGLE_API_KEY or GEMINI_API_KEY was set, and preferred it over
TYPESAFE_API_KEY. A Google key is exported for many other reasons, so that
was no opt-in, and it silently moved anyone with both keys off TypeSafe.

TypeSafe answers by default again; Gemini only when
LIGHTPANDA_DECISION_PROVIDER=gemini. Missing-key messages, tool
descriptions and skill notes say so, from one App.decision_env_hint.
2026-11-13 10:31:24 +01:00
Adrià Arrufat e8f9864cc4 script: keep read_only test's return value off stdout
The test's `return 1;` printed to stdout, which METRICS=true test runs
redirect into bench.json, so perf-fmt failed to parse it.
2026-11-12 12:00:28 +01:00
Adrià Arrufat ecb7ac0663 Merge remote-tracking branch 'origin/main' into gemini-decisions 2026-11-12 10:19:53 +01:00
Adrià Arrufat 89d82c586b tools: rename jev.zig to decisions.zig
The module serves either decision model now, so it takes the name of
the zenai layer it wraps; MockJev becomes MockDecisions to match.
2026-11-11 21:50:25 +01:00
Adrià Arrufat 21c8c8e037 tools: ask Gemini Decisions or TypeSafe Jev
classify, acceptCookies and login now go through zenai.decisions, which
asks whichever decision model has a key: Gemini's Decisions API
(GOOGLE_API_KEY/GEMINI_API_KEY) or TypeSafe System One
(TYPESAFE_API_KEY). Gemini is preferred when both are set;
LIGHTPANDA_DECISION_PROVIDER=gemini|typesafe picks one.

Messages, tool descriptions and the REPL's no-key fallback name both
keys. The test mock serves Gemini's endpoint too, every mock test names
its provider so a developer's own Gemini key never reaches Google, and
the acceptCookies and login happy paths run against both.
2026-11-11 21:48:54 +01:00
Adrià Arrufat 397ce80de8 agent: run the --save check replay read-only, on shared plumbing
The replay's pages don't close when the script ends, so the repair turn
read pages[0], not what the replay saw. It now reads the last page the
replay opened, through the session's tool-frame override, and every page
the replays opened is closed afterwards. That drops the reload of the
script's first goto and the URL parsing behind it.

The replay runs with Runtime.read_only, which refuses every tool
Tool.replaySafe rules out at the call, however the script spells it. The
text match stays as the gate on replaying at all: a script that fails
before its first act would otherwise go to repair. A fix whose replay
doesn't pass keeps the first script.

Shared with what was already there:
- Runtime.runCaptured is the capped-console capture MCP's run tool had,
  now used by both, so the replay keeps MCP's truncation note.
- extract sets ToolResult.no_data from its full JSON, instead of the
  agent re-parsing capped output.
- pageIds/lastPageOpenedSince/closePagesOpenedSince move to browser_tools.
- one read-only gate for prompt requests and the repair turn.
- one fence parser for both synthesis paths.
2026-11-11 17:54:29 +01:00
Adrià Arrufat f5cfbc5a31 tools: explain a failed parse instead of gating the call
diagnoseArgTypes ran before dispatch and hand-copied std.json's coercion, so
any drift rejected a call that would have worked. Run it only once a tool has
returned InvalidParams, and probe std.json itself with each field's real
integer type. goto {waitUntil:0} and a byte array for a selector, which the
gate rejected, parse again.

Out-of-range integers now name the range instead of falling through to the
generic text. Drop the .number handling no schema uses, share the schema
lookup, and remove comments that only narrated.
2026-11-05 14:55:54 +01:00
Adrià Arrufat 09dbac3ec4 Merge branch 'main' into agent/typed-tool-errors 2026-11-05 14:27:08 +01:00
Adrià Arrufat 05712604c0 Merge pull request #4315 from coolswood/agent/async-popup-follow
tools: follow a window the action opens late, and a popups tool to list/switch
2026-11-05 11:19:45 +01:00
coolswood 3627f34075 tools: transports read the explained error, and classify's schema admits its real shape
The script runtime's failure text and MCP's in-band evaluate/extract
operational failures both emitted the bare error name even though
errorMessage already carried the recovery; both read it now.

classify accepts questions as a JSON object or array as well as a
JSON-encoded string (its description says so; the Zig param is a
std.json.Value), but its schema typed the field string-only — a raw
object, the form the description leads with, is now legal by
declaration too.
2026-11-04 21:04:36 +02:00
coolswood b33d7711d6 tools: name a wrong-typed argument instead of bare InvalidParams
diagnoseArgTypes compares each argument's JSON type against the type the
tool's schema declares for it and answers in-band — argument 'timeout'
must be an integer, got string "60000" — before parseValue buries the
mismatch in a bare InvalidParams. Unknown keys and fields the schema
doesn't type still pass through to parseValue, and enum membership stays
with diagnoseArgs.
2026-11-04 19:57:45 +02:00
Adrià Arrufat a72392f79e mcp: stream tool output over SSE on the HTTP transport
A POST from a client that accepts text/event-stream is answered with an
event stream once the call sends a notification or outlives the 15s
heartbeat, which then keeps proxies from timing out a silent call. A call
that finishes first still gets one JSON reply, as does any client that
doesn't take SSE.

The run tool reports each console line while the script runs, up to the
same 64 KB cap as the result: as notifications/progress when the call
carries a progressToken, otherwise as notifications/message, filtered by
logging/setLevel. The server now advertises the logging capability. Over
stdio the notifications go out between responses.

The worker hands notifications to the connection thread through the job,
which the connection thread drains until the call finishes. A client that
hangs up mid-stream drops later notifications without blocking the call.
2026-11-04 15:23:35 +01:00
DeryFerd 11a51ea3c5 http: refuse the Fetch bad ports for every request, not just WebSocket
The Fetch standard lists ports a page must never reach (22, 25, 110, 143,
5060, ...). `http.isBadPort` implements that list, but the only caller was
the WebSocket constructor. fetch(), XHR, subresources and navigation all
went straight to the network, so script could probe ssh, smtp, pop3 and the
rest, and Chrome-compatible behaviour differed.

Move the decision into `Client.pipeline`, next to `isUrlBlocked`, so every
transfer inherits it: the initial request, each redirect hop, subresources
and navigations. Internal transfers (robots.txt, the CORS preflight fetch)
are skipped because they are browser bookkeeping, not a page-chosen
destination.

The new `error.UnsafePort` maps to Chrome's `net::ERR_UNSAFE_PORT` through
CDP, so Page.navigate and Network.loadingFailed report what a Chromium client
expects instead of an invented name.

Several fixtures used `127.0.0.1:1` as a guaranteed-refused host. Port 1 is
on the bad-port list, so those now move to `65534` (still unassigned and
still refusing) to keep testing connection failure rather than port policy.
The WebSocket bad-port test keeps `:22`; WebSocket fails before the pipeline.

Tests: a unit test for the URL helper, a fetch() case asserting the promise
rejects, and a CDP errorText case for ERR_UNSAFE_PORT.
2026-11-03 22:52:28 +07:00
Adrià Arrufat 71c94c3743 tools: fix the remaining popup-follow review points
- awaitQueuedNavigation resolves the live frame itself, so no caller hands it
  a frame a runner wait may have freed; settleAction's two drain passes share
  one drainNavigation helper
- awaitLatePopup and settleWatchingPopups are one watchPopups(until, budget),
  keyed on the page root rather than a followed popup's id
- only an explicit popups {follow} outranks the Runtime's per-call frame
  override; a window a click opened no longer moves a script's page handle,
  currentFrame no longer drops a follow on a sibling page, and the lookup
  stays on the override's page
- popups {follow} is not recorded again: its frame id doesn't survive a replay
- jev/login share settleAndFollow; its second settleAction pass is scoped from
  after the first, so a window already followed isn't followed again
- beginAction keeps its main signature; click/press set await_late_popup on
  the scope
- execPopups checks windows via Page.findFrameByFrameId + parent == null
- trim narrative comments
2026-11-02 22:41:36 +01:00
coolswood 6ab9f088e6 tools: answer the async-popup review
- the late-popup watch rides a runner condition (WaitCondition.popups_above):
  the wait ends the moment a window opens, and the runner re-resolves the
  page for the condition every tick, so a navigation committing mid-watch no
  longer leaves the loop reading a freed Page; the 100ms slicing is gone
- settleAction drains the navigation the watch can leave queued, then
  re-resolves the page and re-checks the registry; the navigation wait is
  keyed from a frame resolved at call time, so settling twice around the
  settle fold never dereferences a scope frame a navigation freed
- a cancel during the watch surfaces as ToolError.Cancelled, not a plain
  "Clicked"
- the watch is skipped when the action already navigated the root
- popups {follow} only accepts the page's own windows (an iframe id used to
  pass findFrameByFrameId), and the follow outranks the script Runtime's
  per-call tool frame override
- a follow is recorded after all: the script synthesis must see where the
  session went; the bare listing stays out
- jev and login fold the watch into their settle wait instead of running a
  quiescence watch and a settle wait back to back

Tests: a late navigation during the watch reports the page it landed on; an
iframe id is refused; a cancel stays cancelled; a follow survives the
override. Full suite: 2169 passed, 7 skipped (external TypeSafe service).
2026-11-02 18:50:44 +02:00
Karl Seguin 64c44720ca chore: remove dead code, remove 'pub' where it isn't needed 2026-11-02 10:11:47 +08:00
Karl Seguin 813e0fb32f Merge pull request #4314 from lightpanda-io/mcp-run-path
mcp: run a script file by path
2026-11-01 07:42:24 +08:00
coolswood a2d2b34df0 tools: follow a window the action opens late, and a popups tool to list/switch
A click can open its window late: the handler fetches first (a one-time
download URL), or opens from a timer. settleAction compared the popup
count right after the action, so those windows landed invisible - never
followed, their URL reported nowhere. The follow behavior from #3327
only ever caught windows opened synchronously.

Click-like actions (click, press, login's submit, Jev's click) now watch
for a late window while the page runs out its work, bounded at 1s. A
page already quiescent resolves .done immediately and pays nothing; a
page kept alive by timers or polling pays at most the budget. The other
actions skip the watch: they don't open windows, and they run in loops
where the worst-case cost would compound.

Also add a popups tool: the windows the current page opened
(window.open / target=_blank), main page first, each with id, url and
title. follow=<id> makes that window current - the way back to a window
a late capture missed, and back to the main page. Not recorded in
replays: frame ids are session-scoped, and a replayed action re-opens
the window for settleAction to follow the way the live run did.
2026-10-30 18:32:08 +02:00
Adrià Arrufat 65d79303c8 mcp: run a script file by path
The MCP save tool writes a script on the server, but run only took the
source, so a client had to send it again to replay it. run now also
takes a path, checked with isPathSafe like save's.

The script file helpers move from the agent to lp.script_file, so /save,
/load and the MCP save and run tools read and write scripts the same way.
2026-10-30 16:27:04 +01:00
Adrià Arrufat 6214c50569 js: drop Env.terminate for requestTerminate
Env.terminate took terminate_mutex, which a microtask checkpoint holds
while it runs. Called from another thread while page JS looped after an
await, it blocked until the checkpoint ended: Ctrl-C on lightpanda fetch
hung with a page running (async () => { await null; while (true) {} })(),
and Driver.shutdown could stall the server loop the same way.

Every caller now uses requestTerminate. TerminateExecution then only runs
from the interrupt on the isolate's own thread, so terminate_mutex has
nothing left to guard and goes too. Tests that need the sticky flag set
with V8's state consumed now set terminate_requested directly.
2026-10-30 16:21:27 +01:00
Adrià Arrufat 052eef98e2 script: own cancel and timeout in Runtime
Runtime.cancel stops a run from any thread through V8 interrupts, and
runSource clears both isolates after a cancelled run. A timeout_ms field
starts a deadline that cancels the run, so the MCP run tool no longer
carries its own timer.

The agent's Ctrl-C goes through the same path. It used Env.terminate,
which waits on the mutex a microtask checkpoint holds, so a script
looping after an await could not be stopped.
2026-10-30 16:16:47 +01:00
Adrià Arrufat e4b15c44ec Merge pull request #4041 from jayhemnani9910/feat/mcp-run
mcp: add a run tool for agent scripts
2026-10-30 15:57:48 +01:00
Adrià Arrufat 3be52fad5a agent: rebuild the masked /login line instead of searching it
forModel replaced the parsed password in the line as typed, but typed
as JSON the password can be escaped ("pa\"ss") and then never matched,
so the line reached the model unmasked. The line the model sees is now
rendered from the masked args.
2026-10-30 13:50:42 +01:00
Adrià Arrufat c98a2fa71d agent: mask a literal login password in what the model is shown
With a key set, /login password=hunter2 succeeded and the REPL recorded
the command into the conversation as typed. The line and the args the
model sees now carry [redacted] in its place; the tool still gets the
password.
2026-10-30 12:43:02 +01:00
Adrià Arrufat 8aa6b4a23f browser: record every consent click, and only once the banner went
replay_args carried the last control clicked, whether or not the re-read
agreed it worked: a dismissal that took a confirmation replayed as one
click, and one that failed was recorded as if it had not. The tool now
takes and reports `selectors`, every control clicked in order, and
offers them for replay only when the verification saw the banner gone.
2026-10-30 12:32:00 +01:00
Adrià Arrufat 6d6069a9f3 agent: let bare /login find its credentials
$LP_PASSWORD with $LP_USERNAME or $LP_EMAIL fills in as the tool's
arguments. Without them, no TypeSafe key sends the model the old
discovery prompt, and a key set gets a usage error naming the LP_*
variables, since matching a site prefix to the host is a guess that can
send one site's password to another's form. /help login says so.
2026-10-30 11:14:59 +01:00
Adrià Arrufat 5aa096a1d5 browser: close what the review found in the Jev tools
- copy the page url and title into the ask's state: the helper thread
  serializes them while page JS frees them
- free the response when the page navigated during the ask
- record the identifier step's submit as nextSelector, so a two-step
  replay clicks each step's own control
- check the form's scheme before a replay fills the username
- report what was submitted when the password step's ask fails
- stop before submitting a two-step page without a username, and when
  no selector could be built for the username field
- read classify({ questions: "..." }) as a question named questions
- drop stale and narrative comments
2026-10-30 11:14:59 +01:00
Adrià Arrufat f2798e4b16 browser: cover download and the Jev tools in each other's switches
returnsJson came from this branch and takesPrompt from main, so after the
rebase each was missing the other side's tools. download reports a line,
not JSON. classify takes questions, and login and acceptCookies pick their
own elements, so none of the three reads a prompt.
2026-10-30 11:14:59 +01:00
Adrià Arrufat 0b87798cc0 agent: hand the fallback model the credentials the command was given
Without a TypeSafe key, `/login` falls back to a prompt, and that prompt was
fixed: it dropped the `username` and `password` the user typed and told the
model to discover `$LP_*` names with `getEnv` instead. That cost a turn, and
on a site with several `LP_` sets the model could pick the wrong one. The
prompt is built from the command's own arguments now.

Two cases no longer fall back at all. `decideOnly` promises nothing is typed,
and the model it handed over to typed and submitted. A literal password would
put the secret in the model's context, so only a `$LP_*` placeholder is passed
on. A username is not a secret, so a literal one goes through as typed.

Both fallback prompts also say that `login` and `acceptCookies` need the key.
Traces showed Haiku and flash-lite calling `login` themselves and flash
calling `acceptCookies`, each spending a round trip on the missing-key error.
With both changes the chat arm of the jev-login demo does only the tree,
`nodeDetails`, `fill` and `click` work, and gemini-3.8-flash's median went
from 22.1s to 19.1s.
2026-10-30 11:14:54 +01:00
Adrià Arrufat 26ca756c74 browser: a second simplify pass over the Jev tools
Reuse the browser already has. `linkTarget` resolves through
`Node.resolveURL` and compares origins with `URL.isSameOrigin` plus
`URL.getPathname`, instead of hand-parsing `scheme://host[:port]` and doing
prefix arithmetic on it: the copy printed an absolute URL whenever the page
and the link disagreed on `:443` or carried userinfo. `isTextOnly` goes
through `string.isOneOf`, `Preset.fromString` through
`std.meta.stringToEnum`, and the file's one `std.fmt.allocPrint` becomes
`arena.print`.

`ToolResult` had grown two booleans that each imply `is_error` and each have
one reader; they are one `failure: ?FailureKind` now, so a third kind is an
enum arm rather than a third bool.

Weight with nothing behind it: `App.askTypesafe` relayed five parameters to
a public field for a single caller, `classify` re-exported four zenai names
no other file names, and `renderCompact` was `renderJson` with one option
flipped. `prepareQuestions` takes the `presets` flag itself, so
`execClassify` loses the labelled block it used to carry an error out of.
`Ask` kept its own copy of `jev.StateOpts`' two fields and relayed them
across; it holds the struct. `choose.collect` resolved each candidate's
accessible name twice.

`SemanticTree` had two spellings of "this node carries something of its
own", and the newer one had already drifted: a node whose only content is
`aria-expanded` lost its line in the no-ids tree although `writeTextLine`
would have printed it. One `contentful`, read by both.

The `/v1/systemone` mock no longer falls back to the first option when its
hint matches nothing, so a reworded fixture fails the test that asked
instead of passing for another reason. `login`'s `decideOnly` is in the input
schema, so it is no longer a branch only a test can reach.

Comments: out go the ones that restate the code under them, and the stale one
about dropping cached clients, which the pool now does by itself.
2026-10-30 11:14:54 +01:00
Adrià Arrufat b97f5c592c browser: take the Jev plumbing from zenai
The question DSL and the client pool had no browser knowledge in them, so
they are zenai's now (lightpanda-io/zenai#44).

classify.zig keeps what is actually the browser's: the page presets a caller
can name instead of wording a question, the wording of the category question,
and what an empty questions object means. It goes from 454 lines to 110, and
its question-shape tests move to zenai with the code.

App keeps a zenai.typesafe.Pool rather than its own idle list. The pool is
handed lp.environ rather than a snapshot of it, because setenv can move the
block an Environ points into — and because it retires a client whose
credentials the environment no longer agrees with, the test scaffold no
longer has to drop idle clients around every Jev test.
2026-10-30 11:14:54 +01:00
Adrià Arrufat c2eb9f2792 browser: apply the simplify pass
The mock answers through std.json.Stringify instead of hand-built JSON with
comma flags, keys come from the constants the real code exports rather than
copies of them, and one enum says which of the three request shapes it got
instead of two flags and an inert count guard.

The REPL's two prompt paths share one helper; fromToolCall gets its doc
comment back, which an insert had handed to its neighbour; four identical
error switches become one function; LineCollector drops an allocator field
its tree already carried; and the TypeSafe test preamble, written four times,
is one scaffold beside the test server that owns the port it needs.
2026-10-30 11:14:54 +01:00
Adrià Arrufat 1fff46094e browser: exercise the Jev path of acceptCookies and login
Nothing covered it: every test so far took the no-candidate path or the
recorded-selector replay, and the /v1/systemone mock answered classify's
question names only.

A choice question is keyed by registry node ids, which differ per run, so a
canned body cannot name one. The mock now answers the request it was sent:
each choice goes to the first option whose description mentions what the
question is about, with a probability for every option offered, since an answer
is rejected otherwise. Requests that ask no such question are classify's, which
asserts exact values, and still get the fixed body.
2026-10-30 11:14:54 +01:00
Adrià Arrufat a19ef8b0fc agent: let /acceptCookies and /login fall back to the model
Both tools ask Jev, which needs TYPESAFE_API_KEY. The two commands existed
before the tools did, as prompts the agent loop drove with tree/click/fill, so
that path is still the right answer when the key is not set.

The REPL asks the tool first and falls back on the answer, rather than checking
the key up front: a recorded selector replays without any key, and that path
never reaches the model at all.

Only the REPL falls back. A model client lives on the Agent, so MCP, CDP and
script callers get the tool's own message instead.
2026-10-30 11:14:54 +01:00
Adrià Arrufat a0603fc6a2 browser: clear cookie walls and sign in without a chat model
`/acceptCookies` sent eleven words of prose into a turn that could run 100
model turns and 200 tool calls, with every tool unrestricted, no check that
the banner went away, and nothing recorded: an LlmCommand is not a recorded
command, so what a saved script kept was whatever exploratory findElement and
click sequence the model happened to emit that run. `/login` was the same
shape plus credentials. Neither was reachable from MCP or from a replayed
script, and both needed a provider key.

Clicking one button is a decision among a handful of candidates the page
already shows us, which is the shape the typed-question model is for. So both
become real tools: `choose.zig` offers the candidates as the question's own
options — the model writes no text and the state carries no node ids, so an
option id we mint is the only way it can point at anything — and a mandatory
"none of these" keeps the argmax honest on a page that has none.

`acceptCookies` costs no model call at all when no control is named like a
banner's, one request for the wall gate and the pick together, and one more to
re-read the page: clicking the control and asking again is its own answer key,
which is why this needs no labelled data. `login` leaves to rules what rules
can settle — a password field is `input[type=password]`, and that is the only
place a password is ever typed, whatever the page's text says — and asks only
what the markup leaves open: which of several text fields takes the identifier,
and which control signs in rather than registering or recovering a password.
An unambiguous sign-in page therefore asks nothing before the submit and one
question after it.

Both act only through a selector built before anything is clicked, since the
first click can navigate and free the nodes the rest of the picks point at.
Every decision is asked before a field is filled, so the identifier does not
ride along in the request; passwords are masked in the state either way.

No confidence threshold anywhere: on our own data two consent walls we got
wrong came back at 0.99 while two correct click picks scored 0.73 and 0.64, so
the verification re-read is the gate and the ranked runner-up is the retry.
2026-10-30 11:14:54 +01:00
Adrià Arrufat 7e129656d7 browser: give each concurrent classify its own TypeSafe client
MCP HTTP sessions now run on their own threads, so classify calls can
overlap. App keeps a pool of clients instead of one behind a lock: each
call takes one and puts it back, keeping its connection warm, and an API
error's detail stays with its call.
2026-10-30 11:14:49 +01:00
Adrià Arrufat dec8271e92 browser: let classify ask the presets beside its own questions
`presets: true` (a tool param, and a `page.classify` option in scripts)
adds every preset the questions don't already ask, so a caller triaging a
page gets its walls and its own answers from one TypeSafe call instead of
two. It needs the object form: a category array answers with one choice.
2026-10-30 11:14:49 +01:00
Adrià Arrufat 97b43872f6 browser: use zenai's ErrorDetail for API tool failures
The search tool kept its own copy of zenai.http.ErrorDetail and duped
the message by hand; ErrorDetail.clone does that. The classify tests
take the environment variable names from zenai.
2026-10-30 11:14:49 +01:00
Adrià Arrufat 5ceea2cc88 browser: surface classify API errors and pass questions as values
A failed System One call now names the HTTP status and the API's
message, reusing the search tool's failure formatting. classify takes
its questions as the value itself or a JSON string, so scripts no longer
stringify them for the tool to parse back, and a recorded classify
replays as a JS literal the way extract does. Tool.returnsJson replaces
Runtime's per-tool switch on which results are JSON.
2026-10-30 11:14:49 +01:00
Adrià Arrufat f41338debf browser: simplify classify and send its state as a JSON object
The page state went out as a JSON string escaped again inside the
request body; zenai's Content.json sends it as an object instead.

Drop QuestionSpec: the answer's own type picks how it is written and a
score's labels come from its question. Share one string-array-to-choices
helper, write the response through std.json.Stringify, and derive the
preset aliases and the tool description's preset list from the enum.
2026-10-30 11:11:17 +01:00
Adrià Arrufat 008a23c262 browser: let classify ask score questions
`{question, levels}` asks Jev for a position on 2-10 levels ordered low to
high, its third question type after yes/no and choice. The answer carries
the `score` between level indices, the nearest `level`, and `probabilities`
keyed by level label rather than the index Jev sends.
2026-10-30 11:11:17 +01:00
Adrià Arrufat 5c4399edd8 browser: let an empty questions object ask every preset
`classify` with `{}` now asks all the presets, keyed by name, instead of
failing with EmptyQuestions. Clients that want a page's overall state no
longer have to list isBlocked, isCaptcha, isConsentWall and isEmptyCatalog
themselves, so a preset added here reaches them without a client change.

`questions` stays required: making it optional would cost the REPL its
`/classify [...]` positional and turn recorded calls into the object form.
2026-10-30 11:11:17 +01:00
Adrià Arrufat 9fa923471e browser: stop classify guessing what an array of questions means
An array was presets when every name in it was a preset, and categories
otherwise, so a category list that happened to use only preset names
silently turned into yes/no questions. An array is now always categories;
presets go through the object form, `{isBlocked: true}`, which already
took them.

A missing answer in the object form is now null instead of 0.0, which
read as a confident "no", or an error that failed the whole call.

The skill note says replay calls Jev live and needs TYPESAFE_API_KEY.
2026-10-30 11:11:17 +01:00
Adrià Arrufat 3f3288c9b6 browser: add a classify tool backed by TypeSafe System One
`classify` asks Jev typed questions about the page, or a subtree of it via
`selector`: an array of preset names (isBlocked, isCaptcha, isConsentWall,
isEmptyCatalog) returns their probabilities, an array of other strings
picks one category, and an object of questions returns an answer per key.
It is a slash command in the REPL and `page.classify` in PandaScript.

The TypeSafe client lives on `App`, created on first use and reused across
calls and sessions, so later calls skip the TCP and TLS handshake. Retries
are disabled since the call blocks the browser thread; zenai still
reconnects a pooled socket the server closed while idle.

Bumps zenai for that reconnect.
2026-10-30 11:11:17 +01:00
Adrià Arrufat 4096a2c232 tools: list and call the page's WebMCP tools
Pages register WebMCP tools through navigator.modelContext.registerTool,
but only CDP clients could see or run them. pageTools lists the current
page's tools and callPageTool runs one, so the agent, the MCP server and
scripts can use them too. A navigation result names the page's tools
when it has any.

callPageTool waits for the tool's promise, returns the text of an
MCP-style CallToolResult or JSON for any other value, and handles a
navigation the tool triggers the same way evaluate does. The CDP WebMCP
domain now shares the invoke path through ModelContext.Tool.invoke.
2026-10-29 16:55:11 +01:00
Adrià Arrufat 0a8bb1b6cf tools: stream downloads to disk and share Download's request
The download tool buffered the whole body in memory (twice, between the
transfer and SyncContext) before writing it. SyncOptions gains a
body_writer that the sync context writes each chunk to instead, and the
tool streams into a std createFileAtomic temp file that replaces `path`
only on success.

Download.request/newTransfer hold the request setup that fromHref and
the tool shared by copy, and the tool now uses Download.isSuccessStatus
(200-203, like Chrome), so a 204 no longer saves an empty file.
2026-10-28 12:04:46 +01:00
Adrià Arrufat e4c6b14726 script: download takes no slash prompt 2026-10-28 10:59:13 +01:00
Adrià Arrufat 931713c27b Merge remote-tracking branch 'origin/main' into pr-4193 2026-10-28 10:58:38 +01:00
coolswood 25d6970715 browser: add a download tool
An agent had no way to get a binary response out of the browser: in-page
fetch is CORS-blocked on cross-origin reads, and base64-ing a large body
through evaluate's result channel doesn't scale. download {url, path}
saves a response body to a file with the session's cookies.

The transfer is a frame-owned engine request (frame.newRequest +
submitSync), so it rides the same pipeline as a page load: redirects
followed, --http-proxy and TLS settings applied, --block-urls enforced
on every hop, cookies attached per hop from the session's jar, and
Set-Cookie from every response — redirect steps included — stored back.
The body is buffered and the file written only on a 2xx, so a failed
download leaves nothing behind; failures carry is_error with the HTTP
status.
2026-10-27 13:16:44 +02:00
Adrià Arrufat b5e939b544 agent: keep the full tool list in prompt turns, fewer prompt-parse rules
A narrower tool list changed the cached prefix twice per prompt command;
toolOutcome already refuses non-read tools, now via Tool.group() rather
than a third hand-kept list. PromptTarget holds the parsed Command.Prompt.

A fully quoted prompt keeps its quotes (the model reads them fine), and
hint fragments follow leadingPositionalField instead of a separate flag.
2026-10-27 10:03:53 +01:00