@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
package/tests/vault-cli.test.mjs
CHANGED
|
@@ -105,7 +105,7 @@ test("a subagent has its own session: the parent's grant is not inherited", asyn
|
|
|
105
105
|
assert.equal(prompts("--question"), before + 1, "the subagent needs its own approval");
|
|
106
106
|
});
|
|
107
107
|
|
|
108
|
-
test("/new drops
|
|
108
|
+
test("/new drops the binding's own session and grants, not the machine-wide unlock", async () => {
|
|
109
109
|
const a = bind(aiVault, true);
|
|
110
110
|
const b = bind(aiVault, true);
|
|
111
111
|
const ac = makeCtx({ sessionId: "11111111-0000-4000-8000-000000000001" }).ctx;
|
|
@@ -119,12 +119,14 @@ test("/new drops only the binding that switched", async () => {
|
|
|
119
119
|
|
|
120
120
|
answers.master(dir, PW);
|
|
121
121
|
const before = masterPrompts();
|
|
122
|
+
// `time` mode: the unlock is the machine's, so the switched binding picks
|
|
123
|
+
// it back up without a password — only its own session and grants are gone.
|
|
122
124
|
assert.equal((await a.tool("vault_list", {}, ac)).isError, undefined);
|
|
123
|
-
assert.equal(masterPrompts(), before
|
|
125
|
+
assert.equal(masterPrompts(), before, "/new does not ask for the password again");
|
|
124
126
|
|
|
125
127
|
const untouched = await b.tool("vault_list", {}, bc);
|
|
126
128
|
assert.equal(untouched.isError, undefined);
|
|
127
|
-
assert.equal(masterPrompts(), before
|
|
129
|
+
assert.equal(masterPrompts(), before, "the other binding keeps its token");
|
|
128
130
|
});
|
|
129
131
|
|
|
130
132
|
test("a missing entry names what is available", async () => {
|
|
@@ -427,3 +429,96 @@ test("by default a read after unlock opens no window: the unlock is the approval
|
|
|
427
429
|
assert.match(audit, /"event":"read_allow","item":"DefaultRead"/, "the read is still audited");
|
|
428
430
|
assert.match(audit, /"reason":"confirm-off"/, "and says the window was off");
|
|
429
431
|
});
|
|
432
|
+
|
|
433
|
+
test("every mode: each call asks for the master password, nothing that opens the store is kept", async () => {
|
|
434
|
+
// Fully isolated: its own mock state (zenity answers), store and runtime,
|
|
435
|
+
// so the other tests' windows and tokens cannot leak in or be counted.
|
|
436
|
+
const { mkdtempSync, readdirSync, existsSync, readFileSync } = await import("node:fs");
|
|
437
|
+
const { join } = await import("node:path");
|
|
438
|
+
const { spawnSync } = await import("node:child_process");
|
|
439
|
+
const box = mkdtempSync(join(process.env.TMPDIR ?? "/tmp", "ai-vault-every-"));
|
|
440
|
+
const store = join(box, "store");
|
|
441
|
+
const runtime = join(box, "runtime");
|
|
442
|
+
const saved = { AI_VAULT_DIR: process.env.AI_VAULT_DIR, XDG_RUNTIME_DIR: process.env.XDG_RUNTIME_DIR, OMP_VAULT_MOCK: process.env.OMP_VAULT_MOCK };
|
|
443
|
+
mkdtempSync(join(box, "x")); // no-op keep
|
|
444
|
+
process.env.AI_VAULT_DIR = store;
|
|
445
|
+
process.env.XDG_RUNTIME_DIR = runtime;
|
|
446
|
+
process.env.OMP_VAULT_MOCK = box;
|
|
447
|
+
const bin = process.env.AI_VAULT_BIN;
|
|
448
|
+
const env = { ...process.env, AI_VAULT_HOST: "", AI_VAULT_HOST_SECRET: "", AI_VAULT_PASSWORD: "" };
|
|
449
|
+
const cli = (args, input) => spawnSync(bin, args, { input, env, encoding: "utf8" });
|
|
450
|
+
const windows = () => (existsSync(join(box, "zenity.log")) ? readFileSync(join(box, "zenity.log"), "utf8").split("\n").filter((l) => l.includes("--password")) : []);
|
|
451
|
+
try {
|
|
452
|
+
const { forgetSettings } = await import("../packages/pi-ai-vault/src/settings.ts");
|
|
453
|
+
forgetSettings();
|
|
454
|
+
answers.master(box, PW, PW);
|
|
455
|
+
const b = bind(aiVault, true);
|
|
456
|
+
const ctx = makeCtx().ctx;
|
|
457
|
+
await b.cmd("init", ctx);
|
|
458
|
+
answers.questions(box, "y");
|
|
459
|
+
answers.entries(box, "u");
|
|
460
|
+
answers.entryPassword(box, "every-pw");
|
|
461
|
+
await b.cmd("add EveryRead", ctx);
|
|
462
|
+
assert.equal(readdirSync(join(runtime, "ai-vault", "sessions")).length, 1, "time mode: one token on disk");
|
|
463
|
+
|
|
464
|
+
// Switch the store to `every` (the strict direction: no password needed).
|
|
465
|
+
const token = JSON.parse(cli(["unlock", "--password-stdin", "--json"], `${PW}\n`).stdout).token;
|
|
466
|
+
const switched = cli(["settings", "vault.unlock", "every", "--token", token, "--json"]);
|
|
467
|
+
assert.equal(switched.status, 0, switched.stderr);
|
|
468
|
+
assert.equal(readdirSync(join(runtime, "ai-vault", "sessions")).length, 0, "every token of the store is gone");
|
|
469
|
+
assert.equal(existsSync(join(store, "agent.session.json")), false, "no machine session either");
|
|
470
|
+
forgetSettings();
|
|
471
|
+
|
|
472
|
+
// Two reads, two master-password windows, no Allow, nothing on disk after.
|
|
473
|
+
answers.master(box, PW, PW);
|
|
474
|
+
const before = windows().length;
|
|
475
|
+
const first = await b.tool("vault_get", { name: "EveryRead" }, ctx);
|
|
476
|
+
assert.equal(first.isError, undefined, textOf(first));
|
|
477
|
+
const second = await b.tool("vault_get", { name: "EveryRead" }, ctx);
|
|
478
|
+
assert.equal(second.isError, undefined, textOf(second));
|
|
479
|
+
assert.equal(windows().length - before, 2, "one master-password window per call");
|
|
480
|
+
assert.match(textOf(second), /every-pw/);
|
|
481
|
+
assert.equal(readdirSync(join(runtime, "ai-vault", "sessions")).length, 0, "still nothing on disk");
|
|
482
|
+
} finally {
|
|
483
|
+
for (const [k, v] of Object.entries(saved)) {
|
|
484
|
+
if (v === undefined) delete process.env[k];
|
|
485
|
+
else process.env[k] = v;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
test("time mode: a second process with the store's secret adopts an existing unlock; one without it does not", async () => {
|
|
491
|
+
// The whole point of `time`: tab A unlocks, tab B (a fresh process, no
|
|
492
|
+
// token) reads without asking. droid's review found this was never true —
|
|
493
|
+
// the shared secret only let a token be *verified*, never *found*.
|
|
494
|
+
const { mkdtempSync, readdirSync } = await import("node:fs");
|
|
495
|
+
const { join } = await import("node:path");
|
|
496
|
+
const { spawnSync } = await import("node:child_process");
|
|
497
|
+
const box = mkdtempSync(join(process.env.TMPDIR ?? "/tmp", "ai-vault-time-"));
|
|
498
|
+
const store = join(box, "store");
|
|
499
|
+
const runtime = join(box, "runtime");
|
|
500
|
+
const bin = process.env.AI_VAULT_BIN;
|
|
501
|
+
const secret = "a".repeat(64);
|
|
502
|
+
const asHost = (secret) => ({ ...process.env, AI_VAULT_DIR: store, XDG_RUNTIME_DIR: runtime, AI_VAULT_HOST: "1", AI_VAULT_HOST_SECRET: secret });
|
|
503
|
+
const run = (env, args, input) => spawnSync(bin, args, { input, env, encoding: "utf8" });
|
|
504
|
+
const { forgetSettings } = await import("../packages/pi-ai-vault/src/settings.ts");
|
|
505
|
+
forgetSettings();
|
|
506
|
+
try {
|
|
507
|
+
assert.equal(run(asHost(secret), ["init", "--password-stdin", "--json"], `${PW}\n`).status, 0);
|
|
508
|
+
const token = JSON.parse(run(asHost(secret), ["unlock", "--password-stdin", "--json"], `${PW}\n`).stdout).token;
|
|
509
|
+
assert.equal(run(asHost(secret), ["add", "--name", "Shared", "--username", "u", "--password-stdin", "--yes", "--token", token], "shared-pw\n").status, 0);
|
|
510
|
+
assert.ok(readdirSync(join(runtime, "ai-vault", "sessions")).length >= 1, "an unlock is on disk");
|
|
511
|
+
// Tab B: the same store secret, no token, a fresh process.
|
|
512
|
+
const adopted = run(asHost(secret), ["get", "Shared", "--json"]);
|
|
513
|
+
assert.equal(adopted.status, 0, adopted.stderr);
|
|
514
|
+
assert.equal(JSON.parse(adopted.stdout).password, "shared-pw");
|
|
515
|
+
// A process without the secret is refused, token or not.
|
|
516
|
+
assert.equal(run(asHost("0".repeat(64)), ["list", "--json"]).status, 5);
|
|
517
|
+
assert.equal(run(asHost("0".repeat(64)), ["status", "--token", token, "--json"]).status, 5);
|
|
518
|
+
// A human (the wrap key) cannot adopt a host's session either.
|
|
519
|
+
const human = { ...process.env, AI_VAULT_DIR: store, XDG_RUNTIME_DIR: runtime, AI_VAULT_HOST: "", AI_VAULT_HOST_SECRET: "" };
|
|
520
|
+
assert.equal(run(human, ["list", "--json"]).status, 5);
|
|
521
|
+
} finally {
|
|
522
|
+
forgetSettings();
|
|
523
|
+
}
|
|
524
|
+
});
|