Skip to content

feat(auth): setup links tie the agent's fetch, login and key to the person's Final step panel #910

Closed

Description

@allisonmahmood

Part of #906. Stacked on #909.

#909's panel only notices the end of each step: a live machine token of yours, then a publication by one of your tokens. That leaves three gaps:

  • Nothing changes for about a minute after the paste.
  • Any computer of yours counts.
  • The funnel can't be tied to one setup.

A one-time setup link in the copied line fixes all three. Mocks: https://post.patchyhq.com/d/zr16hz72b8gy, "L1".

What changes

The line

  • The panel's line becomes Set up Patchy using <instance>/llms.txt?s=<id>.
  • <id> is at least 128 bits from the platform's CSPRNG, base32, and parsed with a fixed length and alphabet. Anything else is ignored.
  • A person has at most one live link. It is reused across reloads and expires 30 minutes after it was made.
  • Get a new line makes a fresh link and retires the old one. It's a POST that passes RequireSession.sameOrigin, is bound to the signed-in user, refuses a stale account, and is rate-limited per user. Nothing changes on a GET.

Picked up

  • An agent fetching /llms.txt?s=<id> with a live link stamps "picked up", the first time only. The response then prints the login command with --setup <id>.
  • The front door stays a static, plain-text, no-store page. Hosting (apps/server) wires in a narrow callback; the SDK gains no Auth dependency.
  • An unknown or expired id, or any failure in the callback, serves the plain llms.txt without --setup. Setup never breaks; it just isn't live.
  • Pickup stamps are rate-limited by the trusted client address.

Login

  • patchy login --setup <id> sends the id as setupLink on POST /api/login/device.
  • The CLI's pending login. The CLI keeps the setup link in its pending login.
    • A rerun with the same link resumes it.
    • A rerun with a different link, or a link on a pending login that had none, starts a fresh login and abandons the old pending one, saying so in next.
    • ADR-0004 records this.
  • Binding. The first device login started with a live link binds to it. The link stores that login's user code and its outcome; it has no foreign key to device_logins, whose rows are deleted on completion, denial and expiry.
  • A second start with the same link doesn't bind. It marks the link contested, and the second login proceeds as an ordinary login.

Key

  • When the poll mints a machine token for a bound login, the same transaction records the token's id and the user who confirmed it on the setup link.
  • The panel shows connected only if that user is the link's owner. Otherwise the outcome is confirmed by another account.

Outcomes the link keeps

The link keeps one of these: pending, denied, expired, contested, connected, or confirmed by another account. When a poll or the start purge deletes the device login, its outcome is written to the link first, so nothing depends on the deleted row.

The panel's states

Read by #909's owner-scoped /guide/steps, never through DeviceLogins.lookup:

  1. Ready: the line.
  2. Copied: browser only.
  3. Picked up: "Your agent opened the line."
  4. Waiting: a login is bound and pending. "Check your agent: it shows a link and a code to confirm." feat(ui): confirm your computer inside the Final step panel #911 puts the confirm here.
  5. Connected: "You're set. Your agent finishes setup from here. What it publishes shows up on Home."
  6. Live: the first patch version created by this setup's token, created or updated, and current and live. It gets feat(ui): Final step, a panel over Home until your agent is connected #909's live note.
  7. Fallback, for contested, denied, expired, confirmed by another account, or the link expiring before connection: "Finish with the link your agent printed, or get a new line." It has Get a new line. Each outcome gets its own first sentence, so the person knows what happened, but they all share one way forward.

Analytics

  • New business events:
    • setup.line_shown when a link is made;
    • setup.picked_up.
    • They carry a separate random setup id, never the link's value.
  • token.minted gains the setup id when the token came from a bound login.
  • Publications already carry the token id, so the per-person funnel (line shown → picked up → token → first publication by that token) is a PostHog join on the setup id and the token id. Publish events don't need the setup id.
  • The raw link value stays out of logs, wide events and evidence. RequestEvents keeps logging route templates only.

Safety

  • The link value grants no identity and reads nothing. Anyone holding it can only:
    • stamp "picked up";
    • start a login that shows up as pending on its owner's panel.
  • feat(ui): confirm your computer inside the Final step panel #911 decides what that pending login may show.
  • The code check stays the person's own comparison with what their agent displays.

Done means

  • Pasting the line moves the panel to "Your agent opened the line" within a few seconds, and to connected once this setup's key is minted, without a reload.
  • A second login using the same line doesn't bind and leads to the fallback.
  • A key confirmed by a different account never shows as connected.
  • An expired or unknown id, or a failing pickup callback, still sets Patchy up through the plain llms.txt.
  • Rerunning patchy login --setup with a new line starts a fresh login rather than resuming the old one.
  • PostHog shows one person's setup from line shown to first publication, with the time between steps, keyed by the setup id.

Surfaces

  • Migrations: an additive Auth migration, next id in landing order, for the setup links table. Old code ignores it, and the existing device login paths are untouched apart from the outcome write. Show it with the rollback rehearsal.
  • Code:
    • the front door callback and its tests (packages/sdk/src/FrontDoor.ts, apps/server wiring);
    • packages/api: the optional setupLink on startDeviceLogin, with docs/API.md regenerated (pnpm --filter @patchy/api render-docs);
    • the CLI's patchy login --setup and its pending state, with packages/patchy/README.md and ADR-0004;
    • packages/analytics catalogue.
  • Skill and docs:
    • skills/patchy/SKILL.md › Login handoff: run the login command llms.txt printed, --setup included. Refresh skills-lock.json if SKILL.md changes.
    • packages/auth/GLOSSARY.md (setup link) and docs/product.md › device login.
  • Tests:
    • binding, contested, expired, denied, wrong-account mint;
    • the purge writing the outcome;
    • the plain fallback;
    • CLI same-link, new-link and legacy-pending reruns;
    • rate limits.

Activity

  1. added
    ready-for-agent
    area:server
    area:cli
    area:ui
    on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:cliarea:serverarea:uiready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions