@coda-console/friends 0.8.0 → 0.9.1
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 +22 -5
- package/lib/rpc-holder.mjs +133 -41
- package/lib/rpc-store.mjs +7 -4
- package/main.mjs +6 -5
- package/package.json +4 -1
- package/view/app.mjs +3 -3
package/README.md
CHANGED
|
@@ -16,15 +16,16 @@
|
|
|
16
16
|
- **好友按电脑分节**:每台一节,顺序同视图,节标题是电脑名;节里是这台自己的好友通道(好友关系按机器上的通道登记,在 A 上加的好友 B 上不会自动出现),状态条(好友数、证书状态、待互认与冲突)和「添加好友」也在这一节。接受邀请与随后的互认、好友详情里的重新互认、移除,都发给这一节、这一行所在的电脑。没有好友的电脑也占一节;同一个好友在两台上都加了,就在两节里各出现一次,不合并。读不到的电脑(`unreachable`)节里写明原因,不出「添加好友」。
|
|
17
17
|
- **只有一台时**页面不出现节标题,状态条与「添加好友」仍在身份卡上。
|
|
18
18
|
- **推荐用法**:好友只在一台电脑上加。好友关系登记在那台电脑上,别的电脑不会自动出现这个好友。邀请里的入网码只能用一次,不必在每台上重复加。
|
|
19
|
+
- **要共享别的电脑**:不必在那台上再加一次好友。加了好友的这台作网关,能把同一空间里别的电脑的远程执行逐台授给好友(见下一节「经网关授出别的机器」)。
|
|
19
20
|
- **几台电脑绑定同一个身份、又在同一个空间里时**,其他电脑发布的记录由 Coda 在这几台之间同步,好友从加了他的那台读取(见 Coda 仓库 `docs/peers.md`)。这是 Coda 基座的行为,本插件不另外保证,也不检查同步是否已经完成。
|
|
20
21
|
|
|
21
22
|
## 把远程执行授给好友
|
|
22
23
|
|
|
23
|
-
好友之间可以把一台机器上的 `remote-exec`(协议 `remote-exec/machine@1`)授给对方:对方的 Agent
|
|
24
|
+
好友之间可以把一台机器上的 `remote-exec`(协议 `remote-exec/machine@1`)授给对方:对方的 Agent 经本机的代理记录,在你的机器上执行命令。授出的可以是加好友的这台自己,也可以是同一空间里别的机器(这台作网关)。`remote-exec` 本身不感知好友,签名、验签与转发都在本插件里;没装 `remote-exec` 的机器照常使用好友功能(清单里是可选实现与可选依赖)。
|
|
24
25
|
|
|
25
26
|
### 用法
|
|
26
27
|
|
|
27
|
-
- **授予**:在好友详情的「共享」一节,「我授给 TA
|
|
28
|
+
- **授予**:在好友详情的「共享」一节,「我授给 TA」点「授予…」,选一台机器:列表里先是这台自己,再是同一空间里打开了远程执行的别的机器,都按机器名列出,一次授一台。前提是已互认(已绑定好友通道),并且被授出的那台在 `remote-exec` 里打开了「允许本空间的机器在这台上执行」。
|
|
28
29
|
- **撤销**:授权那一行的菜单选「撤销」。撤销以本机为准,立即生效:还没启动的调用不再启动,已经在跑的发取消,授权先显示「撤销中」,取消在后面跟上,不弹确认。
|
|
29
30
|
- **用好友授给我的**:「TA 授给我」里的每一条是一条代理记录,名字见下面的「代理记录的名字」,同步在你的空间里。会话里像用本机的远程执行一样,对这条记录调用 `exec`;你空间里的别的机器也能用,签名和收回答由持有这条记录的那台机器做。
|
|
30
31
|
- **看别人做了什么**:持有方在「共享」里能看到最近的操作记录(谁、哪条授权、命令摘要与结局)。
|
|
@@ -37,7 +38,7 @@
|
|
|
37
38
|
- **昵称**:与基座的 `AccordNickname` 同一套:32 字节公钥从最高位起每 7 位一组,至多 36 组;0–77 是字母(对 26 取余),78–87 是数字,88–127 是结束(不足 2 位时跳过)。解不出昵称的用公钥前 8 位十六进制。
|
|
38
39
|
- **尾号**:完整尾号是公钥按大端无符号整数写成的十进制,补零到 78 位,记在代理记录的 `tail` 标签里。名字里默认写最后 4 位;本机同一 `<机器名>@<昵称>` 的代理记录最后 4 位也相同时,这几条都写到能互相区分的最短位数。
|
|
39
40
|
- **会话里的 `target`**:可以写 `机器名@昵称`(不撞名时)或 `机器名@昵称#尾号`(尾号从最后一位往前数的任意位数),这要求基座含 coda#3040;更早的基座只认完整名字或记录地址。
|
|
40
|
-
- **机器名**:是持有方自己报的,要能放进标题:含控制字符(C0、DEL、C1
|
|
41
|
+
- **机器名**:是持有方自己报的,要能放进标题:含控制字符(C0、DEL、C1)、换行、双向控制符,或首尾有空白的,调用方不登记这条授权(不替换、不裁剪:改完的名字可能与别的记录相同);授予时被授出的那台机器的名字不合这条,授予当场失败。`@`、`#`、中间的空格、非 ASCII 文字照旧可以。
|
|
41
42
|
- **名字的范围**:名字只在当下在场的记录里判唯一。另一位好友可以专门挖一把昵称相同、末 4 位也相同的钥匙(昵称越短越容易),再授出一台同名机器:两条都在时会被要求带更长的尾号;前一条不在时,后一条就是唯一匹配。基座(含 coda#3040)的保护是:会话开场表里列出过的名字,在这个会话里始终指开场时那条记录,那条没了就报不可用。脚本、Skill、定时任务这类跨会话的引用写记录地址(`coda://…/<UUID>`),地址不会换主人。
|
|
42
43
|
|
|
43
44
|
### 授权的含义
|
|
@@ -48,6 +49,21 @@
|
|
|
48
49
|
- **授给机器身份的好友**(对方没绑个人身份,只装了后端):只授给对方那一台机器。
|
|
49
50
|
- 授权记下授予那一刻核验到的调用方作者。调用方后来绑了个人身份、解绑或换了根,旧授权与代理记录立即停用,要重新授予;持有方这一侧只有机器钥匙变了才停用:绑定、解绑个人身份或换根都不影响它授出去的授权。另外,目标记录删掉了,授权也随之结束(`target_missing`),之后重建同 id 的记录也不会恢复,要重新授予。
|
|
50
51
|
|
|
52
|
+
### 经网关授出别的机器
|
|
53
|
+
|
|
54
|
+
加了好友的这台(网关 A)可以把同一空间里另一台 B 的远程执行授给好友。好友只和 A 互认,请求先到 A,A 核对授权后用 Coda 的跨机调用去调 B;B 不用和好友互认,也不用装好友插件。
|
|
55
|
+
|
|
56
|
+
- **能授出什么**:只有机器自己的 `remote-exec` 记录(本机的,或空间里别的机器自己的),一台一台选;A 能调用的机器不会自动对好友开放。别的好友分享来的代理记录不能再转授,页面不列,授予也会被拒。A 要装着 `remote-exec`,才看得到别的机器的这类记录。
|
|
57
|
+
- **每次核对**:授权记下目标是哪台机器的哪条记录。每次准入和提交前,A 重新核对好友身份、授权没撤、目标仍是那台机器上 `remote-exec` 的那条记录,对不上就拒绝。好友只能用被授予的那条,只开放 `exec`。
|
|
58
|
+
- **B 离线**:授权保留,B 回来后接着能用。空间约 3 分钟没听到 B 才把它记成离线:
|
|
59
|
+
- 已记成离线的:「我授给 TA」里显示「目标离线」,请求在交给 B 之前就被拒,好友当场收到 `target_offline`、效果 none。
|
|
60
|
+
- 还没记成离线的那几分钟:命令照常交出、排在 A 这边等 B。等到「命令时限 + 60 秒」还没结局,A 放弃这次调用,好友收到 `timeout`、效果未知。放弃时 Coda 用取消顶替还没送到 B 的调用,B 回来先收到取消,不会再执行这条命令。
|
|
61
|
+
- **B 被移出空间**:A 读不到 B 的记录,显示「读不到目标」,好友当场收到 `target_unreachable`、效果 none,授权保留;B 回到空间后接着能用。
|
|
62
|
+
- **B 的记录确实没了**(B 关了远程执行、卸了插件):B 仍在空间里而记录已不在,授权随之结束(`target_missing`),之后要重新授予。
|
|
63
|
+
- **撤销**:同本机的授权,A 撤销后立即拒绝新请求,正在 B 上跑的调用经 Coda 的取消结束。
|
|
64
|
+
- **好友那一侧**:B 显示为一台机器,名字是 B 的机器名(`B的机器名@昵称#尾号`);授权与回答仍由 A 的机器钥匙签,好友插件 0.8.0 起就能用,不用升级。
|
|
65
|
+
- **B 的机主看得到什么**:B 上的远程执行只看到来自 A 的调用,看不出是替哪位好友发的;哪位好友、什么命令记在 A 的「最近的操作」里。
|
|
66
|
+
|
|
51
67
|
### 生成与接受邀请
|
|
52
68
|
|
|
53
69
|
- **生成**:在「添加好友」弹层的上半点「生成邀请」(需在 Coda 客户端里打开好友页)。邀请带入网码和**一次性口令** `bindingToken`,24 小时内有效,只能用一次;它是凭据,只显示这一次,关掉弹层就清掉。
|
|
@@ -75,7 +91,8 @@
|
|
|
75
91
|
- **时钟**:两边时钟差超过 2 分钟,或本机时钟大幅回拨,都会拒绝或暂停准入。
|
|
76
92
|
- **断线后变慢**:连接断过一次后,回答可能晚 12 到 45 秒;75 秒内没有「运行中」回执,调用按 `peer_offline`、效果未知失败。
|
|
77
93
|
- **同根的别台机器也能用**:几台电脑绑定同一个身份、又在同一个空间里时,好友授给你的代理,别台机器也看得到、调得动,不必在每台上各自登记。调用经持有这条代理记录的那台转发,那台要在线。能看到是因为空间会同步代理记录,与是否同根无关。
|
|
78
|
-
-
|
|
94
|
+
- **请求被拒时**:授权在、请求方就是被授权人且仍是已绑定的好友时,持有方签回失败的结局,写明原因(如 `revoked`、`target_unreachable`、`target_offline`),效果 none,好友当场知道命令没有执行;这样的回答照常占每分钟的名额。别的请求(没有这条授权、不是好友、超了名额)持有方只记账、不回答,调用方 75 秒内收不到回执,按 `peer_offline`、效果未知失败。
|
|
95
|
+
- 配额:每个好友至多 8 个在途、4 个同时执行、每分钟 30 个新请求;全机 32、8、120。
|
|
79
96
|
|
|
80
97
|
## 社交网关
|
|
81
98
|
|
|
@@ -101,7 +118,7 @@
|
|
|
101
118
|
## 权限与数据边界
|
|
102
119
|
|
|
103
120
|
- `friends/social@1` 的权限组:`read` 管 `friends`、`records`;`publish` 管 `publish`、`retract`、`outbox`。
|
|
104
|
-
- `uses`:`coda/accord@1` 的 `read`(读好友表)、`publish`(网关代别的插件发布)、`manage
|
|
121
|
+
- `uses`:`coda/accord@1` 的 `read`(读好友表)、`publish`(网关代别的插件发布)、`manage`(接受邀请、互认、移除);`coda/machine@1` 的 `read`(别台的目标读不到时,看那台还在不在空间里)。`optionalUses`:`remote-exec/machine@1` 的 `use`(转给本机的远程执行,没装就没有这部分)。
|
|
105
122
|
- 保留种类 `friends/rpc-grant`、`friends/rpc-call`、`friends/rpc-answer`:只有本插件的内部入口能签发与读取,通用网关的发布、撤回、`records`、`outbox` 都不给出。
|
|
106
123
|
- 入网码(`authKey`)是凭据:只在提交时用一次,提交后立即清空输入框,不写入任何文件、日志或页面状态。
|
|
107
124
|
- 节点名等外来数据只当文本渲染(`textContent`),不当指令或 HTML。
|
package/lib/rpc-holder.mjs
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
1
|
+
// 好友签名网关的持有方:把一条 remote-exec/machine@1 记录的 exec 授给一位好友,收好友签名的调用请求(friends/rpc-call),
|
|
2
|
+
// 验过、核对本机授权后调那条记录的 exec,再签回答(friends/rpc-answer)发回去。格式、窗口、配额、恢复以 coda#3011 为准。
|
|
3
|
+
//
|
|
4
|
+
// - 目标可以是本机的记录,也可以是同一空间里别的机器自己的 remote-exec 记录(本机作网关,调用经 Coda 的跨机调用转到那台);逐条授予,
|
|
5
|
+
// 好友分享来的代理记录(provider 是 friends)不能转授。授权记下目标归哪台机器(`target.owner`),每次准入、提交前核对目标仍是那台机器上
|
|
6
|
+
// remote-exec 的那条记录。别台的记录读不到时,那台的机器记录(coda/machine@1)还在才算记录确实没了、授权失效;那台被移出空间或分不清时
|
|
7
|
+
// 只拒不失效。那台离线时目录库留着它的副本,读得到:机器记录已说离线(空间约 3 分钟没听到它)的,准入与提交前就拒绝;还没说离线的那几分钟,
|
|
8
|
+
// 跨机调用排在本机调用内核的发件箱里,到「命令时限 + 余量」由内核放弃(放弃即发取消,取消顶替还没送到的调用信,那台回来先收到取消,不再执行)。
|
|
9
|
+
// - 准入前就拒绝的请求:授权在、请求方就是被授权人、此刻仍是已绑定的好友、本机机器钥匙仍是授权时那把,就照提交前拒绝的同一条路
|
|
10
|
+
// 签回失败终态(原因写明,effects none),对方立刻知道没执行;其余(没有这条授权、不是好友、超了配额)照旧只记账、不回话。
|
|
3
11
|
//
|
|
4
12
|
// - 授权表(rpc-store 的 grants.json)是权威:撤权与失效先落盘、不可逆,之后尚未提交的不再启动,已提交的走「对方发来取消」同一条路径取消;授权记录(friends/rpc-grant)的发与撤
|
|
5
13
|
// 按授权号排成一条队,发不出去等能发了再补,撤回要等原来那把机器钥匙能签时补发。启动后查一次目录,本机机器钥匙签出、授权表里却没有对应有效授权的
|
|
@@ -24,10 +32,11 @@ import { answerDueAt, commandInfo, inflightKey, isCorrupt } from './rpc-store.mj
|
|
|
24
32
|
export { ANSWER_KEEP_MS } from './rpc-store.mjs';
|
|
25
33
|
|
|
26
34
|
const ACCORD = { kind: 'coda/accord@1', id: 'local' };
|
|
27
|
-
const PROVIDER = 'remote-exec';
|
|
35
|
+
const PROVIDER = 'remote-exec', MACHINE_KIND = 'coda/machine@1';
|
|
28
36
|
export const POLL_MS = 15_000;
|
|
29
37
|
// exec 不给 timeout 时 remote-exec 的默认时限(秒);remote-exec 的操作时限比命令时限多 30 秒(630 对 600),收尾用。
|
|
30
|
-
|
|
38
|
+
// 跨机调用的总时限是命令时限加 CALL_GRACE_MS(remote-exec 的 30 秒余量,再留 30 秒给结局送回):到点由内核放弃,排着没送出的不会再执行。
|
|
39
|
+
const DEFAULT_TIMEOUT_S = 120, CALL_GRACE_MS = 60_000;
|
|
31
40
|
// 见过的最大时刻至多每分钟落一次盘。
|
|
32
41
|
const CLOCK_STEP_MS = 60_000;
|
|
33
42
|
// 失效落盘失败后重试的退避:从 1 秒起翻倍,至多 1 分钟。
|
|
@@ -45,8 +54,10 @@ const REASONS = {
|
|
|
45
54
|
machine_changed: '本机的机器钥匙变了,旧钥匙下的授权已停用',
|
|
46
55
|
grantee_changed: '这位好友的签名身份变了,授给旧身份的授权已停用',
|
|
47
56
|
not_friend: '和这位好友的通道已不在',
|
|
48
|
-
target_missing: '
|
|
49
|
-
target_changed: '
|
|
57
|
+
target_missing: '授权的目标记录已不在了',
|
|
58
|
+
target_changed: '授权的目标不再是授权时那台机器上 remote-exec 提供的那条记录',
|
|
59
|
+
target_unreachable: '此刻读不到授权的目标机器上的这条记录(那台不在空间里)',
|
|
60
|
+
target_offline: '授权的目标机器此刻离线',
|
|
50
61
|
expired: '过了最晚启动时刻',
|
|
51
62
|
};
|
|
52
63
|
|
|
@@ -93,8 +104,9 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
93
104
|
async function identity() {
|
|
94
105
|
let accord = null;
|
|
95
106
|
try { accord = await coda.get(ACCORD); } catch { /* 没有 Accord:没有身份 */ }
|
|
96
|
-
// `author`
|
|
97
|
-
return { machine: machineOf(accord), author: accord?.spec?.author ?? null,
|
|
107
|
+
// `author` 是本机此刻的作者(机器钥匙或根),只用来认出本机自己署的请求;`owner` 是本机后端的 ID(本机记录的 owner),用来认出本机的目标。
|
|
108
|
+
return { machine: machineOf(accord), author: accord?.spec?.author ?? null, owner: typeof accord?.owner === 'string' ? accord.owner : null,
|
|
109
|
+
certState: certStateOf(accord), ...friendsOf(accord) };
|
|
98
110
|
}
|
|
99
111
|
// `bound`:此刻绑定有效的好友作者 → 是不是个人作者(好友表的 `certified`,宿主还不写时是 null);个人作者证书过期的不在里面。
|
|
100
112
|
// `listed`:好友表里出现的所有作者(证书过期的仍以原作者列着);好友表读不出时是 null,不拿它判失效。
|
|
@@ -111,14 +123,36 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
111
123
|
async function targetOf({ kind, id }) {
|
|
112
124
|
try { return await coda.get({ kind, id }); } catch (e) { if (e?.code === 'not_found') return null; throw e; }
|
|
113
125
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
126
|
+
// 一条授权的目标此刻怎样:`{ entry, problem }`,`entry` 是读到的记录(没有是 null),`problem` 为 null 是目标仍是授权时那台机器上
|
|
127
|
+
// remote-exec 的那条记录。本机的目标照旧:不在了是 target_missing,换了样子是 target_changed,都让授权失效。
|
|
128
|
+
// 别台的目标:读不到时那台的机器记录还在(还在空间里),才是 target_missing;那台被移出空间(目录库不再跟随它,它的副本连同机器记录一起没了)、
|
|
129
|
+
// 本机此刻没有这个协议、或读到的不是那台的那条,都是 target_unreachable:只拒绝,不失效,那台回来就接着能用。
|
|
130
|
+
// `live`(准入、提交、列出时)另看别台的机器记录:已说离线的是 target_offline,同样只拒不失效。发授权记录时不看,离线不妨碍授出。
|
|
131
|
+
async function targetCheck(grant, me, { live = false } = {}) {
|
|
132
|
+
const here = me?.owner != null && grant.target.owner === me.owner;
|
|
133
|
+
let entry;
|
|
134
|
+
try { entry = await coda.get({ kind: grant.target.kind, id: grant.target.id }); } catch (e) {
|
|
135
|
+
if (e?.code !== 'not_found') throw e;
|
|
136
|
+
// 本机的读不到就是没有;别台的 not_found 是本机没有这个协议(远程执行插件不在),分不清那台的记录在不在。
|
|
137
|
+
if (!here) return { entry: null, problem: 'target_unreachable' };
|
|
138
|
+
entry = null;
|
|
139
|
+
}
|
|
140
|
+
if (entry) {
|
|
141
|
+
// owner 相同就是同一台上的那条(本机的 owner 是本机,别台的副本 owner 是那台)。
|
|
142
|
+
const same = entry.plugin === grant.target.provider && entry.owner === grant.target.owner;
|
|
143
|
+
if (!same) return { entry, problem: here ? 'target_changed' : 'target_unreachable' };
|
|
144
|
+
return { entry, problem: live && entry.local !== true && await machineOffline(entry.owner) ? 'target_offline' : null };
|
|
145
|
+
}
|
|
146
|
+
if (here) return { entry: null, problem: 'target_missing' };
|
|
147
|
+
return { entry: null, problem: await machineInSpace(grant.target.owner) ? 'target_missing' : 'target_unreachable' };
|
|
148
|
+
}
|
|
149
|
+
// 那台机器此刻还在空间里:本机读得到它的机器记录。读的时候出错按「不知道」答 false,调用方据此只拒不失效(不会因读错让授权失效)。
|
|
150
|
+
async function machineInSpace(owner) {
|
|
151
|
+
try { return Boolean(await coda.get({ kind: MACHINE_KIND, id: owner })); } catch { return false; }
|
|
152
|
+
}
|
|
119
153
|
// 授权此刻还能不能用来准入、提交:没撤(撤了的给失效原因)、本机机器钥匙仍是授权时记下的那把、被授权的好友作者还在好友表里、
|
|
120
|
-
//
|
|
121
|
-
const grantProblem = (grant, me,
|
|
154
|
+
// 它的好友绑定此刻有效、目标仍是授权时那台机器上那条 remote-exec 记录(`check` 是 targetCheck 的结果)。读不出本机的机器钥匙(没有 Accord)不算钥匙变了,给 `no_identity`。
|
|
155
|
+
const grantProblem = (grant, me, check) => {
|
|
122
156
|
if (!grant) return 'no_grant';
|
|
123
157
|
if (grant.revokedAt !== undefined) return grant.endedBy ?? 'revoked';
|
|
124
158
|
const pending = pendingEnd(grant);
|
|
@@ -127,7 +161,7 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
127
161
|
if (me.machine !== grant.holder.machine) return 'machine_changed';
|
|
128
162
|
if (granteeGone(grant, me)) return 'grantee_changed';
|
|
129
163
|
if (!me.bound.has(grant.grantee)) return 'not_friend';
|
|
130
|
-
return
|
|
164
|
+
return check?.problem ?? null;
|
|
131
165
|
};
|
|
132
166
|
// 这条授权在不在待落盘的失效里:在就给失效原因。
|
|
133
167
|
function pendingEnd(grant) {
|
|
@@ -155,6 +189,7 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
155
189
|
});
|
|
156
190
|
}
|
|
157
191
|
// 看到机器钥匙变了、被授权的好友换了作者、目标没了:授权就此失效,写进授权表(不等证书),授权记录的撤回留作待补。
|
|
192
|
+
// 不在 ENDING 里的(target_unreachable 等)只拒不失效。
|
|
158
193
|
async function invalidate(grant, problem) {
|
|
159
194
|
if (!grant || grant.revokedAt !== undefined || !ENDING[problem]) return;
|
|
160
195
|
await endGrant(grant.id, ENDING[problem]);
|
|
@@ -222,8 +257,11 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
222
257
|
if (isAuthor(me.machine) && me.machine !== row.holder.machine) row = await endGrant(id, ENDING.machine_changed);
|
|
223
258
|
else if (granteeGone(row, me)) row = await endGrant(id, ENDING.grantee_changed);
|
|
224
259
|
else {
|
|
225
|
-
|
|
226
|
-
if (
|
|
260
|
+
const check = await targetCheck(row, me);
|
|
261
|
+
if (ENDING[check.problem]) row = await endGrant(id, ENDING[check.problem]);
|
|
262
|
+
// 别台的目标此刻读不到:已发出的授权记录原样留着(只拒不失效),那台回来后照常。
|
|
263
|
+
else if (check.problem) return true;
|
|
264
|
+
target = check.entry;
|
|
227
265
|
}
|
|
228
266
|
}
|
|
229
267
|
if (row.revokedAt !== undefined) {
|
|
@@ -344,8 +382,12 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
344
382
|
}
|
|
345
383
|
if (!admitting) return false;
|
|
346
384
|
const grant = await store.getGrant(body.grant);
|
|
347
|
-
const problem = grant && grant.grantee !== author ? 'no_grant' : grantProblem(grant, me, grant ? await
|
|
348
|
-
if (problem) {
|
|
385
|
+
const problem = grant && grant.grantee !== author ? 'no_grant' : grantProblem(grant, me, grant ? await targetCheck(grant, me, { live: true }) : null);
|
|
386
|
+
if (problem) {
|
|
387
|
+
await invalidate(grant, problem);
|
|
388
|
+
if (!(await answerRefusal(record, body, digest, grant, me, problem))) await reject(author, problem);
|
|
389
|
+
return true;
|
|
390
|
+
}
|
|
349
391
|
const window = replayWindow(body.createdAt, body.expiresAt, now());
|
|
350
392
|
if (!window.ok) { await reject(author, window.code); return true; }
|
|
351
393
|
const { verdict } = await store.quota(author);
|
|
@@ -362,6 +404,24 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
362
404
|
return true;
|
|
363
405
|
}
|
|
364
406
|
|
|
407
|
+
// 准入前就拒绝、又该让对方知道的(见文件头):在 store 准入的同一次写入里直接登记成拒绝的终态(同号去重、配额照算),
|
|
408
|
+
// 盘上从来没有可执行的一项;签回答走在途表的老路(之后照常撤回)。
|
|
409
|
+
// 给 true 是已经这样处理了;窗口、输入不合,或配额、表容量不让准入的,给 false,由调用方照旧只记账。先到的取消(没人在等)也不回话。
|
|
410
|
+
async function answerRefusal(record, body, digest, grant, me, problem) {
|
|
411
|
+
const caller = body.caller;
|
|
412
|
+
if (!grant || !REASONS[problem] || grant.grantee !== caller || !me.bound.has(caller) || me.machine !== grant.holder.machine || body.cancel === true || stopped) return false;
|
|
413
|
+
if (!replayWindow(body.createdAt, body.expiresAt, now()).ok) return false;
|
|
414
|
+
const input = rebuildExecInput(body.input);
|
|
415
|
+
if (!input.ok) return false;
|
|
416
|
+
const call = { target: grant.target, input: input.input };
|
|
417
|
+
const refusal = await closing({ caller, request: body.request, grant: grant.id, call }, refused(problem));
|
|
418
|
+
const admitted = await store.admit({ caller, request: body.request, grant: grant.id, digest, key: idempotencyKey(caller, body.request),
|
|
419
|
+
notAfter: body.expiresAt, call, version: record.version, refusal });
|
|
420
|
+
if (!admitted.ok) return false;
|
|
421
|
+
drive(caller, body.request);
|
|
422
|
+
return true;
|
|
423
|
+
}
|
|
424
|
+
|
|
365
425
|
const answerBody = (entry, grant, { state, finishedAt, result, error }) =>
|
|
366
426
|
({ holder: grant.holder.machine, caller: entry.caller, grant: entry.grant, request: entry.request, digest: entry.digest, state, acceptedAt: entry.admittedAt, finishedAt, result, error });
|
|
367
427
|
|
|
@@ -422,7 +482,7 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
422
482
|
if (entry.canceled) return end(entry, canceledOutcome());
|
|
423
483
|
if (clockUnsure()) return null;
|
|
424
484
|
const [me, grant] = await Promise.all([identity(), store.getGrant(entry.grant)]);
|
|
425
|
-
const problem = grantProblem(grant, me, grant ? await
|
|
485
|
+
const problem = grantProblem(grant, me, grant ? await targetCheck(grant, me, { live: true }) : null);
|
|
426
486
|
if (stopped || problem === 'no_identity') return null;
|
|
427
487
|
if (problem) { await invalidate(grant, problem); return end(entry, refused(problem)); }
|
|
428
488
|
// 已过最晚启动时刻:答失败,不签 running、不提交。
|
|
@@ -445,9 +505,9 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
445
505
|
const refused = problem => ({ state: 'failed', error: { code: problem, message: `${REASONS[problem]},命令没有启动`, effects: 'none' } });
|
|
446
506
|
const endedReason = by => by === 'revoked' ? '对方撤销了授权' : REASONS[by];
|
|
447
507
|
const canceledOutcome = by => ({ state: 'canceled', error: { code: 'canceled', message: by ? `${endedReason(by)},命令没有启动` : '调用方取消了这次调用,命令没有启动', effects: 'none' } });
|
|
448
|
-
const interrupted = why => ({ state: 'failed', error: { code: 'interrupted', message: `${why}
|
|
508
|
+
const interrupted = why => ({ state: 'failed', error: { code: 'interrupted', message: `${why};命令可能已经执行,结果不明`, effects: 'unknown' } });
|
|
449
509
|
|
|
450
|
-
//
|
|
510
|
+
// 调那条记录的 exec(别台的由 Coda 转过去),带内核幂等键:重启后再调接上原来的调用、拿到它的结局,不会再执行一遍。
|
|
451
511
|
// 取消之后绝不再用这个幂等键调内核(SDK 没有只查不建的调用,路由期间取消的那次还没登记,再调就会新建、把命令跑起来),结局只按本进程确认得了的写:
|
|
452
512
|
// - 首次调用发出之前就取消了:canceled、效果 none,命令一次也没跑;
|
|
453
513
|
// - 那次调用在中止生效之前自己结束了:照它的结局;
|
|
@@ -460,7 +520,7 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
460
520
|
// 先登记中止的手柄、再读一次:取消落在这之前的,这里看得到;落在之后的,会经手柄中止。
|
|
461
521
|
if ((await store.get(entry.caller, entry.request))?.canceled) controller.abort();
|
|
462
522
|
const { target, input } = entry.call;
|
|
463
|
-
const
|
|
523
|
+
const limit = (input.timeout ?? DEFAULT_TIMEOUT_S) * 1000 + CALL_GRACE_MS;
|
|
464
524
|
let outcome = outcomes.get(key);
|
|
465
525
|
if (outcome === undefined && controller.signal.aborted) {
|
|
466
526
|
// 「没发出」的标记留到终态落盘成功:落盘失败重来时仍签 canceled。重启后接手的不在 `unissued` 里。
|
|
@@ -472,7 +532,7 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
472
532
|
} else if (outcome === undefined) try {
|
|
473
533
|
unissued.delete(key);
|
|
474
534
|
outcome = { state: 'completed', result: await coda.call({ kind: target.kind, id: target.id }, 'exec', input,
|
|
475
|
-
{ id: entry.key, timeout:
|
|
535
|
+
{ id: entry.key, timeout: limit, signal: controller.signal }) };
|
|
476
536
|
} catch (e) {
|
|
477
537
|
const by = (await store.get(entry.caller, entry.request))?.canceledBy;
|
|
478
538
|
// 中止后交回的是中止原因(AbortError),不是原调用的结局;中止前已自己结束的,照它的结局分类。
|
|
@@ -483,6 +543,9 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
483
543
|
// 调用内核确认是取消的才记 canceled;跑完的照实完成,执行端以别的原因失败的(interrupted 等)照实记它自己的错误,拿不到结局的效果记 unknown。
|
|
484
544
|
if (by && ['canceled', 'cancelled'].includes(e?.code)) {
|
|
485
545
|
outcome = { state: 'canceled', error: { code: 'canceled', message: `${endedReason(by)},调用已取消`, effects } };
|
|
546
|
+
} else if (e?.code === 'timeout') {
|
|
547
|
+
// 到了命令时限加余量还没结局(多半是目标机器连不上):内核已放弃并发了取消,还没送到的不会再执行。
|
|
548
|
+
outcome = { state: 'failed', error: { code: 'timeout', message: `命令时限加 ${CALL_GRACE_MS / 1000} 秒内没有结局,已放弃这次调用(目标机器可能连不上);命令可能已经执行,结果不明`, effects } };
|
|
486
549
|
} else outcome = { state: 'failed', error: { code: String(e?.code ?? 'internal'), message: message(e), effects } };
|
|
487
550
|
}
|
|
488
551
|
}
|
|
@@ -510,17 +573,22 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
510
573
|
|
|
511
574
|
// 落终态(先落盘),连同要写进操作记录的那一行一起落:之后中途退出,重启照它补写。已有终态的不改。
|
|
512
575
|
// 耗时用单调时钟,从本进程开始经手它算起(重启后接手的,从接手时算)。
|
|
513
|
-
async function end(entry,
|
|
576
|
+
async function end(entry, outcome) {
|
|
577
|
+
const key = inflightKey(entry.caller, entry.request), { state, ending, row } = await closing(entry, outcome);
|
|
578
|
+
const done = await store.finish(entry.caller, entry.request, { state, ...ending }, row);
|
|
579
|
+
since.delete(key);
|
|
580
|
+
announced.delete(key);
|
|
581
|
+
return done.entry;
|
|
582
|
+
}
|
|
583
|
+
// 终态要落的两样:结局(`ending`:finishedAt 与 result、error)和操作记录的那一行。`entry` 只用到 caller、request、grant 与 call。
|
|
584
|
+
async function closing(entry, { state, result, error }) {
|
|
514
585
|
const finishedAt = now(), key = inflightKey(entry.caller, entry.request), { target, input } = entry.call;
|
|
515
586
|
let name = target.id;
|
|
516
587
|
try { name = (await targetOf(target))?.spec?.name || target.id; } catch { /* 名字只是展示 */ }
|
|
517
588
|
const row = { v: 1, at: finishedAt, request: entry.request, friend: entry.caller, grant: entry.grant, target: { kind: target.kind, id: target.id, name }, op: 'exec',
|
|
518
589
|
command: commandInfo(input.command), outcome: state, ...(error ? { code: error.code } : {}), ...(result && 'exitCode' in result ? { exitCode: result.exitCode } : {}),
|
|
519
590
|
ms: Math.round(monotonic() - (since.get(key) ?? monotonic())) };
|
|
520
|
-
|
|
521
|
-
since.delete(key);
|
|
522
|
-
announced.delete(key);
|
|
523
|
-
return done.entry;
|
|
591
|
+
return { state, ending: { finishedAt, ...(result === undefined ? {} : { result }), ...(error === undefined ? {} : { error }) }, row };
|
|
524
592
|
}
|
|
525
593
|
|
|
526
594
|
// 把随终态落盘的那一行写进操作记录(按调用方 + 请求号幂等),再去掉它。写不进去不吞掉:留在在途项上,下一次扫在途表时补写。
|
|
@@ -612,11 +680,16 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
612
680
|
lastIdentity = current;
|
|
613
681
|
tick({ grants: changed }).catch(() => {});
|
|
614
682
|
}
|
|
615
|
-
//
|
|
683
|
+
// 目标记录变了:本机的没了就地把指向它的授权失效落盘(之后同 id 重建的也不再生效),再去补撤回;公开的 spec 字段或 available 变了就重发它的授权记录。
|
|
684
|
+
// 别台的没了:那台被移出空间时它的副本也一起以 DELETED 交来,所以要那台的机器记录还在、这条也确实还读不到,才失效(见 targetCheck)。
|
|
616
685
|
function onTarget({ type, id, entry } = {}) {
|
|
617
686
|
if (type === 'DELETED') {
|
|
687
|
+
const owner = typeof entry?.owner === 'string' ? entry.owner : null;
|
|
688
|
+
const pointsHere = grant => grant.target.kind === PROTOCOL && grant.target.id === id && (owner === null || grant.target.owner === owner);
|
|
689
|
+
// 别台的:公开内容留着,那台回来时照它比,变了才重发。
|
|
690
|
+
if (entry?.local === false && owner !== null) { remoteGone(id, owner, pointsHere).catch(note); return; }
|
|
618
691
|
availability.delete(id);
|
|
619
|
-
endGrants(`target:${id}`,
|
|
692
|
+
endGrants(`target:${id}`, pointsHere, ENDING.target_missing);
|
|
620
693
|
return;
|
|
621
694
|
}
|
|
622
695
|
const before = availability.get(id), after = JSON.stringify([pickSpec(entry?.spec), entry?.status?.available === true]);
|
|
@@ -625,17 +698,24 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
625
698
|
store.listGrants().then(grants => { for (const grant of grants) if (grant.target.id === id) dirtyGrants.add(grant.id); kick(); }, note);
|
|
626
699
|
}
|
|
627
700
|
|
|
701
|
+
async function remoteGone(id, owner, pointsHere) {
|
|
702
|
+
const check = await targetCheck({ target: { kind: PROTOCOL, id, owner, provider: PROVIDER } }, null);
|
|
703
|
+
if (stopped || check.problem !== 'target_missing') return;
|
|
704
|
+
endGrants(`target:${owner}/${id}`, pointsHere, ENDING.target_missing);
|
|
705
|
+
}
|
|
706
|
+
|
|
628
707
|
// ---- 授予、撤销与列出 ----
|
|
629
708
|
|
|
630
709
|
async function grant({ friend, target } = {}) {
|
|
631
710
|
if (stopped) throw fail('interrupted', '好友网关已停止');
|
|
632
711
|
if (!isAuthor(friend)) throw invalid('friend 须是好友的公钥(ed25519:…)');
|
|
633
|
-
if (!target || typeof target !== 'object' || target.kind !== PROTOCOL || typeof target.id !== 'string' || !target.id) throw invalid(`target
|
|
712
|
+
if (!target || typeof target !== 'object' || target.kind !== PROTOCOL || typeof target.id !== 'string' || !target.id) throw invalid(`target 须是一条 ${PROTOCOL} 记录的 { kind, id }`);
|
|
634
713
|
const entry = await targetOf(target);
|
|
635
|
-
if (!entry) throw fail('not_found',
|
|
636
|
-
|
|
714
|
+
if (!entry) throw fail('not_found', `没有记录 ${target.kind}/${target.id}`);
|
|
715
|
+
// 本机的,或同一空间里别的机器自己的(目录库只跟随空间里的机器,好友的记录不在里面);好友分享来的代理记录 provider 是 friends,在这里拒掉。
|
|
637
716
|
if (entry.plugin !== PROVIDER) throw invalid(`只能授出 ${PROVIDER} 提供的记录,这条是 ${entry.plugin ?? '未知插件'} 的`);
|
|
638
|
-
if (!
|
|
717
|
+
if (typeof entry.owner !== 'string' || !entry.owner) throw invalid('读不出这条记录归哪台机器');
|
|
718
|
+
if (!machineNameOk(entry.spec?.name)) throw invalid('这台机器的名字含控制字符、换行、双向控制符,或首尾有空白,对方不会登记它:请先改名');
|
|
639
719
|
const me = await identity();
|
|
640
720
|
if (!me.bound.has(friend)) throw invalid('这位不是已绑定好友通道的好友');
|
|
641
721
|
if (!isAuthor(me.machine)) throw fail('invalid_state', '读不出本机的机器钥匙,不能授权');
|
|
@@ -647,7 +727,7 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
647
727
|
for (const one of pendingEnds.values()) one.after.add(row.id);
|
|
648
728
|
await settle(row.id);
|
|
649
729
|
}
|
|
650
|
-
return describe(row, me, entry);
|
|
730
|
+
return describe(row, me, { entry, problem: null });
|
|
651
731
|
}
|
|
652
732
|
|
|
653
733
|
async function revoke({ grant: id } = {}) {
|
|
@@ -667,13 +747,17 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
667
747
|
return new Set((await store.listInflight()).filter(entry => entry.state === 'submitted').map(entry => entry.grant));
|
|
668
748
|
}
|
|
669
749
|
|
|
670
|
-
// 一条授权此刻的状态:available(可用)、target_off(目标已关)、target_missing(目标不在)、
|
|
750
|
+
// 一条授权此刻的状态:available(可用)、target_off(目标已关)、target_offline(别台的目标此刻离线,这期间的请求被拒)、target_missing(目标不在)、
|
|
751
|
+
// target_unreachable(别台的目标此刻读不到,授权仍在)、no_identity(读不出本机的机器钥匙)、
|
|
671
752
|
// revoking(已撤或失效,名下已提交的调用还没都落到终态)、revoked(已撤)、machine_changed(本机的机器钥匙变了,旧钥匙下的授权停用)、grantee_changed(这位好友换了签名身份,授给旧身份的停用)。
|
|
672
753
|
// 在待落盘的失效里的,与准入一样当作已失效。本机证书过期不影响这里。
|
|
673
|
-
|
|
754
|
+
// `check` 是 targetCheck 的结果。
|
|
755
|
+
function describe(row, me, check, revoking = new Set()) {
|
|
756
|
+
const target = check?.entry ?? null, problem = check?.problem ?? null;
|
|
674
757
|
const status = row.revokedAt !== undefined ? (revoking.has(row.id) ? 'revoking' : row.endedBy ?? 'revoked') : pendingEnd(row)
|
|
675
758
|
?? (isAuthor(me.machine) && row.holder.machine !== me.machine ? 'machine_changed' : granteeGone(row, me) ? 'grantee_changed'
|
|
676
|
-
:
|
|
759
|
+
: ['target_unreachable', 'target_offline'].includes(problem) ? problem : problem ? 'target_missing' : !isAuthor(me.machine) ? 'no_identity'
|
|
760
|
+
: target.status?.available === true ? 'available' : 'target_off');
|
|
677
761
|
return { grant: row.id, friend: row.grantee, target: { kind: row.target.kind, id: row.target.id, name: target?.spec?.name ?? null },
|
|
678
762
|
createdAt: row.createdAt, ...(row.revokedAt === undefined ? {} : { revokedAt: row.revokedAt }), status };
|
|
679
763
|
}
|
|
@@ -683,10 +767,18 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
683
767
|
let grants = [], revoking = new Set();
|
|
684
768
|
try { grants = await store.listGrants(); revoking = await submittedGrants(); } catch (e) { note(e); if (!isCorrupt(e)) throw e; }
|
|
685
769
|
const rows = [];
|
|
686
|
-
for (const row of grants)
|
|
770
|
+
for (const row of grants) {
|
|
771
|
+
const check = await targetCheck(row, me, { live: row.revokedAt === undefined }).catch(() => ({ entry: null, problem: 'target_unreachable' }));
|
|
772
|
+
rows.push(describe(row, me, check, revoking));
|
|
773
|
+
}
|
|
687
774
|
return { certState: me.certState, admitting: admissionOpen(), corrupt, grants: rows };
|
|
688
775
|
}
|
|
689
776
|
|
|
777
|
+
// 别台的机器此刻离线(它的机器记录的 status.offline,读的时候算)。读不出按不离线:调用另有「命令时限 + 余量」兜底。
|
|
778
|
+
async function machineOffline(owner) {
|
|
779
|
+
try { return (await coda.get({ kind: MACHINE_KIND, id: owner }))?.status?.offline === true; } catch { return false; }
|
|
780
|
+
}
|
|
781
|
+
|
|
690
782
|
function ledger({ limit = 50, friend } = {}) {
|
|
691
783
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 1000) throw invalid('limit 须是 1 到 1000 的整数');
|
|
692
784
|
if (friend !== undefined && !isAuthor(friend)) throw invalid('friend 须是好友的公钥(ed25519:…)');
|
package/lib/rpc-store.mjs
CHANGED
|
@@ -42,7 +42,7 @@ export const isCorrupt = error => error?.code === 'corrupt';
|
|
|
42
42
|
|
|
43
43
|
// ---- 条目的形状 ----
|
|
44
44
|
|
|
45
|
-
// 授权行:`holder.machine`
|
|
45
|
+
// 授权行:`holder.machine` 是授予时本机的机器钥匙(持有方始终以机器出现);`target.owner` 是目标记录所在的后端:本机的,或同一空间里本机作网关授出的别的机器;`granteePerson` 是被授权的好友当时是不是个人作者
|
|
46
46
|
// (好友表的 `certified`,宿主还不写时是 null)。
|
|
47
47
|
const isFlag = value => typeof value === 'boolean';
|
|
48
48
|
// 授权号以外的各项:新授权在 store 里查重没命中才生成授权号,先按这些校验。
|
|
@@ -255,10 +255,13 @@ export function createRpcStore(stateDir, { now = Date.now, newId = randomUUID, o
|
|
|
255
255
|
* `{ ok: true, entry }`,或 `{ ok: false, code }`:`duplicate`(同号同摘要,带原来那一项)、`digest_conflict`(同号不同摘要,原项不动)、
|
|
256
256
|
* `table_full`(实际保存的项已达 4096,清掉可清的之后仍满;不挤掉承担去重或交付的项)、`busy`(带 `limit`、`scope`、`retryAfterMs`)。
|
|
257
257
|
* `canceled: true` 是取消先于请求到达:先留下标记,之后不会再启动。过期 24 小时的旧项顺手清掉;表按行数满了,再清已过期的可清项。
|
|
258
|
+
* `refusal`(`{ state, ending, row }`,同 finish 的终态与那一行操作记录)是准入前就拒绝、要签回终态的:同样去重、算配额,但写进去的就是终态,
|
|
259
|
+
* 不带子调用参数,盘上没有可执行的一刻。
|
|
258
260
|
*/
|
|
259
|
-
const admit = ({ caller, request, grant, digest, key, notAfter, call, canceled, version }) => serial(async () => {
|
|
260
|
-
const at = now(),
|
|
261
|
-
|
|
261
|
+
const admit = ({ caller, request, grant, digest, key, notAfter, call, canceled, version, refusal }) => serial(async () => {
|
|
262
|
+
const at = now(), base = { caller, request, grant, digest, key, notAfter, admittedAt: at, ...(version === undefined ? {} : { version }) };
|
|
263
|
+
const entry = refusal ? { ...base, state: refusal.state, outcome: refusal.ending, ledger: refusal.row }
|
|
264
|
+
: { ...base, state: 'admitted', call, ...(canceled ? { canceled: true, canceledAt: at } : {}) };
|
|
262
265
|
if (!inflightOk(entry) || !call) throw invalid('在途项的各项不合格');
|
|
263
266
|
const entries = purged(await load('inflight')), slot = inflightKey(caller, request), old = entries[slot];
|
|
264
267
|
if (old) return old.digest === digest ? { ok: false, code: 'duplicate', entry: old } : { ok: false, code: 'digest_conflict', entry: old };
|
package/main.mjs
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// coda.call);模块管这几样:
|
|
3
3
|
// - 业务无关的社交网关 friends/social@1(lib/gateway.mjs):别的插件经它读好友、发布与撤回记录,全部透传 coda/accord@1;
|
|
4
4
|
// 发布策略用 `coda self policy.get|policy.setKind` 读写;
|
|
5
|
-
// - 签名网关的持有方(lib/rpc-holder.mjs
|
|
5
|
+
// - 签名网关的持有方(lib/rpc-holder.mjs):把本机或同一空间里别的机器的 remote-exec 记录的 exec 授给好友、转发好友签名的调用,
|
|
6
6
|
// 授权与操作记录用 `coda self grants.list|grants.grant|grants.revoke|ledger.list` 读写。持有方出错不影响社交网关。
|
|
7
7
|
// - 签名网关的调用方(lib/rpc-caller.mjs):把好友授给本机的记录登记成代理记录,接住对它的 exec 转给好友签名执行。调用方出错不影响社交网关与持有方。
|
|
8
|
-
// 好友授给本机的代理记录用 `coda self proxies.list`
|
|
8
|
+
// 好友授给本机的代理记录用 `coda self proxies.list` 读;授予时可选的 remote-exec 记录(本机的与同空间别的机器的)用 `coda self grants.targets` 读。
|
|
9
9
|
// 持有方、调用方的这几样(shared)好友页也经视图消息调用。
|
|
10
10
|
import { createGateway } from './lib/gateway.mjs';
|
|
11
11
|
import { createCaller } from './lib/rpc-caller.mjs';
|
|
@@ -19,7 +19,7 @@ const handles = [];
|
|
|
19
19
|
|
|
20
20
|
export async function activate(coda) {
|
|
21
21
|
const dir = coda.plugin.state;
|
|
22
|
-
//
|
|
22
|
+
// 好友页的「共享」一节用的:持有方的四个操作、调用方的代理记录、可授出的 remote-exec 记录。
|
|
23
23
|
const shared = {
|
|
24
24
|
...Object.fromEntries(HOLDER_ACTIONS.map(name => [name, input => {
|
|
25
25
|
if (!holder) throw new Error('这台机器没有插件状态目录,好友授权存不下');
|
|
@@ -31,8 +31,9 @@ export async function activate(coda) {
|
|
|
31
31
|
if (callerDown) throw new Error(callerDown);
|
|
32
32
|
return caller.list(input);
|
|
33
33
|
},
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
// 本机的在前,然后是同一空间里别的机器自己的;只列 remote-exec 提供的(好友分享来的代理记录 provider 是 friends,不列)。
|
|
35
|
+
'grants.targets': async () => (await coda.list(TARGET_KIND)).filter(entry => entry.plugin === 'remote-exec')
|
|
36
|
+
.map(entry => ({ id: entry.id, name: entry.spec?.name ?? entry.id, os: entry.spec?.os ?? '', user: entry.spec?.user ?? '', available: entry.status?.available === true, local: entry.local === true })),
|
|
36
37
|
};
|
|
37
38
|
coda.views.register('friends', {
|
|
38
39
|
open(view) {
|
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.
|
|
7
|
+
"version": "0.9.1",
|
|
8
8
|
"categories": [
|
|
9
9
|
"Skills 与工具"
|
|
10
10
|
],
|
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
"read",
|
|
22
22
|
"publish",
|
|
23
23
|
"manage"
|
|
24
|
+
],
|
|
25
|
+
"coda/machine@1": [
|
|
26
|
+
"read"
|
|
24
27
|
]
|
|
25
28
|
},
|
|
26
29
|
"optionalUses": {
|
package/view/app.mjs
CHANGED
|
@@ -394,7 +394,7 @@ function drawDetail() {
|
|
|
394
394
|
// 本地先行:授予、撤销先改界面,进行中只显示在那一行的状态位置;模块明确拒绝(refused)就回滚、原因写在那一行;
|
|
395
395
|
// 超时、发不出去这类结果不明的,保持本机的选择,后台每隔几秒重读授权恢复。
|
|
396
396
|
const SHARE_STATUS = {
|
|
397
|
-
available: ['可用', 'bound'], target_off: ['目标已关闭', 'pending'], target_missing: ['目标不在了', 'pending'], no_identity: ['读不出本机身份', 'pending'],
|
|
397
|
+
available: ['可用', 'bound'], target_off: ['目标已关闭', 'pending'], target_missing: ['目标不在了', 'pending'], target_offline: ['目标离线', 'pending'], target_unreachable: ['读不到目标', 'pending'], no_identity: ['读不出本机身份', 'pending'],
|
|
398
398
|
granting: ['授予中', 'busy'], revoking: ['撤销中', 'busy'], machine_changed: ['已停用', 'pending'], grantee_changed: ['已停用', 'pending'],
|
|
399
399
|
};
|
|
400
400
|
const PROXY_STATUS = {
|
|
@@ -595,7 +595,7 @@ function openPicker(m, row) {
|
|
|
595
595
|
picker.dialog.scrim.hidden = false;
|
|
596
596
|
drawPicker();
|
|
597
597
|
const sh = shareOf(m);
|
|
598
|
-
ask(m, 'grants.targets').then(targets => { sh.targets = targets; sh.targetsProblem = null; }, e => { sh.targetsProblem =
|
|
598
|
+
ask(m, 'grants.targets').then(targets => { sh.targets = targets; sh.targetsProblem = null; }, e => { sh.targetsProblem = `读不到远程执行记录:${e.message}`; }).then(drawPicker);
|
|
599
599
|
}
|
|
600
600
|
function closePicker() {
|
|
601
601
|
picker.ctx = null;
|
|
@@ -611,7 +611,7 @@ function drawPicker() {
|
|
|
611
611
|
return h('li', {}, h('button', { class: 'pick', type: 'button', disabled: Boolean(why), onclick: () => { if (!why) grantTo(m, row, target); } },
|
|
612
612
|
h('span', { class: 'g-info' }, h('span', { class: 'g-name truncate' }, target.name), h('span', { class: 'g-sub truncate' }, `${target.os} · ${target.user}`), scope ? h('span', { class: 'g-sub truncate' }, scope) : null),
|
|
613
613
|
why ? h('span', { class: 'why' }, why) : null));
|
|
614
|
-
}) : emptyRow('
|
|
614
|
+
}) : emptyRow('没有可授出的远程执行记录'));
|
|
615
615
|
}
|
|
616
616
|
|
|
617
617
|
// ---- 网络节点 ----
|