pi-ai-vault 0.12.4 → 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/README.md +2 -0
- package/README.zh.md +2 -0
- package/package.json +2 -2
- package/src/cli.ts +63 -12
- package/src/settings.ts +1 -1
package/README.md
CHANGED
|
@@ -57,6 +57,8 @@ When the local store asks for its master password is a per-machine setting (`/va
|
|
|
57
57
|
| Mode | Behaviour |
|
|
58
58
|
|---|---|
|
|
59
59
|
| `never` | never asks, and reads open no window — the "the agent may use these freely" passwords |
|
|
60
|
+
|
|
61
|
+
By default (`session`) 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.
|
|
60
62
|
| `time` | asks again N hours after the unlock (default 8) |
|
|
61
63
|
| `session` | once per session, dies with it (default) |
|
|
62
64
|
|
package/README.zh.md
CHANGED
|
@@ -52,6 +52,8 @@ omp plugin install npm:pi-ai-vault # omp,同一个包
|
|
|
52
52
|
| 模式 | 行为 |
|
|
53
53
|
|---|---|
|
|
54
54
|
| `never` | 永远不问,读取也不弹确认窗——「agent 可以自由使用」的那批密码 |
|
|
55
|
+
|
|
56
|
+
默认(`session`)读取同样不弹窗:解锁会话的主密码就是授权,每次读取仍记审计。`/vault confirm on` 让每次读取都弹窗。
|
|
55
57
|
| `time` | 解锁后 N 小时(默认 8)再问一次 |
|
|
56
58
|
| `session` | 每个会话一次,会话结束失效(默认) |
|
|
57
59
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-ai-vault",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
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.13.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@earendil-works/pi-coding-agent": "^1.5.0",
|
package/src/cli.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { createHmac, randomBytes } from "node:crypto";
|
|
11
11
|
import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
|
|
12
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
12
|
+
import { chmodSync, existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
13
13
|
import { createRequire } from "node:module";
|
|
14
14
|
import { homedir } from "node:os";
|
|
15
15
|
import { delimiter, dirname, extname, join } from "node:path";
|
|
@@ -216,14 +216,31 @@ function message(stderr: string, fallback: string): string {
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
/**
|
|
219
|
-
* The secret
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
219
|
+
* The secret every pi/omp process on this machine shares for the sessions
|
|
220
|
+
* it unlocked. It lives in `<store>/.host` (0600), next to the store and its
|
|
221
|
+
* `.wrap` key, so it is protected by exactly what protects them: the user's
|
|
222
|
+
* home directory.
|
|
223
|
+
*
|
|
224
|
+
* It used to be minted per process, which meant every herdr tab, every
|
|
225
|
+
* subagent and every `/new` had its own secret and could not read a session
|
|
226
|
+
* another one had opened — so each of them asked for the master password
|
|
227
|
+
* again. One secret per store fixes that: a session opened in one tab is
|
|
228
|
+
* usable in the next.
|
|
229
|
+
*
|
|
230
|
+
* What this does not change: a session file is still signed with this secret,
|
|
231
|
+
* so the model's bash still cannot use a token it finds on disk *unless* it
|
|
232
|
+
* also reads `.host`. That is the same exposure as `.wrap` — the "same user"
|
|
233
|
+
* line the README already draws — and the per-read confirm window is the
|
|
234
|
+
* control on top of it, unchanged.
|
|
224
235
|
*/
|
|
225
236
|
export class HostSecret {
|
|
226
237
|
#value: string | undefined;
|
|
238
|
+
#file: string | undefined;
|
|
239
|
+
|
|
240
|
+
/** Point the secret at a store directory: the first `value` reads or creates it there. */
|
|
241
|
+
attach(storeDir: string): void {
|
|
242
|
+
this.#file = join(storeDir, ".host");
|
|
243
|
+
}
|
|
227
244
|
|
|
228
245
|
get present(): boolean {
|
|
229
246
|
return this.#value !== undefined;
|
|
@@ -234,15 +251,19 @@ export class HostSecret {
|
|
|
234
251
|
if (secret && secret.length >= 32) this.#value = secret;
|
|
235
252
|
}
|
|
236
253
|
|
|
237
|
-
/** 32 fresh bytes, hex —
|
|
254
|
+
/** 32 fresh bytes, hex — a new secret for this store; every live session is voided. */
|
|
238
255
|
rotate(): string {
|
|
239
|
-
|
|
240
|
-
|
|
256
|
+
const fresh = randomBytes(32).toString("hex");
|
|
257
|
+
this.#value = fresh;
|
|
258
|
+
if (this.#file) this.#persist(fresh);
|
|
259
|
+
return fresh;
|
|
241
260
|
}
|
|
242
261
|
|
|
243
|
-
/** The secret,
|
|
262
|
+
/** The secret: the store's, read or created on first use. */
|
|
244
263
|
get value(): string {
|
|
245
|
-
|
|
264
|
+
if (this.#value) return this.#value;
|
|
265
|
+
this.#value = this.#read() ?? this.rotate();
|
|
266
|
+
return this.#value;
|
|
246
267
|
}
|
|
247
268
|
|
|
248
269
|
/** Environment for a CLI child: marks us as the host and passes the secret. */
|
|
@@ -257,15 +278,45 @@ export class HostSecret {
|
|
|
257
278
|
.update(`allow:${token}:${entry.toLowerCase()}:${answer ? "y" : "n"}`)
|
|
258
279
|
.digest("hex");
|
|
259
280
|
}
|
|
281
|
+
|
|
282
|
+
#read(): string | undefined {
|
|
283
|
+
if (!this.#file) return undefined;
|
|
284
|
+
try {
|
|
285
|
+
const text = readFileSync(this.#file, "utf8").trim();
|
|
286
|
+
if (/^[0-9a-f]{64}$/.test(text)) return text;
|
|
287
|
+
} catch {
|
|
288
|
+
/* not there yet */
|
|
289
|
+
}
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
#persist(secret: string): void {
|
|
294
|
+
if (!this.#file) return;
|
|
295
|
+
try {
|
|
296
|
+
writeFileSync(this.#file, `${secret}\n`, { mode: 0o600 });
|
|
297
|
+
chmodSync(this.#file, 0o600);
|
|
298
|
+
} catch {
|
|
299
|
+
/* a read-only store directory: the secret stays in memory for this process */
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** The store directory, by the CLI's own rule: `AI_VAULT_DIR`, else `~/.ai-vault`. */
|
|
305
|
+
export function storeDir(): string {
|
|
306
|
+
return process.env.AI_VAULT_DIR || join(homedir(), ".ai-vault");
|
|
260
307
|
}
|
|
261
308
|
|
|
262
309
|
export class VaultCli {
|
|
263
310
|
private readonly launch = resolveLaunch();
|
|
264
311
|
/** The program that gets started: `AI_VAULT_BIN` when that was set. */
|
|
265
312
|
readonly bin = this.launch?.program;
|
|
266
|
-
/**
|
|
313
|
+
/** One per store, shared by every process that uses it: `<store>/.host`. */
|
|
267
314
|
host = new HostSecret();
|
|
268
315
|
|
|
316
|
+
constructor() {
|
|
317
|
+
this.host.attach(storeDir());
|
|
318
|
+
}
|
|
319
|
+
|
|
269
320
|
get available(): boolean {
|
|
270
321
|
return this.bin !== undefined;
|
|
271
322
|
}
|
package/src/settings.ts
CHANGED
|
@@ -24,7 +24,7 @@ export interface Settings {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export const DEFAULT_SETTINGS: Settings = {
|
|
27
|
-
vault: { unlock: "session", hours: 8, confirm:
|
|
27
|
+
vault: { unlock: "session", hours: 8, confirm: false, auto: false },
|
|
28
28
|
bitwarden: { unlock: "session", hours: 8, import: "ask", persisted: false, expiresAt: null },
|
|
29
29
|
ente: { unlock: "session", hours: 8, persisted: false, expiresAt: null },
|
|
30
30
|
};
|