@xiaolikt/ai-vault 0.12.2 → 0.12.4
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 +12 -0
- package/README.zh.md +2 -0
- package/crates/ai-vault/Cargo.toml +1 -1
- package/crates/ai-vault/build.rs +82 -0
- package/crates/ai-vault/src/cli.rs +46 -5
- package/crates/ai-vault/src/dialog.rs +211 -168
- package/crates/ai-vault/windows/dialog.cs +579 -0
- package/package.json +6 -6
- package/packages/pi-ai-vault/package.json +2 -2
- package/packages/pi-ai-vault/src/bitwarden.ts +40 -15
- package/packages/pi-ai-vault/src/cli.ts +26 -3
- package/tests/windows.test.mjs +133 -65
package/Cargo.lock
CHANGED
package/README.md
CHANGED
|
@@ -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
|
@@ -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
|
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
//! Build steps for the one platform that needs a second binary.
|
|
2
|
+
//!
|
|
3
|
+
//! `crates/ai-vault/windows/dialog.cs` is the CLI's dialog program: a small
|
|
4
|
+
//! WinForms application that the Rust side starts and talks to over stdin and
|
|
5
|
+
//! stdout. Building it from the Rust build keeps it honest — the binary lands
|
|
6
|
+
//! beside `ai-vault.exe`, and `cargo build` is still all there is to do.
|
|
7
|
+
//!
|
|
8
|
+
//! Nothing here touches the Rust build when it cannot run: a host without the
|
|
9
|
+
//! C# compiler still builds `ai-vault.exe`, and the Windows dialogs fall back to
|
|
10
|
+
//! the PowerShell scripts in `dialog.rs` (slower, same windows).
|
|
11
|
+
|
|
12
|
+
use std::path::PathBuf;
|
|
13
|
+
use std::process::Command;
|
|
14
|
+
|
|
15
|
+
fn main() {
|
|
16
|
+
println!("cargo:rerun-if-changed=windows/dialog.cs");
|
|
17
|
+
|
|
18
|
+
// Only a Windows build has a dialog program; emit nothing anywhere else.
|
|
19
|
+
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let source = PathBuf::from("windows").join("dialog.cs");
|
|
24
|
+
let Some(out_dir) = std::env::var_os("OUT_DIR") else { return };
|
|
25
|
+
// OUT_DIR is <target>/<profile>/build/<pkg>-<hash>/out: four levels up is
|
|
26
|
+
// <target>/<profile>, the directory the binaries go in, which is where the
|
|
27
|
+
// CLI looks for it. (Nth is counted from zero, "out" being the first.)
|
|
28
|
+
let bin_dir = PathBuf::from(&out_dir)
|
|
29
|
+
.ancestors()
|
|
30
|
+
.nth(4)
|
|
31
|
+
.map(PathBuf::from)
|
|
32
|
+
.filter(|dir| dir.is_dir())
|
|
33
|
+
.unwrap_or_else(|| PathBuf::from(&out_dir));
|
|
34
|
+
let output = bin_dir.join("dialog.exe");
|
|
35
|
+
|
|
36
|
+
match compile(&source, &output) {
|
|
37
|
+
Ok(()) => {}
|
|
38
|
+
Err(why) => {
|
|
39
|
+
// The Linux and macOS builds never get here; a Windows host without
|
|
40
|
+
// csc does, and keeps working with the fallback.
|
|
41
|
+
println!("cargo:warning=the Windows dialog program was not built ({why}); the PowerShell dialogs will be used");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
fn compile(source: &PathBuf, output: &PathBuf) -> Result<(), String> {
|
|
47
|
+
let csc = std::env::var_os("CSC")
|
|
48
|
+
.map(PathBuf::from)
|
|
49
|
+
.or_else(|| {
|
|
50
|
+
std::env::var_os("SystemRoot").map(|root| {
|
|
51
|
+
let base = PathBuf::from(root);
|
|
52
|
+
// The C# 5 compiler that ships with the framework: enough for
|
|
53
|
+
// this file, and no SDK to install.
|
|
54
|
+
let path = base.join("Microsoft.NET").join("Framework64").join("v4.0.30319").join("csc.exe");
|
|
55
|
+
if path.is_file() {
|
|
56
|
+
path
|
|
57
|
+
} else {
|
|
58
|
+
base.join("Microsoft.NET").join("Framework").join("v4.0.30319").join("csc.exe")
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
.filter(|path| path.is_file())
|
|
63
|
+
.ok_or("no csc.exe (the .NET Framework C# compiler) on this machine")?;
|
|
64
|
+
|
|
65
|
+
if let Some(parent) = output.parent() {
|
|
66
|
+
let _ = std::fs::create_dir_all(parent);
|
|
67
|
+
}
|
|
68
|
+
let status = Command::new(&csc)
|
|
69
|
+
.arg("/nologo")
|
|
70
|
+
.arg("/target:winexe")
|
|
71
|
+
.arg("/optimize+")
|
|
72
|
+
.arg(format!("/out:{}", output.display()))
|
|
73
|
+
.arg("/r:System.Windows.Forms.dll")
|
|
74
|
+
.arg("/r:System.Drawing.dll")
|
|
75
|
+
.arg(source)
|
|
76
|
+
.status()
|
|
77
|
+
.map_err(|error| format!("cannot run {}: {error}", csc.display()))?;
|
|
78
|
+
if !status.success() {
|
|
79
|
+
return Err(format!("csc exited with {status}"));
|
|
80
|
+
}
|
|
81
|
+
Ok(())
|
|
82
|
+
}
|
|
@@ -476,8 +476,10 @@ fn read_approval() -> Result<bool, Fault> {
|
|
|
476
476
|
Ok(matches!(answer.as_str(), "y" | "yes" | "allow" | "允许" | "1" | "true"))
|
|
477
477
|
}
|
|
478
478
|
|
|
479
|
+
/// The master password, in a window that can show what was typed: a typo in it
|
|
480
|
+
/// is expensive.
|
|
479
481
|
fn ask_password(title: &str, label: &str) -> Result<String, Fault> {
|
|
480
|
-
match dialog::prompt_secret(title, label) {
|
|
482
|
+
match dialog::prompt_secret(title, label, true) {
|
|
481
483
|
Answer::Value(value) => Ok(value),
|
|
482
484
|
Answer::Cancelled => Err(Fault::Denied("cancelled: no password entered".into())),
|
|
483
485
|
Answer::NoUi => Err(Fault::NeedsUi("password")),
|
|
@@ -491,7 +493,7 @@ fn ask_password(title: &str, label: &str) -> Result<String, Fault> {
|
|
|
491
493
|
/// The field is reported in the error's text, which the host reads after the
|
|
492
494
|
/// `needs-ui: password` line.
|
|
493
495
|
fn ask_field_password(field: &str, title: &str, label: &str) -> Result<String, Fault> {
|
|
494
|
-
match dialog::prompt_secret(title, label) {
|
|
496
|
+
match dialog::prompt_secret(title, label, false) {
|
|
495
497
|
Answer::Value(value) => Ok(value),
|
|
496
498
|
Answer::Cancelled => Err(Fault::Denied("cancelled: no password entered".into())),
|
|
497
499
|
Answer::NoUi => Err(Fault::NeedsUiField(field.to_string())),
|
|
@@ -707,6 +709,39 @@ fn which(program: &str) -> bool {
|
|
|
707
709
|
})
|
|
708
710
|
}
|
|
709
711
|
|
|
712
|
+
/// What a master password must be, and a word of advice on what it should be.
|
|
713
|
+
/// One key derives the store's key, so its strength is the strength of the
|
|
714
|
+
/// whole store; the floor is eight characters, as it has always been.
|
|
715
|
+
fn check_master_password(password: &str) -> Result<(), Fault> {
|
|
716
|
+
let length = password.chars().count();
|
|
717
|
+
if length < 8 {
|
|
718
|
+
return Err(Fault::Usage(tr(
|
|
719
|
+
"the master password must be at least 8 characters",
|
|
720
|
+
"主密码至少需要 8 个字符",
|
|
721
|
+
).to_string()));
|
|
722
|
+
}
|
|
723
|
+
let classes = [
|
|
724
|
+
password.chars().any(|c| c.is_ascii_lowercase()),
|
|
725
|
+
password.chars().any(|c| c.is_ascii_uppercase()),
|
|
726
|
+
password.chars().any(|c| c.is_ascii_digit()),
|
|
727
|
+
password.chars().any(|c| !c.is_ascii_alphanumeric()),
|
|
728
|
+
]
|
|
729
|
+
.iter()
|
|
730
|
+
.filter(|present| **present)
|
|
731
|
+
.count();
|
|
732
|
+
let strong = length >= 16 || (length >= 12 && classes >= 3);
|
|
733
|
+
if !strong {
|
|
734
|
+
eprintln!(
|
|
735
|
+
"ai-vault: {}",
|
|
736
|
+
tr(
|
|
737
|
+
"advice: a passphrase of four unrelated words is both stronger and easier to remember than a short password.",
|
|
738
|
+
"建议:四个互不相关的词组成的长口令,比短短一个密码既更安全也更好记。",
|
|
739
|
+
)
|
|
740
|
+
);
|
|
741
|
+
}
|
|
742
|
+
Ok(())
|
|
743
|
+
}
|
|
744
|
+
|
|
710
745
|
fn init(paths: &Paths, out: &Out, password_stdin: bool, requester: &str, idle_min: Option<i64>) -> Outcome {
|
|
711
746
|
if paths.store().exists() {
|
|
712
747
|
return Err(Fault::Error(format!(
|
|
@@ -717,9 +752,15 @@ fn init(paths: &Paths, out: &Out, password_stdin: bool, requester: &str, idle_mi
|
|
|
717
752
|
let password = if password_stdin {
|
|
718
753
|
read_password()?
|
|
719
754
|
} else {
|
|
720
|
-
let first = ask_password(
|
|
721
|
-
|
|
722
|
-
|
|
755
|
+
let first = ask_password(
|
|
756
|
+
tr("ai-vault · set master password", "ai-vault · 创建主密码"),
|
|
757
|
+
tr(
|
|
758
|
+
"Choose a long passphrase, not a word: this one key protects every secret in the store.",
|
|
759
|
+
"请选一句足够长的口令,而不是一个单词:这一把钥匙保护库里所有密码。",
|
|
760
|
+
),
|
|
761
|
+
)?;
|
|
762
|
+
if let Err(fault) = check_master_password(&first) {
|
|
763
|
+
return Err(fault);
|
|
723
764
|
}
|
|
724
765
|
let again = ask_password(tr("ai-vault · confirm master password", "ai-vault · 确认主密码"), tr("type it again", "再输入一次"))?;
|
|
725
766
|
if again != first {
|