@pixygon/quests
The Ludens quest layer for Pixygon apps — daily board, personal quests, player contracts, cross-app events
Install
# .npmrc @pixygon:registry=https://ppm.pixygon.io/ npm install @pixygon/quests@0.8.6
Versions
| Version | Published | Integrity |
|---|---|---|
| 0.8.6 latest | 2026-11-19 | sha512-V9hmBqQkB2aab69… |
| 0.8.5 | 2026-11-19 | sha512-8tKdT+S/mi+DaMa… |
| 0.8.4 | 2026-10-22 | sha512-uhiRv+oSrDUU2ni… |
| 0.8.3 | 2026-10-05 | sha512-AsmN4QfOhOxqOjs… |
| 0.8.2 | 2026-08-01 | sha512-W7t0biETV4euUHF… |
| 0.8.1 | 2026-08-01 | sha512-Dm2mzZMTzUOLicz… |
| 0.8.0 | 2026-07-27 | sha512-PVOlAqEEVWfr/8D… |
| 0.7.0 | 2026-07-27 | sha512-dUrl1kMlLe9hPyi… |
| 0.6.0 | 2026-07-25 | sha512-aDfYm80zgEOYRPV… |
| 0.5.1 | 2026-07-25 | sha512-2L9N9r1ShVKBG8j… |
| 0.5.0 | 2026-07-25 | sha512-in767q8b3jhGi8U… |
| 0.4.1 | 2026-07-25 | sha512-rpAtav3gZlP4yPM… |
| 0.4.0 | 2026-07-25 | sha512-HX0QW5lDBjXrcr3… |
| 0.3.0 | 2026-07-25 | sha512-TlfdjNyh+twJdR8… |
| 0.2.0 | 2026-07-25 | sha512-6TV2jnGdaYmJZkr… |
| 0.1.2 | 2026-07-25 | sha512-or1qeDLJpXRwGk0… |
| 0.1.1 | 2026-07-25 | sha512-vwfF6FPyaQIWXmG… |
| 0.1.0 | 2026-07-25 | sha512-47XfB1RcRUzDTDG… |
@pixygon/quests
The Ludens quest layer — the daily board, self-authored quests, player contracts, the cross-app event spine, and the Passport. 4 repos depend on it (pixygon.io, Kartograf, Tastebud, CoreFeed) and all four wire it the same way; everything below is that shape, not an idealised example.
Everything talks to /v1/ludens/* on the Pixygon API. Every player route on
that router is verifyToken-gated — no token, no quest layer.
Retrofitting it into an existing app (≈20 minutes)
Written for an agent. Do these in order. Step 3 is where every mistake lives.
1. Install
npm i @pixygon/quests
Six peer deps, all of which a MUI app already has: @mui/material ≥6,
@mui/icons-material ≥6, @emotion/react ≥11, @emotion/styled ≥11,
react ≥18, react-dom ≥18. The package has no runtime dependencies and
no Redux/RTK — if you were about to add a store slice for quests, don't.
All state is hook-local plus one React context.
2. Learn the two import paths
There are exactly two subpaths in the exports map, . and ./components, and
one rule that 4/4 repos follow:
import { QuestsProvider } from '@pixygon/quests/components' // ← the provider, from /components
import { useQuestlog, DailyBoard, usePassport } from '@pixygon/quests' // ← everything else, from root
The root barrel re-exports ./components too, so components resolve from
both — but hooks, config helpers and ludensFetch are root-only. Two
paths that look plausible and do not exist: @pixygon/quests/hooks and any
deep @pixygon/quests/dist/... / /src/... path. Neither is in the exports
map, so Node ESM resolution rejects them (ERR_PACKAGE_PATH_NOT_EXPORTED) —
verify.mjs fails the repo for either.
3. Mount the provider — below auth
⚠ This is the step that fails silently. QuestsConfigContext is created
with a working default (appId: 'pixygon', the real baseUrl, and
getToken: () => null) and does not throw when no provider is mounted.
Every hook starts with if (!config.getToken()) return, and <DailyBoard>
returns null while loading. An app with no <QuestsProvider> therefore
looks completely normal, renders no errors, and measures nothing. There is no
runtime signal. Mount it.
The estate pattern is a thin wrapper file, src/providers/QuestsProvider.tsx
(identical in all four repos):
import type { ReactNode } from 'react'
import { QuestsProvider as PixygonQuestsProvider } from '@pixygon/quests/components'
import { useToken } from '@pixygon/auth'
const API_URL = import.meta.env.VITE_API_URL || 'https://api.pixygon.io/v1'
export function QuestsProvider({ children }: { children: ReactNode }) {
// useAuth() does NOT expose the token — that lives on useToken().
const { getAccessToken } = useToken()
return (
<PixygonQuestsProvider appId="kartograf" baseUrl={API_URL} getToken={getAccessToken}>
{children}
</PixygonQuestsProvider>
)
}
Then mount it in main.tsx inside <AuthProvider> and inside the Router.
Three things to get exactly right:
| Prop | Rule |
|---|---|
getToken | useToken().getAccessToken from @pixygon/auth. Nothing else. |
appId | your repo's own lowercase slug — pixygon, kartograf, tastebud, corefeed |
baseUrl | import.meta.env.VITE_API_URL || 'https://api.pixygon.io/v1', or omit it |
The getToken trap. The signature is
getToken: () => string | null — synchronous. Two things in
@pixygon/auth are named getAccessToken and only one of them fits:
useToken().getAccessToken→() => string | null✅createTokenStorage(appId).getAccessToken→() => Promise<string | null>❌
Passing the async one type-errors only if types are checked; at runtime
config.getToken() returns a Promise, which is truthy, so the guard passes and
Authorization: Bearer [object Promise] goes out — every call 401s. And
useAuth() does not expose a token at all (pixygon.io's wrapper carries a
comment about exactly this). verify.mjs fails all three wrong shapes.
baseUrl is the API root, not the ludens root: ludensFetch builds
${baseUrl}/ludens${path} itself. Passing .../v1/ludens gives you
/v1/ludens/ludens/quests. pixygon.io omits baseUrl entirely and takes the
package default — that is fine, and correct for any app with no env override.
4. Mount the Passport
<PassportProvider> holds the one Passport overlay — the player's cross-app
identity panel — and must sit inside your <QuestsProvider> (it uses
usePassportSummary) and inside the Router (its deep links call
navigate). Unlike the quests context, usePassport() does throw
(usePassport must be used within <PassportProvider>), so this half of the
package fails loudly.
<PassportProvider
currentApp="map" // your panel shows "here" instead of deep-linking
user={{ name: user?.userName }}
onNavigate={(key) => {
if (key === 'map') { navigate('/map'); return true }
if (key === 'status' || key === 'account') { navigate('/profile'); return true }
return false // → full-page window.location.assign()
}}
>
The panel keys are quests · status · party · library · map · wallet. The
footer button uses the key account, which is not one of those panels —
4/4 repos handle it explicitly, and forgetting it means "Account & settings"
hard-navigates off your SPA to https://pixygon.io/profile. Returning falsy
from onNavigate (including forgetting to return true) is what triggers the
full page load.
Then put the entry point in your header:
import { PassportAvatar } from '@pixygon/quests'
<PassportAvatar size={34} /> // badges claimable quests + contracts needing action
Or open it from your own element — and note the signature:
const { open } = usePassport() // open(anchor?: HTMLElement | null)
<Box onClick={(e) => open(e.currentTarget)}>…</Box> // ✅ anchors the popover to the element
<Box onClick={open}>…</Box> // ❌ passes a SyntheticMouseEvent as the anchor
The second form is a real bug that shipped (Kartograf StatsBar.tsx): the
event object lands in setAnchorEl and then in MUI's Popover anchorEl.
If you have nothing to anchor to, call open() with no arguments — the panel
falls back to the top-right of the screen. CoreFeed's Sidebar does it right:
onClick={() => { if (isMobile) onClose?.(); openPassport(); }}.
5. Drop in the surfaces
import { DailyBoard, QuestLog, ContractBoard } from '@pixygon/quests'
<DailyBoard onClaimed={(xp) => confetti(xp)} /> // the world's 3 daily quests + streak
<QuestLog /> // board + personal quests + authoring UI
<ContractBoard userId={user._id} position={{ lat, lng }} /> // the bounty board
Or build your own on the hooks — useQuestlog(), useContracts(),
useNearbyQuests(lat, lng, radiusKm) (Kartograf's ! markers),
usePassportSummary(enabled).
6. Emit events — or deliberately don't
The server advances quests from verbs. useLudensEvents() batches them
(flush every 4 s, max 25 per POST, plus on visibilitychange and unmount;
failed batches are unshifted back onto the queue, so a dropped request costs
latency, not progress).
The hook can only be called from a component. Kartograf and Tastebud both
carry the same ~20-line src/utils/ludensBus.ts (ludensEmit /
registerLudensSink / LUDENS_COMPLETED_EVENT, code byte-identical between
the two repos, only the doc comment differs) so any non-React code can emit,
plus a bridge component mounted inside the provider:
function LudensBridge() {
const { emit } = useLudensEvents((questKeys) => {
window.dispatchEvent(new CustomEvent(LUDENS_COMPLETED_EVENT, { detail: questKeys }))
})
useEffect(() => registerLudensSink((verb, value, payload) => emit(verb, value ?? 1, payload)), [emit])
return null
}
CoreFeed emits nothing client-side on purpose — its verbs (meal.logged,
water.logged) are emitted server-side by the createMeal/createWater
controllers, which makes them verified. Prefer that when the action already
goes through the API: emitLudensEvent marks client-attested progress
unverifiedProgress, which gates spendable rewards at claim time (XP still
pays). Not emitting is a valid answer, so verify.mjs only notes it.
The verbs are not free-form — they must match the server's quest definitions
(POST /v1/ludens/definitions/seed in PixygonAPI). The ones that exist today:
kartograf distance.walked · landmark.visited · landmark.created · landmark.rated
treasure.collected · treasure.hidden · pin.created · mystery.solved
animunda task.completed · garden.tended
corefeed meal.logged · water.logged (server-emitted)
tastebud entry.added · entry.rated
A typo'd verb is silently discarded — the event is stored, nothing matches it.
7. Verify it worked
node node_modules/@pixygon/quests/verify.mjs
# or, from Dyson's registry:
pearl verify quests
Static check — installed version, import-path discipline, a real provider
mount, the getToken shape, appId, baseUrl, the six peer deps, and the
Passport wiring traps above. Exit 0 pass, 1 fail.
What verify can and cannot prove. It cannot tell "working" from "silently
no-op" — see the warning in step 3. It reads text, so it cannot prove the
runtime React tree (a lazy route can still put a usePassport() consumer
outside the provider), cannot prove your token is non-null, and cannot prove
your verbs match the server. The end-to-end proof is: log in, do the thing,
open the Passport, watch the quest advance.
How the server sees it
Three facts that contradict reasonable assumptions, all verified against
PixygonAPI/services/ludensEngine.js:
appIddoes not gate anything. Event matching is onverbalone (plus an optionalstep.target).appis recorded on the event and used for labelling. Emittingdistance.walkedfromappId: 'tastebud'still advances the Kartograf quest.- The daily board is global.
boardEligibledaily definitions are drawn for every player with no per-app filter — the same three quests for everyone on Earth, which is the point. Your app is a panel, not a silo. - Claiming is two-phase and server-side. Events flip a quest to
completed;claimpays. Nothing in this package can mint XP.
Cross-app chains (x-body-and-soul: walk 2 km in Kartograf → log a meal in
CoreFeed → complete a task in Animunda) are the reason the layer is shared at
all.
API
| Export | From | Use |
|---|---|---|
<QuestsProvider appId getToken baseUrl?> | @pixygon/quests/components | the mount — always from this subpath |
<PassportProvider currentApp user onNavigate onLogout title appUrls> | both | holds the one Passport overlay |
usePassport() | both | { isOpen, open(el?), close, toggle(el?), user } — throws without its provider |
<PassportAvatar size hotkey sx> | both | top-right entry point, badged with what needs action |
<PassportMenu> | both | the panel itself (PassportProvider renders it for you) |
<DailyBoard title? onClaimed?> | both | the world's daily board + streak |
<QuestLog onClaimed?> | both | board + personal quests + authoring |
<ContractBoard userId position? onError?> | both | the bounty board |
<QuestCard quest onClaim onCheckoff busy> | both | one quest row |
useQuestlog() | @pixygon/quests | { board, personal, streak, xp, level, claimable, claim, checkoff, createPersonal, deletePersonal, refresh } |
useLudensEvents(onCompleted?) | @pixygon/quests | { emit(verb, value=1, payload?), flush() } |
useContracts({ load?, near? }) | @pixygon/quests | { mine, open, create, accept, submit, approve, reject, cancel, decline, abandon } |
useNearbyQuests(lat, lng, radiusKm=10) | @pixygon/quests | { markers, loading, refresh } — map ! pins |
usePassportSummary(enabled=true) | @pixygon/quests | one call powering every Passport panel |
useQuestsConfig() | @pixygon/quests | the live config (returns the default if unmounted) |
ludensFetch(config, path, init?) | @pixygon/quests | raw authed call to ${baseUrl}/ludens${path} |
levelForXp(xp) / xpForLevel(level) | @pixygon/quests | the ONE level curve (same as @pixygon/social) |
localDateKey(d?) | @pixygon/quests | local-time YYYY-MM-DD; the server trusts the client's day |
QuestsConfigContext | @pixygon/quests | escape hatch; prefer <QuestsProvider> |
types: PlayerQuest, Questlog, Contract, PauseSummary, ClaimResult, … | @pixygon/quests |
Config
interface QuestsConfig {
appId: string // default 'pixygon' — your app slug, for event labelling
baseUrl: string // default 'https://api.pixygon.io/v1' — the API ROOT, not /ludens
getToken: () => string | null // default () => null — SYNCHRONOUS. useToken().getAccessToken
}
<QuestsProvider> takes { appId, getToken, baseUrl?, children }; baseUrl
falls back to the default above.
Endpoints it calls
All relative to ${baseUrl}/ludens, all verifyToken-gated:
GET /quests?date=YYYY-MM-DD POST /quests/:id/claim POST /quests/:id/checkoff
POST /personal DELETE /personal/:key
POST /events { events: [...] }
GET /contracts GET /contracts?role=open&lat=&lng=&radiusKm=
POST /contracts POST /contracts/:id/{accept,submit,approve,reject,cancel,decline,abandon}
GET /contracts/nearby?lat=&lng=&radiusKm=
GET /pause?date=YYYY-MM-DD
Gotchas
- A missing
<QuestsProvider>is invisible. The config context default is non-throwing, so hooks early-return,<DailyBoard>rendersnull, and the app looks fine. This is the single most expensive mistake with this package and no runtime check catches it. (usePassport()is the only guard that throws.) getTokenis synchronous.useToken().getAccessToken, nevercreateTokenStorage(...).getAccessToken(async) and neveruseAuth()(no token at all). See step 3.baseUrlmust not end in/ludens.ludensFetchadds that segment.QuestsProviderbuilds its context value as a bare object literal with nouseMemo. Every re-render of your wrapper mints a freshconfigidentity;useQuestlog/useContracts/useNearbyQuests/usePassportSummaryall listconfigin theiruseCallbackdeps and then runuseEffect(() => { void refresh() }, [refresh]). Mount the wrapper high and keep it out of anything that re-renders per frame (map position, timers), or you get a refetch per render. Whether it actually loops depends entirely on your host's render frequency — this is a package-side fix waiting to happen.onClick={open}passes a mouse event as the popover anchor. UseonClick={(e) => open(e.currentTarget)}oronClick={() => open()}.- Handle the
'account'key inonNavigate. It is a footer button, not a panel, so it's easy to miss — and missing it hard-navigates out of your SPA. - Version drift is currently harmless. The repo is at 0.8.2 while
Kartograf, Tastebud and CoreFeed still resolve 0.6.0. Diffed 2026-08-07:
0.6.0's
distexport lists are character-for-character identical to 0.8.2's (only the chunk hash differs) and its exports map already has both subpaths. So a retrofit written against 0.8.2 works on a 0.6.0 install. Don't assume this stays true — re-diff before relying on it again. - MUI major drift. The package is built and typechecked against MUI 7 and
uses
PopoverslotProps/anchorReference. Tastebud runs MUI 9. The peer range (>=6) allows it and nothing here proves the Popover still renders correctly — open the Passport and look. - Don't reach for Redux. There is none in this package, by design.
- Prefer server-side emission for anything the API already sees. Client
events are marked
unverifiedProgressand that gates spendable rewards.
Publishing
npm run build && npm publish --access public