vibecodingmachine-core 1.0.2 → 2025.11.2-7.1302
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/.babelrc +13 -13
- package/README.md +28 -28
- package/__tests__/applescript-manager-claude-fix.test.js +286 -286
- package/__tests__/requirement-2-auto-start-looping.test.js +69 -69
- package/__tests__/requirement-3-auto-start-looping.test.js +69 -69
- package/__tests__/requirement-4-auto-start-looping.test.js +69 -69
- package/__tests__/requirement-6-auto-start-looping.test.js +73 -73
- package/__tests__/requirement-7-status-tracking.test.js +332 -332
- package/jest.config.js +18 -18
- package/jest.setup.js +12 -12
- package/package.json +48 -48
- package/src/auth/access-denied.html +119 -119
- package/src/auth/shared-auth-storage.js +230 -230
- package/src/autonomous-mode/feature-implementer.cjs +70 -70
- package/src/autonomous-mode/feature-implementer.js +425 -425
- package/src/chat-management/chat-manager.cjs +71 -71
- package/src/chat-management/chat-manager.js +342 -342
- package/src/ide-integration/__tests__/applescript-manager-thread-closure.test.js +227 -227
- package/src/ide-integration/aider-cli-manager.cjs +850 -850
- package/src/ide-integration/applescript-manager.cjs +1088 -1088
- package/src/ide-integration/applescript-manager.js +2802 -2802
- package/src/ide-integration/applescript-utils.js +306 -306
- package/src/ide-integration/cdp-manager.cjs +221 -221
- package/src/ide-integration/cdp-manager.js +321 -321
- package/src/ide-integration/claude-code-cli-manager.cjs +301 -301
- package/src/ide-integration/cline-cli-manager.cjs +2252 -2252
- package/src/ide-integration/continue-cli-manager.js +431 -431
- package/src/ide-integration/provider-manager.cjs +354 -354
- package/src/ide-integration/quota-detector.cjs +34 -34
- package/src/ide-integration/quota-detector.js +349 -349
- package/src/ide-integration/windows-automation-manager.js +262 -262
- package/src/index.cjs +47 -43
- package/src/index.js +17 -17
- package/src/llm/direct-llm-manager.cjs +609 -609
- package/src/ui/ButtonComponents.js +247 -247
- package/src/ui/ChatInterface.js +499 -499
- package/src/ui/StateManager.js +259 -259
- package/src/utils/audit-logger.cjs +116 -116
- package/src/utils/config-helpers.cjs +94 -94
- package/src/utils/config-helpers.js +94 -94
- package/src/utils/electron-update-checker.js +113 -85
- package/src/utils/gcloud-auth.cjs +394 -394
- package/src/utils/logger.cjs +193 -193
- package/src/utils/logger.js +191 -191
- package/src/utils/repo-helpers.cjs +120 -120
- package/src/utils/repo-helpers.js +120 -120
- package/src/utils/requirement-helpers.js +432 -432
- package/src/utils/update-checker.js +227 -167
- package/src/utils/version-checker.js +169 -0
|
@@ -1,221 +1,221 @@
|
|
|
1
|
-
// @vibecodingmachine/core - CDP Manager (CommonJS)
|
|
2
|
-
// Handles Chrome DevTools Protocol interactions with IDEs
|
|
3
|
-
|
|
4
|
-
const CDP = require('chrome-remote-interface');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* CDP Manager for IDE interactions
|
|
8
|
-
* Handles Chrome DevTools Protocol-based text sending for IDEs like VS Code and Cursor
|
|
9
|
-
*/
|
|
10
|
-
class CDPManager {
|
|
11
|
-
constructor() {
|
|
12
|
-
this.logger = console;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Timeout utility function
|
|
17
|
-
* @param {number} ms - Timeout in milliseconds
|
|
18
|
-
* @param {Promise} promise - Promise to timeout
|
|
19
|
-
* @returns {Promise} Promise with timeout
|
|
20
|
-
*/
|
|
21
|
-
timeout(ms, promise) {
|
|
22
|
-
return Promise.race([
|
|
23
|
-
promise,
|
|
24
|
-
new Promise((_, reject) =>
|
|
25
|
-
setTimeout(() => reject(new Error(`Operation timed out after ${ms}ms`)), ms)
|
|
26
|
-
)
|
|
27
|
-
]);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Send text to an IDE via CDP
|
|
32
|
-
* @param {string} text - The text to send
|
|
33
|
-
* @param {string} ide - The IDE name ('vscode', 'cursor')
|
|
34
|
-
* @returns {Promise<Object>} Result object with success status and details
|
|
35
|
-
*/
|
|
36
|
-
async sendText(text, ide) {
|
|
37
|
-
if (typeof text !== 'string') {
|
|
38
|
-
return {
|
|
39
|
-
success: false,
|
|
40
|
-
error: `Invalid text type: ${typeof text}. Expected string.`,
|
|
41
|
-
debug: { textType: typeof text, textValue: text }
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const ideName = ide === 'cursor' ? 'Cursor' : ide === 'vscode' ? 'VS Code' : 'Unknown IDE';
|
|
46
|
-
const port = ide === 'cursor' ? 9225 : 9222;
|
|
47
|
-
|
|
48
|
-
this.logger.log(`🔍 sendText: Starting debug session`);
|
|
49
|
-
this.logger.log(`📋 IDE: ${ideName} (${ide})`);
|
|
50
|
-
this.logger.log(`🔌 Port: ${port}`);
|
|
51
|
-
this.logger.log(`💬 Text: "${text.substring(0, 100)}${text.length > 100 ? '...' : ''}"`);
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
// For VS Code, use the working approach from commit 6235f46b
|
|
55
|
-
if (ide === 'vscode') {
|
|
56
|
-
return await this.sendTextToVSCode(text);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// For other IDEs, use basic CDP approach
|
|
60
|
-
return await this.sendTextBasic(text, ide);
|
|
61
|
-
} catch (error) {
|
|
62
|
-
this.logger.error('CDP error:', error);
|
|
63
|
-
return {
|
|
64
|
-
success: false,
|
|
65
|
-
error: `CDP error: ${error.message}`,
|
|
66
|
-
debug: { ide, port, textLength: text.length }
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Send text to VS Code using the working approach
|
|
73
|
-
* @param {string} text - The text to send
|
|
74
|
-
* @returns {Promise<Object>} Result object
|
|
75
|
-
*/
|
|
76
|
-
async sendTextToVSCode(text) {
|
|
77
|
-
try {
|
|
78
|
-
const targets = await CDP.List({ port: 9222 });
|
|
79
|
-
if (!targets || targets.length === 0) {
|
|
80
|
-
return { success: false, error: 'Could not find VS Code. Make sure VS Code is running with --remote-debugging-port=9222' };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const workbench = targets.find(t => t.url && t.url.includes('workbench')) || targets[0];
|
|
84
|
-
if (!workbench) return { success: false, error: 'No VS Code workbench target found.' };
|
|
85
|
-
|
|
86
|
-
this.logger.log(`Found ${targets.length} targets, using workbench: ${workbench.title}`);
|
|
87
|
-
const client = await CDP({ port: 9222, target: workbench });
|
|
88
|
-
const { Runtime, Input, Page, DOM } = client;
|
|
89
|
-
await Runtime.enable();
|
|
90
|
-
await DOM.enable();
|
|
91
|
-
if (Page && Page.bringToFront) { try { await Page.bringToFront(); } catch (_) {} }
|
|
92
|
-
|
|
93
|
-
// Use clipboard approach to avoid focus issues
|
|
94
|
-
const clipboardText = String(text).slice(0, 4000);
|
|
95
|
-
this.logger.log('Copying text to clipboard:', clipboardText);
|
|
96
|
-
|
|
97
|
-
// Try to paste the text after a short delay
|
|
98
|
-
setTimeout(async () => {
|
|
99
|
-
try {
|
|
100
|
-
const isDarwin = process.platform === 'darwin';
|
|
101
|
-
const pasteMods = isDarwin ? 4 /* Meta */ : 2 /* Ctrl */;
|
|
102
|
-
await Input.dispatchKeyEvent({ type: 'keyDown', key: 'v', text: 'v', modifiers: pasteMods });
|
|
103
|
-
await Input.dispatchKeyEvent({ type: 'keyUp', key: 'v', text: 'v', modifiers: pasteMods });
|
|
104
|
-
this.logger.log('Pasted text via Cmd+V');
|
|
105
|
-
} catch (e) {
|
|
106
|
-
this.logger.log('Paste failed:', e.message);
|
|
107
|
-
}
|
|
108
|
-
}, 200);
|
|
109
|
-
|
|
110
|
-
// Also try typing the text character by character
|
|
111
|
-
setTimeout(async () => {
|
|
112
|
-
try {
|
|
113
|
-
this.logger.log('Starting character-by-character typing...');
|
|
114
|
-
for (let i = 0; i < clipboardText.length; i++) {
|
|
115
|
-
const char = clipboardText[i];
|
|
116
|
-
await Input.dispatchKeyEvent({ type: 'keyDown', key: char, text: char });
|
|
117
|
-
await Input.dispatchKeyEvent({ type: 'keyUp', key: char, text: char });
|
|
118
|
-
await new Promise(resolve => setTimeout(resolve, 20));
|
|
119
|
-
}
|
|
120
|
-
this.logger.log('Finished character-by-character typing');
|
|
121
|
-
|
|
122
|
-
// Try multiple submission methods
|
|
123
|
-
setTimeout(async () => {
|
|
124
|
-
try {
|
|
125
|
-
this.logger.log('Attempting to submit message...');
|
|
126
|
-
|
|
127
|
-
// Method 1: Press Enter
|
|
128
|
-
await Input.dispatchKeyEvent({ type: 'keyDown', key: 'Enter' });
|
|
129
|
-
await Input.dispatchKeyEvent({ type: 'keyUp', key: 'Enter' });
|
|
130
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
131
|
-
|
|
132
|
-
// Method 2: Try Cmd+Enter
|
|
133
|
-
const isDarwin = process.platform === 'darwin';
|
|
134
|
-
const enterMods = isDarwin ? 4 /* Meta */ : 2 /* Ctrl */;
|
|
135
|
-
await Input.dispatchKeyEvent({ type: 'keyDown', key: 'Enter', text: 'Enter', modifiers: enterMods });
|
|
136
|
-
await Input.dispatchKeyEvent({ type: 'keyUp', key: 'Enter', text: 'Enter', modifiers: enterMods });
|
|
137
|
-
|
|
138
|
-
} catch (e) {
|
|
139
|
-
this.logger.log('Submission failed:', e.message);
|
|
140
|
-
}
|
|
141
|
-
}, 300);
|
|
142
|
-
|
|
143
|
-
} catch (e) {
|
|
144
|
-
this.logger.log('Character typing failed:', e.message);
|
|
145
|
-
}
|
|
146
|
-
}, 500);
|
|
147
|
-
|
|
148
|
-
this.logger.log(`Successfully sent message to VS Code via CDP`);
|
|
149
|
-
return {
|
|
150
|
-
success: true,
|
|
151
|
-
method: 'cdp-clipboard',
|
|
152
|
-
message: `Message sent to VS Code: ${text}`,
|
|
153
|
-
note: 'Message sent via CDP with clipboard approach'
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
} catch (error) {
|
|
157
|
-
this.logger.error('VS Code CDP error:', error);
|
|
158
|
-
return { success: false, error: `VS Code CDP error: ${error.message}` };
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Send text using basic CDP approach
|
|
164
|
-
* @param {string} text - The text to send
|
|
165
|
-
* @param {string} ide - The IDE name
|
|
166
|
-
* @returns {Promise<Object>} Result object
|
|
167
|
-
*/
|
|
168
|
-
async sendTextBasic(text, ide) {
|
|
169
|
-
const textToSend = String(text).slice(0, 4000);
|
|
170
|
-
const port = ide === 'cursor' ? 9225 : 9222;
|
|
171
|
-
|
|
172
|
-
try {
|
|
173
|
-
const targets = await this.timeout(5000, CDP.List({ port }));
|
|
174
|
-
if (!targets || targets.length === 0) {
|
|
175
|
-
return { success: false, error: `Could not find ${ide}. Make sure ${ide} is running with --remote-debugging-port=${port}` };
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const workbench = targets.find(t => t.url && t.url.includes('workbench')) || targets[0];
|
|
179
|
-
if (!workbench) return { success: false, error: `No ${ide} workbench target found.` };
|
|
180
|
-
|
|
181
|
-
const client = await this.timeout(10000, CDP({ port, target: workbench }));
|
|
182
|
-
const { Runtime, Input, Page } = client;
|
|
183
|
-
|
|
184
|
-
await this.timeout(5000, Runtime.enable());
|
|
185
|
-
await this.timeout(5000, Page.enable());
|
|
186
|
-
|
|
187
|
-
if (Page && Page.bringToFront) {
|
|
188
|
-
try {
|
|
189
|
-
await this.timeout(3000, Page.bringToFront());
|
|
190
|
-
} catch (error) {
|
|
191
|
-
this.logger.log(`Bring to front failed: ${error.message}`);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Type the text character by character
|
|
196
|
-
for (let i = 0; i < textToSend.length; i++) {
|
|
197
|
-
const char = textToSend[i];
|
|
198
|
-
await Input.dispatchKeyEvent({ type: 'keyDown', key: char, text: char });
|
|
199
|
-
await Input.dispatchKeyEvent({ type: 'keyUp', key: char, text: char });
|
|
200
|
-
await new Promise(resolve => setTimeout(resolve, 20));
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Press Enter to submit
|
|
204
|
-
await Input.dispatchKeyEvent({ type: 'keyDown', key: 'Enter' });
|
|
205
|
-
await Input.dispatchKeyEvent({ type: 'keyUp', key: 'Enter' });
|
|
206
|
-
|
|
207
|
-
return {
|
|
208
|
-
success: true,
|
|
209
|
-
method: 'cdp-basic',
|
|
210
|
-
message: `Message sent to ${ide}: ${text}`,
|
|
211
|
-
note: 'Message sent via basic CDP approach'
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
} catch (error) {
|
|
215
|
-
this.logger.error(`${ide} CDP error:`, error);
|
|
216
|
-
return { success: false, error: `${ide} CDP error: ${error.message}` };
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
module.exports = { CDPManager };
|
|
1
|
+
// @vibecodingmachine/core - CDP Manager (CommonJS)
|
|
2
|
+
// Handles Chrome DevTools Protocol interactions with IDEs
|
|
3
|
+
|
|
4
|
+
const CDP = require('chrome-remote-interface');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* CDP Manager for IDE interactions
|
|
8
|
+
* Handles Chrome DevTools Protocol-based text sending for IDEs like VS Code and Cursor
|
|
9
|
+
*/
|
|
10
|
+
class CDPManager {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.logger = console;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Timeout utility function
|
|
17
|
+
* @param {number} ms - Timeout in milliseconds
|
|
18
|
+
* @param {Promise} promise - Promise to timeout
|
|
19
|
+
* @returns {Promise} Promise with timeout
|
|
20
|
+
*/
|
|
21
|
+
timeout(ms, promise) {
|
|
22
|
+
return Promise.race([
|
|
23
|
+
promise,
|
|
24
|
+
new Promise((_, reject) =>
|
|
25
|
+
setTimeout(() => reject(new Error(`Operation timed out after ${ms}ms`)), ms)
|
|
26
|
+
)
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Send text to an IDE via CDP
|
|
32
|
+
* @param {string} text - The text to send
|
|
33
|
+
* @param {string} ide - The IDE name ('vscode', 'cursor')
|
|
34
|
+
* @returns {Promise<Object>} Result object with success status and details
|
|
35
|
+
*/
|
|
36
|
+
async sendText(text, ide) {
|
|
37
|
+
if (typeof text !== 'string') {
|
|
38
|
+
return {
|
|
39
|
+
success: false,
|
|
40
|
+
error: `Invalid text type: ${typeof text}. Expected string.`,
|
|
41
|
+
debug: { textType: typeof text, textValue: text }
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const ideName = ide === 'cursor' ? 'Cursor' : ide === 'vscode' ? 'VS Code' : 'Unknown IDE';
|
|
46
|
+
const port = ide === 'cursor' ? 9225 : 9222;
|
|
47
|
+
|
|
48
|
+
this.logger.log(`🔍 sendText: Starting debug session`);
|
|
49
|
+
this.logger.log(`📋 IDE: ${ideName} (${ide})`);
|
|
50
|
+
this.logger.log(`🔌 Port: ${port}`);
|
|
51
|
+
this.logger.log(`💬 Text: "${text.substring(0, 100)}${text.length > 100 ? '...' : ''}"`);
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
// For VS Code, use the working approach from commit 6235f46b
|
|
55
|
+
if (ide === 'vscode') {
|
|
56
|
+
return await this.sendTextToVSCode(text);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// For other IDEs, use basic CDP approach
|
|
60
|
+
return await this.sendTextBasic(text, ide);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
this.logger.error('CDP error:', error);
|
|
63
|
+
return {
|
|
64
|
+
success: false,
|
|
65
|
+
error: `CDP error: ${error.message}`,
|
|
66
|
+
debug: { ide, port, textLength: text.length }
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Send text to VS Code using the working approach
|
|
73
|
+
* @param {string} text - The text to send
|
|
74
|
+
* @returns {Promise<Object>} Result object
|
|
75
|
+
*/
|
|
76
|
+
async sendTextToVSCode(text) {
|
|
77
|
+
try {
|
|
78
|
+
const targets = await CDP.List({ port: 9222 });
|
|
79
|
+
if (!targets || targets.length === 0) {
|
|
80
|
+
return { success: false, error: 'Could not find VS Code. Make sure VS Code is running with --remote-debugging-port=9222' };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const workbench = targets.find(t => t.url && t.url.includes('workbench')) || targets[0];
|
|
84
|
+
if (!workbench) return { success: false, error: 'No VS Code workbench target found.' };
|
|
85
|
+
|
|
86
|
+
this.logger.log(`Found ${targets.length} targets, using workbench: ${workbench.title}`);
|
|
87
|
+
const client = await CDP({ port: 9222, target: workbench });
|
|
88
|
+
const { Runtime, Input, Page, DOM } = client;
|
|
89
|
+
await Runtime.enable();
|
|
90
|
+
await DOM.enable();
|
|
91
|
+
if (Page && Page.bringToFront) { try { await Page.bringToFront(); } catch (_) {} }
|
|
92
|
+
|
|
93
|
+
// Use clipboard approach to avoid focus issues
|
|
94
|
+
const clipboardText = String(text).slice(0, 4000);
|
|
95
|
+
this.logger.log('Copying text to clipboard:', clipboardText);
|
|
96
|
+
|
|
97
|
+
// Try to paste the text after a short delay
|
|
98
|
+
setTimeout(async () => {
|
|
99
|
+
try {
|
|
100
|
+
const isDarwin = process.platform === 'darwin';
|
|
101
|
+
const pasteMods = isDarwin ? 4 /* Meta */ : 2 /* Ctrl */;
|
|
102
|
+
await Input.dispatchKeyEvent({ type: 'keyDown', key: 'v', text: 'v', modifiers: pasteMods });
|
|
103
|
+
await Input.dispatchKeyEvent({ type: 'keyUp', key: 'v', text: 'v', modifiers: pasteMods });
|
|
104
|
+
this.logger.log('Pasted text via Cmd+V');
|
|
105
|
+
} catch (e) {
|
|
106
|
+
this.logger.log('Paste failed:', e.message);
|
|
107
|
+
}
|
|
108
|
+
}, 200);
|
|
109
|
+
|
|
110
|
+
// Also try typing the text character by character
|
|
111
|
+
setTimeout(async () => {
|
|
112
|
+
try {
|
|
113
|
+
this.logger.log('Starting character-by-character typing...');
|
|
114
|
+
for (let i = 0; i < clipboardText.length; i++) {
|
|
115
|
+
const char = clipboardText[i];
|
|
116
|
+
await Input.dispatchKeyEvent({ type: 'keyDown', key: char, text: char });
|
|
117
|
+
await Input.dispatchKeyEvent({ type: 'keyUp', key: char, text: char });
|
|
118
|
+
await new Promise(resolve => setTimeout(resolve, 20));
|
|
119
|
+
}
|
|
120
|
+
this.logger.log('Finished character-by-character typing');
|
|
121
|
+
|
|
122
|
+
// Try multiple submission methods
|
|
123
|
+
setTimeout(async () => {
|
|
124
|
+
try {
|
|
125
|
+
this.logger.log('Attempting to submit message...');
|
|
126
|
+
|
|
127
|
+
// Method 1: Press Enter
|
|
128
|
+
await Input.dispatchKeyEvent({ type: 'keyDown', key: 'Enter' });
|
|
129
|
+
await Input.dispatchKeyEvent({ type: 'keyUp', key: 'Enter' });
|
|
130
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
131
|
+
|
|
132
|
+
// Method 2: Try Cmd+Enter
|
|
133
|
+
const isDarwin = process.platform === 'darwin';
|
|
134
|
+
const enterMods = isDarwin ? 4 /* Meta */ : 2 /* Ctrl */;
|
|
135
|
+
await Input.dispatchKeyEvent({ type: 'keyDown', key: 'Enter', text: 'Enter', modifiers: enterMods });
|
|
136
|
+
await Input.dispatchKeyEvent({ type: 'keyUp', key: 'Enter', text: 'Enter', modifiers: enterMods });
|
|
137
|
+
|
|
138
|
+
} catch (e) {
|
|
139
|
+
this.logger.log('Submission failed:', e.message);
|
|
140
|
+
}
|
|
141
|
+
}, 300);
|
|
142
|
+
|
|
143
|
+
} catch (e) {
|
|
144
|
+
this.logger.log('Character typing failed:', e.message);
|
|
145
|
+
}
|
|
146
|
+
}, 500);
|
|
147
|
+
|
|
148
|
+
this.logger.log(`Successfully sent message to VS Code via CDP`);
|
|
149
|
+
return {
|
|
150
|
+
success: true,
|
|
151
|
+
method: 'cdp-clipboard',
|
|
152
|
+
message: `Message sent to VS Code: ${text}`,
|
|
153
|
+
note: 'Message sent via CDP with clipboard approach'
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
} catch (error) {
|
|
157
|
+
this.logger.error('VS Code CDP error:', error);
|
|
158
|
+
return { success: false, error: `VS Code CDP error: ${error.message}` };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Send text using basic CDP approach
|
|
164
|
+
* @param {string} text - The text to send
|
|
165
|
+
* @param {string} ide - The IDE name
|
|
166
|
+
* @returns {Promise<Object>} Result object
|
|
167
|
+
*/
|
|
168
|
+
async sendTextBasic(text, ide) {
|
|
169
|
+
const textToSend = String(text).slice(0, 4000);
|
|
170
|
+
const port = ide === 'cursor' ? 9225 : 9222;
|
|
171
|
+
|
|
172
|
+
try {
|
|
173
|
+
const targets = await this.timeout(5000, CDP.List({ port }));
|
|
174
|
+
if (!targets || targets.length === 0) {
|
|
175
|
+
return { success: false, error: `Could not find ${ide}. Make sure ${ide} is running with --remote-debugging-port=${port}` };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const workbench = targets.find(t => t.url && t.url.includes('workbench')) || targets[0];
|
|
179
|
+
if (!workbench) return { success: false, error: `No ${ide} workbench target found.` };
|
|
180
|
+
|
|
181
|
+
const client = await this.timeout(10000, CDP({ port, target: workbench }));
|
|
182
|
+
const { Runtime, Input, Page } = client;
|
|
183
|
+
|
|
184
|
+
await this.timeout(5000, Runtime.enable());
|
|
185
|
+
await this.timeout(5000, Page.enable());
|
|
186
|
+
|
|
187
|
+
if (Page && Page.bringToFront) {
|
|
188
|
+
try {
|
|
189
|
+
await this.timeout(3000, Page.bringToFront());
|
|
190
|
+
} catch (error) {
|
|
191
|
+
this.logger.log(`Bring to front failed: ${error.message}`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Type the text character by character
|
|
196
|
+
for (let i = 0; i < textToSend.length; i++) {
|
|
197
|
+
const char = textToSend[i];
|
|
198
|
+
await Input.dispatchKeyEvent({ type: 'keyDown', key: char, text: char });
|
|
199
|
+
await Input.dispatchKeyEvent({ type: 'keyUp', key: char, text: char });
|
|
200
|
+
await new Promise(resolve => setTimeout(resolve, 20));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Press Enter to submit
|
|
204
|
+
await Input.dispatchKeyEvent({ type: 'keyDown', key: 'Enter' });
|
|
205
|
+
await Input.dispatchKeyEvent({ type: 'keyUp', key: 'Enter' });
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
success: true,
|
|
209
|
+
method: 'cdp-basic',
|
|
210
|
+
message: `Message sent to ${ide}: ${text}`,
|
|
211
|
+
note: 'Message sent via basic CDP approach'
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
} catch (error) {
|
|
215
|
+
this.logger.error(`${ide} CDP error:`, error);
|
|
216
|
+
return { success: false, error: `${ide} CDP error: ${error.message}` };
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
module.exports = { CDPManager };
|