Repository navigation
Description
Parent
Auth: Clerk, companies and machine tokens on tier 0, spec §10.
What to build
patchy login and patchy logout, and the skill that teaches an agent to drive them. An agent runs patchy login, gets one document with the URL, the code and the next command, relays them, and finishes with patchy login --complete; a person at a real terminal runs the same command and it waits. patchy logout forgets the key first and revokes it as a courtesy. The login handoff replaces the mint announcement everywhere an agent reads.
Do
patchy login [--complete [code]] [--wait <seconds>]exactly as spec §10: the start request withos.hostname()and the stored key's id; the agent gate (stdin a terminal, no--json, none ofCLAUDECODE,CLAUDE_CODE_ENTRYPOINT,CURSOR_AGENT,CODEX_SANDBOX,CODEX_SANDBOX_NETWORK_DISABLED,GEMINI_CLI,OPENCODE,CLINE_ACTIVE,AI_AGENT,CI); blocking for a human until the code expires or the person answers; otherwise the handoff (lines or the JSON document withnextandagentNextSteps) and exit 0; resume on a rerun with a live login pending;--completerefusing a foreign code (local, naming the live one), polling at the interval plus five onslow_down,pendingafter--wait(default 60) at exit 0; denied, expired and unknown as the server's answers at exit 2 with the copy from the prototype ticket, polling even when the local record says expired; on complete, save withsource: "login"and the machine, forget the pending record, printLogged in to <instance> as <company>. This machine is "<name>".- State and precedence:
device-login.json(owner-only, one entry per instance: device code, user code, both URLs, interval, expiry);credentials.jsonentries gainmachine: { id, name }forsource: "login". One credential chain for every command (spec §10):PATCHY_API_TOKEN, then the stored credential for the resolved instance, then the dev env's seeded token; so a login outranks the worktree's seeded key.status'shasTokenandtokenSource(login,auth-set,null) walk the same chain. patchy logout: delete the stored credential and the pending record first, thenPOST /api/logoutwith the token just deleted; a 401 is success; unreachable is exit 0 with the warning from spec §10. It removes only the stored credential: inside a worktree it says This worktree's dev instance still publishes with its seeded key; withPATCHY_API_TOKENset it warns that the environment token is not its to remove.{ ok, instanceUrl, revoked, warnings }under--json.upload,delete,shareandwhoamiwith no key: exit 1local,Run: patchy login. Nothing starts a login on the caller's behalf. Whatpatchyprints when a page refuses it stays the door line from the door ticket.- ADR-0004: the line that a command whose local act succeeded reports a failed courtesy call as a warning, never as an exit code; the
--jsonshapes oflogin,logoutandwhoami; the mint-announcement exception goes (under--json, stderr carries failures and nothing else). - Skill and docs: the
patchyskill's Publishing section (the first run ispatchy loginthenupload; the handoff: show the person the URL and the code, never open a browser, then runnext;logout; the sign-in vocabulary the user hears, publishing key for the machine token) andreferences/onboarding.md(the probe table'stokenSourcevalues; step 3 becomes login-then-publish with the words to say; the operator-token path gone);skills-lock.json;packages/cli/README.md(the two commands, the state files, the exit-code examples,whoami);docs/DEVELOPMENT.md's CLI paragraph. Glossary: Publishing's Login handoff rewritten to what ships, Publishing key is the machine token, State dir namesdevice-login.json, Onboarding and Onboarding probe follow the new step 3. - Packed e2e:
patchy login --jsonagainst the real server up to the handoff (the document's keys andnext),--complete --wait 0answeringpending,logouton the seeded token as a courtesy call, the agent gate underCLAUDECODE=1on a pty; the token never in argv or output. - Tests: the gate's truth table; resume; the foreign-code refusal; each terminal answer's exit code and copy;
logoutwhen the instance is unreachable.
Surfaces
The CLI (README, ADR-0004, skill, lock hash); the wire contract (the client of the two device routes and logout); the dev loop (the e2e); vocabulary and product shape; reverse states (logout beside login).
Done when
- From an agent's shell tool in a worktree with
pnpm devup:pnpm patchy login --jsonreturns the handoff in under two seconds; after confirming in a browser,pnpm patchy login --completeprintsLogged in to … as Patchy Dev;pnpm patchy whoaminames the machine just logged in;pnpm patchy logoutprints the seeded-key line andwhoamithen names the seeded machine again. Outside a worktree,logoutthenwhoamiis exit 1 namingpatchy login. - In a real terminal with the agent variables unset,
pnpm patchy loginwaits and saves the key after the browser confirms. -
pnpm test,pnpm typecheck,pnpm lintand the packed e2e pass; the skill's hash inskills-lock.jsonmatches.
Decisions implemented
How agent-driven CLIs hand off a device login; patchy login end to end; Device login (logout, upload with no token, CI out of scope); ADR-0004; spec §10 and §12. The prototype branch prototype/patchy-login has the command and its state file; copy the shape, not the files.
Activity
feat(cli): add login and logout (#142)
feat(cli): add login and logout (#142)