Skip to content

Commit

Permalink
remove commands recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
abeatrix committed Jan 3, 2024
1 parent 0fef0ee commit deecab3
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 320 deletions.
191 changes: 0 additions & 191 deletions lib/shared/src/chat/recipes/custom-prompt.ts

This file was deleted.

1 change: 0 additions & 1 deletion lib/shared/src/chat/recipes/recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export type RecipeID =
| 'generate-unit-test'
| 'git-history'
| 'improve-variable-names'
| 'custom-prompt'
| 'next-questions'
| 'pr-description'
| 'release-notes'
Expand Down
5 changes: 0 additions & 5 deletions lib/shared/src/editor/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { URI } from 'vscode-uri'

import { CodyPrompt } from '../chat/prompts'
import { ContextFile } from '../codebase-context/messages'

export interface ActiveTextEditor {
content: string
filePath: string
Expand Down Expand Up @@ -82,8 +79,6 @@ export interface VsCodeFixupController {
}

export interface VsCodeCommandsController {
addCommand(key: string, input?: string, contextFiles?: ContextFile[], addEnhancedContext?: boolean): Promise<string>
getCommand(commandRunnerId: string): CodyPrompt | null
menu(type: 'custom' | 'config' | 'default', showDesc?: boolean): Promise<void>
}

Expand Down
30 changes: 4 additions & 26 deletions vscode/src/chat/MessageProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,7 @@ export abstract class MessageProvider extends MessageHandler implements vscode.D

// Filter the human input to check for chat commands and retrieve the correct recipe id
// e.g. /edit from 'chat-question' should be redirected to use the 'fixup' recipe
const command = await this.chatCommandsFilter(
humanChatInput,
recipeId,
{ source, requestID },
userInputContextFiles
)
const command = await this.chatCommandsFilter(humanChatInput, recipeId, { source, requestID })
if (!command) {
return
}
Expand Down Expand Up @@ -576,14 +571,13 @@ export abstract class MessageProvider extends MessageHandler implements vscode.D
break
}
// Get prompt details from controller by title then execute prompt's command
return this.executeRecipe('custom-prompt', title, 'custom-commands')
return vscode.commands.executeCommand('cody.action.commands.exec', title)
}

protected async chatCommandsFilter(
text: string,
recipeId: RecipeID,
eventTrace?: { requestID?: string; source?: ChatEventSource },
userContextFiles?: ContextFile[]
eventTrace?: { requestID?: string; source?: ChatEventSource }
): Promise<{ text: string; recipeId: RecipeID; source?: ChatEventSource } | void> {
const source = eventTrace?.source || undefined
text = text.trim()
Expand Down Expand Up @@ -634,23 +628,7 @@ export abstract class MessageProvider extends MessageHandler implements vscode.D
const assistantResponse = 'Command failed. Please open a file and try again.'
return this.addCustomInteraction({ assistantResponse, text, source })
}
const commandRunnerID = await this.editor.controllers.command?.addCommand(
text,
eventTrace?.requestID,
userContextFiles
)
// no op
if (!commandRunnerID) {
return
}

if (commandRunnerID === 'invalid') {
const assistantResponse = `__${text}__ is not a valid command`
// If no command found, send error message to view
return this.addCustomInteraction({ assistantResponse, text, source })
}

return { text: commandRunnerID, recipeId: 'custom-prompt', source }
return vscode.commands.executeCommand('cody.action.commands.exec', text)
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions vscode/src/chat/chat-view/ChatManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ export class ChatManager implements vscode.Disposable {
return
}

// If it's a fixup command, run the recipe via sidebar view without creating a new panel
if (command.mode === 'edit' || command.mode === 'insert') {
await this.sidebarViewController.executeRecipe('custom-prompt', command.prompt, source)
return
}

// Else, open a new chanel panel and run the command in the new panel
const chatProvider = await this.getChatProvider()
await chatProvider.executeCommand(command, source)
Expand Down
18 changes: 12 additions & 6 deletions vscode/src/chat/chat-view/SimpleChatPanelProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,16 +581,22 @@ export class SimpleChatPanelProvider implements vscode.Disposable {
}

public async executeCommand(command: CodyPrompt, source: ChatEventSource, requestID = uuid.v4()): Promise<void> {
const promptText = command.prompt + command.additionalInput
const promptText = [command.prompt, command.additionalInput].join(' ')
// Check for edit commands
if (command.mode !== 'ask') {
return executeEdit({ instruction: promptText }, source)
}
const text = [command.slashCommand, command.additionalInput].join(' ')
const inputText = [command.slashCommand, command.additionalInput].join(' ')
const currentFile = this.editor.getActiveTextEditorSelectionOrVisibleContent()
const displayText = createDisplayTextWithFileSelection(text, currentFile)
if (!currentFile) {
if (command.context?.selection || command.context?.currentFile || command.context?.currentDir) {
this.postError(new Error('Command failed. Please open a file and try again.'), 'transcript')
return
}
}
const displayText = createDisplayTextWithFileSelection(inputText, currentFile)
this.chatModel.addHumanMessage({ text: promptText }, displayText)
await this.saveSession(text)
await this.saveSession(inputText)
// trigger the context progress indicator
this.postViewTranscript({ speaker: 'assistant' })
await this.generateAssistantResponse(
Expand All @@ -604,7 +610,7 @@ export class SimpleChatPanelProvider implements vscode.Disposable {
requestID,
chatModel: this.chatModel.modelID,
// 🚨 SECURITY: included only for DotCom users.
promptText: authStatus.endpoint && isDotCom(authStatus.endpoint) ? text : undefined,
promptText: authStatus.endpoint && isDotCom(authStatus.endpoint) ? promptText : undefined,
contextSummary,
}
telemetryService.log('CodyVSCodeExtension:recipe:chat-question:executed', properties, {
Expand All @@ -620,7 +626,7 @@ export class SimpleChatPanelProvider implements vscode.Disposable {
if (this.webviewPanel) {
this.webviewPanel.title =
this.history.getChat(this.authProvider.getAuthStatus(), this.sessionID)?.chatTitle ||
getChatPanelTitle(text)
getChatPanelTitle(inputText)
}
}

Expand Down
Loading

0 comments on commit deecab3

Please sign in to comment.