@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
@@ -89,7 +89,8 @@ ${Object.entries(BOT_MOTION).map(motionCase).join('\n')}
89
89
  const double LEAN_MAX = 16;
90
90
  readonly System.Windows.FrameworkElement w;
91
91
  readonly System.Windows.UIElement bot, shadow, earL, earR, visorFx, face;
92
- readonly System.Windows.Shapes.Shape tint, halo;
92
+ readonly System.Windows.Shapes.Shape tint, halo;
93
+ readonly System.Windows.UIElement blushL, blushR;
93
94
  readonly ScaleTransform botScale, shadowScale, faceScale, mouthOpen, talk;
94
95
  readonly RotateTransform botLean, headRot, antRot;
95
96
  readonly TranslateTransform botMove, headMove, faceLook, eyeLook, scanY;
@@ -124,7 +125,7 @@ ${Object.entries(BOT_MOTION).map(motionCase).join('\n')}
124
125
  readonly Spring lookX = new Spring(0), lookY = new Spring(0), near = new Spring(0);
125
126
  int curX = int.MinValue, curY = int.MinValue; double curMovedAt = -10;
126
127
  double prevHead, prevHeadVel, headAcc;
127
- double nextBlink = 1.2, blinkAt = -10; bool doubleBlink;
128
+ double nextBlink = 1.2, blinkAt = -10, blushAt = -10; bool doubleBlink;
128
129
  double nextGlance = 2, glanceX, glanceY;
129
130
  double hopAt = -10, shakeAt = -10, nodAt = -10, perkAt = -10, flashAt = -10;
130
131
  bool hopKick, landKick;
@@ -171,7 +172,7 @@ ${Object.entries(BOT_MOTION).map(motionCase).join('\n')}
171
172
  bot = Get<System.Windows.UIElement>("Bot"); shadow = Get<System.Windows.UIElement>("Shadow");
172
173
  earL = Get<System.Windows.UIElement>("EarGlowL"); earR = Get<System.Windows.UIElement>("EarGlowR");
173
174
  visorFx = Get<System.Windows.UIElement>("VisorFx"); face = Get<System.Windows.UIElement>("Face");
174
- tint = Get<System.Windows.Shapes.Shape>("AntennaTint"); halo = Get<System.Windows.Shapes.Shape>("AntennaHalo");
175
+ tint = Get<System.Windows.Shapes.Shape>("AntennaTint"); halo = Get<System.Windows.Shapes.Shape>("AntennaHalo"); blushL = w.FindName("BlushL") as System.Windows.UIElement; blushR = w.FindName("BlushR") as System.Windows.UIElement;
175
176
  botScale = Get<ScaleTransform>("BotScale"); shadowScale = Get<ScaleTransform>("ShadowScale"); faceScale = Get<ScaleTransform>("FaceScale");
176
177
  mouthOpen = Get<ScaleTransform>("MouthOpenScale"); talk = Get<ScaleTransform>("MouthTalkScale");
177
178
  botLean = Get<RotateTransform>("BotLean"); headRot = Get<RotateTransform>("HeadRot"); antRot = Get<RotateTransform>("AntennaRot");
