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

fix(agent&vscode): remove experimental flag for generating commit massage. #2341

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
9 changes: 5 additions & 4 deletions clients/tabby-agent/src/AgentConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export type AgentConfig = {
limitScope: any;
calculateReplaceRange: any;
};
experimentalChat: {
chat: {
edit: {
documentMaxChars: number;
commandMaxChars: number;
Expand Down Expand Up @@ -159,7 +159,7 @@ export const defaultAgentConfig: AgentConfig = {
limitScope: {},
calculateReplaceRange: {},
},
experimentalChat: {
chat: {
edit: {
documentMaxChars: 3000,
commandMaxChars: 200,
Expand Down Expand Up @@ -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: <type>(<scope>): <description> \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<type>(<scope>): <description>.\n\n\nThe <type> 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: {
Expand Down
12 changes: 6 additions & 6 deletions clients/tabby-agent/src/TabbyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)/);
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions clients/tabby-agent/src/configFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ const typeCheckSchema: Record<string, string> = {
"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",
Expand Down
4 changes: 2 additions & 2 deletions clients/tabby-agent/src/lsp/ChatEditProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class ChatEditProvider {
}

async provideEditCommands(params: ChatEditCommandParams): Promise<ChatEditCommand[]> {
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);

Expand Down Expand Up @@ -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;
}
Expand Down
76 changes: 42 additions & 34 deletions clients/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -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"
}
]
Expand Down Expand Up @@ -241,12 +254,7 @@
},
"tabby.experimental": {
"default": {},
"properties": {
"chat.generateCommitMessage": {
"type": "boolean",
"default": false
}
}
"properties": {}
}
}
}
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions clients/vscode/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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.");
Expand Down
25 changes: 1 addition & 24 deletions clients/vscode/src/ContextVariables.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -33,11 +24,6 @@ export class ContextVariables {
});
}

private updateExperimentalFlags() {
const experimental = this.config.workspace.get<Record<string, unknown>>("experimental", {});
this.generateCommitMessageEnabled = !!experimental["chat.generateCommitMessage"];
}

updateChatEditResolving() {
const editor = window.activeTextEditor;
if (!editor) {
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion clients/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down