cursor-bridge 1.2.0 → 1.3.0
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/dist/index.js +40 -3
- package/package.json +1 -1
- package/src/index.ts +48 -4
package/dist/index.js
CHANGED
|
@@ -5,8 +5,45 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
const ws_1 = __importDefault(require("ws"));
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
8
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
10
|
const BRIDGE_URL = 'wss://cursor-226b2ae97542.herokuapp.com';
|
|
11
|
+
function sendToCursor(prompt) {
|
|
12
|
+
try {
|
|
13
|
+
// Escape special characters for AppleScript
|
|
14
|
+
const escaped = prompt
|
|
15
|
+
.replace(/\\/g, '\\\\')
|
|
16
|
+
.replace(/"/g, '\\"')
|
|
17
|
+
.replace(/\n/g, '\\n');
|
|
18
|
+
const script = `
|
|
19
|
+
tell application "Cursor"
|
|
20
|
+
activate
|
|
21
|
+
end tell
|
|
22
|
+
delay 0.5
|
|
23
|
+
tell application "System Events"
|
|
24
|
+
tell process "Cursor"
|
|
25
|
+
-- Open Composer with Cmd+I
|
|
26
|
+
keystroke "i" using command down
|
|
27
|
+
delay 0.3
|
|
28
|
+
-- Type the prompt
|
|
29
|
+
keystroke "${escaped}"
|
|
30
|
+
delay 0.2
|
|
31
|
+
-- Submit with Enter
|
|
32
|
+
key code 36
|
|
33
|
+
end tell
|
|
34
|
+
end tell
|
|
35
|
+
`;
|
|
36
|
+
(0, child_process_1.execSync)(`osascript -e '${script.replace(/'/g, "'\\''")}'`, {
|
|
37
|
+
timeout: 10000,
|
|
38
|
+
});
|
|
39
|
+
console.log(chalk_1.default.hex('#22C55E')(' ✓ ') +
|
|
40
|
+
chalk_1.default.white('Sent to Cursor IDE'));
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
console.log(chalk_1.default.hex('#EF4444')(' ✗ ') +
|
|
44
|
+
chalk_1.default.gray('Failed to send to Cursor. Is it running?'));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
10
47
|
function generatePairCode() {
|
|
11
48
|
return Math.floor(100000 + Math.random() * 900000).toString();
|
|
12
49
|
}
|
|
@@ -71,12 +108,12 @@ function connect() {
|
|
|
71
108
|
console.log(chalk_1.default.hex('#A855F7')(' → ') +
|
|
72
109
|
chalk_1.default.white('Command received: ') +
|
|
73
110
|
chalk_1.default.gray(prompt.substring(0, 80) + (prompt.length > 80 ? '...' : '')));
|
|
74
|
-
|
|
111
|
+
sendToCursor(prompt);
|
|
75
112
|
ws.send(JSON.stringify({
|
|
76
113
|
type: 'response',
|
|
77
114
|
payload: {
|
|
78
|
-
status: '
|
|
79
|
-
message:
|
|
115
|
+
status: 'sent',
|
|
116
|
+
message: 'Sent to Cursor IDE',
|
|
80
117
|
},
|
|
81
118
|
timestamp: Date.now(),
|
|
82
119
|
}));
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,11 +1,54 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import WebSocket from 'ws';
|
|
4
|
+
import { execSync } from 'child_process';
|
|
4
5
|
import chalk from 'chalk';
|
|
5
|
-
import os from 'os';
|
|
6
6
|
|
|
7
7
|
const BRIDGE_URL = 'wss://cursor-226b2ae97542.herokuapp.com';
|
|
8
8
|
|
|
9
|
+
function sendToCursor(prompt: string): void {
|
|
10
|
+
try {
|
|
11
|
+
// Escape special characters for AppleScript
|
|
12
|
+
const escaped = prompt
|
|
13
|
+
.replace(/\\/g, '\\\\')
|
|
14
|
+
.replace(/"/g, '\\"')
|
|
15
|
+
.replace(/\n/g, '\\n');
|
|
16
|
+
|
|
17
|
+
const script = `
|
|
18
|
+
tell application "Cursor"
|
|
19
|
+
activate
|
|
20
|
+
end tell
|
|
21
|
+
delay 0.5
|
|
22
|
+
tell application "System Events"
|
|
23
|
+
tell process "Cursor"
|
|
24
|
+
-- Open Composer with Cmd+I
|
|
25
|
+
keystroke "i" using command down
|
|
26
|
+
delay 0.3
|
|
27
|
+
-- Type the prompt
|
|
28
|
+
keystroke "${escaped}"
|
|
29
|
+
delay 0.2
|
|
30
|
+
-- Submit with Enter
|
|
31
|
+
key code 36
|
|
32
|
+
end tell
|
|
33
|
+
end tell
|
|
34
|
+
`;
|
|
35
|
+
|
|
36
|
+
execSync(`osascript -e '${script.replace(/'/g, "'\\''")}'`, {
|
|
37
|
+
timeout: 10000,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
console.log(
|
|
41
|
+
chalk.hex('#22C55E')(' ✓ ') +
|
|
42
|
+
chalk.white('Sent to Cursor IDE'),
|
|
43
|
+
);
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.log(
|
|
46
|
+
chalk.hex('#EF4444')(' ✗ ') +
|
|
47
|
+
chalk.gray('Failed to send to Cursor. Is it running?'),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
9
52
|
function generatePairCode(): string {
|
|
10
53
|
return Math.floor(100000 + Math.random() * 900000).toString();
|
|
11
54
|
}
|
|
@@ -105,13 +148,14 @@ function connect() {
|
|
|
105
148
|
chalk.gray(prompt.substring(0, 80) + (prompt.length > 80 ? '...' : '')),
|
|
106
149
|
);
|
|
107
150
|
|
|
108
|
-
|
|
151
|
+
sendToCursor(prompt);
|
|
152
|
+
|
|
109
153
|
ws!.send(
|
|
110
154
|
JSON.stringify({
|
|
111
155
|
type: 'response',
|
|
112
156
|
payload: {
|
|
113
|
-
status: '
|
|
114
|
-
message:
|
|
157
|
+
status: 'sent',
|
|
158
|
+
message: 'Sent to Cursor IDE',
|
|
115
159
|
},
|
|
116
160
|
timestamp: Date.now(),
|
|
117
161
|
}),
|