Files
Bike-Tinder/app/static/sw.js
Torres 04463cadcd P3: personalization core — event log + taste engine + section engine + agent pass + API + frontend
- db.py: guarded P3 tables (swipe_events/sections/section_items/taste_profile/
  agent_runs), one-time event seeding from swipes, append_event round math
- taste.py: deterministic taste engine (action x round x recency weights,
  n/(n+3) shrink, ramp w=min(.85,N/60), percentile norm, agent adjustments
  +/-10, points + source-labeled breakdown + tank bands)
- sections.py: compose/read/exhaust/forge — 2 wildcards + <=5 returns
  (<=2 nopes, surprising only) + remainder new, <=4/family, >=3 price
  bands w/ repair, returns maybe>like>nope, last-two-section exclusion,
  ondemand/strict modes
- agentpass.py: mock (deterministic) / live (OpenRouter, one retry) /
  fallback; strict payload schema; --print-summary/--dry-run
- api.py: GET /api/section, POST /api/section/forge, GET /api/trends,
  POST /api/agent/run, POST /api/prefs; P3 payload fields (points, tank,
  slot, round_next, points_breakdown); events stamped with section_id
- frontend: section buffer + progress pill, report screen + forge + mode
  toggle, WILDCARD/SECOND LOOK bands, tank gauges (list + dossier), dossier
  Why-this-rank, real Trends tab, /api/deck fallback for pre-P3 API, sw v2
- selfcheck: 9 new P3 checks (25/25 green)
2026-11-10 23:18:26 -04:00

68 lines
1.9 KiB
JavaScript

/* Bike-Tinder service worker.
- Precache the app shell at install; index.html + sw.js are served with
Cache-Control: no-cache so updates are picked up.
- /api/* : network-first; offline -> 503 JSON (the page toasts "Offline").
- /img/* : cache-first with network fill (mirrored thumbnails stay usable
offline once seen).
- Everything else (shell/navigation): network-first, fall back to cache.
*/
const VERSION = 'bike-tinder-v2';
const SHELL = [
'/',
'/manifest.json',
'/apple-touch-icon.png',
'/icons/icon-192.png',
'/icons/icon-512.png',
'/icons/icon-512-maskable.png'
];
self.addEventListener('install', (e) => {
e.waitUntil(
caches.open(VERSION)
.then((c) => c.addAll(SHELL))
.then(() => self.skipWaiting())
);
});
self.addEventListener('activate', (e) => {
e.waitUntil(
caches.keys()
.then((keys) => Promise.all(keys.filter((k) => k !== VERSION).map((k) => caches.delete(k))))
.then(() => self.clients.claim())
);
});
self.addEventListener('fetch', (e) => {
const req = e.request;
if (req.method !== 'GET') return;
const url = new URL(req.url);
if (url.pathname.startsWith('/api/')) {
e.respondWith(
fetch(req).catch(() => new Response(JSON.stringify({ error: 'offline' }),
{ status: 503, headers: { 'Content-Type': 'application/json' } }))
);
return;
}
if (url.pathname.startsWith('/img/')) {
e.respondWith(
caches.match(req).then((hit) => hit || fetch(req).then((res) => {
if (res.ok) {
const clone = res.clone();
caches.open(VERSION).then((c) => c.put(req, clone));
}
return res;
}).catch(() => new Response('', { status: 404 })))
);
return;
}
// shell + navigation: network first, cache fallback (offline launch)
e.respondWith(
fetch(req).then((res) => res).catch(() =>
caches.match(req).then((hit) => hit || caches.match('/'))
)
);
});