pi-straw-boss 0.72.0 → 0.73.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.
@@ -5343,7 +5343,7 @@ function checkText(text10) {
5343
5343
  }
5344
5344
  var OVERLAY_OPEN = "A /boss gui lan screen is open in this session; only Escape can be sent to it from a paired device.";
5345
5345
  var BOSS_LOCAL = /^\s*\/boss\s+(gui\s+(stop|rotate|remote|lan|devices|unpair|view\s+\S+)|server|lan|answer|link\s+decide)(?=\s|$)/;
5346
- var BOSS_LINK_LOCAL = /^\s*\/boss\s+link\s+(on|confirms?|asks|answer|invite|join|create|leave|operate)(?=\s|$)/;
5346
+ var BOSS_LINK_LOCAL = /^\s*\/boss\s+link\s+(on|confirms?|asks|answer|invite|join|create|leave|operate|trust|role|remove|rotate)(?=\s|$)/;
5347
5347
  var BOSS_OPEN = /^\s*\/boss\s+open\s+([\s\S]*)$/;
5348
5348
  var BOSS_SEND = /^\s*\/boss\s+send(?=\s|$)([\s\S]*)$/;
5349
5349
  var localOnlyText = (text10) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-straw-boss",
3
- "version": "0.72.0",
3
+ "version": "0.73.0",
4
4
  "description": "Straw Boss coordination for pi in Herdr: sessions join a tab's net by choice, the first joiner is its main agent, a workspace tower opens on demand with a live monitoring dashboard, and boss_broadcast reaches the rest",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/bosslink.ts CHANGED
@@ -4,15 +4,18 @@ import { firstWord, folderOf } from "./bossopen.ts";
4
4
  import type { Here } from "./heremark.ts";
5
5
  import { hereOnlyOpts } from "./intercept.ts";
6
6
  import { line, plain } from "./safetext.ts";
7
+ import { LEVELS, type Level } from "./link/config.ts";
8
+ import { idOk } from "./link/device.ts";
7
9
  import { decodeInvite } from "./link/join.ts";
10
+ import type { MemberView } from "./link/admin.ts";
8
11
  import type { LinkView } from "./link/holder.ts";
9
12
  import type { Lang } from "./memorycmd.ts";
10
13
  import { readSecret, showScreen } from "./secretscreen.ts";
11
14
  import type { Kit } from "./state.ts";
12
15
 
13
- // The boss's typed twins of the Straw Link operations the page alone could do (`/boss link confirms | confirm | asks | answer | invite show|cancel | join | join cancel | create | leave`; the first of `link status` and
14
- // `link decide` are bossopen.ts's). Like bosspaths.ts each posts to the route the page posts to (`link/confirm-answer`, `dialog-answer`, `invite-text`, `invite-cancel`, `join-start`, `join-project`, `join-cancel`,
15
- // `create`, `leave`), so the holder keeps every check (the digest, the device, the level, the folder, the relay); this side parses the line, shows the whole question in pi, and asks hereOnly (hereOnlyOpts) before
16
+ // The boss's typed twins of the Straw Link operations the page alone could do (`/boss link confirms | confirm | asks | answer | invite <team> [unattended <device>] | invite show|cancel | join | join cancel | create | leave | trust | role |
17
+ // remove | rotate`; the first of `link status` and `link decide` are bossopen.ts's). Like bosspaths.ts each posts to the route the page posts to (`link/confirm-answer`, `dialog-answer`, `invite`, `invite-text`, `invite-cancel`,
18
+ // `join-start`, `join-project`, `join-cancel`, `create`, `leave`, `trust`, `role`, `remove`, `rotate`), so the holder keeps every check (the digest, the device, the level, the folder, the relay); this side parses the line, shows the whole question in pi, and asks hereOnly (hereOnlyOpts) before
16
19
  // anything that lets a teammate's tower run a call, answers for an unattended box, or changes who may command this computer. They are the boss's typed input only: boss.ts refuses them in a tower run or an ally run,
17
20
  // control.ts keeps a paired device's composer from typing them, and no tool reaches this module. Two things here are secrets: the relay's token goes from a masked screen (secretscreen.ts) into the request and nowhere else
18
21
  // (pi's `ctx.ui.input` echoes it), and an invite's text is drawn on a screen of its own, never as a notice. Whatever a teammate's device wrote (arguments, questions, labels) is shown with control and bidi characters as
@@ -25,15 +28,15 @@ type Share = "status" | "presence";
25
28
 
26
29
  export type LinkMore =
27
30
  | { action: "confirms" } | { action: "confirm"; id: string; verdict: "allow" | "deny" } | { action: "asks" } | { action: "answer"; id: string; cancel: boolean; text: string }
