refactor(credits): simplify credit system — remove productivity credits, guild pools, complex gift types

The credit system was overengineered for the local-first architecture:
- Productivity micro-credits (task/event/contact creation at 0.02 credits) made no sense
  since these operations happen locally in IndexedDB with zero server cost and were never enforced
- Guild pool system (6 DB tables, spending limits, membership checks) had no active users
- Gift system had 5 types (simple/personalized/split/first_come/riddle) when 2 suffice

Now credits are only charged for operations that actually cost money: AI API calls and
premium features (sync, exports). This makes the value proposition clear to users.

Changes:
- Remove 8 productivity operations + CreditCategory.PRODUCTIVITY from @mana/credits
- Delete guild pool service, routes, schema (3 files); remove guild refs from 8 backend files
- Simplify gifts to simple + personalized only; remove bcrypt/riddle/portions logic
- Update all frontend pages (credits dashboard, gift create/redeem, public gift page)
- Update shared-hono consumeCredits() to remove creditSource parameter
- Update mana-credits CLAUDE.md

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-04-10 19:08:42 +02:00
parent 29ad31c4ed
commit e068335dd4
32 changed files with 143 additions and 922 deletions

View file

@ -65,23 +65,38 @@ apps/{project}/apps/web/
### Derived Values with $derived
**CRITICAL: `$derived(expr)` vs `$derived.by(fn)`**
- `$derived(expression)` — takes a **single expression**. The value IS the expression result.
- `$derived.by(() => { ... return value; })` — takes a **function** (thunk). Use this when you need `if`/`switch`/`for` or multiple statements.
**Common mistake:** writing `$derived(() => { ... })` — this stores the arrow function itself as the value, not its return value. Every `{#if myDerived}` will be truthy (functions are always truthy), and `myDerived()` will fail with "not callable" at the type level.
```svelte
<script lang="ts">
let count = $state(0);
let items = $state<Item[]>([]);
// Computed value - updates automatically
// ✅ Single expression → $derived
const doubled = $derived(count * 2);
const itemCount = $derived(items.length);
const hasItems = $derived(items.length > 0);
// Complex derived
const sortedItems = $derived([...items].sort((a, b) => a.name.localeCompare(b.name)));
// Derived with conditions
// ✅ Ternary is still a single expression
const displayText = $derived(
count === 0 ? 'No items' : count === 1 ? '1 item' : `${count} items`
);
// ✅ Multi-statement logic → $derived.by
const filteredItems = $derived.by(() => {
if (!searchQuery.trim()) return items;
const q = searchQuery.toLowerCase();
return items.filter((i) => i.name.toLowerCase().includes(q));
});
// ❌ WRONG — stores the function, not the result!
// const filteredItems = $derived(() => { ... });
</script>
```