@aivin-labs/cli 1.0.4 → 1.0.8
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.
- package/README.md +263 -216
- package/bin/cli.mjs +1780 -1361
- package/bin/lib/browserAutomation.mjs +655 -648
- package/bin/lib/browserTui.mjs +276 -245
- package/bin/lib/cancellation.mjs +61 -0
- package/bin/lib/codegen.mjs +61 -5
- package/bin/lib/connectors.mjs +55 -21
- package/bin/lib/deploy.mjs +25 -2
- package/bin/lib/mcpProxy.mjs +869 -773
- package/bin/lib/mission.mjs +13 -1
- package/bin/lib/missionStream.mjs +696 -660
- package/bin/lib/pluginAuthResolve.mjs +127 -0
- package/bin/lib/pluginTrigger.mjs +207 -90
- package/bin/lib/releaseKeys.mjs +9 -0
- package/bin/lib/remote/activityLog.mjs +68 -0
- package/bin/lib/remote/autoStart.mjs +457 -0
- package/bin/lib/remote/autoUpdate.mjs +129 -0
- package/bin/lib/remote/brand.mjs +60 -0
- package/bin/lib/remote/browserTunnel.mjs +292 -0
- package/bin/lib/remote/callLedger.mjs +134 -0
- package/bin/lib/remote/cdpPolicy.mjs +66 -0
- package/bin/lib/remote/client.mjs +726 -0
- package/bin/lib/remote/constants.mjs +173 -0
- package/bin/lib/remote/credentials.mjs +208 -0
- package/bin/lib/remote/daemonLock.mjs +86 -0
- package/bin/lib/remote/dailyBrowser.mjs +371 -0
- package/bin/lib/remote/deviceMemory.mjs +246 -0
- package/bin/lib/remote/deviceProfile.mjs +142 -0
- package/bin/lib/remote/deviceWatches.mjs +138 -0
- package/bin/lib/remote/docText.mjs +117 -0
- package/bin/lib/remote/fileIndexer.mjs +399 -0
- package/bin/lib/remote/gui/index.mjs +245 -0
- package/bin/lib/remote/gui/officeHostSource.mjs +393 -0
- package/bin/lib/remote/gui/windowsHost.mjs +109 -0
- package/bin/lib/remote/gui/windowsHostSource.mjs +904 -0
- package/bin/lib/remote/httpTransfer.mjs +89 -0
- package/bin/lib/remote/idempotency.mjs +135 -0
- package/bin/lib/remote/keepAwake.mjs +100 -0
- package/bin/lib/remote/localConfirm.mjs +268 -0
- package/bin/lib/remote/localPolicy.mjs +249 -0
- package/bin/lib/remote/mascot/assets.mjs +218 -0
- package/bin/lib/remote/mascot/hostSource.mjs +362 -0
- package/bin/lib/remote/mascot/index.mjs +322 -0
- package/bin/lib/remote/mascot/labels.mjs +83 -0
- package/bin/lib/remote/mascot/strings.mjs +189 -0
- package/bin/lib/remote/memberFsPool.mjs +134 -0
- package/bin/lib/remote/memberFsWorker.mjs +60 -0
- package/bin/lib/remote/mission.mjs +156 -0
- package/bin/lib/remote/missionQuestion.mjs +63 -0
- package/bin/lib/remote/multiUser.mjs +344 -0
- package/bin/lib/remote/netProxy.mjs +145 -0
- package/bin/lib/remote/notify.mjs +58 -0
- package/bin/lib/remote/office/index.mjs +90 -0
- package/bin/lib/remote/policyCommand.mjs +93 -0
- package/bin/lib/remote/processes.mjs +217 -0
- package/bin/lib/remote/sandbox.mjs +221 -0
- package/bin/lib/remote/schedule.mjs +213 -0
- package/bin/lib/remote/scheduler.mjs +124 -0
- package/bin/lib/remote/textIndex.mjs +131 -0
- package/bin/lib/remote/tokenStore.mjs +77 -0
- package/bin/lib/remote/toolHandlers.mjs +726 -0
- package/bin/lib/remote/undoStore.mjs +242 -0
- package/bin/lib/remoteControl.mjs +26 -0
- package/bin/lib/scaffold.mjs +654 -653
- package/bin/lib/selfUpdate.mjs +71 -0
- package/bin/lib/store.mjs +16 -2
- package/bin/lib/tasks.mjs +52 -8
- package/bin/lib/update/binarySwap.mjs +63 -0
- package/bin/lib/update/constants.mjs +56 -0
- package/bin/lib/update/download.mjs +145 -0
- package/bin/lib/update/signature.mjs +42 -0
- package/bin/lib/update/state.mjs +205 -0
- package/bin/lib/update/versions.mjs +60 -0
- package/bin/lib/util.mjs +8 -0
- package/docs/CLI.md +1353 -1274
- package/package.json +71 -62
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { AIVIN_BRAND } from '../brand.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cửa sổ linh vật (Windows, WPF qua PowerShell) — sống suốt phiên `aivin remote start`, nhận lệnh từng dòng JSON trên stdin, gửi sự kiện
|
|
5
|
+
* người dùng ra stdout. Nhận diện theo hộp xác nhận tại máy (localConfirm.mjs): logo, màu phẳng của logo, bo góc, chuyển động ngắn.
|
|
6
|
+
*
|
|
7
|
+
* - Không viền, nền trong suốt (vùng trong suốt bấm xuyên qua), luôn nằm trên, không có trên thanh tác vụ / Alt+Tab.
|
|
8
|
+
* - KHÔNG cướp focus (WS_EX_NOACTIVATE): người dùng đang gõ, hoặc AI đang điều khiển một ứng dụng, không bị cửa sổ này giật phím.
|
|
9
|
+
* - Không có trong ảnh chụp màn hình (WDA_EXCLUDEFROMCAPTURE, Windows 10 2004+): ảnh AI chụp để điều khiển giao diện, chia sẻ màn hình
|
|
10
|
+
* khi họp không thấy linh vật. Thử nghiệm cần chụp được thì đặt AIVIN_MASCOT_CAPTURABLE=1.
|
|
11
|
+
* - Kéo để di chuyển (nhớ chỗ), bấm để mở / thu bảng nhật ký; bảng mở về phía còn chỗ trên màn hình, kẹp trong vùng màn hình.
|
|
12
|
+
* Lệnh vào: state | main | log | gui | show | quit. Sự kiện ra: ready | pos | pause | resume | hide | off.
|
|
13
|
+
* Tệp .ps1 giữ toàn ASCII (PowerShell 5 đọc .ps1 không BOM theo bảng mã cũ) — mọi chữ hiện ra nằm trong config.json (UTF-8).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const B = AIVIN_BRAND;
|
|
17
|
+
|
|
18
|
+
/** Màu từng trạng thái: `fg` chấm / chữ, `bg` nền chip. */
|
|
19
|
+
export const MASCOT_PALETTE = Object.freeze({
|
|
20
|
+
idle: { fg: '#00B42A', bg: '#E8FFEA' },
|
|
21
|
+
working: { fg: B.brand, bg: '#E8F3FF' },
|
|
22
|
+
thinking: { fg: B.light, bg: '#E6F9FF' },
|
|
23
|
+
waiting: { fg: B.warn, bg: B.warnBg },
|
|
24
|
+
paused: { fg: B.muted, bg: '#F2F3F5' },
|
|
25
|
+
offline: { fg: B.muted, bg: '#F2F3F5' },
|
|
26
|
+
done: { fg: '#00B42A', bg: '#E8FFEA' },
|
|
27
|
+
error: { fg: '#F53F3F', bg: '#FFECE8' },
|
|
28
|
+
ink: B.ink,
|
|
29
|
+
muted: B.muted,
|
|
30
|
+
log: { run: B.brand, ok: '#00B42A', fail: '#F53F3F', info: B.muted, warn: B.warn },
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const MASCOT_GLYPHS = Object.freeze({ run: '●', ok: '✓', fail: '✕', info: '•', warn: '!' });
|
|
34
|
+
|
|
35
|
+
const ease = (mode = 'EaseOut') => `<DoubleAnimation.EasingFunction><CubicEase EasingMode="${mode}"/></DoubleAnimation.EasingFunction>`;
|
|
36
|
+
|
|
37
|
+
/** Hiện / ẩn có chuyển động: mờ → rõ + phóng nhẹ (gốc phóng đặt ở phần tử). */
|
|
38
|
+
const motion = (key, opacity, scale, ms, mode) => `<Storyboard x:Key="${key}">
|
|
39
|
+
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="${opacity}" Duration="0:0:0.${ms}"/>
|
|
40
|
+
${['ScaleX', 'ScaleY'].map((axis) => `<DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.${axis})" To="${scale}" Duration="0:0:0.${ms}">${ease(mode)}</DoubleAnimation>`).join('\n ')}
|
|
41
|
+
</Storyboard>`;
|
|
42
|
+
|
|
43
|
+
/** Nút bo góc: lớp phủ màu `Tag` hiện dần khi rê chuột, nhấn thì thu nhẹ (như hộp xác nhận). */
|
|
44
|
+
const buttonStyle = (key, radius) => `<Style x:Key="${key}" TargetType="Button">
|
|
45
|
+
<Setter Property="FontSize" Value="13"/><Setter Property="FontWeight" Value="SemiBold"/><Setter Property="Cursor" Value="Hand"/>
|
|
46
|
+
<Setter Property="FocusVisualStyle" Value="{x:Null}"/><Setter Property="Focusable" Value="False"/>
|
|
47
|
+
<Setter Property="Template"><Setter.Value><ControlTemplate TargetType="Button">
|
|
48
|
+
<Grid x:Name="root" RenderTransformOrigin="0.5,0.5" Background="Transparent">
|
|
49
|
+
<Grid.RenderTransform><ScaleTransform ScaleX="1" ScaleY="1"/></Grid.RenderTransform>
|
|
50
|
+
<Border CornerRadius="${radius}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"/>
|
|
51
|
+
<Border x:Name="h" CornerRadius="${radius}" Background="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}" Opacity="0"/>
|
|
52
|
+
<ContentPresenter Margin="{TemplateBinding Padding}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
|
53
|
+
</Grid>
|
|
54
|
+
<ControlTemplate.Triggers>
|
|
55
|
+
<Trigger Property="IsMouseOver" Value="True">
|
|
56
|
+
<Trigger.EnterActions><BeginStoryboard><Storyboard><DoubleAnimation Storyboard.TargetName="h" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.150"/></Storyboard></BeginStoryboard></Trigger.EnterActions>
|
|
57
|
+
<Trigger.ExitActions><BeginStoryboard><Storyboard><DoubleAnimation Storyboard.TargetName="h" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.200"/></Storyboard></BeginStoryboard></Trigger.ExitActions>
|
|
58
|
+
</Trigger>
|
|
59
|
+
<Trigger Property="IsPressed" Value="True">
|
|
60
|
+
<Trigger.EnterActions><BeginStoryboard><Storyboard>${['ScaleX', 'ScaleY'].map((a) => `<DoubleAnimation Storyboard.TargetName="root" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.${a})" To="0.97" Duration="0:0:0.090"/>`).join('')}</Storyboard></BeginStoryboard></Trigger.EnterActions>
|
|
61
|
+
<Trigger.ExitActions><BeginStoryboard><Storyboard>${['ScaleX', 'ScaleY'].map((a) => `<DoubleAnimation Storyboard.TargetName="root" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.${a})" To="1" Duration="0:0:0.090"/>`).join('')}</Storyboard></BeginStoryboard></Trigger.ExitActions>
|
|
62
|
+
</Trigger>
|
|
63
|
+
</ControlTemplate.Triggers>
|
|
64
|
+
</ControlTemplate></Setter.Value></Setter>
|
|
65
|
+
</Style>`;
|
|
66
|
+
|
|
67
|
+
const SHADOW = '<DropShadowEffect BlurRadius="24" ShadowDepth="6" Direction="270" Opacity="0.16" Color="#0B1B3F"/>';
|
|
68
|
+
|
|
69
|
+
/** Mắt vẽ trên thân 80×80 (biểu tượng 160×160 thu nửa): tròng trắng + con ngươi + đốm sáng, nằm trên dải phía trên của dải lụa. */
|
|
70
|
+
const EYES = [{ x: 38, y: 20 }, { x: 50.5, y: 18.5 }];
|
|
71
|
+
const eyeWhites = EYES.map(({ x, y }) => `<Ellipse Canvas.Left="${x - 3.75}" Canvas.Top="${y - 4.5}" Width="7.5" Height="9" Fill="White"/>`).join('\n ');
|
|
72
|
+
const pupils = EYES.map(({ x, y }) => `<Ellipse Canvas.Left="${x - 1.6}" Canvas.Top="${y - 1.8}" Width="4.4" Height="5.4" Fill="${B.ink}"/>
|
|
73
|
+
<Ellipse Canvas.Left="${x - 0.8}" Canvas.Top="${y - 0.9}" Width="1.7" Height="1.7" Fill="White"/>`).join('\n ');
|
|
74
|
+
|
|
75
|
+
export const MASCOT_XAML = `<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
76
|
+
SizeToContent="WidthAndHeight" WindowStyle="None" AllowsTransparency="True" Background="Transparent" ResizeMode="NoResize"
|
|
77
|
+
Topmost="True" ShowInTaskbar="False" ShowActivated="False" FontFamily="Segoe UI" UseLayoutRounding="True" Opacity="0">
|
|
78
|
+
<Window.Resources>
|
|
79
|
+
${buttonStyle('Btn', 9)}
|
|
80
|
+
${buttonStyle('IconBtn', 8)}
|
|
81
|
+
${motion('PanelIn', 1, 1, 180, 'EaseOut')}
|
|
82
|
+
${motion('PanelOut', 0, 0.96, 120, 'EaseIn')}
|
|
83
|
+
${motion('BubbleIn', 1, 1, 160, 'EaseOut')}
|
|
84
|
+
${motion('BubbleOut', 0, 0.94, 140, 'EaseIn')}
|
|
85
|
+
<Storyboard x:Key="WindowIn"><DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.250"/></Storyboard>
|
|
86
|
+
<Storyboard x:Key="Pulse" RepeatBehavior="Forever" AutoReverse="True">
|
|
87
|
+
<DoubleAnimation Storyboard.TargetName="Dot" Storyboard.TargetProperty="Opacity" From="1" To="0.3" Duration="0:0:0.700"/>
|
|
88
|
+
</Storyboard>
|
|
89
|
+
<Storyboard x:Key="Look" RepeatBehavior="Forever">
|
|
90
|
+
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="LookX" Storyboard.TargetProperty="X">
|
|
91
|
+
<EasingDoubleKeyFrame KeyTime="0:0:0" Value="0"/><EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="-1.3"/>
|
|
92
|
+
<EasingDoubleKeyFrame KeyTime="0:0:1.6" Value="-1.3"/><EasingDoubleKeyFrame KeyTime="0:0:2.2" Value="1.3"/>
|
|
93
|
+
<EasingDoubleKeyFrame KeyTime="0:0:3.2" Value="1.3"/><EasingDoubleKeyFrame KeyTime="0:0:3.8" Value="0"/>
|
|
94
|
+
</DoubleAnimationUsingKeyFrames>
|
|
95
|
+
</Storyboard>
|
|
96
|
+
<Storyboard x:Key="Hop">
|
|
97
|
+
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="HopY" Storyboard.TargetProperty="Y">
|
|
98
|
+
<EasingDoubleKeyFrame KeyTime="0:0:0" Value="0"/><EasingDoubleKeyFrame KeyTime="0:0:0.16" Value="-9"><EasingDoubleKeyFrame.EasingFunction><CubicEase EasingMode="EaseOut"/></EasingDoubleKeyFrame.EasingFunction></EasingDoubleKeyFrame>
|
|
99
|
+
<EasingDoubleKeyFrame KeyTime="0:0:0.36" Value="0"><EasingDoubleKeyFrame.EasingFunction><BounceEase Bounces="1" Bounciness="3" EasingMode="EaseOut"/></EasingDoubleKeyFrame.EasingFunction></EasingDoubleKeyFrame>
|
|
100
|
+
</DoubleAnimationUsingKeyFrames>
|
|
101
|
+
</Storyboard>
|
|
102
|
+
</Window.Resources>
|
|
103
|
+
<StackPanel x:Name="Root" Margin="14">
|
|
104
|
+
<Border x:Name="Panel" Visibility="Collapsed" Width="372" Margin="0,0,0,10" CornerRadius="16" Background="White" BorderBrush="#E5E6EB"
|
|
105
|
+
BorderThickness="1" Opacity="0" RenderTransformOrigin="0.5,1">
|
|
106
|
+
<Border.RenderTransform><ScaleTransform ScaleX="0.96" ScaleY="0.96"/></Border.RenderTransform>
|
|
107
|
+
<Border.Effect>${SHADOW}</Border.Effect>
|
|
108
|
+
<DockPanel Margin="18,14,12,14">
|
|
109
|
+
<DockPanel DockPanel.Dock="Top" LastChildFill="False">
|
|
110
|
+
<Image x:Name="PanelLogo" Width="22" Height="22" RenderOptions.BitmapScalingMode="HighQuality" VerticalAlignment="Center"/>
|
|
111
|
+
<TextBlock x:Name="PanelTitle" FontSize="14" FontWeight="SemiBold" Foreground="${B.ink}" Margin="8,0,0,0" VerticalAlignment="Center"/>
|
|
112
|
+
<Border x:Name="Chip" CornerRadius="10" Padding="8,2,8,3" Margin="8,0,0,0" VerticalAlignment="Center">
|
|
113
|
+
<TextBlock x:Name="ChipText" FontSize="11.5" FontWeight="SemiBold"/>
|
|
114
|
+
</Border>
|
|
115
|
+
<Button x:Name="PanelClose" DockPanel.Dock="Right" Style="{StaticResource IconBtn}" Content="✕" Width="30" Height="30" FontSize="11"
|
|
116
|
+
FontWeight="Normal" Background="Transparent" BorderThickness="0" Tag="#F2F3F5" Foreground="${B.muted}"/>
|
|
117
|
+
</DockPanel>
|
|
118
|
+
<TextBlock x:Name="NowLabel" DockPanel.Dock="Top" Margin="0,14,0,4" FontSize="11" FontWeight="SemiBold" Foreground="${B.muted}"/>
|
|
119
|
+
<TextBlock x:Name="NowText" DockPanel.Dock="Top" FontSize="14" Foreground="${B.ink}" TextWrapping="Wrap" LineHeight="20" Margin="0,0,6,0"/>
|
|
120
|
+
<DockPanel DockPanel.Dock="Bottom" Margin="0,12,6,0" LastChildFill="False">
|
|
121
|
+
<Button x:Name="PauseBtn" Style="{StaticResource Btn}" Height="34" Padding="14,0" Background="White" Foreground="${B.ink}"
|
|
122
|
+
BorderBrush="#C9CDD4" BorderThickness="1" Tag="#0F000000"/>
|
|
123
|
+
<Button x:Name="OffBtn" DockPanel.Dock="Right" Style="{StaticResource Btn}" Height="34" Padding="10,0" Background="Transparent"
|
|
124
|
+
Foreground="${B.muted}" BorderThickness="0" Tag="#F2F3F5" FontWeight="Normal"/>
|
|
125
|
+
<Button x:Name="HideBtn" DockPanel.Dock="Right" Style="{StaticResource Btn}" Height="34" Padding="10,0" Background="Transparent"
|
|
126
|
+
Foreground="${B.body}" BorderThickness="0" Tag="#F2F3F5" FontWeight="Normal"/>
|
|
127
|
+
</DockPanel>
|
|
128
|
+
<TextBlock x:Name="LogLabel" DockPanel.Dock="Top" Margin="0,16,0,6" FontSize="11" FontWeight="SemiBold" Foreground="${B.muted}"/>
|
|
129
|
+
<Border CornerRadius="10" Background="#F7F8FA" BorderBrush="#EEF0F4" BorderThickness="1" Margin="0,0,6,0">
|
|
130
|
+
<Grid>
|
|
131
|
+
<TextBlock x:Name="Empty" Margin="12,14" FontSize="12.5" Foreground="${B.muted}" TextWrapping="Wrap"/>
|
|
132
|
+
<ScrollViewer Height="260" VerticalScrollBarVisibility="Auto"><StackPanel x:Name="LogList" Margin="0,4"/></ScrollViewer>
|
|
133
|
+
</Grid>
|
|
134
|
+
</Border>
|
|
135
|
+
</DockPanel>
|
|
136
|
+
</Border>
|
|
137
|
+
<Grid x:Name="Bubble" Visibility="Collapsed" Opacity="0" RenderTransformOrigin="0.5,1">
|
|
138
|
+
<Grid.RenderTransform><ScaleTransform ScaleX="0.94" ScaleY="0.94"/></Grid.RenderTransform>
|
|
139
|
+
<Border CornerRadius="14" Background="White" BorderBrush="#E5E6EB" BorderThickness="1" Padding="12,8,14,9" MaxWidth="250" Margin="0,0,0,7">
|
|
140
|
+
<Border.Effect>${SHADOW}</Border.Effect>
|
|
141
|
+
<DockPanel>
|
|
142
|
+
<Ellipse x:Name="BubbleDot" Width="7" Height="7" Margin="0,6,8,0" VerticalAlignment="Top"/>
|
|
143
|
+
<TextBlock x:Name="BubbleText" FontSize="13" Foreground="${B.ink}" TextWrapping="Wrap" MaxHeight="38" TextTrimming="CharacterEllipsis" LineHeight="19"/>
|
|
144
|
+
</DockPanel>
|
|
145
|
+
</Border>
|
|
146
|
+
<Path x:Name="Tail" Data="M0,0 L14,0 L7,8 Z" Fill="White" Stroke="#E5E6EB" StrokeThickness="1" VerticalAlignment="Bottom" Margin="0,0,0,0"/>
|
|
147
|
+
<Rectangle x:Name="TailCover" Width="12" Height="2" Fill="White" VerticalAlignment="Bottom" Margin="0,0,0,7"/>
|
|
148
|
+
</Grid>
|
|
149
|
+
<!-- Nền alpha 1/255: cửa sổ layered cho bấm xuyên qua điểm trong suốt hẳn — khe giữa dải lụa vẫn phải bấm / kéo được. -->
|
|
150
|
+
<Grid x:Name="Mascot" Width="84" Height="88" Cursor="Hand" Background="#01FFFFFF">
|
|
151
|
+
<Ellipse Width="44" Height="7" VerticalAlignment="Bottom" Margin="0,0,0,2" Fill="#140B1B3F"/>
|
|
152
|
+
<Canvas x:Name="Floater" Width="80" Height="80" VerticalAlignment="Top" HorizontalAlignment="Center">
|
|
153
|
+
<Canvas.RenderTransform><TransformGroup><TranslateTransform x:Name="FloatY"/><TranslateTransform x:Name="HopY"/></TransformGroup></Canvas.RenderTransform>
|
|
154
|
+
<Canvas.Triggers>
|
|
155
|
+
<EventTrigger RoutedEvent="FrameworkElement.Loaded"><BeginStoryboard><Storyboard RepeatBehavior="Forever" AutoReverse="True">
|
|
156
|
+
<DoubleAnimation Storyboard.TargetName="FloatY" Storyboard.TargetProperty="Y" From="-3" To="3" Duration="0:0:1.800"><DoubleAnimation.EasingFunction><SineEase EasingMode="EaseInOut"/></DoubleAnimation.EasingFunction></DoubleAnimation>
|
|
157
|
+
</Storyboard></BeginStoryboard></EventTrigger>
|
|
158
|
+
</Canvas.Triggers>
|
|
159
|
+
<Image x:Name="Body" Width="80" Height="80" RenderOptions.BitmapScalingMode="HighQuality"/>
|
|
160
|
+
<Canvas x:Name="Eyes" Width="80" Height="80" IsHitTestVisible="False" RenderTransformOrigin="0.5,0.24">
|
|
161
|
+
<Canvas.RenderTransform><TransformGroup><ScaleTransform x:Name="Lid" ScaleY="1"/><ScaleTransform x:Name="Blink" ScaleY="1"/></TransformGroup></Canvas.RenderTransform>
|
|
162
|
+
<Canvas.Triggers>
|
|
163
|
+
<EventTrigger RoutedEvent="FrameworkElement.Loaded"><BeginStoryboard><Storyboard RepeatBehavior="Forever">
|
|
164
|
+
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="Blink" Storyboard.TargetProperty="ScaleY" Duration="0:0:4.300">
|
|
165
|
+
<DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="1"/><LinearDoubleKeyFrame KeyTime="0:0:3.700" Value="1"/>
|
|
166
|
+
<LinearDoubleKeyFrame KeyTime="0:0:3.780" Value="0.1"/><LinearDoubleKeyFrame KeyTime="0:0:3.880" Value="1"/>
|
|
167
|
+
</DoubleAnimationUsingKeyFrames>
|
|
168
|
+
</Storyboard></BeginStoryboard></EventTrigger>
|
|
169
|
+
</Canvas.Triggers>
|
|
170
|
+
${eyeWhites}
|
|
171
|
+
<Canvas>
|
|
172
|
+
<Canvas.RenderTransform><TranslateTransform x:Name="LookX"/></Canvas.RenderTransform>
|
|
173
|
+
${pupils}
|
|
174
|
+
</Canvas>
|
|
175
|
+
</Canvas>
|
|
176
|
+
</Canvas>
|
|
177
|
+
<Ellipse x:Name="Dot" Width="13" Height="13" Stroke="White" StrokeThickness="2.5" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,56,9,0"/>
|
|
178
|
+
</Grid>
|
|
179
|
+
</StackPanel>
|
|
180
|
+
</Window>`;
|
|
181
|
+
|
|
182
|
+
export const MASCOT_PS1 = String.raw`$ErrorActionPreference = 'Stop'
|
|
183
|
+
Add-Type -AssemblyName PresentationFramework, PresentationCore, WindowsBase
|
|
184
|
+
$utf8 = New-Object Text.UTF8Encoding $false
|
|
185
|
+
$dir = $env:AIVIN_MASCOT_DIR
|
|
186
|
+
function ReadText($name) { [IO.File]::ReadAllText((Join-Path $dir $name), $utf8) }
|
|
187
|
+
$cfg = ReadText 'config.json' | ConvertFrom-Json
|
|
188
|
+
$T = $cfg.strings; $P = $cfg.palette
|
|
189
|
+
$out = New-Object IO.StreamWriter([Console]::OpenStandardOutput(), $utf8); $out.AutoFlush = $true
|
|
190
|
+
function Send($o) { $out.WriteLine(($o | ConvertTo-Json -Compress)) }
|
|
191
|
+
# Win32 calls + a background thread that reads stdin lines into a queue (stream ReadLineAsync faults on a console pipe in .NET Framework).
|
|
192
|
+
Add-Type -TypeDefinition @'
|
|
193
|
+
using System; using System.Collections.Concurrent; using System.IO; using System.Runtime.InteropServices; using System.Text; using System.Threading;
|
|
194
|
+
namespace AivinMascot {
|
|
195
|
+
public static class Native {
|
|
196
|
+
[DllImport("user32.dll")] public static extern int GetWindowLong(IntPtr h, int i);
|
|
197
|
+
[DllImport("user32.dll")] public static extern int SetWindowLong(IntPtr h, int i, int v);
|
|
198
|
+
[DllImport("user32.dll")] public static extern bool SetWindowDisplayAffinity(IntPtr h, uint a);
|
|
199
|
+
}
|
|
200
|
+
public static class Input {
|
|
201
|
+
public static readonly ConcurrentQueue<string> Lines = new ConcurrentQueue<string>();
|
|
202
|
+
public static volatile bool Closed;
|
|
203
|
+
public static void Start() {
|
|
204
|
+
var t = new Thread(() => {
|
|
205
|
+
try {
|
|
206
|
+
var r = new StreamReader(Console.OpenStandardInput(), new UTF8Encoding(false));
|
|
207
|
+
string line; while ((line = r.ReadLine()) != null) Lines.Enqueue(line);
|
|
208
|
+
} catch { }
|
|
209
|
+
Closed = true;
|
|
210
|
+
});
|
|
211
|
+
t.IsBackground = true; t.Start();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
'@
|
|
216
|
+
|
|
217
|
+
$w = [Windows.Markup.XamlReader]::Parse((ReadText 'mascot.xaml'))
|
|
218
|
+
function E($n) { $w.FindName($n) }
|
|
219
|
+
$conv = New-Object Windows.Media.BrushConverter
|
|
220
|
+
function Brush($hex) { $conv.ConvertFromString($hex) }
|
|
221
|
+
function Img($file) { $b = New-Object Windows.Media.Imaging.BitmapImage; $b.BeginInit(); $b.UriSource = New-Object Uri (Join-Path $dir $file); $b.CacheOption = 'OnLoad'; $b.EndInit(); $b.Freeze(); $b }
|
|
222
|
+
(E 'Body').Source = Img 'mascot.png'; (E 'PanelLogo').Source = Img 'logo.png'
|
|
223
|
+
$w.Title = $T.window_title; (E 'Mascot').ToolTip = $T.tooltip; (E 'PanelTitle').Text = $T.panel_title
|
|
224
|
+
(E 'NowLabel').Text = $T.now_label; (E 'LogLabel').Text = $T.log_label; (E 'Empty').Text = $T.nothing_yet; (E 'NowText').Text = $T.ready
|
|
225
|
+
(E 'HideBtn').Content = $T.hide; (E 'OffBtn').Content = $T.turn_off; (E 'PanelClose').ToolTip = $T.close
|
|
226
|
+
|
|
227
|
+
# No focus stealing + no Alt+Tab entry; hidden from screen capture (AI screenshots, screen sharing).
|
|
228
|
+
$w.Add_SourceInitialized({
|
|
229
|
+
$h = (New-Object Windows.Interop.WindowInteropHelper $w).Handle
|
|
230
|
+
$ex = [AivinMascot.Native]::GetWindowLong($h, -20)
|
|
231
|
+
[void][AivinMascot.Native]::SetWindowLong($h, -20, ($ex -bor 0x08000000 -bor 0x00000080))
|
|
232
|
+
if (-not $env:AIVIN_MASCOT_CAPTURABLE) { [void][AivinMascot.Native]::SetWindowDisplayAffinity($h, 0x11) }
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
# Anchor = screen point of the mascot center (DIPs); the window is laid out around it, kept on screen.
|
|
236
|
+
$wa = [Windows.SystemParameters]::WorkArea
|
|
237
|
+
$script:cx = if ($cfg.x -ne $null) { [double]$cfg.x } else { $wa.Right - 76 }
|
|
238
|
+
$script:cy = if ($cfg.y -ne $null) { [double]$cfg.y } else { $wa.Bottom - 70 }
|
|
239
|
+
function Place {
|
|
240
|
+
$vl = [Windows.SystemParameters]::VirtualScreenLeft; $vt = [Windows.SystemParameters]::VirtualScreenTop
|
|
241
|
+
$vw = [Windows.SystemParameters]::VirtualScreenWidth; $vh = [Windows.SystemParameters]::VirtualScreenHeight
|
|
242
|
+
$script:cx = [Math]::Max($vl + 40, [Math]::Min($script:cx, $vl + $vw - 40)); $script:cy = [Math]::Max($vt + 40, [Math]::Min($script:cy, $vt + $vh - 40))
|
|
243
|
+
$side = if ($script:cx -gt $vl + $vw / 2) { 'Right' } else { 'Left' }
|
|
244
|
+
foreach ($n in 'Panel', 'Bubble', 'Mascot') { (E $n).HorizontalAlignment = $side }
|
|
245
|
+
foreach ($n in 'Tail', 'TailCover') { (E $n).HorizontalAlignment = $side }
|
|
246
|
+
$tm = if ($side -eq 'Right') { '0,0,35,0' } else { '35,0,0,0' }; (E 'Tail').Margin = $tm
|
|
247
|
+
(E 'TailCover').Margin = if ($side -eq 'Right') { '0,0,36,7' } else { '36,0,0,7' }
|
|
248
|
+
$w.UpdateLayout()
|
|
249
|
+
$p = (E 'Mascot').TranslatePoint((New-Object Windows.Point 42, 40), $w)
|
|
250
|
+
$left = $script:cx - $p.X; $top = $script:cy - $p.Y
|
|
251
|
+
$w.Left = [Math]::Max($vl, [Math]::Min($left, $vl + $vw - $w.ActualWidth))
|
|
252
|
+
$w.Top = [Math]::Max($vt, [Math]::Min($top, $vt + $vh - $w.ActualHeight))
|
|
253
|
+
}
|
|
254
|
+
$w.Add_SizeChanged({ Place })
|
|
255
|
+
|
|
256
|
+
$script:state = 'idle'
|
|
257
|
+
function SetState($s) {
|
|
258
|
+
if (-not $P.$s) { return }
|
|
259
|
+
$script:state = $s; $c = $P.$s
|
|
260
|
+
(E 'Dot').Fill = Brush $c.fg; (E 'BubbleDot').Fill = Brush $c.fg
|
|
261
|
+
(E 'Chip').Background = Brush $c.bg; (E 'ChipText').Foreground = Brush $c.fg; (E 'ChipText').Text = $T.('state_' + $s)
|
|
262
|
+
$busy = $s -eq 'working' -or $s -eq 'thinking'
|
|
263
|
+
if ($busy) { $w.FindResource('Pulse').Begin($w, $true); $w.FindResource('Look').Begin($w, $true) } else { $w.FindResource('Pulse').Stop($w); $w.FindResource('Look').Stop($w); (E 'Dot').Opacity = 1 }
|
|
264
|
+
(E 'Lid').ScaleY = if ($s -eq 'idle' -or $s -eq 'paused' -or $s -eq 'offline') { 0.55 } else { 1 }
|
|
265
|
+
(E 'PauseBtn').Content = if ($s -eq 'paused') { $T.resume } else { $T.pause }
|
|
266
|
+
if ($s -eq 'done' -or $s -eq 'waiting') { $w.FindResource('Hop').Begin($w) }
|
|
267
|
+
if (-not $busy -and $s -ne 'waiting' -and (E 'Bubble').Visibility -eq 'Visible') { $script:bubbleTimer.Stop(); $script:bubbleTimer.Start() }
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
$script:bubbleTimer = New-Object Windows.Threading.DispatcherTimer; $script:bubbleTimer.Interval = [TimeSpan]::FromSeconds(7)
|
|
271
|
+
$script:bubbleTimer.Add_Tick({ $script:bubbleTimer.Stop(); HideBubble })
|
|
272
|
+
function HideBubble {
|
|
273
|
+
$b = E 'Bubble'; if ($b.Visibility -ne 'Visible') { return }
|
|
274
|
+
$sb = $w.FindResource('BubbleOut').Clone(); $sb.Add_Completed({ (E 'Bubble').Visibility = 'Collapsed' }); $sb.Begin($b)
|
|
275
|
+
}
|
|
276
|
+
function ShowBubble($text) {
|
|
277
|
+
(E 'NowText').Text = $text
|
|
278
|
+
if ((E 'Panel').Visibility -eq 'Visible') { return }
|
|
279
|
+
(E 'BubbleText').Text = $text
|
|
280
|
+
$b = E 'Bubble'
|
|
281
|
+
if ($b.Visibility -ne 'Visible') { $b.Visibility = 'Visible'; $w.FindResource('BubbleIn').Begin($b) }
|
|
282
|
+
$script:bubbleTimer.Stop()
|
|
283
|
+
if ($script:state -ne 'working' -and $script:state -ne 'thinking' -and $script:state -ne 'waiting') { $script:bubbleTimer.Start() }
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
$script:rows = @{}; $script:order = New-Object System.Collections.Generic.Queue[string]
|
|
287
|
+
function LogEntry($m) {
|
|
288
|
+
$row = $null; if ($m.id) { $row = $script:rows[[string]$m.id] }
|
|
289
|
+
if (-not $row) {
|
|
290
|
+
$dp = New-Object Windows.Controls.DockPanel; $dp.Margin = '10,6,10,6'
|
|
291
|
+
$g = New-Object Windows.Controls.TextBlock; $g.Width = 16; $g.FontSize = 12; $g.FontWeight = 'Bold'; $g.Margin = '0,1,6,0'; [Windows.Controls.DockPanel]::SetDock($g, 'Left')
|
|
292
|
+
$tm = New-Object Windows.Controls.TextBlock; $tm.FontSize = 11; $tm.Foreground = Brush $P.muted; $tm.Margin = '8,2,0,0'; [Windows.Controls.DockPanel]::SetDock($tm, 'Right')
|
|
293
|
+
$sp = New-Object Windows.Controls.StackPanel
|
|
294
|
+
$ti = New-Object Windows.Controls.TextBlock; $ti.FontSize = 13; $ti.Foreground = Brush $P.ink; $ti.TextWrapping = 'Wrap'
|
|
295
|
+
$sub = New-Object Windows.Controls.TextBlock; $sub.FontSize = 11.5; $sub.Foreground = Brush $P.muted; $sub.TextWrapping = 'Wrap'; $sub.MaxHeight = 32; $sub.TextTrimming = 'CharacterEllipsis'; $sub.Margin = '0,1,0,0'
|
|
296
|
+
[void]$sp.Children.Add($ti); [void]$sp.Children.Add($sub)
|
|
297
|
+
[void]$dp.Children.Add($g); [void]$dp.Children.Add($tm); [void]$dp.Children.Add($sp)
|
|
298
|
+
$list = E 'LogList'; $list.Children.Insert(0, $dp); (E 'Empty').Visibility = 'Collapsed'
|
|
299
|
+
$row = @{ glyph = $g; time = $tm; title = $ti; sub = $sub }
|
|
300
|
+
if ($m.id) { $script:rows[[string]$m.id] = $row; $script:order.Enqueue([string]$m.id) }
|
|
301
|
+
while ($list.Children.Count -gt 150) { $list.Children.RemoveAt($list.Children.Count - 1) }
|
|
302
|
+
while ($script:order.Count -gt 150) { $script:rows.Remove($script:order.Dequeue()) }
|
|
303
|
+
}
|
|
304
|
+
if ($m.status) { $row.glyph.Text = $cfg.glyphs.($m.status); $row.glyph.Foreground = Brush $P.log.($m.status) }
|
|
305
|
+
if ($m.title) { $row.title.Text = $m.title }
|
|
306
|
+
if ($m.PSObject.Properties['sub']) { $row.sub.Text = [string]$m.sub; $row.sub.Visibility = if ($m.sub) { 'Visible' } else { 'Collapsed' } }
|
|
307
|
+
if ($m.time) { $row.time.Text = $m.time }
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function TogglePanel {
|
|
311
|
+
$p = E 'Panel'
|
|
312
|
+
if ($p.Visibility -eq 'Visible') {
|
|
313
|
+
$sb = $w.FindResource('PanelOut').Clone(); $sb.Add_Completed({ (E 'Panel').Visibility = 'Collapsed' }); $sb.Begin($p)
|
|
314
|
+
} else {
|
|
315
|
+
$script:bubbleTimer.Stop(); (E 'Bubble').Visibility = 'Collapsed'; (E 'Bubble').Opacity = 0
|
|
316
|
+
$p.Visibility = 'Visible'; $w.FindResource('PanelIn').Begin($p)
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
$script:userHidden = $false; $script:guiHidden = $false
|
|
321
|
+
function ApplyVisibility { $w.Visibility = if ($script:userHidden -or $script:guiHidden) { 'Hidden' } else { 'Visible' } }
|
|
322
|
+
|
|
323
|
+
# Drag to move, click to open / collapse the activity panel (DragMove returns on mouse up; no movement = click).
|
|
324
|
+
(E 'Mascot').Add_MouseLeftButtonDown({ param($s, $e)
|
|
325
|
+
$l0 = $w.Left; $t0 = $w.Top
|
|
326
|
+
try { $w.DragMove() } catch { }
|
|
327
|
+
$dx = $w.Left - $l0; $dy = $w.Top - $t0
|
|
328
|
+
if ([Math]::Abs($dx) + [Math]::Abs($dy) -lt 4) { TogglePanel }
|
|
329
|
+
else { $script:cx += $dx; $script:cy += $dy; Place; Send @{ t = 'pos'; x = [int]$script:cx; y = [int]$script:cy } }
|
|
330
|
+
$e.Handled = $true
|
|
331
|
+
})
|
|
332
|
+
(E 'PanelClose').Add_Click({ TogglePanel })
|
|
333
|
+
(E 'PauseBtn').Add_Click({ if ($script:state -eq 'paused') { Send @{ t = 'resume' } } else { Send @{ t = 'pause' } } })
|
|
334
|
+
(E 'HideBtn').Add_Click({ $script:userHidden = $true; ApplyVisibility; Send @{ t = 'hide' } })
|
|
335
|
+
(E 'OffBtn').Add_Click({ Send @{ t = 'off' } })
|
|
336
|
+
|
|
337
|
+
function Handle($m) {
|
|
338
|
+
switch ($m.t) {
|
|
339
|
+
'state' { SetState $m.state }
|
|
340
|
+
'main' { if ($m.quiet) { (E 'NowText').Text = $m.text } else { ShowBubble $m.text } }
|
|
341
|
+
'log' { LogEntry $m }
|
|
342
|
+
'gui' { $script:guiHidden = [bool]$m.active; ApplyVisibility }
|
|
343
|
+
'show' { $script:userHidden = $false; ApplyVisibility }
|
|
344
|
+
'quit' { $w.Close() }
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
# Commands arrive as JSON lines on stdin (background thread -> queue); the UI drains the queue. stdin closed = daemon gone -> close.
|
|
349
|
+
[AivinMascot.Input]::Start()
|
|
350
|
+
$pump = New-Object Windows.Threading.DispatcherTimer; $pump.Interval = [TimeSpan]::FromMilliseconds(80)
|
|
351
|
+
$pump.Add_Tick({
|
|
352
|
+
$line = $null
|
|
353
|
+
while ([AivinMascot.Input]::Lines.TryDequeue([ref]$line)) {
|
|
354
|
+
if ($line) { try { Handle ($line | ConvertFrom-Json) } catch { [Console]::Error.WriteLine($_.Exception.Message) } }
|
|
355
|
+
}
|
|
356
|
+
if ([AivinMascot.Input]::Closed -and [AivinMascot.Input]::Lines.IsEmpty) { $pump.Stop(); $w.Close() }
|
|
357
|
+
})
|
|
358
|
+
$w.Add_ContentRendered({ SetState 'idle'; Place; $w.FindResource('WindowIn').Begin($w); $pump.Start(); Send @{ t = 'ready' } })
|
|
359
|
+
$app = New-Object Windows.Application
|
|
360
|
+
$app.ShutdownMode = 'OnMainWindowClose'
|
|
361
|
+
[void]$app.Run($w)
|
|
362
|
+
`;
|