28
- | { action: "on" | "operate" | "operate-off" | "operate-on" } | { action: "invite-cancel" | "invite-show"; hash: string } | { action: "join-cancel" } | { action: "leave"; team: string; force: boolean }
31
+ | { action: "on" | "operate" | "operate-off" | "operate-on" } | { action: "invite-cancel" | "invite-show"; hash: string } | { action: "invite-make"; team: string; device?: string } | { action: "trust"; device: string; level: Level } | { action: "role"; team: string; device: string; role: "admin" | "member" } | { action: "remove"; team: string; device: string } | { action: "rotate"; team: string } | { action: "join-cancel" } | { action: "leave"; team: string; force: boolean }
29
32
  | { action: "create"; relay: string; project: string; share?: Share; label?: string } | { action: "join"; source: string; project?: string; share?: Share; label?: string };
30
33
 
31
34
  /** A moment as the boss reads it on this computer: `2026-11-07 14:03`. */
32
35
  const stamp = (ms: number): string => { const d = new Date(ms), p = (n: number) => String(n).padStart(2, "0"); return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`; };
33
36
 
34
- const VERBS = ["on", "confirms", "confirm", "asks", "answer", "invite", "join", "create", "leave", "operate"];
37
+ const VERBS = ["on", "confirms", "confirm", "asks", "answer", "invite", "join", "create", "leave", "operate", "trust", "role", "remove", "rotate"];
35
38
  /** What Tab completes for these (boss.ts adds them after the page's `link status` and `link decide`). */
36
- export const LINK_ARGUMENTS = Object.entries({ "link on": "Set up Straw Link on this computer, as the GUI page's Set up button does", "link confirms": "List the confirms teammates' towers wait on (the call's arguments in full)", "link confirm": "Allow or deny a teammate tower's call: link confirm <id> allow|deny", "link asks": "List the questions unattended devices forwarded to you", "link answer": "Answer a forwarded question: link answer <id> <choice number | text> (or --cancel)", "link invite show": "Show an open invite's text on this screen only: link invite show <hash>", "link invite cancel": "Cancel an open invite: link invite cancel <hash>", "link join": "Join a team: link join <invite text | @file> [--project <dir>] [--share status|presence] [--label <name>]", "link join cancel": "Cancel the join in progress", "link create": "Create a team: link create <relay> <dir> [--share status|presence] [--label <name>] (asks for the relay's token privately)", "link leave": "Leave a team on this computer: link leave <team> [--force]", "link operate": "List the operate sessions this computer holds on unattended boxes", "link operate off": "End every operate session this computer holds, and keep operate off until link operate on", "link operate on": "Turn operate on again after link operate off", "link units": "List the units and mains the unattended boxes reported: link units [box]", "link stop": "Ask a box to stop one of its mains: link stop <box> <main | handle start> [--interrupt] [reason]" }).map(([value, description]) => ({ value, label: value, description }));
39
+ export const LINK_ARGUMENTS = Object.entries({ "link on": "Set up Straw Link on this computer, as the GUI page's Set up button does", "link confirms": "List the confirms teammates' towers wait on (the call's arguments in full)", "link confirm": "Allow or deny a teammate tower's call: link confirm <id> allow|deny", "link asks": "List the questions unattended devices forwarded to you", "link answer": "Answer a forwarded question: link answer <id> <choice number | text> (or --cancel)", "link invite": "Make an invite and show its text on this screen only: link invite <team> [unattended <device id>]", "link invite show": "Show an open invite's text on this screen only: link invite show <hash>", "link invite cancel": "Cancel an open invite: link invite cancel <hash>", "link join": "Join a team: link join <invite text | @file> [--project <dir>] [--share status|presence] [--label <name>]", "link join cancel": "Cancel the join in progress", "link create": "Create a team: link create <relay> <dir> [--share status|presence] [--label <name>] (asks for the relay's token privately)", "link leave": "Leave a team on this computer: link leave <team> [--force]", "link trust": "Set what a teammate's device may do from its tower: link trust <device> reply|forward|dispatch", "link role": "Make a device of a team an admin or a member: link role <team> <device> admin|member", "link remove": "Remove a device from a team (an admin's act): link remove <team> <device>", "link rotate": "Replace a team's key for every device (an admin's act): link rotate <team>", "link operate": "List the operate sessions this computer holds on unattended boxes", "link operate off": "End every operate session this computer holds, and keep operate off until link operate on", "link operate on": "Turn operate on again after link operate off", "link units": "List the units and mains the unattended boxes reported: link units [box]", "link stop": "Ask a box to stop one of its mains: link stop <box> <main | handle start> [--interrupt] [reason]" }).map(([value, description]) => ({ value, label: value, description }));
37
40
 
38
41
  /** The words of a typed line (a quoted run is one word), flags `--name value` or `--name=value` split off; undefined for a flag that is not allowed or has no value. */
39
42
  function split(text: string, allowed: readonly string[], bare: readonly string[] = []): { pos: string[]; flag: Record<string, string> } | undefined {
@@ -79,7 +82,14 @@ export function parseLinkMore(rest: string | undefined): LinkMore | "usage" | un
79
82
  case "confirms": return p.pos.length === 1 ? { action: "confirms" } : "usage";
80
83
  case "asks": return p.pos.length === 1 ? { action: "asks" } : "usage";
81
84
  case "confirm": return p.pos.length === 3 && (b === "allow" || b === "deny") ? { action: "confirm", id: a!, verdict: b } : "usage";
82
- case "invite": return p.pos.length === 3 && (a === "cancel" || a === "show") ? { action: a === "cancel" ? "invite-cancel" : "invite-show", hash: b! } : "usage";
85
+ case "invite":
86
+ if (p.pos.length === 3 && (a === "cancel" || a === "show")) return { action: a === "cancel" ? "invite-cancel" : "invite-show", hash: b! };
87
+ if (a === "cancel" || a === "show") return "usage";
88
+ return p.pos.length === 2 ? { action: "invite-make", team: a! } : p.pos.length === 4 && b === "unattended" ? { action: "invite-make", team: a!, device: p.pos[3]! } : "usage";
89
+ case "trust": return p.pos.length === 3 && (LEVELS as readonly string[]).includes(b!) ? { action: "trust", device: a!, level: b as Level } : "usage";
90
+ case "role": return p.pos.length === 4 && (p.pos[3] === "admin" || p.pos[3] === "member") ? { action: "role", team: a!, device: b!, role: p.pos[3] } : "usage";
91
+ case "remove": return p.pos.length === 3 ? { action: "remove", team: a!, device: b! } : "usage";
92
+ case "rotate": return p.pos.length === 2 ? { action: "rotate", team: a! } : "usage";
83
93
  case "create": return p.pos.length === 3 ? { action: "create", relay: a!, project: b!, ...extra } : "usage";
84
94
  default: return a === "cancel" ? (p.pos.length === 2 && !Object.keys(p.flag).length ? { action: "join-cancel" } : "usage") : p.pos.length === 2 ? { action: "join", source: a!, ...(p.flag.project ? { project: p.flag.project } : {}), ...extra } : "usage";
85
95
  }
@@ -104,7 +114,7 @@ function readDialog(json: unknown): Dlg | undefined {
104
114
 
105
115
  const WORDS = {
106
116
  en: {
107
- usage: { on: "/boss link on", confirms: "/boss link confirms", confirm: "/boss link confirm <id> allow|deny", asks: "/boss link asks", answer: "/boss link answer <id> <choice number | text> | answer <id> (asks in pi) | answer <id> --cancel", invite: "/boss link invite show|cancel <hash>", join: "/boss link join <invite text | @file> [--project <dir>] [--share status|presence] [--label <name>] | join cancel", create: "/boss link create <relay> <dir> [--share status|presence] [--label <name>]", leave: "/boss link leave <team> [--force]", operate: "/boss link operate [off|on]" } as Record<string, string>,
117
+ usage: { on: "/boss link on", confirms: "/boss link confirms", confirm: "/boss link confirm <id> allow|deny", asks: "/boss link asks", answer: "/boss link answer <id> <choice number | text> | answer <id> (asks in pi) | answer <id> --cancel", invite: "/boss link invite <team> [unattended <device id>] | invite show|cancel <hash>", join: "/boss link join <invite text | @file> [--project <dir>] [--share status|presence] [--label <name>] | join cancel", create: "/boss link create <relay> <dir> [--share status|presence] [--label <name>]", leave: "/boss link leave <team> [--force]", operate: "/boss link operate [off|on]", trust: "/boss link trust <device> reply|forward|dispatch", role: "/boss link role <team> <device> admin|member", remove: "/boss link remove <team> <device>", rotate: "/boss link rotate <team>" } as Record<string, string>,
108
118
  off: "Straw Link is not on in this server (turn it on with /boss link on)",
109
119
  setup: "Setting up Straw Link: it takes a few seconds, then /boss link status shows it",
110
120
  noScreen: "This needs the pi screen to ask you first",
@@ -155,6 +165,31 @@ const WORDS = {
155
165
  invValid: (left: string) => `Valid for ${left}`,
156
166
  invFooter: "Enter or Esc closes this screen. The text is a credential: it is shown here and nowhere else.",
157
167
  joinCancelled: "Cancelled the join",
168
+ noDevice: (q: string, team: string) => `No device${team ? ` in team ${team}` : ""} is named or starts with "${q}" (a label, a short id, or four or more characters of its id)`,
169
+ manyDevices: (q: string, list: string, team: string) => `More than one device${team ? ` in ${team}` : ""} is named or starts with "${q}"; nothing was done. Name one by more of its id:\n${list}`,
170
+ notSelf: "This is this computer: the page changes other devices only (leave a team with /boss link leave <team>)",
171
+ badDeviceId: "A device id is 26 characters (a to z, 2 to 7), the one in the unattended device's link/device.id",
172
+ inviteTitle: "Make an invite?",
173
+ inviteBody: (team: string, id: string, device: string) => `A new invite to the team ${team} (${id}). Its text is a credential: it is shown next on a private screen and nowhere else, and it lapses on its own. ${device ? `It is pinned to the unattended device ${device}: only that device can join with it.` : "Anyone who has the text can ask to join; the request waits for your approval."}`,
174
+ trustTitle: "Change this device's trust?",
175
+ trustBody: (name: string, short: string, from: string, to: string, help: string) => `${name} (${short}): from ${from} to ${to}, for every team this computer shares with it. ${help}`,
176
+ levelHelp: { reply: "reply: the allowed read-only tools run; anything else asks you here", forward: "forward: the same, but anything else asks that device's owner on their computer", dispatch: "dispatch: runs as a message from you would, under this computer's own guards" } as Record<string, string>,
177
+ trustSame: (name: string, level: string) => `${name} is already ${level}: nothing to change`,
178
+ notRunning: (team: string) => `Team ${team} is stopped on this computer: nothing can be done in it`,
179
+ notAdmin: (team: string) => `This device is not an admin of ${team}: only an admin can do this`,
180
+ notAttendedSelf: (team: string) => `This device is not an attended member of ${team}: only an attended member can invite`,
181
+ roleSame: (name: string, to: string) => `${name} is ${to === "admin" ? "an admin" : "a member"} already: nothing to change`,
182
+ adminAttended: (name: string) => `${name} is an unattended device: only an attended device can be an admin`,
183
+ trustDone: (name: string, level: string) => `Set the trust of ${name} to ${level}`,
184
+ roleTitle: "Change this device's role?",
185
+ roleBody: (name: string, short: string, team: string, admin: boolean) => (admin ? `${name} (${short}) becomes an admin of ${team}: it can remove devices, change roles and rotate the team key, as you can.` : `${name} (${short}) becomes a member of ${team}: it can no longer remove devices, change roles or rotate the key.`),
186
+ roleDone: (name: string, team: string, admin: boolean) => `${name} is now ${admin ? "an admin" : "a member"} of ${team}`,
187
+ removeTitle: "Remove this device?",
188
+ removeBody: (name: string, short: string, team: string, others: number) => `${name} (${short}) is removed from the team ${team}, signed by this computer. It can no longer read or send in the team, and its id is banned: it comes back only with new keys. The team key is replaced too: the old one is retired and a new team key is sealed to the ${others} other device${others === 1 ? "" : "s"} that stay, besides this computer.`,
189
+ removeDone: (name: string, team: string) => `Removed ${name} from ${team}`,
190
+ rotateTitle: "Rotate the team key?",
191
+ rotateBody: (team: string, others: number) => `Rotate the key of the team ${team}. The key is replaced for every device in it: the old key is retired, and a new one is sealed through the relay to each of the ${others} other device${others === 1 ? "" : "s"} (besides this computer). Nobody is removed and no role changes.`,
192
+ rotateDone: (team: string) => `Rotated the key of ${team}`,
158
193
  leaveTitle: "Leave this team?",
159
194
  leaveBody: (name: string, id: string, force: boolean) => `${name} (${id}): this computer forgets the team (its team file and config entry). The roster at the relay is untouched; an admin removes this device.${force ? " Leave even if this device is the team's only attended admin: nobody could remove a device or rotate the key." : ""}`,
160
195
  leftTeam: (name: string) => `Left ${name}`,
@@ -183,7 +218,7 @@ const WORDS = {
183
218
  asksWait: (n: number) => `${n} forwarded question${n === 1 ? "" : "s"} wait${n === 1 ? "s" : ""}: /boss link asks`,
184
219
  },
185
220
  "zh-TW": {
186
- usage: { on: "/boss link on", confirms: "/boss link confirms", confirm: "/boss link confirm <id> allow|deny", asks: "/boss link asks", answer: "/boss link answer <id> <選項編號 | 文字> | answer <id>(在 pi 裡逐題問)| answer <id> --cancel", invite: "/boss link invite show|cancel <hash>", join: "/boss link join <邀請文字 | @檔案> [--project <資料夾>] [--share status|presence] [--label <名稱>] | join cancel", create: "/boss link create <中繼站> <資料夾> [--share status|presence] [--label <名稱>]", leave: "/boss link leave <團隊> [--force]", operate: "/boss link operate [off|on]" } as Record<string, string>,
221
+ usage: { on: "/boss link on", confirms: "/boss link confirms", confirm: "/boss link confirm <id> allow|deny", asks: "/boss link asks", answer: "/boss link answer <id> <選項編號 | 文字> | answer <id>(在 pi 裡逐題問)| answer <id> --cancel", invite: "/boss link invite <團隊> [unattended <裝置 id>] | invite show|cancel <hash>", join: "/boss link join <邀請文字 | @檔案> [--project <資料夾>] [--share status|presence] [--label <名稱>] | join cancel", create: "/boss link create <中繼站> <資料夾> [--share status|presence] [--label <名稱>]", leave: "/boss link leave <團隊> [--force]", operate: "/boss link operate [off|on]", trust: "/boss link trust <裝置> reply|forward|dispatch", role: "/boss link role <團隊> <裝置> admin|member", remove: "/boss link remove <團隊> <裝置>", rotate: "/boss link rotate <團隊>" } as Record<string, string>,
187
222
  off: "這個伺服器沒有開 Straw Link(用 /boss link on 開啟)",
188
223
  setup: "正在設定 Straw Link:要等幾秒,之後 /boss link status 會顯示",
189
224
  noScreen: "這個動作需要 pi 畫面,才能先問你",
@@ -234,6 +269,31 @@ const WORDS = {
234
269
  invValid: (left: string) => `還有效 ${left}`,
235
270
  invFooter: "按 Enter 或 Esc 關閉這個畫面。這段文字是憑證:只在這裡顯示,不會出現在別處。",
236
271
  joinCancelled: "已取消加入",
272
+ noDevice: (q: string, team: string) => `${team ? `團隊 ${team} 裡` : ""}沒有名為或以「${q}」開頭的裝置(名稱、短 id,或 id 的前四碼以上)`,
273
+ manyDevices: (q: string, list: string, team: string) => `${team ? `團隊 ${team} 裡` : ""}不只一個裝置名為或以「${q}」開頭,什麼都沒做。請用 id 更長的一段指明其中一個:\n${list}`,
274
+ notSelf: "這是這台電腦:頁面只改其他裝置(要離開團隊,用 /boss link leave <團隊>)",
275
+ badDeviceId: "裝置 id 是 26 個字元(a 到 z、2 到 7),就是無人值守裝置的 link/device.id 裡的那一串",
276
+ inviteTitle: "要建立邀請嗎?",
277
+ inviteBody: (team: string, id: string, device: string) => `為團隊 ${team}(${id})建立新邀請。邀請文字是憑證:接著只會顯示在私密畫面,不會出現在別處,也會自己失效。${device ? `它綁定無人值守裝置 ${device}:只有那部裝置能用它加入。` : "拿到文字的人都能要求加入;要求會等你核准。"}`,
278
+ trustTitle: "要改變這部裝置的信任嗎?",
279
+ trustBody: (name: string, short: string, from: string, to: string, help: string) => `${name}(${short}):從 ${from} 改為 ${to},對這台電腦與它共有的每個團隊都生效。${help}`,
280
+ levelHelp: { reply: "reply:允許的唯讀工具會執行;其他的在這裡問你", forward: "forward:同上,但其他的會問那部裝置的主人,在他的電腦上", dispatch: "dispatch:照你本人送來的訊息執行,受這台電腦自己的防護限制" } as Record<string, string>,
281
+ trustSame: (name: string, level: string) => `${name} 已經是 ${level}:不用改`,
282
+ notRunning: (team: string) => `團隊 ${team} 在這台電腦上已停止:什麼都不能做`,
283
+ notAdmin: (team: string) => `這台裝置不是 ${team} 的管理員:只有管理員能這樣做`,
284
+ notAttendedSelf: (team: string) => `這台裝置不是 ${team} 的有人值守成員:只有有人值守的成員能邀請`,
285
+ roleSame: (name: string, to: string) => `${name} 已經是${to === "admin" ? "管理員" : "成員"}:不用改`,
286
+ adminAttended: (name: string) => `${name} 是無人值守的裝置:只有有人值守的裝置能當管理員`,
287
+ trustDone: (name: string, level: string) => `已把 ${name} 的信任設為 ${level}`,
288
+ roleTitle: "要改變這部裝置的角色嗎?",
289
+ roleBody: (name: string, short: string, team: string, admin: boolean) => (admin ? `${name}(${short})將成為 ${team} 的管理員:它能像你一樣移除裝置、改變角色、輪替團隊金鑰。` : `${name}(${short})將成為 ${team} 的成員:它不能再移除裝置、改變角色或輪替金鑰。`),
290
+ roleDone: (name: string, team: string, admin: boolean) => `${name} 現在是 ${team} 的${admin ? "管理員" : "成員"}`,
291
+ removeTitle: "要移除這部裝置嗎?",
292
+ removeBody: (name: string, short: string, team: string, others: number) => `${name}(${short})會由這台電腦簽署,移出團隊 ${team}。它不能再讀或送團隊的訊息,它的 id 也被列入黑名單:要換新金鑰才能回來。團隊金鑰也會更換:舊金鑰作廢,新的團隊金鑰會封給留下來的另外 ${others} 部裝置(不含這台電腦)。`,
293
+ removeDone: (name: string, team: string) => `已把 ${name} 移出 ${team}`,
294
+ rotateTitle: "要輪替團隊金鑰嗎?",
295
+ rotateBody: (team: string, others: number) => `輪替團隊 ${team} 的金鑰。團隊裡每部裝置的金鑰都會更換:舊金鑰作廢,新金鑰會透過中繼站封給另外 ${others} 部裝置(不含這台電腦)。沒有人被移除,角色也不變。`,
296
+ rotateDone: (team: string) => `已輪替 ${team} 的團隊金鑰`,
237
297
  leaveTitle: "要離開這個團隊嗎?",
238
298
  leaveBody: (name: string, id: string, force: boolean) => `${name}(${id}):這台電腦會忘掉這個團隊(它的團隊檔與設定項目)。中繼站上的名冊不變,要由管理員移除這台裝置。${force ? "即使這台裝置是團隊唯一有人值守的管理員也離開:之後沒有人能移除裝置或輪替金鑰。" : ""}`,
239
299
  leftTeam: (name: string) => `已離開 ${name}`,
@@ -284,7 +344,7 @@ export function createBossLink({ s, tell }: Pick<Kit, "s" | "tell">, { record, p
284
344
  * another's would shadow it, so more than one is ambiguous, and all of them are returned for the boss to tell apart.
285
345
  */
286
346
  function lookup<T>(list: T[], q: string, keys: (x: T) => string[], id: (x: T) => string): { one: T } | { error: "none" } | { error: "many"; hits: T[] } {
287
- const low = q.toLowerCase(), hits = list.filter((x) => keys(x).some((k) => k.toLowerCase() === low) || (q.length >= MIN_ID && (id(x).startsWith(q) || plain(id(x)).startsWith(q))));
347
+ const low = q.toLowerCase(), hits = list.filter((x) => keys(x).some((k) => k.toLowerCase() === low) || (q.length >= MIN_ID && (id(x).toLowerCase().startsWith(low) || plain(id(x)).toLowerCase().startsWith(low))));
288
348
  return hits.length === 1 ? { one: hits[0]! } : hits.length ? { error: "many", hits } : { error: "none" };
289
349
  }
290
350
  /** Ids as a listing shows them: the first eight characters as the boss reads them, and the whole id (to 64) where another listed id starts with those eight, so two ids that look alike are told apart. */
@@ -315,6 +375,8 @@ export function createBossLink({ s, tell }: Pick<Kit, "s" | "tell">, { record, p
315
375
  tell(found.error === "none" ? t().none[kind](q) : t().many[kind](q, found.hits.map(show).join("\n")), "error");
316
376
  };
317
377
 
378
+ const pickTeam = (view: LinkView, team: string) => pick(lookup(view.teams, team, (y) => [y.team, y.name], (y) => y.team), "team", team, (y) => ` ${plain(y.team).slice(0, FULL_ID)} ${line(y.name)}`);
379
+
318
380
  // ---- Confirms (G1) --------------------------------------------------------------------------------------------------------------------
319
381
 
320
382
  async function confirms() {
@@ -428,20 +490,97 @@ export function createBossLink({ s, tell }: Pick<Kit, "s" | "tell">, { record, p
428
490
  }
429
491
  const reply = await post(got.r, "link/invite-text", { hash: i.hash }, 10_000), text = reply.body.text;
430
492
  if (reply.status !== 200 || typeof text !== "string") return tell(refusal(reply), "error");
431
- const left = typeof reply.body.expires === "number" ? reply.body.expires - Date.now() : 0;
432
- const ui = s.ui!;
433
- await here(() => showScreen(ui, { title: t().invTitle(line(i.teamName), line(i.forDevice.slice(0, 6))), lines: [text, "", t().invValid(t().left(Math.max(0, left)))], footer: t().invFooter }));
493
+ await drawInvite(text, reply.body.expires, i.teamName, i.forDevice);
494
+ }
495
+ /** An invite's text on the private screen (secretscreen.ts), until the boss closes it: the one place the text is drawn. */
496
+ async function drawInvite(text: string, expires: unknown, teamName: string, forDevice: string): Promise<boolean> {
497
+ const left = typeof expires === "number" ? expires - Date.now() : 0, ui = s.ui!;
498
+ return here(() => showScreen(ui, { title: t().invTitle(line(teamName), line(forDevice.slice(0, 6))), lines: [text, "", t().invValid(t().left(Math.max(0, left)))], footer: t().invFooter }));
499
+ }
500
+ /** `invite <team> [unattended <device>]`: the page's Invite and Invite an unattended device, after a confirm. The screen comes first (the text could not be shown otherwise), the confirm second, the invite last. */
501
+ async function makeInvite(team: string, device: string | undefined) {
502
+ if (!needPrivate()) return;
503
+ const forDevice = device?.trim().toLowerCase();
504
+ if (forDevice !== undefined && !idOk(forDevice)) return tell(t().badDeviceId, "error");
505
+ const got = await state();
506
+ if (!got) return;
507
+ const x = pickTeam(got.view, team);
508
+ if (!x) return;
509
+ if (x.status !== "running") return tell(t().notRunning(line(x.name)), "error");
510
+ if (!x.self.attended) return tell(t().notAttendedSelf(line(x.name)), "error");
511
+ if (!(await confirm(t().inviteTitle, t().inviteBody(line(x.name), x.team.slice(0, 6), forDevice ? line(forDevice) : ""), true))) return tell(t().declined);
512
+ const reply = await post(got.r, "link/invite", { team: x.team, ...(forDevice ? { forDevice } : {}) }, 30_000), text = reply.body.text;
513
+ if (reply.status !== 200 || typeof text !== "string") return tell(refusal(reply), "error");
514
+ if (await drawInvite(text, reply.body.expires, x.name, forDevice ?? "")) return;
515
+ // pi's no-op `ui.custom` (RPC mode) draws nothing: the invite just made could not be read, so it is cancelled.
516
+ if (typeof reply.body.hash === "string") await post(got.r, "link/invite-cancel", { hash: reply.body.hash }, 10_000);
517
+ tell(t().noPrivate, "error");
434
518
  }
435
519
  async function leave(team: string, force: boolean) {
436
520
  if (!needScreen()) return;
437
521
  const got = await state();
438
522
  if (!got) return;
439
- const x = pick(lookup(got.view.teams, team, (y) => [y.team, y.name], (y) => y.team), "team", team, (y) => ` ${plain(y.team).slice(0, FULL_ID)} ${line(y.name)}`);
523
+ const x = pickTeam(got.view, team);
440
524
  if (!x) return;
441
525
  if (!(await confirm(t().leaveTitle, t().leaveBody(line(x.name), x.team.slice(0, 6), force), true))) return tell(t().notLeft);
442
526
  const reply = await post(got.r, "link/leave", { team: x.team, force }, 30_000);
443
527
  reply.status === 200 ? tell(t().leftTeam(line(x.name))) : tell(refusal(reply), "error");
444
528
  }
529
+ /** The one device of `members` that `q` names (a label, a short id, an id, or four or more characters of the id); a device in several teams is one, and this computer is told as such. An error is told. */
530
+ function deviceOf(members: MemberView[], q: string, team = ""): MemberView | undefined {
531
+ const groups = new Map<string, MemberView[]>();
532
+ for (const m of members) groups.set(m.id, [...(groups.get(m.id) ?? []), m]);
533
+ const found = lookup([...groups.values()], q, (g) => g.flatMap((m) => [m.id, m.short, m.label]), (g) => g[0]!.id);
534
+ if ("one" in found) return found.one[0]!.self ? void tell(t().notSelf, "error") : found.one[0]!;
535
+ if (found.error === "none") return void tell(t().noDevice(q, line(team)), "error");
536
+ const ids = shownIds(found.hits.map((g) => g[0]!.id));
537
+ tell(t().manyDevices(q, found.hits.map((g, i) => ` ${ids[i]} ${line(g[0]!.label)}`).join("\n"), line(team)), "error");
538
+ }
539
+ /** The page's state, the team `team` names, and (for a role or a remove) the device of that team `device` names, or an error told. */
540
+ async function inTeam(team: string, device?: string) {
541
+ if (!needScreen()) return;
542
+ const got = await state(), x = got && pickTeam(got.view, team), m = x && device !== undefined ? deviceOf(x.members, device, x.name) : undefined;
543
+ if (!got || !x || (device !== undefined && !m)) return undefined;
544
+ if (x.status !== "running") return void tell(t().notRunning(line(x.name)), "error");
545
+ if (x.self.role !== "admin") return void tell(t().notAdmin(line(x.name)), "error");
546
+ return { r: got.r, x, m: m! };
547
+ }
548
+ async function trust(device: string, level: Level) {
549
+ if (!needScreen()) return;
550
+ const got = await state(), m = got && deviceOf(got.view.teams.flatMap((y) => y.members), device);
551
+ if (!got || !m) return;
552
+ const name = line(m.label);
553
+ if (m.trust === level) return tell(t().trustSame(name, level));
554
+ if (!(await confirm(t().trustTitle, t().trustBody(name, line(m.short), m.trust, level, t().levelHelp[level]!), true))) return tell(t().declined);
555
+ const reply = await post(got.r, "link/trust", { device: m.id, level }, 30_000);
556
+ reply.status === 200 ? tell(t().trustDone(name, level)) : tell(refusal(reply), "error");
557
+ }
558
+ async function role(team: string, device: string, to: "admin" | "member") {
559
+ const got = await inTeam(team, device);
560
+ if (!got) return;
561
+ const name = line(got.m.label), where = line(got.x.name);
562
+ if (got.m.role === to) return tell(t().roleSame(name, to));
563
+ if (to === "admin" && !got.m.attended) return tell(t().adminAttended(name), "error");
564
+ if (!(await confirm(t().roleTitle, t().roleBody(name, line(got.m.short), where, to === "admin"), true))) return tell(t().declined);
565
+ const reply = await post(got.r, "link/role", { team: got.x.team, device: got.m.id, role: to }, 60_000);
566
+ reply.status === 200 ? tell(t().roleDone(name, where, to === "admin")) : tell(refusal(reply), "error");
567
+ }
568
+ async function remove(team: string, device: string) {
569
+ const got = await inTeam(team, device);
570
+ if (!got) return;
571
+ const name = line(got.m.label), where = line(got.x.name), stay = got.x.members.filter((y) => !y.self && y.id !== got.m.id).length;
572
+ if (!(await confirm(t().removeTitle, t().removeBody(name, line(got.m.short), where, stay), true))) return tell(t().declined);
573
+ const reply = await post(got.r, "link/remove", { team: got.x.team, device: got.m.id }, 60_000);
574
+ reply.status === 200 ? tell(t().removeDone(name, where)) : tell(refusal(reply), "error");
575
+ }
576
+ async function rotate(team: string) {
577
+ const got = await inTeam(team);
578
+ if (!got) return;
579
+ const where = line(got.x.name);
580
+ if (!(await confirm(t().rotateTitle, t().rotateBody(where, got.x.members.filter((y) => !y.self).length), true))) return tell(t().declined);
581
+ const reply = await post(got.r, "link/rotate", { team: got.x.team }, 60_000);
582
+ reply.status === 200 ? tell(t().rotateDone(where)) : tell(refusal(reply), "error");
583
+ }
445
584
  async function create(p: Extract<LinkMore, { action: "create" }>, cwd: string) {
446
585
  if (!needPrivate()) return;
447
586
  const dir = folder(p.project, cwd);
@@ -516,6 +655,11 @@ export function createBossLink({ s, tell }: Pick<Kit, "s" | "tell">, { record, p
516
655
  case "answer": return answer(parsed.id, parsed.cancel, parsed.text);
517
656
  case "invite-cancel": return invite(parsed.hash, false);
518
657
  case "invite-show": return invite(parsed.hash, true);
658
+ case "invite-make": return makeInvite(parsed.team, parsed.device);
659
+ case "trust": return trust(parsed.device, parsed.level);
660
+ case "role": return role(parsed.team, parsed.device, parsed.role);
661
+ case "remove": return remove(parsed.team, parsed.device);
662
+ case "rotate": return rotate(parsed.team);
519
663
  case "join-cancel": {
520
664
  const reply = await post(await record(), "link/join-cancel", {}, 10_000);
521
665
  return reply.status === 200 ? tell(t().joinCancelled) : tell(refusal(reply), "error");
package/src/control.ts CHANGED
@@ -170,8 +170,8 @@ export function checkText(text: unknown): string | Reply {
170
170
  const OVERLAY_OPEN = "A /boss gui lan screen is open in this session; only Escape can be sent to it from a paired device.";
171
171
  /** Boss commands that manage pairing, remote access, Wi-Fi, or the server: a paired device's composer and a new session's first message never run them, nor `gui view <mode>` (the local page and the terminal do). A slip guard, not a boundary: the key pad's terminal keys are not filtered. */
172
172
  const BOSS_LOCAL = /^\s*\/boss\s+(gui\s+(stop|rotate|remote|lan|devices|unpair|view\s+\S+)|server|lan|answer|link\s+decide)(?=\s|$)/;
173
- /** The Straw Link subcommands that change who may command this computer or answer for it (bosslink.ts), and the ones that show a credential or a teammate's call: the same slip guard as `link decide`. `link` and `link status` stay readable. */
174
- const BOSS_LINK_LOCAL = /^\s*\/boss\s+link\s+(on|confirms?|asks|answer|invite|join|create|leave|operate)(?=\s|$)/;
173
+ /** The Straw Link subcommands that change who may command this computer or answer for it, a team's roster or its key (bosslink.ts), and the ones that show a credential or a teammate's call: the same slip guard as `link decide`. `link` and `link status` stay readable. */
174
+ const BOSS_LINK_LOCAL = /^\s*\/boss\s+link\s+(on|confirms?|asks|answer|invite|join|create|leave|operate|trust|role|remove|rotate)(?=\s|$)/;
175
175
  const BOSS_OPEN = /^\s*\/boss\s+open\s+([\s\S]*)$/, BOSS_SEND = /^\s*\/boss\s+send(?=\s|$)([\s\S]*)$/;
176
176
  /** A text a paired device may not send: a local-only /boss command, or a `/boss open` whose first message, or a `/boss send` whose text (at any depth), is one, since the new pane or the other session would run it from this computer. */
177
177
  export const localOnlyText = (text: string): boolean => {
@@ -41,14 +41,16 @@ export async function readSecret(ui: Ui, screen: Screen & { hint: string }): Pro
41
41
  });
42
42
  }
43
43
 
44
- /** The boss reads `lines` (a credential) on a screen of its own until Enter or Escape; nothing of it stays in the chat or the terminal's scrollback. */
45
- export async function showScreen(ui: Ui, screen: Screen & { lines: string[] }): Promise<void> {
46
- if (typeof ui.custom !== "function") return;
47
- await ui.custom<void>((_tui, _theme, _keys, done) => ({
44
+ /** The boss reads `lines` (a credential) on a screen of its own until Enter or Escape (false when the ui drew nothing: pi's no-op `custom` in RPC mode); nothing of it stays in the chat or the terminal's scrollback. */
45
+ export async function showScreen(ui: Ui, screen: Screen & { lines: string[] }): Promise<boolean> {
46
+ if (typeof ui.custom !== "function") return false;
47
+ let drawn = false;
48
+ await ui.custom<void>((_tui, _theme, _keys, done) => ((drawn = true), {
48
49
  render: (width) => draw(screen, width, screen.lines.flatMap((line) => rows(line, Math.max(1, width)))),
49
50
  invalidate() {},
50
51
  handleInput(data: string) {
51
52
  if (matchesKey(data, "escape") || matchesKey(data, "enter")) done();
52
53
  },
53
54
  }));
55
+ return drawn;
54
56
  }