ai_co_discuss 0.4.51 → 0.4.53

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/docs/runner.md CHANGED
@@ -43,7 +43,7 @@ codiscuss setup
43
43
 
44
44
  Windows 上在终端运行 `codiscuss setup` 时,“安装配置”一步有“桌面快捷方式”:还没有时默认勾选“创建‘共议’快捷方式”,已有时显示为“重新生成”、默认不勾(非交互运行不创建);也可随时运行 `codiscuss launcher` 生成或重新生成。它会生成“共议”程序,桌面和开始菜单各有一个快捷方式,双击即可启动服务并打开网站。服务运行时任务栏右下角有共议图标:左键打开**管理面板**(也可运行 `codiscuss panel`),右键可打开共议、重启或关闭服务。管理面板分两页:“概览”显示本机服务状态(可启动、重启、停止)、检查并安装新版本(同时更新你的房间技能)、开关“登录 Windows 时自动启动”;“账号”页左侧选账号,“管理员”里管理你自己的 Claude Code / Codex / Antigravity 登录(可直接登录、切换方式、退出;Claude Code 推荐 Setup Token)、API 密钥和已安装的技能(可从技能库添加);面板只能在这台电脑上打开。第一次需要在“设置 → 个性化 → 任务栏 → 其他系统托盘图标”里打开“共议”,图标才会常驻任务栏。
45
45
 
46
- 管理面板的每项操作也能用命令行完成:`codiscuss admin`(`codiscuss admin --help` 列出全部命令),适合经 SSH 远程管理这台电脑。`start`、`stop`(彻底退出:面板与图标、登录入口、隧道、共议服务;托管账号的实例照常运行)、`restart`、`update` 不需要面板在运行;`start` 在已登录的桌面会话里启动,任务栏图标照常出现。其余命令经运行中的面板执行,与点击界面效果相同,只有这台电脑的管理员能用;隔离账号时的管理员确认仍弹在这台电脑的桌面上。
46
+ 管理面板的每项操作也能用命令行完成:`codiscuss admin`(`codiscuss admin --help` 列出全部命令),适合经 SSH 远程管理这台电脑。`start`、`stop`(彻底退出:面板与图标、登录入口、隧道、共议服务;托管账号的实例照常运行)、`restart`、`update` 不需要面板在运行;`start` 在已登录的桌面会话里启动,任务栏图标照常出现。其余命令经运行中的面板执行,与点击界面效果相同,只有这台电脑的管理员能用。建或删隔离账号的 Windows 用户需要管理员权限:在管理员终端或管理员的 SSH 会话里直接执行,否则在这台电脑的桌面上弹出确认。`account add` 中途失败时,解决后重新执行同一命令,会从缺少的步骤接着做。
47
47
 
48
48
  给别人开账号用这台电脑上的 AI 时,在 setup 的“安装配置”里勾选“托管管理”(或加 `--hosting`,`--no-hosting` 关闭;选择会记住),面板会多出“托管账号”页:
49
49
  - 点“新建账号”,填账号名,默认“隔离”(给它一个独立的 Windows 用户,电脑会弹出一次管理员确认);向导会一次装好它要用的程序、房间技能、系统提示词和随包工作流,并启动它的网站,最后显示一次密码。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai_co_discuss",
3
- "version": "0.4.51",
3
+ "version": "0.4.53",
4
4
  "bin": {
5
5
  "codiscuss": "runner/codiscuss.mjs"
6
6
  },
@@ -3,8 +3,10 @@
3
3
  * running panel's own interface, so a command does exactly what the same click does.
4
4
  *
5
5
  * It opens the panel the way the taskbar icon does, with the key in the owner's service directory
6
- * (`admin-panel.json`, readable by the owner only), so only the computer's owner can use it. Elevation prompts and
7
- * browser windows the panel opens appear in the owner's desktop session, not in this terminal.
6
+ * (`admin-panel.json`, readable by the owner only), so only the computer's owner can use it. Browser windows the panel
7
+ * opens appear in the owner's desktop session, not in this terminal. Steps that need administrator rights run in this
8
+ * command when it already has them (an elevated terminal, an administrator's SSH session), through the panel's own
9
+ * operations; otherwise the panel asks on the desktop.
8
10
  *
9
11
  * Starting, stopping, restarting and updating work without the panel running: `start` launches everything in the owner's
10
12
  * desktop session (from an SSH session, through a one-time scheduled task that runs there), so the taskbar icon appears
@@ -20,14 +22,18 @@ import { data_home, entry_settings, entry_status, stop_entry } from '../gateway/
20
22
  import { local_status } from './discussion_local.mjs';
21
23
  import { stop_tunnel } from './hosting_tunnel.mjs';
22
24
  import { launcher_path } from './launcher.mjs';
25
+ import { running_elevated } from './os_users.mjs';
23
26
 
24
27
  const STATE_FILE = 'admin-panel.json';
25
28
  const OWNER = 'owner';
29
+ // What needs administrator rights (creating or removing an account's Windows user, which registers its instance task).
30
+ const ELEVATED_PATHS = /^accounts\/[^/]+\/os-user(\/remove)?$/;
26
31
  const LOGIN_WAIT_MS = 60_000, UPDATE_WAIT_MS = 10 * 60_000, START_WAIT_MS = 90_000, POLL_MS = 1500;
27
32
  const RUNNER = dirname(fileURLToPath(import.meta.url));
28
33
  const DESKTOP_TASK = 'CoDiscuss start (one time)';
29
34
 
30
- export const HELP = `用法:codiscuss admin <命令> [参数](与管理面板的操作一一对应,需管理面板正在运行)
35
+ export const HELP = `用法:codiscuss admin <命令> [参数](与管理面板的操作一一对应;除启动与退出外,需管理面板正在运行)
36
+ 需要管理员权限的步骤(建或删 Windows 用户),在管理员终端或管理员的 SSH 会话里直接执行;否则在电脑桌面上弹出确认。
31
37
 
32
38
  启动与退出(不需要面板在运行)
33
39
  start 启动共议:服务、管理面板与任务栏图标、登录入口与隧道(在桌面会话里启动)
@@ -36,25 +42,29 @@ export const HELP = `用法:codiscuss admin <命令> [参数](与管理面
36
42
  update [check] 检查更新;不带 check 时安装最新版(面板未运行时先启动)并等待每一步结果
37
43
 
38
44
  本机
39
- status 概览:服务、版本、开机自启、登录入口、托管账号
45
+ status [--full] 概览:服务、版本、开机自启、登录入口、托管账号;--full 输出面板的完整状态
40
46
  service start|stop|restart 只启停共议服务(网站与讨论服务)
41
47
  autostart on|off 登录 Windows 时自动启动
42
48
 
43
- 登录入口与外网访问(需打开托管管理)
49
+ 登录入口与访问方式(需打开托管管理)
44
50
  entry start|stop 启动或停止登录入口
45
- entry mode local|relay|tunnel 外网访问方式
51
+ entry mode local|relay|tunnel 访问方式:仅这台电脑 | 线上中转 | 自有域名
46
52
  entry join <接入码> 用接入码接入线上站点并切换到线上中转
47
- entry connect <站点> <绑定令牌> 只绑定线上站点(管理员远程用),不改外网访问方式
53
+ entry connect <站点> <绑定令牌> 只绑定线上站点(管理员远程用),不改访问方式
54
+ entry code [--config <wrangler.jsonc>] [--site <地址>] 在部署线上站点的电脑上生成接入码(不填用上次的)
55
+ entry tunnel <域名> [隧道名] 设置自有域名(Cloudflare 隧道),输出授权链接;域名须已托管在 Cloudflare
56
+ entry tunnel status 查看自有域名设置的进度
48
57
  runtime sync 同步隔离账号的程序副本
49
58
 
50
59
  托管账号
51
60
  account list
52
- account add <名> [--no-isolate] [--no-start] 创建、隔离、初始化 AI 环境、开启入口保护、启动;输出一次性密码
61
+ account add <名> [--no-isolate] [--no-start] 创建、隔离、初始化 AI 环境、开启入口保护、启动;输出一次性密码。
62
+ 中途失败时解决后重新执行同一命令,从缺少的步骤接着做
53
63
  account start|stop|disable|enable|remove|password <名>
54
64
  account isolate|unisolate|protect|unprotect <名>
55
65
 
56
66
  命令行登录(目标 owner 为管理员自己,否则为托管账号名)
57
- login status <目标>
67
+ login status <目标> 各程序的登录状态,以及每个程序可用的登录方式
58
68
  login set <目标> <claude|codex> <方式> --set 字段=值 ... 如 login set alice claude setup_token --set token=sk-ant-oat01-…
59
69
  login start <目标> <程序> <方式> 浏览器登录:输出链接,之后用 login submit 提交授权码或回调地址
60
70
  login submit <作业> <文本> / login progress <作业> / login cancel <作业>
@@ -97,24 +107,35 @@ const wait = ms => new Promise(done => setTimeout(done, ms));
97
107
  const need = (value, usage) => { if (!value) throw new Error(`缺少参数:${usage}`); return value; };
98
108
  const is_owner = target => target === OWNER;
99
109
 
100
- /** Create an account the way the panel's wizard does, step by step; the password is reported even if a later step fails. */
110
+ /**
111
+ * Create an account the way the panel's wizard does, step by step. Run again for an account that exists, it goes on
112
+ * from the first step missing; the password is reported once created, even if a later step fails.
113
+ */
101
114
  async function add_account(call, name, { isolate, start }) {
102
115
  const steps = [];
103
- const created = await call('accounts', { name });
104
- steps.push('已创建账号与文件夹');
116
+ const existing = (await call('state')).accounts?.find(item => item.name === name);
117
+ let password = '';
118
+ if (existing) steps.push('账号已存在,从缺少的步骤接着做(密码不变;需要新密码用 account password)');
119
+ else { password = (await call('accounts', { name })).password; steps.push('已创建账号与文件夹'); }
120
+ const report = extra => ({ name, ...(password ? { password } : {}), steps, ...extra });
105
121
  try {
106
- if (isolate) {
122
+ if (isolate && !existing?.os_user) {
107
123
  await call(`accounts/${name}/os-user`, {});
108
- steps.push('已创建独立的 Windows 用户(电脑上的管理员确认已通过)');
124
+ steps.push(running_elevated() ? '已创建独立的 Windows 用户' : '已创建独立的 Windows 用户(电脑上的管理员确认已通过)');
125
+ }
126
+ if (isolate) {
109
127
  const state = await call('state');
110
128
  if (!state.clis?.app || !state.clis?.python) { await call('clis/install', {}); steps.push('已安装隔离账号的程序副本'); }
111
129
  }
112
130
  await call(`accounts/${name}/env/init`, {});
113
131
  steps.push(isolate ? '已初始化 AI 环境' : '已安装随包工作流');
114
- if (process.platform === 'win32') { await call(`accounts/${name}/protect`, { on: true }); steps.push('已开启入口保护'); }
115
- if (start) { await call(`accounts/${name}/start`, {}); steps.push('已启动实例'); }
116
- } catch (error) { return { name, password: created.password, steps, failed: error.message }; }
117
- return { name, password: created.password, steps };
132
+ if (process.platform === 'win32' && !existing?.protected) { await call(`accounts/${name}/protect`, { on: true }); steps.push('已开启入口保护'); }
133
+ if (start && !existing?.running) { await call(`accounts/${name}/start`, {}); steps.push('已启动实例'); }
134
+ } catch (error) {
135
+ const rights = /管理员权限/.test(error.message) ? '在管理员终端或管理员的 SSH 会话里执行,或在电脑桌面上确认提权,' : '';
136
+ return report({ failed: error.message, next: `${rights}解决后重新执行 codiscuss admin account add ${name},会从这一步接着做` });
137
+ }
138
+ return report({});
118
139
  }
119
140
 
120
141
  const ACCOUNT_ACTIONS = { start: 'start', stop: 'stop', disable: 'disable', enable: 'enable', remove: 'remove', password: 'password',
@@ -142,7 +163,10 @@ async function start_login(call, target, cli, method) {
142
163
 
143
164
  async function login_command(call, [action, ...rest], values) {
144
165
  const target = (name) => (is_owner(name) ? '_' : need(name, '目标'));
145
- if (action === 'status') return call(`logins/${target(rest[0])}`);
166
+ if (action === 'status') {
167
+ const [status, state] = await Promise.all([call(`logins/${target(rest[0])}`), call('state')]);
168
+ return { status, methods: login_methods(state.login_methods) };
169
+ }
146
170
  if (action === 'set') {
147
171
  const [who, cli, method] = rest;
148
172
  const fields = Object.fromEntries((values.set || []).map(pair => { const at = pair.indexOf('='); return [pair.slice(0, at), pair.slice(at + 1)]; }));
@@ -155,6 +179,13 @@ async function login_command(call, [action, ...rest], values) {
155
179
  throw new Error(HELP);
156
180
  }
157
181
 
182
+ /** The ways each program signs in, as `login set` (filled-in fields) or `login start` (in a browser) takes them. */
183
+ function login_methods(methods = {}) {
184
+ return Object.fromEntries(Object.entries(methods).map(([cli, list]) => [cli, list.map(item => (item.interactive
185
+ ? `${item.key}:${item.label}(login start <目标> ${cli} ${item.key})`
186
+ : `${item.key}:${item.label}(login set <目标> ${cli} ${item.key} ${(item.fields || []).map(field => `--set ${field}=…`).join(' ')})`))]));
187
+ }
188
+
158
189
  async function key_command(call, [action, who, ref], values) {
159
190
  const base = is_owner(need(who, '目标')) ? 'owner/keys' : `accounts/${who}/keys`;
160
191
  if (action === 'list') return call(base);
@@ -295,19 +326,58 @@ async function update(call, data) {
295
326
  throw new Error('更新超过 10 分钟没有完成:之后用 codiscuss admin status 查看版本');
296
327
  }
297
328
 
298
- async function entry_command(call, [action, first, second]) {
329
+ async function entry_command(call, [action, first, second], values) {
299
330
  if (action === 'start' || action === 'stop') return call(`entry/${action}`, {});
300
331
  if (action === 'mode') return call('entry/mode', { mode: need(first, 'local|relay|tunnel') });
301
332
  if (action === 'join') return call('relay/join', { code: need(first, '接入码') });
302
333
  if (action === 'connect') return call('site/connect', { site: need(first, '站点'), setup_key: need(second, '绑定令牌') });
334
+ if (action === 'code') return call('site/code', { config: values.config || '', site: values.site || '' });
335
+ if (action === 'tunnel') return first === 'status' ? call('tunnel/setup') : setup_tunnel(call, need(first, '域名'), second || '');
303
336
  throw new Error(HELP);
304
337
  }
305
338
 
339
+ /** Start setting up the owner's domain and wait for the Cloudflare authorization link (or the end). */
340
+ async function setup_tunnel(call, host, name) {
341
+ await call('tunnel/setup', { host, name });
342
+ for (let waited = 0; waited < LOGIN_WAIT_MS; waited += POLL_MS) {
343
+ await wait(POLL_MS);
344
+ const job = await call('tunnel/setup');
345
+ if (job.url) return { ...job, note: '用任一浏览器打开 url,登录 Cloudflare 并选择这个域名授权;之后用 entry tunnel status 查看进度' };
346
+ if (job.status !== 'running') return job;
347
+ }
348
+ return { ...(await call('tunnel/setup')), note: '仍在进行,用 entry tunnel status 查看进度' };
349
+ }
350
+
351
+ /** The overview at a glance: what runs, where users sign in, and each account in one line. */
352
+ function summary(state) {
353
+ const { entry, service } = state;
354
+ const tunnel = entry?.tunnel ? (entry.tunnel.connected ? '已连接' : entry.tunnel.running ? '连接中' : '未运行') : undefined;
355
+ return { hosting: state.hosting, version: state.version, autostart: state.autostart,
356
+ service: { running: service.running, url: service.url, version: service.version, error: service.error || undefined },
357
+ ...(state.hosting ? {
358
+ entry: entry && { running: entry.running, mode: entry.mode, address: entry.address || `http://127.0.0.1:${entry.port}`, tunnel, problem: entry.relay?.problem || undefined },
359
+ runtime: state.clis,
360
+ accounts: state.accounts.map(item => ({ name: item.name, isolated: Boolean(item.os_user), protected: item.protected, running: item.running, disabled: item.disabled })),
361
+ } : {}) };
362
+ }
363
+
364
+ /**
365
+ * The panel's client, with the steps that need administrator rights done in this command when it already has them: an
366
+ * administrator's SSH session has no desktop to answer the panel's prompt.
367
+ */
368
+ async function with_elevation(call, data) {
369
+ if (!running_elevated()) return call;
370
+ const { create_panel } = await import('./admin_panel.mjs');
371
+ const { api } = create_panel({ data, key: '', port: 0 });
372
+ return (path, body) => (body !== undefined && ELEVATED_PATHS.test(path) ? api('POST', `/api/${path}`, body) : call(path, body));
373
+ }
374
+
306
375
  /** Run one `codiscuss admin` command and print its result as JSON. */
