dsh-workflow-canvas 1.5.5 → 1.6.0

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/client.js CHANGED
@@ -197,7 +197,7 @@ window.__ModuleLoader__.load({
197
197
  '10. 点右上角「☰ 预设」可保存当前画布(连同横/竖排方向),多会话实时同步并支持点 ↻ 刷新;切换横/竖排会自动记住默认偏好供新会话沿用。',
198
198
  '11. 你可以直接让我改画布:说「把那三个节点的分工改成…」,我会就地修改,不动你摆的位置。',
199
199
  '12. session 线连到 Lead 时,我会在暂停那步拿到那个子代理的会话,可以继续追问它。',
200
- '13. 按住鼠标中键(或空格 + 左键)拖动画布平移;点击子代理节点左下角状态可直达它的对话记录。',
200
+ '13. 按住鼠标中键(或空格 + 左键)拖动画布平移;点击子代理节点左下角状态可直达它的对话记录;运行后左下角「复盘」胶囊(或「⋯ → 📊 执行复盘」)可查看耗时、分支与回环记录并复制 Markdown(零额外 Token)。',
201
201
  '14. 快捷键与历史:顶栏提供 ↶ 撤销 / ↷ 重做按钮(支持撤销节点移动与横竖排切换);默认 Shift+A 新建,Shift+D 复制,Delete 删除,Ctrl+Z / Ctrl+Shift+Z(Ctrl+Y)撤销重做,Esc 关闭弹窗(可在「⋯ → 快捷键设置」自定义)。',
202
202
  ].join('\n'),
203
203
  openChat: '会话',
@@ -314,6 +314,34 @@ window.__ModuleLoader__.load({
314
314
  tipMemoryPick: '选择要续接的历史子会话(默认自动沿用最新记忆)',
315
315
  tipPreset: '能力范围(点一下切换,受主对话权限上限约束):standard = 全部工具(读写文件、跑命令、子代理、工作流、网页、办公);minimal = 只读思考(文件读写关闭,没有子代理/工作流/网页)',
316
316
  tipFallback: '失败重试:该节点出错时自动换一个模型再跑一次',
317
+ runSummaryBtn: '复盘',
318
+ runSummaryMenu: '📊 执行复盘',
319
+ runSummaryTitle: '执行复盘摘要',
320
+ runSummaryEmpty: '当前会话还没有运行记录',
321
+ runSummaryCopy: '⧉ 复制 MD',
322
+ runSummaryCopied: '已复制 Markdown 复盘报告',
323
+ runSummaryElapsed: '总耗时',
324
+ runSummaryDone: '已完成',
325
+ runSummaryLoops: '回环重试',
326
+ runSummaryParallel: '并发上限',
327
+ runSummaryNodesHead: '节点耗时与状态',
328
+ runSummaryLoopsHead: '回环记录',
329
+ runSummaryFallback: '备用回退',
330
+ runSummaryContinued: '续接会话',
331
+ runSummaryReused: '缓存复用',
332
+ runSummaryRuns: '{n} 轮',
333
+ runSummaryExhausted: '已达上限',
334
+ runSummaryFocusTip: '点击居中定位到该节点',
335
+ runSummaryOpenChatTip: '打开该子代理会话',
336
+ runSummaryTip: '查看本次工作流耗时、节点状态、条件分支与回环复盘(零额外 Token)',
337
+ runStRunning: '运行中',
338
+ runStDone: '已完成',
339
+ runStWaiting: '待拍板',
340
+ runStHalted: '已终止',
341
+ runStFailed: '失败',
342
+ runStEmpty: '空输出',
343
+ runStPruned: '跳过',
344
+ runStPending: '未启动',
317
345
  },
318
346
  en: {
319
347
  addAgent: '+ Subagent', addLead: '+ Lead', addCond: '+ Condition', undo: '↶ Undo', redo: '↷ Redo', sync: '↥ Sync',
@@ -393,7 +421,7 @@ window.__ModuleLoader__.load({
393
421
  '10. Open ☰ Presets to save the current canvas (including horizontal/vertical direction) — presets sync live across open chats with a manual ↻ refresh button; toggling layout direction is remembered for new sessions.',
394
422
  '11. You can ask me to edit the canvas; I patch it in place and keep your layout.',
395
423
  '12. A session link into a Lead step hands me that child agent, so I can follow up with it.',
396
- '13. Hold the middle mouse button (or Space + drag) to pan; click a subagent status badge at the bottom-left to open its chat.',
424
+ '13. Hold the middle mouse button (or Space + drag) to pan; click a subagent status badge at the bottom-left to open its chat; click the bottom-left Summary pill (or ⋯ → 📊 Run summary) for live timing, branch & retry breakdown and Markdown export (zero extra tokens).',
397
425
  '14. History & shortcuts: toolbar ↶ Undo / ↷ Redo buttons undo structural edits, node drags, and layout flips; Shift+A adds at cursor, Shift+D duplicates, Delete removes, Ctrl+Z / Ctrl+Shift+Z (Ctrl+Y) undo/redo, Esc closes popups (customizable under ⋯ → Shortcuts).',
398
426
  ].join('\n'),
399
427
  openChat: 'Chat',
@@ -510,6 +538,34 @@ window.__ModuleLoader__.load({
510
538
  tipMemoryPick: 'Pick which past child session to resume (defaults to latest)',
511
539
  tipPreset: 'Capability (click to toggle; bounded by the main chat permission mode): standard = all tools (files, shells, subagents, workflow, web, office); minimal = read-only thinking (no file writes, no subagents/workflow/web)',
512
540
  tipFallback: 'Retry: when this node fails, rerun it once on another model',
541
+ runSummaryBtn: 'Summary',
542
+ runSummaryMenu: '📊 Run summary',
543
+ runSummaryTitle: 'Run Summary',
544
+ runSummaryEmpty: 'No workflow run recorded in this session yet',
545
+ runSummaryCopy: '⧉ Copy MD',
546
+ runSummaryCopied: 'Copied Markdown run summary',
547
+ runSummaryElapsed: 'Elapsed',
548
+ runSummaryDone: 'Completed',
549
+ runSummaryLoops: 'Loop retries',
550
+ runSummaryParallel: 'Max parallel',
551
+ runSummaryNodesHead: 'Node timeline',
552
+ runSummaryLoopsHead: 'Loop history',
553
+ runSummaryFallback: 'Fallback',
554
+ runSummaryContinued: 'Continued',
555
+ runSummaryReused: 'Cached',
556
+ runSummaryRuns: '{n} runs',
557
+ runSummaryExhausted: 'Exhausted',
558
+ runSummaryFocusTip: 'Click to focus this node on canvas',
559
+ runSummaryOpenChatTip: 'Open child session',
560
+ runSummaryTip: 'Inspect run timing, node status, branch verdicts & retry history (zero extra tokens)',
561
+ runStRunning: 'Running',
562
+ runStDone: 'Completed',
563
+ runStWaiting: 'Awaiting Lead',
564
+ runStHalted: 'Halted',
565
+ runStFailed: 'Failed',
566
+ runStEmpty: 'Empty',
567
+ runStPruned: 'Skipped',
568
+ runStPending: 'Pending',
513
569
  },
514
570
  };
515
571
 
@@ -600,6 +656,45 @@ window.__ModuleLoader__.load({
600
656
  background: 'transparent', color: C.text, fontSize: '11px',
601
657
  cursor: 'pointer', whiteSpace: 'nowrap', lineHeight: '16px',
602
658
  },
659
+ floatSummaryBtn: {
660
+ position: 'absolute', left: '10px', bottom: '10px', zIndex: 30,
661
+ display: 'inline-flex', alignItems: 'center', gap: '5px',
662
+ padding: '4px 10px', borderRadius: '999px',
663
+ background: C.elevated, color: C.text, border: '1px solid ' + C.border,
664
+ fontSize: '11px', fontWeight: 600, lineHeight: '16px',
665
+ cursor: 'pointer', boxShadow: '0 4px 14px rgba(0,0,0,0.28)',
666
+ maxWidth: 'calc(100% - 118px)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
667
+ fontVariantNumeric: 'tabular-nums',
668
+ },
669
+ summaryKpiRow: {
670
+ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(84px, 1fr))', gap: '6px',
671
+ marginBottom: '10px', flex: '0 0 auto',
672
+ },
673
+ summaryKpi: {
674
+ padding: '6px 8px', borderRadius: '6px',
675
+ background: C.raised, border: '1px solid ' + C.border,
676
+ display: 'flex', flexDirection: 'column', gap: '2px', minWidth: 0,
677
+ },
678
+ summaryRow: {
679
+ padding: '7px 8px', borderRadius: '6px', flex: '0 0 auto',
680
+ background: C.raised, border: '1px solid ' + C.border,
681
+ display: 'flex', flexDirection: 'column', gap: '4px',
682
+ },
683
+ summaryBarTrack: {
684
+ width: '100%', height: '3px', borderRadius: '2px',
685
+ background: C.border, overflow: 'hidden', opacity: 0.75,
686
+ },
687
+ summaryBarFill: {
688
+ height: '100%', borderRadius: '2px',
689
+ transition: 'width 180ms ease',
690
+ },
691
+ summaryChip: {
692
+ display: 'inline-flex', alignItems: 'center', gap: '3px',
693
+ padding: '1px 5px', borderRadius: '4px',
694
+ border: '1px solid ' + C.border, background: C.base,
695
+ color: C.dim, fontSize: '10px', lineHeight: '13px',
696
+ maxWidth: '100%', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
697
+ },
603
698
  ctxDivider: {
604
699
  height: '1px', background: C.border, opacity: 0.65, margin: '3px 4px',
605
700
  },
@@ -1126,17 +1221,25 @@ window.__ModuleLoader__.load({
1126
1221
  };
1127
1222
  }
1128
1223
 
1129
- /** Compute unified Stop button visibility, label and tooltip across running & waitingLead states. */
1224
+ /** Compute unified Stop button state across idle, running & waitingLead modes. */
1130
1225
  function stopButtonState({ sessionRunning, runningNodesCount, waitingLead, triggering, stopping, lang }) {
1131
1226
  const en = lang === 'en';
1132
1227
  const hasRunning = Boolean(sessionRunning || triggering || Number(runningNodesCount) > 0);
1133
1228
  const hasWaiting = Boolean(waitingLead);
1134
1229
  if (!hasRunning && !hasWaiting) {
1135
- return { visible: false, disabled: true, mode: 'idle', label: '', title: '' };
1230
+ return {
1231
+ visible: true,
1232
+ active: false,
1233
+ disabled: true,
1234
+ mode: 'idle',
1235
+ label: en ? '⏹ Stop' : '⏹ 终止',
1236
+ title: en ? 'No running or paused workflow to stop' : '当前没有运行中或等待拍板的任务',
1237
+ };
1136
1238
  }
1137
1239
  const mode = hasRunning ? 'running' : 'waiting';
1138
1240
  return {
1139
1241
  visible: true,
1242
+ active: true,
1140
1243
  disabled: Boolean(stopping),
1141
1244
  mode,
1142
1245
  label: stopping
@@ -1211,6 +1314,228 @@ window.__ModuleLoader__.load({
1211
1314
  return { leadReadyIds, leadDoneIds };
1212
1315
  }
1213
1316
 
1317
+ /** Format millisecond durations cleanly for badges, KPI cards and Markdown tables. */
1318
+ function formatDurationMs(ms) {
1319
+ if (typeof ms !== 'number' || !Number.isFinite(ms) || ms < 0) return '—';
1320
+ if (ms < 1000) return Math.round(ms) + 'ms';
1321
+ if (ms < 60000) return (ms / 1000).toFixed(1) + 's';
1322
+ const totalSec = Math.round(ms / 1000);
1323
+ const min = Math.floor(totalSec / 60);
1324
+ const sec = totalSec % 60;
1325
+ if (min < 60) return min + 'm ' + sec + 's';
1326
+ const hr = Math.floor(min / 60);
1327
+ const remMin = min % 60;
1328
+ return hr + 'h ' + remMin + 'm';
1329
+ }
1330
+
1331
+ /**
1332
+ * Normalize `.run.json` telemetry into a UI/Markdown view model.
1333
+ * Supports both v1.6 `runState.summary` and older `.run.json` files without `summary`.
1334
+ */
1335
+ function buildRunSummaryView({ runState, nodes, runsById, now, fallbackTiming }) {
1336
+ if (!runState || typeof runState !== 'object' || runState.status === 'idle') {
1337
+ return { hasData: false };
1338
+ }
1339
+ const clock = typeof now === 'number' ? now : Date.now();
1340
+ const canvasNodes = Array.isArray(nodes) ? nodes : [];
1341
+ const byCanvasId = new Map(canvasNodes.map((n) => [n.id, n]));
1342
+ const runMap = runsById && typeof runsById === 'object' ? runsById : {};
1343
+ const sum = runState.summary && typeof runState.summary === 'object' ? runState.summary : null;
1344
+ const status = runState.status || (sum && sum.status) || 'running';
1345
+ const waitingLead = runState.waitingLead || null;
1346
+ const isLive = status === 'running' || status === 'need-lead';
1347
+
1348
+ let rows = [];
1349
+ let minNodeStart = null;
1350
+ let maxNodeEnd = null;
1351
+ if (sum && Array.isArray(sum.nodes) && sum.nodes.length > 0) {
1352
+ rows = sum.nodes.map((entry) => {
1353
+ if (typeof entry.startedAt === 'number' && (minNodeStart === null || entry.startedAt < minNodeStart)) {
1354
+ minNodeStart = entry.startedAt;
1355
+ }
1356
+ if (typeof entry.endedAt === 'number' && (maxNodeEnd === null || entry.endedAt > maxNodeEnd)) {
1357
+ maxNodeEnd = entry.endedAt;
1358
+ }
1359
+ const baseMs = typeof entry.durationMs === 'number' ? entry.durationMs : 0;
1360
+ const liveExtra = (entry.status === 'running' || entry.status === 'waiting')
1361
+ && typeof entry.startedAt === 'number' && !entry.endedAt
1362
+ ? Math.max(0, clock - entry.startedAt)
1363
+ : 0;
1364
+ const totalMs = baseMs + liveExtra;
1365
+ const canvasNode = byCanvasId.get(entry.id);
1366
+ const childRun = runMap[entry.id] || null;
1367
+ const entryStatus = entry.status || 'pending';
1368
+ const isUnrun = entryStatus === 'pruned' || (entryStatus === 'pending' && totalMs === 0);
1369
+ const isZeroLead = (entry.kind || (canvasNode && canvasNode.kind)) === 'lead' && totalMs === 0 && entryStatus !== 'running' && entryStatus !== 'waiting';
1370
+ return {
1371
+ id: entry.id,
1372
+ label: entry.label || (canvasNode && canvasNode.label) || entry.id,
1373
+ kind: entry.kind || (canvasNode && canvasNode.kind) || 'agent',
1374
+ status: entryStatus,
1375
+ durationMs: (isUnrun || isZeroLead) ? null : totalMs,
1376
+ runs: typeof entry.runs === 'number' ? entry.runs : 0,
1377
+ model: entry.model || '',
1378
+ fallbackUsed: Boolean(entry.fallbackUsed),
1379
+ sessionContinued: Boolean(entry.sessionContinued),
1380
+ childId: isUnrun ? '' : (entry.childId || (childRun && childRun.childId) || ''),
1381
+ reason: entry.reason || '',
1382
+ onCanvas: Boolean(canvasNode),
1383
+ };
1384
+ });
1385
+ } else {
1386
+ // Graceful fallback for older `.run.json` payloads written before `summary` existed.
1387
+ const doneSet = new Set(Array.isArray(runState.done) ? runState.done : []);
1388
+ const prunedSet = new Set(Array.isArray(runState.pruned) ? runState.pruned : []);
1389
+ const decisions = runState.decisions && typeof runState.decisions === 'object' ? runState.decisions : {};
1390
+ rows = canvasNodes.filter((n) => n && n.id !== 'lead').map((n) => {
1391
+ const dec = decisions[n.id] || null;
1392
+ const childRun = runMap[n.id] || null;
1393
+ let st = 'pending';
1394
+ if (prunedSet.has(n.id)) st = 'pruned';
1395
+ else if (status === 'need-lead' && waitingLead && waitingLead.id === n.id) st = 'waiting';
1396
+ else if (dec && dec.failed) st = 'failed';
1397
+ else if (doneSet.has(n.id)) st = 'done';
1398
+ const reason = dec
1399
+ ? ((Array.isArray(dec.branchLabels) && dec.branchLabels.length ? dec.branchLabels.join(', ') : (dec.branchLabel || ''))
1400
+ + (dec.reason ? ' — ' + dec.reason : ''))
1401
+ : '';
1402
+ return {
1403
+ id: n.id,
1404
+ label: n.label || n.id,
1405
+ kind: n.kind || 'agent',
1406
+ status: st,
1407
+ durationMs: null,
1408
+ runs: doneSet.has(n.id) ? 1 : 0,
1409
+ model: n.model || '',
1410
+ fallbackUsed: false,
1411
+ sessionContinued: false,
1412
+ childId: (st === 'pruned' || st === 'pending') ? '' : ((childRun && childRun.childId) || ''),
1413
+ reason,
1414
+ onCanvas: true,
1415
+ };
1416
+ });
1417
+ }
1418
+
1419
+ if (!rows.length) return { hasData: false };
1420
+
1421
+ let doneCount = 0;
1422
+ let failedCount = 0;
1423
+ let prunedCount = 0;
1424
+ let runningCount = 0;
1425
+ let maxNodeMs = 0;
1426
+ for (const r of rows) {
1427
+ if (r.status === 'done' || r.status === 'reused') doneCount += 1;
1428
+ else if (r.status === 'failed' || r.status === 'empty') failedCount += 1;
1429
+ else if (r.status === 'pruned') prunedCount += 1;
1430
+ else if (r.status === 'running' || r.status === 'waiting') runningCount += 1;
1431
+ if (typeof r.durationMs === 'number' && r.durationMs > maxNodeMs) maxNodeMs = r.durationMs;
1432
+ }
1433
+
1434
+ const fb = fallbackTiming && typeof fallbackTiming === 'object' ? fallbackTiming : null;
1435
+ const startedAt = (sum && typeof sum.startedAt === 'number')
1436
+ ? sum.startedAt
1437
+ : (minNodeStart !== null ? minNodeStart : (fb && typeof fb.startedAt === 'number' ? fb.startedAt : null));
1438
+ const endedAt = (sum && typeof sum.endedAt === 'number')
1439
+ ? sum.endedAt
1440
+ : (!isLive && maxNodeEnd !== null
1441
+ ? maxNodeEnd
1442
+ : (!isLive && fb && typeof fb.endedAt === 'number' ? fb.endedAt : null));
1443
+ const elapsedMs = startedAt !== null
1444
+ ? Math.max(0, (endedAt !== null ? endedAt : (isLive ? clock : (runState.at || clock))) - startedAt)
1445
+ : (maxNodeMs > 0 ? maxNodeMs : null);
1446
+
1447
+ const loops = sum && Array.isArray(sum.loops) ? sum.loops : [];
1448
+ const totalLoops = sum && typeof sum.totalLoops === 'number'
1449
+ ? sum.totalLoops
1450
+ : loops.reduce((acc, l) => acc + (Number(l && l.used) || 0), 0);
1451
+
1452
+ return {
1453
+ hasData: true,
1454
+ status,
1455
+ isLive,
1456
+ waitingLead,
1457
+ haltedReason: (sum && sum.haltedReason) || '',
1458
+ maxParallel: (sum && typeof sum.maxParallel === 'number') ? sum.maxParallel : null,
1459
+ elapsedMs,
1460
+ totalCount: rows.length,
1461
+ doneCount,
1462
+ failedCount,
1463
+ prunedCount,
1464
+ runningCount,
1465
+ maxNodeMs,
1466
+ totalLoops,
1467
+ loops,
1468
+ nodes: rows,
1469
+ };
1470
+ }
1471
+
1472
+ /** Render a deterministic GitHub-Flavored Markdown report from a run summary view. */
1473
+ function formatRunSummaryMarkdown(view, lang) {
1474
+ if (!view || !view.hasData) return '';
1475
+ const en = lang === 'en';
1476
+ const dict = I18N[en ? 'en' : 'zh'];
1477
+ const statusLabel = (st) => {
1478
+ if (st === 'done') return dict.runStDone;
1479
+ if (st === 'reused') return dict.runSummaryReused;
1480
+ if (st === 'running') return dict.runStRunning;
1481
+ if (st === 'waiting' || st === 'need-lead') return dict.runStWaiting;
1482
+ if (st === 'halted') return dict.runStHalted;
1483
+ if (st === 'failed') return dict.runStFailed;
1484
+ if (st === 'empty') return dict.runStEmpty;
1485
+ if (st === 'pruned') return dict.runStPruned;
1486
+ return dict.runStPending;
1487
+ };
1488
+ const kindLabel = (k) => (k === 'condition' ? (en ? 'Condition' : '条件') : (k === 'lead' ? 'Lead' : (en ? 'Subagent' : '子代理')));
1489
+ const esc = (s) => String(s || '').replace(/\|/g, '\\|').replace(/\r?\n/g, ' ');
1490
+ const lines = [
1491
+ '### ' + dict.runSummaryTitle,
1492
+ '',
1493
+ '- **' + (en ? 'Status' : '状态') + '**: ' + statusLabel(view.status)
1494
+ + (view.waitingLead && view.waitingLead.label ? ' (' + view.waitingLead.label + ')' : ''),
1495
+ '- **' + dict.runSummaryElapsed + '**: ' + formatDurationMs(view.elapsedMs),
1496
+ '- **' + (en ? 'Nodes' : '节点') + '**: ' + view.doneCount + '/' + view.totalCount
1497
+ + (view.failedCount ? ' · ' + view.failedCount + ' ' + dict.runStFailed : '')
1498
+ + (view.prunedCount ? ' · ' + view.prunedCount + ' ' + dict.runStPruned : ''),
1499
+ '- **' + dict.runSummaryLoops + '**: ' + view.totalLoops
1500
+ + (view.maxParallel ? ' · **' + dict.runSummaryParallel + '**: ×' + view.maxParallel : ''),
1501
+ ];
1502
+ if (view.haltedReason) {
1503
+ lines.push('- **' + (en ? 'Halt reason' : '终止原因') + '**: ' + esc(view.haltedReason));
1504
+ }
1505
+ lines.push('');
1506
+ lines.push(en
1507
+ ? '| Node | Type | Status | Duration | Runs | Notes |'
1508
+ : '| 节点 | 类型 | 状态 | 耗时 | 轮次 | 备注 |');
1509
+ lines.push('| :--- | :--- | :--- | ---: | ---: | :--- |');
1510
+ for (const n of view.nodes) {
1511
+ const notes = [];
1512
+ if (n.model) notes.push(n.model);
1513
+ if (n.fallbackUsed) notes.push(dict.runSummaryFallback);
1514
+ if (n.sessionContinued) notes.push(dict.runSummaryContinued);
1515
+ if (n.reason) notes.push(n.reason);
1516
+ lines.push(
1517
+ '| ' + esc(n.label)
1518
+ + ' | ' + kindLabel(n.kind)
1519
+ + ' | ' + statusLabel(n.status)
1520
+ + ' | ' + formatDurationMs(n.durationMs)
1521
+ + ' | ' + (n.runs > 0 ? String(n.runs) : '—')
1522
+ + ' | ' + esc(notes.join(' · '))
1523
+ + ' |',
1524
+ );
1525
+ }
1526
+ if (view.loops && view.loops.length) {
1527
+ lines.push('');
1528
+ lines.push('#### ' + dict.runSummaryLoopsHead);
1529
+ for (const lp of view.loops) {
1530
+ lines.push('- **' + esc(lp.fromLabel) + ' ↺ ' + esc(lp.toLabel) + '** (' + lp.used + '/' + lp.max + (lp.exhausted ? ' · ' + dict.runSummaryExhausted : '') + ')');
1531
+ for (const r of (lp.rounds || [])) {
1532
+ lines.push(' - R' + r.round + ': ' + esc(r.reason));
1533
+ }
1534
+ }
1535
+ }
1536
+ return lines.join('\n');
1537
+ }
1538
+
1214
1539
  function isCustomBranches(node) {
1215
1540
  return Boolean(node && node.kind === 'condition' && Array.isArray(node.branches) && node.branches.length >= 2);
1216
1541
  }
@@ -2057,50 +2382,100 @@ window.__ModuleLoader__.load({
2057
2382
  {
2058
2383
  id: 'lead', kind: 'lead', label: 'Lead', y: 0,
2059
2384
  task: en
2060
- ? 'Implement the requested change and verify with tests: if checks fail, automatically loop back with feedback to fix (up to 3 retries), then hand off to me for final review.'
2061
- : '实现目标功能并跑测试验证:若测试或检查不通过,自动带着失败原因回环修改(最多 3 次),全部通过后交我终审交付。',
2385
+ ? 'Ship OAuth login end-to-end: scan codebase and security constraints in parallel, pause for my sign-off, build core code and tests/docs concurrently with an automated retry loop if checks fail, then deliver to final review.'
2386
+ : '端到端交付 OAuth 登录模块:先并行摸底代码库与安全约束,我拍板后并行开发实现与文档用例;质量门禁未通过则带反馈自动回环修复(最多 3 轮),通过后直达终审交付。',
2387
+ refs: ['AGENTS.md', 'docs/auth-spec.md'],
2062
2388
  provider: '', model: '', role: '',
2063
2389
  },
2390
+ {
2391
+ id: 'lp_scan', kind: 'agent', y: 0,
2392
+ label: en ? 'Codebase Scan' : '代码库摸底',
2393
+ provider: '', model: '', reasoning: '', preset: 'standard', keepSession: true,
2394
+ role: en
2395
+ ? 'Locate auth routes, session middleware and conventions; keep warm session for Core Implement.'
2396
+ : '定位鉴权路由、会话中间件与工程约定,保留热会话供核心实现无缝续接。',
2397
+ },
2398
+ {
2399
+ id: 'lp_risk', kind: 'agent', y: 100,
2400
+ label: en ? 'Security Spec' : '安全与约束',
2401
+ provider: '', model: '', reasoning: '', preset: 'minimal', keepSession: false,
2402
+ refs: ['docs/security.md'],
2403
+ role: en
2404
+ ? 'Read-only threat check (CSRF, PKCE, token rotation); output structured JSON spec.'
2405
+ : '只读梳理 CSRF、PKCE 与令牌轮换约束,输出结构化 JSON 方案。',
2406
+ },
2407
+ {
2408
+ id: 'lp_signoff', kind: 'lead', y: 0,
2409
+ label: en ? 'Lead Sign-Off' : 'Lead 拍板',
2410
+ provider: '', model: '',
2411
+ role: en
2412
+ ? 'Review structured spec, confirm scope and non-goals, then release parallel delivery.'
2413
+ : '评审结构化安全方案,锁定改动边界与不做的事,放行并行实现。',
2414
+ },
2064
2415
  {
2065
2416
  id: 'lp_impl', kind: 'agent', y: 0,
2066
- label: en ? 'Implement' : '编写实现',
2067
- provider: '', model: '', reasoning: '', preset: 'standard', keepSession: false,
2417
+ label: en ? 'Core Implement' : '核心实现与自测',
2418
+ provider: '', model: '', reasoning: '', preset: 'standard', keepSession: true,
2068
2419
  role: en
2069
- ? 'Implement the requested change cleanly. When invoked on a retry round, focus directly on fixing the reported issues and list modified files.'
2070
- : '按需求完成代码或文档实现;若处于回环修正轮次,针对打回理由直接定点修复并列出改动清单。',
2420
+ ? 'Continue inside scan session to implement OAuth flow and run tests; on retry rounds fix reported defects directly.'
2421
+ : '沿用摸底热会话实现 OAuth 流程并跑测试;若被打回则按反馈定点修复。',
2071
2422
  },
2072
2423
  {
2073
- id: 'lp_test', kind: 'agent', y: 0,
2074
- label: en ? 'Test & Verify' : '测试与检查',
2424
+ id: 'lp_docs', kind: 'agent', y: 100,
2425
+ label: en ? 'Docs & Checklist' : '文档与验收清单',
2075
2426
  provider: '', model: '', reasoning: '', preset: 'standard', keepSession: false,
2076
2427
  role: en
2077
- ? 'Run tests/lint/checks against the implementation and report exact pass/fail status, error logs, and remaining defects.'
2078
- : '对实现结果运行单测、构建或逐项核验,如实汇报通过情况、具体报错日志与遗留缺陷。',
2428
+ ? 'Update config docs and acceptance checklist in parallel (never touch source files).'
2429
+ : '并行补齐配置文档与验收清单(不改业务源码,与回环实现互不干扰)。',
2079
2430
  },
2080
2431
  {
2081
2432
  id: 'lp_gate', kind: 'condition', y: 0,
2082
- label: en ? 'Checks Passed?' : '是否通过?',
2433
+ label: en ? 'Quality Gate' : '质量门禁',
2083
2434
  provider: '', model: '', reasoning: '', preset: 'minimal', keepSession: false,
2435
+ branches: [
2436
+ { id: 'true', label: en ? 'Pass' : '通过', when: en ? 'All tests and security checks passed' : '单测与安全核验全部通过' },
2437
+ { id: 'false', label: en ? 'Fix Loop' : '打回修复', when: en ? 'Any test failed or defect remains' : '存在测试失败或未解决缺陷' },
2438
+ ],
2084
2439
  role: en
2085
- ? 'Return pass=true only if all tests/checks passed with no unresolved defects; otherwise return pass=false with a concise, actionable fix reason.'
2086
- : '仅当测试与检查全部通过且无未解决缺陷时返回 true;否则返回 false,并在理由里写清下一轮需修复的具体问题。',
2440
+ ? 'Verify test results and security checklist; route to Pass only when clean, otherwise return actionable fix feedback.'
2441
+ : '核验测试结果与安全清单;全部通过走「通过」,否则走「打回修复」并附具体修复理由。',
2087
2442
  },
2088
2443
  {
2089
2444
  id: 'lp_final', kind: 'lead', y: 0,
2090
- label: en ? 'Lead Final Review' : 'Lead 终审',
2445
+ label: en ? 'Lead Ship Gate' : 'Lead 终审交付',
2091
2446
  provider: '', model: '',
2092
2447
  role: en
2093
- ? 'Review the verified result (or the round-by-round summary if retries exhausted) and decide whether to ship or intervene.'
2094
- : '审阅最终通过的改动摘要(或回环达上限后的历次失败记录),确认交付或拍板下一步处理。',
2448
+ ? 'Combine verified implementation and docs into final release summary.'
2449
+ : '汇聚通过门禁的实现与文档,给出最终交付结论。',
2095
2450
  },
2096
2451
  ];
2097
2452
  const loopEdges = [
2098
- { id: 'lp1', from: 'lead', to: 'lp_impl', type: 'prompt' },
2099
- { id: 'lp2', from: 'lp_impl', to: 'lp_test', type: 'prompt' },
2100
- { id: 'lp3', from: 'lp_test', to: 'lp_gate', type: 'prompt' },
2101
- { id: 'lp4', from: 'lp_gate', to: 'lp_final', type: 'prompt', branch: 'true' },
2102
- { id: 'lp5', from: 'lp_gate', to: 'lp_impl', type: 'prompt', branch: 'false', loop: true, maxIterations: 3 },
2453
+ { id: 'lp1', from: 'lead', to: 'lp_scan', type: 'prompt' },
2454
+ { id: 'lp2', from: 'lead', to: 'lp_risk', type: 'prompt' },
2455
+ { id: 'lp3', from: 'lp_scan', to: 'lp_signoff', type: 'prompt' },
2456
+ { id: 'lp4', from: 'lp_risk', to: 'lp_signoff', type: 'structured' },
2457
+ { id: 'lp5', from: 'lp_signoff', to: 'lp_impl', type: 'prompt' },
2458
+ { id: 'lp6', from: 'lp_scan', to: 'lp_impl', type: 'session-ref' },
2459
+ { id: 'lp7', from: 'lp_signoff', to: 'lp_docs', type: 'prompt' },
2460
+ { id: 'lp8', from: 'lp_impl', to: 'lp_gate', type: 'prompt' },
2461
+ { id: 'lp9', from: 'lp_gate', to: 'lp_final', type: 'prompt', branch: 'true' },
2462
+ { id: 'lp10', from: 'lp_gate', to: 'lp_impl', type: 'prompt', branch: 'false', loop: true, maxIterations: 3 },
2463
+ { id: 'lp11', from: 'lp_docs', to: 'lp_final', type: 'prompt' },
2103
2464
  ];
2465
+ // Align the loop pair (lp_impl -> lp_gate) on the outer rail side (top in lr, right in tb)
2466
+ // so the dashed loop frame and outer bypass arc never overlap the parallel bypass node lp_docs.
2467
+ const loopLaid = layoutGraph(loopNodes, loopEdges, direction).map((n) => ({ ...n }));
2468
+ const lpById = new Map(loopLaid.map((n) => [n.id, n]));
2469
+ if (direction === 'tb') {
2470
+ const leftX = Math.min(lpById.get('lp_impl').x, lpById.get('lp_docs').x);
2471
+ const rightX = Math.max(lpById.get('lp_impl').x, lpById.get('lp_docs').x);
2472
+ lpById.get('lp_docs').x = leftX;
2473
+ lpById.get('lp_impl').x = rightX;
2474
+ lpById.get('lp_gate').x = rightX;
2475
+ } else {
2476
+ lpById.get('lp_gate').y = lpById.get('lp_impl').y - 8;
2477
+ lpById.get('lp_docs').y = Math.max(lpById.get('lp_docs').y, lpById.get('lp_gate').y + nodeHeight(lpById.get('lp_gate')) + 64);
2478
+ }
2104
2479
  return [
2105
2480
  {
2106
2481
  id: 'tpl-swe',
@@ -2128,8 +2503,8 @@ window.__ModuleLoader__.load({
2128
2503
  },
2129
2504
  {
2130
2505
  id: 'tpl-loop',
2131
- name: en ? 'Retry Loop: Implement → Test ↺ Fix → Review' : '循环重试:实现 → 测试验收 ↺ 自动修复 → 终审',
2132
- nodes: layoutGraph(loopNodes, loopEdges, direction),
2506
+ name: en ? 'Full Showcase: Parallel → Gate → Loop ↺ Fix → Ship' : '全功能回环:并行摸底 → 拍板 → 实现 ↺ 门禁 → 终审',
2507
+ nodes: loopLaid,
2133
2508
  edges: loopEdges,
2134
2509
  },
2135
2510
  ];
@@ -2552,6 +2927,9 @@ window.__ModuleLoader__.load({
2552
2927
  const [menuAlign, setMenuAlign] = useState('right');
2553
2928
  const [presetAlign, setPresetAlign] = useState('right');
2554
2929
  const [helpOpen, setHelpOpen] = useState(false);
2930
+ const [summaryOpen, setSummaryOpen] = useState(false);
2931
+ const [summaryNow, setSummaryNow] = useState(() => Date.now());
2932
+ const clientRunTimingRef = useRef({ startedAt: null, endedAt: null, prevStatus: '', runAt: null });
2555
2933
  const [shortcuts, setShortcuts] = useState(loadShortcuts);
2556
2934
  const shortcutsRef = useRef(shortcuts);
2557
2935
  shortcutsRef.current = shortcuts;
@@ -2925,10 +3303,14 @@ window.__ModuleLoader__.load({
2925
3303
  await Promise.all(tasks);
2926
3304
  runTriggeringRef.current = false;
2927
3305
  setRunTriggering(false);
3306
+ const stopNow = Date.now();
2928
3307
  setRunState((prev) => ({
2929
3308
  ...(prev || {}),
2930
3309
  status: 'halted',
2931
3310
  waitingLead: null,
3311
+ ...(prev && prev.summary
3312
+ ? { summary: { ...prev.summary, status: 'halted', endedAt: prev.summary.endedAt || stopNow } }
3313
+ : {}),
2932
3314
  }));
2933
3315
  setStatusById((prev) => {
2934
3316
  const next = {};
@@ -3191,6 +3573,13 @@ window.__ModuleLoader__.load({
3191
3573
  centerOn(lead.x + NODE_W / 2, lead.y + NODE_H / 2, nextK);
3192
3574
  };
3193
3575
 
3576
+ const focusNode = (nodeId) => {
3577
+ const target = nodesRef.current.find((n) => n.id === nodeId);
3578
+ if (!target) return;
3579
+ setSelectedIds([target.id]);
3580
+ centerOn(target.x + NODE_W / 2, target.y + nodeHeight(target) / 2);
3581
+ };
3582
+
3194
3583
  /** Horizontal drag scrubber on the percentage pill; pure click resets to 100% on Lead. */
3195
3584
  const onZoomPillDown = (e) => {
3196
3585
  if (e.button !== 0) return;
@@ -3350,7 +3739,7 @@ window.__ModuleLoader__.load({
3350
3739
  }
3351
3740
  };
3352
3741
 
3353
- const openNodeSession = async (node) => {
3742
+ const openNodeSession = async (node, fallbackChildId) => {
3354
3743
  let run = runsById[node.id];
3355
3744
  if (!run) {
3356
3745
  const sessions = hostCtx && hostCtx.sessions;
@@ -3364,6 +3753,9 @@ window.__ModuleLoader__.load({
3364
3753
  run = nextRuns[node.id];
3365
3754
  }
3366
3755
  }
3756
+ if (!run && fallbackChildId) {
3757
+ run = { childId: fallbackChildId, mode: 'local', label: node.label || node.id };
3758
+ }
3367
3759
  if (!run) { flash(t('cannotOpen')); return; }
3368
3760
  openRun(node, run);
3369
3761
  };
@@ -3705,12 +4097,7 @@ window.__ModuleLoader__.load({
3705
4097
  flash(t('clearedCanvas'));
3706
4098
  };
3707
4099
 
3708
- const exportToClipboard = () => {
3709
- const cleanNodes = nodesRef.current.map((n) => {
3710
- const { runs: _runs, ...rest } = n;
3711
- return rest;
3712
- });
3713
- const text = JSON.stringify({ nodes: cleanNodes, edges: edgesRef.current, direction: directionRef.current }, null, 2);
4100
+ const copyTextToClipboard = (text, okMsg) => {
3714
4101
  const fallbackCopy = () => {
3715
4102
  try {
3716
4103
  const ta = document.createElement('textarea');
@@ -3721,20 +4108,35 @@ window.__ModuleLoader__.load({
3721
4108
  ta.select();
3722
4109
  const ok = document.execCommand && document.execCommand('copy');
3723
4110
  document.body.removeChild(ta);
3724
- flash(ok ? t('exportOk') : t('exportFail'));
4111
+ flash(ok ? okMsg : t('exportFail'));
3725
4112
  } catch (_e) {
3726
4113
  flash(t('exportFail'));
3727
4114
  }
3728
4115
  };
3729
4116
  try {
3730
4117
  if (navigator.clipboard && navigator.clipboard.writeText) {
3731
- navigator.clipboard.writeText(text).then(() => flash(t('exportOk')), fallbackCopy);
4118
+ navigator.clipboard.writeText(text).then(() => flash(okMsg), fallbackCopy);
3732
4119
  return;
3733
4120
  }
3734
4121
  } catch (_e) { /* fall through */ }
3735
4122
  fallbackCopy();
3736
4123
  };
3737
4124
 
4125
+ const exportToClipboard = () => {
4126
+ const cleanNodes = nodesRef.current.map((n) => {
4127
+ const { runs: _runs, ...rest } = n;
4128
+ return rest;
4129
+ });
4130
+ const text = JSON.stringify({ nodes: cleanNodes, edges: edgesRef.current, direction: directionRef.current }, null, 2);
4131
+ copyTextToClipboard(text, t('exportOk'));
4132
+ };
4133
+
4134
+ const copyRunSummary = (view) => {
4135
+ const md = formatRunSummaryMarkdown(view, lang);
4136
+ if (!md) { flash(t('runSummaryEmpty')); return; }
4137
+ copyTextToClipboard(md, t('runSummaryCopied'));
4138
+ };
4139
+
3738
4140
  const openAddMenuAtCursor = () => {
3739
4141
  const wrap = canvasWrapRef.current;
3740
4142
  const content = contentRef.current;
@@ -4051,9 +4453,16 @@ window.__ModuleLoader__.load({
4051
4453
  const keyActionsRef = useRef(null);
4052
4454
  keyActionsRef.current = {
4053
4455
  undo, redo, deleteSelected, duplicateSelected, openAddMenuAtCursor, addNode, fitView, autoLayout, toggleDirection, flash, t,
4054
- addMenu, ctxMenu, loopEditEdgeId, roleEditFor, openModelFor, menuOpen, presetOpen, helpOpen, shortcutsOpen, recordingAction, decisionViewFor, refsEditFor,
4055
- setAddMenu, setCtxMenu, setLoopEditEdgeId, setRoleEditFor, setOpenModelFor, setMenuOpen, setPresetOpen, setHelpOpen, setShortcutsOpen, setRecordingAction, setShortcuts, setDecisionViewFor, setRefsEditFor,
4456
+ addMenu, ctxMenu, loopEditEdgeId, roleEditFor, openModelFor, menuOpen, presetOpen, helpOpen, summaryOpen, shortcutsOpen, recordingAction, decisionViewFor, refsEditFor,
4457
+ setAddMenu, setCtxMenu, setLoopEditEdgeId, setRoleEditFor, setOpenModelFor, setMenuOpen, setPresetOpen, setHelpOpen, setSummaryOpen, setShortcutsOpen, setRecordingAction, setShortcuts, setDecisionViewFor, setRefsEditFor,
4056
4458
  };
4459
+ const summaryIsLive = Boolean(runState && (runState.status === 'running' || runState.status === 'need-lead'));
4460
+ useEffect(() => {
4461
+ if (!summaryIsLive) return undefined;
4462
+ setSummaryNow(Date.now());
4463
+ const timer = setInterval(() => setSummaryNow(Date.now()), 1000);
4464
+ return () => clearInterval(timer);
4465
+ }, [summaryIsLive, summaryOpen]);
4057
4466
  useEffect(() => {
4058
4467
  const isEditable = (target) => {
4059
4468
  if (!target || !(target instanceof HTMLElement)) return false;
@@ -4081,7 +4490,7 @@ window.__ModuleLoader__.load({
4081
4490
  return;
4082
4491
  }
4083
4492
  if (ev.key === 'Escape') {
4084
- if (act.addMenu || act.ctxMenu || act.loopEditEdgeId || act.roleEditFor || act.openModelFor || act.menuOpen || act.presetOpen || act.helpOpen || act.shortcutsOpen || act.decisionViewFor || act.refsEditFor) {
4493
+ if (act.addMenu || act.ctxMenu || act.loopEditEdgeId || act.roleEditFor || act.openModelFor || act.menuOpen || act.presetOpen || act.helpOpen || act.summaryOpen || act.shortcutsOpen || act.decisionViewFor || act.refsEditFor) {
4085
4494
  ev.preventDefault();
4086
4495
  act.setAddMenu(null);
4087
4496
  act.setCtxMenu(null);
@@ -4091,6 +4500,7 @@ window.__ModuleLoader__.load({
4091
4500
  act.setMenuOpen(false);
4092
4501
  act.setPresetOpen(null);
4093
4502
  act.setHelpOpen(false);
4503
+ act.setSummaryOpen(false);
4094
4504
  act.setShortcutsOpen(false);
4095
4505
  act.setRecordingAction(null);
4096
4506
  act.setDecisionViewFor(null);
@@ -4098,7 +4508,7 @@ window.__ModuleLoader__.load({
4098
4508
  }
4099
4509
  return;
4100
4510
  }
4101
- if (act.shortcutsOpen) return;
4511
+ if (act.shortcutsOpen || act.summaryOpen || act.helpOpen) return;
4102
4512
  if (isEditable(ev.target)) return;
4103
4513
  if (act.addMenu) {
4104
4514
  const lf = act.addMenu.linkFrom || null;
@@ -5041,6 +5451,51 @@ window.__ModuleLoader__.load({
5041
5451
  const nodeAttemptsMap = (enabled && runState && runState.nodeAttempts && typeof runState.nodeAttempts === 'object')
5042
5452
  ? runState.nodeAttempts
5043
5453
  : {};
5454
+ // Client-side fallback wall-clock tracking in case an older backend `.run.json` omits `summary.startedAt`.
5455
+ // Never synthesize startedAt from `runState.at` (which is the write/finish timestamp of `.run.json`).
5456
+ (() => {
5457
+ const curSt = runState && typeof runState.status === 'string' ? runState.status : '';
5458
+ const curAt = runState && typeof runState.at === 'number' ? runState.at : null;
5459
+ const tr = clientRunTimingRef.current;
5460
+ if (!curSt || curSt === 'idle') {
5461
+ tr.startedAt = null;
5462
+ tr.endedAt = null;
5463
+ tr.runAt = null;
5464
+ tr.prevStatus = curSt;
5465
+ } else if (curSt === 'running' && tr.prevStatus !== 'running' && tr.prevStatus !== 'need-lead') {
5466
+ tr.startedAt = (runState && runState.summary && typeof runState.summary.startedAt === 'number')
5467
+ ? runState.summary.startedAt
5468
+ : Date.now();
5469
+ tr.endedAt = null;
5470
+ tr.runAt = curAt;
5471
+ tr.prevStatus = curSt;
5472
+ } else if (curSt === 'done' || curSt === 'halted') {
5473
+ if (tr.prevStatus === 'running' || tr.prevStatus === 'need-lead') {
5474
+ if (tr.startedAt !== null) {
5475
+ tr.endedAt = (runState && runState.summary && typeof runState.summary.endedAt === 'number')
5476
+ ? runState.summary.endedAt
5477
+ : Date.now();
5478
+ tr.runAt = curAt;
5479
+ }
5480
+ } else if (curAt !== null && tr.runAt !== null && curAt !== tr.runAt) {
5481
+ // A fresh terminal `.run.json` arrived without observing a `running` poll in between:
5482
+ // drop any prior run's client clock rather than mixing two different runs.
5483
+ tr.startedAt = null;
5484
+ tr.endedAt = null;
5485
+ tr.runAt = curAt;
5486
+ }
5487
+ tr.prevStatus = curSt;
5488
+ } else {
5489
+ tr.prevStatus = curSt;
5490
+ }
5491
+ })();
5492
+ const runSummary = buildRunSummaryView({
5493
+ runState,
5494
+ nodes,
5495
+ runsById,
5496
+ now: summaryNow,
5497
+ fallbackTiming: clientRunTimingRef.current,
5498
+ });
5044
5499
  const loopGroups = loopGroupsForUI(nodes, edges);
5045
5500
  const edgeKeyForState = (e) => String(e.from) + '->' + String(e.to) + '|' + String(e.type || 'prompt') + '|' + String(e.branch || '');
5046
5501
  const loopPillItems = [];
@@ -5747,6 +6202,12 @@ window.__ModuleLoader__.load({
5747
6202
  onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
5748
6203
  onClick: () => { toggleLang(); },
5749
6204
  }, t('ctxLangToggle') + t('sep') + (lang === 'zh' ? '中文' : 'EN')),
6205
+ h('div', {
6206
+ style: S.moreRow,
6207
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
6208
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
6209
+ onClick: () => { setMenuOpen(false); setSummaryNow(Date.now()); setSummaryOpen(true); },
6210
+ }, t('runSummaryMenu')),
5750
6211
  h('div', {
5751
6212
  style: S.moreRow,
5752
6213
  onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
@@ -5775,6 +6236,165 @@ window.__ModuleLoader__.load({
5775
6236
  h('div', { style: S.helpBody }, t('helpBody').split('\n').map((line, i) => h('div', { key: i, style: S.helpLine }, line))),
5776
6237
  ),
5777
6238
  ),
6239
+ summaryOpen && (() => {
6240
+ const stVisual = (st) => {
6241
+ if (st === 'done') return { icon: '✓', color: '#3fb950', label: t('runStDone') };
6242
+ if (st === 'reused') return { icon: '⚡', color: '#3fb950', label: t('runSummaryReused') };
6243
+ if (st === 'running') return { icon: '●', color: '#2f81f7', label: t('runStRunning') };
6244
+ if (st === 'waiting' || st === 'need-lead') return { icon: '⏸', color: '#2f81f7', label: t('runStWaiting') };
6245
+ if (st === 'halted') return { icon: '⏹', color: '#e5534b', label: t('runStHalted') };
6246
+ if (st === 'failed') return { icon: '✕', color: '#e5534b', label: t('runStFailed') };
6247
+ if (st === 'empty') return { icon: '⚠', color: '#d29922', label: t('runStEmpty') };
6248
+ if (st === 'pruned') return { icon: '↷', color: C.dim, label: t('runStPruned') };
6249
+ return { icon: '○', color: C.dim, label: t('runStPending') };
6250
+ };
6251
+ const topSt = runSummary.hasData ? stVisual(runSummary.status) : null;
6252
+ return h('div', {
6253
+ style: S.helpOverlay,
6254
+ onMouseDown: (e) => { e.stopPropagation(); if (e.target === e.currentTarget) setSummaryOpen(false); },
6255
+ },
6256
+ h('div', { style: { ...S.helpCard, maxWidth: '460px', display: 'flex', flexDirection: 'column', maxHeight: '82%', overflow: 'hidden' } },
6257
+ h('div', { style: { ...S.helpHead, flex: '0 0 auto' } },
6258
+ h('span', { style: { ...S.helpTitle, display: 'inline-flex', alignItems: 'center', gap: '6px', minWidth: 0 } },
6259
+ h('span', null, t('runSummaryTitle')),
6260
+ topSt && h('span', {
6261
+ style: {
6262
+ fontSize: '10px', fontWeight: 600, padding: '1px 6px', borderRadius: '999px',
6263
+ color: topSt.color, border: '1px solid ' + topSt.color,
6264
+ whiteSpace: 'nowrap',
6265
+ },
6266
+ }, topSt.icon + ' ' + topSt.label),
6267
+ ),
6268
+ runSummary.hasData && h('button', {
6269
+ style: S.btn,
6270
+ type: 'button',
6271
+ onClick: () => copyRunSummary(runSummary),
6272
+ }, t('runSummaryCopy')),
6273
+ h('button', {
6274
+ style: S.btn,
6275
+ type: 'button',
6276
+ onClick: () => setSummaryOpen(false),
6277
+ }, t('close')),
6278
+ ),
6279
+ !runSummary.hasData
6280
+ ? h('div', { style: { padding: '18px 8px', textAlign: 'center', color: C.dim, fontSize: '12px' } }, t('runSummaryEmpty'))
6281
+ : h(React.Fragment, null,
6282
+ h('div', { style: S.summaryKpiRow },
6283
+ h('div', { style: S.summaryKpi },
6284
+ h('span', { style: { fontSize: '10px', color: C.dim } }, t('runSummaryElapsed')),
6285
+ h('span', { style: { fontSize: '13px', fontWeight: 600, color: C.text, fontVariantNumeric: 'tabular-nums' } }, formatDurationMs(runSummary.elapsedMs)),
6286
+ ),
6287
+ h('div', { style: S.summaryKpi },
6288
+ h('span', { style: { fontSize: '10px', color: C.dim } }, t('runSummaryDone')),
6289
+ h('span', { style: { fontSize: '13px', fontWeight: 600, color: runSummary.failedCount ? '#e5534b' : '#3fb950', fontVariantNumeric: 'tabular-nums' } },
6290
+ runSummary.doneCount + '/' + runSummary.totalCount),
6291
+ ),
6292
+ h('div', { style: S.summaryKpi },
6293
+ h('span', { style: { fontSize: '10px', color: C.dim } }, t('runSummaryLoops')),
6294
+ h('span', { style: { fontSize: '13px', fontWeight: 600, color: runSummary.totalLoops ? '#d29922' : C.text, fontVariantNumeric: 'tabular-nums' } }, String(runSummary.totalLoops)),
6295
+ ),
6296
+ h('div', { style: S.summaryKpi },
6297
+ h('span', { style: { fontSize: '10px', color: C.dim } }, t('runSummaryParallel')),
6298
+ h('span', { style: { fontSize: '13px', fontWeight: 600, color: C.text, fontVariantNumeric: 'tabular-nums' } }, '×' + (runSummary.maxParallel || maxParallel)),
6299
+ ),
6300
+ ),
6301
+ h('div', { style: { flex: '1 1 auto', minHeight: 0, overflowY: 'auto', display: 'flex', flexDirection: 'column', gap: '8px', paddingRight: '2px' } },
6302
+ runSummary.haltedReason && h('div', {
6303
+ style: {
6304
+ flex: '0 0 auto', padding: '6px 8px', borderRadius: '6px', fontSize: '11px', lineHeight: '1.45',
6305
+ color: '#e5534b', background: 'rgba(229,83,75,0.12)', border: '1px solid rgba(229,83,75,0.4)',
6306
+ },
6307
+ }, '⏹ ' + runSummary.haltedReason),
6308
+ runSummary.status === 'need-lead' && runSummary.waitingLead && h('div', {
6309
+ style: {
6310
+ flex: '0 0 auto', padding: '6px 8px', borderRadius: '6px', fontSize: '11px', lineHeight: '1.45',
6311
+ color: '#2f81f7', background: 'rgba(47,129,247,0.12)', border: '1px solid rgba(47,129,247,0.4)',
6312
+ },
6313
+ }, '⏸ ' + t('runStWaiting') + ': ' + (runSummary.waitingLead.label || runSummary.waitingLead.id)),
6314
+ h('div', { style: { flex: '0 0 auto', fontSize: '11px', fontWeight: 600, color: C.dim } }, t('runSummaryNodesHead')),
6315
+ h('div', { style: { display: 'flex', flexDirection: 'column', gap: '5px' } },
6316
+ runSummary.nodes.map((n) => {
6317
+ const sv = stVisual(n.status);
6318
+ const barPct = (typeof n.durationMs === 'number' && n.durationMs > 0 && runSummary.maxNodeMs > 0)
6319
+ ? Math.max(4, Math.min(100, Math.round((n.durationMs / runSummary.maxNodeMs) * 100)))
6320
+ : 0;
6321
+ const kindMeta = n.kind === 'condition'
6322
+ ? { label: lang === 'en' ? 'Cond' : '条件', color: '#d29922', border: 'rgba(210,153,34,0.45)' }
6323
+ : n.kind === 'lead'
6324
+ ? { label: 'Lead', color: '#2f81f7', border: 'rgba(47,129,247,0.45)' }
6325
+ : { label: lang === 'en' ? 'Agent' : '子代理', color: '#3fb950', border: 'rgba(63,185,80,0.45)' };
6326
+ return h('div', { key: n.id, style: S.summaryRow },
6327
+ h('div', { style: { display: 'flex', alignItems: 'center', gap: '6px', minWidth: 0 } },
6328
+ h('span', { style: { color: sv.color, fontSize: '11px', fontWeight: 700, flex: '0 0 auto' }, title: sv.label }, sv.icon),
6329
+ h('button', {
6330
+ type: 'button',
6331
+ disabled: !n.onCanvas,
6332
+ title: n.onCanvas ? t('runSummaryFocusTip') : undefined,
6333
+ style: {
6334
+ flex: '1 1 auto', minWidth: 0, textAlign: 'left', padding: 0,
6335
+ border: 'none', background: 'transparent', color: C.text,
6336
+ fontSize: '11px', fontWeight: 600, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
6337
+ cursor: n.onCanvas ? 'pointer' : 'default',
6338
+ },
6339
+ onClick: () => { if (n.onCanvas) { focusNode(n.id); setSummaryOpen(false); } },
6340
+ }, n.label),
6341
+ h('span', { style: { ...S.summaryChip, color: kindMeta.color, borderColor: kindMeta.border, flex: '0 0 auto' } }, kindMeta.label),
6342
+ h('span', { style: { fontSize: '11px', color: C.dim, fontVariantNumeric: 'tabular-nums', flex: '0 0 auto' } }, formatDurationMs(n.durationMs)),
6343
+ n.childId && h('button', {
6344
+ type: 'button',
6345
+ title: t('runSummaryOpenChatTip'),
6346
+ style: { ...S.condAddBtn, padding: '0 5px', height: '18px', flex: '0 0 auto' },
6347
+ onClick: () => {
6348
+ setSummaryOpen(false);
6349
+ const targetNode = nodeById.get(n.id) || { id: n.id, label: n.label };
6350
+ openNodeSession(targetNode, n.childId);
6351
+ },
6352
+ }, '↗'),
6353
+ ),
6354
+ barPct > 0 && h('div', { style: S.summaryBarTrack },
6355
+ h('div', { style: { ...S.summaryBarFill, width: barPct + '%', background: sv.color } }),
6356
+ ),
6357
+ (n.model || n.fallbackUsed || n.sessionContinued || n.runs > 1 || n.status === 'reused' || n.reason) && h('div', {
6358
+ style: { display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: '4px' },
6359
+ },
6360
+ n.model && h('span', { style: S.summaryChip }, n.model),
6361
+ n.runs > 1 && h('span', { style: { ...S.summaryChip, color: '#d29922' } }, t('runSummaryRuns').replace('{n}', String(n.runs))),
6362
+ n.fallbackUsed && h('span', { style: { ...S.summaryChip, color: '#d29922' } }, t('runSummaryFallback')),
6363
+ n.sessionContinued && h('span', { style: { ...S.summaryChip, color: '#a371f7' } }, t('runSummaryContinued')),
6364
+ n.status === 'reused' && h('span', { style: { ...S.summaryChip, color: '#3fb950' } }, t('runSummaryReused')),
6365
+ n.reason && h('span', {
6366
+ style: {
6367
+ fontSize: '10px', lineHeight: '1.35',
6368
+ color: n.status === 'failed' ? '#e5534b' : C.dim,
6369
+ wordBreak: 'break-word',
6370
+ },
6371
+ }, n.reason),
6372
+ ),
6373
+ );
6374
+ }),
6375
+ ),
6376
+ runSummary.loops.length > 0 && h(React.Fragment, null,
6377
+ h('div', { style: { flex: '0 0 auto', fontSize: '11px', fontWeight: 600, color: C.dim, marginTop: '2px' } }, t('runSummaryLoopsHead')),
6378
+ h('div', { style: { display: 'flex', flexDirection: 'column', gap: '5px', flex: '0 0 auto' } },
6379
+ runSummary.loops.map((lp, idx) => h('div', { key: idx, style: S.summaryRow },
6380
+ h('div', { style: { display: 'flex', alignItems: 'center', gap: '6px' } },
6381
+ h('span', { style: { fontSize: '11px', fontWeight: 600, color: '#d29922', flex: '1 1 auto', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
6382
+ lp.fromLabel + ' ↺ ' + lp.toLabel),
6383
+ h('span', { style: { ...S.summaryChip, color: lp.exhausted ? '#e5534b' : '#d29922' } },
6384
+ lp.used + '/' + lp.max + (lp.exhausted ? ' · ' + t('runSummaryExhausted') : '')),
6385
+ ),
6386
+ (lp.rounds || []).map((r, rIdx) => h('div', {
6387
+ key: rIdx,
6388
+ style: { fontSize: '10px', color: C.dim, lineHeight: '1.4', paddingLeft: '6px', borderLeft: '2px solid ' + C.border },
6389
+ }, 'R' + r.round + ': ' + r.reason)),
6390
+ )),
6391
+ ),
6392
+ ),
6393
+ ),
6394
+ ),
6395
+ ),
6396
+ );
6397
+ })(),
5778
6398
  shortcutsOpen && (() => {
5779
6399
  const actionLabels = {
5780
6400
  addNode: t('scAddNode'),
@@ -5892,15 +6512,23 @@ window.__ModuleLoader__.load({
5892
6512
  stopBtn.visible && h('button', {
5893
6513
  type: 'button',
5894
6514
  disabled: stopBtn.disabled,
5895
- style: {
5896
- ...S.floatStop,
5897
- opacity: stopBtn.disabled ? 0.6 : 1,
5898
- cursor: stopBtn.disabled ? 'not-allowed' : 'pointer',
5899
- },
6515
+ style: stopBtn.active
6516
+ ? {
6517
+ ...S.floatStop,
6518
+ opacity: stopBtn.disabled ? 0.6 : 1,
6519
+ cursor: stopBtn.disabled ? 'not-allowed' : 'pointer',
6520
+ }
6521
+ : {
6522
+ ...S.floatStop,
6523
+ border: '1px solid ' + C.border,
6524
+ color: C.dim,
6525
+ opacity: 0.55,
6526
+ cursor: 'not-allowed',
6527
+ },
5900
6528
  title: stopBtn.title,
5901
- onMouseEnter: (e) => { if (!stopBtn.disabled) e.currentTarget.style.background = 'rgba(229,83,75,0.18)'; },
6529
+ onMouseEnter: (e) => { if (stopBtn.active && !stopBtn.disabled) e.currentTarget.style.background = 'rgba(229,83,75,0.18)'; },
5902
6530
  onMouseLeave: (e) => { e.currentTarget.style.background = C.elevated; },
5903
- onClick: () => { if (!stopBtn.disabled) stopWorkflow(); },
6531
+ onClick: () => { if (stopBtn.active && !stopBtn.disabled) stopWorkflow(); },
5904
6532
  }, stopBtn.label),
5905
6533
  ),
5906
6534
  addMenu && (() => {
@@ -6031,6 +6659,42 @@ window.__ModuleLoader__.load({
6031
6659
  menuRow('clr', t('clearCanvasBtn'), () => { setCtxMenu(null); clearCanvas(); }, { danger: true }),
6032
6660
  );
6033
6661
  })(),
6662
+ runSummary.hasData && (() => {
6663
+ const pillIcon = runSummary.status === 'done' ? '✓'
6664
+ : runSummary.status === 'running' ? '●'
6665
+ : runSummary.status === 'need-lead' ? '⏸'
6666
+ : '⏹';
6667
+ const pillColor = runSummary.status === 'done'
6668
+ ? (runSummary.failedCount ? '#d29922' : '#3fb950')
6669
+ : runSummary.status === 'running' || runSummary.status === 'need-lead'
6670
+ ? '#2f81f7'
6671
+ : '#e5534b';
6672
+ const elapsedText = runSummary.elapsedMs !== null ? ' · ' + formatDurationMs(runSummary.elapsedMs) : '';
6673
+ const loopText = runSummary.totalLoops > 0 ? ' · ↺' + runSummary.totalLoops : '';
6674
+ return h('button', {
6675
+ type: 'button',
6676
+ style: { ...S.floatSummaryBtn, borderColor: runSummary.isLive ? pillColor : C.border },
6677
+ title: t('runSummaryTip'),
6678
+ onMouseDown: (e) => e.stopPropagation(),
6679
+ onMouseEnter: (e) => { e.currentTarget.style.borderColor = pillColor; },
6680
+ onMouseLeave: (e) => { e.currentTarget.style.borderColor = runSummary.isLive ? pillColor : C.border; },
6681
+ onClick: () => {
6682
+ setMenuOpen(false);
6683
+ setPresetOpen(null);
6684
+ setCtxMenu(null);
6685
+ setAddMenu(null);
6686
+ setLoopEditEdgeId(null);
6687
+ setOpenModelFor(null);
6688
+ setSummaryNow(Date.now());
6689
+ setSummaryOpen(true);
6690
+ },
6691
+ },
6692
+ h('span', { style: { color: pillColor, flex: '0 0 auto' } }, pillIcon),
6693
+ h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', minWidth: 0 } },
6694
+ t('runSummaryBtn') + ' · ' + runSummary.doneCount + '/' + runSummary.totalCount + loopText),
6695
+ elapsedText && h('span', { style: { flex: '0 0 auto', color: C.dim, fontVariantNumeric: 'tabular-nums' } }, elapsedText),
6696
+ );
6697
+ })(),
6034
6698
  h('div', {
6035
6699
  style: S.floatZoomBar,
6036
6700
  onMouseDown: (e) => e.stopPropagation(),
@@ -6336,7 +7000,7 @@ window.__ModuleLoader__.load({
6336
7000
  }),
6337
7001
  btn.label,
6338
7002
  ),
6339
- stopBtn.visible && h('button', {
7003
+ stopBtn.active && h('button', {
6340
7004
  type: 'button',
6341
7005
  disabled: stopBtn.disabled,
6342
7006
  style: {
@@ -6711,7 +7375,7 @@ window.__ModuleLoader__.load({
6711
7375
  try { console.error('[workflow-canvas] apply failed', error); } catch (_e) { /* ignore */ }
6712
7376
  }
6713
7377
  },
6714
- __test: { topoOrder, wouldCycle, soloLeadNodeIds, layoutGraph, builtinTemplates, deadEndNodeIds, nextEffectLevel, nextMaxParallel, dropdownAlign, zoomAroundPoint, scrubZoom, applyPanStep, normalizeDirection, loadDefaultDirection, saveDefaultDirection, loadPresets, savePresets, buildPlan, loadDoc, saveDoc, storageKey, socketCenterY, nodeHeight, conditionBranchesForUI, distanceToEdge, edgeCurve, compatibleTargetsForWire, conditionVerdictSummary, entryRunButtonState, stopButtonState, deriveLeadStatuses, outputSocketX, inputSocketPos, outputSocketPos, normalizeRefsUI, clampMenuPos, cloneSelection, nextSelectionOnNodeClick, DEFAULT_SHORTCUTS, normalizeShortcut, formatShortcutFromEvent, matchesShortcut, applyShortcutBinding, normalizeMaxIterationsUI, loopMemberIdsUI, loopGroupsForUI, pruneInvalidLoopEdges, canLinkAsLoop, analyzeLoopSelection, loopEdgeArc },
7378
+ __test: { I18N, S, topoOrder, wouldCycle, soloLeadNodeIds, layoutGraph, builtinTemplates, deadEndNodeIds, nextEffectLevel, nextMaxParallel, dropdownAlign, zoomAroundPoint, scrubZoom, applyPanStep, normalizeDirection, loadDefaultDirection, saveDefaultDirection, loadPresets, savePresets, buildPlan, loadDoc, saveDoc, storageKey, socketCenterY, nodeHeight, conditionBranchesForUI, distanceToEdge, edgeCurve, compatibleTargetsForWire, conditionVerdictSummary, entryRunButtonState, stopButtonState, deriveLeadStatuses, formatDurationMs, buildRunSummaryView, formatRunSummaryMarkdown, outputSocketX, inputSocketPos, outputSocketPos, normalizeRefsUI, clampMenuPos, cloneSelection, nextSelectionOnNodeClick, DEFAULT_SHORTCUTS, normalizeShortcut, formatShortcutFromEvent, matchesShortcut, applyShortcutBinding, normalizeMaxIterationsUI, loopMemberIdsUI, loopGroupsForUI, pruneInvalidLoopEdges, canLinkAsLoop, analyzeLoopSelection, loopEdgeArc },
6715
7379
  };
6716
7380
  },
6717
7381
  });