Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(chat): float slash suggestions above the composer like mentions

rubenluetke10-beep00315cde2423
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx b/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
index ca84ef9b84..d5ba3cde79 100644
--- a/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
@@ -471,7 +471,7 @@ export function AgentComposer({ autoFocus = false }: { autoFocus?: boolean }) {
{/* The blue variant of this strip lived here; a running microphone is a
live state, not the accent, so it now shares the one green strip. */}
<DictationStatus onStop={stopDictation} />
- <ChatCommandPanel control={commands} />
+ <ChatCommandPanel control={commands} anchorRef={cardRef} />
<ChatAttachmentStrip
attachments={files.attachments}
analyzing={files.analyzing}
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/ChatCommands.test.tsx b/jarvis/ui/web/frontend/src/components/agentchat/ChatCommands.test.tsx
index e437d5c12b..ab7b38188d 100644
--- a/jarvis/ui/web/frontend/src/components/agentchat/ChatCommands.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentchat/ChatCommands.test.tsx
@@ -1,6 +1,6 @@
import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
import { afterEach, beforeEach, expect, it, vi } from "vitest";
-import { useState } from "react";
+import { useRef, useState } from "react";
import { CHAT_COMMAND_NAMES, parseChatCommand, type ChatControlState } from "@/lib/chatControlApi";
import { createAgentChatStore } from "@/store/agentChat";
import { EMPTY_TIMELINE, reduceEvent } from "./reduce";
@@ -19,9 +19,11 @@ let failOnce = false;
function Harness() {
const [value, setValue] = useState("");
+ const anchorRef = useRef<HTMLDivElement>(null);
const commands = useChatCommands({ value, setValue, onModel: model, agentId: "test" });
- return <><ChatCommandPanel control={commands} /><input aria-label="Message" value={value} onChange={(e) => setValue(e.target.value)} onKeyDown={commands.onKeyDown} />
- <button onClick={() => void commands.execute(value)}>Send</button></>;
+ return <div role="dialog"><div style={{ overflow: "hidden" }} data-testid="scroll-container"><div ref={anchorRef}>
+ <ChatCommandPanel control={commands} anchorRef={anchorRef} /><input aria-label="Message" value={value} onChange={(e) => setValue(e.target.value)} onKeyDown={commands.onKeyDown} />
+ <button onClick={() => void commands.execute(value)}>Send</button></div></div></div>;
}
function type(text: string) { fireEvent.change(screen.getByRole("textbox"), { target: { value: text } }); }
function send(text: string) { type(text); fireEvent.click(screen.getByText("Send")); }
@@ -52,6 +54,29 @@ it("offers all sixteen commands and supports keyboard selection", async () => {
expect(requests).toHaveLength(0);
});
+it("floats outside the clipping container while staying inside the agent dialog", async () => {
+ type("/");
+ const popup = await screen.findByRole("listbox");
+ expect(popup.parentElement).toBe(screen.getByRole("dialog"));
+ expect(screen.getByTestId("scroll-container").contains(popup)).toBe(false);
+ expect(popup.classList.contains("fixed")).toBe(true);
+ expect(popup.style.bottom).not.toBe("");
+});
+
+it("selects an exact command on Enter and dismisses without losing the draft", async () => {
+ type("/clear");
+ await screen.findByRole("option");
+ fireEvent.keyDown(screen.getByRole("textbox"), { key: "Enter" });
+ expect((screen.getByRole("textbox") as HTMLInputElement).value).toBe("/clear ");
+ expect(requests).toHaveLength(0);
+ type("/go");
+ fireEvent.keyDown(screen.getByRole("textbox"), { key: "Escape" });
+ expect(screen.queryByRole("listbox")).toBeNull();
+ expect((screen.getByRole("textbox") as HTMLInputElement).value).toBe("/go");
+ type("/goal");
+ expect(await screen.findByRole("listbox")).toBeTruthy();
+});
+
it("clears and restores only the local view", async () => {
const original = store.getState().timeline;
send("/clear");
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/ChatCommands.tsx b/jarvis/ui/web/frontend/src/components/agentchat/ChatCommands.tsx
index 6f76cfc24a..bfe68272bb 100644
--- a/jarvis/ui/web/frontend/src/components/agentchat/ChatCommands.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentchat/ChatCommands.tsx
@@ -1,4 +1,5 @@
-import { useEffect, useMemo, useRef, useState, type KeyboardEvent } from "react";
+import { useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type KeyboardEvent, type RefObject } from "react";
+import { createPortal } from "react-dom";
import { Loader2, Pause, Play, X } from "lucide-react";
import { useT } from "@/i18n";
import { cn } from "@/lib/utils";
@@ -28,6 +29,7 @@ export function useChatCommands({ value, setValue, onModel, onClear, agentId = "
const [error, setError] = useState("");
const [busy, setBusy] = useState(false);
const [help, setHelp] = useState(false);
+ const [dismissed, setDismissed] = useState(false);
const [panel, setPanel] = useState<"status" | "find" | "routines" | null>(null);
const [hits, setHits] = useState<ChatSearchHit[]>([]);
const [result, setResult] = useState<ChatCommandResult | null>(null);
@@ -62,8 +64,8 @@ export function useChatCommands({ value, setValue, onModel, onClear, agentId = "
}), [catalog, t]);
const token = /^\/([a-z]*)$/.exec(value.trimStart());
const matches = commands.filter((row) => help || row.name.startsWith(token?.[1] ?? ""));
- const open = enabled && (help || Boolean(token && matches.length));
- useEffect(() => { setActiveIndex(0); }, [value, help]);
+ const open = enabled && !dismissed && (help || Boolean(token && matches.length));
+ useEffect(() => { setActiveIndex(0); setDismissed(false); }, [value, help]);
useEffect(() => { if (value) setHelp(false); }, [value]);
async function ensureSession(): Promise<string> {
@@ -108,7 +110,7 @@ export function useChatCommands({ value, setValue, onModel, onClear, agentId = "
sending.current = true; setBusy(true); setError(""); setHelp(false); setResult(null);
try {
switch (command.name) {
- case "help": setHelp(true); break;
+ case "help": setDismissed(false); setHelp(true); break;
case "clear": (onClear ?? view.clear)(); setPanel(null); break;
case "history": restoreTranscriptView(sid); break;
case "model":
@@ -134,11 +136,11 @@ export function useChatCommands({ value, setValue, onModel, onClear, agentId = "
}
function onKeyDown(event: KeyboardEvent): boolean {
if (!open || !matches.length) return false;
- if (event.key === "Escape") { event.preventDefault(); setHelp(false); setValue(""); return true; }
+ if (event.key === "Escape") { event.preventDefault(); setHelp(false); setDismissed(true); return true; }
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
event.preventDefault(); setActiveIndex((n) => (n + (event.key === "ArrowDown" ? 1 : -1) + matches.length) % matches.length); return true;
}
- if (event.key === "Tab" || event.key === "Enter" && value.trim() !== `/${matches[activeIndex]?.name}`) {
+ if (event.key === "Tab" || event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing) {
event.preventDefault(); select(matches[activeIndex] ?? matches[0]); return true;
}
return false;
@@ -153,9 +155,32 @@ export function useChatCommands({ value, setValue, onModel, onClear, agentId = "
state, error, busy, panel, setPanel, hits, reveal, result, agentId };
}
-export function ChatCommandPanel({ control }: { control: ReturnType<typeof useChatCommands> }) {
+export function ChatCommandPanel({ control, anchorRef }: { control: ReturnType<typeof useChatCommands>; anchorRef: RefObject<HTMLElement | null> }) {
const t = useT();
const list = useRef<HTMLDivElement>(null);
+ const [position, setPosition] = useState<CSSProperties | null>(null);
+ useLayoutEffect(() => {
+ if (!control.open) return;
+ const measure = () => {
+ const anchor = anchorRef.current;
+ if (!anchor) return;
+ const rect = anchor.getBoundingClientRect();
+ const width = Math.min(Math.max(rect.width, 320), window.innerWidth - 16);
+ setPosition({
+ left: Math.min(Math.max(8, rect.left), Math.max(8, window.innerWidth - width - 8)),
+ bottom: window.innerHeight - rect.top + 6,
+ width,
+ maxHeight: Math.max(120, Math.min(340, rect.top - 14)),
+ });
+ };
+ measure();
+ window.addEventListener("scroll", measure, true);
+ window.addEventListener("resize", measure);
+ return () => {
+ window.removeEventListener("scroll", measure, true);
+ window.removeEventListener("resize", measure);
+ };
+ }, [control.open, anchorRef, control.matches.length]);
useEffect(() => { list.current?.querySelector<HTMLElement>('[aria-selected="true"]')?.scrollIntoView?.({ block: "nearest" }); }, [control.activeIndex, control.open]);
if (!control.enabled) return null;
const goal = control.state?.goal;
@@ -183,13 +208,14 @@ export function ChatCommandPanel({ control }: { control: ReturnType<typeof useCh
<span className="text-muted-foreground">#{hit.seq}</span> <span className="whitespace-pre-wrap">{hit.text}</span></button>) : <p>{t("slash.no_matches")}</p> : null}
</section> : null}
{control.result?.data.result ? <p className="mb-2 text-muted-foreground" role="status">{t("slash.command_done")}: /{control.result.command}</p> : null}
- {control.open ? <div ref={list} role="listbox" aria-label={t("slash.help")} className="absolute bottom-full left-0 right-0 z-40 mb-2 max-h-80 overflow-auto rounded-xl border border-border bg-popover p-1 shadow-lg">
+ {control.open && position ? createPortal(<div ref={list} role="listbox" aria-label={t("slash.help")} data-combobox-panel="" data-testid="slash-command-picker" style={position}
+ className="pointer-events-auto fixed z-[70] overflow-y-auto rounded-xl border border-border-strong bg-popover p-1 text-xs text-foreground shadow-float">
{control.matches.map((row, index) => <button key={row.name} role="option" aria-selected={index === control.activeIndex} aria-disabled={!row.available}
onMouseEnter={() => control.setActiveIndex(index)} onMouseDown={(e) => e.preventDefault()} onClick={() => control.select(row)}
className={cn("block w-full rounded-lg px-3 py-2 text-left", index === control.activeIndex && "bg-secondary", !row.available && "opacity-50")}>
<span className="font-medium">/{row.name}</span><span className="ml-3 text-muted-foreground">{t(`slash.commands.${row.name}`)}</span>
<span className="mt-0.5 block text-[11px] text-muted-foreground">{row.available ? row.example : row.reason}</span>
</button>)}
- </div> : null}
+ </div>, anchorRef.current?.closest<HTMLElement>('[role="dialog"]') ?? document.body) : null}
</div>;
}
diff --git a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
index c30d95d2c9..bd2fe427ee 100644
--- a/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/chat/AgentChatPanel.tsx
@@ -1104,7 +1104,7 @@ export function Composer({ agent, mentionable, busy, sessionId, cwd, provider, s
return (
<div className="shrink-0 px-4 pb-4 pt-2 sm:px-6">
- <div className={CHAT_MEASURE}><ChatCommandPanel control={commands} /></div>
+ <div className={CHAT_MEASURE}><ChatCommandPanel control={commands} anchorRef={composerRef} /></div>
{problem ? <p className="mb-1 px-1 text-xs text-destructive">{problem}</p> : null}
{mentionOpen && codingError ? <button type="button" className="mb-1 text-xs text-destructive underline" onClick={() => setCodingRetry((n) => n + 1)}>{t("society.chat.coding_retry")}</button> : null}
{mentionOpen && capabilities.inventoryError ? <button type="button" className="mb-1 text-xs text-destructive underline" onClick={capabilities.retryInventory}>{t("common.retry")}</button> : null}