fix(brain): botBrowser keeps a tab per person, one deadline, and never repeats an action

- each asker has a tab and connection of their own (at most 5, least recently used closes first)
- links, forms and window.open that would open a new tab load in the same tab
- one 15 s deadline covers connecting, the action and the page; events do not extend it
- a broken connection retries only open and read; click, type and back may have run and are not repeated
- <<< and >>> in page content are replaced so it cannot close the fence
- the description says how to search on a site (open, then type with submit=true); eval case 0/3 -> 3/3 on qwen3:8b

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-13 22:33:00 +09:00
parent 077db5031c
commit 56212c06dc
5 changed files with 249 additions and 54 deletions

View File

@@ -17,8 +17,20 @@ read it, click a link or button, type into a field, go back. Product rules: `doc
`https://`); `file:`, `chrome:`, `data:`, `javascript:` and the rest are refused. The browser's
own network rules (public addresses only) are the app's proxy's job.
- **Raw data, no LLM call.** The tool returns plain text for the reply model.
- **Bounded.** Each action waits at most 15 s for the page; text is cut at 6,000 characters and the
list of links and buttons at 40.
- **Bounded.** One deadline of 15 s covers an action: connecting, the action and waiting for the
page; events arriving in between do not extend it. Text is cut at 6,000 characters and the list
of links and buttons at 40.
- **A tab per person.** Each asker (`ToolContext.user_id`) has a tab and connection of their own,
so one person's page and numbered list are never another's. At most 5 tabs; the least recently
used one is closed first.
- **One tab, also for "new tab" links.** Before a click or typing, links, forms and `<base>` lose
their `target` and `window.open` loads the address in the same tab, so what opens is what the
tool reads next.
- **Never twice.** When the connection breaks during an action, `open` and `read` are tried once
more on a fresh connection (a fresh tab); `click`, `type` and `back` are not, because they may
already have taken effect: the tool says it may or may not have happened.
- **The fence holds.** `<<<` and `>>>` in anything read from a page become `‹‹‹` and `›››`, so page
text cannot close or reopen the fence.
- **Logs** carry the action and timings, never the address, the typed text or page content.
## Schema
@@ -38,9 +50,9 @@ buttons, all inside the fence. Failures come back as `Error: ...` with `success=
## Backend
`BrowserSession(cdp_url)` speaks CDP over the first page target's WebSocket (`websockets` sync
client): `Page.navigate`, `Runtime.evaluate` (reading, finding and clicking elements),
`Input.insertText` and `Input.dispatchKeyEvent` (typing, Enter). The tool keeps one session per
process and makes a new one when the old one fails. Tests and evals replace `session_factory`.
`BrowserSession(cdp_url, deadline)` opens a tab of its own (`/json/new`) and speaks CDP over its
WebSocket (`websockets` sync client); `close()` closes the tab: `Page.navigate`, `Runtime.evaluate` (reading, finding and clicking elements),
`Input.insertText` and `Input.dispatchKeyEvent` (typing, Enter). The tool keeps a session per person
and makes a new one when the old one fails. Tests and evals replace `session_factory`.
Eval: `evals/test_bot_browser_tool.py`.