Skip to content

feat: Atomic Chat account — sign-in and remote access (dev builds only) - #410

Open
Vect0rM wants to merge 12 commits into
mainfrom
change/accounts-sign-in
Open

Vect0rM wants to merge 12 commits into
mainfrom
change/accounts-sign-in

Conversation

@Vect0rM

@Vect0rM Vect0rM commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Summary

Desktop client for the new accounts API on api.atomic.chat (atomic-chat-backend PR #1, live since 2026-11-10). People can sign in with an email one-time code or with Google, see their profile and every device signed in, sign a device out, and delete the account.

The whole feature is behind PlatformFeature.ACCOUNTS, which is on in desktop dev builds only. Release builds show nothing new. Turning it on for release will be a separate commit, after a check in the real Tauri window and translations beyond en/fr.

Decision record: docs/decisions/2026-11-10-sign-in-to-an-atomic-chat-account.md.

What's in it

Rust: src-tauri/src/core/account/

  • Rust owns the session, and tokens never cross IPC. The webview gets AccountStatus and token-free DTOs through account_* commands, plus an account-changed event.
  • The session is stored in atomic-account.json in the data folder, mode 0600, written to a temp file and then renamed. This follows the ChatGPT and MCP token files.
  • Refresh is single-flight under one tokio::Mutex. The backend rotates refresh tokens and treats a replay as theft.
    • invalid_grant ends the session.
    • Network and server errors keep the session.
    • A 401 invalid_token triggers one refresh and one retry.
  • Google uses the system browser and a loopback redirect, http://127.0.0.1:<port>/auth/callback.
    • It reuses the MCP sign-in listener. start_callback_server now takes the callback path.
    • We don't use atomic-chat:// because only macOS registers that scheme.
  • Every sign-in sends a client object: desktop, the device name, the platform, the app version, and a random installation_id. The id outlives sign-out, so signing in again replaces this install's previous session.
  • Factory reset signs out first (best effort, 5 s timeout) and removes the session file.
  • ATOMIC_ACCOUNT_API_URL points the app at a local backend. It accepts https, or http on loopback only.

Web app

  • An account avatar in the rail, above Help, opens Account (/account/), a rail section of its own that is lit while open.
    • It has no contextual sidebar yet, so the page takes the full width. Remote access and sync will add rows later.
    • Settings has no Account row.
  • The page offers:
    • sign-in, laid out like the other settings cards: Google's branded button, or an email code with a resend countdown and readable errors;
    • the profile, with display-name editing;
    • devices: Atomic Server sessions are shown as such, and other devices can be signed out. While the list loads, a placeholder row of the same shape holds the card's height, and a repeat visit shows the last list at once;
    • account deletion. When the backend asks for a fresh sign-in, the dialog signs in again and retries only if it is still the same user id.
  • Onboarding: an optional account step in the full flow, after Media and before Purpose, behind the same flag.
    • Three benefit cards (private chat sync, remote access, one sign-in everywhere), then Google and email-code sign-in, built from the onboarding shell's own classes and tokens in both themes.
    • Skip goes on without an account; a signed-in run shows the account and Continue. A sign-in there is reported as onboarding_account_signed_in with its method.
    • The settings card and the step share one sign-in implementation, useAccountSignIn.
    • Decision record: docs/decisions/2026-11-11-give-the-account-its-own-section-and-an-onboarding-step.md.
  • Strings: account and onboarding-account namespaces in en, fr and ru. Other locales fall back to en for now.

Testing

  • Rust: cargo test --lib -- core::account core::mcp::oauth core::app::constants passes (35 tests).
    • The tests run against a fake hyper backend: store and file mode, single-flight refresh, invalid_grant vs. a transient failure, retry after a 401, error mapping, and Google PKCE / state / cancel through the real loopback listener.
    • clippy is clean on the new files.
  • Web:
    • Vitest for the account components, the store, the rail, the settings menu and fr parity: 97 tests.
    • The IPC contract test now lists the 12 account_* commands as desktop-only.
    • Browser layout tests (1024/1280 px, default/XL font, light/dark) pass, including one that the Devices card keeps its height when its row loads.
    • The onboarding step has unit tests (skip, email code, Google, already signed in), step-order tests, and a browser layout test in en and ru: no overflow, sign-in controls as tall as the step's buttons, and errors that do not move the page.
    • Full Vitest (8236 tests) and make verify-fast pass on 9901ab2.
    • The test-quality guard, eslint and prettier are clean.
  • By hand: a dev build of this branch against prod (sign-in, the Account page, the onboarding step).

Remote access through the account

Desktop client for the account backend's remote access API (atomic-chat-backend PR #2, live since 2026-11-11), in both roles, behind the same PlatformFeature.ACCOUNTS flag. Decision record: docs/decisions/2026-11-12-share-and-use-models-through-the-account.md.

Pins core v0.23.0 (AtomicBot-ai/atomic-chat-core#98, release): PUT /atomic/v1/server/client-keys lets the public API accept the device keys next to the server's own key. Checked against the released binary: a device key is refused before the push, accepted after it, refused again once cleared; a stranger's key is refused, a bad body gets 400, and the key never shows in the server state. main (v2.4.5) is merged in, so the branch now carries main's core pin 0.23.4, which includes the route.

Host — Account → Remote models → "Share this computer's models"

  • The switch makes sure the server has its own API key; if not, it generates one after a dialog explaining that local tools need it too. It then starts the server (restarting one that runs without its key) and the tunnel with auto-start, and registers this computer as a host. Off pauses: keys leave the core, the host shows offline, devices keep their grants.
  • "Add a device" opens a 10-minute code with a QR code (atomic-chat://remote/pair?c=…&k=…). The QR secret never reaches the backend. Devices asking with "Connect" show up with a check code and Allow/Deny; a toast with "Review" appears on any page.
  • Each device gets its own sk-atomic-… key, HPKE-sealed to its X25519 key (plus a MAC for code pairings). It also gets a sealed address list (tunnel URL, then LAN URLs), resealed with a higher sequence number when the tunnel URL or LAN changes. Revoke ends one device at once.

Client — "Use models from your other computers"

  • Lists the account's computers. "Connect" asks for access and shows the check code to compare on the host. A code from a host (or a pasted pair link) pairs directly.
  • The key is opened and checked; for a code pairing, a credential whose MAC does not match is refused and revoked, rather than trusted. LAN is preferred when it answers within 1.5 s, else the tunnel; re-checked every 3 minutes.
  • A ready connection becomes a provider " (remote)". It follows the new address or key and lists the host's models. It is read-only on Endpoints and disappears when access ends.

Rust: src-tauri/src/core/account/remote/

  • protocol.rs implements the README protocol. It is checked against vectors from the backend's reference tests/remote_protocol.py, and a one-off run had the Python reference open Rust-sealed values.
  • atomic-remote.json is mode 0600 and bound to the signed-in user: device key, issued keys, received keys, the open code's secrets.
  • Sign-out, a lost session, deletion or a new sign-in wipe what was shared and received; the backend has already ended it.
  • New crates: hpke 0.12, chacha20poly1305, hkdf.

Security fix (ede2dc2, from the review of the same host ported to Atomic Server, AtomicBot-ai/atomic-server#97)

  • The host used to hand a key to any grant the account service reported as approved with a method other than code. A compromised or buggy backend could fabricate an approved request with its own key and get a device key plus the sealed addresses without anyone clicking Allow; a key swapped after Allow was sealed to the new key.
  • Now Allow works only for a request shown by the last sync and first writes an allowed record (grant, device, public key) to atomic-remote.json. plan_host issues to an approved request only when a record matches all three; any other method is denied. Records go once the key is out or the grant ends; end_access clears them.
  • A used pairing code is cleared only after its credential upload succeeded, so a failed upload can retry.
  • Sign-out refreshes through authed() before /v1/auth/logout; a test now pins it.

Web

  • The Account section gets its sidebar back: Overview, Remote models.
  • The Remote models page, the request toasts, and the managed-provider sync (lib/account-remote-providers.ts).
  • Fix (859a624): Refresh on "Use models from your other computers" spins while it reloads the computers and lists every connected computer's models again; a newer address list from the host (endpointsSeq) re-lists them too, even at the same address, so a provider created while its host had no models no longer stays empty.
  • Fix (7846cc7): turning sharing off now ends every device's access (keys out of the core, waiting requests denied, live grants revoked; the host record stays; the page asks first when devices have access), the host shows " disconnected" when a device leaves from its side, and a device shows an offline host (no heartbeat for 90 s, or an empty address list) as "Offline" with one toast instead of "Connected", keeping its provider and re-listing its models when it is back; the ended toast names the host (" ended your access").
  • en/fr/ru strings.

Testing (remote access)

  • Rust: 68 account tests, 44 of them new: protocol vectors, host plan, client step, host/client rounds against a fake backend, store, and status that leaks no key or address. clippy is clean.
  • Live: the opt-in account::remote::live_tests passed against a local backend built from atomic-chat-backend main. Two installs of one account went through QR pairing, key in the core, ack, address, revoke, request + Allow with matching check codes, and device sign-out.
  • Web: unit tests for the page (consent + server/tunnel/sharing order, restart of a keyless server, a failed server, Allow, Revoke, add-device dialog, connect, check code, pairing errors), the store, and the provider sync. Browser layout tests for the page (en/ru, 1024/1280 px, default/XL font, light/dark) caught one overflow, now fixed. make verify-fast passes.
  • Not yet: a run in the real Tauri window, and Mac ↔ Windows over a real tunnel.

How to try it

  1. Build a desktop dev build of this branch. It talks to https://api.atomic.chat by default.
  2. Click the person icon at the bottom of the rail.
  3. Sign in by email code or with Google.
  4. Remote access: on one computer, Account → Remote models → turn on "Share this computer's models". On a second desktop signed in to the same account, click Connect and allow it on the first, or type the code from "Add a device". The first computer then shows up as a provider " (remote)".
  5. For the onboarding step, run FORCE_ONBOARDING_VARIANT=full make dev-fresh and go on past Media. Ctrl-C and FRESH_INSTALL=true FORCE_ONBOARDING=true FORCE_ONBOARDING_VARIANT=full yarn dev replays it.

🤖 Generated with Claude Code

Vect0rM and others added 4 commits November 10, 2026 15:43
Desktop client for the accounts API on api.atomic.chat: sign in with an
email one-time code or Google, see the profile and the devices signed in,
sign a device out, and delete the account.

- Rust owns the session (src-tauri/src/core/account): tokens never cross
  IPC, live in atomic-account.json (mode 0600, written via temp + rename),
  refresh is single-flight, invalid_grant ends the session, network errors
  keep it, and a 401 refreshes once and retries.
- Google signs in through the system browser and a loopback redirect
  (127.0.0.1/auth/callback) on the MCP sign-in listener, which now takes
  the callback path as a parameter.
- Each sign-in sends a stable installation_id that outlives sign-out, so
  signing in again replaces this install's previous session.
- Factory reset signs out first and removes the session file.
- UI: an account avatar above Help in the rail opens Settings -> Account
  (sign-in, profile, devices, delete with re-auth that checks the user id).
- Gated by PlatformFeature.ACCOUNTS: desktop dev builds only for now.
- ADR: docs/decisions/2026-11-10-sign-in-to-an-atomic-chat-account.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The account no longer lives under Settings. The rail avatar opens
/account/, a section of its own that is lit while it is open. It has no
contextual sidebar for now, so the page takes the full width and the
sidebar toggle is hidden there. Remote access and sync will add rows
later. Settings drops its Account row, and the route moves from
/settings/account to /account/.

The account page reads like the other settings cards:
- sign-in is laid out in rows, with Google's own branded button;
- Google stays offered unless the backend says it is off;
- the profile card no longer lists sign-in methods.

The Devices card no longer jumps on load:
- the loading state is one row shaped like a device row (this device is
  always listed), with the same line heights;
- the last list is kept in the account store for the signed-in user, so
  a repeat visit shows it at once and refreshes it in place;
- a layout test checks that the card keeps its height when the row loads.

Also fixes a flaky device-order test whose fixtures tied on new Date().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The full first-run flow gets an optional `account` step after Media and
before Purpose, so it serves both everyday use and the server path. It
is gated by the accounts flag; the experiment's model_only and none
variants are unchanged.

The step is built from the onboarding shell's own pieces and tokens, in
light and dark:
- three benefit cards: private chat sync, remote access, one sign-in
  everywhere;
- Google and email-code sign-in in one row, with controls as tall as the
  step's buttons at any font size;
- a reserved message line, so errors never move the page;
- a signed-in card;
- Skip or Continue, as on the Cloud and Media steps.

The Google and email-code logic moves from AccountSignIn into a shared
useAccountSignIn hook, so the settings card and the step behave the same.
A sign-in on the step is reported as onboarding_account_signed_in with
its method.

Strings: onboarding-account in en, fr and ru, plus Russian for the whole
account namespace. The session-lost toast no longer points at
Settings -> Account.

Recorded in docs/decisions/2026-11-11-give-the-account-its-own-section-and-an-onboarding-step.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Desktop client for the account backend's remote access API, in both roles.

Host ("Share this computer's models"): registers the device and the host,
long-polls host sync as a heartbeat with the tunnel and LAN state read from
the core. It honours a code pairing only when the device's proof matches the
code or the QR secret it showed, and a request only after "Allow" with
matching check codes. Each device gets its own key for the public API, sealed
with HPKE to the device's X25519 key (plus a MAC for code pairings), and a
sealed address list that is resealed with a higher sequence number whenever
the tunnel URL or LAN changes. Keys of grants that end leave the core at once.

Client ("Use models from your other computers"): long-polls its grants, opens
the key, refuses one whose code-pairing MAC does not match, acknowledges it,
follows newer address lists, and prefers a LAN address that answers. A ready
connection becomes a read-only "<computer> (remote)" provider.

- Rust `core/account/remote/`: protocol (checked against the backend's
  reference vectors both ways), API client, 0600 `atomic-remote.json`,
  host and client rounds, background loops, `account_remote_*` commands and
  events. Sign-out, a lost session, deletion or a new sign-in wipe what was
  shared and received.
- New crates: hpke 0.12, chacha20poly1305, hkdf.
- Device keys reach the core through `PUT /atomic/v1/server/client-keys`
  (atomic-chat-core PR #98); sharing requires the server's own key and
  generates one with consent.
- Web: Account sidebar is back (Overview, Remote models); the Remote models
  page; request toasts on any page; managed providers kept in step; en/fr/ru.
- An opt-in live test runs two installs of one account against a real API.

Decision record: docs/decisions/2026-11-12-share-and-use-models-through-the-account.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Vect0rM Vect0rM changed the title feat: sign in to an Atomic Chat account (dev builds only) feat: Atomic Chat account — sign-in and remote access (dev builds only) Nov 12, 2026
Vect0rM and others added 4 commits November 12, 2026 14:07
Core v0.23.0 adds `PUT /atomic/v1/server/client-keys`
(AtomicBot-ai/atomic-chat-core#98): the public listener accepts the keys a
sharing computer hands its paired devices, next to its own API key. Without
it, remote access through the account answers those devices with 401.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	package.json
#	web-app/package.json
#	yarn.lock
Vect0rM and others added 3 commits November 13, 2026 12:35
…uter

The remote access host handed a key to any grant the account service
reported as approved with a method other than code. A compromised or
buggy backend could fabricate an approved request with its own public
key and get a device key and the sealed addresses without anyone
clicking Allow, and a key swapped after Allow was sealed to the new key
although the check code covered the old one.

- atomic-remote.json keeps `allowed` records: grant, device, public key.
- Allow works only for a request shown from the last sync and writes the
  record before calling approve.
- plan_host issues to an approved request only when a record matches
  grant, device and key; any other method is denied.
- Records go once their key is out or their grant is no longer pending
  or approved; end_access and removing this host clear them.
- A used pairing code is cleared only after its credential upload
  succeeded, so a failed upload can retry.
- Sign-out already refreshes through authed(); a test now pins that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a newer address list

A remote provider created while its host served no models kept an empty
list: starting a model on the host changed neither the address nor the
key, so no connections event came and the provider stayed hidden from
the model picker. The refresh button on "Use models from your other
computers" only reloaded the list of computers, with no sign of progress.

- Refresh spins and is disabled while it runs; it reloads the computers
  and re-lists every connected computer's models
  (`syncAccountRemoteProviders(..., { refreshModels: true })`), keeping
  the one-at-a-time queue.
- Provider connections carry the host's address list number
  (`endpointsSeq`). A newer list is announced even at the same address,
  and the provider sync lists that host's models again.

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

Stopping sharing on a host only paused it: grants stayed active, so the
devices kept saying "Connected", and a host that stopped kept showing as
connected on the device.

Host (this computer shares):
- Turning sharing off ends every device's access: keys leave the core
  first, a waiting request is denied, and every other live grant of
  this host is revoked (revoked_by_user). The host record stays, so no
  new "new computer" email. The page asks first when devices have access.
- A device whose access ends from its side (Disconnect, sign-out, a
  revoke elsewhere) raises "<device> disconnected" once
  (account-remote-device-left). The host's own revoke or stop does not.

Client (this computer uses another's models):
- The grant read's host.online is kept per connection. An offline host,
  or one that sent an empty address list (its server stopped), reads
  "Offline" instead of "Connected", with one toast when it goes. The
  provider stays and lists the host's models again when it is back.
- A host that ends this device's access is named in the toast
  ("<host> ended your access").

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