Skip to content
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

refactor: remove starter and premade from cody.json #939

Merged
merged 2 commits into from
Sep 6, 2023
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
15 changes: 0 additions & 15 deletions lib/shared/src/chat/prompts/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Preamble } from '../preamble'

import * as defaultPrompts from './default-prompts.json'
import { toSlashCommand } from './utils'

Expand Down Expand Up @@ -32,25 +30,12 @@ export interface MyPrompts {
commands: Map<string, CodyPrompt>
// backward compatibility
recipes?: Map<string, CodyPrompt>
// Premade is a set of prompts that are added to the start of every new conversation
// --this is where we define the "identity" and "rules" for Cody
premade?: Preamble
// A conversation starter --this is added to the start of every human input sent to Cody.
starter: string
}

// JSON format of MyPrompts
export interface MyPromptsJSON {
commands: { [id: string]: Omit<CodyPrompt, 'slashCommand'> }
recipes?: { [id: string]: CodyPrompt }
premade?: CodyPremade
starter?: string
}

export interface CodyPremade {
actions: string
rules: string
answer: string
}

export interface CodyPrompt {
Expand Down
2 changes: 2 additions & 0 deletions vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Starting from `0.2.0`, Cody is using `major.EVEN_NUMBER.patch` for release versi

### Changed

- Remove `starter` and `premade` fields from the configuration files for custom commands (cody.json). [pull/939](https://github.com/sourcegraph/cody/pull/939)

## [0.10.0]

### Added
Expand Down
26 changes: 6 additions & 20 deletions vscode/src/chat/MessageProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,8 @@ export abstract class MessageProvider extends MessageHandler implements vscode.D
default: {
this.sendTranscript()

const myPremade = (await this.editor.controllers.command?.getCustomConfig())?.premade
if (myPremade) {
this.telemetryService.log('CodyVSCodeExtension:command:customPremade:applied')
}

const { prompt, contextFiles, preciseContexts } = await this.transcript.getPromptForLastInteraction(
getPreamble(this.contextProvider.context.getCodebase(), myPremade),
getPreamble(this.contextProvider.context.getCodebase()),
this.maxPromptTokens
)
this.transcript.setUsedContextFilesForLastInteraction(contextFiles, preciseContexts)
Expand Down Expand Up @@ -374,13 +369,8 @@ export abstract class MessageProvider extends MessageHandler implements vscode.D
}
transcript.addInteraction(interaction)

const myPremade = (await this.editor.controllers.command?.getCustomConfig())?.premade
if (myPremade) {
this.telemetryService.log('CodyVSCodeExtension:command:customPremade:applied')
}

const { prompt, contextFiles } = await transcript.getPromptForLastInteraction(
getPreamble(this.contextProvider.context.getCodebase(), myPremade),
getPreamble(this.contextProvider.context.getCodebase()),
this.maxPromptTokens
)
transcript.setUsedContextFilesForLastInteraction(contextFiles)
Expand Down Expand Up @@ -476,14 +466,10 @@ export abstract class MessageProvider extends MessageHandler implements vscode.D
// Get prompt details from controller by title then execute prompt's command
const promptText = this.editor.controllers.command?.find(title)
await this.editor.controllers.command?.get('command')
logDebug('executeCustomCommand:starting', title)
if (!promptText) {
return
}
await this.executeRecipe('custom-prompt', promptText)
const starter = (await this.editor.controllers.command?.getCustomConfig())?.starter
if (starter) {
this.telemetryService.log('CodyVSCodeExtension:command:customStarter:applied')

if (promptText) {
logDebug('executeCustomCommand:starting', title)
await this.executeRecipe('custom-prompt', promptText)
}
return
}
Expand Down
16 changes: 1 addition & 15 deletions vscode/src/custom-prompts/CustomPromptsStore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { omit } from 'lodash'
import * as vscode from 'vscode'

import { Preamble } from '@sourcegraph/cody-shared/src/chat/preamble'
import {
CodyPrompt,
CodyPromptType,
Expand All @@ -10,7 +9,6 @@ import {
MyPromptsJSON,
} from '@sourcegraph/cody-shared/src/chat/prompts'
import { fromSlashCommand, toSlashCommand } from '@sourcegraph/cody-shared/src/chat/prompts/utils'
import { newPromptMixin, PromptMixin } from '@sourcegraph/cody-shared/src/prompt/prompt-mixin'

import { logDebug, logError } from '../log'

Expand All @@ -30,9 +28,7 @@ import { promptSizeInit } from './utils/menu'
*/
export class CustomPromptsStore implements vscode.Disposable {
public myPromptsJSON: MyPromptsJSON | null = null
public myPremade: Preamble | undefined = undefined
public myPromptsMap = new Map<string, CodyPrompt>()
public myStarter = ''

public promptSize = promptSizeInit
public jsonFileUris: { user?: vscode.Uri; workspace?: vscode.Uri }
Expand Down Expand Up @@ -89,7 +85,7 @@ export class CustomPromptsStore implements vscode.Disposable {
} catch (error) {
logError('CustomPromptsStore:refresh', 'failed', { verbose: error })
}
return { commands: this.myPromptsMap, premade: this.myPremade, starter: this.myStarter }
return { commands: this.myPromptsMap }
}

/**
Expand Down Expand Up @@ -144,19 +140,11 @@ export class CustomPromptsStore implements vscode.Disposable {
// read from the updated config file
return await this.build(type)
}

for (const [key, prompt] of promptEntries) {
const current: CodyPrompt = { ...prompt, slashCommand: toSlashCommand(key) }
current.type = type
this.myPromptsMap.set(current.slashCommand, current)
}

this.myPremade = json.premade
// avoid duplicate starter prompts
if (json.starter && json?.starter !== this.myStarter) {
PromptMixin.addCustom(newPromptMixin(json.starter))
this.myStarter = json.starter
}
if (type === 'user') {
this.myPromptsJSON = json
}
Expand Down Expand Up @@ -275,8 +263,6 @@ export class CustomPromptsStore implements vscode.Disposable {
this.isActive = false
this.myPromptsMap = new Map<string, CodyPrompt>()
this.promptSize = { ...promptSizeInit }
this.myPremade = undefined
this.myStarter = ''
this.myPromptsJSON = null
}

Expand Down