-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·286 lines (254 loc) · 8.4 KB
/
Copy pathcli.js
File metadata and controls
executable file
·286 lines (254 loc) · 8.4 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/usr/bin/env node
import { execFile } from 'child_process';
import { createRequire } from 'module';
import { fileURLToPath } from 'url';
import path from 'path';
import { promisify } from 'util';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const execFileAsync = promisify(execFile);
const require = createRequire(import.meta.url);
const pkg = require('./package.json');
const [,, command, ...args] = process.argv;
function scriptPath(name) {
return path.join(__dirname, name);
}
async function runShell(script) {
try {
await execFileAsync('bash', [scriptPath(script)], { stdio: 'inherit' });
} catch (err) {
process.exit(err.status ?? 1);
}
}
function printHelp() {
console.log(`remotelab v${pkg.version}
Usage:
remotelab setup Run interactive setup
remotelab start Start all services
remotelab stop Stop all services
remotelab restart [service] Restart services (chat=owner+guests|tunnel|bridge|all)
remotelab provision-host Plan or execute whole-host provider provisioning
remotelab bootstrap-host Converge a Linux host into a RemoteLab host baseline
remotelab install-profile Resolve modules from install env and render runtime plan
remotelab validate-profile Validate host + profile health and report degradation
remotelab guest-instance Create isolated guest instances on this machine
remotelab admin Manage fleet hosts and host -> instance admin views
remotelab chat Run chat server in foreground
remotelab api Call the local RemoteLab HTTP API with owner auth
remotelab mail Manage agent mailbox and send outbound email
remotelab gmail Manage the bound Gmail mailbox connector
remotelab connector Invoke instance-scoped connector capabilities
remotelab assistant-message Append an assistant message with optional local-file attachments
remotelab local-bridge Manage linked local helper bridges for a session
remotelab agenda Manage the instance calendar feed
remotelab trigger Manage durable session triggers
remotelab schedule Manage recurring cron schedules
remotelab usage-summary Summarize local Codex token usage
remotelab session-spawn Spawn a focused parallel session from a source session
remotelab generate-token Generate a new access token
remotelab set-password Set username & password for login
remotelab --help Show this help message
remotelab --version Show version`);
}
switch (command) {
case 'setup':
await runShell('setup.sh');
break;
case 'start':
await runShell('start.sh');
break;
case 'stop':
await runShell('stop.sh');
break;
case 'restart': {
const service = args[0] || 'all';
try {
await execFileAsync('bash', [scriptPath('restart.sh'), service], { stdio: 'inherit' });
} catch (err) {
process.exit(err.status ?? 1);
}
break;
}
case 'provision-host':
case 'bootstrap-host':
case 'install-profile':
case 'validate-profile': {
const { runInstanceFactoryCommand } = await import(scriptPath('lib/instance-factory-command.mjs'));
try {
process.exitCode = await runInstanceFactoryCommand(command, args);
} catch (error) {
console.error(error.message || String(error));
process.exit(1);
}
break;
}
case 'chat':
await import(scriptPath('chat-server.mjs'));
break;
case 'release': {
console.error('`remotelab release` has been removed. RemoteLab now runs the current source tree after restart. Use `remotelab restart chat` for the owner surface.');
process.exit(1);
break;
}
case 'guest-instance':
case 'guest-instances': {
const { runGuestInstanceCommand } = await import(scriptPath('lib/guest-instance-command.mjs'));
try {
process.exitCode = await runGuestInstanceCommand(args);
} catch (error) {
console.error(error.message || String(error));
process.exit(1);
}
break;
}
case 'admin': {
const { runAdminCommand } = await import(scriptPath('lib/admin-command.mjs'));
try {
process.exitCode = await runAdminCommand(args);
} catch (error) {
console.error(error.message || String(error));
process.exit(1);
}
break;
}
case 'api': {
const { runRemoteLabApiCommand } = await import(scriptPath('lib/remotelab-api-command.mjs'));
try {
process.exitCode = await runRemoteLabApiCommand(args);
} catch (error) {
console.error(error.message || String(error));
process.exit(1);
}
break;
}
case 'mail':
case 'email': {
const { runAgentMailCommand } = await import(scriptPath('lib/agent-mail-command.mjs'));
try {
process.exitCode = await runAgentMailCommand(args);
} catch (error) {
console.error(error.message || String(error));
process.exit(1);
}
break;
}
case 'gmail': {
const { runGmailCommand } = await import(scriptPath('lib/gmail-command.mjs'));
try {
process.exitCode = await runGmailCommand(args);
} catch (error) {
console.error(error.message || String(error));
process.exit(1);
}
break;
}
case 'connector':
case 'connectors': {
const { runConnectorCommand } = await import(scriptPath('lib/connector-command.mjs'));
try {
process.exitCode = await runConnectorCommand(args);
} catch (error) {
console.error(error.message || String(error));
process.exit(1);
}
break;
}
case 'assistant-message':
case 'assistant-messages': {
const { runAssistantMessageCommand } = await import(scriptPath('lib/assistant-message-command.mjs'));
try {
process.exitCode = await runAssistantMessageCommand(args);
} catch (error) {
console.error(error.message || String(error));
process.exit(1);
}
break;
}
case 'local-bridge': {
const { runLocalBridgeCommand } = await import(scriptPath('lib/local-bridge-command.mjs'));
try {
process.exitCode = await runLocalBridgeCommand(args);
} catch (error) {
console.error(error.message || String(error));
process.exit(1);
}
break;
}
case 'agenda': {
const { runAgendaCommand } = await import(scriptPath('lib/agenda-command.mjs'));
try {
process.exitCode = await runAgendaCommand(args);
} catch (error) {
console.error(error.message || String(error));
process.exit(1);
}
break;
}
case 'trigger':
case 'triggers': {
const { runTriggerCommand } = await import(scriptPath('lib/trigger-command.mjs'));
try {
process.exitCode = await runTriggerCommand(args);
} catch (error) {
console.error(error.message || String(error));
process.exit(1);
}
break;
}
case 'schedule':
case 'schedules': {
const { runScheduleCommand } = await import(scriptPath('lib/schedule-command.mjs'));
try {
process.exitCode = await runScheduleCommand(args);
} catch (error) {
console.error(error.message || String(error));
process.exit(1);
}
break;
}
case 'usage-summary': {
const { runUsageSummaryCommand } = await import(scriptPath('lib/usage-summary-command.mjs'));
try {
process.exitCode = await runUsageSummaryCommand(args);
} catch (error) {
console.error(error.message || String(error));
process.exit(1);
}
break;
}
case 'session-spawn':
case 'spawn-session': {
const { runSessionSpawnCommand } = await import(scriptPath('lib/session-spawn-command.mjs'));
try {
process.exitCode = await runSessionSpawnCommand(args);
} catch (error) {
console.error(error.message || String(error));
process.exit(1);
}
break;
}
case 'generate-token': {
try {
await execFileAsync('node', [scriptPath('generate-token.mjs')], { stdio: 'inherit' });
} catch (err) {
process.exit(err.status ?? 1);
}
break;
}
case 'set-password': {
await import(scriptPath('set-password.mjs'));
break;
}
case '--version':
case '-v':
console.log(pkg.version);
break;
case '--help':
case '-h':
case undefined:
printHelp();
break;
default:
console.error(`Unknown command: ${command}`);
console.error('Run "remotelab --help" for usage.');
process.exit(1);
}