P4-A: commande WS answer — répondre aux dialogues sans clavier
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)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
71
packages/web/src/components/DialogPrompt.vue
Normal file
71
packages/web/src/components/DialogPrompt.vue
Normal file
@@ -0,0 +1,71 @@
|
||||
<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>
|
||||
@@ -37,6 +37,9 @@
|
||||
<button v-else class="btn-danger text-xs" @click="confirming = true">{{ t('worktrees.delete') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- réponse rapide aux dialogues des sessions corrélées en attente (sans ouvrir le terminal) -->
|
||||
<DialogPrompt v-for="ws in waitingSessions" :key="`dlg-${ws.id}`" :session="ws" class="mt-2" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -48,6 +51,7 @@ import { useWorktreesStore } from '../stores/worktrees';
|
||||
import { useSessionsStore } from '../stores/sessions';
|
||||
import { ApiError } from '../lib/api';
|
||||
import SessionStateBadge from './SessionStateBadge.vue';
|
||||
import DialogPrompt from './DialogPrompt.vue';
|
||||
|
||||
const props = defineProps<{ worktree: WorktreeSummary }>();
|
||||
const { t } = useI18n();
|
||||
@@ -60,6 +64,11 @@ function liveSession(s: SessionSummary): SessionSummary {
|
||||
return sessions.sessions.find((x) => x.id === s.id) ?? s;
|
||||
}
|
||||
|
||||
// sessions corrélées actuellement bloquées sur un dialogue → réponse rapide inline.
|
||||
const waitingSessions = computed(() =>
|
||||
props.worktree.sessions.map(liveSession).filter((s) => s.live && s.activity === 'waiting' && s.dialog),
|
||||
);
|
||||
|
||||
const confirming = ref(false);
|
||||
const forceNeeded = ref(false);
|
||||
const error = ref<string | null>(null);
|
||||
|
||||
Reference in New Issue
Block a user