Skip to content

Commit 30cba85

Browse files
committed
feature: default paths in config, updated/simplified readme
1 parent 142c9e1 commit 30cba85

File tree

4 files changed

+59
-44
lines changed

4 files changed

+59
-44
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.venv
22
**/__pycache__
3-
output
3+
output
4+
**/.DS_Store

README.md

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Also see [this](https://forum.cursor.com/t/guide-5-steps-exporting-chats-prompts
88

99
## Features
1010

11-
- **Discover Chats**: Discover all `state.vscdb` files in a directory and print a few lines of dialogue so one can identify which is the workspace (chat) one is searching for. It's also possible to filter by text.
12-
- **Export Chats**: Export chats data for a certain workspace to Markdown files or print it to the command line.
11+
- **Discover Chats**: Discover all chats from all workspaces and print a few lines of dialogue so one can identify which is the workspace (or chat) one is searching for. It's also possible to filter by text.
12+
- **Export Chats**: Export chats for the most recent (or a specific) workspace to Markdown files or print it to the command line.
1313

1414
## Installation
1515

@@ -26,49 +26,44 @@ Also see [this](https://forum.cursor.com/t/guide-5-steps-exporting-chats-prompts
2626

2727
## Usage
2828

29-
Find, where the `state.vscdb` is located in your computer. The table below may help:
29+
First, find, where the `state.vscdb` files are located on your computer. Confirm that corresponding to your system, the right path is set in the [config.yml](./config.yml) file. Update it if not set correctly.
3030

31-
| OS | Path |
32-
|------------------|-----------------------------------------------------------|
33-
| Windows | `%APPDATA%\Cursor\User\workspaceStorage` |
34-
| macOS | `/Users/YOUR_USERNAME/Library/Application Support/Cursor/User/workspaceStorage` |
35-
| Linux | `/home/YOUR_USERNAME/.config/Cursor/User/workspaceStorage` |
31+
Both the `discover` and `export` commands will work with this path by default, but you can also provide a custom path any time.
3632

37-
### Discover Chats of all Workspaces
38-
```sh
39-
python3 chat.py discover --search-text "matplotlib"
40-
```
33+
---
4134

42-
### Export all Chats of a specific Workspace
35+
### Discover Chats
4336
```sh
44-
python3 chat.py export --output-dir output "/Users/myuser/Library/Application Support/Cursor/User/workspaceStorage/b989572f2e2186b48b808da2da437416/state.vscdb"
45-
```
37+
# Help on usage
38+
./chat.py discover --help
4639
47-
If no directory is provided, the tool will automatically use the default Cursor workspace storage directory for your OS.
48-
49-
### Export the latest Tab from a specific Workspace
50-
```sh
51-
python3 chat.py export --output-dir output --latest-tab "/Users/myuser/Library/Application Support/Cursor/User/workspaceStorage/b989572f2e2186b48b808da2da437416/state.vscdb"
52-
```
40+
# Discover all chats from all workspaces
41+
./chat.py discover
5342
54-
### Auto-detect and Export Workspace Chats
43+
# Apply text filter
44+
./chat.py discover --search-text "matplotlib"
5545
56-
Examples:
46+
# Discover all chats from all workspaces at a custom path
47+
./chat.py discover "/path/to/workspaces"
48+
```
5749

50+
---
5851

59-
#### Export all tabs from the most recent workspace
52+
### Export Chats
53+
See `./chat.py export --help` for general help. Examples:
6054
```sh
61-
python3 chat.py export --output-dir output
62-
```
55+
# Help on usage
56+
./chat.py export --help
6357
64-
If no database path is provided, the tool will automatically use the most recent workspace.
58+
# Print all chats of the most recent workspace to the command line
59+
./chat.py export
6560
66-
#### Export the latest tab from the most recent workspace
61+
# Export all chats of the most recent workspace as Markdown
62+
./chat.py export --output-dir "/path/to/output"
6763
68-
You can use the `--latest-tab` flag to export only the most recent tab:
64+
# Export only the latest chat of the most recent workspace
65+
./chat.py export --latest-tab --output-dir "/path/to/output"
6966
70-
```sh
71-
python3 chat.py export --output-dir output --latest-tab
67+
# Export all chats of a specifc workspace
68+
./chat.py export --output-dir "/path/to/output" "/path/to/workspaces/workspace-dir/state.vscdb"
7269
```
73-
74-
These commands will automatically detect the appropriate directory for your OS when needed, find the latest workspace if no path is provided, and export the chats to the specified output directory according to the chosen options.

chat.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from rich.markdown import Markdown
1010
from loguru import logger
1111
import json
12+
import yaml
1213
import platform
1314
from pathlib import Path
1415

@@ -91,21 +92,35 @@ def export(
9192
raise typer.Exit(code=1)
9293

9394
def get_cursor_workspace_path() -> Path:
95+
config_path = Path("config.yml")
96+
logger.debug(f"Looking for configuration file at: {config_path}")
97+
98+
if not config_path.exists():
99+
error_message = f"Configuration file not found: {config_path}"
100+
logger.error(error_message)
101+
raise FileNotFoundError(error_message)
102+
103+
with open(config_path, 'r') as f:
104+
config = yaml.safe_load(f)
105+
logger.debug("Configuration file loaded successfully")
106+
94107
system = platform.system()
95-
home = Path.home()
108+
logger.debug(f"Detected operating system: {system}")
96109

97-
if system == "Windows":
98-
base_path = Path(os.environ.get("APPDATA")) / "Cursor" / "User" / "workspaceStorage"
99-
elif system == "Darwin": # macOS
100-
base_path = home / "Library" / "Application Support" / "Cursor" / "User" / "workspaceStorage"
101-
elif system == "Linux":
102-
base_path = home / ".config" / "Cursor" / "User" / "workspaceStorage"
103-
else:
104-
raise ValueError(f"Unsupported operating system: {system}")
110+
if system not in config["default_vscdb_dir_paths"]:
111+
error_message = f"Unsupported operating system: {system}"
112+
logger.error(error_message)
113+
raise ValueError(error_message)
114+
115+
base_path = Path(os.path.expandvars(config["default_vscdb_dir_paths"][system])).expanduser()
116+
logger.debug(f"Resolved base path: {base_path}")
105117

106118
if not base_path.exists():
107-
raise FileNotFoundError(f"Cursor workspace storage directory not found: {base_path}")
119+
error_message = f"Cursor workspace storage directory not found: {base_path}"
120+
logger.error(error_message)
121+
raise FileNotFoundError(error_message)
108122

123+
logger.info(f"Cursor workspace storage directory found: {base_path}")
109124
return base_path
110125

111126
def get_latest_workspace_db_path() -> str:

config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
default_vscdb_dir_paths:
2+
Windows: "%APPDATA%/Cursor/User/workspaceStorage"
3+
Darwin: "~/Library/Application Support/Cursor/User/workspaceStorage"
4+
Linux: "~/.config/Cursor/User/workspaceStorage"
15
aichat_query: "SELECT value FROM ItemTable WHERE [key] IN ('workbench.panel.aichat.view.aichat.chatdata');"

0 commit comments

Comments
 (0)