feat: add store_versions.ts — localStorage schema versioning for ae_loc and ae_events_loc

Persistent stores grow and change over time. svelte-persisted-store deep-merges
old localStorage values with new defaults, so stale values (e.g. hash_prefix_length: 1)
silently survive schema changes and cause subtle bugs.

- src/lib/stores/store_versions.ts:
  Single source of truth for AE_LOC_VERSION / AE_EVENTS_LOC_VERSION.
  Side-effect on import: reads raw localStorage and wipes if __version mismatches.
  Must be imported first in ae_stores.ts and ae_events_stores.ts so the wipe
  happens before persisted() hydrates from localStorage.

- ae_stores.ts + ae_events_stores.ts:
  Import store_versions as first import; add __version to persisted store defaults.

- documentation/TODO__Agents.md:
  Added stores refactor task — both store files need a cleanup pass.

Bump AE_LOC_VERSION or AE_EVENTS_LOC_VERSION by 1 on breaking schema changes.
Non-breaking changes (new optional fields, default value tweaks) do not need a bump.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Scott Idem
2026-03-11 12:43:05 -04:00
parent ca91afbd9d
commit 241e05bc79
4 changed files with 79 additions and 0 deletions

View File

@@ -1,3 +1,7 @@
// store_versions MUST be first import — its side-effect wipes stale localStorage
// before svelte-persisted-store hydrates from it.
import { AE_LOC_VERSION } from '$lib/stores/store_versions';
import { persisted } from 'svelte-persisted-store';
import { readable, writable } from 'svelte/store';
@@ -62,6 +66,7 @@ const ver_idb = '2025-05-01_1445'; // Not currently used
// *** BEGIN *** Longer-term app data. This should be stored to local storage.
const ae_app_local_data_defaults: key_val = {
__version: AE_LOC_VERSION, // Schema version gate — see store_versions.ts
last_page_reload: null,
// last_idb_reload: null,
// last_cache_refresh: null, // Date.now()