sisyo 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/LICENSE +16 -16
  2. package/README.md +167 -166
  3. package/bin/known-hashes.json +6 -1
  4. package/bin/sisyo.js +285 -285
  5. package/package.json +30 -30
  6. package/templates/.claude/rules/agents-and-tests.md +32 -24
  7. package/templates/.claude/rules/docs.md +19 -19
  8. package/templates/.claude/skills/fastapi-best-practices/ASYNC-PATTERNS.md +121 -121
  9. package/templates/.claude/skills/fastapi-best-practices/DATABASE.md +153 -153
  10. package/templates/.claude/skills/fastapi-best-practices/DEPENDENCIES.md +140 -140
  11. package/templates/.claude/skills/fastapi-best-practices/PROJECT-STRUCTURE.md +90 -90
  12. package/templates/.claude/skills/fastapi-best-practices/PYDANTIC-GUIDE.md +155 -155
  13. package/templates/.claude/skills/fastapi-best-practices/SKILL.md +123 -123
  14. package/templates/.claude/skills/g6-style/SKILL.md +125 -125
  15. package/templates/.claude/skills/g6-style/references/checks.md +58 -58
  16. package/templates/.claude/skills/g6-style/references/imagery.md +103 -103
  17. package/templates/.claude/skills/g6-style/references/motion.md +121 -121
  18. package/templates/.claude/skills/g6-style/references/sections.md +263 -263
  19. package/templates/.claude/skills/g6-style/references/tokens.md +197 -197
  20. package/templates/.claude/skills/hindsight/SKILL.md +175 -175
  21. package/templates/.claude/skills/hoang-auth/SKILL.md +188 -0
  22. package/templates/.claude/skills/html-docs/SKILL.md +207 -207
  23. package/templates/.claude/skills/i18n-multilang/SKILL.md +153 -153
  24. package/templates/.claude/skills/i18n-multilang/assets/languages.json +47 -47
  25. package/templates/.claude/skills/i18n-multilang/assets/plural-vectors.json +46 -46
  26. package/templates/.claude/skills/i18n-multilang/assets/project/README.md +17 -17
  27. package/templates/.claude/skills/i18n-multilang/assets/project/gitattributes.txt +6 -6
  28. package/templates/.claude/skills/i18n-multilang/assets/project/gitignore.txt +4 -4
  29. package/templates/.claude/skills/i18n-multilang/assets/project/glossary.json +6 -6
  30. package/templates/.claude/skills/i18n-multilang/assets/project/i18n.config.json +22 -22
  31. package/templates/.claude/skills/i18n-multilang/assets/project/locales/__source__/common.json +10 -10
  32. package/templates/.claude/skills/i18n-multilang/assets/project/notes/common.json +5 -5
  33. package/templates/.claude/skills/i18n-multilang/assets/project/style.md +20 -20
  34. package/templates/.claude/skills/i18n-multilang/references/format.md +100 -100
  35. package/templates/.claude/skills/i18n-multilang/references/languages.md +97 -97
  36. package/templates/.claude/skills/i18n-multilang/references/layout-and-versioning.md +256 -256
  37. package/templates/.claude/skills/i18n-multilang/references/numbers.md +161 -161
  38. package/templates/.claude/skills/i18n-multilang/references/platform-unity.md +142 -142
  39. package/templates/.claude/skills/i18n-multilang/references/platform-web.md +107 -107
  40. package/templates/.claude/skills/i18n-multilang/references/translation.md +143 -143
  41. package/templates/.claude/skills/i18n-multilang/references/voice.md +271 -271
  42. package/templates/.claude/skills/i18n-multilang/scripts/i18n.py +1041 -1041
  43. package/templates/.claude/skills/i18n-multilang/scripts/numwords.py +1013 -1013
  44. package/templates/.claude/skills/i18n-multilang/scripts/voice.py +478 -478
  45. package/templates/.claude/skills/neon-game-ui-ux-skill/COMPONENTS.md +490 -490
  46. package/templates/.claude/skills/neon-game-ui-ux-skill/GAMIFICATION.md +246 -246
  47. package/templates/.claude/skills/neon-game-ui-ux-skill/ICONS.md +249 -249
  48. package/templates/.claude/skills/neon-game-ui-ux-skill/LAYOUT-NAV.md +362 -362
  49. package/templates/.claude/skills/neon-game-ui-ux-skill/MOTION-A11Y.md +168 -168
  50. package/templates/.claude/skills/neon-game-ui-ux-skill/SKILL.md +137 -137
  51. package/templates/.claude/skills/neon-game-ui-ux-skill/TOKENS.md +323 -323
  52. package/templates/.claude/skills/react-page-oriented/SKILL.md +407 -407
  53. package/templates/.claude/skills/react-page-oriented/triggers.md +12 -12
  54. package/templates/.claude/skills/terraform-best-practices/SKILL.md +341 -341
  55. package/templates/.claude/skills/typesafe-jev/SKILL.md +148 -148
  56. package/templates/.claude/skills/vibe-docs/SKILL.md +242 -242
  57. package/templates/SISYO.md +37 -37
  58. package/templates/docs/99_progress/features.md +7 -7
  59. package/templates/docs/99_progress/handoff.md +19 -19
  60. package/templates/docs/99_progress/todo.md +15 -15
  61. package/templates/docs/MAP.md +26 -26
