Settings saved on the server, live on every device #73

Closed
kayg wants to merge 0 commits from issue/72-prefs into dev
Owner

Closes #72.

Server - new crates/prefs plugin prefs:

  • prefs.get (read-only, all keys), prefs.set {key, value} (mutating, idempotency key; null clears a key), journal event prefs.changed {key, value}.
  • One JSON file per user (users/<id>/prefs.json), written only via fsio::write_atomic. A damaged file is never overwritten.
  • Keys match ^[a-z]+(\.[a-z0-9-]+)+$ (max 80 chars), values up to 4 KB of JSON, at most 200 keys. Errors come from the core catalogue (invalid input 400, too large 413). Setting the same value again is quiet (no event).

Web

  • Prefs load right after sign-in (inside checkAuth) and main.ts waits for that (max 4 s) before mounting, so the saved theme/accent/backdrop are applied before the first paint. Theme application moved into lib/theme.svelte.ts.
  • setPref shows the change at once and writes through prefs.set (toast and revert if it fails). prefs.changed events from the live socket update other devices.
  • Pane widths and the sidebar order stay in localStorage (per device).

Tests

  • Rust: 9 unit/integration tests in crates/prefs (key rules, size cap, 200-key cap, idempotent retry, two clients with live event, restart, no cross-user leak, concurrent saves) and a real-server HTTP test crates/calternal/tests/prefs_live.rs.
  • Playwright (e2e/prefs.spec.ts, chromium-1440): change accent in one page, second page updates live; reload keeps it; a fresh browser gets it; the accent/scheme are set when the app first appears and when the shell first renders (verified the test fails if main.ts does not wait for prefs).

Locally: cargo test --workspace, clippy and fmt clean, bun run check 0 errors, Playwright chromium-1440, chromium-390, flow all pass (WebKit cannot launch on this machine).

🤖 Generated with Claude Code

Closes #72. **Server** - new `crates/prefs` plugin `prefs`: - `prefs.get` (read-only, all keys), `prefs.set {key, value}` (mutating, idempotency key; `null` clears a key), journal event `prefs.changed {key, value}`. - One JSON file per user (`users/<id>/prefs.json`), written only via `fsio::write_atomic`. A damaged file is never overwritten. - Keys match `^[a-z]+(\.[a-z0-9-]+)+$` (max 80 chars), values up to 4 KB of JSON, at most 200 keys. Errors come from the core catalogue (invalid input 400, too large 413). Setting the same value again is quiet (no event). **Web** - Prefs load right after sign-in (inside `checkAuth`) and `main.ts` waits for that (max 4 s) before mounting, so the saved theme/accent/backdrop are applied before the first paint. Theme application moved into `lib/theme.svelte.ts`. - `setPref` shows the change at once and writes through `prefs.set` (toast and revert if it fails). `prefs.changed` events from the live socket update other devices. - Pane widths and the sidebar order stay in localStorage (per device). **Tests** - Rust: 9 unit/integration tests in `crates/prefs` (key rules, size cap, 200-key cap, idempotent retry, two clients with live event, restart, no cross-user leak, concurrent saves) and a real-server HTTP test `crates/calternal/tests/prefs_live.rs`. - Playwright (`e2e/prefs.spec.ts`, chromium-1440): change accent in one page, second page updates live; reload keeps it; a fresh browser gets it; the accent/scheme are set when the app first appears and when the shell first renders (verified the test fails if main.ts does not wait for prefs). Locally: `cargo test --workspace`, clippy and fmt clean, `bun run check` 0 errors, Playwright chromium-1440, chromium-390, flow all pass (WebKit cannot launch on this machine). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Settings saved on the server, live on every device (#72)
All checks were successful
CI / rust (pull_request) Successful in 58s
CI / web (pull_request) Successful in 2m6s
85228a5565
New prefs plugin (prefs.get, prefs.set, prefs.changed) keeping one JSON
file per user, written only with write_atomic. Keys are checked, values
capped at 4 KB, at most 200 keys. The web app loads prefs right after
sign-in and applies them before the first paint, saves through
prefs.set, and follows prefs.changed from other devices. Pane widths
stay on the device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Author
Owner

Reviewed by Claude: prefs plugin with atomic per-user file, validated keys/size caps, idempotent set, prefs.changed live; web applies before first paint (bounded 4 s wait). CI green. Merging and redeploying next.

Reviewed by Claude: prefs plugin with atomic per-user file, validated keys/size caps, idempotent set, prefs.changed live; web applies before first paint (bounded 4 s wait). CI green. Merging and redeploying next.
Author
Owner

Closing: this branch is already fully contained in dev (it landed through a merge train). Branch cleanup, 2026-10-15.

Closing: this branch is already fully contained in `dev` (it landed through a merge train). Branch cleanup, 2026-10-15.
kayg closed this pull request 2026-10-15 08:35:21 +00:00
All checks were successful
CI / rust (pull_request) Successful in 58s
CI / web (pull_request) Successful in 2m6s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal!73
No description provided.