pi-ai-vault 0.7.0 → 0.8.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 +6 -0
- package/package.json +2 -2
- package/src/bitwarden.ts +12 -9
- package/src/ente.ts +278 -0
- package/src/index.ts +3 -0
package/README.md
CHANGED
|
@@ -31,6 +31,8 @@ omp plugin install npm:pi-ai-vault # omp,同一个包
|
|
|
31
31
|
| `vault_import` | 把 Bitwarden 登录项抄进本地库(先确认) | 否 |
|
|
32
32
|
| `bw_list` / `bw_run` / `bw_clipboard` / `bw_reveal` | 在线 Bitwarden(`bw` CLI) | 否,`bw_reveal` 除外 |
|
|
33
33
|
| `bw_inject` | 注入 bash 环境(**仅 pi**,omp 不注册) | 否 |
|
|
34
|
+
| `ente_list` | Ente Auth 条目元数据 | 否 |
|
|
35
|
+
| `ente_code` | 当前 TOTP/Steam 验证码(每次确认) | 是,用户当场允许 |
|
|
34
36
|
|
|
35
37
|
## 命令
|
|
36
38
|
|
|
@@ -61,6 +63,10 @@ omp plugin install npm:pi-ai-vault # omp,同一个包
|
|
|
61
63
|
|
|
62
64
|
所以默认情况下 **只有你同意导入的密码才会进 ai-vault**。Bitwarden 自己的主密码请求频率也有单独设置(`bitwarden.unlock`:`never` / `time` / `session`),用 `/vault settings` 查看和修改。
|
|
63
65
|
|
|
66
|
+
## Ente
|
|
67
|
+
|
|
68
|
+
`ente` CLI 自己登录一次(`ente account login --app auth`),插件只是它的客户端:`ente_list` 只给元数据,`ente_code` 每次弹窗确认。详见仓库 README。
|
|
69
|
+
|
|
64
70
|
## 安全边界(一句话版)
|
|
65
71
|
|
|
66
72
|
模型的 `bash` 能找到会话令牌、能 `list`,但**签不出读取确认**(签名密钥只在插件进程内存里)、**改不了令牌文件**(带 HMAC,改了就作废)、**免费拿不到 `grant`**(要主密码)。详见仓库 README「安全」一节。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-ai-vault",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "pi extension for ai-vault: one machine-wide encrypted secret store plus live Bitwarden. Works in pi and in omp (the omp fork reads the same manifest).",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"security"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@xiaolikt/ai-vault": "0.
|
|
28
|
+
"@xiaolikt/ai-vault": "0.8.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@earendil-works/pi-coding-agent": "^1.5.0",
|
package/src/bitwarden.ts
CHANGED
|
@@ -354,7 +354,7 @@ const AUDIT_MAX_BYTES = 1024 * 1024;
|
|
|
354
354
|
let auditModeFixed = false;
|
|
355
355
|
|
|
356
356
|
/** One audit line per event. `session` is the binding's label, so a subagent's `bw_run` can be told from its parent's. */
|
|
357
|
-
async function
|
|
357
|
+
export async function auditEvent(event: string, detail: string, session?: string): Promise<void> {
|
|
358
358
|
try {
|
|
359
359
|
await fs.mkdir(STATE_DIR, { recursive: true, mode: 0o700 });
|
|
360
360
|
const log = path.join(STATE_DIR, "audit.log");
|
|
@@ -513,7 +513,7 @@ async function lock(st: BwState, reason: string): Promise<void> {
|
|
|
513
513
|
st.lockTimer = undefined;
|
|
514
514
|
}
|
|
515
515
|
if (hadSession) {
|
|
516
|
-
await
|
|
516
|
+
await auditEvent("lock", `reason=${reason}`, st.sessionLabel);
|
|
517
517
|
if (!releaseSessionKey()) return; // another binding still uses its own key
|
|
518
518
|
try {
|
|
519
519
|
const bin = await resolveBw();
|
|
@@ -581,7 +581,7 @@ async function ensureUnlocked(st: BwState, ctx: ExtensionContext | undefined, si
|
|
|
581
581
|
signal,
|
|
582
582
|
});
|
|
583
583
|
if (r.code !== 0) {
|
|
584
|
-
await
|
|
584
|
+
await auditEvent("unlock", "deny=bad-password", st.sessionLabel);
|
|
585
585
|
throw new Error(`Unlock failed (wrong master password or CLI error). ${tail(r.stderr, 120)}`);
|
|
586
586
|
}
|
|
587
587
|
const key = r.stdout.replace(/[\r\n]+$/, "");
|
|
@@ -599,7 +599,7 @@ async function ensureUnlocked(st: BwState, ctx: ExtensionContext | undefined, si
|
|
|
599
599
|
// from the bitwarden.hours policy.
|
|
600
600
|
await settingsCli().run(["bw-session", "put"], { stdin: key }).catch(() => undefined);
|
|
601
601
|
}
|
|
602
|
-
await
|
|
602
|
+
await auditEvent("unlock", "ok", st.sessionLabel);
|
|
603
603
|
// Refresh in the background: a full sync can take seconds on large vaults.
|
|
604
604
|
const lastSync = Date.parse(status?.lastSync ?? "");
|
|
605
605
|
if (!Number.isFinite(lastSync) || Date.now() - lastSync > 15 * 60_000) {
|
|
@@ -750,7 +750,7 @@ async function approveItem(
|
|
|
750
750
|
const user = item.username ? ` (user: ${item.username})` : "";
|
|
751
751
|
const ok = await confirmAction(ctx, title, `Item: ${name}${user}\nField: ${field}\n${detail}\n\nAllow?`, signal);
|
|
752
752
|
if (!ok) {
|
|
753
|
-
await
|
|
753
|
+
await auditEvent(event, `deny item="${name}" field=${field}`, st.sessionLabel);
|
|
754
754
|
return undefined;
|
|
755
755
|
}
|
|
756
756
|
return { session, item };
|
|
@@ -1116,6 +1116,9 @@ export function registerBitwarden(pi: ExtensionAPI, st: BwState, ompHost: boolea
|
|
|
1116
1116
|
spawnHook: ({ command, cwd, env }) => {
|
|
1117
1117
|
// A BW_SESSION exported in the user's shell must not reach bash.
|
|
1118
1118
|
for (const name of Object.keys(env)) if (name.startsWith("BW_")) delete env[name];
|
|
1119
|
+
// Same for Ente's unattended vault key / export password: the model's
|
|
1120
|
+
// shell must not be able to open Ente Auth with what the user exported.
|
|
1121
|
+
for (const name of ["ENTE_CLI_VAULT_KEY", "ENTE_CLI_PASSWORD"]) delete env[name];
|
|
1119
1122
|
for (const [name, rec] of st.injected) env[name] = rec.value;
|
|
1120
1123
|
return { command, cwd, env };
|
|
1121
1124
|
},
|
|
@@ -1230,7 +1233,7 @@ export function registerBitwarden(pi: ExtensionAPI, st: BwState, ompHost: boolea
|
|
|
1230
1233
|
const { value, itemId, itemName } = await secretOf(approved.session, approved.item, field, signal);
|
|
1231
1234
|
st.injected.set(envName, { value, item: itemName, field, at: Date.now() });
|
|
1232
1235
|
rememberScrubValue(envName, value);
|
|
1233
|
-
await
|
|
1236
|
+
await auditEvent("inject", `allow env=${envName} item="${itemName}" (${itemId}) field=${field}`, st.sessionLabel);
|
|
1234
1237
|
safeStatus(ctx, `🔓 bw: ${st.injected.size} env var(s)`);
|
|
1235
1238
|
const weak =
|
|
1236
1239
|
value.length < 6
|
|
@@ -1303,7 +1306,7 @@ export function registerBitwarden(pi: ExtensionAPI, st: BwState, ompHost: boolea
|
|
|
1303
1306
|
signal,
|
|
1304
1307
|
group: true,
|
|
1305
1308
|
});
|
|
1306
|
-
await
|
|
1309
|
+
await auditEvent("run", `allow env=${envName} item="${itemName}" field=${field} exit=${r.code}`, st.sessionLabel);
|
|
1307
1310
|
const raw = [r.stdout, r.stderr].filter((s) => s.length > 0).join("\n");
|
|
1308
1311
|
const scrubbed = scrubText(raw, scrubValues.values()).text;
|
|
1309
1312
|
const output =
|
|
@@ -1356,7 +1359,7 @@ export function registerBitwarden(pi: ExtensionAPI, st: BwState, ompHost: boolea
|
|
|
1356
1359
|
// so tool output carrying it must be scrubbed like an injected var.
|
|
1357
1360
|
rememberScrubValue("CLIPBOARD", value);
|
|
1358
1361
|
await copyToClipboard(value);
|
|
1359
|
-
await
|
|
1362
|
+
await auditEvent("clipboard", `allow item="${itemName}" field=${field}`, st.sessionLabel);
|
|
1360
1363
|
const clears =
|
|
1361
1364
|
CONFIG.clipboardClearSeconds > 0 ? `Clears in ${CONFIG.clipboardClearSeconds}s.` : "Auto-clear disabled.";
|
|
1362
1365
|
return {
|
|
@@ -1401,7 +1404,7 @@ export function registerBitwarden(pi: ExtensionAPI, st: BwState, ompHost: boolea
|
|
|
1401
1404
|
);
|
|
1402
1405
|
if (!approved) throw new Error("User declined the reveal.");
|
|
1403
1406
|
const { value, itemName } = await secretOf(approved.session, approved.item, field, signal);
|
|
1404
|
-
await
|
|
1407
|
+
await auditEvent("reveal", `allow item="${itemName}" field=${field}`, st.sessionLabel);
|
|
1405
1408
|
return {
|
|
1406
1409
|
content: [{ type: "text", text: `${itemName} (${field}):\n<secret>${value}</secret>` }],
|
|
1407
1410
|
details: { item: itemName, field },
|
package/src/ente.ts
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ente CLI client.
|
|
3
|
+
*
|
|
4
|
+
* `ente` (Ente's "client for terminals and agents") is logged in once —
|
|
5
|
+
* `ente account login --app auth` — and then keeps its session on disk
|
|
6
|
+
* (`$XDG_DATA_HOME/ente-cli`) with the database key in the OS keychain, or in
|
|
7
|
+
* `ENTE_CLI_VAULT_KEY` for unattended use. So no password per call here: we
|
|
8
|
+
* only run the CLI and parse its JSON.
|
|
9
|
+
*
|
|
10
|
+
* What this module adds on top of the bare CLI is the extension's rules:
|
|
11
|
+
* metadata listing returns no secrets, reading one current code always passes
|
|
12
|
+
* through a confirm window that names the entry, and every read is audited.
|
|
13
|
+
*
|
|
14
|
+
* JSON contract (ente.com/help/cli/auth):
|
|
15
|
+
* `auth code list --json` -> [{ id, name, issuer, accountName, type }]
|
|
16
|
+
* `auth code view <q> --json` -> the same object plus { otp, validUntil }
|
|
17
|
+
*/
|
|
18
|
+
import { spawn } from "node:child_process";
|
|
19
|
+
import { existsSync } from "node:fs";
|
|
20
|
+
import { homedir } from "node:os";
|
|
21
|
+
import { delimiter, join } from "node:path";
|
|
22
|
+
import type { ExtensionAPI, ExtensionContext, ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
23
|
+
import { Type } from "typebox";
|
|
24
|
+
|
|
25
|
+
import { auditEvent } from "./bitwarden.js";
|
|
26
|
+
import { confirmWindow, forDialog } from "./prompt.js";
|
|
27
|
+
import { withTier } from "./host.js";
|
|
28
|
+
|
|
29
|
+
export interface EnteCodeMeta {
|
|
30
|
+
id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
issuer: string;
|
|
33
|
+
accountName: string;
|
|
34
|
+
type: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface EnteCode extends EnteCodeMeta {
|
|
38
|
+
otp: string;
|
|
39
|
+
validUntil: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class EnteError extends Error {
|
|
43
|
+
constructor(message: string, readonly code: number) {
|
|
44
|
+
super(message);
|
|
45
|
+
this.name = "EnteError";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const ENTE_MISSING =
|
|
50
|
+
"ente CLI 没找到(要的是 ente.com 的 `ente`,0.4+)。装好后先 `ente account login --app auth` 登录一次;也可以用 ENTE_BIN 指到二进制。";
|
|
51
|
+
|
|
52
|
+
/** `ENTE_BIN`, then PATH, then the usual install spots. */
|
|
53
|
+
export function resolveEnte(): string | undefined {
|
|
54
|
+
const explicit = process.env.ENTE_BIN;
|
|
55
|
+
if (explicit) return existsSync(explicit) ? explicit : undefined;
|
|
56
|
+
for (const dir of (process.env.PATH ?? "").split(delimiter)) {
|
|
57
|
+
if (!dir) continue;
|
|
58
|
+
const candidate = join(dir, "ente");
|
|
59
|
+
if (existsSync(candidate)) return candidate;
|
|
60
|
+
}
|
|
61
|
+
for (const candidate of [
|
|
62
|
+
join(homedir(), ".local", "opt", "ente-cli", "bin", "ente"),
|
|
63
|
+
join(homedir(), ".local", "bin", "ente"),
|
|
64
|
+
join(homedir(), ".cargo", "bin", "ente"),
|
|
65
|
+
]) {
|
|
66
|
+
if (existsSync(candidate)) return candidate;
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface Run {
|
|
72
|
+
code: number;
|
|
73
|
+
stdout: string;
|
|
74
|
+
stderr: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function runEnte(args: string[], signal?: AbortSignal): Promise<Run> {
|
|
78
|
+
const bin = resolveEnte();
|
|
79
|
+
if (!bin) throw new EnteError(ENTE_MISSING, 127);
|
|
80
|
+
if (signal?.aborted) throw new EnteError("Cancelled.", 4);
|
|
81
|
+
return new Promise<Run>((resolve, reject) => {
|
|
82
|
+
const child = spawn(bin, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
83
|
+
let stdout = "";
|
|
84
|
+
let stderr = "";
|
|
85
|
+
const onAbort = () => child.kill("SIGKILL");
|
|
86
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
87
|
+
child.stdout?.on("data", (chunk: Buffer | string) => {
|
|
88
|
+
if (stdout.length < 8 * 1024 * 1024) stdout += chunk;
|
|
89
|
+
});
|
|
90
|
+
child.stderr?.on("data", (chunk: Buffer | string) => {
|
|
91
|
+
if (stderr.length < 64_000) stderr += chunk;
|
|
92
|
+
});
|
|
93
|
+
child.on("error", (error) => {
|
|
94
|
+
signal?.removeEventListener("abort", onAbort);
|
|
95
|
+
reject(new EnteError(`cannot run ente: ${error.message}`, 127));
|
|
96
|
+
});
|
|
97
|
+
child.on("close", (code) => {
|
|
98
|
+
signal?.removeEventListener("abort", onAbort);
|
|
99
|
+
resolve({ code: code ?? -1, stdout, stderr });
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function enteJson<T>(args: string[], signal?: AbortSignal): Promise<T> {
|
|
105
|
+
// --no-input: a prompt becomes an error instead of a hang behind our back.
|
|
106
|
+
const run = await runEnte(["--json", "--no-input", ...args], signal);
|
|
107
|
+
if (run.code !== 0) {
|
|
108
|
+
const message = run.stderr
|
|
109
|
+
.split(/\r?\n/)
|
|
110
|
+
.map((line) => line.trim())
|
|
111
|
+
.filter(Boolean)
|
|
112
|
+
.slice(-3)
|
|
113
|
+
.join(" ");
|
|
114
|
+
throw new EnteError(message || `ente exited with ${run.code}`, run.code);
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
return JSON.parse(run.stdout) as T;
|
|
118
|
+
} catch {
|
|
119
|
+
throw new EnteError(`ente returned non-JSON output: ${run.stdout.slice(0, 200)}`, 1);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const asString = (value: unknown): string => (typeof value === "string" ? value : "");
|
|
124
|
+
const normalize = (raw: unknown): EnteCodeMeta => {
|
|
125
|
+
const r = (raw ?? {}) as Record<string, unknown>;
|
|
126
|
+
return {
|
|
127
|
+
id: asString(r.id),
|
|
128
|
+
name: forDialog(asString(r.name), 80),
|
|
129
|
+
issuer: forDialog(asString(r.issuer), 60),
|
|
130
|
+
accountName: forDialog(asString(r.accountName), 60),
|
|
131
|
+
type: asString(r.type) || "totp",
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/** Metadata only: names, issuers, account names. No codes, no secrets. */
|
|
136
|
+
export async function listCodes(signal?: AbortSignal): Promise<EnteCodeMeta[]> {
|
|
137
|
+
const list = async (extra: string[] = []): Promise<EnteCodeMeta[]> => {
|
|
138
|
+
const raw = await enteJson<unknown[]>(["auth", "code", "list", ...extra], signal);
|
|
139
|
+
return Array.isArray(raw) ? raw.map(normalize) : [];
|
|
140
|
+
};
|
|
141
|
+
try {
|
|
142
|
+
return await list();
|
|
143
|
+
} catch (error) {
|
|
144
|
+
// A first run may have nothing synced yet; --offline reads what is cached.
|
|
145
|
+
// A not-logged-in CLI fails both ways, and the error is what the user needs.
|
|
146
|
+
if (!(error instanceof EnteError)) throw error;
|
|
147
|
+
return list(["--offline"]);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** One current code. The caller must have shown the user which entry this is. */
|
|
152
|
+
export async function viewCode(ref: string, signal?: AbortSignal): Promise<EnteCode> {
|
|
153
|
+
const raw = await enteJson<Record<string, unknown>>(["auth", "code", "view", ref], signal);
|
|
154
|
+
const meta = normalize(raw);
|
|
155
|
+
const otp = asString(raw.otp);
|
|
156
|
+
if (!otp) throw new EnteError(`ente returned no code for "${ref}"`, 1);
|
|
157
|
+
return { ...meta, otp, validUntil: asString(raw.validUntil) };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The entry a reference really names, so the window shows what will be read. */
|
|
161
|
+
export function resolveRef(items: EnteCodeMeta[], ref: string): EnteCodeMeta | undefined {
|
|
162
|
+
const query = ref.trim().toLowerCase();
|
|
163
|
+
if (!query) return undefined;
|
|
164
|
+
const haystack = (item: EnteCodeMeta): string =>
|
|
165
|
+
`${item.name}\n${item.issuer}\n${item.accountName}`.toLowerCase();
|
|
166
|
+
const exact = items.filter((item) => item.name.toLowerCase() === query);
|
|
167
|
+
if (exact.length === 1) return exact[0];
|
|
168
|
+
const hits = items.filter((item) => haystack(item).includes(query));
|
|
169
|
+
return hits.length === 1 ? hits[0] : exact[0] ?? (hits.length > 1 ? undefined : undefined);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
type ToolOutcome = {
|
|
173
|
+
content: { type: "text"; text: string }[];
|
|
174
|
+
details: { ok?: boolean; denied?: boolean; item?: string; count?: number };
|
|
175
|
+
isError?: boolean;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const fail = (text: string, denied = false): ToolOutcome => ({
|
|
179
|
+
content: [{ type: "text" as const, text }],
|
|
180
|
+
details: { ok: false, ...(denied ? { denied: true } : {}) },
|
|
181
|
+
isError: true,
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const describe = (error: unknown): string => (error instanceof Error ? error.message : String(error));
|
|
185
|
+
|
|
186
|
+
export function registerEnte(pi: ExtensionAPI): void {
|
|
187
|
+
const listParams = Type.Object({});
|
|
188
|
+
const listTool: ToolDefinition<typeof listParams, { ok?: boolean; count?: number }> = {
|
|
189
|
+
name: "ente_list",
|
|
190
|
+
label: "Ente: list Auth codes",
|
|
191
|
+
description:
|
|
192
|
+
"List the entries saved in Ente Auth through the `ente` CLI: name, issuer, account name, type (totp/hotp/steam). " +
|
|
193
|
+
"NEVER returns codes or secrets. Use ente_code to read one; the user must approve a window first. " +
|
|
194
|
+
"Sessions come from `ente account login --app auth` (and optionally ENTE_CLI_VAULT_KEY), not from the master password of ai-vault.",
|
|
195
|
+
promptSnippet: "List Ente Auth entries (metadata only).",
|
|
196
|
+
parameters: listParams,
|
|
197
|
+
async execute(_id, _params, signal, _onUpdate, ctx) {
|
|
198
|
+
try {
|
|
199
|
+
const items = await listCodes(signal);
|
|
200
|
+
await auditEvent(`ente.list`, `count=${items.length}`, sessionLabelOf(ctx));
|
|
201
|
+
return {
|
|
202
|
+
content: [{ type: "text" as const, text: JSON.stringify(items, null, 1) }],
|
|
203
|
+
details: { count: items.length },
|
|
204
|
+
};
|
|
205
|
+
} catch (error) {
|
|
206
|
+
return fail(describe(error));
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const codeParams = Type.Object({
|
|
212
|
+
name: Type.String({ description: "Entry name, or part of its name/issuer/account" }),
|
|
213
|
+
});
|
|
214
|
+
const codeTool: ToolDefinition<typeof codeParams, { ok?: boolean; denied?: boolean; item?: string }> = {
|
|
215
|
+
name: "ente_code",
|
|
216
|
+
label: "Ente: show a current code",
|
|
217
|
+
description:
|
|
218
|
+
"Return the current TOTP/Steam code for one Ente Auth entry. The user approves a window that names the entry; the code is short-lived. " +
|
|
219
|
+
"If the user denies, do not retry. Codes go into the conversation — prefer passing them on in the same turn.",
|
|
220
|
+
promptSnippet: "Read one current Ente Auth code after the user approves a window.",
|
|
221
|
+
parameters: codeParams,
|
|
222
|
+
async execute(_id, params, signal, _onUpdate, ctx) {
|
|
223
|
+
try {
|
|
224
|
+
const items = await listCodes(signal);
|
|
225
|
+
if (items.length === 0) return fail("Ente Auth has no saved codes on this device — run `ente account login --app auth` first.");
|
|
226
|
+
const item = resolveRef(items, params.name);
|
|
227
|
+
if (!item) {
|
|
228
|
+
const names = items.slice(0, 15).map((i) => `${i.name}${i.issuer ? ` (${i.issuer})` : ""}`);
|
|
229
|
+
return fail(`no single Ente entry matches "${params.name}". candidates: ${names.join(", ") || "(none)"}`);
|
|
230
|
+
}
|
|
231
|
+
const ok = await confirmWindow(
|
|
232
|
+
ctx as unknown as Parameters<typeof confirmWindow>[0],
|
|
233
|
+
"pi-ai-vault · Ente Auth 验证码",
|
|
234
|
+
`条目: ${item.name}\n签发方: ${item.issuer || "-"}\n账号: ${item.accountName || "-"}\n\n读取当前验证码?(会进入对话)`,
|
|
235
|
+
signal,
|
|
236
|
+
);
|
|
237
|
+
if (!ok) {
|
|
238
|
+
await auditEvent("ente.code", `deny item="${item.name}"`, sessionLabelOf(ctx));
|
|
239
|
+
return fail(`user denied reading the code for "${item.name}" — do not retry`, true);
|
|
240
|
+
}
|
|
241
|
+
const code = await viewCode(item.name, signal);
|
|
242
|
+
await auditEvent("ente.code", `allow item="${item.name}"`, sessionLabelOf(ctx));
|
|
243
|
+
return {
|
|
244
|
+
content: [
|
|
245
|
+
{
|
|
246
|
+
type: "text" as const,
|
|
247
|
+
text: JSON.stringify(
|
|
248
|
+
{ name: code.name, issuer: code.issuer, accountName: code.accountName, code: code.otp, validUntil: code.validUntil, via: "ente" },
|
|
249
|
+
null,
|
|
250
|
+
1,
|
|
251
|
+
),
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
details: { ok: true, item: code.name },
|
|
255
|
+
};
|
|
256
|
+
} catch (error) {
|
|
257
|
+
if (signal?.aborted) return fail("cancelled", true);
|
|
258
|
+
return fail(describe(error));
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
pi.registerTool(withTier(listTool, "read"));
|
|
264
|
+
pi.registerTool(withTier(codeTool, "write"));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** Same shape as the Bitwarden audit lines: the session or subagent that asked. */
|
|
268
|
+
function sessionLabelOf(ctx: ExtensionContext | undefined): string {
|
|
269
|
+
const agent = (ctx as { agent?: { kind?: string; id?: string } } | undefined)?.agent;
|
|
270
|
+
if (agent?.kind === "sub" && agent.id) return agent.id.replace(/[^\w.-]/g, "").slice(0, 24);
|
|
271
|
+
let id = "";
|
|
272
|
+
try {
|
|
273
|
+
id = (ctx as { sessionManager?: { getSessionId?: () => string } } | undefined)?.sessionManager?.getSessionId?.() ?? "";
|
|
274
|
+
} catch {
|
|
275
|
+
/* a context without a session manager */
|
|
276
|
+
}
|
|
277
|
+
return id.replace(/-/g, "").slice(0, 8) || "main";
|
|
278
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
type BwState,
|
|
24
24
|
} from "./bitwarden.js";
|
|
25
25
|
import { CliError, VaultCli } from "./cli.js";
|
|
26
|
+
import { registerEnte } from "./ente.js";
|
|
26
27
|
import { isOmpHost, onSessionLeave, sessionLabel, subagentId, withTier } from "./host.js";
|
|
27
28
|
import { confirmWindow, forDialog, promptSecret, promptText, type PromptHost } from "./prompt.js";
|
|
28
29
|
import { forgetSettings, getSettingsSafe, type Settings } from "./settings.js";
|
|
@@ -1017,6 +1018,8 @@ export default function aiVault(pi: ExtensionAPI): void {
|
|
|
1017
1018
|
pi.registerTool(vaultAddTool(scope));
|
|
1018
1019
|
pi.registerTool(vaultImportTool(scope, bw));
|
|
1019
1020
|
registerBitwarden(pi, bw, omp);
|
|
1021
|
+
// Ente Auth: the `ente` CLI keeps its own login; these tools only read codes.
|
|
1022
|
+
registerEnte(pi);
|
|
1020
1023
|
pi.registerCommand("vault", {
|
|
1021
1024
|
description: "本地密码库 + Bitwarden 导入(/vault help)",
|
|
1022
1025
|
handler: commandHandler(scope, bw),
|