src/holds the library source. Public exports are insrc/index.tsand the main module lives insrc/Mnemonic/(provider.tsx,use.ts,codecs.ts,types.ts,json-schema.ts,schema.ts).- Build outputs are emitted to
dist/(published viapackage.jsonfiles). Rebuilddist/after source changes (npm run build) before consumers can see them. - Configuration lives at the repo root:
tsconfig.json,tsup.config.ts,vitest.config.ts,vitest.setup.ts. website/contains the Docusaurus documentation site with its ownpackage.json. API reference is auto-generated from TypeDoc. Deployed to GitHub Pages via.github/workflows/deploy-docs.yml.README.mdcontains the public usage example.
npm run buildbuilds the package withtsupintodist/.npm run devrunstsup --watchfor continuous builds.npm run testruns the Vitest test suite once.npm run test:watchruns Vitest in watch mode.npm run lintruns TypeScript type-checking withtsc --noEmit.npm run formatformats all files with Prettier.npm run format:checkchecks formatting without writing.npm run docsgenerates API documentation with TypeDoc intodocs/.npm run docs:watchruns TypeDoc in watch mode for live preview.npm run docs:sitebuilds the Docusaurus documentation site (website/build/).npm run docs:site:startstarts the Docusaurus dev server for live editing.
- TypeScript, ES modules (
"type": "module"). - Indentation: 4 spaces. Prefer explicit types on public APIs in
src/index.tsandsrc/Mnemonic/exports. - File naming: lower-case with
.ts/.tsx; React hooks useuse*.ts(example:use.ts). - Keep exports centralized in
src/index.ts.
- Test runner: Vitest (
vitest.config.ts,vitest.setup.ts). - Place tests alongside source or in
src/with.test.ts/.test.tsxsuffixes. - Run all tests with
npm run testand focus during development withnpm run test:watch.
- No commit history exists yet. Use clear, imperative messages (e.g.,
Add Mnemonic headers). - PRs should include a concise summary, testing notes (
npm run test/npm run lint), and screenshots for UI changes.
- Releases are handled by GitHub Actions on tagged releases. Tag format:
vX.Y.Z(example:v0.1.0).
This file is generated by scripts/generate-agent-instructions.mjs. Edit website/docs/ai/* and run npm run docs:ai instead of editing this file directly.
useMnemonicKey(...)must run inside aMnemonicProvider.- Use
useMnemonicKeyOptional(...)fromreact-mnemonic/optionalonly when a reusable component may render without a provider and should degrade to local in-memory state instead of crashing. - Prefer
useMnemonicKey(...)over rawlocalStoragefor durable app or UI state. Use raw storage only in adapters, tests, or low-level library internals. - Every stored key is namespaced as
${namespace}.${key}in the underlying storage backend. defaultValueis required and defines the fallback when a key is absent or invalid.set(next)persists a new value for the key.reset()persistsdefaultValueagain.remove()deletes the key entirely, so the next read falls back todefaultValue.- Use
set(null)when "cleared" is a durable state that must survive reload. - Do not persist access tokens, refresh tokens, raw session IDs, or other auth credentials as durable UI state.
- Auth-scoped durable state should use a user-aware namespace and be cleared on logout or expiry.
- For multi-step wizards, persist user-authored draft values and derive completion from them; keep active step, validation errors, and submit-in-flight state ephemeral unless resume-on-reload is an explicit feature.
- For shopping carts, persist canonical line items and quantities; derive subtotal and item count instead of storing them, and treat empty-cart semantics separately from
remove(). - SSR is safe by default: the server renders
defaultValueunless you opt intossr.serverValue. - Schema migrations handle structural version upgrades.
reconcile(...)handles conditional read-time policy rewrites. StorageLikeis intentionally synchronous in beta 1.- Consumer code should import published values and types from
react-mnemonic, not internal paths or local ambient shims.
- Should this survive reload, or is it only runtime UI state?
- Is
nullmeaningfully different from a missing key? - Should other tabs stay in sync?
- Is SSR involved, and if so should the server render
defaultValue,ssr.serverValue, or delay hydration? - Is schema evolution likely enough to justify a versioned schema and migration path now?
- Theme Preference With Cross-Tab Sync
- Saved Filters With Durable Clear Intent
- Dismissible Announcement UI
- Durable Draft Content With Ephemeral Form Metadata
- Optional Persistence For Component Libraries
- Schema Upgrade With Migration Plus Reconciliation
- SSR Placeholder For Theme
- Auth-Aware Durable State With Automatic Cleanup
- Multi-Step Wizard With Durable Draft And Ephemeral Navigation
- Shopping Cart With Canonical Line Items And Derived Totals
- Treat
website/docs/ai/*as the canonical source. - Run
npm run docs:aiafter changing canonical AI docs. - Run
npm run ai:checkto verify generated instruction packs and retrieval artifacts are in sync.