feat(focus): earn from focused time with Forest-style focus sessions #14

Merged
alex merged 3 commits from feat/focus into feat/allele-genetics 2026-10-31 18:25:25 +01:00
Owner

Stacked on #13 (allele genetics); merge that first.

Focused time becomes the second way to earn, beside habits, in the spirit of Forest. This is the first half of the new Forestry-style progression; the bee lifecycle (wild hives, inventory, princesses and drones, queens that die) is the next PR.

What changes

  • New Focus context (libs/contexts/focus, schema focus): a FocusSession lasts 15, 25, 50 or 90 minutes, one running per keeper (a unique index enforces it too). It completes only once its time is up by the server's clock (5 s tolerance) and can be abandoned. Completing it publishes focus.session_completed.v1. API: GET /api/focus, PUT /api/focus/sessions/{id}, POST .../complete, POST .../abandon.
  • Rewards: Ledger.creditFocus pays a completed session at once: 0.5 nectar and 0.2 pollen per minute, at most 180 minutes in any rolling 24 hours, each session once. It publishes rewards.focus_rewarded.v1. Migration 202611010930-focus-credits.
  • Apiary: credits focus rewards to the Keeper's stores.
  • App (inside the game screen): a Focus hotbar slot with the lengths and what each will pay today, a countdown panel over the island, Give up with a confirmation, and a completed or lost summary. Leaving the app for more than 10 s loses the session; this is checked through page visibility and remembered across a closed app (honour system, as in Forest). The stores show the pay at once and keep reloading briefly until Rewards has paid.
  • Docs: docs/contexts/focus.md, the context map, Rewards' rules and published language, and the planned Apiary progression.

Checks

  • nx affected -t lint typecheck test build passes, as does int-test for focus, rewards and apiary against Postgres.
  • In the browser: started sessions, completed one (backdated in the local database) and watched the pay reach the stores, gave up, and lost one by leaving. While testing I found that switching to the terminal hides Chrome, which correctly loses the session.

🤖 Generated with Claude Code

Stacked on #13 (allele genetics); merge that first. Focused time becomes the second way to earn, beside habits, in the spirit of Forest. This is the first half of the new Forestry-style progression; the bee lifecycle (wild hives, inventory, princesses and drones, queens that die) is the next PR. ## What changes - **New Focus context** (`libs/contexts/focus`, schema `focus`): a `FocusSession` lasts 15, 25, 50 or 90 minutes, one running per keeper (a unique index enforces it too). It completes only once its time is up by the server's clock (5 s tolerance) and can be abandoned. Completing it publishes `focus.session_completed.v1`. API: `GET /api/focus`, `PUT /api/focus/sessions/{id}`, `POST .../complete`, `POST .../abandon`. - **Rewards**: `Ledger.creditFocus` pays a completed session at once: 0.5 nectar and 0.2 pollen per minute, at most 180 minutes in any rolling 24 hours, each session once. It publishes `rewards.focus_rewarded.v1`. Migration `202611010930-focus-credits`. - **Apiary**: credits focus rewards to the Keeper's stores. - **App** (inside the game screen): a Focus hotbar slot with the lengths and what each will pay today, a countdown panel over the island, Give up with a confirmation, and a completed or lost summary. Leaving the app for more than 10 s loses the session; this is checked through page visibility and remembered across a closed app (honour system, as in Forest). The stores show the pay at once and keep reloading briefly until Rewards has paid. - **Docs**: `docs/contexts/focus.md`, the context map, Rewards' rules and published language, and the planned Apiary progression. ## Checks - `nx affected -t lint typecheck test build` passes, as does `int-test` for focus, rewards and apiary against Postgres. - In the browser: started sessions, completed one (backdated in the local database) and watched the pay reach the stores, gave up, and lost one by leaving. While testing I found that switching to the terminal hides Chrome, which correctly loses the session. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A new Focus context records timed sessions (15, 25, 50 or 90 minutes, one at a
time). A session completes only once its time is up by the server's clock and
publishes FocusSessionCompletedV1. Rewards pays it at once on the Ledger, 0.5
nectar and 0.2 pollen a minute, at most 180 minutes in any 24 hours, and
publishes FocusRewardedV1 for the Apiary's stores.

The game screen gets a Focus slot: pick a length, watch the countdown over the
island, give up or complete. Leaving the app for more than ten seconds loses
the session, judged by page visibility and remembered across a closed app. The
stores show the pay at once while the server catches up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The game moves to a Forestry-like progression. A homestead per keeper holds an
island of cells, an inventory of individual bees (princesses and drones, each
with a genome) and supplies. Focus sessions explore Andalusia and turn up wild
hives (the first always does); collecting one gives a pure-bred princess and
drones. Hives and flowers are placed on the island from hive kits and seeds,
bought with nectar and pollen. A princess and a drone in an empty hive become
a queen who makes honey near the flower her new flower gene names, for her
new lifespan gene in hours; at her death she leaves a princess and drones bred
from her and her mate. The keeper aggregate becomes the wallet.

Existing keepers are migrated: their hive keeps its queen alive with flowers
around it, and reserve queens become a princess and a drone each. The web app
gets a guide to the next step, a build hotbar with glowing cells, a hive panel,
a bee inventory, and a scene drawn from the homestead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reviewed-on: https://git.selene.acl.sh/Habitea/App/pulls/15
alex merged commit 8d81e4315e into feat/allele-genetics 2026-10-31 18:25:25 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Habitea/App!14
No description provided.