@aivin-labs/cli 1.0.43 → 1.0.47

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.
@@ -20,6 +20,8 @@ export const BOT_RIG = Object.freeze({
20
20
  earR: { x: 170.6, y: 97.3, w: 12, h: 33 },
21
21
  /** Mặt vẽ theo đơn vị gốc rồi phóng FACE_SCALE, tâm đặt hơi dưới tâm kính. */
22
22
  face: { x: 97.2, y: 90.5, scale: 1.6, eyeDx: 15, eyeY: -3.5, mouthY: 10.5 },
23
+ /** Mắt khi có người đang xem máy: đoạn sóng sin rộng ±halfWidth, biên độ amp, bước sóng length (đơn vị mặt), trôi hz vòng/giây. */
24
+ wave: { halfWidth: 9.5, amp: 4.2, length: 15, hz: 1.1, segments: 24, stroke: 3.6 },
23
25
  /**
24
26
  * Màn hình 3D khi đang làm (Viewport3D thật, phối cảnh): tấm chính trước ngực + hai tấm nhỏ hai bên quây quanh bot. Bot chăm chú nhìn
25
27
  * lần lượt từng màn (mắt + đầu hướng theo `look` / `head`, màn đang nhìn sáng lên), ở mỗi màn `dwell` giây (ngẫu nhiên trong khoảng).
@@ -78,7 +80,7 @@ export const BOT_FACES = Object.freeze({
78
80
  sheepish: { eyes: 'happy', mouth: 'hmm' },
79
81
  });
80
82
 
81
- export const BOT_EYES = Object.freeze(['open', 'focus', 'up', 'wide', 'happy', 'closed', 'sad', 'dizzy', 'wink', 'curious', 'star', 'droop']);
83
+ export const BOT_EYES = Object.freeze(['open', 'focus', 'up', 'wide', 'happy', 'closed', 'sad', 'dizzy', 'wink', 'curious', 'star', 'droop', 'wave']);
82
84
  export const BOT_MOUTHS = Object.freeze(['smile', 'flat', 'hmm', 'open', 'grin', 'wobble', 'talk', 'frown', 'wail']);
83
85
 
84
86
  /**
@@ -116,6 +118,7 @@ const starEye = `<Path Data="M0,-6.5 Q1.2,-1.2 6.5,0 Q1.2,1.2 0,6.5 Q-1.2,1.2 -6
116
118
  export const BOT_SPINS = Object.freeze(['SpinL', 'SpinR']);
117
119
 
118
120
  /** Kiểu mắt: [trái, phải?] — thiếu phải thì dùng như trái. Mắt viên thuốc nào có tên Blink* thì chớp được. */
121
+ const waveEye = (name) => `<Polyline x:Name="${name}" Points="${-BOT_RIG.wave.halfWidth},0 ${BOT_RIG.wave.halfWidth},0" ${glowStroke(BOT_RIG.wave.stroke)}/>`;
119
122
  const EYE_SHAPES = {
120
123
  open: [pill(10, 14, 'BlinkL'), pill(10, 14, 'BlinkR')],
121
124
  focus: [pill(10, 8, 'BlinkFL'), pill(10, 8, 'BlinkFR')],
@@ -131,6 +134,7 @@ const EYE_SHAPES = {
131
134
  wink: [`<Path Data="M-8,3 Q0,-8 8,3" ${glowStroke()} Fill="{x:Null}"/>`, pill(10, 14, 'BlinkWnkR')],
132
135
  curious: [pill(10, 8, 'BlinkCurL'), pill(12.5, 16, 'BlinkCurR')],
133
136
  star: [starEye],
137
+ wave: [waveEye('WaveL'), waveEye('WaveR')],
134
138
  // Buồn / xin lỗi: mắt thấp hơn, lông mày xếch lên ở phía trong (hai đầu gần nhau cao hơn).
135
139
  droop: [
136
140
  `<Canvas Canvas.Top="1.5">${pill(10, 11, 'BlinkDrL')}</Canvas><Path Data="M-6.5,-8 L4.5,-11.5" ${glowStroke(2.6)}/>`,
@@ -691,9 +691,10 @@ function Wake($fromHover = $false) {
691
691
  }
692
692
  return $false
693
693
  }
694
+ $script:remoteView = $false
694
695
  $script:dozeTimer = New-Object Windows.Threading.DispatcherTimer; $script:dozeTimer.Interval = [TimeSpan]::FromSeconds(3)
695
696
  $script:dozeTimer.Add_Tick({
696
- if ($script:state -eq 'idle' -and -not $script:rig.Dozing -and -not $script:rig.Hover -and (E 'AskBox').Visibility -ne 'Visible' -and (E 'Panel').Visibility -ne 'Visible' -and ((Get-Date) - $script:lastActive).TotalSeconds -ge ${MASCOT_DOZE_SEC}) {
697
+ if (-not $script:remoteView -and $script:state -eq 'idle' -and -not $script:rig.Dozing -and -not $script:rig.Hover -and (E 'AskBox').Visibility -ne 'Visible' -and (E 'Panel').Visibility -ne 'Visible' -and ((Get-Date) - $script:lastActive).TotalSeconds -ge ${MASCOT_DOZE_SEC}) {
697
698
  # A yawn first, nodding off when yawn finishes (or on next tick).
698
699
  if (-not $script:yawned) { $script:yawned = $true; $script:rig.Play('yawn'); SetFace 'yawn'; $script:faceTimer.Stop(); $script:faceTimer.Interval = [TimeSpan]::FromSeconds(2.2); $script:faceTimer.Start() }
699
700
  elseif (-not $script:faceTimer.IsEnabled) { $script:rig.Doze($true); SetFace 'offline' }
@@ -961,6 +962,12 @@ function Handle($m) {
961
962
  'main' { if ($m.quiet) { SetText (E 'NowText') $m.text } else { ShowBubble $m.text $m.url } }
962
963
  'log' { LogEntry $m }
963
964
  'gui' { $script:guiHidden = [bool]$m.active; ApplyVisibility }
965
+ # Someone is viewing / controlling this computer: wave eyes for the whole session.
966
+ 'remote_view' {
967
+ $script:remoteView = [bool]$m.on
968
+ if ($script:remoteView) { [void](Wake) }
969
+ $script:rig.RemoteWave($script:remoteView)
970
+ }
964
971
  'show' { $script:userHidden = $false; ApplyVisibility }
965
972
  # Daemon-driven reaction, e.g. 'wave' when the user comes back, or the mood of an answer's emoji (mood.mjs: its own face + time).
966
973
  'gesture' {
@@ -1,16 +1,16 @@
1
-
2
- function formatDeviceLabel(raw, lang = 'vi') {
3
- if (!raw) return null;
4
- const isVi = lang === 'vi';
5
- const s = String(raw).trim();
6
- if (/iphone/i.test(s)) return isVi ? 'Điện thoại iPhone' : 'iPhone';
7
- if (/ipad/i.test(s)) return isVi ? 'Máy tính bảng iPad' : 'iPad';
8
- if (/android/i.test(s)) return isVi ? 'Điện thoại Android' : 'Android phone';
9
- if (/mac/i.test(s)) return isVi ? 'Máy tính Mac' : 'Mac computer';
10
- if (/win/i.test(s)) return isVi ? 'Máy tính khác' : 'Another computer';
11
- if (/web/i.test(s)) return isVi ? 'Trình duyệt web' : 'Web browser';
12
- return s;
13
- }
1
+
2
+ function formatDeviceLabel(raw, lang = 'vi') {
3
+ if (!raw) return null;
4
+ const isVi = lang === 'vi';
5
+ const s = String(raw).trim();
6
+ if (/iphone/i.test(s)) return isVi ? 'Điện thoại iPhone' : 'iPhone';
7
+ if (/ipad/i.test(s)) return isVi ? 'Máy tính bảng iPad' : 'iPad';
8
+ if (/android/i.test(s)) return isVi ? 'Điện thoại Android' : 'Android phone';
9
+ if (/mac/i.test(s)) return isVi ? 'Máy tính Mac' : 'Mac computer';
10
+ if (/win/i.test(s)) return isVi ? 'Máy tính khác' : 'Another computer';
11
+ if (/web/i.test(s)) return isVi ? 'Trình duyệt web' : 'Web browser';
12
+ return s;
13
+ }
14
14
  import fs from 'fs';
15
15
  import path from 'path';
16
16
  import readline from 'readline';
@@ -47,7 +47,7 @@ export const MascotState = Object.freeze({
47
47
  });
48
48
  export const LogStatus = Object.freeze({ RUN: 'run', OK: 'ok', FAIL: 'fail', INFO: 'info', WARN: 'warn' });
49
49
  /** Lệnh gửi cửa sổ / sự kiện cửa sổ gửi về (một dòng JSON mỗi lệnh). */
50
- export const HostCommand = Object.freeze({ STATE: 'state', MAIN: 'main', LOG: 'log', GUI: 'gui', SHOW: 'show', QUIT: 'quit', OPEN_ASK: 'open_ask', QUICK_VOICE: 'quick_voice', VOICE_TOGGLE: 'voice_toggle', GESTURE: 'gesture', NOTIFY_FREQ: 'notify_freq' });
50
+ export const HostCommand = Object.freeze({ STATE: 'state', MAIN: 'main', LOG: 'log', GUI: 'gui', SHOW: 'show', QUIT: 'quit', OPEN_ASK: 'open_ask', QUICK_VOICE: 'quick_voice', VOICE_TOGGLE: 'voice_toggle', GESTURE: 'gesture', NOTIFY_FREQ: 'notify_freq', REMOTE_VIEW: 'remote_view' });
51
51
 
52
52
  /** `aivin ui` (terminal khác) chạm tệp này → daemon đang chạy hiện linh vật + mở ô hỏi (mascot/ui.mjs). */
53
53
  export const MASCOT_SHOW_FILE = path.join(REMOTE_CONFIG_DIR, 'mascot-show');
@@ -130,8 +130,8 @@ const VOICE_EVENTS = new Set([HostEvent.VOICE_START, HostEvent.VOICE_AUDIO, Host
130
130
 
131
131
  const THINK_MS = 8000;
132
132
  const RESULT_MS = 6000;
133
- const MAIN_THROTTLE_MS = 600;
134
- /** Chờ chừng này trước khi báo mất kết nối: rớt mạng thoáng qua vài giây rồi tự nối lại ngay thì giữ im lặng, không bật bong bóng. */
133
+ const MAIN_THROTTLE_MS = 600;
134
+ /** Chờ chừng này trước khi báo mất kết nối: rớt mạng thoáng qua vài giây rồi tự nối lại ngay thì giữ im lặng, không bật bong bóng. */
135
135
  const OFFLINE_GRACE_MS = 8000;
136
136
  const RESTART_DELAYS_MS = [5000, 30_000, 120_000];
137
137
  const QUEUE_LOGS = 40;
@@ -271,6 +271,7 @@ export function createMascot({
271
271
  let lastPin = null;
272
272
  // Tệp thả vào bot đang chờ: cửa sổ dựng lại vẫn ôm thùng có số tệp.
273
273
  let lastFiles = null;
274
+ let lastRemoteView = null;
274
275
  // Đang nói chuyện bằng giọng (cửa sổ báo voice_start … voice_stop / daemon gửi voice_end): đổi ngôn ngữ chờ tới khi xong mới dựng lại.
275
276
  let voiceOn = false;
276
277
  let langRebuild = false;
@@ -283,6 +284,7 @@ export function createMascot({
283
284
  if (msg.t === AskCommand.CHOICES) lastChoices = msg;
284
285
  if (msg.t === AskCommand.PIN) lastPin = msg;
285
286
  if (msg.t === AskCommand.FILES) lastFiles = msg;
287
+ if (msg.t === HostCommand.REMOTE_VIEW) lastRemoteView = msg;
286
288
  if (msg.t === VoiceCommand.END) { voiceOn = false; if (langRebuild) timers.setTimeout(rebuildForLang, 0); }
287
289
  if (ready) return write(msg);
288
290
  if (msg.t === HostCommand.LOG) {
@@ -324,6 +326,7 @@ export function createMascot({
324
326
  write(lastPin);
325
327
  }
326
328
  if (lastFiles?.files?.length) write(lastFiles);
329
+ if (lastRemoteView?.on) write(lastRemoteView);
327
330
  if (commandOnReady) { write({ t: commandOnReady }); commandOnReady = null; }
328
331
  };
329
332
 
@@ -512,7 +515,7 @@ export function createMascot({
512
515
  timers.clearTimeout(restartTimer);
513
516
  timers.clearTimeout(thinkTimer);
514
517
  timers.clearTimeout(resultTimer);
515
- timers.clearTimeout(mainTimer);
518
+ timers.clearTimeout(mainTimer);
516
519
  timers.clearTimeout(offlineTimer);
517
520
  quitHost();
518
521
  }
@@ -522,8 +525,8 @@ export function createMascot({
522
525
  const waiting = new Set();
523
526
  let guiActive = 0;
524
527
  let paused = false;
525
- let offline = false;
526
- let offlineTimer = null;
528
+ let offline = false;
529
+ let offlineTimer = null;
527
530
  let everConnected = false;
528
531
  let phase = MascotState.IDLE;
529
532
  let batchOk = 0;
@@ -613,11 +616,11 @@ export function createMascot({
613
616
  /** Lệnh của ô hỏi (ask.mjs: chat / chat_busy / ask_status) → cửa sổ. */
614
617
  chat(cmd) { send(cmd); },
615
618
  connected() {
616
- const hadBlip = offlineTimer !== null && !offline && everConnected;
617
- timers.clearTimeout(offlineTimer);
618
- offlineTimer = null;
619
- everConnected = true;
620
- if (hadBlip) return;
619
+ const hadBlip = offlineTimer !== null && !offline && everConnected;
620
+ timers.clearTimeout(offlineTimer);
621
+ offlineTimer = null;
622
+ everConnected = true;
623
+ if (hadBlip) return;
621
624
  offline = false;
622
625
  syncState();
623
626
  log({ status: LogStatus.INFO, title: t(MascotText.CONNECTED) });
@@ -625,17 +628,17 @@ export function createMascot({
625
628
  send({ t: HostCommand.MAIN, text: t(MascotText.READY), quiet: true });
626
629
  },
627
630
  disconnected() {
628
- if (offline || offlineTimer) return;
629
- const showOffline = () => {
630
- offlineTimer = null;
631
- if (offline || closed) return;
632
- offline = true;
633
- syncState();
634
- log({ status: LogStatus.WARN, title: t(MascotText.DISCONNECTED) });
635
- main(t(MascotText.DISCONNECTED));
636
- };
637
- if (offlineGraceMs <= 0) return showOffline();
638
- offlineTimer = timers.setTimeout(showOffline, offlineGraceMs);
631
+ if (offline || offlineTimer) return;
632
+ const showOffline = () => {
633
+ offlineTimer = null;
634
+ if (offline || closed) return;
635
+ offline = true;
636
+ syncState();
637
+ log({ status: LogStatus.WARN, title: t(MascotText.DISCONNECTED) });
638
+ main(t(MascotText.DISCONNECTED));
639
+ };
640
+ if (offlineGraceMs <= 0) return showOffline();
641
+ offlineTimer = timers.setTimeout(showOffline, offlineGraceMs);
639
642
  },
640
643
  paused(on) {
641
644
  if (paused === on) return;
@@ -645,22 +648,23 @@ export function createMascot({
645
648
  log({ status: on ? LogStatus.WARN : LogStatus.INFO, title: text });
646
649
  main(text);
647
650
  },
648
- /** Có người đang xem + điều khiển màn hình máy này từ web (Desktop Scenecast) — chủ máy luôn biết. */
649
- remoteView(on, { device } = {}) {
650
- if (on) {
651
- const devName = formatDeviceLabel(device, currentLang);
652
- const text = devName
653
- ? t(MascotText.CAST_VIEWING_DEVICE, { device: devName })
654
- : t(MascotText.CAST_VIEWING);
655
- log({ status: LogStatus.WARN, title: text });
656
- main(text);
657
- send({ t: HostCommand.GESTURE, g: 'startle', face: 'curious', sec: 4.5 });
658
- } else {
659
- const text = t(MascotText.CAST_ENDED);
660
- log({ status: LogStatus.INFO, title: text });
661
- main(text);
662
- send({ t: HostCommand.GESTURE, g: 'relief', face: 'relief', sec: 2.5 });
663
- }
651
+ /** Có người đang xem + điều khiển màn hình máy này từ web (Desktop Scenecast) — chủ máy luôn biết. */
652
+ remoteView(on, { device } = {}) {
653
+ send({ t: HostCommand.REMOTE_VIEW, on: !!on });
654
+ if (on) {
655
+ const devName = formatDeviceLabel(device, currentLang);
656
+ const text = devName
657
+ ? t(MascotText.CAST_VIEWING_DEVICE, { device: devName })
658
+ : t(MascotText.CAST_VIEWING);
659
+ log({ status: LogStatus.WARN, title: text });
660
+ main(text);
661
+ send({ t: HostCommand.GESTURE, g: 'startle', face: 'curious', sec: 4.5 });
662
+ } else {
663
+ const text = t(MascotText.CAST_ENDED);
664
+ log({ status: LogStatus.INFO, title: text });
665
+ main(text);
666
+ send({ t: HostCommand.GESTURE, g: 'relief', face: 'relief', sec: 2.5 });
667
+ }
664
668
  },
665
669
  callStarted(call, tool) {
666
670
  if (!call?.call_id || tool?.internal) return;
@@ -41,6 +41,8 @@ const SCREENS = BOT_RIG.screens;
41
41
  const SP = BOT_RIG.sparks;
42
42
  const TR = BOT_RIG.tray;
43
43
 
44
+ const WAVE = BOT_RIG.wave;
45
+
44
46
  export const RIG_CS = String.raw`
45
47
  public sealed class Motion {
46
48
  public readonly double Bob, BobHz, Breathe, Lean, HeadTilt, HeadY, Antenna, Glow, GlowPulse, GlowHz, Tint, TintPulse, TintHz, Scan, Scale, Opacity, LookX, LookY;
@@ -150,6 +152,10 @@ ${Object.entries(BOT_MOTION).map(motionCase).join('\n')}
150
152
  readonly Dictionary<string, System.Windows.UIElement> mouthEls = new Dictionary<string, System.Windows.UIElement>();
151
153
  readonly ScaleTransform eyeMorphL, eyeMorphR, mouthMorph;
152
154
  string eyesNow, eyesNext, mouthNow, mouthNext; double mouthAt;
155
+ readonly System.Windows.Shapes.Polyline waveL, waveR;
156
+ bool waveOn;
157
+ const double WAVE_HALF = ${n(WAVE.halfWidth)}, WAVE_AMP = ${n(WAVE.amp)}, WAVE_LEN = ${n(WAVE.length)}, WAVE_HZ = ${n(WAVE.hz)}, WAVE_EYE_DX = ${n(BOT_RIG.face.eyeDx)};
158
+ const int WAVE_SEGMENTS = ${WAVE.segments};
153
159
  readonly Spring eyeSq = new Spring(1), mouthSq = new Spring(1);
154
160
  const double MOUTH_LAG = 0.05;
155
161
  // Antenna light color: eases from the old state's color to the new one.
@@ -208,6 +214,7 @@ ${SCREENS.map((sc, i) => ` screens.Add(MakeScreen(${i}, ${n(sc.tilt)}, ${n(
208
214
  faceBase = faceScale.ScaleX;
209
215
  foreach (var name in new[] { ${BOT_EYES.map((e) => `"${e}"`).join(', ')} }) eyeEls[name] = new[] { Get<System.Windows.UIElement>("Eyes_" + name + "_L"), Get<System.Windows.UIElement>("Eyes_" + name + "_R") };
210
216
  foreach (var name in new[] { ${BOT_MOUTHS.map((e) => `"${e}"`).join(', ')} }) mouthEls[name] = Get<System.Windows.UIElement>("Mouth_" + name);
217
+ waveL = Get<System.Windows.Shapes.Polyline>("WaveL"); waveR = Get<System.Windows.Shapes.Polyline>("WaveR");
211
218
  eyeMorphL = Get<ScaleTransform>("EyeMorphL"); eyeMorphR = Get<ScaleTransform>("EyeMorphR"); mouthMorph = Get<ScaleTransform>("MouthMorph");
212
219
  tint.Fill = tintBrush; halo.Fill = tintBrush;
213
220
  tray = Get<System.Windows.UIElement>("Tray"); trayArrow = Get<System.Windows.UIElement>("TrayArrow"); trayBase = Get<System.Windows.UIElement>("TrayBase"); trayNo = Get<System.Windows.UIElement>("TrayNo");
@@ -243,12 +250,30 @@ ${SCREENS.map((sc, i) => ` screens.Add(MakeScreen(${i}, ${n(sc.tilt)}, ${n(
243
250
  public void SetFace(string eyes, string mouth) {
244
251
  if (!eyeEls.ContainsKey(eyes) || !mouthEls.ContainsKey(mouth)) return;
245
252
  if (eyesNow == null) { eyesNow = eyes; ShowEyes(eyes); }
253
+ else if (waveOn) { eyesNow = eyes; eyesNext = null; } // Remote viewer: the eyes stay a wave; only remember the face to restore when the session ends.
246
254
  else if (eyesNext != null || eyes != eyesNow) eyesNext = eyes;
247
255
  if (mouthNow == null) { mouthNow = mouth; ShowMouth(mouth); }
248
256
  else if (mouthNext != null || mouth != mouthNow) { if (mouthNext == null) mouthAt = Now + MOUTH_LAG; mouthNext = mouth; }
249
257
  }
250
258
  void ShowEyes(string name) {
251
- foreach (var kv in eyeEls) { var v = kv.Key == name ? Visibility.Visible : Visibility.Collapsed; foreach (var e in kv.Value) e.Visibility = v; }
259
+ string shown = waveOn ? "wave" : name;
260
+ foreach (var kv in eyeEls) { var v = kv.Key == shown ? Visibility.Visible : Visibility.Collapsed; foreach (var e in kv.Value) e.Visibility = v; }
261
+ }
262
+ /** Someone is viewing / controlling this computer: both eyes become one continuously moving sine wave, over any face, until the session ends. */
263
+ public void RemoteWave(bool on) {
264
+ if (on == waveOn) return;
265
+ if (on && dozing) Doze(false);
266
+ waveOn = on;
267
+ ShowEyes(eyesNow);
268
+ }
269
+ /** Phase follows the real position, so it reads as one wave running through both eyes. */
270
+ PointCollection WavePoints(double t, double eyeCenter) {
271
+ var points = new PointCollection(WAVE_SEGMENTS + 1);
272
+ for (int i = 0; i <= WAVE_SEGMENTS; i++) {
273
+ double x = -WAVE_HALF + 2 * WAVE_HALF * i / WAVE_SEGMENTS;
274
+ points.Add(new Point(x, WAVE_AMP * Math.Sin(2 * Math.PI * ((x + eyeCenter) / WAVE_LEN - WAVE_HZ * t))));
275
+ }
276
+ return points;
252
277
  }
253
278
  void ShowMouth(string name) {
254
279
  foreach (var kv in mouthEls) kv.Value.Visibility = kv.Key == name ? Visibility.Visible : Visibility.Collapsed;
@@ -272,7 +297,7 @@ ${SCREENS.map((sc, i) => ` screens.Add(MakeScreen(${i}, ${n(sc.tilt)}, ${n(
272
297
 
273
298
  /** Doze off (the window calls this after a long idle) or wake up: wake = perk up, antenna flick, a blink. */
274
299
  public void Doze(bool on) {
275
- if (on == dozing) return;
300
+ if (on == dozing || (on && waveOn)) return;
276
301
  dozing = on; m = Motion.For(on ? "doze" : state);
277
302
  if (on) nextJerk = Now + 6 + rnd.NextDouble() * 5;
278
303
  else { perkAt = Now; antA.V += 150; blinkAt = Now; }
@@ -580,6 +605,7 @@ ${SCREENS.map((sc, i) => ` screens.Add(MakeScreen(${i}, ${n(sc.tilt)}, ${n(
580
605
  double blink = 1;
581
606
  if (bu >= 0 && bu < 0.17) blink = bu < 0.06 ? 1 - 0.9 * (bu / 0.06) : (bu < 0.08 ? 0.1 : 0.1 + 0.9 * Math.Sin((bu - 0.08) / 0.09 * Math.PI / 2));
582
607
  foreach (var b in blinks) b.ScaleY = blink;
608
+ if (waveOn) { waveL.Points = WavePoints(t, -WAVE_EYE_DX); waveR.Points = WavePoints(t, WAVE_EYE_DX); }
583
609
  if (dz > 0) foreach (var r in spins) r.Angle = (dizU * 540) % 360;
584
610
 
585
611
  // 10) Face morph: eyes squash shut fast (~80 ms, no overshoot), swap kind while shut, spring open with a small overshoot (and a
@@ -1,6 +1,6 @@
1
1
  import chalk from 'chalk';
2
2
  import readline from 'readline/promises';
3
- import { CONFIRM_RANK, ConfirmMode, DEFAULT_LOCAL_POLICY, REMOTE_POLICY_FILE, saveLocalPolicy, stricterPolicy, verifyLocalPolicy } from './localPolicy.mjs';
3
+ import { CAST_CONSENT_RANK, CONFIRM_RANK, CastConsentMode, ConfirmMode, DEFAULT_LOCAL_POLICY, REMOTE_POLICY_FILE, saveLocalPolicy, stricterPolicy, verifyLocalPolicy } from './localPolicy.mjs';
4
4
 
5
5
  /**
6
6
  * `aivin remote policy [hành động] [giá trị]` — chủ máy đặt sàn luật tại máy (localPolicy.mjs). Siết luật chạy ngay; NỚI luật (bớt xác
@@ -14,12 +14,19 @@ const CONFIRM_TEXT = {
14
14
  [ConfirmMode.NEVER]: 'không hỏi trên máy — chỉ theo luật phía Aivin',
15
15
  };
16
16
 
17
+ const CAST_TEXT = {
18
+ [CastConsentMode.ASK]: 'mỗi phiên xem / điều khiển màn hình phải bấm "Cho phép" trên máy',
19
+ [CastConsentMode.UNATTENDED]: 'xem / điều khiển màn hình KHÔNG cần người ở máy',
20
+ [CastConsentMode.OFF]: 'tắt hẳn xem / điều khiển màn hình',
21
+ };
22
+
17
23
  function show(policy) {
18
24
  console.log(chalk.blue('🛡️ Luật tại máy này') + chalk.gray(` (${REMOTE_POLICY_FILE})`));
19
25
  console.log(` Xác nhận trên máy: ${chalk.cyan(policy.confirm)} — ${CONFIRM_TEXT[policy.confirm]} (chờ tối đa ${policy.confirm_timeout_sec} s)`);
26
+ console.log(` Xem màn hình: ${chalk.cyan(policy.cast_consent)} — ${CAST_TEXT[policy.cast_consent]}`);
20
27
  console.log(` Công cụ tắt: ${policy.deny_tools.length ? policy.deny_tools.join(', ') : chalk.gray('không')}`);
21
28
  console.log(` Lệnh chặn thêm: ${policy.blocked_commands.length ? policy.blocked_commands.map((r) => `/${r}/`).join(' ') : chalk.gray('không')}`);
22
- console.log(chalk.gray(' Đổi: aivin remote policy confirm <never|risky|always> · deny|allow <công cụ> · block|unblock "<regex>" · timeout <giây>'));
29
+ console.log(chalk.gray(' Đổi: aivin remote policy confirm <never|risky|always> · deny|allow <công cụ> · block|unblock "<regex>" · timeout <giây> · cast <ask|unattended|off>'));
23
30
  }
24
31
 
25
32
  /** Nới luật: chỉ người gõ trong terminal thật, và phải trả lời "có". */
@@ -84,8 +91,14 @@ export async function runPolicyCommand(action, value) {
84
91
  next.confirm_timeout_sec = Math.round(sec);
85
92
  break;
86
93
  }
94
+ case 'cast': {
95
+ if (!Object.hasOwn(CAST_CONSENT_RANK, v)) throw new Error('Dùng: aivin remote policy cast <ask|unattended|off>');
96
+ if (CAST_CONSENT_RANK[v] < CAST_CONSENT_RANK[policy.cast_consent]) await assertHumanLoosening(`Đổi xem màn hình từ "${policy.cast_consent}" sang "${v}": ${CAST_TEXT[v]}`);
97
+ next.cast_consent = v;
98
+ break;
99
+ }
87
100
  default:
88
- throw new Error(`Không hiểu "${action}". Dùng: confirm | deny | allow | block | unblock | timeout`);
101
+ throw new Error(`Không hiểu "${action}". Dùng: confirm | deny | allow | block | unblock | timeout | cast`);
89
102
  }
90
103
  const saved = saveLocalPolicy(next);
91
104
  console.log(chalk.green('✅ Đã lưu — có hiệu lực ngay (công cụ tắt / bật lại vào danh mục ở lần khởi động daemon kế tiếp).'));
@@ -182,8 +182,8 @@ export function agentEnv(env = process.env) {
182
182
  return { PYTHONIOENCODING: 'utf-8', PYTHONUTF8: '1', ...scrubEnv(env), [AGENT_CALL_ENV]: '1' };
183
183
  }
184
184
 
185
- const HUMAN_ONLY_REMOTE_COMMANDS = new Set(['start', 'pair', 'unpair', 'pause', 'resume', 'enable', 'disable', 'reset-id', 'do', 'forget-folder']);
186
- const HUMAN_ONLY_COMMANDS = new Set(['do', 'login', 'logout', 'uninstall']);
185
+ const HUMAN_ONLY_REMOTE_COMMANDS = new Set(['start', 'pair', 'unpair', 'pause', 'resume', 'enable', 'disable', 'reset-id', 'do', 'forget-folder', 'policy', 'disconnect']);
186
+ const HUMAN_ONLY_COMMANDS = new Set(['do', 'login', 'logout', 'uninstall', 'server', 'update']);
187
187
 
188
188
  /** Lệnh chỉ người ngồi trước máy được chạy. `parent` / `name`: lệnh cha + lệnh con của CLI. */
189
189
  export function assertHumanCommand(parent, name, env = process.env) {
@@ -212,7 +212,9 @@ const CATASTROPHIC_COMMANDS = [
212
212
  const AIVIN_DIR_SEGMENT = /(?:^|[\\/\s'"`~=:(;,|&])\.aivin(?:-release)?(?=[\\/\s'"`);,|&]|$)/i;
213
213
 
214
214
  /** Agent gọi chính CLI Aivin để đổi việc ghép máy / luật / giao việc mới. Khớp chuỗi — `assertHumanCommand` là chốt thứ hai trong tiến trình CLI. */
215
- const AIVIN_SELF_COMMAND = /\baivin(\.exe)?["']?\s+(remote\s+(pair|start|unpair|pause|resume|enable|disable|reset-id|do|forget-folder)\b|do\b|login\b|logout\b|uninstall\b|desktop\s+uninstall\b)/i;
215
+ const AIVIN_SELF_COMMAND = /\baivin(\.exe)?["']?\s+(remote\s+(pair|start|unpair|pause|resume|enable|disable|reset-id|do|forget-folder|policy|disconnect)\b|do\b|login\b|logout\b|uninstall\b|desktop\s+uninstall\b)/i;
216
+ /** `server` / `update` là từ thường hay xuất hiện sau chữ "aivin" trong nội dung lệnh: chỉ khớp khi đứng ở vị trí chạy lệnh. */
217
+ const AIVIN_SERVER_OR_UPDATE = /(?:^|[;&|\n]\s*)(?:[\w.:~\\/-]*[\\/])?aivin(\.exe)?["']?\s+(server|update)\b/i;
216
218
 
217
219
  function mentionsProtectedDir(command) {
218
220
  if (AIVIN_DIR_SEGMENT.test(command)) return true;
@@ -228,7 +230,7 @@ export function assertCommandAllowed(command) {
228
230
  if (CATASTROPHIC_COMMANDS.some((re) => re.test(command))) {
229
231
  throw new DeviceToolError(DeviceErrorCode.BLOCKED_COMMAND, 'Command blocked by the device safety floor (destroys the whole system)');
230
232
  }
231
- if (AIVIN_SELF_COMMAND.test(command)) {
233
+ if (AIVIN_SELF_COMMAND.test(command) || AIVIN_SERVER_OR_UPDATE.test(command)) {
232
234
  throw new DeviceToolError(DeviceErrorCode.BLOCKED_COMMAND, 'Command changes this computer\'s Aivin pairing or starts new Aivin work — only the person at the computer can do that');
233
235
  }
234
236
  if (mentionsProtectedDir(command)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aivin-labs/cli",
3
- "version": "1.0.43",
3
+ "version": "1.0.47",
4
4
  "description": "aivin CLI - scaffold, run, and deploy Aivin plugins built on @aivin-labs/sdk",
5
5
  "type": "module",
6
6
  "bin": {