@aivin-labs/cli 1.0.11 → 1.0.13

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.
Files changed (41) hide show
  1. package/README.md +16 -0
  2. package/bin/cli.mjs +67 -0
  3. package/bin/lib/remote/browserTunnel.mjs +47 -8
  4. package/bin/lib/remote/callLedger.mjs +73 -14
  5. package/bin/lib/remote/client.mjs +89 -8
  6. package/bin/lib/remote/cloudFiles.mjs +53 -0
  7. package/bin/lib/remote/constants.mjs +17 -0
  8. package/bin/lib/remote/dailyBrowser.mjs +8 -2
  9. package/bin/lib/remote/desktop/desktopCast.mjs +198 -0
  10. package/bin/lib/remote/desktop/desktopCastSource.mjs +514 -0
  11. package/bin/lib/remote/desktop/desktopWebRtc.mjs +95 -0
  12. package/bin/lib/remote/desktop/index.mjs +44 -7
  13. package/bin/lib/remote/desktop/linux.mjs +1 -1
  14. package/bin/lib/remote/desktop/linuxTraySource.mjs +434 -427
  15. package/bin/lib/remote/desktop/mac.mjs +2 -2
  16. package/bin/lib/remote/desktop/macTraySource.mjs +295 -292
  17. package/bin/lib/remote/desktop/traySource.mjs +541 -527
  18. package/bin/lib/remote/deviceProfile.mjs +1 -0
  19. package/bin/lib/remote/docText.mjs +85 -0
  20. package/bin/lib/remote/fileIndexer.mjs +757 -399
  21. package/bin/lib/remote/folderRules.mjs +140 -0
  22. package/bin/lib/remote/gui/index.mjs +126 -17
  23. package/bin/lib/remote/gui/windowsHost.mjs +9 -2
  24. package/bin/lib/remote/gui/windowsHostSource.mjs +194 -51
  25. package/bin/lib/remote/idempotency.mjs +49 -20
  26. package/bin/lib/remote/localPolicy.mjs +8 -2
  27. package/bin/lib/remote/mascot/askHostSource.mjs +18 -0
  28. package/bin/lib/remote/mascot/bot.mjs +29 -4
  29. package/bin/lib/remote/mascot/hostSource.mjs +4 -4
  30. package/bin/lib/remote/mascot/rigSource.mjs +12 -7
  31. package/bin/lib/remote/osSearch.mjs +107 -0
  32. package/bin/lib/remote/sqliteDb.mjs +51 -0
  33. package/bin/lib/remote/toolHandlers.mjs +788 -741
  34. package/bin/lib/remoteControl.mjs +26 -26
  35. package/docs/AIVIN_MASCOT.md +14 -0
  36. package/docs/CLI.md +1504 -1484
  37. package/docs/media/aivin-mascot-live.gif +0 -0
  38. package/docs/media/aivin-mascot-live.png +0 -0
  39. package/docs/media/aivin-remote-architecture.svg +102 -0
  40. package/package.json +71 -71
  41. package/docs/media/aivin-mascot-states.mp4 +0 -0
@@ -4,6 +4,7 @@ import path from 'path';
4
4
  import { createHash } from 'crypto';
5
5
  import { execFileSync, spawn } from 'child_process';
6
6
  import { REMOTE_CONFIG_DIR } from '../constants.mjs';
7
+ import { lockHolder } from '../daemonLock.mjs';
7
8
  import { AIVIN_LOGO_PNG_BASE64 } from '../brand.mjs';
8
9
  import { TRAY_CS } from './traySource.mjs';
9
10
  import { trayStrings } from './strings.mjs';
@@ -31,7 +32,7 @@ export function launcherExePath(env = process.env) {
31
32
  }
32
33
 
33
34
  /** Tên hiện ở Start menu / Task Manager → Startup apps (mô tả của Aivin.exe) / khay: "AIVIN Bot CLI" (30/10/2026; trước là "Aivin"). */
