vibecodingmachine-core 1.0.0 → 1.0.1
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 +47 -45
- 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 +43 -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 +85 -78
- 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 +167 -167
|
@@ -1,306 +1,306 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared AppleScript utilities for IDE integration
|
|
3
|
-
* Consolidates common AppleScript patterns to follow DRY principles
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
class AppleScriptUtils {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.logger = console;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Generate AppleScript for focusing AI panel with multiple fallback strategies
|
|
13
|
-
* @param {string} text - The text to send to the AI panel
|
|
14
|
-
* @param {string} ide - The IDE name (e.g., 'cursor')
|
|
15
|
-
* @returns {string} Complete AppleScript code
|
|
16
|
-
*/
|
|
17
|
-
generateAIPanelFocusScript(text, ide = 'cursor') {
|
|
18
|
-
const escapedText = text.replace(/"/g, '\\"');
|
|
19
|
-
|
|
20
|
-
return `
|
|
21
|
-
tell application "System Events"
|
|
22
|
-
tell process "${ide}"
|
|
23
|
-
-- Check if the process is running before attempting to interact
|
|
24
|
-
try
|
|
25
|
-
set frontmost to true
|
|
26
|
-
delay 1
|
|
27
|
-
|
|
28
|
-
-- PRE-CHECK: Ensure we're not in an editor
|
|
29
|
-
try
|
|
30
|
-
-- Press Escape to ensure we're not in any input mode
|
|
31
|
-
key code 53 -- Escape
|
|
32
|
-
delay 0.5
|
|
33
|
-
on error
|
|
34
|
-
-- Continue if escape fails
|
|
35
|
-
end try
|
|
36
|
-
|
|
37
|
-
${this.generateFocusStrategies(escapedText)}
|
|
38
|
-
on error
|
|
39
|
-
-- Process not running or not accessible
|
|
40
|
-
error "Process '${ide}' is not running or not accessible. VibeCodingMachine does not open IDEs - please open ${ide} manually first."
|
|
41
|
-
end try
|
|
42
|
-
end tell
|
|
43
|
-
end tell`;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Generate multiple focus strategies with fallbacks
|
|
48
|
-
* @param {string} escapedText - The escaped text to send
|
|
49
|
-
* @returns {string} AppleScript focus strategies
|
|
50
|
-
*/
|
|
51
|
-
generateFocusStrategies(escapedText) {
|
|
52
|
-
return `
|
|
53
|
-
-- STRATEGY 1: Direct AI Panel Focus via Keyboard Shortcut (Cmd+L) - Primary
|
|
54
|
-
try
|
|
55
|
-
-- Use Cmd+L to focus AI panel (faster and more reliable)
|
|
56
|
-
key code 37 using {command down} -- Cmd+L
|
|
57
|
-
delay 1.5
|
|
58
|
-
|
|
59
|
-
-- Open new chat session with Cmd+T to prevent crashes
|
|
60
|
-
key code 17 using {command down} -- Cmd+T
|
|
61
|
-
delay 2.5
|
|
62
|
-
|
|
63
|
-
-- Skip clearing text to avoid selecting file content
|
|
64
|
-
-- The chat input should be empty when opening new chat session
|
|
65
|
-
|
|
66
|
-
-- Wait additional time for chat input field to be fully ready
|
|
67
|
-
delay 1.0
|
|
68
|
-
|
|
69
|
-
-- Type the message
|
|
70
|
-
keystroke "${escapedText}"
|
|
71
|
-
delay 1.5
|
|
72
|
-
|
|
73
|
-
-- Send with Cmd+Enter (standard for chat interfaces)
|
|
74
|
-
key code 36 using {command down}
|
|
75
|
-
delay 0.5
|
|
76
|
-
|
|
77
|
-
-- Fallback: Press Enter to ensure submission
|
|
78
|
-
key code 36
|
|
79
|
-
delay 0.5
|
|
80
|
-
|
|
81
|
-
-- Additional fallback: Press Enter again to be absolutely sure
|
|
82
|
-
key code 36
|
|
83
|
-
delay 1.0
|
|
84
|
-
|
|
85
|
-
return "Message sent via AppleScript to AI Panel using Cmd+L shortcut with new chat session (Cmd+T)"
|
|
86
|
-
on error
|
|
87
|
-
-- STRATEGY 2: Command Palette Approach (Fallback 1) - NO AI PANEL TOGGLE
|
|
88
|
-
try
|
|
89
|
-
-- Step 1: Open Command Palette (Cmd+Shift+P)
|
|
90
|
-
key code 35 using {command down, shift down} -- Cmd+Shift+P
|
|
91
|
-
delay 0.8
|
|
92
|
-
|
|
93
|
-
-- Step 2: Type "View: Focus into Secondary Side Bar" to focus AI panel
|
|
94
|
-
keystroke "View: Focus into Secondary Side Bar"
|
|
95
|
-
delay 0.8
|
|
96
|
-
|
|
97
|
-
-- Step 3: Press Enter to focus AI Panel
|
|
98
|
-
key code 36 -- Enter
|
|
99
|
-
delay 2.0
|
|
100
|
-
|
|
101
|
-
-- Step 4: Open new chat session with Cmd+T to prevent crashes
|
|
102
|
-
key code 17 using {command down} -- Cmd+T
|
|
103
|
-
delay 2.5
|
|
104
|
-
|
|
105
|
-
-- Step 5: Skip clearing text to avoid selecting file content
|
|
106
|
-
-- The chat input should be empty when opening new chat session
|
|
107
|
-
|
|
108
|
-
-- Step 6: Wait additional time for chat input field to be fully ready
|
|
109
|
-
delay 1.0
|
|
110
|
-
|
|
111
|
-
-- Step 7: Type the message
|
|
112
|
-
keystroke "${escapedText}"
|
|
113
|
-
delay 1.5
|
|
114
|
-
|
|
115
|
-
-- Step 8: Send with Cmd+Enter (standard for chat interfaces)
|
|
116
|
-
key code 36 using {command down}
|
|
117
|
-
delay 0.5
|
|
118
|
-
|
|
119
|
-
-- Fallback: Press Enter to ensure submission
|
|
120
|
-
key code 36
|
|
121
|
-
delay 0.5
|
|
122
|
-
|
|
123
|
-
-- Additional fallback: Press Enter again to be absolutely sure
|
|
124
|
-
key code 36
|
|
125
|
-
delay 1.0
|
|
126
|
-
|
|
127
|
-
return "Message sent via AppleScript to AI Panel using command palette fallback with new chat session (Cmd+T)"
|
|
128
|
-
on error
|
|
129
|
-
-- STRATEGY 3: Direct Element Targeting (Last Resort)
|
|
130
|
-
try
|
|
131
|
-
-- Look for AI panel elements and click them
|
|
132
|
-
set aiPanelFound to false
|
|
133
|
-
|
|
134
|
-
-- Try to find text fields that might be chat inputs
|
|
135
|
-
set allTextFields to text field of window 1
|
|
136
|
-
repeat with textField in allTextFields
|
|
137
|
-
try
|
|
138
|
-
-- Click on the text field (likely chat input)
|
|
139
|
-
click textField
|
|
140
|
-
delay 0.5
|
|
141
|
-
|
|
142
|
-
-- Open new chat session with Cmd+T to prevent crashes
|
|
143
|
-
key code 17 using {command down} -- Cmd+T
|
|
144
|
-
delay 2.5
|
|
145
|
-
|
|
146
|
-
-- Skip clearing text to avoid selecting file content
|
|
147
|
-
-- The chat input should be empty when opening new chat session
|
|
148
|
-
|
|
149
|
-
-- Wait additional time for chat input field to be fully ready
|
|
150
|
-
delay 1.0
|
|
151
|
-
|
|
152
|
-
-- Type the message
|
|
153
|
-
keystroke "${escapedText}"
|
|
154
|
-
delay 1.5
|
|
155
|
-
|
|
156
|
-
-- Send with Cmd+Enter
|
|
157
|
-
key code 36 using {command down}
|
|
158
|
-
delay 0.5
|
|
159
|
-
|
|
160
|
-
-- Fallback: Press Enter to ensure submission
|
|
161
|
-
key code 36
|
|
162
|
-
delay 0.5
|
|
163
|
-
|
|
164
|
-
-- Additional fallback: Press Enter again to be absolutely sure
|
|
165
|
-
key code 36
|
|
166
|
-
delay 1.0
|
|
167
|
-
|
|
168
|
-
set aiPanelFound to true
|
|
169
|
-
exit repeat
|
|
170
|
-
on error
|
|
171
|
-
-- Continue to next text field
|
|
172
|
-
end try
|
|
173
|
-
end repeat
|
|
174
|
-
|
|
175
|
-
if aiPanelFound then
|
|
176
|
-
return "Message sent via AppleScript to AI Panel using direct element targeting"
|
|
177
|
-
end if
|
|
178
|
-
on error
|
|
179
|
-
-- STRATEGY 4: Emergency fallback - ensure we're not in editor
|
|
180
|
-
try
|
|
181
|
-
-- First escape any terminal focus
|
|
182
|
-
key code 53 -- Escape key
|
|
183
|
-
delay 1
|
|
184
|
-
|
|
185
|
-
-- Click in editor area to escape terminal
|
|
186
|
-
do shell script "/usr/local/bin/cliclick c:400,300"
|
|
187
|
-
delay 1
|
|
188
|
-
|
|
189
|
-
-- Try Tab navigation to find chat input
|
|
190
|
-
repeat 3 times
|
|
191
|
-
key code 48 -- Tab key
|
|
192
|
-
delay 0.5
|
|
193
|
-
end repeat
|
|
194
|
-
|
|
195
|
-
-- Open new chat session with Cmd+T to prevent crashes
|
|
196
|
-
key code 17 using {command down} -- Cmd+T
|
|
197
|
-
delay 2.5
|
|
198
|
-
|
|
199
|
-
-- Wait additional time for chat input field to be fully ready
|
|
200
|
-
delay 1.0
|
|
201
|
-
|
|
202
|
-
-- Type the message
|
|
203
|
-
keystroke "${escapedText}"
|
|
204
|
-
delay 1.5
|
|
205
|
-
|
|
206
|
-
-- Send with Cmd+Enter
|
|
207
|
-
key code 36 using {command down}
|
|
208
|
-
delay 0.5
|
|
209
|
-
|
|
210
|
-
-- Fallback: Press Enter to ensure submission
|
|
211
|
-
key code 36
|
|
212
|
-
delay 0.5
|
|
213
|
-
|
|
214
|
-
-- Additional fallback: Press Enter again to be absolutely sure
|
|
215
|
-
key code 36
|
|
216
|
-
delay 1.0
|
|
217
|
-
|
|
218
|
-
return "Message sent via AppleScript to AI Panel using emergency fallback with new chat session (Cmd+T)"
|
|
219
|
-
on error
|
|
220
|
-
return "ERROR: All AI panel focus strategies failed"
|
|
221
|
-
end try
|
|
222
|
-
end try
|
|
223
|
-
end try
|
|
224
|
-
end try`;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Generate Windows PowerShell script for AI panel focus
|
|
229
|
-
* @param {string} text - The text to send to the AI panel
|
|
230
|
-
* @returns {string} Complete PowerShell script
|
|
231
|
-
*/
|
|
232
|
-
generateWindowsAIPanelScript(text) {
|
|
233
|
-
const escapedText = text.replace(/"/g, '""');
|
|
234
|
-
|
|
235
|
-
return `
|
|
236
|
-
# Windows AI Panel Focus Script - Consolidated
|
|
237
|
-
Add-Type -AssemblyName System.Windows.Forms
|
|
238
|
-
Add-Type -AssemblyName System.Drawing
|
|
239
|
-
|
|
240
|
-
# Function to find Cursor window
|
|
241
|
-
function Find-CursorWindow {
|
|
242
|
-
$processes = Get-Process | Where-Object { $_.ProcessName -like "*cursor*" -or $_.MainWindowTitle -like "*cursor*" }
|
|
243
|
-
foreach ($proc in $processes) {
|
|
244
|
-
if ($proc.MainWindowHandle -ne [IntPtr]::Zero) {
|
|
245
|
-
return $proc
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
return $null
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
# Function to focus AI Panel and send text
|
|
252
|
-
function Send-ToAIPanel {
|
|
253
|
-
param($windowHandle, $text)
|
|
254
|
-
|
|
255
|
-
# Focus the Cursor window
|
|
256
|
-
[Microsoft.VisualBasic.Interaction]::AppActivate($windowHandle)
|
|
257
|
-
Start-Sleep -Milliseconds 500
|
|
258
|
-
|
|
259
|
-
# Step 1: Try Cmd+L equivalent (Ctrl+L on Windows) to focus AI panel
|
|
260
|
-
[System.Windows.Forms.SendKeys]::SendWait("^l")
|
|
261
|
-
Start-Sleep -Milliseconds 1500
|
|
262
|
-
|
|
263
|
-
# Step 2: Open new chat session with Ctrl+T to prevent crashes
|
|
264
|
-
[System.Windows.Forms.SendKeys]::SendWait("^t")
|
|
265
|
-
Start-Sleep -Milliseconds 1000
|
|
266
|
-
|
|
267
|
-
# Step 3: Clear any existing text in the chat input (Ctrl+A, Delete)
|
|
268
|
-
[System.Windows.Forms.SendKeys]::SendWait("^a")
|
|
269
|
-
Start-Sleep -Milliseconds 200
|
|
270
|
-
[System.Windows.Forms.SendKeys]::SendWait("{DELETE}")
|
|
271
|
-
Start-Sleep -Milliseconds 200
|
|
272
|
-
|
|
273
|
-
# Step 4: Type the message
|
|
274
|
-
[System.Windows.Forms.SendKeys]::SendWait("$text")
|
|
275
|
-
Start-Sleep -Milliseconds 500
|
|
276
|
-
|
|
277
|
-
# Step 5: Send with Ctrl+Enter (standard for chat interfaces)
|
|
278
|
-
[System.Windows.Forms.SendKeys]::SendWait("^{ENTER}")
|
|
279
|
-
Start-Sleep -Milliseconds 1000
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
try {
|
|
283
|
-
# Find Cursor window
|
|
284
|
-
$cursorProcess = Find-CursorWindow
|
|
285
|
-
if ($cursorProcess -eq $null) {
|
|
286
|
-
Write-Output "ERROR: Cursor window not found"
|
|
287
|
-
exit 1
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
Write-Output "Found Cursor process: $($cursorProcess.ProcessName) (PID: $($cursorProcess.Id))"
|
|
291
|
-
|
|
292
|
-
# Send the text to AI Panel
|
|
293
|
-
Send-ToAIPanel -windowHandle $cursorProcess.MainWindowHandle -text "${escapedText}"
|
|
294
|
-
|
|
295
|
-
Write-Output "SUCCESS: Message sent to Cursor AI Panel using Ctrl+L shortcut with new chat session (Ctrl+T)"
|
|
296
|
-
exit 0
|
|
297
|
-
|
|
298
|
-
} catch {
|
|
299
|
-
Write-Output "ERROR: $($_.Exception.Message)"
|
|
300
|
-
exit 1
|
|
301
|
-
}`;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
module.exports = AppleScriptUtils;
|
|
306
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Shared AppleScript utilities for IDE integration
|
|
3
|
+
* Consolidates common AppleScript patterns to follow DRY principles
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
class AppleScriptUtils {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.logger = console;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Generate AppleScript for focusing AI panel with multiple fallback strategies
|
|
13
|
+
* @param {string} text - The text to send to the AI panel
|
|
14
|
+
* @param {string} ide - The IDE name (e.g., 'cursor')
|
|
15
|
+
* @returns {string} Complete AppleScript code
|
|
16
|
+
*/
|
|
17
|
+
generateAIPanelFocusScript(text, ide = 'cursor') {
|
|
18
|
+
const escapedText = text.replace(/"/g, '\\"');
|
|
19
|
+
|
|
20
|
+
return `
|
|
21
|
+
tell application "System Events"
|
|
22
|
+
tell process "${ide}"
|
|
23
|
+
-- Check if the process is running before attempting to interact
|
|
24
|
+
try
|
|
25
|
+
set frontmost to true
|
|
26
|
+
delay 1
|
|
27
|
+
|
|
28
|
+
-- PRE-CHECK: Ensure we're not in an editor
|
|
29
|
+
try
|
|
30
|
+
-- Press Escape to ensure we're not in any input mode
|
|
31
|
+
key code 53 -- Escape
|
|
32
|
+
delay 0.5
|
|
33
|
+
on error
|
|
34
|
+
-- Continue if escape fails
|
|
35
|
+
end try
|
|
36
|
+
|
|
37
|
+
${this.generateFocusStrategies(escapedText)}
|
|
38
|
+
on error
|
|
39
|
+
-- Process not running or not accessible
|
|
40
|
+
error "Process '${ide}' is not running or not accessible. VibeCodingMachine does not open IDEs - please open ${ide} manually first."
|
|
41
|
+
end try
|
|
42
|
+
end tell
|
|
43
|
+
end tell`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Generate multiple focus strategies with fallbacks
|
|
48
|
+
* @param {string} escapedText - The escaped text to send
|
|
49
|
+
* @returns {string} AppleScript focus strategies
|
|
50
|
+
*/
|
|
51
|
+
generateFocusStrategies(escapedText) {
|
|
52
|
+
return `
|
|
53
|
+
-- STRATEGY 1: Direct AI Panel Focus via Keyboard Shortcut (Cmd+L) - Primary
|
|
54
|
+
try
|
|
55
|
+
-- Use Cmd+L to focus AI panel (faster and more reliable)
|
|
56
|
+
key code 37 using {command down} -- Cmd+L
|
|
57
|
+
delay 1.5
|
|
58
|
+
|
|
59
|
+
-- Open new chat session with Cmd+T to prevent crashes
|
|
60
|
+
key code 17 using {command down} -- Cmd+T
|
|
61
|
+
delay 2.5
|
|
62
|
+
|
|
63
|
+
-- Skip clearing text to avoid selecting file content
|
|
64
|
+
-- The chat input should be empty when opening new chat session
|
|
65
|
+
|
|
66
|
+
-- Wait additional time for chat input field to be fully ready
|
|
67
|
+
delay 1.0
|
|
68
|
+
|
|
69
|
+
-- Type the message
|
|
70
|
+
keystroke "${escapedText}"
|
|
71
|
+
delay 1.5
|
|
72
|
+
|
|
73
|
+
-- Send with Cmd+Enter (standard for chat interfaces)
|
|
74
|
+
key code 36 using {command down}
|
|
75
|
+
delay 0.5
|
|
76
|
+
|
|
77
|
+
-- Fallback: Press Enter to ensure submission
|
|
78
|
+
key code 36
|
|
79
|
+
delay 0.5
|
|
80
|
+
|
|
81
|
+
-- Additional fallback: Press Enter again to be absolutely sure
|
|
82
|
+
key code 36
|
|
83
|
+
delay 1.0
|
|
84
|
+
|
|
85
|
+
return "Message sent via AppleScript to AI Panel using Cmd+L shortcut with new chat session (Cmd+T)"
|
|
86
|
+
on error
|
|
87
|
+
-- STRATEGY 2: Command Palette Approach (Fallback 1) - NO AI PANEL TOGGLE
|
|
88
|
+
try
|
|
89
|
+
-- Step 1: Open Command Palette (Cmd+Shift+P)
|
|
90
|
+
key code 35 using {command down, shift down} -- Cmd+Shift+P
|
|
91
|
+
delay 0.8
|
|
92
|
+
|
|
93
|
+
-- Step 2: Type "View: Focus into Secondary Side Bar" to focus AI panel
|
|
94
|
+
keystroke "View: Focus into Secondary Side Bar"
|
|
95
|
+
delay 0.8
|
|
96
|
+
|
|
97
|
+
-- Step 3: Press Enter to focus AI Panel
|
|
98
|
+
key code 36 -- Enter
|
|
99
|
+
delay 2.0
|
|
100
|
+
|
|
101
|
+
-- Step 4: Open new chat session with Cmd+T to prevent crashes
|
|
102
|
+
key code 17 using {command down} -- Cmd+T
|
|
103
|
+
delay 2.5
|
|
104
|
+
|
|
105
|
+
-- Step 5: Skip clearing text to avoid selecting file content
|
|
106
|
+
-- The chat input should be empty when opening new chat session
|
|
107
|
+
|
|
108
|
+
-- Step 6: Wait additional time for chat input field to be fully ready
|
|
109
|
+
delay 1.0
|
|
110
|
+
|
|
111
|
+
-- Step 7: Type the message
|
|
112
|
+
keystroke "${escapedText}"
|
|
113
|
+
delay 1.5
|
|
114
|
+
|
|
115
|
+
-- Step 8: Send with Cmd+Enter (standard for chat interfaces)
|
|
116
|
+
key code 36 using {command down}
|
|
117
|
+
delay 0.5
|
|
118
|
+
|
|
119
|
+
-- Fallback: Press Enter to ensure submission
|
|
120
|
+
key code 36
|
|
121
|
+
delay 0.5
|
|
122
|
+
|
|
123
|
+
-- Additional fallback: Press Enter again to be absolutely sure
|
|
124
|
+
key code 36
|
|
125
|
+
delay 1.0
|
|
126
|
+
|
|
127
|
+
return "Message sent via AppleScript to AI Panel using command palette fallback with new chat session (Cmd+T)"
|
|
128
|
+
on error
|
|
129
|
+
-- STRATEGY 3: Direct Element Targeting (Last Resort)
|
|
130
|
+
try
|
|
131
|
+
-- Look for AI panel elements and click them
|
|
132
|
+
set aiPanelFound to false
|
|
133
|
+
|
|
134
|
+
-- Try to find text fields that might be chat inputs
|
|
135
|
+
set allTextFields to text field of window 1
|
|
136
|
+
repeat with textField in allTextFields
|
|
137
|
+
try
|
|
138
|
+
-- Click on the text field (likely chat input)
|
|
139
|
+
click textField
|
|
140
|
+
delay 0.5
|
|
141
|
+
|
|
142
|
+
-- Open new chat session with Cmd+T to prevent crashes
|
|
143
|
+
key code 17 using {command down} -- Cmd+T
|
|
144
|
+
delay 2.5
|
|
145
|
+
|
|
146
|
+
-- Skip clearing text to avoid selecting file content
|
|
147
|
+
-- The chat input should be empty when opening new chat session
|
|
148
|
+
|
|
149
|
+
-- Wait additional time for chat input field to be fully ready
|
|
150
|
+
delay 1.0
|
|
151
|
+
|
|
152
|
+
-- Type the message
|
|
153
|
+
keystroke "${escapedText}"
|
|
154
|
+
delay 1.5
|
|
155
|
+
|
|
156
|
+
-- Send with Cmd+Enter
|
|
157
|
+
key code 36 using {command down}
|
|
158
|
+
delay 0.5
|
|
159
|
+
|
|
160
|
+
-- Fallback: Press Enter to ensure submission
|
|
161
|
+
key code 36
|
|
162
|
+
delay 0.5
|
|
163
|
+
|
|
164
|
+
-- Additional fallback: Press Enter again to be absolutely sure
|
|
165
|
+
key code 36
|
|
166
|
+
delay 1.0
|
|
167
|
+
|
|
168
|
+
set aiPanelFound to true
|
|
169
|
+
exit repeat
|
|
170
|
+
on error
|
|
171
|
+
-- Continue to next text field
|
|
172
|
+
end try
|
|
173
|
+
end repeat
|
|
174
|
+
|
|
175
|
+
if aiPanelFound then
|
|
176
|
+
return "Message sent via AppleScript to AI Panel using direct element targeting"
|
|
177
|
+
end if
|
|
178
|
+
on error
|
|
179
|
+
-- STRATEGY 4: Emergency fallback - ensure we're not in editor
|
|
180
|
+
try
|
|
181
|
+
-- First escape any terminal focus
|
|
182
|
+
key code 53 -- Escape key
|
|
183
|
+
delay 1
|
|
184
|
+
|
|
185
|
+
-- Click in editor area to escape terminal
|
|
186
|
+
do shell script "/usr/local/bin/cliclick c:400,300"
|
|
187
|
+
delay 1
|
|
188
|
+
|
|
189
|
+
-- Try Tab navigation to find chat input
|
|
190
|
+
repeat 3 times
|
|
191
|
+
key code 48 -- Tab key
|
|
192
|
+
delay 0.5
|
|
193
|
+
end repeat
|
|
194
|
+
|
|
195
|
+
-- Open new chat session with Cmd+T to prevent crashes
|
|
196
|
+
key code 17 using {command down} -- Cmd+T
|
|
197
|
+
delay 2.5
|
|
198
|
+
|
|
199
|
+
-- Wait additional time for chat input field to be fully ready
|
|
200
|
+
delay 1.0
|
|
201
|
+
|
|
202
|
+
-- Type the message
|
|
203
|
+
keystroke "${escapedText}"
|
|
204
|
+
delay 1.5
|
|
205
|
+
|
|
206
|
+
-- Send with Cmd+Enter
|
|
207
|
+
key code 36 using {command down}
|
|
208
|
+
delay 0.5
|
|
209
|
+
|
|
210
|
+
-- Fallback: Press Enter to ensure submission
|
|
211
|
+
key code 36
|
|
212
|
+
delay 0.5
|
|
213
|
+
|
|
214
|
+
-- Additional fallback: Press Enter again to be absolutely sure
|
|
215
|
+
key code 36
|
|
216
|
+
delay 1.0
|
|
217
|
+
|
|
218
|
+
return "Message sent via AppleScript to AI Panel using emergency fallback with new chat session (Cmd+T)"
|
|
219
|
+
on error
|
|
220
|
+
return "ERROR: All AI panel focus strategies failed"
|
|
221
|
+
end try
|
|
222
|
+
end try
|
|
223
|
+
end try
|
|
224
|
+
end try`;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Generate Windows PowerShell script for AI panel focus
|
|
229
|
+
* @param {string} text - The text to send to the AI panel
|
|
230
|
+
* @returns {string} Complete PowerShell script
|
|
231
|
+
*/
|
|
232
|
+
generateWindowsAIPanelScript(text) {
|
|
233
|
+
const escapedText = text.replace(/"/g, '""');
|
|
234
|
+
|
|
235
|
+
return `
|
|
236
|
+
# Windows AI Panel Focus Script - Consolidated
|
|
237
|
+
Add-Type -AssemblyName System.Windows.Forms
|
|
238
|
+
Add-Type -AssemblyName System.Drawing
|
|
239
|
+
|
|
240
|
+
# Function to find Cursor window
|
|
241
|
+
function Find-CursorWindow {
|
|
242
|
+
$processes = Get-Process | Where-Object { $_.ProcessName -like "*cursor*" -or $_.MainWindowTitle -like "*cursor*" }
|
|
243
|
+
foreach ($proc in $processes) {
|
|
244
|
+
if ($proc.MainWindowHandle -ne [IntPtr]::Zero) {
|
|
245
|
+
return $proc
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return $null
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
# Function to focus AI Panel and send text
|
|
252
|
+
function Send-ToAIPanel {
|
|
253
|
+
param($windowHandle, $text)
|
|
254
|
+
|
|
255
|
+
# Focus the Cursor window
|
|
256
|
+
[Microsoft.VisualBasic.Interaction]::AppActivate($windowHandle)
|
|
257
|
+
Start-Sleep -Milliseconds 500
|
|
258
|
+
|
|
259
|
+
# Step 1: Try Cmd+L equivalent (Ctrl+L on Windows) to focus AI panel
|
|
260
|
+
[System.Windows.Forms.SendKeys]::SendWait("^l")
|
|
261
|
+
Start-Sleep -Milliseconds 1500
|
|
262
|
+
|
|
263
|
+
# Step 2: Open new chat session with Ctrl+T to prevent crashes
|
|
264
|
+
[System.Windows.Forms.SendKeys]::SendWait("^t")
|
|
265
|
+
Start-Sleep -Milliseconds 1000
|
|
266
|
+
|
|
267
|
+
# Step 3: Clear any existing text in the chat input (Ctrl+A, Delete)
|
|
268
|
+
[System.Windows.Forms.SendKeys]::SendWait("^a")
|
|
269
|
+
Start-Sleep -Milliseconds 200
|
|
270
|
+
[System.Windows.Forms.SendKeys]::SendWait("{DELETE}")
|
|
271
|
+
Start-Sleep -Milliseconds 200
|
|
272
|
+
|
|
273
|
+
# Step 4: Type the message
|
|
274
|
+
[System.Windows.Forms.SendKeys]::SendWait("$text")
|
|
275
|
+
Start-Sleep -Milliseconds 500
|
|
276
|
+
|
|
277
|
+
# Step 5: Send with Ctrl+Enter (standard for chat interfaces)
|
|
278
|
+
[System.Windows.Forms.SendKeys]::SendWait("^{ENTER}")
|
|
279
|
+
Start-Sleep -Milliseconds 1000
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
try {
|
|
283
|
+
# Find Cursor window
|
|
284
|
+
$cursorProcess = Find-CursorWindow
|
|
285
|
+
if ($cursorProcess -eq $null) {
|
|
286
|
+
Write-Output "ERROR: Cursor window not found"
|
|
287
|
+
exit 1
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
Write-Output "Found Cursor process: $($cursorProcess.ProcessName) (PID: $($cursorProcess.Id))"
|
|
291
|
+
|
|
292
|
+
# Send the text to AI Panel
|
|
293
|
+
Send-ToAIPanel -windowHandle $cursorProcess.MainWindowHandle -text "${escapedText}"
|
|
294
|
+
|
|
295
|
+
Write-Output "SUCCESS: Message sent to Cursor AI Panel using Ctrl+L shortcut with new chat session (Ctrl+T)"
|
|
296
|
+
exit 0
|
|
297
|
+
|
|
298
|
+
} catch {
|
|
299
|
+
Write-Output "ERROR: $($_.Exception.Message)"
|
|
300
|
+
exit 1
|
|
301
|
+
}`;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
module.exports = AppleScriptUtils;
|
|
306
|
+
|