Unverified Commit 2da72913 authored by dan's avatar dan Committed by GitHub

[next-dev-loop] Fix cookies (#95177)

The underlying `agent-browser` was flaky about sessions, which is
resolved in https://github.com/vercel-labs/agent-browser/pull/1486. This
bumps the skill to use that version.

## Test Plan

Verified manually that the dev loop skill now doesn't log me out all the
time. I haven't finished the eval run but so far it also looks much more
positive:

<img width="518" height="99" alt="Screenshot 2026-06-25 at 20 59 46"
src="https://github.com/user-attachments/assets/b8f47750-33a1-433c-a086-6f5e8cf4ca00"
/>
parent 1ecbfceb
...@@ -32,8 +32,8 @@ The two views cross-check each other. ...@@ -32,8 +32,8 @@ The two views cross-check each other.
- Next.js **16.3+** with **Turbopack** — `/_next/mcp` plus the - Next.js **16.3+** with **Turbopack** — `/_next/mcp` plus the
proactive compile check via `get_compilation_issues`. proactive compile check via `get_compilation_issues`.
- `agent-browser` **>= 0.30.1** — React introspection plus `wait --url` - `agent-browser` **>= 0.31.0** — React introspection, worktree-scoped
matching full dev-server URLs. `session id`, idempotent `--restore`, and launch flag reconciliation.
These are hard floors, not soft preferences. If anything is missing, These are hard floors, not soft preferences. If anything is missing,
tell the user how to upgrade and stop. Don't fall back to grepping tell the user how to upgrade and stop. Don't fall back to grepping
...@@ -53,28 +53,33 @@ at the versions above. ...@@ -53,28 +53,33 @@ at the versions above.
Once per session, confirm both views are live. Once per session, confirm both views are live.
1. **Open `agent-browser` at the target URL, restoring saved 1. **Open `agent-browser` at the target URL, restoring saved
login state when present.** Build the `open` command from: login state when present.** First derive one stable session id for
- `--session <name>` — you'll reuse this exact name on every later this checkout and use it for every `agent-browser` command:
`agent-browser` command, so make it unique to this checkout and
stable. Build it from a fixed formula so it never varies between ```bash
calls: `"$(basename "$PWD")-$(pwd -P | shasum | cut -c1-8)"`. The SESSION="$(agent-browser session id --scope worktree --prefix next-dev-loop)"
bare basename collides across parallel worktrees or copies. export AGENT_BROWSER_SESSION="$SESSION"
- `--state ~/.agent-browser/sessions/<name>-default.json` if export AGENT_BROWSER_RESTORE="$SESSION"
that file exists. Omit on first run — a missing path fails ```
the open.
- `--headed --enable react-devtools` — always pass both on `open`. Then open the target URL:
A running daemon won't reapply launch flags, so you will often see
`⚠ --headed ignored: daemon already running`; that's expected. ```bash
Assuming you always run the daemon with these flags, you can ignore agent-browser --session "$SESSION" --restore --headed --enable react-devtools open <url>
this warning. Only if you're sure the flags of the running daemon ```
are wrong, you may run `agent-browser close` first, then re-open.
`--scope worktree` keeps parallel worktrees and copied checkouts
The browser is the user's. If state was not restored (first from colliding. Bare `--restore` uses the session id as the
run, expired session) and the page is gated, the user drives persistence key, loads saved cookies/localStorage before navigation
the login — pause until they confirm. Session state is sticky: when present, and auto-saves state on close. Always pass the desired
you can't add `--enable react-devtools` after the session is launch flags on `open`; agent-browser will reuse, relaunch, or restart
open, and `cookies set` on a not-yet-opened session creates a its scoped background state as needed.
sessionless cookie that silently fails to apply.
The browser is the user's. If state was not restored (first run,
expired session) and the page is gated, the user drives the login —
pause until they confirm. After login, continue using the same session
and restore context; `agent-browser close` saves the cookie state so
the next `open` restores it.
2. Probe `/_next/mcp` (`tools/list`) — confirm it's reachable and 2. Probe `/_next/mcp` (`tools/list`) — confirm it's reachable and
lists `get_compilation_issues`: lists `get_compilation_issues`:
...@@ -116,12 +121,12 @@ manual rather than from memory. ...@@ -116,12 +121,12 @@ manual rather than from memory.
## gotchas ## gotchas
- **Every `agent-browser` command must know your session, or it - **Every `agent-browser` command must know your session and restore
silently uses a different, empty default browser (blank reads; a key, or it may use an empty default browser or fail to save login
working page looks broken).** Easiest: `export state.** Easiest: export both `AGENT_BROWSER_SESSION="$SESSION"` and
AGENT_BROWSER_SESSION=<name>` at the top of each shell you run `AGENT_BROWSER_RESTORE="$SESSION"` at the top of each shell you run
agent-browser in; then every command there uses it, with no agent-browser in. If you do not export them, pass
per-command `--session` flag to repeat. `--session "$SESSION" --restore` on every command.
- **When the two views disagree, suspect the tooling first.** If - **When the two views disagree, suspect the tooling first.** If
`agent-browser` says a route is broken but `/_next/mcp` and the `agent-browser` says a route is broken but `/_next/mcp` and the
server say it rendered cleanly, a stale or misdirected browser server say it rendered cleanly, a stale or misdirected browser
...@@ -135,10 +140,11 @@ AGENT_BROWSER_SESSION=<name>` at the top of each shell you run ...@@ -135,10 +140,11 @@ AGENT_BROWSER_SESSION=<name>` at the top of each shell you run
- A blank read, empty snapshot, `about:blank`, or a "no browser - A blank read, empty snapshot, `about:blank`, or a "no browser
session" error — right after `open` or after a click (even if `open` session" error — right after `open` or after a click (even if `open`
reported the page) — is the browser dropping the page (a stale reported the page) — is the browser dropping the page (a stale
daemon), not a broken route. Reopen your session at the URL and session), not a broken route. Reopen your session at the URL with
re-snapshot; if still blank, run `agent-browser --session <name> `--session "$SESSION" --restore` and re-snapshot; if still blank,
close`, then open again. Don't fall back to `curl`; it bypasses the run `agent-browser --session "$SESSION" --restore close`, then open
browser you're testing. again. Don't fall back to `curl`; it bypasses the browser you're
testing.
- React introspection output is stale after navigation. Re-run. - React introspection output is stale after navigation. Re-run.
- `/_next/mcp` replies are SSE — read the JSON off the `data:` line - `/_next/mcp` replies are SSE — read the JSON off the `data:` line
with `sed -n 's/^data: //p'` (a plain `sed 's/^data: //'` leaves the with `sed -n 's/^data: //p'` (a plain `sed 's/^data: //'` leaves the
...@@ -171,10 +177,10 @@ get_compilation_issues Turbopack only; errors on webpack ...@@ -171,10 +177,10 @@ get_compilation_issues Turbopack only; errors on webpack
## teardown ## teardown
Close the session: `agent-browser --session <name> close` — the same Close the session with the same session and restore context:
`--session` every command used. `close` writes that session's state to `agent-browser --session "$SESSION" --restore close`. `close` saves
disk so the next loop's `--state` restores login. Leave `next dev` up that session's cookies and storage so the next loop's `--restore` open
for the next loop. keeps the user logged in. Leave `next dev` up for the next loop.
--- ---
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment