@xiaolikt/ai-vault 0.9.1 → 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.
@@ -1,3 +1,4 @@
1
+ import { tr } from "./i18n.js";
1
2
  /**
2
3
  * ai-vault — the pi/omp extension.
3
4
  *
@@ -100,8 +101,8 @@ interface Scope {
100
101
  const cli = new VaultCli();
101
102
 
102
103
  const CLI_MISSING =
103
- "ai-vault CLI 没找到。装一次就有全机共享的库:cargo install --path <repo>/crates/ai-vault(或用 AI_VAULT_BIN 指向编译好的二进制)";
104
- const NOT_INITIALIZED = "本地库还没初始化 — 运行 /vault init";
104
+ tr("ai-vault CLI not found. Install it once for a machine-wide store: cargo install --path <repo>/crates/ai-vault (or point AI_VAULT_BIN at a compiled binary)", "ai-vault CLI 没找到。装一次就有全机共享的库:cargo install --path <repo>/crates/ai-vault(或用 AI_VAULT_BIN 指向编译好的二进制)");
105
+ const NOT_INITIALIZED = tr("the local store is not initialised — run /vault init", "本地库还没初始化 — 运行 /vault init");
105
106
  const LOCKED = "local vault is locked (no master password entered, or the window was cancelled)";
106
107
 
107
108
  const dialogs = (ctx: Ctx): PromptHost => ctx as unknown as PromptHost;
@@ -216,9 +217,9 @@ async function ensureUnlocked(scope: Scope, ctx: Ctx, signal?: AbortSignal): Pro
216
217
  result = await attempt();
217
218
  } catch (error) {
218
219
  if (!(error instanceof CliError) || !error.needsUi) throw error;
219
- const password = await promptSecret(dialogs(ctx), "ai-vault · 解锁", "本地库主密码", signal);
220
+ const password = await promptSecret(dialogs(ctx), tr("ai-vault · unlock", "ai-vault · 解锁"), tr("local store master password", "本地库主密码"), signal);
220
221
  if (!password) {
221
- if (!signal?.aborted) note(ctx, "没有输入主密码(窗口已取消,或没有桌面/界面)", "warning");
222
+ if (!signal?.aborted) note(ctx, tr("no master password entered (the window was cancelled, or there is no desktop/UI)", "没有输入主密码(窗口已取消,或没有桌面/界面)"), "warning");
222
223
  return false;
223
224
  }
224
225
  result = await attempt(password);
@@ -237,7 +238,7 @@ async function ensureUnlocked(scope: Scope, ctx: Ctx, signal?: AbortSignal): Pro
237
238
  return true;
238
239
  } catch (error) {
239
240
  if (error instanceof CliError && error.auth) {
240
- note(ctx, "ai-vault: 主密码错误", "error");
241
+ note(ctx, tr("ai-vault: wrong master password", "ai-vault: 主密码错误"), "error");
241
242
  return false;
242
243
  }
243
244
  if (error instanceof CliError && /not initialized/i.test(error.message)) {
@@ -358,8 +359,8 @@ async function bitwardenFallback(
358
359
  const label = `${hit.name}${hit.username ? ` user:${hit.username}` : ""}`;
359
360
  const allow = await confirmWindow(
360
361
  dialogs(ctx),
361
- "pi-ai-vault · Bitwarden 里找到",
362
- `本地库没有「${forDialog(name)}」,Bitwarden 里有:\n${forDialog(label)}\n\n读取这一次吗?`,
362
+ tr("pi-ai-vault · found in Bitwarden", "pi-ai-vault · Bitwarden 里找到"),
363
+ tr(`Not in the local store as "${forDialog(name)}」,Bitwarden 里yes:\n${forDialog(label)}\n\n读取这一次吗?`, `本地库没有「${forDialog(name)}」,Bitwarden 里有:\n${forDialog(label)}\n\n读取这一次吗?`),
363
364
  signal,
364
365
  );
365
366
  if (!allow) return fail(`user denied reading "${hit.name}" from Bitwarden — do not retry`, true);
@@ -367,8 +368,8 @@ async function bitwardenFallback(
367
368
 
368
369
  const confirmed = await confirmWindow(
369
370
  dialogs(ctx),
370
- "pi-ai-vault · 导入到 ai-vault",
371
- `把「${forDialog(hit.name)}」写进 ai-vault 吗?\n\n允许 → 以后直接读本地库(按当前解锁模式,可能免密)\n拒绝 → 只用这一次,不写入本地库`,
371
+ tr("pi-ai-vault · import into ai-vault", "pi-ai-vault · 导入到 ai-vault"),
372
+ tr(`Write "${forDialog(hit.name)}」写进 ai-vault 吗?\n\nAllow → read from the local store from now on (no password under the current unlock policy)\nDeny → use it once only; nothing is written to the local store`, `把「${forDialog(hit.name)}」写进 ai-vault 吗?\n\n允许 → 以后直接读本地库(按当前解锁模式,可能免密)\n拒绝 → 只用这一次,不写入本地库`),
372
373
  signal,
373
374
  );
374
375
  return confirmed ? importIt() : asValue("bitwarden-once");
@@ -407,9 +408,9 @@ function vaultGetTool(scope: Scope, bw: BwState): ToolDefinition<typeof vaultGet
407
408
  const sub = subagentId(ctx);
408
409
  const allowed = await confirmWindow(
409
410
  dialogs(ctx),
410
- "ai-vault · 读取本地密码",
411
- `条目: ${forDialog(params.name)}\n请求方: ${sub ? `子代理 ${forDialog(sub, 32)}` : "主会话"}\n原因: ${forDialog(params.reason ?? "(未说明)", 120)}\n\n` +
412
- "允许后 5 分钟内同一请求方可再次读取。密码会进入对话。",
411
+ tr("ai-vault · read local password", "ai-vault · 读取本地密码"),
412
+ tr(`Entry: ${forDialog(params.name)}\nRequester: ${sub ? `subagent ${forDialog(sub, 32)}` : "main session"}\nReason: ${forDialog(params.reason ?? "(none given)", 120)}\n\n`, `条目: ${forDialog(params.name)}\n请求方: ${sub ? `子代理 ${forDialog(sub, 32)}` : "主会话"}\n原因: ${forDialog(params.reason ?? "(未说明)", 120)}\n\n`) +
413
+ tr("Allowing lets the same requester read it again for 5 minutes. The password enters the conversation.", "允许后 5 分钟内同一请求方可再次读取。密码会进入对话。"),
413
414
  signal,
414
415
  );
415
416
  // Relaying is our privilege as the host: sign the answer under the
@@ -518,7 +519,7 @@ async function saveLocalEntry(scope: Scope, ctx: Ctx, req: SaveRequest): Promise
518
519
  if (!(await ensureUnlocked(scope, ctx, req.signal))) return LOCKED;
519
520
  let name = req.name?.trim() ?? "";
520
521
  if (!name) {
521
- const entered = await promptText(dialogs(ctx), "ai-vault · 新条目", "名称", req.signal);
522
+ const entered = await promptText(dialogs(ctx), tr("ai-vault · new entry", "ai-vault · 新条目"), tr("name", "名称"), req.signal);
522
523
  name = entered?.trim() ?? "";
523
524
  }
524
525
  if (!name) return "cancelled: no entry name";
@@ -542,16 +543,16 @@ async function saveLocalEntry(scope: Scope, ctx: Ctx, req: SaveRequest): Promise
542
543
  }
543
544
  if (error.needsUi === "confirm") {
544
545
  const meta = [
545
- req.username?.trim() ? `用户名: ${forDialog(req.username, 60)}` : "",
546
+ req.username?.trim() ? tr(`Username: ${forDialog(req.username, 60)}`, `用户名: ${forDialog(req.username, 60)}`) : "",
546
547
  req.uri?.trim() ? `URI: ${forDialog(req.uri, 120)}` : "",
547
- req.notes?.trim() ? `备注: ${forDialog(req.notes, 120)}` : "",
548
+ req.notes?.trim() ? tr(`Notes: ${forDialog(req.notes, 120)}`, `备注: ${forDialog(req.notes, 120)}`) : "",
548
549
  ]
549
550
  .filter(Boolean)
550
551
  .join("\n");
551
552
  const ok = await confirmWindow(
552
553
  dialogs(ctx),
553
- "ai-vault · 保存到本地库",
554
- `保存条目「${forDialog(name)}」。${meta ? `\n${meta}` : ""}\n下一步会弹出窗口,由你输入密码。密码不会进入对话。`,
554
+ tr("ai-vault · save to local store", "ai-vault · 保存到本地库"),
555
+ tr(`Save the entry "${forDialog(name)}".${meta ? `\n${meta}` : ""}\nA window opens next for you to type the password. It never enters the conversation.`, `保存条目「${forDialog(name)}」。${meta ? `\n${meta}` : ""}\n下一步会弹出窗口,由你输入密码。密码不会进入对话。`),
555
556
  req.signal,
556
557
  );
557
558
  if (!ok) return `user denied saving "${name}"`;
@@ -559,12 +560,12 @@ async function saveLocalEntry(scope: Scope, ctx: Ctx, req: SaveRequest): Promise
559
560
  continue;
560
561
  }
561
562
  if (error.needsUi === "text") {
562
- const entered = await promptText(dialogs(ctx), `ai-vault · ${name}`, "用户名(可留空)", req.signal);
563
+ const entered = await promptText(dialogs(ctx), `ai-vault · ${name}`, tr("username (optional)", "用户名(可留空)"), req.signal);
563
564
  if (entered === undefined) return "cancelled";
564
565
  args.push("--username", entered);
565
566
  continue;
566
567
  }
567
- const password = await promptSecret(dialogs(ctx), "ai-vault · 密码", name, req.signal);
568
+ const password = await promptSecret(dialogs(ctx), tr("ai-vault · password", "ai-vault · 密码"), name, req.signal);
568
569
  if (!password) return "cancelled: no password entered";
569
570
  args.push("--password-stdin");
570
571
  stdin = `${password}\n`;
@@ -594,11 +595,11 @@ async function importBitwarden(
594
595
  .slice(0, 15)
595
596
  .map((item) => `• ${item.name}${item.username ? ` user:${item.username}` : ""}${item.uri ? ` ${item.uri}` : ""}`)
596
597
  .join("\n");
597
- const more = meta.length > 15 ? `\n… 还有 ${meta.length - 15} 条` : "";
598
+ const more = meta.length > 15 ? tr(`\n… 还yes ${meta.length - 15} 条`, `\n… 还有 ${meta.length - 15} 条`) : "";
598
599
  const allowed = await confirmWindow(
599
600
  dialogs(ctx),
600
- "ai-vault · 从 Bitwarden 导入",
601
- `匹配 ${meta.length} 条。其中带密码的登录项会写入本地加密库,同名条目会被更新。\n\n${shown}${more}\n\n允许导入?`,
601
+ tr("ai-vault · import from Bitwarden", "ai-vault · 从 Bitwarden 导入"),
602
+ tr(`Matched ${meta.length} 条。其中带密码的登录项会写入本地加密库,同名条目会被更新。\n\n${shown}${more}\n\nImport?`, `匹配 ${meta.length} 条。其中带密码的登录项会写入本地加密库,同名条目会被更新。\n\n${shown}${more}\n\n允许导入?`),
602
603
  signal,
603
604
  );
604
605
  if (!allowed) return { text: "user denied the Bitwarden import", ok: false, count: 0 };
@@ -633,21 +634,21 @@ async function importBitwarden(
633
634
  // ---------------------------------------------------------------- commands
634
635
 
635
636
  const HELP = [
636
- "/vault init 创建全机共享的本地加密库(弹出窗口设置主密码)",
637
- "/vault unlock | lock 解锁 / 锁定(清空本会话的授权)",
638
- "/vault mode [never|time|session] 查看/切换解锁模式(切换要主密码)",
639
- "/vault settings [键 值] 查看/修改设置(vault.unlock、bitwarden.*、ente.* …)",
640
- "/vault ente-key 保存 ente 的 ENTE_CLI_VAULT_KEY(免钥匙串/免登录)",
641
- "/vault status 状态与授权剩余时间",
642
- "/vault list 本地条目元数据",
643
- "/vault add [名称] 新增本地条目(用户名、密码在弹窗里输入)",
644
- '/vault remove <名称> 删除本地条目(带空格的名称加引号:"GitHub (2)")',
645
- "/vault grant <名称> [分钟] 手动授权读取(默认 5 分钟,上限 60)",
646
- "/vault revoke <名称|all> 撤销授权",
647
- "/vault audit [n] 最近 n 条审计(默认 30)",
648
- "/vault import <bitwarden.json> 从 Bitwarden 未加密 JSON 导出导入",
649
- "/vault import-bw [搜索词] 直接从 bw CLI 导入登录项(先弹窗确认)",
650
- "/bw status|unlock|lock|clear 在线 Bitwarden 会话(见 bw_* 工具)",
637
+ tr("/vault init create the machine-wide encrypted store (a dialog sets the master password)", "/vault init 创建全机共享的本地加密库(弹出窗口设置主密码)"),
638
+ tr("/vault unlock | lock unlock / lock (clears this session's grants)", "/vault unlock | lock 解锁 / 锁定(清空本会话的授权)"),
639
+ tr("/vault mode [never|time|session] show/switch the unlock policy (switching needs the master password)", "/vault mode [never|time|session] 查看/切换解锁模式(切换要主密码)"),
640
+ tr("/vault settings [key value] show/change settings (vault.unlock, bitwarden.*, ente.* …)", "/vault settings [键 值] 查看/修改设置(vault.unlock、bitwarden.*、ente.* …)"),
641
+ tr("/vault ente-key save Ente's ENTE_CLI_VAULT_KEY (no keychain, no login)", "/vault ente-key 保存 ente 的 ENTE_CLI_VAULT_KEY(免钥匙串/免登录)"),
642
+ tr("/vault status state and grants left", "/vault status 状态与授权剩余时间"),
643
+ tr("/vault list local entry metadata", "/vault list 本地条目元数据"),
644
+ tr("/vault add [name] add a local entry (username and password typed in a dialog)", "/vault add [名称] 新增本地条目(用户名、密码在弹窗里输入)"),
645
+ tr('/vault remove <name> delete an entry (quote names with spaces: "GitHub (2)")', '/vault remove <名称> 删除本地条目(带空格的名称加引号:"GitHub (2)")'),
646
+ tr("/vault grant <name> [minutes] a standing read grant (default 5 min, max 60)", "/vault grant <名称> [分钟] 手动授权读取(默认 5 分钟,上限 60)"),
647
+ tr("/vault revoke <name|all> revoke grants", "/vault revoke <名称|all> 撤销授权"),
648
+ tr("/vault audit [n] the last n audit lines (default 30)", "/vault audit [n] 最近 n 条审计(默认 30)"),
649
+ tr("/vault import <bitwarden.json> import an unencrypted Bitwarden JSON export", "/vault import <bitwarden.json> 从 Bitwarden 未加密 JSON 导出导入"),
650
+ tr("/vault import-bw [search] import logins straight from the bw CLI (asks first)", "/vault import-bw [搜索词] 直接从 bw CLI 导入登录项(先弹窗确认)"),
651
+ tr("/bw status|unlock|lock|clear the live Bitwarden session (see the bw_* tools)", "/bw status|unlock|lock|clear 在线 Bitwarden 会话(见 bw_* 工具)"),
651
652
  ].join("\n");
652
653
 
653
654
  /** Split a command line into words; quotes keep a name such as "GitHub (2)" intact. */
