@celljs/ta-secrets 4.29.0 → 4.31.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.en.md CHANGED
@@ -10,6 +10,7 @@ A pi package that comes with Ta (on by default, off in Settings → Extensions):
10
10
  - **Used**: a bash command writes `"$TA_SECRET_GITHUB_TOKEN"`, and only that command gets the value, sourced from a file only you read, removed as it starts; the conversation keeps the command as written.
11
11
  - **Only to its hosts**: a secret bound to hosts (tokens of GitHub, GitLab and Gitee are by default) is a placeholder in the command, whose HTTPS goes through Ta's proxy on this computer, which puts the value in (headers and URL) for those hosts alone; commands running git get tokens so too. Needs `openssl`.
12
12
  - **SSH**: private keys are held by an ssh-agent of each command that may connect (ssh, scp, rsync, git), never a variable, ended with it.
13
+ - **Only in one directory**: once a directory is marked work or private (Directory marks), each can be used "only in Client A": in conversations of other directories Ta is not told its name, and a command naming it is refused; a key captured or asked for in that directory's conversations is kept to it from the start. With the mark gone (or Directory marks off) it is given to no one, not to all. Before a conversation of work or private sends what it holds to a group chat, someone else's Ta or people nearby, Ta asks you once.
13
14
  - **Lately used**: which secrets each command was given, how, the command and the conversation, in Settings → Vault.
14
15
  - **Wiped**: values in tool results and in what goes to the model (as written, base64, URL-encoded) become their names.
15
16
  - **With your account**: while devices sync, each goes to your other devices sealed end to end (the class Vault), but those whose "Sync to my devices" you turn off. Other packages keep sign-ins in it too (`TaExtensionHost.credentials`), as the tokens of WeChat and WeCom bots (kept to this device). Opened from Me → Vault.
package/README.md CHANGED
@@ -10,6 +10,7 @@ Ta 自带的 pi 包(默认开启,可在 设置 → 扩展 关闭):保险
10
10
  - **用**:bash 命令里写 `"$TA_SECRET_GITHUB_TOKEN"`,Ta 只给这一条命令值(从只有你能读、随即删除的临时文件里读入);会话里存的是原命令。
11
11
  - **只发往绑定的主机**:给密钥绑定主机后(GitHub、GitLab、Gitee 的 token 默认绑定),命令里拿到的只是占位,它的 HTTPS 经 Ta 本机的代理出去,代理只对这些主机把占位换成真值(请求头和 URL);运行 git 的命令也这样自动拿到 token。需要本机有 `openssl`。
12
12
  - **SSH**:私钥由每条可能连 SSH 的命令(ssh、scp、rsync、git)自己的 ssh-agent 持有,不进环境变量,命令结束 agent 就关掉。
13
+ - **只在某个目录用**:目录标成公司或私密后(目录标记),每条可以选"只在「客户 A」":别的目录的对话里 Ta 看不到这个名字,命令里写了也拒绝;在那个目录的对话里收起或要来的密钥默认就只在那儿用。标记被取消(或关掉目录标记)时这条谁都不给,而不是谁都给。公司或私密目录里的对话要把内容发到群聊、交给别人的 Ta、给附近的人看时,先问你一次。
13
14
  - **最近使用**:每次给出密钥都记下哪些、怎么给的、命令和对话,设置 → 保险箱 里能看到。
14
15
  - **Ta 自己用的登录**:远程桌面的账号密码由 Ta 服务经 `TaExtensionHost.credentials` 存取(类型 `sign-in`),列在保险箱里可删;不告诉模型,命令里点名会被拒,页面也建不了这一类。
15
16
  - **擦**:工具结果和发给模型的内容里出现的值(原文、base64、URL 编码)都换成名字。
@@ -1,3 +1,106 @@
1
+ // ../ta-protocol/esm/common/boundary-protocol.js
2
+ var TA_BOUNDARY_KINDS = ["general", "work", "private", "guest"];
3
+ var TA_GENERAL_BOUNDARY = Object.freeze({ kind: "general" });
4
+ var words = (en, zh, tw, ja) => ({
5
+ "en-US": en,
6
+ "zh-CN": zh,
7
+ "zh-TW": tw,
8
+ "ja-JP": ja
9
+ });
10
+ var TA_OUTBOUND_TOOLS = {
11
+ say_in_group: { what: words("send it to a group chat", "发到群聊", "發到群聊", "グループチャットに送る") },
12
+ hand_task: { what: words("hand it to someone else's Ta", "交给别人的 Ta", "交給別人的 Ta", "他の人の Ta に渡す") },
13
+ nearby_show: { what: words("show it to people nearby", "给附近的人看", "給附近的人看", "近くの人に見せる") },
14
+ draft_moment: { what: words("post it to your Moments", "发到动态", "發到動態", "モーメントに投稿"), asks: true },
15
+ share_link: { what: words("share it by a link", "生成分享链接", "產生分享連結", "リンクで共有"), asks: true },
16
+ public_link: { what: words("put it on the internet", "公开到网上", "公開到網上", "インターネットに公開"), asks: true },
17
+ nearby_greet: { what: words("send it to someone nearby", "发给附近的人", "發給附近的人", "近くの人に送る"), asks: true },
18
+ nearby_group: { what: words("start a group chat with people nearby", "和附近的人建群", "和附近的人建群", "近くの人とグループを作る"), asks: true },
19
+ feedback_draft: { what: words("send it to the makers of Ta", "发给 Ta 的开发者", "發給 Ta 的開發者", "Ta の開発者に送る"), asks: true }
20
+ };
21
+ var TaBoundaryUtil;
22
+ (function(TaBoundaryUtil2) {
23
+ async function list(host) {
24
+ var _a, _b;
25
+ var _c;
26
+ try {
27
+ return ((_c = await ((_b = (_a = host.boundaries) === null || _a === undefined ? undefined : _a.list) === null || _b === undefined ? undefined : _b.call(_a))) !== null && _c !== undefined ? _c : []).map(valid).filter((one) => one.kind !== "general");
28
+ } catch (_d) {
29
+ return [];
30
+ }
31
+ }
32
+ TaBoundaryUtil2.list = list;
33
+ function label(boundary) {
34
+ var _a;
35
+ return boundary.name || ((_a = boundary.root) === null || _a === undefined ? undefined : _a.replace(/[\\/]+$/, "").split(/[\\/]/).pop()) || boundary.kind;
36
+ }
37
+ TaBoundaryUtil2.label = label;
38
+ async function of(host, location) {
39
+ if (!host.boundaries || !location) {
40
+ return TA_GENERAL_BOUNDARY;
41
+ }
42
+ try {
43
+ return await host.boundaries.of(location);
44
+ } catch (_a) {
45
+ return TA_GENERAL_BOUNDARY;
46
+ }
47
+ }
48
+ TaBoundaryUtil2.of = of;
49
+ async function ofAll(host, locations) {
50
+ const found = new Map;
51
+ for (const location of new Set(locations)) {
52
+ found.set(location, await of(host, location));
53
+ }
54
+ return found;
55
+ }
56
+ TaBoundaryUtil2.ofAll = ofAll;
57
+ function key(boundary) {
58
+ var _a;
59
+ return boundary.kind === "general" ? "general" : `${boundary.kind}:${(_a = boundary.root) !== null && _a !== undefined ? _a : ""}`;
60
+ }
61
+ TaBoundaryUtil2.key = key;
62
+ function canSee(from, of2) {
63
+ if (from.kind === "guest" || of2.kind === "guest") {
64
+ return false;
65
+ }
66
+ if (of2.kind === "general") {
67
+ return from.kind !== "private";
68
+ }
69
+ return key(from) === key(of2);
70
+ }
71
+ TaBoundaryUtil2.canSee = canSee;
72
+ function profile(boundary, general, notes) {
73
+ const own = (notes === null || notes === undefined ? undefined : notes.trim()) || undefined;
74
+ const all = (general === null || general === undefined ? undefined : general.trim()) || undefined;
75
+ switch (boundary.kind) {
76
+ case "general":
77
+ return all ? { general: all } : {};
78
+ case "work":
79
+ return { ...all ? { general: all } : {}, ...own ? { notes: own } : {} };
80
+ case "private":
81
+ return own ? { notes: own } : {};
82
+ default:
83
+ return {};
84
+ }
85
+ }
86
+ TaBoundaryUtil2.profile = profile;
87
+ function valid(value) {
88
+ const boundary = value;
89
+ if (!boundary || typeof boundary !== "object" || !TA_BOUNDARY_KINDS.includes(boundary.kind)) {
90
+ return TA_GENERAL_BOUNDARY;
91
+ }
92
+ if (boundary.kind === "general") {
93
+ return TA_GENERAL_BOUNDARY;
94
+ }
95
+ return {
96
+ kind: boundary.kind,
97
+ ...typeof boundary.root === "string" && boundary.root ? { root: boundary.root } : {},
98
+ ...typeof boundary.name === "string" && boundary.name.trim() ? { name: boundary.name.trim() } : {}
99
+ };
100
+ }
101
+ TaBoundaryUtil2.valid = valid;
102
+ })(TaBoundaryUtil || (TaBoundaryUtil = {}));
103
+
1
104
  // ../ta-protocol/esm/common/ta-extension-host.js
