@xiaolikt/ai-vault 0.9.0 → 0.10.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 CHANGED
@@ -1,348 +1,490 @@
1
1
  # ai-vault
2
2
 
3
- 一台电脑一个加密密码库。`ai-vault` 是一个 Rust 写的 CLI,库文件、加解密、桌面弹窗全在它里面;pi / omp 的插件只是它的客户端,不再各存一份。
3
+ [中文版](README.zh.md)
4
+
5
+ One encrypted secret store per machine. `ai-vault` is a Rust CLI that owns the
6
+ store, the cryptography and the desktop dialogs; the pi/omp extension is only a
7
+ client of it, so agents no longer keep a copy each.
4
8
 
5
9
  ```
6
- ~/.ai-vault/store.json ChaCha20-Poly1305 + scrypt,0600
7
- ~/.ai-vault/audit.log 谁在什么时候读了什么,从不记值
8
- ~/.ai-vault/store.lock 多进程读改写时的文件锁
9
- $XDG_RUNTIME_DIR/ai-vault/sessions/<token>.json 解锁令牌(0600,tmpfs)
10
+ ~/.ai-vault/store.json ChaCha20-Poly1305 + scrypt, 0600
11
+ ~/.ai-vault/audit.log who read what and when; never a value
12
+ ~/.ai-vault/store.lock file lock for read-modify-write across processes
13
+ $XDG_RUNTIME_DIR/ai-vault/sessions/<token>.json unlock tokens (0600, tmpfs)
10
14
  ```
11
15
 
12
- 因为位置是固定的、由 CLI 独占的,所以同一台机器上 pi、omp、脚本、别的 agent 拿到的都是同一批已导入的密码,不会再出现「这个 agent 导过、那个没导过」。
16
+ Because the location is fixed and owned by the CLI, pi, omp, scripts and any
17
+ other agent on the machine see the same imported passwords. No more "this agent
18
+ imported it, that one didn't".
19
+
20
+ ## Why a CLI plus an extension
13
21
 
14
- ## 为什么是 CLI + 插件
22
+ - **One implementation of the cryptography** (Rust). The extension holds no key,
23
+ no crypto code and no second store.
24
+ - **Sessions do not live in the agent process.** `ai-vault unlock` derives the
25
+ key and writes a short token file; the extension only holds the token id. If
26
+ the agent crashes, reloads or switches session, the key expires with the token.
27
+ - **One dialog implementation.** With a desktop the CLI opens its own window;
28
+ without one it exits with code `3` and only then does the extension use its
29
+ host's prompt. Two windows never compete for input.
30
+ - **Easy to add a host.** Any new agent, in any language, uses the same store if
31
+ it can run `ai-vault get <name> --json`.
15
32
 
16
- - **加密只有一份实现**(Rust),插件里没有密钥、没有 crypto 代码,也没有第二份库。
17
- - **会话不在 agent 进程里**:`ai-vault unlock` 派生 key 后写一个短命令牌文件,插件只持有令牌 id。agent 崩了、被 reload、换会话,key 都跟着令牌一起过期。
18
- - **弹窗只有一份逻辑**:有桌面时 CLI 自己开 zenity;没有桌面时返回退出码 `3`,插件才用自己的输入框,绝不出现两个窗口抢输入。
19
- - **换宿主很容易**:任何语言写的新 agent 只要会跑 `ai-vault get <名字> --json` 就能用同一个库。
33
+ ## Language
20
34
 
21
- ## 安装
35
+ Documentation is English by default; [README.zh.md](README.zh.md) is the Chinese
36
+ edition. The CLI and the extension show English in dialogs, prompts and
37
+ messages unless `AI_VAULT_LANG=zh` is set (or the locale is `zh_*`); the
38
+ extension passes the language down to the CLI so both halves agree. Texts a
39
+ host parses — exit codes, `needs-ui:`, error patterns — never change.
40
+
41
+ ## Install
22
42
 
23
43
  ### npm
24
44
 
25
- 三个包:
45
+ Three packages:
26
46
 
27
- | 包 | 内容 | 谁装 |
47
+ | Package | Contents | Who installs it |
28
48
  |---|---|---|
29
- | `@xiaolikt/ai-vault` | `bin/ai-vault.cjs` 转发器 + Rust 源码 | 想只要 CLI 的人 |
30
- | `@xiaolikt/ai-vault-linux-x64` | 预编译二进制,`os/cpu` 限定 | 被上一条自动拉下来 |
31
- | **`pi-ai-vault`** | pi/omp 插件(`vault_*` + `bw_*` 工具) | pi 或 omp,依赖上一条 |
49
+ | `@xiaolikt/ai-vault` | the `bin/ai-vault.cjs` dispatcher + Rust sources | anyone who wants just the CLI |
50
+ | `@xiaolikt/ai-vault-<os>-<arch>` | the prebuilt binary, `os`/`cpu` gated | pulled in by the above |
51
+ | **`pi-ai-vault`** | the pi/omp extension (`vault_*` + `bw_*` + `ente_*` tools) | pi or omp; depends on the above |
32
52
 
33
53
  ```bash
34
- npm i -g @xiaolikt/ai-vault # 只要 CLI
35
- pi install npm:pi-ai-vault # 插件(自动带上 CLI)
54
+ npm i -g @xiaolikt/ai-vault # just the CLI
55
+ pi install npm:pi-ai-vault # the extension (brings the CLI along)
36
56
  omp plugin install npm:pi-ai-vault
37
57
  ```
38
58
 
39
- 插件本身就是 pi 的扩展清单,omp 是 pi 的兼容分支,**同一个包在两个宿主里都能用**:omp 上会自动注册 `bw_run`、pi 上还会多一个 `bw_inject`,差别只在 `src/host.ts` 的运行时探测里。
59
+ The extension is a pi extension manifest; omp is a pi-compatible fork, so
60
+ **one package serves both hosts**: omp gets `bw_run`, pi additionally gets
61
+ `bw_inject`. The only differences are feature-detected at runtime in `src/host.ts`.
40
62
 
41
- npm 上的裸名 `ai-vault` 已被别人占用(3.5.1),所以 CLI 用 scope。主包里的 `bin/ai-vault.cjs` 只是个转发器:找到 `@xiaolikt/ai-vault-<os>-<arch>` 里的真二进制,把 argv、stdio 和**退出码**(3/4/5 是宿主契约,不能改)原样交出去。
63
+ The bare name `ai-vault` is taken on npm (3.5.1), hence the scope. `bin/ai-vault.cjs`
64
+ is only a forwarder: it finds the real binary in `@xiaolikt/ai-vault-<os>-<arch>`
65
+ and hands over argv, stdio and **the exit code** (3/4/5 are the host contract and
66
+ must not be rewritten).
42
67
 
43
- 发布(需要 `npm login`):
68
+ ### Platforms
44
69
 
