ai_co_discuss 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/discuss-host/SKILL.md +1 -1
- package/.agents/skills/discuss-host/references/control.md +9 -3
- package/.agents/skills/discuss-host/references/workflow.md +4 -1
- package/.agents/skills/discuss-participant/SKILL.md +3 -2
- package/.agents/skills/discuss-participant/references/interactive-html.md +57 -0
- package/.agents/skills/discuss-participant/references/writing.md +1 -1
- package/.agents/skills/workflow-creator/SKILL.md +10 -2
- package/.agents/skills/workflow-creator/references/model-selection.md +1 -1
- package/backend/free_room.py +101 -11
- package/backend/message_queue.py +1 -1
- package/backend/schema.sql +21 -0
- package/backend/server.py +18 -3
- package/docs/deployment.md +22 -0
- package/docs/en/deployment.md +22 -0
- package/docs/en/guide/external-members.md +1 -1
- package/docs/en/guide/faq.md +6 -2
- package/docs/en/guide/members.md +4 -4
- package/docs/en/guide/rooms.md +12 -4
- package/docs/en/guide/scheduling.md +3 -4
- package/docs/en/guide/workflows.md +6 -3
- package/docs/en/guide/working.md +8 -4
- package/docs/guide/external-members.md +1 -1
- package/docs/guide/faq.md +6 -2
- package/docs/guide/members.md +4 -4
- package/docs/guide/rooms.md +13 -5
- package/docs/guide/scheduling.md +3 -4
- package/docs/guide/workflows.md +6 -3
- package/docs/guide/working.md +8 -4
- package/frontend/locales/en/app.json +51 -1
- package/frontend/locales/en/backend.json +12 -1
- package/frontend/locales/en/core.json +10 -3
- package/frontend/locales/en/discussion.json +13 -2
- package/frontend/locales/en/room.json +37 -2
- package/frontend/locales/en/settings.json +8 -6
- package/gateway/login_page.mjs +77 -9
- package/package.json +3 -3
- package/runner/adapters/index.mjs +10 -0
- package/runner/adapters/profiles.mjs +19 -0
- package/runner/discuss.py +11 -2
- package/runner/discussion_launch.mjs +241 -44
- package/runner/expert_prompts.mjs +1 -2
- package/runner/free_runner.mjs +23 -9
- package/runner/host_permissions.mjs +57 -0
- package/runner/hosting_tunnel.mjs +25 -7
- package/runner/i18n_en.mjs +2 -0
- package/runner/scheduler.mjs +45 -102
- package/runner/session_driver.mjs +3 -4
- package/runner/workflow_flow.mjs +32 -2
- package/runner/workflows.mjs +84 -21
- package/web/admin.js +1 -1
- package/web/app.js +686 -173
- package/web/i18n.js +3 -3
- package/web/markdown.js +2 -2
- package/web/modern.css +1 -1
- package/web/modern.js +60 -60
- package/workflows/story-serial/SKILL.md +7 -5
- package/workflows/story-serial/agents/recorder.md +6 -5
- package/workflows/story-serial/agents/writer.md +1 -1
- package/workflows/story-serial/commands.json +1 -1
- package/workflows/story-serial/templates/README.md +3 -3
- package/workflows/story-serial/templates//344/270/226/347/225/214.md +1 -1
- package/workflows/story-serial/templates//345/267/245/344/275/234/345/217/260.md +3 -3
- package/workflows/story-serial/templates//346/216/222/347/272/277/350/241/250.md +2 -2
- package/workflows/story-serial/templates//346/226/207/351/243/216.md +1 -1
- package/workflows/story-serial/templates//347/212/266/346/200/201//344/270/273/350/247/222.yaml +2 -2
- package/workflows/story-serial/templates//347/212/266/346/200/201//344/272/272/347/211/251.yaml +1 -1
- package/workflows/story-serial/templates//347/212/266/346/200/201//345/210/206/351/233/206/350/256/260/345/275/225.yaml +1 -1
- package/workflows/story-serial/templates//347/212/266/346/200/201//346/215/256/347/202/271.yaml +1 -1
- package/workflows/story-serial/templates//347/212/266/346/200/201//347/211/251/350/265/204.yaml +3 -3
- package/workflows/story-serial/templates//347/212/266/346/200/201//347/272/277/347/264/242.yaml +4 -3
- package/workflows/story-serial/tools//347/212/266/346/200/201/346/243/200/346/237/245.py +81 -7
- package/workflows/story-serial/workflows/revise-episodes/SKILL.md +9 -4
- package/workflows/story-serial/workflows/revise-episodes/flow.json +93 -0
- package/workflows/story-serial/workflows/tidy-docs/SKILL.md +55 -0
- package/workflows/story-serial/workflows/tidy-docs/flow.json +74 -0
- package/workflows/story-serial/workflows/tidy-docs/references//346/226/207/346/241/243/346/240/207/345/207/206.md +97 -0
|
@@ -17,9 +17,9 @@ import { guard_remote_request, list_remote_directories, remote_allows, remote_ro
|
|
|
17
17
|
import { list_devices, machine_fingerprint, revoke_device, start_pairing } from './device_auth.mjs';
|
|
18
18
|
import { setup_sidecar } from './adapters/antigravity_app.mjs';
|
|
19
19
|
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';
|
|
20
|
-
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
|
+
import { ADAPTER_IDS, ADAPTER_PROFILES, adapter_capabilities, adapter_profile, DEFAULT_API_MAX_REQUESTS, inherited_access, MAX_API_MAX_REQUESTS, platform_adapters, same_session_family } from './adapters/profiles.mjs';
|
|
21
21
|
import { API_PROVIDERS, api_check, api_models, managed_api_keys, save_api_key, saved_api_keys, validate_api_profile } from './discussion_api.mjs';
|
|
22
|
-
import {
|
|
22
|
+
import { SCHEDULER_PROVIDERS, scheduler_check } from './scheduler.mjs';
|
|
23
23
|
import { save_tts_settings, tts_release, tts_settings, tts_speak } from './tts.mjs';
|
|
24
24
|
import { local_service_stop, local_services } from './tts_providers.mjs';
|
|
25
25
|
import { weixin_command } from './weixin.mjs';
|
|
@@ -30,10 +30,12 @@ import { run_image_tool } from './adapters/api_images.mjs';
|
|
|
30
30
|
import { access_levels, BUILTIN_EXPERT_PRESETS, MAX_EXPERT_PROMPT, PROJECT_ACCESS } from './expert_prompts.mjs';
|
|
31
31
|
import { acquire_lock, api, check_extra_directories, DiscussionStore, service_drafts, validate_config } from './discussion_runner.mjs';
|
|
32
32
|
import { FreeRoomRunner, free_task_files } from './free_runner.mjs';
|
|
33
|
-
import { assert_workflow_enabled, bind_room_workflow, delete_workflow, get_workflow, list_workflows, load_room_workflow, parse_workflow_draft, preview_workflow, rename_workflow, save_workflow, set_workflow_disabled, workflow_cards, workflow_directory, WORKFLOW_ID_PATTERN } from './workflows.mjs';
|
|
33
|
+
import { assert_workflow_enabled, bind_room_workflow, delete_workflow, get_workflow, list_workflows, load_room_workflow, parse_workflow_draft, preview_workflow, rename_workflow, save_workflow, set_workflow_disabled, workflow_cards, workflow_directory, workflow_member_list, WORKFLOW_ID_PATTERN } from './workflows.mjs';
|
|
34
34
|
import { assert_shared_home, CONNECTION_FIELDS, configuration_snapshot, read_registry, registered_identity, register_room, service_home, service_pid, start_service } from './discussion_service.mjs';
|
|
35
35
|
import { site_fetch } from './entry_client.mjs';
|
|
36
36
|
import { t } from './i18n.mjs';
|
|
37
|
+
import { host_room_limit, without_host_item } from './host_permissions.mjs';
|
|
38
|
+
import { HOST_ACTION_ITEMS, HOST_ITEMS, HOST_LEGACY_ITEMS, host_allowed, host_permission_fields, host_permissions, host_refusal, normalize_host_permissions } from './host_permissions.mjs';
|
|
37
39
|
|
|
38
40
|
// A platform is a type; `Claude-review` is another Claude instance with its own session, model and effort. An ID is
|
|
39
41
|
// English letters, digits and underscores only; a Chinese name is a display label.
|
|
@@ -103,8 +105,8 @@ const HELP = `用法:codiscuss launch settings [--file FILE]
|
|
|
103
105
|
codiscuss launch presets [--file FILE]
|
|
104
106
|
codiscuss launch machine-link --file FILE
|
|
105
107
|
codiscuss launch workflow-adopt (--draft FILE | --id WORKFLOW) [--access-file FILE]
|
|
106
|
-
codiscuss launch workflow-join [--card ID[,ID] | --sub SUB] [--access-file FILE]
|
|
107
|
-
codiscuss launch workflow-leave --sub SUB [--access-file FILE]
|
|
108
|
+
codiscuss launch workflow-join [--card ID[,ID] | --sub SUB | --card ID --label 显示名] [--access-file FILE]
|
|
109
|
+
codiscuss launch workflow-leave (--sub SUB | --member 成员) [--access-file FILE]
|
|
108
110
|
codiscuss launch host-control ACTION [选项] [--access-file FILE]
|
|
109
111
|
codiscuss launch workflow-check (--dir DIR | --draft FILE)
|
|
110
112
|
codiscuss launch workflow-save (--dir DIR | --draft FILE)
|
|
@@ -150,9 +152,9 @@ room-profiles 导出房间的本机成员软件配置与实际会话 ID(不含
|
|
|
150
152
|
room-restore 把导入房间的本机成员配置登记到本机并核对原会话存在,Claude Code 成员保持手动;须提供 site、room_id、token、local_members。
|
|
151
153
|
room-fork 把从原房间分支出的新房间登记到本机,各本机成员从原会话分叉、不含分支点之后的执行,原会话不变;须提供 site、room_id、token、source_room_id、source_token、executions({成员名: [排除的执行编号]})。
|
|
152
154
|
workflow-adopt 主持人在本房间启用工作流:--draft 把自己的草稿(一段,分段头 1/1)保存进工作流库后启用,--id 启用工作流库里已有的工作流(不改动它);缺的卡片成员由本机服务邀请,项目权限最高可写;须房主已为本房间打开“主持人完整权限”。凭据为本次任务的 access_file(或 DISCUSS_ACCESS_FILE)。
|
|
153
|
-
workflow-join 主持人为本房间在用工作流里还没有成员的卡片(启用后才新增的)邀请成员,不填 --card 即全部主线卡片;无需额外授权,离开或移除的成员由用户请回。--sub 改为请进该子工作流的卡片成员(离开的请回原会话)。凭据同上。
|
|
154
|
-
workflow-leave 主持人用完子工作流后,把 --sub 子工作流卡片的成员设为离开(会话保留,下次 workflow-join --sub 请回);主线成员不能这样请离。凭据同上。
|
|
155
|
-
host-control
|
|
155
|
+
workflow-join 主持人为本房间在用工作流里还没有成员的卡片(启用后才新增的)邀请成员,不填 --card 即全部主线卡片;无需额外授权,离开或移除的成员由用户请回。--sub 改为请进该子工作流的卡片成员(离开的请回原会话)。凭据同上。 --card 一张卡片加 --label 显示名:按这个显示名请一位扮演该卡片的成员(同一张卡可请多位,各有自己的会话;显示名只在本房间、不能和别的成员重复;该卡片已有同名的离开成员就请回它的原会话)。
|
|
156
|
+
workflow-leave 主持人用完子工作流后,把 --sub 子工作流卡片的成员设为离开(会话保留,下次 workflow-join --sub 请回);主线成员不能这样请离。凭据同上。 --member 成员(成员 ID 或显示名)只请离子工作流卡片的这一位成员。
|
|
157
|
+
host-control 主持人代房主控制房间,须房主已为本房间勾选对应的主持人权限(任务的 host_permissions 列出已勾选的项),凭据同上;成员用 --member(成员 ID 或显示名),除 retry、model、label 外不能是主持人自己:
|
|
156
158
|
诊断:details --execution N 读取该执行的本机过程日志(服务端详情与事件记录用 execution / room events 读取);
|
|
157
159
|
恢复:stop --member 打断;stop-all 停止全部执行、请求与接力;steer --member --text 话 [--submission-id ID] 向它进行中的执行插话;
|
|
158
160
|
retry --execution N 重试失败的执行(含你自己的);model --member [--model M] [--effort E] 改 CLI 或 API 成员的模型与强度(空值恢复默认;API 成员不填模型则保留原模型;换后房间留一条系统记录,成员下次任务带 model_change);model --member M --list 列出该成员软件的可用模型;
|
|
@@ -164,6 +166,10 @@ host-control 主持人代房主控制房间,须房主已为本房间打开“
|
|
|
164
166
|
推进:order 读取发言顺序,order --order 甲,乙 --revision REV 调整尚未发言的部分;
|
|
165
167
|
discussion 读取讨论,discussion --do start --goal 目标 --revision REV 开启(上限用房间默认值),--do pause|resume|end --revision REV;
|
|
166
168
|
goal 读取 Goal,goal --do start --goal 目标 --revision REV 开启(预算用房主默认值,默认不限时为 8 次续跑、90 分钟),--do pause|resume|end --revision REV。
|
|
169
|
+
房间:create-room --title 标题 [--goal 目标] [--members 甲,乙] [--host 平台] [--cwd 子目录] [--access read|write] [--text 首条消息] [--submission-id ID]
|
|
170
|
+
新建一个房间分担工作:成员用本机已配置的软件,项目权限默认只读、最高可写,目录只能是本房间项目目录或其子目录;不填 --host 时由与你同款的专家主持;
|
|
171
|
+
新房间的主持人权限取本机默认值但不能再新建房间,本房间可新建的数量有上限;两边各留一张链接卡片;重试沿用同一 --submission-id;
|
|
172
|
+
room-post --room 房间编号 --text 话 [--submission-id ID] 在关联房间(你新建的,或新建本房间的)发言,按房主消息唤醒该房间、标注来自本房间;自用户上次发言起两边互传的条数受本机“关联房间互传上限”限制(默认不限);读它用平常的读取命令、房间编号写新房间的(跨房间只能读)。
|
|
167
173
|
不开放:批准超出上限的轮数、项目权限高于可写或放行工具、改项目目录、撤回回退用户消息、私聊、对主持人自己的其他操作。
|
|
168
174
|
workflow-check 按导入规则校验工作流文件夹或单段草稿,返回预览,不保存;workflow-save 校验后保存进工作流库(同 ID 覆盖),卡片按声明的项目权限保存。写法见 workflow-creator 技能。
|
|
169
175
|
JSON 指定 site、entry(conversation/web)、room(建房内容,含 submission_id)
|
|
@@ -402,10 +408,10 @@ export async function room_models(home, raw, { read_defaults = profile => cached
|
|
|
402
408
|
outside_enforced: read_only_enforced({ ...profile, project_access: profile.project_access || config.project_access || 'read' }) } : {}) }];
|
|
403
409
|
})));
|
|
404
410
|
// Smart scheduling is a local choice; only which model decides is shown, never its key.
|
|
405
|
-
const scheduler = config.scheduler ? { provider: config.scheduler.provider, model: config.scheduler.model
|
|
411
|
+
const scheduler = config.scheduler ? { provider: config.scheduler.provider, model: config.scheduler.model } : null;
|
|
406
412
|
return { room_id: input.room_id, registered: paths.length > 0, participants, scheduler, project_directory: config.cwd || '',
|
|
407
413
|
extra_directories: config.extra_directories || [],
|
|
408
|
-
workflow: room_workflow_status(config, home), host_workflows: Boolean(config.host_workflows),
|
|
414
|
+
workflow: room_workflow_status(config, home), host_workflows: Boolean(config.host_workflows), host_permissions: host_permissions(config),
|
|
409
415
|
api_max_requests: config.api_max_requests ?? DEFAULT_API_MAX_REQUESTS,
|
|
410
416
|
// Whether members may draw here, and whether this computer has an image service to draw with.
|
|
411
417
|
image_generation: Boolean(config.image_generation), image_configured: image_settings(home).configured };
|
|
@@ -451,8 +457,9 @@ function room_workflow_status(config, home) {
|
|
|
451
457
|
// `cards` are the main flow's, which a refresh fills; a sub-workflow's cards join only when it is used.
|
|
452
458
|
const cards = Object.values(loaded.cards || {});
|
|
453
459
|
return { id: config.workflow.id, label: loaded.label || config.workflow.id, enabled: Boolean(config.workflow.enabled),
|
|
454
|
-
available: !loaded.error, members: config.workflow.members || {},
|
|
455
|
-
|
|
460
|
+
available: !loaded.error, members: config.workflow.members || {}, ...(config.workflow.extra_members ? { extra_members: config.workflow.extra_members } : {}),
|
|
461
|
+
cards: cards.filter(card => !card.sub_workflow).map(card => card.card), stages: loaded.stages || [],
|
|
462
|
+
sub_workflows: (loaded.sub_workflows || []).map(sub => ({ id: sub.id, label: sub.label || sub.id, description: sub.description, cards: sub.cards, attach: sub.attach || [] })) };
|
|
456
463
|
}
|
|
457
464
|
|
|
458
465
|
/**
|
|
@@ -695,7 +702,7 @@ function read_log_tail(path) {
|
|
|
695
702
|
return length < size ? text.slice(text.indexOf('\n') + 1) : text;
|
|
696
703
|
}
|
|
697
704
|
|
|
698
|
-
const CREATE_PREFERENCE_RANGES = { max_rounds: [0, 100], max_minutes: [0, 1440], goal_max_continues: [0, 100], goal_max_minutes: [0, 1440], chain_rounds: [0, 100],
|
|
705
|
+
const CREATE_PREFERENCE_RANGES = { max_rounds: [0, 100], max_minutes: [0, 1440], goal_max_continues: [0, 100], goal_max_minutes: [0, 1440], chain_rounds: [0, 100], relay_rounds: [0, 100],
|
|
699
706
|
api_max_requests: [0, MAX_API_MAX_REQUESTS] };
|
|
700
707
|
const CREATE_PREFERENCE_FLAGS = ['named_followup', 'host_workflows', 'advanced_open'];
|
|
701
708
|
const MAX_PREFERENCE_MODEL_LENGTH = 200;
|
|
@@ -711,12 +718,20 @@ function validate_create_preferences(input) {
|
|
|
711
718
|
const [minimum, maximum] = CREATE_PREFERENCE_RANGES[field];
|
|
712
719
|
valid = Number.isInteger(value) && value >= minimum && value <= maximum;
|
|
713
720
|
} else if (field === 'drive') valid = ['free', 'discussion', 'goal'].includes(value);
|
|
721
|
+
else if (field === 'host_project_access') valid = ['read', 'write', 'auto', 'full'].includes(value);
|
|
714
722
|
else if (field === 'workflow_id') valid = typeof value === 'string' && (!value || WORKFLOW_ID_PATTERN.test(value));
|
|
715
723
|
else if (field === 'scheduler') valid = valid_scheduler_preference(value);
|
|
724
|
+
else if (field === 'host_permissions') valid = valid_host_permissions(value);
|
|
716
725
|
if (!valid) throw new Error(`建房偏好字段无效:${field}`);
|
|
717
726
|
}
|
|
718
727
|
}
|
|
719
728
|
|
|
729
|
+
/** Host permissions as the page sends them: known items, and a room limit when given. */
|
|
730
|
+
function valid_host_permissions(value) {
|
|
731
|
+
return Boolean(value) && typeof value === 'object' && Array.isArray(value.items) && value.items.every(item => HOST_ITEMS.includes(item))
|
|
732
|
+
&& (value.room_limit === undefined || Number.isInteger(value.room_limit));
|
|
733
|
+
}
|
|
734
|
+
|
|
720
735
|
/** A scheduler preference carries selections, never a key or even a key reference. */
|
|
721
736
|
function valid_scheduler_preference(value) {
|
|
722
737
|
if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
@@ -724,7 +739,8 @@ function valid_scheduler_preference(value) {
|
|
|
724
739
|
enabled: item => typeof item === 'boolean',
|
|
725
740
|
provider: item => typeof item === 'string' && (!item || Object.hasOwn(SCHEDULER_PROVIDERS, item)),
|
|
726
741
|
model: item => typeof item === 'string' && item.length <= MAX_PREFERENCE_MODEL_LENGTH,
|
|
727
|
-
|
|
742
|
+
// The decision method was retired on 2026-11-21; preferences saved before still carry it and are read as before.
|
|
743
|
+
mode: item => typeof item === 'string',
|
|
728
744
|
};
|
|
729
745
|
return Object.entries(value).every(([field, item]) => Object.hasOwn(fields, field) && fields[field](item));
|
|
730
746
|
}
|
|
@@ -1008,7 +1024,7 @@ function free_launch_config(home, input, room, directory, options) {
|
|
|
1008
1024
|
if (workflow && Object.values(workflow.members).some(name => !names.includes(name))) throw new Error('工作流成员须在本次邀请的成员中');
|
|
1009
1025
|
return validate_config({ site: input.site, room: room.id || 'preview', token: options.token, mode: 'free', participants, members, api_home: home,
|
|
1010
1026
|
scheduler: input.scheduler || undefined, cwd: input.cwd, extra_directories: input.extra_directories, project_access: input.project_access || undefined, workflow,
|
|
1011
|
-
|
|
1027
|
+
...host_permission_fields(normalize_host_permissions(input.host_permissions, input.host_workflows === true)), api_max_requests: input.api_max_requests,
|
|
1012
1028
|
image_generation: input.image_generation === true || undefined,
|
|
1013
1029
|
data_directory: join(directory, 'runtime'), draft_directory: service_drafts(home, join(directory, 'runtime')) }, directory);
|
|
1014
1030
|
}
|
|
@@ -1217,7 +1233,7 @@ export async function room_settings(home, raw) {
|
|
|
1217
1233
|
const config = configuration_snapshot(path).config;
|
|
1218
1234
|
const next = { ...config, ...(requests !== undefined ? { api_max_requests: requests } : {}), ...(images !== undefined ? { image_generation: images } : {}) };
|
|
1219
1235
|
// Off is written as null, not dropped, so the running service's merge of the new configuration turns it off too.
|
|
1220
|
-
if (scheduler !== undefined) next.scheduler = scheduler && { provider: scheduler.provider, model: scheduler.model, api_key_ref: scheduler.api_key_ref
|
|
1236
|
+
if (scheduler !== undefined) next.scheduler = scheduler && { provider: scheduler.provider, model: scheduler.model, api_key_ref: scheduler.api_key_ref };
|
|
1221
1237
|
if (cwd !== undefined) {
|
|
1222
1238
|
if (config.cwd) throw new Error('本房间已有项目目录,建房后不能更改;可添加其他项目目录');
|
|
1223
1239
|
if (typeof cwd !== 'string' || !isAbsolute(cwd) || !existsSync(cwd) || !statSync(cwd).isDirectory()) throw new Error('项目目录须为本机已有文件夹的完整路径');
|
|
@@ -1231,23 +1247,41 @@ export async function room_settings(home, raw) {
|
|
|
1231
1247
|
validate_config(next, dirname(path));
|
|
1232
1248
|
atomic_json(path, next);
|
|
1233
1249
|
return { room_id: input.room_id, ...(requests !== undefined ? { api_max_requests: requests } : {}), ...(images !== undefined ? { image_generation: images } : {}),
|
|
1234
|
-
...(scheduler !== undefined ? { scheduler: next.scheduler ? { provider: next.scheduler.provider, model: next.scheduler.model
|
|
1250
|
+
...(scheduler !== undefined ? { scheduler: next.scheduler ? { provider: next.scheduler.provider, model: next.scheduler.model } : null } : {}),
|
|
1235
1251
|
...(cwd !== undefined ? { project_directory: cwd } : {}), ...(directories !== undefined ? { extra_directories: directories } : {}) };
|
|
1236
1252
|
} finally { release(); }
|
|
1237
1253
|
}
|
|
1238
1254
|
|
|
1255
|
+
/**
|
|
1256
|
+
* The access `name` gains by taking over `source`'s, or null when it gains none: either is not woken here, the access
|
|
1257
|
+
* is not the runner's to set, or 可写 would have no project to write.
|
|
1258
|
+
*/
|
|
1259
|
+
function inherited_project_access(config, name, source) {
|
|
1260
|
+
const level = member => member.project_access || config.project_access || 'read';
|
|
1261
|
+
const [profile, other] = [config.participants?.[name], config.participants?.[source]];
|
|
1262
|
+
if (!profile || !other) return null;
|
|
1263
|
+
const facts = adapter_profile(profile.adapter);
|
|
1264
|
+
if (facts?.own_project_when_bound && profile.session_id) return null;
|
|
1265
|
+
const next = inherited_access({ adapter: profile.adapter, project_access: level(profile) }, { adapter: other.adapter, project_access: level(other) });
|
|
1266
|
+
return next === level(profile) || (next === 'write' && !(profile.cwd || config.cwd)) ? null : next;
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1239
1269
|
/**
|
|
1240
1270
|
* Switch one woken member's project files between read-only and writable after the room is created. Every run builds its
|
|
1241
1271
|
* permissions from the configuration, so the change applies from the member's next delivery and keeps its session.
|
|
1242
1272
|
*/
|
|
1243
1273
|
export async function room_member_access(home, raw) {
|
|
1244
1274
|
const { input, path } = await member_room_context(home, raw);
|
|
1245
|
-
const { name
|
|
1246
|
-
if (!PROJECT_ACCESS.includes(project_access)) throw new Error('project_access 只能为 read、write、auto 或 full');
|
|
1275
|
+
const { name } = input;
|
|
1276
|
+
if (input.inherit_from === undefined && !PROJECT_ACCESS.includes(input.project_access)) throw new Error('project_access 只能为 read、write、auto 或 full');
|
|
1247
1277
|
const release = acquire_lock(join(dirname(path), 'configuration-edit'));
|
|
1248
1278
|
try {
|
|
1249
1279
|
const config = configuration_snapshot(path).config;
|
|
1250
1280
|
const profile = config.participants?.[name];
|
|
1281
|
+
// A new host takes over the previous host's access as far as its own software goes (inherited_access); a member
|
|
1282
|
+
// whose access the runner does not set, or that has nothing to gain, is left as it is without an error.
|
|
1283
|
+
const project_access = input.inherit_from === undefined ? input.project_access : inherited_project_access(config, name, input.inherit_from);
|
|
1284
|
+
if (project_access === null) return { room_id: input.room_id, member: name, changed: false };
|
|
1251
1285
|
if (!profile) throw new Error(`${name} 不由本机唤醒,项目权限由它自己的会话决定`);
|
|
1252
1286
|
if (profile.project_access === 'own') throw new Error(`${name} 是手动接入的成员,权限沿用它自己会话的软件设置`);
|
|
1253
1287
|
const facts = adapter_profile(profile.adapter);
|
|
@@ -1259,7 +1293,7 @@ export async function room_member_access(home, raw) {
|
|
|
1259
1293
|
const next = { ...config, participants: { ...config.participants, [name]: { ...profile, project_access } } };
|
|
1260
1294
|
validate_config(next, dirname(path));
|
|
1261
1295
|
atomic_json(path, next);
|
|
1262
|
-
return { room_id: input.room_id, member: name, project_access };
|
|
1296
|
+
return { room_id: input.room_id, member: name, project_access, ...(input.inherit_from === undefined ? {} : { changed: true }) };
|
|
1263
1297
|
} finally { release(); }
|
|
1264
1298
|
}
|
|
1265
1299
|
|
|
@@ -1937,10 +1971,13 @@ export async function room_workflow(home, raw) {
|
|
|
1937
1971
|
try {
|
|
1938
1972
|
const config = configuration_snapshot(path).config;
|
|
1939
1973
|
if (input.action === 'host') {
|
|
1940
|
-
// The owner's per-room grant
|
|
1941
|
-
|
|
1974
|
+
// The owner's per-room grant of what the host may do by itself, item by item; the older `allowed` ticks or clears
|
|
1975
|
+
// the items the single switch covered.
|
|
1976
|
+
if (input.permissions !== undefined && !valid_host_permissions(input.permissions)) throw new Error('主持人权限须为 { items, room_limit }');
|
|
1977
|
+
const permissions = input.permissions ?? { ...host_permissions(config), items: input.allowed === true ? HOST_LEGACY_ITEMS : [] };
|
|
1978
|
+
const next = { ...config, ...host_permission_fields(permissions) };
|
|
1942
1979
|
atomic_json(path, next);
|
|
1943
|
-
return { room_id: input.room_id, host_workflows: Boolean(next.host_workflows) };
|
|
1980
|
+
return { room_id: input.room_id, host_workflows: Boolean(next.host_workflows), host_permissions: host_permissions(next) };
|
|
1944
1981
|
}
|
|
1945
1982
|
if (input.action === 'enable') {
|
|
1946
1983
|
get_workflow(home, input.workflow?.id);
|
|
@@ -1953,7 +1990,7 @@ export async function room_workflow(home, raw) {
|
|
|
1953
1990
|
if (!['away', 'back', 'disable'].includes(input.action)) throw new Error('action 须为 enable、sync、away、back、disable 或 host');
|
|
1954
1991
|
if (!config.workflow?.id) throw new Error('本房间没有工作流');
|
|
1955
1992
|
const room = await site_request(input.site, `/api/rooms/${input.room_id}`, input.token);
|
|
1956
|
-
const names = new Set(
|
|
1993
|
+
const names = new Set(workflow_member_list(config.workflow).map(item => item.name));
|
|
1957
1994
|
const members = room.free.members.filter(item => names.has(item.name) && item.role !== 'host');
|
|
1958
1995
|
if (input.action === 'back') {
|
|
1959
1996
|
// Each comes back to its own session; a removed member stays removed.
|
|
@@ -2098,8 +2135,10 @@ async function sync_workflow_cards(home, path, config, roster, cards) {
|
|
|
2098
2135
|
try {
|
|
2099
2136
|
const current = configuration_snapshot(path).config;
|
|
2100
2137
|
if (current.workflow?.id !== workflow.id) throw new Error('本房间的工作流已更换,请重新读取后再试');
|
|
2101
|
-
// The map is replaced, not merged, so dropped cards leave it.
|
|
2102
|
-
const
|
|
2138
|
+
// The map is replaced, not merged, so dropped cards leave it; so do further members of a dropped card.
|
|
2139
|
+
const extra = Object.fromEntries(Object.entries(current.workflow.extra_members || {}).filter(([, card]) => known.includes(card)));
|
|
2140
|
+
const { extra_members: ignored, ...binding } = current.workflow;
|
|
2141
|
+
const next = { ...current, workflow: { ...binding, members, ...(Object.keys(extra).length ? { extra_members: extra } : {}) } };
|
|
2103
2142
|
atomic_json(path, next);
|
|
2104
2143
|
return { room_id: config.room, workflow: room_workflow_status(next, home), members };
|
|
2105
2144
|
} finally { release(); }
|
|
@@ -2121,8 +2160,9 @@ async function refresh_room_workflow(home, raw) {
|
|
|
2121
2160
|
* authorized the workflow's cards, so this needs no further grant. Only cards with no member yet may be named, so a
|
|
2122
2161
|
* member the user sent away or removed stays so. Returns the room's workflow status and the card map.
|
|
2123
2162
|
*/
|
|
2124
|
-
export async function join_workflow(home, { access_file, cards, sub }) {
|
|
2125
|
-
const { path, config, roster } = await host_room(home, access_file);
|
|
2163
|
+
export async function join_workflow(home, { access_file, cards, sub, label }) {
|
|
2164
|
+
const { path, config, roster, labels } = await host_room(home, access_file);
|
|
2165
|
+
if (label !== undefined) return join_labeled_member(home, { path, config, roster, labels }, cards, String(label).trim());
|
|
2126
2166
|
if (sub) return sync_workflow_cards(home, path, config, roster, sub_workflow_cards(home, config, sub));
|
|
2127
2167
|
const mapped = Object.keys(config.workflow?.members || {});
|
|
2128
2168
|
const taken = (cards || []).filter(card => mapped.includes(card));
|
|
@@ -2131,6 +2171,57 @@ export async function join_workflow(home, { access_file, cards, sub }) {
|
|
|
2131
2171
|
return sync_workflow_cards(home, path, config, roster, cards?.length ? cards : known.filter(card => !mapped.includes(card)));
|
|
2132
2172
|
}
|
|
2133
2173
|
|
|
2174
|
+
// A member's display name in the room, as the owner's labels limit it.
|
|
2175
|
+
const MAX_MEMBER_LABEL = 32;
|
|
2176
|
+
|
|
2177
|
+
/**
|
|
2178
|
+
* The host brings one member to play a card under a display name of its own (`workflow-join --card ID --label 名字`,
|
|
2179
|
+
* user 2026-11-21): several members may play one card, each in its own session, e.g. one per character for a card
|
|
2180
|
+
* that plays a character. A card with no member yet gets this one as its first; otherwise it is one more, kept in
|
|
2181
|
+
* `extra_members`. A member of this card that already has the name comes back (its own session) instead of a new one;
|
|
2182
|
+
* a name another member uses is refused. Returns the room's workflow status, the card maps and the member brought.
|
|
2183
|
+
*/
|
|
2184
|
+
async function join_labeled_member(home, { path, config, roster, labels }, cards, label) {
|
|
2185
|
+
if (!config.workflow?.id || !config.workflow.enabled) throw new Error('本房间没有在用的工作流');
|
|
2186
|
+
if (cards?.length !== 1) throw new Error('--label 须和 --card 一起用,且只写一张卡片');
|
|
2187
|
+
if (!label || label.length > MAX_MEMBER_LABEL || /\n/.test(label)) throw new Error(`--label 须为 1—${MAX_MEMBER_LABEL} 字、不换行的显示名`);
|
|
2188
|
+
const [card] = cards;
|
|
2189
|
+
const workflow = get_workflow(home, config.workflow.id);
|
|
2190
|
+
const agent = workflow_cards(workflow).find(item => item.card === card);
|
|
2191
|
+
if (!agent) throw new Error(`工作流 ${workflow.id} 没有卡片 ${card}`);
|
|
2192
|
+
const shown = member => labels[member.name] || member.name;
|
|
2193
|
+
const live = roster.filter(member => member.status !== 'removed');
|
|
2194
|
+
const players = workflow_member_list(config.workflow).filter(item => item.card === card).map(item => item.name);
|
|
2195
|
+
const same = live.find(member => players.includes(member.name) && shown(member) === label);
|
|
2196
|
+
const owner = { site: config.site, room_id: config.room, token: config.token };
|
|
2197
|
+
let name = same?.name;
|
|
2198
|
+
if (same?.status === 'away') await room_member(home, { ...owner, action: 'rejoin', name });
|
|
2199
|
+
if (!same) {
|
|
2200
|
+
if (live.some(member => shown(member) === label || member.name === label)) throw new Error(`本房间已有显示名为“${label}”的成员,换一个名字`);
|
|
2201
|
+
const first = !live.some(member => member.name === config.workflow.members?.[card]);
|
|
2202
|
+
const taken = new Set([...roster.map(member => member.name), ...workflow_member_list(config.workflow).map(item => item.name)]);
|
|
2203
|
+
name = taken.has(agent.name) ? free_instance(agent.name, taken) : agent.name;
|
|
2204
|
+
const api = card_api_profile(home, platform_of(agent.name));
|
|
2205
|
+
const settings = Object.fromEntries(['project_access', 'model', 'effort'].filter(field => agent[field]).map(field => [field, agent[field]]));
|
|
2206
|
+
if (api && settings.project_access && !access_levels('api').includes(settings.project_access)) settings.project_access = 'write';
|
|
2207
|
+
const joined = await room_member(home, { ...owner, action: 'add', name, participants: { [name]: { ...api, ...settings } } });
|
|
2208
|
+
name = joined.member;
|
|
2209
|
+
await site_request(config.site, `/api/rooms/${config.room}/labels`, config.token, { labels: { [name]: label } });
|
|
2210
|
+
if (agent.description) await site_request(config.site, `/api/rooms/${config.room}/descriptions`, config.token, { descriptions: { [name]: agent.description } });
|
|
2211
|
+
const release = acquire_lock(join(dirname(path), 'configuration-edit'));
|
|
2212
|
+
try {
|
|
2213
|
+
const current = configuration_snapshot(path).config;
|
|
2214
|
+
if (current.workflow?.id !== workflow.id) throw new Error('本房间的工作流已更换,请重新读取后再试');
|
|
2215
|
+
const binding = first ? { ...current.workflow, members: { ...current.workflow.members, [card]: name } }
|
|
2216
|
+
: { ...current.workflow, extra_members: { ...(current.workflow.extra_members || {}), [name]: card } };
|
|
2217
|
+
atomic_json(path, { ...current, workflow: binding });
|
|
2218
|
+
} finally { release(); }
|
|
2219
|
+
}
|
|
2220
|
+
const next = configuration_snapshot(path).config;
|
|
2221
|
+
return { room_id: config.room, workflow: room_workflow_status(next, home), members: next.workflow.members, extra_members: next.workflow.extra_members || {},
|
|
2222
|
+
member: name, label, card, ...(same ? { returned: true } : {}) };
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2134
2225
|
/** The cards a sub-workflow of the room's workflow in use brings; refuses one it lacks or one with no cards. */
|
|
2135
2226
|
function sub_workflow_cards(home, config, sub) {
|
|
2136
2227
|
if (!config.workflow?.id || !config.workflow.enabled) throw new Error('本房间没有在用的工作流');
|
|
@@ -2146,14 +2237,23 @@ function sub_workflow_cards(home, config, sub) {
|
|
|
2146
2237
|
* stopped, sessions kept), so `workflow-join --sub` brings them back to their own sessions. Only a sub-workflow's cards
|
|
2147
2238
|
* may be sent away this way; the main flow's members stay for the user to manage.
|
|
2148
2239
|
*/
|
|
2149
|
-
export async function leave_sub_workflow(home, { access_file, sub }) {
|
|
2150
|
-
if (!sub) throw new Error('须用 --sub
|
|
2151
|
-
const { config, roster } = await host_room(home, access_file);
|
|
2152
|
-
|
|
2153
|
-
|
|
2240
|
+
export async function leave_sub_workflow(home, { access_file, sub, member: wanted }) {
|
|
2241
|
+
if (!sub && !wanted) throw new Error('须用 --sub 指定子工作流,或用 --member 指定成员');
|
|
2242
|
+
const { config, roster, labels } = await host_room(home, access_file);
|
|
2243
|
+
if (!config.workflow?.id || !config.workflow.enabled) throw new Error('本房间没有在用的工作流');
|
|
2244
|
+
// A sub-workflow's members: every member of its cards, a card's further members (`extra_members`) included.
|
|
2245
|
+
const sub_cards = sub ? sub_workflow_cards(home, config, sub)
|
|
2246
|
+
: workflow_cards(get_workflow(home, config.workflow.id)).filter(agent => agent.sub_workflow).map(agent => agent.card);
|
|
2247
|
+
let names = workflow_member_list(config.workflow).filter(item => sub_cards.includes(item.card)).map(item => item.name);
|
|
2248
|
+
if (wanted) {
|
|
2249
|
+
const member = roster.find(item => item.status !== 'removed' && (item.name === wanted || labels[item.name] === wanted || String(item.id) === String(wanted)));
|
|
2250
|
+
if (!member) throw new Error(`本房间没有成员 ${wanted}`);
|
|
2251
|
+
if (!names.includes(member.name)) throw new Error(`${wanted} 不是${sub ? `子工作流 ${sub} ` : '子工作流卡片'}的成员;主线成员不能这样请离`);
|
|
2252
|
+
names = [member.name];
|
|
2253
|
+
}
|
|
2154
2254
|
const away = roster.filter(member => names.includes(member.name) && member.status === 'active' && member.role !== 'host');
|
|
2155
2255
|
for (const member of away) await site_request(config.site, `/api/rooms/${config.room}/members/${member.id}`, config.token, { action: 'away' });
|
|
2156
|
-
return { room_id: config.room, sub, away: away.map(member => member.name) };
|
|
2256
|
+
return { room_id: config.room, ...(sub ? { sub } : {}), away: away.map(member => member.name) };
|
|
2157
2257
|
}
|
|
2158
2258
|
|
|
2159
2259
|
// When the owner left the room's goal budget at no limit, a goal the host opens itself still stops by these.
|
|
@@ -2289,7 +2389,101 @@ async function member_change(action, target, request, labels) {
|
|
|
2289
2389
|
...(['away', 'remove'].includes(action) ? { cancelled_pending: Math.max(0, (target.pending || 0) - (after?.pending ?? 0)) } : {}) };
|
|
2290
2390
|
}
|
|
2291
2391
|
|
|
2392
|
+
/** The headers for a write in another room: the caller's name, without this room's host credential, which means nothing there. */
|
|
2393
|
+
const caller_only = headers => ({ 'User-Agent': headers['User-Agent'] });
|
|
2394
|
+
|
|
2395
|
+
/** A directory for a room the host creates: this room's project directory or a folder inside it, never wider. */
|
|
2396
|
+
function spawned_directory(parent, wanted) {
|
|
2397
|
+
if (!wanted) return parent || undefined;
|
|
2398
|
+
if (!parent) throw new Error('本房间没有项目目录,新房间不能指定 --cwd');
|
|
2399
|
+
const target = resolve(parent, wanted);
|
|
2400
|
+
const inside = relative(resolve(parent), target);
|
|
2401
|
+
if (inside.startsWith('..') || isAbsolute(inside)) throw new Error(`新房间的目录只能是本房间的项目目录或其子目录:${parent}`);
|
|
2402
|
+
if (!existsSync(target) || !statSync(target).isDirectory()) throw new Error(`目录不存在或不是文件夹:${target}`);
|
|
2403
|
+
return target;
|
|
2404
|
+
}
|
|
2405
|
+
|
|
2406
|
+
/** The registered configuration of a room this computer launched; throws when there is none. */
|
|
2407
|
+
function registered_room_config(home, site, room_id) {
|
|
2408
|
+
const path = registered_room_path(home, site, room_id);
|
|
2409
|
+
if (!path) throw new Error(`本机没有登记房间 ${room_id}`);
|
|
2410
|
+
return { path, config: configuration_snapshot(path).config };
|
|
2411
|
+
}
|
|
2412
|
+
|
|
2413
|
+
/** Change a registered room's configuration under its edit lock. */
|
|
2414
|
+
function edit_room_config(path, change) {
|
|
2415
|
+
const release = acquire_lock(join(dirname(path), 'configuration-edit'));
|
|
2416
|
+
try { atomic_json(path, change(configuration_snapshot(path).config)); } finally { release(); }
|
|
2417
|
+
}
|
|
2418
|
+
|
|
2419
|
+
/**
|
|
2420
|
+
* Create a room for part of the work (`create-room`, user 2026-11-21): this computer's configured software as members,
|
|
2421
|
+
* project access at most write, the directory this room's or one inside it. The new room's host is `--host` when given,
|
|
2422
|
+
* else this host's own platform with its settings. Its host permissions are this computer's defaults without creating
|
|
2423
|
+
* rooms, so rooms do not multiply. A card links the two rooms both ways; `--text` is its first message, sent as by
|
|
2424
|
+
* `room-post`. A retry passes the same --submission-id and returns the same room.
|
|
2425
|
+
*/
|
|
2426
|
+
async function host_create_room(ctx, o) {
|
|
2427
|
+
const { home, config, host } = ctx;
|
|
2428
|
+
if (!o.title) throw new Error('须用 --title 写明新房间的标题');
|
|
2429
|
+
const created = config.spawned_rooms || [];
|
|
2430
|
+
const submission_id = o.submission_id || randomUUID();
|
|
2431
|
+
if (!/^[A-Za-z0-9_-]{8,100}$/.test(submission_id)) throw new Error('--submission-id 须为 8–100 位字母、数字、下划线或连字符');
|
|
2432
|
+
const retry = created.find(item => item.submission_id === submission_id);
|
|
2433
|
+
if (!retry && created.length >= host_room_limit(config)) {
|
|
2434
|
+
throw new Error(`本房间已新建 ${created.length} 个房间,达到上限 ${host_room_limit(config)};需要更多请让用户在“主持人权限”里调高上限`);
|
|
2435
|
+
}
|
|
2436
|
+
if (o.access && !HOST_CARD_ACCESS.includes(o.access)) throw new Error('新房间成员的项目权限只能是 read 或 write');
|
|
2437
|
+
const access = o.access || 'read';
|
|
2438
|
+
const host_name = o.host || platform_of(host);
|
|
2439
|
+
const names = [...new Set([host_name, ...(o.members || '').split(',').map(name => name.trim()).filter(Boolean)])];
|
|
2440
|
+
const participants = Object.fromEntries(names.map(name => [name, host_invite_profile(home, name, { access })]));
|
|
2441
|
+
if (!o.host) {
|
|
2442
|
+
// The same expert as this host: its software, model and effort, in a new session and at the access asked for.
|
|
2443
|
+
const { session_id, cwd, project_access, ...own } = config.participants?.[host] || {};
|
|
2444
|
+
participants[host_name] = { ...own, project_access: access };
|
|
2445
|
+
}
|
|
2446
|
+
const preferences = launch_settings(home).create_preferences || {};
|
|
2447
|
+
const permissions = without_host_item(normalize_host_permissions(preferences.host_permissions, preferences.host_workflows === true), 'create_rooms');
|
|
2448
|
+
const receipt = await launch_discussion(home, { site: config.site, entry: 'web', cwd: spawned_directory(config.cwd, o.cwd), participants,
|
|
2449
|
+
host_permissions: permissions, room: { title: o.title, goal: o.goal || '', mode: 'free', host: host_name, submission_id,
|
|
2450
|
+
members: names.map(name => ({ name, access: 'runner' })) } }, ctx.launch_options);
|
|
2451
|
+
const room_id = receipt.room.id;
|
|
2452
|
+
const parent_path = registered_room_path(home, config.site, config.room);
|
|
2453
|
+
if (!retry) edit_room_config(parent_path, saved => ({ ...saved, spawned_rooms: [...(saved.spawned_rooms || []), { room: room_id, submission_id }] }));
|
|
2454
|
+
const label = ctx.labels[host] || host;
|
|
2455
|
+
await ctx.call('/room-link', { relation: 'child', room_id, host: label });
|
|
2456
|
+
const registered = registered_room_config(home, config.site, room_id);
|
|
2457
|
+
if (registered.config.spawned_from !== config.room) edit_room_config(registered.path, saved => ({ ...saved, spawned_from: config.room }));
|
|
2458
|
+
const child = registered.config;
|
|
2459
|
+
await site_request(config.site, `/api/rooms/${room_id}/room-link`, child.token, { relation: 'parent', room_id: config.room, host: label }, caller_only(ctx.headers));
|
|
2460
|
+
const first = o.text ? await host_room_post({ ...ctx, config: configuration_snapshot(parent_path).config }, { room: room_id, text: o.text, submission_id: `${submission_id}-first` }) : null;
|
|
2461
|
+
return { room_id, title: receipt.room.title, url: receipt.url, host: host_name, members: names, project_access: access,
|
|
2462
|
+
cwd: child.cwd || null, ...(first ? { message_id: first.message_id } : {}) };
|
|
2463
|
+
}
|
|
2464
|
+
|
|
2465
|
+
/**
|
|
2466
|
+
* Speak in a linked room (`room-post`): one this room created, or the room that created this one. It goes with that
|
|
2467
|
+
* room's owner credential, so it routes and wakes as the owner's message there, labelled with this room and host. The
|
|
2468
|
+
* site counts how many messages two hosts pass each other before the owner speaks again, against this computer's
|
|
2469
|
+
* `relay_rounds` preference (0, the default, is unlimited; set in the new-room form's advanced settings).
|
|
2470
|
+
*/
|
|
2471
|
+
async function host_room_post(ctx, o) {
|
|
2472
|
+
const { home, config, host } = ctx;
|
|
2473
|
+
if (!o.room || (o.room !== config.spawned_from && !(config.spawned_rooms || []).some(item => item.room === o.room))) {
|
|
2474
|
+
throw new Error('只能在与本房间关联的房间里发言(本房间新建的房间,或新建本房间的房间);用 --room 指定其房间编号');
|
|
2475
|
+
}
|
|
2476
|
+
if (!o.text) throw new Error('须用 --text 写明要发的消息');
|
|
2477
|
+
const child = registered_room_config(home, config.site, o.room).config;
|
|
2478
|
+
const result = await site_request(config.site, `/api/rooms/${o.room}/messages`, child.token, { author: '用户', text: o.text,
|
|
2479
|
+
submission_id: o.submission_id || randomUUID(), relay: { room_id: config.room, host: ctx.labels[host] || host,
|
|
2480
|
+
limit: launch_settings(home).create_preferences?.relay_rounds ?? 0 } }, caller_only(ctx.headers));
|
|
2481
|
+
return { room_id: o.room, message_id: result.message?.id ?? null, queued: result.queued ?? null };
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2292
2484
|
const HOST_CONTROLS = {
|
|
2485
|
+
'create-room': host_create_room,
|
|
2486
|
+
'room-post': host_room_post,
|
|
2293
2487
|
stop: (ctx, o) => {
|
|
2294
2488
|
const target = host_target(ctx, o.member);
|
|
2295
2489
|
return member_change('stop', target, ctx.call(`/members/${target.id}/interrupt`, {}), ctx.labels);
|
|
@@ -2341,16 +2535,17 @@ const HOST_CONTROLS = {
|
|
|
2341
2535
|
* included). What stays the owner's: acting on the host itself, approving rounds beyond the limit, access above write
|
|
2342
2536
|
* or tool approvals, project directories, the owner's messages and private chats.
|
|
2343
2537
|
*/
|
|
2344
|
-
export async function host_control(home, action, options) {
|
|
2538
|
+
export async function host_control(home, action, options, launch_options = {}) {
|
|
2345
2539
|
if (!Object.hasOwn(HOST_CONTROLS, action || '')) throw new Error(`操作须为 ${Object.keys(HOST_CONTROLS).join('、')} 之一`);
|
|
2346
2540
|
const { config, roster, labels, host } = await host_room(home, options.access_file);
|
|
2347
|
-
|
|
2541
|
+
const needed = HOST_ACTION_ITEMS[action];
|
|
2542
|
+
if (needed && !host_allowed(config, needed)) throw new Error(host_refusal(needed));
|
|
2348
2543
|
// The User-Agent names the caller in the event log; the host's own credential is what lets the site label what it
|
|
2349
2544
|
// does as the host's (steer, stop) by its display name, since every write here carries the owner's credential.
|
|
2350
2545
|
const headers = { 'User-Agent': `AI-CoDiscuss-host:${host}`, 'X-Acting-Member-Token': config.members[host].token };
|
|
2351
2546
|
const owner = { site: config.site, room_id: config.room, token: config.token };
|
|
2352
2547
|
const call = (path, body) => site_request(config.site, `/api/rooms/${config.room}${path}`, config.token, body, headers);
|
|
2353
|
-
return HOST_CONTROLS[action]({ home, config, roster, labels, host, headers, owner, call }, options);
|
|
2548
|
+
return HOST_CONTROLS[action]({ home, config, roster, labels, host, headers, owner, call, launch_options }, options);
|
|
2354
2549
|
}
|
|
2355
2550
|
|
|
2356
2551
|
/** Cards as the host may bring them: any access above writing is lowered to it. */
|
|
@@ -2367,7 +2562,7 @@ const host_cards = agents => agents.map(agent => agent.project_access && !HOST_C
|
|
|
2367
2562
|
export async function adopt_workflow(home, { access_file, draft_file, workflow_id }) {
|
|
2368
2563
|
if (!draft_file === !workflow_id) throw new Error('须提供 --draft 草稿文件或 --id 工作流库中的工作流 ID 之一;凭据用 --access-file 或 DISCUSS_ACCESS_FILE');
|
|
2369
2564
|
const { config, roster } = await host_room(home, access_file);
|
|
2370
|
-
if (!config
|
|
2565
|
+
if (!host_allowed(config, 'workflows')) throw new Error(host_refusal('workflows'));
|
|
2371
2566
|
const bound = config.workflow?.id;
|
|
2372
2567
|
let workflow;
|
|
2373
2568
|
if (workflow_id) workflow = get_workflow(home, workflow_id);
|
|
@@ -2387,7 +2582,7 @@ export async function adopt_workflow(home, { access_file, draft_file, workflow_i
|
|
|
2387
2582
|
const owner = { site: config.site, room_id: config.room, token: config.token };
|
|
2388
2583
|
const members = await join_workflow_cards(home, config, roster, workflow, bound === workflow.id ? config.workflow.members || {} : {});
|
|
2389
2584
|
const enabled = await room_workflow(home, { ...owner, action: 'enable', workflow: { id: workflow.id, members } });
|
|
2390
|
-
return { ...enabled, members, skill_path: join(workflow_directory(home, workflow.id), 'SKILL.md') };
|
|
2585
|
+
return { ...enabled, members, skill_path: join(workflow_directory(home, workflow.id), 'SKILL.md'), ...(workflow.warnings ? { warnings: workflow.warnings } : {}) };
|
|
2391
2586
|
}
|
|
2392
2587
|
|
|
2393
2588
|
/**
|
|
@@ -2460,6 +2655,7 @@ export async function launch_main(args = process.argv.slice(2), input_text) {
|
|
|
2460
2655
|
model: { type: 'string' }, effort: { type: 'string' }, do: { type: 'string' }, execution: { type: 'string' }, text: { type: 'string' },
|
|
2461
2656
|
goal: { type: 'string' }, label: { type: 'string' }, description: { type: 'string' }, adapter: { type: 'string' }, 'submission-id': { type: 'string' },
|
|
2462
2657
|
message: { type: 'string' }, minutes: { type: 'string' }, off: { type: 'boolean' }, list: { type: 'boolean' },
|
|
2658
|
+
title: { type: 'string' }, members: { type: 'string' }, host: { type: 'string' }, cwd: { type: 'string' }, room: { type: 'string' },
|
|
2463
2659
|
} });
|
|
2464
2660
|
if (values.help || !positionals.length) return process.stdout.write(command_help(positionals[0]));
|
|
2465
2661
|
if (positionals[0] === 'workflow-adopt') {
|
|
@@ -2470,18 +2666,19 @@ export async function launch_main(args = process.argv.slice(2), input_text) {
|
|
|
2470
2666
|
if (positionals[0] === 'host-control') {
|
|
2471
2667
|
const { member, order, revision, name, access, model, effort, execution, text, goal, label, description, adapter } = values;
|
|
2472
2668
|
const result = await host_control(service_home(), positionals[1], { member, order, revision, name, access, model, effort, execution, text, goal,
|
|
2473
|
-
label, description, adapter, message: values.message, minutes: values.minutes, off: values.off, list: values.list, do: values.do, submission_id: values['submission-id'],
|
|
2669
|
+
label, description, adapter, message: values.message, minutes: values.minutes, off: values.off, list: values.list, do: values.do, submission_id: values['submission-id'],
|
|
2670
|
+
title: values.title, members: values.members, host: values.host, cwd: values.cwd, room: values.room, access_file: values['access-file'] || process.env.DISCUSS_ACCESS_FILE });
|
|
2474
2671
|
return process.stdout.write(`${JSON.stringify(result)}
|
|
2475
2672
|
`);
|
|
2476
2673
|
}
|
|
2477
2674
|
if (positionals[0] === 'workflow-join') {
|
|
2478
2675
|
const cards = (values.card || '').split(',').map(card => card.trim()).filter(Boolean);
|
|
2479
|
-
const result = await join_workflow(service_home(), { cards, sub: values.sub, access_file: values['access-file'] || process.env.DISCUSS_ACCESS_FILE });
|
|
2676
|
+
const result = await join_workflow(service_home(), { cards, sub: values.sub, label: values.label, access_file: values['access-file'] || process.env.DISCUSS_ACCESS_FILE });
|
|
2480
2677
|
return process.stdout.write(`${JSON.stringify(result)}
|
|
2481
2678
|
`);
|
|
2482
2679
|
}
|
|
2483
2680
|
if (positionals[0] === 'workflow-leave') {
|
|
2484
|
-
const result = await leave_sub_workflow(service_home(), { sub: values.sub, access_file: values['access-file'] || process.env.DISCUSS_ACCESS_FILE });
|
|
2681
|
+
const result = await leave_sub_workflow(service_home(), { sub: values.sub, member: values.member, access_file: values['access-file'] || process.env.DISCUSS_ACCESS_FILE });
|
|
2485
2682
|
return process.stdout.write(`${JSON.stringify(result)}
|
|
2486
2683
|
`);
|
|
2487
2684
|
}
|
|
@@ -2503,7 +2700,7 @@ export async function launch_main(args = process.argv.slice(2), input_text) {
|
|
|
2503
2700
|
const space = account_space(home), restricted = Boolean(space.projects_root);
|
|
2504
2701
|
if (values.remote || restricted) {
|
|
2505
2702
|
guard_remote_request(positionals[0], input, { projects: granted_projects(home), participants: launch_settings(home).participants, home });
|
|
2506
|
-
if (values.remote && positionals[0] === 'room-workflow' && input?.action === 'host') throw new Error('
|
|
2703
|
+
if (values.remote && positionals[0] === 'room-workflow' && input?.action === 'host') throw new Error('主持人权限只能在电脑上开启');
|
|
2507
2704
|
if (restricted && positionals[0] === 'pick-directory') throw new Error('此账号只能使用自己的项目文件夹');
|
|
2508
2705
|
// Another device repeats the saved program locations it cannot see; keep them rather than dropping them.
|
|
2509
2706
|
if (positionals[0] === 'settings' && input?.participants) input.participants = keep_saved_locations(home, input.participants);
|
|
@@ -2514,7 +2711,7 @@ export async function launch_main(args = process.argv.slice(2), input_text) {
|
|
|
2514
2711
|
}
|
|
2515
2712
|
let result;
|
|
2516
2713
|
if (positionals[0] === 'settings') result = { ...(input ? save_launch_settings(home, input) : launch_settings(home)), api_providers: API_PROVIDERS,
|
|
2517
|
-
scheduler_providers: SCHEDULER_PROVIDERS,
|
|
2714
|
+
scheduler_providers: SCHEDULER_PROVIDERS, 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) };
|
|
2518
2715
|
// The online site an invitation would use, so an external expert's card says before the room exists whether a link can be made.
|
|
2519
2716
|
if (positionals[0] === 'settings') result.invite_site = await (await import('./external_gateway.mjs')).invite_site_state(home);
|
|
2520
2717
|
else if (positionals[0] === 'projects') result = input ? save_launch_projects(home, input) : launch_projects(home);
|
|
@@ -85,8 +85,7 @@ export const TASK_SUBCOMMANDS = ['room', 'message', 'turn', 'state', 'goal', 'mo
|
|
|
85
85
|
* The limit on a quick answer given inline with --body: a run allowed only codiscuss commands refuses a command line
|
|
86
86
|
* carrying shell symbols, and PowerShell rewrites `$` and backticks inside quotes. The participant skill says the same.
|
|
87
87
|
*/
|
|
88
|
-
export const INLINE_BODY_RULE = '--body
|
|
89
|
-
|
|
88
|
+
export const INLINE_BODY_RULE = '--body 只用于不超过 200 字的短答,不能含反引号、英文括号、$、;、&、|、<、> 或换行,否则写草稿再用 --body-file';
|
|
90
89
|
// How many times one execution is resumed to correct commands it can fix itself (2026-11-19 user: three).
|
|
91
90
|
export const MAX_REFUSAL_RETRIES = 3;
|
|
92
91
|
const REFUSED_COMMAND_SHOWN = 200;
|