Skip to content

feat: accounts, workspaces and machine connect through the relay - #171

Open
sanchitrk wants to merge 22 commits into
canaryfrom
feat-oauth-clerk
Open

sanchitrk wants to merge 22 commits into
canaryfrom
feat-oauth-clerk

Conversation

@sanchitrk

@sanchitrk sanchitrk commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Milestone 1 of CodeWork's cloud identity: people sign in, belong to workspaces, and connect their machines to them through a new relay service.

Relay (infra/relay, packages/schema)

  • Effect HTTP API at relay.codework.sh with Clerk sign-in. Accounts are keyed on the Clerk subject (email is display only); a new account gets a default workspace, and people can create more.
  • Machine links are confirmed by the machine. A machine registers its own key per workspace and shows a code. A member approving the code only marks the pairing; the link goes live when the machine's next poll, signed with that key, takes it. Other connects for the same machine are superseded, and a connect that stops polling drops out of Waiting to Join after 20 s, so an abandoned code can never replace a working link.
  • Signed JWS for every machine request (pair, poll, heartbeat, revoke), bound to its operation; revoke is replay-protected.
  • Members list pending connects, approve or decline them (the CLI is told it was declined), and list machines with online state. A machine's owner or a workspace owner/admin can remove it; the machine forgets the link on its next heartbeat, but only while it still holds the refused key.
  • 503 when the sign-in vendor is unreachable (token check or a first visit's profile), 401 only for tokens it refuses. Workspace and machine ids are checked at the wire.
  • Postgres via @effect/sql-pg, code-first migrations. Runs on Node against the compose Postgres; the production deploy is a follow-up.

CLI (packages/codework)

  • codework connect [--workspace <id>] [--machine-id <id>] and codework disconnect. Links record the relay they were made with, and heartbeat/disconnect go there. Polls retry through transient failures; heartbeats run in parallel with a timeout. connect names a bad or unknown workspace, an unreachable relay, and how to start the server when none runs.
  • machine.info, machine.rename, machine.connect and machine.disconnect on the server RPC (disconnect reports whether the relay confirmed), mirrored in the widget and app contracts.

Desktop (apps/web, apps/desktop, apps/server)

  • Sign in with Clerk inside the app, pick or create a workspace, Profile settings.
  • Setup page: install the CLI, start its server, connect this machine; opened once per sign-in when this machine isn't set up for the workspace. Terminal commands carry --workspace and, for a home chosen in Settings, --home.
  • Settings → Machines: this machine's name and id; Waiting to Join with Approve/Decline (machine id shown, replacements marked, approved ones show Connecting…); Enter a Code Instead; the workspace's machines with Disconnect/Remove. A row with this machine's id under a key it doesn't hold can be removed; disconnect falls back to removing it when the relay can't confirm.
  • Connection status slot in the sidebar footer: Offline, Can't Reach CodeWork, Sign-In Unavailable or Signed Out, with Reconnect; it retries on its own. The account is remembered on the device and the machine list keeps what CodeWork last said while it can't be reached.
  • Linear-style light theme, Lilex mono, readable install/start/connect errors, a shared Collapse.

Testing

  • Relay E2E (infra/relay/test, real relay on Docker Postgres + real CLI + a Clerk test user): sign-in and default workspace, re-signup with a known email, the sign-in vendor down, pair → heartbeat → disconnect, a forged heartbeat, decline, a code typed without its dash, remove, an abandoned connect approved late, two competing connects, a second relay, and bad workspace ids. Artifacts in infra/relay/test/__artifacts__/.
  • Exercised in the Electron app against the local relay: sign-up and setup, two workspaces on one machine, approve/decline/manual codes, remove and stray rows, the relay and the sign-in vendor going away and coming back, the installer offline, and a real session (Kimi K3 via GitHub Copilot) on a project.
  • vp check, vp run typecheck and vp run knip:check pass.

Not in this PR

Production deploy of the relay and Clerk production instance, local listener auth, pairing hardening (fingerprints, rate limits, owner on replace), offline revocation retry, stale-lock recovery, invites and member management, and scoping machine data by workspace.

🤖 Generated with Claude Code

sanchitrk and others added 17 commits November 17, 2026 13:56
The relay is the cloud API for accounts, workspaces and machines. This first
slice verifies Clerk session tokens and serves GET /v1/me, which creates the
account and its default workspace on first sight, exactly once even under
concurrent first calls. Postgres runs locally from compose.yaml; the E2E
suite boots the real relay against it with a real Clerk test user.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds @codeworksh/schema, a private package bundled into its consumers, holding
the relay API and Ed25519 request signing shared by the relay and the CLI.

The relay gains machine links, pairings and replay-guarded assertions:
machines pair with a key they generate, a workspace member approves the code,
and later requests are signed with that per-workspace key. Heartbeats keep a
90-second online lease; a machine can revoke its own link.

The CLI gains `codework connect` and `codework disconnect`, keeps its identity
and links in <home>/machine.json, and `codework serve` sends heartbeats for
every connected workspace without ever blocking local work.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The desktop app now requires a signed-in account. Clerk's Electron bridge
registers the renderer scheme (now codeworkdev://app for unpackaged runs),
keeps the session encrypted under the app's data folder, and the renderer
gates the app behind Clerk's sign-in. When Clerk is unreachable the app still
opens, so local work never waits on the cloud.

Once signed in, the sidebar shows the account's workspaces from the relay and
remembers the one picked. The relay allows CORS from the desktop origins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The CodeWork RPC gains machine.info, machine.rename and a streaming
machine.connect, whose shapes live in @codeworksh/schema and are shared by
the codework contract, the widget mirror and the app contract.

From the workspace menu the desktop connects this machine (it shows the code
and approves it as the signed-in member) or approves a code another machine
printed with `codework connect`. Settings > Machines lists the workspace's
machines with their online status from the relay, and names this machine;
a rename reaches the relay with an immediate heartbeat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When no codework is found, Settings > Providers offers Install CodeWork. The
app server runs the same script as `curl -fsSL https://codework.sh/install | sh`
into the install folder, without touching the shell's startup file, then
starts the local server. Development and canary builds install the newest
development build. CODEWORK_INSTALL_SCRIPT points it at another script.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clicking Sign up sent the window to Clerk's hosted Account Portal, which
cannot return to an Electron window. Sign-in and sign-up now render in the
app on their own paths, and Clerk navigates between them and their steps
through the app's handlers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
POST /v1/workspaces creates a workspace the signed-in person owns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- /workspaces/join: a full-window page to name and create a workspace; the app switches to it.
- The workspace menu holds Settings, Invite & Manage Members (disabled until invites), Switch
  Workspace and Sign Out; it stays as CodeWork while the relay is unreachable. The sidebar's
  Settings link is gone.
- Connect This Machine and Approve a Machine move to Settings > Machines.
- Menu rows highlight at once and fade out over 150ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clerk is briefly not loaded while it signs out, after the splash is gone; the sign-in backdrop
holds the window, and signing out goes straight to the sign-in page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Settings groups pages under Personal, Application and Workspace; Personal > Profile, at
  /workspaces/<id>/settings/account/profile, edits the picture and name.
- Light theme follows Linear's palette; primary actions use the indigo accent.
- Primitives follow Linear: settings page and cards, 28px inputs (44px large), 32px pill and 28px
  compact buttons, 32px menu rows with a soft shadow, sidebar rows and headings, the main panel.
- Lilex is the mono font (ligatures only in code blocks); Inter uses optical sizes; descriptions
  use a 450 weight.
- dark: styles follow the app theme, not the system's.
- Fix: opening Create a Workspace no longer crashes or bounces home while its page loads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- GET /v1/workspaces/:id/pairings lists connects started for the workspace, with their codes.
- POST /v1/pairings/decline expires a pending code.
- POST /v1/workspaces/:id/machines/:machineId/remove revokes a machine; its owner or a workspace
  owner or admin may.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Settings > Machines moves to /workspaces/<id>/settings/machines under Administration: machines
  waiting to join with Approve, Decline and Approve All; Enter a Code Instead; the machine list with
  Disconnect for this machine and Remove for others; placeholders while loading.
- machine.disconnect leaves a workspace from the app.
- The account retries while the relay is unreachable instead of staying failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- relay: declining a connect sets a declined status (new migration), so the
  CLI says it was declined instead of expired; approve and decline accept a
  code in any case, with or without its dash
- cli: connect explains an unreachable relay instead of a transport error;
  the server sends a heartbeat right after a connect so the machine shows
  online at once
- desktop: setup opens once per sign-in, not once per launch; Machines
  re-reads this machine's links while they disagree with the relay; relay
  failures read as "Can't reach CodeWork's servers"; pending rows and menus
  name the machine id; setup's connect command names the workspace and its
  copy uses one product name
- relay E2E covers decline, a typed code and removing a machine

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…atus slot

Relay and machines:
- a link goes live only when the machine's next poll, signed with the new
  key, takes it; approval just marks the pairing, sibling connects are
  superseded, and a connect that stops polling drops out of Waiting to
  Join after 20 s, so an abandoned code can never replace a working link
- links record the relay they were made with; heartbeat and disconnect go
  there, and a refused link is removed only while it still holds the
  refused key
- accounts are keyed on the auth subject alone; email is display only, so
  signing up again with a known email works
- the relay answers 503 when its sign-in vendor is unreachable and 401 only
  for tokens the vendor refuses
- workspace and machine ids are checked at the wire; connect names a bad
  or unknown workspace plainly
- polls retry through transient failures; heartbeats run in parallel with
  a timeout and log refusals

Desktop:
- one status slot in the sidebar footer: Offline, Can't Reach CodeWork,
  Sign-In Unavailable or Signed Out, with Reconnect; it retries on its own
- the account is remembered on the device, and the machine list keeps
  what CodeWork last said while it can't be reached
- a row with this machine's id under a key it doesn't hold can be
  removed; disconnect falls back to removing it when the relay can't
  confirm
- Approve All is gone; approved connects show Connecting…, replacements
  are marked
- a shared Collapse clips only while it moves, so Enter a Code Instead
  opens without jitter or a cut-off focus ring

E2E covers abandoned and competing connects, a second relay, re-signup,
the sign-in vendor down, and bad workspace ids.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…visit

- codework connect says how to start the server when none runs for the
  home, with --home when one was given
- Setup's terminal commands carry --home when the server's home was
  chosen in Settings
- the relay answers 503, not 500, when its sign-in vendor can't give a new
  person's profile on their first visit
- the connect E2E normalises the temp home in its artifacts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sanchitrk
sanchitrk changed the base branch from main to canary November 18, 2026 11:08
sanchitrk and others added 4 commits November 18, 2026 18:33
The page body had become max-w-27 (108px), squeezing every card into a strip. The header, loading
skeleton and body now share one container token, so their widths cannot drift apart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dark takes Linear's dark palette through the theme tokens: its border and text scale, indigo accent
and primary buttons, full-strength focus rings, hairline field borders, lighter row selection and
its status colours. Destructive buttons stay solid red in dark. Light is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A CLI that fails to run, or a server this app can't read, now replaces the step's line in the
error colour, matching the step's other errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant