Commit graph

304 commits

Author SHA1 Message Date
Jon Seager
de3e1d4bcb
fix(nix): add openssl build inputs for webauthn-rs
webauthn-rs-core unconditionally depends on openssl for X.509 and
signature verification. Add pkg-config and openssl to the nix build
so the package builds in the sandbox.
2026-02-05 12:34:57 +00:00
Jon Seager
149921dc31
refactor(account): simplify backup/restore with native download link
Replace the blob URL download JS with a Content-Disposition header on
the export endpoint and a plain <a> tag. Consolidate restore JS from
event listeners into a single global function.
2026-02-05 12:27:17 +00:00
Jon Seager
9eb9a9a56c
feat(account): display OpenRouter usage on account page
Show cumulative cost, API call count, and total tokens in card
layout when the user has AI usage data.
2026-02-05 12:09:43 +00:00
Jon Seager
0a93df845f
feat(ai): record usage after each OpenRouter extraction
Wire AiUsageRepository into AppState and add a fire-and-forget
record_ai_usage helper. All extraction route handlers now capture
the usage tuple and record it in the background.
2026-02-05 12:09:36 +00:00
Jon Seager
6271b0e5e5
feat(ai): capture usage data from OpenRouter API responses
Add Usage struct to parse prompt_tokens, completion_tokens,
total_tokens, and cost from every OpenRouter response. Extraction
functions now return (result, Option<Usage>) tuples. New ai_usage
table stores per-call records with a repository trait and SQL
implementation.
2026-02-05 12:08:48 +00:00
Jon Seager
69b039b02d
feat(account): add backup download and restore UI
Add a Data section to the account page with buttons to download
a JSON backup and restore from a previously exported backup file.
2026-02-05 11:51:36 +00:00
Jon Seager
6a0d94739b
feat(auth): allow naming the initial passkey during registration
- Add "Passkey Name" field to the registration form
- Pass passkey_name through start/finish WebAuthn ceremony
- Use user-provided name instead of hardcoded "default"
2026-02-05 11:24:52 +00:00
Jon Seager
16a4704fcf
feat(account): add account page with passkey and token management
- Add /account page with passkey list, token list, and sign-out
- Replace nav login/logout buttons with user icon linking to /account or /login
- Add passkey management: add new passkeys (WebAuthn ceremony), delete with confirmation
- Add token management: create, copy one-time value, revoke with confirmation
- Add user/key/clipboard icon macros
- Add PasskeyCredentialRepository::get() for ownership verification
- Add WebAuthn passkey/start and passkey/finish endpoints for adding passkeys
2026-02-05 11:24:43 +00:00
Jon Seager
25705ea0c0
fix(ui): update empty state messages based on auth status
Show a simple "No X added yet" for unauthenticated visitors.
Authenticated users see a prompt to click the Add button.
2026-02-05 11:14:39 +00:00
Jon Seager
e6d9f861e6
style(tables): normalize text styling to match brews table
Replace bold amber (font-semibold text-amber-800) with medium stone
(font-medium text-stone-800) across roaster, roast, cafe, and cup
list templates to match the brews table convention.
2026-02-05 11:11:44 +00:00
Jon Seager
c6b98f81c9
docs: update documentation for passkey auth
- Replace BREWLOG_ADMIN_USERNAME/PASSWORD with BREWLOG_RP_ID/RP_ORIGIN
- Document first-user bootstrap via one-time registration URL
- Document CLI browser handoff flow for token creation
- Update bootstrap script for new token creation process
- Change default URL references from 127.0.0.1 to localhost
2026-02-05 11:00:25 +00:00
Jon Seager
4bc64dd12f
test(auth): update tests for passkey migration
- Replace password-based token creation with direct DB inserts in CLI helpers
- Use INSERT OR IGNORE for concurrent test thread safety on shared user
- Update server test helpers with passkey/registration_token repos and WebAuthn state
- Remove password-based auth tests, keep bearer token validation tests
- Set BREWLOG_RP_ID, RP_ORIGIN, OPENROUTER_API_KEY, FOURSQUARE_API_KEY in test env
- Use localhost instead of 127.0.0.1 for WebAuthn RP ID compatibility
2026-02-05 11:00:20 +00:00
Jon Seager
03e03d87d9
feat(auth): replace password auth with WebAuthn passkeys
Replace username/password authentication with FIDO2/WebAuthn passkey-based
auth using webauthn-rs. Sessions and bearer tokens are unchanged — only the
way they are created changes.

