ai_co_discuss 0.4.78 → 0.4.80

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.
Files changed (52) hide show
  1. package/.agents/skills/discuss-participant/SKILL.md +1 -0
  2. package/.agents/skills/local-tts-setup/SKILL.md +3 -2
  3. package/backend/external_members.py +27 -8
  4. package/backend/free_room.py +13 -1
  5. package/backend/message_queue.py +15 -5
  6. package/backend/schema.sql +3 -0
  7. package/backend/server.py +24 -3
  8. package/docs/deployment.md +1 -1
  9. package/docs/en/deployment.md +1 -1
  10. package/docs/en/runner.md +5 -2
  11. package/docs/runner.md +6 -3
  12. package/frontend/locales/en/admin.json +38 -11
  13. package/frontend/locales/en/app.json +1 -0
  14. package/frontend/locales/en/backend_worker.json +9 -5
  15. package/frontend/locales/en/core.json +3 -6
  16. package/frontend/locales/en/discussion.json +3 -2
  17. package/frontend/locales/en/external.json +21 -8
  18. package/frontend/locales/en/room.json +13 -8
  19. package/frontend/locales/en/settings.json +12 -1
  20. package/package.json +1 -1
  21. package/runner/adapters/api.mjs +8 -5
  22. package/runner/adapters/api_web.mjs +42 -63
  23. package/runner/adapters/claude.mjs +6 -1
  24. package/runner/adapters/cli.mjs +1 -1
  25. package/runner/adapters/codex_bridge.mjs +4 -3
  26. package/runner/adapters/codex_cli.mjs +65 -4
  27. package/runner/adapters/common.mjs +1 -1
  28. package/runner/adapters/profiles.mjs +16 -3
  29. package/runner/admin_cli.mjs +21 -5
  30. package/runner/admin_panel.mjs +56 -13
  31. package/runner/discuss.py +15 -3
  32. package/runner/discussion_launch.mjs +3 -3
  33. package/runner/execution_progress.mjs +7 -3
  34. package/runner/expert_prompts.mjs +8 -5
  35. package/runner/external_client.mjs +115 -26
  36. package/runner/external_gateway.mjs +9 -5
  37. package/runner/free_runner.mjs +1 -1
  38. package/runner/i18n_en.mjs +13 -9
  39. package/runner/os_users.mjs +15 -3
  40. package/runner/project_files.mjs +6 -5
  41. package/runner/tts_providers.mjs +22 -2
  42. package/web/admin.css +1 -1
  43. package/web/admin.js +3 -3
  44. package/web/app.js +162 -27
  45. package/web/backup.js +1 -1
  46. package/web/i18n.js +4 -4
  47. package/web/icons/custom-api.svg +11 -0
  48. package/web/icons/external-expert.svg +11 -0
  49. package/web/markdown.css +1 -1
  50. package/web/modern.css +1 -1
  51. package/web/modern.js +70 -65
  52. package/web/office/docx.js +3 -3
@@ -14,6 +14,7 @@ import { cli_delivery } from './cli.mjs';
14
14
  import { daemon_chat, daemon_link } from './codex_daemon.mjs';
15
15
  import { CALL_TIMEOUT_MS, edge_entries, launch_directory, log_entries, marked, model_entry, json_line, newest_record, not_sent,
16
16
  page_sessions, preview_messages, project_directory, prompt_text, prompt_title, query_catalog, same_path, typed_prompt } from './common.mjs';
17
+ import { adapter_capabilities } from './profiles.mjs';
17
18
 
18
19
  /** Codex exec may linger after its final event; the finished turn is already saved, so stop it to free the session. */
19
20
  const CLI_EXIT_GRACE_MS = 1500;
@@ -21,13 +22,69 @@ const CODEX_PERMISSIONS_MIN_MINOR = 163;
21
22
  const FORK_TIMEOUT_MS = 60_000;
22
23
  const CODEX_BRIDGE = fileURLToPath(new URL('./codex_bridge.mjs', import.meta.url));
23
24
 