34
- export const DISPLAY_NAME = 'AIVIN Bot CLI';
35
+ export const DISPLAY_NAME = 'AIVIN Bot';
35
36
  const startMenuDir = (env) => path.join(env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming'), 'Microsoft', 'Windows', 'Start Menu', 'Programs');
36
37
 
37
38
  export function startMenuShortcutPath(env = process.env) {
@@ -39,9 +40,12 @@ export function startMenuShortcutPath(env = process.env) {
39
40
  }
40
41
 
41
42
  /** Lối tắt tên cũ ("Aivin.lnk") — dọn khi cài / gỡ để Start menu không có hai mục. */
42
- export function legacyStartMenuShortcutPath(env = process.env) {
43
- return path.join(startMenuDir(env), 'Aivin.lnk');
44
- }
43
+ export function legacyStartMenuShortcutPaths(env = process.env) {
44
+ return [path.join(startMenuDir(env), 'Aivin.lnk'), path.join(startMenuDir(env), 'AIVIN Bot CLI.lnk')];
45
+ }
46
+ export function legacyStartMenuShortcutPath(env = process.env) {
47
+ return legacyStartMenuShortcutPaths(env)[0];
48
+ }
45
49
 
46
50
  /** Mã C# của Aivin.exe cho thư mục cấu hình này (gắn cứng: lối tắt / khoá Run không mang biến môi trường AIVIN_REMOTE_HOME theo). */
47
51
  export function launcherSource(home = REMOTE_CONFIG_DIR) {
@@ -232,6 +236,37 @@ export function isDesktopInstalled() {
232
236
  */
233
237
  export const TrayLaunch = Object.freeze({ OPEN: 'open', AUTOSTART: 'autostart', INSTALLED: 'installed' });
234
238
 
239
+ const sleepSync = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
240
+
241
+ function trayRunning() {
242
+ try {
243
+ const out = execFileSync('tasklist', ['/FI', 'IMAGENAME eq Aivin.exe', '/FI', `USERNAME eq ${os.userInfo().username}`, '/NH'], { encoding: 'utf8', timeout: 10_000, windowsHide: true });
244
+ return /Aivin\.exe/i.test(out);
245
+ } catch {
246
+ return false;
247
+ }
248
+ }
249
+
250
+ /**
251
+ * Khay bản cũ đang chạy (vừa biên dịch bản mới): bảo nó thoát (dừng luôn listener nó giữ) và chờ — không thì bản mới mở lên gặp mutex
252
+ * một-bản-chạy, thoát im lặng, khay cũ chạy mã cũ tới lần đăng nhập sau.
253
+ */
254
+ export function quitRunningTray({ exe = launcherExePath(), wait = sleepSync } = {}) {
255
+ if (!trayRunning()) return false;
256
+ try { execFileSync(exe, ['--quit'], { stdio: 'ignore', windowsHide: true, timeout: 10_000 }); } catch { /* không chạy */ }
257
+ for (let i = 0; i < 40 && trayRunning(); i++) wait(250);
258
+ return true;
259
+ }
260
+
261
+ /**
262
+ * Khay vẫn là bản này nhưng aivin vừa được cài lại / nâng bản: listener đang chạy vẫn giữ mã cũ trong bộ nhớ tới lần khởi động máy sau —
263
+ * dừng nó, khay mở lại bằng tệp mới sau ~2 s.
264
+ */
265
+ function restartListener() {
266
+ const pid = lockHolder();
267
+ if (pid) try { process.kill(pid); } catch { /* vừa tự thoát */ }
268
+ }
269
+
235
270
  export function launchTray({ exe = launcherExePath(), mode = TrayLaunch.OPEN } = {}) {
236
271
  const args = mode === TrayLaunch.OPEN ? [] : [`--${mode}`];
237
272
  spawn(exe, args, { detached: true, stdio: 'ignore', windowsHide: true }).unref();
@@ -247,22 +282,24 @@ export function installDesktop({ argv, rollback = null, lang = 'en', autostart =
247
282
  fs.writeFileSync(LOGO_FILE, Buffer.from(AIVIN_LOGO_PNG_BASE64, 'base64'));
248
283
  const { exe, built } = ensureLauncher();
249
284
  const lnk = startMenuShortcutPath();
250
- fs.rmSync(legacyStartMenuShortcutPath(), { force: true });
285
+ for (const p of legacyStartMenuShortcutPaths()) fs.rmSync(p, { force: true });
251
286
  if (built || !fs.existsSync(lnk)) ensureStartMenuShortcut({ exe, lnk, lang });
252
287
  if (autostart) registerStartup(exe);
288
+ if (launch && built) quitRunningTray({ exe });
289
+ else if (launch) restartListener();
253
290
  if (launch) launchTray({ exe, mode: launchMode });
254
291
  return { exe, shortcut: lnk, built, autostart: startupState().enabled };
255
292
  }
256
293
 
257
294
  /** Gỡ: đóng khay (dừng daemon nó đang giữ), xoá mục khởi động, lối tắt, Aivin.exe, desktop\. */
258
- export function uninstallDesktop({ wait = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms) } = {}) {
295
+ export function uninstallDesktop({ wait = sleepSync } = {}) {
259
296
  const exe = launcherExePath();
260
297
  if (fs.existsSync(exe)) {
261
298
  try { execFileSync(exe, ['--quit'], { stdio: 'ignore', windowsHide: true, timeout: 10_000 }); } catch { /* không chạy */ }
262
299
  }
263
300
  unregisterStartup();
264
301
  fs.rmSync(startMenuShortcutPath(), { force: true });
265
- fs.rmSync(legacyStartMenuShortcutPath(), { force: true });
302
+ for (const p of legacyStartMenuShortcutPaths()) fs.rmSync(p, { force: true });
266
303
  for (let i = 0; i < 20 && fs.existsSync(exe); i++) {
267
304
  try { fs.rmSync(exe, { force: true }); } catch { wait(250); }
268
305
  }
@@ -44,7 +44,7 @@ export function linuxDesktopEntry({ launcher = LINUX_LAUNCHER_FILE, icon = LOGO_
44
44
  '[Desktop Entry]',
45
45
  'Type=Application',
46
46
  'Version=1.0',
47
- 'Name=AIVIN Bot CLI',
47
+ 'Name=AIVIN Bot',
48
48
  `Comment=${s.shortcut}`,
49
49
  `Exec=${desktopExecArg(launcher)}${autostart ? ' --autostart' : ''}`,
50
50
  `Icon=${icon}`,