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.

Tighten Assistant prompt history boundaries

rcourtman93420de15792
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 7eccbc95cc..9ce22736a9 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -324,8 +324,12 @@ runtime cost control, and shared AI transport surfaces.
input cursor boundary: previous history is available at the start of the
current draft, and next history restores the saved draft at the end. Pulse's
Assistant drawer follows that draft-safe recall model rather than limiting
- history recall to an empty composer. Scoped context replay remains owned by
- explicit session handoff metadata or queued follow-up edit state.
+ history recall to an empty composer. Once a history entry is loaded, the
+ same boundary ownership remains direction-specific: ArrowUp may move to an
+ older prompt only from the start edge, and ArrowDown may move newer or
+ restore the saved draft only from the end edge, so normal textarea movement
+ is not stolen at the opposite boundary. Scoped context replay remains owned
+ by explicit session handoff metadata or queued follow-up edit state.
Unsent composer drafts are recoverable remount state, not prompt history:
closing or remounting the Assistant drawer must restore the current prompt,
structured mentions, cursor position, and any queued-follow-up edit metadata
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
index 8c54b5fca1..9bdfc65d70 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
+++ b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
@@ -2156,6 +2156,7 @@ describe('AIChat', () => {
fireEvent.keyDown(textarea, { key: 'ArrowUp' });
await waitFor(() => expect(textarea.value).toBe('first prompt'));
+ textarea.setSelectionRange(textarea.value.length, textarea.value.length);
fireEvent.keyDown(textarea, { key: 'ArrowDown' });
await waitFor(() => expect(textarea.value).toBe('second prompt'));
@@ -2180,11 +2181,82 @@ describe('AIChat', () => {
await waitFor(() => expect(textarea.value).toBe('previous prompt'));
+ textarea.setSelectionRange(textarea.value.length, textarea.value.length);
fireEvent.keyDown(textarea, { key: 'ArrowDown' });
await waitFor(() => expect(textarea.value).toBe('draft prompt'));
});
+ it('keeps previous-history navigation at the start boundary only', async () => {
+ localStorage.setItem(
+ 'pulse:ai_chat_prompt_history',
+ JSON.stringify([
+ { prompt: 'newer prompt', mentions: [] },
+ { prompt: 'older prompt', mentions: [] },
+ ]),
+ );
+
+ renderChat();
+ const textarea = screen.getByPlaceholderText(
+ 'Ask about your infrastructure...',
+ ) as HTMLTextAreaElement;
+
+ fireEvent.input(textarea, { target: { value: 'draft prompt' } });
+ textarea.setSelectionRange(0, 0);
+ fireEvent.keyDown(textarea, { key: 'ArrowUp' });
+ await waitFor(() => expect(textarea.value).toBe('newer prompt'));
+
+ textarea.setSelectionRange(textarea.value.length, textarea.value.length);
+ const arrowUpAtEnd = new KeyboardEvent('keydown', {
+ key: 'ArrowUp',
+ bubbles: true,
+ cancelable: true,
+ });
+ textarea.dispatchEvent(arrowUpAtEnd);
+
+ expect(textarea.value).toBe('newer prompt');
+ expect(arrowUpAtEnd.defaultPrevented).toBe(false);
+
+ textarea.setSelectionRange(0, 0);
+ fireEvent.keyDown(textarea, { key: 'ArrowUp' });
+ await waitFor(() => expect(textarea.value).toBe('older prompt'));
+ });
+
+ it('keeps next-history navigation at the end boundary only', async () => {
+ localStorage.setItem(
+ 'pulse:ai_chat_prompt_history',
+ JSON.stringify([
+ { prompt: 'newer prompt', mentions: [] },
+ { prompt: 'older prompt', mentions: [] },
+ ]),
+ );
+
+ renderChat();
+ const textarea = screen.getByPlaceholderText(
+ 'Ask about your infrastructure...',
+ ) as HTMLTextAreaElement;
+
+ fireEvent.input(textarea, { target: { value: 'draft prompt' } });
+ textarea.setSelectionRange(0, 0);
+ fireEvent.keyDown(textarea, { key: 'ArrowUp' });
+ await waitFor(() => expect(textarea.value).toBe('newer prompt'));
+
+ textarea.setSelectionRange(0, 0);
+ const arrowDownAtStart = new KeyboardEvent('keydown', {
+ key: 'ArrowDown',
+ bubbles: true,
+ cancelable: true,
+ });
+ textarea.dispatchEvent(arrowDownAtStart);
+
+ expect(textarea.value).toBe('newer prompt');
+ expect(arrowDownAtStart.defaultPrevented).toBe(false);
+
+ textarea.setSelectionRange(textarea.value.length, textarea.value.length);
+ fireEvent.keyDown(textarea, { key: 'ArrowDown' });
+ await waitFor(() => expect(textarea.value).toBe('draft prompt'));
+ });
+
it('loads persisted prompt history for recall', async () => {
localStorage.setItem(
'pulse:ai_chat_prompt_history',
diff --git a/frontend-modern/src/components/AI/Chat/index.tsx b/frontend-modern/src/components/AI/Chat/index.tsx
index 2bdedda359..6a4335cea9 100644
--- a/frontend-modern/src/components/AI/Chat/index.tsx
+++ b/frontend-modern/src/components/AI/Chat/index.tsx
@@ -991,7 +991,9 @@ export const AIChat: Component<AIChatProps> = (props) => {
const text = input();
const cursor = textareaRef.selectionStart ?? text.length;
const inHistory = promptHistoryIndex() >= 0;
- if (inHistory) return cursor === 0 || cursor === text.length;
+ if (inHistory) {
+ return direction === 'up' ? cursor === 0 : cursor === text.length;
+ }
if (direction === 'up') return cursor === 0;
return false;
};