pi-ai-vault 0.8.0 → 0.9.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/README.md CHANGED
@@ -65,7 +65,9 @@ omp plugin install npm:pi-ai-vault # omp,同一个包
65
65
 
66
66
  ## Ente
67
67
 
68
- `ente` CLI 自己登录一次(`ente account login --app auth`),插件只是它的客户端:`ente_list` 只给元数据,`ente_code` 每次弹窗确认。详见仓库 README。
68
+ `ente` CLI 自己登录一次(`ente account login --app auth`),插件只是它的客户端:`ente_list` 只给元数据,`ente_code` 每次弹窗确认。
69
+
70
+ 想完全免钥匙串:`ente vault key generate` → `/vault ente-key` 粘进去 → `/vault settings ente.unlock never`。密钥由 ai-vault 加密封存。详见仓库 README。
69
71
 
70
72
  ## 安全边界(一句话版)
71
73
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-ai-vault",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "pi extension for ai-vault: one machine-wide encrypted secret store plus live Bitwarden. 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.8.0"
28
+ "@xiaolikt/ai-vault": "0.9.1"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@earendil-works/pi-coding-agent": "^1.5.0",
package/src/cli.ts CHANGED
@@ -64,20 +64,29 @@ export function resolveBinary(): string | undefined {
64
64
  // pip/npm layouts hoist differently: walk up from packages/pi-ai-vault/src.
65
65
  let dir = dirname(fileURLToPath(import.meta.url));
66
66
  for (let depth = 0; depth < 5; depth++) {
67
- const bundled = join(dir, "node_modules", ".bin", "ai-vault");
68
- if (existsSync(bundled)) return bundled;
67
+ for (const name of process.platform === "win32" ? ["ai-vault.exe", "ai-vault.cmd", "ai-vault.ps1"] : ["ai-vault"]) {
68
+ const bundled = join(dir, "node_modules", ".bin", name);
69
+ if (existsSync(bundled)) return bundled;
70
+ }
69
71
  const parent = dirname(dir);
70
72
  if (parent === dir) break;
71
73
  dir = parent;
72
74
  }
73
75
 
76
+ // Windows has no execute bit and npm links .cmd/.ps1 wrappers beside the exe.
77
+ const names = process.platform === "win32" ? ["ai-vault.exe", "ai-vault.cmd", "ai-vault.ps1", "ai-vault"] : ["ai-vault"];
74
78
  for (const entry of (process.env.PATH ?? "").split(delimiter)) {
75
79
  if (!entry) continue;
76
- const candidate = join(entry, "ai-vault");
77
- if (existsSync(candidate)) return candidate;
80
+ for (const name of names) {
81
+ const candidate = join(entry, name);
82
+ if (existsSync(candidate)) return candidate;
83
+ }
78
84
  }
79
- for (const candidate of [join(homedir(), ".local", "bin", "ai-vault"), join(homedir(), ".cargo", "bin", "ai-vault")]) {
80
- if (existsSync(candidate)) return candidate;
85
+ for (const base of [join(homedir(), ".local", "bin"), join(homedir(), ".cargo", "bin"), join(homedir(), ".ai-vault", "bin")]) {
86
+ for (const name of names) {
87
+ const candidate = join(base, name);
88
+ if (existsSync(candidate)) return candidate;
89
+ }
81
90
  }
82
91
  return undefined;
83
92
  }
package/src/ente.ts CHANGED
@@ -25,6 +25,7 @@ import { Type } from "typebox";
25
25
  import { auditEvent } from "./bitwarden.js";
26
26
  import { confirmWindow, forDialog } from "./prompt.js";
27
27
  import { withTier } from "./host.js";
28
+ import { getSettingsSafe, settingsCli } from "./settings.js";
28
29
 
29
30
  export interface EnteCodeMeta {
30
31
  id: string;
@@ -74,12 +75,37 @@ interface Run {
74
75
  stderr: string;
75
76
  }
76
77
 
78
+ /**
79
+ * The environment for one `ente` run.
80
+ *
81
+ * `ente.unlock = never | time`: the key is kept sealed by ai-vault (the same
82
+ * wrapping as the Bitwarden session), so Ente needs neither the OS keychain
83
+ * nor a login window. `session` (default) leaves the keychain in charge and
84
+ * passes nothing.
85
+ */
86
+ async function enteEnv(signal?: AbortSignal): Promise<Record<string, string | undefined>> {
87
+ const env: Record<string, string | undefined> = { ...process.env };
88
+ // Never let a key the user exported in their shell decide this.
89
+ delete env.ENTE_CLI_VAULT_KEY;
90
+ const settings = await getSettingsSafe(signal);
91
+ if (settings.ente.unlock === "session") return env;
92
+ try {
93
+ const sealed = await settingsCli().json<{ key: string }>(["ente-session", "get"], { signal });
94
+ if (sealed?.key) env.ENTE_CLI_VAULT_KEY = sealed.key;
95
+ } catch {
96
+ // No key saved yet, or it expired: ente will fall back to the keychain,
97
+ // which is exactly what a `session` policy would have done.
98
+ }
99
+ return env;
100
+ }
101
+
77
102
  async function runEnte(args: string[], signal?: AbortSignal): Promise<Run> {
78
103
  const bin = resolveEnte();
79
104
  if (!bin) throw new EnteError(ENTE_MISSING, 127);
80
105
  if (signal?.aborted) throw new EnteError("Cancelled.", 4);
106
+ const env = await enteEnv(signal);
81
107
  return new Promise<Run>((resolve, reject) => {
82
- const child = spawn(bin, args, { stdio: ["ignore", "pipe", "pipe"] });
108
+ const child = spawn(bin, args, { stdio: ["ignore", "pipe", "pipe"], env });
83
109
  let stdout = "";
84
110
  let stderr = "";
85
111
  const onAbort = () => child.kill("SIGKILL");
package/src/index.ts CHANGED
@@ -636,7 +636,8 @@ const HELP = [
636
636
  "/vault init 创建全机共享的本地加密库(弹出窗口设置主密码)",
637
637
  "/vault unlock | lock 解锁 / 锁定(清空本会话的授权)",
638
638
  "/vault mode [never|time|session] 查看/切换解锁模式(切换要主密码)",
639
- "/vault settings [键 值] 查看/修改设置(vault.unlock、bitwarden.unlock、bitwarden.import …)",
639
+ "/vault settings [键 值] 查看/修改设置(vault.unlock、bitwarden.*、ente.* …)",
640
+ "/vault ente-key 保存 ente 的 ENTE_CLI_VAULT_KEY(免钥匙串/免登录)",
640
641
  "/vault status 状态与授权剩余时间",
641
642
  "/vault list 本地条目元数据",
642
643
  "/vault add [名称] 新增本地条目(用户名、密码在弹窗里输入)",
@@ -711,6 +712,9 @@ function settingsText(s: Settings): string {
711
712
  `bitwarden.hours: ${s.bitwarden.hours}`,
712
713
  `bitwarden.import: ${s.bitwarden.import} (ask | always | never)`,
713
714
  `bitwarden 已落盘的会话: ${persisted}`,
715
+ `ente.unlock: ${s.ente.unlock} (never | time | session)`,
716
+ `ente.hours: ${s.ente.hours}`,
717
+ `ente 已落盘的密钥: ${s.ente.persisted ? "有" : "无"}`,
714
718
  ].join("\n");
715
719
  }
716
720
 
@@ -782,6 +786,24 @@ function commandHandler(scope: Scope, bw: BwState) {
782
786
  }
783
787
  return;
784
788
  }
789
+ case "ente-key": {
790
+ // Ente's unattended key: generated by `ente vault key generate`.
791
+ // Saved sealed, so `ente.unlock = never | time` can use it.
792
+ const key = await promptSecret(dialogs(ctx), "ai-vault · Ente 密钥", "ente vault key generate 输出的密钥");
793
+ if (!key) {
794
+ note(ctx, "已取消", "warning");
795
+ return;
796
+ }
797
+ try {
798
+ const args = ["ente-session", "put"];
799
+ await cli.run(args, { stdin: key });
800
+ forgetSettings();
801
+ note(ctx, "已保存(封存)。现在可以设置 /vault settings ente.unlock never");
802
+ } catch (error) {
803
+ note(ctx, `ai-vault: ${describe(error)}`, "error");
804
+ }
805
+ return;
806
+ }
785
807
  case "settings": {
786
808
  const [key, ...valueParts] = rest;
787
809
  const value = valueParts.join(" ").trim();
package/src/settings.ts CHANGED
@@ -19,11 +19,14 @@ export interface Settings {
19
19
  persisted: boolean;
20
20
  expiresAt: number | null;
21
21
  };
22
+ /** Ente's ENTE_CLI_VAULT_KEY: session leaves it to the OS keychain. */
23
+ ente: { unlock: UnlockModeName; hours: number; persisted: boolean; expiresAt: number | null };
22
24
  }
23
25
 
24
26
  export const DEFAULT_SETTINGS: Settings = {
25
27
  vault: { unlock: "session", hours: 8, auto: false },
26
28
  bitwarden: { unlock: "session", hours: 8, import: "ask", persisted: false, expiresAt: null },
29
+ ente: { unlock: "session", hours: 8, persisted: false, expiresAt: null },
27
30
  };
28
31
 
29
32
  const cli = new VaultCli();