Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Consume Assistant popup Escape locally

rcourtman6943831292f6
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index ad2ca29090..7f098686c9 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -224,6 +224,18 @@ runtime cost control, and shared AI transport surfaces.
to the composer, and leave ordinary prompts or already-submitted local
command actions untouched. Closing the popup must not leave `/mo`, `/new`, or
another executable command token behind for the next Enter press.
+ Prompt-owned popups must consume their local keyboard commands before global
+ drawer handlers can reinterpret them. The same OpenCode autocomplete source
+ registers prompt-scoped previous/next/hide/select/complete commands in
+ `packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx`
+ (lines 600-658), and OpenCode's help dialog binds Escape as a dialog-local
+ close command in
+ `packages/opencode/src/cli/cmd/tui/ui/dialog-help.tsx` (lines 11-16).
+ Pulse adapts that by having slash autocomplete, resource mention
+ autocomplete, and Assistant command help prevent default handling and stop
+ later document-level keyboard handlers for their owned navigation,
+ selection, and close keys. Escape inside those local surfaces must close the
+ local popup/dialog only; it must not also close the Assistant drawer.
Failed-turn retry is part of that same local chat-runtime boundary: a
retryable in-memory assistant error may replay the original user turn's
structured mentions, finding id, approval override, handoff resources,
diff --git a/frontend-modern/src/components/AI/Chat/AssistantCommandHelpDialog.tsx b/frontend-modern/src/components/AI/Chat/AssistantCommandHelpDialog.tsx
index 3c9a92a1f0..5f3592e542 100644
--- a/frontend-modern/src/components/AI/Chat/AssistantCommandHelpDialog.tsx
+++ b/frontend-modern/src/components/AI/Chat/AssistantCommandHelpDialog.tsx
@@ -17,9 +17,15 @@ interface AssistantCommandHelpDialogProps {
}
export function AssistantCommandHelpDialog(props: AssistantCommandHelpDialogProps) {
+ const consumeDialogCloseKey = (event: KeyboardEvent) => {
+ event.preventDefault();
+ event.stopPropagation();
+ event.stopImmediatePropagation();
+ };
+
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key !== 'Escape') return;
- event.preventDefault();
+ consumeDialogCloseKey(event);
props.onClose();
};
diff --git a/frontend-modern/src/components/AI/Chat/MentionAutocomplete.tsx b/frontend-modern/src/components/AI/Chat/MentionAutocomplete.tsx
index aac95dd0c7..adf4449adb 100644
--- a/frontend-modern/src/components/AI/Chat/MentionAutocomplete.tsx
+++ b/frontend-modern/src/components/AI/Chat/MentionAutocomplete.tsx
@@ -38,6 +38,12 @@ export function MentionAutocomplete(props: MentionAutocompleteProps) {
setSelectedIndex(0);
});
+ const consumeMentionKey = (e: KeyboardEvent) => {
+ e.preventDefault();
+ e.stopPropagation();
+ e.stopImmediatePropagation();
+ };
+
// Handle keyboard navigation
const handleKeyDown = (e: KeyboardEvent) => {
if (!props.visible) return;
@@ -46,22 +52,22 @@ export function MentionAutocomplete(props: MentionAutocompleteProps) {
switch (e.key) {
case 'ArrowDown':
- e.preventDefault();
+ consumeMentionKey(e);
setSelectedIndex((i) => Math.min(i + 1, resources.length - 1));
break;
case 'ArrowUp':
- e.preventDefault();
+ consumeMentionKey(e);
setSelectedIndex((i) => Math.max(i - 1, 0));
break;
case 'Enter':
case 'Tab':
- e.preventDefault();
+ consumeMentionKey(e);
if (resources[selectedIndex()]) {
props.onSelect(resources[selectedIndex()]);
}
break;
case 'Escape':
- e.preventDefault();
+ consumeMentionKey(e);
props.onClose();
break;
}
diff --git a/frontend-modern/src/components/AI/Chat/SlashCommandAutocomplete.tsx b/frontend-modern/src/components/AI/Chat/SlashCommandAutocomplete.tsx
index f3228699e2..e74a44df10 100644
--- a/frontend-modern/src/components/AI/Chat/SlashCommandAutocomplete.tsx
+++ b/frontend-modern/src/components/AI/Chat/SlashCommandAutocomplete.tsx
@@ -65,34 +65,35 @@ export function SlashCommandAutocomplete(props: SlashCommandAutocompleteProps) {
props.onSelect(command);
};
+ const consumeCommandKey = (event: KeyboardEvent) => {
+ event.preventDefault();
+ event.stopPropagation();
+ event.stopImmediatePropagation();
+ };
+
const handleKeyDown = (event: KeyboardEvent) => {
if (!props.visible) return;
const options = commands();
switch (event.key) {
case 'ArrowDown':
- event.preventDefault();
- event.stopPropagation();
+ consumeCommandKey(event);
setSelectedIndex((index) => Math.min(index + 1, Math.max(0, options.length - 1)));
break;
case 'ArrowUp':
- event.preventDefault();
- event.stopPropagation();
+ consumeCommandKey(event);
setSelectedIndex((index) => Math.max(index - 1, 0));
break;
case 'Enter':
- event.preventDefault();
- event.stopPropagation();
+ consumeCommandKey(event);
selectCommand(options[selectedIndex()]);
break;
case 'Tab':
- event.preventDefault();
- event.stopPropagation();
+ consumeCommandKey(event);
selectCommand(options[selectedIndex()]);
break;
case 'Escape':
- event.preventDefault();
- event.stopPropagation();
+ consumeCommandKey(event);
props.onClose();
break;
}
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/AssistantCommandHelpDialog.test.tsx b/frontend-modern/src/components/AI/Chat/__tests__/AssistantCommandHelpDialog.test.tsx
new file mode 100644
index 0000000000..5d5ec5de02
--- /dev/null
+++ b/frontend-modern/src/components/AI/Chat/__tests__/AssistantCommandHelpDialog.test.tsx
@@ -0,0 +1,27 @@
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { cleanup, render, screen } from '@solidjs/testing-library';
+import { AssistantCommandHelpDialog } from '../AssistantCommandHelpDialog';
+
+afterEach(cleanup);
+
+describe('AssistantCommandHelpDialog', () => {
+ it('consumes Escape as a local dialog close command', () => {
+ const onClose = vi.fn();
+ render(() => <AssistantCommandHelpDialog onClose={onClose} onRunCommand={vi.fn()} />);
+ expect(screen.getByRole('dialog', { name: 'Assistant commands' })).toBeInTheDocument();
+
+ const laterDocumentHandler = vi.fn();
+ document.addEventListener('keydown', laterDocumentHandler);
+ const escapeEvent = new KeyboardEvent('keydown', {
+ bubbles: true,
+ cancelable: true,
+ key: 'Escape',
+ });
+ document.dispatchEvent(escapeEvent);
+
+ document.removeEventListener('keydown', laterDocumentHandler);
+ expect(escapeEvent.defaultPrevented).toBe(true);
+ expect(laterDocumentHandler).not.toHaveBeenCalled();
+ expect(onClose).toHaveBeenCalledOnce();
+ });
+});
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/MentionAutocomplete.test.tsx b/frontend-modern/src/components/AI/Chat/__tests__/MentionAutocomplete.test.tsx
index d12a815ce2..bd9855355c 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/MentionAutocomplete.test.tsx
+++ b/frontend-modern/src/components/AI/Chat/__tests__/MentionAutocomplete.test.tsx
@@ -261,6 +261,25 @@ describe('MentionAutocomplete', () => {
expect(onClose).toHaveBeenCalledOnce();
});
+ it('consumes owned keyboard events before later document handlers see them', () => {
+ const onClose = vi.fn();
+ renderAutocomplete({ onClose });
+ const laterDocumentHandler = vi.fn();
+ document.addEventListener('keydown', laterDocumentHandler);
+
+ const escapeEvent = new KeyboardEvent('keydown', {
+ bubbles: true,
+ cancelable: true,
+ key: 'Escape',
+ });
+ document.dispatchEvent(escapeEvent);
+
+ document.removeEventListener('keydown', laterDocumentHandler);
+ expect(escapeEvent.defaultPrevented).toBe(true);
+ expect(laterDocumentHandler).not.toHaveBeenCalled();
+ expect(onClose).toHaveBeenCalledOnce();
+ });
+
it('does not respond to keyboard events when not visible', () => {
const onSelect = vi.fn();
const onClose = vi.fn();
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/SlashCommandAutocomplete.test.tsx b/frontend-modern/src/components/AI/Chat/__tests__/SlashCommandAutocomplete.test.tsx
new file mode 100644
index 0000000000..5b10db0a7b
--- /dev/null
+++ b/frontend-modern/src/components/AI/Chat/__tests__/SlashCommandAutocomplete.test.tsx
@@ -0,0 +1,68 @@
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { cleanup, render } from '@solidjs/testing-library';
+import { SlashCommandAutocomplete } from '../SlashCommandAutocomplete';
+
+afterEach(cleanup);
+
+describe('SlashCommandAutocomplete', () => {
+ it('consumes local command navigation keys before later document handlers see them', () => {
+ const onClose = vi.fn();
+ const onSelect = vi.fn();
+ render(() => (
+ <SlashCommandAutocomplete
+ query="mo"
+ visible
+ position={{ top: 58, left: 0 }}
+ onClose={onClose}
+ onSelect={onSelect}
+ />
+ ));
+ const laterDocumentHandler = vi.fn();
+ document.addEventListener('keydown', laterDocumentHandler);
+
+ const escapeEvent = new KeyboardEvent('keydown', {
+ bubbles: true,
+ cancelable: true,
+ key: 'Escape',
+ });
+ document.dispatchEvent(escapeEvent);
+
+ document.removeEventListener('keydown', laterDocumentHandler);
+ expect(escapeEvent.defaultPrevented).toBe(true);
+ expect(laterDocumentHandler).not.toHaveBeenCalled();
+ expect(onClose).toHaveBeenCalledOnce();
+ expect(onSelect).not.toHaveBeenCalled();
+ });
+
+ it('consumes selection keys while running the selected local command', () => {
+ const onSelect = vi.fn();
+ render(() => (
+ <SlashCommandAutocomplete
+ query="mo"
+ visible
+ position={{ top: 58, left: 0 }}
+ onClose={vi.fn()}
+ onSelect={onSelect}
+ />
+ ));
+ const laterDocumentHandler = vi.fn();
+ document.addEventListener('keydown', laterDocumentHandler);
+
+ const enterEvent = new KeyboardEvent('keydown', {
+ bubbles: true,
+ cancelable: true,
+ key: 'Enter',
+ });
+ document.dispatchEvent(enterEvent);
+
+ document.removeEventListener('keydown', laterDocumentHandler);
+ expect(enterEvent.defaultPrevented).toBe(true);
+ expect(laterDocumentHandler).not.toHaveBeenCalled();
+ expect(onSelect).toHaveBeenCalledWith(
+ expect.objectContaining({
+ action: 'models',
+ name: 'models',
+ }),
+ );
+ });
+});