From 31f28a2c183f6ead50941027632d7ab64b7bb2d4 Mon Sep 17 00:00:00 2001 From: simosmik Date: Tue, 14 Apr 2026 21:58:53 +0000 Subject: [PATCH] chore: remove unused route (migrated to providers already) --- server/routes/cursor.js | 218 ---------------------------------------- 1 file changed, 218 deletions(-) diff --git a/server/routes/cursor.js b/server/routes/cursor.js index 02269e45..7e395023 100644 --- a/server/routes/cursor.js +++ b/server/routes/cursor.js @@ -2,7 +2,6 @@ import express from 'express'; import { promises as fs } from 'fs'; import path from 'path'; import os from 'os'; -import { spawn } from 'child_process'; import sqlite3 from 'sqlite3'; import { open } from 'sqlite'; import crypto from 'crypto'; @@ -578,221 +577,4 @@ router.get('/sessions', async (req, res) => { }); } }); - -// GET /api/cursor/sessions/:sessionId - Get specific Cursor session from SQLite -router.get('/sessions/:sessionId', async (req, res) => { - try { - const { sessionId } = req.params; - const { projectPath } = req.query; - - // Calculate cwdID hash for the project path - const cwdId = crypto.createHash('md5').update(projectPath || process.cwd()).digest('hex'); - const storeDbPath = path.join(os.homedir(), '.cursor', 'chats', cwdId, sessionId, 'store.db'); - - - // Open SQLite database - const db = await open({ - filename: storeDbPath, - driver: sqlite3.Database, - mode: sqlite3.OPEN_READONLY - }); - - // Get all blobs to build the DAG structure - const allBlobs = await db.all(` - SELECT rowid, id, data FROM blobs - `); - - // Build the DAG structure from parent-child relationships - const blobMap = new Map(); // id -> blob data - const parentRefs = new Map(); // blob id -> [parent blob ids] - const childRefs = new Map(); // blob id -> [child blob ids] - const jsonBlobs = []; // Clean JSON messages - - for (const blob of allBlobs) { - blobMap.set(blob.id, blob); - - // Check if this is a JSON blob (actual message) or protobuf (DAG structure) - if (blob.data && blob.data[0] === 0x7B) { // Starts with '{' - JSON blob - try { - const parsed = JSON.parse(blob.data.toString('utf8')); - jsonBlobs.push({ ...blob, parsed }); - } catch (e) { - console.log('Failed to parse JSON blob:', blob.rowid); - } - } else if (blob.data) { // Protobuf blob - extract parent references - const parents = []; - let i = 0; - - // Scan for parent references (0x0A 0x20 followed by 32-byte hash) - while (i < blob.data.length - 33) { - if (blob.data[i] === 0x0A && blob.data[i+1] === 0x20) { - const parentHash = blob.data.slice(i+2, i+34).toString('hex'); - if (blobMap.has(parentHash)) { - parents.push(parentHash); - } - i += 34; - } else { - i++; - } - } - - if (parents.length > 0) { - parentRefs.set(blob.id, parents); - // Update child references - for (const parentId of parents) { - if (!childRefs.has(parentId)) { - childRefs.set(parentId, []); - } - childRefs.get(parentId).push(blob.id); - } - } - } - } - - // Perform topological sort to get chronological order - const visited = new Set(); - const sorted = []; - - // DFS-based topological sort - function visit(nodeId) { - if (visited.has(nodeId)) return; - visited.add(nodeId); - - // Visit all parents first (dependencies) - const parents = parentRefs.get(nodeId) || []; - for (const parentId of parents) { - visit(parentId); - } - - // Add this node after all its parents - const blob = blobMap.get(nodeId); - if (blob) { - sorted.push(blob); - } - } - - // Start with nodes that have no parents (roots) - for (const blob of allBlobs) { - if (!parentRefs.has(blob.id)) { - visit(blob.id); - } - } - - // Visit any remaining nodes (disconnected components) - for (const blob of allBlobs) { - visit(blob.id); - } - - // Now extract JSON messages in the order they appear in the sorted DAG - const messageOrder = new Map(); // JSON blob id -> order index - let orderIndex = 0; - - for (const blob of sorted) { - // Check if this blob references any JSON messages - if (blob.data && blob.data[0] !== 0x7B) { // Protobuf blob - // Look for JSON blob references - for (const jsonBlob of jsonBlobs) { - try { - const jsonIdBytes = Buffer.from(jsonBlob.id, 'hex'); - if (blob.data.includes(jsonIdBytes)) { - if (!messageOrder.has(jsonBlob.id)) { - messageOrder.set(jsonBlob.id, orderIndex++); - } - } - } catch (e) { - // Skip if can't convert ID - } - } - } - } - - // Sort JSON blobs by their appearance order in the DAG - const sortedJsonBlobs = jsonBlobs.sort((a, b) => { - const orderA = messageOrder.get(a.id) ?? Number.MAX_SAFE_INTEGER; - const orderB = messageOrder.get(b.id) ?? Number.MAX_SAFE_INTEGER; - if (orderA !== orderB) return orderA - orderB; - // Fallback to rowid if not in order map - return a.rowid - b.rowid; - }); - - // Use sorted JSON blobs - const blobs = sortedJsonBlobs.map((blob, idx) => ({ - ...blob, - sequence_num: idx + 1, - original_rowid: blob.rowid - })); - - // Get metadata from meta table - const metaRows = await db.all(` - SELECT key, value FROM meta - `); - - // Parse metadata - let metadata = {}; - for (const row of metaRows) { - if (row.value) { - try { - // Try to decode as hex-encoded JSON - const hexMatch = row.value.toString().match(/^[0-9a-fA-F]+$/); - if (hexMatch) { - const jsonStr = Buffer.from(row.value, 'hex').toString('utf8'); - metadata[row.key] = JSON.parse(jsonStr); - } else { - metadata[row.key] = row.value.toString(); - } - } catch (e) { - metadata[row.key] = row.value.toString(); - } - } - } - - // Extract messages from sorted JSON blobs - const messages = []; - for (const blob of blobs) { - try { - // We already parsed JSON blobs earlier - const parsed = blob.parsed; - - if (parsed) { - // Filter out ONLY system messages at the server level - // Check both direct role and nested message.role - const role = parsed?.role || parsed?.message?.role; - if (role === 'system') { - continue; // Skip only system messages - } - messages.push({ - id: blob.id, - sequence: blob.sequence_num, - rowid: blob.original_rowid, - content: parsed - }); - } - } catch (e) { - // Skip blobs that cause errors - console.log(`Skipping blob ${blob.id}: ${e.message}`); - } - } - - await db.close(); - - res.json({ - success: true, - session: { - id: sessionId, - projectPath: projectPath, - messages: messages, - metadata: metadata, - cwdId: cwdId - } - }); - - } catch (error) { - console.error('Error reading Cursor session:', error); - res.status(500).json({ - error: 'Failed to read Cursor session', - details: error.message - }); - } -}); - export default router; \ No newline at end of file