ai_co_discuss 0.4.89 → 0.4.91
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/.agents/skills/discuss-host/SKILL.md +1 -1
- package/backend/schema.sql +11 -0
- package/docs/deployment.md +1 -1
- package/docs/en/deployment.md +1 -1
- package/docs/en/runner.md +1 -1
- package/docs/runner.md +1 -1
- package/frontend/locales/en/admin.json +17 -15
- package/frontend/locales/en/backend.json +10 -1
- package/frontend/locales/en/backend_worker.json +6 -1
- package/gateway/direct.mjs +219 -0
- package/gateway/gateway.mjs +4 -0
- package/package.json +1 -1
- package/runner/account_env.mjs +22 -4
- package/runner/admin_cli.mjs +2 -0
- package/runner/admin_panel.mjs +144 -4
- package/runner/device_auth.mjs +14 -3
- package/runner/direct_entry.mjs +164 -0
- package/runner/discussion_launch.mjs +1 -1
- package/runner/discussion_local.mjs +2 -1
- package/runner/discussion_service.mjs +7 -2
- package/runner/expert_prompts.mjs +1 -1
- package/runner/external_client.mjs +4 -2
- package/runner/external_gateway.mjs +11 -5
- package/runner/hosting_setup.mjs +6 -1
- package/runner/i18n_en.mjs +10 -2
- package/runner/relay_channel.mjs +1 -1
- package/runner/remote_launch.mjs +46 -4
- package/web/admin.css +1 -1
- package/web/admin.js +3 -3
- package/web/app.js +38 -22
- package/web/i18n.js +3 -3
- package/web/modern.css +1 -1
- package/web/modern.js +49 -48
|
@@ -24,7 +24,7 @@ description: "AI CoDiscuss 的主持技能,仅主持人调用,且须同时
|
|
|
24
24
|
1. **用户是需求方和最终决策者**:先处理尚未处理的用户留言,再安排他人或收束;遵守用户设定的上限,不自行放宽。(主持人负责理解意图,不替用户做决定。)
|
|
25
25
|
2. **收束前自查**:收束、宣告完成(含 Goal 完成)或关闭定时检查前,对照任务里的 `room_goal` 和用户最近的要求;还有遗留方向就继续安排,或告诉用户还差什么。(一次派活或一个 Goal 做完,不等于房间任务完成。)
|
|
26
26
|
3. **权限由用户授予**:不邀请成员,不开启讨论或 Goal,不扩大工作目录、软件权限或执行额度,派活不超出用户给的范围。唯一例外是任务有 `host_workflows: true`(房主打开了“主持人完整权限”),边界见 [房间控制与恢复](references/control.md)。(扩权与刹车留在用户手里。)
|
|
27
|
-
4. **有工作流先分流**:任务有 `workflow` 字段时,派活或改文件之前先读 `workflow.skill_path`,把请求对照主线和每个 `workflow.sub_workflows` 的 `description`;命中就读它的 SKILL.md
|
|
27
|
+
4. **有工作流先分流**:任务有 `workflow` 字段时,派活或改文件之前先读 `workflow.skill_path`,把请求对照主线和每个 `workflow.sub_workflows` 的 `description`;命中就读它的 SKILL.md 并照做,不问用户要不要用,回答开头用一句话写明走的哪条;都不命中就按普通请求处理,回答里不必说明;写明只在用户要求时用的,用户没要求就不用。(靠临场想起来会漏掉,流程也就形同虚设。)
|
|
28
28
|
5. **不用软件自带的定时、唤醒或后台等待**,也不手动通知已配置的本地成员;要隔一段时间再看进展用 `checkin`。(本轮结束即执行结束,之后回来的结果无法提交;自带唤醒还会和程序投递并发续接同一会话。)
|
|
29
29
|
|
|
30
30
|
## 主持判断
|
package/backend/schema.sql
CHANGED
|
@@ -1122,6 +1122,17 @@ CREATE TABLE IF NOT EXISTS local_machines (
|
|
|
1122
1122
|
seen_at INTEGER NOT NULL DEFAULT 0,
|
|
1123
1123
|
created_at INTEGER NOT NULL
|
|
1124
1124
|
);
|
|
1125
|
+
-- One-time binding tokens a bound computer issues for a hosted account on itself (10 minutes, hash only); a computer
|
|
1126
|
+
-- bound this way is that computer's child and cannot issue tokens of its own (2026-11-19, #5494).
|
|
1127
|
+
CREATE TABLE IF NOT EXISTS machine_setup (
|
|
1128
|
+
token_hash TEXT PRIMARY KEY,
|
|
1129
|
+
parent_id TEXT NOT NULL REFERENCES local_machines(id) ON DELETE CASCADE,
|
|
1130
|
+
created_at INTEGER NOT NULL
|
|
1131
|
+
);
|
|
1132
|
+
CREATE TABLE IF NOT EXISTS machine_parents (
|
|
1133
|
+
machine_id TEXT PRIMARY KEY REFERENCES local_machines(id) ON DELETE CASCADE,
|
|
1134
|
+
parent_id TEXT NOT NULL REFERENCES local_machines(id) ON DELETE CASCADE
|
|
1135
|
+
);
|
|
1125
1136
|
-- A room launch submitted from a device without the local service; the paired computer claims and runs it.
|
|
1126
1137
|
-- The request (with the room's new credentials) is cleared once the launch finishes or fails.
|
|
1127
1138
|
CREATE TABLE IF NOT EXISTS remote_launches (
|
package/docs/deployment.md
CHANGED
|
@@ -175,7 +175,7 @@ npx wrangler deploy --config deploy/entry.wrangler.jsonc
|
|
|
175
175
|
"vars": { "ENTRY_URL": "https://codiscuss-entry.<账号子域>.workers.dev" }
|
|
176
176
|
```
|
|
177
177
|
|
|
178
|
-
接入一台托管电脑:在你(部署线上站点的电脑)的管理面板“概览 →
|
|
178
|
+
接入一台托管电脑:在你(部署线上站点的电脑)的管理面板“概览 → 本机 → 线上网站”点“生成接入码”,填部署配置路径与站点地址后生成(需已登录 wrangler;一次性,再生成会让未用过的作废);把接入码发给托管电脑,在它的“本机 → 线上网站”点“绑定”粘贴,再到“登录入口 → 托管账号入口”打开“经线上网站中转”的开关,它会取得入口地址并启动所需服务(已开启的自有域名不受影响,两者可同时使用;命令行 `codiscuss admin entry join 接入码` 一步完成这些)。托管账号要邀请外部专家时,在“账号”页打开“允许邀请外部专家”,面板自动替该账号绑定,不需要接入码。面板给出的链接带电脑编号(`?m=…`),发给使用者即可。使用者的请求经入口 Worker 和中转到达这台电脑的登录入口,登录、会话与入口保护都在电脑上;Cloudflare 能看到这些往来内容(与自有域名隧道相同),每个页面的请求都计入 Workers 免费额度。
|
|
179
179
|
|
|
180
180
|
## 常见问题
|
|
181
181
|
|
package/docs/en/deployment.md
CHANGED
|
@@ -173,7 +173,7 @@ It gets its own `workers.dev` address (such as `https://codiscuss-entry.<account
|
|
|
173
173
|
"vars": { "ENTRY_URL": "https://codiscuss-entry.<account-subdomain>.workers.dev" }
|
|
174
174
|
```
|
|
175
175
|
|
|
176
|
-
To connect a hosted computer: in the admin panel of your computer (the one that deployed the online site), go to **Overview →
|
|
176
|
+
To connect a hosted computer: in the admin panel of your computer (the one that deployed the online site), go to **Overview → This computer → Online site**, choose **Generate access code**, fill in the deployment config path and site address, and generate it (wrangler must be signed in; the code is single-use, and generating a new one voids unused ones). Send it to the hosted computer, paste it under **This computer → Online site → Bind** there, then turn on **Through the online site** under **Sign-in entry → Hosted account entry**; it fetches the entry address and starts what it needs (an enabled own domain is unaffected and both can be on; `codiscuss admin entry join <code>` does all of this in one step). For a hosted account to invite external experts, turn on **Allow inviting external experts** for it on the Accounts page; the panel binds it for you, with no access code. The link the panel shows carries the computer's ID (`?m=…`); send it to the users. Their requests reach this computer's sign-in entry through the entry Worker and the relay, while sign-in, sessions and entry protection all stay on the computer. Cloudflare can see this traffic (as with a tunnel on your own domain), and every page request counts against the free Workers quota.
|
|
177
177
|
|
|
178
178
|
## Troubleshooting
|
|
179
179
|
|
package/docs/en/runner.md
CHANGED
|
@@ -71,7 +71,7 @@ If you deploy the site yourself, run this once on the machine running your agent
|
|
|
71
71
|
codiscuss local connect https://your-site
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
It binds this computer to the site with a one-time token: generated automatically on the machine that deployed the site (after `wrangler login`); otherwise run `codiscuss token` there first and add `--setup-key TOKEN`. Each token works once. Without the command line: in this computer's management panel, choose Bind under
|
|
74
|
+
It binds this computer to the site with a one-time token: generated automatically on the machine that deployed the site (after `wrangler login`); otherwise run `codiscuss token` there first and add `--setup-key TOKEN`. Each token works once. Without the command line: in this computer's management panel, choose Bind under This computer → Online site and paste the access code generated on the deploying computer (Generate access code in the same place there, or `codiscuss admin entry code`). Inviting external experts also needs this binding. For a hosted account to invite external experts, turn on Allow inviting external experts for it on the Accounts page: with your own domain on, the other computer reaches the account directly through your domain, not the online site; otherwise the panel binds it to the online site for you. Neither needs an access code. The hosted site has no accounts or passwords and keeps no rooms: every device pairs with this computer first, then reads and writes its rooms through the relay, which must be deployed first (see "Relay" in the [deployment guide](deployment.md)). Revoke with `codiscuss local disconnect https://your-site`.
|
|
75
75
|
|
|
76
76
|
### From Other Devices
|
|
77
77
|
|
package/docs/runner.md
CHANGED
|
@@ -85,7 +85,7 @@ Windows 上在终端运行 `codiscuss setup` 时,“安装配置”一步有
|
|
|
85
85
|
codiscuss local connect https://你的站点
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
-
它用一次性绑定令牌把这台电脑绑定到网站:在部署网站的电脑上(已 `wrangler login`)自动生成,否则先在部署网站的电脑上运行 `codiscuss token`,再加 `--setup-key
|
|
88
|
+
它用一次性绑定令牌把这台电脑绑定到网站:在部署网站的电脑上(已 `wrangler login`)自动生成,否则先在部署网站的电脑上运行 `codiscuss token`,再加 `--setup-key 令牌`。每个令牌只能用一次。也可以不用命令行:在这台电脑的管理面板“本机 → 线上网站”点“绑定”,粘贴部署网站的电脑生成的接入码(它的同一处“生成接入码”,或 `codiscuss admin entry code`),一步完成。邀请外部专家也需要先绑定。托管账号要邀请外部专家时,在“账号”页打开该账号的“允许邀请外部专家”:开着自有域名时,对方经你的域名直接连到这个账号,不经线上网站;否则面板自动替它绑定线上网站。两种都不需要接入码。线上网站没有账号和密码,也不保存房间;任何设备都要先与这台电脑配对,再经中转读写电脑上的房间,需先部署中转(见[部署指南](deployment.md)“中转”)。撤销使用 `codiscuss local disconnect https://你的站点`。
|
|
89
89
|
|
|
90
90
|
### 在其他设备上远程控制
|
|
91
91
|
|
|
@@ -146,7 +146,6 @@
|
|
|
146
146
|
"刷新全部": "Refresh all",
|
|
147
147
|
"请求失败({value1})": "Request failed ({value1})",
|
|
148
148
|
"线上网站": "Online site",
|
|
149
|
-
"不需要域名:经共议线上站点中转到这台电脑,手机和外地的电脑都能打开。需要先用接入码接入线上站点。": "No domain needed: relay through a CoDiscuss online site to this computer, accessible from phones and remote computers. Connect to the online site with an access code first.",
|
|
150
149
|
"自有域名": "Own domain",
|
|
151
150
|
"用你托管在 Cloudflare 的域名,经 Cloudflare 隧道连到这台电脑。需要有自己的域名。": "Connect a domain you host on Cloudflare to this computer through a Cloudflare Tunnel. Requires your own domain.",
|
|
152
151
|
"已连接": "Connected",
|
|
@@ -157,8 +156,6 @@
|
|
|
157
156
|
"登录入口启动后隧道随之启动": "The tunnel starts with the sign-in entry",
|
|
158
157
|
"暂时打不开": "Temporarily unavailable",
|
|
159
158
|
"可以访问": "Accessible",
|
|
160
|
-
"已接入 {value1},开启时取得入口地址": "Connected to {value1}; the entry address is obtained when you turn it on",
|
|
161
|
-
"已关闭线上网站": "Online site turned off",
|
|
162
159
|
"已开启自有域名": "Own domain turned on",
|
|
163
160
|
"已关闭自有域名": "Own domain turned off",
|
|
164
161
|
"没有找到 {value1}": "{value1} not found",
|
|
@@ -300,14 +297,8 @@
|
|
|
300
297
|
"未创建": "Not created",
|
|
301
298
|
"保存后创建该文件": "This file will be created when saved",
|
|
302
299
|
"撤销修改": "Discard changes",
|
|
303
|
-
"已开启线上网站": "Online site turned on",
|
|
304
|
-
"托管账号的使用者经共议线上站点访问这台电脑,不需要自有域名": "Hosted account users access this computer through a CoDiscuss online site; no domain of your own needed",
|
|
305
|
-
"已接入 {value1}": "Connected to {value1}",
|
|
306
300
|
"· 入口 {value1}": "· Entry {value1}",
|
|
307
|
-
"。换站点时粘贴新的接入码。": ". Paste a new access code to switch sites.",
|
|
308
301
|
"接入码": "Access code",
|
|
309
|
-
"向为你提供线上站点的人要(自己部署了线上站点的,在下面生成)。只能用一次。": "Ask your online site provider for one (if you host the site yourself, generate one below). Single use only.",
|
|
310
|
-
"接入并开启": "Connect and turn on",
|
|
311
302
|
"生成接入码": "Generate access code",
|
|
312
303
|
"在部署线上站点的电脑上用": "On the computer deploying the online site, use",
|
|
313
304
|
"部署配置": "Deployment config",
|
|
@@ -315,8 +306,6 @@
|
|
|
315
306
|
"站点地址": "Site address",
|
|
316
307
|
"生成": "Generate",
|
|
317
308
|
"复制接入码": "Copy access code",
|
|
318
|
-
"发给托管电脑的操作者,粘贴到它的这个窗口里。只能用一次;再生成一个会让之前没用过的作废。": "Send this to the operator of the hosting computer to paste into this dialog there. Single use only; generating another invalidates unused codes.",
|
|
319
|
-
"线上网站和自有域名隧道一样,Cloudflare 能看到托管账号的往来内容;登录、会话与入口保护仍由这台电脑负责。每个页面的请求都经过 Cloudflare Workers,免费额度适合少量使用者,人多时改用自有域名。": "As with a tunnel using your own domain, Cloudflare can see hosted accounts' traffic over the online site. This computer still handles sign-in, sessions and entry protection. Every page request goes through Cloudflare Workers; the free quota suits a small number of users. Use your own domain for more users.",
|
|
320
309
|
"已加入技能库:{value1}": "Added to skill library: {value1}",
|
|
321
310
|
"{value1} 不是文件夹或 .zip,已跳过": "{value1} is not a folder or .zip; skipped",
|
|
322
311
|
"已从技能库删除 {value1}": "Deleted {value1} from skill library",
|
|
@@ -368,11 +357,8 @@
|
|
|
368
357
|
"绑定": "Bind",
|
|
369
358
|
"解绑": "Unbind",
|
|
370
359
|
"共议服务未运行": "The CoDiscuss service is not running",
|
|
371
|
-
"绑定后,扫码配对过的设备可以在外面使用这台电脑": "Once bound, devices paired by QR code can use this computer from anywhere",
|
|
372
360
|
"共议服务未运行,线上网站暂时连不上这台电脑": "The CoDiscuss service is not running, so the online site cannot reach this computer for now",
|
|
373
361
|
"绑定线上网站": "Bind online site",
|
|
374
|
-
"你部署的共议线上网站,绑定后在本地网页的“设置”里给手机等设备配对": "The CoDiscuss online site you deployed. Once bound, pair phones and other devices under Settings on the local page",
|
|
375
|
-
"绑定令牌": "Binding token",
|
|
376
362
|
"已绑定线上网站": "Online site bound",
|
|
377
363
|
"已解绑线上网站": "Online site unbound",
|
|
378
364
|
"解绑线上网站": "Unbind online site",
|
|
@@ -387,5 +373,21 @@
|
|
|
387
373
|
"{value1} 有新版本": "New version of {value1}",
|
|
388
374
|
"托管账号从这份副本运行。更新共议时会自动同步;Claude Code 等程序单独升级后,在这里同步一次。": "Hosted accounts run from this copy. Updating CoDiscuss syncs it automatically; sync here once after upgrading Claude Code or another program on its own.",
|
|
389
375
|
"登录入口未运行,使用者暂时无法登录": "The sign-in entry is not running, so users cannot sign in for now",
|
|
390
|
-
"
|
|
376
|
+
"已允许该账号邀请外部专家": "This account can now invite external experts",
|
|
377
|
+
"已停止该账号邀请外部专家": "This account can no longer invite external experts",
|
|
378
|
+
"允许邀请外部专家": "Allow inviting external experts",
|
|
379
|
+
"扫码配对过的设备可以在外面使用这台电脑": "Devices paired by QR code can use this computer from elsewhere",
|
|
380
|
+
"需先在“本机 → 线上网站”绑定": "Bind under This computer → Online site first",
|
|
381
|
+
"经线上网站中转": "Through the online site",
|
|
382
|
+
"不需要域名:经共议线上网站中转到这台电脑,手机和外地的电脑都能打开。需要这台电脑已在“本机 → 线上网站”绑定。": "No domain needed: relayed through the CoDiscuss online site to this computer, so phones and computers elsewhere can open it. This computer must be bound under This computer → Online site.",
|
|
383
|
+
"已开启经线上网站中转": "Relay through the online site turned on",
|
|
384
|
+
"已关闭经线上网站中转": "Relay through the online site turned off",
|
|
385
|
+
"其他设备远程使用、邀请外部专家、托管账号经线上网站登录都需要": "Needed for using this computer from other devices, inviting external experts, and hosted accounts signing in through the online site",
|
|
386
|
+
"在部署线上网站的电脑上,为其他电脑生成绑定用的接入码": "On the computer that deployed the online site, make an access code for binding another computer",
|
|
387
|
+
"绑定共议线上网站(形如 https://xxx.pages.dev),不是你的自有域名": "Bind the CoDiscuss online site (like https://xxx.pages.dev), not your own domain",
|
|
388
|
+
"在部署线上网站的电脑上生成(它的管理面板“本机 → 线上网站 → 生成接入码”,或运行 codiscuss admin entry code),只能用一次。就在那台电脑上绑定时,只填站点地址即可。": "Generate it on the computer that deployed the online site (its management panel: This computer → Online site → Generate access code, or run codiscuss admin entry code); each code works once. On that computer itself, the site address alone is enough.",
|
|
389
|
+
"发给要绑定的电脑,在它的管理面板“本机 → 线上网站 → 绑定”里粘贴。只能用一次;再生成一个会让之前没用过的作废。": "Send it to the computer to bind and paste it in its management panel under This computer → Online site → Bind. It works once; generating another voids any unused earlier one.",
|
|
390
|
+
"不需要域名:经共议线上网站中转到这台电脑,手机和外地的电脑都能打开。": "No domain needed: relayed through the CoDiscuss online site to this computer, so phones and computers elsewhere can open it.",
|
|
391
|
+
"打开后,这个账号就能在房间里邀请另一台电脑上的 AI;关闭再打开后,之前加入的外部专家需要重新邀请": "Turned on, this account can invite AI on other computers into its rooms; after turning it off and on again, external experts who joined must be invited again",
|
|
392
|
+
"需要先开启托管账号入口的自有域名,或在“概览 → 本机 → 线上网站”绑定线上网站": "Turn on your own domain for the hosted account entry, or bind an online site under Overview → This computer → Online site, first"
|
|
391
393
|
}
|
|
@@ -816,5 +816,14 @@
|
|
|
816
816
|
"读取总量已达上限": "The total read volume limit has been reached",
|
|
817
817
|
"配额 {key} 须为 1–{limit} 的整数": "Quota {key} must be an integer from 1 to {limit}",
|
|
818
818
|
"需要本房间外部成员的凭证": "This room's external member credential is required",
|
|
819
|
-
"diffs 须为最多 {max_changed_files} 项的列表": "diffs must be a list of at most {max_changed_files} items"
|
|
819
|
+
"diffs 须为最多 {max_changed_files} 项的列表": "diffs must be a list of at most {max_changed_files} items",
|
|
820
|
+
"还有托管账号开着“允许邀请外部专家”,请先在“账号”页关闭": "Some hosted accounts still allow inviting external experts; turn that off on the Accounts page first",
|
|
821
|
+
"这台电脑未绑定线上网站,请在管理面板“本机 → 线上网站”处绑定": "This computer is not bound to an online site. Bind it under This computer → Online site in the management panel.",
|
|
822
|
+
"{value1} 的线上网站版本过旧,请部署方更新线上网站后再试": "The online site at {value1} is too old; ask whoever deploys it to update it, then try again",
|
|
823
|
+
"线上网站没有签发绑定令牌:{value1}": "The online site did not issue a binding token: {value1}",
|
|
824
|
+
"绑定令牌已过期,请重试": "The binding token expired; try again",
|
|
825
|
+
"线上网站没有释放这个账号:{value1}": "The online site did not release this account: {value1}",
|
|
826
|
+
"请先关闭该账号的“允许邀请外部专家”,再更改隔离": "Turn off Allow inviting external experts for this account before changing its isolation",
|
|
827
|
+
"没有建立直连身份": "The direct identity was not created",
|
|
828
|
+
"还有托管账号经自有域名邀请外部专家,请先在“账号”页关闭它们的“允许邀请外部专家”": "Some hosted accounts invite external experts through your own domain; turn off Allow inviting external experts for them on the Accounts page first"
|
|
820
829
|
}
|
|
@@ -82,5 +82,10 @@
|
|
|
82
82
|
"绑定失败(退出码 {value1})": "Binding failed (exit code {value1})",
|
|
83
83
|
"这台电脑已绑定 {value1},请先解绑": "This computer is already bound to {value1}. Unbind it first",
|
|
84
84
|
"这个地址不是共议线上站点:{value1}": "This address is not a CoDiscuss online site: {value1}",
|
|
85
|
-
"托管账号入口的线上网站还开着,请先关闭它": "The hosted accounts' online site is still on. Turn it off first"
|
|
85
|
+
"托管账号入口的线上网站还开着,请先关闭它": "The hosted accounts' online site is still on. Turn it off first",
|
|
86
|
+
"这个电脑编号已绑定,不能用托管账号的令牌改绑": "This computer id is already bound and cannot be rebound with a hosted account's token",
|
|
87
|
+
"托管账号的电脑不能再签发绑定令牌": "A hosted account's computer cannot issue binding tokens",
|
|
88
|
+
"未使用的绑定令牌过多,请稍后再试": "Too many unused binding tokens; try again later",
|
|
89
|
+
"这台电脑绑定的托管账号已达上限 {max} 个": "This computer has reached its limit of {max} bound hosted accounts",
|
|
90
|
+
"这台电脑名下没有这个托管账号": "This computer has no such hosted account"
|
|
86
91
|
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The three addresses an external member's computer uses, answered by the sign-in entry on the owner's own domain for
|
|
3
|
+
* hosted accounts that invite external experts without the online relay (user 2026-11-19, #5588; security #5599):
|
|
4
|
+
*
|
|
5
|
+
* GET /api/machines the accounts reached directly: id and public keys under a neutral name
|
|
6
|
+
* POST /api/machines/<id>/pair a sealed invite redemption, handed to that account's receiver
|
|
7
|
+
* POST /api/machines/<id>/relay a member's sealed request, handed to that account's receiver
|
|
8
|
+
*
|
|
9
|
+
* They are answered only when the request comes in on the owner's domain (its Host), the tunnel is on, and the request
|
|
10
|
+
* carries no live session; everything else goes through the entry as before. What this never does:
|
|
11
|
+
* - pass anything from the account's receiver to the caller but a status and a sealed reply it re-serialises itself, with
|
|
12
|
+
* fixed headers, so an account cannot put a page of its own on the entry's address (#8);
|
|
13
|
+
* - add the entry's handshake, a cookie or the caller's path when calling the receiver: the path is fixed and the
|
|
14
|
+
* member's path travels in the body, so an account that points its `local/direct.json` elsewhere gains nothing (#9);
|
|
15
|
+
* - serve more at once than a few requests per account and in all, nor more redemptions than the limits below (#11, #12).
|
|
16
|
+
* Which computer id belongs to which account is the panel's (`direct-accounts.json` in the administrator's directory).
|
|
17
|
+
*/
|
|
18
|
+
import http from 'node:http';
|
|
19
|
+
import { closeSync, existsSync, lstatSync, openSync, readFileSync, readSync } from 'node:fs';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
|
+
|
|
22
|
+
export const DIRECT_ACCOUNTS_FILE = 'direct-accounts.json';
|
|
23
|
+
const RECEIVER_FILE = join('local', 'direct.json');
|
|
24
|
+
const RECEIVER_PATH = '/direct';
|
|
25
|
+
const RECEIVER_TOKEN_HEADER = 'x-codiscuss-direct';
|
|
26
|
+
const BODY_MAX = 512 * 1024;
|
|
27
|
+
// A member's computer sends its request at once; a slow sender is cut off and only ever holds a cheap reading slot (#5617).
|
|
28
|
+
const READ_TIMEOUT_MS = 5_000;
|
|
29
|
+
const READING_MAX = 64;
|
|
30
|
+
// The receiver file is the account's to write: read only a small one (#5617).
|
|
31
|
+
const RECEIVER_FILE_MAX = 16 * 1024;
|
|
32
|
+
const KEY_PART = /^[A-Za-z0-9_-]{1,64}$/;
|
|
33
|
+
// The online relay holds a request at most this long (backend/updates.mjs RELAY_MAX_WAIT_MS).
|
|
34
|
+
const WAIT_MAX_MS = 80_000;
|
|
35
|
+
const REPLY_MAX = 4 * 1024 * 1024;
|
|
36
|
+
const GLOBAL_CONCURRENT = 16;
|
|
37
|
+
const ACCOUNT_CONCURRENT = 4;
|
|
38
|
+
// Redemptions: per sending address as the online site allows (worker.mjs limit_pairing), and per account in all.
|
|
39
|
+
const PAIR_WINDOW_MS = 10 * 60 * 1000;
|
|
40
|
+
const PAIR_PER_SOURCE = 10;
|
|
41
|
+
const PAIR_PER_ACCOUNT = 40;
|
|
42
|
+
const ID_PATTERN = /^[A-Za-z0-9_-]{16,80}$/;
|
|
43
|
+
const MACHINE_PATTERN = /^[0-9a-f]{32}$/;
|
|
44
|
+
const ROUTE = /^\/api\/machines\/([0-9a-f]{32})\/(pair|relay)$/;
|
|
45
|
+
const HEADERS = { 'Content-Type': 'application/json; charset=utf-8', 'X-Content-Type-Options': 'nosniff', 'Cache-Control': 'no-store' };
|
|
46
|
+
|
|
47
|
+
function answer(response, status, value) {
|
|
48
|
+
response.writeHead(status, HEADERS);
|
|
49
|
+
response.end(JSON.stringify(value));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function read_json(path) {
|
|
53
|
+
try { return existsSync(path) ? JSON.parse(readFileSync(path, 'utf8')) : {}; } catch { return {}; }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The owner's domain the tunnel serves, or '' while the tunnel is off. */
|
|
57
|
+
function direct_host(settings) {
|
|
58
|
+
return settings.tunnel_enabled && settings.tunnel?.host ? String(settings.tunnel.host).toLowerCase() : '';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** One account's receiver as its discussion service published it, refusing a folder that is a link (#9). */
|
|
62
|
+
function read_receiver(home) {
|
|
63
|
+
for (const path of [home, join(home, 'local')]) {
|
|
64
|
+
try { if (lstatSync(path).isSymbolicLink()) return null; } catch { return null; }
|
|
65
|
+
}
|
|
66
|
+
const file = join(home, RECEIVER_FILE);
|
|
67
|
+
let receiver;
|
|
68
|
+
try {
|
|
69
|
+
if (lstatSync(file).isSymbolicLink()) return null;
|
|
70
|
+
// The limit is kept by the read itself, not by a size checked before it that could change in between (#5625).
|
|
71
|
+
const fd = openSync(file, 'r'), buffer = Buffer.alloc(RECEIVER_FILE_MAX + 1);
|
|
72
|
+
let size;
|
|
73
|
+
try { size = readSync(fd, buffer, 0, buffer.length, 0); } finally { closeSync(fd); }
|
|
74
|
+
if (size > RECEIVER_FILE_MAX) return null;
|
|
75
|
+
receiver = JSON.parse(buffer.subarray(0, size).toString('utf8'));
|
|
76
|
+
} catch { return null; }
|
|
77
|
+
const valid = Number.isInteger(receiver.port) && receiver.port > 0 && receiver.port < 65536 && typeof receiver.token === 'string'
|
|
78
|
+
&& /^[0-9a-f]{64}$/.test(receiver.token) && typeof receiver.machine === 'string' && MACHINE_PATTERN.test(receiver.machine);
|
|
79
|
+
return valid ? { port: receiver.port, token: receiver.token, machine: receiver.machine, public_key: public_key(receiver.public_key), sign_key: public_key(receiver.sign_key) } : null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** A P-256 public key rebuilt from its four fields, or null: nothing else the account wrote is passed on (#5617). */
|
|
83
|
+
function public_key(value) {
|
|
84
|
+
if (!value || typeof value !== 'object' || value.kty !== 'EC' || value.crv !== 'P-256' || !KEY_PART.test(String(value.x)) || !KEY_PART.test(String(value.y))) return null;
|
|
85
|
+
return { kty: 'EC', crv: 'P-256', x: value.x, y: value.y };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Read a JSON body up to BODY_MAX within READ_TIMEOUT_MS. */
|
|
89
|
+
function read_body(request) {
|
|
90
|
+
return new Promise((done, fail) => {
|
|
91
|
+
const parts = [];
|
|
92
|
+
let size = 0;
|
|
93
|
+
const timer = setTimeout(() => { request.destroy(); fail(Object.assign(new Error('读取超时'), { status: 408 })); }, READ_TIMEOUT_MS);
|
|
94
|
+
request.on('data', part => {
|
|
95
|
+
size += part.length;
|
|
96
|
+
if (size > BODY_MAX) { clearTimeout(timer); request.destroy(); fail(Object.assign(new Error('请求过大'), { status: 413 })); return; }
|
|
97
|
+
parts.push(part);
|
|
98
|
+
});
|
|
99
|
+
request.on('end', () => { clearTimeout(timer); try { done(JSON.parse(Buffer.concat(parts).toString('utf8'))); } catch { fail(Object.assign(new Error('请求格式无效'), { status: 400 })); } });
|
|
100
|
+
request.on('error', error => { clearTimeout(timer); fail(error); });
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Call one receiver; resolves `{ status, body }`, or null when it could not be reached or did not answer in time. */
|
|
105
|
+
function call_receiver(receiver, payload, timeout_ms) {
|
|
106
|
+
return new Promise(done => {
|
|
107
|
+
const text = JSON.stringify(payload);
|
|
108
|
+
const upstream = http.request({ host: '127.0.0.1', port: receiver.port, path: RECEIVER_PATH, method: 'POST', timeout: timeout_ms,
|
|
109
|
+
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(text), [RECEIVER_TOKEN_HEADER]: receiver.token } }, reply => {
|
|
110
|
+
const parts = [];
|
|
111
|
+
let size = 0;
|
|
112
|
+
reply.on('data', part => { size += part.length; if (size > REPLY_MAX) { reply.destroy(); done(null); } else parts.push(part); });
|
|
113
|
+
reply.on('end', () => { try { done({ status: reply.statusCode, body: JSON.parse(Buffer.concat(parts).toString('utf8')) }); } catch { done(null); } });
|
|
114
|
+
reply.on('error', () => done(null));
|
|
115
|
+
});
|
|
116
|
+
upstream.on('timeout', () => { upstream.destroy(); done(null); });
|
|
117
|
+
upstream.on('error', () => done(null));
|
|
118
|
+
upstream.end(text);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Only a sealed reply in the relay's shape, rebuilt field by field (#8). */
|
|
123
|
+
function sealed_reply(id, body) {
|
|
124
|
+
const response = body?.response;
|
|
125
|
+
if (body?.id !== id || body?.status !== 'done' || !response || typeof response.iv !== 'string' || typeof response.data !== 'string'
|
|
126
|
+
|| response.iv.length > 64 || response.data.length > REPLY_MAX) return null;
|
|
127
|
+
return { id, status: 'done', response: { iv: response.iv, data: response.data, ...(response.encoding === 'gzip' ? { encoding: 'gzip' } : {}) } };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Build the direct handler for one entry. Returns `handle(request, response, signed_in)`, true when it answered the
|
|
132
|
+
* request; `data` is the administrator's directory, `instance_home(data, name)` an account's service directory.
|
|
133
|
+
*/
|
|
134
|
+
export function create_direct({ data, read_accounts, entry_settings, instance_home, now = Date.now }) {
|
|
135
|
+
let active = 0, reading = 0;
|
|
136
|
+
const per_account = new Map(), pairs = new Map();
|
|
137
|
+
|
|
138
|
+
/** Count one redemption against its source and account; false once either is over its limit. */
|
|
139
|
+
function allow_pair(source, name) {
|
|
140
|
+
const at = now();
|
|
141
|
+
const fresh = list => (list || []).filter(time => at - time < PAIR_WINDOW_MS);
|
|
142
|
+
const by_source = fresh(pairs.get(`s:${source}`)), by_account = fresh(pairs.get(`a:${name}`));
|
|
143
|
+
if (by_source.length >= PAIR_PER_SOURCE || by_account.length >= PAIR_PER_ACCOUNT) {
|
|
144
|
+
pairs.set(`s:${source}`, by_source); pairs.set(`a:${name}`, by_account);
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
pairs.set(`s:${source}`, [...by_source, at]); pairs.set(`a:${name}`, [...by_account, at]);
|
|
148
|
+
if (pairs.size > 10_000) for (const [key, list] of pairs) if (!fresh(list).length) pairs.delete(key);
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** The accounts reached directly: id → name, for accounts that exist and are not disabled. */
|
|
153
|
+
function direct_accounts() {
|
|
154
|
+
const accounts = read_accounts(data), mapped = read_json(join(data, DIRECT_ACCOUNTS_FILE));
|
|
155
|
+
return Object.entries(mapped).filter(([id, name]) => MACHINE_PATTERN.test(id) && accounts[name] && !accounts[name].disabled);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return async function handle(request, response, signed_in) {
|
|
159
|
+
if (signed_in) return false;
|
|
160
|
+
const path = new URL(request.url, 'http://entry').pathname;
|
|
161
|
+
const route = ROUTE.exec(path);
|
|
162
|
+
if (!route && path !== '/api/machines') return false;
|
|
163
|
+
// Only these addresses read the entry's settings, so signed-in pages pay nothing for this (#5617).
|
|
164
|
+
const host = direct_host(entry_settings(data));
|
|
165
|
+
if (!host || String(request.headers.host || '').toLowerCase() !== host) return false;
|
|
166
|
+
if (path === '/api/machines') {
|
|
167
|
+
if (request.method !== 'GET') return false;
|
|
168
|
+
const machines = [];
|
|
169
|
+
for (const [id, name] of direct_accounts()) {
|
|
170
|
+
const receiver = read_receiver(instance_home(data, name));
|
|
171
|
+
if (receiver?.machine === id && receiver.public_key && receiver.sign_key) {
|
|
172
|
+
machines.push({ id, name: '托管账号', public_key: receiver.public_key, sign_key: receiver.sign_key, online: true, projects: [], clients: {} });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
answer(response, 200, { machines });
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
if (request.method !== 'POST') { request.resume(); answer(response, 404, { error: '地址不存在' }); return true; }
|
|
179
|
+
const [, machine, kind] = route;
|
|
180
|
+
const name = direct_accounts().find(([id]) => id === machine)?.[1];
|
|
181
|
+
if (!name) { request.resume(); answer(response, 404, { error: '这台电脑尚未连接网站' }); return true; }
|
|
182
|
+
// Cloudflare writes the sending address on the way in through the tunnel.
|
|
183
|
+
const source = String(request.headers['cf-connecting-ip'] || request.socket.remoteAddress || 'unknown');
|
|
184
|
+
if (kind === 'pair' && !allow_pair(source, name)) { request.resume(); answer(response, 429, { error: '配对尝试过于频繁,请稍后再试' }); return true; }
|
|
185
|
+
// The body is announced and small; it is read in a slot of its own, apart from the slots the receiver is called in.
|
|
186
|
+
const length = Number(request.headers['content-length']);
|
|
187
|
+
if (!Number.isInteger(length) || length <= 0 || length > BODY_MAX) { request.resume(); answer(response, length > BODY_MAX ? 413 : 411, { error: '请求须注明长度且不超过上限' }); return true; }
|
|
188
|
+
if (reading >= READING_MAX) { request.resume(); answer(response, 503, { error: '请求过多,请稍后再试' }); return true; }
|
|
189
|
+
reading += 1;
|
|
190
|
+
let body;
|
|
191
|
+
try { body = await read_body(request); } catch (error) { answer(response, error.status || 400, { error: error.message }); return true; }
|
|
192
|
+
finally { reading -= 1; }
|
|
193
|
+
const { id, envelope, wait } = body || {};
|
|
194
|
+
if (typeof id !== 'string' || !ID_PATTERN.test(id) || !envelope || typeof envelope !== 'object') { answer(response, 400, { error: '命令编号无效' }); return true; }
|
|
195
|
+
if (active >= GLOBAL_CONCURRENT || (per_account.get(name) || 0) >= ACCOUNT_CONCURRENT) { answer(response, 503, { error: '请求过多,请稍后再试' }); return true; }
|
|
196
|
+
active += 1;
|
|
197
|
+
per_account.set(name, (per_account.get(name) || 0) + 1);
|
|
198
|
+
try {
|
|
199
|
+
const receiver = read_receiver(instance_home(data, name));
|
|
200
|
+
if (!receiver || receiver.machine !== machine) { answer(response, 200, { id, status: 'offline' }); return true; }
|
|
201
|
+
const timeout = Math.min(Math.max(Number.isInteger(wait) ? wait : 8000, 1000), WAIT_MAX_MS);
|
|
202
|
+
const result = await call_receiver(receiver, { kind, path, credential: String(request.headers['x-codiscuss-device'] || ''), id, envelope }, timeout);
|
|
203
|
+
if (!result) { answer(response, 200, { id, status: 'unknown' }); return true; }
|
|
204
|
+
if (result.status === 200) {
|
|
205
|
+
const reply = sealed_reply(id, result.body);
|
|
206
|
+
reply ? answer(response, 200, reply) : answer(response, 200, { id, status: 'unknown' });
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
// A refusal keeps only its kind; the receiver's own words are not passed on.
|
|
210
|
+
const refusal = { 400: '请求格式无效', 401: '这台设备没有与电脑配对,或配对已失效', 403: '这个入口只接受外部成员的请求', 404: '地址不存在', 413: '请求过大', 503: '请求过多,请稍后再试' };
|
|
211
|
+
const status = refusal[result.status] ? result.status : 502;
|
|
212
|
+
answer(response, status, { error: refusal[status] || '暂时无法处理' });
|
|
213
|
+
return true;
|
|
214
|
+
} finally {
|
|
215
|
+
active -= 1;
|
|
216
|
+
per_account.set(name, per_account.get(name) - 1);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
}
|
package/gateway/gateway.mjs
CHANGED
|
@@ -18,6 +18,7 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
|
18
18
|
import { parseArgs } from 'node:util';
|
|
19
19
|
|
|
20
20
|
import { ENTRY_KEY_PATTERN, verified_connection } from '../runner/entry_client.mjs';
|
|
21
|
+
import { create_direct } from './direct.mjs';
|
|
21
22
|
import { login_page } from './login_page.mjs';
|
|
22
23
|
|
|
23
24
|
const SESSION_COOKIE = 'codiscuss_entry';
|
|
@@ -417,6 +418,8 @@ export function instance_key(data, name) {
|
|
|
417
418
|
export function create_gateway({ data, now = Date.now }) {
|
|
418
419
|
const sessions = load_sessions(data, now());
|
|
419
420
|
const failures = new Map();
|
|
421
|
+
// External members' computers reach hosted accounts on the owner's domain without the online relay (#5588).
|
|
422
|
+
const direct = create_direct({ data, read_accounts, entry_settings, instance_home, now });
|
|
420
423
|
const save_sessions = () => write_json(join(data, SESSIONS_FILE), Object.fromEntries(sessions));
|
|
421
424
|
|
|
422
425
|
/** The account a request's session still grants, or null; a session that no longer grants access is dropped. */
|
|
@@ -462,6 +465,7 @@ export function create_gateway({ data, now = Date.now }) {
|
|
|
462
465
|
return send(response, 303, { Location: LOGIN_PATH, 'Set-Cookie': cookie_header(request, '', 0) });
|
|
463
466
|
}
|
|
464
467
|
const account = account_of(request);
|
|
468
|
+
if (await direct(request, response, Boolean(account))) return;
|
|
465
469
|
// The site asks this to tell a page opened through the entry from one opened at the instance itself.
|
|
466
470
|
if (path === SESSION_PATH && request.method === 'GET') return account ? send_json(response, 200, { signed_in: true }) : send_json(response, 401, { error: '请先登录' });
|
|
467
471
|
if (account) return forward(request, response, account.port, { protected: account.protected === true, key: account.protected === true ? instance_key(data, account.name) : '' });
|
package/package.json
CHANGED
package/runner/account_env.mjs
CHANGED
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
* status the skills installed, the prompt, and whether the layout is complete.
|
|
16
16
|
* skills install the skill folders in <job>/skills/ (replacing a copy of the same name) and remove request.remove.
|
|
17
17
|
* prompt write request.prompt as the system prompt of all three.
|
|
18
|
+
* direct create (request.site, the owner's domain) or remove (request.remove) the direct identity of the service
|
|
19
|
+
* home request.home, with which external members reach this account on that domain; sealed for this user.
|
|
20
|
+
* site bind the service home request.home to the online site request.site with the one-time child token
|
|
21
|
+
* request.setup_key, or remove that binding (request.unbind); the binding file is sealed for this user.
|
|
18
22
|
*/
|
|
19
23
|
import { cpSync, existsSync, linkSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, renameSync, rmSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
20
24
|
import { homedir } from 'node:os';
|
|
@@ -144,15 +148,29 @@ function prompt(request) {
|
|
|
144
148
|
return { ok: true, layout: layout_status() };
|
|
145
149
|
}
|
|
146
150
|
|
|
147
|
-
|
|
151
|
+
/** Bind or unbind this user's service home on the online site; the panel gave a one-time child token. */
|
|
152
|
+
async function site(request) {
|
|
153
|
+
const { bind_machine, save_site_connection } = await import('./discussion_local.mjs');
|
|
154
|
+
if (request.unbind) { save_site_connection(request.home, request.site); return { ok: true }; }
|
|
155
|
+
return { machine: await bind_machine(request.home, request.site, request.setup_key) };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Create or remove this user's direct identity; the panel records which computer id is which account. */
|
|
159
|
+
async function direct(request) {
|
|
160
|
+
const { create_direct_link, remove_direct_link } = await import('./remote_launch.mjs');
|
|
161
|
+
if (request.remove) { remove_direct_link(request.home); return { ok: true }; }
|
|
162
|
+
return { machine: create_direct_link(request.home, request.site).id };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async function main() {
|
|
148
166
|
const [action, job] = process.argv.slice(2);
|
|
149
167
|
const path = join(job, 'request.json');
|
|
150
168
|
const request = existsSync(path) ? JSON.parse(readFileSync(path, 'utf8')) : {};
|
|
151
169
|
// The job folder is the owner's; the request goes when the owner removes it.
|
|
152
170
|
try { rmSync(path, { force: true }); } catch { /* removed with the job folder */ }
|
|
153
|
-
const run = { init, status, skills: () => skills(job, request), prompt }[action];
|
|
171
|
+
const run = { init, status, skills: () => skills(job, request), prompt, site, direct }[action];
|
|
154
172
|
if (!run) throw new Error(`未知操作:${action}`);
|
|
155
|
-
process.stdout.write(`${JSON.stringify(run(request))}\n`);
|
|
173
|
+
process.stdout.write(`${JSON.stringify(await run(request))}\n`);
|
|
156
174
|
}
|
|
157
175
|
|
|
158
|
-
|
|
176
|
+
main().catch(error => { process.stdout.write(`${JSON.stringify({ error: error.message })}\n`); process.exitCode = 1; });
|
package/runner/admin_cli.mjs
CHANGED
|
@@ -67,6 +67,7 @@ export const HELP = t(`用法:codiscuss admin <命令> [参数](与管理面
|
|
|
67
67
|
中途失败时解决后重新执行同一命令,从缺少的步骤接着做
|
|
68
68
|
account start|stop|disable|enable|remove|password <名>
|
|
69
69
|
account isolate|unisolate|protect|unprotect <名>
|
|
70
|
+
account external|unexternal <名> 允许或停止该账号邀请外部专家(自动替它绑定这台电脑绑定的线上网站)
|
|
70
71
|
|
|
71
72
|
命令行登录(目标 owner 为管理员自己,否则为托管账号名)
|
|
72
73
|
login status <目标> 各程序的登录状态,以及每个程序可用的登录方式
|
|
@@ -151,6 +152,7 @@ async function account_command(call, [action, name], values) {
|
|
|
151
152
|
need(name, t('account {value1} <名>', { value1: action }));
|
|
152
153
|
if (action === 'add') return add_account(call, name, { isolate: !values['no-isolate'], start: !values['no-start'] });
|
|
153
154
|
if (action === 'protect' || action === 'unprotect') return call(`accounts/${name}/protect`, { on: action === 'protect' });
|
|
155
|
+
if (action === 'external' || action === 'unexternal') return call(`accounts/${name}/external`, { on: action === 'external' });
|
|
154
156
|
if (!ACCOUNT_ACTIONS[action]) throw new Error(HELP);
|
|
155
157
|
return call(`accounts/${name}/${ACCOUNT_ACTIONS[action]}`, {});
|
|
156
158
|
}
|