Skip to content

feat(cli): patchy login and patchy logout #142

Closed

Description

@allisonmahmood

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 with os.hostname() and the stored key's id; the agent gate (stdin a terminal, no --json, none of CLAUDECODE, 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 with next and agentNextSteps) and exit 0; resume on a rerun with a live login pending; --complete refusing a foreign code (local, naming the live one), polling at the interval plus five on slow_down, pending after --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 with source: "login" and the machine, forget the pending record, print Logged 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.json entries gain machine: { id, name } for source: "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's hasToken and tokenSource (login, auth-set, null) walk the same chain.
  • patchy logout: delete the stored credential and the pending record first, then POST /api/logout with 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; with PATCHY_API_TOKEN set it warns that the environment token is not its to remove. { ok, instanceUrl, revoked, warnings } under --json.
  • upload, delete, share and whoami with no key: exit 1 local, Run: patchy login. Nothing starts a login on the caller's behalf. What patchy prints 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 --json shapes of login, logout and whoami; the mint-announcement exception goes (under --json, stderr carries failures and nothing else).
  • Skill and docs: the patchy skill's Publishing section (the first run is patchy login then upload; the handoff: show the person the URL and the code, never open a browser, then run next; logout; the sign-in vocabulary the user hears, publishing key for the machine token) and references/onboarding.md (the probe table's tokenSource values; 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 names device-login.json, Onboarding and Onboarding probe follow the new step 3.
  • Packed e2e: patchy login --json against the real server up to the handoff (the document's keys and next), --complete --wait 0 answering pending, logout on the seeded token as a courtesy call, the agent gate under CLAUDECODE=1 on 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; logout when 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 dev up: pnpm patchy login --json returns the handoff in under two seconds; after confirming in a browser, pnpm patchy login --complete prints Logged in to … as Patchy Dev; pnpm patchy whoami names the machine just logged in; pnpm patchy logout prints the seeded-key line and whoami then names the seeded machine again. Outside a worktree, logout then whoami is exit 1 naming patchy login.
  • In a real terminal with the agent variables unset, pnpm patchy login waits and saves the key after the browser confirms.
  • pnpm test, pnpm typecheck, pnpm lint and the packed e2e pass; the skill's hash in skills-lock.json matches.

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.

Blocked by

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:cliarea:docsready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions