ronantakizawa/codereview-bench huggingface dataset:
Repository: TabbyML/tabby
File: ee/tabby-ui/lib/tabby/token-management.ts (TypeScript)

Code before:
import { jwtDecode } from 'jwt-decode'
import { isNil } from 'lodash-es'
import { FetcherOptions } from 'tabby-chat-panel/index'

import { isClientSide } from '../utils'
import { AuthData } from './auth'

export const AUTH_TOKEN_KEY = '_tabby_auth'
export const AUTH_LOCK_KEY = '_tabby_auth_lock'
export const FETCHER_OPTIONS_KEY = '_tabby_fetcher_options'

const getAuthToken = (): AuthData | undefined => {
  if (isClientSide()) {
    let tokenData = localStorage.getItem(AUTH_TOKEN_KEY)
    if (!tokenData) return undefined
    try {
      return JSON.parse(tokenData)
    } catch (e) {
      return undefined
    }
  }
  return undefined
}

const saveAuthToken = (authData: AuthData) => {
  localStorage.setItem(AUTH_TOKEN_KEY, JSON.stringify(authData))
}

const clearAuthToken = () => {
  localStorage.removeItem(AUTH_TOKEN_KEY)
  // FIXME(liangfung)
  // dispatching storageEvent to notify updating `authToken` in `AuthProvider`,
  // the `useEffect` hook depending on `authToken` in `AuthProvider` will be fired and updating the authState
  window.dispatchEvent(
    new StorageEvent('storage', {

Review comment (suggestion):
```suggestion
export const FETCHER_OPTIONS_KEY = '_tabby_chat_sdk_fetcher_options'
```

Code after:
import { jwtDecode } from 'jwt-decode'
import { isNil } from 'lodash-es'
import { FetcherOptions } from 'tabby-chat-panel/index'

import { isClientSide } from '../utils'
import { AuthData } from './auth'

export const AUTH_TOKEN_KEY = '_tabby_auth'
export const AUTH_LOCK_KEY = '_tabby_auth_lock'
const FETCHER_OPTIONS_KEY = '_tabby_chat_sdk_fetcher_options'

const getAuthToken = (): AuthData | undefined => {
  if (isClientSide()) {
    let tokenData = localStorage.getItem(AUTH_TOKEN_KEY)
    if (!tokenData) return undefined
    try {
      return JSON.parse(tokenData)
    } catch (e) {
      return undefined
    }
  }
  return undefined
}

const saveAuthToken = (authData: AuthData) => {
  localStorage.setItem(AUTH_TOKEN_KEY, JSON.stringify(authData))
}

const clearAuthToken = () => {
  localStorage.removeItem(AUTH_TOKEN_KEY)
  // FIXME(liangfung)
  // dispatching storageEvent to notify updating `authToken` in `AuthProvider`,
  // the `useEffect` hook depending on `authToken` in `AuthProvider` will be fired and updating the authState
  window.dispatchEvent(
    new StorageEvent('storage', {
Repository: TabbyML/tabby
File: ee/tabby-ui/lib/tabby/token-management.ts (TypeScript)

Code before:
import { jwtDecode } from 'jwt-decode'
import { isNil } from 'lodash-es'
import { FetcherOptions } from 'tabby-chat-panel/index'

import { isClientSide } from '../utils'
import { AuthData } from './auth'

export const AUTH_TOKEN_KEY = '_tabby_auth'
export const AUTH_LOCK_KEY = '_tabby_auth_lock'
export const FETCHER_OPTIONS_KEY = '_tabby_chat_sdk_fetcher_options'

const getAuthToken = (): AuthData | undefined => {
  if (isClientSide()) {
    let tokenData = localStorage.getItem(AUTH_TOKEN_KEY)
    if (!tokenData) return undefined
    try {
      return JSON.parse(tokenData)
    } catch (e) {
      return undefined
    }
  }
  return undefined
}

const saveAuthToken = (authData: AuthData) => {
  localStorage.setItem(AUTH_TOKEN_KEY, JSON.stringify(authData))
}

const clearAuthToken = () => {
  localStorage.removeItem(AUTH_TOKEN_KEY)
  // FIXME(liangfung)
  // dispatching storageEvent to notify updating `authToken` in `AuthProvider`,
  // the `useEffect` hook depending on `authToken` in `AuthProvider` will be fired and updating the authState
  window.dispatchEvent(
    new StorageEvent('storage', {

Review comment (suggestion):
```suggestion
const FETCHER_OPTIONS_KEY = '_tabby_chat_sdk_fetcher_options'
```

Code after:
import { jwtDecode } from 'jwt-decode'
import { isNil } from 'lodash-es'
import { FetcherOptions } from 'tabby-chat-panel/index'

import { isClientSide } from '../utils'
import { AuthData } from './auth'

export const AUTH_TOKEN_KEY = '_tabby_auth'
export const AUTH_LOCK_KEY = '_tabby_auth_lock'
const FETCHER_OPTIONS_KEY = '_tabby_chat_sdk_fetcher_options'

const getAuthToken = (): AuthData | undefined => {
  if (isClientSide()) {
    let tokenData = localStorage.getItem(AUTH_TOKEN_KEY)
    if (!tokenData) return undefined
    try {
      return JSON.parse(tokenData)
    } catch (e) {
      return undefined
    }
  }
  return undefined
}

const saveAuthToken = (authData: AuthData) => {
  localStorage.setItem(AUTH_TOKEN_KEY, JSON.stringify(authData))
}

const clearAuthToken = () => {
  localStorage.removeItem(AUTH_TOKEN_KEY)
  // FIXME(liangfung)
  // dispatching storageEvent to notify updating `authToken` in `AuthProvider`,
  // the `useEffect` hook depending on `authToken` in `AuthProvider` will be fired and updating the authState
  window.dispatchEvent(
    new StorageEvent('storage', {
Repository: TabbyML/tabby
File: clients/tabby-agent/src/AgentConfig.ts (TypeScript)

Code before:
          // overlap lines between neighbor chunks
          overlapLines: number;
        };
      };
      clipboard: {
        minChars: number;
        maxChars: number;
      };
    };
    debounce: {
      mode: "adaptive" | "fixed";
      interval: number;
    };
    solution: {
      // The max number of unique choices to be fetched before stopping
      maxItems: number;
      // The max number of attempts to fetch choices before stopping
      maxTries: number;
      // The temperature for fetching the second and subsequent choices
      temperature: number;
    };
  };
  postprocess: {
    limitScope: any;
    calculateReplaceRange: any;
    minChars: number;
  };
  chat: {
    edit: {
      documentMaxChars: number;
      commandMaxChars: number;
      responseDocumentTag: string[];
      responseCommentTag: string[] | undefined;
      promptTemplate: {
        replace: string;
        insert: string;
      };
      presetCommands: Record<
        string,
        {
          label: string;
          filters: Record<string, string>;
          kind: "replace" | "insert";
          promptTemplate: string;
        }
      >;
    };
    generateCommitMessage: {
      maxDiffLength: number;
      promptTemplate: string;
      responseMatcher: string;

Review comment (suggestion):
```suggestion
    minCompletionChars: number;
```

Code after:
          // overlap lines between neighbor chunks
          overlapLines: number;
        };
      };
      clipboard: {
        minChars: number;
        maxChars: number;
      };
    };
    debounce: {
      mode: "adaptive" | "fixed";
      interval: number;
    };
    solution: {
      // The max number of unique choices to be fetched before stopping
      maxItems: number;
      // The max number of attempts to fetch choices before stopping
      maxTries: number;
      // The temperature for fetching the second and subsequent choices
      temperature: number;
    };
  };
  postprocess: {
    limitScope: any;
    calculateReplaceRange: any;
    minCompletionChars: number;
  };
  chat: {
    edit: {
      documentMaxChars: number;
      commandMaxChars: number;
      responseDocumentTag: string[];
      responseCommentTag: string[] | undefined;
      promptTemplate: {
        replace: string;
        insert: string;
      };
      presetCommands: Record<
        string,
        {
          label: string;
          filters: Record<string, string>;
          kind: "replace" | "insert";
          promptTemplate: string;
        }
      >;
    };
    generateCommitMessage: {
      maxDiffLength: number;
      promptTemplate: string;
      responseMatcher: string;
Repository: TabbyML/tabby
File: clients/vscode/src/code-action/QuickFix.ts (TypeScript)

Code before:

  provideCodeActions(
    _document: TextDocument,
    _range: Range | Selection,
    context: CodeActionContext,
    token: CancellationToken,
  ): CodeAction[] | undefined {
    if (token.isCancellationRequested) {
      return;
    }

    if (!this.contextVariables.chatEnabled) {
      return;
    }
    if (context.diagnostics.length === 0) {
      return [];
    }

    //TODO: Get all diagnostics from the context and substring with max command chars
    const lspErrors = context.diagnostics[0];
    getLogger("QuickFixCodeActionProvider").info("lspErrors", lspErrors);

    const quickFixEditing = new CodeAction("Fixing with Tabby", CodeActionKind.QuickFix);
    quickFixEditing.command = {
      command: "tabby.chat.edit.start",
      title: "Fixing with Tabby",
      arguments: [
        {
          errorContext: lspErrors,
        },
      ],
    };

    return [quickFixEditing];
  }
}


Review comment (suggestion):
```suggestion
      title: "Fix with Tabby",
```

Code after:

  provideCodeActions(
    _document: TextDocument,
    _range: Range | Selection,
    context: CodeActionContext,
    token: CancellationToken,
  ): CodeAction[] | undefined {
    if (token.isCancellationRequested) {
      return;
    }

    if (!this.contextVariables.chatEnabled) {
      return;
    }
    if (context.diagnostics.length === 0) {
      return [];
    }

    const lspErrors = context.diagnostics
      .map((diagnostic, idx) => "Error " + idx + ": " + diagnostic.message)
      .join("\n");
    const userCommand = `Here is some error information that occurred in the selection:
                        ${lspErrors}
                        Please provide the correct command to fix the error.`;
    getLogger("QuickFixCodeActionProvider").info("lspErrors", lspErrors);

    const quickFixEditing = new CodeAction("Fix with Tabby", CodeActionKind.QuickFix);
    quickFixEditing.command = {
      command: "tabby.chat.edit.start",
      title: "Fix with Tabby",
      arguments: [userCommand],
    };

    return [quickFixEditing];
  }
}
Repository: TabbyML/tabby
File: clients/vscode/src/code-action/QuickFix.ts (TypeScript)

Code before:
  Selection,
  TextDocument,
} from "vscode";
import { ContextVariables } from "../ContextVariables";
import { getLogger } from "../logger";
export class QuickFixCodeActionProvider implements CodeActionProviderInterface {
  constructor(private readonly contextVariables: ContextVariables) {}

  provideCodeActions(
    _document: TextDocument,
    _range: Range | Selection,
    context: CodeActionContext,
    token: CancellationToken,
  ): CodeAction[] | undefined {
    if (token.isCancellationRequested) {
      return;
    }

    if (!this.contextVariables.chatEnabled) {
      return;
    }
    if (context.diagnostics.length === 0) {
      return [];
    }

    //TODO: Get all diagnostics from the context and substring with max command chars
    const lspErrors = context.diagnostics[0];
    getLogger("QuickFixCodeActionProvider").info("lspErrors", lspErrors);

    const quickFixEditing = new CodeAction("Fixing with Tabby", CodeActionKind.QuickFix);
    quickFixEditing.command = {
      command: "tabby.chat.edit.start",
      title: "Fix with Tabby",
      arguments: [
        {
          errorContext: lspErrors,
        },
      ],
    };

    return [quickFixEditing];
  }
}


Review comment (suggestion):
```suggestion
```

This is handled in backend automatically

Code after:
  Selection,
  TextDocument,
} from "vscode";
import { ContextVariables } from "../ContextVariables";
import { getLogger } from "../logger";
export class QuickFixCodeActionProvider implements CodeActionProviderInterface {
  constructor(private readonly contextVariables: ContextVariables) {}

  provideCodeActions(
    _document: TextDocument,
    _range: Range | Selection,
    context: CodeActionContext,
    token: CancellationToken,
  ): CodeAction[] | undefined {
    if (token.isCancellationRequested) {
      return;
    }

    if (!this.contextVariables.chatEnabled) {
      return;
    }
    if (context.diagnostics.length === 0) {
      return [];
    }

    const lspErrors = context.diagnostics
      .map((diagnostic, idx) => "Error " + idx + ": " + diagnostic.message)
      .join("\n");
    const userCommand = `Here is some error information that occurred in the selection:
                        ${lspErrors}
                        Please provide the correct command to fix the error.`;
    getLogger("QuickFixCodeActionProvider").info("lspErrors", lspErrors);

    const quickFixEditing = new CodeAction("Fix with Tabby", CodeActionKind.QuickFix);
    quickFixEditing.command = {
      command: "tabby.chat.edit.start",
      title: "Fix with Tabby",
      arguments: [userCommand],
    };

    return [quickFixEditing];
  }
}
Repository: TabbyML/tabby
File: clients/vscode/src/code-action/QuickFix.ts (TypeScript)

Code before:
import { getLogger } from "../logger";
export class QuickFixCodeActionProvider implements CodeActionProviderInterface {
  constructor(private readonly contextVariables: ContextVariables) {}

  provideCodeActions(
    _document: TextDocument,
    _range: Range | Selection,
    context: CodeActionContext,
    token: CancellationToken,
  ): CodeAction[] | undefined {
    if (token.isCancellationRequested) {
      return;
    }

    if (!this.contextVariables.chatEnabled) {
      return;
    }
    if (context.diagnostics.length === 0) {
      return [];
    }

    //TODO: Get all diagnostics from the context and substring with max command chars
    const lspErrors = context.diagnostics[0];
    getLogger("QuickFixCodeActionProvider").info("lspErrors", lspErrors);

    const quickFixEditing = new CodeAction("Fixing with Tabby", CodeActionKind.QuickFix);
    quickFixEditing.command = {
      command: "tabby.chat.edit.start",
      title: "Fix with Tabby",
      arguments: [
        {
          errorContext: lspErrors,
        },
      ],
    };

    return [quickFixEditing];
  }
}


Review comment (suggestion):
```suggestion
    const quickFixEditing = new CodeAction("Fix with Tabby", CodeActionKind.QuickFix);
```

Code after:
import { getLogger } from "../logger";
export class QuickFixCodeActionProvider implements CodeActionProviderInterface {
  constructor(private readonly contextVariables: ContextVariables) {}

  provideCodeActions(
    _document: TextDocument,
    _range: Range | Selection,
    context: CodeActionContext,
    token: CancellationToken,
  ): CodeAction[] | undefined {
    if (token.isCancellationRequested) {
      return;
    }

    if (!this.contextVariables.chatEnabled) {
      return;
    }
    if (context.diagnostics.length === 0) {
      return [];
    }

    const lspErrors = context.diagnostics
      .map((diagnostic, idx) => "Error " + idx + ": " + diagnostic.message)
      .join("\n");
    const userCommand = `Here is some error information that occurred in the selection:
                        ${lspErrors}
                        Please provide the correct command to fix the error.`;
    getLogger("QuickFixCodeActionProvider").info("lspErrors", lspErrors);

    const quickFixEditing = new CodeAction("Fix with Tabby", CodeActionKind.QuickFix);
    quickFixEditing.command = {
      command: "tabby.chat.edit.start",
      title: "Fix with Tabby",
      arguments: [userCommand],
    };

    return [quickFixEditing];
  }
}
Repository: TabbyML/tabby
File: clients/vscode/src/code-action/QuickFix.ts (TypeScript)

Code before:
  TextDocument,
} from "vscode";
import { ContextVariables } from "../ContextVariables";
import { getLogger } from "../logger";
export class QuickFixCodeActionProvider implements CodeActionProviderInterface {
  constructor(private readonly contextVariables: ContextVariables) {}

  provideCodeActions(
    _document: TextDocument,
    _range: Range | Selection,
    context: CodeActionContext,
    token: CancellationToken,
  ): CodeAction[] | undefined {
    if (token.isCancellationRequested) {
      return;
    }

    if (!this.contextVariables.chatEnabled) {
      return;
    }
    if (context.diagnostics.length === 0) {
      return [];
    }

    //TODO: Get all diagnostics from the context and substring with max command chars
    const lspErrors = context.diagnostics[0];
    getLogger("QuickFixCodeActionProvider").info("lspErrors", lspErrors);

    const quickFixEditing = new CodeAction("Fixing with Tabby", CodeActionKind.QuickFix);
    quickFixEditing.command = {
      command: "tabby.chat.edit.start",
      title: "Fix with Tabby",
      arguments: [
        {
          errorContext: lspErrors,
        },
      ],
    };

    return [quickFixEditing];
  }
}


Review comment (suggestion):
```suggestion
    const lspErrors = context.diagnostics;
```

Code after:
  TextDocument,
} from "vscode";
import { ContextVariables } from "../ContextVariables";
import { getLogger } from "../logger";
export class QuickFixCodeActionProvider implements CodeActionProviderInterface {
  constructor(private readonly contextVariables: ContextVariables) {}

  provideCodeActions(
    _document: TextDocument,
    _range: Range | Selection,
    context: CodeActionContext,
    token: CancellationToken,
  ): CodeAction[] | undefined {
    if (token.isCancellationRequested) {
      return;
    }

    if (!this.contextVariables.chatEnabled) {
      return;
    }
    if (context.diagnostics.length === 0) {
      return [];
    }

    const lspErrors = context.diagnostics
      .map((diagnostic, idx) => "Error " + idx + ": " + diagnostic.message)
      .join("\n");
    const userCommand = `Here is some error information that occurred in the selection:
                        ${lspErrors}
                        Please provide the correct command to fix the error.`;
    getLogger("QuickFixCodeActionProvider").info("lspErrors", lspErrors);

    const quickFixEditing = new CodeAction("Fix with Tabby", CodeActionKind.QuickFix);
    quickFixEditing.command = {
      command: "tabby.chat.edit.start",
      title: "Fix with Tabby",
      arguments: [userCommand],
    };

    return [quickFixEditing];
  }
}
Repository: TabbyML/tabby
File: clients/vscode/src/code-action/QuickFix.ts (TypeScript)

Code before:
    context: CodeActionContext,
    token: CancellationToken,
  ): CodeAction[] | undefined {
    if (token.isCancellationRequested) {
      return;
    }

    if (!this.contextVariables.chatEnabled) {
      return;
    }
    if (context.diagnostics.length === 0) {
      return [];
    }

    //TODO: Get all diagnostics from the context and substring with max command chars
    const lspErrors = context.diagnostics[0];
    getLogger("QuickFixCodeActionProvider").info("lspErrors", lspErrors);

    const quickFixEditing = new CodeAction("Fixing with Tabby", CodeActionKind.QuickFix);
    quickFixEditing.command = {
      command: "tabby.chat.edit.start",
      title: "Fix with Tabby",
      arguments: [
        {
          errorContext: lspErrors,
        },
      ],
    };

    return [quickFixEditing];
  }
}


Review comment (suggestion):
```suggestion
    userCommand
```

Construct userCommand here directly using lspErrors.

Code after:
    context: CodeActionContext,
    token: CancellationToken,
  ): CodeAction[] | undefined {
    if (token.isCancellationRequested) {
      return;
    }

    if (!this.contextVariables.chatEnabled) {
      return;
    }
    if (context.diagnostics.length === 0) {
      return [];
    }

    const lspErrors = context.diagnostics
      .map((diagnostic, idx) => "Error " + idx + ": " + diagnostic.message)
      .join("\n");
    const userCommand = `Here is some error information that occurred in the selection:
                        ${lspErrors}
                        Please provide the correct command to fix the error.`;
    getLogger("QuickFixCodeActionProvider").info("lspErrors", lspErrors);

    const quickFixEditing = new CodeAction("Fix with Tabby", CodeActionKind.QuickFix);
    quickFixEditing.command = {
      command: "tabby.chat.edit.start",
      title: "Fix with Tabby",
      arguments: [userCommand],
    };

    return [quickFixEditing];
  }
}
Repository: TabbyML/tabby
File: clients/tabby-agent/src/AgentConfig.ts (TypeScript)

Code before:
        },
      },
      clipboard: {
        minChars: 3,
        maxChars: 2000,
      },
    },
    debounce: {
      mode: "adaptive",
      interval: 250, // ms
    },
    solution: {
      maxItems: 3,
      maxTries: 6,
      temperature: 0.8,
    },
  },
  postprocess: {
    limitScope: {},
    calculateReplaceRange: {},
    minCompletionChars: 4,
  },
  chat: {
    edit: {
      documentMaxChars: 3000,
      commandMaxChars: 600,
      responseDocumentTag: ["<GENERATEDCODE>", "</GENERATEDCODE>"],
      responseCommentTag: undefined,
      promptTemplate: {
        replace: editCommandReplacePrompt,
        insert: editCommandInsertPrompt,
      },
      presetCommands: {
        "/doc": {
          label: "Generate Docs",
          filters: { languageIdNotIn: "plaintext,markdown" },
          kind: "replace",
          promptTemplate: generateDocsPrompt,
        },
        "/fix": {
          label: "Fix spelling and grammar errors",
          filters: { languageIdIn: "plaintext,markdown" },
          kind: "replace",
          promptTemplate: fixSpellingAndGrammarPrompt,
        },
      },
    },
    generateCommitMessage: {
      maxDiffLength: 3600,
      promptTemplate: generateCommitMessagePrompt,
      responseMatcher:

Review comment (suggestion):
@icycodes i think it's safe to remove the command max chars check in agent, but leave the char clipping in individual command (e.g command trigger by user shall apply max chars clipping, but command triggered by features like "fix this" shall not having such clipping.

Code after:
      },
      clipboard: {
        minChars: 3,
        maxChars: 2000,
      },
    },
    debounce: {
      mode: "adaptive",
      interval: 250, // ms
    },
    solution: {
      maxItems: 3,
      maxTries: 6,
      temperature: 0.8,
    },
  },
  postprocess: {
    limitScope: {},
    calculateReplaceRange: {},
    minCompletionChars: 4,
  },
  chat: {
    edit: {
      documentMaxChars: 3000,
      responseDocumentTag: ["<GENERATEDCODE>", "</GENERATEDCODE>"],
      responseCommentTag: undefined,
      promptTemplate: {
        replace: editCommandReplacePrompt,
        insert: editCommandInsertPrompt,
      },
      presetCommands: {
        "/doc": {
          label: "Generate Docs",
          filters: { languageIdNotIn: "plaintext,markdown" },
          kind: "replace",
          promptTemplate: generateDocsPrompt,
        },
        "/fix": {
          label: "Fix spelling and grammar errors",
          filters: { languageIdIn: "plaintext,markdown" },
          kind: "replace",
          promptTemplate: fixSpellingAndGrammarPrompt,
        },
      },
    },
    generateCommitMessage: {
      maxDiffLength: 3600,
      promptTemplate: generateCommitMessagePrompt,
      responseMatcher:
        /(?<=(["'`]+)?\s*)(feat|fix|docs|refactor|style|test|build|ci|chore)(\(\S+\))?:.+(?=\s*\1)/gis.toString(),
    },