2
105
  var TA_WEBHOOK_MAX_BYTES = 256 * 1024;
3
106
  var TA_HOST_EVENT = "ta:host";
@@ -267,12 +370,12 @@ var TaLanguageUtil;
267
370
  return of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG);
268
371
  }
269
372
  TaLanguageUtil2.server = server;
270
- function pick(language, words) {
271
- return words[of(language)];
373
+ function pick(language, words2) {
374
+ return words2[of(language)];
272
375
  }
273
376
  TaLanguageUtil2.pick = pick;
274
- function say(words) {
275
- return words[server()];
377
+ function say(words2) {
378
+ return words2[server()];
276
379
  }
277
380
  TaLanguageUtil2.say = say;
278
381
  function chinese(language) {
@@ -614,17 +717,42 @@ var SecretsServerTexts;
614
717
  return TaLanguageUtil.of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG || "");
615
718
  }
616
719
  SecretsServerTexts.language = language;
617
- function captured(names) {
618
- const words = TaLanguageUtil.say(KINDS);
619
- const list = TaLanguageUtil.list(language(), [...new Set(names.map((name) => words[TaSecretRef.kind(name)]))]);
620
- return TaLanguageUtil.say({
720
+ function captured(names, kept) {
721
+ const words2 = TaLanguageUtil.say(KINDS);
722
+ const list = TaLanguageUtil.list(language(), [...new Set(names.map((name) => words2[TaSecretRef.kind(name)]))]);
723
+ const said = TaLanguageUtil.say({
621
724
  "zh-CN": `已把你发的${list}收进保险箱:Ta 看不到内容,用到时才填入`,
622
725
  "zh-TW": `已把你發的${list}收進保險箱:Ta 看不到內容,用到時才填入`,
623
726
  "en-US": `Kept the ${list} you sent in the vault: Ta never sees it, and fills it in where it is used`,
624
727
  "ja-JP": `送信された${list}を金庫に保管しました。Ta には中身が見えず、使う時に入力されます`
625
728
  });
729
+ return kept ? said + TaLanguageUtil.say({
730
+ "zh-CN": `,只在「${kept}」的对话里用`,
731
+ "zh-TW": `,只在「${kept}」的對話裡用`,
732
+ "en-US": `, in the conversations of ${kept} only`,
733
+ "ja-JP": `(「${kept}」の会話でのみ使用)`
734
+ }) : said;
626
735
  }
627
736
  SecretsServerTexts.captured = captured;
737
+ function outbound(what, boundary) {
738
+ const name = TaBoundaryUtil.label(boundary);
739
+ const work = boundary.kind === "work";
740
+ return [
741
+ TaLanguageUtil.say({
742
+ "zh-CN": `要${what}吗?`,
743
+ "zh-TW": `要${what}嗎?`,
744
+ "en-US": `${what.charAt(0).toUpperCase()}${what.slice(1)}?`,
745
+ "ja-JP": `${what}しますか?`
746
+ }),
747
+ TaLanguageUtil.say({
748
+ "zh-CN": `这个对话在${work ? "公司" : "私密"}目录「${name}」里,内容会离开这个目录。`,
749
+ "zh-TW": `這個對話在${work ? "公司" : "私密"}目錄「${name}」裡,內容會離開這個目錄。`,
750
+ "en-US": `This conversation is in ${name}, a directory marked ${work ? "work" : "private"}: what it holds leaves it.`,
751
+ "ja-JP": `この会話は${work ? "仕事用" : "プライベート"}のフォルダー「${name}」にあり、内容がそこから出ていきます。`
752
+ })
753
+ ];
754
+ }
755
+ SecretsServerTexts.outbound = outbound;
628
756
  function ask(name, purpose, hosts = []) {
629
757
  const host = TaLanguageUtil.list(language(), hosts);
630
758
  return hosts.length ? TaLanguageUtil.say({
@@ -660,18 +788,90 @@ var SecretsServerTexts;
660
788
  SecretsServerTexts.askPlaceholder = askPlaceholder;
661
789
  })(SecretsServerTexts ||= {});
662
790
 
791
+ // web-src/vault-boundaries.ts
792
+ var VaultBoundaries;
793
+ ((VaultBoundaries) => {
794
+ VaultBoundaries.GUEST_PROMPT = "This conversation is with a guest of the Ta, not its user: no secret of the user is here. Never ask for one, nor for any of the guest's.";
795
+ async function choices(host, entries) {
796
+ return { choices: await TaBoundaryUtil.list(host), idle: await idle(host, entries) };
797
+ }
798
+ VaultBoundaries.choices = choices;
799
+ function of(value) {
800
+ const boundary = TaBoundaryUtil.valid(value);
801
+ return (boundary.kind === "work" || boundary.kind === "private") && boundary.root ? boundary : undefined;
802
+ }
803
+ VaultBoundaries.of = of;
804
+ async function here(host, cwd) {
805
+ return TaBoundaryUtil.key(await TaBoundaryUtil.of(host, cwd));
806
+ }
807
+ VaultBoundaries.here = here;
808
+ function inside(entry, here2) {
809
+ return !guest(here2) && (!entry.boundary || TaBoundaryUtil.key(entry.boundary) === here2);
810
+ }
811
+ VaultBoundaries.inside = inside;
812
+ function guest(here2) {
813
+ return here2.startsWith("guest:");
814
+ }
815
+ VaultBoundaries.guest = guest;
816
+ async function idle(host, entries) {
817
+ const bound = entries.filter((entry) => entry.boundary);
818
+ const now = await TaBoundaryUtil.ofAll(host, bound.map((entry) => entry.boundary?.root));
819
+ return bound.filter((entry) => TaBoundaryUtil.key(now.get(entry.boundary?.root) ?? { kind: "general" }) !== TaBoundaryUtil.key(entry.boundary)).map((entry) => entry.name);
820
+ }
821
+ VaultBoundaries.idle = idle;
822
+ function outbound(tool, language) {
823
+ const found = Object.keys(TA_OUTBOUND_TOOLS).includes(tool) ? TA_OUTBOUND_TOOLS[tool] : undefined;
824
+ return found && !found.asks ? found.what[language] : undefined;
825
+ }
826
+ VaultBoundaries.outbound = outbound;
827
+ function sends(tool) {
828
+ return Object.keys(TA_OUTBOUND_TOOLS).includes(tool);
829
+ }
830
+ VaultBoundaries.sends = sends;
831
+ function guarded(boundary) {
832
+ return boundary.kind === "work" || boundary.kind === "private";
833
+ }
834
+ VaultBoundaries.guarded = guarded;
835
+ })(VaultBoundaries ||= {});
836
+
663
837
  // web-src/extension.ts
838
+ async function guard(found, tool, location, ctx) {
839
+ if (found && VaultBoundaries.sends(tool) && (await TaBoundaryUtil.of(found.host, location)).kind === "guest") {
840
+ return { block: true, reason: "This conversation is with a guest of the Ta: nothing goes out of it from here. Say so kindly." };
841
+ }
842
+ const what = found && VaultBoundaries.outbound(tool, SecretsServerTexts.language());
843
+ const boundary = what ? await TaBoundaryUtil.of(found.host, location) : undefined;
844
+ if (!what || !boundary || !VaultBoundaries.guarded(boundary)) {
845
+ return;
846
+ }
847
+ if (!ctx.hasUI) {
848
+ return {
849
+ block: true,
850
+ reason: "This conversation is in a directory marked work or private: what it holds goes out of Ta only once the user agrees, and no one is here to ask. Tell the user."
851
+ };
852
+ }
853
+ const [title, message] = SecretsServerTexts.outbound(what, boundary);
854
+ if (await ctx.ui.confirm(title, message).catch(() => false)) {
855
+ return;
856
+ }
857
+ return { block: true, reason: "The user did not agree to send it out of the directory of this conversation. Do not send it another way." };
858
+ }
664
859
  var SHELLS = { bash: "command" };
665
860
  function activate(pi) {
666
861
  let reached;
667
862
  const vault = () => reached ??= TaHostUtil.reach(pi.events, NAME).then((found) => found?.service?.vault);
863
+ const where = (found, ctx) => found.locate(ctx.sessionManager?.getSessionFile?.(), ctx.cwd);
864
+ const outbound = async (tool, ctx) => {
865
+ const found = VaultBoundaries.sends(tool) ? await vault() : undefined;
866
+ return found ? guard(found, tool, await where(found, ctx), ctx) : undefined;
867
+ };
668
868
  pi.on("session_start", () => {
669
869
  vault();
670
870
  });
671
- pi.on("before_agent_start", async (event) => {
871
+ pi.on("before_agent_start", async (event, ctx) => {
672
872
  const found = await vault();
673
873
  if (found) {
674
- event.systemPromptOptions.sections = { ...event.systemPromptOptions.sections, [SECTION]: await found.prompt() };
874
+ event.systemPromptOptions.sections = { ...event.systemPromptOptions.sections, [SECTION]: await found.prompt(await where(found, ctx)) };
675
875
  }
676
876
  });
677
877
  pi.on("input", async (event, ctx) => {
@@ -679,17 +879,25 @@ function activate(pi) {
679
879
  if (!found || !event.text) {
680
880
  return { action: "continue" };
681
881
  }
682
- const { text, names } = await found.capture(event.text);
882
+ const location = await where(found, ctx);
883
+ const { text, names } = await found.capture(event.text, location);
683
884
  if (names.length) {
684
- ctx.ui.notify(SecretsServerTexts.captured(names), "info");
885
+ const kept = VaultBoundaries.of(await TaBoundaryUtil.of(found.host, location));
886
+ const bound = kept && (await found.list()).some((entry) => names.includes(entry.name) && entry.boundary);
887
+ ctx.ui.notify(SecretsServerTexts.captured(names, bound && kept ? TaBoundaryUtil.label(kept) : undefined), "info");
685
888
  }
686
889
  return text === event.text ? { action: "continue" } : { action: "transform", text, images: event.images };
687
890
  });
688
891
  pi.on("tool_call", async (event, ctx) => {
689
892
  const field = SHELLS[event.toolName];
690
893
  if (!field) {
894
+ const refused = await outbound(event.toolName, ctx);
895
+ if (refused) {
896
+ return refused;
897
+ }
691
898
  if (JSON.stringify(event.input ?? {}).includes("TA_SECRET_")) {
692
- await (await vault())?.fill(event.input, event.toolName, ctx.sessionManager?.getSessionName?.());
899
+ const found2 = await vault();
900
+ await found2?.fill(event.input, event.toolName, ctx.sessionManager?.getSessionName?.(), await where(found2, ctx));
693
901
  }
694
902
  return;
695
903
  }
@@ -698,7 +906,7 @@ function activate(pi) {
698
906
  return;
699
907
  }
700
908
  const found = await vault();
701
- const prepared = await found?.prepare(command, { cwd: ctx.cwd, conversation: ctx.sessionManager?.getSessionName?.() });
909
+ const prepared = found && await found.prepare(command, { cwd: ctx.cwd, location: await where(found, ctx), conversation: ctx.sessionManager?.getSessionName?.() });
702
910
  if (prepared?.block) {
703
911
  return { block: true, reason: prepared.block };
704
912
  }
@@ -760,6 +968,9 @@ function activate(pi) {
760
968
  if (!ctx.hasUI) {
761
969
  throw new Error("There is no one to ask here: the user adds secrets in Ta, Settings, Vault.");
762
970
  }
971
+ if ((await TaBoundaryUtil.of(found.host, await where(found, ctx))).kind === "guest") {
972
+ throw new Error("This conversation is with a guest of the Ta: the vault keeps nothing of theirs. Do without it.");
973
+ }
763
974
  const name = SecretNames.normalize(String(params.name ?? ""));
764
975
  if (!SecretNames.valid(name)) {
765
976
  throw new Error("Give a name of letters, digits and _, as GITHUB_TOKEN.");
@@ -785,7 +996,16 @@ function activate(pi) {
785
996
  details: { name }
786
997
  };
787
998
  }
788
- await found.add({ name, value: value.trim(), kind: params.kind === "personal" ? "personal" : "credential", note: purpose, source: "asked", hosts });
999
+ const kept = params.kind === "personal" ? undefined : VaultBoundaries.of(await TaBoundaryUtil.of(found.host, await where(found, ctx)));
1000
+ await found.add({
1001
+ name,
1002
+ value: value.trim(),
1003
+ kind: params.kind === "personal" ? "personal" : "credential",
1004
+ note: purpose,
1005
+ source: "asked",
1006
+ hosts,
1007
+ ...kept ? { boundary: kept } : {}
1008
+ });
789
1009
  const handle = SecretNames.handle(name);
790
1010
  const how = hosts.length ? ` It reaches only ${hosts.join(", ")}: use "${handle}" in a header or a query of a request to them (through Ta's proxy); git over https gets it there by itself.` : ` Use it in bash commands as "${handle}".`;
791
1011
  return { content: [{ type: "text", text: `Kept in the vault as ${handle}.${how}` }], details: { name } };
package/host/index.mjs CHANGED
@@ -279,6 +279,12 @@ class VaultService {
279
279
  setLocal(name, local) {
280
280
  return this.vault.setLocal(String(name ?? ""), local === true);
281
281
  }
282
+ setBoundary(name, boundary) {
283
+ return this.vault.setBoundary(String(name ?? ""), boundary ?? null);
284
+ }
285
+ async boundaries() {
286
+ return this.vault.boundaries();
287
+ }
282
288
  capturing() {
283
289
  return this.vault.capturing();
284
290
  }
@@ -605,6 +611,109 @@ import { mkdtemp as mkdtemp2, readFile as readFile3, rm as rm2, writeFile as wri
605
611
  import { homedir, tmpdir as tmpdir2 } from "node:os";
606
612
  import { join as join3, resolve, sep } from "node:path";
607
613
 
614
+ // ../ta-protocol/esm/common/boundary-protocol.js
615
+ var TA_BOUNDARY_KINDS = ["general", "work", "private", "guest"];
616
+ var TA_GENERAL_BOUNDARY = Object.freeze({ kind: "general" });
617
+ var words = (en, zh, tw, ja) => ({
618
+ "en-US": en,
619
+ "zh-CN": zh,
620
+ "zh-TW": tw,
621
+ "ja-JP": ja
622
+ });
623
+ var TA_OUTBOUND_TOOLS = {
624
+ say_in_group: { what: words("send it to a group chat", "发到群聊", "發到群聊", "グループチャットに送る") },
625
+ hand_task: { what: words("hand it to someone else's Ta", "交给别人的 Ta", "交給別人的 Ta", "他の人の Ta に渡す") },
626
+ nearby_show: { what: words("show it to people nearby", "给附近的人看", "給附近的人看", "近くの人に見せる") },
627
+ draft_moment: { what: words("post it to your Moments", "发到动态", "發到動態", "モーメントに投稿"), asks: true },
628
+ share_link: { what: words("share it by a link", "生成分享链接", "產生分享連結", "リンクで共有"), asks: true },
629
+ public_link: { what: words("put it on the internet", "公开到网上", "公開到網上", "インターネットに公開"), asks: true },
630
+ nearby_greet: { what: words("send it to someone nearby", "发给附近的人", "發給附近的人", "近くの人に送る"), asks: true },
631
+ nearby_group: { what: words("start a group chat with people nearby", "和附近的人建群", "和附近的人建群", "近くの人とグループを作る"), asks: true },
632
+ feedback_draft: { what: words("send it to the makers of Ta", "发给 Ta 的开发者", "發給 Ta 的開發者", "Ta の開発者に送る"), asks: true }
633
+ };
634
+ var TaBoundaryUtil;
635
+ (function(TaBoundaryUtil2) {
636
+ async function list(host) {
637
+ var _a, _b;
638
+ var _c;
639
+ try {
640
+ return ((_c = await ((_b = (_a = host.boundaries) === null || _a === undefined ? undefined : _a.list) === null || _b === undefined ? undefined : _b.call(_a))) !== null && _c !== undefined ? _c : []).map(valid).filter((one) => one.kind !== "general");
641
+ } catch (_d) {
642
+ return [];
643
+ }
644
+ }
645
+ TaBoundaryUtil2.list = list;
646
+ function label(boundary) {
647
+ var _a;
648
+ return boundary.name || ((_a = boundary.root) === null || _a === undefined ? undefined : _a.replace(/[\\/]+$/, "").split(/[\\/]/).pop()) || boundary.kind;
649
+ }
650
+ TaBoundaryUtil2.label = label;
651
+ async function of(host, location) {
652
+ if (!host.boundaries || !location) {
653
+ return TA_GENERAL_BOUNDARY;
654
+ }
655
+ try {
656
+ return await host.boundaries.of(location);
657
+ } catch (_a) {
658
+ return TA_GENERAL_BOUNDARY;
659
+ }
660
+ }
661
+ TaBoundaryUtil2.of = of;
662
+ async function ofAll(host, locations) {
663
+ const found = new Map;
664
+ for (const location of new Set(locations)) {
665
+ found.set(location, await of(host, location));
666
+ }
667
+ return found;
668
+ }
669
+ TaBoundaryUtil2.ofAll = ofAll;
670
+ function key(boundary) {
671
+ var _a;
672
+ return boundary.kind === "general" ? "general" : `${boundary.kind}:${(_a = boundary.root) !== null && _a !== undefined ? _a : ""}`;
673
+ }
674
+ TaBoundaryUtil2.key = key;
675
+ function canSee(from, of2) {
676
+ if (from.kind === "guest" || of2.kind === "guest") {
677
+ return false;
678
+ }
679
+ if (of2.kind === "general") {
680
+ return from.kind !== "private";
681
+ }
682
+ return key(from) === key(of2);
683
+ }
684
+ TaBoundaryUtil2.canSee = canSee;
685
+ function profile(boundary, general, notes) {
686
+ const own = (notes === null || notes === undefined ? undefined : notes.trim()) || undefined;
687
+ const all = (general === null || general === undefined ? undefined : general.trim()) || undefined;
688
+ switch (boundary.kind) {
689
+ case "general":
690
+ return all ? { general: all } : {};
691
+ case "work":
692
+ return { ...all ? { general: all } : {}, ...own ? { notes: own } : {} };
693
+ case "private":
694
+ return own ? { notes: own } : {};
695
+ default:
696
+ return {};
697
+ }
698
+ }
699
+ TaBoundaryUtil2.profile = profile;
700
+ function valid(value) {
701
+ const boundary = value;
702
+ if (!boundary || typeof boundary !== "object" || !TA_BOUNDARY_KINDS.includes(boundary.kind)) {
703
+ return TA_GENERAL_BOUNDARY;
704
+ }
705
+ if (boundary.kind === "general") {
706
+ return TA_GENERAL_BOUNDARY;
707
+ }
708
+ return {
709
+ kind: boundary.kind,
710
+ ...typeof boundary.root === "string" && boundary.root ? { root: boundary.root } : {},
711
+ ...typeof boundary.name === "string" && boundary.name.trim() ? { name: boundary.name.trim() } : {}
712
+ };
713
+ }
714
+ TaBoundaryUtil2.valid = valid;
715
+ })(TaBoundaryUtil || (TaBoundaryUtil = {}));
716
+
608
717
  // ../ta-protocol/esm/common/redactor.js
609
718
  var REDACTED = "[redacted]";
610
719
  var WHOLE = [
@@ -992,6 +1101,52 @@ class Scrubber {
992
1101
  }
993
1102
  }
994
1103
 
1104
+ // web-src/vault-boundaries.ts
1105
+ var VaultBoundaries;
1106
+ ((VaultBoundaries) => {
1107
+ VaultBoundaries.GUEST_PROMPT = "This conversation is with a guest of the Ta, not its user: no secret of the user is here. Never ask for one, nor for any of the guest's.";
1108
+ async function choices(host, entries) {
1109
+ return { choices: await TaBoundaryUtil.list(host), idle: await idle(host, entries) };
1110
+ }
1111
+ VaultBoundaries.choices = choices;
1112
+ function of(value) {
1113
+ const boundary = TaBoundaryUtil.valid(value);
1114
+ return (boundary.kind === "work" || boundary.kind === "private") && boundary.root ? boundary : undefined;
1115
+ }
1116
+ VaultBoundaries.of = of;
1117
+ async function here(host, cwd) {
1118
+ return TaBoundaryUtil.key(await TaBoundaryUtil.of(host, cwd));
1119
+ }
1120
+ VaultBoundaries.here = here;
1121
+ function inside(entry, here2) {
1122
+ return !guest(here2) && (!entry.boundary || TaBoundaryUtil.key(entry.boundary) === here2);
1123
+ }
1124
+ VaultBoundaries.inside = inside;
1125
+ function guest(here2) {
1126
+ return here2.startsWith("guest:");
1127
+ }
1128
+ VaultBoundaries.guest = guest;
1129
+ async function idle(host, entries) {
1130
+ const bound = entries.filter((entry) => entry.boundary);
1131
+ const now = await TaBoundaryUtil.ofAll(host, bound.map((entry) => entry.boundary?.root));
1132
+ return bound.filter((entry) => TaBoundaryUtil.key(now.get(entry.boundary?.root) ?? { kind: "general" }) !== TaBoundaryUtil.key(entry.boundary)).map((entry) => entry.name);
1133
+ }
1134
+ VaultBoundaries.idle = idle;
1135
+ function outbound(tool, language) {
1136
+ const found = Object.keys(TA_OUTBOUND_TOOLS).includes(tool) ? TA_OUTBOUND_TOOLS[tool] : undefined;
1137
+ return found && !found.asks ? found.what[language] : undefined;
1138
+ }
1139
+ VaultBoundaries.outbound = outbound;
1140
+ function sends(tool) {
1141
+ return Object.keys(TA_OUTBOUND_TOOLS).includes(tool);
1142
+ }
1143
+ VaultBoundaries.sends = sends;
1144
+ function guarded(boundary) {
1145
+ return boundary.kind === "work" || boundary.kind === "private";
1146
+ }
1147
+ VaultBoundaries.guarded = guarded;
1148
+ })(VaultBoundaries ||= {});
1149
+
995
1150
  // web-src/vault-sync.ts
996
1151
  var VaultSync;
997
1152
  ((VaultSync) => {
@@ -1003,7 +1158,8 @@ var VaultSync;
1003
1158
  ...entry.gitUser ? { gitUser: entry.gitUser } : {},
1004
1159
  ...entry.hint ? { hint: entry.hint } : {},
1005
1160
  ...entry.ssh ? { ssh: true } : {},
1006
- ...entry.signIn ? { signIn: entry.signIn } : {}
1161
+ ...entry.signIn ? { signIn: entry.signIn } : {},
1162
+ ...entry.boundary ? { boundary: entry.boundary } : {}
1007
1163
  };
1008
1164
  }
1009
1165
  VaultSync.about = about;
@@ -1022,7 +1178,8 @@ var VaultSync;
1022
1178
  ...given.gitUser && Array.isArray(given.hosts) && given.hosts.length ? { gitUser: given.gitUser } : {},
1023
1179
  ...given.kind === "personal" && given.hint ? { hint: given.hint } : {},
1024
1180
  ...SecretNames.privateKey(given.value) ? { ssh: true } : {},
1025
- ...given.signIn ? { signIn: given.signIn } : {}
1181
+ ...given.signIn ? { signIn: given.signIn } : {},
1182
+ ...given.boundary ? { boundary: given.boundary } : {}
1026
1183
  };
1027
1184
  return value === given.value && JSON.stringify(about(entry)) === JSON.stringify(about(came));
1028
1185
  }
@@ -1047,6 +1204,7 @@ var VaultSync;
1047
1204
  ...typeof about2.note === "string" ? { note: about2.note } : {},
1048
1205
  ...typeof about2.gitUser === "string" ? { gitUser: about2.gitUser } : {},
1049
1206
  ...typeof about2.hint === "string" ? { hint: about2.hint } : {},
1207
+ boundary: VaultBoundaries.of(about2.boundary) ?? null,
1050
1208
  ...kind === "sign-in" && signIn ? {
1051
1209
  signIn: {
1052
1210
  id: signIn.id,
@@ -1110,6 +1268,7 @@ class Vault {
1110
1268
  const ssh = SecretNames.privateKey(value);
1111
1269
  const hosts = ssh ? [] : input.hosts !== undefined ? SecretNames.hosts(input.hosts) : before?.hosts ?? SecretNames.defaultHosts(name);
1112
1270
  const gitUser = input.gitUser?.trim() || before?.gitUser;
1271
+ const boundary = input.boundary !== undefined ? VaultBoundaries.of(input.boundary) : before?.boundary;
1113
1272
  const entry = {
1114
1273
  name,
1115
1274
  kind: input.kind === "personal" || input.kind === "sign-in" ? input.kind : "credential",
@@ -1121,7 +1280,8 @@ class Vault {
1121
1280
  ...ssh ? { ssh: true } : {},
1122
1281
  ...input.kind === "personal" && input.hint ? { hint: String(input.hint).slice(0, 60) } : {},
1123
1282
  ...input.kind === "sign-in" && input.signIn ? { signIn: input.signIn } : {},
1124
- ...input.local ?? before?.local ? { local: true } : {}
1283
+ ...input.local ?? before?.local ? { local: true } : {},
1284
+ ...boundary ? { boundary } : {}
1125
1285
  };
1126
1286
  await this.save([...entries.filter((one) => one.name !== name), entry]);
1127
1287
  (await this.loaded()).set(name, entry.ssh && !value.endsWith(`
@@ -1148,14 +1308,31 @@ class Vault {
1148
1308
  });
1149
1309
  }
1150
1310
  setLocal(name, local) {
1311
+ return this.change(name, ({ local: _local, ...rest }) => local ? { ...rest, local: true } : rest);
1312
+ }
1313
+ setBoundary(name, boundary) {
1314
+ const kept = boundary === null ? undefined : VaultBoundaries.of(boundary);
1315
+ if (boundary !== null && !kept) {
1316
+ return Promise.reject(new Error("A secret is kept to a directory marked work or private, or to none."));
1317
+ }
1318
+ return this.change(name, ({ boundary: _boundary, ...rest }) => kept ? { ...rest, boundary: kept } : rest);
1319
+ }
1320
+ async locate(sessionFile, cwd) {
1321
+ return (sessionFile ? await this.host.sessionCwd?.(sessionFile).catch(() => {
1322
+ return;
1323
+ }) : undefined) ?? cwd;
1324
+ }
1325
+ boundaries() {
1326
+ return this.list().then((entries) => VaultBoundaries.choices(this.host, entries));
1327
+ }
1328
+ change(name, update) {
1151
1329
  return this.serial(async () => {
1152
1330
  const entries = await this.list();
1153
1331
  const entry = entries.find((one) => one.name === name);
1154
1332
  if (!entry) {
1155
1333
  throw new Error(`The vault has no ${name}.`);
1156
1334
  }
1157
- const { local: _local, ...rest } = entry;
1158
- const next = local ? { ...rest, local: true } : rest;
1335
+ const next = update(entry);
1159
1336
  await this.save(entries.map((one) => one.name === name ? next : one));
1160
1337
  this.credentials?.changed();
1161
1338
  return next;
@@ -1240,8 +1417,13 @@ class Vault {
1240
1417
  async setCapturingPersonal(on) {
1241
1418
  await this.host.setExtensionData(NAME, Keys.PERSONAL, on === true);
1242
1419
  }
1243
- async capture(text) {
1420
+ async capture(text, cwd) {
1244
1421
  let out = (await this.scrubber()).text(text);
1422
+ const where = await TaBoundaryUtil.of(this.host, cwd);
1423
+ if (where.kind === "guest") {
1424
+ return { text: out, names: [] };
1425
+ }
1426
+ const boundary = VaultBoundaries.of(where);
1245
1427
  const names = [];
1246
1428
  const take = async (spans, personal) => {
1247
1429
  for (const span of [...spans].reverse()) {
@@ -1251,7 +1433,7 @@ class Vault {
1251
1433
  name: await this.freeName(span.kind),
1252
1434
  value,
1253
1435
  source: "pasted",
1254
- ...personal ? { kind: "personal", hint: span.hint, hosts: [] } : {}
1436
+ ...personal ? { kind: "personal", hint: span.hint, hosts: [] } : boundary ? { boundary } : {}
1255
1437
  })).name;
1256
1438
  names.unshift(name);
1257
1439
  out = out.slice(0, span.start) + SecretNames.handle(name) + out.slice(span.end);
@@ -1268,8 +1450,9 @@ class Vault {
1268
1450
  }
1269
1451
  return { text: out, names: [...new Set(names)] };
1270
1452
  }
1271
- async fill(input, tool, conversation) {
1272
- const personal = new Map((await this.list()).filter((entry) => entry.kind === "personal").map((entry) => [entry.name, entry]));
1453
+ async fill(input, tool, conversation, cwd) {
1454
+ const here = await VaultBoundaries.here(this.host, cwd);
1455
+ const personal = new Map((await this.list()).filter((entry) => entry.kind === "personal" && VaultBoundaries.inside(entry, here)).map((entry) => [entry.name, entry]));
1273
1456
  const values = await this.loaded();
1274
1457
  const used = new Set;
1275
1458
  const put = (text) => text.replace(/\$\{?TA_SECRET_([A-Z0-9_]+)\}?/g, (whole, name) => {
@@ -1334,8 +1517,16 @@ class Vault {
1334
1517
  if (this.isRemote(place.cwd)) {
1335
1518
  return named.length ? { block: "The vault gives secrets only to commands of this computer, and this conversation works on a remote host. Tell the user." } : {};
1336
1519
  }
1337
- const entries = await this.list();
1520
+ const here = await VaultBoundaries.here(this.host, place.location ?? place.cwd);
1521
+ const all = await this.list();
1338
1522
  const values = await this.loaded();
1523
+ const elsewhere = named.filter((name) => all.some((entry) => entry.name === name && !VaultBoundaries.inside(entry, here)));
1524
+ if (elsewhere.length) {
1525
+ return {
1526
+ block: `${elsewhere.map(SecretNames.handle).join(", ")}: kept to the conversations of another directory, as the user set it in Settings, Vault. Do not work around it; tell the user.`
1527
+ };
1528
+ }
1529
+ const entries = all.filter((entry) => VaultBoundaries.inside(entry, here));
1339
1530
  const byName = new Map(entries.map((entry) => [entry.name, entry]));
1340
1531
  const signIns = named.filter((name) => byName.get(name)?.kind === "sign-in");
1341
1532
  if (signIns.length) {
@@ -1407,8 +1598,12 @@ class Vault {
1407
1598
  async uses() {
1408
1599
  return SecretNames.uses(await this.host.getExtensionData(NAME, Keys.USES));
1409
1600
  }
1410
- async prompt() {
1411
- const entries = (await this.list()).filter((entry) => entry.kind !== "sign-in");
1601
+ async prompt(cwd) {
1602
+ const here = await VaultBoundaries.here(this.host, cwd);
1603
+ if (VaultBoundaries.guest(here)) {
1604
+ return VaultBoundaries.GUEST_PROMPT;
1605
+ }
1606
+ const entries = (await this.list()).filter((entry) => entry.kind !== "sign-in" && VaultBoundaries.inside(entry, here));
1412
1607
  const kept = entries.length ? entries.map((entry) => `- ${Vault.described(entry)}`).join(`
1413
1608
  `) : "- none yet";
1414
1609
  return [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-secrets",
3
- "version": "4.29.0",
3
+ "version": "4.31.0",
4
4
  "description": "A pi package for Ta: a vault of secrets kept in the keychain, which Ta uses in commands by name without the model ever seeing them",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -27,8 +27,8 @@
27
27
  "watch": "tsc -b -w --preserveWatchOutput"
28
28
  },
29
29
  "devDependencies": {
30
- "@celljs/ta-protocol": "4.29.0",
31
- "@celljs/ta-web": "4.29.0",
30
+ "@celljs/ta-protocol": "4.31.0",
31
+ "@celljs/ta-web": "4.31.0",
32
32
  "@types/react": "^19.3.0"
33
33
  },
34
34
  "publishConfig": {
@@ -62,6 +62,9 @@
62
62
  "tools": {
63
63
  "request_secret": "settings.manage"
64
64
  }
65
- }
65
+ },
66
+ "sections": [
67
+ "ta-secrets"
68
+ ]
66
69
  }
67
70
  }
package/web/index.js CHANGED
@@ -67,6 +67,12 @@ var EN = {
67
67
  localLabel: "This device only",
68
68
  fromDevice: "from another device",
69
69
  syncSwitch: "Sync to my devices",
70
+ whereLabel: "Where it is used",
71
+ whereAll: "All conversations",
72
+ whereOnly: "Only in {name} ({kind})",
73
+ whereIdle: "not in use: {name} is not marked now",
74
+ whereWork: "work",
75
+ wherePrivate: "private",
70
76
  keptSynced: "Each follows your account to your other devices, sealed end to end, unless you keep it to this one.",
71
77
  signInUser: "account {user}",
72
78
  remove: "Remove",
@@ -119,6 +125,12 @@ var ZH = {
119
125
  localLabel: "只留本机",
120
126
  fromDevice: "来自其他设备",
121
127
  syncSwitch: "同步到我的设备",
128
+ whereLabel: "在哪儿用",
129
+ whereAll: "所有对话",
130
+ whereOnly: "只在「{name}」({kind})",
131
+ whereIdle: "暂不可用:「{name}」现在没有标记",
132
+ whereWork: "公司",
133
+ wherePrivate: "私密",
122
134
  keptSynced: "默认随账号端到端加密同步到你的其他设备;关掉开关的只留在这台。",
123
135
  signInUser: "账号 {user}",
124
136
  remove: "删除",
@@ -171,6 +183,12 @@ var ZH_TW = {
171
183
  localLabel: "只留本機",
172
184
  fromDevice: "來自其他裝置",
173
185
  syncSwitch: "同步到我的裝置",
186
+ whereLabel: "在哪裡用",
187
+ whereAll: "所有對話",
188
+ whereOnly: "只在「{name}」({kind})",
189
+ whereIdle: "暫不可用:「{name}」現在沒有標記",
190
+ whereWork: "公司",
191
+ wherePrivate: "私密",
174
192
  keptSynced: "預設隨帳號端到端加密同步到你的其他裝置;關掉開關的只留在這台。",
175
193
  signInUser: "帳號 {user}",
176
194
  remove: "刪除",
@@ -223,6 +241,12 @@ var JA = {
223
241
  localLabel: "この端末のみ",
224
242
  fromDevice: "別の端末から",
225
243
  syncSwitch: "自分の端末に同期",
244
+ whereLabel: "使う場所",
245
+ whereAll: "すべての会話",
246
+ whereOnly: "「{name}」のみ({kind})",
247
+ whereIdle: "使用停止中:「{name}」は今マークされていません",
248
+ whereWork: "仕事",
249
+ wherePrivate: "プライベート",
226
250
  keptSynced: "アカウントの他の端末へエンドツーエンドで暗号化して同期します。スイッチをオフにしたものはこの端末だけに残ります。",
227
251
  signInUser: "アカウント {user}",
228
252
  remove: "削除",
@@ -349,6 +373,109 @@ var SecretNames;
349
373
  SecretNames.entries = entries;
350
374
  })(SecretNames ||= {});
351
375
 
376
+ // ../ta-protocol/esm/common/boundary-protocol.js
377
+ var TA_BOUNDARY_KINDS = ["general", "work", "private", "guest"];
378
+ var TA_GENERAL_BOUNDARY = Object.freeze({ kind: "general" });
379
+ var words = (en, zh, tw, ja) => ({
380
+ "en-US": en,
381
+ "zh-CN": zh,
382
+ "zh-TW": tw,
383
+ "ja-JP": ja
384
+ });
385
+ var TA_OUTBOUND_TOOLS = {
386
+ say_in_group: { what: words("send it to a group chat", "发到群聊", "發到群聊", "グループチャットに送る") },
387
+ hand_task: { what: words("hand it to someone else's Ta", "交给别人的 Ta", "交給別人的 Ta", "他の人の Ta に渡す") },
388
+ nearby_show: { what: words("show it to people nearby", "给附近的人看", "給附近的人看", "近くの人に見せる") },
389
+ draft_moment: { what: words("post it to your Moments", "发到动态", "發到動態", "モーメントに投稿"), asks: true },
390
+ share_link: { what: words("share it by a link", "生成分享链接", "產生分享連結", "リンクで共有"), asks: true },
391
+ public_link: { what: words("put it on the internet", "公开到网上", "公開到網上", "インターネットに公開"), asks: true },
392
+ nearby_greet: { what: words("send it to someone nearby", "发给附近的人", "發給附近的人", "近くの人に送る"), asks: true },
393
+ nearby_group: { what: words("start a group chat with people nearby", "和附近的人建群", "和附近的人建群", "近くの人とグループを作る"), asks: true },
394
+ feedback_draft: { what: words("send it to the makers of Ta", "发给 Ta 的开发者", "發給 Ta 的開發者", "Ta の開発者に送る"), asks: true }
395
+ };
396
+ var TaBoundaryUtil;
397
+ (function(TaBoundaryUtil2) {
398
+ async function list(host) {
399
+ var _a, _b;
400
+ var _c;
401
+ try {
402
+ return ((_c = await ((_b = (_a = host.boundaries) === null || _a === undefined ? undefined : _a.list) === null || _b === undefined ? undefined : _b.call(_a))) !== null && _c !== undefined ? _c : []).map(valid).filter((one) => one.kind !== "general");
403
+ } catch (_d) {
404
+ return [];
405
+ }
406
+ }
407
+ TaBoundaryUtil2.list = list;
408
+ function label(boundary) {
409
+ var _a;
410
+ return boundary.name || ((_a = boundary.root) === null || _a === undefined ? undefined : _a.replace(/[\\/]+$/, "").split(/[\\/]/).pop()) || boundary.kind;
411
+ }
412
+ TaBoundaryUtil2.label = label;
413
+ async function of(host, location) {
414
+ if (!host.boundaries || !location) {
415
+ return TA_GENERAL_BOUNDARY;
416
+ }
417
+ try {
418
+ return await host.boundaries.of(location);
419
+ } catch (_a) {
420
+ return TA_GENERAL_BOUNDARY;
421
+ }
422
+ }
423
+ TaBoundaryUtil2.of = of;
424
+ async function ofAll(host, locations) {
425
+ const found = new Map;
426
+ for (const location of new Set(locations)) {
427
+ found.set(location, await of(host, location));
428
+ }
429
+ return found;
430
+ }
431
+ TaBoundaryUtil2.ofAll = ofAll;
432
+ function key(boundary) {
433
+ var _a;
434
+ return boundary.kind === "general" ? "general" : `${boundary.kind}:${(_a = boundary.root) !== null && _a !== undefined ? _a : ""}`;
435
+ }
436
+ TaBoundaryUtil2.key = key;
437
+ function canSee(from, of2) {
438
+ if (from.kind === "guest" || of2.kind === "guest") {
439
+ return false;
440
+ }
441
+ if (of2.kind === "general") {
442
+ return from.kind !== "private";
443
+ }
444
+ return key(from) === key(of2);
445
+ }
446
+ TaBoundaryUtil2.canSee = canSee;
447
+ function profile(boundary, general, notes) {
448
+ const own = (notes === null || notes === undefined ? undefined : notes.trim()) || undefined;
449
+ const all = (general === null || general === undefined ? undefined : general.trim()) || undefined;
450
+ switch (boundary.kind) {
451
+ case "general":
452
+ return all ? { general: all } : {};
453
+ case "work":
454
+ return { ...all ? { general: all } : {}, ...own ? { notes: own } : {} };
455
+ case "private":
456
+ return own ? { notes: own } : {};
457
+ default:
458
+ return {};
459
+ }
460
+ }
461
+ TaBoundaryUtil2.profile = profile;
462
+ function valid(value) {
463
+ const boundary = value;
464
+ if (!boundary || typeof boundary !== "object" || !TA_BOUNDARY_KINDS.includes(boundary.kind)) {
465
+ return TA_GENERAL_BOUNDARY;
466
+ }
467
+ if (boundary.kind === "general") {
468
+ return TA_GENERAL_BOUNDARY;
469
+ }
470
+ return {
471
+ kind: boundary.kind,
472
+ ...typeof boundary.root === "string" && boundary.root ? { root: boundary.root } : {},
473
+ ...typeof boundary.name === "string" && boundary.name.trim() ? { name: boundary.name.trim() } : {}
474
+ };
475
+ }
476
+ TaBoundaryUtil2.valid = valid;
477
+ })(TaBoundaryUtil || (TaBoundaryUtil = {}));
478
+
352
479
  // web-src/settings.tsx
353
480
  function message(error) {
354
481
  return error instanceof Error ? error.message : String(error);
@@ -371,11 +498,11 @@ function useStored(pi, key, parse) {
371
498
  }
372
499
  var capture = (value) => value !== false;
373
500
  function CaptureSetting({ pi }) {
374
- const words = SecretsWords.of(pi.ui.language);
501
+ const words2 = SecretsWords.of(pi.ui.language);
375
502
  const on = useStored(pi, Keys.CAPTURE, capture);
376
503
  return /* @__PURE__ */ React.createElement(pi.ui.Switch, {
377
504
  checked: on,
378
- label: words.captureLabel,
505
+ label: words2.captureLabel,
379
506
  onChange: (next) => pi.callHost("setCapturing", next).catch((error) => {
380
507
  pi.ui.notify(message(error), "error");
381
508
  throw error;
@@ -383,11 +510,11 @@ function CaptureSetting({ pi }) {
383
510
  });
384
511
  }
385
512
  function PersonalSetting({ pi }) {
386
- const words = SecretsWords.of(pi.ui.language);
513
+ const words2 = SecretsWords.of(pi.ui.language);
387
514
  const on = useStored(pi, Keys.PERSONAL, capture);
388
515
  return /* @__PURE__ */ React.createElement(pi.ui.Switch, {
389
516
  checked: on,
390
- label: words.personalLabel,
517
+ label: words2.personalLabel,
391
518
  onChange: (next) => pi.callHost("setCapturingPersonal", next).catch((error) => {
392
519
  pi.ui.notify(message(error), "error");
393
520
  throw error;
@@ -395,10 +522,10 @@ function PersonalSetting({ pi }) {
395
522
  });
396
523
  }
397
524
  function RemoveButton({ pi, entry }) {
398
- const words = SecretsWords.of(pi.ui.language);
525
+ const words2 = SecretsWords.of(pi.ui.language);
399
526
  const [busy, run] = pi.ui.useBusy();
400
527
  const remove = async () => {
401
- if (await pi.ui.confirm(SecretsWords.format(words.removeTitle, { name: entry.name }), words.removeHint, { confirmLabel: words.remove, danger: true })) {
528
+ if (await pi.ui.confirm(SecretsWords.format(words2.removeTitle, { name: entry.name }), words2.removeHint, { confirmLabel: words2.remove, danger: true })) {
402
529
  await run(() => pi.callHost("remove", entry.name).catch((error) => pi.ui.notify(message(error), "error")));
403
530
  }
404
531
  };
@@ -410,34 +537,77 @@ function RemoveButton({ pi, entry }) {
410
537
  onClick: () => void remove()
411
538
  }, busy && /* @__PURE__ */ React.createElement("span", {
412
539
  className: "ta-spinner ta-busy-mark"
413
- }), /* @__PURE__ */ React.createElement("span", null, words.remove));
540
+ }), /* @__PURE__ */ React.createElement("span", null, words2.remove));
414
541
  }
415
542
  function SyncSwitch({ pi, entry }) {
416
- const words = SecretsWords.of(pi.ui.language);
543
+ const words2 = SecretsWords.of(pi.ui.language);
417
544
  return /* @__PURE__ */ React.createElement(pi.ui.Switch, {
418
545
  checked: !entry.local,
419
- label: words.syncSwitch,
546
+ label: words2.syncSwitch,
420
547
  onChange: (next) => pi.callHost("setLocal", entry.name, !next).catch((error) => {
421
548
  pi.ui.notify(message(error), "error");
422
549
  throw error;
423
550
  })
424
551
  });
425
552
  }
426
- function signInWords(words, entry) {
553
+ function useBoundaryChoices(pi, entries) {
554
+ const [choices, setChoices] = React.useState({ choices: [], idle: [] });
555
+ React.useEffect(() => {
556
+ let live = true;
557
+ if (entries.length) {
558
+ pi.callHost("boundaries").then((found) => live && setChoices(found), () => {
559
+ return;
560
+ });
561
+ }
562
+ return () => {
563
+ live = false;
564
+ };
565
+ }, [pi, entries]);
566
+ return choices;
567
+ }
568
+ function WhereSelect({ pi, entry, choices }) {
569
+ const words2 = SecretsWords.of(pi.ui.language);
570
+ const [busy, run] = pi.ui.useBusy();
571
+ const own = entry.boundary;
572
+ const options = own && !choices.some((one) => TaBoundaryUtil.key(one) === TaBoundaryUtil.key(own)) ? [own, ...choices] : choices;
573
+ if (!options.some((one) => one.root)) {
574
+ return null;
575
+ }
576
+ return /* @__PURE__ */ React.createElement("select", {
577
+ className: "ta-input ta-secrets-where",
578
+ "aria-label": words2.whereLabel,
579
+ title: words2.whereLabel,
580
+ disabled: busy,
581
+ value: own ? TaBoundaryUtil.key(own) : "",
582
+ onChange: (event) => {
583
+ const next = options.find((one) => TaBoundaryUtil.key(one) === event.target.value) ?? null;
584
+ run(() => pi.callHost("setBoundary", entry.name, next).catch((error) => pi.ui.notify(message(error), "error")));
585
+ }
586
+ }, /* @__PURE__ */ React.createElement("option", {
587
+ value: ""
588
+ }, words2.whereAll), options.filter((one) => one.root).map((one) => /* @__PURE__ */ React.createElement("option", {
589
+ key: TaBoundaryUtil.key(one),
590
+ value: TaBoundaryUtil.key(one)
591
+ }, SecretsWords.format(words2.whereOnly, {
592
+ name: TaBoundaryUtil.label(one),
593
+ kind: one.kind === "work" ? words2.whereWork : words2.wherePrivate
594
+ }))));
595
+ }
596
+ function signInWords(words2, entry) {
427
597
  const signIn = entry.signIn;
428
598
  if (!signIn) {
429
599
  return;
430
600
  }
431
601
  if (signIn.feature === "relay") {
432
- return SecretsWords.format(words.kindRelay, { name: signIn.name });
602
+ return SecretsWords.format(words2.kindRelay, { name: signIn.name });
433
603
  }
434
604
  if (signIn.feature === "store") {
435
- return SecretsWords.format(words.kindStore, { name: signIn.name });
605
+ return SecretsWords.format(words2.kindStore, { name: signIn.name });
436
606
  }
437
607
  if (signIn.feature === "bot") {
438
- return signIn.name.startsWith("weixin:") ? words.kindBotWeixin : words.kindBotWecom;
608
+ return signIn.name.startsWith("weixin:") ? words2.kindBotWeixin : words2.kindBotWecom;
439
609
  }
440
- return SecretsWords.format(words.kindDesktop, { name: signIn.name });
610
+ return SecretsWords.format(words2.kindDesktop, { name: signIn.name });
441
611
  }
442
612
  var GROUPS = [
443
613
  { title: "groupSignIns", has: (entry) => entry.kind === "sign-in" },
@@ -445,13 +615,14 @@ var GROUPS = [
445
615
  { title: "groupPersonal", has: (entry) => entry.kind === "personal" }
446
616
  ];
447
617
  function KeptSetting({ pi }) {
448
- const words = SecretsWords.of(pi.ui.language);
618
+ const words2 = SecretsWords.of(pi.ui.language);
449
619
  const entries = useStored(pi, Keys.ENTRIES, SecretNames.entries);
620
+ const where = useBoundaryChoices(pi, entries);
450
621
  if (!entries.length) {
451
622
  return /* @__PURE__ */ React.createElement(pi.ui.Empty, {
452
623
  compact: true,
453
- title: words.emptyTitle,
454
- hint: words.emptyHint
624
+ title: words2.emptyTitle,
625
+ hint: words2.emptyHint
455
626
  });
456
627
  }
457
628
  return /* @__PURE__ */ React.createElement("div", {
@@ -463,7 +634,7 @@ function KeptSetting({ pi }) {
463
634
  className: "ta-secrets-group"
464
635
  }, /* @__PURE__ */ React.createElement("h4", {
465
636
  className: "ta-secrets-group-title"
466
- }, words[group.title]), /* @__PURE__ */ React.createElement("ul", {
637
+ }, words2[group.title]), /* @__PURE__ */ React.createElement("ul", {
467
638
  className: "ta-secrets-list"
468
639
  }, items.map((entry) => /* @__PURE__ */ React.createElement("li", {
469
640
  key: entry.name
@@ -474,16 +645,21 @@ function KeptSetting({ pi }) {
474
645
  }, entry.name), /* @__PURE__ */ React.createElement("span", {
475
646
  className: "ta-secrets-meta"
476
647
  }, [
477
- signInWords(words, entry) ?? (entry.note || (entry.ssh ? words.sshKey : entry.kind === "personal" ? words.kindPersonal : words.kindCredential)),
478
- entry.signIn?.user ? SecretsWords.format(words.signInUser, { user: entry.signIn.user }) : undefined,
648
+ signInWords(words2, entry) ?? (entry.note || (entry.ssh ? words2.sshKey : entry.kind === "personal" ? words2.kindPersonal : words2.kindCredential)),
649
+ entry.signIn?.user ? SecretsWords.format(words2.signInUser, { user: entry.signIn.user }) : undefined,
479
650
  entry.hint,
480
- entry.ssh && entry.note ? words.sshKey : undefined,
481
- entry.hosts?.length ? SecretsWords.format(words.hostsLabel, { hosts: entry.hosts.join(", ") }) : undefined,
482
- entry.local ? words.localLabel : entry.source === "synced" ? words.fromDevice : undefined,
483
- entry.uses ? SecretsWords.format(words.usedTimes, { count: entry.uses }) : words.neverUsed
651
+ entry.ssh && entry.note ? words2.sshKey : undefined,
652
+ entry.hosts?.length ? SecretsWords.format(words2.hostsLabel, { hosts: entry.hosts.join(", ") }) : undefined,
653
+ entry.boundary && where.idle.includes(entry.name) ? SecretsWords.format(words2.whereIdle, { name: TaBoundaryUtil.label(entry.boundary) }) : undefined,
654
+ entry.local ? words2.localLabel : entry.source === "synced" ? words2.fromDevice : undefined,
655
+ entry.uses ? SecretsWords.format(words2.usedTimes, { count: entry.uses }) : words2.neverUsed
484
656
  ].filter(Boolean).join(" · "))), /* @__PURE__ */ React.createElement("span", {
485
657
  className: "ta-secrets-actions"
486
- }, /* @__PURE__ */ React.createElement(SyncSwitch, {
658
+ }, entry.kind !== "sign-in" && /* @__PURE__ */ React.createElement(WhereSelect, {
659
+ pi,
660
+ entry,
661
+ choices: where.choices
662
+ }), /* @__PURE__ */ React.createElement(SyncSwitch, {
487
663
  pi,
488
664
  entry
489
665
  }), /* @__PURE__ */ React.createElement(RemoveButton, {
@@ -519,12 +695,12 @@ function ago(language, at, justNow) {
519
695
  return justNow;
520
696
  }
521
697
  function UsesSetting({ pi }) {
522
- const words = SecretsWords.of(pi.ui.language);
698
+ const words2 = SecretsWords.of(pi.ui.language);
523
699
  const uses = useStored(pi, Keys.USES, SecretNames.uses);
524
700
  if (!uses.length) {
525
701
  return /* @__PURE__ */ React.createElement(pi.ui.Empty, {
526
702
  compact: true,
527
- title: words.usesNone
703
+ title: words2.usesNone
528
704
  });
529
705
  }
530
706
  return /* @__PURE__ */ React.createElement("ul", {
@@ -540,10 +716,10 @@ function UsesSetting({ pi }) {
540
716
  title: use.command
541
717
  }, use.command)), /* @__PURE__ */ React.createElement("span", {
542
718
  className: "ta-secrets-when"
543
- }, [use.how.map((how) => words[HOW[how]]).join(" + "), use.conversation, ago(pi.ui.language, use.at, words.justNow)].filter(Boolean).join(" · ")))));
719
+ }, [use.how.map((how) => words2[HOW[how]]).join(" + "), use.conversation, ago(pi.ui.language, use.at, words2.justNow)].filter(Boolean).join(" · ")))));
544
720
  }
545
721
  function AddSetting({ pi }) {
546
- const words = SecretsWords.of(pi.ui.language);
722
+ const words2 = SecretsWords.of(pi.ui.language);
547
723
  const [name, setName] = React.useState("");
548
724
  const [value, setValue] = React.useState("");
549
725
  const [hosts, setHosts] = React.useState("");
@@ -559,7 +735,7 @@ function AddSetting({ pi }) {
559
735
  setName("");
560
736
  setValue("");
561
737
  setHosts("");
562
- pi.ui.notify(SecretsWords.format(words.added, { name: entry.name }), "info");
738
+ pi.ui.notify(SecretsWords.format(words2.added, { name: entry.name }), "info");
563
739
  }, (error) => pi.ui.notify(message(error), "error")));
564
740
  };
565
741
  return /* @__PURE__ */ React.createElement("form", {
@@ -568,7 +744,7 @@ function AddSetting({ pi }) {
568
744
  }, /* @__PURE__ */ React.createElement("input", {
569
745
  className: "ta-input",
570
746
  value: name,
571
- placeholder: words.namePlaceholder,
747
+ placeholder: words2.namePlaceholder,
572
748
  autoCapitalize: "characters",
573
749
  autoCorrect: "off",
574
750
  spellCheck: false,
@@ -577,7 +753,7 @@ function AddSetting({ pi }) {
577
753
  className: "ta-input ta-secrets-value",
578
754
  rows: 1,
579
755
  value,
580
- placeholder: words.valuePlaceholder,
756
+ placeholder: words2.valuePlaceholder,
581
757
  autoComplete: "off",
582
758
  autoCorrect: "off",
583
759
  autoCapitalize: "off",
@@ -586,7 +762,7 @@ function AddSetting({ pi }) {
586
762
  }), /* @__PURE__ */ React.createElement("input", {
587
763
  className: "ta-input",
588
764
  value: hosts,
589
- placeholder: words.hostsPlaceholder,
765
+ placeholder: words2.hostsPlaceholder,
590
766
  autoCapitalize: "off",
591
767
  autoCorrect: "off",
592
768
  spellCheck: false,
@@ -598,10 +774,10 @@ function AddSetting({ pi }) {
598
774
  disabled: !ready
599
775
  }, busy && /* @__PURE__ */ React.createElement("span", {
600
776
  className: "ta-spinner ta-busy-mark"
601
- }), /* @__PURE__ */ React.createElement("span", null, words.addLabel)));
777
+ }), /* @__PURE__ */ React.createElement("span", null, words2.addLabel)));
602
778
  }
603
779
  function vaultSettings(pi) {
604
- const words = () => SecretsWords.of(pi.ui.language);
780
+ const words2 = () => SecretsWords.of(pi.ui.language);
605
781
  let store;
606
782
  pi.callHost("info").then((info) => {
607
783
  store = info.store;
@@ -609,38 +785,38 @@ function vaultSettings(pi) {
609
785
  return;
610
786
  });
611
787
  return {
612
- title: () => words().settingsTitle,
788
+ title: () => words2().settingsTitle,
613
789
  icon: pi.ui.icons.KeyRound,
614
790
  group: "privacy",
615
791
  order: -10,
616
792
  rows: [
617
- { key: "capture", label: () => words().captureLabel, description: () => words().captureHint, render: () => /* @__PURE__ */ React.createElement(CaptureSetting, {
793
+ { key: "capture", label: () => words2().captureLabel, description: () => words2().captureHint, render: () => /* @__PURE__ */ React.createElement(CaptureSetting, {
618
794
  pi
619
795
  }) },
620
796
  {
621
797
  key: "personal",
622
- label: () => words().personalLabel,
623
- description: () => words().personalHint,
798
+ label: () => words2().personalLabel,
799
+ description: () => words2().personalHint,
624
800
  render: () => /* @__PURE__ */ React.createElement(PersonalSetting, {
625
801
  pi
626
802
  })
627
803
  },
628
804
  {
629
805
  key: "kept",
630
- label: () => words().keptLabel,
806
+ label: () => words2().keptLabel,
631
807
  description: () => {
632
- const kept = store === "file" ? words().keptFile : words().keptKeychain;
633
- return `${kept}${/[。.]$/.test(kept) ? "" : " "}${words().keptSynced}`;
808
+ const kept = store === "file" ? words2().keptFile : words2().keptKeychain;
809
+ return `${kept}${/[。.]$/.test(kept) ? "" : " "}${words2().keptSynced}`;
634
810
  },
635
811
  stacked: true,
636
812
  render: () => /* @__PURE__ */ React.createElement(KeptSetting, {
637
813
  pi
638
814
  })
639
815
  },
640
- { key: "add", label: () => words().addLabel, description: () => words().addHint, stacked: true, render: () => /* @__PURE__ */ React.createElement(AddSetting, {
816
+ { key: "add", label: () => words2().addLabel, description: () => words2().addHint, stacked: true, render: () => /* @__PURE__ */ React.createElement(AddSetting, {
641
817
  pi
642
818
  }) },
643
- { key: "uses", label: () => words().usesLabel, description: () => words().usesHint, stacked: true, render: () => /* @__PURE__ */ React.createElement(UsesSetting, {
819
+ { key: "uses", label: () => words2().usesLabel, description: () => words2().usesHint, stacked: true, render: () => /* @__PURE__ */ React.createElement(UsesSetting, {
644
820
  pi
645
821
  }) }
646
822
  ]
@@ -659,6 +835,10 @@ var STYLE = `
659
835
  .ta-secrets-group { display: flex; flex-direction: column; }
660
836
  .ta-secrets-group-title { margin: 0 0 2px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); font-weight: 500; }
661
837
  .ta-secrets-actions { display: flex; flex: none; align-items: center; gap: 12px; }
838
+ .ta-secrets-where { width: auto; max-width: 180px; height: 30px; padding: 0 8px; font-size: calc(12px * var(--ta-font-scale)); }
839
+ [data-layout='compact'] .ta-secrets-list li:has(.ta-secrets-where) { flex-wrap: wrap; }
840
+ [data-layout='compact'] .ta-secrets-list li:has(.ta-secrets-where) .ta-secrets-actions { flex: 1 1 100%; }
841
+ [data-layout='compact'] .ta-secrets-where { flex: 1 1 auto; min-width: 0; max-width: none; }
662
842
  .ta-secrets-add { display: flex; gap: 8px; width: 100%; }
663
843
  .ta-secrets-value { display: block; box-sizing: border-box; height: 36px; padding: 0 10px; line-height: 34px; resize: none; overflow: hidden; white-space: nowrap; font: inherit; -webkit-text-security: disc; }
664
844
  .ta-secrets-value::placeholder { line-height: 34px; }
@@ -669,7 +849,7 @@ var STYLE = `
669
849
  .ta-secrets-add .ta-input:first-child { font-family: var(--ta-mono); }
670
850
  [data-layout='compact'] .ta-secrets-add { flex-direction: column; }
671
851
  [data-layout='compact'] .ta-secrets-add .ta-input { flex: none; }
672
- [data-layout='compact'] .ta-secrets-add .ta-button { height: 36px; }
852
+ .ta-secrets-add .ta-button { flex: none; height: 36px; }
673
853
  `;
674
854
  function injectStyle() {
675
855
  const element = document.createElement("style");