Repository: TabbyML/tabby
File: clients/vscode/src/extension.ts (TypeScript)

Code before:

  // Register code actions
  /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */ /* eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error */
  /* eslint-disable-next-line @typescript-eslint/no-unused-vars */ // @ts-ignore noUnusedLocals
  const codeActions = new CodeActions(client, contextVariables);

  logger.info("Tabby extension activated.");

  // Start async initialization
  const startClient = async () => {
    await gitProvider.init();

    logger.info("Launching language server tabby-agent...");
    await client.start();
    logger.info("Language server tabby-agent launched.");
  };

  await Promise.all([
    // start LSP client
    startClient(),

    // findFiles preheat
    initFindFiles(context),
  ]);

  const canGetToken = async (requestId?: string): Promise<{ token: string | undefined }> => {
    if (requestId && config.isTokenRequestApproved(requestId)) {
      return { token: config.serverRecords.get(config.serverEndpoint)?.token };
    }

    const response = await window.showInformationMessage(
      `Would you like to share your Tabby's token with endpoint ${config.serverEndpoint}?`,
      { modal: true, detail: "This will share your token to third parties VSCode extention" },
      "Yes",
      "No",
    );

    if (response === "Yes") {
      if (requestId) {
        await config.addApprovedTokenRequestId(requestId);
      }
      return { token: config.serverRecords.get(config.serverEndpoint)?.token };
    }
    return { token: undefined };
  };
  return {
    canGetToken,
  };
}

export async function deactivate() {

Review comment (security):
```suggestion
  const tryReadAuthenticationToken = async (requestId?: string): Promise<{ token: string | undefined }> => {
```

Code after:

  // Register code actions
  /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */ /* eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error */
  /* eslint-disable-next-line @typescript-eslint/no-unused-vars */ // @ts-ignore noUnusedLocals
  const codeActions = new CodeActions(client, contextVariables);

  logger.info("Tabby extension activated.");

  // Start async initialization
  const startClient = async () => {
    await gitProvider.init();

    logger.info("Launching language server tabby-agent...");
    await client.start();
    logger.info("Language server tabby-agent launched.");
  };

  await Promise.all([
    // start LSP client
    startClient(),

    // findFiles preheat
    initFindFiles(context),
  ]);

  const tryReadAuthenticationToken = async (): Promise<{ token: string | undefined }> => {
    const response = await window.showInformationMessage(
      "Do you consent to sharing your Tabby token with another VSCode extension?",
      {
        modal: true,
        detail: `The extension requests your token to access the Tabby server at ${config.serverEndpoint}. Sharing your token allows the extension to perform actions as if it were you. Only proceed if you trust the extension.`,
      },
      "Yes",
      "No",
    );

    if (response === "Yes") {
      return { token: config.serverRecords.get(config.serverEndpoint)?.token };
    }
    return { token: undefined };
  };
  return {
    tryReadAuthenticationToken,
  };
}

export async function deactivate() {
  logger.info("Deactivating Tabby extension...");
  await clientRef?.stop();
  logger.info("Tabby extension deactivated.");
}