@aivin-labs/cli 1.0.50 → 1.0.57

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.
@@ -80,6 +80,12 @@ public static class AivinHumanGuard {
80
80
  keyHook = SetWindowsHookEx(13, keyProc, mod, 0);
81
81
  return mouseHook != IntPtr.Zero && keyHook != IntPtr.Zero;
82
82
  }
83
+ /** Gỡ ngay khi hộp đóng: hook mức thấp làm mọi lần di chuột / gõ phím của cả máy chờ luồng này, tiến trình chưa thoát mà luồng thôi bơm thông điệp là chuột khựng (12/11/2026). */
84
+ public static void Uninstall() {
85
+ if (mouseHook != IntPtr.Zero) { UnhookWindowsHookEx(mouseHook); mouseHook = IntPtr.Zero; }
86
+ if (keyHook != IntPtr.Zero) { UnhookWindowsHookEx(keyHook); keyHook = IntPtr.Zero; }
87
+ window = IntPtr.Zero;
88
+ }
83
89
  public static bool Recent(int ms) { return lastTrusted >= 0 && clock.ElapsedMilliseconds - lastTrusted <= ms; }
84
90
  }
85
91
  `;
@@ -113,5 +119,6 @@ export const HUMAN_GUARD_PS = [
113
119
  "try { Add-Type -TypeDefinition (D 'AIVIN_GUARD_CS') -ErrorAction Stop; $script:guard = $true } catch { }",
114
120
  'function Install-Guard($win) { if (-not $script:guard) { return }; try { $h = (New-Object System.Windows.Interop.WindowInteropHelper($win)).Handle; $tg = [long]0; [void][long]::TryParse([string]$env:AIVIN_GUARD_TAG, [ref]$tg); if (-not [AivinHumanGuard]::Install($h, $tg)) { $script:guard = $false } } catch { $script:guard = $false } }',
115
121
  `function Test-Human { if (-not $script:guard) { return $true }; return [AivinHumanGuard]::Recent(${HUMAN_RECENT_MS}) }`,
122
+ 'function Remove-Guard { try { [AivinHumanGuard]::Uninstall() } catch { } }',
116
123
  "$script:hintLeft = 0; $script:hint = D 'AIVIN_GUARD_HINT'",
117
124
  ];
@@ -140,14 +140,14 @@ const WINDOWS_SCRIPT = [
140
140
  "$script:result = 'No'; $script:closing = $false; $card = $w.FindName('Card')",
141
141
  '$tm = New-Object Windows.Threading.DispatcherTimer; $tm.Interval = [TimeSpan]::FromSeconds(1)',
142
142
  // Đóng có hiệu ứng: chạy storyboard "Out" rồi mới đóng cửa sổ; bấm liên tiếp chỉ tính lần đầu.
143
- "function Finish($r) { if ($script:closing) { return }; $script:closing = $true; $script:result = $r; $tm.Stop(); $sb = $w.FindResource('Out').Clone(); $sb.Add_Completed({ $w.Close() }); $sb.Begin($card) }",
143
+ "function Finish($r) { if ($script:closing) { return }; $script:closing = $true; $script:result = $r; $tm.Stop(); Remove-Guard; $sb = $w.FindResource('Out').Clone(); $sb.Add_Completed({ $w.Close() }); $sb.Begin($card) }",
144
144
  "$w.FindName('Allow').Add_Click({ if (Test-Human) { Finish 'Yes' } else { $script:hintLeft = 3; $cd.Text = $script:hint } })",
145
145
  "$w.FindName('Reject').Add_Click({ Finish 'No' }); $w.FindName('Close').Add_Click({ Finish 'No' })",
146
146
  "$w.FindName('Head').Add_MouseLeftButtonDown({ $w.DragMove() })",
147
147
  "$script:left = [int]$env:AIVIN_C_SECONDS; $fmt = D 'AIVIN_C_COUNTDOWN'; $cd = $w.FindName('Countdown'); $cd.Text = $fmt -f $script:left",
148
148
  "$tm.Add_Tick({ $script:left--; if ($script:hintLeft -gt 0) { $script:hintLeft--; $cd.Text = $script:hint } else { $cd.Text = $fmt -f $script:left }; if ($script:left -le 0) { Finish 'Timeout' } })",
149
149
  "$w.Add_ContentRendered({ Install-Guard $w; $w.FindResource('In').Begin($card); $w.Activate(); [void]$w.FindName('Reject').Focus(); $tm.Start() })",
150
- '[void]$w.ShowDialog(); $tm.Stop(); $script:result',
150
+ '[void]$w.ShowDialog(); Remove-Guard; $tm.Stop(); $script:result',
151
151
  ].join('\n');
152
152
 
153
153
  /** Nội dung chữ thường (macOS / Linux / terminal): lý do, mục đích agent ghi, lệnh. */