Skip to content

Commit 4478db8

Browse files
committed
Slash command shortcut for mentioning GPT-5 Agent
1 parent ea9b8d5 commit 4478db8

File tree

4 files changed

+47
-27
lines changed

4 files changed

+47
-27
lines changed

cli/src/chat.tsx

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import { trackEvent } from './utils/analytics'
7575
import { logger } from './utils/logger'
7676

7777
import type { CommandResult } from './commands/command-registry'
78+
import type { MatchedSlashCommand } from './hooks/use-suggestion-engine'
7879
import type { MultilineInputHandle } from './components/multiline-input'
7980
import type { User } from './utils/auth'
8081
import type { AgentMode } from './utils/constants'
@@ -669,14 +670,10 @@ export const Chat = ({
669670
],
670671
)
671672

672-
// Click handler for slash menu items - executes command immediately
673-
const handleSlashItemClick = useCallback(
674-
async (index: number) => {
675-
const selected = slashMatches[index]
676-
if (!selected) return
677-
678-
// If the command has insertText, insert it instead of executing
679-
if (selected.insertText && slashContext.startIndex >= 0) {
673+
// Helper to apply insertText for slash commands - returns true if handled
674+
const applySlashInsertText = useCallback(
675+
(selected: MatchedSlashCommand): boolean => {
676+
if (selected.insertText != null && slashContext.startIndex >= 0) {
680677
const before = inputValue.slice(0, slashContext.startIndex)
681678
const after = inputValue.slice(
682679
slashContext.startIndex + 1 + slashContext.query.length,
@@ -687,8 +684,21 @@ export const Chat = ({
687684
lastEditDueToNav: false,
688685
})
689686
setSlashSelectedIndex(0)
690-
return
687+
return true
691688
}
689+
return false
690+
},
691+
[slashContext, inputValue, setInputValue, setSlashSelectedIndex],
692+
)
693+
694+
// Click handler for slash menu items - executes command or inserts text
695+
const handleSlashItemClick = useCallback(
696+
async (index: number) => {
697+
const selected = slashMatches[index]
698+
if (!selected) return
699+
700+
// If the command has insertText, insert it instead of executing
701+
if (applySlashInsertText(selected)) return
692702

693703
// Execute the selected slash command immediately
694704
const commandString = `/${selected.id}`
@@ -699,9 +709,7 @@ export const Chat = ({
699709
},
700710
[
701711
slashMatches,
702-
slashContext,
703-
inputValue,
704-
setInputValue,
712+
applySlashInsertText,
705713
setSlashSelectedIndex,
706714
onSubmitPrompt,
707715
agentMode,
@@ -903,19 +911,7 @@ export const Chat = ({
903911
if (!selected) return
904912

905913
// If the command has insertText, insert it instead of executing
906-
if (selected.insertText && slashContext.startIndex >= 0) {
907-
const before = inputValue.slice(0, slashContext.startIndex)
908-
const after = inputValue.slice(
909-
slashContext.startIndex + 1 + slashContext.query.length,
910-
)
911-
setInputValue({
912-
text: before + selected.insertText + after,
913-
cursorPosition: before.length + selected.insertText.length,
914-
lastEditDueToNav: false,
915-
})
916-
setSlashSelectedIndex(0)
917-
return
918-
}
914+
if (applySlashInsertText(selected)) return
919915

920916
// Execute the selected slash command immediately
921917
const commandString = `/${selected.id}`
@@ -929,6 +925,10 @@ export const Chat = ({
929925
// Complete the word without executing - same as clicking on the item
930926
const selected = slashMatches[slashSelectedIndex] || slashMatches[0]
931927
if (!selected || slashContext.startIndex < 0) return
928+
929+
// If the command has insertText, insert it instead of the command
930+
if (applySlashInsertText(selected)) return
931+
932932
const before = inputValue.slice(0, slashContext.startIndex)
933933
const after = inputValue.slice(
934934
slashContext.startIndex + 1 + slashContext.query.length,
@@ -1096,6 +1096,9 @@ export const Chat = ({
10961096
setSlashSelectedIndex,
10971097
slashMatches,
10981098
slashSelectedIndex,
1099+
slashContext,
1100+
inputValue,
1101+
applySlashInsertText,
10991102
onSubmitPrompt,
11001103
agentMode,
11011104
handleCommandResult,

cli/src/commands/__tests__/router-input.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,11 @@ describe('command-registry', () => {
360360
...COMMAND_REGISTRY.flatMap((c) => c.aliases),
361361
])
362362

363-
for (const slashCommand of SLASH_COMMANDS) {
363+
// Commands with insertText are UI-only shortcuts that insert text into
364+
// the input field instead of executing a command.
365+
const executableCommands = SLASH_COMMANDS.filter((cmd) => !cmd.insertText)
366+
367+
for (const slashCommand of executableCommands) {
364368
expect(registered.has(slashCommand.id)).toBe(true)
365369
for (const alias of slashCommand.aliases ?? []) {
366370
expect(registered.has(alias)).toBe(true)

cli/src/commands/command-registry.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,19 @@ export const COMMAND_REGISTRY: CommandDefinition[] = [
454454
return { openPublishMode: true }
455455
},
456456
}),
457+
defineCommand({
458+
name: 'gpt-5-agent',
459+
handler: (params) => {
460+
// Insert @ GPT-5 Agent into the input field (UI shortcut, not a real command)
461+
params.setInputValue({
462+
text: '@GPT-5 Agent ',
463+
cursorPosition: '@GPT-5 Agent '.length,
464+
lastEditDueToNav: false,
465+
})
466+
params.inputRef.current?.focus()
467+
// Don't save to history - this is just a UI shortcut
468+
},
469+
}),
457470
defineCommand({
458471
name: 'connect:claude',
459472
aliases: ['claude'],

cli/src/data/slash-commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export const SLASH_COMMANDS: SlashCommand[] = [
121121
id: 'gpt-5-agent',
122122
label: 'gpt-5-agent',
123123
description: 'Mention the GPT-5 agent to help solve complex problems',
124-
insertText: '@gpt-5-agent ',
124+
insertText: '@GPT-5 Agent ',
125125
},
126126
{
127127
id: 'logout',

0 commit comments

Comments
 (0)