chore: 建立仓库并纳入修改 Cursor 用过的脚本
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"mcpServers": {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
Temp/
|
||||||
|
*.log
|
||||||
|
aidocs/
|
||||||
|
迁移导出/聊天记录/
|
||||||
+137
@@ -0,0 +1,137 @@
|
|||||||
|
# Cursor 迁移对话记录
|
||||||
|
|
||||||
|
日期:2026-12-06
|
||||||
|
机器:刚重装的 Windows,用户目录仍是 `C:\Users\Administrator`
|
||||||
|
备份:`F:\Cursor`(旧用户目录 `F:\Cursor\Users\Administrator`)
|
||||||
|
|
||||||
|
这份文件留在磁盘上。恢复脚本会覆盖 Cursor 的聊天数据库,界面里的这次对话会消失,操作步骤以本文为准。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 怎么恢复
|
||||||
|
|
||||||
|
1. 完全退出 Cursor。托盘图标也要退出,任务管理器里不能再有 `Cursor.exe`。
|
||||||
|
2. 确认 U 盘仍是 `F:`,备份目录仍是 `F:\Cursor`。
|
||||||
|
3. 双击运行:
|
||||||
|
|
||||||
|
`E:\code\AIChatMover\Restore-CursorFromUsb.bat`
|
||||||
|
|
||||||
|
4. 窗口里输入 `YES` 后等待。主要是从 U 盘复制约 7 GB 的聊天数据库,再加上项目索引、Agent 数据和扩展,合计大约 9 GB。耗时取决于 U 盘速度。
|
||||||
|
5. 脚本结束后再打开 Cursor,重新登录。
|
||||||
|
6. 用原来的路径打开项目(盘符和目录名要一致),聊天会挂回对应项目。
|
||||||
|
|
||||||
|
回滚(只恢复“覆盖前”的新装数据库和工作区索引,已拷入的 MCP、技能、扩展文件会留下):
|
||||||
|
|
||||||
|
`E:\code\AIChatMover\Rollback-CursorRestore.bat`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 对话
|
||||||
|
|
||||||
|
### 用户
|
||||||
|
|
||||||
|
你好
|
||||||
|
|
||||||
|
### 助手
|
||||||
|
|
||||||
|
你好。可以直接说要看代码、改功能,还是查问题。
|
||||||
|
|
||||||
|
### 用户
|
||||||
|
|
||||||
|
当前电脑刚刚重装完成。希望把原本电脑上 Cursor 的项目聊天记录迁回本机。备份在 U 盘 `F:\Cursor`。先说明怎样迁移。因为需要重启 Cursor,这一步自己来做。可以写好 bat/ps1 脚本。
|
||||||
|
|
||||||
|
### 助手
|
||||||
|
|
||||||
|
查看了备份和本机目录,结论记在下面「备份里实际有什么」和「脚本会做什么」。脚本没有在 Cursor 仍打开时执行。
|
||||||
|
|
||||||
|
### 用户
|
||||||
|
|
||||||
|
还有 Cursor 的一些 MCP、Skills 之类的也要恢复。
|
||||||
|
|
||||||
|
### 助手
|
||||||
|
|
||||||
|
MCP、Skills、规则、插件、扩展和用户设置一并列入恢复范围。
|
||||||
|
|
||||||
|
### 用户
|
||||||
|
|
||||||
|
可以丢失本对话和登录状态,可以重新登录。本对话只需要把聊天记录写成 md 文档。
|
||||||
|
|
||||||
|
### 助手
|
||||||
|
|
||||||
|
本文档就是这次对话的记录。恢复脚本改为直接覆盖聊天数据库,不再保留本次新装的登录状态。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 备份里实际有什么
|
||||||
|
|
||||||
|
旧机和新机都是用户 `Administrator`,项目路径仍在 `E:\code\...` 和 `E:\Work\...`。工作区编号由路径算出来,所以路径不变时,旧聊天能对上原来的项目。
|
||||||
|
|
||||||
|
聊天数据主要在这些位置:
|
||||||
|
|
||||||
|
| 内容 | 备份位置 | 大约体积 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 全部对话正文、会话列表 | `%AppData%\Cursor\User\globalStorage\state.vscdb`(含 wal/shm) | 7.0 GB,约 43 万条记录,340 个会话头 |
|
||||||
|
| 对话搜索索引 | 同目录 `conversation-search.db` | 8 MB |
|
||||||
|
| 每个项目的会话索引 | `%AppData%\Cursor\User\workspaceStorage`(26 个工作区) | 65 MB |
|
||||||
|
| 代理转录 | `%USERPROFILE%\.cursor\projects\*\agent-transcripts` | projects 共 260 MB,21 个转录目录,135 个 jsonl |
|
||||||
|
| Agent 存储 | `%LOCALAPPDATA%\Cursor\AgentStores` | 609 MB |
|
||||||
|
| 最近打开的窗口 | `globalStorage\storage.json` | 很小 |
|
||||||
|
|
||||||
|
MCP 和技能:
|
||||||
|
|
||||||
|
- `%USERPROFILE%\.cursor\mcp.json`:服务器名 MemRelay、charles、rea
|
||||||
|
- `%USERPROFILE%\.agents\servers`:git、memrelay、playwright
|
||||||
|
- `%USERPROFILE%\.agents\skills`:技能目录(含额外的 reverse-engineer-anything、deploy-with-vercel)
|
||||||
|
- `%USERPROFILE%\.cursor\skills-cursor`:Cursor 自带技能
|
||||||
|
- `%USERPROFILE%\.cursor\rules\dev-rules.mdc`
|
||||||
|
- `%USERPROFILE%\.cursor\plugins`(约 167 MB,含本地插件 collaboration-rules)
|
||||||
|
- `%USERPROFILE%\.cursor\extensions`(14 个扩展,约 469 MB)
|
||||||
|
- `%USERPROFILE%\.cursor\plans`
|
||||||
|
- 用户设置 `%AppData%\Cursor\User\settings.json`
|
||||||
|
- 多根工作区 `glassMultiRootWorkspaces\cbnsmsinfo.code-workspace`
|
||||||
|
|
||||||
|
脚本故意不复制:缓存、GPUCache、日志、Crashpad、`machineid`、浏览器 Cookie、`anysphere.cursor-agent-worker` 里的运行日志(约 255 MB)、以及 `.pi`、`.codex`、`.pi-desktop`(不是 Cursor 的数据)。
|
||||||
|
|
||||||
|
重装之后,Windows 的加密密钥已经换过。旧库里的登录令牌、MCP 的 OAuth 令牌通常解不开,所以要重新登录,OAuth 类 MCP 要重新授权。`mcp.json` 里的服务器配置会回来。聊天正文在 `state.vscdb` 里,随库一起覆盖回来。
|
||||||
|
|
||||||
|
## 脚本会做什么
|
||||||
|
|
||||||
|
`Restore-CursorFromUsb.ps1`:
|
||||||
|
|
||||||
|
1. 发现 `Cursor.exe` 仍在运行,或聊天库正被占用,就直接退出。
|
||||||
|
2. 把当前(新装)的聊天库、`storage.json`、`settings.json`、`workspaceStorage` 快照到 `C:\CursorMigrationBackup\<时间戳>\`。
|
||||||
|
3. 先把 U 盘上的数据库复制到 `C:\CursorMigrationBackup\incoming\`,核对文件大小,再替换本机文件。这样复制中途失败时,本机原库还在。
|
||||||
|
4. 替换 `state.vscdb`、`conversation-search.db` 以及它们的 `-wal`、`-shm`。替换前会删掉本机旧的 wal/shm,避免和新库混在一起。
|
||||||
|
5. 合并复制工作区、项目转录、AgentStores、MCP、技能、规则、计划、插件、扩展、设置和 `argv.json`、`cli-config.json`。
|
||||||
|
6. 本机多出来的目录不会被删掉。例如这次的 `e-code-AIChatMover` 项目目录会留下,但界面里的这次对话会随数据库覆盖而消失。
|
||||||
|
|
||||||
|
## 恢复后要打开的项目路径
|
||||||
|
|
||||||
|
这些路径来自备份里的 `workspace.json`。代码本身不在 `F:\Cursor` 里,需要项目文件夹仍在原路径:
|
||||||
|
|
||||||
|
- `E:\code\AIRules`
|
||||||
|
- `E:\code\CapaReport`
|
||||||
|
- `E:\code\cbnsmsinfo`
|
||||||
|
- `E:\code\commguard-next`
|
||||||
|
- `E:\code\EunivTools`
|
||||||
|
- `E:\code\GisDataTools`
|
||||||
|
- `E:\code\Google_Manager`
|
||||||
|
- `E:\code\LTEDongle`
|
||||||
|
- `E:\code\MarketGrid`
|
||||||
|
- `E:\code\MarketGrid\xyzserver`
|
||||||
|
- `E:\code\Metrix`
|
||||||
|
- `E:\code\Metrix\plugins\CapacityReport`
|
||||||
|
- `E:\code\net-oss-routing`
|
||||||
|
- `E:\code\NqiTools`
|
||||||
|
- `E:\code\PunchLog`
|
||||||
|
- `E:\code\QGIS`
|
||||||
|
- `E:\code\SiteDemolition`
|
||||||
|
- `E:\code\tempcode\go\helloworld`
|
||||||
|
- `E:\Work\临时需求\0701\SiteDataTool0701`
|
||||||
|
- `E:\Work\临时需求\1027-AOI-CGI`
|
||||||
|
- `E:\Work\临时需求\360NetSpeed`
|
||||||
|
- `E:\TempData\EmptyTemp`
|
||||||
|
- `E:\Users\Administrator\Downloads\metrix-hosted-app-example`
|
||||||
|
- `C:\Users\Administrator\AppData\Roaming\Cursor\glassMultiRootWorkspaces\cbnsmsinfo.code-workspace`
|
||||||
|
|
||||||
|
打开对应文件夹后,左侧历史里应能看到旧对话。若某个项目目录还没拷回电脑,先把代码放回同一路径再打开。
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
@echo off
|
||||||
|
cd /d "%~dp0"
|
||||||
|
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0Restart-Cursor.ps1" -DelaySeconds 2
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
# Restart Cursor from a detached process so the caller can exit first.
|
||||||
|
# Usage:
|
||||||
|
# Restart-Cursor.bat
|
||||||
|
# powershell -ExecutionPolicy Bypass -File .\Restart-Cursor.ps1 -DelaySeconds 8
|
||||||
|
|
||||||
|
param(
|
||||||
|
[switch]$Worker,
|
||||||
|
[int]$DelaySeconds = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
$log = Join-Path $PSScriptRoot "Restart-Cursor.log"
|
||||||
|
|
||||||
|
function Write-Log([string]$Message) {
|
||||||
|
$line = "{0} {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Message
|
||||||
|
Add-Content -LiteralPath $log -Value $line -Encoding UTF8
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $Worker) {
|
||||||
|
$cmd = "powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" -Worker -DelaySeconds $DelaySeconds"
|
||||||
|
$result = Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{ CommandLine = $cmd }
|
||||||
|
if ($result.ReturnValue -ne 0) {
|
||||||
|
Write-Log "start worker failed: $($result.ReturnValue)"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
Write-Log "worker started pid=$($result.ProcessId) delay=$DelaySeconds"
|
||||||
|
Write-Host "Cursor will restart in $DelaySeconds seconds."
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
Start-Sleep -Seconds $DelaySeconds
|
||||||
|
|
||||||
|
$running = @(Get-CimInstance Win32_Process -Filter "Name = 'Cursor.exe'" | Where-Object { $_.ExecutablePath })
|
||||||
|
$fallback = "D:\Program Files\cursor\Cursor.exe"
|
||||||
|
if ($running.Count -gt 0) {
|
||||||
|
$exe = $running[0].ExecutablePath
|
||||||
|
} elseif (Test-Path -LiteralPath $fallback) {
|
||||||
|
$exe = $fallback
|
||||||
|
} else {
|
||||||
|
Write-Log "Cursor.exe not found"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Log "closing $exe"
|
||||||
|
Get-Process -Name Cursor -ErrorAction SilentlyContinue | ForEach-Object {
|
||||||
|
[void]$_.CloseMainWindow()
|
||||||
|
}
|
||||||
|
|
||||||
|
$deadline = (Get-Date).AddSeconds(12)
|
||||||
|
while ((Get-Process -Name Cursor -ErrorAction SilentlyContinue) -and (Get-Date) -lt $deadline) {
|
||||||
|
Start-Sleep -Milliseconds 400
|
||||||
|
}
|
||||||
|
|
||||||
|
$left = @(Get-Process -Name Cursor -ErrorAction SilentlyContinue)
|
||||||
|
if ($left.Count -gt 0) {
|
||||||
|
Write-Log "force stop $($left.Count)"
|
||||||
|
$left | Stop-Process -Force
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Start-Process -FilePath $exe
|
||||||
|
Write-Log "started $exe"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
@echo off
|
||||||
|
chcp 65001 >nul
|
||||||
|
cd /d "%~dp0"
|
||||||
|
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0Restore-CursorFromUsb.ps1"
|
||||||
|
echo.
|
||||||
|
pause
|
||||||
@@ -0,0 +1,401 @@
|
|||||||
|
# Restore Cursor chats, MCP, skills, and related settings.
|
||||||
|
# Default backup is the new machine's user profile copy: G:\Users\Administrator
|
||||||
|
# Also accepts an older full-disk layout such as F:\Cursor\Users\Administrator.
|
||||||
|
# Close Cursor completely before running. Login on this machine will be replaced.
|
||||||
|
# Usage:
|
||||||
|
# Restore-CursorFromUsb.bat
|
||||||
|
# powershell -ExecutionPolicy Bypass -File .\Restore-CursorFromUsb.ps1
|
||||||
|
# powershell -ExecutionPolicy Bypass -File .\Restore-CursorFromUsb.ps1 -Rollback
|
||||||
|
|
||||||
|
param(
|
||||||
|
[string]$BackupRoot = "G:\Users\Administrator",
|
||||||
|
[switch]$Rollback
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
$SnapshotRoot = "C:\CursorMigrationBackup"
|
||||||
|
$LatestFile = Join-Path $SnapshotRoot "latest.txt"
|
||||||
|
|
||||||
|
function Write-Step([string]$Message) {
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "== $Message" -ForegroundColor Cyan
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-CursorRunning {
|
||||||
|
$procs = @(Get-CimInstance Win32_Process -ErrorAction SilentlyContinue | Where-Object {
|
||||||
|
$_.Name -eq "Cursor.exe" -or
|
||||||
|
($_.ExecutablePath -and $_.ExecutablePath -like "*\Cursor\Cursor.exe")
|
||||||
|
})
|
||||||
|
return $procs
|
||||||
|
}
|
||||||
|
|
||||||
|
function Assert-CursorClosed {
|
||||||
|
$procs = @(Test-CursorRunning)
|
||||||
|
if ($procs.Count -gt 0) {
|
||||||
|
Write-Host "Cursor 仍在运行。请先完全退出(含托盘图标),任务管理器里不要留下 Cursor.exe。" -ForegroundColor Yellow
|
||||||
|
$procs | Select-Object ProcessId, Name, ExecutablePath | Format-Table -AutoSize | Out-Host
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = Join-Path $env:APPDATA "Cursor\User\globalStorage\state.vscdb"
|
||||||
|
if (Test-Path -LiteralPath $db) {
|
||||||
|
try {
|
||||||
|
$stream = [System.IO.File]::Open($db, "Open", "ReadWrite", "None")
|
||||||
|
$stream.Close()
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "聊天数据库仍被占用。请确认 Cursor 已退出后重新运行。" -ForegroundColor Yellow
|
||||||
|
Write-Host $_.Exception.Message
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Invoke-RoboCopy {
|
||||||
|
param([Parameter(Mandatory = $true)][string[]]$RoboArgs)
|
||||||
|
& robocopy.exe @RoboArgs | Out-Host
|
||||||
|
$code = $LASTEXITCODE
|
||||||
|
if ($code -ge 8) {
|
||||||
|
throw "robocopy 失败,退出码 $code : robocopy $($RoboArgs -join ' ')"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Copy-Tree {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)][string]$Source,
|
||||||
|
[Parameter(Mandatory = $true)][string]$Destination,
|
||||||
|
[switch]$Quiet
|
||||||
|
)
|
||||||
|
if (-not (Test-Path -LiteralPath $Source)) {
|
||||||
|
Write-Host "跳过,源不存在: $Source" -ForegroundColor DarkYellow
|
||||||
|
return
|
||||||
|
}
|
||||||
|
New-Item -ItemType Directory -Force -Path $Destination | Out-Null
|
||||||
|
Write-Host "目录: $Source"
|
||||||
|
$args = @($Source, $Destination, "/E", "/COPY:DAT", "/DCOPY:DAT", "/R:2", "/W:2", "/XJ", "/FFT")
|
||||||
|
if ($Quiet) {
|
||||||
|
$args += @("/NFL", "/NDL", "/NP")
|
||||||
|
}
|
||||||
|
Invoke-RoboCopy $args
|
||||||
|
}
|
||||||
|
|
||||||
|
function Copy-FileForce {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)][string]$Source,
|
||||||
|
[Parameter(Mandatory = $true)][string]$Destination
|
||||||
|
)
|
||||||
|
if (-not (Test-Path -LiteralPath $Source)) {
|
||||||
|
Write-Host "跳过,源不存在: $Source" -ForegroundColor DarkYellow
|
||||||
|
return
|
||||||
|
}
|
||||||
|
$parent = Split-Path -Parent $Destination
|
||||||
|
if ($parent) {
|
||||||
|
New-Item -ItemType Directory -Force -Path $parent | Out-Null
|
||||||
|
}
|
||||||
|
Copy-Item -LiteralPath $Source -Destination $Destination -Force
|
||||||
|
Write-Host "文件: $Destination"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-SqliteSet {
|
||||||
|
param([Parameter(Mandatory = $true)][string]$Directory, [Parameter(Mandatory = $true)][string]$BaseName)
|
||||||
|
$files = @()
|
||||||
|
foreach ($suffix in @("", "-wal", "-shm")) {
|
||||||
|
$path = Join-Path $Directory ($BaseName + $suffix)
|
||||||
|
if (Test-Path -LiteralPath $path) {
|
||||||
|
$files += $path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $files
|
||||||
|
}
|
||||||
|
|
||||||
|
function Remove-SqliteSet {
|
||||||
|
param([Parameter(Mandatory = $true)][string]$Directory, [Parameter(Mandatory = $true)][string]$BaseName)
|
||||||
|
foreach ($suffix in @("-wal", "-shm", "")) {
|
||||||
|
$path = Join-Path $Directory ($BaseName + $suffix)
|
||||||
|
if (Test-Path -LiteralPath $path) {
|
||||||
|
Remove-Item -LiteralPath $path -Force
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Restore-SqliteDatabase {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)][string]$SourceDir,
|
||||||
|
[Parameter(Mandatory = $true)][string]$DestDir,
|
||||||
|
[Parameter(Mandatory = $true)][string]$BaseName,
|
||||||
|
[Parameter(Mandatory = $true)][string]$IncomingRoot
|
||||||
|
)
|
||||||
|
$sourceFile = Join-Path $SourceDir $BaseName
|
||||||
|
if (-not (Test-Path -LiteralPath $sourceFile)) {
|
||||||
|
throw "找不到数据库: $sourceFile"
|
||||||
|
}
|
||||||
|
|
||||||
|
$stage = Join-Path $IncomingRoot $BaseName
|
||||||
|
if (Test-Path -LiteralPath $stage) {
|
||||||
|
Remove-Item -LiteralPath $stage -Recurse -Force
|
||||||
|
}
|
||||||
|
New-Item -ItemType Directory -Force -Path $stage | Out-Null
|
||||||
|
|
||||||
|
foreach ($suffix in @("", "-wal", "-shm")) {
|
||||||
|
$name = $BaseName + $suffix
|
||||||
|
$from = Join-Path $SourceDir $name
|
||||||
|
if (-not (Test-Path -LiteralPath $from)) { continue }
|
||||||
|
$sizeMb = "{0:N1}" -f ((Get-Item -LiteralPath $from).Length / 1MB)
|
||||||
|
Write-Host "复制 $name ($sizeMb MB)"
|
||||||
|
Invoke-RoboCopy @($SourceDir, $stage, $name, "/J", "/R:2", "/W:3", "/NFL", "/NDL")
|
||||||
|
$copied = Join-Path $stage $name
|
||||||
|
$srcLen = (Get-Item -LiteralPath $from).Length
|
||||||
|
$dstLen = (Get-Item -LiteralPath $copied).Length
|
||||||
|
if ($srcLen -ne $dstLen) {
|
||||||
|
throw "$name 大小不一致。源 $srcLen 字节,副本 $dstLen 字节。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
New-Item -ItemType Directory -Force -Path $DestDir | Out-Null
|
||||||
|
Remove-SqliteSet -Directory $DestDir -BaseName $BaseName
|
||||||
|
foreach ($suffix in @("", "-wal", "-shm")) {
|
||||||
|
$name = $BaseName + $suffix
|
||||||
|
$from = Join-Path $stage $name
|
||||||
|
if (Test-Path -LiteralPath $from) {
|
||||||
|
Move-Item -LiteralPath $from -Destination (Join-Path $DestDir $name) -Force
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Host "已替换 $DestDir\$BaseName"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-SourceUser {
|
||||||
|
param([Parameter(Mandatory = $true)][string]$Root)
|
||||||
|
$selfMarker = Join-Path $Root "AppData\Roaming\Cursor\User\globalStorage\state.vscdb"
|
||||||
|
if (Test-Path -LiteralPath $selfMarker) {
|
||||||
|
return $Root
|
||||||
|
}
|
||||||
|
$direct = Join-Path $Root "Users\Administrator"
|
||||||
|
$marker = Join-Path $direct "AppData\Roaming\Cursor\User\globalStorage\state.vscdb"
|
||||||
|
if (Test-Path -LiteralPath $marker) {
|
||||||
|
return $direct
|
||||||
|
}
|
||||||
|
$users = Join-Path $Root "Users"
|
||||||
|
if (Test-Path -LiteralPath $users) {
|
||||||
|
foreach ($dir in Get-ChildItem -LiteralPath $users -Directory) {
|
||||||
|
$candidate = Join-Path $dir.FullName "AppData\Roaming\Cursor\User\globalStorage\state.vscdb"
|
||||||
|
if (Test-Path -LiteralPath $candidate) {
|
||||||
|
return $dir.FullName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw "在 $Root 下没有找到 Cursor 的 state.vscdb。请确认 U 盘盘符和备份目录。"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Save-Snapshot {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)][string]$Destination,
|
||||||
|
[Parameter(Mandatory = $true)][string[]]$WorkspaceNames
|
||||||
|
)
|
||||||
|
New-Item -ItemType Directory -Force -Path $Destination | Out-Null
|
||||||
|
$globalStorage = Join-Path $env:APPDATA "Cursor\User\globalStorage"
|
||||||
|
$snapGlobal = Join-Path $Destination "AppData\Roaming\Cursor\User\globalStorage"
|
||||||
|
New-Item -ItemType Directory -Force -Path $snapGlobal | Out-Null
|
||||||
|
|
||||||
|
foreach ($base in @("state.vscdb", "conversation-search.db")) {
|
||||||
|
foreach ($path in (Get-SqliteSet -Directory $globalStorage -BaseName $base)) {
|
||||||
|
Copy-Item -LiteralPath $path -Destination (Join-Path $snapGlobal (Split-Path -Leaf $path)) -Force
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$storage = Join-Path $globalStorage "storage.json"
|
||||||
|
if (Test-Path -LiteralPath $storage) {
|
||||||
|
Copy-Item -LiteralPath $storage -Destination (Join-Path $snapGlobal "storage.json") -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
$settings = Join-Path $env:APPDATA "Cursor\User\settings.json"
|
||||||
|
if (Test-Path -LiteralPath $settings) {
|
||||||
|
$snapUser = Join-Path $Destination "AppData\Roaming\Cursor\User"
|
||||||
|
New-Item -ItemType Directory -Force -Path $snapUser | Out-Null
|
||||||
|
Copy-Item -LiteralPath $settings -Destination (Join-Path $snapUser "settings.json") -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
$ws = Join-Path $env:APPDATA "Cursor\User\workspaceStorage"
|
||||||
|
if (Test-Path -LiteralPath $ws) {
|
||||||
|
Copy-Tree -Source $ws -Destination (Join-Path $Destination "AppData\Roaming\Cursor\User\workspaceStorage") -Quiet
|
||||||
|
}
|
||||||
|
|
||||||
|
$manifest = [ordered]@{
|
||||||
|
created = (Get-Date).ToString("s")
|
||||||
|
computer = $env:COMPUTERNAME
|
||||||
|
userProfile = $env:USERPROFILE
|
||||||
|
appData = $env:APPDATA
|
||||||
|
localAppData = $env:LOCALAPPDATA
|
||||||
|
workspaceFolders = $WorkspaceNames
|
||||||
|
}
|
||||||
|
$manifestPath = Join-Path $Destination "manifest.json"
|
||||||
|
$manifest | ConvertTo-Json | Set-Content -LiteralPath $manifestPath -Encoding UTF8
|
||||||
|
Set-Content -LiteralPath $LatestFile -Value $Destination -Encoding UTF8
|
||||||
|
Write-Host "快照: $Destination"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Restore-Snapshot {
|
||||||
|
param([Parameter(Mandatory = $true)][string]$Snapshot)
|
||||||
|
$manifestPath = Join-Path $Snapshot "manifest.json"
|
||||||
|
if (-not (Test-Path -LiteralPath $manifestPath)) {
|
||||||
|
throw "快照缺少 manifest.json: $Snapshot"
|
||||||
|
}
|
||||||
|
$manifest = Get-Content -LiteralPath $manifestPath -Raw -Encoding UTF8 | ConvertFrom-Json
|
||||||
|
|
||||||
|
$globalStorage = Join-Path $env:APPDATA "Cursor\User\globalStorage"
|
||||||
|
$snapGlobal = Join-Path $Snapshot "AppData\Roaming\Cursor\User\globalStorage"
|
||||||
|
foreach ($base in @("state.vscdb", "conversation-search.db")) {
|
||||||
|
$srcFile = Join-Path $snapGlobal $base
|
||||||
|
if (-not (Test-Path -LiteralPath $srcFile)) { continue }
|
||||||
|
Remove-SqliteSet -Directory $globalStorage -BaseName $base
|
||||||
|
foreach ($path in (Get-SqliteSet -Directory $snapGlobal -BaseName $base)) {
|
||||||
|
Copy-Item -LiteralPath $path -Destination (Join-Path $globalStorage (Split-Path -Leaf $path)) -Force
|
||||||
|
}
|
||||||
|
Write-Host "已回滚 $base"
|
||||||
|
}
|
||||||
|
|
||||||
|
$snapStorage = Join-Path $snapGlobal "storage.json"
|
||||||
|
if (Test-Path -LiteralPath $snapStorage) {
|
||||||
|
Copy-Item -LiteralPath $snapStorage -Destination (Join-Path $globalStorage "storage.json") -Force
|
||||||
|
}
|
||||||
|
$snapSettings = Join-Path $Snapshot "AppData\Roaming\Cursor\User\settings.json"
|
||||||
|
if (Test-Path -LiteralPath $snapSettings) {
|
||||||
|
Copy-Item -LiteralPath $snapSettings -Destination (Join-Path $env:APPDATA "Cursor\User\settings.json") -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
$wsDest = Join-Path $env:APPDATA "Cursor\User\workspaceStorage"
|
||||||
|
$known = @()
|
||||||
|
if ($manifest.workspaceFolders) {
|
||||||
|
$known = @($manifest.workspaceFolders)
|
||||||
|
}
|
||||||
|
if (Test-Path -LiteralPath $wsDest) {
|
||||||
|
foreach ($dir in Get-ChildItem -LiteralPath $wsDest -Directory) {
|
||||||
|
if ($known -notcontains $dir.Name) {
|
||||||
|
Write-Host "移除恢复时新增的工作区: $($dir.Name)"
|
||||||
|
Remove-Item -LiteralPath $dir.FullName -Recurse -Force
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$wsSnap = Join-Path $Snapshot "AppData\Roaming\Cursor\User\workspaceStorage"
|
||||||
|
if (Test-Path -LiteralPath $wsSnap) {
|
||||||
|
Copy-Tree -Source $wsSnap -Destination $wsDest -Quiet
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Confirm-Action([string]$Prompt) {
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host $Prompt -ForegroundColor Yellow
|
||||||
|
$answer = Read-Host "输入 YES 继续"
|
||||||
|
if ($answer -ne "YES") {
|
||||||
|
Write-Host "已取消。"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert-CursorClosed
|
||||||
|
|
||||||
|
if ($Rollback) {
|
||||||
|
if (-not (Test-Path -LiteralPath $LatestFile)) {
|
||||||
|
Write-Host "这是回滚脚本,还没有可回滚的快照。" -ForegroundColor Yellow
|
||||||
|
Write-Host "迁移请运行同目录下的 Restore-CursorFromUsb.bat"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
$snapshot = (Get-Content -LiteralPath $LatestFile -Raw).Trim()
|
||||||
|
if (-not (Test-Path -LiteralPath $snapshot)) {
|
||||||
|
throw "快照目录不存在: $snapshot"
|
||||||
|
}
|
||||||
|
Confirm-Action "将把 Cursor 聊天库和工作区索引恢复到覆盖前的快照:`n$snapshot"
|
||||||
|
Write-Step "回滚"
|
||||||
|
Restore-Snapshot -Snapshot $snapshot
|
||||||
|
Write-Step "回滚完成"
|
||||||
|
Write-Host "可以重新打开 Cursor。MCP、技能、扩展文件没有从磁盘删除。"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Step "检查备份"
|
||||||
|
if (-not (Test-Path -LiteralPath $BackupRoot)) {
|
||||||
|
throw "备份目录不存在: $BackupRoot"
|
||||||
|
}
|
||||||
|
$sourceUser = Get-SourceUser -Root $BackupRoot
|
||||||
|
$sourceRoaming = Join-Path $sourceUser "AppData\Roaming\Cursor"
|
||||||
|
$sourceLocal = Join-Path $sourceUser "AppData\Local\Cursor"
|
||||||
|
$sourceDotCursor = Join-Path $sourceUser ".cursor"
|
||||||
|
$sourceAgents = Join-Path $sourceUser ".agents"
|
||||||
|
Write-Host "备份用户目录: $sourceUser"
|
||||||
|
Write-Host "本机用户目录: $env:USERPROFILE"
|
||||||
|
|
||||||
|
$freeC = (Get-PSDrive -Name C).Free
|
||||||
|
if ($freeC -lt 20GB) {
|
||||||
|
throw "C 盘剩余空间不足 20 GB(当前 $([math]::Round($freeC/1GB, 1)) GB)。覆盖聊天库前需要足够空间。"
|
||||||
|
}
|
||||||
|
|
||||||
|
Confirm-Action @"
|
||||||
|
即将用 U 盘备份覆盖本机 Cursor 数据:
|
||||||
|
- 聊天数据库 state.vscdb(约 7 GB)和搜索索引
|
||||||
|
- 各项目工作区索引、项目转录、AgentStores
|
||||||
|
- MCP、Skills、规则、计划、插件、扩展、用户设置
|
||||||
|
本机当前登录状态和这次新装后的对话会被覆盖。开始前会先做快照到:
|
||||||
|
$SnapshotRoot
|
||||||
|
"@
|
||||||
|
|
||||||
|
$wsNow = Join-Path $env:APPDATA "Cursor\User\workspaceStorage"
|
||||||
|
$workspaceNames = @()
|
||||||
|
if (Test-Path -LiteralPath $wsNow) {
|
||||||
|
$workspaceNames = @(Get-ChildItem -LiteralPath $wsNow -Directory | ForEach-Object { $_.Name })
|
||||||
|
}
|
||||||
|
|
||||||
|
$stamp = Get-Date -Format "yyyyMMdd-HHmmss"
|
||||||
|
$snapshot = Join-Path $SnapshotRoot $stamp
|
||||||
|
$incoming = Join-Path $SnapshotRoot "incoming"
|
||||||
|
|
||||||
|
Write-Step "保存当前数据快照"
|
||||||
|
Save-Snapshot -Destination $snapshot -WorkspaceNames $workspaceNames
|
||||||
|
|
||||||
|
Write-Step "替换聊天数据库"
|
||||||
|
$srcGlobal = Join-Path $sourceRoaming "User\globalStorage"
|
||||||
|
$dstGlobal = Join-Path $env:APPDATA "Cursor\User\globalStorage"
|
||||||
|
Restore-SqliteDatabase -SourceDir $srcGlobal -DestDir $dstGlobal -BaseName "state.vscdb" -IncomingRoot $incoming
|
||||||
|
Restore-SqliteDatabase -SourceDir $srcGlobal -DestDir $dstGlobal -BaseName "conversation-search.db" -IncomingRoot $incoming
|
||||||
|
Copy-FileForce -Source (Join-Path $srcGlobal "storage.json") -Destination (Join-Path $dstGlobal "storage.json")
|
||||||
|
|
||||||
|
Write-Step "复制项目工作区索引"
|
||||||
|
$srcWorkspace = Join-Path $sourceRoaming "User\workspaceStorage"
|
||||||
|
$dstWorkspace = Join-Path $env:APPDATA "Cursor\User\workspaceStorage"
|
||||||
|
Copy-Tree -Source $srcWorkspace -Destination $dstWorkspace -Quiet
|
||||||
|
if (Test-Path -LiteralPath $srcWorkspace) {
|
||||||
|
Get-ChildItem -LiteralPath $srcWorkspace -Recurse -File -Force | Where-Object {
|
||||||
|
$_.Name -in @("state.vscdb", "state.vscdb-wal", "state.vscdb-shm", "workspace.json")
|
||||||
|
} | ForEach-Object {
|
||||||
|
$relative = $_.FullName.Substring($srcWorkspace.Length).TrimStart("\")
|
||||||
|
$target = Join-Path $dstWorkspace $relative
|
||||||
|
New-Item -ItemType Directory -Force -Path (Split-Path -Parent $target) | Out-Null
|
||||||
|
Copy-Item -LiteralPath $_.FullName -Destination $target -Force
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Copy-Tree -Source (Join-Path $sourceRoaming "glassMultiRootWorkspaces") -Destination (Join-Path $env:APPDATA "Cursor\glassMultiRootWorkspaces") -Quiet
|
||||||
|
Copy-FileForce -Source (Join-Path $sourceRoaming "User\settings.json") -Destination (Join-Path $env:APPDATA "Cursor\User\settings.json")
|
||||||
|
Copy-Tree -Source (Join-Path $sourceRoaming "User\snippets") -Destination (Join-Path $env:APPDATA "Cursor\User\snippets") -Quiet
|
||||||
|
|
||||||
|
Write-Step "复制项目转录和 Agent 数据"
|
||||||
|
Copy-Tree -Source (Join-Path $sourceDotCursor "projects") -Destination (Join-Path $env:USERPROFILE ".cursor\projects") -Quiet
|
||||||
|
Copy-Tree -Source (Join-Path $sourceDotCursor "plans") -Destination (Join-Path $env:USERPROFILE ".cursor\plans") -Quiet
|
||||||
|
Copy-Tree -Source (Join-Path $sourceLocal "AgentStores") -Destination (Join-Path $env:LOCALAPPDATA "Cursor\AgentStores") -Quiet
|
||||||
|
|
||||||
|
Write-Step "复制 MCP、Skills、规则、插件和扩展"
|
||||||
|
Copy-FileForce -Source (Join-Path $sourceDotCursor "mcp.json") -Destination (Join-Path $env:USERPROFILE ".cursor\mcp.json")
|
||||||
|
Copy-FileForce -Source (Join-Path $sourceDotCursor "argv.json") -Destination (Join-Path $env:USERPROFILE ".cursor\argv.json")
|
||||||
|
Copy-FileForce -Source (Join-Path $sourceDotCursor "cli-config.json") -Destination (Join-Path $env:USERPROFILE ".cursor\cli-config.json")
|
||||||
|
Copy-Tree -Source (Join-Path $sourceDotCursor "rules") -Destination (Join-Path $env:USERPROFILE ".cursor\rules") -Quiet
|
||||||
|
Copy-Tree -Source (Join-Path $sourceDotCursor "skills-cursor") -Destination (Join-Path $env:USERPROFILE ".cursor\skills-cursor") -Quiet
|
||||||
|
Copy-Tree -Source (Join-Path $sourceDotCursor "plugins") -Destination (Join-Path $env:USERPROFILE ".cursor\plugins") -Quiet
|
||||||
|
Copy-Tree -Source (Join-Path $sourceDotCursor "extensions") -Destination (Join-Path $env:USERPROFILE ".cursor\extensions") -Quiet
|
||||||
|
Copy-Tree -Source $sourceAgents -Destination (Join-Path $env:USERPROFILE ".agents") -Quiet
|
||||||
|
|
||||||
|
if (Test-Path -LiteralPath $incoming) {
|
||||||
|
Remove-Item -LiteralPath $incoming -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Step "完成"
|
||||||
|
Write-Host "快照保留在: $snapshot"
|
||||||
|
Write-Host "现在可以重新打开 Cursor 并登录。"
|
||||||
|
Write-Host "用原来的路径打开项目后,旧对话会挂回该项目。说明见 Cursor迁移对话记录.md"
|
||||||
|
Write-Host "若要退回覆盖前的聊天库,运行 Rollback-CursorRestore.bat"
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
@echo off
|
||||||
|
chcp 65001 >nul
|
||||||
|
cd /d "%~dp0"
|
||||||
|
echo 这是回滚,不是迁移。要把 U 盘数据迁回来,请运行 Restore-CursorFromUsb.bat
|
||||||
|
echo.
|
||||||
|
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0Restore-CursorFromUsb.ps1" -Rollback
|
||||||
|
echo.
|
||||||
|
pause
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
# 把 Cursor Agent 窗口改成简体中文。先退出 Cursor,写入 molten 语言和窗口模式,再重新打开。
|
||||||
|
# 用法: powershell -ExecutionPolicy Bypass -File .\Set-CursorAgentZh.ps1
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
$log = Join-Path $PSScriptRoot "Set-CursorAgentZh.log"
|
||||||
|
|
||||||
|
function Write-Log([string]$Message) {
|
||||||
|
$line = "{0} {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Message
|
||||||
|
Add-Content -LiteralPath $log -Value $line -Encoding UTF8
|
||||||
|
}
|
||||||
|
|
||||||
|
Start-Sleep -Seconds 8
|
||||||
|
$fallback = "D:\Program Files\cursor\Cursor.exe"
|
||||||
|
$running = @(Get-CimInstance Win32_Process -Filter "Name = 'Cursor.exe'" | Where-Object { $_.ExecutablePath })
|
||||||
|
if ($running.Count -gt 0) { $exe = $running[0].ExecutablePath } else { $exe = $fallback }
|
||||||
|
Write-Log "closing $exe"
|
||||||
|
Get-Process -Name Cursor -ErrorAction SilentlyContinue | ForEach-Object { [void]$_.CloseMainWindow() }
|
||||||
|
$deadline = (Get-Date).AddSeconds(12)
|
||||||
|
while ((Get-Process -Name Cursor -ErrorAction SilentlyContinue) -and (Get-Date) -lt $deadline) {
|
||||||
|
Start-Sleep -Milliseconds 400
|
||||||
|
}
|
||||||
|
$left = @(Get-Process -Name Cursor -ErrorAction SilentlyContinue)
|
||||||
|
if ($left.Count -gt 0) {
|
||||||
|
Write-Log "force stop $($left.Count)"
|
||||||
|
$left | Stop-Process -Force
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
|
||||||
|
if ($pythonCmd) {
|
||||||
|
$python = $pythonCmd.Source
|
||||||
|
} else {
|
||||||
|
$python = "D:\SoftwareSpace\uv\bin\python.exe"
|
||||||
|
}
|
||||||
|
$py = Join-Path $PSScriptRoot "set-cursor-zh.py"
|
||||||
|
& $python $py
|
||||||
|
Write-Log "python exit $LASTEXITCODE"
|
||||||
|
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||||
|
Start-Process -FilePath $exe
|
||||||
|
Write-Log "started $exe"
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import json
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
prefs_path = r"C:\Users\Administrator\AppData\Roaming\Cursor\molten\prefs.json"
|
||||||
|
db_path = r"C:\Users\Administrator\AppData\Roaming\Cursor\User\globalStorage\state.vscdb"
|
||||||
|
with open(prefs_path, encoding="utf-8") as f:
|
||||||
|
prefs = json.load(f)
|
||||||
|
prefs["i18nGate"] = True
|
||||||
|
prefs["language"] = "zh-CN"
|
||||||
|
with open(prefs_path, "w", encoding="utf-8", newline="\n") as f:
|
||||||
|
json.dump(prefs, f, ensure_ascii=False, indent=2)
|
||||||
|
f.write("\n")
|
||||||
|
|
||||||
|
con = sqlite3.connect(db_path, timeout=20)
|
||||||
|
try:
|
||||||
|
mirror = con.execute(
|
||||||
|
"SELECT value FROM ItemTable WHERE key = ?",
|
||||||
|
("cursor.agentsWindow.gateMirror",),
|
||||||
|
).fetchone()
|
||||||
|
auth_id = json.loads(mirror[0])["authId"] if mirror else ""
|
||||||
|
if not auth_id:
|
||||||
|
raise SystemExit("missing auth id")
|
||||||
|
override = json.dumps({"authId": auth_id, "mode": "molten"}, separators=(",", ":"))
|
||||||
|
row = con.execute(
|
||||||
|
"SELECT key FROM ItemTable WHERE key = ?",
|
||||||
|
("cursor.agentsWindow.override",),
|
||||||
|
).fetchone()
|
||||||
|
if row:
|
||||||
|
con.execute(
|
||||||
|
"UPDATE ItemTable SET value = ? WHERE key = ?",
|
||||||
|
(override, "cursor.agentsWindow.override"),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
con.execute(
|
||||||
|
"INSERT INTO ItemTable (key, value) VALUES (?, ?)",
|
||||||
|
("cursor.agentsWindow.override", override),
|
||||||
|
)
|
||||||
|
con.commit()
|
||||||
|
finally:
|
||||||
|
con.close()
|
||||||
|
print("ok")
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
# Cursor 迁移对话记录
|
||||||
|
|
||||||
|
日期:2026-12-06
|
||||||
|
机器:刚重装的 Windows,用户目录仍是 `C:\Users\Administrator`
|
||||||
|
备份:`F:\Cursor`(旧用户目录 `F:\Cursor\Users\Administrator`)
|
||||||
|
|
||||||
|
这份文件留在磁盘上。恢复脚本会覆盖 Cursor 的聊天数据库,界面里的这次对话会消失,操作步骤以本文为准。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 怎么恢复
|
||||||
|
|
||||||
|
1. 完全退出 Cursor。托盘图标也要退出,任务管理器里不能再有 `Cursor.exe`。
|
||||||
|
2. 确认 U 盘仍是 `F:`,备份目录仍是 `F:\Cursor`。
|
||||||
|
3. 双击运行:
|
||||||
|
|
||||||
|
`E:\code\AIChatMover\Restore-CursorFromUsb.bat`
|
||||||
|
|
||||||
|
4. 窗口里输入 `YES` 后等待。主要是从 U 盘复制约 7 GB 的聊天数据库,再加上项目索引、Agent 数据和扩展,合计大约 9 GB。耗时取决于 U 盘速度。
|
||||||
|
5. 脚本结束后再打开 Cursor,重新登录。
|
||||||
|
6. 用原来的路径打开项目(盘符和目录名要一致),聊天会挂回对应项目。
|
||||||
|
|
||||||
|
回滚(只恢复“覆盖前”的新装数据库和工作区索引,已拷入的 MCP、技能、扩展文件会留下):
|
||||||
|
|
||||||
|
`E:\code\AIChatMover\Rollback-CursorRestore.bat`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 对话
|
||||||
|
|
||||||
|
### 用户
|
||||||
|
|
||||||
|
你好
|
||||||
|
|
||||||
|
### 助手
|
||||||
|
|
||||||
|
你好。可以直接说要看代码、改功能,还是查问题。
|
||||||
|
|
||||||
|
### 用户
|
||||||
|
|
||||||
|
当前电脑刚刚重装完成。希望把原本电脑上 Cursor 的项目聊天记录迁回本机。备份在 U 盘 `F:\Cursor`。先说明怎样迁移。因为需要重启 Cursor,这一步自己来做。可以写好 bat/ps1 脚本。
|
||||||
|
|
||||||
|
### 助手
|
||||||
|
|
||||||
|
查看了备份和本机目录,结论记在下面「备份里实际有什么」和「脚本会做什么」。脚本没有在 Cursor 仍打开时执行。
|
||||||
|
|
||||||
|
### 用户
|
||||||
|
|
||||||
|
还有 Cursor 的一些 MCP、Skills 之类的也要恢复。
|
||||||
|
|
||||||
|
### 助手
|
||||||
|
|
||||||
|
MCP、Skills、规则、插件、扩展和用户设置一并列入恢复范围。
|
||||||
|
|
||||||
|
### 用户
|
||||||
|
|
||||||
|
可以丢失本对话和登录状态,可以重新登录。本对话只需要把聊天记录写成 md 文档。
|
||||||
|
|
||||||
|
### 助手
|
||||||
|
|
||||||
|
本文档就是这次对话的记录。恢复脚本改为直接覆盖聊天数据库,不再保留本次新装的登录状态。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 备份里实际有什么
|
||||||
|
|
||||||
|
旧机和新机都是用户 `Administrator`,项目路径仍在 `E:\code\...` 和 `E:\Work\...`。工作区编号由路径算出来,所以路径不变时,旧聊天能对上原来的项目。
|
||||||
|
|
||||||
|
聊天数据主要在这些位置:
|
||||||
|
|
||||||
|
| 内容 | 备份位置 | 大约体积 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 全部对话正文、会话列表 | `%AppData%\Cursor\User\globalStorage\state.vscdb`(含 wal/shm) | 7.0 GB,约 43 万条记录,340 个会话头 |
|
||||||
|
| 对话搜索索引 | 同目录 `conversation-search.db` | 8 MB |
|
||||||
|
| 每个项目的会话索引 | `%AppData%\Cursor\User\workspaceStorage`(26 个工作区) | 65 MB |
|
||||||
|
| 代理转录 | `%USERPROFILE%\.cursor\projects\*\agent-transcripts` | projects 共 260 MB,21 个转录目录,135 个 jsonl |
|
||||||
|
| Agent 存储 | `%LOCALAPPDATA%\Cursor\AgentStores` | 609 MB |
|
||||||
|
| 最近打开的窗口 | `globalStorage\storage.json` | 很小 |
|
||||||
|
|
||||||
|
MCP 和技能:
|
||||||
|
|
||||||
|
- `%USERPROFILE%\.cursor\mcp.json`:服务器名 MemRelay、charles、rea
|
||||||
|
- `%USERPROFILE%\.agents\servers`:git、memrelay、playwright
|
||||||
|
- `%USERPROFILE%\.agents\skills`:技能目录(含额外的 reverse-engineer-anything、deploy-with-vercel)
|
||||||
|
- `%USERPROFILE%\.cursor\skills-cursor`:Cursor 自带技能
|
||||||
|
- `%USERPROFILE%\.cursor\rules\dev-rules.mdc`
|
||||||
|
- `%USERPROFILE%\.cursor\plugins`(约 167 MB,含本地插件 collaboration-rules)
|
||||||
|
- `%USERPROFILE%\.cursor\extensions`(14 个扩展,约 469 MB)
|
||||||
|
- `%USERPROFILE%\.cursor\plans`
|
||||||
|
- 用户设置 `%AppData%\Cursor\User\settings.json`
|
||||||
|
- 多根工作区 `glassMultiRootWorkspaces\cbnsmsinfo.code-workspace`
|
||||||
|
|
||||||
|
脚本故意不复制:缓存、GPUCache、日志、Crashpad、`machineid`、浏览器 Cookie、`anysphere.cursor-agent-worker` 里的运行日志(约 255 MB)、以及 `.pi`、`.codex`、`.pi-desktop`(不是 Cursor 的数据)。
|
||||||
|
|
||||||
|
重装之后,Windows 的加密密钥已经换过。旧库里的登录令牌、MCP 的 OAuth 令牌通常解不开,所以要重新登录,OAuth 类 MCP 要重新授权。`mcp.json` 里的服务器配置会回来。聊天正文在 `state.vscdb` 里,随库一起覆盖回来。
|
||||||
|
|
||||||
|
## 脚本会做什么
|
||||||
|
|
||||||
|
`Restore-CursorFromUsb.ps1`:
|
||||||
|
|
||||||
|
1. 发现 `Cursor.exe` 仍在运行,或聊天库正被占用,就直接退出。
|
||||||
|
2. 把当前(新装)的聊天库、`storage.json`、`settings.json`、`workspaceStorage` 快照到 `C:\CursorMigrationBackup\<时间戳>\`。
|
||||||
|
3. 先把 U 盘上的数据库复制到 `C:\CursorMigrationBackup\incoming\`,核对文件大小,再替换本机文件。这样复制中途失败时,本机原库还在。
|
||||||
|
4. 替换 `state.vscdb`、`conversation-search.db` 以及它们的 `-wal`、`-shm`。替换前会删掉本机旧的 wal/shm,避免和新库混在一起。
|
||||||
|
5. 合并复制工作区、项目转录、AgentStores、MCP、技能、规则、计划、插件、扩展、设置和 `argv.json`、`cli-config.json`。
|
||||||
|
6. 本机多出来的目录不会被删掉。例如这次的 `e-code-AIChatMover` 项目目录会留下,但界面里的这次对话会随数据库覆盖而消失。
|
||||||
|
|
||||||
|
## 恢复后要打开的项目路径
|
||||||
|
|
||||||
|
这些路径来自备份里的 `workspace.json`。代码本身不在 `F:\Cursor` 里,需要项目文件夹仍在原路径:
|
||||||
|
|
||||||
|
- `E:\code\AIRules`
|
||||||
|
- `E:\code\CapaReport`
|
||||||
|
- `E:\code\cbnsmsinfo`
|
||||||
|
- `E:\code\commguard-next`
|
||||||
|
- `E:\code\EunivTools`
|
||||||
|
- `E:\code\GisDataTools`
|
||||||
|
- `E:\code\Google_Manager`
|
||||||
|
- `E:\code\LTEDongle`
|
||||||
|
- `E:\code\MarketGrid`
|
||||||
|
- `E:\code\MarketGrid\xyzserver`
|
||||||
|
- `E:\code\Metrix`
|
||||||
|
- `E:\code\Metrix\plugins\CapacityReport`
|
||||||
|
- `E:\code\net-oss-routing`
|
||||||
|
- `E:\code\NqiTools`
|
||||||
|
- `E:\code\PunchLog`
|
||||||
|
- `E:\code\QGIS`
|
||||||
|
- `E:\code\SiteDemolition`
|
||||||
|
- `E:\code\tempcode\go\helloworld`
|
||||||
|
- `E:\Work\临时需求\0701\SiteDataTool0701`
|
||||||
|
- `E:\Work\临时需求\1027-AOI-CGI`
|
||||||
|
- `E:\Work\临时需求\360NetSpeed`
|
||||||
|
- `E:\TempData\EmptyTemp`
|
||||||
|
- `E:\Users\Administrator\Downloads\metrix-hosted-app-example`
|
||||||
|
- `C:\Users\Administrator\AppData\Roaming\Cursor\glassMultiRootWorkspaces\cbnsmsinfo.code-workspace`
|
||||||
|
|
||||||
|
打开对应文件夹后,左侧历史里应能看到旧对话。若某个项目目录还没拷回电脑,先把代码放回同一路径再打开。
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
@echo off
|
||||||
|
cd /d "%~dp0"
|
||||||
|
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0Restart-Cursor.ps1" -DelaySeconds 2
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
# Restart Cursor from a detached process so the caller can exit first.
|
||||||
|
# Usage:
|
||||||
|
# Restart-Cursor.bat
|
||||||
|
# powershell -ExecutionPolicy Bypass -File .\Restart-Cursor.ps1 -DelaySeconds 8
|
||||||
|
|
||||||
|
param(
|
||||||
|
[switch]$Worker,
|
||||||
|
[int]$DelaySeconds = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
$log = Join-Path $PSScriptRoot "Restart-Cursor.log"
|
||||||
|
|
||||||
|
function Write-Log([string]$Message) {
|
||||||
|
$line = "{0} {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Message
|
||||||
|
Add-Content -LiteralPath $log -Value $line -Encoding UTF8
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $Worker) {
|
||||||
|
$cmd = "powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" -Worker -DelaySeconds $DelaySeconds"
|
||||||
|
$result = Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{ CommandLine = $cmd }
|
||||||
|
if ($result.ReturnValue -ne 0) {
|
||||||
|
Write-Log "start worker failed: $($result.ReturnValue)"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
Write-Log "worker started pid=$($result.ProcessId) delay=$DelaySeconds"
|
||||||
|
Write-Host "Cursor will restart in $DelaySeconds seconds."
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
Start-Sleep -Seconds $DelaySeconds
|
||||||
|
|
||||||
|
$running = @(Get-CimInstance Win32_Process -Filter "Name = 'Cursor.exe'" | Where-Object { $_.ExecutablePath })
|
||||||
|
$fallback = "D:\Program Files\cursor\Cursor.exe"
|
||||||
|
if ($running.Count -gt 0) {
|
||||||
|
$exe = $running[0].ExecutablePath
|
||||||
|
} elseif (Test-Path -LiteralPath $fallback) {
|
||||||
|
$exe = $fallback
|
||||||
|
} else {
|
||||||
|
Write-Log "Cursor.exe not found"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Log "closing $exe"
|
||||||
|
Get-Process -Name Cursor -ErrorAction SilentlyContinue | ForEach-Object {
|
||||||
|
[void]$_.CloseMainWindow()
|
||||||
|
}
|
||||||
|
|
||||||
|
$deadline = (Get-Date).AddSeconds(12)
|
||||||
|
while ((Get-Process -Name Cursor -ErrorAction SilentlyContinue) -and (Get-Date) -lt $deadline) {
|
||||||
|
Start-Sleep -Milliseconds 400
|
||||||
|
}
|
||||||
|
|
||||||
|
$left = @(Get-Process -Name Cursor -ErrorAction SilentlyContinue)
|
||||||
|
if ($left.Count -gt 0) {
|
||||||
|
Write-Log "force stop $($left.Count)"
|
||||||
|
$left | Stop-Process -Force
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Start-Process -FilePath $exe
|
||||||
|
Write-Log "started $exe"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
@echo off
|
||||||
|
chcp 65001 >nul
|
||||||
|
cd /d "%~dp0"
|
||||||
|
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0Restore-CursorFromUsb.ps1"
|
||||||
|
echo.
|
||||||
|
pause
|
||||||
@@ -0,0 +1,401 @@
|
|||||||
|
# Restore Cursor chats, MCP, skills, and related settings.
|
||||||
|
# Default backup is the new machine's user profile copy: G:\Users\Administrator
|
||||||
|
# Also accepts an older full-disk layout such as F:\Cursor\Users\Administrator.
|
||||||
|
# Close Cursor completely before running. Login on this machine will be replaced.
|
||||||
|
# Usage:
|
||||||
|
# Restore-CursorFromUsb.bat
|
||||||
|
# powershell -ExecutionPolicy Bypass -File .\Restore-CursorFromUsb.ps1
|
||||||
|
# powershell -ExecutionPolicy Bypass -File .\Restore-CursorFromUsb.ps1 -Rollback
|
||||||
|
|
||||||
|
param(
|
||||||
|
[string]$BackupRoot = "G:\Users\Administrator",
|
||||||
|
[switch]$Rollback
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
$SnapshotRoot = "C:\CursorMigrationBackup"
|
||||||
|
$LatestFile = Join-Path $SnapshotRoot "latest.txt"
|
||||||
|
|
||||||
|
function Write-Step([string]$Message) {
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "== $Message" -ForegroundColor Cyan
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-CursorRunning {
|
||||||
|
$procs = @(Get-CimInstance Win32_Process -ErrorAction SilentlyContinue | Where-Object {
|
||||||
|
$_.Name -eq "Cursor.exe" -or
|
||||||
|
($_.ExecutablePath -and $_.ExecutablePath -like "*\Cursor\Cursor.exe")
|
||||||
|
})
|
||||||
|
return $procs
|
||||||
|
}
|
||||||
|
|
||||||
|
function Assert-CursorClosed {
|
||||||
|
$procs = @(Test-CursorRunning)
|
||||||
|
if ($procs.Count -gt 0) {
|
||||||
|
Write-Host "Cursor 仍在运行。请先完全退出(含托盘图标),任务管理器里不要留下 Cursor.exe。" -ForegroundColor Yellow
|
||||||
|
$procs | Select-Object ProcessId, Name, ExecutablePath | Format-Table -AutoSize | Out-Host
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = Join-Path $env:APPDATA "Cursor\User\globalStorage\state.vscdb"
|
||||||
|
if (Test-Path -LiteralPath $db) {
|
||||||
|
try {
|
||||||
|
$stream = [System.IO.File]::Open($db, "Open", "ReadWrite", "None")
|
||||||
|
$stream.Close()
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "聊天数据库仍被占用。请确认 Cursor 已退出后重新运行。" -ForegroundColor Yellow
|
||||||
|
Write-Host $_.Exception.Message
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Invoke-RoboCopy {
|
||||||
|
param([Parameter(Mandatory = $true)][string[]]$RoboArgs)
|
||||||
|
& robocopy.exe @RoboArgs | Out-Host
|
||||||
|
$code = $LASTEXITCODE
|
||||||
|
if ($code -ge 8) {
|
||||||
|
throw "robocopy 失败,退出码 $code : robocopy $($RoboArgs -join ' ')"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Copy-Tree {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)][string]$Source,
|
||||||
|
[Parameter(Mandatory = $true)][string]$Destination,
|
||||||
|
[switch]$Quiet
|
||||||
|
)
|
||||||
|
if (-not (Test-Path -LiteralPath $Source)) {
|
||||||
|
Write-Host "跳过,源不存在: $Source" -ForegroundColor DarkYellow
|
||||||
|
return
|
||||||
|
}
|
||||||
|
New-Item -ItemType Directory -Force -Path $Destination | Out-Null
|
||||||
|
Write-Host "目录: $Source"
|
||||||
|
$args = @($Source, $Destination, "/E", "/COPY:DAT", "/DCOPY:DAT", "/R:2", "/W:2", "/XJ", "/FFT")
|
||||||
|
if ($Quiet) {
|
||||||
|
$args += @("/NFL", "/NDL", "/NP")
|
||||||
|
}
|
||||||
|
Invoke-RoboCopy $args
|
||||||
|
}
|
||||||
|
|
||||||
|
function Copy-FileForce {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)][string]$Source,
|
||||||
|
[Parameter(Mandatory = $true)][string]$Destination
|
||||||
|
)
|
||||||
|
if (-not (Test-Path -LiteralPath $Source)) {
|
||||||
|
Write-Host "跳过,源不存在: $Source" -ForegroundColor DarkYellow
|
||||||
|
return
|
||||||
|
}
|
||||||
|
$parent = Split-Path -Parent $Destination
|
||||||
|
if ($parent) {
|
||||||
|
New-Item -ItemType Directory -Force -Path $parent | Out-Null
|
||||||
|
}
|
||||||
|
Copy-Item -LiteralPath $Source -Destination $Destination -Force
|
||||||
|
Write-Host "文件: $Destination"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-SqliteSet {
|
||||||
|
param([Parameter(Mandatory = $true)][string]$Directory, [Parameter(Mandatory = $true)][string]$BaseName)
|
||||||
|
$files = @()
|
||||||
|
foreach ($suffix in @("", "-wal", "-shm")) {
|
||||||
|
$path = Join-Path $Directory ($BaseName + $suffix)
|
||||||
|
if (Test-Path -LiteralPath $path) {
|
||||||
|
$files += $path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $files
|
||||||
|
}
|
||||||
|
|
||||||
|
function Remove-SqliteSet {
|
||||||
|
param([Parameter(Mandatory = $true)][string]$Directory, [Parameter(Mandatory = $true)][string]$BaseName)
|
||||||
|
foreach ($suffix in @("-wal", "-shm", "")) {
|
||||||
|
$path = Join-Path $Directory ($BaseName + $suffix)
|
||||||
|
if (Test-Path -LiteralPath $path) {
|
||||||
|
Remove-Item -LiteralPath $path -Force
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Restore-SqliteDatabase {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)][string]$SourceDir,
|
||||||
|
[Parameter(Mandatory = $true)][string]$DestDir,
|
||||||
|
[Parameter(Mandatory = $true)][string]$BaseName,
|
||||||
|
[Parameter(Mandatory = $true)][string]$IncomingRoot
|
||||||
|
)
|
||||||
|
$sourceFile = Join-Path $SourceDir $BaseName
|
||||||
|
if (-not (Test-Path -LiteralPath $sourceFile)) {
|
||||||
|
throw "找不到数据库: $sourceFile"
|
||||||
|
}
|
||||||
|
|
||||||
|
$stage = Join-Path $IncomingRoot $BaseName
|
||||||
|
if (Test-Path -LiteralPath $stage) {
|
||||||
|
Remove-Item -LiteralPath $stage -Recurse -Force
|
||||||
|
}
|
||||||
|
New-Item -ItemType Directory -Force -Path $stage | Out-Null
|
||||||
|
|
||||||
|
foreach ($suffix in @("", "-wal", "-shm")) {
|
||||||
|
$name = $BaseName + $suffix
|
||||||
|
$from = Join-Path $SourceDir $name
|
||||||
|
if (-not (Test-Path -LiteralPath $from)) { continue }
|
||||||
|
$sizeMb = "{0:N1}" -f ((Get-Item -LiteralPath $from).Length / 1MB)
|
||||||
|
Write-Host "复制 $name ($sizeMb MB)"
|
||||||
|
Invoke-RoboCopy @($SourceDir, $stage, $name, "/J", "/R:2", "/W:3", "/NFL", "/NDL")
|
||||||
|
$copied = Join-Path $stage $name
|
||||||
|
$srcLen = (Get-Item -LiteralPath $from).Length
|
||||||
|
$dstLen = (Get-Item -LiteralPath $copied).Length
|
||||||
|
if ($srcLen -ne $dstLen) {
|
||||||
|
throw "$name 大小不一致。源 $srcLen 字节,副本 $dstLen 字节。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
New-Item -ItemType Directory -Force -Path $DestDir | Out-Null
|
||||||
|
Remove-SqliteSet -Directory $DestDir -BaseName $BaseName
|
||||||
|
foreach ($suffix in @("", "-wal", "-shm")) {
|
||||||
|
$name = $BaseName + $suffix
|
||||||
|
$from = Join-Path $stage $name
|
||||||
|
if (Test-Path -LiteralPath $from) {
|
||||||
|
Move-Item -LiteralPath $from -Destination (Join-Path $DestDir $name) -Force
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Host "已替换 $DestDir\$BaseName"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-SourceUser {
|
||||||
|
param([Parameter(Mandatory = $true)][string]$Root)
|
||||||
|
$selfMarker = Join-Path $Root "AppData\Roaming\Cursor\User\globalStorage\state.vscdb"
|
||||||
|
if (Test-Path -LiteralPath $selfMarker) {
|
||||||
|
return $Root
|
||||||
|
}
|
||||||
|
$direct = Join-Path $Root "Users\Administrator"
|
||||||
|
$marker = Join-Path $direct "AppData\Roaming\Cursor\User\globalStorage\state.vscdb"
|
||||||
|
if (Test-Path -LiteralPath $marker) {
|
||||||
|
return $direct
|
||||||
|
}
|
||||||
|
$users = Join-Path $Root "Users"
|
||||||
|
if (Test-Path -LiteralPath $users) {
|
||||||
|
foreach ($dir in Get-ChildItem -LiteralPath $users -Directory) {
|
||||||
|
$candidate = Join-Path $dir.FullName "AppData\Roaming\Cursor\User\globalStorage\state.vscdb"
|
||||||
|
if (Test-Path -LiteralPath $candidate) {
|
||||||
|
return $dir.FullName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw "在 $Root 下没有找到 Cursor 的 state.vscdb。请确认 U 盘盘符和备份目录。"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Save-Snapshot {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)][string]$Destination,
|
||||||
|
[Parameter(Mandatory = $true)][string[]]$WorkspaceNames
|
||||||
|
)
|
||||||
|
New-Item -ItemType Directory -Force -Path $Destination | Out-Null
|
||||||
|
$globalStorage = Join-Path $env:APPDATA "Cursor\User\globalStorage"
|
||||||
|
$snapGlobal = Join-Path $Destination "AppData\Roaming\Cursor\User\globalStorage"
|
||||||
|
New-Item -ItemType Directory -Force -Path $snapGlobal | Out-Null
|
||||||
|
|
||||||
|
foreach ($base in @("state.vscdb", "conversation-search.db")) {
|
||||||
|
foreach ($path in (Get-SqliteSet -Directory $globalStorage -BaseName $base)) {
|
||||||
|
Copy-Item -LiteralPath $path -Destination (Join-Path $snapGlobal (Split-Path -Leaf $path)) -Force
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$storage = Join-Path $globalStorage "storage.json"
|
||||||
|
if (Test-Path -LiteralPath $storage) {
|
||||||
|
Copy-Item -LiteralPath $storage -Destination (Join-Path $snapGlobal "storage.json") -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
$settings = Join-Path $env:APPDATA "Cursor\User\settings.json"
|
||||||
|
if (Test-Path -LiteralPath $settings) {
|
||||||
|
$snapUser = Join-Path $Destination "AppData\Roaming\Cursor\User"
|
||||||
|
New-Item -ItemType Directory -Force -Path $snapUser | Out-Null
|
||||||
|
Copy-Item -LiteralPath $settings -Destination (Join-Path $snapUser "settings.json") -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
$ws = Join-Path $env:APPDATA "Cursor\User\workspaceStorage"
|
||||||
|
if (Test-Path -LiteralPath $ws) {
|
||||||
|
Copy-Tree -Source $ws -Destination (Join-Path $Destination "AppData\Roaming\Cursor\User\workspaceStorage") -Quiet
|
||||||
|
}
|
||||||
|
|
||||||
|
$manifest = [ordered]@{
|
||||||
|
created = (Get-Date).ToString("s")
|
||||||
|
computer = $env:COMPUTERNAME
|
||||||
|
userProfile = $env:USERPROFILE
|
||||||
|
appData = $env:APPDATA
|
||||||
|
localAppData = $env:LOCALAPPDATA
|
||||||
|
workspaceFolders = $WorkspaceNames
|
||||||
|
}
|
||||||
|
$manifestPath = Join-Path $Destination "manifest.json"
|
||||||
|
$manifest | ConvertTo-Json | Set-Content -LiteralPath $manifestPath -Encoding UTF8
|
||||||
|
Set-Content -LiteralPath $LatestFile -Value $Destination -Encoding UTF8
|
||||||
|
Write-Host "快照: $Destination"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Restore-Snapshot {
|
||||||
|
param([Parameter(Mandatory = $true)][string]$Snapshot)
|
||||||
|
$manifestPath = Join-Path $Snapshot "manifest.json"
|
||||||
|
if (-not (Test-Path -LiteralPath $manifestPath)) {
|
||||||
|
throw "快照缺少 manifest.json: $Snapshot"
|
||||||
|
}
|
||||||
|
$manifest = Get-Content -LiteralPath $manifestPath -Raw -Encoding UTF8 | ConvertFrom-Json
|
||||||
|
|
||||||
|
$globalStorage = Join-Path $env:APPDATA "Cursor\User\globalStorage"
|
||||||
|
$snapGlobal = Join-Path $Snapshot "AppData\Roaming\Cursor\User\globalStorage"
|
||||||
|
foreach ($base in @("state.vscdb", "conversation-search.db")) {
|
||||||
|
$srcFile = Join-Path $snapGlobal $base
|
||||||
|
if (-not (Test-Path -LiteralPath $srcFile)) { continue }
|
||||||
|
Remove-SqliteSet -Directory $globalStorage -BaseName $base
|
||||||
|
foreach ($path in (Get-SqliteSet -Directory $snapGlobal -BaseName $base)) {
|
||||||
|
Copy-Item -LiteralPath $path -Destination (Join-Path $globalStorage (Split-Path -Leaf $path)) -Force
|
||||||
|
}
|
||||||
|
Write-Host "已回滚 $base"
|
||||||
|
}
|
||||||
|
|
||||||
|
$snapStorage = Join-Path $snapGlobal "storage.json"
|
||||||
|
if (Test-Path -LiteralPath $snapStorage) {
|
||||||
|
Copy-Item -LiteralPath $snapStorage -Destination (Join-Path $globalStorage "storage.json") -Force
|
||||||
|
}
|
||||||
|
$snapSettings = Join-Path $Snapshot "AppData\Roaming\Cursor\User\settings.json"
|
||||||
|
if (Test-Path -LiteralPath $snapSettings) {
|
||||||
|
Copy-Item -LiteralPath $snapSettings -Destination (Join-Path $env:APPDATA "Cursor\User\settings.json") -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
$wsDest = Join-Path $env:APPDATA "Cursor\User\workspaceStorage"
|
||||||
|
$known = @()
|
||||||
|
if ($manifest.workspaceFolders) {
|
||||||
|
$known = @($manifest.workspaceFolders)
|
||||||
|
}
|
||||||
|
if (Test-Path -LiteralPath $wsDest) {
|
||||||
|
foreach ($dir in Get-ChildItem -LiteralPath $wsDest -Directory) {
|
||||||
|
if ($known -notcontains $dir.Name) {
|
||||||
|
Write-Host "移除恢复时新增的工作区: $($dir.Name)"
|
||||||
|
Remove-Item -LiteralPath $dir.FullName -Recurse -Force
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$wsSnap = Join-Path $Snapshot "AppData\Roaming\Cursor\User\workspaceStorage"
|
||||||
|
if (Test-Path -LiteralPath $wsSnap) {
|
||||||
|
Copy-Tree -Source $wsSnap -Destination $wsDest -Quiet
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Confirm-Action([string]$Prompt) {
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host $Prompt -ForegroundColor Yellow
|
||||||
|
$answer = Read-Host "输入 YES 继续"
|
||||||
|
if ($answer -ne "YES") {
|
||||||
|
Write-Host "已取消。"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert-CursorClosed
|
||||||
|
|
||||||
|
if ($Rollback) {
|
||||||
|
if (-not (Test-Path -LiteralPath $LatestFile)) {
|
||||||
|
Write-Host "这是回滚脚本,还没有可回滚的快照。" -ForegroundColor Yellow
|
||||||
|
Write-Host "迁移请运行同目录下的 Restore-CursorFromUsb.bat"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
$snapshot = (Get-Content -LiteralPath $LatestFile -Raw).Trim()
|
||||||
|
if (-not (Test-Path -LiteralPath $snapshot)) {
|
||||||
|
throw "快照目录不存在: $snapshot"
|
||||||
|
}
|
||||||
|
Confirm-Action "将把 Cursor 聊天库和工作区索引恢复到覆盖前的快照:`n$snapshot"
|
||||||
|
Write-Step "回滚"
|
||||||
|
Restore-Snapshot -Snapshot $snapshot
|
||||||
|
Write-Step "回滚完成"
|
||||||
|
Write-Host "可以重新打开 Cursor。MCP、技能、扩展文件没有从磁盘删除。"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Step "检查备份"
|
||||||
|
if (-not (Test-Path -LiteralPath $BackupRoot)) {
|
||||||
|
throw "备份目录不存在: $BackupRoot"
|
||||||
|
}
|
||||||
|
$sourceUser = Get-SourceUser -Root $BackupRoot
|
||||||
|
$sourceRoaming = Join-Path $sourceUser "AppData\Roaming\Cursor"
|
||||||
|
$sourceLocal = Join-Path $sourceUser "AppData\Local\Cursor"
|
||||||
|
$sourceDotCursor = Join-Path $sourceUser ".cursor"
|
||||||
|
$sourceAgents = Join-Path $sourceUser ".agents"
|
||||||
|
Write-Host "备份用户目录: $sourceUser"
|
||||||
|
Write-Host "本机用户目录: $env:USERPROFILE"
|
||||||
|
|
||||||
|
$freeC = (Get-PSDrive -Name C).Free
|
||||||
|
if ($freeC -lt 20GB) {
|
||||||
|
throw "C 盘剩余空间不足 20 GB(当前 $([math]::Round($freeC/1GB, 1)) GB)。覆盖聊天库前需要足够空间。"
|
||||||
|
}
|
||||||
|
|
||||||
|
Confirm-Action @"
|
||||||
|
即将用 U 盘备份覆盖本机 Cursor 数据:
|
||||||
|
- 聊天数据库 state.vscdb(约 7 GB)和搜索索引
|
||||||
|
- 各项目工作区索引、项目转录、AgentStores
|
||||||
|
- MCP、Skills、规则、计划、插件、扩展、用户设置
|
||||||
|
本机当前登录状态和这次新装后的对话会被覆盖。开始前会先做快照到:
|
||||||
|
$SnapshotRoot
|
||||||
|
"@
|
||||||
|
|
||||||
|
$wsNow = Join-Path $env:APPDATA "Cursor\User\workspaceStorage"
|
||||||
|
$workspaceNames = @()
|
||||||
|
if (Test-Path -LiteralPath $wsNow) {
|
||||||
|
$workspaceNames = @(Get-ChildItem -LiteralPath $wsNow -Directory | ForEach-Object { $_.Name })
|
||||||
|
}
|
||||||
|
|
||||||
|
$stamp = Get-Date -Format "yyyyMMdd-HHmmss"
|
||||||
|
$snapshot = Join-Path $SnapshotRoot $stamp
|
||||||
|
$incoming = Join-Path $SnapshotRoot "incoming"
|
||||||
|
|
||||||
|
Write-Step "保存当前数据快照"
|
||||||
|
Save-Snapshot -Destination $snapshot -WorkspaceNames $workspaceNames
|
||||||
|
|
||||||
|
Write-Step "替换聊天数据库"
|
||||||
|
$srcGlobal = Join-Path $sourceRoaming "User\globalStorage"
|
||||||
|
$dstGlobal = Join-Path $env:APPDATA "Cursor\User\globalStorage"
|
||||||
|
Restore-SqliteDatabase -SourceDir $srcGlobal -DestDir $dstGlobal -BaseName "state.vscdb" -IncomingRoot $incoming
|
||||||
|
Restore-SqliteDatabase -SourceDir $srcGlobal -DestDir $dstGlobal -BaseName "conversation-search.db" -IncomingRoot $incoming
|
||||||
|
Copy-FileForce -Source (Join-Path $srcGlobal "storage.json") -Destination (Join-Path $dstGlobal "storage.json")
|
||||||
|
|
||||||
|
Write-Step "复制项目工作区索引"
|
||||||
|
$srcWorkspace = Join-Path $sourceRoaming "User\workspaceStorage"
|
||||||
|
$dstWorkspace = Join-Path $env:APPDATA "Cursor\User\workspaceStorage"
|
||||||
|
Copy-Tree -Source $srcWorkspace -Destination $dstWorkspace -Quiet
|
||||||
|
if (Test-Path -LiteralPath $srcWorkspace) {
|
||||||
|
Get-ChildItem -LiteralPath $srcWorkspace -Recurse -File -Force | Where-Object {
|
||||||
|
$_.Name -in @("state.vscdb", "state.vscdb-wal", "state.vscdb-shm", "workspace.json")
|
||||||
|
} | ForEach-Object {
|
||||||
|
$relative = $_.FullName.Substring($srcWorkspace.Length).TrimStart("\")
|
||||||
|
$target = Join-Path $dstWorkspace $relative
|
||||||
|
New-Item -ItemType Directory -Force -Path (Split-Path -Parent $target) | Out-Null
|
||||||
|
Copy-Item -LiteralPath $_.FullName -Destination $target -Force
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Copy-Tree -Source (Join-Path $sourceRoaming "glassMultiRootWorkspaces") -Destination (Join-Path $env:APPDATA "Cursor\glassMultiRootWorkspaces") -Quiet
|
||||||
|
Copy-FileForce -Source (Join-Path $sourceRoaming "User\settings.json") -Destination (Join-Path $env:APPDATA "Cursor\User\settings.json")
|
||||||
|
Copy-Tree -Source (Join-Path $sourceRoaming "User\snippets") -Destination (Join-Path $env:APPDATA "Cursor\User\snippets") -Quiet
|
||||||
|
|
||||||
|
Write-Step "复制项目转录和 Agent 数据"
|
||||||
|
Copy-Tree -Source (Join-Path $sourceDotCursor "projects") -Destination (Join-Path $env:USERPROFILE ".cursor\projects") -Quiet
|
||||||
|
Copy-Tree -Source (Join-Path $sourceDotCursor "plans") -Destination (Join-Path $env:USERPROFILE ".cursor\plans") -Quiet
|
||||||
|
Copy-Tree -Source (Join-Path $sourceLocal "AgentStores") -Destination (Join-Path $env:LOCALAPPDATA "Cursor\AgentStores") -Quiet
|
||||||
|
|
||||||
|
Write-Step "复制 MCP、Skills、规则、插件和扩展"
|
||||||
|
Copy-FileForce -Source (Join-Path $sourceDotCursor "mcp.json") -Destination (Join-Path $env:USERPROFILE ".cursor\mcp.json")
|
||||||
|
Copy-FileForce -Source (Join-Path $sourceDotCursor "argv.json") -Destination (Join-Path $env:USERPROFILE ".cursor\argv.json")
|
||||||
|
Copy-FileForce -Source (Join-Path $sourceDotCursor "cli-config.json") -Destination (Join-Path $env:USERPROFILE ".cursor\cli-config.json")
|
||||||
|
Copy-Tree -Source (Join-Path $sourceDotCursor "rules") -Destination (Join-Path $env:USERPROFILE ".cursor\rules") -Quiet
|
||||||
|
Copy-Tree -Source (Join-Path $sourceDotCursor "skills-cursor") -Destination (Join-Path $env:USERPROFILE ".cursor\skills-cursor") -Quiet
|
||||||
|
Copy-Tree -Source (Join-Path $sourceDotCursor "plugins") -Destination (Join-Path $env:USERPROFILE ".cursor\plugins") -Quiet
|
||||||
|
Copy-Tree -Source (Join-Path $sourceDotCursor "extensions") -Destination (Join-Path $env:USERPROFILE ".cursor\extensions") -Quiet
|
||||||
|
Copy-Tree -Source $sourceAgents -Destination (Join-Path $env:USERPROFILE ".agents") -Quiet
|
||||||
|
|
||||||
|
if (Test-Path -LiteralPath $incoming) {
|
||||||
|
Remove-Item -LiteralPath $incoming -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Step "完成"
|
||||||
|
Write-Host "快照保留在: $snapshot"
|
||||||
|
Write-Host "现在可以重新打开 Cursor 并登录。"
|
||||||
|
Write-Host "用原来的路径打开项目后,旧对话会挂回该项目。说明见 Cursor迁移对话记录.md"
|
||||||
|
Write-Host "若要退回覆盖前的聊天库,运行 Rollback-CursorRestore.bat"
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
@echo off
|
||||||
|
chcp 65001 >nul
|
||||||
|
cd /d "%~dp0"
|
||||||
|
echo 这是回滚,不是迁移。要把 U 盘数据迁回来,请运行 Restore-CursorFromUsb.bat
|
||||||
|
echo.
|
||||||
|
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0Restore-CursorFromUsb.ps1" -Rollback
|
||||||
|
echo.
|
||||||
|
pause
|
||||||
+133
@@ -0,0 +1,133 @@
|
|||||||
|
# 重装机器交接:聊天恢复与开发环境
|
||||||
|
|
||||||
|
日期:2026-12-06
|
||||||
|
来源机器:DESKTOP-NIXEVOL,用户 Administrator
|
||||||
|
新机器备份根目录:**`G:\Users\Administrator`**
|
||||||
|
|
||||||
|
这台机器上的旧备份曾是 `F:\Cursor\Users\Administrator`。新机器上用户目录备份直接在 `G:\Users\Administrator`,不再套一层 `F:\Cursor`。`Restore-CursorFromUsb.ps1` 的默认 `-BackupRoot` 已改成这个路径;如果传入的目录自身就含有 `AppData\Roaming\Cursor\User\globalStorage\state.vscdb`,脚本会把它当作备份用户目录。
|
||||||
|
|
||||||
|
本目录不含密码、Token、API Key。MCP 密钥仍在原机 `C:\Users\Administrator\.cursor\mcp.json`,不要把密文抄进这份交接。
|
||||||
|
|
||||||
|
## 新机器上怎么用这份材料
|
||||||
|
|
||||||
|
1. 把整个 `E:\code\AIChatMover` 拷到新机器同一路径,或至少拷走 `迁移导出`、`Restore-CursorFromUsb.ps1`、`Restore-CursorFromUsb.bat`、`Rollback-CursorRestore.bat`、`Restart-Cursor.ps1`、`Restart-Cursor.bat`。
|
||||||
|
2. 项目记忆压缩包在本项目 `aidocs\`(若已下载)。全局规则、安装习惯和本会话事实写在本文。
|
||||||
|
3. 原始聊天记录在 `迁移导出\聊天记录\`。
|
||||||
|
4. Cursor 聊天恢复:完全退出 Cursor 后运行 `Restore-CursorFromUsb.bat`。备份必须是 `G:\Users\Administrator`。
|
||||||
|
5. PI-Desktop 聊天不在 Cursor 库里,见下文单独恢复。
|
||||||
|
|
||||||
|
## 安装规则(必须遵守)
|
||||||
|
|
||||||
|
1. 用 winget 和 Scoop 都查版本,**哪个新用哪个**。版本相同优先 **winget**。
|
||||||
|
2. 32 位和 64 位都优先装到 `D:\Program Files\<软件名>`。
|
||||||
|
3. 安装程序不能接受路径里的空格时,改到 `D:\SoftwareSpace\<软件名>`。
|
||||||
|
4. 只有完全不能指定目录时,才用安装程序默认位置。
|
||||||
|
5. Scoop 根目录固定为 `D:\SoftwareSpace\scoop`。不要用 `D:\Program Files\scoop` 或 `scoop-global`。不用 `scoop install -g`。
|
||||||
|
6. winget 和 Scoop 安装前,如果 D 盘已有该软件的旧数据,先删除再安装。
|
||||||
|
7. 这台电脑不安装 Qt,不为 Qt 准备 `D:\Qt`。以后界面可能用 FLTK、Qt 或 Tauri,但当前明确不装 Qt。
|
||||||
|
8. 库和包缓存放在 D 盘、挂在对应安装目录下,并起清楚的目录名。不要落到 C 盘用户目录。
|
||||||
|
9. 若同一软件的正式安装在 `D:\SoftwareSpace`,则 `D:\Program Files` 下同名的另一份是冗余,可以删除。反过来,正式程序在 `D:\Program Files` 时,`D:\SoftwareSpace` 里的缓存不是第二份程序,不能删。Go 就是后者:程序在 `D:\Program Files\Go`,缓存在 `D:\SoftwareSpace\go`。
|
||||||
|
10. 需要重启 Cursor 时运行 `Restart-Cursor.bat`。它会另开独立进程再关掉并重新打开 Cursor。
|
||||||
|
11. 交流、注释、提交信息用简体中文。提交格式 `type: 中文一句话`。type 只用 feat、fix、refactor、style、docs、chore、revert。
|
||||||
|
12. MemRelay 可用时是唯一记忆库。凭据只放密码库,普通记忆和项目文件不写密文。
|
||||||
|
13. 软件代理端口沿用 `http://127.0.0.1:7897`(Clash / Mihomo)。npm、pnpm、pip、uv、Go 的代理配置没有写入各自的配置文件,下载时只用当次进程的环境变量。
|
||||||
|
14. Docker 尚未安装。三种方式:Docker Desktop + WSL2;只在 WSL2 里装 Docker Engine;本机只装客户端并连远程引擎。第三种不需要 WSL,本机可以执行 docker 命令,但容器在远程机器上。用户暂定先不装。
|
||||||
|
|
||||||
|
## 已安装环境
|
||||||
|
|
||||||
|
| 软件 | 版本 | 位置 | 说明 |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| Git | 2.56.1.windows.1 | `D:\Program Files\Git` | 系统 Path 含 `cmd` |
|
||||||
|
| Scoop | 0.6.0 | `D:\SoftwareSpace\scoop` | 系统变量 `SCOOP`。只用来查版本和装 winget 没有的包 |
|
||||||
|
| NVM for Windows | 2.0.1 | `C:\Users\Administrator\AppData\Local\Author Software\nvm` | 安装器拒绝自定义程序目录 |
|
||||||
|
| Node | 26.14.0 默认;27.0.0-alpha.0.2.0 | `D:\SoftwareSpace\nodejs` | nvm 的 `root`。最新正式版就是 26.14.0 LTS;27 只有 alpha |
|
||||||
|
| npm | 11.21.3 | 随 Node | 缓存 `D:\SoftwareSpace\nodejs\npm-cache` |
|
||||||
|
| pnpm | 12.26.0 | 随默认 Node | 仓库 `...\pnpm-store`,缓存 `...\pnpm-cache`。配置文件约 90 字节在 `%LOCALAPPDATA%\pnpm\config\config.yaml` |
|
||||||
|
| uv | 0.13.13 | `D:\SoftwareSpace\uv` | 解释器 `...\python`,启动器 `...\bin`,缓存 `...\cache` |
|
||||||
|
| Python | 3.15.2 默认;3.13.18 | 由 uv 管理 | `python` / `python3` 是 3.15.2。pip 26.3 用 `python -m pip`,没有单独的 `pip.exe`。pip 缓存 `D:\SoftwareSpace\uv\pip-cache` |
|
||||||
|
| Temurin JDK | 25.0.5.1 LTS | `D:\Program Files\Java\jdk-25` | 不需要单独的 JRE。`JAVA_HOME` 指向这里。名称里的 Eclipse 是基金会,不是 Eclipse IDE |
|
||||||
|
| Go | 1.27.4 | `D:\Program Files\Go` | 无单独版本管理器,用 `GOTOOLCHAIN=auto`。额外工具链会进模块缓存 |
|
||||||
|
| Go 缓存 | | `D:\SoftwareSpace\go` | `GOPATH`、`build-cache`、`mod-cache` |
|
||||||
|
| rustup | 1.29.3 | `D:\SoftwareSpace\rustup` | `RUSTUP_HOME` |
|
||||||
|
| Rust | 1.100.1 stable MSVC | `D:\SoftwareSpace\cargo` | `CARGO_HOME`。crate 缓存在 `cargo\registry`。未设 `CARGO_TARGET_DIR` |
|
||||||
|
| VS 生成工具 | 2026 / 18.12.1 | `D:\Program Files\Microsoft Visual Studio\2026\BuildTools` | MSVC 14.52.37025。选 MSVC 是为了以后的 Tauri、Qt、FLTK。不要装 GNU 作为默认 |
|
||||||
|
| 7-Zip | 26.06 | `D:\Program Files\7-Zip` | |
|
||||||
|
| Zig | 0.17.1 | `D:\Program Files\Zig` | 已从 `D:\SoftwareSpace\zig` 挪过来,旧目录已删 |
|
||||||
|
| apktool | 3.0.3 | `D:\Program Files\apktool` | REA 要求 2.7.0 或更新。已离开 Scoop |
|
||||||
|
| JADX | 1.5.6 | `D:\Program Files\jadx` | REA 7.0.0 写明配套 1.5.6,不要改成 winget 上的 1.5.7 |
|
||||||
|
| jadx-headless-mcp | 0.8.0 | `D:\Program Files\jadx\jadx-headless-mcp-0.8.0-all.jar` | REA 实际调用的是这个 JAR |
|
||||||
|
| Everything | 1.4.1.1032 | `D:\Program Files\Everything` | 稳定版。1.4 没有自带 MCP;1.5 插件才能在进程内开 MCP |
|
||||||
|
| LocalSend | 1.19.0 | `D:\Program Files\LocalSend` | 图形版。Scoop 只有 CLI |
|
||||||
|
| Android platform-tools | 旧文件仍在 | `D:\Program Files\Android\platform-tools` | 已在系统 Path。这次没有重装 |
|
||||||
|
| Scrcpy | 旧文件仍在 | `D:\Program Files\Scrcpy` | 已加入系统 Path。这次没有重装 |
|
||||||
|
|
||||||
|
系统 Path 里还应有:`D:\SoftwareSpace\cargo\bin`、`D:\SoftwareSpace\uv\bin`、`D:\SoftwareSpace\uv`、`D:\SoftwareSpace\scoop\shims`、nvm 与 `.nodejs`、`D:\SoftwareSpace\nodejs\v26.14.0`。
|
||||||
|
|
||||||
|
REA npm 包 `rea-agents` 为 7.0.0,npm 上没有更新。MCP 里 `JAVA_HOME`、`REA_APKTOOL_COMMAND`、`REA_JADX_MCP_JAR` 已指向上述新路径。Ghidra 目录仍是旧路径 `C:\Users\Administrator\AppData\Local\rea-engines\ghidra_12.1.4_PUBLIC`,这次没有重装。
|
||||||
|
|
||||||
|
## 还没装
|
||||||
|
|
||||||
|
- WSL2 发行版、Docker Desktop。用户决定先不装。第三种「本机客户端连远程引擎」可以在本机执行 docker 命令,不需要 WSL。
|
||||||
|
- Qt。
|
||||||
|
- 第二套 JDK 或 mise。
|
||||||
|
- IDEA 仍是旧目录 `D:\Program Files\JetBrains\IntelliJ IDEA 2026.2.2`,没有重装,也不在 Path 里。
|
||||||
|
- 完整 Android SDK。现在只有旧的 platform-tools。
|
||||||
|
- CMake、WebView2 未单独安装。做 FLTK 源码编译或 Tauri 时再补。
|
||||||
|
|
||||||
|
## Cursor 聊天恢复
|
||||||
|
|
||||||
|
脚本:`Restore-CursorFromUsb.ps1`,双击 `Restore-CursorFromUsb.bat`。
|
||||||
|
|
||||||
|
新机器:
|
||||||
|
|
||||||
|
```bat
|
||||||
|
powershell -ExecutionPolicy Bypass -File Restore-CursorFromUsb.ps1 -BackupRoot "G:\Users\Administrator"
|
||||||
|
```
|
||||||
|
|
||||||
|
不传参数时默认也是这个路径。完全退出 Cursor 再运行。脚本会先把当前库快照到 `C:\CursorMigrationBackup`。回滚用 `Rollback-CursorRestore.bat`。
|
||||||
|
|
||||||
|
恢复范围仍是:`state.vscdb`、`conversation-search.db`、`workspaceStorage`、`.cursor\projects`、`.cursor\plans`、AgentStores、`mcp.json`、skills、rules、plugins、extensions、`.agents`、用户设置。不复制缓存、日志、`machineid`。重装后 Windows 加密密钥已换,登录和 OAuth MCP 要重新授权。
|
||||||
|
|
||||||
|
## PI-Desktop 聊天恢复
|
||||||
|
|
||||||
|
聊天不在 Cursor 数据库里,在用户目录 `.pi-desktop`。
|
||||||
|
|
||||||
|
备份:`G:\Users\Administrator\.pi-desktop`
|
||||||
|
目标:`C:\Users\Administrator\.pi-desktop`
|
||||||
|
|
||||||
|
两边 `pi.sqlite` 的 `user_version` 必须一致再覆盖。本机这次两边都是 36。备份有 8 个会话、2335 条消息。要复制:
|
||||||
|
|
||||||
|
- `pi.sqlite`
|
||||||
|
- `sessions`
|
||||||
|
- `attachments`
|
||||||
|
- `review-changes`
|
||||||
|
|
||||||
|
不要覆盖 `secrets`。先完全退出 PI-Desktop。覆盖前把目标上现有的 `pi.sqlite` 改名为 `pi.sqlite.before-restore`。
|
||||||
|
|
||||||
|
本机已经从旧路径 `F:\Cursor\Users\Administrator\.pi-desktop` 恢复过一次。新机器要改用 `G:\Users\Administrator\.pi-desktop`。
|
||||||
|
|
||||||
|
## 本会话聊了什么
|
||||||
|
|
||||||
|
完整原文在 `聊天记录\` 下的两个 jsonl。摘要:
|
||||||
|
|
||||||
|
1. 从 U 盘备份迁回 Cursor 聊天、MCP、Skills。脚本写成后由用户退出 Cursor 执行。核对 `state.vscdb` 约 7.4 GB,341 个会话。
|
||||||
|
2. Origin MCP 失败是因为重装后登录令牌无效,服务端要求退出再登录。原生 Windows 上 Origin 仓库命令行仍不支持。
|
||||||
|
3. 按记忆和 D 盘残留列出旧开发环境,确认那些是旧系统残留,要删掉重装。
|
||||||
|
4. winget 已随系统可用,版本 v1.30.310。
|
||||||
|
5. 删掉旧的 `D:\Program Files\scoop` 和 `scoop-global`。
|
||||||
|
6. 订立安装目录规则,并几次收紧:不装 Qt;Scoop 根目录 `D:\SoftwareSpace\scoop`;版本新者优先,相同用 winget;安装前删 D 盘旧数据;缓存放 D 盘。
|
||||||
|
7. 装 Git、Scoop、nvm、Node、uv、Python、JDK 25、VS 2026 C++ 生成工具、Rust MSVC、Go、7-Zip、Zig、apktool、JADX、Everything、LocalSend。
|
||||||
|
8. 误把 VS 2022 装向 `D:\Program`,已停止并删除该残留。正式的是 VS 2026。
|
||||||
|
9. 缓存都用真实下载核对过:Cargo registry、npm、pnpm、pip、Go module/build cache 都在 D 盘。
|
||||||
|
10. 配置 daro MCP。配置 Termius 仓库的 `safe.directory`。cmd 里必须用双引号,单引号不会保护空格。
|
||||||
|
11. 讨论过 Docker 的三种装法,用户决定先不装。
|
||||||
|
|
||||||
|
## 习惯
|
||||||
|
|
||||||
|
- 先给结论,再给依据。能做完并验证的直接做。
|
||||||
|
- 中文。KISS。不把产品界面写成开发说明。
|
||||||
|
- 防过度防御,入口校验一次,不提前抽象。
|
||||||
|
- 每个可独立验证的改动完成后提交,格式 `type: 中文一句话`。有远端则 fetch、必要时 rebase 再推送,不使用 force。
|
||||||
|
- 多 Agent 时每个 Agent 用仓库内 `Temp/worktrees/<任务名>`,合并后删除。
|
||||||
|
- PowerShell 5.1 脚本含中文时要 UTF-8 BOM,或脚本只写 ASCII、中文放 UTF-8 文件。
|
||||||
|
- 重启 Cursor 用本项目的 `Restart-Cursor.bat`。
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
# 全局习惯与规则
|
||||||
|
|
||||||
|
这些是 MemRelay 里现行的全局规则和偏好,供新机器上的会话直接继承。安装目录的最新版本以 `交接说明.md` 为准,它覆盖了更早的「软件一律进 D:\Program Files、Qt 放 D:\Qt\App」。
|
||||||
|
|
||||||
|
## 安装位置(2026-12-06 现行)
|
||||||
|
|
||||||
|
这台 Windows 不使用 Qt 做开发,不要安装 Qt。
|
||||||
|
|
||||||
|
用 winget 或 Scoop 安装工具时,32 位和 64 位都按同一顺序:
|
||||||
|
|
||||||
|
1. 先用两边查版本,哪个更新就用哪个。版本相同优先 winget。
|
||||||
|
2. 优先装到 `D:\Program Files\<软件名>`。不要装到 C 盘。
|
||||||
|
3. 不能接受路径空格时,装到 `D:\SoftwareSpace\<软件名>`。
|
||||||
|
4. 完全不能指定目录时,才用安装程序默认位置。
|
||||||
|
5. Scoop 根目录固定为 `D:\SoftwareSpace\scoop`。不要用 scoop、scoop-global 把工具堆在一起,也不要用 `scoop install -g`。
|
||||||
|
6. 安装前如果 D 盘已有该软件旧数据,先删除再安装。
|
||||||
|
7. 若正式安装在 `D:\SoftwareSpace`,`D:\Program Files` 下同名的另一份程序可以删。缓存目录不是第二份程序。
|
||||||
|
8. winget 可移植包不要留在 `C:\Program Files\WinGet\Packages`。
|
||||||
|
|
||||||
|
## 开发实施
|
||||||
|
|
||||||
|
- 遵循 KISS 与 YAGNI,用最简单且正确的实现。
|
||||||
|
- 优先复用已有框架和约定,不为假设中的未来需求加依赖。
|
||||||
|
- 修改范围与当前目标一致。完成前清理临时内容和无用代码。
|
||||||
|
- 前端以真实工作流、桌面可用性、信息层级和无重叠为验收标准。
|
||||||
|
- 界面不要用辅助标签去解释已经能看懂的布局。错误、警告和关键状态直接展示。
|
||||||
|
- Web 表单优先「标题在左、控件在右」。较大的多行内容「标题在上、内容在下」。
|
||||||
|
- 页面顶部标题在滚动时保持可见,操作放在标题右侧。弹窗的保存、取消固定显示。
|
||||||
|
- 长内容在控件内部滚动,不要让整个页面承担滚动。
|
||||||
|
- 产品界面只写给使用者看的内容。不要把聊天记录、实现说明、调试信息写进产品页面。
|
||||||
|
|
||||||
|
## 防过度设计
|
||||||
|
|
||||||
|
1. 几乎不会发生的边界,先讲清概率,经用户确认再加防护。
|
||||||
|
2. 外部数据只在边界校验一次。
|
||||||
|
3. 只使用一次的逻辑就近内联。
|
||||||
|
4. 非必要不用 try/catch。一个函数能写清楚就不要拆开。
|
||||||
|
|
||||||
|
## Git
|
||||||
|
|
||||||
|
- 每个可独立验证的功能完成并验证后立即提交。
|
||||||
|
- 格式:`type: 中文一句话`。type 只用 feat、fix、refactor、style、docs、chore、revert。
|
||||||
|
- 有远端时提交后推送。推送前 fetch;远端有新提交则先 rebase。被拒绝时先查原因。未经明确确认不用 `--force` 或 `--force-with-lease`。
|
||||||
|
- 功能分支可集成且目标明确时,rebase 到目标分支后 fast-forward 合并。有保护分支、评审或 CI 时改走 PR。
|
||||||
|
- 不提交秘密值、`data/`、`config.json`、Temp、抓包文件。没有改动不做空提交。
|
||||||
|
|
||||||
|
## 记忆
|
||||||
|
|
||||||
|
- MemRelay 可用时它是唯一记忆存储,不维护本地 aidocs 作为第二份记忆。
|
||||||
|
- 会话开始先看能力、解析项目、读上下文和检查点。
|
||||||
|
- 只有 MemRelay 不可用时,才把待同步内容暂存到 `aidocs/project_context.md`,并保证 `aidocs/` 被 gitignore。
|
||||||
|
- 不把猜测、临时数据、未裁定冲突、闲聊和密文写入记忆。
|
||||||
|
- 未设置项目目录时,不主动创建 MemRelay 项目。
|
||||||
|
|
||||||
|
## 协作
|
||||||
|
|
||||||
|
- 默认中文。
|
||||||
|
- 当前开发环境是 Windows。命令和路径要能在 Windows 上跑。
|
||||||
|
- 先理解现有项目再改。能独立完成的直接做完并验证。
|
||||||
|
- 答题时先给已经确定的答案。
|
||||||
|
- 多 Agent 开发时,每个 Agent 使用仓库内已被 gitignore 的 `Temp/worktrees/<任务名>`。完成后 rebase 再 fast-forward 合并,然后删除 worktree。
|
||||||
|
|
||||||
|
## PowerShell
|
||||||
|
|
||||||
|
- Windows PowerShell 5.1 按系统代码页解析无 BOM 的 ps1。含中文的脚本要加 UTF-8 BOM,或脚本只写 ASCII、中文放 UTF-8 文件。
|
||||||
|
- 5.1 的 `Add-Content` / `Out-File` 默认不是 UTF-8。
|
||||||
|
- 不要用 `Select-Object -First` 截断仍在写文件的上游。
|
||||||
|
|
||||||
|
## 其他已确认事实
|
||||||
|
|
||||||
|
- 软件安装优先 D 盘,避免占满系统盘。
|
||||||
|
- Docker Hub 需要代理时,Docker Desktop 用 Manual,HTTP/HTTPS 为 `http://127.0.0.1:7897`。换机器时以实际端口为准。
|
||||||
|
- 协作规则插件装在 `%USERPROFILE%\.cursor\plugins\local\collaboration-rules\`。
|
||||||
|
- PotPlayer:`D:\Program Files\DAUM\PotPlayer\PotPlayerMini64.exe`。IPTV 项目在 `E:\code\IPTV`,启动 `E:\code\IPTV\启动Web界面.bat`,页面是 http://127.0.0.1:8787 。
|
||||||
Reference in New Issue
Block a user