carlos / platform Public

spec: agent login by link (first slice of agent-first onboarding)

Paul's rulings R1 (approve by link with code check), R2 (email code in
any browser), R3 (secrets are the person's choice, later slice).
Builder check folded in as marked calls.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 6a1589609f60e5d462f5b4c2c4fd6f7fe3dcc13d parent 0d55ef8
1 file changed, +197 −0
  • docs/superpowers/specs/2026-11-07-agent-login-link-design.md +197 −0

CI cancelled — superseded by a newer push — run details

diff --git a/docs/superpowers/specs/2026-11-07-agent-login-link-design.md b/docs/superpowers/specs/2026-11-07-agent-login-link-design.md
new file mode 100644
index 000000000..39b54abfe
--- /dev/null
+++ b/docs/superpowers/specs/2026-11-07-agent-login-link-design.md
@@ -0,0 +1,197 @@
+# Agent login by link
+
+Status: draft for Paul, 2026-11-07. First slice of "agent-first onboarding
+and console parity"; the later slices are listed under Non-goals.
+
+## Why
+
+On 2026-11-07 a new Carloku user drove a Claude Code cloud session from a
+phone. Getting that session logged in took him through the console's
+front page, two email round trips, a "Link expired" (fixed in v0.34.21),
+an email code that only works in the browser that asked for it, and
+finally a page titled "Approve a terminal" asking him to type a code he
+had to read out of the chat. He was using Claude, not a terminal, and
+afterwards the console gave him no idea what to do next.
+
+Paul's goal: a person gets a deployed app with as little friction as
+possible. Simplifying login is the first step.
+
+Paul's rulings (2026-11-07, in this session):
+
+- R1. An agent may be approved by following a link that carries its code,
+ after the person checks the code matches the one the agent shows. This
+ deliberately reverses "nothing is approved by following a link"
+ (authcli.go handleCLIApprovePage, auth.go's bare-URI print). GitHub and
+ Google accept the same risk.
+- R2. An emailed sign-in code works in any browser, entered with its
+ address, keeping the per-address guess limits.
+- R3. Secrets are the person's choice: through the agent, or entered on
+ Carloku themselves. (Later slice; recorded here so this slice doesn't
+ close it off.)
+
+## Goals
+
+1. From an agent session, logging in takes taps, not typing: one link,
+ one sign-in if not already signed in, one Approve.
+2. It works when the link, the email and the approval open in different
+ browsers on one phone (the Claude app's in-app browser, Safari, a mail
+ app's viewer).
+3. It works for agents that only see a command's output when the command
+ ends (Claude Code's Bash tool returns output at exit; default timeout
+ 2 minutes, the login lasts 10).
+4. No dead end: after approving, the page says the agent is connected and
+ to go back to it, and offers the next useful place in the console.
+5. The words fit an agent as well as a terminal.
+
+## Non-goals (later slices, separate designs)
+
+- A Carloku MCP connector for Claude chat users.
+- Setting secrets in the console (R3), a first-run "what next" page beyond
+ the approval page's pointer, and the CLI / console / MCP parity table
+ and its guard test.
+- Loopback-redirect login for a CLI on the same machine as the browser.
+- Changing token lifetime, scopes or the revoke page.
+
+## Anti-goals
+
+- A link that approves with no human checking anything. The person still
+ sees the code and what is asking, and still presses Approve.
+- Losing detection: the issuance notice (notifyCLIIssued) and "That wasn't
+ me" stay exactly as they are.
+- Making approval cheaper than a fresh sign-in: the step-up on Approve
+ stays (requireFreshAuth). An email sign-in minutes ago already counts.
+- Codes or tokens in logs, or in any URL other than the user code that
+ `verification_uri_complete` already carries.
+
+## Design
+
+### 1. The CLI prints the link
+
+`carlos auth login` prints `verification_uri_complete` (the console
+already returns it) as the thing to open, and the code as the thing to
+check, not to type:
+
+ Open this link to approve this login:
+
+ https://console.carloku.com/auth/cli?code=WXYZ-4823
+
+ The page will show the code WXYZ-4823. Approve only if it matches.
+
+The comment block in auth.go explaining why the bare URI is printed is
+replaced with the reason for R1 and the controls that remain.
+
+Default label: when the environment shows the CLI is running under an
+agent (Claude Code sets `CLAUDECODE=1`; others can be added), the default
+label names it, e.g. "Claude Code on <host>". `--label` still wins. The
+label stays self-reported and the page keeps saying so.
+
+### 2. A login an agent can relay
+
+Two flags make the wait optional:
+
+- `carlos auth login --no-wait` starts the login, prints the link and
+ code, stores the pending device code beside the credentials file (mode
+ 0600, expires with the login), and exits 0 at once.
+- `carlos auth login --wait` collects a pending login: it polls until
+ approved, denied or expired, then stores the token as today. With no
+ pending login it says so and exits non-zero.
+
+Plain `carlos auth login` keeps today's behaviour (print, then wait).
+`carlos auth login --help` and the docs page for agents say: agents use
+`--no-wait`, show the person the link, then run `--wait`.
+
+Builder's call: whether a second `--no-wait` replaces the stored pending
+login (my call: yes, newest wins), and the exact file name.
+
+### 3. The approval page acts on the code in the link
+
+`GET /auth/cli?code=X`, signed in:
+
+- The code is resolved (it is no longer only echoed). A live, pending
+ request renders the description that today appears only after typing:
+ the code, large; the label with its "supplied by the machine asking"
+ caveat; where it dialled from (IP, plus city and country from the
+ platform GeoIP feed when it has an answer); how long ago it started;
+ when it expires. Then: Approve, and "That wasn't me".
+- The question on the page is the check R1 depends on, in plain words:
+ "Does your agent show this code?" plus "If you didn't just ask an agent
+ or terminal to log in, press That wasn't me."
+- Unknown, expired or already-decided codes say so and show the typed-code
+ box as today (it stays as the fallback for a code read off a screen).
+- Lookups count against the existing wrong-code limiters (per address,
+ per IP) exactly like typed codes, so the page is no better an oracle
+ than the form.
+
+`GET /auth/cli?code=X`, signed out: unchanged. The front page asks the
+person to sign in with next=/auth/cli?code=X. Both the Keymail callback
+and the email link and code already carry next, and since v0.34.21 land
+via `/?next=`, so whichever browser finishes signing in arrives on the
+approval page with the code.
+
+Approve stays a POST with the session's CSRF token and the step-up gate.
+Deny stays ungated.
+
+### 4. Email codes work in any browser (R2)
+
+`POST /auth/email/code` checks the code against this browser's flow first
+(today's rule). When this browser's flow has no live sign-in challenge, it
+checks the newest live sign-in challenge for the address the form carries.
+Everything else stands: 5 wrong codes burn a challenge
+(emailCodeAttempts), 10 wrong codes per address per day, 30 per IP per
+hour, a right code ends the address's other sign-in challenges, and the
+reply still never says whether an address has a challenge.
+
+The check page already carries the address. A browser that never asked
+needs a way to reach a code box for an address: the front page's "Check
+your email" step is reached by asking for an email, which sends a new
+one. Builder's call: add "I already have a code" to the front page form
+(address + code), or rely on the check page plus the any-browser link
+only. My call: add it, because a mail app that opens links in its own
+viewer is exactly where the link fails and the code is the fallback.
+
+### 5. Words
+
+Drafts only; every string goes through copy review when built.
+
+- Title: "Approve a sign-in" (not "Approve a terminal"). Lede: "{label}
+ is asking to use Carloku as you."
+- Front-page banner when next is /auth/cli: "Sign in to connect your agent
+ or terminal."
+- After Approve: "Connected. Go back to {label}; it carries on by itself."
+ Then one link: the person's current account ("Open your apps").
+- After Deny: unchanged meaning, new wording to match.
+- Settings: "command-line access" becomes "agents and terminals".
+
+## Constraints
+
+- Console plus the CLI; no box, edge or root behaviour changes. The CLI's
+ auth.go is in the module-root package, which is inside the census scope,
+ so expect an envelope re-pin needing a cross-family approval on #280
+ (`make census-card` says exactly).
+- Everything works with JavaScript off.
+- Release follows the v0.34.21 pattern: dev console, then flagship
+ console inside a #421 window lock. The CLI change ships in the normal
+ release (tap, apt).
+
+## Test plan (for the builder)
+
+- Approval page resolves a live code from the link and shows the
+ description; Approve issues the token; Deny kills it.
+- Signed-out link → sign in by email link in a second browser → lands on
+ the approval page with the code → Approve works.
+- Wrong or stale codes in the link count against the limiters; the page
+ answers unknown and expired codes the same way the form does.
+- Any-browser email code: a browser with no flow signs in with address +
+ code; wrong codes count per address and per IP; the per-challenge burn
+ still applies; a browser with its own flow still checks its own first.
+- CLI: `--no-wait` exits at once with the link and stores the pending
+ login; `--wait` completes it; plain login unchanged; labels under
+ CLAUDECODE=1.
+- The claim invariant probes (claim_invariant_probes_*) cover the changed
+ routes.
+
+## Left to the builder
+
+File names, flag spellings beyond `--no-wait` and `--wait`, how the GeoIP
+place is formatted, and test structure. Marked "my call" above: newest
+pending login wins; add "I already have a code" to the front page.