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);
|
||||
|
||||
@@ -47,6 +47,16 @@ export default {
|
||||
idle: 'idle',
|
||||
waiting: 'waiting',
|
||||
},
|
||||
dialog: {
|
||||
waiting: 'Waiting for your input',
|
||||
deny: 'Deny (Esc)',
|
||||
kind: {
|
||||
trust: 'Trust',
|
||||
permission: 'Permission',
|
||||
question: 'Question',
|
||||
plan: 'Plan',
|
||||
},
|
||||
},
|
||||
},
|
||||
dashboard: {
|
||||
title: 'Worktrees',
|
||||
|
||||
@@ -49,6 +49,16 @@ const fr: typeof en = {
|
||||
idle: 'inactive',
|
||||
waiting: 'en attente',
|
||||
},
|
||||
dialog: {
|
||||
waiting: 'En attente de votre saisie',
|
||||
deny: 'Refuser (Échap)',
|
||||
kind: {
|
||||
trust: 'Confiance',
|
||||
permission: 'Permission',
|
||||
question: 'Question',
|
||||
plan: 'Plan',
|
||||
},
|
||||
},
|
||||
},
|
||||
dashboard: {
|
||||
title: 'Worktrees',
|
||||
|
||||
@@ -75,6 +75,16 @@ export class Attachment {
|
||||
this.client.sendControl({ type: 'stdin', channel: this.channel, data });
|
||||
}
|
||||
|
||||
/** Répond à un dialogue Claude (P4-A) sans clavier ; le serveur traduit en keystrokes. */
|
||||
answer(action: 'select' | 'confirm' | 'deny', optionN?: number): void {
|
||||
if (this.closed || this.channel < 0) return;
|
||||
this.client.sendControl(
|
||||
action === 'select' && optionN !== undefined
|
||||
? { type: 'answer', channel: this.channel, action, optionN }
|
||||
: { type: 'answer', channel: this.channel, action },
|
||||
);
|
||||
}
|
||||
|
||||
/** mémorise toujours la taille (réutilisée à la ré-attache) ; n'envoie que si controlling */
|
||||
resize(cols: number, rows: number): void {
|
||||
this.cols = cols;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<LanguageSwitcher />
|
||||
</div>
|
||||
</header>
|
||||
<DialogPrompt v-if="session && session.activity === 'waiting'" :session="session" class="m-2" />
|
||||
<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">
|
||||
@@ -26,6 +27,7 @@ import { useRoute } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useSessionsStore } from '../stores/sessions';
|
||||
import TerminalView from '../components/TerminalView.vue';
|
||||
import DialogPrompt from '../components/DialogPrompt.vue';
|
||||
import LanguageSwitcher from '../components/LanguageSwitcher.vue';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
</div>
|
||||
<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>
|
||||
<DialogPrompt v-if="s.live && s.activity === 'waiting'" :session="s" />
|
||||
<div class="flex flex-wrap items-center gap-2 text-xs text-zinc-500">
|
||||
<span v-if="s.live">{{ t('sessions.clients', s.clients) }}</span>
|
||||
<span v-if="s.exitCode !== null">· {{ t('sessions.exitCode', { code: s.exitCode }) }}</span>
|
||||
@@ -110,6 +111,7 @@ import { useAuthStore } from '../stores/auth';
|
||||
import { useSessionsStore } from '../stores/sessions';
|
||||
import LanguageSwitcher from '../components/LanguageSwitcher.vue';
|
||||
import SessionStateBadge from '../components/SessionStateBadge.vue';
|
||||
import DialogPrompt from '../components/DialogPrompt.vue';
|
||||
|
||||
const { t, locale } = useI18n();
|
||||
const router = useRouter();
|
||||
|
||||
Reference in New Issue
Block a user