dr-claw 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1380 -0
- package/NOTICE +17 -0
- package/README.md +875 -0
- package/README.zh-CN.md +857 -0
- package/dist/api-docs.html +878 -0
- package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/assets/_basePickBy-C0n1uo4u.js +1 -0
- package/dist/assets/_baseUniq-BRNmhFkc.js +1 -0
- package/dist/assets/arc-DOMBmC_A.js +1 -0
- package/dist/assets/architectureDiagram-VXUJARFQ-CtMWglbD.js +36 -0
- package/dist/assets/blockDiagram-VD42YOAC-DK_gTkJy.js +122 -0
- package/dist/assets/c4Diagram-YG6GDRKO-DrDAvsn7.js +10 -0
- package/dist/assets/channel-BFOE7OyC.js +1 -0
- package/dist/assets/chunk-4BX2VUAB-CGbhdZcN.js +1 -0
- package/dist/assets/chunk-55IACEB6-sGeFSxen.js +1 -0
- package/dist/assets/chunk-B4BG7PRW-RxgHAU_P.js +165 -0
- package/dist/assets/chunk-DI55MBZ5-CvHUXZrx.js +220 -0
- package/dist/assets/chunk-FMBD7UC4-Sn7cXVNU.js +15 -0
- package/dist/assets/chunk-QN33PNHL-bDKOHppN.js +1 -0
- package/dist/assets/chunk-QZHKN3VN-B9kN5LGm.js +1 -0
- package/dist/assets/chunk-TZMSLE5B-CCBe6len.js +1 -0
- package/dist/assets/classDiagram-2ON5EDUG-DQoMNYlY.js +1 -0
- package/dist/assets/classDiagram-v2-WZHVMYZB-DQoMNYlY.js +1 -0
- package/dist/assets/clone-BulQSblH.js +1 -0
- package/dist/assets/cose-bilkent-S5V4N54A-r6sLiHBW.js +1 -0
- package/dist/assets/cytoscape.esm-5J0xJHOV.js +321 -0
- package/dist/assets/dagre-6UL2VRFP-AbsaR1Oa.js +4 -0
- package/dist/assets/defaultLocale-DX6XiGOO.js +1 -0
- package/dist/assets/diagram-PSM6KHXK-DjCvdUyy.js +24 -0
- package/dist/assets/diagram-QEK2KX5R-CqiocXkH.js +43 -0
- package/dist/assets/diagram-S2PKOQOG-D5ALeoII.js +24 -0
- package/dist/assets/erDiagram-Q2GNP2WA-C1AeOsiz.js +60 -0
- package/dist/assets/flowDiagram-NV44I4VS-C98ve_DO.js +162 -0
- package/dist/assets/ganttDiagram-JELNMOA3-3zdLvcxD.js +267 -0
- package/dist/assets/gitGraphDiagram-V2S2FVAM-nDuDMsHh.js +65 -0
- package/dist/assets/graph-Blm-emkR.js +1 -0
- package/dist/assets/index-B8Yutsnm.css +1 -0
- package/dist/assets/index-Cf6gyhc3.js +654 -0
- package/dist/assets/infoDiagram-HS3SLOUP-CmzE3q0R.js +2 -0
- package/dist/assets/init-Gi6I4Gst.js +1 -0
- package/dist/assets/journeyDiagram-XKPGCS4Q-CYaW7LrP.js +139 -0
- package/dist/assets/kanban-definition-3W4ZIXB7-mkmW7p0j.js +89 -0
- package/dist/assets/layout-Ct2kFIId.js +1 -0
- package/dist/assets/linear-CKG9EwIJ.js +1 -0
- package/dist/assets/mermaid.core-CaKcUnnd.js +250 -0
- package/dist/assets/mindmap-definition-VGOIOE7T-Bct-pYin.js +68 -0
- package/dist/assets/ordinal-Cboi1Yqb.js +1 -0
- package/dist/assets/pieDiagram-ADFJNKIX-C8wFD4Jr.js +30 -0
- package/dist/assets/quadrantDiagram-AYHSOK5B-CuiE_f46.js +7 -0
- package/dist/assets/requirementDiagram-UZGBJVZJ-C4v1CqU8.js +64 -0
- package/dist/assets/sankeyDiagram-TZEHDZUN-keAqqs-Y.js +10 -0
- package/dist/assets/sequenceDiagram-WL72ISMW-ClNbvKTB.js +145 -0
- package/dist/assets/stateDiagram-FKZM4ZOC-D8We-2vq.js +1 -0
- package/dist/assets/stateDiagram-v2-4FDKWEC3-BUURfjrE.js +1 -0
- package/dist/assets/timeline-definition-IT6M3QCI-DsvEMT5T.js +61 -0
- package/dist/assets/treemap-GDKQZRPO-TJrzN7Bj.js +162 -0
- package/dist/assets/vendor-codemirror-ansM-eig.js +33 -0
- package/dist/assets/vendor-react-BWF6YQQ3.js +8 -0
- package/dist/assets/vendor-xterm-DfcmCpbH.js +66 -0
- package/dist/assets/xychartDiagram-PRI3JC2R-BdATmY5F.js +7 -0
- package/dist/clear-cache.html +85 -0
- package/dist/convert-icons.md +53 -0
- package/dist/dr-claw.png +0 -0
- package/dist/favicon.png +0 -0
- package/dist/generate-icons.js +49 -0
- package/dist/icons/claude-ai-icon.svg +1 -0
- package/dist/icons/codex-white.svg +3 -0
- package/dist/icons/codex.svg +3 -0
- package/dist/icons/cursor-white.svg +12 -0
- package/dist/icons/cursor.svg +1 -0
- package/dist/icons/file.svg +16997 -0
- package/dist/icons/generate-icons.md +19 -0
- package/dist/icons/icon-128x128.png +0 -0
- package/dist/icons/icon-144x144.png +0 -0
- package/dist/icons/icon-152x152.png +0 -0
- package/dist/icons/icon-192x192.png +0 -0
- package/dist/icons/icon-384x384.png +0 -0
- package/dist/icons/icon-512x512.png +0 -0
- package/dist/icons/icon-72x72.png +0 -0
- package/dist/icons/icon-96x96.png +0 -0
- package/dist/icons/news/arxiv.svg +1 -0
- package/dist/icons/news/huggingface.svg +8 -0
- package/dist/icons/news/x-black.png +0 -0
- package/dist/icons/news/x-white.png +0 -0
- package/dist/icons/news/xiaohongshu.png +0 -0
- package/dist/index.html +51 -0
- package/dist/leveraged-cognition.png +0 -0
- package/dist/manifest.json +61 -0
- package/dist/screenshots/chat.png +0 -0
- package/dist/screenshots/new_claw.png +0 -0
- package/dist/screenshots/news_dashboard.png +0 -0
- package/dist/screenshots/project_dashboard.png +0 -0
- package/dist/screenshots/research_lab.png +0 -0
- package/dist/screenshots/skill_library.png +0 -0
- package/dist/screenshots/task_list.png +0 -0
- package/dist/screenshots/terminal_example.png +0 -0
- package/dist/screenshots/terminal_example1.png +0 -0
- package/dist/sw.js +58 -0
- package/dist/wechat-group-qr.jpg +0 -0
- package/package.json +133 -0
- package/public/api-docs.html +878 -0
- package/public/clear-cache.html +85 -0
- package/public/convert-icons.md +53 -0
- package/public/dr-claw.png +0 -0
- package/public/favicon.png +0 -0
- package/public/generate-icons.js +49 -0
- package/public/icons/claude-ai-icon.svg +1 -0
- package/public/icons/codex-white.svg +3 -0
- package/public/icons/codex.svg +3 -0
- package/public/icons/cursor-white.svg +12 -0
- package/public/icons/cursor.svg +1 -0
- package/public/icons/file.svg +16997 -0
- package/public/icons/generate-icons.md +19 -0
- package/public/icons/icon-128x128.png +0 -0
- package/public/icons/icon-144x144.png +0 -0
- package/public/icons/icon-152x152.png +0 -0
- package/public/icons/icon-192x192.png +0 -0
- package/public/icons/icon-384x384.png +0 -0
- package/public/icons/icon-512x512.png +0 -0
- package/public/icons/icon-72x72.png +0 -0
- package/public/icons/icon-96x96.png +0 -0
- package/public/icons/news/arxiv.svg +1 -0
- package/public/icons/news/huggingface.svg +8 -0
- package/public/icons/news/x-black.png +0 -0
- package/public/icons/news/x-white.png +0 -0
- package/public/icons/news/xiaohongshu.png +0 -0
- package/public/leveraged-cognition.png +0 -0
- package/public/manifest.json +61 -0
- package/public/screenshots/chat.png +0 -0
- package/public/screenshots/new_claw.png +0 -0
- package/public/screenshots/news_dashboard.png +0 -0
- package/public/screenshots/project_dashboard.png +0 -0
- package/public/screenshots/research_lab.png +0 -0
- package/public/screenshots/skill_library.png +0 -0
- package/public/screenshots/task_list.png +0 -0
- package/public/screenshots/terminal_example.png +0 -0
- package/public/screenshots/terminal_example1.png +0 -0
- package/public/sw.js +58 -0
- package/public/wechat-group-qr.jpg +0 -0
- package/scripts/export-skills-catalog-v2.mjs +746 -0
- package/scripts/fix-node-pty.js +45 -0
- package/scripts/gemini_image_core.py +470 -0
- package/scripts/install-python-tools.js +64 -0
- package/server/AGENTS.md +73 -0
- package/server/__tests__/gemini-legacy-thought.test.mjs +88 -0
- package/server/__tests__/runtimePorts.test.mjs +115 -0
- package/server/__tests__/session-delete.test.mjs +166 -0
- package/server/bin/compute-node +70 -0
- package/server/claude-sdk.js +799 -0
- package/server/cli-chat.js +488 -0
- package/server/cli.js +354 -0
- package/server/compute-node.js +439 -0
- package/server/constants/config.js +5 -0
- package/server/cursor-cli.js +340 -0
- package/server/database/auth.db +0 -0
- package/server/database/db.js +1852 -0
- package/server/database/init.sql +194 -0
- package/server/gemini-cli.js +1352 -0
- package/server/index.js +3154 -0
- package/server/load-env.js +71 -0
- package/server/local-gpu.js +860 -0
- package/server/middleware/auth.js +100 -0
- package/server/openai-codex.js +724 -0
- package/server/openrouter.js +890 -0
- package/server/project-token-usage.js +407 -0
- package/server/projects.js +3973 -0
- package/server/routes/agent.js +1272 -0
- package/server/routes/auth.js +128 -0
- package/server/routes/auto-research.js +558 -0
- package/server/routes/cli-auth.js +958 -0
- package/server/routes/codex.js +344 -0
- package/server/routes/commands.js +601 -0
- package/server/routes/compute.js +358 -0
- package/server/routes/cursor.js +795 -0
- package/server/routes/git.js +1348 -0
- package/server/routes/mcp-utils.js +48 -0
- package/server/routes/mcp.js +618 -0
- package/server/routes/news.js +711 -0
- package/server/routes/projects.js +633 -0
- package/server/routes/references.js +338 -0
- package/server/routes/settings.js +285 -0
- package/server/routes/skills.js +914 -0
- package/server/routes/taskmaster.js +2566 -0
- package/server/routes/telemetry.js +89 -0
- package/server/routes/user.js +155 -0
- package/server/scripts/fix_session_names.js +57 -0
- package/server/scripts/research-news/common_words.py +19 -0
- package/server/scripts/research-news/link_keywords.py +298 -0
- package/server/scripts/research-news/scan_existing_notes.py +266 -0
- package/server/scripts/research-news/scoring_utils.py +227 -0
- package/server/scripts/research-news/search_arxiv.py +842 -0
- package/server/scripts/research-news/search_huggingface.py +438 -0
- package/server/scripts/research-news/search_x.py +490 -0
- package/server/scripts/research-news/search_xiaohongshu.py +610 -0
- package/server/taskmaster-templates/README.md +150 -0
- package/server/taskmaster-templates/README.zh-CN.md +150 -0
- package/server/taskmaster-templates/ai-research-dataset.json +230 -0
- package/server/taskmaster-templates/ai-research-method-model.json +230 -0
- package/server/taskmaster-templates/ai-research-position-paper.json +230 -0
- package/server/telemetry.js +121 -0
- package/server/templates/AGENTS.md +103 -0
- package/server/templates/CLAUDE.md +104 -0
- package/server/templates/GEMINI.md +103 -0
- package/server/templates/cursor-project.md +108 -0
- package/server/templates/index.js +37 -0
- package/server/utils/__tests__/sessionTokenUsage.test.js +82 -0
- package/server/utils/auto-research-mailer.js +57 -0
- package/server/utils/cliResolution.js +170 -0
- package/server/utils/commandParser.js +303 -0
- package/server/utils/cursorCommand.js +61 -0
- package/server/utils/geminiApiKey.js +28 -0
- package/server/utils/gitConfig.js +24 -0
- package/server/utils/imageAttachmentFiles.js +35 -0
- package/server/utils/mcp-detector.js +198 -0
- package/server/utils/parsers/bibtex-parser.js +207 -0
- package/server/utils/permissions.js +100 -0
- package/server/utils/runtimePorts.js +212 -0
- package/server/utils/sessionFormatting.js +68 -0
- package/server/utils/sessionIndex.js +100 -0
- package/server/utils/sessionMode.js +95 -0
- package/server/utils/sessionTokenUsage.js +105 -0
- package/server/utils/taskmaster-websocket.js +129 -0
- package/server/utils/zotero-client.js +136 -0
- package/shared/errorClassifier.js +102 -0
- package/shared/geminiThinkingSupport.d.ts +22 -0
- package/shared/geminiThinkingSupport.js +96 -0
- package/shared/geminiThoughtParser.d.ts +8 -0
- package/shared/geminiThoughtParser.js +30 -0
- package/shared/modelConstants.js +139 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import crossSpawn from 'cross-spawn';
|
|
3
|
+
import { resolveCursorCliCommand } from './utils/cursorCommand.js';
|
|
4
|
+
import { applyStageTagsToSession, recordIndexedSession } from './utils/sessionIndex.js';
|
|
5
|
+
|
|
6
|
+
// Use cross-spawn on Windows for better command execution
|
|
7
|
+
const spawnFunction = process.platform === 'win32' ? crossSpawn : spawn;
|
|
8
|
+
|
|
9
|
+
let activeCursorProcesses = new Map(); // Track active processes by session ID
|
|
10
|
+
|
|
11
|
+
async function spawnCursor(command, options = {}, ws) {
|
|
12
|
+
return new Promise(async (resolve, reject) => {
|
|
13
|
+
const { sessionId, projectPath, cwd, resume, toolsSettings, skipPermissions, model, images, sessionMode, stageTagKeys, stageTagSource = 'task_context', env } = options;
|
|
14
|
+
let capturedSessionId = sessionId; // Track session ID throughout the process
|
|
15
|
+
let sessionCreatedSent = false; // Track if we've already sent session-created event
|
|
16
|
+
let messageBuffer = ''; // Buffer for accumulating assistant messages
|
|
17
|
+
|
|
18
|
+
// Use tools settings passed from frontend, or defaults
|
|
19
|
+
const settings = toolsSettings || {
|
|
20
|
+
allowedShellCommands: [],
|
|
21
|
+
skipPermissions: false
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Build Cursor CLI command
|
|
25
|
+
const args = [];
|
|
26
|
+
|
|
27
|
+
// Build flags allowing both resume and prompt together (reply in existing session)
|
|
28
|
+
// Treat presence of sessionId as intention to resume, regardless of resume flag
|
|
29
|
+
if (sessionId) {
|
|
30
|
+
args.push('--resume=' + sessionId);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (command && command.trim()) {
|
|
34
|
+
// Provide a prompt (works for both new and resumed sessions)
|
|
35
|
+
args.push('-p', command);
|
|
36
|
+
|
|
37
|
+
// Add model flag if specified (only meaningful for new sessions; harmless on resume)
|
|
38
|
+
if (!sessionId && model) {
|
|
39
|
+
args.push('--model', model);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Request streaming JSON when we are providing a prompt
|
|
43
|
+
args.push('--output-format', 'stream-json');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Always trust the workspace directory since the user explicitly chose it
|
|
47
|
+
args.push('--trust');
|
|
48
|
+
|
|
49
|
+
// Add skip permissions flag if enabled
|
|
50
|
+
if (skipPermissions || settings.skipPermissions) {
|
|
51
|
+
args.push('-f');
|
|
52
|
+
console.log('⚠️ Using -f flag (skip permissions)');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Use cwd (actual project directory) instead of projectPath
|
|
56
|
+
const workingDir = cwd || projectPath || process.cwd();
|
|
57
|
+
const cursorCommand = resolveCursorCliCommand();
|
|
58
|
+
|
|
59
|
+
// Synchronous (better-sqlite3) — no await needed.
|
|
60
|
+
if (sessionId && workingDir) {
|
|
61
|
+
applyStageTagsToSession({
|
|
62
|
+
sessionId,
|
|
63
|
+
projectPath: workingDir,
|
|
64
|
+
stageTagKeys,
|
|
65
|
+
source: stageTagSource,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!cursorCommand) {
|
|
70
|
+
const errorMessage = 'Cursor CLI not found. Install Cursor CLI or set CURSOR_CLI_PATH to `agent` or `cursor-agent`.';
|
|
71
|
+
ws.send({
|
|
72
|
+
type: 'cursor-error',
|
|
73
|
+
error: errorMessage,
|
|
74
|
+
sessionId: capturedSessionId || sessionId || null
|
|
75
|
+
});
|
|
76
|
+
reject(new Error(errorMessage));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
console.log('Spawning Cursor CLI:', cursorCommand, args.join(' '));
|
|
81
|
+
console.log('Working directory:', workingDir);
|
|
82
|
+
console.log('Session info - Input sessionId:', sessionId, 'Resume:', resume);
|
|
83
|
+
|
|
84
|
+
const cursorProcess = spawnFunction(cursorCommand, args, {
|
|
85
|
+
cwd: workingDir,
|
|
86
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
87
|
+
env: { ...(env || process.env) }
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Store process reference for potential abort
|
|
91
|
+
const processKey = capturedSessionId || Date.now().toString();
|
|
92
|
+
activeCursorProcesses.set(processKey, {
|
|
93
|
+
process: cursorProcess,
|
|
94
|
+
startTime: Date.now()
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const getSessionStartTime = () => {
|
|
98
|
+
const sessionData = activeCursorProcesses.get(capturedSessionId || processKey);
|
|
99
|
+
return sessionData?.startTime;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// Handle stdout (streaming JSON responses)
|
|
103
|
+
cursorProcess.stdout.on('data', (data) => {
|
|
104
|
+
const rawOutput = data.toString();
|
|
105
|
+
console.log('📤 Cursor CLI stdout:', rawOutput);
|
|
106
|
+
|
|
107
|
+
const lines = rawOutput.split('\n').filter(line => line.trim());
|
|
108
|
+
|
|
109
|
+
for (const line of lines) {
|
|
110
|
+
try {
|
|
111
|
+
const response = JSON.parse(line);
|
|
112
|
+
console.log('📄 Parsed JSON response:', response);
|
|
113
|
+
|
|
114
|
+
// Handle different message types
|
|
115
|
+
switch (response.type) {
|
|
116
|
+
case 'system':
|
|
117
|
+
if (response.subtype === 'init') {
|
|
118
|
+
// Capture session ID
|
|
119
|
+
if (response.session_id && !capturedSessionId) {
|
|
120
|
+
capturedSessionId = response.session_id;
|
|
121
|
+
console.log('📝 Captured session ID:', capturedSessionId);
|
|
122
|
+
|
|
123
|
+
// Update process key with captured session ID
|
|
124
|
+
if (processKey !== capturedSessionId) {
|
|
125
|
+
const sessionData = activeCursorProcesses.get(processKey);
|
|
126
|
+
if (sessionData) {
|
|
127
|
+
activeCursorProcesses.delete(processKey);
|
|
128
|
+
sessionData.sessionId = capturedSessionId;
|
|
129
|
+
activeCursorProcesses.set(capturedSessionId, sessionData);
|
|
130
|
+
} else {
|
|
131
|
+
// Fallback if somehow not found
|
|
132
|
+
activeCursorProcesses.set(capturedSessionId, {
|
|
133
|
+
process: cursorProcess,
|
|
134
|
+
startTime: Date.now()
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Set session ID on writer (for API endpoint compatibility)
|
|
140
|
+
if (ws.setSessionId && typeof ws.setSessionId === 'function') {
|
|
141
|
+
ws.setSessionId(capturedSessionId);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Send session-created event only once for new sessions
|
|
145
|
+
if (!sessionId && !sessionCreatedSent) {
|
|
146
|
+
sessionCreatedSent = true;
|
|
147
|
+
recordIndexedSession({
|
|
148
|
+
sessionId: capturedSessionId,
|
|
149
|
+
provider: 'cursor',
|
|
150
|
+
projectPath: workingDir,
|
|
151
|
+
sessionMode: sessionMode || 'research',
|
|
152
|
+
displayName: response.session_title || response.title || null,
|
|
153
|
+
stageTagKeys,
|
|
154
|
+
tagSource: stageTagSource,
|
|
155
|
+
});
|
|
156
|
+
ws.send({
|
|
157
|
+
type: 'session-created',
|
|
158
|
+
sessionId: capturedSessionId,
|
|
159
|
+
model: response.model,
|
|
160
|
+
cwd: response.cwd,
|
|
161
|
+
mode: sessionMode || 'research',
|
|
162
|
+
startTime: getSessionStartTime()
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Send system info to frontend
|
|
168
|
+
ws.send({
|
|
169
|
+
type: 'cursor-system',
|
|
170
|
+
data: response,
|
|
171
|
+
sessionId: capturedSessionId || sessionId || null,
|
|
172
|
+
startTime: getSessionStartTime()
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
|
|
177
|
+
case 'user':
|
|
178
|
+
// Forward user message
|
|
179
|
+
ws.send({
|
|
180
|
+
type: 'cursor-user',
|
|
181
|
+
data: response,
|
|
182
|
+
sessionId: capturedSessionId || sessionId || null,
|
|
183
|
+
startTime: getSessionStartTime()
|
|
184
|
+
});
|
|
185
|
+
break;
|
|
186
|
+
|
|
187
|
+
case 'assistant':
|
|
188
|
+
// Accumulate assistant message chunks
|
|
189
|
+
if (response.message && response.message.content && response.message.content.length > 0) {
|
|
190
|
+
const textContent = response.message.content[0].text;
|
|
191
|
+
messageBuffer += textContent;
|
|
192
|
+
|
|
193
|
+
// Send as Claude-compatible format for frontend
|
|
194
|
+
ws.send({
|
|
195
|
+
type: 'claude-response',
|
|
196
|
+
data: {
|
|
197
|
+
type: 'content_block_delta',
|
|
198
|
+
startTime: getSessionStartTime(),
|
|
199
|
+
delta: {
|
|
200
|
+
type: 'text_delta',
|
|
201
|
+
text: textContent
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
sessionId: capturedSessionId || sessionId || null
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
break;
|
|
208
|
+
|
|
209
|
+
case 'result':
|
|
210
|
+
// Session complete
|
|
211
|
+
console.log('Cursor session result:', response);
|
|
212
|
+
|
|
213
|
+
// Send final message if we have buffered content
|
|
214
|
+
if (messageBuffer) {
|
|
215
|
+
ws.send({
|
|
216
|
+
type: 'claude-response',
|
|
217
|
+
data: {
|
|
218
|
+
type: 'content_block_stop',
|
|
219
|
+
startTime: getSessionStartTime(),
|
|
220
|
+
},
|
|
221
|
+
sessionId: capturedSessionId || sessionId || null
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Send completion event
|
|
226
|
+
ws.send({
|
|
227
|
+
type: 'cursor-result',
|
|
228
|
+
sessionId: capturedSessionId || sessionId,
|
|
229
|
+
data: response,
|
|
230
|
+
success: response.subtype === 'success',
|
|
231
|
+
startTime: getSessionStartTime(),
|
|
232
|
+
});
|
|
233
|
+
break;
|
|
234
|
+
|
|
235
|
+
default:
|
|
236
|
+
// Forward any other message types
|
|
237
|
+
ws.send({
|
|
238
|
+
type: 'cursor-response',
|
|
239
|
+
data: response,
|
|
240
|
+
sessionId: capturedSessionId || sessionId || null,
|
|
241
|
+
startTime: getSessionStartTime(),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
} catch (parseError) {
|
|
245
|
+
console.log('📄 Non-JSON response:', line);
|
|
246
|
+
// If not JSON, send as raw text
|
|
247
|
+
ws.send({
|
|
248
|
+
type: 'cursor-output',
|
|
249
|
+
data: line,
|
|
250
|
+
sessionId: capturedSessionId || sessionId || null,
|
|
251
|
+
startTime: getSessionStartTime()
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
// Handle stderr
|
|
258
|
+
cursorProcess.stderr.on('data', (data) => {
|
|
259
|
+
console.error('Cursor CLI stderr:', data.toString());
|
|
260
|
+
ws.send({
|
|
261
|
+
type: 'cursor-error',
|
|
262
|
+
error: data.toString(),
|
|
263
|
+
sessionId: capturedSessionId || sessionId || null
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
// Handle process completion
|
|
268
|
+
cursorProcess.on('close', async (code) => {
|
|
269
|
+
console.log(`Cursor CLI process exited with code ${code}`);
|
|
270
|
+
|
|
271
|
+
// Clean up process reference
|
|
272
|
+
const finalSessionId = capturedSessionId || sessionId || processKey;
|
|
273
|
+
ws.send({
|
|
274
|
+
type: 'claude-complete',
|
|
275
|
+
sessionId: finalSessionId,
|
|
276
|
+
exitCode: code,
|
|
277
|
+
isNewSession: !sessionId && !!command // Flag to indicate this was a new session
|
|
278
|
+
});
|
|
279
|
+
activeCursorProcesses.delete(finalSessionId);
|
|
280
|
+
|
|
281
|
+
if (code === 0) {
|
|
282
|
+
resolve();
|
|
283
|
+
} else {
|
|
284
|
+
reject(new Error(`Cursor CLI exited with code ${code}`));
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
// Handle process errors
|
|
289
|
+
cursorProcess.on('error', (error) => {
|
|
290
|
+
console.error('Cursor CLI process error:', error);
|
|
291
|
+
|
|
292
|
+
// Clean up process reference on error
|
|
293
|
+
const finalSessionId = capturedSessionId || sessionId || processKey;
|
|
294
|
+
activeCursorProcesses.delete(finalSessionId);
|
|
295
|
+
|
|
296
|
+
ws.send({
|
|
297
|
+
type: 'cursor-error',
|
|
298
|
+
error: error.message,
|
|
299
|
+
sessionId: capturedSessionId || sessionId || null
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
reject(error);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
// Close stdin since Cursor doesn't need interactive input
|
|
306
|
+
cursorProcess.stdin.end();
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function abortCursorSession(sessionId) {
|
|
311
|
+
const sessionData = activeCursorProcesses.get(sessionId);
|
|
312
|
+
if (sessionData && sessionData.process) {
|
|
313
|
+
console.log(`🛑 Aborting Cursor session: ${sessionId}`);
|
|
314
|
+
sessionData.process.kill('SIGTERM');
|
|
315
|
+
activeCursorProcesses.delete(sessionId);
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function isCursorSessionActive(sessionId) {
|
|
322
|
+
return activeCursorProcesses.has(sessionId);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function getCursorSessionStartTime(sessionId) {
|
|
326
|
+
const sessionData = activeCursorProcesses.get(sessionId);
|
|
327
|
+
return sessionData ? sessionData.startTime : null;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function getActiveCursorSessions() {
|
|
331
|
+
return Array.from(activeCursorProcesses.keys());
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export {
|
|
335
|
+
spawnCursor,
|
|
336
|
+
abortCursorSession,
|
|
337
|
+
isCursorSessionActive,
|
|
338
|
+
getCursorSessionStartTime,
|
|
339
|
+
getActiveCursorSessions
|
|
340
|
+
};
|
|
File without changes
|