45
- ```bash
46
- ./scripts/stage-npm.sh # 编译并staging到 npm/linux-x64
47
- npm publish npm/linux-x64 --access public
48
- npm publish --access public
49
- ```
50
-
51
- 邮箱 OTP 2FA 的账号不能直接用 `--otp` 发布(npm 会回 `E403 ... granular access token with bypass 2fa enabled is required`)。做法:网页 Settings → Access Tokens → **Granular Access Token**,勾上 *Bypass 2FA*、权限 *Read and write (publish and stage)*,把令牌写进 `~/.npmrc`:
70
+ | Platform | Status |
71
+ |---|---|
72
+ | Linux x64 / arm64 | ✅ published (`@xiaolikt/ai-vault-linux-x64` / `-linux-arm64`) |
73
+ | Windows x64 | ✅ published (`@xiaolikt/ai-vault-win32-x64`); dialogs via PowerShell/WinForms |
74
+ | 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
+ What is portable:
77
+ - **Crypto/storage**: pure Rust (chacha20poly1305, scrypt, hmac, sha2, base64, zeroize)
78
+ - **File locks**: `fs4` (flock on Linux/macOS, LockFileEx on Windows)
79
+ - **Permissions**: 0600/0700 on Unix; Windows has no mode bits and relies on the
80
+ `%USERPROFILE%\.ai-vault` ACL
81
+ - **Session directory**: `$XDG_RUNTIME_DIR` (Linux), `$TMPDIR` (macOS), `%TEMP%`
82
+ (Windows) — per-user, OS-cleaned
83
+ - **Dialogs**: zenity / osascript / PowerShell+WinForms behind one `Answer`
84
+ contract (`NoUi` is what falls back to the host prompt)
85
+
86
+ Cross-compile yourself (no Mac or Windows machine needed):
52
87
 
53
88
  ```bash
54
- printf '//registry.npmjs.org/:_authToken=%s\n' "<token>" > ~/.npmrc && chmod 600 ~/.npmrc
89
+ cargo install cargo-zigbuild
90
+ rustup target add aarch64-unknown-linux-gnu x86_64-pc-windows-gnu
91
+ cargo zigbuild --release --target aarch64-unknown-linux-gnu
92
+ cargo zigbuild --release --target x86_64-pc-windows-gnu
93
+ ./scripts/stage-npm.sh linux-arm64 --from target/aarch64-unknown-linux-gnu/release/ai-vault
94
+ ./scripts/stage-npm.sh win32-x64 --from target/x86_64-pc-windows-gnu/release/ai-vault.exe
55
95
  ```
56
96
 
57
- 这类令牌 npm 会在 2027 年 1 月起逐步作废,届时改用 trusted publishing 或 TOTP 2FA。
97
+ `stage-npm.sh` accepts either an npm platform name (`darwin-arm64`) or a Rust
98
+ 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).
58
100
 
59
- 别的平台要有自己的二进制包:`./scripts/stage-npm.sh darwin-arm64 --from <交叉编译产物>`,发布后把对应名字加进 `optionalDependencies`。没有匹配的平台包时,shim 会明确报错并提示 `cargo install --path crates/ai-vault`。
60
-
61
- ### 从源码 / git
101
+ ### From source / git
62
102
 
63
103
  ```bash
64
- # 1. 编译 CLI 并放进 PATH(~/.local/bin/ai-vault)
104
+ # 1. Build the CLI and put it on PATH (~/.local/bin/ai-vault)
65
105
  ./install.sh
66
106
 
67
- # 2. 插件(仓库根也有 pi 清单,指向 packages/pi-ai-vault,所以 git 装法依旧可用)
107
+ # 2. The extension (the repo root has a pi manifest pointing at
108
+ # packages/pi-ai-vault, so git installs keep working)
68
109
  pi install git:github.com/xiaolikt/ai-vault
69
110
  omp plugin install git+ssh://git@github.com/xiaolikt/ai-vault.git
70
111
 
71
- # 3. 建库(弹窗设主密码,两次)
112
+ # 3. Create the store (a dialog asks for the master password, twice)
72
113
  /vault init
73
114
  ```
74
115
 
75
- 要求:Rust(`cargo`)编译期用;运行时需要 `zenity` 才弹窗,没有就退回宿主的输入框。
116
+ Requires Rust (`cargo`) to build; at runtime `zenity` for dialogs (the host
117
+ prompt is the fallback).
76
118
 
77
- **不要同时安装旧的 `omp-vault` 和 `ai-vault`**:两边都注册 `vault_*` 工具,会重复。
119
+ **Do not install `omp-vault` or `pi-bitwarden` alongside ai-vault**: they
120
+ register the same `vault_*` / `bw_*` tools and you get duplicates. Both are
121
+ archived; see *Migrating*.
78
122
 
79
- ### 从 omp-vault 迁移
123
+ ### Migrating
80
124
 
81
- 第一次运行 `ai-vault` 时,如果 `~/.ai-vault/store.json` 不存在而 `~/.omp/vault/store.json` 存在,CLI 会**复制**(不删除)库和审计日志过去,主密码不变——文件格式没变,只是位置变了。旧文件留着,想回退随时可以。
125
+ - **From `omp-vault`** (the TypeScript predecessor): the first time `ai-vault`
126
+ runs and `~/.ai-vault/store.json` is absent while `~/.omp/vault/store.json`
127
+ exists, the CLI **copies** (never deletes) the store and audit log across.
128
+ The master password is unchanged — the file format is the same, only the
129
+ location moved. The old files stay for as long as you want a way back.
130
+ - **From `pi-bitwarden`** (archived): every tool it had is here under the same
131
+ name. `pi remove git:github.com/xiaolikt/pi-bitwarden` first, then install
132
+ `pi-ai-vault`.
82
133
 
83
134
  ## CLI
84
135
 
85
136
  ```text
86
- ai-vault [--dir DIR] [--json] <命令>
137
+ ai-vault [--dir DIR] [--json] <command>
87
138
  ```
88
139
 
89
- | 命令 | 作用 |
140
+ | Command | What it does |
90
141
  |---|---|
91
- | `path` | 打印库、会话目录的位置 |
92
- | `doctor` | 路径、是否初始化、有没有桌面和 zenity、版本 |
93
- | `init [--password-stdin]` | 建库(弹窗两次设密码),成功后直接给一个令牌 |
94
- | `unlock [--password-stdin] [--requester ID]` | 按当前模式解锁,stdout 一个令牌 |
95
- | `mode [get]` / `mode set never\|time\|session [--hours N]` | 查看/切换解锁模式(切换要主密码) |
96
- | `settings [键] [值]` | 全部设置:`vault.*` `bitwarden.*` `ente.unlock` `ente.hours` |
97
- | `bw-session get\|put\|clear` | Bitwarden 会话密钥的落盘副本(`bitwarden.unlock != session` 时用,加密封存) |
98
- | `ente-session get\|put\|clear` | Ente 的 `ENTE_CLI_VAULT_KEY`(`ente.unlock != session` 时用,同样加密封存) |
99
- | `rekey` | 把旧库的 scrypt 参数升到当前默认(要主密码) |
100
- | `status --token T` | 条目数、过期时间、还活着的读授权 |
101
- | `lock --token T \| --all` | 丢掉令牌(`--all` 清空本机所有会话) |
102
- | `list --token T` | 条目元数据(名称/用户名/URI),没有密码 |
103
- | `get <名字> [--reason R] [--answer-stdin]` | 读一条;没有授权时先弹确认窗 |
104
- | `add --name N [--username U] [--uri U] [--notes N] [--password-stdin] [--yes]` | 新增/更新;密码由弹窗输入 |
105
- | `save --yes [--file F]` | 从 stdin 读一组条目 JSON,批量写入(导入用) |
106
- | `remove <名字> [--yes]` | 删除(带空格的名称加引号) |
107
- | `grant <名字> [--minutes N]` / `revoke <名字\|--all>` | 手动给/撤读授权(默认 5 分钟,上限 60) |
108
- | `audit [n]` | 最近 n 条审计(默认 30) |
109
- | `import <bitwarden.json> [--yes]` | 从 Bitwarden 未加密导出导入 |
110
-
111
- 令牌也可以走环境变量:`AI_VAULT_TOKEN`。库目录:`--dir` / `AI_VAULT_DIR` / `~/.ai-vault`。
112
-
113
- ### 退出码(宿主集成契约)
114
-
115
- | 码 | 含义 | 宿主该做什么 |
142
+ | `path` | print the store and session locations |
143
+ | `doctor` | paths, whether initialised, desktop/zenity availability, KDF, version |
144
+ | `init [--password-stdin]` | create the store (a dialog sets the password twice); prints a token |
145
+ | `unlock [--password-stdin] [--requester ID]` | unlock under the current policy; prints a token |
146
+ | `mode [get]` / `mode set never\|time\|session [--hours N]` | show / switch the unlock policy (switching needs the master password) |
147
+ | `settings [key] [value]` | every setting: `vault.*` `bitwarden.*` `ente.*` |
148
+ | `bw-session get\|put\|clear` | the persisted `bw` session key (used when `bitwarden.unlock != session`; sealed at rest) |
149
+ | `ente-session get\|put\|clear` | Ente's `ENTE_CLI_VAULT_KEY` (used when `ente.unlock != session`; sealed the same way) |
150
+ | `rekey` | raise an old store's scrypt parameters to the current default (needs the master password) |
151
+ | `status --token T` | item count, expiry, live read grants |
152
+ | `lock --token T \| --all` | drop a token (`--all` ends every session on the machine) |
153
+ | `list --token T` | entry metadata (name/username/URI); no passwords |
154
+ | `get <name> [--reason R] [--answer-stdin]` | read one entry; a confirm window opens unless a grant is live |
155
+ | `add --name N [--username U] [--uri U] [--notes N] [--password-stdin] [--yes]` | create/update; the password is typed in a dialog |
156
+ | `save --yes [--file F]` | read an array of entries as JSON and write them (the import path) |
157
+ | `remove <name> [--yes]` | delete (quote names with spaces) |
158
+ | `grant <name> [--minutes N]` / `revoke <name\|--all>` | a standing read grant (default 5 min, max 60); `grant` costs the master password |
159
+ | `audit [n]` | the last n audit lines (default 30) |
160
+ | `import <bitwarden.json> [--yes]` | import an unencrypted Bitwarden export |
161
+
162
+ The token can also come from `AI_VAULT_TOKEN`. The store directory is `--dir`,
163
+ then `AI_VAULT_DIR`, then `~/.ai-vault`.
164
+
165
+ ### Exit codes (the host contract)
166
+
167
+ | Code | Meaning | What a host does |
116
168
  |---|---|---|
117
- | 0 | 成功 | stdout 是结果(`--json` 时是 JSON) |
118
- | 1 | 出错 | 把 stderr 第一行给用户看 |
119
- | 2 | 参数/用法错误 | 同上 |
120
- | 3 | 需要界面 | stderr 有 `needs-ui: password\|text\|confirm`;宿主自己弹框,把值经 stdin 送回并加对应开关 |
121
- | 4 | 用户拒绝/取消 | **不要重试**,问用户 |
122
- | 5 | 未解锁 / 密码错 | 重新 `unlock`,或提示主密码错误 |
169
+ | 0 | success | stdout is the result (JSON with `--json`) |
170
+ | 1 | error | show the first stderr line to the user |
171
+ | 2 | usage error | same |
172
+ | 3 | needs UI | stderr says `needs-ui: password\|text\|confirm`; the host prompts itself and sends the value back on stdin with the matching flag |
173
+ | 4 | user denied / cancelled | **do not retry**; ask the user |
174
+ | 5 | locked / wrong password | `unlock` again, or report the wrong password |
123
175
 
124
- 所以「没有桌面的机器」也能用:`unlock --password-stdin`、`add --password-stdin --yes`、`save --yes` 就是无界面路径。
176
+ So a headless machine works too: `unlock --password-stdin`, `add --password-stdin --yes`
177
+ and `save --yes` need no window at all.
125
178
 
126
- **转发确认是宿主特权**,需要三样东西同时成立:
179
+ **Relaying a confirmation is a host privilege** and needs all three of:
127
180
 
128
181
  ```bash
129
182
  AI_VAULT_HOST=1 \
130
- AI_VAULT_HOST_SECRET=<unlock 时返回的 hostSecret> \
131
- ai-vault get <条目> --token <T> --answer-stdin --approval <hex> <<< 'y'
132
- # approval = HMAC-SHA256(hostSecret, "allow:<T>:<条目小写>:y")
183
+ AI_VAULT_HOST_SECRET=<the secret the host minted> \
184
+ ai-vault get <entry> --token <T> --answer-stdin --approval <hex> <<< 'y'
185
+ # approval = HMAC-SHA256(hostSecret, "allow:<T>:<entry lowercased>:y")
133
186
  ```
134
187
 
135
- `unlock`/`init` 只在 `AI_VAULT_HOST=1` 时返回 `hostSecret`;它只存在于宿主进程内存里,CLI 用它给会话文件签名、用它核对转发。少了任何一样,`--answer-stdin` 都是退出码 2。这就是为什么模型的 `bash` 即使拿到令牌也签不出「允许」。
188
+ `unlock`/`init` only echo a `hostSecret` back to a caller that already presented
189
+ one. It exists only in the host process's memory; the CLI signs session files
190
+ with it and checks relays against it. Missing any one of the three, `--answer-stdin`
191
+ is exit code 2. That is why the model's `bash`, even with a token in hand,
192
+ cannot sign an "allow".
136
193
 
137
- ## 插件里的工具
194
+ ## Extension tools
138
195
 
139
- | 工具 | 作用 | 等级 | 模型看到密码? |
196
+ | Tool | What it does | Tier | Model sees the secret? |
140
197
  |---|---|---|---|
141
- | `vault_list` | 本地库元数据 | read | 否 |
142
- | `vault_get` | 读一条:**先本地库,再 Bitwarden**;命中后按 `bitwarden.import` 处理(问 / 直接导入 / 只读一次) | exec | 是,用户当场允许 |
143
- | `vault_add` | 存一条;密码在弹窗里输入 | write | 否 |
144
- | `vault_import` | 把 Bitwarden 登录项抄进本地库(先确认) | write | 否 |
145
- | `bw_list` | 查在线 Bitwarden 元数据 | read | 否 |
146
- | `bw_run` | 用 `$VAULT_SECRET` 跑一条命令,输出擦洗 | exec | 否 |
147
- | `bw_inject` | 注入 bash 环境(**仅 pi**) | exec | 否 |
148
- | `bw_clipboard` | 复制到剪贴板,到时清除 | write | 否 |
149
- | `bw_reveal` | 明文返回(默认关闭,每次确认) | exec | 是,用户当场允许 |
150
- | `ente_list` | Ente Auth 条目元数据(名称/签发方/账号/类型) | read | 否 |
151
- | `ente_code` | 读一条当前 TOTP/Steam 验证码,每次弹窗确认 | write | 是,用户当场允许 |
198
+ | `vault_list` | local store metadata | read | no |
199
+ | `vault_get` | read one: **local store first, Bitwarden second**; a Bitwarden hit follows `bitwarden.import` (ask / import / read once) | exec | yes, user-approved on the spot |
200
+ | `vault_add` | store one; the password is typed in a dialog | write | no |
201
+ | `vault_import` | copy Bitwarden logins into the local store (asks first) | write | no |
202
+ | `bw_list` | live Bitwarden metadata | read | no |
203
+ | `bw_run` | run one command with `$VAULT_SECRET` in its env; output scrubbed | exec | no |
204
+ | `bw_inject` | inject into the bash env (**pi only**) | exec | no |
205
+ | `bw_clipboard` | copy to the clipboard, cleared after a delay | write | no |
206
+ | `bw_reveal` | plain text (off by default, confirmed per call) | exec | yes, user-approved on the spot |
207
+ | `ente_list` | Ente Auth entry metadata (name/issuer/account/type) | read | no |
208
+ | `ente_code` | one current TOTP/Steam code, confirmed per call | write | yes, user-approved on the spot |
152
209
 
153
- Ente 的会话由 `ente` 自己管(登录一次);`ente.unlock` 只决定那把 `ENTE_CLI_VAULT_KEY` 要不要由 ai-vault 加密封存。
210
+ Ente's login is managed by `ente` itself (once); `ente.unlock` only decides
211
+ whether ai-vault keeps `ENTE_CLI_VAULT_KEY` sealed for it.
154
212
 
155
- 字段选择:`password`(默认)· `totp`(种子)· `code`(动态验证码)· `notes` · `field:<自定义字段名>`。
213
+ Field selector: `password` (default) · `totp` (seed) · `code` (rotating code) ·
214
+ `notes` · `field:<custom field name>`.
156
215
 
157
- ### 查询顺序:本地优先,Bitwarden 兜底
216
+ ### Lookup order: local first, Bitwarden as fallback
158
217
 
159
- `vault_get` 先问 `ai-vault`(这台机器共用的库),只有本地没有才去搜 Bitwarden:
218
+ `vault_get` asks `ai-vault` (the store this machine shares) first and only
219
+ searches Bitwarden on a miss:
160
220
 
161
221
  ```
162
222
  vault_get "github"
163
- └─ ai-vault 有 → 直接返回(按解锁模式决定要不要窗口)
164
- └─ ai-vault 没有 → Bitwarden 搜索
165
- ├─ 没命中 → 报「本地没有、Bitwarden 也没有」
166
- └─ 命中 → ① 给你看这一条(名称/用户名),问读不读
167
- ② 读了再问:导入 ai-vault(以后免 Bitwarden)还是只用这一次
223
+ ├─ in ai-vault → returned (the unlock policy decides whether a window opens)
224
+ └─ not in ai-vault → search Bitwarden
225
+ ├─ no hit → "not local, not in Bitwarden"
226
+ └─ hit → ① show you the entry (name/user), ask whether to read it
227
+ ② after reading, ask: import into ai-vault, or use once?
168
228
  ```
169
229
 
170
- 这样两者就隔离了:**只有你同意导入的密码才进 ai-vault**,ai-vault 里的就是「agent 可以自由使用」的那批;其余仍留在 Bitwarden 里,每次都要你点。
230
+ That keeps the two apart: **only the passwords you approve for import ever
231
+ enter ai-vault**, and ai-vault is the set "the agent may use freely". Everything
232
+ else stays in Bitwarden and asks every time.
171
233
 
172
- ### 解锁模式
234
+ ### Unlock policies
173
235
 
174
- `ai-vault` 什么时候要主密码,由这台机器的模式决定(`~/.ai-vault/config.json`):
236
+ When `ai-vault` asks for its master password is a per-machine setting
237
+ (`~/.ai-vault/config.json`):
175
238
 
176
- | 模式 | 行为 | 适合 |
239
+ | Mode | Behaviour | For |
177
240
  |---|---|---|
178
- | `never` | 永远不问。密钥写在 `~/.ai-vault/agent.session.json`(0600),**读取也不再弹确认窗** | 把一批「随便用」的密码交给 agent |
179
- | `time` | 解锁后 N 小时(默认 8,`--hours` 可改)再问一次 | 有边界的长任务 |
180
- | `session` | 每个会话问一次,会话结束就失效(默认) | 日常 |
241
+ | `never` | never asks. The key lives in `~/.ai-vault/agent.session.json` (0600) and **reads open no window either** | handing the agent a set of "use freely" passwords |
242
+ | `time` | asks again N hours after the unlock (default 8, `--hours`) | long bounded tasks |
243
+ | `session` | once per session; dies with it (default) | everyday |
181
244
 
182
245
  ```bash
183
- ai-vault mode # 看当前模式
184
- ai-vault mode set never # 切换要主密码
246
+ ai-vault mode # show
247
+ ai-vault mode set never # switching needs the master password
185
248
  ai-vault mode set time --hours 4
186
249
  ai-vault mode set session
187
250
  ```
188
- 插件里同样有:`/vault mode`、`/vault mode time 4`。**切换模式一定要输主密码**——尤其是切到 `never`,因为它把密钥落到磁盘上。
251
+ In the extension: `/vault mode`, `/vault mode time 4`. **Switching always costs
252
+ the master password** — especially into `never`, because that writes the key to disk.
189
253
 
190
- `never` 不是「安全一点」而是「明确放弃这层保护」:任何能读你 home 目录的进程都能读出库里的全部密码。它存在的意义是把「可以让 AI 随便用」的密码和 Bitwarden 里那些「每次都要问」的分开。
254
+ `never` is not "a bit safer"; it is explicitly giving up this layer: any process
255
+ that can read your home directory can read every password in the store. Its point
256
+ is to separate "the AI may use these" from "ask me every time".
191
257
 
192
- ### Bitwarden 也是同样三种模式(独立设置)
258
+ ### Bitwarden has the same three modes (set separately)
193
259
 
194
- | 设置 | 值 | 行为 |
260
+ | Setting | Value | Behaviour |
195
261
  |---|---|---|
196
- | `bitwarden.unlock` | `never` | `bw` 会话密钥落盘(`~/.ai-vault/bitwarden.session.json`,0600),**不再问 Bitwarden 主密码** |
197
- | | `time` | 同上,但 `bitwarden.hours` 小时后失效,重新要密码 |
198
- | | `session` | 密钥只在 agent 进程内存里,每个会话问一次(默认) |
199
- | `bitwarden.import` | `ask` | `vault_get` 本地没命中 → 显示 Bitwarden 命中项 → 读一次 → 问是否导入(默认) |
200
- | | `always` | 命中就直接导入并返回,**一个窗口都不开**(完全自动,慎用) |
201
- | | `never` | 只读一次,问一次,永不写入本地库 |
262
+ | `bitwarden.unlock` | `never` | the `bw` session key is kept on disk (`~/.ai-vault/bitwarden.session.json`, 0600, sealed); **no Bitwarden master password is asked** |
263
+ | | `time` | the same, but it expires after `bitwarden.hours` and the password is asked again |
264
+ | | `session` | the key stays in the agent's memory; asked once per session (default) |
265
+ | `bitwarden.import` | `ask` | local miss → show the Bitwarden hit → read once → ask whether to import (default) |
266
+ | | `always` | import on a hit and return it, **no window at all** (fully automatic; use with care) |
267
+ | | `never` | read once, ask once, never write to the local store |
202
268
 
203
269
  ```bash
204
- ai-vault settings # 全部设置
270
+ ai-vault settings # everything
205
271
  ai-vault settings bitwarden.unlock never
206
272
  ai-vault settings bitwarden.import always
207
273
  ai-vault settings bitwarden.hours 24
208
274
  ```
209
- 插件里:`/vault settings`、`/vault settings bitwarden.import always`。
275
+ In the extension: `/vault settings`, `/vault settings bitwarden.import always`.
210
276
 
211
- > `bitwarden.import = always` 配合 `bitwarden.unlock = never`,等于「Bitwarden 里任何一条被问到就自动进库、以后免密随便读」。这是最快也是最不设防的组合,只在完全信任 agent 时用。
277
+ > `bitwarden.import = always` together with `bitwarden.unlock = never` means
278
+ > "anything in Bitwarden that gets asked for is imported automatically and read
279
+ > without a password from then on". Fastest and least guarded combination; only
280
+ > with an agent you fully trust.
212
281
 
213
- `bw-session put/get/clear` 就是那个落盘密钥的读写口:插件在主密码解锁成功后写入,切回 `session` 模式时自动清掉,`/bw lock` 也会清掉。
282
+ `bw-session put/get/clear` is the handle for that persisted key: the extension
283
+ writes it after a successful master-password unlock, it is cleared when the
284
+ policy goes back to `session`, and `/bw lock` clears it too.
214
285
 
215
- ## 插件里的命令
286
+ ## Extension commands
216
287
 
217
288
  ```
218
- /vault init 创建本地库(弹窗设主密码)
219
- /vault unlock | lock 解锁 / 锁定本会话
220
- /vault mode [never|time|session] 查看/切换解锁模式(切换要主密码)
221
- /vault settings [键 值] 查看/修改设置(bitwarden.* 也在这里)
222
- /vault status 状态、过期时间、授权剩余
223
- /vault list 条目元数据
224
- /vault add [名称] 新增(用户名、密码在弹窗里输入)
225
- /vault remove <名称> 删除("GitHub (2)" 这种要加引号)
226
- /vault grant <名称> [分钟] 手动授权读取
227
- /vault revoke <名称|all> 撤销授权
228
- /vault audit [n] 最近 n 条审计
229
- /vault import <bitwarden.json> 从未加密导出导入
230
- /vault import-bw [搜索词] 直接从 bw 导入登录项
231
- /bw status|unlock|lock|clear 在线 Bitwarden 会话
289
+ /vault init create the local store (dialog sets the master password)
290
+ /vault unlock | lock unlock / lock this session
291
+ /vault mode [never|time|session] show / switch the unlock policy (switching needs the password)
292
+ /vault settings [key value] show / change settings (bitwarden.*, ente.*)
293
+ /vault ente-key save Ente's ENTE_CLI_VAULT_KEY (no keychain, no login)
294
+ /vault status state, expiry, grants left
295
+ /vault list entry metadata
296
+ /vault add [name] add (username and password typed in a dialog)
297
+ /vault remove <name> delete (quote names like "GitHub (2)")
298
+ /vault grant <name> [minutes] a standing read grant (needs the master password)
299
+ /vault revoke <name|all> revoke grants
300
+ /vault audit [n] the last n audit lines
301
+ /vault import <bitwarden.json> import an unencrypted export
302
+ /vault import-bw [search] import logins straight from bw
303
+ /bw status|unlock|lock|clear the live Bitwarden session
232
304
  ```
233
305
 
234
- ## 会话与隔离
306
+ ## Sessions and isolation
235
307
 
236
- - 每个绑定(一个会话,或一个子代理)在第一次用到库时各自 `ai-vault unlock`,拿到**自己的令牌**。父会话的解锁和授权子代理继承不到;确认窗口里会写「请求方: 子代理 0-Explore」。
237
- - 令牌寿命由解锁模式决定(见上):`session` 最长 24 小时、`time` 到 N 小时、`never` 不过期。`/new`、`/fork`、退出会让插件把自己的令牌删掉;`/resume` 保留。失效、被改、属于旧库的令牌文件在**每次** CLI 调用时都会被清掉。
238
- - 读授权存在令牌里,所以天然按请求方隔离;`/vault grant`、`/vault revoke` 改的就是它。
239
- - 库文件本身共享:读改写有 `flock`,两个 agent 同时写不会丢更新(旧版是后写覆盖先写)。
308
+ - Every binding (a session, or a subagent) runs its own `ai-vault unlock` on
309
+ first use and gets **its own token**. A subagent cannot inherit the parent's
310
+ unlock or grants; the confirm window says "requester: subagent 0-Explore".
311
+ - Token lifetime follows the unlock policy (above): `session` up to 24 hours,
312
+ `time` until N hours, `never` never. `/new`, `/fork` and quitting make the
313
+ extension drop its own token; `/resume` keeps it. Expired, tampered or
314
+ old-store token files are swept on **every** CLI call.
315
+ - Read grants live in the token, so they are isolated per requester by
316
+ construction; `/vault grant` and `/vault revoke` change exactly that.
317
+ - The store file itself is shared: read-modify-write holds a file lock, so two
318
+ agents writing at once do not lose updates.
240
319
 
241
320
  ## Bitwarden
242
321
 
243
- 需要 `bw`(先 `bw login`)。第一次用到时弹窗要主密码,之后每次调用只在确认窗口里点允许。
244
-
245
- - 要跑一条命令、又不想让密码进对话:`bw_run`。值在子进程环境里,命令结束就没了;stdout/stderr 里出现原值、base64/base64url/URL/hex 形式(包括 `base64` 的 76 列换行和 `xxd` 的空格 hex)都会被替换成 `[BW_SCRUBBED:VAR]`。输出最多保留 8 MiB,超出部分丢弃并标注。
246
- - pi 上还可以 `bw_inject` 注入 bash 环境,后续多条命令都能用。
247
- - `bw_clipboard` 复制的值也会登记到擦洗列表:之后用 `pbpaste` / `xclip -o` / `wl-paste` 读回剪贴板,结果同样会被擦洗。
248
- - 确认窗口里显示的是**实际命中的条目**(名称+用户名),不是模型给的引用。
249
- - `/bw lock` 只丢弃当前绑定的会话密钥;同一进程里还有别的绑定持有时不会执行全局 `bw lock`,最后一个绑定释放时才真正作废 CLI 会话。
250
- - Bitwarden 会话密钥只在 agent 进程内存里,不落盘、不进 bash 环境。
251
-
252
- ## Ente(Auth 验证码)
253
-
254
- `ente` 是 Ente 官方的终端客户端(0.4+)。它**自己登录一次**:
322
+ Requires `bw` (run `bw login` first). The first use asks for the master password
323
+ in a window; after that each call only needs "allow" in the confirm window.
324
+
325
+ - To run a command without the secret entering the conversation: `bw_run`. The
326
+ value is in the child's environment and gone when the command ends; the raw
327
+ value and its base64/base64url/URL/hex forms (including `base64`'s 76-column
328
+ wrapping and `xxd`'s spaced hex) are replaced in stdout/stderr with
329
+ `[BW_SCRUBBED:VAR]`. Output is capped at 8 MiB; the excess is dropped and marked.
330
+ - On pi, `bw_inject` puts it in the bash environment for several commands.
331
+ - Values copied by `bw_clipboard` join the scrub list too: reading the
332
+ clipboard back with `pbpaste` / `xclip -o` / `wl-paste` is scrubbed as well.
333
+ - The confirm window shows the **entry actually matched** (name + username), not
334
+ the reference the model gave.
335
+ - `/bw lock` only drops the current binding's session key; a global `bw lock`
336
+ runs only when the last binding in the process releases its key.
337
+ - The Bitwarden session key lives in the agent process's memory only, unless
338
+ `bitwarden.unlock` is `never`/`time`, in which case it is sealed at rest
339
+ (see *Security*).
340
+
341
+ ## Ente (Auth codes)
342
+
343
+ `ente` is Ente's official terminal client (0.4+). It **logs in once**:
255
344
 
256
345
  ```bash
257
- ente account login --app auth # 邮箱 + 密码(+ 2FA 验证码)
258
- ente auth code list # 之后每次都不再问密码
346
+ ente account login --app auth # email + password (+ a 2FA code)
347
+ ente auth code list # never asks for the password again
259
348
  ```
260
349
 
261
- 会话存在 `$XDG_DATA_HOME/ente-cli`(Linux 默认 `~/.local/share/ente-cli`),数据库密钥默认放系统钥匙串;无桌面/无人值守时用
350
+ The session lives in `$XDG_DATA_HOME/ente-cli` (`~/.local/share/ente-cli` on
351
+ Linux) and the database key in the OS keychain by default. For a machine
352
+ without a desktop or keychain:
262
353
 
263
354
  ```bash
264
- ente vault key generate # 打印一个 key
265
- export ENTE_CLI_VAULT_KEY=<那个 key> # 之后连钥匙串都不用
355
+ ente vault key generate # prints a key; generate it once
356
+ /vault ente-key # paste it into the dialog; ai-vault seals it
357
+ /vault settings ente.unlock never # ente children get it automatically
266
358
  ```
267
359
 
268
- 所以在 `session` 这种日常形态下,**每次查看不会再要你的密码**,最多要一次系统钥匙串解锁。
360
+ So in the everyday `session` form, **looking up a code never asks for your
361
+ password** — at most one keychain unlock.
269
362
 
270
- 想连钥匙串都不要(无人值守):
271
-
272
- ```bash
273
- ente vault key generate # 打印一个 key,拿一次就固定
274
- /vault ente-key # 在弹窗里粘进去,ai-vault 把它加密封存
275
- /vault settings ente.unlock never # 之后 ente 子进程自动带上它
276
- ```
277
- `ente.unlock` 和 `bitwarden.unlock` 是同一套三档(`never`/`time`/`session`),`ente-session get|put|clear` 是它的 CLI 入口;密钥用库目录的 wrap key 封存(0600),单独拷走 `ente.session.json` 解不开。插件永远不会把你 shell 里导出的 `ENTE_CLI_VAULT_KEY` 传给子进程——只有它自己封存的那把会。
363
+ `ente.unlock` is the same three-way switch as `bitwarden.unlock`
364
+ (`never`/`time`/`session`); `ente-session get|put|clear` is its CLI handle. The
365
+ key is sealed under the store directory's wrap key (0600); copying
366
+ `ente.session.json` away yields nothing. The extension never passes an
367
+ `ENTE_CLI_VAULT_KEY` exported in your shell to a child — only its own sealed copy.
278
368
 
279
- pi-ai-vault 只是这套 CLI 的客户端,本身不保存 Ente 的任何密钥:
369
+ pi-ai-vault is only a client of that CLI and keeps no Ente key of its own:
280
370
 
281
- | 工具 | 作用 |
371
+ | Tool | What it does |
282
372
  |---|---|
283
- | `ente_list` | 列出条目(name / issuer / accountName / type),**不含验证码** |
284
- | `ente_code <名字>` | 弹窗显示实际命中的条目,允许后返回当前验证码和过期时间 |
373
+ | `ente_list` | list entries (name / issuer / accountName / type); **no codes** |
374
+ | `ente_code <name>` | show the entry actually matched in a window; on allow, return the current code and its expiry |
285
375
 
286
- 安全上和 `bw_*` 一套规则:列表只给元数据;读码每次确认;拒绝后不重试;允许/拒绝都写审计(`~/.bw/pi-extension/audit.log`,`ente.code` 事件,不含码本身);条目名/签发方进窗口前会被压成一行,防伪造。
376
+ Same rules as `bw_*`: listing is metadata only; reading a code is confirmed
377
+ every time; a deny is final; both outcomes are audited (`~/.bw/pi-extension/audit.log`,
378
+ `ente.code` events, never the code itself); names and issuers are flattened to one
379
+ line before they reach a window.
287
380
 
288
- 插件启动的 bash 会剔除 `ENTE_CLI_VAULT_KEY` / `ENTE_CLI_PASSWORD`,避免你 shell 里导出的免密 key 漏进模型自己的命令环境。**注意**:`ente` 二进制本身也在 PATH 上,模型直接跑 `ente auth code view` 仍能绕过这个扩展的确认窗——要收紧要靠 `ENTE_CLI_VAULT_KEY` + 把模型的 `ENTE_CLI_HOME` 指到别处,或者干脆不让 agent 有 shell。
381
+ The bash the extension starts strips `ENTE_CLI_VAULT_KEY` / `ENTE_CLI_PASSWORD`,
382
+ so an unattended key you exported does not leak into the model's own commands.
383
+ **Note**: the `ente` binary is on PATH, so the model running `ente auth code view`
384
+ directly still bypasses this extension's confirm window. Tightening that means
385
+ `ENTE_CLI_VAULT_KEY` plus pointing the model's `ENTE_CLI_HOME` elsewhere — or not
386
+ giving the agent a shell.
289
387
 
290
- ## 安全
388
+ ## Security
291
389
 
292
- ### 威胁模型:谁能做什么
390
+ ### Threat model: who can do what
293
391
 
294
- 所有东西都跑在**你的用户**下,所以边界不是「用户 vs 别人」,而是**你(人)vs 跑在你账号下的 agent**。设计目标是:agent 可以*用*密码,但不能*绕过你*去拿。
392
+ Everything runs as **your user**, so the boundary is not "you vs other users" but
393
+ **you (the human) vs the agents running under your account**. The goal: the agent
394
+ may *use* passwords but cannot *get around you* to take them.
295
395
 
296
- | 角色 | 能 | 不能 |
396
+ | Role | Can | Cannot |
297
397
  |---|---|---|
298
- | **你**(终端里手敲 `ai-vault`) | 一切 | — |
299
- | **宿主**(pi/omp 扩展进程,持 `AI_VAULT_HOST=1` + 内存里的 host secret) | 替你转发确认(要签名)、改设置 | 不知道主密码(除非你输了) |
300
- | **agent**(模型的 `bash`,同一用户,能读 `~/.ai-vault`) | 读到会话令牌文件(但插件开的会话没有 secret 用不了,一用就作废) | **伪造一次读取确认、给令牌加授权、改确认窗里的请求方、`list` 插件会话、拿到 Bitwarden 主密码** |
301
- | **别的用户 / 离线拿到文件的人** | 读到密文 | 解密(scrypt + ChaCha20-Poly1305) |
302
-
303
- ### 怎么做到的
304
-
305
- - **确认窗不能被绕过。** `vault_get` 的确认要么是 CLI 自己开的 zenity 窗口,要么是宿主转发的答案。转发的答案必须带 `--approval`:用**宿主进程内存里的 secret** 对 `allow:<token>:<条目>:<y|n>` 做 HMAC。模型的 bash 能找到令牌文件,但没有 secret,签不出来;拿别的条目的签名重放、把 `n` 改成 `y`,都会对不上。
306
- - **令牌文件不能改。** 每个会话文件带 HMAC(宿主会话用 host secret,手敲 CLI 的会话用库目录的 wrap key)。改了 `grants`、改了 `requester`、哪怕只改一个字节,CLI 都报 `session file was modified outside ai-vault` 并删掉文件。
307
- - **`grant` 不再是免费的。** 给一条条目「N 分钟免确认」是一次长期授权,现在要主密码(和切模式同一级别)。
308
- - **`never` 模式是明确放弃上面这些。** 密钥写在 `~/.ai-vault/agent.session.json`,读取不再有任何窗口。它的意义是把「可以让 AI 随便用」和「每次都要问我」分开;开了它,就等于信任 agent 的输出渠道,不只是 agent。
309
- - **Bitwarden 会话密钥加密封存。** `bitwarden.unlock = never|time` 时,`bw` 的会话密钥用 ChaCha20-Poly1305 封在 `~/.ai-vault/bitwarden.session.json` 下,密钥是 `~/.ai-vault/.wrap`(0600)。单独拷走那个文件什么都打不开。`bw unlock --raw` 的会话密钥等价于**整个** Bitwarden 保险库的读权限,所以这个文件的敏感度 ≥ 库本身。
310
- - **确认窗里的字不是模型写的。** 条目名、原因、用户名、URI 进窗口前都压成一行、去掉控制字符、截到 80–120 字符,模型没法在名字里塞换行伪造第二条「已授权」。
311
- - **KDF。** 新库 scrypt `N=2^17`(128 MiB);文件头记着参数,旧库(`N=2^15`)照常打开,`ai-vault rekey` 升级。低于 `2^15` 的参数一律拒收(防降级)。
312
- - **主密码**只经过弹窗或宿主输入框;`unlock` 派生的 key 只写进令牌文件(0600,优先 tmpfs)。`BW_*` 在所有子进程环境里剔除。
313
- - **审计**:`~/.ai-vault/audit.log` 记录会话、条目、允许/拒绝/原因、以及 `unsigned-relay`、`bad-approval`、`modified-outside` 这类尝试,从不记值;1 MiB 轮转。
314
- - **原子写 + flock**:临时文件(0600)→ fsync → rename → 目录 fsync;多进程读改写有文件锁。失效/被改/旧库的令牌文件每次调用都会被清掉。
315
- - `bw_reveal` 默认关闭;擦洗只在值长度 ≥ 6 时生效,防不住网络外传和单向哈希——`bw_run` / `bw_inject` 的价值是值不进对话,不是防住被注入的 agent。
316
- - `notes` 只在 `get`(授权之后)里出现,`list` 不输出它。
317
-
318
- ### 已知边界
319
-
320
- - `session` 模式下,模型的 bash **能**读到令牌文件,但拿到也没用:插件开的会话用宿主内存里的 secret 签名,bash 没有 secret,第一次用就会被判「文件被改」而作废(连 `list` 都做不了,还会把那个文件删掉)。只有**你在终端手敲** `ai-vault unlock` 开出来的会话(用 wrap key 签名)才能被同用户进程 `list`——那种会话本来就没有窗口可以绕,这是「同一用户」的固有暴露面。真正收紧要靠不同的用户或容器。
321
- - 一个 `AI_VAULT_HOST=1` 但没带 secret 的调用方,会被当成普通用户对待:拿不到 secret、签不了转发。
322
- - `bitwarden.import = always` + `bitwarden.unlock = never` 等于「Bitwarden 里任何一条被问到就自动进免费库」。README 不建议,但它能开。
323
- - zenity 窗口的标题栏属于窗口管理器;全屏伪造窗口不在防护范围内。
324
-
325
- ## 开发
398
+ | **You** (typing `ai-vault` in a terminal) | everything | — |
399
+ | **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 |
400
+ | **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 voids it) | **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** |
401
+ | **Another user / someone with the files offline** | read ciphertext | decrypt (scrypt + ChaCha20-Poly1305) |
402
+
403
+ ### How
404
+
405
+ - **The confirm window cannot be bypassed.** `vault_get`'s confirmation is
406
+ either the CLI's own window or an answer relayed by the host. A relayed
407
+ answer must carry `--approval`: an HMAC under the **host process's in-memory
408
+ secret** over `allow:<token>:<entry>:<y|n>`. The model's bash can find the
409
+ token file but not the secret, so it cannot sign; a signature for another
410
+ entry, or with `n` flipped to `y`, does not match.
411
+ - **Token files cannot be edited.** Every session file carries an HMAC (host
412
+ sessions under the host secret, hand-typed CLI sessions under the store's wrap
413
+ key). Change `grants`, change `requester`, change one byte: the CLI reports
414
+ `session file was modified outside ai-vault` and deletes the file.
415
+ - **`grant` is no longer free.** "No window for N minutes" on an entry is a
416
+ standing approval and now costs the master password, like a policy change.
417
+ - **`never` mode is giving up the above on purpose.** The key is written to
418
+ `~/.ai-vault/agent.session.json` and reads open no window. Its point is to
419
+ separate "the AI may use these" from "ask me every time". Turning it on means
420
+ trusting the agent's output channel, not just the agent.
421
+ - **Sealed Bitwarden session.** With `bitwarden.unlock = never|time` the `bw`
422
+ session key is sealed with ChaCha20-Poly1305 under `~/.ai-vault/.wrap` (0600)
423
+ into `~/.ai-vault/bitwarden.session.json`. Copying that file alone opens
424
+ nothing. A `bw unlock --raw` session key is read access to your **entire**
425
+ Bitwarden vault, so that file is at least as sensitive as the store itself.
426
+ Ente's vault key gets the same treatment.
427
+ - **The text in a confirm window is not written by the model.** Entry names,
428
+ reasons, usernames and URIs are flattened to one line, control characters
429
+ removed, truncated to 80–120 characters before they reach a window, so a
430
+ newline in a name cannot forge a second "approved" block.
431
+ - **KDF.** New stores use scrypt `N=2^17` (128 MiB); the parameters travel in the
432
+ file header, so an old store (`N=2^15`) opens unchanged and `ai-vault rekey`
433
+ upgrades it. Anything below `2^15` is refused as a downgrade.
434
+ - **The master password** only passes through a dialog or the host prompt; the
435
+ key `unlock` derives only goes into the token file (0600, tmpfs when there is
436
+ one). `BW_*` is stripped from every child environment.
437
+ - **Audit**: `~/.ai-vault/audit.log` records sessions, entries, allow/deny with
438
+ the reason, and attempts such as `unsigned-relay`, `bad-approval`,
439
+ `modified-outside`; never a value. Rotated at 1 MiB.
440
+ - **Atomic writes + file lock**: temp file (0600) → fsync → rename → directory
441
+ fsync; a file lock around read-modify-write. Expired, tampered and old-store
442
+ token files are swept on every call.
443
+ - `bw_reveal` is off by default; the scrubber only engages for values ≥ 6
444
+ characters and cannot stop exfiltration over the network or one-way hashes —
445
+ `bw_run` / `bw_inject` are about keeping values out of the conversation, not
446
+ about stopping an agent that has been injected.
447
+ - `notes` appear only in `get` (after approval); `list` never prints them.
448
+
449
+ ### Known limits
450
+
451
+ - In `session` mode the model's bash **can** read a token file, but it does it
452
+ no good: a session the extension opened is signed under the host's in-memory
453
+ secret, and without that secret the first use is judged "modified" and voided
454
+ (no `list` either; the file is deleted). Only a session **you** opened by
455
+ typing `ai-vault unlock` in a terminal (signed under the wrap key) can be
456
+ `list`ed by a same-user process — that session had no window to bypass in
457
+ the first place. This is the inherent exposure of "same user"; really
458
+ tightening it needs a different user or a container.
459
+ - A caller with `AI_VAULT_HOST=1` but no secret is treated as a human: it gets
460
+ no secret and cannot relay.
461
+ - `bitwarden.import = always` + `bitwarden.unlock = never` means "anything in
462
+ Bitwarden that gets asked for is imported automatically". Not recommended; it
463
+ can be turned on.
464
+ - The title bar of a zenity window belongs to the window manager; a full-screen
465
+ fake window is out of scope.
466
+
467
+ ## Developing
326
468
 
327
469
  ```bash
328
- cargo test # Rust 单元测试(存储、加密格式、导入映射)
329
- npm test # 先把 CLI 编译出来,再跑插件测试(真实 CLI + mock zenity)
330
- npm run test:npm # 打 tarball、临时 prefix 全局安装、跑 shim 与退出码
331
- npm run test:cli # 只测二进制:无桌面时的退出码契约、加密落盘、审计
470
+ cargo test # Rust unit tests (store, crypto format, import mapping)
471
+ npm test # builds the CLI, then runs the extension tests (real CLI + mock zenity/ente)
472
+ npm run test:npm # pack tarballs, install into a throwaway prefix, run the shim and exit codes
473
+ npm run test:cli # the binary alone: headless exit-code contract, encryption at rest, audit
332
474
  npm run typecheck
333
- bash test/smoke.sh pi # 真宿主冒烟(需要模型凭据)
475
+ bash test/smoke.sh pi # smoke on a real host (needs model credentials)
334
476
  ```
335
477
 
336
- 目录:
478
+ Layout:
337
479
 
338
480
  ```
339
- crates/ai-vault/src/ main.rs cli.rs crypto.rs store.rs session.rs dialog.rs import.rs audit.rs paths.rs
340
- bin/ai-vault.cjs npm 入口:找平台包、转发 argv/stdio/退出码
341
- scripts/stage-npm.sh 把 release 二进制 stage 成 npm 平台包
342
- packages/pi-ai-vault/ npm 包 pi-ai-vault:src/ = index.ts(工具/命令) cli.ts(CLI 客户端)
343
- bitwarden.ts prompt.ts host.ts import-map.ts scrub.ts
344
- test/cli.sh 二进制级集成测试
345
- test/npm.sh npm 打包/安装/转发测试
481
+ crates/ai-vault/src/ main.rs cli.rs crypto.rs store.rs session.rs sealed.rs dialog.rs import.rs audit.rs paths.rs perms.rs config.rs
482
+ bin/ai-vault.cjs npm entry: find the platform package, forward argv/stdio/exit code
483
+ scripts/stage-npm.sh turn a release binary into an npm platform package
484
+ packages/pi-ai-vault/ the npm package pi-ai-vault: src/ = index.ts (tools/commands) cli.ts (CLI client)
485
+ settings.ts ente.ts bitwarden.ts prompt.ts host.ts import-map.ts scrub.ts
486
+ test/cli.sh binary-level integration tests
487
+ test/npm.sh npm pack/install/forwarding tests
346
488
  ```
347
489
 
348
490
  ## License