@aivin-labs/cli 1.0.4 → 1.0.8
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/README.md +263 -216
- package/bin/cli.mjs +1780 -1361
- package/bin/lib/browserAutomation.mjs +655 -648
- package/bin/lib/browserTui.mjs +276 -245
- package/bin/lib/cancellation.mjs +61 -0
- package/bin/lib/codegen.mjs +61 -5
- package/bin/lib/connectors.mjs +55 -21
- package/bin/lib/deploy.mjs +25 -2
- package/bin/lib/mcpProxy.mjs +869 -773
- package/bin/lib/mission.mjs +13 -1
- package/bin/lib/missionStream.mjs +696 -660
- package/bin/lib/pluginAuthResolve.mjs +127 -0
- package/bin/lib/pluginTrigger.mjs +207 -90
- package/bin/lib/releaseKeys.mjs +9 -0
- package/bin/lib/remote/activityLog.mjs +68 -0
- package/bin/lib/remote/autoStart.mjs +457 -0
- package/bin/lib/remote/autoUpdate.mjs +129 -0
- package/bin/lib/remote/brand.mjs +60 -0
- package/bin/lib/remote/browserTunnel.mjs +292 -0
- package/bin/lib/remote/callLedger.mjs +134 -0
- package/bin/lib/remote/cdpPolicy.mjs +66 -0
- package/bin/lib/remote/client.mjs +726 -0
- package/bin/lib/remote/constants.mjs +173 -0
- package/bin/lib/remote/credentials.mjs +208 -0
- package/bin/lib/remote/daemonLock.mjs +86 -0
- package/bin/lib/remote/dailyBrowser.mjs +371 -0
- package/bin/lib/remote/deviceMemory.mjs +246 -0
- package/bin/lib/remote/deviceProfile.mjs +142 -0
- package/bin/lib/remote/deviceWatches.mjs +138 -0
- package/bin/lib/remote/docText.mjs +117 -0
- package/bin/lib/remote/fileIndexer.mjs +399 -0
- package/bin/lib/remote/gui/index.mjs +245 -0
- package/bin/lib/remote/gui/officeHostSource.mjs +393 -0
- package/bin/lib/remote/gui/windowsHost.mjs +109 -0
- package/bin/lib/remote/gui/windowsHostSource.mjs +904 -0
- package/bin/lib/remote/httpTransfer.mjs +89 -0
- package/bin/lib/remote/idempotency.mjs +135 -0
- package/bin/lib/remote/keepAwake.mjs +100 -0
- package/bin/lib/remote/localConfirm.mjs +268 -0
- package/bin/lib/remote/localPolicy.mjs +249 -0
- package/bin/lib/remote/mascot/assets.mjs +218 -0
- package/bin/lib/remote/mascot/hostSource.mjs +362 -0
- package/bin/lib/remote/mascot/index.mjs +322 -0
- package/bin/lib/remote/mascot/labels.mjs +83 -0
- package/bin/lib/remote/mascot/strings.mjs +189 -0
- package/bin/lib/remote/memberFsPool.mjs +134 -0
- package/bin/lib/remote/memberFsWorker.mjs +60 -0
- package/bin/lib/remote/mission.mjs +156 -0
- package/bin/lib/remote/missionQuestion.mjs +63 -0
- package/bin/lib/remote/multiUser.mjs +344 -0
- package/bin/lib/remote/netProxy.mjs +145 -0
- package/bin/lib/remote/notify.mjs +58 -0
- package/bin/lib/remote/office/index.mjs +90 -0
- package/bin/lib/remote/policyCommand.mjs +93 -0
- package/bin/lib/remote/processes.mjs +217 -0
- package/bin/lib/remote/sandbox.mjs +221 -0
- package/bin/lib/remote/schedule.mjs +213 -0
- package/bin/lib/remote/scheduler.mjs +124 -0
- package/bin/lib/remote/textIndex.mjs +131 -0
- package/bin/lib/remote/tokenStore.mjs +77 -0
- package/bin/lib/remote/toolHandlers.mjs +726 -0
- package/bin/lib/remote/undoStore.mjs +242 -0
- package/bin/lib/remoteControl.mjs +26 -0
- package/bin/lib/scaffold.mjs +654 -653
- package/bin/lib/selfUpdate.mjs +71 -0
- package/bin/lib/store.mjs +16 -2
- package/bin/lib/tasks.mjs +52 -8
- package/bin/lib/update/binarySwap.mjs +63 -0
- package/bin/lib/update/constants.mjs +56 -0
- package/bin/lib/update/download.mjs +145 -0
- package/bin/lib/update/signature.mjs +42 -0
- package/bin/lib/update/state.mjs +205 -0
- package/bin/lib/update/versions.mjs +60 -0
- package/bin/lib/util.mjs +8 -0
- package/docs/CLI.md +1353 -1274
- package/package.json +71 -62
package/bin/cli.mjs
CHANGED
|
@@ -1,1361 +1,1780 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { Command } from 'commander';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
import fs from 'fs';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
import inquirer from 'inquirer';
|
|
8
|
-
import { spawn } from 'child_process';
|
|
9
|
-
import axios from 'axios';
|
|
10
|
-
import dotenv from 'dotenv';
|
|
11
|
-
import { fileURLToPath, pathToFileURL } from 'url';
|
|
12
|
-
import { dirname } from 'path';
|
|
13
|
-
import { createRequire } from 'module';
|
|
14
|
-
// Same flatten logic PluginServer.ts uses for local/production runtime resolution - re-exported
|
|
15
|
-
// from the installed @aivin-labs/sdk (not vendored here) so deploy and runtime agree on exactly
|
|
16
|
-
// the same rules for what manifest.json's { ...commonFields, plugins: [...] } authoring shape
|
|
17
|
-
// expands into.
|
|
18
|
-
import { flattenManifestFile } from '@aivin-labs/sdk';
|
|
19
|
-
|
|
20
|
-
import
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
import
|
|
24
|
-
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
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
|
-
// Command:
|
|
194
|
-
program
|
|
195
|
-
.command('
|
|
196
|
-
.description('
|
|
197
|
-
.option('--
|
|
198
|
-
.option('--
|
|
199
|
-
.option('--
|
|
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
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
.
|
|
364
|
-
.
|
|
365
|
-
.action(async (
|
|
366
|
-
try {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
.command('
|
|
380
|
-
.description(
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
.
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
.
|
|
428
|
-
.
|
|
429
|
-
.
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
.
|
|
443
|
-
.
|
|
444
|
-
.option('
|
|
445
|
-
.option('--
|
|
446
|
-
.option('--
|
|
447
|
-
.option('--
|
|
448
|
-
.option('--
|
|
449
|
-
.
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
.
|
|
463
|
-
.
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
.
|
|
476
|
-
.
|
|
477
|
-
.option('--
|
|
478
|
-
.option('
|
|
479
|
-
.action(async (
|
|
480
|
-
try {
|
|
481
|
-
await
|
|
482
|
-
} catch (error) {
|
|
483
|
-
console.error(chalk.red('❌'), error.message);
|
|
484
|
-
process.exit(1);
|
|
485
|
-
}
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
.
|
|
492
|
-
.
|
|
493
|
-
.
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
.
|
|
523
|
-
.
|
|
524
|
-
.
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
.
|
|
551
|
-
.
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
.
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
.
|
|
569
|
-
.
|
|
570
|
-
.option('--
|
|
571
|
-
.
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
.
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
.
|
|
598
|
-
.
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
await
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
.
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
.
|
|
683
|
-
.
|
|
684
|
-
.
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
.
|
|
699
|
-
.
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
.
|
|
710
|
-
.
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
.
|
|
728
|
-
.
|
|
729
|
-
.option('--
|
|
730
|
-
.option('--
|
|
731
|
-
.
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
url = await requireArg(url, {
|
|
738
|
-
prompt: 'GitHub
|
|
739
|
-
usage: 'Usage: aivin mcp
|
|
740
|
-
});
|
|
741
|
-
await
|
|
742
|
-
} catch (error) {
|
|
743
|
-
console.error(chalk.red('❌'), error.message);
|
|
744
|
-
process.exit(1);
|
|
745
|
-
}
|
|
746
|
-
});
|
|
747
|
-
|
|
748
|
-
mcpCommand
|
|
749
|
-
.command('
|
|
750
|
-
.description('
|
|
751
|
-
.option('--
|
|
752
|
-
.
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
.option('
|
|
766
|
-
.option('--
|
|
767
|
-
.
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
.
|
|
819
|
-
.
|
|
820
|
-
.action(() => {
|
|
821
|
-
try {
|
|
822
|
-
//
|
|
823
|
-
//
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
console.log(chalk.gray(
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
const
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
console.log(chalk.gray(
|
|
861
|
-
console.log(chalk.
|
|
862
|
-
|
|
863
|
-
console.log(chalk.
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
const
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
console.
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
process.
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
console.log(chalk.
|
|
910
|
-
|
|
911
|
-
console.log(chalk.
|
|
912
|
-
|
|
913
|
-
console.
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
}
|
|
961
|
-
await
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
.
|
|
971
|
-
.
|
|
972
|
-
.
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
.
|
|
994
|
-
.
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
.
|
|
1025
|
-
.
|
|
1026
|
-
.
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
.
|
|
1042
|
-
|
|
1043
|
-
.
|
|
1044
|
-
|
|
1045
|
-
.
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
console.
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
.
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
.command('
|
|
1069
|
-
.description('
|
|
1070
|
-
.option('--
|
|
1071
|
-
.option('--
|
|
1072
|
-
.option('--
|
|
1073
|
-
.option('--
|
|
1074
|
-
.option('--
|
|
1075
|
-
.
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
});
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
const
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
.
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
if (
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
});
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
.command('
|
|
1161
|
-
.description('
|
|
1162
|
-
.
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
.
|
|
1209
|
-
.
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
);
|
|
1231
|
-
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
console.log(chalk.
|
|
1239
|
-
|
|
1240
|
-
} catch (error) {
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
.
|
|
1248
|
-
.
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
console.log(chalk.green(
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
.
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
.
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import inquirer from 'inquirer';
|
|
8
|
+
import { spawn } from 'child_process';
|
|
9
|
+
import axios from 'axios';
|
|
10
|
+
import dotenv from 'dotenv';
|
|
11
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
12
|
+
import { dirname } from 'path';
|
|
13
|
+
import { createRequire } from 'module';
|
|
14
|
+
// Same flatten logic PluginServer.ts uses for local/production runtime resolution - re-exported
|
|
15
|
+
// from the installed @aivin-labs/sdk (not vendored here) so deploy and runtime agree on exactly
|
|
16
|
+
// the same rules for what manifest.json's { ...commonFields, plugins: [...] } authoring shape
|
|
17
|
+
// expands into.
|
|
18
|
+
import { flattenManifestFile } from '@aivin-labs/sdk';
|
|
19
|
+
|
|
20
|
+
// Side-effect only import - installs the global Ctrl+C → abort-in-flight-requests wiring
|
|
21
|
+
// (`bin/lib/cancellation.mjs`) once, before any command runs. Must load before any lib file below
|
|
22
|
+
// makes its first axios call so the interceptor is already in place.
|
|
23
|
+
import './lib/cancellation.mjs';
|
|
24
|
+
|
|
25
|
+
import { DEFAULT_AIVIN_BASE_URL, GLOBAL_CREDENTIALS_PATH, fetchWebUrl, loadActiveContext, clearActiveContext } from './lib/context.mjs';
|
|
26
|
+
import { requireArg } from './lib/util.mjs';
|
|
27
|
+
import { readStdin, createFromJSON, createInteractive, validatePluginConfig, validateMcpProxyConfig } from './lib/scaffold.mjs';
|
|
28
|
+
import { buildDeploymentPayload, deployPlugin, incrementVersion } from './lib/deploy.mjs';
|
|
29
|
+
import { initInteractive, makePluginFromDescription, convertExistingProject } from './lib/codegen.mjs';
|
|
30
|
+
import { searchPlugins, showPluginInfo, askPlugin, streamPluginLogs, triggerPlugin, deletePluginCmd } from './lib/pluginTrigger.mjs';
|
|
31
|
+
import { connectorAuthHeaders, connectorBaseUrl, listConnectors, registerConnector, searchConnectors, buildRegisterConnectorDto } from './lib/connectors.mjs';
|
|
32
|
+
import { attachStore, createStore, deleteStore, detachStore, listStores, removeNode, setStoreEnabled } from './lib/store.mjs';
|
|
33
|
+
import { buildMcpManifest, parseMcpArgs, guessConnectorQueryFromEnvVarName, createMcpProxyPlugin, scanAndPublishMcp, registerMcpWatch, unwatchMcp, listMcpWatches, setFieldConnector } from './lib/mcpProxy.mjs';
|
|
34
|
+
import {
|
|
35
|
+
saveGlobalApiKey,
|
|
36
|
+
browserLogin,
|
|
37
|
+
basicLogin,
|
|
38
|
+
requireSavedApiKey,
|
|
39
|
+
logAccountIdentity,
|
|
40
|
+
listRemoteApiKeys,
|
|
41
|
+
generateApiKey,
|
|
42
|
+
revokeApiKeyByName,
|
|
43
|
+
tryFetchWhoami,
|
|
44
|
+
parseApiKeyClient,
|
|
45
|
+
} from './lib/auth.mjs';
|
|
46
|
+
import {
|
|
47
|
+
missionAuthHeaders,
|
|
48
|
+
missionServerUrl,
|
|
49
|
+
resolveWorkspace,
|
|
50
|
+
searchAgents,
|
|
51
|
+
pullAgentIntoWorkspace,
|
|
52
|
+
createAgent,
|
|
53
|
+
publishAgent,
|
|
54
|
+
installAgentInteractive,
|
|
55
|
+
listAgentsCmd,
|
|
56
|
+
} from './lib/workspace.mjs';
|
|
57
|
+
import { runMission, runBrowserMission } from './lib/mission.mjs';
|
|
58
|
+
import { DeviceAccess } from './lib/remote/constants.mjs';
|
|
59
|
+
import { configureProxy } from './lib/remote/netProxy.mjs';
|
|
60
|
+
import { DAEMON_RUNNING } from './lib/remote/daemonLock.mjs';
|
|
61
|
+
import { runPolicyCommand } from './lib/remote/policyCommand.mjs';
|
|
62
|
+
import { loadMascotSettings, saveMascotSettings } from './lib/remote/mascot/index.mjs';
|
|
63
|
+
import { MascotText, mascotLang, mascotText } from './lib/remote/mascot/strings.mjs';
|
|
64
|
+
import { RESTART_EXIT_CODE, UPDATE_ROLLED_BACK, UpdateStatus, cleanupRetired, downloadRoot, installUpdate, isStandaloneBinary, saveUpdateSettings } from './lib/selfUpdate.mjs';
|
|
65
|
+
import {
|
|
66
|
+
createAutomationJob,
|
|
67
|
+
listTasks,
|
|
68
|
+
listMyTasks,
|
|
69
|
+
getTaskById,
|
|
70
|
+
updateTaskById,
|
|
71
|
+
deleteTaskById,
|
|
72
|
+
createTask,
|
|
73
|
+
buildCreateTaskPayload,
|
|
74
|
+
pickWorkspaceAndProject,
|
|
75
|
+
createProjectCmd,
|
|
76
|
+
updateProjectCmd,
|
|
77
|
+
deleteProjectCmd,
|
|
78
|
+
listProjectsCmd,
|
|
79
|
+
} from './lib/tasks.mjs';
|
|
80
|
+
import {
|
|
81
|
+
startRemoteClient,
|
|
82
|
+
testRemoteConnection,
|
|
83
|
+
enableAutoStart,
|
|
84
|
+
disableAutoStart,
|
|
85
|
+
getAutoStartStatus,
|
|
86
|
+
buildDeviceProfile,
|
|
87
|
+
buildTools,
|
|
88
|
+
buildCatalog,
|
|
89
|
+
getOrCreateDeviceId,
|
|
90
|
+
resetDeviceId,
|
|
91
|
+
loadDeviceCredentials,
|
|
92
|
+
pairDevice,
|
|
93
|
+
listDevices,
|
|
94
|
+
unpairDevice,
|
|
95
|
+
isRemotePaused,
|
|
96
|
+
setRemotePaused,
|
|
97
|
+
getRecentLogs,
|
|
98
|
+
clearLogs,
|
|
99
|
+
memoryStats,
|
|
100
|
+
listMemoryItems,
|
|
101
|
+
searchMemory,
|
|
102
|
+
putMemoryItems,
|
|
103
|
+
deleteMemoryItems,
|
|
104
|
+
clearDeviceMemory,
|
|
105
|
+
createFileIndex,
|
|
106
|
+
indexRootsFor,
|
|
107
|
+
runRemoteMission,
|
|
108
|
+
MemoryKind,
|
|
109
|
+
} from './lib/remoteControl.mjs';
|
|
110
|
+
|
|
111
|
+
// Load env vars: the current project's `.env` first (any deliberate per-project override), THEN
|
|
112
|
+
// fill in AIVIN_BASE_URL/API_KEY/SDK_ENDPOINT from the machine's active context if the project
|
|
113
|
+
// didn't set them. `dotenv.config()` never overrides a variable that's already set, so a project's
|
|
114
|
+
// own `.env` (or a real shell env var) always wins over the global context, exactly like before -
|
|
115
|
+
// but nothing requires a project to have a `.env` at all anymore for the common single-context case.
|
|
116
|
+
// `quiet: true` - otherwise dotenv prints an "injected env" tip line to stdout on every run, which
|
|
117
|
+
// would corrupt `--json-output` mode (meant for clean, parseable JSON on stdout).
|
|
118
|
+
dotenv.config({ quiet: true });
|
|
119
|
+
|
|
120
|
+
{
|
|
121
|
+
const activeContext = loadActiveContext();
|
|
122
|
+
if (activeContext) {
|
|
123
|
+
if (!process.env.AIVIN_BASE_URL) process.env.AIVIN_BASE_URL = activeContext.base_url;
|
|
124
|
+
if (!process.env.API_KEY) process.env.API_KEY = activeContext.api_key;
|
|
125
|
+
if (!process.env.SDK_ENDPOINT && activeContext.sdk_endpoint) process.env.SDK_ENDPOINT = activeContext.sdk_endpoint;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
130
|
+
|
|
131
|
+
const __dirname = dirname(__filename);
|
|
132
|
+
|
|
133
|
+
// This CLI's own version (`aivin --version`) - distinct from whatever @aivin-labs/sdk version a
|
|
134
|
+
// given plugin project has installed. See lib/scaffold.mjs for how a fresh scaffold's `@aivin-labs/
|
|
135
|
+
// sdk` dependency pin is resolved (from the actually-installed sdk, not from here).
|
|
136
|
+
// Bản tệp chạy đóng gói (scripts/build-binary.mjs) không có package.json trên đĩa — phiên bản được ghi sẵn lúc build.
|
|
137
|
+
const CLI_PACKAGE_JSON = process.env.AIVIN_CLI_BINARY
|
|
138
|
+
? { version: process.env.AIVIN_CLI_BINARY, engines: {} }
|
|
139
|
+
: JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
|
|
140
|
+
|
|
141
|
+
const CLI_VERSION = CLI_PACKAGE_JSON.version;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* `aivin start` spawns the plugin project's own installed `@aivin-labs/sdk`'s `bin/server.mjs`,
|
|
145
|
+
* which loads `src/main.ts` directly via Node's native TS execution (no separate compile step) -
|
|
146
|
+
* the same mechanism this CLI's own `engines.node` field (">=22.0.0") documents as required for
|
|
147
|
+
* itself. Node <22 doesn't strip TS types at all, so that failure doesn't surface as anything about
|
|
148
|
+
* Node versions - it's a raw loader error ("Unknown file extension \".ts\"") thrown from deep inside
|
|
149
|
+
* `server.mjs`, giving no hint that the fix is just "use a newer Node". Check the constraint up
|
|
150
|
+
* front instead, once, with a message that says exactly what's wrong and how to fix it.
|
|
151
|
+
*/
|
|
152
|
+
function checkNodeVersion() {
|
|
153
|
+
const required = CLI_PACKAGE_JSON.engines?.node;
|
|
154
|
+
const requiredMajor = required && parseInt(required.match(/(\d+)/)?.[1], 10);
|
|
155
|
+
const currentMajor = parseInt(process.versions.node.split('.')[0], 10);
|
|
156
|
+
if (requiredMajor && currentMajor < requiredMajor) {
|
|
157
|
+
console.error(
|
|
158
|
+
chalk.red(`❌ Node ${process.version} detected - aivin requires Node ${required} (native TypeScript execution).`),
|
|
159
|
+
);
|
|
160
|
+
console.error(chalk.gray(` Switch versions (e.g. \`nvm use ${requiredMajor}\`) and try again.`));
|
|
161
|
+
process.exit(1);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Resolves `bin/server.mjs` from the CURRENT PROJECT's own installed `@aivin-labs/sdk` (not this
|
|
167
|
+
* CLI's install location - after the cli/sdk package split those are two different places, and
|
|
168
|
+
* `aivin start`/`aivin test` must run whatever sdk version the plugin project actually depends on,
|
|
169
|
+
* the same one its own `npm install` resolved). Resolves `@aivin-labs/sdk/package.json` (an
|
|
170
|
+
* explicit "./package.json" export, see the sdk's package.json) via Node's normal module resolution
|
|
171
|
+
* rooted at the current directory, then derives `bin/server.mjs` from its location by plain path
|
|
172
|
+
* math - deliberately not a second module-specifier resolution, since `bin/server.mjs` itself isn't
|
|
173
|
+
* (and doesn't need to be) part of the sdk's public `exports` map.
|
|
174
|
+
*/
|
|
175
|
+
function resolveLocalSdkServerPath(currentDir = process.cwd()) {
|
|
176
|
+
const localRequire = createRequire(pathToFileURL(path.join(currentDir, 'noop.cjs')).href);
|
|
177
|
+
let sdkPackageJsonPath;
|
|
178
|
+
try {
|
|
179
|
+
sdkPackageJsonPath = localRequire.resolve('@aivin-labs/sdk/package.json');
|
|
180
|
+
} catch (error) {
|
|
181
|
+
throw new Error(
|
|
182
|
+
`Could not find @aivin-labs/sdk installed in ${currentDir} - run \`npm install\` first.`,
|
|
183
|
+
{ cause: error },
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
return path.join(path.dirname(sdkPackageJsonPath), 'bin', 'server.mjs');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const program = new Command();
|
|
190
|
+
|
|
191
|
+
program.name('aivin').description('aivin CLI - scaffold, run, and deploy Aivin plugins').version(CLI_VERSION);
|
|
192
|
+
|
|
193
|
+
// Command: create plugin
|
|
194
|
+
program
|
|
195
|
+
.command('create [name]')
|
|
196
|
+
.description('Create new plugin')
|
|
197
|
+
.option('--json <config>', 'JSON config (AI mode)')
|
|
198
|
+
.option('--stdin', 'Read from stdin')
|
|
199
|
+
.option('--name <name>', 'Plugin name (if not specified, will prompt)')
|
|
200
|
+
.option('--silent', 'Silent mode')
|
|
201
|
+
.option('--json-output', 'JSON output')
|
|
202
|
+
.action(async (name, options) => {
|
|
203
|
+
if (name) options.name = name;
|
|
204
|
+
try {
|
|
205
|
+
let result;
|
|
206
|
+
|
|
207
|
+
if (options.stdin) {
|
|
208
|
+
const stdinData = await readStdin();
|
|
209
|
+
result = await createFromJSON(stdinData, options);
|
|
210
|
+
} else if (options.json) {
|
|
211
|
+
result = await createFromJSON(options.json, options);
|
|
212
|
+
} else {
|
|
213
|
+
result = await createInteractive(options);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (options.jsonOutput && result) {
|
|
217
|
+
console.log(JSON.stringify(result, null, 2));
|
|
218
|
+
}
|
|
219
|
+
} catch (error) {
|
|
220
|
+
if (options.jsonOutput) {
|
|
221
|
+
console.log(
|
|
222
|
+
JSON.stringify(
|
|
223
|
+
{
|
|
224
|
+
success: false,
|
|
225
|
+
error: error.message,
|
|
226
|
+
code: error.code || 'ERROR',
|
|
227
|
+
},
|
|
228
|
+
null,
|
|
229
|
+
2,
|
|
230
|
+
),
|
|
231
|
+
);
|
|
232
|
+
} else if (!options.silent) {
|
|
233
|
+
console.error(chalk.red('❌'), error.message);
|
|
234
|
+
}
|
|
235
|
+
process.exit(1);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// Command: init plugin - guided one-step replacement for `create` + `plugin make`
|
|
240
|
+
program
|
|
241
|
+
.command('init [name]')
|
|
242
|
+
.description('Set up a new plugin step by step: asks what it should do, then generates real working code from that description')
|
|
243
|
+
.option('--name <name>', 'Plugin name (if not specified, will prompt)')
|
|
244
|
+
.option('--model <model>', 'LLM model to use for generation')
|
|
245
|
+
.option('--provider <provider>', 'LLM provider to use for generation')
|
|
246
|
+
.action(async (name, options) => {
|
|
247
|
+
if (name) options.name = name;
|
|
248
|
+
try {
|
|
249
|
+
await initInteractive(options);
|
|
250
|
+
} catch (error) {
|
|
251
|
+
console.error(chalk.red('❌'), error.message);
|
|
252
|
+
process.exit(1);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// Command: Validate plugin config
|
|
257
|
+
program
|
|
258
|
+
.command('validate')
|
|
259
|
+
.description('Validate manifest.json in the current directory (or --json/--stdin for scripted use)')
|
|
260
|
+
.option('--json <config>', 'JSON config, instead of reading manifest.json from the current directory')
|
|
261
|
+
.option('--stdin', 'Read JSON config from stdin, instead of reading manifest.json')
|
|
262
|
+
.option('--json-output', 'JSON output')
|
|
263
|
+
.action(async (options) => {
|
|
264
|
+
try {
|
|
265
|
+
let configData;
|
|
266
|
+
|
|
267
|
+
if (options.stdin) {
|
|
268
|
+
configData = await readStdin();
|
|
269
|
+
} else if (options.json) {
|
|
270
|
+
configData = options.json;
|
|
271
|
+
} else {
|
|
272
|
+
// Simple, no-flags default: validate manifest.json in the current directory - the case
|
|
273
|
+
// you actually want most of the time (`aivin validate` from inside your plugin project).
|
|
274
|
+
// --json/--stdin remain for scripted/CI use where the config isn't a file on disk yet.
|
|
275
|
+
const manifestPath = path.join(process.cwd(), 'manifest.json');
|
|
276
|
+
if (!fs.existsSync(manifestPath)) {
|
|
277
|
+
throw new Error('No manifest.json found in the current directory. Pass --json <config> or --stdin instead.');
|
|
278
|
+
}
|
|
279
|
+
configData = fs.readFileSync(manifestPath, 'utf8');
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Expand the default { ...commonFields, plugins: [...] } shape and validate every entry -
|
|
283
|
+
// flattenManifestFile itself throws on structural problems (empty plugins[], missing
|
|
284
|
+
// id/name/func, bare top-level array).
|
|
285
|
+
const config = flattenManifestFile(JSON.parse(configData));
|
|
286
|
+
const entries = Array.isArray(config) ? config : [config];
|
|
287
|
+
const errors = entries.flatMap((entry, i) =>
|
|
288
|
+
validatePluginConfig(entry).errors.map((e) =>
|
|
289
|
+
entries.length > 1 ? `plugins[${i}] (${entry.name || 'unnamed'}): ${e}` : e,
|
|
290
|
+
),
|
|
291
|
+
);
|
|
292
|
+
const result = { valid: errors.length === 0, errors };
|
|
293
|
+
|
|
294
|
+
if (options.jsonOutput) {
|
|
295
|
+
console.log(
|
|
296
|
+
JSON.stringify(
|
|
297
|
+
{
|
|
298
|
+
valid: result.valid,
|
|
299
|
+
errors: result.errors,
|
|
300
|
+
},
|
|
301
|
+
null,
|
|
302
|
+
2,
|
|
303
|
+
),
|
|
304
|
+
);
|
|
305
|
+
} else {
|
|
306
|
+
if (result.valid) {
|
|
307
|
+
console.log(chalk.green('✅ Valid'));
|
|
308
|
+
} else {
|
|
309
|
+
console.log(chalk.red('❌ Invalid:'));
|
|
310
|
+
result.errors.forEach((error) => console.log(` • ${error}`));
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (!result.valid) process.exit(1);
|
|
315
|
+
} catch (error) {
|
|
316
|
+
if (options.jsonOutput) {
|
|
317
|
+
console.log(JSON.stringify({ valid: false, error: error.message }, null, 2));
|
|
318
|
+
} else {
|
|
319
|
+
console.error(chalk.red('❌'), error.message);
|
|
320
|
+
}
|
|
321
|
+
process.exit(1);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
// Command: start plugin server
|
|
326
|
+
program
|
|
327
|
+
.command('start')
|
|
328
|
+
.description('Start plugin server')
|
|
329
|
+
.option('--debug', 'Log every sdk.* call live as it happens (human-readable), not just the final trace summary')
|
|
330
|
+
.option('--debug-json', 'Same live per-call logging as --debug, but one JSON object per line on stdout - for a script/coding agent to parse instead of a human')
|
|
331
|
+
.option('--no-watch', 'Disable hot-reload - restart manually (Ctrl+C + `aivin start` again) after editing src/ instead')
|
|
332
|
+
.action((options) => {
|
|
333
|
+
checkNodeVersion();
|
|
334
|
+
let serverPath;
|
|
335
|
+
try {
|
|
336
|
+
serverPath = resolveLocalSdkServerPath();
|
|
337
|
+
} catch (error) {
|
|
338
|
+
console.error(chalk.red('❌'), error.message);
|
|
339
|
+
process.exit(1);
|
|
340
|
+
}
|
|
341
|
+
const debugEnv = options.debugJson ? { SDK_DEBUG: 'json' } : options.debug ? { SDK_DEBUG: 'true' } : {};
|
|
342
|
+
const watchEnv = options.watch === false ? { AIVIN_START_WATCH: 'false' } : {};
|
|
343
|
+
const child = spawn('node', [serverPath], {
|
|
344
|
+
stdio: 'inherit',
|
|
345
|
+
env: { ...process.env, ...debugEnv, ...watchEnv },
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
child.on('error', (error) => {
|
|
349
|
+
console.error(chalk.red('❌'), error.message);
|
|
350
|
+
process.exit(1);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
child.on('exit', (code) => {
|
|
354
|
+
if (code !== 0) {
|
|
355
|
+
process.exit(code);
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
// Command: deploy plugin to server (always private to your org - see buildDeploymentPayload's
|
|
361
|
+
// doc comment above for why there's no public/store-submission scope here)
|
|
362
|
+
program
|
|
363
|
+
.command('deploy')
|
|
364
|
+
.description('Deploy plugin to your org on the Aivin server')
|
|
365
|
+
.action(async () => {
|
|
366
|
+
try {
|
|
367
|
+
await deployPlugin({
|
|
368
|
+
endpointPath: '/plugins/deploy',
|
|
369
|
+
label: 'Deploying plugin',
|
|
370
|
+
});
|
|
371
|
+
} catch (error) {
|
|
372
|
+
console.error(chalk.red('❌'), error.message);
|
|
373
|
+
process.exit(1);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// Command: deploy to a throwaway test instance (backend rejects this in production)
|
|
378
|
+
program
|
|
379
|
+
.command('test')
|
|
380
|
+
.description(
|
|
381
|
+
'Deploy to a non-production test instance, then smoke-test it with generated input and save a report to .test/',
|
|
382
|
+
)
|
|
383
|
+
.option('--workspace <id>', 'Workspace id to run the smoke test against (default: auto-picks your first one)')
|
|
384
|
+
.option('--no-smoke-test', 'Only deploy - skip the generated-input invoke test and report')
|
|
385
|
+
.option('--verify-proxy', 'Also invoke MCP proxy entries for real (empty input) instead of skipping them - only use if you know the underlying tool(s) have no meaningful side effects')
|
|
386
|
+
.action(async (options) => {
|
|
387
|
+
try {
|
|
388
|
+
await deployPlugin({
|
|
389
|
+
endpointPath: '/plugins/test/deploy',
|
|
390
|
+
label: 'Deploying to test instance',
|
|
391
|
+
smokeTest: options.smokeTest !== false,
|
|
392
|
+
workspaceOverride: options.workspace,
|
|
393
|
+
verifyProxy: options.verifyProxy,
|
|
394
|
+
});
|
|
395
|
+
} catch (error) {
|
|
396
|
+
console.error(chalk.red('❌'), error.message);
|
|
397
|
+
process.exit(1);
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
const pluginCommand = program.command('plugin').description('AI-assisted plugin authoring');
|
|
402
|
+
|
|
403
|
+
pluginCommand
|
|
404
|
+
.command('search [query]')
|
|
405
|
+
.description("Search the platform's plugin ecosystem for something to reuse instead of writing it yourself")
|
|
406
|
+
.option('--workspace <id>', 'Restrict to plugins visible in this workspace (default: your whole org)')
|
|
407
|
+
.option('--mcp <server_id>', 'List every tool/resource/prompt plugin generated from one MCP server (the id printed by `aivin mcp`/`aivin plugin search`, e.g. "modelcontextprotocol-servers-src-everything") instead of doing a text search')
|
|
408
|
+
.option('--store <store_id>', 'Restrict to plugins hosted on one self-hosted plugin store (the id printed by `aivin pluginstore ls`) - combines with the text query/--mcp, not a replacement for them')
|
|
409
|
+
.option('--limit <n>', 'Max results to show')
|
|
410
|
+
.option('--plain', 'Print a flat list instead of the interactive browser (for scripts/CI)')
|
|
411
|
+
.action(async (query, options) => {
|
|
412
|
+
try {
|
|
413
|
+
// --mcp is an exact-id lookup, not a text search - the query string is optional in that mode.
|
|
414
|
+
if (!options.mcp) {
|
|
415
|
+
query = await requireArg(query, { prompt: 'What are you looking for?', usage: 'Usage: aivin plugin search "<query>"' });
|
|
416
|
+
}
|
|
417
|
+
await searchPlugins(query, options);
|
|
418
|
+
} catch (error) {
|
|
419
|
+
console.error(chalk.red('❌'), error.message);
|
|
420
|
+
process.exit(1);
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
pluginCommand
|
|
425
|
+
.command('info <id>')
|
|
426
|
+
.description("Show one plugin's detail (input/output schema, setup needs) directly by id, no search query needed")
|
|
427
|
+
.option('--workspace <id>', 'Restrict to plugins visible in this workspace (default: your whole org)')
|
|
428
|
+
.option('--plain', 'Print flat instead of the interactive browser, if falling back to closest-match results')
|
|
429
|
+
.action(async (id, options) => {
|
|
430
|
+
try {
|
|
431
|
+
await showPluginInfo(id, options);
|
|
432
|
+
} catch (error) {
|
|
433
|
+
console.error(chalk.red('❌'), error.message);
|
|
434
|
+
process.exit(1);
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
pluginCommand
|
|
439
|
+
.command('ask [mission]')
|
|
440
|
+
.description('One-shot: search for the best-matching plugin for a plain-language mission and trigger it right away, like an agent would')
|
|
441
|
+
.option('--top <n>', 'How many candidates to consider/print as runner-up context (default 5) - only the top match is ever run')
|
|
442
|
+
.option('-i, --input <json>', 'Input fields as a JSON string - skips the interactive field-by-field prompt')
|
|
443
|
+
.option('--workspace <id>', 'Workspace id to search/run against (default: auto-picks your first one)')
|
|
444
|
+
.option('--agent <id>', 'Agent id to run as, if the plugin needs one for HIL/confirm behavior to be accurate')
|
|
445
|
+
.option('--watch-logs', "Also stream the chosen plugin's own live console output inline")
|
|
446
|
+
.option('--no-auth-prompt', "Don't offer to connect/configure a missing connector interactively when the run comes back needing one - just print the result and exit")
|
|
447
|
+
.option('--save', 'Write this run\'s result to .test/trigger/<timestamp>.json for later --compare')
|
|
448
|
+
.option('--compare <file>', 'Diff this run\'s result against a previously --save\'d .test/trigger/*.json file')
|
|
449
|
+
.action(async (mission, options) => {
|
|
450
|
+
try {
|
|
451
|
+
await askPlugin(mission, options);
|
|
452
|
+
} catch (error) {
|
|
453
|
+
console.error(chalk.red('❌'), error.message);
|
|
454
|
+
process.exit(1);
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
pluginCommand
|
|
459
|
+
.command('make [description]')
|
|
460
|
+
.description('Generate src/main.ts from a natural-language business description')
|
|
461
|
+
.option('--model <model>', 'LLM model to use for generation')
|
|
462
|
+
.option('--provider <provider>', 'LLM provider to use for generation')
|
|
463
|
+
.action(async (description, options) => {
|
|
464
|
+
try {
|
|
465
|
+
description = await requireArg(description, { prompt: 'What should this plugin do?', usage: 'Usage: aivin plugin make "<description>"' });
|
|
466
|
+
await makePluginFromDescription(description, options);
|
|
467
|
+
} catch (error) {
|
|
468
|
+
console.error(chalk.red('❌'), error.message);
|
|
469
|
+
process.exit(1);
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
pluginCommand
|
|
474
|
+
.command('convert [hint]')
|
|
475
|
+
.description('Turn an existing project in the current directory into an Aivin plugin')
|
|
476
|
+
.option('--model <model>', 'LLM model to use for generation')
|
|
477
|
+
.option('--provider <provider>', 'LLM provider to use for generation')
|
|
478
|
+
.option('--force', 'Re-run conversion even if src/main.ts already exists (e.g. redo a previous bad/stale result)')
|
|
479
|
+
.action(async (hint, options) => {
|
|
480
|
+
try {
|
|
481
|
+
await convertExistingProject(hint, options);
|
|
482
|
+
} catch (error) {
|
|
483
|
+
console.error(chalk.red('❌'), error.message);
|
|
484
|
+
process.exit(1);
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
pluginCommand
|
|
489
|
+
.command('trigger [mission] [input]')
|
|
490
|
+
.description('Invoke this deployed plugin for real and print the result - like the platform\'s Playground')
|
|
491
|
+
.option('--id <pluginId>', 'Plugin id to trigger directly - skips the local manifest.json lookup (e.g. for `aivin mcp` plugins, which have no local project directory)')
|
|
492
|
+
.option('--func <name>', 'Which function to trigger, for a multi-function plugin (matches name/func/id) - ignored when --id is given')
|
|
493
|
+
.option('--workspace <id>', 'Workspace id to run against (default: auto-picks your first one)')
|
|
494
|
+
.option('--agent <id>', 'Agent id to run as, if the plugin needs one for HIL/confirm behavior to be accurate')
|
|
495
|
+
.option('--watch-logs', 'Also stream the plugin\'s own live console output inline (same feed as `aivin plugin logs`) instead of needing a second terminal - requires permission to view that plugin\'s logs (your own/org\'s deployments; most store plugins from other orgs will just skip this and fall back to the REST result only)')
|
|
496
|
+
.option('--no-auth-prompt', "Don't offer to connect/configure a missing connector interactively when the run comes back needing one - just print the result and exit")
|
|
497
|
+
.option('--save', 'Write this run\'s result to .test/trigger/<timestamp>.json for later --compare')
|
|
498
|
+
.option('--compare <file>', 'Diff this run\'s result against a previously --save\'d .test/trigger/*.json file')
|
|
499
|
+
.action(async (mission, input, options) => {
|
|
500
|
+
try {
|
|
501
|
+
await triggerPlugin(mission, input, options);
|
|
502
|
+
} catch (error) {
|
|
503
|
+
console.error(chalk.red('❌'), error.message);
|
|
504
|
+
process.exit(1);
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
pluginCommand
|
|
509
|
+
.command('logs [pluginId]')
|
|
510
|
+
.description('Tail a deployed plugin\'s own console output live (defaults to the current directory\'s manifest.json id)')
|
|
511
|
+
.option('--func <name>', 'Which function\'s id to resolve, for a multi-function plugin (only used when pluginId is omitted)')
|
|
512
|
+
.action(async (pluginId, options) => {
|
|
513
|
+
try {
|
|
514
|
+
await streamPluginLogs(pluginId, options);
|
|
515
|
+
} catch (error) {
|
|
516
|
+
console.error(chalk.red('❌'), error.message);
|
|
517
|
+
process.exit(1);
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
pluginCommand
|
|
522
|
+
.command('delete [id]')
|
|
523
|
+
.description("Delete a plugin you own, or every plugin from one batch deploy at once with --group <groupId> (e.g. everything `aivin mcp <url>` generated in one run - see the group_id it prints after deploying)")
|
|
524
|
+
.option('--group <groupId>', 'Delete every plugin sharing this group_id instead of a single plugin by id')
|
|
525
|
+
.option('-y, --yes', 'Skip the confirmation prompt (for scripts/CI)')
|
|
526
|
+
.action(async (id, options) => {
|
|
527
|
+
try {
|
|
528
|
+
await deletePluginCmd(id, options);
|
|
529
|
+
} catch (error) {
|
|
530
|
+
console.error(chalk.red('❌'), error.message);
|
|
531
|
+
process.exit(1);
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
const connectorCommand = program.command('connector').description('Register and discover reusable connectors (OAuth apps / credential-form namespaces)');
|
|
536
|
+
|
|
537
|
+
connectorCommand
|
|
538
|
+
.command('register')
|
|
539
|
+
.description('Register a new connector namespace, interactively')
|
|
540
|
+
.action(async () => {
|
|
541
|
+
try {
|
|
542
|
+
await registerConnector();
|
|
543
|
+
} catch (error) {
|
|
544
|
+
console.error(chalk.red('❌'), error.message);
|
|
545
|
+
process.exit(1);
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
connectorCommand
|
|
550
|
+
.command('search [query]')
|
|
551
|
+
.description("Search connectors for something to reuse instead of registering a new one")
|
|
552
|
+
.option('--limit <n>', 'Max results to show')
|
|
553
|
+
.option('--plain', 'Print a flat list instead of the interactive browser (for scripts/CI)')
|
|
554
|
+
.action(async (query, options) => {
|
|
555
|
+
try {
|
|
556
|
+
query = await requireArg(query, { prompt: 'What are you looking for?', usage: 'Usage: aivin connector search "<query>"' });
|
|
557
|
+
await searchConnectors(query, options);
|
|
558
|
+
} catch (error) {
|
|
559
|
+
console.error(chalk.red('❌'), error.message);
|
|
560
|
+
process.exit(1);
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
connectorCommand
|
|
565
|
+
.command('list')
|
|
566
|
+
.description('List connectors visible to your org')
|
|
567
|
+
.option('--page <n>', 'Page number')
|
|
568
|
+
.option('--limit <n>', 'Items per page')
|
|
569
|
+
.option('--include-deprecated', "Also show your org's deprecated connectors (hidden by default)")
|
|
570
|
+
.option('--plain', 'Print a flat list instead of the interactive browser (for scripts/CI)')
|
|
571
|
+
.action(async (options) => {
|
|
572
|
+
try {
|
|
573
|
+
await listConnectors(options);
|
|
574
|
+
} catch (error) {
|
|
575
|
+
console.error(chalk.red('❌'), error.message);
|
|
576
|
+
process.exit(1);
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
connectorCommand
|
|
581
|
+
.command('deprecate [id]')
|
|
582
|
+
.description("Hide a connector you own from search/list without breaking plugins already using it")
|
|
583
|
+
.action(async (id) => {
|
|
584
|
+
try {
|
|
585
|
+
id = await requireArg(id, { prompt: 'Connector id to deprecate:', usage: 'Usage: aivin connector deprecate <id>' });
|
|
586
|
+
await axios.post(`${connectorBaseUrl()}/connectors/${encodeURIComponent(id)}/deprecate`, {}, connectorAuthHeaders());
|
|
587
|
+
console.log(chalk.green(`✅ "${id}" is now deprecated - still usable, hidden from new search/list.`));
|
|
588
|
+
} catch (error) {
|
|
589
|
+
const message = error.response?.data?.message || error.message;
|
|
590
|
+
console.error(chalk.red('❌'), message);
|
|
591
|
+
process.exit(1);
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
connectorCommand
|
|
596
|
+
.command('undeprecate [id]')
|
|
597
|
+
.description('Make a previously-deprecated connector you own discoverable again')
|
|
598
|
+
.action(async (id) => {
|
|
599
|
+
try {
|
|
600
|
+
id = await requireArg(id, { prompt: 'Connector id to un-deprecate:', usage: 'Usage: aivin connector undeprecate <id>' });
|
|
601
|
+
await axios.post(`${connectorBaseUrl()}/connectors/${encodeURIComponent(id)}/undeprecate`, {}, connectorAuthHeaders());
|
|
602
|
+
console.log(chalk.green(`✅ "${id}" is discoverable again.`));
|
|
603
|
+
} catch (error) {
|
|
604
|
+
const message = error.response?.data?.message || error.message;
|
|
605
|
+
console.error(chalk.red('❌'), message);
|
|
606
|
+
process.exit(1);
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
const pluginStoreCommand = program
|
|
611
|
+
.command('pluginstore')
|
|
612
|
+
.description('Self-hosted aivin-service worker (Docker) - attach it to your org as a plugin store. See docs/GETTING_STARTED.md.');
|
|
613
|
+
|
|
614
|
+
pluginStoreCommand
|
|
615
|
+
.command('create [store_id]')
|
|
616
|
+
.description('Create a new plugin store + attach this machine as its first node')
|
|
617
|
+
.option('--label <label>', 'Display label for the store (defaults to store_id)')
|
|
618
|
+
.option('--node-label <label>', 'Display label for this node/instance')
|
|
619
|
+
.option('--data-dir <path>', 'Where to write worker-identity.json (default: ~/.aivin/service-data)')
|
|
620
|
+
.action(async (storeId, options) => {
|
|
621
|
+
try {
|
|
622
|
+
await createStore(storeId, options);
|
|
623
|
+
} catch (error) {
|
|
624
|
+
console.error(chalk.red('❌'), error.message);
|
|
625
|
+
process.exit(1);
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
pluginStoreCommand
|
|
630
|
+
.command('attach [store_id]')
|
|
631
|
+
.description('Attach this machine as another node of an existing plugin store')
|
|
632
|
+
.option('--node-label <label>', 'Display label for this node/instance')
|
|
633
|
+
.option('--data-dir <path>', 'Where to write worker-identity.json (default: ~/.aivin/service-data)')
|
|
634
|
+
.action(async (storeId, options) => {
|
|
635
|
+
try {
|
|
636
|
+
await attachStore(storeId, options);
|
|
637
|
+
} catch (error) {
|
|
638
|
+
console.error(chalk.red('❌'), error.message);
|
|
639
|
+
process.exit(1);
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
pluginStoreCommand
|
|
644
|
+
.command('ls')
|
|
645
|
+
.description('List plugin stores visible to your org, with online/offline status per node')
|
|
646
|
+
.action(async (options) => {
|
|
647
|
+
try {
|
|
648
|
+
await listStores(options);
|
|
649
|
+
} catch (error) {
|
|
650
|
+
console.error(chalk.red('❌'), error.message);
|
|
651
|
+
process.exit(1);
|
|
652
|
+
}
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
pluginStoreCommand
|
|
656
|
+
.command('enable [store_id]')
|
|
657
|
+
.description('Enable a store for your org (org admin only)')
|
|
658
|
+
.action(async (storeId) => {
|
|
659
|
+
try {
|
|
660
|
+
storeId = await requireArg(storeId, { prompt: 'Store id to enable:', usage: 'Usage: aivin pluginstore enable <store_id>' });
|
|
661
|
+
await setStoreEnabled(storeId, true);
|
|
662
|
+
} catch (error) {
|
|
663
|
+
console.error(chalk.red('❌'), error.message);
|
|
664
|
+
process.exit(1);
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
pluginStoreCommand
|
|
669
|
+
.command('disable [store_id]')
|
|
670
|
+
.description('Disable a store for your org without deleting it (org admin only)')
|
|
671
|
+
.action(async (storeId) => {
|
|
672
|
+
try {
|
|
673
|
+
storeId = await requireArg(storeId, { prompt: 'Store id to disable:', usage: 'Usage: aivin pluginstore disable <store_id>' });
|
|
674
|
+
await setStoreEnabled(storeId, false);
|
|
675
|
+
} catch (error) {
|
|
676
|
+
console.error(chalk.red('❌'), error.message);
|
|
677
|
+
process.exit(1);
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
pluginStoreCommand
|
|
682
|
+
.command('rm [store_id]')
|
|
683
|
+
.description('Delete a store - revokes EVERY node attached to it, not just this machine (org admin only)')
|
|
684
|
+
.option('-y, --yes', 'Skip the confirmation prompt')
|
|
685
|
+
.action(async (storeId, options) => {
|
|
686
|
+
try {
|
|
687
|
+
storeId = await requireArg(storeId, { prompt: 'Store id to delete:', usage: 'Usage: aivin pluginstore rm <store_id>' });
|
|
688
|
+
await deleteStore(storeId, options);
|
|
689
|
+
} catch (error) {
|
|
690
|
+
console.error(chalk.red('❌'), error.message);
|
|
691
|
+
process.exit(1);
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
pluginStoreCommand
|
|
696
|
+
.command('rm-node [store_id] [node_id]')
|
|
697
|
+
.description('Remove one node from a store (e.g. one that never came online) without touching its other nodes - org admin not required')
|
|
698
|
+
.option('-y, --yes', 'Skip the confirmation prompt')
|
|
699
|
+
.action(async (storeId, nodeId, options) => {
|
|
700
|
+
try {
|
|
701
|
+
await removeNode(storeId, nodeId, options);
|
|
702
|
+
} catch (error) {
|
|
703
|
+
console.error(chalk.red('❌'), error.message);
|
|
704
|
+
process.exit(1);
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
pluginStoreCommand
|
|
709
|
+
.command('detach')
|
|
710
|
+
.description("Remove THIS machine's pairing only (local file only, no BE call) - the running aivin-service picks it up automatically")
|
|
711
|
+
.option('--data-dir <path>', 'Where worker-identity.json lives (default: ~/.aivin/service-data)')
|
|
712
|
+
.action((options) => {
|
|
713
|
+
try {
|
|
714
|
+
detachStore(options);
|
|
715
|
+
} catch (error) {
|
|
716
|
+
console.error(chalk.red('❌'), error.message);
|
|
717
|
+
process.exit(1);
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
|
|
721
|
+
const mcpCommand = program
|
|
722
|
+
.command('mcp')
|
|
723
|
+
.description('MCP proxy plugins - wrap an external MCP server tool/resource/prompt, no code required');
|
|
724
|
+
|
|
725
|
+
mcpCommand
|
|
726
|
+
.argument('[url]', 'GitHub/GitLab/npm/Smithery URL, or a live MCP server URL, to scan and convert')
|
|
727
|
+
.option('--publish', 'Deploy to your org, then submit for community store review (needs admin approval)')
|
|
728
|
+
.option('--private', 'Deploy to your org only - default')
|
|
729
|
+
.option('--org', 'Alias of --private - there is no narrower per-workspace scope today')
|
|
730
|
+
.option('--quiet', 'Skip live progress output while scanning (on by default otherwise)')
|
|
731
|
+
.option('--auth', 'Đánh dấu MCP này cần credential -> BE sinh connection_id, CLI hỏi gắn connector (OAuth HOẶC credential_form tuỳ chọn lúc đó). Dùng cho MCP cần API key/token mà scan không tự nhận ra')
|
|
732
|
+
.option('--oauth', 'Bí danh cũ của --auth (giữ để không phá lệnh đã dùng)')
|
|
733
|
+
.option('--test-token <token>', 'Access token dùng THỬ để đọc tool của remote MCP cần OAuth (Notion/Slack/Linear/Figma...). Chỉ dùng lúc quét, KHÔNG lưu lại - xem test_token trong plugin-store.proto')
|
|
734
|
+
.option('-y, --yes', 'Skip the deploy confirmation prompt (required in non-TTY/CI contexts, which otherwise now refuse to deploy at all - see scanAndPublishMcp)')
|
|
735
|
+
.action(async (url, options) => {
|
|
736
|
+
try {
|
|
737
|
+
url = await requireArg(url, {
|
|
738
|
+
prompt: 'GitHub/GitLab/npm/Smithery URL, or a live MCP server URL:',
|
|
739
|
+
usage: 'Usage: aivin mcp <url> [--publish|--private|--org]',
|
|
740
|
+
});
|
|
741
|
+
await scanAndPublishMcp(url, options);
|
|
742
|
+
} catch (error) {
|
|
743
|
+
console.error(chalk.red('❌'), error.message);
|
|
744
|
+
process.exit(1);
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
mcpCommand
|
|
749
|
+
.command('create [name]')
|
|
750
|
+
.description('Scaffold a manifest-only plugin that proxies to an external MCP server')
|
|
751
|
+
.option('--transport <transport>', 'stdio | sse')
|
|
752
|
+
.option('--command <command>', 'Command to launch the MCP server (stdio transport)')
|
|
753
|
+
.option('--args <args>', 'Space-separated args for --command (stdio transport)')
|
|
754
|
+
.option('--url <url>', 'Remote MCP server URL (sse transport)')
|
|
755
|
+
.option('--kind <kind>', 'tool | resource | prompt (default: tool)')
|
|
756
|
+
.option('--tool-name <name>', 'MCP tool name (kind=tool)')
|
|
757
|
+
.option('--resource-uri <uri>', 'MCP resource URI (kind=resource)')
|
|
758
|
+
.option('--resource-mime-type <mime>', 'MIME type of the resource (kind=resource)')
|
|
759
|
+
.option('--prompt-name <name>', 'MCP prompt name (kind=prompt)')
|
|
760
|
+
.option('--description <description>', 'Plugin description')
|
|
761
|
+
.option(
|
|
762
|
+
'--auth-secret-key <key>',
|
|
763
|
+
'Name of the workspace secret to use as the token/credential, if the MCP server needs auth',
|
|
764
|
+
)
|
|
765
|
+
.option('--auth-type <type>', 'auth_type value to send (default: "bearer" when --auth-secret-key is set) - check your backend for which values it supports')
|
|
766
|
+
.option('--connector <id>', "Existing connector id for this plugin's connection_id (readiness/\"needs login\" display only - does NOT inject anything into the running MCP server; run with no flags for the interactive per-variable auth setup that actually does)")
|
|
767
|
+
.action(async (name, options) => {
|
|
768
|
+
try {
|
|
769
|
+
name = await requireArg(name, { prompt: 'Plugin name (lowercase letters, numbers, hyphens):', usage: 'Usage: aivin mcp create <name>' });
|
|
770
|
+
await createMcpProxyPlugin(name, options);
|
|
771
|
+
} catch (error) {
|
|
772
|
+
console.error(chalk.red('❌'), error.message);
|
|
773
|
+
process.exit(1);
|
|
774
|
+
}
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
mcpCommand
|
|
778
|
+
.command('watch [url]')
|
|
779
|
+
.description('Watch a GitHub repo/branch and auto-rescan+resync its plugins when the branch updates (checked server-side every ~5 min, no CLI process needs to stay running)')
|
|
780
|
+
.option('--branch <name>', "Branch to watch (default: the repo's default branch)")
|
|
781
|
+
.option('--list', 'List your watched repos instead of registering a new one')
|
|
782
|
+
.action(async (url, options) => {
|
|
783
|
+
try {
|
|
784
|
+
if (options.list) {
|
|
785
|
+
await listMcpWatches();
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
url = await requireArg(url, {
|
|
789
|
+
prompt: 'GitHub repo URL to watch:',
|
|
790
|
+
usage: 'Usage: aivin mcp watch <url> [--branch <name>] | aivin mcp watch --list',
|
|
791
|
+
});
|
|
792
|
+
await registerMcpWatch(url, options);
|
|
793
|
+
} catch (error) {
|
|
794
|
+
console.error(chalk.red('❌'), error.message);
|
|
795
|
+
process.exit(1);
|
|
796
|
+
}
|
|
797
|
+
});
|
|
798
|
+
|
|
799
|
+
mcpCommand
|
|
800
|
+
.command('unwatch <url>')
|
|
801
|
+
.description('Stop auto-resyncing a previously watched repo')
|
|
802
|
+
.option('--branch <name>', 'Branch to unwatch (default: all watched branches for this repo)')
|
|
803
|
+
.action(async (url, options) => {
|
|
804
|
+
try {
|
|
805
|
+
await unwatchMcp(url, options);
|
|
806
|
+
} catch (error) {
|
|
807
|
+
console.error(chalk.red('❌'), error.message);
|
|
808
|
+
process.exit(1);
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
|
|
812
|
+
program
|
|
813
|
+
.command('login')
|
|
814
|
+
.argument('[baseUrl]', 'Server to log into (REST API base) - defaults to production (api.aivin.cloud). Pass a staging/self-hosted host to switch the machine\'s active context to it, e.g. `aivin login beta-api.aivin.vn`.')
|
|
815
|
+
.description('Log in and save an API key for plugin deployment (opens your browser by default)')
|
|
816
|
+
.option('-k, --api-key <key>', 'Set API key directly (skip login entirely)')
|
|
817
|
+
.option('--basic', 'Log in with email/password directly in the terminal instead of a browser')
|
|
818
|
+
.option('--google', 'Alias of the default browser flow - pick Google once the page opens')
|
|
819
|
+
.option('--client <client>', 'Client/org id to use with --basic (default: "aivin.cloud")')
|
|
820
|
+
.action(async (baseUrl, options) => {
|
|
821
|
+
try {
|
|
822
|
+
// Bare hostname (no scheme) is the common case for a quick `aivin login beta-api.aivin.vn` -
|
|
823
|
+
// assume https, same as every other *.aivin.* endpoint in this file.
|
|
824
|
+
const resolvedBaseUrl = baseUrl ? (/^https?:\/\//.test(baseUrl) ? baseUrl : `https://${baseUrl}`) : DEFAULT_AIVIN_BASE_URL;
|
|
825
|
+
process.env.AIVIN_BASE_URL = resolvedBaseUrl;
|
|
826
|
+
|
|
827
|
+
if (options.apiKey) {
|
|
828
|
+
console.log(chalk.blue('🔑 Setting API key...'));
|
|
829
|
+
// Best-effort - `aivin whoami` reads straight from the saved file with no server calls of
|
|
830
|
+
// its own, so whatever identity is resolvable here is all it will ever have to show.
|
|
831
|
+
const identity = await tryFetchWhoami(resolvedBaseUrl, options.apiKey);
|
|
832
|
+
const sdkEndpoint = saveGlobalApiKey(options.apiKey, resolvedBaseUrl, identity);
|
|
833
|
+
console.log(chalk.green('✅ API key set successfully!'));
|
|
834
|
+
console.log(chalk.gray(` Active context: ${resolvedBaseUrl}${sdkEndpoint ? ` (SDK_ENDPOINT: ${sdkEndpoint})` : ''}`));
|
|
835
|
+
console.log(chalk.green(`💾 Saved to ${GLOBAL_CREDENTIALS_PATH} - every project on this machine now targets this server.`));
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
// Only the browser flow needs a web app URL - fetch it from the backend itself (not needed/
|
|
840
|
+
// fetched for --basic, which never touches AIVIN_WEB_URL at all). Same override precedence
|
|
841
|
+
// as everywhere else: a caller-set AIVIN_WEB_URL (project .env/shell) always wins.
|
|
842
|
+
if (!options.basic && !process.env.AIVIN_WEB_URL) {
|
|
843
|
+
const webUrl = await fetchWebUrl(resolvedBaseUrl);
|
|
844
|
+
if (webUrl) {
|
|
845
|
+
process.env.AIVIN_WEB_URL = webUrl;
|
|
846
|
+
} else {
|
|
847
|
+
// fetchWebUrl swallows its own errors (bad host, typo'd domain, TLS/DNS failure) and
|
|
848
|
+
// returns null - warn instead of silently opening the PRODUCTION web app's login page,
|
|
849
|
+
// which would mint a key for the wrong server without any indication why.
|
|
850
|
+
console.log(chalk.yellow(`⚠️ Couldn't reach ${resolvedBaseUrl} to resolve its web app URL - check the host is correct.`));
|
|
851
|
+
console.log(chalk.yellow(` Falling back to the production web app (https://brain.aivin.cloud) - the key it mints will still be saved against ${resolvedBaseUrl}, likely NOT what you want.`));
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
const apiKey = options.basic ? await basicLogin(options) : await browserLogin();
|
|
856
|
+
|
|
857
|
+
console.log(chalk.green('✅ Login successful!'));
|
|
858
|
+
const identity = await tryFetchWhoami(resolvedBaseUrl, apiKey);
|
|
859
|
+
const sdkEndpoint = saveGlobalApiKey(apiKey, resolvedBaseUrl, identity);
|
|
860
|
+
console.log(chalk.gray(` Active context: ${resolvedBaseUrl}${sdkEndpoint ? ` (SDK_ENDPOINT: ${sdkEndpoint})` : ''}`));
|
|
861
|
+
console.log(chalk.green(`💾 Saved to ${GLOBAL_CREDENTIALS_PATH} - every project on this machine now targets this server.`));
|
|
862
|
+
} catch (error) {
|
|
863
|
+
console.log(chalk.red('❌ Login failed:'), error.message);
|
|
864
|
+
process.exit(1);
|
|
865
|
+
}
|
|
866
|
+
});
|
|
867
|
+
|
|
868
|
+
program
|
|
869
|
+
.command('logout')
|
|
870
|
+
.description('Clear the saved API key on this machine (~/.aivin/credentials) - run `aivin login` again to log back in')
|
|
871
|
+
.action(() => {
|
|
872
|
+
try {
|
|
873
|
+
// Captured BEFORE clearing so we can tell whether the currently-effective API_KEY (already
|
|
874
|
+
// loaded into process.env at startup - see the dotenv/loadActiveContext precedence block at
|
|
875
|
+
// the top of this file) came from this file or from a project's own .env, which logout never
|
|
876
|
+
// touches.
|
|
877
|
+
const savedContext = loadActiveContext();
|
|
878
|
+
const cleared = clearActiveContext();
|
|
879
|
+
if (cleared) {
|
|
880
|
+
console.log(chalk.green(`✅ Logged out - removed ${GLOBAL_CREDENTIALS_PATH}`));
|
|
881
|
+
} else {
|
|
882
|
+
console.log(chalk.gray('Already logged out - no saved credentials found.'));
|
|
883
|
+
}
|
|
884
|
+
if (process.env.API_KEY && process.env.API_KEY !== savedContext?.api_key) {
|
|
885
|
+
console.log(chalk.gray(" Note: this directory still has its own API_KEY set (from a project .env or shell env) - unset that too if you want it fully logged out here."));
|
|
886
|
+
}
|
|
887
|
+
} catch (error) {
|
|
888
|
+
console.error(chalk.red('❌'), error.message);
|
|
889
|
+
process.exit(1);
|
|
890
|
+
}
|
|
891
|
+
});
|
|
892
|
+
|
|
893
|
+
program
|
|
894
|
+
.command('whoami')
|
|
895
|
+
.description('Show which account is currently logged in on this machine (reads ~/.aivin/credentials - no server call)')
|
|
896
|
+
.action(() => {
|
|
897
|
+
try {
|
|
898
|
+
const apiKey = requireSavedApiKey();
|
|
899
|
+
const serverUrl = process.env.AIVIN_BASE_URL || DEFAULT_AIVIN_BASE_URL;
|
|
900
|
+
const localClient = parseApiKeyClient(apiKey);
|
|
901
|
+
|
|
902
|
+
// The effective API_KEY may come from a project's own .env instead of `~/.aivin/credentials`
|
|
903
|
+
// (see the dotenv precedence near the top of this file) - identity/login time only exist in
|
|
904
|
+
// the latter, so a project .env override has nothing to show beyond the key's own client id.
|
|
905
|
+
const savedContext = loadActiveContext();
|
|
906
|
+
const fromSavedContext = savedContext?.api_key === apiKey;
|
|
907
|
+
const identity = fromSavedContext ? savedContext : {};
|
|
908
|
+
|
|
909
|
+
console.log(chalk.green('✅ Logged in'));
|
|
910
|
+
console.log(chalk.gray(' Email: ') + (identity.email || chalk.gray('unknown')));
|
|
911
|
+
console.log(chalk.gray(' Name: ') + (identity.name || chalk.gray('unknown')));
|
|
912
|
+
console.log(chalk.gray(' Org: ') + (identity.org_name || identity.client || localClient || chalk.gray('unknown')));
|
|
913
|
+
if (identity.org_domain) console.log(chalk.gray(' Domain: ') + identity.org_domain);
|
|
914
|
+
console.log(chalk.gray(' Server: ') + serverUrl);
|
|
915
|
+
if (fromSavedContext && savedContext.logged_in_at) {
|
|
916
|
+
console.log(chalk.gray(' Logged in at: ') + new Date(savedContext.logged_in_at).toLocaleString());
|
|
917
|
+
} else if (!fromSavedContext) {
|
|
918
|
+
console.log(chalk.gray(" (API_KEY is from this project's .env, not `aivin login` - no recorded identity/login time)"));
|
|
919
|
+
} else if (!identity.email) {
|
|
920
|
+
console.log(chalk.gray(' (Account info wasn\'t resolvable at login time - run `aivin login` again to refresh it)'));
|
|
921
|
+
}
|
|
922
|
+
} catch (error) {
|
|
923
|
+
console.error(chalk.red('❌'), error.message);
|
|
924
|
+
process.exit(1);
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
|
|
928
|
+
const keyCommand = program.command('key').description('Manage named API keys for your account');
|
|
929
|
+
|
|
930
|
+
keyCommand
|
|
931
|
+
.command('gen [name]')
|
|
932
|
+
.description('Create (or replace) a named API key for your account - shown only once')
|
|
933
|
+
.option('--save', 'Also save this key as this machine\'s default (~/.aivin/credentials), like `aivin login -k`')
|
|
934
|
+
.action(async (name, options) => {
|
|
935
|
+
try {
|
|
936
|
+
name = await requireArg(name, { prompt: 'Name for this API key:', usage: 'Usage: aivin key gen <name>' });
|
|
937
|
+
console.log(chalk.blue(`🔑 Creating API key "${name}"...`));
|
|
938
|
+
const plainKey = await generateApiKey(name);
|
|
939
|
+
console.log(chalk.green('✅ API key created!'));
|
|
940
|
+
console.log(chalk.yellow('🔑 Key:'), chalk.cyan(plainKey));
|
|
941
|
+
console.log(chalk.gray(' This is shown only once - store it somewhere safe.'));
|
|
942
|
+
if (options.save) {
|
|
943
|
+
const serverUrl = process.env.AIVIN_BASE_URL || DEFAULT_AIVIN_BASE_URL;
|
|
944
|
+
const identity = await tryFetchWhoami(serverUrl, plainKey);
|
|
945
|
+
saveGlobalApiKey(plainKey, serverUrl, identity);
|
|
946
|
+
console.log(chalk.green(`💾 Saved to ${GLOBAL_CREDENTIALS_PATH} - every project on this machine can use it now.`));
|
|
947
|
+
}
|
|
948
|
+
} catch (error) {
|
|
949
|
+
console.error(chalk.red('❌'), error.message);
|
|
950
|
+
process.exit(1);
|
|
951
|
+
}
|
|
952
|
+
});
|
|
953
|
+
|
|
954
|
+
keyCommand
|
|
955
|
+
.command('revoke [name]')
|
|
956
|
+
.description('Revoke a named API key for your account')
|
|
957
|
+
.action(async (name) => {
|
|
958
|
+
try {
|
|
959
|
+
name = await requireArg(name, { prompt: 'Name of the API key to revoke:', usage: 'Usage: aivin key revoke <name>' });
|
|
960
|
+
console.log(chalk.blue(`🔑 Revoking API key "${name}"...`));
|
|
961
|
+
await revokeApiKeyByName(name);
|
|
962
|
+
console.log(chalk.green(`✅ API key "${name}" revoked.`));
|
|
963
|
+
} catch (error) {
|
|
964
|
+
console.error(chalk.red('❌'), error.message);
|
|
965
|
+
process.exit(1);
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
|
|
969
|
+
keyCommand
|
|
970
|
+
.command('list')
|
|
971
|
+
.description('List API keys on your account')
|
|
972
|
+
.action(async () => {
|
|
973
|
+
try {
|
|
974
|
+
const serverUrl = process.env.AIVIN_BASE_URL || 'https://api.aivin.cloud';
|
|
975
|
+
const apiKey = requireSavedApiKey();
|
|
976
|
+
await logAccountIdentity(serverUrl, apiKey);
|
|
977
|
+
const items = await listRemoteApiKeys(serverUrl, apiKey);
|
|
978
|
+
if (items.length === 0) {
|
|
979
|
+
console.log(chalk.gray('No API keys found.'));
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
items.forEach((k) => {
|
|
983
|
+
const created = k.created_at ? new Date(k.created_at).toISOString() : 'unknown';
|
|
984
|
+
console.log(` ${chalk.cyan(k.name)} ${chalk.gray(`(created ${created})`)}`);
|
|
985
|
+
});
|
|
986
|
+
} catch (error) {
|
|
987
|
+
console.error(chalk.red('❌'), error.message);
|
|
988
|
+
process.exit(1);
|
|
989
|
+
}
|
|
990
|
+
});
|
|
991
|
+
|
|
992
|
+
program
|
|
993
|
+
.command('browser [mission]')
|
|
994
|
+
.description("Run an AI Browser mission - by default opens/reuses a local browser window dedicated to AI Browser (own profile, own cookies - log in once, watch missions run live from then on); --remote uses a server-side browser instead")
|
|
995
|
+
.option('--remote', 'Use a server-side pooled browser instead of your own local one (no local browser needed, no cookies/logins carried over)')
|
|
996
|
+
.option('--debug-port <port>', 'Local mode only: port to look for/launch your browser\'s remote debugging on (default: 9222, auto-tries a few nearby ports if that one is taken by something else) - pass this to pin an exact port instead')
|
|
997
|
+
.option('--browser <edge|chrome>', "Local mode only: which browser to drive - default: auto-detects your OS's actual default browser, falling back to whichever of Edge/Chrome is installed if that can't be determined")
|
|
998
|
+
.option('--url <url>', "Local mode only: open this URL before the mission starts, instead of a blank page - skips a wasted first analysis step and avoids the AI having to search the web to find the target site itself (auto-guessed for a few well-known sites mentioned by name in the mission if omitted)")
|
|
999
|
+
.option('--workspace <id>', 'Workspace id to run in (default: your personal workspace)')
|
|
1000
|
+
.option('--project <id>', 'Project id within the workspace (--remote only)')
|
|
1001
|
+
.option('--agent <id>', "Agent id to run as (default: an auto-created/cached agent for local mode, or the workspace's default agent for --remote) - AI Browser is triggered as a tool this agent uses, real HIL suspend/resume requires an agent context")
|
|
1002
|
+
.option('--no-watch', 'Fire the mission and return immediately - skip streaming live progress and auto-opening the viewer')
|
|
1003
|
+
.option('--view', 'Just (re)open the fullscreen interactive viewer for whatever HIL session is already active - no mission is started')
|
|
1004
|
+
.action(async (mission, options) => {
|
|
1005
|
+
try {
|
|
1006
|
+
if (!options.view) {
|
|
1007
|
+
mission = await requireArg(mission, {
|
|
1008
|
+
prompt: 'What should the AI Browser do?',
|
|
1009
|
+
usage: 'Usage: aivin browser "<mission detail>" (or: aivin browser --view to just reopen the interactive viewer)',
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
await runBrowserMission(mission, options);
|
|
1013
|
+
} catch (error) {
|
|
1014
|
+
console.error(chalk.red('❌'), error.message);
|
|
1015
|
+
process.exit(1);
|
|
1016
|
+
}
|
|
1017
|
+
});
|
|
1018
|
+
|
|
1019
|
+
program
|
|
1020
|
+
.command('update')
|
|
1021
|
+
.description('Update aivin to the latest release (installs from get.aivin.vn; checks the release signature, the SHA256 and that the new build starts)')
|
|
1022
|
+
.option('--check', 'Only check whether a newer release exists')
|
|
1023
|
+
.option('--to <version>', 'Install this release instead of the latest, e.g. v1.0.9 (also allows going back)')
|
|
1024
|
+
.option('--auto <on|off>', 'Turn background updates of `aivin remote start` on or off for this computer')
|
|
1025
|
+
.option('--proxy <url>', 'HTTP proxy to download through (default: HTTPS_PROXY, else the system proxy setting; "none" = connect directly)')
|
|
1026
|
+
.action(async (options) => {
|
|
1027
|
+
try {
|
|
1028
|
+
if (options.auto !== undefined) {
|
|
1029
|
+
const value = String(options.auto).toLowerCase();
|
|
1030
|
+
if (!['on', 'off'].includes(value)) throw new Error('Dùng: aivin update --auto on|off');
|
|
1031
|
+
saveUpdateSettings({ auto: value === 'on' });
|
|
1032
|
+
console.log(chalk.green(value === 'on' ? '✅ Đã bật tự cập nhật nền.' : '✅ Đã tắt tự cập nhật nền — cập nhật bằng `aivin update` khi cần.'));
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
configureProxy({ explicit: options.proxy });
|
|
1036
|
+
if (isStandaloneBinary()) cleanupRetired();
|
|
1037
|
+
const root = downloadRoot();
|
|
1038
|
+
const res = await installUpdate({ version: options.to, root, check: !!options.check, force: !!options.to });
|
|
1039
|
+
if (res.status === UpdateStatus.UP_TO_DATE) return console.log(chalk.green(`✅ aivin ${res.current} là bản mới nhất.`));
|
|
1040
|
+
if (res.status === UpdateStatus.NOT_BINARY) {
|
|
1041
|
+
return console.log(chalk.yellow(`⬆ Có aivin ${res.latest} (máy này ${res.current}). Bản cài qua npm: npm i -g @aivin-labs/cli@latest`));
|
|
1042
|
+
}
|
|
1043
|
+
if (res.status === UpdateStatus.AVAILABLE) return console.log(chalk.yellow(`⬆ Có aivin ${res.latest} (máy này ${res.current}) — chạy \`aivin update\` để cài.`));
|
|
1044
|
+
if (res.status === UpdateStatus.SKIPPED) {
|
|
1045
|
+
return console.log(chalk.yellow(`⚠️ Máy này đã tự lùi khỏi aivin ${res.latest} (khởi động hỏng). Vẫn muốn cài: aivin update --to ${res.latest}`));
|
|
1046
|
+
}
|
|
1047
|
+
if (res.status === UpdateStatus.BUSY) return console.log(chalk.yellow('⏳ Đang có một lần cập nhật khác chạy trên máy này — thử lại sau ít phút.'));
|
|
1048
|
+
console.log(chalk.green(`✅ Đã cài aivin ${res.latest} (trước đó ${res.current}).`));
|
|
1049
|
+
console.log(chalk.gray(' `aivin remote start` chạy nền (tự khởi động cùng máy) tự chuyển sang bản mới khi máy rảnh; cửa sổ đang mở thì đóng và chạy lại.'));
|
|
1050
|
+
} catch (error) {
|
|
1051
|
+
console.error(chalk.red('❌'), error.message);
|
|
1052
|
+
process.exit(1);
|
|
1053
|
+
}
|
|
1054
|
+
});
|
|
1055
|
+
|
|
1056
|
+
const remoteCommand = program
|
|
1057
|
+
.command('remote')
|
|
1058
|
+
.description('Let your Aivin agents work on this computer (Device Agent) - pair, run the listener, manage memory and safety')
|
|
1059
|
+
// Proxy công ty cho mọi lệnh remote gọi máy chủ (ghép máy, remote do, test…) — `start` tự cấu hình kèm --proxy của nó.
|
|
1060
|
+
.hook('preAction', (_cmd, action) => { if (action.name() !== 'start') configureProxy({ explicit: action.opts().proxy }); });
|
|
1061
|
+
|
|
1062
|
+
const remoteFail = (error) => {
|
|
1063
|
+
console.error(chalk.red('❌'), error.message);
|
|
1064
|
+
process.exit(1);
|
|
1065
|
+
};
|
|
1066
|
+
|
|
1067
|
+
remoteCommand
|
|
1068
|
+
.command('start')
|
|
1069
|
+
.description('Pair this computer (first time) and listen for work from your agents in the foreground')
|
|
1070
|
+
.option('--dir <path>', 'Folder the agent may work in (default: the folder saved at pairing, else the current folder)')
|
|
1071
|
+
.option('--name <name>', 'Name shown for this computer (default: hostname)')
|
|
1072
|
+
.option('--repair', 'Pair again (new device token; the old one stops working)')
|
|
1073
|
+
.option('--full-access', 'Let the agent work anywhere on this computer (all drives; relative paths start at your home folder). Kept across restarts; --dir switches back to one folder')
|
|
1074
|
+
.option('--code <code>', 'Pair with a one-time code from Aivin (chat box → Browser ▾ → Add this computer) - no `aivin login` needed')
|
|
1075
|
+
.option('--server <url>', 'Aivin server the code belongs to (Aivin prints it in the command when needed)')
|
|
1076
|
+
.option('--no-browser', "Don't let AI Browser use a browser window on this computer (web tasks then run in Aivin's server-side browser)")
|
|
1077
|
+
.option('--no-gui', "Don't let the agent control app windows on this computer with the mouse/keyboard (Windows)")
|
|
1078
|
+
.option('--separate-browser', "Always use Aivin's own browser window, never your everyday Chrome/Edge (even if remote debugging is enabled at chrome://inspect/#remote-debugging)")
|
|
1079
|
+
.option('--quiet', 'No interactive logs')
|
|
1080
|
+
.option('--proxy <url>', 'HTTP proxy to reach Aivin through (default: HTTPS_PROXY, else the system proxy setting; "none" = connect directly)')
|
|
1081
|
+
.option('--no-keep-awake', "Don't keep this computer from sleeping while the agent is working on it")
|
|
1082
|
+
.option('--no-auto-update', "Don't download new aivin releases in the background this run (to turn it off for good: aivin update --auto off)")
|
|
1083
|
+
.option('--no-mascot', "Don't show the Aivin mascot on screen this run (to turn it off for good: aivin remote mascot off)")
|
|
1084
|
+
.option('--multi-user', "Organization cloud computer (Linux container provisioned by Aivin): token from AIVIN_DEVICE_TOKEN/AIVIN_DEVICE_ID/AIVIN_SERVER, every org member works in their own Linux account + home folder")
|
|
1085
|
+
.action(async (options) => {
|
|
1086
|
+
try {
|
|
1087
|
+
await startRemoteClient(options);
|
|
1088
|
+
} catch (error) {
|
|
1089
|
+
// Tự khởi động (--quiet) mà đã có cửa sổ khác nhận việc: không phải lỗi — thoát 0 để trình giữ chạy không chạy lại mãi.
|
|
1090
|
+
if (error?.code === DAEMON_RUNNING && options.quiet) {
|
|
1091
|
+
console.error(chalk.gray(error.message));
|
|
1092
|
+
process.exit(0);
|
|
1093
|
+
}
|
|
1094
|
+
// Vừa tự lùi bản: có trình giữ chạy → mã 75, được mở lại ngay bằng bản cũ.
|
|
1095
|
+
if (error?.code === UPDATE_ROLLED_BACK) {
|
|
1096
|
+
console.error(chalk.yellow(`↩ ${error.message}`));
|
|
1097
|
+
process.exit(error.restart ? RESTART_EXIT_CODE : 1);
|
|
1098
|
+
}
|
|
1099
|
+
remoteFail(error);
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
|
|
1103
|
+
remoteCommand
|
|
1104
|
+
.command('pair')
|
|
1105
|
+
.description('Pair (or re-pair) this computer with your account without starting the listener')
|
|
1106
|
+
.option('--dir <path>', 'Folder the agent may work in (default: current folder)')
|
|
1107
|
+
.option('--name <name>', 'Name shown for this computer (default: hostname)')
|
|
1108
|
+
.action(async (options) => {
|
|
1109
|
+
try {
|
|
1110
|
+
const roots = [path.resolve(options.dir || process.cwd())];
|
|
1111
|
+
const creds = await pairDevice({ serverUrl: missionServerUrl(), apiKey: process.env.API_KEY, roots, name: options.name, profile: buildDeviceProfile(roots) });
|
|
1112
|
+
console.log(chalk.green(`✅ Đã ghép máy "${creds.name}" (${creds.device_id})`));
|
|
1113
|
+
console.log(chalk.gray(` Thư mục được phép: ${creds.roots.join(' | ')}`));
|
|
1114
|
+
console.log(chalk.gray(' Chạy `aivin remote start` để bắt đầu nhận việc.'));
|
|
1115
|
+
} catch (error) {
|
|
1116
|
+
remoteFail(error);
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
1119
|
+
|
|
1120
|
+
remoteCommand
|
|
1121
|
+
.command('devices')
|
|
1122
|
+
.description('List computers paired with your account and whether they are online')
|
|
1123
|
+
.action(async () => {
|
|
1124
|
+
try {
|
|
1125
|
+
const devices = await listDevices({ serverUrl: missionServerUrl(), apiKey: process.env.API_KEY });
|
|
1126
|
+
const mine = loadDeviceCredentials()?.device_id;
|
|
1127
|
+
if (!devices.length) return console.log(chalk.gray('Chưa có máy nào được ghép. Chạy `aivin remote start` trên máy cần dùng.'));
|
|
1128
|
+
for (const d of devices) {
|
|
1129
|
+
const state = d.online ? chalk.green('● online') : chalk.gray('○ offline');
|
|
1130
|
+
console.log(`${state} ${chalk.bold(d.name)}${d.device_id === mine ? chalk.cyan(' (máy này)') : ''} ${chalk.gray(`${d.platform || ''} · ${d.tools_count} công cụ · ${d.device_id}`)}`);
|
|
1131
|
+
}
|
|
1132
|
+
} catch (error) {
|
|
1133
|
+
remoteFail(error);
|
|
1134
|
+
}
|
|
1135
|
+
});
|
|
1136
|
+
|
|
1137
|
+
remoteCommand
|
|
1138
|
+
.command('unpair [deviceId]')
|
|
1139
|
+
.description('Revoke a paired computer (default: this one) - its token stops working immediately')
|
|
1140
|
+
.action(async (deviceId) => {
|
|
1141
|
+
try {
|
|
1142
|
+
const target = deviceId || loadDeviceCredentials()?.device_id;
|
|
1143
|
+
if (!target) throw new Error('Máy này chưa được ghép.');
|
|
1144
|
+
await unpairDevice({ serverUrl: missionServerUrl(), apiKey: process.env.API_KEY, deviceId: target });
|
|
1145
|
+
console.log(chalk.green(`✅ Đã thu hồi máy ${target}.`));
|
|
1146
|
+
} catch (error) {
|
|
1147
|
+
remoteFail(error);
|
|
1148
|
+
}
|
|
1149
|
+
});
|
|
1150
|
+
|
|
1151
|
+
remoteCommand
|
|
1152
|
+
.command('pause')
|
|
1153
|
+
.description('Kill switch: refuse every remote call on this computer until `aivin remote resume`')
|
|
1154
|
+
.action(() => {
|
|
1155
|
+
setRemotePaused(true);
|
|
1156
|
+
console.log(chalk.yellow('⏸ Đã tạm dừng — máy này từ chối mọi việc từ xa.'));
|
|
1157
|
+
});
|
|
1158
|
+
|
|
1159
|
+
remoteCommand
|
|
1160
|
+
.command('mascot [action]')
|
|
1161
|
+
.description('The Aivin mascot floating on screen while the listener runs (Windows): on | off — no argument shows the current setting')
|
|
1162
|
+
.action((action) => {
|
|
1163
|
+
const lang = mascotLang();
|
|
1164
|
+
if (action && !['on', 'off'].includes(action)) remoteFail(new Error(mascotText(lang, MascotText.CMD_USAGE)));
|
|
1165
|
+
if (process.platform !== 'win32') console.log(chalk.gray(mascotText(lang, MascotText.CMD_UNSUPPORTED)));
|
|
1166
|
+
if (!action) return console.log(mascotText(lang, loadMascotSettings().enabled ? MascotText.CMD_STATUS_ON : MascotText.CMD_STATUS_OFF));
|
|
1167
|
+
saveMascotSettings({ enabled: action === 'on' });
|
|
1168
|
+
console.log(chalk.green(`✅ ${mascotText(lang, action === 'on' ? MascotText.CMD_ON : MascotText.CMD_OFF)}`));
|
|
1169
|
+
});
|
|
1170
|
+
|
|
1171
|
+
remoteCommand
|
|
1172
|
+
.command('policy [action] [value]')
|
|
1173
|
+
.description('Rules enforced on this computer itself (Aivin cannot change them): which steps need a click on this computer, tools turned off, extra blocked commands')
|
|
1174
|
+
.action(async (action, value) => {
|
|
1175
|
+
try {
|
|
1176
|
+
await runPolicyCommand(action, value);
|
|
1177
|
+
} catch (error) {
|
|
1178
|
+
remoteFail(error);
|
|
1179
|
+
}
|
|
1180
|
+
});
|
|
1181
|
+
|
|
1182
|
+
remoteCommand
|
|
1183
|
+
.command('resume')
|
|
1184
|
+
.description('Turn the kill switch off')
|
|
1185
|
+
.action(() => {
|
|
1186
|
+
setRemotePaused(false);
|
|
1187
|
+
console.log(chalk.green('▶ Máy này nhận việc từ xa trở lại.'));
|
|
1188
|
+
});
|
|
1189
|
+
|
|
1190
|
+
remoteCommand
|
|
1191
|
+
.command('enable')
|
|
1192
|
+
.description('Start the listener automatically when this computer starts')
|
|
1193
|
+
.option('--dir <path>', 'Folder the agent may work in (default: current folder)')
|
|
1194
|
+
.option('--proxy <url>', 'HTTP proxy the auto-started listener should use (default: detect at every start)')
|
|
1195
|
+
.action((options) => {
|
|
1196
|
+
try {
|
|
1197
|
+
const res = enableAutoStart(options);
|
|
1198
|
+
console.log(chalk.green('✅ Đã bật tự khởi động cùng máy.'));
|
|
1199
|
+
console.log(chalk.gray(` Thư mục: ${res.rootDir}`));
|
|
1200
|
+
console.log(chalk.gray(` Tệp khởi động: ${res.filePath}`));
|
|
1201
|
+
if (res.warning) console.log(chalk.yellow(` ⚠️ ${res.warning}`));
|
|
1202
|
+
} catch (error) {
|
|
1203
|
+
remoteFail(error);
|
|
1204
|
+
}
|
|
1205
|
+
});
|
|
1206
|
+
|
|
1207
|
+
remoteCommand
|
|
1208
|
+
.command('disable')
|
|
1209
|
+
.description('Stop starting the listener with this computer')
|
|
1210
|
+
.action(() => {
|
|
1211
|
+
try {
|
|
1212
|
+
disableAutoStart();
|
|
1213
|
+
console.log(chalk.green('✅ Đã tắt tự khởi động cùng máy.'));
|
|
1214
|
+
} catch (error) {
|
|
1215
|
+
remoteFail(error);
|
|
1216
|
+
}
|
|
1217
|
+
});
|
|
1218
|
+
|
|
1219
|
+
remoteCommand
|
|
1220
|
+
.command('status')
|
|
1221
|
+
.description('Show pairing, allowed folders, kill switch, auto-start, tools and memory of this computer')
|
|
1222
|
+
.action(() => {
|
|
1223
|
+
try {
|
|
1224
|
+
const creds = loadDeviceCredentials();
|
|
1225
|
+
const roots = creds?.roots?.length ? creds.roots : [process.cwd()];
|
|
1226
|
+
const profile = buildDeviceProfile(roots);
|
|
1227
|
+
const { catalog, hash } = buildCatalog(buildTools({ roots, binaries: profile.binaries, projects: profile.projects }));
|
|
1228
|
+
const stats = memoryStats();
|
|
1229
|
+
console.log(chalk.blue('💻 Máy này:'));
|
|
1230
|
+
console.log(chalk.gray(` Mã máy: ${getOrCreateDeviceId()}`));
|
|
1231
|
+
console.log(chalk.gray(` Đã ghép: ${creds ? chalk.green(`có — ${creds.name} @ ${creds.server_url}`) : chalk.yellow('chưa')}`));
|
|
1232
|
+
console.log(chalk.gray(` Thư mục: ${roots.join(' | ')}`));
|
|
1233
|
+
console.log(chalk.gray(` Công tắc ngắt: ${isRemotePaused() ? chalk.yellow('ĐANG TẠM DỪNG') : 'tắt'}`));
|
|
1234
|
+
console.log(chalk.gray(` Tự khởi động: ${getAutoStartStatus().enabled ? 'bật' : 'tắt'}`));
|
|
1235
|
+
console.log(chalk.gray(` Chương trình: ${profile.binaries.join(', ') || '-'}`));
|
|
1236
|
+
console.log(chalk.gray(` Dự án: ${profile.projects.map((p) => `${p.name} (${p.kind})`).join(', ') || '-'}`));
|
|
1237
|
+
console.log(chalk.gray(` Ghi nhớ: ${stats.total} mục (${stats.with_vector} có vector) — ${stats.dir}`));
|
|
1238
|
+
console.log(chalk.blue(`\n🛠️ ${catalog.length} công cụ (dấu vân tay ${hash.slice(0, 12)}):`));
|
|
1239
|
+
for (const t of catalog) console.log(` - ${chalk.cyan(t.name)}${t.read_only ? chalk.gray(' [chỉ đọc]') : t.destructive ? chalk.red(' [không hoàn tác]') : chalk.yellow(' [ghi]')}`);
|
|
1240
|
+
} catch (error) {
|
|
1241
|
+
remoteFail(error);
|
|
1242
|
+
}
|
|
1243
|
+
});
|
|
1244
|
+
|
|
1245
|
+
remoteCommand
|
|
1246
|
+
.command('test')
|
|
1247
|
+
.description('Check the server connection and whether the server sees this computer online')
|
|
1248
|
+
.action(async () => {
|
|
1249
|
+
try {
|
|
1250
|
+
const r = await testRemoteConnection();
|
|
1251
|
+
console.log(chalk.gray(` Máy chủ: ${r.serverUrl} — ${r.httpOk ? chalk.green(`thông (${r.latencyMs} ms)`) : chalk.red('không kết nối được')}`));
|
|
1252
|
+
console.log(chalk.gray(` Đã ghép: ${r.paired ? `có (${r.deviceId})` : chalk.yellow('chưa — chạy aivin remote start')}`));
|
|
1253
|
+
if (r.online !== null) console.log(chalk.gray(` Online: ${r.online ? chalk.green('có') : chalk.yellow(r.registered === false ? 'máy chủ không có máy này (đã thu hồi?)' : 'không — chạy aivin remote start')}`));
|
|
1254
|
+
if (r.error) console.log(chalk.yellow(` ⚠️ ${r.error}`));
|
|
1255
|
+
} catch (error) {
|
|
1256
|
+
remoteFail(error);
|
|
1257
|
+
}
|
|
1258
|
+
});
|
|
1259
|
+
|
|
1260
|
+
remoteCommand
|
|
1261
|
+
.command('logs')
|
|
1262
|
+
.description('Recent remote activity on this computer')
|
|
1263
|
+
.option('--limit <n>', 'Entries to show (default 30)', '30')
|
|
1264
|
+
.option('--clear', 'Clear the activity log')
|
|
1265
|
+
.action((options) => {
|
|
1266
|
+
if (options.clear) {
|
|
1267
|
+
clearLogs();
|
|
1268
|
+
return console.log(chalk.green('✅ Đã xoá nhật ký.'));
|
|
1269
|
+
}
|
|
1270
|
+
const logs = getRecentLogs(options.limit);
|
|
1271
|
+
if (!logs.length) return console.log(chalk.gray('Chưa có hoạt động nào.'));
|
|
1272
|
+
for (const log of logs) {
|
|
1273
|
+
const time = log.timestamp ? new Date(log.timestamp).toLocaleTimeString() : '';
|
|
1274
|
+
if (log.type === 'tool_call') console.log(` [${time}] ${log.success ? chalk.green('✓') : chalk.red('✗')} ${chalk.cyan(log.tool)}${log.ms !== undefined ? chalk.gray(` ${log.ms} ms`) : ''} ${log.error ? chalk.red(log.error) : ''}`);
|
|
1275
|
+
else console.log(` [${time}] ${chalk.gray(log.type)} ${chalk.gray(log.reason || log.serverUrl || '')}`);
|
|
1276
|
+
}
|
|
1277
|
+
});
|
|
1278
|
+
|
|
1279
|
+
remoteCommand
|
|
1280
|
+
.command('memory [action] [value...]')
|
|
1281
|
+
.description('On-device memory (~/.aivin/memory/*.yaml): list [kind] | search <words> | add <text> | forget <id> | clear [kind]')
|
|
1282
|
+
.option('--kind <kind>', `Kind: ${Object.values(MemoryKind).join(', ')}`)
|
|
1283
|
+
.option('--key <key>', 'Stable key for add (default: derived from the text)')
|
|
1284
|
+
.action((action = 'list', valueParts = [], options) => {
|
|
1285
|
+
try {
|
|
1286
|
+
const value = valueParts.join(' ').trim();
|
|
1287
|
+
if (action === 'search') {
|
|
1288
|
+
if (!value) throw new Error('Dùng: aivin remote memory search <từ khoá>');
|
|
1289
|
+
const hits = searchMemory({ query: value, kinds: options.kind ? [options.kind] : undefined, limit: 20 });
|
|
1290
|
+
if (!hits.length) return console.log(chalk.gray('Không có mục nào khớp.'));
|
|
1291
|
+
hits.forEach((h) => console.log(` ${chalk.gray(h.id)} [${h.kind}] ${chalk.bold(h.key)}: ${h.text}`));
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1294
|
+
if (action === 'add') {
|
|
1295
|
+
if (!value) throw new Error('Dùng: aivin remote memory add "<nội dung>" --kind fact --key <khoá>');
|
|
1296
|
+
const kind = options.kind || MemoryKind.FACT;
|
|
1297
|
+
const key = options.key || value.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, '-').slice(0, 60);
|
|
1298
|
+
putMemoryItems([{ kind, key, text: value }]);
|
|
1299
|
+
return console.log(chalk.green(`✅ Đã nhớ [${kind}] ${key}`));
|
|
1300
|
+
}
|
|
1301
|
+
if (action === 'forget') {
|
|
1302
|
+
if (!value) throw new Error('Dùng: aivin remote memory forget <id> (xem id bằng memory list / search)');
|
|
1303
|
+
const res = deleteMemoryItems({ ids: value.split(/[\s,]+/) });
|
|
1304
|
+
return console.log(chalk.green(`✅ Đã quên ${res.deleted} mục.`));
|
|
1305
|
+
}
|
|
1306
|
+
if (action === 'clear') {
|
|
1307
|
+
clearDeviceMemory(value || options.kind || undefined);
|
|
1308
|
+
return console.log(chalk.green('✅ Đã xoá bộ nhớ.'));
|
|
1309
|
+
}
|
|
1310
|
+
const page = listMemoryItems({ kind: value || options.kind, limit: 100 });
|
|
1311
|
+
const stats = memoryStats();
|
|
1312
|
+
console.log(chalk.blue(`🧠 Bộ nhớ trên máy: ${stats.total} mục — ${stats.dir} (sửa tay các tệp .yaml được)`));
|
|
1313
|
+
page.items.forEach((i) => console.log(` ${chalk.gray(i.id)} [${i.kind}] ${chalk.bold(i.key)}: ${String(i.text).slice(0, 160)}`));
|
|
1314
|
+
if (page.next_cursor !== null) console.log(chalk.gray(` … còn ${page.total - page.items.length} mục`));
|
|
1315
|
+
} catch (error) {
|
|
1316
|
+
remoteFail(error);
|
|
1317
|
+
}
|
|
1318
|
+
});
|
|
1319
|
+
|
|
1320
|
+
remoteCommand
|
|
1321
|
+
.command('reindex')
|
|
1322
|
+
.description('Rebuild the file index of the allowed folders now')
|
|
1323
|
+
.action(async () => {
|
|
1324
|
+
try {
|
|
1325
|
+
const creds = loadDeviceCredentials();
|
|
1326
|
+
const index = createFileIndex(indexRootsFor(creds?.roots || [process.cwd()], creds?.access === DeviceAccess.FULL));
|
|
1327
|
+
const stats = await index.build();
|
|
1328
|
+
index.close();
|
|
1329
|
+
console.log(chalk.green(`✅ Chỉ mục: ${stats.files} tệp (${stats.updated} cập nhật, ${stats.removed} bỏ) trong ${stats.ms} ms`));
|
|
1330
|
+
} catch (error) {
|
|
1331
|
+
remoteFail(error);
|
|
1332
|
+
}
|
|
1333
|
+
});
|
|
1334
|
+
|
|
1335
|
+
remoteCommand
|
|
1336
|
+
.command('reset-id')
|
|
1337
|
+
.description('Give this computer a new device id (cloned machines) - you must pair again')
|
|
1338
|
+
.action(() => {
|
|
1339
|
+
const id = resetDeviceId();
|
|
1340
|
+
console.log(chalk.green(`✅ Mã máy mới: ${id} — chạy \`aivin remote start\` để ghép lại.`));
|
|
1341
|
+
});
|
|
1342
|
+
|
|
1343
|
+
remoteCommand
|
|
1344
|
+
.command('do [objective]')
|
|
1345
|
+
.description('Give a job to the Device Agent on your computer (the listener must be running there)')
|
|
1346
|
+
.option('--device <name>', 'Which paired computer (default: your online one)')
|
|
1347
|
+
.option('--cwd <path>', 'Folder the job is about')
|
|
1348
|
+
.option('--file <id...>', 'Aivin workspace file id(s) the job may save onto the computer')
|
|
1349
|
+
.option('--workspace <id>', 'Workspace id (default: your personal workspace)')
|
|
1350
|
+
.option('--agent <id>', 'Agent to act as (default: the workspace default agent)')
|
|
1351
|
+
.option('--no-watch', 'Do not stream progress')
|
|
1352
|
+
.action(async (objective, options) => {
|
|
1353
|
+
try {
|
|
1354
|
+
objective = await requireArg(objective, { prompt: 'What should the agent do on your computer?', usage: 'Usage: aivin remote do "<job>"' });
|
|
1355
|
+
await runRemoteMission(objective, options);
|
|
1356
|
+
} catch (error) {
|
|
1357
|
+
remoteFail(error);
|
|
1358
|
+
}
|
|
1359
|
+
});
|
|
1360
|
+
|
|
1361
|
+
const doCommand = program
|
|
1362
|
+
.command('do [agentNickname] [mission]')
|
|
1363
|
+
.description("Have <agentNickname> work toward a goal in the background - not a specific deployed plugin")
|
|
1364
|
+
.option('--workspace <id>', 'Workspace id to run in (default: your personal workspace)')
|
|
1365
|
+
.option('--project <id>', 'Project id within the workspace')
|
|
1366
|
+
.option('--no-watch', 'Fire the mission and return immediately - skip streaming live progress')
|
|
1367
|
+
.action(async (agentNickname, mission, options) => {
|
|
1368
|
+
try {
|
|
1369
|
+
mission = await requireArg(mission, {
|
|
1370
|
+
prompt: 'What should the agent do?',
|
|
1371
|
+
usage: 'Usage: aivin do <agent_nickname> "<mission detail>" (or: aivin do job "<automation job description>")',
|
|
1372
|
+
});
|
|
1373
|
+
await runMission(agentNickname, mission, options);
|
|
1374
|
+
} catch (error) {
|
|
1375
|
+
console.error(chalk.red('❌'), error.message);
|
|
1376
|
+
process.exit(1);
|
|
1377
|
+
}
|
|
1378
|
+
});
|
|
1379
|
+
|
|
1380
|
+
doCommand
|
|
1381
|
+
.command('job [description]')
|
|
1382
|
+
.description('Create a new automation job from a plain-language description')
|
|
1383
|
+
.option('--workspace <id>', 'Workspace id to create the job in (default: your personal workspace)')
|
|
1384
|
+
.option('--project <id>', 'Project id within the workspace')
|
|
1385
|
+
.option('--agent <id>', "Agent id the job runs as (default: the workspace's default agent)")
|
|
1386
|
+
.option('--schedule <condition>', 'Natural-language schedule, e.g. "every Monday at 9am" (default: let the platform infer one)')
|
|
1387
|
+
.action(async (description, options) => {
|
|
1388
|
+
try {
|
|
1389
|
+
description = await requireArg(description, { prompt: 'What should this automation job do?', usage: 'Usage: aivin do job "<automation job description>"' });
|
|
1390
|
+
await createAutomationJob(description, options);
|
|
1391
|
+
} catch (error) {
|
|
1392
|
+
console.error(chalk.red('❌'), error.message);
|
|
1393
|
+
process.exit(1);
|
|
1394
|
+
}
|
|
1395
|
+
});
|
|
1396
|
+
|
|
1397
|
+
const taskCommand = program
|
|
1398
|
+
.command('task [description]')
|
|
1399
|
+
.description('Create a new task from a plain-language description')
|
|
1400
|
+
.option('--workspace <id>', 'Workspace id to create the task in (default: your personal workspace)')
|
|
1401
|
+
.option('--project <id>', 'Project id within the workspace')
|
|
1402
|
+
.option('--assignee <userId>', 'User id to assign the task to (default: unassigned)')
|
|
1403
|
+
.action(async (description, options) => {
|
|
1404
|
+
try {
|
|
1405
|
+
description = await requireArg(description, {
|
|
1406
|
+
prompt: 'What is this task?',
|
|
1407
|
+
usage: 'Usage: aivin task "<description>" (or: aivin task list/mine/get/update/delete)',
|
|
1408
|
+
});
|
|
1409
|
+
await createTask(description, options);
|
|
1410
|
+
} catch (error) {
|
|
1411
|
+
console.error(chalk.red('❌'), error.message);
|
|
1412
|
+
process.exit(1);
|
|
1413
|
+
}
|
|
1414
|
+
});
|
|
1415
|
+
|
|
1416
|
+
taskCommand
|
|
1417
|
+
.command('list')
|
|
1418
|
+
.description('List tasks in a project')
|
|
1419
|
+
.option('--workspace <id>', 'Workspace id (default: your personal workspace)')
|
|
1420
|
+
.option('--project <id>', "Project id (default: the workspace's first project)")
|
|
1421
|
+
.option('--status <status>', 'Filter by status (todo/doing/done/backlog/cancel)')
|
|
1422
|
+
.option('--assignee <userId>', 'Filter by assignee user id')
|
|
1423
|
+
.option('--search <text>', 'Filter by search text')
|
|
1424
|
+
.action(async (options) => {
|
|
1425
|
+
try {
|
|
1426
|
+
await listTasks(options);
|
|
1427
|
+
} catch (error) {
|
|
1428
|
+
console.error(chalk.red('❌'), error.message);
|
|
1429
|
+
process.exit(1);
|
|
1430
|
+
}
|
|
1431
|
+
});
|
|
1432
|
+
|
|
1433
|
+
taskCommand
|
|
1434
|
+
.command('mine')
|
|
1435
|
+
.description('List tasks assigned to you in a project')
|
|
1436
|
+
.option('--workspace <id>', 'Workspace id (default: your personal workspace)')
|
|
1437
|
+
.option('--project <id>', "Project id (default: the workspace's first project)")
|
|
1438
|
+
.action(async (options) => {
|
|
1439
|
+
try {
|
|
1440
|
+
await listMyTasks(options);
|
|
1441
|
+
} catch (error) {
|
|
1442
|
+
console.error(chalk.red('❌'), error.message);
|
|
1443
|
+
process.exit(1);
|
|
1444
|
+
}
|
|
1445
|
+
});
|
|
1446
|
+
|
|
1447
|
+
taskCommand
|
|
1448
|
+
.command('get [id]')
|
|
1449
|
+
.description('Get a task by id')
|
|
1450
|
+
.action(async (id) => {
|
|
1451
|
+
try {
|
|
1452
|
+
id = await requireArg(id, { prompt: 'Task id:', usage: 'Usage: aivin task get <id>' });
|
|
1453
|
+
await getTaskById(id);
|
|
1454
|
+
} catch (error) {
|
|
1455
|
+
console.error(chalk.red('❌'), error.message);
|
|
1456
|
+
process.exit(1);
|
|
1457
|
+
}
|
|
1458
|
+
});
|
|
1459
|
+
|
|
1460
|
+
taskCommand
|
|
1461
|
+
.command('update [id]')
|
|
1462
|
+
.description('Update a task')
|
|
1463
|
+
.option('--status <status>', 'todo|doing|done|backlog|cancel')
|
|
1464
|
+
.option('--title <title>', 'New title')
|
|
1465
|
+
.option('--description <text>', 'New content/description')
|
|
1466
|
+
.option('--assignee <userId>', 'Reassign to this user id')
|
|
1467
|
+
.option('--priority <priority>', 'low|medium|high|urgent')
|
|
1468
|
+
.action(async (id, options) => {
|
|
1469
|
+
try {
|
|
1470
|
+
id = await requireArg(id, { prompt: 'Task id:', usage: 'Usage: aivin task update <id>' });
|
|
1471
|
+
await updateTaskById(id, options);
|
|
1472
|
+
} catch (error) {
|
|
1473
|
+
console.error(chalk.red('❌'), error.message);
|
|
1474
|
+
process.exit(1);
|
|
1475
|
+
}
|
|
1476
|
+
});
|
|
1477
|
+
|
|
1478
|
+
taskCommand
|
|
1479
|
+
.command('delete [id]')
|
|
1480
|
+
.description('Delete a task')
|
|
1481
|
+
.option('-y, --yes', 'Skip the confirmation prompt (for scripts/CI)')
|
|
1482
|
+
.action(async (id, options) => {
|
|
1483
|
+
try {
|
|
1484
|
+
id = await requireArg(id, { prompt: 'Task id to delete:', usage: 'Usage: aivin task delete <id>' });
|
|
1485
|
+
await deleteTaskById(id, options);
|
|
1486
|
+
} catch (error) {
|
|
1487
|
+
console.error(chalk.red('❌'), error.message);
|
|
1488
|
+
process.exit(1);
|
|
1489
|
+
}
|
|
1490
|
+
});
|
|
1491
|
+
|
|
1492
|
+
program
|
|
1493
|
+
.command('workspace')
|
|
1494
|
+
.description('Browse your workspaces and projects, and pick one to use with --workspace/--project')
|
|
1495
|
+
.option('--plain', 'Print a flat list instead of the interactive picker (for scripts/CI)')
|
|
1496
|
+
.action(async (options) => {
|
|
1497
|
+
try {
|
|
1498
|
+
await pickWorkspaceAndProject(options);
|
|
1499
|
+
} catch (error) {
|
|
1500
|
+
console.error(chalk.red('❌'), error.message);
|
|
1501
|
+
process.exit(1);
|
|
1502
|
+
}
|
|
1503
|
+
});
|
|
1504
|
+
|
|
1505
|
+
const agentCommand = program.command('agent').description('List, search, install, create, and publish AI Staff agents');
|
|
1506
|
+
|
|
1507
|
+
agentCommand
|
|
1508
|
+
.command('list')
|
|
1509
|
+
.description('Browse agents already installed in a workspace (↑/↓ to move, space/enter for details, q to quit)')
|
|
1510
|
+
.option('--workspace <id>', 'Workspace id (default: your personal workspace)')
|
|
1511
|
+
.option('--plain', 'Print a flat list instead of the interactive browser (for scripts/CI)')
|
|
1512
|
+
.action(async (options) => {
|
|
1513
|
+
try {
|
|
1514
|
+
await listAgentsCmd(options);
|
|
1515
|
+
} catch (error) {
|
|
1516
|
+
console.error(chalk.red('❌'), error.message);
|
|
1517
|
+
process.exit(1);
|
|
1518
|
+
}
|
|
1519
|
+
});
|
|
1520
|
+
|
|
1521
|
+
agentCommand
|
|
1522
|
+
.command('search [query]')
|
|
1523
|
+
.description('Search the AI Staff marketplace for an agent')
|
|
1524
|
+
.option('--workspace <id>', 'Workspace id for context (default: your personal workspace)')
|
|
1525
|
+
.option('--limit <n>', 'Max results to show')
|
|
1526
|
+
.action(async (query, options) => {
|
|
1527
|
+
try {
|
|
1528
|
+
query = await requireArg(query, { prompt: 'What are you looking for?', usage: 'Usage: aivin agent search "<query>"' });
|
|
1529
|
+
const serverUrl = missionServerUrl();
|
|
1530
|
+
const authHeaders = missionAuthHeaders();
|
|
1531
|
+
const workspace = await resolveWorkspace(serverUrl, authHeaders, options.workspace);
|
|
1532
|
+
const results = await searchAgents(serverUrl, authHeaders, {
|
|
1533
|
+
query,
|
|
1534
|
+
workspaceId: workspace.id || workspace._id,
|
|
1535
|
+
limit: options.limit,
|
|
1536
|
+
});
|
|
1537
|
+
if (results.length === 0) {
|
|
1538
|
+
console.log(chalk.yellow(`No agents found matching "${query}".`));
|
|
1539
|
+
return;
|
|
1540
|
+
}
|
|
1541
|
+
console.log(chalk.blue(`Found ${results.length} agent(s) matching "${query}":\n`));
|
|
1542
|
+
results.forEach((a) => {
|
|
1543
|
+
console.log(chalk.bold(a.nickname || a.name) + chalk.gray(` (${a.id})`));
|
|
1544
|
+
if (a.bio) console.log(` ${a.bio}`);
|
|
1545
|
+
console.log();
|
|
1546
|
+
});
|
|
1547
|
+
} catch (error) {
|
|
1548
|
+
console.error(chalk.red('❌'), error.message);
|
|
1549
|
+
process.exit(1);
|
|
1550
|
+
}
|
|
1551
|
+
});
|
|
1552
|
+
|
|
1553
|
+
agentCommand
|
|
1554
|
+
.command('install [query]')
|
|
1555
|
+
.description('Search the marketplace and install an agent into a workspace')
|
|
1556
|
+
.option('--workspace <id>', 'Workspace id to install into (default: your personal workspace)')
|
|
1557
|
+
.action(async (query, options) => {
|
|
1558
|
+
try {
|
|
1559
|
+
const serverUrl = missionServerUrl();
|
|
1560
|
+
const authHeaders = missionAuthHeaders();
|
|
1561
|
+
const workspace = await resolveWorkspace(serverUrl, authHeaders, options.workspace);
|
|
1562
|
+
const workspaceId = workspace.id || workspace._id;
|
|
1563
|
+
|
|
1564
|
+
let picked;
|
|
1565
|
+
if (query) {
|
|
1566
|
+
const results = await searchAgents(serverUrl, authHeaders, { query, workspaceId, limit: 10 });
|
|
1567
|
+
if (results.length === 0) throw new Error(`No marketplace agents found matching "${query}".`);
|
|
1568
|
+
if (!process.stdout.isTTY || !process.stdin.isTTY) {
|
|
1569
|
+
picked = results[0];
|
|
1570
|
+
} else {
|
|
1571
|
+
const { pickedAgent } = await inquirer.prompt([
|
|
1572
|
+
{
|
|
1573
|
+
type: 'select',
|
|
1574
|
+
name: 'pickedAgent',
|
|
1575
|
+
message: 'Install which agent?',
|
|
1576
|
+
choices: results.map((a) => ({ name: `${a.nickname || a.name}${a.bio ? chalk.gray(` - ${a.bio}`) : ''}`, value: a })),
|
|
1577
|
+
},
|
|
1578
|
+
]);
|
|
1579
|
+
picked = pickedAgent;
|
|
1580
|
+
}
|
|
1581
|
+
} else {
|
|
1582
|
+
picked = await installAgentInteractive(serverUrl, authHeaders, workspaceId);
|
|
1583
|
+
console.log(chalk.gray(`Installed into ${workspace.name || workspaceId}.`));
|
|
1584
|
+
return;
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
await pullAgentIntoWorkspace(serverUrl, authHeaders, { agentId: picked.id, workspaceId });
|
|
1588
|
+
console.log(chalk.green(`✅ Installed "${picked.nickname || picked.name}" into ${workspace.name || workspaceId}.`));
|
|
1589
|
+
} catch (error) {
|
|
1590
|
+
console.error(chalk.red('❌'), error.message);
|
|
1591
|
+
process.exit(1);
|
|
1592
|
+
}
|
|
1593
|
+
});
|
|
1594
|
+
|
|
1595
|
+
agentCommand
|
|
1596
|
+
.command('make')
|
|
1597
|
+
.description('Create a brand new AI Staff agent')
|
|
1598
|
+
.option('--name <name>', 'Agent name')
|
|
1599
|
+
.option('--nickname <nickname>', 'Agent nickname (used to @-mention/target it)')
|
|
1600
|
+
.option('--email <email>', 'Agent email')
|
|
1601
|
+
.option('--bio <bio>', 'Short bio')
|
|
1602
|
+
.option('--workspace <id>', 'Workspace to install the new agent into (default: your personal workspace)')
|
|
1603
|
+
.action(async (options) => {
|
|
1604
|
+
try {
|
|
1605
|
+
const serverUrl = missionServerUrl();
|
|
1606
|
+
const authHeaders = missionAuthHeaders();
|
|
1607
|
+
const workspace = await resolveWorkspace(serverUrl, authHeaders, options.workspace);
|
|
1608
|
+
|
|
1609
|
+
const canPrompt = process.stdout.isTTY && process.stdin.isTTY;
|
|
1610
|
+
const answers = { name: options.name, nickname: options.nickname, email: options.email, bio: options.bio };
|
|
1611
|
+
if ((!answers.name || !answers.nickname || !answers.email) && canPrompt) {
|
|
1612
|
+
const prompted = await inquirer.prompt(
|
|
1613
|
+
[
|
|
1614
|
+
!answers.name && { type: 'input', name: 'name', message: 'Agent name:', validate: (v) => v.trim().length > 0 || 'Required' },
|
|
1615
|
+
!answers.nickname && {
|
|
1616
|
+
type: 'input',
|
|
1617
|
+
name: 'nickname',
|
|
1618
|
+
message: 'Agent nickname (used to @-mention/target it):',
|
|
1619
|
+
validate: (v) => v.trim().length > 0 || 'Required',
|
|
1620
|
+
},
|
|
1621
|
+
!answers.email && { type: 'input', name: 'email', message: 'Agent email:', validate: (v) => v.trim().length > 0 || 'Required' },
|
|
1622
|
+
!answers.bio && { type: 'input', name: 'bio', message: 'Short bio (optional):' },
|
|
1623
|
+
].filter(Boolean),
|
|
1624
|
+
);
|
|
1625
|
+
Object.assign(answers, prompted);
|
|
1626
|
+
}
|
|
1627
|
+
if (!answers.name || !answers.nickname || !answers.email) {
|
|
1628
|
+
throw new Error('Usage: aivin agent make --name <name> --nickname <nickname> --email <email> [--bio <bio>]');
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
const agent = await createAgent(serverUrl, authHeaders, { ...answers, workspaceId: workspace.id || workspace._id });
|
|
1632
|
+
console.log(chalk.green(`✅ Created agent "${agent.nickname || agent.name}"!`));
|
|
1633
|
+
if (agent.id) console.log(chalk.gray(` ID: ${agent.id}`));
|
|
1634
|
+
} catch (error) {
|
|
1635
|
+
console.error(chalk.red('❌'), error.message);
|
|
1636
|
+
process.exit(1);
|
|
1637
|
+
}
|
|
1638
|
+
});
|
|
1639
|
+
|
|
1640
|
+
agentCommand
|
|
1641
|
+
.command('publish [agentId]')
|
|
1642
|
+
.description('Publish an agent you own to the marketplace')
|
|
1643
|
+
.option('--workspace <id>', 'Workspace the agent lives in (default: your personal workspace)')
|
|
1644
|
+
.action(async (agentId, options) => {
|
|
1645
|
+
try {
|
|
1646
|
+
const serverUrl = missionServerUrl();
|
|
1647
|
+
const authHeaders = missionAuthHeaders();
|
|
1648
|
+
const workspace = await resolveWorkspace(serverUrl, authHeaders, options.workspace);
|
|
1649
|
+
|
|
1650
|
+
if (!agentId) {
|
|
1651
|
+
const agents = workspace.agents || [];
|
|
1652
|
+
if (agents.length === 0) throw new Error(`Workspace "${workspace.name}" has no agents to publish.`);
|
|
1653
|
+
if (!process.stdout.isTTY || !process.stdin.isTTY) {
|
|
1654
|
+
throw new Error('Usage: aivin agent publish <agentId>');
|
|
1655
|
+
}
|
|
1656
|
+
const { pickedAgentId } = await inquirer.prompt([
|
|
1657
|
+
{
|
|
1658
|
+
type: 'select',
|
|
1659
|
+
name: 'pickedAgentId',
|
|
1660
|
+
message: 'Publish which agent?',
|
|
1661
|
+
choices: agents.map((a) => ({ name: a.nickname || a.name || a.id, value: a.id || a.agent_id })),
|
|
1662
|
+
},
|
|
1663
|
+
]);
|
|
1664
|
+
agentId = pickedAgentId;
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
await publishAgent(serverUrl, authHeaders, { agentId, workspaceId: workspace.id || workspace._id });
|
|
1668
|
+
console.log(chalk.green(`✅ Published agent ${agentId} to the marketplace.`));
|
|
1669
|
+
} catch (error) {
|
|
1670
|
+
console.error(chalk.red('❌'), error.message);
|
|
1671
|
+
process.exit(1);
|
|
1672
|
+
}
|
|
1673
|
+
});
|
|
1674
|
+
|
|
1675
|
+
const projectCommand = program.command('project').description('List, create, update, and delete projects within a workspace');
|
|
1676
|
+
|
|
1677
|
+
projectCommand
|
|
1678
|
+
.command('list')
|
|
1679
|
+
.description('List projects in a workspace')
|
|
1680
|
+
.option('--workspace <id>', 'Workspace id (default: your personal workspace)')
|
|
1681
|
+
.action(async (options) => {
|
|
1682
|
+
try {
|
|
1683
|
+
await listProjectsCmd(options);
|
|
1684
|
+
} catch (error) {
|
|
1685
|
+
console.error(chalk.red('❌'), error.message);
|
|
1686
|
+
process.exit(1);
|
|
1687
|
+
}
|
|
1688
|
+
});
|
|
1689
|
+
|
|
1690
|
+
projectCommand
|
|
1691
|
+
.command('create [name]')
|
|
1692
|
+
.description('Create a new project in a workspace')
|
|
1693
|
+
.option('--workspace <id>', 'Workspace id (default: your personal workspace)')
|
|
1694
|
+
.action(async (name, options) => {
|
|
1695
|
+
try {
|
|
1696
|
+
name = await requireArg(name, { prompt: 'Project name:', usage: 'Usage: aivin project create <name>' });
|
|
1697
|
+
await createProjectCmd(name, options);
|
|
1698
|
+
} catch (error) {
|
|
1699
|
+
console.error(chalk.red('❌'), error.message);
|
|
1700
|
+
process.exit(1);
|
|
1701
|
+
}
|
|
1702
|
+
});
|
|
1703
|
+
|
|
1704
|
+
projectCommand
|
|
1705
|
+
.command('update [id]')
|
|
1706
|
+
.description('Update a project (currently: rename)')
|
|
1707
|
+
.option('--workspace <id>', 'Workspace id (default: your personal workspace)')
|
|
1708
|
+
.option('--name <name>', 'New name')
|
|
1709
|
+
.action(async (id, options) => {
|
|
1710
|
+
try {
|
|
1711
|
+
id = await requireArg(id, { prompt: 'Project id:', usage: 'Usage: aivin project update <id> --name <new name>' });
|
|
1712
|
+
await updateProjectCmd(id, options);
|
|
1713
|
+
} catch (error) {
|
|
1714
|
+
console.error(chalk.red('❌'), error.message);
|
|
1715
|
+
process.exit(1);
|
|
1716
|
+
}
|
|
1717
|
+
});
|
|
1718
|
+
|
|
1719
|
+
projectCommand
|
|
1720
|
+
.command('delete [id]')
|
|
1721
|
+
.description('Delete a project')
|
|
1722
|
+
.option('--workspace <id>', 'Workspace id (default: your personal workspace)')
|
|
1723
|
+
.option('-y, --yes', 'Skip the confirmation prompt (for scripts/CI)')
|
|
1724
|
+
.action(async (id, options) => {
|
|
1725
|
+
try {
|
|
1726
|
+
id = await requireArg(id, { prompt: 'Project id to delete:', usage: 'Usage: aivin project delete <id>' });
|
|
1727
|
+
await deleteProjectCmd(id, options);
|
|
1728
|
+
} catch (error) {
|
|
1729
|
+
console.error(chalk.red('❌'), error.message);
|
|
1730
|
+
process.exit(1);
|
|
1731
|
+
}
|
|
1732
|
+
});
|
|
1733
|
+
|
|
1734
|
+
export {
|
|
1735
|
+
validatePluginConfig,
|
|
1736
|
+
incrementVersion,
|
|
1737
|
+
validateMcpProxyConfig,
|
|
1738
|
+
buildDeploymentPayload,
|
|
1739
|
+
buildMcpManifest,
|
|
1740
|
+
parseMcpArgs,
|
|
1741
|
+
guessConnectorQueryFromEnvVarName,
|
|
1742
|
+
setFieldConnector,
|
|
1743
|
+
buildRegisterConnectorDto,
|
|
1744
|
+
buildCreateTaskPayload,
|
|
1745
|
+
buildDeviceProfile,
|
|
1746
|
+
buildTools,
|
|
1747
|
+
buildCatalog,
|
|
1748
|
+
enableAutoStart,
|
|
1749
|
+
disableAutoStart,
|
|
1750
|
+
getAutoStartStatus,
|
|
1751
|
+
resetDeviceId,
|
|
1752
|
+
getRecentLogs,
|
|
1753
|
+
clearLogs,
|
|
1754
|
+
testRemoteConnection,
|
|
1755
|
+
runRemoteMission,
|
|
1756
|
+
};
|
|
1757
|
+
|
|
1758
|
+
// Only parse argv when run directly (`aivin ...` / `node bin/cli.mjs ...`),
|
|
1759
|
+
// not when this module is imported (e.g. by tests) - otherwise Commander
|
|
1760
|
+
// would parse the importing process's argv and could call process.exit().
|
|
1761
|
+
//
|
|
1762
|
+
// `import.meta.url` is always the module's real (symlink-resolved) path, but `process.argv[1]` is
|
|
1763
|
+
// whatever literal path launched it - through `npm link`'s global shim that's a symlink
|
|
1764
|
+
// (~/AppData/Roaming/npm/node_modules/@aivin-labs/sdk/bin/cli.mjs -> this repo), which would never
|
|
1765
|
+
// string-equal the resolved URL and silently skip program.parse() entirely (global `aivin` would
|
|
1766
|
+
// do nothing at all). Resolve argv[1] through the same symlink before comparing.
|
|
1767
|
+
function resolveIsMain() {
|
|
1768
|
+
// Tệp chạy đóng gói: chính nó là chương trình, không có chuyện bị import.
|
|
1769
|
+
if (process.env.AIVIN_CLI_BINARY) return true;
|
|
1770
|
+
if (!process.argv[1]) return false;
|
|
1771
|
+
try {
|
|
1772
|
+
return import.meta.url === pathToFileURL(fs.realpathSync(process.argv[1])).href;
|
|
1773
|
+
} catch {
|
|
1774
|
+
return import.meta.url === pathToFileURL(process.argv[1]).href;
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1778
|
+
if (resolveIsMain()) {
|
|
1779
|
+
program.parse(process.argv);
|
|
1780
|
+
}
|