ai_co_discuss 0.5.21 → 0.5.23

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 (85) hide show
  1. package/.agents/skills/codiscuss-draft-cleanup/SKILL.md +16 -0
  2. package/.agents/skills/codiscuss-draft-cleanup/cleanup.py +70 -0
  3. package/.agents/skills/codiscuss-draft-cleanup/scan.py +70 -0
  4. package/.agents/skills/discuss-host/references/control.md +2 -2
  5. package/.agents/skills/discuss-host/references/workflow.md +4 -2
  6. package/.agents/skills/discuss-participant/SKILL.md +2 -0
  7. package/.agents/skills/local-stt-setup/SKILL.md +9 -8
  8. package/.agents/skills/local-tts-setup/SKILL.md +10 -9
  9. package/.agents/skills/share-card/SKILL.md +7 -6
  10. package/.agents/skills/share-card/references/share-card.md +34 -8
  11. package/.agents/skills/workflow-creator/SKILL.md +22 -14
  12. package/README.md +2 -0
  13. package/README.zh-CN.md +2 -0
  14. package/backend/free_room.py +64 -8
  15. package/backend/message_queue.py +9 -0
  16. package/backend/schema.sql +13 -1
  17. package/backend/server.py +289 -59
  18. package/docs/en/guide/admin.md +18 -0
  19. package/docs/en/guide/members.md +7 -1
  20. package/docs/en/guide/remote.md +1 -1
  21. package/docs/en/guide/rooms.md +14 -6
  22. package/docs/en/guide/voice.md +2 -0
  23. package/docs/en/guide/workflows.md +9 -5
  24. package/docs/en/guide/working.md +6 -4
  25. package/docs/guide/admin.md +18 -0
  26. package/docs/guide/members.md +7 -1
  27. package/docs/guide/remote.md +1 -1
  28. package/docs/guide/rooms.md +13 -6
  29. package/docs/guide/voice.md +2 -0
  30. package/docs/guide/workflows.md +9 -5
  31. package/docs/guide/working.md +6 -4
  32. package/frontend/locales/en/admin.json +58 -1
  33. package/frontend/locales/en/app.json +18 -1
  34. package/frontend/locales/en/backend.json +6 -0
  35. package/frontend/locales/en/core.json +4 -2
  36. package/frontend/locales/en/discussion.json +4 -1
  37. package/frontend/locales/en/room.json +85 -1
  38. package/gateway/gateway.mjs +49 -9
  39. package/package.json +3 -1
  40. package/runner/account_space.mjs +10 -0
  41. package/runner/adapters/antigravity_app.mjs +31 -4
  42. package/runner/adapters/antigravity_cli.mjs +9 -2
  43. package/runner/adapters/api.mjs +3 -2
  44. package/runner/adapters/api_pi.mjs +3 -2
  45. package/runner/adapters/api_pi_extension.mjs +5 -3
  46. package/runner/adapters/claude.mjs +32 -9
  47. package/runner/adapters/cli.mjs +2 -2
  48. package/runner/adapters/codex_app.mjs +192 -69
  49. package/runner/adapters/codex_cli.mjs +10 -5
  50. package/runner/adapters/common.mjs +414 -11
  51. package/runner/adapters/index.mjs +6 -0
  52. package/runner/admin_cli.mjs +22 -5
  53. package/runner/admin_panel.mjs +118 -5
  54. package/runner/admin_storage.mjs +105 -0
  55. package/runner/discussion_launch.mjs +328 -128
  56. package/runner/discussion_runner.mjs +12 -3
  57. package/runner/discussion_service.mjs +224 -37
  58. package/runner/discussion_skills.mjs +1 -1
  59. package/runner/expert_prompts.mjs +2 -2
  60. package/runner/experts.mjs +227 -0
  61. package/runner/file_diff.mjs +1 -1
  62. package/runner/free_runner.mjs +236 -51
  63. package/runner/i18n_en.mjs +39 -0
  64. package/runner/os_users.mjs +33 -1
  65. package/runner/project_files.mjs +7 -1
  66. package/runner/project_migration.mjs +245 -0
  67. package/runner/relay_channel.mjs +1 -1
  68. package/runner/remote_launch.mjs +4 -3
  69. package/runner/share_card.mjs +17 -1
  70. package/runner/share_shared.mjs +26 -9
  71. package/runner/site_deploy.mjs +2 -1
  72. package/runner/slash_names.mjs +12 -1
  73. package/runner/speech_directories.mjs +20 -0
  74. package/runner/storage_guard.mjs +383 -0
  75. package/runner/tts_providers.mjs +22 -21
  76. package/runner/workflows.mjs +211 -57
  77. package/web/admin.css +1 -1
  78. package/web/admin.js +8 -8
  79. package/web/app.js +589 -80
  80. package/web/i18n.js +4 -4
  81. package/web/markdown.css +1 -1
  82. package/web/modern.css +1 -1
  83. package/web/modern.js +68 -66
  84. package/workflows/decision-council/flow.json +216 -25
  85. package/workflows/trpg-classic/flow.json +151 -21
