feat(p11): temps réel complet (watcher checkout principal + topic settings)
P11-A — branche du checkout principal modifiée hors Arboretum : - fs-watcher: pin « permanent » non évinçable (pinRepo/unpinRepo, repoPins dans evictIfNeeded) - worktree-manager: armMainCheckoutWatchers() + arm/désarm sur addRepo/découverte/removeRepo/hidden - index.ts: armMainCheckoutWatchers() dans runDaemon → git checkout CLI sur le principal → worktree_update <500ms sans watch client P11-B — réglages en temps réel : - protocole additif: type SettingsBroadcast (source unique, réutilisé par SettingsResponse), topic 'settings', message settings_update (validés parseClientMessage + gateway) - core/settings-bus.ts (EventEmitter) ; routes/settings émet après PATCH ; gateway relaie aux abonnés 'settings' - web: ws-client subscribeSettings + routage ; store settings applySettings/startRealtime ; AppShell abonne globalement ; SettingsView re-sync des drafts scalaires sans écraser une saisie en cours - tests: protocol (topic settings) + fs-watcher (pinRepo non évincé) ; acceptance-p11.mjs (checkout principal <500ms + settings_update)
This commit is contained in:
@@ -45,11 +45,13 @@ onMounted(() => {
|
||||
worktrees.startRealtime();
|
||||
sessions.startRealtime();
|
||||
groups.startRealtime();
|
||||
settings.startRealtime(); // P11 : réglages synchronisés en temps réel (multi-onglets/clients)
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
worktrees.stopRealtime();
|
||||
sessions.stopRealtime();
|
||||
groups.stopRealtime();
|
||||
settings.stopRealtime();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -29,6 +29,8 @@ export interface TerminalSink {
|
||||
export type SessionEvent = Extract<ServerMessage, { type: 'session_update' | 'session_exit' | 'session_archived' }>;
|
||||
export type WorktreeEvent = Extract<ServerMessage, { type: 'repo_update' | 'repo_removed' | 'worktree_update' | 'worktree_removed' }>;
|
||||
export type GroupEvent = Extract<ServerMessage, { type: 'group_update' | 'group_removed' }>;
|
||||
/** P11 — un réglage a changé (diffusé au topic 'settings'). */
|
||||
export type SettingsUpdateEvent = Extract<ServerMessage, { type: 'settings_update' }>;
|
||||
/** P7 — signal ciblé « le détail (changes/diff) d'un worktree regardé a changé ». */
|
||||
export type WorktreeChangesEvent = Extract<ServerMessage, { type: 'worktree_changes' }>;
|
||||
|
||||
@@ -127,6 +129,7 @@ export class WsClient {
|
||||
private readonly sessionListeners = new Set<(e: SessionEvent) => void>();
|
||||
private readonly worktreeListeners = new Set<(e: WorktreeEvent) => void>();
|
||||
private readonly groupListeners = new Set<(e: GroupEvent) => void>();
|
||||
private readonly settingsListeners = new Set<(e: SettingsUpdateEvent) => void>();
|
||||
/** P7 — abonnements ciblés au détail d'un worktree (clé repoId\0path → listeners). */
|
||||
private readonly worktreeChangesListeners = new Map<string, Set<(e: WorktreeChangesEvent) => void>>();
|
||||
|
||||
@@ -177,11 +180,12 @@ export class WsClient {
|
||||
}
|
||||
|
||||
/** topics actifs = union des abonnements courants (une seule connexion partagée). */
|
||||
private activeTopics(): Array<'sessions' | 'worktrees' | 'groups'> {
|
||||
const t: Array<'sessions' | 'worktrees' | 'groups'> = [];
|
||||
private activeTopics(): Array<'sessions' | 'worktrees' | 'groups' | 'settings'> {
|
||||
const t: Array<'sessions' | 'worktrees' | 'groups' | 'settings'> = [];
|
||||
if (this.sessionListeners.size > 0) t.push('sessions');
|
||||
if (this.worktreeListeners.size > 0) t.push('worktrees');
|
||||
if (this.groupListeners.size > 0) t.push('groups');
|
||||
if (this.settingsListeners.size > 0) t.push('settings');
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -219,6 +223,16 @@ export class WsClient {
|
||||
};
|
||||
}
|
||||
|
||||
subscribeSettings(listener: (e: SettingsUpdateEvent) => void): () => void {
|
||||
this.settingsListeners.add(listener);
|
||||
this.connect();
|
||||
this.sendSub();
|
||||
return () => {
|
||||
this.settingsListeners.delete(listener);
|
||||
this.sendSub();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* P7 — observe le détail (changes/diff) d'un worktree précis : envoie `watch`, route les
|
||||
* `worktree_changes` correspondants vers `listener`, et ré-arme automatiquement après reconnexion.
|
||||
@@ -487,6 +501,10 @@ export class WsClient {
|
||||
for (const cb of this.groupListeners) cb(msg);
|
||||
return;
|
||||
}
|
||||
case 'settings_update': {
|
||||
for (const cb of this.settingsListeners) cb(msg);
|
||||
return;
|
||||
}
|
||||
case 'worktree_changes': {
|
||||
const set = this.worktreeChangesListeners.get(`${msg.repoId}\0${msg.path}`);
|
||||
if (set) for (const cb of set) cb(msg);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import type { ServerInfo, SettingsResponse, UpdateSettingsRequest } from '@arboretum/shared';
|
||||
import type { ServerInfo, SettingsBroadcast, SettingsResponse, UpdateSettingsRequest } from '@arboretum/shared';
|
||||
import { api } from '../lib/api';
|
||||
import { wsClient } from '../lib/ws-client';
|
||||
|
||||
// Réglages serveur (découverte des dépôts, infos serveur).
|
||||
// Les préférences purement client (langue) restent gérées par l'i18n/localStorage.
|
||||
@@ -15,18 +16,33 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
const purgeDays = ref(0);
|
||||
const loaded = ref(false);
|
||||
const saving = ref(false);
|
||||
let unsubscribe: (() => void) | null = null;
|
||||
|
||||
/** Applique le sous-objet `settings` (utilisé par GET/PATCH ET par le push WS settings_update). */
|
||||
function applySettings(s: SettingsBroadcast): void {
|
||||
scanRoots.value = s.scanRoots;
|
||||
scanIntervalMin.value = s.scanIntervalMin;
|
||||
claudeBinPath.value = s.claudeBinPath;
|
||||
claudeHome.value = s.claudeHome;
|
||||
retentionDays.value = s.retentionDays;
|
||||
purgeDays.value = s.purgeDays;
|
||||
}
|
||||
|
||||
function apply(res: SettingsResponse): void {
|
||||
server.value = res.server;
|
||||
scanRoots.value = res.settings.scanRoots;
|
||||
scanIntervalMin.value = res.settings.scanIntervalMin;
|
||||
claudeBinPath.value = res.settings.claudeBinPath;
|
||||
claudeHome.value = res.settings.claudeHome;
|
||||
retentionDays.value = res.settings.retentionDays;
|
||||
purgeDays.value = res.settings.purgeDays;
|
||||
applySettings(res.settings);
|
||||
loaded.value = true;
|
||||
}
|
||||
|
||||
// P11 — temps réel : un PATCH /settings d'un autre client/onglet rafraîchit le store ici.
|
||||
function startRealtime(): void {
|
||||
unsubscribe ??= wsClient.subscribeSettings((e) => applySettings(e.settings));
|
||||
}
|
||||
function stopRealtime(): void {
|
||||
unsubscribe?.();
|
||||
unsubscribe = null;
|
||||
}
|
||||
|
||||
async function fetch(): Promise<void> {
|
||||
apply(await api.get<SettingsResponse>('/api/v1/settings'));
|
||||
}
|
||||
@@ -40,5 +56,5 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
}
|
||||
}
|
||||
|
||||
return { server, scanRoots, scanIntervalMin, claudeBinPath, claudeHome, retentionDays, purgeDays, loaded, saving, fetch, save };
|
||||
return { server, scanRoots, scanIntervalMin, claudeBinPath, claudeHome, retentionDays, purgeDays, loaded, saving, fetch, save, startRealtime, stopRealtime };
|
||||
});
|
||||
|
||||
@@ -258,7 +258,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { AlertCircle, Archive, Bell, BellOff, Check, CheckCircle2, Coffee, Copy, Download, FolderOpen, KeyRound, Plus, RefreshCw, ScanSearch, Send, Server, Shield, SlidersHorizontal, Terminal, Trash2, X } from '@lucide/vue';
|
||||
import type {
|
||||
@@ -470,6 +470,14 @@ async function deleteMyData(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
// P11 — un settings_update WS (autre onglet/client) re-synchronise un draft SCALAIRE uniquement
|
||||
// s'il n'a pas été modifié localement (le draft valait encore l'ancienne valeur du store) → on
|
||||
// n'écrase jamais une saisie en cours.
|
||||
watch(() => settings.scanIntervalMin, (n, o) => { if (intervalDraft.value === o) intervalDraft.value = n; });
|
||||
watch(() => settings.retentionDays, (n, o) => { if (retentionDraft.value === o) retentionDraft.value = n; });
|
||||
watch(() => settings.claudeBinPath, (n, o) => { if (claudeBinDraft.value === (o ?? '')) claudeBinDraft.value = n ?? ''; });
|
||||
watch(() => settings.claudeHome, (n, o) => { if (claudeHomeDraft.value === (o ?? '')) claudeHomeDraft.value = n ?? ''; });
|
||||
|
||||
onMounted(async () => {
|
||||
await Promise.all([loadTokens(), settings.loaded ? Promise.resolve() : settings.fetch()]);
|
||||
syncDiscoveryDraft();
|
||||
@@ -477,4 +485,5 @@ onMounted(async () => {
|
||||
syncRetentionDraft();
|
||||
void push.refresh();
|
||||
});
|
||||
// Le temps réel des réglages est géré globalement par l'AppShell (settings.startRealtime).
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user