feat(p10): archivage automatique des sessions terminées (rétention configurable)

- DB: migration #10 (sessions.archived_at + index), helpers archive/unarchive/archiveExpired (soft-archive, jamais de DELETE)
- core/retention-settings.ts: session_retention_days (défaut 30, 0=jamais, 1-3650) + session_purge_days (off)
- core/session-archive.ts: scheduler start/stop/sweep (calqué DiscoveryService), câblé dans runDaemon
- pty-manager.list({includeArchived}) + SessionSummary.archived + emitHistoricalUpdate
- routes: GET /sessions?includeArchived, POST/DELETE /sessions/:id/archive, POST /sessions/archive-now
- protocole additif: message WS session_archived (relayé par la gateway, abonnés 'sessions')
- settings: retentionDays/purgeDays exposés et validés dans PATCH /settings
- web: store sessions (showArchived + archive/unarchive), SessionsListView (toggle/badge/actions), SettingsView (slider rétention), i18n EN+FR
- tests: retention-settings + session-archive (vitest) + settings-routes étendu ; acceptance-p10.mjs (sweep, event WS, resume d'une session archivée → 201, rétention=0)
This commit is contained in:
2026-06-27 13:31:28 +02:00
parent be43911dc0
commit c8dd539571
22 changed files with 818 additions and 42 deletions

View File

@@ -10,6 +10,9 @@ export const useSessionsStore = defineStore('sessions', () => {
const loadError = ref<string | null>(null);
// false (défaut) : les sessions masquées sont exclues ; true : on les inclut (mode « afficher les masquées »).
const showHidden = ref(false);
// false (défaut) : les sessions auto-archivées sont exclues ; true : on les inclut (P10). Filtre
// indépendant et cumulable avec showHidden.
const showArchived = ref(false);
let unsubscribe: (() => void) | null = null;
// vivantes d'abord, puis par date de création décroissante (même ordre que le serveur)
@@ -28,6 +31,11 @@ export const useSessionsStore = defineStore('sessions', () => {
remove(session.id);
return;
}
// idem pour les sessions auto-archivées quand « afficher les archivées » est inactif.
if (session.archived && !showArchived.value) {
remove(session.id);
return;
}
const idx = sessions.value.findIndex((s) => s.id === session.id);
if (idx >= 0) sessions.value.splice(idx, 1, session);
else sessions.value.push(session);
@@ -39,6 +47,12 @@ export const useSessionsStore = defineStore('sessions', () => {
upsert(e.session);
return;
}
if (e.type === 'session_archived') {
// marque la session archivée puis upsert (qui la retire si « afficher les archivées » est off).
const current = sessions.value.find((s) => s.id === e.sessionId);
if (current) upsert({ ...current, archived: true });
return;
}
const current = sessions.value.find((s) => s.id === e.sessionId);
if (!current) return;
upsert({
@@ -55,8 +69,11 @@ export const useSessionsStore = defineStore('sessions', () => {
loading.value = true;
loadError.value = null;
try {
const url = showHidden.value ? '/api/v1/sessions?includeHidden=true' : '/api/v1/sessions';
const res = await api.get<SessionsListResponse>(url);
const params = new URLSearchParams();
if (showHidden.value) params.set('includeHidden', 'true');
if (showArchived.value) params.set('includeArchived', 'true');
const qs = params.toString();
const res = await api.get<SessionsListResponse>(`/api/v1/sessions${qs ? `?${qs}` : ''}`);
sessions.value = sorted(res.sessions);
} catch (err) {
loadError.value = err instanceof Error ? err.message : String(err);
@@ -70,6 +87,24 @@ export const useSessionsStore = defineStore('sessions', () => {
await fetchSessions();
}
async function setShowArchived(value: boolean): Promise<void> {
showArchived.value = value;
await fetchSessions();
}
// Archive une session managée terminée (retrait optimiste si on n'affiche pas les archivées).
async function archiveSession(id: string): Promise<void> {
await api.post<{ ok: true }>(`/api/v1/sessions/${id}/archive`);
if (!showArchived.value) remove(id);
}
// Dés-archive une session (un session_update WS la ré-affichera ; mise à jour optimiste locale).
async function unarchiveSession(id: string): Promise<void> {
await api.delete<{ ok: true }>(`/api/v1/sessions/${id}/archive`);
const current = sessions.value.find((s) => s.id === id);
if (current) upsert({ ...current, archived: false });
}
// Masque une session découverte (retrait optimiste si on n'affiche pas les masquées).
async function hideSession(id: string): Promise<void> {
await api.post<{ ok: true }>(`/api/v1/sessions/${id}/hide`);
@@ -136,8 +171,10 @@ export const useSessionsStore = defineStore('sessions', () => {
loading,
loadError,
showHidden,
showArchived,
fetchSessions,
setShowHidden,
setShowArchived,
startRealtime,
stopRealtime,
createSession,
@@ -148,5 +185,7 @@ export const useSessionsStore = defineStore('sessions', () => {
hideSession,
unhideSession,
hideDiscovered,
archiveSession,
unarchiveSession,
};
});