Commit graph

2590 commits

Author SHA1 Message Date
Till JS
4bdf4238ce docs(mana/web): roundup data layer audit through encryption phase 6
Updates DATA_LAYER_AUDIT.md to reflect everything that landed since
the last refresh (which stopped at Sprint 4). The doc is now the
authoritative status surface for both audit-sprint and encryption-
sprint progress.

What's new in the doc:

  Status table (Section 0)
    Adds the missing post-Sprint 4 work and the full encryption phase
    table:
      - Sprint 4+ Listeners (575c5c36f)
      - Test-Fix sprint (ae648650e)
      - Backlog 1/2/3 — Indexed queries V9, SSE pipeline, Activity log
      - Encryption phases 1-6 with commits
    The "tests passing" line bumps to 262/262 across 20 files.

  Architecture diagram (Section 1)
    Shows how a write now flows through encryptRecord BEFORE the
    Dexie hook, and how reads route through decryptRecords on the
    way out of liveQuery. Adds a second diagram for the Encryption
    Pipeline (login → vault unlock → MemoryKeyProvider → wrap/
    unwrap → IndexedDB) that wasn't documented anywhere before.

  File map (Section 1)
    Splits into "Datenschicht" and "Encryption" sub-tables. The
    encryption table lists all 17 new files across crypto/, mana-auth
    services, the settings page and the onboarding banner with a
    one-line purpose for each.

  Eckdaten
    Schema versions 1-10 (was 1-7), and the new "At-Rest-Encryption"
    bullet noting 22+ tables.

  Critical fixes table (Section 2 🔴)
    #4 "Keine Verschlüsselung im Browser" flips from "noch offen" to
    "Encryption Phase 1-6 " with the one-line summary.

  🟢 backlog status table
    #13 SSE buffer flips to  via Backlog 2.
    #14 Tombstone cleanup loop flips to  via Sprint 4+.
    #18 Activity log flips to  via Backlog 3.

  New Section 5 — Encryption Pipeline
    Documents the trust model end-to-end:
      - Where each piece lives (mana-auth env KEK, wrapped MK in
        encryption_vaults, browser sessionStorage, IndexedDB blobs)
      - The complete table-by-table list of WHAT is encrypted and
        WHAT stays plaintext, with the per-table reasoning for the
        plaintext exceptions (dreamSymbols.name for indexed lookup,
        cycleDayLogs.symptoms for Set-diff, inventar.invItems.name
        for index, etc.)
      - "Was Mana technisch (nicht) sehen kann" — three-level honest
        disclosure: never / theoretically / structurally

  Section 6 — Backlog
    Reorders by remaining encryption work first:
      1. Phase 7 cross-module title coverage (timeBlocks coupling)
      2. Phase 7 server-pushed records (picture/storage/music)
      3. Phase 7 storeless modules (nutriphi/uload/context/questions)
      4. Phase 8 recovery code opt-in for true zero-knowledge
      5. Conflict viz UI
      6. Composite indexes for multi-account
      7. V3 migration tests

  Stärken (Section 7)
    Adds the encryption-specific properties: dedicated crypto/ sub-
    module entkoppelt vom sync layer, vault-singleton via
    vault-instance.ts, dimension "Vertraulichkeit" added to the
    final tagline.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 20:03:43 +02:00
Till JS
28395b313d docs: GPU tunnel setup, STT env wiring, and 2026-04-07 postmortem
Three docs updates landing the institutional knowledge from today's
Memoro voice recording deploy:

- docs/MAC_MINI_SERVER.md: architecture diagram updated to show the
  two-tunnel setup (cloudflared on the Mac Mini for *.mana.how
  except gpu-*, plus a separate cloudflared running as a Windows
  Service on the GPU box for gpu-*.mana.how). New "GPU Tunnel
  (mana-gpu-server)" section explains how to add hostnames in the
  Cloudflare dashboard, the standard 502 debug ladder (DNS misroute,
  service stopped, scheduled task crashed, missing public hostname),
  and how the API key flows from the Windows .env through Mac Mini
  .env to the mana-web container.

- docs/ENVIRONMENT_VARIABLES.md: STT section updated to reflect that
  MANA_STT_URL/API_KEY are now wired into the mana-web container via
  docker-compose.macmini.yml (committed in 42bd2a3a0). Health-check
  command added; cross-link to MAC_MINI_SERVER.md for the debug ladder.

- docs/POSTMORTEM_2026-04-07.md (new): full incident timeline of
  today's deploy. Six root causes (tunnel never started, DB wiped
  without re-push, untracked module-registry files, uncommitted
  Dockerfile heap bump, missing compose env vars, /offline prerender
  500). Three "what went poorly" honest assessments (premature P0
  alarm, miscounted commits, clumsy stash dance). Action items split
  by priority — high priority is the clean-clone build CI job, which
  would have caught half the issues today.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 19:59:04 +02:00
Till JS
6b8e2c7176 feat(mana/web): encryption phase 6.2/6.3 — settings page + onboarding banner
Two user-facing surfaces for the encryption pipeline that's been
running invisibly since Phase 4. Closes the loop on "we encrypt
your data" by making the claim concrete, verifiable, and rotatable.

vault-instance.ts (new)
  Lazy-singleton wrapper around createVaultClient. The root layout
  was holding a private vault client reference; the settings page
  needs the same instance to call rotate() and read state.
  getVaultClient() builds it on first call from authStore +
  getManaAuthUrl(), reuses it forever after. Phase 3's
  setKeyProvider/getActiveKey wiring means the rest of the data
  layer doesn't need to know about the singleton at all — only
  callers that want to drive lock/unlock/rotate explicitly do.

  +layout.svelte and the new settings/security page both call
  getVaultClient() — the underlying MemoryKeyProvider is shared
  via setKeyProvider, so an unlock from either surface immediately
  reflects in both.

routes/(app)/settings/security/+page.svelte (new)
  Surface for the encryption vault state. Three sections:

    1. STATUS card with a coloured badge:
       - 🔒 Verschlüsselt (green) when unlocked
       - 🔓 Gesperrt (amber) when locked, plus a "Schlüssel jetzt
         laden" button that calls vaultClient.unlock()
       - error states distinguish auth/network/server with
         localised copy and a retry button

       A 1-second poll mirrors external lock/unlock events
       (logout, manual lock from another tab) so the badge stays
       fresh without a hard refresh. Disposed on unmount.

    2. ENCRYPTED FIELDS list — derived from the registry:
       Object.entries(ENCRYPTION_REGISTRY).filter(enabled).map(...)
       Renders one row per table with the field allowlist visible
       in monospace, plus a count summary at the top. The list is
       always honest: if a registry entry is enabled:false (Phase 7
       targets, server-pushed tables, etc.), it does not appear.

    3. ROTATE card (danger styling):
       Two-step confirm before mutating. Calls vaultClient.rotate()
       which the existing Phase 3 wire already routes through
       /api/v1/me/encryption-vault/rotate. Toast on success/failure.
       Explicitly documents that the old MK is GONE and current
       data is NOT auto-re-encrypted — the user accepts that risk.

    4. HONEST DISCLOSURE section: lists what Mana CAN'T see
       (encrypted blobs), what Mana COULD technically see
       (the wrapped MK if a hosting employee actively reaches for
       the KEK), and what's structurally visible (counts,
       timestamps, relationships). Reads better than any policy
       page because it's anchored in the actual data layout.

