ai_co_discuss 0.5.39 → 0.5.40

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.
@@ -11,7 +11,7 @@ import { spawn, spawnSync } from 'node:child_process';
11
11
  import { randomBytes } from 'node:crypto';
12
12
  import { closeSync, copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, openSync, realpathSync, readdirSync, readFileSync, readSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
13
13
  import http from 'node:http';
14
- import { panel_clean, panel_storage, panel_repair } from './admin_maintenance.mjs';
14
+ import { panel_clean, panel_clear_attachments, panel_room_attachments, panel_storage, panel_repair } from './admin_maintenance.mjs';
15
15
  import { homedir, tmpdir } from 'node:os';
16
16
  import tls from 'node:tls';
17
17
  import { dirname, extname, join, resolve } from 'node:path';
@@ -23,8 +23,9 @@ import { account_home, add_account, data_home, entry_settings, entry_status, ins
23
23
  import { signed_site_url, site_fetch, verified_connection } from './entry_client.mjs';
24
24
  import { API_PROVIDERS, save_api_key } from './discussion_api.mjs';
25
25
  import { STT_PROVIDERS, TTS_PROVIDERS } from './tts_providers.mjs';
26
- import { ensure_tunnel, start_tunnel_setup, tunnel_setup_state, tunnel_status } from './hosting_tunnel.mjs';
27
- import { machine_links } from './remote_launch.mjs';
26
+ import { ensure_tunnel, stop_tunnel, start_tunnel_setup, tunnel_setup_state, tunnel_status } from './hosting_tunnel.mjs';
27
+ import { RELAY_REGIONS } from './device_auth.mjs';
28
+ import { machine_links, save_machine_links } from './remote_launch.mjs';
28
29
  import { read_relay_health, request_relay_reconnect } from './relay_health.mjs';
29
30
  import { instance_recovery } from './instance_recovery.mjs';
30
31
  import { mark_backup_release, reserve_project_root, set_project_migration } from '../gateway/gateway.mjs';
@@ -68,6 +69,8 @@ const UPDATE_STALE_MS = 10 * 60 * 1000;
68
69
  const UPDATE_FINISH_CHECK_MS = 3000;
69
70
  const OWNER_ENV_TIMEOUT_MS = 120_000;
70
71
  // How often the panel makes sure the entry's tunnel runs as set, and how long an update waits for the entry to be back.
72
+ const TUNNEL_CONNECT_MS = 30_000;
73
+ const TUNNEL_POLL_MS = 500;
71
74
  const TUNNEL_CHECK_MS = 60_000;
72
75
  const ENTRY_BACK_MS = 15_000;
73
76
  // How long the panel waits for the relay's entry Worker to answer whether it is reachable.
@@ -763,6 +766,7 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
763
766
  login_status, apply_login, logout, start_login, login_progress, submit_login, cancel_login, install_runtime, prepare_account, account_env, account_skills, account_workflows, owner_env, owner_skills, shared_cli_state,
764
767
  save_api_key, list_keys, remove_key, use_shared_programs, service_overview, run_owner_service, latest_version, check_package, begin_update,
765
768
  set_account_external, reconcile_external, autostart_enabled, set_autostart, entry_overview, start_entry, stop_entry, keep_tunnel, start_tunnel_setup, set_entry_way, set_relay_url, connect_site, make_access_code, join_relay, protect_account, start_verified, hand_over: () => {}, ...ops };
769
+ let reconnecting_tunnel;
766
770
  const hosts = new Set([`127.0.0.1:${port}`, `localhost:${port}`]);
767
771
  const recovery = instance_recovery(data, { wanted: name => wanted_port(data, name, ops.instance_flag_set || instance_flag_set),
768
772
  probe: ops.instance_state || instance_state, start: name => op.start_verified(data, name), now: ops.now,
@@ -787,11 +791,13 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
787
791
  if (path === '/api/storage' && method === 'GET') return panel_storage(data, site_url(data));
788
792
  if (path === '/api/storage/clean' && method === 'POST') return panel_clean(data, site_url(data), body);
789
793
  if (path === '/api/storage/repair' && method === 'POST') return panel_repair(data, site_url(data), body);
794
+ if (path === '/api/storage/attachments' && method === 'POST') return panel_room_attachments(site_url(data), body);
795
+ if (path === '/api/storage/attachments/clear' && method === 'POST') return panel_clear_attachments(site_url(data), body);
790
796
  if (method === 'GET' && section === 'state') {
791
797
  const windows = process.platform === 'win32';
792
798
  const service = op.service_overview(data), bound = bound_site(data);
793
799
  const restarts = hosting ? recovery.status() : {};
794
- return { hosting, version: VERSION, service, online_site: bound?.site || '', platform: process.platform,
800
+ return { hosting, version: VERSION, service, online_site: bound?.site || '', relay_region: bound?.region ?? 'apac', platform: process.platform,
795
801
  relay_health: read_relay_health(data, bound, service.running && service.pid),
796
802
  launcher: windows && existsSync(launcher_path(data)), autostart: windows && op.autostart_enabled(), login_methods: LOGIN_METHODS, providers: API_PROVIDERS,
797
803
  ...(hosting ? { accounts: (await op.list_accounts(data)).map(item => ({ ...item, last_restart: restarts[item.name] })), clis: op.shared_cli_state(), entry: await op.entry_overview(data, { reach: false }) }
@@ -856,6 +862,20 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
856
862
  // The owner's own online site: bound, checked and left here whether or not this computer hosts accounts.
857
863
  if (method === 'POST' && section === 'site' && name === 'connect') { const bound = await bind_online_site(data, body, op.connect_site); after_change(); return bound; }
858
864
  if (method === 'POST' && section === 'site' && name === 'disconnect') { const left = await disconnect_site(data); after_change(); return left; }
865
+ if (section === 'site' && name === 'region' && ['GET', 'POST'].includes(method)) {
866
+ const bound = bound_site(data);
867
+ if (!bound) throw panel_error('尚未绑定线上网站');
868
+ if (method === 'GET') return { region: bound.region };
869
+ if (!RELAY_REGIONS.includes(body.region)) throw panel_error('中转地区无效');
870
+ if (bound.region === body.region) return { region: bound.region };
871
+ const links = machine_links(data);
872
+ links.sites[bound.site].relay_region = body.region;
873
+ save_machine_links(data, links);
874
+ const service = op.service_overview(data);
875
+ if (service.pid) request_relay_reconnect(data, { ...bound, wait_region: body.region }, service.pid);
876
+ after_change();
877
+ return { region: body.region };
878
+ }
859
879
  if (method === 'POST' && section === 'site' && name === 'reconnect') {
860
880
  const bound = bound_site(data), service = op.service_overview(data);
861
881
  if (!bound) throw panel_error('尚未绑定线上网站');
@@ -892,6 +912,10 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
892
912
  if (method === 'POST' && section === 'site' && name === 'code') return op.make_access_code(data, body);
893
913
  if (method === 'POST' && section === 'relay' && name === 'join') return op.join_relay(data, body.code);
894
914
  // The outside address: a Cloudflare tunnel set up by a job of its own (it waits for the owner in the browser).
915
+ if (method === 'POST' && section === 'tunnel' && name === 'reconnect') {
916
+ reconnecting_tunnel ??= reconnect_tunnel(data).finally(() => { reconnecting_tunnel = null; });
917
+ return reconnecting_tunnel;
918
+ }
895
919
  if (section === 'tunnel' && name === 'setup') {
896
920
  if (method === 'GET') return tunnel_setup_state(data);
897
921
  if (method === 'POST') return op.start_tunnel_setup(data, body.host, body.name);
@@ -1008,6 +1032,23 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
1008
1032
  }
1009
1033
 
1010
1034
  /** The account entry as the hosting page shows it: whether it runs, its loopback port and the address customers open. */
1035
+ /** Restart only cloudflared and return the final readiness probe. */
1036
+ async function reconnect_tunnel(data) {
1037
+ const entry = await entry_status(data);
1038
+ const { tunnel, tunnel_enabled } = entry_settings(data);
1039
+ if (!tunnel) throw panel_error('请先配置自有域名');
1040
+ if (!tunnel_enabled) throw panel_error('请先开启自有域名');
1041
+ if (!entry.running) throw panel_error('请先启动登录入口');
1042
+ stop_tunnel(data);
1043
+ await ensure_tunnel(data, tunnel, entry.port);
1044
+ const deadline = Date.now() + TUNNEL_CONNECT_MS;
1045
+ while (true) {
1046
+ const status = await tunnel_status(data);
1047
+ if (status.connected || Date.now() >= deadline) return status;
1048
+ await new Promise(resolve => setTimeout(resolve, TUNNEL_POLL_MS));
1049
+ }
1050
+ }
1051
+
1011
1052
  /** Keep the entry's tunnel as the settings say: running while hosting is on and the entry is meant to run. */
1012
1053
  function keep_tunnel(data) {
1013
1054
  const { tunnel, port, running, tunnel_enabled } = entry_settings(data);
@@ -1017,7 +1058,7 @@ function keep_tunnel(data) {
1017
1058
  /** The online site this computer is bound to (`codiscuss local connect`) and its id there, or null. */
1018
1059
  function bound_site(data) {
1019
1060
  const [site, link] = Object.entries(machine_links(data).sites || {}).find(([, item]) => item?.id && item?.private_key) || [];
1020
- return site ? { site, machine: link.id } : null;
1061
+ return site ? { site, machine: link.id, region: RELAY_REGIONS.includes(link.relay_region) ? link.relay_region : 'apac' } : null;
1021
1062
  }
1022
1063
 
1023
1064
  /** Ask the relay's entry Worker whether it is one and whether this computer is connected to it. */
@@ -10,6 +10,8 @@ import { join } from 'node:path';
10
10
  import { atomic_json } from './files.mjs';
11
11
  import { b64url, from_b64url, verify_assertion, verify_registration } from './webauthn.mjs';
12
12
 
13
+ // The site enforces the matching list in backend/worker.mjs.
14
+ export const RELAY_REGIONS = ['auto', 'apac', 'apac-ne', 'apac-se', 'wnam', 'enam', 'weur', 'eeur', 'oc', 'sam', 'afr', 'me'];
13
15
  const DEVICES_FILE = 'devices.json';
14
16
  // What other devices did here: trust changes and every remote write, never content. Shown in the device list, so an
15
17
  // unexpected entry (a device you did not add, a write you did not make) can be noticed and revoked.
@@ -247,11 +249,12 @@ export async function signed_device_list(home, link, now = Date.now(), externals
247
249
  ...externals.map(({ id, x, y, room, expires_at }) => ({ id, x, y, kind: 'external', room, expires_at }))];
248
250
  // An unchanged list keeps its signature and issued_at, so the heartbeat that carries it is the same each time and
249
251
  // the website neither rewrites it nor wakes the relay (2026-11-19, #5500); issued_at is when the content last changed.
250
- const content = JSON.stringify({ machine: link.id, devices: listed });
252
+ const region = RELAY_REGIONS.includes(link.relay_region) ? link.relay_region : 'apac';
253
+ const content = JSON.stringify({ machine: link.id, relay_region: region, devices: listed });
251
254
  const cache_key = [home, link.id, link.sign_private_key?.x || ''].join('|');
252
255
  const cached = signed_lists.get(cache_key);
253
256
  if (cached?.content === content) return cached.signed;
254
- const body = JSON.stringify({ machine: link.id, issued_at: Math.max(now, (cached?.issued_at || 0) + 1), devices: listed });
257
+ const body = JSON.stringify({ machine: link.id, relay_region: region, issued_at: Math.max(now, (cached?.issued_at || 0) + 1), devices: listed });
255
258
  const key = await crypto.subtle.importKey('jwk', link.sign_private_key, { name: 'ECDSA', namedCurve: 'P-256' }, false, ['sign']);
256
259
  const signature = await crypto.subtle.sign({ name: 'ECDSA', hash: 'SHA-256' }, key, new TextEncoder().encode(body));
257
260
  const signed = { body, signature: b64url(new Uint8Array(signature)) };
@@ -341,6 +341,8 @@ export async function request_attachments(config, execution, member_directory =
341
341
  const number = Number.isInteger(file.number) ? file.number : index + 1;
342
342
  const entry = { message_id, number, placeholder: attachment_placeholder(file, number), file_name: file.file_name,
343
343
  content_type: file.content_type, size: file.size, id: file.id, path: '' };
344
+ // The owner freed this file's bytes; say so instead of failing a download.
345
+ if (file.cleared_at) { entry.error = '附件已被房主清理,原文件不可用'; result.push(entry); continue; }
344
346
  try { entry.path = await save_attachment(config, member_directory, execution.id, message_id, entry, file.sha256); }
345
347
  catch (error) { entry.error = error.message; }
346
348
  result.push(entry);
@@ -203,6 +203,9 @@ export async function ensure_tunnel(data, tunnel, port, want = true) {
203
203
  mkdirSync(data, { recursive: true });
204
204
  writeFileSync(path, config);
205
205
  const metrics = await free_port();
206
+ // Another caller may have started the same tunnel while the metrics port was being allocated.
207
+ const concurrent = read_state(data);
208
+ if (concurrent?.pid && alive(concurrent.pid)) return 'running';
206
209
  const log = openSync(join(data, LOG_FILE), 'a');
207
210
  // Detached and outside the package folder: it runs on after the panel, and never holds a folder npm replaces.
208
211
  const child = spawn(cloudflared, ['tunnel', '--config', path, '--metrics', `127.0.0.1:${metrics}`, 'run', tunnel.name],
@@ -1,5 +1,9 @@
1
1
  /** English CLI strings. */
2
2
  export default {
3
+ "请先配置自有域名": "Configure the domain first.",
4
+ "请先开启自有域名": "Enable the domain first.",
5
+ "请先启动登录入口": "Start the sign-in entry first.",
6
+ "中转地区无效": "Invalid relay region",
3
7
  "analytics 查看全房间协作统计": "analytics Show collaboration statistics across rooms",
4
8
  "用法:codiscuss analytics [--range today|7d|30d|all] [--scope all|current] [--from YYYY-MM-DD --to YYYY-MM-DD] [--json]": "Usage: codiscuss analytics [--range today|7d|30d|all] [--scope all|current] [--from YYYY-MM-DD --to YYYY-MM-DD] [--json]",
5
9
  "需要管理员身份": "Administrator access required",
@@ -39,6 +43,8 @@ export default {
39
43
  " account migrate-data <名> --project-data-root <目录> 停止实例并迁移项目数据": " account migrate-data <name> --project-data-root <path> Stop the instance and move project data",
40
44
  " account add <名> --project-data-root <目录> 将新账号的项目、工作区和成员草稿放在指定目录": " account add <name> --project-data-root <path> Store a new account's projects, workspace and member drafts in this directory",
41
45
  "存储清理范围无效": "Invalid storage cleanup scope",
46
+ "附件请求失败(HTTP {status})": "Attachment request failed (HTTP {status}).",
47
+ " storage attachments [ROOM [clear ID... --confirm]] 按房间查看附件占用、列出某房间附件或清理所选附件原件": " storage attachments [ROOM [clear ID... --confirm]] Show attachment usage by room, list one room's attachments, or clear the chosen originals",
42
48
  "深度修理须同时指定 logs 与 confirm。": "Deep repair requires both logs and confirm.",
43
49
  " storage [clean | repair [logs --confirm]] 查看用量、安全清理或深度修理日志": " storage [clean | repair [logs --confirm]] Show usage, clean safely or repair finished logs",
44
50
  "房间:create-room --title 标题 [--goal 目标] [--members 甲,乙] [--host 平台] [--host-model 模型] [--host-effort 档位] [--cwd 子目录] [--access read|write|auto|full] [--text 首条消息 | --body-file FILE] [--submission-id ID]": "Rooms: create-room --title TITLE [--goal GOAL] [--members A,B] [--host PLATFORM] [--host-model MODEL] [--host-effort LEVEL] [--cwd SUBDIRECTORY] [--access read|write|auto|full] [--text MESSAGE | --body-file FILE] [--submission-id ID]",
@@ -144,7 +150,7 @@ export default {
144
150
  "已打开:{value1}": "Opened: {value1}",
145
151
  "AI CoDiscuss 讨论服务\n服务目录:{value1}\n已登记 {value2} 个房间\nCtrl+C 停止服务\n": "AI CoDiscuss discussion service\nService folder: {value1}\n{value2} rooms registered\nCtrl+C to stop the service\n",
146
152
  "尚未登记房间;可在另一终端运行 codiscuss service add --config FILE。\n": "No rooms registered yet. Run codiscuss service add --config FILE in another terminal.\n",
147
- "用法:codiscuss admin <命令> [参数](与管理面板的操作一一对应;除启动与退出外,需管理面板正在运行)\n需要管理员权限的步骤(建或删 Windows 用户),在管理员终端或管理员的 SSH 会话里直接执行;否则在电脑桌面上弹出确认。\n\n启动与退出(不需要面板在运行)\n start 启动共议:服务、管理面板与任务栏图标、登录入口与隧道(在桌面会话里启动)\n stop 彻底退出:管理面板与图标、登录入口、隧道、共议服务;托管账号的实例照常运行\n restart stop 后 start\n update [check] 检查更新;不带 check 时安装最新版(面板未运行时先启动)并等待每一步结果\n\n本机\n status [--full] 概览:服务、中转状态、版本、开机自启、登录入口、托管账号;--full 输出面板的完整状态\n service start|stop|restart 只启停共议服务(网站与讨论服务)\n autostart on|off 登录 Windows 时自动启动\n\n管理员入口\n site status 本地网页与线上网站的地址\n site connect <接入码|站点> [绑定令牌] 绑定线上网站(管理员外出、邀请外部专家用);在部署该网站的电脑上只填站点即可\n site disconnect 解绑线上网站,已配对的设备不能再连到这台电脑\n site reconnect 立即重连已绑定网站的中转\n\n登录入口与访问方式(需打开托管管理)\n entry start|stop 启动或停止登录入口\n entry open|close relay|tunnel 开启或关闭访问方式:线上网站 | 自有域名,两种可同时开启\n entry join <接入码> 用接入码接入线上站点并开启线上网站\n entry code [--config <wrangler.jsonc>] [--site <地址>] 在部署线上站点的电脑上生成接入码(不填用上次的)\n entry tunnel <域名> [隧道名] 设置自有域名(Cloudflare 隧道),输出授权链接;域名须已托管在 Cloudflare\n entry tunnel status 查看自有域名设置的进度\n runtime sync 同步隔离账号的程序副本\n drives restrict 只允许隔离账号用系统盘:其他固定磁盘对它们的 Windows 用户拒绝访问(需管理员权限,之后重启它们的实例)\n\n托管账号\n account list\n account add <名> [--no-isolate] [--no-start] 创建、隔离、初始化 AI 环境、开启入口保护、启动;输出一次性密码。\n 中途失败时解决后重新执行同一命令,从缺少的步骤接着做\n account start|stop|disable|enable|remove|password <名>\n account isolate|unisolate|protect|unprotect <名>\n\n命令行登录(目标 owner 为管理员自己,否则为托管账号名)\n login status <目标> 各程序的登录状态,以及每个程序可用的登录方式\n login set <目标> <claude|codex> <方式> --set 字段=值 ... 如 login set alice claude setup_token --set token=sk-ant-oat01-…\n login start <目标> <程序> <方式> 浏览器登录:输出链接,之后用 login submit 提交授权码或回调地址\n login submit <作业> <文本> / login progress <作业> / login cancel <作业>\n logout <目标> <程序>\n\nAPI 密钥、技能、工作流、系统提示词(目标同上)\n key list <目标> / key add <目标> --base-url <地址> --key <密钥> / key remove <目标> <编号>\n skill library / skill import <文件夹或.zip> / skill delete <名>\n skill list <目标> / skill install <目标> <名>... / skill remove <目标> <名>...\n workflow list <目标> / workflow install <目标> / workflow update <目标>\n prompt get <账号> / prompt set <账号> --file <文件> 托管账号的系统提示词(管理员本人的成员用 codiscuss launch prompts)\n prompt default get / prompt default set --file <文件> 新托管账号的默认系统提示词\n\n结果以 JSON 输出。--data 指定管理员服务目录(默认 ~/.codiscuss)。\n": "Usage: codiscuss admin <command> [arguments] (matches admin panel actions; the panel must be running except for start and stop)\nSteps requiring administrator rights (creating or deleting Windows users) run directly in an administrator terminal or administrator SSH session. Otherwise, approve the prompt on the computer's desktop.\n\nStart and exit (panel need not be running)\n start Start CoDiscuss: service, panel and tray icon, sign-in entry and tunnel (in the desktop session)\n stop Exit panel and tray icon, sign-in entry, tunnel and service; hosted instances keep running\n restart Run stop, then start\n update [check] Check for updates; omit check to install the latest version and wait for results (starts the panel if needed)\n\nLocal\n status [--full] Show service, relay health, version, startup, sign-in entry and hosted accounts; --full returns full panel state\n service start|stop|restart Start or stop only the CoDiscuss service (site and discussion service)\n autostart on|off Start automatically at Windows sign-in\n\nAdministrator entry\n site status Addresses of the local page and the online site\n site connect <access code|site> [token] Bind an online site (for using it away from this computer and inviting external experts); on the computer that deployed it, the site alone is enough\n site disconnect Unbind the online site; paired devices can no longer reach this computer\n site reconnect Reconnect the relay to the bound online site now\n\nSign-in entry and access methods (hosting must be enabled)\n entry start|stop Start or stop the sign-in entry\n entry open|close relay|tunnel Turn an access method on or off: online site | own domain; both can be on\n entry join <code> Connect to an online site with an access code and turn on the online site\n entry code [--config <wrangler.jsonc>] [--site <address>] Generate an access code on the deployment computer (defaults to last settings)\n entry tunnel <domain> [tunnel-name] Configure a Cloudflare Tunnel and show the authorization link; domain must be hosted on Cloudflare\n entry tunnel status Show domain setup progress\n runtime sync Sync program copies for isolated accounts\n drives restrict Keep isolated accounts on the system drive: other fixed drives deny their Windows users (needs administrator rights; restart their instances afterwards)\n\nHosted accounts\n account list\n account add <name> [--no-isolate] [--no-start] Create, isolate, initialize AI environment, protect and start; show password once\n On failure, fix the cause and rerun the same command to resume missing steps\n account start|stop|disable|enable|remove|password <name>\n account isolate|unisolate|protect|unprotect <name>\n\nCLI sign-ins (target owner is the admin; otherwise use a hosted account name)\n login status <target> Show each app's sign-in status and available methods\n login set <target> <claude|codex> <method> --set field=value ... e.g. login set alice claude setup_token --set token=sk-ant-oat01-…\n login start <target> <app> <method> Browser sign-in: show a link; use login submit for the authorization code or callback URL\n login submit <job> <text> / login progress <job> / login cancel <job>\n logout <target> <app>\n\nAPI keys, skills, workflows and system prompts (same target convention)\n key list <target> / key add <target> --base-url <address> --key <key> / key remove <target> <id>\n skill library / skill import <folder-or.zip> / skill delete <name>\n skill list <target> / skill install <target> <name>... / skill remove <target> <name>...\n workflow list <target> / workflow install <target> / workflow update <target>\n prompt get <account> / prompt set <account> --file <file> A hosted account's system prompt (for the admin's own members use codiscuss launch prompts)\n prompt default get / prompt default set --file <file> Default system prompt for new hosted accounts\n\nResults are JSON. --data sets the admin service folder (default ~/.codiscuss).\n",
153
+ "用法:codiscuss admin <命令> [参数](与管理面板的操作一一对应;除启动与退出外,需管理面板正在运行)\n需要管理员权限的步骤(建或删 Windows 用户),在管理员终端或管理员的 SSH 会话里直接执行;否则在电脑桌面上弹出确认。\n\n启动与退出(不需要面板在运行)\n start 启动共议:服务、管理面板与任务栏图标、登录入口与隧道(在桌面会话里启动)\n stop 彻底退出:管理面板与图标、登录入口、隧道、共议服务;托管账号的实例照常运行\n restart stop 后 start\n update [check] 检查更新;不带 check 时安装最新版(面板未运行时先启动)并等待每一步结果\n\n本机\n status [--full] 概览:服务、中转状态、版本、开机自启、登录入口、托管账号;--full 输出面板的完整状态\n service start|stop|restart 只启停共议服务(网站与讨论服务)\n autostart on|off 登录 Windows 时自动启动\n\n管理员入口\n site status 本地网页与线上网站的地址\n site connect <接入码|站点> [绑定令牌] 绑定线上网站(管理员外出、邀请外部专家用);在部署该网站的电脑上只填站点即可\n site disconnect 解绑线上网站,已配对的设备不能再连到这台电脑\n site region [地区] 查看或设置中转地区(auto、apac、apac-ne、apac-se、wnam、enam、weur、eeur、oc、sam、afr、me)\n site reconnect 立即重连已绑定网站的中转\n\n登录入口与访问方式(需打开托管管理)\n entry start|stop 启动或停止登录入口\n entry open|close relay|tunnel 开启或关闭访问方式:线上网站 | 自有域名,两种可同时开启\n entry join <接入码> 用接入码接入线上站点并开启线上网站\n entry code [--config <wrangler.jsonc>] [--site <地址>] 在部署线上站点的电脑上生成接入码(不填用上次的)\n entry tunnel <域名> [隧道名] 设置自有域名(Cloudflare 隧道),输出授权链接;域名须已托管在 Cloudflare\n entry tunnel reconnect 重新连接隧道,保留登录会话\n entry tunnel status 查看自有域名设置的进度\n runtime sync 同步隔离账号的程序副本\n drives restrict 只允许隔离账号用系统盘:其他固定磁盘对它们的 Windows 用户拒绝访问(需管理员权限,之后重启它们的实例)\n\n托管账号\n account list\n account add <名> [--no-isolate] [--no-start] 创建、隔离、初始化 AI 环境、开启入口保护、启动;输出一次性密码。\n 中途失败时解决后重新执行同一命令,从缺少的步骤接着做\n account start|stop|disable|enable|remove|password <名>\n account isolate|unisolate|protect|unprotect <名>\n\n命令行登录(目标 owner 为管理员自己,否则为托管账号名)\n login status <目标> 各程序的登录状态,以及每个程序可用的登录方式\n login set <目标> <claude|codex> <方式> --set 字段=值 ... 如 login set alice claude setup_token --set token=sk-ant-oat01-…\n login start <目标> <程序> <方式> 浏览器登录:输出链接,之后用 login submit 提交授权码或回调地址\n login submit <作业> <文本> / login progress <作业> / login cancel <作业>\n logout <目标> <程序>\n\nAPI 密钥、技能、工作流、系统提示词(目标同上)\n key list <目标> / key add <目标> --base-url <地址> --key <密钥> / key remove <目标> <编号>\n skill library / skill import <文件夹或.zip> / skill delete <名>\n skill list <目标> / skill install <目标> <名>... / skill remove <目标> <名>...\n workflow list <目标> / workflow install <目标> / workflow update <目标>\n prompt get <账号> / prompt set <账号> --file <文件> 托管账号的系统提示词(管理员本人的成员用 codiscuss launch prompts)\n prompt default get / prompt default set --file <文件> 新托管账号的默认系统提示词\n\n结果以 JSON 输出。--data 指定管理员服务目录(默认 ~/.codiscuss)。\n": "Usage: codiscuss admin <command> [arguments] (matches admin panel actions; the panel must be running except for start and stop)\nSteps requiring administrator rights (creating or deleting Windows users) run directly in an administrator terminal or administrator SSH session. Otherwise, approve the prompt on the computer's desktop.\n\nStart and exit (panel need not be running)\n start Start CoDiscuss: service, panel and tray icon, sign-in entry and tunnel (in the desktop session)\n stop Exit panel and tray icon, sign-in entry, tunnel and service; hosted instances keep running\n restart Run stop, then start\n update [check] Check for updates; omit check to install the latest version and wait for results (starts the panel if needed)\n\nLocal\n status [--full] Show service, relay health, version, startup, sign-in entry and hosted accounts; --full returns full panel state\n service start|stop|restart Start or stop only the CoDiscuss service (site and discussion service)\n autostart on|off Start automatically at Windows sign-in\n\nAdministrator entry\n site status Addresses of the local page and the online site\n site connect <access code|site> [token] Bind an online site (for using it away from this computer and inviting external experts); on the computer that deployed it, the site alone is enough\n site disconnect Unbind the online site; paired devices can no longer reach this computer\n site region [region] Show or set relay location (auto, apac, apac-ne, apac-se, wnam, enam, weur, eeur, oc, sam, afr, me)\n site reconnect Reconnect the relay to the bound online site now\n\nSign-in entry and access methods (hosting must be enabled)\n entry start|stop Start or stop the sign-in entry\n entry open|close relay|tunnel Turn an access method on or off: online site | own domain; both can be on\n entry join <code> Connect to an online site with an access code and turn on the online site\n entry code [--config <wrangler.jsonc>] [--site <address>] Generate an access code on the deployment computer (defaults to last settings)\n entry tunnel <domain> [tunnel-name] Configure a Cloudflare Tunnel and show the authorization link; domain must be hosted on Cloudflare\n entry tunnel reconnect Reconnect the tunnel and preserve sign-in sessions\n entry tunnel status Show domain setup progress\n runtime sync Sync program copies for isolated accounts\n drives restrict Keep isolated accounts on the system drive: other fixed drives deny their Windows users (needs administrator rights; restart their instances afterwards)\n\nHosted accounts\n account list\n account add <name> [--no-isolate] [--no-start] Create, isolate, initialize AI environment, protect and start; show password once\n On failure, fix the cause and rerun the same command to resume missing steps\n account start|stop|disable|enable|remove|password <name>\n account isolate|unisolate|protect|unprotect <name>\n\nCLI sign-ins (target owner is the admin; otherwise use a hosted account name)\n login status <target> Show each app's sign-in status and available methods\n login set <target> <claude|codex> <method> --set field=value ... e.g. login set alice claude setup_token --set token=sk-ant-oat01-…\n login start <target> <app> <method> Browser sign-in: show a link; use login submit for the authorization code or callback URL\n login submit <job> <text> / login progress <job> / login cancel <job>\n logout <target> <app>\n\nAPI keys, skills, workflows and system prompts (same target convention)\n key list <target> / key add <target> --base-url <address> --key <key> / key remove <target> <id>\n skill library / skill import <folder-or.zip> / skill delete <name>\n skill list <target> / skill install <target> <name>... / skill remove <target> <name>...\n workflow list <target> / workflow install <target> / workflow update <target>\n prompt get <account> / prompt set <account> --file <file> A hosted account's system prompt (for the admin's own members use codiscuss launch prompts)\n prompt default get / prompt default set --file <file> Default system prompt for new hosted accounts\n\nResults are JSON. --data sets the admin service folder (default ~/.codiscuss).\n",
148
154
  "管理面板没有在运行:在这台电脑的桌面上运行 codiscuss panel open,或从任务栏图标打开": "The admin panel is not running. Run codiscuss panel open on this computer's desktop, or open it from the tray icon.",
149
155
  "管理面板没有响应:在这台电脑的桌面上运行 codiscuss panel open": "The admin panel did not respond. Run codiscuss panel open on this computer's desktop.",
150
156
  "管理面板拒绝了钥匙(面板可能刚重启):稍后重试": "The admin panel rejected the key (it may have just restarted). Try again shortly.",
@@ -17,7 +17,7 @@ import { t } from './i18n.mjs';
17
17
  import { granted_projects, room_share_job, remote_execution_details, remote_room_files, remote_room_media, remote_room_page } from './discussion_launch.mjs';
18
18
  import { acquire_lock } from './discussion_runner.mjs';
19
19
  import { local_settings } from './discussion_setup.mjs';
20
- import { machine_links, relay_cipher, save_machine_links, relayed_command, ROOM_ACTIONS, run_launch_command, sync_remote_launches, unseal } from './remote_launch.mjs';
20
+ import { machine_links, relay_cipher, save_machine_links, relayed_command, ROOM_ACTIONS, run_launch_command, synced_relay_region, sync_remote_launches, unseal } from './remote_launch.mjs';
21
21
  import { claim_relayed_command, guard_remote_directories } from './remote_policy.mjs';
22
22
  import { audit, DEVICE_ACTIONS, device_command, open_signed_request } from './device_auth.mjs';
23
23
  import { answer_external, INVITE_COMMANDS, is_external_request } from './external_gateway.mjs';
@@ -598,7 +598,7 @@ async function hold_channel(home, site, { connected, log, signal, health, watch
598
598
  */
599
599
  export function start_relay_channels(home, { log = () => {}, signal, health }) {
600
600
  const connected = new Set(), held = new Map();
601
- const requested_site = reconnect_reader(home);
601
+ const requested_site = reconnect_reader(home, site => synced_relay_region(home, site));
602
602
  function start(site, link) {
603
603
  const controller = new AbortController(), channel_signal = AbortSignal.any([signal, controller.signal]);
604
604
  const record = { controller, machine: link.id, token: link.token, timer: null, confirmed: false };
@@ -72,13 +72,14 @@ export function request_relay_reconnect(home, bound, pid) {
72
72
  }
73
73
 
74
74
  /** Consume each request once, ignoring requests for a replaced service or binding. */
75
- export function reconnect_reader(home) {
75
+ export function reconnect_reader(home, synced_region = () => undefined) {
76
76
  let seen;
77
77
  return sites => {
78
78
  let request;
79
79
  try { request = JSON.parse(readFileSync(join(home, RECONNECT_FILE), 'utf8')); }
80
80
  catch { return; } // A manual request must not prevent the normal channels starting.
81
81
  if (!request?.id || request.id === seen || request.pid !== process.pid) return;
82
+ if (request.wait_region && synced_region(request.site) !== request.wait_region) return;
82
83
  seen = request.id;
83
84
  if (sites[request.site]?.id === request.machine) return request.site;
84
85
  };
@@ -214,12 +214,17 @@ export async function sync_remote_launches(home, { log = () => {}, throttle = fa
214
214
  try { ({ launches, sync_seconds } = await machine_request(site, link, '/sync', payload, { health })); }
215
215
  catch (error) { log(`${site}: 同步电脑状态失败:${error.message}`); continue; }
216
216
  const interval = Number.isFinite(sync_seconds) ? Math.min(Math.max(sync_seconds, SYNC_MIN_SECONDS), SYNC_MAX_SECONDS) : SYNC_MIN_SECONDS;
217
- last_syncs.set(key, { content, at: Date.now(), interval });
217
+ last_syncs.set(key, { content, at: Date.now(), interval, region: link.relay_region ?? 'apac' });
218
218
  if (launches?.length) log(`${site}: 网站返回了 ${launches.length} 个旧格式启动任务,已忽略;远程启动须由已配对设备签名`);
219
219
  }
220
220
  }
221
221
  // The last state each service directory sent each site: { content, at, interval }.
222
222
  const last_syncs = new Map();
223
+
224
+ /** Region acknowledged by the site in this service process. */
225
+ export function synced_relay_region(home, site) {
226
+ return last_syncs.get([home, site].join('|'))?.region;
227
+ }
223
228
  const SYNC_MIN_SECONDS = 3;
224
229
  const SYNC_MAX_SECONDS = 600;
225
230
 
@@ -217,7 +217,8 @@ export function create_share_core({ t, display_name, collapse_visual_fences, is_
217
217
  for (const [path, body] of Object.entries(responses)) {
218
218
  if (!/\/messages\?/.test(path)) continue;
219
219
  for (const message of body.messages || []) for (const file of message.attachments || []) {
220
- if (file.room_id !== room_id) continue;
220
+ // A cleared file has no bytes to copy; the page shows its card as cleared, as the room does.
221
+ if (file.room_id !== room_id || file.cleared_at) continue;
221
222
  const route = share_file_route(file);
222
223
  // A data URL names the plain type; parameters such as a charset would not survive the share site's check.
223
224
  files.set(route, { route, room_id, id: file.id, created_at: message.created_at, author: message.author_label || message.author, file_name: file.file_name, size: Number(file.size) || 0, message_id: message.id, ...share_site_file(file.file_name),