307
376
  export async function admin_cli(args, { client = panel_client, print = text => process.stdout.write(text) } = {}) {
308
377
  const { positionals, values } = parseArgs({ args, allowPositionals: true, options: {
309
378
  data: { type: 'string' }, help: { type: 'boolean', short: 'h' }, 'no-isolate': { type: 'boolean' }, 'no-start': { type: 'boolean' },
310
379
  set: { type: 'string', multiple: true }, 'base-url': { type: 'string' }, key: { type: 'string' }, file: { type: 'string' }, group: { type: 'string' },
380
+ full: { type: 'boolean' }, config: { type: 'string' }, site: { type: 'string' },
311
381
  } });
312
382
  const [command, ...rest] = positionals;
313
383
  if (!command || values.help || command === 'help') return print(HELP);
@@ -324,13 +394,16 @@ export async function admin_cli(args, { client = panel_client, print = text => p
324
394
  print(`${JSON.stringify(result, null, 2)}\n`);
325
395
  return result;
326
396
  }
327
- const call = await client(data);
397
+ const call = await with_elevation(await client(data), data);
328
398
  const commands = {
329
- status: async () => { const { login_methods: _methods, providers: _providers, ...state } = await call('state'); return state; },
399
+ status: async () => {
400
+ const { login_methods: _methods, providers: _providers, ...state } = await call('state');
401
+ return values.full ? state : summary(state);
402
+ },
330
403
  service: () => call(`service/${need(rest[0], 'start|stop|restart')}`, {}),
331
404
  autostart: () => call('autostart', { on: need(rest[0], 'on|off') === 'on' }),
332
405
  update: () => (rest[0] === 'check' ? call('update/check') : update(call, data)),
333
- entry: () => entry_command(call, rest),
406
+ entry: () => entry_command(call, rest, values),
334
407
  runtime: () => (rest[0] === 'sync' ? call('clis/install', {}) : Promise.reject(new Error(HELP))),
335
408
  account: () => account_command(call, rest, values),
336
409
  login: () => login_command(call, rest, values),
@@ -343,5 +416,7 @@ export async function admin_cli(args, { client = panel_client, print = text => p
343
416
  if (!commands[command]) throw new Error(HELP);
344
417
  const result = await commands[command]();
345
418
  print(`${JSON.stringify(result, null, 2)}\n`);
419
+ // A step that failed part way (account add) is reported in the result, and in the exit code for scripts.
420
+ if (result?.failed) process.exitCode = 1;
346
421
  return result;
347
422
  }
@@ -12,6 +12,7 @@ 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
14
  import { homedir, tmpdir } from 'node:os';
15
+ import tls from 'node:tls';
15
16
  import { dirname, extname, join, resolve } from 'node:path';
16
17
  import { fileURLToPath, pathToFileURL } from 'node:url';
17
18
  import { parseArgs } from 'node:util';
@@ -43,7 +44,12 @@ const VERSION = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8')).ver
43
44
  const NPM_PACKAGE = 'ai_co_discuss';
44
45
  const LATEST_URL = `https://registry.npmjs.org/${NPM_PACKAGE}/latest`;
45
46
  const LATEST_TTL_MS = 60 * 60 * 1000;
46
- const LATEST_TIMEOUT_MS = 8000;
47
+ const OUTSIDE_TIMEOUT_MS = 8000, OUTSIDE_ATTEMPTS = 2;
48
+ // Node 24 (OpenSSL 3.5) offers a post-quantum key share first, which makes its TLS greeting span several packets; behind
49
+ // a Clash (Mihomo) TUN such connections were reset more than half the time, while curl and browsers got through (seen
50
+ // 2026-11-14). What the panel fetches outside is public (the latest version, a site's entry address, the relay's state),
51
+ // so it offers the classic key shares only.
52
+ tls.DEFAULT_ECDH_CURVE = 'X25519:prime256v1:secp384r1';
47
53
  const STATE_FILE = 'admin-panel.json';
48
54
  // An update's progress and report, kept in the service directory (panel_updater.mjs writes it too), and how long an
49
55
  // unfinished one blocks another.
@@ -95,10 +101,28 @@ function service_overview(data) {
95
101
 
96
102
  let latest = { at: 0, version: '' };
97
103
 
104
+ /**
105
+ * Fetch an outside address, trying once more when it fails: now and then a request to Cloudflare stalls for many seconds
106
+ * while the next one answers in under two (seen 2026-11-14). Failing is reported naming the host, not as a problem of
107
+ * the site.
108
+ */
109
+ async function fetch_outside(url, timeout_ms) {
110
+ for (let attempt = 1; ; attempt += 1) {
111
+ try {
112
+ return await fetch(url, { signal: AbortSignal.timeout(timeout_ms) });
113
+ } catch (error) {
114
+ const timed_out = error.name === 'TimeoutError';
115
+ if (attempt < OUTSIDE_ATTEMPTS) continue;
116
+ const why = timed_out ? `${timeout_ms / 1000} 秒内没有响应` : `连接被断开(${error.cause?.code || error.message})`;
117
+ throw new Error(`连不上 ${new URL(url).host}:${why},请检查这台电脑的网络或代理后重试`);
118
+ }
119
+ }
120
+ }
121
+
98
122
  /** The newest published version, asked of the npm registry at most once an hour (nothing about this computer is sent). */
99
123
  async function latest_version(force = false) {
100
124
  if (!force && latest.version && Date.now() - latest.at < LATEST_TTL_MS) return latest.version;
101
- const response = await fetch(LATEST_URL, { signal: AbortSignal.timeout(LATEST_TIMEOUT_MS) });
125
+ const response = await fetch_outside(LATEST_URL, OUTSIDE_TIMEOUT_MS);
102
126
  if (!response.ok) throw new Error(`查询新版本失败(HTTP ${response.status})`);
103
127
  latest = { at: Date.now(), version: String((await response.json()).version || '') };
104
128
  return latest.version;
@@ -503,7 +527,7 @@ function run_instance(data, name, command) {
503
527
  // An account without its own Windows user runs as the owner and could read everything the owner can; it is not let
504
528
  // run while people outside can reach the entry.
505
529
  if (command === 'start' && process.platform === 'win32' && !read_os_users(data)[name] && entry_settings(data).mode !== 'local') {
506
- throw new Error(`外网访问已开启,${name} 未隔离(以你的身份运行),不能启动:请先隔离该账号,或把外网访问改为“仅本机”`);
530
+ throw new Error(`外网访问已开启,${name} 未隔离(以你的身份运行),不能启动:请先隔离该账号,或把登录入口的访问方式改为“仅这台电脑”`);
507
531
  }
508
532
  if (command === 'start' && read_os_users(data)[name]) {
509
533
  const { local_script } = shared_paths();
@@ -718,7 +742,7 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
718
742
  throw new Error('接口不存在');
719
743
  }
720
744
 
721
- return http.createServer(async (request, response) => {
745
+ const server = http.createServer(async (request, response) => {
722
746
  try {
723
747
  const url = new URL(request.url, 'http://127.0.0.1');
724
748
  // Only a page this browser opened from this address; anything else (another site, a renamed host) is refused.
@@ -757,6 +781,9 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
757
781
  else send_json(response, error.status || 400, { error: error.message });
758
782
  }
759
783
  });
784
+ // The same operations without HTTP, for `codiscuss admin` run elevated (the steps that need administrator rights).
785
+ server.api = api;
786
+ return server;
760
787
  }
761
788
 
762
789
  /** The account entry as the hosting page shows it: whether it runs, its loopback port and the address customers open. */
@@ -775,7 +802,7 @@ function bound_site(data) {
775
802
  /** Ask the relay's entry Worker whether it is one and whether this computer is connected to it. */
776
803
  async function relay_status(relay_url, machine) {
777
804
  try {
778
- const answer = await fetch(`${relay_url}/_codiscuss/status?machine=${machine || '0'.repeat(32)}`, { signal: AbortSignal.timeout(RELAY_CHECK_MS) });
805
+ const answer = await fetch_outside(`${relay_url}/_codiscuss/status?machine=${machine || '0'.repeat(32)}`, RELAY_CHECK_MS);
779
806
  const result = await answer.json();
780
807
  return result.service === 'codiscuss-entry' ? { reachable: true, online: Boolean(result.online) } : { reachable: false, online: false };
781
808
  } catch { return { reachable: false, online: false }; }
@@ -820,7 +847,7 @@ async function set_entry_mode(data, mode) {
820
847
  const users = read_os_users(data), accounts = read_accounts(data);
821
848
  const exposed = [];
822
849
  for (const [name, account] of Object.entries(accounts)) if (!users[name] && await instance_running(account.port)) exposed.push(name);
823
- if (exposed.length) throw new Error(`未隔离的账号正在运行(${exposed.join('、')}),它们以你的身份运行,开启外网访问前请先停止或隔离`);
850
+ if (exposed.length) throw new Error(`未隔离的账号正在运行(${exposed.join('、')}),它们以你的身份运行,改用线上中转或自有域名前请先停止或隔离`);
824
851
  }
825
852
  save_entry_settings(data, { mode });
826
853
  if (mode !== 'local' && !(await entry_status(data)).running) { await start_entry(data); save_entry_settings(data, { running: true }); }
@@ -893,7 +920,8 @@ async function join_relay(data, text) {
893
920
 
894
921
  /** The entry Worker address an online site gives (`GET /api/entry`). */
895
922
  async function site_entry_url(site) {
896
- const given = await fetch(`${site}/api/entry`, { signal: AbortSignal.timeout(RELAY_CHECK_MS) }).then(answer => answer.json()).catch(() => ({}));
923
+ const answer = await fetch_outside(`${site}/api/entry`, OUTSIDE_TIMEOUT_MS);
924
+ const given = await answer.json().catch(() => ({}));
897
925
  if (!given.entry_url) throw new Error(`${site} 没有提供入口地址:请部署线上站点的人在部署配置里设置 ENTRY_URL 并重新发布`);
898
926
  return given.entry_url;
899
927
  }
@@ -113,15 +113,28 @@ function write_os_users(data, users) {
113
113
 
114
114
  const quote = text => `'${String(text).replaceAll("'", "''")}'`;
115
115
 
116
+ let elevated_already = null;
117
+
118
+ /**
119
+ * Whether this process already runs with administrator rights (an elevated terminal, or an administrator's SSH session,
120
+ * which Windows gives the full token): an elevated script then runs directly, with no prompt nobody could answer.
121
+ */
122
+ export function running_elevated() {
123
+ if (elevated_already === null) elevated_already = process.platform === 'win32' && spawnSync('net', ['session'], { stdio: 'ignore', windowsHide: true }).status === 0;
124
+ return elevated_already;
125
+ }
126
+
116
127
  /**
117
128
  * Run a PowerShell script and return what it printed.
118
129
  *
119
130
  * Args:
120
131
  * script: The script text; written to a file with a byte-order mark, since Windows PowerShell 5.1 reads one without it
121
132
  * in the ANSI code page.
122
- * elevated: Run through a UAC prompt; output then comes back through a file.
133
+ * elevated: Run through a UAC prompt (directly when this process is already elevated); output then comes back through
134
+ * a file.
123
135
  */
124
136
  export function run_powershell(script, { elevated = false, timeout = DEFAULT_TIMEOUT_MS } = {}) {
137
+ if (elevated && running_elevated()) elevated = false;
125
138
  mkdirSync(OWNER_JOB_ROOT, { recursive: true });
126
139
  const job = join(OWNER_JOB_ROOT, `owner-${process.pid}-${randomBytes(6).toString('hex')}`);
127
140
  mkdirSync(job);