State Management
Relevant source files
The following files were used as context for generating this wiki page:
State management in the cursor-free-vip project is a decentralized system responsible for handling application configuration, user data, and machine-specific identifiers. Its primary purpose is to manage the necessary settings and data to interact with the Cursor application, with a strong focus on features that reset or modify Cursor's trial status. The state is persisted across multiple files, including a central config.ini file, a storage.json file, and an SQLite database (state.vscdb).
This system is not a monolithic state store but rather a collection of functions and classes that read, write, and manipulate state across these different storage mechanisms. Key functionalities include discovering application paths, managing machine IDs to bypass trial detection, and storing user authentication details. The state management logic is distributed across several scripts, primarily config.py for configuration and totally_reset_cursor.py for machine state manipulation.
Configuration Management (config.ini)
The primary mechanism for user-configurable state is the config.ini file, located in the .cursor-free-vip directory within the user's Documents folder. The config.py script is responsible for the creation, validation, and management of this file.
Sources: config.py, main.py:121-147
Configuration Setup Flow
The setup_config function in config.py orchestrates the initialization of the configuration. It detects the operating system, defines default paths and settings, and ensures the config.ini file exists and is populated with all necessary sections and options.
The following diagram illustrates the configuration setup process.
Sources: config.py:19-247
Configuration Structure
The config.ini file is divided into several sections, each managing a different aspect of the application's behavior.
[Paths] Sections
Platform-specific sections (WindowsPaths, MacPaths, LinuxPaths) store the file paths required to locate and interact with the Cursor application and its data files. These paths are determined dynamically based on the operating system.
| Section | Key | Description | Default Value (Example) |
|---|---|---|---|
WindowsPaths | storage_path | Path to the storage.json file. | %APPDATA%\Cursor\User\globalStorage\storage.json |
WindowsPaths | sqlite_path | Path to the state.vscdb SQLite database. | %APPDATA%\Cursor\User\globalStorage\state.vscdb |
WindowsPaths | machine_id_path | Path to the machineId file. | %APPDATA%\Cursor\machineId |
WindowsPaths | cursor_path | Path to the Cursor application resources. | %LOCALAPPDATA%\Programs\Cursor\resources\app |
MacPaths | storage_path | Path to the storage.json file. | ~/Library/Application Support/Cursor/User/globalStorage/storage.json |
LinuxPaths | storage_path | Path to the storage.json file. | ~/.config/cursor/User/globalStorage/storage.json |
Sources: config.py:127-217, totally_reset_cursor.py:195-263
Other Configuration Sections
The config.ini file also contains sections for browser settings, timing controls, utility flags, and more.
| Section | Key | Description | Default Value |
|---|---|---|---|
Browser | default_browser | The default browser to use for automation. | chrome |
Browser | chrome_path | Path to the Chrome executable. | (OS-dependent) |
Timing | max_timeout | Maximum timeout for various operations in seconds. | 160 |
Utils | enabled_update_check | Flag to enable or disable automatic update checks. | True |
OAuth | timeout | Timeout for OAuth authentication flow. | 120 |
Token | refresh_server | URL for the token refresh server. | https://token.cursorpro.com.cn |
Language | current_language | The current language for the UI. | (Detected from system) |
TempMailPlus | enabled | Flag to enable TempMailPlus for email verification. | false |
Sources: config.py:64-125, 219-224
User Data & Machine State
A core feature of the project is the ability to reset Cursor's trial state. This is achieved by manipulating user-specific data stored in storage.json, state.vscdb, and a machineId file. The MachineIDResetter class in totally_reset_cursor.py and reset_machine_manual.py encapsulates this logic.
Data Storage Locations
The state is primarily stored in three locations, whose paths are managed by the config.ini file.
This diagram shows that config.ini holds the paths to the other state files.
Sources: totally_reset_cursor.py:603-722, config.py:127-217
Machine ID Reset Process
The MachineIDResetter class is central to the state manipulation logic. It generates new unique identifiers and updates them across all relevant storage locations.
MachineIDResetter Class
Sources: totally_reset_cursor.py:603-662
Reset Flow
The reset_machine_ids method orchestrates the entire reset process. It involves generating new IDs, backing up old files, and writing the new IDs to storage.json, state.vscdb, and the system-specific machineId file.
Sources: totally_reset_cursor.py:804-862
The generate_new_ids function creates a new set of identifiers using uuid and hashlib.
# totally_reset_cursor.py:664-685
def generate_new_ids(self):
"""Generate new machine ID"""
# Generate new UUID
dev_device_id = str(uuid.uuid4())
# Generate new machineId (64 characters of hexadecimal)
machine_id = hashlib.sha256(os.urandom(32)).hexdigest()
# Generate new macMachineId (128 characters of hexadecimal)
mac_machine_id = hashlib.sha512(os.urandom(64)).hexdigest()
# Generate new sqmId
sqm_id = "{" + str(uuid.uuid4()).upper() + "}"
self.update_machine_id_file(dev_device_id)
return {
"telemetry.devDeviceId": dev_device_id,
"telemetry.macMachineId": mac_machine_id,
"telemetry.machineId": machine_id,
"telemetry.sqmId": sqm_id,
"storage.serviceMachineId": dev_device_id,
}
Sources: totally_reset_cursor.py:664-685
The new IDs are then written to the state.vscdb SQLite database, replacing existing values.
-- totally_reset_cursor.py:706-709
INSERT OR REPLACE INTO ItemTable (key, value)
VALUES (?, ?)
Sources: totally_reset_cursor.py:706-709
Authentication State
The application also manages user authentication state, primarily the access token required for API calls. The cursor_acc_info.py script contains logic to retrieve this token from various potential locations.
Token Retrieval
The get_token function attempts to find the user's access token by searching through storage.json, state.vscdb, and finally the Electron session storage files. This multi-source approach increases the likelihood of finding a valid token.
This sequence diagram shows the token retrieval process.
Sources: cursor_acc_info.py:151-170
Summary
The state management system in cursor-free-vip is a pragmatic and distributed architecture designed to support the project's core features. It relies on a central config.ini file for user settings and path definitions, while manipulating application-specific state in storage.json and state.vscdb to achieve its goals, such as resetting trial periods. The logic is spread across multiple scripts, with config.py handling setup and totally_reset_cursor.py and cursor_acc_info.py managing the reading and writing of dynamic state like machine IDs and authentication tokens. This design, while not a centralized state store, is effective for the tool's specific purposes.