Skip to content

prototype(cli): patchy login end to end (#131) - #132

Closed
allisonmahmood wants to merge 11 commits into
mainfrom
prototype/patchy-login
Closed

allisonmahmood wants to merge 11 commits into
mainfrom
prototype/patchy-login

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Prototype for #131, closed unmerged on purpose: the branch is the primary source for the device-login decision and the spec carries what was decided. Stacked on the login-door prototype (#127, also closed unmerged).

The question. patchy login prints a URL and a code that an agent relays to a human, then receives a machine token. An agent's shell tool waits for the process to exit, so a login that blocks never gets its URL in front of anyone. #130 narrowed the shapes to two; this builds both so the handoff, the confirm page and the reverse states could be felt rather than argued.

What it builds. Two unauthenticated routes (POST /api/login/device, POST /api/login/device/token), a device-login table and service that mints the machine token on confirm and hands it out exactly once on the poll, the confirm page behind the door in three copy variants (?v=a|b|c, undoored at /prototype/login/device), every reverse state (deny, expired, answered, unknown, bare, the #122 item 9 bounce), and patchy login in Stripe's shape and the always-two-step shape (PATCHY_LOGIN_SHAPE). scripts/prototype/patchy-login.mjs drives the page headlessly.

What it found is on #131: from the agent seat only the non-blocking shapes work, whatever the stream; the URL with the code survives the door and the portal in one click; deny, expiry, re-login and the stale-session bounce behave as #122 decided.

Made by Claude Fable 5.1 in Claude Code.

allisonmahmood and others added 11 commits September 2, 2026 20:58
Throwaway prototype for the login-door ticket. Every /d/* page (and two
door-only routes, /login/device and /sign-out) now sits behind route-scoped
router middleware that hands the request to @clerk/backend's
authenticateRequest, copies Clerk's headers back, redirects for the
handshake, shows a script-free door page when signed out, and matches the
Clerk user to a prototype_users row (migration 0090, just-in-time into
acct_dev) before serving with private, no-store caching.

ClerkSession.prototype.ts is the Effect service over the SDK; it builds
without keys so the server boots and the door fails closed. It wraps
globalThis.fetch to log every outbound call as [clerk-net], and the door
logs one [door] line per request with the verdict, timings, network count
and the Set-Cookie attributes Clerk returned (values redacted). The dev
runner forwards every CLERK_* key from dev.env plus PROTOTYPE_DOOR_MODE.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…119

node scripts/prototype/login-door.mjs <patchUrl> walks the whole trip a
person makes: the pasted link to the door page, the Account Portal sign-in
with a +clerk_test address and code 424242, and back to the served patch,
recording every main-frame hop with its status and Set-Cookie attributes,
the cookie jar, and the [door]/[clerk-net] lines from dev.log. --wait N
reloads after N seconds, --sign-out exercises the device page and the
sign-out form, --print-jwt-key derives CLERK_JWT_KEY from the JWKS.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…edirects, in-memory router (#119)

Seven offline tests over the login door prototype: a session signed by an RSA-2048 test keypair verifies through CLERK_JWT_KEY with no network and the door serves it; a hand-built fetch client on redirect: manual sees the SDK's handshake 307, its Location and the __clerk_redirect_count cookie; HttpRouter.toHttpEffect with HttpServerRequest.fromWeb drives the door in memory; HttpClient.withCookiesRef carries the loop-guard cookie across hand-driven hops until the SDK gives up; an expired session handshakes only a document GET and sign-out still expires every Clerk cookie while the BAPI revoke fails offline; and a pk_live_ key answers a cookie-less document GET with the door where a pk_test_ key handshakes.

The fake instance, keypair, session signing, fetch guard and acct_dev seed live in @patchy/auth/testing so the other suites can be put behind the same door.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…uites green (#119)

Pages.test.ts and the server's booted-whole test broke when the door went in front of /d/*: ClerkSession was not provided in one and the door failed closed with a 503 in the other. Both now take the offline instance's keys through their ConfigProvider, seed acct_dev for the door's just-in-time user row, and send a signed-in reader's cookies; a doored page is private, no-store, so the cache expectations follow.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…RL comment tells the truth (#119)

Three corrections from the review round, so the branch reads as a true
primary source for the real door:

- `__clerk_handshake` and `__clerk_handshake_nonce` join what `/sign-out`
  expires, plain and suffixed. Nothing else clears them and the payload is a
  standing `__session` directive, so a browser that kept the cookie was
  signed in again on its next document GET. T8 now asserts the 303 expires
  the pair and the next GET is the door.
- The comment over the Web `Request` claimed the SDK builds the handshake's
  `redirect_url` from the public URL. It does not: `deriveUrlFromHeaders`
  rebuilds the origin from `X-Forwarded-Host` / `Host` and
  `X-Forwarded-Proto`. The comment now says so, and says the real door has
  to pin those headers from `publicBaseUrl` too.
- The door CSP gains `img-src data:` so the shared shell's grain is not
  blocked on door pages.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…what did not happen (#119)

Copy only, from the review round. The device done page said the machine
"was confirmed", but the POST only logs the choice and mints nothing. The
outsider lede said the account "is not part of the company this patch is
shared in", which is the wrong-company state; the page is the no-company
one, whose product answer is create or join.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Throwaway, on top of the login-door prototype. Device login on the wire
(POST /api/login/device, POST /api/login/device/token), a device-login
table and service that mints the machine token on confirm, the confirm
page behind the door in three copy variants (?v=a|b|c, and undoored at
/prototype/login/device), its reverse states (deny, expired, answered,
unknown, bare), the item-9 bounce back through the door, and patchy login
in both shapes the research surfaced: Stripe's (block for a human, one
JSON document plus --complete otherwise) and always-two-step
(PATCHY_LOGIN_SHAPE=two-step). scripts/prototype/patchy-login.mjs drives
the confirm page headlessly.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area labels Sep 3, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Closed unmerged on purpose: a prototype, kept as the primary source for #131's decision. The branch stays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area area:server Touches the server area size:l 501-1,000 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant