Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/cody-shared/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions client/cody-shared/src/chat/recipes/inline-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import { truncateText } from '../../prompt/truncation'
import { Interaction } from '../transcript/interaction'

import { ChatQuestion } from './chat-question'
import { FileTouch } from './file-touch'
import { Fixup } from './fixup'
import { commandRegex } from './helpers'
import { InlineTouch } from './inline-touch'
import { Recipe, RecipeContext, RecipeID } from './recipe'

export class InlineAssist implements Recipe {
export class InlineChat implements Recipe {
public id: RecipeID = 'inline-chat'

constructor(private debug: (filterLabel: string, text: string, ...args: unknown[]) => void) {}

public async getInteraction(humanChatInput: string, context: RecipeContext): Promise<Interaction | null> {
// Check if this is a touch request
if (commandRegex.touch.test(humanChatInput)) {
return new FileTouch(this.debug).getInteraction(humanChatInput.replace(commandRegex.touch, ''), context)
return new InlineTouch(this.debug).getInteraction(humanChatInput.replace(commandRegex.touch, ''), context)
}

// Check if this is a fixup request
Expand All @@ -39,14 +39,13 @@ export class InlineAssist implements Recipe {

// Reconstruct Cody's prompt using user's context
// Replace placeholders in reverse order to avoid collisions if a placeholder occurs in the input
const promptText = InlineAssist.prompt
const promptText = InlineChat.prompt
.replace('{humanInput}', truncatedText)
.replace('{selectedText}', truncatedSelectedText)
.replace('{fileName}', selection.fileName)

// Text display in UI fpr human that includes the selected code
const displayText =
humanChatInput + InlineAssist.displayPrompt.replace('{selectedText}', selection.selectedText)
const displayText = humanChatInput + InlineChat.displayPrompt.replace('{selectedText}', selection.selectedText)

return Promise.resolve(
new Interaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { Recipe, RecipeContext, RecipeID } from './recipe'
/** ======================================================
* Recipe for Generating a New File
====================================================== **/
export class FileTouch implements Recipe {
public id: RecipeID = 'file-touch'
export class InlineTouch implements Recipe {
public id: RecipeID = 'inline-touch'
private workspacePath = vscode.workspace.workspaceFolders?.[0].uri

constructor(private debug: (filterLabel: string, text: string, ...args: unknown[]) => void) {}
Expand All @@ -43,7 +43,7 @@ export class FileTouch implements Recipe {
// Create file path from selection.fileName and workspacePath
const currentFilePath = `${this.workspacePath.fsPath}/${selection.fileName}`
const currentDir = currentFilePath.replace(/\/[^/]+$/, '')
this.debug('FileTouch:currentDir', 'currentDir', currentDir)
this.debug('InlineTouch:currentDir', 'currentDir', currentDir)

// Create new file name based on the user's input
const newFileName = commandRegex.noTest.test(humanInput)
Expand All @@ -60,15 +60,15 @@ export class FileTouch implements Recipe {
// Create file if it doesn't exist
workspaceEditor.createFile(fileUri, { ignoreIfExists: true })
await vscode.workspace.applyEdit(workspaceEditor)
this.debug('FileTouch:workspaceEditor', 'createFile', fileUri)
this.debug('InlineTouch:workspaceEditor', 'createFile', fileUri)

const truncatedText = truncateText(humanInput, MAX_HUMAN_INPUT_TOKENS)
const MAX_RECIPE_CONTENT_TOKENS = MAX_RECIPE_INPUT_TOKENS + MAX_RECIPE_SURROUNDING_TOKENS * 2
const truncatedSelectedText = truncateText(selection.selectedText, MAX_RECIPE_CONTENT_TOKENS)

// Reconstruct Cody's prompt using user's context
// Replace placeholders in reverse order to avoid collisions if a placeholder occurs in the input
const prompt = FileTouch.newFilePrompt
const prompt = InlineTouch.newFilePrompt
const promptText = prompt
.replace('{newFileName}', newFsPath)
.replace('{humanInput}', truncatedText)
Expand All @@ -88,7 +88,7 @@ export class FileTouch implements Recipe {
return
}
await this.addContentToNewFile(workspaceEditor, fileUri, content)
this.debug('FileTouch:responseMultiplexer', 'BufferedBotResponseSubscriber', content)
this.debug('InlineTouch:responseMultiplexer', 'BufferedBotResponseSubscriber', content)
})
)

Expand Down Expand Up @@ -168,11 +168,11 @@ export class FileTouch implements Recipe {
const contextMessages: ContextMessage[] = []
// Add selected text and current file as context and create context messages from current directory
const selectedContext = ChatQuestion.getEditorSelectionContext(selection)
const currentDirContext = await FileTouch.getEditorDirContext(currentDir)
const currentDirContext = await InlineTouch.getEditorDirContext(currentDir)
contextMessages.push(...selectedContext, ...currentDirContext)
// Create context messages from open tabs
if (contextMessages.length < 10) {
contextMessages.push(...FileTouch.getEditorOpenTabsContext(currentDir))
contextMessages.push(...InlineTouch.getEditorOpenTabsContext(currentDir))
}
return contextMessages.slice(-10)
}
Expand Down Expand Up @@ -238,7 +238,7 @@ export class FileTouch implements Recipe {

// Get display text for human
private getHumanDisplayText(humanChatInput: string, fileName: string): string {
return '**✨Touch✨** ' + humanChatInput + FileTouch.displayPrompt + fileName
return '**✨Touch✨** ' + humanChatInput + InlineTouch.displayPrompt + fileName
}

private async getInstructionFromInput(): Promise<string> {
Expand Down
2 changes: 1 addition & 1 deletion client/cody-shared/src/chat/recipes/recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type RecipeID =
| 'context-search'
| 'explain-code-detailed'
| 'explain-code-high-level'
| 'file-touch'
| 'inline-touch'
| 'find-code-smells'
| 'fixup'
| 'generate-docstring'
Expand Down
2 changes: 1 addition & 1 deletion client/cody-shared/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface Configuration {
customHeaders: Record<string, string>
autocomplete: boolean
experimentalChatPredictions: boolean
experimentalInline: boolean
inlineChat: boolean
experimentalGuardrails: boolean
experimentalNonStop: boolean
autocompleteAdvancedProvider: 'anthropic' | 'unstable-codegen' | 'unstable-huggingface'
Expand Down
2 changes: 1 addition & 1 deletion client/cody-shared/src/telemetry/EventLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function getInlineFromConfig(config: vscode.WorkspaceConfiguration): boolean {
if (!config) {
return false
}
return config.get<boolean>('cody.experimental.inline', false)
return config.get<boolean>('cody.inlineChat.enabled', false)
}

function getNonStopFromConfig(config: vscode.WorkspaceConfiguration): boolean {
Expand Down
5 changes: 4 additions & 1 deletion client/cody/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ Starting from `0.2.0`, Cody is using `major.EVEN_NUMBER.patch` for release versi
- Refactored authentication process. [pull/53434](https://github.com/sourcegraph/sourcegraph/pull/53434)
- New sign-in and sign-out flow. [pull/53434](https://github.com/sourcegraph/sourcegraph/pull/53434)
- Analytical logs are now displayed in the Output view. [pull/53870](https://github.com/sourcegraph/sourcegraph/pull/53870)
- Renamed Inline Assist to Inline Chat. [pull/53725](https://github.com/sourcegraph/sourcegraph/pull/53725)
- Inline Chat: Renamed Inline Assist to Inline Chat. [pull/53725](https://github.com/sourcegraph/sourcegraph/pull/53725) [pull/54315](https://github.com/sourcegraph/sourcegraph/pull/54315)
- Chat: Link to the "Getting Started" guide directly from the first chat message instead of the external documentation website. [pull/54175](https://github.com/sourcegraph/sourcegraph/pull/54175)
- Codebase status icons. [pull/54262](https://github.com/sourcegraph/sourcegraph/pull/54262)
- Changed the keyboard shortcut for the file touch recipe to `ctrl+alt+/` to avoid conflicts. [pull/54275](https://github.com/sourcegraph/sourcegraph/pull/54275)
- Inline Chat: Do not change current focus when Inline Fixup is done. [pull/53980](https://github.com/sourcegraph/sourcegraph/pull/53980)
- Inline Chat: Replace Close CodeLens with Accept. [pull/53980](https://github.com/sourcegraph/sourcegraph/pull/53980)
- Inline Chat: Moved to Beta state. It is now enabled by default. [pull/54315](https://github.com/sourcegraph/sourcegraph/pull/54315)

## [0.2.5]

Expand Down
46 changes: 23 additions & 23 deletions client/cody/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
{
"id": "inline-assist",
"title": "Inline Chat (Experimental)",
"description": "Chat with Cody without leaving your file. Click the + button next to any line number in a file to bring up Inline Chat.\n[Enable in Settings](command:cody.walkthrough.enableInlineAssist)",
"description": "Chat with Cody without leaving your file. Click the + button next to any line number in a file to bring up Inline Chat.\n[Enable in Settings](command:cody.walkthrough.enableInlineChat)",
"media": {
"markdown": "walkthroughs/inline-assist.md"
}
Expand Down Expand Up @@ -356,38 +356,38 @@
"title": "Show Explain"
},
{
"command": "cody.walkthrough.enableInlineAssist",
"command": "cody.walkthrough.enableInlineChat",
"category": "Cody Walkthrough",
"title": "Show Inline Chat"
},
{
"command": "cody.comment.add",
"title": "Ask Cody",
"category": "Cody Inline Chat",
"when": "cody.activated && cody.inline-assist.enabled",
"when": "cody.activated && config.cody.inlineChat.enabled",
"enablement": "!commentIsEmpty"
},
{
"command": "cody.comment.delete",
"title": "Remove Comment",
"category": "Cody Inline Chat",
"when": "cody.activated && cody.inline-assist.enabled",
"when": "cody.activated && config.cody.inlineChat.enabled",
"enablement": "!commentThreadIsEmpty",
"icon": "$(trash)"
},
{
"command": "cody.comment.load",
"title": "Loading",
"category": "Cody Inline Chat",
"when": "cody.activated && cody.inline-assist.enabled",
"when": "cody.activated && config.cody.inlineChat.enabled",
"enablement": "!commentThreadIsEmpty",
"icon": "$(sync~spin)"
},
{
"command": "cody.inline.new",
"title": "Start a new Inline Chat session (Ctrl+Shift+C)",
"category": "Cody Inline Assist",
"when": "cody.activated && cody.inline-assist.enabled",
"when": "cody.activated && config.cody.inlineChat.enabled",
"enablement": "!commentIsEmpty"
},
{
Expand All @@ -397,7 +397,7 @@
"enablement": "config.cody.experimental.guardrails && editorHasSelection"
},
{
"command": "cody.recipe.file-touch",
"command": "cody.recipe.inline-touch",
"category": "Cody",
"title": "Touch"
},
Expand Down Expand Up @@ -472,7 +472,7 @@
"when": "cody.activated && editorHasSelection && !editorReadonly"
},
{
"command": "cody.recipe.file-touch",
"command": "cody.recipe.inline-touch",
"key": "ctrl+alt+/",
"mac": "cmd+alt+/",
"when": "cody.activated && editorTextFocus && !editorReadonly"
Expand Down Expand Up @@ -508,7 +508,7 @@
"when": "cody.activated && editorHasSelection"
},
{
"command": "cody.recipe.file-touch",
"command": "cody.recipe.inline-touch",
"when": "cody.activated && editorHasSelection"
},
{
Expand Down Expand Up @@ -605,7 +605,7 @@
"when": "false"
},
{
"command": "cody.walkthrough.enableInlineAssist",
"command": "cody.walkthrough.enableInlineChat",
"when": "false"
}
],
Expand All @@ -629,8 +629,8 @@
"when": "cody.activated"
},
{
"command": "cody.recipe.file-touch",
"when": "cody.activated && cody.inline-assist.enabled"
"command": "cody.recipe.inline-touch",
"when": "cody.activated && config.cody.inlineChat.enabled"
},
{
"command": "cody.recipe.generate-unit-test",
Expand Down Expand Up @@ -725,24 +725,24 @@
{
"command": "cody.comment.add",
"group": "inline",
"when": "cody.activated && commentController =~ /^cody-inline/ && cody.inline-assist.enabled"
"when": "cody.activated && commentController =~ /^cody-inline/ && config.cody.inlineChat.enabled"
},
{
"command": "cody.focus",
"group": "inline",
"when": "!cody.activated && commentController =~ /^cody-inline/ && cody.inline-assist.enabled"
"when": "!cody.activated && commentController =~ /^cody-inline/ && config.cody.inlineChat.enabled"
}
],
"comments/commentThread/title": [
{
"command": "cody.comment.delete",
"group": "inline@1",
"when": "cody.activated && commentController =~ /^cody-inline/ && cody.replied && !commentThreadIsEmpty && cody.inline-assist.enabled"
"when": "cody.activated && commentController =~ /^cody-inline/ && cody.replied && !commentThreadIsEmpty && config.cody.inlineChat.enabled"
},
{
"command": "cody.comment.load",
"group": "inline@2",
"when": "cody.activated && commentController =~ /^cody-inline/ && cody.reply.pending && cody.inline-assist.enabled"
"when": "cody.activated && commentController =~ /^cody-inline/ && cody.reply.pending && config.cody.inlineChat.enabled"
}
],
"view/item/context": [
Expand Down Expand Up @@ -819,18 +819,18 @@
"markdownDescription": "Enables inline code suggestions in your editor.",
"default": true
},
"cody.experimental.chatPredictions": {
"cody.inlineChat.enabled": {
"order": 6,
"title": "Cody Inline Chat",
"type": "boolean",
"default": false,
"markdownDescription": "Adds suggestions of possible relevant messages in the chat window."
"markdownDescription": "Enables asking questions and requesting code changes directly from within the code editor. Use the + button next to any line of code to start an inline chat.",
"default": true
},
"cody.experimental.inline": {
"cody.experimental.chatPredictions": {
"order": 7,
"title": "Cody Inline Chat",
"type": "boolean",
"markdownDescription": "Enables asking questions and requesting code changes directly from within the code editor. Use the + button next to any line of code to start an inline chat.",
"default": false
"default": false,
"markdownDescription": "Adds suggestions of possible relevant messages in the chat window."
},
"cody.experimental.guardrails": {
"order": 8,
Expand Down
8 changes: 4 additions & 4 deletions client/cody/src/chat/recipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ChatQuestion } from '@sourcegraph/cody-shared/src/chat/recipes/chat-que
import { ContextSearch } from '@sourcegraph/cody-shared/src/chat/recipes/context-search'
import { ExplainCodeDetailed } from '@sourcegraph/cody-shared/src/chat/recipes/explain-code-detailed'
import { ExplainCodeHighLevel } from '@sourcegraph/cody-shared/src/chat/recipes/explain-code-high-level'
import { FileTouch } from '@sourcegraph/cody-shared/src/chat/recipes/file-touch'
import { FindCodeSmells } from '@sourcegraph/cody-shared/src/chat/recipes/find-code-smells'
import { Fixup } from '@sourcegraph/cody-shared/src/chat/recipes/fixup'
import { GenerateDocstring } from '@sourcegraph/cody-shared/src/chat/recipes/generate-docstring'
Expand All @@ -11,7 +10,8 @@ import { ReleaseNotes } from '@sourcegraph/cody-shared/src/chat/recipes/generate
import { GenerateTest } from '@sourcegraph/cody-shared/src/chat/recipes/generate-test'
import { GitHistory } from '@sourcegraph/cody-shared/src/chat/recipes/git-log'
import { ImproveVariableNames } from '@sourcegraph/cody-shared/src/chat/recipes/improve-variable-names'
import { InlineAssist } from '@sourcegraph/cody-shared/src/chat/recipes/inline-chat'
import { InlineChat } from '@sourcegraph/cody-shared/src/chat/recipes/inline-chat'
import { InlineTouch } from '@sourcegraph/cody-shared/src/chat/recipes/inline-touch'
import { NextQuestions } from '@sourcegraph/cody-shared/src/chat/recipes/next-questions'
import { NonStop } from '@sourcegraph/cody-shared/src/chat/recipes/non-stop'
import { OptimizeCode } from '@sourcegraph/cody-shared/src/chat/recipes/optimize-code'
Expand Down Expand Up @@ -40,14 +40,14 @@ function init(): void {
new ContextSearch(),
new ExplainCodeDetailed(),
new ExplainCodeHighLevel(),
new FileTouch(debug),
new FindCodeSmells(),
new Fixup(),
new GenerateDocstring(),
new GenerateTest(),
new GitHistory(),
new ImproveVariableNames(),
new InlineAssist(debug),
new InlineChat(debug),
new InlineTouch(debug),
new NextQuestions(),
new NonStop(),
new OptimizeCode(),
Expand Down
6 changes: 3 additions & 3 deletions client/cody/src/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('getConfiguration', () => {
autocomplete: true,
experimentalChatPredictions: false,
experimentalGuardrails: false,
experimentalInline: false,
inlineChat: true,
experimentalNonStop: false,
customHeaders: {},
debugEnable: false,
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('getConfiguration', () => {
return true
case 'cody.experimental.guardrails':
return true
case 'cody.experimental.inline':
case 'cody.inlineChat.enabled':
return true
case 'cody.experimental.nonStop':
return true
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('getConfiguration', () => {
autocomplete: false,
experimentalChatPredictions: true,
experimentalGuardrails: true,
experimentalInline: true,
inlineChat: true,
experimentalNonStop: true,
debugEnable: true,
debugVerbose: true,
Expand Down
2 changes: 1 addition & 1 deletion client/cody/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function getConfiguration(config: ConfigGetter): Configuration {
debugFilter: debugRegex,
autocomplete: config.get(CONFIG_KEY.autocompleteEnabled, true),
experimentalChatPredictions: config.get(CONFIG_KEY.experimentalChatPredictions, isTesting),
experimentalInline: config.get(CONFIG_KEY.experimentalInline, isTesting),
inlineChat: config.get(CONFIG_KEY.inlineChatEnabled, true),
experimentalGuardrails: config.get(CONFIG_KEY.experimentalGuardrails, isTesting),
experimentalNonStop: config.get(CONFIG_KEY.experimentalNonStop, isTesting),
autocompleteAdvancedProvider,
Expand Down
Loading