@@ -666,7 +667,7 @@ async function initStore(scope: Scope, ctx: Ctx, label: string): Promise<void> {
666
667
  scope.token = result.token;
667
668
  scope.items = 0;
668
669
  setStatus(ctx, scope);
669
- note(ctx, `ai-vault 已创建: ${cli.dir}/store.json`);
670
+ note(ctx, tr(`ai-vault created: ${cli.dir}/store.json`, `ai-vault 已创建: ${cli.dir}/store.json`));
670
671
  };
671
672
  try {
672
673
  finish(await cli.open<UnlockResult>("init", ["--requester", label]));
@@ -681,14 +682,14 @@ async function initStore(scope: Scope, ctx: Ctx, label: string): Promise<void> {
681
682
  return;
682
683
  }
683
684
  }
684
- const pass = await promptSecret(dialogs(ctx), "ai-vault · 创建主密码", "至少 8 位");
685
+ const pass = await promptSecret(dialogs(ctx), tr("ai-vault · set master password", "ai-vault · 创建主密码"), tr("at least 8 characters", "至少 8 位"));
685
686
  if (!pass || pass.length < 8) {
686
- note(ctx, "已取消,或密码短于 8 位", "warning");
687
+ note(ctx, tr("cancelled, or the password is shorter than 8 characters", "已取消,或密码短于 8 位"), "warning");
687
688
  return;
688
689
  }
