From f5e00a34181303dedba4aeebb367d98c9d07ce0e Mon Sep 17 00:00:00 2001 From: Zhiming Ma Date: Tue, 4 Jun 2024 16:56:51 +0800 Subject: [PATCH] fix(agent&vscode): remove experimental flag for generating commit message. (#2341) --- clients/tabby-agent/src/AgentConfig.ts | 9 ++- clients/tabby-agent/src/TabbyAgent.ts | 12 +-- clients/tabby-agent/src/configFile.ts | 9 ++- .../tabby-agent/src/lsp/ChatEditProvider.ts | 4 +- clients/vscode/package.json | 76 ++++++++++--------- clients/vscode/src/Commands.ts | 10 +-- clients/vscode/src/ContextVariables.ts | 25 +----- clients/vscode/src/extension.ts | 2 +- 8 files changed, 67 insertions(+), 80 deletions(-) diff --git a/clients/tabby-agent/src/AgentConfig.ts b/clients/tabby-agent/src/AgentConfig.ts index 4d8935fd6030..bf45e7d3b1fe 100644 --- a/clients/tabby-agent/src/AgentConfig.ts +++ b/clients/tabby-agent/src/AgentConfig.ts @@ -62,7 +62,7 @@ export type AgentConfig = { limitScope: any; calculateReplaceRange: any; }; - experimentalChat: { + chat: { edit: { documentMaxChars: number; commandMaxChars: number; @@ -159,7 +159,7 @@ export const defaultAgentConfig: AgentConfig = { limitScope: {}, calculateReplaceRange: {}, }, - experimentalChat: { + chat: { edit: { documentMaxChars: 3000, commandMaxChars: 200, @@ -198,8 +198,9 @@ export const defaultAgentConfig: AgentConfig = { generateCommitMessage: { maxDiffLength: 3600, promptTemplate: - "Generate a commit message based on the given diff. \nYou should only reply with the commit message, and the commit message should be in the following format: (): \nexamples: \n * feat(chat): add support for chat. \n * fix(ui): fix homepage links. \nThe diff is: \n\n```diff \n{{diff}} \n``` \n", - responseMatcher: /(?<=^\s*(the commit message.*:\s+)|(`{3}|["'`])\s*)[^"'`\s].*(?=\s*\2\s*$)/gi.toString(), + "You are an AI coding assistant. You should generate a commit message based on the given diff. \nYou should reply the commit message in the following format: \n(): .\n\n\nThe could be feat, fix, docs, refactor, style, test, build, ci, or chore.\nThe scope is optional. \nFor examples: \n- feat: add support for chat. \n- fix(ui): fix homepage links. \n\nThe diff is:\n```diff\n{{diff}}\n```\n", + responseMatcher: + /(?<=(["'`]+)?\s*)(feat|fix|docs|refactor|style|test|build|ci|chore)(\(\w+\))?:.+(?=\s*\1)/gi.toString(), }, }, logs: { diff --git a/clients/tabby-agent/src/TabbyAgent.ts b/clients/tabby-agent/src/TabbyAgent.ts index 02cd7dfe74a7..6d577497bcef 100644 --- a/clients/tabby-agent/src/TabbyAgent.ts +++ b/clients/tabby-agent/src/TabbyAgent.ts @@ -797,7 +797,7 @@ export class TabbyAgent extends EventEmitter implements Agent { } // select diffs from the list to generate a prompt under the prompt size limit - const { maxDiffLength, promptTemplate, responseMatcher } = this.config.experimentalChat.generateCommitMessage; + const { maxDiffLength, promptTemplate, responseMatcher } = this.config.chat.generateCommitMessage; let splitDiffs: string[]; if (typeof diff === "string") { splitDiffs = diff.split(/\n(?=diff)/); @@ -886,25 +886,25 @@ export class TabbyAgent extends EventEmitter implements Agent { throw new Error("Agent is not initialized"); } - const documentMaxChars = this.config.experimentalChat.edit.documentMaxChars; + const documentMaxChars = this.config.chat.edit.documentMaxChars; if (selection.end - selection.start > documentMaxChars) { throw new Error("Document to edit is too long"); } - if (command.length > this.config.experimentalChat.edit.commandMaxChars) { + if (command.length > this.config.chat.edit.commandMaxChars) { throw new Error("Command is too long"); } let promptTemplate: string; let userCommand: string; const presetCommand = /^\/\w+\b/g.exec(command)?.[0]; - const presetConfig = presetCommand && this.config.experimentalChat.edit.presetCommands[presetCommand]; + const presetConfig = presetCommand && this.config.chat.edit.presetCommands[presetCommand]; if (presetConfig) { promptTemplate = presetConfig.promptTemplate; userCommand = command.substring(presetCommand.length); } else { promptTemplate = insertMode - ? this.config.experimentalChat.edit.promptTemplate.insert - : this.config.experimentalChat.edit.promptTemplate.replace; + ? this.config.chat.edit.promptTemplate.insert + : this.config.chat.edit.promptTemplate.replace; userCommand = command; } // Extract the selected text and the surrounding context diff --git a/clients/tabby-agent/src/configFile.ts b/clients/tabby-agent/src/configFile.ts index 41782abee2a8..ef22602fcf7c 100644 --- a/clients/tabby-agent/src/configFile.ts +++ b/clients/tabby-agent/src/configFile.ts @@ -77,10 +77,11 @@ const typeCheckSchema: Record = { "completion.solution.maxItems": "number", "completion.solution.maxTries": "number", "completion.solution.temperature": "number", - experimentalChat: "object", - "experimentalChat.generateCommitMessage": "object", - "experimentalChat.generateCommitMessage.maxDiffLength": "number", - "experimentalChat.generateCommitMessage.promptTemplate": "string", + chat: "object", + "chat.edit": "object", + "chat.generateCommitMessage": "object", + "chat.generateCommitMessage.maxDiffLength": "number", + "chat.generateCommitMessage.promptTemplate": "string", logs: "object", "logs.level": "string", tls: "object", diff --git a/clients/tabby-agent/src/lsp/ChatEditProvider.ts b/clients/tabby-agent/src/lsp/ChatEditProvider.ts index 2f9fed7f9886..576b366bf56e 100644 --- a/clients/tabby-agent/src/lsp/ChatEditProvider.ts +++ b/clients/tabby-agent/src/lsp/ChatEditProvider.ts @@ -59,7 +59,7 @@ export class ChatEditProvider { } async provideEditCommands(params: ChatEditCommandParams): Promise { - const commands = this.agent.getConfig().experimentalChat.edit.presetCommands; + const commands = this.agent.getConfig().chat.edit.presetCommands; const result: ChatEditCommand[] = []; const document = this.documents.get(params.location.uri); @@ -112,7 +112,7 @@ export class ChatEditProvider { message: "Chat feature not available", } as ChatFeatureNotAvailableError; } - const config = this.agent.getConfig().experimentalChat; + const config = this.agent.getConfig().chat; if (params.command.length > config.edit.commandMaxChars) { throw { name: "ChatEditCommandTooLongError", message: "Command too long" } as ChatEditCommandTooLongError; } diff --git a/clients/vscode/package.json b/clients/vscode/package.json index 249fbf658352..54cdbca1e9c0 100644 --- a/clients/vscode/package.json +++ b/clients/vscode/package.json @@ -36,78 +36,91 @@ "commands": [ { "command": "tabby.toggleInlineCompletionTriggerMode", - "title": "Tabby: Toggle Code Completion Trigger Mode (Automatic/Manual)" + "title": "Toggle Code Completion Trigger Mode (Automatic/Manual)", + "category": "Tabby" }, { "command": "tabby.inlineCompletion.trigger", - "title": "Tabby: Trigger Code Completion Manually" + "title": "Trigger Code Completion Manually", + "category": "Tabby" }, { "command": "tabby.setApiEndpoint", - "title": "Tabby: Specify API Endpoint of Tabby" + "title": "Specify API Endpoint of Tabby", + "category": "Tabby" }, { "command": "tabby.setApiToken", - "title": "Tabby: Set API Token" + "title": "Set API Token", + "category": "Tabby" }, { "command": "tabby.openSettings", - "title": "Tabby: Open Settings" + "title": "Open Settings", + "category": "Tabby" }, { "command": "tabby.openTabbyAgentSettings", - "title": "Tabby: Open Tabby Agent Settings" + "title": "Open Tabby Agent Settings", + "category": "Tabby" }, { "command": "tabby.gettingStarted", - "title": "Tabby: Getting Started" + "title": "Getting Started", + "category": "Tabby" }, { "command": "tabby.openOnlineHelp", - "title": "Tabby: Online Help" + "title": "Online Help", + "category": "Tabby" }, { "command": "tabby.notifications.resetMuted", - "title": "Tabby: Reset notifications marked as \"Don't Show Again\"" + "title": "Reset notifications marked as \"Don't Show Again\"", + "category": "Tabby" }, { "command": "tabby.chat.explainCodeBlock", - "title": "Tabby: Explain This" + "title": "Explain This", + "category": "Tabby" }, { "command": "tabby.chat.fixCodeBlock", - "title": "Tabby: Fix This" + "title": "Fix This", + "category": "Tabby" }, { "command": "tabby.chat.generateCodeBlockDoc", - "title": "Tabby: Generate Docs" + "title": "Generate Docs", + "category": "Tabby" }, { "command": "tabby.chat.generateCodeBlockTest", - "title": "Tabby: Generate Tests" + "title": "Generate Tests", + "category": "Tabby" }, { - "command": "tabby.experimental.chat.generateCommitMessage", + "command": "tabby.chat.generateCommitMessage", "title": "Generate Commit Message", "category": "Tabby" }, { - "command": "tabby.experimental.chat.edit.start", + "command": "tabby.chat.edit.start", "title": "Edit", "category": "Tabby" }, { - "command": "tabby.experimental.chat.edit.stop", + "command": "tabby.chat.edit.stop", "title": "Stop Editing", "category": "Tabby" }, { - "command": "tabby.experimental.chat.edit.accept", + "command": "tabby.chat.edit.accept", "title": "Accept Changes", "category": "Tabby" }, { - "command": "tabby.experimental.chat.edit.discard", + "command": "tabby.chat.edit.discard", "title": "Discard Changes", "category": "Tabby" } @@ -139,23 +152,23 @@ "when": "editorHasSelection && tabby.chatEnabled" }, { - "command": "tabby.experimental.chat.generateCommitMessage", - "when": "tabby.chatEnabled && tabby.generateCommitMessageEnabled" + "command": "tabby.chat.generateCommitMessage", + "when": "tabby.chatEnabled" }, { - "command": "tabby.experimental.chat.edit.start", + "command": "tabby.chat.edit.start", "when": "tabby.chatEnabled" }, { - "command": "tabby.experimental.chat.edit.stop", + "command": "tabby.chat.edit.stop", "when": "false" }, { - "command": "tabby.experimental.chat.edit.accept", + "command": "tabby.chat.edit.accept", "when": "false" }, { - "command": "tabby.experimental.chat.edit.discard", + "command": "tabby.chat.edit.discard", "when": "false" } ] @@ -241,12 +254,7 @@ }, "tabby.experimental": { "default": {}, - "properties": { - "chat.generateCommitMessage": { - "type": "boolean", - "default": false - } - } + "properties": {} } } } @@ -291,24 +299,24 @@ "when": "inlineSuggestionVisible" }, { - "command": "tabby.experimental.chat.edit.start", + "command": "tabby.chat.edit.start", "key": "ctrl+i", "mac": "cmd+i", "when": "tabby.chatEnabled && editorTextFocus && !editorReadonly" }, { - "command": "tabby.experimental.chat.edit.stop", + "command": "tabby.chat.edit.stop", "key": "escape", "when": "tabby.chatEditInProgress && editorTextFocus && !editorReadonly" }, { - "command": "tabby.experimental.chat.edit.accept", + "command": "tabby.chat.edit.accept", "key": "ctrl+enter", "mac": "cmd+enter", "when": "tabby.chatEditResolving && editorTextFocus && !editorReadonly" }, { - "command": "tabby.experimental.chat.edit.discard", + "command": "tabby.chat.edit.discard", "key": "escape", "mac": "escape", "when": "tabby.chatEditResolving && editorTextFocus && !editorReadonly" diff --git a/clients/vscode/src/Commands.ts b/clients/vscode/src/Commands.ts index 92daec0f84a5..97d13d33d7d2 100644 --- a/clients/vscode/src/Commands.ts +++ b/clients/vscode/src/Commands.ts @@ -263,7 +263,7 @@ export class Commands { window.showInformationMessage("No active editor"); } }, - "experimental.chat.edit.start": async () => { + "chat.edit.start": async () => { const editor = window.activeTextEditor; if (!editor) { return; @@ -387,10 +387,10 @@ export class Commands { }); quickPick.show(); }, - "experimental.chat.edit.stop": async () => { + "chat.edit.stop": async () => { this.chatEditCancellationTokenSource?.cancel(); }, - "experimental.chat.edit.accept": async () => { + "chat.edit.accept": async () => { const editor = window.activeTextEditor; if (!editor) { return; @@ -404,7 +404,7 @@ export class Commands { }; await this.client.chat.resolveEdit({ location, action: "accept" }); }, - "experimental.chat.edit.discard": async () => { + "chat.edit.discard": async () => { const editor = window.activeTextEditor; if (!editor) { return; @@ -418,7 +418,7 @@ export class Commands { }; await this.client.chat.resolveEdit({ location, action: "discard" }); }, - "experimental.chat.generateCommitMessage": async () => { + "chat.generateCommitMessage": async () => { const repos = this.gitProvider.getRepositories() ?? []; if (repos.length < 1) { window.showInformationMessage("No Git repositories found."); diff --git a/clients/vscode/src/ContextVariables.ts b/clients/vscode/src/ContextVariables.ts index f5113b40e22b..60fc82d597df 100644 --- a/clients/vscode/src/ContextVariables.ts +++ b/clients/vscode/src/ContextVariables.ts @@ -1,25 +1,16 @@ import { commands, window, workspace, Range } from "vscode"; import { Client } from "./lsp/Client"; -import { Config } from "./Config"; export class ContextVariables { private chatEnabledValue = false; - private generateCommitMessageEnabledValue = false; private chatEditInProgressValue = false; private chatEditResolvingValue = false; - constructor( - private readonly client: Client, - private readonly config: Config, - ) { + constructor(private readonly client: Client) { this.chatEnabled = this.client.chat.isAvailable; this.client.chat.on("didChangeAvailability", (params: boolean) => { this.chatEnabled = params; }); - this.updateExperimentalFlags(); - this.config.on("updated", () => { - this.updateExperimentalFlags(); - }); this.updateChatEditResolving(); window.onDidChangeTextEditorSelection((params) => { if (params.textEditor === window.activeTextEditor) { @@ -33,11 +24,6 @@ export class ContextVariables { }); } - private updateExperimentalFlags() { - const experimental = this.config.workspace.get>("experimental", {}); - this.generateCommitMessageEnabled = !!experimental["chat.generateCommitMessage"]; - } - updateChatEditResolving() { const editor = window.activeTextEditor; if (!editor) { @@ -63,15 +49,6 @@ export class ContextVariables { this.chatEnabledValue = value; } - get generateCommitMessageEnabled(): boolean { - return this.generateCommitMessageEnabledValue; - } - - private set generateCommitMessageEnabled(value: boolean) { - commands.executeCommand("setContext", "tabby.generateCommitMessageEnabled", value); - this.generateCommitMessageEnabledValue = value; - } - get chatEditInProgress(): boolean { return this.chatEditInProgressValue; } diff --git a/clients/vscode/src/extension.ts b/clients/vscode/src/extension.ts index 948915a296d6..dc35fb5a4672 100644 --- a/clients/vscode/src/extension.ts +++ b/clients/vscode/src/extension.ts @@ -67,7 +67,7 @@ export async function activate(context: ExtensionContext) { ); const issues = new Issues(client, config); - const contextVariables = new ContextVariables(client, config); + const contextVariables = new ContextVariables(client); /* eslint-disable-next-line @typescript-eslint/no-unused-vars */ /* @ts-expect-error noUnusedLocals */ const statusBarItem = new StatusBarItem(context, client, config, issues, inlineCompletionProvider); /* eslint-disable-next-line @typescript-eslint/no-unused-vars */ /* @ts-expect-error noUnusedLocals */