@xiaolikt/ai-vault 0.12.3 → 0.13.0
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 -0
- package/README.zh.md +11 -0
- package/crates/ai-vault/Cargo.toml +1 -1
- package/crates/ai-vault/build.rs +82 -0
- package/crates/ai-vault/src/cli.rs +55 -10
- package/crates/ai-vault/src/config.rs +6 -4
- package/crates/ai-vault/src/crypto.rs +3 -1
- package/crates/ai-vault/src/dialog.rs +214 -390
- package/crates/ai-vault/src/session.rs +13 -0
- package/crates/ai-vault/windows/dialog.cs +579 -0
- package/package.json +6 -6
- package/packages/pi-ai-vault/README.md +2 -0
- package/packages/pi-ai-vault/README.zh.md +2 -0
- 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 +89 -15
- package/packages/pi-ai-vault/src/settings.ts +1 -1
- package/test/cli.sh +19 -0
- package/tests/bitwarden-tools.test.mjs +4 -1
- package/tests/vault-cli.test.mjs +56 -0
- package/tests/windows.test.mjs +133 -79
package/Cargo.lock
CHANGED
package/README.md
CHANGED
|
@@ -315,6 +315,15 @@ When `ai-vault` asks for its master password is a per-machine setting
|
|
|
315
315
|
| `never` | never asks. The key lives in `~/.ai-vault/agent.session.json` (0600) and **reads open no window either** | handing the agent a set of "use freely" passwords |
|
|
316
316
|
| `time` | asks again N hours after the unlock (default 8, `--hours`) | long bounded tasks |
|
|
317
317
|
| `session` | once per session; dies with it (default) | everyday |
|
|
318
|
+
| `vault.confirm` | whether each read opens a confirm window **while the session is unlocked** (default **off**). The master password that opened the session is the approval — a window the model cannot answer for you — and every read is still audited entry by entry. `on` puts a second window on every read; turning it off costs the master password, turning it back on is free | `off` for everyday; `on` to see each request before it is answered |
|
|
319
|
+
|
|
320
|
+
**Why `session` no longer means "every tab asks".** Every pi/omp process on the
|
|
321
|
+
machine shares one store-wide host secret (`~/.ai-vault/.host`, 0600), so a
|
|
322
|
+
session opened in one process is usable in the next: a second herdr tab, a
|
|
323
|
+
subagent, a `/fork` — none of them asks again while an unlocked session
|
|
324
|
+
exists. The secret is protected by exactly what protects the store and its
|
|
325
|
+
wrap key, the user's home directory; a token found on disk is still refused
|
|
326
|
+
without it.
|
|
318
327
|
|
|
319
328
|
```bash
|
|
320
329
|
ai-vault mode # show
|
|
@@ -357,6 +366,22 @@ In the extension: `/vault settings`, `/vault settings bitwarden.import always`.
|
|
|
357
366
|
writes it after a successful master-password unlock, it is cleared when the
|
|
358
367
|
policy goes back to `session`, and `/bw lock` clears it too.
|
|
359
368
|
|
|
369
|
+
### Where the settings live
|
|
370
|
+
|
|
371
|
+
Not in a file. They are inside `store.json`, sealed under the same key as the
|
|
372
|
+
passwords, so reading or changing them needs the store's key — a password, or
|
|
373
|
+
a session opened with one. There is nothing to edit on disk: flipping a byte
|
|
374
|
+
of the store is a tamper and the whole store is refused. A plaintext
|
|
375
|
+
`config.json` from an older version is brought inside at the next unlock, but
|
|
376
|
+
only its harmless keys travel; `confirm = false` and `unlock = never` are not
|
|
377
|
+
taken from a file, so an edit made while the file was still plain text grants
|
|
378
|
+
nothing.
|
|
379
|
+
|
|
380
|
+
Every change that **lowers** protection costs the master password — `unlock =
|
|
381
|
+
never`, keeping the Bitwarden or Ente key on disk, importing Bitwarden hits
|
|
382
|
+
without asking. Turning `confirm` *on* is free; it is off by default, so
|
|
383
|
+
turning it off costs nothing until you have turned it on.
|
|
384
|
+
|
|
360
385
|
## Extension commands
|
|
361
386
|
|
|
362
387
|
```
|
|
@@ -523,6 +548,13 @@ may *use* passwords but cannot *get around you* to take them.
|
|
|
523
548
|
about stopping an agent that has been injected.
|
|
524
549
|
- `notes` appear only in `get` (after approval); `list` never prints them.
|
|
525
550
|
|
|
551
|
+
- **A token is bound to who signed it, and re-signed by its own signer.** A
|
|
552
|
+
session file records whether the host's secret or the store key signed it
|
|
553
|
+
and is checked with that key only, so a token created one way is refused —
|
|
554
|
+
not deleted — when presented the other way. And a later call never re-signs
|
|
555
|
+
it under the caller's key: a human's terminal session that the pi process
|
|
556
|
+
used once stays the human's.
|
|
557
|
+
|
|
526
558
|
### Known limits
|
|
527
559
|
|
|
528
560
|
- In `session` mode the model's bash **can** read a token file, but it does it
|
package/README.zh.md
CHANGED
|
@@ -254,6 +254,9 @@ vault_get "github"
|
|
|
254
254
|
| `never` | 永远不问。密钥写在 `~/.ai-vault/agent.session.json`(0600),**读取也不再弹确认窗** | 把一批「随便用」的密码交给 agent |
|
|
255
255
|
| `time` | 解锁后 N 小时(默认 8,`--hours` 可改)再问一次 | 有边界的长任务 |
|
|
256
256
|
| `session` | 每个会话问一次,会话结束就失效(默认) | 日常 |
|
|
257
|
+
| `vault.confirm` | 会话解锁期间,每次读取是否**再弹一次确认窗**(默认**关**)。打开会话的主密码就是授权——那个窗口模型替你答不了——每次读取仍逐条写审计。`on` 是每次读取都再弹一次;关要主密码,开回去免费 | 日常用 `off`;想每个请求在被回答前看一眼就 `on` |
|
|
258
|
+
|
|
259
|
+
**为什么 `session` 不再是「每个 tab 都要问」。** 机器上所有 pi/omp 进程共用一个库级 host secret(`~/.ai-vault/.host`,0600),所以一个进程开的会话在下一个进程里直接可用:第二个 herdr tab、子代理、`/fork`——只要还有解锁着的会话,谁都不会再要密码。这个 secret 和库、和 wrap key 受同一种保护(你的 home 目录);磁盘上捡到的令牌没有它照样被拒。
|
|
257
260
|
|
|
258
261
|
```bash
|
|
259
262
|
ai-vault mode # 看当前模式
|
|
@@ -288,6 +291,12 @@ ai-vault settings bitwarden.hours 24
|
|
|
288
291
|
|
|
289
292
|
`bw-session put/get/clear` 就是那个落盘密钥的读写口:插件在主密码解锁成功后写入,切回 `session` 模式时自动清掉,`/bw lock` 也会清掉。
|
|
290
293
|
|
|
294
|
+
### 设置存在哪里
|
|
295
|
+
|
|
296
|
+
不在文件里。设置在 `store.json` 里面,和密码用同一把 key 封在一起,所以读写设置都需要库的 key——主密码,或一个用它打开的会话。磁盘上没有东西可改:动 `store.json` 一个字节就是篡改,整个库会被拒。旧版留下的明文 `config.json` 会在下次解锁时带进去,但只带无害的键;`confirm = false` 和 `unlock = never` 不会从文件里来,所以趁文件还是明文时做的改动什么都换不到。
|
|
297
|
+
|
|
298
|
+
所有**降低**保护的改动都要主密码——`unlock = never`、把 Bitwarden / Ente 的密钥落盘、不询问就导入 Bitwarden 条目。把 `confirm` **打开**是免费的;它默认是关的,所以不动它就不花钱。
|
|
299
|
+
|
|
291
300
|
## 插件里的命令
|
|
292
301
|
|
|
293
302
|
```
|
|
@@ -393,6 +402,8 @@ pi-ai-vault 只是这套 CLI 的客户端,本身不保存 Ente 的任何密钥
|
|
|
393
402
|
- `bw_reveal` 默认关闭;擦洗只在值长度 ≥ 6 时生效,防不住网络外传和单向哈希——`bw_run` / `bw_inject` 的价值是值不进对话,不是防住被注入的 agent。
|
|
394
403
|
- `notes` 只在 `get`(授权之后)里出现,`list` 不输出它。
|
|
395
404
|
|
|
405
|
+
- **令牌绑定签名者,重签也只用原来的签名者。** 会话文件记着它是用宿主 secret 还是库 key 签的,只用那把 key 校验;换一种方式出示的令牌会被拒绝,但不会被删掉。之后的调用也绝不会用调用方的 key 重签它:一个人在终端开的会话被 pi 进程用过一次,仍然是那个人的。
|
|
406
|
+
|
|
396
407
|
### 已知边界
|
|
397
408
|
|
|
398
409
|
- `session` 模式下,模型的 bash **能**读到令牌文件,但拿到也没用:插件开的会话用宿主内存里的 secret 签名,bash 没有 secret,第一次用就会被判「文件被改」而作废(连 `list` 都做不了,还会把那个文件删掉)。只有**你在终端手敲** `ai-vault unlock` 开出来的会话(用 wrap key 签名)才能被同用户进程 `list`——那种会话本来就没有窗口可以绕,这是「同一用户」的固有暴露面。真正收紧要靠不同的用户或容器。
|
|
@@ -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())),
|
|
@@ -603,11 +605,15 @@ fn persist(paths: &Paths, session: &Session) {
|
|
|
603
605
|
let _ = if auto {
|
|
604
606
|
session::save_auto(paths, session)
|
|
605
607
|
} else {
|
|
606
|
-
//
|
|
607
|
-
//
|
|
608
|
-
match
|
|
609
|
-
Ok(
|
|
610
|
-
Err(e) =>
|
|
608
|
+
// Write it back under the key it was signed with, never the caller's
|
|
609
|
+
// own: the caller got here only by holding that key, so it has it.
|
|
610
|
+
let (host, wrap) = match signing_keys(paths) {
|
|
611
|
+
Ok(keys) => keys,
|
|
612
|
+
Err(e) => return drop(e),
|
|
613
|
+
};
|
|
614
|
+
match session.resigner(host, wrap) {
|
|
615
|
+
Some(signer) => session.save(paths, &signer),
|
|
616
|
+
None => Ok(()), // an unsigned file is not ours to re-sign; leave it
|
|
611
617
|
}
|
|
612
618
|
};
|
|
613
619
|
}
|
|
@@ -707,6 +713,39 @@ fn which(program: &str) -> bool {
|
|
|
707
713
|
})
|
|
708
714
|
}
|
|
709
715
|
|
|
716
|
+
/// What a master password must be, and a word of advice on what it should be.
|
|
717
|
+
/// One key derives the store's key, so its strength is the strength of the
|
|
718
|
+
/// whole store; the floor is eight characters, as it has always been.
|
|
719
|
+
fn check_master_password(password: &str) -> Result<(), Fault> {
|
|
720
|
+
let length = password.chars().count();
|
|
721
|
+
if length < 8 {
|
|
722
|
+
return Err(Fault::Usage(tr(
|
|
723
|
+
"the master password must be at least 8 characters",
|
|
724
|
+
"主密码至少需要 8 个字符",
|
|
725
|
+
).to_string()));
|
|
726
|
+
}
|
|
727
|
+
let classes = [
|
|
728
|
+
password.chars().any(|c| c.is_ascii_lowercase()),
|
|
729
|
+
password.chars().any(|c| c.is_ascii_uppercase()),
|
|
730
|
+
password.chars().any(|c| c.is_ascii_digit()),
|
|
731
|
+
password.chars().any(|c| !c.is_ascii_alphanumeric()),
|
|
732
|
+
]
|
|
733
|
+
.iter()
|
|
734
|
+
.filter(|present| **present)
|
|
735
|
+
.count();
|
|
736
|
+
let strong = length >= 16 || (length >= 12 && classes >= 3);
|
|
737
|
+
if !strong {
|
|
738
|
+
eprintln!(
|
|
739
|
+
"ai-vault: {}",
|
|
740
|
+
tr(
|
|
741
|
+
"advice: a passphrase of four unrelated words is both stronger and easier to remember than a short password.",
|
|
742
|
+
"建议:四个互不相关的词组成的长口令,比短短一个密码既更安全也更好记。",
|
|
743
|
+
)
|
|
744
|
+
);
|
|
745
|
+
}
|
|
746
|
+
Ok(())
|
|
747
|
+
}
|
|
748
|
+
|
|
710
749
|
fn init(paths: &Paths, out: &Out, password_stdin: bool, requester: &str, idle_min: Option<i64>) -> Outcome {
|
|
711
750
|
if paths.store().exists() {
|
|
712
751
|
return Err(Fault::Error(format!(
|
|
@@ -717,9 +756,15 @@ fn init(paths: &Paths, out: &Out, password_stdin: bool, requester: &str, idle_mi
|
|
|
717
756
|
let password = if password_stdin {
|
|
718
757
|
read_password()?
|
|
719
758
|
} else {
|
|
720
|
-
let first = ask_password(
|
|
721
|
-
|
|
722
|
-
|
|
759
|
+
let first = ask_password(
|
|
760
|
+
tr("ai-vault · set master password", "ai-vault · 创建主密码"),
|
|
761
|
+
tr(
|
|
762
|
+
"Choose a long passphrase, not a word: this one key protects every secret in the store.",
|
|
763
|
+
"请选一句足够长的口令,而不是一个单词:这一把钥匙保护库里所有密码。",
|
|
764
|
+
),
|
|
765
|
+
)?;
|
|
766
|
+
if let Err(fault) = check_master_password(&first) {
|
|
767
|
+
return Err(fault);
|
|
723
768
|
}
|
|
724
769
|
let again = ask_password(tr("ai-vault · confirm master password", "ai-vault · 确认主密码"), tr("type it again", "再输入一次"))?;
|
|
725
770
|
if again != first {
|
|
@@ -79,14 +79,16 @@ pub struct UnlockPolicy {
|
|
|
79
79
|
#[serde(default = "default_hours")]
|
|
80
80
|
pub hours: i64,
|
|
81
81
|
/// Whether each read of an entry opens a confirm window while the session
|
|
82
|
-
/// is unlocked.
|
|
83
|
-
/// is
|
|
82
|
+
/// is unlocked. Off by default: the master password that opened the
|
|
83
|
+
/// session is the approval (a window the model cannot answer for you),
|
|
84
|
+
/// and every read is still audited entry by entry. On means the second
|
|
85
|
+
/// window on every read, for someone who wants to see each request.
|
|
84
86
|
#[serde(default = "default_confirm")]
|
|
85
87
|
pub confirm: bool,
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
fn default_confirm() -> bool {
|
|
89
|
-
|
|
91
|
+
false
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
fn default_hours() -> i64 {
|
|
@@ -211,7 +213,7 @@ mod tests {
|
|
|
211
213
|
// A config written by the previous version had only `unlock`.
|
|
212
214
|
let parsed: Config = serde_json::from_str(r#"{"unlock":{"mode":"time","hours":4}}"#).unwrap();
|
|
213
215
|
assert_eq!(parsed.unlock.mode, UnlockMode::Time);
|
|
214
|
-
|
|
216
|
+
assert!(!parsed.unlock.confirm, "a config from before the switch reads as off: the unlock is the approval");
|
|
215
217
|
assert_eq!(parsed.bitwarden.import, ImportPolicy::Ask);
|
|
216
218
|
assert_eq!(parsed.bitwarden.store.hours, 8);
|
|
217
219
|
}
|
|
@@ -312,7 +312,9 @@ mod tests {
|
|
|
312
312
|
let v1 = StoreFile { v: 1, salt: salt.iter().map(|b| format!("{b:02x}")).collect(), kdf: Some(kdf), ct: base64::engine::general_purpose::STANDARD.encode(blob) };
|
|
313
313
|
let (payload, _) = open_with_passphrase(&v1, "pw").unwrap();
|
|
314
314
|
assert_eq!(payload.items[0].name, "GitHub");
|
|
315
|
-
|
|
315
|
+
// A store from before the switch carries no `confirm`; it reads as the
|
|
316
|
+
// default, which is off: the unlock is the approval.
|
|
317
|
+
assert!(!payload.config.unlock.confirm);
|
|
316
318
|
}
|
|
317
319
|
|
|
318
320
|
#[test]
|