Nouvelle commande WS de haut niveau `answer {channel, action, optionN?}`
traduite côté serveur en keystrokes (chiffre+Entrée / Entrée / Esc) et
validée contre le dialogue courant du tracker (anti-frappe fantôme mobile).
- protocol.ts : message `answer` + validation parseClientMessage + ErrorCode INVALID_ANSWER
- pty-manager.answer() : mappe l'intention en write PTY, réutilise le modèle mono-utilisateur
- gateway : case `answer` (NOT_CONTROLLING / SESSION_EXITED / INVALID_ANSWER)
- web : Attachment.answer(), DialogPrompt.vue (attache interactive légère sink no-op),
intégré dans SessionView, SessionsListView, WorktreeCard + i18n en/fr
- tests : parseClientMessage (answer valide/malformé + fuzz), pty-manager.answer (163 verts)
72 lines
2.6 KiB
Vue
72 lines
2.6 KiB
Vue
<template>
|
|
<div v-if="dialog" class="rounded-lg border border-amber-900/60 bg-amber-950/30 p-3">
|
|
<div class="flex items-center gap-2">
|
|
<span class="badge bg-amber-900 text-amber-200">{{ t(`sessions.dialog.kind.${dialog.kind}`) }}</span>
|
|
<span class="text-sm text-amber-100">{{ dialog.waitingFor ?? t('sessions.dialog.waiting') }}</span>
|
|
</div>
|
|
<div class="mt-2 flex flex-wrap gap-2">
|
|
<button
|
|
v-for="opt in dialog.options"
|
|
:key="opt.n"
|
|
class="btn text-xs"
|
|
:class="opt.selected ? 'border-amber-400 text-amber-200' : ''"
|
|
:disabled="busy"
|
|
@click="respond('select', opt.n)"
|
|
>
|
|
<span class="font-mono text-amber-400">{{ opt.n }}</span> {{ opt.label }}
|
|
</button>
|
|
<button class="btn-danger text-xs" :disabled="busy" @click="respond('deny')">
|
|
{{ t('sessions.dialog.deny') }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
// P4-A : répondre à un dialogue Claude sans ouvrir le terminal. Le composant gère sa
|
|
// propre attache interactive LÉGÈRE (sink no-op, sans xterm), créée à la demande au
|
|
// premier clic et libérée au démontage — c'est ce qui réalise la réponse « mobile ».
|
|
import { computed, onUnmounted } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import type { SessionSummary } from '@arboretum/shared';
|
|
import { wsClient, type Attachment, type TerminalSink } from '../lib/ws-client';
|
|
import { ref } from 'vue';
|
|
|
|
const props = defineProps<{ session: SessionSummary }>();
|
|
const { t } = useI18n();
|
|
|
|
const busy = ref(false);
|
|
const dialog = computed(() => (props.session.activity === 'waiting' ? props.session.dialog ?? null : null));
|
|
|
|
// Sink no-op : l'attache de réponse n'affiche rien ; elle rappelle le callback du flow
|
|
// control pour ne jamais bloquer le PTY côté serveur.
|
|
const noopSink: TerminalSink = {
|
|
write: (_data, cb) => cb?.(),
|
|
reset: () => {},
|
|
onDetached: () => {},
|
|
onControlChanged: () => {},
|
|
};
|
|
|
|
let attachPromise: Promise<Attachment> | null = null;
|
|
function ensureAttached(): Promise<Attachment> {
|
|
attachPromise ??= wsClient.attach({ sessionId: props.session.id, mode: 'interactive', cols: 120, rows: 32, sink: noopSink });
|
|
return attachPromise;
|
|
}
|
|
|
|
async function respond(action: 'select' | 'confirm' | 'deny', optionN?: number): Promise<void> {
|
|
busy.value = true;
|
|
try {
|
|
const att = await ensureAttached();
|
|
att.answer(action, optionN);
|
|
} catch {
|
|
// attache impossible (session disparue) : l'état réel arrive par session_update
|
|
} finally {
|
|
busy.value = false;
|
|
}
|
|
}
|
|
|
|
onUnmounted(() => {
|
|
attachPromise?.then((a) => a.detach()).catch(() => {});
|
|
});
|
|
</script>
|