@@ -297,9 +298,10 @@ ${SCREENS.map((sc, i) => ` screens.Add(MakeScreen(${i}, ${n(sc.tilt)}, ${n(
297
298
  double t = Now;
298
299
  switch (g) {
299
300
  case "dizzy": dizzyAt = t; antA.V += 220; break;
300
- case "giggle": giggleAt = t; antA.V -= 140; blinkAt = t; break;
301
+ case "giggle": giggleAt = t; antA.V -= 140; blinkAt = t; blushAt = t; break;
301
302
  case "purr": purrUntil = t + 0.9; break;
302
- case "wave": hopAt = t; hopKick = landKick = false; perkAt = t + 0.6; flashAt = t; break;
303
+ case "wave": hopAt = t; hopKick = landKick = false; perkAt = t + 0.6; flashAt = t; blushAt = t; break;
304
+ case "wink": blinkAt = t; blushAt = t; antA.V -= 60; break;
303
305
  // Busy -> needs you: a start (eyes pop wide, antenna jolts, a quick rise) before the waiting look.
304
306
  case "startle": perkAt = t; flashAt = t; antA.V -= 260; eyeSq.V += 6; pop.V += 2.5; break;
305
307
  // Done after an error: no hop - sag with a slow breath out, then perk up.
@@ -474,7 +476,8 @@ ${SCREENS.map((sc, i) => ` screens.Add(MakeScreen(${i}, ${n(sc.tilt)}, ${n(
474
476
  if (cu >= 0 && cu < 1) { double k = cu * cu * (3 - 2 * cu); tintBrush.Color = Mix(colorFrom, colorTo, k); }
475
477
  else if (hasColor && tintBrush.Color != colorTo) tintBrush.Color = colorTo;
476
478
  tint.Opacity = tv; halo.Opacity = Clamp(0.12 + (tv - 0.45) * 0.9 + flash * 0.5, 0, 0.8);
477
- visorFx.Opacity = scan; scanY.Y = (scanPhase % 1.0) * VISOR_SCAN;
479
+ visorFx.Opacity = scan; scanY.Y = (scanPhase % 1.0) * VISOR_SCAN;
480
+ double blush = Math.Max(purrK * 0.9, Bump(t - blushAt, 1.8) * 0.85); if (blushL != null) blushL.Opacity = blush; if (blushR != null) blushR.Opacity = blush;
478
481
 
479
482
  // 7) Screens (working): flip up from edge-on one after another with a little overshoot, drift, the focused one lights up;
480
483
  // text scrolls / bars bounce. Collapsed when folded away (no 3D work). Zzz (offline): letters drift up and fade.
@@ -569,10 +572,12 @@ ${SCREENS.map((sc, i) => ` screens.Add(MakeScreen(${i}, ${n(sc.tilt)}, ${n(
569
572
  if (state == "working" && inState > 15) { if (rnd.NextDouble() < 0.5) squintAt = t; else nodAt = t; }
570
573
  else if (state == "waiting" && inState > 12) {
571
574
  askAt = t; askSide = rnd.NextDouble() < 0.5 ? -1 : 1; askLevel = Math.Min(askLevel + 1, 3);
572
- if (askLevel >= 2) perkAt = t + 0.3;
575
+ if (askLevel >= 2) perkAt = t + 0.3;
576
+ SetFace("curious", "hmm");
573
577
  }
574
578
  }
575
579
  }
580
+ if (state == "waiting" && t - askAt >= 2.0 && eyesNow == "curious" && eyesNext == null) SetFace("wide", "open");
576
581
  mouthOpen.ScaleY = 1 + Math.Sin(t * 3.4) * 0.1; mouthOpen.ScaleX = 1 - Math.Sin(t * 3.4) * 0.05;
577
582
  talk.ScaleY = 0.45 + 0.55 * Math.Abs(Math.Sin(t * 12));
578
583
 
@@ -0,0 +1,107 @@
1
+ import { execFile } from 'child_process';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { isProtectedPath } from './sandbox.mjs';
5
+
6
+ /**
7
+ * Tìm tệp qua bộ tìm của hệ điều hành — cho những gì chỉ mục của Aivin cố ý bỏ (thư mục gộp, kho code, ổ khác ngoài thư mục nhà…): Windows
8
+ * Search (SystemIndex), macOS Spotlight (`mdfind`), Linux `plocate` / `locate`. Không dựng gì thêm trên máy; hệ điều hành không có / tắt bộ
9
+ * tìm → trả rỗng. Kết quả luôn lọc lại theo gốc được phép + vùng cấm (bộ tìm của hệ điều hành không biết sàn của Aivin).
10
+ */
11
+
12
+ const MAX_WORDS = 6;
13
+ const DEFAULT_TIMEOUT_MS = 4000;
14
+
15
+ const wordsOf = (query) => [...new Set(String(query || '').split(/[^\p{L}\p{N}]+/u).filter((w) => w.length >= 2))].slice(0, MAX_WORDS);
16
+
17
+ function run(cmd, args, { env, timeoutMs }) {
18
+ return new Promise((resolve) => {
19
+ execFile(cmd, args, { env: { ...process.env, ...env }, windowsHide: true, timeout: timeoutMs, maxBuffer: 8 * 1024 * 1024, encoding: 'utf8' },
20
+ (_err, stdout) => resolve(String(stdout || '')));
21
+ });
22
+ }
23
+
24
+ /** Câu SQL cho Windows Search: mọi từ đều phải khớp tên tệp hoặc nội dung đã được Windows lập chỉ mục; chỉ trong các gốc. */
25
+ export function windowsSearchSql(words, roots, limit) {
26
+ const scope = roots.map((r) => `SCOPE='file:${r.replace(/\\/g, '/').replace(/'/g, "''")}'`).join(' OR ');
27
+ const cond = words.map((w) => `(System.FileName LIKE '%${w}%' OR CONTAINS(*, '"${w}*"'))`).join(' AND ');
28
+ return `SELECT TOP ${limit} System.ItemPathDisplay, System.Size, System.DateModified FROM SystemIndex WHERE (${scope}) AND ${cond} ORDER BY System.Search.Rank DESC`;
29
+ }
30
+
31
+ const WINDOWS_SCRIPT = `
32
+ $ErrorActionPreference = 'Stop'
33
+ [Console]::OutputEncoding = [Text.Encoding]::UTF8
34
+ $c = New-Object -ComObject ADODB.Connection
35
+ $c.Open("Provider=Search.CollatorDSO;Extended Properties='Application=Windows';")
36
+ $rs = New-Object -ComObject ADODB.Recordset
37
+ $rs.Open($env:AIVIN_OS_SQL, $c)
38
+ while (-not $rs.EOF) {
39
+ $m = $rs.Fields.Item('System.DateModified').Value
40
+ $d = if ($m -is [datetime]) { $m.ToString('yyyy-MM-dd') } else { '' }
41
+ [Console]::Out.WriteLine([string]$rs.Fields.Item('System.ItemPathDisplay').Value + [char]9 + [string]$rs.Fields.Item('System.Size').Value + [char]9 + $d)
42
+ $rs.MoveNext()
43
+ }
44
+ `;
45
+
46
+ async function searchWindows(words, roots, limit, timeoutMs, exec) {
47
+ const out = await exec('powershell.exe', ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-Command', WINDOWS_SCRIPT], {
48
+ env: { AIVIN_OS_SQL: windowsSearchSql(words, roots, limit) }, timeoutMs,
49
+ });
50
+ return out.split(/\r?\n/).filter(Boolean).map((line) => {
51
+ const [abs, size, modified] = line.split('\t');
52
+ return { abs, size: size ? Number(size) : undefined, modified: modified || undefined };
53
+ });
54
+ }
55
+
56
+ async function searchMac(words, roots, limit, timeoutMs, exec) {
57
+ const lists = await Promise.all(roots.map((r) => exec('mdfind', ['-onlyin', r, words.join(' ')], { timeoutMs })));
58
+ return lists.flatMap((o) => o.split('\n')).filter(Boolean).slice(0, limit * 3).map((abs) => ({ abs }));
59
+ }
60
+
61
+ async function searchLinux(words, limit, timeoutMs, exec) {
62
+ for (const cmd of ['plocate', 'locate']) {
63
+ const out = await exec(cmd, ['-i', '-l', String(limit * 20), words[0]], { timeoutMs });
64
+ if (out) return out.split('\n').filter(Boolean).map((abs) => ({ abs }));
65
+ }
66
+ return [];
67
+ }
68
+
69
+ const inRoots = (abs, roots) => roots.some((r) => {
70
+ const rel = path.relative(r, abs);
71
+ return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
72
+ });
73
+
74
+ /**
75
+ * Tìm `query` qua bộ tìm của hệ điều hành trong `roots` → `[{ abs, size?, modified? }]` (tối đa `limit`). Lỗi / hết giờ / không có bộ tìm →
76
+ * mảng rỗng (không bao giờ ném lỗi).
77
+ */
78
+ export async function osFileSearch(query, { roots, limit = 10, timeoutMs = DEFAULT_TIMEOUT_MS, platform = process.platform, exec = run } = {}) {
79
+ const words = wordsOf(query);
80
+ if (!words.length || !roots?.length) return [];
81
+ const resolved = roots.map((r) => path.resolve(r));
82
+ let found;
83
+ try {
84
+ if (platform === 'win32') found = await searchWindows(words, resolved, limit * 2, timeoutMs, exec);
85
+ else if (platform === 'darwin') found = await searchMac(words, resolved, limit, timeoutMs, exec);
86
+ else found = await searchLinux(words, limit, timeoutMs, exec);
87
+ } catch {
88
+ return [];
89
+ }
90
+ const lower = words.map((w) => w.toLowerCase());
91
+ const out = [];
92
+ for (const hit of found) {
93
+ if (out.length >= limit) break;
94
+ if (!hit.abs || !path.isAbsolute(hit.abs) || !inRoots(hit.abs, resolved) || isProtectedPath(hit.abs)) continue;
95
+ // locate chỉ lọc được theo một từ — các từ còn lại khớp trên đường dẫn.
96
+ if (platform === 'linux' && !lower.every((w) => hit.abs.toLowerCase().includes(w))) continue;
97
+ if (hit.size === undefined) {
98
+ try {
99
+ const st = fs.statSync(hit.abs);
100
+ hit.size = st.isFile() ? st.size : undefined;
101
+ hit.modified = new Date(st.mtimeMs).toISOString().slice(0, 10);
102
+ } catch { continue; }
103
+ }
104
+ out.push(hit);
105
+ }
106
+ return out;
107
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * SQLite có sẵn trong runtime, không thêm gói: `bun:sqlite` (bản aivin.exe đóng gói bằng Bun) hoặc `node:sqlite` (chạy từ npm / mã nguồn,
3
+ * Node ≥ 22.13). Nạp lúc cần (import động) — Node cũ hơn vẫn chạy được phần còn lại của CLI. Trả một lớp mỏng chung: `exec`, `prepare`
4
+ * (`run` / `get` / `all`, tham số theo vị trí), `transaction`, `close`.
5
+ */
6
+ export async function openSqlite(file) {
7
+ if (globalThis.Bun) {
8
+ const { Database } = await import('bun:sqlite');
9
+ return wrap(new Database(file, { create: true }));
10
+ }
11
+ // node:sqlite còn gắn nhãn thử nghiệm: bỏ đúng cảnh báo đó, không để nó lẫn vào đầu ra của CLI.
12
+ const emit = process.emitWarning;
13
+ process.emitWarning = (warning, ...rest) => {
14
+ if (/SQLite/i.test(String(warning?.message ?? warning))) return;
15
+ emit.call(process, warning, ...rest);
16
+ };
17
+ try {
18
+ const { DatabaseSync } = await import('node:sqlite');
19
+ return wrap(new DatabaseSync(file));
20
+ } finally {
21
+ process.emitWarning = emit;
22
+ }
23
+ }
24
+
25
+ function wrap(db) {
26
+ const prepare = (sql) => {
27
+ const st = db.prepare(sql);
28
+ return {
29
+ run: (...args) => st.run(...args),
30
+ get: (...args) => st.get(...args) ?? undefined,
31
+ all: (...args) => st.all(...args),
32
+ };
33
+ };
34
+ return {
35
+ exec: (sql) => db.exec(sql),
36
+ prepare,
37
+ /** Chạy `fn` trong một giao dịch (lỗi → huỷ cả khối). */
38
+ transaction(fn) {
39
+ db.exec('BEGIN');
40
+ try {
41
+ const out = fn();
42
+ db.exec('COMMIT');
43
+ return out;
44
+ } catch (e) {
45
+ db.exec('ROLLBACK');
46
+ throw e;
47
+ }
48
+ },
49
+ close: () => db.close(),
50
+ };
51
+ }