@xiaolikt/ai-vault 0.9.1 → 0.11.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 +1 -1
- package/README.md +395 -243
- package/README.zh.md +417 -0
- package/crates/ai-vault/Cargo.toml +1 -1
- package/crates/ai-vault/src/cli.rs +300 -88
- package/crates/ai-vault/src/dialog.rs +14 -7
- package/crates/ai-vault/src/i18n.rs +56 -0
- package/crates/ai-vault/src/import.rs +85 -48
- package/crates/ai-vault/src/main.rs +1 -0
- package/crates/ai-vault/src/store.rs +237 -5
- package/package.json +5 -5
- 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 +41 -25
- package/packages/pi-ai-vault/src/cli.ts +11 -4
- 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/import-map.ts +166 -58
- package/packages/pi-ai-vault/src/index.ts +194 -114
- package/packages/pi-ai-vault/src/prompt.ts +3 -2
- package/packages/pi-ai-vault/src/types.ts +52 -0
- package/test/cli.sh +44 -0
- package/tests/bitwarden-tools.test.mjs +2 -2
- package/tests/import-map.test.mjs +75 -38
- package/tests/mocks/bin/bw +5 -1
- package/tests/mocks/bin/zenity +7 -2
- package/tests/vault-cli.test.mjs +56 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiaolikt/ai-vault",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "One machine-wide encrypted secret store for AI coding agents: the ai-vault Rust CLI (npm-installable) plus the pi-ai-vault extension for pi and omp.",
|
|
3
|
+
"version": "0.11.0",
|
|
4
|
+
"description": "One machine-wide encrypted secret store for AI coding agents: the ai-vault Rust CLI (npm-installable, Linux/macOS/Windows) plus the pi-ai-vault extension for pi and omp.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/xiaolikt/ai-vault.git"
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"optionalDependencies": {
|
|
36
|
-
"@xiaolikt/ai-vault-linux-x64": "0.
|
|
37
|
-
"@xiaolikt/ai-vault-linux-arm64": "0.
|
|
38
|
-
"@xiaolikt/ai-vault-win32-x64": "0.
|
|
36
|
+
"@xiaolikt/ai-vault-linux-x64": "0.11.0",
|
|
37
|
+
"@xiaolikt/ai-vault-linux-arm64": "0.11.0",
|
|
38
|
+
"@xiaolikt/ai-vault-win32-x64": "0.11.0"
|
|
39
39
|
},
|
|
40
40
|
"files": [
|
|
41
41
|
"bin",
|
|
@@ -1,82 +1,77 @@
|
|
|
1
1
|
# pi-ai-vault
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[中文版](README.zh.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The pi extension for [ai-vault](https://www.npmjs.com/package/@xiaolikt/ai-vault) — **omp installs the same package** (omp is a pi-compatible fork; the manifest and tool API are identical, and the only differences are feature-detected at runtime in `src/host.ts`).
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
It hands one machine-wide encrypted secret store to your agent: `~/.ai-vault`, shared by every agent on the machine. The extension does no cryptography itself; it only holds a session token.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
8
10
|
|
|
9
11
|
```bash
|
|
10
|
-
pi install npm:pi-ai-vault
|
|
11
|
-
omp plugin install npm:pi-ai-vault
|
|
12
|
+
pi install npm:pi-ai-vault # pi; brings the ai-vault CLI along
|
|
13
|
+
omp plugin install npm:pi-ai-vault # omp; the same package
|
|
12
14
|
```
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
Then, in that host's session:
|
|
15
17
|
|
|
16
18
|
```
|
|
17
19
|
/vault init
|
|
18
20
|
```
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
(A dialog asks for the master password, twice. With a desktop it is the CLI's own window; without one, the host's prompt.)
|
|
23
|
+
|
|
24
|
+
You can also install straight from the repository: `pi install git:github.com/xiaolikt/ai-vault`.
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
Do not install `pi-bitwarden` or `omp-vault` as well: they register the same `bw_*` / `vault_*` tools. Both are archived.
|
|
23
27
|
|
|
24
|
-
##
|
|
28
|
+
## Tools
|
|
25
29
|
|
|
26
|
-
|
|
|
30
|
+
| Tool | What it does | Model sees the secret? |
|
|
27
31
|
|---|---|---|
|
|
28
|
-
| `vault_list` |
|
|
29
|
-
| `vault_get` |
|
|
30
|
-
| `vault_add` |
|
|
31
|
-
| `vault_import` |
|
|
32
|
-
| `bw_list` / `bw_run` / `bw_clipboard` / `bw_reveal` |
|
|
33
|
-
| `bw_inject` |
|
|
34
|
-
| `ente_list` | Ente Auth
|
|
35
|
-
| `ente_code` |
|
|
32
|
+
| `vault_list` | local store metadata | no |
|
|
33
|
+
| `vault_get` | read one: local store first, then Bitwarden; a Bitwarden hit follows `bitwarden.import` (ask / import / read once) | yes, user-approved on the spot |
|
|
34
|
+
| `vault_add` | store one, any Bitwarden type (login, note, card, identity, sshkey, bankaccount, driverslicense, passport); secret fields are typed in a dialog | no |
|
|
35
|
+
| `vault_import` | copy Bitwarden logins into the local store (asks first) | no |
|
|
36
|
+
| `bw_list` / `bw_run` / `bw_clipboard` / `bw_reveal` | live Bitwarden through the `bw` CLI | no (`bw_reveal` excepted) |
|
|
37
|
+
| `bw_inject` | inject into the bash env (**pi only**; omp does not register it) | no |
|
|
38
|
+
| `ente_list` | Ente Auth entry metadata | no |
|
|
39
|
+
| `ente_code` | one current TOTP/Steam code, confirmed per call | yes, user-approved on the spot |
|
|
36
40
|
|
|
37
|
-
##
|
|
41
|
+
## Commands
|
|
38
42
|
|
|
39
43
|
```
|
|
40
44
|
/vault init | unlock | lock | status | list | add | remove
|
|
41
|
-
/vault
|
|
42
|
-
/vault
|
|
45
|
+
/vault mode [never|time|session] unlock policy (switching needs the master password)
|
|
46
|
+
/vault settings [key value] bitwarden.*, ente.*
|
|
47
|
+
/vault ente-key save Ente's ENTE_CLI_VAULT_KEY
|
|
48
|
+
/vault grant <name> [minutes] | revoke <name|all> | audit [n]
|
|
49
|
+
/vault import <bitwarden.json> | import-bw [search]
|
|
43
50
|
/bw status|unlock|lock|clear
|
|
44
51
|
```
|
|
45
52
|
|
|
46
|
-
##
|
|
53
|
+
## Unlock policies
|
|
47
54
|
|
|
48
|
-
|
|
55
|
+
When the local store asks for its master password is a per-machine setting (`/vault mode`, switching needs the password):
|
|
49
56
|
|
|
50
|
-
|
|
|
57
|
+
| Mode | Behaviour |
|
|
51
58
|
|---|---|
|
|
52
|
-
| `never` |
|
|
53
|
-
| `time` |
|
|
54
|
-
| `session` |
|
|
59
|
+
| `never` | never asks, and reads open no window — the "the agent may use these freely" passwords |
|
|
60
|
+
| `time` | asks again N hours after the unlock (default 8) |
|
|
61
|
+
| `session` | once per session, dies with it (default) |
|
|
55
62
|
|
|
56
|
-
`vault_get`
|
|
57
|
-
|
|
58
|
-
| `bitwarden.import` | 行为 |
|
|
59
|
-
|---|---|
|
|
60
|
-
| `ask`(默认) | 给你看这一条 → 读一次 → 问「导入 ai-vault / 只用这一次」 |
|
|
61
|
-
| `always` | 命中直接导入并返回,不开窗口 |
|
|
62
|
-
| `never` | 只读一次,永不写入本地库 |
|
|
63
|
+
`vault_get` searches Bitwarden on a local miss; a hit is shown to you, then read once, then — following `bitwarden.import` — offered for import into ai-vault (so it never touches Bitwarden again) or used just this once. So **only the passwords you approve for import ever enter ai-vault**.
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
Bitwarden's own master-password prompts follow their own switch (`bitwarden.unlock`), and Ente's keychain is bypassed by `ente.unlock` — see `/vault settings`.
|
|
65
66
|
|
|
66
67
|
## Ente
|
|
67
68
|
|
|
68
|
-
`ente` CLI
|
|
69
|
-
|
|
70
|
-
想完全免钥匙串:`ente vault key generate` → `/vault ente-key` 粘进去 → `/vault settings ente.unlock never`。密钥由 ai-vault 加密封存。详见仓库 README。
|
|
71
|
-
|
|
72
|
-
## 安全边界(一句话版)
|
|
73
|
-
|
|
74
|
-
模型的 `bash` 能找到会话令牌、能 `list`,但**签不出读取确认**(签名密钥只在插件进程内存里)、**改不了令牌文件**(带 HMAC,改了就作废)、**免费拿不到 `grant`**(要主密码)。详见仓库 README「安全」一节。
|
|
69
|
+
The `ente` CLI logs in once (`ente account login --app auth`); the extension is only its client: `ente_list` is metadata, `ente_code` confirms every time.
|
|
75
70
|
|
|
76
|
-
|
|
71
|
+
To skip the keychain entirely: `ente vault key generate` → `/vault ente-key` → `/vault settings ente.unlock never`. The key is sealed by ai-vault.
|
|
77
72
|
|
|
78
|
-
|
|
73
|
+
## Security boundary, in one paragraph
|
|
79
74
|
|
|
80
|
-
|
|
75
|
+
The model's `bash` can find a session token and even `list` with one you opened by hand — but it **cannot sign a read confirmation** (the signing secret lives only in the extension process), **cannot edit a token file** (HMAC'd; an edit voids it), and **cannot get a free `grant`** (that costs the master password). Full details in the repository README, *Security*.
|
|
81
76
|
|
|
82
77
|
MIT
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# pi-ai-vault
|
|
2
|
+
|
|
3
|
+
[English](README.md)
|
|
4
|
+
|
|
5
|
+
ai-vault 的 pi 扩展——**omp 也能直接装同一个包**(omp 是 pi 的兼容分支,清单和工具 API 一致;差别只在 `src/host.ts` 的运行时探测里)。
|
|
6
|
+
|
|
7
|
+
它把本地加密密码库交给 [`ai-vault`](https://www.npmjs.com/package/@xiaolikt/ai-vault) 这个 Rust CLI:一台电脑一个库(`~/.ai-vault`),所有 agent 共用。插件本身不做加解密,只持有会话令牌。
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pi install npm:pi-ai-vault # pi,自动带上 ai-vault CLI
|
|
13
|
+
omp plugin install npm:pi-ai-vault # omp,同一个包
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
然后在该宿主的会话里:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
/vault init
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
(弹窗设主密码,两次。有桌面就开 zenity,没有就退回宿主自己的输入框。)
|
|
23
|
+
|
|
24
|
+
不想用 npm 也可以从仓库装:`pi install git:github.com/xiaolikt/ai-vault`。
|
|
25
|
+
|
|
26
|
+
## 工具
|
|
27
|
+
|
|
28
|
+
| 工具 | 作用 | 模型看到密码? |
|
|
29
|
+
|---|---|---|
|
|
30
|
+
| `vault_list` | 本地库条目元数据 | 否 |
|
|
31
|
+
| `vault_get` | 读一条:**先本地库,再 Bitwarden**;Bitwarden 命中会问「读一次 / 导入 ai-vault」 | 是,用户当场允许 |
|
|
32
|
+
| `vault_add` | 存一条,Bitwarden 的全部类型(登录、笔记、银行卡、身份、SSH 密钥、银行账户、驾照、护照);秘密字段在弹窗里输 | 否 |
|
|
33
|
+
| `vault_import` | 把 Bitwarden 登录项抄进本地库(先确认) | 否 |
|
|
34
|
+
| `bw_list` / `bw_run` / `bw_clipboard` / `bw_reveal` | 在线 Bitwarden(`bw` CLI) | 否,`bw_reveal` 除外 |
|
|
35
|
+
| `bw_inject` | 注入 bash 环境(**仅 pi**,omp 不注册) | 否 |
|
|
36
|
+
| `ente_list` | Ente Auth 条目元数据 | 否 |
|
|
37
|
+
| `ente_code` | 当前 TOTP/Steam 验证码(每次确认) | 是,用户当场允许 |
|
|
38
|
+
|
|
39
|
+
## 命令
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
/vault init | unlock | lock | status | list | add | remove
|
|
43
|
+
/vault grant <名称> [分钟] | revoke <名称|all> | audit [n]
|
|
44
|
+
/vault import <bitwarden.json> | import-bw [搜索词]
|
|
45
|
+
/bw status|unlock|lock|clear
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 解锁模式
|
|
49
|
+
|
|
50
|
+
本地库什么时候要主密码,由这台机器的模式决定(`/vault mode`,切换要主密码):
|
|
51
|
+
|
|
52
|
+
| 模式 | 行为 |
|
|
53
|
+
|---|---|
|
|
54
|
+
| `never` | 永远不问,读取也不弹确认窗——「agent 可以自由使用」的那批密码 |
|
|
55
|
+
| `time` | 解锁后 N 小时(默认 8)再问一次 |
|
|
56
|
+
| `session` | 每个会话一次,会话结束失效(默认) |
|
|
57
|
+
|
|
58
|
+
`vault_get` 找不到本地条目时会去 Bitwarden 搜;命中后按 `bitwarden.import` 处理:
|
|
59
|
+
|
|
60
|
+
| `bitwarden.import` | 行为 |
|
|
61
|
+
|---|---|
|
|
62
|
+
| `ask`(默认) | 给你看这一条 → 读一次 → 问「导入 ai-vault / 只用这一次」 |
|
|
63
|
+
| `always` | 命中直接导入并返回,不开窗口 |
|
|
64
|
+
| `never` | 只读一次,永不写入本地库 |
|
|
65
|
+
|
|
66
|
+
所以默认情况下 **只有你同意导入的密码才会进 ai-vault**。Bitwarden 自己的主密码请求频率也有单独设置(`bitwarden.unlock`:`never` / `time` / `session`),用 `/vault settings` 查看和修改。
|
|
67
|
+
|
|
68
|
+
## Ente
|
|
69
|
+
|
|
70
|
+
`ente` CLI 自己登录一次(`ente account login --app auth`),插件只是它的客户端:`ente_list` 只给元数据,`ente_code` 每次弹窗确认。
|
|
71
|
+
|
|
72
|
+
想完全免钥匙串:`ente vault key generate` → `/vault ente-key` 粘进去 → `/vault settings ente.unlock never`。密钥由 ai-vault 加密封存。详见仓库 README。
|
|
73
|
+
|
|
74
|
+
## 安全边界(一句话版)
|
|
75
|
+
|
|
76
|
+
模型的 `bash` 能找到会话令牌、能 `list`,但**签不出读取确认**(签名密钥只在插件进程内存里)、**改不了令牌文件**(带 HMAC,改了就作废)、**免费拿不到 `grant`**(要主密码)。详见仓库 README「安全」一节。
|
|
77
|
+
|
|
78
|
+
## 隔离
|
|
79
|
+
|
|
80
|
+
每个会话、每个子代理各自 `ai-vault unlock`,拿自己的令牌和读授权;父会话的解锁子代理继承不到。空闲 10 分钟自动失效,`/new`、`/fork`、退出会清掉本绑定的令牌。
|
|
81
|
+
|
|
82
|
+
完整说明(CLI 参数、退出码契约、Bitwarden 擦洗、审计、安全模型)见仓库 README:https://github.com/xiaolikt/ai-vault
|
|
83
|
+
|
|
84
|
+
MIT
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-ai-vault",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "pi extension for ai-vault: one machine-wide encrypted secret store
|
|
3
|
+
"version": "0.11.0",
|
|
4
|
+
"description": "pi extension for ai-vault: one machine-wide encrypted secret store, live Bitwarden and Ente Auth. Works in pi and in omp (the omp fork reads the same manifest).",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/xiaolikt/ai-vault.git"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"security"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@xiaolikt/ai-vault": "0.
|
|
28
|
+
"@xiaolikt/ai-vault": "0.11.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@earendil-works/pi-coding-agent": "^1.5.0",
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
39
|
"src",
|
|
40
|
-
"README.md"
|
|
40
|
+
"README.md",
|
|
41
|
+
"README.zh.md"
|
|
41
42
|
],
|
|
42
43
|
"pi": {
|
|
43
44
|
"extensions": [
|
|
@@ -52,10 +52,12 @@ import path from "node:path";
|
|
|
52
52
|
import type { ExtensionAPI, ExtensionContext, ToolDefinition, ToolResultEventResult } from "@earendil-works/pi-coding-agent";
|
|
53
53
|
import { createBashTool } from "@earendil-works/pi-coding-agent";
|
|
54
54
|
import { Type } from "typebox";
|
|
55
|
-
import {
|
|
55
|
+
import { bitwardenItems, filterItems } from "./import-map.js";
|
|
56
|
+
import type { Draft } from "./types.js";
|
|
56
57
|
import { onSessionLeave, sessionLabel, withTier } from "./host.js";
|
|
57
58
|
import { confirmWindow, hasDisplay, promptSecret } from "./prompt.js";
|
|
58
59
|
import { getSettingsSafe, settingsCli } from "./settings.js";
|
|
60
|
+
import { tr } from "./i18n.js";
|
|
59
61
|
import { scrubDeep, scrubText } from "./scrub.js";
|
|
60
62
|
|
|
61
63
|
// ---------------------------------------------------------------------------
|
|
@@ -151,12 +153,16 @@ const BW_LOGIN_HINT =
|
|
|
151
153
|
type BwItem = {
|
|
152
154
|
id?: string;
|
|
153
155
|
name?: string;
|
|
156
|
+
type?: number;
|
|
154
157
|
notes?: string;
|
|
155
158
|
login?: { username?: string; password?: string; totp?: string; uris?: { uri?: string }[] };
|
|
156
|
-
|
|
159
|
+
card?: { cardholderName?: string; brand?: string; number?: string; code?: string };
|
|
160
|
+
identity?: { title?: string; firstName?: string; lastName?: string; email?: string; phone?: string };
|
|
161
|
+
sshKey?: { publicKey?: string; keyFingerprint?: string };
|
|
162
|
+
fields?: { name?: string; value?: string; type?: number }[];
|
|
157
163
|
};
|
|
158
164
|
/** Only metadata is cached; secrets stay in the vault process until needed. */
|
|
159
|
-
type LiteItem = { id: string; name: string; username: string; uri: string };
|
|
165
|
+
type LiteItem = { id: string; name: string; username: string; uri: string; type: string };
|
|
160
166
|
type InjectedSecret = { value: string; item: string; field: string; at: number };
|
|
161
167
|
|
|
162
168
|
/**
|
|
@@ -450,7 +456,7 @@ async function bwStatus(session?: string, signal?: AbortSignal): Promise<any> {
|
|
|
450
456
|
|
|
451
457
|
/** The Bitwarden master password, in a window or the host's input dialog. */
|
|
452
458
|
async function askMasterPassword(ctx: ExtensionContext | undefined, signal?: AbortSignal): Promise<string> {
|
|
453
|
-
const pw = await promptSecret(ctx, "Bitwarden · 主密码", "解锁 Bitwarden 保险库", signal);
|
|
459
|
+
const pw = await promptSecret(ctx, tr("Bitwarden · master password", "Bitwarden · 主密码"), tr("unlock the Bitwarden vault", "解锁 Bitwarden 保险库"), signal);
|
|
454
460
|
if (pw) return pw;
|
|
455
461
|
if (signal?.aborted) throw new Error("Cancelled.");
|
|
456
462
|
if (!hasDisplay() && !ctx?.hasUI) {
|
|
@@ -623,12 +629,23 @@ async function ensureUnlocked(st: BwState, ctx: ExtensionContext | undefined, si
|
|
|
623
629
|
return pending;
|
|
624
630
|
}
|
|
625
631
|
|
|
632
|
+
const BW_TYPE_NAMES: Record<number, string> = { 1: "login", 2: "note", 3: "card", 4: "identity", 5: "sshKey", 6: "bankAccount", 7: "driversLicense", 8: "passport" };
|
|
633
|
+
|
|
626
634
|
function toLite(raw: BwItem): LiteItem {
|
|
635
|
+
const type = BW_TYPE_NAMES[raw.type ?? 1] ?? `type-${raw.type}`;
|
|
636
|
+
// The identifying, non-secret line of each type: username for a login,
|
|
637
|
+
// cardholder for a card, a person's name for an identity, and so on.
|
|
638
|
+
const who =
|
|
639
|
+
raw.login?.username ??
|
|
640
|
+
raw.card?.cardholderName ??
|
|
641
|
+
(raw.identity ? [raw.identity.title, raw.identity.firstName, raw.identity.lastName].filter(Boolean).join(" ") : "") ??
|
|
642
|
+
"";
|
|
627
643
|
return {
|
|
628
644
|
id: raw.id ?? "",
|
|
629
645
|
name: raw.name ?? "",
|
|
630
|
-
username:
|
|
646
|
+
username: who,
|
|
631
647
|
uri: raw.login?.uris?.[0]?.uri ?? "",
|
|
648
|
+
type,
|
|
632
649
|
};
|
|
633
650
|
}
|
|
634
651
|
|
|
@@ -795,34 +812,35 @@ export async function queryBitwarden(
|
|
|
795
812
|
}
|
|
796
813
|
|
|
797
814
|
/**
|
|
798
|
-
*
|
|
799
|
-
* Call only after the user has agreed to the import —
|
|
815
|
+
* Every item that matches `search`, ready to store in the local vault: all
|
|
816
|
+
* types, field for field. Call only after the user has agreed to the import —
|
|
817
|
+
* this reads secrets.
|
|
800
818
|
*/
|
|
801
|
-
export async function
|
|
819
|
+
export async function pullBitwardenItems(
|
|
802
820
|
st: BwState,
|
|
803
821
|
ctx: ExtensionContext | undefined,
|
|
804
822
|
search: string | undefined,
|
|
805
823
|
signal?: AbortSignal,
|
|
806
|
-
): Promise<
|
|
824
|
+
): Promise<Draft[]> {
|
|
807
825
|
const session = await ensureUnlocked(st, ctx, signal);
|
|
808
826
|
const raw: unknown = await runBwJson(["list", "items"], session, signal);
|
|
809
|
-
return
|
|
827
|
+
return filterItems(bitwardenItems(raw), search);
|
|
810
828
|
}
|
|
811
829
|
|
|
812
|
-
export type
|
|
830
|
+
export type BitwardenHit = { draft: Draft; label: string };
|
|
813
831
|
|
|
814
832
|
/**
|
|
815
|
-
* Look one
|
|
816
|
-
* own: the caller shows the user what was found and asks
|
|
817
|
-
* `undefined` means "no such item"; an ambiguous reference
|
|
818
|
-
* candidates so the model can pick one.
|
|
833
|
+
* Look one item up, of any type, and return it as a draft with its secrets,
|
|
834
|
+
* with no window of its own: the caller shows the user what was found and asks
|
|
835
|
+
* whether to read it. `undefined` means "no such item"; an ambiguous reference
|
|
836
|
+
* throws with the candidates so the model can pick one.
|
|
819
837
|
*/
|
|
820
|
-
export async function
|
|
838
|
+
export async function lookupBitwardenItem(
|
|
821
839
|
st: BwState,
|
|
822
840
|
ctx: ExtensionContext | undefined,
|
|
823
841
|
ref: string,
|
|
824
842
|
signal?: AbortSignal,
|
|
825
|
-
): Promise<
|
|
843
|
+
): Promise<BitwardenHit | undefined> {
|
|
826
844
|
const session = await ensureUnlocked(st, ctx, signal);
|
|
827
845
|
let item: LiteItem;
|
|
828
846
|
try {
|
|
@@ -831,14 +849,12 @@ export async function lookupBitwardenLogin(
|
|
|
831
849
|
if (e instanceof Error && /^No Bitwarden item matches/.test(e.message)) return undefined;
|
|
832
850
|
throw e;
|
|
833
851
|
}
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
uris: item.uri ? [item.uri] : [],
|
|
841
|
-
};
|
|
852
|
+
if (!item.id) throw new Error(`Bitwarden item "${item.name}" has no id, so it cannot be read.`);
|
|
853
|
+
const full = (await runBwJson(["get", "item", item.id], session, signal)) as unknown;
|
|
854
|
+
const [draft] = bitwardenItems([full]);
|
|
855
|
+
if (!draft) return undefined;
|
|
856
|
+
const who = item.username ? ` ${item.username}` : "";
|
|
857
|
+
return { draft, label: `${draft.name}${who} (${item.type})` };
|
|
842
858
|
}
|
|
843
859
|
|
|
844
860
|
function normalizeEnvName(raw: string): string {
|
|
@@ -12,6 +12,7 @@ import { spawn } from "node:child_process";
|
|
|
12
12
|
import { existsSync } from "node:fs";
|
|
13
13
|
import { homedir } from "node:os";
|
|
14
14
|
import { delimiter, dirname, join } from "node:path";
|
|
15
|
+
import { lang } from "./i18n.js";
|
|
15
16
|
import { fileURLToPath } from "node:url";
|
|
16
17
|
|
|
17
18
|
export const EXIT = {
|
|
@@ -33,14 +34,19 @@ export interface CliRun {
|
|
|
33
34
|
|
|
34
35
|
/** Non-zero exit from the CLI, with the meaning of the code preserved. */
|
|
35
36
|
export class CliError extends Error {
|
|
37
|
+
/** For `needsUi === "password"`: the hidden field the CLI wants next. */
|
|
38
|
+
readonly field: string | undefined;
|
|
39
|
+
|
|
36
40
|
constructor(
|
|
37
41
|
readonly code: number,
|
|
38
42
|
readonly needsUi: UiStep | undefined,
|
|
39
43
|
message: string,
|
|
40
44
|
readonly stderr: string,
|
|
45
|
+
field?: string,
|
|
41
46
|
) {
|
|
42
47
|
super(message);
|
|
43
48
|
this.name = "CliError";
|
|
49
|
+
this.field = field;
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
get denied(): boolean {
|
|
@@ -91,7 +97,7 @@ export function resolveBinary(): string | undefined {
|
|
|
91
97
|
return undefined;
|
|
92
98
|
}
|
|
93
99
|
|
|
94
|
-
const NEEDS_UI = /^needs-ui:\s*(\w+)
|
|
100
|
+
const NEEDS_UI = /^needs-ui:\s*(\w+)(?:\s+field=(\S+))?/m;
|
|
95
101
|
|
|
96
102
|
function message(stderr: string, fallback: string): string {
|
|
97
103
|
const lines = stderr
|
|
@@ -133,7 +139,7 @@ export class HostSecret {
|
|
|
133
139
|
|
|
134
140
|
/** Environment for a CLI child: marks us as the host and passes the secret. */
|
|
135
141
|
env(): Record<string, string> {
|
|
136
|
-
return { AI_VAULT_HOST: "1", AI_VAULT_HOST_SECRET: this.value };
|
|
142
|
+
return { AI_VAULT_HOST: "1", AI_VAULT_HOST_SECRET: this.value, AI_VAULT_LANG: lang() };
|
|
137
143
|
}
|
|
138
144
|
|
|
139
145
|
/** HMAC over "allow:<token>:<entry>:<y|n>", what `get --answer-stdin` expects. */
|
|
@@ -193,8 +199,9 @@ export class VaultCli {
|
|
|
193
199
|
else child.stdin?.end();
|
|
194
200
|
});
|
|
195
201
|
if (run.code !== 0) {
|
|
196
|
-
const
|
|
197
|
-
|
|
202
|
+
const match = NEEDS_UI.exec(run.stderr);
|
|
203
|
+
const step = match?.[1] as UiStep | undefined;
|
|
204
|
+
throw new CliError(run.code, step, message(run.stderr, `ai-vault exited with ${run.code}`), run.stderr, match?.[2]);
|
|
198
205
|
}
|
|
199
206
|
return run;
|
|
200
207
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { tr } from "./i18n.js";
|
|
1
2
|
/**
|
|
2
3
|
* Ente CLI client.
|
|
3
4
|
*
|
|
@@ -48,7 +49,7 @@ export class EnteError extends Error {
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
const ENTE_MISSING =
|
|
51
|
-
"ente CLI 没找到(要的是 ente.com 的 `ente`,0.4+)。装好后先 `ente account login --app auth` 登录一次;也可以用 ENTE_BIN 指到二进制。";
|
|
52
|
+
tr("ente CLI not found (that is ente.com's `ente`, 0.4+). After installing it, run `ente account login --app auth` once; ENTE_BIN can point at the binary.", "ente CLI 没找到(要的是 ente.com 的 `ente`,0.4+)。装好后先 `ente account login --app auth` 登录一次;也可以用 ENTE_BIN 指到二进制。");
|
|
52
53
|
|
|
53
54
|
/** `ENTE_BIN`, then PATH, then the usual install spots. */
|
|
54
55
|
export function resolveEnte(): string | undefined {
|
|
@@ -256,8 +257,8 @@ export function registerEnte(pi: ExtensionAPI): void {
|
|
|
256
257
|
}
|
|
257
258
|
const ok = await confirmWindow(
|
|
258
259
|
ctx as unknown as Parameters<typeof confirmWindow>[0],
|
|
259
|
-
"pi-ai-vault · Ente Auth 验证码",
|
|
260
|
-
`条目: ${item.name}\n签发方: ${item.issuer || "-"}\n账号: ${item.accountName || "-"}\n\n
|
|
260
|
+
tr("pi-ai-vault · Ente Auth code", "pi-ai-vault · Ente Auth 验证码"),
|
|
261
|
+
tr(`Entry: ${item.name}\n签发方: ${item.issuer || "-"}\n账号: ${item.accountName || "-"}\n\nRead the current code? (It enters the conversation.)`, `条目: ${item.name}\n签发方: ${item.issuer || "-"}\n账号: ${item.accountName || "-"}\n\n读取当前验证码?(会进入对话)`),
|
|
261
262
|
signal,
|
|
262
263
|
);
|
|
263
264
|
if (!ok) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User-facing strings: English by default, Chinese with `AI_VAULT_LANG=zh`
|
|
3
|
+
* (or a `zh_*` locale). The same rule as the CLI's i18n.rs, and the language
|
|
4
|
+
* is passed down to the CLI so its windows and messages agree with ours.
|
|
5
|
+
*
|
|
6
|
+
* Texts a *host* parses (exit codes, `needs-ui:`, error patterns such as
|
|
7
|
+
* "no such entry") never change; only what a human reads does.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export type Lang = "en" | "zh";
|
|
11
|
+
|
|
12
|
+
function detect(): Lang {
|
|
13
|
+
const explicit = (process.env.AI_VAULT_LANG ?? "").toLowerCase();
|
|
14
|
+
if (explicit.startsWith("zh")) return "zh";
|
|
15
|
+
if (explicit) return "en";
|
|
16
|
+
const locale = ["LC_ALL", "LC_MESSAGES", "LANG"]
|
|
17
|
+
.map((name) => (process.env[name] ?? "").toLowerCase())
|
|
18
|
+
.find((value) => value.length > 0);
|
|
19
|
+
return locale?.startsWith("zh") ? "zh" : "en";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let cached: Lang | undefined;
|
|
23
|
+
|
|
24
|
+
export function lang(): Lang {
|
|
25
|
+
return (cached ??= detect());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Pick the English or the Chinese text. */
|
|
29
|
+
export function tr(en: string, zh: string): string {
|
|
30
|
+
return lang() === "zh" ? zh : en;
|
|
31
|
+
}
|