YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
feat(chat): / command palette, and a Claude-style composer hint (#6026)
Louis Beaumontdbb382cb2ba4
diff --git a/apps/screenpipe-app-tauri/components/__tests__/global-chat-mentions.test.ts b/apps/screenpipe-app-tauri/components/__tests__/global-chat-mentions.test.tsindex d59039965..2bfa5fcfe 100644--- a/apps/screenpipe-app-tauri/components/__tests__/global-chat-mentions.test.ts+++ b/apps/screenpipe-app-tauri/components/__tests__/global-chat-mentions.test.ts@@ -9,6 +9,7 @@ import {buildChatMentionSuggestions,buildSkillMentionSuggestions,buildTagMentionSuggestions,+ COMPOSER_COMMAND_SUGGESTIONS,findComposerMention,filterMentionSuggestions,mentionSuggestionIdentity,@@ -385,6 +386,65 @@ describe("global chat mentions", () => {expect(findComposerMention(input)).toEqual({ trigger, filter });});+ it.each([+ ["/", ""],+ ["/n", "n"],+ ["/new", "new"],+ ["/clear-filters", "clear-filters"],+ ])("opens the command palette for %s", (input, filter) => {+ expect(findComposerMention(input)).toEqual({ trigger: "/", filter });+ });++ // A slash is only a command at position 0. Dates and paths keep typing.+ it.each([+ ["03/04/2025"],+ ["look at src/lib/chat-utils.ts"],+ ["tell me /new"],+ ["/new and then"],+ ])("does not open the command palette for %s", (input) => {+ const match = findComposerMention(input);+ expect(match?.trigger).not.toBe("/");+ });++ it("filters commands by tag and description", () => {+ const base = {+ atMentionSuggestions: [],+ tagMentionSuggestions: [],+ allTagMentionSuggestions: [],+ tagSearchSuggestions: [],+ speakerSuggestions: [],+ };++ expect(+ filterMentionSuggestions({ ...base, mentionTrigger: "/", mentionFilter: "" }),+ ).toEqual(COMPOSER_COMMAND_SUGGESTIONS);++ expect(+ filterMentionSuggestions({+ ...base,+ mentionTrigger: "/",+ mentionFilter: "new",+ }).map((suggestion) => suggestion.tag),+ ).toEqual(["/new"]);++ // matches the description, not just the tag+ expect(+ filterMentionSuggestions({+ ...base,+ mentionTrigger: "/",+ mentionFilter: "inspector",+ }).map((suggestion) => suggestion.tag),+ ).toEqual(["/inspector"]);+ });++ it("gives every command an action id so picking one never inserts text", () => {+ for (const suggestion of COMPOSER_COMMAND_SUGGESTIONS) {+ expect(suggestion.category).toBe("command");+ expect(suggestion.commandId).toBeTruthy();+ expect(suggestion.tag.startsWith("/")).toBe(true);+ }+ });+it("shows speaker suggestions from the @ composer trigger", () => {const atMentionSuggestions = [{ tag: "@today", description: "today's activity", category: "time" as const },diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/composer-input-box.tsx b/apps/screenpipe-app-tauri/components/chat/standalone/composer-input-box.tsxindex 790ffdddd..cadf240d2 100644--- a/apps/screenpipe-app-tauri/components/chat/standalone/composer-input-box.tsx+++ b/apps/screenpipe-app-tauri/components/chat/standalone/composer-input-box.tsx@@ -69,7 +69,10 @@ export function ComposerInputBox({? input.disabledReason: input.isLoading || input.isStreaming? "Message will be queued..."- : "Ask about your screen... (@ chats, $ skills, ~ time, # tags)"+ : // Kept to the same rendered width as the previous legend so it+ // still fits the 600px minimum chat window on one line. `~`+ // and `#` stay live and are taught by the palette itself.+ "Ask about your screen... (/ for commands, @ chats, $ skills)"}disabled={!input.canChat}spellCheck={false}diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-chat-mentions.ts b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-chat-mentions.tsindex aaf7f9363..a1fae6b0f 100644--- a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-chat-mentions.ts+++ b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-chat-mentions.ts@@ -13,7 +13,9 @@ import {mentionSuggestionIdentity,parseMentions,resolvePinnedMentionIndex,+ COMPOSER_COMMAND_SUGGESTIONS,TIME_RANGE_MENTION_SUGGESTIONS,+ type ComposerCommandId,type MentionSuggestion as ChatMentionSuggestion,type MentionTrigger,} from "@/lib/chat-utils";@@ -53,6 +55,7 @@ interface UseChatMentionsOptions {tagMentionSuggestions: MentionSuggestion[];allTagMentionSuggestions: MentionSuggestion[];onOpenConversation: (conversationId: string) => void | Promise<void>;+ onRunCommand: (commandId: ComposerCommandId) => void | Promise<void>;}export function useChatMentions({@@ -66,6 +69,7 @@ export function useChatMentions({tagMentionSuggestions,allTagMentionSuggestions,onOpenConversation,+ onRunCommand,}: UseChatMentionsOptions) {const [showMentionDropdown, setShowMentionDropdown] = useState(false);const [isComposing, setIsComposing] = useState(false);@@ -631,6 +635,22 @@ export function useChatMentions({}, [hasConnectionChip, setChipScrollTop, setInput]);const insertMention = useCallback((tag: string) => {+ // A `/` entry is an action, not a token. Consume the typed command and run+ // it, keeping anything the cursor was sitting in front of.+ const command = COMPOSER_COMMAND_SUGGESTIONS.find(+ (suggestion) => suggestion.tag === tag,+ );+ if (command?.commandId) {+ const cursorPos = inputRef.current?.selectionStart ?? input.length;+ setInput(input.slice(cursorPos));+ setShowMentionDropdown(false);+ setMentionFilter("");+ setMentionTrigger("@");+ inputRef.current?.focus();+ void onRunCommand(command.commandId);+ return;+ }+const chatSuggestion = recentChatSuggestions.find((suggestion) => suggestion.tag === tag && suggestion.conversationId,);@@ -661,7 +681,7 @@ export function useChatMentions({setMentionFilter("");setMentionTrigger("@");inputRef.current?.focus();- }, [input, inputRef, onOpenConversation, recentChatSuggestions, setInput]);+ }, [input, inputRef, onOpenConversation, onRunCommand, recentChatSuggestions, setInput]);return {showMentionDropdown,diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/mention-dropdown.tsx b/apps/screenpipe-app-tauri/components/chat/standalone/mention-dropdown.tsxindex 98e3445e8..f0f31555b 100644--- a/apps/screenpipe-app-tauri/components/chat/standalone/mention-dropdown.tsx+++ b/apps/screenpipe-app-tauri/components/chat/standalone/mention-dropdown.tsx@@ -23,9 +23,10 @@ export function MentionDropdown({animate={{ opacity: 1, y: 0 }}exit={{ opacity: 0, y: 4 }}transition={{ duration: 0.1 }}- className="absolute bottom-full left-0 right-0 mb-1 bg-background border border-border shadow-lg overflow-hidden z-50 max-h-[240px] overflow-y-auto"+ className="absolute bottom-full left-0 right-0 mb-1 bg-background border border-border shadow-lg overflow-hidden z-50 flex flex-col">- {["chat", "skill", "range", "time", "content", "app", "tag", "speaker"].map((category) => {+ <div className="max-h-[240px] overflow-y-auto">+ {["command", "chat", "skill", "range", "time", "content", "app", "tag", "speaker"].map((category) => {const items = mentions.suggestions.filter((suggestion) => suggestion.category === category,);@@ -33,7 +34,9 @@ export function MentionDropdown({return (<div key={category}><div className="px-2 py-1 text-[10px] font-medium uppercase tracking-wider text-muted-foreground bg-muted/30 border-b border-border/50">- {category === "chat"+ {category === "command"+ ? "commands"+ : category === "chat"? "recent chats": category === "skill"? "installed skills"@@ -87,6 +90,10 @@ export function MentionDropdown({<span>Searching tags...</span></div>)}+ </div>+ <div className="px-3 py-1.5 text-[10px] text-muted-foreground border-t border-border/50 bg-muted/20">+ type to filter · ↓/enter to select · esc to clear+ </div></motion.div></AnimatePresence>);diff --git a/apps/screenpipe-app-tauri/components/standalone-chat.tsx b/apps/screenpipe-app-tauri/components/standalone-chat.tsxindex 1a776a6c7..938edf6cc 100644--- a/apps/screenpipe-app-tauri/components/standalone-chat.tsx+++ b/apps/screenpipe-app-tauri/components/standalone-chat.tsx@@ -43,6 +43,7 @@ import {isConversationHistorySyncPrompt,isInjectedTitleSourcePrompt,normalizeComposerMentionsForModel,+ type ComposerCommandId,type ComposerSkillReference,} from "@/lib/chat-utils";import { useAutoSuggestions } from "@/lib/hooks/use-auto-suggestions";@@ -418,6 +419,11 @@ export function StandaloneChat({const openMentionConversationRef = useRef<((conversationId: string) => void | Promise<void>) | null>(null);+ // `/` commands run handlers that are declared further down this component, so+ // they are reached through a ref rather than reordering the whole file.+ const runComposerCommandRef = useRef<+ ((commandId: ComposerCommandId) => void | Promise<void>) | null+ >(null);const atMentionSuggestions = React.useMemo(() => [...STATIC_MENTION_SUGGESTIONS, ...appMentionSuggestions],@@ -475,6 +481,7 @@ export function StandaloneChat({allTagMentionSuggestions,onOpenConversation: (targetConversationId) =>openMentionConversationRef.current?.(targetConversationId),+ onRunCommand: (commandId) => runComposerCommandRef.current?.(commandId),});const dropdownRef = useRef<HTMLDivElement>(null);// Root of the chat surface. The webview drag-drop event is window-global and@@ -1201,6 +1208,25 @@ export function StandaloneChat({(window as any).__e2eStopChat = handleStop;}+ // Render assignment, matching openMentionConversationRef above: every handler+ // a `/` command needs is defined by this point.+ runComposerCommandRef.current = async (commandId: ComposerCommandId) => {+ switch (commandId) {+ case "new-chat":+ await startNewConversationRef.current?.();+ return;+ case "stop":+ await handleStop();+ return;+ case "inspector":+ toggleInspector();+ return;+ case "pipes":+ await commands.showWindow({ Home: { page: "pipes" } });+ return;+ }+ };+const answerPiExtensionUiRequest = useCallback(async (requestId: string | undefined,diff --git a/apps/screenpipe-app-tauri/lib/chat-utils.ts b/apps/screenpipe-app-tauri/lib/chat-utils.tsindex e0328f08b..4c3b9dd28 100644--- a/apps/screenpipe-app-tauri/lib/chat-utils.ts+++ b/apps/screenpipe-app-tauri/lib/chat-utils.ts@@ -933,10 +933,21 @@ export function parseMentions(input: string, options?: ParseMentionsOptions): Paexport interface MentionSuggestion {tag: string;description: string;- category: "chat" | "skill" | "range" | "time" | "content" | "app" | "speaker" | "tag";+ category:+ | "command"+ | "chat"+ | "skill"+ | "range"+ | "time"+ | "content"+ | "app"+ | "speaker"+ | "tag";label?: string;appName?: string;conversationId?: string;+ /** Present only on `/` entries. Picking one runs an action instead of inserting text. */+ commandId?: ComposerCommandId;}export function mentionSuggestionIdentity(suggestion: MentionSuggestion): string {@@ -1093,11 +1104,56 @@ function formatTagAutocompleteDescription(item: AppAutocompleteItem) {return pluralize(item.count, "use");}-export type MentionTrigger = "@" | "#" | "$" | "~";+export type ComposerCommandId = "new-chat" | "stop" | "inspector" | "pipes";++/**+ * `/` entries run an action rather than inserting a token. Ordered the way they+ * are offered, so the first row is the one a bare `/` most likely wants.+ */+export const COMPOSER_COMMAND_SUGGESTIONS: MentionSuggestion[] = [+ {+ tag: "/new",+ label: "/new",+ description: "start a new chat",+ category: "command",+ commandId: "new-chat",+ },+ {+ tag: "/stop",+ label: "/stop",+ description: "stop the current response",+ category: "command",+ commandId: "stop",+ },+ {+ tag: "/inspector",+ label: "/inspector",+ description: "toggle the inspector panel",+ category: "command",+ commandId: "inspector",+ },+ {+ tag: "/pipes",+ label: "/pipes",+ description: "open pipes",+ category: "command",+ commandId: "pipes",+ },+];++export type MentionTrigger = "@" | "#" | "$" | "~" | "/";export function findComposerMention(textBeforeCursor: string,): { trigger: MentionTrigger; filter: string } | null {+ // Anchored to position 0 on purpose: a slash only opens the palette when the+ // message starts with it. Otherwise `03/04` and `src/lib` would open a menu+ // mid-sentence.+ const commandMatch = textBeforeCursor.match(/^\/([\w-]*)$/);+ if (commandMatch) {+ return { trigger: "/", filter: commandMatch[1] };+ }+const match =textBeforeCursor.match(/([@#$])([\w:.-]*)$/) ??textBeforeCursor.match(/(~)([^~@#$]*)$/);@@ -1141,6 +1197,10 @@ export function filterMentionSuggestions({suggestion.label?.toLowerCase().includes(filter) ||suggestion.description.toLowerCase().includes(filter);+ if (mentionTrigger === "/") {+ return COMPOSER_COMMAND_SUGGESTIONS.filter(matchesFilter);+ }+if (mentionTrigger === "#") {if (!filter) return tagMentionSuggestions;if (tagSearchSuggestions.length > 0) return tagSearchSuggestions;