Repository navigation
Closed
Labels
wayfinder:prototypeWayfinder ticket: prototype
Description
Question
Build patchy login on a throwaway branch and drive it the way an agent will, so the shape of the handoff can be felt rather than argued. Blocked on How agent-driven CLIs hand off a device login and settles Q1 and Q2 of Device login: the protocol, and the machine token's columns.
What the prototype must let us try:
- The handoff from inside an agent. Run
patchy login --jsonthrough an agent's shell tool. Does the agent get the URL and code to the human before the process exits? Try the shapes the research surfaced (two-step on one command; blocking in a terminal and two-step under--json; blocking with the handoff on stderr) and record what each felt like from both seats. - The URL.
/login/device?code=XXXX-XXXXwith the user code as the lookup key, behind the door from the door prototype (prototype/login-door), with the company and person named from the session and the machine name prefilled from the CLI's hostname. Does the page read as "a machine is being authorised" and nothing else? Does a bare/login/deviceneed to exist? - Deny, expire, and the second run. Press deny; wait out the ten minutes; run
patchy loginagain with a login pending, and again after it completed.
Resolution: which CLI shape, what the URL carries, and the copy of the confirm page, with the branch linked as the asset. The branch is thrown away; the spec carries the decision.
From the research (How agent-driven CLIs hand off a device login, resolved 2026-09-04)
- The two shapes to try in item 1 are now concrete: Stripe's, which blocks for a human at a TTY and otherwise (
--json, non-TTY, or an agent detected fromCLAUDECODE,CURSOR_AGENT,CODEX_*and kin) writes one JSON document and exits 0, withpatchy login --complete <code>polling on the second call; and the always two-step shape from round one on Device login: the protocol, and the machine token's columns #122, wherepatchy loginstarts or resumes on the same command with no mode switch. Both print one JSON document per run naming the next command (Netlify'sagent_next_steps). Try each from an agent's shell tool and from a terminal. - Print the bare code beside the URL even though the URL carries it (Wrangler, Turborepo and Railway do, citing RFC 8628 §3.3.1 and the agent transcript), and persist the device code, interval and expiry to the state dir as Stripe does, so the second call has what it needs.
- Supabase's confirm page is the only open-source copy in the set; the research comment quotes it as the floor for item 2.
Metadata
Metadata
Assignees
Labels
wayfinder:prototypeWayfinder ticket: prototype
Activity
allisonmahmood commentedon Sep 3, 2026
Prototype built; the agent seat is done, the human seat is yours
Asset:
prototype/patchy-login(one commit on top ofprototype/login-door). This worktree's dev instance is up athttp://127.0.0.1:35558with the Clerk dev keys;pnpm devin any checkout of the branch gives you your own. The ticket stays open: the shape and the copy are picks, not findings.What is on the branch
POST /api/login/devicestarts a login (device code, user code, the confirm URL with and without the code, interval, expiry);POST /api/login/device/tokenpolls it (pending/slow_down,completewith the token exactly once, or a 410 sayingexpired,deniedorunknown). Both are admitted by the guard beside the mint and start is per-address limited like the mint. Indocs/API.md.prototype_device_logins(migration 0091). Confirm mints anuploadtoken on the user's company account with the name the person typed, revokes the previous key when it is the same account's (Q4's rule), and the poll that reports the outcome deletes the row./login/device?code=XXXX-XXXX, in three copy variants switched with?v=a|b|cand a bar at the bottom: A leads with the code (Vercel's shape), B with the machine and a receipt table, C with a three-line checklist. Undoored with sample data at/prototype/login/device?v=a(&relogin=1adds the re-login line,&again=1the item-9 notice). Reverse states: denied, expired (410), already answered (410), unknown code (404), bare/login/device.patchy login [--complete [code]] [--wait <s>] [--block],PATCHY_LOGIN_SHAPE=stripe(default) ortwo-step. A login credential outranks the dev env's seeded token sowhoamishows it inside a worktree.scripts/prototype/patchy-login.mjs <deviceUrl> confirm|deny|look [--v b] [--machine NAME] [--delay 70] [--extras]drives the page headlessly as a+clerk_testuser and screenshots every variant.Item 1, the handoff, from the agent seat
I ran every shape through my own shell tool (Claude Code;
CLAUDECODEis set, stdin is not a terminal).Stripe's shape,
--json: one document in 1.4 s, exit 0:{"ok":true,"status":"awaiting_confirmation","verificationUrl":"http://127.0.0.1:35558/login/device?code=HLSS-RDRG","verificationUrlBare":"http://127.0.0.1:35558/login/device","userCode":"HLSS-RDRG","expiresAt":"2026-09-03T22:32:28.782Z","interval":5,"next":"patchy login --complete HLSS-RDRG","agentNextSteps":"Show the person the URL and the code and ask them to confirm it in a browser where they are signed in. Do not open a browser yourself. Then run the next command; it waits up to a minute and says pending if they have not confirmed yet.","notWaitingBecause":"--json"}Stripe's shape, no flag: the agent gate fired on its own (
CLAUDECODE is set), same handoff as text lines plusThen run: patchy login --complete HLSS-RDRG. Then--complete --wait 0answeredpendingwith the samenext; after the browser confirmed,--completeansweredlogged_inwith the machine{ id, name }and the credentials path, andwhoamiprintedAPI token: allison-laptop (tok_…).Blocking (
--block, and the human path under a pty with the agent variables unset): the CLI wrote the handoff at +2 s and sat inWaiting...; my tool call returned at +17 s with everything at once. Same with--json --block, where the handoff rides on stderr and stdout stays empty until the document. From this seat the stream is irrelevant: nothing reaches the agent before exit. Item 1's "blocking with the handoff on stderr" is dead on arrival for an agent, and only the two non-blocking shapes work.Always two-step:
patchy loginstarts,patchy loginagain resumes (Not confirmed yet. The code QMCP-DMVW is good for 10 more minutes. Then run: patchy login). No agent detection needed at all.What told the two apart in practice:
patchy loginwhile one is pending starts a fresh code under Stripe's shape and orphans the old one; under two-step it resumes. The orphan matters: the old page still confirms, and a token minted for a code nobody polls sits in the row until the sweep an hour after expiry.--complete <code>with the wrong code is alocalrefusal naming the live one (has code BFHT-VHMW, not MWQH-TBFW), a cheap check that the agent and the person are talking about the same login.Item 2, the URL
/login/device?code=…survives the door, the Account Portal and the handshake: 4.9–5.1 s and one click from the pasted link to the page, signed out. The page names the company and the person from the session, prefills the machine name from the CLI's hostname (t1ehere) or, on a re-login, the old key's name withReplaces the key named allison-laptop, which stops working when you confirm. The bare/login/deviceis a message page: Open the link your terminal printed. patchy login prints a link that carries its own code, so there is nothing to type here.Item 3, the reverse states
Nothing was logged in. The code MLCL-ZTWL is dead and no key was made.Then--complete:The login was denied in the browser. Nothing was saved. Run: patchy login, exit 2; the previous key is untouched.This code has expired. A login code lasts ten minutes. Run patchy login again…. The CLI refused from its own record without polling (The pending login for … expired. Run: patchy login, exit 1local), thenNo login is pending…on the next call. So the server'sexpiredanswer is only ever reached when the CLI's clock is behind, and the row waits for the sweep.303 POST /login/device→200 GET /login/device?code=…through a refresh handshake, nothing minted, and the person is back on the same page. I added a notice for that return: Your sign-in was refreshed before that went through. Check the code and press Confirm again.Screenshots of every state are under
.local/prototype/in this worktree (r1-confirm-a|b|c,r1-bare,r1-unknown,r2-after-deny,r7-after-confirm).What only you can settle
patchy loginwith a live login pending polls it instead of minting a new code, and--completestays as the explicit, checkable form. That collapses the two shapes to one difference, whether a human waits in-process./prototype/login/device. The ticket wants the chosen page's text in the spec.local(it knew from its own record, no network) orrejected(make it poll so the server says so and deletes the row).Run
pnpm patchy loginin a real terminal for the blocking feel, then from your own Claude Code for the agent one. Prototype gaps, not questions: the token sits on the company account (the branch has no user-owned tokens), nolast_used_at/expires_at, no Your machines, nopatchy logout.allisonmahmood commentedon Sep 3, 2026
Resolution (2026-09-04)
Allison drove the prototype from the human seat and picked; the agent seat's record is the comment above. The asset is
prototype/patchy-login, kept as PR #132, closed unmerged on purpose. The branch is thrown away; this comment and #122 carry the decision.The CLI shape: Stripe's gate, plus resume
patchy loginblocks only for a human at a TTY: stdin is a terminal, no--json, and none of the agent variables is set (CLAUDECODE,CLAUDE_CODE_ENTRYPOINT,CURSOR_AGENT,CODEX_SANDBOX,CODEX_SANDBOX_NETWORK_DISABLED,GEMINI_CLI,OPENCODE,CLINE_ACTIVE,AI_AGENT,CI; the spec owns the list). It prints the handoff, waits until the code expires or the person answers, and saves the key.isattyalone is the wrong gate: an agent's shell tool has a TTY and still sees nothing before exit.expiresAt,interval,next(the command to run) andagentNextSteps(show the person the URL and code, never open a browser, then runnext). Text mode prints the same as lines withThen run: …and one line saying why it did not wait.patchy loginwhile a live login is pending resumes it rather than minting a new code, so an agent that reruns the command never orphans a code the page can still confirm.patchy login --complete [code]is the explicit form: it refuses a code that is not the pending one (local, naming the live one), polls at the interval (plus five onslow_down), and after--waitseconds (default 60) answers{ status: "pending", next, agentNextSteps }, exit 0. Oncompleteit saves the token withsource: "login"and the machine{ id, name }, forgets the pending record, and printsLogged in to <instance> as <company>. This machine is "<name>".rejected. The CLI polls even when its own record says the code has expired, so the server reports it and deletes the row (Allison's pick over a local refusal). Copy:The login was denied in the browser. Nothing was saved. Run: patchy login/The login expired before it was confirmed (codes last ten minutes). Run: patchy login/No login is pending for code XXXX-XXXX on <instance>; it may already have been reported. Run: patchy login.device-login.json, owner-only, one entry per instance) so the second call has what the poll needs. The start request carriesos.hostname()as the machine-name hint and, on a re-login, the stored key's id. A login credential outranks the dev env's seeded token.The URL and the page
/login/device?code=XXXX-XXXX, the user code as the lookup key, behind the door; the code survives the door, the Account Portal and the handshake (one click, ~5 s from the pasted link). The page confirms the code, never asks for it./login/devicewith no code is a message page and nothing more: Open the link your terminal printed.patchy loginprints a link that carries its own code, so there is nothing to type here. If someone sent you here to type a code, don't: that is the trick the link is designed to avoid.Device login. LedeIs this the code on your terminal?, then the code in a large mono headline. Body: A terminal just ranpatchy loginand wants to publish at as (<email>). If the code matches, name the machine and confirm. If you didn't run it, deny: nothing happens. FieldMachine name, prefilled from the CLI's hostname, or on a re-login from the old key's name with Replaces the key named<name>, which stops working when you confirm. ButtonsConfirmandDeny. Foot: The code expires in N minutes. The key it makes works for 90 days, or 30 days unused, and can be revoked any time on Your machines.<machine> is logged in.It can publish and manage patches at as<email>until you revoke it on Your machines. Your terminal already knows; you can close this tab. After deny:Nothing was logged in.The code XXXX-XXXX is dead and no key was made. If you didn't runpatchy login, there is nothing else to do. Expired (410):This code has expired.A login code lasts ten minutes. Runpatchy loginagain on the machine and open the new link it prints. Already answered (410):This code was already used.Unknown (404):Nothing is waiting for this code.Check the link you opened, or runpatchy loginagain…Facts for the spec
Handoff round trip 1.4 s; sign-in plus door to the page 4.9–5.1 s and one click; the confirm page's own hops are one read. Confirm mints the token, revokes the old key when it is the same user's, and stores the plaintext until the poll that reports it deletes the row (the prototype's shortcut; the spec may pick a better hand-off than a plaintext column, but "the row leaves with the poll that reports it" stands). The prototype's tokens sit on the company account; the real machine token is the user's, per #122.
allisonmahmood commentedon Sep 3, 2026
Resolved above; the branch and PR #132 are the asset.