@xiaolikt/ai-vault 0.9.0 → 0.10.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 +122 -4
- package/README.md +364 -222
- package/README.zh.md +388 -0
- package/bin/ai-vault.cjs +6 -0
- package/crates/ai-vault/Cargo.toml +2 -3
- package/crates/ai-vault/src/audit.rs +4 -6
- package/crates/ai-vault/src/cli.rs +56 -41
- package/crates/ai-vault/src/crypto.rs +4 -11
- package/crates/ai-vault/src/dialog.rs +294 -9
- package/crates/ai-vault/src/i18n.rs +56 -0
- package/crates/ai-vault/src/main.rs +2 -0
- package/crates/ai-vault/src/paths.rs +30 -7
- package/crates/ai-vault/src/perms.rs +54 -0
- package/crates/ai-vault/src/sealed.rs +3 -4
- package/crates/ai-vault/src/session.rs +9 -21
- package/package.json +5 -3
- package/packages/pi-ai-vault/README.md +40 -45
- package/packages/pi-ai-vault/README.zh.md +84 -0
- package/packages/pi-ai-vault/package.json +5 -4
- package/packages/pi-ai-vault/src/bitwarden.ts +2 -1
- package/packages/pi-ai-vault/src/cli.ts +17 -7
- package/packages/pi-ai-vault/src/ente.ts +4 -3
- package/packages/pi-ai-vault/src/i18n.ts +31 -0
- package/packages/pi-ai-vault/src/index.ts +77 -76
- package/packages/pi-ai-vault/src/prompt.ts +3 -2
- package/test/cli.sh +6 -4
- package/test/npm.sh +14 -1
- package/tests/mocks/bin/zenity +7 -2
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//! User-facing strings, English by default, Chinese with `AI_VAULT_LANG=zh`
|
|
2
|
+
//! (or a `zh_*` locale). Rust-side texts: dialogs, prompts, notices, errors.
|
|
3
|
+
//!
|
|
4
|
+
//! The rule: a message that a human reads is English unless they asked for
|
|
5
|
+
//! Chinese. Strings that a *host* parses (exit codes, `needs-ui:`,
|
|
6
|
+
//! `no such entry`, the JSON keys) never change.
|
|
7
|
+
|
|
8
|
+
use std::sync::OnceLock;
|
|
9
|
+
|
|
10
|
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
11
|
+
pub enum Lang {
|
|
12
|
+
En,
|
|
13
|
+
Zh,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static LANG: OnceLock<Lang> = OnceLock::new();
|
|
17
|
+
|
|
18
|
+
pub fn lang() -> Lang {
|
|
19
|
+
*LANG.get_or_init(detect)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
fn detect() -> Lang {
|
|
23
|
+
let explicit = std::env::var("AI_VAULT_LANG").unwrap_or_default().to_lowercase();
|
|
24
|
+
if explicit.starts_with("zh") {
|
|
25
|
+
return Lang::Zh;
|
|
26
|
+
}
|
|
27
|
+
if explicit == "en" || !explicit.is_empty() {
|
|
28
|
+
return Lang::En;
|
|
29
|
+
}
|
|
30
|
+
let locale = ["LC_ALL", "LC_MESSAGES", "LANG"]
|
|
31
|
+
.iter()
|
|
32
|
+
.find_map(|name| std::env::var(name).ok())
|
|
33
|
+
.unwrap_or_default()
|
|
34
|
+
.to_lowercase();
|
|
35
|
+
if locale.starts_with("zh") {
|
|
36
|
+
Lang::Zh
|
|
37
|
+
} else {
|
|
38
|
+
Lang::En
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/// Pick the English or the Chinese text.
|
|
43
|
+
pub fn tr(en: &'static str, zh: &'static str) -> &'static str {
|
|
44
|
+
match lang() {
|
|
45
|
+
Lang::En => en,
|
|
46
|
+
Lang::Zh => zh,
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/// The same with owned strings (formatted text).
|
|
51
|
+
pub fn tr_owned(en: String, zh: String) -> String {
|
|
52
|
+
match lang() {
|
|
53
|
+
Lang::En => en,
|
|
54
|
+
Lang::Zh => zh,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -53,14 +53,30 @@ impl Paths {
|
|
|
53
53
|
self.dir.join("store.lock")
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
/// Session tokens hold key material, so they prefer tmpfs when there is
|
|
57
|
-
/// they vanish at logout instead of lying on disk.
|
|
56
|
+
/// Session tokens hold key material, so they prefer a tmpfs when there is
|
|
57
|
+
/// one: they vanish at logout instead of lying on disk.
|
|
58
|
+
///
|
|
59
|
+
/// Linux $XDG_RUNTIME_DIR (a tmpfs)
|
|
60
|
+
/// macOS $TMPDIR (per-user, cleaned by the OS)
|
|
61
|
+
/// Windows %TEMP% (per-user)
|
|
58
62
|
pub fn sessions(&self) -> PathBuf {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
if self.dir != Paths::resolve(None).dir {
|
|
64
|
+
return self.dir.join("sessions");
|
|
65
|
+
}
|
|
66
|
+
#[cfg(target_os = "linux")]
|
|
67
|
+
{
|
|
68
|
+
if let Some(runtime) = env::var_os("XDG_RUNTIME_DIR").filter(|v| !v.is_empty()) {
|
|
69
|
+
return PathBuf::from(runtime).join("ai-vault").join("sessions");
|
|
62
70
|
}
|
|
63
|
-
|
|
71
|
+
return self.dir.join("sessions");
|
|
72
|
+
}
|
|
73
|
+
#[cfg(any(target_os = "macos", target_os = "windows"))]
|
|
74
|
+
{
|
|
75
|
+
env::temp_dir().join("ai-vault").join("sessions")
|
|
76
|
+
}
|
|
77
|
+
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
|
|
78
|
+
{
|
|
79
|
+
self.dir.join("sessions")
|
|
64
80
|
}
|
|
65
81
|
}
|
|
66
82
|
|
|
@@ -70,5 +86,12 @@ impl Paths {
|
|
|
70
86
|
}
|
|
71
87
|
|
|
72
88
|
pub fn home() -> PathBuf {
|
|
73
|
-
|
|
89
|
+
#[cfg(windows)]
|
|
90
|
+
let key = "USERPROFILE";
|
|
91
|
+
#[cfg(not(windows))]
|
|
92
|
+
let key = "HOME";
|
|
93
|
+
env::var_os(key)
|
|
94
|
+
.map(PathBuf::from)
|
|
95
|
+
.or_else(|| env::var_os("HOME").map(PathBuf::from))
|
|
96
|
+
.unwrap_or_else(|| Path::new(".").to_path_buf())
|
|
74
97
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//! File and directory permissions, per platform.
|
|
2
|
+
//!
|
|
3
|
+
//! On Unix a secret file is 0600 and its directory 0700. Windows has no mode
|
|
4
|
+
//! bits: a file under the user's profile is protected by the profile's ACL,
|
|
5
|
+
//! which is why the store lives in `%USERPROFILE%\.ai-vault` and nothing else
|
|
6
|
+
//! is done there. The helpers are no-ops that keep the call sites honest.
|
|
7
|
+
|
|
8
|
+
use std::fs::OpenOptions;
|
|
9
|
+
use std::path::Path;
|
|
10
|
+
|
|
11
|
+
/// Open a new file that only this user can read, where the OS has such a thing.
|
|
12
|
+
pub fn open_private(path: &Path) -> std::io::Result<std::fs::File> {
|
|
13
|
+
let mut options = OpenOptions::new();
|
|
14
|
+
options.write(true).create_new(true);
|
|
15
|
+
#[cfg(unix)]
|
|
16
|
+
{
|
|
17
|
+
use std::os::unix::fs::OpenOptionsExt;
|
|
18
|
+
options.mode(0o600);
|
|
19
|
+
}
|
|
20
|
+
options.open(path)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/// Narrow an existing file to the owner, best effort.
|
|
24
|
+
pub fn restrict_file(path: &Path) {
|
|
25
|
+
#[cfg(unix)]
|
|
26
|
+
{
|
|
27
|
+
use std::os::unix::fs::PermissionsExt;
|
|
28
|
+
let _ = std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o600));
|
|
29
|
+
}
|
|
30
|
+
#[cfg(not(unix))]
|
|
31
|
+
{
|
|
32
|
+
let _ = path;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/// Narrow a directory to the owner, best effort.
|
|
37
|
+
pub fn restrict_dir(path: &Path) {
|
|
38
|
+
#[cfg(unix)]
|
|
39
|
+
{
|
|
40
|
+
use std::os::unix::fs::PermissionsExt;
|
|
41
|
+
let _ = std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o700));
|
|
42
|
+
}
|
|
43
|
+
#[cfg(not(unix))]
|
|
44
|
+
{
|
|
45
|
+
let _ = path;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/// Best-effort fsync of a directory entry, where the platform allows it.
|
|
50
|
+
pub fn sync_dir(dir: &Path) {
|
|
51
|
+
if let Ok(handle) = std::fs::File::open(dir) {
|
|
52
|
+
let _ = handle.sync_all();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
//! unless `bw-session get` is asked for it.
|
|
10
10
|
|
|
11
11
|
use std::fs;
|
|
12
|
-
use std::os::unix::fs::PermissionsExt;
|
|
13
12
|
|
|
14
13
|
use serde::{Deserialize, Serialize};
|
|
15
14
|
|
|
@@ -72,9 +71,9 @@ fn wrap_key(paths: &Paths) -> Result<crypto::Key, String> {
|
|
|
72
71
|
}
|
|
73
72
|
let fresh = crypto::random_bytes::<32>();
|
|
74
73
|
fs::create_dir_all(&paths.dir).map_err(|e| format!("cannot create {}: {e}", paths.dir.display()))?;
|
|
75
|
-
|
|
74
|
+
crate::perms::restrict_dir(&paths.dir);
|
|
76
75
|
crypto::write_atomic(&path, &fresh)?;
|
|
77
|
-
|
|
76
|
+
crate::perms::restrict_file(&path);
|
|
78
77
|
Ok(crypto::Key::new(fresh))
|
|
79
78
|
}
|
|
80
79
|
|
|
@@ -149,7 +148,7 @@ pub fn save(paths: &Paths, kind: Kind, secret: &str) -> Result<Option<i64>, Stri
|
|
|
149
148
|
let bytes = serde_json::to_vec(&stored).map_err(|e| format!("cannot serialize session: {e}"))?;
|
|
150
149
|
let path = paths.dir.join(kind.file());
|
|
151
150
|
crypto::write_atomic(&path, &bytes)?;
|
|
152
|
-
|
|
151
|
+
crate::perms::restrict_file(&path);
|
|
153
152
|
Ok(expires_at)
|
|
154
153
|
}
|
|
155
154
|
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
|
|
17
17
|
use std::collections::BTreeMap;
|
|
18
18
|
use std::fs;
|
|
19
|
-
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
|
|
20
19
|
|
|
21
20
|
use base64::engine::general_purpose::STANDARD as B64;
|
|
22
21
|
use base64::Engine as _;
|
|
@@ -158,7 +157,7 @@ impl Session {
|
|
|
158
157
|
signed.sign(host_secret);
|
|
159
158
|
let dir = paths.sessions();
|
|
160
159
|
fs::create_dir_all(&dir).map_err(|e| format!("cannot create {}: {e}", dir.display()))?;
|
|
161
|
-
|
|
160
|
+
crate::perms::restrict_dir(&dir);
|
|
162
161
|
let text = serde_json::to_vec(&signed).map_err(|e| format!("cannot serialize session: {e}"))?;
|
|
163
162
|
crypto::write_atomic(&paths.session_file(&signed.token), &text)
|
|
164
163
|
}
|
|
@@ -277,7 +276,7 @@ pub fn load_auto(paths: &Paths) -> Result<Option<Session>, String> {
|
|
|
277
276
|
|
|
278
277
|
pub fn save_auto(paths: &Paths, session: &Session) -> Result<(), String> {
|
|
279
278
|
fs::create_dir_all(&paths.dir).map_err(|e| format!("cannot create {}: {e}", paths.dir.display()))?;
|
|
280
|
-
|
|
279
|
+
crate::perms::restrict_dir(&paths.dir);
|
|
281
280
|
let bytes = serde_json::to_vec(session).map_err(|e| format!("cannot serialize session: {e}"))?;
|
|
282
281
|
crypto::write_atomic(&paths.auto_session(), &bytes)
|
|
283
282
|
}
|
|
@@ -294,8 +293,8 @@ pub fn ensure_session_dir(paths: &Paths) -> Result<(), String> {
|
|
|
294
293
|
fs::create_dir_all(&paths.dir).map_err(|e| format!("cannot create {}: {e}", paths.dir.display()))?;
|
|
295
294
|
let dir = paths.sessions();
|
|
296
295
|
fs::create_dir_all(&dir).map_err(|e| format!("cannot create {}: {e}", dir.display()))?;
|
|
297
|
-
|
|
298
|
-
|
|
296
|
+
crate::perms::restrict_dir(&dir);
|
|
297
|
+
crate::perms::restrict_dir(&paths.dir);
|
|
299
298
|
Ok(())
|
|
300
299
|
}
|
|
301
300
|
|
|
@@ -314,30 +313,19 @@ impl StoreLock {
|
|
|
314
313
|
.create(true)
|
|
315
314
|
.read(true)
|
|
316
315
|
.write(true)
|
|
317
|
-
.mode(0o600)
|
|
318
316
|
.open(&path)
|
|
319
317
|
.map_err(|e| format!("cannot open {}: {e}", path.display()))?;
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
if rc != 0 {
|
|
325
|
-
return Err(format!("cannot lock {}: {}", path.display(), std::io::Error::last_os_error()));
|
|
326
|
-
}
|
|
327
|
-
}
|
|
318
|
+
crate::perms::restrict_file(&path);
|
|
319
|
+
// fs4 takes an OS lock on Unix (flock), Windows (LockFileEx) and macOS.
|
|
320
|
+
<fs::File as fs4::fs_std::FileExt>::lock_exclusive(&file)
|
|
321
|
+
.map_err(|e| format!("cannot lock {}: {e}", path.display()))?;
|
|
328
322
|
Ok(StoreLock { file, path })
|
|
329
323
|
}
|
|
330
324
|
}
|
|
331
325
|
|
|
332
326
|
impl Drop for StoreLock {
|
|
333
327
|
fn drop(&mut self) {
|
|
334
|
-
|
|
335
|
-
{
|
|
336
|
-
use std::os::unix::io::AsRawFd;
|
|
337
|
-
unsafe {
|
|
338
|
-
libc::flock(self.file.as_raw_fd(), libc::LOCK_UN);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
328
|
+
let _ = <fs::File as fs4::fs_std::FileExt>::unlock(&self.file);
|
|
341
329
|
let _ = &self.path;
|
|
342
330
|
}
|
|
343
331
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiaolikt/ai-vault",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "One machine-wide encrypted secret store for AI coding agents: the ai-vault Rust CLI (npm-installable) plus the pi-ai-vault extension for pi and omp.",
|
|
3
|
+
"version": "0.10.0",
|
|
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",
|
|
7
7
|
"url": "git+https://github.com/xiaolikt/ai-vault.git"
|
|
@@ -33,7 +33,9 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"optionalDependencies": {
|
|
36
|
-
"@xiaolikt/ai-vault-linux-x64": "0.
|
|
36
|
+
"@xiaolikt/ai-vault-linux-x64": "0.10.0",
|
|
37
|
+
"@xiaolikt/ai-vault-linux-arm64": "0.10.0",
|
|
38
|
+
"@xiaolikt/ai-vault-win32-x64": "0.10.0"
|
|
37
39
|
},
|
|
38
40
|
"files": [
|
|
39
41
|
"bin",
|
|
@@ -1,82 +1,77 @@
|
|
|
1
1
|
# pi-ai-vault
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[中文版](README.zh.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The pi extension for [ai-vault](https://www.npmjs.com/package/@xiaolikt/ai-vault) — **omp installs the same package** (omp is a pi-compatible fork; the manifest and tool API are identical, and the only differences are feature-detected at runtime in `src/host.ts`).
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
It hands one machine-wide encrypted secret store to your agent: `~/.ai-vault`, shared by every agent on the machine. The extension does no cryptography itself; it only holds a session token.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
8
10
|
|
|
9
11
|
```bash
|
|
10
|
-
pi install npm:pi-ai-vault
|
|
11
|
-
omp plugin install npm:pi-ai-vault
|
|
12
|
+
pi install npm:pi-ai-vault # pi; brings the ai-vault CLI along
|
|
13
|
+
omp plugin install npm:pi-ai-vault # omp; the same package
|
|
12
14
|
```
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
Then, in that host's session:
|
|
15
17
|
|
|
16
18
|
```
|
|
17
19
|
/vault init
|
|
18
20
|
```
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
(A dialog asks for the master password, twice. With a desktop it is the CLI's own window; without one, the host's prompt.)
|
|
23
|
+
|
|
24
|
+
You can also install straight from the repository: `pi install git:github.com/xiaolikt/ai-vault`.
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
Do not install `pi-bitwarden` or `omp-vault` as well: they register the same `bw_*` / `vault_*` tools. Both are archived.
|
|
23
27
|
|
|
24
|
-
##
|
|
28
|
+
## Tools
|
|
25
29
|
|
|
26
|
-
|
|
|
30
|
+
| Tool | What it does | Model sees the secret? |
|
|
27
31
|
|---|---|---|
|
|
28
|
-
| `vault_list` |
|
|
29
|
-
| `vault_get` |
|
|
30
|
-
| `vault_add` |
|
|
31
|
-
| `vault_import` |
|
|
32
|
-
| `bw_list` / `bw_run` / `bw_clipboard` / `bw_reveal` |
|
|
33
|
-
| `bw_inject` |
|
|
34
|
-
| `ente_list` | Ente Auth
|
|
35
|
-
| `ente_code` |
|
|
32
|
+
| `vault_list` | local store metadata | no |
|
|
33
|
+
| `vault_get` | read one: local store first, then Bitwarden; a Bitwarden hit follows `bitwarden.import` (ask / import / read once) | yes, user-approved on the spot |
|
|
34
|
+
| `vault_add` | store one; the password is typed in a dialog | no |
|
|
35
|
+
| `vault_import` | copy Bitwarden logins into the local store (asks first) | no |
|
|
36
|
+
| `bw_list` / `bw_run` / `bw_clipboard` / `bw_reveal` | live Bitwarden through the `bw` CLI | no (`bw_reveal` excepted) |
|
|
37
|
+
| `bw_inject` | inject into the bash env (**pi only**; omp does not register it) | no |
|
|
38
|
+
| `ente_list` | Ente Auth entry metadata | no |
|
|
39
|
+
| `ente_code` | one current TOTP/Steam code, confirmed per call | yes, user-approved on the spot |
|
|
36
40
|
|
|
37
|
-
##
|
|
41
|
+
## Commands
|
|
38
42
|
|
|
39
43
|
```
|
|
40
44
|
/vault init | unlock | lock | status | list | add | remove
|
|
41
|
-
/vault
|
|
42
|
-
/vault
|
|
45
|
+
/vault mode [never|time|session] unlock policy (switching needs the master password)
|
|
46
|
+
/vault settings [key value] bitwarden.*, ente.*
|
|
47
|
+
/vault ente-key save Ente's ENTE_CLI_VAULT_KEY
|
|
48
|
+
/vault grant <name> [minutes] | revoke <name|all> | audit [n]
|
|
49
|
+
/vault import <bitwarden.json> | import-bw [search]
|
|
43
50
|
/bw status|unlock|lock|clear
|
|
44
51
|
```
|
|
45
52
|
|
|
46
|
-
##
|
|
53
|
+
## Unlock policies
|
|
47
54
|
|
|
48
|
-
|
|
55
|
+
When the local store asks for its master password is a per-machine setting (`/vault mode`, switching needs the password):
|
|
49
56
|
|
|
50
|
-
|
|
|
57
|
+
| Mode | Behaviour |
|
|
51
58
|
|---|---|
|
|
52
|
-
| `never` |
|
|
53
|
-
| `time` |
|
|
54
|
-
| `session` |
|
|
59
|
+
| `never` | never asks, and reads open no window — the "the agent may use these freely" passwords |
|
|
60
|
+
| `time` | asks again N hours after the unlock (default 8) |
|
|
61
|
+
| `session` | once per session, dies with it (default) |
|
|
55
62
|
|
|
56
|
-
`vault_get`
|
|
57
|
-
|
|
58
|
-
| `bitwarden.import` | 行为 |
|
|
59
|
-
|---|---|
|
|
60
|
-
| `ask`(默认) | 给你看这一条 → 读一次 → 问「导入 ai-vault / 只用这一次」 |
|
|
61
|
-
| `always` | 命中直接导入并返回,不开窗口 |
|
|
62
|
-
| `never` | 只读一次,永不写入本地库 |
|
|
63
|
+
`vault_get` searches Bitwarden on a local miss; a hit is shown to you, then read once, then — following `bitwarden.import` — offered for import into ai-vault (so it never touches Bitwarden again) or used just this once. So **only the passwords you approve for import ever enter ai-vault**.
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
Bitwarden's own master-password prompts follow their own switch (`bitwarden.unlock`), and Ente's keychain is bypassed by `ente.unlock` — see `/vault settings`.
|
|
65
66
|
|
|
66
67
|
## Ente
|
|
67
68
|
|
|
68
|
-
`ente` CLI
|
|
69
|
-
|
|
70
|
-
想完全免钥匙串:`ente vault key generate` → `/vault ente-key` 粘进去 → `/vault settings ente.unlock never`。密钥由 ai-vault 加密封存。详见仓库 README。
|
|
71
|
-
|
|
72
|
-
## 安全边界(一句话版)
|
|
73
|
-
|
|
74
|
-
模型的 `bash` 能找到会话令牌、能 `list`,但**签不出读取确认**(签名密钥只在插件进程内存里)、**改不了令牌文件**(带 HMAC,改了就作废)、**免费拿不到 `grant`**(要主密码)。详见仓库 README「安全」一节。
|
|
69
|
+
The `ente` CLI logs in once (`ente account login --app auth`); the extension is only its client: `ente_list` is metadata, `ente_code` confirms every time.
|
|
75
70
|
|
|
76
|
-
|
|
71
|
+
To skip the keychain entirely: `ente vault key generate` → `/vault ente-key` → `/vault settings ente.unlock never`. The key is sealed by ai-vault.
|
|
77
72
|
|
|
78
|
-
|
|
73
|
+
## Security boundary, in one paragraph
|
|
79
74
|
|
|
80
|
-
|
|
75
|
+
The model's `bash` can find a session token and even `list` with one you opened by hand — but it **cannot sign a read confirmation** (the signing secret lives only in the extension process), **cannot edit a token file** (HMAC'd; an edit voids it), and **cannot get a free `grant`** (that costs the master password). Full details in the repository README, *Security*.
|
|
81
76
|
|
|
82
77
|
MIT
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# pi-ai-vault
|
|
2
|
+
|
|
3
|
+
[English](README.md)
|
|
4
|
+
|
|
5
|
+
ai-vault 的 pi 扩展——**omp 也能直接装同一个包**(omp 是 pi 的兼容分支,清单和工具 API 一致;差别只在 `src/host.ts` 的运行时探测里)。
|
|
6
|
+
|
|
7
|
+
它把本地加密密码库交给 [`ai-vault`](https://www.npmjs.com/package/@xiaolikt/ai-vault) 这个 Rust CLI:一台电脑一个库(`~/.ai-vault`),所有 agent 共用。插件本身不做加解密,只持有会话令牌。
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pi install npm:pi-ai-vault # pi,自动带上 ai-vault CLI
|
|
13
|
+
omp plugin install npm:pi-ai-vault # omp,同一个包
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
然后在该宿主的会话里:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
/vault init
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
(弹窗设主密码,两次。有桌面就开 zenity,没有就退回宿主自己的输入框。)
|
|
23
|
+
|
|
24
|
+
不想用 npm 也可以从仓库装:`pi install git:github.com/xiaolikt/ai-vault`。
|
|
25
|
+
|
|
26
|
+
## 工具
|
|
27
|
+
|
|
28
|
+
| 工具 | 作用 | 模型看到密码? |
|
|
29
|
+
|---|---|---|
|
|
30
|
+
| `vault_list` | 本地库条目元数据 | 否 |
|
|
31
|
+
| `vault_get` | 读一条:**先本地库,再 Bitwarden**;Bitwarden 命中会问「读一次 / 导入 ai-vault」 | 是,用户当场允许 |
|
|
32
|
+
| `vault_add` | 存一条;密码由用户在弹出的窗口里输入 | 否 |
|
|
33
|
+
| `vault_import` | 把 Bitwarden 登录项抄进本地库(先确认) | 否 |
|
|
34
|
+
| `bw_list` / `bw_run` / `bw_clipboard` / `bw_reveal` | 在线 Bitwarden(`bw` CLI) | 否,`bw_reveal` 除外 |
|
|
35
|
+
| `bw_inject` | 注入 bash 环境(**仅 pi**,omp 不注册) | 否 |
|
|
36
|
+
| `ente_list` | Ente Auth 条目元数据 | 否 |
|
|
37
|
+
| `ente_code` | 当前 TOTP/Steam 验证码(每次确认) | 是,用户当场允许 |
|
|
38
|
+
|
|
39
|
+
## 命令
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
/vault init | unlock | lock | status | list | add | remove
|
|
43
|
+
/vault grant <名称> [分钟] | revoke <名称|all> | audit [n]
|
|
44
|
+
/vault import <bitwarden.json> | import-bw [搜索词]
|
|
45
|
+
/bw status|unlock|lock|clear
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 解锁模式
|
|
49
|
+
|
|
50
|
+
本地库什么时候要主密码,由这台机器的模式决定(`/vault mode`,切换要主密码):
|
|
51
|
+
|
|
52
|
+
| 模式 | 行为 |
|
|
53
|
+
|---|---|
|
|
54
|
+
| `never` | 永远不问,读取也不弹确认窗——「agent 可以自由使用」的那批密码 |
|
|
55
|
+
| `time` | 解锁后 N 小时(默认 8)再问一次 |
|
|
56
|
+
| `session` | 每个会话一次,会话结束失效(默认) |
|
|
57
|
+
|
|
58
|
+
`vault_get` 找不到本地条目时会去 Bitwarden 搜;命中后按 `bitwarden.import` 处理:
|
|
59
|
+
|
|
60
|
+
| `bitwarden.import` | 行为 |
|
|
61
|
+
|---|---|
|
|
62
|
+
| `ask`(默认) | 给你看这一条 → 读一次 → 问「导入 ai-vault / 只用这一次」 |
|
|
63
|
+
| `always` | 命中直接导入并返回,不开窗口 |
|
|
64
|
+
| `never` | 只读一次,永不写入本地库 |
|
|
65
|
+
|
|
66
|
+
所以默认情况下 **只有你同意导入的密码才会进 ai-vault**。Bitwarden 自己的主密码请求频率也有单独设置(`bitwarden.unlock`:`never` / `time` / `session`),用 `/vault settings` 查看和修改。
|
|
67
|
+
|
|
68
|
+
## Ente
|
|
69
|
+
|
|
70
|
+
`ente` CLI 自己登录一次(`ente account login --app auth`),插件只是它的客户端:`ente_list` 只给元数据,`ente_code` 每次弹窗确认。
|
|
71
|
+
|
|
72
|
+
想完全免钥匙串:`ente vault key generate` → `/vault ente-key` 粘进去 → `/vault settings ente.unlock never`。密钥由 ai-vault 加密封存。详见仓库 README。
|
|
73
|
+
|
|
74
|
+
## 安全边界(一句话版)
|
|
75
|
+
|
|
76
|
+
模型的 `bash` 能找到会话令牌、能 `list`,但**签不出读取确认**(签名密钥只在插件进程内存里)、**改不了令牌文件**(带 HMAC,改了就作废)、**免费拿不到 `grant`**(要主密码)。详见仓库 README「安全」一节。
|
|
77
|
+
|
|
78
|
+
## 隔离
|
|
79
|
+
|
|
80
|
+
每个会话、每个子代理各自 `ai-vault unlock`,拿自己的令牌和读授权;父会话的解锁子代理继承不到。空闲 10 分钟自动失效,`/new`、`/fork`、退出会清掉本绑定的令牌。
|
|
81
|
+
|
|
82
|
+
完整说明(CLI 参数、退出码契约、Bitwarden 擦洗、审计、安全模型)见仓库 README:https://github.com/xiaolikt/ai-vault
|
|
83
|
+
|
|
84
|
+
MIT
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-ai-vault",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "pi extension for ai-vault: one machine-wide encrypted secret store
|
|
3
|
+
"version": "0.10.0",
|
|
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",
|
|
7
7
|
"url": "git+https://github.com/xiaolikt/ai-vault.git"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"security"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@xiaolikt/ai-vault": "0.
|
|
28
|
+
"@xiaolikt/ai-vault": "0.10.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@earendil-works/pi-coding-agent": "^1.5.0",
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
39
|
"src",
|
|
40
|
-
"README.md"
|
|
40
|
+
"README.md",
|
|
41
|
+
"README.zh.md"
|
|
41
42
|
],
|
|
42
43
|
"pi": {
|
|
43
44
|
"extensions": [
|
|
@@ -56,6 +56,7 @@ import { bitwardenLogins, filterLogins, type LoginDraft } from "./import-map.js"
|
|
|
56
56
|
import { onSessionLeave, sessionLabel, withTier } from "./host.js";
|
|
57
57
|
import { confirmWindow, hasDisplay, promptSecret } from "./prompt.js";
|
|
58
58
|
import { getSettingsSafe, settingsCli } from "./settings.js";
|
|
59
|
+
import { tr } from "./i18n.js";
|
|
59
60
|
import { scrubDeep, scrubText } from "./scrub.js";
|
|
60
61
|
|
|
61
62
|
// ---------------------------------------------------------------------------
|
|
@@ -450,7 +451,7 @@ async function bwStatus(session?: string, signal?: AbortSignal): Promise<any> {
|
|
|
450
451
|
|
|
451
452
|
/** The Bitwarden master password, in a window or the host's input dialog. */
|
|
452
453
|
async function askMasterPassword(ctx: ExtensionContext | undefined, signal?: AbortSignal): Promise<string> {
|
|
453
|
-
const pw = await promptSecret(ctx, "Bitwarden · 主密码", "解锁 Bitwarden 保险库", signal);
|
|
454
|
+
const pw = await promptSecret(ctx, tr("Bitwarden · master password", "Bitwarden · 主密码"), tr("unlock the Bitwarden vault", "解锁 Bitwarden 保险库"), signal);
|
|
454
455
|
if (pw) return pw;
|
|
455
456
|
if (signal?.aborted) throw new Error("Cancelled.");
|
|
456
457
|
if (!hasDisplay() && !ctx?.hasUI) {
|
|
@@ -12,6 +12,7 @@ import { spawn } from "node:child_process";
|
|
|
12
12
|
import { existsSync } from "node:fs";
|
|
13
13
|
import { homedir } from "node:os";
|
|
14
14
|
import { delimiter, dirname, join } from "node:path";
|
|
15
|
+
import { lang } from "./i18n.js";
|
|
15
16
|
import { fileURLToPath } from "node:url";
|
|
16
17
|
|
|
17
18
|
export const EXIT = {
|
|
@@ -64,20 +65,29 @@ export function resolveBinary(): string | undefined {
|
|
|
64
65
|
// pip/npm layouts hoist differently: walk up from packages/pi-ai-vault/src.
|
|
65
66
|
let dir = dirname(fileURLToPath(import.meta.url));
|
|
66
67
|
for (let depth = 0; depth < 5; depth++) {
|
|
67
|
-
const
|
|
68
|
-
|
|
68
|
+
for (const name of process.platform === "win32" ? ["ai-vault.exe", "ai-vault.cmd", "ai-vault.ps1"] : ["ai-vault"]) {
|
|
69
|
+
const bundled = join(dir, "node_modules", ".bin", name);
|
|
70
|
+
if (existsSync(bundled)) return bundled;
|
|
71
|
+
}
|
|
69
72
|
const parent = dirname(dir);
|
|
70
73
|
if (parent === dir) break;
|
|
71
74
|
dir = parent;
|
|
72
75
|
}
|
|
73
76
|
|
|
77
|
+
// Windows has no execute bit and npm links .cmd/.ps1 wrappers beside the exe.
|
|
78
|
+
const names = process.platform === "win32" ? ["ai-vault.exe", "ai-vault.cmd", "ai-vault.ps1", "ai-vault"] : ["ai-vault"];
|
|
74
79
|
for (const entry of (process.env.PATH ?? "").split(delimiter)) {
|
|
75
80
|
if (!entry) continue;
|
|
76
|
-
const
|
|
77
|
-
|
|
81
|
+
for (const name of names) {
|
|
82
|
+
const candidate = join(entry, name);
|
|
83
|
+
if (existsSync(candidate)) return candidate;
|
|
84
|
+
}
|
|
78
85
|
}
|
|
79
|
-
for (const
|
|
80
|
-
|
|
86
|
+
for (const base of [join(homedir(), ".local", "bin"), join(homedir(), ".cargo", "bin"), join(homedir(), ".ai-vault", "bin")]) {
|
|
87
|
+
for (const name of names) {
|
|
88
|
+
const candidate = join(base, name);
|
|
89
|
+
if (existsSync(candidate)) return candidate;
|
|
90
|
+
}
|
|
81
91
|
}
|
|
82
92
|
return undefined;
|
|
83
93
|
}
|
|
@@ -124,7 +134,7 @@ export class HostSecret {
|
|
|
124
134
|
|
|
125
135
|
/** Environment for a CLI child: marks us as the host and passes the secret. */
|
|
126
136
|
env(): Record<string, string> {
|
|
127
|
-
return { AI_VAULT_HOST: "1", AI_VAULT_HOST_SECRET: this.value };
|
|
137
|
+
return { AI_VAULT_HOST: "1", AI_VAULT_HOST_SECRET: this.value, AI_VAULT_LANG: lang() };
|
|
128
138
|
}
|
|
129
139
|
|
|
130
140
|
/** HMAC over "allow:<token>:<entry>:<y|n>", what `get --answer-stdin` expects. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { tr } from "./i18n.js";
|
|
1
2
|
/**
|
|
2
3
|
* Ente CLI client.
|
|
3
4
|
*
|
|
@@ -48,7 +49,7 @@ export class EnteError extends Error {
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
const ENTE_MISSING =
|
|
51
|
-
"ente CLI 没找到(要的是 ente.com 的 `ente`,0.4+)。装好后先 `ente account login --app auth` 登录一次;也可以用 ENTE_BIN 指到二进制。";
|
|
52
|
+
tr("ente CLI not found (that is ente.com's `ente`, 0.4+). After installing it, run `ente account login --app auth` once; ENTE_BIN can point at the binary.", "ente CLI 没找到(要的是 ente.com 的 `ente`,0.4+)。装好后先 `ente account login --app auth` 登录一次;也可以用 ENTE_BIN 指到二进制。");
|
|
52
53
|
|
|
53
54
|
/** `ENTE_BIN`, then PATH, then the usual install spots. */
|
|
54
55
|
export function resolveEnte(): string | undefined {
|
|
@@ -256,8 +257,8 @@ export function registerEnte(pi: ExtensionAPI): void {
|
|
|
256
257
|
}
|
|
257
258
|
const ok = await confirmWindow(
|
|
258
259
|
ctx as unknown as Parameters<typeof confirmWindow>[0],
|
|
259
|
-
"pi-ai-vault · Ente Auth 验证码",
|
|
260
|
-
`条目: ${item.name}\n签发方: ${item.issuer || "-"}\n账号: ${item.accountName || "-"}\n\n
|
|
260
|
+
tr("pi-ai-vault · Ente Auth code", "pi-ai-vault · Ente Auth 验证码"),
|
|
261
|
+
tr(`Entry: ${item.name}\n签发方: ${item.issuer || "-"}\n账号: ${item.accountName || "-"}\n\nRead the current code? (It enters the conversation.)`, `条目: ${item.name}\n签发方: ${item.issuer || "-"}\n账号: ${item.accountName || "-"}\n\n读取当前验证码?(会进入对话)`),
|
|
261
262
|
signal,
|
|
262
263
|
);
|
|
263
264
|
if (!ok) {
|