@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/Cargo.lock +122 -4
- package/README.md +364 -222
- package/README.zh.md +388 -0
- package/bin/ai-vault.cjs +6 -0
- package/crates/ai-vault/Cargo.toml +2 -3
- package/crates/ai-vault/src/audit.rs +4 -6
- package/crates/ai-vault/src/cli.rs +56 -41
- package/crates/ai-vault/src/crypto.rs +4 -11
- package/crates/ai-vault/src/dialog.rs +294 -9
- package/crates/ai-vault/src/i18n.rs +56 -0
- package/crates/ai-vault/src/main.rs +2 -0
- package/crates/ai-vault/src/paths.rs +30 -7
- package/crates/ai-vault/src/perms.rs +54 -0
- package/crates/ai-vault/src/sealed.rs +3 -4
- package/crates/ai-vault/src/session.rs +9 -21
- package/package.json +5 -3
- package/packages/pi-ai-vault/README.md +40 -45
- package/packages/pi-ai-vault/README.zh.md +84 -0
- package/packages/pi-ai-vault/package.json +5 -4
- package/packages/pi-ai-vault/src/bitwarden.ts +2 -1
- package/packages/pi-ai-vault/src/cli.ts +17 -7
- package/packages/pi-ai-vault/src/ente.ts +4 -3
- package/packages/pi-ai-vault/src/i18n.ts +31 -0
- package/packages/pi-ai-vault/src/index.ts +77 -76
- package/packages/pi-ai-vault/src/prompt.ts +3 -2
- package/test/cli.sh +6 -4
- package/test/npm.sh +14 -1
- package/tests/mocks/bin/zenity +7 -2
package/README.md
CHANGED
|
@@ -1,348 +1,490 @@
|
|
|
1
1
|
# ai-vault
|
|
2
2
|
|
|
3
|
-
|
|
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
|
|
7
|
-
~/.ai-vault/audit.log
|
|
8
|
-
~/.ai-vault/store.lock
|
|
9
|
-
$XDG_RUNTIME_DIR/ai-vault/sessions/<token>.json
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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`
|
|
30
|
-
| `@xiaolikt/ai-vault
|
|
31
|
-
| **`pi-ai-vault`** | 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 #
|
|
35
|
-
pi install npm:pi-ai-vault #
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
68
|
+
### Platforms
|
|
44
69
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
### 从源码 / git
|
|
101
|
+
### From source / git
|
|
62
102
|
|
|
63
103
|
```bash
|
|
64
|
-
# 1.
|
|
104
|
+
# 1. Build the CLI and put it on PATH (~/.local/bin/ai-vault)
|
|
65
105
|
./install.sh
|
|
66
106
|
|
|
67
|
-
# 2.
|
|
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
|
-
|
|
116
|
+
Requires Rust (`cargo`) to build; at runtime `zenity` for dialogs (the host
|
|
117
|
+
prompt is the fallback).
|
|
76
118
|
|
|
77
|
-
|
|
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
|
-
###
|
|
123
|
+
### Migrating
|
|
80
124
|
|
|
81
|
-
|
|
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` |
|
|
93
|
-
| `init [--password-stdin]` |
|
|
94
|
-
| `unlock [--password-stdin] [--requester ID]` |
|
|
95
|
-
| `mode [get]` / `mode set never\|time\|session [--hours N]` |
|
|
96
|
-
| `settings [
|
|
97
|
-
| `bw-session get\|put\|clear` |
|
|
98
|
-
| `ente-session get\|put\|clear` | Ente
|
|
99
|
-
| `rekey` |
|
|
100
|
-
| `status --token T` |
|
|
101
|
-
| `lock --token T \| --all` |
|
|
102
|
-
| `list --token T` |
|
|
103
|
-
| `get
|
|
104
|
-
| `add --name N [--username U] [--uri U] [--notes N] [--password-stdin] [--yes]` |
|
|
105
|
-
| `save --yes [--file F]` |
|
|
106
|
-
| `remove
|
|
107
|
-
| `grant
|
|
108
|
-
| `audit [n]` |
|
|
109
|
-
| `import <bitwarden.json> [--yes]` |
|
|
110
|
-
|
|
111
|
-
|
|
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 |
|
|
118
|
-
| 1 |
|
|
119
|
-
| 2 |
|
|
120
|
-
| 3 |
|
|
121
|
-
| 4 |
|
|
122
|
-
| 5 |
|
|
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
|
-
|
|
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=<
|
|
131
|
-
ai-vault get
|
|
132
|
-
# approval = HMAC-SHA256(hostSecret, "allow:<T
|
|
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`
|
|
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` |
|
|
142
|
-
| `vault_get` |
|
|
143
|
-
| `vault_add` |
|
|
144
|
-
| `vault_import` |
|
|
145
|
-
| `bw_list` |
|
|
146
|
-
| `bw_run` |
|
|
147
|
-
| `bw_inject` |
|
|
148
|
-
| `bw_clipboard` |
|
|
149
|
-
| `bw_reveal` |
|
|
150
|
-
| `ente_list` | Ente Auth
|
|
151
|
-
| `ente_code` |
|
|
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
|
|
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
|
-
|
|
213
|
+
Field selector: `password` (default) · `totp` (seed) · `code` (rotating code) ·
|
|
214
|
+
`notes` · `field:<custom field name>`.
|
|
156
215
|
|
|
157
|
-
###
|
|
216
|
+
### Lookup order: local first, Bitwarden as fallback
|
|
158
217
|
|
|
159
|
-
`vault_get`
|
|
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
|
-
|
|
164
|
-
└─ ai-vault
|
|
165
|
-
├─
|
|
166
|
-
└─
|
|
167
|
-
|
|
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
|
-
|
|
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`
|
|
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` |
|
|
179
|
-
| `time` |
|
|
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
|
-
|
|
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`
|
|
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`
|
|
197
|
-
| | `time` |
|
|
198
|
-
| | `session` |
|
|
199
|
-
| `bitwarden.import` | `ask` |
|
|
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
|
-
|
|
275
|
+
In the extension: `/vault settings`, `/vault settings bitwarden.import always`.
|
|
210
276
|
|
|
211
|
-
> `bitwarden.import = always`
|
|
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`
|
|
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 [
|
|
222
|
-
/vault
|
|
223
|
-
/vault
|
|
224
|
-
/vault
|
|
225
|
-
/vault
|
|
226
|
-
/vault
|
|
227
|
-
/vault
|
|
228
|
-
/vault
|
|
229
|
-
/vault
|
|
230
|
-
/vault import
|
|
231
|
-
/bw
|
|
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
|
-
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
-
|
|
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
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
-
|
|
247
|
-
|
|
248
|
-
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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 #
|
|
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
|
-
|
|
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 #
|
|
265
|
-
|
|
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
|
-
|
|
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
|
-
|
|
273
|
-
ente
|
|
274
|
-
|
|
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
|
|
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` |
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
|
299
|
-
|
|
|
300
|
-
| **agent
|
|
301
|
-
|
|
|
302
|
-
|
|
303
|
-
###
|
|
304
|
-
|
|
305
|
-
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
- **
|
|
312
|
-
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
- `
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
-
|
|
322
|
-
|
|
323
|
-
-
|
|
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 #
|
|
330
|
-
npm run test:npm #
|
|
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
|
|
341
|
-
scripts/stage-npm.sh
|
|
342
|
-
packages/pi-ai-vault/ npm
|
|
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
|