-
Notifications
You must be signed in to change notification settings - Fork 965
feat(desktop): add slash commands and chat UI improvements #1309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+429
−47
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9e36788
Slash command
Kitenite 495ad1f
Fix issues
Kitenite 4d0c370
Merge remote-tracking branch 'origin' into kitenite/slash-and
Kitenite 267e6db
Refactor
Kitenite 8c25e34
Update create PR skill
Kitenite b482993
Refactor
Kitenite 445f268
feat(chat): scan .claude/commands/ for custom slash commands on load
Kitenite 07660c5
refactor(chat): use Popover anchoring for slash commands, merge origi…
Kitenite 6ae82d5
merge: resolve conflict with origin (remove SUGGESTIONS import)
Kitenite 517ec88
More fixes
Kitenite f458a7c
Merge remote-tracking branch 'origin' into kitenite/slash-and
Kitenite 7826260
Remove speculative change
Kitenite 708fa41
fix(streams,desktop): make SDK errors visible in chat and remove dead…
Kitenite e55c204
Merge remote-tracking branch 'origin' into kitenite/slash-and
Kitenite 19bb884
fix(desktop): log filesystem errors in scanCustomCommands instead of …
Kitenite 051ec3f
Lint
Kitenite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...Content/TabView/ChatPane/ChatInterface/components/SlashCommandInput/SlashCommandInput.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { usePromptInputController } from "@superset/ui/ai-elements/prompt-input"; | ||
| import { Popover, PopoverAnchor } from "@superset/ui/popover"; | ||
| import { useCallback } from "react"; | ||
| import { | ||
| resolveCommandAction, | ||
| type SlashCommand, | ||
| useSlashCommands, | ||
| } from "../../hooks/useSlashCommands"; | ||
| import { SlashCommandMenu } from "../SlashCommandMenu"; | ||
|
|
||
| interface SlashCommandInputProps { | ||
| onCommandSend: (command: SlashCommand) => void; | ||
| cwd: string; | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| export function SlashCommandInput({ | ||
| onCommandSend, | ||
| cwd, | ||
| children, | ||
| }: SlashCommandInputProps) { | ||
| const { textInput } = usePromptInputController(); | ||
|
|
||
| const slashCommands = useSlashCommands({ | ||
| inputValue: textInput.value, | ||
| cwd, | ||
| }); | ||
|
|
||
| const executeCommand = useCallback( | ||
| (command: SlashCommand) => { | ||
| const action = resolveCommandAction(command); | ||
| if (action.shouldSend) { | ||
| onCommandSend(command); | ||
| } | ||
| textInput.setInput(action.text); | ||
| }, | ||
| [onCommandSend, textInput], | ||
| ); | ||
|
|
||
| const handleKeyDownCapture = useCallback( | ||
| (e: React.KeyboardEvent) => { | ||
| if (!slashCommands.isOpen) return; | ||
|
|
||
| switch (e.key) { | ||
| case "Escape": | ||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
| textInput.setInput(""); | ||
| break; | ||
| case "Enter": | ||
| case "Tab": { | ||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
| const cmd = | ||
| slashCommands.filteredCommands[slashCommands.selectedIndex]; | ||
| if (cmd) executeCommand(cmd); | ||
| break; | ||
| } | ||
| case "ArrowUp": | ||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
| slashCommands.navigateUp(); | ||
| break; | ||
| case "ArrowDown": | ||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
| slashCommands.navigateDown(); | ||
| break; | ||
| } | ||
| }, | ||
| [slashCommands, textInput, executeCommand], | ||
| ); | ||
|
|
||
| return ( | ||
| <Popover open={slashCommands.isOpen}> | ||
| <PopoverAnchor asChild> | ||
| <div onKeyDownCapture={handleKeyDownCapture}>{children}</div> | ||
| </PopoverAnchor> | ||
| <SlashCommandMenu | ||
| commands={slashCommands.filteredCommands} | ||
| selectedIndex={slashCommands.selectedIndex} | ||
| onSelect={executeCommand} | ||
| onHover={slashCommands.setSelectedIndex} | ||
| /> | ||
| </Popover> | ||
| ); | ||
| } |
1 change: 1 addition & 0 deletions
1
...tentView/TabsContent/TabView/ChatPane/ChatInterface/components/SlashCommandInput/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { SlashCommandInput } from "./SlashCommandInput"; |
72 changes: 72 additions & 0 deletions
72
...bsContent/TabView/ChatPane/ChatInterface/components/SlashCommandMenu/SlashCommandMenu.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { PopoverContent } from "@superset/ui/popover"; | ||
| import { useEffect, useRef } from "react"; | ||
| import type { SlashCommand } from "../../hooks/useSlashCommands"; | ||
|
|
||
| interface SlashCommandMenuProps { | ||
| commands: SlashCommand[]; | ||
| selectedIndex: number; | ||
| onSelect: (command: SlashCommand) => void; | ||
| onHover: (index: number) => void; | ||
| } | ||
|
|
||
| export function SlashCommandMenu({ | ||
| commands, | ||
| selectedIndex, | ||
| onSelect, | ||
| onHover, | ||
| }: SlashCommandMenuProps) { | ||
| const selectedRef = useRef<HTMLButtonElement>(null); | ||
|
|
||
| // biome-ignore lint/correctness/useExhaustiveDependencies: must scroll when selectedIndex changes | ||
| useEffect(() => { | ||
| selectedRef.current?.scrollIntoView({ block: "nearest" }); | ||
| }, [selectedIndex]); | ||
|
|
||
| if (commands.length === 0) return null; | ||
|
|
||
| return ( | ||
| <PopoverContent | ||
| side="top" | ||
| align="start" | ||
| sideOffset={0} | ||
| className="w-80 p-0 text-xs" | ||
| onOpenAutoFocus={(e) => e.preventDefault()} | ||
| onCloseAutoFocus={(e) => e.preventDefault()} | ||
| > | ||
| <div className="max-h-[200px] overflow-y-auto p-1"> | ||
| {commands.map((cmd, index) => ( | ||
| <button | ||
| key={cmd.name} | ||
| ref={index === selectedIndex ? selectedRef : undefined} | ||
| type="button" | ||
| className={`flex w-full cursor-pointer flex-col gap-0.5 rounded-md px-3 py-2 text-left transition-colors ${ | ||
| index === selectedIndex | ||
| ? "bg-accent text-accent-foreground" | ||
| : "hover:bg-accent/50" | ||
| }`} | ||
| onMouseEnter={() => onHover(index)} | ||
| onMouseDown={(e) => { | ||
| e.preventDefault(); | ||
| onSelect(cmd); | ||
| }} | ||
| > | ||
| <div className="flex items-center gap-1.5"> | ||
| <span className="font-mono text-muted-foreground">/</span> | ||
| <span className="font-medium">{cmd.name}</span> | ||
| {cmd.argumentHint && ( | ||
| <span className="text-muted-foreground"> | ||
| {cmd.argumentHint} | ||
| </span> | ||
| )} | ||
| </div> | ||
| {cmd.description && ( | ||
| <span className="text-muted-foreground pl-4"> | ||
| {cmd.description} | ||
| </span> | ||
| )} | ||
| </button> | ||
| ))} | ||
| </div> | ||
| </PopoverContent> | ||
| ); | ||
| } |
1 change: 1 addition & 0 deletions
1
...ntentView/TabsContent/TabView/ChatPane/ChatInterface/components/SlashCommandMenu/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { SlashCommandMenu } from "./SlashCommandMenu"; |
5 changes: 5 additions & 0 deletions
5
...ew/ContentView/TabsContent/TabView/ChatPane/ChatInterface/hooks/useSlashCommands/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export { | ||
| resolveCommandAction, | ||
| type SlashCommand, | ||
| useSlashCommands, | ||
| } from "./useSlashCommands"; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Front-matter regex won't match on Windows due to
\r\nline endings.readFileSyncpreserves OS-native line endings. On Windows,^---\nwon't match---\r\n, sodescriptionandargumentHintwill silently fall back to""for all commands.Proposed fix — use `\r?\n` in the regex
Note: the
$/mflag in the inner regexes will match before\n, but.+will greedily consume a trailing\r. You may want to.trim()the captures (already done on lines 45-46, so those are fine).📝 Committable suggestion
🤖 Prompt for AI Agents