@aivin-labs/cli 1.0.5 → 1.0.11

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 (93) hide show
  1. package/README.md +288 -216
  2. package/bin/assets/aivin-mascot.png +0 -0
  3. package/bin/cli.mjs +551 -5
  4. package/bin/lib/browserAutomation.mjs +384 -614
  5. package/bin/lib/browserTui.mjs +276 -251
  6. package/bin/lib/cancellation.mjs +61 -0
  7. package/bin/lib/localBrowser.mjs +345 -0
  8. package/bin/lib/mcpProxy.mjs +869 -837
  9. package/bin/lib/missionStream.mjs +696 -691
  10. package/bin/lib/releaseKeys.mjs +9 -0
  11. package/bin/lib/remote/activityLog.mjs +68 -0
  12. package/bin/lib/remote/autoStart.mjs +617 -0
  13. package/bin/lib/remote/autoUpdate.mjs +129 -0
  14. package/bin/lib/remote/brand.mjs +60 -0
  15. package/bin/lib/remote/browserTunnel.mjs +403 -0
  16. package/bin/lib/remote/callLedger.mjs +134 -0
  17. package/bin/lib/remote/cdpPolicy.mjs +79 -0
  18. package/bin/lib/remote/client.mjs +808 -0
  19. package/bin/lib/remote/clipboard.mjs +138 -0
  20. package/bin/lib/remote/codingAgents.mjs +293 -0
  21. package/bin/lib/remote/constants.mjs +234 -0
  22. package/bin/lib/remote/credentials.mjs +208 -0
  23. package/bin/lib/remote/daemonLock.mjs +86 -0
  24. package/bin/lib/remote/dailyBrowser.mjs +371 -0
  25. package/bin/lib/remote/desktop/index.mjs +272 -0
  26. package/bin/lib/remote/desktop/linux.mjs +144 -0
  27. package/bin/lib/remote/desktop/linuxTraySource.mjs +427 -0
  28. package/bin/lib/remote/desktop/mac.mjs +187 -0
  29. package/bin/lib/remote/desktop/macTraySource.mjs +292 -0
  30. package/bin/lib/remote/desktop/strings.mjs +74 -0
  31. package/bin/lib/remote/desktop/traySource.mjs +527 -0
  32. package/bin/lib/remote/deviceMemory.mjs +246 -0
  33. package/bin/lib/remote/deviceProfile.mjs +142 -0
  34. package/bin/lib/remote/deviceWatches.mjs +138 -0
  35. package/bin/lib/remote/docText.mjs +117 -0
  36. package/bin/lib/remote/fileIndexer.mjs +399 -0
  37. package/bin/lib/remote/gui/index.mjs +326 -0
  38. package/bin/lib/remote/gui/officeHostSource.mjs +393 -0
  39. package/bin/lib/remote/gui/windowsHost.mjs +109 -0
  40. package/bin/lib/remote/gui/windowsHostSource.mjs +1156 -0
  41. package/bin/lib/remote/httpTransfer.mjs +89 -0
  42. package/bin/lib/remote/idempotency.mjs +135 -0
  43. package/bin/lib/remote/keepAwake.mjs +100 -0
  44. package/bin/lib/remote/localConfirm.mjs +268 -0
  45. package/bin/lib/remote/localPolicy.mjs +256 -0
  46. package/bin/lib/remote/mascot/adpcm.mjs +70 -0
  47. package/bin/lib/remote/mascot/ask.mjs +768 -0
  48. package/bin/lib/remote/mascot/askHostSource.mjs +512 -0
  49. package/bin/lib/remote/mascot/assets.mjs +827 -0
  50. package/bin/lib/remote/mascot/bot.mjs +372 -0
  51. package/bin/lib/remote/mascot/hostSource.mjs +759 -0
  52. package/bin/lib/remote/mascot/hotkey.mjs +66 -0
  53. package/bin/lib/remote/mascot/index.mjs +493 -0
  54. package/bin/lib/remote/mascot/labels.mjs +82 -0
  55. package/bin/lib/remote/mascot/rigSource.mjs +609 -0
  56. package/bin/lib/remote/mascot/strings.mjs +375 -0
  57. package/bin/lib/remote/mascot/ui.mjs +104 -0
  58. package/bin/lib/remote/mascot/voiceSource.mjs +584 -0
  59. package/bin/lib/remote/meeting/index.mjs +415 -0
  60. package/bin/lib/remote/meeting/recorder.mjs +109 -0
  61. package/bin/lib/remote/meeting/recorderSource.mjs +394 -0
  62. package/bin/lib/remote/meeting/transcribe.mjs +259 -0
  63. package/bin/lib/remote/memberFsPool.mjs +134 -0
  64. package/bin/lib/remote/memberFsWorker.mjs +60 -0
  65. package/bin/lib/remote/mission.mjs +156 -0
  66. package/bin/lib/remote/missionQuestion.mjs +63 -0
  67. package/bin/lib/remote/multiUser.mjs +344 -0
  68. package/bin/lib/remote/netProxy.mjs +145 -0
  69. package/bin/lib/remote/notify.mjs +58 -0
  70. package/bin/lib/remote/office/index.mjs +90 -0
  71. package/bin/lib/remote/policyCommand.mjs +93 -0
  72. package/bin/lib/remote/processes.mjs +217 -0
  73. package/bin/lib/remote/sandbox.mjs +221 -0
  74. package/bin/lib/remote/schedule.mjs +213 -0
  75. package/bin/lib/remote/scheduler.mjs +124 -0
  76. package/bin/lib/remote/tabGroups.mjs +209 -0
  77. package/bin/lib/remote/textIndex.mjs +131 -0
  78. package/bin/lib/remote/tokenStore.mjs +77 -0
  79. package/bin/lib/remote/toolHandlers.mjs +741 -0
  80. package/bin/lib/remote/undoStore.mjs +242 -0
  81. package/bin/lib/remoteControl.mjs +26 -0
  82. package/bin/lib/scaffold.mjs +654 -653
  83. package/bin/lib/selfUpdate.mjs +71 -0
  84. package/bin/lib/update/binarySwap.mjs +63 -0
  85. package/bin/lib/update/constants.mjs +56 -0
  86. package/bin/lib/update/download.mjs +145 -0
  87. package/bin/lib/update/signature.mjs +42 -0
  88. package/bin/lib/update/state.mjs +205 -0
  89. package/bin/lib/update/versions.mjs +60 -0
  90. package/docs/AIVIN_MASCOT.md +116 -0
  91. package/docs/CLI.md +1484 -1299
  92. package/docs/media/aivin-mascot-states.mp4 +0 -0
  93. package/package.json +71 -62
