Repository navigation
Expand file tree
/
Copy pathstart.js
More file actions
executable file
·265 lines (215 loc) · 6.69 KB
/
Copy pathstart.js
File metadata and controls
executable file
·265 lines (215 loc) · 6.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/usr/bin/env node
/**
* Cascade Multiagent - Interactive REPL
*
* Automatically connects to Windsurf and mounts the UI,
* then provides an interactive prompt for commands.
*/
const readline = require('readline');
const cascade = require('./index');
const PORT = 9333;
let connected = false;
let mounted = false;
// ANSI colors
const colors = {
reset: '\x1b[0m',
bright: '\x1b[1m',
cyan: '\x1b[36m',
green: '\x1b[32m',
red: '\x1b[31m',
yellow: '\x1b[33m',
gray: '\x1b[90m'
};
function log(message, color = 'reset') {
console.log(colors[color] + message + colors.reset);
}
async function initialize() {
try {
log('\n╔═══════════════════════════════════════════╗', 'cyan');
log('║ Cascade Multiagent - Interactive Mode ║', 'cyan');
log('╚═══════════════════════════════════════════╝', 'cyan');
log('');
log('→ Connecting to Windsurf...', 'gray');
const result = await cascade.connect(PORT);
connected = true;
log(`✓ Connected to: ${result.pageTitle}`, 'green');
log('→ Trusting workspace...', 'gray');
await cascade.trustWorkspace();
log('→ Opening Cascade panel...', 'gray');
await cascade.open();
log('→ Hijacking UI...', 'gray');
const mountResult = await cascade.mountCustomUI();
mounted = true;
log('✓ UI mounted successfully!', 'green');
log(` Panels: ${mountResult.extraction.panelCount}`, 'gray');
log(` Handlers: ${mountResult.extraction.handlersExtracted}`, 'gray');
log('');
// startREPL();
} catch (error) {
log(`✗ Initialization failed: ${error.message}`, 'red');
console.error(error.stack);
process.exit(1);
}
}
function startREPL() {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: colors.cyan + 'cascade> ' + colors.reset
});
log('Ready! Type "help" for available commands.', 'yellow');
log('');
rl.prompt();
rl.on('line', async (line) => {
const input = line.trim();
if (!input) {
rl.prompt();
return;
}
const [command, ...args] = input.split(' ');
try {
switch (command.toLowerCase()) {
case 'help':
showHelp();
break;
case 'send':
if (args.length < 2) {
log('Usage: send <panel> <message>', 'red');
} else {
const panelIndex = parseInt(args[0]);
const message = args.slice(1).join(' ');
await sendMessage(panelIndex, message);
}
break;
case 'list':
await listPanels();
break;
case 'spawn':
await spawnPanel();
break;
case 'status':
showStatus();
break;
case 'restore':
await restoreUI();
break;
case 'exit':
case 'quit':
await cleanup();
process.exit(0);
break;
default:
log(`Unknown command: ${command}. Type "help" for available commands.`, 'red');
}
} catch (error) {
log(`Error: ${error.message}`, 'red');
}
rl.prompt();
});
rl.on('SIGINT', async () => {
log('\n\nReceived Ctrl+C...', 'yellow');
await cleanup();
process.exit(0);
});
rl.on('close', async () => {
await cleanup();
process.exit(0);
});
}
function showHelp() {
log('\nAvailable commands:', 'bright');
log(' send <panel> <message> Send message to panel (e.g., send 0 Hello!)', 'gray');
log(' list List all panels', 'gray');
log(' spawn Create new Cascade panel', 'gray');
log(' status Show current status', 'gray');
log(' restore Restore original Windsurf UI', 'gray');
log(' help Show this help message', 'gray');
log(' exit Exit and cleanup', 'gray');
log('');
}
async function sendMessage(panelIndex, message) {
log(`→ Sending to panel ${panelIndex}...`, 'gray');
const result = await cascade.send(panelIndex, message);
if (result.sent) {
log('✓ Message sent', 'green');
log('→ Waiting for response...', 'gray');
const response = await cascade.getResponse(panelIndex, 15000);
if (response.stable) {
log('\n--- Response ---', 'cyan');
console.log(response.response);
log('--- End ---\n', 'cyan');
} else {
log('⚠ Response timeout', 'yellow');
}
} else {
log(`✗ Send failed: ${result.error || 'Button not enabled'}`, 'red');
}
}
async function listPanels() {
const panels = await cascade.listPanels();
log(`\nFound ${panels.length} panel(s):`, 'bright');
if (panels.length === 0) {
log(' No panels found.', 'gray');
} else {
panels.forEach(panel => {
const status = panel.visible ? '✓' : '✗';
const enabled = panel.buttonEnabled ? 'ready' : 'busy';
log(` [${panel.index}] ${status} ${enabled} - ${panel.inputContent || '(empty)'}`, 'gray');
});
}
log('');
}
async function spawnPanel() {
log('→ Spawning new panel...', 'gray');
const result = await cascade.spawnCascade();
if (result.spawned) {
log(`✓ Panel spawned at index ${result.newIndex}`, 'green');
log(` Total panels: ${result.afterCount}`, 'gray');
} else {
log('✗ Failed to spawn panel', 'red');
}
}
function showStatus() {
log('\nStatus:', 'bright');
log(` Connected: ${connected ? '✓' : '✗'}`, connected ? 'green' : 'red');
log(` UI Hijacked: ${mounted ? '✓' : '✗'}`, mounted ? 'green' : 'red');
log(` Port: ${PORT}`, 'gray');
const mountStatus = cascade.getHijackStatus();
if (mountStatus) {
log(` Panels: ${mountStatus.extraction.panelCount}`, 'gray');
log(` Handlers: ${mountStatus.extraction.handlersExtracted}`, 'gray');
}
log('');
}
async function restoreUI() {
if (!mounted) {
log('UI not mounted, nothing to restore.', 'yellow');
return;
}
log('→ Restoring original UI...', 'gray');
const result = await cascade.restoreUI();
if (result.restored) {
log('✓ UI restored', 'green');
mounted = false;
} else {
log(`✗ Restore failed: ${result.error}`, 'red');
}
}
async function cleanup() {
log('\n→ Cleaning up...', 'gray');
if (mounted) {
await cascade.restoreUI();
log('✓ UI restored', 'green');
}
if (connected) {
await cascade.disconnect();
log('✓ Disconnected', 'green');
}
log('Goodbye!', 'cyan');
}
// Start the interactive session
initialize().catch(error => {
log(`Fatal error: ${error.message}`, 'red');
console.error(error.stack);
process.exit(1);
});