@@ -1,246 +1,246 @@
1
- # Gamification
2
-
3
- The game layer as reusable UX patterns, the honesty rules that keep it from turning into a dark pattern, and the data
4
- contract the UI expects from a backend. The UI only **displays** game state; every number is decided by the server.
5
- The components that draw these patterns are described in `COMPONENTS.md`.
6
-
7
- ## 1. The loop
8
-
9
- ```
10
- action (answer, finish, save, claim)
11
- → server grants XP, returns a Reward
12
- → burst flies from the control to the HUD (the moment)
13
- → HUD numbers update, path / quest advance (the state)
14
- → next step is highlighted (the pull)
15
- ```
16
-
17
- Each element answers one question for the user:
18
-
19
- | Element | Question | Where |
20
- |---|---|---|
21
- | XP + level | "Am I getting anywhere overall?" | HUD: level hexagon + XP bar |
22
- | Daily goal | "Have I done enough today?" | HUD ring; centre dial of the bottom bar |
23
- | Streak | "Am I consistent?" | HUD pill |
24
- | Daily path | "What do I do next?" | Home hero card |
25
- | Quests | "What else could I do today?" | Home side column |
26
- | Achievements | "What have I collected over months?" | Home / profile grid |
27
-
28
- If a product cannot answer one of these questions honestly (for example there is no meaningful daily unit), leave that
29
- element out. A streak in an app people use twice a month is noise.
30
-
31
- ## 2. XP
32
-
33
- - XP is granted for **completed, meaningful actions**, by the server, in small integers (LenS: 5 for a
34
- correct answer, 1 for a wrong one, 2 per answered question up to 10 for finishing a session, 30 for the daily
35
- chest, 10-20 for a quest).
36
- - **Every repeatable source has a bound**: a per-session maximum and a number of paid repetitions per local day
37
- (LenS pays 5 session-completion bonuses a day; later sessions still work but earn 0). Without bounds a loop
38
- of tiny sessions farms XP, levels and count-based achievements, and the numbers stop meaning anything.
39
- - **Every grant is idempotent.** A grant has a `(source, source_id)` key that is unique per user (examples:
40
- `quiz_complete` + session id; `quest` + `<local date>:<quest id>`; `chest` + local date; `word_added` + the
41
- normalised word). Repeating the request returns a Reward with `xp_earned: 0, duplicate: true` and the current
42
- totals. The UI can therefore retry and double-tap safely, and must treat `duplicate` as "nothing to celebrate".
43
- - Wrong or failed attempts may earn a token amount (1 XP) so that effort is acknowledged, but never as much as
44
- success.
45
-
46
- ## 3. Levels
47
-
48
- - Thresholds are cumulative XP: `0, 100, 250, 500, 1000, 2000, 3500, 5500, 8000, 12000, 17000, 25000`, then a fixed
49
- step (10 000) per level, so levels never end and the bar never sticks at a cap.
50
- - The API sends `level`, `total_xp`, `level_floor`, `next_level_xp`. The XP bar gets
51
- `current = max(0, total_xp - level_floor)` and `span = max(1, next_level_xp - level_floor)` and shows
52
- `current / span`. **Do not** compute `total_xp / next_level_xp`: thresholds are cumulative, so that bar starts each
53
- level half full and is wrong.
54
- - The client never holds the level table (only a dev gallery may, to simulate). One source of truth avoids a HUD that
55
- disagrees with the server after a rule change.
56
- - A level-up is the top of the intensity ladder (§8): a modal, once, with what was unlocked if anything.
57
-
58
- ## 4. Streak
59
-
60
- Three states, decided by the server from the user's **local** day:
61
-
62
- | State | Meaning | HUD | Copy |
63
- |---|---|---|---|
64
- | `done` | Active today | Ember ring + glow, flame glows | "You were active today. See you tomorrow!" |
65
- | `at_risk` | Last active yesterday, nothing yet today | Amber ring, flame floats 3 times | "Earn any XP today to keep your streak alive." |
66
- | `zero` | Lapsed or never started | Grey, flame mono | "Earn any XP today to start a new streak." |
67
-
68
- - The first XP of a local day extends the streak (`Reward.streak_extended`).
69
- - **Read-decay**: a lapsed streak reads as `0 / zero` immediately, before the next activity; the stored counter is
70
- only reset on the next grant. The user never sees a streak that is already lost.
71
- - The "local day" comes from a time zone stored in the user's settings (UTC when unset), not from the request's
72
- clock. A user who travels west must not lose a day: a last-active day in the future counts as today.
73
- - `at_risk` is information, not alarm: amber, a short finite animation, no countdown timer, no push of guilt.
74
- A lapsed streak is shown plainly; the longest streak stays visible ("best 21") so past effort is not erased.
75
-
76
- ## 5. Daily goal
77
-
78
- - Ratio = `min(1, today.xp / today.goal)`; a goal of 0 counts as reached (ratio 1). The goal is a **user setting**.
79
- - Shown as a 34 px ring in the HUD with the percentage inside; at 100 % the ring's own check pops in.
80
- - The same ring is the centre "dial" of the mobile bottom bar (LAYOUT-NAV.md): the thing the user came to do is the
81
- biggest, most central control, and it shows how much of today is done.
82
- - Reaching the goal (`Reward.goal_reached_now`) is a medium moment: toast-level, not a modal.
83
-
84
- ## 6. Daily path and chest
85
-
86
- A short fixed sequence of today's activities (LenS: Review → Quiz → Read → Speak) ending in a chest.
87
-
88
- - Each step has a goal measured from today's counts; the server returns per step
89
- `{ id, label, state: done | in_progress | current | todo, progress 0..1, to }`.
90
- - Done steps stay done. The **first** open step is `current` (or `in_progress` once it has partial progress); later
91
- open steps are `todo`, which the UI shows as **locked** with the hint "Finish <current> to unlock". The lock is a
92
- focus device: only one thing is asked at a time. (Whether locked steps are really unreachable is a product choice;
93
- in LenS the pages stay reachable from the navigation, the path only recommends an order.)
94
- - The chest is `locked` until every step is done, then `ready`, then `claimed`; one per local day, a fixed amount
95
- shown in advance (`+30 XP`). Claiming is an explicit tap on a CTA that replaces "Continue": the user opens it.
96
- - Hero card copy follows the state: "Start today's path" → "2 of 4 steps done · Next up: ..." → "Path complete!
97
- Open your chest to collect +30 XP" → "Every step is done. A new path unlocks tomorrow."
98
- - After the claim the chest button disappears; if it was activated from the keyboard, move focus to the card heading
99
- (`tabIndex={-1}`) so focus does not fall to `<body>`.
100
-
101
- ## 7. Quests and achievements
102
-
103
- **Quests** (daily, 3 per day): one constant ("Earn {daily goal} XP") plus two drawn from a pool by a hash of the
104
- date, so they are the same for everyone that day and stable across servers, never two with the same metric.
105
-
106
- - `{ id, title, icon, tone, progress, goal, reward_xp, state: active | complete | claimed }`; `progress` is capped at
107
- `goal`.
108
- - A complete quest must be **claimed** by the user (gold Claim keycap). The claim is the reward moment; granting
109
- silently on completion wastes it.
110
- - Claim errors: 404 (not one of today's quests: the day rolled over) and 409 (not complete) mean the client's view is
111
- stale. Do not show an error toast for these; refetch and show the server's view.
112
- - Optimistic step: mark the quest `claimed` in the cache as soon as the claim succeeds; the refetch confirms it.
113
-
114
- **Achievements** (long-term): a fixed catalog `{ key, name, description, tier, icon }` plus per user
115
- `{ earned_at, progress 0..1 }`.
116
-
117
- - Tiers map to effort: first steps bronze; hundreds / a week silver; many hundreds / a month gold; extremes rare.
118
- - Progress for "reach level N" is measured in XP, so the ring moves with every grant.
119
- - Newly earned ones arrive in `Reward.new_achievements` and are toasted; the grid shows a NEW ribbon once.
120
- - Locked achievements show their name and goal. Use `secret` sparingly, for surprises, not to hide requirements.
121
-
122
- ## 8. Reward moments: the intensity ladder
123
-
124
- | Level | Trigger | What plays | Blocks input? |
125
- |---|---|---|---|
126
- | 0 | Any XP < 50 | Burst dots + `+N XP` chip flies to the XP bar, bar pulses; screen-reader announcement only | No |
127
- | 1 | XP >= 50, achievement, goal reached | The same + a toast (2.5 s) | No |
128
- | 2 | Quest complete (waiting for claim) | Card turns gold, Claim button pulses, sheen loops | No |
129
- | 3 | Chest ready | Node pops in with a gold burst; hero CTA becomes "Open chest" | No |
130
- | 4 | Level up | Modal after the chip lands: rays, badge opens, Continue | Yes, dismissible at once (Esc, scrim, Continue) |
131
-
132
- Rules:
133
-
134
- - **Match intensity to rarity.** If every answer opened a modal, the level-up would mean nothing and the user would
135
- be interrupted hundreds of times a day.
136
- - **Merge.** Gains within 400 ms become one burst with the sum. Several grants from one action must not stack three
137
- animations.
138
- - **The reward lands on the HUD.** The chip flies to the XP bar and the bar updates when it arrives: the user sees
139
- where the number went. Updating the HUD first and animating afterwards breaks the cause-and-effect.
140
- - **Start from where the user acted.** Pass the pressed control as the anchor, or better its centre point, measured
141
- **at press time**: the reward arrives after the request, when the control may have re-rendered or gone (a Claim
142
- button becomes "Claimed").
143
- - **Never block for more than 700 ms**, never require watching. Level 4 is the only modal and closes on the first key.
144
- - Reduced motion: the chip fades in place, numbers change instantly, colour and text feedback stay.
145
-
146
- ## 9. Honesty rules
147
-
148
- 1. **No fake scarcity.** No invented countdowns, no "only 2 left", no rewards that expire to create pressure. The
149
- only real deadline is the end of the local day, and it is stated plainly.
150
- 2. **No loss framing beyond the facts.** "Earn any XP today to keep your streak" is a fact. "You are about to lose
151
- everything" is not acceptable copy.
152
- 3. **Rewards are shown before they are earned** (`+30 XP` on the chest, `+20 XP` on the quest) and paid exactly.
153
- No random amounts presented as fixed, no bait.
154
- 4. **The server is the only authority.** The client never adds XP locally except as a short optimistic patch that
155
- a refetch then replaces. A client-side counter that drifts from the server is a bug the user will notice.
156
- 5. **Idempotent grants** (§2), so a retry or a double tap can never pay twice or show a second celebration.
157
- 6. **Farming is closed** by per-session and per-day bounds, not by hiding the activity. A capped action still works,
158
- it just earns nothing more today, and the UI can say so.
159
- 7. **Nothing is gated behind the game.** Locks in the path order the day; they do not withhold features the user
160
- has. XP buys no advantage that can also be bought with money.
161
- 8. **Opt-out friendly.** The HUD is compact; celebrations are skippable; reduced motion is respected. A user who
162
- ignores the game still gets a usable product.
163
-
164
- ## 10. Data contract
165
-
166
- ### HUD read model: `GET /gamification/hud`
167
-
168
- One request returns everything the shell and the home page show.
169
-
170
- | Field | Type | Meaning |
171
- |---|---|---|
172
- | `level` | integer | Current level |
173
- | `total_xp` | integer | Lifetime XP |
174
- | `level_floor` | integer | Cumulative XP where this level started |
175
- | `next_level_xp` | integer | Cumulative XP where the next level starts |
176
- | `streak.current` | integer | Days in the streak (0 when lapsed: read-decay, §4) |
177
- | `streak.longest` | integer | Best streak ever |
178
- | `streak.state` | `done` \| `at_risk` \| `zero` | §4 |
179
- | `today.date` | `YYYY-MM-DD` | The user's local day |
180
- | `today.xp` | integer | XP earned today |
181
- | `today.goal` | integer | The user's daily goal |
182
- | `today.<counts>` | integers | Product-specific counts of today (LenS: quizzes, readings, speaking seconds, dictations, words reviewed, words added) |
183
- | `path[]` | list | Today's steps, in order |
184
- | `path[].id` | string | Stable step id |
185
- | `path[].label` | string | Short label under the node |
186
- | `path[].state` | `done` \| `in_progress` \| `current` \| `todo` | `todo` is drawn as locked |
187
- | `path[].progress` | 0..1 | Ring around an in-progress node |
188
- | `path[].to` | string | Route of the step |
189
- | `quests[]` | list | Today's quests |
190
- | `quests[].id`, `.title` | string | |
191
- | `quests[].icon`, `.tone` | string | Names from the icon registry and the tone list |
192
- | `quests[].progress`, `.goal` | integer | `progress` is capped at `goal` |
193
- | `quests[].reward_xp` | integer | Shown before it is earned |
194
- | `quests[].state` | `active` \| `complete` \| `claimed` | |
195
- | `chest.state` | `locked` \| `ready` \| `claimed` | |
196
- | `chest.xp` | integer | The chest's fixed reward |
197
-
198
- - One read model, not five endpoints: the top bar, its panel, the bottom bar's dial and the home page share one
199
- cached query (stale time about 30 s) and can never disagree.
200
- - `icon` and `tone` come from the server as names. Map unknown names to a fallback on the client; a server deploy
201
- must not be able to crash the page.
202
- - The server computes "today" and every state. The client does no date arithmetic.
203
- - Mapping to the components: the API's `at_risk` is the pill's `at-risk`; a path step's `todo` is the node's
204
- `locked`, `in_progress` is `in-progress`; the chest becomes the last node of the path with state `chest` (the node
205
- shows "ready" when every earlier step is done).
206
-
207
- ### Reward: returned by every response that grants XP
208
-
209
- | Field | Type | Meaning |
210
- |---|---|---|
211
- | `xp_earned` | integer | The delta; 0 for a repeat |
212
- | `total_xp`, `level`, `level_floor`, `next_level_xp` | integers | The **new totals**, same meaning as in the HUD |
213
- | `leveled_up` | boolean | This grant crossed a level threshold |
214
- | `streak` | integer | The streak after this grant |
215
- | `streak_extended` | boolean | First activity of the local day |
216
- | `new_achievements[]` | `{ key, name, description, tier, icon }` | Earned by this grant |
217
- | `daily_xp`, `daily_goal` | integers | Today's XP after this grant, and the goal |
218
- | `goal_reached_now` | boolean | This grant crossed the daily goal |
219
- | `duplicate` | boolean | This grant was already paid (§2) |
220
-
221
- A Reward carries the new totals, not only the delta, so the client can patch the HUD without arithmetic.
222
-
223
- Other endpoints in LenS: `POST /gamification/quests/{id}/claim` and `POST /gamification/chest/claim` (both return a
224
- Reward; the chest answers 409 until every step is done), `GET /gamification/achievements/catalog` (each catalog item
225
- plus `earned_at` and `progress` 0..1), `GET /gamification/activity?days=N` (per-day rows for a heatmap, 1 to 120
226
- days; days without activity have no row).
227
-
228
- ### Client wiring
229
-
230
- One function, "play a reward", is called from the success handler of every mutation that can grant XP, with the
231
- Reward and the anchor captured at press time:
232
-
233
- 1. The reward is missing or `duplicate`: invalidate the game queries and stop. Nothing to celebrate.
234
- 2. If `xp_earned > 0`, or it levelled up, or it brought achievements: call the reward system
235
- (`rewardXp({ xp: xp_earned, anchor, levelUp: leveled_up ? { level } : undefined, achievements })`,
236
- COMPONENTS.md).
237
- 3. After **1100 ms** when XP was earned (the 400 ms merge window + the 700 ms flight; otherwise at once): write the
238
- new totals into the cached HUD and invalidate every game query. The bar fills at the moment the chip visibly
239
- arrives; the refetch then replaces the optimistic values.
240
- 4. The optimistic patch copies `level`, `total_xp`, `level_floor`, `next_level_xp`; sets the streak to
241
- `{ current: reward.streak, longest: max(old longest, reward.streak), state: 'done' }`; sets `today.xp` and
242
- `today.goal` from `daily_xp` / `daily_goal`. It **never moves totals backwards**: when
243
- `reward.total_xp < hud.total_xp` the HUD is kept as it is, because two rewards can land out of order.
244
- 5. All game queries share a key prefix, so one invalidation refreshes the HUD, path, quests, chest and badges.
245
- 6. A write that earns XP **without** returning a Reward (a side effect of another API) emits a small "HUD is stale"
246
- signal that the shell subscribes to and answers with the same invalidation. Prefer returning a Reward.
1
+ # Gamification
2
+
3
+ The game layer as reusable UX patterns, the honesty rules that keep it from turning into a dark pattern, and the data
4
+ contract the UI expects from a backend. The UI only **displays** game state; every number is decided by the server.
5
+ The components that draw these patterns are described in `COMPONENTS.md`.
6
+
7
+ ## 1. The loop
8
+
9
+ ```
10
+ action (answer, finish, save, claim)
11
+ → server grants XP, returns a Reward
12
+ → burst flies from the control to the HUD (the moment)
13
+ → HUD numbers update, path / quest advance (the state)
14
+ → next step is highlighted (the pull)
15
+ ```
16
+
17
+ Each element answers one question for the user:
18
+
19
+ | Element | Question | Where |
20
+ |---|---|---|
21
+ | XP + level | "Am I getting anywhere overall?" | HUD: level hexagon + XP bar |
22
+ | Daily goal | "Have I done enough today?" | HUD ring; centre dial of the bottom bar |
23
+ | Streak | "Am I consistent?" | HUD pill |
24
+ | Daily path | "What do I do next?" | Home hero card |
25
+ | Quests | "What else could I do today?" | Home side column |
26
+ | Achievements | "What have I collected over months?" | Home / profile grid |
27
+
28
+ If a product cannot answer one of these questions honestly (for example there is no meaningful daily unit), leave that
29
+ element out. A streak in an app people use twice a month is noise.
30
+
31
+ ## 2. XP
32
+
33
+ - XP is granted for **completed, meaningful actions**, by the server, in small integers (LenS: 5 for a
34
+ correct answer, 1 for a wrong one, 2 per answered question up to 10 for finishing a session, 30 for the daily
35
+ chest, 10-20 for a quest).
36
+ - **Every repeatable source has a bound**: a per-session maximum and a number of paid repetitions per local day
37
+ (LenS pays 5 session-completion bonuses a day; later sessions still work but earn 0). Without bounds a loop
38
+ of tiny sessions farms XP, levels and count-based achievements, and the numbers stop meaning anything.
39
+ - **Every grant is idempotent.** A grant has a `(source, source_id)` key that is unique per user (examples:
40
+ `quiz_complete` + session id; `quest` + `<local date>:<quest id>`; `chest` + local date; `word_added` + the
41
+ normalised word). Repeating the request returns a Reward with `xp_earned: 0, duplicate: true` and the current
42
+ totals. The UI can therefore retry and double-tap safely, and must treat `duplicate` as "nothing to celebrate".
43
+ - Wrong or failed attempts may earn a token amount (1 XP) so that effort is acknowledged, but never as much as
44
+ success.
45
+
46
+ ## 3. Levels
47
+
48
+ - Thresholds are cumulative XP: `0, 100, 250, 500, 1000, 2000, 3500, 5500, 8000, 12000, 17000, 25000`, then a fixed
49
+ step (10 000) per level, so levels never end and the bar never sticks at a cap.
50
+ - The API sends `level`, `total_xp`, `level_floor`, `next_level_xp`. The XP bar gets
51
+ `current = max(0, total_xp - level_floor)` and `span = max(1, next_level_xp - level_floor)` and shows
52
+ `current / span`. **Do not** compute `total_xp / next_level_xp`: thresholds are cumulative, so that bar starts each
53
+ level half full and is wrong.
54
+ - The client never holds the level table (only a dev gallery may, to simulate). One source of truth avoids a HUD that
55
+ disagrees with the server after a rule change.
56
+ - A level-up is the top of the intensity ladder (§8): a modal, once, with what was unlocked if anything.
57
+
58
+ ## 4. Streak
59
+
60
+ Three states, decided by the server from the user's **local** day:
61
+
62
+ | State | Meaning | HUD | Copy |
63
+ |---|---|---|---|
64
+ | `done` | Active today | Ember ring + glow, flame glows | "You were active today. See you tomorrow!" |
65
+ | `at_risk` | Last active yesterday, nothing yet today | Amber ring, flame floats 3 times | "Earn any XP today to keep your streak alive." |
66
+ | `zero` | Lapsed or never started | Grey, flame mono | "Earn any XP today to start a new streak." |
67
+
68
+ - The first XP of a local day extends the streak (`Reward.streak_extended`).
69
+ - **Read-decay**: a lapsed streak reads as `0 / zero` immediately, before the next activity; the stored counter is
70
+ only reset on the next grant. The user never sees a streak that is already lost.
71
+ - The "local day" comes from a time zone stored in the user's settings (UTC when unset), not from the request's
72
+ clock. A user who travels west must not lose a day: a last-active day in the future counts as today.
73
+ - `at_risk` is information, not alarm: amber, a short finite animation, no countdown timer, no push of guilt.
74
+ A lapsed streak is shown plainly; the longest streak stays visible ("best 21") so past effort is not erased.
75
+
76
+ ## 5. Daily goal
77
+
78
+ - Ratio = `min(1, today.xp / today.goal)`; a goal of 0 counts as reached (ratio 1). The goal is a **user setting**.
79
+ - Shown as a 34 px ring in the HUD with the percentage inside; at 100 % the ring's own check pops in.
80
+ - The same ring is the centre "dial" of the mobile bottom bar (LAYOUT-NAV.md): the thing the user came to do is the
81
+ biggest, most central control, and it shows how much of today is done.
82
+ - Reaching the goal (`Reward.goal_reached_now`) is a medium moment: toast-level, not a modal.
83
+
84
+ ## 6. Daily path and chest
85
+
86
+ A short fixed sequence of today's activities (LenS: Review → Quiz → Read → Speak) ending in a chest.
87
+
88
+ - Each step has a goal measured from today's counts; the server returns per step
89
+ `{ id, label, state: done | in_progress | current | todo, progress 0..1, to }`.
90
+ - Done steps stay done. The **first** open step is `current` (or `in_progress` once it has partial progress); later
91
+ open steps are `todo`, which the UI shows as **locked** with the hint "Finish <current> to unlock". The lock is a
92
+ focus device: only one thing is asked at a time. (Whether locked steps are really unreachable is a product choice;
93
+ in LenS the pages stay reachable from the navigation, the path only recommends an order.)
94
+ - The chest is `locked` until every step is done, then `ready`, then `claimed`; one per local day, a fixed amount
95
+ shown in advance (`+30 XP`). Claiming is an explicit tap on a CTA that replaces "Continue": the user opens it.
96
+ - Hero card copy follows the state: "Start today's path" → "2 of 4 steps done · Next up: ..." → "Path complete!
97
+ Open your chest to collect +30 XP" → "Every step is done. A new path unlocks tomorrow."
98
+ - After the claim the chest button disappears; if it was activated from the keyboard, move focus to the card heading
99
+ (`tabIndex={-1}`) so focus does not fall to `<body>`.
100
+
101
+ ## 7. Quests and achievements
102
+
103
+ **Quests** (daily, 3 per day): one constant ("Earn {daily goal} XP") plus two drawn from a pool by a hash of the
104
+ date, so they are the same for everyone that day and stable across servers, never two with the same metric.
105
+
106
+ - `{ id, title, icon, tone, progress, goal, reward_xp, state: active | complete | claimed }`; `progress` is capped at
107
+ `goal`.
108
+ - A complete quest must be **claimed** by the user (gold Claim keycap). The claim is the reward moment; granting
109
+ silently on completion wastes it.
110
+ - Claim errors: 404 (not one of today's quests: the day rolled over) and 409 (not complete) mean the client's view is
111
+ stale. Do not show an error toast for these; refetch and show the server's view.
112
+ - Optimistic step: mark the quest `claimed` in the cache as soon as the claim succeeds; the refetch confirms it.
113
+
114
+ **Achievements** (long-term): a fixed catalog `{ key, name, description, tier, icon }` plus per user
115
+ `{ earned_at, progress 0..1 }`.
116
+
117
+ - Tiers map to effort: first steps bronze; hundreds / a week silver; many hundreds / a month gold; extremes rare.
118
+ - Progress for "reach level N" is measured in XP, so the ring moves with every grant.
119
+ - Newly earned ones arrive in `Reward.new_achievements` and are toasted; the grid shows a NEW ribbon once.
120
+ - Locked achievements show their name and goal. Use `secret` sparingly, for surprises, not to hide requirements.
121
+
122
+ ## 8. Reward moments: the intensity ladder
123
+
124
+ | Level | Trigger | What plays | Blocks input? |
125
+ |---|---|---|---|
126
+ | 0 | Any XP < 50 | Burst dots + `+N XP` chip flies to the XP bar, bar pulses; screen-reader announcement only | No |
127
+ | 1 | XP >= 50, achievement, goal reached | The same + a toast (2.5 s) | No |
128
+ | 2 | Quest complete (waiting for claim) | Card turns gold, Claim button pulses, sheen loops | No |
129
+ | 3 | Chest ready | Node pops in with a gold burst; hero CTA becomes "Open chest" | No |
130
+ | 4 | Level up | Modal after the chip lands: rays, badge opens, Continue | Yes, dismissible at once (Esc, scrim, Continue) |
131
+
132
+ Rules:
133
+
134
+ - **Match intensity to rarity.** If every answer opened a modal, the level-up would mean nothing and the user would
135
+ be interrupted hundreds of times a day.
136
+ - **Merge.** Gains within 400 ms become one burst with the sum. Several grants from one action must not stack three
137
+ animations.
138
+ - **The reward lands on the HUD.** The chip flies to the XP bar and the bar updates when it arrives: the user sees
139
+ where the number went. Updating the HUD first and animating afterwards breaks the cause-and-effect.
140
+ - **Start from where the user acted.** Pass the pressed control as the anchor, or better its centre point, measured
141
+ **at press time**: the reward arrives after the request, when the control may have re-rendered or gone (a Claim
142
+ button becomes "Claimed").
143
+ - **Never block for more than 700 ms**, never require watching. Level 4 is the only modal and closes on the first key.
144
+ - Reduced motion: the chip fades in place, numbers change instantly, colour and text feedback stay.
145
+
146
+ ## 9. Honesty rules
147
+
148
+ 1. **No fake scarcity.** No invented countdowns, no "only 2 left", no rewards that expire to create pressure. The
149
+ only real deadline is the end of the local day, and it is stated plainly.
150
+ 2. **No loss framing beyond the facts.** "Earn any XP today to keep your streak" is a fact. "You are about to lose
151
+ everything" is not acceptable copy.
152
+ 3. **Rewards are shown before they are earned** (`+30 XP` on the chest, `+20 XP` on the quest) and paid exactly.
153
+ No random amounts presented as fixed, no bait.
154
+ 4. **The server is the only authority.** The client never adds XP locally except as a short optimistic patch that
155
+ a refetch then replaces. A client-side counter that drifts from the server is a bug the user will notice.
156
+ 5. **Idempotent grants** (§2), so a retry or a double tap can never pay twice or show a second celebration.
157
+ 6. **Farming is closed** by per-session and per-day bounds, not by hiding the activity. A capped action still works,
158
+ it just earns nothing more today, and the UI can say so.
159
+ 7. **Nothing is gated behind the game.** Locks in the path order the day; they do not withhold features the user
160
+ has. XP buys no advantage that can also be bought with money.
161
+ 8. **Opt-out friendly.** The HUD is compact; celebrations are skippable; reduced motion is respected. A user who
162
+ ignores the game still gets a usable product.
163
+
164
+ ## 10. Data contract
165
+
166
+ ### HUD read model: `GET /gamification/hud`
167
+
168
+ One request returns everything the shell and the home page show.
169
+
170
+ | Field | Type | Meaning |
171
+ |---|---|---|
172
+ | `level` | integer | Current level |
173
+ | `total_xp` | integer | Lifetime XP |
174
+ | `level_floor` | integer | Cumulative XP where this level started |
175
+ | `next_level_xp` | integer | Cumulative XP where the next level starts |
176
+ | `streak.current` | integer | Days in the streak (0 when lapsed: read-decay, §4) |
177
+ | `streak.longest` | integer | Best streak ever |
178
+ | `streak.state` | `done` \| `at_risk` \| `zero` | §4 |
179
+ | `today.date` | `YYYY-MM-DD` | The user's local day |
180
+ | `today.xp` | integer | XP earned today |
181
+ | `today.goal` | integer | The user's daily goal |
182
+ | `today.<counts>` | integers | Product-specific counts of today (LenS: quizzes, readings, speaking seconds, dictations, words reviewed, words added) |
183
+ | `path[]` | list | Today's steps, in order |
184
+ | `path[].id` | string | Stable step id |
185
+ | `path[].label` | string | Short label under the node |
186
+ | `path[].state` | `done` \| `in_progress` \| `current` \| `todo` | `todo` is drawn as locked |
187
+ | `path[].progress` | 0..1 | Ring around an in-progress node |
188
+ | `path[].to` | string | Route of the step |
189
+ | `quests[]` | list | Today's quests |
190
+ | `quests[].id`, `.title` | string | |
191
+ | `quests[].icon`, `.tone` | string | Names from the icon registry and the tone list |
192
+ | `quests[].progress`, `.goal` | integer | `progress` is capped at `goal` |
193
+ | `quests[].reward_xp` | integer | Shown before it is earned |
194
+ | `quests[].state` | `active` \| `complete` \| `claimed` | |
195
+ | `chest.state` | `locked` \| `ready` \| `claimed` | |
196
+ | `chest.xp` | integer | The chest's fixed reward |
197
+
198
+ - One read model, not five endpoints: the top bar, its panel, the bottom bar's dial and the home page share one
199
+ cached query (stale time about 30 s) and can never disagree.
200
+ - `icon` and `tone` come from the server as names. Map unknown names to a fallback on the client; a server deploy
201
+ must not be able to crash the page.
202
+ - The server computes "today" and every state. The client does no date arithmetic.
203
+ - Mapping to the components: the API's `at_risk` is the pill's `at-risk`; a path step's `todo` is the node's
204
+ `locked`, `in_progress` is `in-progress`; the chest becomes the last node of the path with state `chest` (the node
205
+ shows "ready" when every earlier step is done).
206
+
207
+ ### Reward: returned by every response that grants XP
208
+
209
+ | Field | Type | Meaning |
210
+ |---|---|---|
211
+ | `xp_earned` | integer | The delta; 0 for a repeat |
212
+ | `total_xp`, `level`, `level_floor`, `next_level_xp` | integers | The **new totals**, same meaning as in the HUD |
213
+ | `leveled_up` | boolean | This grant crossed a level threshold |
214
+ | `streak` | integer | The streak after this grant |
215
+ | `streak_extended` | boolean | First activity of the local day |
216
+ | `new_achievements[]` | `{ key, name, description, tier, icon }` | Earned by this grant |
217
+ | `daily_xp`, `daily_goal` | integers | Today's XP after this grant, and the goal |
218
+ | `goal_reached_now` | boolean | This grant crossed the daily goal |
219
+ | `duplicate` | boolean | This grant was already paid (§2) |
220
+
221
+ A Reward carries the new totals, not only the delta, so the client can patch the HUD without arithmetic.
222
+
223
+ Other endpoints in LenS: `POST /gamification/quests/{id}/claim` and `POST /gamification/chest/claim` (both return a
224
+ Reward; the chest answers 409 until every step is done), `GET /gamification/achievements/catalog` (each catalog item
225
+ plus `earned_at` and `progress` 0..1), `GET /gamification/activity?days=N` (per-day rows for a heatmap, 1 to 120
226
+ days; days without activity have no row).
227
+
228
+ ### Client wiring
229
+
230
+ One function, "play a reward", is called from the success handler of every mutation that can grant XP, with the
231
+ Reward and the anchor captured at press time:
232
+
233
+ 1. The reward is missing or `duplicate`: invalidate the game queries and stop. Nothing to celebrate.
234
+ 2. If `xp_earned > 0`, or it levelled up, or it brought achievements: call the reward system
235
+ (`rewardXp({ xp: xp_earned, anchor, levelUp: leveled_up ? { level } : undefined, achievements })`,
236
+ COMPONENTS.md).
237
+ 3. After **1100 ms** when XP was earned (the 400 ms merge window + the 700 ms flight; otherwise at once): write the
238
+ new totals into the cached HUD and invalidate every game query. The bar fills at the moment the chip visibly
239
+ arrives; the refetch then replaces the optimistic values.
240
+ 4. The optimistic patch copies `level`, `total_xp`, `level_floor`, `next_level_xp`; sets the streak to
241
+ `{ current: reward.streak, longest: max(old longest, reward.streak), state: 'done' }`; sets `today.xp` and
242
+ `today.goal` from `daily_xp` / `daily_goal`. It **never moves totals backwards**: when
243
+ `reward.total_xp < hud.total_xp` the HUD is kept as it is, because two rewards can land out of order.
244
+ 5. All game queries share a key prefix, so one invalidation refreshes the HUD, path, quests, chest and badges.
245
+ 6. A write that earns XP **without** returning a Reward (a side effect of another API) emits a small "HUD is stale"
246
+ signal that the shell subscribes to and answers with the same invalidation. Prefer returning a Reward.