-
Notifications
You must be signed in to change notification settings - Fork 519
Expand file tree
/
Copy pathslash-commands.ts
More file actions
258 lines (242 loc) · 6.46 KB
/
slash-commands.ts
File metadata and controls
258 lines (242 loc) · 6.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
import { CHATGPT_OAUTH_ENABLED } from '@codebuff/common/constants/chatgpt-oauth'
import { CLAUDE_OAUTH_ENABLED } from '@codebuff/common/constants/claude-oauth'
import { AGENT_MODES, IS_FREEBUFF } from '../utils/constants'
import { getChatGptOAuthStatus } from '../utils/chatgpt-oauth'
import { CREDITS_REFERRAL_BONUS } from '@codebuff/common/old-constants'
import type { SkillsMap } from '@codebuff/common/types/skill'
export interface SlashCommand {
id: string
label: string
description: string
aliases?: string[]
/**
* If true, this command can be invoked without a leading slash when the
* input matches the command id exactly (no arguments).
*/
implicitCommand?: boolean
/**
* If set, selecting this command inserts this text into the input field
* instead of executing a command. Useful for agent shortcuts.
*/
insertText?: string
}
// Generate mode commands from the AGENT_MODES constant (excluded in Freebuff)
const MODE_COMMANDS: SlashCommand[] = IS_FREEBUFF
? []
: AGENT_MODES.map((mode) => ({
id: `mode:${mode.toLowerCase()}`,
label: `mode:${mode.toLowerCase()}`,
description: `Switch to ${mode} mode`,
}))
const FREEBUFF_REMOVED_COMMAND_IDS = new Set([
'connect:claude',
'ads:enable',
'ads:disable',
'refer-friends',
'usage',
'subscribe',
'agent:gpt-5',
'image',
'publish',
'init',
])
const FREEBUFF_ONLY_COMMAND_IDS = new Set([
'connect',
'plan',
])
const ALL_SLASH_COMMANDS: SlashCommand[] = [
{
id: 'help',
label: 'help',
description: 'Display keyboard shortcuts and tips',
aliases: ['h', '?'],
implicitCommand: true,
},
...(CLAUDE_OAUTH_ENABLED
? [
{
id: 'connect:claude',
label: 'connect:claude (deprecated)',
description: 'Claude subscription will be removed March 1st',
aliases: ['claude'],
},
]
: []),
...(CHATGPT_OAUTH_ENABLED
? [
{
id: 'connect',
label: 'connect',
description: 'Connect your ChatGPT account',
aliases: ['connect:chatgpt', 'chatgpt'],
},
]
: []),
{
id: 'ads:enable',
label: 'ads:enable',
description: 'Enable contextual ads',
},
{
id: 'ads:disable',
label: 'ads:disable',
description: 'Disable contextual ads',
},
{
id: 'refer-friends',
label: 'refer-friends',
description: `Refer friends for ${CREDITS_REFERRAL_BONUS} bonus credits each`,
aliases: ['referral'],
},
{
id: 'init',
label: 'init',
description: 'Create a starter knowledge.md file',
implicitCommand: true,
},
// {
// id: 'undo',
// label: 'undo',
// description: 'Undo the last change made by the assistant',
// },
// {
// id: 'redo',
// label: 'redo',
// description: 'Redo the most recent undone change',
// },
{
id: 'usage',
label: 'usage',
description: 'View credits and subscription quota',
aliases: ['credits'],
},
{
id: 'subscribe',
label: 'subscribe',
description: 'Subscribe to get more usage',
aliases: ['strong', 'sub', 'buy-credits'],
},
{
id: 'interview',
label: 'interview',
description: 'AI asks a series of questions to flesh out request into a spec',
},
{
id: 'plan',
label: 'plan',
description: 'Create a plan with GPT 5.4',
},
{
id: 'review',
label: 'review',
description: 'Review code changes with GPT 5.4',
},
{
id: 'new',
label: 'new',
description: 'Clear the conversation history and start a new chat',
aliases: ['n', 'clear', 'c', 'reset'],
implicitCommand: true,
},
{
id: 'history',
label: 'history',
description: 'Browse and resume past conversations',
aliases: ['chats'],
},
{
id: 'agent:gpt-5',
label: 'agent:gpt-5',
description: 'Spawn the GPT-5 agent to help solve complex problems',
insertText: '@GPT-5 Agent ',
},
// {
// id: 'agent:opus',
// label: 'agent:opus',
// description: 'Spawn the Opus agent to help solve any problem',
// insertText: '@Opus Agent ',
// },
{
id: 'feedback',
label: 'feedback',
description: IS_FREEBUFF ? 'Share general feedback about Freebuff' : 'Share general feedback about Codebuff',
},
{
id: 'bash',
label: 'bash',
description: 'Enter bash mode ("!" at beginning enters bash mode)',
aliases: ['!'],
},
{
id: 'image',
label: 'image',
description: 'Attach an image file (or Ctrl+V to paste from clipboard)',
aliases: ['img', 'attach'],
},
...MODE_COMMANDS,
// {
// id: 'publish',
// label: 'publish',
// description: 'Publish agents to the agent store',
// },
{
id: 'theme:toggle',
label: 'theme:toggle',
description: 'Toggle between light and dark mode',
},
{
id: 'logout',
label: 'logout',
description: 'Sign out of your session',
aliases: ['signout'],
implicitCommand: true,
},
{
id: 'exit',
label: 'exit',
description: 'Quit the CLI',
aliases: ['quit', 'q'],
implicitCommand: true,
},
]
export const SLASH_COMMANDS = IS_FREEBUFF
? ALL_SLASH_COMMANDS.filter(
(cmd) => !FREEBUFF_REMOVED_COMMAND_IDS.has(cmd.id),
)
: ALL_SLASH_COMMANDS.filter(
(cmd) => !FREEBUFF_ONLY_COMMAND_IDS.has(cmd.id),
)
export const SLASHLESS_COMMAND_IDS = new Set(
SLASH_COMMANDS.filter((cmd) => cmd.implicitCommand).map((cmd) =>
cmd.id.toLowerCase(),
),
)
/** Maximum description length for skill commands in the slash menu */
const SKILL_MENU_DESCRIPTION_MAX_LENGTH = 50
function truncateDescription(description: string): string {
if (description.length <= SKILL_MENU_DESCRIPTION_MAX_LENGTH) {
return description
}
return description.slice(0, SKILL_MENU_DESCRIPTION_MAX_LENGTH - 1) + '…'
}
/**
* Returns SLASH_COMMANDS merged with skill commands.
* Skills become slash commands that users can invoke directly.
*/
export function getSlashCommandsWithSkills(skills: SkillsMap): SlashCommand[] {
const skillCommands: SlashCommand[] = Object.values(skills).map((skill) => ({
id: `skill:${skill.name}`,
label: `skill:${skill.name}`,
description: truncateDescription(skill.description),
}))
let commands = [...SLASH_COMMANDS, ...skillCommands]
if (IS_FREEBUFF && !getChatGptOAuthStatus().connected) {
commands = commands.map((cmd) => {
if (cmd.id === 'review' || cmd.id === 'plan') {
return { ...cmd, description: 'Connect required. ' + cmd.description }
}
return cmd
})
}
return commands
}