Skip to content

Commit 799c58e

Browse files
committed
feat: Enhance user experience and functionality
- Bump extension version to 1.74.0+1 - Add support for custom commit templates using `commit_template.md` in `.cody/configs/` - Implement visual confirmation with a checkmark icon for the copy code block button in chat, with a 5-second reset timer - Enable local context for Enterprise Starter users and add Enterprise Starter development workspace URL - Fix temperature application in chat and workflow functionalities
1 parent ec363f7 commit 799c58e

File tree

8 files changed

+59
-17
lines changed

8 files changed

+59
-17
lines changed

lib/shared/src/chat/chat.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class ChatClient {
8787
messages = messages.concat([{ speaker: 'assistant' }])
8888
}
8989

90-
DEFAULT_CHAT_COMPLETION_PARAMETERS.temperature = this.temperature
90+
DEFAULT_CHAT_COMPLETION_PARAMETERS.temperature = await this.getTemperature()
9191
const completionParams = {
9292
...DEFAULT_CHAT_COMPLETION_PARAMETERS,
9393
...params,

lib/shared/src/sourcegraph-api/environments.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const DOTCOM_WORKSPACE_UPGRADE_URL = new URL('https://sourcegraph.com/cod
4343

4444
const Workspaces_Host_Prod = '.sourcegraph.app'
4545
const Workspaces_Host_Dev = '.sourcegraphapp.test:3443'
46+
const Workspaces_Host_ES_DEV = '.sourcegraphdev.app'
4647

4748
// 🚨 SECURITY: This is used to validate a set of URLs we will allow to be passed in
4849
// to the editor in the URL handler.
@@ -56,7 +57,8 @@ export function isWorkspaceInstance(arg: Pick<AuthStatus, 'endpoint'> | undefine
5657
try {
5758
return (
5859
new URL(url).host.endsWith(Workspaces_Host_Prod) ||
59-
new URL(url).host.endsWith(Workspaces_Host_Dev)
60+
new URL(url).host.endsWith(Workspaces_Host_Dev) ||
61+
new URL(url).host.endsWith(Workspaces_Host_ES_DEV)
6062
)
6163
} catch {
6264
return false

vscode/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "cody-ai",
44
"private": true,
55
"displayName": "Cody: AI Code Assistant",
6-
"version": "1.74.0+0",
6+
"version": "1.74.0+1",
77
"publisher": "sourcegraph",
88
"license": "Apache-2.0",
99
"icon": "resources/sourcegraph.png",

vscode/src/chat/initialContext.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
ContextItemSource,
55
type ContextItemTree,
66
type DefaultContext,
7-
FeatureFlag,
87
REMOTE_REPOSITORY_PROVIDER_URI,
98
abortableOperation,
109
authStatus,
@@ -16,7 +15,6 @@ import {
1615
displayPathBasename,
1716
distinctUntilChanged,
1817
expandToLineRange,
19-
featureFlagProvider,
2018
fromVSCodeEvent,
2119
isDotCom,
2220
isError,
@@ -51,7 +49,7 @@ export function observeDefaultContext({
5149
getCurrentFileOrSelection({ chatBuilder }).pipe(distinctUntilChanged()),
5250
getCorpusContextItemsForEditorState().pipe(distinctUntilChanged()),
5351
getOpenCtxContextItems().pipe(distinctUntilChanged()),
54-
featureFlagProvider.evaluatedFeatureFlag(FeatureFlag.NoDefaultRepoChip)
52+
Observable.of(false)
5553
).pipe(
5654
debounceTime(50),
5755
map(
@@ -210,9 +208,8 @@ export function getCorpusContextItemsForEditorState(
210208
return combineLatest(relevantAuthStatus, remoteReposForAllWorkspaceFolders).pipe(
211209
abortableOperation(async ([authStatus, remoteReposForAllWorkspaceFolders], signal) => {
212210
const items: ContextItem[] = []
213-
214211
// Local context is not available to enterprise users
215-
if (!authStatus.isEnterpriseUser) {
212+
if (!authStatus.isEnterpriseUser && authStatus.isEnterpriseStarterUser) {
216213
// TODO(sqs): Support multi-root. Right now, this only supports the 1st workspace root.
217214
const workspaceFolder = vscode.workspace.workspaceFolders?.at(0)
218215

vscode/src/commands/scm/prompts.ts

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { ps } from '@sourcegraph/cody-shared'
1+
import * as path from 'node:path'
2+
import { PromptString, ps } from '@sourcegraph/cody-shared'
3+
import * as vscode from 'vscode'
24

35
const COMMIT_INTRO = ps`Review the following git command output to understand the changes you are about to generate a commit message for.`
46

@@ -29,3 +31,32 @@ export const COMMIT_COMMAND_PROMPTS = {
2931
*/
3032
noTemplate: COMMMIT_TEMPLATE_NOT_FOUNT,
3133
}
34+
35+
export async function getCustomCommitTemplate(): Promise<PromptString | undefined> {
36+
try {
37+
const workspaceFolders = vscode.workspace.workspaceFolders?.[0]
38+
if (!workspaceFolders) {
39+
return undefined
40+
}
41+
42+
const commitTemplatePath = path.join(
43+
workspaceFolders.uri.path,
44+
'.cody',
45+
'configs',
46+
'commit_template.md'
47+
)
48+
49+
const fileUri = vscode.Uri.file(commitTemplatePath)
50+
const content = await vscode.workspace.fs.readFile(fileUri)
51+
const commitTemplate = Buffer.from(content).toString('utf-8')
52+
53+
// Return undefined if content is empty or only whitespace
54+
if (!commitTemplate.trim()) {
55+
return undefined
56+
}
57+
58+
return PromptString.unsafe_fromLLMResponse(commitTemplate)
59+
} catch {
60+
return undefined
61+
}
62+
}

vscode/src/commands/scm/source-control.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import * as vscode from 'vscode'
2020
import { PromptBuilder } from '../../prompt-builder'
2121
import type { API, GitExtension, InputBox, Repository } from '../../repository/builtinGitExtension'
2222
import { getContextFilesFromGitApi as getContext } from '../context/git-api'
23-
import { COMMIT_COMMAND_PROMPTS } from './prompts'
23+
import { COMMIT_COMMAND_PROMPTS, getCustomCommitTemplate } from './prompts'
2424

2525
export class CodySourceControl implements vscode.Disposable {
2626
private disposables: vscode.Disposable[] = []
@@ -228,9 +228,9 @@ export class CodySourceControl implements vscode.Disposable {
228228
throw new Error('Failed to get git output.')
229229
}
230230

231-
const templatePrompt = this.commitTemplate
232-
? COMMIT_COMMAND_PROMPTS.template
233-
: COMMIT_COMMAND_PROMPTS.noTemplate
231+
const templateMessage = await getCustomCommitTemplate()
232+
const customTemplate = templateMessage ? templateMessage : COMMIT_COMMAND_PROMPTS.template
233+
const templatePrompt = this.commitTemplate ? COMMIT_COMMAND_PROMPTS.noTemplate : customTemplate
234234
const text = COMMIT_COMMAND_PROMPTS.instruction.replace('{COMMIT_TEMPLATE}', templatePrompt)
235235
const transcript: ChatMessage[] = [{ speaker: 'human', text }]
236236

vscode/src/workflow/workflow-executor.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,6 @@ async function executeLLMNode(
536536
): Promise<string> {
537537
abortSignal?.throwIfAborted()
538538
const oldTemperature = await chatClient.getTemperature()
539-
await chatClient.setTemperature((node as LLMNode).data.temperature)
540-
541539
const inputs = combineParentOutputsByConnectionOrder(node.id, context).map(input =>
542540
sanitizeForPrompt(input)
543541
)
@@ -565,6 +563,7 @@ async function executeLLMNode(
565563
]
566564

567565
const streamPromise = new Promise<string>((resolve, reject) => {
566+
chatClient.setTemperature((node as LLMNode).data.temperature)
568567
// Use the AsyncGenerator correctly
569568
chatClient
570569
.chat(
@@ -580,6 +579,7 @@ async function executeLLMNode(
580579
abortSignal
581580
)
582581
.then(async stream => {
582+
chatClient.setTemperature(oldTemperature)
583583
const accumulated = new StringBuilder()
584584
//let chunksProcessed = 0
585585
try {
@@ -605,7 +605,6 @@ async function executeLLMNode(
605605
})
606606
.catch(reject)
607607
})
608-
await chatClient.setTemperature(oldTemperature)
609608
return await Promise.race([streamPromise, timeout])
610609
} catch (error) {
611610
await chatClient.setTemperature(oldTemperature)

vscode/webviews/chat/cells/messageCell/assistant/AssistantMessageCell.tsx

+14-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import isEqual from 'lodash/isEqual'
1919
import { type FunctionComponent, type RefObject, memo, useMemo } from 'react'
2020
import type { ApiPostMessage, UserAccountInfo } from '../../../../Chat'
2121
import { chatModelIconComponent } from '../../../../components/ChatModelIcon'
22+
import { CheckCodeBlockIcon } from '../../../../icons/CodeBlockActionIcons'
2223
import { useOmniBox } from '../../../../utils/useOmniBox'
2324
import {
2425
ChatMessageContent,
@@ -175,11 +176,23 @@ export const AssistantMessageCell: FunctionComponent<{
175176
<button
176177
type="button"
177178
className="tw-flex tw-items-center tw-gap-2 tw-text-sm tw-text-muted-foreground hover:tw-text-foreground"
178-
onClick={() => {
179+
onClick={event => {
180+
const button = event.currentTarget
181+
const originalContent = button.innerHTML
182+
183+
// Change to check icon when clicked
184+
button.innerHTML = CheckCodeBlockIcon
185+
186+
// Copy text to clipboard
179187
navigator.clipboard.writeText(
180188
message.text?.toString() || ''
181189
)
182190
copyButtonOnSubmit?.(message.text?.toString() || '')
191+
192+
// Reset after 5 seconds
193+
setTimeout(() => {
194+
button.innerHTML = originalContent
195+
}, 5000)
183196
}}
184197
title="Copy message to clipboard"
185198
>

0 commit comments

Comments
 (0)