Diigo needed devtools spelunking; sketch handing a browser debug capability to an agent that watches, records sanitized fixtures, and writes small deterministic steps behind a policy facet. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
30 lines
2.7 KiB
Markdown
30 lines
2.7 KiB
Markdown
# learn by watching: an agent that finds a site's hidden API
|
|
|
|
social.coop and zotero publish nice APIs. diigo doesn't: for [diigo-cache](../diigo-cache/README.md) we opened browser devtools, watched the requests the web app made, and wrote a client for them by hand ([the mm-diigo diigo-bak scripts](https://github.com/dckc/mm-diigo)). What if a bot did that part?
|
|
|
|
## the workflow
|
|
|
|
1. **I log in, by hand.** Whatever site: diigo, my bank. The password never leaves me; the session lives in the browser.
|
|
2. **I grab a debug capability** on that browser: a [PinchTab](https://github.com/pinchtab/pinchtab) token, or a Chrome DevTools Protocol / WebDriver BiDi endpoint.
|
|
3. **I hand it to a smart coding agent** (e.g. Opus) and say what I'm about to do: "get last month's transactions."
|
|
4. **It watches me** navigate and do the task, recording the proceedings: network requests and responses, plus my clicks.
|
|
5. **It sanitizes the recording** into fixtures for unit tests: cookies, auth headers, account numbers, and names replaced with stand-ins.
|
|
6. **It writes code** that later uses the debug capability deterministically, with no model in the loop, tested against those fixtures.
|
|
|
|
## small steps within a policy
|
|
|
|
The generated code only does small steps, such as `listTransactions({ from, to })` or `bookmarksPage(n)`. More sophisticated code (a scheduler, another agent) can drive them, but the steps themselves must clearly stay within a policy:
|
|
|
|
> I'm only downloading my bank transactions, not paying bills.
|
|
|
|
The policy is code, not a prompt: a facet in front of the debug capability that allows only the requests the recording justified (method + URL pattern, e.g. `GET /accounts/*/transactions`) and refuses everything else. The driver holds only the facet, never the raw capability, so a confused or compromised driver still can't reach `POST /payments`. This is the [governed mower](good-fences-make-good-agents.md) again: I attenuate before I hand it over.
|
|
|
|
Raw CDP is nearly unlimited authority (it can evaluate arbitrary JS in the page), which is why only the watching phase, with me present, uses it directly.
|
|
|
|
## open questions
|
|
|
|
- **Replay or drive?** If the recorded API is plain HTTP, extract the session and replay it with `fetch`, as diigo-cache does; the facet then wraps `fetch`, not a browser. Sites that need in-page JS (anti-bot tokens, signed requests) have to be driven through the browser.
|
|
- **Who reviews the policy?** The agent proposes the allowlist from the recording; I approve it. Is a diff of URL patterns reviewable enough?
|
|
- **Drift:** sites change their private APIs. The fixtures make breakage loud; re-watching should be cheap.
|
|
- **Session lifetime:** the facet is only as durable as the login. Re-login stays manual.
|