- TypeScript 91%
- HTML 6%
- CSS 3%
- Docker <1%
santa #
Secret Santa over Bluesky DMs. v1 is a bot; this repo is currently the questionnaire backend.
Accounts #
| Handle | Display name | Role |
|---|---|---|
@atmo.gift |
Secret Santa HQ 🎄 | Commands, questionnaire, status |
@santa.atmo.gift |
Your Secret Santa 🎅 | Relay: messages to/from your santa |
@nicelister.atmo.gift |
Your Nice-Lister 🎁 | Relay: messages to/from the person you're gifting |
Copy convention: the person you gift is your nice-lister (never "giftee" in
user-facing text). Lexicon namespace: gift.atmo.*.
Layout #
src/fuzzy/ normalize, Jaro-Winkler, OSA edit distance
src/questionnaire/ countries (fuzzy ISO lookup), parsers, question defs,
engine (pure state machine), service (sqlite persistence)
src/moderation/ offline categorizer queue: export / import / review
src/db/ Kysely schema + migrations (SQLite)
src/chat/ ChatClient interface; BskyChatClient (real), FakeChatNetwork
(in-memory chat service for tests/sim), message chunking
src/bot/ runtime (poll → route → relay → outbox), copy, config
src/cli/ sim, admin, moderation, try
src/main.ts live bot
Testing #
Three layers, from fastest to most real:
1. Automated — npm test. The real bot runtime against FakeChatNetwork,
an in-memory chat service that models 1:1 convos, per-account logs and
cursors, DM settings (all / following / none), the 1000-grapheme cap and
injected transient failures.
2. Simulator — npm run sim. Same runtime, interactive, playing several
people at once:
alice → hq> join … answer the questionnaire …
alice → hq> /as bob switch person
bob → hq> santa: hi send to a specific bot account
bob → hq> /approve fake categorizer: clear pending answers
bob → hq> /pair alice bob alice gifts bob
bob → hq> /as alice
alice → hq> nice: any coffee prefs? → [bob ⇠ @santa.atmo.gift] any coffee prefs?
alice → hq> /dms none test the "can't reach you" path
3. Live, on real accounts, safely — npm start with an allowlist.
- Create an app password for each bot account with DM access enabled.
cp .env.example .env, fill in credentials, and setSANTA_ALLOWLISTto your own handle plus an alt. Everyone else is ignored completely.npm start. On first run each account skips its DM history.- From your main: DM
@atmo.gift"join" and finish the questionnaire. npm run admin -- approve-pending→ you get the "all set" DM.- Repeat with the alt, then
npm run admin -- pair you.bsky.social alt.bsky.social. - DM
@nicelister.atmo.giftfrom your main → arrives on the alt from@santa.atmo.gift. - To test the unreachable path: set the alt's DMs to "No one" before step 7
and don't DM
@santafrom it — the message queues, the alt gets an HQ nudge, and saying hi to@santaflushes it.
npm run admin -- participants shows status and pairings.
Languages #
Live: English only (SANTA_LOCALES=en). Translations exist for Spanish,
Portuguese (Brazil), French, German, Dutch and Japanese but are unreviewed;
enable one with e.g. SANTA_LOCALES=en,pt after a native-speaker review.
Disabled languages are never inferred or offered, "language" replies
"English only for now", and a saved choice of a disabled language falls back
to English.
Translations:
via i18next. Catalogs: src/i18n/locales/<lang>.json
(English is the source; missing keys fall back to it). Standard i18next JSON,
so Crowdin / Weblate / Lokalise can import and export it directly.
- Choosing: on first contact the bot infers a language from the
langstags on the person's recent posts and adds a "reply "language"" hint. "language" / "idioma" / "langue" / "Sprache" / "taal" / "言語" (in any language) shows a menu; "idioma español" switches directly. Stored inuser_pref; a switch mid-questionnaire re-asks the current question. - Keywords:
kw.<name>lists are what the bot accepts (yes/no, commands, choices). The first entry is what it shows, via nesting:"Reply \"$t(kw.back.0)\"", so the word we tell people to type always works. English keywords are accepted in every language. - Review pipeline:
src/i18n/review/<lang>.jsontracks each key asmachine/reviewed/stale, with a hash of the English it was translated from.npm run i18n— report (exits 1 on missing keys or placeholder mismatches)npm run i18n -- sync— track new keys; mark keys stale when English changesnpm run i18n -- mark es reviewed q.budget.prompt …— record a review
- The categorizer export includes each answer's
lang.
Budgets and money #
Budget tiers are defined in US dollars of spending power and shown to each
person in their own currency, adjusted by purchasing power parity, so "small"
is about the same effort everywhere (up to $20 · £15 · €10–15 · ₹400 · ¥2,000).
Typed amounts are read in local currency unless they say otherwise ("$25"
from the UK is US dollars). npx tsx src/cli/tiers.ts GB IN prints what a
country sees.
src/questionnaire/money.json is a committed snapshot; the bot never fetches
it at runtime. Refresh with npm run update-money (a few times a year is plenty):
| Data | Source |
|---|---|
| Country → currency | Unicode CLDR supplemental/currencyData |
| Spending power | World Bank WDI PA.NUS.PRVT.PP (PPP, private consumption) |
| Market rates (only for converting typed foreign amounts) | open.er-api.com |
Countries without PPP data use the market rate; unknown currencies show USD.
Transport semantics #
- Inbound is at-most-once: a message is marked processed before handling, so a crash can drop a message but never answers a questionnaire step twice.
- Relay messages are logged in
relay_message(moderation + retry queue). Unreachable recipients get one HQ nudge per backlog; the backlog flushes when they message that relay account. Transient failures retry each tick. - Reactions and replies carry over. Each delivered copy is recorded in
relay_copy; a reaction on a copy is mirrored onto the original by the bot account on the sender's side (so it stays anonymous), and removing it removes the mirror. A reply to a relayed message arrives as a reply to its twin; if the target is gone it's sent as a plain message. - The outbox (written by offline jobs like moderation import) is drained by HQ.
Data rules #
- Answers (
answer) are append-only versions. Editing supersedes the old row; a moderation verdict always refers to the exact text it judged. - Shipping addresses live only in
shipping_address— never inanswer, so the categorizer cannot see them, and purge is one table. - In-progress conversations (
questionnaire_session) hold draft answers, including a draft address, and are deleted on submit / purge.
Categorizer: TypeSafe Jev #
src/moderation/jev.ts classifies each pending answer with
TypeSafe AI's Jev (@typesafe-ai/sdk, pinned). One
request per answer; one yes/no question per policy rule (hate/harassment,
sexual, violence/threats, self-harm, personal contact info, money/scams,
dangerous/illegal). An answer is flagged for human review if any rule's
probability is ≥ 0.4; every score is stored in moderation_result.
# needs TYPESAFE_API_KEY (local .env, or: fly secrets set --app atmo-gift TYPESAFE_API_KEY=…)
npm run moderation -- jev --dry-run # see verdicts, import nothing
npm run moderation -- jev # classify + import
npm run moderation -- jev --threshold 0.3 # stricter
fly ssh console --app atmo-gift -C "node --import tsx src/cli/moderation.ts jev --dry-run"
Failed requests (after the SDK's retries) are skipped and stay pending for the next run. Not run automatically: run it before matching.
Categorizer contract #
Every typed answer except the address is moderated before the participant is
eligible for matching (submitted → ready). Skipped answers are clean.
SANTA_DB=santa.db npm run moderation -- export > pending.jsonl
# pending.jsonl: {"answer_id":12,"question_id":"loves","text":"tea, books"}
# your categorizer writes results.jsonl:
# {"answer_id":12,"categorizer":"my-model","categorizer_version":"2026-11",
# "verdict":"flag","labels":[{"label":"harassment","score":0.91}]}
npm run moderation -- import results.jsonl
npm run moderation -- flagged # human review queue
npm run moderation -- review 12 approve|reject [note]
No DIDs or handles are exported. Status precedence: a flag from any
categorizer beats clean; human approved/rejected beats both. Results
for answers edited since export are recorded but don't change status.
Status changes to ready / needs_changes queue an outbox DM.
Website / privacy policy #
site/ is a static site deployed to wisp.place from the
@atmo.gift account; the privacy policy is site/privacy/index.html
(served at /privacy/). Deploy with npm run deploy-site (set
WISPCTL_APP_PASSWORD to skip the browser login).
The policy describes promises the bot must keep — address and relay-message purge at release, anonymized-only stats, delete-on-request. Update it when data handling changes.
Deploying (Fly.io) #
A background worker: no HTTP service, exactly one machine, SQLite on a
volume at /data. Two running copies (including a local npm start against
the same accounts) would both answer every DM, so stop the local bot first.
First time:
fly apps create atmo-gift --org personal
fly volumes create santa_data --app atmo-gift --region iad --size 1 --yes
fly secrets set --app atmo-gift --stage \
SANTA_HQ_PASSWORD=… SANTA_SANTA_PASSWORD=… SANTA_NICELISTER_PASSWORD=…
fly deploy --ha=false
After that: fly deploy --ha=false. Logs: fly logs. Admin tools run on the
machine: fly ssh console -C "node --import tsx src/cli/admin.ts participants".
Non-secret settings live in fly.toml [env] (allowlist, languages, exchange).
Production is open to everyone (no SANTA_ALLOWLIST) as of 2026-11-13.
Fly snapshots volumes daily (5-day retention); fly volumes snapshots list.