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
@@ -19,15 +19,417 @@ export function cli_timeout_reason(milliseconds) {
19
19
  return t('CLI 运行超过 {seconds} 秒仍未结束,已终止', { seconds: Math.round(milliseconds / 1000) });
20
20
  }
21
21
  /** Tool names that edit files, across the softwares' event streams. */
22
- // A shell command that may write files: a redirect into a file, an in-place edit, a script writing, a copy, move or
23
- // delete. Only such a command claims the paths it names; reading commands (cat, grep, git diff) claim none.
24
- const SHELL_WRITES = /(?<![=\-<>])>{1,2}(?!=)\s*(?!&|\/dev\/null|\$null|nul\b)|\bsed\s+-i|\.write\w*\(|write_text|writeFileSync|\b(?:Set|Add)-Content\b|\bOut-File\b|\btee\b|\b(?:mv|cp|rm)\s|\b(?:Move|Copy|Remove|Rename)-Item\b|\bgit\s+(?:checkout|restore|apply|mv|rm)\b/i;
22
+ const SHELL_WRAPPER_PREFIX = /^"?[^"]*?(?:powershell|pwsh|cmd|bash|sh)(?:\.exe)?"?\s+(?:(?:-[A-Za-z]+(?:\s+(?!-Command\b|\/c\b|-lc\b|-c\b)[^\s'"]+)?)\s+)*(?:-Command|\/c|-lc|-c)\s+([\s\S]*)$/i;
23
+ const NULL_DEVICES = new Set(['/dev/null', '$null', 'nul', 'con', 'prn', 'aux']);
24
+ const PS_SWITCH_FLAGS = new Set(['-force', '-nonewline', '-passthru', '-append', '-noclobber', '-whatif', '-confirm', '-asbytestream', '-raw', '-recurse']);
25
+ const PS_PATH_FLAGS = new Set(['-path', '-literalpath', '-filepath']);
26
+
27
+ /** Decode a shlex-style single/double-quoted shell argument string back into its inner script text. */
28
+ function unquote_shell_arg(raw) {
29
+ const text = raw.trim();
30
+ if (!text || !['\'', '"'].includes(text[0])) return text;
31
+ let result = '', i = 0;
32
+ while (i < text.length) {
33
+ const ch = text[i];
34
+ if (ch === '\'') {
35
+ const end = text.indexOf('\'', i + 1);
36
+ if (end < 0) return text;
37
+ result += text.slice(i + 1, end);
38
+ i = end + 1;
39
+ } else if (ch === '"') {
40
+ i += 1;
41
+ let closed = false;
42
+ while (i < text.length) {
43
+ if (text[i] === '\\' && i + 1 < text.length && ['"', '\\', '$', '`'].includes(text[i + 1])) {
44
+ result += text[i + 1];
45
+ i += 2;
46
+ } else if (text[i] === '"') {
47
+ i += 1;
48
+ closed = true;
49
+ break;
50
+ } else {
51
+ result += text[i++];
52
+ }
53
+ }
54
+ if (!closed) return text;
55
+ } else {
56
+ return text;
57
+ }
58
+ }
59
+ return result;
60
+ }
61
+
62
+ /** Strip an outer shell wrapper (`powershell -Command …`, `bash -lc …`, `cmd /c …`) to inspect the real command. */
63
+ function unwrap_shell_command(command) {
64
+ const text = String(command || '').trim();
65
+ const match = text.match(SHELL_WRAPPER_PREFIX);
66
+ return match ? unquote_shell_arg(match[1]) : text;
67
+ }
68
+
69
+ /** Keep only plausible literal target file paths; reject options, variables, globs, URLs and null devices. */
70
+ function clean_target_path(raw) {
71
+ let value = String(raw || '').trim();
72
+ if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith('\'') && value.endsWith('\''))) value = value.slice(1, -1).trim();
73
+ if (!value || value.startsWith('-') || value.startsWith('&') || NULL_DEVICES.has(value.toLowerCase())) return '';
74
+ if (/[\r\n\t*?`$%]|^[a-z][a-z0-9+.-]*:\/\//i.test(value) || value === '.' || value === '..') return '';
75
+ return value;
76
+ }
77
+
78
+ /** Add one cleaned literal path into a target set. */
79
+ function collect_path(targets, raw) {
80
+ const cleaned = clean_target_path(raw);
81
+ if (cleaned) targets.add(cleaned);
82
+ }
83
+
84
+ /** Resolve a variable or literal argument against literal path bindings. */
85
+ function collect_bound(targets, literal, variable, bindings) {
86
+ if (literal) return collect_path(targets, literal);
87
+ for (const item of bindings.get(variable) || []) collect_path(targets, item);
88
+ }
25
89
 
26
- /** The paths a file-writing shell command names (with a folder or an extension), so files it wrote count as the agent's own. */
90
+ /** Extract literal write targets from an embedded Python snippet in statement order; reads claim nothing. */
91
+ // Ignore write-like examples inside strings and comments.
92
+ function* script_calls(stmt, pattern, syntax) {
93
+ const spans = [...stmt.matchAll(syntax)];
94
+ for (const match of stmt.matchAll(pattern)) {
95
+ if (!spans.some(span => span.index <= match.index && match.index < span.index + span[0].length)) yield match;
96
+ }
97
+ }
98
+ const PYTHON_DATA = /'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|#.*/g;
99
+ const NODE_DATA = /'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|\x60(?:\\.|[^\x60\\])*\x60|\/\/.*/g;
100
+
101
+ function python_written_paths(script) {
102
+ const bindings = new Map(), targets = new Set();
103
+ for (const raw_line of String(script || '').split(/\r?\n/)) {
104
+ if (/^\s*#/.test(raw_line)) continue;
105
+ const loop = raw_line.match(/^\s*for\s+(\w+)(\s*,\s*\w+)*\s+in\s+\[([\s\S]*?)\]\s*:/);
106
+ if (loop) {
107
+ const pattern = loop[2] ? /\(\s*r?(['"])([^'"]+)\1/g : /(?:^|,)\s*r?(['"])([^'"]+)\1/g;
108
+ const items = [...loop[3].matchAll(pattern)].map(item => item[2]);
109
+ if (items.length) bindings.set(loop[1], items);
110
+ else bindings.delete(loop[1]);
111
+ }
112
+ for (const stmt of raw_line.split(';')) {
113
+ const assign = stmt.match(/^\s*(\w+)\s*=(?!=)\s*(.*)$/);
114
+ if (assign) {
115
+ const rhs = assign[2].trim();
116
+ const literal = rhs.match(/^(?:(?:pathlib\.)?Path\(\s*)?r?(['"])([^'"]+)\1\s*\)?\s*(?:#.*)?$/)?.[2];
117
+ const ref = !literal && rhs.match(/^(?:(?:pathlib\.)?Path\(\s*)?(\w+)\s*\)?\s*(?:#.*)?$/)?.[1];
118
+ if (literal) bindings.set(assign[1], [literal]);
119
+ else if (ref && bindings.has(ref)) bindings.set(assign[1], bindings.get(ref));
120
+ else bindings.delete(assign[1]);
121
+ }
122
+ for (const m of script_calls(stmt, /(?:pathlib\.)?Path\(\s*(?:r?(['"])([^'"]+)\1|(\w+))\s*\)\.(?:write_text|write_bytes|unlink)\(/g, PYTHON_DATA)) {
123
+ collect_bound(targets, m[2], m[3], bindings);
124
+ }
125
+ for (const m of script_calls(stmt, /\b(\w+)\.(?:write_text|write_bytes|unlink)\(/g, PYTHON_DATA)) {
126
+ collect_bound(targets, '', m[1], bindings);
127
+ }
128
+ for (const m of script_calls(stmt, /\bopen\(\s*(?:r?(['"])([^'"]+)\1|(\w+))\s*,\s*(?:mode\s*=\s*)?['"](?=[rwbta+x]*[wax+])[rwbta+x]+['"]/g, PYTHON_DATA)) {
129
+ collect_bound(targets, m[2], m[3], bindings);
130
+ }
131
+ for (const m of script_calls(stmt, /\b(\w+)\.open\(\s*(?:mode\s*=\s*)?['"][^'"]*[wax+][^'"]*['"]/g, PYTHON_DATA)) {
132
+ collect_bound(targets, '', m[1], bindings);
133
+ }
134
+ for (const m of script_calls(stmt, /\bshutil\.(?:copy|copy2|copyfile)\(\s*[^,\n]+,\s*(?:r?(['"])([^'"]+)\1|(\w+))\s*[,)]/g, PYTHON_DATA)) {
135
+ collect_bound(targets, m[2], m[3], bindings);
136
+ }
137
+ for (const m of script_calls(stmt, /\bos\.(?:remove|unlink)\(\s*(?:r?(['"])([^'"]+)\1|(\w+))\s*\)/g, PYTHON_DATA)) {
138
+ collect_bound(targets, m[2], m[3], bindings);
139
+ }
140
+ for (const m of script_calls(stmt, /\bos\.(?:replace|rename)\(\s*(?:r?(['"])([^'"]+)\1|(\w+))\s*,\s*(?:r?(['"])([^'"]+)\4|(\w+))\s*\)/g, PYTHON_DATA)) {
141
+ collect_bound(targets, m[2], m[3], bindings);
142
+ collect_bound(targets, m[5], m[6], bindings);
143
+ }
144
+ }
145
+ }
146
+ return [...targets];
147
+ }
148
+
149
+ /** Extract literal write targets from an embedded Node snippet (`node -e` / `node -`); imports and reads claim nothing. */
150
+ function node_written_paths(script) {
151
+ const bindings = new Map(), targets = new Set();
152
+ for (const line of String(script || '').split(/\r?\n/)) {
153
+ for (const stmt of line.split(';')) {
154
+ const assign = stmt.match(/^\s*(?:(?:const|let|var)\s+)?(\w+)\s*=(?!=)\s*(.*)$/);
155
+ if (assign) {
156
+ const literal = assign[2].trim().match(/^(['"])([^'"]+)\1\s*(?:\/\/.*)?$/)?.[2];
157
+ if (literal) bindings.set(assign[1], [literal]);
158
+ else bindings.delete(assign[1]);
159
+ }
160
+ for (const m of script_calls(stmt, /(?:\bfs(?:\.promises)?\.)?(?:writeFileSync|appendFileSync|writeFile|appendFile|rmSync|unlinkSync|unlink)\(\s*(?:(['"])([^'"]+)\1|(\w+))\s*[,)]/g, NODE_DATA)) {
161
+ collect_bound(targets, m[2], m[3], bindings);
162
+ }
163
+ for (const m of script_calls(stmt, /(?:\bfs(?:\.promises)?\.)?copyFileSync\(\s*[^,\n]+,\s*(?:(['"])([^'"]+)\1|(\w+))\s*[,)]/g, NODE_DATA)) {
164
+ collect_bound(targets, m[2], m[3], bindings);
165
+ }
166
+ for (const m of script_calls(stmt, /(?:\bfs(?:\.promises)?\.)?renameSync\(\s*(?:(['"])([^'"]+)\1|(\w+))\s*,\s*(?:(['"])([^'"]+)\4|(\w+))\s*\)/g, NODE_DATA)) {
167
+ collect_bound(targets, m[2], m[3], bindings);
168
+ collect_bound(targets, m[5], m[6], bindings);
169
+ }
170
+ }
171
+ }
172
+ return [...targets];
173
+ }
174
+
175
+ /** Extract embedded PowerShell here-strings and bash heredocs so their bodies never pollute shell command parsing. */
176
+ function extract_embedded_scripts(text, targets) {
177
+ let rest = text.replace(/@(['"])\r?\n([\s\S]*?)\r?\n\1@([ \t]*\|[ \t]*[^\r\n;]*)?/g, (full, _q, body, pipe = '') => {
178
+ if (/^\s*\|\s*(?:python(?:3)?|py)(?:\.exe)?\b(?![^\r\n]*\s-c\b)/i.test(pipe)) {
179
+ python_written_paths(body).forEach(path => targets.add(path));
180
+ return '';
181
+ }
182
+ if (/^\s*\|\s*node(?:\.exe)?\b(?![^\r\n]*\s(?:-e|--eval)\b)/i.test(pipe)) {
183
+ node_written_paths(body).forEach(path => targets.add(path));
184
+ return '';
185
+ }
186
+ return pipe ? `''${pipe}` : '\'\'';
187
+ });
188
+ rest = rest.replace(/^([^\r\n]*<<-?\s*(['"]?)([A-Za-z_]\w*)\2[^\r\n]*)\r?\n([\s\S]*?)\r?\n[ \t]*\3(?=\r?\n|$)/gm, (_full, header, _q, _tag, body) => {
189
+ if (/^\s*(?:[A-Za-z_]\w*=\S+\s+)*(?:python(?:3)?|py)(?:\.exe)?\b/i.test(header)) {
190
+ python_written_paths(body).forEach(path => targets.add(path));
191
+ return '';
192
+ }
193
+ if (/^\s*(?:[A-Za-z_]\w*=\S+\s+)*node(?:\.exe)?\b/i.test(header)) {
194
+ node_written_paths(body).forEach(path => targets.add(path));
195
+ return '';
196
+ }
197
+ return header.replace(/<<-?\s*(['"]?)[A-Za-z_]\w*\1/, '');
198
+ });
199
+ return rest;
200
+ }
201
+
202
+ /** Extract PowerShell `[IO.File]::Write*` targets bound to literal paths or simple `$var = 'path'` assignments. */
203
+ function powershell_io_writes(text, targets) {
204
+ const bindings = new Map();
205
+ for (const line of text.split(/\r?\n/)) {
206
+ const assign = line.match(/^\s*(\$\w+)\s*=\s*(.*)$/);
207
+ if (assign) {
208
+ const literal = assign[2].match(/^(?:Resolve-Path\s+)?(['"])([^'"]+)\1\s*;?\s*$/i)?.[2];
209
+ if (literal) bindings.set(assign[1], [literal]);
210
+ else bindings.delete(assign[1]);
211
+ }
212
+ for (const m of line.matchAll(/^\s*\[(?:System\.)?IO\.File\]::(?:WriteAllText|WriteAllBytes|WriteAllLines|AppendAllText|AppendAllLines)\(\s*(?:(['"])([^'"]+)\1|(\$\w+))\s*,/gi)) {
213
+ collect_bound(targets, m[2], m[3], bindings);
214
+ }
215
+ }
216
+ }
217
+
218
+ /** Split a shell script into top-level command segments on `&&`, `||`, `;`, `|` and newlines, respecting quotes. */
219
+ function split_shell_segments(text) {
220
+ const segments = [];
221
+ let current = '', quote = '', depth = 0;
222
+ for (let i = 0; i < text.length; i++) {
223
+ const ch = text[i], next = text[i + 1];
224
+ if (quote) {
225
+ current += ch;
226
+ if (ch === '\\' && quote === '"' && next !== undefined) { current += next; i++; }
227
+ else if (ch === quote) quote = '';
228
+ continue;
229
+ }
230
+ if (ch === '\'' || ch === '"') { quote = ch; current += ch; continue; }
231
+ if (ch === '(') { depth++; current += ch; continue; }
232
+ if (ch === ')' && depth > 0) { depth--; current += ch; continue; }
233
+ if (!depth && (ch === '\n' || ch === '\r' || ch === ';' || ch === '|')) {
234
+ if (current.trim()) segments.push(current.trim());
235
+ current = '';
236
+ if (ch === '|' && next === '|') i++;
237
+ continue;
238
+ }
239
+ if (!depth && ch === '&' && next === '&') {
240
+ if (current.trim()) segments.push(current.trim());
241
+ current = '';
242
+ i++;
243
+ continue;
244
+ }
245
+ current += ch;
246
+ }
247
+ if (current.trim()) segments.push(current.trim());
248
+ return segments;
249
+ }
250
+
251
+ /** Tokenize one shell segment while preserving quoted arguments and separating redirection operators. */
252
+ function tokenize_segment(segment) {
253
+ const tokens = [];
254
+ let current = '', quote = '';
255
+ const flush = () => { if (current) { tokens.push(current); current = ''; } };
256
+ for (let i = 0; i < segment.length; i++) {
257
+ const ch = segment[i], next = segment[i + 1];
258
+ if (quote) {
259
+ if (ch === '\\' && quote === '"' && next !== undefined) { current += next; i++; }
260
+ else if (ch === quote) quote = '';
261
+ else current += ch;
262
+ continue;
263
+ }
264
+ if (ch === '\'' || ch === '"') { quote = ch; continue; }
265
+ if (/\s/.test(ch)) { flush(); continue; }
266
+ const redir = segment.slice(i).match(/^(?:[12&]?>>?|<<<?|<<)/);
267
+ if (redir && (!current || /^[12&]$/.test(current))) {
268
+ const op = current ? current + redir[0] : redir[0];
269
+ current = '';
270
+ if (/^(?:[12&]?>>?|<<<?|<<)$/.test(op)) { tokens.push({ redir: op }); i += redir[0].length - 1; continue; }
271
+ }
272
+ current += ch;
273
+ }
274
+ flush();
275
+ return tokens;
276
+ }
277
+
278
+ /** Strip redirections from a tokenized segment, collecting only stdout/combined output targets (`>`, `>>`, `1>`, `&>`). */
279
+ function strip_redirections(tokens, targets) {
280
+ const argv = [];
281
+ for (let i = 0; i < tokens.length; i++) {
282
+ const token = tokens[i];
283
+ if (typeof token === 'object' && token.redir) {
284
+ const target = typeof tokens[i + 1] === 'string' ? tokens[++i] : '';
285
+ if (/^(?:1|&)?>>?$/.test(token.redir) && target && !target.startsWith('&')) collect_path(targets, target);
286
+ } else if (typeof token === 'string') {
287
+ argv.push(token);
288
+ }
289
+ }
290
+ return argv;
291
+ }
292
+
293
+ /** Extract write targets from one simple command's argv (already stripped of redirections). */
294
+ function command_written_paths(argv, targets) {
295
+ let index = 0;
296
+ while (index < argv.length && (/^[A-Za-z_]\w*=/.test(argv[index]) || argv[index] === '&')) index++;
297
+ if (index >= argv.length) return;
298
+ const cmd = argv[index].split(/[\\/]/).at(-1).replace(/\.exe$/i, '').toLowerCase();
299
+ const args = argv.slice(index + 1);
300
+ if (['python', 'python3', 'py'].includes(cmd)) {
301
+ const c = args.indexOf('-c');
302
+ if (c >= 0 && args[c + 1]) python_written_paths(args[c + 1]).forEach(path => targets.add(path));
303
+ return;
304
+ }
305
+ if (cmd === 'node') {
306
+ const e = args.findIndex(arg => arg === '-e' || arg === '--eval');
307
+ if (e >= 0 && args[e + 1]) node_written_paths(args[e + 1]).forEach(path => targets.add(path));
308
+ return;
309
+ }
310
+ if (cmd === 'cp' || cmd === 'copy') {
311
+ const positional = [];
312
+ for (let i = 0; i < args.length; i++) {
313
+ if (args[i] === '-t' || args[i] === '--target-directory') { i++; return; }
314
+ if (args[i].startsWith('--target-directory=')) return;
315
+ if (!args[i].startsWith('-')) positional.push(args[i]);
316
+ }
317
+ if (positional.length >= 2 && !/[\\/]$/.test(positional.at(-1))) collect_path(targets, positional.at(-1));
318
+ return;
319
+ }
320
+ if (cmd === 'copy-item' || cmd === 'cpi') {
321
+ const dest = args.findIndex(arg => arg.toLowerCase() === '-destination');
322
+ if (dest >= 0 && args[dest + 1]) return collect_path(targets, args[dest + 1]);
323
+ const positional = args.filter((arg, i) => !arg.startsWith('-') && !(i > 0 && args[i - 1].startsWith('-') && !PS_SWITCH_FLAGS.has(args[i - 1].toLowerCase())));
324
+ if (positional.length >= 2 && !/[\\/]$/.test(positional.at(-1))) collect_path(targets, positional.at(-1));
325
+ return;
326
+ }
327
+ if (cmd === 'mv' || cmd === 'move' || cmd === 'move-item' || cmd === 'mi') {
328
+ const positional = [];
329
+ for (let i = 0; i < args.length; i++) {
330
+ const lower = args[i].toLowerCase();
331
+ if (['-path', '-literalpath', '-destination'].includes(lower) && args[i + 1]) { positional.push(args[++i]); continue; }
332
+ if (args[i].startsWith('-')) { if (!PS_SWITCH_FLAGS.has(lower) && cmd.includes('-')) i++; continue; }
333
+ positional.push(args[i]);
334
+ }
335
+ if (positional.length >= 2) positional.forEach(item => { if (!/[\\/]$/.test(item)) collect_path(targets, item); });
336
+ return;
337
+ }
338
+ if (cmd === 'rename-item' || cmd === 'rni') {
339
+ const path_flag = args.findIndex(arg => PS_PATH_FLAGS.has(arg.toLowerCase()));
340
+ const positional = args.filter((arg, i) => !arg.startsWith('-') && !(i > 0 && args[i - 1].startsWith('-') && !PS_SWITCH_FLAGS.has(args[i - 1].toLowerCase())));
341
+ const source = path_flag >= 0 ? args[path_flag + 1] : positional[0];
342
+ if (source) collect_path(targets, source);
343
+ const name_flag = args.findIndex(arg => arg.toLowerCase() === '-newname');
344
+ const renamed = name_flag >= 0 ? args[name_flag + 1] : positional[1];
345
+ if (source && renamed && !/[\\/]/.test(renamed)) {
346
+ const prefix = source.includes('/') ? source.slice(0, source.lastIndexOf('/') + 1)
347
+ : source.includes('\\') ? source.slice(0, source.lastIndexOf('\\') + 1) : '';
348
+ collect_path(targets, `${prefix}${renamed}`);
349
+ }
350
+ return;
351
+ }
352
+ if (['rm', 'del', 'erase', 'remove-item', 'ri', 'touch', 'tee'].includes(cmd)) {
353
+ for (let i = 0; i < args.length; i++) {
354
+ const lower = args[i].toLowerCase();
355
+ if (PS_PATH_FLAGS.has(lower) && args[i + 1]) { collect_path(targets, args[++i]); continue; }
356
+ if (args[i].startsWith('-')) continue;
357
+ collect_path(targets, args[i]);
358
+ }
359
+ return;
360
+ }
361
+ if (cmd === 'new-item' || cmd === 'ni') {
362
+ const path_flag = args.findIndex(arg => PS_PATH_FLAGS.has(arg.toLowerCase()));
363
+ const name_flag = args.findIndex(arg => arg.toLowerCase() === '-name');
364
+ const positional = args.filter((arg, i) => !arg.startsWith('-') && !(i > 0 && args[i - 1].startsWith('-') && !PS_SWITCH_FLAGS.has(args[i - 1].toLowerCase())));
365
+ const base = path_flag >= 0 ? args[path_flag + 1] : positional[0];
366
+ const name = name_flag >= 0 ? args[name_flag + 1] : '';
367
+ if (base && name) collect_path(targets, `${base.replace(/[\\/]+$/, '')}/${name}`);
368
+ else if (base || name) collect_path(targets, base || name);
369
+ return;
370
+ }
371
+ if (['set-content', 'add-content', 'out-file', 'sc', 'ac'].includes(cmd)) {
372
+ const path_flag = args.findIndex(arg => PS_PATH_FLAGS.has(arg.toLowerCase()));
373
+ if (path_flag >= 0 && args[path_flag + 1]) return collect_path(targets, args[path_flag + 1]);
374
+ for (let i = 0; i < args.length; i++) {
375
+ const lower = args[i].toLowerCase();
376
+ if (lower.startsWith('-')) { if (!PS_SWITCH_FLAGS.has(lower)) i++; continue; }
377
+ return collect_path(targets, args[i]);
378
+ }
379
+ return;
380
+ }
381
+ if (cmd === 'sed') {
382
+ let in_place = false, has_script_flag = false;
383
+ const positional = [];
384
+ for (let i = 0; i < args.length; i++) {
385
+ const arg = args[i];
386
+ if (arg === '-i' || arg.startsWith('-i') || arg === '--in-place' || arg.startsWith('--in-place=')) {
387
+ in_place = true;
388
+ if (arg === '-i' && args[i + 1] === '') i++;
389
+ continue;
390
+ }
391
+ if (arg === '-e' || arg === '-f' || arg === '--expression' || arg === '--file') { has_script_flag = true; i++; continue; }
392
+ if (arg.startsWith('-')) continue;
393
+ positional.push(arg);
394
+ }
395
+ if (!in_place) return;
396
+ (has_script_flag ? positional : positional.slice(1)).forEach(item => collect_path(targets, item));
397
+ return;
398
+ }
399
+ if (cmd === 'git') {
400
+ let i = 0;
401
+ while (i < args.length && args[i].startsWith('-')) i += ['-c', '-C', '--git-dir', '--work-tree'].includes(args[i]) ? 2 : 1;
402
+ const sub = args[i]?.toLowerCase(), rest = args.slice(i + 1);
403
+ if (sub === 'restore' || sub === 'rm') {
404
+ for (let j = 0; j < rest.length; j++) {
405
+ if (rest[j] === '--') { rest.slice(j + 1).forEach(item => collect_path(targets, item)); return; }
406
+ if (rest[j] === '-s' || rest[j] === '--source') { j++; continue; }
407
+ if (!rest[j].startsWith('-')) collect_path(targets, rest[j]);
408
+ }
409
+ } else if (sub === 'checkout') {
410
+ const dash = rest.indexOf('--');
411
+ if (dash >= 0) rest.slice(dash + 1).forEach(item => collect_path(targets, item));
412
+ } else if (sub === 'mv') {
413
+ rest.filter(item => !item.startsWith('-')).forEach(item => collect_path(targets, item));
414
+ }
415
+ }
416
+ }
417
+
418
+ /**
419
+ * The literal target file paths a shell command writes to, parsed per segment and by write-target position so copy
420
+ * sources, redirected inputs and read-only commands in compound lines are never blamed; unknown targets stay empty.
421
+ */
27
422
  export function shell_written_paths(command) {
28
- const text = String(command || '');
29
- if (!SHELL_WRITES.test(text)) return [];
30
- return text.split(/[\s'"`;|&<>(),=]+/).filter(token => /[\\/]/.test(token) && /\.[\w-]+$/.test(token));
423
+ const text = unwrap_shell_command(command);
424
+ if (!text) return [];
425
+ const targets = new Set();
426
+ const remaining = extract_embedded_scripts(text, targets);
427
+ powershell_io_writes(remaining, targets);
428
+ for (const segment of split_shell_segments(remaining)) {
429
+ const argv = strip_redirections(tokenize_segment(segment), targets);
430
+ command_written_paths(argv, targets);
431
+ }
432
+ return [...targets];
31
433
  }
