From af0604e54ab4b686ae40dd3f7d7af52bb545b56f Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Thu, 25 Sep 2025 20:40:31 +0800 Subject: [PATCH] fix: enhance Cursor and Qoder detection in SSH and DevContainer environments This commit improves the detection logic for Cursor and Qoder IDEs by adding pattern matching for environment variables VSCODE_GIT_ASKPASS_MAIN and BROWSER that contain '.cursor-server' or '.qoder-server' substrings. This fixes issues where the IDE detection was not working properly in SSH and DevContainer environments. The changes include: 1. Added new environment variable patterns in envConfigs for Cursor and Qoder detection 2. Enhanced getCoDevelopedBy function to support substring pattern matching 3. Added comprehensive tests to verify the new detection logic This ensures that users working in remote development environments (SSH, DevContainer) will have proper Co-developed-by trailers added to their commits when using Cursor or Qoder. Change-Id: Ieb98755b1c0aa178b49484b2cdc613c11f90df39 Co-developed-by: Qoder --- src/commands/exec.ts | 20 ++++++++++++++++++++ test/commands/exec.test.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/commands/exec.ts b/src/commands/exec.ts index 823fc3a..92bf5ed 100644 --- a/src/commands/exec.ts +++ b/src/commands/exec.ts @@ -19,6 +19,11 @@ const envConfigs: [string, string][] = [ ['__CFBundleIdentifier=dev.kiro.desktop', 'Kiro '], ['VSCODE_BRAND=Qoder', 'Qoder '], ['__CFBundleIdentifier=com.qoder.ide', 'Qoder '], // Use this unstable variable until Qoder has a better one + // Check env variables for IDEs in remove development environments + ['VSCODE_GIT_ASKPASS_MAIN=*.cursor-server*', 'Cursor '], + ['BROWSER=*.cursor-server*', 'Cursor '], + ['VSCODE_GIT_ASKPASS_MAIN=*.qoder-server*', 'Qoder '], + ['BROWSER=*.qoder-server*', 'Qoder '], ]; /** @@ -302,6 +307,21 @@ function getCoDevelopedBy(): string { // Continue to next configuration if value is falsy continue; } + + // For pattern matching cases (starts and ends with *, e.g., "*.cursor-server*") + if ( + expectedValue && + expectedValue.startsWith('*') && + expectedValue.endsWith('*') && + expectedValue.length > 2 + ) { + // Extract the pattern between the asterisks + const pattern = expectedValue.substring(1, expectedValue.length - 1); + if (actualValue.includes(pattern)) { + return coDevelopedBy; + } + continue; + } } // Return empty string if none of the environment configurations match diff --git a/test/commands/exec.test.ts b/test/commands/exec.test.ts index a51071a..f95db78 100644 --- a/test/commands/exec.test.ts +++ b/test/commands/exec.test.ts @@ -737,6 +737,33 @@ describe('exec command utilities', () => { process.env.CLAUDECODE = ''; expect(getCoDevelopedBy()).toBe(''); }); + + // Enhanced tests for Cursor and Qoder detection + it('should return Cursor CoDevelopedBy when VSCODE_GIT_ASKPASS_MAIN contains .cursor-server', () => { + clearCoDevelopedByEnvVars(); + process.env.VSCODE_GIT_ASKPASS_MAIN = + '/home/user/.cursor-server/bin/askpass-main.js'; + expect(getCoDevelopedBy()).toBe('Cursor '); + }); + + it('should return Cursor CoDevelopedBy when BROWSER contains .cursor-server', () => { + clearCoDevelopedByEnvVars(); + process.env.BROWSER = '/home/user/.cursor-server/bin/helpers/browser.sh'; + expect(getCoDevelopedBy()).toBe('Cursor '); + }); + + it('should return Qoder CoDevelopedBy when VSCODE_GIT_ASKPASS_MAIN contains .qoder-server', () => { + clearCoDevelopedByEnvVars(); + process.env.VSCODE_GIT_ASKPASS_MAIN = + '/home/user/.qoder-server/bin/askpass-main.js'; + expect(getCoDevelopedBy()).toBe('Qoder '); + }); + + it('should return Qoder CoDevelopedBy when BROWSER contains .qoder-server', () => { + clearCoDevelopedByEnvVars(); + process.env.BROWSER = '/home/user/.qoder-server/bin/helpers/browser.sh'; + expect(getCoDevelopedBy()).toBe('Qoder '); + }); }); describe('hasCoDevelopedBy', () => {