@coda-console/friends 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,6 +5,7 @@
5
5
  - **本机身份**:身份卡显示本机的展示名、确定性几何纹头像、公钥短码(点按复制),下方状态条给出已互认好友数(有待互认、冲突时提示)与身份、证书状态。没有建身份时显示「未建身份」并提示前往客户端「设置 › 身份」创建。
6
6
  - **公钥派生的昵称与头像**:本机和好友都没有可编辑的昵称、照片、Emoji 或主题色,统一由 Accord 公钥推出。展示名是 `昵称 #尾号`:昵称按 coda#3040 的算法取公钥 256 位,从最高位起每 7 位一组(至多 36 组),`0–77` 为字母、`78–87` 为数字、`88–127` 为结束符(已有不足 2 位时跳过,够 2 位就结束,读完仍不足 2 位则没有昵称);尾号是公钥按大端整数转成十进制(补零到 78 位)后的末 4 位,同昵称且末 4 位相撞的公钥从右往左逐位加位直到区分(如 `xs #04084`、`xs #14084`)。撞号一起比的是当前页面(跨电脑时是视图里所有电脑)上的全部本人公钥与好友公钥;网关 `friends` 操作的 `title` 则由本机身份与全部好友一起比。解不出昵称时退回公钥短码(`ed25519:` 之后前 8 位),还没有公钥的待互认好友用节点名。头像是由公钥确定性生成的 5×5 几何纹,灰色,换设备也一样;没有合法公钥时取名字首字。这些算法不在插件里:页面用 WebView 标准库 `coda-view://lib/v1/accord.js`,Node 侧(网关、代理记录)用 `@coda-console/protocol/accord`,两者是同一份实现,测试用协议包的测试向量对齐。
7
7
  - **添加好友**:点身份卡上的「添加好友」,粘贴对方给的邀请(JSON、`coda-friend://` 链接或多行 `key=value`),接受后自动尝试互认。邀请也可以在同一个弹层里生成,见下文「生成与接受邀请」。
8
+ - **同身份通道合并**:同一台电脑上,指向同一个完整公钥(`author`)的多条通道(如 `node:` + `link:`、两条 `link:`,或对方多台设备共用个人根身份)合并成一张好友卡片:状态里有冲突就算冲突(不隐藏密钥冲突),否则有已互认的算已互认,其余为待互认;多条连接时副标题写「N 条连接」,已互认的好友名下还有待互认通道时再注明「(M 待互认)」。没有公钥的待互认通道不与任何条目合并。详情里公钥与「共享」归整个好友,「连接」一节逐条列出各通道(通道键、机器、范围有差别时一并写出),每条各自有状态、重新互认和二次确认的移除,移除一条后弹层留在其余连接上;只有一条连接时详情保持原样。好友数、状态条与网关 `friends/social@1` 的 `friendCount`、`friends` 都按合并后的好友统计。
8
9
  - **好友列表**:实时跟随好友表变化,宽屏双列。点好友打开详情:昵称、几何纹头像、完整公钥(可复制)、节点名、连接状态、「共享」(见下文「把远程执行授给好友」)、重新互认、二次确认后移除。
9
10
  - **社交网关 `friends/social@1`**:业务无关,别的插件(在 `optionalUses` 里声明)经它读好友与好友分享的记录、向好友发布与撤回记录,不必各自处理没有身份、证书过期和重试。
10
11
 
@@ -13,7 +14,7 @@
13
14
  页面不自己选电脑:App 的全局视图里有哪几台,页面就读哪几台,没有机器标签。
14
15
 
15
16
  - **本机身份按公钥显示**:按各台 Accord 的 `spec.author` 分组,同一身份只显示一张身份卡,视图里有不同身份的电脑时每个身份一张。
16
- - **好友按电脑分节**:每台一节,顺序同视图,节标题是电脑名;节里是这台自己的好友通道(好友关系按机器上的通道登记,在 A 上加的好友 B 上不会自动出现),状态条(好友数、证书状态、待互认与冲突)和「添加好友」也在这一节。接受邀请与随后的互认、好友详情里的重新互认、移除,都发给这一节、这一行所在的电脑。没有好友的电脑也占一节;同一个好友在两台上都加了,就在两节里各出现一次,不合并。读不到的电脑(`unreachable`)节里写明原因,不出「添加好友」。
17
+ - **好友按电脑分节**:每台一节,顺序同视图,节标题是电脑名;节里是这台自己的好友通道(好友关系按机器上的通道登记,在 A 上加的好友 B 上不会自动出现),状态条(好友数、证书状态、待互认与冲突)和「添加好友」也在这一节。接受邀请与随后的互认、好友详情里的重新互认、移除,都发给这一节、这一行所在的电脑。没有好友的电脑也占一节;同一个好友在两台上都加了,就在两节里各出现一次,不跨电脑合并(合并只在同一台电脑内按完整公钥进行)。读不到的电脑(`unreachable`)节里写明原因,不出「添加好友」。
17
18
  - **只有一台时**页面不出现节标题,状态条与「添加好友」仍在身份卡上。
18
19
  - **推荐用法**:好友只在一台电脑上加。好友关系登记在那台电脑上,别的电脑不会自动出现这个好友。邀请里的入网码只能用一次,不必在每台上重复加。
19
20
  - **要共享别的电脑**:不必在那台上再加一次好友。加了好友的这台作网关,能把同一空间里别的电脑的远程执行逐台授给好友(见下一节「经网关授出别的机器」)。
@@ -184,7 +185,7 @@ coda self grants.restrict '{"grant":"<授权号>","restrict":{"dirs":[…]}}'
184
185
 
185
186
  | 操作 | 作用 |
186
187
  | --- | --- |
187
- | `friends`(读) | 互认的好友(`includePending` 带上待互认与冲突的),只来自 Accord 的好友表:`{ selfAuthor, certState, friends }`,每行的 `title` 是公钥派生的展示名,不读名片记录 |
188
+ | `friends`(读) | 互认的好友(`includePending` 带上待互认与冲突的),只来自 Accord 的好友表:`{ selfAuthor, certState, friends }`,每行的 `title` 是公钥派生的展示名,不读名片记录;指向同一公钥的多条通道合并成一行,顶层 `node`、`peerNode`、`scope` 取代表通道,`channels` 列出各条通道 |
188
189
  | `records`(读) | 按 `kind`、`author`、`id`、`cursor` 读好友分享的记录,不读 `binding` 与 `friends/rpc-` 前缀 |
189
190
  | `publish` | 发布 `{ kind, id, body, audience? }`;同作者同内容不重发,换作者重发 |
190
191
  | `retract` | 撤回一条,或省略 `id` 撤回本机在这个 `kind` 下的全部(含队列里还没发出去的) |
package/lib/friends.mjs CHANGED
@@ -118,13 +118,36 @@ export function certStateOf(accord) {
118
118
  const RANK = { conflict: 0, pending: 1, bound: 2 };
119
119
  export const statusOf = friend => friend.conflict ? 'conflict' : friend.bound ? 'bound' : 'pending';
120
120
 
121
+ const compare = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
122
+ const channelOf = friend => ({ node: friend.node, mode: typeof friend.mode === 'string' && friend.mode ? friend.mode : null, peerNode: friend.peerNode ?? null, scope: friend.scope,
123
+ author: friend.author ?? null, machine: typeof friend.machine === 'string' && friend.machine ? friend.machine : null,
124
+ certified: typeof friend.certified === 'boolean' ? friend.certified : null, status: statusOf(friend), updatedAt: friend.updatedAt ?? 0 });
125
+ const certifiedOf = channels => {
126
+ const list = channels.some(c => c.status === 'bound') ? channels.filter(c => c.status === 'bound') : channels;
127
+ return list.some(c => c.certified === true) ? true : list.some(c => c.certified === false) ? false : null;
128
+ };
129
+
121
130
  /**
122
- * 好友表(`status.friends`)合成的行:标题是公钥派生的 `昵称 #尾号`(`identityTitles`:同昵称且尾号相撞时向左加位,无昵称的公钥是短码),
123
- * 没有公钥的待互认项用节点名。撞号要和本人、别的电脑上的好友一起比,所以 `titles`(author → 标题,`identityTitles` 的结果)由调用方算好给出。
124
- * 按状态(冲突、待互认、已互认)再按更新时间新的在前排序,同样的输入排出同样的顺序。
131
+ * 好友表(`status.friends`)合成的行:同一台电脑上指向同一完整公钥(author)的通道归并成一个好友,通道逐条放在 `channels`(状态、更新时间新的在前);
132
+ * 没有公钥的待互认通道不与任何条目归并,各自成行。好友状态:任一通道密钥冲突即冲突(不隐藏冲突),否则任一已互认即已互认,其余待互认;
133
+ * 顶层 `node`、`peerNode`、`scope` 取代表通道(第一条状态等于好友状态的通道),`updatedAt` 取各通道最大值。
134
+ * 标题是公钥派生的 `昵称 #尾号`(`identityTitles`:同昵称且尾号相撞时向左加位,无昵称的公钥是短码),没有公钥的待互认项用节点名。
135
+ * 撞号要和本人、别的电脑上的好友一起比,所以 `titles`(author → 标题,`identityTitles` 的结果)由调用方算好给出。
136
+ * 好友行按状态(冲突、待互认、已互认)再按更新时间新的在前排序,同样的输入排出同样的顺序。
125
137
  */
126
138
  export function mergeFriendRows(friends = [], { titles, shortAuthor }) {
127
- const rows = friends.map(friend => ({ node: friend.node, author: friend.author ?? null, short: shortAuthor(friend.author), status: statusOf(friend),
128
- peerNode: friend.peerNode ?? null, scope: friend.scope, updatedAt: friend.updatedAt ?? 0, title: titles.get(friend.author) ?? friend.node }));
129
- return rows.sort((a, b) => RANK[a.status] - RANK[b.status] || b.updatedAt - a.updatedAt || (a.node < b.node ? -1 : a.node > b.node ? 1 : 0));
139
+ const groups = new Map();
140
+ for (const friend of friends) {
141
+ const channel = channelOf(friend), key = channel.author ? `a:${channel.author}` : `n:${channel.node}`;
142
+ if (!groups.has(key)) groups.set(key, []);
143
+ groups.get(key).push(channel);
144
+ }
145
+ const rows = [...groups.values()].map(channels => {
146
+ channels.sort((a, b) => RANK[a.status] - RANK[b.status] || b.updatedAt - a.updatedAt || compare(a.node, b.node));
147
+ const status = channels.some(c => c.status === 'conflict') ? 'conflict' : channels.some(c => c.status === 'bound') ? 'bound' : 'pending';
148
+ const primary = channels.find(c => c.status === status) ?? channels[0], { author } = primary;
149
+ return { node: primary.node, author, short: shortAuthor(author), status, peerNode: primary.peerNode, scope: primary.scope, certified: certifiedOf(channels),
150
+ updatedAt: Math.max(...channels.map(c => c.updatedAt)), title: titles.get(author) ?? primary.node, channels };
151
+ });
152
+ return rows.sort((a, b) => RANK[a.status] - RANK[b.status] || b.updatedAt - a.updatedAt || compare(a.author ?? '', b.author ?? '') || compare(a.node, b.node));
130
153
  }
package/lib/gateway.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  // 自己不建第二份目录库,只在 outbox.json 里留还没发出去的 body(同步成功即释放)。所有会写盘、会外发的动作排成一条队,
3
3
  // 发布、撤回、证书变化引起的冲洗互不交叉。
4
4
  import { identityTitles, shortAuthor } from '@coda-console/protocol/accord';
5
- import { mergeFriendRows, statusOf } from './friends.mjs';
5
+ import { mergeFriendRows } from './friends.mjs';
6
6
  import { MAX_BODY_BYTES, canSkip, canonicalHash, certStateOf, checkId, checkKind, checkPublish, entryKey, holdState, keyOf, retractKey, invalid, isPending, markRejected, markSynced,
7
7
  nextSeq, queuePublish, queueRetract, readOutbox, withState, writeOutbox } from './outbox.mjs';
8
8
  import { readPolicy, setKindPaused } from './policy.mjs';
@@ -154,8 +154,9 @@ export function createGateway(coda, dir) {
154
154
  const outbox = dir ? await readOutbox(dir) : {}, { pausedKinds } = dir ? await readPolicy(dir) : { pausedKinds: [] };
155
155
  const until = accord?.status?.certificate?.until;
156
156
  const friends = Array.isArray(accord?.status?.friends) ? accord.status.friends : [];
157
+ const rows = mergeFriendRows(friends, { titles: new Map(), shortAuthor });
157
158
  const status = { author, certState, ...(Number.isSafeInteger(until) && until >= 0 ? { certUntil: until } : {}),
158
- friendCount: friends.filter(friend => statusOf(friend) === 'bound').length, pendingCount: Object.values(outbox).filter(isPending).length, pausedKinds };
159
+ friendCount: rows.filter(row => row.status === 'bound').length, pendingCount: Object.values(outbox).filter(isPending).length, pausedKinds };
159
160
  if (!stopped) await coda.put({ kind: SOCIAL, key: 'local' }, { spec: { version: 1 }, status });
160
161
  } catch { /* 状态记录下一次动作会再写 */ }
161
162
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName": "好友",
5
5
  "description": "管理 Accord 身份与熟人好友通道,并提供业务无关的好友网关",
6
6
  "icon": { "symbol": "person.2.fill", "color": "blue" },
7
- "version": "0.11.0",
7
+ "version": "0.12.0",
8
8
  "categories": [
9
9
  "Skills 与工具"
10
10
  ],
package/view/app.mjs CHANGED
@@ -5,6 +5,7 @@
5
5
  // 移除好友后留在网络里的节点(status.networkRemovals)显示在分节里,用户点「重试」才读、才删,页面不会自己调用。
6
6
  // 昵称、头像都由 Accord 公钥推出(WebView 标准库 coda-view://lib/v1/accord.js、avatar.mjs),没有可编辑的名片;
7
7
  // 节点名等外来数据一律用 textContent / DOM API 渲染,从不拼 HTML 字符串。
8
+ import { shortAuthor } from 'coda-view://lib/v1/accord.js';
8
9
  import { accordStatusSummary, resolveAvatar } from '../lib/avatar.mjs';
9
10
  import { checked, parseInvite } from '../lib/friends.mjs';
10
11
  import { friendSections, identities, listMembers, memberTitles } from '../lib/view-members.mjs';
@@ -65,6 +66,10 @@ function onChange(m, { type, entry }) {
65
66
  m.entry = entry;
66
67
  m.author = entry.spec?.author ?? null;
67
68
  m.friends = entry.status?.friends ?? [];
69
+ for (const one of gone) {
70
+ if (one.m !== m || m.friends.some(f => f.node === one.node)) continue;
71
+ gone.delete(one); state.busy.delete(one.key); state.notice.delete(one.key);
72
+ }
68
73
  m.loaded = true;
69
74
  draw();
70
75
  }
@@ -318,25 +323,32 @@ async function submitInvite() {
318
323
  // 不同电脑上的 node 可能相同,忙碌与提示按(电脑, node)记。
319
324
  let drawn = []; // 最近一次 draw 的分节,详情按它找当前行
320
325
 
321
- async function handshake(m, row) {
322
- const key = rowKey(m, row.node);
326
+ async function handshake(m, ch) {
327
+ const key = rowKey(m, ch.node);
323
328
  state.busy.add(key); state.notice.set(key, { kind: 'progress', text: '正在互认…' }); draw();
324
329
  let notice;
325
- try { await coda.call(LOCAL, 'handshake', { node: row.node, ...(row.peerNode ? { peerNode: row.peerNode } : {}) }, via(m)); notice = { kind: 'ok', text: '互认完成' }; }
330
+ try { await coda.call(LOCAL, 'handshake', { node: ch.node, ...(ch.peerNode ? { peerNode: ch.peerNode } : {}) }, via(m)); notice = { kind: 'ok', text: '互认完成' }; }
326
331
  catch (e) { notice = { kind: 'error', text: `互认失败:${e.message}` }; }
327
332
  state.notice.set(key, notice); state.busy.delete(key); draw();
328
333
  }
329
- async function remove(m, row) {
330
- const key = rowKey(m, row.node);
334
+ // 移除已成功、却还在等 Accord 推送确认这条通道消失的连接。
335
+ const gone = new Set();
336
+ async function remove(m, ch) {
337
+ const key = rowKey(m, ch.node);
331
338
  state.busy.add(key); state.notice.set(key, { kind: 'progress', text: '正在移除…' }); draw();
332
339
  let failure = null;
333
- try { await coda.call(LOCAL, 'remove', { node: row.node }, via(m)); }
340
+ try { await coda.call(LOCAL, 'remove', { node: ch.node }, via(m)); }
334
341
  catch (e) { failure = { kind: 'error', text: `移除失败:${e.message}` }; }
335
- state.busy.delete(key);
336
- if (failure) state.notice.set(key, failure);
342
+ if (failure) { state.busy.delete(key); state.notice.set(key, failure); }
337
343
  else {
338
- state.notice.delete(key); state.removing = null;
339
- if (state.detail?.key === key) closeDialog();
344
+ if (state.removing === key) state.removing = null;
345
+ // 只剩这一条连接就没有好友可看了;多条时留着弹层,等 Accord 推送变化后画出剩下的连接(最后一条没了,重画时弹层自己关)。
346
+ const open = detailRow();
347
+ const last = open && state.detail.member === m && open.channels.length === 1 && open.channels[0].node === ch.node;
348
+ // 推送还没把这条通道拿掉时,它保持不可操作,免得对已移除的通道再发请求;推送到了(onChange)再清理。
349
+ if (!last && m.friends.some(f => f.node === ch.node)) gone.add({ key, m, node: ch.node });
350
+ else { state.busy.delete(key); state.notice.delete(key); }
351
+ if (last) closeDialog();
340
352
  }
341
353
  draw();
342
354
  }
@@ -344,30 +356,60 @@ const detail = {
344
356
  dialog: makeDialog({ title: '好友', close: '完成', onClose: () => { state.detail = null; state.removing = null; state.menu = null; closePicker(); } }),
345
357
  card: h('div'),
346
358
  info: h('dl', { class: 'facts' }),
359
+ conns: h('section', { class: 'conns' }),
347
360
  share: h('section', { class: 'share' }),
348
361
  actions: h('div', { class: 'actions split' }),
349
362
  notice: h('div'),
350
363
  };
351
- detail.dialog.body.append(h('div', { class: 'stack' }, detail.card, detail.info, detail.share, detail.actions, detail.notice));
352
- const detailRow = () => state.detail && drawn.find(section => section.member === state.detail.member).rows.find(row => row.node === state.detail.node);
364
+ detail.dialog.body.append(h('div', { class: 'stack' }, detail.card, detail.info, detail.conns, detail.share, detail.actions, detail.notice));
365
+ // 详情按公钥跟着好友走;还没有公钥的待互认通道按节点找,互认成功拿到公钥后改按公钥跟,并读出共享。
366
+ function detailRow() {
367
+ const d = state.detail;
368
+ if (!d) return undefined;
369
+ const rows = drawn.find(section => section.member === d.member).rows;
370
+ if (d.author) return rows.find(row => row.author === d.author);
371
+ const found = rows.find(row => row.channels.some(c => c.node === d.node));
372
+ if (found?.author) { d.author = found.author; loadShare(d.member, found); }
373
+ return found;
374
+ }
353
375
  function openDetail(m, row) {
354
- state.detail = { member: m, node: row.node, key: rowKey(m, row.node) }; state.removing = null; state.menu = null;
376
+ state.detail = { member: m, author: row.author, node: row.node }; state.removing = null; state.menu = null;
355
377
  shareOf(m).opsOpen = false;
356
378
  drawDetail();
357
379
  showDialog(detail.dialog);
358
380
  loadShare(m, row);
359
381
  }
360
382
  function fact(label, ...value) { return [h('dt', {}, label), h('dd', { class: 'selectable' }, ...value)]; }
383
+ const copiedKey = (m, row) => rowKey(m, `copy:${row.author}`);
361
384
  async function copyFriendKey(m, row) {
362
- const key = rowKey(m, row.node);
385
+ const key = copiedKey(m, row);
363
386
  try { await coda.copy(row.author); state.notice.set(key, { kind: 'ok', text: '公钥已复制' }); }
364
387
  catch (e) { state.notice.set(key, { kind: 'error', text: `复制失败:${e.message}` }); }
365
388
  draw();
366
389
  }
390
+ // 多条连接时,逐条列出:通道键、机器、范围只在条与条之间有差别时才写出来,否则分不清。
391
+ function connRow(m, row, ch) {
392
+ const key = rowKey(m, ch.node), busy = state.busy.has(key), notice = state.notice.get(key);
393
+ const machines = new Set(row.channels.map(c => c.machine).filter(Boolean)), scopes = new Set(row.channels.map(c => c.scope));
394
+ const sub = [ch.peerNode && ch.node !== ch.peerNode ? ch.node : null, machines.size > 1 && ch.machine ? `机器 @${shortAuthor(ch.machine)}` : null, scopes.size > 1 ? ch.scope : null].filter(Boolean);
395
+ return h('li', { class: 'g-row conn', 'aria-busy': busy ? 'true' : null },
396
+ h('div', { class: 'g-info' }, h('span', { class: 'g-name mono conn-name' }, ch.peerNode ?? ch.node), sub.length ? h('span', { class: 'g-sub conn-sub' }, sub.join(' · ')) : null),
397
+ h('span', { class: `badge ${ch.status}` }, STATUS_TEXT[ch.status]),
398
+ h('div', { class: 'conn-body' },
399
+ ch.status === 'conflict' ? h('p', { class: 'warn-box' }, '对方的密钥与之前互认的不一致,可能换了设备或身份。确认是本人后可「重新互认」,否则建议移除。') : null,
400
+ h('div', { class: 'actions' }, ...(state.removing === key
401
+ ? [h('span', { class: 'secondary' }, '移除这条连接后不再经它同步,确定吗?'), h('span', { class: 'spacer' }),
402
+ h('button', { class: 'btn danger small', type: 'button', disabled: busy, onclick: () => remove(m, ch) }, '确认移除'),
403
+ h('button', { class: 'btn quiet small', type: 'button', onclick: () => { state.removing = null; draw(); } }, '再想想')]
404
+ : [h('button', { class: 'btn quiet small', type: 'button', disabled: busy, onclick: () => handshake(m, ch) }, '重新互认'), h('span', { class: 'spacer' }),
405
+ h('button', { class: 'btn danger small', type: 'button', disabled: busy, onclick: () => { state.removing = key; draw(); } }, '移除…')])),
406
+ notice ? h('p', { class: notice.kind }, notice.text) : null));
407
+ }
367
408
  function drawDetail() {
368
- const row = detailRow(), { member: m, key } = state.detail;
409
+ const row = detailRow(), { member: m } = state.detail;
369
410
  if (!row) return;
370
- const busy = state.busy.has(key), notice = state.notice.get(key);
411
+ const many = row.channels.length > 1, [ch] = row.channels, key = rowKey(m, ch.node);
412
+ const busy = state.busy.has(key), notice = state.notice.get(key), copied = row.author ? state.notice.get(copiedKey(m, row)) : null;
371
413
  detail.dialog.heading.textContent = multi ? `${row.title} · ${m.name}` : row.title;
372
414
  detail.card.replaceChildren(h('div', { class: 'mini-card' }, h('div', { class: 'banner small' }),
373
415
  h('div', { class: 'mini-body row' }, h('span', { class: 'av-ring lg' }, avatar(rowAvatar(row), 'lg')),
@@ -375,19 +417,23 @@ function drawDetail() {
375
417
  h('span', { class: `badge ${row.status}` }, STATUS_TEXT[row.status]))));
376
418
  detail.info.replaceChildren(
377
419
  ...fact('公钥', row.author ? h('span', { class: 'mono key-full' }, row.author) : h('span', { class: 'secondary' }, '密钥未互认'),
378
- row.author ? h('button', { class: 'btn quiet small', type: 'button', onclick: () => copyFriendKey(m, row) }, '复制公钥') : null),
379
- ...fact('节点', h('span', { class: 'mono' }, row.peerNode ?? row.node)),
380
- ...fact('连接', STATUS_TEXT[row.status]));
381
- detail.actions.replaceChildren(...(state.removing === key
420
+ row.author ? h('button', { class: 'btn quiet small', type: 'button', onclick: () => copyFriendKey(m, row) }, '复制公钥') : null,
421
+ copied ? h('span', { class: copied.kind }, copied.text) : null),
422
+ ...(many ? [] : [...fact('节点', h('span', { class: 'mono' }, row.peerNode ?? row.node)), ...fact('连接', STATUS_TEXT[row.status])]));
423
+ detail.conns.hidden = !many;
424
+ detail.conns.replaceChildren(...(many ? [h('h4', { class: 'sub-head' }, '连接', h('span', { class: 'count' }, String(row.channels.length))),
425
+ h('ul', { class: 'glist' }, row.channels.map(c => connRow(m, row, c)))] : []));
426
+ detail.actions.hidden = many;
427
+ detail.actions.replaceChildren(...(many ? [] : state.removing === key
382
428
  ? [h('span', { class: 'secondary' }, '移除后不再同步这位好友,确定吗?'), h('span', { class: 'spacer' }),
383
- h('button', { class: 'btn danger small', type: 'button', disabled: busy, onclick: () => remove(m, row) }, '确认移除'),
429
+ h('button', { class: 'btn danger small', type: 'button', disabled: busy, onclick: () => remove(m, ch) }, '确认移除'),
384
430
  h('button', { class: 'btn quiet small', type: 'button', onclick: () => { state.removing = null; draw(); } }, '再想想')]
385
- : [h('button', { class: 'btn quiet small', type: 'button', disabled: busy, onclick: () => handshake(m, row) }, '重新互认'), h('span', { class: 'spacer' }),
431
+ : [h('button', { class: 'btn quiet small', type: 'button', disabled: busy, onclick: () => handshake(m, ch) }, '重新互认'), h('span', { class: 'spacer' }),
386
432
  h('button', { class: 'btn danger small', type: 'button', disabled: busy, onclick: () => { state.removing = key; draw(); } }, '移除好友…')]));
387
433
  drawShare(m, row);
388
- fill(detail.notice,
434
+ fill(detail.notice, ...(many ? [] : [
389
435
  row.status === 'conflict' ? h('p', { class: 'warn-box' }, '对方的密钥与之前互认的不一致,可能换了设备或身份。确认是本人后可「重新互认」,否则建议移除。') : null,
390
- notice ? h('p', { class: notice.kind }, notice.text) : null);
436
+ notice ? h('p', { class: notice.kind }, notice.text) : null]));
391
437
  }
392
438
 
393
439
  // ---- 共享:授给这位好友的远程执行、好友授给本机的、最近的操作 ----
@@ -406,7 +452,6 @@ const PROXY_STATUS = {
406
452
  // 授出的范围不让选,由对方的身份决定:个人身份授给他名下的机器,机器身份只授给那一台;基座还没给 certified 时不写。
407
453
  const scopeNote = certified => (certified === true ? '授给这个人名下的机器' : certified === false ? '只授给对方那一台机器' : null);
408
454
  const shareOf = m => (m.share ??= { grants: null, problem: null, corrupt: null, clock: 0, writes: 0, touched: 0, reread: false, pending: [], revoking: new Map(), theirs: new Map(), ops: new Map(), targets: null, targetsProblem: null, opsOpen: false, scopeOpen: new Set(), rescoping: new Map(), timer: null });
409
- const certifiedOf = (m, row) => m.friends.find(friend => friend.node === row.node)?.certified;
410
455
  const mergeGrant = (sh, made) => { const all = sh.grants ?? []; sh.grants = all.some(g => g.grant === made.grant) ? all.map(g => (g.grant === made.grant ? made : g)) : [...all, made]; };
411
456
  // 已撤的不显示;撤销中的(名下的调用还在取消)显示。
412
457
  // 能改范围的:还在用的授权(已撤销、已失效、目标不在了的不行)。
@@ -559,7 +604,7 @@ function shareRow({ key, name, sub, subKind, scope, badge, busy, menu }) {
559
604
  onclick: e => { e.stopPropagation?.(); item.run(); } }, item.label, item.note ? h('span', { class: 'menu-note' }, item.note) : null))) : null);
560
605
  }
561
606
  function drawShare(m, row) {
562
- const sh = shareOf(m), scope = scopeNote(certifiedOf(m, row));
607
+ const sh = shareOf(m), scope = scopeNote(row.certified);
563
608
  const mine = [
564
609
  ...(sh.grants ?? []).filter(g => g.friend === row.author && visibleGrant(g)).map(g => {
565
610
  const local = sh.revoking.get(g.grant), re = sh.rescoping.get(g.grant), waiting = re?.unknown, failed = local?.error ?? re?.error;
@@ -576,7 +621,7 @@ function drawShare(m, row) {
576
621
  const their = sh.theirs.get(row.author);
577
622
  const theirRows = (their?.rows ?? []).map(proxy => shareRow({ key: `t:${proxy.key}`, name: proxy.name, scope: scopeView(sh, `t:${proxy.key}`, proxy.restrict), badge: PROXY_STATUS[proxy.status] ?? ['不可用', 'pending'] }));
578
623
  const ops = sh.ops.get(row.author);
579
- const canGrant = row.status === 'bound' && Boolean(row.author) && sh.grants !== null && !sh.corrupt;
624
+ const canGrant = row.channels.some(c => c.status === 'bound') && Boolean(row.author) && sh.grants !== null && !sh.corrupt;
580
625
  fill(detail.share,
581
626
  h('h4', {}, `共享 · ${m.name}`),
582
627
  h('div', {}, h('div', { class: 'sub-head' }, '我授给 TA', h('span', { class: 'spacer' }),
@@ -632,7 +677,7 @@ function closePicker() {
632
677
  function cancelPicker() { if (!picker.ctx?.busy) closePicker(); }
633
678
  function drawPicker() {
634
679
  if (picker.ctx?.stage !== 'list') return;
635
- const { m, row } = picker.ctx, sh = shareOf(m), scope = scopeNote(certifiedOf(m, row));
680
+ const { m, row } = picker.ctx, sh = shareOf(m), scope = scopeNote(row.certified);
636
681
  const taken = new Set([...(sh.grants ?? []).filter(g => g.friend === row.author && visibleGrant(g)).map(g => g.target.id), ...sh.pending.filter(p => p.friend === row.author && p.state !== 'denied').map(p => p.target.id)]);
637
682
  fill(picker.list, sh.targetsProblem ? h('li', { class: 'error g-empty' }, sh.targetsProblem) : sh.targets === null ? emptyRow('正在读取…')
638
683
  : sh.targets.length ? sh.targets.map(target => {
@@ -777,7 +822,7 @@ function dirRow(c, dir, i) {
777
822
  h('button', { class: 'btn quiet small', type: 'button', 'aria-label': `删除第 ${i + 1} 行`, disabled: c.busy, onclick: () => { c.dirs.splice(c.dirs.indexOf(dir), 1); c.problem = null; drawForm(); } }, '删除'));
778
823
  }
779
824
  function drawForm() {
780
- const c = picker.ctx, { m, row, target } = c, modify = Boolean(c.grant), dirsMode = c.mode === 'dirs', scope = scopeNote(certifiedOf(m, row));
825
+ const c = picker.ctx, { m, row, target } = c, modify = Boolean(c.grant), dirsMode = c.mode === 'dirs', scope = scopeNote(row.certified);
781
826
  const option = (mode, label, note, off) => h('label', { class: `opt${c.mode === mode ? ' on' : ''}${off ? ' off' : ''}` },
782
827
  h('input', { type: 'radio', name: 'scope', checked: c.mode === mode, disabled: off || c.busy, onchange: () => { c.mode = mode; c.problem = null; drawForm(); } }),
783
828
  h('span', { class: 'g-info' }, h('span', { class: 'g-name' }, label), h('span', { class: 'g-sub' }, note)));
@@ -930,9 +975,12 @@ function removalBlock(m) {
930
975
  }
931
976
 
932
977
  function friendTile(m, row) {
933
- return h('li', {}, h('button', { class: 'f-tile', type: 'button', 'aria-label': `${row.title},${STATUS_TEXT[row.status]}`, onclick: () => openDetail(m, row) },
978
+ const count = row.channels.length, pending = row.channels.filter(c => c.status === 'pending').length;
979
+ const meta = row.short ? `@${row.short}` : '密钥未互认';
980
+ return h('li', {}, h('button', { class: 'f-tile', type: 'button', 'aria-label': `${row.title},${STATUS_TEXT[row.status]}${count > 1 ? `,${count} 条连接` : ''}`, onclick: () => openDetail(m, row) },
934
981
  avatar(rowAvatar(row), 'sm'),
935
- h('span', { class: 'f-info' }, h('span', { class: 'f-name truncate' }, row.title), h('span', { class: 'f-meta truncate' }, row.short ? `@${row.short}` : '密钥未互认')),
982
+ h('span', { class: 'f-info' }, h('span', { class: 'f-name truncate' }, row.title),
983
+ h('span', { class: 'f-meta truncate' }, count > 1 ? `${meta} · ${count} 条连接${row.status === 'bound' && pending ? `(${pending} 待互认)` : ''}` : meta)),
936
984
  h('span', { class: `badge ${row.status}` }, STATUS_TEXT[row.status])));
937
985
  }
938
986
 
package/view/style.css CHANGED
@@ -165,6 +165,10 @@ details[open] > summary { margin-bottom: 10px; }
165
165
  .g-name { font-weight: 650; }
166
166
  .g-sub { font-size: .85em; color: var(--fg3); }
167
167
  .g-sub.error { color: var(--red); }
168
+ .g-row.conn { flex-wrap: wrap; align-items: flex-start; }
169
+ .conn-name, .conn-sub { overflow-wrap: anywhere; }
170
+ .conn-body { flex: 1 1 100%; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
171
+ .conn-body .warn-box { margin: 0; }
168
172
  .badge.busy { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
169
173
  .badge.busy::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 5px; border-radius: 50%; background: currentColor; animation: pulse 1s ease-in-out infinite; }
170
174
  @keyframes pulse { 50% { opacity: .25; } }