P4-C: PWA installable, service worker push & campagne de fiabilité dialogues

- PWA: public/manifest.webmanifest + icon.svg + meta index.html (theme-color, apple-touch-icon)
- public/sw.js: service worker push-only (push → showNotification tag=sessionId ;
  notificationclick → focus/ouvre /sessions/<id>) — pas de précache (hors périmètre)
- lib/push.ts + stores/push.ts: enable/disable, abonnement VAPID, enregistrement SW au boot
- DashboardView: toggle « Notifications » (gardé par pushSupported) + i18n en/fr
- campagne de fiabilité (verdict S3): classification de tous les types de dialogue sur captures
  réelles (trust/permission×2/question) + refus Esc (deny-esc2) + plan (synthétique)
- acceptance-p4.mjs: VAPID/auth/Origin, subscribe idempotent/unsubscribe, answer (rejets)

Choix: SW écrit à la main plutôt que vite-plugin-pwa (qui tirait ~295 paquets Workbox +
2 vulns esbuild high pour un SW push-only). Zéro dépendance front nouvelle. 175 tests verts,
acceptance p1..p4 ALL GREEN.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Johan LEROY
2026-06-15 12:23:00 +02:00
parent 28b9283825
commit fbbfafae9b
14 changed files with 505 additions and 1 deletions

View File

@@ -0,0 +1,18 @@
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512" role="img" aria-label="Arboretum">
<rect width="512" height="512" fill="#09090b"/>
<!-- arbre / branches (worktrees) — tracé dans la zone sûre maskable (~80% central) -->
<g fill="none" stroke="#34d399" stroke-width="22" stroke-linecap="round" stroke-linejoin="round">
<!-- tronc -->
<path d="M256 420 V232"/>
<!-- branche gauche -->
<path d="M256 300 L168 212"/>
<!-- branche droite -->
<path d="M256 268 L344 180"/>
</g>
<!-- nœuds (sessions) -->
<g fill="#34d399">
<circle cx="256" cy="156" r="34"/>
<circle cx="160" cy="196" r="26"/>
<circle cx="352" cy="164" r="26"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 727 B

View File

@@ -0,0 +1,13 @@
{
"name": "Arboretum",
"short_name": "Arboretum",
"description": "A self-hosted dashboard for your git worktrees and Claude Code sessions.",
"start_url": "/",
"scope": "/",
"display": "standalone",
"background_color": "#09090b",
"theme_color": "#09090b",
"icons": [
{ "src": "/icon.svg", "sizes": "any", "type": "image/svg+xml", "purpose": "any maskable" }
]
}

52
packages/web/public/sw.js Normal file
View File

@@ -0,0 +1,52 @@
// Service worker Arboretum (P4-C) : Web Push + clic de notification.
// Volontairement minimal — pas de précache offline (hors périmètre P4) : son seul rôle est de
// recevoir les push (session passée en `waiting`) et d'ouvrir/focus la vue session au clic.
self.addEventListener('push', (event) => {
let data = {};
try {
data = event.data ? event.data.json() : {};
} catch {
data = {};
}
const title = data.title || 'Arboretum';
const options = {
body: data.body || 'A session needs your input.',
tag: data.sessionId || 'arboretum', // remplace la notif précédente de la même session
data: { url: data.url || '/' },
icon: '/icon.svg',
badge: '/icon.svg',
requireInteraction: true, // ignoré sur iOS, respecté ailleurs
};
event.waitUntil(self.registration.showNotification(title, options));
});
self.addEventListener('notificationclick', (event) => {
event.notification.close();
const url = (event.notification.data && event.notification.data.url) || '/';
const target = new URL(url, self.location.origin).href;
event.waitUntil(
(async () => {
const clients = await self.clients.matchAll({ type: 'window', includeUncontrolled: true });
for (const client of clients) {
// un onglet de l'app est déjà ouvert : on le focus (et on y navigue si besoin)
if ('focus' in client) {
await client.focus();
if (client.url !== target && 'navigate' in client) {
try {
await client.navigate(target);
} catch {
// navigate peut échouer selon le contexte ; le focus suffit
}
}
return;
}
}
await self.clients.openWindow(target);
})(),
);
});
// Pas de précache : on s'active immédiatement pour que le push soit opérationnel sans recharger.
self.addEventListener('install', () => self.skipWaiting());
self.addEventListener('activate', (event) => event.waitUntil(self.clients.claim()));