Core Utilities (utils.py)
Relevant source files
The following files were used as context for generating this wiki page:
The cursor-free-vip project relies on a set of core utility functions distributed across several key Python scripts, primarily totally_reset_cursor.py, reset_machine_manual.py, and config.py. These utilities form the backbone of the application, providing essential services for interacting with the local system and the Cursor application's files. Their primary responsibilities include dynamic path resolution for different operating systems, management of the config.ini file, version checking of the Cursor application, and the modification of core JavaScript files to alter application behavior.
These utilities are designed to be cross-platform, with specific logic for Windows, macOS, and Linux to locate necessary application files and directories. They are crucial for the main features of the tool, such as resetting machine identifiers to bypass trial limitations and patching the application to enable extended functionality.
Path and Configuration Management
The tool's ability to function across different operating systems and user environments depends on robust path resolution and configuration management. These functions locate Cursor application files and manage a central config.ini file for storing paths and settings.
Path Resolution
The scripts use several functions to dynamically find essential Cursor files and directories. The logic is platform-dependent and often involves checking a list of default locations and falling back to a user-configurable path stored in config.ini.
The following diagram illustrates the general flow for resolving Cursor application paths.
The key path resolution functions are summarized in the table below.
| Function | Description | Source File |
|---|---|---|
get_user_documents_path() | Retrieves the path to the user's "Documents" folder, which is used as the base for the .cursor-free-vip configuration directory. | totally_reset_cursor.py:33-53 |
get_cursor_paths() | Locates the core Cursor application directory containing package.json and out/main.js. It checks config.ini first and then falls back to OS-specific default locations. | totally_reset_cursor.py:56-187 |
get_cursor_machine_id_path() | Returns the path to the machineId file, which varies by OS (%APPDATA% on Windows, ~/.config/cursor on Linux, ~/Library/Application Support on macOS). | totally_reset_cursor.py:189-231 |
get_workbench_cursor_path() | Finds the path to workbench.desktop.main.js, a key file for patching UI elements and application behavior. | totally_reset_cursor.py:233-294 |
Sources: totally_reset_cursor.py, reset_machine_manual.py
Configuration Setup (config.py)
The setup_config function in config.py is responsible for creating and managing the config.ini file located in Documents/.cursor-free-vip.
The process is as follows:
- Determine the path for the
.cursor-free-vipdirectory. - If the directory or
config.inifile does not exist, it creates them. - It populates the
config.iniwith default sections and values, including browser paths, timing settings, and OS-specific paths for Cursor files. - If the file already exists, it reads the existing configuration and adds any missing default options, ensuring backward compatibility.
This ensures that all scripts have a centralized and persistent source for configuration values.
Sources: config.py:20-226
File Patching and Modification
A core feature of the tool is its ability to modify Cursor's internal JavaScript files to change its behavior. This is primarily handled by modify_workbench_js and modify_main_js.
UI and Behavior Modification (modify_workbench_js)
This function targets workbench.desktop.main.js to alter the user interface and bypass certain limitations. It performs string replacements on the file's content.
Key Modifications:
- "Upgrade to Pro" Button: Replaces the "Upgrade to Pro" button with a link to the
cursor-free-vipGitHub repository. - "Pro Trial" Badge: Changes the "Pro Trial" badge to simply "Pro".
- Toast Notifications: Hides toast notifications by adding a
hiddenclass. - Token Limit: Modifies the
getEffectiveTokenLimitfunction to return a very large number (e.g., 9,000,000), effectively bypassing the token limit for AI interactions.
The function uses platform-specific patterns to identify the code to be replaced, as the minified JavaScript differs slightly between Windows, macOS, and Linux.
Sources: totally_reset_cursor.py:441-520, reset_machine_manual.py:443-522, bypass_token_limit.py:116-194
Machine ID Logic Patching (modify_main_js)
This function patches out/main.js to alter how the application retrieves the machine ID. It uses regular expressions to modify the getMachineId and getMacMachineId asynchronous functions. The goal is to remove the logic that generates a new ID if one doesn't exist, forcing the application to rely on the ID provided by the tool.
The following diagram shows the file patching sequence.
The regex patterns used are:
patterns = {
r"async getMachineId\(\)\{return [^??]+\?\?([^}]+)\}": r"async getMachineId(){return \1}",
r"async getMacMachineId\(\)\{return [^??]+\?\?([^}]+)\}": r"async getMacMachineId(){return \1}",
}
Sources: totally_reset_cursor.py:531-534
Machine ID Reset (MachineIDResetter)
The MachineIDResetter class in totally_reset_cursor.py and reset_machine_manual.py orchestrates the process of resetting all identifiers used by Cursor to track trial status.
ID Generation and Storage
The reset_machine_ids method is the main entry point. It performs the following steps:
- Backup: Creates a backup of
storage.json. - Generate New IDs: Calls
generate_new_idsto create new random identifiers. - Update
storage.json: Injects the new IDs into the JSON configuration file. - Update
state.vscdb: Callsupdate_sqlite_dbto insert or replace the new IDs in the SQLite database. - Update System IDs: Calls
update_system_idsto modify system-level identifiers (e.g., Windows Registry). - Patch Files: Calls
modify_workbench_jsandpatch_cursor_get_machine_idto apply necessary code modifications.
The following diagram illustrates the flow of the machine ID reset process.
Sources: totally_reset_cursor.py:840-901
The generate_new_ids function creates several new identifiers to replace the old ones.
| ID Key | Description | Generation Method |
|---|---|---|
telemetry.devDeviceId | A new device identifier. | str(uuid.uuid4()) |
telemetry.machineId | A 64-character hexadecimal ID. | hashlib.sha256(os.urandom(32)) |
telemetry.macMachineId | A 128-character hexadecimal ID. | hashlib.sha512(os.urandom(64)) |
telemetry.sqmId | A new GUID for the SQM client. | "{"+str(uuid.uuid4()).upper()+"}" |
storage.serviceMachineId | A service-level machine ID, same as devDeviceId. | str(uuid.uuid4()) |
Sources: totally_reset_cursor.py:737-756
System-Level ID Modification
The update_system_ids function attempts to modify identifiers stored at the operating system level, which requires elevated privileges.
- Windows: It updates
MachineGuidinHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\CryptographyandMachineIdinHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SQMClient. - macOS: It uses the
plutilcommand withsudoto replace theUUIDin/var/root/Library/Preferences/SystemConfiguration/com.apple.platform.uuid.plist.
These modifications make the reset more robust by changing identifiers outside of Cursor's own configuration files.
Sources: totally_reset_cursor.py:793-839
Version Checking
The check_cursor_version utility function is used to determine if the installed Cursor version is compatible with the patching logic.
- It calls
get_cursor_pathsto findpackage.json. - It reads and parses the
versionfield from the JSON file. - It compares the current version against a minimum required version (e.g.,
0.45.0). - It returns
Trueif the version is sufficient for patching andFalseotherwise.
This check ensures that the script does not attempt to patch an incompatible or unsupported version of Cursor, preventing potential errors.
Sources: totally_reset_cursor.py:355-416
Internationalization (i18n)
The Translator class in main.py provides multi-language support for the tool's command-line interface.
- Language Detection: It attempts to detect the system's language using
localeon Unix-like systems andctypeson Windows. - Translation Loading: It loads all
.jsonfiles from thelocales/directory into a dictionary. - Text Retrieval: The
get(key, **kwargs)method retrieves a translated string from the loaded dictionary based on the current language setting. It supports fallback to English if a translation is missing. - Language Switching: The
set_language(lang_code)method allows the user to change the active language, which is then saved toconfig.ini.
This utility makes the tool accessible to a wider audience by providing a localized user experience.
Sources: main.py:64-245, locales/en.json