ai_co_discuss 0.5.19 → 0.5.21
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-participant/SKILL.md +2 -1
- package/.agents/skills/share-card/SKILL.md +15 -0
- package/.agents/skills/share-card/references/share-card.md +43 -0
- package/.agents/skills/workflow-creator/SKILL.md +3 -0
- package/backend/execution_diagnostics.py +149 -0
- package/backend/free_room.py +133 -40
- package/backend/message_queue.py +6 -4
- package/backend/room_trace.py +219 -0
- package/backend/schema.sql +7 -1
- package/backend/server.py +113 -8
- package/docs/en/guide/cli.md +20 -0
- package/docs/en/guide/faq.md +1 -0
- package/docs/en/guide/members.md +3 -1
- package/docs/en/guide/rooms.md +7 -3
- package/docs/en/guide/workflows.md +2 -0
- package/docs/en/guide/working.md +9 -4
- package/docs/guide/cli.md +20 -0
- package/docs/guide/faq.md +1 -0
- package/docs/guide/members.md +3 -1
- package/docs/guide/rooms.md +7 -3
- package/docs/guide/workflows.md +2 -0
- package/docs/guide/working.md +9 -4
- package/frontend/locales/en/app.json +8 -0
- package/frontend/locales/en/backend.json +5 -0
- package/frontend/locales/en/discussion.json +10 -3
- package/frontend/locales/en/execution-diagnostics.json +32 -0
- package/frontend/locales/en/room.json +1 -0
- package/frontend/locales/en/settings.json +5 -0
- package/package.json +3 -2
- package/runner/adapters/antigravity_cli.mjs +15 -1
- package/runner/adapters/api.mjs +27 -3
- package/runner/adapters/api_images.mjs +1 -1
- package/runner/adapters/api_pi.mjs +30 -1
- package/runner/adapters/cli.mjs +15 -6
- package/runner/adapters/codex_bridge.mjs +20 -6
- package/runner/adapters/codex_cli.mjs +2 -1
- package/runner/codiscuss.mjs +7 -0
- package/runner/discuss.py +24 -2
- package/runner/discussion_launch.mjs +1 -1
- package/runner/discussion_setup.mjs +1 -1
- package/runner/discussion_skills.mjs +1 -1
- package/runner/expert_prompts.mjs +4 -3
- package/runner/free_runner.mjs +102 -24
- package/runner/i18n_en.mjs +45 -2
- package/runner/remote_launch.mjs +2 -2
- package/runner/share_card.mjs +1314 -0
- package/runner/share_service.mjs +25 -7
- package/runner/share_shared.mjs +28 -7
- package/runner/site_deploy.mjs +125 -4
- package/runner/timeline_metrics.mjs +185 -0
- package/runner/workflows.mjs +38 -9
- package/web/app.js +303 -81
- package/web/i18n.js +3 -3
- package/web/modern.css +1 -1
- package/web/modern.js +98 -67
- package/workflows/decision-council/SKILL.md +2 -1
- package/workflows/decision-council/flow.json +15 -15
- package/workflows/story-serial/agents/writer.md +1 -1
- package/workflows/story-serial/flow.json +456 -123
- package/workflows/story-serial/workflows/aigc-reduce/flow.json +134 -13
- package/workflows/story-serial/workflows/character-play/flow.json +212 -25
- package/workflows/story-serial/workflows/jack-sparrow/flow.json +67 -23
- package/workflows/story-serial/workflows/luke-nichols/flow.json +67 -23
- package/workflows/story-serial/workflows/revise-episodes/flow.json +184 -23
- package/workflows/story-serial/workflows/tidy-docs/flow.json +256 -19
- package/workflows/tri-model-dev/SKILL.md +72 -0
- package/workflows/tri-model-dev/agents/advisor.md +22 -0
- package/workflows/tri-model-dev/agents/backend.md +25 -0
- package/workflows/tri-model-dev/agents/reviewer.md +38 -0
- package/workflows/tri-model-dev/flow.json +397 -0
- package/workflows/tri-model-dev/workflows/browser-verify/SKILL.md +22 -0
- package/workflows/tri-model-dev/workflows/browser-verify/agents/browser_ops.md +18 -0
- package/workflows/tri-model-dev/workflows/browser-verify/flow.json +136 -0
- package/workflows/trpg-classic/flow.json +17 -17
package/runner/share_service.mjs
CHANGED
|
@@ -101,7 +101,8 @@ async function prepare(config, room, signal) {
|
|
|
101
101
|
const members = (info.members || []).filter(m => m.status !== 'removed').map(m => m.label || m.name);
|
|
102
102
|
const linked = Boolean((await (await local_read(config, '/api/rooms/' + room + '/share-link', signal)).json()).link);
|
|
103
103
|
return { summary: { title: info.title, description: t('{members} 在同一个房间协作 · {messages} 条消息 · {runs} 次执行', { members: members.join('、'), messages: info.message_count, runs }),
|
|
104
|
-
fingerprint: await share_fingerprint(clean, with_files), exported_at: now(), files, spots: core.share_sensitive_spots(clean), file_spots, linked, runs
|
|
104
|
+
fingerprint: await share_fingerprint(clean, with_files), exported_at: now(), files, spots: core.share_sensitive_spots(clean), file_spots, linked, runs,
|
|
105
|
+
materials: core.share_card_materials_info(clean) },
|
|
105
106
|
payload: { responses: clean, responses_with_files: with_files } };
|
|
106
107
|
}
|
|
107
108
|
|
|
@@ -171,9 +172,26 @@ async function publish(config, job, plan, signal, transport, update) {
|
|
|
171
172
|
const link = { share_id: result.id || prior?.share_id, manage_token: result.manage_token || prior?.manage_token, url: result.url || prior?.url, expires_at: result.expires_at };
|
|
172
173
|
if (!ID.test(link.share_id) || !/^[\w-]{43}$/.test(link.manage_token) || (plan.files.length && !ID.test(result.revision))
|
|
173
174
|
|| link.url !== SHARE_SITE + '/s/' + link.share_id) throw new Error(t('分享站返回了无效的链接'));
|
|
174
|
-
|
|
175
|
+
const card = core.share_card(plan.draft, link);
|
|
176
|
+
card.publication = { revision: result.revision, total: plan.files.length, ...(plan.files.length ? {} : { done: 0 }) };
|
|
177
|
+
await local_read(config, route, signal, { link: { ...link, card } }).then(r => r.json());
|
|
178
|
+
if (plan.files.length) {
|
|
179
|
+
update(0, 0, result.revision);
|
|
180
|
+
try { await publish_attachments(plan.files, { link, card, config, signal, transport, update }); }
|
|
181
|
+
finally {
|
|
182
|
+
const { revision, done } = card.publication;
|
|
183
|
+
await local_read(config, '/api/rooms/' + job.room_id + '/share-card', signal,
|
|
184
|
+
{ share_id: link.share_id, publication: { revision, done } }).catch(() => {});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return { url: link.url, expires_at: link.expires_at, updated, card };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async function publish_attachments(files, { link, card, config, signal, transport, update }) {
|
|
175
191
|
const group = new AbortController(), active = AbortSignal.any([signal, group.signal]);
|
|
176
|
-
|
|
192
|
+
const { revision } = card.publication;
|
|
193
|
+
card.publication.done = 0;
|
|
194
|
+
await core.share_parallel(files, SHARE_UPLOAD_CONCURRENCY, async file => {
|
|
177
195
|
for (let attempt = 1; ; attempt++) {
|
|
178
196
|
let sent = 0;
|
|
179
197
|
try {
|
|
@@ -189,8 +207,9 @@ async function publish(config, job, plan, signal, transport, update) {
|
|
|
189
207
|
}
|
|
190
208
|
if (size !== file.size) throw Object.assign(new Error(t('附件大小已变化,请重新整理分享')), { permanent: true });
|
|
191
209
|
}
|
|
192
|
-
await transport.file(SHARE_SITE + '/api/shares/' + link.share_id + '/files/' + file.id + '?revision=' +
|
|
210
|
+
await transport.file(SHARE_SITE + '/api/shares/' + link.share_id + '/files/' + file.id + '?revision=' + revision,
|
|
193
211
|
{ Authorization: 'Bearer ' + link.manage_token, 'Content-Type': file.site_type, 'Content-Length': file.size }, measured(), active);
|
|
212
|
+
card.publication.done++;
|
|
194
213
|
update(1, 0);
|
|
195
214
|
break;
|
|
196
215
|
} catch (error) {
|
|
@@ -200,8 +219,6 @@ async function publish(config, job, plan, signal, transport, update) {
|
|
|
200
219
|
}
|
|
201
220
|
}
|
|
202
221
|
});
|
|
203
|
-
const card = core.share_card(plan.draft, link);
|
|
204
|
-
return { url: link.url, expires_at: link.expires_at, updated, card: { ...card, question: card.question.slice(0, 600), outcome: card.outcome.slice(0, 600) } };
|
|
205
222
|
}
|
|
206
223
|
|
|
207
224
|
|
|
@@ -273,9 +290,10 @@ class ShareManager {
|
|
|
273
290
|
job.progress = { ...progress(job.phase), total: plan?.files.length || 0, bytes_total: plan?.bytes || 0 };
|
|
274
291
|
this.save(job);
|
|
275
292
|
let last_save = Date.now();
|
|
276
|
-
const update = (count, bytes) => {
|
|
293
|
+
const update = (count, bytes, revision) => {
|
|
277
294
|
signal.throwIfAborted();
|
|
278
295
|
job.progress.step = 'uploading'; job.progress.done += count; job.progress.bytes_done += bytes;
|
|
296
|
+
if (revision) job.progress.revision = revision;
|
|
279
297
|
if (Date.now() - last_save > PROGRESS_SAVE_MS) { this.save(job); last_save = Date.now(); }
|
|
280
298
|
};
|
|
281
299
|
(async () => {
|
package/runner/share_shared.mjs
CHANGED
|
@@ -64,6 +64,13 @@ export const SHARE_HOME_FOLDERS = [/(?<![\w./-])[A-Za-z]:[\\/]+Users[\\/]+[^\\/\
|
|
|
64
64
|
const ABSOLUTE_PATH = /^(?:[A-Za-z]:[\\/]|\/)/;
|
|
65
65
|
// A folder named by fewer parts ("C:", "/home") is too broad to rewrite in text.
|
|
66
66
|
export const SHARE_FOLDER_MIN_PARTS = 2;
|
|
67
|
+
/** Identify the receipt headings produced by answering, recommending or delegating a room question. */
|
|
68
|
+
export function is_share_question_receipt(text) {
|
|
69
|
+
const heading = String(text || "").trimStart().split("\n", 1)[0].trimEnd();
|
|
70
|
+
return /^(?:回答问题\s*#?\d+|Answer to question #\d+)(?:[::]|$)/iu.test(heading)
|
|
71
|
+
|| /^(?:请主持人先讨论并给推荐|交给主持人决定)(问题 #\d+)$/u.test(heading)
|
|
72
|
+
|| /^(?:Host, please discuss and recommend first|Leaving it to the host to decide) \(question #\d+\)$/iu.test(heading);
|
|
73
|
+
}
|
|
67
74
|
// Attachments whose text is scanned for keys and folders before sharing: plain text up to this size, not packed office files.
|
|
68
75
|
export const TEXT_ATTACHMENT = /\.(md|markdown|txt|log|csv|tsv|json|jsonc|ya?ml|toml|ini|xml|html?|css|vue|[cm]?js|jsx|tsx?|py|sql|sh|ps1|bat|srt|vtt|ass|ssa|lrc|fcpxml|kdenlive|mlt|otio|edl|docx|xlsx|xls|ods|pptx|prproj|zip)$/i;
|
|
69
76
|
export const SHARE_SCAN_BYTES = 2 * 1024 * 1024;
|
|
@@ -350,20 +357,34 @@ export function create_share_core({ t, display_name, collapse_visual_fences, is_
|
|
|
350
357
|
return String(text || "").replace(/```[\s\S]*?```/g, " ").replace(/!?\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/[`*_>#|~-]+/g, " ").replace(/\s+/g, " ").trim();
|
|
351
358
|
}
|
|
352
359
|
|
|
360
|
+
function share_card_messages(responses) {
|
|
361
|
+
return Object.entries(responses).filter(([path]) => /\/messages\?/.test(path)).flatMap(([, body]) => body.messages || [])
|
|
362
|
+
.filter(message => message.kind !== "system" && message.text).sort((a, b) => a.id - b.id);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function share_card_materials_info(responses) {
|
|
366
|
+
const messages = share_card_messages(responses);
|
|
367
|
+
return { through: messages.at(-1)?.id ?? null, count: messages.length };
|
|
368
|
+
}
|
|
369
|
+
|
|
353
370
|
/** What the share card shows of a prepared page: members, the first question, the latest outcome and the counts. */
|
|
354
371
|
function share_card(draft, link) {
|
|
355
372
|
const room = draft.responses[`/api/rooms/${draft.room_id}`] || {};
|
|
356
373
|
const members = (room.members || []).filter(member => member.status !== "removed").map(member => member.label || display_name(member.name));
|
|
357
|
-
const messages =
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
const
|
|
361
|
-
const answers = messages.filter(message => message.author !== "用户" && message.id > (question?.id ?? 0));
|
|
374
|
+
const messages = share_card_messages(draft.responses);
|
|
375
|
+
const question = messages.find(message => message.author === "用户" && !is_share_question_receipt(message.text)
|
|
376
|
+
&& !/^\/?(?:继续|好的?|同意|continue|ok)[。.!!\s]*$/iu.test(message.text.trim()));
|
|
377
|
+
const answers = messages.filter(message => message.author !== "用户" && message.author !== "系统" && message.id > (question?.id ?? 0));
|
|
362
378
|
const outcome = answers.findLast(message => message.summary) || answers.at(-1);
|
|
363
379
|
// Text the owner was asked to check stays off the card, which cannot be taken back once posted; it can be typed in.
|
|
364
380
|
const flagged = new Set((draft.spots || []).map(spot => spot.where));
|
|
365
381
|
const text = (message, value) => message && !flagged.has(`#${message.id}`) ? share_plain(value) : "";
|
|
366
|
-
|
|
382
|
+
const result = text(outcome, outcome?.summary || outcome?.text);
|
|
383
|
+
const sentences = result.match(/[^。!?.!?]+(?:[。!?]|[.!?](?=\s|$)|$)/gu) || [];
|
|
384
|
+
const complete = sentences[0]?.trim();
|
|
385
|
+
return { title: draft.title, members, materials: { through: messages.at(-1)?.id ?? null, count: messages.length },
|
|
386
|
+
question: text(question, question?.text).slice(0, 600),
|
|
387
|
+
outcome: (complete && result.startsWith(complete) ? complete : result).slice(0, 600),
|
|
367
388
|
stats: t('{members} 位 AI · {messages} 条消息 · {runs} 次执行', { members: members.length, messages: room.message_count ?? messages.length, runs: draft.runs ?? 0 }),
|
|
368
389
|
url: link.url, expires: t('{time} 前有效', { time: new Date(link.expires_at).toLocaleString(undefined, { hour12: false }) }) };
|
|
369
390
|
}
|
|
@@ -443,5 +464,5 @@ export function create_share_core({ t, display_name, collapse_visual_fences, is_
|
|
|
443
464
|
const extra = scanned.filter(item => item.texts), unread = scanned.filter(item => !item.texts);
|
|
444
465
|
return [...share_sensitive_spots({}, extra), ...unread];
|
|
445
466
|
}
|
|
446
|
-
return { share_path, share_clean, share_parallel, share_batch, share_strings, share_sensitive_spots, share_files, share_file_route, share_site_file, share_carried_files, share_file_kind, share_file_kinds, share_responses, share_named_paths, share_folder_pattern, share_payload, share_plain, share_card, share_collect_reads, share_find_delivered, share_scan_files };
|
|
467
|
+
return { share_path, share_clean, share_parallel, share_batch, share_strings, share_sensitive_spots, share_files, share_file_route, share_site_file, share_carried_files, share_file_kind, share_file_kinds, share_responses, share_named_paths, share_folder_pattern, share_payload, share_plain, share_card, share_card_materials_info, share_collect_reads, share_find_delivered, share_scan_files };
|
|
447
468
|
}
|
package/runner/site_deploy.mjs
CHANGED
|
@@ -24,6 +24,8 @@ const DEVICES_FILE = 'site-devices.json';
|
|
|
24
24
|
const STAGES_FILE = 'site-stages.json';
|
|
25
25
|
const MAX_LOCAL_STAGES = 200;
|
|
26
26
|
const SITE_ID_PATTERN = /^[a-z2-7]{10}$/;
|
|
27
|
+
const SHA256_PATTERN = /^[a-f0-9]{64}$/;
|
|
28
|
+
const DIAGNOSTIC_TIMEOUT_MS = 10_000;
|
|
27
29
|
const SKIP_DIRECTORIES = new Set(['.git', '.svn', '.hg', 'node_modules', '__pycache__', '.wrangler']);
|
|
28
30
|
const SKIP_FILES = new Set(['.ds_store', 'thumbs.db', 'desktop.ini']);
|
|
29
31
|
|
|
@@ -434,7 +436,7 @@ function load_local_stage(home, stage_id) {
|
|
|
434
436
|
return store[stage_id] || null;
|
|
435
437
|
}
|
|
436
438
|
|
|
437
|
-
async function room_api_request(site, path, { method = 'GET', token = '', body = undefined, fetcher = fetch } = {}) {
|
|
439
|
+
async function room_api_request(site, path, { method = 'GET', token = '', body = undefined, fetcher = fetch, signal } = {}) {
|
|
438
440
|
if (!site) return null;
|
|
439
441
|
const headers = { 'Accept-Language': 'zh-CN' };
|
|
440
442
|
if (token) headers['X-Discussion-Token'] = token;
|
|
@@ -444,6 +446,7 @@ async function room_api_request(site, path, { method = 'GET', token = '', body =
|
|
|
444
446
|
const res = await deployment_fetch(send, `${site.replace(/\/+$/, '')}${path}`, {
|
|
445
447
|
method,
|
|
446
448
|
headers,
|
|
449
|
+
signal,
|
|
447
450
|
...(body !== undefined ? { body: JSON.stringify(body) } : {}),
|
|
448
451
|
});
|
|
449
452
|
const parsed = await res.json().catch(() => ({}));
|
|
@@ -453,7 +456,7 @@ async function room_api_request(site, path, { method = 'GET', token = '', body =
|
|
|
453
456
|
return parsed;
|
|
454
457
|
}
|
|
455
458
|
|
|
456
|
-
async function worker_api(origin, path, { method = 'GET', token = '', body = undefined, raw_body = undefined, content_type = '', fetcher = fetch } = {}) {
|
|
459
|
+
async function worker_api(origin, path, { method = 'GET', token = '', body = undefined, raw_body = undefined, content_type = '', fetcher = fetch, signal } = {}) {
|
|
457
460
|
const headers = { 'Accept-Language': 'zh-CN' };
|
|
458
461
|
if (token) headers.Authorization = `Bearer ${token}`;
|
|
459
462
|
if (raw_body !== undefined) {
|
|
@@ -464,6 +467,7 @@ async function worker_api(origin, path, { method = 'GET', token = '', body = und
|
|
|
464
467
|
const res = await deployment_fetch(fetcher, `${origin}${path}`, {
|
|
465
468
|
method,
|
|
466
469
|
headers,
|
|
470
|
+
signal,
|
|
467
471
|
...(raw_body !== undefined ? { body: raw_body } : body !== undefined ? { body: JSON.stringify(body) } : {}),
|
|
468
472
|
});
|
|
469
473
|
const parsed = await res.json().catch(() => ({}));
|
|
@@ -524,7 +528,114 @@ async function write_stage_record(home, { room_id, site, write_token }, { real_t
|
|
|
524
528
|
};
|
|
525
529
|
}
|
|
526
530
|
|
|
527
|
-
/**
|
|
531
|
+
/** Query the owned-site endpoint, with version-only evidence from older Workers. */
|
|
532
|
+
async function remote_diagnostics(origin, site_id, token, fetcher) {
|
|
533
|
+
const options = () => ({ token, fetcher, signal: AbortSignal.timeout(DIAGNOSTIC_TIMEOUT_MS) });
|
|
534
|
+
try {
|
|
535
|
+
const remote = await worker_api(origin, `/api/sites/${site_id}/diagnostics`, options());
|
|
536
|
+
return { ...remote, details_available: true };
|
|
537
|
+
} catch (error) {
|
|
538
|
+
if (error.http_status !== 404) throw error;
|
|
539
|
+
const { sites } = await worker_api(origin, '/api/sites', options());
|
|
540
|
+
const site = sites?.find(item => item.id === site_id);
|
|
541
|
+
if (!site) throw error;
|
|
542
|
+
return { status: site.status, url: site.url, source_room: site.source?.room,
|
|
543
|
+
active_version: site.status === 'active' ? site.current_version || null : null,
|
|
544
|
+
manifest: null, samples: null, details_available: false };
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/** Read the room's own version and linked stage without the synchronization performed by site-list. */
|
|
549
|
+
async function read_registration(conn, site_id, fetcher) {
|
|
550
|
+
if (!conn.site) return { state: 'unavailable' };
|
|
551
|
+
const path = conn.room_id ? `/api/rooms/${encodeURIComponent(conn.room_id)}/sites` : '/api/sites';
|
|
552
|
+
try {
|
|
553
|
+
const data = await room_api_request(conn.site, path, { fetcher, signal: AbortSignal.timeout(DIAGNOSTIC_TIMEOUT_MS) });
|
|
554
|
+
const record = data?.sites?.find(item => item.site_id === site_id);
|
|
555
|
+
const linked = data?.stages?.find(item => item.site_id === site_id);
|
|
556
|
+
const stage = linked ? { stage_id: linked.stage_id, ready: linked.ready, file_count: linked.file_count, bytes: linked.bytes } : null;
|
|
557
|
+
return { state: record ? 'observed' : 'missing', room_id: record?.room_id || conn.room_id || null,
|
|
558
|
+
version: record?.current_version ?? null, status: record?.status ?? null, stage };
|
|
559
|
+
} catch {
|
|
560
|
+
return { state: 'unavailable' };
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/** Only use the public hostname corresponding to this ID and hosting service. */
|
|
565
|
+
function public_site_origin(origin, site_id, url) {
|
|
566
|
+
try {
|
|
567
|
+
const public_url = new URL(url);
|
|
568
|
+
if (public_url.protocol === 'https:' && !public_url.port && !public_url.username && !public_url.password
|
|
569
|
+
&& public_url.hostname === `${site_id}.${new URL(origin).hostname}`) return public_url.origin;
|
|
570
|
+
} catch { /* the address could not be verified */ }
|
|
571
|
+
return '';
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/** Hash the anonymous response in a bounded stream and discard the body. */
|
|
575
|
+
async function check_public_file(origin, path, digest, fetcher) {
|
|
576
|
+
const checked = { path, expected_sha256: SHA256_PATTERN.test(digest || '') ? digest : null,
|
|
577
|
+
actual_sha256: null, http_status: null, status: 'unavailable' };
|
|
578
|
+
if (!origin) return checked;
|
|
579
|
+
try {
|
|
580
|
+
const response = await fetcher(origin + path, { method: 'GET', redirect: 'manual', cache: 'no-store',
|
|
581
|
+
signal: AbortSignal.timeout(DIAGNOSTIC_TIMEOUT_MS) });
|
|
582
|
+
checked.http_status = response.status;
|
|
583
|
+
if (response.status !== 200) {
|
|
584
|
+
await response.body?.cancel();
|
|
585
|
+
return { ...checked, status: 'http_error' };
|
|
586
|
+
}
|
|
587
|
+
const hash = createHash('sha256');
|
|
588
|
+
let bytes = 0;
|
|
589
|
+
for await (const chunk of response.body || []) {
|
|
590
|
+
bytes += chunk.byteLength;
|
|
591
|
+
if (bytes > LOCAL_SITE_LIMITS.max_site_bytes) return { ...checked, status: 'too_large' };
|
|
592
|
+
hash.update(chunk);
|
|
593
|
+
}
|
|
594
|
+
checked.actual_sha256 = hash.digest('hex');
|
|
595
|
+
checked.status = !checked.expected_sha256 ? 'unverified'
|
|
596
|
+
: checked.expected_sha256 === checked.actual_sha256 ? 'match' : 'mismatch';
|
|
597
|
+
} catch { /* no result if the request or response stream failed */ }
|
|
598
|
+
return checked;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/** Determine the furthest confirmed step for the pending manifest or the active version. */
|
|
602
|
+
function confirmed_stage(remote, registration_matches, probes) {
|
|
603
|
+
const manifest = remote.manifest;
|
|
604
|
+
if (manifest?.status === 'uploading' && manifest.version > (remote.active_version || 0)) {
|
|
605
|
+
if (manifest.uploaded === manifest.file_count) return 'upload_complete';
|
|
606
|
+
return manifest.uploaded ? 'upload_partial' : 'manifest_registered';
|
|
607
|
+
}
|
|
608
|
+
if (!remote.active_version) return 'inactive';
|
|
609
|
+
if (!registration_matches) return 'remote_activated';
|
|
610
|
+
if (probes.entry?.status === 'match' && (!probes.asset || probes.asset.status === 'match')) return 'public_samples_verified';
|
|
611
|
+
return 'room_registered';
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/** Compare independently observed deployment records and anonymous public responses. */
|
|
615
|
+
async function diagnose_site(home, conn, site_id, { origin, token, fetcher }) {
|
|
616
|
+
const remote = await remote_diagnostics(origin, site_id, token, fetcher);
|
|
617
|
+
const target = conn.room_id ? conn : resolve_room_connection(home, { room_id: remote.source_room, site: conn.site });
|
|
618
|
+
const registration = await read_registration(target, site_id, fetcher);
|
|
619
|
+
if (conn.room_id && remote.source_room !== conn.room_id && registration.state !== 'observed') {
|
|
620
|
+
throw new SiteCommandError(t('站点不属于当前房间'), { code: 'auth', http_status: 403 });
|
|
621
|
+
}
|
|
622
|
+
const public_origin = public_site_origin(origin, site_id, remote.url);
|
|
623
|
+
const asset_path = remote.samples?.asset?.path;
|
|
624
|
+
const [entry, asset] = remote.active_version ? await Promise.all([
|
|
625
|
+
check_public_file(public_origin, '/', remote.samples?.entry?.sha256, fetcher),
|
|
626
|
+
typeof asset_path === 'string' && inspect_local_path(asset_path).ok
|
|
627
|
+
? check_public_file(public_origin, '/' + asset_path.split('/').map(encodeURIComponent).join('/'),
|
|
628
|
+
remote.samples.asset.sha256, fetcher) : null,
|
|
629
|
+
]) : [null, null];
|
|
630
|
+
const probes = { entry, asset };
|
|
631
|
+
const registration_matches_active = remote.active_version && registration.state === 'observed'
|
|
632
|
+
? registration.version === remote.active_version && registration.status === 'active' : null;
|
|
633
|
+
return { site_id, url: public_origin || null, registration, remote: { status: remote.status, active_version: remote.active_version,
|
|
634
|
+
manifest: remote.manifest, details_available: remote.details_available }, registration_matches_active, probes,
|
|
635
|
+
last_confirmed_stage: confirmed_stage(remote, registration_matches_active, probes) };
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/** Execute a local site command. */
|
|
528
639
|
export async function site_command(home, command, input = {}, { fetcher = fetch, sites_origin: origin_override = '' } = {}) {
|
|
529
640
|
const origin = sites_origin(origin_override || input.sites_origin || '');
|
|
530
641
|
const conn = resolve_room_connection(home, input);
|
|
@@ -746,6 +857,10 @@ export async function site_command(home, command, input = {}, { fetcher = fetch,
|
|
|
746
857
|
throw new SiteCommandError(t('本机尚未注册发布身份,无法操作该站点'), { code: 'auth', http_status: 403 });
|
|
747
858
|
}
|
|
748
859
|
|
|
860
|
+
if (command === 'site-diagnose') {
|
|
861
|
+
return diagnose_site(home, conn, site_id, { origin, token: identity.device_token, fetcher });
|
|
862
|
+
}
|
|
863
|
+
|
|
749
864
|
if (command === 'site-renew') {
|
|
750
865
|
const res = await worker_api(origin, `/api/sites/${site_id}/renew`, {
|
|
751
866
|
method: 'POST', token: identity.device_token, body: {}, fetcher,
|
|
@@ -814,6 +929,7 @@ const SITE_CLI_HELP = () => t(`AI CoDiscuss 网站部署
|
|
|
814
929
|
codiscuss site stage (--dir 目录 | --file 文件.html) [--room 房间] [--title 标题] [--exclude 路径]
|
|
815
930
|
codiscuss site publish (--dir 目录 | --file 文件.html | --stage 编号) [--site 站点编号] [--room 房间] [--title 标题] [--exclude 路径]
|
|
816
931
|
codiscuss site list [--room 房间]
|
|
932
|
+
codiscuss site diagnose <站点编号> [--room 房间]
|
|
817
933
|
codiscuss site renew <站点编号> [--room 房间]
|
|
818
934
|
codiscuss site rollback <站点编号> [--version 版本号] [--room 房间]
|
|
819
935
|
codiscuss site revoke <站点编号> [--room 房间]
|
|
@@ -873,6 +989,7 @@ export async function site_cli(args, { home = service_home(), fetcher = fetch }
|
|
|
873
989
|
stage: 'site-stage',
|
|
874
990
|
publish: 'site-publish',
|
|
875
991
|
list: 'site-list',
|
|
992
|
+
diagnose: 'site-diagnose',
|
|
876
993
|
renew: 'site-renew',
|
|
877
994
|
rollback: 'site-rollback',
|
|
878
995
|
revoke: 'site-revoke',
|
|
@@ -891,13 +1008,17 @@ export async function site_cli(args, { home = service_home(), fetcher = fetch }
|
|
|
891
1008
|
dir: values.dir || undefined,
|
|
892
1009
|
file: values.file || undefined,
|
|
893
1010
|
stage_id: values.stage || undefined,
|
|
894
|
-
site_id: values.site || (['renew', 'rollback', 'revoke'].includes(sub) ? positionals[1] : undefined),
|
|
1011
|
+
site_id: values.site || (['diagnose', 'renew', 'rollback', 'revoke'].includes(sub) ? positionals[1] : undefined),
|
|
895
1012
|
title: values.title || undefined,
|
|
896
1013
|
exclude: values.exclude || undefined,
|
|
897
1014
|
version: values.version !== undefined ? Number(values.version) : undefined,
|
|
898
1015
|
sites_origin: values['sites-origin'] || undefined,
|
|
899
1016
|
};
|
|
900
1017
|
try {
|
|
1018
|
+
if (sub === 'diagnose' && access.room && (input.room_id !== access.room
|
|
1019
|
+
|| (values.url && values.url.replace(/\/+$/, '') !== access.site?.replace(/\/+$/, '')))) {
|
|
1020
|
+
throw new SiteCommandError(t('站点诊断须使用凭据绑定的房间和网站'), { code: 'auth', http_status: 403 });
|
|
1021
|
+
}
|
|
901
1022
|
const result = await site_command(home, command, input, { fetcher });
|
|
902
1023
|
process.stdout.write(`${JSON.stringify({ ok: true, data: result }, null, 2)}\n`);
|
|
903
1024
|
} catch (error) {
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure timeline and concurrency-panorama calculations shared by the web timeline page (`frontend/timeline-model.js`),
|
|
3
|
+
* the share-card CLI (`runner/share_card.mjs`), and share modules. Zero UI, locale, or Node.js dependencies.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** The owner as a member of the timeline: rows named this represent the owner's messages rather than executions. */
|
|
7
|
+
export const USER_MEMBER = '用户';
|
|
8
|
+
|
|
9
|
+
/** 820ms, 6.9s, 42s, 3m 05s, 2h 05m: the precision a reader compares at each scale. */
|
|
10
|
+
export function format_duration(ms) {
|
|
11
|
+
if (ms < 1000) return `${Math.max(0, Math.round(ms))}ms`;
|
|
12
|
+
if (ms < 10_000) return `${(ms / 1000).toFixed(1)}s`;
|
|
13
|
+
const seconds = Math.round(ms / 1000);
|
|
14
|
+
if (seconds < 60) return `${seconds}s`;
|
|
15
|
+
if (seconds < 3600) return `${Math.floor(seconds / 60)}m ${String(seconds % 60).padStart(2, '0')}s`;
|
|
16
|
+
return `${Math.floor(seconds / 3600)}h ${String(Math.floor(seconds % 3600 / 60)).padStart(2, '0')}m`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* One execution's stages. Queue runs from the request to delivery and wake from delivery to the first sign of work:
|
|
21
|
+
* the discussion's enter, else a free execution's first recorded segment (approximate). Without either, the time after
|
|
22
|
+
* delivery is all work and wake is absent. An execution still running ends at `now_ms`, and so does its last segment:
|
|
23
|
+
* the phase it was last seen in is shown as lasting until the next report says otherwise (`live`). Progress notes are
|
|
24
|
+
* placed when the website received them, within the execution.
|
|
25
|
+
*/
|
|
26
|
+
export function execution_stages(item, now_ms) {
|
|
27
|
+
const running = item.state === 'running';
|
|
28
|
+
const end = item.finished_at ? item.finished_at * 1000 : now_ms;
|
|
29
|
+
const dispatched = item.dispatched_at ? item.dispatched_at * 1000 : 0;
|
|
30
|
+
const queued = Math.min(item.queued_at ? item.queued_at * 1000 : dispatched || end, dispatched || end);
|
|
31
|
+
const raw_segments = Array.isArray(item.segments) ? item.segments : [];
|
|
32
|
+
// `seen` is where output was last seen; past it a live segment is only assumed to go on, and is drawn as a faint tail.
|
|
33
|
+
const segments = dispatched ? raw_segments.map((segment, index) => {
|
|
34
|
+
const live = running && index === raw_segments.length - 1;
|
|
35
|
+
const seen = Math.min(dispatched + segment.end_ms, end);
|
|
36
|
+
return { phase: segment.phase, tool: segment.tool, live, seen, start: Math.min(dispatched + segment.start_ms, end), end: live ? end : seen };
|
|
37
|
+
}) : [];
|
|
38
|
+
// Phases not read yet (`segments_pending`, see has_phase_detail) still say where the first began.
|
|
39
|
+
const entered = item.started_at ? item.started_at * 1000 : segments[0]?.start ?? (dispatched && item.first_ms != null ? Math.min(dispatched + item.first_ms, end) : 0);
|
|
40
|
+
const work_start = dispatched ? Math.max(dispatched, Math.min(entered || dispatched, end)) : end;
|
|
41
|
+
const notes = dispatched ? (item.notes || []).map((at, index) => ({ index, at: Math.min(Math.max(at * 1000, dispatched), end) })) : [];
|
|
42
|
+
return {
|
|
43
|
+
start: queued, end, queue: [queued, dispatched || end],
|
|
44
|
+
wake: dispatched && work_start > dispatched ? [dispatched, work_start] : null,
|
|
45
|
+
work: dispatched ? [work_start, end] : null,
|
|
46
|
+
wake_approx: !item.started_at, segments, notes,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The room cut into tasks, oldest first. A task starts only where the owner asked for something new while the room was
|
|
52
|
+
* idle: an execution started by a message the owner wrote (`task_author` "用户") that no earlier execution answered, with
|
|
53
|
+
* every execution requested before it already ended. Everything else joins the task in progress: the owner's
|
|
54
|
+
* interjections while work runs, the host's dispatches and proactive posts, hand-backs, the program's wakes, Goal runs and
|
|
55
|
+
* retries. No time threshold and no dispatch chain decide it.
|
|
56
|
+
*/
|
|
57
|
+
export function timeline_segments(executions, now_ms) {
|
|
58
|
+
const ordered = executions.map((item) => ({ item, stages: execution_stages(item, now_ms) }))
|
|
59
|
+
.sort((a, b) => a.stages.queue[0] - b.stages.queue[0] || a.item.id - b.item.id);
|
|
60
|
+
const segments = [];
|
|
61
|
+
const asked = new Set();
|
|
62
|
+
let busy_until = -Infinity;
|
|
63
|
+
for (const entry of ordered) {
|
|
64
|
+
const { item, stages } = entry;
|
|
65
|
+
const key = `${item.source}:${item.id}`;
|
|
66
|
+
const new_ask = item.task_author === USER_MEMBER && item.task_id != null && !asked.has(item.task_id);
|
|
67
|
+
if (!segments.length || (new_ask && stages.queue[0] >= busy_until)) {
|
|
68
|
+
segments.push({ key, opener: item, opened: new_ask, items: [], keys: new Set(), interjections: [] });
|
|
69
|
+
} else if (new_ask) {
|
|
70
|
+
segments.at(-1).interjections.push({ key, task_id: item.task_id, task: item.task || '', at: stages.queue[0] });
|
|
71
|
+
}
|
|
72
|
+
const segment = segments.at(-1);
|
|
73
|
+
segment.items.push(entry);
|
|
74
|
+
segment.keys.add(key);
|
|
75
|
+
if (item.task_id != null) asked.add(item.task_id);
|
|
76
|
+
busy_until = Math.max(busy_until, stages.end);
|
|
77
|
+
}
|
|
78
|
+
return segments;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The room in real time (2026-11-23 user's request, #8032): one linear axis from the first execution to the last end,
|
|
83
|
+
* nothing folded. `steps` cut that span wherever an execution starts or ends; each has `members` (who was working then,
|
|
84
|
+
* as `{ member, count, keys }` in order of first appearance, `keys` the row keys of their executions then) and `total`.
|
|
85
|
+
* An execution counts from its delivery to its end, so waiting in the queue is not work; a step with `total` 0 is the
|
|
86
|
+
* room standing idle, also listed in `idle`. `tasks` are the segments' spans (`key`, `task`, `opened`, `start`, `end`),
|
|
87
|
+
* the owner's rows left out. `peak` is the most at once.
|
|
88
|
+
* What the view is opened for (#8279): how much of the span the room worked by itself (`busy_ms`, the span less its idle
|
|
89
|
+
* time) and how many executions started without the owner (`runs`, of which `self_started` were begun by the host's
|
|
90
|
+
* dispatch, a relay, a hand-back, a wake or a Goal run rather than a message the owner wrote). `unattended` is the
|
|
91
|
+
* longest the room ran on by itself after one of the owner's messages (#8313): from the message until the room first
|
|
92
|
+
* stood idle or the owner wrote again, as `{ start, end }`, or null.
|
|
93
|
+
*/
|
|
94
|
+
export function realtime_model(segments) {
|
|
95
|
+
const runs = segments.flatMap((segment) => segment.items).filter(({ item, stages }) => item.source !== 'user' && stages.work)
|
|
96
|
+
.map(({ item, stages }) => ({ key: `${item.source}:${item.id}`, member: item.member, start: stages.queue[1], end: Math.max(stages.queue[1], stages.end),
|
|
97
|
+
asked: stages.queue[0], self_started: Boolean(item.task_author) && item.task_author !== USER_MEMBER }));
|
|
98
|
+
if (!runs.length) return { start: 0, end: 0, steps: [], idle: [], tasks: [], peak: 0, members: [], idle_ms: 0, busy_ms: 0, runs: 0, self_started: 0, unattended: null };
|
|
99
|
+
const members = [...new Set([...runs].sort((a, b) => a.start - b.start).map((run) => run.member))];
|
|
100
|
+
const times = [...new Set(runs.flatMap((run) => [run.start, run.end]))].sort((a, b) => a - b);
|
|
101
|
+
const steps = [];
|
|
102
|
+
for (let index = 0; index + 1 < times.length; index += 1) {
|
|
103
|
+
const [start, end] = [times[index], times[index + 1]];
|
|
104
|
+
const keys = new Map();
|
|
105
|
+
for (const run of runs) if (run.start <= start && run.end >= end) keys.set(run.member, [...(keys.get(run.member) || []), run.key]);
|
|
106
|
+
const list = members.filter((member) => keys.has(member)).map((member) => ({ member, count: keys.get(member).length, keys: keys.get(member) }));
|
|
107
|
+
const total = list.reduce((sum, entry) => sum + entry.count, 0);
|
|
108
|
+
const last = steps.at(-1);
|
|
109
|
+
if (last && last.total === total && last.members.length === list.length && last.members.every((entry, at) => entry.member === list[at].member && entry.keys.join() === list[at].keys.join())) last.end = end;
|
|
110
|
+
else steps.push({ start, end, members: list, total });
|
|
111
|
+
}
|
|
112
|
+
const idle = steps.filter((step) => !step.total).map(({ start, end }) => ({ start, end }));
|
|
113
|
+
const tasks = segments.map((segment) => {
|
|
114
|
+
const spans = segment.items.filter(({ item }) => item.source !== 'user').map(({ stages }) => stages);
|
|
115
|
+
return spans.length ? { key: segment.key, task: segment.opener.task || '', opened: segment.opened,
|
|
116
|
+
start: Math.min(...spans.map((stages) => stages.queue[1] || stages.start)), end: Math.max(...spans.map((stages) => stages.end)) } : null;
|
|
117
|
+
}).filter(Boolean);
|
|
118
|
+
const idle_ms = idle.reduce((sum, gap) => sum + gap.end - gap.start, 0);
|
|
119
|
+
// The room's busy stretches, then for each run the owner asked for: until its stretch ends or the owner writes again.
|
|
120
|
+
const busy = [];
|
|
121
|
+
for (const run of [...runs].sort((a, b) => a.start - b.start)) {
|
|
122
|
+
const last = busy.at(-1);
|
|
123
|
+
if (last && run.start <= last.end) last.end = Math.max(last.end, run.end);
|
|
124
|
+
else busy.push({ start: run.start, end: run.end });
|
|
125
|
+
}
|
|
126
|
+
const asks = [...new Set(runs.filter((run) => !run.self_started).map((run) => run.asked))].sort((a, b) => a - b);
|
|
127
|
+
let unattended = null;
|
|
128
|
+
for (const run of runs.filter((item) => !item.self_started)) {
|
|
129
|
+
const stretch = busy.find((item) => item.start <= run.start && run.start <= item.end);
|
|
130
|
+
const next = asks.find((at) => at > run.asked) ?? Infinity;
|
|
131
|
+
const end = Math.min(stretch?.end ?? run.end, next);
|
|
132
|
+
if (end > run.asked && (!unattended || end - run.asked > unattended.end - unattended.start)) unattended = { start: run.asked, end };
|
|
133
|
+
}
|
|
134
|
+
return { start: times[0], end: times.at(-1), steps, idle, tasks, members, peak: Math.max(...steps.map((step) => step.total)),
|
|
135
|
+
idle_ms, busy_ms: times.at(-1) - times[0] - idle_ms, runs: runs.length, self_started: runs.filter((run) => run.self_started).length, unattended };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Compute collaboration metrics from raw timeline executions using the exact same definitions as RealtimeView.vue.
|
|
140
|
+
*
|
|
141
|
+
* @param {Array<object>} executions Timeline execution records from `/api/rooms/:id/timeline`.
|
|
142
|
+
* @param {number} [now_ms] Reference timestamp in epoch ms for running executions.
|
|
143
|
+
* @returns {object} Summary metrics, per-member work totals, and the underlying realtime model.
|
|
144
|
+
*/
|
|
145
|
+
export function collaboration_metrics(executions, now_ms = Date.now()) {
|
|
146
|
+
const segments = timeline_segments(executions || [], now_ms);
|
|
147
|
+
const model = realtime_model(segments);
|
|
148
|
+
const span_ms = Math.max(0, model.end - model.start);
|
|
149
|
+
const percent = (part, whole) => (whole ? Math.round(part / whole * 100) : 0);
|
|
150
|
+
const member_stats = new Map();
|
|
151
|
+
for (const segment of segments) {
|
|
152
|
+
for (const { item, stages } of segment.items) {
|
|
153
|
+
if (item.source === 'user' || !stages.work) continue;
|
|
154
|
+
const entry = member_stats.get(item.member) || { member: item.member, runs: 0, work_ms: 0 };
|
|
155
|
+
entry.runs += 1;
|
|
156
|
+
entry.work_ms += Math.max(0, stages.end - stages.queue[1]);
|
|
157
|
+
member_stats.set(item.member, entry);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const member_totals = [...member_stats.values()]
|
|
161
|
+
.sort((a, b) => b.work_ms - a.work_ms || b.runs - a.runs)
|
|
162
|
+
.map((entry) => ({ ...entry, work_text: format_duration(entry.work_ms) }));
|
|
163
|
+
const unattended = model.unattended ? {
|
|
164
|
+
start_ms: model.unattended.start,
|
|
165
|
+
end_ms: model.unattended.end,
|
|
166
|
+
duration_ms: model.unattended.end - model.unattended.start,
|
|
167
|
+
duration_text: format_duration(model.unattended.end - model.unattended.start),
|
|
168
|
+
} : null;
|
|
169
|
+
return {
|
|
170
|
+
span_ms,
|
|
171
|
+
span_text: format_duration(span_ms),
|
|
172
|
+
busy_ms: model.busy_ms,
|
|
173
|
+
busy_text: format_duration(model.busy_ms),
|
|
174
|
+
busy_percent: percent(model.busy_ms, span_ms),
|
|
175
|
+
idle_ms: model.idle_ms,
|
|
176
|
+
idle_text: format_duration(model.idle_ms),
|
|
177
|
+
runs: model.runs,
|
|
178
|
+
self_started: model.self_started,
|
|
179
|
+
self_started_percent: percent(model.self_started, model.runs),
|
|
180
|
+
peak_concurrency: model.peak,
|
|
181
|
+
unattended,
|
|
182
|
+
member_totals,
|
|
183
|
+
model,
|
|
184
|
+
};
|
|
185
|
+
}
|
package/runner/workflows.mjs
CHANGED
|
@@ -20,6 +20,8 @@ export const MAX_WORKFLOW_SKILL = 20000;
|
|
|
20
20
|
export const MAX_WORKFLOW_CARDS = 30;
|
|
21
21
|
const MAX_WORKFLOW_LABEL = 32;
|
|
22
22
|
const MAX_WORKFLOW_DESCRIPTION = 500;
|
|
23
|
+
const MAX_WORKFLOW_AUTHOR = 64;
|
|
24
|
+
const MAX_WORKFLOW_SOURCE = 200;
|
|
23
25
|
const MAX_DRAFT_PARTS = 20;
|
|
24
26
|
const WORKFLOW_LOCK_WAIT_MS = 5000;
|
|
25
27
|
const BACKUP_DIRECTORY = /^\.old-([a-z0-9_-]{1,40})-[0-9a-f-]{36}$/;
|
|
@@ -177,9 +179,19 @@ function skill_label(fields) {
|
|
|
177
179
|
return (fields.metadata && typeof fields.metadata === 'object' ? fields.metadata.label : '') || (typeof fields.label === 'string' ? fields.label : '');
|
|
178
180
|
}
|
|
179
181
|
|
|
180
|
-
/**
|
|
181
|
-
function
|
|
182
|
-
|
|
182
|
+
/** Human-facing display metadata under `metadata:` (`author`, `source`), never sent to the host. */
|
|
183
|
+
function skill_meta(fields) {
|
|
184
|
+
const meta = fields.metadata && typeof fields.metadata === 'object' ? fields.metadata : {};
|
|
185
|
+
const pick = key => (typeof meta[key] === 'string' ? meta[key].trim() : '');
|
|
186
|
+
const author = pick('author'), source = pick('source');
|
|
187
|
+
return { ...(author ? { author } : {}), ...(source ? { source } : {}) };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** SKILL.md frontmatter as the Agent Skills format writes it: display fields (and a sub-workflow's `attach`) go under `metadata`. */
|
|
191
|
+
function skill_fields(id, label, description, attach = [], meta = {}) {
|
|
192
|
+
const { author, source } = meta;
|
|
193
|
+
return { name: id, description, metadata: { label, ...(author ? { author } : {}), ...(source ? { source } : {}),
|
|
194
|
+
...(attach?.length ? { attach: attach.join(', ') } : {}) } };
|
|
183
195
|
}
|
|
184
196
|
|
|
185
197
|
/** A sub-workflow's `metadata.attach`: the main flow's stage IDs it attaches to, written comma-separated. */
|
|
@@ -285,7 +297,7 @@ function workflow_from_files(skill_text, cards, resources = {}, ignored = []) {
|
|
|
285
297
|
const { [FLOW_FILE]: flow_text, ...others } = resources;
|
|
286
298
|
const flow = typeof flow_text === 'string' ? parse_flow_text(flow_text, FLOW_FILE) : undefined;
|
|
287
299
|
const { sub_workflows, rest } = split_sub_workflows(others, ignored);
|
|
288
|
-
return { id: fields.name || '', label: skill_label(fields), description: fields.description || '', skill: body,
|
|
300
|
+
return { id: fields.name || '', label: skill_label(fields), description: fields.description || '', ...skill_meta(fields), skill: body,
|
|
289
301
|
agents: cards_from_files(cards, 'agents/', ignored), resources: rest, sub_workflows, ...(flow ? { flow } : {}) };
|
|
290
302
|
}
|
|
291
303
|
|
|
@@ -549,8 +561,11 @@ export function validate_workflow(input, validate_card) {
|
|
|
549
561
|
// Checked only when saving: a workflow saved earlier under one of these names can still be read and deleted.
|
|
550
562
|
if (RESERVED_WORKFLOW_IDS.includes(id)) throw new Error(`工作流 ID 不能用 ${id}:它是内置模式 /${id} 的命令`);
|
|
551
563
|
const label = String(input.label || '').trim(), description = String(input.description || '').trim(), skill = String(input.skill || '').trim();
|
|
564
|
+
const author = String(input.author || '').trim(), source = String(input.source || '').trim();
|
|
552
565
|
if (label.length > MAX_WORKFLOW_LABEL) throw new Error(`工作流显示名最多 ${MAX_WORKFLOW_LABEL} 字`);
|
|
553
566
|
if (description.length > MAX_WORKFLOW_DESCRIPTION || /\n/.test(description)) throw new Error(`工作流描述最多 ${MAX_WORKFLOW_DESCRIPTION} 字,且不能换行`);
|
|
567
|
+
if (author.length > MAX_WORKFLOW_AUTHOR || /\n/.test(author)) throw new Error(`工作流作者最多 ${MAX_WORKFLOW_AUTHOR} 字,且不能换行`);
|
|
568
|
+
if (source.length > MAX_WORKFLOW_SOURCE || /\n/.test(source)) throw new Error(`工作流出处最多 ${MAX_WORKFLOW_SOURCE} 字,且不能换行`);
|
|
554
569
|
if (!skill) throw new Error('SKILL.md 正文不能为空');
|
|
555
570
|
if (skill.length > MAX_WORKFLOW_SKILL) throw new Error(`SKILL.md 正文最多 ${MAX_WORKFLOW_SKILL} 字`);
|
|
556
571
|
const agents = input.agents || [];
|
|
@@ -563,7 +578,7 @@ export function validate_workflow(input, validate_card) {
|
|
|
563
578
|
const sub_workflows = input.sub_workflows === undefined ? undefined : validate_sub_workflows(input.sub_workflows, validate_card, main_cards);
|
|
564
579
|
workflow_cards({ agents: normalized, sub_workflows });
|
|
565
580
|
const flow = validate_flow(input.flow, main_cards, sub_workflows?.map(sub => sub.id));
|
|
566
|
-
return { id, label, description, skill, agents: normalized,
|
|
581
|
+
return { id, label, description, ...(author ? { author } : {}), ...(source ? { source } : {}), skill, agents: normalized,
|
|
567
582
|
...(resources === undefined ? {} : { resources }),
|
|
568
583
|
...(sub_workflows === undefined ? {} : { sub_workflows }),
|
|
569
584
|
...(flow === undefined ? {} : { flow }) };
|
|
@@ -658,7 +673,10 @@ export function list_workflows(home, card_ready = null) {
|
|
|
658
673
|
const unavailable = card_ready ? workflow_cards(workflow).filter(agent => !card_ready(agent.name)).map(agent => ({
|
|
659
674
|
card: agent.card, label: agent.label || agent.card, platform: agent.name.slice(0, agent.name.length - agent.card.length - 1),
|
|
660
675
|
...(agent.sub_workflow ? { sub_workflow: agent.sub_workflow } : {}) })) : [];
|
|
661
|
-
return { id, label: workflow.label || id, description: workflow.description,
|
|
676
|
+
return { id, label: workflow.label || id, description: workflow.description,
|
|
677
|
+
...(workflow.author ? { author: workflow.author } : {}),
|
|
678
|
+
...(workflow.source ? { source: workflow.source } : {}),
|
|
679
|
+
cards: workflow.agents.length, directory: workflow.directory,
|
|
662
680
|
...(unavailable.length ? { unavailable } : {}), ...flag };
|
|
663
681
|
} catch (error) { return { id, label: id, description: '', cards: 0, error: error.message, ...flag }; }
|
|
664
682
|
});
|
|
@@ -703,7 +721,7 @@ export function rename_workflow(home, id, label) {
|
|
|
703
721
|
if (text.length > MAX_WORKFLOW_LABEL) throw new Error(`工作流显示名最多 ${MAX_WORKFLOW_LABEL} 字`);
|
|
704
722
|
return with_workflow_lock(home, () => {
|
|
705
723
|
const workflow = read_saved_workflow(home, id);
|
|
706
|
-
writeFileSync(join(workflow.directory, 'SKILL.md'), serialize_markdown(skill_fields(id, text, workflow.description), workflow.skill));
|
|
724
|
+
writeFileSync(join(workflow.directory, 'SKILL.md'), serialize_markdown(skill_fields(id, text, workflow.description, [], workflow), workflow.skill));
|
|
707
725
|
return { id, label: text };
|
|
708
726
|
});
|
|
709
727
|
}
|
|
@@ -801,7 +819,7 @@ export function save_workflow(home, input, validate_card, base = {}) {
|
|
|
801
819
|
const carry = { folders: card_folders(directory), replace: base.overwrite === true || !existsSync(directory),
|
|
802
820
|
backup: (card, folder) => backups.push(backup_card(home, workflow.id, card, folder)) };
|
|
803
821
|
mkdirSync(join(staging, 'agents'), { recursive: true });
|
|
804
|
-
writeFileSync(join(staging, 'SKILL.md'), serialize_markdown(skill_fields(workflow.id, workflow.label, workflow.description), workflow.skill));
|
|
822
|
+
writeFileSync(join(staging, 'SKILL.md'), serialize_markdown(skill_fields(workflow.id, workflow.label, workflow.description, [], workflow), workflow.skill));
|
|
805
823
|
write_cards(join(staging, 'agents'), workflow.agents, carry);
|
|
806
824
|
if (workflow.resources) write_resources(staging, workflow.resources);
|
|
807
825
|
else if (existsSync(directory)) keep_resources(directory, staging);
|
|
@@ -947,7 +965,7 @@ export function load_room_workflow(config) {
|
|
|
947
965
|
const stages = (workflow.flow?.stages || []).map(stage => ({ id: stage.id, label: stage.label || stage.id }));
|
|
948
966
|
return { id: binding.id, label: workflow.label || binding.id, description: workflow.description || '', directory, skill_path: join(directory, 'SKILL.md'), skill: workflow.skill,
|
|
949
967
|
revision: revision_of(workflow.skill), members: binding.members || {}, extra_members: binding.extra_members || {}, cards, sub_workflows, stages,
|
|
950
|
-
commands: workflow.commands };
|
|
968
|
+
commands: workflow.commands, content_revision: workflow.revision };
|
|
951
969
|
} catch (error) { return { id: binding.id, error: error.message }; }
|
|
952
970
|
}
|
|
953
971
|
|
|
@@ -956,6 +974,17 @@ export function card_of_member(workflow, member_name) {
|
|
|
956
974
|
return Object.entries(workflow?.members || {}).find(([, name]) => name === member_name)?.[0] || workflow?.extra_members?.[member_name] || '';
|
|
957
975
|
}
|
|
958
976
|
|
|
977
|
+
/** Capture the workflow actually supplied to a delivery, without prompts, descriptions or local paths. */
|
|
978
|
+
export function workflow_execution_binding(workflow, member, host_has_workflow) {
|
|
979
|
+
if (!workflow || workflow.error) return null;
|
|
980
|
+
const card = card_of_member(workflow, member.name);
|
|
981
|
+
const source = workflow.cards[card];
|
|
982
|
+
if (!source && !host_has_workflow) return null;
|
|
983
|
+
const sub = workflow.sub_workflows.find(item => item.id === source?.sub_workflow);
|
|
984
|
+
return { id: workflow.id, revision: workflow.content_revision || workflow.revision, card: source ? card : null,
|
|
985
|
+
sub_workflow: sub?.id ?? null, sub_revision: sub?.revision ?? null, skills: (source?.skills || []).slice(0, 50) };
|
|
986
|
+
}
|
|
987
|
+
|
|
959
988
|
/** Every member a workflow brought, with its card: each card's first member, then the further members of a card. */
|
|
960
989
|
export function workflow_member_list(workflow) {
|
|
961
990
|
return [...Object.entries(workflow?.members || {}).map(([card, name]) => ({ card, name })),
|