@xiaolikt/ai-vault 0.11.0 → 0.12.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 +32 -5
- package/README.zh.md +14 -5
- package/crates/ai-vault/Cargo.toml +1 -1
- package/crates/ai-vault/src/cli.rs +188 -62
- package/crates/ai-vault/src/config.rs +41 -12
- package/crates/ai-vault/src/crypto.rs +69 -18
- package/crates/ai-vault/src/dialog.rs +185 -37
- package/crates/ai-vault/src/sealed.rs +1 -9
- package/crates/ai-vault/src/session.rs +79 -22
- package/package.json +4 -4
- package/packages/pi-ai-vault/package.json +2 -2
- package/packages/pi-ai-vault/src/bitwarden.ts +154 -27
- package/packages/pi-ai-vault/src/cli.ts +117 -25
- package/packages/pi-ai-vault/src/ente.ts +5 -2
- package/packages/pi-ai-vault/src/index.ts +51 -6
- package/packages/pi-ai-vault/src/settings.ts +37 -7
- package/test/cli.sh +68 -24
- package/tests/ente.test.mjs +25 -6
- package/tests/helpers.mjs +42 -5
- package/tests/vault-cli.test.mjs +21 -19
- package/tests/windows.test.mjs +416 -0
package/Cargo.lock
CHANGED
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ client of it, so agents no longer keep a copy each.
|
|
|
11
11
|
~/.ai-vault/audit.log who read what and when; never a value
|
|
12
12
|
~/.ai-vault/store.lock file lock for read-modify-write across processes
|
|
13
13
|
$XDG_RUNTIME_DIR/ai-vault/sessions/<token>.json unlock tokens (0600, tmpfs)
|
|
14
|
+
%TEMP%\ai-vault\sessions\<token>.json the same on Windows: a regular file under the user's profile
|
|
14
15
|
```
|
|
15
16
|
|
|
16
17
|
Because the location is fixed and owned by the CLI, pi, omp, scripts and any
|
|
@@ -70,7 +71,7 @@ must not be rewritten).
|
|
|
70
71
|
| Platform | Status |
|
|
71
72
|
|---|---|
|
|
72
73
|
| Linux x64 / arm64 | ✅ published (`@xiaolikt/ai-vault-linux-x64` / `-linux-arm64`) |
|
|
73
|
-
| Windows x64 | ✅ published (`@xiaolikt/ai-vault-win32-x64`); dialogs via PowerShell
|
|
74
|
+
| Windows x64 | ✅ published (`@xiaolikt/ai-vault-win32-x64`); dialogs via Windows PowerShell + WinForms, both built in |
|
|
74
75
|
| macOS arm64 / x64 | 🔧 compiles (`cargo check --target aarch64-apple-darwin` passes); the binary needs the Apple SDK, so `.github/workflows/build.yml` builds it on a macOS runner |
|
|
75
76
|
|
|
76
77
|
What is portable:
|
|
@@ -79,7 +80,8 @@ What is portable:
|
|
|
79
80
|
- **Permissions**: 0600/0700 on Unix; Windows has no mode bits and relies on the
|
|
80
81
|
`%USERPROFILE%\.ai-vault` ACL
|
|
81
82
|
- **Session directory**: `$XDG_RUNTIME_DIR` (Linux), `$TMPDIR` (macOS), `%TEMP%`
|
|
82
|
-
(Windows) — per-user,
|
|
83
|
+
(Windows) — per-user; tmpfs on Linux, and on Windows a regular folder that the
|
|
84
|
+
next `ai-vault` run sweeps of expired tokens
|
|
83
85
|
- **Dialogs**: zenity / osascript / PowerShell+WinForms behind one `Answer`
|
|
84
86
|
contract (`NoUi` is what falls back to the host prompt)
|
|
85
87
|
|
|
@@ -96,7 +98,30 @@ cargo zigbuild --release --target x86_64-pc-windows-gnu
|
|
|
96
98
|
|
|
97
99
|
`stage-npm.sh` accepts either an npm platform name (`darwin-arm64`) or a Rust
|
|
98
100
|
triple (`aarch64-apple-darwin`). macOS binaries can only be linked with the
|
|
99
|
-
Apple SDK, so CI does that (build + publish on a `v*` tag).
|
|
101
|
+
Apple SDK, so CI does that (build + publish on a `v*` tag). The darwin packages
|
|
102
|
+
are already listed under `optionalDependencies`; npm skips an optional
|
|
103
|
+
dependency that is not published yet, so the list can precede them.
|
|
104
|
+
`--from` refuses a binary older than the last version bump, and one that can run
|
|
105
|
+
here must also report the version being published.
|
|
106
|
+
|
|
107
|
+
### Windows
|
|
108
|
+
|
|
109
|
+
- **The extension starts `ai-vault.exe` itself.** Node will not run npm's
|
|
110
|
+
`.cmd`/`.ps1` wrappers without a shell, so the plugin resolves the binary of
|
|
111
|
+
`@xiaolikt/ai-vault-win32-x64` directly and, where only a wrapper exists, reads
|
|
112
|
+
it and starts what it names with its own Node.
|
|
113
|
+
- **A dialog needs an interactive session.** Services, scheduled tasks that run
|
|
114
|
+
without a logged-on user and sshd sessions have no visible desktop; there the
|
|
115
|
+
CLI answers exit code 3 (`needs-ui`) and the host prompt is used. A window
|
|
116
|
+
nobody answers closes after the same 600 s as on Linux, and counts as a cancel.
|
|
117
|
+
- **What is typed in a dialog is UTF-8**, whatever the console's code page is
|
|
118
|
+
(936 on a Chinese Windows). A dialog that fails to open is reported as
|
|
119
|
+
`needs-ui`, never as a cancel.
|
|
120
|
+
- **`bw` installed with npm works** (`bw.cmd` is unwrapped the same way).
|
|
121
|
+
`bw_run` needs Git for Windows: `bash.exe` is looked up next to the `git.exe`
|
|
122
|
+
on PATH. The clipboard goes through Windows PowerShell, as UTF-8 on stdin and
|
|
123
|
+
stdout.
|
|
124
|
+
- The store is `%USERPROFILE%\.ai-vault`, protected by the profile's ACL.
|
|
100
125
|
|
|
101
126
|
### From source / git
|
|
102
127
|
|
|
@@ -435,7 +460,7 @@ may *use* passwords but cannot *get around you* to take them.
|
|
|
435
460
|
|---|---|---|
|
|
436
461
|
| **You** (typing `ai-vault` in a terminal) | everything | — |
|
|
437
462
|
| **The host** (the pi/omp extension process; `AI_VAULT_HOST=1` + a secret in memory) | relay your confirmations (signed), change settings | learn the master password unless you type it |
|
|
438
|
-
| **The agent** (the model's `bash`, same user, can read `~/.ai-vault`) | read a token file (but a session the extension opened is useless without the secret — first use
|
|
463
|
+
| **The agent** (the model's `bash`, same user, can read `~/.ai-vault`) | read a token file (but a session the extension opened is useless without the secret — first use is refused) | **forge a read confirmation, mint a grant on a token, change the requester shown in a window, `list` an extension session, get the Bitwarden master password, change any setting by editing a file** |
|
|
439
464
|
| **Another user / someone with the files offline** | read ciphertext | decrypt (scrypt + ChaCha20-Poly1305) |
|
|
440
465
|
|
|
441
466
|
### How
|
|
@@ -471,7 +496,9 @@ may *use* passwords but cannot *get around you* to take them.
|
|
|
471
496
|
upgrades it. Anything below `2^15` is refused as a downgrade.
|
|
472
497
|
- **The master password** only passes through a dialog or the host prompt; the
|
|
473
498
|
key `unlock` derives only goes into the token file (0600, tmpfs when there is
|
|
474
|
-
one
|
|
499
|
+
one; on Windows a regular file under `%TEMP%`, protected by the profile's ACL,
|
|
500
|
+
which a reboot leaves in place until the next `ai-vault` run removes it once
|
|
501
|
+
expired). `BW_*` is stripped from every child environment.
|
|
475
502
|
- **Audit**: `~/.ai-vault/audit.log` records sessions, entries, allow/deny with
|
|
476
503
|
the reason, and attempts such as `unsigned-relay`, `bad-approval`,
|
|
477
504
|
`modified-outside`; never a value. Rotated at 1 MiB.
|
package/README.zh.md
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
~/.ai-vault/audit.log 谁在什么时候读了什么,从不记值
|
|
10
10
|
~/.ai-vault/store.lock 多进程读改写时的文件锁
|
|
11
11
|
$XDG_RUNTIME_DIR/ai-vault/sessions/<token>.json 解锁令牌(0600,tmpfs)
|
|
12
|
+
%TEMP%\ai-vault\sessions\<token>.json Windows:同样的内容,用户目录下的普通文件
|
|
12
13
|
```
|
|
13
14
|
|
|
14
15
|
因为位置是固定的、由 CLI 独占的,所以同一台机器上 pi、omp、脚本、别的 agent 拿到的都是同一批已导入的密码,不会再出现「这个 agent 导过、那个没导过」。
|
|
@@ -64,21 +65,21 @@ printf '//registry.npmjs.org/:_authToken=%s\n' "<token>" > ~/.npmrc && chmod 600
|
|
|
64
65
|
|
|
65
66
|
这类令牌 npm 会在 2027 年 1 月起逐步作废,届时改用 trusted publishing 或 TOTP 2FA。
|
|
66
67
|
|
|
67
|
-
别的平台要有自己的二进制包:`./scripts/stage-npm.sh darwin-arm64 --from
|
|
68
|
+
别的平台要有自己的二进制包:`./scripts/stage-npm.sh darwin-arm64 --from <交叉编译产物>`。darwin 的两个包已经列在 `optionalDependencies` 里,还没发布时 npm 会跳过 optional 依赖,所以列表可以先于包存在。没有匹配的平台包时,shim 会明确报错并提示 `cargo install --path crates/ai-vault`。`--from` 会拒绝早于上一次改版本号的二进制;能在本机运行的二进制,还必须自报正在发布的版本。
|
|
68
69
|
|
|
69
70
|
### 平台
|
|
70
71
|
|
|
71
72
|
| 平台 | 状态 |
|
|
72
73
|
|---|---|
|
|
73
74
|
| Linux x64 / arm64 | ✅ 已发布(`@xiaolikt/ai-vault-linux-x64` / `-linux-arm64`) |
|
|
74
|
-
| Windows x64 | ✅ 已发布(`@xiaolikt/ai-vault-win32-x64
|
|
75
|
+
| Windows x64 | ✅ 已发布(`@xiaolikt/ai-vault-win32-x64`),对话框走系统自带的 Windows PowerShell + WinForms |
|
|
75
76
|
| macOS arm64 / x64 | 🔧 代码已可编译(`cargo check --target aarch64-apple-darwin` 通过),二进制需要 Apple SDK —— 由 `.github/workflows/build.yml` 的 macOS runner 产出 |
|
|
76
77
|
|
|
77
78
|
跨平台的部分:
|
|
78
79
|
- **加密/存储**:纯 Rust(chacha20poly1305、scrypt、hmac、sha2、base64、zeroize)
|
|
79
80
|
- **文件锁**:`fs4`(Linux/macOS 用 flock,Windows 用 LockFileEx)
|
|
80
81
|
- **权限**:Unix 设 0600/0700;Windows 没有位权限,靠 `%USERPROFILE%\.ai-vault` 的 ACL
|
|
81
|
-
- **会话目录**:Linux `$XDG_RUNTIME_DIR`、macOS `$TMPDIR`、Windows `%TEMP
|
|
82
|
+
- **会话目录**:Linux `$XDG_RUNTIME_DIR`、macOS `$TMPDIR`、Windows `%TEMP%`,都是每人一份;Linux 上是 tmpfs,Windows 上是普通目录,过期的令牌由下一次 `ai-vault` 运行清掉
|
|
82
83
|
- **弹窗**:Linux zenity / macOS osascript / Windows PowerShell+WinForms,同一套 `Answer` 契约(`NoUi` 才回退到宿主输入框)
|
|
83
84
|
|
|
84
85
|
自己交叉编译(不需要 Mac/Windows 机器):
|
|
@@ -94,6 +95,14 @@ cargo zigbuild --release --target x86_64-pc-windows-gnu
|
|
|
94
95
|
|
|
95
96
|
`stage-npm.sh` 两种写法都收:npm 平台名(`darwin-arm64`)或 Rust triple(`aarch64-apple-darwin`)。macOS 的二进制只能用 Apple SDK 链,所以留给 CI(tag push 时自动构建 + 发布)。
|
|
96
97
|
|
|
98
|
+
### Windows
|
|
99
|
+
|
|
100
|
+
- **插件直接启动 `ai-vault.exe`。** Node 不带 shell 跑不了 npm 的 `.cmd`/`.ps1` 包装器,所以插件直接解析 `@xiaolikt/ai-vault-win32-x64` 里的二进制;只有包装器时,读出它指向的目标,用自己的 Node 启动。
|
|
101
|
+
- **弹窗需要交互式会话。** 服务、"用户未登录也运行"的计划任务、sshd 会话里没有可见桌面,CLI 会返回退出码 3(`needs-ui`),改用宿主输入框。没人应答的窗口和 Linux 一样在 600 秒后关闭,按取消处理。
|
|
102
|
+
- **弹窗里输入的内容一律是 UTF-8**,不管控制台代码页是什么(中文 Windows 是 936)。打不开的窗口报成 `needs-ui`,不会被当成取消。
|
|
103
|
+
- **npm 装的 `bw` 可用**(`bw.cmd` 同样被拆开启动)。`bw_run` 需要 Git for Windows:在 PATH 上 `git.exe` 的旁边找 `bash.exe`。剪贴板走 Windows PowerShell,值以 UTF-8 走 stdin/stdout。
|
|
104
|
+
- 库在 `%USERPROFILE%\.ai-vault`,靠用户目录的 ACL 保护。
|
|
105
|
+
|
|
97
106
|
### 从源码 / git
|
|
98
107
|
|
|
99
108
|
```bash
|
|
@@ -364,7 +373,7 @@ pi-ai-vault 只是这套 CLI 的客户端,本身不保存 Ente 的任何密钥
|
|
|
364
373
|
|---|---|---|
|
|
365
374
|
| **你**(终端里手敲 `ai-vault`) | 一切 | — |
|
|
366
375
|
| **宿主**(pi/omp 扩展进程,持 `AI_VAULT_HOST=1` + 内存里的 host secret) | 替你转发确认(要签名)、改设置 | 不知道主密码(除非你输了) |
|
|
367
|
-
| **agent**(模型的 `bash`,同一用户,能读 `~/.ai-vault`) | 读到会话令牌文件(但插件开的会话没有 secret
|
|
376
|
+
| **agent**(模型的 `bash`,同一用户,能读 `~/.ai-vault`) | 读到会话令牌文件(但插件开的会话没有 secret,一用就被拒) | **伪造一次读取确认、给令牌加授权、改确认窗里的请求方、`list` 插件会话、拿到 Bitwarden 主密码、靠改文件改任何设置** |
|
|
368
377
|
| **别的用户 / 离线拿到文件的人** | 读到密文 | 解密(scrypt + ChaCha20-Poly1305) |
|
|
369
378
|
|
|
370
379
|
### 怎么做到的
|
|
@@ -376,7 +385,7 @@ pi-ai-vault 只是这套 CLI 的客户端,本身不保存 Ente 的任何密钥
|
|
|
376
385
|
- **Bitwarden 会话密钥加密封存。** `bitwarden.unlock = never|time` 时,`bw` 的会话密钥用 ChaCha20-Poly1305 封在 `~/.ai-vault/bitwarden.session.json` 下,密钥是 `~/.ai-vault/.wrap`(0600)。单独拷走那个文件什么都打不开。`bw unlock --raw` 的会话密钥等价于**整个** Bitwarden 保险库的读权限,所以这个文件的敏感度 ≥ 库本身。
|
|
377
386
|
- **确认窗里的字不是模型写的。** 条目名、原因、用户名、URI 进窗口前都压成一行、去掉控制字符、截到 80–120 字符,模型没法在名字里塞换行伪造第二条「已授权」。
|
|
378
387
|
- **KDF。** 新库 scrypt `N=2^17`(128 MiB);文件头记着参数,旧库(`N=2^15`)照常打开,`ai-vault rekey` 升级。低于 `2^15` 的参数一律拒收(防降级)。
|
|
379
|
-
- **主密码**只经过弹窗或宿主输入框;`unlock` 派生的 key 只写进令牌文件(0600,优先 tmpfs
|
|
388
|
+
- **主密码**只经过弹窗或宿主输入框;`unlock` 派生的 key 只写进令牌文件(0600,优先 tmpfs;Windows 上是 `%TEMP%` 下的普通文件,靠用户目录的 ACL 保护,重启后仍在,过期后由下一次 `ai-vault` 运行删除)。`BW_*` 在所有子进程环境里剔除。
|
|
380
389
|
- **审计**:`~/.ai-vault/audit.log` 记录会话、条目、允许/拒绝/原因、以及 `unsigned-relay`、`bad-approval`、`modified-outside` 这类尝试,从不记值;1 MiB 轮转。
|
|
381
390
|
- **原子写 + flock**:临时文件(0600)→ fsync → rename → 目录 fsync;多进程读改写有文件锁。失效/被改/旧库的令牌文件每次调用都会被清掉。
|
|
382
391
|
- `bw_reveal` 默认关闭;擦洗只在值长度 ≥ 6 时生效,防不住网络外传和单向哈希——`bw_run` / `bw_inject` 的价值是值不进对话,不是防住被注入的 agent。
|