@@ -0,0 +1,77 @@
1
+ import { execFileSync } from 'child_process';
2
+ import fs from 'fs';
3
+
4
+ /**
5
+ * Token thiết bị cất trong kho bí mật của hệ điều hành (29/10/2026). Trước đây `~/.aivin/device-credentials.json` giữ token dạng chữ thường
6
+ * (chỉ có quyền 600) — chép thư mục `.aivin` (sao lưu, đồng bộ đám mây, ổ cứng bị lấy) là mang theo được quyền điều khiển máy.
7
+ * - Windows: DPAPI phạm vi người dùng hiện tại (`ProtectedData`, qua PowerShell) — bản mã nằm trong tệp, chỉ đúng tài khoản Windows trên
8
+ * đúng máy này giải được.
9
+ * - macOS: Keychain đăng nhập (`security`), tệp chỉ còn dấu "token ở Keychain".
10
+ * - Linux: Secret Service (`secret-tool`, GNOME Keyring / KWallet) khi có phiên D-Bus; máy chủ không có kho → tệp quyền 600 như cũ.
11
+ * Bảo vệ khỏi chép tệp sang nơi khác; KHÔNG chống được mã độc chạy dưới chính tài khoản người dùng (nó gọi được cùng API).
12
+ */
13
+
14
+ export const TokenStoreKind = Object.freeze({ DPAPI: 'dpapi', KEYCHAIN: 'keychain', LIBSECRET: 'libsecret', FILE: 'file' });
15
+
16
+ const SERVICE = 'aivin-device-token';
17
+ /** Thêm vào DPAPI để ứng dụng khác của cùng người dùng không giải mã nhầm / tình cờ (không phải bí mật). */
18
+ const DPAPI_ENTROPY = 'aivin-device-token-v1';
19
+
20
+ const PS = ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-Command'];
21
+ const DPAPI_PROTECT = `Add-Type -AssemblyName System.Security; $e = [Text.Encoding]::UTF8.GetBytes('${DPAPI_ENTROPY}'); $b = [Text.Encoding]::UTF8.GetBytes([Console]::In.ReadToEnd()); [Convert]::ToBase64String([Security.Cryptography.ProtectedData]::Protect($b, $e, 'CurrentUser'))`;
22
+ const DPAPI_UNPROTECT = `Add-Type -AssemblyName System.Security; $e = [Text.Encoding]::UTF8.GetBytes('${DPAPI_ENTROPY}'); $b = [Convert]::FromBase64String([Console]::In.ReadToEnd().Trim()); [Text.Encoding]::UTF8.GetString([Security.Cryptography.ProtectedData]::Unprotect($b, $e, 'CurrentUser'))`;
23
+
24
+ const run = (cmd, args, input) => execFileSync(cmd, args, { input, encoding: 'utf8', timeout: 20_000, windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'] }).trim();
25
+
26
+ /** Kho dùng trên máy này. `AIVIN_TOKEN_STORE=file` ép tệp thường (máy không có kho / gỡ lỗi). */
27
+ export function preferredTokenStore({ platform = process.platform, env = process.env, exists = fs.existsSync } = {}) {
28
+ const forced = String(env.AIVIN_TOKEN_STORE || '').toLowerCase();
29
+ if (Object.values(TokenStoreKind).includes(forced)) return forced;
30
+ if (platform === 'win32') return TokenStoreKind.DPAPI;
31
+ if (platform === 'darwin' && exists('/usr/bin/security')) return TokenStoreKind.KEYCHAIN;
32
+ if (platform === 'linux' && env.DBUS_SESSION_BUS_ADDRESS && ['/usr/bin/secret-tool', '/bin/secret-tool'].some((p) => exists(p))) return TokenStoreKind.LIBSECRET;
33
+ return TokenStoreKind.FILE;
34
+ }
35
+
36
+ const quote = (s) => `"${String(s).replace(/["\\]/g, '\\$&')}"`;
37
+
38
+ /**
39
+ * Cất token → phần ghi vào tệp: `{ token_store, token_enc? }` (kho hệ điều hành) hoặc `{ device_token }` (tệp thường). Kho lỗi (Keychain bị
40
+ * khoá, không có keyring…) → tệp thường, kèm `fallback_reason` để in ra.
41
+ */
42
+ export function sealToken(token, { account, store = preferredTokenStore() } = {}) {
43
+ try {
44
+ if (store === TokenStoreKind.DPAPI) return { token_store: store, token_enc: run('powershell.exe', [...PS, DPAPI_PROTECT], token) };
45
+ if (store === TokenStoreKind.KEYCHAIN) {
46
+ run('/usr/bin/security', ['-i'], `add-generic-password -U -a ${quote(account)} -s ${SERVICE} -l "Aivin device token" -w ${quote(token)}\n`);
47
+ return { token_store: store };
48
+ }
49
+ if (store === TokenStoreKind.LIBSECRET) {
50
+ run('secret-tool', ['store', '--label=Aivin device token', 'service', SERVICE, 'account', account], token);
51
+ return { token_store: store };
52
+ }
53
+ } catch (e) {
54
+ return { device_token: token, fallback_reason: String(e?.stderr || e?.message || e).trim().slice(0, 200) };
55
+ }
56
+ return { device_token: token };
57
+ }
58
+
59
+ /** Lấy lại token từ bản ghi trong tệp — `null` khi không giải được (tệp chép từ máy / tài khoản khác, kho đã xoá). */
60
+ export function openToken(record) {
61
+ if (!record) return null;
62
+ if (record.device_token) return record.device_token;
63
+ try {
64
+ if (record.token_store === TokenStoreKind.DPAPI && record.token_enc) return run('powershell.exe', [...PS, DPAPI_UNPROTECT], record.token_enc) || null;
65
+ if (record.token_store === TokenStoreKind.KEYCHAIN) return run('/usr/bin/security', ['find-generic-password', '-a', record.device_id, '-s', SERVICE, '-w']) || null;
66
+ if (record.token_store === TokenStoreKind.LIBSECRET) return run('secret-tool', ['lookup', 'service', SERVICE, 'account', record.device_id]) || null;
67
+ } catch { /* không giải được */ }
68
+ return null;
69
+ }
70
+
71
+ /** Xoá token khỏi kho hệ điều hành (DPAPI / tệp thường: xoá tệp là đủ). */
72
+ export function forgetToken(record) {
73
+ try {
74
+ if (record?.token_store === TokenStoreKind.KEYCHAIN) run('/usr/bin/security', ['delete-generic-password', '-a', record.device_id, '-s', SERVICE]);
75
+ if (record?.token_store === TokenStoreKind.LIBSECRET) run('secret-tool', ['clear', 'service', SERVICE, 'account', record.device_id]);
76
+ } catch { /* không có thì thôi */ }
77
+ }