This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
JetShift is a client-side-only PWA that generates a personalised 7-day jet lag mitigation plan based on the Kronauer/Jewett/Forger circadian oscillator model. All computation runs in the browser; there is no backend.
# Install
npm install
# Run tests (full suite)
npx vitest run
# Run a single test by name
npx vitest run --reporter=verbose -t "computeCBTMinimum"
# Type-check
npx tsc --noEmit
# Dev server
npm run dev
# Production build
npm run buildModules are built in strict dependency order (Stages 1–9). Never import from a later stage into an earlier one.
| Module | Stage | Description |
|---|---|---|
src/lib/time.ts |
0 | toMinutes / fromMinutes helpers; no deps |
src/types.ts |
0 | All TypeScript interfaces (UserInput, JetLagPlan, DayPlan, HourBlock, Action, etc.) |
src/circadian.ts |
1 | PRC model: computeCBTMinimum, detectTravelDirection, computeLightWindows, advanceCBTMinimum |
src/flightUtils.ts |
2 | computeFlightDuration, convertToHomeTime, layoverPhaseWindows |
src/mealScheduler.ts |
3 | generateMealSchedule — meal/fast actions per day |
src/actions.ts |
4 | assembleHourlyBlocks — pure 24-block assembler |
src/planner.ts |
5 | generatePlan — orchestrates stages 1–4 into a 7-day JetLagPlan |
src/validation.ts |
6 | validateUserInput → { valid, errors[] } |
src/storage.ts |
7 | IndexedDB via idb: savePlan, getPlan, listPlans, deletePlan, clearPlanStorage |
src/ui/* |
8 | React screens: <InputForm>, <PlanView>, <AboutModal> |
vite.config.ts |
9 | Vite + vite-plugin-pwa (Workbox, manifest) |
generatePlan always produces exactly 7 days: 2 pre-travel + 1 travel + 4 post-arrival, starting 2 days before departure. Each day has 24 HourBlocks (one per hour 0–23).
Use Luxon only. Never import moment, dayjs, or date-fns. All timezone arithmetic uses DateTime.fromISO(..., { zone }) and .setZone(). The detectTravelDirection function picks the shorter path across the dateline (wraps diffs > 720 min).
duration = ((wakeMins - sleepMins) + 1440) % 1440
offsetMins = duration <= 420 ? 120 : 180 // 7h boundary
chronoOffset: early → −60, late → +60, intermediate → 0
cbtMin = wakeMins − offsetMins + chronoOffset
- Red first: run the failing test before writing any code.
- One test, one commit: message format
stage-N: <test name>. - No code outside the current stage's module.
- All prior stages must stay green before moving forward.
- If any invariant is violated:
git reset --hard HEADand retry. - No
any, no.skip(), no.only(), noxit()— ever. - No logic in UI code (Stages 1–7 are pure TS + IndexedDB).
// vitest.config.ts
{ test: { environment: 'jsdom', setupFiles: ['fake-indexeddb/auto'] } }The test file is src/__tests__/jetshift.test.ts. It uses declare function stubs at the bottom that must be replaced with real imports from their respective modules as each stage is built.
advanceCBTMinimumsign convention: tests treat eastward as a positive minute-delta;SPEC.md.txtprose says the opposite. Match the tests. File a follow-up after Stage 5.- Service worker
x-from-cacheheader (test line 602): non-standard header, requires a custom WorkboxhandlerDidRespondplugin or test rewrite. Decide at Stage 9 — do not silently change the test. SPEC.md.txttypo line 108:habitual SleepStart(stray space). Tests already use correct formhabitualSleepStart. Fix spec after Stage 9.