@xiaolikt/ai-vault 0.12.1 → 0.12.3
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/Cargo.lock +1 -1
- package/README.md +13 -1
- package/README.zh.md +3 -1
- package/crates/ai-vault/Cargo.toml +1 -1
- package/crates/ai-vault/src/dialog.rs +258 -36
- package/package.json +6 -4
- package/packages/pi-ai-vault/package.json +2 -2
- package/tests/windows.test.mjs +23 -9
package/Cargo.lock
CHANGED
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ must not be rewritten).
|
|
|
72
72
|
|---|---|
|
|
73
73
|
| Linux x64 / arm64 | ✅ published (`@xiaolikt/ai-vault-linux-x64` / `-linux-arm64`) |
|
|
74
74
|
| Windows x64 | ✅ published (`@xiaolikt/ai-vault-win32-x64`); dialogs via Windows PowerShell + WinForms, both built in |
|
|
75
|
-
| macOS arm64 / x64 |
|
|
75
|
+
| macOS arm64 / x64 | ✅ published (`@xiaolikt/ai-vault-darwin-arm64` / `-darwin-x64`), built by `.github/workflows/build.yml` on a macOS runner — the Apple SDK cannot be had anywhere else |
|
|
76
76
|
|
|
77
77
|
What is portable:
|
|
78
78
|
- **Crypto/storage**: pure Rust (chacha20poly1305, scrypt, hmac, sha2, base64, zeroize)
|
|
@@ -117,6 +117,18 @@ here must also report the version being published.
|
|
|
117
117
|
- **What is typed in a dialog is UTF-8**, whatever the console's code page is
|
|
118
118
|
(936 on a Chinese Windows). A dialog that fails to open is reported as
|
|
119
119
|
`needs-ui`, never as a cancel.
|
|
120
|
+
- **A password can be typed in any script.** Windows turns the IME off in a
|
|
121
|
+
password edit control (so that a candidate window cannot show what is typed),
|
|
122
|
+
and a Chinese master password could not be entered at all. The field is an
|
|
123
|
+
ordinary text box whose text is hidden by colour instead: one bullet per
|
|
124
|
+
character and a caret are drawn over it, and a check box shows the text.
|
|
125
|
+
- **The windows follow the display and the theme**, the way a zenity window
|
|
126
|
+
follows the GTK theme: laid out for the screen's scale (DPI-aware above
|
|
127
|
+
100 %), dark when the user's apps are dark (the title bar too), the user's
|
|
128
|
+
accent colour on the one affirmative button, which is the rightmost one as in
|
|
129
|
+
a GNOME dialog; Cancel is text only. Microsoft YaHei UI or Segoe UI, with the
|
|
130
|
+
shield as the icon. The confirm window has Deny and Allow of equal weight,
|
|
131
|
+
and Enter is Deny.
|
|
120
132
|
- **`bw` installed with npm works** (`bw.cmd` is unwrapped the same way).
|
|
121
133
|
`bw_run` needs Git for Windows: `bash.exe` is looked up next to the `git.exe`
|
|
122
134
|
on PATH. The clipboard goes through Windows PowerShell, as UTF-8 on stdin and
|
package/README.zh.md
CHANGED
|
@@ -73,7 +73,7 @@ printf '//registry.npmjs.org/:_authToken=%s\n' "<token>" > ~/.npmrc && chmod 600
|
|
|
73
73
|
|---|---|
|
|
74
74
|
| Linux x64 / arm64 | ✅ 已发布(`@xiaolikt/ai-vault-linux-x64` / `-linux-arm64`) |
|
|
75
75
|
| Windows x64 | ✅ 已发布(`@xiaolikt/ai-vault-win32-x64`),对话框走系统自带的 Windows PowerShell + WinForms |
|
|
76
|
-
| macOS arm64 / x64 |
|
|
76
|
+
| macOS arm64 / x64 | ✅ 已发布(`@xiaolikt/ai-vault-darwin-arm64` / `-darwin-x64`),由 `.github/workflows/build.yml` 在 macOS runner 上构建——Apple SDK 别处拿不到 |
|
|
77
77
|
|
|
78
78
|
跨平台的部分:
|
|
79
79
|
- **加密/存储**:纯 Rust(chacha20poly1305、scrypt、hmac、sha2、base64、zeroize)
|
|
@@ -100,6 +100,8 @@ cargo zigbuild --release --target x86_64-pc-windows-gnu
|
|
|
100
100
|
- **插件直接启动 `ai-vault.exe`。** Node 不带 shell 跑不了 npm 的 `.cmd`/`.ps1` 包装器,所以插件直接解析 `@xiaolikt/ai-vault-win32-x64` 里的二进制;只有包装器时,读出它指向的目标,用自己的 Node 启动。
|
|
101
101
|
- **弹窗需要交互式会话。** 服务、"用户未登录也运行"的计划任务、sshd 会话里没有可见桌面,CLI 会返回退出码 3(`needs-ui`),改用宿主输入框。没人应答的窗口和 Linux 一样在 600 秒后关闭,按取消处理。
|
|
102
102
|
- **弹窗里输入的内容一律是 UTF-8**,不管控制台代码页是什么(中文 Windows 是 936)。打不开的窗口报成 `needs-ui`,不会被当成取消。
|
|
103
|
+
- **任何文字都能输入。** Windows 会在密码编辑控件里关掉输入法(免得候选窗露出输入内容),中文主密码此前根本打不进去。现在输入框是普通文本框,只用颜色把文字藏起来:上面画着每个字符一个圆点和光标,另有一个「显示」勾选框可以看明文。
|
|
104
|
+
- **窗口跟随屏幕和主题**,就像 zenity 跟随 GTK 主题:按显示比例排版(缩放高于 100% 时启用 DPI 感知),系统应用是深色时窗口和标题栏也是深色,唯一的肯定按钮用系统强调色、放在最右边(和 GNOME 对话框一样),「取消」只是文字。字体用 Microsoft YaHei UI 或 Segoe UI,图标是系统的盾牌。确认框里「拒绝」和「允许」等权重,回车是「拒绝」。
|
|
103
105
|
- **npm 装的 `bw` 可用**(`bw.cmd` 同样被拆开启动)。`bw_run` 需要 Git for Windows:在 PATH 上 `git.exe` 的旁边找 `bash.exe`。剪贴板走 Windows PowerShell,值以 UTF-8 走 stdin/stdout。
|
|
104
106
|
- 库在 `%USERPROFILE%\.ai-vault`,靠用户目录的 ACL 保护。
|
|
105
107
|
|
|
@@ -179,10 +179,11 @@ mod win {
|
|
|
179
179
|
use std::thread::JoinHandle;
|
|
180
180
|
use std::time::{Duration, Instant};
|
|
181
181
|
|
|
182
|
-
// WinForms from PowerShell: no extra dependency, and
|
|
183
|
-
// the
|
|
182
|
+
// WinForms from PowerShell: no extra dependency, and the windows can follow
|
|
183
|
+
// the display and the theme. Exit 0 = OK (value on stdout), 1 = cancel,
|
|
184
|
+
// 2 = no window.
|
|
184
185
|
//
|
|
185
|
-
//
|
|
186
|
+
// Four things matter on a real Windows desktop:
|
|
186
187
|
// * `[Console]::Out.Write` encodes with the console's code page (936 on a
|
|
187
188
|
// Chinese Windows), so a password typed in Chinese arrived as mojibake
|
|
188
189
|
// and keyed a store no other machine could open. The value leaves as
|
|
@@ -191,27 +192,240 @@ mod win {
|
|
|
191
192
|
// load) used to make PowerShell exit 1, which reads as "the user
|
|
192
193
|
// cancelled": the host was told not to retry. The scripts trap into
|
|
193
194
|
// exit 2, and an exit 1 that printed an error counts the same.
|
|
194
|
-
|
|
195
|
+
// * Windows turns the IME off in a password edit control (so that a
|
|
196
|
+
// candidate window cannot show what is typed), and a Chinese password
|
|
197
|
+
// could not be entered at all. The field is an ordinary text box whose
|
|
198
|
+
// text is hidden by colour; a bullet per character is drawn over it.
|
|
199
|
+
// * `Controls.Add` puts a control at the back, and the label with the
|
|
200
|
+
// bullets sat under the box: what was typed looked like nothing. It is
|
|
201
|
+
// brought to the front. (DrawToBitmap paints the other way round, so
|
|
202
|
+
// only a capture from the screen showed it.)
|
|
203
|
+
const PRELUDE: &str = r#"
|
|
195
204
|
$ErrorActionPreference = 'Stop'
|
|
196
205
|
try {
|
|
197
206
|
Add-Type -AssemblyName System.Windows.Forms, System.Drawing
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
$
|
|
205
|
-
$
|
|
206
|
-
$
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
207
|
+
[System.Windows.Forms.Application]::EnableVisualStyles()
|
|
208
|
+
|
|
209
|
+
# The window follows the display and the theme, the way a zenity window
|
|
210
|
+
# follows the GTK theme: DPI-aware when the display is scaled, a dark
|
|
211
|
+
# palette and a dark title bar when the user's apps are dark, and the
|
|
212
|
+
# user's accent colour on the one positive button.
|
|
213
|
+
$scale = 1.0
|
|
214
|
+
$dark = $false
|
|
215
|
+
$accent = [System.Drawing.Color]::FromArgb(0, 120, 212)
|
|
216
|
+
$native = $false
|
|
217
|
+
try {
|
|
218
|
+
Add-Type -TypeDefinition 'using System; using System.Runtime.InteropServices; public static class AiVaultWin { [DllImport("user32.dll")] public static extern bool SetProcessDPIAware(); [DllImport("dwmapi.dll")] public static extern int DwmSetWindowAttribute(IntPtr h, int a, ref int v, int s); }'
|
|
219
|
+
$native = $true
|
|
220
|
+
} catch { }
|
|
221
|
+
try {
|
|
222
|
+
$dpi = [int](Get-ItemProperty 'HKCU:\Control Panel\Desktop\WindowMetrics' -Name AppliedDPI -ErrorAction Stop).AppliedDPI
|
|
223
|
+
if ($dpi -gt 96 -and $native -and [AiVaultWin]::SetProcessDPIAware()) { $scale = $dpi / 96.0 }
|
|
224
|
+
} catch { }
|
|
225
|
+
try {
|
|
226
|
+
$dark = [int](Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize' -Name AppsUseLightTheme -ErrorAction Stop).AppsUseLightTheme -eq 0
|
|
227
|
+
} catch { }
|
|
228
|
+
try {
|
|
229
|
+
$palette = (Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Accent' -Name AccentPalette -ErrorAction Stop).AccentPalette
|
|
230
|
+
if ($palette -and $palette.Length -ge 4) { $accent = [System.Drawing.Color]::FromArgb($palette[2], $palette[1], $palette[0]) }
|
|
231
|
+
} catch { }
|
|
232
|
+
$accentHover = [System.Drawing.Color]::FromArgb([Math]::Min(255, $accent.R + 24), [Math]::Min(255, $accent.G + 24), [Math]::Min(255, $accent.B + 24))
|
|
233
|
+
$onAccent = if ((0.299 * $accent.R + 0.587 * $accent.G + 0.114 * $accent.B) -gt 150) { [System.Drawing.Color]::Black } else { [System.Drawing.Color]::White }
|
|
234
|
+
if ($dark) {
|
|
235
|
+
$paper = [System.Drawing.Color]::FromArgb(32, 32, 32)
|
|
236
|
+
$card = [System.Drawing.Color]::FromArgb(43, 43, 43)
|
|
237
|
+
$hover = [System.Drawing.Color]::FromArgb(54, 54, 54)
|
|
238
|
+
$line = [System.Drawing.Color]::FromArgb(66, 66, 66)
|
|
239
|
+
$ink = [System.Drawing.Color]::FromArgb(255, 255, 255)
|
|
240
|
+
$muted = [System.Drawing.Color]::FromArgb(170, 170, 170)
|
|
241
|
+
} else {
|
|
242
|
+
$paper = [System.Drawing.Color]::FromArgb(243, 243, 243)
|
|
243
|
+
$card = [System.Drawing.Color]::FromArgb(255, 255, 255)
|
|
244
|
+
$hover = [System.Drawing.Color]::FromArgb(234, 234, 234)
|
|
245
|
+
$line = [System.Drawing.Color]::FromArgb(173, 173, 173)
|
|
246
|
+
$ink = [System.Drawing.Color]::FromArgb(26, 26, 26)
|
|
247
|
+
$muted = [System.Drawing.Color]::FromArgb(96, 96, 96)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function Px([double]$v) { [int][Math]::Round($v * $scale) }
|
|
251
|
+
|
|
252
|
+
# One typeface for Latin and Chinese where there is one; the system's otherwise.
|
|
253
|
+
$families = [System.Drawing.FontFamily]::Families | ForEach-Object { $_.Name }
|
|
254
|
+
$ui = 'Segoe UI'
|
|
255
|
+
foreach ($name in 'Microsoft YaHei UI', 'Microsoft YaHei') {
|
|
256
|
+
if ($families -contains $name) { $ui = $name; break }
|
|
257
|
+
}
|
|
258
|
+
function New-Font([double]$size, [System.Drawing.FontStyle]$style = [System.Drawing.FontStyle]::Regular) {
|
|
259
|
+
[System.Drawing.Font]::new($ui, [single]$size, $style, [System.Drawing.GraphicsUnit]::Point)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
# A control's shape with round corners. Call it once the control has its size.
|
|
263
|
+
function Round-Corners($control, [int]$radius) {
|
|
264
|
+
$w = $control.Width; $h = $control.Height; $d = [Math]::Min($radius * 2, [Math]::Min($w, $h))
|
|
265
|
+
if ($d -lt 2) { return }
|
|
266
|
+
$path = [System.Drawing.Drawing2D.GraphicsPath]::new()
|
|
267
|
+
$path.AddArc(0, 0, $d, $d, 180, 90); $path.AddArc($w - $d, 0, $d, $d, 270, 90)
|
|
268
|
+
$path.AddArc($w - $d, $h - $d, $d, $d, 0, 90); $path.AddArc(0, $h - $d, $d, $d, 90, 90)
|
|
269
|
+
$path.CloseFigure()
|
|
270
|
+
$control.Region = [System.Drawing.Region]::new($path)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function New-Window([string]$title) {
|
|
274
|
+
$w = [System.Windows.Forms.Form]::new()
|
|
275
|
+
$w.Text = $title
|
|
276
|
+
$w.FormBorderStyle = 'FixedDialog'; $w.MaximizeBox = $false; $w.MinimizeBox = $false
|
|
277
|
+
$w.AutoScaleMode = 'None'
|
|
278
|
+
$w.StartPosition = 'CenterScreen'; $w.TopMost = $true
|
|
279
|
+
$w.BackColor = $paper; $w.Font = New-Font 10
|
|
280
|
+
$w.Icon = [System.Drawing.Icon]::new([System.Drawing.SystemIcons]::Shield, (Px 16), (Px 16))
|
|
281
|
+
$w.ClientSize = [System.Drawing.Size]::new((Px 460), 0)
|
|
282
|
+
if ($dark -and $native) {
|
|
283
|
+
$on = 1 # DWMWA_USE_IMMERSIVE_DARK_MODE: the title bar follows the theme
|
|
284
|
+
[void][AiVaultWin]::DwmSetWindowAttribute($w.Handle, 20, [ref]$on, 4)
|
|
285
|
+
}
|
|
286
|
+
return $w
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
# A label that wraps, as tall as its text needs.
|
|
290
|
+
function Add-Text($w, [string]$text, [int]$top) {
|
|
291
|
+
$lbl = [System.Windows.Forms.Label]::new()
|
|
292
|
+
$lbl.Text = $text; $lbl.Font = New-Font 10.5; $lbl.ForeColor = $ink
|
|
293
|
+
$lbl.Left = Px 24; $lbl.Top = $top; $lbl.Width = (Px 460) - (Px 48)
|
|
294
|
+
$g = $lbl.CreateGraphics()
|
|
295
|
+
$lbl.Height = [int]($g.MeasureString($text, $lbl.Font, $lbl.Width).Height) + (Px 2)
|
|
296
|
+
$g.Dispose()
|
|
297
|
+
$w.Controls.Add($lbl)
|
|
298
|
+
return $lbl
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
# kind: accent (the one positive action), outline (an equal partner), quiet
|
|
302
|
+
# (text only, like the Cancel of a GNOME dialog).
|
|
303
|
+
function New-Button($w, [string]$text, [string]$result, [string]$kind) {
|
|
304
|
+
$b = [System.Windows.Forms.Button]::new()
|
|
305
|
+
$b.Text = $text; $b.DialogResult = $result; $b.FlatStyle = 'Flat'; $b.Tag = $kind
|
|
306
|
+
$b.Size = [System.Drawing.Size]::new((Px 96), (Px 34))
|
|
307
|
+
$b.Font = New-Font 10 ([System.Drawing.FontStyle]::Bold)
|
|
308
|
+
if ($kind -eq 'accent') {
|
|
309
|
+
$b.FlatAppearance.BorderSize = 0; $b.BackColor = $accent; $b.ForeColor = $onAccent
|
|
310
|
+
Round-Corners $b (Px 6)
|
|
311
|
+
} elseif ($kind -eq 'outline') {
|
|
312
|
+
$b.FlatAppearance.BorderSize = 1; $b.FlatAppearance.BorderColor = $line
|
|
313
|
+
$b.BackColor = $card; $b.ForeColor = $ink
|
|
314
|
+
Round-Corners $b (Px 6)
|
|
315
|
+
} else {
|
|
316
|
+
$b.FlatAppearance.BorderSize = 0; $b.BackColor = $paper; $b.ForeColor = $ink
|
|
317
|
+
$b.Font = New-Font 10
|
|
318
|
+
}
|
|
319
|
+
$b.Add_MouseEnter({ if ($this.Tag -eq 'accent') { $this.BackColor = $accentHover } else { $this.BackColor = $hover } })
|
|
320
|
+
$b.Add_MouseLeave({ if ($this.Tag -eq 'accent') { $this.BackColor = $accent } elseif ($this.Tag -eq 'quiet') { $this.BackColor = $paper } else { $this.BackColor = $card } })
|
|
321
|
+
$w.Controls.Add($b)
|
|
322
|
+
return $b
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
# A row at the bottom, flush right, in the order given (left to right): as
|
|
326
|
+
# in a GNOME dialog, the affirmative button is the rightmost one.
|
|
327
|
+
function Add-Buttons($w, $buttons, [int]$top) {
|
|
328
|
+
$x = $w.ClientSize.Width - (Px 24)
|
|
329
|
+
for ($i = $buttons.Count - 1; $i -ge 0; $i--) {
|
|
330
|
+
$b = $buttons[$i]
|
|
331
|
+
$b.Left = $x - $b.Width; $b.Top = $top
|
|
332
|
+
$x = $b.Left - (Px 8)
|
|
333
|
+
}
|
|
334
|
+
$w.ClientSize = [System.Drawing.Size]::new((Px 460), $top + (Px 34) + (Px 24))
|
|
335
|
+
}
|
|
336
|
+
"#;
|
|
337
|
+
|
|
338
|
+
const PREAMBLE: &str = r#"
|
|
339
|
+
$f = New-Window $env:AI_VAULT_DLG_TITLE
|
|
340
|
+
$secret = $env:AI_VAULT_DLG_SECRET -eq '1'
|
|
341
|
+
|
|
342
|
+
$lbl = Add-Text $f $env:AI_VAULT_DLG_TEXT (Px 22)
|
|
343
|
+
|
|
344
|
+
# The field: a panel draws a border that scales with the display and turns
|
|
345
|
+
# to the accent colour while the field has the focus; the text box fills it.
|
|
346
|
+
$field = [System.Windows.Forms.Panel]::new()
|
|
347
|
+
$field.BackColor = $line
|
|
348
|
+
$field.Left = Px 24; $field.Top = $lbl.Bottom + (Px 12); $field.Width = (Px 460) - (Px 48); $field.Height = Px 40
|
|
349
|
+
Round-Corners $field (Px 6)
|
|
350
|
+
$inner = [System.Windows.Forms.Panel]::new()
|
|
351
|
+
$inner.BackColor = $card; $inner.Dock = 'Fill'
|
|
352
|
+
$field.Padding = [System.Windows.Forms.Padding]::new((Px 1))
|
|
353
|
+
$inner.Add_SizeChanged({ Round-Corners $inner (Px 5) })
|
|
354
|
+
$field.Controls.Add($inner)
|
|
355
|
+
$f.Controls.Add($field)
|
|
356
|
+
|
|
357
|
+
$box = [System.Windows.Forms.TextBox]::new()
|
|
358
|
+
$box.Font = New-Font 11
|
|
359
|
+
$box.BorderStyle = 'None'; $box.AutoSize = $false
|
|
360
|
+
$box.BackColor = $card
|
|
361
|
+
if ($secret) { $box.ForeColor = $card }
|
|
362
|
+
$box.Height = $box.PreferredHeight
|
|
363
|
+
$inner.Padding = [System.Windows.Forms.Padding]::new((Px 12), 0, (Px 12), 0)
|
|
364
|
+
$inner.Controls.Add($box)
|
|
365
|
+
|
|
366
|
+
# Over the box, a label with one bullet per typed character and a caret of
|
|
367
|
+
# its own: the box keeps its text (and the IME), and shows none of it.
|
|
368
|
+
$mask = [System.Windows.Forms.Label]::new()
|
|
369
|
+
$mask.BackColor = $card; $mask.Font = New-Font 12; $mask.ForeColor = $ink
|
|
370
|
+
$mask.TextAlign = 'MiddleLeft'
|
|
371
|
+
$mask.Padding = [System.Windows.Forms.Padding]::new((Px 12), 0, 0, 0)
|
|
372
|
+
$mask.Visible = $secret
|
|
373
|
+
$caret = [System.Windows.Forms.Label]::new()
|
|
374
|
+
$caret.BackColor = $ink; $caret.Width = [Math]::Max(1, (Px 1)); $caret.Height = Px 18
|
|
375
|
+
$caret.Visible = $false
|
|
376
|
+
if ($secret) { $inner.Controls.Add($mask); $inner.Controls.Add($caret) }
|
|
377
|
+
# Controls.Add puts a control at the BACK: the mask and the caret have to be
|
|
378
|
+
# in front of the box, or the box paints over them.
|
|
379
|
+
$mask.BringToFront(); $caret.BringToFront()
|
|
380
|
+
function Layout-Field {
|
|
381
|
+
$box.Left = $inner.Padding.Left
|
|
382
|
+
$box.Top = [int](($inner.ClientSize.Height - $box.Height) / 2)
|
|
383
|
+
$box.Width = $inner.ClientSize.Width - $inner.Padding.Horizontal
|
|
384
|
+
$mask.Bounds = $inner.ClientRectangle
|
|
385
|
+
Update-Mask
|
|
386
|
+
}
|
|
387
|
+
$inner.Add_SizeChanged({ Round-Corners $inner (Px 5); Layout-Field })
|
|
388
|
+
|
|
389
|
+
$show = [System.Windows.Forms.LinkLabel]::new()
|
|
390
|
+
$show.Text = $env:AI_VAULT_DLG_SHOW
|
|
391
|
+
$show.Font = New-Font 9.5
|
|
392
|
+
$show.LinkColor = $accent; $show.ActiveLinkColor = $accentHover; $show.VisitedLinkColor = $accent
|
|
393
|
+
$show.LinkBehavior = [System.Windows.Forms.LinkBehavior]::HoverUnderline
|
|
394
|
+
$show.Visible = $secret
|
|
395
|
+
$f.Controls.Add($show)
|
|
396
|
+
$show.Width = $show.PreferredWidth + (Px 4); $show.Height = $show.PreferredHeight
|
|
397
|
+
$show.Left = $field.Right - $show.Width; $show.Top = $field.Bottom + (Px 10)
|
|
398
|
+
|
|
399
|
+
$shown = $false
|
|
400
|
+
function Set-Field-Look {
|
|
401
|
+
if ($shown -or -not $secret) { $box.ForeColor = $ink; $mask.Visible = $false }
|
|
402
|
+
else { $box.ForeColor = $card; $mask.Visible = $true }
|
|
403
|
+
$caret.Visible = ($box.Focused -and -not $shown -and $secret)
|
|
404
|
+
Update-Mask
|
|
405
|
+
}
|
|
406
|
+
function Update-Mask {
|
|
407
|
+
$mask.Text = ('● ' * $box.TextLength).TrimEnd()
|
|
408
|
+
$typed = if ($mask.Text) { $mask.Text + ' ' } else { '' }
|
|
409
|
+
$width = [System.Windows.Forms.TextRenderer]::MeasureText($typed, $mask.Font).Width
|
|
410
|
+
$caret.Left = $mask.Left + [Math]::Min($mask.Padding.Left + $width, $mask.Width - $caret.Width)
|
|
411
|
+
$caret.Top = $mask.Top + [int](($mask.Height - $caret.Height) / 2)
|
|
412
|
+
}
|
|
413
|
+
$box.Add_TextChanged({ Update-Mask })
|
|
414
|
+
$box.Add_GotFocus({ $caret.Visible = (-not $shown -and $secret); $field.BackColor = $accent })
|
|
415
|
+
$box.Add_LostFocus({ $caret.Visible = $false; $field.BackColor = $line })
|
|
416
|
+
$mask.Add_Click({ $box.Focus() })
|
|
417
|
+
$show.Add_LinkClicked({ $shown = -not $shown; Set-Field-Look; [void]$box.Focus() })
|
|
418
|
+
$blink = [System.Windows.Forms.Timer]::new(); $blink.Interval = 530
|
|
419
|
+
$blink.Add_Tick({ if ($box.Focused -and $secret -and -not $shown) { $caret.Visible = -not $caret.Visible } })
|
|
420
|
+
$blink.Start()
|
|
421
|
+
|
|
422
|
+
$cancel = New-Button $f $env:AI_VAULT_DLG_CANCEL 'Cancel' 'quiet'
|
|
423
|
+
$ok = New-Button $f $env:AI_VAULT_DLG_OK 'OK' 'accent'
|
|
424
|
+
$bottom = $(if ($secret) { $show.Bottom } else { $field.Bottom }) + (Px 20)
|
|
425
|
+
Add-Buttons $f @($cancel, $ok) $bottom
|
|
426
|
+
$f.AcceptButton = $ok; $f.CancelButton = $cancel
|
|
427
|
+
$f.Add_Shown({ Layout-Field; [void]$box.Focus() })
|
|
428
|
+
|
|
215
429
|
if ($f.ShowDialog() -eq 'OK') {
|
|
216
430
|
$bytes = [System.Text.Encoding]::UTF8.GetBytes($box.Text)
|
|
217
431
|
$stdout = [Console]::OpenStandardOutput()
|
|
@@ -225,20 +439,23 @@ try {
|
|
|
225
439
|
}
|
|
226
440
|
"#;
|
|
227
441
|
|
|
228
|
-
// A
|
|
229
|
-
//
|
|
230
|
-
//
|
|
442
|
+
// A window of its own rather than a MessageBox: the buttons then say
|
|
443
|
+
// Allow and Deny in the user's language, and it matches the other one.
|
|
444
|
+
// Both weigh the same, and Deny has the focus: Enter is the safe answer
|
|
445
|
+
// from wherever the focus starts, Esc too. Allow takes a click, or Tab
|
|
446
|
+
// and Enter on it.
|
|
231
447
|
const CONFIRM: &str = r#"
|
|
232
|
-
$
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
$
|
|
236
|
-
$
|
|
237
|
-
$
|
|
238
|
-
$
|
|
239
|
-
$
|
|
240
|
-
$
|
|
241
|
-
|
|
448
|
+
$f = New-Window $env:AI_VAULT_DLG_TITLE
|
|
449
|
+
$lbl = Add-Text $f $env:AI_VAULT_DLG_TEXT (Px 22)
|
|
450
|
+
|
|
451
|
+
$deny = New-Button $f $env:AI_VAULT_DLG_DENY 'Cancel' 'outline'
|
|
452
|
+
$allow = New-Button $f $env:AI_VAULT_DLG_ALLOW 'OK' 'outline'
|
|
453
|
+
Add-Buttons $f @($deny, $allow) ($lbl.Bottom + (Px 24))
|
|
454
|
+
$f.AcceptButton = $deny
|
|
455
|
+
$f.CancelButton = $deny
|
|
456
|
+
$f.Add_Shown({ $deny.Focus() })
|
|
457
|
+
|
|
458
|
+
if ($f.ShowDialog() -eq 'OK') { exit 0 }
|
|
242
459
|
exit 1
|
|
243
460
|
} catch {
|
|
244
461
|
[Console]::Error.Write($_)
|
|
@@ -275,13 +492,18 @@ try {
|
|
|
275
492
|
})
|
|
276
493
|
}
|
|
277
494
|
|
|
278
|
-
fn powershell(
|
|
495
|
+
fn powershell(body: &str, title: &str, text: &str, secret: bool) -> Out {
|
|
496
|
+
let script = format!("{PRELUDE}{body}");
|
|
279
497
|
let mut cmd = Command::new(powershell_exe());
|
|
280
|
-
cmd.args(["-NoProfile", "-NonInteractive", "-STA", "-Command", script])
|
|
498
|
+
cmd.args(["-NoProfile", "-NonInteractive", "-STA", "-Command", &script])
|
|
281
499
|
.env("AI_VAULT_DLG_TITLE", title)
|
|
282
500
|
.env("AI_VAULT_DLG_TEXT", text)
|
|
283
501
|
.env("AI_VAULT_DLG_SECRET", if secret { "1" } else { "0" })
|
|
502
|
+
.env("AI_VAULT_DLG_OK", crate::i18n::tr("OK", "确定"))
|
|
284
503
|
.env("AI_VAULT_DLG_CANCEL", crate::i18n::tr("Cancel", "取消"))
|
|
504
|
+
.env("AI_VAULT_DLG_SHOW", crate::i18n::tr("Show", "显示"))
|
|
505
|
+
.env("AI_VAULT_DLG_ALLOW", crate::i18n::tr("Allow", "允许"))
|
|
506
|
+
.env("AI_VAULT_DLG_DENY", crate::i18n::tr("Deny", "拒绝"))
|
|
285
507
|
.stdin(Stdio::null())
|
|
286
508
|
.stdout(Stdio::piped())
|
|
287
509
|
.stderr(Stdio::piped());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiaolikt/ai-vault",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.3",
|
|
4
4
|
"description": "One machine-wide encrypted secret store for AI coding agents: the ai-vault Rust CLI (npm-installable, Linux/macOS/Windows) plus the pi-ai-vault extension for pi and omp.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,9 +33,11 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"optionalDependencies": {
|
|
36
|
-
"@xiaolikt/ai-vault-linux-x64": "0.12.
|
|
37
|
-
"@xiaolikt/ai-vault-linux-arm64": "0.12.
|
|
38
|
-
"@xiaolikt/ai-vault-win32-x64": "0.12.
|
|
36
|
+
"@xiaolikt/ai-vault-linux-x64": "0.12.3",
|
|
37
|
+
"@xiaolikt/ai-vault-linux-arm64": "0.12.3",
|
|
38
|
+
"@xiaolikt/ai-vault-win32-x64": "0.12.3",
|
|
39
|
+
"@xiaolikt/ai-vault-darwin-arm64": "0.12.3",
|
|
40
|
+
"@xiaolikt/ai-vault-darwin-x64": "0.12.3"
|
|
39
41
|
},
|
|
40
42
|
"files": [
|
|
41
43
|
"bin",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-ai-vault",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.3",
|
|
4
4
|
"description": "pi extension for ai-vault: one machine-wide encrypted secret store, live Bitwarden and Ente Auth. Works in pi and in omp (the omp fork reads the same manifest).",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"security"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@xiaolikt/ai-vault": "0.12.
|
|
28
|
+
"@xiaolikt/ai-vault": "0.12.3"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@earendil-works/pi-coding-agent": "^1.5.0",
|
package/tests/windows.test.mjs
CHANGED
|
@@ -370,14 +370,24 @@ function showWindow(script) {
|
|
|
370
370
|
|
|
371
371
|
const SHOWN = " if ($f.ShowDialog() -eq 'OK') {";
|
|
372
372
|
const passwordWindow = (action) => {
|
|
373
|
-
const script = dialogScript("PREAMBLE");
|
|
373
|
+
const script = dialogScript("PRELUDE") + dialogScript("PREAMBLE");
|
|
374
374
|
assert.ok(script.includes(SHOWN), "the password window still calls ShowDialog()");
|
|
375
375
|
return script.replace(SHOWN, `${autoAnswer(action)}\n${SHOWN}`);
|
|
376
376
|
};
|
|
377
377
|
|
|
378
378
|
test("Windows: the password window answers in UTF-8, whatever the console's code page", onDesktop, () => {
|
|
379
379
|
const value = "密码测试-Pässw0rd";
|
|
380
|
-
|
|
380
|
+
// The field must not be a password edit control (Windows turns the IME off
|
|
381
|
+
// there): the text is hidden by colour, and bullets are drawn over the field.
|
|
382
|
+
const kept = [
|
|
383
|
+
"if ($box.UseSystemPasswordChar) { throw 'the field is a password edit control: no IME there' }",
|
|
384
|
+
"if ($box.ForeColor -ne $box.BackColor) { throw 'the typed text is visible' }",
|
|
385
|
+
`$box.Text = '${value}'`,
|
|
386
|
+
"if ($mask.Text -notmatch '●') { throw 'no bullets are drawn over the field' }",
|
|
387
|
+
"if ($mask.Parent.Controls.GetChildIndex($mask) -ge $mask.Parent.Controls.GetChildIndex($box)) { throw 'the bullets are behind the text box: Controls.Add puts a control at the back' }",
|
|
388
|
+
"$f.DialogResult = 'OK'",
|
|
389
|
+
].join("; ");
|
|
390
|
+
const r = showWindow(passwordWindow(kept));
|
|
381
391
|
assert.equal(r.status, 0, r.stderr.toString());
|
|
382
392
|
assert.equal(new TextDecoder().decode(r.stdout), value);
|
|
383
393
|
});
|
|
@@ -393,7 +403,7 @@ test("Windows: cancel and an empty field end the prompt cleanly (exit 1 / empty,
|
|
|
393
403
|
});
|
|
394
404
|
|
|
395
405
|
test("Windows: a window that cannot open exits 2; a script that will not parse exits 1 with the error on stderr", onDesktop, () => {
|
|
396
|
-
const script = dialogScript("PREAMBLE");
|
|
406
|
+
const script = dialogScript("PRELUDE") + dialogScript("PREAMBLE");
|
|
397
407
|
// A policy that forbids Add-Type, simulated by shadowing the cmdlet.
|
|
398
408
|
const forbidden = showWindow("function Add-Type { throw 'Add-Type is blocked by policy (simulated)' }\n" + script);
|
|
399
409
|
assert.equal(forbidden.status, 2, "reported as no window, which is needs-ui to the host");
|
|
@@ -407,10 +417,14 @@ test("Windows: a window that cannot open exits 2; a script that will not parse e
|
|
|
407
417
|
assert.notEqual(unparsable.stderr.toString().trim(), "");
|
|
408
418
|
});
|
|
409
419
|
|
|
410
|
-
test("Windows: the confirm window is
|
|
411
|
-
const script = dialogScript("CONFIRM");
|
|
412
|
-
|
|
413
|
-
assert.
|
|
414
|
-
const
|
|
415
|
-
assert.
|
|
420
|
+
test("Windows: the confirm window is one of its own: Enter is Deny, a click on Allow is the only way to exit 0", onDesktop, () => {
|
|
421
|
+
const script = dialogScript("PRELUDE") + dialogScript("CONFIRM");
|
|
422
|
+
assert.match(script, /\$f\.AcceptButton = \$deny/, "Enter is the safe answer");
|
|
423
|
+
assert.match(script, /\$f\.CancelButton = \$deny/, "Esc is the safe answer");
|
|
424
|
+
const shown = " if ($f.ShowDialog() -eq 'OK') { exit 0 }";
|
|
425
|
+
assert.ok(script.includes(shown), "the confirm window still ends in ShowDialog()");
|
|
426
|
+
const answer = (click) => showWindow(script.replace(shown, `${autoAnswer(click)}\n${shown}`)).status;
|
|
427
|
+
assert.notEqual(answer("$f.Close()"), 0, "a closed window must never read as approval");
|
|
428
|
+
assert.equal(answer("$deny.PerformClick()"), 1, "Deny");
|
|
429
|
+
assert.equal(answer("$allow.PerformClick()"), 0, "Allow");
|
|
416
430
|
});
|