capsite: docs: learn by watching — an agent finds a site's hidden API

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>
This commit is contained in:
dckcandClaude Opus 5.5 committed 2026-10-09 02:45:59 -05:00
1 parent 1d8a220bbc
commit 1fb01b3d55
2 files changed
+31

No files matched your search

+2
View File
@@ -218,6 +218,8 @@ to every goal in this tree.
pattern, abstracted from the E-on-Java sources (bearer secrets, pattern, abstracted from the E-on-Java sources (bearer secrets,
YURL32, secret≠address); the reason ids ride only fragments and POST YURL32, secret≠address); the reason ids ride only fragments and POST
bodies bodies
- [docs/learn-by-watching.md](docs/learn-by-watching.md) — an agent
watches me use a site, then writes policy-bounded code for its hidden API
- [the mm-diigo diigo-bak scripts](https://github.com/dckc/mm-diigo) — - [the mm-diigo diigo-bak scripts](https://github.com/dckc/mm-diigo) —
provenance of the fluent client and dump generator (`projects/diigo-bak/`: provenance of the fluent client and dump generator (`projects/diigo-bak/`:
WebApp.js, diigo-dump.mjs, diigo-interact.mjs; mm-diigo commit 7dbb367, WebApp.js, diigo-dump.mjs, diigo-interact.mjs; mm-diigo commit 7dbb367,
+29
View File
@@ -0,0 +1,29 @@
# 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.