P2: découverte & reprise des sessions Claude

Arboretum découvre désormais toutes les sessions Claude de la machine
(scan ~/.claude/projects + registre ~/.claude/sessions), distingue
vivantes/mortes par pid+procStart, et permet de reprendre une morte
(--resume dans son cwd d'origine) ou forker une vivante sans la corrompre.

- shared: SessionSummary enrichi (source, claudeSessionId, pid, resumable,
  attachable, registryStatus) — additif, PROTOCOL_VERSION inchangé ;
  types REST resume/fork.
- db: migration id:2 (claude_session_id, resumed_from).
- core: jsonl-discovery (parseur tolérant, scan asynchrone non bloquant),
  session-registry (vivacité pid+procStart), discovery-service (cache +
  refresh périodique + diff/broadcast), pty-manager (resume/fork + capture
  du claudeSessionId via le registre).
- routes: /sessions/:id/resume (garde-fou 409 anti-corruption sur session
  vivante) et /fork ; GET fusionné managées + découvertes ; relais WS.
- web: badges managed/discovered + busy/idle/waiting, actions conditionnelles
  (Open/Observe/Kill vs Fork/View vs Resume/Fork), vue read-only des sessions
  externes, i18n EN/FR.
- tests: jsonl-discovery, session-registry, discovery-service + resume/fork
  (130 verts) ; acceptation E2E acceptance-p2.mjs (sans quota) ALL GREEN.

Conforme aux verdicts S1 (resume dans cwd d'origine, vivacité pid+procStart)
et S4 (munge cwd, parseur tête+queue, priorité de titre).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-12 18:20:21 +02:00
parent 8bc48448c2
commit fb175bc7c5
27 changed files with 1363 additions and 41 deletions

View File

@@ -27,9 +27,14 @@ export default {
creating: 'Creating…',
open: 'Open',
observe: 'Observe',
view: 'View',
resume: 'Resume',
fork: 'Fork',
kill: 'Kill',
confirmKill: 'Confirm kill',
live: 'live',
resumable: 'resumable',
sourceDiscovered: 'discovered',
clients: 'no client | 1 client | {n} clients',
exitCode: 'exit code {code}',
statusLabel: {
@@ -37,11 +42,17 @@ export default {
running: 'running',
exited: 'exited',
},
registryStatus: {
busy: 'busy',
idle: 'idle',
waiting: 'waiting',
},
},
terminal: {
observer: 'observer (read-only)',
sessionEnded: 'Session ended',
back: 'Sessions',
notAttachable: 'This session runs outside Arboretum — fork it to interact, or resume it once it has stopped.',
},
ws: {
reconnecting: 'Connection lost — reconnecting…',

View File

@@ -29,9 +29,14 @@ const fr: typeof en = {
creating: 'Création…',
open: 'Ouvrir',
observe: 'Observer',
view: 'Voir',
resume: 'Reprendre',
fork: 'Dupliquer',
kill: 'Tuer',
confirmKill: 'Confirmer',
live: 'en cours',
resumable: 'reprenable',
sourceDiscovered: 'découverte',
clients: 'aucun client | 1 client | {n} clients',
exitCode: 'code de sortie {code}',
statusLabel: {
@@ -39,11 +44,18 @@ const fr: typeof en = {
running: 'en cours',
exited: 'terminée',
},
registryStatus: {
busy: 'occupée',
idle: 'inactive',
waiting: 'en attente',
},
},
terminal: {
observer: 'observateur (lecture seule)',
sessionEnded: 'Session terminée',
back: 'Sessions',
notAttachable:
'Cette session tourne hors dArboretum — dupliquez-la pour interagir, ou reprenez-la une fois arrêtée.',
},
ws: {
reconnecting: 'Connexion perdue — reconnexion…',

View File

@@ -72,5 +72,30 @@ export const useSessionsStore = defineStore('sessions', () => {
await api.delete<{ ok: true }>(`/api/v1/sessions/${id}`);
}
return { sessions, loading, loadError, fetchSessions, startRealtime, stopRealtime, createSession, killSession };
// Reprise d'une session morte (nouveau PTY managé dans son cwd d'origine, côté serveur).
async function resumeSession(id: string): Promise<SessionSummary> {
const res = await api.post<SessionResponse>(`/api/v1/sessions/${id}/resume`);
upsert(res.session);
return res.session;
}
// Fork d'une session (vivante ou morte) — ne corrompt jamais l'originale.
async function forkSession(id: string): Promise<SessionSummary> {
const res = await api.post<SessionResponse>(`/api/v1/sessions/${id}/fork`);
upsert(res.session);
return res.session;
}
return {
sessions,
loading,
loadError,
fetchSessions,
startRealtime,
stopRealtime,
createSession,
killSession,
resumeSession,
forkSession,
};
});

View File

@@ -12,7 +12,11 @@
<LanguageSwitcher />
</div>
</header>
<TerminalView :key="`${sessionId}:${mode}`" :session-id="sessionId" :mode="mode" class="flex-1" />
<TerminalView v-if="attachable" :key="`${sessionId}:${mode}`" :session-id="sessionId" :mode="mode" class="flex-1" />
<!-- session externe non détenue par Arboretum : pas de terminal interactif (cf. fork/resume). -->
<div v-else class="flex flex-1 items-center justify-center p-6 text-center">
<p class="max-w-md text-sm text-zinc-400">{{ t('terminal.notAttachable') }}</p>
</div>
</div>
</template>
@@ -31,6 +35,8 @@ const store = useSessionsStore();
const sessionId = computed(() => String(route.params.id));
const mode = computed<'interactive' | 'observer'>(() => (route.query.mode === 'observer' ? 'observer' : 'interactive'));
const session = computed(() => store.sessions.find((s) => s.id === sessionId.value) ?? null);
// défaut true : une navigation directe (liste pas encore chargée) tente l'attache d'une session managée.
const attachable = computed(() => session.value?.attachable ?? true);
onMounted(() => {
// navigation directe : la liste n'est pas encore chargée (en-tête cwd/commande)

View File

@@ -39,6 +39,7 @@
</button>
</form>
<p v-if="createError" class="text-sm text-red-400">{{ createError }}</p>
<p v-if="actionError" class="text-sm text-red-400">{{ actionError }}</p>
<p v-if="store.loadError" class="text-sm text-red-400">{{ store.loadError }}</p>
<p v-else-if="store.loading && store.sessions.length === 0" class="text-sm text-zinc-500">
@@ -54,32 +55,49 @@
>
<div class="flex items-center gap-2">
<span class="badge bg-zinc-800 font-mono text-zinc-300">{{ s.command }}</span>
<span v-if="s.source === 'discovered'" class="badge bg-sky-950 text-sky-400">
{{ t('sessions.sourceDiscovered') }}
</span>
<span v-if="s.live" class="badge gap-1 bg-emerald-950 text-emerald-400">
<span class="inline-block h-1.5 w-1.5 animate-pulse rounded-full bg-emerald-400" />
{{ t('sessions.live') }}
{{ s.registryStatus ? t(`sessions.registryStatus.${s.registryStatus}`) : t('sessions.live') }}
</span>
<span v-else-if="s.resumable" class="badge bg-amber-950 text-amber-400">{{ t('sessions.resumable') }}</span>
<span v-else class="badge bg-zinc-800 text-zinc-500">{{ t('sessions.statusLabel.exited') }}</span>
<span class="ml-auto text-xs text-zinc-500">{{ formatDate(s.createdAt) }}</span>
</div>
<p class="truncate font-mono text-sm text-zinc-300" :title="s.cwd">{{ s.cwd }}</p>
<p v-if="s.title" class="truncate text-sm text-zinc-200" :title="s.title">{{ s.title }}</p>
<p class="truncate font-mono text-xs text-zinc-400" :title="s.cwd">{{ s.cwd }}</p>
<div class="flex flex-wrap items-center gap-2 text-xs text-zinc-500">
<span>{{ t(`sessions.statusLabel.${s.status}`) }}</span>
<span v-if="s.live">· {{ t('sessions.clients', s.clients) }}</span>
<span v-if="s.live">{{ t('sessions.clients', s.clients) }}</span>
<span v-if="s.exitCode !== null">· {{ t('sessions.exitCode', { code: s.exitCode }) }}</span>
<div v-if="s.live" class="ml-auto flex items-center gap-2">
<RouterLink :to="{ name: 'session', params: { id: s.id } }" class="btn">
{{ t('sessions.open') }}
</RouterLink>
<RouterLink :to="{ name: 'session', params: { id: s.id }, query: { mode: 'observer' } }" class="btn">
{{ t('sessions.observe') }}
</RouterLink>
<template v-if="killArmedId === s.id">
<button class="btn-danger" :disabled="killing" @click="onConfirmKill(s.id)">
{{ t('sessions.confirmKill') }}
</button>
<button class="btn" @click="killArmedId = null">{{ t('common.cancel') }}</button>
<div class="ml-auto flex items-center gap-2">
<!-- session managée vivante : terminal complet -->
<template v-if="s.attachable">
<RouterLink :to="{ name: 'session', params: { id: s.id } }" class="btn">{{ t('sessions.open') }}</RouterLink>
<RouterLink :to="{ name: 'session', params: { id: s.id }, query: { mode: 'observer' } }" class="btn">
{{ t('sessions.observe') }}
</RouterLink>
<template v-if="killArmedId === s.id">
<button class="btn-danger" :disabled="killing" @click="onConfirmKill(s.id)">
{{ t('sessions.confirmKill') }}
</button>
<button class="btn" @click="killArmedId = null">{{ t('common.cancel') }}</button>
</template>
<button v-else class="btn-danger" @click="killArmedId = s.id">{{ t('sessions.kill') }}</button>
</template>
<!-- session externe vivante : pas d'attache (PTY non détenu) vue read-only ou fork -->
<template v-else-if="s.live">
<RouterLink :to="{ name: 'session', params: { id: s.id } }" class="btn">{{ t('sessions.view') }}</RouterLink>
<button class="btn" :disabled="actingId === s.id" @click="onFork(s.id)">{{ t('sessions.fork') }}</button>
</template>
<!-- session morte reprenable : resume direct ou fork -->
<template v-else-if="s.resumable">
<button class="btn-primary" :disabled="actingId === s.id" @click="onResume(s.id)">
{{ t('sessions.resume') }}
</button>
<button class="btn" :disabled="actingId === s.id" @click="onFork(s.id)">{{ t('sessions.fork') }}</button>
</template>
<button v-else class="btn-danger" @click="killArmedId = s.id">{{ t('sessions.kill') }}</button>
</div>
</div>
</li>
@@ -107,6 +125,8 @@ const creating = ref(false);
const createError = ref<string | null>(null);
const killArmedId = ref<string | null>(null);
const killing = ref(false);
const actingId = ref<string | null>(null);
const actionError = ref<string | null>(null);
onMounted(() => {
void store.fetchSessions();
@@ -131,6 +151,32 @@ async function onCreate(): Promise<void> {
}
}
async function onResume(id: string): Promise<void> {
actingId.value = id;
actionError.value = null;
try {
const session = await store.resumeSession(id);
await router.push({ name: 'session', params: { id: session.id } });
} catch (err) {
actionError.value = err instanceof Error ? err.message : String(err);
} finally {
actingId.value = null;
}
}
async function onFork(id: string): Promise<void> {
actingId.value = id;
actionError.value = null;
try {
const session = await store.forkSession(id);
await router.push({ name: 'session', params: { id: session.id } });
} catch (err) {
actionError.value = err instanceof Error ? err.message : String(err);
} finally {
actingId.value = null;
}
}
async function onConfirmKill(id: string): Promise<void> {
killing.value = true;
try {