689
- const again = await promptSecret(dialogs(ctx), "ai-vault · 确认主密码", "再输入一次");
690
+ const again = await promptSecret(dialogs(ctx), tr("ai-vault · confirm master password", "ai-vault · 确认主密码"), tr("type it again", "再输入一次"));
690
691
  if (again !== pass) {
691
- note(ctx, "两次主密码不一致,已取消", "warning");
692
+ note(ctx, tr("the two passwords do not match; cancelled", "两次主密码不一致,已取消"), "warning");
692
693
  return;
693
694
  }
694
695
  try {
@@ -701,20 +702,20 @@ async function initStore(scope: Scope, ctx: Ctx, label: string): Promise<void> {
701
702
  function settingsText(s: Settings): string {
702
703
  const persisted = s.bitwarden.persisted
703
704
  ? s.bitwarden.expiresAt
704
- ? `有(${Math.max(0, Math.round((s.bitwarden.expiresAt - Date.now()) / 60_000))} 分钟后过期)`
705
- : "有(不过期)"
706
- : "无";
705
+ ? tr(`yes(${Math.max(0, Math.round((s.bitwarden.expiresAt - Date.now()) / 60_000))} 分钟后过期)`, `有(${Math.max(0, Math.round((s.bitwarden.expiresAt - Date.now()) / 60_000))} 分钟后过期)`)
706
+ : tr("yes (no expiry)", "有(不过期)")
707
+ : tr("no", "无");
707
708
  return [
708
709
  `vault.unlock: ${s.vault.unlock} (never | time | session)`,
709
- `vault.hours: ${s.vault.hours} (time 模式用)`,
710
- `vault 机器级会话: ${s.vault.auto ? "有(免密)" : "无"}`,
710
+ tr(`vault.hours: ${s.vault.hours} (time mode)`, `vault.hours: ${s.vault.hours} (time 模式用)`),
711
+ tr(`vault machine-wide session: ${s.vault.auto ? "yes (no password)" : "no"}`, `vault 机器级会话: ${s.vault.auto ? "有(免密)" : "无"}`),
711
712
  `bitwarden.unlock: ${s.bitwarden.unlock} (never | time | session)`,
712
713
  `bitwarden.hours: ${s.bitwarden.hours}`,
713
714
  `bitwarden.import: ${s.bitwarden.import} (ask | always | never)`,
714
- `bitwarden 已落盘的会话: ${persisted}`,
715
+ tr(`bitwarden persisted session: ${persisted}`, `bitwarden 已落盘的会话: ${persisted}`),
715
716
  `ente.unlock: ${s.ente.unlock} (never | time | session)`,
716
717
  `ente.hours: ${s.ente.hours}`,
717
- `ente 已落盘的密钥: ${s.ente.persisted ? "有" : "无"}`,
718
+ tr(`ente persisted key: ${s.ente.persisted ? "yes" : "no"}`, `ente 已落盘的密钥: ${s.ente.persisted ? "有" : "无"}`),
718
719
  ].join("\n");
719
720
  }
720
721
 
@@ -739,7 +740,7 @@ function commandHandler(scope: Scope, bw: BwState) {
739
740
  case "lock": {
740
741
  await lockNow(scope);
741
742
  setStatus(ctx, scope);
742
- note(ctx, "本地库已锁定,授权已清空");
743
+ note(ctx, tr("the local store is locked; grants cleared", "本地库已锁定,授权已清空"));
743
744
  return;
744
745
  }
745
746
  case "status": {
@@ -754,10 +755,10 @@ function commandHandler(scope: Scope, bw: BwState) {
754
755
  : "never";
755
756
  const how =
756
757
  status.mode === "never"
757
- ? "never(免密)"
758
+ ? tr("never (no password)", "never(免密)")
758
759
  : status.mode === "time"
759
- ? `time(每 ${status.hours}h 要一次密码)`
760
- : "session(每个会话一次)";
760
+ ? tr(`time (the password every ${status.hours}h)`, `time(每 ${status.hours}h 要一次密码)`)
761
+ : tr("session (once per session)", "session(每个会话一次)");
761
762
  const lines = [
762
763
  `store: ${cli.dir}/store.json`,
763
764
  `session: ${status.requester}`,
@@ -789,16 +790,16 @@ function commandHandler(scope: Scope, bw: BwState) {
789
790
  case "ente-key": {
790
791
  // Ente's unattended key: generated by `ente vault key generate`.
791
792
  // Saved sealed, so `ente.unlock = never | time` can use it.
792
- const key = await promptSecret(dialogs(ctx), "ai-vault · Ente 密钥", "ente vault key generate 输出的密钥");
793
+ const key = await promptSecret(dialogs(ctx), tr("ai-vault · Ente key", "ai-vault · Ente 密钥"), tr("the key printed by ente vault key generate", "ente vault key generate 输出的密钥"));
793
794
  if (!key) {
794
- note(ctx, "已取消", "warning");
795
+ note(ctx, tr("cancelled", "已取消"), "warning");
795
796
  return;
796
797
  }
797
798
  try {
798
799
  const args = ["ente-session", "put"];
799
800
  await cli.run(args, { stdin: key });
800
801
  forgetSettings();
801
- note(ctx, "已保存(封存)。现在可以设置 /vault settings ente.unlock never");
802
+ note(ctx, tr("saved (sealed). You can now set /vault settings ente.unlock never", "已保存(封存)。现在可以设置 /vault settings ente.unlock never"));
802
803
  } catch (error) {
803
804
  note(ctx, `ai-vault: ${describe(error)}`, "error");
804
805
  }
@@ -820,14 +821,14 @@ function commandHandler(scope: Scope, bw: BwState) {
820
821
  // `vault.unlock` opens its own password window (or answers
821
822
  // needs-ui); the other keys do not prompt at all.
822
823
  const run = await cli.withPassword(["settings", key, value], () =>
823
- promptSecret(dialogs(ctx), "ai-vault · 主密码", "改变解锁模式需要验证"),
824
+ promptSecret(dialogs(ctx), tr("ai-vault · master password", "ai-vault · 主密码"), tr("changing the unlock policy needs verification", "改变解锁模式需要验证")),
824
825
  );
825
826
  forgetSettings();
826
827
  const updated = JSON.parse(run.stdout) as Settings;
827
828
  if (key.startsWith("vault.")) await lockNow(scope);
828
829
  note(ctx, settingsText(updated));
829
830
  } catch (error) {
830
- note(ctx, `ai-vault: ${error instanceof CliError && error.denied ? "已取消" : describe(error)}`, "warning");
831
+ note(ctx, `ai-vault: ${error instanceof CliError && error.denied ? tr("cancelled", "已取消") : describe(error)}`, "warning");
831
832
  }
832
833
  return;
833
834
  }
@@ -840,10 +841,10 @@ function commandHandler(scope: Scope, bw: BwState) {
840
841
  ctx,
841
842
  [
842
843
  `mode: ${current.mode}`,
843
- `hours: ${current.hours}(time 模式用)`,
844
- `machine-wide session: ${current.auto ? "yes(免密)" : "no"}`,
844
+ tr(`hours: ${current.hours}(time mode)`, `hours: ${current.hours}(time 模式用)`),
845
+ `machine-wide session: ${current.auto ? tr("yes (no password)", "yes(免密)") : "no"}`,
845
846
  "",
846
- "/vault mode never|time|session [小时] 切换(要主密码)",
847
+ tr("/vault mode never|time|session [hours] switch (needs the master password)", "/vault mode never|time|session [小时] 切换(要主密码)"),
847
848
  ].join("\n"),
848
849
  );
849
850
  } catch (error) {
@@ -852,13 +853,13 @@ function commandHandler(scope: Scope, bw: BwState) {
852
853
  return;
853
854
  }
854
855
  if (!["never", "time", "session", "no-password"].includes(sub)) {
855
- note(ctx, "用法: /vault mode [never|time|session] [小时]", "warning");
856
+ note(ctx, tr("usage: /vault mode [never|time|session] [hours]", "用法: /vault mode [never|time|session] [小时]"), "warning");
856
857
  return;
857
858
  }
858
859
  const args = ["mode", "set", sub];
859
860
  if (hoursArg) args.push("--hours", hoursArg);
860
861
  try {
861
- const run = await cli.withPassword(args, () => promptSecret(dialogs(ctx), "ai-vault · 主密码", "切换解锁模式"));
862
+ const run = await cli.withPassword(args, () => promptSecret(dialogs(ctx), tr("ai-vault · master password", "ai-vault · 主密码"), tr("switch the unlock policy", "切换解锁模式")));
862
863
  const result = JSON.parse(run.stdout) as { mode: UnlockModeName; hours: number; auto: boolean };
863
864
  forgetSettings();
864
865
  await lockNow(scope);
@@ -867,13 +868,13 @@ function commandHandler(scope: Scope, bw: BwState) {
867
868
  setStatus(ctx, scope);
868
869
  const how =
869
870
  result.mode === "never"
870
- ? "以后免密(密钥已写盘,任何能读你文件的程序都能读到库里的密码)"
871
+ ? tr("no password from now on (the key is on disk: anything that can read your files can read every password in the store)", "以后免密(密钥已写盘,任何能读你文件的程序都能读到库里的密码)")
871
872
  : result.mode === "time"
872
- ? `以后每 ${result.hours} 小时要一次密码`
873
- : "以后每个会话要一次密码";
873
+ ? tr(`the password is asked again every ${result.hours} hours from now on`, `以后每 ${result.hours} 小时要一次密码`)
874
+ : tr("the password is asked once per session from now on", "以后每个会话要一次密码");
874
875
  note(ctx, `mode → ${result.mode},${how}`);
875
876
  } catch (error) {
876
- note(ctx, `ai-vault: ${error instanceof CliError && error.denied ? "已取消" : describe(error)}`, "warning");
877
+ note(ctx, `ai-vault: ${error instanceof CliError && error.denied ? tr("cancelled", "已取消") : describe(error)}`, "warning");
877
878
  }
878
879
  return;
879
880
  }
@@ -898,7 +899,7 @@ function commandHandler(scope: Scope, bw: BwState) {
898
899
  const name = rest.join(" ");
899
900
  if (!(await ensureUnlocked(scope, ctx))) return;
900
901
  if (!name) {
901
- note(ctx, "用法: /vault remove <名称>", "warning");
902
+ note(ctx, tr("usage: /vault remove <name>", "用法: /vault remove <名称>"), "warning");
902
903
  return;
903
904
  }
904
905
  const args = ["remove", name, "--token", scope.token!];
@@ -912,7 +913,7 @@ function commandHandler(scope: Scope, bw: BwState) {
912
913
  note(ctx, `ai-vault: ${describe(error)}`, error instanceof CliError && error.denied ? "warning" : "error");
913
914
  return;
914
915
  }
915
- const sure = await confirmWindow(dialogs(ctx), "ai-vault · 删除条目", `删除「${forDialog(name)}」?删除后无法恢复。`);
916
+ const sure = await confirmWindow(dialogs(ctx), tr("ai-vault · delete entry", "ai-vault · 删除条目"), tr(`Delete "${forDialog(name)}"? This cannot be undone.`, `删除「${forDialog(name)}」?删除后无法恢复。`));
916
917
  if (!sure) return;
917
918
  try {
918
919
  const result = await cli.json<RemovingResult>([...args, "--yes"]);
@@ -932,7 +933,7 @@ function commandHandler(scope: Scope, bw: BwState) {
932
933
  const minutes = rest.length > 1 && /^\d+$/.test(last) ? rest.pop() : undefined;
933
934
  const name = rest.join(" ");
934
935
  if (!(await ensureUnlocked(scope, ctx)) || !name) {
935
- note(ctx, "先解锁;用法: /vault grant <名称> [分钟](带空格的名称加引号)", "warning");
936
+ note(ctx, tr("unlock first; usage: /vault grant <name> [minutes] (quote names with spaces)", "先解锁;用法: /vault grant <名称> [分钟](带空格的名称加引号)"), "warning");
936
937
  return;
937
938
  }
938
939
  const args = ["grant", name, "--token", scope.token!];
@@ -940,7 +941,7 @@ function commandHandler(scope: Scope, bw: BwState) {
940
941
  try {
941
942
  // A standing grant costs the master password, like a mode change.
942
943
  const run = await cli.withPassword(args, () =>
943
- promptSecret(dialogs(ctx), "ai-vault · 授权读取", "主密码(给这条条目 N 分钟免确认)"),
944
+ promptSecret(dialogs(ctx), tr("ai-vault · grant read", "ai-vault · 授权读取"), tr("master password (lets this entry be read without confirmation for N minutes)", "主密码(给这条条目 N 分钟免确认)")),
944
945
  );
945
946
  const result = JSON.parse(run.stdout) as { name: string; minutes: number };
946
947
  setStatus(ctx, scope, "·granted");
@@ -957,7 +958,7 @@ function commandHandler(scope: Scope, bw: BwState) {
957
958
  if (target === "all") args.push("--all");
958
959
  else if (target) args.push(target);
959
960
  else {
960
- note(ctx, "用法: /vault revoke <名称|all>", "warning");
961
+ note(ctx, tr("usage: /vault revoke <name|all>", "用法: /vault revoke <名称|all>"), "warning");
961
962
  return;
962
963
  }
963
964
  try {
@@ -986,7 +987,7 @@ function commandHandler(scope: Scope, bw: BwState) {
986
987
  case "import": {
987
988
  const path = rest.join(" ");
988
989
  if (!path) {
989
- note(ctx, "用法: /vault import <bitwarden-export.json>", "warning");
990
+ note(ctx, tr("usage: /vault import <bitwarden-export.json>", "用法: /vault import <bitwarden-export.json>"), "warning");
990
991
  return;
991
992
  }
992
993
  if (!(await ensureUnlocked(scope, ctx))) return;
@@ -1003,8 +1004,8 @@ function commandHandler(scope: Scope, bw: BwState) {
1003
1004
  }
1004
1005
  const sure = await confirmWindow(
1005
1006
  dialogs(ctx),
1006
- "ai-vault · 从 Bitwarden 导入",
1007
- `导入 ${path} 里的 Bitwarden 登录项?同名条目会被更新。`,
1007
+ tr("ai-vault · import from Bitwarden", "ai-vault · 从 Bitwarden 导入"),
1008
+ tr(`Import ${path} Bitwarden logins? Same-name entries are updated.`, `导入 ${path} 里的 Bitwarden 登录项?同名条目会被更新。`),
1008
1009
  );
1009
1010
  if (!sure) return;
1010
1011
  try {
@@ -1043,7 +1044,7 @@ export default function aiVault(pi: ExtensionAPI): void {
1043
1044
  // Ente Auth: the `ente` CLI keeps its own login; these tools only read codes.
1044
1045
  registerEnte(pi);
1045
1046
  pi.registerCommand("vault", {
1046
- description: "本地密码库 + Bitwarden 导入(/vault help)",
1047
+ description: tr("local secret store + Bitwarden import (/vault help)", "本地密码库 + Bitwarden 导入(/vault help)"),
1047
1048
  handler: commandHandler(scope, bw),
1048
1049
  });
1049
1050
  // A transcript that starts fresh (/new, /fork) must not inherit this unlock
@@ -8,6 +8,7 @@
8
8
  * instead. Upstream pi shows typed text in the clear; OMP masks it.
9
9
  */
10
10
  import { spawn, spawnSync } from "node:child_process";
11
+ import { tr } from "./i18n.js";
11
12
  import { existsSync } from "node:fs";
12
13
  import { join } from "node:path";
13
14
 
@@ -190,8 +191,8 @@ export async function confirmWindow(
190
191
  "--no-markup",
191
192
  "--width=520",
192
193
  "--default-cancel",
193
- "--ok-label=允许",
194
- "--cancel-label=拒绝",
194
+ `--ok-label=${tr("Allow", "允许")}`,
195
+ `--cancel-label=${tr("Deny", "拒绝")}`,
195
196
  `--timeout=${DIALOG_MS / 1000}`,
196
197
  ],
197
198
  signal,
@@ -1,7 +1,8 @@
1
1
  #!/bin/bash
2
2
  # Mock zenity for the ai-vault tests. Every call is one line in
3
3
  # $OMP_VAULT_MOCK/zenity.log (newlines inside an argument show as ⏎).
4
- # --password a master-password dialog (its title says 主密码) answers with
4
+ # --password a master-password dialog (its title says 主密码 or "master
5
+ # password"/"unlock"/"set master password") answers with
5
6
  # the first line of $OMP_VAULT_MOCK/passwords, or "testmaster"
6
7
  # when that file is missing or empty; any other password dialog
7
8
  # answers with the first line of $OMP_VAULT_MOCK/entry-passwords
@@ -24,7 +25,11 @@ for arg in "$@"; do
24
25
  case "$arg" in
25
26
  --password)
26
27
  kind="entry"
27
- for a in "$@"; do [[ "$a" == --title=*主密码* || "$a" == --title=*解锁* || "$a" == --title=*创建* ]] && kind="master"; done
28
+ for a in "$@"; do
29
+ case "$a" in
30
+ --title=*主密码*|--title=*解锁*|--title=*创建*|--title=*master\ password*|--title=*unlock*) kind="master" ;;
31
+ esac
32
+ done
28
33
  if [[ "$kind" == "master" ]]; then
29
34
  if [[ -s "$DIR/passwords" ]]; then take_first "$DIR/passwords"; else echo "testmaster"; fi
30
35
  elif [[ -f "$DIR/entry-passwords" ]]; then