25
+ const WINDOWS_SANDBOX_VALUE = String.raw`sandbox\s*=\s*["'](?:elevated|unelevated)["']`;
26
+ const WINDOWS_SANDBOX_TOP_LEVEL = new RegExp(String.raw`^windows(?:\.|\s*=\s*\{[^}]*\b)${WINDOWS_SANDBOX_VALUE}`);
27
+ const WINDOWS_SANDBOX_IN_SECTION = new RegExp(`^${WINDOWS_SANDBOX_VALUE}`);
28
+ let sandbox_lookup = { key: '', missing: false };
29
+
30
+ /** Whether a config.toml text chooses a Windows sandbox: `[windows] sandbox = …`, `windows.sandbox = …` or an inline table. */
31
+ function chooses_windows_sandbox(text) {
32
+ let section = '';
33
+ for (const line of text.split(/\r?\n/).map(item => item.trim())) {
34
+ const header = line.match(/^\[([^[\]]+)\]/);
35
+ if (header) section = header[1].trim();
36
+ else if (section === 'windows' ? WINDOWS_SANDBOX_IN_SECTION.test(line) : !section && WINDOWS_SANDBOX_TOP_LEVEL.test(line)) return true;
37
+ }
38
+ return false;
39
+ }
40
+
41
+ /**
42
+ * Whether Codex on this Windows computer has no sandbox chosen: with none it refuses every command before starting it
43
+ * (`rejected: blocked by policy`, tested 0.169.0 on 2026-11-18). Read again only when the file changes, as the room
44
+ * runner asks often. Other systems have their own sandbox.
45
+ */
46
+ export function codex_sandbox_missing(platform = process.platform, env = process.env) {
47
+ if (platform !== 'win32') return false;
48
+ const path = join(env.CODEX_HOME || join(homedir(), '.codex'), 'config.toml');
49
+ let key = `${path}:none`;
50
+ try { key = `${path}:${statSync(path).mtimeMs}`; } catch { /* no config file: nothing chosen */ }
51
+ if (key === sandbox_lookup.key) return sandbox_lookup.missing;
52
+ let text = '';
53
+ try { text = readFileSync(path, 'utf8'); } catch { /* no config file: nothing chosen */ }
54
+ sandbox_lookup = { key, missing: !chooses_windows_sandbox(text) };
55
+ return sandbox_lookup.missing;
56
+ }
57
+
58
+ /** 全放开, or a hosted background instance where the sandbox cannot start: its limits rest on the task's rules alone. */
59
+ function runs_unsandboxed(config) {
60
+ return config.project_access === 'full' || Boolean(adapter_capabilities('codex_cli').no_sandbox);
61
+ }
62
+
63
+ /**
64
+ * The system-level rule of a thread that runs without a sandbox, or ''. It stays with the thread for good while the room's
65
+ * access can change later, so it defers to what each task says.
66
+ */
67
+ export function codex_developer_instructions() {
68
+ return adapter_capabilities('codex_cli').no_sandbox
69
+ ? '这台电脑的后台环境没有 Codex 沙箱,系统不会拦截写入。任务说明写明项目文件只读时,只读全靠你遵守:不要创建、修改或删除项目文件,也不要运行会改动项目的命令,只在草稿目录写文件。' : '';
70
+ }
71
+
72
+ /**
73
+ * Why 只读 or 可写 cannot run on this computer, or ''. On a person's own computer nothing but the sandbox stands between
74
+ * Codex and all of that person's files, so its absence is reported instead of quietly running with full access.
75
+ */
76
+ export function codex_sandbox_refusal(config, platform = process.platform, env = process.env) {
77
+ if (runs_unsandboxed(config) || ['auto', 'own'].includes(config.project_access) || !codex_sandbox_missing(platform, env)) return '';
78
+ return '这台电脑的 Codex 还没有配置 Windows 沙箱,只读和可写权限无法生效,未交付任务。请在管理员终端运行 codex sandbox setup --elevated --current-user 配置沙箱,或把这位成员的项目权限改成“全放开”(Codex 将拥有当前 Windows 账号的全部权限)。';
79
+ }
80
+
24
81
  /**
25
82
  * Build a per-invocation profile without inheriting a user's custom profile of the same name. The room's other project
26
83
  * directories (`task.extra_directories`) get their own read or write entry.
27
84
  */