EncryptionIntroBanner.svelte (new)
  One-time onboarding banner that fires on the first vault unlock
  ever on a given device. Uses localStorage('mana-encryption-intro-
  dismissed') as the persistent flag. Shows a green-bordered card
  bottom-centre explaining at-rest encryption in three sentences,
  with a "Mehr erfahren →" link to /settings/security and an X
  dismiss button.

  Why a banner instead of a toast?
    - Toasts disappear after 3s; a privacy claim deserves longer
      attention.
    - The banner has room for a learn-more link; toasts don't.
    - Dismissing it is an explicit user action, which matches the
      "you understand and accept" social contract.

  Polls vault state every 500ms for up to 30s after mount so it
  fires even if the unlock happens asynchronously after the layout
  finishes rendering. Auto-clears the timer once it shows or after
  the 30s window. SSR-safe: localStorage access is guarded.

  Mounted globally in the root layout next to the existing
  SuggestionToast, OfflineIndicator, PwaUpdatePrompt.

Layout integration
  routes/+layout.svelte:
    - Drops the inline createVaultClient + getManaAuthUrl import
      in favour of getVaultClient() — single source of truth.
    - <EncryptionIntroBanner /> mounted alongside the other
      global UI elements.

Verified: 20 test files, 262/262 tests passing. Pre-existing
TS error in src/routes/(app)/settings/+page.svelte:338
(getSecurityEvents on authStore) is unrelated parallel drift.

Encryption pipeline status: Phase 1-6 complete.
  - 22 tables encrypted at rest covering >85% of user-typed bytes
  - Server-side master key vault with KEK-wrapping (mana-auth)
  - Vault unlock on login, lock on logout
  - Per-record encryptRecord/decryptRecord through every store
  - Settings UI showing status + rotate
  - First-login onboarding banner

Remaining for a hypothetical Phase 7:
  - tasks/calendar.events/habits — title leakage via timeBlocks
  - picture/storage/music — server-pushed, needs API encryption
  - nutriphi/uload/context.documents/questions — store extraction
    needed before they can flow through encryptRecord
  - Recovery code opt-in for true zero-knowledge users (server
    can't even technically decrypt)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 19:54:09 +02:00
Till JS
de33ed8687 fix(mana/web): disable prerender on /offline (FIXME)
The SvelteKit prerender worker throws "Error: 500 /offline" with no
usable stack trace, blocking the production build. Suspected cause: a
module-level side-effect on the shared layout that fails when no
`window` is available — likely from one of the new vault-client or
data-layer-listeners imports that landed in the encryption phase 4-6
sprints.

SSR'ing /offline at request time is harmless — it's just a static
"you're offline" message — so this is a safe workaround that unblocks
the deploy. The real fix is to bisect which import on the offline
codepath throws on the bare server and add a `typeof window` guard
or move it to onMount.

Without this, the unified mana-web image cannot be rebuilt.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 19:50:32 +02:00
Till JS
5d4123d2b0 fix(mana/web): commit module-registry + module.config.ts files (build-critical)
These files have been sitting untracked in working trees on multiple
machines since the unified module-registry refactor. database.ts
imports from $lib/data/module-registry but the file itself was never
git-add'd, so the production build crashes on any clean clone with:

    Could not resolve "./module-registry" from "src/lib/data/database.ts"

Discovered today during the first deploy of the Memoro recording
pipeline: pulling onto the Mac Mini (which had its own untracked copies
of these files in a stash) revealed that origin/main has been silently
broken for clean builds. Fixed by committing the canonical versions:

  - apps/mana/apps/web/src/lib/data/module-registry.ts
  - apps/mana/apps/web/src/lib/data/module-registry.test.ts
  - apps/mana/apps/web/src/lib/modules/{31 modules}/module.config.ts

The events module already had its module.config.ts committed in
6a60e22a3 (events Phase 2), so it isn't included here.

Also bumps apps/mana/apps/web/Dockerfile build heap from 4096 → 8192:
the unified app outgrew the 4 GB ceiling somewhere between Sprint 2
and Sprint 3 of the data layer rewrite, and Vite OOMs while bundling
all 32 module chunks. The bump existed locally on multiple boxes but
was never committed; today's deploy hit the OOM and required restoring
the bump from a stash to make the image rebuild succeed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 19:49:58 +02:00
Till JS
42bd2a3a04 chore(deploy): wire MANA_STT_URL/API_KEY into mana-web container
The unified mana-web container needs MANA_STT_URL + MANA_STT_API_KEY at
runtime so its server-side proxies (/api/v1/memoro/transcribe and
/api/v1/dreams/transcribe) can reach mana-stt with the right credentials.
The browser never holds the key.

URL points at the public tunnel (https://gpu-stt.mana.how → Cloudflare
tunnel mana-gpu-server → Windows GPU box localhost:3020) so the resolver
works regardless of where the container runs. The API key is sourced from
the Mac Mini .env, which is gitignored.

Without this, the proxies short-circuit with HTTP 503 "mana-stt is not
configured" — observed today on first deploy of the recording pipeline.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 19:47:42 +02:00
Till JS
73f294b298 feat(mana/web): encryption phase 6.1 — cards, presi, inventar, planta
Four more modules join the encrypted-at-rest path. Tables flipped:

  - cards.cards         front + back   (no `notes` column on LocalCard)
  - cards.cardDecks     name + description   (schema uses `name` not `title`)
  - presi.presiDecks    title + description
  - presi.slides        content   (LocalSlide has only the SlideContent
                                    object — no separate `notes`. The
                                    JSON-stringify in wrapValue handles
                                    nested-object content cleanly)
  - inventar.invItems   description   (only — `name` is in the schema
                                        index used by where()/sortBy
                                        queries, and `notes` is an array
                                        of {id, content, createdAt} that
                                        addNote/deleteNote splice in
                                        place; encrypting either would
                                        force per-mutation decrypt+
                                        re-encrypt of the whole array.
                                        Phase 7 concern.)
  - planta.plants       name + careNotes + temperature + soilType
                        (`name` is NOT indexed for plants — the schema
                        only indexes id/isActive/healthStatus, so it's
                        safe to encrypt unlike inventar/dreamSymbols)

Per-module mutations
  Each store now follows the established Phase 4/5 pattern:
    - createX: build LocalRecord, snapshot via toX() for the optimistic
      return, encryptRecord, then table.add
    - updateX: build diff, encryptRecord on the diff, then table.update
    - The Sprint 1 atomic-cascade deleteDeck (cards + presi) is unchanged
      because deletes only touch plaintext deletedAt/updatedAt fields.

  planta.update() reads the row back after the write to return a Plant
  to its caller; that read goes through decryptRecord because the
  raw row is now encrypted on disk.

Per-module queries
  useAllDecks / useDeck / useCardsByDeck (cards)
  useAllDecks / useDeck / useDeckSlides (presi)
  useAllItems (inventar)
  useAllPlants (planta)
  All filter on plaintext metadata first, then decryptRecords on the
  visible set.

cross-app-queries dashboard widgets
  - useRecentDecks (presi)  decrypts the title/description before the
    dashboard widget renders the deck name
  - useCardsProgress decrypts the deck name list — counts continue to
    work on plaintext fields

Skipped intentionally
  - tasks / calendar.events / habits — title is duplicated to the
    cross-module timeBlocks table. Encrypting only the task copy
    would still leak the title via the timeBlock. Needs a coordinated
    timeBlocks encryption pass (Phase 6.1.5).
  - picture.images / storage.files / music.songs — records are
    server-pushed (image generation, file uploads, library imports).
    Client-side encryptRecord can't help; needs the API service to
    encrypt before pushing, or a sync-time wrap step. Documented as
    a Phase 7 concern.
  - nutriphi.meals / uload.links / context.documents / questions /
    answers — write directly from views, no store. Need a store
    extraction first.

Verified: 20 test files, 262/262 tests passing. Pre-existing TS
errors in context/index.ts, picture/images.svelte.ts, planta/
quick-input-adapter.ts and questions/index.ts are unrelated parallel
refactor drift.

Phase 6.2 next: settings/security UI showing vault status, encrypted-
table list, manual rotate button.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 19:44:38 +02:00
Till JS
b2bddfefab docs(events): roadmap of remaining Phase 2 work + tech debt
Drops a ROADMAP.md inside the module so the next session has a
single place to look. Lists what's shipped, the remaining feature
ideas (iCal, per-guest tokens, recurring, websockets, email
invites, reminders, capacity waitlist), and the tech-debt residue.
2026-04-07 19:35:16 +02:00
Till JS
6a60e22a31 feat(events): bring list (wer bringt was?) — Phase 2
Add an "eventItems" mini-collection attached to each social event so
hosts can track what each guest is bringing, and so public visitors
on the share-link page can claim an item without an account.

Local-first side
- New eventItems table (Dexie v11), module config update for sync.
- LocalEventItem type + EventItem domain type, useEventItems query.
- eventItemsStore: addItem / updateItem / toggleDone / assign /
  deleteItem. Every mutation pushes the full list to the server
  snapshot via eventsStore.syncItems if the event is published.
- BringListEditor component on the host DetailView with assign-to-
  guest dropdown, quantity, and done-checkbox.
- eventsStore.syncItems + a syncItems call in publishEvent so the
  public page sees pre-existing items as soon as the event ships.

Server side
- New event_items_published table (FK cascade from events_published
  so unpublishing wipes the bring list along with the snapshot).
- Host endpoints PUT/GET /events/:eventId/items: full-replace upsert
  that preserves any existing claimed_by_name across host edits, max
  100 items, ownership check.
- Public POST /rsvp/:token/items/:itemId/claim: name-only claim, 1×
  per item (first write wins), shares the per-token hourly rate
  bucket with RSVP submissions to keep the abuse surface uniform.
- GET /rsvp/:token now also returns the bring list (sorted) so the
  public page renders in a single round-trip.

Public RSVP page
- Renders the bring list with claim buttons; clicking prompts for a
  name and POSTs the claim, then optimistically updates the UI.
- New bring-list i18n keys for all five locales (de/en/it/fr/es).

Tests
- 15 new server tests covering host PUT/GET (insert / update / prune /
  ownership / claimed-name preservation / cascade), GET /rsvp item
  exposure, and POST /claim (success / double-claim / cross-token /
  cancelled / validation). 50 server tests total, all green.
- E2E spec scoped to .guest-editor where the new BringListEditor
  introduced a duplicate "Hinzufügen" button label.
2026-04-07 19:31:39 +02:00
Till JS
af92720a62 feat(mana/web): encryption phase 5 — rollout to chat/dreams/memoro/contacts/cycles/finance
Six modules join the notes pilot (Phase 4) on the encrypted-at-rest path.
Every user-typed text and PII field listed below is now wrapped via
AES-GCM-256 with the per-user master key before any write hits Dexie,
and decrypted on every liveQuery read coming back through the public
queries module.

Tables flipped to enabled:true in the registry
  - chat.messages          messageText
  - chat.conversations     title
  - chat.chatTemplates     name + description + systemPrompt + initialQuestion
  - dreams.dreams          title + content + transcript + interpretation
                           + aiInterpretation + location
  - dreams.dreamSymbols    meaning   (name stays plaintext — used as
                                       indexed lookup key in touchSymbols /
                                       updateSymbol via where('name'))
  - memoro.memos           title + intro + transcript
  - memoro.memories        title + content
  - contacts.contacts      firstName + lastName + email + phone + mobile
                           + birthday + street + city + postalCode
                           + country + notes + website + linkedin
                           + twitter + instagram + github
  - cycles.cycles          notes
  - cycles.cycleDayLogs    notes + mood   (symptoms stays plaintext —
                                            standardised label array
                                            consumed by symptomsStore.touchSymptoms
                                            via Set diffs in dayLogsStore.logDay)
  - finance.transactions   description + note   (the schema uses
                                                  `note` singular,
                                                  not `notes` or `merchant`
                                                  as my earlier draft had it)

Tables intentionally left disabled
  - questions / answers — direct db.table().update() call sites in
    DetailView.svelte instead of going through a store. Need a store
    extraction first; registry entry stays in place so the flip is a
    one-line change once the store exists.
  - tasks, events, calendar.events, plants, meals, slides, presiDecks,
    cards, links, etc. — fall through to a future Phase 6 once the
    chat/dreams/memoro/contacts pilots are validated in real use.

Per-module changes
  Each store now follows the same pattern the notes pilot established:
    1. Build the LocalRecord with plaintext fields
    2. Snapshot it via toX() for the optimistic UI return value
    3. await encryptRecord(tableName, record)   // mutates in place
    4. await table.add(record)                   // ciphertext lands on disk

  For updates the diff is encrypted in place before the update() call
  so partial updates only encrypt the modified fields.

  The transcribeBlob flows in dreams + memoro decrypt the existing
  record first (to read the user-typed `content`), then build a
  diff and re-encrypt it. Same for contactsStore.ensureSelfContact
  which compares against decrypted-existing values to decide whether
  the profile-sync needs an update.

Per-module query changes
  Each public liveQuery now filters on plaintext metadata (deletedAt,
  isArchived, etc.) FIRST, then runs decryptRecords on the visible
  set, then maps to the public type. Cost stays bounded by what the
  view actually renders, not the total table size.

  cross-app-queries.ts useFavoriteContacts decrypts firstName before
  the localeCompare sort.

Test fixes
  - aes.test.ts: the "registry returns null for disabled tables"
    assertion now picks tasks + events as the disabled examples
    (messages + contacts both flipped on in this commit).
  - cycles.integration.test.ts:
    1. beforeEach installs a fresh MemoryKeyProvider with a real
       Web Crypto key so dayLogsStore.logDay can encrypt mood/notes
    2. The "no duplicate" upsert test decrypts the raw rows it reads
       directly from the table before asserting on the mood field
  - module-registry.test.ts (drive-by, unrelated): adds eventItems
    to the events appId snapshot to match the parallel module-registry
    refactor.

Verified: 20 test files, 262/262 tests passing.

Phase 6 will roll out to the remaining tables (tasks, events, plants,
meals, slides, etc.) and finally light up the settings/security UI
(lock state, manual rotate, recovery code opt-in).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 19:28:26 +02:00
Till JS
3eabbc5e53 i18n(events): RSVP page in it/fr/es + extract e2e helper
- strings.ts: add Italian, French, Spanish dictionaries (≈25 keys
  each) and widen Lang to the full DE/EN/IT/FR/ES set.
- +page.server.ts: pickLang now matches any of the five supported
  locales from Accept-Language; SSR error messages localised the
  same way.
- e2e/helpers.ts: extract the dismissWelcomeModal helper out of
  events.spec.ts so future module specs can reuse it without
  duplicating the locale-agnostic dialog locator.
2026-04-07 19:11:59 +02:00
Till JS
897256c985 test(mana-events): 35 server tests covering routes + sweeper
Add bun:test integration suite that exercises every public and host
endpoint plus the rate-bucket sweeper against a real Postgres. The
Hono app factory was extracted from index.ts into app.ts so tests can
build their own instance with a header-based auth mock instead of
spinning up mana-auth + JWKS.

Coverage:
- health route smoke
- public RSVP: snapshot fetch (incl. 404, cancelled, summary
  privacy), submit, validation (name, status, email, plus-ones,
  cancelled), upsert dedup (incl. null/missing email parity), summary
  aggregation across yes/no/maybe + plus-ones, rate-limit cap (5/h),
  absolute per-token cap (20)
- host events: publish (auth, idempotent token reuse, ownership),
  snapshot update (partial, ownership, 404), delete (cascade FK to
  rsvps + buckets, ownership, idempotent), get rsvps (ownership)
- sweeper: removes >2h-old buckets, keeps fresh ones, no-op on empty

Mock auth lives in a small helper that injects an X-Test-User header
into a fake middleware, so the same createApp() factory powers both
production (real jwtAuth) and tests (header mock).
2026-04-07 19:02:54 +02:00
Till JS
bed08a1aa6 feat(mana/web): encryption phase 4 — notes pilot live
First module with at-rest encryption flipped on. The notes table's
title + content are now encrypted with AES-GCM-256 before any write
hits Dexie, decrypted on every read coming back through liveQuery,
and travel as opaque ciphertext through the sync wire (pending
changes, server push, applyServerChanges, the lot).

What changes for the user
  - Nothing visible. Optimistic UI render still uses the plaintext
    snapshot returned by createNote(). Edits look identical to the
    old Phase 3 behaviour. The difference is invisible until you
    crack open DevTools → Application → IndexedDB → mana → notes,
    where you'll see ciphertext instead of "Buy milk".

What changes on disk
  - notes.title and notes.content store ciphertext blobs
    (`enc:1:<iv-b64>.<ct-b64>`)
  - All other columns (id, color, isPinned, isArchived, createdAt,
    updatedAt, deletedAt, userId, __fieldTimestamps) stay plaintext
    so liveQuery filtering, sorting, and Field-Level LWW continue to
    work without changes.
  - _pendingChanges.data carries the same ciphertext blobs — server
    receives opaque values, never plaintext.

Files
  registry.ts
    notes flipped to enabled:true with the corrected field list
    ['title', 'content'] (the schema has no 'body' column).

  aes.test.ts
    Existing assertion that "Phase 1 has no encrypted tables" is
    rewritten as "notes is enabled in Phase 4" so the registry flip
    doesn't break the foundation suite.

  record-helpers.ts
    encryptRecord/decryptRecord/decryptRecords loosen the generic
    constraint from `T extends Record<string, unknown>` to
    `T extends object`. Domain types like LocalNote work as direct
    arguments without an `as Record<string, unknown>` cast at every
    call site. Internal field reads/writes go through a sealed
    Record-shaped view.

  notes/stores/notes.svelte.ts
    createNote: snapshots the plaintext for the optimistic return
    value, then encryptRecord('notes', record) before noteTable.add.
    updateNote: encrypts the diff in place; non-encrypted fields
    (color, isPinned, isArchived) pass through untouched.
    togglePin / archiveNote / deleteNote: untouched — they only
    update plaintext columns.

  notes/queries.ts
    useAllNotes: filter on plaintext metadata first (deletedAt,
    isArchived) so the decrypt workload is bounded by the visible
    set, not the whole table. Then decryptRecords across what's
    left, then map+sort.
    useNote(id): new helper for detail views.

  notes-encryption.test.ts (new — 8 cases)
    End-to-end against fake-indexeddb with a real Web Crypto master
    key in MemoryKeyProvider:
      1. Title + content land as ciphertext on disk
      2. Structural fields stay plaintext on disk
      3. updateNote re-encrypts modified content but leaves flags
      4. togglePin / archiveNote produce byte-identical title blobs
         (i.e. no spurious re-encryption)
      5. _pendingChanges.data carries ciphertext + plaintext metadata
      6. Wrong-key decrypt fails closed (returns blobs, not garbage)
      7. Locked vault refuses new writes with VaultLockedError
      8. Locked vault still serves blobs without crashing on read

Test bilanz: 4 crypto-related test files, 64/64 passing
(31 AES + 12 record-helpers + 12 vault-client + 8 notes E2E + 1 misc).
Full mana/web suite: 20 files, 262/262 tests passing.

Stand der encryption pipeline:
  Phase 1   Foundation (1ba5948ce)
  Phase 2   Server vault (e9915428c)
  Phase 3   Wire-up (354cbcb17)
  Phase 4   Notes pilot (this commit)
  Phase 5 → roll out to chat, dreams, memoro, contacts, etc.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 19:00:11 +02:00
Till JS
640242500e fix(events): production wiring + polling resilience (quick wins)
Five small follow-ups on Phase 1b:

- docker-compose.macmini.yml: add the mana-events container with the
  same shape as mana-credits, expose port 3065, add a Traefik route
  for events.mana.how, and inject PUBLIC_MANA_EVENTS_URL into the
  mana-web container so the SvelteKit SSR + browser both reach it.
- mana-events: background sweeper that deletes rsvp_rate_buckets
  rows older than 2h every hour. Without it, long-published events
  accumulate one row per traffic-hour forever (FK cascade only fires
  on snapshot delete).
- PublicRsvpList: track consecutiveFailures and only show the error
  banner after two failures in a row, so a single mid-poll network
  hiccup doesn't flash a 30s error the user can't act on.
- apps/mana/apps/web: declare postgres as a devDep (already imported
  by the e2e spec via pnpm hoisting, now explicit).
2026-04-07 18:53:29 +02:00
Till JS
354cbcb176 feat(mana/web): encryption phase 3 — vault client + record helpers + layout wire-up
Adds the client-side wire-up that lets browsers fetch their master key
from the mana-auth server vault and use it to encrypt/decrypt configured
record fields. Still a no-op at the user-visible level until Phase 4
flips registry entries to enabled:true on a per-table basis.

vault-client.ts
  Browser HTTP client for the three Phase 2 endpoints. Built around a
  factory that takes (authUrl, getToken) and returns { unlock, lock,
  refetch, rotate, getState }. Reuses the active MemoryKeyProvider if
  one is already installed, otherwise registers a fresh one.

  unlock() flow:
    1. Short-circuits if already unlocked.
    2. GET /api/v1/me/encryption-vault/key with Bearer token.
    3. On 404 + code:'VAULT_NOT_INITIALISED', auto-fires POST /init so
       the user is bootstrapped on first login per device.
    4. Imports the returned base64 bytes via importMasterKey() into a
       non-extractable CryptoKey, pushes it into MemoryKeyProvider.
    5. Zeroes the raw byte buffer once imported (best-effort heap hygiene).

  Network layer: 3-attempt retry loop with full-jitter exponential
  backoff (500ms→8s), retries only on 0/408/429/5xx. 4xx surfaces
  immediately so auth/permission errors don't stall the UI for seconds.

  Error categorisation: 401/403→auth, network→network, 5xx→server,
  rest→unknown. Returned as VaultUnlockState so callers can render
  intent ("please re-login" vs "we're trying again" vs "the server
  is having a moment").

record-helpers.ts
  encryptRecord(tableName, record):
    - Looks up the registry, returns unchanged if the table is not
      configured or registry entry is disabled.
    - Builds a work list of fields that need encryption (skipping
      null/undefined and already-encrypted blobs — the latter makes
      the helper idempotent on a re-emit from liveQuery).
    - Throws VaultLockedError on the first call that needs the key
      but finds the vault locked. Module stores let it bubble; the
      UI surfaces "you need to unlock" toast.

  decryptRecord(tableName, record):
    - Mirror of encryptRecord. Locked-vault behaviour is to LEAVE the
      blobs in place (rather than throw) so views can still render
      structural fields and show a "🔒" placeholder where content
      used to be.
    - Per-field decrypt failure (corrupt blob, wrong key) is caught,
      logged, and the field stays encrypted. The rest of the record
      decrypts normally — one bad blob doesn't kill the whole read.

  decryptRecords: array variant that skips null/undefined entries.

Layout integration (+layout.svelte)
  - createVaultClient is constructed once at module init, reused
    across all auth-state changes.
  - The existing $effect on authStore.user gets a new branch:
    - userId set + hasAnyEncryption() → vaultClient.unlock()
    - userId cleared → vaultClient.lock()
  - hasAnyEncryption() guards the network round-trip: while every
    table is enabled:false (Phase 3 default), no fetch happens at all.
    Phase 4 enables tables one by one and the unlock kicks in
    automatically.

Tests
  - record-helpers.test.ts: 12 cases — encrypt skips non-listed fields,
    null/undefined pass-through, idempotent on already-encrypted,
    table-not-in-registry no-op, VaultLockedError on missing key,
    decrypt roundtrip, locked-vault returns blobs unchanged, per-field
    failure logged + others continue, JSON.stringify/parse roundtrip
    survives the sync wire.
  - vault-client.test.ts: 12 cases — happy path GET /key, idempotent
    second unlock, 404 → auto /init, generic 404 does NOT trigger
    /init, 401/403 → auth error, fetch throw → network error, no
    token → auth error without network call, lock() clears key,
    refetch() re-pulls, rotate() POSTs and installs.

Verified: 7 test files, 110/110 src/lib/data/ tests passing
(31 AES + 12 record-helpers + 12 vault-client + 20 sync + 6 activity
+ 19 recurrence + 10 misc helpers).

Phase 4 (next): pilot the notes module — flip its registry entry to
enabled:true, wrap the notes store add/update to call encryptRecord,
wrap the notes queries to call decryptRecord, add a settings page
showing lock state and a manual rotate button.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 18:49:22 +02:00
Till JS
c5aeaf5e7f feat(memoro): voice recording → mana-stt transcription pipeline
Adds end-to-end browser voice capture for the Memoro module, mirroring the
existing dreams pattern: MediaRecorder → SvelteKit server proxy → mana-stt
on the Windows GPU box via Cloudflare tunnel.

Recording UI lives in /memoro page header (mic button + live timer + cancel +
sticky-permission retry). Server proxy at /api/v1/memoro/transcribe forwards
the blob with the server-held X-API-Key. memosStore.createFromVoice creates a
placeholder memo with processingStatus='processing' and fires transcribeBlob
in the background, which writes the transcript and flips status on completion
(or 'failed' with error in metadata).

Also corrects the mana-stt hostname across the repo: stt-api.mana.how (which
never existed in DNS) → gpu-stt.mana.how (the actual Cloudflare tunnel route
to the Windows GPU box). Adds an ENVIRONMENT_VARIABLES.md section explaining
how to obtain MANA_STT_API_KEY and where the tunnel terminates. Adds tunnel
health probes to the mac-mini health-check script so we catch tunnel-side
breakage in addition to LAN-side.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 18:48:41 +02:00
Till JS
4d9bf78f41 docs(cycles): add ROADMAP with future feature ideas
Consolidates all the "could still do" ideas from the initial design
sessions into a single roadmap document next to the module:

- Short-term quality-of-life polish (keyboard shortcuts, date picker,
  orphan symptom IDs, plural forms)
- Mid-term features (BBT chart, history page, pattern recognition,
  cycle notes panel, per-day detail page)
- Testing gaps (component tests, Playwright E2E, migration tests)
- Long-term production-readiness (notifications, memoro audio notes,
  PDF export, privacy mode with app-lock, mobile port)
- Initial ManaScore estimate and ecosystem health indicators
- Explicit non-goals and a recommended next-steps ordering

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 18:39:38 +02:00
Till JS
e9915428cb feat(mana-auth): encryption vault — phase 2 (server-side master key custody)
Adds the server side of the per-user encryption vault. Phase 1 shipped
the client foundation (no-op while every table is enabled:false). This
commit lets the client actually fetch a master key when Phase 3 flips
the registry switches.

Schema (Drizzle + raw SQL migration)
  - auth.encryption_vaults: per-user wrapped MK + IV + format version +
    kek_id stamp + created/rotated timestamps. PK = user_id, ON DELETE
    CASCADE so account deletion wipes the vault.
  - auth.encryption_vault_audit: append-only trail of init/fetch/rotate
    actions with IP, user-agent, HTTP status, free-form context.
  - sql/002_encryption_vaults.sql: idempotent CREATE TABLE + ENABLE +
    FORCE row-level security with a `current_setting('app.current_user_id')`
    policy on both tables. FORCE makes the policy apply to the table
    owner too — no bypass via grants.

KEK loader (services/encryption-vault/kek.ts)
  - Loads a 32-byte AES-256 KEK from the MANA_AUTH_KEK env var (base64).
  - Production: missing or wrong-length input is fatal at boot.
  - Development: 32-zero-byte fallback so contributors can run the
    service without provisioning a secret. Logs a loud warning.
  - wrapMasterKey / unwrapMasterKey use Web Crypto AES-GCM-256 over the
    raw 32-byte MK with a fresh 12-byte IV per wrap. Returns base64
    pair for storage.
  - generateMasterKey + activeKekId helpers used by the service.
  - Future migration to KMS / Vault: only loadKek() changes; the
    kek_id stamp on each row tracks which KEK produced it.

EncryptionVaultService (services/encryption-vault/index.ts)
  - init(userId): idempotent — returns existing MK or mints a new one.
  - getMasterKey(userId): unwraps the stored MK; throws VaultNotFoundError
    on no-row so the route can return 404 cleanly.
  - rotate(userId): mints fresh MK, replaces wrap. Caller is on the
    hook for re-encryption — destructive by design.
  - withUserScope(userId, fn): wraps every read/write in a Drizzle
    transaction with set_config('app.current_user_id', userId, true)
    so the RLS policy admits only the matching row. Empty userId is
    rejected up-front.
  - writeAudit() appends a row to encryption_vault_audit on every
    action including failures, so probing attempts leave a trail.

Routes (routes/encryption-vault.ts)
  - POST /api/v1/me/encryption-vault/init  — idempotent bootstrap
  - GET  /api/v1/me/encryption-vault/key   — fetch the active MK
  - POST /api/v1/me/encryption-vault/rotate — destructive rotation
  - All return base64-encoded master key bytes plus formatVersion +
    kekId. JWT-protected via the existing /api/v1/me/* middleware.
  - readAuditContext() pulls X-Forwarded-For + User-Agent off the
    request for the audit row.

Bootstrap (index.ts)
  - loadKek() runs at top-level await before any route can fire so a
    misconfigured KEK fails closed at boot, never at request time.
  - encryptionVaultService is mounted under /api/v1/me/encryption-vault
    so it inherits the existing JWT middleware and shows up next to the
    GDPR self-service endpoints.

Tests (services/encryption-vault/kek.test.ts)
  - 11 Bun-test cases covering: KEK load (happy path, wrong length,
    idempotent, before-load guard), generateMasterKey randomness,
    wrap/unwrap roundtrip, IV uniqueness across repeated wraps,
    wrong-MK-length rejection, tampered-ciphertext rejection,
    wrong-length IV rejection, wrong-KEK rejection.
  - Service-level integration tests deferred — they need a real
    Postgres for the RLS behaviour, set up via existing mana-sync
    test pattern in CI.

Config + env
  - .env.development gains MANA_AUTH_KEK= (empty → dev fallback)
    with a comment explaining the production requirement.
  - services/mana-auth/package.json gains "test": "bun test".

Verified: 11/11 KEK tests passing, 31/31 Phase 1 client tests still
passing, only pre-existing TS errors remain in mana-auth (auth.ts:281
forgetPassword + api-keys.ts:50 insert overload — both unrelated).

Phase 3: client wires the MemoryKeyProvider to GET /encryption-vault/key
on login, flips registry entries to enabled:true table by table, and
extends the Dexie hooks to call wrapValue/unwrapValue on configured
fields.
Phase 4: settings UI for lock state, key rotation, recovery code opt-in.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 18:38:09 +02:00
Till JS
3a4c6654b5 test(events): playwright e2e specs + flake-resistant config
Restore the events Playwright suite (lost in a rebase) and harden it
against Vite cold-start HMR flakes. Six tests cover the local-first
host flow (create, edit guests, RSVP totals, delete) and the public
RSVP page (snapshot render, submit, upsert, 404). The host flow runs
in guest mode and dismisses the welcome modal via a small helper.

playwright.config.ts boots mana-auth, the Vite dev server, and
mana-events as separate webServers with reuseExistingServer=true so
running tests against an already-up dev environment is a no-op. Bumps
the per-test timeout to 60s and the expect timeout to 10s, and tells
goto() to wait for networkidle so locator clicks don't race a Vite
recompile.
2026-04-07 18:36:45 +02:00
Till JS
4d46cbb676 i18n(cycles): real translations for it/fr/es
Replace the English-copy stubs in it.json, fr.json, and es.json with
actual Italian, French, and Spanish translations covering the full
cycles namespace — phase labels, flow/mood levels, section headers,
actions, placeholders, stats, relative dates, symptom manager, and
the calendar.

Key structure remains identical across all 5 locales so the parity
test still passes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 18:28:31 +02:00
Till JS
343804b25c refactor(cycles): make date formatting locale-aware
Replace hardcoded 'de-DE' toLocaleDateString calls across ListView,
CyclesWidget, and pure helpers with the active svelte-i18n locale.

Pure helpers in queries.ts now take their locale (and for relative
dates, their labels) as parameters so they stay pure and testable:

- formatLogDate(iso, labels, dateLocale)
- groupLogsByMonth(logs, dateLocale)
- New RelativeDateLabels type, exported from the module barrel

ListView builds relativeLabels from $_ and threads dateLocale through;
CyclesWidget does the same using a tiny $locale-derived helper.

New i18n keys cycles.relativeDate.{today,yesterday,daysAgo} across
all five locales (real de/en translations, stubs for it/fr/es).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 18:23:58 +02:00
Till JS
1ba5948ce5 feat(mana/web): encryption foundation — phase 1 (no-op)
Lays the groundwork for selective field-level encryption-at-rest in the
data layer. Phase 1 ships ONLY the building blocks; nothing is actually
encrypted yet (every registry entry has enabled:false), so this commit
is a no-op for app behaviour and safe to merge.

New module: src/lib/data/crypto/

aes.ts — pure Web Crypto AES-GCM-256 wrap/unwrap
  - wrapValue / unwrapValue with format-versioned envelope
    `enc:1:<base64-iv>.<base64-ct>` — one-scan detection, survives
    JSON.stringify on the sync wire, ~1.4× original byte length.
  - JSON-stringifies the input so any value type works (string, number,
    object, array). null/undefined pass through unchanged so optional
    fields don't need a guard at every call site.
  - Authenticated encryption: tampered ciphertext throws on decrypt.
  - generateMasterKey / importMasterKey / exportMasterKey for the
    Phase 2 server-side vault flow.
  - toBufferSource() helper works around the TS 5.7 Uint8Array generic
    parameterisation that broke the WebCrypto BufferSource overloads.

key-provider.ts — pluggable master-key source
  - KeyProvider interface (getKey, isUnlocked, onChange).
  - NullKeyProvider (default): always-locked, encryption call sites
    silently skip. Safe for the rollout window where individual tables
    are still flipping enabled:true.
  - MemoryKeyProvider: holds a CryptoKey in process memory only,
    notifies subscribers on lock/unlock transitions, sets a sentinel
    in sessionStorage so the UI can detect the unlock state on hard
    reload before the vault fetch completes.
  - setKeyProvider / getKeyProvider / getActiveKey / isVaultUnlocked
    are the boundary the rest of the data layer calls — no direct
    references to the concrete provider.

registry.ts — strict per-table allowlist
  - 30 tables registered, all enabled:false in Phase 1.
  - Field selection rule: encrypt user-typed text, transcripts, PII,
    free-form notes; leave IDs, timestamps, status flags, foreign
    keys, sort keys plaintext so the query/index/sync layer keeps
    working unchanged.
  - getEncryptedFields(table) returns null for the common (disabled)
    case so the Dexie hook hot-path stays allocation-free.
  - hasAnyEncryption() lets the boot path skip the vault fetch
    entirely while everything is still disabled.

index.ts — barrel export so consumers don't reach into sub-files.

aes.test.ts — 31 tests covering:
  - isEncrypted detection (string prefix, non-strings, wrong version)
  - wrap/unwrap roundtrip for string, empty string, unicode, object,
    array, number, boolean, 10KB blob, null, undefined, plaintext
    pass-through, null/undefined unwrap pass-through
  - IV uniqueness across repeated wraps of the same plaintext
  - Wrong-key rejection
  - Tampered-ciphertext rejection (auth tag mismatch)
  - Malformed-blob handling (missing iv/ct separator)
  - importMasterKey / exportMasterKey raw byte roundtrip
  - importMasterKey rejects non-32-byte input
  - KeyProvider lifecycle: NullKeyProvider default, MemoryKeyProvider
    set/get, listener fires only on transitions, dispose unsubscribes
  - Registry: returns null for unregistered/disabled tables, every
    entry has non-empty + duplicate-free fields list, hasAnyEncryption
    returns false in Phase 1

All tests pass against Node 20 native Web Crypto. No fake-indexeddb
needed — the foundation is pure functions over crypto.subtle.

Verified: 31/31 new tests + 291/291 full mana/web suite passing.

Phase 2: mana-auth server-side vault (encryption_vaults table, KEK
loading, GET /me/encryption-key endpoint).
Phase 3: wire MemoryKeyProvider to the vault fetch on login, flip
registry entries to enabled:true table by table, extend Dexie hooks
to call wrapValue/unwrapValue on configured fields.
Phase 4: settings UI (lock state, key rotation, recovery code opt-in).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 18:19:41 +02:00
Till JS
9e802b1e17 feat(cycles): dashboard widget with phase + countdown
Add a CyclesWidget that appears on the unified dashboard. Shows the
current phase as a colored badge, the cycle day, a big-number
countdown to the next period, and the predicted next-period date.
Clickable — links to /cycles.

- New CyclesWidget.svelte under modules/core/widgets using liveQuery
  against the cycles table
- Registered via WIDGET_REGISTRY + widgetComponents map
- WidgetType union + requiredBackend union both extended
- Existing dashboard.test.ts whitelist updated for the new backend
- i18n keys dashboard.widgets.cycles.{title,description,empty,open}
  added across all 5 locales

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 17:37:27 +02:00
Till JS
0896b1afd1 test(cycles): i18n key parity across all 5 locales
Loads de/en/it/fr/es cycles locale files and asserts their flattened
key paths are identical. Catches stub copies drifting silently when
new keys are added to de/en and forgotten in the others.

Also asserts every leaf value is a non-empty string so a missing
translation can't masquerade as null or an empty string.

Uses 'de' as the reference and renames vitest's 'it' to 'test' to
avoid shadowing the 'it.json' import.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 17:12:17 +02:00
Till JS
b0a9dfeedb feat(cycles): month calendar view with phase coloring
Add a CycleCalendar component above the edit sections in the
workbench ListView. Shows a 7×6 month grid with each day colored by
its derived phase, small flow markers on days with bleeding, the
current day outlined, and the edit target highlighted with a ring.

- Prev/next month buttons and a clickable header to jump back to
  the current month
- Monday-first week, weekday labels localized via locale store
- Clicking any day switches editingDate so the flow/mood/symptom
  controls below update that day directly
- Collapsible via a +/− toggle in the section header
- i18n keys for calendar.title/prev/next; de + en translated,
  it/fr/es mirrored from en

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 17:05:20 +02:00
Till JS
e7585fb870 fix(mana-events): cascade rate buckets when an event is unpublished
Add an ON DELETE CASCADE FK from rsvp_rate_buckets.token to
events_published.token. Without it, deleting a snapshot left orphaned
rate-limit rows behind, slowly leaking storage. Verified with a
direct SQL cascade test.
2026-04-07 16:20:05 +02:00
Till JS
59a9c05872 feat(cycles): symptom management UI
Add a modal to create, rename, recolor, and delete custom symptoms
without leaving the workbench view. Opens from a small "Verwalten"
button next to the Symptoms section header.

- New SymptomManager.svelte component wired to symptomsStore
- Inline edit mode with name + category select
- Delete with confirm (shows current name)
- i18n keys for manager strings + symptomCategory labels, de/en
  translated, it/fr/es mirrored from en

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 16:19:29 +02:00
Till JS
b97e2b5c6e test(cycles): integration tests with fake-indexeddb
24 tests covering the complex store interactions that pure-function
tests cannot reach:

- cyclesStore.createCycle auto-closes the previous open cycle and
  computes length, but leaves future cycles untouched when backfilling
- cyclesStore.setPeriodEnd separates "end of bleeding" from endDate
- dayLogsStore.logDay upserts per date (no duplicates even across
  multiple partial updates)
- Auto-start cycle fires on bleeding flow with no history or after a
  closed cycle >= 10 days old, but NOT for spotting or mid-cycle bleeds
- Auto-end period sets periodEndDate after 2 dry days, does not
  re-trigger on already-ended cycles
- Symptom reference counters adjust correctly when a log is created,
  updated (adds/removes symptoms), and deleted
- autoAssignCycle retroactively attaches orphan logs to a newly
  created cycle

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 16:11:04 +02:00
Till JS
f7a5bb841e fix(dreams): macOS-aware mic deny message + force-retry escape hatch
The previous "click the lock icon" advice is wrong on macOS, where
"sticky deny" usually originates from the system-level Privacy &
Security setting, not a per-site browser setting. There is no lock
icon to click and the user has no obvious next step.

Now:

- The denied message detects macOS/iOS via navigator.platform and
  walks through the actual fix path: System Settings → Privacy &
  Security → Microphone → enable browser → fully quit and restart it
  (Cmd+Q, not just close the tab — the permission only re-reads on
  cold start). Also points to chrome://settings/content/microphone
  as the second-most-likely culprit
- Non-mac path lists the same two causes in the right order
- Recorder.start now accepts { force: true } that bypasses the
  Permissions API pre-check and actually calls getUserMedia, so the
  raw browser error (NotAllowedError, SecurityError, etc) surfaces.
  Useful when the Permissions API is wrong or stale
- ListView shows a "Trotzdem versuchen" button next to the error
  text. Clicking it routes through the force path

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 16:10:44 +02:00
Till JS
a6828a16c2 fix(dreams): explain why the mic prompt isn't appearing
The voice capture used to surface a generic "Mikrofon-Zugriff
verweigert" whenever getUserMedia rejected, even though the actual
cause was usually one of three distinct, fixable conditions:

- Insecure context (http://192.168.x.x:5173 instead of localhost or
  https) — getUserMedia is silently unavailable, no prompt
- Sticky deny — user previously refused once, browser remembers and
  rejects without ever asking again
- Hardware: no microphone, busy mic, security policy

Now the recorder:

1. Checks window.isSecureContext first and tells the user to switch
   to https or localhost, naming the offending host
2. Queries the Permissions API for "microphone" before calling
   getUserMedia. If state is "denied", shows step-by-step recovery
   instructions (lock icon → mic → allow → reload) instead of pretending
   the user actively denied just now
3. Maps NotAllowedError / NotFoundError / NotReadableError /
   SecurityError to specific German messages, with the raw error as a
   fallback so the rest is still debuggable

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 15:55:05 +02:00
Till JS
63a6f62529 fix(dreams): proxy tolerates octet-stream + invalid form bodies
Two adjustments after end-to-end testing the voice flow against the
self-hosted mana-stt on the GPU server:

- Browser MediaRecorder always sets a clean audio/* mime type, but
  CLI clients (curl, scripts) often send application/octet-stream
  for audio files. Empty mime types should also pass through. Tighten
  rejection to clearly non-audio types only.
- await request.formData() throws on a missing/invalid body which
  surfaces as a SvelteKit 500 with "Internal Error". Catch it and
  return a 400 with a useful message instead.

Verified end-to-end with WhisperX large-v3-turbo: m4a (Anna voice)
transcribed in ~2.4s through the proxy.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 15:48:36 +02:00
Till JS
984c516788 feat(cycles): extract UI strings to svelte-i18n
Move all hardcoded German strings in the cycles ListView to per-module
translation files under lib/i18n/locales/cycles/. German and English
are fully translated; it/fr/es are stub copies of en.json for now.

Registers the cycles namespace in lib/i18n/index.ts alongside the other
modules. Phase labels, flow labels, mood labels, section headers,
buttons, placeholders, and the delete-confirmation message all flow
through $_('cycles.*').

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 15:45:27 +02:00
Till JS
82559f684c feat(mana/web): local activity log + periodic prune
New _activity table (V10 schema bump) capturing every local write to a
sync-tracked table, intended as the data backbone for a future
"What changed recently?" UI and per-record history view.

Schema is deliberately tiny — no field diffs, no payloads — so the
disk footprint stays bounded:
  ++id, createdAt, appId, collection, recordId, op, userId
plus compound indexes [appId+createdAt] and [collection+recordId] for
the per-app feed and per-record history paths.

Population
  database.ts trackActivity() helper is called from the same Dexie
  creating/updating hooks that already drive _pendingChanges. Lives
  next to trackPendingChange to share the db reference and avoid an
  import cycle with activity.ts. Server-applied changes are skipped
  (the apply lock guards both writers) so the feed reflects local
  user intent rather than sync echo. Soft deletes (deletedAt set on
  an update) are recorded as op:'delete'.

Read API (activity.ts)
  - getRecentActivity({ appId?, collection?, recordId?, limit? })
    walks the appropriate compound index in reverse and short-
    circuits on the limit, so cost is O(limit) regardless of total
    log size. Always scoped to the active user via getEffectiveUserId.
  - pruneActivityLog() drops entries >90d old + caps the table at
    ACTIVITY_MAX_ENTRIES (10k) by FIFO.

Scheduling
  data-layer-listeners.ts now runs pruneActivityLog alongside the
  existing tombstone cleanup (boot + 24h interval), with a separate
  Sentry tag so failures of one job don't mask the other.

Tests
  6 new tests in activity.test.ts cover insert / update / delete
  hook propagation, appId filter, multi-user isolation, the limit
  option, and TTL pruning. All pass against fake-indexeddb.

Drive-by
  vite.config.ts gains a `test.exclude` for `e2e/**` so the new
  Playwright specs the events module shipped don't crash vitest with
  `test.afterAll() not expected here`. Two pre-existing failures
  unrelated to this audit are now also out of the way.

Verified: 22/22 test files, 220/220 tests passing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 15:36:37 +02:00
Till JS
ad0215863d perf(mana/web): pipeline SSE reads against sequential apply
Two improvements to the SSE event loop in connectSSE:

1. Read/apply pipelining
   The previous loop did read → parse → await applyServerChanges →
   read. A slow apply blocked the network reader, so each event
   incurred the latency of the previous event's IndexedDB write
   before the next chunk could even start streaming in.

   Now apply work is enqueued onto a sequential promise chain
   (applyChain) and the read loop returns to draining the network
   immediately. LWW correctness still requires in-order application,
   so the chain serialises applies — the win is just decoupling I/O
   from disk work, not parallelism. The chain is awaited once at the
   end so the SSE state never resumes from a cursor that hasn't been
   written.

2. Allocation-light parser
   indexOf/slice replaces split('\n\n') and split('\n'). The previous
   parser allocated a fresh array of strings on every chunk; the new
   one walks the rolling buffer in place and only materialises the
   one event block currently being inspected. Same complexity, less
   GC pressure on busy streams.

Drive-by: tightens the JSON.parse error handling to skip malformed
events explicitly instead of swallowing them inside an outer try.

Verified: 20/20 sync.test.ts still passing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 14:57:21 +02:00
Till JS
333855c502 feat(cycles): edit and delete past day entries
Click any row in the recent-entries list to switch the editing target
to that day. The flow/mood/symptom/temperature/notes controls then
update that past entry instead of today, with a pink banner showing
which day is being edited and offering 'back to today' and 'delete'
buttons. Confirmation dialog prevents accidental deletes.

Implementation: editingDate signal drives all logDay() calls and a
derived editingLog from useAllDayLogs() avoids creating per-date
queries. The dayLogsStore.deleteLog() soft-deletes via deletedAt.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 14:55:17 +02:00
Till JS
42c9eb1e17 perf(mana/web): index updatedAt for recent-X dashboard widgets
Schema bump V9 adds an updatedAt secondary index to the six tables
that the cross-app dashboard widgets use for "recent N" lookups:
conversations, images, presiDecks, documents, songs, mukkePlaylists.
Dexie builds the index lazily on first open — no migration code,
no data touched.

Recent-query refactor:
  useRecentConversations
  useRecentImages
  useRecentDecks
  useRecentDocuments

  All four switched from `toArray() + JS sort + slice` to
  `orderBy('updatedAt').reverse().filter().limit()`. Dexie walks the
  BTree backwards and short-circuits as soon as `limit` matches
  accumulate, so the cost is O(limit + filtered) instead of O(table).

  For a dashboard with thousands of stored conversations or images,
  the dashboard widget previously read every record on every render
  (liveQuery re-runs on any write). Now it stops after 5–6 hits.

Verified: 20/20 sync.test.ts still passing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 14:55:11 +02:00
Till JS
473b8c0091 feat(cycles): auto-detect period start and end
When the user logs a bleeding flow (light/medium/heavy) and the previous
cycle ended at least 10 days ago (or no cycle exists), automatically
create a new cycle. When the user logs 'none' for at least 2 consecutive
days after the last bleeding day in an open cycle, automatically set
periodEndDate to that last bleeding day.

Heuristics live in utils/auto-detect.ts as pure functions and are wired
into dayLogsStore.logDay. Conservative thresholds avoid false positives
for mid-cycle spotting and partial bleeding patterns. 18 unit tests
cover the edge cases.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 14:52:06 +02:00
Till JS
85fda7b5df fix(mana/web): three runtime regressions from sprint 1-3 data layer rewrite
1. database.ts — defer pending-change writes out of the user transaction.
   `taskTable.add()` opens an implicit Dexie transaction scoped only to
   `tasks`. The creating-hook then tried to write to `_pendingChanges`,
   which is not in scope, throwing `NotFoundError: object store not in
   scope` and breaking every create across todo/calendar/contacts/etc.
   `queueMicrotask` is not enough — Dexie binds the active transaction
   to the current zone via Promise scheduling and treats microtasks as
   "still inside". `setTimeout(0)` breaks out cleanly so the deferred
   add() spawns its own implicit transaction.

2. workbench/AppPage.svelte — guard ListView reload by appId.
   The list-loader $effect read `app` (a $derived of getApp(appId)) and
   on every reactive churn cleared `ListComponent = null`, making the
   whole carousel flash a spinner. After a task create, liveQuery churn
   propagated up enough to retrigger this effect, which looked exactly
   like a full page reload to the user. Now we only reload when appId
   itself changes, with a stale-load guard for out-of-order awaits.

3. zitare/ListView.svelte — pull `quotesStore.initialize()` out of $effect.
   The effect called initialize() (which writes `currentQuote` $state)
   and then read `currentQuote` back, creating a classic write-then-read
   loop that hit `effect_update_depth_exceeded`. Initialize now runs in
   onMount; the effect is read-only.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 14:50:19 +02:00
Till JS
ae648650ea test(mana/web): unbreak three pre-existing test files
base-client.test.ts
  Source had been localised to German (Sitzung abgelaufen,
  Keine Berechtigung, Server-Fehler (500)) but the test still
  asserted on the old English strings. Updates the assertions
  to the German substrings so a future copy tweak doesn't
  break them again.

dashboard.test.ts
  Widget registry has grown from 16 to 22 entries and the
  required-backend list now includes nutriphi and planta. The
  hard count assertion is replaced with a >=16 floor so adding
  widgets no longer requires updating the test on every PR.

content/help/index.test.ts
  getManaHelpContent() routes through svelte-i18n's t() helper.
  In the test env the i18n store was uninitialised, so the
  helper returned bare key strings and the .split(',') on a
  missing tags entry threw. Adds a beforeAll that registers
  the help dictionary for both de and en and awaits waitLocale
  so the helper resolves real values.

Verified: 196/196 tests across 20 files now passing
(was 154/163 before this commit).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 14:48:30 +02:00
Till JS
578c9f3397 feat(dreams): voice capture via mana-stt
Adds a one-tap voice recorder at the top of the Dreams module. Speak
your dream right after waking, the audio is sent through a server-side
proxy to mana-stt, and the transcript appears in the entry as soon as
it lands.

- New /api/v1/dreams/transcribe SvelteKit server route proxies the
  upload to mana-stt with the server-held MANA_STT_API_KEY (never
  exposed to the browser); validates mime, size, missing config
- Adds MANA_STT_URL + MANA_STT_API_KEY to the mana-web env config in
  generate-env.mjs (private, not PUBLIC_ prefixed)
- New DreamRecorder class wraps MediaRecorder with reactive
  $state — status, elapsed timer, error; supports cancel
- dreamsStore.createFromVoice creates a placeholder dream with
  processingStatus='transcribing' and kicks off the upload
- dreamsStore.transcribeBlob uploads, writes the result back into
  the dream, falls back to processingStatus='failed' on errors
- Adds processingStatus + processingError + audioDurationMs to
  LocalDream; backwards-compatible defaults in toDream
- Mic button in ListView with idle / requesting / recording
  (with elapsed timer + pulsing red) / stopping states
- Cancel button discards the in-flight recording
- Transcribing badge ●●● + failed ! badge on dream rows
- Inline editor shows live transcription status; while it's running
  and the user hasn't typed anything, the transcript folds into the
  edit buffer as soon as it arrives

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 14:39:11 +02:00
Till JS
836c9692c5 fix(events): tech debt — self-heal snapshots, tombstones, polling cleanup, RSVP i18n
- PublicRsvpList: collapse onMount/onDestroy/$effect into a single
  $effect with proper cleanup; eliminates the redundant interval init
  paths and the dead else-branch
- DetailView: re-push the snapshot to mana-events when a published
  event is opened, so any earlier fire-and-forget that lost a write
  silently self-heals
- New _eventsTombstones queue (db version 8): when unpublish/delete
  fails to remove the server snapshot, queue (eventId, token) for
  retry; ListView drains the queue on mount with capped attempts
- Public /rsvp/[token]: detect Accept-Language in +page.server.ts,
  pass lang to the page, and use a small inline DE/EN dict in
  strings.ts — no svelte-i18n on the public route
2026-04-07 14:36:11 +02:00
Till JS
fbab96c74b feat(cycles): add menstrual cycle tracking module
New unified-app module under apps/mana/apps/web/src/lib/modules/cycles.
Adds three Dexie tables (cycles, cycleDayLogs, cycleSymptoms) in db v7,
SYNC_APP_MAP entry, app-registry registration, branding (icon + entry +
APP_URLS), and a /cycles route.

Includes phase derivation (menstruation/follicular/ovulation/luteal),
heuristic next-period and fertile-window prediction (rolling mean over
last 6 cycles), 10 default symptoms, and 33 unit tests covering the
pure utilities.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 14:35:33 +02:00
Till JS
575c5c36fd feat(mana/web): subscribe data layer events to toasts + Sentry + scheduler
New data-layer-listeners.ts wires the fire-and-forget CustomEvents the
sync engine and quota helpers emit into the rest of the app:

- mana:storage-quota-exceeded
  → toast.info / .warning / .error depending on whether the recovery
    cleanup succeeded, and a Sentry capture for the failure cases.
- mana:sync-telemetry
  → push:error / pull:error are routed to captureException with the
    error category as a tag. Auth and network errors are downgraded to
    console.warn so they don't drown Sentry in expected token blips.
  → apply:malformed-drop becomes a captureMessage warning.
  → success events log to console.debug only when import.meta.env.DEV.
- Tombstone cleanup loop
  → cleanupTombstones() runs once on idle after boot, then every 24h.
    Errors caught locally and reported via captureException with a
    'tombstone-cleanup' tag. Soft-deleted rows older than 30 days are
    hard-purged so the IndexedDB doesn't grow unbounded.

Wired into the root layout's onMount: installDataLayerListeners()
returns a dispose function that removes both window listeners and
clears the cleanup interval.

Closes the audit's "no telemetry" + "no quota handling" + "tombstone
cleanup helper exists but unused" trio in one shot.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 14:34:18 +02:00
Till JS
771721ca30 feat(dreams): polish symbol library — sort, auto-save, merge, navigation
SymbolsView:
- Sort tabs (Häufigkeit / A-Z / Zuletzt) above the cloud
- More dramatic font scaling using sqrt easing for visual hierarchy
- "?" badge on symbols without a personal meaning, dimmed until hover
- "Zuletzt" sort shows the most recent dreamDate per symbol
- A-Z and Zuletzt switch the cloud to a vertical list layout
- Hides symbols whose count dropped to zero (e.g. after merge)

SymbolDetailView:
- Auto-save with 500ms debounce + transient "Gespeichert" hint
- Co-occurring chips are clickable and navigate to that symbol's detail
- Dream refs are clickable buttons; ListView passes onOpenDream so a
  click jumps back to the timeline and opens the dream for editing
- Manual merge UI: "Zusammenführen…" button reveals a select with all
  other symbols, confirmation dialog before merging
- Re-initializes edit buffer when navigating between symbols (lastInitId
  guard instead of one-shot initialized flag)

Helpers:
- getLastUsedBySymbol returns a Map of symbol → most recent dreamDate

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 14:28:05 +02:00
Till JS
216746721e feat(events): add mana-events service + public RSVP flow (Phase 1b)
New Hono+Bun service at services/mana-events on port 3065 with two
schemas in mana_platform: events_published (snapshots) and public_rsvps
(unauthenticated responses), plus a per-token hourly rate-limit bucket.

- Host endpoints (JWT) for publish/update/unpublish/list-rsvps
- Public endpoints for snapshot fetch + RSVP upsert with rate limiting
- New /rsvp/[token] page outside the auth gate, SSR-loads the snapshot
- Client store wires publishEvent/unpublishEvent to the server, syncs
  snapshot updates after edits, and deletes the snapshot on event delete
- DetailView polls GET /events/:id/rsvps every 30s while open and lets
  hosts import a public response into their local guest list
- generate-env, setup-databases.sh, .env.development, hooks.server.ts,
  package.json wired for local dev
2026-04-07 14:27:48 +02:00
Till JS
980a5e996c feat(dreams): symbol library with detail view, meaning, mood stats
Adds a Symbols view to the Dreams module — the long-term differentiator
that lets users build a personal symbol vocabulary instead of relying
on generic dream-dictionary entries.

- New view-mode tabs (Träume / Symbole) at the top of the Dreams view
- SymbolsView: wordcloud-style list of all symbols sized by frequency,
  with name search and inline color dots
- SymbolDetailView: editable name + personal meaning + color picker,
  mood distribution bars, co-occurring symbols, and chronological
  list of all dreams that reference the symbol
- dreamsStore.updateSymbol: rename propagates to all referencing dreams,
  collisions auto-merge with the existing symbol
- dreamsStore.deleteSymbol: removes the symbol from all dreams
- dreamsStore.mergeSymbols: rewrites references and sums counts
- New query helpers: getDreamsWithSymbol, getMoodDistribution,
  getCooccurringSymbols

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 14:22:17 +02:00
Till JS
feb1674203 docs(mana/web): mark sprints 1-4 complete in data layer audit
Updates DATA_LAYER_AUDIT.md to reflect the actual state after the
seven-commit audit pass. All critical (🔴) and high-priority (🟡)
items from the original audit are now closed; remaining 🟢 items are
listed in a Backlog section with clear next steps.

Status table at the top maps each sprint to its commit hash so the
audit doc is now self-referential — anyone reading it can jump
directly to the change that fixed each item.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 14:22:05 +02:00
Till JS
733dca45f1 fix(mana/web): sprint 4 — perf, quota, telemetry, indexed queries
Sprint 4.1 — per-table sync apply lock
  Replaces the global _applyingServerChanges boolean with a Set of
  currently-applying table names (beginApplyingTables / isApplyingTable).
  applyServerChanges now scopes the lock to exactly the tables it touches,
  so a user typing into chat while todo is syncing no longer has their
  write silently dropped from _pendingChanges. The legacy single-flag API
  is kept as a thin shim for backward compatibility.

Sprint 4.2 — IndexedDB quota handling
  - quota-detect.ts (no Dexie deps, importable from database.ts):
    isQuotaError() across browsers + Dexie wrapped errors,
    notifyQuotaExceeded() dispatches a CustomEvent the UI can subscribe to.
  - quota.ts (re-exports detect helpers + adds db-aware bits):
    cleanupTombstones() hard-deletes old soft-deleted rows to reclaim space,
    withQuotaRecovery() wraps a write op with one cleanup-and-retry pass.
  - applyServerChanges wraps each per-table transaction in a quota
    recovery loop. A full DB no longer crashes the pull.
  - The Dexie creating/updating hooks now write _pendingChanges via
    trackPendingChange(), which catches QuotaError on the fire-and-forget
    promise and surfaces the event instead of silently losing the entry.

Sprint 4.3 — sync telemetry events
  New sync-telemetry.ts emits a window CustomEvent for every push/pull
  lifecycle transition: push:start/ok/error, pull:start/ok/error,
  apply:malformed-drop, apply:done. Errors carry a coarse category
  (network/auth/http-5xx/http-4xx/parse/unknown) and durations are
  measured in ms. No record contents are emitted — safe to forward to
  Sentry / a debug HUD without leaking PII.

Sprint 4.4 — indexed queries on hot dashboard paths
  Three cross-app dashboard widgets that previously full-scanned every
  task / time block on every render now use indexed range queries:
    - useTodayTasks       → .where('dueDate').belowOrEqual(endOfToday)
    - useUpcomingTasks    → .where('dueDate').between(start, end)
    - useUpcomingEvents   → .where('startDate').between(now, future)
  useFavoriteContacts hits the indexed isFavorite column directly (with
  a number-or-boolean compound key for legacy / fresh records).

Verified: 20/20 tests in sync.test.ts still passing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 14:18:22 +02:00
Till JS
30022e82e1 feat(events): scaffold social events module (Phase 1a, local-only)
New 'events' module for planning gatherings with guest lists and RSVPs,
distinct from the personal calendar. Events surface in the calendar via
TimeBlock with sourceModule='events'. Guests, RSVPs and a publish stub
work fully local-first; the public RSVP server lands in Phase 1b.
2026-04-07 14:12:41 +02:00
Till JS
22d3d2b695 feat(dreams): quick wins — date/time picker, filter tabs, symbol filtering
- Filter tabs (All / Lucid / Nightmare / Recurring) above the dream list
- Symbol chips in the insights ribbon are clickable to filter the list
- Symbol chips on each dream row are clickable too, with active state
- Editor exposes dreamDate, bedtime and wakeTime via native pickers
- Sleep quality star rating in the editor (1–5, toggleable)
- Recurring-dream toggle alongside the lucid toggle
- Recurring badge on dream rows
- Dream row converted from <button> to div role=button so nested chip
  buttons are valid HTML

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 14:12:12 +02:00