ai_co_discuss 0.3.46 → 0.3.49
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 -0
- package/.agents/skills/discuss-host/references/discussion.md +113 -113
- package/.agents/skills/discuss-host/references/free.md +36 -34
- package/.agents/skills/discuss-host/references/goal.md +35 -0
- package/.agents/skills/discuss-participant/SKILL.md +1 -0
- package/.agents/skills/workflow-creator/SKILL.md +2 -2
- package/README.md +3 -1
- package/backend/admin.py +104 -35
- package/backend/free_room.py +2170 -2136
- package/backend/goal_room.py +358 -0
- package/backend/mode_room.py +105 -0
- package/backend/schema.sql +1593 -1510
- package/backend/server.py +2636 -2555
- package/backend/session_room.py +1180 -1148
- package/docs/THIRD_PARTY_NOTICES.md +1293 -1264
- package/docs/deployment.md +5 -1
- package/docs/en/workflow.md +15 -1
- package/docs/runner.md +28 -7
- package/docs/workflow.md +15 -1
- package/package.json +3 -2
- package/runner/adapters/api.mjs +333 -313
- package/runner/adapters/claude.mjs +12 -16
- package/runner/admin_account.mjs +12 -19
- package/runner/device_auth.mjs +369 -0
- package/runner/discuss.py +1208 -1125
- package/runner/discussion_launch.mjs +107 -12
- package/runner/discussion_service.mjs +25 -1
- package/runner/expert_prompts.mjs +132 -132
- package/runner/free_runner.mjs +982 -910
- package/runner/pinyin_table.mjs +406 -0
- package/runner/project_files.mjs +52 -3
- package/runner/relay_channel.mjs +51 -7
- package/runner/remote_launch.mjs +221 -235
- package/runner/remote_policy.mjs +156 -0
- package/runner/scheduler.mjs +459 -429
- package/runner/stt.mjs +2 -2
- package/runner/tts.mjs +74 -113
- package/runner/tts_providers.mjs +205 -0
- package/runner/webauthn.mjs +155 -0
- package/runner/workflows.mjs +371 -348
- package/web/app.js +355 -51
- package/web/modern.css +1 -1
- package/web/modern.js +5764 -3816
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What another device may ask this computer to do. Folders stay inside the saved projects (which only this computer
|
|
3
|
+
* can widen), software locations, tool approvals and full access are set only here, and each relayed command runs once
|
|
4
|
+
* within a short time window. Enforced in this process, never by the website or the page.
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync, opendirSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
7
|
+
import { dirname, isAbsolute, join, relative } from 'node:path';
|
|
8
|
+
|
|
9
|
+
import { atomic_json } from './files.mjs';
|
|
10
|
+
|
|
11
|
+
const DIRECTORY_PAGE_SIZE = 200;
|
|
12
|
+
// Stop reading a huge folder after this many entries; the listing says it was cut short.
|
|
13
|
+
const DIRECTORY_SCAN_LIMIT = 5000;
|
|
14
|
+
// A relayed command older or newer than this is refused; its id is remembered for twice as long.
|
|
15
|
+
export const COMMAND_MAX_AGE_MS = 10 * 60 * 1000;
|
|
16
|
+
const COMMANDS_FILE = 'relay-commands.json';
|
|
17
|
+
// Fields naming a program location: another device may only repeat what this computer already saved.
|
|
18
|
+
const SOFTWARE_FIELDS = ['executable', 'ipc_directory'];
|
|
19
|
+
// Actions that repair this computer's own software setup: never from another device.
|
|
20
|
+
const LOCAL_ONLY_ACTIONS = new Set(['room-config']);
|
|
21
|
+
// Commands that put a member to work in a room with the access they name.
|
|
22
|
+
const WRITE_COMMANDS = new Set(['start', 'room-member', 'room-member-access', 'room-restore', 'room-fork']);
|
|
23
|
+
|
|
24
|
+
/** True when `target` is `root` or lies inside it; Windows compares without case. */
|
|
25
|
+
function inside(root, target) {
|
|
26
|
+
const path = relative(root, target);
|
|
27
|
+
return path === '' || (!path.startsWith('..') && !isAbsolute(path));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Reject network shares, device names, stream suffixes and relative paths before touching the disk. */
|
|
31
|
+
function plain_absolute(path) {
|
|
32
|
+
if (typeof path !== 'string' || !path.trim() || path.includes('\0')) return false;
|
|
33
|
+
// \\server\share and \\?\ or \\.\ device paths would make Windows contact other machines or raw devices.
|
|
34
|
+
if (/^[\\/]{2}/.test(path)) return false;
|
|
35
|
+
if (process.platform === 'win32' && (path.indexOf(':', 2) >= 0 || !/^[A-Za-z]:[\\/]/.test(path))) return false;
|
|
36
|
+
return isAbsolute(path);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The real folders other devices may work in: the saved projects that still exist here. */
|
|
40
|
+
export function remote_roots(projects) {
|
|
41
|
+
const roots = [];
|
|
42
|
+
for (const project of projects || []) {
|
|
43
|
+
try {
|
|
44
|
+
const real = realpathSync(project.path);
|
|
45
|
+
if (statSync(real).isDirectory()) roots.push({ name: project.name, path: real });
|
|
46
|
+
} catch { /* A project moved away grants nothing. */ }
|
|
47
|
+
}
|
|
48
|
+
return roots;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Resolve a folder another device named, through links, and require it to sit inside a saved project and outside this
|
|
53
|
+
* service's own directory. Returns the real path.
|
|
54
|
+
*/
|
|
55
|
+
export function remote_directory(path, { roots, home }) {
|
|
56
|
+
const refused = new Error(`电脑未允许其他设备使用这个目录:${typeof path === 'string' ? path : ''}。请在电脑上把它(或它的上级目录)加入常用项目`);
|
|
57
|
+
if (!plain_absolute(path)) throw refused;
|
|
58
|
+
let real;
|
|
59
|
+
try { real = realpathSync(path); } catch { throw refused; }
|
|
60
|
+
if (!plain_absolute(real) || !statSync(real).isDirectory()) throw refused;
|
|
61
|
+
if (!roots.some(root => inside(root.path, real))) throw refused;
|
|
62
|
+
let service;
|
|
63
|
+
try { service = realpathSync(home); } catch { service = home; }
|
|
64
|
+
if (inside(service, real)) throw refused;
|
|
65
|
+
return real;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Visit every value under `value`, calling `visit(key, item)` for each object property. */
|
|
69
|
+
function walk(value, visit) {
|
|
70
|
+
if (Array.isArray(value)) return value.forEach(item => walk(item, visit));
|
|
71
|
+
if (!value || typeof value !== 'object') return;
|
|
72
|
+
for (const [key, item] of Object.entries(value)) {
|
|
73
|
+
visit(key, item);
|
|
74
|
+
walk(item, visit);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Refuse a relayed request that would reach past what this computer granted: a folder outside the saved projects,
|
|
80
|
+
* a program location not already saved here, full access, or write access to a room without this device's
|
|
81
|
+
* passkey-confirmed grant (`write_allowed(room_id)`).
|
|
82
|
+
*/
|
|
83
|
+
export function guard_remote_request(command, input, { projects, participants, home, write_allowed = () => false, write_needed }) {
|
|
84
|
+
if (LOCAL_ONLY_ACTIONS.has(command)) throw new Error('此操作只能在这台电脑上执行');
|
|
85
|
+
if (!input || typeof input !== 'object') return;
|
|
86
|
+
const roots = remote_roots(projects);
|
|
87
|
+
const saved = Object.values(participants || {});
|
|
88
|
+
const known = Object.fromEntries(SOFTWARE_FIELDS.map(field => [field, new Set(saved.map(profile => profile[field]).filter(Boolean))]));
|
|
89
|
+
let writes = false;
|
|
90
|
+
walk(input, (key, value) => {
|
|
91
|
+
if (key === 'cwd' && value) remote_directory(value, { roots, home });
|
|
92
|
+
else if (SOFTWARE_FIELDS.includes(key) && value && !known[key].has(value)) throw new Error(`其他设备不能更改软件位置(${key}),请在电脑上设置`);
|
|
93
|
+
else if (key === 'project_access' && value === 'full') throw new Error('“全放开”只能在电脑上设置');
|
|
94
|
+
// `own` comes only from taking over a session on this computer; it may write, so another device cannot claim it.
|
|
95
|
+
else if (key === 'project_access' && value === 'own') throw new Error('沿用原会话权限(own)只能在电脑上接管会话时产生');
|
|
96
|
+
else if (key === 'project_access' && ['write', 'auto'].includes(value)) writes = true;
|
|
97
|
+
// An approved tool such as a shell can change files whatever the member's level says.
|
|
98
|
+
else if (key === 'allowed_tools' && Array.isArray(value) && value.length) writes = true;
|
|
99
|
+
});
|
|
100
|
+
// Saved presets and workflow cards only describe access; it takes effect in a room, which is checked here.
|
|
101
|
+
if (writes && WRITE_COMMANDS.has(command)) {
|
|
102
|
+
if (command === 'start' || typeof input.room_id !== 'string') throw new Error('其他设备新建房间时成员须为只读;建好后在房间里开启可写(需通行密钥确认)');
|
|
103
|
+
if (!write_allowed(input.room_id)) throw write_needed(input.room_id);
|
|
104
|
+
}
|
|
105
|
+
// A saved project only widens what other devices reach, so a new or moved one must already lie inside the old ones.
|
|
106
|
+
if (command === 'projects' && Array.isArray(input.projects)) {
|
|
107
|
+
const existing = new Map((projects || []).map(project => [project.id, project.path]));
|
|
108
|
+
for (const project of input.projects) {
|
|
109
|
+
if (existing.get(project?.id) !== project?.path) remote_directory(project?.path, { roots, home });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* List the sub-folders another device may browse: the saved projects at the top, then folders inside them, one page
|
|
116
|
+
* at a time. Only folder names are returned, never file names or contents.
|
|
117
|
+
*/
|
|
118
|
+
export function list_remote_directories({ path = '', offset = 0 } = {}, { projects, home }) {
|
|
119
|
+
if (!Number.isSafeInteger(offset) || offset < 0) throw new Error('目录分页位置无效');
|
|
120
|
+
const roots = remote_roots(projects);
|
|
121
|
+
if (!path) return { path: '', parent: null, entries: roots.map(root => ({ name: root.name, path: root.path })), next_offset: null, truncated: false };
|
|
122
|
+
const folder = remote_directory(path, { roots, home });
|
|
123
|
+
const names = [];
|
|
124
|
+
let scanned = 0, truncated = false;
|
|
125
|
+
const directory = opendirSync(folder);
|
|
126
|
+
try {
|
|
127
|
+
for (let entry = directory.readSync(); entry; entry = directory.readSync()) {
|
|
128
|
+
if (++scanned > DIRECTORY_SCAN_LIMIT) { truncated = true; break; }
|
|
129
|
+
// Links are not followed, so browsing never leaves the granted folders.
|
|
130
|
+
if (entry.isDirectory()) names.push(entry.name);
|
|
131
|
+
}
|
|
132
|
+
} finally { directory.closeSync(); }
|
|
133
|
+
names.sort((left, right) => left.localeCompare(right, 'zh-CN', { numeric: true }));
|
|
134
|
+
const page = names.slice(offset, offset + DIRECTORY_PAGE_SIZE);
|
|
135
|
+
const parent = roots.some(root => relative(root.path, folder) === '') ? '' : dirname(folder);
|
|
136
|
+
return { path: folder, parent, entries: page.map(name => ({ name, path: join(folder, name) })),
|
|
137
|
+
next_offset: offset + page.length < names.length ? offset + page.length : null, truncated };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Accept a relayed command id once: it must carry a send time within the window, and an id already run inside the
|
|
142
|
+
* window is refused. Ids are kept on disk so a restart does not reopen the window.
|
|
143
|
+
*/
|
|
144
|
+
export function claim_relayed_command(home, id, sent_at, now = Date.now()) {
|
|
145
|
+
if (typeof id !== 'string' || !id) throw new Error('远程命令缺少编号');
|
|
146
|
+
if (!Number.isFinite(sent_at) || Math.abs(now - sent_at) > COMMAND_MAX_AGE_MS) {
|
|
147
|
+
throw new Error('远程命令已过期或设备时间偏差过大,请核对手机时间后重试');
|
|
148
|
+
}
|
|
149
|
+
const path = join(home, COMMANDS_FILE);
|
|
150
|
+
let seen = {};
|
|
151
|
+
try { if (existsSync(path)) seen = JSON.parse(readFileSync(path, 'utf8')).ids || {}; } catch { seen = {}; }
|
|
152
|
+
if (seen[id]) throw new Error('远程命令已执行过,不再重复执行');
|
|
153
|
+
const kept = Object.fromEntries(Object.entries(seen).filter(([, time]) => now - time <= 2 * COMMAND_MAX_AGE_MS));
|
|
154
|
+
kept[id] = now;
|
|
155
|
+
atomic_json(path, { ids: kept });
|
|
156
|
+
}
|