28
85
  export function codex_permissions(config, task, platform = process.platform) {
29
- // 全放开 runs without approval or sandbox, so there is no profile to build or check.
30
- if (config.project_access === 'full') return { name: '', args: ['--dangerously-bypass-approvals-and-sandbox'] };
86
+ // Running without approval or sandbox, there is no profile to build or check.
87
+ if (runs_unsandboxed(config)) return { name: '', args: ['--dangerously-bypass-approvals-and-sandbox'] };
31
88
  const name = `codiscuss-${randomUUID()}`;
32
89
  // A taken-over manual member writes like 可写: its own config may sandbox read-only and then could not save its answer draft.
33
90
  const base = ['auto', 'own'].includes(config.project_access) || (project_directory(config) && config.project_access === 'write')
@@ -111,10 +168,14 @@ async function check_codex_permissions(config, task, permissions, spawn_process)
111
168
  * thread; 全放开 has no profile and opens the thread without sandbox or approval instead.
112
169
  */
113
170
  function invocation(config, binding, task) {
171
+ const refusal = codex_sandbox_refusal(config);
172
+ if (refusal) throw not_sent(new Error(refusal));
114
173
  const permissions = codex_permissions(config, task);
115
- const full = config.project_access === 'full';
174
+ const full = runs_unsandboxed(config);
175
+ const developer_instructions = codex_developer_instructions();
116
176
  const input = `${JSON.stringify({ prompt: task.prompt, thread_id: binding.session_id || '', cwd: launch_directory(config, task),
117
- model: config.model || '', effort: config.effort || '', full, ...(task.images?.length ? { images: task.images.map(image => image.path) } : {}) })}\n`;
177
+ model: config.model || '', effort: config.effort || '', full, ...(developer_instructions ? { developer_instructions } : {}),
178
+ ...(task.images?.length ? { images: task.images.map(image => image.path) } : {}) })}\n`;
118
179
  return { executable: process.execPath, args: [CODEX_BRIDGE, config.executable, ...(full ? [] : permissions.args)], input,
119
180
  steer: text => `${JSON.stringify({ steer: text })}\n`,
120
181
  ...(permissions.name ? { check: spawn_process => check_codex_permissions(config, task, permissions, spawn_process) } : {}) };
@@ -113,7 +113,7 @@ export function watch_events(adapter, stream, task) {
113
113
  let event;
114
114
  try { event = JSON.parse(line); } catch { return; }
115
115
  const phase = adapter.events.phase(event);
116
- if (phase) task.on_activity?.(phase, adapter.events.tool(event));
116
+ if (phase) task.on_activity?.(phase, adapter.events.tool(event), adapter.events.call?.(event));
117
117
  const note = adapter.events.note(event);
118
118
  if (note) task.on_note?.(note);
119
119
  report_edits(adapter, event, task);
@@ -45,8 +45,17 @@
45
45
  * - `session_family`: profiles sharing one session store; switching among them keeps the conversation.
46
46
  * - `windows_command`: how its shell names the codiscuss CLI on Windows.
47
47
  * - `task_rules(cli, {runs_commands})`: fixed task text this software needs, added by the runner so no member prompt drops it.
48
+ * - `sandbox_needs_desktop`: its sandbox cannot start in a background session without a desktop, so there it runs without
49
+ * one and `adapter_capabilities` reports `no_sandbox` and no enforced limits (see `NO_DESKTOP_VARIABLE`).
48
50
  */
49
51
  const ALL_ACCESS = ['read', 'write', 'auto', 'full'];
52
+ /**
53
+ * Set to '1' by the start script of an instance running as a background task of its own Windows user. Codex CLI 0.169's
54
+ * sandbox process exits with 0xC0000142 there, while the same settings start on a desktop (tested 2026-11-18).
55
+ */
56
+ export const NO_DESKTOP_VARIABLE = 'CODISCUSS_NO_DESKTOP';
57
+ // The web page bundles this file and has no process.
58
+ const no_desktop = () => globalThis.process?.env?.[NO_DESKTOP_VARIABLE] === '1';
50
59
  /** API slot defaults; identity and wire protocol stay independent, and a custom slot starts without a provider. */
51
60
  export const API_PROVIDERS = {
52
61
  Codex: { label: 'OpenAI', base_url: 'https://api.openai.com/v1', api_protocol: 'responses', models: ['gpt-6.1-sol', 'gpt-6-astra', 'gpt-6-luna'] },
@@ -82,6 +91,7 @@ export const ADAPTER_PROFILES = {
82
91
  auto: '沙箱外的操作由模型申请提权,Codex 自动审核代替人工批准', full: '无沙箱、无审批(--dangerously-bypass-approvals-and-sandbox)' },
83
92
  client: 'codex', adopt: 'session', host_existing: true, session_family: 'codex', browse_sessions: true,
84
93
  lockdown_hint: '沙箱只读档仍可读整个磁盘、运行任意只读命令,无法只放行 codiscuss 命令',
94
+ sandbox_needs_desktop: true,
85
95
  capabilities: { delivery: PROCESS, rewind: 'cut', project: true, access_env: true, enforces_read_only: true, limits_directories: true, ripgrep: true, chat: true, resume: true, images: true, capture: FINAL_REMARK,
86
96
  tool_lockdown: false,
87
97
  // Codex CLI 0.163 records a command's output in its session about 0.1 s after reporting it done (2026-11-15).
@@ -136,8 +146,8 @@ export const ADAPTER_PROFILES = {
136
146
  // Pi passes the level as each protocol's own reasoning parameter; it clamps xhigh / max to high without a per-model map,
137
147
  // so only the three levels every protocol takes are offered. A chat endpoint without a reasoning parameter ignores it.
138
148
  efforts: ['low', 'medium', 'high'], models: false, access_levels: ['read', 'write'], per_tool_allow: false, adopt: '', host_existing: false,
139
- access_hints: { read: '可联网搜索和读取网页,用接入程序的文件工具读取、搜索项目文件,可运行工作流登记的只读命令',
140
- write: '可联网搜索和读取网页,用 Pi 自带的读写、编辑与命令行在项目里工作,和本地 CLI 可写一致;Pi 没有审批,可写即可直接运行命令' },
149
+ access_hints: { read: '可读取网页,本机保存了 DeepSeek API Key 时可联网搜索(由 DeepSeek 计费);用接入程序的文件工具读取、搜索项目文件,可运行工作流登记的只读命令',
150
+ write: '可读取网页,本机保存了 DeepSeek API Key 时可联网搜索(由 DeepSeek 计费);用 Pi 自带的读写、编辑与命令行在项目里工作,和本地 CLI 可写一致;Pi 没有审批,可写即可直接运行命令' },
141
151
  unsupported_hints: { auto: 'Pi 没有需要软件审批的操作,可写即可直接运行命令', full: 'Pi 没有需要软件审批的操作,可写即可直接运行命令' },
142
152
  // Runs in the Pi harness (api_pi.mjs), which keeps a session the runner cuts like a CLI's.
143
153
  // Whether a model reads images depends on the model, not the protocol: the owner says so on the card (`image_input`).
@@ -190,5 +200,8 @@ export function lockdown_support(id, config = {}) {
190
200
 
191
201
  /** What an adapter can do; an unknown adapter can do nothing. */
192
202
  export function adapter_capabilities(id) {
193
- return ADAPTER_PROFILES[id]?.capabilities || { delivery: IN_APP, rewind: 'kept', project: false, capture: false };
203
+ const profile = ADAPTER_PROFILES[id];
204
+ if (!profile) return { delivery: IN_APP, rewind: 'kept', project: false, capture: false };
205
+ return profile.sandbox_needs_desktop && no_desktop()
206
+ ? { ...profile.capabilities, no_sandbox: true, enforces_read_only: false, limits_directories: false } : profile.capabilities;
194
207
  }
@@ -47,11 +47,15 @@ export const HELP = t(`用法:codiscuss admin <命令> [参数](与管理面
47
47
  service start|stop|restart 只启停共议服务(网站与讨论服务)
48
48
  autostart on|off 登录 Windows 时自动启动
49
49
 
50
+ 管理员入口
51
+ site status 本地网页与线上网站的地址
52
+ site connect <站点> [绑定令牌] 绑定线上网站(管理员外出用);在部署该网站的电脑上可不填令牌
53
+ site disconnect 解绑线上网站,已配对的设备不能再连到这台电脑
54
+
50
55
  登录入口与访问方式(需打开托管管理)
51
56
  entry start|stop 启动或停止登录入口
52
- entry open|close relay|tunnel 开启或关闭访问方式:线上中转 | 自有域名,两种可同时开启
53
- entry join <接入码> 用接入码接入线上站点并开启线上中转
54
- entry connect <站点> <绑定令牌> 只绑定线上站点(管理员远程用),不改访问方式
57
+ entry open|close relay|tunnel 开启或关闭访问方式:线上网站 | 自有域名,两种可同时开启
58
+ entry join <接入码> 用接入码接入线上站点并开启线上网站
55
59
  entry code [--config <wrangler.jsonc>] [--site <地址>] 在部署线上站点的电脑上生成接入码(不填用上次的)
56
60
  entry tunnel <域名> [隧道名] 设置自有域名(Cloudflare 隧道),输出授权链接;域名须已托管在 Cloudflare
57
61
  entry tunnel status 查看自有域名设置的进度
@@ -331,12 +335,22 @@ async function entry_command(call, [action, first, second], values) {
331
335
  if (action === 'start' || action === 'stop') return call(`entry/${action}`, {});
332
336
  if (action === 'open' || action === 'close') return call('entry/way', { way: need(first, 'relay|tunnel'), enabled: action === 'open' });
333
337
  if (action === 'join') return call('relay/join', { code: need(first, t('接入码')) });
334
- if (action === 'connect') return call('site/connect', { site: need(first, t('站点')), setup_key: need(second, t('绑定令牌')) });
335
338
  if (action === 'code') return call('site/code', { config: values.config || '', site: values.site || '' });
336
339
  if (action === 'tunnel') return first === 'status' ? call('tunnel/setup') : setup_tunnel(call, need(first, t('域名')), second || '');
337
340
  throw new Error(HELP);
338
341
  }
339
342
 
343
+ /** The owner's own ways in: the local page and the online site this computer is bound to. */
344
+ async function site_command(call, [action, first, second]) {
345
+ if (!action || action === 'status') {
346
+ const state = await call('state');
347
+ return { local: state.service.url || null, online: state.online_site || null };
348
+ }
349
+ if (action === 'connect') return call('site/connect', { site: need(first, t('站点')), setup_key: second || '' });
350
+ if (action === 'disconnect') return call('site/disconnect', {});
351
+ throw new Error(HELP);
352
+ }
353
+
340
354
  /** Start setting up the owner's domain and wait for the Cloudflare authorization link (or the end). */
341
355
  async function setup_tunnel(call, host, name) {
342
356
  await call('tunnel/setup', { host, name });
@@ -355,8 +369,9 @@ function summary(state) {
355
369
  const tunnel = entry?.tunnel ? (entry.tunnel.connected ? t('已连接') : entry.tunnel.running ? t('连接中') : t('未运行')) : undefined;
356
370
  return { hosting: state.hosting, version: state.version, autostart: state.autostart,
357
371
  service: { running: service.running, url: service.url, version: service.version, error: service.error || undefined },
372
+ online_site: state.online_site || undefined,
358
373
  ...(state.hosting ? {
359
- entry: entry && { running: entry.running, relay_enabled: entry.relay_enabled, tunnel_enabled: entry.tunnel_enabled, address: entry.address || `http://127.0.0.1:${entry.port}`, tunnel, problem: entry.relay?.problem || undefined },
374
+ entry: entry && { running: entry.running, relay_enabled: entry.relay_enabled, tunnel_enabled: entry.tunnel_enabled, address: entry.address || undefined, tunnel, problem: entry.relay?.problem || undefined },
360
375
  runtime: state.clis,
361
376
  accounts: state.accounts.map(item => ({ name: item.name, isolated: Boolean(item.os_user), protected: item.protected, running: item.running, disabled: item.disabled })),
362
377
  } : {}) };
@@ -404,6 +419,7 @@ export async function admin_cli(args, { client = panel_client, print = text => p
404
419
  service: () => call(`service/${need(rest[0], 'start|stop|restart')}`, {}),
405
420
  autostart: () => call('autostart', { on: need(rest[0], 'on|off') === 'on' }),
406
421
  update: () => (rest[0] === 'check' ? call('update/check') : update(call, data)),
422
+ site: () => site_command(call, rest),
407
423
  entry: () => entry_command(call, rest, values),
408
424
  runtime: () => (rest[0] === 'sync' ? call('clis/install', {}) : Promise.reject(new Error(HELP))),
409
425
  account: () => account_command(call, rest, values),
@@ -30,7 +30,7 @@ import { clear_instance_flag, create_os_user, install_shared_runtime, instance_k
30
30
  import { install_workflows, shipped_workflows } from './discussion_skills.mjs';
31
31
  import { list_workflows, workflows_home } from './workflows.mjs';
32
32
  import { hosted_prompt, import_skill, library_root, list_library, remove_library_skill, save_hosted_prompt } from './skill_library.mjs';
33
- import { local_status } from './discussion_local.mjs';
33
+ import { local_status, save_site_connection } from './discussion_local.mjs';
34
34
  import { autostart_enabled, launcher_path, set_autostart } from './launcher.mjs';
35
35
  import { show_tray } from './tray.mjs';
36
36
  import { OPERATOR_EVENTS_FILE } from './account_space.mjs';
@@ -56,6 +56,8 @@ const STATE_FILE = 'admin-panel.json';
56
56
  // unfinished one blocks another.
57
57
  const UPDATE_JOB_FILE = 'panel-update.json';
58
58
  const UPDATE_STALE_MS = 10 * 60 * 1000;
59
+ // How often a running panel looks for an install to finish: one started during the install never gets the updater's start.
60
+ const UPDATE_FINISH_CHECK_MS = 3000;
59
61
  const OWNER_ENV_TIMEOUT_MS = 120_000;
60
62
  // 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.
61
63
  const TUNNEL_CHECK_MS = 60_000;
@@ -107,10 +109,10 @@ let latest = { at: 0, version: '' };
107
109
  * while the next one answers in under two (seen 2026-11-14). Failing is reported naming the host, not as a problem of
108
110
  * the site.
109
111
  */
110
- async function fetch_outside(url, timeout_ms) {
112
+ async function fetch_outside(url, timeout_ms, init = {}) {
111
113
  for (let attempt = 1; ; attempt += 1) {
112
114
  try {
113
- return await fetch(url, { signal: AbortSignal.timeout(timeout_ms) });
115
+ return await fetch(url, { ...init, signal: AbortSignal.timeout(timeout_ms) });
114
116
  } catch (error) {
115
117
  const timed_out = error.name === 'TimeoutError';
116
118
  if (attempt < OUTSIDE_ATTEMPTS) continue;
@@ -129,6 +131,12 @@ async function latest_version(force = false) {
129
131
  return latest.version;
130
132
  }
131
133
 
134
+ /** Refuse an update npm cannot deliver yet, before anything is stopped: a new version is listed minutes before its package downloads. */
135
+ async function check_package(version) {
136
+ const response = await fetch_outside(`https://registry.npmjs.org/${NPM_PACKAGE}/-/${NPM_PACKAGE}-${version}.tgz`, OUTSIDE_TIMEOUT_MS, { method: 'HEAD' });
137
+ if (response.status === 404) throw panel_error('v{value1} 刚发布,npm 还在准备安装包,请过几分钟再更新;当前版本和服务没有受影响', { value1: version });
138
+ }
139
+
132
140
  /** Whether version a is newer than b (plain x.y.z). */
133
141
  export function newer_version(a, b) {
134
142
  const left = String(a).split('.').map(Number), right = String(b).split('.').map(Number);
@@ -228,7 +236,7 @@ async function finish_update(data) {
228
236
  // The panel itself starts an entry left on (run_panel); the report says once it serves again.
229
237
  if (hosting_enabled(data) && entry_settings(data).running) await update_step(steps, t('已重新启动登录入口'), async () => {
230
238
  for (let waited = 0; waited < ENTRY_BACK_MS; waited += 500) { if ((await entry_status(data)).running) return; await new Promise(done => setTimeout(done, 500)); }
231
- throw panel_error('入口没有重新启动,在“概览”页“托管”下点“启动”看原因');
239
+ throw panel_error('入口没有重新启动,在“概览 → 登录入口 → 托管账号入口”点“启动”看原因');
232
240
  });
233
241
  if (hosting_enabled(data)) {
234
242
  const accounts = await list_accounts(data);
@@ -392,7 +400,7 @@ function install_runtime(data) {
392
400
  */
393
401
  function account_env(data, name, action, request = {}, folders = {}) {
394
402
  const { env_script } = shared_paths();
395
- if (!existsSync(env_script)) throw panel_error('还没有安装隔离账号的程序副本,请先在“概览 → 托管 → 程序副本”中同步');
403
+ if (!existsSync(env_script)) throw panel_error('还没有安装隔离账号的程序副本,请先在“概览 → 登录入口 → 托管账号入口”中同步');
396
404
  const text = run_as_user(data, name, `& ${ps_quote(process.execPath)} ${ps_quote(env_script)} ${action} $Job`,
397
405
  { files: { 'request.json': JSON.stringify(request) }, folders, timeout: 120_000 });
398
406
  const line = text.split(/\r?\n/).reverse().find(item => item.trim().startsWith('{'));
@@ -546,11 +554,11 @@ function run_instance(data, name, command) {
546
554
  // An account without its own Windows user runs as the owner and could read everything the owner can; it is not let
547
555
  // run while people outside can reach the entry.
548
556
  if (command === 'start' && process.platform === 'win32' && !read_os_users(data)[name] && (entry_settings(data).relay_enabled || entry_settings(data).tunnel_enabled)) {
549
- throw panel_error('外网访问已开启,{value1} 未隔离(以你的身份运行),不能启动:请先隔离该账号,或关闭登录入口的线上中转和自有域名', { value1: name });
557
+ throw panel_error('外网访问已开启,{value1} 未隔离(以你的身份运行),不能启动:请先隔离该账号,或关闭登录入口的线上网站和自有域名', { value1: name });
550
558
  }
551
559
  if (command === 'start' && read_os_users(data)[name]) {
552
560
  const { local_script } = shared_paths();
553
- if (!existsSync(local_script)) throw panel_error('还没有安装隔离账号的程序副本,请先在“概览 → 托管 → 程序副本”中同步');
561
+ if (!existsSync(local_script)) throw panel_error('还没有安装隔离账号的程序副本,请先在“概览 → 登录入口 → 托管账号入口”中同步');
554
562
  // Whatever was set up first, the instance starts on the shared copies its Windows user can run.
555
563
  use_shared_programs(data, name);
556
564
  return start_instance_as_user(data, name, service, local_script, process.execPath, { key_file });
@@ -645,7 +653,7 @@ function cookie(request, name) {
645
653
  export function create_panel({ data, key, port, ops = {}, sessions = new Set() }) {
646
654
  const op = { list_accounts, add_account, reset_password, set_account_disabled, remove_account, run_instance, create_os_user, remove_os_user,
647
655
  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, owner_prompts, save_owner_prompt, shared_cli_state,
648
- save_api_key, list_keys, remove_key, use_shared_programs, service_overview, run_owner_service, latest_version, begin_update,
656
+ save_api_key, list_keys, remove_key, use_shared_programs, service_overview, run_owner_service, latest_version, check_package, begin_update,
649
657
  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 };
650
658
  const hosts = new Set([`127.0.0.1:${port}`, `localhost:${port}`]);
651
659
 
@@ -656,7 +664,7 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
656
664
  const hosting = hosting_enabled(data);
657
665
  if (method === 'GET' && section === 'state') {
658
666
  const windows = process.platform === 'win32';
659
- return { hosting, version: VERSION, service: op.service_overview(data), platform: process.platform,
667
+ return { hosting, version: VERSION, service: op.service_overview(data), online_site: bound_site(data)?.site || '', platform: process.platform,
660
668
  launcher: windows && existsSync(launcher_path(data)), autostart: windows && op.autostart_enabled(), login_methods: LOGIN_METHODS, providers: API_PROVIDERS,
661
669
  ...(hosting ? { accounts: await op.list_accounts(data), clis: op.shared_cli_state(), entry: await op.entry_overview(data) }
662
670
  : { accounts: [], clis: {}, entry: null }) };
@@ -674,7 +682,11 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
674
682
  const current = op.service_overview(data).version || VERSION, version = await op.latest_version(name === 'check');
675
683
  return { current, latest: version, available: newer_version(version, current) };
676
684
  }
677
- if (method === 'POST' && section === 'update') return op.begin_update(data, await op.latest_version(true), op.hand_over);
685
+ if (method === 'POST' && section === 'update') {
686
+ const version = await op.latest_version(true);
687
+ await op.check_package(version);
688
+ return op.begin_update(data, version, op.hand_over);
689
+ }
678
690
  if (method === 'POST' && section === 'autostart') return { autostart: op.set_autostart(Boolean(body.on), data) };
679
691
  // Command-line sign-in: '_' is the owner; an account name is a hosted account with its own Windows user.
680
692
  if (section === 'login-jobs') {
@@ -711,6 +723,9 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
711
723
  if (method === 'POST' && !name) return import_skill(data, body);
712
724
  if (method === 'POST' && action === 'remove') { remove_library_skill(data, name); return { ok: true }; }
713
725
  }
726
+ // The owner's own online site: bound, checked and left here whether or not this computer hosts accounts.
727
+ if (method === 'POST' && section === 'site' && name === 'connect') return bind_online_site(data, body, op.connect_site);
728
+ if (method === 'POST' && section === 'site' && name === 'disconnect') return disconnect_site(data);
714
729
  // Hosting: only once the owner turned it on in setup.
715
730
  if (!hosting) throw panel_error('托管管理未打开:运行 codiscuss setup 勾选“托管管理(管理面板)”');
716
731
  if (method === 'POST' && section === 'clis' && name === 'install') return op.install_runtime(data);
@@ -725,7 +740,6 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
725
740
  // How people outside reach the entry, the relay's entry address, and binding this computer to an online site.
726
741
  if (method === 'POST' && section === 'entry' && name === 'way') return op.set_entry_way(data, String(body.way || ''), body.enabled === true);
727
742
  if (method === 'POST' && section === 'entry' && name === 'relay') return op.set_relay_url(data, body.url);
728
- if (method === 'POST' && section === 'site' && name === 'connect') return op.connect_site(data, body.site, body.setup_key);
729
743
  // The access code: made on the computer that deployed the online site, pasted on a hosting computer.
730
744
  if (method === 'GET' && section === 'site' && name === 'code') return { ...deploy_settings(data), site: deploy_settings(data).site || bound_site(data)?.site || '' };
731
745
  if (method === 'POST' && section === 'site' && name === 'code') return op.make_access_code(data, body);
@@ -877,7 +891,7 @@ async function prepare_entry_way(data, way) {
877
891
  const users = read_os_users(data), accounts = read_accounts(data);
878
892
  const exposed = [];
879
893
  for (const [name, account] of Object.entries(accounts)) if (!users[name] && await instance_running(account.port)) exposed.push(name);
880
- if (exposed.length) throw panel_error('未隔离的账号正在运行({value1}),它们以你的身份运行,开启线上中转或自有域名前请先停止或隔离', { value1: exposed.join('、') });
894
+ if (exposed.length) throw panel_error('未隔离的账号正在运行({value1}),它们以你的身份运行,开启线上网站或自有域名前请先停止或隔离', { value1: exposed.join('、') });
881
895
  }
882
896
  }
883
897
 
@@ -891,6 +905,12 @@ async function set_entry_way(data, way, enabled) {
891
905
  if (enabled) await prepare_entry_way(data, way);
892
906
  save_entry_settings(data, { [`${way}_enabled`]: enabled });
893
907
  if (enabled && !(await entry_status(data)).running) { await start_entry(data); save_entry_settings(data, { running: true }); }
908
+ // With no way left on nobody can reach the entry, so it does not keep running.
909
+ const settings = entry_settings(data);
910
+ if (!enabled && !settings.relay_enabled && !settings.tunnel_enabled) {
911
+ if ((await entry_status(data)).running) await stop_entry(data);
912
+ save_entry_settings(data, { running: false });
913
+ }
894
914
  if (enabled && way === 'relay' && !local_status(data).running) await run_owner_service(data, 'start');
895
915
  await keep_tunnel(data);
896
916
  return entry_overview(data);
@@ -954,7 +974,7 @@ async function join_relay(data, text) {
954
974
  await set_relay_url(data, entry_url);
955
975
  steps.push(t('入口地址 {value1}', { value1: entry_url }));
956
976
  const overview = await set_entry_way(data, 'relay', true);
957
- steps.push(t('已开启线上中转'));
977
+ steps.push(t('已开启线上网站'));
958
978
  return { steps, entry: overview };
959
979
  }
960
980
 
@@ -988,6 +1008,26 @@ function connect_site(data, site, setup_key) {
988
1008
  });
989
1009
  }
990
1010
 
1011
+ /** Bind this computer to the owner's online site; it has one at a time, and the address must be such a site. */
1012
+ async function bind_online_site(data, { site, setup_key }, connect) {
1013
+ const bound = bound_site(data);
1014
+ let origin;
1015
+ try { origin = new URL(String(site || '').trim()).origin; } catch { throw panel_error('站点地址格式不对,例如 https://xxx.pages.dev'); }
1016
+ if (bound && bound.site !== origin) throw panel_error('这台电脑已绑定 {value1},请先解绑', { value1: bound.site });
1017
+ const result = await connect(data, origin, setup_key);
1018
+ if (!result) throw panel_error('这个地址不是共议线上站点:{value1}', { value1: origin });
1019
+ return result;
1020
+ }
1021
+
1022
+ /** Leave the online site: its paired devices can no longer reach this computer. The hosted accounts' address depends on it. */
1023
+ function disconnect_site(data) {
1024
+ const bound = bound_site(data);
1025
+ if (!bound) return { disconnected: '' };
1026
+ if (entry_settings(data).relay_enabled) throw panel_error('托管账号入口的线上网站还开着,请先关闭它');
1027
+ save_site_connection(data, bound.site);
1028
+ return { disconnected: bound.site };
1029
+ }
1030
+
991
1031
  // ---- Hosted accounts' failures, to the owner's Weixin ----
992
1032
 
993
1033
  /** Whether two paths name the same place, as written (Windows paths compare without regard to case). */
@@ -1230,6 +1270,8 @@ function run_panel(data, port) {
1230
1270
  const keeper = setInterval(keep, TUNNEL_CHECK_MS);
1231
1271
  // Hosted accounts' failures reach the owner's Weixin; one pass at a time.
1232
1272
  let relaying = false;
1273
+ const finisher = setInterval(() => finish_update(data).catch(error => process.stderr.write(t(`更新收尾失败:{value1}
1274
+ `, { value1: error.message }))), UPDATE_FINISH_CHECK_MS);
1233
1275
  const relay = setInterval(() => {
1234
1276
  if (relaying) return;
1235
1277
  relaying = true;
@@ -1265,6 +1307,7 @@ function run_panel(data, port) {
1265
1307
  } });
1266
1308
  function shutdown(exit = true) {
1267
1309
  clearInterval(relay);
1310
+ clearInterval(finisher);
1268
1311
  // The tunnel runs on without the panel, like the entry.
1269
1312
  clearInterval(keeper);
1270
1313
  tray?.close();
package/runner/discuss.py CHANGED
@@ -32,6 +32,9 @@ MAX_ATTACHMENT_BYTES = 20 * 1024 * 1024
32
32
  MAX_MESSAGE_ATTACHMENTS = 10
33
33
  # Environment variables a hosting AI session exposes its own ID through, with the client name the room records.
34
34
  SESSION_VARIABLES = (("CLAUDE_CODE_SESSION_ID", "claude"), ("CODEX_THREAD_ID", "codex"), ("ANTIGRAVITY_CONVERSATION_ID", "antigravity"))
35
+ READ_ONLY_HEADER = "X-Discussion-Read-Only"
36
+ # What a room-scoped credential may read beyond its room on its site: the room list and every room's read routes.
37
+ CROSS_ROOM_READ_PATH = re.compile(r"/api/rooms(?:/[^/]+(?:/.*)?)?|/r/[^/]+(?:/.*)?")
35
38
  MAX_TEXT_LENGTH = 32000
36
39
  MAX_SUMMARY_LENGTH = 1000
37
40
  MAX_BRIEF_LENGTH = 1600
@@ -1647,8 +1650,15 @@ def finish_creation_access(args, site, plan, value):
1647
1650
  return {"owner_access_file": str(path), "member_access_files": paths}
1648
1651
 
1649
1652
 
1650
- def access_headers(args, site, path):
1651
- """Load a room-scoped secret only for its exact site and room."""
1653
+ def cross_room_read(access, site, method, target):
1654
+ """Whether this is a plain read of another room on the credential's own site, outside a restricted run."""
1655
+ restricted = os.getenv("CODISCUSS_TOOL_LOCKDOWN") == "1" or access.get("tool_lockdown")
1656
+ return (method == "GET" and not restricted and access.get("site", "").rstrip("/") == site
1657
+ and CROSS_ROOM_READ_PATH.fullmatch(target) is not None)
1658
+
1659
+
1660
+ def access_headers(args, site, path, method="GET"):
1661
+ """Load a room-scoped secret only for its exact site and room; another room is read without it, declared read-only."""
1652
1662
  access = load_access(args)
1653
1663
  if not access:
1654
1664
  return {}
@@ -1657,6 +1667,8 @@ def access_headers(args, site, path):
1657
1667
  creation = target == "/api/rooms" and bool(access.get("submission_id"))
1658
1668
  reading = f"/r/{access.get('room', '')}"
1659
1669
  if access.get("site", "").rstrip("/") != site or not (creation or target == expected or target.startswith(expected + "/") or target == reading or target.startswith(reading + "/")):
1670
+ if cross_room_read(access, site, method, target):
1671
+ return {READ_ONLY_HEADER: "1"}
1660
1672
  raise CliError("凭据文件不属于本次站点和房间")
1661
1673
  token = access.get("token")
1662
1674
  if not isinstance(token, str) or not 32 <= len(token) <= 256:
@@ -1783,7 +1795,7 @@ def run(args, registry):
1783
1795
  # The member-scope routes answer in their own shape (子Task1 CONTRACT §3); it is passed on as is.
1784
1796
  result = external_send(plan, access, timeout)
1785
1797
  else:
1786
- headers = access_headers(args, site, plan.path)
1798
+ headers = access_headers(args, site, plan.path, plan.method)
1787
1799
  value = send_request(plan, url, timeout, headers) if headers else send_request(plan, url, timeout)
1788
1800
  result = project_result(value, plan, site)
1789
1801
  if getattr(args, "operation", "") == "room create":
@@ -16,7 +16,7 @@ import { guard_remote_request, list_remote_directories, remote_allows, remote_ro
16
16
  import { list_devices, machine_fingerprint, revoke_device, start_pairing } from './device_auth.mjs';
17
17
  import { setup_sidecar } from './adapters/antigravity_app.mjs';
18
18
  import { adapter_of, adoption_adapter, BRANCHABLE_ADAPTERS, branch_session, execution_details, session_preview, session_settings, software_defaults, software_defaults_stamp, software_effort, software_models, software_sessions, software_skills } from './adapters/index.mjs';
19
- import { ADAPTER_IDS, ADAPTER_PROFILES, adapter_profile, DEFAULT_API_MAX_REQUESTS, MAX_API_MAX_REQUESTS, platform_adapters, same_session_family } from './adapters/profiles.mjs';
19
+ import { ADAPTER_IDS, ADAPTER_PROFILES, adapter_capabilities, adapter_profile, DEFAULT_API_MAX_REQUESTS, MAX_API_MAX_REQUESTS, platform_adapters, same_session_family } from './adapters/profiles.mjs';
20
20
  import { API_PROVIDERS, api_check, api_models, managed_api_keys, save_api_key, saved_api_keys, validate_api_profile } from './discussion_api.mjs';
21
21
  import { DEFAULT_SCHEDULER_MODE, SCHEDULER_MODES, SCHEDULER_PROVIDERS, scheduler_check } from './scheduler.mjs';
22
22
  import { save_tts_settings, tts_release, tts_settings, tts_speak } from './tts.mjs';
@@ -134,7 +134,7 @@ pick-directory 在本机弹出系统目录选择窗口,返回所选路径;
134
134
  browse-directory 列出常用项目及其中的子文件夹(只含文件夹名,分页),供其他设备选择目录;path 为空时列出常用项目。
135
135
  device-pairing 在本机生成 12 位设备配对码(2 分钟有效,可选 temporary 临时设备、without_passkey 允许这次配对不用通行密钥、site 指定已绑定的网站),扫码链接带本机密钥指纹;只能在这台电脑上执行,新设备只能在电脑前添加。
136
136
  devices 列出已配对设备;提供 revoke(设备 id)撤销设备。
137
- ${t("room-invite 创建待签到席位并签发邀请;提供 member_id 时重发该席位链接,旧链接失效。须提供 room_id、token,可选 level(discuss/read)、folders、duration(1h/today/3d)、site_url;程序先读名单 revision 再建席位。链接有效 10 分钟,未签到席位 7 天结束;未绑定线上站点时只建立席位。")}
137
+ ${t("room-invite 创建待签到席位并签发邀请;提供 member_id 时重发该席位链接,旧链接失效。须提供 room_id、token,可选 level(discuss/read)、folders、duration(1h/today/3d/7d/30d)、site_url;程序先读名单 revision 再建席位。链接有效 10 分钟,未签到席位 7 天结束;未绑定线上站点时只建立席位。")}
138
138
  room-invites 列出房间未兑换的邀请(不含配对码);须提供 room_id、token。
139
139
  room-invite-revoke 撤销一条未兑换的邀请;须提供 room_id、token、invite_id。
140
140
  projects 读取本机已配置的项目(名称与绝对路径);提供 JSON(projects 列表)时整体替换保存。
@@ -2390,7 +2390,7 @@ export async function launch_main(args = process.argv.slice(2), input_text) {
2390
2390
  }
2391
2391
  let result;
2392
2392
  if (positionals[0] === 'settings') result = { ...(input ? save_launch_settings(home, input) : launch_settings(home)), api_providers: API_PROVIDERS,
2393
- scheduler_providers: SCHEDULER_PROVIDERS, scheduler_modes: SCHEDULER_MODES, scheduler_default_mode: DEFAULT_SCHEDULER_MODE, api_keys: saved_api_keys(home), managed_api_keys: restricted ? managed_api_keys(home) : [], projects: launch_projects(home).projects, projects_restricted: restricted, workspace: space.workspace, user_home: restricted ? homedir() : '', ...expert_presets(home), ...workflow_library(home) };
2393
+ scheduler_providers: SCHEDULER_PROVIDERS, scheduler_modes: SCHEDULER_MODES, scheduler_default_mode: DEFAULT_SCHEDULER_MODE, api_keys: saved_api_keys(home), managed_api_keys: restricted ? managed_api_keys(home) : [], projects: launch_projects(home).projects, projects_restricted: restricted, full_access_only: ADAPTER_IDS.filter(id => adapter_capabilities(id).no_sandbox), workspace: space.workspace, user_home: restricted ? homedir() : '', ...expert_presets(home), ...workflow_library(home) };
2394
2394
  else if (positionals[0] === 'projects') result = input ? save_launch_projects(home, input) : launch_projects(home);
2395
2395
  else if (positionals[0] === 'presets') result = input ? save_expert_presets(home, input) : expert_presets(home);
2396
2396
  else if (positionals[0] === 'workflows') result = await workflows_command(home, input || {});
@@ -35,15 +35,19 @@ export class SegmentLog {
35
35
  log.next_note += 1;
36
36
  log.notes.push({ seq: log.next_note, text: text.slice(0, MAX_NOTE_LENGTH).replace(/[\uD800-\uDBFF]$/, '') });
37
37
  }
38
- /** The software produced output now; a phase, when the output names one, starts a new segment unless it continues the open one. */
39
- mark(id, phase = '', tool = '') {
38
+ /**
39
+ * The software produced output now; a phase, when the output names one, starts a new segment unless it continues the
40
+ * open one. `call` names one tool call where the software says so: calls of one tool in a row are then counted apart.
41
+ */
42
+ mark(id, phase = '', tool = '', call = '') {
40
43
  const log = this.executions.get(id);
41
44
  if (!log) return;
42
45
  log.last = this.now() - log.origin;
43
46
  if (log.open) log.open.end_ms = log.last;
44
47
  if (!phase) return;
45
48
  tool = tool.slice(0, MAX_SEGMENT_TOOL).replace(/[\uD800-\uDBFF]$/, '');
46
- if (log.open?.phase === phase && log.open.tool === tool) return;
49
+ if (log.open?.phase === phase && log.open.tool === tool && (!call || call === log.open_call)) return;
50
+ log.open_call = call;
47
51
  if (log.open) log.closed.push(log.open);
48
52
  log.open = null;
49
53
  if (log.next_seq >= MAX_EXECUTION_SEGMENTS) return;
@@ -60,13 +60,16 @@ export function access_levels(adapter) {
60
60
 
61
61
  /**
62
62
  * All four levels labelled for the page, with what each does in this software on hover; ones it lacks are shown but
63
- * disabled, so every CLI card lines up the same four levels.
63
+ * disabled, so every CLI card lines up the same four levels. `full_only_hint`, given where this computer can run the
64
+ * software only without its sandbox, disables every level but 全放开 and says why.
64
65
  */
65
- export function access_options(adapter) {
66
+ export function access_options(adapter, full_only_hint = '') {
66
67
  const levels = access_levels(adapter), profile = adapter_profile(adapter);
67
- return PROJECT_ACCESS.map(value => levels.includes(value)
68
- ? { value, label: ACCESS_LABELS[value], hint: profile?.access_hints?.[value] || '' }
69
- : { value, label: ACCESS_LABELS[value], hint: profile?.unsupported_hints?.[value] || '该软件不支持此档位', disabled: true });
68
+ return PROJECT_ACCESS.map(value => {
69
+ if (!levels.includes(value)) return { value, label: ACCESS_LABELS[value], hint: profile?.unsupported_hints?.[value] || '该软件不支持此档位', disabled: true };
70
+ if (full_only_hint && value !== 'full') return { value, label: ACCESS_LABELS[value], hint: full_only_hint, disabled: true };
71
+ return { value, label: ACCESS_LABELS[value], hint: profile?.access_hints?.[value] || '' };
72
+ });
70
73
  }
71
74
 
72
75
  /** The page's name for a level; `own` reads as decided by the member's own session. */