@xiaolikt/ai-vault 0.13.0 → 0.14.1
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 +53 -51
- package/README.zh.md +28 -35
- package/crates/ai-vault/Cargo.toml +1 -1
- package/crates/ai-vault/src/cli.rs +196 -34
- package/crates/ai-vault/src/config.rs +88 -11
- package/crates/ai-vault/src/crypto.rs +10 -1
- package/crates/ai-vault/src/sealed.rs +3 -1
- package/crates/ai-vault/src/session.rs +74 -0
- package/package.json +6 -6
- package/packages/pi-ai-vault/README.md +3 -2
- package/packages/pi-ai-vault/README.zh.md +4 -3
- package/packages/pi-ai-vault/package.json +2 -2
- package/packages/pi-ai-vault/src/bitwarden.ts +3 -3
- package/packages/pi-ai-vault/src/cli.ts +11 -5
- package/packages/pi-ai-vault/src/ente.ts +2 -2
- package/packages/pi-ai-vault/src/index.ts +121 -51
- package/packages/pi-ai-vault/src/settings.ts +14 -2
- package/test/cli.sh +67 -2
- package/tests/vault-cli.test.mjs +98 -3
|
@@ -19,7 +19,14 @@ pub enum UnlockMode {
|
|
|
19
19
|
Never,
|
|
20
20
|
/// Ask again after `hours`, counted from the unlock (not from the last use).
|
|
21
21
|
Time,
|
|
22
|
-
/// Ask
|
|
22
|
+
/// Ask on every call; no token is ever written, so nothing on disk can
|
|
23
|
+
/// open the store. The opposite end from `Never`.
|
|
24
|
+
Every,
|
|
25
|
+
/// Only for the Bitwarden and Ente keys: keep them in the CLI's own
|
|
26
|
+
/// memory, write nothing. (For the store itself this used to mean "once
|
|
27
|
+
/// per process", which in a multi-tab host was once per tab, once per
|
|
28
|
+
/// `/new`, once per subagent — never what anyone wanted; the store's
|
|
29
|
+
/// modes are now never | time | every.)
|
|
23
30
|
Session,
|
|
24
31
|
}
|
|
25
32
|
|
|
@@ -28,15 +35,27 @@ impl UnlockMode {
|
|
|
28
35
|
match text.trim().to_lowercase().as_str() {
|
|
29
36
|
"never" | "no-password" | "none" | "off" => Some(UnlockMode::Never),
|
|
30
37
|
"time" | "hours" => Some(UnlockMode::Time),
|
|
31
|
-
"
|
|
38
|
+
"every" | "everytime" | "every-time" | "always-ask" | "ask" | "on" => Some(UnlockMode::Every),
|
|
39
|
+
"session" => Some(UnlockMode::Session),
|
|
32
40
|
_ => None,
|
|
33
41
|
}
|
|
34
42
|
}
|
|
35
43
|
|
|
44
|
+
/// The modes the store's own unlock policy accepts.
|
|
45
|
+
pub fn parse_store(text: &str) -> Option<UnlockMode> {
|
|
46
|
+
match text.trim().to_lowercase().as_str() {
|
|
47
|
+
// A store set to `session` before the mode was removed: the closest
|
|
48
|
+
// honest meaning is "ask again, but not on every call".
|
|
49
|
+
"session" => Some(UnlockMode::Time),
|
|
50
|
+
other => UnlockMode::parse(other).filter(|m| *m != UnlockMode::Session),
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
36
54
|
pub fn as_str(self) -> &'static str {
|
|
37
55
|
match self {
|
|
38
56
|
UnlockMode::Never => "never",
|
|
39
57
|
UnlockMode::Time => "time",
|
|
58
|
+
UnlockMode::Every => "every",
|
|
40
59
|
UnlockMode::Session => "session",
|
|
41
60
|
}
|
|
42
61
|
}
|
|
@@ -72,7 +91,7 @@ impl ImportPolicy {
|
|
|
72
91
|
}
|
|
73
92
|
}
|
|
74
93
|
|
|
75
|
-
#[derive(Debug, Clone, Copy, Serialize
|
|
94
|
+
#[derive(Debug, Clone, Copy, Serialize)]
|
|
76
95
|
pub struct UnlockPolicy {
|
|
77
96
|
pub mode: UnlockMode,
|
|
78
97
|
/// `Time` mode only: hours between password prompts.
|
|
@@ -91,31 +110,78 @@ fn default_confirm() -> bool {
|
|
|
91
110
|
false
|
|
92
111
|
}
|
|
93
112
|
|
|
113
|
+
/// The store's own policy reads its mode the way the settings command does:
|
|
114
|
+
/// `session` — the mode that was removed — is `time`, so a legacy file or an
|
|
115
|
+
/// older ciphertext cannot carry a per-process policy back to life.
|
|
116
|
+
impl<'de> Deserialize<'de> for UnlockPolicy {
|
|
117
|
+
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
|
118
|
+
#[derive(Deserialize)]
|
|
119
|
+
struct Raw {
|
|
120
|
+
#[serde(default)]
|
|
121
|
+
mode: Option<UnlockMode>,
|
|
122
|
+
#[serde(default = "default_hours")]
|
|
123
|
+
hours: i64,
|
|
124
|
+
#[serde(default = "default_confirm")]
|
|
125
|
+
confirm: bool,
|
|
126
|
+
}
|
|
127
|
+
let raw = Raw::deserialize(deserializer)?;
|
|
128
|
+
let mode = raw
|
|
129
|
+
.mode
|
|
130
|
+
.map(|m| if m == UnlockMode::Session { UnlockMode::Time } else { m })
|
|
131
|
+
.unwrap_or(UnlockMode::Time);
|
|
132
|
+
Ok(UnlockPolicy { mode, hours: raw.hours, confirm: raw.confirm })
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/// The store's own default: an afternoon's work without asking again.
|
|
94
137
|
fn default_hours() -> i64 {
|
|
138
|
+
4
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/// The Bitwarden and Ente keys: their session outlives a work sitting.
|
|
142
|
+
fn default_key_hours() -> i64 {
|
|
95
143
|
8
|
|
96
144
|
}
|
|
97
145
|
|
|
98
146
|
impl Default for UnlockPolicy {
|
|
99
147
|
fn default() -> Self {
|
|
100
|
-
UnlockPolicy { mode: UnlockMode::
|
|
148
|
+
UnlockPolicy { mode: UnlockMode::Time, hours: default_hours(), confirm: default_confirm() }
|
|
101
149
|
}
|
|
102
150
|
}
|
|
103
151
|
|
|
104
152
|
/// How a third-party CLI's credential is kept on disk.
|
|
105
|
-
#[derive(Debug, Clone, Copy, Serialize
|
|
153
|
+
#[derive(Debug, Clone, Copy, Serialize)]
|
|
106
154
|
pub struct StorePolicy {
|
|
107
155
|
/// `never` keeps the credential in the store directory (sealed), so the
|
|
108
156
|
/// CLI needs no keychain or password; `time` does the same with a
|
|
109
157
|
/// deadline; `session` (default) leaves it in the CLI's own keychain.
|
|
110
|
-
#[serde(default = "default_bw_mode")]
|
|
111
158
|
pub unlock: UnlockMode,
|
|
112
|
-
#[serde(default = "default_hours")]
|
|
113
159
|
pub hours: i64,
|
|
114
160
|
}
|
|
115
161
|
|
|
116
162
|
impl Default for StorePolicy {
|
|
117
163
|
fn default() -> Self {
|
|
118
|
-
StorePolicy { unlock: default_bw_mode(), hours:
|
|
164
|
+
StorePolicy { unlock: default_bw_mode(), hours: default_key_hours() }
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/// The Bitwarden and Ente keys have no `every`. A file that says otherwise is
|
|
169
|
+
/// not accepted as "keep it forever", which is what a plain `UnlockMode`
|
|
170
|
+
/// would have made of it: the whole entry falls back to the default.
|
|
171
|
+
impl<'de> Deserialize<'de> for StorePolicy {
|
|
172
|
+
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
|
173
|
+
#[derive(Deserialize)]
|
|
174
|
+
struct Raw {
|
|
175
|
+
#[serde(default = "default_bw_mode")]
|
|
176
|
+
unlock: UnlockMode,
|
|
177
|
+
#[serde(default = "default_key_hours")]
|
|
178
|
+
hours: i64,
|
|
179
|
+
}
|
|
180
|
+
let raw = Raw::deserialize(deserializer)?;
|
|
181
|
+
if raw.unlock == UnlockMode::Every {
|
|
182
|
+
return Err(serde::de::Error::custom("`every` is not a mode for the Bitwarden and Ente keys (never, time or session)"));
|
|
183
|
+
}
|
|
184
|
+
Ok(StorePolicy { unlock: raw.unlock, hours: raw.hours })
|
|
119
185
|
}
|
|
120
186
|
}
|
|
121
187
|
|
|
@@ -180,7 +246,7 @@ pub fn take_legacy(paths: &Paths) -> Option<Config> {
|
|
|
180
246
|
let Ok(parsed) = serde_json::from_str::<Config>(&text) else { return None };
|
|
181
247
|
let mut config = parsed;
|
|
182
248
|
if config.unlock.mode == UnlockMode::Never {
|
|
183
|
-
config.unlock.mode = UnlockMode::
|
|
249
|
+
config.unlock.mode = UnlockMode::Time;
|
|
184
250
|
}
|
|
185
251
|
config.unlock.confirm = true;
|
|
186
252
|
Some(config)
|
|
@@ -193,7 +259,9 @@ mod tests {
|
|
|
193
259
|
#[test]
|
|
194
260
|
fn parses_aliases() {
|
|
195
261
|
assert_eq!(UnlockMode::parse("no-password"), Some(UnlockMode::Never));
|
|
196
|
-
assert_eq!(UnlockMode::parse("
|
|
262
|
+
assert_eq!(UnlockMode::parse("every"), Some(UnlockMode::Every));
|
|
263
|
+
assert_eq!(UnlockMode::parse_store("session"), Some(UnlockMode::Time), "an old store setting is read as time");
|
|
264
|
+
assert_eq!(UnlockMode::parse_store("every-time"), Some(UnlockMode::Every));
|
|
197
265
|
assert_eq!(UnlockMode::parse("2h"), None);
|
|
198
266
|
assert_eq!(ImportPolicy::parse("auto"), Some(ImportPolicy::Always));
|
|
199
267
|
assert_eq!(ImportPolicy::parse("off"), Some(ImportPolicy::Never));
|
|
@@ -202,12 +270,21 @@ mod tests {
|
|
|
202
270
|
#[test]
|
|
203
271
|
fn defaults_are_the_cautious_ones() {
|
|
204
272
|
let config = Config::default();
|
|
205
|
-
assert_eq!(config.unlock.mode, UnlockMode::
|
|
273
|
+
assert_eq!(config.unlock.mode, UnlockMode::Time);
|
|
274
|
+
assert_eq!(config.unlock.hours, 4);
|
|
206
275
|
assert_eq!(config.bitwarden.store.unlock, UnlockMode::Session);
|
|
207
276
|
assert_eq!(config.ente.unlock, UnlockMode::Session);
|
|
208
277
|
assert_eq!(config.bitwarden.import, ImportPolicy::Ask);
|
|
209
278
|
}
|
|
210
279
|
|
|
280
|
+
#[test]
|
|
281
|
+
fn the_keys_refuse_every() {
|
|
282
|
+
let err = serde_json::from_str::<Config>(r#"{"bitwarden":{"unlock":"every","hours":8}}"#);
|
|
283
|
+
assert!(err.is_err(), "every for a key must not be read as a mode");
|
|
284
|
+
let ok = serde_json::from_str::<Config>(r#"{"ente":{"unlock":"time","hours":2}}"#).unwrap();
|
|
285
|
+
assert_eq!(ok.ente.unlock, UnlockMode::Time);
|
|
286
|
+
}
|
|
287
|
+
|
|
211
288
|
#[test]
|
|
212
289
|
fn old_configs_still_load() {
|
|
213
290
|
// A config written by the previous version had only `unlock`.
|
|
@@ -53,6 +53,14 @@ pub struct StoreFile {
|
|
|
53
53
|
pub salt: String,
|
|
54
54
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
55
55
|
pub kdf: Option<Kdf>,
|
|
56
|
+
/// A plaintext hint that the store's unlock policy is `every`: the CLI
|
|
57
|
+
/// must ask for the password *before* it can read the policy, which lives
|
|
58
|
+
/// inside the ciphertext. It is only a prompt to ask — whether a call is
|
|
59
|
+
/// allowed is still decided by the settings under the key — so editing it
|
|
60
|
+
/// cannot lower protection: cleared, the CLI finds no token and refuses;
|
|
61
|
+
/// set, the CLI asks for a password it would not otherwise have asked for.
|
|
62
|
+
#[serde(default, rename = "askEvery", skip_serializing_if = "std::ops::Not::not")]
|
|
63
|
+
pub ask_every: bool,
|
|
56
64
|
pub ct: String,
|
|
57
65
|
}
|
|
58
66
|
|
|
@@ -141,6 +149,7 @@ pub fn seal(salt: &[u8], kdf: Kdf, key: &[u8; 32], items: &[Item], config: &crat
|
|
|
141
149
|
v: 1,
|
|
142
150
|
salt: salt.iter().map(|b| format!("{b:02x}")).collect(),
|
|
143
151
|
kdf: Some(kdf),
|
|
152
|
+
ask_every: config.unlock.mode == crate::config::UnlockMode::Every,
|
|
144
153
|
ct: B64.encode(blob),
|
|
145
154
|
})
|
|
146
155
|
}
|
|
@@ -309,7 +318,7 @@ mod tests {
|
|
|
309
318
|
let body = cipher.encrypt(Nonce::from_slice(&iv), plain.as_slice()).unwrap();
|
|
310
319
|
let mut blob = iv.to_vec();
|
|
311
320
|
blob.extend_from_slice(&body);
|
|
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) };
|
|
321
|
+
let v1 = StoreFile { v: 1, salt: salt.iter().map(|b| format!("{b:02x}")).collect(), kdf: Some(kdf), ask_every: false, ct: base64::engine::general_purpose::STANDARD.encode(blob) };
|
|
313
322
|
let (payload, _) = open_with_passphrase(&v1, "pw").unwrap();
|
|
314
323
|
assert_eq!(payload.items[0].name, "GitHub");
|
|
315
324
|
// A store from before the switch carries no `confirm`; it reads as the
|
|
@@ -130,10 +130,12 @@ pub fn save(paths: &Paths, kind: Kind, secret: &str, policy: config::StorePolicy
|
|
|
130
130
|
));
|
|
131
131
|
}
|
|
132
132
|
let now = now_ms();
|
|
133
|
+
// The Bitwarden and Ente keys have no `every`: their CLI keeps its own
|
|
134
|
+
// session, and "ask on every call" is not a thing a bw session can do.
|
|
133
135
|
let expires_at = match policy.unlock {
|
|
134
136
|
UnlockMode::Never => None,
|
|
135
137
|
UnlockMode::Time => Some(now + policy.hours.clamp(1, 24 * 90) * 3_600_000),
|
|
136
|
-
UnlockMode::Session => None,
|
|
138
|
+
UnlockMode::Session | UnlockMode::Every => None,
|
|
137
139
|
};
|
|
138
140
|
let wrap = wrap_key(paths)?;
|
|
139
141
|
let stored = Stored { saved_at: now, expires_at, sealed: seal(&wrap, secret)? };
|
|
@@ -61,6 +61,22 @@ pub struct Session {
|
|
|
61
61
|
/// the other way.
|
|
62
62
|
#[serde(default, skip_serializing_if = "Option::is_none", rename = "signedBy")]
|
|
63
63
|
pub signed_by: Option<String>,
|
|
64
|
+
/// How this session may be used. `auto` is the `never`-mode machine
|
|
65
|
+
/// session: it *is* the approval. `every` was opened by the password that
|
|
66
|
+
/// came with this call: approved for this call, never written. A token
|
|
67
|
+
/// session is `normal`. The distinction matters where a read decides
|
|
68
|
+
/// whether the session itself is the authorization.
|
|
69
|
+
#[serde(default, rename = "kind")]
|
|
70
|
+
pub kind: SessionKind,
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
|
|
74
|
+
#[serde(rename_all = "lowercase")]
|
|
75
|
+
pub enum SessionKind {
|
|
76
|
+
#[default]
|
|
77
|
+
Normal,
|
|
78
|
+
Auto,
|
|
79
|
+
Every,
|
|
64
80
|
}
|
|
65
81
|
|
|
66
82
|
|
|
@@ -117,9 +133,15 @@ impl Session {
|
|
|
117
133
|
grants: BTreeMap::new(),
|
|
118
134
|
mac: None,
|
|
119
135
|
signed_by: None,
|
|
136
|
+
kind: SessionKind::Normal,
|
|
120
137
|
}
|
|
121
138
|
}
|
|
122
139
|
|
|
140
|
+
pub fn with_kind(mut self, kind: SessionKind) -> Self {
|
|
141
|
+
self.kind = kind;
|
|
142
|
+
self
|
|
143
|
+
}
|
|
144
|
+
|
|
123
145
|
/// The signer this session was signed with, for writing it back unchanged.
|
|
124
146
|
/// A session is signed by whoever opened it; a later call made with the
|
|
125
147
|
/// other kind of key must not re-sign it under its own, or the opener
|
|
@@ -265,10 +287,62 @@ pub fn load(paths: &Paths, token: &str, host_secret: Option<&str>, wrap_key: Opt
|
|
|
265
287
|
Ok(session)
|
|
266
288
|
}
|
|
267
289
|
|
|
290
|
+
/// The newest live token of this store that the caller can verify — one
|
|
291
|
+
/// opened by any process, since they all sign under the store-wide host
|
|
292
|
+
/// secret (or, for a human at a terminal, the wrap key). `time` mode's
|
|
293
|
+
/// cross-process unlock rests on this: a call without a token adopts an
|
|
294
|
+
/// existing one rather than asking for the password again.
|
|
295
|
+
pub fn find_live(paths: &Paths, keys: &(Option<String>, Option<String>)) -> Option<Session> {
|
|
296
|
+
let current = crypto::read_store(&paths.store()).ok().flatten().map(|store| crypto::store_id(&store))?;
|
|
297
|
+
let now = now_ms();
|
|
298
|
+
let mut best: Option<Session> = None;
|
|
299
|
+
if let Ok(entries) = fs::read_dir(paths.sessions()) {
|
|
300
|
+
for entry in entries.flatten() {
|
|
301
|
+
let path = entry.path();
|
|
302
|
+
if path.extension().and_then(|e| e.to_str()) != Some("json") {
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
let Ok(text) = fs::read_to_string(&path) else { continue };
|
|
306
|
+
let Ok(session) = serde_json::from_str::<Session>(&text) else { continue };
|
|
307
|
+
if session.store_id != current || session.expired(now) || session.kind == SessionKind::Every {
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
if !session.verifies(keys.0.as_deref(), keys.1.as_deref()) {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
let newer = best.as_ref().map_or(true, |b| session.last_active > b.last_active);
|
|
314
|
+
if newer {
|
|
315
|
+
best = Some(session);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
best
|
|
320
|
+
}
|
|
321
|
+
|
|
268
322
|
pub fn delete(paths: &Paths, token: &str) -> bool {
|
|
269
323
|
fs::remove_file(paths.session_file(token)).is_ok()
|
|
270
324
|
}
|
|
271
325
|
|
|
326
|
+
/// Remove every token file of one store (the sessions directory is shared
|
|
327
|
+
/// across stores); the machine-wide session is not touched.
|
|
328
|
+
pub fn delete_all_of(paths: &Paths, store: &crate::crypto::StoreFile) -> usize {
|
|
329
|
+
let current = crate::crypto::store_id(store);
|
|
330
|
+
let mut removed = 0;
|
|
331
|
+
if let Ok(entries) = fs::read_dir(paths.sessions()) {
|
|
332
|
+
for entry in entries.flatten() {
|
|
333
|
+
let path = entry.path();
|
|
334
|
+
let mine = fs::read_to_string(&path)
|
|
335
|
+
.ok()
|
|
336
|
+
.and_then(|text| serde_json::from_str::<Session>(&text).ok())
|
|
337
|
+
.is_some_and(|s| s.store_id == current);
|
|
338
|
+
if mine && fs::remove_file(&path).is_ok() {
|
|
339
|
+
removed += 1;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
removed
|
|
344
|
+
}
|
|
345
|
+
|
|
272
346
|
pub fn delete_all(paths: &Paths) -> usize {
|
|
273
347
|
let dir = paths.sessions();
|
|
274
348
|
let mut removed = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiaolikt/ai-vault",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.1",
|
|
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,11 +33,11 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"optionalDependencies": {
|
|
36
|
-
"@xiaolikt/ai-vault-linux-x64": "0.
|
|
37
|
-
"@xiaolikt/ai-vault-linux-arm64": "0.
|
|
38
|
-
"@xiaolikt/ai-vault-win32-x64": "0.
|
|
39
|
-
"@xiaolikt/ai-vault-darwin-arm64": "0.
|
|
40
|
-
"@xiaolikt/ai-vault-darwin-x64": "0.
|
|
36
|
+
"@xiaolikt/ai-vault-linux-x64": "0.14.1",
|
|
37
|
+
"@xiaolikt/ai-vault-linux-arm64": "0.14.1",
|
|
38
|
+
"@xiaolikt/ai-vault-win32-x64": "0.14.1",
|
|
39
|
+
"@xiaolikt/ai-vault-darwin-arm64": "0.14.1",
|
|
40
|
+
"@xiaolikt/ai-vault-darwin-x64": "0.14.1"
|
|
41
41
|
},
|
|
42
42
|
"files": [
|
|
43
43
|
"bin",
|
|
@@ -56,11 +56,12 @@ When the local store asks for its master password is a per-machine setting (`/va
|
|
|
56
56
|
|
|
57
57
|
| Mode | Behaviour |
|
|
58
58
|
|---|---|
|
|
59
|
+
| `every` | asks on every call; nothing is kept that could open the store |
|
|
59
60
|
| `never` | never asks, and reads open no window — the "the agent may use these freely" passwords |
|
|
60
61
|
|
|
61
|
-
By default (`
|
|
62
|
+
By default (`time`) a read opens no window either: the master password that unlocked the session is the approval, and every read is audited. `/vault confirm on` puts a window on every read.
|
|
62
63
|
| `time` | asks again N hours after the unlock (default 8) |
|
|
63
|
-
| `
|
|
64
|
+
| `time` (default, 4 h) | once, then every pi/omp process on the machine uses that unlock for N hours |
|
|
64
65
|
|
|
65
66
|
`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**.
|
|
66
67
|
|
|
@@ -51,11 +51,12 @@ omp plugin install npm:pi-ai-vault # omp,同一个包
|
|
|
51
51
|
|
|
52
52
|
| 模式 | 行为 |
|
|
53
53
|
|---|---|
|
|
54
|
+
| `every` | 每次调用都问;不留任何能打开库的东西 |
|
|
54
55
|
| `never` | 永远不问,读取也不弹确认窗——「agent 可以自由使用」的那批密码 |
|
|
55
56
|
|
|
56
|
-
默认(`
|
|
57
|
-
| `time
|
|
58
|
-
| `
|
|
57
|
+
默认(`time`)读取同样不弹窗:解锁会话的主密码就是授权,每次读取仍记审计。`/vault confirm on` 让每次读取都弹窗。
|
|
58
|
+
| `time`(默认,4 小时) | 问一次,之后机器上所有 pi/omp 进程共用这次解锁 N 小时 |
|
|
59
|
+
| `every` | 每次调用都问;不留任何能打开库的东西 |
|
|
59
60
|
|
|
60
61
|
`vault_get` 找不到本地条目时会去 Bitwarden 搜;命中后按 `bitwarden.import` 处理:
|
|
61
62
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-ai-vault",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.1",
|
|
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.
|
|
28
|
+
"@xiaolikt/ai-vault": "0.14.1"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@earendil-works/pi-coding-agent": "^1.5.0",
|
|
@@ -57,7 +57,7 @@ import type { Draft } from "./types.js";
|
|
|
57
57
|
import { onSessionLeave, sessionLabel, withTier } from "./host.js";
|
|
58
58
|
import { confirmWindow, hasDisplay, promptSecret } from "./prompt.js";
|
|
59
59
|
import { npmShimLaunch, type CliLaunch } from "./cli.js";
|
|
60
|
-
import { getSettingsSafe, settingsCli, settingsToken } from "./settings.js";
|
|
60
|
+
import { getSettingsSafe, settingsCli, settingsOpts, settingsToken } from "./settings.js";
|
|
61
61
|
import { tr } from "./i18n.js";
|
|
62
62
|
import { scrubDeep, scrubText } from "./scrub.js";
|
|
63
63
|
|
|
@@ -676,7 +676,7 @@ async function ensureUnlocked(st: BwState, ctx: ExtensionContext | undefined, si
|
|
|
676
676
|
// directory), so Bitwarden costs no window at all.
|
|
677
677
|
if (policy.unlock !== "session") {
|
|
678
678
|
try {
|
|
679
|
-
const saved = await settingsCli().json<{ key: string }>(["bw-session", "get"], { signal });
|
|
679
|
+
const saved = await settingsCli().json<{ key: string }>(["bw-session", "get"], { signal, ...settingsOpts() });
|
|
680
680
|
if (saved?.key) {
|
|
681
681
|
const verify = await bwStatus(saved.key, signal);
|
|
682
682
|
if (verify?.status === "unlocked") {
|
|
@@ -720,7 +720,7 @@ async function ensureUnlocked(st: BwState, ctx: ExtensionContext | undefined, si
|
|
|
720
720
|
// Keep the key where the CLI can hand it back; the file's expiry comes
|
|
721
721
|
// from the bitwarden.hours policy.
|
|
722
722
|
const token = settingsToken();
|
|
723
|
-
await settingsCli().run(["bw-session", "put", ...(token ? ["--token", token] : [])], { stdin: key }).catch(() => undefined);
|
|
723
|
+
await settingsCli().run(["bw-session", "put", ...(token ? ["--token", token] : [])], { stdin: key, ...settingsOpts() }).catch(() => undefined);
|
|
724
724
|
}
|
|
725
725
|
await auditEvent("unlock", "ok", st.sessionLabel);
|
|
726
726
|
// Refresh in the background: a full sync can take seconds on large vaults.
|
|
@@ -326,7 +326,7 @@ export class VaultCli {
|
|
|
326
326
|
return process.env.AI_VAULT_DIR ?? join(homedir(), ".ai-vault");
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
-
async run(args: string[], opts: { stdin?: string; signal?: AbortSignal } = {}): Promise<CliRun> {
|
|
329
|
+
async run(args: string[], opts: { stdin?: string; signal?: AbortSignal; password?: string } = {}): Promise<CliRun> {
|
|
330
330
|
const launch = this.launch;
|
|
331
331
|
if (!launch) {
|
|
332
332
|
throw new CliError(EXIT.error, undefined, "ai-vault CLI not found", "");
|
|
@@ -337,7 +337,10 @@ export class VaultCli {
|
|
|
337
337
|
const run = await new Promise<CliRun>((resolve, reject) => {
|
|
338
338
|
// A program Node will not start fails here like any other CLI failure,
|
|
339
339
|
// not as a bare exception from inside the promise.
|
|
340
|
-
|
|
340
|
+
// `every` mode: the master password travels in the child's environment,
|
|
341
|
+
// never on the command line, and lives for exactly this call.
|
|
342
|
+
const passwordEnv = opts.password !== undefined ? { AI_VAULT_PASSWORD: opts.password } : {};
|
|
343
|
+
const child = startCli(launch, args, { ...process.env, ...this.host.env(), ...passwordEnv }, () => {
|
|
341
344
|
opts.signal?.removeEventListener("abort", onAbort);
|
|
342
345
|
reject(new CliError(EXIT.error, undefined, `cannot run ${launch.program}: ${lastStartError}`, ""));
|
|
343
346
|
});
|
|
@@ -376,14 +379,14 @@ export class VaultCli {
|
|
|
376
379
|
* `init` or `unlock`: returns the parsed result with the token, and keeps
|
|
377
380
|
* the host secret the CLI minted (or used ours) for later signing.
|
|
378
381
|
*/
|
|
379
|
-
async open<T extends { hostSecret?: string }>(subcommand: "init" | "unlock", args: string[], opts: { stdin?: string; signal?: AbortSignal } = {}): Promise<T> {
|
|
382
|
+
async open<T extends { hostSecret?: string }>(subcommand: "init" | "unlock", args: string[], opts: { stdin?: string; signal?: AbortSignal; password?: string } = {}): Promise<T> {
|
|
380
383
|
const result = await this.json<T>([subcommand, ...args], opts);
|
|
381
384
|
this.host.adopt(result.hostSecret);
|
|
382
385
|
return result;
|
|
383
386
|
}
|
|
384
387
|
|
|
385
388
|
/** One CLI call whose output is a JSON object. */
|
|
386
|
-
async json<T>(args: string[], opts: { stdin?: string; signal?: AbortSignal } = {}): Promise<T> {
|
|
389
|
+
async json<T>(args: string[], opts: { stdin?: string; signal?: AbortSignal; password?: string } = {}): Promise<T> {
|
|
387
390
|
const run = await this.run([...args, "--json"], opts);
|
|
388
391
|
try {
|
|
389
392
|
return JSON.parse(run.stdout) as T;
|
|
@@ -396,8 +399,11 @@ export class VaultCli {
|
|
|
396
399
|
async withPassword(
|
|
397
400
|
args: string[],
|
|
398
401
|
ask: () => Promise<string | undefined>,
|
|
399
|
-
opts: { stdin?: string; signal?: AbortSignal } = {},
|
|
402
|
+
opts: { stdin?: string; signal?: AbortSignal; password?: string } = {},
|
|
400
403
|
): Promise<CliRun> {
|
|
404
|
+
// In `every` mode the call already carries the master password: the CLI
|
|
405
|
+
// reuses it for the verification instead of asking for it again.
|
|
406
|
+
if (opts.password !== undefined) return this.run(args, opts);
|
|
401
407
|
try {
|
|
402
408
|
return await this.run(args, opts);
|
|
403
409
|
} catch (error) {
|
|
@@ -26,7 +26,7 @@ import { Type } from "typebox";
|
|
|
26
26
|
import { auditEvent } from "./bitwarden.js";
|
|
27
27
|
import { confirmWindow, forDialog } from "./prompt.js";
|
|
28
28
|
import { withTier } from "./host.js";
|
|
29
|
-
import { getSettingsSafe, settingsCli } from "./settings.js";
|
|
29
|
+
import { getSettingsSafe, settingsCli, settingsOpts } from "./settings.js";
|
|
30
30
|
|
|
31
31
|
export interface EnteCodeMeta {
|
|
32
32
|
id: string;
|
|
@@ -94,7 +94,7 @@ async function enteEnv(signal?: AbortSignal): Promise<Record<string, string | un
|
|
|
94
94
|
const settings = await getSettingsSafe(signal);
|
|
95
95
|
if (settings.ente.unlock === "session") return env;
|
|
96
96
|
try {
|
|
97
|
-
const sealed = await settingsCli().json<{ key: string }>(["ente-session", "get"], { signal });
|
|
97
|
+
const sealed = await settingsCli().json<{ key: string }>(["ente-session", "get"], { signal, ...settingsOpts() });
|
|
98
98
|
if (sealed?.key) env.ENTE_CLI_VAULT_KEY = sealed.key;
|
|
99
99
|
} catch {
|
|
100
100
|
// No key saved yet, or it expired: ente will fall back to the keychain,
|