@@ -0,0 +1,227 @@
1
+ import { BUILTIN_EXPERT_PRESETS } from './expert_prompts.mjs';
2
+ import { createHash, randomUUID } from 'node:crypto';
3
+ import { cpSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
4
+ import { basename, dirname, join } from 'node:path';
5
+ import { DatabaseSync } from 'node:sqlite';
6
+ import { atomic_json } from './files.mjs';
7
+ import { expert_disk_key, expert_skills, parse_markdown, serialize_markdown } from './workflows.mjs';
8
+
9
+ const ID = /^[a-zA-Z0-9_]{1,16}$/;
10
+ const FIELDS = ['label', 'description', 'project_access', 'model', 'effort'];
11
+
12
+ function checked(...paths) {
13
+ for (const path of paths) {
14
+ if (lstatSync(path, { throwIfNoEntry: false })?.isSymbolicLink()) throw new Error('专家路径不能包含符号链接');
15
+ }
16
+ return paths.at(-1);
17
+ }
18
+
19
+ function root_path(root, home) {
20
+ if (!root) return checked(join(home, 'experts'));
21
+ const base = join(root.path, '.codiscuss');
22
+ return checked(base, join(base, 'experts'));
23
+ }
24
+
25
+ function location(directory, id) {
26
+ if (!/^(?:[a-z]+-)?[A-Za-z0-9_]{1,16}$/.test(id)) throw new Error('无效的专家编号');
27
+ const folder = checked(join(directory, id));
28
+ const flat = checked(join(directory, id + '.md'));
29
+ if (existsSync(flat) && existsSync(folder)) throw new Error('专家的单文件和文件夹不能同时存在');
30
+ return existsSync(folder) ? checked(join(folder, id + '.md')) : flat;
31
+ }
32
+
33
+ function trust_key(root, id) { return 'expert:' + root.id + ':' + id; }
34
+
35
+ function read_trust(home) {
36
+ const path = join(home, 'project-trust.json');
37
+ return existsSync(path) ? JSON.parse(readFileSync(path, 'utf8')) : {};
38
+ }
39
+
40
+ function digest(path) {
41
+ const hash = createHash('sha256').update(readFileSync(path));
42
+ const skills = join(dirname(path), 'skills');
43
+ function visit(directory, prefix) {
44
+ for (const item of readdirSync(directory, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
45
+ const file = checked(join(directory, item.name)), key = prefix + item.name;
46
+ if (item.isDirectory()) visit(file, key + '/');
47
+ else if (item.isFile()) hash.update(key).update('\0').update(readFileSync(file)).update('\0');
48
+ }
49
+ }
50
+ if (path === join(dirname(path), basename(dirname(path)) + '.md') && existsSync(checked(skills))) visit(skills, '');
51
+ return hash.digest('hex');
52
+ }
53
+
54
+ function record_trust(home, root, id, path) {
55
+ atomic_json(join(home, 'project-trust.json'), { ...read_trust(home), [trust_key(root, id)]: digest(path) });
56
+ }
57
+
58
+ /** Read standalone project experts, preserving requested access for owner approval. */
59
+ export function project_experts(home, root, validate) {
60
+ const directory = root_path(root, home);
61
+ if (!existsSync(directory)) return [];
62
+ const records = root ? read_trust(home) : {};
63
+ const result = [];
64
+ for (const item of readdirSync(directory, { withFileTypes: true })) {
65
+ const disk = item.isDirectory() ? item.name : item.name.replace(/\.md$/, '');
66
+ if (!/^(?:[a-z]+-)?[A-Za-z0-9_]{1,16}$/.test(disk) || (!item.isDirectory() && !item.name.endsWith('.md'))) continue;
67
+ const path = location(directory, disk);
68
+ if (!existsSync(path)) continue;
69
+ const { fields, body } = parse_markdown(readFileSync(path, 'utf8'), path);
70
+ const id = fields.name || fields.platform;
71
+ if (!ID.test(id) || (disk !== id && disk !== fields.platform?.toLowerCase() + '-' + id)) throw new Error('专家文件名与编号不一致');
72
+ const preset = { name: fields.name ? fields.platform + '-' + id : fields.platform, system_prompt: body };
73
+ for (const key of FIELDS) if (fields[key]) preset[key] = fields[key];
74
+ validate?.(preset);
75
+ const trusted = !root || records[trust_key(root, disk)] === digest(path);
76
+ const skills = checked(join(directory, disk), join(directory, disk, 'skills'));
77
+ if (existsSync(skills)) for (const entry of readdirSync(skills)) checked(join(skills, entry), join(skills, entry, 'SKILL.md'));
78
+ result.push({ ...preset, id, platform: fields.platform, scope: root ? 'project' : 'global',
79
+ ...(root ? { project_id: root.id, project_name: root.name, readonly: root.readonly, trusted } : {}), skills: expert_skills(join(directory, disk)),
80
+ ...(!trusted && preset.project_access && preset.project_access !== 'read' ? { project_access: 'read', requested_access: preset.project_access } : {}) });
81
+ }
82
+ return result;
83
+ }
84
+
85
+ /** Edit one project preset under the same local lock as project trust records. */
86
+ export function change_project_expert(home, root, input, validate) {
87
+ return with_expert_lock(home, () => update_definition(home, root, input, validate));
88
+ }
89
+
90
+ function with_expert_lock(home, action) {
91
+ mkdirSync(home, { recursive: true });
92
+ const lock = new DatabaseSync(join(home, 'workflows-lock.sqlite3'));
93
+ try {
94
+ lock.exec('PRAGMA busy_timeout=5000; BEGIN IMMEDIATE');
95
+ return action();
96
+ } finally { lock.close(); }
97
+ }
98
+
99
+ function update_definition(home, root, input, validate) {
100
+ const directory = root_path(root, home);
101
+ const name = input.preset?.name || input.name || '';
102
+ const id = input.id || name.split('-').at(-1);
103
+ const entries = name ? [] : project_experts(home, root, validate).filter(item => item.id === id);
104
+ if (!name && entries.length !== 1) throw new Error('请使用完整专家名称');
105
+ const platform = name ? name.split('-')[0] : entries[0].platform;
106
+ const disk = expert_disk_key(directory, platform, id);
107
+ const path = location(directory, disk);
108
+ if (input.action === 'trust') {
109
+ if (!existsSync(path)) throw new Error('找不到项目专家');
110
+ if (root) record_trust(home, root, disk, path);
111
+ return;
112
+ }
113
+ if (root?.readonly) throw new Error('项目目录只读');
114
+ if (input.action === 'delete') {
115
+ const current = project_experts(home, root, validate).find(item => item.id === id && (!name || item.name === name));
116
+ if (!current) throw new Error('找不到项目专家');
117
+ const target = dirname(path) === directory ? path : dirname(path);
118
+ const backup = join(home, 'backups', 'expert-' + id + '-' + randomUUID());
119
+ mkdirSync(dirname(backup), { recursive: true });
120
+ cpSync(target, backup, { recursive: true });
121
+ rmSync(target, { recursive: true });
122
+ return;
123
+ }
124
+ if (input.action !== 'save') throw new Error('未知的专家操作');
125
+ const preset = Object.fromEntries(['name', 'system_prompt', ...FIELDS].filter(key => input.preset[key] !== undefined).map(key => [key, input.preset[key]]));
126
+ validate?.(preset);
127
+ if (name !== platform && name !== platform + '-' + id) throw new Error('专家名称与编号不一致');
128
+ if (existsSync(path) && parse_markdown(readFileSync(path, 'utf8'), path).fields.platform !== platform) throw new Error('此专家编号已由另一个平台使用');
129
+ if (existsSync(path) && !input.overwrite) throw Object.assign(new Error('专家已存在'), { code: 'preset_exists', details: {} });
130
+ const fields = Object.fromEntries(FIELDS.map(key => [key, preset[key]]));
131
+ mkdirSync(dirname(path), { recursive: true });
132
+ for (const leftover of readdirSync(dirname(path))) {
133
+ if (/\.md\.[0-9a-f-]{36}\.tmp$/.test(leftover)) rmSync(join(dirname(path), leftover), { force: true });
134
+ }
135
+ const tmp = path + '.' + randomUUID() + '.tmp';
136
+ try {
137
+ writeFileSync(tmp, serialize_markdown({ name: name === platform ? '' : id, platform, ...fields }, preset.system_prompt));
138
+ renameSync(tmp, path);
139
+ } finally { rmSync(tmp, { force: true }); }
140
+ if (root) record_trust(home, root, disk, path);
141
+ }
142
+
143
+ function update_templates(home, templates) {
144
+ if (templates === undefined) return;
145
+ const lock = new DatabaseSync(join(home, 'launch-settings-lock.sqlite3'));
146
+ try {
147
+ lock.exec('PRAGMA busy_timeout=5000; BEGIN IMMEDIATE');
148
+ const file = join(home, 'launch-settings.json');
149
+ const settings = existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : { participants: {} };
150
+ atomic_json(file, { ...settings, description_templates: templates });
151
+ } finally { lock.close(); }
152
+ }
153
+
154
+ /** Copy legacy skills through a staging directory so an interrupted backup can be retried. */
155
+ function backup_legacy_skills(source, destination) {
156
+ if (existsSync(destination)) return;
157
+ mkdirSync(dirname(destination), { recursive: true });
158
+ const staging = destination + '.' + randomUUID() + '.tmp';
159
+ try {
160
+ cpSync(source, staging, { recursive: true });
161
+ renameSync(staging, destination);
162
+ } finally { rmSync(staging, { force: true, recursive: true }); }
163
+ }
164
+
165
+ /** Migrate legacy definitions once, retaining the source and copies of shared platform skills. */
166
+ export function ensure_global_experts_migrated(home) {
167
+ const marker = join(home, 'experts-migrated-v1');
168
+ if (existsSync(marker)) return;
169
+ with_expert_lock(home, () => {
170
+ if (existsSync(marker)) return;
171
+ const legacy = join(home, 'expert-presets.json'), archived = legacy + '.migrated';
172
+ const source = existsSync(legacy) ? legacy : archived;
173
+ const data = existsSync(source) ? JSON.parse(readFileSync(source, 'utf8')) : {};
174
+ const presets = [...(data.presets || [])];
175
+ for (const preset of BUILTIN_EXPERT_PRESETS) {
176
+ if (!data.hidden_builtins?.includes(preset.name) && !presets.some(item => item.name === preset.name)) presets.push(preset);
177
+ }
178
+ const names = new Set(presets.map(item => item.name));
179
+ const directory = root_path(null, home), backups = join(home, 'backups');
180
+ if (existsSync(source)) {
181
+ mkdirSync(backups, { recursive: true });
182
+ const copy = join(backups, 'expert-presets-migration-v1.json');
183
+ if (!existsSync(copy)) cpSync(source, copy);
184
+ }
185
+ for (const original of presets) {
186
+ const preset = { ...original }, [platform] = preset.name.split('-');
187
+ if (!/^[A-Za-z]+$/.test(platform)) throw new Error('无效的旧专家平台');
188
+ const original_id = preset.name.slice(platform.length + 1) || platform;
189
+ let id = original_id;
190
+ if (!ID.test(id)) {
191
+ let index = 1;
192
+ while (names.has(platform + '-preset' + index)) index++;
193
+ id = 'preset' + index;
194
+ preset.label ||= preset.name;
195
+ preset.name = platform + '-' + id;
196
+ names.add(preset.name);
197
+ }
198
+ const disk = expert_disk_key(directory, platform, id);
199
+ if (disk !== original_id && /^[\p{L}\p{N}_-]+$/u.test(original_id)) {
200
+ const shared = checked(join(directory, original_id), join(directory, original_id, 'skills'));
201
+ if (existsSync(shared)) {
202
+ const backup = join(backups, 'expert-skills-v1-' + original_id);
203
+ backup_legacy_skills(shared, backup);
204
+ cpSync(backup, join(directory, disk, 'skills'), { recursive: true });
205
+ }
206
+ }
207
+ update_definition(home, null, { action: 'save', preset, overwrite: true });
208
+ }
209
+ update_templates(home, data.description_templates);
210
+ if (existsSync(legacy)) renameSync(legacy, archived);
211
+ writeFileSync(marker, '1\n');
212
+ });
213
+ }
214
+
215
+ /** Reconcile legacy bulk updates with definitions while preserving unchanged skill folders. */
216
+ export function replace_global_experts(home, presets, templates, validate) {
217
+ with_expert_lock(home, () => {
218
+ if (presets) {
219
+ const before = project_experts(home, null, validate);
220
+ for (const preset of presets) update_definition(home, null, { action: 'save', preset, overwrite: true }, validate);
221
+ for (const previous of before) if (!presets.some(item => item.name === previous.name)) {
222
+ update_definition(home, null, { action: 'delete', name: previous.name }, validate);
223
+ }
224
+ }
225
+ update_templates(home, templates);
226
+ });
227
+ }
@@ -45,7 +45,7 @@ export function capture_base(directory, before) {
45
45
 
46
46
  /** The file as Git has it (the last commit), or missing when Git does not track it. */
47
47
  function committed(directory, path) {
48
- const result = spawnSync('git', ['-C', directory, 'show', `HEAD:${path}`], { maxBuffer: MAX_DIFF_BYTES * 2, windowsHide: true, timeout: GIT_TIMEOUT_MS });
48
+ const result = spawnSync('git', ['-C', directory, 'show', `HEAD:./${path}`], { maxBuffer: MAX_DIFF_BYTES * 2, windowsHide: true, timeout: GIT_TIMEOUT_MS });
49
49
  if (result.status !== 0) return { missing: true };
50
50
  if (result.stdout.length > MAX_DIFF_BYTES) return { skipped: 'large' };
51
51
  return result.stdout.includes(0) ? { skipped: 'binary' } : { text: result.stdout.toString('utf8') };