@xiaolikt/ai-vault 0.12.0 → 0.12.2
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 +32 -5
- package/README.zh.md +14 -5
- package/crates/ai-vault/Cargo.toml +1 -1
- package/crates/ai-vault/src/dialog.rs +185 -37
- package/package.json +6 -4
- package/packages/pi-ai-vault/package.json +2 -2
- package/packages/pi-ai-vault/src/bitwarden.ts +151 -25
- package/packages/pi-ai-vault/src/cli.ts +117 -25
- package/packages/pi-ai-vault/src/ente.ts +5 -2
- package/tests/helpers.mjs +6 -5
- package/tests/windows.test.mjs +416 -0
package/Cargo.lock
CHANGED
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ client of it, so agents no longer keep a copy each.
|
|
|
11
11
|
~/.ai-vault/audit.log who read what and when; never a value
|
|
12
12
|
~/.ai-vault/store.lock file lock for read-modify-write across processes
|
|
13
13
|
$XDG_RUNTIME_DIR/ai-vault/sessions/<token>.json unlock tokens (0600, tmpfs)
|
|
14
|
+
%TEMP%\ai-vault\sessions\<token>.json the same on Windows: a regular file under the user's profile
|
|
14
15
|
```
|
|
15
16
|
|
|
16
17
|
Because the location is fixed and owned by the CLI, pi, omp, scripts and any
|
|
@@ -70,8 +71,8 @@ must not be rewritten).
|
|
|
70
71
|
| Platform | Status |
|
|
71
72
|
|---|---|
|
|
72
73
|
| Linux x64 / arm64 | ✅ published (`@xiaolikt/ai-vault-linux-x64` / `-linux-arm64`) |
|
|
73
|
-
| Windows x64 | ✅ published (`@xiaolikt/ai-vault-win32-x64`); dialogs via PowerShell
|
|
74
|
-
| macOS arm64 / x64 |
|
|
74
|
+
| Windows x64 | ✅ published (`@xiaolikt/ai-vault-win32-x64`); dialogs via Windows PowerShell + WinForms, both built in |
|
|
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 |
|
|
75
76
|
|
|
76
77
|
What is portable:
|
|
77
78
|
- **Crypto/storage**: pure Rust (chacha20poly1305, scrypt, hmac, sha2, base64, zeroize)
|
|
@@ -79,7 +80,8 @@ What is portable:
|
|
|
79
80
|
- **Permissions**: 0600/0700 on Unix; Windows has no mode bits and relies on the
|
|
80
81
|
`%USERPROFILE%\.ai-vault` ACL
|
|
81
82
|
- **Session directory**: `$XDG_RUNTIME_DIR` (Linux), `$TMPDIR` (macOS), `%TEMP%`
|
|
82
|
-
(Windows) — per-user,
|
|
83
|
+
(Windows) — per-user; tmpfs on Linux, and on Windows a regular folder that the
|
|
84
|
+
next `ai-vault` run sweeps of expired tokens
|
|
83
85
|
- **Dialogs**: zenity / osascript / PowerShell+WinForms behind one `Answer`
|
|
84
86
|
contract (`NoUi` is what falls back to the host prompt)
|
|
85
87
|
|
|
@@ -96,7 +98,30 @@ cargo zigbuild --release --target x86_64-pc-windows-gnu
|
|
|
96
98
|
|
|
97
99
|
`stage-npm.sh` accepts either an npm platform name (`darwin-arm64`) or a Rust
|
|
98
100
|
triple (`aarch64-apple-darwin`). macOS binaries can only be linked with the
|
|
99
|
-
Apple SDK, so CI does that (build + publish on a `v*` tag).
|
|
101
|
+
Apple SDK, so CI does that (build + publish on a `v*` tag). The darwin packages
|
|
102
|
+
are already listed under `optionalDependencies`; npm skips an optional
|
|
103
|
+
dependency that is not published yet, so the list can precede them.
|
|
104
|
+
`--from` refuses a binary older than the last version bump, and one that can run
|
|
105
|
+
here must also report the version being published.
|
|
106
|
+
|
|
107
|
+
### Windows
|
|
108
|
+
|
|
109
|
+
- **The extension starts `ai-vault.exe` itself.** Node will not run npm's
|
|
110
|
+
`.cmd`/`.ps1` wrappers without a shell, so the plugin resolves the binary of
|
|
111
|
+
`@xiaolikt/ai-vault-win32-x64` directly and, where only a wrapper exists, reads
|
|
112
|
+
it and starts what it names with its own Node.
|
|
113
|
+
- **A dialog needs an interactive session.** Services, scheduled tasks that run
|
|
114
|
+
without a logged-on user and sshd sessions have no visible desktop; there the
|
|
115
|
+
CLI answers exit code 3 (`needs-ui`) and the host prompt is used. A window
|
|
116
|
+
nobody answers closes after the same 600 s as on Linux, and counts as a cancel.
|
|
117
|
+
- **What is typed in a dialog is UTF-8**, whatever the console's code page is
|
|
118
|
+
(936 on a Chinese Windows). A dialog that fails to open is reported as
|
|
119
|
+
`needs-ui`, never as a cancel.
|
|
120
|
+
- **`bw` installed with npm works** (`bw.cmd` is unwrapped the same way).
|
|
121
|
+
`bw_run` needs Git for Windows: `bash.exe` is looked up next to the `git.exe`
|
|
122
|
+
on PATH. The clipboard goes through Windows PowerShell, as UTF-8 on stdin and
|
|
123
|
+
stdout.
|
|
124
|
+
- The store is `%USERPROFILE%\.ai-vault`, protected by the profile's ACL.
|
|
100
125
|
|
|
101
126
|
### From source / git
|
|
102
127
|
|
|
@@ -471,7 +496,9 @@ may *use* passwords but cannot *get around you* to take them.
|
|
|
471
496
|
upgrades it. Anything below `2^15` is refused as a downgrade.
|
|
472
497
|
- **The master password** only passes through a dialog or the host prompt; the
|
|
473
498
|
key `unlock` derives only goes into the token file (0600, tmpfs when there is
|
|
474
|
-
one
|
|
499
|
+
one; on Windows a regular file under `%TEMP%`, protected by the profile's ACL,
|
|
500
|
+
which a reboot leaves in place until the next `ai-vault` run removes it once
|
|
501
|
+
expired). `BW_*` is stripped from every child environment.
|
|
475
502
|
- **Audit**: `~/.ai-vault/audit.log` records sessions, entries, allow/deny with
|
|
476
503
|
the reason, and attempts such as `unsigned-relay`, `bad-approval`,
|
|
477
504
|
`modified-outside`; never a value. Rotated at 1 MiB.
|
package/README.zh.md
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
~/.ai-vault/audit.log 谁在什么时候读了什么,从不记值
|
|
10
10
|
~/.ai-vault/store.lock 多进程读改写时的文件锁
|
|
11
11
|
$XDG_RUNTIME_DIR/ai-vault/sessions/<token>.json 解锁令牌(0600,tmpfs)
|
|
12
|
+
%TEMP%\ai-vault\sessions\<token>.json Windows:同样的内容,用户目录下的普通文件
|
|
12
13
|
```
|
|
13
14
|
|
|
14
15
|
因为位置是固定的、由 CLI 独占的,所以同一台机器上 pi、omp、脚本、别的 agent 拿到的都是同一批已导入的密码,不会再出现「这个 agent 导过、那个没导过」。
|
|
@@ -64,21 +65,21 @@ printf '//registry.npmjs.org/:_authToken=%s\n' "<token>" > ~/.npmrc && chmod 600
|
|
|
64
65
|
|
|
65
66
|
这类令牌 npm 会在 2027 年 1 月起逐步作废,届时改用 trusted publishing 或 TOTP 2FA。
|
|
66
67
|
|
|
67
|
-
别的平台要有自己的二进制包:`./scripts/stage-npm.sh darwin-arm64 --from
|
|
68
|
+
别的平台要有自己的二进制包:`./scripts/stage-npm.sh darwin-arm64 --from <交叉编译产物>`。darwin 的两个包已经列在 `optionalDependencies` 里,还没发布时 npm 会跳过 optional 依赖,所以列表可以先于包存在。没有匹配的平台包时,shim 会明确报错并提示 `cargo install --path crates/ai-vault`。`--from` 会拒绝早于上一次改版本号的二进制;能在本机运行的二进制,还必须自报正在发布的版本。
|
|
68
69
|
|
|
69
70
|
### 平台
|
|
70
71
|
|
|
71
72
|
| 平台 | 状态 |
|
|
72
73
|
|---|---|
|
|
73
74
|
| Linux x64 / arm64 | ✅ 已发布(`@xiaolikt/ai-vault-linux-x64` / `-linux-arm64`) |
|
|
74
|
-
| Windows x64 | ✅ 已发布(`@xiaolikt/ai-vault-win32-x64
|
|
75
|
-
| macOS arm64 / x64 |
|
|
75
|
+
| Windows x64 | ✅ 已发布(`@xiaolikt/ai-vault-win32-x64`),对话框走系统自带的 Windows PowerShell + WinForms |
|
|
76
|
+
| macOS arm64 / x64 | ✅ 已发布(`@xiaolikt/ai-vault-darwin-arm64` / `-darwin-x64`),由 `.github/workflows/build.yml` 在 macOS runner 上构建——Apple SDK 别处拿不到 |
|
|
76
77
|
|
|
77
78
|
跨平台的部分:
|
|
78
79
|
- **加密/存储**:纯 Rust(chacha20poly1305、scrypt、hmac、sha2、base64、zeroize)
|
|
79
80
|
- **文件锁**:`fs4`(Linux/macOS 用 flock,Windows 用 LockFileEx)
|
|
80
81
|
- **权限**:Unix 设 0600/0700;Windows 没有位权限,靠 `%USERPROFILE%\.ai-vault` 的 ACL
|
|
81
|
-
- **会话目录**:Linux `$XDG_RUNTIME_DIR`、macOS `$TMPDIR`、Windows `%TEMP
|
|
82
|
+
- **会话目录**:Linux `$XDG_RUNTIME_DIR`、macOS `$TMPDIR`、Windows `%TEMP%`,都是每人一份;Linux 上是 tmpfs,Windows 上是普通目录,过期的令牌由下一次 `ai-vault` 运行清掉
|
|
82
83
|
- **弹窗**:Linux zenity / macOS osascript / Windows PowerShell+WinForms,同一套 `Answer` 契约(`NoUi` 才回退到宿主输入框)
|
|
83
84
|
|
|
84
85
|
自己交叉编译(不需要 Mac/Windows 机器):
|
|
@@ -94,6 +95,14 @@ cargo zigbuild --release --target x86_64-pc-windows-gnu
|
|
|
94
95
|
|
|
95
96
|
`stage-npm.sh` 两种写法都收:npm 平台名(`darwin-arm64`)或 Rust triple(`aarch64-apple-darwin`)。macOS 的二进制只能用 Apple SDK 链,所以留给 CI(tag push 时自动构建 + 发布)。
|
|
96
97
|
|
|
98
|
+
### Windows
|
|
99
|
+
|
|
100
|
+
- **插件直接启动 `ai-vault.exe`。** Node 不带 shell 跑不了 npm 的 `.cmd`/`.ps1` 包装器,所以插件直接解析 `@xiaolikt/ai-vault-win32-x64` 里的二进制;只有包装器时,读出它指向的目标,用自己的 Node 启动。
|
|
101
|
+
- **弹窗需要交互式会话。** 服务、"用户未登录也运行"的计划任务、sshd 会话里没有可见桌面,CLI 会返回退出码 3(`needs-ui`),改用宿主输入框。没人应答的窗口和 Linux 一样在 600 秒后关闭,按取消处理。
|
|
102
|
+
- **弹窗里输入的内容一律是 UTF-8**,不管控制台代码页是什么(中文 Windows 是 936)。打不开的窗口报成 `needs-ui`,不会被当成取消。
|
|
103
|
+
- **npm 装的 `bw` 可用**(`bw.cmd` 同样被拆开启动)。`bw_run` 需要 Git for Windows:在 PATH 上 `git.exe` 的旁边找 `bash.exe`。剪贴板走 Windows PowerShell,值以 UTF-8 走 stdin/stdout。
|
|
104
|
+
- 库在 `%USERPROFILE%\.ai-vault`,靠用户目录的 ACL 保护。
|
|
105
|
+
|
|
97
106
|
### 从源码 / git
|
|
98
107
|
|
|
99
108
|
```bash
|
|
@@ -376,7 +385,7 @@ pi-ai-vault 只是这套 CLI 的客户端,本身不保存 Ente 的任何密钥
|
|
|
376
385
|
- **Bitwarden 会话密钥加密封存。** `bitwarden.unlock = never|time` 时,`bw` 的会话密钥用 ChaCha20-Poly1305 封在 `~/.ai-vault/bitwarden.session.json` 下,密钥是 `~/.ai-vault/.wrap`(0600)。单独拷走那个文件什么都打不开。`bw unlock --raw` 的会话密钥等价于**整个** Bitwarden 保险库的读权限,所以这个文件的敏感度 ≥ 库本身。
|
|
377
386
|
- **确认窗里的字不是模型写的。** 条目名、原因、用户名、URI 进窗口前都压成一行、去掉控制字符、截到 80–120 字符,模型没法在名字里塞换行伪造第二条「已授权」。
|
|
378
387
|
- **KDF。** 新库 scrypt `N=2^17`(128 MiB);文件头记着参数,旧库(`N=2^15`)照常打开,`ai-vault rekey` 升级。低于 `2^15` 的参数一律拒收(防降级)。
|
|
379
|
-
- **主密码**只经过弹窗或宿主输入框;`unlock` 派生的 key 只写进令牌文件(0600,优先 tmpfs
|
|
388
|
+
- **主密码**只经过弹窗或宿主输入框;`unlock` 派生的 key 只写进令牌文件(0600,优先 tmpfs;Windows 上是 `%TEMP%` 下的普通文件,靠用户目录的 ACL 保护,重启后仍在,过期后由下一次 `ai-vault` 运行删除)。`BW_*` 在所有子进程环境里剔除。
|
|
380
389
|
- **审计**:`~/.ai-vault/audit.log` 记录会话、条目、允许/拒绝/原因、以及 `unsigned-relay`、`bad-approval`、`modified-outside` 这类尝试,从不记值;1 MiB 轮转。
|
|
381
390
|
- **原子写 + flock**:临时文件(0600)→ fsync → rename → 目录 fsync;多进程读改写有文件锁。失效/被改/旧库的令牌文件每次调用都会被清掉。
|
|
382
391
|
- `bw_reveal` 默认关闭;擦洗只在值长度 ≥ 6 时生效,防不住网络外传和单向哈希——`bw_run` / `bw_inject` 的价值是值不进对话,不是防住被注入的 agent。
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
//!
|
|
7
7
|
//! When no window can open at all, the caller gets `NoUi` and the host UI
|
|
8
8
|
//! (pi/omp prompt) takes over. Cancel and our own timeout end the prompt here:
|
|
9
|
-
//! they never turn into a second prompt.
|
|
9
|
+
//! they never turn into a second prompt. Every platform answers the value as
|
|
10
|
+
//! UTF-8, whatever the terminal's code page is.
|
|
10
11
|
|
|
11
12
|
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
|
|
12
13
|
use std::env;
|
|
@@ -33,8 +34,17 @@ pub fn has_display() -> bool {
|
|
|
33
34
|
.iter()
|
|
34
35
|
.any(|name| env::var_os(name).is_some_and(|v| !v.is_empty()));
|
|
35
36
|
}
|
|
36
|
-
// macOS
|
|
37
|
-
#[cfg(
|
|
37
|
+
// macOS always has a window server for an interactive user.
|
|
38
|
+
#[cfg(target_os = "macos")]
|
|
39
|
+
{
|
|
40
|
+
true
|
|
41
|
+
}
|
|
42
|
+
// Only the interactive session on Windows has a desktop anyone can see.
|
|
43
|
+
#[cfg(target_os = "windows")]
|
|
44
|
+
{
|
|
45
|
+
win::has_display()
|
|
46
|
+
}
|
|
47
|
+
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
|
|
38
48
|
{
|
|
39
49
|
true
|
|
40
50
|
}
|
|
@@ -163,39 +173,89 @@ mod mac {
|
|
|
163
173
|
#[cfg(target_os = "windows")]
|
|
164
174
|
mod win {
|
|
165
175
|
use super::{Answer, DIALOG_SECONDS};
|
|
176
|
+
use std::io::Read;
|
|
177
|
+
use std::path::PathBuf;
|
|
166
178
|
use std::process::{Command, Stdio};
|
|
179
|
+
use std::thread::JoinHandle;
|
|
180
|
+
use std::time::{Duration, Instant};
|
|
167
181
|
|
|
168
182
|
// WinForms from PowerShell: no extra dependency, and PasswordChar can hide
|
|
169
183
|
// the input. Exit 0 = OK (value on stdout), 1 = cancel, 2 = no window.
|
|
184
|
+
//
|
|
185
|
+
// Two things matter on a real Windows desktop:
|
|
186
|
+
// * `[Console]::Out.Write` encodes with the console's code page (936 on a
|
|
187
|
+
// Chinese Windows), so a password typed in Chinese arrived as mojibake
|
|
188
|
+
// and keyed a store no other machine could open. The value leaves as
|
|
189
|
+
// UTF-8 bytes through the raw stream instead.
|
|
190
|
+
// * Any error (a policy that forbids Add-Type, WinForms that will not
|
|
191
|
+
// load) used to make PowerShell exit 1, which reads as "the user
|
|
192
|
+
// cancelled": the host was told not to retry. The scripts trap into
|
|
193
|
+
// exit 2, and an exit 1 that printed an error counts the same.
|
|
170
194
|
const PREAMBLE: &str = r#"
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
$f
|
|
175
|
-
$f.
|
|
176
|
-
$
|
|
177
|
-
$
|
|
178
|
-
$
|
|
179
|
-
$
|
|
180
|
-
$
|
|
181
|
-
|
|
182
|
-
$
|
|
183
|
-
$
|
|
184
|
-
$
|
|
185
|
-
$
|
|
186
|
-
$
|
|
187
|
-
$
|
|
188
|
-
$
|
|
189
|
-
|
|
195
|
+
$ErrorActionPreference = 'Stop'
|
|
196
|
+
try {
|
|
197
|
+
Add-Type -AssemblyName System.Windows.Forms, System.Drawing
|
|
198
|
+
$f = New-Object System.Windows.Forms.Form
|
|
199
|
+
$f.Text = $env:AI_VAULT_DLG_TITLE
|
|
200
|
+
$f.Width = 480; $f.Height = 200; $f.StartPosition = 'CenterScreen'
|
|
201
|
+
$f.TopMost = $true; $f.FormBorderStyle = 'FixedDialog'; $f.MaximizeBox = $false
|
|
202
|
+
$lbl = New-Object System.Windows.Forms.Label
|
|
203
|
+
$lbl.Text = $env:AI_VAULT_DLG_TEXT; $lbl.Left = 12; $lbl.Top = 12; $lbl.Width = 440; $lbl.Height = 60
|
|
204
|
+
$f.Controls.Add($lbl)
|
|
205
|
+
$box = New-Object System.Windows.Forms.TextBox
|
|
206
|
+
$box.Left = 12; $box.Top = 80; $box.Width = 440
|
|
207
|
+
if ($env:AI_VAULT_DLG_SECRET -eq '1') { $box.UseSystemPasswordChar = $true }
|
|
208
|
+
$f.Controls.Add($box)
|
|
209
|
+
$ok = New-Object System.Windows.Forms.Button
|
|
210
|
+
$ok.Text = 'OK'; $ok.DialogResult = 'OK'; $ok.Left = 280; $ok.Top = 115; $f.AcceptButton = $ok
|
|
211
|
+
$cancel = New-Object System.Windows.Forms.Button
|
|
212
|
+
$cancel.Text = $env:AI_VAULT_DLG_CANCEL; $cancel.DialogResult = 'Cancel'; $cancel.Left = 370; $cancel.Top = 115; $f.CancelButton = $cancel
|
|
213
|
+
$f.Controls.Add($ok); $f.Controls.Add($cancel)
|
|
214
|
+
$f.Add_Shown({ $box.Focus() })
|
|
215
|
+
if ($f.ShowDialog() -eq 'OK') {
|
|
216
|
+
$bytes = [System.Text.Encoding]::UTF8.GetBytes($box.Text)
|
|
217
|
+
$stdout = [Console]::OpenStandardOutput()
|
|
218
|
+
$stdout.Write($bytes, 0, $bytes.Length); $stdout.Flush()
|
|
219
|
+
exit 0
|
|
220
|
+
}
|
|
221
|
+
exit 1
|
|
222
|
+
} catch {
|
|
223
|
+
[Console]::Error.Write($_)
|
|
224
|
+
exit 2
|
|
225
|
+
}
|
|
190
226
|
"#;
|
|
191
227
|
|
|
228
|
+
// A MessageBox has no top-most flag of its own, so it is owned by an
|
|
229
|
+
// invisible one that has: an approval hiding behind other windows reads as
|
|
230
|
+
// a hang. The default button stays "No".
|
|
192
231
|
const CONFIRM: &str = r#"
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
232
|
+
$ErrorActionPreference = 'Stop'
|
|
233
|
+
try {
|
|
234
|
+
Add-Type -AssemblyName System.Windows.Forms, System.Drawing
|
|
235
|
+
$owner = New-Object System.Windows.Forms.Form
|
|
236
|
+
$owner.TopMost = $true; $owner.Opacity = 0; $owner.ShowInTaskbar = $false
|
|
237
|
+
$owner.StartPosition = 'CenterScreen'; $owner.Width = 1; $owner.Height = 1
|
|
238
|
+
$owner.Show()
|
|
239
|
+
$r = [System.Windows.Forms.MessageBox]::Show($owner, $env:AI_VAULT_DLG_TEXT, $env:AI_VAULT_DLG_TITLE, 'YesNo', 'Warning', 'Button2')
|
|
240
|
+
$owner.Close()
|
|
241
|
+
if ($r -eq 'Yes') { exit 0 }
|
|
242
|
+
exit 1
|
|
243
|
+
} catch {
|
|
244
|
+
[Console]::Error.Write($_)
|
|
245
|
+
exit 2
|
|
246
|
+
}
|
|
197
247
|
"#;
|
|
198
248
|
|
|
249
|
+
/// Windows PowerShell by its full path. The window takes the master
|
|
250
|
+
/// password, so the bare name is not left for a PATH entry or a working
|
|
251
|
+
/// directory to answer to.
|
|
252
|
+
fn powershell_exe() -> PathBuf {
|
|
253
|
+
std::env::var_os("SystemRoot")
|
|
254
|
+
.map(PathBuf::from)
|
|
255
|
+
.map(|root| root.join("System32").join("WindowsPowerShell").join("v1.0").join("powershell.exe"))
|
|
256
|
+
.unwrap_or_else(|| PathBuf::from("powershell"))
|
|
257
|
+
}
|
|
258
|
+
|
|
199
259
|
struct Out {
|
|
200
260
|
spawned: bool,
|
|
201
261
|
code: i32,
|
|
@@ -203,8 +263,20 @@ if ($r -eq 'Yes') { exit 0 } else { exit 1 }
|
|
|
203
263
|
stderr: String,
|
|
204
264
|
}
|
|
205
265
|
|
|
266
|
+
/// Read a pipe to its end on its own thread: a chatty start must not block
|
|
267
|
+
/// on a full pipe while the window is open.
|
|
268
|
+
fn drain<R: Read + Send + 'static>(pipe: Option<R>) -> JoinHandle<String> {
|
|
269
|
+
std::thread::spawn(move || {
|
|
270
|
+
let mut bytes = Vec::new();
|
|
271
|
+
if let Some(mut pipe) = pipe {
|
|
272
|
+
let _ = pipe.read_to_end(&mut bytes);
|
|
273
|
+
}
|
|
274
|
+
String::from_utf8_lossy(&bytes).into_owned()
|
|
275
|
+
})
|
|
276
|
+
}
|
|
277
|
+
|
|
206
278
|
fn powershell(script: &str, title: &str, text: &str, secret: bool) -> Out {
|
|
207
|
-
let mut cmd = Command::new(
|
|
279
|
+
let mut cmd = Command::new(powershell_exe());
|
|
208
280
|
cmd.args(["-NoProfile", "-NonInteractive", "-STA", "-Command", script])
|
|
209
281
|
.env("AI_VAULT_DLG_TITLE", title)
|
|
210
282
|
.env("AI_VAULT_DLG_TEXT", text)
|
|
@@ -213,20 +285,46 @@ if ($r -eq 'Yes') { exit 0 } else { exit 1 }
|
|
|
213
285
|
.stdin(Stdio::null())
|
|
214
286
|
.stdout(Stdio::piped())
|
|
215
287
|
.stderr(Stdio::piped());
|
|
216
|
-
let
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
Err(_) =>
|
|
288
|
+
let unspawned = || Out {
|
|
289
|
+
spawned: false,
|
|
290
|
+
code: 127,
|
|
291
|
+
stdout: String::new(),
|
|
292
|
+
stderr: String::new(),
|
|
293
|
+
};
|
|
294
|
+
let mut child = match cmd.spawn() {
|
|
295
|
+
Ok(child) => child,
|
|
296
|
+
Err(_) => return unspawned(),
|
|
297
|
+
};
|
|
298
|
+
let stdout = drain(child.stdout.take());
|
|
299
|
+
let stderr = drain(child.stderr.take());
|
|
300
|
+
// A window nobody answers must not hold the caller forever, exactly as
|
|
301
|
+
// zenity's --timeout does not: after DIALOG_SECONDS it is ours to close,
|
|
302
|
+
// and closing it is a cancel. (Windows has no `giving up after`.)
|
|
303
|
+
let deadline = Instant::now() + Duration::from_secs(DIALOG_SECONDS as u64);
|
|
304
|
+
let status = loop {
|
|
305
|
+
match child.try_wait() {
|
|
306
|
+
Ok(Some(status)) => break Some(status),
|
|
307
|
+
Ok(None) if Instant::now() < deadline => std::thread::sleep(Duration::from_millis(100)),
|
|
308
|
+
_ => {
|
|
309
|
+
let _ = child.kill();
|
|
310
|
+
let _ = child.wait();
|
|
311
|
+
break None;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
let stdout = stdout.join().unwrap_or_default();
|
|
316
|
+
let stderr = stderr.join().unwrap_or_default();
|
|
317
|
+
match status {
|
|
318
|
+
None => Out { spawned: true, code: 1, stdout, stderr },
|
|
319
|
+
Some(status) => Out { spawned: true, code: status.code().unwrap_or(-1), stdout, stderr },
|
|
225
320
|
}
|
|
226
321
|
}
|
|
227
322
|
|
|
323
|
+
/// Exit 1 with nothing on stderr is the user's cancel. Anything else means
|
|
324
|
+
/// no answer came out of a window: our own exit 2, a script PowerShell
|
|
325
|
+
/// could not even parse (exit 1, with the error on stderr), or a crash.
|
|
228
326
|
fn failed(out: &Out) -> bool {
|
|
229
|
-
!out.spawned || (out.code != 0 && out.code != 1)
|
|
327
|
+
!out.spawned || (out.code != 0 && out.code != 1) || (out.code == 1 && !out.stderr.trim().is_empty())
|
|
230
328
|
}
|
|
231
329
|
|
|
232
330
|
pub fn prompt_secret(title: &str, label: &str) -> Answer<String> {
|
|
@@ -258,6 +356,53 @@ if ($r -eq 'Yes') { exit 0 } else { exit 1 }
|
|
|
258
356
|
}
|
|
259
357
|
Answer::Value(out.code == 0)
|
|
260
358
|
}
|
|
359
|
+
|
|
360
|
+
/// Whether this process may show a window at all. Only the interactive
|
|
361
|
+
/// session's window station (`WinSta0`) is visible; a service, a scheduled
|
|
362
|
+
/// task that runs without a logged-on user, or an sshd session gets a
|
|
363
|
+
/// `Service-0x0-…` station instead, where a dialog would open onto a
|
|
364
|
+
/// desktop nobody sees and never be answered.
|
|
365
|
+
pub fn has_display() -> bool {
|
|
366
|
+
// USEROBJECTFLAGS, as user32 lays it out: two BOOLs and a DWORD.
|
|
367
|
+
#[repr(C)]
|
|
368
|
+
#[derive(Default)]
|
|
369
|
+
struct UserObjectFlags {
|
|
370
|
+
f_inherit: i32,
|
|
371
|
+
f_reserved: i32,
|
|
372
|
+
dw_flags: u32,
|
|
373
|
+
}
|
|
374
|
+
const UOI_FLAGS: i32 = 1;
|
|
375
|
+
const WSF_VISIBLE: u32 = 0x0001;
|
|
376
|
+
#[link(name = "user32")]
|
|
377
|
+
extern "system" {
|
|
378
|
+
fn GetProcessWindowStation() -> *mut core::ffi::c_void;
|
|
379
|
+
fn GetUserObjectInformationW(
|
|
380
|
+
hobj: *mut core::ffi::c_void,
|
|
381
|
+
index: i32,
|
|
382
|
+
info: *mut core::ffi::c_void,
|
|
383
|
+
len: u32,
|
|
384
|
+
needed: *mut u32,
|
|
385
|
+
) -> i32;
|
|
386
|
+
}
|
|
387
|
+
// SAFETY: two Win32 queries against the calling process's own window
|
|
388
|
+
// station; every pointer is either handed out by the OS or a live local.
|
|
389
|
+
unsafe {
|
|
390
|
+
let station = GetProcessWindowStation();
|
|
391
|
+
if station.is_null() {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
let mut flags = UserObjectFlags::default();
|
|
395
|
+
let mut needed: u32 = 0;
|
|
396
|
+
let ok = GetUserObjectInformationW(
|
|
397
|
+
station,
|
|
398
|
+
UOI_FLAGS,
|
|
399
|
+
&mut flags as *mut UserObjectFlags as *mut core::ffi::c_void,
|
|
400
|
+
std::mem::size_of::<UserObjectFlags>() as u32,
|
|
401
|
+
&mut needed,
|
|
402
|
+
);
|
|
403
|
+
ok != 0 && flags.dw_flags & WSF_VISIBLE != 0
|
|
404
|
+
}
|
|
405
|
+
}
|
|
261
406
|
}
|
|
262
407
|
|
|
263
408
|
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
|
|
@@ -532,7 +677,9 @@ mod tests {
|
|
|
532
677
|
assert!(cut.ends_with('…'));
|
|
533
678
|
}
|
|
534
679
|
|
|
680
|
+
// The rest of this file's helpers exist only where zenity does.
|
|
535
681
|
#[test]
|
|
682
|
+
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
|
|
536
683
|
fn gtk_diagnostics_are_not_failures() {
|
|
537
684
|
assert!(is_gtk_diagnostic("(zenity:1234): Gtk-WARNING **: cannot open display"));
|
|
538
685
|
assert!(!is_gtk_diagnostic("zenity: command not found"));
|
|
@@ -540,6 +687,7 @@ mod tests {
|
|
|
540
687
|
}
|
|
541
688
|
|
|
542
689
|
#[test]
|
|
690
|
+
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
|
|
543
691
|
fn failed_spawn_and_dead_display_are_no_ui() {
|
|
544
692
|
let missing = Zenity { spawned: false, code: 127, stdout: String::new(), stderr: String::new() };
|
|
545
693
|
assert!(failed_to_open(&missing));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiaolikt/ai-vault",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
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.2",
|
|
37
|
+
"@xiaolikt/ai-vault-linux-arm64": "0.12.2",
|
|
38
|
+
"@xiaolikt/ai-vault-win32-x64": "0.12.2",
|
|
39
|
+
"@xiaolikt/ai-vault-darwin-arm64": "0.12.2",
|
|
40
|
+
"@xiaolikt/ai-vault-darwin-x64": "0.12.2"
|
|
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.2",
|
|
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.2"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@earendil-works/pi-coding-agent": "^1.5.0",
|