- Add webauthn-rs, uuid, open, url deps; remove argon2, rpassword
- Add passkey_credentials and registration_tokens tables (migrations 17-18)
- Add domain entities, typed IDs, and repository traits for passkeys/tokens
- Add SQL repository implementations for passkeys and registration tokens
- Add ChallengeStore for in-memory WebAuthn ceremony state
- Add WebAuthn route handlers (register/auth start+finish ceremonies)
- Add CLI browser handoff for token creation (opens browser, local callback)
- Replace login form with "Sign in with Passkey" button
- Add registration page for first-user bootstrap via one-time token
- Replace BREWLOG_ADMIN_USERNAME/PASSWORD with BREWLOG_RP_ID/RP_ORIGIN
- Change default BREWLOG_URL from 127.0.0.1 to localhost (WebAuthn requires it)
2026-02-05 11:00:07 +00:00
Jon Seager
8c521f0e05
feat(data): redesign mobile data page with card layout and tab selector
- Add collapsible mobile tab selector with chevron icons
- Integrate search bar into tab component (below tabs)
- Replace Datastar search handler with vanilla JS for reliability
- Add mobile card layout: card-title, card-date, card-actions classes
- Add three-dot action menu for mobile with details/summary pattern
- Hide duplicate search inside data-content via CSS
- Pass search_value to DataTemplate for input preservation
2026-02-04 22:22:18 +00:00
Jon Seager
dd08e84572
fix(data): fix search bar 400 error on data page
Split Query<DataQuery> (which used #[serde(flatten)]) into two
separate extractors, since serde_urlencoded doesn't support flatten
and coerces all flattened values to strings, breaking u32 parsing.
2026-02-04 20:57:26 +00:00
Jon Seager
2c045f9335
fix(templates): remove dead detail-page links from list tables
The detail page routes and templates were removed but list templates
still linked to them. Replace the <a> tags with plain text to avoid
navigating to non-existent pages.
2026-02-04 20:53:19 +00:00
Jon Seager
2eca0ae3c6
refactor(bags): replace dual-section bag list with single paginated table
Remove the open-bags card grid and closed-bags history table in favour
of a unified table showing all bags with status badges and actions.

- Simplify load_bag_page to single BagFilter::all() query
- Remove open_bags field from BagPageData and BagListTemplate
- Add Status column with Open/Closed badges and remaining weight
- Add Close and Delete action buttons per row
2026-02-04 20:53:12 +00:00
Jon Seager
4bdfc661f9
refactor: consolidate entity pages into unified /data and /add views
Replace per-entity pages (/roasters, /roasts, /bags, /brews, /gear,
/cafes, /cups) and detail pages with a single tabbed /data view and
a dedicated /add page for entity creation.

- Add /data route with tab-based navigation using Datastar
- Add /add route consolidating all create forms
- Remove per-entity page handlers and standalone templates
- Remove detail page routes, handlers, and templates
- Update ListNavigator to accept String paths for query-param URLs
- Update home page and timeline links to use new /data?type=X paths
- Update nav to reference /data instead of individual entity pages
2026-02-04 20:51:30 +00:00
Jon Seager
50a372015c
feat(backup): expose backup/restore via authenticated API endpoints
- Add GET /api/v1/backup and POST /api/v1/backup/restore endpoints
  behind AuthenticatedUser
- Add BackupService to AppState and BackupClient for HTTP access
- Update CLI backup/restore to use API instead of direct DB access
- Remove --database-url flag from backup and restore commands
- Increase body limit to 50MB for restore endpoint
- Add API and CLI tests for auth, export, restore, and round-trip
- Update README to document auth requirement and API endpoints
2026-02-04 19:38:49 +00:00
Jon Seager
e31f1c741e
docs(claude): add code simplicity rules to prevent complexity creep
Add "Keeping Code Flat and Simple" section with five rules:
- Extract large closures (>10 lines) into named functions
- DRY repeated blocks that differ only by a parameter
- Prefer match over chained if/else-if when branching on a value
- Extract shared predicates into named helpers
- Use generic helpers for repeated structural patterns
2026-02-04 19:25:45 +00:00
Jon Seager
47c89bd725
refactor: simplify overly nested and duplicated code across five modules
- Extract 35-line filter_map closure into parse_cafe() in foursquare.rs
- Unify triple-duplicated search branching in pagination.rs into
  fetch_records() and fetch_count() helpers
- DRY three identical gear-loading blocks in brews.rs via
  load_gear_options() helper
- Flatten nested if/else-if in timeline map_details() using match,
  extract shared is_blank() helper
- Deduplicate JSON decode pattern in backup.rs with decode_json_vec()
  and decode_json_opt() helpers
2026-02-04 19:25:35 +00:00
Jon Seager
939743a224
feat(home): add inline detail subtitles to timeline preview cards
Show contextual details inline with event titles on home page timeline
cards. Each event type picks relevant fields: brew shows roaster and
brewer, roast shows roaster and origin, cafe shows city and country,
cup shows roaster and cafe, others show first three detail values.
2026-02-04 19:14:30 +00:00
Jon Seager
cdf90d1ff3
feat(home): add relative dates to timeline and brew cards
- Add relative_date() helper to views module for humanized timestamps
- Show relative dates on home page timeline preview and brew cards
- Format: "Just now", "Xm ago", "Xh ago", "Yesterday", "Xd/Xw ago"
2026-02-04 19:03:05 +00:00
Jon Seager
ba7a38b16f
refactor(home): redesign stats section with icon pills and responsive layout
- Replace single bordered card with compact pill-style stat links
- Add Heroicons for each stat category (beaker, fire, building, bag, cup, location, wrench)
- Rename old bag icon to cup, add new shopping-bag icon for bags
- Use 2-column grid on mobile, centered flex wrap on desktop
- Add min-width on numbers to align labels consistently
2026-02-04 18:54:37 +00:00
Jon Seager
ef039da123
fix(home): prevent text wrapping in brew and bag card detail fields 2026-02-04 17:49:57 +00:00
Jon Seager
37cd595c93
fix(home): truncate long names in brew and bag cards
Add text truncation with ellipsis to roast and roaster names in the
recent brews and open bags cards to prevent layout inconsistency when
titles wrap.
2026-02-04 17:43:36 +00:00
Jon Seager
91a9900c24
feat(scan): optionally open a bag when scanning coffee
Add "Open a bag of this coffee" checkbox (default: checked) to the
scan form with a configurable amount field (default: 250g). When
enabled, creates a bag and timeline event alongside the roaster/roast.
2026-02-04 17:41:53 +00:00
Jon Seager
ec62a1fc7b
fix(scan): clear signals and reset form on repeated extractions
Clear all roaster/roast signals before each extraction request to
prevent stale values from persisting across consecutive scans. Also
reset the extract form on completion to clear the prompt input.
2026-02-04 17:41:46 +00:00
Jon Seager
249d9c2583
refactor(home): consolidate scan results form and improve save behavior
- Merge roaster and roast sections into single bordered box
- Move cancel and save buttons inside the form border
- Reset form and reload homepage after save instead of redirecting to /roasts
2026-02-04 17:29:26 +00:00
Jon Seager
327a820b52
fix(home): simplify scan bag input layout
- Use camera icon-only button instead of "Take Photo" text
- Align camera button and text input horizontally
- Remove Go button, form submits on Enter
2026-02-04 17:28:24 +00:00
Jon Seager
52084be7ed
refactor(nav): replace login and logout text with icons
- Add login and logout icon macros to shared icons partial
- Desktop nav uses icon-only with aria-label for both
- Mobile nav uses icon + text for both
2026-02-04 17:21:58 +00:00
Jon Seager
f3a4cc7075
feat(home): limit open bags to 3 most recently updated
- Add UpdatedAt variant to BagSortKey
- Sort home page bags by updated_at desc instead of roast_date
- Limit to 3 bags instead of showing all open bags
2026-02-04 17:19:26 +00:00
Jon Seager
d15d58b32c
fix(auth): redirect login and logout to homepage instead of timeline 2026-02-04 17:14:56 +00:00
Jon Seager
e508af4c52
feat(nav): add check-in icon to navigation bar
- Add checkin map-pin icon to shared icons partial
- Add check-in nav link (icon on desktop, icon + text on mobile)
- Only shown when authenticated
- Set nav_active to "checkin" on the check-in page
2026-02-04 17:14:52 +00:00
Jon Seager
ebd2698b42
feat(home): redesign home page with recent brews cards and inline scan
- Replace single "Last Brew" with grid of 3 recent brew cards
- Show brew details with emphasis on weight/volume, grind, and brewer
- Add "Brew Again" action matching bag card button style
- Replace quick-action buttons with always-visible "Scan Bag" section
- Fix activity chip wrapping by widening to w-28 with whitespace-nowrap
- Increase section gap from gap-6 to gap-8 for better visual spacing
2026-02-04 17:14:46 +00:00
Jon Seager
62740c4c68
fix(home): move Last Brew heading outside card for consistent section styling 2026-02-04 16:43:45 +00:00
Jon Seager
836b241977
fix(home): align recent activity chips to fixed width for consistent text positioning 2026-02-04 16:40:54 +00:00
Jon Seager
305bc5f5a5
fix(tests): abort server tasks on test cleanup to prevent zombie processes
Store the tokio AbortHandle in TestApp and implement Drop to abort the
spawned server task. Previously the JoinHandle was silently dropped,
leaving server tasks running indefinitely after tests completed.
2026-02-04 16:37:08 +00:00
Jon Seager
3bbcd33933
refactor(templates): extract inline SVG icons into shared icons partial
Replace duplicated inline SVGs across 16 templates with reusable Askama
macros from a new icons.html partial, reducing repetition and making
icon updates a single-point change.
2026-02-04 16:32:18 +00:00
Jon Seager
a31c91211c
refactor: require OpenRouter and Foursquare API keys at startup
- Remove has_ai_extract/has_foursquare conditionals from all templates
- Remove boolean fields from template structs and route handlers
- Remove has_ai_extract()/has_foursquare() methods from AppState
- Change API key fields from Option<String> to String in ServerConfig
  and AppState
- Validate keys in run_server() with clear error messages
- Remove runtime key checks from extraction/nearby route handlers
- Update README and CLAUDE.md to reflect required configuration
2026-02-04 16:13:04 +00:00
Jon Seager
98c8391670
refactor(templates): extract shared bag card partial for open bags
- Create bag_card.html macro used by both home page and bags page
- Replace divergent card styles with consistent amber-themed design
- Add closeBag() JS to bags page for closing bags with confirmation
- Use "Close" button with cross icon consistently across both pages
2026-02-04 16:01:57 +00:00
Jon Seager
10c19b1f67
fix(templates): align cancel button styling across all form pages
- Update bags, brews, and gear cancel buttons to match cafes/roasters style
- Use amber-300 border with stone-700 text for consistent cancel button appearance
2026-02-04 16:01:44 +00:00
Jon Seager
e9bb291f83
fix(templates): use amber outline style for secondary action buttons
- Update btn-adjust CSS from white/stone to amber border with transparent bg
- Apply consistent amber-500 border, amber-700 text across all action buttons
- Affected pages: roasters, roasts, home, cafes, check-in, brews
2026-02-04 16:01:26 +00:00
Jon Seager
706a1fd131
fix(timeline): use consistent "Added" labels and simplify cup title
- Change "Brewed" to "Brew Added" and "Cup" to "Cup Added" for consistency
- Simplify cup timeline title to just the roast name
2026-02-04 16:01:03 +00:00
Jon Seager
fa5386c671
feat(checkin): add roast/cafe summary bars and data attribute selects
- Add roast name and roaster name signals to check-in page
- Show selected cafe city as subtext in cafe summary bar
- Add roast summary bar showing roast name and roaster after selection
- Use data attributes on select options for structured cafe/roast data
- Add name/city fields to CafeOptionView and name/roaster_name to RoastOptionView
- Return roaster name signal from scan endpoint for roast summary display
2026-02-04 16:00:53 +00:00
Jon Seager
0309ee08df
feat(checkin): add city search, cafe review form, and UX improvements
- Add "Search by city" toggle as alternative to GPS location
- Replace saved cafes button list with select dropdown
- Show editable review form when selecting a Foursquare result
- Guard all datastar-fetch handlers with in-progress signals
- Fix step indicator spacing (mt-4 on steps 2 and 3)
2026-02-04 15:02:20 +00:00
Jon Seager
6e6efac5f4
docs: update CLAUDE.md for Datastar-native patterns
- Document data-bind (not data-model) for two-way signal binding
- Document signal naming: kebab-case in HTML, camelCase in JS/JSON
- Document render_signals_json for application/json signal patches
- Document datastar-fetch event bubbling and per-form guard pattern
- Document extraction template pattern with inline FileReader JS
- Remove outdated extract.js documentation and element ID conventions
- Update static assets section (no separate JS files)
2026-02-04 14:37:13 +00:00
Jon Seager
2a94b87d49
refactor: remove extract.js and checkin.js
All extraction and check-in interactivity is now handled by Datastar
signals and inline FileReader JS. No separate JavaScript files remain.
2026-02-04 14:37:04 +00:00
Jon Seager
e4a304b406
feat(checkin): Datastar-native check-in and nearby cafe search
- Add POST /api/v1/check-in endpoint with CheckInSubmission
- nearby_cafes returns HTML fragment for Datastar, JSON for API
- Add NearbyCafeView and NearbyCafesFragment for server-rendered results
- Rewrite checkin.html: replace checkin.js with Datastar signals,
  @post for submission, @get for nearby search, inline geolocation JS
- Cafe filtering uses data-show with signal-based search
2026-02-04 14:36:55 +00:00
Jon Seager
bc30555447
refactor(extraction): Datastar-native AI extraction across all pages
Extraction endpoints now accept FlexiblePayload (form or JSON) and
return application/json signal patches for Datastar requests. Templates
use data-bind for two-way signal binding and data-on:datastar-fetch
with per-form guards to prevent event bubbling between forms.

- extract_roaster, extract_roast_info, extract_bag_scan return signals
- submit_scan extended with optional image/prompt for combined extract+save
- match_roaster_id fuzzy-matches extracted roaster name to existing IDs
- Templates use data-bind:_signal-name (not data-model) for form binding
- Each datastar-fetch handler guards with its own in-progress signal
2026-02-04 14:36:42 +00:00