32
434
  export const EDIT_TOOLS = /^(Edit|MultiEdit|Write|NotebookEdit|write_file|edit_file|write_to_file|replace_file_content|multi_replace_file_content)$/;
33
435
  /** A refused operation's detail and rule are cut to this length; a run reports at most this many. */
@@ -138,8 +540,9 @@ export function tree_killable(child) {
138
540
  * lines are left to the caller's own parsing.
139
541
  */
140
542
  export function watch_events(adapter, stream, task) {
141
- if (!task.on_activity && !task.on_note) return;
543
+ if (!task.on_activity && !task.on_note && !task.on_edits) return;
142
544
  track_edits(adapter, task);
545
+ const pending_edits = new Map();
143
546
  createInterface({ input: stream, crlfDelay: Infinity }).on('line', line => {
144
547
  let event;
145
548
  try { event = JSON.parse(line); } catch { return; }
@@ -147,7 +550,7 @@ export function watch_events(adapter, stream, task) {
147
550
  if (phase) task.on_activity?.(phase, adapter.events.tool(event), adapter.events.call?.(event));
148
551
  const note = adapter.events.note(event);
149
552
  if (note) task.on_note?.(note);
150
- report_edits(adapter, event, task);
553
+ report_edits(adapter, event, task, pending_edits);
151
554
  });
152
555
  }
153
556
 
@@ -160,8 +563,8 @@ export function track_edits(adapter, task) {
160
563
  }
161
564
 
162
565
  /** Pass on the files one event says the agent edited with its own edit tools. */
163
- export function report_edits(adapter, event, task) {
164
- const paths = adapter.events.edits?.(event) || [];
566
+ export function report_edits(adapter, event, task, pending) {
567
+ const paths = adapter.events.edits?.(event, pending) || [];
165
568
  if (paths.length) task.on_edits?.(paths);
166
569
  }
167
570
 
@@ -52,6 +52,12 @@ const SESSION_PATTERN = /^[0-9A-Za-z_-]{8,128}$/;
52
52
  /** The descriptor of a configured adapter, or null for a value this version does not support. */
53
53
  export function adapter_of(id) { return ADAPTERS[id] || null; }
54
54
 
55
+ /** Return stop support for a prospective delivery using its configured profile and session binding. */
56
+ export function preflight_stoppable(profile, binding = {}) {
57
+ return adapter_of(profile.adapter)?.preflight_stoppable?.(profile, binding)
58
+ ?? adapter_capabilities(profile.adapter).delivery.stoppable;
59
+ }
60
+
55
61
  /** Read one recorded delivery's outcome without starting software; missing or unreadable evidence is unknown. */
56
62
  export async function recover_turn(adapter_id, record) {
57
63
  try {
@@ -87,7 +87,11 @@ API 密钥、技能、工作流、系统提示词(目标同上)
87
87
  prompt default get / prompt default set --file <文件> 新托管账号的默认系统提示词
88
88
 
89
89
  结果以 JSON 输出。--data 指定管理员服务目录(默认 ~/.codiscuss)。
90
- `);
90
+ `) + t(' storage [clean] 查看存储用量,或清理已确认结束的执行临时目录') + '\n'
91
+ + t(' account add <名> --project-data-root <目录> 将新账号的项目、工作区和成员草稿放在指定目录') + '\n'
92
+ + t(' account migrate-data <名> --project-data-root <目录> 停止实例并迁移项目数据') + '\n'
93
+ + t(' account migration-backups <名> 查看各迁移备份的位置与字节数') + '\n'
94
+ + t(' account release-backup <名> <迁移编号> <目录类别> --confirm 停止实例并释放指定备份') + '\n';
91
95
 
92
96
  /** A client of the running panel: enters with the owner key and keeps the session for the requests that follow. */
93
97
  export async function panel_client(data) {
@@ -119,12 +123,15 @@ const is_owner = target => target === OWNER;
119
123
  * Create an account the way the panel's wizard does, step by step. Run again for an account that exists, it goes on
120
124
  * from the first step missing; the password is reported once created, even if a later step fails.
121
125
  */
122
- async function add_account(call, name, { isolate, start }) {
126
+ async function add_account(call, name, { isolate, start, project_data_root }) {
123
127
  const steps = [];
124
128
  const existing = (await call('state')).accounts?.find(item => item.name === name);
129
+ if (existing && project_data_root && (!existing.project_data_root || relative(existing.project_data_root, project_data_root))) {
130
+ throw new Error(t('已有账号使用不同的数据目录,请用 account migrate-data 显式迁移。'));
131
+ }
125
132
  let password = '';
126
133
  if (existing) steps.push(t('账号已存在,从缺少的步骤接着做(密码不变;需要新密码用 account password)'));
127
- else { password = (await call('accounts', { name })).password; steps.push(t('已创建账号与文件夹')); }
134
+ else { password = (await call('accounts', { name, ...(project_data_root ? { project_data_root } : {}) })).password; steps.push(t('已创建账号与文件夹')); }
128
135
  const report = extra => ({ name, ...(password ? { password } : {}), steps, ...extra });
129
136
  try {
130
137
  if (isolate && !existing?.os_user) {
@@ -149,10 +156,13 @@ async function add_account(call, name, { isolate, start }) {
149
156
  const ACCOUNT_ACTIONS = { start: 'start', stop: 'stop', disable: 'disable', enable: 'enable', remove: 'remove', password: 'password',
150
157
  isolate: 'os-user', unisolate: 'os-user/remove' };
151
158
 
152
- async function account_command(call, [action, name], values) {
159
+ async function account_command(call, [action, name, id, kind], values) {
153
160
  if (action === 'list') return (await call('state')).accounts;
154
161
  need(name, t('account {value1} <名>', { value1: action }));
155
- if (action === 'add') return add_account(call, name, { isolate: !values['no-isolate'], start: !values['no-start'] });
162
+ if (action === 'add') return add_account(call, name, { isolate: !values['no-isolate'], start: !values['no-start'], project_data_root: values['project-data-root'] });
163
+ if (action === 'migrate-data') return call(`accounts/${name}/migrate-data`, { project_data_root: need(values['project-data-root'], '--project-data-root') });
164
+ if (action === 'migration-backups') return call(`accounts/${name}/migration-backups`);
165
+ if (action === 'release-backup') return call(`accounts/${name}/release-backup`, { id, kind, confirm: values.confirm === true });
156
166
  if (action === 'protect' || action === 'unprotect') return call(`accounts/${name}/protect`, { on: action === 'protect' });
157
167
  if (!ACCOUNT_ACTIONS[action]) throw new Error(HELP);
158
168
  return call(`accounts/${name}/${ACCOUNT_ACTIONS[action]}`, {});
@@ -397,6 +407,8 @@ async function with_elevation(call, data) {
397
407
  export async function admin_cli(args, { client = panel_client, print = text => process.stdout.write(text) } = {}) {
398
408
  const { positionals, values } = parseArgs({ args, allowPositionals: true, options: {
399
409
  data: { type: 'string' }, help: { type: 'boolean', short: 'h' }, 'no-isolate': { type: 'boolean' }, 'no-start': { type: 'boolean' },
410
+ 'project-data-root': { type: 'string' },
411
+ confirm: { type: 'boolean' },
400
412
  set: { type: 'string', multiple: true }, 'base-url': { type: 'string' }, key: { type: 'string' }, file: { type: 'string' }, group: { type: 'string' },
401
413
  full: { type: 'boolean' }, config: { type: 'string' }, site: { type: 'string' },
402
414
  } });
@@ -417,6 +429,11 @@ export async function admin_cli(args, { client = panel_client, print = text => p
417
429
  }
418
430
  const call = await with_elevation(await client(data), data);
419
431
  const commands = {
432
+ storage: () => {
433
+ if (!rest.length) return call('storage');
434
+ if (rest.length === 1 && rest[0] === 'clean') return call('storage/clean', {});
435
+ throw new Error(HELP);
436
+ },
420
437
  status: async () => {
421
438
  const { login_methods: _methods, providers: _providers, ...state } = await call('state');
422
439
  if (state.online_site) {